1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: SketchPlugin_MacroArc.cpp
4 // Created: 26 Apr 2014
5 // Author: Artem ZHIDKOV
7 #include "SketchPlugin_MacroArc.h"
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"
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>
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 #include <GeomAPI_ShapeIterator.h>
34 #include <GeomDataAPI_Point2D.h>
35 #include <GeomDataAPI_Dir.h>
37 #include <GeomAlgoAPI_Circ2dBuilder.h>
38 #include <GeomAlgoAPI_EdgeBuilder.h>
39 #include <GeomAlgoAPI_CompoundBuilder.h>
40 #include <GeomAlgoAPI_PointBuilder.h>
45 const double tolerance = 1e-7;
46 const double paramTolerance = 1.e-4;
47 const double PI = 3.141592653589793238463;
49 static void projectPointOnCircle(AttributePoint2DPtr& thePoint, const GeomAPI_Circ2d& theCircle)
51 std::shared_ptr<GeomAPI_Pnt2d> aProjection = theCircle.project(thePoint->pnt());
53 thePoint->setValue(aProjection);
56 static void intersectShapeAndCircle(const GeomShapePtr& theShape,
57 const GeomAPI_Circ2d& theCircle,
58 const SketchPlugin_Sketch* theSketch,
59 AttributePoint2DPtr& theIntersection)
61 if (!theShape->isEdge())
62 return projectPointOnCircle(theIntersection, theCircle);
64 // convert shape to unbounded
65 std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theShape));
66 if (anEdge->isLine()) {
67 static const double HALF_SIZE = 1.e6;
68 std::shared_ptr<GeomAPI_XYZ> aLoc = anEdge->line()->location()->xyz();
69 std::shared_ptr<GeomAPI_XYZ> aDir = anEdge->line()->direction()->xyz();
71 std::shared_ptr<GeomAPI_Pnt> aStart(
72 new GeomAPI_Pnt(aLoc->added(aDir->multiplied(-HALF_SIZE))));
73 std::shared_ptr<GeomAPI_Pnt> aEnd(
74 new GeomAPI_Pnt(aLoc->added(aDir->multiplied(HALF_SIZE))));
75 anEdge = GeomAlgoAPI_EdgeBuilder::line(aStart, aEnd);
76 } else if (anEdge->isArc()) {
77 std::shared_ptr<GeomAPI_Circ> aCircle = anEdge->circle();
78 anEdge = GeomAlgoAPI_EdgeBuilder::lineCircle(
79 aCircle->center(), aCircle->normal(), aCircle->radius());
82 // convert 2D circle to 3D object
83 std::shared_ptr<GeomAPI_Pnt2d> aCenter2d = theCircle.center();
84 std::shared_ptr<GeomAPI_Pnt> aCenter(theSketch->to3D(aCenter2d->x(), aCenter2d->y()));
85 std::shared_ptr<GeomDataAPI_Dir> aNDir = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
86 const_cast<SketchPlugin_Sketch*>(theSketch)->attribute(SketchPlugin_Sketch::NORM_ID()));
87 std::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z()));
89 GeomShapePtr aCircleShape =
90 GeomAlgoAPI_EdgeBuilder::lineCircle(aCenter, aNormal, theCircle.radius());
92 GeomShapePtr anInter = anEdge->intersect(aCircleShape);
93 std::shared_ptr<GeomAPI_Pnt2d> anInterPnt;
95 return projectPointOnCircle(theIntersection, theCircle);
96 if (anInter->isVertex()) {
97 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(anInter));
98 anInterPnt = theSketch->to2D(aVertex->point());
99 } else if (anInter->isCompound()) {
100 double aMinDist = 1.e300;
102 GeomAPI_ShapeIterator anIt(anInter);
103 for (; anIt.more(); anIt.next()) {
104 GeomShapePtr aCurrent = anIt.current();
105 if (!aCurrent->isVertex())
107 std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aCurrent));
108 std::shared_ptr<GeomAPI_Pnt2d> aPnt = theSketch->to2D(aVertex->point());
109 double aDist = aPnt->distance(theIntersection->pnt());
110 if (aDist < aMinDist) {
116 theIntersection->setValue(anInterPnt);
120 SketchPlugin_MacroArc::SketchPlugin_MacroArc()
121 : SketchPlugin_SketchEntity(),
126 void SketchPlugin_MacroArc::initAttributes()
128 data()->addAttribute(ARC_TYPE(), ModelAPI_AttributeString::typeId());
130 data()->addAttribute(CENTER_POINT_ID(), GeomDataAPI_Point2D::typeId());
131 data()->addAttribute(START_POINT_1_ID(), GeomDataAPI_Point2D::typeId());
132 data()->addAttribute(END_POINT_1_ID(), GeomDataAPI_Point2D::typeId());
134 data()->addAttribute(START_POINT_2_ID(), GeomDataAPI_Point2D::typeId());
135 data()->addAttribute(END_POINT_2_ID(), GeomDataAPI_Point2D::typeId());
136 data()->addAttribute(PASSED_POINT_ID(), GeomDataAPI_Point2D::typeId());
138 data()->addAttribute(TANGENT_POINT_ID(), ModelAPI_AttributeRefAttr::typeId());
139 data()->addAttribute(END_POINT_3_ID(), GeomDataAPI_Point2D::typeId());
141 data()->addAttribute(REVERSED_ID(), ModelAPI_AttributeBoolean::typeId());
143 data()->addAttribute(RADIUS_ID(), ModelAPI_AttributeDouble::typeId());
144 data()->addAttribute(ANGLE_ID(), ModelAPI_AttributeDouble::typeId());
146 data()->addAttribute(AUXILIARY_ID(), ModelAPI_AttributeBoolean::typeId());
148 data()->addAttribute(CENTER_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId());
149 data()->addAttribute(START_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId());
150 data()->addAttribute(END_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId());
151 data()->addAttribute(PASSED_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId());
153 data()->addAttribute(EDIT_ARC_TYPE_ID(), ModelAPI_AttributeString::typeId());
155 boolean(REVERSED_ID())->setValue(false);
156 string(EDIT_ARC_TYPE_ID())->setValue("");
158 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CENTER_POINT_REF_ID());
159 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), START_POINT_REF_ID());
160 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), END_POINT_REF_ID());
161 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PASSED_POINT_REF_ID());
162 ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EDIT_ARC_TYPE_ID());
165 void SketchPlugin_MacroArc::attributeChanged(const std::string& theID)
167 std::string anArcType = string(ARC_TYPE())->value();
169 // If arc type switched reset according attributes.
170 if(theID == ARC_TYPE()) {
171 SketchPlugin_Tools::resetAttribute(this, CENTER_POINT_ID());
172 SketchPlugin_Tools::resetAttribute(this, CENTER_POINT_REF_ID());
173 SketchPlugin_Tools::resetAttribute(this, START_POINT_1_ID());
174 SketchPlugin_Tools::resetAttribute(this, START_POINT_REF_ID());
175 SketchPlugin_Tools::resetAttribute(this, END_POINT_1_ID());
176 SketchPlugin_Tools::resetAttribute(this, END_POINT_REF_ID());
177 SketchPlugin_Tools::resetAttribute(this, START_POINT_2_ID());
178 SketchPlugin_Tools::resetAttribute(this, END_POINT_2_ID());
179 SketchPlugin_Tools::resetAttribute(this, PASSED_POINT_ID());
180 SketchPlugin_Tools::resetAttribute(this, PASSED_POINT_REF_ID());
181 SketchPlugin_Tools::resetAttribute(this, TANGENT_POINT_ID());
182 SketchPlugin_Tools::resetAttribute(this, END_POINT_3_ID());
183 SketchPlugin_Tools::resetAttribute(this, REVERSED_ID());
184 SketchPlugin_Tools::resetAttribute(this, RADIUS_ID());
185 SketchPlugin_Tools::resetAttribute(this, ANGLE_ID());
190 boolean(REVERSED_ID())->setValue(false);
192 } else if(anArcType == ARC_TYPE_BY_CENTER_AND_POINTS())
193 fillByCenterAndTwoPassed();
194 else if(anArcType == ARC_TYPE_BY_THREE_POINTS())
195 fillByThreePassedPoints();
196 else if(anArcType == ARC_TYPE_BY_TANGENT_EDGE())
201 if(myCenter.get() && myStart.get()) {
202 aRadius = myCenter->distance(myStart);
204 if(myStart->isEqual(myEnd)) {
207 GeomAPI_Circ2d aCircleForArc(myCenter, myStart);
208 double aStartParam, anEndParam;
209 aCircleForArc.parameter(myStart, paramTolerance, aStartParam);
210 aCircleForArc.parameter(myEnd, paramTolerance, anEndParam);
211 anAngle = (anEndParam - aStartParam) / PI * 180.0;
212 if(boolean(REVERSED_ID())->value()) anAngle = 360.0 - anAngle;
217 bool aWasBlocked = data()->blockSendAttributeUpdated(true);
218 real(RADIUS_ID())->setValue(aRadius);
219 real(ANGLE_ID())->setValue(anAngle);
220 data()->blockSendAttributeUpdated(aWasBlocked, false);
223 GeomShapePtr SketchPlugin_MacroArc::getArcShape(bool isBound)
225 if(!myStart.get() || !myEnd.get() || !myCenter.get()) {
226 return GeomShapePtr();
229 SketchPlugin_Sketch* aSketch = sketch();
231 return GeomShapePtr();
234 std::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(myCenter->x(), myCenter->y()));
235 std::shared_ptr<GeomAPI_Pnt> aStart(aSketch->to3D(myStart->x(), myStart->y()));
236 std::shared_ptr<GeomAPI_Pnt> anEnd(aSketch->to3D(myEnd->x(), myEnd->y()));
237 std::shared_ptr<GeomDataAPI_Dir> aNDir =
238 std::dynamic_pointer_cast<GeomDataAPI_Dir>(aSketch->attribute(SketchPlugin_Sketch::NORM_ID()));
239 std::shared_ptr<GeomAPI_Dir> aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z()));
241 GeomShapePtr anArcShape;
243 anArcShape = boolean(REVERSED_ID())->value() ?
244 GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, anEnd, aStart, aNormal)
245 : GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aStart, anEnd, aNormal);
247 double aRadius = aCenter->distance(aStart);
248 anArcShape = GeomAlgoAPI_EdgeBuilder::lineCircle(aCenter, aNormal, aRadius);
254 AISObjectPtr SketchPlugin_MacroArc::getAISObject(AISObjectPtr thePrevious)
256 if(!myStart.get() || !myEnd.get() || !myCenter.get()) {
257 return AISObjectPtr();
260 SketchPlugin_Sketch* aSketch = sketch();
262 return AISObjectPtr();
265 GeomShapePtr anArcShape = getArcShape();
266 std::shared_ptr<GeomAPI_Pnt> aCenter = aSketch->to3D(myCenter->x(), myCenter->y());;
267 GeomShapePtr aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter);
269 if(!anArcShape.get() || !aCenterPointShape.get()) {
270 return AISObjectPtr();
273 std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
274 aShapes.push_back(anArcShape);
275 aShapes.push_back(aCenterPointShape);
277 std::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
278 AISObjectPtr anAIS = thePrevious;
280 anAIS.reset(new GeomAPI_AISObject());
282 anAIS->createShape(aCompound);
286 void SketchPlugin_MacroArc::execute()
288 FeaturePtr anArcFeature = createArcFeature();
294 // Create constraints.
295 std::string anArcType = string(ARC_TYPE())->value();
296 if(anArcType == ARC_TYPE_BY_CENTER_AND_POINTS()) {
297 SketchPlugin_Tools::createConstraint(this,
298 CENTER_POINT_REF_ID(),
299 anArcFeature->attribute(SketchPlugin_Arc::CENTER_ID()),
302 SketchPlugin_Tools::createConstraint(this,
303 START_POINT_REF_ID(),
304 anArcFeature->attribute(SketchPlugin_Arc::START_ID()),
307 SketchPlugin_Tools::createConstraint(this,
309 anArcFeature->attribute(SketchPlugin_Arc::END_ID()),
312 } else if(anArcType == ARC_TYPE_BY_THREE_POINTS()) {
313 SketchPlugin_Tools::createConstraint(this,
314 START_POINT_REF_ID(),
315 anArcFeature->attribute(SketchPlugin_Arc::START_ID()),
318 SketchPlugin_Tools::createConstraint(this,
320 anArcFeature->attribute(SketchPlugin_Arc::END_ID()),
323 SketchPlugin_Tools::createConstraint(this,
324 PASSED_POINT_REF_ID(),
326 anArcFeature->lastResult(),
328 } else if(anArcType == ARC_TYPE_BY_TANGENT_EDGE()) {
329 // constraints for tangent arc
330 SketchPlugin_Tools::createConstraint(this,
332 anArcFeature->attribute(SketchPlugin_Arc::START_ID()),
335 FeaturePtr aTangent = sketch()->addFeature(SketchPlugin_ConstraintTangent::ID());
336 AttributeRefAttrPtr aRefAttrA = aTangent->refattr(SketchPlugin_Constraint::ENTITY_A());
337 AttributeRefAttrPtr aTgPntRefAttr = refattr(TANGENT_POINT_ID());
338 FeaturePtr aTgFeature = ModelAPI_Feature::feature(aTgPntRefAttr->attr()->owner());
339 aRefAttrA->setObject(aTgFeature->lastResult());
340 AttributeRefAttrPtr aRefAttrB = aTangent->refattr(SketchPlugin_Constraint::ENTITY_B());
341 aRefAttrB->setObject(anArcFeature->lastResult());
342 // constraint for end point
343 SketchPlugin_Tools::createConstraint(this,
345 anArcFeature->attribute(SketchPlugin_Arc::END_ID()),
350 // message to init reentrant operation
351 static Events_ID anId = SketchPlugin_MacroArcReentrantMessage::eventId();
352 std::shared_ptr<SketchPlugin_MacroArcReentrantMessage> aMessage = std::shared_ptr
353 <SketchPlugin_MacroArcReentrantMessage>(new SketchPlugin_MacroArcReentrantMessage(anId, 0));
355 std::string anEditArcType = string(EDIT_ARC_TYPE_ID())->value();
356 aMessage->setTypeOfCreation(!anEditArcType.empty() ? anEditArcType : anArcType);
357 aMessage->setCreatedFeature(anArcFeature);
358 Events_Loop::loop()->send(aMessage);
361 std::string SketchPlugin_MacroArc::processEvent(const std::shared_ptr<Events_Message>& theMessage)
363 std::string aFilledAttributeName;
364 std::shared_ptr<SketchPlugin_MacroArcReentrantMessage> aReentrantMessage =
365 std::dynamic_pointer_cast<SketchPlugin_MacroArcReentrantMessage>(theMessage);
366 if (aReentrantMessage.get()) {
367 FeaturePtr aCreatedFeature = aReentrantMessage->createdFeature();
368 std::string anArcType = aReentrantMessage->typeOfCreation();
370 string(ARC_TYPE())->setValue(anArcType);
372 aFilledAttributeName = ARC_TYPE();
373 if(anArcType == ARC_TYPE_BY_TANGENT_EDGE()) {
374 aFilledAttributeName = TANGENT_POINT_ID();
375 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
376 attribute(aFilledAttributeName));
377 FeaturePtr aCreatedFeature = aReentrantMessage->createdFeature();
378 aRefAttr->setAttr(aCreatedFeature->attribute(SketchPlugin_Arc::END_ID()));
381 ObjectPtr anObject = aReentrantMessage->selectedObject();
382 AttributePtr anAttribute = aReentrantMessage->selectedAttribute();
383 std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = aReentrantMessage->clickedPoint();
385 if (aClickedPoint.get() && (anObject.get() || anAttribute.get())) {
386 if (anArcType == ARC_TYPE_BY_CENTER_AND_POINTS() ||
387 anArcType == ARC_TYPE_BY_THREE_POINTS()) {
388 std::string aReferenceAttributeName;
389 if (anArcType == ARC_TYPE_BY_CENTER_AND_POINTS()) {
390 aFilledAttributeName = CENTER_POINT_ID();
391 aReferenceAttributeName = CENTER_POINT_REF_ID();
394 aFilledAttributeName = START_POINT_2_ID();
395 aReferenceAttributeName = START_POINT_REF_ID();
397 // fill 2d point attribute
398 AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
399 attribute(aFilledAttributeName));
400 aPointAttr->setValue(aClickedPoint);
401 // fill reference attribute
402 AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
403 attribute(aReferenceAttributeName));
404 if (aRefAttr.get()) {
405 if (anAttribute.get())
406 aRefAttr->setAttr(anAttribute);
407 else if (anObject.get()) {
408 // if presentation of previous reentrant macro arc is used, the object is invalid,
409 // we should use result of previous feature of the message(Arc)
410 if (!anObject->data()->isValid()) {
411 FeaturePtr aCreatedFeature = aReentrantMessage->createdFeature();
412 anObject = aCreatedFeature->lastResult();
414 aRefAttr->setObject(anObject);
420 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
422 return aFilledAttributeName;
425 FeaturePtr SketchPlugin_MacroArc::createArcFeature()
427 FeaturePtr anArcFeature = sketch()->addFeature(SketchPlugin_Arc::ID());
428 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
429 anArcFeature->attribute(SketchPlugin_Arc::CENTER_ID()))->setValue(myCenter);
430 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
431 anArcFeature->attribute(SketchPlugin_Arc::START_ID()))->setValue(myStart);
432 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
433 anArcFeature->attribute(SketchPlugin_Arc::END_ID()))->setValue(myEnd);
434 anArcFeature->boolean(SketchPlugin_Arc::REVERSED_ID())
435 ->setValue(boolean(REVERSED_ID())->value());
436 anArcFeature->boolean(SketchPlugin_Arc::AUXILIARY_ID())
437 ->setValue(boolean(AUXILIARY_ID())->value());
438 anArcFeature->execute();
443 void SketchPlugin_MacroArc::fillByCenterAndTwoPassed()
445 AttributePoint2DPtr aCenterPointAttr =
446 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(CENTER_POINT_ID()));
447 if (!aCenterPointAttr->isInitialized())
450 AttributePoint2DPtr aStartPointAttr =
451 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_POINT_1_ID()));
452 if (!aStartPointAttr->isInitialized())
455 myCenter = aCenterPointAttr->pnt();
456 myStart = aStartPointAttr->pnt();
459 AttributePoint2DPtr anEndPointAttr =
460 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(END_POINT_1_ID()));
461 if (!anEndPointAttr->isInitialized())
464 GeomAPI_Circ2d aCircleForArc(myCenter, myStart);
466 bool aWasBlocked = data()->blockSendAttributeUpdated(true);
467 // check the end point is referred to another feature
468 GeomShapePtr aRefShape;
469 AttributeRefAttrPtr aEndPointRefAttr = refattr(END_POINT_REF_ID());
470 if (aEndPointRefAttr && aEndPointRefAttr->isInitialized()) {
471 if (aEndPointRefAttr->isObject()) {
472 FeaturePtr aFeature = ModelAPI_Feature::feature(aEndPointRefAttr->object());
474 aRefShape = aFeature->lastResult()->shape();
478 // Calculate end point as an intersection between circle and another shape
479 intersectShapeAndCircle(aRefShape, aCircleForArc, sketch(), anEndPointAttr);
481 // End point should be a projection on circle.
482 projectPointOnCircle(anEndPointAttr, aCircleForArc);
484 data()->blockSendAttributeUpdated(aWasBlocked, false);
485 myEnd = anEndPointAttr->pnt();
487 // update the REVERSED flag
488 recalculateReversedFlagByEnd(aCircleForArc);
491 void SketchPlugin_MacroArc::recalculateReversedFlagByEnd(const GeomAPI_Circ2d& theCurrentCircular)
493 double aParameterNew = 0.0;
494 if(theCurrentCircular.parameter(myEnd, paramTolerance, aParameterNew)) {
495 if(myParamBefore <= PI / 2.0 && aParameterNew >= PI * 1.5) {
496 boolean(REVERSED_ID())->setValue(true);
497 } else if(myParamBefore >= PI * 1.5 && aParameterNew <= PI / 2.0) {
498 boolean(REVERSED_ID())->setValue(false);
501 myParamBefore = aParameterNew;
504 void SketchPlugin_MacroArc::fillByThreePassedPoints()
506 AttributePoint2DPtr aStartPointAttr =
507 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_POINT_2_ID()));
508 if (!aStartPointAttr->isInitialized())
511 AttributePoint2DPtr anEndPointAttr =
512 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(END_POINT_2_ID()));
513 if (!anEndPointAttr->isInitialized())
516 myStart = aStartPointAttr->pnt();
517 myEnd = anEndPointAttr->pnt();
519 AttributePoint2DPtr aPassedPointAttr =
520 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(PASSED_POINT_ID()));
521 if (aPassedPointAttr->isInitialized()) {
522 std::shared_ptr<GeomAPI_Pnt2d> aPassedPnt;
523 std::shared_ptr<GeomAPI_Shape> aTangentCurve;
524 SketchPlugin_Tools::convertRefAttrToPointOrTangentCurve(
525 refattr(PASSED_POINT_REF_ID()), aPassedPointAttr, aTangentCurve, aPassedPnt);
527 GeomAlgoAPI_Circ2dBuilder aCircBuilder(SketchPlugin_Sketch::plane(sketch()));
528 aCircBuilder.addPassingPoint(myStart);
529 aCircBuilder.addPassingPoint(myEnd);
531 aCircBuilder.addTangentCurve(aTangentCurve);
532 aCircBuilder.setClosestPoint(aPassedPointAttr->pnt());
534 aCircBuilder.addPassingPoint(aPassedPnt);
536 std::shared_ptr<GeomAPI_Circ2d> aCircle = aCircBuilder.circle();
539 myCenter = aCircle->center();
541 aCircle = std::shared_ptr<GeomAPI_Circ2d>(new GeomAPI_Circ2d(myCenter, myStart));
542 recalculateReversedFlagByPassed(*aCircle);
544 myCenter.reset(new GeomAPI_Pnt2d(myStart->xy()->added(myEnd->xy())->multiplied(0.5)));
547 void SketchPlugin_MacroArc::recalculateReversedFlagByPassed(
548 const GeomAPI_Circ2d& theCurrentCircular)
550 AttributePoint2DPtr aPassedAttr =
551 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(PASSED_POINT_ID()));
552 std::shared_ptr<GeomAPI_Pnt2d> aPassed = theCurrentCircular.project(aPassedAttr->pnt());
554 double aEndParam, aPassedParam;
555 theCurrentCircular.parameter(myEnd, paramTolerance, aEndParam);
556 theCurrentCircular.parameter(aPassed, paramTolerance, aPassedParam);
558 if(aPassedParam > aEndParam)
559 boolean(REVERSED_ID())->setValue(true);
561 boolean(REVERSED_ID())->setValue(false);
563 myParamBefore = aEndParam;
566 void SketchPlugin_MacroArc::fillByTangentEdge()
568 AttributeRefAttrPtr aTangentAttr = refattr(TANGENT_POINT_ID());
569 if (!aTangentAttr->isInitialized())
572 AttributePoint2DPtr aTangentPointAttr =
573 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aTangentAttr->attr());
574 if (!aTangentPointAttr->isInitialized())
577 AttributePoint2DPtr anEndPointAttr =
578 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(END_POINT_3_ID()));
579 if (!anEndPointAttr->isInitialized())
582 myStart = aTangentPointAttr->pnt();
583 myEnd = anEndPointAttr->pnt();
584 if (myStart->isEqual(myEnd))
587 // obtain a shape the tangent point belongs to
588 FeaturePtr aTangentFeature = ModelAPI_Feature::feature(aTangentPointAttr->owner());
589 std::shared_ptr<GeomAPI_Shape> aTangentShape = aTangentFeature->lastResult()->shape();
591 GeomAlgoAPI_Circ2dBuilder aCircBuilder(SketchPlugin_Sketch::plane(sketch()));
592 aCircBuilder.addPassingPoint(myStart);
593 aCircBuilder.addPassingPoint(myEnd);
594 aCircBuilder.addTangentCurve(aTangentShape);
596 std::shared_ptr<GeomAPI_Circ2d> aCircle = aCircBuilder.circle();
597 myCenter = aCircle->center();
599 // rebuild circle to set start point equal to zero parameter
600 aCircle = std::shared_ptr<GeomAPI_Circ2d>(new GeomAPI_Circ2d(myCenter, myStart));
601 recalculateReversedFlagByEnd(*aCircle);