00001
00002
00003
00004
00005
00006
00007
00008 #ifndef _SO_DIALOG_SPREADSHEET_H_
00009 #define _SO_DIALOG_SPREADSHEET_H_
00010
00011 #include <DialogViz/SoDialogVizAll.h>
00012 #include <Inventor/fields/SoFieldContainer.h>
00013 #include <Inventor/fields/SoSubFieldContainer.h>
00014
00015 #include <Inventor/sensors/SoOneShotSensor.h>
00016
00017 #include <ImageViz/Fields/SoSFLabelAnalysisResult.h>
00018 #include <ImageViz/Nodes/Analysis/SoLabelAnalysisResult.h>
00019
00020
00021
00022 class SoDialogSpreadSheet : public SoFieldContainer
00023 {
00024 SO_FIELDCONTAINER_HEADER(SoDialogSpreadSheet);
00025 public:
00026 SoDialogSpreadSheet()
00027 :m_mainWindow(NULL), m_topLevelDialog(NULL), m_connectedEngine(NULL)
00028 {
00029 SO_FIELDCONTAINER_CONSTRUCTOR(SoDialogSpreadSheet);
00030 SO_FIELDCONTAINER_ADD_FIELD(spreadsheet, (NULL));
00031 }
00032
00033 SoDialogSpreadSheet(SoWidget mainWindow)
00034 :m_mainWindow(mainWindow), m_topLevelDialog(NULL), m_connectedEngine(NULL)
00035 {
00036 SO_FIELDCONTAINER_CONSTRUCTOR(SoDialogSpreadSheet);
00037 SO_FIELDCONTAINER_ADD_FIELD(spreadsheet, (NULL));
00038 }
00039
00040 SoSFLabelAnalysisResult spreadsheet;
00041 private:
00042 virtual void notify(SoNotList* list)
00043 {
00044 if ((list->getLastRec()->getType() == SoNotRec::CONTAINER))
00045 {
00046 if ( list->getLastField() == &spreadsheet )
00047 {
00048 bool firstTime = false;
00049 SoImageVizEngine* engine = NULL;
00050 SoEngineOutput* output = NULL;
00051 if ( spreadsheet.getConnectedEngine( output ) )
00052 engine = dynamic_cast<SoImageVizEngine*>( output->getContainer() );
00053
00054 if ( m_connectedEngine != engine )
00055 {
00056 firstTime = true;
00057 if ( m_connectedEngine != NULL )
00058 m_connectedEngine->onEnd.remove( *this, &SoDialogSpreadSheet::updateAfterCompute );
00059
00060 m_connectedEngine = engine;
00061 if ( m_connectedEngine != NULL )
00062 m_connectedEngine->onEnd.add( *this, &SoDialogSpreadSheet::updateAfterCompute );
00063 }
00064
00065 if ( m_connectedEngine != NULL )
00066 {
00067 m_connectedEngine->startEvaluate();
00068
00069 if( firstTime && !m_connectedEngine->isEvaluating() )
00070 updateDialog();
00071 }
00072 else if ( spreadsheet.getDirty() )
00073 updateDialog();
00074 }
00075 }
00076
00077 SoFieldContainer::notify(list);
00078 }
00079 private:
00080
00081 static void callBackUpdate(void* data, SoSensor* sensor)
00082 {
00083 ((SoDialogSpreadSheet*)data)->updateDialog();
00084 delete sensor;
00085 }
00086
00087 void updateAfterCompute(SoImageVizEngine::EventArg &arg)
00088 {
00089 if (arg.getProgress() == 1.0f)
00090 {
00091 SoOneShotSensor* sensor = new SoOneShotSensor(SoDialogSpreadSheet::callBackUpdate, this);
00092 sensor->schedule();
00093 }
00094 }
00095
00096 void updateDialog()
00097 {
00098 SoLabelAnalysisResult* anl = spreadsheet.getValue();
00099
00100
00101 if ( m_topLevelDialog != NULL )
00102 {
00103 m_topLevelDialog->removeAllChildren();
00104 m_topLevelDialog->close();
00105 m_topLevelDialog = NULL;
00106 }
00107
00108
00109 {
00110 m_topLevelDialog = new SoTopLevelDialog();
00111 m_topLevelDialog->ref();
00112 m_topLevelDialog->label.setValue( "ImageViz spreadsheet analysis" );
00113 m_topLevelDialog->resizable = TRUE;
00114 m_topLevelDialog->windowResizedByChildren = FALSE;
00115 m_topLevelDialog->vScrollVisibility = SoTopLevelDialog::ALWAYS;
00116 m_topLevelDialog->hScrollVisibility = SoTopLevelDialog::ALWAYS;
00117 }
00118
00119 if ( anl != NULL )
00120 {
00121
00122 SoMenuBar* menu = new SoMenuBar();
00123 m_topLevelDialog->addChild( menu );
00124
00125
00126 SoColumnDialog* m_mainSheet = new SoColumnDialog();
00127 m_mainSheet->windowResizedByChildren = FALSE;
00128 m_mainSheet->fixedHeight = FALSE;
00129 m_topLevelDialog->addChild( m_mainSheet );
00130
00131 int nCols = anl->getNumMeasure();
00132 size_t realnRows = anl->getNumLabels();
00133 size_t nRows = realnRows;
00134
00135
00136
00137
00138
00139 if ( realnRows > 255 )
00140 {
00141 SoDebugError::postWarning( "SoDialogSpreadSheet", "Only the first 255 rows will be displayed" );
00142 nRows = 255;
00143 }
00144
00145
00146 {
00147 SoRowDialog* currentColumn = new SoRowDialog();
00148 m_mainSheet->addChild( currentColumn );
00149
00150
00151
00152 {
00153 SoColumnDialog* cellDiag = new SoColumnDialog();
00154 SoDialogLabel* dialogLabel = new SoDialogLabel();
00155 dialogLabel->label.setValue( "LabelId" );
00156 cellDiag->addChild( dialogLabel );
00157 currentColumn->addChild( cellDiag );
00158 }
00159
00160 for ( size_t j = 0; j < nRows; ++j )
00161 {
00162 SoColumnDialog* cellDiag = new SoColumnDialog();
00163 SoDialogLabel* dialogLabel = new SoDialogLabel();
00164 dialogLabel->label.setValue( SbString( ( int )( j ) ) );
00165 cellDiag->addChild( dialogLabel );
00166 currentColumn->addChild( cellDiag );
00167 }
00168 }
00169
00170
00171 for ( int i = 0; i < nCols; ++i )
00172
00173 {
00174 SoRowDialog* currentColumn = new SoRowDialog();
00175 m_mainSheet->addChild( currentColumn );
00176 int nbComp = anl->getNumMeasureComponent( i );
00177 SbString cellValue = anl->getMeasureName( i );
00178
00179
00180 for ( size_t j = 0; j < nRows; ++j )
00181 {
00182 for ( int comp = 0; comp < nbComp; ++comp )
00183 {
00184
00185 if ( j == 0 )
00186 {
00187 SbString columnName = anl->getMeasureName( i );
00188
00189 if ( nbComp > 1 )
00190 {
00191 columnName += "(component ";
00192 columnName += comp;
00193 columnName += ")";
00194 }
00195
00196
00197 {
00198 SoColumnDialog* cellDiag = new SoColumnDialog();
00199 SoDialogLabel* dialogLabel = new SoDialogLabel();
00200 dialogLabel->label.setValue( columnName );
00201 cellDiag->addChild( dialogLabel );
00202 currentColumn->addChild( cellDiag );
00203 }
00204 }
00205
00206 SbString cellValue;
00207
00208 switch ( anl->getMeasureFormat( i ) )
00209 {
00210 case SoDataMeasure::INT:
00211 case SoDataMeasure::FLOAT:
00212 {
00213 cellValue += anl->getValueAsString( ( int )( j ), i, comp );
00214 break;
00215 }
00216 case SoDataMeasure::STRING:
00217 default:
00218 {
00219 cellValue += "\"";
00220 cellValue += anl->getValueAsString( ( int )( j ), i, comp );
00221 cellValue += "\"";
00222 break;
00223 }
00224 }
00225
00226
00227 SoColumnDialog* cellDiag = new SoColumnDialog();
00228 SoDialogLabel* dialogLabel = new SoDialogLabel();
00229 dialogLabel->label.setValue( cellValue );
00230 cellDiag->addChild( dialogLabel );
00231 currentColumn->addChild( cellDiag );
00232 }
00233 }
00234 }
00235
00236 m_topLevelDialog->buildDialog( m_mainWindow, FALSE );
00237 m_topLevelDialog->show();
00238 }
00239 }
00240
00241 SoWidget m_mainWindow;
00242 SoTopLevelDialog* m_topLevelDialog;
00243 SoImageVizEngine* m_connectedEngine;
00244 };
00245
00246 SO_FIELDCONTAINER_SOURCE(SoDialogSpreadSheet);
00247 void SoDialogSpreadSheet::initClass()
00248 { SO_FIELDCONTAINER_INIT_CLASS(SoDialogSpreadSheet,"SoDialogSpreadSheet",SoFieldContainer); }
00249
00250 void SoDialogSpreadSheet::exitClass()
00251 {
00252 SO__FIELDCONTAINER_EXIT_CLASS(SoDialogSpreadSheet);
00253 }
00254
00255 #endif // _SO_DIALOG_SPREADSHEET_H_
00256