1 // Copyright (C) 2014-2022 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
20 #include "FeaturesAPI_BooleanCommon.h"
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Selection.h>
24 #include <ModelHighAPI_Tools.h>
27 static const double DEFAULT_FUZZY = 1.e-5;
30 //==================================================================================================
31 FeaturesAPI_BooleanCommon::FeaturesAPI_BooleanCommon(
32 const std::shared_ptr<ModelAPI_Feature>& theFeature)
33 : ModelHighAPI_Interface(theFeature)
38 //==================================================================================================
39 FeaturesAPI_BooleanCommon::FeaturesAPI_BooleanCommon(
40 const std::shared_ptr<ModelAPI_Feature>& theFeature,
41 const std::list<ModelHighAPI_Selection>& theMainObjects,
42 const ModelHighAPI_Double& theFuzzy)
43 : ModelHighAPI_Interface(theFeature)
46 fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_SIMPLE(), VAR_NAME(creationMethod));
47 fillAttribute(theMainObjects, VAR_NAME(mainObjects));
48 fillAttribute(theFuzzy, VAR_NAME(fuzzyParam));
50 // Get the evaluated fuzzy parameter from the attribute!!
51 bool aUseFuzzy = (fuzzyParam()->value() > 0);
52 fillAttribute(aUseFuzzy, VAR_NAME(useFuzzy));
54 ModelHighAPI_Double aFuzzy(DEFAULT_FUZZY);
55 fillAttribute(aFuzzy, VAR_NAME(fuzzyParam));
62 //==================================================================================================
63 FeaturesAPI_BooleanCommon::FeaturesAPI_BooleanCommon(
64 const std::shared_ptr<ModelAPI_Feature>& theFeature,
65 const std::list<ModelHighAPI_Selection>& theMainObjects,
66 const std::list<ModelHighAPI_Selection>& theToolObjects,
67 const ModelHighAPI_Double& theFuzzy)
68 : ModelHighAPI_Interface(theFeature)
71 fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_ADVANCED(), VAR_NAME(creationMethod));
72 fillAttribute(theMainObjects, VAR_NAME(mainObjects));
73 fillAttribute(theToolObjects, VAR_NAME(toolObjects));
74 fillAttribute(theFuzzy, VAR_NAME(fuzzyParam));
76 // Get the evaluated fuzzy parameter from the attribute!!
77 bool aUseFuzzy = (fuzzyParam()->value() > 0);
78 fillAttribute(aUseFuzzy, VAR_NAME(useFuzzy));
80 ModelHighAPI_Double aFuzzy(DEFAULT_FUZZY);
81 fillAttribute(aFuzzy, VAR_NAME(fuzzyParam));
88 //==================================================================================================
89 FeaturesAPI_BooleanCommon::~FeaturesAPI_BooleanCommon()
94 //==================================================================================================
95 void FeaturesAPI_BooleanCommon::setMainObjects(
96 const std::list<ModelHighAPI_Selection>& theMainObjects)
98 fillAttribute(theMainObjects, VAR_NAME(mainObjects));
103 //==================================================================================================
104 void FeaturesAPI_BooleanCommon::setToolObjects(
105 const std::list<ModelHighAPI_Selection>& theToolObjects)
107 fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_ADVANCED(), VAR_NAME(creationMethod));
108 fillAttribute(theToolObjects, VAR_NAME(toolObjects));
113 //==================================================================================================
114 void FeaturesAPI_BooleanCommon::setUseFuzzy(bool theUseFuzzy)
116 fillAttribute(theUseFuzzy, VAR_NAME(useFuzzy));
121 //==================================================================================================
122 void FeaturesAPI_BooleanCommon::setFuzzyValue(const ModelHighAPI_Double& theFuzzy)
124 fillAttribute(theFuzzy, VAR_NAME(fuzzyParam));
129 //==================================================================================================
130 void FeaturesAPI_BooleanCommon::setAdvancedMode(const bool theMode)
133 fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_ADVANCED(), VAR_NAME(creationMethod));
135 fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_SIMPLE(), VAR_NAME(creationMethod));
141 //==================================================================================================
142 void FeaturesAPI_BooleanCommon::dump(ModelHighAPI_Dumper& theDumper) const
144 FeaturePtr aBase = feature();
146 theDumper << aBase << " = model.addCommon";
148 const std::string& aDocName = theDumper.name(aBase->document());
149 AttributeStringPtr aMode = aBase->string(FeaturesPlugin_BooleanCommon::CREATION_METHOD());
150 AttributeSelectionListPtr anObjects =
151 aBase->selectionList(FeaturesPlugin_BooleanCommon::OBJECT_LIST_ID());
152 AttributeSelectionListPtr aTools =
153 aBase->selectionList(FeaturesPlugin_BooleanCommon::TOOL_LIST_ID());
154 bool aUseFuzzy = aBase->boolean(FeaturesPlugin_BooleanCommon::USE_FUZZY_ID())->value();
155 AttributeDoublePtr aFuzzy = aBase->real(FeaturesPlugin_BooleanCommon::FUZZY_PARAM_ID());
157 theDumper << "(" << aDocName << ", " << anObjects;
159 if (aMode->value() == FeaturesPlugin_BooleanCommon::CREATION_METHOD_ADVANCED()) {
160 theDumper << ", " << aTools;
164 theDumper << ", fuzzyParam = " << aFuzzy;
166 if (!aBase->data()->version().empty())
167 theDumper << ", keepSubResults = True";
169 theDumper << ")" << std::endl;
172 //==================================================================================================
173 BooleanCommonPtr addCommon(const std::shared_ptr<ModelAPI_Document>& thePart,
174 const std::list<ModelHighAPI_Selection>& theMainObjects,
175 const std::list<ModelHighAPI_Selection>& theToolObjects,
176 const ModelHighAPI_Double& theFuzzy,
177 const bool keepSubResults)
179 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanCommon::ID());
181 aFeature->data()->setVersion("");
182 BooleanCommonPtr aCommon;
183 if (theToolObjects.empty())
184 aCommon.reset(new FeaturesAPI_BooleanCommon(aFeature, theMainObjects, theFuzzy));
186 aCommon.reset(new FeaturesAPI_BooleanCommon(aFeature, theMainObjects, theToolObjects, theFuzzy));