Salome HOME
dump the fuzzy value as attribute and not as double
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_BooleanCommon.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_BooleanCommon.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_BooleanCommon::FeaturesAPI_BooleanCommon(
32   const std::shared_ptr<ModelAPI_Feature>& theFeature)
33 : ModelHighAPI_Interface(theFeature)
34 {
35   initialize();
36 }
37
38 //==================================================================================================
39 FeaturesAPI_BooleanCommon::FeaturesAPI_BooleanCommon(
40   const std::shared_ptr<ModelAPI_Feature>& theFeature,
41   const std::list<ModelHighAPI_Selection>& theMainObjects,
42   const ModelHighAPI_Double& theFuzzy)
43 : ModelHighAPI_Interface(theFeature)
44 {
45   if(initialize()) {
46     bool aUseFuzzy = (theFuzzy.value() > 0);
47     ModelHighAPI_Double aFuzzy = (aUseFuzzy ? theFuzzy : ModelHighAPI_Double(DEFAULT_FUZZY));
48     fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_SIMPLE(), mycreationMethod);
49     fillAttribute(theMainObjects, mymainObjects);
50     fillAttribute(aUseFuzzy, myuseFuzzy);
51     fillAttribute(aFuzzy, myfuzzyValue);
52
53     execute(false);
54   }
55 }
56
57 //==================================================================================================
58 FeaturesAPI_BooleanCommon::FeaturesAPI_BooleanCommon(
59   const std::shared_ptr<ModelAPI_Feature>& theFeature,
60   const std::list<ModelHighAPI_Selection>& theMainObjects,
61   const std::list<ModelHighAPI_Selection>& theToolObjects,
62   const ModelHighAPI_Double& theFuzzy)
63 : ModelHighAPI_Interface(theFeature)
64 {
65   if(initialize()) {
66     bool aUseFuzzy = (theFuzzy.value() > 0);
67     ModelHighAPI_Double aFuzzy = (aUseFuzzy ? theFuzzy : ModelHighAPI_Double(DEFAULT_FUZZY));
68     fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_ADVANCED(), mycreationMethod);
69     fillAttribute(theMainObjects, mymainObjects);
70     fillAttribute(theToolObjects, mytoolObjects);
71     fillAttribute(aUseFuzzy, myuseFuzzy);
72     fillAttribute(aFuzzy, myfuzzyValue);
73
74     execute(false);
75   }
76 }
77
78 //==================================================================================================
79 FeaturesAPI_BooleanCommon::~FeaturesAPI_BooleanCommon()
80 {
81 }
82
83
84 //==================================================================================================
85 void FeaturesAPI_BooleanCommon::setMainObjects(
86   const std::list<ModelHighAPI_Selection>& theMainObjects)
87 {
88   fillAttribute(theMainObjects, mymainObjects);
89
90   execute();
91 }
92
93 //==================================================================================================
94 void FeaturesAPI_BooleanCommon::setToolObjects(
95   const std::list<ModelHighAPI_Selection>& theToolObjects)
96 {
97   fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_ADVANCED(), mycreationMethod);
98   fillAttribute(theToolObjects, mytoolObjects);
99
100   execute();
101 }
102
103 //==================================================================================================
104 void FeaturesAPI_BooleanCommon::setUseFuzzy(bool theUseFuzzy)
105 {
106   fillAttribute(theUseFuzzy, myuseFuzzy);
107
108   execute();
109 }
110
111 //==================================================================================================
112 void FeaturesAPI_BooleanCommon::setFuzzyValue(const ModelHighAPI_Double& theFuzzy)
113 {
114   fillAttribute(theFuzzy, myfuzzyValue);
115
116   execute();
117 }
118
119 //==================================================================================================
120 void FeaturesAPI_BooleanCommon::setAdvancedMode(const bool theMode)
121 {
122   if (theMode) {
123     fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_ADVANCED(), mycreationMethod);
124   } else {
125     fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_SIMPLE(), mycreationMethod);
126   }
127
128   execute();
129 }
130
131 //==================================================================================================
132 void FeaturesAPI_BooleanCommon::dump(ModelHighAPI_Dumper& theDumper) const
133 {
134   FeaturePtr aBase = feature();
135
136   theDumper << aBase << " = model.addCommon";
137
138   const std::string& aDocName = theDumper.name(aBase->document());
139   AttributeStringPtr aMode = aBase->string(FeaturesPlugin_BooleanCommon::CREATION_METHOD());
140   AttributeSelectionListPtr anObjects =
141     aBase->selectionList(FeaturesPlugin_BooleanCommon::OBJECT_LIST_ID());
142   AttributeSelectionListPtr aTools =
143     aBase->selectionList(FeaturesPlugin_BooleanCommon::TOOL_LIST_ID());
144   bool aUseFuzzy = aBase->boolean(FeaturesPlugin_BooleanCommon::USE_FUZZY_ID())->value();
145   AttributeDoublePtr aFuzzy = aBase->real(FeaturesPlugin_BooleanCommon::FUZZY_PARAM_ID());
146
147   theDumper << "(" << aDocName << ", " << anObjects;
148
149   if (aMode->value() == FeaturesPlugin_BooleanCommon::CREATION_METHOD_ADVANCED()) {
150     theDumper << ", " << aTools;
151   }
152
153   if (aUseFuzzy)
154     theDumper << ", fuzzyParam = " << aFuzzy;
155
156   if (!aBase->data()->version().empty())
157     theDumper << ", keepSubResults = True";
158
159   theDumper << ")" << std::endl;
160 }
161
162 //==================================================================================================
163 BooleanCommonPtr addCommon(const std::shared_ptr<ModelAPI_Document>& thePart,
164                            const std::list<ModelHighAPI_Selection>& theMainObjects,
165                            const std::list<ModelHighAPI_Selection>& theToolObjects,
166                            const ModelHighAPI_Double& fuzzyParam,
167                            const bool keepSubResults)
168 {
169   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanCommon::ID());
170   if (!keepSubResults)
171     aFeature->data()->setVersion("");
172   BooleanCommonPtr aCommon;
173   if (theToolObjects.empty())
174     aCommon.reset(new FeaturesAPI_BooleanCommon(aFeature, theMainObjects, fuzzyParam));
175   else
176     aCommon.reset(new FeaturesAPI_BooleanCommon(aFeature, theMainObjects, theToolObjects, fuzzyParam));
177   return aCommon;
178 }