1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <GeomValidators_BooleanArguments.h>
23 #include <Events_InfoMessage.h>
25 #include <ModelAPI_AttributeInteger.h>
26 #include <ModelAPI_AttributeSelectionList.h>
27 #include <ModelAPI_ResultCompSolid.h>
28 #include <ModelAPI_Tools.h>
30 //=================================================================================================
31 bool GeomValidators_BooleanArguments::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
32 const std::list<std::string>& theArguments,
33 Events_InfoMessage& theError) const
35 if(theArguments.size() != 3) {
36 theError = "Wrong number of arguments (expected 3).";
40 int anObjectsNb = 0, aToolsNb = 0;
41 int anOperationType = 0;
43 std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
45 bool isAllInSameCompSolid = true;
46 ResultCompSolidPtr aCompSolid;
48 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
50 anObjectsNb = anAttrSelList->size();
51 for(int anIndex = 0; anIndex < anObjectsNb; ++anIndex) {
52 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
53 ResultPtr aContext = anAttr->context();
54 ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
55 if(aResCompSolidPtr.get()) {
56 if(aCompSolid.get()) {
57 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
59 aCompSolid = aResCompSolidPtr;
62 isAllInSameCompSolid = false;
70 anAttrSelList = theFeature->selectionList(*anIt);
72 aToolsNb = anAttrSelList->size();
73 if(isAllInSameCompSolid) {
74 for(int anIndex = 0; anIndex < aToolsNb; ++anIndex) {
75 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
76 ResultPtr aContext = anAttr->context();
77 ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
78 if(aResCompSolidPtr.get()) {
79 if(aCompSolid.get()) {
80 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
82 aCompSolid = aResCompSolidPtr;
85 isAllInSameCompSolid = false;
93 std::shared_ptr<ModelAPI_AttributeInteger> anAttrInt = theFeature->integer(*anIt);
95 anOperationType = anAttrInt->value();
98 if(anOperationType == 1) {
100 if(anObjectsNb + aToolsNb < 2) {
101 theError = "Not enough arguments for Fuse operation.";
103 } else if(isAllInSameCompSolid) {
104 theError = "Operations only between sub-shapes of the same shape not allowed.";
108 if(anObjectsNb < 1) {
109 theError = "Objects not selected.";
113 theError = "Tools not selected.";
116 if(isAllInSameCompSolid) {
117 theError = "Operations only between sub-shapes of the same shape not allowed.";
125 //=================================================================================================
126 bool GeomValidators_BooleanArguments::isNotObligatory(std::string theFeature,
127 std::string theAttribute)
129 if(theAttribute == "main_objects" || theAttribute == "tool_objects") {