Salome HOME
added checkbox in UI for optional fuzzy parameter
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_BooleanSmash.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_BooleanSmash.h"
21
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Selection.h>
24 #include <ModelHighAPI_Tools.h>
25
26
27 static const double DEFAULT_FUZZY = 1.e-5;
28
29
30 //==================================================================================================
31 FeaturesAPI_BooleanSmash::FeaturesAPI_BooleanSmash(
32   const std::shared_ptr<ModelAPI_Feature>& theFeature)
33 : ModelHighAPI_Interface(theFeature)
34 {
35   initialize();
36 }
37
38 //==================================================================================================
39 FeaturesAPI_BooleanSmash::FeaturesAPI_BooleanSmash(
40   const std::shared_ptr<ModelAPI_Feature>& theFeature,
41   const std::list<ModelHighAPI_Selection>& theMainObjects,
42   const std::list<ModelHighAPI_Selection>& theToolObjects,
43   const ModelHighAPI_Double& theFuzzy)
44 : ModelHighAPI_Interface(theFeature)
45 {
46   if(initialize()) {
47     bool aUseFuzzy = (theFuzzy.value() > 0);
48     ModelHighAPI_Double aFuzzy = (aUseFuzzy ? theFuzzy : ModelHighAPI_Double(DEFAULT_FUZZY));
49     fillAttribute(theMainObjects, mymainObjects);
50     fillAttribute(theToolObjects, mytoolObjects);
51     fillAttribute(aUseFuzzy, myuseFuzzy);
52     fillAttribute(aFuzzy, myfuzzyParam);
53
54     execute(false);
55   }
56 }
57
58 //==================================================================================================
59 FeaturesAPI_BooleanSmash::~FeaturesAPI_BooleanSmash()
60 {
61 }
62
63
64 //==================================================================================================
65 void FeaturesAPI_BooleanSmash::setMainObjects(
66   const std::list<ModelHighAPI_Selection>& theMainObjects)
67 {
68   fillAttribute(theMainObjects, mymainObjects);
69
70   execute();
71 }
72
73 //==================================================================================================
74 void FeaturesAPI_BooleanSmash::setToolObjects(
75   const std::list<ModelHighAPI_Selection>& theToolObjects)
76 {
77   fillAttribute(theToolObjects, mytoolObjects);
78
79   execute();
80 }
81
82 //==================================================================================================
83 void FeaturesAPI_BooleanSmash::setUseFuzzy(bool theUseFuzzy)
84 {
85   fillAttribute(theUseFuzzy, myuseFuzzy);
86
87   execute();
88 }
89
90 //==================================================================================================
91 void FeaturesAPI_BooleanSmash::setFuzzyValue(const ModelHighAPI_Double& theFuzzy)
92 {
93   fillAttribute(theFuzzy, myfuzzyParam);
94
95   execute();
96 }
97
98 //==================================================================================================
99 void FeaturesAPI_BooleanSmash::dump(ModelHighAPI_Dumper& theDumper) const
100 {
101   FeaturePtr aBase = feature();
102
103   theDumper << aBase << " = model.addSmash";
104
105   const std::string& aDocName = theDumper.name(aBase->document());
106   AttributeSelectionListPtr anObjects =
107     aBase->selectionList(FeaturesPlugin_BooleanSmash::OBJECT_LIST_ID());
108   AttributeSelectionListPtr aTools =
109     aBase->selectionList(FeaturesPlugin_BooleanSmash::TOOL_LIST_ID());
110   bool aUseFuzzy = aBase->boolean(FeaturesPlugin_BooleanSmash::USE_FUZZY_ID())->value();
111   double aFuzzy = aBase->real(FeaturesPlugin_BooleanSmash::FUZZY_PARAM_ID())->value();
112
113   theDumper << "(" << aDocName << ", " << anObjects << ", " << aTools;
114
115   if (aUseFuzzy)
116     theDumper << ", fuzzyParam = " << aFuzzy;
117
118   if (!aBase->data()->version().empty())
119     theDumper << ", keepSubResults = True";
120
121   theDumper << ")" << std::endl;
122 }
123
124 //==================================================================================================
125 BooleanSmashPtr addSmash(const std::shared_ptr<ModelAPI_Document>& thePart,
126                          const std::list<ModelHighAPI_Selection>& theMainObjects,
127                          const std::list<ModelHighAPI_Selection>& theToolObjects,
128                          const ModelHighAPI_Double& fuzzyParam,
129                          const bool keepSubResults)
130 {
131   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanSmash::ID());
132   if (!keepSubResults)
133     aFeature->data()->setVersion("");
134   return BooleanSmashPtr(new FeaturesAPI_BooleanSmash(aFeature, theMainObjects, theToolObjects, fuzzyParam));
135 }