From 7311aa08755d2e9e1ede57a284dc53d4912507c9 Mon Sep 17 00:00:00 2001 From: dbv Date: Fri, 24 Mar 2017 17:04:06 +0300 Subject: [PATCH] Issue #2024: Redesign of circle and arc of circle Redesigned "real" arc feature. --- src/SketchPlugin/SketchPlugin_Arc.cpp | 43 +++++++++++++++- src/SketchPlugin/SketchPlugin_MacroArc.cpp | 58 ++++++++++++++++++++++ 2 files changed, 99 insertions(+), 2 deletions(-) diff --git a/src/SketchPlugin/SketchPlugin_Arc.cpp b/src/SketchPlugin/SketchPlugin_Arc.cpp index e752c7be1..9ebf16eb3 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.cpp +++ b/src/SketchPlugin/SketchPlugin_Arc.cpp @@ -192,13 +192,52 @@ void SketchPlugin_Arc::attributeChanged(const std::string& theID) aCirc->parameter(anEdge->lastPoint(), paramTolerance, anEndParam); aWasBlocked = data()->blockSendAttributeUpdated(true); if(aStartParam < aMidParam && aMidParam < anEndParam) { - setReversed(true); - } else { setReversed(false); + } else { + setReversed(true); } data()->blockSendAttributeUpdated(aWasBlocked, false); } } + } else if(theID == CENTER_ID() || theID == START_ID() || theID == END_ID()) { + if(!aCenterAttr->isInitialized() + || !aStartAttr->isInitialized() + || !anEndAttr->isInitialized()) { + return; + } + std::shared_ptr aCenter = aCenterAttr->pnt(); + std::shared_ptr aStart = aStartAttr->pnt(); + std::shared_ptr anEnd = anEndAttr->pnt(); + double aRadius = aCenter->distance(aStart); + if (aRadius < tolerance) + return; + std::shared_ptr aCircleForArc(new GeomAPI_Circ2d(aCenter, aStart)); + + bool aWasBlocked = data()->blockSendAttributeUpdated(true); + // The Arc end point is projected + // on the circle formed by center and start points + std::shared_ptr aProjection = aCircleForArc->project(anEnd); + if (aProjection && anEnd->distance(aProjection) > tolerance) { + anEndAttr->setValue(aProjection); + anEnd = aProjection; + } + data()->blockSendAttributeUpdated(aWasBlocked, false); + + double aParameterNew = 0.0; + if(aCircleForArc->parameter(anEnd, paramTolerance, aParameterNew)) { + bool aWasBlocked = data()->blockSendAttributeUpdated(true); + if(myParamBefore <= PI / 2.0 && aParameterNew >= PI * 1.5) { + if(!boolean(REVERSED_ID())->value()) { + boolean(REVERSED_ID())->setValue(true); + } + } else if(myParamBefore >= PI * 1.5 && aParameterNew <= PI / 2.0) { + if(boolean(REVERSED_ID())->value()) { + boolean(REVERSED_ID())->setValue(false); + } + } + data()->blockSendAttributeUpdated(aWasBlocked, false); + } + myParamBefore = aParameterNew; } double aRadius = 0; diff --git a/src/SketchPlugin/SketchPlugin_MacroArc.cpp b/src/SketchPlugin/SketchPlugin_MacroArc.cpp index a5572566b..6528ca247 100644 --- a/src/SketchPlugin/SketchPlugin_MacroArc.cpp +++ b/src/SketchPlugin/SketchPlugin_MacroArc.cpp @@ -6,6 +6,7 @@ #include "SketchPlugin_MacroArc.h" +#include "SketchPlugin_Arc.h" #include "SketchPlugin_Sketch.h" #include "SketchPlugin_Tools.h" @@ -333,4 +334,61 @@ AISObjectPtr SketchPlugin_MacroArc::getAISObject(AISObjectPtr thePrevious) void SketchPlugin_MacroArc::execute() { + // Create arc feature. + FeaturePtr anArcFeature = sketch()->addFeature(SketchPlugin_Arc::ID()); + std::dynamic_pointer_cast( + anArcFeature->attribute(SketchPlugin_Arc::CENTER_ID()))->setValue(myCenter); + std::dynamic_pointer_cast( + anArcFeature->attribute(SketchPlugin_Arc::START_ID()))->setValue(myStart); + std::dynamic_pointer_cast( + anArcFeature->attribute(SketchPlugin_Arc::END_ID()))->setValue(myEnd); + anArcFeature->boolean(SketchPlugin_Arc::REVERSED_ID()) + ->setValue(boolean(REVERSED_ID())->value()); + anArcFeature->execute(); + + myCenter.reset(); + myStart.reset(); + myEnd.reset(); + + // Create constraints. + std::string anArcType = string(ARC_TYPE())->value(); + if(anArcType == ARC_TYPE_BY_CENTER_AND_POINTS()) { + SketchPlugin_Tools::createConstraint(this, + CENTER_POINT_REF_ID(), + anArcFeature->attribute(SketchPlugin_Arc::CENTER_ID()), + ObjectPtr(), + false); + SketchPlugin_Tools::createConstraint(this, + START_POINT_REF_ID(), + anArcFeature->attribute(SketchPlugin_Arc::START_ID()), + ObjectPtr(), + false); + SketchPlugin_Tools::createConstraint(this, + END_POINT_REF_ID(), + anArcFeature->attribute(SketchPlugin_Arc::END_ID()), + ObjectPtr(), + false); + } else if(anArcType == ARC_TYPE_BY_THREE_POINTS()) { + SketchPlugin_Tools::createConstraint(this, + START_POINT_REF_ID(), + anArcFeature->attribute(SketchPlugin_Arc::START_ID()), + ObjectPtr(), + false); + SketchPlugin_Tools::createConstraint(this, + END_POINT_REF_ID(), + anArcFeature->attribute(SketchPlugin_Arc::END_ID()), + ObjectPtr(), + false); + SketchPlugin_Tools::createConstraint(this, + PASSED_POINT_REF_ID(), + AttributePtr(), + anArcFeature->lastResult(), + true); + } else if(anArcType == ARC_TYPE_BY_TANGENT_EDGE()) { + SketchPlugin_Tools::createConstraint(this, + END_POINT_REF_ID(), + anArcFeature->attribute(SketchPlugin_Arc::END_ID()), + ObjectPtr(), + false); + } } -- 2.39.2