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