7fd59977 |
1 | // File : BinTObjDrivers_ReferenceDriver.cxx |
2 | // Created : Wed Nov 24 11:42:17 2004 |
3 | // Author : Edward AGAPOV |
4 | // Copyright: Open CASCADE 2007 |
5 | // The original implementation Copyright: (C) RINA S.p.A |
6 | |
7 | |
8 | #include <BinTObjDrivers_ReferenceDriver.hxx> |
9 | #include <CDM_MessageDriver.hxx> |
10 | #include <TDF_Attribute.hxx> |
11 | #include <TObj_TReference.hxx> |
12 | #include <BinObjMgt_Persistent.hxx> |
13 | #include <TObj_Object.hxx> |
14 | #include <TObj_Model.hxx> |
15 | #include <TObj_Assistant.hxx> |
16 | #include <TDF_ChildIterator.hxx> |
17 | #include <TDF_Tool.hxx> |
18 | |
19 | IMPLEMENT_STANDARD_HANDLE(BinTObjDrivers_ReferenceDriver,BinMDF_ADriver) |
20 | IMPLEMENT_STANDARD_RTTIEXT(BinTObjDrivers_ReferenceDriver,BinMDF_ADriver) |
21 | |
22 | //======================================================================= |
23 | //function : BinTObjDrivers_ReferenceDriver |
24 | //purpose : constructor |
25 | //======================================================================= |
26 | |
27 | BinTObjDrivers_ReferenceDriver::BinTObjDrivers_ReferenceDriver |
28 | (const Handle(CDM_MessageDriver)& theMessageDriver) |
29 | : BinMDF_ADriver( theMessageDriver, NULL) |
30 | { |
31 | } |
32 | |
33 | //======================================================================= |
34 | //function : NewEmpty |
35 | //purpose : Creates a new attribute |
36 | //======================================================================= |
37 | |
38 | Handle(TDF_Attribute) BinTObjDrivers_ReferenceDriver::NewEmpty() const |
39 | { |
40 | return new TObj_TReference; |
41 | } |
42 | |
43 | //======================================================================= |
44 | //function : Paste |
45 | //purpose : Translate the contents of <theSource> and put it |
46 | // into <theTarget>. |
47 | //======================================================================= |
48 | |
49 | Standard_Boolean BinTObjDrivers_ReferenceDriver::Paste |
50 | (const BinObjMgt_Persistent& theSource, |
51 | const Handle(TDF_Attribute)& theTarget, |
52 | BinObjMgt_RRelocationTable&) const |
53 | { |
54 | // master label |
55 | TDF_Label aMasterLabel; |
56 | Handle(TDF_Data) aDS = theTarget->Label().Data(); |
57 | if (! theSource.GetLabel (aDS, aMasterLabel)) return Standard_False; |
58 | |
59 | // isSameDoc flag |
60 | Standard_Boolean isSameDoc = Standard_False; |
61 | if (! (theSource >> isSameDoc)) return Standard_False; |
62 | |
63 | // DS for referred label |
64 | if (!isSameDoc) |
65 | { |
66 | TCollection_AsciiString aName; |
67 | if (! (theSource >> aName)) return Standard_False; |
68 | Handle(TObj_Model) aModel = Handle(TObj_Model)::DownCast |
69 | ( TObj_Assistant::FindModel( aName.ToCString() )); |
70 | if (aModel.IsNull()) |
71 | { |
72 | TCollection_AsciiString anEntry; |
73 | TDF_Tool::Entry (theTarget->Label(), anEntry); |
74 | WriteMessage (TCollection_ExtendedString ("TObj_TReference retrieval: ") |
75 | + "wrong model ID " + aName + ", entry " + anEntry); |
76 | return Standard_False; |
77 | } |
78 | aDS = aModel->GetLabel().Data(); |
79 | } |
80 | // reffered label |
81 | TDF_Label aLabel; |
82 | if (! theSource.GetLabel (aDS, aLabel)) return Standard_False; |
83 | |
84 | // set reference attribute fields |
85 | Handle(TObj_TReference) aTarget = |
86 | Handle(TObj_TReference)::DownCast (theTarget); |
87 | aTarget->Set ( aLabel, aMasterLabel ); |
88 | |
89 | return !aLabel.IsNull() && !aMasterLabel.IsNull(); |
90 | } |
91 | |
92 | //======================================================================= |
93 | //function : Paste |
94 | //purpose : Translate the contents of <theSource> and put it |
95 | // into <theTarget>. |
96 | // Store master and referred labels as entry, the other model referred |
97 | // as entry in model-container |
98 | //======================================================================= |
99 | |
100 | void BinTObjDrivers_ReferenceDriver::Paste |
101 | (const Handle(TDF_Attribute)& theSource, |
102 | BinObjMgt_Persistent& theTarget, |
103 | BinObjMgt_SRelocationTable&) const |
104 | { |
105 | Handle(TObj_TReference) aSource = |
106 | Handle(TObj_TReference)::DownCast (theSource); |
107 | |
108 | Handle(TObj_Object) aLObject = aSource->Get(); |
109 | if (aLObject.IsNull()) |
110 | return; |
111 | |
112 | // labels |
113 | TDF_Label aLabel = aLObject->GetLabel(); |
114 | TDF_Label aMasterLabel = aSource->GetMasterLabel(); |
115 | Standard_Boolean isSameDoc = (aLabel.Root() == aMasterLabel.Root()); |
116 | |
117 | // store data |
118 | // 1 - the master label; |
119 | theTarget << aMasterLabel; |
120 | // 2 - isSameDoc flag plus may be a Model ID |
121 | theTarget << isSameDoc; |
122 | if (! isSameDoc) |
123 | { |
124 | TCollection_AsciiString aName; |
125 | Handle(TObj_Model) aModel = |
126 | Handle(TObj_Model)::DownCast( aLObject->GetModel() ); |
127 | aName = TCollection_AsciiString( aModel->GetModelName()->String() ); |
128 | theTarget << aName; |
129 | } |
130 | // 3 - referred label; |
131 | theTarget << aLabel; |
132 | } |