1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "FeaturesAPI_Symmetry.h"
23 #include <ModelHighAPI_Dumper.h>
24 #include <ModelHighAPI_Tools.h>
26 //==================================================================================================
27 FeaturesAPI_Symmetry::FeaturesAPI_Symmetry(const std::shared_ptr<ModelAPI_Feature>& theFeature)
28 : ModelHighAPI_Interface(theFeature)
33 //==================================================================================================
34 FeaturesAPI_Symmetry::FeaturesAPI_Symmetry(const std::shared_ptr<ModelAPI_Feature>& theFeature,
35 const std::list<ModelHighAPI_Selection>& theMainObjects,
36 const ModelHighAPI_Selection& theObject)
37 : ModelHighAPI_Interface(theFeature)
40 fillAttribute(theMainObjects, mainObjects());
41 GeomAPI_Shape::ShapeType aType = getShapeType(theObject);
42 if(aType == GeomAPI_Shape::VERTEX) {
44 } else if(aType == GeomAPI_Shape::EDGE) {
46 } else if(aType == GeomAPI_Shape::FACE) {
52 //==================================================================================================
53 FeaturesAPI_Symmetry::~FeaturesAPI_Symmetry()
57 //==================================================================================================
58 void FeaturesAPI_Symmetry::setMainObjects(
59 const std::list<ModelHighAPI_Selection>& theMainObjects)
61 fillAttribute(theMainObjects, mainObjects());
66 //==================================================================================================
67 void FeaturesAPI_Symmetry::setPoint(const ModelHighAPI_Selection& thePointObject)
69 fillAttribute(FeaturesPlugin_Symmetry::CREATION_METHOD_BY_POINT(), creationMethod());
70 fillAttribute(thePointObject, pointObject());
75 //==================================================================================================
76 void FeaturesAPI_Symmetry::setAxis(const ModelHighAPI_Selection& theAxisObject)
78 fillAttribute(FeaturesPlugin_Symmetry::CREATION_METHOD_BY_AXIS(), creationMethod());
79 fillAttribute(theAxisObject, axisObject());
84 //==================================================================================================
85 void FeaturesAPI_Symmetry::setPlane(const ModelHighAPI_Selection& thePlaneObject)
87 fillAttribute(FeaturesPlugin_Symmetry::CREATION_METHOD_BY_PLANE(), creationMethod());
88 fillAttribute(thePlaneObject, planeObject());
93 //==================================================================================================
94 void FeaturesAPI_Symmetry::dump(ModelHighAPI_Dumper& theDumper) const
96 FeaturePtr aBase = feature();
97 const std::string& aDocName = theDumper.name(aBase->document());
99 AttributeSelectionListPtr anAttrObjects =
100 aBase->selectionList(FeaturesPlugin_Symmetry::OBJECTS_LIST_ID());
101 theDumper << aBase << " = model.addMirror(" << aDocName << ", " << anAttrObjects;
103 std::string aCreationMethod =
104 aBase->string(FeaturesPlugin_Symmetry::CREATION_METHOD())->value();
106 if (aCreationMethod == FeaturesPlugin_Symmetry::CREATION_METHOD_BY_POINT()) {
107 AttributeSelectionPtr anAttrPoint =
108 aBase->selection(FeaturesPlugin_Symmetry::POINT_OBJECT_ID());
109 theDumper << ", " << anAttrPoint;
110 } else if (aCreationMethod == FeaturesPlugin_Symmetry::CREATION_METHOD_BY_AXIS()) {
111 AttributeSelectionPtr anAttrAxis =
112 aBase->selection(FeaturesPlugin_Symmetry::AXIS_OBJECT_ID());
113 theDumper << ", " << anAttrAxis;
114 } else if (aCreationMethod == FeaturesPlugin_Symmetry::CREATION_METHOD_BY_PLANE()) {
115 AttributeSelectionPtr anAttrPlane =
116 aBase->selection(FeaturesPlugin_Symmetry::PLANE_OBJECT_ID());
117 theDumper << ", " << anAttrPlane;
120 theDumper << ")" << std::endl;
123 //==================================================================================================
124 SymmetryPtr addMirror(const std::shared_ptr<ModelAPI_Document>& thePart,
125 const std::list<ModelHighAPI_Selection>& theMainObjects,
126 const ModelHighAPI_Selection& theObject)
128 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Symmetry::ID());
129 return SymmetryPtr(new FeaturesAPI_Symmetry(aFeature, theMainObjects, theObject));