0030686: Visualization, SelectMgr_ViewerSelector - sorting issues of transformation...
[occt.git] / src / BinMDataStd / BinMDataStd_TreeNodeDriver.cxx
CommitLineData
b311480e 1// Created on: 2001-08-24
2// Created by: Alexnder GRIGORIEV
973c2be1 3// Copyright (c) 2001-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.
7fd59977 15
42cf5bc1 16
17#include <BinMDataStd_TreeNodeDriver.hxx>
18#include <BinObjMgt_Persistent.hxx>
83ae3591 19#include <Message_Messenger.hxx>
42cf5bc1 20#include <Standard_Type.hxx>
7fd59977 21#include <TCollection_ExtendedString.hxx>
42cf5bc1 22#include <TDataStd_TreeNode.hxx>
23#include <TDF_Attribute.hxx>
7fd59977 24
92efcf78 25IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_TreeNodeDriver,BinMDF_ADriver)
26
7fd59977 27//=======================================================================
28//function : BinMDataStd_TreeNodeDriver
29//purpose : Constructor
30//=======================================================================
7fd59977 31BinMDataStd_TreeNodeDriver::BinMDataStd_TreeNodeDriver
83ae3591 32 (const Handle(Message_Messenger)& theMsgDriver)
7fd59977 33 : BinMDF_ADriver (theMsgDriver, NULL)
34{}
35
36//=======================================================================
37//function : NewEmpty
38//purpose :
39//=======================================================================
40Handle(TDF_Attribute) BinMDataStd_TreeNodeDriver::NewEmpty() const
41{
42 return (new TDataStd_TreeNode());
43}
44
45//=======================================================================
46//function : Paste
47//purpose :
48//=======================================================================
49Standard_Boolean BinMDataStd_TreeNodeDriver::Paste
50 (const BinObjMgt_Persistent& theSource,
51 const Handle(TDF_Attribute)& theTarget,
52 BinObjMgt_RRelocationTable& theRelocTable) const
53{
54 Handle(TDataStd_TreeNode) aT = Handle(TDataStd_TreeNode)::DownCast(theTarget);
55
56 // read int fields
57 Standard_Integer i, aNb;
58 for (i = 0 ; i < 4; ++i)
59 {
60 if (! (theSource >> aNb))
61 return Standard_False;
62 if (aNb < 0) continue;
63
64 Handle(TDataStd_TreeNode) aNode;
65 if (theRelocTable.IsBound(aNb))
66 aNode = Handle(TDataStd_TreeNode)::DownCast(theRelocTable.Find(aNb));
67 else
68 {
69 aNode = Handle(TDataStd_TreeNode)::DownCast( aT->NewEmpty() ); // already with tree ID
70 theRelocTable.Bind(aNb, aNode);
71 }
72 switch (i) {
73 case 0: aT->SetFather (aNode); break;
74 case 1: aT->SetNext (aNode); break;
75 case 2: aT->SetPrevious(aNode); break;
76 case 3: aT->SetFirst (aNode); break;
77 default: continue;
78 }
79 }
80
81 // tree id
82 Standard_GUID aGUID;
83 if (! (theSource >> aGUID))
84 return Standard_False;
85 aT->SetTreeID(aGUID);
86
87 return Standard_True;
88}
89
90//=======================================================================
91//function : Paste
92//purpose :
93//=======================================================================
94void BinMDataStd_TreeNodeDriver::Paste
95 (const Handle(TDF_Attribute)& theSource,
96 BinObjMgt_Persistent& theTarget,
97 BinObjMgt_SRelocationTable& theRelocTable) const
98{
99 Handle(TDataStd_TreeNode) aS = Handle(TDataStd_TreeNode)::DownCast(theSource);
100
101 // first write int fields
102 Standard_Integer i, aNb;
103 for (i = 0 ; i < 4; ++i)
104 {
105 Handle(TDataStd_TreeNode) aNode;
106 switch (i) {
107 case 0: aNode = aS->Father(); break;
108 case 1: aNode = aS->Next(); break;
109 case 2: aNode = aS->Previous(); break;
110 case 3: aNode = aS->First(); break;
111 default: continue;
112 }
113 if (aNode.IsNull())
114 aNb = -1;
115 else
116 aNb = theRelocTable.Add(aNode); // create and/or get index
117 theTarget.PutInteger(aNb);
118 }
119
120 // tree id
121 theTarget << aS->ID();
122}