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
8 // under the terms of the GNU Lesser General Public 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 <CDM_MessageDriver.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_HANDLE(XmlTObjDrivers_ReferenceDriver,XmlMDF_ADriver)
37 IMPLEMENT_STANDARD_RTTIEXT(XmlTObjDrivers_ReferenceDriver,XmlMDF_ADriver)
39 IMPLEMENT_DOMSTRING (MasterEntry, "master")
40 IMPLEMENT_DOMSTRING (ReferredEntry, "entry")
41 IMPLEMENT_DOMSTRING (ReferredModelEntry, "modelentry")
43 //=======================================================================
44 //function : XmlTObjDrivers_ReferenceDriver
45 //purpose : constructor
46 //=======================================================================
48 XmlTObjDrivers_ReferenceDriver::XmlTObjDrivers_ReferenceDriver
49 (const Handle(CDM_MessageDriver)& theMessageDriver)
50 : XmlMDF_ADriver( theMessageDriver, NULL)
54 //=======================================================================
56 //purpose : Creates a new attribute
57 //=======================================================================
59 Handle(TDF_Attribute) XmlTObjDrivers_ReferenceDriver::NewEmpty() const
61 return new TObj_TReference;
64 //=======================================================================
66 //purpose : Translate the contents of <aSource> and put it
67 // into <aTarget>, using the relocation table
68 // <aRelocTable> to keep the sharings.
69 //=======================================================================
71 Standard_Boolean XmlTObjDrivers_ReferenceDriver::Paste
72 (const XmlObjMgt_Persistent& Source,
73 const Handle(TDF_Attribute)& Target,
74 XmlObjMgt_RRelocationTable& /*RelocTable*/) const
76 const XmlObjMgt_Element& anElement = Source;
79 TCollection_AsciiString RefEntry = anElement.getAttribute(::ReferredEntry());
80 TCollection_AsciiString MasterEntry = anElement.getAttribute(::MasterEntry());
81 // entry in model holder
82 TCollection_AsciiString InHolderEntry =
83 anElement.getAttribute(::ReferredModelEntry());
86 TDF_Label aLabel, aMasterLabel;
87 TDF_Tool::Label (Target->Label().Data(), MasterEntry, aMasterLabel);
89 if (InHolderEntry.IsEmpty())
90 TDF_Tool::Label (Target->Label().Data(), RefEntry, aLabel, Standard_True);
93 Handle(TObj_Model) aModel = Handle(TObj_Model)::DownCast
94 ( TObj_Assistant::FindModel( InHolderEntry.ToCString() ));
95 TDF_Tool::Label (aModel->GetLabel().Data(), RefEntry, aLabel, Standard_True);
97 Handle(TObj_TReference) aTarget =
98 Handle(TObj_TReference)::DownCast (Target);
99 aTarget->Set ( aLabel, aMasterLabel );
101 return !aLabel.IsNull() && !aMasterLabel.IsNull();
104 //=======================================================================
106 //purpose : Translate the contents of <aSource> and put it
107 // into <aTarget>, using the relocation table
108 // <aRelocTable> to keep the sharings.
109 // Store master and referred labels as entry, the other model referred
110 // as entry in model-container
111 //=======================================================================
113 void XmlTObjDrivers_ReferenceDriver::Paste
114 (const Handle(TDF_Attribute)& Source,
115 XmlObjMgt_Persistent& Target,
116 XmlObjMgt_SRelocationTable& /*RelocTable*/) const
118 Handle(TObj_TReference) aSource =
119 Handle(TObj_TReference)::DownCast (Source);
121 Handle(TObj_Object) aLObject = aSource->Get();
122 if (aLObject.IsNull())
126 TCollection_AsciiString entry;
127 TDF_Label aLabel = aLObject->GetLabel();
128 TDF_Tool::Entry( aLabel, entry );
129 Target.Element().setAttribute(::ReferredEntry(), entry.ToCString());
133 TDF_Label aMasterLabel = aSource->GetMasterLabel();
134 TDF_Tool::Entry( aMasterLabel, entry );
135 Target.Element().setAttribute(::MasterEntry(), entry.ToCString());
137 // is reference to other document
138 if (aLabel.Root() == aMasterLabel.Root()) return;
140 Handle(TObj_Model) aModel =
141 Handle(TObj_Model)::DownCast( aLObject->GetModel() );
142 TCollection_AsciiString aModelName( aModel->GetModelName()->String() );
143 Target.Element().setAttribute(::ReferredModelEntry(), aModelName.ToCString());