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