b311480e |
1 | // Created on: 2001-09-12 |
2 | // Created by: Julia DOROVSKIKH |
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_RelationDriver.hxx> |
18 | #include <BinObjMgt_Persistent.hxx> |
83ae3591 |
19 | #include <Message_Messenger.hxx> |
42cf5bc1 |
20 | #include <Standard_Type.hxx> |
7fd59977 |
21 | #include <TDataStd_Relation.hxx> |
22 | #include <TDataStd_Variable.hxx> |
42cf5bc1 |
23 | #include <TDF_Attribute.hxx> |
7fd59977 |
24 | #include <TDF_ListIteratorOfAttributeList.hxx> |
25 | |
92efcf78 |
26 | IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_RelationDriver,BinMDF_ADriver) |
27 | |
7fd59977 |
28 | //======================================================================= |
29 | //function : BinMDataStd_RelationDriver |
30 | //purpose : Constructor |
31 | //======================================================================= |
32 | BinMDataStd_RelationDriver::BinMDataStd_RelationDriver |
83ae3591 |
33 | (const Handle(Message_Messenger)& theMsgDriver) |
7fd59977 |
34 | : BinMDF_ADriver (theMsgDriver, NULL) |
35 | {} |
36 | |
37 | //======================================================================= |
38 | //function : NewEmpty |
39 | //purpose : |
40 | //======================================================================= |
41 | Handle(TDF_Attribute) BinMDataStd_RelationDriver::NewEmpty() const |
42 | { |
43 | return (new TDataStd_Relation()); |
44 | } |
45 | |
46 | //======================================================================= |
47 | //function : Paste |
48 | //purpose : persistent -> transient (retrieve) |
49 | //======================================================================= |
50 | Standard_Boolean BinMDataStd_RelationDriver::Paste |
51 | (const BinObjMgt_Persistent& theSource, |
52 | const Handle(TDF_Attribute)& theTarget, |
53 | BinObjMgt_RRelocationTable& theRelocTable) const |
54 | { |
55 | Handle(TDataStd_Relation) aC = |
56 | Handle(TDataStd_Relation)::DownCast(theTarget); |
57 | |
58 | // variables |
59 | Standard_Integer nbvar; |
60 | if (! (theSource >> nbvar) || nbvar < 0) |
61 | return Standard_False; |
62 | TDF_AttributeList& aList = aC->GetVariables(); |
63 | for (; nbvar > 0; nbvar--) |
64 | { |
65 | Handle(TDF_Attribute) aV; |
66 | Standard_Integer aNb; |
67 | if (! (theSource >> aNb)) |
68 | return Standard_False; |
69 | if (aNb > 0) |
70 | { |
71 | if (theRelocTable.IsBound(aNb)) |
72 | aV = Handle(TDataStd_Variable)::DownCast(theRelocTable.Find(aNb)); |
73 | else |
74 | { |
75 | aV = new TDataStd_Variable; |
76 | theRelocTable.Bind(aNb, aV); |
77 | } |
78 | } |
79 | aList.Append(aV); |
80 | } |
81 | |
82 | // expression |
83 | TCollection_ExtendedString aString; |
84 | if (! (theSource >> aString)) |
85 | return Standard_False; |
86 | aC->SetRelation(aString); |
87 | |
88 | return Standard_True; |
89 | } |
90 | |
91 | //======================================================================= |
92 | //function : Paste |
93 | //purpose : transient -> persistent (store) |
94 | //======================================================================= |
95 | void BinMDataStd_RelationDriver::Paste |
96 | (const Handle(TDF_Attribute)& theSource, |
97 | BinObjMgt_Persistent& theTarget, |
98 | BinObjMgt_SRelocationTable& theRelocTable) const |
99 | { |
100 | Handle(TDataStd_Relation) aC = |
101 | Handle(TDataStd_Relation)::DownCast(theSource); |
102 | |
103 | // variables |
104 | const TDF_AttributeList& aList = aC->GetVariables(); |
105 | Standard_Integer nbvar = aList.Extent(); |
106 | theTarget << nbvar; |
107 | TDF_ListIteratorOfAttributeList it; |
108 | for (it.Initialize(aList); it.More(); it.Next()) |
109 | { |
110 | const Handle(TDF_Attribute)& TV = it.Value(); |
111 | Standard_Integer aNb; |
112 | if (!TV.IsNull()) |
113 | aNb = theRelocTable.Add(TV); |
114 | else |
115 | aNb = -1; |
116 | theTarget << aNb; |
117 | } |
118 | |
119 | // expression |
120 | TCollection_ExtendedString aName = aC->Name(); |
121 | theTarget << aName; |
122 | } |