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;
55 anAttrSelList = theFeature->selectionList(*anIt);
57 aToolsNb = anAttrSelList->size();
58 for(int anIndex = 0; anIndex < aToolsNb; ++anIndex) {
59 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
60 ResultPtr aContext = anAttr->context();
61 ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
62 if(aResCompSolidPtr.get()) {
63 if(aCompSolid.get()) {
64 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
66 aCompSolid = aResCompSolidPtr;
69 isAllInSameCompSolid = false;
75 std::shared_ptr<ModelAPI_AttributeInteger> anAttrInt = theFeature->integer(*anIt);
77 anOperationType = anAttrInt->value();
80 if(anOperationType == 1) {
82 if(anObjectsNb + aToolsNb < 2) {
83 theError = "Not enough arguments for Fuse operation.";
85 } else if(isAllInSameCompSolid) {
86 theError = "Operations only between sub-shapes of the same shape not allowed.";
91 theError = "Objects not selected.";
95 theError = "Tools not selected.";
98 if(isAllInSameCompSolid) {
99 theError = "Operations only between sub-shapes of the same shape not allowed.";
107 //=================================================================================================
108 bool GeomValidators_BooleanArguments::isNotObligatory(std::string theFeature,
109 std::string theAttribute)
111 if(theAttribute == "main_objects" || theAttribute == "tool_objects") {