1 // File: OpenGl_GraphicDriver_4.cxx
2 // Created: 20 October 2011
3 // Author: Sergey ZERCHANINOV
4 // Copyright: OPEN CASCADE 2011
6 #include <OpenGl_GraphicDriver.hxx>
8 #include <NCollection_DataMap.hxx>
9 #include <OpenGl_Structure.hxx>
10 #include <OpenGl_CView.hxx>
12 void OpenGl_GraphicDriver::ClearStructure (const Graphic3d_CStructure& theCStructure)
14 OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
15 if (aStructure == NULL)
19 InvalidateAllWorkspaces();
22 void OpenGl_GraphicDriver::ContextStructure (const Graphic3d_CStructure& theCStructure)
24 OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
25 if (aStructure == NULL)
28 aStructure->SetTransformPersistence (theCStructure.TransformPersistence);
30 if (theCStructure.ContextLine.IsDef)
31 aStructure->SetAspectLine (theCStructure.ContextLine);
33 if (theCStructure.ContextFillArea.IsDef)
34 aStructure->SetAspectFace (theCStructure.ContextFillArea);
36 if (theCStructure.ContextMarker.IsDef)
37 aStructure->SetAspectMarker (theCStructure.ContextMarker);
39 if (theCStructure.ContextText.IsDef)
40 aStructure->SetAspectText (theCStructure.ContextText);
42 InvalidateAllWorkspaces();
45 void OpenGl_GraphicDriver::Connect (const Graphic3d_CStructure& theFather,
46 const Graphic3d_CStructure& theSon)
48 OpenGl_Structure* aFather = (OpenGl_Structure* )theFather.ptrStructure;
49 OpenGl_Structure* aSon = (OpenGl_Structure* )theSon.ptrStructure;
51 aFather->Connect(aSon);
54 void OpenGl_GraphicDriver::Disconnect (const Graphic3d_CStructure& theFather,
55 const Graphic3d_CStructure& theSon)
57 OpenGl_Structure* aFather = (OpenGl_Structure* )theFather.ptrStructure;
58 OpenGl_Structure* aSon = (OpenGl_Structure* )theSon.ptrStructure;
60 aFather->Disconnect(aSon);
63 void OpenGl_GraphicDriver::DisplayStructure (const Graphic3d_CView& theCView,
64 const Graphic3d_CStructure& theCStructure,
65 const Standard_Integer thePriority)
67 const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView;
68 OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure;
69 if (aCView == NULL || aStructure == NULL)
72 aCView->View->DisplayStructure (aStructure, thePriority);
73 aCView->WS->Invalidate();
76 void OpenGl_GraphicDriver::EraseStructure (const Graphic3d_CView& theCView,
77 const Graphic3d_CStructure& theCStructure)
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->EraseStructure (aStructure);
85 aCView->WS->Invalidate();
88 void OpenGl_GraphicDriver::RemoveStructure (const Graphic3d_CStructure& theCStructure)
90 if (!GetMapOfStructures().IsBound (theCStructure.Id))
93 OpenGl_Structure* aStructure = OpenGl_GraphicDriver::GetMapOfStructures().Find (theCStructure.Id);
94 OpenGl_GraphicDriver::GetMapOfStructures().UnBind (theCStructure.Id);
96 InvalidateAllWorkspaces();
99 void OpenGl_GraphicDriver::Structure (Graphic3d_CStructure& theCStructure)
101 RemoveStructure (theCStructure);
103 OpenGl_Structure* aStructure = new OpenGl_Structure();
105 aStructure->SetDegenerateModel (theCStructure.ContextFillArea.DegenerationMode,
106 theCStructure.ContextFillArea.SkipRatio);
108 Standard_Integer aStatus = 0;
109 if (theCStructure.highlight) aStatus |= OPENGL_NS_HIGHLIGHT;
110 if (!theCStructure.visible) aStatus |= OPENGL_NS_HIDE;
111 aStructure->SetNamedStatus (aStatus);
113 theCStructure.ptrStructure = aStructure;
114 OpenGl_GraphicDriver::GetMapOfStructures().Bind (theCStructure.Id, aStructure);
115 InvalidateAllWorkspaces();
118 //=======================================================================
119 //function : ChangeZLayer
121 //=======================================================================
123 void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure,
124 const Standard_Integer theLayer)
126 if (!GetMapOfStructures().IsBound (theCStructure.Id))
129 OpenGl_Structure* aStructure =
130 OpenGl_GraphicDriver::GetMapOfStructures().Find (theCStructure.Id);
132 aStructure->SetZLayer (theLayer);
135 //=======================================================================
136 //function : ChangeZLayer
138 //=======================================================================
140 void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure,
141 const Graphic3d_CView& theCView,
142 const Standard_Integer theNewLayerId)
144 const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView;
146 if (!GetMapOfStructures().IsBound (theCStructure.Id) || !aCView)
149 OpenGl_Structure* aStructure =
150 OpenGl_GraphicDriver::GetMapOfStructures().Find (theCStructure.Id);
152 aCView->View->ChangeZLayer (aStructure, theNewLayerId);
155 //=======================================================================
156 //function : GetZLayer
158 //=======================================================================
160 Standard_Integer OpenGl_GraphicDriver::GetZLayer (const Graphic3d_CStructure& theCStructure) const
162 if (!GetMapOfStructures().IsBound (theCStructure.Id))
165 OpenGl_Structure* aStructure =
166 OpenGl_GraphicDriver::GetMapOfStructures().Find (theCStructure.Id);
168 return aStructure->GetZLayer();
171 //=======================================================================
172 //function : UnsetZLayer
174 //=======================================================================
176 void OpenGl_GraphicDriver::UnsetZLayer (const Standard_Integer theLayerId)
178 NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator
179 aStructIt (GetMapOfStructures ());
181 for( ; aStructIt.More (); aStructIt.Next ())
183 OpenGl_Structure* aStruct = aStructIt.ChangeValue ();
184 if (aStruct->GetZLayer () == theLayerId)
185 aStruct->SetZLayer (0);