1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "SketchAPI_Arc.h"
23 #include <GeomAPI_Pnt2d.h>
25 #include <ModelHighAPI_Double.h>
26 #include <ModelHighAPI_Dumper.h>
27 #include <ModelHighAPI_Selection.h>
28 #include <ModelHighAPI_Tools.h>
30 #include <SketchPlugin_ConstraintCoincidence.h>
31 #include <SketchPlugin_ConstraintTangent.h>
33 /// Obtain constraints prepared by tangent arc
34 static std::list<FeaturePtr> tangentArcConstraints(const FeaturePtr& theArc);
36 //================================================================================================
37 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature> & theFeature)
38 : SketchAPI_SketchEntity(theFeature)
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,
49 : SketchAPI_SketchEntity(theFeature)
52 setByCenterStartEnd(theCenterX, theCenterY, theStartX,
53 theStartY, theEndX, theEndY, theInversed);
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,
63 : SketchAPI_SketchEntity(theFeature)
66 setByCenterStartEnd(theCenter, theStart, theEnd, theInversed);
70 //================================================================================================
71 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
72 const ModelHighAPI_Selection& theExternal)
73 : SketchAPI_SketchEntity(theFeature)
76 setByExternal(theExternal);
80 //================================================================================================
81 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
82 const std::string& theExternalName)
83 : SketchAPI_SketchEntity(theFeature)
86 setByExternalName(theExternalName);
90 //================================================================================================
91 SketchAPI_Arc::~SketchAPI_Arc()
96 //================================================================================================
97 void SketchAPI_Arc::setByCenterStartEnd(double theCenterX, double theCenterY,
98 double theStartX, double theStartY,
99 double theEndX, double theEndY,
102 fillAttribute(center(), theCenterX, theCenterY);
103 fillAttribute(startPoint(), theStartX, theStartY);
104 fillAttribute(endPoint(), theEndX, theEndY);
105 fillAttribute(theInversed, myreversed);
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,
116 fillAttribute(theCenter, mycenter);
117 fillAttribute(theStart, mystartPoint);
118 fillAttribute(theEnd, myendPoint);
119 fillAttribute(theInversed, myreversed);
124 //================================================================================================
125 void SketchAPI_Arc::setByExternal(const ModelHighAPI_Selection & theExternal)
127 fillAttribute(theExternal, external());
132 //===============================================================================================
133 void SketchAPI_Arc::setByExternalName(const std::string & theExternalName)
135 fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
140 //================================================================================================
141 void SketchAPI_Arc::dump(ModelHighAPI_Dumper& theDumper) const
144 return; // no need to dump copied feature
146 FeaturePtr aBase = feature();
147 const std::string& aSketchName = theDumper.parentName(aBase);
149 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
150 if (anExternal->context()) {
152 theDumper << aBase << " = " << aSketchName << ".addArc(" << anExternal << ")" << std::endl;
154 // arc given by center and start, end points
155 theDumper << aBase << " = " << aSketchName << ".addArc(" << center() << ", "
156 << startPoint() << ", " << endPoint() << ", " << reversed() << ")" << std::endl;
158 // dump "auxiliary" flag if necessary
159 SketchAPI_SketchEntity::dump(theDumper);