1 // Copyright (C) 2014-2021 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 : ModelHighAPI_Interface(theFeature)
42 fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), mycreationMethod);
43 fillAttribute(theMainObjects, mymainObjects);
44 fillAttribute(theRemoveEdges, myremoveEdges);
50 //==================================================================================================
51 FeaturesAPI_BooleanFuse::FeaturesAPI_BooleanFuse(
52 const std::shared_ptr<ModelAPI_Feature>& theFeature,
53 const std::list<ModelHighAPI_Selection>& theMainObjects,
54 const std::list<ModelHighAPI_Selection>& theToolObjects,
55 const bool theRemoveEdges)
56 : ModelHighAPI_Interface(theFeature)
59 fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
60 fillAttribute(theMainObjects, mymainObjects);
61 fillAttribute(theToolObjects, mytoolObjects);
62 fillAttribute(theRemoveEdges, myremoveEdges);
68 //==================================================================================================
69 FeaturesAPI_BooleanFuse::~FeaturesAPI_BooleanFuse()
74 //==================================================================================================
75 void FeaturesAPI_BooleanFuse::setMainObjects(
76 const std::list<ModelHighAPI_Selection>& theMainObjects)
78 fillAttribute(theMainObjects, mymainObjects);
83 //==================================================================================================
84 void FeaturesAPI_BooleanFuse::setToolObjects(
85 const std::list<ModelHighAPI_Selection>& theToolObjects)
87 fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
88 fillAttribute(theToolObjects, mytoolObjects);
93 //==================================================================================================
94 void FeaturesAPI_BooleanFuse::setRemoveEdges(const bool theRemoveEdges)
96 fillAttribute(theRemoveEdges, myremoveEdges);
101 //==================================================================================================
102 void FeaturesAPI_BooleanFuse::setAdvancedMode(const bool theMode)
105 fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
107 fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), mycreationMethod);
113 //==================================================================================================
114 void FeaturesAPI_BooleanFuse::dump(ModelHighAPI_Dumper& theDumper) const
116 FeaturePtr aBase = feature();
118 theDumper << aBase << " = model.addFuse";
120 const std::string& aDocName = theDumper.name(aBase->document());
121 AttributeStringPtr aMode = aBase->string(FeaturesPlugin_BooleanFuse::CREATION_METHOD());
122 AttributeSelectionListPtr anObjects =
123 aBase->selectionList(FeaturesPlugin_BooleanFuse::OBJECT_LIST_ID());
124 AttributeSelectionListPtr aTools =
125 aBase->selectionList(FeaturesPlugin_BooleanFuse::TOOL_LIST_ID());
126 AttributeBooleanPtr aRemoveEdges =
127 aBase->boolean(FeaturesPlugin_BooleanFuse::REMOVE_INTERSECTION_EDGES_ID());
129 theDumper << "(" << aDocName << ", " << anObjects;
131 if (aMode->value() == FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED()) {
132 theDumper << ", " << aTools;
135 if (aRemoveEdges->value()) {
136 theDumper << ", removeEdges = True";
139 if (!aBase->data()->version().empty())
140 theDumper << ", keepSubResults = True";
142 theDumper << ")" << std::endl;
145 //==================================================================================================
146 BooleanFusePtr addFuse(const std::shared_ptr<ModelAPI_Document>& thePart,
147 const std::list<ModelHighAPI_Selection>& theMainObjects,
148 const std::pair<std::list<ModelHighAPI_Selection>, bool>& theToolObjects,
149 const bool theRemoveEdges,
150 const bool keepSubResults)
152 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanFuse::ID());
154 aFeature->data()->setVersion("");
156 bool aRemoveEdges = theRemoveEdges;
157 if (theToolObjects.first.empty())
158 aRemoveEdges = aRemoveEdges || theToolObjects.second;
160 BooleanFusePtr aFuse;
161 if (theToolObjects.first.empty())
162 aFuse.reset(new FeaturesAPI_BooleanFuse(aFeature, theMainObjects, aRemoveEdges));
164 aFuse.reset(new FeaturesAPI_BooleanFuse(aFeature, theMainObjects, theToolObjects.first,