]> SALOME platform Git repositories - modules/shaper.git/blob - src/FeaturesAPI/FeaturesAPI_BooleanFuse.cpp
Salome HOME
support fuzzy parameter in all boolean operations
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_BooleanFuse.cpp
1 // Copyright (C) 2014-2022  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "FeaturesAPI_BooleanFuse.h"
21
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Selection.h>
24 #include <ModelHighAPI_Tools.h>
25
26 //==================================================================================================
27 FeaturesAPI_BooleanFuse::FeaturesAPI_BooleanFuse(
28   const std::shared_ptr<ModelAPI_Feature>& theFeature)
29 : ModelHighAPI_Interface(theFeature)
30 {
31   initialize();
32 }
33
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)
41 {
42   if (initialize()) {
43     fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), mycreationMethod);
44     fillAttribute(theMainObjects, mymainObjects);
45     fillAttribute(theRemoveEdges, myremoveEdges);
46     fillAttribute(theFuzzy, myfuzzyParam);
47
48     execute(false);
49   }
50 }
51
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)
60 {
61   if(initialize()) {
62     fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
63     fillAttribute(theMainObjects, mymainObjects);
64     fillAttribute(theToolObjects, mytoolObjects);
65     fillAttribute(theRemoveEdges, myremoveEdges);
66     fillAttribute(theFuzzy, myfuzzyParam);
67
68     execute(false);
69   }
70 }
71
72 //==================================================================================================
73 FeaturesAPI_BooleanFuse::~FeaturesAPI_BooleanFuse()
74 {
75 }
76
77
78 //==================================================================================================
79 void FeaturesAPI_BooleanFuse::setMainObjects(
80   const std::list<ModelHighAPI_Selection>& theMainObjects)
81 {
82   fillAttribute(theMainObjects, mymainObjects);
83
84   execute();
85 }
86
87 //==================================================================================================
88 void FeaturesAPI_BooleanFuse::setToolObjects(
89   const std::list<ModelHighAPI_Selection>& theToolObjects)
90 {
91   fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
92   fillAttribute(theToolObjects, mytoolObjects);
93
94   execute();
95 }
96
97 //==================================================================================================
98 void FeaturesAPI_BooleanFuse::setRemoveEdges(const bool theRemoveEdges)
99 {
100   fillAttribute(theRemoveEdges, myremoveEdges);
101
102   execute();
103 }
104
105 //==================================================================================================
106 void FeaturesAPI_BooleanFuse::setFuzzyValue(const ModelHighAPI_Double& theFuzzy)
107 {
108   fillAttribute(theFuzzy, myfuzzyParam);
109
110   execute();
111 }
112
113 //==================================================================================================
114 void FeaturesAPI_BooleanFuse::setAdvancedMode(const bool theMode)
115 {
116   if (theMode) {
117     fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED(), mycreationMethod);
118   } else {
119     fillAttribute(FeaturesPlugin_BooleanFuse::CREATION_METHOD_SIMPLE(), mycreationMethod);
120   }
121
122   execute();
123 }
124
125 //==================================================================================================
126 void FeaturesAPI_BooleanFuse::dump(ModelHighAPI_Dumper& theDumper) const
127 {
128   FeaturePtr aBase = feature();
129
130   theDumper << aBase << " = model.addFuse";
131
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();
141
142   theDumper << "(" << aDocName << ", " << anObjects;
143
144   if (aMode->value() == FeaturesPlugin_BooleanFuse::CREATION_METHOD_ADVANCED()) {
145     theDumper << ", " << aTools;
146   }
147
148   if (aRemoveEdges->value()) {
149     theDumper << ", removeEdges = True";
150   }
151
152   if (aFuzzy != 1.e-8) {
153     theDumper << ", fuzzyParam = " << aFuzzy;
154   }
155
156   if (!aBase->data()->version().empty())
157     theDumper << ", keepSubResults = True";
158
159   theDumper << ")" << std::endl;
160 }
161
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)
169 {
170   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanFuse::ID());
171   if (!keepSubResults)
172     aFeature->data()->setVersion("");
173
174   bool aRemoveEdges = theRemoveEdges;
175   if (theToolObjects.first.empty())
176     aRemoveEdges = aRemoveEdges || theToolObjects.second;
177
178   BooleanFusePtr aFuse;
179   if (theToolObjects.first.empty())
180     aFuse.reset(new FeaturesAPI_BooleanFuse(aFeature, theMainObjects, aRemoveEdges, fuzzyParam));
181   else {
182     aFuse.reset(new FeaturesAPI_BooleanFuse(aFeature, theMainObjects, theToolObjects.first,
183                                             aRemoveEdges, fuzzyParam));
184   }
185   return aFuse;
186 }