Salome HOME
Issue #429: error when fix the same segment twice
authorazv <azv@opencascade.com>
Wed, 1 Apr 2015 11:10:00 +0000 (14:10 +0300)
committerazv <azv@opencascade.com>
Wed, 1 Apr 2015 11:10:21 +0000 (14:10 +0300)
Implemented validator for the rigid constraint

src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/SketchPlugin_Validators.h
src/SketchPlugin/plugin-Sketch.xml

index c7ee95fcc32070a00d6564cbb37effd8ad1f9870..e0f06569fd4db5541af848c5e703476d1ccc9726 100644 (file)
@@ -55,6 +55,8 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
                               new SketchPlugin_ExternalValidator);
   aFactory->registerValidator("SketchPlugin_TangentAttr",
                               new SketchPlugin_TangentAttrValidator);
+  aFactory->registerValidator("SketchPlugin_NotFixed",
+                              new SketchPlugin_NotFixedValidator);
 
   // register this plugin
   ModelAPI_Session::get()->registerPlugin(this);
index 358c82c1b4982e73bf8875c5e31b952798c55d16..baace5c2aa3541633ba64400234e2f2b17bbde84 100644 (file)
@@ -7,6 +7,7 @@
 #include "SketchPlugin_Validators.h"
 #include "SketchPlugin_ConstraintDistance.h"
 #include "SketchPlugin_ConstraintCoincidence.h"
+#include "SketchPlugin_ConstraintRigid.h"
 #include "SketchPlugin_Line.h"
 #include "SketchPlugin_Arc.h"
 
@@ -135,4 +136,32 @@ bool SketchPlugin_TangentAttrValidator::isValid(
   return false;
 }
 
+bool SketchPlugin_NotFixedValidator::isValid(
+    const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const
+{
+  std::shared_ptr<SketchPlugin_Feature> aFeature =
+      std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
+  if (!aFeature)
+    return true;
+
+  AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+  if (!aRefAttr)
+    return false;
+
+  SketchPlugin_Sketch* aSketch = aFeature->sketch();
+  int aNbFeatures = aSketch->numberOfSubs();
+  for (int anInd = 0; anInd < aNbFeatures; anInd++) {
+    FeaturePtr aSubFeature = aSketch->subFeature(anInd);
+    if (aSubFeature->getKind() != SketchPlugin_ConstraintRigid::ID() || aSubFeature == aFeature)
+      continue;
+    AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+        aSubFeature->attribute(SketchPlugin_ConstraintRigid::ENTITY_A()));
+    if (aRefAttr->isObject()) {
+      if (aRefAttr->object() == aRAttr->object())
+        return false;
+    } else if (aRefAttr->attr() == aRAttr->attr())
+      return false;
+  }
+  return true;
+}
 
index 11721fbd1dfd654190b980d2ea91f650b62943dc..21ad277f77c251619a740d6ce6a80292934ef86c 100644 (file)
@@ -44,4 +44,21 @@ class SketchPlugin_TangentAttrValidator : public ModelAPI_AttributeValidator
 };
 
 
+/**\class SketchPlugin_NotFixed
+ * \ingroup Validators
+ * \brief Validator for the rigid constraint input.
+ *
+ * It just checks there is no rigid constraint for the current feature.
+ */
+class SketchPlugin_NotFixedValidator : public ModelAPI_AttributeValidator
+{
+ public:
+  //! returns true if attribute is not used in another rigid constraint
+  //! \param theAttribute the checked attribute
+  //! \param theArguments arguments of the attribute
+  virtual bool isValid(const AttributePtr& theAttribute,
+                       const std::list<std::string>& theArguments) const;
+};
+
+
 #endif
index 7274cc18dab72adb9939c9da12a5904ad506d7d5..898546d74aba78ec695b681341ee84af991fab72 100644 (file)
         <shape_selector id="ConstraintEntityA" label="Object" tooltip="Select an object" 
             shape_types="edge vertex">
           <validator id="PartSet_SketchEntityValidator" parameters="SketchPoint,SketchLine,SketchCircle,SketchArc"/>
+          <validator id="SketchPlugin_NotFixed"/>
         </shape_selector>
         <validator id="PartSet_RigidValidator"/>
       </feature>