1 // Created on: 2011-10-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <OpenGl_GraphicDriver.hxx>
23 #include <NCollection_DataMap.hxx>
24 #include <OpenGl_Structure.hxx>
25 #include <OpenGl_CView.hxx>
27 void OpenGl_GraphicDriver::ClearStructure (const Graphic3d_CStructure& theCStructure)
29 OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
30 if (aStructure == NULL)
33 aStructure->Clear (GetSharedContext());
36 void OpenGl_GraphicDriver::ContextStructure (const Graphic3d_CStructure& theCStructure)
38 OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
39 if (aStructure == NULL)
42 aStructure->SetTransformPersistence (theCStructure.TransformPersistence);
44 if (theCStructure.ContextLine.IsDef)
45 aStructure->SetAspectLine (theCStructure.ContextLine);
47 if (theCStructure.ContextFillArea.IsDef)
48 aStructure->SetAspectFace (GetSharedContext(), theCStructure.ContextFillArea);
50 if (theCStructure.ContextMarker.IsDef)
51 aStructure->SetAspectMarker (theCStructure.ContextMarker);
53 if (theCStructure.ContextText.IsDef)
54 aStructure->SetAspectText (theCStructure.ContextText);
57 void OpenGl_GraphicDriver::Connect (const Graphic3d_CStructure& theFather,
58 const Graphic3d_CStructure& theSon)
60 OpenGl_Structure* aFather = (OpenGl_Structure* )theFather.ptrStructure;
61 OpenGl_Structure* aSon = (OpenGl_Structure* )theSon.ptrStructure;
63 aFather->Connect(aSon);
66 void OpenGl_GraphicDriver::Disconnect (const Graphic3d_CStructure& theFather,
67 const Graphic3d_CStructure& theSon)
69 OpenGl_Structure* aFather = (OpenGl_Structure* )theFather.ptrStructure;
70 OpenGl_Structure* aSon = (OpenGl_Structure* )theSon.ptrStructure;
72 aFather->Disconnect(aSon);
75 void OpenGl_GraphicDriver::DisplayStructure (const Graphic3d_CView& theCView,
76 const Graphic3d_CStructure& theCStructure,
77 const Standard_Integer thePriority)
79 const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
80 OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
81 if (aCView == NULL || aStructure == NULL)
84 aCView->View->DisplayStructure (aStructure, thePriority);
87 void OpenGl_GraphicDriver::EraseStructure (const Graphic3d_CView& theCView,
88 const Graphic3d_CStructure& theCStructure)
90 const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
91 OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
92 if (aCView == NULL || aStructure == NULL)
95 aCView->View->EraseStructure (aStructure);
98 void OpenGl_GraphicDriver::RemoveStructure (const Graphic3d_CStructure& theCStructure)
100 if (!myMapOfStructure.IsBound (theCStructure.Id))
103 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
104 myMapOfStructure.UnBind (theCStructure.Id);
105 OpenGl_Element::Destroy (GetSharedContext(), aStructure);
108 void OpenGl_GraphicDriver::Structure (Graphic3d_CStructure& theCStructure)
110 RemoveStructure (theCStructure);
112 OpenGl_Structure* aStructure = new OpenGl_Structure();
114 Standard_Integer aStatus = 0;
115 if (theCStructure.highlight) aStatus |= OPENGL_NS_HIGHLIGHT;
116 if (!theCStructure.visible) aStatus |= OPENGL_NS_HIDE;
117 aStructure->SetNamedStatus (aStatus);
119 theCStructure.ptrStructure = aStructure;
120 myMapOfStructure.Bind (theCStructure.Id, aStructure);
123 //=======================================================================
124 //function : ChangeZLayer
126 //=======================================================================
128 void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure,
129 const Standard_Integer theLayer)
131 if (!myMapOfStructure.IsBound (theCStructure.Id))
134 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
136 aStructure->SetZLayer (theLayer);
139 //=======================================================================
140 //function : ChangeZLayer
142 //=======================================================================
144 void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure,
145 const Graphic3d_CView& theCView,
146 const Standard_Integer theNewLayerId)
148 const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView;
150 if (!myMapOfStructure.IsBound (theCStructure.Id) || !aCView)
153 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
155 aCView->View->ChangeZLayer (aStructure, theNewLayerId);
158 //=======================================================================
159 //function : GetZLayer
161 //=======================================================================
163 Standard_Integer OpenGl_GraphicDriver::GetZLayer (const Graphic3d_CStructure& theCStructure) const
165 if (!myMapOfStructure.IsBound (theCStructure.Id))
168 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
170 return aStructure->GetZLayer();
173 //=======================================================================
174 //function : UnsetZLayer
176 //=======================================================================
178 void OpenGl_GraphicDriver::UnsetZLayer (const Standard_Integer theLayerId)
180 NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator aStructIt (myMapOfStructure);
181 for( ; aStructIt.More (); aStructIt.Next ())
183 OpenGl_Structure* aStruct = aStructIt.ChangeValue ();
184 if (aStruct->GetZLayer () == theLayerId)
185 aStruct->SetZLayer (0);