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