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)
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);
88 aCView->WS->Invalidate();
91 void OpenGl_GraphicDriver::EraseStructure (const Graphic3d_CView& theCView,
92 const Graphic3d_CStructure& theCStructure)
94 const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
95 OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
96 if (aCView == NULL || aStructure == NULL)
99 aCView->View->EraseStructure (aStructure);
100 aCView->WS->Invalidate();
103 void OpenGl_GraphicDriver::RemoveStructure (const Graphic3d_CStructure& theCStructure)
105 if (!GetMapOfStructures().IsBound (theCStructure.Id))
108 OpenGl_Structure* aStructure = OpenGl_GraphicDriver::GetMapOfStructures().Find (theCStructure.Id);
109 OpenGl_GraphicDriver::GetMapOfStructures().UnBind (theCStructure.Id);
111 InvalidateAllWorkspaces();
114 void OpenGl_GraphicDriver::Structure (Graphic3d_CStructure& theCStructure)
116 RemoveStructure (theCStructure);
118 OpenGl_Structure* aStructure = new OpenGl_Structure();
120 aStructure->SetDegenerateModel (theCStructure.ContextFillArea.DegenerationMode,
121 theCStructure.ContextFillArea.SkipRatio);
123 Standard_Integer aStatus = 0;
124 if (theCStructure.highlight) aStatus |= OPENGL_NS_HIGHLIGHT;
125 if (!theCStructure.visible) aStatus |= OPENGL_NS_HIDE;
126 aStructure->SetNamedStatus (aStatus);
128 theCStructure.ptrStructure = aStructure;
129 OpenGl_GraphicDriver::GetMapOfStructures().Bind (theCStructure.Id, aStructure);
130 InvalidateAllWorkspaces();
133 //=======================================================================
134 //function : ChangeZLayer
136 //=======================================================================
138 void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure,
139 const Standard_Integer theLayer)
141 if (!GetMapOfStructures().IsBound (theCStructure.Id))
144 OpenGl_Structure* aStructure =
145 OpenGl_GraphicDriver::GetMapOfStructures().Find (theCStructure.Id);
147 aStructure->SetZLayer (theLayer);
150 //=======================================================================
151 //function : ChangeZLayer
153 //=======================================================================
155 void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure,
156 const Graphic3d_CView& theCView,
157 const Standard_Integer theNewLayerId)
159 const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView;
161 if (!GetMapOfStructures().IsBound (theCStructure.Id) || !aCView)
164 OpenGl_Structure* aStructure =
165 OpenGl_GraphicDriver::GetMapOfStructures().Find (theCStructure.Id);
167 aCView->View->ChangeZLayer (aStructure, theNewLayerId);
170 //=======================================================================
171 //function : GetZLayer
173 //=======================================================================
175 Standard_Integer OpenGl_GraphicDriver::GetZLayer (const Graphic3d_CStructure& theCStructure) const
177 if (!GetMapOfStructures().IsBound (theCStructure.Id))
180 OpenGl_Structure* aStructure =
181 OpenGl_GraphicDriver::GetMapOfStructures().Find (theCStructure.Id);
183 return aStructure->GetZLayer();
186 //=======================================================================
187 //function : UnsetZLayer
189 //=======================================================================
191 void OpenGl_GraphicDriver::UnsetZLayer (const Standard_Integer theLayerId)
193 NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator
194 aStructIt (GetMapOfStructures ());
196 for( ; aStructIt.More (); aStructIt.Next ())
198 OpenGl_Structure* aStruct = aStructIt.ChangeValue ();
199 if (aStruct->GetZLayer () == theLayerId)
200 aStruct->SetZLayer (0);