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