Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Symmetry.cpp
1 // Copyright (C) 2014-2017  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<mailto:webmaster.salome@opencascade.com>
18 //
19
20 #include "FeaturesAPI_Symmetry.h"
21
22 #include <ModelHighAPI_Dumper.h>
23 #include <ModelHighAPI_Tools.h>
24
25 //==================================================================================================
26 FeaturesAPI_Symmetry::FeaturesAPI_Symmetry(const std::shared_ptr<ModelAPI_Feature>& theFeature)
27 : ModelHighAPI_Interface(theFeature)
28 {
29   initialize();
30 }
31
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)
36 : ModelHighAPI_Interface(theFeature)
37 {
38   if(initialize()) {
39     fillAttribute(theMainObjects, mainObjects());
40     GeomAPI_Shape::ShapeType aType = getShapeType(theObject);
41     if(aType == GeomAPI_Shape::VERTEX) {
42       setPoint(theObject);
43     } else if(aType == GeomAPI_Shape::EDGE) {
44       setAxis(theObject);
45     } else if(aType == GeomAPI_Shape::FACE) {
46       setPlane(theObject);
47     }
48   }
49 }
50
51 //==================================================================================================
52 FeaturesAPI_Symmetry::~FeaturesAPI_Symmetry()
53 {
54 }
55
56 //==================================================================================================
57 void FeaturesAPI_Symmetry::setMainObjects(
58   const std::list<ModelHighAPI_Selection>& theMainObjects)
59 {
60   fillAttribute(theMainObjects, mainObjects());
61
62   execute();
63 }
64
65 //==================================================================================================
66 void FeaturesAPI_Symmetry::setPoint(const ModelHighAPI_Selection& thePointObject)
67 {
68   fillAttribute(FeaturesPlugin_Symmetry::CREATION_METHOD_BY_POINT(), creationMethod());
69   fillAttribute(thePointObject, pointObject());
70
71   execute();
72 }
73
74 //==================================================================================================
75 void FeaturesAPI_Symmetry::setAxis(const ModelHighAPI_Selection& theAxisObject)
76 {
77   fillAttribute(FeaturesPlugin_Symmetry::CREATION_METHOD_BY_AXIS(), creationMethod());
78   fillAttribute(theAxisObject, axisObject());
79
80   execute();
81 }
82
83 //==================================================================================================
84 void FeaturesAPI_Symmetry::setPlane(const ModelHighAPI_Selection& thePlaneObject)
85 {
86   fillAttribute(FeaturesPlugin_Symmetry::CREATION_METHOD_BY_PLANE(), creationMethod());
87   fillAttribute(thePlaneObject, planeObject());
88
89   execute();
90 }
91
92 //==================================================================================================
93 void FeaturesAPI_Symmetry::dump(ModelHighAPI_Dumper& theDumper) const
94 {
95   FeaturePtr aBase = feature();
96   const std::string& aDocName = theDumper.name(aBase->document());
97
98   AttributeSelectionListPtr anAttrObjects =
99     aBase->selectionList(FeaturesPlugin_Symmetry::OBJECTS_LIST_ID());
100   theDumper << aBase << " = model.addSymmetry(" << aDocName << ", " << anAttrObjects;
101
102   std::string aCreationMethod =
103     aBase->string(FeaturesPlugin_Symmetry::CREATION_METHOD())->value();
104
105   if (aCreationMethod == FeaturesPlugin_Symmetry::CREATION_METHOD_BY_POINT()) {
106     AttributeSelectionPtr anAttrPoint =
107       aBase->selection(FeaturesPlugin_Symmetry::POINT_OBJECT_ID());
108     theDumper << ", " << anAttrPoint;
109   } else if (aCreationMethod == FeaturesPlugin_Symmetry::CREATION_METHOD_BY_AXIS()) {
110     AttributeSelectionPtr anAttrAxis =
111       aBase->selection(FeaturesPlugin_Symmetry::AXIS_OBJECT_ID());
112     theDumper << ", " << anAttrAxis;
113   } else if (aCreationMethod == FeaturesPlugin_Symmetry::CREATION_METHOD_BY_PLANE()) {
114     AttributeSelectionPtr anAttrPlane =
115       aBase->selection(FeaturesPlugin_Symmetry::PLANE_OBJECT_ID());
116     theDumper << ", " << anAttrPlane;
117   }
118
119   theDumper << ")" << std::endl;
120 }
121
122 //==================================================================================================
123 SymmetryPtr addSymmetry(const std::shared_ptr<ModelAPI_Document>& thePart,
124                               const std::list<ModelHighAPI_Selection>& theMainObjects,
125                               const ModelHighAPI_Selection& theObject)
126 {
127   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Symmetry::ID());
128   return SymmetryPtr(new FeaturesAPI_Symmetry(aFeature, theMainObjects, theObject));
129 }