]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #30 - Sketch base GUI: create, draw lines
authornds <natalia.donis@opencascade.com>
Tue, 13 May 2014 10:56:36 +0000 (14:56 +0400)
committernds <natalia.donis@opencascade.com>
Tue, 13 May 2014 10:56:36 +0000 (14:56 +0400)
Create constraint on point

src/PartSet/PartSet_OperationSketchLine.cpp
src/PartSet/PartSet_OperationSketchLine.h
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/plugin-Sketch.xml

index 7449f99adda70fa433be8242cdbf8b30d7b30388..9235348a7f68f2fdbf6bac9dd651800fdde95f1f 100644 (file)
@@ -10,6 +10,9 @@
 #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>
@@ -193,12 +196,34 @@ boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::createFeature()
     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)
index 498f3ca4b7117f467877109ed8ed41842c1a66d6..d92224aaab9621a1a760f4f608dd55253cc40d31 100644 (file)
@@ -82,6 +82,12 @@ protected:
   /// \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
index ab95647eedc7b0abec58d235f20d2536a1b23dab..bef72b89daba45c662e0d7ba3e670cb0ecc9b5c1 100644 (file)
@@ -1,6 +1,7 @@
 #include "SketchPlugin_Plugin.h"
 #include "SketchPlugin_Sketch.h"
 #include "SketchPlugin_Line.h"
+#include "SketchPlugin_ConstraintCoincidence.h"
 #include <ModelAPI_PluginManager.h>
 #include <ModelAPI_Document.h>
 
@@ -23,6 +24,9 @@ boost::shared_ptr<ModelAPI_Feature> SketchPlugin_Plugin::createFeature(string th
   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>();
 }
index f90c4e124abdb215309fc8158f486db6f17cebb1..29cf61b04a16a7c8ad45c3e60295d10fdf4c4dcf 100644 (file)
@@ -10,7 +10,7 @@
         <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>