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_Line.h"
22 //--------------------------------------------------------------------------------------
23 #include <GeomAPI_Pnt2d.h>
24 //--------------------------------------------------------------------------------------
25 #include <ModelHighAPI_Dumper.h>
26 #include <ModelHighAPI_Selection.h>
27 #include <ModelHighAPI_Tools.h>
28 //--------------------------------------------------------------------------------------
29 SketchAPI_Line::SketchAPI_Line(
30 const std::shared_ptr<ModelAPI_Feature> & theFeature)
31 : SketchAPI_SketchEntity(theFeature)
36 SketchAPI_Line::SketchAPI_Line(
37 const std::shared_ptr<ModelAPI_Feature> & theFeature,
38 double theX1, double theY1, double theX2, double theY2)
39 : SketchAPI_SketchEntity(theFeature)
42 setByCoordinates(theX1, theY1, theX2, theY2);
46 SketchAPI_Line::SketchAPI_Line(
47 const std::shared_ptr<ModelAPI_Feature> & theFeature,
48 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
49 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
50 : SketchAPI_SketchEntity(theFeature)
53 setByPoints(theStartPoint, theEndPoint);
57 SketchAPI_Line::SketchAPI_Line(
58 const std::shared_ptr<ModelAPI_Feature> & theFeature,
59 const ModelHighAPI_Selection & theExternal )
60 : SketchAPI_SketchEntity(theFeature)
63 setByExternal(theExternal);
67 SketchAPI_Line::SketchAPI_Line(
68 const std::shared_ptr<ModelAPI_Feature> & theFeature,
69 const std::string & theExternalName )
70 : SketchAPI_SketchEntity(theFeature)
73 setByExternalName(theExternalName);
77 SketchAPI_Line::~SketchAPI_Line()
82 //--------------------------------------------------------------------------------------
83 void SketchAPI_Line::setByCoordinates(
84 double theX1, double theY1, double theX2, double theY2)
86 fillAttribute(startPoint(), theX1, theY1);
87 fillAttribute(endPoint(), theX2, theY2);
92 void SketchAPI_Line::setByPoints(
93 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
94 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
96 fillAttribute(theStartPoint, startPoint());
97 fillAttribute(theEndPoint, endPoint());
102 void SketchAPI_Line::setByExternal(const ModelHighAPI_Selection & theExternal)
104 fillAttribute(theExternal, external());
109 void SketchAPI_Line::setByExternalName(const std::string & theExternalName)
111 fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
116 //--------------------------------------------------------------------------------------
117 void SketchAPI_Line::setStartPoint(double theX, double theY)
119 fillAttribute(startPoint(), theX, theY);
123 void SketchAPI_Line::setStartPoint(const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
125 fillAttribute(thePoint, startPoint());
129 void SketchAPI_Line::setEndPoint(double theX, double theY)
131 fillAttribute(endPoint(), theX, theY);
135 void SketchAPI_Line::setEndPoint(const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
137 fillAttribute(thePoint, endPoint());
142 //--------------------------------------------------------------------------------------
144 void SketchAPI_Line::dump(ModelHighAPI_Dumper& theDumper) const
147 return; // no need to dump copied feature
149 FeaturePtr aBase = feature();
150 const std::string& aSketchName = theDumper.parentName(aBase);
152 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
153 if (anExternal->context()) {
155 theDumper << aBase << " = " << aSketchName << ".addLine(" << anExternal << ")" << std::endl;
157 // segment given by its points
158 theDumper << aBase << " = " << aSketchName << ".addLine("
159 << startPoint() << ", " << endPoint() << ")" << std::endl;
161 // dump "auxiliary" flag if necessary
162 SketchAPI_SketchEntity::dump(theDumper);