]> SALOME platform Git repositories - modules/shaper.git/blob - src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.cpp
Salome HOME
Issue #2052: Modification of parameters don't work (sketch, extrusion)
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_ValidatorTransform.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 #include "FeaturesPlugin_ValidatorTransform.h"
4
5 #include <Events_InfoMessage.h>
6
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"
12
13 bool FeaturesPlugin_ValidatorTransform::isValid(const AttributePtr& theAttribute,
14                                                 const std::list<std::string>& theArguments,
15                                                 Events_InfoMessage& theError) const
16 {
17   bool aValid = true;
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());
22     return false;
23   }
24
25   std::shared_ptr<ModelAPI_AttributeSelectionList> aCurSelList =
26                            std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
27
28   DocumentPtr aDocument = theAttribute->owner()->document();
29   SessionPtr aMgr = ModelAPI_Session::get();
30   bool isPartSetDocument = aDocument == aMgr->moduleDocument();
31
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();
40       if (aValid) {
41         ResultCompSolidPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
42         aValid = aComp.get() != NULL;
43       }
44     }
45     if (!aValid)
46       anErrorGroupName = aResult->groupName();
47   }
48   if (!aValid) {
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);
54   }
55   return aValid;
56 }