0031353: TDocStd_Application does not have api to set progress indicator
[occt.git] / src / XmlMDF / XmlMDF_ReferenceDriver.cxx
CommitLineData
b311480e 1// Created on: 2001-09-04
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.
b311480e 15
16//AGV 150202: Changed prototype XmlObjMgt::SetStringValue()
7fd59977 17
83ae3591 18#include <Message_Messenger.hxx>
42cf5bc1 19#include <Standard_Type.hxx>
20#include <TDF_Attribute.hxx>
7fd59977 21#include <TDF_Reference.hxx>
22#include <TDF_Tool.hxx>
42cf5bc1 23#include <XmlMDF_ReferenceDriver.hxx>
24#include <XmlObjMgt.hxx>
25#include <XmlObjMgt_Persistent.hxx>
7fd59977 26
92efcf78 27IMPLEMENT_STANDARD_RTTIEXT(XmlMDF_ReferenceDriver,XmlMDF_ADriver)
28
7fd59977 29//=======================================================================
30//function : XmlMDF_ReferenceDriver
31//purpose : Constructor
32//=======================================================================
33XmlMDF_ReferenceDriver::XmlMDF_ReferenceDriver
83ae3591 34 (const Handle(Message_Messenger)& theMsgDriver)
7fd59977 35 : XmlMDF_ADriver (theMsgDriver, NULL)
36{}
37
38//=======================================================================
39//function : NewEmpty
40//purpose :
41//=======================================================================
42Handle(TDF_Attribute) XmlMDF_ReferenceDriver::NewEmpty() const
43{
44 return (new TDF_Reference());
45}
46
47//=======================================================================
48//function : Paste
49//purpose : persistent -> transient (retrieve)
50//=======================================================================
51Standard_Boolean XmlMDF_ReferenceDriver::Paste
52 (const XmlObjMgt_Persistent& theSource,
53 const Handle(TDF_Attribute)& theTarget,
54 XmlObjMgt_RRelocationTable& ) const
55{
56 XmlObjMgt_DOMString anXPath = XmlObjMgt::GetStringValue(theSource);
57
58 if (anXPath == NULL)
59 {
83ae3591 60 myMessageDriver->Send ("Cannot retrieve reference string from element", Message_Fail);
7fd59977 61 return Standard_False;
62 }
63
64 TCollection_AsciiString anEntry;
65 if (XmlObjMgt::GetTagEntryString (anXPath, anEntry) == Standard_False)
66 {
67 TCollection_ExtendedString aMessage =
68 TCollection_ExtendedString ("Cannot retrieve reference from \"")
69 + anXPath + '\"';
83ae3591 70 myMessageDriver->Send (aMessage, Message_Fail);
7fd59977 71 return Standard_False;
72 }
73
74 Handle(TDF_Reference) aRef = Handle(TDF_Reference)::DownCast(theTarget);
75
76 // find label by entry
77 TDF_Label tLab; // Null label.
78 if (anEntry.Length() > 0)
79 {
80 TDF_Tool::Label(aRef->Label().Data(), anEntry, tLab, Standard_True);
81 }
82
83 // set referenced label
84 aRef->Set(tLab);
85
86 return Standard_True;
87}
88
89//=======================================================================
90//function : Paste
91//purpose : transient -> persistent (store)
92// <label tag='1'> <This is label entry 0:4:1>
93// ...
94// <label tag='8'> <This is label entry 0:4:1:8>
95//
96// <TDF_Reference id="621"> /document/label/label[@tag="4"]/label[@tag="1"]
97// </TDF_Reference> <This is reference to label 0:4:1>
98//=======================================================================
99void XmlMDF_ReferenceDriver::Paste (const Handle(TDF_Attribute)& theSource,
100 XmlObjMgt_Persistent& theTarget,
101 XmlObjMgt_SRelocationTable& ) const
102{
103 Handle(TDF_Reference) aRef = Handle(TDF_Reference)::DownCast(theSource);
104 if (!aRef.IsNull())
105 {
106 const TDF_Label& lab = aRef->Label();
107 const TDF_Label& refLab = aRef->Get();
108 if (!lab.IsNull() && !refLab.IsNull())
109 {
110 if (lab.IsDescendant(refLab.Root()))
111 {
112 // Internal reference
113 TCollection_AsciiString anEntry;
114 TDF_Tool::Entry(refLab, anEntry);
115
116 XmlObjMgt_DOMString aDOMString;
117 XmlObjMgt::SetTagEntryString (aDOMString, anEntry);
118 // No occurrence of '&', '<' and other irregular XML characters
119 XmlObjMgt::SetStringValue (theTarget, aDOMString, Standard_True);
120 }
121 }
122 }
123}