1 // Copyright (C) 2007-2008 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
22 // VISU VISUGUI : GUI of VISU component
23 // File : VisuGUI_Module.h
27 #ifndef VisuGUI_Prs3dTools_HeaderFile
28 #define VisuGUI_Prs3dTools_HeaderFile
30 #include "VISUConfig.hh"
31 #include "VisuGUI_Tools.h"
32 #include "VisuGUI_ViewTools.h"
33 #include "VISU_ColoredPrs3dFactory.hh"
34 #include "VISU_PipeLine.hxx"
35 #include "VisuGUI_DialogRunner.h"
37 #include <SUIT_Desktop.h>
38 #include <SUIT_ResourceMgr.h>
40 #include <SPlot2d_ViewWindow.h>
42 #include <vtkRenderer.h>
46 //---------------------------------------------------------------
47 template<class TPrs3d_i, class TViewer, class TDlg, int TIsDlgModal>
49 EditPrs3d(VisuGUI* theModule,
50 Handle(SALOME_InteractiveObject)& theIO,
51 VISU::Prs3d_i* thePrs3d,
52 SVTK_ViewWindow* theViewWindow)
54 if (TPrs3d_i* aPrs3d = dynamic_cast<TPrs3d_i*>(thePrs3d)) {
55 bool isModal = TIsDlgModal;
56 if( ColoredPrs3d_i* aColoredPrs3d = dynamic_cast<ColoredPrs3d_i*>(aPrs3d) )
57 if( !aColoredPrs3d->IsTimeStampFixed() )
60 TDlg* aDlg = new TDlg (theModule);
61 aDlg->initFromPrsObject(aPrs3d, true);
62 if (runAndWait(aDlg,isModal)) {
63 if (!(aDlg->storeToPrsObject(aPrs3d))) {
68 aPrs3d->UpdateActors();
69 } catch (std::runtime_error& exc) {
70 aPrs3d->RemoveActors();
73 SUIT_MessageBox::warning
74 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
75 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()) );
78 theViewWindow->getRenderer()->ResetCameraClippingRange();
79 theViewWindow->Repaint();
81 // Optionally, create table and curves for cut lines
82 QApplication::setOverrideCursor(Qt::WaitCursor);
83 CreateCurves( theModule,
84 dynamic_cast<VISU::CutLines_i*>( aPrs3d ),
86 false ); // in edition mode
87 QApplication::restoreOverrideCursor();
94 //----------------------------------------------------------------------------
95 template<class TPrs3d_i, class TDlg, int TIsDlgModal>
97 EditPrs3d(VisuGUI* theModule,
98 Handle(SALOME_InteractiveObject)& theIO,
99 VISU::Prs3d_i* thePrs3d,
100 SVTK_ViewWindow* theViewWindow = NULL)
102 SVTK_ViewWindow* aViewWindow = theViewWindow;
104 // Create SVTK_ViewWindow, if it does not exist
105 aViewWindow = GetViewWindow<SVTK_Viewer>(theModule);
107 EditPrs3d<TPrs3d_i,SVTK_Viewer,TDlg,TIsDlgModal>(theModule, theIO, thePrs3d, aViewWindow);
112 //---------------------------------------------------------------
113 template<class TPrs3d_i>
115 CreatePrs3dFromFactory(VisuGUI* theModule,
116 _PTR(SObject) theTimeStamp,
117 const char* theMeshName,
118 VISU::Entity theEntity,
119 const char* theFieldName,
121 ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode)
123 VISU::Result_var aResult;
124 if (CheckResult(theModule, theTimeStamp, aResult)){
125 QApplication::setOverrideCursor(Qt::WaitCursor);
126 TPrs3d_i* aPrs3d = NULL;
127 if(thePublishInStudyMode == VISU::ColoredPrs3d_i::EPublishUnderTimeStamp)
128 aPrs3d = VISU::CreatePrs3d<TPrs3d_i>(aResult,
135 CORBA::Float anUsedMemory = 0.0;
136 CORBA::Float aRequiredMemory = 0.0;
137 VISU::ColoredPrs3dCache::EnlargeType anEnlargeType =
138 VISU::GetRequiredCacheMemory<TPrs3d_i>(aResult,
146 if( anEnlargeType == VISU::ColoredPrs3dCache::IMPOSSIBLE )
148 size_t aMb = 1024 * 1024;
149 double aFreeMemory = double(VISU_PipeLine::GetAvailableMemory(8192*aMb)) / double(aMb);
151 CORBA::Float aNecessaryMemory = aRequiredMemory - aFreeMemory - anUsedMemory;
152 SUIT_MessageBox::warning(GetDesktop(theModule),
153 QObject::tr("WRN_VISU"),
154 QObject::tr("ERR_NO_MEMORY_TO_BUILD").arg(aNecessaryMemory) );
155 QApplication::restoreOverrideCursor();
160 if( anEnlargeType == VISU::ColoredPrs3dCache::ENLARGE )
162 if(SUIT_MessageBox::information(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::warning(GetDesktop(theModule),
187 QObject::tr("WRN_VISU"),
188 QObject::tr("ERR_CANT_BUILD_PRESENTATION") );
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,
224 (const char*)aMeshName.toLatin1(),
225 (Entity)anEntity.toInt(),
226 (const char*)aFieldName.toLatin1(),
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); IPAL 20125 dmv
263 // Display created presentation.
265 PublishInView(theModule, aPrs3d, aViewWindow);
266 if(GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false)){
267 aViewWindow->onFitAll();
270 AddScalarBarPosition(theModule, aViewWindow, aPrs3d, aPos);
280 //---------------------------------------------------------------
281 template<class TPrs3d_i, class TViewer, class TDlg, int IsDlgModal>
283 CreatePrs3dInViewer(VisuGUI* theModule,
284 _PTR(SObject) theTimeStampSObj,
285 ColoredPrs3d_i::EPublishInStudyMode thePublishInStudyMode)
288 // Create new TViewWindow instance, if it does not exist.
289 typedef typename TViewer::TViewWindow TViewWindow;
290 if (!GetViewWindow<TViewer>(theModule))
293 aPrs = CreateAndEditPrs3d<TPrs3d_i,TViewer,TDlg,IsDlgModal>
294 (theModule,theTimeStampSObj,thePublishInStudyMode);
296 theModule->application()->putInfo(QObject::tr("INF_DONE"));
301 //----------------------------------------------------------------------------
302 template<class TPrs3d_i, class TDlg, int IsDlgModal>
304 CreatePrs3d(VisuGUI* theModule,
305 const QString& theDesiredViewerType = QString())
308 if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule)))
311 _PTR(SObject) aTimeStampSObj;
312 Handle(SALOME_InteractiveObject) anIO;
313 ColoredPrs3d_i::EPublishInStudyMode aPublishInStudyMode;
314 if (!CheckTimeStamp(theModule,aTimeStampSObj,anIO,aPublishInStudyMode))
317 if(/*aPublishInStudyMode == */VISU::ColoredPrs3d_i::EPublishIndependently){
318 // CreatePrs3dInViewer<TPrs3d_i,VVTK_Viewer,TDlg,0>
319 // (theModule,aTimeStampSObj,aPublishInStudyMode);
320 aPrs = CreatePrs3dInViewer<TPrs3d_i,SVTK_Viewer,TDlg,0>
321 (theModule,aTimeStampSObj,aPublishInStudyMode);
324 if(theDesiredViewerType.isNull()){
325 if (/*SUIT_ViewManager* aViewManager = */theModule->getApp()->activeViewManager())
326 /*if (aViewManager->getType() == VVTK_Viewer::Type()){
327 aPrs = CreatePrs3dInViewer<TPrs3d_i,VVTK_Viewer,TDlg,IsDlgModal>
328 (theModule,aTimeStampSObj,aPublishInStudyMode);
331 aPrs = CreatePrs3dInViewer<TPrs3d_i,SVTK_Viewer,TDlg,IsDlgModal>
332 (theModule,aTimeStampSObj,aPublishInStudyMode);
334 /*if(theDesiredViewerType == VVTK_Viewer::Type()) {
335 aPrs = CreatePrs3dInViewer<TPrs3d_i,VVTK_Viewer,TDlg,IsDlgModal>
336 (theModule,aTimeStampSObj,aPublishInStudyMode);
338 aPrs = CreatePrs3dInViewer<TPrs3d_i,SVTK_Viewer,TDlg,IsDlgModal>
339 (theModule,aTimeStampSObj,aPublishInStudyMode);
347 //----------------------------------------------------------------------------
348 template<typename TInterface>
349 typename TInterface::_var_type
350 GetInterface(CORBA::Object_ptr theObject)
352 if(!CORBA::is_nil(theObject))
353 return TInterface::_narrow(theObject);
354 return TInterface::_nil();
358 //----------------------------------------------------------------------------
359 template<typename TServant>
361 GetServantInterface(CORBA::Object_ptr theObject)
363 if(!CORBA::is_nil(theObject)){
364 PortableServer::ServantBase_var aServant = GetServant(theObject);
365 return dynamic_cast<TServant*>(aServant.in());
371 //----------------------------------------------------------------------------