]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Add some constraint to SketchAPI_Sketch
authorspo <sergey.pokhodenko@opencascade.com>
Tue, 14 Jun 2016 10:23:58 +0000 (13:23 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Fri, 17 Jun 2016 11:41:07 +0000 (14:41 +0300)
src/SketchAPI/SketchAPI_Sketch.cpp
src/SketchAPI/SketchAPI_Sketch.h

index c0bdae5e882e34f3f60e2c16786836aec20de1cf..52119f62b44c7f7f6b88a94fd7625c31d04ecb4a 100644 (file)
@@ -9,7 +9,6 @@
 //--------------------------------------------------------------------------------------
 #include <SketchPlugin_Constraint.h>
 #include <SketchPlugin_ConstraintAngle.h>
-//#include <SketchPlugin_ConstraintBase.h>
 #include <SketchPlugin_ConstraintCoincidence.h>
 #include <SketchPlugin_ConstraintCollinear.h>
 #include <SketchPlugin_ConstraintDistance.h>
 #include <SketchPlugin_ConstraintVertical.h>
 //--------------------------------------------------------------------------------------
 #include <ModelAPI_CompositeFeature.h>
+#include <ModelHighAPI_RefAttr.h>
+#include <ModelHighAPI_Selection.h>
 #include <ModelHighAPI_Tools.h>
+//--------------------------------------------------------------------------------------
 #include "SketchAPI_Circle.h"
 #include "SketchAPI_Line.h"
 //--------------------------------------------------------------------------------------
@@ -86,6 +88,17 @@ void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
   execute();
 }
 
+//--------------------------------------------------------------------------------------
+void SketchAPI_Sketch::setValue(
+    const std::shared_ptr<ModelAPI_Feature> & theConstraint,
+    const ModelHighAPI_Double & theValue)
+{
+  // TODO(spo): check somehow that the feature is a constraint or eliminate crash if the feature have no real attribute VALUE
+  fillAttribute(theValue, theConstraint->real(SketchPlugin_Constraint::VALUE()));
+
+  theConstraint->execute();
+}
+
 //--------------------------------------------------------------------------------------
 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
                     const std::shared_ptr<GeomAPI_Ax3> & thePlane)
@@ -103,6 +116,14 @@ SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
   return SketchPtr(new SketchAPI_Sketch(aFeature, theExternal));
 }
 
+SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
+                    const std::string & theExternalName)
+{
+  // TODO(spo): check that thePart is not empty
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
+  return SketchPtr(new SketchAPI_Sketch(aFeature, ModelHighAPI_Selection("FACE", theExternalName)));
+}
+
 //--------------------------------------------------------------------------------------
 std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(double theX1, double theY1, double theX2, double theY2)
 {
@@ -178,19 +199,61 @@ std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCoincident(
     const ModelHighAPI_RefAttr & thePoint1,
     const ModelHighAPI_RefAttr & thePoint2)
 {
-  std::shared_ptr<ModelAPI_Feature> aFeature = compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
-  fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_ConstraintCoincidence::ENTITY_A()));
-  fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_ConstraintCoincidence::ENTITY_B()));
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+      compositeFeature()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
+  fillAttribute(thePoint1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
+  fillAttribute(thePoint2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
   aFeature->execute();
   return aFeature;
 }
 
-//--------------------------------------------------------------------------------------
-void SketchAPI_Sketch::setValue(
-    const std::shared_ptr<ModelAPI_Feature> & theConstraint,
+std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setDistance(
+    const ModelHighAPI_RefAttr & thePoint,
+    const ModelHighAPI_RefAttr & theLine,
     const ModelHighAPI_Double & theValue)
 {
-  fillAttribute(theValue, theConstraint->real(SketchPlugin_Constraint::VALUE()));
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+      compositeFeature()->addFeature(SketchPlugin_ConstraintDistance::ID());
+  fillAttribute(thePoint, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
+  fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
+  fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
+  aFeature->execute();
+  return aFeature;
+}
+
+std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setLength(
+    const ModelHighAPI_RefAttr & theLine,
+    const ModelHighAPI_Double & theValue)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+      compositeFeature()->addFeature(SketchPlugin_ConstraintLength::ID());
+  fillAttribute(theLine, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
+  fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
+  aFeature->execute();
+  return aFeature;
 }
 
+std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setParallel(
+    const ModelHighAPI_RefAttr & theLine1,
+    const ModelHighAPI_RefAttr & theLine2)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+      compositeFeature()->addFeature(SketchPlugin_ConstraintParallel::ID());
+  fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
+  fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
+  aFeature->execute();
+  return aFeature;
+}
+
+std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setPerpendicular(
+    const ModelHighAPI_RefAttr & theLine1,
+    const ModelHighAPI_RefAttr & theLine2)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+      compositeFeature()->addFeature(SketchPlugin_ConstraintPerpendicular::ID());
+  fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
+  fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
+  aFeature->execute();
+  return aFeature;
+}
 //--------------------------------------------------------------------------------------
index 3dce93862620252a67699b1595051812d7947eb7..70ec19cb9baf2e9410a61a1964145d43c86e6803 100644 (file)
@@ -115,15 +115,39 @@ public:
   /// Set coincident
   SKETCHAPI_EXPORT
   std::shared_ptr<ModelAPI_Feature> setCoincident(
-      // TODO(spo): should it be more concrete type (e.g. ModelAPI_Object)?
       const ModelHighAPI_RefAttr & thePoint1,
       const ModelHighAPI_RefAttr & thePoint2);
 
+  /// Set distance
+  SKETCHAPI_EXPORT
+  std::shared_ptr<ModelAPI_Feature> setDistance(
+      const ModelHighAPI_RefAttr & thePoint,
+      const ModelHighAPI_RefAttr & theLine,
+      const ModelHighAPI_Double & theValue);
+
+  /// Set length
+  SKETCHAPI_EXPORT
+  std::shared_ptr<ModelAPI_Feature> setLength(
+      const ModelHighAPI_RefAttr & theLine,
+      const ModelHighAPI_Double & theValue);
+
+  /// Set parallel
+  SKETCHAPI_EXPORT
+  std::shared_ptr<ModelAPI_Feature> setParallel(
+      const ModelHighAPI_RefAttr & theLine1,
+      const ModelHighAPI_RefAttr & theLine2);
+
+  /// Set perpendicular
+  SKETCHAPI_EXPORT
+  std::shared_ptr<ModelAPI_Feature> setPerpendicular(
+      const ModelHighAPI_RefAttr & theLine1,
+      const ModelHighAPI_RefAttr & theLine2);
+
   // TODO(spo): set* (constraints)
 
   // TODO(spo): addMirror
 
-  /// Set value
+  /// Set constraint value
   SKETCHAPI_EXPORT
   void setValue(
       const std::shared_ptr<ModelAPI_Feature> & theConstraint,
@@ -153,6 +177,13 @@ SKETCHAPI_EXPORT
 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
                     const ModelHighAPI_Selection & theExternal);
 
+/**\ingroup CPPHighAPI
+ * \brief Create Sketch feature
+ */
+SKETCHAPI_EXPORT
+SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
+                    const std::string & theExternalName);
+
 //--------------------------------------------------------------------------------------
 //--------------------------------------------------------------------------------------
 #endif /* SRC_SKETCHAPI_SKETCHAPI_SKETCH_H_ */