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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include <GeomValidators_BooleanArguments.h>
22 #include <Events_InfoMessage.h>
24 #include <ModelAPI_AttributeInteger.h>
25 #include <ModelAPI_AttributeSelectionList.h>
26 #include <ModelAPI_ResultCompSolid.h>
27 #include <ModelAPI_Tools.h>
29 //=================================================================================================
30 bool GeomValidators_BooleanArguments::isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
31 const std::list<std::string>& theArguments,
32 Events_InfoMessage& theError) const
34 if(theArguments.size() != 3) {
35 theError = "Wrong number of arguments (expected 3).";
39 int anObjectsNb = 0, aToolsNb = 0;
40 int anOperationType = 0;
42 std::list<std::string>::const_iterator anIt = theArguments.begin(), aLast = theArguments.end();
44 bool isAllInSameCompSolid = true;
45 ResultCompSolidPtr aCompSolid;
47 AttributeSelectionListPtr anAttrSelList = theFeature->selectionList(*anIt);
49 anObjectsNb = anAttrSelList->size();
50 for(int anIndex = 0; anIndex < anObjectsNb; ++anIndex) {
51 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
52 ResultPtr aContext = anAttr->context();
53 ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
54 if(aResCompSolidPtr.get()) {
55 if(aCompSolid.get()) {
56 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
58 aCompSolid = aResCompSolidPtr;
61 isAllInSameCompSolid = false;
69 anAttrSelList = theFeature->selectionList(*anIt);
71 aToolsNb = anAttrSelList->size();
72 if(isAllInSameCompSolid) {
73 for(int anIndex = 0; anIndex < aToolsNb; ++anIndex) {
74 AttributeSelectionPtr anAttr = anAttrSelList->value(anIndex);
75 ResultPtr aContext = anAttr->context();
76 ResultCompSolidPtr aResCompSolidPtr = ModelAPI_Tools::compSolidOwner(aContext);
77 if(aResCompSolidPtr.get()) {
78 if(aCompSolid.get()) {
79 isAllInSameCompSolid = aCompSolid == aResCompSolidPtr;
81 aCompSolid = aResCompSolidPtr;
84 isAllInSameCompSolid = false;
92 std::shared_ptr<ModelAPI_AttributeInteger> anAttrInt = theFeature->integer(*anIt);
94 anOperationType = anAttrInt->value();
97 if(anOperationType == 1) {
99 if(anObjectsNb + aToolsNb < 2) {
100 theError = "Not enough arguments for Fuse operation.";
102 } else if(isAllInSameCompSolid) {
103 theError = "Operations only between sub-shapes of the same shape not allowed.";
107 if(anObjectsNb < 1) {
108 theError = "Objects not selected.";
112 theError = "Tools not selected.";
115 if(isAllInSameCompSolid) {
116 theError = "Operations only between sub-shapes of the same shape not allowed.";
124 //=================================================================================================
125 bool GeomValidators_BooleanArguments::isNotObligatory(std::string theFeature,
126 std::string theAttribute)
128 if(theAttribute == "main_objects" || theAttribute == "tool_objects") {