Salome HOME
NRI : Merge from V1_2.
[modules/geom.git] / src / SKETCHER / GEOM_Sketcher.h
1 //  GEOM SKETCHER : basic sketcher
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   : GEOM_Sketcher.h
25 //  Author : Nicolas REJNERI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "GEOM_SketcherStatus.h"
30
31 #include <V3d_Viewer.hxx>
32 #include <V3d_View.hxx>
33 #include <BRepBuilderAPI_MakeWire.hxx>
34 #include <Geom_Plane.hxx>
35 #include <AIS_InteractiveContext.hxx>
36 #include <AIS_Shape.hxx>
37 #include <AIS_Axis.hxx>
38 #include <TopoDS_Edge.hxx>
39 #include <AIS_LengthDimension.hxx>
40 #include <AIS_RadiusDimension.hxx>
41 #include <AIS_AngleDimension.hxx>
42 #include <Geom2d_Line.hxx>
43 #include <TColStd_SequenceOfInteger.hxx>
44 #include <TColgp_SequenceOfPnt2d.hxx>
45 #include <gp_Vec2d.hxx>
46
47 class Sketch  
48 {
49 public:
50         Sketch();
51         ~Sketch();
52         Sketch(const Handle(V3d_Viewer)& aViewer);
53         Sketch(const Handle(V3d_Viewer)& aViewer, 
54                        const Quantity_Color& anAxisColor,
55                        const Quantity_Color& aCurrentColor,
56                        const Quantity_Color& aWireColor);
57
58         static void fitInResol(Standard_Real &toFit, 
59                                Standard_Boolean minIsResol = Standard_False);
60
61         void MakeCurrentEdge(const Standard_Integer  Xp   ,
62                                      const Standard_Integer  Yp   ,
63                                      const Handle(V3d_View)& aView );
64         
65         void MakeCurrentEdge(const Standard_Real  X, const Standard_Real Y);
66
67         Standard_Boolean SetDimension(Standard_Real& aValue); 
68         void SetDimension(Standard_Real& deltaX,Standard_Real& deltaY);
69
70         void SetXDimension(Standard_Real& deltaX);
71         void SetYDimension(Standard_Real& deltaY);
72
73         void SetSegmentAngle(Standard_Real& aValue); 
74         Standard_Real GetSegmentAngle();
75
76         void ValidateEdge();
77
78         TopoDS_Wire Close();
79         TopoDS_Wire End();
80
81         void Clear();
82
83         Standard_Boolean Delete();
84
85         void SetPlane(const Handle(Geom_Plane)& aPlane);
86
87         void SetWireColor(const Quantity_Color& aColor);
88         void SetCurrentColor(const Quantity_Color& aColor);
89         void SetAxisColor(const Quantity_Color& aColor);
90
91         void SetParameterVisibility(const TypeOfParameter atype, 
92                                             const Standard_Boolean OnOff);
93
94         void HiligthWithColor(const TypeOfParameter atype, 
95                                       const Quantity_NameOfColor acolor);
96         void Unhiligth(const TypeOfParameter atype);
97
98         Standard_Boolean IsValidCurrentParameter(const TypeOfParameter atype);
99
100         void SetParameterValue(const TypeOfParameter atype, Standard_Real aValue);
101
102         void ChangeMode(const SketchStatus aMode);
103
104         void SetTransitionStatus(const TransitionStatus aStatus);
105
106         SketchStatus GetCurrentStatus(); 
107         Standard_Integer GetmyEdgesNumber();
108
109 private :
110         
111         void Init();
112
113         void MakeCurrentSegment(Standard_Real X, Standard_Real Y);
114
115         void MakeCurrentArc(Standard_Real X, Standard_Real Y);
116
117         void DisplayCurrentEdge();
118
119         void DisplayLengthDimension(const TopoDS_Vertex& V1,const TopoDS_Vertex& V2);
120         void DisplayXDimension(const TopoDS_Vertex& V1,const TopoDS_Vertex& V2);
121         void DisplayYDimension(const TopoDS_Vertex& V1,const TopoDS_Vertex& V2);
122         void DisplayAngleDimension();
123         void DisplayRadiusDimension();
124
125         void AddEdgeToWire();
126
127         void RemoveLastEdge();
128
129         void CreateConstraints();
130
131 private:
132         // Current status of construction
133         SketchStatus myCurrentStatus; 
134         // Transition status between arcs and segments
135         TransitionStatus myTransitionStatus;  
136         // Current wire
137         BRepBuilderAPI_MakeWire myCurrentWire;
138         // Current presentable wire
139         Handle_AIS_Shape myPresentableWire;   
140         // Number of edges into the current wire
141         Standard_Integer myEdgesNumber;       
142         // Store for each edge how it has been built i.d the value of myCurrentStatus
143         TColStd_SequenceOfInteger myConstructionMode; 
144         // Store for each edge how it has been built i.d the value of myTransitionStatus
145         TColStd_SequenceOfInteger myConstraintMode;  
146         // Current edge 
147         TopoDS_Shape myCurrentEdge; 
148         // Previous edge
149         TopoDS_Edge myPreviousEdge; 
150         // List of points to interpolate when computing a curve by interpolation
151         TColgp_SequenceOfPnt2d myPointsToInterpolate; 
152         // Tangent vector at beginning of curve
153         gp_Vec2d myTangentVector;         
154         // Tangent flag at beginning og curve
155         Standard_Boolean myTangentFlag;   
156         
157         // Origin of sketch
158         TopoDS_Vertex myFirstPointSketch; 
159         // Last x coordinate of end point of previous edge or picked point
160         Standard_Real myLastX; 
161         // Last y coordinate of end point of previous edge or picked point
162         Standard_Real myLastY; 
163         // angle between 2 segments when an ANGLE TransitionStatus is set.
164         Standard_Real mySegmentAngle;  
165         // Length of segment when the length of the segment is fixed before the angle
166         Standard_Real mySegmentLength; 
167         // Value of X fixed coordinate 
168         Standard_Real mySegmentX;                    
169         // Value of Y fixed Coordinate
170         Standard_Real mySegmentY;                    
171         Handle_AIS_Shape myPresentableEdge;          // Current presentable edge
172         Handle_AIS_LengthDimension myLengthDimension;// For display of current length segment dimension
173         Handle_AIS_LengthDimension myXDimension;     // For display of current X segment dimension
174         Handle_AIS_LengthDimension myYDimension;     // For display of current Y segment dimension
175         Handle_AIS_LengthDimension myRadiusDimension;// For display of current radius dimension
176         Handle_AIS_AngleDimension myAngleDimension;  // For display of current angle dimension
177         Standard_Boolean myIsLengthDimensionVisible; // Visibility flag for LengthDimension
178         Standard_Boolean myIsXDimensionVisible;      // Visibility flag for X Dimension
179         Standard_Boolean myIsYDimensionVisible;      // Visibility flag for Y Dimension
180         Standard_Boolean myIsRadiusDimensionVisible; // Visibility flag for RadiusDimension
181         Standard_Boolean myIsAngleDimensionVisible;  // Visibility flag for AngleDimension
182         Handle_AIS_Axis myPresentableMediatrice;     // Chord mediatrice of current circle as a presentable object
183         Handle_Geom2d_Line myMediatrice; // Chord mediatrice of current circle as a 2d line
184         Handle_AIS_Shape myCenterCircle; // to visualise center of current arc
185
186         Handle_AIS_Axis myHAxis;         // Horizontal axis
187         Handle_AIS_Axis myVAxis;         // Vertical axis
188         Handle_AIS_Axis myAngularAxis;   // Axis making a predefined angle with the previous edge
189
190         Quantity_Color myWireColor;      // Color of wire and of build edges
191         Quantity_Color myCurrentColor;   // Color of edge under construction
192         Quantity_Color myAxisColor;      // Color for axis
193         Handle_AIS_InteractiveContext myInteractiveContext; // Interactive context for display management
194         
195         Handle_Geom_Plane myPlane;       // Plane of sketch
196
197         BRepBuilderAPI_MakeWire myPasteWire;                                            
198         Standard_Integer myPasteEdgesNumber;
199         TColStd_SequenceOfInteger myPasteConstructionMode;
200         TColStd_SequenceOfInteger myPasteConstraintMode;        
201 };