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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : VisuGUI_Module.h
28 #ifndef VisuGUI_Prs3dTools_HeaderFile
29 #define VisuGUI_Prs3dTools_HeaderFile
31 #include "VISU_Gen_i.hh"
32 #include "VisuGUI_ViewTools.h"
33 #include "VisuGUI_DialogRunner.h"
35 #include <vtkRenderer.h>
41 //---------------------------------------------------------------
44 runAndWait( QDialog* dlg, const bool modal )
46 VisuGUI_DialogRunner r( dlg );
47 return r.run( modal );
50 //---------------------------------------------------------------
51 template<class TPrs3d_i, class TViewer, class TDlg, int TIsDlgModal>
53 EditPrs3d(VisuGUI* theModule,
54 VISU::Prs3d_i* thePrs3d,
55 SVTK_ViewWindow* theViewWindow)
57 if (TPrs3d_i* aPrs3d = dynamic_cast<TPrs3d_i*>(thePrs3d)) {
58 TDlg* aDlg = new TDlg (theModule);
59 aDlg->initFromPrsObject(aPrs3d);
60 if (runAndWait(aDlg,TIsDlgModal)) {
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();
92 template<class TPrs3d_i, class TDlg, int TIsDlgModal>
95 EditPrs3d(VisuGUI* theModule,
96 Handle(SALOME_InteractiveObject)& theIO,
97 VISU::Prs3d_i* thePrs3d,
98 SVTK_ViewWindow* theViewWindow = NULL)
100 SVTK_ViewWindow* aViewWindow = theViewWindow;
102 // Create SVTK_ViewWindow, if it does not exist
103 aViewWindow = GetViewWindow<SVTK_Viewer>(theModule);
105 EditPrs3d<TPrs3d_i,SVTK_Viewer,TDlg,TIsDlgModal>(theModule, thePrs3d, aViewWindow);
106 aViewWindow->highlight(theIO, 1);
110 //---------------------------------------------------------------
111 template<class TPrs3d_i>
114 CreatePrs3d(VisuGUI* theModule,
115 _PTR(SObject) theTimeStamp,
116 const char* theMeshName,
117 VISU::Entity theEntity,
118 const char* theFieldName,
121 VISU::Result_var aResult;
122 if (CheckResult(theModule,theTimeStamp,aResult)){
123 QApplication::setOverrideCursor(Qt::waitCursor);
125 GetVisuGen(theModule)->template CreatePrs3d<TPrs3d_i>
126 (aResult,theMeshName,theEntity,theFieldName,theTimeId);
127 QApplication::restoreOverrideCursor();
131 SUIT_MessageBox::warn1(GetDesktop(theModule),
132 QObject::tr("WRN_VISU"),
133 QObject::tr("ERR_CANT_BUILD_PRESENTATION"),
134 QObject::tr("BUT_OK") );
139 //---------------------------------------------------------------
140 template<class TPrs3d_i, class TViewer, class TDlg, int IsDlgModal>
143 CreatePrs3d(VisuGUI* theModule,
144 _PTR(SObject) theTimeStamp,
145 const Handle(SALOME_InteractiveObject)& theIO)
147 Storable::TRestoringMap aMap = getMapOfValue(theTimeStamp);
150 QString aType = Storable::FindValue(aMap,"myType",&isExist);
151 if (!isExist || aType.toInt() != TTIMESTAMP )
154 QString aMeshName = Storable::FindValue(aMap,"myMeshName",&isExist).latin1();
155 QString anEntity = Storable::FindValue(aMap,"myEntityId",&isExist).latin1();
156 QString aFieldName = Storable::FindValue(aMap,"myFieldName",&isExist).latin1();
157 QString aTimeStampId = Storable::FindValue(aMap,"myTimeStampId",&isExist).latin1();
159 // Create new TViewWindow instance, if it does not exist.
160 typedef typename TViewer::TViewWindow TViewWindow;
161 TViewWindow* aViewWindow = GetViewWindow<TViewer>(theModule);
163 // Define free position for scalar bar.
164 int aPos = GetFreePositionOfDefaultScalarBar(theModule, aViewWindow);
165 GetResourceMgr()->setValue("VISU", "scalar_bar_position_num", aPos);
167 QApplication::setOverrideCursor(Qt::waitCursor);
170 CreatePrs3d<TPrs3d_i>(theModule,
173 (Entity)anEntity.toInt(),
175 aTimeStampId.toInt());
177 QApplication::restoreOverrideCursor();
179 SUIT_ResourceMgr* aResourceMgr = GetResourceMgr();
180 int aValue = aResourceMgr->integerValue("VISU","BuildDefaultPrs3d",0);
182 if (TDlg* aDlg = new TDlg(theModule)) { // dialog box in creation mode
183 aDlg->initFromPrsObject(aPrs3d);
185 if (runAndWait(aDlg,IsDlgModal) && (aDlg->storeToPrsObject(aPrs3d))) {
186 // Optionally, create table and curves for cut lines
187 QApplication::setOverrideCursor(Qt::waitCursor);
188 CreateCurves( theModule,
189 dynamic_cast<VISU::CutLines_i*>( aPrs3d ),
191 true ); // in creation mode
192 UpdateObjBrowser(theModule,true,theTimeStamp);
193 QApplication::restoreOverrideCursor();
196 DeletePrs3d(theModule,aPrs3d,theIO);
203 // Display created presentation.
205 PublishInView(theModule, aPrs3d, aViewWindow, /*highlight = */true);
206 aViewWindow->onFitAll();
208 AddScalarBarPosition(theModule, aViewWindow, aPrs3d, aPos);
218 //---------------------------------------------------------------
219 template<class TPrs3d_i, class TViewer, class TDlg, int IsDlgModal>
222 CreatePrs3d(VisuGUI* theModule)
224 if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule)))
227 _PTR(SObject) aTimeStampSObj;
228 Handle(SALOME_InteractiveObject) anIO;
229 if (!CheckTimeStamp(theModule,aTimeStampSObj,&anIO))
232 // Create new TViewWindow instance, if it does not exist.
233 typedef typename TViewer::TViewWindow TViewWindow;
234 if (!GetViewWindow<TViewer>(theModule))
237 if (!CreatePrs3d<TPrs3d_i,TViewer,TDlg,IsDlgModal>(theModule,aTimeStampSObj,anIO))
240 theModule->application()->putInfo(QObject::tr("INF_DONE"));
243 template<class TPrs3d_i, class TDlg, int IsDlgModal>
246 CreatePrs3d(VisuGUI* theModule)
248 if (SUIT_ViewManager* aViewManager = theModule->getApp()->activeViewManager()) {
249 QString aType = aViewManager->getType();
250 if (aType == VVTK_Viewer::Type())
251 CreatePrs3d<TPrs3d_i,VVTK_Viewer,TDlg,IsDlgModal>(theModule);
253 CreatePrs3d<TPrs3d_i,SVTK_Viewer,TDlg,IsDlgModal>(theModule);