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
29 #ifndef VisuGUI_Prs3dTools_HeaderFile
30 #define VisuGUI_Prs3dTools_HeaderFile
32 #include "VISU_Gen_i.hh"
33 #include "VisuGUI_ViewTools.h"
34 #include "VisuGUI_DialogRunner.h"
36 #include <vtkRenderer.h>
42 //---------------------------------------------------------------
45 runAndWait( QDialog* dlg, const bool modal )
47 VisuGUI_DialogRunner r( dlg );
48 return r.run( modal );
51 //---------------------------------------------------------------
52 template<class TPrs3d_i, class TViewer, class TDlg, int TIsDlgModal>
54 EditPrs3d(VisuGUI* theModule,
55 VISU::Prs3d_i* thePrs3d)
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) {
69 SUIT_MessageBox::warn1
70 (GetDesktop(theModule), QObject::tr("WRN_VISU"),
71 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()),
72 QObject::tr("BUT_OK"));
74 aPrs3d->RemoveActors();
76 typedef typename TViewer::TViewWindow TViewWindow;
77 if(TViewWindow* aViewWindow = GetViewWindow<TViewer>(theModule)){
78 aViewWindow->getRenderer()->ResetCameraClippingRange();
79 aViewWindow->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();
93 template<class TPrs3d_i, class TDlg, int TIsDlgModal>
96 EditPrs3d(VisuGUI* theModule,
97 VISU::Prs3d_i* thePrs3d)
99 EditPrs3d<TPrs3d_i,SVTK_Viewer,TDlg,TIsDlgModal>(theModule,thePrs3d);
102 //---------------------------------------------------------------
103 template<class TPrs3d_i>
106 CreatePrs3d(VisuGUI* theModule,
107 _PTR(SObject) theTimeStamp,
108 const char* theMeshName,
109 VISU::Entity theEntity,
110 const char* theFieldName,
113 VISU::Result_var aResult;
114 if (CheckResult(theModule,theTimeStamp,aResult)){
115 QApplication::setOverrideCursor(Qt::waitCursor);
117 GetVisuGen(theModule)->template CreatePrs3d<TPrs3d_i>
118 (aResult,theMeshName,theEntity,theFieldName,theTimeId);
119 QApplication::restoreOverrideCursor();
123 SUIT_MessageBox::warn1(GetDesktop(theModule),
124 QObject::tr("WRN_VISU"),
125 QObject::tr("ERR_CANT_BUILD_PRESENTATION"),
126 QObject::tr("BUT_OK") );
131 //---------------------------------------------------------------
132 template<class TPrs3d_i, class TViewer, class TDlg, int IsDlgModal>
135 CreatePrs3d(VisuGUI* theModule,
136 _PTR(SObject) theTimeStamp,
137 const Handle(SALOME_InteractiveObject)& theIO,
138 const bool theIsCreateView = false)
140 Storable::TRestoringMap aMap = getMapOfValue(theTimeStamp);
143 QString aType = Storable::FindValue(aMap,"myType",&isExist);
144 if(!isExist || aType.toInt() != TTIMESTAMP )
147 QString aMeshName = Storable::FindValue(aMap,"myMeshName",&isExist).latin1();
148 QString anEntity = Storable::FindValue(aMap,"myEntityId",&isExist).latin1();
149 QString aFieldName = Storable::FindValue(aMap,"myFieldName",&isExist).latin1();
150 QString aTimeStampId = Storable::FindValue(aMap,"myTimeStampId",&isExist).latin1();
152 int aPos = GetFreePositionOfDefaultScalarBar(theModule);
153 GetResourceMgr()->setValue("VISU","scalar_bar_position_num",aPos);
155 QApplication::setOverrideCursor(Qt::waitCursor);
158 CreatePrs3d<TPrs3d_i>(theModule,
161 (Entity)anEntity.toInt(),
163 aTimeStampId.toInt());
165 QApplication::restoreOverrideCursor();
167 SUIT_ResourceMgr* aResourceMgr = GetResourceMgr();
168 int aValue = aResourceMgr->integerValue("VISU","BuildDefaultPrs3d",0);
170 if(TDlg* aDlg = new TDlg(theModule)){ // dialog box in creation mode
171 aDlg->initFromPrsObject(aPrs3d);
173 if(runAndWait(aDlg,IsDlgModal) && (aDlg->storeToPrsObject(aPrs3d))) {
174 // Optionally, create table and curves for cut lines
175 QApplication::setOverrideCursor(Qt::waitCursor);
176 CreateCurves( theModule,
177 dynamic_cast<VISU::CutLines_i*>( aPrs3d ),
179 true ); // in creation mode
180 UpdateObjBrowser(theModule,true,theTimeStamp);
181 QApplication::restoreOverrideCursor();
184 DeletePrs3d(theModule,aPrs3d,theIO);
190 PublishInView<TViewer>(theModule,aPrs3d,true,theIsCreateView);
192 AddScalarBarPosition(theModule,aPrs3d,aPos);
201 //---------------------------------------------------------------
202 template<class TPrs3d_i, class TViewer, class TDlg, int IsDlgModal>
205 CreatePrs3d(VisuGUI* theModule,
206 const bool theIsCreateView = true)
208 if (CheckLock(GetCStudy(GetAppStudy(theModule)),GetDesktop(theModule)))
211 _PTR(SObject) aTimeStampSObj;
212 Handle(SALOME_InteractiveObject) anIO;
213 if(!CheckTimeStamp(theModule,aTimeStampSObj,&anIO))
216 if(!CreatePrs3d<TPrs3d_i,TViewer,TDlg,IsDlgModal>(theModule,aTimeStampSObj,anIO,theIsCreateView))
219 theModule->application()->putInfo(QObject::tr("INF_DONE"));
221 typedef typename TViewer::TViewWindow TView;
222 if(TView* aView = GetViewWindow<TViewer>(theModule,theIsCreateView))
226 template<class TPrs3d_i, class TDlg, int IsDlgModal>
229 CreatePrs3d(VisuGUI* theModule,
230 const bool theIsCreateView = true)
232 if(SUIT_ViewManager* aViewManager = theModule->getApp()->activeViewManager()){
233 QString aType = aViewManager->getType();
234 if(aType == SVTK_Viewer::Type())
235 CreatePrs3d<TPrs3d_i,SVTK_Viewer,TDlg,IsDlgModal>(theModule,theIsCreateView);
236 else if(aType == VVTK_Viewer::Type())
237 CreatePrs3d<TPrs3d_i,VVTK_Viewer,TDlg,IsDlgModal>(theModule,theIsCreateView);