1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "SketchAPI_Projection.h"
22 #include <SketchPlugin_Line.h>
23 #include <SketchPlugin_Circle.h>
25 #include <SketchAPI_Line.h>
26 #include <SketchAPI_Circle.h>
27 #include <SketchAPI_Arc.h>
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)
40 SketchAPI_Projection::SketchAPI_Projection(
41 const std::shared_ptr<ModelAPI_Feature> & theFeature,
42 const ModelHighAPI_Selection & theExternalFeature )
43 : SketchAPI_SketchEntity(theFeature)
46 setExternalFeature(theExternalFeature);
50 SketchAPI_Projection::SketchAPI_Projection(
51 const std::shared_ptr<ModelAPI_Feature> & theFeature,
52 const std::string & theExternalName)
53 : SketchAPI_SketchEntity(theFeature)
56 setByExternalName(theExternalName);
60 SketchAPI_Projection::~SketchAPI_Projection()
65 //--------------------------------------------------------------------------------------
66 void SketchAPI_Projection::setExternalFeature(const ModelHighAPI_Selection & theExternalFeature)
68 fillAttribute(theExternalFeature, externalFeature());
73 void SketchAPI_Projection::setByExternalName(const std::string& theExternalName)
75 fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
80 //--------------------------------------------------------------------------------------
81 std::shared_ptr<SketchAPI_SketchEntity> SketchAPI_Projection::createdFeature() const
83 AttributeRefAttrPtr aProjectedRefAttr = projectedFeature();
84 FeaturePtr aProjectedFeature = ModelAPI_Feature::feature(aProjectedRefAttr->object());
85 std::shared_ptr<SketchAPI_SketchEntity> anEntity;
87 if(!aProjectedFeature.get()) {
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));
100 //--------------------------------------------------------------------------------------
102 void SketchAPI_Projection::dump(ModelHighAPI_Dumper& theDumper) const
104 FeaturePtr aBase = feature();
105 const std::string& aSketchName = theDumper.parentName(aBase);
107 AttributeSelectionPtr anExternal = externalFeature();
108 theDumper << aBase << " = " << aSketchName << ".addProjection(" << anExternal << ")" << std::endl;
109 // dump "auxiliary" flag if necessary
110 SketchAPI_SketchEntity::dump(theDumper);
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;