]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchAPI/SketchAPI_SketchEntity.cpp
Salome HOME
#18963 C++17 ready
[modules/shaper.git] / src / SketchAPI / SketchAPI_SketchEntity.cpp
1 // Copyright (C) 2014-2020  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
18 //
19
20 #include "SketchAPI_SketchEntity.h"
21 #include <SketchAPI_Arc.h>
22 #include <SketchAPI_BSpline.h>
23 #include <SketchAPI_Circle.h>
24 #include <SketchAPI_Ellipse.h>
25 #include <SketchAPI_EllipticArc.h>
26 #include <SketchAPI_IntersectionPoint.h>
27 #include <SketchAPI_Line.h>
28 #include <SketchAPI_Point.h>
29 //--------------------------------------------------------------------------------------
30 #include <ModelHighAPI_Dumper.h>
31 #include <ModelHighAPI_Tools.h>
32
33 #include <SketchPlugin_Arc.h>
34 #include <SketchPlugin_BSpline.h>
35 #include <SketchPlugin_Circle.h>
36 #include <SketchPlugin_Ellipse.h>
37 #include <SketchPlugin_IntersectionPoint.h>
38 #include <SketchPlugin_Line.h>
39 #include <SketchPlugin_Point.h>
40 //--------------------------------------------------------------------------------------
41 SketchAPI_SketchEntity::SketchAPI_SketchEntity(
42     const std::shared_ptr<ModelAPI_Feature> & theFeature)
43 : ModelHighAPI_Interface(theFeature)
44 {
45   initialize();
46 }
47
48 SketchAPI_SketchEntity::~SketchAPI_SketchEntity()
49 {
50
51 }
52
53 //--------------------------------------------------------------------------------------
54 bool SketchAPI_SketchEntity::initialize()
55 {
56   SET_ATTRIBUTE(Auxiliary, ModelAPI_AttributeBoolean, SketchPlugin_SketchEntity::AUXILIARY_ID())
57
58   return true;
59 }
60
61 //--------------------------------------------------------------------------------------
62 std::shared_ptr<ModelAPI_AttributeBoolean> SketchAPI_SketchEntity::auxiliary() const
63 {
64   return myAuxiliary;
65 }
66
67 void SketchAPI_SketchEntity::setAuxiliary(bool theAuxiliary)
68 {
69   fillAttribute(theAuxiliary, myAuxiliary);
70
71   execute();
72 }
73
74 //--------------------------------------------------------------------------------------
75 void SketchAPI_SketchEntity::dump(ModelHighAPI_Dumper& theDumper) const
76 {
77   FeaturePtr aBase = feature();
78   AttributeBooleanPtr anAux = aBase->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID());
79   if (anAux->value()) {
80     const std::string& aName = theDumper.name(aBase);
81     theDumper << aName << ".setAuxiliary(" << anAux << ")" <<std::endl;
82   }
83 }
84
85 bool SketchAPI_SketchEntity::isCopy() const
86 {
87   // check the feature is a copy of another entity
88   AttributeBooleanPtr isCopy = feature()->boolean(SketchPlugin_SketchEntity::COPY_ID());
89   AttributeReferencePtr hasParent = feature()->reference(SketchPlugin_SketchEntity::PARENT_ID());
90   return (isCopy.get() && isCopy->value()) || (hasParent && hasParent->value());
91 }
92
93 std::list<std::shared_ptr<SketchAPI_SketchEntity> >
94 SketchAPI_SketchEntity::wrap(const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures)
95 {
96   std::list<std::shared_ptr<SketchAPI_SketchEntity> > aResult;
97   std::list<std::shared_ptr<ModelAPI_Feature> >::const_iterator anIt = theFeatures.begin();
98   for (; anIt != theFeatures.end(); ++anIt) {
99     if ((*anIt)->getKind() == SketchPlugin_Line::ID())
100       aResult.push_back(std::shared_ptr<SketchAPI_SketchEntity>(new SketchAPI_Line(*anIt)));
101     else if ((*anIt)->getKind() == SketchPlugin_Arc::ID())
102       aResult.push_back(std::shared_ptr<SketchAPI_SketchEntity>(new SketchAPI_Arc(*anIt)));
103     else if ((*anIt)->getKind() == SketchPlugin_Circle::ID())
104       aResult.push_back(std::shared_ptr<SketchAPI_SketchEntity>(new SketchAPI_Circle(*anIt)));
105     else if ((*anIt)->getKind() == SketchPlugin_Ellipse::ID())
106       aResult.push_back(std::shared_ptr<SketchAPI_SketchEntity>(new SketchAPI_Ellipse(*anIt)));
107     else if ((*anIt)->getKind() == SketchPlugin_EllipticArc::ID())
108       aResult.push_back(std::shared_ptr<SketchAPI_SketchEntity>(new SketchAPI_EllipticArc(*anIt)));
109     else if ((*anIt)->getKind() == SketchPlugin_BSpline::ID())
110       aResult.push_back(std::shared_ptr<SketchAPI_SketchEntity>(new SketchAPI_BSpline(*anIt)));
111     else if ((*anIt)->getKind() == SketchPlugin_BSplinePeriodic::ID()) {
112       aResult.push_back(
113           std::shared_ptr<SketchAPI_SketchEntity>(new SketchAPI_BSplinePeriodic(*anIt)));
114     }
115     else if ((*anIt)->getKind() == SketchPlugin_Point::ID())
116       aResult.push_back(std::shared_ptr<SketchAPI_SketchEntity>(new SketchAPI_Point(*anIt)));
117     else if ((*anIt)->getKind() == SketchPlugin_IntersectionPoint::ID())
118       aResult.push_back(std::shared_ptr<SketchAPI_SketchEntity>(
119                                                     new SketchAPI_IntersectionPoint(*anIt)));
120   }
121   return aResult;
122 }