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 %1 type is not processed";
21 theError.arg(theAttribute->attributeType());
25 std::shared_ptr<ModelAPI_AttributeSelectionList> aCurSelList =
26 std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
28 DocumentPtr aDocument = theAttribute->owner()->document();
29 SessionPtr aMgr = ModelAPI_Session::get();
30 bool isPartSetDocument = aDocument == aMgr->moduleDocument();
32 std::string anErrorGroupName;
33 for(int i = 0; i < aCurSelList->size() && aValid; i++) {
34 std::shared_ptr<ModelAPI_AttributeSelection> aSelAttribute = aCurSelList->value(i);
35 ResultPtr aResult = aSelAttribute->context();
36 if (isPartSetDocument) // PartSet document: Result Part is valid
37 aValid = aResult->groupName() == ModelAPI_ResultPart::group();
38 else { // Part document: Result CompSolid is valid
39 aValid = aResult->groupName() == ModelAPI_ResultBody::group();
41 ResultCompSolidPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
42 aValid = aComp.get() != NULL;
46 anErrorGroupName = aResult->groupName();
49 std::string aResultGroupName = isPartSetDocument ? ModelAPI_ResultPart::group()
50 : ModelAPI_ResultBody::group();
51 theError = "Objects from the %1 group can be selected in the %2 document, "
52 "but an objects from the %3 group is selected.";
53 theError.arg(aResultGroupName).arg(aDocument->kind()).arg(anErrorGroupName);