1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include "FeaturesPlugin_ValidatorTransform.h"
5 #include <Events_InfoMessage.h>
7 #include "ModelAPI_AttributeSelectionList.h"
8 #include "ModelAPI_ResultPart.h"
9 #include "ModelAPI_ResultBody.h"
10 #include "ModelAPI_ResultCompSolid.h"
11 #include "ModelAPI_Session.h"
13 bool FeaturesPlugin_ValidatorTransform::isValid(const AttributePtr& theAttribute,
14 const std::list<std::string>& theArguments,
15 Events_InfoMessage& theError) const
18 std::string anAttributeType = theAttribute->attributeType();
19 if (anAttributeType != ModelAPI_AttributeSelectionList::typeId()) {
20 theError = "The attribute with the " + theAttribute->attributeType() + " type is not processed";
24 std::shared_ptr<ModelAPI_AttributeSelectionList> aCurSelList =
25 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
27 DocumentPtr aDocument = theAttribute->owner()->document();
28 SessionPtr aMgr = ModelAPI_Session::get();
29 bool isPartSetDocument = aDocument == aMgr->moduleDocument();
31 std::string anErrorGroupName;
32 for(int i = 0; i < aCurSelList->size() && aValid; i++) {
33 std::shared_ptr<ModelAPI_AttributeSelection> aSelAttribute = aCurSelList->value(i);
34 ResultPtr aResult = aSelAttribute->context();
35 if (isPartSetDocument) // PartSet document: Result Part is valid
36 aValid = aResult->groupName() == ModelAPI_ResultPart::group();
37 else { // Part document: Result CompSolid is valid
38 aValid = aResult->groupName() == ModelAPI_ResultBody::group();
40 ResultCompSolidPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
41 aValid = aComp.get() != NULL;
45 anErrorGroupName = aResult->groupName();
48 std::string aResultGroupName = isPartSetDocument ? ModelAPI_ResultPart::group()
49 : ModelAPI_ResultBody::group();
50 theError = "Objects from the " + aResultGroupName +
51 " group can be selected in the " + aDocument->kind() +
52 "document, but an objects from the " + anErrorGroupName +
53 " group is selected.";