1 // Copyright (C) 2014-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_Symmetry.h"
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Tools.h>
25 //==================================================================================================
26 FeaturesAPI_Symmetry::FeaturesAPI_Symmetry(const std::shared_ptr<ModelAPI_Feature>& theFeature)
27 : ModelHighAPI_Interface(theFeature)
32 //==================================================================================================
33 FeaturesAPI_Symmetry::FeaturesAPI_Symmetry(const std::shared_ptr<ModelAPI_Feature>& theFeature,
34 const std::list<ModelHighAPI_Selection>& theMainObjects,
35 const ModelHighAPI_Selection& theObject,
37 : ModelHighAPI_Interface(theFeature)
40 fillAttribute(theMainObjects, mainObjects());
41 fillAttribute(theKeepOriginal, keepOriginal());
42 GeomAPI_Shape::ShapeType aType = getShapeType(theObject);
43 if(aType == GeomAPI_Shape::VERTEX) {
45 } else if(aType == GeomAPI_Shape::EDGE) {
47 } else if(aType == GeomAPI_Shape::FACE) {
53 //==================================================================================================
54 FeaturesAPI_Symmetry::~FeaturesAPI_Symmetry()
58 //==================================================================================================
59 void FeaturesAPI_Symmetry::setMainObjects(
60 const std::list<ModelHighAPI_Selection>& theMainObjects)
62 fillAttribute(theMainObjects, mainObjects());
67 //==================================================================================================
68 void FeaturesAPI_Symmetry::setPoint(const ModelHighAPI_Selection& thePointObject)
70 fillAttribute(FeaturesPlugin_Symmetry::CREATION_METHOD_BY_POINT(), creationMethod());
71 fillAttribute(thePointObject, pointObject());
76 //==================================================================================================
77 void FeaturesAPI_Symmetry::setAxis(const ModelHighAPI_Selection& theAxisObject)
79 fillAttribute(FeaturesPlugin_Symmetry::CREATION_METHOD_BY_AXIS(), creationMethod());
80 fillAttribute(theAxisObject, axisObject());
85 //==================================================================================================
86 void FeaturesAPI_Symmetry::setPlane(const ModelHighAPI_Selection& thePlaneObject)
88 fillAttribute(FeaturesPlugin_Symmetry::CREATION_METHOD_BY_PLANE(), creationMethod());
89 fillAttribute(thePlaneObject, planeObject());
94 //==================================================================================================
95 void FeaturesAPI_Symmetry::dump(ModelHighAPI_Dumper& theDumper) const
97 FeaturePtr aBase = feature();
98 const std::string& aDocName = theDumper.name(aBase->document());
100 AttributeSelectionListPtr anAttrObjects =
101 aBase->selectionList(FeaturesPlugin_Symmetry::OBJECTS_LIST_ID());
102 theDumper << aBase << " = model.addSymmetry(" << aDocName << ", " << anAttrObjects;
104 std::string aCreationMethod =
105 aBase->string(FeaturesPlugin_Symmetry::CREATION_METHOD())->value();
107 if (aCreationMethod == FeaturesPlugin_Symmetry::CREATION_METHOD_BY_POINT()) {
108 AttributeSelectionPtr anAttrPoint =
109 aBase->selection(FeaturesPlugin_Symmetry::POINT_OBJECT_ID());
110 theDumper << ", " << anAttrPoint;
111 } else if (aCreationMethod == FeaturesPlugin_Symmetry::CREATION_METHOD_BY_AXIS()) {
112 AttributeSelectionPtr anAttrAxis =
113 aBase->selection(FeaturesPlugin_Symmetry::AXIS_OBJECT_ID());
114 theDumper << ", " << anAttrAxis;
115 } else if (aCreationMethod == FeaturesPlugin_Symmetry::CREATION_METHOD_BY_PLANE()) {
116 AttributeSelectionPtr anAttrPlane =
117 aBase->selection(FeaturesPlugin_Symmetry::PLANE_OBJECT_ID());
118 theDumper << ", " << anAttrPlane;
121 theDumper << ", keepOriginal = " << keepOriginal();
123 if (!aBase->data()->version().empty())
124 theDumper << ", keepSubResults = True";
126 theDumper << ")" << std::endl;
129 //==================================================================================================
130 SymmetryPtr addSymmetry(const std::shared_ptr<ModelAPI_Document>& thePart,
131 const std::list<ModelHighAPI_Selection>& theMainObjects,
132 const ModelHighAPI_Selection& theObject,
133 const bool theKeepOriginal,
134 const bool theKeepSubResults)
136 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Symmetry::ID());
137 if (!theKeepSubResults)
138 aFeature->data()->setVersion("");
139 return SymmetryPtr(new FeaturesAPI_Symmetry(
140 aFeature, theMainObjects, theObject, theKeepOriginal));