From 1f41ff707094ce873abe9bbb95faaa363665a205 Mon Sep 17 00:00:00 2001 From: dbv Date: Mon, 21 Dec 2015 17:20:46 +0300 Subject: [PATCH] Bug #1045: Group not exported in GEOM --- src/FeaturesPlugin/group_widget.xml | 8 ++-- src/GeomValidators/CMakeLists.txt | 4 +- .../GeomValidators_BodyShapes.cpp | 37 +++++++++++++++++++ .../GeomValidators_BodyShapes.h | 31 ++++++++++++++++ src/GeomValidators/GeomValidators_Plugin.cpp | 2 + 5 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 src/GeomValidators/GeomValidators_BodyShapes.cpp create mode 100644 src/GeomValidators/GeomValidators_BodyShapes.h diff --git a/src/FeaturesPlugin/group_widget.xml b/src/FeaturesPlugin/group_widget.xml index 1b1825329..a39b7ac96 100644 --- a/src/FeaturesPlugin/group_widget.xml +++ b/src/FeaturesPlugin/group_widget.xml @@ -1,7 +1,9 @@ - + + + \ No newline at end of file diff --git a/src/GeomValidators/CMakeLists.txt b/src/GeomValidators/CMakeLists.txt index c9768eb39..4ac409c81 100644 --- a/src/GeomValidators/CMakeLists.txt +++ b/src/GeomValidators/CMakeLists.txt @@ -4,6 +4,7 @@ INCLUDE(Common) SET(PROJECT_HEADERS GeomValidators.h + GeomValidators_BodyShapes.h GeomValidators_BooleanArguments.h GeomValidators_ConstructionComposite.h GeomValidators_DifferentShapes.h @@ -19,6 +20,7 @@ SET(PROJECT_HEADERS ) SET(PROJECT_SOURCES + GeomValidators_BodyShapes.cpp GeomValidators_BooleanArguments.cpp GeomValidators_ConstructionComposite.cpp GeomValidators_DifferentShapes.cpp @@ -34,7 +36,7 @@ SET(PROJECT_SOURCES ) SET(PROJECT_LIBRARIES - ModelAPI + ModelAPI Events GeomAPI ) diff --git a/src/GeomValidators/GeomValidators_BodyShapes.cpp b/src/GeomValidators/GeomValidators_BodyShapes.cpp new file mode 100644 index 000000000..734938ecc --- /dev/null +++ b/src/GeomValidators/GeomValidators_BodyShapes.cpp @@ -0,0 +1,37 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomValidators_BodyShapes.cpp +// Created: 21 December 2015 +// Author: Dmitry Bobylev + +#include "GeomValidators_BodyShapes.h" + +#include +#include + +bool GeomValidators_BodyShapes::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const +{ + std::string anAttributeType = theAttribute->attributeType(); + if (anAttributeType == ModelAPI_AttributeSelectionList::typeId()) { + AttributeSelectionListPtr aSelectionListAttr = + std::dynamic_pointer_cast(theAttribute); + // all context objects should not be sketch entities + for(int i = 0, aSize = aSelectionListAttr->size(); i < aSize; i++) { + AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i); + ObjectPtr anObject = aSelectAttr->context(); + if (!anObject.get()) + return false; + else { + FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); + std::string aFeatureKind = aFeature->getKind(); + if(aFeatureKind == "Sketch") { + return false; + } + } + } + } + + return true; +} diff --git a/src/GeomValidators/GeomValidators_BodyShapes.h b/src/GeomValidators/GeomValidators_BodyShapes.h new file mode 100644 index 000000000..19fe81f79 --- /dev/null +++ b/src/GeomValidators/GeomValidators_BodyShapes.h @@ -0,0 +1,31 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomValidators_BodyShapes.h +// Created: 21 December 2015 +// Author: Dmitry Bobylev + +#ifndef GeomValidators_BodyShapes_H +#define GeomValidators_BodyShapes_H + +#include + +#include +#include + +/** + * Generic validator for any attribute of a feature. + */ +class GeomValidators_BodyShapes : public ModelAPI_AttributeValidator +{ +public: + /// \return True if the attribute is valid. It checks whether the shape is a + /// body subshape. Does not allow select construction shapes. + /// \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& theArguments, + std::string& theError) const; +}; + +#endif diff --git a/src/GeomValidators/GeomValidators_Plugin.cpp b/src/GeomValidators/GeomValidators_Plugin.cpp index e8f8574a1..43d997084 100644 --- a/src/GeomValidators/GeomValidators_Plugin.cpp +++ b/src/GeomValidators/GeomValidators_Plugin.cpp @@ -2,6 +2,7 @@ #include +#include #include #include #include @@ -24,6 +25,7 @@ GeomValidators_Plugin::GeomValidators_Plugin() SessionPtr aMgr = ModelAPI_Session::get(); ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + aFactory->registerValidator("GeomValidators_BodyShapes", new GeomValidators_BodyShapes); aFactory->registerValidator("GeomValidators_BooleanArguments", new GeomValidators_BooleanArguments); aFactory->registerValidator("GeomValidators_ConstructionComposite", new GeomValidators_ConstructionComposite); aFactory->registerValidator("GeomValidators_Different", new GeomValidators_Different); -- 2.39.2