1 // Copyright (C) 2007-2010 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 "VisuGUI_ViewTools.h"
34 #include "VISU_ColoredPrs3dFactory.hh"
35 #include "VISU_PipeLine.hxx"
36 #include "VisuGUI_DialogRunner.h"
38 #include <SUIT_Desktop.h>
39 #include <SUIT_ResourceMgr.h>
41 #include <SPlot2d_ViewWindow.h>
43 #include <vtkRenderer.h>
47 //---------------------------------------------------------------
48 template<class TPrs3d_i, class TViewer, class TDlg, int TIsDlgModal>
50 EditPrs3d(VisuGUI* theModule,
51 Handle(SALOME_InteractiveObject)& theIO,
52 VISU::Prs3d_i* thePrs3d,
53 SVTK_ViewWindow* theViewWindow)
55 if (TPrs3d_i* aPrs3d = dynamic_cast<TPrs3d_i*>(thePrs3d)) {
56 bool isModal = TIsDlgModal;
57 if( ColoredPrs3d_i* aColoredPrs3d = dynamic_cast<ColoredPrs3d_i*>(aPrs3d) )
58 if( !aColoredPrs3d->IsTimeStampFixed() )
61 TDlg* aDlg = new TDlg (theModule);
62 aDlg->initFromPrsObject(aPrs3d, true);
63 if (runAndWait(aDlg,isModal)) {
64 if (!(aDlg->storeToPrsObject(aPrs3d))) {
69 aPrs3d->UpdateActors();
70 } catch (std::runtime_error& exc) {
71 aPrs3d->RemoveActors();
74 SUIT_MessageBox::warning
75 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
76 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()) );
79 theViewWindow->getRenderer()->ResetCameraClippingRange();
80 theViewWindow->Repaint();
82 // Optionally, create table and curves for cut lines
83 QApplication::setOverrideCursor(Qt::WaitCursor);
84 CreateCurves( theModule,
85 dynamic_cast<VISU::CutLinesBase_i*>( aPrs3d ),
87 false ); // in edition mode
88 QApplication::restoreOverrideCursor();
95 //----------------------------------------------------------------------------
96 template<class TPrs3d_i, class TDlg, int TIsDlgModal>
98 EditPrs3d(VisuGUI* theModule,
99 Handle(SALOME_InteractiveObject)& theIO,
100 VISU::Prs3d_i* thePrs3d,
101 SVTK_ViewWindow* theViewWindow = NULL)
103 SVTK_ViewWindow* aViewWindow = theViewWindow;
105 // Create SVTK_ViewWindow, if it does not exist
106 aViewWindow = GetViewWindow<SVTK_Viewer>(theModule);
108 EditPrs3d<TPrs3d_i,SVTK_Viewer,TDlg,TIsDlgModal>(theModule, theIO, thePrs3d, aViewWindow);
113 //---------------------------------------------------------------
114 template<class TPrs3d_i>
116 CreatePrs3dFromFactory(VisuGUI* theModule,
117 _PTR(SObject) theTimeStamp,
118 const char* theMeshName,
119 VISU::Entity theEntity,
120 const char* theFieldName,
122 ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode)
124 VISU::Result_var aResult;
125 if (CheckResult(theModule, theTimeStamp, aResult)){
126 QApplication::setOverrideCursor(Qt::WaitCursor);
127 TPrs3d_i* aPrs3d = NULL;
128 if(thePublishInStudyMode == VISU::ColoredPrs3d_i::EPublishUnderTimeStamp)
129 aPrs3d = VISU::CreatePrs3d<TPrs3d_i>(aResult,
136 CORBA::Float anUsedMemory = 0.0;
137 CORBA::Float aRequiredMemory = 0.0;
138 VISU::ColoredPrs3dCache::EnlargeType anEnlargeType =
139 VISU::GetRequiredCacheMemory<TPrs3d_i>(aResult,
147 if( anEnlargeType == VISU::ColoredPrs3dCache::IMPOSSIBLE )
149 size_t aMb = 1024 * 1024;
150 double aFreeMemory = double(VISU_PipeLine::GetAvailableMemory(8192*aMb)) / double(aMb);
152 CORBA::Float aNecessaryMemory = aRequiredMemory - aFreeMemory - anUsedMemory;
153 SUIT_MessageBox::warning(GetDesktop(theModule),
154 QObject::tr("WRN_VISU"),
155 QObject::tr("ERR_NO_MEMORY_TO_BUILD").arg(aNecessaryMemory) );
156 QApplication::restoreOverrideCursor();
161 if( anEnlargeType == VISU::ColoredPrs3dCache::ENLARGE )
163 if(SUIT_MessageBox::information(GetDesktop(theModule),
164 QObject::tr("WRN_VISU"),
165 QObject::tr("WRN_EXTRA_MEMORY_REQUIRED").arg(aRequiredMemory),
166 QObject::tr("&OK"), QObject::tr("&Cancel"),
169 QApplication::restoreOverrideCursor();
173 aPrs3d = VISU::CreateHolder2GetDeviceByType<TPrs3d_i>(aResult,
183 QApplication::restoreOverrideCursor();
187 SUIT_MessageBox::warning(GetDesktop(theModule),
188 QObject::tr("WRN_VISU"),
189 QObject::tr("ERR_CANT_BUILD_PRESENTATION") );
195 //---------------------------------------------------------------
196 template<class TPrs3d_i, class TViewer, class TDlg, int IsDlgModal>
198 CreateAndEditPrs3d(VisuGUI* theModule,
199 _PTR(SObject) theTimeStamp,
200 ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode)
202 Storable::TRestoringMap aRestoringMap = Storable::GetStorableMap(theTimeStamp);
203 VISU::VISUType aType = VISU::Storable::RestoringMap2Type(aRestoringMap);
204 if ( aType != TTIMESTAMP )
207 QString aMeshName = aRestoringMap["myMeshName"];
208 QString anEntity = aRestoringMap["myEntityId"];
209 QString aFieldName = aRestoringMap["myFieldName"];
210 QString aTimeStampId = aRestoringMap["myTimeStampId"];
212 // Create new TViewWindow instance, if it does not exist.
213 typedef typename TViewer::TViewWindow TViewWindow;
214 TViewWindow* aViewWindow = GetViewWindow<TViewer>(theModule);
216 // Define free position for scalar bar.
217 int aPos = GetFreePositionOfDefaultScalarBar(theModule, aViewWindow);
218 GetResourceMgr()->setValue("VISU", "scalar_bar_position_num", aPos);
220 QApplication::setOverrideCursor(Qt::WaitCursor);
223 CreatePrs3dFromFactory<TPrs3d_i>(theModule,
225 (const char*)aMeshName.toLatin1(),
226 (Entity)anEntity.toInt(),
227 (const char*)aFieldName.toLatin1(),
228 aTimeStampId.toInt(),
229 thePublishInStudyMode);
231 QApplication::restoreOverrideCursor();
233 SUIT_ResourceMgr* aResourceMgr = GetResourceMgr();
234 int aValue = aResourceMgr->integerValue("VISU","BuildDefaultPrs3d",0);
235 if(aResourceMgr->booleanValue("VISU","display_only",false)){
236 theModule->OnEraseAll();
240 if (TDlg* aDlg = new TDlg(theModule)) { // dialog box in creation mode
241 aDlg->initFromPrsObject(aPrs3d, true);
242 if (runAndWait(aDlg,IsDlgModal) && (aDlg->storeToPrsObject(aPrs3d))) {
243 if(aResourceMgr->booleanValue("VISU","display_only",false)){
244 if(SPlot2d_Viewer* aPlot2d = GetPlot2dViewer(theModule, false)) aPlot2d->EraseAll();
246 // Optionally, create table and curves for cut lines
247 QApplication::setOverrideCursor(Qt::WaitCursor);
248 CreateCurves( theModule,
249 dynamic_cast<VISU::CutLinesBase_i*>( aPrs3d ),
251 true ); // in creation mode
252 UpdateObjBrowser(theModule,true,theTimeStamp);
253 QApplication::restoreOverrideCursor();
256 if ( theModule->application() )
257 DeletePrs3d(theModule,aPrs3d);
258 QApplication::restoreOverrideCursor();
264 // aViewWindow = GetViewWindow<TViewer>(theModule); IPAL 20125 dmv
265 // Display created presentation.
267 PublishInView(theModule, aPrs3d, aViewWindow);
268 if(GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)){
269 aViewWindow->onFitAll();
272 AddScalarBarPosition(theModule, aViewWindow, aPrs3d, aPos);
282 //---------------------------------------------------------------
283 template<class TPrs3d_i, class TViewer, class TDlg, int IsDlgModal>
285 CreatePrs3dInViewer(VisuGUI* theModule,
286 _PTR(SObject) theTimeStampSObj,
287 ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode)
290 // Create new TViewWindow instance, if it does not exist.
291 typedef typename TViewer::TViewWindow TViewWindow;
292 if (!GetViewWindow<TViewer>(theModule))
295 aPrs = CreateAndEditPrs3d<TPrs3d_i,TViewer,TDlg,IsDlgModal>
296 (theModule,theTimeStampSObj,thePublishInStudyMode);
298 theModule->application()->putInfo(QObject::tr("INF_DONE"));
303 //----------------------------------------------------------------------------
304 template<class TPrs3d_i, class TDlg, int IsDlgModal>
306 CreatePrs3d(VisuGUI* theModule,
307 const QString& theDesiredViewerType = QString())
310 if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule)))
313 _PTR(SObject) aTimeStampSObj;
314 Handle(SALOME_InteractiveObject) anIO;
315 ColoredPrs3d_i::EPublishInStudyMode aPublishInStudyMode;
316 if (!CheckTimeStamp(theModule,aTimeStampSObj,anIO,aPublishInStudyMode))
319 if(/*aPublishInStudyMode == */VISU::ColoredPrs3d_i::EPublishIndependently){
320 // CreatePrs3dInViewer<TPrs3d_i,VVTK_Viewer,TDlg,0>
321 // (theModule,aTimeStampSObj,aPublishInStudyMode);
322 aPrs = CreatePrs3dInViewer<TPrs3d_i,SVTK_Viewer,TDlg,0>
323 (theModule,aTimeStampSObj,aPublishInStudyMode);
326 if(theDesiredViewerType.isNull()){
327 if (/*SUIT_ViewManager* aViewManager = */theModule->getApp()->activeViewManager())
328 /*if (aViewManager->getType() == VVTK_Viewer::Type()){
329 aPrs = CreatePrs3dInViewer<TPrs3d_i,VVTK_Viewer,TDlg,IsDlgModal>
330 (theModule,aTimeStampSObj,aPublishInStudyMode);
333 aPrs = CreatePrs3dInViewer<TPrs3d_i,SVTK_Viewer,TDlg,IsDlgModal>
334 (theModule,aTimeStampSObj,aPublishInStudyMode);
336 /*if(theDesiredViewerType == VVTK_Viewer::Type()) {
337 aPrs = CreatePrs3dInViewer<TPrs3d_i,VVTK_Viewer,TDlg,IsDlgModal>
338 (theModule,aTimeStampSObj,aPublishInStudyMode);
340 aPrs = CreatePrs3dInViewer<TPrs3d_i,SVTK_Viewer,TDlg,IsDlgModal>
341 (theModule,aTimeStampSObj,aPublishInStudyMode);
349 //----------------------------------------------------------------------------
350 template<typename TInterface>
351 typename TInterface::_var_type
352 GetInterface(CORBA::Object_ptr theObject)
354 if(!CORBA::is_nil(theObject))
355 return TInterface::_narrow(theObject);
356 return TInterface::_nil();
360 //----------------------------------------------------------------------------
361 template<typename TServant>
363 GetServantInterface(CORBA::Object_ptr theObject)
365 if(!CORBA::is_nil(theObject)){
366 PortableServer::ServantBase_var aServant = GetServant(theObject);
367 return dynamic_cast<TServant*>(aServant.in());
373 //----------------------------------------------------------------------------