0024047: Exception in TPrsStd_AISPresentation during destruction of TDocStd_Document
[occt.git] / src / TPrsStd / TPrsStd_AISViewer.cxx
1 // Created on: 1998-09-30
2 // Created by: Denis PASCAL
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22
23 #include <TPrsStd_AISViewer.ixx>
24 #include <TDF_Label.hxx>
25
26 //=======================================================================
27 //function : GetID
28 //purpose  : 
29 //=======================================================================
30
31 const Standard_GUID& TPrsStd_AISViewer::GetID () 
32 {  
33   static Standard_GUID TPrsStd_AISViewerID("04fb4d05-5690-11d1-8940-080009dc3333");
34   return TPrsStd_AISViewerID;
35 }
36 //=======================================================================
37 //function : New
38 //purpose  : 
39 //=======================================================================
40
41 Handle(TPrsStd_AISViewer) TPrsStd_AISViewer::New (const TDF_Label& acces, 
42                                                   const Handle(V3d_Viewer)& viewer)
43 {   
44   Handle(TPrsStd_AISViewer) V;
45   if (acces.Root().FindAttribute(TPrsStd_AISViewer::GetID(),V)) { 
46     Standard_DomainError::Raise("already done");
47   }
48   V = new TPrsStd_AISViewer();
49   V->SetInteractiveContext (new AIS_InteractiveContext(viewer));
50   acces.Root().AddAttribute(V);
51   return V; 
52 }
53
54 //=======================================================================
55 //function : New
56 //purpose  : 
57 //=======================================================================
58 Handle(TPrsStd_AISViewer) TPrsStd_AISViewer::New (const TDF_Label& acces, 
59                                                   const Handle(AIS_InteractiveContext)& IC) 
60 {   
61   Handle(TPrsStd_AISViewer) V;
62   if (acces.Root().FindAttribute(TPrsStd_AISViewer::GetID(),V)) { 
63     Standard_DomainError::Raise("already done");
64   }
65   V = new TPrsStd_AISViewer();
66   V->SetInteractiveContext (IC);
67   acces.Root().AddAttribute(V);
68   return V; 
69 }
70
71 //=======================================================================
72 //function : Find
73 //purpose  : 
74 //=======================================================================
75 Standard_Boolean TPrsStd_AISViewer::Find (const TDF_Label& acces, 
76                                           Handle(TPrsStd_AISViewer)& V) 
77
78   return (acces.Root().FindAttribute(TPrsStd_AISViewer::GetID(),V)); 
79 }
80
81 //=======================================================================
82 //function : Find
83 //purpose  : 
84 //=======================================================================
85 Standard_Boolean TPrsStd_AISViewer::Find (const TDF_Label& acces, 
86                                           Handle(AIS_InteractiveContext)& IC)
87
88   Handle(TPrsStd_AISViewer) V; 
89   if (acces.Root().FindAttribute(TPrsStd_AISViewer::GetID(),V)) { 
90     IC = V->GetInteractiveContext();
91     return Standard_True; 
92   }
93   return Standard_False; 
94
95
96 //=======================================================================
97 //function : Find
98 //purpose  : 
99 //=======================================================================
100
101 Standard_Boolean TPrsStd_AISViewer::Find (const TDF_Label& acces, 
102                                           Handle(V3d_Viewer)& VIEW) 
103
104   Handle(TPrsStd_AISViewer) V;
105   if (acces.Root().FindAttribute(TPrsStd_AISViewer::GetID(),V)) { 
106     VIEW = V->GetInteractiveContext()->CurrentViewer();
107     return Standard_True; 
108   }
109   return Standard_False; 
110 }
111
112 //=======================================================================
113 //function : Has
114 //purpose  : 
115 //=======================================================================
116 Standard_Boolean TPrsStd_AISViewer::Has (const TDF_Label& acces) 
117
118   return (acces.Root().IsAttribute(TPrsStd_AISViewer::GetID())); 
119 }
120
121 //=======================================================================
122 //function : Update
123 //purpose  : 
124 //=======================================================================
125 void TPrsStd_AISViewer::Update (const TDF_Label& acces)  
126
127   Handle(TPrsStd_AISViewer) viewer; 
128   if (Find (acces,viewer)) viewer->Update(); 
129 }
130
131
132 //=======================================================================
133 //function : TPrsStd_AISViewer
134 //purpose  : 
135 //=======================================================================
136
137 TPrsStd_AISViewer::TPrsStd_AISViewer()
138 {
139 }
140
141 //=======================================================================
142 //function : Update
143 //purpose  : 
144 //=======================================================================
145
146 void TPrsStd_AISViewer::Update () const
147 {
148   myInteractiveContext->UpdateCurrentViewer();  
149 }
150  
151 //=======================================================================
152 //function : SetInteractiveContext
153 //purpose  : 
154 //=======================================================================
155
156 void TPrsStd_AISViewer::SetInteractiveContext(const Handle(AIS_InteractiveContext)& ctx) 
157 {
158   myInteractiveContext = ctx;
159 }
160
161 //=======================================================================
162 //function : GetInteractiveContext
163 //purpose  : 
164 //=======================================================================
165
166 Handle(AIS_InteractiveContext) TPrsStd_AISViewer::GetInteractiveContext() const
167 {
168   return myInteractiveContext;
169 }
170
171
172 //=======================================================================
173 //function : ID
174 //purpose  : 
175 //=======================================================================
176
177 const Standard_GUID& TPrsStd_AISViewer::ID() const { return GetID(); }
178
179
180 //=======================================================================
181 //function : Restore
182 //purpose  : 
183 //=======================================================================
184
185 void TPrsStd_AISViewer::Restore(const Handle(TDF_Attribute)&) 
186 {
187 }
188
189 //=======================================================================
190 //function : NewEmpty
191 //purpose  : 
192 //=======================================================================
193
194 Handle(TDF_Attribute) TPrsStd_AISViewer::NewEmpty() const
195 {
196   return new  TPrsStd_AISViewer();
197 }
198
199 //=======================================================================
200 //function : Paste
201 //purpose  : 
202 //=======================================================================
203
204 void TPrsStd_AISViewer::Paste (const Handle(TDF_Attribute)&,
205                              const Handle(TDF_RelocationTable)&) const
206 {
207 }
208
209