1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // VISU VISUGUI : GUI of VISU component
24 // File : VisuGUI_Module.h
28 #ifndef VisuGUI_Prs3dTools_HeaderFile
29 #define VisuGUI_Prs3dTools_HeaderFile
31 #include "VISUConfig.hh"
32 #include "VisuGUI_Tools.h"
33 #include "VISU_Tools.h"
34 #include "VisuGUI_ViewTools.h"
35 #include "VISU_ColoredPrs3dFactory.hh"
36 #include "VISU_PipeLine.hxx"
37 #include "VisuGUI_DialogRunner.h"
39 #include <SUIT_Desktop.h>
40 #include <SUIT_ResourceMgr.h>
42 #include <SPlot2d_ViewWindow.h>
44 #include <vtkRenderer.h>
48 //---------------------------------------------------------------
49 template<class TPrs3d_i, class TViewer, class TDlg, int TIsDlgModal>
51 EditPrs3d(VisuGUI* theModule,
52 Handle(SALOME_InteractiveObject)& theIO,
53 VISU::Prs3d_i* thePrs3d,
54 SVTK_ViewWindow* theViewWindow)
56 if (TPrs3d_i* aPrs3d = dynamic_cast<TPrs3d_i*>(thePrs3d)) {
57 bool isModal = TIsDlgModal;
58 if( ColoredPrs3d_i* aColoredPrs3d = dynamic_cast<ColoredPrs3d_i*>(aPrs3d) )
59 if( !aColoredPrs3d->IsTimeStampFixed() )
62 TDlg* aDlg = new TDlg (theModule);
63 aDlg->initFromPrsObject(aPrs3d, true);
64 if (runAndWait(aDlg,isModal)) {
65 if (!(aDlg->storeToPrsObject(aPrs3d))) {
70 aPrs3d->UpdateActors();
71 } catch (std::runtime_error& exc) {
72 aPrs3d->RemoveActors();
75 SUIT_MessageBox::warning
76 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
77 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()) );
80 theViewWindow->getRenderer()->ResetCameraClippingRange();
81 theViewWindow->Repaint();
83 // Optionally, create table and curves for cut lines
84 QApplication::setOverrideCursor(Qt::WaitCursor);
85 CreateCurves( theModule,
86 dynamic_cast<VISU::CutLinesBase_i*>( aPrs3d ),
88 false ); // in edition mode
89 QApplication::restoreOverrideCursor();
96 //----------------------------------------------------------------------------
97 template<class TPrs3d_i, class TDlg, int TIsDlgModal>
99 EditPrs3d(VisuGUI* theModule,
100 Handle(SALOME_InteractiveObject)& theIO,
101 VISU::Prs3d_i* thePrs3d,
102 SVTK_ViewWindow* theViewWindow = NULL)
104 SVTK_ViewWindow* aViewWindow = theViewWindow;
106 // Create SVTK_ViewWindow, if it does not exist
107 aViewWindow = GetViewWindow<SVTK_Viewer>(theModule);
109 EditPrs3d<TPrs3d_i,SVTK_Viewer,TDlg,TIsDlgModal>(theModule, theIO, thePrs3d, aViewWindow);
114 //---------------------------------------------------------------
115 template<class TPrs3d_i>
117 CreatePrs3dFromFactory(VisuGUI* theModule,
118 _PTR(SObject) theTimeStamp,
119 const char* theMeshName,
120 VISU::Entity theEntity,
121 const char* theFieldName,
123 ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode)
125 VISU::Result_var aResult;
126 if (CheckResult(theModule, theTimeStamp, aResult)){
127 QApplication::setOverrideCursor(Qt::WaitCursor);
128 TPrs3d_i* aPrs3d = NULL;
129 if(thePublishInStudyMode == VISU::ColoredPrs3d_i::EPublishUnderTimeStamp)
130 aPrs3d = VISU::CreatePrs3d<TPrs3d_i>(aResult,
137 CORBA::Float anUsedMemory = 0.0;
138 CORBA::Float aRequiredMemory = 0.0;
139 VISU::ColoredPrs3dCache::EnlargeType anEnlargeType =
140 VISU::GetRequiredCacheMemory<TPrs3d_i>(aResult,
148 if( anEnlargeType == VISU::ColoredPrs3dCache::IMPOSSIBLE )
150 size_t aMb = 1024 * 1024;
151 double aFreeMemory = double(VISU_PipeLine::GetAvailableMemory(8192*(double)aMb)) / double(aMb);
153 CORBA::Float aNecessaryMemory = aRequiredMemory - aFreeMemory - anUsedMemory;
154 SUIT_MessageBox::warning(GetDesktop(theModule),
155 QObject::tr("WRN_VISU"),
156 QObject::tr("ERR_NO_MEMORY_TO_BUILD").arg(aNecessaryMemory) );
157 QApplication::restoreOverrideCursor();
162 if( anEnlargeType == VISU::ColoredPrs3dCache::ENLARGE )
164 if(SUIT_MessageBox::information(GetDesktop(theModule),
165 QObject::tr("WRN_VISU"),
166 QObject::tr("WRN_EXTRA_MEMORY_REQUIRED").arg(aRequiredMemory),
167 QObject::tr("&OK"), QObject::tr("&Cancel"),
170 QApplication::restoreOverrideCursor();
174 aPrs3d = VISU::CreateHolder2GetDeviceByType<TPrs3d_i>(aResult,
184 QApplication::restoreOverrideCursor();
188 SUIT_MessageBox::warning(GetDesktop(theModule),
189 QObject::tr("WRN_VISU"),
190 QObject::tr("ERR_CANT_BUILD_PRESENTATION") );
196 //---------------------------------------------------------------
197 template<class TPrs3d_i, class TViewer, class TDlg, int IsDlgModal>
199 CreateAndEditPrs3d(VisuGUI* theModule,
200 _PTR(SObject) theTimeStamp,
201 ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode)
203 Storable::TRestoringMap aRestoringMap = Storable::GetStorableMap(theTimeStamp);
204 VISU::VISUType aType = VISU::Storable::RestoringMap2Type(aRestoringMap);
205 if ( aType != TTIMESTAMP )
208 QString aMeshName = aRestoringMap["myMeshName"];
209 QString anEntity = aRestoringMap["myEntityId"];
210 QString aFieldName = aRestoringMap["myFieldName"];
211 QString aTimeStampId = aRestoringMap["myTimeStampId"];
213 // Create new TViewWindow instance, if it does not exist.
214 typedef typename TViewer::TViewWindow TViewWindow;
215 TViewWindow* aViewWindow = GetViewWindow<TViewer>(theModule);
217 // Define free position for scalar bar.
218 int aPos = GetFreePositionOfDefaultScalarBar(theModule, aViewWindow);
219 GetResourceMgr()->setValue("VISU", "scalar_bar_position_num", aPos);
221 QApplication::setOverrideCursor(Qt::WaitCursor);
224 CreatePrs3dFromFactory<TPrs3d_i>(theModule,
226 (const char*)aMeshName.toLatin1(),
227 (Entity)anEntity.toInt(),
228 (const char*)aFieldName.toLatin1(),
229 aTimeStampId.toInt(),
230 thePublishInStudyMode);
232 QApplication::restoreOverrideCursor();
234 SUIT_ResourceMgr* aResourceMgr = GetResourceMgr();
235 int aValue = aResourceMgr->integerValue("VISU","BuildDefaultPrs3d",0);
236 if(aResourceMgr->booleanValue("VISU","display_only",false)){
237 theModule->OnEraseAll();
238 SetVisibilityState(aPrs3d->GetEntry(),Qtx::ShownState);
242 if (TDlg* aDlg = new TDlg(theModule)) { // dialog box in creation mode
243 aDlg->initFromPrsObject(aPrs3d, true);
244 if (runAndWait(aDlg,IsDlgModal) && (aDlg->storeToPrsObject(aPrs3d))) {
245 if(aResourceMgr->booleanValue("VISU","display_only",false)){
246 if(SPlot2d_Viewer* aPlot2d = GetPlot2dViewer(theModule, false)) aPlot2d->EraseAll();
248 // Optionally, create table and curves for cut lines
249 QApplication::setOverrideCursor(Qt::WaitCursor);
250 CreateCurves( theModule,
251 dynamic_cast<VISU::CutLinesBase_i*>( aPrs3d ),
253 true ); // in creation mode
254 UpdateObjBrowser(theModule,true,theTimeStamp);
255 QApplication::restoreOverrideCursor();
258 if ( theModule->application() )
259 DeletePrs3d(theModule,aPrs3d);
260 QApplication::restoreOverrideCursor();
266 // aViewWindow = GetViewWindow<TViewer>(theModule); IPAL 20125 dmv
267 // Display created presentation.
269 PublishInView(theModule, aPrs3d, aViewWindow);
270 if(GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)){
271 aViewWindow->onFitAll();
274 AddScalarBarPosition(theModule, aViewWindow, aPrs3d, aPos);
284 //---------------------------------------------------------------
285 template<class TPrs3d_i, class TViewer, class TDlg, int IsDlgModal>
287 CreatePrs3dInViewer(VisuGUI* theModule,
288 _PTR(SObject) theTimeStampSObj,
289 ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode)
292 // Create new TViewWindow instance, if it does not exist.
293 typedef typename TViewer::TViewWindow TViewWindow;
294 if (!GetViewWindow<TViewer>(theModule))
297 aPrs = CreateAndEditPrs3d<TPrs3d_i,TViewer,TDlg,IsDlgModal>
298 (theModule,theTimeStampSObj,thePublishInStudyMode);
300 theModule->application()->putInfo(QObject::tr("INF_DONE"));
305 //----------------------------------------------------------------------------
306 template<class TPrs3d_i, class TDlg, int IsDlgModal>
308 CreatePrs3d(VisuGUI* theModule,
309 const QString& theDesiredViewerType = QString())
312 if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule)))
315 _PTR(SObject) aTimeStampSObj;
316 Handle(SALOME_InteractiveObject) anIO;
317 ColoredPrs3d_i::EPublishInStudyMode aPublishInStudyMode;
318 if (!CheckTimeStamp(theModule,aTimeStampSObj,anIO,aPublishInStudyMode))
321 if(/*aPublishInStudyMode == */VISU::ColoredPrs3d_i::EPublishIndependently){
322 // CreatePrs3dInViewer<TPrs3d_i,VVTK_Viewer,TDlg,0>
323 // (theModule,aTimeStampSObj,aPublishInStudyMode);
324 aPrs = CreatePrs3dInViewer<TPrs3d_i,SVTK_Viewer,TDlg,0>
325 (theModule,aTimeStampSObj,aPublishInStudyMode);
328 if(theDesiredViewerType.isNull()){
329 if (/*SUIT_ViewManager* aViewManager = */theModule->getApp()->activeViewManager())
330 /*if (aViewManager->getType() == VVTK_Viewer::Type()){
331 aPrs = CreatePrs3dInViewer<TPrs3d_i,VVTK_Viewer,TDlg,IsDlgModal>
332 (theModule,aTimeStampSObj,aPublishInStudyMode);
335 aPrs = CreatePrs3dInViewer<TPrs3d_i,SVTK_Viewer,TDlg,IsDlgModal>
336 (theModule,aTimeStampSObj,aPublishInStudyMode);
338 /*if(theDesiredViewerType == VVTK_Viewer::Type()) {
339 aPrs = CreatePrs3dInViewer<TPrs3d_i,VVTK_Viewer,TDlg,IsDlgModal>
340 (theModule,aTimeStampSObj,aPublishInStudyMode);
342 aPrs = CreatePrs3dInViewer<TPrs3d_i,SVTK_Viewer,TDlg,IsDlgModal>
343 (theModule,aTimeStampSObj,aPublishInStudyMode);
351 //----------------------------------------------------------------------------
352 template<typename TInterface>
353 typename TInterface::_var_type
354 GetInterface(CORBA::Object_ptr theObject)
356 if(!CORBA::is_nil(theObject))
357 return TInterface::_narrow(theObject);
358 return TInterface::_nil();
362 //----------------------------------------------------------------------------
363 template<typename TServant>
365 GetServantInterface(CORBA::Object_ptr theObject)
367 if(!CORBA::is_nil(theObject)){
368 PortableServer::ServantBase_var aServant = GetServant(theObject);
369 return dynamic_cast<TServant*>(aServant.in());
375 //----------------------------------------------------------------------------