Select full results only.
${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
ModelHighAPI
GeomAPI
GeomAlgoAPI
+ GeomValidators
XAOShaper
)
SOURCE_GROUP ("Resource Files" FILES ${TEXT_RESOURCES})
new ExchangePlugin_ImportFormatValidator);
aFactory->registerValidator("ExchangePlugin_ExportFormat",
new ExchangePlugin_ExportFormatValidator);
+ aFactory->registerValidator("ExchangePlugin_InHistory",
+ new ExchangePlugin_InHistoryValidator);
}
FeaturePtr ExchangePlugin_Plugin::createFeature(std::string theFeatureID)
#include <ModelAPI_Object.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeSelectionList.h>
#include <list>
#include <string>
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;
+}
};
+/**
+ * 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
<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>
GeomValidators_ValueOrder.h
GeomValidators_Intersected.h
GeomValidators_NotSelfIntersected.h
+ GeomValidators_GlobalSelection.h
)
SET(PROJECT_SOURCES
GeomValidators_ValueOrder.cpp
GeomValidators_Intersected.cpp
GeomValidators_NotSelfIntersected.cpp
+ GeomValidators_GlobalSelection.cpp
)
SET(PROJECT_LIBRARIES
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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
#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>
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);