]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #392 Can not create axis on two points of one sketch
authornds <natalia.donis@opencascade.com>
Mon, 2 Feb 2015 09:22:58 +0000 (12:22 +0300)
committernds <natalia.donis@opencascade.com>
Mon, 2 Feb 2015 09:22:58 +0000 (12:22 +0300)
src/ConstructionPlugin/axis_widget.xml
src/ModelAPI/CMakeLists.txt
src/ModelAPI/ModelAPI_ShapeValidator.cpp [new file with mode: 0644]
src/ModelAPI/ModelAPI_ShapeValidator.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/PartSet/PartSet_Module.cpp

index f612a83d08e470a660ae85390bfd57f6d2badecc..a3424e3f1b1d5acb8a0b43f68b91684142b7da1d 100644 (file)
@@ -14,6 +14,6 @@
     tooltip="Select a second point"
     shape_types="vertex">
     <selection_filter id="NoConstructionSubShapesFilter"/>
-    <validator id="PartSet_DifferentObjects"/>
+    <validator id="PartSet_DifferentShapes"/>
   </shape_selector>
 </source>
index 738664c17187339a52195be27b47ecc5491339b3..e8ef2bad290e75210907cb1e53a7561f1cdaad95 100644 (file)
@@ -37,6 +37,7 @@ SET(PROJECT_HEADERS
     ModelAPI_ResultValidator.h
     ModelAPI_Session.h
     ModelAPI_Tools.h
+    ModelAPI_ShapeValidator.h
     ModelAPI_Validator.h
 )
 
@@ -65,6 +66,7 @@ SET(PROJECT_SOURCES
     ModelAPI_ResultGroup.cpp
     ModelAPI_ResultPart.cpp
     ModelAPI_Session.cpp
+    ModelAPI_ShapeValidator.cpp
     ModelAPI_Tools.cpp
 )
 
diff --git a/src/ModelAPI/ModelAPI_ShapeValidator.cpp b/src/ModelAPI/ModelAPI_ShapeValidator.cpp
new file mode 100644 (file)
index 0000000..b451ed1
--- /dev/null
@@ -0,0 +1,36 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModelAPI_ShapeValidator.cpp
+// Created:     2 Feb 2015
+// Author:      Natalia ERMOLAEVA
+
+#include "ModelAPI_ShapeValidator.h"
+
+#include <ModelAPI_AttributeSelection.h>
+#include "ModelAPI_Object.h"
+
+bool ModelAPI_ShapeValidator::isValid(const FeaturePtr& theFeature,
+                                      const AttributePtr& theAttribute,
+                                      const GeomShapePtr& theShape) const
+{
+  std::string aCurrentAttributeId = theAttribute->id();
+  // get all feature attributes
+  std::list<AttributePtr> anAttrs = 
+                   theFeature->data()->attributes(ModelAPI_AttributeSelection::type());
+  if (anAttrs.size() > 0 && theShape.get() != NULL) {
+    std::list<AttributePtr>::iterator anAttr = anAttrs.begin();
+    for(; anAttr != anAttrs.end(); anAttr++) {
+      AttributePtr anAttribute = *anAttr;
+      // take into concideration only other attributes
+      if (anAttribute.get() != NULL && anAttribute->id() != aCurrentAttributeId) {
+        AttributeSelectionPtr aSelectionAttribute = 
+          std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(anAttribute);
+        // the shape of the attribute should be not the same
+        if (aSelectionAttribute.get() != NULL && theShape->isEqual(aSelectionAttribute->value())) {
+          return false;
+        }
+      }
+    }
+  }
+  return true;
+}
diff --git a/src/ModelAPI/ModelAPI_ShapeValidator.h b/src/ModelAPI/ModelAPI_ShapeValidator.h
new file mode 100644 (file)
index 0000000..596e1c0
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModelAPI_ShapeValidator.h
+// Created:     2 Feb 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef ModelAPI_ShapeValidator_H
+#define ModelAPI_ShapeValidator_H
+
+#include <ModelAPI.h>
+
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Attribute.h>
+
+#include <GeomAPI_Shape.h>
+
+/**
+ * Generic validator for any attribute of a feature.
+ */
+class ModelAPI_ShapeValidator : public ModelAPI_Validator
+{
+public:
+  /// returns True if the attribute is valid. It checks whether the feature of the attribute
+  /// does not contain a selection attribute filled with the same shape
+  /// \param theFeature a feature to check
+  /// \param theAttribute an attribute to check
+  /// \param theShape a shape
+  MODELAPI_EXPORT bool isValid(const FeaturePtr& theFeature, const AttributePtr& theAttribute,
+                               const GeomShapePtr& theShape) const;
+};
+
+#endif
index 070cec76c88d88845c2fcb4b2bb20fe29d5ac6f2..81e45ef0a11c250d5709646e0dc210c9dd14acb5 100644 (file)
@@ -35,6 +35,7 @@
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_ResultValidator.h>
 #include <ModelAPI_RefAttrValidator.h>
+#include <ModelAPI_ShapeValidator.h>
 
 #include <Config_WidgetAPI.h>
 #include <Events_Error.h>
@@ -502,6 +503,17 @@ bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr<G
         return false;
       }
     }
+    else {
+      const ModelAPI_ShapeValidator* aShapeValidator = 
+                               dynamic_cast<const ModelAPI_ShapeValidator*>(*aValidator);
+      if (aShapeValidator) {
+        DataPtr aData = myFeature->data();
+        AttributeSelectionPtr aSelectAttr = aData->selection(attributeID());
+        if (!aShapeValidator->isValid(myFeature, aSelectAttr, theShape)) {
+          return false;
+        }
+      }
+    }
   }
   return true;
 }
\ No newline at end of file
index 253514b35851187a985df819b9a7ac3ddd7ee7ef..d94e396a6e0cc5f07f361025a851af08daef5463 100644 (file)
@@ -26,6 +26,7 @@
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Session.h>
+#include <ModelAPI_ShapeValidator.h>
 
 #include <GeomDataAPI_Point2D.h>
 #include <GeomDataAPI_Point.h>
@@ -115,6 +116,7 @@ void PartSet_Module::registerValidators()
   aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
   aFactory->registerValidator("PartSet_RigidValidator", new PartSet_RigidValidator);
   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
+  aFactory->registerValidator("PartSet_DifferentShapes", new ModelAPI_ShapeValidator);
   aFactory->registerValidator("PartSet_SketchValidator", new PartSet_SketchValidator);
 }