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_Rectangle.h"
21 //--------------------------------------------------------------------------------------
22 #include <GeomAPI_Pnt2d.h>
23 //--------------------------------------------------------------------------------------
24 #include <ModelHighAPI_Selection.h>
25 #include <ModelHighAPI_Tools.h>
26 #include <ModelHighAPI_Dumper.h>
28 //--------------------------------------------------------------------------------------
29 SketchAPI_Rectangle::SketchAPI_Rectangle(
30 const std::shared_ptr<ModelAPI_Feature> & theFeature)
31 : SketchAPI_SketchEntity(theFeature)
36 SketchAPI_Rectangle::SketchAPI_Rectangle(
37 const std::shared_ptr<ModelAPI_Feature> & theFeature,
38 double theX1, double theY1, double theX2, double theY2)
39 : SketchAPI_SketchEntity(theFeature)
42 setByCoordinates(theX1, theY1, theX2, theY2);
46 SketchAPI_Rectangle::SketchAPI_Rectangle(
47 const std::shared_ptr<ModelAPI_Feature> & theFeature,
48 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
49 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
50 : SketchAPI_SketchEntity(theFeature)
53 setByPoints(theStartPoint, theEndPoint);
57 SketchAPI_Rectangle::~SketchAPI_Rectangle()
61 //--------------------------------------------------------------------------------------
62 void SketchAPI_Rectangle::setByCoordinates(
63 double theX1, double theY1, double theX2, double theY2)
65 fillAttribute(startPoint(), theX1, theY1);
66 fillAttribute(endPoint(), theX2, theY2);
71 void SketchAPI_Rectangle::setByPoints(
72 const std::shared_ptr<GeomAPI_Pnt2d> & theStartPoint,
73 const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
75 fillAttribute(theStartPoint, startPoint());
76 fillAttribute(theEndPoint, endPoint());
81 //--------------------------------------------------------------------------------------
83 std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_Rectangle::lines() const
85 std::list<FeaturePtr> aFeatures;
86 std::list<ObjectPtr> aList = linesList()->list();
87 std::list<ObjectPtr>::const_iterator anIt = aList.begin();
88 for (; anIt != aList.end(); ++anIt)
89 aFeatures.push_back(ModelAPI_Feature::feature(*anIt));
90 return SketchAPI_SketchEntity::wrap(aFeatures);
93 //==================================================================================================
94 void SketchAPI_Rectangle::dump(ModelHighAPI_Dumper& theDumper) const
97 FeaturePtr aBase = feature();
99 /// do not dump sub-features eg: lines and lines constraints
100 AttributeRefListPtr noToDumpList = aBase->reflist(SketchPlugin_Rectangle::NOT_TO_DUMP_LIST_ID());
101 for( int i = 0; i < noToDumpList->size(); i++){
102 theDumper.doNotDumpFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(noToDumpList->object(i)));
106 return; // no need to dump copied feature
108 const std::string& aSketchName = theDumper.parentName(aBase);
110 AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
111 if (anExternal->context()) {
112 // rectangle is external
113 theDumper << aBase << " = " << aSketchName << ".addRectangle(" << anExternal << ")" << std::endl;
115 // rectangle given by start and end points
116 theDumper << aBase << " = " << aSketchName << ".addRectangle("
117 << startPoint() << ", " << endPoint() << ")" << std::endl;
119 // dump "auxiliary" flag if necessary
120 SketchAPI_SketchEntity::dump(theDumper);