Salome HOME
Merge branch 'occ/shaper2smesh'
[modules/shaper.git] / src / SketchAPI / SketchAPI_Projection.cpp
1 // Copyright (C) 2014-2019  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_Projection.h"
21
22 #include <SketchPlugin_Line.h>
23 #include <SketchPlugin_BSpline.h>
24 #include <SketchPlugin_BSplinePeriodic.h>
25 #include <SketchPlugin_Circle.h>
26 #include <SketchPlugin_Ellipse.h>
27 #include <SketchPlugin_EllipticArc.h>
28 #include <SketchPlugin_Point.h>
29
30 #include <SketchAPI_Arc.h>
31 #include <SketchAPI_BSpline.h>
32 #include <SketchAPI_Circle.h>
33 #include <SketchAPI_Ellipse.h>
34 #include <SketchAPI_EllipticArc.h>
35 #include <SketchAPI_Line.h>
36 #include <SketchAPI_Point.h>
37
38 #include <ModelHighAPI_Dumper.h>
39 #include <ModelHighAPI_Selection.h>
40 #include <ModelHighAPI_Tools.h>
41 //--------------------------------------------------------------------------------------
42 SketchAPI_Projection::SketchAPI_Projection(
43     const std::shared_ptr<ModelAPI_Feature> & theFeature)
44 : SketchAPI_SketchEntity(theFeature)
45 {
46   initialize();
47 }
48
49 SketchAPI_Projection::SketchAPI_Projection(
50     const std::shared_ptr<ModelAPI_Feature> & theFeature,
51     const ModelHighAPI_Selection & theExternalFeature )
52 : SketchAPI_SketchEntity(theFeature)
53 {
54   if (initialize()) {
55     setExternalFeature(theExternalFeature);
56   }
57 }
58
59 SketchAPI_Projection::SketchAPI_Projection(
60     const std::shared_ptr<ModelAPI_Feature> & theFeature,
61     const std::string & theExternalName)
62 : SketchAPI_SketchEntity(theFeature)
63 {
64   if (initialize()) {
65     setByExternalName(theExternalName);
66   }
67 }
68
69 SketchAPI_Projection::~SketchAPI_Projection()
70 {
71
72 }
73
74 //--------------------------------------------------------------------------------------
75 void SketchAPI_Projection::setExternalFeature(const ModelHighAPI_Selection & theExternalFeature)
76 {
77   fillAttribute(theExternalFeature, externalFeature());
78
79   execute(true);
80 }
81
82 void SketchAPI_Projection::setByExternalName(const std::string& theExternalName)
83 {
84   setExternalFeature(ModelHighAPI_Selection("EDGE", theExternalName));
85 }
86
87 void SketchAPI_Projection::setIncludeToResult(bool theKeepResult)
88 {
89   fillAttribute(theKeepResult, includeToResult());
90   execute(true);
91 }
92
93 //--------------------------------------------------------------------------------------
94 std::shared_ptr<SketchAPI_SketchEntity> SketchAPI_Projection::createdFeature() const
95 {
96   AttributeRefAttrPtr aProjectedRefAttr = projectedFeature();
97   FeaturePtr aProjectedFeature = ModelAPI_Feature::feature(aProjectedRefAttr->object());
98   std::shared_ptr<SketchAPI_SketchEntity> anEntity;
99
100   if(!aProjectedFeature.get()) {
101     return anEntity;
102   }
103
104   if (aProjectedFeature->getKind() == SketchPlugin_Line::ID())
105     anEntity.reset(new SketchAPI_Line(aProjectedFeature));
106   else if (aProjectedFeature->getKind() == SketchPlugin_Circle::ID())
107     anEntity.reset(new SketchAPI_Circle(aProjectedFeature));
108   else if (aProjectedFeature->getKind() == SketchPlugin_Arc::ID())
109     anEntity.reset(new SketchAPI_Arc(aProjectedFeature));
110   else if (aProjectedFeature->getKind() == SketchPlugin_Ellipse::ID())
111     anEntity.reset(new SketchAPI_Ellipse(aProjectedFeature));
112   else if (aProjectedFeature->getKind() == SketchPlugin_EllipticArc::ID())
113     anEntity.reset(new SketchAPI_EllipticArc(aProjectedFeature));
114   else if (aProjectedFeature->getKind() == SketchPlugin_BSpline::ID())
115     anEntity.reset(new SketchAPI_BSpline(aProjectedFeature));
116   else if (aProjectedFeature->getKind() == SketchPlugin_BSplinePeriodic::ID())
117     anEntity.reset(new SketchAPI_BSplinePeriodic(aProjectedFeature));
118   else if (aProjectedFeature->getKind() == SketchPlugin_Point::ID())
119     anEntity.reset(new SketchAPI_Point(aProjectedFeature));
120
121   return anEntity;
122 }
123
124 //--------------------------------------------------------------------------------------
125
126 void SketchAPI_Projection::dump(ModelHighAPI_Dumper& theDumper) const
127 {
128   FeaturePtr aBase = feature();
129   const std::string& aSketchName = theDumper.parentName(aBase);
130
131   AttributeSelectionPtr anExternal = externalFeature();
132   AttributeBooleanPtr isIncludeToRes = includeToResult();
133   theDumper << aBase << " = " << aSketchName << ".addProjection("
134             << anExternal << ", " << isIncludeToRes << ")" << std::endl;
135   // dump "auxiliary" flag if necessary
136   SketchAPI_SketchEntity::dump(theDumper);
137
138   // Dump created line feature
139   AttributeRefAttrPtr aProjectedRefAttr = projectedFeature();
140   FeaturePtr aProjectedFeature = ModelAPI_Feature::feature(aProjectedRefAttr->object());
141   theDumper << aProjectedFeature << " = "
142     << theDumper.name(aBase) << ".createdFeature()" << std::endl;
143 }