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