From: nds Date: Wed, 16 Sep 2015 15:09:31 +0000 (+0300) Subject: Issue #839 Selection of Part sub-results X-Git-Tag: V_1.4.0~53 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=23898b690da4986d891bde5b124bbcec7e8144f1;p=modules%2Fshaper.git Issue #839 Selection of Part sub-results --- diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 7650ed84f..ab09c8cf3 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -24,6 +24,7 @@ SET(PROJECT_HEADERS FeaturesPlugin_RevolutionBoolean.h FeaturesPlugin_RevolutionCut.h FeaturesPlugin_RevolutionFuse.h + FeaturesPlugin_ValidatorTransform.h ) SET(PROJECT_SOURCES @@ -46,6 +47,7 @@ SET(PROJECT_SOURCES FeaturesPlugin_RevolutionBoolean.cpp FeaturesPlugin_RevolutionCut.cpp FeaturesPlugin_RevolutionFuse.cpp + FeaturesPlugin_ValidatorTransform.cpp ) SET(XML_RESOURCES diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp index a92358003..26a5b37e6 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -30,6 +31,11 @@ static FeaturesPlugin_Plugin* MY_FEATURES_INSTANCE = new FeaturesPlugin_Plugin() FeaturesPlugin_Plugin::FeaturesPlugin_Plugin() { + SessionPtr aMgr = ModelAPI_Session::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + aFactory->registerValidator("FeaturesPlugin_ValidatorTransform", + new FeaturesPlugin_ValidatorTransform); + // register this plugin ModelAPI_Session::get()->registerPlugin(this); } diff --git a/src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.cpp b/src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.cpp new file mode 100755 index 000000000..570d1fb6f --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.cpp @@ -0,0 +1,54 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#include "FeaturesPlugin_ValidatorTransform.h" + +#include "ModelAPI_AttributeSelectionList.h" +#include "ModelAPI_ResultPart.h" +#include "ModelAPI_ResultBody.h" +#include "ModelAPI_ResultCompSolid.h" +#include "ModelAPI_Session.h" + +bool FeaturesPlugin_ValidatorTransform::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const +{ + bool aValid = true; + std::string anAttributeType = theAttribute->attributeType(); + if (anAttributeType != ModelAPI_AttributeSelectionList::typeId()) { + theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed"; + return false; + } + + std::shared_ptr aCurSelList = + std::dynamic_pointer_cast(theAttribute); + + DocumentPtr aDocument = theAttribute->owner()->document(); + SessionPtr aMgr = ModelAPI_Session::get(); + bool isPartSetDocument = aDocument == aMgr->moduleDocument(); + + std::string anErrorGroupName; + for(int i = 0; i < aCurSelList->size() && aValid; i++) { + std::shared_ptr aSelAttribute = aCurSelList->value(i); + ResultPtr aResult = aSelAttribute->context(); + if (isPartSetDocument) // PartSet document: Result Part is valid + aValid = aResult->groupName() == ModelAPI_ResultPart::group(); + else { // Part document: Result CompSolid is valid + aValid = aResult->groupName() == ModelAPI_ResultBody::group(); + if (aValid) { + ResultCompSolidPtr aComp = std::dynamic_pointer_cast(aResult); + aValid = aComp.get() != NULL; + } + } + if (!aValid) + anErrorGroupName = aResult->groupName(); + } + if (!aValid) { + std::string aResultGroupName = isPartSetDocument ? ModelAPI_ResultPart::group() + : ModelAPI_ResultBody::group(); + theError = "Objects from the " + aResultGroupName + + " group can be selected in the " + aDocument->kind() + + "document, but an objects from the " + anErrorGroupName + + " group is selected."; + } + return aValid; +} diff --git a/src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.h b/src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.h new file mode 100755 index 000000000..b1bb5c256 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.h @@ -0,0 +1,27 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: FeaturesPlugin_ValidatorTransform.h +// Created: 16 Sep 2015 +// Author: Natalia ERMOLAEVA + +#ifndef FeaturesPlugin_ValidatorTransform_H +#define FeaturesPlugin_ValidatorTransform_H + +#include "ModelAPI_AttributeValidator.h" + +/** +* \ingroup Validators +* A validator of selection +*/ +class FeaturesPlugin_ValidatorTransform : public ModelAPI_AttributeValidator +{ + public: + //! returns true if attribute is valid + //! \param theAttribute the checked attribute + //! \param theArguments arguments of the attribute + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const; +}; + +#endif diff --git a/src/FeaturesPlugin/placement_widget.xml b/src/FeaturesPlugin/placement_widget.xml index 4403f94f0..48dab601c 100644 --- a/src/FeaturesPlugin/placement_widget.xml +++ b/src/FeaturesPlugin/placement_widget.xml @@ -7,6 +7,7 @@ tooltip="Select a solid objects" type_choice="" concealment="true" > + + +