Salome HOME
sources v1.2
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.h
1 //  SMESH SMESHGUI : GUI for SMESH 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   : SMESHGUI.h
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 #ifndef SMESHGUI_HeaderFile
30 #define SMESHGUI_HeaderFile
31
32 #include "TColStd_MapOfInteger.hxx"
33
34 #include "SMESHDS_Document.hxx"
35
36 // SALOME Includes
37 #include "QAD_Desktop.h"
38 #include "SALOME_Selection.h"
39 #include "SALOME_InteractiveObject.hxx"
40
41 #include "SMESH_Actor.h"
42
43 #include "SMESHGUI_StudyAPI.h"
44
45 // IDL Headers
46 #include <SALOMEconfig.h>
47 #include CORBA_SERVER_HEADER(SMESH_Gen)
48 #include CORBA_SERVER_HEADER(SMESH_Mesh)
49 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
50 #include CORBA_SERVER_HEADER(SMESH_BasicHypothesis)
51 #include CORBA_SERVER_HEADER(GEOM_Gen)
52 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
53
54 // QT Includes
55 #include <qstringlist.h>
56
57 // VTK Inlcudes
58 #include <vtkScalarBarActor.h>
59
60 //=================================================================================
61 // class    : SMESHGUI
62 // purpose  :
63 //=================================================================================
64 class SMESHGUI : public QObject
65 {
66   Q_OBJECT
67
68 private :
69     
70   QAD_Desktop*              myDesktop;
71   QAD_Study*                myActiveStudy;
72   SMESH::SMESH_Gen_var      myComponentMesh;
73   GEOM::GEOM_Gen_var        myComponentGeom;
74
75   QDialog*                  myActiveDialogBox;
76   int                       myNbMesh ;
77   int                       myState ;     
78
79   vtkActorCollection*       mySimulationActors;
80   vtkActor2DCollection*     mySimulationActors2D;
81
82   SMESH_Actor*              myCurrentMesh;
83
84   SALOMEDS::Study_var       myStudy;
85   int                       myStudyId;
86
87   SMESHGUI_StudyAPI         myStudyAPI;
88
89   //  vtkScalarBarActor*    myScalarBar;
90
91   Handle_SMESHDS_Document   myDocument;//NBU
92
93   bool                      myAutomaticUpdate;
94
95 public :
96
97   SMESHGUI();
98   ~SMESHGUI();
99
100   static SMESHGUI*    GetOrCreateSMESHGUI( QAD_Desktop* desktop );
101   static SMESHGUI*    GetSMESHGUI() ;
102
103   QAD_Study*          GetActiveStudy() ;
104   QAD_Desktop*        GetDesktop() ;
105   SALOMEDS::Study_ptr GetStudy();
106   SMESHGUI_StudyAPI   GetStudyAPI();
107
108   vtkScalarBarActor*  GetScalarBar();
109
110   QDialog*            GetActiveDialogBox() ;               
111   void                SetActiveDialogBox(QDialog* aDlg) ;  
112
113   void                SetState(int aState) ;
114   void                ResetState() ;                       
115   bool                DefineDlgPosition(QWidget* aDlg, int& x, int& y) ;
116
117
118   /* Managed by IAPP */
119   Standard_EXPORT  static bool OnGUIEvent ( int theCommandID, QAD_Desktop* parent) ; 
120   Standard_EXPORT  static bool OnMousePress ( QMouseEvent* pe, QAD_Desktop* parent, 
121                                               QAD_StudyFrame* studyFrame );
122   Standard_EXPORT  static bool OnMouseMove  ( QMouseEvent* pe, QAD_Desktop* parent, 
123                                               QAD_StudyFrame* studyFrame );
124   Standard_EXPORT  static bool OnKeyPress   ( QKeyEvent* pe, QAD_Desktop* parent, 
125                                               QAD_StudyFrame* studyFrame );
126   Standard_EXPORT  static void activeStudyChanged ( QAD_Desktop* parent ); 
127   Standard_EXPORT  static bool SetSettings ( QAD_Desktop* parent );
128   Standard_EXPORT  static void DefinePopup( QString & theContext, 
129                                             QString & theParent, 
130                                             QString & theObject );
131   Standard_EXPORT  static bool CustomPopup ( QAD_Desktop* parent,
132                                              QPopupMenu* popup,
133                                              const QString& theContext,
134                                              const QString& theParent,
135                                              const QString& theObject );
136   Standard_EXPORT  static void BuildPresentation(const Handle(SALOME_InteractiveObject)&);
137
138   void OnEditDelete();
139
140   /* Mesh Management */
141   SMESH::SMESH_Mesh_ptr       InitMesh( GEOM::GEOM_Shape_ptr aShape, QString NameMesh );
142   SMESH::SMESH_subMesh_ptr    AddSubMesh( SMESH::SMESH_Mesh_ptr aMesh, GEOM::GEOM_Shape_ptr aShape, QString NameMesh );
143
144   /* Hypothesis Management */
145   SMESH::SMESH_Hypothesis_ptr CreateHypothesis( QString TypeHypothesis, QString NameHypothesis );
146   void AddHypothesisOnMesh( SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp ) ;
147   void AddHypothesisOnSubMesh( SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp ) ;
148
149   void RemoveHypothesisOrAlgorithmOnMesh( const Handle(SALOME_InteractiveObject)& IObject ) ;
150   void RemoveHypothesisOrAlgorithmOnMesh( SALOMEDS::SObject_ptr MorSM, SMESH::SMESH_Hypothesis_ptr anHyp ) ;
151
152   void CreateLocalLength( QString TypeHypothesis, QString NameHypothesis, double Length );
153   void CreateNbSegments( QString TypeHypothesis, QString NameHypothesis, double nbSegments );
154   void CreateMaxElementArea( QString TypeHypothesis, QString NameHypothesis, double MaxArea );
155   void CreateMaxElementVolume( QString TypeHypothesis, QString NameHypothesis, double MaxVolume );
156
157   /* Algorithms Management */
158   void AddAlgorithmOnMesh( SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp );
159   void AddAlgorithmOnSubMesh( SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp );
160   void CreateAlgorithm( QString TypeAlgo, QString NameAlgo );
161
162   /* NODES */
163   void ViewNodes();
164   vtkActor* SimulationMoveNode(SMESH_Actor* Mactor, int idnode);
165   void MoveNode( SMESH::SMESH_Mesh_ptr aMesh, int idnode, float x, float y, float z);
166   void AddNode(SMESH_Actor*, int idnode, float x, float y, float z) ; 
167   void AddNodes( SMESH_Actor* Mactor, int number, 
168                  const SMESH::double_array& coords, const SMESH::long_array& indexes);
169
170   void DisplaySimulationNode( SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z);
171   void DisplaySimulationMoveNode( vtkActor* ac, int idnode, float x, float y, float z);
172
173   void RemoveNode(SMESH_Actor*, int idnode) ;
174   void RemoveNodes(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex) ;
175   void RemoveNodes(SMESH_Actor* Mactor, int number, 
176                    const SMESH::double_array& coords, const SMESH::long_array& indexes);
177
178   /* EDGES */
179   void AddEdge(SMESH_Actor*, int idedge, int idnode1, int idnode2) ;
180   void AddEdges( SMESH_Actor* Mactor, int number, 
181                  const SMESH::double_array& coords, const SMESH::long_array& indexes);
182   void DisplayEdges(SMESH_Actor* ac, bool visibility = true);
183   void DisplayEdgesConnectivityLegendBox(vtkActor *ac);
184   void DisplaySimulationEdge( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex );
185
186   /* TRIANGLES */
187   void AddTriangle(SMESH_Actor*, int idtri, int idnode1, int idnode2, int idnode3) ;
188   void AddTriangles( SMESH_Actor* Mactor, int number, 
189                      const SMESH::double_array& coords, const SMESH::long_array& indexes);
190   void DisplaySimulationTriangle( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse );
191
192   /* QUADRANGLES */
193   void AddQuadrangle(SMESH_Actor*, int idquad, int idnode1, int idnode2, 
194                       int idnode3, int idnode4) ;
195   void AddQuadrangles( SMESH_Actor* Mactor, int number, 
196                        const SMESH::double_array& coords, const SMESH::long_array& indexes);
197   void DisplaySimulationQuadrangle( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse );
198
199   /* VOLUMES */
200   void AddTetra(SMESH_Actor*, int idtetra, int idnode1, int idnode2, 
201                  int idnode3, int idnode4) ;
202   void AddHexaedre(SMESH_Actor*, int idhexa, int idnode1, int idnode2, 
203                     int idnode3, int idnode4, int idnode5, int idnode6, int idnode7, int idnode8) ;
204   void AddTetras( SMESH_Actor* Mactor, int number, 
205                        const SMESH::double_array& coords, const SMESH::long_array& indexes);
206   void AddHexaedres( SMESH_Actor* Mactor, int number, 
207                        const SMESH::double_array& coords, const SMESH::long_array& indexes);
208   void DisplaySimulationTetra( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex );
209   void DisplaySimulationHexa( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex );
210
211   /* ELEMENTS */
212   void RemoveElement(SMESH_Actor*, int idnode);
213   void RemoveElements(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex) ;
214   void RemoveElements(SMESH_Actor* Mactor, int number, 
215                       const SMESH::double_array& coords, const SMESH::long_array& indexes);
216   void OrientationElements(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex);
217   void DiagonalInversion(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex);
218
219   void AddFace( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse );
220   void AddEdge( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex );
221   void AddVolume( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex );
222   void AddNode( SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z);
223
224   /* Simulation management */
225   void EraseSimulationActors() ;    
226
227   /* Non modal dialog boxes magement */
228   void EmitSignalDeactivateDialog() ;
229   void EmitSignalCloseAllDialogs() ;
230
231   /* Selection management */
232   int GetNameOfSelectedIObjects( SALOME_Selection* Sel, QString& aName ) ;
233   int GetNameOfSelectedNodes( SALOME_Selection* Sel, QString& aName ) ;
234   int GetNameOfSelectedElements( SALOME_Selection* Sel, QString& aName ) ;
235   int GetNameOfSelectedEdges( SALOME_Selection* Sel, QString& aName ) ;
236
237   SMESH::SMESH_Hypothesis_ptr ConvertIOinSMESHHypothesis( const Handle(SALOME_InteractiveObject)& IO, 
238                                                           Standard_Boolean& testResult ) ;
239
240   SMESH::SMESH_Mesh_ptr       ConvertIOinMesh(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult) ;
241   SMESH::SMESH_subMesh_ptr    ConvertIOinSubMesh(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult) ;
242
243   /* Geometry Client */
244   GEOM::GEOM_Shape_ptr        ConvertIOinGEOMShape( const Handle(SALOME_InteractiveObject)& IO, 
245                                                     Standard_Boolean& testResult ) ;
246
247   /* Popup management */
248   QString CheckTypeObject(const Handle(SALOME_InteractiveObject)& IO);
249   QString CheckHomogeneousSelection();
250
251   /* Scripts management */
252   SMESH_Actor* ReadScript(SMESH::SMESH_Mesh_ptr aMesh);
253
254   /* Actors management */
255   void Dump(SMESH_Actor* Mactor);
256
257   void SetViewMode(int commandId);
258   void ChangeRepresentation( SMESH_Actor* ac, int type );
259
260   SMESH_Actor* FindActor(SMESH::SMESH_Mesh_ptr aMesh, 
261                          Standard_Boolean& testResult,
262                          bool onlyInActiveView);
263   SMESH_Actor* FindActorByEntry(QString entry, 
264                                 Standard_Boolean& testResult,
265                                 bool onlyInActiveView);
266
267   void InitActor(SMESH::SMESH_Mesh_ptr aMesh);
268   void DisplayActor(SMESH_Actor* ac, bool visibility = true);
269   void EraseActor(SMESH_Actor* ac);
270   bool AddActorInSelection(SMESH_Actor* ac);
271
272   void UpdateView();
273
274   void Update();
275   void Update(const Handle(SALOME_InteractiveObject)& IO);
276
277   void ScalarVisibilityOff();
278
279
280   /* Settings management */
281   void SetSettingsScalarBar(vtkScalarBarActor* theScalarBar,
282                             QString Bold, QString Italic, QString Shadow, QString Font, 
283                             QString Orientation, float Width, float Height, 
284                             int NbColors, int NbLabels);
285   void DisplayScalarBar(bool visibility);
286   void UpdateScalarBar(float MinRange, float MaxRange);
287
288   void SetDisplaySettings(); 
289
290   SALOMEDS::Study::ListOfSObject* GetMeshesUsingAlgoOrHypothesis( SMESH::SMESH_Hypothesis_ptr AlgoOrHyp ) ;
291
292   /* Control management */
293   void Control(int theCommandID);
294
295   /* Parameter functions */
296   double Parameter( Standard_Boolean& res, const double aValue,
297                     const char* aLabel,    const char* aTitle,
298                     const double bottom,   const double top, const int decimals ) ;
299   int    Parameter( Standard_Boolean& res, const int aValue,
300                     const char* aLabel,    const char* aTitle,
301                     const int bottom,      const int top ) ;
302
303   static void setOrb();
304
305   /* Import/Export */ //NBU
306   static void Import_Document(QAD_Desktop* parent, int theCommandID);
307   static void Export_Document(QAD_Desktop* parent, int theCommandID);
308   static void Import_Mesh(QAD_Desktop* parent, int theCommandID);
309   static void Export_Mesh(QAD_Desktop* parent, int theCommandID);
310
311 signals:
312   void SignalDeactivateActiveDialog() ;
313   void SignalCloseAllDialogs() ;
314 };
315
316 #endif