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