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