0025418: Debug output to be limited to OCC development environment
[occt.git] / src / XmlMDF / XmlMDF_ReferenceDriver.cxx
1 // Created on: 2001-09-04
2 // Created by: Julia DOROVSKIKH
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 //AGV 150202: Changed prototype XmlObjMgt::SetStringValue()
17
18 #include <XmlMDF_ReferenceDriver.ixx>
19 #include <XmlObjMgt.hxx>
20
21 #include <TDF_Reference.hxx>
22 #include <TDF_Tool.hxx>
23
24 //=======================================================================
25 //function : XmlMDF_ReferenceDriver
26 //purpose  : Constructor
27 //=======================================================================
28 XmlMDF_ReferenceDriver::XmlMDF_ReferenceDriver
29                         (const Handle(CDM_MessageDriver)& theMsgDriver)
30       : XmlMDF_ADriver (theMsgDriver, NULL)
31 {}
32
33 //=======================================================================
34 //function : NewEmpty
35 //purpose  : 
36 //=======================================================================
37 Handle(TDF_Attribute) XmlMDF_ReferenceDriver::NewEmpty() const
38 {
39   return (new TDF_Reference());
40 }
41
42 //=======================================================================
43 //function : Paste
44 //purpose  : persistent -> transient (retrieve)
45 //=======================================================================
46 Standard_Boolean XmlMDF_ReferenceDriver::Paste
47                 (const XmlObjMgt_Persistent&   theSource,
48                  const Handle(TDF_Attribute)&  theTarget,
49                  XmlObjMgt_RRelocationTable&   ) const
50 {
51   XmlObjMgt_DOMString anXPath = XmlObjMgt::GetStringValue(theSource);
52
53   if (anXPath == NULL)
54   {
55     WriteMessage ("Cannot retrieve reference string from element");
56     return Standard_False;
57   }
58
59   TCollection_AsciiString anEntry;
60   if (XmlObjMgt::GetTagEntryString (anXPath, anEntry) == Standard_False)
61   {
62     TCollection_ExtendedString aMessage =
63       TCollection_ExtendedString ("Cannot retrieve reference from \"")
64         + anXPath + '\"';
65     WriteMessage (aMessage);
66     return Standard_False;
67   }
68
69   Handle(TDF_Reference) aRef = Handle(TDF_Reference)::DownCast(theTarget);
70
71   // find label by entry
72   TDF_Label tLab; // Null label.
73   if (anEntry.Length() > 0)
74   {
75     TDF_Tool::Label(aRef->Label().Data(), anEntry, tLab, Standard_True);
76   }
77
78   // set referenced label
79   aRef->Set(tLab);
80
81   return Standard_True;
82 }
83
84 //=======================================================================
85 //function : Paste
86 //purpose  : transient -> persistent (store)
87 //           <label tag='1'>     <This is label entry 0:4:1>
88 //           ...
89 //           <label tag='8'>     <This is label entry 0:4:1:8>
90 //
91 //           <TDF_Reference id="621"> /document/label/label[@tag="4"]/label[@tag="1"]
92 //           </TDF_Reference>    <This is reference to label 0:4:1>
93 //=======================================================================
94 void XmlMDF_ReferenceDriver::Paste (const Handle(TDF_Attribute)&  theSource,
95                                     XmlObjMgt_Persistent&         theTarget,
96                                     XmlObjMgt_SRelocationTable&   ) const
97 {
98   Handle(TDF_Reference) aRef = Handle(TDF_Reference)::DownCast(theSource);
99   if (!aRef.IsNull())
100   {
101     const TDF_Label& lab = aRef->Label();
102     const TDF_Label& refLab = aRef->Get();
103     if (!lab.IsNull() && !refLab.IsNull())
104     {
105       if (lab.IsDescendant(refLab.Root()))
106       {
107         // Internal reference
108         TCollection_AsciiString anEntry;
109         TDF_Tool::Entry(refLab, anEntry);
110
111         XmlObjMgt_DOMString aDOMString;
112         XmlObjMgt::SetTagEntryString (aDOMString, anEntry);
113         // No occurrence of '&', '<' and other irregular XML characters
114         XmlObjMgt::SetStringValue (theTarget, aDOMString, Standard_True);
115       }
116     }
117   }
118 }