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