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