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