0030675: Visualization - remove redundant proxy classes in hierarchy of PrsMgr_Presen...
[occt.git] / src / ShapePersistent / ShapePersistent_Geom2d.cxx
1 // Copyright (c) 2017 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #include <Standard_NullObject.hxx>
15
16 #include <ShapePersistent_Geom2d.hxx>
17 #include <ShapePersistent_Geom2d_Curve.hxx>
18
19 #include <Geom2d_BezierCurve.hxx>
20 #include <Geom2d_BSplineCurve.hxx>
21 #include <Geom2d_TrimmedCurve.hxx>
22 #include <Geom2d_OffsetCurve.hxx>
23
24 //=======================================================================
25 // Direction
26 //=======================================================================
27 template<>
28 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom2d::Direction,
29                                                   Geom2d_Direction,
30                                                   gp_Dir2d>
31   ::PName() const { return "PGeom2d_Direction"; }
32
33 template<>
34 void ShapePersistent_Geom::instance<ShapePersistent_Geom2d::Direction,
35                                     Geom2d_Direction,
36                                     gp_Dir2d>
37 ::Write(StdObjMgt_WriteData& theWriteData) const
38 {
39   Handle(Geom2d_Direction) aMyGeom =
40     Handle(Geom2d_Direction)::DownCast(myTransient);
41   theWriteData << aMyGeom->Dir2d();
42 }
43
44 //=======================================================================
45 // VectorWithMagnitude
46 //=======================================================================
47 template<>
48 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom2d::VectorWithMagnitude,
49                                                   Geom2d_VectorWithMagnitude,
50                                                   gp_Vec2d>
51   ::PName() const { return "PGeom2d_VectorWithMagnitude"; }
52
53 template<>
54 void ShapePersistent_Geom::instance<ShapePersistent_Geom2d::VectorWithMagnitude,
55                                       Geom2d_VectorWithMagnitude,
56                                       gp_Vec2d>
57 ::Write(StdObjMgt_WriteData& theWriteData) const
58 {
59   Handle(Geom2d_VectorWithMagnitude) aMyGeom =
60     Handle(Geom2d_VectorWithMagnitude)::DownCast(myTransient);
61   theWriteData << aMyGeom->Vec2d();
62 }
63
64 //=======================================================================
65 // AxisPlacement
66 //=======================================================================
67 template<>
68 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom2d::AxisPlacement,
69                                                   Geom2d_AxisPlacement,
70                                                   gp_Ax2d>
71   ::PName() const { return "PGeom2d_AxisPlacement"; }
72
73 template<>
74 void ShapePersistent_Geom::instance<ShapePersistent_Geom2d::AxisPlacement,
75                                       Geom2d_AxisPlacement,
76                                       gp_Ax2d>
77 ::Write(StdObjMgt_WriteData& theWriteData) const
78 {
79   Handle(Geom2d_AxisPlacement) aMyGeom =
80     Handle(Geom2d_AxisPlacement)::DownCast(myTransient);
81   write(theWriteData, aMyGeom->Ax2d());
82 }
83
84 //=======================================================================
85 // Transformation
86 //=======================================================================
87 template<>
88 Standard_CString ShapePersistent_Geom::instance<ShapePersistent_Geom2d::Transformation,
89                                                   Geom2d_Transformation,
90                                                   gp_Trsf2d>
91   ::PName() const { return "PGeom2d_Transformation"; }
92
93 template<>
94 void ShapePersistent_Geom::instance<ShapePersistent_Geom2d::Transformation,
95                                     Geom2d_Transformation,
96                                     gp_Trsf2d>
97   ::PChildren(StdObjMgt_Persistent::SequenceOfPersistent&) const
98 {
99 }
100
101 template<>
102 void ShapePersistent_Geom2d::instance<ShapePersistent_Geom2d::Transformation,
103                                       Geom2d_Transformation,
104                                       gp_Trsf2d>
105 ::Write(StdObjMgt_WriteData& theWriteData) const
106 {
107   theWriteData << myTransient->Trsf2d();
108 }
109
110 //=======================================================================
111 // Curve
112 //=======================================================================
113
114 Handle(ShapePersistent_Geom2d::Curve)
115 ShapePersistent_Geom2d::Translate(const Handle(Geom2d_Curve)& theCurve,
116                                   StdObjMgt_TransientPersistentMap& theMap)
117 {
118   Handle(ShapePersistent_Geom2d::Curve) aPC;
119   if (!theCurve.IsNull())
120   {
121     if (theMap.IsBound(theCurve))
122       aPC = Handle(ShapePersistent_Geom2d::Curve)::DownCast(theMap.Find(theCurve));
123     else
124     {
125       Handle(Standard_Type) aCT = theCurve->DynamicType();
126       if (aCT == STANDARD_TYPE(Geom2d_Line)) {
127         aPC = ShapePersistent_Geom2d_Curve::Translate(Handle(Geom2d_Line)::DownCast(theCurve), theMap);
128       }
129       else if (aCT == STANDARD_TYPE(Geom2d_Circle)) {
130         aPC = ShapePersistent_Geom2d_Curve::Translate(Handle(Geom2d_Circle)::DownCast(theCurve), theMap);
131       }
132       else if (aCT == STANDARD_TYPE(Geom2d_Ellipse)) {
133         aPC = ShapePersistent_Geom2d_Curve::Translate(Handle(Geom2d_Ellipse)::DownCast(theCurve), theMap);
134       }
135       else if (aCT == STANDARD_TYPE(Geom2d_Hyperbola)) {
136         aPC = ShapePersistent_Geom2d_Curve::Translate(Handle(Geom2d_Hyperbola)::DownCast(theCurve), theMap);
137       }
138       else if (aCT == STANDARD_TYPE(Geom2d_Parabola)) {
139         aPC = ShapePersistent_Geom2d_Curve::Translate(Handle(Geom2d_Parabola)::DownCast(theCurve), theMap);
140       }
141       else if (aCT == STANDARD_TYPE(Geom2d_BezierCurve)) {
142         aPC = ShapePersistent_Geom2d_Curve::Translate(Handle(Geom2d_BezierCurve)::DownCast(theCurve), theMap);
143       }
144       else if (aCT == STANDARD_TYPE(Geom2d_BSplineCurve)) {
145         aPC = ShapePersistent_Geom2d_Curve::Translate(Handle(Geom2d_BSplineCurve)::DownCast(theCurve), theMap);
146       }
147       else if (aCT == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
148         aPC = ShapePersistent_Geom2d_Curve::Translate(Handle(Geom2d_TrimmedCurve)::DownCast(theCurve), theMap);
149       }
150       else if (aCT == STANDARD_TYPE(Geom2d_OffsetCurve)) {
151         aPC = ShapePersistent_Geom2d_Curve::Translate(Handle(Geom2d_OffsetCurve)::DownCast(theCurve), theMap);
152       }
153       else {
154         Standard_NullObject::Raise("No mapping for the current Transient Curve");
155       }
156       theMap.Bind(theCurve, aPC);
157     }
158   }
159   return aPC;
160 }