]> SALOME platform Git repositories - modules/shaper.git/blob - src/FeaturesPlugin/FeaturesPlugin_ValidatorTransform.cpp
Salome HOME
9722f88361b267612baf4f5264c75aebe2b00975
[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 " + theAttribute->attributeType() + " type is not processed";
21     return false;
22   }
23
24   std::shared_ptr<ModelAPI_AttributeSelectionList> aCurSelList = 
25                            std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
26
27   DocumentPtr aDocument = theAttribute->owner()->document();
28   SessionPtr aMgr = ModelAPI_Session::get();
29   bool isPartSetDocument = aDocument == aMgr->moduleDocument();
30
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();
39       if (aValid) {
40         ResultCompSolidPtr aComp = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aResult);
41         aValid = aComp.get() != NULL;
42       }
43     }
44     if (!aValid)
45       anErrorGroupName = aResult->groupName();
46   }
47   if (!aValid) {
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.";
54   }
55   return aValid;
56 }