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