From: dbv Date: Fri, 24 Mar 2017 14:04:06 +0000 (+0300) Subject: Issue #2024: Redesign of circle and arc of circle X-Git-Tag: V_2.7.0~184 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0055749835b1aca56e3dc0ec14718c775f438b5c;p=modules%2Fshaper.git Issue #2024: Redesign of circle and arc of circle Redesigned "real" arc feature. --- 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); + } }