Salome HOME
Slight improvement and refactoring of dimension displaying
[modules/geom.git] / src / EntityGUI / EntityGUI_3DSketcherDlg.h
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18
19 // GEOM GEOMGUI : GUI for Geometry component
20 // File   : EntityGUI_3DSketcherDlg.h
21 // Author : DMV, OCN
22
23 #ifndef ENTITYGUI_3DSKETCHERDLG_H
24 #define ENTITYGUI_3DSKETCHERDLG_H
25
26 #include <GEOMBase_Skeleton.h>
27
28 class QButtonGroup;
29 class QDoubleSpinBox;
30 class EntityGUI_3Spin;
31 class EntityGUI_Type;
32 class EntityGUI_Angles;
33 class EntityGUI_Controls;
34 class SOCC_Prs;
35 class gp_Dir;
36
37 #include <AIS_ListOfInteractive.hxx>
38 #include <AIS_AngleDimension.hxx>
39 #include <AIS_LengthDimension.hxx>
40
41 #ifndef COORD_MIN
42 #  define COORD_MIN -1e+15
43 #  define COORD_MAX +1e+15
44 #  define MAX_NUMBER 100000
45 #  define DBL_DIGITS_DISPLAY 16
46 #endif // COORD_MIN
47
48 // For convenience
49 bool isSame (double d1, double d2);
50
51 //=================================================================================
52 // class    : EntityGUI_Dlg
53 // purpose  :
54 //=================================================================================
55 class EntityGUI_3DSketcherDlg : public GEOMBase_Skeleton
56
57   Q_OBJECT
58
59   struct XYZ
60   {
61     XYZ() { x = y = z = 0.0; command = params = ""; L=A=0; }
62     double  x,  y,  z; // for preview only
63     int L, A;          // for preview only
64     QString command;
65     QString params;
66   };
67   
68   struct prsType
69   {
70     prsType(){L=A=0;}
71     int L;
72     int A;
73   };
74   
75   typedef QList<XYZ> XYZList;
76
77 public:
78   EntityGUI_3DSketcherDlg (GeometryGUI*, QWidget* = 0, bool = false, Qt::WindowFlags = 0, const double = 2.);
79   ~EntityGUI_3DSketcherDlg();
80
81 protected:
82  
83   // redefined from GEOMBase_Helper
84   virtual GEOM::GEOM_IOperations_ptr createOperation();
85   virtual bool                       isValid( QString& );
86   virtual bool                       execute( ObjectList& );
87
88 private:
89   void                               Init();
90   void                               enterEvent( QEvent* );
91
92   virtual void                       displayPreview( GEOM::GEOM_Object_ptr,
93                                                      const bool = false,
94                                                      const bool = false,
95                                                      const bool = true,
96                                                      const double = -1,
97                                                      const int  = -1,
98                                                      const int  = -1);
99   
100   Handle(AIS_LengthDimension)        createAISLengthDimension(double theLength, 
101                                                               gp_Pnt P1, 
102                                                               gp_Pnt P2,
103                                                               gp_Dir theNormal);  
104   
105   Handle(AIS_AngleDimension)         createAISAngleDimension(double theAngle, 
106                                                              gp_Pnt P0, 
107                                                              gp_Pnt P1,
108                                                              gp_Pnt P2);
109   
110   void                               displayAngle(double theAngle, 
111                                                   gp_Pnt P0, 
112                                                   gp_Pnt P1,
113                                                   gp_Pnt P2, 
114                                                   bool store = false);
115   
116   void                               displayLength(gp_Pnt P1,
117                                                    gp_Pnt P2,
118                                                    gp_Dir theNormal,
119                                                    bool store = false);
120   
121   void                               displayTrihedron( int );
122   
123   void                               displayDimensions(bool store = false);
124
125   bool                               createShapes( GEOM::GEOM_Object_ptr,
126                                                    TopoDS_Shape&,
127                                                    TopoDS_Shape& );
128
129   XYZ                                getLastPoint() const;
130   XYZ                                getPenultimatePoint() const;
131   XYZ                                getCurrentPoint() const;
132   
133   gp_Dir                             getPresentationPlane() const;
134   
135   std::string                        doubleToString( double );
136   
137   gp_Trsf                            toReferenceSystem(gp_Pnt origin) const;
138   gp_Trsf                            toCurrentSystem(gp_Pnt origin) const;
139   
140   void                               removeLastIOFromPrs();
141   void                               restoreLastIOToPrs();
142   
143   double                             radius(gp_Pnt) const;
144   double                             height(gp_Pnt) const;
145   double                             longitude(gp_Pnt) const;
146   double                             latitude(gp_Pnt) const;
147
148 private:
149   XYZList                            myPointsList;
150   XYZList                            myRedoList;
151   AIS_ListOfInteractive              myLengthIORedoList;
152   AIS_ListOfInteractive              myAngleIORedoList;
153   prsType                            myPrsType;
154
155   EntityGUI_3Spin*                   Group3Spin;
156   EntityGUI_Angles*                  GroupAngles;
157   EntityGUI_Controls*                GroupControls;
158   EntityGUI_Type*                    GroupType;
159   QButtonGroup*                      myTypeGroup1;
160   QButtonGroup*                      myTypeGroup2;
161
162   int                                myMode;
163   int                                myCoordType;
164   int                                myOrientation;
165   bool                               myOK;
166   bool                               isLengthVisible;
167   bool                               isAngleVisible;
168   
169   double                             myLineWidth;
170   GeometryGUI*                       myGeometryGUI;
171   SOCC_Prs*                          myAnglePrs;
172   SOCC_Prs*                          myLengthPrs;
173
174 private slots:
175   void                               ClickOnOk();
176   void                               ClickOnAddPoint();
177   bool                               ClickOnApply();
178   //  bool                               isSameAsPrevious();
179   void                               UpdateButtonsState();
180   void                               UpdatePointCoordinates();
181
182   void                               ClickOnUndo();
183   void                               ClickOnRedo();
184
185   void                               SelectionIntoArgument();
186   void                               DeactivateActiveDialog();
187   void                               ActivateThisDialog();
188   void                               TypeClicked( int );
189   void                               ValueChangedInSpinBox( double );
190   void                               ButtonClicked( bool );
191   void                               BoxChecked ( bool );
192   void                               SetDoubleSpinBoxStep( double );
193 };
194
195 #endif // ENTITYGUI_SKETCHERDLG_H