00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <iostream>
00021 #include "resourceplacement.h"
00022
00023 #include "resourceplacementdialog.h"
00024 #include "spfst.h"
00025 #include "spfst-legacy.h"
00026
00027
00028 const int ResourcePlacementDialog::xsize = 400;
00029 const int ResourcePlacementDialog::ysize = 612;
00030 const int ResourcePlacementDialog::xOffSet = xsize/10;
00031 const int ResourcePlacementDialog::yOffSet = ysize/20;
00032 const int ResourcePlacementDialog::leftIndent = xsize/50;;
00033
00034
00035 ResourcePlacementDialog::ResourcePlacementDialog( ) :
00036 ASC_PG_Dialog(NULL, PG_Rect( 100,100, xsize, ysize ), "Place Resources", SHOW_CLOSE ),
00037 fuelRoughness(1), materialRoughness(1), maxFuelOffSet(100), maxMaterialOffSet(100),
00038 fuelRoughnessWidget(NULL), materialRoughnessWidget(NULL), fuelOffsetWidget(NULL), materialOffsetWidget(NULL), d(0)
00039 {
00040 int xFuelWidgetPos = leftIndent;
00041 int yFuelWidgetPos = ysize/10;
00042 int hFuelWidget = GetTextHeight() + 10;
00043 placeFuelWidget = new PG_CheckButton(this, PG_Rect(xFuelWidgetPos, yFuelWidgetPos, xsize/3 , GetTextHeight()*2), "Fuel");
00044 placeFuelWidget->SetSizeByText();
00045
00046
00047
00048 int xMaterialWidgetPos = xFuelWidgetPos;
00049 int yMaterialWidgetPos = yFuelWidgetPos + hFuelWidget;
00050 placeMaterialWidget = new PG_CheckButton(this, PG_Rect(xMaterialWidgetPos, yMaterialWidgetPos, xsize/3, GetTextHeight()*2), "Material");
00051 placeMaterialWidget->SetSizeByText();
00052
00053 int xFuelRoughnessLabelPos = 0;
00054 if(placeFuelWidget->Width() > placeMaterialWidget->Width()) {
00055 xFuelRoughnessLabelPos = xFuelWidgetPos + placeFuelWidget->Width() + xOffSet;
00056 } else {
00057 xFuelRoughnessLabelPos = xFuelWidgetPos + placeMaterialWidget->Width() + xOffSet;
00058 }
00059 fuelRoughnessLabel = new PG_Label(this, PG_Rect(xFuelRoughnessLabelPos, yFuelWidgetPos , 40, hFuelWidget), "Fuel Roughness: ");
00060 fuelRoughnessLabel->SetSizeByText();
00061
00062 materialRoughnessLabel = new PG_Label(this, PG_Rect(xFuelRoughnessLabelPos, yMaterialWidgetPos , 40, hFuelWidget), "Material Roughness: ");
00063 materialRoughnessLabel->SetSizeByText();
00064
00065 int xFuelRoughnessWidgetPos = 0;
00066 if(fuelRoughnessLabel->Width() > materialRoughnessLabel->Width()) {
00067 xFuelRoughnessWidgetPos = xFuelRoughnessLabelPos + fuelRoughnessLabel->Width();
00068 } else {
00069 xFuelRoughnessWidgetPos = xFuelRoughnessLabelPos + materialRoughnessLabel->Width();
00070 }
00071 fuelRoughnessWidget = new PG_LineEdit ( this, PG_Rect(xFuelRoughnessWidgetPos, yFuelWidgetPos, xsize - ( xFuelRoughnessLabelPos + fuelRoughnessLabel->Width() + xOffSet), hFuelWidget));
00072 fuelRoughnessWidget->SetValidKeys("1234567890.");
00073 fuelRoughnessWidget->SetText("1.0");
00074
00075
00076
00077 materialRoughnessWidget = new PG_LineEdit ( this, PG_Rect(xFuelRoughnessWidgetPos, yMaterialWidgetPos, xsize - ( xFuelRoughnessLabelPos + fuelRoughnessLabel->Width() + xOffSet), hFuelWidget));
00078 materialRoughnessWidget->SetValidKeys("1234567890.");
00079 materialRoughnessWidget->SetText("1.0");
00080
00081
00082
00083 int yFuelOffSetLabelPos = yMaterialWidgetPos + hFuelWidget + yOffSet;
00084 fuelOffSetLabel = new PG_Label(this, PG_Rect(xFuelWidgetPos, yFuelOffSetLabelPos, 40, hFuelWidget), "Fuel Offset: ");
00085 fuelOffSetLabel->SetSizeByText();
00086
00087 int xFuelOffSetValue = xFuelWidgetPos + fuelOffSetLabel->Width();
00088 fuelOffSetValue = new PG_LineEdit(this, PG_Rect(xFuelOffSetValue, yFuelOffSetLabelPos, 40, hFuelWidget));
00089 fuelOffSetValue->SetText(int2String(ResourcePlacement::MAXFUELVALUE));
00090 fuelOffSetValue->SetValidKeys("1234567890");
00091 fuelOffSetValue->SetEditable(false);
00092
00093 int yFuelOffSetSliderPos = int(yFuelOffSetLabelPos + hFuelWidget * 1.5);
00094 fuelOffSetSlider = new PG_Slider(this, PG_Rect(xFuelWidgetPos, yFuelOffSetSliderPos, xsize - (xFuelWidgetPos + leftIndent) , hFuelWidget), PG_ScrollBar::HORIZONTAL);
00095 fuelOffSetSlider->SetRange(ResourcePlacement::MINFUELVALUE, ResourcePlacement::MAXFUELVALUE);
00096 fuelOffSetSlider->SetPosition(atoi(fuelOffSetValue->GetText()));
00097 fuelOffSetSlider->sigSlide.connect(slot(*this, &ResourcePlacementDialog::scrollTrackEventFuel));
00098
00099
00100
00101 int yMaterialOffSetLabelPos = yFuelOffSetSliderPos + hFuelWidget;
00102 materialOffSetLabel = new PG_Label(this, PG_Rect(xFuelWidgetPos, yMaterialOffSetLabelPos, 40, hFuelWidget), "Material Offset: ");
00103 materialOffSetLabel->SetSizeByText();
00104
00105 int xMaterialOffSetValue = xFuelWidgetPos + materialOffSetLabel->Width();
00106 materialOffSetValue = new PG_LineEdit(this, PG_Rect(xMaterialOffSetValue, yMaterialOffSetLabelPos, 40, hFuelWidget));
00107 materialOffSetValue->SetText(int2String(ResourcePlacement::MAXMATERIALVALUE));
00108 materialOffSetValue->SetValidKeys("1234567890");
00109 materialOffSetValue->SetEditable(false);
00110
00111 int yMaterialOffSetSliderPos = int(yMaterialOffSetLabelPos + hFuelWidget * 1.5);
00112 materialOffSetSlider = new PG_Slider(this, PG_Rect(xFuelWidgetPos, yMaterialOffSetSliderPos, xsize - (xFuelWidgetPos + leftIndent) , hFuelWidget), PG_ScrollBar::HORIZONTAL);
00113 materialOffSetSlider->SetRange(ResourcePlacement::MINMATERIALVALUE, ResourcePlacement::MAXMATERIALVALUE);
00114 materialOffSetSlider->SetPosition(atoi(materialOffSetValue->GetText()));
00115 materialOffSetSlider->sigSlide.connect(slot(*this, &ResourcePlacementDialog::scrollTrackEventMaterial));
00116
00117
00118 int yFuelFreeRatioLabelPos = yMaterialOffSetSliderPos + hFuelWidget + yOffSet;
00119 fuelFreeRatioLabel = new PG_Label(this, PG_Rect(xFuelWidgetPos, yFuelFreeRatioLabelPos, 40, hFuelWidget), "Fuel Free Fields Ratio: ");
00120 fuelFreeRatioLabel->SetSizeByText();
00121
00122 int xFuelFreeRatioValue = xFuelWidgetPos + fuelFreeRatioLabel->Width();
00123 fuelFreeRatioValue = new PG_LineEdit(this, PG_Rect(xFuelFreeRatioValue, yFuelFreeRatioLabelPos, 40, hFuelWidget));
00124 fuelFreeRatioValue->SetText(int2String(0));
00125 fuelFreeRatioValue->SetValidKeys("1234567890");
00126 fuelFreeRatioValue->SetEditable(false);
00127
00128 int yFuelFreeRatioSliderPos = int(yFuelFreeRatioLabelPos + hFuelWidget * 1.5);
00129 fuelFreeRatioSlider = new PG_Slider(this, PG_Rect(xFuelWidgetPos, yFuelFreeRatioSliderPos, xsize - (xFuelWidgetPos + leftIndent) , hFuelWidget), PG_ScrollBar::HORIZONTAL);
00130 fuelFreeRatioSlider->SetRange(0, 100);
00131 fuelFreeRatioSlider->SetPosition(atoi(fuelFreeRatioValue->GetText()));
00132 fuelFreeRatioSlider->sigSlide.connect(slot(*this, &ResourcePlacementDialog::scrollTrackEventFuelFreeRatio));
00133
00134
00135 int yMaterialFreeRatioLabelPos = yFuelFreeRatioSliderPos + hFuelWidget ;
00136 materialFreeRatioLabel = new PG_Label(this, PG_Rect(xFuelWidgetPos, yMaterialFreeRatioLabelPos, 40, hFuelWidget), "Material Free Fields Ratio: ");
00137 materialFreeRatioLabel->SetSizeByText();
00138
00139 int xMaterialFreeRatioValue = xFuelWidgetPos + materialFreeRatioLabel->Width();
00140 materialFreeRatioValue = new PG_LineEdit(this, PG_Rect(xMaterialFreeRatioValue, yMaterialFreeRatioLabelPos, 40, hFuelWidget));
00141 materialFreeRatioValue->SetText(int2String(0));
00142 materialFreeRatioValue->SetValidKeys("1234567890");
00143 materialFreeRatioValue->SetEditable(false);
00144
00145 int yMaterialFreeRatioSliderPos = int(yMaterialFreeRatioLabelPos + hFuelWidget * 1.5);
00146 materialFreeRatioSlider = new PG_Slider(this, PG_Rect(xFuelWidgetPos, yMaterialFreeRatioSliderPos, xsize - (xFuelWidgetPos + leftIndent) , hFuelWidget), PG_ScrollBar::HORIZONTAL);
00147 materialFreeRatioSlider->SetRange(0, 100);
00148 materialFreeRatioSlider->SetPosition(atoi(materialFreeRatioValue->GetText()));
00149 materialFreeRatioSlider->sigSlide.connect(slot(*this, &ResourcePlacementDialog::scrollTrackEventMaterialFreeRatio));
00150
00151
00152
00153 (new PG_Button(this, PG_Rect(30, Height()-40, (Width()-70)/2, 30), "OK", 100))->sigClick.connect(SigC::slot( *this, &ResourcePlacementDialog::buttonEvent ));
00154 (new PG_Button(this, PG_Rect(Width()/2+5, Height()-40, (Width()-70)/2, 30), "Cancel", 101))->sigClick.connect(SigC::slot( *this, &ResourcePlacementDialog::closeWindow ));
00155
00156 sigClose.connect( SigC::slot( *this, &ResourcePlacementDialog::closeWindow ));
00157 }
00158
00159
00160
00161 bool ResourcePlacementDialog::buttonEvent( PG_Button* button ) {
00162 if((atof(fuelRoughnessWidget->GetText())<=0) || (atof(fuelRoughnessWidget->GetText())>=4) ||
00163 (atof(materialRoughnessWidget->GetText())<=0) || (atof(materialRoughnessWidget->GetText())>=4)) {
00164 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");
00165 d->Show();
00166
00167 return true;
00168 } else {
00169 quitModalLoop(1);
00170 ResourcePlacement rp (*actmap , atof(fuelRoughnessWidget->GetText()), atof(materialRoughnessWidget->GetText()), atoi(fuelOffSetValue->GetText()), atoi(materialOffSetValue->GetText()), 0, atoi(materialFreeRatioValue->GetText()));
00171
00172 if((placeFuelWidget->GetPressed()) && (placeMaterialWidget->GetPressed())) {
00173 rp.placeResources();
00174 } else if(placeFuelWidget->GetPressed()) {
00175 rp.placeFuelResources();
00176 } else if(placeMaterialWidget->GetPressed()) {
00177 rp.placeMaterialResources();
00178 }
00179 return true;
00180 }
00181 }
00182
00183
00184
00185 bool ResourcePlacementDialog::scrollTrackEventMaterial(long data) {
00186 materialOffSetValue->SetText( int2String(data));
00187 return true;
00188 }
00189
00190 bool ResourcePlacementDialog::scrollTrackEventFuel(long data) {
00191 stringstream s;
00192 s << data;
00193 fuelOffSetValue->SetText( s.str().c_str());
00194 return true;
00195 }
00196
00197
00198 bool ResourcePlacementDialog::scrollTrackEventMaterialFreeRatio(long data){
00199 materialFreeRatioValue->SetText( int2String(data));
00200 return true;
00201 }
00202
00203
00204 bool ResourcePlacementDialog::scrollTrackEventFuelFreeRatio(long data){
00205 fuelFreeRatioValue->SetText(int2String(data));
00206 return true;
00207 }
00208
00209 bool ResourcePlacementDialog::buttonErrorOkEvent( PG_Button* button ){
00210 quitModalLoop(1);
00211 return true;
00212 }
00213
00214 void resourcePlacementDialog() {
00215 ResourcePlacementDialog rpd;
00216 rpd.Show();
00217 rpd.RunModal();
00218 }
00219
00220
00221
00222