0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[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-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
18 #include <AIS_InteractiveContext.hxx>
19 #include <Standard_GUID.hxx>
20 #include <Standard_Type.hxx>
21 #include <TDF_Attribute.hxx>
22 #include <TDF_ChildIterator.hxx>
23 #include <TDF_Label.hxx>
24 #include <TDF_RelocationTable.hxx>
25 #include <TDataXtd_Presentation.hxx>
26 #include <TPrsStd_AISPresentation.hxx>
27 #include <TPrsStd_AISViewer.hxx>
28 #include <V3d_Viewer.hxx>
29
30 IMPLEMENT_STANDARD_RTTIEXT(TPrsStd_AISViewer,TDF_Attribute)
31
32 //=======================================================================
33 //function : GetID
34 //purpose  : 
35 //=======================================================================
36 const Standard_GUID& TPrsStd_AISViewer::GetID () 
37 {  
38   static Standard_GUID TPrsStd_AISViewerID("04fb4d05-5690-11d1-8940-080009dc3333");
39   return TPrsStd_AISViewerID;
40 }
41 //=======================================================================
42 //function : New
43 //purpose  : 
44 //=======================================================================
45
46 Handle(TPrsStd_AISViewer) TPrsStd_AISViewer::New (const TDF_Label& acces, 
47                                                   const Handle(V3d_Viewer)& viewer)
48 {   
49   Handle(TPrsStd_AISViewer) V;
50   if (acces.Root().FindAttribute(TPrsStd_AISViewer::GetID(),V)) { 
51     throw Standard_DomainError("already done");
52   }
53   V = new TPrsStd_AISViewer();
54   V->SetInteractiveContext (new AIS_InteractiveContext(viewer));
55   acces.Root().AddAttribute(V);
56
57   // put TPrsStd_AISPresentation attribute at all labels containing
58   // TDataXtd_Presentation attribute
59   for (TDF_ChildIterator anIt(acces.Root(), Standard_True); anIt.More(); anIt.Next())
60   {
61     Handle(TDataXtd_Presentation) aPrsData;
62     if (anIt.Value().FindAttribute(TDataXtd_Presentation::GetID(), aPrsData)) { 
63       TPrsStd_AISPresentation::Set (anIt.Value(), aPrsData->GetDriverGUID());
64     }
65   }
66
67   return V; 
68 }
69
70 //=======================================================================
71 //function : New
72 //purpose  : 
73 //=======================================================================
74 Handle(TPrsStd_AISViewer) TPrsStd_AISViewer::New (const TDF_Label& acces, 
75                                                   const Handle(AIS_InteractiveContext)& IC) 
76 {   
77   Handle(TPrsStd_AISViewer) V;
78   if (acces.Root().FindAttribute(TPrsStd_AISViewer::GetID(),V)) { 
79     throw Standard_DomainError("already done");
80   }
81   V = new TPrsStd_AISViewer();
82   V->SetInteractiveContext (IC);
83   acces.Root().AddAttribute(V);
84
85   // put TPrsStd_AISPresentation attribute at all labels containing
86   // TDataXtd_Presentation attribute
87   for (TDF_ChildIterator anIt(acces.Root(), Standard_True); anIt.More(); anIt.Next())
88   {
89     Handle(TDataXtd_Presentation) aPrsData;
90     if (anIt.Value().FindAttribute(TDataXtd_Presentation::GetID(), aPrsData)) { 
91       TPrsStd_AISPresentation::Set (anIt.Value(), aPrsData->GetDriverGUID());
92     }
93   }
94
95   return V; 
96 }
97
98 //=======================================================================
99 //function : Find
100 //purpose  : 
101 //=======================================================================
102 Standard_Boolean TPrsStd_AISViewer::Find (const TDF_Label& acces, 
103                                           Handle(TPrsStd_AISViewer)& V) 
104
105   return (acces.Root().FindAttribute(TPrsStd_AISViewer::GetID(),V)); 
106 }
107
108 //=======================================================================
109 //function : Find
110 //purpose  : 
111 //=======================================================================
112 Standard_Boolean TPrsStd_AISViewer::Find (const TDF_Label& acces, 
113                                           Handle(AIS_InteractiveContext)& IC)
114
115   Handle(TPrsStd_AISViewer) V; 
116   if (acces.Root().FindAttribute(TPrsStd_AISViewer::GetID(),V)) { 
117     IC = V->GetInteractiveContext();
118     return Standard_True; 
119   }
120   return Standard_False; 
121
122
123 //=======================================================================
124 //function : Find
125 //purpose  : 
126 //=======================================================================
127
128 Standard_Boolean TPrsStd_AISViewer::Find (const TDF_Label& acces, 
129                                           Handle(V3d_Viewer)& VIEW) 
130
131   Handle(TPrsStd_AISViewer) V;
132   if (acces.Root().FindAttribute(TPrsStd_AISViewer::GetID(),V)) { 
133     VIEW = V->GetInteractiveContext()->CurrentViewer();
134     return Standard_True; 
135   }
136   return Standard_False; 
137 }
138
139 //=======================================================================
140 //function : Has
141 //purpose  : 
142 //=======================================================================
143 Standard_Boolean TPrsStd_AISViewer::Has (const TDF_Label& acces) 
144
145   return (acces.Root().IsAttribute(TPrsStd_AISViewer::GetID())); 
146 }
147
148 //=======================================================================
149 //function : Update
150 //purpose  : 
151 //=======================================================================
152 void TPrsStd_AISViewer::Update (const TDF_Label& acces)  
153
154   Handle(TPrsStd_AISViewer) viewer; 
155   if (Find (acces,viewer)) viewer->Update(); 
156 }
157
158
159 //=======================================================================
160 //function : TPrsStd_AISViewer
161 //purpose  : 
162 //=======================================================================
163
164 TPrsStd_AISViewer::TPrsStd_AISViewer()
165 {
166 }
167
168 //=======================================================================
169 //function : Update
170 //purpose  : 
171 //=======================================================================
172
173 void TPrsStd_AISViewer::Update () const
174 {
175   myInteractiveContext->UpdateCurrentViewer();  
176 }
177  
178 //=======================================================================
179 //function : SetInteractiveContext
180 //purpose  : 
181 //=======================================================================
182
183 void TPrsStd_AISViewer::SetInteractiveContext(const Handle(AIS_InteractiveContext)& ctx) 
184 {
185   myInteractiveContext = ctx;
186 }
187
188 //=======================================================================
189 //function : GetInteractiveContext
190 //purpose  : 
191 //=======================================================================
192
193 Handle(AIS_InteractiveContext) TPrsStd_AISViewer::GetInteractiveContext() const
194 {
195   return myInteractiveContext;
196 }
197
198
199 //=======================================================================
200 //function : ID
201 //purpose  : 
202 //=======================================================================
203
204 const Standard_GUID& TPrsStd_AISViewer::ID() const { return GetID(); }
205
206
207 //=======================================================================
208 //function : Restore
209 //purpose  : 
210 //=======================================================================
211
212 void TPrsStd_AISViewer::Restore(const Handle(TDF_Attribute)&) 
213 {
214 }
215
216 //=======================================================================
217 //function : NewEmpty
218 //purpose  : 
219 //=======================================================================
220
221 Handle(TDF_Attribute) TPrsStd_AISViewer::NewEmpty() const
222 {
223   return new  TPrsStd_AISViewer();
224 }
225
226 //=======================================================================
227 //function : Paste
228 //purpose  : 
229 //=======================================================================
230
231 void TPrsStd_AISViewer::Paste (const Handle(TDF_Attribute)&,
232                              const Handle(TDF_RelocationTable)&) const
233 {
234 }
235
236