Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / SketchAPI / SketchAPI_Circle.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        SketchAPI_Circle.cpp
4 // Created:     09 June 2016
5 // Author:      Dmitry Bobylev
6
7 #include "SketchAPI_Circle.h"
8
9 #include <GeomAPI_Pnt2d.h>
10
11 #include <ModelHighAPI_Double.h>
12 #include <ModelHighAPI_Dumper.h>
13 #include <ModelHighAPI_Selection.h>
14 #include <ModelHighAPI_Tools.h>
15
16 //==================================================================================================
17 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature> & theFeature)
18 : SketchAPI_SketchEntity(theFeature)
19 {
20   initialize();
21 }
22
23 //==================================================================================================
24 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
25                                    double theCenterX,
26                                    double theCenterY,
27                                    double theRadius)
28 : SketchAPI_SketchEntity(theFeature)
29 {
30   if(initialize()) {
31     setByCenterAndRadius(theCenterX, theCenterY, theRadius);
32   }
33 }
34
35 //==================================================================================================
36 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
37                                    const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
38                                    double theRadius)
39 : SketchAPI_SketchEntity(theFeature)
40 {
41   if(initialize()) {
42     setByCenterAndRadius(theCenter, theRadius);
43   }
44 }
45
46 //==================================================================================================
47 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
48                                    const ModelHighAPI_Selection& theExternal)
49 : SketchAPI_SketchEntity(theFeature)
50 {
51   if (initialize()) {
52     setByExternal(theExternal);
53   }
54 }
55
56 //==================================================================================================
57 SketchAPI_Circle::SketchAPI_Circle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
58                                    const std::string& theExternalName)
59 : SketchAPI_SketchEntity(theFeature)
60 {
61   if (initialize()) {
62     setByExternalName(theExternalName);
63   }
64 }
65
66 //==================================================================================================
67 SketchAPI_Circle::~SketchAPI_Circle()
68 {
69
70 }
71
72 //==================================================================================================
73 void SketchAPI_Circle::setByCenterAndRadius(double theCenterX, double theCenterY, double theRadius)
74 {
75   fillAttribute(center(), theCenterX, theCenterY);
76   fillAttribute(theRadius, myradius);
77
78   execute();
79 }
80
81 //==================================================================================================
82 void SketchAPI_Circle::setByCenterAndRadius(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
83                                             double theRadius)
84 {
85   fillAttribute(theCenter, mycenter);
86   fillAttribute(theRadius, myradius);
87
88   execute();
89 }
90
91 //==================================================================================================
92 void SketchAPI_Circle::setByExternal(const ModelHighAPI_Selection & theExternal)
93 {
94   fillAttribute(theExternal, external());
95
96   execute();
97 }
98
99 //==================================================================================================
100 void SketchAPI_Circle::setByExternalName(const std::string & theExternalName)
101 {
102   fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
103
104   execute();
105 }
106
107 //==================================================================================================
108 void SketchAPI_Circle::setCenter(double theX, double theY)
109 {
110   fillAttribute(center(), theX, theY);
111
112   execute();
113 }
114
115 //==================================================================================================
116 void SketchAPI_Circle::setCenter(const std::shared_ptr<GeomAPI_Pnt2d> & theCenter)
117 {
118   fillAttribute(theCenter, mycenter);
119
120   execute();
121 }
122
123 //==================================================================================================
124 void SketchAPI_Circle::setRadius(double theRadius)
125 {
126   fillAttribute(ModelHighAPI_Double(theRadius), myradius);
127
128   execute();
129 }
130
131 //==================================================================================================
132 void SketchAPI_Circle::dump(ModelHighAPI_Dumper& theDumper) const
133 {
134   if (isCopy())
135     return; // no need to dump copied feature
136
137   FeaturePtr aBase = feature();
138   const std::string& aSketchName = theDumper.parentName(aBase);
139
140   AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
141   if (anExternal->context()) {
142     // circle is external
143     theDumper << aBase << " = " << aSketchName << ".addCircle(" << anExternal << ")" << std::endl;
144   } else {
145     // circle given by center and radius
146     theDumper << aBase << " = " << aSketchName << ".addCircle("
147               << center() << ", " << radius() << ")" << std::endl;
148   }
149   // dump "auxiliary" flag if necessary
150   SketchAPI_SketchEntity::dump(theDumper);
151 }