Salome HOME
Merge remote-tracking branch 'remotes/origin/2018_Lot1_Tasks'
[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 : ModelHighAPI_Interface(theFeature)
38 {
39   if(initialize()) {
40     fillAttribute(theMainObjects, mainObjects());
41     GeomAPI_Shape::ShapeType aType = getShapeType(theObject);
42     if(aType == GeomAPI_Shape::VERTEX) {
43       setPoint(theObject);
44     } else if(aType == GeomAPI_Shape::EDGE) {
45       setAxis(theObject);
46     } else if(aType == GeomAPI_Shape::FACE) {
47       setPlane(theObject);
48     }
49   }
50 }
51
52 //==================================================================================================
53 FeaturesAPI_Symmetry::~FeaturesAPI_Symmetry()
54 {
55 }
56
57 //==================================================================================================
58 void FeaturesAPI_Symmetry::setMainObjects(
59   const std::list<ModelHighAPI_Selection>& theMainObjects)
60 {
61   fillAttribute(theMainObjects, mainObjects());
62
63   execute();
64 }
65
66 //==================================================================================================
67 void FeaturesAPI_Symmetry::setPoint(const ModelHighAPI_Selection& thePointObject)
68 {
69   fillAttribute(FeaturesPlugin_Symmetry::CREATION_METHOD_BY_POINT(), creationMethod());
70   fillAttribute(thePointObject, pointObject());
71
72   execute();
73 }
74
75 //==================================================================================================
76 void FeaturesAPI_Symmetry::setAxis(const ModelHighAPI_Selection& theAxisObject)
77 {
78   fillAttribute(FeaturesPlugin_Symmetry::CREATION_METHOD_BY_AXIS(), creationMethod());
79   fillAttribute(theAxisObject, axisObject());
80
81   execute();
82 }
83
84 //==================================================================================================
85 void FeaturesAPI_Symmetry::setPlane(const ModelHighAPI_Selection& thePlaneObject)
86 {
87   fillAttribute(FeaturesPlugin_Symmetry::CREATION_METHOD_BY_PLANE(), creationMethod());
88   fillAttribute(thePlaneObject, planeObject());
89
90   execute();
91 }
92
93 //==================================================================================================
94 void FeaturesAPI_Symmetry::dump(ModelHighAPI_Dumper& theDumper) const
95 {
96   FeaturePtr aBase = feature();
97   const std::string& aDocName = theDumper.name(aBase->document());
98
99   AttributeSelectionListPtr anAttrObjects =
100     aBase->selectionList(FeaturesPlugin_Symmetry::OBJECTS_LIST_ID());
101   theDumper << aBase << " = model.addMirror(" << aDocName << ", " << anAttrObjects;
102
103   std::string aCreationMethod =
104     aBase->string(FeaturesPlugin_Symmetry::CREATION_METHOD())->value();
105
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;
118   }
119
120   theDumper << ")" << std::endl;
121 }
122
123 //==================================================================================================
124 SymmetryPtr addMirror(const std::shared_ptr<ModelAPI_Document>& thePart,
125                       const std::list<ModelHighAPI_Selection>& theMainObjects,
126                       const ModelHighAPI_Selection& theObject)
127 {
128   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Symmetry::ID());
129   return SymmetryPtr(new FeaturesAPI_Symmetry(aFeature, theMainObjects, theObject));
130 }