Salome HOME
da537be6ede1d3126a256708fafbd045f29eeb32
[modules/shaper.git] / src / SketchAPI / SketchAPI_IntersectionPoint.cpp
1 // Copyright (C) 2014-2021  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
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)
34 {
35   initialize();
36 }
37
38 SketchAPI_IntersectionPoint::SketchAPI_IntersectionPoint(
39     const std::shared_ptr<ModelAPI_Feature> & theFeature,
40     const ModelHighAPI_Selection & theExternal )
41 : SketchAPI_SketchEntity(theFeature)
42 {
43   if (initialize()) {
44     setByExternalEdge(theExternal);
45   }
46 }
47
48 SketchAPI_IntersectionPoint::SketchAPI_IntersectionPoint(
49     const std::shared_ptr<ModelAPI_Feature> & theFeature,
50     const std::wstring & theExternalName )
51 : SketchAPI_SketchEntity(theFeature)
52 {
53   if (initialize()) {
54     setByExternalEdgeName(theExternalName);
55   }
56 }
57
58 SketchAPI_IntersectionPoint::~SketchAPI_IntersectionPoint()
59 {
60
61 }
62
63 //--------------------------------------------------------------------------------------
64 void SketchAPI_IntersectionPoint::setByExternalEdge(const ModelHighAPI_Selection & theExternalLine)
65 {
66   fillAttribute(theExternalLine, externalFeature());
67
68   execute();
69 }
70
71 void SketchAPI_IntersectionPoint::setByExternalEdgeName(const std::wstring & theExternalLineName)
72 {
73   fillAttribute(ModelHighAPI_Selection("EDGE", theExternalLineName), externalFeature());
74
75   execute();
76 }
77
78 void SketchAPI_IntersectionPoint::setIncludeToResult(bool theKeepResult)
79 {
80   fillAttribute(theKeepResult, includeToResult());
81   execute(true);
82 }
83
84 //--------------------------------------------------------------------------------------
85
86 std::list<std::shared_ptr<SketchAPI_SketchEntity> >
87 SketchAPI_IntersectionPoint::intersectionPoints() const
88 {
89   std::list<std::shared_ptr<SketchAPI_SketchEntity> > anEntities;
90
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())
97     {
98       std::shared_ptr<SketchAPI_SketchEntity> anEnt(new SketchAPI_Point(aFeature));
99       anEntities.push_back(anEnt);
100     }
101   }
102
103   return anEntities;
104 }
105
106 //--------------------------------------------------------------------------------------
107
108 void SketchAPI_IntersectionPoint::dump(ModelHighAPI_Dumper& theDumper) const
109 {
110   FeaturePtr aBase = feature();
111   const std::string& aSketchName = theDumper.parentName(aBase);
112
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);
119
120   // Dump variables for a list of intersected points
121   theDumper << "[";
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())
126       theDumper << ", ";
127     theDumper << (*anIt)->feature();
128   }
129   theDumper << "] = " << theDumper.name(aBase) << ".intersectionPoints()" << std::endl;
130 }