]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchAPI/SketchAPI_Arc.cpp
Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / SketchAPI / SketchAPI_Arc.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        SketchAPI_Arc.cpp
4 // Created:     09 June 2016
5 // Author:      Dmitry Bobylev
6
7 #include "SketchAPI_Arc.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 #include <SketchPlugin_ConstraintCoincidence.h>
17 #include <SketchPlugin_ConstraintTangent.h>
18
19 /// Obtain constraints prepared by tangent arc
20 static std::list<FeaturePtr> tangentArcConstraints(const FeaturePtr& theArc);
21
22 //================================================================================================
23 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature> & theFeature)
24 : SketchAPI_SketchEntity(theFeature)
25 {
26   initialize();
27 }
28
29 //================================================================================================
30 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
31                              double theCenterX, double theCenterY,
32                              double theStartX, double theStartY,
33                              double theEndX, double theEndY,
34                              bool theInversed)
35 : SketchAPI_SketchEntity(theFeature)
36 {
37   if(initialize()) {
38     setByCenterStartEnd(theCenterX, theCenterY, theStartX,
39                         theStartY, theEndX, theEndY, theInversed);
40   }
41 }
42
43 //================================================================================================
44 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
45                              const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
46                              const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
47                              const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
48                              bool theInversed)
49 : SketchAPI_SketchEntity(theFeature)
50 {
51   if(initialize()) {
52     setByCenterStartEnd(theCenter, theStart, theEnd, theInversed);
53   }
54 }
55
56 //================================================================================================
57 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
58                              const ModelHighAPI_Selection& theExternal)
59 : SketchAPI_SketchEntity(theFeature)
60 {
61   if (initialize()) {
62     setByExternal(theExternal);
63   }
64 }
65
66 //================================================================================================
67 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
68                              const std::string& theExternalName)
69 : SketchAPI_SketchEntity(theFeature)
70 {
71   if (initialize()) {
72     setByExternalName(theExternalName);
73   }
74 }
75
76 //================================================================================================
77 SketchAPI_Arc::~SketchAPI_Arc()
78 {
79
80 }
81
82 //================================================================================================
83 void SketchAPI_Arc::setByCenterStartEnd(double theCenterX, double theCenterY,
84                                         double theStartX, double theStartY,
85                                         double theEndX, double theEndY,
86                                         bool theInversed)
87 {
88   fillAttribute(center(), theCenterX, theCenterY);
89   fillAttribute(startPoint(), theStartX, theStartY);
90   fillAttribute(endPoint(), theEndX, theEndY);
91   fillAttribute(theInversed, myreversed);
92
93   execute();
94 }
95
96 //================================================================================================
97 void SketchAPI_Arc::setByCenterStartEnd(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
98                                         const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
99                                         const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
100                                         bool theInversed)
101 {
102   fillAttribute(theCenter, mycenter);
103   fillAttribute(theStart, mystartPoint);
104   fillAttribute(theEnd, myendPoint);
105   fillAttribute(theInversed, myreversed);
106
107   execute();
108 }
109
110 //================================================================================================
111 void SketchAPI_Arc::setByExternal(const ModelHighAPI_Selection & theExternal)
112 {
113   fillAttribute(theExternal, external());
114
115   execute();
116 }
117
118 //===============================================================================================
119 void SketchAPI_Arc::setByExternalName(const std::string & theExternalName)
120 {
121   fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
122
123   execute();
124 }
125
126 //================================================================================================
127 void SketchAPI_Arc::dump(ModelHighAPI_Dumper& theDumper) const
128 {
129   if (isCopy())
130     return; // no need to dump copied feature
131
132   FeaturePtr aBase = feature();
133   const std::string& aSketchName = theDumper.parentName(aBase);
134
135   AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
136   if (anExternal->context()) {
137     // arc is external
138     theDumper << aBase << " = " << aSketchName << ".addArc(" << anExternal << ")" << std::endl;
139   } else {
140     // arc given by center and start, end points
141     theDumper << aBase << " = " << aSketchName << ".addArc(" << center() << ", "
142               << startPoint() << ", " << endPoint() << ", " << reversed() << ")" << std::endl;
143   }
144   // dump "auxiliary" flag if necessary
145   SketchAPI_SketchEntity::dump(theDumper);
146 }