-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathSketcher_CommandBezierCurve.cxx
272 lines (238 loc) · 6.99 KB
/
Sketcher_CommandBezierCurve.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/**
* \file Sketcher_CommandBezierCurve.cxx
* \brief Implementation file for the class Sketcher_CommandBezierCurve
* \author <a href="mailto:[email protected]?subject=Sketcher_CommandBezierCurve.cxx">Sergei Maslov</a>
*/
#include "Sketcher_CommandBezierCurve.hxx"
IMPLEMENT_STANDARD_RTTIEXT(Sketcher_CommandBezierCurve, Sketcher_Command)
/**
* \fn Sketcher_CommandBezierCurve()
* \brief Constructs a Sketcher_CommandBezierCurve
*/
Sketcher_CommandBezierCurve::Sketcher_CommandBezierCurve()
: Sketcher_Command("BezierCurve."),
tempPnt2d(gp::Origin2d()),
myFirstgp_Pnt(gp::Origin()),
tempPnt(gp::Origin()),
curEdge()
{
myBezierCurveAction = Nothing;
TColgp_Array1OfPnt2d curgp_Array1CurvePoles2d(1,2);
curgp_Array1CurvePoles2d.SetValue (1, myFirstgp_Pnt2d);
curgp_Array1CurvePoles2d.SetValue (2, tempPnt2d);
myGeom2d_BezierCurve = new Geom2d_BezierCurve(curgp_Array1CurvePoles2d);
TColgp_Array1OfPnt curgp_Array1CurvePoles(1,2);
curgp_Array1CurvePoles.SetValue (1, myFirstgp_Pnt);
curgp_Array1CurvePoles.SetValue (2, tempPnt);
myGeom_BezierCurve = new Geom_BezierCurve(curgp_Array1CurvePoles);
myRubberAIS_Shape = new AIS_Shape(curEdge);
}
/**
* \fn ~Sketcher_CommandBezierCurve()
* \brief destructor
*/
Sketcher_CommandBezierCurve::~Sketcher_CommandBezierCurve()
{
}
/**
* \fn Action()
* \brief turn command to active state
*/
void Sketcher_CommandBezierCurve::Action()
{
myBezierCurveAction = Input_1Point;
}
/**
* \fn MouseInputEvent(const gp_Pnt2d& thePnt2d )
* \brief input event handler
* \return Standard_Boolean
* \param thePnt2d const gp_Pnt2d&
*/
Standard_Boolean Sketcher_CommandBezierCurve::MouseInputEvent(const gp_Pnt2d& thePnt2d)
{
curPnt2d = myAnalyserSnap->MouseInput(thePnt2d);
switch (myBezierCurveAction)
{
case Nothing: break;
case Input_1Point:
{
myFirstgp_Pnt2d = curPnt2d;
myFirstgp_Pnt = ElCLib::To3d(curCoordinateSystem.Ax2(),curPnt2d);
myFirstPoint->SetPnt(myFirstgp_Pnt);
// myRubberLine->SetPoints(myFirstPoint,myFirstPoint);
Handle (Geom2d_CartesianPoint) myGeom2d_Point = new Geom2d_CartesianPoint(curPnt2d);
Handle(AIS_Point) myAIS_Point = new AIS_Point(myFirstPoint);
myContext->Display(myAIS_Point, true);
AddObject(myGeom2d_Point,myAIS_Point,PointSketcherObject);
// myContext->Display(myRubberLine,0,-1);
firstPoint = true;
myBezierCurveAction = Input_2Point;
IndexCounter = 2;
}
break;
case Input_2Point:
{
myGeom2d_BezierCurve->SetPole (1,myFirstgp_Pnt2d);
myGeom2d_BezierCurve->SetPole (IndexCounter,curPnt2d);
tempPnt = ElCLib::To3d(curCoordinateSystem.Ax2(),curPnt2d);
myGeom_BezierCurve->SetPole (1,myFirstgp_Pnt);
myGeom_BezierCurve->SetPole (IndexCounter,tempPnt);
mySecondPoint->SetPnt(tempPnt);
BRepBuilderAPI_MakeEdge ME (myGeom_BezierCurve,myFirstgp_Pnt,tempPnt);
if (ME.IsDone ())
{
storePoles();
curEdge = ME.Edge();
myRubberAIS_Shape->Set(curEdge);
myContext->Remove(myRubberLine, false);
myContext->Display(myRubberAIS_Shape,0,-1, true);
myGeom2d_BezierCurve->InsertPoleAfter (IndexCounter,curPnt2d);
myGeom_BezierCurve->InsertPoleAfter (IndexCounter,tempPnt);
IndexCounter++;
myBezierCurveAction = Input_OtherPoints;
}
}
break;
case Input_OtherPoints:
{
myGeom2d_BezierCurve->SetPole (IndexCounter,curPnt2d);
tempPnt = ElCLib::To3d(curCoordinateSystem.Ax2(),curPnt2d);
// mySecondPoint->SetPnt(tempPnt);
myGeom_BezierCurve->SetPole (IndexCounter,tempPnt);
BRepBuilderAPI_MakeEdge ME (myGeom_BezierCurve,myFirstgp_Pnt,tempPnt);
if (ME.IsDone ())
{
storePoles();
curEdge = ME.Edge();
if( IndexCounter > MAXIMUMPOLES) closeBezierCurve();
else
{
myRubberAIS_Shape->Set(curEdge);
myContext->Redisplay(myRubberAIS_Shape, true);
myGeom2d_BezierCurve->InsertPoleAfter (IndexCounter,curPnt2d);
myGeom_BezierCurve->InsertPoleAfter (IndexCounter,tempPnt);
tempPnt2d = curPnt2d;
IndexCounter++;
}
}
}
break;
default:break;
}
return Standard_False;
}
/**
* \fn MouseMoveEvent(const gp_Pnt2d& thePnt2d )
* \brief mouse move handler
* \return void
* \param thePnt2d const gp_Pnt2d&
*/
void Sketcher_CommandBezierCurve::MouseMoveEvent (const gp_Pnt2d& thePnt2d)
{
curPnt2d = myAnalyserSnap->MouseMove(thePnt2d);
switch (myBezierCurveAction)
{
case Nothing: break;
case Input_1Point: break;
case Input_2Point:
mySecondPoint->SetPnt(ElCLib::To3d(curCoordinateSystem.Ax2(),curPnt2d));
myRubberLine->SetPoints(myFirstPoint,mySecondPoint);
if(firstPoint)
{
myContext->Display(myRubberLine,0,-1, true);
firstPoint = false;
}else
{
myContext->Redisplay(myRubberLine, true);
}
break;
case Input_OtherPoints:
{
myGeom2d_BezierCurve->SetPole (IndexCounter,curPnt2d);
mySecondPoint->SetPnt(ElCLib::To3d(curCoordinateSystem.Ax2(),curPnt2d));
myGeom_BezierCurve->SetPole (IndexCounter,mySecondPoint->Pnt());
BRepBuilderAPI_MakeEdge ME (myGeom_BezierCurve,myFirstgp_Pnt,mySecondPoint->Pnt());
if (ME.IsDone ())
{
curEdge = ME.Edge();
myRubberAIS_Shape->Set(curEdge);
myContext->Redisplay(myRubberAIS_Shape, true);
}
else
IndexCounter--;
}
break;
default:break;
}
}
/**
* \fn CancelEvent()
* \brief cancel event handler, stop entering object
* \return void
*/
void Sketcher_CommandBezierCurve::CancelEvent()
{
switch (myBezierCurveAction)
{
case Nothing: break;
case Input_1Point: break;
case Input_2Point:
myContext->Remove(myRubberLine, true);
break;
case Input_OtherPoints:
{
myGeom2d_BezierCurve->RemovePole (IndexCounter);
myGeom_BezierCurve->RemovePole (IndexCounter);
BRepBuilderAPI_MakeEdge ME (myGeom_BezierCurve,myFirstgp_Pnt,tempPnt);
if (ME.IsDone ())
{
curEdge = ME.Edge();
IndexCounter--;
closeBezierCurve();
}
}
break;
default:break;
}
myBezierCurveAction = Nothing;
}
/**
* \fn GetTypeOfMethod()
* \brief get command Method
* \return Sketcher_ObjectTypeOfMethod
*/
Sketcher_ObjectTypeOfMethod Sketcher_CommandBezierCurve::GetTypeOfMethod()
{
return BezierCurve_Method;
}
/**
* \fn closeBezierCurve()
* \brief display Bezier Curve, add to list of objects
* \return void
*/
void Sketcher_CommandBezierCurve::closeBezierCurve()
{
myContext->Remove(myRubberAIS_Shape, false);
Handle (AIS_Shape) myAIS_Shape = new AIS_Shape(curEdge);
AddObject(myGeom2d_BezierCurve,myAIS_Shape,CurveSketcherObject);
myContext->Display(myAIS_Shape, true);
for(Standard_Integer i = IndexCounter; i>2;i--)
{
myGeom2d_BezierCurve->RemovePole (i);
myGeom_BezierCurve->RemovePole (i);
}
myBezierCurveAction = Input_1Point;
}
/**
* \fn storePoles()
* \brief display Pole point, add to list of objects
* \return void
*/
void Sketcher_CommandBezierCurve::storePoles()
{
Handle (Geom2d_CartesianPoint) myGeom2d_Point = new Geom2d_CartesianPoint(curPnt2d);
mySecondPoint->SetPnt(ElCLib::To3d(curCoordinateSystem.Ax2(),curPnt2d));
Handle(AIS_Point) myAIS_Point = new AIS_Point(mySecondPoint);
myContext->Display(myAIS_Point, true);
AddObject(myGeom2d_Point,myAIS_Point,PointSketcherObject);
}