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_IntersectionPoint.h"
21 #include "SketchAPI_Point.h"
22 //--------------------------------------------------------------------------------------
23 #include <SketchPlugin_Point.h>
24 //--------------------------------------------------------------------------------------
25 #include <GeomAPI_Pnt2d.h>
26 //--------------------------------------------------------------------------------------
27 #include <ModelHighAPI_Dumper.h>
28 #include <ModelHighAPI_Selection.h>
29 #include <ModelHighAPI_Tools.h>
30 //--------------------------------------------------------------------------------------
31 SketchAPI_IntersectionPoint::SketchAPI_IntersectionPoint(
32 const std::shared_ptr<ModelAPI_Feature> & theFeature)
33 : SketchAPI_SketchEntity(theFeature)
38 SketchAPI_IntersectionPoint::SketchAPI_IntersectionPoint(
39 const std::shared_ptr<ModelAPI_Feature> & theFeature,
40 const ModelHighAPI_Selection & theExternal )
41 : SketchAPI_SketchEntity(theFeature)
44 setByExternalEdge(theExternal);
48 SketchAPI_IntersectionPoint::SketchAPI_IntersectionPoint(
49 const std::shared_ptr<ModelAPI_Feature> & theFeature,
50 const std::wstring & theExternalName )
51 : SketchAPI_SketchEntity(theFeature)
54 setByExternalEdgeName(theExternalName);
58 SketchAPI_IntersectionPoint::~SketchAPI_IntersectionPoint()
63 //--------------------------------------------------------------------------------------
64 void SketchAPI_IntersectionPoint::setByExternalEdge(const ModelHighAPI_Selection & theExternalLine)
66 fillAttribute(theExternalLine, externalFeature());
71 void SketchAPI_IntersectionPoint::setByExternalEdgeName(const std::wstring & theExternalLineName)
73 fillAttribute(ModelHighAPI_Selection("EDGE", theExternalLineName), externalFeature());
78 void SketchAPI_IntersectionPoint::setIncludeToResult(bool theKeepResult)
80 fillAttribute(theKeepResult, includeToResult());
84 //--------------------------------------------------------------------------------------
86 std::list<std::shared_ptr<SketchAPI_SketchEntity> >
87 SketchAPI_IntersectionPoint::intersectionPoints() const
89 std::list<std::shared_ptr<SketchAPI_SketchEntity> > anEntities;
91 std::list<ObjectPtr> anIntersections =
92 feature()->reflist(SketchPlugin_IntersectionPoint::INTERSECTION_POINTS_ID())->list();
93 for (std::list<ObjectPtr>::iterator anIt = anIntersections.begin();
94 anIt != anIntersections.end(); ++anIt) {
95 FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
96 if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
98 std::shared_ptr<SketchAPI_SketchEntity> anEnt(new SketchAPI_Point(aFeature));
99 anEntities.push_back(anEnt);
106 //--------------------------------------------------------------------------------------
108 void SketchAPI_IntersectionPoint::dump(ModelHighAPI_Dumper& theDumper) const
110 FeaturePtr aBase = feature();
111 const std::string& aSketchName = theDumper.parentName(aBase);
113 AttributeSelectionPtr anExternal = externalFeature();
114 AttributeBooleanPtr isIncludeToRes = includeToResult();
115 theDumper << aBase << " = " << aSketchName << ".addIntersectionPoint("
116 << anExternal << ", " << isIncludeToRes << ")" << std::endl;
117 // dump "auxiliary" flag if necessary
118 SketchAPI_SketchEntity::dump(theDumper);
120 // Dump variables for a list of intersected points
122 std::list<std::shared_ptr<SketchAPI_SketchEntity> > aList = intersectionPoints();
123 std::list<std::shared_ptr<SketchAPI_SketchEntity> >::const_iterator anIt = aList.begin();
124 for (; anIt != aList.end(); ++anIt) {
125 if (anIt != aList.begin())
127 theDumper << (*anIt)->feature();
129 theDumper << "] = " << theDumper.name(aBase) << ".intersectionPoints()" << std::endl;