]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchAPI/SketchAPI_Rectangle.cpp
Salome HOME
[GITHUB #2] problem in export dialog - difference in STEP vs BREP
[modules/shaper.git] / src / SketchAPI / SketchAPI_Rectangle.cpp
1 // Copyright (C) 2014-2024  CEA, EDF
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 #include "SketchAPI_Point.h"
24 //--------------------------------------------------------------------------------------
25 #include <ModelHighAPI_Selection.h>
26 #include <ModelHighAPI_Tools.h>
27 #include <ModelHighAPI_Dumper.h>
28
29 //--------------------------------------------------------------------------------------
30 SketchAPI_Rectangle::SketchAPI_Rectangle(
31     const std::shared_ptr<ModelAPI_Feature> & theFeature)
32   : SketchAPI_SketchEntity(theFeature)
33 {
34   initialize();
35 }
36
37 SketchAPI_Rectangle::SketchAPI_Rectangle(const std::shared_ptr<ModelAPI_Feature> & theFeature,
38                                          double theX1, double theY1,
39                                          double theX2, double theY2,
40                                          bool theCreateByCenterAndCorner)
41   : SketchAPI_SketchEntity(theFeature)
42 {
43   if (initialize()) {
44     theCreateByCenterAndCorner ? setByCenterAndCornerCoords(theX1, theY1, theX2, theY2) : setByCoordinates(theX1, theY1, theX2, theY2);
45   }
46 }
47
48 SketchAPI_Rectangle::SketchAPI_Rectangle(const std::shared_ptr<ModelAPI_Feature> & theFeature,
49                                          const std::shared_ptr<GeomAPI_Pnt2d> & thePoint1,
50                                          const std::shared_ptr<GeomAPI_Pnt2d> & thePoint2,
51                                          bool theCreateByCenterAndCorner)
52   : SketchAPI_SketchEntity(theFeature)
53 {
54   if (initialize()) {
55     theCreateByCenterAndCorner ? setByCenterAndCornerPoints(thePoint1, thePoint2) : setByPoints(thePoint1, thePoint2);
56   }
57 }
58
59 //--------------------------------------------------------------------------------------
60 void SketchAPI_Rectangle::setByCoordinates(
61     double theX1, double theY1, double theX2, double theY2)
62 {
63   fillAttribute("RectangleTypeByCorners", type());
64   fillAttribute(startPoint(), theX1, theY1);
65   fillAttribute(endPoint(), theX2, theY2);
66   execute();
67 }
68
69 void SketchAPI_Rectangle::setByPoints(const std::shared_ptr<GeomAPI_Pnt2d> & theFirstPoint,
70                                       const std::shared_ptr<GeomAPI_Pnt2d> & theSecondPoint)
71 {
72   fillAttribute("RectangleTypeByCorners", type());
73   fillAttribute(theFirstPoint, startPoint());
74   fillAttribute(theSecondPoint, endPoint());
75   execute();
76 }
77
78 void SketchAPI_Rectangle::setByCenterAndCornerCoords(
79   double theCenterX, double theCenterY,
80   double theCornerX, double theCornerY
81 ) {
82   fillAttribute("RectangleTypeCentered", type());
83   fillAttribute(centerPoint(), theCenterX, theCenterY);
84   fillAttribute(cornerPoint(), theCornerX, theCornerY);
85   execute();
86 }
87
88 void SketchAPI_Rectangle::setByCenterAndCornerPoints(
89   const std::shared_ptr<GeomAPI_Pnt2d> & theCenterPoint,
90   const std::shared_ptr<GeomAPI_Pnt2d> & theCornerPoint
91 ) {
92   fillAttribute("RectangleTypeCentered", type());
93   fillAttribute(theCenterPoint, centerPoint());
94   fillAttribute(theCornerPoint, cornerPoint());
95   execute();
96 }
97
98 //--------------------------------------------------------------------------------------
99
100 std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_Rectangle::lines() const
101 {
102   std::list<FeaturePtr> aFeatures;
103   std::list<ObjectPtr> aList = linesList()->list();
104   std::list<ObjectPtr>::const_iterator anIt = aList.begin();
105   for (; anIt != aList.end(); ++anIt)
106     aFeatures.push_back(ModelAPI_Feature::feature(*anIt));
107   return SketchAPI_SketchEntity::wrap(aFeatures);
108 }
109
110 std::shared_ptr<SketchAPI_Point> SketchAPI_Rectangle::centerSketchPoint() const
111 {
112   auto aFeature = ModelAPI_Feature::feature(centerPointRef()->object());
113   return std::shared_ptr<SketchAPI_Point>(new SketchAPI_Point(aFeature));
114 }