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(const std::shared_ptr<ModelAPI_Feature>& theFeature)
32 : SketchAPI_SketchEntity(theFeature)
37 //==================================================================================================
38 SketchAPI_MacroRectangle::SketchAPI_MacroRectangle(const std::shared_ptr<ModelAPI_Feature>& theFeature,
42 double theSecondY, bool isFirstPointCenter):
43 SketchAPI_SketchEntity(theFeature)
46 if(isFirstPointCenter)
47 setByCenterAndEndPoints(theStartX, theStartY, theSecondX, theSecondY);
49 setByStartAndEndPoints(theStartX, theStartY, theSecondX, theSecondY);
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)
60 if(isFirstPointCenter)
61 setByCenterAndEndPoints(theStartPoint, theSecondPoint);
63 setByStartAndEndPoints(theStartPoint, theSecondPoint);
67 //==================================================================================================
68 SketchAPI_MacroRectangle::~SketchAPI_MacroRectangle()
72 //==================================================================================================
73 void SketchAPI_MacroRectangle::setByStartAndEndPoints(double theStartX, double theStartY,
74 double theEndX, double theEndY)
76 fillAttribute(SketchPlugin_MacroRectangle::START_END_POINT_TYPE_ID(), rectangleType());
77 fillAttribute(startPoint1(), theStartX, theStartY);
78 fillAttribute(endPoint1(), theEndX, theEndY);
82 //==================================================================================================
83 void SketchAPI_MacroRectangle::setByStartAndEndPoints(const std::shared_ptr<GeomAPI_Pnt2d>& theStartPoint,
84 const std::shared_ptr<GeomAPI_Pnt2d>& theEndPoint)
86 fillAttribute(SketchPlugin_MacroRectangle::START_END_POINT_TYPE_ID(), rectangleType());
87 fillAttribute(theStartPoint, startPoint1());
88 fillAttribute(theEndPoint, endPoint1());
93 //==================================================================================================
94 void SketchAPI_MacroRectangle::setByCenterAndEndPoints(double theCenterX, double theCenterY, double theEndX, double theEndY)
96 fillAttribute(SketchPlugin_MacroRectangle::CENTER_END_POINT_TYPE_ID(), rectangleType());
97 fillAttribute(endPoint2(), theEndX, theEndY);
98 fillAttribute(centerPoint(), theCenterX, theCenterY);
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());
111 //==================================================================================================
113 void SketchAPI_MacroRectangle::dump(ModelHighAPI_Dumper& theDumper) const
115 FeaturePtr aBase = feature();
117 std::shared_ptr<SketchPlugin_MacroRectangle> myRectangle = std::dynamic_pointer_cast<SketchPlugin_MacroRectangle>(aBase);
122 return; // no need to dump copied feature
124 const std::string& aSketchName = theDumper.parentName(aBase);
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;
131 theDumper << aBase << " = " << aSketchName << ".addRectangle(";
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;
137 // rectangle given by start and end points
138 theDumper << startPoint1() << ", " << endPoint1() << ", 0)" << std::endl;
140 // dump "auxiliary" flag if necessary
141 SketchAPI_SketchEntity::dump(theDumper);