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