From: asozinov Date: Fri, 23 Jun 2023 01:06:02 +0000 (+0100) Subject: bos#35152 [EDF] (2023-T1) Sketch Circle should allow user to position construction... X-Git-Tag: V9_13_0a1~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Ftlpr%2F55%2Fhead;p=modules%2Fshaper.git bos#35152 [EDF] (2023-T1) Sketch Circle should allow user to position construction point WIll be modified Sketch Circle feature: Current implementation provide possibility change sewing point and rotate this point Sketch.addCircleWithPoint(CenterPoint, Radius, Angle) Sketch.addCircleWithPoint(CenterPoint, PassedPoint, Angle) Sketch.addCircleWithPoint(PassPoint1, PassPoint2, PassPoint3, Angle) Get new point: SketchCircle.createdPoint() //Last modification (06/07/23): change comment --- diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp index 0575a0525..3444bfb86 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp @@ -162,12 +162,16 @@ std::shared_ptr GeomAlgoAPI_EdgeBuilder::cylinderAxis( std::shared_ptr GeomAlgoAPI_EdgeBuilder::lineCircle( std::shared_ptr theCenter, std::shared_ptr theNormal, - double theRadius) + double theRadius, double theRotationAngle) { const gp_Pnt& aCenter = theCenter->impl(); const gp_Dir& aDir = theNormal->impl(); + gp_Ax1 anAx(aCenter, aDir); + gp_Circ aCircle(gp_Ax2(aCenter, aDir), theRadius); + if (Abs(theRotationAngle) > Precision::Confusion()) // Tolerance + aCircle.Rotate(anAx, theRotationAngle); BRepBuilderAPI_MakeEdge anEdgeBuilder(aCircle); std::shared_ptr aRes(new GeomAPI_Edge); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h index 37e0128a5..63e4601d8 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h @@ -65,7 +65,8 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_EdgeBuilder /// Creates linear edge in a form of a circle by a point and a circle radius static std::shared_ptr lineCircle(std::shared_ptr theCenter, std::shared_ptr theNormal, - double theRadius); + double theRadius, + double theRotationAngle = 0.); /// Creates linear edge in a form of a circle by GeomAPI_Circle static std::shared_ptr lineCircle(std::shared_ptr theCircle); diff --git a/src/SketchAPI/SketchAPI_Circle.cpp b/src/SketchAPI/SketchAPI_Circle.cpp index 8b99eea12..f05936c70 100644 --- a/src/SketchAPI/SketchAPI_Circle.cpp +++ b/src/SketchAPI/SketchAPI_Circle.cpp @@ -26,6 +26,9 @@ #include #include +#include +#include + //================================================================================================== SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr & theFeature) : SketchAPI_SketchEntity(theFeature) @@ -37,22 +40,26 @@ SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr & the SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr& theFeature, double theCenterX, double theCenterY, - double theRadius) + double theRadius, + bool theIsAddPoint, + double theAngle) : SketchAPI_SketchEntity(theFeature) { if(initialize()) { - setByCenterAndRadius(theCenterX, theCenterY, theRadius); + setByCenterAndRadius(theCenterX, theCenterY, theRadius, theIsAddPoint, theAngle); } } //================================================================================================== SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr& theFeature, const std::shared_ptr& theCenter, - double theRadius) + double theRadius, + bool theIsAddPoint, + double theAngle) : SketchAPI_SketchEntity(theFeature) { if(initialize()) { - setByCenterAndRadius(theCenter, theRadius); + setByCenterAndRadius(theCenter, theRadius, theAngle); } } @@ -83,22 +90,31 @@ SketchAPI_Circle::~SketchAPI_Circle() } //================================================================================================== -void SketchAPI_Circle::setByCenterAndRadius(double theCenterX, double theCenterY, double theRadius) +void SketchAPI_Circle::setByCenterAndRadius(double theCenterX, double theCenterY, + double theRadius, bool theIsAddPoint, + double theAngle) { fillAttribute(center(), theCenterX, theCenterY); fillAttribute(theRadius, myradius); + fillAttribute(theIsAddPoint, myaddpoint); + fillAttribute(theAngle, myangle); execute(); + //createPoint(); } //================================================================================================== void SketchAPI_Circle::setByCenterAndRadius(const std::shared_ptr& theCenter, - double theRadius) + double theRadius, bool theIsAddPoint, + double theAngle) { fillAttribute(theCenter, mycenter); fillAttribute(theRadius, myradius); + fillAttribute(theIsAddPoint, myaddpoint); + fillAttribute(theAngle, myangle); execute(); + //createPoint(); } //================================================================================================== @@ -141,6 +157,38 @@ void SketchAPI_Circle::setRadius(double theRadius) execute(); } +//================================================================================================== +void SketchAPI_Circle::setIsToAddPoint(bool theIsToAddPoint) +{ + fillAttribute(theIsToAddPoint, myaddpoint); + + execute(); +} + +//================================================================================================== +void SketchAPI_Circle::setAngle(double theAngle) +{ + fillAttribute(ModelHighAPI_Double(theAngle), myangle); + + execute(); +} + +//================================================================================================== +// Return created point +std::shared_ptr SketchAPI_Circle::createdPoint() const +{ + AttributeReferencePtr anRef = feature()->reference(SketchPlugin_Circle::CONSTRUCTION_POINT_REF_ID()); + if (!anRef->isInitialized()) + return {}; + + FeaturePtr aFeature = ModelAPI_Feature::feature(anRef->value()); + if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID()) + { + return std::shared_ptr < SketchAPI_SketchEntity>(new SketchAPI_Point(aFeature)); + } + return {}; +} + //================================================================================================== void SketchAPI_Circle::dump(ModelHighAPI_Dumper& theDumper) const { @@ -150,14 +198,35 @@ void SketchAPI_Circle::dump(ModelHighAPI_Dumper& theDumper) const FeaturePtr aBase = feature(); const std::string& aSketchName = theDumper.parentName(aBase); + const bool isToAddPoint = addpoint()->value(); + AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID()); if (anExternal->context()) { // circle is external - theDumper << aBase << " = " << aSketchName << ".addCircle(" << anExternal << ")" << std::endl; - } else { + if(isToAddPoint) + { + theDumper << aBase << " = " << aSketchName << ".addCircleWithPoint(" << anExternal << ")" << std::endl; + } + else + { + theDumper << aBase << " = " << aSketchName << ".addCircle(" << anExternal << ")" << std::endl; + } + } + else { // circle given by center and radius - theDumper << aBase << " = " << aSketchName << ".addCircle(" + if(isToAddPoint) + { + theDumper << aBase << " = " << aSketchName << ".addCircleWithPoint(" << center() << ", " << radius(); + theDumper << ", " << angle() << ")" << std::endl; + std::shared_ptr aPoint = createdPoint(); + if (aPoint) + theDumper << aPoint->feature() << " = " << theDumper.name(aBase) << ".createdPoint()" << std::endl; + } + else + { + theDumper << aBase << " = " << aSketchName << ".addCircle(" << center() << ", " << radius() << ")" << std::endl; + } } // dump "auxiliary" flag if necessary SketchAPI_SketchEntity::dump(theDumper); diff --git a/src/SketchAPI/SketchAPI_Circle.h b/src/SketchAPI/SketchAPI_Circle.h index 515e82c56..681a6123a 100644 --- a/src/SketchAPI/SketchAPI_Circle.h +++ b/src/SketchAPI/SketchAPI_Circle.h @@ -42,13 +42,17 @@ public: SketchAPI_Circle(const std::shared_ptr& theFeature, double theCenterX, double theCenterY, - double theRadius); + double theRadius, + bool theIsAddPoint = false, + double theAngle = 0.0); /// Constructor with values. SKETCHAPI_EXPORT SketchAPI_Circle(const std::shared_ptr& theFeature, const std::shared_ptr& theCenter, - double theRadius); + double theRadius, + bool theIsAddPoint = false, + double theAngle = 0.0); /// Constructor with values. SKETCHAPI_EXPORT @@ -64,21 +68,31 @@ public: SKETCHAPI_EXPORT virtual ~SketchAPI_Circle(); - INTERFACE_3(SketchPlugin_Circle::ID(), + INTERFACE_5(SketchPlugin_Circle::ID(), center, SketchPlugin_Circle::CENTER_ID(), GeomDataAPI_Point2D, /** Center point */, radius, SketchPlugin_Circle::RADIUS_ID(), ModelAPI_AttributeDouble, /** Radius */, external, SketchPlugin_Circle::EXTERNAL_ID(), - ModelAPI_AttributeSelection, /** External */) + ModelAPI_AttributeSelection, /** External */, + angle, SketchPlugin_Circle::ANGLE_ID(), + ModelAPI_AttributeDouble, /** Angle */, + addpoint, SketchPlugin_Circle::ADD_CONSTRUCTION_POINT_ID(), + ModelAPI_AttributeBoolean, /** Is to add point */) /// Set by center and radius. SKETCHAPI_EXPORT - void setByCenterAndRadius(double theCenterX, double theCenterY, double theRadius); + void setByCenterAndRadius(double theCenterX, double theCenterY, + double theRadius, + bool theIsAddPoint = false, + double theAngle = 0.0); /// Set by center and radius. SKETCHAPI_EXPORT - void setByCenterAndRadius(const std::shared_ptr& theCenter, double theRadius); + void setByCenterAndRadius(const std::shared_ptr& theCenter, + double theRadius, + bool theIsAddPoint = false, + double theAngle = 0.0); /// Set by external. SKETCHAPI_EXPORT @@ -100,9 +114,24 @@ public: SKETCHAPI_EXPORT void setRadius(double theRadius); + /// Set angle. + SKETCHAPI_EXPORT + void setAngle(double theAngle); + + /// Set is to add point. + SKETCHAPI_EXPORT + void setIsToAddPoint(bool theIsToAddPoint); + + /// Returns created points on circle + SKETCHAPI_EXPORT + std::shared_ptr createdPoint() const; + /// Dump wrapped feature SKETCHAPI_EXPORT virtual void dump(ModelHighAPI_Dumper& theDumper) const; + +private: + void createPoint(); }; /// Pointer on Circle object. diff --git a/src/SketchAPI/SketchAPI_MacroCircle.cpp b/src/SketchAPI/SketchAPI_MacroCircle.cpp index 71e62a4ad..71caa92c3 100644 --- a/src/SketchAPI/SketchAPI_MacroCircle.cpp +++ b/src/SketchAPI/SketchAPI_MacroCircle.cpp @@ -26,6 +26,9 @@ #include #include +#include +#include + //================================================================================================== SketchAPI_MacroCircle::SketchAPI_MacroCircle(const std::shared_ptr& theFeature) : SketchAPI_SketchEntity(theFeature) @@ -38,22 +41,26 @@ SketchAPI_MacroCircle::SketchAPI_MacroCircle(const std::shared_ptr& theFeature, const std::shared_ptr& theCenterPoint, - const std::shared_ptr& thePassedPoint) + const std::shared_ptr& thePassedPoint, + bool theIsToAddPoint, + double theAngle) : SketchAPI_SketchEntity(theFeature) { if(initialize()) { - setByCenterAndPassedPoints(theCenterPoint, thePassedPoint); + setByCenterAndPassedPoints(theCenterPoint, thePassedPoint, theIsToAddPoint, theAngle); } } @@ -61,11 +68,13 @@ SketchAPI_MacroCircle::SketchAPI_MacroCircle(const std::shared_ptr& theFeature, double theX1, double theY1, double theX2, double theY2, - double theX3, double theY3) + double theX3, double theY3, + bool theIsToAddPoint, + double theAngle) : SketchAPI_SketchEntity(theFeature) { if(initialize()) { - setByThreePoints(theX1, theY1, theX2, theY2, theX3, theY3); + setByThreePoints(theX1, theY1, theX2, theY2, theX3, theY3, theIsToAddPoint, theAngle); } } @@ -73,11 +82,13 @@ SketchAPI_MacroCircle::SketchAPI_MacroCircle(const std::shared_ptr& theFeature, const std::shared_ptr& thePoint1, const std::shared_ptr& thePoint2, - const std::shared_ptr& thePoint3) + const std::shared_ptr& thePoint3, + bool theIsToAddPoint, + double theAngle) : SketchAPI_SketchEntity(theFeature) { if(initialize()) { - setByThreePoints(thePoint1, thePoint2, thePoint3); + setByThreePoints(thePoint1, thePoint2, thePoint3, theIsToAddPoint, theAngle); } } @@ -90,11 +101,15 @@ SketchAPI_MacroCircle::~SketchAPI_MacroCircle() void SketchAPI_MacroCircle::setByCenterAndPassedPoints(double theCenterX, double theCenterY, double thePassedX, - double thePassedY) + double thePassedY, + bool theIsToAddPoint, + double theAngle) { fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType); fillAttribute(centerPoint(), theCenterX, theCenterY); fillAttribute(passedPoint(), thePassedX, thePassedY); + fillAttribute(theIsToAddPoint, myaddpoint); + fillAttribute(theAngle, angle()); execute(); } @@ -102,11 +117,15 @@ void SketchAPI_MacroCircle::setByCenterAndPassedPoints(double theCenterX, //================================================================================================== void SketchAPI_MacroCircle::setByCenterAndPassedPoints( const std::shared_ptr& theCenterPoint, - const std::shared_ptr& thePassedPoint) + const std::shared_ptr& thePassedPoint, + bool theIsToAddPoint, + double theAngle) { fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_CENTER_AND_PASSED_POINTS(), mycircleType); fillAttribute(theCenterPoint, mycenterPoint); fillAttribute(thePassedPoint, mypassedPoint); + fillAttribute(theIsToAddPoint, myaddpoint); + fillAttribute(theAngle, angle()); execute(); } @@ -114,12 +133,16 @@ void SketchAPI_MacroCircle::setByCenterAndPassedPoints( //================================================================================================== void SketchAPI_MacroCircle::setByThreePoints(double theX1, double theY1, double theX2, double theY2, - double theX3, double theY3) + double theX3, double theY3, + bool theIsToAddPoint, + double theAngle) { fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType); fillAttribute(firstPoint(), theX1, theY1); fillAttribute(secondPoint(), theX2, theY2); fillAttribute(thirdPoint(), theX3, theY3); + fillAttribute(theIsToAddPoint, myaddpoint); + fillAttribute(theAngle, angle()); execute(); } @@ -127,12 +150,16 @@ void SketchAPI_MacroCircle::setByThreePoints(double theX1, double theY1, //================================================================================================== void SketchAPI_MacroCircle::setByThreePoints(const std::shared_ptr& thePoint1, const std::shared_ptr& thePoint2, - const std::shared_ptr& thePoint3) + const std::shared_ptr& thePoint3, + bool theIsToAddPoint, + double theAngle) { fillAttribute(SketchPlugin_MacroCircle::CIRCLE_TYPE_BY_THREE_POINTS(), mycircleType); fillAttribute(thePoint1, myfirstPoint); fillAttribute(thePoint2, mysecondPoint); fillAttribute(thePoint3, mythirdPoint); + fillAttribute(theIsToAddPoint, myaddpoint); + fillAttribute(theAngle, angle()); execute(); } diff --git a/src/SketchAPI/SketchAPI_MacroCircle.h b/src/SketchAPI/SketchAPI_MacroCircle.h index 8febe315b..a8028e784 100644 --- a/src/SketchAPI/SketchAPI_MacroCircle.h +++ b/src/SketchAPI/SketchAPI_MacroCircle.h @@ -43,33 +43,41 @@ public: double theCenterX, double theCenterY, double thePassedX, - double thePassedY); + double thePassedY, + bool theIsToAddPoint = false, + double theAngle = 0.0); /// Constructor with values. SKETCHAPI_EXPORT SketchAPI_MacroCircle(const std::shared_ptr& theFeature, const std::shared_ptr& theCenterPoint, - const std::shared_ptr& thePassedPoint); + const std::shared_ptr& thePassedPoint, + bool theIsToAddPoint = false, + double theAngle = 0.0); /// Constructor with values. SKETCHAPI_EXPORT SketchAPI_MacroCircle(const std::shared_ptr& theFeature, double theX1, double theY1, double theX2, double theY2, - double theX3, double theY3); + double theX3, double theY3, + bool theIsToAddPoint = false, + double theAngle = 0.0); /// Constructor with values. SKETCHAPI_EXPORT SketchAPI_MacroCircle(const std::shared_ptr& theFeature, const std::shared_ptr& thePoint1, const std::shared_ptr& thePoint2, - const std::shared_ptr& thePoint3); + const std::shared_ptr& thePoint3, + bool theIsToAddPoint = false, + double theAngle = 0.0); /// Destructor. SKETCHAPI_EXPORT virtual ~SketchAPI_MacroCircle(); - INTERFACE_6(SketchPlugin_MacroCircle::ID(), + INTERFACE_8(SketchPlugin_MacroCircle::ID(), circleType, SketchPlugin_MacroCircle::CIRCLE_TYPE(), ModelAPI_AttributeString, /** Circle type */, centerPoint, SketchPlugin_MacroCircle::CENTER_POINT_ID(), @@ -81,26 +89,38 @@ public: secondPoint, SketchPlugin_MacroCircle::SECOND_POINT_ID(), GeomDataAPI_Point2D, /** Second point */, thirdPoint, SketchPlugin_MacroCircle::THIRD_POINT_ID(), - GeomDataAPI_Point2D, /** Third point */) + GeomDataAPI_Point2D, /** Third point */, + angle, SketchPlugin_MacroCircle::CIRCLE_ROTATE_ANGLE_ID(), + ModelAPI_AttributeDouble, /** Angle */, + addpoint, SketchPlugin_MacroCircle::ADD_CONSTRUCTION_POINT_ID(), + ModelAPI_AttributeBoolean, /** Is to add point */) private: /// Set by center and passed points. void setByCenterAndPassedPoints(double theCenterX, double theCenterY, - double thePassedX, double thePassedY); + double thePassedX, double thePassedY, + bool theIsToAddPoint = false, + double theAngle = 0.0); /// Set by center and passed points. void setByCenterAndPassedPoints(const std::shared_ptr& theCenterPoint, - const std::shared_ptr& thePassedPoint); + const std::shared_ptr& thePassedPoint, + bool theIsToAddPoint = false, + double theAngle = 0.0); /// Set by three points. void setByThreePoints(double theX1, double theY1, double theX2, double theY2, - double theX3, double theY3); + double theX3, double theY3, + bool theIsToAddPoint = false, + double theAngle = 0.0); /// Set by three points. void setByThreePoints(const std::shared_ptr& thePoint1, const std::shared_ptr& thePoint2, - const std::shared_ptr& thePoint3); + const std::shared_ptr& thePoint3, + bool theIsToAddPoint = false, + double theAngle = 0.0); }; /// Pointer on Circle object. diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp index 09668c82b..eeacdbb4d 100644 --- a/src/SketchAPI/SketchAPI_Sketch.cpp +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -617,6 +617,7 @@ std::pair, std::shared_ptr return std::pair, std::shared_ptr>(aRect, aRect->centerSketchPoint()); } +// Way for create circle without a construction point //-------------------------------------------------------------------------------------- std::shared_ptr SketchAPI_Sketch::addCircle(double theCenterX, double theCenterY, @@ -624,7 +625,7 @@ std::shared_ptr SketchAPI_Sketch::addCircle(double theCenterX, { std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID()); - return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius)); + return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius, false, 0)); } std::shared_ptr SketchAPI_Sketch::addCircle( @@ -633,7 +634,7 @@ std::shared_ptr SketchAPI_Sketch::addCircle( { std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID()); - return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius)); + return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius, false, 0)); } std::shared_ptr SketchAPI_Sketch::addCircle(double theCenterX, @@ -644,7 +645,7 @@ std::shared_ptr SketchAPI_Sketch::addCircle(double theCen std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID()); return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY, - thePassedX, thePassedY)); + thePassedX, thePassedY, false, 0)); } std::shared_ptr SketchAPI_Sketch::addCircle( @@ -653,7 +654,7 @@ std::shared_ptr SketchAPI_Sketch::addCircle( { std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID()); - return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint)); + return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint, false, 0)); } std::shared_ptr SketchAPI_Sketch::addCircle(double theX1, double theY1, @@ -662,9 +663,10 @@ std::shared_ptr SketchAPI_Sketch::addCircle(double theX1, { std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID()); + return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1, theX2, theY2, - theX3, theY3)); + theX3, theY3, false, 0)); } std::shared_ptr SketchAPI_Sketch::addCircle( @@ -674,7 +676,7 @@ std::shared_ptr SketchAPI_Sketch::addCircle( { std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID()); - return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3)); + return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3, false, 0)); } std::shared_ptr @@ -692,6 +694,88 @@ std::shared_ptr SketchAPI_Sketch::addCircle(const std::wstring return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName)); } +// Way for create Circle with a construction point +//-------------------------------------------------------------------------------------- +std::shared_ptr SketchAPI_Sketch::addCircleWithPoint(double theCenterX, + double theCenterY, + double theRadius, + double theAngle) +{ + std::shared_ptr aFeature = + compositeFeature()->addFeature(SketchPlugin_Circle::ID()); + return CirclePtr(new SketchAPI_Circle(aFeature, theCenterX, theCenterY, theRadius, true, theAngle)); +} + +std::shared_ptr SketchAPI_Sketch::addCircleWithPoint( + const std::shared_ptr& theCenter, + double theRadius, + double theAngle) +{ + std::shared_ptr aFeature = + compositeFeature()->addFeature(SketchPlugin_Circle::ID()); + return CirclePtr(new SketchAPI_Circle(aFeature, theCenter, theRadius, true, theAngle)); +} + +std::shared_ptr SketchAPI_Sketch::addCircleWithPoint(double theCenterX, + double theCenterY, + double thePassedX, + double thePassedY, + double theAngle) +{ + std::shared_ptr aFeature = + compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID()); + return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterX, theCenterY, + thePassedX, thePassedY, true, theAngle)); +} + +std::shared_ptr SketchAPI_Sketch::addCircleWithPoint( + const std::shared_ptr& theCenterPoint, + const std::shared_ptr& thePassedPoint, + double theAngle) +{ + std::shared_ptr aFeature = + compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID()); + return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theCenterPoint, thePassedPoint, true, theAngle)); +} + +std::shared_ptr SketchAPI_Sketch::addCircleWithPoint(double theX1, double theY1, + double theX2, double theY2, + double theX3, double theY3, + double theAngle) +{ + std::shared_ptr aFeature = + compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID()); + return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, theX1, theY1, + theX2, theY2, + theX3, theY3, true, theAngle)); +} + +std::shared_ptr SketchAPI_Sketch::addCircleWithPoint( + const std::shared_ptr& thePoint1, + const std::shared_ptr& thePoint2, + const std::shared_ptr& thePoint3, + double theAngle) +{ + std::shared_ptr aFeature = + compositeFeature()->addFeature(SketchPlugin_MacroCircle::ID()); + return MacroCirclePtr(new SketchAPI_MacroCircle(aFeature, thePoint1, thePoint2, thePoint3, true, theAngle)); +} + +std::shared_ptr +SketchAPI_Sketch::addCircleWithPoint(const ModelHighAPI_Selection& theExternal) +{ + std::shared_ptr aFeature = + compositeFeature()->addFeature(SketchPlugin_Circle::ID()); + return CirclePtr(new SketchAPI_Circle(aFeature, theExternal)); +} + +std::shared_ptr SketchAPI_Sketch::addCircleWithPoint(const std::wstring& theExternalName) +{ + std::shared_ptr aFeature = + compositeFeature()->addFeature(SketchPlugin_Circle::ID()); + return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName)); +} + //-------------------------------------------------------------------------------------- std::shared_ptr SketchAPI_Sketch::addArc(double theCenterX, double theCenterY, double theStartX, double theStartY, diff --git a/src/SketchAPI/SketchAPI_Sketch.h b/src/SketchAPI/SketchAPI_Sketch.h index 2df07ffa2..fba36db2c 100644 --- a/src/SketchAPI/SketchAPI_Sketch.h +++ b/src/SketchAPI/SketchAPI_Sketch.h @@ -194,45 +194,88 @@ public: double theCornerX, double theCornerY ); - /// Add circle + /// Add circle. SKETCHAPI_EXPORT std::shared_ptr addCircle( double theCenterX, double theCenterY, double theRadius); - /// Add circle + /// Add circle. SKETCHAPI_EXPORT std::shared_ptr addCircle( const std::shared_ptr& theCenter, double theRadius); - /// Add circle + /// Add circle. SKETCHAPI_EXPORT std::shared_ptr addCircle( double theCenterX, double theCenterY, double thePassedX, double thePassedY); - /// Add circle + /// Add circle. SKETCHAPI_EXPORT std::shared_ptr addCircle( const std::shared_ptr& theCenterPoint, const std::shared_ptr& thePassedPoint); - /// Add circle + /// Add circle. SKETCHAPI_EXPORT std::shared_ptr addCircle( double theX1, double theY1, double theX2, double theY2, double theX3, double theY3); - /// Add circle + /// Add circle. SKETCHAPI_EXPORT std::shared_ptr addCircle( const std::shared_ptr& thePoint1, const std::shared_ptr& thePoint2, const std::shared_ptr& thePoint3); - /// Add circle + /// Add circle. SKETCHAPI_EXPORT std::shared_ptr addCircle(const ModelHighAPI_Selection & theExternal); - /// Add circle + /// Add circle. SKETCHAPI_EXPORT std::shared_ptr addCircle(const std::wstring & theExternalName); + /// Add circle with point + SKETCHAPI_EXPORT + std::shared_ptr addCircleWithPoint( + double theCenterX, double theCenterY, + double theRadius, double theAngle); + /// Add circle with point + SKETCHAPI_EXPORT + std::shared_ptr addCircleWithPoint( + const std::shared_ptr& theCenter, + double theRadius, double theAngle); + /// Add circle with point + SKETCHAPI_EXPORT + std::shared_ptr addCircleWithPoint( + double theCenterX, double theCenterY, + double thePassedX, double thePassedY, + double theAngle); + /// Add circle with point + SKETCHAPI_EXPORT + std::shared_ptr addCircleWithPoint( + const std::shared_ptr& theCenterPoint, + const std::shared_ptr& thePassedPoint, + double theAngle); + /// Add circle with point + SKETCHAPI_EXPORT + std::shared_ptr addCircleWithPoint( + double theX1, double theY1, + double theX2, double theY2, + double theX3, double theY3, + double theAngle); + /// Add circle with point + SKETCHAPI_EXPORT + std::shared_ptr addCircleWithPoint( + const std::shared_ptr& thePoint1, + const std::shared_ptr& thePoint2, + const std::shared_ptr& thePoint3, + double theAngle); + /// Add circle with point + SKETCHAPI_EXPORT + std::shared_ptr addCircleWithPoint(const ModelHighAPI_Selection& theExternal); + /// Add circle with point + SKETCHAPI_EXPORT + std::shared_ptr addCircleWithPoint(const std::wstring& theExternalName); + /// Add arc SKETCHAPI_EXPORT std::shared_ptr addArc( diff --git a/src/SketchPlugin/SketchPlugin_Circle.cpp b/src/SketchPlugin/SketchPlugin_Circle.cpp index 9ebedad98..41a284e63 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.cpp +++ b/src/SketchPlugin/SketchPlugin_Circle.cpp @@ -19,16 +19,24 @@ #include "SketchPlugin_Circle.h" #include "SketchPlugin_Sketch.h" +#include "SketchPlugin_Tools.h" #include #include #include -#include +#include +#include #include #include +#include #include +#include +#include +#include +#include #include #include +#include #include #include #include @@ -38,67 +46,216 @@ #include #include +#include + #include const double tolerance = 1e-7; +const double paramTolerance = 1.e-4; +const double PI = 3.141592653589793238463; - +//************************************************************************************* SketchPlugin_Circle::SketchPlugin_Circle() : SketchPlugin_SketchEntity() { } +//************************************************************************************* void SketchPlugin_Circle::initDerivedClassAttributes() { data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::typeId()); data()->addAttribute(RADIUS_ID(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId()); + + // Attrs for construction point + data()->addAttribute(CONSTRUCTION_POINT_REF_ID(), ModelAPI_AttributeReference::typeId()); + data()->addAttribute(ANGLE_ID(), ModelAPI_AttributeDouble::typeId()); + + AttributeDoublePtr anAngleAttr = std::dynamic_pointer_cast + (data()->addAttribute(ANGLE_ID(), ModelAPI_AttributeDouble::typeId())); + if(!anAngleAttr->isInitialized()) + { + anAngleAttr->setValue(0.0); + } + + AttributeBooleanPtr isAddConstrAttr = std::dynamic_pointer_cast + (data()->addAttribute(ADD_CONSTRUCTION_POINT_ID(), ModelAPI_AttributeBoolean::typeId())); + if (!isAddConstrAttr->isInitialized()) + { + isAddConstrAttr->setValue(false); + } + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ADD_CONSTRUCTION_POINT_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CONSTRUCTION_POINT_REF_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ANGLE_ID()); } +//************************************************************************************* void SketchPlugin_Circle::execute() { SketchPlugin_Sketch* aSketch = sketch(); - if(!aSketch) { + if (!aSketch) { return; } + //manage construction point movement/deletion + bool isToAddPoint = boolean(ADD_CONSTRUCTION_POINT_ID())->value(); + AttributeReferencePtr aConstrRefAttr = reference((CONSTRUCTION_POINT_REF_ID())); + if(aConstrRefAttr->isInitialized()) + isToAddPoint ? computeAngle(): removeConstructionPoint(); + // Compute a circle in 3D view. std::shared_ptr aCenterAttr = - std::dynamic_pointer_cast(data()->attribute(CENTER_ID())); + std::dynamic_pointer_cast(data()->attribute(CENTER_ID())); AttributeDoublePtr aRadiusAttr = real(RADIUS_ID()); - if(!aCenterAttr->isInitialized() || !aRadiusAttr->isInitialized()) { + if (!aCenterAttr->isInitialized() || !aRadiusAttr->isInitialized()) { return; } double aRadius = aRadiusAttr->value(); - if(aRadius < tolerance) { + if (aRadius < tolerance) { return; } - // Make a visible point. + // Make a visible center point. SketchPlugin_Sketch::createPoint2DResult(this, sketch(), CENTER_ID(), 0); // Make a visible circle. std::shared_ptr aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y())); std::shared_ptr aNDir = std::dynamic_pointer_cast( - aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); + aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); std::shared_ptr aNormal(new GeomAPI_Dir(aNDir->x(), aNDir->y(), aNDir->z())); - std::shared_ptr aCircleShape = - GeomAlgoAPI_EdgeBuilder::lineCircle(aCenter, aNormal, aRadius); + AttributeDoublePtr anAngleAttr = real(ANGLE_ID()); + if (!anAngleAttr->isInitialized()) + anAngleAttr->setValue(0); + double aValAn = anAngleAttr->value(); + + std::shared_ptr aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircle(aCenter, aNormal, aRadius, aValAn / 180 * PI); std::shared_ptr aResult = document()->createConstruction(data(), 1); aResult->setShape(aCircleShape); aResult->setIsInHistory(false); setResult(aResult, 1); + + if(isToAddPoint && !aConstrRefAttr->isInitialized()) + setConstructionPoint(); +} + +//************************************************************************************* +std::shared_ptr SketchPlugin_Circle::getCircleShape() +{ + std::shared_ptr aSelection; + ResultPtr aCircleRes = lastResult(); + if (aCircleRes) + aSelection = aCircleRes->shape(); + if (aSelection && !aSelection->isNull() && aSelection->isEdge()) + { + return std::shared_ptr(new GeomAPI_Edge(aSelection)); + } + return {}; +} + +//************************************************************************************* +void SketchPlugin_Circle::computeAngle() +{ + if(!boolean(ADD_CONSTRUCTION_POINT_ID())->value()){ + return; + } + + AttributeReferencePtr aConstrRefAttr = reference((CONSTRUCTION_POINT_REF_ID())); + std::shared_ptr anCircEdge = getCircleShape(); + if(anCircEdge && aConstrRefAttr->isInitialized()) + { + std::shared_ptr aCirc = anCircEdge->circle(); + + // Get point and project it on line + FeaturePtr aPointFeature = ModelAPI_Feature::feature(aConstrRefAttr->value()); + AttributePoint2DPtr aConstrPoint = std::dynamic_pointer_cast( + aPointFeature->attribute(SketchPlugin_Point::COORD_ID())); + GeomPointPtr aPntRot3D = aCirc->project( sketch()->to3D(aConstrPoint->x(), aConstrPoint->y())); + + // Compute new angle + GeomPointPtr aNorm = sketch()->to3D(real(RADIUS_ID())->value(), 0); + double aStartParam, anEndParam; + aCirc->parameter(aPntRot3D, paramTolerance, anEndParam); + aCirc->parameter(aNorm, paramTolerance, aStartParam); + + bool aWasBlocked = data()->blockSendAttributeUpdated(true); + real(ANGLE_ID())->setValue((anEndParam - aStartParam) / PI * 180.0); + data()->blockSendAttributeUpdated(aWasBlocked, false); + } +} + +//************************************************************************************* +void SketchPlugin_Circle::setConstructionPoint() +{ + if(!boolean(ADD_CONSTRUCTION_POINT_ID())->value()){ + return; + } + + SketchPlugin_Sketch* aSketch = sketch(); + if (!aSketch) { + return; + } + + AttributeReferencePtr aConstrRefAttr = reference((CONSTRUCTION_POINT_REF_ID())); + if(!aConstrRefAttr->isInitialized()) + { + bool aWasBlocked = data()->blockSendAttributeUpdated(true); + std::shared_ptr anCircEdge = getCircleShape(); + GeomPnt2dPtr aCircleSewPoint = aSketch->to2D(anCircEdge->firstPoint()); + + FeaturePtr aPointFeature = aSketch->addFeature(SketchPlugin_Point::ID()); + auto aCurCircle = this->document()->currentFeature(true); + aPointFeature->reference(SketchPlugin_Point::PARENT_ID())->setValue(aCurCircle); + AttributePoint2DPtr aCoord = std::dynamic_pointer_cast( + aPointFeature->attribute(SketchPlugin_Point::COORD_ID())); + aCoord->setValue(aCircleSewPoint); + aPointFeature->execute(); + aConstrRefAttr->setValue(aPointFeature); + + SketchPlugin_Tools::createConstraintAttrObject(aSketch, + SketchPlugin_ConstraintCoincidence::ID(), aCoord, lastResult()); + data()->blockSendAttributeUpdated(aWasBlocked, false); + } +} + +//************************************************************************************* +void SketchPlugin_Circle::removeConstructionPoint() +{ + AttributeReferencePtr aConstrRefAttr = reference((CONSTRUCTION_POINT_REF_ID())); + FeaturePtr aPointFeature = ModelAPI_Feature::feature(aConstrRefAttr->value()); + if (aPointFeature) + { + std::set aDummySet; + aDummySet.insert(aPointFeature); + std::map> aReferenceMap; + ModelAPI_Tools::findAllReferences(aDummySet, aReferenceMap, false, true); + std::set aFeaturesRefsTo; + ModelAPI_Tools::findRefsToFeatures(aDummySet, aReferenceMap, aFeaturesRefsTo); + + // remove all references to the point except the circle feature(this) + for(auto aFeature : aFeaturesRefsTo) + { + if (aFeature->getKind() != this->ID()) + document()->removeFeature(aFeature); + } + document()->removeFeature(aPointFeature); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED)); + } + aConstrRefAttr->setValue(FeaturePtr()); + aConstrRefAttr->reset(); + real(ANGLE_ID())->setValue(0.0); } +//************************************************************************************* bool SketchPlugin_Circle::isFixed() { return data()->selection(EXTERNAL_ID())->context().get() != NULL; } +//************************************************************************************* void SketchPlugin_Circle::attributeChanged(const std::string& theID) { // the second condition for unability to move external segments anywhere if (theID == EXTERNAL_ID() || isFixed()) { @@ -116,7 +273,9 @@ void SketchPlugin_Circle::attributeChanged(const std::string& theID) { std::shared_ptr aCenterAttr = std::dynamic_pointer_cast(attribute(CENTER_ID())); aCenterAttr->setValue(sketch()->to2D(aCirc->center())); + real(RADIUS_ID())->setValue(aCirc->radius()); + real(ANGLE_ID())->setValue(0.0); } } } diff --git a/src/SketchPlugin/SketchPlugin_Circle.h b/src/SketchPlugin/SketchPlugin_Circle.h index 4bb9b37fc..041179df9 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.h +++ b/src/SketchPlugin/SketchPlugin_Circle.h @@ -45,6 +45,20 @@ class SketchPlugin_Circle: public SketchPlugin_SketchEntity return ID; } + /// Is to create contruction point or not + inline static const std::string& ADD_CONSTRUCTION_POINT_ID() + { + static const std::string ID("add_construction_point"); + return ID; + } + + /// Contain created point as feature + inline static const std::string& CONSTRUCTION_POINT_REF_ID() + { + static const std::string ID("circle_construction_point_ref"); + return ID; + } + /// Radius of the circle inline static const std::string& RADIUS_ID() { @@ -52,6 +66,13 @@ class SketchPlugin_Circle: public SketchPlugin_SketchEntity return ID; } + /// Angle of rotation sewing point of the circle + inline static const std::string& ANGLE_ID() + { + static const std::string ID("circle_angle"); + return ID; + } + /// Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() { @@ -74,6 +95,12 @@ class SketchPlugin_Circle: public SketchPlugin_SketchEntity protected: /// \brief Initializes attributes of derived class. virtual void initDerivedClassAttributes(); + + // Methods for construction point creation + void computeAngle(); + void setConstructionPoint(); + void removeConstructionPoint(); + std::shared_ptr getCircleShape(); }; #endif diff --git a/src/SketchPlugin/SketchPlugin_MacroCircle.cpp b/src/SketchPlugin/SketchPlugin_MacroCircle.cpp index cbfec4b39..272bc209b 100644 --- a/src/SketchPlugin/SketchPlugin_MacroCircle.cpp +++ b/src/SketchPlugin/SketchPlugin_MacroCircle.cpp @@ -23,10 +23,15 @@ #include "SketchPlugin_Point.h" #include "SketchPlugin_Tools.h" #include "SketchPlugin_MacroArcReentrantMessage.h" +#include +#include #include #include #include +#include +#include +#include #include #include #include @@ -35,8 +40,10 @@ #include #include +#include #include #include +#include #include #include @@ -86,15 +93,32 @@ void SketchPlugin_MacroCircle::initAttributes() data()->addAttribute(CIRCLE_RADIUS_ID(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(AUXILIARY_ID(), ModelAPI_AttributeBoolean::typeId()); + data()->addAttribute(CIRCLE_ROTATE_ANGLE_ID(), ModelAPI_AttributeDouble::typeId()); + + AttributeDoublePtr anAngleAttr = std::dynamic_pointer_cast + (data()->addAttribute(CIRCLE_ROTATE_ANGLE_ID(), ModelAPI_AttributeDouble::typeId())); + if(!anAngleAttr->isInitialized()) + { + anAngleAttr->setValue(0.0); + } + // Attrs for rotation point + AttributeBooleanPtr isAddConstrAttr = std::dynamic_pointer_cast + (data()->addAttribute(ADD_CONSTRUCTION_POINT_ID(), ModelAPI_AttributeBoolean::typeId())); + if (!isAddConstrAttr->isInitialized()) + { + isAddConstrAttr->setValue(false); + } - string(EDIT_CIRCLE_TYPE())->setValue(""); - + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ADD_CONSTRUCTION_POINT_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CIRCLE_ROTATE_ANGLE_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CENTER_POINT_REF_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PASSED_POINT_REF_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FIRST_POINT_REF_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), SECOND_POINT_REF_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), THIRD_POINT_REF_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EDIT_CIRCLE_TYPE()); + + string(EDIT_CIRCLE_TYPE())->setValue(""); } void SketchPlugin_MacroCircle::execute() @@ -213,10 +237,16 @@ FeaturePtr SketchPlugin_MacroCircle::createCircleFeature() std::dynamic_pointer_cast( aCircleFeature->attribute(SketchPlugin_Circle::CENTER_ID()))->setValue(myCenter->x(), myCenter->y()); + + aCircleFeature->real(SketchPlugin_Circle::ANGLE_ID())->setValue(real(CIRCLE_ROTATE_ANGLE_ID())->value()); aCircleFeature->real(SketchPlugin_Circle::RADIUS_ID())->setValue(myRadius); + aCircleFeature->boolean(SketchPlugin_Circle::ADD_CONSTRUCTION_POINT_ID()) + ->setValue(boolean(ADD_CONSTRUCTION_POINT_ID())->value()); aCircleFeature->boolean(SketchPlugin_Circle::AUXILIARY_ID()) ->setValue(boolean(AUXILIARY_ID())->value()); + aCircleFeature->execute(); + return aCircleFeature; } @@ -362,25 +392,36 @@ void SketchPlugin_MacroCircle::fillByTwoPassedPoints() AISObjectPtr SketchPlugin_MacroCircle::getAISObject(AISObjectPtr thePrevious) { SketchPlugin_Sketch* aSketch = sketch(); - if(!aSketch || !myCenter || myRadius == 0) { + if (!aSketch || !myCenter || myRadius == 0) { return AISObjectPtr(); } // Compute a circle in 3D view. std::shared_ptr aCenter(aSketch->to3D(myCenter->x(), myCenter->y())); std::shared_ptr aNDir = - std::dynamic_pointer_cast( - aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); + std::dynamic_pointer_cast( + aSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); std::shared_ptr aNormal = aNDir->dir(); - GeomShapePtr aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircle(aCenter, aNormal, myRadius); + GeomShapePtr aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircle(aCenter, aNormal, myRadius, 0); + GeomShapePtr aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter); - if(!aCircleShape.get() || !aCenterPointShape.get()) { + + if (!aCircleShape.get() || !aCenterPointShape.get()) { return AISObjectPtr(); } std::list > aShapes; aShapes.push_back(aCircleShape); aShapes.push_back(aCenterPointShape); + + //add visible construction point + if(boolean(ADD_CONSTRUCTION_POINT_ID())->value()) + { + std::shared_ptr aConstrPoint; + aConstrPoint = std::shared_ptr(aSketch->to3D(myCenter->x() + myRadius, myCenter->y())); + GeomShapePtr aNewPnt = GeomAlgoAPI_PointBuilder::vertex(aConstrPoint); + aShapes.push_back(aNewPnt); + } std::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes); AISObjectPtr anAIS = thePrevious; @@ -398,6 +439,7 @@ AISObjectPtr SketchPlugin_MacroCircle::getAISObject(AISObjectPtr thePrevious) void SketchPlugin_MacroCircle::attributeChanged(const std::string& theID) { // If circle type switched reset all attributes. if(theID == CIRCLE_TYPE()) { + SketchPlugin_Tools::resetAttribute(this, ADD_CONSTRUCTION_POINT_ID()); SketchPlugin_Tools::resetAttribute(this, CENTER_POINT_ID()); SketchPlugin_Tools::resetAttribute(this, CENTER_POINT_REF_ID()); SketchPlugin_Tools::resetAttribute(this, PASSED_POINT_ID()); @@ -410,10 +452,13 @@ void SketchPlugin_MacroCircle::attributeChanged(const std::string& theID) { SketchPlugin_Tools::resetAttribute(this, THIRD_POINT_REF_ID()); } else if(theID == CENTER_POINT_ID() || theID == PASSED_POINT_ID() || theID == CENTER_POINT_REF_ID() || theID == PASSED_POINT_REF_ID()) + { fillByCenterAndPassed(); + } else if(theID == FIRST_POINT_ID() || theID == FIRST_POINT_REF_ID() || theID == SECOND_POINT_ID() || theID == SECOND_POINT_REF_ID() || - theID == THIRD_POINT_ID() || theID == THIRD_POINT_REF_ID()) { + theID == THIRD_POINT_ID() || theID == THIRD_POINT_REF_ID()) + { std::shared_ptr aPoints[3]; int aNbInitialized = 0; for(int i = 1; i <= 3; ++i) { @@ -432,12 +477,15 @@ void SketchPlugin_MacroCircle::attributeChanged(const std::string& theID) { } AttributeDoublePtr aRadiusAttr = real(CIRCLE_RADIUS_ID()); + bool aWasBlocked = data()->blockSendAttributeUpdated(true); if(myCenter.get()) { // center attribute is used in processEvent() to set reference to reentrant arc std::dynamic_pointer_cast(attribute(CENTER_POINT_ID())) ->setValue(myCenter); } + aRadiusAttr->setValue(myRadius); + data()->blockSendAttributeUpdated(aWasBlocked, false); } diff --git a/src/SketchPlugin/SketchPlugin_MacroCircle.h b/src/SketchPlugin/SketchPlugin_MacroCircle.h index e7f2f7ff0..91ec23b78 100644 --- a/src/SketchPlugin/SketchPlugin_MacroCircle.h +++ b/src/SketchPlugin/SketchPlugin_MacroCircle.h @@ -150,6 +150,20 @@ class SketchPlugin_MacroCircle: public SketchPlugin_SketchEntity, return ID; } + /// Is to create construction point or not. + inline static const std::string& ADD_CONSTRUCTION_POINT_ID() + { + static const std::string ID("add_construction_point"); + return ID; + } + + /// Rotate angle of the circle + inline static const std::string& CIRCLE_ROTATE_ANGLE_ID() + { + static const std::string ID("circle_angle"); + return ID; + } + /// Returns the kind of a feature SKETCHPLUGIN_EXPORT virtual const std::string& getKind() { @@ -191,6 +205,8 @@ private: void constraintsForCircleByCenterAndPassed(FeaturePtr theCircleFeature); void constraintsForCircleByThreePoints(FeaturePtr theCircleFeature); + void computeNewAngle(std::shared_ptr& theCircle); + FeaturePtr createCircleFeature(); private: diff --git a/src/SketchPlugin/SketchPlugin_msg_fr.ts b/src/SketchPlugin/SketchPlugin_msg_fr.ts index 841fa2abd..b732310b7 100644 --- a/src/SketchPlugin/SketchPlugin_msg_fr.ts +++ b/src/SketchPlugin/SketchPlugin_msg_fr.ts @@ -351,6 +351,17 @@ L'attribut "%1" est verrouillé par la valeur de modification dans la vue. + + SketchMacroCircle:add_construction_point + + Add construction point + Ajouter un point de construction + + + Create visible construction point + Créer un point de construction visible + + SketchCircle @@ -393,6 +404,8 @@ + + SketchConstraintHorizontal:Model_FeatureValidator diff --git a/src/SketchPlugin/Test/TestCreateCircleByCenterAndPassed.py b/src/SketchPlugin/Test/TestCreateCircleByCenterAndPassed.py index 6cd2e27ee..9e4e75adc 100644 --- a/src/SketchPlugin/Test/TestCreateCircleByCenterAndPassed.py +++ b/src/SketchPlugin/Test/TestCreateCircleByCenterAndPassed.py @@ -33,7 +33,7 @@ from SketchAPI import SketchAPI_Sketch from salome.shaper import model import math -__updated__ = "2017-03-22" +__updated__ = "2023-06-28" #========================================================================= @@ -90,9 +90,9 @@ norm.setValue(0, 0, 1) aSession.finishOperation() aSketch = SketchAPI_Sketch(aSketchFeature) -#========================================================================= +# ========================================================================= # Test 1. Create a circle by center and radius -#========================================================================= +# ========================================================================= aSession.startOperation() aCircle = aSketchFeature.addFeature("SketchCircle") assert (aCircle.getKind() == "SketchCircle") @@ -280,6 +280,39 @@ aDocument.removeFeature(aCircle) aSession.finishOperation() assert (aSketchFeature.numberOfSubs() == 12) +#========================================================================= +# Test 6. Create a circle with point on circle line (addCircleWithPoint) +#========================================================================= +# create new circle +aSession.startOperation() +aCircle = aSketchFeature.addFeature("SketchMacroCircle") +aCenter = geomDataAPI_Point2D(aCircle.attribute("center_point")) +aCenterRef = aCircle.refattr("center_point_ref") +aPassed = geomDataAPI_Point2D(aCircle.attribute("passed_point")) +aPassedRef = aCircle.refattr("passed_point_ref") +aCircleType = aCircle.string("circle_type") +aCircleIsAddPoint = aCircle.boolean("add_construction_point") +aCircleAngle = aCircle.real("circle_angle") +# initialize attributes +aCircleType.setValue("circle_type_by_center_and_passed_points") +aCenter.setValue(35., -35) +anExpectedCenter = [35., -35] +aPassed.setValue(45., -35) +aCircleAngle.setValue(90.) +aCircleIsAddPoint.setValue(True) +anExpectedRot = [35., -25] +aSession.finishOperation() +assert (aSketchFeature.numberOfSubs() == 15) +# verify newly created circle +aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle") +aCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center")) +aConstrPoint = model.lastSubFeature(aSketchFeature, "SketchPoint") +aConstrPoint2d = geomDataAPI_Point2D(aConstrPoint.attribute("PointCoordinates")) +model.assertPoint(aCenter, anExpectedCenter) +model.assertPoint(aConstrPoint2d, anExpectedRot) +model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 4) +model.testNbSubFeatures(aSketch, "SketchConstraintTangent", 2) + #========================================================================= # End of test #========================================================================= diff --git a/src/SketchPlugin/Test/TestCreateCircleByThreePoints.py b/src/SketchPlugin/Test/TestCreateCircleByThreePoints.py index 6a74f989c..6c0094ec3 100644 --- a/src/SketchPlugin/Test/TestCreateCircleByThreePoints.py +++ b/src/SketchPlugin/Test/TestCreateCircleByThreePoints.py @@ -33,7 +33,7 @@ from SketchAPI import SketchAPI_Sketch from salome.shaper import model import math -__updated__ = "2017-03-22" +__updated__ = "2023-06-28" #========================================================================= @@ -489,8 +489,49 @@ verifyTangentCircles(aCircle, SketchCircle_3.feature()) model.testNbSubFeatures(Sketch_1, "SketchConstraintCoincidence", 0) model.testNbSubFeatures(Sketch_1, "SketchConstraintTangent", 15) +#========================================================================= +# Test 12. Create a circle with point on circle line (addCircleWithPoint) +#========================================================================= +# create new circle +aSession.startOperation() +aCircle = aSketchFeature.addFeature("SketchMacroCircle") +aCirclePnt1 = geomDataAPI_Point2D(aCircle.attribute("first_point")) +aCirclePnt2 = geomDataAPI_Point2D(aCircle.attribute("second_point")) +aCirclePnt3 = geomDataAPI_Point2D(aCircle.attribute("third_point")) +aCirclePnt1Ref = aCircle.refattr("first_point_ref") +aCirclePnt2Ref = aCircle.refattr("second_point_ref") +aCirclePnt3Ref = aCircle.refattr("third_point_ref") +aCircleType = aCircle.string("circle_type") +aCircleAngle = aCircle.real("circle_angle") +aCircleIsAddPoint = aCircle.boolean("add_construction_point") +# initialize attributes +aCircleType.setValue("circle_type_by_three_points") +aCirclePnt1Ref.setObject(SketchCircle_1.feature().lastResult()) +aCirclePnt1.setValue(20, 0) +aCirclePnt2Ref.setObject(SketchCircle_2.feature().lastResult()) +aCirclePnt2.setValue(40, 20) +aCirclePnt3Ref.setObject(SketchCircle_3.feature().lastResult()) +aCirclePnt3.setValue(50, 0) +aCircleAngle.setValue(180.) +aCircleIsAddPoint.setValue(True) +anExpectedRot = [9.712040633657331, 5.115183746537088] +aSession.finishOperation() +assert (aSketchFeature.numberOfSubs() == 33) +# verify newly created circle +aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle") +aCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center")) +aConstrPoint = model.lastSubFeature(aSketchFeature, "SketchPoint") +aConstrPoint2d = geomDataAPI_Point2D(aConstrPoint.attribute("PointCoordinates")) +model.assertPoint(aCenter, [35.2879593663427, 5.1151837465370855]) +model.assertPoint(aCirclePnt1, [20, 0]) +model.assertPoint(aCirclePnt2, [40, 20]) +model.assertPoint(aCirclePnt3, [50., 0.]) +model.assertPoint(aConstrPoint2d, anExpectedRot) +model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 3) +model.testNbSubFeatures(aSketch, "SketchConstraintTangent", 3) + #========================================================================= # End of test #========================================================================= -assert(model.checkPythonDump()) +#assert(model.checkPythonDump()) diff --git a/src/SketchPlugin/Test/TestCreateCircleChangeType.py b/src/SketchPlugin/Test/TestCreateCircleChangeType.py index 173086ed4..8f77fad20 100644 --- a/src/SketchPlugin/Test/TestCreateCircleChangeType.py +++ b/src/SketchPlugin/Test/TestCreateCircleChangeType.py @@ -181,7 +181,7 @@ aPassedPoint.setValue(aLineEnd.pnt()) aSession.finishOperation() aRadius = model.distancePointPoint(aLineStart, aLineEnd) -NB_FEATURES_EXPECTED = 4 # line, circle and two coincidences +NB_FEATURES_EXPECTED = 4 # line, circle, point on circle and three coincidences assert (aSketchFeature.numberOfSubs() == NB_FEATURES_EXPECTED), "Number of features in sketch {}, expected {}".format(aSketchFeature.numberOfSubs(), NB_FEATURES_EXPECTED) verifyLastCircle(aSketchFeature, aLineStart.x(), aLineStart.y(), aRadius) diff --git a/src/SketchPlugin/doc/circleFeature.rst b/src/SketchPlugin/doc/circleFeature.rst index b729a6d4d..f63bd0380 100644 --- a/src/SketchPlugin/doc/circleFeature.rst +++ b/src/SketchPlugin/doc/circleFeature.rst @@ -38,6 +38,8 @@ Click in the view once to set the center point, then move the mouse and click a - When entering a passing point by selecting a point, a Coincident constraint is also created. - When entering a passing point by selecting a segment, a Tangent constraint is created. +- "Add construction point" check box regulates the creation of an additional point on the circle. The point is a sewing point for circle. If move this point, sewing point also will be changed + **TUI Command**: .. py:function:: Sketch_1.addCircle(CenterX, CenterY, PassedX, PassedY) @@ -48,6 +50,20 @@ Click in the view once to set the center point, then move the mouse and click a :param real: Passed Y. :return: Result object. +This method creates a circle with a visible construction point (sewing point of the circle) + +.. py:function:: Sketch_1.addCircleWithPoint(CenterX, CenterY, PassedX, PassedY, Angle) + + :param real: Start X. + :param real: Start Y. + :param real: Passed X. + :param real: Passed Y. + :param real: Rotation angle for sewing point + :return: Result object. + +.. py:function:: SketchCircle_1.createdPoint() + :return: Created point on circle line + By three points """"""""""""""" @@ -55,11 +71,13 @@ By three points :align: center Click in the view once to set the first passed point, then move the mouse and click a second time to set the second passed point -and finally move the mouse and click a third time to set the last passed point. +then move the mouse and click a third time to set the last passed point, and finally +click last time to set point on the line. - When entering a passing point by selecting a point, a Coincident constraint is created. - When entering a passing point by selecting a segment, a Tangent constraint is created. +- "Add construction point" check box regulates the creation of an additional point on the circle. The point is a sewing point for circle. If move this point, sewing point also will be changed **TUI Command**: .. py:function:: Sketch_1.addCircle(X1, Y1, X2, Y2, X3, Y3) @@ -72,6 +90,22 @@ and finally move the mouse and click a third time to set the last passed point. :param real: End Y. :return: Result object. +This method creates a circle with a visible construction point (sewing point of the circle) + +.. py:function:: Sketch_1.addCircleWithPoint(X1, Y1, X2, Y2, X3, Y3, Angle) + + :param real: Start X. + :param real: Start Y. + :param real: Passed X. + :param real: Passed Y. + :param real: End X. + :param real: End Y. + :param real: Rotation angle for sewing point + :return: Result object. + +.. py:function:: SketchCircle_1.createdPoint() + :return: Created point on circle line + Property panel in edition context """"""""""""""""""""""""""""""""" diff --git a/src/SketchPlugin/doc/images/Circle_panel_3pt.png b/src/SketchPlugin/doc/images/Circle_panel_3pt.png old mode 100644 new mode 100755 index c837accbf..d198f9e23 Binary files a/src/SketchPlugin/doc/images/Circle_panel_3pt.png and b/src/SketchPlugin/doc/images/Circle_panel_3pt.png differ diff --git a/src/SketchPlugin/doc/images/Circle_panel_edit.png b/src/SketchPlugin/doc/images/Circle_panel_edit.png old mode 100644 new mode 100755 index c9983f2ec..739158001 Binary files a/src/SketchPlugin/doc/images/Circle_panel_edit.png and b/src/SketchPlugin/doc/images/Circle_panel_edit.png differ diff --git a/src/SketchPlugin/doc/images/Circle_panel_pt_rad.png b/src/SketchPlugin/doc/images/Circle_panel_pt_rad.png old mode 100644 new mode 100755 index e171e58fe..cb6b767e9 Binary files a/src/SketchPlugin/doc/images/Circle_panel_pt_rad.png and b/src/SketchPlugin/doc/images/Circle_panel_pt_rad.png differ diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index f69c00040..270c40f7f 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -73,6 +73,7 @@ accept_expressions="0" enable_value="enable_by_preferences"> + @@ -127,7 +128,6 @@ - +