624f732f |
1 | // Created on: 2016-11-10 |
2 | // Created by: Anton KOZULIN |
3 | // Copyright (c) 2016 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #include <BinMDataXtd_TriangulationDriver.hxx> |
17 | #include <BinObjMgt_Persistent.hxx> |
83ae3591 |
18 | #include <Message_Messenger.hxx> |
624f732f |
19 | #include <Standard_Type.hxx> |
20 | #include <TDataXtd_Triangulation.hxx> |
21 | #include <TDF_Attribute.hxx> |
22 | |
23 | IMPLEMENT_STANDARD_RTTIEXT(BinMDataXtd_TriangulationDriver,BinMDF_ADriver) |
24 | |
25 | //======================================================================= |
26 | //function : BinMDataXtd_TriangulationDriver |
27 | //purpose : Constructor |
28 | //======================================================================= |
83ae3591 |
29 | BinMDataXtd_TriangulationDriver::BinMDataXtd_TriangulationDriver(const Handle(Message_Messenger)& theMsgDriver) |
624f732f |
30 | : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataXtd_Triangulation)->Name()) |
31 | { |
32 | |
33 | } |
34 | |
35 | //======================================================================= |
36 | //function : NewEmpty |
37 | //purpose : |
38 | //======================================================================= |
39 | Handle(TDF_Attribute) BinMDataXtd_TriangulationDriver::NewEmpty() const |
40 | { |
41 | return new TDataXtd_Triangulation(); |
42 | } |
43 | |
44 | //======================================================================= |
45 | //function : Paste |
46 | //purpose : persistent -> transient (retrieve) |
47 | //======================================================================= |
48 | Standard_Boolean BinMDataXtd_TriangulationDriver::Paste(const BinObjMgt_Persistent& theSource, |
49 | const Handle(TDF_Attribute)& theTarget, |
50 | BinObjMgt_RRelocationTable& ) const |
51 | { |
52 | Handle(TDataXtd_Triangulation) attrubute = Handle(TDataXtd_Triangulation)::DownCast(theTarget); |
53 | |
54 | Standard_Integer i; |
55 | Standard_Real deflection, x, y, z; |
56 | Standard_Integer n1, n2, n3; |
57 | Standard_Integer nbNodes(0), nbTriangles(0); |
58 | Standard_Boolean hasUV(Standard_False); |
59 | gp_Pnt p; |
60 | |
61 | theSource >> nbNodes; |
62 | theSource >> nbTriangles; |
63 | theSource >> hasUV; |
64 | theSource >> deflection; |
65 | |
66 | // allocate the mesh |
67 | Handle(Poly_Triangulation) PT = new Poly_Triangulation(nbNodes, nbTriangles, hasUV); |
68 | |
69 | // deflection |
70 | PT->Deflection(deflection); |
71 | |
72 | // read nodes |
73 | for (i = 1; i <= nbNodes; i++) |
74 | { |
75 | theSource >> x; |
76 | theSource >> y; |
77 | theSource >> z; |
78 | PT->ChangeNode(i).SetCoord(x, y, z); |
79 | } |
80 | |
81 | // read 2d nodes |
82 | if (hasUV) |
83 | { |
84 | for (i = 1; i <= nbNodes; i++) |
85 | { |
86 | theSource >> x; |
87 | theSource >> y; |
88 | PT->ChangeUVNode(i).SetCoord(x,y); |
89 | } |
90 | } |
91 | |
92 | // read triangles |
93 | for (i = 1; i <= nbTriangles; i++) |
94 | { |
95 | theSource >> n1; |
96 | theSource >> n2; |
97 | theSource >> n3; |
98 | PT->ChangeTriangle(i).Set(n1, n2, n3); |
99 | } |
100 | |
101 | // set triangulation to Ocaf attribute |
102 | attrubute->Set(PT); |
103 | return !PT.IsNull(); |
104 | } |
105 | |
106 | //======================================================================= |
107 | //function : Paste |
108 | //purpose : transient -> persistent (store) |
109 | //======================================================================= |
110 | void BinMDataXtd_TriangulationDriver::Paste(const Handle(TDF_Attribute)& theSource, |
111 | BinObjMgt_Persistent& theTarget, |
112 | BinObjMgt_SRelocationTable& ) const |
113 | { |
114 | const Handle(TDataXtd_Triangulation) attribute = Handle(TDataXtd_Triangulation)::DownCast(theSource); |
115 | const Handle(Poly_Triangulation)& PT = attribute->Get(); |
116 | if (!PT.IsNull()) |
117 | { |
118 | Standard_Integer nbNodes = PT->NbNodes(); |
119 | Standard_Integer nbTriangles = PT->NbTriangles(); |
120 | Standard_Integer n1, n2, n3; |
121 | |
122 | // write number of elements |
123 | theTarget << nbNodes; |
124 | theTarget << nbTriangles; |
125 | theTarget << (PT->HasUVNodes() ? 1 : 0); |
126 | // write the deflection |
127 | theTarget << PT->Deflection(); |
128 | |
129 | // write 3d nodes |
130 | Standard_Integer i; |
131 | for (i = 1; i <= nbNodes; i++) |
132 | { |
133 | theTarget << PT->Node(i).X(); |
134 | theTarget << PT->Node(i).Y(); |
135 | theTarget << PT->Node(i).Z(); |
136 | } |
137 | |
138 | // write 2d nodes |
139 | if (PT->HasUVNodes()) |
140 | { |
141 | for (i = 1; i <= nbNodes; i++) |
142 | { |
143 | theTarget << PT->UVNode(i).X(); |
144 | theTarget << PT->UVNode(i).Y(); |
145 | } |
146 | } |
147 | |
148 | // Write triangles |
149 | const Poly_Array1OfTriangle& Triangles = PT->Triangles(); |
06bc0a59 |
150 | for (i = 1; i <= nbTriangles; i++) |
624f732f |
151 | { |
152 | Triangles(i).Get(n1, n2, n3); |
153 | theTarget << n1; |
154 | theTarget << n2; |
155 | theTarget << n3; |
156 | } |
157 | } |
158 | } |