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