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_BooleanSmash.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_BooleanSmash::FeaturesAPI_BooleanSmash(
32 const std::shared_ptr<ModelAPI_Feature>& theFeature)
33 : ModelHighAPI_Interface(theFeature)
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)
47 fillAttribute(theMainObjects, VAR_NAME(mainObjects));
48 fillAttribute(theToolObjects, VAR_NAME(toolObjects));
49 fillAttribute(theFuzzy, VAR_NAME(fuzzyParam));
51 // Get the evaluated fuzzy parameter from the attribute!!
52 bool aUseFuzzy = (fuzzyParam()->value() > 0);
53 fillAttribute(aUseFuzzy, VAR_NAME(useFuzzy));
55 ModelHighAPI_Double aFuzzy(DEFAULT_FUZZY);
56 fillAttribute(aFuzzy, VAR_NAME(fuzzyParam));
63 //==================================================================================================
64 FeaturesAPI_BooleanSmash::~FeaturesAPI_BooleanSmash()
69 //==================================================================================================
70 void FeaturesAPI_BooleanSmash::setMainObjects(
71 const std::list<ModelHighAPI_Selection>& theMainObjects)
73 fillAttribute(theMainObjects, VAR_NAME(mainObjects));
78 //==================================================================================================
79 void FeaturesAPI_BooleanSmash::setToolObjects(
80 const std::list<ModelHighAPI_Selection>& theToolObjects)
82 fillAttribute(theToolObjects, VAR_NAME(toolObjects));
87 //==================================================================================================
88 void FeaturesAPI_BooleanSmash::setUseFuzzy(bool theUseFuzzy)
90 fillAttribute(theUseFuzzy, VAR_NAME(useFuzzy));
95 //==================================================================================================
96 void FeaturesAPI_BooleanSmash::setFuzzyValue(const ModelHighAPI_Double& theFuzzy)
98 fillAttribute(theFuzzy, VAR_NAME(fuzzyParam));
103 //==================================================================================================
104 void FeaturesAPI_BooleanSmash::dump(ModelHighAPI_Dumper& theDumper) const
106 FeaturePtr aBase = feature();
108 theDumper << aBase << " = model.addSmash";
110 const std::string& aDocName = theDumper.name(aBase->document());
111 AttributeSelectionListPtr anObjects =
112 aBase->selectionList(FeaturesPlugin_BooleanSmash::OBJECT_LIST_ID());
113 AttributeSelectionListPtr aTools =
114 aBase->selectionList(FeaturesPlugin_BooleanSmash::TOOL_LIST_ID());
115 bool aUseFuzzy = aBase->boolean(FeaturesPlugin_BooleanSmash::USE_FUZZY_ID())->value();
116 AttributeDoublePtr aFuzzy = aBase->real(FeaturesPlugin_BooleanSmash::FUZZY_PARAM_ID());
118 theDumper << "(" << aDocName << ", " << anObjects << ", " << aTools;
121 theDumper << ", fuzzyParam = " << aFuzzy;
123 if (!aBase->data()->version().empty())
124 theDumper << ", keepSubResults = True";
126 theDumper << ")" << std::endl;
129 //==================================================================================================
130 BooleanSmashPtr addSmash(const std::shared_ptr<ModelAPI_Document>& thePart,
131 const std::list<ModelHighAPI_Selection>& theMainObjects,
132 const std::list<ModelHighAPI_Selection>& theToolObjects,
133 const ModelHighAPI_Double& theFuzzy,
134 const bool keepSubResults)
136 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_BooleanSmash::ID());
138 aFeature->data()->setVersion("");
139 return BooleanSmashPtr(new FeaturesAPI_BooleanSmash(aFeature, theMainObjects, theToolObjects, theFuzzy));