Salome HOME
1. Manage color of construction point using preferences dialog box.
[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(
32     const std::shared_ptr<ModelAPI_Feature>& theFeature)
33   : SketchAPI_SketchEntity(theFeature)
34 {
35   initialize();
36 }
37
38 //==================================================================================================
39 SketchAPI_MacroRectangle::SketchAPI_MacroRectangle(
40     const std::shared_ptr<ModelAPI_Feature>& theFeature,
41     double theStartX,
42     double theStartY,
43     double theSecondX,
44     double theSecondY,
45     bool isFirstPointCenter):
46   SketchAPI_SketchEntity(theFeature)
47 {
48   if(initialize()) {
49     if(isFirstPointCenter)
50       setByCenterAndEndPoints(theStartX, theStartY, theSecondX, theSecondY);
51     else
52       setByStartAndEndPoints(theStartX, theStartY, theSecondX, theSecondY);
53   }
54 }
55
56 //==================================================================================================
57 SketchAPI_MacroRectangle::SketchAPI_MacroRectangle(
58     const std::shared_ptr<ModelAPI_Feature>& theFeature,
59     const std::shared_ptr<GeomAPI_Pnt2d>& theStartPoint,
60     const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint, bool isFirstPointCenter):
61   SketchAPI_SketchEntity(theFeature)
62 {
63   if(initialize()) {
64     if(isFirstPointCenter)
65       setByCenterAndEndPoints(theStartPoint, theSecondPoint);
66     else
67       setByStartAndEndPoints(theStartPoint, theSecondPoint);
68   }
69 }
70
71 //==================================================================================================
72 SketchAPI_MacroRectangle::~SketchAPI_MacroRectangle()
73 {
74 }
75
76 //==================================================================================================
77 void SketchAPI_MacroRectangle::setByStartAndEndPoints(double theStartX, double theStartY,
78                                                       double theEndX, double theEndY)
79 {
80   fillAttribute(SketchPlugin_MacroRectangle::START_END_POINT_TYPE_ID(), rectangleType());
81   fillAttribute(startPoint1(), theStartX, theStartY);
82   fillAttribute(endPoint1(), theEndX, theEndY);
83   execute();
84 }
85
86 //==================================================================================================
87 void SketchAPI_MacroRectangle::setByStartAndEndPoints(
88     const std::shared_ptr<GeomAPI_Pnt2d>& theStartPoint,
89     const std::shared_ptr<GeomAPI_Pnt2d>& theEndPoint)
90 {
91   fillAttribute(SketchPlugin_MacroRectangle::START_END_POINT_TYPE_ID(), rectangleType());
92   fillAttribute(theStartPoint, startPoint1());
93   fillAttribute(theEndPoint, endPoint1());
94
95   execute();
96 }
97
98 //==================================================================================================
99 void SketchAPI_MacroRectangle::setByCenterAndEndPoints(double theCenterX, double theCenterY,
100                                                        double theEndX, double theEndY)
101 {
102   fillAttribute(SketchPlugin_MacroRectangle::CENTER_END_POINT_TYPE_ID(), rectangleType());
103   fillAttribute(endPoint2(), theEndX, theEndY);
104   fillAttribute(centerPoint(), theCenterX, theCenterY);
105   execute();
106 }
107
108 //==================================================================================================
109 void SketchAPI_MacroRectangle::setByCenterAndEndPoints(
110     const std::shared_ptr<GeomAPI_Pnt2d>& theCenterPoint,
111     const std::shared_ptr<GeomAPI_Pnt2d>& theEndPoint){
112   fillAttribute(SketchPlugin_MacroRectangle::CENTER_END_POINT_TYPE_ID(), rectangleType());
113   fillAttribute(theEndPoint, endPoint2());
114   fillAttribute(theCenterPoint, centerPoint());
115
116   execute();
117 }
118
119 //==================================================================================================
120 /*
121 void SketchAPI_MacroRectangle::dump(ModelHighAPI_Dumper& theDumper) const
122 {
123   FeaturePtr aBase = feature();
124
125   std::shared_ptr<SketchPlugin_MacroRectangle> myRectangle = std::dynamic_pointer_cast<SketchPlugin_MacroRectangle>(aBase);
126   if(!myRectangle)
127     return;
128
129   if (isCopy())
130     return; // no need to dump copied feature
131
132   const std::string& aSketchName = theDumper.parentName(aBase);
133
134   AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
135   if (anExternal->context()) {
136     // rectangle is external
137     theDumper << aBase << " = " << aSketchName << ".addRectangle(" << anExternal << ")" << std::endl;
138   } else {
139     theDumper << aBase << " = " << aSketchName << ".addRectangle(";
140
141     if(myRectangle->TYPE_ID() == SketchPlugin_MacroRectangle::START_CENTER_POINT_TYPE_ID())
142       // rectangle given by start and center points
143       theDumper  << startPoint2() << ", " << centerPoint() << ", 1)" << std::endl;
144     else
145       // rectangle given by start and end points
146       theDumper  << startPoint1() << ", " << endPoint1() << ", 0)" << std::endl;
147   }
148   // dump "auxiliary" flag if necessary
149   SketchAPI_SketchEntity::dump(theDumper);
150 }
151 */