X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchAPI%2FSketchAPI_MacroEllipse.cpp;h=e667f5b0c0f4f812ec9383b894c283ff3801aeb9;hb=745c72679f6346375d5e886b25cc3865f3c4daae;hp=c3ed48080d6f9d365379ccf597a359d7fc3aae32;hpb=c30e18c73237bc82890b00fe48352f88e054ed5b;p=modules%2Fshaper.git diff --git a/src/SketchAPI/SketchAPI_MacroEllipse.cpp b/src/SketchAPI/SketchAPI_MacroEllipse.cpp index c3ed48080..e667f5b0c 100644 --- a/src/SketchAPI/SketchAPI_MacroEllipse.cpp +++ b/src/SketchAPI/SketchAPI_MacroEllipse.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// Copyright (C) 2014-2021 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -28,38 +28,16 @@ #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 POINT_ATTR(x) (std::dynamic_pointer_cast(feature()->attribute((x)))) +#define POINT_REF(x) (feature()->refattr((x))) -#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; -} - - -SketchAPI_MacroEllipse::SketchAPI_MacroEllipse(const std::shared_ptr& theFeature) +SketchAPI_MacroEllipse::SketchAPI_MacroEllipse(const std::shared_ptr& theFeature, + bool callInitialize) : SketchAPI_SketchEntity(theFeature) { - initialize(); + if (callInitialize && initialize()) + storeSketch(theFeature); } SketchAPI_MacroEllipse::SketchAPI_MacroEllipse(const std::shared_ptr& theFeature, @@ -70,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, @@ -170,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)