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