]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_Prs3dTools.h
Salome HOME
PAL9807 - some dialogs in VISU must be non-modal
[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 int runAndWait( QDialog* dlg, const bool modal )
35 {
36   if( modal )
37     return dlg->exec();
38
39   dlg->show();
40
41   qApp->enter_loop();
42
43   return dlg->result();
44 }
45
46 namespace VISU
47 {
48   class CutLines_i;
49
50   //---------------------------------------------------------------
51   template<class TPrs3d_i, class TDlg, int IsDlgModal >
52   void
53   EditPrs3d (SalomeApp_Module* theModule, VISU::Prs3d_i* thePrs3d)
54   {
55     TPrs3d_i* aPrsObject = dynamic_cast<TPrs3d_i*>(thePrs3d);
56     if (aPrsObject) {
57       TDlg* aDlg = new TDlg (theModule);
58       aDlg->initFromPrsObject(aPrsObject);
59       if (runAndWait(aDlg,IsDlgModal)) {
60         if (!(aDlg->storeToPrsObject(aPrsObject))) {
61           delete aDlg;
62           return;
63         }
64         RecreateActor(theModule, aPrsObject);
65         if (SVTK_ViewWindow* vw = GetViewWindow(theModule)) {
66           vw->getRenderer()->ResetCameraClippingRange();
67           vw->Repaint();
68         }
69         // Optionally, create table and curves for cut lines
70         QApplication::setOverrideCursor(Qt::waitCursor);
71         CreateCurves( theModule,
72                       dynamic_cast<VISU::CutLines_i*>( aPrsObject ),
73                       aDlg,
74                       false ); // in edition mode
75         QApplication::restoreOverrideCursor();
76       }
77       delete aDlg;
78     }
79   }
80
81
82   //---------------------------------------------------------------
83   template<class TPrs3d_i>
84   TPrs3d_i*
85   CreatePrs3d(SalomeApp_Module* theModule,
86               _PTR(SObject) theTimeStamp,
87               const char* theMeshName,
88               VISU::Entity theEntity,
89               const char* theFieldName,
90               int theTimeId)
91   {
92     VISU::Result_var aResult;
93     if (CheckResult(theModule,theTimeStamp,aResult)){
94       QApplication::setOverrideCursor(Qt::waitCursor);
95       typedef typename TPrs3d_i::TInterface TPrs3d;
96       typename TPrs3d::_var_type aPrs3d =
97         GetVisuGen(theModule)->template Prs3dOnField<TPrs3d_i>
98         (aResult,theMeshName,theEntity,theFieldName,theTimeId);
99       QApplication::restoreOverrideCursor();
100       if (!CORBA::is_nil(aPrs3d.in()))
101         return dynamic_cast<TPrs3d_i*>(VISU::GetServant(aPrs3d.in()).in());
102     }
103     SUIT_MessageBox::warn1(GetDesktop(theModule),
104                            QObject::tr("WRN_VISU"),
105                            QObject::tr("ERR_CANT_BUILD_PRESENTATION"),
106                            QObject::tr("BUT_OK") );
107     return NULL;
108   }
109
110
111   //---------------------------------------------------------------
112   template<class TPrs3d_i, class TDlg, int IsDlgModal>
113   bool
114   CreatePrs3d(SalomeApp_Module* theModule,
115               _PTR(SObject) theTimeStamp,
116               const Handle(SALOME_InteractiveObject)& theIO)
117   {
118     using namespace VISU;
119     Storable::TRestoringMap aMap = getMapOfValue(theTimeStamp);
120     bool isExist;
121     QString aType = Storable::FindValue(aMap,"myType",&isExist);
122     if(!isExist || aType.toInt() != TTIMESTAMP )
123       return false;
124     QString aMeshName = Storable::FindValue(aMap,"myMeshName",&isExist).latin1();
125     QString anEntity = Storable::FindValue(aMap,"myEntityId",&isExist).latin1();
126     QString aFieldName = Storable::FindValue(aMap,"myFieldName",&isExist).latin1();
127     QString aTimeStampId = Storable::FindValue(aMap,"myTimeStampId",&isExist).latin1();
128     QApplication::setOverrideCursor(Qt::waitCursor);
129     
130     TPrs3d_i* aPrs3d =
131       CreatePrs3d<TPrs3d_i>(theModule,
132                             theTimeStamp,
133                             aMeshName.latin1(),
134                             (Entity)anEntity.toInt(),
135                             aFieldName.latin1(),
136                             aTimeStampId.toInt());
137     
138     QApplication::restoreOverrideCursor();
139     if(aPrs3d){
140       SUIT_ResourceMgr* aResourceMgr = GetResourceMgr();
141       int aValue = aResourceMgr->integerValue("VISU","BuildDefaultPrs3d",0);
142       if(!aValue){
143         if(TDlg* aDlg = new TDlg(theModule)){ // dialog box in creation mode
144           aDlg->initFromPrsObject(aPrs3d);
145
146             if(runAndWait(aDlg,IsDlgModal) && (aDlg->storeToPrsObject(aPrs3d))) {
147               // Optionally, create table and curves for cut lines
148               QApplication::setOverrideCursor(Qt::waitCursor);
149               CreateCurves( theModule,
150                             dynamic_cast<VISU::CutLines_i*>( aPrs3d ),
151                             aDlg,
152                             true ); // in creation mode
153               QApplication::restoreOverrideCursor();
154               delete aDlg;
155             } else {
156               DeletePrs3d(theModule,aPrs3d,theIO);
157               delete aDlg;
158               return false;
159             }
160         }
161       }
162       PublishInView(theModule,aPrs3d);
163       return true;
164     }
165     return false;
166   }
167   
168   
169   //---------------------------------------------------------------
170   template<class TPrs3d_i, class TDlg, int IsDlgModal>
171   void
172   CreatePrs3d(SalomeApp_Module* theModule)
173   {
174     if (CheckLock(GetCStudy(GetAppStudy(theModule))))
175       return;
176     
177     _PTR(SObject) aTimeStampSObj;
178     Handle(SALOME_InteractiveObject) anIO;
179     if (!CheckTimeStamp(theModule,aTimeStampSObj,&anIO))
180       return;
181     
182     if (!CreatePrs3d<TPrs3d_i,TDlg,IsDlgModal>(theModule,aTimeStampSObj,anIO))
183       return;
184     
185     theModule->application()->putInfo(QObject::tr("INF_DONE"));
186     theModule->updateObjBrowser();
187     UpdateObjBrowser(theModule);
188     
189     if (SVTK_ViewWindow* aView = GetViewWindow(theModule))
190       aView->onFitAll();
191   }
192
193 }
194
195 #endif