+
+void SketchAPI_MacroEllipse::setByMajorAxisAndPassedPoint(
+ const std::shared_ptr<GeomAPI_Pnt2d>& theMajorAxisStart,
+ const ModelHighAPI_RefAttr& theMajorAxisStartRef,
+ const std::shared_ptr<GeomAPI_Pnt2d>& theMajorAxisEnd,
+ const ModelHighAPI_RefAttr& theMajorAxisEndRef,
+ const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint,
+ const ModelHighAPI_RefAttr& thePassedPointRef)
+{
+ fillAttribute(SketchPlugin_MacroEllipse::ELLIPSE_TYPE_BY_AXIS_AND_POINT(), myellipseType);
+
+ AttributePoint2DPtr aMajorAxisStartAttr =
+ POINT_ATTR(SketchPlugin_MacroEllipse::MAJOR_AXIS_START_ID());
+ AttributePoint2DPtr aMajorAxisEndAttr =
+ POINT_ATTR(SketchPlugin_MacroEllipse::MAJOR_AXIS_END_ID());
+ AttributePoint2DPtr aPassedAttr = POINT_ATTR(SketchPlugin_MacroEllipse::PASSED_POINT_1_ID());
+
+ AttributeRefAttrPtr aMajorAxisStartRef =
+ POINT_REF(SketchPlugin_MacroEllipse::MAJOR_AXIS_START_REF_ID());
+ AttributeRefAttrPtr aMajorAxisEndRef =
+ POINT_REF(SketchPlugin_MacroEllipse::MAJOR_AXIS_END_REF_ID());
+ AttributeRefAttrPtr aPassedRef = POINT_REF(SketchPlugin_MacroEllipse::PASSED_POINT_1_REF_ID());
+
+ fillAttribute(theMajorAxisStart, theMajorAxisStartRef, aMajorAxisStartAttr, aMajorAxisStartRef);
+ fillAttribute(theMajorAxisEnd, theMajorAxisEndRef, aMajorAxisEndAttr, aMajorAxisEndRef);
+ fillAttribute(thePassedPoint, thePassedPointRef, aPassedAttr, aPassedRef);
+
+ storeSketch(feature());
+ execute();
+}
+
+void SketchAPI_MacroEllipse::storeSketch(const FeaturePtr& theFeature)
+{
+ const std::set<AttributePtr>& aRefs = theFeature->data()->refsToMe();
+ for (std::set<AttributePtr>::const_iterator anIt = aRefs.begin(); anIt != aRefs.end(); ++anIt)
+ if ((*anIt)->id() == SketchPlugin_Sketch::FEATURES_ID()) {
+ mySketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>((*anIt)->owner());
+ break;
+ }
+}
+
+std::shared_ptr<SketchAPI_Point> SketchAPI_MacroEllipse::center()
+{
+ if (!myCenter)
+ collectAuxiliary();
+ return myCenter;
+}
+
+std::shared_ptr<SketchAPI_Point> SketchAPI_MacroEllipse::focus1()
+{
+ if (!myFocus1)
+ collectAuxiliary();
+ return myFocus1;
+}
+
+std::shared_ptr<SketchAPI_Point> SketchAPI_MacroEllipse::focus2()
+{
+ if (!myFocus2)
+ collectAuxiliary();
+ return myFocus2;
+}
+
+std::shared_ptr<SketchAPI_Point> SketchAPI_MacroEllipse::majorAxisStart()
+{
+ if (!myMajorAxisStart)
+ collectAuxiliary();
+ return myMajorAxisStart;
+}
+
+std::shared_ptr<SketchAPI_Point> SketchAPI_MacroEllipse::majorAxisEnd()
+{
+ if (!myMajorAxisEnd)
+ collectAuxiliary();
+ return myMajorAxisEnd;
+}
+
+std::shared_ptr<SketchAPI_Point> SketchAPI_MacroEllipse::minorAxisStart()
+{
+ if (!myMinorAxisStart)
+ collectAuxiliary();
+ return myMinorAxisStart;
+}
+
+std::shared_ptr<SketchAPI_Point> SketchAPI_MacroEllipse::minorAxisEnd()
+{
+ if (!myMinorAxisEnd)
+ collectAuxiliary();
+ return myMinorAxisEnd;
+}
+
+std::shared_ptr<SketchAPI_Line> SketchAPI_MacroEllipse::majorAxis()
+{
+ if (!myMajorAxis)
+ collectAuxiliary();
+ return myMajorAxis;
+}
+
+std::shared_ptr<SketchAPI_Line> SketchAPI_MacroEllipse::minorAxis()
+{
+ if (!myMinorAxis)
+ collectAuxiliary();
+ return myMinorAxis;
+}
+
+void SketchAPI_MacroEllipse::collectAuxiliary()
+{
+ // collect auxiliary features
+ int aNbSubs = mySketch->numberOfSubs();
+ std::shared_ptr<SketchAPI_Point>* anAuxPoint[] = {
+ &myCenter, &myFocus1, &myFocus2,
+ &myMajorAxisStart, &myMajorAxisEnd,
+ &myMinorAxisStart, &myMinorAxisEnd
+ };
+ std::shared_ptr<SketchAPI_Line>* anAuxLine[] = {&myMajorAxis, &myMinorAxis};
+ for (int aPtInd = 7, aLinInd = 2; (aPtInd > 0 || aLinInd > 0) && aNbSubs >= 0; ) {
+ FeaturePtr aCurFeature = mySketch->subFeature(--aNbSubs);
+ if (aPtInd > 0 && aCurFeature->getKind() == SketchPlugin_Point::ID())
+ anAuxPoint[--aPtInd]->reset(new SketchAPI_Point(aCurFeature));
+ else if (aLinInd > 0 && aCurFeature->getKind() == SketchPlugin_Line::ID())
+ anAuxLine[--aLinInd]->reset(new SketchAPI_Line(aCurFeature));
+ }
+}