1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomValidators_BooleanArguments.cpp
4 // Created: 30 June 2015
5 // Author: Dmitry Bobylev
7 #include <GeomValidators_BooleanArguments.h>
9 #include <Events_InfoMessage.h>
11 #include <ModelAPI_AttributeInteger.h>
12 #include <ModelAPI_AttributeSelectionList.h>
13 #include <ModelAPI_ResultCompSolid.h>
14 #include <ModelAPI_Tools.h>
16 //=================================================================================================
17 bool GeomValidators_BooleanArguments::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
18 const std::list<std::string>& theArguments,
19 Events_InfoMessage& theError) const
21 if(theArguments.size() != 3) {
22 theError = "Wrong number of arguments (expected 3).";
26 int anObjectsNb = 0, aToolsNb = 0;
27 int anOperationType = 0;
29 std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
31 bool isAllInSameCompSolid = true;
32 ResultCompSolidPtr aCompSolid;
34 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
36 anObjectsNb = anAttrSelList->size();
37 for(int anIndex = 0; anIndex < anObjectsNb; ++anIndex) {
38 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
39 ResultPtr aContext = anAttr->context();
40 ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
41 if(aResCompSolidPtr.get()) {
42 if(aCompSolid.get()) {
43 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
45 aCompSolid = aResCompSolidPtr;
48 isAllInSameCompSolid = false;
56 anAttrSelList = theFeature->selectionList(*anIt);
58 aToolsNb = anAttrSelList->size();
59 if(isAllInSameCompSolid) {
60 for(int anIndex = 0; anIndex < aToolsNb; ++anIndex) {
61 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
62 ResultPtr aContext = anAttr->context();
63 ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
64 if(aResCompSolidPtr.get()) {
65 if(aCompSolid.get()) {
66 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
68 aCompSolid = aResCompSolidPtr;
71 isAllInSameCompSolid = false;
79 std::shared_ptr<ModelAPI_AttributeInteger> anAttrInt = theFeature->integer(*anIt);
81 anOperationType = anAttrInt->value();
84 if(anOperationType == 1) {
86 if(anObjectsNb + aToolsNb < 2) {
87 theError = "Not enough arguments for Fuse operation.";
89 } else if(isAllInSameCompSolid) {
90 theError = "Operations only between sub-shapes of the same shape not allowed.";
95 theError = "Objects not selected.";
99 theError = "Tools not selected.";
102 if(isAllInSameCompSolid) {
103 theError = "Operations only between sub-shapes of the same shape not allowed.";
111 //=================================================================================================
112 bool GeomValidators_BooleanArguments::isNotObligatory(std::string theFeature,
113 std::string theAttribute)
115 if(theAttribute == "main_objects" || theAttribute == "tool_objects") {