0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / BinMDataStd / BinMDataStd_ReferenceListDriver.cxx
1 // Created on: 2007-05-29
2 // Created by: Vlad Romashko
3 // Copyright (c) 2007-2014 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
17 #include <BinMDataStd_ReferenceListDriver.hxx>
18 #include <BinMDataStd.hxx>
19 #include <BinObjMgt_Persistent.hxx>
20 #include <Message_Messenger.hxx>
21 #include <Standard_Type.hxx>
22 #include <TDataStd_ReferenceList.hxx>
23 #include <TDF_Attribute.hxx>
24 #include <TDF_Label.hxx>
25 #include <TDF_ListIteratorOfLabelList.hxx>
26 #include <TDF_Tool.hxx>
27
28 IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_ReferenceListDriver,BinMDF_ADriver)
29
30 //=======================================================================
31 //function : BinMDataStd_ReferenceListDriver
32 //purpose  : Constructor
33 //=======================================================================
34 BinMDataStd_ReferenceListDriver::BinMDataStd_ReferenceListDriver(const Handle(Message_Messenger)& theMsgDriver)
35      : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_ReferenceList)->Name())
36 {
37
38 }
39
40 //=======================================================================
41 //function : NewEmpty
42 //purpose  : 
43 //=======================================================================
44 Handle(TDF_Attribute) BinMDataStd_ReferenceListDriver::NewEmpty() const
45 {
46   return new TDataStd_ReferenceList();
47 }
48
49 //=======================================================================
50 //function : Paste
51 //purpose  : persistent -> transient (retrieve)
52 //=======================================================================
53 Standard_Boolean BinMDataStd_ReferenceListDriver::Paste(const BinObjMgt_Persistent&  theSource,
54                                                         const Handle(TDF_Attribute)& theTarget,
55                                                         BinObjMgt_RRelocationTable&  theRelocTable) const
56 {
57   Standard_Integer aFirstInd, aLastInd;
58   if (! (theSource >> aFirstInd >> aLastInd))
59     return Standard_False;
60
61   const Handle(TDataStd_ReferenceList) anAtt = Handle(TDataStd_ReferenceList)::DownCast(theTarget);
62   if(aLastInd > 0) {
63
64     const Standard_Integer aLength = aLastInd - aFirstInd + 1;
65     if (aLength <= 0)
66       return Standard_False;
67     for (Standard_Integer i = aFirstInd; i <= aLastInd; i++)
68     {
69       TCollection_AsciiString entry;
70       if ( !(theSource >> entry) )
71         return Standard_False;
72       TDF_Label L;
73       TDF_Tool::Label(anAtt->Label().Data(), entry, L, Standard_True);
74       if (!L.IsNull())
75         anAtt->Append(L);
76     }
77   }
78
79   BinMDataStd::SetAttributeID(theSource, anAtt, theRelocTable.GetHeaderData()->StorageVersion().IntegerValue());
80   return Standard_True;
81 }
82
83 //=======================================================================
84 //function : Paste
85 //purpose  : transient -> persistent (store)
86 //=======================================================================
87 void BinMDataStd_ReferenceListDriver::Paste(const Handle(TDF_Attribute)& theSource,
88                                             BinObjMgt_Persistent&        theTarget,
89                                             BinObjMgt_SRelocationTable&  ) const
90 {
91   const Handle(TDataStd_ReferenceList) anAtt = Handle(TDataStd_ReferenceList)::DownCast(theSource);
92   if (anAtt.IsNull())
93     return;
94   const Standard_Integer aFirstInd = (anAtt->Extent()> 0) ? 1 : 0;
95   const Standard_Integer aLastInd(anAtt->Extent());  
96   theTarget << aFirstInd << aLastInd;
97   if(aLastInd == 0) return;
98   TDF_ListIteratorOfLabelList itr(anAtt->List());
99   for (Standard_Integer i = aFirstInd; itr.More(); itr.Next(), i++)
100   {
101     TDF_Label L = itr.Value();
102     if (!L.IsNull())
103     {
104       TCollection_AsciiString entry;
105       TDF_Tool::Entry(L, entry);
106       theTarget << entry;
107     }
108   }
109
110   // process user defined guid
111   if(anAtt->ID() != TDataStd_ReferenceList::GetID()) 
112     theTarget << anAtt->ID();
113 }