-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathSketcher_CommandArc3P.cxx
447 lines (381 loc) · 12.9 KB
/
Sketcher_CommandArc3P.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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
/**
* \file Sketcher_CommandArc3P.cxx
* \brief Implementation file for the class Sketcher_CommandArc3P
* \author <a href="mailto:[email protected]?subject=Sketcher_CommandArc3P.cxx">Sergei Maslov</a>
*/
#include "Sketcher_CommandArc3P.hxx"
IMPLEMENT_STANDARD_RTTIEXT(Sketcher_CommandArc3P, Sketcher_Command)
/**
* \fn Sketcher_CommandArc3P()
* \brief Constructs a Sketcher_CommandArc3P
*/
Sketcher_CommandArc3P::Sketcher_CommandArc3P()
: Sketcher_Command("Arc3P."),
tempCirc(curCoordinateSystem.Ax2(),SKETCHER_RADIUS),
temp2dAdaptor_Curve(),
temp2d_Circ()
{
myArc3PAction = Nothing;
tempGeom_Circle = new Geom_Circle(curCoordinateSystem.Ax2(),SKETCHER_RADIUS);
myRubberCircle = new AIS_Circle(tempGeom_Circle);
myRubberCircle->SetColor(Quantity_NOC_LIGHTPINK1);
mySecondgp_Pnt2d = gp::Origin2d();
third_Pnt = gp::Origin();
midpoint2d = gp::Origin2d();
tempu1_pnt2d = gp::Origin2d();
tempu2_pnt2d = gp::Origin2d();
tempGeom2d_Line = new Geom2d_Line(tempu1_pnt2d,gp::DX2d());
tempGeom2d_Circle = new Geom2d_Circle(temp2d_Circ);
FirstGeom2d_Point = new Geom2d_CartesianPoint(tempu1_pnt2d);
TempGeom2d_Point = new Geom2d_CartesianPoint(tempu2_pnt2d);
u1=u2=0;
temp_u1=temp_u2=0;
dist1 = dist2 = 0;
}
/**
* \fn ~Sketcher_CommandArc3P()
* \brief destructor
*/
Sketcher_CommandArc3P::~Sketcher_CommandArc3P()
{
}
/**
* \fn Action()
* \brief turn command to active state
*/
void Sketcher_CommandArc3P::Action()
{
myArc3PAction = Input_1ArcPoint;
tempCirc.SetPosition (curCoordinateSystem.Ax2());
}
/**
* \fn MouseInputEvent(const gp_Pnt2d& thePnt2d )
* \brief input event handler
* \return Standard_Boolean
* \param thePnt2d const gp_Pnt2d&
*/
Standard_Boolean Sketcher_CommandArc3P::MouseInputEvent(const gp_Pnt2d& thePnt2d )
{
curPnt2d = myAnalyserSnap->MouseInput(thePnt2d);
switch (myArc3PAction)
{
case Nothing: break;
case Input_1ArcPoint:
myFirstgp_Pnt2d = curPnt2d;
myFirstPoint->SetPnt(ElCLib::To3d(curCoordinateSystem.Ax2(),curPnt2d));
if (!myPolylineMode)
{
// myRubberLine->SetPoints(myFirstPoint,myFirstPoint);
// myContext->Display(myRubberLine,0,-1);
firstPoint = true;
myArc3PAction = Input_2ArcPoint;
}
else
{
findlastSObject();
myContext->Display(myRubberCircle,0,-1, true);
}
break;
case Input_2ArcPoint:
{
mySecondgp_Pnt2d = curPnt2d;
mySecondPoint->SetPnt(ElCLib::To3d(curCoordinateSystem.Ax2(),curPnt2d));
tempCirc.SetLocation(myFirstPoint->Pnt().Scaled(mySecondPoint->Pnt(),0.5));
tempCirc.SetRadius(myFirstgp_Pnt2d.Distance(curPnt2d) / 2);
tempGeom_Circle->SetCirc(tempCirc);
myRubberCircle->SetCircle(tempGeom_Circle);
Standard_Real u1 = ElCLib::Parameter(tempCirc,myFirstPoint->Pnt());
Standard_Real u2 = ElCLib::Parameter(tempCirc,mySecondPoint->Pnt());
if ( u1 > u2 )
{
myRubberCircle->SetFirstParam(u2);
myRubberCircle->SetLastParam (u1);
}
else
{
myRubberCircle->SetFirstParam(u1);
myRubberCircle->SetLastParam (u2);
}
myContext->Remove(myRubberLine, false);
myContext->Display(myRubberCircle,0,-1, false);
myContext->Redisplay(myRubberCircle, true);
myArc3PAction = Input_3ArcPoint;
}
break;
case Input_3ArcPoint:
{
Handle (Geom2d_CartesianPoint) Geom2d_Point1 = new Geom2d_CartesianPoint(myFirstgp_Pnt2d);
Handle (Geom2d_CartesianPoint) Geom2d_Point2 = new Geom2d_CartesianPoint(mySecondgp_Pnt2d);
Handle (Geom2d_CartesianPoint) Geom2d_Point3 = new Geom2d_CartesianPoint(curPnt2d);
Geom2dGcc_Circ2d3Tan tempGcc_Circ2d3Tan(Geom2d_Point1,Geom2d_Point2,Geom2d_Point3,1.0e-10);
if (tempGcc_Circ2d3Tan.IsDone() && tempGcc_Circ2d3Tan.NbSolutions()>0)
{
Handle(Geom2d_Arc) myGeom2d_Arc = new Geom2d_Arc(tempGcc_Circ2d3Tan.ThisSolution(1));
myGeom2d_Arc->SetParam(myFirstgp_Pnt2d,mySecondgp_Pnt2d,curPnt2d);
Handle(Geom_Circle) Geom_Circle1 = new Geom_Circle(ElCLib::To3d(curCoordinateSystem.Ax2(),myGeom2d_Arc->Circ2d()));
Handle(AIS_Circle) myAIS_Circle = new AIS_Circle(Geom_Circle1);
myAIS_Circle->SetFirstParam(myGeom2d_Arc->FirstParameter());
myAIS_Circle->SetLastParam (myGeom2d_Arc->LastParameter());
AddObject(myGeom2d_Arc,myAIS_Circle,ArcSketcherObject);
myContext->Remove(myRubberCircle, false);
myContext->Display(myAIS_Circle, true);
myArc3PAction = Input_1ArcPoint;
}
}
break;
case Input_PolylineArc:
{
TempGeom2d_Point->SetPnt2d(curPnt2d);
Geom2dGcc_QualifiedCurve temp2d_QualifiedCurve(temp2dAdaptor_Curve, GccEnt_unqualified);
Geom2dGcc_Circ2d3Tan tempGcc_Circ2d3Tan(temp2d_QualifiedCurve,FirstGeom2d_Point,TempGeom2d_Point,1.0e-6,0);
if (tempGcc_Circ2d3Tan.IsDone() && tempGcc_Circ2d3Tan.NbSolutions()>0)
{
temp2d_Circ = tempGcc_Circ2d3Tan.ThisSolution(1);
u1 = ElCLib::Parameter(temp2d_Circ,myFirstgp_Pnt2d);
u2 = ElCLib::Parameter(temp2d_Circ,curPnt2d);
temp_u1 = u1 + (u2 - u1) / 100;
temp_u2 = u1 - (u2 - u1) / 100;
tempu1_pnt2d = ElCLib::Value(temp_u1, temp2d_Circ);
tempu2_pnt2d = ElCLib::Value(temp_u2, temp2d_Circ);
dist1 = tempu1_pnt2d.Distance(midpoint2d);
dist2 = tempu2_pnt2d.Distance(midpoint2d);
if (dist1 < dist2) tempu1_pnt2d = tempu2_pnt2d;
Handle(Geom2d_Arc) myGeom2d_Arc = new Geom2d_Arc(temp2d_Circ);
myGeom2d_Arc->SetParam(myFirstgp_Pnt2d,tempu1_pnt2d,curPnt2d);
Handle(Geom_Circle) Geom_Circle1 = new Geom_Circle(ElCLib::To3d(curCoordinateSystem.Ax2(),myGeom2d_Arc->Circ2d()));
Handle(AIS_Circle) myAIS_Circle = new AIS_Circle(Geom_Circle1);
myAIS_Circle->SetFirstParam(myGeom2d_Arc->FirstParameter());
myAIS_Circle->SetLastParam (myGeom2d_Arc->LastParameter());
myContext->Display(myAIS_Circle, false);
AddObject(myGeom2d_Arc,myAIS_Circle,ArcSketcherObject);
midpoint2d = myGeom2d_Arc->MiddlePnt();
tempGeom2d_Circle->SetCirc2d(myGeom2d_Arc->Circ2d());
temp2dAdaptor_Curve.Load(tempGeom2d_Circle);
myFirstgp_Pnt2d = curPnt2d;
FirstGeom2d_Point->SetPnt2d(myFirstgp_Pnt2d);
myFirstPoint->SetPnt(ElCLib::To3d(curCoordinateSystem.Ax2(),curPnt2d));
tempGeom_Circle->SetRadius(0);
myRubberCircle->SetCircle(tempGeom_Circle);
myContext->Redisplay(myRubberCircle, true);
}
}
default:break;
}
return Standard_False;
}
/**
* \fn MouseMoveEvent(const gp_Pnt2d& thePnt2d )
* \brief mouse move handler
* \return void
* \param thePnt2d const gp_Pnt2d&
*/
void Sketcher_CommandArc3P::MouseMoveEvent (const gp_Pnt2d& thePnt2d)
{
curPnt2d = myAnalyserSnap->MouseMove(thePnt2d);
switch (myArc3PAction)
{
case Nothing:break;
case Input_1ArcPoint:
curPnt2d = myAnalyserSnap->MouseMove(thePnt2d);
break;
case Input_2ArcPoint:
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_3ArcPoint:
{
third_Pnt = ElCLib::To3d(curCoordinateSystem.Ax2(),curPnt2d);
gce_MakeCirc tempMakeCirc = gce_MakeCirc(myFirstPoint->Pnt(),mySecondPoint->Pnt(),third_Pnt);
if (tempMakeCirc.Status() == gce_Done)
{
tempGeom_Circle->SetCirc(tempMakeCirc.Value());
myRubberCircle->SetCircle(tempGeom_Circle);
myRubberCircle->SetFirstParam(ElCLib::Parameter(tempGeom_Circle->Circ(),myFirstPoint->Pnt()));
myRubberCircle->SetLastParam (ElCLib::Parameter(tempGeom_Circle->Circ(),third_Pnt));
myContext->Redisplay(myRubberCircle, true);
}
}
break;
case Input_PolylineArc:
{
third_Pnt = ElCLib::To3d(curCoordinateSystem.Ax2(),curPnt2d);
TempGeom2d_Point->SetPnt2d(curPnt2d);
Geom2dGcc_QualifiedCurve temp2d_QualifiedCurve(temp2dAdaptor_Curve, GccEnt_unqualified);
Geom2dGcc_Circ2d3Tan tempGcc_Circ2d3Tan(temp2d_QualifiedCurve,FirstGeom2d_Point,TempGeom2d_Point,1.0e-6,0);
if (tempGcc_Circ2d3Tan.IsDone() && tempGcc_Circ2d3Tan.NbSolutions()>0)
{
temp2d_Circ = tempGcc_Circ2d3Tan.ThisSolution(1);
u1 = ElCLib::Parameter(temp2d_Circ,myFirstgp_Pnt2d);
u2 = ElCLib::Parameter(temp2d_Circ,curPnt2d);
temp_u1 = u1 + (u2 - u1) / 100;
temp_u2 = u1 - (u2 - u1) / 100;
tempu1_pnt2d = ElCLib::Value(temp_u1, temp2d_Circ);
tempu2_pnt2d = ElCLib::Value(temp_u2, temp2d_Circ);
dist1 = tempu1_pnt2d.Distance(midpoint2d);
dist2 = tempu2_pnt2d.Distance(midpoint2d);
if (dist1 < dist2) tempu1_pnt2d = tempu2_pnt2d;
gce_MakeCirc tempMakeCirc(myFirstPoint->Pnt(),ElCLib::To3d(curCoordinateSystem.Ax2(),tempu1_pnt2d),third_Pnt);
if (tempMakeCirc.Status() == gce_Done)
{
tempGeom_Circle->SetCirc(tempMakeCirc.Value());
// myRubberCircle->SetCircle(tempGeom_Circle);
myRubberCircle->SetFirstParam(ElCLib::Parameter(tempGeom_Circle->Circ(),myFirstPoint->Pnt()));
myRubberCircle->SetLastParam (ElCLib::Parameter(tempGeom_Circle->Circ(),third_Pnt));
myContext->Redisplay(myRubberCircle, true);
}
}
break;
}
default:break;
}
}
/**
* \fn CancelEvent()
* \brief cancel event handler, stop entering object
* \return void
*/
void Sketcher_CommandArc3P::CancelEvent()
{
switch (myArc3PAction)
{
case Nothing: break;
case Input_1ArcPoint: break;
case Input_2ArcPoint: myContext->Remove(myRubberLine, true);
break;
case Input_3ArcPoint: myContext->Remove(myRubberCircle, true);
break;
case Input_PolylineArc: myContext->Remove(myRubberCircle, true);
break;
default: break;
}
myArc3PAction = Nothing;
}
/**
* \fn GetTypeOfMethod()
* \brief get command Method
* \return Sketcher_ObjectTypeOfMethod
*/
Sketcher_ObjectTypeOfMethod Sketcher_CommandArc3P::GetTypeOfMethod()
{
return Arc3P_Method;
}
/**
* \fn SetPolylineFirstPnt(const gp_Pnt2d& p1)
* \brief set last entering gp_Pnt2d for polyline
* \return void
* \param p1 const gp_Pnt2d&
*/
void Sketcher_CommandArc3P::SetPolylineFirstPnt(const gp_Pnt2d& p1)
{
myFirstgp_Pnt2d = p1;
myFirstPoint->SetPnt(ElCLib::To3d(curCoordinateSystem.Ax2(),p1));
findlastSObject();
myContext->Display(myRubberCircle,0,-1, true);
}
/**
* \fn GetPolylineFirstPnt(gp_Pnt2d& p1)
* \brief get last entering gp_Pnt2d for polyline
* \return Standard_Boolean
* \param p1 gp_Pnt2d&
*/
Standard_Boolean Sketcher_CommandArc3P::GetPolylineFirstPnt(gp_Pnt2d& p1)
{
if (myArc3PAction == Input_PolylineArc && myPolylineMode == Standard_True)
{
p1 = myFirstgp_Pnt2d;
return Standard_True;
}
else
return Standard_False;
}
/**
* \fn SetPolylineMode(Standard_Boolean mode)
* \brief set polyline mode
* \return void
* \param mode Standard_Boolean
*/
void Sketcher_CommandArc3P::SetPolylineMode (Standard_Boolean mode)
{
myPolylineMode = mode;
switch (myArc3PAction)
{
case Nothing: break;
case Input_1ArcPoint: break;
case Input_2ArcPoint: findlastSObject();
myContext->Remove(myRubberLine, false);
myContext->Display(myRubberCircle,0,-1, true);
break;
case Input_3ArcPoint: findlastSObject();
myContext->Redisplay(myRubberCircle, true);
break;
case Input_PolylineArc: mySecondPoint->SetPnt(ElCLib::To3d(curCoordinateSystem.Ax2(),curPnt2d));
myRubberLine->SetPoints(myFirstPoint,mySecondPoint);
myContext->Remove(myRubberCircle, false);
myContext->Display(myRubberLine,0,-1, true);
myArc3PAction = Input_2ArcPoint;
break;
default: break;
}
}
/**
* \fn findlastSObject()
* \brief find last object at list of objects
* \return void
*/
void Sketcher_CommandArc3P::findlastSObject()
{
midpoint2d = gp::Origin2d();
if (data->Length() > 0)
{
Handle(Sketcher_Object) lastSObject = Handle(Sketcher_Object)::DownCast(data->Value(data->Length()));
if (lastSObject->GetGeometryType() == LineSketcherObject)
{
Handle(Geom2d_Edge) last2d_Edge = Handle(Geom2d_Edge)::DownCast(lastSObject->GetGeometry());
if (last2d_Edge->GetStart_Pnt().IsEqual(myFirstgp_Pnt2d,1.0e-6) ||
last2d_Edge->GetEnd_Pnt().IsEqual(myFirstgp_Pnt2d,1.0e-6))
{
midpoint2d = last2d_Edge->MiddlePnt();
tempGeom2d_Line->SetLin2d(last2d_Edge->Lin2d());
temp2dAdaptor_Curve.Load(tempGeom2d_Line);
}
else setTempLine();
}
else if (lastSObject->GetGeometryType() == ArcSketcherObject)
{
Handle(Geom2d_Arc) last2d_Arc = Handle(Geom2d_Arc)::DownCast(lastSObject->GetGeometry());
if (last2d_Arc->FirstPnt().IsEqual(myFirstgp_Pnt2d,1.0e-6) ||
last2d_Arc->LastPnt().IsEqual(myFirstgp_Pnt2d,1.0e-6))
{
midpoint2d = last2d_Arc->MiddlePnt();
tempGeom2d_Circle->SetCirc2d(last2d_Arc->Circ2d());
temp2dAdaptor_Curve.Load(tempGeom2d_Circle);
}
else setTempLine();
}
else setTempLine();
}
else setTempLine();
FirstGeom2d_Point->SetPnt2d(myFirstgp_Pnt2d);
tempGeom_Circle->SetRadius(0);
myRubberCircle->SetCircle(tempGeom_Circle);
myArc3PAction = Input_PolylineArc;
}
/**
* \fn setTempLine()
* \brief set default horisontal line
* \return void
*/
void Sketcher_CommandArc3P::setTempLine()
{
tempGeom2d_Line->SetLocation(myFirstgp_Pnt2d);
tempGeom2d_Line->SetDirection (gp::DX2d());
temp2dAdaptor_Curve.Load(tempGeom2d_Line);
}