From b200c0c98cb5b967a20ad42af6b7b8d807e6922e Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 3 Apr 2017 09:11:27 +0300 Subject: [PATCH] Issues #2027, #2024, #2063, #2067: reentrant message to fill new operation by result of the previous one. Issue #2064(PartSet_OperationPrs) --- .../SketchPlugin_ConstraintCoincidence.cpp | 29 +++++++++++++++++++ .../SketchPlugin_ConstraintCoincidence.h | 8 +++++ 2 files changed, 37 insertions(+) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp index 8d2ab687e..5fa7f0f07 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.cpp @@ -11,11 +11,14 @@ #include #include +#include #include #include #include +#include + SketchPlugin_ConstraintCoincidence::SketchPlugin_ConstraintCoincidence() { } @@ -96,3 +99,29 @@ AttributePoint2DPtr SketchPlugin_ConstraintCoincidence::getPoint(const FeaturePt SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID()); return aPoint; } + +void SketchPlugin_ConstraintCoincidence::createCoincidenceFeature(SketchPlugin_Sketch* theSketch, + const std::shared_ptr& thePoint1, + const std::shared_ptr& thePoint2) +{ + FeaturePtr aFeature; + if (theSketch) { + aFeature = theSketch->addFeature(SketchPlugin_ConstraintCoincidence::ID()); + } else { + std::shared_ptr aDoc = theSketch->document(); + aFeature = aDoc->addFeature(SketchPlugin_ConstraintCoincidence::ID()); + } + + std::shared_ptr aData = aFeature->data(); + + std::shared_ptr aRef1 = std::dynamic_pointer_cast< + ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A())); + aRef1->setAttr(thePoint1); + + std::shared_ptr aRef2 = std::dynamic_pointer_cast< + ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_B())); + aRef2->setAttr(thePoint2); + + // we need to flush created signal in order to coincidence is processed by solver + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED)); +} diff --git a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h index 4990259e2..c41358c3c 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintCoincidence.h @@ -52,6 +52,14 @@ class SketchPlugin_ConstraintCoincidence : public SketchPlugin_ConstraintBase static FeaturePtr findCoincidenceFeature(const FeaturePtr& theFeature1, const FeaturePtr& theFeature2); + /// Creates a constraint on two points + /// \param theSketch a sketch feature + /// \param thePoint1 the first point + /// \param thePoint2 the second point + static void createCoincidenceFeature(SketchPlugin_Sketch* theSketch, + const std::shared_ptr& thePoint1, + const std::shared_ptr& thePoint2); + /// Returns point of coincidence feature /// \param theFeature a coincidence feature /// \return point 2d attribute. Coincidence always has at least one point 2d attribute -- 2.39.2