Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-10-20 |
2 | // Created by: Sergey ZERCHANINOV | |
973c2be1 | 3 | // Copyright (c) 2011-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
973c2be1 | 7 | // This library is free software; you can redistribute it and / or modify it |
8 | // under the terms of the GNU Lesser General Public 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. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
7fd59977 | 15 | |
2166f0fa | 16 | #include <OpenGl_GraphicDriver.hxx> |
7fd59977 | 17 | |
2166f0fa SK |
18 | #include <NCollection_DataMap.hxx> |
19 | #include <OpenGl_Structure.hxx> | |
20 | #include <OpenGl_CView.hxx> | |
7fd59977 | 21 | |
2166f0fa SK |
22 | void OpenGl_GraphicDriver::ClearStructure (const Graphic3d_CStructure& theCStructure) |
23 | { | |
24 | OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure; | |
25 | if (aStructure == NULL) | |
26 | return; | |
7fd59977 | 27 | |
5e27df78 | 28 | aStructure->Clear (GetSharedContext()); |
2166f0fa | 29 | } |
7fd59977 | 30 | |
2166f0fa SK |
31 | void OpenGl_GraphicDriver::ContextStructure (const Graphic3d_CStructure& theCStructure) |
32 | { | |
33 | OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure; | |
34 | if (aStructure == NULL) | |
35 | return; | |
7fd59977 | 36 | |
2166f0fa | 37 | aStructure->SetTransformPersistence (theCStructure.TransformPersistence); |
7fd59977 | 38 | |
2166f0fa SK |
39 | if (theCStructure.ContextLine.IsDef) |
40 | aStructure->SetAspectLine (theCStructure.ContextLine); | |
7fd59977 | 41 | |
2166f0fa | 42 | if (theCStructure.ContextFillArea.IsDef) |
fd4a6963 | 43 | aStructure->SetAspectFace (theCStructure.ContextFillArea); |
7fd59977 | 44 | |
2166f0fa | 45 | if (theCStructure.ContextMarker.IsDef) |
fd4a6963 | 46 | aStructure->SetAspectMarker (theCStructure.ContextMarker); |
7fd59977 | 47 | |
2166f0fa SK |
48 | if (theCStructure.ContextText.IsDef) |
49 | aStructure->SetAspectText (theCStructure.ContextText); | |
7fd59977 | 50 | } |
51 | ||
2166f0fa SK |
52 | void OpenGl_GraphicDriver::Connect (const Graphic3d_CStructure& theFather, |
53 | const Graphic3d_CStructure& theSon) | |
54 | { | |
55 | OpenGl_Structure* aFather = (OpenGl_Structure* )theFather.ptrStructure; | |
56 | OpenGl_Structure* aSon = (OpenGl_Structure* )theSon.ptrStructure; | |
57 | if (aFather && aSon) | |
58 | aFather->Connect(aSon); | |
7fd59977 | 59 | } |
60 | ||
2166f0fa SK |
61 | void OpenGl_GraphicDriver::Disconnect (const Graphic3d_CStructure& theFather, |
62 | const Graphic3d_CStructure& theSon) | |
63 | { | |
64 | OpenGl_Structure* aFather = (OpenGl_Structure* )theFather.ptrStructure; | |
65 | OpenGl_Structure* aSon = (OpenGl_Structure* )theSon.ptrStructure; | |
66 | if (aFather && aSon) | |
67 | aFather->Disconnect(aSon); | |
7fd59977 | 68 | } |
69 | ||
2166f0fa SK |
70 | void OpenGl_GraphicDriver::DisplayStructure (const Graphic3d_CView& theCView, |
71 | const Graphic3d_CStructure& theCStructure, | |
72 | const Standard_Integer thePriority) | |
73 | { | |
74 | const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; | |
75 | OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure; | |
76 | if (aCView == NULL || aStructure == NULL) | |
77 | return; | |
78 | ||
79 | aCView->View->DisplayStructure (aStructure, thePriority); | |
7fd59977 | 80 | } |
81 | ||
2166f0fa SK |
82 | void OpenGl_GraphicDriver::EraseStructure (const Graphic3d_CView& theCView, |
83 | const Graphic3d_CStructure& theCStructure) | |
84 | { | |
85 | const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; | |
86 | OpenGl_Structure* aStructure = (OpenGl_Structure* )theCStructure.ptrStructure; | |
87 | if (aCView == NULL || aStructure == NULL) | |
88 | return; | |
7fd59977 | 89 | |
2166f0fa | 90 | aCView->View->EraseStructure (aStructure); |
7fd59977 | 91 | } |
92 | ||
2166f0fa SK |
93 | void OpenGl_GraphicDriver::RemoveStructure (const Graphic3d_CStructure& theCStructure) |
94 | { | |
5e27df78 | 95 | if (!myMapOfStructure.IsBound (theCStructure.Id)) |
2166f0fa | 96 | return; |
7fd59977 | 97 | |
5e27df78 | 98 | OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id); |
99 | myMapOfStructure.UnBind (theCStructure.Id); | |
eef7fc64 | 100 | Graphic3d_CStructure& aCStruct = const_cast<Graphic3d_CStructure&>(theCStructure); |
101 | aCStruct.ptrStructure = 0; | |
5e27df78 | 102 | OpenGl_Element::Destroy (GetSharedContext(), aStructure); |
7fd59977 | 103 | } |
104 | ||
2166f0fa SK |
105 | void OpenGl_GraphicDriver::Structure (Graphic3d_CStructure& theCStructure) |
106 | { | |
107 | RemoveStructure (theCStructure); | |
7fd59977 | 108 | |
2166f0fa | 109 | OpenGl_Structure* aStructure = new OpenGl_Structure(); |
7fd59977 | 110 | |
2166f0fa SK |
111 | Standard_Integer aStatus = 0; |
112 | if (theCStructure.highlight) aStatus |= OPENGL_NS_HIGHLIGHT; | |
113 | if (!theCStructure.visible) aStatus |= OPENGL_NS_HIDE; | |
2166f0fa | 114 | aStructure->SetNamedStatus (aStatus); |
7fd59977 | 115 | |
2166f0fa | 116 | theCStructure.ptrStructure = aStructure; |
5e27df78 | 117 | myMapOfStructure.Bind (theCStructure.Id, aStructure); |
7fd59977 | 118 | } |
59f45b7c | 119 | |
120 | //======================================================================= | |
121 | //function : ChangeZLayer | |
122 | //purpose : | |
123 | //======================================================================= | |
124 | ||
125 | void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure, | |
126 | const Standard_Integer theLayer) | |
127 | { | |
5e27df78 | 128 | if (!myMapOfStructure.IsBound (theCStructure.Id)) |
59f45b7c | 129 | return; |
130 | ||
5e27df78 | 131 | OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id); |
59f45b7c | 132 | |
133 | aStructure->SetZLayer (theLayer); | |
134 | } | |
135 | ||
136 | //======================================================================= | |
137 | //function : ChangeZLayer | |
138 | //purpose : | |
139 | //======================================================================= | |
140 | ||
141 | void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure, | |
142 | const Graphic3d_CView& theCView, | |
143 | const Standard_Integer theNewLayerId) | |
144 | { | |
145 | const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView; | |
146 | ||
5e27df78 | 147 | if (!myMapOfStructure.IsBound (theCStructure.Id) || !aCView) |
59f45b7c | 148 | return; |
149 | ||
5e27df78 | 150 | OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id); |
59f45b7c | 151 | |
152 | aCView->View->ChangeZLayer (aStructure, theNewLayerId); | |
153 | } | |
154 | ||
155 | //======================================================================= | |
156 | //function : GetZLayer | |
157 | //purpose : | |
158 | //======================================================================= | |
159 | ||
160 | Standard_Integer OpenGl_GraphicDriver::GetZLayer (const Graphic3d_CStructure& theCStructure) const | |
161 | { | |
5e27df78 | 162 | if (!myMapOfStructure.IsBound (theCStructure.Id)) |
59f45b7c | 163 | return -1; |
164 | ||
5e27df78 | 165 | OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id); |
59f45b7c | 166 | |
167 | return aStructure->GetZLayer(); | |
168 | } | |
169 | ||
170 | //======================================================================= | |
171 | //function : UnsetZLayer | |
172 | //purpose : | |
173 | //======================================================================= | |
174 | ||
175 | void OpenGl_GraphicDriver::UnsetZLayer (const Standard_Integer theLayerId) | |
176 | { | |
5e27df78 | 177 | NCollection_DataMap<Standard_Integer, OpenGl_Structure*>::Iterator aStructIt (myMapOfStructure); |
59f45b7c | 178 | for( ; aStructIt.More (); aStructIt.Next ()) |
179 | { | |
180 | OpenGl_Structure* aStruct = aStructIt.ChangeValue (); | |
181 | if (aStruct->GetZLayer () == theLayerId) | |
182 | aStruct->SetZLayer (0); | |
183 | } | |
184 | } |