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 bool aUseFuzzy = (theFuzzy.value() > 0);
48 ModelHighAPI_Double aFuzzy = (aUseFuzzy ? theFuzzy : ModelHighAPI_Double(DEFAULT_FUZZY));
49 fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), mycreationMethod);
50 fillAttribute(theMainObjects, mymainObjects);
51 fillAttribute(theRemoveEdges, myremoveEdges);
52 fillAttribute(aUseFuzzy, myuseFuzzy);
53 fillAttribute(aFuzzy, myfuzzyParam);
59 //==================================================================================================
60 FeaturesAPI_BooleanFuse::FeaturesAPI_BooleanFuse(
61 const std::shared_ptr<ModelAPI_Feature>& theFeature,
62 const std::list<ModelHighAPI_Selection>& theMainObjects,
63 const std::list<ModelHighAPI_Selection>& theToolObjects,
64 const bool theRemoveEdges,
65 const ModelHighAPI_Double& theFuzzy)
66 : ModelHighAPI_Interface(theFeature)
69 bool aUseFuzzy = (theFuzzy.value() > 0);
70 ModelHighAPI_Double aFuzzy = (aUseFuzzy ? theFuzzy : ModelHighAPI_Double(DEFAULT_FUZZY));
71 fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
72 fillAttribute(theMainObjects, mymainObjects);
73 fillAttribute(theToolObjects, mytoolObjects);
74 fillAttribute(theRemoveEdges, myremoveEdges);
75 fillAttribute(aUseFuzzy, myuseFuzzy);
76 fillAttribute(aFuzzy, myfuzzyParam);
82 //==================================================================================================
83 FeaturesAPI_BooleanFuse::~FeaturesAPI_BooleanFuse()
88 //==================================================================================================
89 void FeaturesAPI_BooleanFuse::setMainObjects(
90 const std::list<ModelHighAPI_Selection>& theMainObjects)
92 fillAttribute(theMainObjects, mymainObjects);
97 //==================================================================================================
98 void FeaturesAPI_BooleanFuse::setToolObjects(
99 const std::list<ModelHighAPI_Selection>& theToolObjects)
101 fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
102 fillAttribute(theToolObjects, mytoolObjects);
107 //==================================================================================================
108 void FeaturesAPI_BooleanFuse::setRemoveEdges(const bool theRemoveEdges)
110 fillAttribute(theRemoveEdges, myremoveEdges);
115 //==================================================================================================
116 void FeaturesAPI_BooleanFuse::setUseFuzzy(bool theUseFuzzy)
118 fillAttribute(theUseFuzzy, myuseFuzzy);
123 //==================================================================================================
124 void FeaturesAPI_BooleanFuse::setFuzzyValue(const ModelHighAPI_Double& theFuzzy)
126 fillAttribute(theFuzzy, myfuzzyParam);
131 //==================================================================================================
132 void FeaturesAPI_BooleanFuse::setAdvancedMode(const bool theMode)
135 fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
137 fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), mycreationMethod);
143 //==================================================================================================
144 void FeaturesAPI_BooleanFuse::dump(ModelHighAPI_Dumper& theDumper) const
146 FeaturePtr aBase = feature();
148 theDumper << aBase << " = model.addFuse";
150 const std::string& aDocName = theDumper.name(aBase->document());
151 AttributeStringPtr aMode = aBase->string(FeaturesPlugin_BooleanFuse::CREATION_METHOD());
152 AttributeSelectionListPtr anObjects =
153 aBase->selectionList(FeaturesPlugin_BooleanFuse::OBJECT_LIST_ID());
154 AttributeSelectionListPtr aTools =
155 aBase->selectionList(FeaturesPlugin_BooleanFuse::TOOL_LIST_ID());
156 AttributeBooleanPtr aRemoveEdges =
157 aBase->boolean(FeaturesPlugin_BooleanFuse::REMOVE_INTERSECTION_EDGES_ID());
158 bool aUseFuzzy = aBase->boolean(FeaturesPlugin_BooleanFuse::USE_FUZZY_ID())->value();
159 double aFuzzy = aBase->real(FeaturesPlugin_BooleanFuse::FUZZY_PARAM_ID())->value();
161 theDumper << "(" << aDocName << ", " << anObjects;
163 if (aMode->value() == FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED()) {
164 theDumper << ", " << aTools;
167 if (aRemoveEdges->value()) {
168 theDumper << ", removeEdges = True";
172 theDumper << ", fuzzyParam = " << aFuzzy;
174 if (!aBase->data()->version().empty())
175 theDumper << ", keepSubResults = True";
177 theDumper << ")" << std::endl;
180 //==================================================================================================
181 BooleanFusePtr addFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
182 const std::list<ModelHighAPI_Selection>& theMainObjects,
183 const std::pair<std::list<ModelHighAPI_Selection>, bool>& theToolObjects,
184 const bool theRemoveEdges,
185 const ModelHighAPI_Double& fuzzyParam,
186 const bool keepSubResults)
188 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanFuse::ID());
190 aFeature->data()->setVersion("");
192 bool aRemoveEdges = theRemoveEdges;
193 if (theToolObjects.first.empty())
194 aRemoveEdges = aRemoveEdges || theToolObjects.second;
196 BooleanFusePtr aFuse;
197 if (theToolObjects.first.empty())
198 aFuse.reset(new FeaturesAPI_BooleanFuse(aFeature, theMainObjects, aRemoveEdges, fuzzyParam));
200 aFuse.reset(new FeaturesAPI_BooleanFuse(aFeature, theMainObjects, theToolObjects.first,
201 aRemoveEdges, fuzzyParam));