00001
00002
00003
00004
00005
00006
00007 #ifndef _SO_ENGINE_DIALOG_VIEWER_H
00008 #define _SO_ENGINE_DIALOG_VIEWER_H
00009
00010
00011 #include <DialogViz/SoDialogVizAll.h>
00012 #include <Inventor/STL/list>
00013 #include <Inventor/misc/SoRefCounter.h>
00014
00015 #include <ImageViz/Engines/SoImageVizEngine.h>
00016 #include <ImageViz/Fields/SoMFDataMeasure.h>
00017 #include <ImageViz/Fields/SoSFImageDataAdapter.h>
00018 #include <ImageViz/Fields/SoSFAnalysisResult.h>
00019 #include <Inventor/fields/SoSFString.h>
00020 #include <Inventor/fields/SoSFVec2f.h>
00021
00022
00023 class SoEngineDialogViewer : public SoRefCounter
00024 {
00025 public:
00027 SoEngineDialogViewer()
00028 :m_mainWindow(NULL)
00029 {
00030 SoDialogViz::init();
00031 m_topLevelDialog = new SoTopLevelDialog();
00032 m_topLevelDialog->ref();
00033 m_topLevelDialog->label = "ImageViz Engine control";
00034 }
00035
00036 void show(Widget mainWindow)
00037 {
00038 m_mainWindow = mainWindow;
00039 m_topLevelDialog->buildDialog(m_mainWindow, FALSE);
00040 m_topLevelDialog->show();
00041 }
00042
00043 void hide()
00044 {
00045 m_topLevelDialog->hide();
00046 m_topLevelDialog->close();
00047 m_topLevelDialog = NULL;
00048 m_mainWindow = NULL;
00049 }
00050
00051 void addDialogInterface(SoImageVizEngine* computeModule);
00052
00053 private:
00055 ~SoEngineDialogViewer()
00056 {
00057 if( m_topLevelDialog !=NULL)
00058 {
00059 m_topLevelDialog->hide();
00060 m_topLevelDialog->close();
00061 m_topLevelDialog = NULL;
00062 }
00063 cleanupModuleList();
00064 SoDialogViz::finish();
00065 }
00066 private:
00067 void cleanupModuleList();
00068 std::list<SoImageVizEngine*> m_computeModuleList;
00069 SoTopLevelDialog* m_topLevelDialog;
00070 Widget m_mainWindow;
00071 };
00072
00073
00074 void SoEngineDialogViewer::cleanupModuleList()
00075 {
00076 std::list<SoImageVizEngine*>::const_iterator it = m_computeModuleList.begin();
00077 while (it != m_computeModuleList.end())
00078 {
00079 (*it)->unref();
00080 ++it;
00081 }
00082 }
00083
00084 class Vec2TextEditAuditor : public SoDialogEditTextAuditor
00085 {
00086 public:
00087
00088 Vec2TextEditAuditor(SoSFVec2f* connectedField)
00089 :m_vec2fField(connectedField)
00090 {}
00091 private:
00092 virtual void dialogEditText(SoDialogEditText* cpt)
00093 {
00094
00095 SbString curValueString = cpt->editText.getValue();
00096 std::vector<SbString> splitString;
00097 curValueString.split(splitString);
00098
00099 if (splitString.size()!=2)
00100 return;
00101
00102 SbVec2f curValuevec;
00103 curValuevec[0] = splitString[0].toFloat();
00104 curValuevec[1] = splitString[1].toFloat();
00105
00106
00107 m_vec2fField->setValue(curValuevec);
00108
00109 }
00110 private:
00111 SoSFVec2f* m_vec2fField;
00112 };
00113
00114
00115
00116 void SoEngineDialogViewer::addDialogInterface(SoImageVizEngine* computeModule)
00117 {
00118 if ( computeModule == NULL)
00119 return;
00120
00121
00122 SoDialogSeparator* dialogSeparator = new SoDialogSeparator();
00123 m_topLevelDialog->addChild(dialogSeparator);
00124
00125 SoDialogLabel* dialogLabel = new SoDialogLabel();
00126 dialogLabel->label = SbString(computeModule->getTypeId().getName().getString());
00127 m_topLevelDialog->addChild(dialogLabel);
00128
00129 SoRowDialog* rowDialog = new SoRowDialog;
00130 m_topLevelDialog->addChild(rowDialog);
00131
00132
00133 const SoFieldData *fieldData = computeModule->getFieldData();
00134 SoFieldList fieldList;
00135 computeModule->getFields(fieldList);
00136 for (int i=0; i<fieldData->getNumFields();++i)
00137 {
00138 SoField* curField = fieldList.get(i);
00139
00140
00141 SoColumnDialog* columnDialog = new SoColumnDialog();
00142 rowDialog->addChild(columnDialog);
00143
00144
00145 SoDialogLabel* fieldNameLabel = new SoDialogLabel;
00146 fieldNameLabel->label.setValue(fieldData->getFieldName(i).getString() );
00147 columnDialog->addChild(fieldNameLabel);
00148
00149
00150 if ( curField->isOfType(SoSFFloat::getClassTypeId()) )
00151 {
00152
00153 SoSFFloat* floatField = dynamic_cast<SoSFFloat*>(curField);
00154 SoDialogRealSlider* floatSlider = new SoDialogRealSlider();
00155 floatSlider->fixedLimits = FALSE;
00156 floatSlider->min.setValue(0.f);
00157 floatSlider->max.setValue(255.f);
00158 floatSlider->value.setValue(floatField->getValue());
00159
00160
00161
00162 floatField->connectFrom(&floatSlider->value, FALSE, FALSE);
00163
00164 columnDialog->addChild(floatSlider);
00165 }
00166 else if ( curField->isOfType(SoSFInt32::getClassTypeId()) )
00167 {
00168
00169 SoSFInt32* intField = dynamic_cast<SoSFInt32*>(curField);
00170 SoDialogIntegerSlider* integerSlider = new SoDialogIntegerSlider();
00171 integerSlider->fixedLimits = FALSE;
00172 integerSlider->min.setValue(0);
00173 integerSlider->max.setValue(255);
00174 integerSlider->value.setValue(intField->getValue());
00175
00176
00177
00178 intField->connectFrom(&integerSlider->value, FALSE, FALSE);
00179
00180 columnDialog->addChild(integerSlider);
00181 }
00182 else if ( curField->isOfType(SoSFVec2f::getClassTypeId()) )
00183 {
00184
00185 SoSFVec2f* vec2fField = dynamic_cast<SoSFVec2f*>(curField);
00186
00187 SoDialogEditText* vec2fEdit = new SoDialogEditText();
00188 SbString vec2fString;
00189 vec2fField->get(vec2fString);
00190 vec2fEdit->editText.setValue(vec2fString);
00191
00192
00193
00194
00195
00196 Vec2TextEditAuditor* vec2TextAuditor = new Vec2TextEditAuditor(vec2fField);
00197 vec2fEdit->addAuditor(vec2TextAuditor);
00198
00199 columnDialog->addChild(vec2fEdit);
00200 }
00201 else if ( curField->isOfType(SoSFEnum::getClassTypeId()) )
00202 {
00203
00204 SoSFEnum* enumField = dynamic_cast<SoSFEnum*>(curField);
00205
00206 SoDialogComboBox* enumCombo = new SoDialogComboBox();
00207
00208 {
00209 int* vals=NULL;
00210 SbName* names=NULL;
00211 int num = 0;
00212 enumField->getEnums(num, vals, names);
00213 for (int i=0;i<num;++i)
00214 enumCombo->items.set1Value(vals[i],names[i].getString());
00215 }
00216
00217 enumCombo->selectedItem = enumField->getValue();
00218
00219
00220
00221 enumField->connectFrom(&enumCombo->selectedItem, FALSE, FALSE);
00222
00223 columnDialog->addChild(enumCombo);
00224 }
00225 else if ( curField->isOfType(SoSFString::getClassTypeId()) )
00226 {
00227
00228 SoSFString* stringField = dynamic_cast<SoSFString*>(curField);
00229
00230 SoDialogEditText* stringEdit = new SoDialogEditText();
00231 stringEdit->editText.setValue(stringField->getValue());
00232
00233
00234 stringField->connectFrom(&stringEdit->editText, FALSE, FALSE);
00235
00236 columnDialog->addChild(stringEdit);
00237 }
00238 else if ( curField->isOfType(SoSFAnalysisResult::getClassTypeId()) )
00239 {
00240
00241 rowDialog->removeChild(rowDialog->getNumChildren()-1);
00242 }
00243 else if ( curField->isOfType(SoSFImageDataAdapter::getClassTypeId()) )
00244 {
00245
00246 rowDialog->removeChild(rowDialog->getNumChildren()-1);
00247 }
00248 else if ( curField->isOfType(SoMFDataMeasure::getClassTypeId()) )
00249 {
00250
00251 rowDialog->removeChild(rowDialog->getNumChildren()-1);
00252 }
00253 else
00254 {
00255
00256 SoDialogLabel* fieldValueLabel = new SoDialogLabel;
00257 SbString fieldValueString;
00258 curField->get(fieldValueString);
00259 fieldValueLabel->label.setValue(fieldValueString);
00260 columnDialog->addChild(fieldValueLabel);
00261 }
00262 }
00263
00264 computeModule->ref();
00265 m_computeModuleList.push_back(computeModule);
00266 }
00267
00268 #endif //_SO_ENGINE_DIALOG_VIEWER_H
00269