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