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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "SketchAPI_Line.h"
21 //--------------------------------------------------------------------------------------
22 #include <GeomAPI_Pnt2d.h>
23 //--------------------------------------------------------------------------------------
24 #include <ModelHighAPI_Dumper.h>
25 #include <ModelHighAPI_Selection.h>
26 #include <ModelHighAPI_Tools.h>
27 //--------------------------------------------------------------------------------------
28 SketchAPI_Line::SketchAPI_Line(
29 const std::shared_ptr<ModelAPI_Feature> & theFeature)
30 : SketchAPI_SketchEntity(theFeature)
35 SketchAPI_Line::SketchAPI_Line(
36 const std::shared_ptr<ModelAPI_Feature> & theFeature,
37 double theX1, double theY1, double theX2, double theY2)
38 : SketchAPI_SketchEntity(theFeature)
41 setByCoordinates(theX1, theY1, theX2, theY2);
45 SketchAPI_Line::SketchAPI_Line(
46 const std::shared_ptr<ModelAPI_Feature> & theFeature,
47 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
48 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
49 : SketchAPI_SketchEntity(theFeature)
52 setByPoints(theStartPoint, theEndPoint);
56 SketchAPI_Line::SketchAPI_Line(
57 const std::shared_ptr<ModelAPI_Feature> & theFeature,
58 const ModelHighAPI_Selection & theExternal )
59 : SketchAPI_SketchEntity(theFeature)
62 setByExternal(theExternal);
66 SketchAPI_Line::SketchAPI_Line(
67 const std::shared_ptr<ModelAPI_Feature> & theFeature,
68 const std::string & theExternalName )
69 : SketchAPI_SketchEntity(theFeature)
72 setByExternalName(theExternalName);
76 SketchAPI_Line::~SketchAPI_Line()
81 //--------------------------------------------------------------------------------------
82 void SketchAPI_Line::setByCoordinates(
83 double theX1, double theY1, double theX2, double theY2)
85 fillAttribute(startPoint(), theX1, theY1);
86 fillAttribute(endPoint(), theX2, theY2);
91 void SketchAPI_Line::setByPoints(
92 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
93 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
95 fillAttribute(theStartPoint, startPoint());
96 fillAttribute(theEndPoint, endPoint());
101 void SketchAPI_Line::setByExternal(const ModelHighAPI_Selection & theExternal)
103 fillAttribute(theExternal, external());
108 void SketchAPI_Line::setByExternalName(const std::string & theExternalName)
110 fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
115 //--------------------------------------------------------------------------------------
116 void SketchAPI_Line::setStartPoint(double theX, double theY)
118 fillAttribute(startPoint(), theX, theY);
122 void SketchAPI_Line::setStartPoint(const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
124 fillAttribute(thePoint, startPoint());
128 void SketchAPI_Line::setEndPoint(double theX, double theY)
130 fillAttribute(endPoint(), theX, theY);
134 void SketchAPI_Line::setEndPoint(const std::shared_ptr<GeomAPI_Pnt2d> & thePoint)
136 fillAttribute(thePoint, endPoint());
141 //--------------------------------------------------------------------------------------
143 void SketchAPI_Line::dump(ModelHighAPI_Dumper& theDumper) const
146 return; // no need to dump copied feature
148 FeaturePtr aBase = feature();
149 const std::string& aSketchName = theDumper.parentName(aBase);
151 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
152 if (anExternal->context()) {
154 theDumper << aBase << " = " << aSketchName << ".addLine(" << anExternal << ")" << std::endl;
156 // segment given by its points
157 theDumper << aBase << " = " << aSketchName << ".addLine("
158 << startPoint() << ", " << endPoint() << ")" << std::endl;
160 // dump "auxiliary" flag if necessary
161 SketchAPI_SketchEntity::dump(theDumper);