0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / BinTObjDrivers / BinTObjDrivers_IntSparseArrayDriver.cxx
CommitLineData
b311480e 1// Created on: 2007-03-30
2// Created by: Michael SAZONOV
973c2be1 3// Copyright (c) 2007-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
7fd59977 16// The original implementation Copyright: (C) RINA S.p.A
17
18#include <BinTObjDrivers_IntSparseArrayDriver.hxx>
83ae3591 19#include <Message_Messenger.hxx>
7fd59977 20#include <TDF_Attribute.hxx>
21#include <BinObjMgt_Persistent.hxx>
22#include <TObj_TIntSparseArray.hxx>
7fd59977 23#include <TDF_Tool.hxx>
24
7fd59977 25
92efcf78 26IMPLEMENT_STANDARD_RTTIEXT(BinTObjDrivers_IntSparseArrayDriver,BinMDF_ADriver)
27
7fd59977 28//=======================================================================
29//function : BinTObjDrivers_IntSparseArrayDriver
30//purpose : constructor
31//=======================================================================
32
33BinTObjDrivers_IntSparseArrayDriver::BinTObjDrivers_IntSparseArrayDriver
83ae3591 34 (const Handle(Message_Messenger)& theMessageDriver)
7fd59977 35: BinMDF_ADriver( theMessageDriver, NULL)
36{
37}
38
39//=======================================================================
40//function : NewEmpty
41//purpose : Creates a new attribute
42//=======================================================================
43
44Handle(TDF_Attribute) BinTObjDrivers_IntSparseArrayDriver::NewEmpty() const
45{
46 return new TObj_TIntSparseArray;
47}
48
49//=======================================================================
50//function : Paste
51//purpose : Retrieve. Translate the contents of <theSource> and put it
52// into <theTarget>.
53//=======================================================================
54
55Standard_Boolean BinTObjDrivers_IntSparseArrayDriver::Paste
56 (const BinObjMgt_Persistent& theSource,
57 const Handle(TDF_Attribute)& theTarget,
58 BinObjMgt_RRelocationTable&) const
59{
60 Handle(TObj_TIntSparseArray) aTarget =
61 Handle(TObj_TIntSparseArray)::DownCast(theTarget);
62
63 // get pairs (ID, value) while ID != 0
64 Standard_Integer anId;
65 if (!(theSource >> anId) || anId < 0)
66 return Standard_False;
67 while (anId)
68 {
69 Standard_Integer aValue;
70 if (!(theSource >> aValue) || aValue <= 0)
71 return Standard_False;
72
73 // store the value in the target array
74 aTarget->SetDoBackup (Standard_False);
75 aTarget->SetValue (anId, aValue);
76 aTarget->SetDoBackup (Standard_True);
77
78 // get next ID
79 if (!(theSource >> anId) || anId < 0)
80 return Standard_False;
81 }
82 return Standard_True;
83}
84
85//=======================================================================
86//function : Paste
87//purpose : Store. Translate the contents of <theSource> and put it
88// into <theTarget>
89//=======================================================================
90
91void BinTObjDrivers_IntSparseArrayDriver::Paste
92 (const Handle(TDF_Attribute)& theSource,
93 BinObjMgt_Persistent& theTarget,
94 BinObjMgt_SRelocationTable&) const
95{
96 Handle(TObj_TIntSparseArray) aSource =
97 Handle(TObj_TIntSparseArray)::DownCast (theSource);
98
99 // put only non-null values as pairs (ID, value)
100 // terminate the list by ID=0
101 TObj_TIntSparseArray::Iterator anIt = aSource->GetIterator();
102 for ( ; anIt.More() ; anIt.Next() )
103 {
104 Standard_Integer aValue = anIt.Value();
105 if (aValue == 0)
106 continue;
107
108 // store ID and value
109 theTarget << (Standard_Integer) anIt.Index() << aValue;
110 }
111 // zero indicates end of the entities
112 theTarget << (Standard_Integer) 0;
113}