]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Horizontal and vertical constraints
authorazv <azv@opencascade.com>
Mon, 16 Mar 2015 09:33:24 +0000 (12:33 +0300)
committerazv <azv@opencascade.com>
Mon, 16 Mar 2015 11:45:30 +0000 (14:45 +0300)
1. SketchPlugin featurea are implemented
2. SketchSolver integration of new constraints is made
3. Unit tests are created

src/SketchPlugin/CMakeLists.txt
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..21b0cfbec6ea735d7f72d388768378f78e9c1e08 100644 (file)
@@ -22,6 +22,8 @@ SET(PROJECT_HEADERS
     SketchPlugin_ConstraintPerpendicular.h
     SketchPlugin_ConstraintRadius.h
     SketchPlugin_ConstraintRigid.h
+    SketchPlugin_ConstraintHorizontal.h
+    SketchPlugin_ConstraintVertical.h
     SketchPlugin_ShapeValidator.h
     SketchPlugin_Validators.h
     SketchPlugin_ResultValidators.h 
@@ -44,6 +46,8 @@ SET(PROJECT_SOURCES
     SketchPlugin_ConstraintPerpendicular.cpp
     SketchPlugin_ConstraintRadius.cpp
     SketchPlugin_ConstraintRigid.cpp
+    SketchPlugin_ConstraintHorizontal.cpp
+    SketchPlugin_ConstraintVertical.cpp
     SketchPlugin_ShapeValidator.cpp
     SketchPlugin_Validators.cpp
     SketchPlugin_ResultValidators.cpp
@@ -89,5 +93,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_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..6aa24717d46231ca99741b656ff3ec695b4b52cd 100644 (file)
@@ -8,11 +8,13 @@
 #include <SketchPlugin_Arc.h>
 #include <SketchPlugin_ConstraintCoincidence.h>
 #include <SketchPlugin_ConstraintDistance.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 +111,10 @@ 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);
   }
   // feature of such kind is not found
   return FeaturePtr();
@@ -153,6 +159,8 @@ 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);
     }
   }
   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..894e3a88f27a1396a03fe6ca9fe064c3d615da10 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"
         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>
     </group>
   </workbench>
 </plugin>
index 61a42b64cf43195b46d9b6bb549cffc78040aa83..b2c7185d77ef488c6fdbf54682e99f6814df4531 100644 (file)
 #include <SketchPlugin_Arc.h>
 #include <SketchPlugin_ConstraintCoincidence.h>
 #include <SketchPlugin_ConstraintDistance.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 +199,22 @@ 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();
+  }
+
   /// \todo Implement other kind of constraints
 
   return getType();