0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / XmlTObjDrivers / XmlTObjDrivers_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 <XmlTObjDrivers_IntSparseArrayDriver.hxx>
83ae3591 19#include <Message_Messenger.hxx>
7fd59977 20#include <XmlObjMgt_Persistent.hxx>
21#include <TObj_TIntSparseArray.hxx>
7fd59977 22#include <TCollection_AsciiString.hxx>
23#include <TDF_Tool.hxx>
24
7fd59977 25
92efcf78 26IMPLEMENT_STANDARD_RTTIEXT(XmlTObjDrivers_IntSparseArrayDriver,XmlMDF_ADriver)
27
7fd59977 28#define ITEM_ID "itemId_"
29#define ITEM_VALUE "itemValue_"
30
31//=======================================================================
32//function : XmlTObjDrivers_IntSparseArrayDriver
33//purpose : constructor
34//=======================================================================
35
36XmlTObjDrivers_IntSparseArrayDriver::XmlTObjDrivers_IntSparseArrayDriver
83ae3591 37 (const Handle(Message_Messenger)& theMessageDriver)
7fd59977 38: XmlMDF_ADriver( theMessageDriver, NULL)
39{
40}
41
42//=======================================================================
43//function : NewEmpty
44//purpose : Creates a new attribute
45//=======================================================================
46
47Handle(TDF_Attribute) XmlTObjDrivers_IntSparseArrayDriver::NewEmpty() const
48{
49 return new TObj_TIntSparseArray;
50}
51
52//=======================================================================
53//function : Paste
54//purpose : Retrieve. Translate the contents of <theSource> and put it
55// into <theTarget>.
56//=======================================================================
57
58Standard_Boolean XmlTObjDrivers_IntSparseArrayDriver::Paste
59 (const XmlObjMgt_Persistent& theSource,
60 const Handle(TDF_Attribute)& theTarget,
61 XmlObjMgt_RRelocationTable&) const
62{
63 const XmlObjMgt_Element& anElement = theSource;
64 Handle(TObj_TIntSparseArray) aTarget =
65 Handle(TObj_TIntSparseArray)::DownCast(theTarget);
66
67 // get pairs (ID, value) while ID != 0
68 Standard_Integer i = 1;
69 TCollection_AsciiString anItemID;
70 TCollection_AsciiString anIdStr = TCollection_AsciiString( ITEM_ID ) +
71 TCollection_AsciiString( i );
72 anItemID = anElement.getAttribute( anIdStr.ToCString() );
73 while( anItemID.IsIntegerValue() && anItemID.IntegerValue() != 0 )
74 {
75 TCollection_AsciiString aStrIndex = TCollection_AsciiString( ITEM_VALUE ) +
76 TCollection_AsciiString( i );
77 TCollection_AsciiString anItemValue = anElement.getAttribute( aStrIndex.ToCString() );
78 if ( anItemValue.IsIntegerValue() )
79 {
80 // store the value in the target array
81 aTarget->SetDoBackup (Standard_False);
82 aTarget->SetValue (anItemID.IntegerValue(), anItemValue.IntegerValue());
83 aTarget->SetDoBackup (Standard_True);
84 }
85 i++;
86 }
87 return Standard_True;
88}
89
90//=======================================================================
91//function : Paste
92//purpose : Store. Translate the contents of <theSource> and put it
93// into <theTarget>
94//=======================================================================
95
96void XmlTObjDrivers_IntSparseArrayDriver::Paste
97 (const Handle(TDF_Attribute)& theSource,
98 XmlObjMgt_Persistent& theTarget,
99 XmlObjMgt_SRelocationTable&) const
100{
101 Handle(TObj_TIntSparseArray) aSource =
102 Handle(TObj_TIntSparseArray)::DownCast (theSource);
103
104 // put only non-null values as pairs (ID, value)
105 // terminate the list by ID=0
106 TObj_TIntSparseArray::Iterator anIt = aSource->GetIterator();
107 Standard_Integer i = 1;
108 for ( ; anIt.More() ; anIt.Next() )
109 {
110 Standard_Integer aValue = anIt.Value();
111 if (aValue == 0)
112 continue;
113 TCollection_AsciiString anIdStr = TCollection_AsciiString( ITEM_ID ) +
114 TCollection_AsciiString( i );
115 TCollection_AsciiString aStrIndex = TCollection_AsciiString( ITEM_VALUE ) +
116 TCollection_AsciiString( i );
7dc9e047 117 theTarget.Element().setAttribute( anIdStr.ToCString(), (Standard_Integer)anIt.Index() );
7fd59977 118 theTarget.Element().setAttribute( aStrIndex.ToCString(), anIt.Value() );
119 i++;
120 }
121 // write last item
122 TCollection_AsciiString anIdStr = TCollection_AsciiString( ITEM_ID ) +
123 TCollection_AsciiString( i );
124 TCollection_AsciiString aStrIndex = TCollection_AsciiString( ITEM_VALUE ) +
125 TCollection_AsciiString( i );
126 theTarget.Element().setAttribute( anIdStr.ToCString(), 0 );
127 theTarget.Element().setAttribute( aStrIndex.ToCString(), 0 );
128}