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_BooleanFuse.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_BooleanFuse::FeaturesAPI_BooleanFuse(
32 const std::shared_ptr<ModelAPI_Feature>& theFeature)
33 : ModelHighAPI_Interface(theFeature)
38 //==================================================================================================
39 FeaturesAPI_BooleanFuse::FeaturesAPI_BooleanFuse(
40 const std::shared_ptr<ModelAPI_Feature>& theFeature,
41 const std::list<ModelHighAPI_Selection>& theMainObjects,
42 const bool theRemoveEdges,
43 const ModelHighAPI_Double& theFuzzy)
44 : ModelHighAPI_Interface(theFeature)
47 fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), VAR_NAME(creationMethod));
48 fillAttribute(theMainObjects, VAR_NAME(mainObjects));
49 fillAttribute(theRemoveEdges, VAR_NAME(removeEdges));
50 fillAttribute(theFuzzy, VAR_NAME(fuzzyParam));
52 // Get the evaluated fuzzy parameter from the attribute!!
53 bool aUseFuzzy = (fuzzyParam()->value() > 0);
54 fillAttribute(aUseFuzzy, VAR_NAME(useFuzzy));
56 ModelHighAPI_Double aFuzzy(DEFAULT_FUZZY);
57 fillAttribute(aFuzzy, VAR_NAME(fuzzyParam));
64 //==================================================================================================
65 FeaturesAPI_BooleanFuse::FeaturesAPI_BooleanFuse(
66 const std::shared_ptr<ModelAPI_Feature>& theFeature,
67 const std::list<ModelHighAPI_Selection>& theMainObjects,
68 const std::list<ModelHighAPI_Selection>& theToolObjects,
69 const bool theRemoveEdges,
70 const ModelHighAPI_Double& theFuzzy)
71 : ModelHighAPI_Interface(theFeature)
74 fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), VAR_NAME(creationMethod));
75 fillAttribute(theMainObjects, VAR_NAME(mainObjects));
76 fillAttribute(theToolObjects, VAR_NAME(toolObjects));
77 fillAttribute(theRemoveEdges, VAR_NAME(removeEdges));
78 fillAttribute(theFuzzy, VAR_NAME(fuzzyParam));
80 // Get the evaluated fuzzy parameter from the attribute!!
81 bool aUseFuzzy = (fuzzyParam()->value() > 0);
82 fillAttribute(aUseFuzzy, VAR_NAME(useFuzzy));
84 ModelHighAPI_Double aFuzzy(DEFAULT_FUZZY);
85 fillAttribute(aFuzzy, VAR_NAME(fuzzyParam));
92 //==================================================================================================
93 FeaturesAPI_BooleanFuse::~FeaturesAPI_BooleanFuse()
98 //==================================================================================================
99 void FeaturesAPI_BooleanFuse::setMainObjects(
100 const std::list<ModelHighAPI_Selection>& theMainObjects)
102 fillAttribute(theMainObjects, VAR_NAME(mainObjects));
107 //==================================================================================================
108 void FeaturesAPI_BooleanFuse::setToolObjects(
109 const std::list<ModelHighAPI_Selection>& theToolObjects)
111 fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), VAR_NAME(creationMethod));
112 fillAttribute(theToolObjects, VAR_NAME(toolObjects));
117 //==================================================================================================
118 void FeaturesAPI_BooleanFuse::setRemoveEdges(const bool theRemoveEdges)
120 fillAttribute(theRemoveEdges, VAR_NAME(removeEdges));
125 //==================================================================================================
126 void FeaturesAPI_BooleanFuse::setUseFuzzy(bool theUseFuzzy)
128 fillAttribute(theUseFuzzy, VAR_NAME(useFuzzy));
133 //==================================================================================================
134 void FeaturesAPI_BooleanFuse::setFuzzyValue(const ModelHighAPI_Double& theFuzzy)
136 fillAttribute(theFuzzy, VAR_NAME(fuzzyParam));
141 //==================================================================================================
142 void FeaturesAPI_BooleanFuse::setAdvancedMode(const bool theMode)
145 fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), VAR_NAME(creationMethod));
147 fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), VAR_NAME(creationMethod));
153 //==================================================================================================
154 void FeaturesAPI_BooleanFuse::dump(ModelHighAPI_Dumper& theDumper) const
156 FeaturePtr aBase = feature();
158 theDumper << aBase << " = model.addFuse";
160 const std::string& aDocName = theDumper.name(aBase->document());
161 AttributeStringPtr aMode = aBase->string(FeaturesPlugin_BooleanFuse::CREATION_METHOD());
162 AttributeSelectionListPtr anObjects =
163 aBase->selectionList(FeaturesPlugin_BooleanFuse::OBJECT_LIST_ID());
164 AttributeSelectionListPtr aTools =
165 aBase->selectionList(FeaturesPlugin_BooleanFuse::TOOL_LIST_ID());
166 AttributeBooleanPtr aRemoveEdges =
167 aBase->boolean(FeaturesPlugin_BooleanFuse::REMOVE_INTERSECTION_EDGES_ID());
168 bool aUseFuzzy = aBase->boolean(FeaturesPlugin_BooleanFuse::USE_FUZZY_ID())->value();
169 AttributeDoublePtr aFuzzy = aBase->real(FeaturesPlugin_BooleanFuse::FUZZY_PARAM_ID());
171 theDumper << "(" << aDocName << ", " << anObjects;
173 if (aMode->value() == FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED()) {
174 theDumper << ", " << aTools;
177 if (aRemoveEdges->value()) {
178 theDumper << ", removeEdges = True";
182 theDumper << ", fuzzyParam = " << aFuzzy;
184 if (!aBase->data()->version().empty())
185 theDumper << ", keepSubResults = True";
187 theDumper << ")" << std::endl;
190 //==================================================================================================
191 BooleanFusePtr addFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
192 const std::list<ModelHighAPI_Selection>& theMainObjects,
193 const std::pair<std::list<ModelHighAPI_Selection>, bool>& theToolObjects,
194 const bool theRemoveEdges,
195 const ModelHighAPI_Double& theFuzzy,
196 const bool keepSubResults)
198 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanFuse::ID());
200 aFeature->data()->setVersion("");
202 bool aRemoveEdges = theRemoveEdges;
203 if (theToolObjects.first.empty())
204 aRemoveEdges = aRemoveEdges || theToolObjects.second;
206 BooleanFusePtr aFuse;
207 if (theToolObjects.first.empty())
208 aFuse.reset(new FeaturesAPI_BooleanFuse(aFeature, theMainObjects, aRemoveEdges, theFuzzy));
210 aFuse.reset(new FeaturesAPI_BooleanFuse(aFeature, theMainObjects, theToolObjects.first,
211 aRemoveEdges, theFuzzy));