]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Constraints for equality of lengths and radii
authorazv <azv@opencascade.com>
Mon, 16 Mar 2015 11:44:23 +0000 (14:44 +0300)
committerazv <azv@opencascade.com>
Mon, 16 Mar 2015 11:45:30 +0000 (14:45 +0300)
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_Plugin.cpp
src/SketchPlugin/plugin-Sketch.xml
src/SketchSolver/SketchSolver_Constraint.cpp

index 21b0cfbec6ea735d7f72d388768378f78e9c1e08..5167dd28ce419abafc7b69b69e12bf2c2ca4f37c 100644 (file)
@@ -24,6 +24,7 @@ SET(PROJECT_HEADERS
     SketchPlugin_ConstraintRigid.h
     SketchPlugin_ConstraintHorizontal.h
     SketchPlugin_ConstraintVertical.h
+    SketchPlugin_ConstraintEqual.h
     SketchPlugin_ShapeValidator.h
     SketchPlugin_Validators.h
     SketchPlugin_ResultValidators.h 
@@ -48,6 +49,7 @@ SET(PROJECT_SOURCES
     SketchPlugin_ConstraintRigid.cpp
     SketchPlugin_ConstraintHorizontal.cpp
     SketchPlugin_ConstraintVertical.cpp
+    SketchPlugin_ConstraintEqual.cpp
     SketchPlugin_ShapeValidator.cpp
     SketchPlugin_Validators.cpp
     SketchPlugin_ResultValidators.cpp
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
index 6aa24717d46231ca99741b656ff3ec695b4b52cd..5e1ac512c7b8a9e9a975855e3e5f0948f1076003 100644 (file)
@@ -8,6 +8,7 @@
 #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>
@@ -115,6 +116,8 @@ FeaturePtr SketchPlugin_Plugin::createFeature(string theFeatureID)
     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();
@@ -161,6 +164,7 @@ std::shared_ptr<ModelAPI_FeatureStateMessage> SketchPlugin_Plugin
       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;
index 894e3a88f27a1396a03fe6ca9fe064c3d615da10..0b98b3328d093614273088bd8b96b577e79d4b63 100644 (file)
@@ -5,7 +5,7 @@
     <group id="Basic">
       <feature
         id="Sketch"
-        nested="SketchPoint SketchLine SketchCircle SketchArc SketchConstraintLength SketchConstraintRadius SketchConstraintDistance SketchConstraintParallel SketchConstraintPerpendicular SketchConstraintRigid SketchConstraintHorizontal SketchConstraintVertical"
+        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"
             <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 b2c7185d77ef488c6fdbf54682e99f6814df4531..980c51879e3574c5c2b008545912f2c6ce3339a6 100644 (file)
@@ -13,6 +13,7 @@
 #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>
@@ -215,6 +216,32 @@ const int& SketchSolver_Constraint::getType(
     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();