]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Validator for tangent constraint
authorvsv <vitaly.smetannikov@opencascade.com>
Thu, 26 Mar 2015 13:26:48 +0000 (16:26 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Thu, 26 Mar 2015 13:26:48 +0000 (16:26 +0300)
src/PartSet/icons/tangent.png
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/SketchPlugin_Validators.h
src/SketchPlugin/plugin-Sketch.xml

index 4ca486e87c9a76f65b3061579dbc94a98ff77567..971e919d20d89067acd7429afb31d97cd48be709 100644 (file)
Binary files a/src/PartSet/icons/tangent.png and b/src/PartSet/icons/tangent.png differ
index 68302fee1541fe700c648e15a9875c25297a213c..c7ee95fcc32070a00d6564cbb37effd8ad1f9870 100644 (file)
@@ -53,6 +53,8 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
                               new SketchPlugin_DistanceAttrValidator);  
   aFactory->registerValidator("SketchPlugin_ExternalValidator",
                               new SketchPlugin_ExternalValidator);
+  aFactory->registerValidator("SketchPlugin_TangentAttr",
+                              new SketchPlugin_TangentAttrValidator);
 
   // register this plugin
   ModelAPI_Session::get()->registerPlugin(this);
index 32a0b30b57cc3028c1311c8b1c5935d5c46841c8..b83ca9639847485bffd07ab04fdfc5a2044758b0 100644 (file)
@@ -6,6 +6,10 @@
 
 #include "SketchPlugin_Validators.h"
 #include "SketchPlugin_ConstraintDistance.h"
+#include "SketchPlugin_ConstraintCoincidence.h"
+#include "SketchPlugin_Line.h"
+#include "SketchPlugin_Arc.h"
+
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_AttributeDouble.h>
@@ -60,3 +64,74 @@ bool SketchPlugin_DistanceAttrValidator::isValid(
   }
   return false;
 }
+
+
+
+bool SketchPlugin_TangentAttrValidator::isValid(
+  const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
+{
+  // there is a check whether the feature contains a point and a linear edge or two point values
+  std::string aParamA = theArguments.front();
+  SessionPtr aMgr = ModelAPI_Session::get();
+  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+
+  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+  AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+  if (!aRefAttr)
+    return false;
+
+  bool isObject = aRefAttr->isObject();
+  ObjectPtr anObject = aRefAttr->object();
+  if (isObject && anObject) {
+    FeaturePtr aRefFea = ModelAPI_Feature::feature(anObject);
+
+    AttributeRefAttrPtr aOtherAttr = aFeature->data()->refattr(aParamA);
+    ObjectPtr aOtherObject = aOtherAttr->object();
+    FeaturePtr aOtherFea = ModelAPI_Feature::feature(aOtherObject);
+
+    if (aRefFea->getKind() == SketchPlugin_Line::ID()) {
+      if (aOtherFea->getKind() != SketchPlugin_Arc::ID())
+        return false;
+    } else if (aRefFea->getKind() == SketchPlugin_Arc::ID()) {
+      if (aOtherFea->getKind() != SketchPlugin_Line::ID())
+        return false;
+    } else
+      return false;
+
+    // check that both have coincidence
+    FeaturePtr aConstrFeature;
+    std::set<FeaturePtr> aCoinList;
+    const std::set<std::shared_ptr<ModelAPI_Attribute>>& aRefsList = aRefFea->data()->refsToMe();
+    std::set<std::shared_ptr<ModelAPI_Attribute>>::const_iterator aIt;
+    for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
+      std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
+      aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
+      if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
+        AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
+        AttributePtr aAR = aRAttr->attr();
+        if (aAR->id() != SketchPlugin_Arc::CENTER_ID()) // ignore constraint to center of arc
+          aCoinList.insert(aConstrFeature);
+      }
+    }
+    // if there is no coincidence then it is not valid
+    if (aCoinList.size() == 0)
+      return false;
+
+    // find that coincedence is the same
+    const std::set<std::shared_ptr<ModelAPI_Attribute>>& aOtherList = aOtherFea->data()->refsToMe();
+    std::set<FeaturePtr>::const_iterator aCoinsIt;
+    for (aIt = aOtherList.cbegin(); aIt != aOtherList.cend(); ++aIt) {
+      std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
+      aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
+      aCoinsIt = aCoinList.find(aConstrFeature);
+      if (aCoinsIt != aCoinList.end()) {
+        AttributeRefAttrPtr aRAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
+        AttributePtr aAR = aRAttr->attr();
+        if (aAR->id() != SketchPlugin_Arc::CENTER_ID())
+          return true;
+      }
+    }
+  }
+  return false;
+}
+
index f686d3e6ebe97a5e75cefcee21b313b3fd2b7f04..88f042bd7ca2c2c3d53c2e2841e3fcdcdf952037 100644 (file)
@@ -26,4 +26,21 @@ class SketchPlugin_DistanceAttrValidator : public ModelAPI_AttributeValidator
                        const std::list<std::string>& theArguments) const;
 };
 
+
+/**\class SketchPlugin_TangentAttrValidator
+ * \ingroup Validators
+ * \brief Validator for the tangent constraint input.
+ *
+ * It just checks that distance is greater than zero.
+ */
+class SketchPlugin_TangentAttrValidator : public ModelAPI_AttributeValidator
+{
+ public:
+  //! returns true if attribute is valid
+  //! \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 2d5e884e13d42fa2e435d946bbce8532dcc36c98..f5199b53424f2b858c77c5ac09188b122f13d978 100644 (file)
         
         <sketch_constraint_shape_selector id="ConstraintEntityB"
             label="Last object" tooltip="Select line or arc" shape_types="edge">
+        <validator id="SketchPlugin_TangentAttr" parameters="ConstraintEntityA"/>
         </sketch_constraint_shape_selector>
       </feature>