00001 #include "ImageCalculatorDialog.h" 00002 #include "ImageArithmaticCube.h" 00003 #include "maintoolbar.h" 00004 00005 00006 ImageCalculatorDialog::ImageCalculatorDialog(GLIMSProject *proj){ 00007 mProj = proj; 00008 calculator = new ImageCalculator(mProj); 00009 buildDialog(); 00010 00011 //this sets up the Dialog to die when closed 00012 this->setWFlags(WDestructiveClose); 00013 } 00014 00015 ImageCalculatorDialog::~ImageCalculatorDialog(){ 00016 //delete the calculator, because it's created with new 00017 if (calculator != NULL) { 00018 delete calculator; 00019 } 00020 } 00021 00022 void ImageCalculatorDialog::buildDialog(){ 00023 setCaption("Image Calculator"); 00024 00025 vbox = new QVBoxLayout(this);//overall layout 00026 00027 //holds equation line and clear button 00028 QHBox *eqbox = new QHBox(this); 00029 vbox->addWidget(eqbox); 00030 00031 //hold equation 00032 equation = new QLineEdit(eqbox); 00033 00034 //button to clear equation 00035 QPushButton *clear = new QPushButton("Clear", eqbox); 00036 QObject::connect(clear, SIGNAL(clicked()), this, SLOT(clearEquation())); 00037 00038 //holds all the keys and function boxes 00039 QHBox *keypad = new QHBox(this); 00040 keypad->setSpacing(10); 00041 00042 vbox->addWidget(keypad); 00043 00044 //TODO add in fn drop-down and band selector 00045 QVBox *selectables = new QVBox(keypad); 00046 00047 //shows all layers and theire representing variable 00048 variables = new QListBox(selectables); 00049 QObject::connect(variables, SIGNAL(doubleClicked( QListBoxItem * )), this, SLOT(insertBand(QListBoxItem * ))); 00050 variables->setMaximumHeight(100); 00051 00052 // stuff for line color selector 00053 lineStyle = new QComboBox(selectables); 00054 //QObject::connect(variables, SIGNAL(activated( int)), this, SLOT(setColor(int))); 00055 00056 00057 GLIMSLineData &mLineData = mProj->getDataset()->getLineData(); 00058 //get the linedefset - for attempt at changing line color 00059 00060 LineDefSet ldfset = mLineData.getLDFSet(); 00061 //LineDefSet &ldfset = mLineData.getLDFSet(); 00062 00063 00064 for ( int i=0; i < (int)ldfset.size(); i++ ) { 00065 //char buf[20]; 00066 LineDef &ldf = mLineData.getLDFSet()[i]; 00067 //std::string lmat = GLIMSGlobals::mGlbMDF[ldf.mLMat].id; 00068 //std::string rmat = GLIMSGlobals::mGlbMDF[ldf.mRMat].id; 00069 std::string color = GLIMSGlobals::AVAILCOLORSTR[ldf.mColor]; 00070 // std::string glactype = GLIMSGlobals::mGlbGlacTypes[ldf.mGlacType].id; 00071 std::string glactype = GLIMSGlobals::mGlbGlacTypes[ldf.mGlacType].value; 00072 // std::string segmentlbl = GLIMSGlobals::mGlbLbls[ldf.mLabel].id; 00073 std::string style = ""; 00074 //std::string type = GLIMSGlobals::mGlbTypes[ ldf.mType ].id; 00075 00076 if ( ldf.mStyle == 1 ) 00077 style = "Solid Line"; 00078 else if ( ldf.mStyle == 2 ) 00079 style = "Dash Line"; 00080 else 00081 style = "Dot Line"; 00082 00083 stringstream lineName; 00084 lineName << glactype << ", " << color << " " << style; 00085 00086 lineStyle->insertItem((lineName.str()).c_str(), i); 00087 } 00088 00089 //end stuff for color selector 00090 00091 00092 //get the band names for displaying in the ListBox 00093 ImageInterface *im = ImageInterface::getInterface(mProj); 00094 // ImageInterface *im = new ImageInterface(mProj); 00095 00096 std::vector<string> names = im->getBandNames(); 00097 00098 for(unsigned int j=0; j<names.size(); j++){ 00099 std::stringstream bandname; 00100 bandname << "b" << j; 00101 00102 bandname << " - " << names[j]; 00103 variables->insertItem((bandname.str()).c_str()); 00104 } 00105 00106 //ImageInterface::destroyInterface(); 00107 00108 //holds various functions that are handled by the parser, 00109 //but not useful enough to get their own buttons 00110 functions = new QComboBox(selectables); 00111 QObject::connect(functions, SIGNAL(activated( const QString &)), this, SLOT(acceptFunction(const QString &))); 00112 00113 functions->insertItem("sin"); 00114 functions->insertItem("cos"); 00115 functions->insertItem("tan"); 00116 functions->insertItem("asin"); 00117 functions->insertItem("acos"); 00118 functions->insertItem("atan"); 00119 functions->insertItem("sinh"); 00120 functions->insertItem("cosh"); 00121 functions->insertItem("tanh"); 00122 functions->insertItem("asinh"); 00123 functions->insertItem("acosh"); 00124 functions->insertItem("atanh"); 00125 functions->insertItem("log2"); 00126 functions->insertItem("log10"); 00127 functions->insertItem("log"); 00128 functions->insertItem("ln"); 00129 functions->insertItem("exp"); 00130 functions->insertItem("sqrt"); 00131 functions->insertItem("sign"); 00132 functions->insertItem("rint"); 00133 functions->insertItem("abs"); 00134 functions->insertItem("min"); 00135 functions->insertItem("max"); 00136 functions->insertItem("sum"); 00137 functions->insertItem("avg"); 00138 00139 00140 //operator buttons 00141 QGrid *operators = new QGrid(2, keypad); 00142 00143 ValueButton *but = new ValueButton("+", operators); 00144 but->setValue("+"); 00145 QToolTip::add(but, "Addition"); 00146 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00147 00148 00149 but = new ValueButton("^2", operators); 00150 but->setValue("^2"); 00151 QToolTip::add(but, "Squared"); 00152 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00153 00154 00155 but = new ValueButton("-", operators); 00156 but->setValue("-"); 00157 QToolTip::add(but, "Subtraction"); 00158 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00159 00160 00161 but = new ValueButton("sqrt", operators); 00162 but->setValue("sqrt"); 00163 QToolTip::add(but, "Square Root"); 00164 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptFunction(char* ))); 00165 00166 00167 but = new ValueButton("/", operators); 00168 but->setValue("/"); 00169 QToolTip::add(but, "Division"); 00170 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00171 00172 00173 but = new ValueButton("^y", operators); 00174 but->setValue("^"); 00175 QToolTip::add(but, "Power"); 00176 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00177 00178 00179 but = new ValueButton("*", operators); 00180 but->setValue("*"); 00181 QToolTip::add(but, "Multiplication"); 00182 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00183 00184 00185 but = new ValueButton("%", operators); 00186 but->setValue("%"); 00187 QToolTip::add(but, "Modulus"); 00188 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00189 00190 //the number section 00191 QGrid *numbers = new QGrid(3, keypad); 00192 00193 but = new ValueButton("1", numbers ); 00194 but->setValue("1"); 00195 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00196 00197 but = new ValueButton("2", numbers ); 00198 but->setValue("2"); 00199 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00200 00201 but = new ValueButton("3", numbers ); 00202 but->setValue("3"); 00203 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00204 00205 but = new ValueButton("4", numbers ); 00206 but->setValue("4"); 00207 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00208 00209 but = new ValueButton("5", numbers ); 00210 but->setValue("5"); 00211 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00212 00213 but = new ValueButton("6", numbers ); 00214 but->setValue("6"); 00215 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00216 00217 but = new ValueButton("7", numbers ); 00218 but->setValue("7"); 00219 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00220 00221 but = new ValueButton("8", numbers ); 00222 but->setValue("8"); 00223 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00224 00225 but = new ValueButton("9", numbers ); 00226 but->setValue("9"); 00227 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00228 00229 but = new ValueButton("( )", numbers ); 00230 but->setValue(""); 00231 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptFunction(char* ))); 00232 00233 but = new ValueButton("0", numbers ); 00234 but->setValue("0"); 00235 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00236 00237 but = new ValueButton(".", numbers ); 00238 but->setValue("."); 00239 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00240 00241 //comparitors keypad (>, =, ect) 00242 QGrid *comparitors = new QGrid(2, keypad); 00243 00244 but = new ValueButton("==", comparitors ); 00245 but->setValue("=="); 00246 QToolTip::add(but, "Equivalent"); 00247 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00248 00249 but = new ValueButton("!=", comparitors ); 00250 but->setValue("!="); 00251 QToolTip::add(but, "Not Equal"); 00252 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00253 00254 but = new ValueButton("<", comparitors ); 00255 but->setValue("<"); 00256 QToolTip::add(but, "Less Than"); 00257 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00258 00259 but = new ValueButton(">", comparitors ); 00260 but->setValue(">"); 00261 QToolTip::add(but, "Greater Than"); 00262 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00263 00264 but = new ValueButton("<=", comparitors ); 00265 but->setValue("<="); 00266 QToolTip::add(but, "Less Than or Equal To"); 00267 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00268 00269 but = new ValueButton(">=", comparitors ); 00270 but->setValue(">="); 00271 QToolTip::add(but, "Greater Than or Equal To"); 00272 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00273 00274 but = new ValueButton("and", comparitors ); 00275 but->setValue(" and "); 00276 QToolTip::add(but, "Boolean And"); 00277 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00278 00279 but = new ValueButton("or", comparitors ); 00280 but->setValue(" or "); 00281 QToolTip::add(but, "Boolean Or"); 00282 QObject::connect(but, SIGNAL(clicked(char* )), this, SLOT(acceptString(char* ))); 00283 00284 00285 00286 //the close and go buttons 00287 QHBox *buttonBox = new QHBox(this); 00288 vbox->addWidget(buttonBox); 00289 00290 00292 //holds various functions that are handled by the parser, 00293 //but not useful enough to get their own buttons 00294 algorithms = new QComboBox(buttonBox); 00295 algorithms->insertItem("Basic Drawing Algorithm"); 00296 algorithms->insertItem("Tweak 1"); 00297 algorithms->insertItem("Tweak 2"); 00298 00299 // end algo chooser 00300 00301 00302 go = new QPushButton("&Convert", buttonBox);//button to do processing 00303 QObject::connect(go, SIGNAL(clicked()), this, SLOT(doCalculation())); 00304 00305 cancel = new QPushButton("Cancel", buttonBox);//cancel 00306 QObject::connect(cancel, SIGNAL(clicked()), this, SLOT(close())); 00307 00308 } 00309 00310 void ImageCalculatorDialog::doCalculation(){ 00311 const char* temp = (equation->text()).ascii(); 00312 00314 calculator->setAlgorithm(algorithms->currentItem()) ; 00315 calculator->calculate(std::string(temp), lineStyle->currentItem()); 00316 emit imgCalcComplete() ; 00317 } 00318 00319 void ImageCalculatorDialog::clearEquation(){ 00320 equation->clear(); 00321 } 00322 00323 00324 void ImageCalculatorDialog::acceptString(char* ch){ 00325 equation->insert(ch); 00326 00327 } 00328 00329 void ImageCalculatorDialog::acceptFunction(char* ch){ 00330 QString sel = ""; 00331 00332 if(equation->hasMarkedText()) 00333 sel = equation->markedText(); 00334 00335 sel.insert(0, "("); 00336 sel.insert(0, ch); 00337 sel.append(")"); 00338 00339 equation->insert(sel); 00340 equation->setCursorPosition(equation->cursorPosition()-1); 00341 00342 } 00343 00344 void ImageCalculatorDialog::acceptFunction(const QString & ch){ 00345 QString sel = ""; 00346 00347 if(equation->hasMarkedText()) 00348 sel = equation->markedText(); 00349 00350 sel.insert(0, "("); 00351 sel.insert(0, ch); 00352 sel.append(")"); 00353 00354 equation->insert(sel); 00355 00356 equation->setCursorPosition(equation->cursorPosition()-1); 00357 00358 } 00359 00360 void ImageCalculatorDialog::insertBand(QListBoxItem * item){ 00361 QString band = item->text(); 00362 band.truncate(band.find("-")); 00363 equation->insert(band); 00364 } 00365 00366 void ImageCalculatorDialog::setColor(int index){ index++;} // just to get the compiler to stop complaining 00367 00368
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |