Salome HOME
d74986f53c6a1aa4db78c2e715214d94d6daa6f3
[modules/shaper.git] / src / SketchAPI / SketchAPI_Arc.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 "SketchAPI_Arc.h"
21
22 #include <GeomAPI_Pnt2d.h>
23
24 #include <ModelHighAPI_Double.h>
25 #include <ModelHighAPI_Dumper.h>
26 #include <ModelHighAPI_Selection.h>
27 #include <ModelHighAPI_Tools.h>
28
29 #include <SketchPlugin_ConstraintCoincidence.h>
30 #include <SketchPlugin_ConstraintTangent.h>
31
32 //================================================================================================
33 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature> & theFeature)
34 : SketchAPI_SketchEntity(theFeature)
35 {
36   initialize();
37 }
38
39 //================================================================================================
40 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
41                              double theCenterX, double theCenterY,
42                              double theStartX, double theStartY,
43                              double theEndX, double theEndY,
44                              bool theInversed)
45 : SketchAPI_SketchEntity(theFeature)
46 {
47   if(initialize()) {
48     setByCenterStartEnd(theCenterX, theCenterY, theStartX,
49                         theStartY, theEndX, theEndY, theInversed);
50   }
51 }
52
53 //================================================================================================
54 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
55                              const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
56                              const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
57                              const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
58                              bool theInversed)
59 : SketchAPI_SketchEntity(theFeature)
60 {
61   if(initialize()) {
62     setByCenterStartEnd(theCenter, theStart, theEnd, theInversed);
63   }
64 }
65
66 //================================================================================================
67 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
68                              const ModelHighAPI_Selection& theExternal)
69 : SketchAPI_SketchEntity(theFeature)
70 {
71   if (initialize()) {
72     setByExternal(theExternal);
73   }
74 }
75
76 //================================================================================================
77 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
78                              const std::wstring& theExternalName)
79 : SketchAPI_SketchEntity(theFeature)
80 {
81   if (initialize()) {
82     setByExternalName(theExternalName);
83   }
84 }
85
86 //================================================================================================
87 SketchAPI_Arc::~SketchAPI_Arc()
88 {
89
90 }
91
92 //================================================================================================
93 void SketchAPI_Arc::setByCenterStartEnd(double theCenterX, double theCenterY,
94                                         double theStartX, double theStartY,
95                                         double theEndX, double theEndY,
96                                         bool theInversed)
97 {
98   fillAttribute(center(), theCenterX, theCenterY);
99   fillAttribute(startPoint(), theStartX, theStartY);
100   fillAttribute(endPoint(), theEndX, theEndY);
101   fillAttribute(theInversed, myreversed);
102
103   execute();
104 }
105
106 //================================================================================================
107 void SketchAPI_Arc::setByCenterStartEnd(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
108                                         const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
109                                         const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
110                                         bool theInversed)
111 {
112   fillAttribute(theCenter, mycenter);
113   fillAttribute(theStart, mystartPoint);
114   fillAttribute(theEnd, myendPoint);
115   fillAttribute(theInversed, myreversed);
116
117   execute();
118 }
119
120 //================================================================================================
121 void SketchAPI_Arc::setByExternal(const ModelHighAPI_Selection & theExternal)
122 {
123   fillAttribute(theExternal, external());
124
125   execute();
126 }
127
128 //===============================================================================================
129 void SketchAPI_Arc::setByExternalName(const std::wstring & theExternalName)
130 {
131   fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
132
133   execute();
134 }
135
136 //================================================================================================
137 void SketchAPI_Arc::dump(ModelHighAPI_Dumper& theDumper) const
138 {
139   if (isCopy())
140     return; // no need to dump copied feature
141
142   FeaturePtr aBase = feature();
143   const std::string& aSketchName = theDumper.parentName(aBase);
144
145   AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
146   if (anExternal->context()) {
147     // arc is external
148     theDumper << aBase << " = " << aSketchName << ".addArc(" << anExternal << ")" << std::endl;
149   } else {
150     // arc given by center and start, end points
151     theDumper << aBase << " = " << aSketchName << ".addArc(" << center() << ", "
152               << startPoint() << ", " << endPoint() << ", " << reversed() << ")" << std::endl;
153   }
154   // dump "auxiliary" flag if necessary
155   SketchAPI_SketchEntity::dump(theDumper);
156 }