X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchAPI%2FSketchAPI_MacroEllipse.cpp;h=7a8c4a04af3cfa2b335097a7eeda5331fffdc990;hb=44b3aa1055279520a1b3d7a6a77f90bf8db5d087;hp=ded0f75ba05b1014cfb03c0377fb69eccbbad5f2;hpb=661aafa65364b86fdbfc9fde9462d31bdf3ae151;p=modules%2Fshaper.git diff --git a/src/SketchAPI/SketchAPI_MacroEllipse.cpp b/src/SketchAPI/SketchAPI_MacroEllipse.cpp index ded0f75ba..7a8c4a04a 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-2020 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 @@ -18,16 +18,26 @@ // #include "SketchAPI_MacroEllipse.h" +#include "SketchAPI_Line.h" +#include "SketchAPI_Point.h" #include #include #include -SketchAPI_MacroEllipse::SketchAPI_MacroEllipse(const std::shared_ptr& theFeature) +#include + +#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, + bool callInitialize) : SketchAPI_SketchEntity(theFeature) { - initialize(); + if (callInitialize && initialize()) + storeSketch(theFeature); } SketchAPI_MacroEllipse::SketchAPI_MacroEllipse(const std::shared_ptr& theFeature, @@ -38,12 +48,16 @@ SketchAPI_MacroEllipse::SketchAPI_MacroEllipse(const std::shared_ptr& thePoint1, - const std::shared_ptr& thePoint2, - const std::shared_ptr& thePoint3) -{ - fillAttribute(thePoint1, mymajorAxisNegativePoint); - fillAttribute(thePoint2, mymajorAxisPositivePoint); - fillAttribute(thePoint3, mypassedPoint); - - execute(); -} - static void fillAttribute(const std::shared_ptr& thePoint, const ModelHighAPI_RefAttr& thePointRef, std::shared_ptr thePointAttr, @@ -136,19 +124,151 @@ 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(theMajorAxisPoint1, theMajorAxisPoint1Ref, - mymajorAxisNegativePoint, mymajorAxisNegativePointRef); - fillAttribute(theMajorAxisPoint2, theMajorAxisPoint2Ref, - mymajorAxisPositivePoint, mymajorAxisPositivePointRef); - fillAttribute(thePassedPoint, thePassedPointRef, mypassedPoint, mypassedPointRef); + 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(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) + collectAuxiliary(); + return myCenter; +} + +std::shared_ptr SketchAPI_MacroEllipse::focus1() +{ + if (!myFocus1) + collectAuxiliary(); + return myFocus1; +} + +std::shared_ptr SketchAPI_MacroEllipse::focus2() +{ + if (!myFocus2) + collectAuxiliary(); + return myFocus2; +} + +std::shared_ptr SketchAPI_MacroEllipse::majorAxisStart() +{ + if (!myMajorAxisStart) + collectAuxiliary(); + return myMajorAxisStart; +} + +std::shared_ptr SketchAPI_MacroEllipse::majorAxisEnd() +{ + if (!myMajorAxisEnd) + collectAuxiliary(); + return myMajorAxisEnd; +} + +std::shared_ptr SketchAPI_MacroEllipse::minorAxisStart() +{ + if (!myMinorAxisStart) + collectAuxiliary(); + return myMinorAxisStart; +} + +std::shared_ptr SketchAPI_MacroEllipse::minorAxisEnd() +{ + if (!myMinorAxisEnd) + collectAuxiliary(); + return myMinorAxisEnd; +} + +std::shared_ptr SketchAPI_MacroEllipse::majorAxis() +{ + if (!myMajorAxis) + collectAuxiliary(); + return myMajorAxis; +} + +std::shared_ptr SketchAPI_MacroEllipse::minorAxis() +{ + if (!myMinorAxis) + collectAuxiliary(); + return myMinorAxis; +} + +void SketchAPI_MacroEllipse::collectAuxiliary() +{ + // collect auxiliary features + int aNbSubs = mySketch->numberOfSubs(); + std::shared_ptr* anAuxPoint[] = { + &myCenter, &myFocus1, &myFocus2, + &myMajorAxisStart, &myMajorAxisEnd, + &myMinorAxisStart, &myMinorAxisEnd + }; + std::shared_ptr* 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)); + } +}