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