From: azv Date: Mon, 7 Oct 2019 10:10:59 +0000 (+0300) Subject: Fix problem with sequential drawing of ellipses. X-Git-Tag: V9_4_0a2~4^2~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=358f0fc98592877657c0736c1beccf86358f063e;p=modules%2Fshaper.git Fix problem with sequential drawing of ellipses. --- diff --git a/src/SketchAPI/SketchAPI_MacroEllipse.cpp b/src/SketchAPI/SketchAPI_MacroEllipse.cpp index 97138d413..9700e1e37 100644 --- a/src/SketchAPI/SketchAPI_MacroEllipse.cpp +++ b/src/SketchAPI/SketchAPI_MacroEllipse.cpp @@ -28,18 +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())) +#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, @@ -58,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); - - storeSketch(feature()); - execute(); -} - static void fillAttribute(const std::shared_ptr& thePoint, const ModelHighAPI_RefAttr& thePointRef, std::shared_ptr thePointAttr, @@ -158,20 +124,58 @@ 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, - 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); + 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(); diff --git a/src/SketchAPI/SketchAPI_MacroEllipse.h b/src/SketchAPI/SketchAPI_MacroEllipse.h index 8f0e88d83..bc2ab1333 100644 --- a/src/SketchAPI/SketchAPI_MacroEllipse.h +++ b/src/SketchAPI/SketchAPI_MacroEllipse.h @@ -100,27 +100,19 @@ protected: private: /// Set flag of creation by center, major semi-axis and passed point. - void setByCenterAndPassedPoints(); + void 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); /// Set flag of creation by major axis and passed point. - void setByMajorAxisAndPassedPoint(); - - /// Set points of ellipse. - void initializePoints(double theMajorAxisX1, double theMajorAxisY1, - double theMajorAxisX2, double theMajorAxisY2, - double thePassedX, double thePassedY); - - /// Set points of ellipse. - void initializePoints(const std::shared_ptr& theMajorAxisPoint1, - const std::shared_ptr& theMajorAxisPoint2, - const std::shared_ptr& thePassedPoint); - - /// Set points of ellipse. - void initializePoints(const std::shared_ptr& theMajorAxisPoint1, - const ModelHighAPI_RefAttr& theMajorAxisPoint1Ref, - const std::shared_ptr& theMajorAxisPoint2, - const ModelHighAPI_RefAttr& theMajorAxisPoint2Ref, - const std::shared_ptr& thePassedPoint, - const ModelHighAPI_RefAttr& thePassedPointRef); + void 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); /// Collect auxiliary features void collectAuxiliary(); diff --git a/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp b/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp index a4abe7b7d..53e605717 100644 --- a/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp +++ b/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp @@ -57,22 +57,32 @@ void SketchPlugin_MacroEllipse::initAttributes() data()->addAttribute(ELLIPSE_TYPE(), ModelAPI_AttributeString::typeId()); data()->addAttribute(EDIT_ELLIPSE_TYPE(), ModelAPI_AttributeString::typeId()); - data()->addAttribute(FIRST_POINT_ID(), GeomDataAPI_Point2D::typeId()); - data()->addAttribute(FIRST_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId()); - data()->addAttribute(SECOND_POINT_ID(), GeomDataAPI_Point2D::typeId()); - data()->addAttribute(SECOND_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId()); + data()->addAttribute(CENTER_POINT_ID(), GeomDataAPI_Point2D::typeId()); + data()->addAttribute(CENTER_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId()); + data()->addAttribute(MAJOR_AXIS_POINT_ID(), GeomDataAPI_Point2D::typeId()); + data()->addAttribute(MAJOR_AXIS_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId()); data()->addAttribute(PASSED_POINT_ID(), GeomDataAPI_Point2D::typeId()); data()->addAttribute(PASSED_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId()); + data()->addAttribute(MAJOR_AXIS_START_ID(), GeomDataAPI_Point2D::typeId()); + data()->addAttribute(MAJOR_AXIS_START_REF_ID(), ModelAPI_AttributeRefAttr::typeId()); + data()->addAttribute(MAJOR_AXIS_END_ID(), GeomDataAPI_Point2D::typeId()); + data()->addAttribute(MAJOR_AXIS_END_REF_ID(), ModelAPI_AttributeRefAttr::typeId()); + data()->addAttribute(PASSED_POINT_1_ID(), GeomDataAPI_Point2D::typeId()); + data()->addAttribute(PASSED_POINT_1_REF_ID(), ModelAPI_AttributeRefAttr::typeId()); + data()->addAttribute(MAJOR_RADIUS_ID(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(MINOR_RADIUS_ID(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(AUXILIARY_ID(), ModelAPI_AttributeBoolean::typeId()); string(EDIT_ELLIPSE_TYPE())->setValue(""); - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FIRST_POINT_REF_ID()); - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), SECOND_POINT_REF_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CENTER_POINT_REF_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), MAJOR_AXIS_POINT_REF_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PASSED_POINT_REF_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), MAJOR_AXIS_START_REF_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), MAJOR_AXIS_END_REF_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PASSED_POINT_1_REF_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EDIT_ELLIPSE_TYPE()); } @@ -100,12 +110,25 @@ void SketchPlugin_MacroEllipse::execute() void SketchPlugin_MacroEllipse::attributeChanged(const std::string& theID) { static const int NB_POINTS = 3; - std::string aPointAttrName[NB_POINTS] = { FIRST_POINT_ID(), - SECOND_POINT_ID(), - PASSED_POINT_ID() }; - std::string aPointRefName[NB_POINTS] = { FIRST_POINT_REF_ID(), - SECOND_POINT_REF_ID(), - PASSED_POINT_REF_ID() }; + std::string aPointAttrName[NB_POINTS]; + std::string aPointRefName[NB_POINTS]; + if (string(ELLIPSE_TYPE())->value() == ELLIPSE_TYPE_BY_CENTER_AXIS_POINT()) { + aPointAttrName[0] = CENTER_POINT_ID(); + aPointAttrName[1] = MAJOR_AXIS_POINT_ID(); + aPointAttrName[2] = PASSED_POINT_ID(); + aPointRefName[0] = CENTER_POINT_REF_ID(); + aPointRefName[1] = MAJOR_AXIS_POINT_REF_ID(); + aPointRefName[2] = PASSED_POINT_REF_ID(); + } else if (string(ELLIPSE_TYPE())->value() == ELLIPSE_TYPE_BY_AXIS_AND_POINT()) { + aPointAttrName[0] = MAJOR_AXIS_START_ID(); + aPointAttrName[1] = MAJOR_AXIS_END_ID(); + aPointAttrName[2] = PASSED_POINT_1_ID(); + aPointRefName[0] = MAJOR_AXIS_START_REF_ID(); + aPointRefName[1] = MAJOR_AXIS_END_REF_ID(); + aPointRefName[2] = PASSED_POINT_1_REF_ID(); + } + else + return; // type of ellipse switched, thus reset all attributes if (theID == ELLIPSE_TYPE()) { @@ -195,8 +218,12 @@ std::string SketchPlugin_MacroEllipse::processEvent( std::shared_ptr aClickedPoint = aReentrantMessage->clickedPoint(); if (aClickedPoint && (anObject || anAttribute)) { - aFilledAttributeName = FIRST_POINT_ID(); - std::string aReferenceAttributeName = FIRST_POINT_REF_ID(); + aFilledAttributeName = CENTER_POINT_ID(); + std::string aReferenceAttributeName = CENTER_POINT_REF_ID(); + if (anEllipseType == ELLIPSE_TYPE_BY_AXIS_AND_POINT()) { + aFilledAttributeName = MAJOR_AXIS_START_ID(); + aReferenceAttributeName = MAJOR_AXIS_START_REF_ID(); + } // fill 2d point attribute AttributePoint2DPtr aPointAttr = @@ -208,7 +235,7 @@ std::string SketchPlugin_MacroEllipse::processEvent( std::dynamic_pointer_cast(attribute(aReferenceAttributeName)); if (anAttribute) { if (!anAttribute->owner() || !anAttribute->owner()->data()->isValid()) { - if (aCreatedFeature && anAttribute->id() == FIRST_POINT_ID()) + if (aCreatedFeature && anAttribute->id() == CENTER_POINT_ID()) anAttribute = aCreatedFeature->attribute( anEllipseType == ELLIPSE_TYPE_BY_CENTER_AXIS_POINT() ? SketchPlugin_Ellipse::CENTER_ID() : @@ -237,11 +264,11 @@ void SketchPlugin_MacroEllipse::constraintsForEllipseByCenterAxisAndPassed( static const bool isTangencyApplicable = false; // Create constraints. SketchPlugin_Tools::createCoincidenceOrTangency( - this, FIRST_POINT_REF_ID(), + this, CENTER_POINT_REF_ID(), theEllipseFeature->attribute(SketchPlugin_Ellipse::CENTER_ID()), ObjectPtr(), isTangencyApplicable); SketchPlugin_Tools::createCoincidenceOrTangency( - this, SECOND_POINT_REF_ID(), + this, MAJOR_AXIS_POINT_REF_ID(), theEllipseFeature->attribute(SketchPlugin_Ellipse::MAJOR_AXIS_END_ID()), ObjectPtr(), isTangencyApplicable); // make coincidence only if PASSED_POINT_REF_ID() refers a point but not an object @@ -259,17 +286,17 @@ void SketchPlugin_MacroEllipse::constraintsForEllipseByMajoxAxisAndPassed( static const bool isTangencyApplicable = false; // Create constraints. SketchPlugin_Tools::createCoincidenceOrTangency( - this, FIRST_POINT_REF_ID(), + this, MAJOR_AXIS_START_REF_ID(), theEllipseFeature->attribute(SketchPlugin_Ellipse::MAJOR_AXIS_START_ID()), ObjectPtr(), isTangencyApplicable); SketchPlugin_Tools::createCoincidenceOrTangency( - this, SECOND_POINT_REF_ID(), + this, MAJOR_AXIS_END_REF_ID(), theEllipseFeature->attribute(SketchPlugin_Ellipse::MAJOR_AXIS_END_ID()), ObjectPtr(), isTangencyApplicable); // make coincidence only if PASSED_POINT_REF_ID() refers a point but not an object - if (!refattr(PASSED_POINT_REF_ID())->isObject()) { + if (!refattr(PASSED_POINT_1_REF_ID())->isObject()) { SketchPlugin_Tools::createCoincidenceOrTangency( - this, PASSED_POINT_REF_ID(), AttributePtr(), + this, PASSED_POINT_1_REF_ID(), AttributePtr(), theEllipseFeature->lastResult(), isTangencyApplicable); } } diff --git a/src/SketchPlugin/SketchPlugin_MacroEllipse.h b/src/SketchPlugin/SketchPlugin_MacroEllipse.h index 609d96bf6..f1a875257 100644 --- a/src/SketchPlugin/SketchPlugin_MacroEllipse.h +++ b/src/SketchPlugin/SketchPlugin_MacroEllipse.h @@ -67,28 +67,28 @@ class SketchPlugin_MacroEllipse: public SketchPlugin_SketchEntity, } /// Attribute for the first point selected during ellipse creation. - inline static const std::string& FIRST_POINT_ID() + inline static const std::string& CENTER_POINT_ID() { static const std::string ID("first_point"); return ID; } /// Reference to the first selected point. - inline static const std::string& FIRST_POINT_REF_ID() + inline static const std::string& CENTER_POINT_REF_ID() { static const std::string ID("first_point_ref"); return ID; } /// Attribute for the second point selected during ellipse creation. - inline static const std::string& SECOND_POINT_ID() + inline static const std::string& MAJOR_AXIS_POINT_ID() { static const std::string ID("second_point"); return ID; } /// Reference to the second selected point. - inline static const std::string& SECOND_POINT_REF_ID() + inline static const std::string& MAJOR_AXIS_POINT_REF_ID() { static const std::string ID("second_point_ref"); return ID; @@ -108,6 +108,48 @@ class SketchPlugin_MacroEllipse: public SketchPlugin_SketchEntity, return ID; } + /// Attribute for the first point selected during ellipse creation. + inline static const std::string& MAJOR_AXIS_START_ID() + { + static const std::string ID("first_point_1"); + return ID; + } + + /// Reference to the first selected point. + inline static const std::string& MAJOR_AXIS_START_REF_ID() + { + static const std::string ID("first_point_ref_1"); + return ID; + } + + /// Attribute for the second point selected during ellipse creation. + inline static const std::string& MAJOR_AXIS_END_ID() + { + static const std::string ID("second_point_1"); + return ID; + } + + /// Reference to the second selected point. + inline static const std::string& MAJOR_AXIS_END_REF_ID() + { + static const std::string ID("second_point_ref_1"); + return ID; + } + + /// Attribute for the third point selected during ellipse creation. + inline static const std::string& PASSED_POINT_1_ID() + { + static const std::string ID("passed_point_1"); + return ID; + } + + /// Reference for passed point selection. + inline static const std::string& PASSED_POINT_1_REF_ID() + { + static const std::string ID("passed_point_ref_1"); + return ID; + } + /// Major radius of the ellipse inline static const std::string& MAJOR_RADIUS_ID() { diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 6acca9a92..1476a1492 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -422,20 +422,20 @@ - - -