1 // Copyright (C) 2017-2019 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_Chamfer.h"
22 #include <ModelHighAPI_Double.h>
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Tools.h>
26 FeaturesAPI_Chamfer::FeaturesAPI_Chamfer(const std::shared_ptr<ModelAPI_Feature>& theFeature)
27 : ModelHighAPI_Interface(theFeature)
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)
40 fillAttribute(theBaseObjects, mybaseObjects);
41 if (performDistances) {
42 fillAttribute(FeaturesPlugin_Chamfer::CREATION_METHOD_DISTANCE_DISTANCE(), mycreationMethod);
43 fillAttribute(theVal1, myd1);
44 fillAttribute(theVal2, myd2);
46 fillAttribute(FeaturesPlugin_Chamfer::CREATION_METHOD_DISTANCE_ANGLE(), mycreationMethod);
47 fillAttribute(theVal1, myd);
48 fillAttribute(theVal2, myangle);
55 FeaturesAPI_Chamfer::~FeaturesAPI_Chamfer()
59 //==================================================================================================
60 void FeaturesAPI_Chamfer::setBase(const std::list<ModelHighAPI_Selection>& theBaseObjects)
62 mybaseObjects->clear();
63 fillAttribute(theBaseObjects, mybaseObjects);
68 void FeaturesAPI_Chamfer::setDistances(const ModelHighAPI_Double& theD1,
69 const ModelHighAPI_Double& theD2)
71 fillAttribute(FeaturesPlugin_Chamfer::CREATION_METHOD_DISTANCE_DISTANCE(), mycreationMethod);
72 fillAttribute(theD1, myd1);
73 fillAttribute(theD2, myd2);
78 void FeaturesAPI_Chamfer::setDistAngle(const ModelHighAPI_Double& theDistance,
79 const ModelHighAPI_Double& theAngle)
81 fillAttribute(FeaturesPlugin_Chamfer::CREATION_METHOD_DISTANCE_ANGLE(), mycreationMethod);
82 fillAttribute(theDistance, myd);
83 fillAttribute(theAngle, myangle);
88 void FeaturesAPI_Chamfer::dump(ModelHighAPI_Dumper& theDumper) const
90 FeaturePtr aBase = feature();
91 const std::string& aDocName = theDumper.name(aBase->document());
93 AttributeSelectionListPtr anAttrObjects =
94 aBase->selectionList(FeaturesPlugin_Chamfer::OBJECT_LIST_ID());
96 theDumper << aBase << " = model.addChamfer(" << aDocName << ", " << anAttrObjects;
98 std::string aCreationMethod = aBase->string(FeaturesPlugin_Chamfer::CREATION_METHOD())->value();
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;
110 theDumper << ")" << std::endl;
113 void FeaturesAPI_Chamfer::execIfBaseNotEmpty()
115 if (mybaseObjects->size() > 0)
120 //==================================================================================================
122 ChamferPtr addChamfer(const std::shared_ptr<ModelAPI_Document>& thePart,
123 const std::list<ModelHighAPI_Selection>& theBaseObjects,
124 const bool performDistances,
125 const ModelHighAPI_Double& theVal1,
126 const ModelHighAPI_Double& theVal2)
128 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Chamfer::ID());
129 return ChamferPtr(new FeaturesAPI_Chamfer(aFeature, theBaseObjects, performDistances,