-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathSketcher.cxx
446 lines (404 loc) · 12.3 KB
/
Sketcher.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.cxx
* \brief Implementation file for the class Sketcher
* \author <a href="mailto:[email protected]?subject=Sketcher.cxx">Sergei Maslov</a>
*/
#include "Sketcher.hxx"
/**
* \fn Sketcher(Handle(AIS_InteractiveContext)& theContext, Sketcher_GUI* sg)
* \brief Constructs a Sketcher
* \param theContext Handle(AIS_InteractiveContext)&
* \param sg Sketcher_GUI*
*/
Sketcher::Sketcher(Handle(AIS_InteractiveContext)& theContext, Sketcher_GUI* sg)
: myCoordinateSystem(gp::XOY())
{
myContext = theContext;
myGUI = sg;
//myGUI->SetAx3(myCoordinateSystem);
//myGUI->SetContext(myContext);
myCurrentMethod = Nothing_Method;
myCurrentDir = gp::DZ();
myTempPnt = gp::Origin();
myCurrentPnt2d = gp::Origin2d();
myCurrentPlane = new Geom_Plane(myCoordinateSystem);
myCurrentLine = new Geom_Line(myTempPnt,myCurrentDir);
PolylineFirstPoint = gp::Origin2d();
PolylineFirstPointExist= Standard_False;
myData = new TColStd_HSequenceOfTransient();
myCommands = new TColStd_HSequenceOfTransient();
myAnalyserSnap = new Sketcher_AnalyserSnap(myContext,myData,myCoordinateSystem);
addCommand(new Sketcher_CommandPoint());
addCommand(new Sketcher_CommandLine2P());
addCommand(new Sketcher_CommandCircleCenterRadius());
addCommand(new Sketcher_CommandCircle3P());
addCommand(new Sketcher_CommandCircle2PTan());
addCommand(new Sketcher_CommandCircleP2Tan());
addCommand(new Sketcher_CommandCircle3Tan());
addCommand(new Sketcher_CommandArc3P());
addCommand(new Sketcher_CommandArcCenter2P());
addCommand(new Sketcher_CommandBezierCurve());
addCommand(new Sketcher_CommandTrim());
}
/**
* \fn ~Sketcher()
* \brief destructor
*/
Sketcher::~Sketcher()
{
delete myGUI;
}
/**
* \fn SetContext(Handle(AIS_InteractiveContext)& theContext)
* \brief set context
* \return void
* \param theContext Handle(AIS_InteractiveContext)&
*/
void Sketcher::SetContext(Handle(AIS_InteractiveContext)& theContext)
{
myContext = theContext;
myAnalyserSnap->SetContext(myContext);
//myGUI->SetContext(theContext);
for( Standard_Integer i=1; i<=myCommands->Length(); i++)
{
CurCommand = Handle(Sketcher_Command)::DownCast(myCommands->Value(i));
CurCommand->SetContext(myContext);
}
}
/**
* \fn SetData(Handle(TColStd_HSequenceOfTransient)& thedata)
* \brief set list of objects
* \return void
* \param thedata TColStd_HSequenceOfTransient)&
*/
void Sketcher::SetData (Handle(TColStd_HSequenceOfTransient)& thedata)
{
myData = thedata;
for( Standard_Integer i=1; i<=myCommands->Length(); i++)
{
CurCommand = Handle(Sketcher_Command)::DownCast(myCommands->Value(i));
CurCommand->SetData(myData);
}
}
/**
* \fn GetData()
* \brief get list of objects
* \return Handle(TColStd_HSequenceOfTransient)&
*/
Handle(TColStd_HSequenceOfTransient) Sketcher::GetData ()
{
return myData;
}
/**
* \fn SetCoordinateSystem(const gp_Ax3& theCS)
* \brief set coordinate system
* \return void
* \param theCS const gp_Ax3&
*/
void Sketcher::SetCoordinateSystem (const gp_Ax3& theCS)
{
myCoordinateSystem = theCS;
myCurrentPlane->SetPosition(myCoordinateSystem);
myAnalyserSnap->SetAx3(myCoordinateSystem);
//myGUI->SetAx3(myCoordinateSystem);
for( Standard_Integer i=1; i<=myCommands->Length(); i++)
{
CurCommand = Handle(Sketcher_Command)::DownCast(myCommands->Value(i));
CurCommand->SetAx3(myCoordinateSystem);
}
}
/**
* \fn GetCoordinateSystem()
* \brief get coordinate system from Sketcher
* \return gp_Ax3
*/
gp_Ax3 Sketcher::GetCoordinateSystem ()
{
return myCoordinateSystem;
}
/**
* \fn SetPrecise(const Standard_Real& aPrecise)
* \brief set precise for snap
* \return void
* \param aPrecise const Standard_Real&
*/
void Sketcher::SetPrecise(const Standard_Real& aPrecise)
{
if (aPrecise > 0)
myAnalyserSnap->SetMinDistance(aPrecise);
}
/**
* \fn SetColor(const Quantity_NameOfColor theColor)
* \brief set color
* \return void
* \param theColor const Quantity_NameOfColor
*/
void Sketcher::SetColor(const Quantity_NameOfColor theColor)
{
for( Standard_Integer i=1; i<=myCommands->Length(); i++)
{
CurCommand = Handle(Sketcher_Command)::DownCast(myCommands->Value(i));
CurCommand->SetColor(theColor);
}
}
/**
* \fn SetType(const Sketcher_ObjectType theType)
* \brief set type of object
* \return void
* \param theType const Sketcher_ObjectType
*/
void Sketcher::SetType(const Sketcher_ObjectType theType)
{
for( Standard_Integer i=1; i<=myCommands->Length(); i++)
{
CurCommand = Handle(Sketcher_Command)::DownCast(myCommands->Value(i));
CurCommand->SetType(theType);
}
}
/**
* \fn SetStyle(const Aspect_TypeOfLine theLineStyle)
* \brief set line style
* \return void
* \param theLineStyle const Aspect_TypeOfLine
*/
void Sketcher::SetStyle(const Aspect_TypeOfLine theLineStyle)
{
for( Standard_Integer i=1; i<=myCommands->Length(); i++)
{
CurCommand = Handle(Sketcher_Command)::DownCast(myCommands->Value(i));
CurCommand->SetStyle(theLineStyle);
}
}
/**
* \fn SetWidth(const Standard_Real& theWidth)
* \brief set line width
* \return void
* \param theWidth const Standard_Real&
*/
void Sketcher::SetWidth(const Standard_Real& theWidth)
{
for( Standard_Integer i=1; i<=myCommands->Length(); i++)
{
CurCommand = Handle(Sketcher_Command)::DownCast(myCommands->Value(i));
CurCommand->SetWidth(theWidth);
}
}
/**
* \fn ObjectAction(const Sketcher_ObjectTypeOfMethod theMethod)
* \brief set entering object command by theMethod
* \return void
* \param theMethod const Sketcher_ObjectTypeOfMethod
*/
void Sketcher::ObjectAction(const Sketcher_ObjectTypeOfMethod theMethod)
{
myCurrentMethod = theMethod;
SelectCurCommand();
CurCommand->Action();
if ((myCurrentMethod == Line2P_Method || myCurrentMethod == Arc3P_Method) && PolylineFirstPointExist)
CurCommand->SetPolylineFirstPnt(PolylineFirstPoint);
else PolylineFirstPointExist = Standard_False;
}
/**
* \fn GetStatus()
* \brief get current object create method
* \return Sketcher_ObjectTypeOfMethod
*/
Sketcher_ObjectTypeOfMethod Sketcher::GetStatus()
{
return myCurrentMethod;
}
/**
* \fn OnMouseInputEvent(const V3d_Coordinate &v3dX,const V3d_Coordinate &v3dY,const V3d_Coordinate &v3dZ,const Standard_Real& projVx,const Standard_Real& projVy,const Standard_Real& projVz)
* \brief input event handler
* \return void
* \param v3dX const V3d_Coordinate&
* \param v3dY const V3d_Coordinate&
* \param v3dZ const V3d_Coordinate&
* \param projVx const Standard_Real&
* \param projVy const Standard_Real&
* \param projVz const Standard_Real&
*/
void Sketcher::OnMouseInputEvent(const V3d_Coordinate &v3dX,const V3d_Coordinate &v3dY,const V3d_Coordinate &v3dZ,
const Standard_Real& projVx,const Standard_Real& projVy,const Standard_Real& projVz)
{
if (ProjectPointOnPlane(v3dX,v3dY,v3dZ,projVx,projVy,projVz))
{
SelectCurCommand();
if(CurCommand->MouseInputEvent(myCurrentPnt2d))
myCurrentMethod = Nothing_Method;
}
}
/**
* \fn OnMouseMoveEvent(const V3d_Coordinate &v3dX,const V3d_Coordinate &v3dY,const V3d_Coordinate &v3dZ,const Standard_Real& projVx,const Standard_Real& projVy,const Standard_Real& projVz)
* \brief mouse move handler
* \return void
* \param v3dX const V3d_Coordinate&
* \param v3dY const V3d_Coordinate&
* \param v3dZ const V3d_Coordinate&
* \param projVx const Standard_Real&
* \param projVy const Standard_Real&
* \param projVz const Standard_Real&
*/
void Sketcher::OnMouseMoveEvent(const V3d_Coordinate &v3dX,const V3d_Coordinate &v3dY,const V3d_Coordinate &v3dZ,
const Standard_Real& projVx,const Standard_Real& projVy,const Standard_Real& projVz)
{
if (ProjectPointOnPlane(v3dX,v3dY,v3dZ,projVx,projVy,projVz))
{
SelectCurCommand();
CurCommand->MouseMoveEvent(myCurrentPnt2d);
}
}
/**
* \fn OnCancel()
* \brief cancel event handler, stop entering object
* \return void
*/
void Sketcher::OnCancel()
{
SelectCurCommand();
myAnalyserSnap->Cancel();
if (myCurrentMethod == Line2P_Method || myCurrentMethod == Arc3P_Method)
PolylineFirstPointExist = CurCommand->GetPolylineFirstPnt(PolylineFirstPoint);
CurCommand->CancelEvent();
myCurrentMethod = Nothing_Method;
}
/**
* \fn DeleteSelectedObject()
* \brief delete objects selected in the context
* \return void
*/
void Sketcher::DeleteSelectedObject()
{
for( Standard_Integer i=1; i<=myData->Length(); i++)
{
myCurObject = Handle(Sketcher_Object)::DownCast(myData->Value(i));
if (myContext->IsSelected (myCurObject->GetAIS_Object()))
{
myContext->Erase(myCurObject->GetAIS_Object(),Standard_False);
myData->Remove (i,Standard_False);
}
}
myContext->UpdateCurrentViewer();
}
/**
* \fn ViewProperties()
* \brief show properties for selected object
* \return void
*/
void Sketcher::ViewProperties()
{
/*for( Standard_Integer i=1; i<=myData->Length(); i++)
{
myCurObject = Handle(Sketcher_Object)::DownCast(myData->Value(i));
if (myContext->IsSelected (myCurObject->GetAIS_Object()))
{
myContext->ClearSelected (true);
myGUI->SetSketcher_Object(myCurObject);
break;
}
}*/
}
/**
* \fn RedrawAll()
* \brief erase and redraw all objects from object list
* \return void
*/
void Sketcher::RedrawAll()
{
for( Standard_Integer i=1; i<=myData->Length(); i++)
{
myCurObject = Handle(Sketcher_Object)::DownCast(myData->Value(i));
myContext->Display(myCurObject->GetAIS_Object(), false);
}
myContext->UpdateCurrentViewer();
}
/**
* \fn SetPolylineMode(Standard_Boolean mode)
* \brief set polyline mode
* \return void
* \param amode Standard_Boolean
*/
void Sketcher::SetPolylineMode(Standard_Boolean amode)
{
for( Standard_Integer i=1; i<=myCommands->Length(); i++)
{
CurCommand = Handle(Sketcher_Command)::DownCast(myCommands->Value(i));
CurCommand->SetPolylineMode(amode);
}
PolylineFirstPointExist = Standard_False;
}
/**
* \fn SetSnap(Sketcher_SnapType theSnap)
* \brief set current snap type
* \return void
* \param theSnap Sketcher_SnapType
*/
void Sketcher::SetSnap(Sketcher_SnapType theSnap)
{
myAnalyserSnap->SetSnapType(theSnap);
}
/**
* \fn GetSnap()
* \brief get current snap type
* \return Sketcher_SnapType
*/
Sketcher_SnapType Sketcher::GetSnap()
{
return myAnalyserSnap->GetSnapType();
}
/**
* \fn ProjectPointOnPlane(const V3d_Coordinate &v3dX,const V3d_Coordinate &v3dY,const V3d_Coordinate &v3dZ,const Standard_Real& projVx,const Standard_Real& projVy,const Standard_Real& projVz)
* \brief calculate 2d point on current plane
* \return Standard_Boolean
* \param v3dX const V3d_Coordinate&
* \param v3dY const V3d_Coordinate&
* \param v3dZ const V3d_Coordinate&
* \param projVx const Standard_Real&
* \param projVy const Standard_Real&
* \param projVz const Standard_Real&
*/
Standard_Boolean Sketcher::ProjectPointOnPlane(const V3d_Coordinate &v3dX,const V3d_Coordinate &v3dY,const V3d_Coordinate &v3dZ,
const Standard_Real& projVx,const Standard_Real& projVy,const Standard_Real& projVz)
{
myTempPnt.SetCoord(v3dX,v3dY,v3dZ);
myCurrentDir.SetCoord(projVx,projVy,projVz);
myCurrentLine->SetDirection(myCurrentDir);
myCurrentLine->SetLocation (myTempPnt);
myIntCS.Perform(myCurrentLine,myCurrentPlane);
if(myIntCS.NbPoints() >= 1)
{
myTempPnt = myIntCS.Point (1);
myCurrentPnt2d.SetX((myTempPnt.X()-myCoordinateSystem.Location().X())*myCoordinateSystem.XDirection().X()+(myTempPnt.Y()-myCoordinateSystem.Location().Y())*myCoordinateSystem.XDirection().Y()+(myTempPnt.Z()-myCoordinateSystem.Location().Z())*myCoordinateSystem.XDirection().Z());
myCurrentPnt2d.SetY((myTempPnt.X()-myCoordinateSystem.Location().X())*myCoordinateSystem.YDirection().X()+(myTempPnt.Y()-myCoordinateSystem.Location().Y())*myCoordinateSystem.YDirection().Y()+(myTempPnt.Z()-myCoordinateSystem.Location().Z())*myCoordinateSystem.YDirection().Z());
return Standard_True;
}
else return Standard_False;
}
/**
* \fn addCommand(Handle(Sketcher_Command) theCommand)
* \brief add theCommand to command list
* \return void
* \param theCommand Handle(Sketcher_Command)
*/
void Sketcher::addCommand(Handle(Sketcher_Command) theCommand)
{
theCommand->SetData(myData);
theCommand->SetContext(myContext);
theCommand->SetAnalyserSnap(myAnalyserSnap);
theCommand->SetAx3(myCoordinateSystem);
myCommands->Append(theCommand);
}
/**
* \fn SelectCurCommand()
* \brief get command from command list
* \return void
*/
void Sketcher::SelectCurCommand()
{
for( Standard_Integer i=1; i<=myCommands->Length(); i++)
{
CurCommand = Handle(Sketcher_Command)::DownCast(myCommands->Value(i));
if(CurCommand->GetTypeOfMethod() == myCurrentMethod)
break;
}
}