]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchAPI/SketchAPI_Rectangle.cpp
Salome HOME
#18963 C++17 ready
[modules/shaper.git] / src / SketchAPI / SketchAPI_Rectangle.cpp
1 // Copyright (C) 2014-2020  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_Rectangle.h"
21 //--------------------------------------------------------------------------------------
22 #include <GeomAPI_Pnt2d.h>
23 //--------------------------------------------------------------------------------------
24 #include <ModelHighAPI_Selection.h>
25 #include <ModelHighAPI_Tools.h>
26 //--------------------------------------------------------------------------------------
27 SketchAPI_Rectangle::SketchAPI_Rectangle(
28     const std::shared_ptr<ModelAPI_Feature> & theFeature)
29 : SketchAPI_SketchEntity(theFeature)
30 {
31   initialize();
32 }
33
34 SketchAPI_Rectangle::SketchAPI_Rectangle(
35     const std::shared_ptr<ModelAPI_Feature> & theFeature,
36     double theX1, double theY1, double theX2, double theY2)
37 : SketchAPI_SketchEntity(theFeature)
38 {
39   if (initialize()) {
40     setByCoordinates(theX1, theY1, theX2, theY2);
41   }
42 }
43
44 SketchAPI_Rectangle::SketchAPI_Rectangle(
45     const std::shared_ptr<ModelAPI_Feature> & theFeature,
46     const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
47     const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
48 : SketchAPI_SketchEntity(theFeature)
49 {
50   if (initialize()) {
51     setByPoints(theStartPoint, theEndPoint);
52   }
53 }
54
55 SketchAPI_Rectangle::~SketchAPI_Rectangle()
56 {
57 }
58
59 //--------------------------------------------------------------------------------------
60 void SketchAPI_Rectangle::setByCoordinates(
61     double theX1, double theY1, double theX2, double theY2)
62 {
63   fillAttribute(startPoint(), theX1, theY1);
64   fillAttribute(endPoint(), theX2, theY2);
65
66   execute();
67 }
68
69 void SketchAPI_Rectangle::setByPoints(
70     const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
71     const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
72 {
73   fillAttribute(theStartPoint, startPoint());
74   fillAttribute(theEndPoint, endPoint());
75
76   execute();
77 }
78
79 //--------------------------------------------------------------------------------------
80
81 std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_Rectangle::lines() const
82 {
83   std::list<FeaturePtr> aFeatures;
84   std::list<ObjectPtr> aList = linesList()->list();
85   std::list<ObjectPtr>::const_iterator anIt = aList.begin();
86   for (; anIt != aList.end(); ++anIt)
87     aFeatures.push_back(ModelAPI_Feature::feature(*anIt));
88   return SketchAPI_SketchEntity::wrap(aFeatures);
89 }