1 // Created on: 2016-11-10
2 // Created by: Anton KOZULIN
3 // Copyright (c) 2016 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <BinMDataXtd_TriangulationDriver.hxx>
17 #include <BinObjMgt_Persistent.hxx>
18 #include <Message_Messenger.hxx>
19 #include <Standard_Type.hxx>
20 #include <TDataXtd_Triangulation.hxx>
21 #include <TDF_Attribute.hxx>
23 IMPLEMENT_STANDARD_RTTIEXT(BinMDataXtd_TriangulationDriver,BinMDF_ADriver)
25 //=======================================================================
26 //function : BinMDataXtd_TriangulationDriver
27 //purpose : Constructor
28 //=======================================================================
29 BinMDataXtd_TriangulationDriver::BinMDataXtd_TriangulationDriver(const Handle(Message_Messenger)& theMsgDriver)
30 : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataXtd_Triangulation)->Name())
35 //=======================================================================
38 //=======================================================================
39 Handle(TDF_Attribute) BinMDataXtd_TriangulationDriver::NewEmpty() const
41 return new TDataXtd_Triangulation();
44 //=======================================================================
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
52 Handle(TDataXtd_Triangulation) attrubute = Handle(TDataXtd_Triangulation)::DownCast(theTarget);
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);
62 theSource >> nbTriangles;
64 theSource >> deflection;
66 if (!nbNodes || !nbTriangles)
68 return Standard_False;
72 Handle(Poly_Triangulation) PT = new Poly_Triangulation(nbNodes, nbTriangles, hasUV);
75 PT->Deflection(deflection);
78 for (i = 1; i <= nbNodes; i++)
83 PT->ChangeNode(i).SetCoord(x, y, z);
89 for (i = 1; i <= nbNodes; i++)
93 PT->ChangeUVNode(i).SetCoord(x,y);
98 for (i = 1; i <= nbTriangles; i++)
103 PT->ChangeTriangle(i).Set(n1, n2, n3);
106 // set triangulation to Ocaf attribute
111 //=======================================================================
113 //purpose : transient -> persistent (store)
114 //=======================================================================
115 void BinMDataXtd_TriangulationDriver::Paste(const Handle(TDF_Attribute)& theSource,
116 BinObjMgt_Persistent& theTarget,
117 BinObjMgt_SRelocationTable& ) const
119 const Handle(TDataXtd_Triangulation) attribute = Handle(TDataXtd_Triangulation)::DownCast(theSource);
120 const Handle(Poly_Triangulation)& PT = attribute->Get();
123 Standard_Integer nbNodes = PT->NbNodes();
124 Standard_Integer nbTriangles = PT->NbTriangles();
125 Standard_Integer n1, n2, n3;
127 // write number of elements
128 theTarget << nbNodes;
129 theTarget << nbTriangles;
130 theTarget << (PT->HasUVNodes() ? 1 : 0);
131 // write the deflection
132 theTarget << PT->Deflection();
136 for (i = 1; i <= nbNodes; i++)
138 theTarget << PT->Node(i).X();
139 theTarget << PT->Node(i).Y();
140 theTarget << PT->Node(i).Z();
144 if (PT->HasUVNodes())
146 for (i = 1; i <= nbNodes; i++)
148 theTarget << PT->UVNode(i).X();
149 theTarget << PT->UVNode(i).Y();
154 const Poly_Array1OfTriangle& Triangles = PT->Triangles();
155 for (i = 1; i <= nbTriangles; i++)
157 Triangles(i).Get(n1, n2, n3);