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 <CDM_MessageDriver.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(CDM_MessageDriver)& 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;
67 Handle(Poly_Triangulation) PT = new Poly_Triangulation(nbNodes, nbTriangles, hasUV);
70 PT->Deflection(deflection);
73 for (i = 1; i <= nbNodes; i++)
78 PT->ChangeNode(i).SetCoord(x, y, z);
84 for (i = 1; i <= nbNodes; i++)
88 PT->ChangeUVNode(i).SetCoord(x,y);
93 for (i = 1; i <= nbTriangles; i++)
98 PT->ChangeTriangle(i).Set(n1, n2, n3);
101 // set triangulation to Ocaf attribute
106 //=======================================================================
108 //purpose : transient -> persistent (store)
109 //=======================================================================
110 void BinMDataXtd_TriangulationDriver::Paste(const Handle(TDF_Attribute)& theSource,
111 BinObjMgt_Persistent& theTarget,
112 BinObjMgt_SRelocationTable& ) const
114 const Handle(TDataXtd_Triangulation) attribute = Handle(TDataXtd_Triangulation)::DownCast(theSource);
115 const Handle(Poly_Triangulation)& PT = attribute->Get();
118 Standard_Integer nbNodes = PT->NbNodes();
119 Standard_Integer nbTriangles = PT->NbTriangles();
120 Standard_Integer n1, n2, n3;
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();
131 for (i = 1; i <= nbNodes; i++)
133 theTarget << PT->Node(i).X();
134 theTarget << PT->Node(i).Y();
135 theTarget << PT->Node(i).Z();
139 if (PT->HasUVNodes())
141 for (i = 1; i <= nbNodes; i++)
143 theTarget << PT->UVNode(i).X();
144 theTarget << PT->UVNode(i).Y();
149 const Poly_Array1OfTriangle& Triangles = PT->Triangles();
150 for (i = 1; i <= nbTriangles; i++)
152 Triangles(i).Get(n1, n2, n3);