From: azv Date: Thu, 28 Nov 2019 07:27:02 +0000 (+0300) Subject: Issue #3093: Export Part - provide filter X-Git-Tag: V9_5_0a1~153 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0393e1dcf9d72684865dc6f8d174df22e045f6d8;p=modules%2Fshaper.git Issue #3093: Export Part - provide filter Select full results only. --- diff --git a/src/ExchangePlugin/CMakeLists.txt b/src/ExchangePlugin/CMakeLists.txt index d580a700f..3c6692e59 100644 --- a/src/ExchangePlugin/CMakeLists.txt +++ b/src/ExchangePlugin/CMakeLists.txt @@ -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}) diff --git a/src/ExchangePlugin/ExchangePlugin_Plugin.cpp b/src/ExchangePlugin/ExchangePlugin_Plugin.cpp index 3d07a73cd..ccb5439e7 100644 --- a/src/ExchangePlugin/ExchangePlugin_Plugin.cpp +++ b/src/ExchangePlugin/ExchangePlugin_Plugin.cpp @@ -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) diff --git a/src/ExchangePlugin/ExchangePlugin_Validators.cpp b/src/ExchangePlugin/ExchangePlugin_Validators.cpp index 33464e087..68490efc6 100644 --- a/src/ExchangePlugin/ExchangePlugin_Validators.cpp +++ b/src/ExchangePlugin/ExchangePlugin_Validators.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -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& theArguments, + Events_InfoMessage& theError) const +{ + std::string anAttributeType = theAttribute->attributeType(); + if(anAttributeType == ModelAPI_AttributeSelection::typeId()) { + AttributeSelectionPtr anAttrSelection = + std::dynamic_pointer_cast(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(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/ExchangePlugin/ExchangePlugin_Validators.h b/src/ExchangePlugin/ExchangePlugin_Validators.h index b8569a5db..9d0de6c65 100644 --- a/src/ExchangePlugin/ExchangePlugin_Validators.h +++ b/src/ExchangePlugin/ExchangePlugin_Validators.h @@ -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& theArguments, + Events_InfoMessage& theError) const; +}; + #endif diff --git a/src/ExchangePlugin/plugin-Exchange.xml b/src/ExchangePlugin/plugin-Exchange.xml index b2da9c048..ecb36cf17 100644 --- a/src/ExchangePlugin/plugin-Exchange.xml +++ b/src/ExchangePlugin/plugin-Exchange.xml @@ -54,6 +54,8 @@ + + diff --git a/src/GeomValidators/CMakeLists.txt b/src/GeomValidators/CMakeLists.txt index 18e5c437c..71d098704 100644 --- a/src/GeomValidators/CMakeLists.txt +++ b/src/GeomValidators/CMakeLists.txt @@ -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 index 000000000..35d6008b5 --- /dev/null +++ b/src/GeomValidators/GeomValidators_GlobalSelection.cpp @@ -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 + +#include +#include +#include +#include +#include + +bool GeomValidators_GlobalSelection::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const +{ + std::string anAttributeType = theAttribute->attributeType(); + if(anAttributeType == ModelAPI_AttributeSelection::typeId()) { + AttributeSelectionPtr anAttrSelection = + std::dynamic_pointer_cast(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(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 index 000000000..3837478ac --- /dev/null +++ b/src/GeomValidators/GeomValidators_GlobalSelection.h @@ -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 + +#include +#include + +/** + * 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& theArguments, + Events_InfoMessage& theError) const; +}; + +#endif diff --git a/src/GeomValidators/GeomValidators_Plugin.cpp b/src/GeomValidators/GeomValidators_Plugin.cpp index a30aa6a15..77a27ea8a 100644 --- a/src/GeomValidators/GeomValidators_Plugin.cpp +++ b/src/GeomValidators/GeomValidators_Plugin.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -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);