00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef VisuGUI_Prs3dTools_HeaderFile
00029 #define VisuGUI_Prs3dTools_HeaderFile
00030
00031 #include "VISUConfig.hh"
00032 #include "VisuGUI_Tools.h"
00033 #include "VISU_Tools.h"
00034 #include "VisuGUI_ViewTools.h"
00035 #include "VISU_ColoredPrs3dFactory.hh"
00036 #include "VISU_PipeLine.hxx"
00037 #include "VisuGUI_DialogRunner.h"
00038
00039 #include <SUIT_Desktop.h>
00040 #include <SUIT_ResourceMgr.h>
00041
00042 #include <SPlot2d_ViewWindow.h>
00043
00044 #include <vtkRenderer.h>
00045
00046 namespace VISU
00047 {
00048
00049 template<class TPrs3d_i, class TViewer, class TDlg, int TIsDlgModal>
00050 void
00051 EditPrs3d(VisuGUI* theModule,
00052 Handle(SALOME_InteractiveObject)& theIO,
00053 VISU::Prs3d_i* thePrs3d,
00054 SVTK_ViewWindow* theViewWindow)
00055 {
00056 if (TPrs3d_i* aPrs3d = dynamic_cast<TPrs3d_i*>(thePrs3d)) {
00057 bool isModal = TIsDlgModal;
00058 if( ColoredPrs3d_i* aColoredPrs3d = dynamic_cast<ColoredPrs3d_i*>(aPrs3d) )
00059 if( !aColoredPrs3d->IsTimeStampFixed() )
00060 isModal = 0;
00061
00062 TDlg* aDlg = new TDlg (theModule);
00063 aDlg->initFromPrsObject(aPrs3d, true);
00064 if (runAndWait(aDlg,isModal)) {
00065 if (!(aDlg->storeToPrsObject(aPrs3d))) {
00066 delete aDlg;
00067 return;
00068 }
00069 try {
00070 aPrs3d->UpdateActors();
00071 } catch (std::runtime_error& exc) {
00072 aPrs3d->RemoveActors();
00073
00074 INFOS(exc.what());
00075 SUIT_MessageBox::warning
00076 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
00077 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()) );
00078 }
00079 if (theViewWindow) {
00080 theViewWindow->getRenderer()->ResetCameraClippingRange();
00081 theViewWindow->Repaint();
00082 }
00083
00084 QApplication::setOverrideCursor(Qt::WaitCursor);
00085 CreateCurves( theModule,
00086 dynamic_cast<VISU::CutLinesBase_i*>( aPrs3d ),
00087 aDlg,
00088 false );
00089 QApplication::restoreOverrideCursor();
00090 }
00091 delete aDlg;
00092 }
00093 }
00094
00095
00096
00097 template<class TPrs3d_i, class TDlg, int TIsDlgModal>
00098 void
00099 EditPrs3d(VisuGUI* theModule,
00100 Handle(SALOME_InteractiveObject)& theIO,
00101 VISU::Prs3d_i* thePrs3d,
00102 SVTK_ViewWindow* theViewWindow = NULL)
00103 {
00104 SVTK_ViewWindow* aViewWindow = theViewWindow;
00105 if (!aViewWindow)
00106
00107 aViewWindow = GetViewWindow<SVTK_Viewer>(theModule);
00108 if (aViewWindow) {
00109 EditPrs3d<TPrs3d_i,SVTK_Viewer,TDlg,TIsDlgModal>(theModule, theIO, thePrs3d, aViewWindow);
00110 }
00111 }
00112
00113
00114
00115 template<class TPrs3d_i>
00116 TPrs3d_i*
00117 CreatePrs3dFromFactory(VisuGUI* theModule,
00118 _PTR(SObject) theTimeStamp,
00119 const char* theMeshName,
00120 VISU::Entity theEntity,
00121 const char* theFieldName,
00122 int theTimeId,
00123 ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode)
00124 {
00125 VISU::Result_var aResult;
00126 if (CheckResult(theModule, theTimeStamp, aResult)){
00127 QApplication::setOverrideCursor(Qt::WaitCursor);
00128 TPrs3d_i* aPrs3d = NULL;
00129 if(thePublishInStudyMode == VISU::ColoredPrs3d_i::EPublishUnderTimeStamp)
00130 aPrs3d = VISU::CreatePrs3d<TPrs3d_i>(aResult,
00131 theMeshName,
00132 theEntity,
00133 theFieldName,
00134 theTimeId);
00135 else
00136 {
00137 CORBA::Float anUsedMemory = 0.0;
00138 CORBA::Float aRequiredMemory = 0.0;
00139 VISU::ColoredPrs3dCache::EnlargeType anEnlargeType =
00140 VISU::GetRequiredCacheMemory<TPrs3d_i>(aResult,
00141 theMeshName,
00142 theEntity,
00143 theFieldName,
00144 theTimeId,
00145 anUsedMemory,
00146 aRequiredMemory);
00147
00148 if( anEnlargeType == VISU::ColoredPrs3dCache::IMPOSSIBLE )
00149 {
00150 size_t aMb = 1024 * 1024;
00151 double aFreeMemory = double(VISU_PipeLine::GetAvailableMemory(8192*(double)aMb)) / double(aMb);
00152
00153 CORBA::Float aNecessaryMemory = aRequiredMemory - aFreeMemory - anUsedMemory;
00154 SUIT_MessageBox::warning(GetDesktop(theModule),
00155 QObject::tr("WRN_VISU"),
00156 QObject::tr("ERR_NO_MEMORY_TO_BUILD").arg(aNecessaryMemory) );
00157 QApplication::restoreOverrideCursor();
00158 return NULL;
00159 }
00160 else
00161 {
00162 if( anEnlargeType == VISU::ColoredPrs3dCache::ENLARGE )
00163 {
00164 if(SUIT_MessageBox::information(GetDesktop(theModule),
00165 QObject::tr("WRN_VISU"),
00166 QObject::tr("WRN_EXTRA_MEMORY_REQUIRED").arg(aRequiredMemory),
00167 QObject::tr("&OK"), QObject::tr("&Cancel"),
00168 0, 1) == 1)
00169 {
00170 QApplication::restoreOverrideCursor();
00171 return NULL;
00172 }
00173 }
00174 aPrs3d = VISU::CreateHolder2GetDeviceByType<TPrs3d_i>(aResult,
00175 theMeshName,
00176 theEntity,
00177 theFieldName,
00178 theTimeId,
00179 anEnlargeType,
00180 aRequiredMemory);
00181 }
00182 }
00183
00184 QApplication::restoreOverrideCursor();
00185 if(aPrs3d)
00186 return aPrs3d;
00187 }
00188 SUIT_MessageBox::warning(GetDesktop(theModule),
00189 QObject::tr("WRN_VISU"),
00190 QObject::tr("ERR_CANT_BUILD_PRESENTATION") );
00191
00192 return NULL;
00193 }
00194
00195
00196
00197 template<class TPrs3d_i, class TViewer, class TDlg, int IsDlgModal>
00198 TPrs3d_i*
00199 CreateAndEditPrs3d(VisuGUI* theModule,
00200 _PTR(SObject) theTimeStamp,
00201 ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode)
00202 {
00203 Storable::TRestoringMap aRestoringMap = Storable::GetStorableMap(theTimeStamp);
00204 VISU::VISUType aType = VISU::Storable::RestoringMap2Type(aRestoringMap);
00205 if ( aType != TTIMESTAMP )
00206 return NULL;
00207
00208 QString aMeshName = aRestoringMap["myMeshName"];
00209 QString anEntity = aRestoringMap["myEntityId"];
00210 QString aFieldName = aRestoringMap["myFieldName"];
00211 QString aTimeStampId = aRestoringMap["myTimeStampId"];
00212
00213
00214 typedef typename TViewer::TViewWindow TViewWindow;
00215 TViewWindow* aViewWindow = GetViewWindow<TViewer>(theModule);
00216
00217
00218 int aPos = GetFreePositionOfDefaultScalarBar(theModule, aViewWindow);
00219 GetResourceMgr()->setValue("VISU", "scalar_bar_position_num", aPos);
00220
00221 QApplication::setOverrideCursor(Qt::WaitCursor);
00222
00223 TPrs3d_i* aPrs3d =
00224 CreatePrs3dFromFactory<TPrs3d_i>(theModule,
00225 theTimeStamp,
00226 (const char*)aMeshName.toLatin1(),
00227 (Entity)anEntity.toInt(),
00228 (const char*)aFieldName.toLatin1(),
00229 aTimeStampId.toInt(),
00230 thePublishInStudyMode);
00231
00232 QApplication::restoreOverrideCursor();
00233 if (aPrs3d) {
00234 SUIT_ResourceMgr* aResourceMgr = GetResourceMgr();
00235 int aValue = aResourceMgr->integerValue("VISU","BuildDefaultPrs3d",0);
00236 if(aResourceMgr->booleanValue("VISU","display_only",false)){
00237 theModule->OnEraseAll();
00238 SetVisibilityState(aPrs3d->GetEntry(),Qtx::ShownState);
00239 }
00240
00241 if (!aValue) {
00242 if (TDlg* aDlg = new TDlg(theModule)) {
00243 aDlg->initFromPrsObject(aPrs3d, true);
00244 if (runAndWait(aDlg,IsDlgModal) && (aDlg->storeToPrsObject(aPrs3d))) {
00245 if(aResourceMgr->booleanValue("VISU","display_only",false)){
00246 if(SPlot2d_Viewer* aPlot2d = GetPlot2dViewer(theModule, false)) aPlot2d->EraseAll();
00247 }
00248
00249 QApplication::setOverrideCursor(Qt::WaitCursor);
00250 CreateCurves( theModule,
00251 dynamic_cast<VISU::CutLinesBase_i*>( aPrs3d ),
00252 aDlg,
00253 true );
00254 UpdateObjBrowser(theModule,true,theTimeStamp);
00255 QApplication::restoreOverrideCursor();
00256 delete aDlg;
00257 } else {
00258 if ( theModule->application() )
00259 DeletePrs3d(theModule,aPrs3d);
00260 QApplication::restoreOverrideCursor();
00261 delete aDlg;
00262 return NULL;
00263 }
00264 }
00265 }
00266
00267
00268 if (aViewWindow) {
00269 PublishInView(theModule, aPrs3d, aViewWindow);
00270 if(GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)){
00271 aViewWindow->onFitAll();
00272 }
00273
00274 AddScalarBarPosition(theModule, aViewWindow, aPrs3d, aPos);
00275 }
00276
00277 return aPrs3d;
00278 }
00279
00280 return NULL;
00281 }
00282
00283
00284
00285 template<class TPrs3d_i, class TViewer, class TDlg, int IsDlgModal>
00286 TPrs3d_i*
00287 CreatePrs3dInViewer(VisuGUI* theModule,
00288 _PTR(SObject) theTimeStampSObj,
00289 ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode)
00290 {
00291 TPrs3d_i* aPrs = 0;
00292
00293 typedef typename TViewer::TViewWindow TViewWindow;
00294 if (!GetViewWindow<TViewer>(theModule))
00295 return aPrs;
00296
00297 aPrs = CreateAndEditPrs3d<TPrs3d_i,TViewer,TDlg,IsDlgModal>
00298 (theModule,theTimeStampSObj,thePublishInStudyMode);
00299
00300 theModule->application()->putInfo(QObject::tr("INF_DONE"));
00301 return aPrs;
00302 }
00303
00304
00305
00306 template<class TPrs3d_i, class TDlg, int IsDlgModal>
00307 TPrs3d_i*
00308 CreatePrs3d(VisuGUI* theModule,
00309 const QString& theDesiredViewerType = QString())
00310 {
00311 TPrs3d_i* aPrs = 0;
00312 if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule)))
00313 return aPrs;
00314
00315 _PTR(SObject) aTimeStampSObj;
00316 Handle(SALOME_InteractiveObject) anIO;
00317 ColoredPrs3d_i::EPublishInStudyMode aPublishInStudyMode;
00318 if (!CheckTimeStamp(theModule,aTimeStampSObj,anIO,aPublishInStudyMode))
00319 return aPrs;
00320
00321 if(VISU::ColoredPrs3d_i::EPublishIndependently){
00322
00323
00324 aPrs = CreatePrs3dInViewer<TPrs3d_i,SVTK_Viewer,TDlg,0>
00325 (theModule,aTimeStampSObj,aPublishInStudyMode);
00326 return aPrs;
00327 }else{
00328 if(theDesiredViewerType.isNull()){
00329 if (theModule->getApp()->activeViewManager())
00330
00331
00332
00333
00334
00335 aPrs = CreatePrs3dInViewer<TPrs3d_i,SVTK_Viewer,TDlg,IsDlgModal>
00336 (theModule,aTimeStampSObj,aPublishInStudyMode);
00337 }else{
00338
00339
00340
00341
00342 aPrs = CreatePrs3dInViewer<TPrs3d_i,SVTK_Viewer,TDlg,IsDlgModal>
00343 (theModule,aTimeStampSObj,aPublishInStudyMode);
00344
00345 }
00346 }
00347 return aPrs;
00348 }
00349
00350
00351
00352 template<typename TInterface>
00353 typename TInterface::_var_type
00354 GetInterface(CORBA::Object_ptr theObject)
00355 {
00356 if(!CORBA::is_nil(theObject))
00357 return TInterface::_narrow(theObject);
00358 return TInterface::_nil();
00359 }
00360
00361
00362
00363 template<typename TServant>
00364 TServant*
00365 GetServantInterface(CORBA::Object_ptr theObject)
00366 {
00367 if(!CORBA::is_nil(theObject)){
00368 PortableServer::ServantBase_var aServant = GetServant(theObject);
00369 return dynamic_cast<TServant*>(aServant.in());
00370 }
00371 return NULL;
00372 }
00373
00374
00375
00376 }
00377
00378 #endif