1 // Created on: 2004-11-24
2 // Created by: Edward AGAPOV
3 // Copyright (c) 2004-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 // The original implementation Copyright: (C) RINA S.p.A
19 #include "XmlTObjDrivers_ReferenceDriver.hxx"
21 #include <Message_Messenger.hxx>
22 #include <TDF_Tool.hxx>
23 #include <TDF_Attribute.hxx>
25 #include <XmlObjMgt.hxx>
26 #include <XmlObjMgt_Persistent.hxx>
27 #include <XmlObjMgt_RRelocationTable.hxx>
29 #include <TObj_TReference.hxx>
30 #include <TObj_Model.hxx>
31 #include <TObj_Object.hxx>
32 #include <TObj_Assistant.hxx>
33 #include <TDF_ChildIterator.hxx>
36 IMPLEMENT_STANDARD_RTTIEXT(XmlTObjDrivers_ReferenceDriver,XmlMDF_ADriver)
37 IMPLEMENT_DOMSTRING (MasterEntry, "master")
38 IMPLEMENT_DOMSTRING (ReferredEntry, "entry")
39 IMPLEMENT_DOMSTRING (ReferredModelEntry, "modelentry")
41 //=======================================================================
42 //function : XmlTObjDrivers_ReferenceDriver
43 //purpose : constructor
44 //=======================================================================
46 XmlTObjDrivers_ReferenceDriver::XmlTObjDrivers_ReferenceDriver
47 (const Handle(Message_Messenger)& theMessageDriver)
48 : XmlMDF_ADriver( theMessageDriver, NULL)
52 //=======================================================================
54 //purpose : Creates a new attribute
55 //=======================================================================
57 Handle(TDF_Attribute) XmlTObjDrivers_ReferenceDriver::NewEmpty() const
59 return new TObj_TReference;
62 //=======================================================================
64 //purpose : Translate the contents of <aSource> and put it
65 // into <aTarget>, using the relocation table
66 // <aRelocTable> to keep the sharings.
67 //=======================================================================
69 Standard_Boolean XmlTObjDrivers_ReferenceDriver::Paste
70 (const XmlObjMgt_Persistent& Source,
71 const Handle(TDF_Attribute)& Target,
72 XmlObjMgt_RRelocationTable& /*RelocTable*/) const
74 const XmlObjMgt_Element& anElement = Source;
77 TCollection_AsciiString RefEntry = anElement.getAttribute(::ReferredEntry());
78 TCollection_AsciiString MasterEntry = anElement.getAttribute(::MasterEntry());
79 // entry in model holder
80 TCollection_AsciiString InHolderEntry =
81 anElement.getAttribute(::ReferredModelEntry());
84 TDF_Label aLabel, aMasterLabel;
85 TDF_Tool::Label (Target->Label().Data(), MasterEntry, aMasterLabel);
87 if (InHolderEntry.IsEmpty())
88 TDF_Tool::Label (Target->Label().Data(), RefEntry, aLabel, Standard_True);
91 Handle(TObj_Model) aModel = TObj_Assistant::FindModel (InHolderEntry.ToCString());
92 TDF_Tool::Label (aModel->GetLabel().Data(), RefEntry, aLabel, Standard_True);
94 Handle(TObj_TReference) aTarget =
95 Handle(TObj_TReference)::DownCast (Target);
96 aTarget->Set ( aLabel, aMasterLabel );
98 return !aLabel.IsNull() && !aMasterLabel.IsNull();
101 //=======================================================================
103 //purpose : Translate the contents of <aSource> and put it
104 // into <aTarget>, using the relocation table
105 // <aRelocTable> to keep the sharings.
106 // Store master and referred labels as entry, the other model referred
107 // as entry in model-container
108 //=======================================================================
110 void XmlTObjDrivers_ReferenceDriver::Paste
111 (const Handle(TDF_Attribute)& Source,
112 XmlObjMgt_Persistent& Target,
113 XmlObjMgt_SRelocationTable& /*RelocTable*/) const
115 Handle(TObj_TReference) aSource =
116 Handle(TObj_TReference)::DownCast (Source);
118 Handle(TObj_Object) aLObject = aSource->Get();
119 if (aLObject.IsNull())
123 TCollection_AsciiString entry;
124 TDF_Label aLabel = aLObject->GetLabel();
125 TDF_Tool::Entry( aLabel, entry );
126 Target.Element().setAttribute(::ReferredEntry(), entry.ToCString());
130 TDF_Label aMasterLabel = aSource->GetMasterLabel();
131 TDF_Tool::Entry( aMasterLabel, entry );
132 Target.Element().setAttribute(::MasterEntry(), entry.ToCString());
134 // is reference to other document
135 if (aLabel.Root() == aMasterLabel.Root()) return;
137 Handle(TObj_Model) aModel = aLObject->GetModel();
138 TCollection_AsciiString aModelName( aModel->GetModelName()->String() );
139 Target.Element().setAttribute(::ReferredModelEntry(), aModelName.ToCString());