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