]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchAPI/SketchAPI_MacroRectangle.cpp
Salome HOME
rectangle feature: complete rectangle type by center and end points
[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 isFirstPointCenter):
43   SketchAPI_SketchEntity(theFeature)
44 {
45   if(initialize()) {
46     if(isFirstPointCenter)
47       setByCenterAndEndPoints(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 isFirstPointCenter):
57   SketchAPI_SketchEntity(theFeature)
58 {
59   if(initialize()) {
60     if(isFirstPointCenter)
61       setByCenterAndEndPoints(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::setByCenterAndEndPoints(double theCenterX, double theCenterY, double theEndX, double theEndY)
95 {
96   fillAttribute(SketchPlugin_MacroRectangle::CENTER_END_POINT_TYPE_ID(), rectangleType());
97   fillAttribute(endPoint2(), theEndX, theEndY);
98   fillAttribute(centerPoint(), theCenterX, theCenterY);
99   execute();
100 }
101
102 //==================================================================================================
103 void SketchAPI_MacroRectangle::setByCenterAndEndPoints(const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint, const std::shared_ptr<GeomAPI_Pnt2d>& theEndPoint){
104   fillAttribute(SketchPlugin_MacroRectangle::CENTER_END_POINT_TYPE_ID(), rectangleType());
105   fillAttribute(theEndPoint, endPoint2());
106   fillAttribute(theCenterPoint, centerPoint());
107
108   execute();
109 }
110
111 //==================================================================================================
112 /*
113 void SketchAPI_MacroRectangle::dump(ModelHighAPI_Dumper& theDumper) const
114 {
115   FeaturePtr aBase = feature();
116
117   std::shared_ptr<SketchPlugin_MacroRectangle> myRectangle = std::dynamic_pointer_cast<SketchPlugin_MacroRectangle>(aBase);
118   if(!myRectangle)
119     return;
120
121   if (isCopy())
122     return; // no need to dump copied feature
123
124   const std::string& aSketchName = theDumper.parentName(aBase);
125
126   AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
127   if (anExternal->context()) {
128     // rectangle is external
129     theDumper << aBase << " = " << aSketchName << ".addRectangle(" << anExternal << ")" << std::endl;
130   } else {
131     theDumper << aBase << " = " << aSketchName << ".addRectangle(";
132
133     if(myRectangle->TYPE_ID() == SketchPlugin_MacroRectangle::START_CENTER_POINT_TYPE_ID())
134       // rectangle given by start and center points
135       theDumper  << startPoint2() << ", " << centerPoint() << ", 1)" << std::endl;
136     else
137       // rectangle given by start and end points
138       theDumper  << startPoint1() << ", " << endPoint1() << ", 0)" << std::endl;
139   }
140   // dump "auxiliary" flag if necessary
141   SketchAPI_SketchEntity::dump(theDumper);
142 }
143 */