b311480e |
1 | // Created by: NW,JPB,CAL |
2 | // Copyright (c) 1991-1999 Matra Datavision |
973c2be1 |
3 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
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 | |
7fd59977 |
16 | //-Version |
81bba717 |
17 | //-Design Declaration of variables specific to managers |
81bba717 |
18 | //-Warning Manager manages a set of structures |
7fd59977 |
19 | //-References |
7fd59977 |
20 | //-Language C++ 2.0 |
7fd59977 |
21 | //-Declarations |
7fd59977 |
22 | // for the class |
42cf5bc1 |
23 | |
24 | #include <Graphic3d_AspectFillArea3d.hxx> |
25 | #include <Graphic3d_AspectLine3d.hxx> |
26 | #include <Graphic3d_AspectMarker3d.hxx> |
27 | #include <Graphic3d_AspectText3d.hxx> |
28 | #include <Graphic3d_DataStructureManager.hxx> |
29 | #include <Graphic3d_GraphicDriver.hxx> |
30 | #include <Graphic3d_InitialisationError.hxx> |
31 | #include <Graphic3d_Structure.hxx> |
32 | #include <Graphic3d_StructureManager.hxx> |
19286d7c |
33 | #include "Graphic3d_StructureManager.pxx" |
42cf5bc1 |
34 | #include <Standard_Transient.hxx> |
35 | #include <Standard_Type.hxx> |
36 | |
7fd59977 |
37 | static Standard_Boolean Initialisation = Standard_True; |
38 | static int StructureManager_ArrayId[StructureManager_MAX]; |
39 | static Standard_Integer StructureManager_CurrentId = 0; |
40 | |
19286d7c |
41 | #include "Graphic3d_Structure.pxx" |
7fd59977 |
42 | #include <Graphic3d_MapIteratorOfMapOfStructure.hxx> |
43 | |
a1954302 |
44 | Graphic3d_StructureManager::Graphic3d_StructureManager (const Handle(Graphic3d_GraphicDriver)& theDriver) |
45 | { |
7fd59977 |
46 | |
47 | Standard_Real Coef; |
48 | Standard_Integer i; |
49 | Standard_Boolean NotFound = Standard_True; |
50 | Standard_Integer Limit = Graphic3d_StructureManager::Limit (); |
51 | |
52 | /* Initialize PHIGS and start up */ |
53 | if (Initialisation) { |
54 | |
55 | Initialisation = Standard_False; |
81bba717 |
56 | /* table to manage IDs of StructureManager */ |
f163f612 |
57 | for (i=0; i<Limit; i++) StructureManager_ArrayId[i] = 0; |
7fd59977 |
58 | |
f163f612 |
59 | StructureManager_CurrentId = 0; |
60 | StructureManager_ArrayId[0] = 1; |
7fd59977 |
61 | |
62 | } |
63 | else { |
f163f612 |
64 | for (i=0; i<Limit && NotFound; i++) |
7fd59977 |
65 | if (StructureManager_ArrayId[i] == 0) { |
66 | NotFound = Standard_False; |
67 | StructureManager_CurrentId = i; |
68 | StructureManager_ArrayId[i] = 1; |
69 | } |
70 | |
71 | if (NotFound) |
f163f612 |
72 | { |
73 | Standard_SStream anErrorDescription; |
74 | anErrorDescription<<"You are trying to create too many ViewManagers at the same time!\n"<< |
75 | "The number of simultaneously created ViewManagers can't exceed "<<Limit<<".\n"; |
76 | Graphic3d_InitialisationError::Raise(anErrorDescription); |
77 | } |
7fd59977 |
78 | } |
79 | |
80 | Coef = (Structure_IDMIN+Structure_IDMAX)/Limit; |
81 | Aspect_GenId theGenId( |
f163f612 |
82 | Standard_Integer (Structure_IDMIN+Coef*(StructureManager_CurrentId)), |
83 | Standard_Integer (Structure_IDMIN+Coef*(StructureManager_CurrentId+1)-1)); |
7fd59977 |
84 | MyStructGenId = theGenId; |
85 | |
86 | MyId = StructureManager_CurrentId; |
87 | |
88 | MyAspectLine3d = new Graphic3d_AspectLine3d (); |
89 | MyAspectText3d = new Graphic3d_AspectText3d (); |
90 | MyAspectMarker3d = new Graphic3d_AspectMarker3d (); |
91 | MyAspectFillArea3d = new Graphic3d_AspectFillArea3d (); |
92 | |
93 | MyUpdateMode = Aspect_TOU_WAIT; |
dc3fe572 |
94 | MyGraphicDriver = theDriver; |
7fd59977 |
95 | |
96 | } |
97 | |
98 | //-Destructors |
99 | |
100 | void Graphic3d_StructureManager::Destroy () { |
101 | |
7fd59977 |
102 | MyDisplayedStructure.Clear (); |
103 | MyHighlightedStructure.Clear (); |
7fd59977 |
104 | StructureManager_ArrayId[MyId] = 0; |
105 | |
106 | } |
107 | |
108 | //-Methods, in order |
109 | |
110 | void Graphic3d_StructureManager::SetUpdateMode (const Aspect_TypeOfUpdate AType) { |
111 | |
112 | MyUpdateMode = AType; |
113 | |
114 | } |
115 | |
116 | Aspect_TypeOfUpdate Graphic3d_StructureManager::UpdateMode () const { |
117 | |
118 | return (MyUpdateMode); |
119 | |
120 | } |
121 | |
122 | void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTX) { |
123 | |
124 | MyAspectLine3d = CTX; |
125 | |
126 | } |
127 | |
128 | void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX) { |
129 | |
130 | MyAspectFillArea3d = CTX; |
131 | |
132 | } |
133 | |
134 | void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& CTX) { |
135 | |
136 | MyAspectText3d = CTX; |
137 | |
138 | } |
139 | |
140 | void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& CTX) { |
141 | |
142 | MyAspectMarker3d = CTX; |
143 | |
144 | } |
145 | |
146 | void Graphic3d_StructureManager::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& CTXL, Handle(Graphic3d_AspectText3d)& CTXT, Handle(Graphic3d_AspectMarker3d)& CTXM, Handle(Graphic3d_AspectFillArea3d)& CTXF) const { |
147 | |
148 | CTXL = MyAspectLine3d; |
149 | CTXT = MyAspectText3d; |
150 | CTXM = MyAspectMarker3d; |
151 | CTXF = MyAspectFillArea3d; |
152 | |
153 | } |
154 | |
155 | Handle(Graphic3d_AspectLine3d) Graphic3d_StructureManager::Line3dAspect () const { |
156 | |
157 | return (MyAspectLine3d); |
158 | |
159 | } |
160 | |
161 | Handle(Graphic3d_AspectText3d) Graphic3d_StructureManager::Text3dAspect () const { |
162 | |
163 | return (MyAspectText3d); |
164 | |
165 | } |
166 | |
167 | Handle(Graphic3d_AspectMarker3d) Graphic3d_StructureManager::Marker3dAspect () const { |
168 | |
169 | return (MyAspectMarker3d); |
170 | |
171 | } |
172 | |
173 | Handle(Graphic3d_AspectFillArea3d) Graphic3d_StructureManager::FillArea3dAspect () const { |
174 | |
175 | return (MyAspectFillArea3d); |
176 | |
177 | } |
178 | |
179 | void Graphic3d_StructureManager::Remove (const Standard_Integer AnId) { |
180 | |
7fd59977 |
181 | MyStructGenId.Free (AnId); |
182 | |
183 | } |
184 | |
7fd59977 |
185 | void Graphic3d_StructureManager::DisplayedStructures (Graphic3d_MapOfStructure& SG) const { |
186 | |
187 | SG.Assign(MyDisplayedStructure); |
188 | |
189 | //JMBStandard_Integer Length = MyDisplayedStructure.Length (); |
190 | |
191 | //JMBfor (Standard_Integer i=1; i<=Length; i++) |
192 | //JMB SG.Add (MyDisplayedStructure.Value (i)); |
193 | |
194 | } |
195 | |
196 | Standard_Integer Graphic3d_StructureManager::NumberOfDisplayedStructures () const { |
197 | |
198 | Standard_Integer Length = MyDisplayedStructure.Extent (); |
199 | |
200 | return (Length); |
201 | |
202 | } |
203 | |
204 | //Handle(Graphic3d_Structure) Graphic3d_StructureManager::DisplayedStructure (const Standard_Integer AnIndex) const { |
205 | |
206 | //return (MyDisplayedStructure.Value (AnIndex)); |
207 | |
208 | //} |
209 | |
210 | void Graphic3d_StructureManager::HighlightedStructures (Graphic3d_MapOfStructure& SG) const { |
211 | |
212 | SG.Assign(MyHighlightedStructure); |
213 | |
214 | } |
215 | |
7fd59977 |
216 | Standard_Integer Graphic3d_StructureManager::NewIdentification () { |
217 | |
218 | Standard_Integer Id = MyStructGenId.Next (); |
219 | |
7fd59977 |
220 | return Id; |
221 | |
222 | } |
223 | |
224 | Handle(Graphic3d_Structure) Graphic3d_StructureManager::Identification (const Standard_Integer AId) const { |
225 | |
226 | // Standard_Integer ind=0; |
227 | Standard_Boolean notfound = Standard_True; |
228 | |
229 | Handle(Graphic3d_Structure) StructNull; |
230 | |
231 | Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure); |
232 | |
233 | Handle(Graphic3d_Structure) SGfound; |
234 | |
235 | for (; it.More() && notfound; it.Next()) { |
236 | Handle(Graphic3d_Structure) SG = it.Key(); |
237 | if ( SG->Identification () == AId) { |
238 | notfound = Standard_False; |
239 | SGfound = SG; |
240 | } |
241 | } |
242 | |
243 | |
244 | if (notfound) |
245 | return (StructNull); |
246 | else |
247 | return (SGfound); |
248 | |
249 | } |
250 | |
251 | Standard_Integer Graphic3d_StructureManager::Identification () const { |
252 | |
253 | return (MyId); |
254 | |
255 | } |
256 | |
257 | Standard_Integer Graphic3d_StructureManager::Limit () { |
258 | |
259 | return (StructureManager_MAX); |
260 | |
261 | } |
262 | |
263 | Standard_Integer Graphic3d_StructureManager::CurrentId () { |
264 | |
265 | return (StructureManager_CurrentId); |
266 | |
267 | } |
268 | |
dc3fe572 |
269 | const Handle(Graphic3d_GraphicDriver)& Graphic3d_StructureManager::GraphicDriver () const { |
7fd59977 |
270 | |
dc3fe572 |
271 | return (MyGraphicDriver); |
7fd59977 |
272 | |
273 | } |
eb4320f2 |
274 | |
8bb96a97 |
275 | void Graphic3d_StructureManager::RecomputeStructures() |
eb4320f2 |
276 | { |
8bb96a97 |
277 | // Go through all unique structures including child (connected) ones and ensure that they are computed. |
278 | Graphic3d_MapOfStructure aStructNetwork; |
279 | |
eb4320f2 |
280 | for (Graphic3d_MapIteratorOfMapOfStructure anIter(MyDisplayedStructure); anIter.More(); anIter.Next()) |
281 | { |
282 | Handle(Graphic3d_Structure) aStructure = anIter.Key(); |
8bb96a97 |
283 | anIter.Key()->Network (anIter.Key(), Graphic3d_TOC_DESCENDANT, aStructNetwork); |
284 | } |
285 | |
286 | RecomputeStructures (aStructNetwork); |
287 | } |
eb4320f2 |
288 | |
8bb96a97 |
289 | void Graphic3d_StructureManager::RecomputeStructures (const Graphic3d_MapOfStructure& theStructures) |
290 | { |
291 | for (Graphic3d_MapIteratorOfMapOfStructure anIter (theStructures); anIter.More(); anIter.Next()) |
292 | { |
293 | Handle(Graphic3d_Structure) aStruct = anIter.Key(); |
294 | aStruct->Clear(); |
295 | aStruct->Compute(); |
eb4320f2 |
296 | } |
297 | } |
a272ed94 |
298 | |
299 | Handle(Graphic3d_ViewAffinity) Graphic3d_StructureManager::RegisterObject (const Handle(Standard_Transient)& theObject) |
300 | { |
301 | Handle(Graphic3d_ViewAffinity) aResult; |
302 | if (myRegisteredObjects.Find (theObject.operator->(), aResult)) |
303 | { |
304 | return aResult; |
305 | } |
306 | |
307 | aResult = new Graphic3d_ViewAffinity(); |
308 | myRegisteredObjects.Bind (theObject.operator->(), aResult); |
309 | return aResult; |
310 | } |
311 | |
312 | void Graphic3d_StructureManager::UnregisterObject (const Handle(Standard_Transient)& theObject) |
313 | { |
314 | myRegisteredObjects.UnBind (theObject.operator->()); |
315 | } |
316 | |
317 | Handle(Graphic3d_ViewAffinity) Graphic3d_StructureManager::ObjectAffinity (const Handle(Standard_Transient)& theObject) const |
318 | { |
319 | Handle(Graphic3d_ViewAffinity) aResult; |
320 | myRegisteredObjects.Find (theObject.operator->(), aResult); |
321 | return aResult; |
322 | } |