1 // Copyright (C) 2014-2020 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SketchAPI_MacroRectangle.h"
21 #include "SketchAPI_Rectangle.h"
23 #include <GeomAPI_Pnt2d.h>
25 #include <ModelHighAPI_Double.h>
26 #include <ModelHighAPI_Dumper.h>
27 #include <ModelHighAPI_Selection.h>
28 #include <ModelHighAPI_Tools.h>
30 //==================================================================================================
31 SketchAPI_MacroRectangle::SketchAPI_MacroRectangle(
32 const std::shared_ptr<ModelAPI_Feature>& theFeature)
33 : SketchAPI_SketchEntity(theFeature)
38 //==================================================================================================
39 SketchAPI_MacroRectangle::SketchAPI_MacroRectangle(
40 const std::shared_ptr<ModelAPI_Feature>& theFeature,
45 bool isFirstPointCenter):
46 SketchAPI_SketchEntity(theFeature)
49 if(isFirstPointCenter)
50 setByCenterAndEndPoints(theStartX, theStartY, theSecondX, theSecondY);
52 setByStartAndEndPoints(theStartX, theStartY, theSecondX, theSecondY);
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)
64 if(isFirstPointCenter)
65 setByCenterAndEndPoints(theStartPoint, theSecondPoint);
67 setByStartAndEndPoints(theStartPoint, theSecondPoint);
71 //==================================================================================================
72 SketchAPI_MacroRectangle::~SketchAPI_MacroRectangle()
76 //==================================================================================================
77 void SketchAPI_MacroRectangle::setByStartAndEndPoints(double theStartX, double theStartY,
78 double theEndX, double theEndY)
80 fillAttribute(SketchPlugin_MacroRectangle::START_END_POINT_TYPE_ID(), rectangleType());
81 fillAttribute(startPoint1(), theStartX, theStartY);
82 fillAttribute(endPoint1(), theEndX, theEndY);
86 //==================================================================================================
87 void SketchAPI_MacroRectangle::setByStartAndEndPoints(
88 const std::shared_ptr<GeomAPI_Pnt2d>& theStartPoint,
89 const std::shared_ptr<GeomAPI_Pnt2d>& theEndPoint)
91 fillAttribute(SketchPlugin_MacroRectangle::START_END_POINT_TYPE_ID(), rectangleType());
92 fillAttribute(theStartPoint, startPoint1());
93 fillAttribute(theEndPoint, endPoint1());
98 //==================================================================================================
99 void SketchAPI_MacroRectangle::setByCenterAndEndPoints(double theCenterX, double theCenterY,
100 double theEndX, double theEndY)
102 fillAttribute(SketchPlugin_MacroRectangle::CENTER_END_POINT_TYPE_ID(), rectangleType());
103 fillAttribute(endPoint2(), theEndX, theEndY);
104 fillAttribute(centerPoint(), theCenterX, theCenterY);
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());
119 //==================================================================================================
121 void SketchAPI_MacroRectangle::dump(ModelHighAPI_Dumper& theDumper) const
123 FeaturePtr aBase = feature();
125 std::shared_ptr<SketchPlugin_MacroRectangle> myRectangle = std::dynamic_pointer_cast<SketchPlugin_MacroRectangle>(aBase);
130 return; // no need to dump copied feature
132 const std::string& aSketchName = theDumper.parentName(aBase);
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;
139 theDumper << aBase << " = " << aSketchName << ".addRectangle(";
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;
145 // rectangle given by start and end points
146 theDumper << startPoint1() << ", " << endPoint1() << ", 0)" << std::endl;
148 // dump "auxiliary" flag if necessary
149 SketchAPI_SketchEntity::dump(theDumper);