Salome HOME
Fix for projection dump.
[modules/shaper.git] / src / SketchAPI / SketchAPI_Projection.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 // Name   : SketchAPI_Projection.cpp
3 // Purpose:
4 //
5 // History:
6 // 16/06/16 - Sergey POKHODENKO - Creation of the file
7
8 //--------------------------------------------------------------------------------------
9 #include "SketchAPI_Projection.h"
10
11 #include <SketchPlugin_Line.h>
12 #include <SketchPlugin_Circle.h>
13
14 #include <SketchAPI_Line.h>
15 #include <SketchAPI_Circle.h>
16 #include <SketchAPI_Arc.h>
17
18 #include <ModelHighAPI_Dumper.h>
19 #include <ModelHighAPI_Selection.h>
20 #include <ModelHighAPI_Tools.h>
21 //--------------------------------------------------------------------------------------
22 SketchAPI_Projection::SketchAPI_Projection(
23     const std::shared_ptr<ModelAPI_Feature> & theFeature)
24 : SketchAPI_SketchEntity(theFeature)
25 {
26   initialize();
27 }
28
29 SketchAPI_Projection::SketchAPI_Projection(
30     const std::shared_ptr<ModelAPI_Feature> & theFeature,
31     const ModelHighAPI_Selection & theExternalFeature )
32 : SketchAPI_SketchEntity(theFeature)
33 {
34   if (initialize()) {
35     setExternalFeature(theExternalFeature);
36   }
37 }
38
39 SketchAPI_Projection::SketchAPI_Projection(
40     const std::shared_ptr<ModelAPI_Feature> & theFeature,
41     const std::string & theExternalName)
42 : SketchAPI_SketchEntity(theFeature)
43 {
44   if (initialize()) {
45     setByExternalName(theExternalName);
46   }
47 }
48
49 SketchAPI_Projection::~SketchAPI_Projection()
50 {
51
52 }
53
54 //--------------------------------------------------------------------------------------
55 void SketchAPI_Projection::setExternalFeature(const ModelHighAPI_Selection & theExternalFeature)
56 {
57   fillAttribute(theExternalFeature, externalFeature());
58
59   execute();
60 }
61
62 void SketchAPI_Projection::setByExternalName(const std::string& theExternalName)
63 {
64   fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
65
66   execute();
67 }
68
69 //--------------------------------------------------------------------------------------
70 std::shared_ptr<SketchAPI_SketchEntity> SketchAPI_Projection::createdFeature() const
71 {
72   AttributeRefAttrPtr aProjectedRefAttr = projectedFeature();
73   FeaturePtr aProjectedFeature = ModelAPI_Feature::feature(aProjectedRefAttr->object());
74
75   std::shared_ptr<SketchAPI_SketchEntity> anEntity;
76   aProjectedFeature->getKind() == SketchPlugin_Line::ID() ?
77     anEntity.reset(new SketchAPI_Line(aProjectedFeature)) :
78     aProjectedFeature->getKind() == SketchPlugin_Circle::ID() ?
79       anEntity.reset(new SketchAPI_Circle(aProjectedFeature)) :
80       anEntity.reset(new SketchAPI_Arc(aProjectedFeature));
81
82   return anEntity;
83 }
84
85 //--------------------------------------------------------------------------------------
86
87 void SketchAPI_Projection::dump(ModelHighAPI_Dumper& theDumper) const
88 {
89   FeaturePtr aBase = feature();
90   const std::string& aSketchName = theDumper.parentName(aBase);
91
92   AttributeSelectionPtr anExternal = externalFeature();
93   theDumper << aBase << " = " << aSketchName << ".addProjection(" << anExternal << ")" << std::endl;
94   // dump "auxiliary" flag if necessary
95   SketchAPI_SketchEntity::dump(theDumper);
96
97   // Dump created line feature
98   AttributeRefAttrPtr aProjectedRefAttr = projectedFeature();
99   FeaturePtr aProjectedFeature = ModelAPI_Feature::feature(aProjectedRefAttr->object());
100   std::string aProjectedName = theDumper.name(aProjectedFeature, false);
101   theDumper << aProjectedName << " = " << theDumper.name(aBase) << ".createdFeature()" << std::endl;
102 }