Salome HOME
876360c8aadcf33faebd76b84c5f7a0bb61584f9
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Symmetry.cpp
1 // Copyright (C) 2014-2023  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
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                                            bool theKeepOriginal)
37 : ModelHighAPI_Interface(theFeature)
38 {
39   if(initialize()) {
40     fillAttribute(theMainObjects, mainObjects());
41     fillAttribute(theKeepOriginal, keepOriginal());
42     GeomAPI_Shape::ShapeType aType = getShapeType(theObject);
43     if(aType == GeomAPI_Shape::VERTEX) {
44       setPoint(theObject);
45     } else if(aType == GeomAPI_Shape::EDGE) {
46       setAxis(theObject);
47     } else if(aType == GeomAPI_Shape::FACE) {
48       setPlane(theObject);
49     }
50   }
51 }
52
53 //==================================================================================================
54 FeaturesAPI_Symmetry::~FeaturesAPI_Symmetry()
55 {
56 }
57
58 //==================================================================================================
59 void FeaturesAPI_Symmetry::setMainObjects(
60   const std::list<ModelHighAPI_Selection>& theMainObjects)
61 {
62   fillAttribute(theMainObjects, mainObjects());
63
64   execute();
65 }
66
67 //==================================================================================================
68 void FeaturesAPI_Symmetry::setPoint(const ModelHighAPI_Selection& thePointObject)
69 {
70   fillAttribute(FeaturesPlugin_Symmetry::CREATION_METHOD_BY_POINT(), creationMethod());
71   fillAttribute(thePointObject, pointObject());
72
73   execute();
74 }
75
76 //==================================================================================================
77 void FeaturesAPI_Symmetry::setAxis(const ModelHighAPI_Selection& theAxisObject)
78 {
79   fillAttribute(FeaturesPlugin_Symmetry::CREATION_METHOD_BY_AXIS(), creationMethod());
80   fillAttribute(theAxisObject, axisObject());
81
82   execute();
83 }
84
85 //==================================================================================================
86 void FeaturesAPI_Symmetry::setPlane(const ModelHighAPI_Selection& thePlaneObject)
87 {
88   fillAttribute(FeaturesPlugin_Symmetry::CREATION_METHOD_BY_PLANE(), creationMethod());
89   fillAttribute(thePlaneObject, planeObject());
90
91   execute();
92 }
93
94 //==================================================================================================
95 void FeaturesAPI_Symmetry::dump(ModelHighAPI_Dumper& theDumper) const
96 {
97   FeaturePtr aBase = feature();
98   const std::string& aDocName = theDumper.name(aBase->document());
99
100   AttributeSelectionListPtr anAttrObjects =
101     aBase->selectionList(FeaturesPlugin_Symmetry::OBJECTS_LIST_ID());
102   theDumper << aBase << " = model.addSymmetry(" << aDocName << ", " << anAttrObjects;
103
104   std::string aCreationMethod =
105     aBase->string(FeaturesPlugin_Symmetry::CREATION_METHOD())->value();
106
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;
119   }
120
121   theDumper << ", keepOriginal = " << keepOriginal();
122
123   if (!aBase->data()->version().empty())
124     theDumper << ", keepSubResults = True";
125
126   theDumper << ")" << std::endl;
127 }
128
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)
135 {
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));
141 }