]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #353 constraint on 2 segments from not acive sketches
authornds <natalia.donis@opencascade.com>
Fri, 27 Feb 2015 12:41:34 +0000 (15:41 +0300)
committernds <natalia.donis@opencascade.com>
Fri, 27 Feb 2015 12:41:34 +0000 (15:41 +0300)
A sketch shape validator for parallel/perpendicular constraints.

src/ModelAPI/ModelAPI_ShapeValidator.cpp
src/ModelAPI/ModelAPI_ShapeValidator.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_Plugin.cpp
src/SketchPlugin/SketchPlugin_ShapeValidator.cpp [new file with mode: 0644]
src/SketchPlugin/SketchPlugin_ShapeValidator.h [new file with mode: 0644]
src/SketchPlugin/plugin-Sketch.xml

index b451ed1bb6a0da11fca64b59fe369df1ca2f09c0..08f0a687b5dce9002c96f38fe0bfdf1e1ab1a25a 100644 (file)
@@ -10,6 +10,8 @@
 #include "ModelAPI_Object.h"
 
 bool ModelAPI_ShapeValidator::isValid(const FeaturePtr& theFeature,
+                                      const std::list<std::string>& theArguments,
+                                      const ObjectPtr& theObject,
                                       const AttributePtr& theAttribute,
                                       const GeomShapePtr& theShape) const
 {
index 596e1c08e682b61e66ac3dab55ed44c08e2ee24a..3be9323f7558e5c8a0dae67a915a3e80778fc4fb 100644 (file)
@@ -24,9 +24,13 @@ 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 theArguments a filter parameters
+  /// \param theObject an object
   /// \param theAttribute an attribute to check
   /// \param theShape a shape
-  MODELAPI_EXPORT bool isValid(const FeaturePtr& theFeature, const AttributePtr& theAttribute,
+  MODELAPI_EXPORT virtual bool isValid(const FeaturePtr& theFeature,
+                               const std::list<std::string>& theArguments,
+                               const ObjectPtr& theObject, const AttributePtr& theAttribute,
                                const GeomShapePtr& theShape) const;
 };
 
index 9dc8c506384745b66ef27ccd568af42c1332c7b1..30787899f28139e6146833f6afbc4ebad2bc6cbb 100644 (file)
@@ -535,7 +535,7 @@ bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptr<G
       if (aShapeValidator) {
         DataPtr aData = myFeature->data();
         AttributeSelectionPtr aSelectAttr = aData->selection(attributeID());
-        if (!aShapeValidator->isValid(myFeature, aSelectAttr, theShape)) {
+        if (!aShapeValidator->isValid(myFeature, *aArgs, theObj, aSelectAttr, theShape)) {
           return false;
         }
       }
index d801aabacb294e48c188df5d896674172be61454..3b9c8dc2647db13f5a63a381a4564c8fca62e806 100644 (file)
@@ -21,6 +21,7 @@ SET(PROJECT_HEADERS
     SketchPlugin_ConstraintPerpendicular.h
     SketchPlugin_ConstraintRadius.h
     SketchPlugin_ConstraintRigid.h
+    SketchPlugin_ShapeValidator.h
     SketchPlugin_Validators.h
     SketchPlugin_ResultValidators.h 
 )
@@ -41,6 +42,7 @@ SET(PROJECT_SOURCES
     SketchPlugin_ConstraintPerpendicular.cpp
     SketchPlugin_ConstraintRadius.cpp
     SketchPlugin_ConstraintRigid.cpp
+    SketchPlugin_ShapeValidator.cpp
     SketchPlugin_Validators.cpp
     SketchPlugin_ResultValidators.cpp
 )
index c486acf65ee2f6898fa02caa30bb51c4b0174c70..20958c5e387540b81a96e000d6c150badd84cff8 100644 (file)
@@ -15,6 +15,7 @@
 #include <SketchPlugin_ConstraintRigid.h>
 #include <SketchPlugin_Validators.h>
 #include <SketchPlugin_ResultValidators.h>
+#include <SketchPlugin_ShapeValidator.h>
 
 #include <Events_Loop.h>
 #include <GeomDataAPI_Dir.h>
@@ -50,6 +51,8 @@ SketchPlugin_Plugin::SketchPlugin_Plugin()
   aFactory->registerValidator("SketchPlugin_ResultPoint", new SketchPlugin_ResultPointValidator);
   aFactory->registerValidator("SketchPlugin_ResultLine", new SketchPlugin_ResultLineValidator);
   aFactory->registerValidator("SketchPlugin_ResultArc", new SketchPlugin_ResultArcValidator);
+  aFactory->registerValidator("SketchPlugin_ShapeValidator",
+                              new SketchPlugin_ShapeValidator);
 
   // register this plugin
   ModelAPI_Session::get()->registerPlugin(this);
diff --git a/src/SketchPlugin/SketchPlugin_ShapeValidator.cpp b/src/SketchPlugin/SketchPlugin_ShapeValidator.cpp
new file mode 100644 (file)
index 0000000..1b27959
--- /dev/null
@@ -0,0 +1,54 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        Model_ResultValidators.cpp
+// Created:     27 Feb 2015
+// Author:      Natalia ERMOLAEVA
+
+#include "SketchPlugin_ShapeValidator.h"
+#include "SketchPlugin_Feature.h"
+
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Result.h>
+#include <ModelAPI_Tools.h>
+#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_ResultValidator.h>
+
+bool SketchPlugin_ShapeValidator::isValid(const FeaturePtr& theFeature,
+                                                  const std::list<std::string>& theArguments,
+                                                  const ObjectPtr& theObject,
+                                                  const AttributePtr& theAttribute,
+                                                  const GeomShapePtr& theShape) const
+{
+  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+  std::shared_ptr<GeomAPI_Shape> aShape = ModelAPI_Tools::shape(aResult);
+
+  // if the shapes are equal, that means that the given shape is a result.
+  // if the result is selected, the 
+  if (aShape->isEqual(theShape))
+    return true;
+
+  // found a non-external argument on the feature
+  std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
+  bool aHasNullParam = false;
+  bool aHasNonExternalParams = false;
+  for (; anIt != aLast; anIt++) {
+    std::string aParamA = *anIt;
+    std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
+          ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(aParamA));
+    if (anAttr) {
+      FeaturePtr anOtherFeature = ModelAPI_Feature::feature(anAttr->object());
+      if (anOtherFeature.get() != NULL) {
+        std::shared_ptr<SketchPlugin_Feature> aSketchFeature = 
+          std::dynamic_pointer_cast<SketchPlugin_Feature>(anOtherFeature);
+        if (aSketchFeature) {
+          aHasNonExternalParams = !aSketchFeature->isExternal();
+        }
+      }
+      else
+        aHasNullParam = true;
+    }
+  }
+  if (aHasNullParam || aHasNonExternalParams)
+    return true;
+  return false;
+}
diff --git a/src/SketchPlugin/SketchPlugin_ShapeValidator.h b/src/SketchPlugin/SketchPlugin_ShapeValidator.h
new file mode 100644 (file)
index 0000000..6e35f4d
--- /dev/null
@@ -0,0 +1,36 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File:        Model_ResultValidators.h
+// Created:     27 Feb 2015
+// Author:      Natalia ERMOLAEVA
+
+#ifndef SketchPlugin_ShapeValidator_H
+#define SketchPlugin_ShapeValidator_H
+
+#include <SketchPlugin.h>
+#include <ModelAPI_ShapeValidator.h>
+#include <ModelAPI_Object.h>
+
+/**\class SketchPlugin_ResultPointValidator
+ * \ingroup Validators
+ * \brief Validator for the points selection
+ *
+ * Allows to select points only.
+ */
+class SketchPlugin_ShapeValidator : public ModelAPI_ShapeValidator
+{
+public:
+  // returns true if there is an empty or non-external shape on the feature.
+  // in the given shape or in the list of attribute shapes
+  /// \param theFeature a feature to check
+  /// \param theArguments a filter parameters
+  /// \param theObject an object
+  /// \param theAttribute an attribute to check
+  /// \param theShape a shape
+  SKETCHPLUGIN_EXPORT virtual bool isValid(const FeaturePtr& theFeature,
+                               const std::list<std::string>& theArguments,
+                               const ObjectPtr& theObject, const AttributePtr& theAttribute,
+                               const GeomShapePtr& theShape) const;
+};
+
+#endif
index cc23f8e008231950cec71b37267a609564b6379e..2300c7a307a897c52fc0f8cc54dac1aeb8ded959 100644 (file)
         <sketch_constraint_shape_selector id="ConstraintEntityA" 
             label="First line" tooltip="Select a line" shape_types="edge">
             <selection_filter id="EdgeFilter" parameters="line"/>
+          <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
         </sketch_constraint_shape_selector>
         
         <sketch_constraint_shape_selector id="ConstraintEntityB" label="Last line" tooltip="Select a line" 
             shape_types="edge">
             <selection_filter id="EdgeFilter" parameters="line"/>
             <validator id="SketchPlugin_DifferentObjects"/>
+            <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityA"/>
         </sketch_constraint_shape_selector>
         
         <sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" internal="1" obligatory="0"/>
         <sketch_constraint_shape_selector id="ConstraintEntityA" 
             label="First line" tooltip="Select an line" 
             shape_types="edge">
-      <selection_filter id="EdgeFilter" parameters="line"/>
+          <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityB"/>
+          <selection_filter id="EdgeFilter" parameters="line"/>
     </sketch_constraint_shape_selector>
         
         <sketch_constraint_shape_selector id="ConstraintEntityB" 
             label="Last line" tooltip="Select an line" 
             shape_types="edge">
             <validator id="SketchPlugin_DifferentObjects"/>
-      <selection_filter id="EdgeFilter" parameters="line"/>
+          <validator id="SketchPlugin_ShapeValidator" parameters="ConstraintEntityA"/>
+          <selection_filter id="EdgeFilter" parameters="line"/>
     </sketch_constraint_shape_selector>
         <validator id="PartSet_PerpendicularValidator"/>
       </feature>