X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchAPI%2FSketchAPI_MacroEllipse.cpp;h=9700e1e375644bb565a644febe4c07b82739339b;hb=c6745a6b1ad00c0285fab5aeac2cb0d57afef5cc;hp=e833775e204e281e037e7eb4a0e1486f0439d681;hpb=ed5df03349ef8e7a9ab592a6a52df0a801d5af14;p=modules%2Fshaper.git diff --git a/src/SketchAPI/SketchAPI_MacroEllipse.cpp b/src/SketchAPI/SketchAPI_MacroEllipse.cpp index e833775e2..9700e1e37 100644 --- a/src/SketchAPI/SketchAPI_MacroEllipse.cpp +++ b/src/SketchAPI/SketchAPI_MacroEllipse.cpp @@ -28,32 +28,8 @@ #include -#define MAJOR_AXIS_NEGATIVE (std::dynamic_pointer_cast( \ - feature()->attribute(SketchPlugin_MacroEllipse::FIRST_POINT_ID()))) -#define MAJOR_AXIS_POSITIVE (std::dynamic_pointer_cast( \ - feature()->attribute(SketchPlugin_MacroEllipse::SECOND_POINT_ID()))) -#define PASSED_POINT (std::dynamic_pointer_cast( \ - feature()->attribute(SketchPlugin_MacroEllipse::PASSED_POINT_ID()))) - -#define MAJOR_AXIS_NEGATIVE_REF (feature()->refattr( \ - SketchPlugin_MacroEllipse::FIRST_POINT_REF_ID())) -#define MAJOR_AXIS_POSITIVE_REF (feature()->refattr( \ - SketchPlugin_MacroEllipse::SECOND_POINT_REF_ID())) -#define PASSED_POINT_REF (feature()->refattr(SketchPlugin_MacroEllipse::PASSED_POINT_REF_ID())) - - -// find a parent sketch -static CompositeFeaturePtr sketch(FeaturePtr theFeature) -{ - CompositeFeaturePtr aSketch; - const std::set& aRefs = theFeature->data()->refsToMe(); - for (std::set::const_iterator anIt = aRefs.begin(); anIt != aRefs.end(); ++anIt) - if ((*anIt)->id() == SketchPlugin_Sketch::FEATURES_ID()) { - aSketch = std::dynamic_pointer_cast((*anIt)->owner()); - break; - } - return aSketch; -} +#define POINT_ATTR(x) (std::dynamic_pointer_cast(feature()->attribute((x)))) +#define POINT_REF(x) (feature()->refattr((x))) SketchAPI_MacroEllipse::SketchAPI_MacroEllipse(const std::shared_ptr& theFeature, @@ -61,7 +37,7 @@ SketchAPI_MacroEllipse::SketchAPI_MacroEllipse(const std::shared_ptr& theFeature, @@ -72,12 +48,16 @@ SketchAPI_MacroEllipse::SketchAPI_MacroEllipse(const std::shared_ptr& thePoint1, - const std::shared_ptr& thePoint2, - const std::shared_ptr& thePoint3) -{ - fillAttribute(thePoint1, MAJOR_AXIS_NEGATIVE); - fillAttribute(thePoint2, MAJOR_AXIS_POSITIVE); - fillAttribute(thePoint3, PASSED_POINT); - - mySketch = sketch(feature()); - execute(); -} - static void fillAttribute(const std::shared_ptr& thePoint, const ModelHighAPI_RefAttr& thePointRef, std::shared_ptr thePointAttr, @@ -172,25 +124,73 @@ static void fillAttribute(const std::shared_ptr& thePoint, fillAttribute(aPoint, thePointAttr); } -void SketchAPI_MacroEllipse::initializePoints( - const std::shared_ptr& theMajorAxisPoint1, - const ModelHighAPI_RefAttr& theMajorAxisPoint1Ref, - const std::shared_ptr& theMajorAxisPoint2, - const ModelHighAPI_RefAttr& theMajorAxisPoint2Ref, +void SketchAPI_MacroEllipse::setByCenterAndPassedPoints( + const std::shared_ptr& theCenter, + const ModelHighAPI_RefAttr& theCenterRef, + const std::shared_ptr& theMajorAxisPoint, + const ModelHighAPI_RefAttr& theMajorAxisPointRef, + const std::shared_ptr& thePassedPoint, + const ModelHighAPI_RefAttr& thePassedPointRef) +{ + fillAttribute(SketchPlugin_MacroEllipse::ELLIPSE_TYPE_BY_CENTER_AXIS_POINT(), myellipseType); + + AttributePoint2DPtr aCenterAttr = POINT_ATTR(SketchPlugin_MacroEllipse::CENTER_POINT_ID()); + AttributePoint2DPtr aMajorAxisAttr = POINT_ATTR(SketchPlugin_MacroEllipse::MAJOR_AXIS_POINT_ID()); + AttributePoint2DPtr aPassedAttr = POINT_ATTR(SketchPlugin_MacroEllipse::PASSED_POINT_ID()); + + AttributeRefAttrPtr aCenterRef = POINT_REF(SketchPlugin_MacroEllipse::CENTER_POINT_REF_ID()); + AttributeRefAttrPtr aMajorAxisRef = + POINT_REF(SketchPlugin_MacroEllipse::MAJOR_AXIS_POINT_REF_ID()); + AttributeRefAttrPtr aPassedRef = POINT_REF(SketchPlugin_MacroEllipse::PASSED_POINT_REF_ID()); + + fillAttribute(theCenter, theCenterRef, aCenterAttr, aCenterRef); + fillAttribute(theMajorAxisPoint, theMajorAxisPointRef, aMajorAxisAttr, aMajorAxisRef); + fillAttribute(thePassedPoint, thePassedPointRef, aPassedAttr, aPassedRef); + + storeSketch(feature()); + execute(); +} + +void SketchAPI_MacroEllipse::setByMajorAxisAndPassedPoint( + const std::shared_ptr& theMajorAxisStart, + const ModelHighAPI_RefAttr& theMajorAxisStartRef, + const std::shared_ptr& theMajorAxisEnd, + const ModelHighAPI_RefAttr& theMajorAxisEndRef, const std::shared_ptr& thePassedPoint, const ModelHighAPI_RefAttr& thePassedPointRef) { - fillAttribute(theMajorAxisPoint1, theMajorAxisPoint1Ref, - MAJOR_AXIS_NEGATIVE, MAJOR_AXIS_NEGATIVE_REF); - fillAttribute(theMajorAxisPoint2, theMajorAxisPoint2Ref, - MAJOR_AXIS_POSITIVE, MAJOR_AXIS_POSITIVE_REF); - fillAttribute(thePassedPoint, thePassedPointRef, - PASSED_POINT, PASSED_POINT_REF); - - mySketch = sketch(feature()); + 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& aRefs = theFeature->data()->refsToMe(); + for (std::set::const_iterator anIt = aRefs.begin(); anIt != aRefs.end(); ++anIt) + if ((*anIt)->id() == SketchPlugin_Sketch::FEATURES_ID()) { + mySketch = std::dynamic_pointer_cast((*anIt)->owner()); + break; + } +} + std::shared_ptr SketchAPI_MacroEllipse::center() { if (!myCenter)