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