]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_Prs3dTools.h
Salome HOME
Fix a regression
[modules/visu.git] / src / VISUGUI / VisuGUI_Prs3dTools.h
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : VisuGUI_Module.h
25 //  Author : 
26 //  Module : VISU
27 //  $Header$
28
29 #ifndef VisuGUI_Prs3dTools_HeaderFile
30 #define VisuGUI_Prs3dTools_HeaderFile
31
32 #include "VisuGUI_Tools.h"
33
34 namespace VISU
35 {
36   class CutLines_i;
37
38   //---------------------------------------------------------------
39   template<class TPrs3d_i, class TDlg>
40   void
41   EditPrs3d (SalomeApp_Module* theModule, VISU::Prs3d_i* thePrs3d)
42   {
43     TPrs3d_i* aPrsObject = dynamic_cast<TPrs3d_i*>(thePrs3d);
44     if (aPrsObject) {
45       TDlg* aDlg = new TDlg (theModule);
46       aDlg->initFromPrsObject(aPrsObject);
47       if (aDlg->exec()) {
48         if (!(aDlg->storeToPrsObject(aPrsObject))) {
49           delete aDlg;
50           return;
51         }
52         RecreateActor(theModule, aPrsObject);
53         if (SVTK_ViewWindow* vw = GetViewWindow(theModule)) {
54           vw->getRenderer()->ResetCameraClippingRange();
55           vw->Repaint();
56         }
57         // Optionally, create table and curves for cut lines
58         QApplication::setOverrideCursor(Qt::waitCursor);
59         CreateCurves( theModule,
60                       dynamic_cast<VISU::CutLines_i*>( aPrsObject ),
61                       aDlg,
62                       false ); // in edition mode
63         QApplication::restoreOverrideCursor();
64       }
65       delete aDlg;
66     }
67   }
68
69
70   //---------------------------------------------------------------
71   template<class TPrs3d_i>
72   TPrs3d_i*
73   CreatePrs3d(SalomeApp_Module* theModule,
74               _PTR(SObject) theTimeStamp,
75               const char* theMeshName,
76               VISU::Entity theEntity,
77               const char* theFieldName,
78               int theTimeId)
79   {
80     VISU::Result_var aResult;
81     if (CheckResult(theModule,theTimeStamp,aResult)){
82       QApplication::setOverrideCursor(Qt::waitCursor);
83       typedef typename TPrs3d_i::TInterface TPrs3d;
84       typename TPrs3d::_var_type aPrs3d =
85         GetVisuGen(theModule)->template Prs3dOnField<TPrs3d_i>
86         (aResult,theMeshName,theEntity,theFieldName,theTimeId);
87       QApplication::restoreOverrideCursor();
88       if (!CORBA::is_nil(aPrs3d.in()))
89         return dynamic_cast<TPrs3d_i*>(VISU::GetServant(aPrs3d.in()).in());
90     }
91     SUIT_MessageBox::warn1(GetDesktop(theModule),
92                            QObject::tr("WRN_VISU"),
93                            QObject::tr("ERR_CANT_BUILD_PRESENTATION"),
94                            QObject::tr("BUT_OK") );
95     return NULL;
96   }
97
98
99   //---------------------------------------------------------------
100   template<class TPrs3d_i, class TDlg, int IsDlgModal>
101   bool
102   CreatePrs3d(SalomeApp_Module* theModule,
103               _PTR(SObject) theTimeStamp,
104               const Handle(SALOME_InteractiveObject)& theIO)
105   {
106     using namespace VISU;
107     Storable::TRestoringMap aMap = getMapOfValue(theTimeStamp);
108     bool isExist;
109     QString aType = Storable::FindValue(aMap,"myType",&isExist);
110     if(!isExist || aType.toInt() != TTIMESTAMP )
111       return false;
112     QString aMeshName = Storable::FindValue(aMap,"myMeshName",&isExist).latin1();
113     QString anEntity = Storable::FindValue(aMap,"myEntityId",&isExist).latin1();
114     QString aFieldName = Storable::FindValue(aMap,"myFieldName",&isExist).latin1();
115     QString aTimeStampId = Storable::FindValue(aMap,"myTimeStampId",&isExist).latin1();
116     QApplication::setOverrideCursor(Qt::waitCursor);
117     
118     TPrs3d_i* aPrs3d =
119       CreatePrs3d<TPrs3d_i>(theModule,
120                             theTimeStamp,
121                             aMeshName.latin1(),
122                             (Entity)anEntity.toInt(),
123                             aFieldName.latin1(),
124                             aTimeStampId.toInt());
125     
126     QApplication::restoreOverrideCursor();
127     if(aPrs3d){
128       SUIT_ResourceMgr* aResourceMgr = GetResourceMgr();
129       int aValue = aResourceMgr->integerValue("VISU","BuildDefaultPrs3d",0);
130       if(!aValue){
131         if(TDlg* aDlg = new TDlg(theModule)){ // dialog box in creation mode
132           aDlg->initFromPrsObject(aPrs3d);
133           if(IsDlgModal)
134             if(aDlg->exec() && (aDlg->storeToPrsObject(aPrs3d))) {
135               // Optionally, create table and curves for cut lines
136               QApplication::setOverrideCursor(Qt::waitCursor);
137               CreateCurves( theModule,
138                             dynamic_cast<VISU::CutLines_i*>( aPrs3d ),
139                             aDlg,
140                             true ); // in creation mode
141               QApplication::restoreOverrideCursor();
142               delete aDlg;
143             } else {
144               DeletePrs3d(theModule,aPrs3d,theIO);
145               delete aDlg;
146               return false;
147             }
148           else{
149             aDlg->show();
150             return true;
151           }
152         }
153       }
154       PublishInView(theModule,aPrs3d);
155       return true;
156     }
157     return false;
158   }
159   
160   
161   //---------------------------------------------------------------
162   template<class TPrs3d_i, class TDlg, int IsDlgModal>
163   void
164   CreatePrs3d(SalomeApp_Module* theModule)
165   {
166     if (CheckLock(GetCStudy(GetAppStudy(theModule))))
167       return;
168     
169     _PTR(SObject) aTimeStampSObj;
170     Handle(SALOME_InteractiveObject) anIO;
171     if (!CheckTimeStamp(theModule,aTimeStampSObj,&anIO))
172       return;
173     
174     if (!CreatePrs3d<TPrs3d_i,TDlg,IsDlgModal>(theModule,aTimeStampSObj,anIO))
175       return;
176     
177     theModule->application()->putInfo(QObject::tr("INF_DONE"));
178     theModule->updateObjBrowser();
179     UpdateObjBrowser(theModule);
180     
181     if (SVTK_ViewWindow* aView = GetViewWindow(theModule))
182       aView->onFitAll();
183   }
184
185 }
186
187 #endif