Salome HOME
Receive DoF from the solver. Update test cases to check DoF.
[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(true);
60 }
61
62 void SketchAPI_Projection::setByExternalName(const std::string& theExternalName)
63 {
64   fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
65
66   execute(true);
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   std::shared_ptr<SketchAPI_SketchEntity> anEntity;
75
76   if(!aProjectedFeature.get()) {
77     return anEntity;
78   }
79
80   aProjectedFeature->getKind() == SketchPlugin_Line::ID() ?
81     anEntity.reset(new SketchAPI_Line(aProjectedFeature)) :
82     aProjectedFeature->getKind() == SketchPlugin_Circle::ID() ?
83       anEntity.reset(new SketchAPI_Circle(aProjectedFeature)) :
84       anEntity.reset(new SketchAPI_Arc(aProjectedFeature));
85
86   return anEntity;
87 }
88
89 //--------------------------------------------------------------------------------------
90
91 void SketchAPI_Projection::dump(ModelHighAPI_Dumper& theDumper) const
92 {
93   FeaturePtr aBase = feature();
94   const std::string& aSketchName = theDumper.parentName(aBase);
95
96   AttributeSelectionPtr anExternal = externalFeature();
97   theDumper << aBase << " = " << aSketchName << ".addProjection(" << anExternal << ")" << std::endl;
98   // dump "auxiliary" flag if necessary
99   SketchAPI_SketchEntity::dump(theDumper);
100
101   // Dump created line feature
102   AttributeRefAttrPtr aProjectedRefAttr = projectedFeature();
103   FeaturePtr aProjectedFeature = ModelAPI_Feature::feature(aProjectedRefAttr->object());
104   theDumper << aProjectedFeature << " = "
105     << theDumper.name(aBase) << ".createdFeature()" << std::endl;
106 }