Salome HOME
Task 2.7. Horizontal and Vertical Distance constraint
[modules/shaper.git] / src / SketchAPI / SketchAPI_Rectangle.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 // Name   : SketchAPI_Rectangle.cpp
3 // Purpose:
4 //
5 // History:
6 // 17/06/16 - Sergey POKHODENKO - Creation of the file
7
8 //--------------------------------------------------------------------------------------
9 #include "SketchAPI_Rectangle.h"
10 //--------------------------------------------------------------------------------------
11 #include <GeomAPI_Pnt2d.h>
12 //--------------------------------------------------------------------------------------
13 #include <ModelHighAPI_Selection.h>
14 #include <ModelHighAPI_Tools.h>
15 //--------------------------------------------------------------------------------------
16 SketchAPI_Rectangle::SketchAPI_Rectangle(
17     const std::shared_ptr<ModelAPI_Feature> & theFeature)
18 : SketchAPI_SketchEntity(theFeature)
19 {
20   initialize();
21 }
22
23 SketchAPI_Rectangle::SketchAPI_Rectangle(
24     const std::shared_ptr<ModelAPI_Feature> & theFeature,
25     double theX1, double theY1, double theX2, double theY2)
26 : SketchAPI_SketchEntity(theFeature)
27 {
28   if (initialize()) {
29     setByCoordinates(theX1, theY1, theX2, theY2);
30   }
31 }
32
33 SketchAPI_Rectangle::SketchAPI_Rectangle(
34     const std::shared_ptr<ModelAPI_Feature> & theFeature,
35     const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
36     const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
37 : SketchAPI_SketchEntity(theFeature)
38 {
39   if (initialize()) {
40     setByPoints(theStartPoint, theEndPoint);
41   }
42 }
43
44 SketchAPI_Rectangle::~SketchAPI_Rectangle()
45 {
46 }
47
48 //--------------------------------------------------------------------------------------
49 void SketchAPI_Rectangle::setByCoordinates(
50     double theX1, double theY1, double theX2, double theY2)
51 {
52   fillAttribute(startPoint(), theX1, theY1);
53   fillAttribute(endPoint(), theX2, theY2);
54
55   execute();
56 }
57
58 void SketchAPI_Rectangle::setByPoints(
59     const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
60     const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
61 {
62   fillAttribute(theStartPoint, startPoint());
63   fillAttribute(theEndPoint, endPoint());
64
65   execute();
66 }
67
68 //--------------------------------------------------------------------------------------
69
70 std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_Rectangle::lines() const
71 {
72   std::list<FeaturePtr> aFeatures;
73   std::list<ObjectPtr> aList = linesList()->list();
74   std::list<ObjectPtr>::const_iterator anIt = aList.begin();
75   for (; anIt != aList.end(); ++anIt)
76     aFeatures.push_back(ModelAPI_Feature::feature(*anIt));
77   return SketchAPI_SketchEntity::wrap(aFeatures);
78 }