Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
authorvsv <vitaly.smetannikov@opencascade.com>
Mon, 16 Mar 2015 11:47:36 +0000 (14:47 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Mon, 16 Mar 2015 11:47:36 +0000 (14:47 +0300)
12 files changed:
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_ConstraintEqual.cpp [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_ConstraintEqual.h [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_ConstraintHorizontal.cpp [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_ConstraintHorizontal.h [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_ConstraintVertical.cpp [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_ConstraintVertical.h [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/Test/TestConstraintHorizontal.py [new file with mode: 0644]
src/SketchPlugin/Test/TestConstraintVertical.py [new file with mode: 0644]
src/SketchPlugin/plugin-Sketch.xml
src/SketchSolver/SketchSolver_Constraint.cpp

index 01c640568d5617ede4b48ae4725b6f6af098850f..5167dd28ce419abafc7b69b69e12bf2c2ca4f37c 100644 (file)
@@ -22,6 +22,9 @@ SET(PROJECT_HEADERS
     SketchPlugin_ConstraintPerpendicular.h
     SketchPlugin_ConstraintRadius.h
     SketchPlugin_ConstraintRigid.h
+    SketchPlugin_ConstraintHorizontal.h
+    SketchPlugin_ConstraintVertical.h
+    SketchPlugin_ConstraintEqual.h
     SketchPlugin_ShapeValidator.h
     SketchPlugin_Validators.h
     SketchPlugin_ResultValidators.h 
@@ -44,6 +47,9 @@ SET(PROJECT_SOURCES
     SketchPlugin_ConstraintPerpendicular.cpp
     SketchPlugin_ConstraintRadius.cpp
     SketchPlugin_ConstraintRigid.cpp
+    SketchPlugin_ConstraintHorizontal.cpp
+    SketchPlugin_ConstraintVertical.cpp
+    SketchPlugin_ConstraintEqual.cpp
     SketchPlugin_ShapeValidator.cpp
     SketchPlugin_Validators.cpp
     SketchPlugin_ResultValidators.cpp
@@ -89,5 +95,7 @@ ADD_UNIT_TESTS(TestSketchPointLine.py
                TestConstraintPerpendicular.py
                TestConstraintRadius.py
                TestConstraintRigid.py
+               TestConstraintHorizontal.py
+               TestConstraintVertical.py
                TestHighload.py
                TestSnowflake.py)
diff --git a/src/SketchPlugin/SketchPlugin_ConstraintEqual.cpp b/src/SketchPlugin/SketchPlugin_ConstraintEqual.cpp
new file mode 100644 (file)
index 0000000..00531ac
--- /dev/null
@@ -0,0 +1,44 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:    SketchPlugin_ConstraintEqual.cpp
+// Created: 16 Mar 2015
+// Author:  Artem ZHIDKOV
+
+#include "SketchPlugin_ConstraintEqual.h"
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_ResultConstruction.h>
+
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Sketch.h>
+
+#include <SketcherPrs_Factory.h>
+
+#include <Config_PropManager.h>
+
+SketchPlugin_ConstraintEqual::SketchPlugin_ConstraintEqual()
+{
+}
+
+void SketchPlugin_ConstraintEqual::initAttributes()
+{
+  data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
+  data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type());
+}
+
+void SketchPlugin_ConstraintEqual::execute()
+{
+}
+
+AISObjectPtr SketchPlugin_ConstraintEqual::getAISObject(AISObjectPtr thePrevious)
+{
+  if (!sketch())
+    return thePrevious;
+
+  AISObjectPtr anAIS = thePrevious;
+  /// TODO: Equal constraint presentation should be put here
+  return anAIS;
+}
+
+
diff --git a/src/SketchPlugin/SketchPlugin_ConstraintEqual.h b/src/SketchPlugin/SketchPlugin_ConstraintEqual.h
new file mode 100644 (file)
index 0000000..b19e989
--- /dev/null
@@ -0,0 +1,51 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:    SketchPlugin_ConstraintEqual.h
+// Created: 16 Mar 2015
+// Author:  Artem ZHIDKOV
+
+#ifndef SketchPlugin_ConstraintEqual_H_
+#define SketchPlugin_ConstraintEqual_H_
+
+#include "SketchPlugin.h"
+#include <SketchPlugin_Sketch.h>
+#include "SketchPlugin_ConstraintBase.h"
+
+/** \class SketchPlugin_ConstraintEqual
+ *  \ingroup Plugins
+ *  \brief Feature for creation of a new constraint specifying equality of lengths of two lines
+ *         or equality of radii of two circular arcs (full circles)
+ *
+ *  This constraint has two attributes:
+ *  SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B()
+ */
+class SketchPlugin_ConstraintEqual : public SketchPlugin_ConstraintBase
+{
+ public:
+  /// Equal constraint kind
+  inline static const std::string& ID()
+  {
+    static const std::string MY_CONSTRAINT_EQUAL_ID("SketchConstraintEqual");
+    return MY_CONSTRAINT_EQUAL_ID;
+  }
+  /// \brief Returns the kind of a feature
+  SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
+  {
+    static std::string MY_KIND = SketchPlugin_ConstraintEqual::ID();
+    return MY_KIND;
+  }
+
+  /// \brief Creates a new part document if needed
+  SKETCHPLUGIN_EXPORT virtual void execute();
+
+  /// \brief Request for initialization of data model of the feature: adding all attributes
+  SKETCHPLUGIN_EXPORT virtual void initAttributes();
+
+  /// Returns the AIS preview
+  SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
+
+  /// \brief Use plugin manager for features creation
+  SketchPlugin_ConstraintEqual();
+};
+
+#endif
diff --git a/src/SketchPlugin/SketchPlugin_ConstraintHorizontal.cpp b/src/SketchPlugin/SketchPlugin_ConstraintHorizontal.cpp
new file mode 100644 (file)
index 0000000..722ea65
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:    SketchPlugin_ConstraintHorizontal.cpp
+// Created: 16 Mar 2015
+// Author:  Artem ZHIDKOV
+
+#include "SketchPlugin_ConstraintHorizontal.h"
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_ResultConstruction.h>
+
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Sketch.h>
+
+#include <SketcherPrs_Factory.h>
+
+#include <Config_PropManager.h>
+
+SketchPlugin_ConstraintHorizontal::SketchPlugin_ConstraintHorizontal()
+{
+}
+
+void SketchPlugin_ConstraintHorizontal::initAttributes()
+{
+  data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
+}
+
+void SketchPlugin_ConstraintHorizontal::execute()
+{
+}
+
+AISObjectPtr SketchPlugin_ConstraintHorizontal::getAISObject(AISObjectPtr thePrevious)
+{
+  if (!sketch())
+    return thePrevious;
+
+  AISObjectPtr anAIS = thePrevious;
+  /// TODO: Horizontal constraint presentation should be put here
+  return anAIS;
+}
+
+
diff --git a/src/SketchPlugin/SketchPlugin_ConstraintHorizontal.h b/src/SketchPlugin/SketchPlugin_ConstraintHorizontal.h
new file mode 100644 (file)
index 0000000..3014e26
--- /dev/null
@@ -0,0 +1,50 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:    SketchPlugin_ConstraintHorizontal.h
+// Created: 16 Mar 2015
+// Author:  Artem ZHIDKOV
+
+#ifndef SketchPlugin_ConstraintHorizontal_H_
+#define SketchPlugin_ConstraintHorizontal_H_
+
+#include "SketchPlugin.h"
+#include <SketchPlugin_Sketch.h>
+#include "SketchPlugin_ConstraintBase.h"
+
+/** \class SketchPlugin_ConstraintHorizontal
+ *  \ingroup Plugins
+ *  \brief Feature for creation of a new constraint horizontality of a line
+ *
+ *  This constraint has one attribute SketchPlugin_Constraint::ENTITY_A(),
+ *  which specifies a line to be horizontal
+ */
+class SketchPlugin_ConstraintHorizontal : public SketchPlugin_ConstraintBase
+{
+ public:
+  /// Horizontal constraint kind
+  inline static const std::string& ID()
+  {
+    static const std::string MY_CONSTRAINT_HORIZONTAL_ID("SketchConstraintHorizontal");
+    return MY_CONSTRAINT_HORIZONTAL_ID;
+  }
+  /// \brief Returns the kind of a feature
+  SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
+  {
+    static std::string MY_KIND = SketchPlugin_ConstraintHorizontal::ID();
+    return MY_KIND;
+  }
+
+  /// \brief Creates a new part document if needed
+  SKETCHPLUGIN_EXPORT virtual void execute();
+
+  /// \brief Request for initialization of data model of the feature: adding all attributes
+  SKETCHPLUGIN_EXPORT virtual void initAttributes();
+
+  /// Returns the AIS preview
+  SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
+
+  /// \brief Use plugin manager for features creation
+  SketchPlugin_ConstraintHorizontal();
+};
+
+#endif
diff --git a/src/SketchPlugin/SketchPlugin_ConstraintVertical.cpp b/src/SketchPlugin/SketchPlugin_ConstraintVertical.cpp
new file mode 100644 (file)
index 0000000..ecfc917
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:    SketchPlugin_ConstraintVertical.cpp
+// Created: 16 Mar 2015
+// Author:  Artem ZHIDKOV
+
+#include "SketchPlugin_ConstraintVertical.h"
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_ResultConstruction.h>
+
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Sketch.h>
+
+#include <SketcherPrs_Factory.h>
+
+#include <Config_PropManager.h>
+
+SketchPlugin_ConstraintVertical::SketchPlugin_ConstraintVertical()
+{
+}
+
+void SketchPlugin_ConstraintVertical::initAttributes()
+{
+  data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
+}
+
+void SketchPlugin_ConstraintVertical::execute()
+{
+}
+
+AISObjectPtr SketchPlugin_ConstraintVertical::getAISObject(AISObjectPtr thePrevious)
+{
+  if (!sketch())
+    return thePrevious;
+
+  AISObjectPtr anAIS = thePrevious;
+  /// TODO: Horizontal constraint presentation should be put here
+  return anAIS;
+}
+
+
diff --git a/src/SketchPlugin/SketchPlugin_ConstraintVertical.h b/src/SketchPlugin/SketchPlugin_ConstraintVertical.h
new file mode 100644 (file)
index 0000000..79b5c74
--- /dev/null
@@ -0,0 +1,50 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:    SketchPlugin_ConstraintVertical.h
+// Created: 16 Mar 2015
+// Author:  Artem ZHIDKOV
+
+#ifndef SketchPlugin_ConstraintVertical_H_
+#define SketchPlugin_ConstraintVertical_H_
+
+#include "SketchPlugin.h"
+#include <SketchPlugin_Sketch.h>
+#include "SketchPlugin_ConstraintBase.h"
+
+/** \class SketchPlugin_ConstraintVertical
+ *  \ingroup Plugins
+ *  \brief Feature for creation of a new constraint verticality of a line
+ *
+ *  This constraint has one attribute SketchPlugin_Constraint::ENTITY_A(),
+ *  which specifies a line to be vertical
+ */
+class SketchPlugin_ConstraintVertical : public SketchPlugin_ConstraintBase
+{
+ public:
+  /// Vertical constraint kind
+  inline static const std::string& ID()
+  {
+    static const std::string MY_CONSTRAINT_VERTICAL_ID("SketchConstraintVertical");
+    return MY_CONSTRAINT_VERTICAL_ID;
+  }
+  /// \brief Returns the kind of a feature
+  SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
+  {
+    static std::string MY_KIND = SketchPlugin_ConstraintVertical::ID();
+    return MY_KIND;
+  }
+
+  /// \brief Creates a new part document if needed
+  SKETCHPLUGIN_EXPORT virtual void execute();
+
+  /// \brief Request for initialization of data model of the feature: adding all attributes
+  SKETCHPLUGIN_EXPORT virtual void initAttributes();
+
+  /// Returns the AIS preview
+  SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
+
+  /// \brief Use plugin manager for features creation
+  SketchPlugin_ConstraintVertical();
+};
+
+#endif
index c4188bf90564bb80a3f32ed8c6d0bc8c29c4730e..5e1ac512c7b8a9e9a975855e3e5f0948f1076003 100644 (file)
@@ -8,11 +8,14 @@
 #include <SketchPlugin_Arc.h>
 #include <SketchPlugin_ConstraintCoincidence.h>
 #include <SketchPlugin_ConstraintDistance.h>
+#include <SketchPlugin_ConstraintEqual.h>
+#include <SketchPlugin_ConstraintHorizontal.h>
 #include <SketchPlugin_ConstraintLength.h>
 #include <SketchPlugin_ConstraintParallel.h>
 #include <SketchPlugin_ConstraintPerpendicular.h>
 #include <SketchPlugin_ConstraintRadius.h>
 #include <SketchPlugin_ConstraintRigid.h>
+#include <SketchPlugin_ConstraintVertical.h>
 #include <SketchPlugin_Validators.h>
 #include <SketchPlugin_ResultValidators.h>
 #include <SketchPlugin_ShapeValidator.h>
@@ -109,6 +112,12 @@ FeaturePtr SketchPlugin_Plugin::createFeature(string theFeatureID)
     return FeaturePtr(new SketchPlugin_ConstraintRadius);
   } else if (theFeatureID == SketchPlugin_ConstraintRigid::ID()) {
     return FeaturePtr(new SketchPlugin_ConstraintRigid);
+  } else if (theFeatureID == SketchPlugin_ConstraintHorizontal::ID()) {
+    return FeaturePtr(new SketchPlugin_ConstraintHorizontal);
+  } else if (theFeatureID == SketchPlugin_ConstraintVertical::ID()) {
+    return FeaturePtr(new SketchPlugin_ConstraintVertical);
+  } else if (theFeatureID == SketchPlugin_ConstraintEqual::ID()) {
+    return FeaturePtr(new SketchPlugin_ConstraintEqual);
   }
   // feature of such kind is not found
   return FeaturePtr();
@@ -153,6 +162,9 @@ std::shared_ptr<ModelAPI_FeatureStateMessage> SketchPlugin_Plugin
       aMsg->setState(SketchPlugin_ConstraintPerpendicular::ID(), aHasSketchPlane);
       aMsg->setState(SketchPlugin_ConstraintRadius::ID(), aHasSketchPlane);
       aMsg->setState(SketchPlugin_ConstraintRigid::ID(), aHasSketchPlane);
+      aMsg->setState(SketchPlugin_ConstraintHorizontal::ID(), aHasSketchPlane);
+      aMsg->setState(SketchPlugin_ConstraintVertical::ID(), aHasSketchPlane);
+      aMsg->setState(SketchPlugin_ConstraintEqual::ID(), aHasSketchPlane);
     }
   }
   return aMsg;
diff --git a/src/SketchPlugin/Test/TestConstraintHorizontal.py b/src/SketchPlugin/Test/TestConstraintHorizontal.py
new file mode 100644 (file)
index 0000000..3373158
--- /dev/null
@@ -0,0 +1,78 @@
+"""
+    TestConstraintHorizontal.py
+    Unit test of SketchPlugin_ConstraintHorizontal class
+        
+    SketchPlugin_ConstraintHorizontal
+        static const std::string MY_CONSTRAINT_HORIZONTAL_ID("SketchConstraintHorizontal");
+        data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
+
+"""
+from GeomDataAPI import *
+from ModelAPI import *
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+
+__updated__ = "2015-03-16"
+
+aSession = ModelAPI_Session.get()
+aDocument = aSession.moduleDocument()
+#=========================================================================
+# Creation of a sketch
+#=========================================================================
+aSession.startOperation()
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
+origin.setValue(0, 0, 0)
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
+dirx.setValue(1, 0, 0)
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
+diry.setValue(0, 1, 0)
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
+norm.setValue(0, 0, 1)
+aSession.finishOperation()
+#=========================================================================
+# Create non-horizontal line
+#=========================================================================
+aSession.startOperation()
+aSketchLine = aSketchFeature.addFeature("SketchLine")
+aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
+aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
+aLineStartPoint.setValue(0., 15.)
+aLineEndPoint.setValue(20., 25.)
+aSession.finishOperation()
+#=========================================================================
+# Assign horizontal constraint for a line
+#=========================================================================
+aSession.startOperation()
+aHorizontalConstraint = aSketchFeature.addFeature("SketchConstraintHorizontal")
+refattrA = aHorizontalConstraint.refattr("ConstraintEntityA")
+aResult = modelAPI_ResultConstruction(aSketchLine.firstResult())
+assert (aResult is not None)
+refattrA.setObject(aResult)
+aHorizontalConstraint.execute()
+aSession.finishOperation()
+assert(aLineStartPoint.y() == aLineEndPoint.y())
+#=========================================================================
+# Move one of boundary points of a line
+#=========================================================================
+deltaX = deltaY = 10.
+aSession.startOperation()
+aLineStartPoint.setValue(aLineStartPoint.x() + deltaX,
+                         aLineStartPoint.y() + deltaY)
+aSession.finishOperation()
+assert(aLineStartPoint.y() == aLineEndPoint.y())
+#=========================================================================
+# Move other boundary point of a line
+#=========================================================================
+deltaX = -3.
+deltaY = -10.
+aSession.startOperation()
+aLineEndPoint.setValue(aLineEndPoint.x() + deltaX,
+                       aLineEndPoint.y() + deltaY)
+aSession.finishOperation()
+assert(aLineStartPoint.y() == aLineEndPoint.y())
+#=========================================================================
+# End of test
+#=========================================================================
diff --git a/src/SketchPlugin/Test/TestConstraintVertical.py b/src/SketchPlugin/Test/TestConstraintVertical.py
new file mode 100644 (file)
index 0000000..87ba28f
--- /dev/null
@@ -0,0 +1,78 @@
+"""
+    TestConstraintVertical.py
+    Unit test of SketchPlugin_ConstraintVertical class
+        
+    SketchPlugin_ConstraintVertical
+        static const std::string MY_CONSTRAINT_VERTICAL_ID("SketchConstraintVertical");
+        data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
+
+"""
+from GeomDataAPI import *
+from ModelAPI import *
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+
+__updated__ = "2015-03-16"
+
+aSession = ModelAPI_Session.get()
+aDocument = aSession.moduleDocument()
+#=========================================================================
+# Creation of a sketch
+#=========================================================================
+aSession.startOperation()
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
+origin.setValue(0, 0, 0)
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
+dirx.setValue(1, 0, 0)
+diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
+diry.setValue(0, 1, 0)
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
+norm.setValue(0, 0, 1)
+aSession.finishOperation()
+#=========================================================================
+# Create non-vertical line
+#=========================================================================
+aSession.startOperation()
+aSketchLine = aSketchFeature.addFeature("SketchLine")
+aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
+aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
+aLineStartPoint.setValue(0., 15.)
+aLineEndPoint.setValue(20., 25.)
+aSession.finishOperation()
+#=========================================================================
+# Assign vertical constraint for a line
+#=========================================================================
+aSession.startOperation()
+aVerticalConstraint = aSketchFeature.addFeature("SketchConstraintVertical")
+refattrA = aVerticalConstraint.refattr("ConstraintEntityA")
+aResult = modelAPI_ResultConstruction(aSketchLine.firstResult())
+assert (aResult is not None)
+refattrA.setObject(aResult)
+aVerticalConstraint.execute()
+aSession.finishOperation()
+assert(aLineStartPoint.x() == aLineEndPoint.x())
+#=========================================================================
+# Move one of boundary points of a line
+#=========================================================================
+deltaX = deltaY = 10.
+aSession.startOperation()
+aLineStartPoint.setValue(aLineStartPoint.x() + deltaX,
+                         aLineStartPoint.y() + deltaY)
+aSession.finishOperation()
+assert(aLineStartPoint.x() == aLineEndPoint.x())
+#=========================================================================
+# Move other boundary point of a line
+#=========================================================================
+deltaX = -3.
+deltaY = -10.
+aSession.startOperation()
+aLineEndPoint.setValue(aLineEndPoint.x() + deltaX,
+                       aLineEndPoint.y() + deltaY)
+aSession.finishOperation()
+assert(aLineStartPoint.x() == aLineEndPoint.x())
+#=========================================================================
+# End of test
+#=========================================================================
index fafdb2fdee5fbccaa8e73368da9e5f73b894118b..0b98b3328d093614273088bd8b96b577e79d4b63 100644 (file)
@@ -5,7 +5,7 @@
     <group id="Basic">
       <feature
         id="Sketch"
-        nested="SketchPoint SketchLine SketchCircle SketchArc SketchConstraintLength SketchConstraintRadius SketchConstraintDistance SketchConstraintParallel SketchConstraintPerpendicular SketchConstraintRigid"
+        nested="SketchPoint SketchLine SketchCircle SketchArc SketchConstraintLength SketchConstraintRadius SketchConstraintDistance SketchConstraintParallel SketchConstraintPerpendicular SketchConstraintRigid SketchConstraintHorizontal SketchConstraintVertical SketchConstraintEqual"
         when_nested="accept abort"
         title="Sketch"
         tooltip="Create a new sketch"
         </shape_selector>
         <validator id="PartSet_RigidValidator"/>
       </feature>
+    <!--  SketchConstraintHorizontal  -->
+      <feature id="SketchConstraintHorizontal" title="Horizontal" tooltip="Create constraint defining horizontal line">
+        <sketch_constraint_shape_selector id="ConstraintEntityA" 
+            label="Line" tooltip="Select a line" shape_types="edge">
+            <selection_filter id="EdgeFilter" parameters="line"/>
+        </sketch_constraint_shape_selector>
+      </feature>
+    <!--  SketchConstraintVertical  -->
+      <feature id="SketchConstraintVertical" title="Vertical" tooltip="Create constraint defining vertical line">
+        <sketch_constraint_shape_selector id="ConstraintEntityA" 
+            label="Line" tooltip="Select a line" shape_types="edge">
+            <selection_filter id="EdgeFilter" parameters="line"/>
+        </sketch_constraint_shape_selector>
+      </feature>
+    <!--  SketchConstraintEqual  -->
+      <feature id="SketchConstraintEqual" title="Equal" tooltip="Create constraint defining equality of two objects">
+        <sketch_constraint_shape_selector id="ConstraintEntityA" 
+            label="First object" tooltip="Select line, circle or arc" shape_types="edge">
+        </sketch_constraint_shape_selector>
+        
+        <sketch_constraint_shape_selector id="ConstraintEntityB"
+            label="Last object" tooltip="Select line, circle or arc" shape_types="edge">
+        </sketch_constraint_shape_selector>
+      </feature>
     </group>
   </workbench>
 </plugin>
index 61a42b64cf43195b46d9b6bb549cffc78040aa83..980c51879e3574c5c2b008545912f2c6ce3339a6 100644 (file)
 #include <SketchPlugin_Arc.h>
 #include <SketchPlugin_ConstraintCoincidence.h>
 #include <SketchPlugin_ConstraintDistance.h>
+#include <SketchPlugin_ConstraintEqual.h>
+#include <SketchPlugin_ConstraintHorizontal.h>
 #include <SketchPlugin_ConstraintLength.h>
 #include <SketchPlugin_ConstraintParallel.h>
 #include <SketchPlugin_ConstraintPerpendicular.h>
 #include <SketchPlugin_ConstraintRadius.h>
 #include <SketchPlugin_ConstraintRigid.h>
+#include <SketchPlugin_ConstraintVertical.h>
 
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_Data.h>
@@ -197,6 +200,48 @@ const int& SketchSolver_Constraint::getType(
     return getType();
   }
 
+  // Constraint for horizontal/vertical line
+  bool isHorizontal = (aConstraintKind.compare(SketchPlugin_ConstraintHorizontal::ID()) == 0);
+  bool isVertical = (aConstraintKind.compare(SketchPlugin_ConstraintVertical::ID()) == 0);
+  if (isHorizontal || isVertical) {
+    int aNbEntities = 2;  // lines in SolveSpace constraints should start from SketchPlugin_Constraint::ENTITY_C() attribute
+    for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++) {
+      std::shared_ptr<ModelAPI_Attribute> anAttr = 
+          aConstrData->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr));
+      if (typeOfAttribute(anAttr) == LINE)
+        myAttributesList[aNbEntities++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
+    }
+    if (aNbEntities == 3)
+      myType = isHorizontal ? SLVS_C_HORIZONTAL : SLVS_C_VERTICAL;
+    return getType();
+  }
+
+  if (aConstraintKind.compare(SketchPlugin_ConstraintEqual::ID()) == 0)
+  {
+    static const int aConstrType[3] = {
+        SLVS_C_EQUAL_RADIUS,
+        SLVS_C_EQUAL_LINE_ARC_LEN,
+        SLVS_C_EQUAL_LENGTH_LINES
+    };
+    int aNbLines = 0;
+    int aNbEntities = 2;  // lines and circles in SolveSpace constraints should start from SketchPlugin_Constraint::ENTITY_C() attribute
+    for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++) {
+      std::shared_ptr<ModelAPI_Attribute> anAttr = 
+          aConstrData->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr));
+      AttrType aType = typeOfAttribute(anAttr);
+      if (aType == LINE)
+      {
+        myAttributesList[aNbEntities++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
+        aNbLines++;
+      }
+      else if (aType == CIRCLE || aType == ARC)
+        myAttributesList[aNbEntities++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr);
+    }
+    if (aNbEntities == 4)
+      myType = aConstrType[aNbLines];
+    return getType();
+  }
+
   /// \todo Implement other kind of constraints
 
   return getType();