]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchAPI/SketchAPI_MacroRectangle.cpp
Salome HOME
move rectangle plugin from python addons to C++.
[modules/shaper.git] / src / SketchAPI / SketchAPI_MacroRectangle.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_MacroRectangle.h"
21 #include "SketchAPI_Rectangle.h"
22
23 #include <GeomAPI_Pnt2d.h>
24
25 #include <ModelHighAPI_Double.h>
26 #include <ModelHighAPI_Dumper.h>
27 #include <ModelHighAPI_Selection.h>
28 #include <ModelHighAPI_Tools.h>
29
30 //==================================================================================================
31 SketchAPI_MacroRectangle::SketchAPI_MacroRectangle(const std::shared_ptr<ModelAPI_Feature>& theFeature)
32   : SketchAPI_SketchEntity(theFeature)
33 {
34   initialize();
35 }
36
37 //==================================================================================================
38 SketchAPI_MacroRectangle::SketchAPI_MacroRectangle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
39                                                    double theStartX,
40                                                    double theStartY,
41                                                    double theSecondX,
42                                                    double theSecondY, bool isSecondPointCenter):
43   SketchAPI_SketchEntity(theFeature)
44 {
45   if(initialize()) {
46     if(isSecondPointCenter)
47       setByStartAndCenterPoints(theStartX, theStartY, theSecondX, theSecondY);
48     else
49       setByStartAndEndPoints(theStartX, theStartY, theSecondX, theSecondY);
50   }
51 }
52
53 //==================================================================================================
54 SketchAPI_MacroRectangle::SketchAPI_MacroRectangle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
55                                                    const std::shared_ptr<GeomAPI_Pnt2d>& theStartPoint,
56                                                    const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint, bool isSecondPointCenter):
57   SketchAPI_SketchEntity(theFeature)
58 {
59   if(initialize()) {
60     if(isSecondPointCenter)
61       setByStartAndCenterPoints(theStartPoint, theSecondPoint);
62     else
63       setByStartAndEndPoints(theStartPoint, theSecondPoint);
64   }
65 }
66
67 //==================================================================================================
68 SketchAPI_MacroRectangle::~SketchAPI_MacroRectangle()
69 {
70 }
71
72 //==================================================================================================
73 void SketchAPI_MacroRectangle::setByStartAndEndPoints(double theStartX, double theStartY,
74                                                       double theEndX, double theEndY)
75 {
76   fillAttribute(SketchPlugin_MacroRectangle::START_END_POINT_TYPE_ID(), rectangleType());
77   fillAttribute(startPoint1(), theStartX, theStartY);
78   fillAttribute(endPoint1(), theEndX, theEndY);
79   execute();
80 }
81
82 //==================================================================================================
83 void SketchAPI_MacroRectangle::setByStartAndEndPoints(const std::shared_ptr<GeomAPI_Pnt2d>& theStartPoint,
84                                                       const std::shared_ptr<GeomAPI_Pnt2d>& theEndPoint)
85 {
86   fillAttribute(SketchPlugin_MacroRectangle::START_END_POINT_TYPE_ID(), rectangleType());
87   fillAttribute(theStartPoint, startPoint1());
88   fillAttribute(theEndPoint, endPoint1());
89
90   execute();
91 }
92
93 //==================================================================================================
94 void SketchAPI_MacroRectangle::setByStartAndCenterPoints(double theStartX, double theStartY,
95                                                          double theCenterX, double theCenterY)
96 {
97   fillAttribute(SketchPlugin_MacroRectangle::START_CENTER_POINT_TYPE_ID(), rectangleType());
98   fillAttribute(startPoint2(), theStartX, theStartY);
99   fillAttribute(centerPoint(), theCenterX, theCenterY);
100   execute();
101 }
102
103 //==================================================================================================
104 void SketchAPI_MacroRectangle::setByStartAndCenterPoints(const std::shared_ptr<GeomAPI_Pnt2d>& theStartPoint,
105                                                          const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint){
106   fillAttribute(SketchPlugin_MacroRectangle::START_END_POINT_TYPE_ID(), rectangleType());
107   fillAttribute(theStartPoint, startPoint2());
108   fillAttribute(theCenterPoint, centerPoint());
109
110   execute();
111 }
112
113 //==================================================================================================
114 /*
115 void SketchAPI_MacroRectangle::dump(ModelHighAPI_Dumper& theDumper) const
116 {
117   FeaturePtr aBase = feature();
118
119   std::shared_ptr<SketchPlugin_MacroRectangle> myRectangle = std::dynamic_pointer_cast<SketchPlugin_MacroRectangle>(aBase);
120   if(!myRectangle)
121     return;
122
123   if (isCopy())
124     return; // no need to dump copied feature
125
126   const std::string& aSketchName = theDumper.parentName(aBase);
127
128   AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
129   if (anExternal->context()) {
130     // rectangle is external
131     theDumper << aBase << " = " << aSketchName << ".addRectangle(" << anExternal << ")" << std::endl;
132   } else {
133     theDumper << aBase << " = " << aSketchName << ".addRectangle(";
134
135     if(myRectangle->TYPE_ID() == SketchPlugin_MacroRectangle::START_CENTER_POINT_TYPE_ID())
136       // rectangle given by start and center points
137       theDumper  << startPoint2() << ", " << centerPoint() << ", 1)" << std::endl;
138     else
139       // rectangle given by start and end points
140       theDumper  << startPoint1() << ", " << endPoint1() << ", 0)" << std::endl;
141   }
142   // dump "auxiliary" flag if necessary
143   SketchAPI_SketchEntity::dump(theDumper);
144 }
145 */