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(
14   const std::shared_ptr<ModelAPI_Feature>& theFeature)
15 : ModelHighAPI_Interface(theFeature)
16 {
17   initialize();
18 }
19
20 //==================================================================================================
21 FeaturesAPI_Symmetry::FeaturesAPI_Symmetry(const std::shared_ptr<ModelAPI_Feature>& theFeature,
22                                        const std::list<ModelHighAPI_Selection>& theMainObjects,
23                                        const ModelHighAPI_Selection& theObject)
24 : ModelHighAPI_Interface(theFeature)
25 {
26   if(initialize()) {
27     fillAttribute(theMainObjects, mymainObjects);
28     GeomAPI_Shape::ShapeType aType = getShapeType(theObject);
29     if(aType == GeomAPI_Shape::VERTEX) {
30       setPoint(theObject);
31     } else if(aType == GeomAPI_Shape::EDGE) {
32       setAxis(theObject);
33     } else if(aType == GeomAPI_Shape::FACE) {
34       setPlane(theObject);
35     }
36   }
37 }
38
39 //==================================================================================================
40 FeaturesAPI_Symmetry::~FeaturesAPI_Symmetry()
41 {
42
43 }
44
45 //==================================================================================================
46 void FeaturesAPI_Symmetry::setMainObjects(
47   const std::list<ModelHighAPI_Selection>& theMainObjects)
48 {
49   fillAttribute(theMainObjects, mainObjects());
50
51   execute();
52 }
53
54 //==================================================================================================
55 void FeaturesAPI_Symmetry::setPoint(const ModelHighAPI_Selection& thePointObject)
56 {
57   fillAttribute(FeaturesPlugin_Symmetry::CREATION_METHOD_BY_POINT(), creationMethod());
58   fillAttribute(thePointObject, pointObject());
59
60   execute();
61 }
62
63 //==================================================================================================
64 void FeaturesAPI_Symmetry::setAxis(const ModelHighAPI_Selection& theAxisObject)
65 {
66   fillAttribute(FeaturesPlugin_Symmetry::CREATION_METHOD_BY_AXIS(), creationMethod());
67   fillAttribute(theAxisObject, axisObject());
68
69   execute();
70 }
71
72 //==================================================================================================
73 void FeaturesAPI_Symmetry::setPlane(const ModelHighAPI_Selection& thePlaneObject)
74 {
75   fillAttribute(FeaturesPlugin_Symmetry::CREATION_METHOD_BY_PLANE(), creationMethod());
76   fillAttribute(thePlaneObject, planeObject());
77
78   execute();
79 }
80
81 //==================================================================================================
82 void FeaturesAPI_Symmetry::dump(ModelHighAPI_Dumper& theDumper) const
83 {
84   std::cout << "DUMP SYMMETRY" << std::endl;
85   FeaturePtr aBase = feature();
86   const std::string& aDocName = theDumper.name(aBase->document());
87
88   AttributeSelectionListPtr anAttrObjects =
89     aBase->selectionList(FeaturesPlugin_Symmetry::OBJECTS_LIST_ID());
90   theDumper << aBase << " = model.addSymmetry(" << aDocName << ", " << anAttrObjects;
91
92   std::string aCreationMethod =
93     aBase->string(FeaturesPlugin_Symmetry::CREATION_METHOD())->value();
94
95   if (aCreationMethod == FeaturesPlugin_Symmetry::CREATION_METHOD_BY_POINT()) {
96     AttributeSelectionPtr anAttrPoint =
97       aBase->selection(FeaturesPlugin_Symmetry::POINT_OBJECT_ID());
98     theDumper << ", " << anAttrPoint;
99   } else if (aCreationMethod == FeaturesPlugin_Symmetry::CREATION_METHOD_BY_AXIS()) {
100     AttributeSelectionPtr anAttrAxis =
101       aBase->selection(FeaturesPlugin_Symmetry::AXIS_OBJECT_ID());
102     theDumper << ", " << anAttrAxis;
103   } else if (aCreationMethod == FeaturesPlugin_Symmetry::CREATION_METHOD_BY_PLANE()) {
104     AttributeSelectionPtr anAttrPlane =
105       aBase->selection(FeaturesPlugin_Symmetry::PLANE_OBJECT_ID());
106     theDumper << ", " << anAttrPlane;
107   }
108
109    theDumper << ")" << std::endl;
110 }
111
112 //==================================================================================================
113 SymmetryPtr addSymmetry(const std::shared_ptr<ModelAPI_Document>& thePart,
114                               const std::list<ModelHighAPI_Selection>& theMainObjects,
115                               const ModelHighAPI_Selection& theObject)
116 {
117   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Symmetry::ID());
118   return SymmetryPtr(new FeaturesAPI_Symmetry(aFeature, theMainObjects, theObject));
119 }