Salome HOME
Pipe feature
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Validators.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        FeaturesPlugin_Validators.cpp
4 // Created:     22 March 2016
5 // Author:      Dmitry Bobylev
6
7 #include "FeaturesPlugin_Validators.h"
8
9 #include <ModelAPI_Attribute.h>
10 #include <ModelAPI_AttributeSelectionList.h>
11 #include <ModelAPI_AttributeString.h>
12
13 //=================================================================================================
14 bool FeaturesPlugin_PipeLocationsValidator::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
15                                                     const std::list<std::string>& theArguments,
16                                                     std::string& theError) const
17 {
18   static const std::string aCreationMethodID = "creation_method";
19   static const std::string aBaseObjectsID = "base_objects";
20   static const std::string aLocationsID = "locations_objects";
21
22
23   if(theFeature->getKind() != "Pipe") {
24     theError = "Feature \"" + theFeature->getKind() + "\" does not supported by this validator.";
25     return false;
26   }
27
28   AttributeStringPtr aCreationMethodAttr = theFeature->string(aCreationMethodID);
29   if(!aCreationMethodAttr.get()) {
30     theError = "Could not get \"" + aCreationMethodID + "\" attribute.";
31     return false;
32   }
33
34   if(aCreationMethodAttr->value() != "locations") {
35     return true;
36   }
37
38   AttributeSelectionListPtr aBaseObjectsSelectionList = theFeature->selectionList(aBaseObjectsID);
39   if(!aBaseObjectsSelectionList.get()) {
40     theError = "Could not get \"" + aBaseObjectsID + "\" attribute.";
41     return false;
42   }
43
44   AttributeSelectionListPtr aLocationsSelectionList = theFeature->selectionList(aLocationsID);
45   if(!aLocationsSelectionList.get()) {
46     theError = "Could not get \"" + aBaseObjectsID + "\" attribute.";
47     return false;
48   }
49
50   if(aLocationsSelectionList->size() > 0 && aLocationsSelectionList->size() != aBaseObjectsSelectionList->size()) {
51     theError = "Number of locations should be the same as base objects.";
52     return false;
53   }
54
55   return true;
56 }
57
58 //=================================================================================================
59 bool FeaturesPlugin_PipeLocationsValidator::isNotObligatory(std::string theFeature, std::string theAttribute)
60 {
61   if(theFeature == "Pipe" && theAttribute == "locations") {
62     return true;
63   }
64   return false;
65 }