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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
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>
30 IMPLEMENT_STANDARD_RTTIEXT(TPrsStd_AISViewer,TDF_Attribute)
32 //=======================================================================
35 //=======================================================================
36 const Standard_GUID& TPrsStd_AISViewer::GetID ()
38 static Standard_GUID TPrsStd_AISViewerID("04fb4d05-5690-11d1-8940-080009dc3333");
39 return TPrsStd_AISViewerID;
41 //=======================================================================
44 //=======================================================================
46 Handle(TPrsStd_AISViewer) TPrsStd_AISViewer::New (const TDF_Label& acces,
47 const Handle(V3d_Viewer)& viewer)
49 Handle(TPrsStd_AISViewer) V;
50 if (acces.Root().FindAttribute(TPrsStd_AISViewer::GetID(),V)) {
51 throw Standard_DomainError("already done");
53 V = new TPrsStd_AISViewer();
54 V->SetInteractiveContext (new AIS_InteractiveContext(viewer));
55 acces.Root().AddAttribute(V);
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())
61 Handle(TDataXtd_Presentation) aPrsData;
62 if (anIt.Value().FindAttribute(TDataXtd_Presentation::GetID(), aPrsData)) {
63 TPrsStd_AISPresentation::Set (anIt.Value(), aPrsData->GetDriverGUID());
70 //=======================================================================
73 //=======================================================================
74 Handle(TPrsStd_AISViewer) TPrsStd_AISViewer::New (const TDF_Label& acces,
75 const Handle(AIS_InteractiveContext)& IC)
77 Handle(TPrsStd_AISViewer) V;
78 if (acces.Root().FindAttribute(TPrsStd_AISViewer::GetID(),V)) {
79 throw Standard_DomainError("already done");
81 V = new TPrsStd_AISViewer();
82 V->SetInteractiveContext (IC);
83 acces.Root().AddAttribute(V);
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())
89 Handle(TDataXtd_Presentation) aPrsData;
90 if (anIt.Value().FindAttribute(TDataXtd_Presentation::GetID(), aPrsData)) {
91 TPrsStd_AISPresentation::Set (anIt.Value(), aPrsData->GetDriverGUID());
98 //=======================================================================
101 //=======================================================================
102 Standard_Boolean TPrsStd_AISViewer::Find (const TDF_Label& acces,
103 Handle(TPrsStd_AISViewer)& V)
105 return (acces.Root().FindAttribute(TPrsStd_AISViewer::GetID(),V));
108 //=======================================================================
111 //=======================================================================
112 Standard_Boolean TPrsStd_AISViewer::Find (const TDF_Label& acces,
113 Handle(AIS_InteractiveContext)& IC)
115 Handle(TPrsStd_AISViewer) V;
116 if (acces.Root().FindAttribute(TPrsStd_AISViewer::GetID(),V)) {
117 IC = V->GetInteractiveContext();
118 return Standard_True;
120 return Standard_False;
123 //=======================================================================
126 //=======================================================================
128 Standard_Boolean TPrsStd_AISViewer::Find (const TDF_Label& acces,
129 Handle(V3d_Viewer)& VIEW)
131 Handle(TPrsStd_AISViewer) V;
132 if (acces.Root().FindAttribute(TPrsStd_AISViewer::GetID(),V)) {
133 VIEW = V->GetInteractiveContext()->CurrentViewer();
134 return Standard_True;
136 return Standard_False;
139 //=======================================================================
142 //=======================================================================
143 Standard_Boolean TPrsStd_AISViewer::Has (const TDF_Label& acces)
145 return (acces.Root().IsAttribute(TPrsStd_AISViewer::GetID()));
148 //=======================================================================
151 //=======================================================================
152 void TPrsStd_AISViewer::Update (const TDF_Label& acces)
154 Handle(TPrsStd_AISViewer) viewer;
155 if (Find (acces,viewer)) viewer->Update();
159 //=======================================================================
160 //function : TPrsStd_AISViewer
162 //=======================================================================
164 TPrsStd_AISViewer::TPrsStd_AISViewer()
168 //=======================================================================
171 //=======================================================================
173 void TPrsStd_AISViewer::Update () const
175 myInteractiveContext->UpdateCurrentViewer();
178 //=======================================================================
179 //function : SetInteractiveContext
181 //=======================================================================
183 void TPrsStd_AISViewer::SetInteractiveContext(const Handle(AIS_InteractiveContext)& ctx)
185 myInteractiveContext = ctx;
188 //=======================================================================
189 //function : GetInteractiveContext
191 //=======================================================================
193 Handle(AIS_InteractiveContext) TPrsStd_AISViewer::GetInteractiveContext() const
195 return myInteractiveContext;
199 //=======================================================================
202 //=======================================================================
204 const Standard_GUID& TPrsStd_AISViewer::ID() const { return GetID(); }
207 //=======================================================================
210 //=======================================================================
212 void TPrsStd_AISViewer::Restore(const Handle(TDF_Attribute)&)
216 //=======================================================================
217 //function : NewEmpty
219 //=======================================================================
221 Handle(TDF_Attribute) TPrsStd_AISViewer::NewEmpty() const
223 return new TPrsStd_AISViewer();
226 //=======================================================================
229 //=======================================================================
231 void TPrsStd_AISViewer::Paste (const Handle(TDF_Attribute)&,
232 const Handle(TDF_RelocationTable)&) const