aeba4b2b18a87b583e38e2be27dbdd1c94d27545
[occt.git] / src / TDocStd / TDocStd_Owner.cxx
1 // Created on: 1999-07-12
2 // Created by: Denis PASCAL
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <TDocStd_Owner.hxx>
18
19 #include <Standard_Dump.hxx>
20 #include <Standard_GUID.hxx>
21 #include <Standard_Type.hxx>
22 #include <TDF_Attribute.hxx>
23 #include <TDF_Data.hxx>
24 #include <TDF_RelocationTable.hxx>
25 #include <TDocStd_Document.hxx>
26
27 IMPLEMENT_STANDARD_RTTIEXT(TDocStd_Owner,TDF_Attribute)
28
29 //=======================================================================
30 //function : GetID
31 //purpose  : 
32 //=======================================================================
33 const Standard_GUID& TDocStd_Owner::GetID() 
34
35   static Standard_GUID TDocStd_OwnerID ("2a96b617-ec8b-11d0-bee7-080009dc3333");
36   return TDocStd_OwnerID; 
37 }
38
39
40 //=======================================================================
41 //function : SetDocument
42 //purpose  : 
43 //=======================================================================
44
45 void TDocStd_Owner::SetDocument (const Handle(TDF_Data)& indata,
46                                  const Handle(TDocStd_Document)& D) 
47 {
48   Handle(TDocStd_Owner) A;
49   if (!indata->Root().FindAttribute (TDocStd_Owner::GetID(), A)) {
50     A = new TDocStd_Owner (); 
51     A->SetDocument(D);
52     indata->Root().AddAttribute(A);
53   }
54   else {  
55     throw Standard_DomainError("TDocStd_Owner::SetDocument : already called");
56   }
57 }
58
59 //=======================================================================
60 //function : GetDocument
61 //purpose  : 
62 //=======================================================================
63
64 Handle(TDocStd_Document) TDocStd_Owner::GetDocument (const Handle(TDF_Data)& ofdata)
65 {
66   Handle(TDocStd_Owner) A;
67   if (!ofdata->Root().FindAttribute (TDocStd_Owner::GetID(), A)) {
68     throw Standard_DomainError("TDocStd_Owner::GetDocument : document not found");
69   }
70   return A->GetDocument();
71 }
72
73 //=======================================================================
74 //function : TDocStd_Owner
75 //purpose  : 
76 //=======================================================================
77
78 TDocStd_Owner::TDocStd_Owner () { }
79
80
81 //=======================================================================
82 //function : SetDocument
83 //purpose  : 
84 //=======================================================================
85
86 void TDocStd_Owner::SetDocument(const Handle( TDocStd_Document)& D) 
87 {
88   myDocument = D;
89 }
90
91
92 //=======================================================================
93 //function : Get
94 //purpose  : 
95 //=======================================================================
96
97 Handle(TDocStd_Document) TDocStd_Owner::GetDocument () const 
98 { return myDocument; 
99 }
100
101
102 //=======================================================================
103 //function : ID
104 //purpose  : 
105 //=======================================================================
106
107 const Standard_GUID& TDocStd_Owner::ID () const { return GetID(); }
108
109
110 //=======================================================================
111 //function : NewEmpty
112 //purpose  : 
113 //=======================================================================
114
115 Handle(TDF_Attribute) TDocStd_Owner::NewEmpty () const
116 {
117   Handle(TDF_Attribute) dummy;
118   return dummy;
119 }
120
121 //=======================================================================
122 //function : Restore
123 //purpose  : 
124 //=======================================================================
125
126 void TDocStd_Owner::Restore(const Handle(TDF_Attribute)&) 
127 {
128 }
129
130 //=======================================================================
131 //function : Paste
132 //purpose  : 
133 //=======================================================================
134
135 void TDocStd_Owner::Paste (const Handle(TDF_Attribute)&,
136                               const Handle(TDF_RelocationTable)&) const
137 {
138 }
139
140 //=======================================================================
141 //function : Dump
142 //purpose  : 
143 //=======================================================================
144
145 Standard_OStream& TDocStd_Owner::Dump (Standard_OStream& anOS) const
146 {  
147   anOS << "Owner";
148   return anOS;
149 }
150
151 //=======================================================================
152 //function : DumpJson
153 //purpose  : 
154 //=======================================================================
155 void TDocStd_Owner::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
156 {
157   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
158
159   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myDocument.get())
160 }
161