From dd037b5c690552a228d6f06104b1997be411301a Mon Sep 17 00:00:00 2001 From: azv Date: Wed, 16 Oct 2019 14:13:50 +0300 Subject: [PATCH] Issue #3049: Create arc Perpendicular to a straight edge mode - impossible to create sequence of arcs --- src/SketchAPI/SketchAPI_Arc.cpp | 3 --- src/SketchAPI/SketchAPI_MacroArc.cpp | 13 ++++------ src/SketchAPI/SketchAPI_MacroArc.h | 6 ++++- src/SketchPlugin/SketchPlugin_MacroArc.cpp | 29 +++++++++++++++++----- src/SketchPlugin/SketchPlugin_MacroArc.h | 13 ++++++++++ src/SketchPlugin/plugin-Sketch.xml | 4 +-- 6 files changed, 48 insertions(+), 20 deletions(-) diff --git a/src/SketchAPI/SketchAPI_Arc.cpp b/src/SketchAPI/SketchAPI_Arc.cpp index 4f973996c..d71722b83 100644 --- a/src/SketchAPI/SketchAPI_Arc.cpp +++ b/src/SketchAPI/SketchAPI_Arc.cpp @@ -29,9 +29,6 @@ #include #include -/// Obtain constraints prepared by tangent arc -static std::list tangentArcConstraints(const FeaturePtr& theArc); - //================================================================================================ SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr & theFeature) : SketchAPI_SketchEntity(theFeature) diff --git a/src/SketchAPI/SketchAPI_MacroArc.cpp b/src/SketchAPI/SketchAPI_MacroArc.cpp index 67dc5f0c7..ebacfb9d1 100644 --- a/src/SketchAPI/SketchAPI_MacroArc.cpp +++ b/src/SketchAPI/SketchAPI_MacroArc.cpp @@ -29,9 +29,6 @@ #include #include -/// Obtain constraints prepared by tangent arc -static std::list tangentArcConstraints(const FeaturePtr& theArc); - //================================================================================================ SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr & theFeature) : SketchAPI_SketchEntity(theFeature) @@ -195,7 +192,7 @@ void SketchAPI_MacroArc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoin bool theInversed) { fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE(), myarcType); - fillAttribute(theTangentPoint, mytangentPoint); + fillAttribute(theTangentPoint, mytransversalPoint); fillAttribute(theEnd, myendPoint3); fillAttribute(theInversed, myreversed); @@ -208,8 +205,8 @@ void SketchAPI_MacroArc::setByTransversal(const ModelHighAPI_RefAttr& theTransve bool theInversed) { fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_TRANSVERSAL_LINE(), myarcType); - fillAttribute(theTransversalPoint, mytangentPoint); - fillAttribute(endPoint3(), theEndX, theEndY); + fillAttribute(theTransversalPoint, mytransversalPoint); + fillAttribute(endPoint4(), theEndX, theEndY); fillAttribute(theInversed, myreversed); execute(); @@ -221,8 +218,8 @@ void SketchAPI_MacroArc::setByTransversal(const ModelHighAPI_RefAttr& theTransve bool theInversed) { fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_TRANSVERSAL_LINE(), myarcType); - fillAttribute(theTransversalPoint, mytangentPoint); - fillAttribute(theEnd, myendPoint3); + fillAttribute(theTransversalPoint, mytransversalPoint); + fillAttribute(theEnd, myendPoint4); fillAttribute(theInversed, myreversed); execute(); diff --git a/src/SketchAPI/SketchAPI_MacroArc.h b/src/SketchAPI/SketchAPI_MacroArc.h index 3a6ae5566..5ac234cc0 100644 --- a/src/SketchAPI/SketchAPI_MacroArc.h +++ b/src/SketchAPI/SketchAPI_MacroArc.h @@ -88,7 +88,7 @@ public: SKETCHAPI_EXPORT virtual ~SketchAPI_MacroArc(); - INTERFACE_12(SketchPlugin_MacroArc::ID(), + INTERFACE_14(SketchPlugin_MacroArc::ID(), arcType, SketchPlugin_MacroArc::ARC_TYPE(), ModelAPI_AttributeString, /** Arc type */, center, SketchPlugin_MacroArc::CENTER_POINT_ID(), @@ -107,6 +107,10 @@ public: ModelAPI_AttributeRefAttr, /** Tangent point */, endPoint3, SketchPlugin_MacroArc::END_POINT_3_ID(), GeomDataAPI_Point2D, /** End point */, + transversalPoint, SketchPlugin_MacroArc::TRANSVERSAL_POINT_ID(), + ModelAPI_AttributeRefAttr, /** Transversal point */, + endPoint4, SketchPlugin_MacroArc::END_POINT_4_ID(), + GeomDataAPI_Point2D, /** End point */, reversed, SketchPlugin_MacroArc::REVERSED_ID(), ModelAPI_AttributeBoolean, /** Reversed flag */, radius, SketchPlugin_MacroArc::RADIUS_ID(), diff --git a/src/SketchPlugin/SketchPlugin_MacroArc.cpp b/src/SketchPlugin/SketchPlugin_MacroArc.cpp index eab082403..ed2caaf65 100644 --- a/src/SketchPlugin/SketchPlugin_MacroArc.cpp +++ b/src/SketchPlugin/SketchPlugin_MacroArc.cpp @@ -154,6 +154,9 @@ void SketchPlugin_MacroArc::initAttributes() data()->addAttribute(TANGENT_POINT_ID(), ModelAPI_AttributeRefAttr::typeId()); data()->addAttribute(END_POINT_3_ID(), GeomDataAPI_Point2D::typeId()); + data()->addAttribute(TRANSVERSAL_POINT_ID(), ModelAPI_AttributeRefAttr::typeId()); + data()->addAttribute(END_POINT_4_ID(), GeomDataAPI_Point2D::typeId()); + data()->addAttribute(REVERSED_ID(), ModelAPI_AttributeBoolean::typeId()); data()->addAttribute(RADIUS_ID(), ModelAPI_AttributeDouble::typeId()); @@ -196,6 +199,8 @@ void SketchPlugin_MacroArc::attributeChanged(const std::string& theID) SketchPlugin_Tools::resetAttribute(this, PASSED_POINT_REF_ID()); SketchPlugin_Tools::resetAttribute(this, TANGENT_POINT_ID()); SketchPlugin_Tools::resetAttribute(this, END_POINT_3_ID()); + SketchPlugin_Tools::resetAttribute(this, TRANSVERSAL_POINT_ID()); + SketchPlugin_Tools::resetAttribute(this, END_POINT_4_ID()); SketchPlugin_Tools::resetAttribute(this, REVERSED_ID()); SketchPlugin_Tools::resetAttribute(this, RADIUS_ID()); SketchPlugin_Tools::resetAttribute(this, ANGLE_ID()); @@ -345,8 +350,10 @@ void SketchPlugin_MacroArc::execute() true); } else { // coincident with connection point + const std::string& aPointAttr = anArcType == ARC_TYPE_BY_TANGENT_EDGE() ? + TANGENT_POINT_ID() : TRANSVERSAL_POINT_ID(); SketchPlugin_Tools::createCoincidenceOrTangency(this, - TANGENT_POINT_ID(), + aPointAttr, anArcFeature->attribute(SketchPlugin_Arc::START_ID()), ObjectPtr(), false); @@ -359,7 +366,7 @@ void SketchPlugin_MacroArc::execute() // setting attributes of the start point constraint AttributeRefAttrPtr aRefAttrA = aStartPointConstraint->refattr(SketchPlugin_Constraint::ENTITY_A()); - AttributeRefAttrPtr aTgPntRefAttr = refattr(TANGENT_POINT_ID()); + AttributeRefAttrPtr aTgPntRefAttr = refattr(aPointAttr); FeaturePtr aTgFeature = ModelAPI_Feature::feature(aTgPntRefAttr->attr()->owner()); aRefAttrA->setObject(aTgFeature->lastResult()); AttributeRefAttrPtr aRefAttrB = @@ -399,11 +406,18 @@ std::string SketchPlugin_MacroArc::processEvent(const std::shared_ptr( - attribute(aFilledAttributeName)); + AttributeRefAttrPtr aRefAttr = refattr(aFilledAttributeName); FeaturePtr aCreatedFeature = aReentrantMessage->createdFeature(); aRefAttr->setAttr(aCreatedFeature->attribute(SketchPlugin_Arc::END_ID())); } + else if (anArcType == ARC_TYPE_BY_TRANSVERSAL_LINE()) { + AttributeRefAttrPtr aRefAttr = refattr(TRANSVERSAL_POINT_ID()); + AttributePtr anAttribute = aReentrantMessage->selectedAttribute(); + if (anAttribute) { + aRefAttr->setAttr(anAttribute); + aFilledAttributeName = TRANSVERSAL_POINT_ID(); + } + } else { ObjectPtr anObject = aReentrantMessage->selectedObject(); AttributePtr anAttribute = aReentrantMessage->selectedAttribute(); @@ -610,7 +624,10 @@ void SketchPlugin_MacroArc::recalculateReversedFlagByPassed( void SketchPlugin_MacroArc::fillByEdge(bool theTransversal) { - AttributeRefAttrPtr aTangentAttr = refattr(TANGENT_POINT_ID()); + const std::string& aStartPoint = theTransversal ? TRANSVERSAL_POINT_ID() : TANGENT_POINT_ID(); + const std::string& aEndPoint = theTransversal ? END_POINT_4_ID() : END_POINT_3_ID(); + + AttributeRefAttrPtr aTangentAttr = refattr(aStartPoint); if (!aTangentAttr->isInitialized()) return; @@ -620,7 +637,7 @@ void SketchPlugin_MacroArc::fillByEdge(bool theTransversal) return; AttributePoint2DPtr anEndPointAttr = - std::dynamic_pointer_cast(attribute(END_POINT_3_ID())); + std::dynamic_pointer_cast(attribute(aEndPoint)); if (!anEndPointAttr->isInitialized()) return; diff --git a/src/SketchPlugin/SketchPlugin_MacroArc.h b/src/SketchPlugin/SketchPlugin_MacroArc.h index 886f6efdc..305b89d8a 100644 --- a/src/SketchPlugin/SketchPlugin_MacroArc.h +++ b/src/SketchPlugin/SketchPlugin_MacroArc.h @@ -132,6 +132,13 @@ class SketchPlugin_MacroArc: public SketchPlugin_SketchEntity, return ID; } + /// End 2D point of the arc + inline static const std::string& END_POINT_4_ID() + { + static const std::string ID = "end_point_4"; + return ID; + } + inline static const std::string& END_POINT_REF_ID() { static const std::string ID = "end_point_ref"; @@ -157,6 +164,12 @@ class SketchPlugin_MacroArc: public SketchPlugin_SketchEntity, return ID; } + static const std::string& TRANSVERSAL_POINT_ID() + { + static const std::string ID("transversal_point"); + return ID; + } + /// Reversed flag inline static const std::string& REVERSED_ID() { diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 69f43adf8..d1a9378d4 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -277,13 +277,13 @@ - -