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   Events_Loop::loop()->flush(anId);
288 }
289
290 std::string SketchPlugin_MacroArc::processEvent(const std::shared_ptr<Events_Message>& theMessage)
291 {
292   std::string aFilledAttributeName;
293   std::shared_ptr<SketchPlugin_MacroArcReentrantMessage> aReentrantMessage =
294         std::dynamic_pointer_cast<SketchPlugin_MacroArcReentrantMessage>(theMessage);
295   if (aReentrantMessage.get()) {
296     FeaturePtr aCreatedFeature = aReentrantMessage->createdFeature();
297     std::string anArcType = aReentrantMessage->typeOfCreation();
298
299     string(ARC_TYPE())->setValue(anArcType);
300
301     aFilledAttributeName = ARC_TYPE();
302     if(anArcType == ARC_TYPE_BY_TANGENT_EDGE()) {
303       aFilledAttributeName = TANGENT_POINT_ID();
304       AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
305                                                         attribute(aFilledAttributeName));
306       FeaturePtr aCreatedFeature = aReentrantMessage->createdFeature();
307       aRefAttr->setAttr(aCreatedFeature->attribute(SketchPlugin_Arc::END_ID()));
308     }
309     else {
310       ObjectPtr anObject = aReentrantMessage->selectedObject();
311       AttributePtr anAttribute = aReentrantMessage->selectedAttribute();
312       std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = aReentrantMessage->clickedPoint();
313
314       if (aClickedPoint.get() && (anObject.get() || anAttribute.get())) {
315         if (anArcType == ARC_TYPE_BY_CENTER_AND_POINTS() ||
316             anArcType == ARC_TYPE_BY_THREE_POINTS()) {
317           std::string aReferenceAttributeName;
318           if (anArcType == ARC_TYPE_BY_CENTER_AND_POINTS()) {
319             aFilledAttributeName = CENTER_POINT_ID();
320             aReferenceAttributeName = CENTER_POINT_REF_ID();
321           }
322           else {
323             aFilledAttributeName = START_POINT_2_ID();
324             aReferenceAttributeName = START_POINT_REF_ID();
325           }
326           // fill 2d point attribute
327           AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
328                                                             attribute(aFilledAttributeName));
329           aPointAttr->setValue(aClickedPoint);
330           // fill reference attribute
331           AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
332                                                             attribute(aReferenceAttributeName));
333           if (aRefAttr.get()) {
334             if (anAttribute.get())
335               aRefAttr->setAttr(anAttribute);
336             else if (anObject.get()) {
337               // if presentation of previous reentrant macro arc is used, the object is invalid,
338               // we should use result of previous feature of the message(Arc)
339               if (!anObject->data()->isValid()) {
340                 FeaturePtr aCreatedFeature = aReentrantMessage->createdFeature();
341                 anObject = aCreatedFeature->lastResult();
342               }
343               aRefAttr->setObject(anObject);
344             }
345           }
346         }
347       }
348     }
349     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
350   }
351   return aFilledAttributeName;
352 }
353
354 FeaturePtr SketchPlugin_MacroArc::createArcFeature()
355 {
356   FeaturePtr anArcFeature = sketch()->addFeature(SketchPlugin_Arc::ID());
357   std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
358       anArcFeature->attribute(SketchPlugin_Arc::CENTER_ID()))->setValue(myCenter);
359   std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
360       anArcFeature->attribute(SketchPlugin_Arc::START_ID()))->setValue(myStart);
361   std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
362       anArcFeature->attribute(SketchPlugin_Arc::END_ID()))->setValue(myEnd);
363   anArcFeature->boolean(SketchPlugin_Arc::REVERSED_ID())
364                 ->setValue(boolean(REVERSED_ID())->value());
365   anArcFeature->boolean(SketchPlugin_Arc::AUXILIARY_ID())
366                 ->setValue(boolean(AUXILIARY_ID())->value());
367   anArcFeature->execute();
368
369   return anArcFeature;
370 }
371
372 void SketchPlugin_MacroArc::fillByCenterAndTwoPassed()
373 {
374   AttributePoint2DPtr aCenterPointAttr =
375       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(CENTER_POINT_ID()));
376   if (!aCenterPointAttr->isInitialized())
377       return;
378
379   AttributePoint2DPtr aStartPointAttr =
380       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_POINT_1_ID()));
381   if (!aStartPointAttr->isInitialized())
382     return;
383
384   myCenter = aCenterPointAttr->pnt();
385   myStart = aStartPointAttr->pnt();
386   myEnd = myStart;
387
388   AttributePoint2DPtr anEndPointAttr =
389       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(END_POINT_1_ID()));
390   if (!anEndPointAttr->isInitialized())
391     return;
392
393   GeomAPI_Circ2d aCircleForArc(myCenter, myStart);
394
395   // End point should be a projection on circle.
396   bool aWasBlocked = data()->blockSendAttributeUpdated(true);
397   projectPointOnCircle(anEndPointAttr, aCircleForArc);
398   data()->blockSendAttributeUpdated(aWasBlocked, false);
399   myEnd = anEndPointAttr->pnt();
400
401   // update the REVERSED flag
402   recalculateReversedFlagByEnd(aCircleForArc);
403 }
404
405 void SketchPlugin_MacroArc::recalculateReversedFlagByEnd(const GeomAPI_Circ2d& theCurrentCircular)
406 {
407   double aParameterNew = 0.0;
408   if(theCurrentCircular.parameter(myEnd, paramTolerance, aParameterNew)) {
409     if(myParamBefore <= PI / 2.0 && aParameterNew >= PI * 1.5) {
410       boolean(REVERSED_ID())->setValue(true);
411     } else if(myParamBefore >= PI * 1.5 && aParameterNew <= PI / 2.0) {
412       boolean(REVERSED_ID())->setValue(false);
413     }
414   }
415   myParamBefore = aParameterNew;
416 }
417
418 void SketchPlugin_MacroArc::fillByThreePassedPoints()
419 {
420   AttributePoint2DPtr aStartPointAttr =
421       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_POINT_2_ID()));
422   if (!aStartPointAttr->isInitialized())
423     return;
424
425   AttributePoint2DPtr anEndPointAttr =
426       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(END_POINT_2_ID()));
427   if (!anEndPointAttr->isInitialized())
428     return;
429
430   myStart = aStartPointAttr->pnt();
431   myEnd = anEndPointAttr->pnt();
432
433   AttributePoint2DPtr aPassedPointAttr =
434       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(PASSED_POINT_ID()));
435   if (aPassedPointAttr->isInitialized()) {
436     std::shared_ptr<GeomAPI_Pnt2d> aPassedPnt;
437     std::shared_ptr<GeomAPI_Shape> aTangentCurve;
438     SketchPlugin_Tools::convertRefAttrToPointOrTangentCurve(
439         refattr(PASSED_POINT_REF_ID()), aPassedPointAttr, aTangentCurve, aPassedPnt);
440
441     std::shared_ptr<GeomAPI_Interface> aPassed;
442     if (aTangentCurve)
443       aPassed = aTangentCurve;
444     else
445       aPassed = aPassedPnt;
446
447     std::shared_ptr<GeomAPI_Ax3> anAxis = SketchPlugin_Sketch::plane(sketch());
448     GeomAPI_Circ2d aCircle(myStart, myEnd, aPassed, anAxis);
449     myCenter = aCircle.center();
450     aCircle = GeomAPI_Circ2d(myCenter, myStart);
451
452     recalculateReversedFlagByPassed(aCircle);
453   } else
454     myCenter.reset(new GeomAPI_Pnt2d(myStart->xy()->added(myEnd->xy())->multiplied(0.5)));
455 }
456
457 void SketchPlugin_MacroArc::recalculateReversedFlagByPassed(
458     const GeomAPI_Circ2d& theCurrentCircular)
459 {
460   AttributePoint2DPtr aPassedAttr =
461       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(PASSED_POINT_ID()));
462   std::shared_ptr<GeomAPI_Pnt2d> aPassed = theCurrentCircular.project(aPassedAttr->pnt());
463
464   double aEndParam, aPassedParam;
465   theCurrentCircular.parameter(myEnd, paramTolerance, aEndParam);
466   theCurrentCircular.parameter(aPassed, paramTolerance, aPassedParam);
467
468   if(aPassedParam > aEndParam)
469     boolean(REVERSED_ID())->setValue(true);
470   else
471     boolean(REVERSED_ID())->setValue(false);
472
473   myParamBefore = aEndParam;
474 }
475
476 void SketchPlugin_MacroArc::fillByTangentEdge()
477 {
478   AttributeRefAttrPtr aTangentAttr = refattr(TANGENT_POINT_ID());
479   if (!aTangentAttr->isInitialized())
480     return;
481
482   AttributePoint2DPtr aTangentPointAttr =
483       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aTangentAttr->attr());
484   if (!aTangentPointAttr->isInitialized())
485     return;
486
487   AttributePoint2DPtr anEndPointAttr =
488       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(END_POINT_3_ID()));
489   if (!anEndPointAttr->isInitialized())
490     return;
491
492   myStart = aTangentPointAttr->pnt();
493   myEnd = anEndPointAttr->pnt();
494   if (myStart->isEqual(myEnd))
495     return;
496
497   // obtain a shape the tangent point belongs to
498   FeaturePtr aTangentFeature = ModelAPI_Feature::feature(aTangentPointAttr->owner());
499   std::shared_ptr<GeomAPI_Shape> aTangentShape = aTangentFeature->lastResult()->shape();
500
501   std::shared_ptr<GeomAPI_Ax3> anAxis = SketchPlugin_Sketch::plane(sketch());
502   GeomAPI_Circ2d aCircle(myStart, myEnd, aTangentShape, anAxis);
503   myCenter = aCircle.center();
504
505   // rebuild circle to set start point equal to zero parameter
506   aCircle = GeomAPI_Circ2d(myCenter, myStart);
507   recalculateReversedFlagByEnd(aCircle);
508 }