Salome HOME
716f1acab7bf6276eb1863afc9512a4c8b19f70d
[modules/geom.git] / src / GEOMGUI / GeometryGUI.h
1 //  File      : GeometryGUI.h
2 //  Created   : 
3 //  Author    : Lucien PIGNOLONI
4 //  Project   : SALOME
5 //  Module    : GeometryGUI
6 //  Copyright : OPEN CASCADE
7 //  $Header$
8
9 #ifndef GeometryGUI_HeaderFile
10 #define GeometryGUI_HeaderFile
11
12 // SALOME Includes
13 #include "QAD_Desktop.h"
14 #include "SALOME_Selection.h"
15 #include "SALOME_InteractiveObject.hxx"
16 #include "GEOM_InteractiveObject.hxx"
17 #include "GEOM_AISShape.hxx"
18 #include "GEOM_Actor.h"
19 #include "GEOM_Sketcher.h"
20
21 // Open CASCADE Includes
22 #include <AIS_InteractiveContext.hxx>
23 #include <Standard.hxx>
24 #include <gp_Pnt.hxx>
25 #include <V3d_View.hxx>
26 #include <Quantity_Color.hxx>
27
28 // IDL Headers
29 #include <SALOMEconfig.h>
30 #include CORBA_SERVER_HEADER(GEOM_Gen)
31 #include CORBA_SERVER_HEADER(SALOMEDS)
32 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
33
34 //=================================================================================
35 //
36 //=================================================================================
37   enum  {
38     POINT_METHOD,
39     CURRENT_SKETCH
40   } ;
41
42
43 //=================================================================================
44 // class    : GeometryGUI
45 // purpose  :
46 //=================================================================================
47 class GeometryGUI : public QObject
48 {
49   Q_OBJECT /* for QT compatibility */
50
51 private :
52     
53   QAD_Desktop*          myDesktop;
54   QAD_Study*            myActiveStudy;
55   GEOM::GEOM_Gen_var myComponentGeom;
56   QDialog*              myActiveDialogBox; /* Unique active dialog box */
57   Handle(AIS_Shape)     mySimulationShape; /* AIS shape used only during topo/geom simulations */
58   vtkActorCollection*   mySimulationActor; /* GEOM Actor used only during topo/geom simulations */
59   int                   myNbGeom ;         /* Unique name for a geom entity */
60   int                   myState ;          /* Identify a method */
61   Sketch                mySketcher;
62
63   Quantity_Color        myShadingColor;
64
65 public :
66
67   GeometryGUI();
68   ~GeometryGUI();
69
70   static       GeometryGUI* GetOrCreateGeometryGUI( QAD_Desktop* desktop );
71   static       GeometryGUI* GetGeometryGUI() ;
72
73   QAD_Study*   GetActiveStudy() ;
74   QAD_Desktop* GetDesktop() ;
75
76   QDialog*     GetActiveDialogBox() ;               /* Returns the active DialogBox */
77   void         SetActiveDialogBox(QDialog* aDlg) ;  /* Sets 'myActiveDialogBox' a pointer to the active Dialog Box  */
78
79   void         SetState(int aState) ;
80   void         ResetState() ;                       /* Sets myState = -1 a private field to indicate wich method is active */
81   bool         DefineDlgPosition(QWidget* aDlg, int& x, int& y) ;
82
83   bool SObjectExist(SALOMEDS::SObject_ptr theFatherObject, const char* IOR);
84
85   void OnEditCopy    ();
86   void OnEditDelete  ();
87   void OnVTKDisplayOnly ();
88
89   void OnDisplayOnly ();
90   void OnDisplayAll  ( bool onlyPreviousDisplayedObject = false );
91   void SetDisplayedObjectList();
92  
93   bool AddInStudy( bool selection = false, const Handle(SALOME_InteractiveObject)& anIO = 0 );
94   bool Display( GEOM::GEOM_Shape_ptr aShape, Standard_CString name = "");
95
96   /* Import and export topology methods */
97   bool Import();
98   bool Export(); 
99
100
101   static int    GetIndex(const TopoDS_Shape& subshape, const TopoDS_Shape& shape, int ShapeType) ;
102   static bool   VertexToPoint(const TopoDS_Shape& S, gp_Pnt& P) ;
103   static void   GetBipointDxDyDz( gp_Pnt P1, gp_Pnt P2, double& dx, double& dy, double& dz) ;
104
105   static bool   GetShapeTypeString( const TopoDS_Shape& aShape,  Standard_CString& aTypeString ) ;
106   static bool   LinearEdgeExtremities( const TopoDS_Shape& S, gp_Pnt& P1, gp_Pnt& P2) ;
107
108   static gp_Pnt ConvertClickToPoint( Standard_Real x, Standard_Real y, Handle(V3d_View) aView ) ;
109
110   /* User dialog 1 parameter returned */
111   static double Parameter( Standard_Boolean& res,
112                            const char* aValue1   = 0,
113                            const char* aTitle1   = 0,
114                            const char* aTitle    = 0,
115                            const double bottom   = -1E6,
116                            const double top      = +1E6,
117                            const int  decimals   = 6 ) ;
118
119   /* Managed by IAPP */
120   Standard_EXPORT  static bool OnGUIEvent ( int theCommandID, QAD_Desktop* parent) ; 
121   Standard_EXPORT  static bool OnMousePress ( QMouseEvent* pe, QAD_Desktop* parent, 
122                                               QAD_StudyFrame* studyFrame );
123   Standard_EXPORT  static bool OnMouseMove  ( QMouseEvent* pe, QAD_Desktop* parent, 
124                                               QAD_StudyFrame* studyFrame );
125   Standard_EXPORT  static bool OnKeyPress   ( QKeyEvent* pe, QAD_Desktop* parent, 
126                                               QAD_StudyFrame* studyFrame );
127   Standard_EXPORT  static void activeStudyChanged ( QAD_Desktop* parent ); 
128   Standard_EXPORT  static bool SetSettings ( QAD_Desktop* parent );
129   Standard_EXPORT  static void DefinePopup( QString & theContext, 
130                                             QString & theParent, 
131                                             QString & theObject );
132   Standard_EXPORT  static bool CustomPopup ( QAD_Desktop* parent,
133                                              QPopupMenu* popup,
134                                              const QString& theContext,
135                                              const QString& theParent,
136                                              const QString& theObject );
137   Standard_EXPORT  static void BuildPresentation(const Handle(SALOME_InteractiveObject)&);
138
139   void Archimede( const Handle(SALOME_InteractiveObject)& IO, const double aWeight,
140                   const double aWaterDensity, const double aMeshingDeflection );
141   
142   void MakePointAndDisplay( const double x, const double y, const double z ) ;
143   void MakeVectorAndDisplay( const gp_Pnt P1, const gp_Pnt P2 );
144   void MakeBoxAndDisplay( const gp_Pnt P1, const gp_Pnt P2 ) ;
145   void MakePlaneAndDisplay( const gp_Pnt P1, const Standard_Real dx, 
146                             const Standard_Real dy, const Standard_Real dz, const Standard_Real TrimSize ) ;
147   void MakeSphereAndDisplay( const gp_Pnt aCenterPoint, const double aRadius) ;
148   void MakeCircleAndDisplay( const gp_Pnt CenterPoint, const gp_Dir dir, const Standard_Real Radius) ;
149   void MakeArcAndDisplay( gp_Pnt InitPoint, gp_Pnt CirclePoint, gp_Pnt EndPoint ) ;
150   void MakeLineAndDisplay( const gp_Pnt InitPoint, const gp_Pnt LastPoint) ;
151   void MakeCylinderAndDisplay( const gp_Pnt BasePoint, const gp_Dir aDir, 
152                                const double Radius, const double aHeight ) ;
153   void MakeConeAndDisplay( const gp_Pnt BasePoint, const gp_Dir aDir, 
154                            const double Radius1, const double Radius2, const double aHeight ) ;
155   void MakeTorusAndDisplay( const gp_Pnt BasePoint, const gp_Dir aDir, 
156                             const double Radius1, const double Radius2 ) ;
157   void MakeBooleanAndDisplay( GEOM::GEOM_Shape_ptr Shape1, GEOM::GEOM_Shape_ptr Shape2, 
158                               const short operation ) ;
159   void MakeRevolutionAndDisplay( GEOM::GEOM_Shape_ptr Shape, const gp_Pnt loc, 
160                                  const gp_Dir dir, Standard_Real revolAngle ) ;
161   void MakePrismAndDisplay( GEOM::GEOM_Shape_ptr BaseShape, const gp_Pnt P1, const gp_Pnt P2 ) ;
162   void MakePipeAndDisplay( GEOM::GEOM_Shape_ptr aPath, GEOM::GEOM_Shape_ptr aBase ) ;
163   void MakeFillingAndDisplay( GEOM::GEOM_Shape_ptr SectionShape, const short mindeg, const short maxdeg, 
164                               const double tol3d, const double tol2d, const short nbiter ) ;
165   void MakeRotationAndDisplay( GEOM::GEOM_Shape_ptr Shape, const gp_Pnt loc, const gp_Dir dir, 
166                                const Standard_Real angle ) ;
167   void MakeTranslationAndDisplay( GEOM::GEOM_Shape_ptr Shape, const gp_Vec V) ;
168
169   void MakeMultiTranslation1DAndDisplay( GEOM::GEOM_Shape_ptr Shape, const gp_Dir Dir, const double Step, const short NbTimes ) ;
170   void MakeMultiTranslation2DAndDisplay( GEOM::GEOM_Shape_ptr Shape, const gp_Dir Dir1, const double Step1, const short NbTimes1,
171                                          const gp_Dir Dir2, const double Step2, const short NbTimes2 ) ;
172   void MakeMultiRotation1DAndDisplay( GEOM::GEOM_Shape_ptr Shape, const gp_Dir Dir, const gp_Pnt Loc, const short NbTimes ) ;
173   void MakeMultiRotation2DAndDisplay( GEOM::GEOM_Shape_ptr Shape, const gp_Dir Dir, const gp_Pnt Loc, const double Ang,
174                                       const short NbTimes1, const double Step, const short NbTimes2 ) ;
175   void MakeCDGAndDisplay( GEOM::GEOM_Shape_ptr Shape );
176   void MakeScaleAndDisplay( GEOM::GEOM_Shape_ptr Shape, const gp_Pnt centralPoint, 
177                             const Standard_Real factor) ;
178   void MakeMirrorAndDisplay( GEOM::GEOM_Shape_ptr Shape1, GEOM::GEOM_Shape_ptr Shape2 ) ;
179   void MakeSewingAndDisplay( GEOM::GEOM_Gen::ListOfIOR& listShapesIOR, 
180                              const Standard_Real precision ) ;
181   void MakeCompoundAndDisplay( GEOM::GEOM_Gen::ListOfIOR& listShapesIOR ) ;
182   void MakeLinearEdgeAndDisplay( const gp_Pnt P1, const gp_Pnt P2 ) ;
183   void MakeOrientationChangeAndDisplay( GEOM::GEOM_Shape_ptr Shape ) ;
184
185   void MakePartitionAndDisplay (const GEOM::GEOM_Gen::ListOfIOR& listShapesIOR,
186                                 const GEOM::GEOM_Gen::ListOfIOR& listToolsIOR,
187                                 const GEOM::GEOM_Gen::ListOfIOR& listKeepInsIOR,
188                                 const GEOM::GEOM_Gen::ListOfIOR& listRemoveInsIOR,
189                                 const GEOM::shape_type           limit ) ;
190
191   void MakeWireAndDisplay( GEOM::GEOM_Gen::ListOfIOR& listShapesIOR ) ;
192   void MakeWorkingPlane( const gp_Pnt P, const gp_Dir D) ;
193   void MakeFaceAndDisplay( GEOM::GEOM_Shape_ptr aWire, const Standard_Boolean wantPlanar ) ;
194
195   /* Simulation management */
196   bool CreateArrowForLinearEdge( const TopoDS_Shape& tds, TopoDS_Shape& ArrowCone ) ;
197   void DisplaySimulationShape(const TopoDS_Shape& S) ; 
198   void EraseSimulationShape() ;    
199
200   /* Selection and objects management */
201
202   TopoDS_Shape GetShapeFromIOR( QString IOR );
203   bool GetTopoFromSelection(SALOME_Selection *Sel, TopoDS_Shape& tds) ;
204   int  GetNameOfSelectedIObjects( SALOME_Selection* Sel, QString& aName ) ; 
205   GEOM::GEOM_Shape_ptr ConvertIOinGEOMShape( const Handle(SALOME_InteractiveObject)& IO, 
206                                        Standard_Boolean& testResult ) ;  
207
208   Handle(GEOM_AISShape) ConvertIOinGEOMAISShape( const Handle(SALOME_InteractiveObject)& IO, 
209                                                  Standard_Boolean& testResult,
210                                                  bool onlyInActiveView = false ) ; 
211   Handle(GEOM_AISShape) ConvertIORinGEOMAISShape( const char * IOR, 
212                                                   Standard_Boolean& testResult,
213                                                   bool onlyInActiveView = false ) ; 
214
215   GEOM_Actor* ConvertIORinGEOMActor( const char * IOR, 
216                                      Standard_Boolean& testResult,
217                                      bool onlyInActiveView = false ) ;
218  
219   void ConvertListOfIOInListOfIOR( const SALOME_ListIO& aList, 
220                                    GEOM::GEOM_Gen::ListOfIOR& listIOR ) ; 
221
222   /* Method used by dialog boxes called when used has entered a name of object in a LineEdit */
223   bool SelectionByNameInDialogs( QWidget* aWidget, const QString& userObjectName, SALOME_Selection *Sel ) ;
224
225   /* Method opening context for any sub shape selection */
226   bool PrepareSubShapeSelection( const int SubShapeType, 
227                                  Standard_Integer& returnLocalContextId ) ;
228
229   /* Method opening context for sub shape selection on an argument shape */
230   bool PrepareSubShapeSelectionArgumentShape( const TopoDS_Shape& aShape,
231                                               const int SubShapeType, 
232                                               Standard_Integer& returnLocalContextId ) ;
233
234   
235   /* Define a list of indices of sub shapes selected in a local context */
236   bool GetIndexSubShapeSelected( const TopoDS_Shape& ShapeTopo,
237                                  const int SubShapeType,
238                                  GEOM::GEOM_Shape::ListOfSubShapeID& ListOfID,
239                                  Standard_Integer& aLocalContextId,
240                                  bool& myUseLocalContext ) ;
241   
242   /* Methods for sub shapes explode */
243   bool OnSubShapeGetAll( const TopoDS_Shape& ShapeTopo, const char* ShapeTopoIOR, const int SubShapeType) ;  
244   bool OnSubShapeGetSelected( const TopoDS_Shape& ShapeTopo,
245                               const char* ShapeTopoIOR,
246                               const int SubShapeType,
247                               Standard_Integer& aLocalContextId,
248                               bool& myUseLocalContext ) ;
249
250   /* Remove faces in a shape */
251   bool OnSuppressFaces( const TopoDS_Shape& ShapeTopo,
252                         const char* ShapeTopoIOR,
253                         const Standard_Integer& aLocalContextId,
254                         bool& myUseLocalContext ) ;
255
256   /* Remove an hole in a topology  (ListOfIdEndFace may be an empty list ) */  
257   bool OnSuppressHole( const char* ShapeTopoIOR,
258                        const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdFace,
259                        const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdWire,
260                        const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdEndFace ) ;
261   
262   /* Remove one or more holes in a face or a shell */
263   bool OnSuppressHolesInFaceOrShell( const char* ShapeTopoIOR,
264                                      const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdWires ) ;
265   
266   /* Create a face corresponding to a hole on a shape */
267   bool OnFillingHole( const TopoDS_Shape& MainShape,
268                       const char* ShapeTopoIOR,
269                       const Standard_Integer& aLocalContextId,
270                       bool& myUseLocalContext ) ;
271   
272   /* Method for Fillet */
273   bool OnFilletGetAll(const TopoDS_Shape& ShapeTopo, const double Radius, const int SubShapeType, const char* ShapeTopoIOR) ;
274   bool OnFilletGetSelected(const TopoDS_Shape& ShapeTopo,
275                            const char* ShapeTopoIOR,
276                            const double Radius,
277                            const int SubShapeType,
278                            Standard_Integer& aLocalContextId,
279                            bool& myUseLocalContext );
280
281   /* Methods for Chamfer */
282   bool OnChamferGetAll(const TopoDS_Shape& ShapeTopo, const double D1, const double D2, const int SubShapeType, const char* ShapeTopoIOR) ;
283   bool OnChamferGetSelected(const TopoDS_Shape& ShapeTopo,
284                             const char* ShapeTopoIOR,
285                             const double D1, const double D2, const int SubShapeType,
286                             Standard_Integer& aLocalContextId,
287                             bool& myUseLocalContext ) ;
288
289   /* Non modal dialog boxes magement */
290   void EmitSignalDeactivateDialog() ;
291   void EmitSignalCloseAllDialogs() ;
292  
293   /* Sketcher management */
294   void OnSketchSegment();
295   void OnSketchArc();  
296   void OnSketchSetAngle();
297   void OnSketchSetx();
298   void OnSketchSety();
299   
300   void OnSketchDelete();
301   void OnSketchClose();
302   void OnSketchEnd();
303   
304   void OnSketchOptionsOnoffangledimension();
305   void OnSketchOptionsOnofflengthdimension();
306   void OnSketchOptionsOnoffradiusdimension();
307   void OnSketchOptionsOnoffxdimension();
308   void OnSketchOptionsOnoffydimension();
309   
310   void OnSettingsNoconstraint();
311   void OnSettingsPerpendicular();
312   void OnSettingsTangent();
313
314 signals:
315   void SignalDeactivateActiveDialog() ;
316   void SignalCloseAllDialogs() ;
317   void SignalDefaultStepValueChanged( double newVal ) ;
318 };
319
320 #endif
321