#include <GeomDataAPI_Point2D.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
+#include <ModelAPI_AttributeRefAttr.h>
+
+#include <SketchPlugin_Constraint.h>
#include <Geom_Line.hxx>
#include <gp_Lin.hxx>
boost::shared_ptr<GeomDataAPI_Point2D> aPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>
(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<GeomDataAPI_Point2D> thePoint1,
+ boost::shared_ptr<GeomDataAPI_Point2D> thePoint2)
+{
+ boost::shared_ptr<ModelAPI_Document> aDoc = document();
+ boost::shared_ptr<ModelAPI_Feature> aFeature = aDoc->addFeature("SketchConstraintCoincidence");
+
+ boost::shared_ptr<ModelAPI_Data> aData = aFeature->data();
+
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef1 =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+ aRef1->setAttr(thePoint1);
+
+ boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef2 =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(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<ModelAPI_Feature> theFeature,
const std::string& theAttribute,
double& theX, double& theY)
/// \returns the created feature
virtual boost::shared_ptr<ModelAPI_Feature> createFeature();
+ /// Creates a constraint on two points
+ /// \param thePoint1 the first point
+ /// \param thePoint1 the second point
+ void createConstraint(boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
+ boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
+
protected:
/// \brief Get the line point 2d coordinates.
/// \param theFeature the line feature
#include "SketchPlugin_Plugin.h"
#include "SketchPlugin_Sketch.h"
#include "SketchPlugin_Line.h"
+#include "SketchPlugin_ConstraintCoincidence.h"
#include <ModelAPI_PluginManager.h>
#include <ModelAPI_Document.h>
else if (theFeatureID == "SketchLine") {
return boost::shared_ptr<ModelAPI_Feature>(new SketchPlugin_Line);
}
+ else if (theFeatureID == "SketchConstraintCoincidence") {
+ return boost::shared_ptr<ModelAPI_Feature>(new SketchPlugin_ConstraintCoincidence);
+ }
// feature of such kind is not found
return boost::shared_ptr<ModelAPI_Feature>();
}
<point_selector id="StartPoint" title="Start point" tooltip="Start point of the line"/>
<point_selector id="EndPoint" title="End point" tooltip="End point of the line"/>
</feature>
- <feature id="SketchConstraintPointsCoincident" text="Points coincidence" tooltip="Create constraint for the coincidence of two points" icon="" />
+ <feature id="SketchConstraintCoincidence" text="Points coincidence" tooltip="Create constraint for the coincidence of two points" icon="" />
</group>
</workbench>
</plugin>