Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Symmetry.cpp
1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D -->
2
3 // File:        FeaturesAPI_Symmetry.cpp
4 // Created:     07 Dec 2016
5 // Author:      Clarisse Genrault (CEA)
6
7 #include "FeaturesAPI_Symmetry.h"
8
9 #include <ModelHighAPI_Dumper.h>
10 #include <ModelHighAPI_Tools.h>
11
12 //==================================================================================================
13 FeaturesAPI_Symmetry::FeaturesAPI_Symmetry(const std::shared_ptr<ModelAPI_Feature>& theFeature)
14 : ModelHighAPI_Interface(theFeature)
15 {
16   initialize();
17 }
18
19 //==================================================================================================
20 FeaturesAPI_Symmetry::FeaturesAPI_Symmetry(const std::shared_ptr<ModelAPI_Feature>& theFeature,
21                                        const std::list<ModelHighAPI_Selection>& theMainObjects,
22                                        const ModelHighAPI_Selection& theObject)
23 : ModelHighAPI_Interface(theFeature)
24 {
25   if(initialize()) {
26     fillAttribute(theMainObjects, mainObjects());
27     GeomAPI_Shape::ShapeType aType = getShapeType(theObject);
28     if(aType == GeomAPI_Shape::VERTEX) {
29       setPoint(theObject);
30     } else if(aType == GeomAPI_Shape::EDGE) {
31       setAxis(theObject);
32     } else if(aType == GeomAPI_Shape::FACE) {
33       setPlane(theObject);
34     }
35   }
36 }
37
38 //==================================================================================================
39 FeaturesAPI_Symmetry::~FeaturesAPI_Symmetry()
40 {
41 }
42
43 //==================================================================================================
44 void FeaturesAPI_Symmetry::setMainObjects(
45   const std::list<ModelHighAPI_Selection>& theMainObjects)
46 {
47   fillAttribute(theMainObjects, mainObjects());
48
49   execute();
50 }
51
52 //==================================================================================================
53 void FeaturesAPI_Symmetry::setPoint(const ModelHighAPI_Selection& thePointObject)
54 {
55   fillAttribute(FeaturesPlugin_Symmetry::CREATION_METHOD_BY_POINT(), creationMethod());
56   fillAttribute(thePointObject, pointObject());
57
58   execute();
59 }
60
61 //==================================================================================================
62 void FeaturesAPI_Symmetry::setAxis(const ModelHighAPI_Selection& theAxisObject)
63 {
64   fillAttribute(FeaturesPlugin_Symmetry::CREATION_METHOD_BY_AXIS(), creationMethod());
65   fillAttribute(theAxisObject, axisObject());
66
67   execute();
68 }
69
70 //==================================================================================================
71 void FeaturesAPI_Symmetry::setPlane(const ModelHighAPI_Selection& thePlaneObject)
72 {
73   fillAttribute(FeaturesPlugin_Symmetry::CREATION_METHOD_BY_PLANE(), creationMethod());
74   fillAttribute(thePlaneObject, planeObject());
75
76   execute();
77 }
78
79 //==================================================================================================
80 void FeaturesAPI_Symmetry::dump(ModelHighAPI_Dumper& theDumper) const
81 {
82   FeaturePtr aBase = feature();
83   const std::string& aDocName = theDumper.name(aBase->document());
84
85   AttributeSelectionListPtr anAttrObjects =
86     aBase->selectionList(FeaturesPlugin_Symmetry::OBJECTS_LIST_ID());
87   theDumper << aBase << " = model.addSymmetry(" << aDocName << ", " << anAttrObjects;
88
89   std::string aCreationMethod =
90     aBase->string(FeaturesPlugin_Symmetry::CREATION_METHOD())->value();
91
92   if (aCreationMethod == FeaturesPlugin_Symmetry::CREATION_METHOD_BY_POINT()) {
93     AttributeSelectionPtr anAttrPoint =
94       aBase->selection(FeaturesPlugin_Symmetry::POINT_OBJECT_ID());
95     theDumper << ", " << anAttrPoint;
96   } else if (aCreationMethod == FeaturesPlugin_Symmetry::CREATION_METHOD_BY_AXIS()) {
97     AttributeSelectionPtr anAttrAxis =
98       aBase->selection(FeaturesPlugin_Symmetry::AXIS_OBJECT_ID());
99     theDumper << ", " << anAttrAxis;
100   } else if (aCreationMethod == FeaturesPlugin_Symmetry::CREATION_METHOD_BY_PLANE()) {
101     AttributeSelectionPtr anAttrPlane =
102       aBase->selection(FeaturesPlugin_Symmetry::PLANE_OBJECT_ID());
103     theDumper << ", " << anAttrPlane;
104   }
105
106   theDumper << ")" << std::endl;
107 }
108
109 //==================================================================================================
110 SymmetryPtr addSymmetry(const std::shared_ptr<ModelAPI_Document>& thePart,
111                               const std::list<ModelHighAPI_Selection>& theMainObjects,
112                               const ModelHighAPI_Selection& theObject)
113 {
114   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Symmetry::ID());
115   return SymmetryPtr(new FeaturesAPI_Symmetry(aFeature, theMainObjects, theObject));
116 }