File: resourceplacementdialog.cpp

package info (click to toggle)
asc 2.6.1.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 81,740 kB
  • sloc: cpp: 158,704; sh: 11,544; ansic: 6,736; makefile: 604; perl: 138
file content (220 lines) | stat: -rw-r--r-- 10,840 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/***************************************************************************
                          paradialog.cpp  -  description
                             -------------------
    begin                : Thu Feb 21 2002
    copyright            : (C) 2002 by Martin Bickel
    email                : bickel@asc-hq.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/



#include <iostream>
#include "resourceplacement.h"
// #include "notificationdialog.h"
#include "resourceplacementdialog.h"
#include "spfst.h"
#include "spfst-legacy.h"


const int ResourcePlacementDialog::xsize = 400;
const int ResourcePlacementDialog::ysize = 612;
const int ResourcePlacementDialog::xOffSet = xsize/10;
const int ResourcePlacementDialog::yOffSet = ysize/20;
const int ResourcePlacementDialog::leftIndent = xsize/50;;


ResourcePlacementDialog::ResourcePlacementDialog( ) :
    ASC_PG_Dialog(NULL, PG_Rect( 100,100, xsize, ysize ), "Place Resources", SHOW_CLOSE ),
    fuelRoughness(1), materialRoughness(1), maxFuelOffSet(100), maxMaterialOffSet(100), 
    fuelRoughnessWidget(NULL), materialRoughnessWidget(NULL), fuelOffsetWidget(NULL), materialOffsetWidget(NULL), d(0)
{
  int xFuelWidgetPos = leftIndent;
  int yFuelWidgetPos = ysize/10;
  int hFuelWidget = GetTextHeight() + 10;
  placeFuelWidget = new PG_CheckButton(this, PG_Rect(xFuelWidgetPos, yFuelWidgetPos, xsize/3 , GetTextHeight()*2), "Fuel");
  placeFuelWidget->SetSizeByText();



  int xMaterialWidgetPos = xFuelWidgetPos;
  int yMaterialWidgetPos = yFuelWidgetPos + hFuelWidget;
  placeMaterialWidget = new PG_CheckButton(this, PG_Rect(xMaterialWidgetPos, yMaterialWidgetPos, xsize/3, GetTextHeight()*2), "Material");
  placeMaterialWidget->SetSizeByText();

  int xFuelRoughnessLabelPos = 0;
  if(placeFuelWidget->Width() > placeMaterialWidget->Width()) {
    xFuelRoughnessLabelPos = xFuelWidgetPos + placeFuelWidget->Width() + xOffSet;
  } else {
    xFuelRoughnessLabelPos = xFuelWidgetPos + placeMaterialWidget->Width() + xOffSet;
  }
  fuelRoughnessLabel = new PG_Label(this, PG_Rect(xFuelRoughnessLabelPos, yFuelWidgetPos , 40, hFuelWidget), "Fuel Roughness: ");
  fuelRoughnessLabel->SetSizeByText();

  materialRoughnessLabel = new PG_Label(this, PG_Rect(xFuelRoughnessLabelPos, yMaterialWidgetPos , 40, hFuelWidget), "Material Roughness: ");
  materialRoughnessLabel->SetSizeByText();

  int xFuelRoughnessWidgetPos = 0;
  if(fuelRoughnessLabel->Width() > materialRoughnessLabel->Width()) {
    xFuelRoughnessWidgetPos = xFuelRoughnessLabelPos + fuelRoughnessLabel->Width();
  } else {
    xFuelRoughnessWidgetPos = xFuelRoughnessLabelPos + materialRoughnessLabel->Width();
  }
  fuelRoughnessWidget = new PG_LineEdit ( this, PG_Rect(xFuelRoughnessWidgetPos, yFuelWidgetPos, xsize - ( xFuelRoughnessLabelPos + fuelRoughnessLabel->Width() + xOffSet), hFuelWidget));
  fuelRoughnessWidget->SetValidKeys("1234567890.");
  fuelRoughnessWidget->SetText("1.0");



  materialRoughnessWidget = new PG_LineEdit ( this, PG_Rect(xFuelRoughnessWidgetPos, yMaterialWidgetPos, xsize - ( xFuelRoughnessLabelPos + fuelRoughnessLabel->Width() + xOffSet), hFuelWidget));
  materialRoughnessWidget->SetValidKeys("1234567890.");
  materialRoughnessWidget->SetText("1.0");



  int yFuelOffSetLabelPos = yMaterialWidgetPos + hFuelWidget + yOffSet;
  fuelOffSetLabel = new PG_Label(this, PG_Rect(xFuelWidgetPos, yFuelOffSetLabelPos, 40, hFuelWidget), "Fuel Offset: ");
  fuelOffSetLabel->SetSizeByText();

  int xFuelOffSetValue = xFuelWidgetPos + fuelOffSetLabel->Width();
  fuelOffSetValue = new PG_LineEdit(this, PG_Rect(xFuelOffSetValue, yFuelOffSetLabelPos, 40, hFuelWidget));
  fuelOffSetValue->SetText(ASCString::toString(ResourcePlacement::MAXFUELVALUE));
  fuelOffSetValue->SetValidKeys("1234567890");
  fuelOffSetValue->SetEditable(false);

  int yFuelOffSetSliderPos = int(yFuelOffSetLabelPos + hFuelWidget * 1.5);
  fuelOffSetSlider = new PG_Slider(this, PG_Rect(xFuelWidgetPos, yFuelOffSetSliderPos, xsize - (xFuelWidgetPos + leftIndent) , hFuelWidget), PG_ScrollBar::HORIZONTAL);
  fuelOffSetSlider->SetRange(ResourcePlacement::MINFUELVALUE, ResourcePlacement::MAXFUELVALUE);
  fuelOffSetSlider->SetPosition(atoi(fuelOffSetValue->GetText()));
  fuelOffSetSlider->sigSlide.connect(sigc::mem_fun(*this, &ResourcePlacementDialog::scrollTrackEventFuel));


  //MaterialOffSet
  int yMaterialOffSetLabelPos = yFuelOffSetSliderPos + hFuelWidget;
  materialOffSetLabel = new PG_Label(this, PG_Rect(xFuelWidgetPos, yMaterialOffSetLabelPos, 40, hFuelWidget), "Material Offset: ");
  materialOffSetLabel->SetSizeByText();

  int xMaterialOffSetValue = xFuelWidgetPos + materialOffSetLabel->Width();
  materialOffSetValue = new PG_LineEdit(this, PG_Rect(xMaterialOffSetValue, yMaterialOffSetLabelPos, 40, hFuelWidget));
  materialOffSetValue->SetText(ASCString::toString(ResourcePlacement::MAXMATERIALVALUE));
  materialOffSetValue->SetValidKeys("1234567890");
  materialOffSetValue->SetEditable(false);

  int yMaterialOffSetSliderPos = int(yMaterialOffSetLabelPos + hFuelWidget * 1.5);
  materialOffSetSlider = new PG_Slider(this, PG_Rect(xFuelWidgetPos, yMaterialOffSetSliderPos, xsize - (xFuelWidgetPos + leftIndent) , hFuelWidget), PG_ScrollBar::HORIZONTAL);
  materialOffSetSlider->SetRange(ResourcePlacement::MINMATERIALVALUE, ResourcePlacement::MAXMATERIALVALUE);
  materialOffSetSlider->SetPosition(atoi(materialOffSetValue->GetText()));
  materialOffSetSlider->sigSlide.connect(sigc::mem_fun(*this, &ResourcePlacementDialog::scrollTrackEventMaterial));

  //FuelFreeRatio
  int yFuelFreeRatioLabelPos = yMaterialOffSetSliderPos + hFuelWidget + yOffSet;
  fuelFreeRatioLabel = new PG_Label(this, PG_Rect(xFuelWidgetPos, yFuelFreeRatioLabelPos, 40, hFuelWidget), "Fuel Free Fields Ratio: ");
  fuelFreeRatioLabel->SetSizeByText();
  
  int xFuelFreeRatioValue = xFuelWidgetPos + fuelFreeRatioLabel->Width();
  fuelFreeRatioValue = new PG_LineEdit(this, PG_Rect(xFuelFreeRatioValue, yFuelFreeRatioLabelPos, 40, hFuelWidget));
  fuelFreeRatioValue->SetText(ASCString::toString(0));
  fuelFreeRatioValue->SetValidKeys("1234567890");
  fuelFreeRatioValue->SetEditable(false);
  
  int yFuelFreeRatioSliderPos = int(yFuelFreeRatioLabelPos + hFuelWidget * 1.5);
  fuelFreeRatioSlider = new PG_Slider(this, PG_Rect(xFuelWidgetPos, yFuelFreeRatioSliderPos, xsize - (xFuelWidgetPos + leftIndent) , hFuelWidget), PG_ScrollBar::HORIZONTAL);
  fuelFreeRatioSlider->SetRange(0, 100);
  fuelFreeRatioSlider->SetPosition(atoi(fuelFreeRatioValue->GetText()));
  fuelFreeRatioSlider->sigSlide.connect(sigc::mem_fun(*this, &ResourcePlacementDialog::scrollTrackEventFuelFreeRatio));
  
  //MaterialFreeRatio
  int yMaterialFreeRatioLabelPos = yFuelFreeRatioSliderPos + hFuelWidget ;
  materialFreeRatioLabel = new PG_Label(this, PG_Rect(xFuelWidgetPos, yMaterialFreeRatioLabelPos, 40, hFuelWidget), "Material Free Fields Ratio: ");
  materialFreeRatioLabel->SetSizeByText();
  
  int xMaterialFreeRatioValue = xFuelWidgetPos + materialFreeRatioLabel->Width();
  materialFreeRatioValue = new PG_LineEdit(this, PG_Rect(xMaterialFreeRatioValue, yMaterialFreeRatioLabelPos, 40, hFuelWidget));
  materialFreeRatioValue->SetText(ASCString::toString(0));
  materialFreeRatioValue->SetValidKeys("1234567890");
  materialFreeRatioValue->SetEditable(false);
  
  int yMaterialFreeRatioSliderPos = int(yMaterialFreeRatioLabelPos + hFuelWidget * 1.5);
  materialFreeRatioSlider = new PG_Slider(this, PG_Rect(xFuelWidgetPos, yMaterialFreeRatioSliderPos, xsize - (xFuelWidgetPos + leftIndent) , hFuelWidget), PG_ScrollBar::HORIZONTAL);
  materialFreeRatioSlider->SetRange(0, 100);
  materialFreeRatioSlider->SetPosition(atoi(materialFreeRatioValue->GetText()));
  materialFreeRatioSlider->sigSlide.connect(sigc::mem_fun(*this, &ResourcePlacementDialog::scrollTrackEventMaterialFreeRatio));
  
  //Buttons OK and Cancel

  (new PG_Button(this, PG_Rect(30, Height()-40, (Width()-70)/2, 30), "OK", 100))->sigClick.connect( sigc::mem_fun( *this, &ResourcePlacementDialog::buttonEvent ));
  (new PG_Button(this, PG_Rect(Width()/2+5, Height()-40, (Width()-70)/2, 30), "Cancel", 101))->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &ResourcePlacementDialog::closeWindow )));

  sigClose.connect( sigc::mem_fun( *this, &ResourcePlacementDialog::closeWindow ));
}



bool ResourcePlacementDialog::buttonEvent( PG_Button* button ) {
  if((atof(fuelRoughnessWidget->GetText())<=0) || (atof(fuelRoughnessWidget->GetText())>=4) ||
      (atof(materialRoughnessWidget->GetText())<=0) || (atof(materialRoughnessWidget->GetText())>=4)) {
     d = new PG_MessageBox(this, PG_Rect(0,0, Width()/2, int(Height()* 0.75)), "Error Report", "Condition 0.0 < roughness < 4.0 not met", PG_Rect(Width()/4 - 25, int(Height()*0.75) - 30, 50, 30), "OK");
    d->Show();
  
    return true;
  } else {
    quitModalLoop(1);
    ResourcePlacement rp (*actmap , atof(fuelRoughnessWidget->GetText()), atof(materialRoughnessWidget->GetText()), atoi(fuelOffSetValue->GetText()), atoi(materialOffSetValue->GetText()), 0, atoi(materialFreeRatioValue->GetText()));

    if((placeFuelWidget->GetPressed()) && (placeMaterialWidget->GetPressed())) {
      rp.placeResources();
    } else if(placeFuelWidget->GetPressed()) {
      rp.placeFuelResources();
    } else if(placeMaterialWidget->GetPressed()) {
      rp.placeMaterialResources();
    }
    return true;
  }
}



bool ResourcePlacementDialog::scrollTrackEventMaterial(long data) {
  materialOffSetValue->SetText( ASCString::toString( (int) data));
  return true;
}

bool ResourcePlacementDialog::scrollTrackEventFuel(long data) {
  fuelOffSetValue->SetText( ASCString::toString( (int) data ));
  return true;
}


bool ResourcePlacementDialog::scrollTrackEventMaterialFreeRatio(long data){
   materialFreeRatioValue->SetText( ASCString::toString((int)data));
  return true;
}


bool ResourcePlacementDialog::scrollTrackEventFuelFreeRatio(long data){
  fuelFreeRatioValue->SetText(ASCString::toString((int)data));
  return true;
}

bool ResourcePlacementDialog::buttonErrorOkEvent( PG_Button* button ){
  quitModalLoop(1);
  return true;
}

void resourcePlacementDialog() {
  ResourcePlacementDialog rpd;
  rpd.Show();
  rpd.RunModal();
}