Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Chamfer.cpp
1 // Copyright (C) 2017-2023  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_Chamfer.h"
21
22 #include <ModelHighAPI_Double.h>
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Tools.h>
25
26 FeaturesAPI_Chamfer::FeaturesAPI_Chamfer(const std::shared_ptr<ModelAPI_Feature>& theFeature)
27   : ModelHighAPI_Interface(theFeature)
28 {
29   initialize();
30 }
31
32 FeaturesAPI_Chamfer::FeaturesAPI_Chamfer(const std::shared_ptr<ModelAPI_Feature>& theFeature,
33                                          const std::list<ModelHighAPI_Selection>& theBaseObjects,
34                                          const bool performDistances,
35                                          const ModelHighAPI_Double& theVal1,
36                                          const ModelHighAPI_Double& theVal2)
37   : ModelHighAPI_Interface(theFeature)
38 {
39   if (initialize()) {
40     fillAttribute(theBaseObjects, mybaseObjects);
41     if (performDistances) {
42       fillAttribute(FeaturesPlugin_Chamfer::CREATION_METHOD_DISTANCE_DISTANCE(), mycreationMethod);
43       fillAttribute(theVal1, myd1);
44       fillAttribute(theVal2, myd2);
45     } else {
46       fillAttribute(FeaturesPlugin_Chamfer::CREATION_METHOD_DISTANCE_ANGLE(), mycreationMethod);
47       fillAttribute(theVal1, myd);
48       fillAttribute(theVal2, myangle);
49     }
50
51     execIfBaseNotEmpty();
52   }
53 }
54
55 FeaturesAPI_Chamfer::~FeaturesAPI_Chamfer()
56 {
57 }
58
59 //==================================================================================================
60 void FeaturesAPI_Chamfer::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
61 {
62   mybaseObjects->clear();
63   fillAttribute(theBaseObjects, mybaseObjects);
64
65   execIfBaseNotEmpty();
66 }
67
68 void FeaturesAPI_Chamfer::setDistances(const ModelHighAPI_Double& theD1,
69                                        const ModelHighAPI_Double& theD2)
70 {
71   fillAttribute(FeaturesPlugin_Chamfer::CREATION_METHOD_DISTANCE_DISTANCE(), mycreationMethod);
72   fillAttribute(theD1, myd1);
73   fillAttribute(theD2, myd2);
74
75   execIfBaseNotEmpty();
76 }
77
78 void FeaturesAPI_Chamfer::setDistAngle(const ModelHighAPI_Double& theDistance,
79                                        const ModelHighAPI_Double& theAngle)
80 {
81   fillAttribute(FeaturesPlugin_Chamfer::CREATION_METHOD_DISTANCE_ANGLE(), mycreationMethod);
82   fillAttribute(theDistance, myd);
83   fillAttribute(theAngle, myangle);
84
85   execIfBaseNotEmpty();
86 }
87
88 void FeaturesAPI_Chamfer::dump(ModelHighAPI_Dumper& theDumper) const
89 {
90   FeaturePtr aBase = feature();
91   const std::string& aDocName = theDumper.name(aBase->document());
92
93   AttributeSelectionListPtr anAttrObjects =
94     aBase->selectionList(FeaturesPlugin_Chamfer::OBJECT_LIST_ID());
95
96   theDumper << aBase << " = model.addChamfer(" << aDocName << ", " << anAttrObjects;
97
98   std::string aCreationMethod = aBase->string(FeaturesPlugin_Chamfer::CREATION_METHOD())->value();
99
100   if(aCreationMethod == FeaturesPlugin_Chamfer::CREATION_METHOD_DISTANCE_DISTANCE()) {
101     AttributeDoublePtr anAttrD1 = aBase->real(FeaturesPlugin_Chamfer::D1_ID());
102     AttributeDoublePtr anAttrD2 = aBase->real(FeaturesPlugin_Chamfer::D2_ID());
103     theDumper << ", True, " << anAttrD1 << ", " << anAttrD2;
104   } else if(aCreationMethod == FeaturesPlugin_Chamfer::CREATION_METHOD_DISTANCE_ANGLE()) {
105     AttributeDoublePtr anAttrD = aBase->real(FeaturesPlugin_Chamfer::D_ID());
106     AttributeDoublePtr anAttrAngle = aBase->real(FeaturesPlugin_Chamfer::ANGLE_ID());
107     theDumper << ", False, " << anAttrD << ", " << anAttrAngle;
108   }
109
110   if (!aBase->data()->version().empty())
111     theDumper << ", keepSubResults = True";
112
113   theDumper << ")" << std::endl;
114 }
115
116 void FeaturesAPI_Chamfer::execIfBaseNotEmpty()
117 {
118   if (mybaseObjects->size() > 0)
119     execute();
120 }
121
122
123 //==================================================================================================
124
125 ChamferPtr addChamfer(const std::shared_ptr<ModelAPI_Document>& thePart,
126                       const std::list<ModelHighAPI_Selection>& theBaseObjects,
127                       const bool performDistances,
128                       const ModelHighAPI_Double& theVal1,
129                       const ModelHighAPI_Double& theVal2,
130                       const bool keepSubResults)
131 {
132   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Chamfer::ID());
133   if (!keepSubResults)
134     aFeature->data()->setVersion("");
135   return ChamferPtr(new FeaturesAPI_Chamfer(aFeature, theBaseObjects, performDistances,
136                                             theVal1, theVal2));
137 }