1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 // Name : SketchAPI_Projection.cpp
6 // 16/06/16 - Sergey POKHODENKO - Creation of the file
8 //--------------------------------------------------------------------------------------
9 #include "SketchAPI_Projection.h"
11 #include <SketchPlugin_Line.h>
12 #include <SketchPlugin_Circle.h>
14 #include <SketchAPI_Line.h>
15 #include <SketchAPI_Circle.h>
16 #include <SketchAPI_Arc.h>
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)
29 SketchAPI_Projection::SketchAPI_Projection(
30 const std::shared_ptr<ModelAPI_Feature> & theFeature,
31 const ModelHighAPI_Selection & theExternalFeature )
32 : SketchAPI_SketchEntity(theFeature)
35 setExternalFeature(theExternalFeature);
39 SketchAPI_Projection::SketchAPI_Projection(
40 const std::shared_ptr<ModelAPI_Feature> & theFeature,
41 const std::string & theExternalName)
42 : SketchAPI_SketchEntity(theFeature)
45 setByExternalName(theExternalName);
49 SketchAPI_Projection::~SketchAPI_Projection()
54 //--------------------------------------------------------------------------------------
55 void SketchAPI_Projection::setExternalFeature(const ModelHighAPI_Selection & theExternalFeature)
57 fillAttribute(theExternalFeature, externalFeature());
62 void SketchAPI_Projection::setByExternalName(const std::string& theExternalName)
64 fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
69 //--------------------------------------------------------------------------------------
70 std::shared_ptr<SketchAPI_SketchEntity> SketchAPI_Projection::createdFeature() const
72 AttributeRefAttrPtr aProjectedRefAttr = projectedFeature();
73 FeaturePtr aProjectedFeature = ModelAPI_Feature::feature(aProjectedRefAttr->object());
74 std::shared_ptr<SketchAPI_SketchEntity> anEntity;
76 if(!aProjectedFeature.get()) {
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));
89 //--------------------------------------------------------------------------------------
91 void SketchAPI_Projection::dump(ModelHighAPI_Dumper& theDumper) const
93 FeaturePtr aBase = feature();
94 const std::string& aSketchName = theDumper.parentName(aBase);
96 AttributeSelectionPtr anExternal = externalFeature();
97 theDumper << aBase << " = " << aSketchName << ".addProjection(" << anExternal << ")" << std::endl;
98 // dump "auxiliary" flag if necessary
99 SketchAPI_SketchEntity::dump(theDumper);
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;