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>
26 //==================================================================================================
27 FeaturesAPI_BooleanFuse::FeaturesAPI_BooleanFuse(
28 const std::shared_ptr<ModelAPI_Feature>& theFeature)
29 : ModelHighAPI_Interface(theFeature)
34 //==================================================================================================
35 FeaturesAPI_BooleanFuse::FeaturesAPI_BooleanFuse(
36 const std::shared_ptr<ModelAPI_Feature>& theFeature,
37 const std::list<ModelHighAPI_Selection>& theMainObjects,
38 const bool theRemoveEdges,
39 const ModelHighAPI_Double& theFuzzy)
40 : ModelHighAPI_Interface(theFeature)
43 fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), mycreationMethod);
44 fillAttribute(theMainObjects, mymainObjects);
45 fillAttribute(theRemoveEdges, myremoveEdges);
46 fillAttribute(theFuzzy, myfuzzyParam);
52 //==================================================================================================
53 FeaturesAPI_BooleanFuse::FeaturesAPI_BooleanFuse(
54 const std::shared_ptr<ModelAPI_Feature>& theFeature,
55 const std::list<ModelHighAPI_Selection>& theMainObjects,
56 const std::list<ModelHighAPI_Selection>& theToolObjects,
57 const bool theRemoveEdges,
58 const ModelHighAPI_Double& theFuzzy)
59 : ModelHighAPI_Interface(theFeature)
62 fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
63 fillAttribute(theMainObjects, mymainObjects);
64 fillAttribute(theToolObjects, mytoolObjects);
65 fillAttribute(theRemoveEdges, myremoveEdges);
66 fillAttribute(theFuzzy, myfuzzyParam);
72 //==================================================================================================
73 FeaturesAPI_BooleanFuse::~FeaturesAPI_BooleanFuse()
78 //==================================================================================================
79 void FeaturesAPI_BooleanFuse::setMainObjects(
80 const std::list<ModelHighAPI_Selection>& theMainObjects)
82 fillAttribute(theMainObjects, mymainObjects);
87 //==================================================================================================
88 void FeaturesAPI_BooleanFuse::setToolObjects(
89 const std::list<ModelHighAPI_Selection>& theToolObjects)
91 fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
92 fillAttribute(theToolObjects, mytoolObjects);
97 //==================================================================================================
98 void FeaturesAPI_BooleanFuse::setRemoveEdges(const bool theRemoveEdges)
100 fillAttribute(theRemoveEdges, myremoveEdges);
105 //==================================================================================================
106 void FeaturesAPI_BooleanFuse::setFuzzyValue(const ModelHighAPI_Double& theFuzzy)
108 fillAttribute(theFuzzy, myfuzzyParam);
113 //==================================================================================================
114 void FeaturesAPI_BooleanFuse::setAdvancedMode(const bool theMode)
117 fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
119 fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), mycreationMethod);
125 //==================================================================================================
126 void FeaturesAPI_BooleanFuse::dump(ModelHighAPI_Dumper& theDumper) const
128 FeaturePtr aBase = feature();
130 theDumper << aBase << " = model.addFuse";
132 const std::string& aDocName = theDumper.name(aBase->document());
133 AttributeStringPtr aMode = aBase->string(FeaturesPlugin_BooleanFuse::CREATION_METHOD());
134 AttributeSelectionListPtr anObjects =
135 aBase->selectionList(FeaturesPlugin_BooleanFuse::OBJECT_LIST_ID());
136 AttributeSelectionListPtr aTools =
137 aBase->selectionList(FeaturesPlugin_BooleanFuse::TOOL_LIST_ID());
138 AttributeBooleanPtr aRemoveEdges =
139 aBase->boolean(FeaturesPlugin_BooleanFuse::REMOVE_INTERSECTION_EDGES_ID());
140 double aFuzzy = aBase->real(FeaturesPlugin_BooleanFuse::FUZZY_PARAM_ID())->value();
142 theDumper << "(" << aDocName << ", " << anObjects;
144 if (aMode->value() == FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED()) {
145 theDumper << ", " << aTools;
148 if (aRemoveEdges->value()) {
149 theDumper << ", removeEdges = True";
152 if (aFuzzy != 1.e-8) {
153 theDumper << ", fuzzyParam = " << aFuzzy;
156 if (!aBase->data()->version().empty())
157 theDumper << ", keepSubResults = True";
159 theDumper << ")" << std::endl;
162 //==================================================================================================
163 BooleanFusePtr addFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
164 const std::list<ModelHighAPI_Selection>& theMainObjects,
165 const std::pair<std::list<ModelHighAPI_Selection>, bool>& theToolObjects,
166 const bool theRemoveEdges,
167 const ModelHighAPI_Double& fuzzyParam,
168 const bool keepSubResults)
170 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanFuse::ID());
172 aFeature->data()->setVersion("");
174 bool aRemoveEdges = theRemoveEdges;
175 if (theToolObjects.first.empty())
176 aRemoveEdges = aRemoveEdges || theToolObjects.second;
178 BooleanFusePtr aFuse;
179 if (theToolObjects.first.empty())
180 aFuse.reset(new FeaturesAPI_BooleanFuse(aFeature, theMainObjects, aRemoveEdges, fuzzyParam));
182 aFuse.reset(new FeaturesAPI_BooleanFuse(aFeature, theMainObjects, theToolObjects.first,
183 aRemoveEdges, fuzzyParam));