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