1 // Created on: 2011-10-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <OpenGl_GraphicDriver.hxx>
18 #include <NCollection_DataMap.hxx>
19 #include <OpenGl_Structure.hxx>
20 #include <OpenGl_CView.hxx>
22 void OpenGl_GraphicDriver::DisplayStructure (const Graphic3d_CView& theCView,
23 Graphic3d_CStructure& theCStructure,
24 const Standard_Integer thePriority)
26 const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
27 OpenGl_Structure* aStructure = (OpenGl_Structure* )&theCStructure;
31 aCView->View->DisplayStructure (aStructure, thePriority);
34 void OpenGl_GraphicDriver::EraseStructure (const Graphic3d_CView& theCView,
35 Graphic3d_CStructure& theCStructure)
37 const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
38 OpenGl_Structure* aStructure = (OpenGl_Structure* )&theCStructure;
39 if (aCView == NULL || aStructure == NULL)
42 aCView->View->EraseStructure (aStructure);
45 void OpenGl_GraphicDriver::RemoveStructure (Handle(Graphic3d_CStructure)& theCStructure)
47 OpenGl_Structure* aStructure = NULL;
48 if (!myMapOfStructure.Find (theCStructure->Id, aStructure))
53 myMapOfStructure.UnBind (theCStructure->Id);
54 aStructure->Release (GetSharedContext());
55 theCStructure.Nullify();
58 Handle(Graphic3d_CStructure) OpenGl_GraphicDriver::Structure (const Handle(Graphic3d_StructureManager)& theManager)
60 Handle(OpenGl_Structure) aStructure = new OpenGl_Structure (theManager);
61 myMapOfStructure.Bind (aStructure->Id, aStructure.operator->());
65 //=======================================================================
66 //function : ChangeZLayer
68 //=======================================================================
70 void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure,
71 const Standard_Integer theLayer)
73 if (!myMapOfStructure.IsBound (theCStructure.Id))
76 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
78 aStructure->SetZLayer (theLayer);
81 //=======================================================================
82 //function : ChangeZLayer
84 //=======================================================================
86 void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure,
87 const Graphic3d_CView& theCView,
88 const Standard_Integer theNewLayerId)
90 const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView;
92 if (!myMapOfStructure.IsBound (theCStructure.Id) || !aCView)
95 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
97 aCView->View->ChangeZLayer (aStructure, theNewLayerId);
100 //=======================================================================
101 //function : GetZLayer
103 //=======================================================================
105 Standard_Integer OpenGl_GraphicDriver::GetZLayer (const Graphic3d_CStructure& theCStructure) const
107 if (!myMapOfStructure.IsBound (theCStructure.Id))
110 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
112 return aStructure->GetZLayer();
115 //=======================================================================
116 //function : UnsetZLayer
118 //=======================================================================
120 void OpenGl_GraphicDriver::UnsetZLayer (const Standard_Integer theLayerId)
122 NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator aStructIt (myMapOfStructure);
123 for( ; aStructIt.More (); aStructIt.Next ())
125 OpenGl_Structure* aStruct = aStructIt.ChangeValue ();
126 if (aStruct->GetZLayer () == theLayerId)
127 aStruct->SetZLayer (0);
131 //=======================================================================
132 //function : ChangePriority
134 //=======================================================================
135 void OpenGl_GraphicDriver::ChangePriority (const Graphic3d_CStructure& theCStructure,
136 const Graphic3d_CView& theCView,
137 const Standard_Integer theNewPriority)
139 const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView;
141 if (!myMapOfStructure.IsBound (theCStructure.Id) || !aCView)
144 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
146 aCView->View->ChangePriority (aStructure, theNewPriority);