]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_MacroArc.cpp
Salome HOME
Issues #2027, #2024, #2063, #2067: reentrant message to fill new operation by result...
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_MacroArc.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        SketchPlugin_MacroArc.cpp
4 // Created:     26 Apr 2014
5 // Author:      Artem ZHIDKOV
6
7 #include "SketchPlugin_MacroArc.h"
8
9 #include "SketchPlugin_Arc.h"
10 #include "SketchPlugin_ConstraintTangent.h"
11 #include "SketchPlugin_Sketch.h"
12 #include "SketchPlugin_Tools.h"
13 #include "SketchPlugin_MacroArcReentrantMessage.h"
14
15 #include <ModelAPI_AttributeDouble.h>
16 #include <ModelAPI_AttributeRefAttr.h>
17 #include <ModelAPI_AttributeString.h>
18 #include <ModelAPI_Events.h>
19 #include <ModelAPI_Session.h>
20 #include <ModelAPI_Validator.h>
21
22 #include <GeomAPI_Circ.h>
23 #include <GeomAPI_Circ2d.h>
24 #include <GeomAPI_Curve.h>
25 #include <GeomAPI_Dir2d.h>
26 #include <GeomAPI_Edge.h>
27 #include <GeomAPI_Lin.h>
28 #include <GeomAPI_Lin2d.h>
29 #include <GeomAPI_Pnt2d.h>
30 #include <GeomAPI_Vertex.h>
31 #include <GeomAPI_XY.h>
32
33 #include <GeomDataAPI_Point2D.h>
34 #include <GeomDataAPI_Dir.h>
35 #include <GeomAlgoAPI_PointBuilder.h>
36 #include <GeomAlgoAPI_EdgeBuilder.h>
37 #include <GeomAlgoAPI_CompoundBuilder.h>
38
39 // for sqrt on Linux
40 #include <math.h>
41
42 const double tolerance = 1e-7;
43 const double paramTolerance = 1.e-4;
44 const double PI = 3.141592653589793238463;
45
46 static void projectPointOnCircle(AttributePoint2DPtr& thePoint, const GeomAPI_Circ2d& theCircle)
47 {
48   std::shared_ptr<GeomAPI_Pnt2d> aProjection = theCircle.project(thePoint->pnt());
49   if(aProjection.get())
50     thePoint->setValue(aProjection);
51 }
52
53
54 SketchPlugin_MacroArc::SketchPlugin_MacroArc()
55 : SketchPlugin_SketchEntity(),
56   myParamBefore(0.0)
57 {
58 }
59
60 void SketchPlugin_MacroArc::initAttributes()
61 {
62   data()->addAttribute(ARC_TYPE(), ModelAPI_AttributeString::typeId());
63
64   data()->addAttribute(CENTER_POINT_ID(), GeomDataAPI_Point2D::typeId());
65   data()->addAttribute(START_POINT_1_ID(), GeomDataAPI_Point2D::typeId());
66   data()->addAttribute(END_POINT_1_ID(), GeomDataAPI_Point2D::typeId());
67
68   data()->addAttribute(START_POINT_2_ID(), GeomDataAPI_Point2D::typeId());
69   data()->addAttribute(END_POINT_2_ID(), GeomDataAPI_Point2D::typeId());
70   data()->addAttribute(PASSED_POINT_ID(), GeomDataAPI_Point2D::typeId());
71
72   data()->addAttribute(TANGENT_POINT_ID(), ModelAPI_AttributeRefAttr::typeId());
73   data()->addAttribute(END_POINT_3_ID(), GeomDataAPI_Point2D::typeId());
74
75   data()->addAttribute(REVERSED_ID(), ModelAPI_AttributeBoolean::typeId());
76
77   data()->addAttribute(RADIUS_ID(), ModelAPI_AttributeDouble::typeId());
78   data()->addAttribute(ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
79
80   data()->addAttribute(AUXILIARY_ID(), ModelAPI_AttributeBoolean::typeId());
81
82   data()->addAttribute(CENTER_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId());
83   data()->addAttribute(START_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId());
84   data()->addAttribute(END_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId());
85   data()->addAttribute(PASSED_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId());
86
87   data()->addAttribute(EDIT_ARC_TYPE_ID(), ModelAPI_AttributeString::typeId());
88
89   boolean(REVERSED_ID())->setValue(false);
90   string(EDIT_ARC_TYPE_ID())->setValue("");
91
92   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CENTER_POINT_REF_ID());
93   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), START_POINT_REF_ID());
94   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), END_POINT_REF_ID());
95   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PASSED_POINT_REF_ID());
96   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EDIT_ARC_TYPE_ID());
97 }
98
99 void SketchPlugin_MacroArc::attributeChanged(const std::string& theID)
100 {
101   std::string anArcType = string(ARC_TYPE())->value();
102
103   // If arc type switched reset according attributes.
104   if(theID == ARC_TYPE()) {
105     SketchPlugin_Tools::resetAttribute(this, CENTER_POINT_ID());
106     SketchPlugin_Tools::resetAttribute(this, CENTER_POINT_REF_ID());
107     SketchPlugin_Tools::resetAttribute(this, START_POINT_1_ID());
108     SketchPlugin_Tools::resetAttribute(this, START_POINT_REF_ID());
109     SketchPlugin_Tools::resetAttribute(this, END_POINT_1_ID());
110     SketchPlugin_Tools::resetAttribute(this, END_POINT_REF_ID());
111     SketchPlugin_Tools::resetAttribute(this, START_POINT_2_ID());
112     SketchPlugin_Tools::resetAttribute(this, END_POINT_2_ID());
113     SketchPlugin_Tools::resetAttribute(this, PASSED_POINT_ID());
114     SketchPlugin_Tools::resetAttribute(this, PASSED_POINT_REF_ID());
115     SketchPlugin_Tools::resetAttribute(this, TANGENT_POINT_ID());
116     SketchPlugin_Tools::resetAttribute(this, END_POINT_3_ID());
117     SketchPlugin_Tools::resetAttribute(this, REVERSED_ID());
118     SketchPlugin_Tools::resetAttribute(this, RADIUS_ID());
119     SketchPlugin_Tools::resetAttribute(this, ANGLE_ID());
120
121     myCenter.reset();
122     myStart.reset();
123     myEnd.reset();
124     boolean(REVERSED_ID())->setValue(false);
125     myParamBefore = 0.0;
126   } else if(anArcType == ARC_TYPE_BY_CENTER_AND_POINTS())
127     fillByCenterAndTwoPassed();
128   else if(anArcType == ARC_TYPE_BY_THREE_POINTS())
129     fillByThreePassedPoints();
130   else if(anArcType == ARC_TYPE_BY_TANGENT_EDGE())
131     fillByTangentEdge();
132
133   double aRadius = 0;
134   double anAngle = 0;
135   if(myCenter.get() && myStart.get()) {
136     aRadius = myCenter->distance(myStart);
137     if(myEnd.get()) {
138       if(myStart->isEqual(myEnd)) {
139         anAngle = 360;
140       } else {
141         GeomAPI_Circ2d aCircleForArc(myCenter, myStart);
142         double aStartParam, anEndParam;
143         aCircleForArc.parameter(myStart, paramTolerance, aStartParam);
144         aCircleForArc.parameter(myEnd, paramTolerance, anEndParam);
145         anAngle = (anEndParam - aStartParam) / PI * 180.0;
146         if(boolean(REVERSED_ID())->value()) anAngle = 360.0 - anAngle;
147       }
148     }
149   }
150
151   bool aWasBlocked = data()->blockSendAttributeUpdated(true);
152   real(RADIUS_ID())->setValue(aRadius);
153   real(ANGLE_ID())->setValue(anAngle);
154   data()->blockSendAttributeUpdated(aWasBlocked, false);
155 }
156
157 GeomShapePtr SketchPlugin_MacroArc::getArcShape()
158 {
159   if(!myStart.get() || !myEnd.get() || !myCenter.get()) {
160     return GeomShapePtr();
161   }
162
163   SketchPlugin_Sketch* aSketch = sketch();
164   if(!aSketch) {
165     return GeomShapePtr();
166   }
167
168   std::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(myCenter->x(), myCenter->y()));
169   std::shared_ptr<GeomAPI_Pnt> aStart(aSketch->to3D(myStart->x(), myStart->y()));
170   std::shared_ptr<GeomAPI_Pnt> anEnd(aSketch->to3D(myEnd->x(), myEnd->y()));
171   std::shared_ptr<GeomDataAPI_Dir> aNDir =
172     std::dynamic_pointer_cast<GeomDataAPI_Dir>(aSketch->attribute(SketchPlugin_Sketch::NORM_ID()));
173   std::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z()));
174
175   GeomShapePtr anArcShape = boolean(REVERSED_ID())->value() ?
176       GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, anEnd, aStart, aNormal)
177     : GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aStart, anEnd, aNormal);
178
179   return anArcShape;
180 }
181
182 AISObjectPtr SketchPlugin_MacroArc::getAISObject(AISObjectPtr thePrevious)
183 {
184   if(!myStart.get() || !myEnd.get() || !myCenter.get()) {
185     return AISObjectPtr();
186   }
187
188   SketchPlugin_Sketch* aSketch = sketch();
189   if(!aSketch) {
190     return AISObjectPtr();
191   }
192
193   GeomShapePtr anArcShape = getArcShape();
194   std::shared_ptr<GeomAPI_Pnt> aCenter = aSketch->to3D(myCenter->x(), myCenter->y());;
195   GeomShapePtr aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter);
196
197   if(!anArcShape.get() || !aCenterPointShape.get()) {
198     return AISObjectPtr();
199   }
200
201   std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
202   aShapes.push_back(anArcShape);
203   aShapes.push_back(aCenterPointShape);
204
205   std::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
206   AISObjectPtr anAIS = thePrevious;
207   if(!anAIS.get()) {
208     anAIS.reset(new GeomAPI_AISObject());
209   }
210   anAIS->createShape(aCompound);
211   return anAIS;
212 }
213
214 void SketchPlugin_MacroArc::execute()
215 {
216   FeaturePtr anArcFeature = createArcFeature();
217
218   myCenter.reset();
219   myStart.reset();
220   myEnd.reset();
221
222   // Create constraints.
223   std::string anArcType = string(ARC_TYPE())->value();
224   if(anArcType == ARC_TYPE_BY_CENTER_AND_POINTS()) {
225     SketchPlugin_Tools::createConstraint(this,
226                                          CENTER_POINT_REF_ID(),
227                                          anArcFeature->attribute(SketchPlugin_Arc::CENTER_ID()),
228                                          ObjectPtr(),
229                                          false);
230     SketchPlugin_Tools::createConstraint(this,
231                                          START_POINT_REF_ID(),
232                                          anArcFeature->attribute(SketchPlugin_Arc::START_ID()),
233                                          ObjectPtr(),
234                                          false);
235     SketchPlugin_Tools::createConstraint(this,
236                                          END_POINT_REF_ID(),
237                                          anArcFeature->attribute(SketchPlugin_Arc::END_ID()),
238                                          ObjectPtr(),
239                                          false);
240   } else if(anArcType == ARC_TYPE_BY_THREE_POINTS()) {
241     SketchPlugin_Tools::createConstraint(this,
242                                          START_POINT_REF_ID(),
243                                          anArcFeature->attribute(SketchPlugin_Arc::START_ID()),
244                                          ObjectPtr(),
245                                          false);
246     SketchPlugin_Tools::createConstraint(this,
247                                          END_POINT_REF_ID(),
248                                          anArcFeature->attribute(SketchPlugin_Arc::END_ID()),
249                                          ObjectPtr(),
250                                          false);
251     SketchPlugin_Tools::createConstraint(this,
252                                          PASSED_POINT_REF_ID(),
253                                          AttributePtr(),
254                                          anArcFeature->lastResult(),
255                                          true);
256   } else if(anArcType == ARC_TYPE_BY_TANGENT_EDGE()) {
257     // constraints for tangent arc
258     SketchPlugin_Tools::createConstraint(this,
259                                          TANGENT_POINT_ID(),
260                                          anArcFeature->attribute(SketchPlugin_Arc::START_ID()),
261                                          ObjectPtr(),
262                                          false);
263     FeaturePtr aTangent = sketch()->addFeature(SketchPlugin_ConstraintTangent::ID());
264     AttributeRefAttrPtr aRefAttrA = aTangent->refattr(SketchPlugin_Constraint::ENTITY_A());
265     AttributeRefAttrPtr aTgPntRefAttr = refattr(TANGENT_POINT_ID());
266     FeaturePtr aTgFeature = ModelAPI_Feature::feature(aTgPntRefAttr->attr()->owner());
267     aRefAttrA->setObject(aTgFeature->lastResult());
268     AttributeRefAttrPtr aRefAttrB = aTangent->refattr(SketchPlugin_Constraint::ENTITY_B());
269     aRefAttrB->setObject(anArcFeature->lastResult());
270     // constraint for end point
271     SketchPlugin_Tools::createConstraint(this,
272                                          END_POINT_REF_ID(),
273                                          anArcFeature->attribute(SketchPlugin_Arc::END_ID()),
274                                          ObjectPtr(),
275                                          false);
276   }
277
278   // message to init reentrant operation
279   static Events_ID anId = SketchPlugin_MacroArcReentrantMessage::eventId();
280   std::shared_ptr<SketchPlugin_MacroArcReentrantMessage> aMessage = std::shared_ptr
281     <SketchPlugin_MacroArcReentrantMessage>(new SketchPlugin_MacroArcReentrantMessage(anId, 0));
282
283   std::string anEditArcType = string(EDIT_ARC_TYPE_ID())->value();
284   aMessage->setTypeOfCreation(!anEditArcType.empty() ? anEditArcType : anArcType);
285   aMessage->setCreatedFeature(anArcFeature);
286   Events_Loop::loop()->send(aMessage);
287 }
288
289 std::string SketchPlugin_MacroArc::processEvent(const std::shared_ptr<Events_Message>& theMessage)
290 {
291   std::string aFilledAttributeName;
292   std::shared_ptr<SketchPlugin_MacroArcReentrantMessage> aReentrantMessage =
293         std::dynamic_pointer_cast<SketchPlugin_MacroArcReentrantMessage>(theMessage);
294   if (aReentrantMessage.get()) {
295     FeaturePtr aCreatedFeature = aReentrantMessage->createdFeature();
296     std::string anArcType = aReentrantMessage->typeOfCreation();
297
298     string(ARC_TYPE())->setValue(anArcType);
299
300     aFilledAttributeName = ARC_TYPE();
301     if(anArcType == ARC_TYPE_BY_TANGENT_EDGE()) {
302       aFilledAttributeName = TANGENT_POINT_ID();
303       AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
304                                                         attribute(aFilledAttributeName));
305       FeaturePtr aCreatedFeature = aReentrantMessage->createdFeature();
306       aRefAttr->setAttr(aCreatedFeature->attribute(SketchPlugin_Arc::END_ID()));
307     }
308     else {
309       ObjectPtr anObject = aReentrantMessage->selectedObject();
310       AttributePtr anAttribute = aReentrantMessage->selectedAttribute();
311       std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = aReentrantMessage->clickedPoint();
312
313       if (aClickedPoint.get() && (anObject.get() || anAttribute.get())) {
314         if (anArcType == ARC_TYPE_BY_CENTER_AND_POINTS() ||
315             anArcType == ARC_TYPE_BY_THREE_POINTS()) {
316           std::string aReferenceAttributeName;
317           if (anArcType == ARC_TYPE_BY_CENTER_AND_POINTS()) {
318             aFilledAttributeName = CENTER_POINT_ID();
319             aReferenceAttributeName = CENTER_POINT_REF_ID();
320           }
321           else {
322             aFilledAttributeName = START_POINT_2_ID();
323             aReferenceAttributeName = START_POINT_REF_ID();
324           }
325           // fill 2d point attribute
326           AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
327                                                             attribute(aFilledAttributeName));
328           aPointAttr->setValue(aClickedPoint);
329           // fill reference attribute
330           AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
331                                                             attribute(aReferenceAttributeName));
332           if (aRefAttr.get()) {
333             if (anAttribute.get())
334               aRefAttr->setAttr(anAttribute);
335             else if (anObject.get()) {
336               // if presentation of previous reentrant macro arc is used, the object is invalid,
337               // we should use result of previous feature of the message(Arc)
338               if (!anObject->data()->isValid()) {
339                 FeaturePtr aCreatedFeature = aReentrantMessage->createdFeature();
340                 anObject = aCreatedFeature->lastResult();
341               }
342               aRefAttr->setObject(anObject);
343             }
344           }
345         }
346       }
347     }
348     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
349   }
350   return aFilledAttributeName;
351 }
352
353 FeaturePtr SketchPlugin_MacroArc::createArcFeature()
354 {
355   FeaturePtr anArcFeature = sketch()->addFeature(SketchPlugin_Arc::ID());
356   std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
357       anArcFeature->attribute(SketchPlugin_Arc::CENTER_ID()))->setValue(myCenter);
358   std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
359       anArcFeature->attribute(SketchPlugin_Arc::START_ID()))->setValue(myStart);
360   std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
361       anArcFeature->attribute(SketchPlugin_Arc::END_ID()))->setValue(myEnd);
362   anArcFeature->boolean(SketchPlugin_Arc::REVERSED_ID())
363                 ->setValue(boolean(REVERSED_ID())->value());
364   anArcFeature->boolean(SketchPlugin_Arc::AUXILIARY_ID())
365                 ->setValue(boolean(AUXILIARY_ID())->value());
366   anArcFeature->execute();
367
368   return anArcFeature;
369 }
370
371 void SketchPlugin_MacroArc::fillByCenterAndTwoPassed()
372 {
373   AttributePoint2DPtr aCenterPointAttr =
374       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(CENTER_POINT_ID()));
375   if (!aCenterPointAttr->isInitialized())
376       return;
377
378   AttributePoint2DPtr aStartPointAttr =
379       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_POINT_1_ID()));
380   if (!aStartPointAttr->isInitialized())
381     return;
382
383   myCenter = aCenterPointAttr->pnt();
384   myStart = aStartPointAttr->pnt();
385   myEnd = myStart;
386
387   AttributePoint2DPtr anEndPointAttr =
388       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(END_POINT_1_ID()));
389   if (!anEndPointAttr->isInitialized())
390     return;
391
392   GeomAPI_Circ2d aCircleForArc(myCenter, myStart);
393
394   // End point should be a projection on circle.
395   bool aWasBlocked = data()->blockSendAttributeUpdated(true);
396   projectPointOnCircle(anEndPointAttr, aCircleForArc);
397   data()->blockSendAttributeUpdated(aWasBlocked, false);
398   myEnd = anEndPointAttr->pnt();
399
400   // update the REVERSED flag
401   recalculateReversedFlagByEnd(aCircleForArc);
402 }
403
404 void SketchPlugin_MacroArc::recalculateReversedFlagByEnd(const GeomAPI_Circ2d& theCurrentCircular)
405 {
406   double aParameterNew = 0.0;
407   if(theCurrentCircular.parameter(myEnd, paramTolerance, aParameterNew)) {
408     if(myParamBefore <= PI / 2.0 && aParameterNew >= PI * 1.5) {
409       boolean(REVERSED_ID())->setValue(true);
410     } else if(myParamBefore >= PI * 1.5 && aParameterNew <= PI / 2.0) {
411       boolean(REVERSED_ID())->setValue(false);
412     }
413   }
414   myParamBefore = aParameterNew;
415 }
416
417 void SketchPlugin_MacroArc::fillByThreePassedPoints()
418 {
419   AttributePoint2DPtr aStartPointAttr =
420       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_POINT_2_ID()));
421   if (!aStartPointAttr->isInitialized())
422     return;
423
424   AttributePoint2DPtr anEndPointAttr =
425       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(END_POINT_2_ID()));
426   if (!anEndPointAttr->isInitialized())
427     return;
428
429   myStart = aStartPointAttr->pnt();
430   myEnd = anEndPointAttr->pnt();
431
432   AttributePoint2DPtr aPassedPointAttr =
433       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(PASSED_POINT_ID()));
434   if (aPassedPointAttr->isInitialized()) {
435     std::shared_ptr<GeomAPI_Pnt2d> aPassedPnt;
436     std::shared_ptr<GeomAPI_Shape> aTangentCurve;
437     SketchPlugin_Tools::convertRefAttrToPointOrTangentCurve(
438         refattr(PASSED_POINT_REF_ID()), aPassedPointAttr, aTangentCurve, aPassedPnt);
439
440     std::shared_ptr<GeomAPI_Interface> aPassed;
441     if (aTangentCurve)
442       aPassed = aTangentCurve;
443     else
444       aPassed = aPassedPnt;
445
446     std::shared_ptr<GeomAPI_Ax3> anAxis = SketchPlugin_Sketch::plane(sketch());
447     GeomAPI_Circ2d aCircle(myStart, myEnd, aPassed, anAxis);
448     myCenter = aCircle.center();
449     aCircle = GeomAPI_Circ2d(myCenter, myStart);
450
451     recalculateReversedFlagByPassed(aCircle);
452   } else
453     myCenter.reset(new GeomAPI_Pnt2d(myStart->xy()->added(myEnd->xy())->multiplied(0.5)));
454 }
455
456 void SketchPlugin_MacroArc::recalculateReversedFlagByPassed(
457     const GeomAPI_Circ2d& theCurrentCircular)
458 {
459   AttributePoint2DPtr aPassedAttr =
460       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(PASSED_POINT_ID()));
461   std::shared_ptr<GeomAPI_Pnt2d> aPassed = theCurrentCircular.project(aPassedAttr->pnt());
462
463   double aEndParam, aPassedParam;
464   theCurrentCircular.parameter(myEnd, paramTolerance, aEndParam);
465   theCurrentCircular.parameter(aPassed, paramTolerance, aPassedParam);
466
467   if(aPassedParam > aEndParam)
468     boolean(REVERSED_ID())->setValue(true);
469   else
470     boolean(REVERSED_ID())->setValue(false);
471
472   myParamBefore = aEndParam;
473 }
474
475 void SketchPlugin_MacroArc::fillByTangentEdge()
476 {
477   AttributeRefAttrPtr aTangentAttr = refattr(TANGENT_POINT_ID());
478   if (!aTangentAttr->isInitialized())
479     return;
480
481   AttributePoint2DPtr aTangentPointAttr =
482       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aTangentAttr->attr());
483   if (!aTangentPointAttr->isInitialized())
484     return;
485
486   AttributePoint2DPtr anEndPointAttr =
487       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(END_POINT_3_ID()));
488   if (!anEndPointAttr->isInitialized())
489     return;
490
491   myStart = aTangentPointAttr->pnt();
492   myEnd = anEndPointAttr->pnt();
493   if (myStart->isEqual(myEnd))
494     return;
495
496   // obtain a shape the tangent point belongs to
497   FeaturePtr aTangentFeature = ModelAPI_Feature::feature(aTangentPointAttr->owner());
498   std::shared_ptr<GeomAPI_Shape> aTangentShape = aTangentFeature->lastResult()->shape();
499
500   std::shared_ptr<GeomAPI_Ax3> anAxis = SketchPlugin_Sketch::plane(sketch());
501   GeomAPI_Circ2d aCircle(myStart, myEnd, aTangentShape, anAxis);
502   myCenter = aCircle.center();
503
504   // rebuild circle to set start point equal to zero parameter
505   aCircle = GeomAPI_Circ2d(myCenter, myStart);
506   recalculateReversedFlagByEnd(aCircle);
507 }