From c1383b05a42a6c61259e0cd847587c02e4a6fbbd Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 13 May 2014 14:56:36 +0400 Subject: [PATCH] refs #30 - Sketch base GUI: create, draw lines Create constraint on point --- src/PartSet/PartSet_OperationSketchLine.cpp | 25 +++++++++++++++++++++ src/PartSet/PartSet_OperationSketchLine.h | 6 +++++ src/SketchPlugin/SketchPlugin_Plugin.cpp | 4 ++++ src/SketchPlugin/plugin-Sketch.xml | 2 +- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index 7449f99ad..9235348a7 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -10,6 +10,9 @@ #include #include #include +#include + +#include #include #include @@ -193,12 +196,34 @@ boost::shared_ptr PartSet_OperationSketchLine::createFeature() boost::shared_ptr aPoint = boost::dynamic_pointer_cast (aData->attribute(LINE_ATTR_START)); aPoint->setValue(myInitPoint->x(), myInitPoint->y()); + + //createConstraint(myInitPoint, aPoint); } emit featureConstructed(aNewFeature, FM_Activation); return aNewFeature; } +void PartSet_OperationSketchLine::createConstraint(boost::shared_ptr thePoint1, + boost::shared_ptr thePoint2) +{ + boost::shared_ptr aDoc = document(); + boost::shared_ptr aFeature = aDoc->addFeature("SketchConstraintCoincidence"); + + boost::shared_ptr aData = aFeature->data(); + + boost::shared_ptr aRef1 = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + aRef1->setAttr(thePoint1); + + boost::shared_ptr aRef2 = + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_B)); + aRef2->setAttr(thePoint2); + + if (aFeature) // TODO: generate an error if feature was not created + aFeature->execute(); +} + void PartSet_OperationSketchLine::getLinePoint(boost::shared_ptr theFeature, const std::string& theAttribute, double& theX, double& theY) diff --git a/src/PartSet/PartSet_OperationSketchLine.h b/src/PartSet/PartSet_OperationSketchLine.h index 498f3ca4b..d92224aaa 100644 --- a/src/PartSet/PartSet_OperationSketchLine.h +++ b/src/PartSet/PartSet_OperationSketchLine.h @@ -82,6 +82,12 @@ protected: /// \returns the created feature virtual boost::shared_ptr createFeature(); + /// Creates a constraint on two points + /// \param thePoint1 the first point + /// \param thePoint1 the second point + void createConstraint(boost::shared_ptr thePoint1, + boost::shared_ptr thePoint2); + protected: /// \brief Get the line point 2d coordinates. /// \param theFeature the line feature diff --git a/src/SketchPlugin/SketchPlugin_Plugin.cpp b/src/SketchPlugin/SketchPlugin_Plugin.cpp index ab95647ee..bef72b89d 100644 --- a/src/SketchPlugin/SketchPlugin_Plugin.cpp +++ b/src/SketchPlugin/SketchPlugin_Plugin.cpp @@ -1,6 +1,7 @@ #include "SketchPlugin_Plugin.h" #include "SketchPlugin_Sketch.h" #include "SketchPlugin_Line.h" +#include "SketchPlugin_ConstraintCoincidence.h" #include #include @@ -23,6 +24,9 @@ boost::shared_ptr SketchPlugin_Plugin::createFeature(string th else if (theFeatureID == "SketchLine") { return boost::shared_ptr(new SketchPlugin_Line); } + else if (theFeatureID == "SketchConstraintCoincidence") { + return boost::shared_ptr(new SketchPlugin_ConstraintCoincidence); + } // feature of such kind is not found return boost::shared_ptr(); } diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index f90c4e124..29cf61b04 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -10,7 +10,7 @@ - + -- 2.39.2