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());
34 InvalidateAllWorkspaces();
37 void OpenGl_GraphicDriver::ContextStructure (const Graphic3d_CStructure& theCStructure)
39 OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
40 if (aStructure == NULL)
43 aStructure->SetTransformPersistence (theCStructure.TransformPersistence);
45 if (theCStructure.ContextLine.IsDef)
46 aStructure->SetAspectLine (theCStructure.ContextLine);
48 if (theCStructure.ContextFillArea.IsDef)
49 aStructure->SetAspectFace (theCStructure.ContextFillArea);
51 if (theCStructure.ContextMarker.IsDef)
52 aStructure->SetAspectMarker (theCStructure.ContextMarker);
54 if (theCStructure.ContextText.IsDef)
55 aStructure->SetAspectText (theCStructure.ContextText);
57 InvalidateAllWorkspaces();
60 void OpenGl_GraphicDriver::Connect (const Graphic3d_CStructure& theFather,
61 const Graphic3d_CStructure& theSon)
63 OpenGl_Structure* aFather = (OpenGl_Structure* )theFather.ptrStructure;
64 OpenGl_Structure* aSon = (OpenGl_Structure* )theSon.ptrStructure;
66 aFather->Connect(aSon);
69 void OpenGl_GraphicDriver::Disconnect (const Graphic3d_CStructure& theFather,
70 const Graphic3d_CStructure& theSon)
72 OpenGl_Structure* aFather = (OpenGl_Structure* )theFather.ptrStructure;
73 OpenGl_Structure* aSon = (OpenGl_Structure* )theSon.ptrStructure;
75 aFather->Disconnect(aSon);
78 void OpenGl_GraphicDriver::DisplayStructure (const Graphic3d_CView& theCView,
79 const Graphic3d_CStructure& theCStructure,
80 const Standard_Integer thePriority)
82 const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
83 OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
84 if (aCView == NULL || aStructure == NULL)
87 aCView->View->DisplayStructure (aStructure, thePriority);
90 void OpenGl_GraphicDriver::EraseStructure (const Graphic3d_CView& theCView,
91 const Graphic3d_CStructure& theCStructure)
93 const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
94 OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
95 if (aCView == NULL || aStructure == NULL)
98 aCView->View->EraseStructure (aStructure);
101 void OpenGl_GraphicDriver::RemoveStructure (const Graphic3d_CStructure& theCStructure)
103 if (!myMapOfStructure.IsBound (theCStructure.Id))
106 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
107 myMapOfStructure.UnBind (theCStructure.Id);
108 OpenGl_Element::Destroy (GetSharedContext(), aStructure);
109 InvalidateAllWorkspaces();
112 void OpenGl_GraphicDriver::Structure (Graphic3d_CStructure& theCStructure)
114 RemoveStructure (theCStructure);
116 OpenGl_Structure* aStructure = new OpenGl_Structure();
118 aStructure->SetDegenerateModel (theCStructure.ContextFillArea.DegenerationMode,
119 theCStructure.ContextFillArea.SkipRatio);
121 Standard_Integer aStatus = 0;
122 if (theCStructure.highlight) aStatus |= OPENGL_NS_HIGHLIGHT;
123 if (!theCStructure.visible) aStatus |= OPENGL_NS_HIDE;
124 aStructure->SetNamedStatus (aStatus);
126 theCStructure.ptrStructure = aStructure;
127 myMapOfStructure.Bind (theCStructure.Id, aStructure);
128 InvalidateAllWorkspaces();
131 //=======================================================================
132 //function : ChangeZLayer
134 //=======================================================================
136 void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure,
137 const Standard_Integer theLayer)
139 if (!myMapOfStructure.IsBound (theCStructure.Id))
142 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
144 aStructure->SetZLayer (theLayer);
147 //=======================================================================
148 //function : ChangeZLayer
150 //=======================================================================
152 void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure,
153 const Graphic3d_CView& theCView,
154 const Standard_Integer theNewLayerId)
156 const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView;
158 if (!myMapOfStructure.IsBound (theCStructure.Id) || !aCView)
161 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
163 aCView->View->ChangeZLayer (aStructure, theNewLayerId);
166 //=======================================================================
167 //function : GetZLayer
169 //=======================================================================
171 Standard_Integer OpenGl_GraphicDriver::GetZLayer (const Graphic3d_CStructure& theCStructure) const
173 if (!myMapOfStructure.IsBound (theCStructure.Id))
176 OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id);
178 return aStructure->GetZLayer();
181 //=======================================================================
182 //function : UnsetZLayer
184 //=======================================================================
186 void OpenGl_GraphicDriver::UnsetZLayer (const Standard_Integer theLayerId)
188 NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator aStructIt (myMapOfStructure);
189 for( ; aStructIt.More (); aStructIt.Next ())
191 OpenGl_Structure* aStruct = aStructIt.ChangeValue ();
192 if (aStruct->GetZLayer () == theLayerId)
193 aStruct->SetZLayer (0);