]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #3093: Export Part - provide filter
authorazv <azv@opencascade.com>
Thu, 28 Nov 2019 07:27:02 +0000 (10:27 +0300)
committerazv <azv@opencascade.com>
Thu, 28 Nov 2019 07:27:02 +0000 (10:27 +0300)
Select full results only.

src/ExchangePlugin/CMakeLists.txt
src/ExchangePlugin/ExchangePlugin_Plugin.cpp
src/ExchangePlugin/ExchangePlugin_Validators.cpp
src/ExchangePlugin/ExchangePlugin_Validators.h
src/ExchangePlugin/plugin-Exchange.xml
src/GeomValidators/CMakeLists.txt
src/GeomValidators/GeomValidators_GlobalSelection.cpp [new file with mode: 0644]
src/GeomValidators/GeomValidators_GlobalSelection.h [new file with mode: 0644]
src/GeomValidators/GeomValidators_Plugin.cpp

index d580a700f8bf7a5a652fb5e342adad432ba81a11..3c6692e59eb3a8ab31d25c336d76c6f069337ae7 100644 (file)
@@ -26,6 +26,7 @@ INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/Events
                     ${PROJECT_SOURCE_DIR}/src/ModelHighAPI
                     ${PROJECT_SOURCE_DIR}/src/GeomAPI
                     ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI
+                    ${PROJECT_SOURCE_DIR}/src/GeomValidators
                     ${PROJECT_SOURCE_DIR}/src/XAO
                     ${PROJECT_SOURCE_DIR}/src/ConstructionPlugin
                     ${PROJECT_SOURCE_DIR}/src/PartSetPlugin
@@ -71,6 +72,7 @@ SET(PROJECT_LIBRARIES
     ModelHighAPI
     GeomAPI
     GeomAlgoAPI
+    GeomValidators
     XAOShaper
 )
 SOURCE_GROUP ("Resource Files" FILES ${TEXT_RESOURCES})
index 3d07a73cd645f9c3bf14b0a61dc3e9b8ed3f4e3f..ccb5439e7b331337437d4a8b17ad19d2a0586693 100644 (file)
@@ -45,6 +45,8 @@ ExchangePlugin_Plugin::ExchangePlugin_Plugin()
                               new ExchangePlugin_ImportFormatValidator);
   aFactory->registerValidator("ExchangePlugin_ExportFormat",
                               new ExchangePlugin_ExportFormatValidator);
+  aFactory->registerValidator("ExchangePlugin_InHistory",
+                              new ExchangePlugin_InHistoryValidator);
 }
 
 FeaturePtr ExchangePlugin_Plugin::createFeature(std::string theFeatureID)
index 33464e0874f11c3fe1661a83ae9819b0a0a968d7..68490efc6d0e659f48d267f811d6faf5b6f2584c 100644 (file)
@@ -27,6 +27,7 @@
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeSelectionList.h>
 
 #include <list>
 #include <string>
@@ -98,3 +99,45 @@ bool ExchangePlugin_FormatValidator::isValid(const AttributePtr& theAttribute,
   theError = "File name does not end with any available format.";
   return false;
 }
+
+
+bool ExchangePlugin_InHistoryValidator::isValid(const AttributePtr& theAttribute,
+                                                const std::list<std::string>& theArguments,
+                                                Events_InfoMessage& theError) const
+{
+  std::string anAttributeType = theAttribute->attributeType();
+  if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
+    AttributeSelectionPtr anAttrSelection =
+      std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+    ResultPtr aContext = anAttrSelection->context();
+    if (!aContext.get()) {
+      theError = "Error: Context is empty.";
+      return false;
+    }
+
+    FeaturePtr aFeature = ModelAPI_Feature::feature(aContext);
+    if (!aFeature->isInHistory()) {
+      theError = "Error: Feature is not in history.";
+      return false;
+    }
+  } else if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
+    AttributeSelectionListPtr anAttrSelectionList =
+      std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+
+    // All objects should not be result constructions.
+    for(int anIndex = 0, aSize = anAttrSelectionList->size(); anIndex < aSize; ++anIndex) {
+      AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
+      if(!isValid(anAttrSelection, theArguments, theError)) {
+        return false;
+      }
+    }
+  } else {
+// LCOV_EXCL_START
+    theError = "Error: Attribute \"%1\" does not supported by this validator.";
+    theError.arg(anAttributeType);
+    return false;
+// LCOV_EXCL_STOP
+  }
+
+  return true;
+}
index b8569a5db3c544a90b962a40c89be439284cd08a..9d0de6c6507d53cddb9c0a93fa3a99a6f3911614 100644 (file)
@@ -71,4 +71,20 @@ class ExchangePlugin_ExportFormatValidator : public ExchangePlugin_FormatValidat
 
 };
 
+/**
+ *  Check the selected result is in history (avoid Origin and coordinate axes and planes).
+ */
+class ExchangePlugin_InHistoryValidator : public ModelAPI_AttributeValidator
+{
+public:
+  /// \return True if the attribute is valid.
+  ///         It checks whether the selected object is in history.
+  /// \param[in] theAttribute an attribute to check
+  /// \param[in] theArguments a filter parameters
+  /// \param[out] theError error message.
+  virtual bool isValid(const AttributePtr& theAttribute,
+                       const std::list<std::string>& theArguments,
+                       Events_InfoMessage& theError) const;
+};
+
 #endif
index b2da9c048c13a88bf0b6d8cf40d3f5eef47a1f44..ecb36cf172de195757c549d24e225ecc78b39097 100644 (file)
@@ -54,6 +54,8 @@
         <multi_selector id="selection_list"
                         tooltip="Select features or results"
                         shape_types="Vertices Edges Faces Solids Compsolids Objects">
+          <validator id="GeomValidators_GlobalSelection" />
+          <validator id="ExchangePlugin_InHistory" />
         </multi_selector>
       </feature>
     </group>
index 18e5c437c1cd10d24fbde0d7dc9328af5d1a9b8c..71d098704cce957b0b4e13484b02570a7d7a8380 100644 (file)
@@ -37,6 +37,7 @@ SET(PROJECT_HEADERS
     GeomValidators_ValueOrder.h
     GeomValidators_Intersected.h
     GeomValidators_NotSelfIntersected.h
+    GeomValidators_GlobalSelection.h
 )
 
 SET(PROJECT_SOURCES
@@ -56,6 +57,7 @@ SET(PROJECT_SOURCES
     GeomValidators_ValueOrder.cpp
     GeomValidators_Intersected.cpp
     GeomValidators_NotSelfIntersected.cpp
+    GeomValidators_GlobalSelection.cpp
 )
 
 SET(PROJECT_LIBRARIES
diff --git a/src/GeomValidators/GeomValidators_GlobalSelection.cpp b/src/GeomValidators/GeomValidators_GlobalSelection.cpp
new file mode 100644 (file)
index 0000000..35d6008
--- /dev/null
@@ -0,0 +1,69 @@
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "GeomValidators_GlobalSelection.h"
+
+#include <Events_InfoMessage.h>
+
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_Tools.h>
+#include <ModelAPI_ResultBody.h>
+
+bool GeomValidators_GlobalSelection::isValid(const AttributePtr& theAttribute,
+                                             const std::list<std::string>& theArguments,
+                                             Events_InfoMessage& theError) const
+{
+  std::string anAttributeType = theAttribute->attributeType();
+  if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
+    AttributeSelectionPtr anAttrSelection =
+      std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+    ResultPtr aContext = anAttrSelection->context();
+    if (!aContext.get()) {
+      theError = "Error: Context is empty.";
+      return false;
+    }
+
+    GeomShapePtr aShape = anAttrSelection->value();
+    if (aShape && !aShape->isEqual(aContext->shape())) {
+      theError = "Error: Local selection not allowed.";
+      return false;
+    }
+  } else if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
+    AttributeSelectionListPtr anAttrSelectionList =
+      std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+
+    // All objects should not be result constructions.
+    for(int anIndex = 0, aSize = anAttrSelectionList->size(); anIndex < aSize; ++anIndex) {
+      AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
+      if(!isValid(anAttrSelection, theArguments, theError)) {
+        return false;
+      }
+    }
+  } else {
+// LCOV_EXCL_START
+    theError = "Error: Attribute \"%1\" does not supported by this validator.";
+    theError.arg(anAttributeType);
+    return false;
+// LCOV_EXCL_STOP
+  }
+
+  return true;
+}
diff --git a/src/GeomValidators/GeomValidators_GlobalSelection.h b/src/GeomValidators/GeomValidators_GlobalSelection.h
new file mode 100644 (file)
index 0000000..3837478
--- /dev/null
@@ -0,0 +1,44 @@
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef GeomValidators_GlobalSelection_H
+#define GeomValidators_GlobalSelection_H
+
+#include <GeomValidators.h>
+
+#include <ModelAPI_AttributeValidator.h>
+#include <ModelAPI_Attribute.h>
+
+/**
+ *  Check the Selection/SelectionList attribute for result selected.
+ */
+class GeomValidators_GlobalSelection : public ModelAPI_AttributeValidator
+{
+public:
+  /// \return True if the attribute is valid.
+  ///         It checks whether the selected object is a full result.
+  /// \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,
+                                             Events_InfoMessage& theError) const;
+};
+
+#endif
index a30aa6a156fe4558f4f32f1f2c85e8e46e5eb380..77a27ea8ad6ec5698656dc03bcd61a888f2534ef 100644 (file)
@@ -25,6 +25,7 @@
 #include <GeomValidators_DifferentShapes.h>
 #include <GeomValidators_Face.h>
 #include <GeomValidators_Finite.h>
+#include <GeomValidators_GlobalSelection.h>
 #include <GeomValidators_ShapeType.h>
 #include <GeomValidators_ZeroOffset.h>
 #include <GeomValidators_FeatureKind.h>
@@ -60,6 +61,7 @@ GeomValidators_Plugin::GeomValidators_Plugin()
   aFactory->registerValidator("GeomValidators_Intersected", new GeomValidators_Intersected);
   aFactory->registerValidator("GeomValidators_NotSelfIntersected",
                               new GeomValidators_NotSelfIntersected);
+  aFactory->registerValidator("GeomValidators_GlobalSelection", new GeomValidators_GlobalSelection);
 
   // Do not register this plugin because it doesn't create features
   //ModelAPI_Session::get()->registerPlugin(this);