Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[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 #include <map>
34
35 #include "SMESHDS_Document.hxx"
36
37 // SALOME Includes
38 #include "SALOMEGUI.h"
39 #include "QAD_Desktop.h"
40 #include "SALOME_Selection.h"
41 #include "SALOME_InteractiveObject.hxx"
42
43 #include "SMESHGUI_StudyAPI.h"
44 #include "SMESHGUI_Hypotheses.h"
45
46 // IDL Headers
47 #include <SALOMEconfig.h>
48 #include CORBA_SERVER_HEADER(SMESH_Gen)
49 #include CORBA_SERVER_HEADER(SMESH_Mesh)
50 #include CORBA_SERVER_HEADER(SMESH_Group)
51 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
52 #include CORBA_SERVER_HEADER(GEOM_Gen)
53 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
54 #include CORBA_SERVER_HEADER(SMESH_Filter)
55
56 // QT Includes
57 #include <qstringlist.h>
58
59 // VTK Inlcludes
60
61 class vtkActorCollection;
62 class vtkActor2DCollection;
63 class vtkScalarBarActor;
64 class vtkActor;
65
66 class SMESH_Actor;
67
68 //=================================================================================
69 // class    : SMESHGUI
70 // purpose  :
71 //=================================================================================
72 class SMESHGUI : public SALOMEGUI
73 {
74   Q_OBJECT
75
76 private :
77     
78   QAD_Desktop*              myDesktop;
79   QAD_Study*                myActiveStudy;
80   SMESH::SMESH_Gen_var      myComponentMesh;
81   GEOM::GEOM_Gen_var        myComponentGeom;
82
83   QDialog*                  myActiveDialogBox;
84   int                       myNbMesh ;
85   int                       myState ;     
86
87   vtkActorCollection*       mySimulationActors;
88   vtkActor2DCollection*     mySimulationActors2D;
89
90   SMESH_Actor*              myCurrentMesh;
91
92   SALOMEDS::Study_var       myStudy;
93   int                       myStudyId;
94
95   SMESHGUI_StudyAPI         myStudyAPI;
96
97   //  vtkScalarBarActor*    myScalarBar;
98
99   SMESHDS_Document *        myDocument;//NBU
100
101   bool                      myAutomaticUpdate;
102
103   SMESH::FilterManager_var  myFilterMgr;
104
105   // Hypotheses/algorithms from plugin libraries
106   map<string, HypothesisData*>                    myHypothesesMap;
107   map<string, HypothesisData*>                    myAlgorithmsMap;
108   map<string, SMESHGUI_GenericHypothesisCreator*> myHypCreatorMap;
109
110 public :
111
112   SMESHGUI( const QString& name = "", QObject* parent = 0 );
113   ~SMESHGUI();
114
115   static SMESHGUI*    GetOrCreateSMESHGUI( QAD_Desktop* desktop );
116   static SMESHGUI*    GetSMESHGUI() ;
117
118   QAD_Study*          GetActiveStudy() ;
119   QAD_Desktop*        GetDesktop() ;
120   SALOMEDS::Study_ptr GetStudy();
121   SMESHGUI_StudyAPI   GetStudyAPI();
122
123   QDialog*            GetActiveDialogBox() ;               
124   void                SetActiveDialogBox(QDialog* aDlg) ;  
125
126   void                SetState(int aState) ;
127   void                ResetState() ;                       
128   bool                DefineDlgPosition(QWidget* aDlg, int& x, int& y) ;
129
130
131   virtual bool OnGUIEvent        (int theCommandID, QAD_Desktop* parent);
132   virtual bool OnMousePress      (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame);
133   virtual bool OnMouseMove       (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame);
134   virtual bool OnKeyPress        (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame);
135   virtual bool ActiveStudyChanged( QAD_Desktop* parent );
136   virtual bool SetSettings       ( QAD_Desktop* parent );
137   virtual void DefinePopup       ( QString & theContext, QString & theParent, QString & theObject );
138   virtual bool CustomPopup       ( QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext,
139                                    const QString & theParent, const QString & theObject );
140   virtual void BuildPresentation ( const Handle(SALOME_InteractiveObject)& theIO );
141   virtual void SupportedViewType (int* buffer, int bufferSize);
142   virtual void Deactivate        ();
143
144   void OnEditDelete();
145
146   /* Mesh Management */
147   SMESH::SMESH_Mesh_ptr       InitMesh( GEOM::GEOM_Shape_ptr aShape, QString NameMesh );
148   SMESH::SMESH_subMesh_ptr    AddSubMesh( SMESH::SMESH_Mesh_ptr aMesh, GEOM::GEOM_Shape_ptr aShape, QString NameMesh );
149   SMESH::SMESH_Group_ptr      AddGroup( SMESH::SMESH_Mesh_ptr aMesh, SMESH::ElementType aType, QString aName );
150
151   /* Hypotheses and Algorithms Management */
152   void InitAvailableHypotheses ();
153   QStringList GetAvailableHypotheses (const bool isAlgo);
154   HypothesisData* GetHypothesisData (const char* aHypType);
155   SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator (const QString& aHypType);
156
157   SMESH::SMESH_Hypothesis_ptr CreateHypothesis (const QString& aHypType,
158                                                 const QString& aHypName,
159                                                 const bool     isAlgo = false);
160
161   bool AddHypothesisOnMesh (SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp);
162   bool AddAlgorithmOnMesh  (SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp);
163
164   bool AddHypothesisOnSubMesh (SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp);
165   bool AddAlgorithmOnSubMesh  (SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp);
166
167   bool RemoveHypothesisOrAlgorithmOnMesh (const Handle(SALOME_InteractiveObject)& IObject);
168   bool RemoveHypothesisOrAlgorithmOnMesh (SALOMEDS::SObject_ptr MorSM,
169                                           SMESH::SMESH_Hypothesis_ptr anHyp);
170
171   void SetPickable(SMESH_Actor* theActor = NULL);
172
173   /* NODES */
174   void ViewNodes();
175   vtkActor* SimulationMoveNode(SMESH_Actor* Mactor, int idnode);
176   void MoveNode( SMESH::SMESH_Mesh_ptr aMesh, int idnode, float x, float y, float z);
177
178   void DisplaySimulationNode( SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z);
179   void DisplaySimulationMoveNode( vtkActor* ac, int idnode, float x, float y, float z);
180
181   void RemoveNodes(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex) ;
182
183   /* EDGES */
184   void DisplayEdges(SMESH_Actor* ac, bool visibility = true);
185   void DisplayEdgesConnectivityLegendBox(vtkActor *ac);
186   void DisplaySimulationEdge( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex );
187
188   /* TRIANGLES */
189   void DisplaySimulationTriangle( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse );
190
191   /* QUADRANGLES */
192   void DisplaySimulationQuadrangle( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse );
193
194   /* VOLUMES */
195   void DisplaySimulationTetra( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex );
196   void DisplaySimulationHexa( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex );
197
198   /* ELEMENTS */
199   void RemoveElements(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex) ;
200   void OrientationElements(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex);
201   void DiagonalInversion(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex);
202
203   void AddFace( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse );
204   void AddEdge( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex );
205   void AddVolume( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex );
206   void AddNode( SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z);
207
208   /* Simulation management */
209   void EraseSimulationActors() ;    
210
211   /* Non modal dialog boxes magement */
212   void EmitSignalDeactivateDialog() ;
213   void EmitSignalCloseAllDialogs() ;
214
215   /* Selection management */
216   int GetNameOfSelectedIObjects( SALOME_Selection* Sel, QString& aName ) ;
217   int GetNameOfSelectedNodes( SALOME_Selection* Sel, QString& aName ) ;
218   int GetNameOfSelectedElements( SALOME_Selection* Sel, QString& aName ) ;
219   int GetNameOfSelectedEdges( SALOME_Selection* Sel, QString& aName ) ;
220
221   SMESH::SMESH_Hypothesis_ptr ConvertIOinSMESHHypothesis( const Handle(SALOME_InteractiveObject)& IO, 
222                                                           Standard_Boolean& testResult ) ;
223
224   SMESH::SMESH_Mesh_ptr       ConvertIOinMesh(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult) ;
225   SMESH::SMESH_subMesh_ptr    ConvertIOinSubMesh(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult) ;
226   SMESH::SMESH_Group_ptr      ConvertIOinSMESHGroup(const Handle(SALOME_InteractiveObject)& IO, Standard_Boolean& testResult) ;
227
228   /* Geometry Client */
229   GEOM::GEOM_Shape_ptr        ConvertIOinGEOMShape( const Handle(SALOME_InteractiveObject)& IO, 
230                                                     Standard_Boolean& testResult ) ;
231
232   /* Popup management */
233   QString CheckTypeObject(const Handle(SALOME_InteractiveObject)& IO);
234   QString CheckHomogeneousSelection();
235
236   /* Scripts management */
237   SMESH_Actor* ReadScript(SMESH::SMESH_Mesh_ptr aMesh);
238
239   /* Actors management */
240   void Dump(SMESH_Actor* Mactor);
241
242   void SetViewMode(int commandId);
243   void ChangeRepresentation( SMESH_Actor* ac, int type );
244
245   SMESH_Actor* FindActor(CORBA::Object_ptr theObj, 
246                          Standard_Boolean& testResult,
247                          bool onlyInActiveView);
248   SMESH_Actor* FindActorByEntry(QString entry, 
249                                 Standard_Boolean& testResult,
250                                 bool onlyInActiveView);
251
252   void InitActor(SMESH::SMESH_Mesh_ptr aMesh);
253   void DisplayActor(SMESH_Actor* ac, bool visibility = true);
254   void EraseActor(SMESH_Actor* ac);
255   bool AddActorInSelection(SMESH_Actor* ac);
256
257   void UpdateView();
258
259   void Update();
260   void Update(const Handle(SALOME_InteractiveObject)& IO);
261
262   void ScalarVisibilityOff();
263
264
265   /* Settings management */
266   void SetSettingsScalarBar(vtkScalarBarActor* theScalarBar,
267                             QString Bold, QString Italic, QString Shadow, QString Font, 
268                             QString Orientation, float Width, float Height, 
269                             int NbColors, int NbLabels);
270   void SetDisplaySettings();    
271
272   SALOMEDS::Study::ListOfSObject* GetMeshesUsingAlgoOrHypothesis( SMESH::SMESH_Hypothesis_ptr AlgoOrHyp ) ;
273
274   /* Control management */
275   void Control(int theCommandID);
276
277   /* Parameter functions */
278   double Parameter( Standard_Boolean& res, const double aValue,
279                     const char* aLabel,    const char* aTitle,
280                     const double bottom,   const double top, const int decimals ) ;
281   int    Parameter( Standard_Boolean& res, const int aValue,
282                     const char* aLabel,    const char* aTitle,
283                     const int bottom,      const int top ) ;
284
285   static void setOrb();
286
287   /* Import/Export */ //NBU
288   static void Import_Mesh(QAD_Desktop* parent, int theCommandID);
289   static void Export_Mesh(QAD_Desktop* parent, int theCommandID);
290
291   /* Filter manager */
292   SMESH::FilterManager_ptr GetFilterMgr();
293
294 signals:
295   void SignalDeactivateActiveDialog() ;
296   void SignalCloseAllDialogs() ;
297 };
298
299 #endif