]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Added selection validator for intersection. Fixed dll exports.
authordbv <dbv@opencascade.com>
Tue, 16 Feb 2016 09:14:33 +0000 (12:14 +0300)
committerdbv <dbv@opencascade.com>
Tue, 16 Feb 2016 12:15:00 +0000 (15:15 +0300)
src/FeaturesPlugin/intersection_widget.xml
src/GeomValidators/CMakeLists.txt
src/GeomValidators/GeomValidators_BodyShapes.h
src/GeomValidators/GeomValidators_BooleanSelection.h
src/GeomValidators/GeomValidators_DifferentShapes.h
src/GeomValidators/GeomValidators_IntersectionSelection.cpp [new file with mode: 0644]
src/GeomValidators/GeomValidators_IntersectionSelection.h [new file with mode: 0644]
src/GeomValidators/GeomValidators_Plugin.cpp

index 988f3e07f366b32eb09e889ffadad6aa27f137ce..7dac829aebe6984738646542fe834aed6e6cf4a8 100644 (file)
@@ -9,7 +9,7 @@
     use_choice="false"
     concealment="true">
     <validator id="PartSet_DifferentObjects"/>
-    <validator id="GeomValidators_ShapeType" parameters="edge,face,solid"/>
+    <validator id="GeomValidators_IntersectionSelection"/>
   </multi_selector>
   <multi_selector id="tool_objects"
     label="Tool objects"
@@ -19,6 +19,6 @@
     use_choice="false"
     concealment="true">
     <validator id="PartSet_DifferentObjects"/>
-    <validator id="GeomValidators_ShapeType" parameters="edge,face,solid"/>
+    <validator id="GeomValidators_IntersectionSelection"/>
   </multi_selector>
 </source>
index ceb12b40d975710bb152119ea0c6fdccd7768d59..b18ae35aad8b9aa746ff6259000e04cd8196f89d 100644 (file)
@@ -18,6 +18,7 @@ SET(PROJECT_HEADERS
     GeomValidators_ZeroOffset.h
     GeomValidators_Different.h
     GeomValidators_BooleanSelection.h
+    GeomValidators_IntersectionSelection.h
 )
 
 SET(PROJECT_SOURCES
@@ -35,6 +36,7 @@ SET(PROJECT_SOURCES
     GeomValidators_ZeroOffset.cpp
     GeomValidators_Different.cpp
     GeomValidators_BooleanSelection.cpp
+    GeomValidators_IntersectionSelection.cpp
 )
 
 SET(PROJECT_LIBRARIES
index 19fe81f79a7953bdbb6837ef0ab8cc431cd10646..33e2f8f504bc240ad219711b86fc9f3b219562e5 100644 (file)
@@ -7,7 +7,7 @@
 #ifndef GeomValidators_BodyShapes_H
 #define GeomValidators_BodyShapes_H
 
-#include <ModelAPI.h>
+#include <GeomValidators.h>
 
 #include <ModelAPI_AttributeValidator.h>
 #include <ModelAPI_Attribute.h>
@@ -23,9 +23,9 @@ public:
   /// \param[in] theAttribute an attribute to check
   /// \param[in] theArguments a filter parameters
   /// \param[out] theError error message.
-  MODELAPI_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
-                                       const std::list<std::string>& theArguments,
-                                       std::string& theError) const;
+  GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+                                             const std::list<std::string>& theArguments,
+                                             std::string& theError) const;
 };
 
 #endif
index 59b5d3ce68c13cc208a7ff4baf241732d506efab..19ced9baa4c1891e15523c4b5d71c8c952714028 100644 (file)
@@ -7,7 +7,7 @@
 #ifndef GeomValidators_BooleanSelection_H
 #define GeomValidators_BooleanSelection_H
 
-#include <ModelAPI.h>
+#include <GeomValidators.h>
 
 #include <ModelAPI_AttributeValidator.h>
 #include <ModelAPI_Attribute.h>
@@ -23,9 +23,9 @@ public:
   /// \param[in] theAttribute an attribute to check.
   /// \param[in] theArguments a filter parameters.
   /// \param[out] theError error message.
-  MODELAPI_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
-                                       const std::list<std::string>& theArguments,
-                                       std::string& theError) const;
+  GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+                                             const std::list<std::string>& theArguments,
+                                             std::string& theError) const;
 };
 
 #endif
index 033ef1b3c30be3486dfab6e331392d2bbc893371..ac3dd5b581a9bbd3fa90dc701585cc645abe9640 100644 (file)
@@ -7,7 +7,7 @@
 #ifndef GeomValidators_DifferentShapes_H
 #define GeomValidators_DifferentShapes_H
 
-#include <ModelAPI.h>
+#include <GeomValidators.h>
 
 #include <ModelAPI_AttributeValidator.h>
 #include <ModelAPI_Attribute.h>
@@ -23,9 +23,9 @@ public:
   /// \param[in] theAttribute an attribute to check
   /// \param[in] theArguments a filter parameters
   /// \param[out] theError error message.
-  MODELAPI_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
-                                       const std::list<std::string>& theArguments,
-                                       std::string& theError) const;
+  GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+                                             const std::list<std::string>& theArguments,
+                                             std::string& theError) const;
 };
 
 #endif
diff --git a/src/GeomValidators/GeomValidators_IntersectionSelection.cpp b/src/GeomValidators/GeomValidators_IntersectionSelection.cpp
new file mode 100644 (file)
index 0000000..e3899d7
--- /dev/null
@@ -0,0 +1,69 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomValidators_IntersectionSelection.cpp
+// Created:     16 Feb 2016
+// Author:      Dmitry Bobylev
+
+#include "GeomValidators_IntersectionSelection.h"
+
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_Feature.h>
+
+bool GeomValidators_IntersectionSelection::isValid(const AttributePtr& theAttribute,
+                                                   const std::list<std::string>& theArguments,
+                                                   std::string& theError) const
+{
+  if(!theAttribute.get()) {
+    theError = "Error: empty selection.";
+    return false;
+  }
+  FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+  AttributeSelectionListPtr anAttrSelectionList = std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+  for(int anIndex = 0; anIndex < anAttrSelectionList->size(); ++anIndex) {
+    AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
+    if(!anAttrSelection.get()) {
+      theError = "Error: empty attribute selection.";
+      return false;
+    }
+    ResultPtr aContext = anAttrSelection->context();
+    if(!aContext.get()) {
+      theError = "Error: empty selection context.";
+      return false;
+    }
+    FeaturePtr aFeature = ModelAPI_Feature::feature(aContext);
+    if(!aFeature.get()) {
+      theError = "Error: empty feature.";
+      return false;
+    }
+    std::string aFeatureKind = aFeature->getKind();
+    if(aFeatureKind == "Sketch" ||
+       aFeatureKind == "Plane" ||
+       aFeatureKind == "Axis") {
+      theError = "Error: ";
+      theError += aFeatureKind;
+      theError += " shape is not allowed for selection.";
+      return false;
+    }
+    std::shared_ptr<GeomAPI_Shape> aShape = anAttrSelection->value();
+    if(!aShape.get()) {
+      aShape = aContext->shape();
+    }
+    if(!aShape.get()) {
+      theError = "Error: empty shape.";
+      return false;
+    }
+    int aShapeType = aShape->shapeType();
+    // Allow to select edges, faces and solids.
+    if(aShapeType != GeomAPI_Shape::EDGE &&
+       aShapeType != GeomAPI_Shape::FACE &&
+       aShapeType != GeomAPI_Shape::SOLID &&
+       aShapeType != GeomAPI_Shape::COMPSOLID &&
+       aShapeType != GeomAPI_Shape::COMPOUND) {
+      theError = "Error: selected shape has the wrong type.";
+      return false;
+    }
+  }
+
+  return true;
+}
diff --git a/src/GeomValidators/GeomValidators_IntersectionSelection.h b/src/GeomValidators/GeomValidators_IntersectionSelection.h
new file mode 100644 (file)
index 0000000..6773a11
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomValidators_IntersectionSelection.h
+// Created:     16 Feb 2016
+// Author:      Dmitry Bobylev
+
+#ifndef GeomValidators_IntersectionSelection_H
+#define GeomValidators_IntersectionSelection_H
+
+#include <GeomValidators.h>
+
+#include <ModelAPI_AttributeValidator.h>
+#include <ModelAPI_Attribute.h>
+
+/// \class GeomValidators_ZeroOffset
+/// \ingroup Validators
+/// \brief Validates selection for boolean operation.
+class GeomValidators_IntersectionSelection: public ModelAPI_AttributeValidator
+{
+public:
+  /// \return True if the attribute is valid. It checks whether the selection
+  /// is acceptable for boolean operation.
+  /// \param[in] theAttribute an attribute to check.
+  /// \param[in] theArguments a filter parameters.
+  /// \param[out] theError error message.
+  GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+                                             const std::list<std::string>& theArguments,
+                                             std::string& theError) const;
+};
+
+#endif
index 497e0a70a78f344d72543d0b6760e3069ed0dde9..824206f632a4de4dfe64c5e12599805b8313c4f3 100644 (file)
@@ -13,6 +13,7 @@
 #include <GeomValidators_PartitionArguments.h>
 #include <GeomValidators_ShapeType.h>
 #include <GeomValidators_ZeroOffset.h>
+#include <GeomValidators_IntersectionSelection.h>
 
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
@@ -37,6 +38,7 @@ GeomValidators_Plugin::GeomValidators_Plugin()
   aFactory->registerValidator("GeomValidators_ShapeType", new GeomValidators_ShapeType);
   aFactory->registerValidator("GeomValidators_ZeroOffset", new GeomValidators_ZeroOffset);
   aFactory->registerValidator("GeomValidators_BooleanSelection", new GeomValidators_BooleanSelection);
+  aFactory->registerValidator("GeomValidators_IntersectionSelection", new GeomValidators_IntersectionSelection);
 
   // register this plugin
   ModelAPI_Session::get()->registerPlugin(this);