From 8b831604b85dd4e1a616c130f9ec5d638a1898ed Mon Sep 17 00:00:00 2001 From: azv Date: Thu, 12 Dec 2019 13:37:52 +0300 Subject: [PATCH] Task 5.1.3 Sketcher: angle dimension (issue #3061) Make Angle constraint reentant. --- .../SketchPlugin_ConstraintAngle.cpp | 24 +++++++++++++++++++ .../SketchPlugin_ConstraintAngle.h | 11 +++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp index 890df386f..10d27ee1c 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -130,6 +131,11 @@ void SketchPlugin_ConstraintAngle::execute() GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); if(!aFlyOutAttr->isInitialized()) compute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()); + + static Events_ID anId = ModelAPI_EventReentrantMessage::eventId(); + std::shared_ptr aMessage( + new ModelAPI_EventReentrantMessage(anId, this)); + Events_Loop::loop()->send(aMessage); } AISObjectPtr SketchPlugin_ConstraintAngle::getAISObject(AISObjectPtr thePrevious) @@ -144,6 +150,24 @@ AISObjectPtr SketchPlugin_ConstraintAngle::getAISObject(AISObjectPtr thePrevious return anAIS; } +// LCOV_EXCL_START +std::string SketchPlugin_ConstraintAngle::processEvent( + const std::shared_ptr& theMessage) +{ + std::string aFilledAttributeName; + + std::shared_ptr aReentrantMessage = + std::dynamic_pointer_cast(theMessage); + if (aReentrantMessage.get()) { + aFilledAttributeName = ENTITY_A(); + refattr(ENTITY_A())->setObject(aReentrantMessage->selectedObject()); + std::dynamic_pointer_cast(attribute(SELECTED_FIRST_POINT_ID())) + ->setValue(aReentrantMessage->clickedPoint()); + } + return aFilledAttributeName; +} +// LCOV_EXCL_STOP + void SketchPlugin_ConstraintAngle::attributeChanged(const std::string& theID) { if (myFlyoutUpdate) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintAngle.h b/src/SketchPlugin/SketchPlugin_ConstraintAngle.h index bc13f731d..9305e1c20 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintAngle.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintAngle.h @@ -21,9 +21,11 @@ #define SketchPlugin_ConstraintAngle_H_ #include "SketchPlugin.h" -#include +#include "SketchPlugin_Sketch.h" #include "SketchPlugin_ConstraintBase.h" +#include + /** \class SketchPlugin_ConstraintAngle * \ingroup Plugins * \brief Feature for creation of a new constraint fix angle between two lines @@ -31,7 +33,8 @@ * This constraint has two attributes: * SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B() */ -class SketchPlugin_ConstraintAngle : public SketchPlugin_ConstraintBase +class SketchPlugin_ConstraintAngle : public SketchPlugin_ConstraintBase, + public ModelAPI_IReentrant { public: /// Angle constraint kind @@ -135,6 +138,10 @@ public: /// Returns the AIS preview SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); + /// Apply information of the message to current object. + /// It fills selected point and the first object. + virtual std::string processEvent(const std::shared_ptr& theMessage); + /// \brief Use plugin manager for features creation SketchPlugin_ConstraintAngle(); -- 2.39.2