From 17d8a9be9ff8975e7551160a82116a65e1203128 Mon Sep 17 00:00:00 2001 From: dbv Date: Fri, 24 Mar 2017 15:36:48 +0300 Subject: [PATCH] Issue #2024: Redesign of circle and arc of circle Redesigned "real" arc feature. --- src/ModelHighAPI/ModelHighAPI_Macro.h | 45 ++ src/PartSet/PartSet_SketcherReentrantMgr.cpp | 52 +- src/PartSet/PartSet_Tools.cpp | 2 +- src/SketchAPI/CMakeLists.txt | 2 + src/SketchAPI/SketchAPI.i | 2 + src/SketchAPI/SketchAPI_Arc.cpp | 203 +---- src/SketchAPI/SketchAPI_Arc.h | 70 +- src/SketchAPI/SketchAPI_MacroArc.cpp | 190 +++++ src/SketchAPI/SketchAPI_MacroArc.h | 152 ++++ src/SketchAPI/SketchAPI_Sketch.cpp | 23 +- src/SketchAPI/SketchAPI_Sketch.h | 9 +- src/SketchAPI/SketchAPI_swig.h | 1 + src/SketchPlugin/SketchPlugin_Arc.cpp | 763 +++--------------- src/SketchPlugin/SketchPlugin_Arc.h | 115 +-- .../SketchPlugin_ConstraintSplit.cpp | 13 +- src/SketchPlugin/SketchPlugin_Fillet.cpp | 2 +- src/SketchPlugin/SketchPlugin_MacroArc.cpp | 27 +- src/SketchPlugin/SketchPlugin_MacroArc.h | 15 +- src/SketchPlugin/SketchPlugin_MacroCircle.h | 6 +- src/SketchPlugin/SketchPlugin_Trim.cpp | 9 +- src/SketchPlugin/SketchPlugin_Validators.cpp | 13 - src/SketchPlugin/plugin-Sketch.xml | 84 +- .../SketchSolver_ConstraintMirror.cpp | 4 +- 23 files changed, 669 insertions(+), 1133 deletions(-) create mode 100644 src/SketchAPI/SketchAPI_MacroArc.cpp create mode 100644 src/SketchAPI/SketchAPI_MacroArc.h diff --git a/src/ModelHighAPI/ModelHighAPI_Macro.h b/src/ModelHighAPI/ModelHighAPI_Macro.h index e37b2efbb..b04dc2676 100644 --- a/src/ModelHighAPI/ModelHighAPI_Macro.h +++ b/src/ModelHighAPI/ModelHighAPI_Macro.h @@ -380,6 +380,51 @@ END_INIT() \ public: +//-------------------------------------------------------------------------------------- +#define INTERFACE_12(KIND, \ + N_0, AN_0, T_0, C_0, \ + N_1, AN_1, T_1, C_1, \ + N_2, AN_2, T_2, C_2, \ + N_3, AN_3, T_3, C_3, \ + N_4, AN_4, T_4, C_4, \ + N_5, AN_5, T_5, C_5, \ + N_6, AN_6, T_6, C_6, \ + N_7, AN_7, T_7, C_7, \ + N_8, AN_8, T_8, C_8, \ + N_9, AN_9, T_9, C_9, \ + N_10, AN_10, T_10, C_10, \ + N_11, AN_11, T_11, C_11) \ + public: \ + INTERFACE_COMMON(KIND) \ + DEFINE_ATTRIBUTE(N_0, T_0, C_0) \ + DEFINE_ATTRIBUTE(N_1, T_1, C_1) \ + DEFINE_ATTRIBUTE(N_2, T_2, C_2) \ + DEFINE_ATTRIBUTE(N_3, T_3, C_3) \ + DEFINE_ATTRIBUTE(N_4, T_4, C_4) \ + DEFINE_ATTRIBUTE(N_5, T_5, C_5) \ + DEFINE_ATTRIBUTE(N_6, T_6, C_6) \ + DEFINE_ATTRIBUTE(N_7, T_7, C_7) \ + DEFINE_ATTRIBUTE(N_8, T_8, C_8) \ + DEFINE_ATTRIBUTE(N_9, T_9, C_9) \ + DEFINE_ATTRIBUTE(N_10, T_10, C_10) \ + DEFINE_ATTRIBUTE(N_11, T_11, C_11) \ + protected: \ + START_INIT() \ + SET_ATTRIBUTE(N_0, T_0, AN_0) \ + SET_ATTRIBUTE(N_1, T_1, AN_1) \ + SET_ATTRIBUTE(N_2, T_2, AN_2) \ + SET_ATTRIBUTE(N_3, T_3, AN_3) \ + SET_ATTRIBUTE(N_4, T_4, AN_4) \ + SET_ATTRIBUTE(N_5, T_5, AN_5) \ + SET_ATTRIBUTE(N_6, T_6, AN_6) \ + SET_ATTRIBUTE(N_7, T_7, AN_7) \ + SET_ATTRIBUTE(N_8, T_8, AN_8) \ + SET_ATTRIBUTE(N_9, T_9, AN_9) \ + SET_ATTRIBUTE(N_10, T_10, AN_10) \ + SET_ATTRIBUTE(N_11, T_11, AN_11) \ + END_INIT() \ + public: + //-------------------------------------------------------------------------------------- #define INTERFACE_14(KIND, \ N_0, AN_0, T_0, C_0, \ diff --git a/src/PartSet/PartSet_SketcherReentrantMgr.cpp b/src/PartSet/PartSet_SketcherReentrantMgr.cpp index 45547cb74..cab4e9945 100644 --- a/src/PartSet/PartSet_SketcherReentrantMgr.cpp +++ b/src/PartSet/PartSet_SketcherReentrantMgr.cpp @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include @@ -155,7 +155,7 @@ bool PartSet_SketcherReentrantMgr::processMouseMoved(ModuleBase_IViewWindow* the isLineFeature = anActiveWidget->attributeID() == anAttributeOnStart; } else if (isTangentArc(aFOperation, module()->sketchMgr()->activeSketch())) { - anAttributeOnStart = SketchPlugin_Arc::TANGENT_POINT_ID(); + anAttributeOnStart = SketchPlugin_MacroArc::TANGENT_POINT_ID(); isArcFeature = anActiveWidget->attributeID() == anAttributeOnStart; } bool aCanBeActivatedByMove = isLineFeature || isArcFeature; @@ -656,32 +656,32 @@ bool PartSet_SketcherReentrantMgr::copyReetntrantAttributes(const FeaturePtr& th //ModuleBase_Tools::flushUpdated(theNewFeature); aChanged = true; } - else if (aFeatureKind == SketchPlugin_Arc::ID()) { + else if (aFeatureKind == SketchPlugin_MacroArc::ID()) { // set arc type - std::string aTypeAttributeId = SketchPlugin_Arc::ARC_TYPE(); + std::string aTypeAttributeId = SketchPlugin_MacroArc::ARC_TYPE(); AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId); AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId); aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value()); - // if the arc is tangent, set coincidence to end point of the previous arc - std::string anArcType = aSourceFeatureTypeAttr->value(); - if (anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT()) { - // get the last point of the previuos arc feature(geom point 2d) - std::shared_ptr aSData = theSourceFeature->data(); - std::shared_ptr aSPointAttr = - std::dynamic_pointer_cast( - aSData->attribute(SketchPlugin_Arc::END_ID())); - // get point attribute on the current feature - AttributeRefAttrPtr aTangentPointAttr = theNewFeature->data()->refattr( - SketchPlugin_Arc::TANGENT_POINT_ID()); - aTangentPointAttr->setAttr(aSPointAttr); - - std::shared_ptr aNPointAttr = - std::dynamic_pointer_cast( - theNewFeature->data()->attribute(SketchPlugin_Arc::END_ID())); - aNPointAttr->setValue(aSPointAttr->x(), aSPointAttr->y()); - - } + //// if the arc is tangent, set coincidence to end point of the previous arc + //std::string anArcType = aSourceFeatureTypeAttr->value(); + //if (anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT()) { + // // get the last point of the previuos arc feature(geom point 2d) + // std::shared_ptr aSData = theSourceFeature->data(); + // std::shared_ptr aSPointAttr = + // std::dynamic_pointer_cast( + // aSData->attribute(SketchPlugin_Arc::END_ID())); + // // get point attribute on the current feature + // AttributeRefAttrPtr aTangentPointAttr = theNewFeature->data()->refattr( + // SketchPlugin_Arc::TANGENT_POINT_ID()); + // aTangentPointAttr->setAttr(aSPointAttr); + + // std::shared_ptr aNPointAttr = + // std::dynamic_pointer_cast( + // theNewFeature->data()->attribute(SketchPlugin_Arc::END_ID())); + // aNPointAttr->setValue(aSPointAttr->x(), aSPointAttr->y()); + + //} //ModuleBase_Tools::flushUpdated(theNewFeature); aChanged = true; } @@ -696,10 +696,10 @@ bool PartSet_SketcherReentrantMgr::isTangentArc(ModuleBase_Operation* theOperati (theOperation); if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) { FeaturePtr aFeature = aFOperation->feature(); - if (aFeature.get() && aFeature->getKind() == SketchPlugin_Arc::ID()) { - AttributeStringPtr aTypeAttr = aFeature->data()->string(SketchPlugin_Arc::ARC_TYPE()); + if (aFeature.get() && aFeature->getKind() == SketchPlugin_MacroArc::ID()) { + AttributeStringPtr aTypeAttr = aFeature->data()->string(SketchPlugin_MacroArc::ARC_TYPE()); std::string anArcType = aTypeAttr.get() ? aTypeAttr->value() : ""; - aTangentArc = anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT(); + aTangentArc = anArcType == SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE(); } } return aTangentArc; diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 2099f347c..37cee3d67 100755 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -383,7 +383,7 @@ ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShap // Create arc aMyFeature = theSketch->addFeature(SketchPlugin_Arc::ID()); if (theShape.Orientation() == TopAbs_REVERSED) - aMyFeature->boolean(SketchPlugin_Arc::INVERSED_ID())->setValue(true); + aMyFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->setValue(true); } else { // Create circle diff --git a/src/SketchAPI/CMakeLists.txt b/src/SketchAPI/CMakeLists.txt index 0b8b8914a..e4347d3d4 100644 --- a/src/SketchAPI/CMakeLists.txt +++ b/src/SketchAPI/CMakeLists.txt @@ -9,6 +9,7 @@ SET(PROJECT_HEADERS SketchAPI_Constraint.h SketchAPI_IntersectionPoint.h SketchAPI_Line.h + SketchAPI_MacroArc.h SketchAPI_MacroCircle.h SketchAPI_Mirror.h SketchAPI_Sketch.h @@ -26,6 +27,7 @@ SET(PROJECT_SOURCES SketchAPI_Constraint.cpp SketchAPI_IntersectionPoint.cpp SketchAPI_Line.cpp + SketchAPI_MacroArc.cpp SketchAPI_MacroCircle.cpp SketchAPI_Mirror.cpp SketchAPI_Sketch.cpp diff --git a/src/SketchAPI/SketchAPI.i b/src/SketchAPI/SketchAPI.i index c5ceee14d..3f1be9624 100644 --- a/src/SketchAPI/SketchAPI.i +++ b/src/SketchAPI/SketchAPI.i @@ -26,6 +26,7 @@ // shared pointers %shared_ptr(SketchAPI_Arc) +%shared_ptr(SketchAPI_MacroArc) %shared_ptr(SketchAPI_Circle) %shared_ptr(SketchAPI_MacroCircle) %shared_ptr(SketchAPI_Constraint) @@ -210,6 +211,7 @@ %include "SketchAPI_Circle.h" %include "SketchAPI_MacroCircle.h" %include "SketchAPI_Arc.h" +%include "SketchAPI_MacroArc.h" %include "SketchAPI_Projection.h" %include "SketchAPI_Mirror.h" %include "SketchAPI_Translation.h" diff --git a/src/SketchAPI/SketchAPI_Arc.cpp b/src/SketchAPI/SketchAPI_Arc.cpp index d281c3af3..d6a84f60f 100644 --- a/src/SketchAPI/SketchAPI_Arc.cpp +++ b/src/SketchAPI/SketchAPI_Arc.cpp @@ -53,54 +53,6 @@ SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr& theFeature } } -//================================================================================================ -SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr& theFeature, - double theStartX, double theStartY, - double theEndX, double theEndY, - double thePassedX, double thePassedY) -: SketchAPI_SketchEntity(theFeature) -{ - if (initialize()) { - setByStartEndPassed(theStartX, theStartY, theEndX, theEndY, thePassedX, thePassedY); - } -} - -//=============================================================================================== -SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr& theFeature, - const std::shared_ptr& theStart, - const std::shared_ptr& theEnd, - const std::shared_ptr& thePassed) -: SketchAPI_SketchEntity(theFeature) -{ - if (initialize()) { - setByStartEndPassed(theStart, theEnd, thePassed); - } -} - -//================================================================================================ -SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr& theFeature, - const ModelHighAPI_RefAttr& theTangentPoint, - double theEndX, double theEndY, - bool theInversed) -: SketchAPI_SketchEntity(theFeature) -{ - if (initialize()) { - setByTangent(theTangentPoint, theEndX, theEndY, theInversed); - } -} - -//================================================================================================ -SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr& theFeature, - const ModelHighAPI_RefAttr& theTangentPoint, - const std::shared_ptr& theEnd, - bool theInversed) -: SketchAPI_SketchEntity(theFeature) -{ - if (initialize()) { - setByTangent(theTangentPoint, theEnd, theInversed); - } -} - //================================================================================================ SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr& theFeature, const ModelHighAPI_Selection& theExternal) @@ -133,11 +85,10 @@ void SketchAPI_Arc::setByCenterStartEnd(double theCenterX, double theCenterY, double theEndX, double theEndY, bool theInversed) { - fillAttribute(SketchPlugin_Arc::ARC_TYPE_CENTER_START_END(), myarcType); fillAttribute(center(), theCenterX, theCenterY); fillAttribute(startPoint(), theStartX, theStartY); fillAttribute(endPoint(), theEndX, theEndY); - fillAttribute(theInversed, myinversed); + fillAttribute(theInversed, myreversed); execute(); } @@ -148,63 +99,10 @@ void SketchAPI_Arc::setByCenterStartEnd(const std::shared_ptr& th const std::shared_ptr& theEnd, bool theInversed) { - fillAttribute(SketchPlugin_Arc::ARC_TYPE_CENTER_START_END(), myarcType); fillAttribute(theCenter, mycenter); fillAttribute(theStart, mystartPoint); fillAttribute(theEnd, myendPoint); - fillAttribute(theInversed, myinversed); - - execute(); -} - -//================================================================================================ -void SketchAPI_Arc::setByStartEndPassed(double theStartX, double theStartY, - double theEndX, double theEndY, - double thePassedX, double thePassedY) -{ - fillAttribute(SketchPlugin_Arc::ARC_TYPE_THREE_POINTS(), myarcType); - fillAttribute(startPoint(), theStartX, theStartY); - fillAttribute(endPoint(), theEndX, theEndY); - fillAttribute(passedPoint(), thePassedX, thePassedY); - - execute(); -} - -//================================================================================================ -void SketchAPI_Arc::setByStartEndPassed(const std::shared_ptr& theStart, - const std::shared_ptr& theEnd, - const std::shared_ptr& thePassed) -{ - fillAttribute(SketchPlugin_Arc::ARC_TYPE_THREE_POINTS(), myarcType); - fillAttribute(theStart, mystartPoint); - fillAttribute(theEnd, myendPoint); - fillAttribute(thePassed, mypassedPoint); - - execute(); -} - -//================================================================================================ -void SketchAPI_Arc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint, - double theEndX, double theEndY, - bool theInversed) -{ - fillAttribute(SketchPlugin_Arc::ARC_TYPE_TANGENT(), myarcType); - fillAttribute(theTangentPoint, mytangentPoint); - fillAttribute(endPoint(), theEndX, theEndY); - fillAttribute(theInversed, myinversed); - - execute(); -} - -//================================================================================================ -void SketchAPI_Arc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint, - const std::shared_ptr& theEnd, - bool theInversed) -{ - fillAttribute(SketchPlugin_Arc::ARC_TYPE_TANGENT(), myarcType); - fillAttribute(theTangentPoint, mytangentPoint); - fillAttribute(theEnd, myendPoint); - fillAttribute(theInversed, myinversed); + fillAttribute(theInversed, myreversed); execute(); } @@ -225,22 +123,6 @@ void SketchAPI_Arc::setByExternalName(const std::string & theExternalName) execute(); } -//=============================================================================================== -void SketchAPI_Arc::setRadius(double theRadius) -{ - fillAttribute(ModelHighAPI_Double(theRadius), myradius); - - execute(); -} - -//================================================================================================ -void SketchAPI_Arc::setAngle(double theAngle) -{ - fillAttribute(ModelHighAPI_Double(theAngle), myangle); - - execute(); -} - //================================================================================================ void SketchAPI_Arc::dump(ModelHighAPI_Dumper& theDumper) const { @@ -255,85 +137,10 @@ void SketchAPI_Arc::dump(ModelHighAPI_Dumper& theDumper) const // arc is external theDumper << aBase << " = " << aSketchName << ".addArc(" << anExternal << ")" << std::endl; } else { - AttributeStringPtr aType = arcType(); - if (aType->value() == SketchPlugin_Arc::ARC_TYPE_CENTER_START_END()) { - // arc given by center and start, end points - theDumper << aBase << " = " << aSketchName << ".addArc(" << center() << ", " - << startPoint() << ", " << endPoint() << ", " << inversed() << ")" << std::endl; - } else if (aType->value() == SketchPlugin_Arc::ARC_TYPE_THREE_POINTS()) { - // arc given by three points - theDumper << aBase << " = " << aSketchName << ".addArc(" << startPoint() << ", " - << endPoint() << ", " << passedPoint() << ")" << std::endl; - } else { - // do not dump coincidence and tangency constraint built by tangent arc - std::list aConstraintsToSkip = tangentArcConstraints(aBase); - std::list::iterator anIt = aConstraintsToSkip.begin(); - for (; anIt != aConstraintsToSkip.end(); ++anIt) - theDumper.doNotDumpFeature(*anIt); - - // tangent arc - AttributeRefAttrPtr aTangentPoint = tangentPoint(); - theDumper << aBase << " = " << aSketchName << ".addArc(" - << aTangentPoint << ", " << endPoint() << ", " << inversed() << ")" << std::endl; - } + // arc given by center and start, end points + theDumper << aBase << " = " << aSketchName << ".addArc(" << center() << ", " + << startPoint() << ", " << endPoint() << ", " << reversed() << ")" << std::endl; } // dump "auxiliary" flag if necessary SketchAPI_SketchEntity::dump(theDumper); } - - -// ==================== Auxiliary functions =============================== -std::list tangentArcConstraints(const FeaturePtr& theArc) -{ - std::list aConstraints; - - std::set aCoincidences; - std::set aTangencies; - - const std::set& aBaseRefs = theArc->data()->refsToMe(); - std::set::const_iterator anIt = aBaseRefs.begin(); - for (; anIt != aBaseRefs.end(); ++anIt) { - FeaturePtr anOwner = ModelAPI_Feature::feature((*anIt)->owner()); - if (anOwner->getKind() == SketchPlugin_ConstraintCoincidence::ID()) - aCoincidences.insert(anOwner); - } - const std::set& aBaseResultRefs = theArc->lastResult()->data()->refsToMe(); - for (anIt = aBaseResultRefs.begin(); anIt != aBaseResultRefs.end(); ++anIt) { - FeaturePtr anOwner = ModelAPI_Feature::feature((*anIt)->owner()); - if (anOwner->getKind() == SketchPlugin_ConstraintTangent::ID()) - aTangencies.insert(anOwner); - } - - AttributePtr aTangentPoint = theArc->refattr(SketchPlugin_Arc::TANGENT_POINT_ID())->attr(); - if (aTangentPoint) { - FeaturePtr aTangentFeature = ModelAPI_Feature::feature(aTangentPoint->owner()); - - const std::set& aTgRefs = aTangentFeature->data()->refsToMe(); - for (anIt = aTgRefs.begin(); anIt != aTgRefs.end(); ++anIt) { - FeaturePtr anOwner = ModelAPI_Feature::feature((*anIt)->owner()); - if (aCoincidences.find(anOwner) != aCoincidences.end()) { - // check the coincidence is correct - AttributePtr aConstrained1 = anOwner->refattr(SketchPlugin_Constraint::ENTITY_A())->attr(); - AttributePtr aConstrained2 = anOwner->refattr(SketchPlugin_Constraint::ENTITY_B())->attr(); - AttributePtr anArcStartPoint = theArc->attribute(SketchPlugin_Arc::START_ID()); - if ((aConstrained1 == anArcStartPoint && aConstrained2 == aTangentPoint) || - (aConstrained1 == aTangentPoint && aConstrained2 == anArcStartPoint)) { - aConstraints.push_back(anOwner); - break; // search first applicable coincidence only - } - } - } - - const std::set& aTgResultRefs = - aTangentFeature->lastResult()->data()->refsToMe(); - for (anIt = aTgResultRefs.begin(); anIt != aTgResultRefs.end(); ++anIt) { - FeaturePtr anOwner = ModelAPI_Feature::feature((*anIt)->owner()); - if (aTangencies.find(anOwner) != aTangencies.end()) { - aConstraints.push_back(anOwner); - break; // search first tangency only - } - } - } - - return aConstraints; -} diff --git a/src/SketchAPI/SketchAPI_Arc.h b/src/SketchAPI/SketchAPI_Arc.h index c1d302377..b0123d4ae 100644 --- a/src/SketchAPI/SketchAPI_Arc.h +++ b/src/SketchAPI/SketchAPI_Arc.h @@ -43,34 +43,6 @@ public: const std::shared_ptr& theEnd, bool theInversed); - /// Constructor with values. - SKETCHAPI_EXPORT - SketchAPI_Arc(const std::shared_ptr& theFeature, - double theStartX, double theStartY, - double theEndX, double theEndY, - double thePassedX, double thePassedY); - - /// Constructor with values. - SKETCHAPI_EXPORT - SketchAPI_Arc(const std::shared_ptr& theFeature, - const std::shared_ptr& theStart, - const std::shared_ptr& theEnd, - const std::shared_ptr& thePassed); - - /// Constructor with values. - SKETCHAPI_EXPORT - SketchAPI_Arc(const std::shared_ptr& theFeature, - const ModelHighAPI_RefAttr& theTangentPoint, - double theEndX, double theEndY, - bool theInversed); - - /// Constructor with values. - SKETCHAPI_EXPORT - SketchAPI_Arc(const std::shared_ptr& theFeature, - const ModelHighAPI_RefAttr& theTangentPoint, - const std::shared_ptr& theEnd, - bool theInversed); - /// Constructor with values. SKETCHAPI_EXPORT SketchAPI_Arc(const std::shared_ptr& theFeature, @@ -85,21 +57,15 @@ public: SKETCHAPI_EXPORT virtual ~SketchAPI_Arc(); - INTERFACE_10(SketchPlugin_Arc::ID(), - arcType, SketchPlugin_Arc::ARC_TYPE(), - ModelAPI_AttributeString, /** Arc type */, + INTERFACE_7(SketchPlugin_Arc::ID(), center, SketchPlugin_Arc::CENTER_ID(), GeomDataAPI_Point2D, /** Center point */, startPoint, SketchPlugin_Arc::START_ID(), GeomDataAPI_Point2D, /** Start point */, endPoint, SketchPlugin_Arc::END_ID(), GeomDataAPI_Point2D, /** End point */, - inversed, SketchPlugin_Arc::INVERSED_ID(), + reversed, SketchPlugin_Arc::REVERSED_ID(), ModelAPI_AttributeBoolean, /** Inversed flag */, - passedPoint, SketchPlugin_Arc::PASSED_POINT_ID(), - GeomDataAPI_Point2D, /** Passed point */, - tangentPoint, SketchPlugin_Arc::TANGENT_POINT_ID(), - ModelAPI_AttributeRefAttr, /** Tangent point */, radius, SketchPlugin_Arc::RADIUS_ID(), ModelAPI_AttributeDouble, /** Radius */, angle, SketchPlugin_Arc::ANGLE_ID(), @@ -121,30 +87,6 @@ public: const std::shared_ptr& theEnd, bool theInversed); - /// Set by start, end and passed points. - SKETCHAPI_EXPORT - void setByStartEndPassed(double theStartX, double theStartY, - double theEndX, double theEndY, - double thePassedX, double thePassedY); - - /// Set by start, end and passed points. - SKETCHAPI_EXPORT - void setByStartEndPassed(const std::shared_ptr& theStart, - const std::shared_ptr& theEnd, - const std::shared_ptr& thePassed); - - /// Set by tangent and end point. - SKETCHAPI_EXPORT - void setByTangent(const ModelHighAPI_RefAttr& theTangentPoint, - double theEndX, double theEndY, - bool theInversed); - - /// Set by tangent and end point. - SKETCHAPI_EXPORT - void setByTangent(const ModelHighAPI_RefAttr& theTangentPoint, - const std::shared_ptr& theEnd, - bool theInversed); - /// Set by external. SKETCHAPI_EXPORT void setByExternal(const ModelHighAPI_Selection& theExternal); @@ -153,14 +95,6 @@ public: SKETCHAPI_EXPORT void setByExternalName(const std::string& theExternalName); - /// Set radius. - SKETCHAPI_EXPORT - void setRadius(double theRadius); - - /// Set angle. - SKETCHAPI_EXPORT - void setAngle(double theAngle); - /// Dump wrapped feature SKETCHAPI_EXPORT virtual void dump(ModelHighAPI_Dumper& theDumper) const; diff --git a/src/SketchAPI/SketchAPI_MacroArc.cpp b/src/SketchAPI/SketchAPI_MacroArc.cpp new file mode 100644 index 000000000..2fa73d5a3 --- /dev/null +++ b/src/SketchAPI/SketchAPI_MacroArc.cpp @@ -0,0 +1,190 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SketchAPI_MacroArc.cpp +// Created: 09 June 2016 +// Author: Dmitry Bobylev + +#include "SketchAPI_MacroArc.h" + +#include + +#include +#include +#include +#include + +#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) +{ + initialize(); +} + +//================================================================================================ +SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr& theFeature, + double theCenterX, double theCenterY, + double theStartX, double theStartY, + double theEndX, double theEndY, + bool theInversed) +: SketchAPI_SketchEntity(theFeature) +{ + if(initialize()) { + setByCenterStartEnd(theCenterX, theCenterY, theStartX, + theStartY, theEndX, theEndY, theInversed); + } +} + +//================================================================================================ +SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr& theFeature, + const std::shared_ptr& theCenter, + const std::shared_ptr& theStart, + const std::shared_ptr& theEnd, + bool theInversed) +: SketchAPI_SketchEntity(theFeature) +{ + if(initialize()) { + setByCenterStartEnd(theCenter, theStart, theEnd, theInversed); + } +} + +//================================================================================================ +SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr& theFeature, + double theStartX, double theStartY, + double theEndX, double theEndY, + double thePassedX, double thePassedY) +: SketchAPI_SketchEntity(theFeature) +{ + if (initialize()) { + setByStartEndPassed(theStartX, theStartY, theEndX, theEndY, thePassedX, thePassedY); + } +} + +//=============================================================================================== +SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr& theFeature, + const std::shared_ptr& theStart, + const std::shared_ptr& theEnd, + const std::shared_ptr& thePassed) +: SketchAPI_SketchEntity(theFeature) +{ + if (initialize()) { + setByStartEndPassed(theStart, theEnd, thePassed); + } +} + +//================================================================================================ +SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr& theFeature, + const ModelHighAPI_RefAttr& theTangentPoint, + double theEndX, double theEndY, + bool theInversed) +: SketchAPI_SketchEntity(theFeature) +{ + if (initialize()) { + setByTangent(theTangentPoint, theEndX, theEndY, theInversed); + } +} + +//================================================================================================ +SketchAPI_MacroArc::SketchAPI_MacroArc(const std::shared_ptr& theFeature, + const ModelHighAPI_RefAttr& theTangentPoint, + const std::shared_ptr& theEnd, + bool theInversed) +: SketchAPI_SketchEntity(theFeature) +{ + if (initialize()) { + setByTangent(theTangentPoint, theEnd, theInversed); + } +} + +//================================================================================================ +SketchAPI_MacroArc::~SketchAPI_MacroArc() +{ + +} + +//================================================================================================ +void SketchAPI_MacroArc::setByCenterStartEnd(double theCenterX, double theCenterY, + double theStartX, double theStartY, + double theEndX, double theEndY, + bool theInversed) +{ + fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_CENTER_AND_POINTS(), myarcType); + fillAttribute(center(), theCenterX, theCenterY); + fillAttribute(startPoint1(), theStartX, theStartY); + fillAttribute(endPoint1(), theEndX, theEndY); + fillAttribute(theInversed, myreversed); + + execute(); +} + +//================================================================================================ +void SketchAPI_MacroArc::setByCenterStartEnd(const std::shared_ptr& theCenter, + const std::shared_ptr& theStart, + const std::shared_ptr& theEnd, + bool theInversed) +{ + fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_CENTER_AND_POINTS(), myarcType); + fillAttribute(theCenter, mycenter); + fillAttribute(theStart, mystartPoint1); + fillAttribute(theEnd, myendPoint1); + fillAttribute(theInversed, myreversed); + + execute(); +} + +//================================================================================================ +void SketchAPI_MacroArc::setByStartEndPassed(double theStartX, double theStartY, + double theEndX, double theEndY, + double thePassedX, double thePassedY) +{ + fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_THREE_POINTS(), myarcType); + fillAttribute(startPoint2(), theStartX, theStartY); + fillAttribute(endPoint2(), theEndX, theEndY); + fillAttribute(passedPoint(), thePassedX, thePassedY); + + execute(); +} + +//================================================================================================ +void SketchAPI_MacroArc::setByStartEndPassed(const std::shared_ptr& theStart, + const std::shared_ptr& theEnd, + const std::shared_ptr& thePassed) +{ + fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_THREE_POINTS(), myarcType); + fillAttribute(theStart, mystartPoint2); + fillAttribute(theEnd, myendPoint2); + fillAttribute(thePassed, mypassedPoint); + + execute(); +} + +//================================================================================================ +void SketchAPI_MacroArc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint, + double theEndX, double theEndY, + bool theInversed) +{ + fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE(), myarcType); + fillAttribute(theTangentPoint, mytangentPoint); + fillAttribute(endPoint3(), theEndX, theEndY); + fillAttribute(theInversed, myreversed); + + execute(); +} + +//================================================================================================ +void SketchAPI_MacroArc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint, + const std::shared_ptr& theEnd, + bool theInversed) +{ + fillAttribute(SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE(), myarcType); + fillAttribute(theTangentPoint, mytangentPoint); + fillAttribute(theEnd, myendPoint3); + fillAttribute(theInversed, myreversed); + + execute(); +} diff --git a/src/SketchAPI/SketchAPI_MacroArc.h b/src/SketchAPI/SketchAPI_MacroArc.h new file mode 100644 index 000000000..c24e24750 --- /dev/null +++ b/src/SketchAPI/SketchAPI_MacroArc.h @@ -0,0 +1,152 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: SketchAPI_MacroArc.h +// Created: 09 June 2016 +// Author: Dmitry Bobylev + +#ifndef SketchAPI_MacroArc_H_ +#define SketchAPI_MacroArc_H_ + +#include "SketchAPI.h" +#include "SketchAPI_SketchEntity.h" + +#include + +#include + +class ModelHighAPI_RefAttr; +class ModelHighAPI_Selection; + +/// \class SketchAPI_MacroArc +/// \ingroup CPPHighAPI +/// \brief Interface for Arc feature. +class SketchAPI_MacroArc: public SketchAPI_SketchEntity +{ +public: + /// Constructor without values. + SKETCHAPI_EXPORT + explicit SketchAPI_MacroArc(const std::shared_ptr& theFeature); + + /// Constructor with values. + SKETCHAPI_EXPORT + SketchAPI_MacroArc(const std::shared_ptr& theFeature, + double theCenterX, double theCenterY, + double theStartX, double theStartY, + double theEndX, double theEndY, + bool theInversed); + + /// Constructor with values. + SKETCHAPI_EXPORT + SketchAPI_MacroArc(const std::shared_ptr& theFeature, + const std::shared_ptr& theCenter, + const std::shared_ptr& theStart, + const std::shared_ptr& theEnd, + bool theInversed); + + /// Constructor with values. + SKETCHAPI_EXPORT + SketchAPI_MacroArc(const std::shared_ptr& theFeature, + double theStartX, double theStartY, + double theEndX, double theEndY, + double thePassedX, double thePassedY); + + /// Constructor with values. + SKETCHAPI_EXPORT + SketchAPI_MacroArc(const std::shared_ptr& theFeature, + const std::shared_ptr& theStart, + const std::shared_ptr& theEnd, + const std::shared_ptr& thePassed); + + /// Constructor with values. + SKETCHAPI_EXPORT + SketchAPI_MacroArc(const std::shared_ptr& theFeature, + const ModelHighAPI_RefAttr& theTangentPoint, + double theEndX, double theEndY, + bool theInversed); + + /// Constructor with values. + SKETCHAPI_EXPORT + SketchAPI_MacroArc(const std::shared_ptr& theFeature, + const ModelHighAPI_RefAttr& theTangentPoint, + const std::shared_ptr& theEnd, + bool theInversed); + + /// Destructor. + SKETCHAPI_EXPORT + virtual ~SketchAPI_MacroArc(); + + void test() { + SketchPlugin_MacroArc::ID(); + } + + INTERFACE_12(SketchPlugin_MacroArc::ID(), + arcType, SketchPlugin_MacroArc::ARC_TYPE(), + ModelAPI_AttributeString, /** Arc type */, + center, SketchPlugin_MacroArc::CENTER_POINT_ID(), + GeomDataAPI_Point2D, /** Center point */, + startPoint1, SketchPlugin_MacroArc::START_POINT_1_ID(), + GeomDataAPI_Point2D, /** Start point */, + endPoint1, SketchPlugin_MacroArc::END_POINT_1_ID(), + GeomDataAPI_Point2D, /** End point */, + startPoint2, SketchPlugin_MacroArc::START_POINT_2_ID(), + GeomDataAPI_Point2D, /** Start point */, + endPoint2, SketchPlugin_MacroArc::END_POINT_2_ID(), + GeomDataAPI_Point2D, /** End point */, + passedPoint, SketchPlugin_MacroArc::PASSED_POINT_ID(), + GeomDataAPI_Point2D, /** Passed point */, + tangentPoint, SketchPlugin_MacroArc::TANGENT_POINT_ID(), + ModelAPI_AttributeRefAttr, /** Tangent point */, + endPoint3, SketchPlugin_MacroArc::END_POINT_3_ID(), + GeomDataAPI_Point2D, /** End point */, + reversed, SketchPlugin_MacroArc::REVERSED_ID(), + ModelAPI_AttributeBoolean, /** Reversed flag */, + radius, SketchPlugin_MacroArc::RADIUS_ID(), + ModelAPI_AttributeDouble, /** Radius */, + angle, SketchPlugin_MacroArc::ANGLE_ID(), + ModelAPI_AttributeDouble, /** Angle */) + +private: + + /// Set by center and start, end point. + SKETCHAPI_EXPORT + void setByCenterStartEnd(double theCenterX, double theCenterY, + double theStartX, double theStartY, + double theEndX, double theEndY, + bool theInversed); + + /// Set by center and start, end point. + SKETCHAPI_EXPORT + void setByCenterStartEnd(const std::shared_ptr& theCenter, + const std::shared_ptr& theStart, + const std::shared_ptr& theEnd, + bool theInversed); + + /// Set by start, end and passed points. + SKETCHAPI_EXPORT + void setByStartEndPassed(double theStartX, double theStartY, + double theEndX, double theEndY, + double thePassedX, double thePassedY); + + /// Set by start, end and passed points. + SKETCHAPI_EXPORT + void setByStartEndPassed(const std::shared_ptr& theStart, + const std::shared_ptr& theEnd, + const std::shared_ptr& thePassed); + + /// Set by tangent and end point. + SKETCHAPI_EXPORT + void setByTangent(const ModelHighAPI_RefAttr& theTangentPoint, + double theEndX, double theEndY, + bool theInversed); + + /// Set by tangent and end point. + SKETCHAPI_EXPORT + void setByTangent(const ModelHighAPI_RefAttr& theTangentPoint, + const std::shared_ptr& theEnd, + bool theInversed); +}; + +/// Pointer on Arc object. +typedef std::shared_ptr MacroArcPtr; + +#endif // SketchAPI_MacroArc_H_ diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp index e126efdfa..edfef921b 100644 --- a/src/SketchAPI/SketchAPI_Sketch.cpp +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -39,6 +39,7 @@ #include //-------------------------------------------------------------------------------------- #include "SketchAPI_Arc.h" +#include "SketchAPI_MacroArc.h" #include "SketchAPI_Circle.h" #include "SketchAPI_IntersectionPoint.h" #include "SketchAPI_Line.h" @@ -378,46 +379,46 @@ std::shared_ptr SketchAPI_Sketch::addArc( return ArcPtr(new SketchAPI_Arc(aFeature, theCenter, theStart, theEnd, theInversed)); } -std::shared_ptr SketchAPI_Sketch::addArc(double theStartX, double theStartY, +std::shared_ptr SketchAPI_Sketch::addArc(double theStartX, double theStartY, double theEndX, double theEndY, double thePassedX, double thePassedY) { std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID()); - return ArcPtr(new SketchAPI_Arc(aFeature, - theStartX, theStartY, - theEndX, theEndY, - thePassedX, thePassedY)); + return MacroArcPtr(new SketchAPI_MacroArc(aFeature, + theStartX, theStartY, + theEndX, theEndY, + thePassedX, thePassedY)); } -std::shared_ptr SketchAPI_Sketch::addArc( +std::shared_ptr SketchAPI_Sketch::addArc( const std::shared_ptr& theStart, const std::shared_ptr& theEnd, const std::shared_ptr& thePassed) { std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID()); - return ArcPtr(new SketchAPI_Arc(aFeature, theStart, theEnd, thePassed)); + return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theStart, theEnd, thePassed)); } -std::shared_ptr SketchAPI_Sketch::addArc( +std::shared_ptr SketchAPI_Sketch::addArc( const ModelHighAPI_RefAttr& theTangentPoint, double theEndX, double theEndY, bool theInversed) { std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID()); - return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEndX, theEndY, theInversed)); + return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theTangentPoint, theEndX, theEndY, theInversed)); } -std::shared_ptr SketchAPI_Sketch::addArc( +std::shared_ptr SketchAPI_Sketch::addArc( const ModelHighAPI_RefAttr& theTangentPoint, const std::shared_ptr& theEnd, bool theInversed) { std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID()); - return ArcPtr(new SketchAPI_Arc(aFeature, theTangentPoint, theEnd, theInversed)); + return MacroArcPtr(new SketchAPI_MacroArc(aFeature, theTangentPoint, theEnd, theInversed)); } std::shared_ptr SketchAPI_Sketch::addArc(const ModelHighAPI_Selection & theExternal) diff --git a/src/SketchAPI/SketchAPI_Sketch.h b/src/SketchAPI/SketchAPI_Sketch.h index 7e7082c14..843630f5b 100644 --- a/src/SketchAPI/SketchAPI_Sketch.h +++ b/src/SketchAPI/SketchAPI_Sketch.h @@ -27,6 +27,7 @@ class ModelHighAPI_RefAttr; class ModelHighAPI_Reference; class ModelHighAPI_Selection; class SketchAPI_Arc; +class SketchAPI_MacroArc; class SketchAPI_Circle; class SketchAPI_MacroCircle; class SketchAPI_IntersectionPoint; @@ -200,28 +201,28 @@ public: /// Add arc SKETCHAPI_EXPORT - std::shared_ptr addArc( + std::shared_ptr addArc( double theStartX, double theStartY, double theEndX, double theEndY, double thePassedX, double thePassedY); /// Add arc SKETCHAPI_EXPORT - std::shared_ptr addArc( + std::shared_ptr addArc( const std::shared_ptr& theStart, const std::shared_ptr& theEnd, const std::shared_ptr& thePassed); /// Add arc SKETCHAPI_EXPORT - std::shared_ptr addArc( + std::shared_ptr addArc( const ModelHighAPI_RefAttr& theTangentPoint, double theEndX, double theEndY, bool theInversed); /// Add arc SKETCHAPI_EXPORT - std::shared_ptr addArc( + std::shared_ptr addArc( const ModelHighAPI_RefAttr& theTangentPoint, const std::shared_ptr& theEnd, bool theInversed); diff --git a/src/SketchAPI/SketchAPI_swig.h b/src/SketchAPI/SketchAPI_swig.h index 0bc5da676..264a26bcb 100644 --- a/src/SketchAPI/SketchAPI_swig.h +++ b/src/SketchAPI/SketchAPI_swig.h @@ -11,6 +11,7 @@ #include "SketchAPI.h" #include "SketchAPI_Arc.h" + #include "SketchAPI_MacroArc.h" #include "SketchAPI_Circle.h" #include "SketchAPI_MacroCircle.h" #include "SketchAPI_Constraint.h" diff --git a/src/SketchPlugin/SketchPlugin_Arc.cpp b/src/SketchPlugin/SketchPlugin_Arc.cpp index 3319be80e..e752c7be1 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.cpp +++ b/src/SketchPlugin/SketchPlugin_Arc.cpp @@ -43,303 +43,105 @@ const double tolerance = 1e-7; const double paramTolerance = 1.e-4; const double PI = 3.141592653589793238463; -namespace { - static const std::string& POINT_ID(int theIndex) - { - switch (theIndex) { - case 1: return SketchPlugin_Arc::START_ID(); - case 2: return SketchPlugin_Arc::END_ID(); - case 3: return SketchPlugin_Arc::PASSED_POINT_ID(); - } - - static const std::string DUMMY; - return DUMMY; - } -} - - SketchPlugin_Arc::SketchPlugin_Arc() - : SketchPlugin_SketchEntity() +: SketchPlugin_SketchEntity() { - myStartUpdate = false; - myEndUpdate = false; - // default values - myXEndBefore = 0; - myYEndBefore = 0; - - myParamBefore = PI * 2.0; + myParamBefore = 0.0; } void SketchPlugin_Arc::initDerivedClassAttributes() { data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::typeId()); data()->addAttribute(START_ID(), GeomDataAPI_Point2D::typeId()); - std::shared_ptr anEndAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(data()->addAttribute(END_ID(), GeomDataAPI_Point2D::typeId())); + data()->addAttribute(END_ID(), GeomDataAPI_Point2D::typeId()); + data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID()); - AttributeBooleanPtr isInversed = std::dynamic_pointer_cast( - data()->addAttribute(INVERSED_ID(), ModelAPI_AttributeBoolean::typeId())); - - // get the initial values - if (anEndAttr->isInitialized()) { - myXEndBefore = anEndAttr->x(); - myYEndBefore = anEndAttr->y(); - } - - AttributeStringPtr anArcType = std::dynamic_pointer_cast( - data()->addAttribute(ARC_TYPE(), ModelAPI_AttributeString::typeId())); + AttributeBooleanPtr isReversed = std::dynamic_pointer_cast( + data()->addAttribute(REVERSED_ID(), ModelAPI_AttributeBoolean::typeId())); - data()->addAttribute(PASSED_POINT_ID(), GeomDataAPI_Point2D::typeId()); - data()->addAttribute(TANGENT_POINT_ID(), ModelAPI_AttributeRefAttr::typeId()); data()->addAttribute(RADIUS_ID(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(ANGLE_ID(), ModelAPI_AttributeDouble::typeId()); // set after all to avoid in attributeChanged reference to not existing attributes - if (!isInversed->isInitialized()) - isInversed->setValue(false); - anArcType->setValue(ARC_TYPE_CENTER_START_END()); - - //data()->addAttribute(CENTER_REF_ID(), ModelAPI_AttributeRefAttr::typeId()); - //ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CENTER_REF_ID()); + if (!isReversed->isInitialized()) { + isReversed->setValue(false); + } } void SketchPlugin_Arc::execute() { SketchPlugin_Sketch* aSketch = sketch(); - // result for the arc is set only when all obligatory attributes are initialized, - // otherwise AIS object is used to visualize the arc's preview - if (aSketch && isFeatureValid()) { - bool hasResult = lastResult().get() != NULL; - - // compute a circle point in 3D view - std::shared_ptr aCenterAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(data()->attribute(CENTER_ID())); - // compute the arc start point - std::shared_ptr aStartAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(data()->attribute(START_ID())); - - std::shared_ptr aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y())); - // make a visible point - std::shared_ptr aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter); - std::shared_ptr aConstr1 = document()->createConstruction( - data(), 0); - aConstr1->setShape(aCenterPointShape); - aConstr1->setIsInHistory(false); - setResult(aConstr1, 0); - - // make a visible circle - std::shared_ptr aNDir = std::dynamic_pointer_cast( - aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); - std::shared_ptr aNormal = aNDir->dir(); - std::shared_ptr aStartPoint(aSketch->to3D(aStartAttr->x(), aStartAttr->y())); - - // compute and change the arc end point - std::shared_ptr anEndAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(data()->attribute(END_ID())); - std::shared_ptr aCircleForArc( - new GeomAPI_Circ2d(aCenterAttr->pnt(), aStartAttr->pnt())); - std::shared_ptr aProjection = aCircleForArc->project(anEndAttr->pnt()); - if (aProjection && anEndAttr->pnt()->distance(aProjection) > tolerance) - anEndAttr->setValue(aProjection); - std::shared_ptr aEndPoint(aSketch->to3D(anEndAttr->x(), anEndAttr->y())); - AttributeBooleanPtr isInversed = - std::dynamic_pointer_cast(attribute(INVERSED_ID())); - - // compute end parameter - aCircleForArc->parameter(anEndAttr->pnt(), paramTolerance, myParamBefore); - - std::shared_ptr aCircleShape; - if(!isInversed->value()) { - aCircleShape = - GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aStartPoint, aEndPoint, aNormal); - } else { - aCircleShape = - GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aEndPoint, aStartPoint, aNormal); - } - - if (aCircleShape) { - std::shared_ptr aConstr2 = document()->createConstruction( - data(), 1); - aConstr2->setShape(aCircleShape); - aConstr2->setIsInHistory(false); - setResult(aConstr2, 1); - } - - if (!hasResult && string(ARC_TYPE())->value() == ARC_TYPE_TANGENT()) { - // constraints for tangent arc have not been prepared yet, do them - tangencyArcConstraints(); - } + if(!aSketch) { + return; } -} -AISObjectPtr SketchPlugin_Arc::getAISObject(AISObjectPtr thePrevious) -{ - SketchPlugin_Sketch* aSketch = sketch(); - if (aSketch) { - // if the feature is valid, the execute() method should be performed, AIS object is empty - if (!isFeatureValid()) { - // compute a circle point in 3D view - std::shared_ptr aCenterAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(data()->attribute(CENTER_ID())); - - std::list > aShapes; - if (aCenterAttr->isInitialized()) { - std::shared_ptr aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y())); - - std::shared_ptr aStartAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::START_ID())); - std::shared_ptr aEndAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::END_ID())); - AttributeStringPtr aTypeAttr = std::dynamic_pointer_cast( - data()->attribute(ARC_TYPE())); - - if (aStartAttr->isInitialized()) { - // make a visible circle - std::shared_ptr aNDir = std::dynamic_pointer_cast( - aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); - bool aHasPlane = aNDir && !(aNDir->x() == 0 && aNDir->y() == 0 && aNDir->z() == 0); - if (aHasPlane) { - std::shared_ptr aNormal = aNDir->dir(); - std::shared_ptr - aStartPoint(aSketch->to3D(aStartAttr->x(), aStartAttr->y())); - std::shared_ptr aEndPoint = aStartPoint; - if (aTypeAttr && aTypeAttr->isInitialized() && - aTypeAttr->value() == ARC_TYPE_THREE_POINTS()) { - if (aEndAttr->isInitialized() && // - aEndAttr->pnt()->distance(aStartAttr->pnt()) > tolerance) { - aEndPoint = aSketch->to3D(aEndAttr->x(), aEndAttr->y()); - std::shared_ptr aPassedAttr = - std::dynamic_pointer_cast( - data()->attribute(PASSED_POINT_ID())); - if (!aPassedAttr->isInitialized()) { - // calculate the appropriate center for the presentation - // check that center is bad for the current start and end and must be recomputed - std::shared_ptr aCircleForArc(new GeomAPI_Circ2d( - aCenterAttr->pnt(), aStartAttr->pnt())); - std::shared_ptr aProjection = - aCircleForArc->project(aEndAttr->pnt()); - if (!aProjection.get() || aEndAttr->pnt()->distance(aProjection) > tolerance) { - std::shared_ptr aDir = - aEndAttr->pnt()->xy()->decreased(aStartAttr->pnt()->xy())->multiplied(0.5); - double x = aDir->x(); - double y = aDir->y(); - aDir->setX(x - y); - aDir->setY(y + x); - std::shared_ptr aCenterXY = aStartAttr->pnt()->xy()->added(aDir); - aCenter = aSketch->to3D(aCenterXY->x(), aCenterXY->y()); - } - } - } else { // issue #1695: don't display circle if initialized only start point - return AISObjectPtr(); - } - } - AttributeBooleanPtr isInversed = - std::dynamic_pointer_cast(attribute(INVERSED_ID())); - - std::shared_ptr aCircleShape = - (isInversed->isInitialized() && isInversed->value()) ? - GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aEndPoint, aStartPoint, aNormal) : - GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aStartPoint, aEndPoint, aNormal); - - if (aCircleShape) - aShapes.push_back(aCircleShape); - } - } - // make a visible point - std::shared_ptr aCenterPointShape = - GeomAlgoAPI_PointBuilder::vertex(aCenter); - aShapes.push_back(aCenterPointShape); - } - if (!aShapes.empty()) { - std::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes); - AISObjectPtr anAIS = thePrevious; - if (!anAIS) - anAIS = AISObjectPtr(new GeomAPI_AISObject); - anAIS->createShape(aCompound); - double aDeflection = Config_PropManager::real("Visualization", "construction_deflection"); - anAIS->setDeflection(aDeflection); - anAIS->setWidth(3); - return anAIS; - } - } + std::shared_ptr aCenterAttr = + std::dynamic_pointer_cast(data()->attribute(CENTER_ID())); + std::shared_ptr aStartAttr = + std::dynamic_pointer_cast(data()->attribute(START_ID())); + std::shared_ptr anEndAttr = + std::dynamic_pointer_cast(data()->attribute(END_ID())); + if(!aCenterAttr->isInitialized() || !aStartAttr->isInitialized() || !anEndAttr->isInitialized()) { + return; } - return AISObjectPtr(); + + // Make a visible point. + SketchPlugin_Sketch::createPoint2DResult(this, sketch(), CENTER_ID(), 0); + + // Make a visible arc. + std::shared_ptr aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y())); + std::shared_ptr aStart(aSketch->to3D(aStartAttr->x(), aStartAttr->y())); + std::shared_ptr anEnd(aSketch->to3D(anEndAttr->x(), anEndAttr->y())); + std::shared_ptr aNDir = std::dynamic_pointer_cast( + aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); + std::shared_ptr aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z())); + + GeomShapePtr anArcShape = boolean(REVERSED_ID())->value() ? + GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, anEnd, aStart, aNormal) + : GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aStart, anEnd, aNormal); + + std::shared_ptr aResult = document()->createConstruction(data(), 1); + aResult->setShape(anArcShape); + aResult->setIsInHistory(false); + setResult(aResult, 1); } void SketchPlugin_Arc::move(double theDeltaX, double theDeltaY) { std::shared_ptr aData = data(); - if (!aData->isValid()) + if(!aData->isValid()) { return; + } bool aWasBlocked = aData->blockSendAttributeUpdated(true); - myStartUpdate = true; - myEndUpdate = true; - std::shared_ptr aPoint2 = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Arc::START_ID())); - if (aPoint2->isInitialized()) - aPoint2->move(theDeltaX, theDeltaY); - - std::shared_ptr aPoint3 = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Arc::END_ID())); - if (aPoint3->isInitialized()) - aPoint3->move(theDeltaX, theDeltaY); - myStartUpdate = false; - myEndUpdate = false; - - std::shared_ptr aPoint1 = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Arc::CENTER_ID())); - if (aPoint1->isInitialized()) - aPoint1->move(theDeltaX, theDeltaY); - - std::shared_ptr aPassedPoint = - std::dynamic_pointer_cast(aData->attribute(PASSED_POINT_ID())); - if (aPassedPoint->isInitialized()) - aPassedPoint->move(theDeltaX, theDeltaY); - aData->blockSendAttributeUpdated(aWasBlocked); -} + std::shared_ptr aCenter = std::dynamic_pointer_cast( + attribute(CENTER_ID())); + if(aCenter->isInitialized()) { + aCenter->move(theDeltaX, theDeltaY); + } -bool SketchPlugin_Arc::isFixed() { - return data()->selection(EXTERNAL_ID())->context().get() != NULL; -} + std::shared_ptr aStart = std::dynamic_pointer_cast( + attribute(START_ID())); + if(aStart->isInitialized()) { + aStart->move(theDeltaX, theDeltaY); + } -bool SketchPlugin_Arc::isFeatureValid() -{ - AttributeStringPtr anArcTypeAttr = - std::dynamic_pointer_cast(data()->attribute(ARC_TYPE())); - if (!anArcTypeAttr) - return false; - std::string anArcType = anArcTypeAttr->value(); + std::shared_ptr anEnd = std::dynamic_pointer_cast( + attribute(END_ID())); + if(anEnd->isInitialized()) { + anEnd->move(theDeltaX, theDeltaY); + } - std::shared_ptr aCenterAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::CENTER_ID())); - std::shared_ptr aStartAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::START_ID())); - std::shared_ptr anEndAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::END_ID())); - std::shared_ptr aPassedAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(data()->attribute(PASSED_POINT_ID())); - - bool isValid = false; - if (anArcType == ARC_TYPE_THREE_POINTS()) - isValid = aStartAttr->isInitialized() && - anEndAttr->isInitialized() && aPassedAttr->isInitialized(); - else - isValid = aCenterAttr->isInitialized() && - aStartAttr->isInitialized() && anEndAttr->isInitialized(); - - return isValid; + aData->blockSendAttributeUpdated(aWasBlocked); } -static inline void adjustPeriod(double& theParam) +bool SketchPlugin_Arc::isFixed() { - static const double PERIOD = 2.0 * PI; - while (theParam < 0.0) theParam += PERIOD; - while (theParam >= PERIOD) theParam -= PERIOD; + return data()->selection(EXTERNAL_ID())->context().get() != NULL; } void SketchPlugin_Arc::attributeChanged(const std::string& theID) @@ -350,424 +152,85 @@ void SketchPlugin_Arc::attributeChanged(const std::string& theID) GeomDataAPI_Point2D>(data()->attribute(START_ID())); std::shared_ptr anEndAttr = std::dynamic_pointer_cast< GeomDataAPI_Point2D>(data()->attribute(END_ID())); - // the second condition for unability to move external segments anywhere - if (theID == EXTERNAL_ID() || isFixed()) { + + // The second condition for unability to move external segments anywhere. + if(theID == EXTERNAL_ID() || isFixed()) { std::shared_ptr aSelection = data()->selection(EXTERNAL_ID())->value(); - if (!aSelection) { + if(!aSelection) { // empty shape in selection shows that the shape is equal to context ResultPtr anExtRes = selection(EXTERNAL_ID())->context(); - if (anExtRes) + if(anExtRes) { aSelection = anExtRes->shape(); + } } // update arguments due to the selection value - if (aSelection && !aSelection->isNull() && aSelection->isEdge()) { + if(aSelection && !aSelection->isNull() && aSelection->isEdge()) { std::shared_ptr anEdge( new GeomAPI_Edge(aSelection)); std::shared_ptr aCirc = anEdge->circle(); - if (aCirc.get()) { + if(aCirc.get()) { + bool aWasBlocked = data()->blockSendAttributeUpdated(true); + aCenterAttr->setValue(sketch()->to2D(aCirc->center())); aStartAttr->setValue(sketch()->to2D(anEdge->firstPoint())); anEndAttr->setValue(sketch()->to2D(anEdge->lastPoint())); - aCenterAttr->setValue(sketch()->to2D(aCirc->center())); - - data()->real(RADIUS_ID())->setValue(aCirc->radius()); - double aStartAngle, aEndAngle; - anEdge->getRange(aStartAngle, aEndAngle); - data()->real(ANGLE_ID())->setValue(aEndAngle - aStartAngle); - myParamBefore = aEndAngle; - adjustPeriod(myParamBefore); - } - } - return; - } - AttributeStringPtr aTypeAttr = - std::dynamic_pointer_cast(attribute(ARC_TYPE())); - - // this is before others since here end attribute may be changed, but with the special behavior - if (aTypeAttr->value() == ARC_TYPE_TANGENT() && - (theID == TANGENT_POINT_ID() || theID == END_ID())) { - SketchPlugin_Sketch* aSketch = sketch(); - AttributeRefAttrPtr aTangPtAttr = std::dynamic_pointer_cast( - data()->attribute(TANGENT_POINT_ID())); - - if (aTangPtAttr->isInitialized() && anEndAttr->isInitialized()) { - // compute orthogonal direction - std::shared_ptr anOrthoDir; - std::shared_ptr aTangentPoint = - std::dynamic_pointer_cast(aTangPtAttr->attr()); - std::shared_ptr aTangPnt2d = aTangentPoint->pnt(); - if (aTangPnt2d->isEqual(anEndAttr->pnt())) - return; - FeaturePtr aTangFeature = ModelAPI_Feature::feature(aTangentPoint->owner()); - std::shared_ptr aTangEdge = std::dynamic_pointer_cast( - aTangFeature->lastResult()->shape()); - if (aTangEdge->isLine()) { - std::shared_ptr aDir = aTangEdge->line()->direction(); - std::shared_ptr aPnt(new GeomAPI_Pnt(aDir->x(), aDir->y(), aDir->z())); - std::shared_ptr aPnt2d = aSketch->to2D(aPnt); - anOrthoDir = std::shared_ptr(new GeomAPI_Dir2d(-aPnt2d->y(), aPnt2d->x())); - } - else if (aTangEdge->isArc()) { - std::shared_ptr aCenter = aTangEdge->circle()->center(); - std::shared_ptr aCenter2d = aSketch->to2D(aCenter); - anOrthoDir = std::shared_ptr( - new GeomAPI_Dir2d(aTangPnt2d->xy()->decreased(aCenter2d->xy()))); - } - - // compute parameters of the middle perpendicular - std::shared_ptr aEndPntCoord = anEndAttr->pnt()->xy(); - std::shared_ptr aTempDir = aEndPntCoord->decreased(aTangPnt2d->xy()); - std::shared_ptr aMidDir(new GeomAPI_Dir2d(-aTempDir->y(), aTempDir->x())); - std::shared_ptr aMidPnt( - new GeomAPI_Pnt2d(aEndPntCoord->added(aTangPnt2d->xy())->multiplied(0.5))); - - // compute center of arc by calculating intersection of - // orthogonal line and middle perpendicular - std::shared_ptr anOrthoLine(new GeomAPI_Lin2d(aTangPnt2d, anOrthoDir)); - std::shared_ptr aMiddleLine(new GeomAPI_Lin2d(aMidPnt, aMidDir)); - std::shared_ptr aCenter = anOrthoLine->intersect(aMiddleLine); - if (aCenter) { - bool aWasBlocked = data()->blockSendAttributeUpdated(true); - aCenterAttr->setValue(aCenter); - aStartAttr->setValue(aTangPnt2d); - data()->blockSendAttributeUpdated(aWasBlocked); - } - - tangencyArcConstraints(); - } - return; - } - - // if changed the base attributes, update all other (is necessary) without recursion - if (theID == CENTER_ID() || theID == START_ID() || theID == END_ID() || theID == ARC_TYPE()) { - if (!isFeatureValid()) - 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; - } - // update all other attributes due to the base attributes values - if (aTypeAttr->value() == ARC_TYPE_THREE_POINTS()) { - // update passed point due to start, end and center - if (aCenter->distance(aStart) > tolerance && aCenter->distance(anEnd) > tolerance) { - // project passed point t othe circle - std::shared_ptr aPassedAttr = - std::dynamic_pointer_cast(data()->attribute(PASSED_POINT_ID())); - if (aPassedAttr->isInitialized()) { - std::shared_ptr aProjection = aCircleForArc->project(aPassedAttr->pnt()); - if (aProjection && aPassedAttr->pnt()->distance(aProjection) > tolerance) { - aPassedAttr->setValue(aProjection); - } - } else { // initialize it by some middle - value - std::shared_ptr aStartDir(new GeomAPI_Dir2d( - aStart->xy()->decreased(aCenter->xy()))); - std::shared_ptr aEndDir(new GeomAPI_Dir2d( - anEnd->xy()->decreased(aCenter->xy()))); - std::shared_ptr aMidDirXY = aStartDir->xy()->added(aEndDir->xy()); - if (aMidDirXY->dot(aMidDirXY) < tolerance * tolerance) { - // start and end directions are opposite, so middle direction will be orthogonal - aMidDirXY->setX(-aStartDir->y()); - aMidDirXY->setY(aStartDir->x()); - } - std::shared_ptr aMidDir(new GeomAPI_Dir2d(aMidDirXY)); - if ((aStartDir->cross(aMidDir) > 0) ^ !isReversed()) - aMidDir->reverse(); - std::shared_ptr aPassedPnt = - aCenter->xy()->added(aMidDir->xy()->multiplied(aCenter->distance(aStart))); - std::dynamic_pointer_cast(data()->attribute(PASSED_POINT_ID()))-> - setValue(aPassedPnt->x(), aPassedPnt->y()); + data()->blockSendAttributeUpdated(aWasBlocked, false); + + std::shared_ptr aCircle2d = + std::shared_ptr(new GeomAPI_Circ2d(aCenterAttr->pnt(), + aStartAttr->pnt())); + + double anEndParam = 0.0; + aCircle2d->parameter(anEndAttr->pnt(), paramTolerance, anEndParam); + myParamBefore = anEndParam; + + double aMidParam = anEndParam / 2.0; + std::shared_ptr aMidPnt2d; + aCircle2d->D0(aMidParam, aMidPnt2d); + std::shared_ptr aMinPnt = sketch()->to3D(aMidPnt2d->x(), aMidPnt2d->y()); + double aStartParam = 0.0; + aCirc->parameter(anEdge->firstPoint(), paramTolerance, aStartParam); + aCirc->parameter(aMinPnt, paramTolerance, aMidParam); + aCirc->parameter(anEdge->lastPoint(), paramTolerance, anEndParam); + aWasBlocked = data()->blockSendAttributeUpdated(true); + if(aStartParam < aMidParam && aMidParam < anEndParam) { + setReversed(true); + } else { + setReversed(false); } + data()->blockSendAttributeUpdated(aWasBlocked, false); } } - // update radius and angle - AttributeDoublePtr aRadiusAttr = std::dynamic_pointer_cast( - data()->attribute(RADIUS_ID())); - aRadiusAttr->setValue(aRadius); - AttributeDoublePtr anAngleAttr = std::dynamic_pointer_cast( - data()->attribute(ANGLE_ID())); - std::shared_ptr aCircle(new GeomAPI_Circ2d(aCenter, aStart)); - double aStartParam, aEndParam; - aCircle->parameter(aStart, paramTolerance, aStartParam); - aCircle->parameter(anEnd, paramTolerance, aEndParam); - adjustPeriod(aStartParam); - adjustPeriod(aEndParam); - // use the passed point for the angle calculation - if (aTypeAttr->value() == ARC_TYPE_THREE_POINTS()) { - std::shared_ptr aPassedAttr = - std::dynamic_pointer_cast(data()->attribute(PASSED_POINT_ID())); - double aPassedParam; - aCircle->parameter(aPassedAttr->pnt(), paramTolerance, aPassedParam); - adjustPeriod(aPassedParam); - double aNewAngle = aPassedParam >= aStartParam && aPassedParam <= aEndParam ? - ((aEndParam - aStartParam) * 180.0 / PI) : - ((aEndParam - aStartParam - 2.0 * PI) * 180.0 / PI); - if (!anAngleAttr->isInitialized() || fabs(aNewAngle - anAngleAttr->value()) > tolerance) - anAngleAttr->setValue(aNewAngle); - } else { - double aNewAngle = (aEndParam - aStartParam) * 180.0 / PI; - if (!anAngleAttr->isInitialized() || fabs(aNewAngle - anAngleAttr->value()) > tolerance) - anAngleAttr->setValue(aNewAngle); - } - - // calculate arc aperture and change the Inversed flag if needed - AttributeBooleanPtr isInversed = - std::dynamic_pointer_cast(attribute(INVERSED_ID())); - double aParameterNew = aEndParam - aStartParam; - if (((0 <= myParamBefore && myParamBefore <= PI / 2.0) || myParamBefore == PI * 2.0) && - PI * 1.5 <= aParameterNew && aParameterNew <= PI * 2.0) - isInversed->setValue(true); - else if (PI * 1.5 <= myParamBefore && myParamBefore <= PI * 2.0 && - 0 <= aParameterNew && aParameterNew <= PI / 2.0) - isInversed->setValue(false); - myParamBefore = aParameterNew; - - // do not need to inform that other parameters were changed in this basis mode: these arguments - // change is enough - data()->blockSendAttributeUpdated(aWasBlocked, false); - return; } - if (theID == PASSED_POINT_ID()) { - bool aWasBlocked = data()->blockSendAttributeUpdated(true); - - std::shared_ptr aPoints[3]; - int aNbInitialized = 0; - for (int i = 1; i <= 3; ++i) { - std::shared_ptr aCurPnt = - std::dynamic_pointer_cast(attribute(POINT_ID(i))); - if (aCurPnt->isInitialized()) - aPoints[aNbInitialized++] = aCurPnt->pnt(); - } - - if (aNbInitialized == 3) { - std::shared_ptr aCircle( - new GeomAPI_Circ2d(aPoints[0], aPoints[1], aPoints[2])); - - std::shared_ptr aCenter = aCircle->center(); - if (aCenter) { - aCenterAttr->setValue(aCenter); + double aRadius = 0; + double anAngle = 0; + if(aCenterAttr->isInitialized() && aStartAttr->isInitialized()) { + aRadius = aCenterAttr->pnt()->distance(aStartAttr->pnt()); + if(anEndAttr->isInitialized()) { + if(aStartAttr->pnt()->isEqual(anEndAttr->pnt())) { + anAngle = 360; + } else { + GeomAPI_Circ2d aCircleForArc(aCenterAttr->pnt(), aStartAttr->pnt()); + double aStartParam, anEndParam; + aCircleForArc.parameter(aStartAttr->pnt(), paramTolerance, aStartParam); + aCircleForArc.parameter(anEndAttr->pnt(), paramTolerance, anEndParam); + anAngle = (anEndParam - aStartParam) / PI * 180.0; + if(isReversed()) anAngle = 360.0 - anAngle; } } - data()->blockSendAttributeUpdated(aWasBlocked); - return; } - if (theID == RADIUS_ID()) { - if (!aStartAttr->isInitialized() || !anEndAttr->isInitialized() || - !aCenterAttr->isInitialized()) - return; - // move center and passed point - std::shared_ptr aStart = aStartAttr->pnt(); - std::shared_ptr anEnd = anEndAttr->pnt(); - std::shared_ptr aCenter = aCenterAttr->pnt(); - if (aStart->distance(aCenter) < tolerance || anEnd->distance(aCenter) < tolerance) - return; - AttributeDoublePtr aRadiusAttr = std::dynamic_pointer_cast( - data()->attribute(RADIUS_ID())); - double aRadius = aRadiusAttr->value(); - - bool aWasBlocked = data()->blockSendAttributeUpdated(true); - std::shared_ptr - aStartDir(new GeomAPI_Dir2d(aStart->xy()->decreased(aCenter->xy()))); - std::shared_ptr - aNewStart = aStartDir->xy()->multiplied(aRadius)->added(aCenter->xy()); - aStartAttr->setValue(aNewStart->x(), aNewStart->y()); - std::shared_ptr - anEndDir(new GeomAPI_Dir2d(anEnd->xy()->decreased(aCenter->xy()))); - std::shared_ptr - aNewEnd = anEndDir->xy()->multiplied(aRadius)->added(aCenter->xy()); - anEndAttr->setValue(aNewEnd->x(), aNewEnd->y()); - data()->blockSendAttributeUpdated(aWasBlocked); - return; - } - if (theID == ANGLE_ID()) { - if (!aStartAttr->isInitialized() || !aCenterAttr->isInitialized()) - return; - AttributeDoublePtr anAngleAttr = std::dynamic_pointer_cast( - data()->attribute(ANGLE_ID())); - bool aWasBlocked = data()->blockSendAttributeUpdated(true); - // move end point and passed point - std::shared_ptr aCenter = aCenterAttr->pnt()->xy(); - double anAngle = anAngleAttr->value() * PI / 180.0; - double sinA = sin(anAngle); - double cosA = cos(anAngle); - std::shared_ptr aStartDir = aStartAttr->pnt()->xy()->decreased(aCenter); - std::shared_ptr aDir(new GeomAPI_XY( - aStartDir->x() * cosA - aStartDir->y() * sinA, - aStartDir->x() * sinA + aStartDir->y() * cosA)); - anEndAttr->setValue(aCenter->x() + aDir->x(), aCenter->y() + aDir->y()); - data()->blockSendAttributeUpdated(aWasBlocked); - return; - } + bool aWasBlocked = data()->blockSendAttributeUpdated(true); + real(RADIUS_ID())->setValue(aRadius); + real(ANGLE_ID())->setValue(anAngle); + data()->blockSendAttributeUpdated(aWasBlocked, false); } void SketchPlugin_Arc::setReversed(bool isReversed) { - std::dynamic_pointer_cast( - attribute(INVERSED_ID()))->setValue(isReversed); - myParamBefore = 0.0; + boolean(REVERSED_ID())->setValue(isReversed); } bool SketchPlugin_Arc::isReversed() { - return std::dynamic_pointer_cast(attribute(INVERSED_ID()))->value(); -} - -void SketchPlugin_Arc::tangencyArcConstraints() -{ - if (!lastResult()) - return; - - std::shared_ptr aStartAttr = - std::dynamic_pointer_cast(attribute(START_ID())); - AttributeRefAttrPtr aTangPtAttr = std::dynamic_pointer_cast( - attribute(TANGENT_POINT_ID())); - if (!aTangPtAttr->attr()) - return; - - FeaturePtr aFeature = ModelAPI_Feature::feature(aStartAttr->owner()); - ObjectPtr aThisArc = aFeature->lastResult(); - aFeature = ModelAPI_Feature::feature(aTangPtAttr->attr()->owner()); - ObjectPtr aTangFeature = aFeature->lastResult(); - - // trying to find constraints to fix the tangency of the arc - std::set aCoincidence; - std::set aTangency; - - AttributeRefAttrPtr aRefAttrA, aRefAttrB; - std::set aRefs = data()->refsToMe(); - const std::set& aRefsToResult = lastResult()->data()->refsToMe(); - aRefs.insert(aRefsToResult.begin(), aRefsToResult.end()); - std::set::const_iterator aRefIt = aRefs.begin(); - for (; aRefIt != aRefs.end(); ++aRefIt) { - FeaturePtr aConstrFeature = ModelAPI_Feature::feature((*aRefIt)->owner()); - if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { - aRefAttrA = std::dynamic_pointer_cast( - aConstrFeature->attribute(SketchPlugin_Constraint::ENTITY_A())); - aRefAttrB = std::dynamic_pointer_cast( - aConstrFeature->attribute(SketchPlugin_Constraint::ENTITY_B())); - if ((aRefAttrA && aRefAttrA->attr() == aStartAttr) || - (aRefAttrB && aRefAttrB->attr() == aStartAttr)) - aCoincidence.insert(aConstrFeature); - } - else if (aConstrFeature->getKind() == SketchPlugin_ConstraintTangent::ID()) { - aRefAttrA = std::dynamic_pointer_cast( - aConstrFeature->attribute(SketchPlugin_Constraint::ENTITY_A())); - aRefAttrB = std::dynamic_pointer_cast( - aConstrFeature->attribute(SketchPlugin_Constraint::ENTITY_B())); - if ((aRefAttrA && aRefAttrA->object() == aThisArc) || - (aRefAttrB && aRefAttrB->object() == aThisArc)) - aTangency.insert(aConstrFeature); - } - } - // search applicable pair of constraints - bool isFound = false; - FeaturePtr aPrevCoincidence, aPrevTangency; - std::set::const_iterator aCIt, aTIt; - for (aCIt = aCoincidence.begin(); aCIt != aCoincidence.end() && !isFound; ++aCIt) { - aRefAttrA = std::dynamic_pointer_cast( - (*aCIt)->attribute(SketchPlugin_Constraint::ENTITY_A())); - aRefAttrB = std::dynamic_pointer_cast( - (*aCIt)->attribute(SketchPlugin_Constraint::ENTITY_B())); - AttributePtr anOtherPoint = - aRefAttrA->attr() == aStartAttr ? aRefAttrB->attr() : aRefAttrA->attr(); - for (aTIt = aTangency.begin(); aTIt != aTangency.end() && !isFound; ++aTIt) { - aRefAttrA = std::dynamic_pointer_cast( - (*aTIt)->attribute(SketchPlugin_Constraint::ENTITY_A())); - aRefAttrB = std::dynamic_pointer_cast( - (*aTIt)->attribute(SketchPlugin_Constraint::ENTITY_B())); - ObjectPtr anOtherObject = aRefAttrA->object() == aThisArc ? - aRefAttrB->object() : aRefAttrA->object(); - FeaturePtr anOtherFeature = ModelAPI_Feature::feature(anOtherObject); - if (anOtherPoint->owner() == anOtherFeature) { - isFound = true; - aPrevCoincidence = *aCIt; - aPrevTangency = *aTIt; - } - } - } - - if (isFound) { - // update previous constraints - aRefAttrA = std::dynamic_pointer_cast( - aPrevCoincidence->attribute(SketchPlugin_Constraint::ENTITY_A())); - aRefAttrB = std::dynamic_pointer_cast( - aPrevCoincidence->attribute(SketchPlugin_Constraint::ENTITY_B())); - if (aRefAttrA->attr() == aStartAttr) - aRefAttrB->setAttr(aTangPtAttr->attr()); - else - aRefAttrA->setAttr(aTangPtAttr->attr()); - - aRefAttrA = std::dynamic_pointer_cast( - aPrevTangency->attribute(SketchPlugin_Constraint::ENTITY_A())); - aRefAttrB = std::dynamic_pointer_cast( - aPrevTangency->attribute(SketchPlugin_Constraint::ENTITY_B())); - if (aRefAttrA->object() == aThisArc) - aRefAttrB->setObject(aTangFeature); - else - aRefAttrA->setObject(aTangFeature); - } else { - // Wait all constraints being removed, then send update events - static Events_ID aDeleteEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED); - bool isDeleteFlushed = Events_Loop::loop()->isFlushed(aDeleteEvent); - if (isDeleteFlushed) - Events_Loop::loop()->setFlushed(aDeleteEvent, false); - // Remove all obtained constraints which use current arc, because - // there is no information which of them were used to build tangency arc. - DocumentPtr aDoc = sketch()->document(); - std::set aFeaturesToBeRemoved; - for (aCIt = aCoincidence.begin(); aCIt != aCoincidence.end(); ++aCIt) - aFeaturesToBeRemoved.insert(*aCIt); - for (aTIt = aTangency.begin(); aTIt != aTangency.end(); ++aTIt) - aFeaturesToBeRemoved.insert(*aTIt); - ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToBeRemoved); - // Send events to update the sub-features by the solver. - if (isDeleteFlushed) - Events_Loop::loop()->setFlushed(aDeleteEvent, true); - else - Events_Loop::loop()->flush(aDeleteEvent); - - // Wait all constraints being created, then send update events - static Events_ID aCreateEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED); - bool isCreateFlushed = Events_Loop::loop()->isFlushed(aCreateEvent); - if (isCreateFlushed) - Events_Loop::loop()->setFlushed(aCreateEvent, false); - - // Create new constraints - FeaturePtr aConstraint = sketch()->addFeature(SketchPlugin_ConstraintCoincidence::ID()); - aRefAttrA = std::dynamic_pointer_cast( - aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A())); - aRefAttrB = std::dynamic_pointer_cast( - aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B())); - aRefAttrA->setAttr(aStartAttr); - aRefAttrB->setAttr(aTangPtAttr->attr()); - aConstraint->execute(); - ModelAPI_EventCreator::get()->sendUpdated(aConstraint, aCreateEvent); - - aConstraint = sketch()->addFeature(SketchPlugin_ConstraintTangent::ID()); - aRefAttrA = std::dynamic_pointer_cast( - aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A())); - aRefAttrB = std::dynamic_pointer_cast( - aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B())); - aRefAttrA->setObject(aThisArc); - aRefAttrB->setObject(aTangFeature); - aConstraint->execute(); - ModelAPI_EventCreator::get()->sendUpdated(aConstraint, aCreateEvent); - - // Send events to update the sub-features by the solver. - if(isCreateFlushed) - Events_Loop::loop()->setFlushed(aCreateEvent, true); - else - Events_Loop::loop()->flush(aCreateEvent); - } + return boolean(REVERSED_ID())->value(); } diff --git a/src/SketchPlugin/SketchPlugin_Arc.h b/src/SketchPlugin/SketchPlugin_Arc.h index 1a5a5fc5e..7b2e29472 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.h +++ b/src/SketchPlugin/SketchPlugin_Arc.h @@ -8,9 +8,10 @@ #define SketchPlugin_Arc_H_ #include "SketchPlugin.h" -#include -#include -#include + +#include "SketchPlugin_SketchEntity.h" + + /**\class SketchPlugin_Arc * \ingroup Plugins @@ -19,106 +20,56 @@ * calculated when there is non-initialized attributes of the arc. The second is a result and * it is calculated if all attributes are initialized. */ -class SketchPlugin_Arc : public SketchPlugin_SketchEntity, public GeomAPI_IPresentable +class SketchPlugin_Arc: public SketchPlugin_SketchEntity { - /// to avoid cyclic dependencies in automatic updates: they mean that - /// update is performed right now and automatic updates are not needed - bool myStartUpdate, myEndUpdate; - /// to avoid (if possible) additional modification of changed coordinate (issue #855) - double myXEndBefore, myYEndBefore; - - /// to define in which direction draw arc - double myParamBefore; - public: /// Arc feature kind inline static const std::string& ID() { - static const std::string MY_SKETCH_ARC_ID("SketchArc"); - return MY_SKETCH_ARC_ID; - } - - inline static const std::string& ARC_TYPE() - { - static const std::string TYPE("ArcType"); - return TYPE; - } - - inline static const std::string& ARC_TYPE_TANGENT() - { - static const std::string TYPE("Tangent"); - return TYPE; - } - - static const std::string& ARC_TYPE_CENTER_START_END() - { - static const std::string TYPE("CenterStartEnd"); - return TYPE; - } - static const std::string& ARC_TYPE_THREE_POINTS() - { - static const std::string TYPE("ThreePoints"); - return TYPE; - } - - static const std::string& TANGENT_POINT_ID() - { - static const std::string TANGENT_PNT("ArcTangentPoint"); - return TANGENT_PNT; + static const std::string ID("SketchArc"); + return ID; } /// Central 2D point of the circle which contains the arc inline static const std::string& CENTER_ID() { - static const std::string MY_CENTER_ID = "ArcCenter"; - return MY_CENTER_ID; - } - - inline static const std::string& CENTER_REF_ID() - { - static const std::string MY_CENTER_REF_ID = "ArcCenterRef"; - return MY_CENTER_REF_ID; + static const std::string ID = "center_point"; + return ID; } /// Start 2D point of the arc inline static const std::string& START_ID() { - static const std::string MY_START_ID = "ArcStartPoint"; - return MY_START_ID; + static const std::string ID = "start_point"; + return ID; } + /// End 2D point of the arc inline static const std::string& END_ID() { - static const std::string MY_END_ID = "ArcEndPoint"; - return MY_END_ID; - } - - /// Inversed flag - inline static const std::string& INVERSED_ID() - { - static const std::string MY_INVERSED_ID("InversedArc"); - return MY_INVERSED_ID; - } - - /// Passed point of the arc. - static const std::string& PASSED_POINT_ID() - { - static const std::string PASSED_PNT("ArcPassedPoint"); - return PASSED_PNT; + static const std::string ID = "end_point"; + return ID; } /// Arc radius. static const std::string& RADIUS_ID() { - static const std::string RADIUS("ArcRadius"); - return RADIUS; + static const std::string ID("radius"); + return ID; } /// Arc angle. static const std::string& ANGLE_ID() { - static const std::string ANGLE("ArcAngle"); - return ANGLE; + static const std::string ID("angle"); + return ID; + } + + /// Reversed flag + inline static const std::string& REVERSED_ID() + { + static const std::string ID("reversed"); + return ID; } /// Returns the kind of a feature @@ -131,15 +82,12 @@ class SketchPlugin_Arc : public SketchPlugin_SketchEntity, public GeomAPI_IPrese /// Returns true is sketch element is under the rigid constraint SKETCHPLUGIN_EXPORT virtual bool isFixed(); - /// Creates an arc-shape - SKETCHPLUGIN_EXPORT virtual void execute(); - /// Called on change of any argument-attribute of this object /// \param theID identifier of changed attribute SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); - /// Returns the AIS preview - virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); + /// Creates an arc-shape + SKETCHPLUGIN_EXPORT virtual void execute(); /// Moves the feature /// \param theDeltaX the delta for X coordinate is moved @@ -149,6 +97,7 @@ class SketchPlugin_Arc : public SketchPlugin_SketchEntity, public GeomAPI_IPrese /// Updates the "reversed" flag /// \param isReversed whether the arc will be reversed void setReversed(bool isReversed); + /// Returns \c true is the arc is reversed bool isReversed(); @@ -160,12 +109,8 @@ protected: virtual void initDerivedClassAttributes(); private: - /// Returns true if all obligatory attributes are initialized - bool isFeatureValid(); - - /// Compose constraints to build tangency arc - void tangencyArcConstraints(); - + /// to define in which direction draw arc + double myParamBefore; }; #endif diff --git a/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp b/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp index 305aba0bb..e21de9591 100755 --- a/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp @@ -837,10 +837,6 @@ void SketchPlugin_ConstraintSplit::splitArc(FeaturePtr& theSplitFeature, return; } - // manually change type of arc to avoid incorrect self-constrainting of the tangent arc - aBaseFeature->string(SketchPlugin_Arc::ARC_TYPE())->setValue( - SketchPlugin_Arc::ARC_TYPE_CENTER_START_END()); - arrangePointsOnArc(aBaseFeature, aStartPointAttrOfBase, anEndPointAttrOfBase, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit); #ifdef DEBUG_SPLIT @@ -1044,7 +1040,7 @@ void SketchPlugin_ConstraintSplit::arrangePointsOnArc( std::shared_ptr aCenter = std::dynamic_pointer_cast( theArc->attribute(SketchPlugin_Arc::CENTER_ID()))->pnt(); - bool isReversed = theArc->boolean(SketchPlugin_Arc::INVERSED_ID())->value(); + bool isReversed = theArc->boolean(SketchPlugin_Arc::REVERSED_ID())->value(); // collect directions to each point std::shared_ptr aStartDir( @@ -1140,9 +1136,6 @@ FeaturePtr SketchPlugin_ConstraintSplit::createArcFeature(const FeaturePtr& theB // by arc; moreover, it may cause cyclicity in hte mechanism of updater bool aWasBlocked = aFeature->data()->blockSendAttributeUpdated(true); - aFeature->string(SketchPlugin_Arc::ARC_TYPE())->setValue( - SketchPlugin_Arc::ARC_TYPE_CENTER_START_END()); - fillAttribute(aFeature->attribute(SketchPlugin_Arc::CENTER_ID()), theBaseFeature->attribute(aCenterAttributeId)); fillAttribute(aFeature->attribute(SketchPlugin_Arc::START_ID()), theFirstPointAttr); @@ -1153,8 +1146,8 @@ FeaturePtr SketchPlugin_ConstraintSplit::createArcFeature(const FeaturePtr& theB /// fill referersed state of created arc as it is on the base arc if (theBaseFeature->getKind() == SketchPlugin_Arc::ID()) { - bool aReversed = theBaseFeature->boolean(SketchPlugin_Arc::INVERSED_ID())->value(); - aFeature->boolean(SketchPlugin_Arc::INVERSED_ID())->setValue(aReversed); + bool aReversed = theBaseFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value(); + aFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->setValue(aReversed); } aFeature->data()->blockSendAttributeUpdated(aWasBlocked); aFeature->execute(); // to obtain result diff --git a/src/SketchPlugin/SketchPlugin_Fillet.cpp b/src/SketchPlugin/SketchPlugin_Fillet.cpp index f56b27d73..7039a37ad 100644 --- a/src/SketchPlugin/SketchPlugin_Fillet.cpp +++ b/src/SketchPlugin/SketchPlugin_Fillet.cpp @@ -667,7 +667,7 @@ void getPointOnEdge(const FeaturePtr theFeature, theFeature->attribute(SketchPlugin_Arc::START_ID()))->pnt(); std::shared_ptr aPntEnd = std::dynamic_pointer_cast( theFeature->attribute(SketchPlugin_Arc::END_ID()))->pnt(); - if(theFeature->attribute(SketchPlugin_Arc::INVERSED_ID())) { + if(theFeature->attribute(SketchPlugin_Arc::REVERSED_ID())) { aPntTemp = aPntStart; aPntStart = aPntEnd; aPntEnd = aPntTemp; diff --git a/src/SketchPlugin/SketchPlugin_MacroArc.cpp b/src/SketchPlugin/SketchPlugin_MacroArc.cpp index 381326476..a5572566b 100644 --- a/src/SketchPlugin/SketchPlugin_MacroArc.cpp +++ b/src/SketchPlugin/SketchPlugin_MacroArc.cpp @@ -41,7 +41,6 @@ const double PI = 3.141592653589793238463; SketchPlugin_MacroArc::SketchPlugin_MacroArc() : SketchPlugin_SketchEntity(), - myIsInversed(false), myParamBefore(0.0) { } @@ -61,6 +60,8 @@ void SketchPlugin_MacroArc::initAttributes() data()->addAttribute(TANGENT_POINT_ID(), ModelAPI_AttributeRefAttr::typeId()); data()->addAttribute(END_POINT_3_ID(), GeomDataAPI_Point2D::typeId()); + data()->addAttribute(REVERSED_ID(), ModelAPI_AttributeBoolean::typeId()); + data()->addAttribute(RADIUS_ID(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(ANGLE_ID(), ModelAPI_AttributeDouble::typeId()); @@ -71,6 +72,8 @@ void SketchPlugin_MacroArc::initAttributes() data()->addAttribute(END_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId()); data()->addAttribute(PASSED_POINT_REF_ID(), ModelAPI_AttributeRefAttr::typeId()); + boolean(REVERSED_ID())->setValue(false); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CENTER_POINT_REF_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), START_POINT_REF_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), END_POINT_REF_ID()); @@ -107,7 +110,7 @@ void SketchPlugin_MacroArc::attributeChanged(const std::string& theID) myCenter.reset(); myStart.reset(); myEnd.reset(); - myIsInversed = false; + boolean(REVERSED_ID())->setValue(false); myParamBefore = 0.0; } else if(anArcType == ARC_TYPE_BY_CENTER_AND_POINTS()) { std::shared_ptr aCenterPointAttr = @@ -141,9 +144,9 @@ void SketchPlugin_MacroArc::attributeChanged(const std::string& theID) double aParameterNew = 0.0; if(aCircleForArc.parameter(myEnd, paramTolerance, aParameterNew)) { if(myParamBefore <= PI / 2.0 && aParameterNew >= PI * 1.5) { - myIsInversed = true; + boolean(REVERSED_ID())->setValue(true); } else if(myParamBefore >= PI * 1.5 && aParameterNew <= PI / 2.0) { - myIsInversed = false; + boolean(REVERSED_ID())->setValue(false); } } myParamBefore = aParameterNew; @@ -174,9 +177,9 @@ void SketchPlugin_MacroArc::attributeChanged(const std::string& theID) aCircle.parameter(myEnd, paramTolerance, anEndParam); aCircle.parameter(aPassed, paramTolerance, aPassedParam); if(aPassedParam > anEndParam) { - myIsInversed = true; + boolean(REVERSED_ID())->setValue(true); } else { - myIsInversed = false; + boolean(REVERSED_ID())->setValue(false); } } else { std::shared_ptr aDir = myEnd->xy()->decreased(myStart->xy())->multiplied(0.5); @@ -251,12 +254,12 @@ void SketchPlugin_MacroArc::attributeChanged(const std::string& theID) double aParameterNew = 0.0; if(aCircleForArc.parameter(myEnd, paramTolerance, aParameterNew)) { if(myParamBefore <= PI / 2.0 && aParameterNew >= PI * 1.5) { - if(!myIsInversed) { - myIsInversed = true; + if(!boolean(REVERSED_ID())->value()) { + boolean(REVERSED_ID())->setValue(true); } } else if(myParamBefore >= PI * 1.5 && aParameterNew <= PI / 2.0) { - if(myIsInversed) { - myIsInversed = false; + if(boolean(REVERSED_ID())->value()) { + boolean(REVERSED_ID())->setValue(false); } } } @@ -276,7 +279,7 @@ void SketchPlugin_MacroArc::attributeChanged(const std::string& theID) aCircleForArc.parameter(myStart, paramTolerance, aStartParam); aCircleForArc.parameter(myEnd, paramTolerance, anEndParam); anAngle = (anEndParam - aStartParam) / PI * 180.0; - if(myIsInversed) anAngle = 360.0 - anAngle; + if(boolean(REVERSED_ID())->value()) anAngle = 360.0 - anAngle; } } } @@ -306,7 +309,7 @@ AISObjectPtr SketchPlugin_MacroArc::getAISObject(AISObjectPtr thePrevious) std::dynamic_pointer_cast( aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); std::shared_ptr aNormal = aNDir->dir(); - GeomShapePtr anArcShape = myIsInversed ? + GeomShapePtr anArcShape = boolean(REVERSED_ID())->value() ? GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, anEnd, aStart, aNormal) : GeomAlgoAPI_EdgeBuilder::lineCircleArc(aCenter, aStart, anEnd, aNormal); GeomShapePtr aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter); diff --git a/src/SketchPlugin/SketchPlugin_MacroArc.h b/src/SketchPlugin/SketchPlugin_MacroArc.h index a082c64a3..aec30931c 100644 --- a/src/SketchPlugin/SketchPlugin_MacroArc.h +++ b/src/SketchPlugin/SketchPlugin_MacroArc.h @@ -8,10 +8,13 @@ #define SketchPlugin_MacroArc_H_ #include "SketchPlugin.h" -#include -#include + +#include "SketchPlugin_SketchEntity.h" + #include +class GeomAPI_Pnt2d; + /**\class SketchPlugin_MacroArc * \ingroup Plugins * \brief Feature for creation of the new arc of circle in PartSet. @@ -132,6 +135,13 @@ class SketchPlugin_MacroArc: public SketchPlugin_SketchEntity, return ID; } + /// Reversed flag + inline static const std::string& REVERSED_ID() + { + static const std::string ID("reversed"); + return ID; + } + /// Arc radius. static const std::string& RADIUS_ID() { @@ -187,7 +197,6 @@ private: std::shared_ptr myEnd; /// To define in which direction draw arc. - bool myIsInversed; double myParamBefore; }; diff --git a/src/SketchPlugin/SketchPlugin_MacroCircle.h b/src/SketchPlugin/SketchPlugin_MacroCircle.h index 05a2d301b..974a0eeb6 100644 --- a/src/SketchPlugin/SketchPlugin_MacroCircle.h +++ b/src/SketchPlugin/SketchPlugin_MacroCircle.h @@ -9,12 +9,12 @@ #include "SketchPlugin.h" -#include "SketchPlugin_Sketch.h" #include "SketchPlugin_SketchEntity.h" #include -#include -#include + +class GeomAPI_Circ2d; +class GeomAPI_Pnt2d; /**\class SketchPlugin_MacroCircle * \ingroup Plugins diff --git a/src/SketchPlugin/SketchPlugin_Trim.cpp b/src/SketchPlugin/SketchPlugin_Trim.cpp index 4ae706045..5a6f4e1ee 100644 --- a/src/SketchPlugin/SketchPlugin_Trim.cpp +++ b/src/SketchPlugin/SketchPlugin_Trim.cpp @@ -824,7 +824,7 @@ void SketchPlugin_Trim::arrangePointsOnArc(const FeaturePtr& theArc, std::shared_ptr aCenter = std::dynamic_pointer_cast( theArc->attribute(SketchPlugin_Arc::CENTER_ID()))->pnt(); - bool isReversed = theArc->boolean(SketchPlugin_Arc::INVERSED_ID())->value(); + bool isReversed = theArc->boolean(SketchPlugin_Arc::REVERSED_ID())->value(); // collect directions to each point std::shared_ptr aStartDir( @@ -952,9 +952,6 @@ FeaturePtr SketchPlugin_Trim::createArcFeature(const FeaturePtr& theBaseFeature, // by arc; moreover, it may cause cyclicity in hte mechanism of updater bool aWasBlocked = aFeature->data()->blockSendAttributeUpdated(true); - aFeature->string(SketchPlugin_Arc::ARC_TYPE())->setValue( - SketchPlugin_Arc::ARC_TYPE_CENTER_START_END()); - fillAttribute(aFeature->attribute(SketchPlugin_Arc::CENTER_ID()), theBaseFeature->attribute(aCenterAttributeId)); fillPointAttribute(aFeature->attribute(SketchPlugin_Arc::START_ID()), theFirstPoint); @@ -965,8 +962,8 @@ FeaturePtr SketchPlugin_Trim::createArcFeature(const FeaturePtr& theBaseFeature, /// fill referersed state of created arc as it is on the base arc if (theBaseFeature->getKind() == SketchPlugin_Arc::ID()) { - bool aReversed = theBaseFeature->boolean(SketchPlugin_Arc::INVERSED_ID())->value(); - aFeature->boolean(SketchPlugin_Arc::INVERSED_ID())->setValue(aReversed); + bool aReversed = theBaseFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value(); + aFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->setValue(aReversed); } aFeature->execute(); // to obtain result aFeature->data()->blockSendAttributeUpdated(aWasBlocked); diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index ce6ee3b34..7b929019c 100755 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -734,19 +734,6 @@ bool SketchPlugin_ArcTangentPointValidator::isValid(const AttributePtr& theAttri return false; } - // Check the tangent point is equal to arc end - FeaturePtr anArc = std::dynamic_pointer_cast(aRefAttr->owner()); - std::shared_ptr anEndPoint = std::dynamic_pointer_cast( - anArc->attribute(SketchPlugin_Arc::END_ID())); - if (anEndPoint->isInitialized()) { - std::shared_ptr aTangPt = - std::dynamic_pointer_cast(anAttr); - if (aTangPt->pnt()->distance(anEndPoint->pnt()) < tolerance) { - theError = "Unable to build arc on same points"; - return false; - } - } - return true; } diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 8a11e16c5..646060b45 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -143,46 +143,50 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - + + @@ -245,7 +249,7 @@ label="Tangent point" tooltip="Select point on line" shape_types="vertex"> - + & theMirrorLine, // process specific features if (theOriginal->getKind() == SketchPlugin_Arc::ID()) { // orientation of arc - theMirrored->boolean(SketchPlugin_Arc::INVERSED_ID())->setValue( - !theOriginal->boolean(SketchPlugin_Arc::INVERSED_ID())->value()); + theMirrored->boolean(SketchPlugin_Arc::REVERSED_ID())->setValue( + !theOriginal->boolean(SketchPlugin_Arc::REVERSED_ID())->value()); } else if (theOriginal->getKind() == SketchPlugin_Circle::ID()) { // radius of the circle theMirrored->real(SketchPlugin_Circle::RADIUS_ID())->setValue( -- 2.30.2