1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "SketchAPI_IntersectionPoint.h"
22 #include "SketchAPI_Point.h"
23 //--------------------------------------------------------------------------------------
24 #include <SketchPlugin_Point.h>
25 //--------------------------------------------------------------------------------------
26 #include <GeomAPI_Pnt2d.h>
27 //--------------------------------------------------------------------------------------
28 #include <ModelHighAPI_Dumper.h>
29 #include <ModelHighAPI_Selection.h>
30 #include <ModelHighAPI_Tools.h>
31 //--------------------------------------------------------------------------------------
32 SketchAPI_IntersectionPoint::SketchAPI_IntersectionPoint(
33 const std::shared_ptr<ModelAPI_Feature> & theFeature)
34 : SketchAPI_SketchEntity(theFeature)
39 SketchAPI_IntersectionPoint::SketchAPI_IntersectionPoint(
40 const std::shared_ptr<ModelAPI_Feature> & theFeature,
41 const ModelHighAPI_Selection & theExternal )
42 : SketchAPI_SketchEntity(theFeature)
45 setByExternalEdge(theExternal);
49 SketchAPI_IntersectionPoint::SketchAPI_IntersectionPoint(
50 const std::shared_ptr<ModelAPI_Feature> & theFeature,
51 const std::string & theExternalName )
52 : SketchAPI_SketchEntity(theFeature)
55 setByExternalEdgeName(theExternalName);
59 SketchAPI_IntersectionPoint::~SketchAPI_IntersectionPoint()
64 //--------------------------------------------------------------------------------------
65 void SketchAPI_IntersectionPoint::setByExternalEdge(const ModelHighAPI_Selection & theExternalLine)
67 fillAttribute(theExternalLine, externalFeature());
72 void SketchAPI_IntersectionPoint::setByExternalEdgeName(const std::string & theExternalLineName)
74 fillAttribute(ModelHighAPI_Selection("EDGE", theExternalLineName), externalFeature());
79 void SketchAPI_IntersectionPoint::setIncludeToResult(bool theKeepResult)
81 fillAttribute(theKeepResult, includeToResult());
85 //--------------------------------------------------------------------------------------
87 std::list<std::shared_ptr<SketchAPI_SketchEntity> >
88 SketchAPI_IntersectionPoint::intersectionPoints() const
90 std::list<std::shared_ptr<SketchAPI_SketchEntity> > anEntities;
92 std::list<ObjectPtr> anIntersections =
93 feature()->reflist(SketchPlugin_IntersectionPoint::INTERSECTION_POINTS_ID())->list();
94 for (std::list<ObjectPtr>::iterator anIt = anIntersections.begin();
95 anIt != anIntersections.end(); ++anIt) {
96 FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
97 if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
99 std::shared_ptr<SketchAPI_SketchEntity> anEnt(new SketchAPI_Point(aFeature));
100 anEntities.push_back(anEnt);
107 //--------------------------------------------------------------------------------------
109 void SketchAPI_IntersectionPoint::dump(ModelHighAPI_Dumper& theDumper) const
111 FeaturePtr aBase = feature();
112 const std::string& aSketchName = theDumper.parentName(aBase);
114 AttributeSelectionPtr anExternal = externalFeature();
115 AttributeBooleanPtr isIncludeToRes = includeToResult();
116 theDumper << aBase << " = " << aSketchName << ".addIntersectionPoint("
117 << anExternal << ", " << isIncludeToRes << ")" << std::endl;
118 // dump "auxiliary" flag if necessary
119 SketchAPI_SketchEntity::dump(theDumper);
121 // Dump variables for a list of intersected points
123 std::list<std::shared_ptr<SketchAPI_SketchEntity> > aList = intersectionPoints();
124 std::list<std::shared_ptr<SketchAPI_SketchEntity> >::const_iterator anIt = aList.begin();
125 for (; anIt != aList.end(); ++anIt) {
126 if (anIt != aList.begin())
128 theDumper << (*anIt)->feature();
130 theDumper << "] = " << theDumper.name(aBase) << ".intersectionPoints()" << std::endl;