1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 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
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 "VisuGUI_ViewTools.h"
34 #include "VISU_ColoredPrs3dFactory.hh"
35 #include "VISU_PipeLine.hxx"
36 #include "VisuGUI_DialogRunner.h"
38 #include <SPlot2d_ViewWindow.h>
40 #include <vtkRenderer.h>
44 //---------------------------------------------------------------
45 template<class TPrs3d_i, class TViewer, class TDlg, int TIsDlgModal>
47 EditPrs3d(VisuGUI* theModule,
48 Handle(SALOME_InteractiveObject)& theIO,
49 VISU::Prs3d_i* thePrs3d,
50 SVTK_ViewWindow* theViewWindow)
52 if (TPrs3d_i* aPrs3d = dynamic_cast<TPrs3d_i*>(thePrs3d)) {
53 bool isModal = TIsDlgModal;
54 if( ColoredPrs3d_i* aColoredPrs3d = dynamic_cast<ColoredPrs3d_i*>(aPrs3d) )
55 if( !aColoredPrs3d->IsTimeStampFixed() )
58 TDlg* aDlg = new TDlg (theModule);
59 aDlg->initFromPrsObject(aPrs3d, true);
60 if (runAndWait(aDlg,isModal)) {
61 if (!(aDlg->storeToPrsObject(aPrs3d))) {
66 aPrs3d->UpdateActors();
67 } catch (std::runtime_error& exc) {
68 aPrs3d->RemoveActors();
71 SUIT_MessageBox::warn1
72 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
73 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()),
74 QObject::tr("BUT_OK"));
77 theViewWindow->getRenderer()->ResetCameraClippingRange();
78 theViewWindow->Repaint();
80 // Optionally, create table and curves for cut lines
81 QApplication::setOverrideCursor(Qt::waitCursor);
82 CreateCurves( theModule,
83 dynamic_cast<VISU::CutLines_i*>( aPrs3d ),
85 false ); // in edition mode
86 QApplication::restoreOverrideCursor();
93 //----------------------------------------------------------------------------
94 template<class TPrs3d_i, class TDlg, int TIsDlgModal>
96 EditPrs3d(VisuGUI* theModule,
97 Handle(SALOME_InteractiveObject)& theIO,
98 VISU::Prs3d_i* thePrs3d,
99 SVTK_ViewWindow* theViewWindow = NULL)
101 SVTK_ViewWindow* aViewWindow = theViewWindow;
103 // Create SVTK_ViewWindow, if it does not exist
104 aViewWindow = GetViewWindow<SVTK_Viewer>(theModule);
106 EditPrs3d<TPrs3d_i,SVTK_Viewer,TDlg,TIsDlgModal>(theModule, theIO, thePrs3d, aViewWindow);
111 //---------------------------------------------------------------
112 template<class TPrs3d_i>
114 CreatePrs3dFromFactory(VisuGUI* theModule,
115 _PTR(SObject) theTimeStamp,
116 const char* theMeshName,
117 VISU::Entity theEntity,
118 const char* theFieldName,
120 ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode)
122 VISU::Result_var aResult;
123 if (CheckResult(theModule, theTimeStamp, aResult)){
124 QApplication::setOverrideCursor(Qt::waitCursor);
125 TPrs3d_i* aPrs3d = NULL;
126 if(thePublishInStudyMode == VISU::ColoredPrs3d_i::EPublishUnderTimeStamp)
127 aPrs3d = VISU::CreatePrs3d<TPrs3d_i>(aResult,
134 CORBA::Float anUsedMemory = 0.0;
135 CORBA::Float aRequiredMemory = 0.0;
136 VISU::ColoredPrs3dCache::EnlargeType anEnlargeType =
137 VISU::GetRequiredCacheMemory<TPrs3d_i>(aResult,
145 if( anEnlargeType == VISU::ColoredPrs3dCache::IMPOSSIBLE )
147 size_t aMb = 1024 * 1024;
148 double aFreeMemory = double(VISU_PipeLine::GetAvailableMemory(2048*aMb)) / double(aMb);
150 CORBA::Float aNecessaryMemory = aRequiredMemory - aFreeMemory - anUsedMemory;
151 SUIT_MessageBox::warn1(GetDesktop(theModule),
152 QObject::tr("WRN_VISU"),
153 QObject::tr("ERR_NO_MEMORY_TO_BUILD").arg(aNecessaryMemory),
154 QObject::tr("&OK") );
155 QApplication::restoreOverrideCursor();
160 if( anEnlargeType == VISU::ColoredPrs3dCache::ENLARGE )
162 if(SUIT_MessageBox::info2(GetDesktop(theModule),
163 QObject::tr("WRN_VISU"),
164 QObject::tr("WRN_EXTRA_MEMORY_REQUIRED").arg(aRequiredMemory),
165 QObject::tr("&OK"), QObject::tr("&Cancel"),
168 QApplication::restoreOverrideCursor();
172 aPrs3d = VISU::CreateHolder2GetDeviceByType<TPrs3d_i>(aResult,
182 QApplication::restoreOverrideCursor();
186 SUIT_MessageBox::warn1(GetDesktop(theModule),
187 QObject::tr("WRN_VISU"),
188 QObject::tr("ERR_CANT_BUILD_PRESENTATION"),
189 QObject::tr("BUT_OK") );
194 //---------------------------------------------------------------
195 template<class TPrs3d_i, class TViewer, class TDlg, int IsDlgModal>
197 CreateAndEditPrs3d(VisuGUI* theModule,
198 _PTR(SObject) theTimeStamp,
199 ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode)
201 Storable::TRestoringMap aRestoringMap = Storable::GetStorableMap(theTimeStamp);
202 VISU::VISUType aType = VISU::Storable::RestoringMap2Type(aRestoringMap);
203 if ( aType != TTIMESTAMP )
206 QString aMeshName = aRestoringMap["myMeshName"];
207 QString anEntity = aRestoringMap["myEntityId"];
208 QString aFieldName = aRestoringMap["myFieldName"];
209 QString aTimeStampId = aRestoringMap["myTimeStampId"];
211 // Create new TViewWindow instance, if it does not exist.
212 typedef typename TViewer::TViewWindow TViewWindow;
213 TViewWindow* aViewWindow = GetViewWindow<TViewer>(theModule);
215 // Define free position for scalar bar.
216 int aPos = GetFreePositionOfDefaultScalarBar(theModule, aViewWindow);
217 GetResourceMgr()->setValue("VISU", "scalar_bar_position_num", aPos);
219 QApplication::setOverrideCursor(Qt::waitCursor);
222 CreatePrs3dFromFactory<TPrs3d_i>(theModule,
225 (Entity)anEntity.toInt(),
227 aTimeStampId.toInt(),
228 thePublishInStudyMode);
230 QApplication::restoreOverrideCursor();
232 SUIT_ResourceMgr* aResourceMgr = GetResourceMgr();
233 int aValue = aResourceMgr->integerValue("VISU","BuildDefaultPrs3d",0);
234 if(aResourceMgr->booleanValue("VISU","display_only",false)){
235 theModule->OnEraseAll();
239 if (TDlg* aDlg = new TDlg(theModule)) { // dialog box in creation mode
240 aDlg->initFromPrsObject(aPrs3d, true);
241 if (runAndWait(aDlg,IsDlgModal) && (aDlg->storeToPrsObject(aPrs3d))) {
242 if(aResourceMgr->booleanValue("VISU","display_only",false)){
243 if(SPlot2d_Viewer* aPlot2d = GetPlot2dViewer(theModule, false)) aPlot2d->EraseAll();
245 // Optionally, create table and curves for cut lines
246 QApplication::setOverrideCursor(Qt::waitCursor);
247 CreateCurves( theModule,
248 dynamic_cast<VISU::CutLines_i*>( aPrs3d ),
250 true ); // in creation mode
251 UpdateObjBrowser(theModule,true,theTimeStamp);
252 QApplication::restoreOverrideCursor();
255 DeletePrs3d(theModule,aPrs3d);
256 QApplication::restoreOverrideCursor();
262 aViewWindow = GetViewWindow<TViewer>(theModule);
263 // Display created presentation.
265 PublishInView(theModule, aPrs3d, aViewWindow);
266 aViewWindow->onFitAll();
268 AddScalarBarPosition(theModule, aViewWindow, aPrs3d, aPos);
278 //---------------------------------------------------------------
279 template<class TPrs3d_i, class TViewer, class TDlg, int IsDlgModal>
281 CreatePrs3dInViewer(VisuGUI* theModule,
282 _PTR(SObject) theTimeStampSObj,
283 ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode)
285 // Create new TViewWindow instance, if it does not exist.
286 typedef typename TViewer::TViewWindow TViewWindow;
287 if (!GetViewWindow<TViewer>(theModule))
290 CreateAndEditPrs3d<TPrs3d_i,TViewer,TDlg,IsDlgModal>
291 (theModule,theTimeStampSObj,thePublishInStudyMode);
293 theModule->application()->putInfo(QObject::tr("INF_DONE"));
297 //----------------------------------------------------------------------------
298 template<class TPrs3d_i, class TDlg, int IsDlgModal>
300 CreatePrs3d(VisuGUI* theModule,
301 const QString& theDesiredViewerType = QString())
303 if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule)))
306 _PTR(SObject) aTimeStampSObj;
307 Handle(SALOME_InteractiveObject) anIO;
308 ColoredPrs3d_i::EPublishInStudyMode aPublishInStudyMode;
309 if (!CheckTimeStamp(theModule,aTimeStampSObj,anIO,aPublishInStudyMode))
312 if(aPublishInStudyMode == VISU::ColoredPrs3d_i::EPublishIndependently){
313 CreatePrs3dInViewer<TPrs3d_i,VVTK_Viewer,TDlg,0>
314 (theModule,aTimeStampSObj,aPublishInStudyMode);
317 if(theDesiredViewerType.isNull()){
318 if (SUIT_ViewManager* aViewManager = theModule->getApp()->activeViewManager())
319 if (aViewManager->getType() == VVTK_Viewer::Type()){
320 CreatePrs3dInViewer<TPrs3d_i,VVTK_Viewer,TDlg,IsDlgModal>
321 (theModule,aTimeStampSObj,aPublishInStudyMode);
324 CreatePrs3dInViewer<TPrs3d_i,SVTK_Viewer,TDlg,IsDlgModal>
325 (theModule,aTimeStampSObj,aPublishInStudyMode);
327 if(theDesiredViewerType == VVTK_Viewer::Type())
328 CreatePrs3dInViewer<TPrs3d_i,VVTK_Viewer,TDlg,IsDlgModal>
329 (theModule,aTimeStampSObj,aPublishInStudyMode);
331 CreatePrs3dInViewer<TPrs3d_i,SVTK_Viewer,TDlg,IsDlgModal>
332 (theModule,aTimeStampSObj,aPublishInStudyMode);
338 //----------------------------------------------------------------------------
339 template<typename TInterface>
340 typename TInterface::_var_type
341 GetInterface(CORBA::Object_ptr theObject)
343 if(!CORBA::is_nil(theObject))
344 return TInterface::_narrow(theObject);
345 return TInterface::_nil();
349 //----------------------------------------------------------------------------
350 template<typename TServant>
352 GetServantInterface(CORBA::Object_ptr theObject)
354 if(!CORBA::is_nil(theObject)){
355 PortableServer::ServantBase_var aServant = GetServant(theObject);
356 return dynamic_cast<TServant*>(aServant.in());
362 //----------------------------------------------------------------------------