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_BooleanCommon.h"
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Selection.h>
24 #include <ModelHighAPI_Tools.h>
27 static const double DEFAULT_FUZZY = 1.e-5;
30 //==================================================================================================
31 FeaturesAPI_BooleanCommon::FeaturesAPI_BooleanCommon(
32 const std::shared_ptr<ModelAPI_Feature>& theFeature)
33 : ModelHighAPI_Interface(theFeature)
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)
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);
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)
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);
78 //==================================================================================================
79 FeaturesAPI_BooleanCommon::~FeaturesAPI_BooleanCommon()
84 //==================================================================================================
85 void FeaturesAPI_BooleanCommon::setMainObjects(
86 const std::list<ModelHighAPI_Selection>& theMainObjects)
88 fillAttribute(theMainObjects, mymainObjects);
93 //==================================================================================================
94 void FeaturesAPI_BooleanCommon::setToolObjects(
95 const std::list<ModelHighAPI_Selection>& theToolObjects)
97 fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_ADVANCED(), mycreationMethod);
98 fillAttribute(theToolObjects, mytoolObjects);
103 //==================================================================================================
104 void FeaturesAPI_BooleanCommon::setUseFuzzy(bool theUseFuzzy)
106 fillAttribute(theUseFuzzy, myuseFuzzy);
111 //==================================================================================================
112 void FeaturesAPI_BooleanCommon::setFuzzyValue(const ModelHighAPI_Double& theFuzzy)
114 fillAttribute(theFuzzy, myfuzzyValue);
119 //==================================================================================================
120 void FeaturesAPI_BooleanCommon::setAdvancedMode(const bool theMode)
123 fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_ADVANCED(), mycreationMethod);
125 fillAttribute(FeaturesPlugin_BooleanCommon::CREATION_METHOD_SIMPLE(), mycreationMethod);
131 //==================================================================================================
132 void FeaturesAPI_BooleanCommon::dump(ModelHighAPI_Dumper& theDumper) const
134 FeaturePtr aBase = feature();
136 theDumper << aBase << " = model.addCommon";
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 double aFuzzy = aBase->real(FeaturesPlugin_BooleanCommon::FUZZY_PARAM_ID())->value();
147 theDumper << "(" << aDocName << ", " << anObjects;
149 if (aMode->value() == FeaturesPlugin_BooleanCommon::CREATION_METHOD_ADVANCED()) {
150 theDumper << ", " << aTools;
154 theDumper << ", fuzzyParam = " << aFuzzy;
156 if (!aBase->data()->version().empty())
157 theDumper << ", keepSubResults = True";
159 theDumper << ")" << std::endl;
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)
169 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanCommon::ID());
171 aFeature->data()->setVersion("");
172 BooleanCommonPtr aCommon;
173 if (theToolObjects.empty())
174 aCommon.reset(new FeaturesAPI_BooleanCommon(aFeature, theMainObjects, fuzzyParam));
176 aCommon.reset(new FeaturesAPI_BooleanCommon(aFeature, theMainObjects, theToolObjects, fuzzyParam));