Commit | Line | Data |
---|---|---|
b311480e | 1 | // Copyright (c) 1995-1999 Matra Datavision |
2 | // Copyright (c) 1999-2012 OPEN CASCADE SAS | |
3 | // | |
4 | // The content of this file is subject to the Open CASCADE Technology Public | |
5 | // License Version 6.5 (the "License"). You may not use the content of this file | |
6 | // except in compliance with the License. Please obtain a copy of the License | |
7 | // at http://www.opencascade.org and read it completely before using this file. | |
8 | // | |
9 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
10 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
11 | // | |
12 | // The Original Code and all software distributed under the License is | |
13 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
14 | // Initial Developer hereby disclaims all such warranties, including without | |
15 | // limitation, any warranties of merchantability, fitness for a particular | |
16 | // purpose or non-infringement. Please see the License for the specific terms | |
17 | // and conditions governing the rights and limitations under the License. | |
18 | ||
7fd59977 | 19 | /*********************************************************************** |
20 | ||
21 | FONCTION : | |
22 | ---------- | |
23 | Classe Visual3d_View.cxx : | |
24 | ||
25 | ||
81bba717 | 26 | Declaration of variables specific to views. |
7fd59977 | 27 | |
81bba717 | 28 | A view is defined by : |
29 | - ViewManager | |
30 | - ContextView | |
31 | - ViewMapping | |
32 | - ViewOrientation | |
7fd59977 | 33 | |
34 | HISTORIQUE DES MODIFICATIONS : | |
35 | -------------------------------- | |
36 | Mars 1992 : NW,JPB,CAL ; Creation. | |
37 | 04-02-97 : FMN ; Suppression de PSOutput, XWDOutput ... | |
38 | 22-04-97 : CAL ; Ajout du Plot. | |
39 | 03-06-97 : FMN ; Correction calcul SetRatio | |
40 | 06-05-97 : CAL ; Ajout du Clear sur les TOS_COMPUTED. | |
41 | 28-07-97 : PCT ; Ajout lumiere frontale headlight. | |
42 | 19-09-97 : CAL ; Remplacement de Window->Position par Window->Size; | |
43 | 17-10-97 : CAL ; Le Projects nouveau est arrive. (NewProjects) | |
44 | 24-10-97 : CAL ; Retrait de DownCast. | |
45 | 24-10-97 : CAL ; Retrait des DataStructure (Vieille maquette inutilisee). | |
46 | 17-11-97 : FMN ; Ajout DoResize dans Resized() | |
47 | 20-11-97 : CAL ; Disparition de la dependance avec math | |
48 | ??-11-97 : CAL ; Retrait de la dependance avec math. Calcul developpe. | |
49 | ??-11-97 : CAL ; Ajout de NumberOfDisplayedStructures | |
50 | 07-08-97 : PCT ; ajout support texture mapping | |
7fd59977 | 51 | 15-01-98 : FMN ; FRA60019 calcul Ratio pour MyViewMappingReset |
52 | 15-01-98 : CAL ; Ajout de la transformation d'une TOS_COMPUTED | |
53 | 26-01-98 : CAL ; Ajout de la methode HaveTheSameOwner | |
54 | 06-02-98 : FMN ; CTS19079: TOP TEN: Probleme de highlight dans EDesigner. | |
55 | 05-03-98 : CAL ; GraphicTransform que si Trsf non invalidante | |
56 | 27-03-98 : CAL ; Ajout de TheStructure = devant Compute (...) !!!! | |
57 | 16-04-98 : CAL ; Remise a ID de la Trsf sur la COMPUTED | |
58 | 20-05-98 : CAL ; Perfs. Connection entre structures COMPUTED. | |
59 | 24-06-98 : CAL ; PRO14526 SetTransparency sur une vue non active. | |
60 | 17-07-98 : CAL ; PRO14872 test sur aTrsf dans ::SetTransform. | |
61 | 16-09-98 : BGN ; Points d'entree du Triedre (S3819, Phase 1) | |
62 | 22-09-98 : BGN ; S3989 (anciennement S3819) | |
63 | TypeOfTriedron* from Aspect (pas Visual3d) | |
64 | 06-10-98 : CAL ; Ajout d'un TIMER si CSF_GraphicTimer est definie. | |
65 | 16-10-98 : CAL ; Ajout d'un TIMER si CSF_GraphicTimer est definie. | |
66 | 02-11-98 : CAL ; Retrait de OSD::SetSignal. | |
67 | 18-11-98 : FMN ; Correction sur la gestion de la perspective | |
68 | 02-12-98 : CAL ; S4062. Ajout des layers. | |
69 | 13-09-99 : GG ; GER61454 Adds LightLimit() and PlaneLimit() methods | |
70 | 10-11-99 : GG ; PRO19603 Add Redraw( area ) method | |
71 | 14-01-00 : GG ; IMP140100 Add ViewManager( ) method | |
72 | 22-10-01 : SAV ; Added EnableDepthTest() method. | |
73 | 30-04-02 : JMB ; MyDisplayStructure : use a Map instead of a Set (very bad performance | |
74 | in data access when a lot of objects are used) | |
75 | Will improve performance of selection mechanisms | |
76 | ||
77 | ************************************************************************/ | |
78 | ||
79 | #define BUC60572 //GG_03-08-99 Add protection on Zclipping & Zcueing planes | |
80 | // positions. | |
81 | ||
7fd59977 | 82 | #define GER61454 //GG 14-09-99 Activates model clipping planes |
83 | ||
7fd59977 | 84 | #define RIC120302 //GG Add a NEW SetWindow method which enable |
85 | // to connect a graphic widget and context to OGL. | |
86 | ||
b8ddfc2f | 87 | //BUC61044 25/10/01 SAV ; added functionality to control gl depth testing from higher API |
88 | //BUC61045 25/10/01 SAV ; added functionality to control gl lighting from higher API | |
7fd59977 | 89 | |
b8ddfc2f | 90 | //OCC1188 SAV Added methods to set background image |
7fd59977 | 91 | |
92 | /*----------------------------------------------------------------------*/ | |
93 | /* | |
94 | * Constantes | |
95 | */ | |
96 | ||
97 | #define NO_DEBUG | |
98 | #define NO_DESTROY | |
99 | #define NO_TRACE | |
100 | #define NO_TRACE_ACCEPT | |
101 | #define NO_TRACE_CLEAR | |
102 | #define NO_TRACE_CONNECT | |
103 | #define NO_TRACE_HIGH | |
104 | #define NO_TRACE_COMP | |
105 | #define NO_TRACE_TRSF | |
106 | #define NO_TRACE_DISPLAY | |
107 | #define NO_TRACE_ISCOMP | |
108 | #define NO_TRACE_LENGTH | |
109 | #define NO_TRACE_LAYER | |
110 | ||
111 | /*----------------------------------------------------------------------*/ | |
112 | /* | |
113 | * Includes | |
114 | */ | |
115 | ||
116 | #ifdef WNT | |
117 | #include <windows.h> | |
118 | #endif | |
119 | ||
120 | // for the class | |
121 | #include <Visual3d_View.ixx> | |
122 | #include <Visual3d_View.pxx> | |
123 | #include <Visual3d_DepthCueingDefinitionError.hxx> | |
124 | #include <Visual3d_ZClippingDefinitionError.hxx> | |
125 | ||
126 | #ifdef OLD_METHOD | |
127 | #include <math_Vector.hxx> | |
128 | #endif /* OLD_METHOD */ | |
129 | ||
130 | #include <OSD.hxx> | |
131 | ||
132 | #include <Graphic3d_Structure.hxx> | |
133 | #include <Graphic3d_MapOfStructure.hxx> | |
134 | #include <Graphic3d_MapIteratorOfMapOfStructure.hxx> | |
135 | #include <Graphic3d_DataStructureManager.hxx> | |
136 | ||
137 | #include <Graphic3d_GraphicDriver.hxx> | |
7fd59977 | 138 | |
139 | #include <Graphic3d_Vector.hxx> | |
140 | #include <Graphic3d_Vertex.hxx> | |
141 | ||
142 | #include <Visual3d_Light.hxx> | |
143 | #include <Visual3d_SetOfLight.hxx> | |
144 | #include <Visual3d_HSetOfLight.hxx> | |
145 | #include <Visual3d_SetIteratorOfSetOfLight.hxx> | |
146 | ||
7fd59977 | 147 | #include <Visual3d_SetIteratorOfSetOfView.hxx> |
148 | ||
149 | #include <Graphic3d_TextureEnv.hxx> | |
150 | ||
151 | #include <TColStd_HArray2OfReal.hxx> | |
152 | ||
4fe56619 | 153 | #if (defined(_WIN32) || defined(__WIN32__)) |
154 | #include <WNT_Window.hxx> | |
155 | #elif (defined(__APPLE__) && !defined(MACOSX_USE_GLX)) | |
156 | #include <Cocoa_Window.hxx> | |
7fd59977 | 157 | #else |
4fe56619 | 158 | #include <Xw_Window.hxx> |
159 | #endif | |
7fd59977 | 160 | |
161 | #include <float.h> | |
162 | ||
163 | //-Aliases | |
164 | ||
165 | //-Global data definitions | |
166 | ||
167 | //-Constructors | |
168 | ||
169 | Visual3d_View::Visual3d_View (const Handle(Visual3d_ViewManager)& AManager): | |
170 | MyContext (), | |
171 | MyViewMapping (), | |
172 | MyViewMappingReset (), | |
173 | MyViewOrientation (), | |
174 | MyViewOrientationReset (), | |
175 | MyTransformation (0, 3, 0, 3), | |
176 | MyMatrixOfMapping (0, 3, 0, 3), | |
177 | MyMatrixOfOrientation (0, 3, 0, 3), | |
178 | MyTOCOMPUTESequence (), | |
179 | MyCOMPUTEDSequence (), | |
180 | MyDisplayedStructure () | |
181 | { | |
182 | Standard_Integer i, j; | |
183 | ||
7fd59977 | 184 | MyPtrViewManager = AManager.operator->(); |
7fd59977 | 185 | MyCView.ViewId = int (AManager->Identification (this)); |
186 | MyCView.Active = 0; | |
187 | MyCView.IsDeleted = 0; | |
188 | ||
bf75be98 | 189 | MyCView.WsId = -1; |
190 | MyCView.DefWindow.IsDefined = 0; | |
7fd59977 | 191 | |
bf75be98 | 192 | MyCView.Context.NbActiveLight = 0; |
7fd59977 | 193 | |
194 | for (i=0; i<=3; i++) | |
195 | for (j=0; j<=3; j++) | |
196 | if (i == j) MyTransformation (i, j) = 1.0; | |
197 | else MyTransformation (i, j) = 0.0; | |
198 | ||
199 | Standard_Real X, Y, Z; | |
200 | ||
201 | (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z); | |
202 | MyCView.Orientation.ViewReferencePoint.x = float (X); | |
203 | MyCView.Orientation.ViewReferencePoint.y = float (Y); | |
204 | MyCView.Orientation.ViewReferencePoint.z = float (Z); | |
205 | (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z); | |
206 | MyCView.Orientation.ViewReferencePlane.x = float (X); | |
207 | MyCView.Orientation.ViewReferencePlane.y = float (Y); | |
208 | MyCView.Orientation.ViewReferencePlane.z = float (Z); | |
209 | (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z); | |
210 | MyCView.Orientation.ViewReferenceUp.x = float (X); | |
211 | MyCView.Orientation.ViewReferenceUp.y = float (Y); | |
212 | MyCView.Orientation.ViewReferenceUp.z = float (Z); | |
213 | ||
214 | Standard_Real Sx, Sy, Sz; | |
215 | ||
216 | MyViewOrientation.AxialScale(Sx, Sy, Sz); | |
217 | MyCView.Orientation.ViewScaleX = float (Sx); | |
218 | MyCView.Orientation.ViewScaleY = float (Sy); | |
219 | MyCView.Orientation.ViewScaleZ = float (Sz); | |
220 | ||
221 | // NKV : 23/07/07 - Define custom MODELVIEW matrix | |
222 | MyCView.Orientation.IsCustomMatrix = 0; | |
223 | memset( (float*)MyCView.Orientation.ModelViewMatrix, 0, 16*sizeof( float ) ); | |
224 | MyCView.Orientation.ModelViewMatrix[0][0] = | |
225 | MyCView.Orientation.ModelViewMatrix[1][1] = | |
226 | MyCView.Orientation.ModelViewMatrix[2][2] = | |
227 | MyCView.Orientation.ModelViewMatrix[3][3] = 1.; | |
228 | // | |
229 | ||
230 | Standard_Real um, vm, uM, vM; | |
231 | ||
232 | MyCView.Mapping.Projection = int (MyViewMapping.Projection ()); | |
233 | (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z); | |
234 | MyCView.Mapping.ProjectionReferencePoint.x = float (X); | |
235 | MyCView.Mapping.ProjectionReferencePoint.y = float (Y); | |
236 | MyCView.Mapping.ProjectionReferencePoint.z = float (Z); | |
237 | MyCView.Mapping.ViewPlaneDistance = | |
238 | float (MyViewMapping.ViewPlaneDistance ()); | |
239 | MyCView.Mapping.BackPlaneDistance = | |
240 | float (MyViewMapping.BackPlaneDistance ()); | |
241 | MyCView.Mapping.FrontPlaneDistance = | |
242 | float (MyViewMapping.FrontPlaneDistance ()); | |
243 | MyViewMapping.WindowLimit (um, vm, uM, vM); | |
244 | MyCView.Mapping.WindowLimit.um = float (um); | |
245 | MyCView.Mapping.WindowLimit.vm = float (vm); | |
246 | MyCView.Mapping.WindowLimit.uM = float (uM); | |
247 | MyCView.Mapping.WindowLimit.vM = float (vM); | |
248 | ||
249 | // NKV : 23/07/07 - Define custom MODELVIEW matrix | |
250 | MyCView.Mapping.IsCustomMatrix = 0; | |
251 | memset( (float*)MyCView.Mapping.ProjectionMatrix, 0, 16*sizeof( float ) ); | |
252 | MyCView.Mapping.ProjectionMatrix[0][0] = | |
253 | MyCView.Mapping.ProjectionMatrix[1][1] = | |
254 | MyCView.Mapping.ProjectionMatrix[2][2] = | |
255 | MyCView.Mapping.ProjectionMatrix[3][3] = 1.; | |
256 | // | |
257 | ||
258 | MyCView.Context.ZBufferActivity = -1; | |
259 | ||
7fd59977 | 260 | MyMatOfMapIsEvaluated = Standard_False; |
261 | MyMatOfOriIsEvaluated = Standard_False; | |
262 | ||
bd92cc2a | 263 | IsInitialized = Standard_False; |
7fd59977 | 264 | ComputedModeIsActive = Standard_False; |
265 | MyCView.Backfacing = 0; | |
7fd59977 | 266 | |
7fd59977 | 267 | MyCView.ptrUnderLayer = 0; |
268 | MyCView.ptrOverLayer = 0; | |
269 | MyCView.GContext = 0; | |
270 | MyCView.GDisplayCB = 0; | |
271 | MyCView.GClientData = 0; | |
272 | ||
dc3fe572 | 273 | MyGraphicDriver = MyViewManager->GraphicDriver(); |
7fd59977 | 274 | |
275 | } | |
276 | ||
277 | Visual3d_View::Visual3d_View (const Handle(Visual3d_ViewManager)& AManager, const Visual3d_ViewOrientation& VO, const Visual3d_ViewMapping& VM, const Visual3d_ContextView& CTX): | |
278 | MyTransformation (0, 3, 0, 3), | |
279 | MyMatrixOfMapping (0, 3, 0, 3), | |
280 | MyMatrixOfOrientation (0, 3, 0, 3), | |
281 | MyTOCOMPUTESequence (), | |
282 | MyCOMPUTEDSequence (), | |
283 | MyDisplayedStructure () | |
284 | { | |
285 | Standard_Integer i, j; | |
286 | ||
7fd59977 | 287 | MyPtrViewManager = AManager.operator->(); |
7fd59977 | 288 | MyViewOrientation = VO; |
289 | MyViewMapping = VM; | |
290 | MyContext = CTX; | |
291 | MyViewOrientationReset = VO; | |
292 | MyViewMappingReset = VM; | |
293 | ||
7fd59977 | 294 | MyCView.ViewId = int (AManager->Identification (this)); |
295 | MyCView.Active = 0; | |
296 | MyCView.IsDeleted = 0; | |
297 | ||
bf75be98 | 298 | MyCView.WsId = -1; |
299 | MyCView.DefWindow.IsDefined = 0; | |
7fd59977 | 300 | |
bf75be98 | 301 | MyCView.Context.NbActiveLight = 0; |
7fd59977 | 302 | |
303 | for (i=0; i<=3; i++) | |
304 | for (j=0; j<=3; j++) | |
305 | if (i == j) MyTransformation (i, j) = 1.0; | |
306 | else MyTransformation (i, j) = 0.0; | |
307 | ||
308 | Standard_Real X, Y, Z; | |
309 | ||
310 | (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z); | |
311 | MyCView.Orientation.ViewReferencePoint.x = float (X); | |
312 | MyCView.Orientation.ViewReferencePoint.y = float (Y); | |
313 | MyCView.Orientation.ViewReferencePoint.z = float (Z); | |
314 | (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z); | |
315 | MyCView.Orientation.ViewReferencePlane.x = float (X); | |
316 | MyCView.Orientation.ViewReferencePlane.y = float (Y); | |
317 | MyCView.Orientation.ViewReferencePlane.z = float (Z); | |
318 | (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z); | |
319 | MyCView.Orientation.ViewReferenceUp.x = float (X); | |
320 | MyCView.Orientation.ViewReferenceUp.y = float (Y); | |
321 | MyCView.Orientation.ViewReferenceUp.z = float (Z); | |
322 | ||
323 | Standard_Real Sx, Sy, Sz; | |
324 | ||
325 | MyViewOrientation.AxialScale(Sx, Sy, Sz); | |
326 | MyCView.Orientation.ViewScaleX = float (Sx); | |
327 | MyCView.Orientation.ViewScaleY = float (Sy); | |
328 | MyCView.Orientation.ViewScaleZ = float (Sz); | |
329 | ||
330 | // NKV : 23/07/07 - Define custom MODELVIEW matrix | |
331 | if (MyViewOrientation.IsCustomMatrix()) { | |
332 | MyCView.Orientation.IsCustomMatrix = 1; | |
333 | for ( i = 0; i < 4; i++) | |
334 | for ( j = 0; j < 4; j++) | |
7f4c4756 | 335 | MyCView.Orientation.ModelViewMatrix[i][j] = |
336 | (Standard_ShortReal)MyViewOrientation.MyModelViewMatrix->Value(i,j); | |
7fd59977 | 337 | } |
338 | else { | |
339 | MyCView.Orientation.IsCustomMatrix = 0; | |
340 | memset( (float*)MyCView.Orientation.ModelViewMatrix, 0, 16*sizeof( float ) ); | |
341 | MyCView.Orientation.ModelViewMatrix[0][0] = | |
342 | MyCView.Orientation.ModelViewMatrix[1][1] = | |
343 | MyCView.Orientation.ModelViewMatrix[2][2] = | |
344 | MyCView.Orientation.ModelViewMatrix[3][3] = 1.; | |
345 | } | |
346 | // | |
347 | ||
348 | Standard_Real um, vm, uM, vM; | |
349 | ||
350 | MyCView.Mapping.Projection = int (MyViewMapping.Projection ()); | |
351 | (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z); | |
352 | MyCView.Mapping.ProjectionReferencePoint.x = float (X); | |
353 | MyCView.Mapping.ProjectionReferencePoint.y = float (Y); | |
354 | MyCView.Mapping.ProjectionReferencePoint.z = float (Z); | |
355 | MyCView.Mapping.ViewPlaneDistance = | |
356 | float (MyViewMapping.ViewPlaneDistance ()); | |
357 | MyCView.Mapping.BackPlaneDistance = | |
358 | float (MyViewMapping.BackPlaneDistance ()); | |
359 | MyCView.Mapping.FrontPlaneDistance = | |
360 | float (MyViewMapping.FrontPlaneDistance ()); | |
361 | MyViewMapping.WindowLimit (um, vm, uM, vM); | |
362 | MyCView.Mapping.WindowLimit.um = float (um); | |
363 | MyCView.Mapping.WindowLimit.vm = float (vm); | |
364 | MyCView.Mapping.WindowLimit.uM = float (uM); | |
365 | MyCView.Mapping.WindowLimit.vM = float (vM); | |
366 | ||
367 | // NKV : 23/07/07 - Define custom MODELVIEW matrix | |
368 | if (MyViewMapping.IsCustomMatrix()) { | |
369 | MyCView.Mapping.IsCustomMatrix = 1; | |
370 | for ( i = 0; i < 4; i++) | |
371 | for ( j = 0; j < 4; j++) | |
7f4c4756 | 372 | MyCView.Mapping.ProjectionMatrix[i][j] = |
373 | (Standard_ShortReal)MyViewMapping.MyProjectionMatrix->Value(i,j); | |
7fd59977 | 374 | } |
375 | else { | |
376 | MyCView.Mapping.IsCustomMatrix = 0; | |
377 | memset( (float*)MyCView.Mapping.ProjectionMatrix, 0, 16*sizeof( float ) ); | |
378 | MyCView.Mapping.ProjectionMatrix[0][0] = | |
379 | MyCView.Mapping.ProjectionMatrix[1][1] = | |
380 | MyCView.Mapping.ProjectionMatrix[2][2] = | |
381 | MyCView.Mapping.ProjectionMatrix[3][3] = 1.; | |
382 | } | |
383 | // | |
384 | ||
385 | MyCView.Context.ZBufferActivity = -1; | |
386 | ||
7fd59977 | 387 | MyMatOfMapIsEvaluated = Standard_False; |
388 | MyMatOfOriIsEvaluated = Standard_False; | |
bd92cc2a | 389 | |
390 | IsInitialized = Standard_False; | |
7fd59977 | 391 | ComputedModeIsActive = Standard_False; |
7fd59977 | 392 | |
7fd59977 | 393 | MyCView.ptrUnderLayer = 0; |
394 | MyCView.ptrOverLayer = 0; | |
395 | MyCView.GContext = 0; | |
396 | MyCView.GDisplayCB = 0; | |
397 | MyCView.GClientData = 0; | |
398 | ||
dc3fe572 | 399 | MyGraphicDriver = MyViewManager->GraphicDriver(); |
7fd59977 | 400 | |
401 | } | |
402 | ||
403 | //-Destructors | |
404 | ||
405 | //-Methods, in order | |
406 | // RIC120302 | |
407 | void Visual3d_View::SetWindow (const Handle(Aspect_Window)& AWindow, | |
408 | const Aspect_RenderingContext AContext, | |
409 | const Aspect_GraphicCallbackProc& ADisplayCB, | |
410 | const Standard_Address AClientData) | |
411 | { | |
412 | if (IsDeleted ()) return; | |
413 | ||
414 | if (IsDefined ()) | |
415 | Visual3d_ViewDefinitionError::Raise ("Window already defined"); | |
416 | ||
417 | MyCView.GContext = AContext; | |
418 | MyCView.GDisplayCB = ADisplayCB; | |
419 | MyCView.GClientData = AClientData; | |
420 | SetWindow(AWindow); | |
421 | } | |
422 | // RIC120302 | |
423 | ||
4fe56619 | 424 | void Visual3d_View::SetWindow (const Handle(Aspect_Window)& theWindow) |
425 | { | |
7fd59977 | 426 | |
427 | if (IsDeleted ()) return; | |
428 | ||
429 | if (IsDefined ()) | |
430 | Visual3d_ViewDefinitionError::Raise ("Window already defined"); | |
431 | ||
4fe56619 | 432 | MyWindow = theWindow; |
7fd59977 | 433 | MyCView.WsId = MyCView.ViewId; |
434 | MyCView.DefWindow.IsDefined = 1; | |
4fe56619 | 435 | |
436 | #if (defined(_WIN32) || defined(__WIN32__)) | |
437 | const Handle(WNT_Window) aWin = Handle(WNT_Window)::DownCast (theWindow); | |
438 | MyCView.DefWindow.XWindow = (HWND )(aWin->HWindow()); | |
439 | MyCView.DefWindow.XParentWindow = (HWND )(aWin->HParentWindow()); | |
440 | WNT_WindowData* aWinData = (WNT_WindowData* )GetWindowLongPtr ((HWND )(aWin->HWindow()), GWLP_USERDATA); | |
441 | aWinData->WNT_WDriver_Ptr = (void* )this; | |
442 | aWinData->WNT_VMgr = (void* )MyPtrViewManager; | |
443 | #elif (defined(__APPLE__) && !defined(MACOSX_USE_GLX)) | |
444 | const Handle(Cocoa_Window) aWin = Handle(Cocoa_Window)::DownCast (theWindow); | |
445 | MyCView.DefWindow.XWindow = (Aspect_Drawable )aWin->HView(); | |
446 | MyCView.DefWindow.XParentWindow = NULL; | |
447 | //MyCView.DefWindow.XParentWindow = aWin->HParentWindow(); | |
7fd59977 | 448 | #else |
4fe56619 | 449 | const Handle(Xw_Window) aWin = Handle(Xw_Window)::DownCast (theWindow); |
450 | MyCView.DefWindow.XWindow = aWin->XWindow(); | |
ed97f43c | 451 | //MyCView.DefWindow.XParentWindow = aWin->XParentWindow(); |
7fd59977 | 452 | #endif |
7fd59977 | 453 | |
454 | Standard_Integer Width, Height; | |
4fe56619 | 455 | theWindow->Size (Width, Height); |
7fd59977 | 456 | |
457 | MyCView.DefWindow.dx = float( Width ); | |
458 | MyCView.DefWindow.dy = float( Height ); | |
459 | ||
460 | Standard_Real R, G, B; | |
461 | MyBackground = MyWindow->Background (); | |
462 | (MyBackground.Color ()).Values (R, G, B, Quantity_TOC_RGB); | |
463 | MyCView.DefWindow.Background.r = float (R); | |
464 | MyCView.DefWindow.Background.g = float (G); | |
465 | MyCView.DefWindow.Background.b = float (B); | |
466 | ||
467 | UpdateView (); | |
468 | if (! MyGraphicDriver->View (MyCView)) | |
469 | Visual3d_ViewDefinitionError::Raise ("Association failed"); | |
470 | ||
471 | MyGradientBackground = MyWindow->GradientBackground(); | |
472 | SetGradientBackground(MyGradientBackground,1); | |
473 | ||
81bba717 | 474 | Standard_Boolean AWait = Standard_False; // => immediate update |
7fd59977 | 475 | MyGraphicDriver->SetVisualisation (MyCView); |
476 | MyGraphicDriver->AntiAliasing (MyCView, MyContext.AliasingIsOn ()); | |
477 | MyGraphicDriver->DepthCueing (MyCView, MyContext.DepthCueingIsOn ()); | |
478 | MyGraphicDriver->ClipLimit (MyCView, AWait); | |
479 | MyGraphicDriver->Environment(MyCView); | |
480 | ||
71c4f9c6 | 481 | // Make view manager z layer list consistent with the view's list. |
482 | MyViewManager->InstallZLayers (this); | |
483 | ||
81bba717 | 484 | // Update planses of model clipping |
7fd59977 | 485 | UpdatePlanes (); |
486 | ||
bf75be98 | 487 | // Update light sources |
7fd59977 | 488 | UpdateLights (); |
489 | ||
490 | /* | |
81bba717 | 491 | * Association view-window does not cause the display |
492 | * of structures that can be displayed in the new view. | |
493 | * In fact, association view-window is done, but the | |
494 | * display is produced only if the view is activated (Activate). | |
7fd59977 | 495 | */ |
496 | ||
497 | SetRatio (); | |
498 | ||
499 | } | |
500 | ||
501 | Handle(Aspect_Window) Visual3d_View::Window () const { | |
502 | ||
503 | if (! IsDefined ()) | |
504 | Visual3d_ViewDefinitionError::Raise ("Window not defined"); | |
505 | ||
506 | return (MyWindow); | |
507 | ||
508 | } | |
509 | ||
510 | Standard_Boolean Visual3d_View::IsDefined () const { | |
511 | ||
512 | if (MyCView.DefWindow.IsDefined) | |
513 | return (Standard_True); | |
514 | else | |
515 | return (Standard_False); | |
516 | ||
517 | } | |
518 | ||
519 | Standard_Boolean Visual3d_View::IsDeleted () const { | |
520 | ||
521 | if (MyCView.IsDeleted) | |
522 | return (Standard_True); | |
523 | else | |
524 | return (Standard_False); | |
525 | ||
526 | } | |
527 | ||
528 | void Visual3d_View::Destroy () { | |
529 | ||
530 | #ifdef DESTROY | |
531 | cout << "Visual3d_View::Destroy (" << Identification () << ")\n"; | |
532 | #endif | |
533 | ||
534 | // Since MyPtrViewManager can be already distroyed, | |
535 | // avoid attempts to access it in SetBackground() | |
536 | MyPtrViewManager = 0; | |
537 | Remove (); | |
538 | ||
539 | } | |
540 | ||
541 | void Visual3d_View::Remove () { | |
542 | ||
543 | #ifdef DESTROY | |
544 | cout << "Visual3d_View::Remove (" << Identification () << ")" << endl; | |
545 | #endif | |
546 | ||
547 | if (IsDeleted ()) return; | |
548 | if (! IsDefined ()) return; | |
549 | ||
550 | MyTOCOMPUTESequence.Clear (); | |
551 | MyCOMPUTEDSequence.Clear (); | |
552 | MyDisplayedStructure.Clear (); | |
553 | ||
554 | Quantity_Color BlackColor (0.0, 0.0, 0.0, Quantity_TOC_RGB); | |
555 | Aspect_Background BlackBackground (BlackColor); | |
556 | SetBackground (BlackBackground); | |
557 | ||
558 | Aspect_GradientBackground BlackGradBackground; | |
559 | SetGradientBackground (BlackGradBackground,0); | |
560 | ||
561 | if (MyPtrViewManager) | |
562 | MyPtrViewManager->UnIdentification( MyCView.ViewId ); | |
563 | ||
564 | MyGraphicDriver->RemoveView (MyCView); | |
565 | ||
566 | MyCView.WsId = -1; | |
567 | MyCView.IsDeleted = 1; | |
568 | MyCView.DefWindow.IsDefined = 0; | |
569 | ||
7fd59977 | 570 | MyMatOfMapIsEvaluated = Standard_False; |
571 | MyMatOfOriIsEvaluated = Standard_False; | |
572 | ||
bd92cc2a | 573 | IsInitialized = Standard_False; |
574 | ||
7fd59977 | 575 | MyWindow.Nullify (); |
576 | ||
577 | } | |
578 | ||
579 | void Visual3d_View::Resized () { | |
580 | ||
581 | if (IsDeleted ()) return; | |
582 | ||
583 | if (! IsDefined ()) | |
584 | Visual3d_ViewDefinitionError::Raise ("Window not defined"); | |
585 | MyWindow->DoResize() ; | |
586 | SetRatio (); | |
587 | ||
588 | } | |
589 | ||
590 | void Visual3d_View::SetRatio () { | |
591 | ||
592 | if (IsDeleted ()) return; | |
593 | ||
594 | Aspect_TypeOfUpdate UpdateMode = MyViewManager->UpdateMode (); | |
595 | MyViewManager->SetUpdateMode (Aspect_TOU_WAIT); | |
596 | ||
597 | Standard_Real Umin, Vmin, Umax, Vmax; | |
598 | Standard_Integer Dxw, Dyw; | |
599 | Standard_Real Dxv, Dyv; | |
600 | Standard_Real Xc, Yc; | |
601 | Standard_Real Rap; | |
602 | ||
603 | Rap = 0. ; | |
604 | MyWindow->Size (Dxw, Dyw); | |
605 | MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ; | |
606 | Xc = (Umin + Umax)/2. ; Yc = (Vmin + Vmax)/2. ; | |
607 | Dxv = Umax - Umin ; Dyv = Vmax - Vmin ; | |
608 | if( Dxw > 0 && Dyw > 0 ) Rap = (Standard_Real)Dyw/(Standard_Real)Dxw ; | |
609 | if( Rap > 0.0 ) { | |
610 | ||
611 | if( Dxv <= Dyv ) | |
612 | { | |
613 | if (Rap <= 1.0) | |
614 | { | |
615 | Dyv = Dxv; | |
616 | Dxv = Dxv/Rap; | |
617 | } | |
618 | else | |
619 | { | |
620 | Dxv = Dxv; | |
621 | Dyv = Dxv*Rap; | |
622 | } | |
623 | } | |
624 | else | |
625 | { | |
626 | if (Rap <= 1.0) | |
627 | { | |
628 | Dxv = Dyv/Rap; | |
629 | Dyv = Dyv; | |
630 | } | |
631 | else | |
632 | { | |
633 | Dxv = Dyv; | |
634 | Dyv = Dyv*Rap; | |
635 | } | |
636 | } | |
637 | ||
638 | Umin = Xc - Dxv/2. ; Vmin = Yc - Dyv/2. ; | |
639 | Umax = Xc + Dxv/2. ; Vmax = Yc + Dyv/2. ; | |
640 | ||
641 | MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ; | |
642 | ||
81bba717 | 643 | // Update before SetViewMapping. |
7fd59977 | 644 | |
645 | MyCView.DefWindow.dx = float( Dxw ); | |
646 | MyCView.DefWindow.dy = float( Dyw ); | |
647 | ||
648 | SetViewMapping (MyViewMapping); | |
649 | // SetViewMappingDefault (); | |
81bba717 | 650 | // FMN+ Update Ratio for MyViewMappingReset |
7fd59977 | 651 | |
652 | MyViewMappingReset.WindowLimit(Umin,Vmin,Umax,Vmax) ; | |
653 | Xc = (Umin + Umax)/2. ; Yc = (Vmin + Vmax)/2. ; | |
654 | Dxv = Umax - Umin ; Dyv = Vmax - Vmin ; | |
655 | ||
656 | if( Dxv <= Dyv ) | |
657 | { | |
658 | if (Rap <= 1.0) | |
659 | { | |
660 | Dyv = Dxv; | |
661 | Dxv = Dxv/Rap; | |
662 | } | |
663 | else | |
664 | { | |
665 | Dxv = Dxv; | |
666 | Dyv = Dxv*Rap; | |
667 | } | |
668 | } | |
669 | else | |
670 | { | |
671 | if (Rap <= 1.0) | |
672 | { | |
673 | Dxv = Dyv/Rap; | |
674 | Dyv = Dyv; | |
675 | } | |
676 | else | |
677 | { | |
678 | Dxv = Dyv; | |
679 | Dyv = Dyv*Rap; | |
680 | } | |
681 | } | |
682 | ||
683 | Umin = Xc - Dxv/2. ; Vmin = Yc - Dyv/2. ; | |
684 | Umax = Xc + Dxv/2. ; Vmax = Yc + Dyv/2. ; | |
685 | ||
686 | MyViewMappingReset.SetWindowLimit(Umin,Vmin,Umax,Vmax) ; | |
687 | ||
81bba717 | 688 | // FMN- Update Ratio for MyViewMappingReset |
7fd59977 | 689 | |
690 | MyGraphicDriver->RatioWindow (MyCView); | |
691 | } | |
692 | ||
81bba717 | 693 | // Force recalculation of 2 matrices. |
7fd59977 | 694 | // |
81bba717 | 695 | // The current view can help to reconstruct a copied view |
696 | // that is itself. Owing to SetWindow and SetRatio the | |
697 | // recalculation of matrices of this new view is imposed. | |
7fd59977 | 698 | MyMatOfMapIsEvaluated = Standard_False; |
699 | MyMatOfOriIsEvaluated = Standard_False; | |
700 | ||
701 | MyViewManager->SetUpdateMode (UpdateMode); | |
702 | if (UpdateMode == Aspect_TOU_ASAP) Update (); | |
703 | ||
704 | } | |
705 | ||
12381341 | 706 | void Visual3d_View::UpdateLights() |
707 | { | |
708 | if (IsDeleted() | |
709 | || !IsDefined()) | |
710 | { | |
711 | return; | |
712 | } | |
7fd59977 | 713 | |
12381341 | 714 | if (MyContext.Model() == Visual3d_TOM_NONE) |
715 | { | |
716 | // activate only a white ambient light | |
717 | Graphic3d_CLight aCLight; | |
718 | aCLight.Type = Visual3d_TOLS_AMBIENT; | |
719 | aCLight.IsHeadlight = Standard_False; | |
720 | aCLight.Color.r() = aCLight.Color.g() = aCLight.Color.b() = 1.0f; | |
7fd59977 | 721 | |
7fd59977 | 722 | MyCView.Context.NbActiveLight = 1; |
12381341 | 723 | MyCView.Context.ActiveLight = &aCLight; |
724 | MyGraphicDriver->SetLight (MyCView); | |
725 | MyCView.Context.ActiveLight = NULL; | |
726 | return; | |
7fd59977 | 727 | } |
7fd59977 | 728 | |
12381341 | 729 | MyCView.Context.NbActiveLight = Min (MyContext.NumberOfActivatedLights(), |
730 | MyGraphicDriver->InquireLightLimit()); | |
731 | if (MyCView.Context.NbActiveLight < 1) | |
732 | { | |
4fe9ad57 | 733 | MyGraphicDriver->SetLight (MyCView); |
12381341 | 734 | return; |
735 | } | |
7fd59977 | 736 | |
12381341 | 737 | // parcing of light sources |
738 | MyCView.Context.ActiveLight = new Graphic3d_CLight[MyCView.Context.NbActiveLight]; | |
739 | for (Standard_Integer aLightIter = 0; aLightIter < MyCView.Context.NbActiveLight; ++aLightIter) | |
740 | { | |
741 | MyCView.Context.ActiveLight[aLightIter] = MyContext.ActivatedLight (aLightIter + 1)->CLight(); | |
742 | } | |
743 | MyGraphicDriver->SetLight (MyCView); | |
744 | delete[] MyCView.Context.ActiveLight; | |
745 | MyCView.Context.ActiveLight = NULL; | |
7fd59977 | 746 | } |
747 | ||
4269bd1b | 748 | void Visual3d_View::UpdatePlanes() |
749 | { | |
750 | MyCView.Context.ClipPlanes = MyContext.GetClipPlanes(); | |
751 | ||
752 | if (IsDeleted() || !IsDefined()) | |
753 | return; | |
7fd59977 | 754 | |
4269bd1b | 755 | MyGraphicDriver->SetClipPlanes (MyCView); |
7fd59977 | 756 | } |
757 | ||
758 | void Visual3d_View::SetBackground (const Aspect_Background& ABack) { | |
759 | ||
760 | if (IsDeleted ()) return; | |
761 | ||
762 | if (! IsDefined ()) | |
763 | Visual3d_ViewDefinitionError::Raise ("Window not defined"); | |
764 | ||
81bba717 | 765 | // At this level, only GL can update the background. |
766 | // It is not necessary to call MyWindow->SetBackground (ABack); as | |
767 | // this method starts update of window background by X | |
768 | // (if the windowing is X) | |
7fd59977 | 769 | |
770 | Standard_Real R, G, B; | |
771 | MyBackground = ABack; | |
772 | (MyBackground.Color ()).Values (R, G, B, Quantity_TOC_RGB); | |
773 | MyCView.DefWindow.Background.r = float (R); | |
774 | MyCView.DefWindow.Background.g = float (G); | |
775 | MyCView.DefWindow.Background.b = float (B); | |
776 | ||
777 | MyGraphicDriver->Background (MyCView); | |
778 | ||
779 | if (MyPtrViewManager && MyViewManager->UpdateMode () == Aspect_TOU_ASAP) | |
780 | Update (); | |
781 | ||
782 | } | |
783 | ||
784 | void Visual3d_View::SetGradientBackground(const Aspect_GradientBackground& ABack, const Standard_Boolean update) | |
785 | { | |
786 | ||
787 | if (IsDeleted ()) return; | |
788 | ||
789 | if (! IsDefined ()) | |
790 | Visual3d_ViewDefinitionError::Raise ("Window not defined"); | |
791 | ||
792 | MyGradientBackground = ABack; | |
793 | Quantity_Color aCol1,aCol2; | |
794 | MyGradientBackground.Colors(aCol1,aCol2); | |
795 | MyGraphicDriver->GradientBackground(MyCView, aCol1, aCol2, MyGradientBackground.BgGradientFillMethod()); | |
796 | ||
797 | if ( update ) | |
798 | Update (); | |
799 | else if (MyPtrViewManager && MyViewManager->UpdateMode () == Aspect_TOU_ASAP) | |
800 | Update(); | |
801 | } | |
802 | ||
803 | void Visual3d_View::SetBackgroundImage( const Standard_CString FileName, | |
804 | const Aspect_FillMethod FillStyle, | |
805 | const Standard_Boolean update ) | |
806 | { | |
7fd59977 | 807 | if ( IsDeleted() ) |
808 | return; | |
809 | if ( !IsDefined() ) | |
810 | Visual3d_ViewDefinitionError::Raise ("Window not defined"); | |
811 | ||
812 | MyGraphicDriver->BackgroundImage( FileName, MyCView, FillStyle ); | |
813 | ||
814 | if ( update ) | |
815 | Update(); | |
816 | else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP ) | |
817 | Update(); | |
7fd59977 | 818 | } |
819 | ||
820 | void Visual3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle, | |
821 | const Standard_Boolean update ) | |
822 | { | |
7fd59977 | 823 | if ( IsDeleted() ) |
824 | return; | |
825 | if ( !IsDefined() ) | |
826 | Visual3d_ViewDefinitionError::Raise ("Window not defined"); | |
827 | ||
828 | MyGraphicDriver->SetBgImageStyle( MyCView, FillStyle ); | |
829 | ||
830 | if ( update ) | |
831 | Update(); | |
832 | else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP ) | |
833 | Update(); | |
7fd59977 | 834 | } |
835 | ||
836 | Aspect_Background Visual3d_View::Background () const { | |
837 | ||
838 | return (MyBackground); | |
839 | ||
840 | } | |
841 | ||
842 | void Visual3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle, | |
843 | const Standard_Boolean update ) | |
844 | { | |
845 | if ( IsDeleted() ) | |
846 | return; | |
847 | if ( !IsDefined() ) | |
848 | Visual3d_ViewDefinitionError::Raise ("Window not defined"); | |
849 | ||
850 | MyGraphicDriver->SetBgGradientStyle( MyCView, FillStyle ); | |
851 | ||
852 | if ( update ) | |
853 | Update(); | |
854 | else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP ) | |
855 | Update(); | |
856 | ||
857 | } | |
858 | ||
859 | Aspect_GradientBackground Visual3d_View::GradientBackground () const { | |
860 | ||
861 | return MyGradientBackground; | |
862 | ||
863 | } | |
864 | ||
865 | void Visual3d_View::SetTransform (const TColStd_Array2OfReal& AMatrix) { | |
866 | ||
867 | if (IsDeleted ()) return; | |
868 | ||
869 | Standard_Integer lr, ur, lc, uc; | |
870 | Standard_Integer i, j; | |
871 | ||
872 | // Assign the new transformation in an array [0..3][0..3] | |
81bba717 | 873 | // Avoid problems if the has defined a matrice [1..4][1..4] |
7fd59977 | 874 | // ou [3..6][-1..2] !! |
875 | lr = AMatrix.LowerRow (); | |
876 | ur = AMatrix.UpperRow (); | |
877 | lc = AMatrix.LowerCol (); | |
878 | uc = AMatrix.UpperCol (); | |
879 | ||
880 | if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) | |
881 | Visual3d_TransformError::Raise ("Transform : not a 4x4 matrix"); | |
882 | ||
883 | for (i=0; i<=3; i++) | |
884 | for (j=0; j<=3; j++) | |
885 | MyTransformation (i, j) = AMatrix (lr + i, lc + j); | |
886 | ||
887 | Graphic3d_Vector VPN; | |
888 | Graphic3d_Vertex VRP; | |
889 | Graphic3d_Vector VUP; | |
890 | Standard_Real Sx, Sy, Sz; | |
891 | ||
892 | Visual3d_ViewOrientation NewViewOrientation; | |
893 | ||
894 | VPN = MyViewOrientation.ViewReferencePlane (); | |
895 | VRP = MyViewOrientation.ViewReferencePoint (); | |
896 | VUP = MyViewOrientation.ViewReferenceUp (); | |
897 | MyViewOrientation.AxialScale(Sx, Sy, Sz); | |
898 | ||
899 | NewViewOrientation.SetViewReferencePlane | |
900 | (Graphic3d_Structure::Transforms (Transform (), VPN)); | |
901 | ||
902 | NewViewOrientation.SetViewReferencePoint | |
903 | (Graphic3d_Structure::Transforms (Transform (), VRP)); | |
904 | ||
905 | NewViewOrientation.SetViewReferenceUp | |
906 | (Graphic3d_Structure::Transforms (Transform (), VUP)); | |
907 | NewViewOrientation.SetAxialScale(Sx, Sy, Sz); | |
908 | ||
909 | SetViewOrientation (NewViewOrientation); | |
910 | ||
7fd59977 | 911 | MyMatOfOriIsEvaluated = Standard_False; |
912 | ||
913 | } | |
914 | ||
915 | const TColStd_Array2OfReal& Visual3d_View::Transform () const { | |
916 | ||
917 | return (MyTransformation); | |
918 | ||
919 | } | |
920 | ||
921 | void Visual3d_View::SetViewOrientation (const Visual3d_ViewOrientation& VO) { | |
922 | ||
923 | if (IsDeleted ()) return; | |
924 | ||
925 | MyViewOrientation = VO; | |
ed97f43c | 926 | |
bd92cc2a | 927 | Standard_Real X, Y, Z; |
81bba717 | 928 | // Tests on modification of parameters. |
bd92cc2a | 929 | Standard_Boolean VUPIsModified = Standard_False; |
930 | Standard_Boolean VRPIsModified = Standard_False; | |
931 | Standard_Boolean VRUIsModified = Standard_False; | |
932 | Standard_Boolean ScaleIsModified = Standard_False; | |
933 | Standard_Boolean CustomIsModified = Standard_False; | |
7fd59977 | 934 | |
935 | (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z); | |
936 | VUPIsModified = | |
bd92cc2a | 937 | MyCView.Orientation.ViewReferencePoint.x != float (X) |
938 | || MyCView.Orientation.ViewReferencePoint.y != float (Y) | |
939 | || MyCView.Orientation.ViewReferencePoint.z != float (Z); | |
7fd59977 | 940 | MyCView.Orientation.ViewReferencePoint.x = float (X); |
941 | MyCView.Orientation.ViewReferencePoint.y = float (Y); | |
942 | MyCView.Orientation.ViewReferencePoint.z = float (Z); | |
943 | ||
944 | (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z); | |
945 | VRPIsModified = | |
bd92cc2a | 946 | MyCView.Orientation.ViewReferencePlane.x != float (X) |
947 | || MyCView.Orientation.ViewReferencePlane.y != float (Y) | |
948 | || MyCView.Orientation.ViewReferencePlane.z != float (Z); | |
7fd59977 | 949 | MyCView.Orientation.ViewReferencePlane.x = float (X); |
950 | MyCView.Orientation.ViewReferencePlane.y = float (Y); | |
951 | MyCView.Orientation.ViewReferencePlane.z = float (Z); | |
952 | ||
953 | (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z); | |
954 | VRUIsModified = | |
bd92cc2a | 955 | MyCView.Orientation.ViewReferenceUp.x != float (X) |
956 | || MyCView.Orientation.ViewReferenceUp.y != float (Y) | |
957 | || MyCView.Orientation.ViewReferenceUp.z != float (Z); | |
7fd59977 | 958 | MyCView.Orientation.ViewReferenceUp.x = float (X); |
959 | MyCView.Orientation.ViewReferenceUp.y = float (Y); | |
960 | MyCView.Orientation.ViewReferenceUp.z = float (Z); | |
961 | ||
bd92cc2a | 962 | MyViewOrientation.AxialScale(X, Y, Z); |
963 | ScaleIsModified = | |
964 | MyCView.Orientation.ViewScaleX != float (X) | |
965 | || MyCView.Orientation.ViewScaleY != float (Y) | |
966 | || MyCView.Orientation.ViewScaleZ != float (Z); | |
967 | MyCView.Orientation.ViewScaleX = float (X); | |
968 | MyCView.Orientation.ViewScaleY = float (Y); | |
969 | MyCView.Orientation.ViewScaleZ = float (Z); | |
7fd59977 | 970 | |
971 | CustomIsModified = | |
498ce76b | 972 | (MyCView.Orientation.IsCustomMatrix != MyViewOrientation.IsCustomMatrix()); |
7fd59977 | 973 | MyCView.Orientation.IsCustomMatrix = MyViewOrientation.IsCustomMatrix(); |
974 | if ( MyViewOrientation.IsCustomMatrix() ) { | |
975 | Standard_Integer i, j; | |
976 | for (i = 0; i < 4; i++) | |
977 | for (j = 0; j < 4; j++) { | |
bd92cc2a | 978 | if (!CustomIsModified) CustomIsModified = |
979 | MyCView.Orientation.ModelViewMatrix[i][j] != MyViewOrientation.MyModelViewMatrix->Value(i,j); | |
7fd59977 | 980 | } |
981 | } | |
982 | ||
983 | #ifdef TRACE_TRSF | |
bd92cc2a | 984 | cout << "Visual3d_View::SetViewOrientation\n"; |
985 | if (VUPIsModified || VRPIsModified || VRUIsModified || ScaleIsModified || CustomIsModified) | |
986 | cout << "VUPIsModified : " << VUPIsModified | |
987 | << ", VRPIsModified : " << VRPIsModified | |
988 | << ", VRUIsModified : " << VRUIsModified | |
989 | << ", CustomIsModified : " << CustomIsModified | |
990 | << ", ScaleIsModified : " << ScaleIsModified << "\n" << flush; | |
7fd59977 | 991 | else |
bd92cc2a | 992 | cout << "no modification\n" << flush; |
7fd59977 | 993 | #endif |
994 | ||
81bba717 | 995 | // restart if one of parameters is modified |
bd92cc2a | 996 | if (!IsInitialized || VUPIsModified || VRPIsModified |
997 | || VRUIsModified || ScaleIsModified || CustomIsModified) { | |
7fd59977 | 998 | |
bd92cc2a | 999 | MyMatOfOriIsEvaluated = !VUPIsModified && !VRPIsModified |
1000 | && !VRUIsModified && !ScaleIsModified; | |
ed97f43c | 1001 | |
bd92cc2a | 1002 | if (! IsDefined ()) return; |
ed97f43c | 1003 | |
bd92cc2a | 1004 | Standard_Boolean AWait = Standard_False; // => immediate update |
1005 | MyGraphicDriver->ViewOrientation (MyCView, AWait); | |
1006 | IsInitialized = Standard_True; | |
1007 | Compute (); | |
7fd59977 | 1008 | |
bd92cc2a | 1009 | if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update (); |
7fd59977 | 1010 | } |
1011 | ||
1012 | } | |
1013 | ||
1014 | Visual3d_ViewOrientation Visual3d_View::ViewOrientation () const { | |
1015 | ||
1016 | return (MyViewOrientation); | |
1017 | ||
1018 | } | |
1019 | ||
1020 | Visual3d_ViewOrientation Visual3d_View::ViewOrientationDefault () const { | |
1021 | ||
1022 | return (MyViewOrientationReset); | |
1023 | ||
1024 | } | |
1025 | ||
1026 | void Visual3d_View::SetViewOrientationDefault () { | |
1027 | ||
1028 | MyViewOrientationReset.Assign (MyViewOrientation); | |
1029 | ||
1030 | } | |
1031 | ||
1032 | void Visual3d_View::ViewOrientationReset () { | |
1033 | ||
1034 | if (IsDeleted ()) return; | |
1035 | ||
1036 | MyViewOrientation = MyViewOrientationReset; | |
1037 | ||
bd92cc2a | 1038 | Standard_Real X, Y, Z; |
7fd59977 | 1039 | |
81bba717 | 1040 | // Tests on modification of parameters. |
bd92cc2a | 1041 | Standard_Boolean VUPIsModified = Standard_False; |
1042 | Standard_Boolean VRPIsModified = Standard_False; | |
1043 | Standard_Boolean VRUIsModified = Standard_False; | |
1044 | Standard_Boolean ScaleIsModified = Standard_False; | |
1045 | Standard_Boolean CustomIsModified = Standard_False; | |
7fd59977 | 1046 | |
1047 | (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z); | |
1048 | VUPIsModified = | |
bd92cc2a | 1049 | MyCView.Orientation.ViewReferencePoint.x != float (X) |
1050 | || MyCView.Orientation.ViewReferencePoint.y != float (Y) | |
1051 | || MyCView.Orientation.ViewReferencePoint.z != float (Z); | |
7fd59977 | 1052 | MyCView.Orientation.ViewReferencePoint.x = float (X); |
1053 | MyCView.Orientation.ViewReferencePoint.y = float (Y); | |
1054 | MyCView.Orientation.ViewReferencePoint.z = float (Z); | |
1055 | ||
1056 | (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z); | |
1057 | VRPIsModified = | |
bd92cc2a | 1058 | MyCView.Orientation.ViewReferencePlane.x != float (X) |
1059 | || MyCView.Orientation.ViewReferencePlane.y != float (Y) | |
1060 | || MyCView.Orientation.ViewReferencePlane.z != float (Z); | |
7fd59977 | 1061 | MyCView.Orientation.ViewReferencePlane.x = float (X); |
1062 | MyCView.Orientation.ViewReferencePlane.y = float (Y); | |
1063 | MyCView.Orientation.ViewReferencePlane.z = float (Z); | |
1064 | ||
1065 | (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z); | |
1066 | VRUIsModified = | |
bd92cc2a | 1067 | MyCView.Orientation.ViewReferenceUp.x != float (X) |
1068 | || MyCView.Orientation.ViewReferenceUp.y != float (Y) | |
1069 | || MyCView.Orientation.ViewReferenceUp.z != float (Z); | |
7fd59977 | 1070 | MyCView.Orientation.ViewReferenceUp.x = float (X); |
1071 | MyCView.Orientation.ViewReferenceUp.y = float (Y); | |
1072 | MyCView.Orientation.ViewReferenceUp.z = float (Z); | |
1073 | ||
bd92cc2a | 1074 | MyViewOrientation.AxialScale(X, Y, Z); |
1075 | ScaleIsModified = | |
1076 | MyCView.Orientation.ViewScaleX != float (X) | |
1077 | || MyCView.Orientation.ViewScaleY != float (Y) | |
1078 | || MyCView.Orientation.ViewScaleZ != float (Z); | |
1079 | MyCView.Orientation.ViewScaleX = float (X); | |
1080 | MyCView.Orientation.ViewScaleY = float (Y); | |
1081 | MyCView.Orientation.ViewScaleZ = float (Z); | |
7fd59977 | 1082 | |
1083 | CustomIsModified = | |
bd92cc2a | 1084 | MyCView.Orientation.IsCustomMatrix != MyViewOrientation.IsCustomMatrix(); |
7fd59977 | 1085 | MyCView.Orientation.IsCustomMatrix = MyViewOrientation.IsCustomMatrix(); |
1086 | if ( MyViewOrientation.IsCustomMatrix() ) { | |
1087 | Standard_Integer i, j; | |
1088 | for (i = 0; i < 4; i++) | |
1089 | for (j = 0; j < 4; j++) { | |
bd92cc2a | 1090 | if (!CustomIsModified) CustomIsModified = |
1091 | MyCView.Orientation.ModelViewMatrix[i][j] != MyViewOrientation.MyModelViewMatrix->Value(i,j); | |
7fd59977 | 1092 | } |
1093 | } | |
1094 | ||
bd92cc2a | 1095 | |
7fd59977 | 1096 | #ifdef TRACE_TRSF |
bd92cc2a | 1097 | cout << "Visual3d_View::ViewOrientationReset\n"; |
1098 | if (VUPIsModified || VRPIsModified || VRUIsModified || ScaleIsModified || CustomIsModified) | |
1099 | cout << "VUPIsModified : " << VUPIsModified | |
1100 | << ", VRPIsModified : " << VRPIsModified | |
1101 | << ", VRUIsModified : " << VRUIsModified | |
1102 | << ", CustomIsModified : " << CustomIsModified | |
1103 | << ", ScaleIsModified : " << ScaleIsModified << "\n" << flush; | |
1104 | else | |
1105 | cout << "no modification\n" << flush; | |
7fd59977 | 1106 | #endif |
1107 | ||
81bba717 | 1108 | // Restart if one of parameters is modified |
bd92cc2a | 1109 | if (!IsInitialized || VUPIsModified || VRPIsModified |
1110 | || VRUIsModified || ScaleIsModified || CustomIsModified) { | |
ed97f43c | 1111 | |
bd92cc2a | 1112 | MyMatOfOriIsEvaluated = !VUPIsModified && !VRPIsModified |
1113 | && !VRUIsModified && !ScaleIsModified; | |
7fd59977 | 1114 | |
bd92cc2a | 1115 | if (! IsDefined ()) return; |
7fd59977 | 1116 | |
bd92cc2a | 1117 | Standard_Boolean AWait = Standard_False; // => immediate update |
1118 | MyGraphicDriver->ViewOrientation (MyCView, AWait); | |
1119 | IsInitialized = Standard_True; | |
1120 | Compute (); | |
7fd59977 | 1121 | |
bd92cc2a | 1122 | if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update (); |
7fd59977 | 1123 | } |
7fd59977 | 1124 | } |
1125 | ||
1126 | void Visual3d_View::SetViewMapping (const Visual3d_ViewMapping& VM) { | |
1127 | ||
1128 | if (IsDeleted ()) return; | |
1129 | ||
1130 | Visual3d_TypeOfProjection OldType = MyViewMapping.Projection (); | |
1131 | Visual3d_TypeOfProjection NewType = VM.Projection (); | |
1132 | ||
1133 | MyViewMapping = VM; | |
1134 | ||
1135 | Standard_Real X, Y, Z; | |
1136 | Standard_Real um, vm, uM, vM; | |
1137 | ||
1138 | MyCView.Mapping.Projection = int (MyViewMapping.Projection ()); | |
1139 | (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z); | |
1140 | MyCView.Mapping.ProjectionReferencePoint.x = float (X); | |
1141 | MyCView.Mapping.ProjectionReferencePoint.y = float (Y); | |
1142 | MyCView.Mapping.ProjectionReferencePoint.z = float (Z); | |
1143 | MyCView.Mapping.ViewPlaneDistance = | |
1144 | float (MyViewMapping.ViewPlaneDistance ()); | |
1145 | MyCView.Mapping.BackPlaneDistance = | |
1146 | float (MyViewMapping.BackPlaneDistance ()); | |
1147 | MyCView.Mapping.FrontPlaneDistance = | |
1148 | float (MyViewMapping.FrontPlaneDistance ()); | |
1149 | MyViewMapping.WindowLimit (um, vm, uM, vM); | |
1150 | MyCView.Mapping.WindowLimit.um = float (um); | |
1151 | MyCView.Mapping.WindowLimit.vm = float (vm); | |
1152 | MyCView.Mapping.WindowLimit.uM = float (uM); | |
1153 | MyCView.Mapping.WindowLimit.vM = float (vM); | |
1154 | ||
1155 | MyCView.Mapping.IsCustomMatrix = MyViewMapping.IsCustomMatrix(); | |
1156 | if (MyViewMapping.IsCustomMatrix()) { | |
1157 | Standard_Integer i, j; | |
1158 | for (i = 0; i < 4; i++) | |
1159 | for (j = 0; j < 4; j++) | |
1160 | MyCView.Mapping.ProjectionMatrix[i][j] = | |
7f4c4756 | 1161 | (Standard_ShortReal)MyViewMapping.MyProjectionMatrix->Value(i,j); |
7fd59977 | 1162 | } |
1163 | ||
7fd59977 | 1164 | MyMatOfMapIsEvaluated = Standard_False; |
1165 | ||
1166 | if (! IsDefined ()) return; | |
1167 | ||
81bba717 | 1168 | Standard_Boolean AWait = Standard_False; // => immediate update |
7fd59977 | 1169 | MyGraphicDriver->ViewMapping (MyCView, AWait); |
1170 | ||
1171 | // Passage Parallele/Perspective | |
1172 | if (OldType != NewType) | |
1173 | Compute (); | |
1174 | ||
1175 | if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update (); | |
1176 | ||
1177 | } | |
1178 | ||
1179 | Visual3d_ViewMapping Visual3d_View::ViewMapping () const { | |
1180 | ||
1181 | return (MyViewMapping); | |
1182 | ||
1183 | } | |
1184 | ||
1185 | Visual3d_ViewMapping Visual3d_View::ViewMappingDefault () const { | |
1186 | ||
1187 | return (MyViewMappingReset); | |
1188 | ||
1189 | } | |
1190 | ||
1191 | void Visual3d_View::SetViewMappingDefault () { | |
1192 | ||
1193 | MyViewMappingReset.Assign (MyViewMapping); | |
1194 | ||
1195 | } | |
1196 | ||
1197 | void Visual3d_View::ViewMappingReset () { | |
1198 | ||
1199 | if (IsDeleted ()) return; | |
1200 | ||
1201 | MyViewMapping = MyViewMappingReset; | |
1202 | ||
1203 | Standard_Real X, Y, Z; | |
1204 | Standard_Real um, vm, uM, vM; | |
1205 | ||
1206 | MyCView.Mapping.Projection = int (MyViewMapping.Projection ()); | |
1207 | (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z); | |
1208 | MyCView.Mapping.ProjectionReferencePoint.x = float (X); | |
1209 | MyCView.Mapping.ProjectionReferencePoint.y = float (Y); | |
1210 | MyCView.Mapping.ProjectionReferencePoint.z = float (Z); | |
1211 | MyCView.Mapping.ViewPlaneDistance = | |
1212 | float (MyViewMapping.ViewPlaneDistance ()); | |
1213 | MyCView.Mapping.BackPlaneDistance = | |
1214 | float (MyViewMapping.BackPlaneDistance ()); | |
1215 | MyCView.Mapping.FrontPlaneDistance = | |
1216 | float (MyViewMapping.FrontPlaneDistance ()); | |
1217 | MyViewMapping.WindowLimit (um, vm, uM, vM); | |
1218 | MyCView.Mapping.WindowLimit.um = float (um); | |
1219 | MyCView.Mapping.WindowLimit.vm = float (vm); | |
1220 | MyCView.Mapping.WindowLimit.uM = float (uM); | |
1221 | MyCView.Mapping.WindowLimit.vM = float (vM); | |
1222 | ||
1223 | MyCView.Mapping.IsCustomMatrix = MyViewMapping.IsCustomMatrix(); | |
1224 | if (MyViewMapping.IsCustomMatrix()) { | |
1225 | Standard_Integer i, j; | |
1226 | for (i = 0; i < 4; i++) | |
1227 | for (j = 0; j < 4; j++) | |
1228 | MyCView.Mapping.ProjectionMatrix[i][j] = | |
7f4c4756 | 1229 | (Standard_ShortReal)MyViewMapping.MyProjectionMatrix->Value(i,j); |
7fd59977 | 1230 | } |
1231 | ||
7fd59977 | 1232 | MyMatOfMapIsEvaluated = Standard_False; |
1233 | ||
1234 | if (! IsDefined ()) return; | |
1235 | ||
81bba717 | 1236 | Standard_Boolean AWait = Standard_False; // => immediate update |
7fd59977 | 1237 | MyGraphicDriver->ViewMapping (MyCView, AWait); |
1238 | ||
1239 | if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update (); | |
1240 | ||
1241 | } | |
1242 | ||
1243 | void Visual3d_View::SetContext (const Visual3d_ContextView& CTX) { | |
1244 | ||
1245 | if (IsDeleted ()) return; | |
1246 | ||
1247 | Visual3d_TypeOfVisualization OldVisualMode; | |
1248 | Visual3d_TypeOfVisualization NewVisualMode; | |
1249 | ||
bf75be98 | 1250 | // To manage display only in case of |
81bba717 | 1251 | // change of visualisation mode. |
7fd59977 | 1252 | OldVisualMode = MyContext.Visualization (); |
1253 | NewVisualMode = CTX.Visualization (); | |
1254 | ||
1255 | Visual3d_TypeOfModel OldModel; | |
1256 | Visual3d_TypeOfModel NewModel; | |
1257 | ||
bf75be98 | 1258 | // To manage change of visualisation only in case |
81bba717 | 1259 | // of change of mode of visualisation or of type of shading. |
7fd59977 | 1260 | OldModel = MyContext.Model (); |
1261 | NewModel = CTX.Model (); | |
1262 | ||
1263 | Standard_Boolean OldAliasingMode; | |
1264 | Standard_Boolean NewAliasingMode; | |
1265 | ||
81bba717 | 1266 | // To manage antialiasing only in case of change. |
7fd59977 | 1267 | OldAliasingMode = MyContext.AliasingIsOn (); |
1268 | NewAliasingMode = CTX.AliasingIsOn (); | |
1269 | ||
1270 | Standard_Boolean OldDepthCueingMode; | |
1271 | Standard_Boolean NewDepthCueingMode; | |
1272 | ||
1273 | Standard_Real OldDepthCueingFrontPlane; | |
1274 | Standard_Real NewDepthCueingFrontPlane; | |
1275 | Standard_Real OldDepthCueingBackPlane; | |
1276 | Standard_Real NewDepthCueingBackPlane; | |
1277 | ||
81bba717 | 1278 | // To manage the depth cueing only in case of change. |
7fd59977 | 1279 | OldDepthCueingMode = MyContext.DepthCueingIsOn (); |
1280 | NewDepthCueingMode = CTX.DepthCueingIsOn (); | |
1281 | ||
1282 | OldDepthCueingFrontPlane = MyContext.DepthCueingFrontPlane (); | |
1283 | NewDepthCueingFrontPlane = CTX.DepthCueingFrontPlane (); | |
1284 | OldDepthCueingBackPlane = MyContext.DepthCueingBackPlane (); | |
1285 | NewDepthCueingBackPlane = CTX.DepthCueingBackPlane (); | |
1286 | ||
1287 | Standard_Boolean OldFrontZClippingMode; | |
1288 | Standard_Boolean NewFrontZClippingMode; | |
1289 | Standard_Boolean OldBackZClippingMode; | |
1290 | Standard_Boolean NewBackZClippingMode; | |
1291 | ||
1292 | Standard_Real OldZClippingFrontPlane; | |
1293 | Standard_Real NewZClippingFrontPlane; | |
1294 | Standard_Real OldZClippingBackPlane; | |
1295 | Standard_Real NewZClippingBackPlane; | |
1296 | ||
81bba717 | 1297 | // To manage the Zclipping only in case of change. |
7fd59977 | 1298 | OldFrontZClippingMode = MyContext.FrontZClippingIsOn (); |
1299 | NewFrontZClippingMode = CTX.FrontZClippingIsOn (); | |
1300 | OldBackZClippingMode = MyContext.BackZClippingIsOn (); | |
1301 | NewBackZClippingMode = CTX.BackZClippingIsOn (); | |
1302 | ||
1303 | OldZClippingFrontPlane = MyContext.ZClippingFrontPlane (); | |
1304 | NewZClippingFrontPlane = CTX.ZClippingFrontPlane (); | |
1305 | OldZClippingBackPlane = MyContext.ZClippingBackPlane (); | |
1306 | NewZClippingBackPlane = CTX.ZClippingBackPlane (); | |
1307 | ||
bf75be98 | 1308 | Handle(Graphic3d_TextureEnv) aTexEnvOld = MyContext.TextureEnv(); |
1309 | Handle(Graphic3d_TextureEnv) aTexEnvNew = CTX.TextureEnv(); | |
7fd59977 | 1310 | |
bf75be98 | 1311 | Visual3d_TypeOfSurfaceDetail OldSurfaceDetail = MyContext.SurfaceDetail(); |
1312 | Visual3d_TypeOfSurfaceDetail NewSurfaceDetail = CTX.SurfaceDetail(); | |
7fd59977 | 1313 | |
1314 | MyContext = CTX; | |
1315 | ||
1316 | UpdateView (); | |
1317 | ||
81bba717 | 1318 | Standard_Boolean AWait = Standard_False; // => immediate update |
7fd59977 | 1319 | if (IsDefined ()) { |
81bba717 | 1320 | // management of visualization modes and types of shading. |
7fd59977 | 1321 | if ((OldVisualMode != NewVisualMode) || (OldModel != NewModel)) |
1322 | MyGraphicDriver->SetVisualisation (MyCView); | |
1323 | ||
81bba717 | 1324 | // management of antialiasing. |
7fd59977 | 1325 | if (OldAliasingMode != NewAliasingMode) |
1326 | MyGraphicDriver->AntiAliasing (MyCView, NewAliasingMode); | |
1327 | ||
81bba717 | 1328 | // management of depth_cueing. |
7fd59977 | 1329 | if ((OldDepthCueingMode != NewDepthCueingMode) || |
1330 | (OldDepthCueingFrontPlane != NewDepthCueingFrontPlane) || | |
1331 | (OldDepthCueingBackPlane != NewDepthCueingBackPlane)) { | |
1332 | #ifdef BUC60572 | |
1333 | if( NewDepthCueingMode && | |
1334 | (NewDepthCueingBackPlane >= NewDepthCueingFrontPlane) ) | |
1335 | Visual3d_DepthCueingDefinitionError::Raise | |
1336 | ("Bad value for DepthCueingPlanes position"); | |
1337 | #endif | |
1338 | MyGraphicDriver->DepthCueing | |
1339 | (MyCView, NewDepthCueingMode); | |
1340 | } | |
1341 | ||
81bba717 | 1342 | // management of Zclipping |
7fd59977 | 1343 | if ((OldFrontZClippingMode != NewFrontZClippingMode) || |
1344 | (OldBackZClippingMode != NewBackZClippingMode) || | |
1345 | (OldZClippingFrontPlane != NewZClippingFrontPlane) || | |
1346 | (OldZClippingBackPlane != NewZClippingBackPlane)) { | |
1347 | #ifdef BUC60572 | |
1348 | if( NewBackZClippingMode && NewFrontZClippingMode && | |
1349 | (NewZClippingBackPlane >= NewZClippingFrontPlane) ) | |
1350 | Visual3d_ZClippingDefinitionError::Raise | |
1351 | ("Bad value for ZClippingPlanes position"); | |
1352 | #endif | |
1353 | MyGraphicDriver->ClipLimit (MyCView, AWait); | |
1354 | } | |
1355 | ||
81bba717 | 1356 | // management of textures |
bf75be98 | 1357 | if ((aTexEnvOld != aTexEnvNew) || (OldSurfaceDetail != NewSurfaceDetail)) |
1358 | { | |
7fd59977 | 1359 | MyGraphicDriver->Environment(MyCView); |
bf75be98 | 1360 | } |
7fd59977 | 1361 | |
81bba717 | 1362 | // Update of planes of model clipping |
7fd59977 | 1363 | UpdatePlanes (); |
1364 | ||
bf75be98 | 1365 | // Update of light sources |
7fd59977 | 1366 | UpdateLights (); |
1367 | } | |
1368 | ||
1369 | if (OldVisualMode != NewVisualMode) { | |
1370 | ||
1371 | /* | |
81bba717 | 1372 | * Change of context => |
1373 | * Remove structures that cannot be displayed | |
1374 | * in the new visualisation mode. | |
1375 | * It is not necessary to warn ViewManager as | |
1376 | * this structure should not disappear from | |
1377 | * the list of structures displayed in it. | |
7fd59977 | 1378 | */ |
1379 | Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure); | |
1380 | Visual3d_TypeOfAnswer Answer; | |
1381 | ||
1382 | Standard_Integer i = MyDisplayedStructure.Extent (); | |
1383 | ||
1384 | Graphic3d_SequenceOfStructure FooSequence; | |
1385 | ||
1386 | while (S1Iterator.More ()) { | |
1387 | Answer = AcceptDisplay (S1Iterator.Key ()); | |
bf75be98 | 1388 | // If the structure can't be displayed in the |
81bba717 | 1389 | // new context of the view, it is removed. |
7fd59977 | 1390 | if ((Answer == Visual3d_TOA_NO) || |
1391 | (Answer == Visual3d_TOA_COMPUTE)) | |
1392 | //Erase (S1Iterator.Key (), Aspect_TOU_WAIT); | |
1393 | FooSequence.Append (S1Iterator.Key ()); | |
1394 | ||
81bba717 | 1395 | // S1Iterator.Next () is located on the next structure |
7fd59977 | 1396 | S1Iterator.Next (); |
1397 | } | |
1398 | ||
1399 | Standard_Integer Length = FooSequence.Length (); | |
81bba717 | 1400 | // The stored structures are removed |
7fd59977 | 1401 | for (i=1; i<=Length; i++) |
1402 | Erase (FooSequence.Value (i), Aspect_TOU_WAIT); | |
1403 | if (Length != 0) FooSequence.Clear (); | |
1404 | ||
1405 | /* | |
81bba717 | 1406 | * Change of context => |
bf75be98 | 1407 | * Display structures that can be displayed |
81bba717 | 1408 | * with the new visualisation mode. |
bf75be98 | 1409 | * All structures with status Displayed are removed from the ViewManager |
1410 | * and displayed in the view directly, if the structure is not already | |
81bba717 | 1411 | * displayed and if the view accepts it in its context. |
7fd59977 | 1412 | */ |
1413 | ||
1414 | i = MyViewManager->NumberOfDisplayedStructures (); | |
1415 | Graphic3d_MapOfStructure Map; | |
1416 | MyViewManager->DisplayedStructures(Map); | |
1417 | Graphic3d_MapIteratorOfMapOfStructure it(Map); | |
1418 | ||
1419 | for (; it.More(); it.Next()) { | |
1420 | Handle(Graphic3d_Structure) SG = it.Key(); | |
1421 | if (! IsDisplayed (SG)) { | |
1422 | Answer = AcceptDisplay(SG); | |
bf75be98 | 1423 | // If the structure can be displayed in the |
81bba717 | 1424 | // new context of the view, it is displayed. |
7fd59977 | 1425 | if ((Answer == Visual3d_TOA_YES) || |
1426 | (Answer == Visual3d_TOA_COMPUTE)) | |
1427 | //Display (MyViewManager->DisplayedStructure (j), | |
1428 | //Aspect_TOU_WAIT); | |
1429 | FooSequence.Append (SG); | |
1430 | } | |
1431 | } | |
1432 | ||
1433 | Length = FooSequence.Length (); | |
81bba717 | 1434 | // The stored structures are displayed |
7fd59977 | 1435 | for (i=1; i<=Length; i++) |
1436 | Display (FooSequence.Value (i), Aspect_TOU_WAIT); | |
1437 | if (Length != 0) FooSequence.Clear (); | |
1438 | } | |
1439 | ||
1440 | if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update (); | |
1441 | ||
1442 | } | |
1443 | ||
1444 | const Visual3d_ContextView& Visual3d_View::Context () const { | |
1445 | ||
1446 | return (MyContext); | |
1447 | ||
1448 | } | |
1449 | ||
1450 | void Visual3d_View::DisplayedStructures (Graphic3d_MapOfStructure& SG) const | |
1451 | { | |
1452 | ||
1453 | if (IsDeleted ()) return; | |
1454 | ||
1455 | Graphic3d_MapIteratorOfMapOfStructure Iterator (MyDisplayedStructure); | |
1456 | ||
1457 | while (Iterator.More ()) { | |
1458 | SG.Add (Iterator.Key ()); | |
1459 | ||
81bba717 | 1460 | // Iterator.Next () is located on the next structure |
7fd59977 | 1461 | Iterator.Next (); |
1462 | } | |
1463 | ||
1464 | } | |
1465 | ||
1466 | void Visual3d_View::Activate () { | |
1467 | ||
1468 | if (IsDeleted ()) return; | |
1469 | ||
1470 | if (! IsDefined ()) | |
1471 | Visual3d_ViewDefinitionError::Raise ("Window not defined"); | |
1472 | ||
1473 | if (! IsActive ()) { | |
1474 | ||
1475 | MyGraphicDriver->ActivateView (MyCView); | |
1476 | MyGraphicDriver->Background (MyCView); | |
1477 | MyGraphicDriver->Transparency | |
1478 | (MyCView, MyViewManager->Transparency ()); | |
1479 | ||
1480 | MyCView.Active = 1; | |
1481 | ||
1482 | /* | |
81bba717 | 1483 | * Activation of a new view => |
1484 | * Display structures that can be displayed in this new view. | |
1485 | * All structures with status | |
bf75be98 | 1486 | * Displayed in ViewManager are returned and displayed in |
1487 | * the view directly, if the structure is not already | |
81bba717 | 1488 | * displayed and if the view accepts it in its context. |
7fd59977 | 1489 | */ |
1490 | ||
1491 | Visual3d_TypeOfAnswer Answer; | |
1492 | Graphic3d_MapOfStructure Map; | |
1493 | MyViewManager->DisplayedStructures(Map); | |
1494 | Graphic3d_MapIteratorOfMapOfStructure it(Map); | |
1495 | ||
1496 | for (; it.More(); it.Next()) { | |
1497 | Handle(Graphic3d_Structure) SG = it.Key(); | |
1498 | if (! IsDisplayed (SG)) { | |
1499 | Answer = AcceptDisplay(SG); | |
81bba717 | 1500 | // If the structure can be displayed in the |
1501 | // new context of the view, it is displayed. | |
7fd59977 | 1502 | if ((Answer == Visual3d_TOA_YES) || |
1503 | (Answer == Visual3d_TOA_COMPUTE)) | |
1504 | Display (SG,Aspect_TOU_WAIT); | |
1505 | } | |
1506 | } | |
1507 | ||
1508 | } | |
1509 | ||
81bba717 | 1510 | // If the activation/desactivation of ZBuffer should be automatic |
1511 | // depending on the presence or absence of facets. | |
7fd59977 | 1512 | if (MyViewManager->ZBufferAuto ()) { |
1513 | Standard_Boolean BContainsFacet = ContainsFacet (); | |
1514 | Standard_Boolean BZBuffer = ZBufferIsActivated (); | |
81bba717 | 1515 | // If the view contains facets |
1516 | // and if ZBuffer is not active | |
7fd59977 | 1517 | if (BContainsFacet && ! BZBuffer) |
1518 | SetZBufferActivity (1); | |
81bba717 | 1519 | // If the view does not contain facets |
1520 | // and if ZBuffer is active | |
7fd59977 | 1521 | if (! BContainsFacet && BZBuffer) |
1522 | SetZBufferActivity (0); | |
1523 | } | |
1524 | ||
1525 | if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update (); | |
1526 | ||
1527 | } | |
1528 | ||
1529 | Standard_Boolean Visual3d_View::IsActive () const { | |
1530 | ||
1531 | if (IsDeleted ()) return (Standard_False); | |
1532 | ||
1533 | if (MyCView.Active) | |
1534 | return (Standard_True); | |
1535 | else | |
1536 | return (Standard_False); | |
1537 | ||
1538 | } | |
1539 | ||
1540 | void Visual3d_View::Deactivate () { | |
1541 | ||
1542 | if (IsDeleted ()) return; | |
1543 | ||
1544 | if (! IsDefined ()) | |
1545 | Visual3d_ViewDefinitionError::Raise ("Window not defined"); | |
1546 | ||
1547 | if (IsActive ()) { | |
1548 | ||
1549 | MyGraphicDriver->DeactivateView (MyCView); | |
1550 | ||
1551 | /* | |
81bba717 | 1552 | * Deactivation of a view => |
1553 | * Removal of structures displayed in this view. | |
1554 | * All structures with status | |
bf75be98 | 1555 | * Displayed in ViewManager are returned and removed from |
1556 | * the view directly, if the structure is not already | |
81bba717 | 1557 | * displayed and if the view accepts it in its context. |
1558 | */ | |
7fd59977 | 1559 | |
1560 | Visual3d_TypeOfAnswer Answer; | |
1561 | Graphic3d_MapOfStructure Map; | |
1562 | MyViewManager->DisplayedStructures(Map); | |
1563 | Graphic3d_MapIteratorOfMapOfStructure it(Map); | |
1564 | ||
1565 | for (; it.More(); it.Next()) { | |
1566 | Handle(Graphic3d_Structure) SG = it.Key(); | |
1567 | if (! IsDisplayed (SG)) { | |
1568 | Answer = AcceptDisplay(SG); | |
81bba717 | 1569 | // If the structure was displayed it is removed. |
7fd59977 | 1570 | if ((Answer == Visual3d_TOA_YES) || |
1571 | (Answer == Visual3d_TOA_COMPUTE)) | |
1572 | Erase (SG,Aspect_TOU_WAIT); | |
1573 | } | |
1574 | } | |
1575 | ||
1576 | if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update (); | |
1577 | ||
81bba717 | 1578 | // No action currently possible in the view |
7fd59977 | 1579 | MyCView.Active = 0; |
1580 | } | |
1581 | ||
1582 | } | |
1583 | ||
1584 | void Visual3d_View::Redraw () { | |
1585 | ||
1586 | Redraw (MyViewManager->UnderLayer (), MyViewManager->OverLayer ()); | |
1587 | ||
1588 | } | |
1589 | ||
1590 | void Visual3d_View::Redraw (const Standard_Integer x, const Standard_Integer y, const Standard_Integer width, const Standard_Integer height) { | |
1591 | ||
1592 | Redraw (MyViewManager->UnderLayer (), MyViewManager->OverLayer (), x, y, width, height); | |
1593 | } | |
1594 | ||
1595 | void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer) { | |
1596 | ||
1597 | if (IsDeleted ()) return; | |
1598 | ||
1599 | if ((! IsDefined ()) || (! IsActive ())) return; | |
1600 | ||
1601 | if (! MyWindow->IsMapped ()) return; | |
1602 | ||
1603 | // san - 14/04/2004 - set up Z buffer state before redrawing | |
81bba717 | 1604 | // If the activation/desactivation of ZBuffer should be automatic |
1605 | // depending on the presence or absence of facets. | |
7fd59977 | 1606 | if (MyViewManager->ZBufferAuto ()) { |
1607 | Standard_Boolean BContainsFacet = ContainsFacet (); | |
1608 | Standard_Boolean BZBuffer = ZBufferIsActivated (); | |
81bba717 | 1609 | // If the view contains facets |
1610 | // and if ZBuffer is not active | |
7fd59977 | 1611 | if (BContainsFacet && ! BZBuffer) |
1612 | SetZBufferActivity (1); | |
81bba717 | 1613 | // If the view contains only facets |
1614 | // and if ZBuffer is active | |
7fd59977 | 1615 | if (! BContainsFacet && BZBuffer) |
1616 | SetZBufferActivity (0); | |
1617 | } | |
1618 | ||
1619 | Aspect_CLayer2d OverCLayer; | |
1620 | Aspect_CLayer2d UnderCLayer; | |
1621 | OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL; | |
1622 | if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer (); | |
1623 | if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer (); | |
1624 | MyGraphicDriver->Redraw (MyCView, UnderCLayer, OverCLayer); | |
1625 | ||
1626 | } | |
1627 | ||
1628 | void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer, const Standard_Integer x, const Standard_Integer y, const Standard_Integer width, const Standard_Integer height) { | |
1629 | ||
1630 | if (IsDeleted ()) return; | |
1631 | ||
1632 | if ((! IsDefined ()) || (! IsActive ())) return; | |
1633 | ||
1634 | if (! MyWindow->IsMapped ()) return; | |
1635 | ||
1636 | // san - 14/04/2004 - set up Z buffer state before redrawing | |
81bba717 | 1637 | // If activation/desactivation of ZBuffer should be automatic |
1638 | // depending on the presence or absence of facets. | |
7fd59977 | 1639 | if (MyViewManager->ZBufferAuto ()) { |
1640 | Standard_Boolean BContainsFacet = ContainsFacet (); | |
1641 | Standard_Boolean BZBuffer = ZBufferIsActivated (); | |
81bba717 | 1642 | // If the view contains facets |
1643 | // and if ZBuffer is not active | |
7fd59977 | 1644 | if (BContainsFacet && ! BZBuffer) |
1645 | SetZBufferActivity (1); | |
81bba717 | 1646 | // If the view contains only facets |
1647 | // and if ZBuffer is active | |
7fd59977 | 1648 | if (! BContainsFacet && BZBuffer) |
1649 | SetZBufferActivity (0); | |
1650 | } | |
1651 | ||
1652 | Aspect_CLayer2d OverCLayer; | |
1653 | Aspect_CLayer2d UnderCLayer; | |
1654 | OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL; | |
1655 | if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer (); | |
1656 | if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer (); | |
1657 | MyGraphicDriver->Redraw (MyCView, UnderCLayer, OverCLayer, x, y, width, height); | |
1658 | ||
1659 | } | |
1660 | ||
1661 | void Visual3d_View::Update () { | |
1662 | ||
1663 | Update (MyViewManager->UnderLayer (), MyViewManager->OverLayer ()); | |
1664 | ||
1665 | } | |
1666 | ||
1667 | void Visual3d_View::Update (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer) { | |
1668 | ||
1669 | if (IsDeleted ()) return; | |
1670 | ||
1671 | if ((! IsDefined ()) || (! IsActive ())) return; | |
1672 | ||
1673 | if (! MyWindow->IsMapped ()) return; | |
1674 | ||
eb4320f2 | 1675 | if (MyGraphicDriver->IsDeviceLost()) |
1676 | { | |
1677 | MyViewManager->ReComputeStructures(); | |
1678 | MyGraphicDriver->ResetDeviceLostFlag(); | |
1679 | } | |
1680 | ||
81bba717 | 1681 | // If activation/desactivation of ZBuffer should be automatic |
1682 | // depending on the presence or absence of facets. | |
7fd59977 | 1683 | if (MyViewManager->ZBufferAuto ()) { |
1684 | Standard_Boolean BContainsFacet = ContainsFacet (); | |
1685 | Standard_Boolean BZBuffer = ZBufferIsActivated (); | |
81bba717 | 1686 | // If the view contains facets |
1687 | // and if ZBuffer is not active | |
1688 | if (BContainsFacet && ! BZBuffer) | |
7fd59977 | 1689 | SetZBufferActivity (1); |
81bba717 | 1690 | // If the view does not contain facets |
1691 | // and if ZBuffer is active | |
7fd59977 | 1692 | if (! BContainsFacet && BZBuffer) |
1693 | SetZBufferActivity (0); | |
1694 | } | |
1695 | ||
1696 | Aspect_CLayer2d OverCLayer; | |
1697 | Aspect_CLayer2d UnderCLayer; | |
1698 | OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL; | |
1699 | if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer (); | |
1700 | if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer (); | |
1701 | //OSD::SetSignal (Standard_False); | |
1702 | MyGraphicDriver->Update (MyCView, UnderCLayer, OverCLayer); | |
1703 | //OSD::SetSignal (Standard_True); | |
1704 | ||
7fd59977 | 1705 | } |
1706 | ||
1707 | Visual3d_TypeOfAnswer Visual3d_View::AcceptDisplay (const Handle(Graphic3d_Structure)& AStructure) const { | |
1708 | ||
81bba717 | 1709 | // Return type of visualization of the view |
7fd59977 | 1710 | Visual3d_TypeOfVisualization ViewType = MyContext.Visualization (); |
1711 | ||
81bba717 | 1712 | // Return type of visualization of the structure |
7fd59977 | 1713 | Graphic3d_TypeOfStructure StructType = AStructure->Visual (); |
1714 | ||
1715 | Visual3d_TypeOfAnswer Result = Visual3d_TOA_NO; | |
1716 | ||
1717 | if (StructType == Graphic3d_TOS_ALL) | |
81bba717 | 1718 | // The structure accepts any type of view |
7fd59977 | 1719 | Result = Visual3d_TOA_YES; |
1720 | else { | |
1721 | if ((StructType == Graphic3d_TOS_SHADING) | |
1722 | && (ViewType == Visual3d_TOV_SHADING)) | |
1723 | Result = Visual3d_TOA_YES; | |
1724 | if ((StructType == Graphic3d_TOS_WIREFRAME) | |
1725 | && (ViewType == Visual3d_TOV_WIREFRAME)) | |
1726 | Result = Visual3d_TOA_YES; | |
1727 | if ((StructType == Graphic3d_TOS_COMPUTED) | |
1728 | && (ViewType == Visual3d_TOV_WIREFRAME)) | |
1729 | Result = Visual3d_TOA_COMPUTE; | |
1730 | if ((StructType == Graphic3d_TOS_COMPUTED) | |
1731 | && (ViewType == Visual3d_TOV_SHADING)) | |
1732 | Result = Visual3d_TOA_COMPUTE; | |
1733 | } | |
1734 | ||
1735 | #ifdef TRACE_ACCEPT | |
1736 | if (Result == Visual3d_TOA_YES) | |
1737 | cout << "YES = Visual3d_View" << MyCView.ViewId | |
1738 | << "::AcceptDisplay (" << AStructure->Identification () << ")\n"; | |
1739 | if (Result == Visual3d_TOA_NO) | |
1740 | cout << "NO = Visual3d_View" << MyCView.ViewId | |
1741 | << "::AcceptDisplay (" << AStructure->Identification () << ")\n"; | |
1742 | if (Result == Visual3d_TOA_COMPUTE) | |
1743 | cout << "COMPUTE = Visual3d_View" << MyCView.ViewId | |
1744 | << "::AcceptDisplay (" << AStructure->Identification () << ")\n"; | |
1745 | cout << flush; | |
1746 | #endif | |
1747 | ||
1748 | return (Result); | |
1749 | ||
1750 | } | |
1751 | ||
35e08fe8 | 1752 | void Visual3d_View::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer /*OldPriority*/, const Standard_Integer NewPriority) { |
7fd59977 | 1753 | |
1754 | if (IsDeleted ()) return; | |
1755 | if (! IsDefined ()) return; | |
1756 | if (! IsActive ()) return; | |
1757 | if (! IsDisplayed (AStructure)) return; | |
1758 | ||
1759 | Standard_Integer Index = IsComputed (AStructure); | |
de75ed09 | 1760 | if (Index != 0 && ComputedMode()) |
7fd59977 | 1761 | { |
1762 | #ifdef TRACE | |
1763 | Standard_Integer StructId = MyCOMPUTEDSequence.Value (Index)->Identification (); | |
1764 | cout << "Visual3d_View" << MyCView.ViewId << "::ChangeDisplayPriority (" | |
1765 | << AStructure->Identification () << "/" << StructId | |
1766 | << ", " << OldPriority << ", " << NewPriority << ")\n"; | |
1767 | cout << flush; | |
1768 | #endif | |
1769 | MyGraphicDriver->EraseStructure | |
1770 | (MyCView, | |
1771 | *(Graphic3d_CStructure *) | |
1772 | MyCOMPUTEDSequence.Value (Index)->CStructure ()); | |
1773 | MyGraphicDriver->DisplayStructure | |
1774 | (MyCView, | |
1775 | *(Graphic3d_CStructure *) | |
1776 | MyCOMPUTEDSequence.Value (Index)->CStructure (), | |
1777 | int (NewPriority)); | |
1778 | } | |
1779 | else { | |
1780 | #ifdef TRACE | |
1781 | Standard_Integer StructId = AStructure->Identification (); | |
1782 | cout << "Visual3d_View" << MyCView.ViewId << "::ChangeDisplayPriority (" | |
1783 | << AStructure->Identification () << "/" << StructId | |
1784 | << ", " << OldPriority << ", " << NewPriority << ")\n"; | |
1785 | cout << flush; | |
1786 | #endif | |
1787 | MyGraphicDriver->EraseStructure | |
1788 | (MyCView, | |
1789 | *(Graphic3d_CStructure *)AStructure->CStructure ()); | |
1790 | MyGraphicDriver->DisplayStructure | |
1791 | (MyCView, | |
1792 | *(Graphic3d_CStructure *)AStructure->CStructure (), | |
1793 | int (NewPriority)); | |
1794 | } | |
1795 | ||
1796 | } | |
1797 | ||
1798 | void Visual3d_View::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) { | |
1799 | ||
1800 | #ifdef TRACE_CLEAR | |
1801 | cout << "Visual3d_View" << MyCView.ViewId << "::Clear (" | |
1802 | << AStructure->Identification () << ")\n"; | |
1803 | cout << flush; | |
1804 | #endif | |
1805 | ||
1806 | Standard_Integer Index = IsComputed (AStructure); | |
1807 | if (Index != 0) { | |
1808 | #ifdef TRACE_CLEAR | |
81bba717 | 1809 | cout << "Structure " << AStructure->Identification () |
1810 | << " calculated in the view " | |
1811 | << Identification () << ", by structure " | |
7fd59977 | 1812 | << MyCOMPUTEDSequence.Value (Index)->Identification () |
81bba717 | 1813 | << " is emptied.\n"; |
7fd59977 | 1814 | cout << flush; |
1815 | #endif | |
1816 | MyCOMPUTEDSequence.Value (Index)->GraphicClear (WithDestruction); | |
1817 | MyCOMPUTEDSequence.Value (Index)->SetHLRValidation (Standard_False); | |
1818 | } | |
1819 | ||
1820 | } | |
1821 | ||
1822 | void Visual3d_View::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) { | |
1823 | ||
1824 | #ifdef TRACE_CONNECT | |
1825 | cout << "Visual3d_View" << MyCView.ViewId << "::Connect (" | |
1826 | << AMother->Identification () | |
1827 | << ADaughter->Identification () << ")\n"; | |
1828 | cout << flush; | |
1829 | #endif | |
1830 | ||
1831 | Standard_Integer IndexM = IsComputed (AMother); | |
1832 | Standard_Integer IndexD = IsComputed (ADaughter); | |
1833 | ||
1834 | if (IndexM != 0 && IndexD != 0) { | |
1835 | #ifdef TRACE_CONNECT | |
81bba717 | 1836 | cout << "Structure " << AMother->Identification () |
1837 | << " is connected to structure " | |
7fd59977 | 1838 | << ADaughter->Identification () << endl; |
81bba717 | 1839 | cout << "These structures are calculated.\n"; |
1840 | cout << "In the view " << Identification () | |
1841 | << "Structure " | |
7fd59977 | 1842 | << MyCOMPUTEDSequence.Value (IndexM)->Identification () |
81bba717 | 1843 | << " is connected to the structure " |
7fd59977 | 1844 | << MyCOMPUTEDSequence.Value (IndexD)->Identification () |
1845 | << endl; | |
1846 | #endif | |
1847 | MyCOMPUTEDSequence.Value (IndexM)->GraphicConnect (MyCOMPUTEDSequence.Value (IndexD)); | |
1848 | } | |
1849 | ||
1850 | } | |
1851 | ||
1852 | void Visual3d_View::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) { | |
1853 | ||
1854 | #ifdef TRACE_CONNECT | |
1855 | cout << "Visual3d_View" << MyCView.ViewId << "::Disconnect (" | |
1856 | << AMother->Identification () | |
1857 | << ADaughter->Identification () << ")\n"; | |
1858 | cout << flush; | |
1859 | #endif | |
1860 | ||
1861 | Standard_Integer IndexM = IsComputed (AMother); | |
1862 | Standard_Integer IndexD = IsComputed (ADaughter); | |
1863 | ||
1864 | if (IndexM != 0 && IndexD != 0) { | |
1865 | #ifdef TRACE_CONNECT | |
81bba717 | 1866 | cout << "Structure " << AMother->Identification () |
1867 | << " is disconnected from the structure " | |
7fd59977 | 1868 | << ADaughter->Identification () << endl; |
81bba717 | 1869 | cout << "These structures are calculated.\n"; |
1870 | cout << "In the view " << Identification () | |
1871 | << "Structure " | |
7fd59977 | 1872 | << MyCOMPUTEDSequence.Value (IndexM)->Identification () |
81bba717 | 1873 | << " is disconnected from the structure " |
7fd59977 | 1874 | << MyCOMPUTEDSequence.Value (IndexD)->Identification () |
1875 | << endl; | |
1876 | #endif | |
1877 | MyCOMPUTEDSequence.Value (IndexM)->GraphicDisconnect (MyCOMPUTEDSequence.Value (IndexD)); | |
1878 | } | |
1879 | ||
1880 | } | |
1881 | ||
1882 | void Visual3d_View::Display (const Handle(Graphic3d_Structure)& AStructure) { | |
1883 | ||
1884 | Display (AStructure, MyViewManager->UpdateMode ()); | |
1885 | ||
1886 | } | |
1887 | ||
1888 | void Visual3d_View::Display (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode) { | |
1889 | ||
1890 | if (IsDeleted ()) return; | |
1891 | if (! IsDefined ()) return; | |
1892 | if (! IsActive ()) return; | |
1893 | ||
81bba717 | 1894 | // If Display on a structure present in the list |
bf75be98 | 1895 | // of calculated structures while it is not |
81bba717 | 1896 | // or more, of calculated type => |
1897 | // - removes it as well as the associated old computed | |
1898 | // THis happens when hlhsr becomes again of type e | |
1899 | // non computed after SetVisual. | |
7fd59977 | 1900 | Standard_Integer Index = IsComputed (AStructure); |
1901 | ||
1902 | if ((Index != 0) && (AStructure->Visual () != Graphic3d_TOS_COMPUTED)) { | |
7fd59977 | 1903 | MyTOCOMPUTESequence.Remove (Index); |
1904 | MyCOMPUTEDSequence.Remove (Index); | |
7fd59977 | 1905 | Index = 0; |
1906 | } | |
1907 | ||
1908 | Visual3d_TypeOfAnswer Answer = AcceptDisplay (AStructure); | |
1909 | ||
7fd59977 | 1910 | if (Answer == Visual3d_TOA_NO) { |
7fd59977 | 1911 | return; |
1912 | } | |
1913 | ||
de75ed09 | 1914 | if (!ComputedMode()) |
1915 | { | |
1916 | Answer = Visual3d_TOA_YES; | |
1917 | } | |
7fd59977 | 1918 | |
1919 | if (Answer == Visual3d_TOA_YES ) { | |
7fd59977 | 1920 | if (IsDisplayed (AStructure)) return; |
1921 | MyGraphicDriver->DisplayStructure ( | |
1922 | MyCView, | |
1923 | *(Graphic3d_CStructure *)AStructure->CStructure (), | |
1924 | int (AStructure->DisplayPriority ()) | |
1925 | ); | |
1926 | MyDisplayedStructure.Add (AStructure); | |
1927 | if (AnUpdateMode == Aspect_TOU_ASAP) Update (); | |
1928 | } | |
1929 | ||
1930 | if (Answer == Visual3d_TOA_COMPUTE) { | |
7fd59977 | 1931 | if (Index != 0) { |
81bba717 | 1932 | // Already computed, is COMPUTED still valid? |
7fd59977 | 1933 | Standard_Integer OldStructId = |
1934 | MyCOMPUTEDSequence.Value (Index)->Identification (); | |
1935 | ||
81bba717 | 1936 | // Case COMPUTED valide |
7fd59977 | 1937 | if (MyCOMPUTEDSequence.Value (Index)->HLRValidation ()) { |
81bba717 | 1938 | // to be displayed |
7fd59977 | 1939 | if (! IsDisplayed (AStructure)) { |
1940 | MyDisplayedStructure.Add (AStructure); | |
1941 | MyGraphicDriver->DisplayStructure ( | |
1942 | MyCView, | |
1943 | *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure (), | |
1944 | int (AStructure->DisplayPriority ()) | |
1945 | ); | |
1946 | if (AnUpdateMode == Aspect_TOU_ASAP) Update (); | |
1947 | } | |
1948 | return; | |
1949 | } | |
1950 | ||
81bba717 | 1951 | // Case COMPUTED invalid |
7fd59977 | 1952 | else { |
81bba717 | 1953 | // Is there another valid representation ? |
1954 | // Find in the sequence of already calculated structures | |
1955 | // 1/ Structure having the same Owner as <AStructure> | |
1956 | // 2/ That is not <AStructure> | |
1957 | // 3/ The COMPUTED which of is valid | |
7fd59977 | 1958 | Standard_Integer NewIndex = HaveTheSameOwner (AStructure); |
1959 | ||
81bba717 | 1960 | // Case of COMPUTED invalid, WITH a valid of replacement |
7fd59977 | 1961 | if (NewIndex != 0) { |
81bba717 | 1962 | // to be displayed |
7fd59977 | 1963 | if (! IsDisplayed (AStructure)) { |
1964 | MyCOMPUTEDSequence.SetValue | |
1965 | (Index, MyCOMPUTEDSequence.Value (NewIndex)); | |
1966 | OldStructId = MyCOMPUTEDSequence.Value (NewIndex)-> | |
1967 | Identification (); | |
1968 | MyDisplayedStructure.Add (AStructure); | |
1969 | MyGraphicDriver->DisplayStructure ( | |
1970 | MyCView, | |
1971 | *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (NewIndex)->CStructure (), | |
1972 | int (AStructure->DisplayPriority ()) | |
1973 | ); | |
1974 | if (AnUpdateMode == Aspect_TOU_ASAP) Update (); | |
1975 | } | |
1976 | return; | |
1977 | } | |
1978 | ||
81bba717 | 1979 | // Cas COMPUTED invalid, WITHOUT a valid of replacement |
7fd59977 | 1980 | else { |
bf75be98 | 1981 | // COMPUTED is removed if displayed |
7fd59977 | 1982 | if (IsDisplayed (AStructure)) |
1983 | MyGraphicDriver->EraseStructure ( | |
1984 | MyCView, | |
1985 | *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure () | |
1986 | ); | |
1987 | } | |
1988 | } | |
1989 | } // if (Index != 0) | |
1990 | ||
1991 | // Compute + Validation | |
1992 | #ifdef OLD | |
1993 | Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this); | |
1994 | #else | |
1995 | Handle(Graphic3d_Structure) TheStructure; | |
1996 | TColStd_Array2OfReal ATrsf (0, 3, 0, 3); | |
1997 | AStructure->Transform (ATrsf); | |
1998 | if (Index != 0) { | |
1999 | TColStd_Array2OfReal Ident (0, 3, 0, 3); | |
2000 | Standard_Integer ii, jj; | |
2001 | for (ii=0; ii<=3; ii++) | |
2002 | for (jj=0; jj<=3; jj++) | |
2003 | Ident (ii, jj) = (ii == jj ? 1.0 : 0.0); | |
2004 | TheStructure = MyCOMPUTEDSequence.Value (Index); | |
2005 | TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE); | |
2006 | if (AStructure->IsTransformed ()) { | |
2007 | AStructure->Compute (this, ATrsf, TheStructure); | |
2008 | } | |
2009 | else { | |
2010 | AStructure->Compute (this, TheStructure); | |
2011 | } | |
2012 | } | |
2013 | else { | |
2014 | if (AStructure->IsTransformed ()) { | |
2015 | TheStructure = AStructure->Compute (this, ATrsf); | |
2016 | } | |
2017 | else { | |
2018 | TheStructure = AStructure->Compute (this); | |
2019 | } | |
2020 | } | |
2021 | #endif | |
2022 | TheStructure->SetHLRValidation (Standard_True); | |
2023 | ||
81bba717 | 2024 | // TOCOMPUTE and COMPUTED associated to sequences are added |
7fd59977 | 2025 | MyTOCOMPUTESequence.Append (AStructure); |
2026 | MyCOMPUTEDSequence.Append (TheStructure); | |
2027 | ||
81bba717 | 2028 | // The previous are removed if necessary |
7fd59977 | 2029 | if (Index != 0) { |
2030 | MyTOCOMPUTESequence.Remove (Index); | |
2031 | MyCOMPUTEDSequence.Remove (Index); | |
2032 | } | |
2033 | ||
81bba717 | 2034 | // Return type of visualisation of the view |
7fd59977 | 2035 | Visual3d_TypeOfVisualization ViewType = MyContext.Visualization (); |
2036 | ||
81bba717 | 2037 | // Of which type will be the computed ? |
7fd59977 | 2038 | Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) && |
2039 | (AStructure->ComputeVisual () != Graphic3d_TOS_SHADING)); | |
2040 | ||
2041 | Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) && | |
2042 | (AStructure->ComputeVisual () != Graphic3d_TOS_WIREFRAME)); | |
2043 | ||
2044 | if (ComputeWireframe) | |
2045 | TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME); | |
2046 | if (ComputeShading) | |
2047 | TheStructure->SetVisual (Graphic3d_TOS_SHADING); | |
2048 | ||
2049 | if (! ComputeShading && ! ComputeWireframe) | |
2050 | Answer = Visual3d_TOA_NO; | |
2051 | else | |
2052 | Answer = AcceptDisplay (TheStructure); | |
2053 | ||
2054 | if (AStructure->IsHighlighted()) { | |
2055 | TheStructure->SetHighlightColor (AStructure->HighlightColor ()); | |
2056 | TheStructure->GraphicHighlight (Aspect_TOHM_COLOR); | |
2057 | } | |
2058 | ||
bf75be98 | 2059 | // It is displayed only if the calculated structure |
81bba717 | 2060 | // has a proper type corresponding to the one of the view. |
7fd59977 | 2061 | if (Answer != Visual3d_TOA_NO) { |
2062 | if (! IsDisplayed (AStructure)) | |
2063 | MyDisplayedStructure.Add (AStructure); | |
2064 | MyGraphicDriver->DisplayStructure ( | |
2065 | MyCView, | |
2066 | *(Graphic3d_CStructure *)TheStructure->CStructure (), | |
2067 | int (AStructure->DisplayPriority ()) | |
2068 | ); | |
2069 | if (AnUpdateMode == Aspect_TOU_ASAP) Update (); | |
2070 | } | |
2071 | } // Visual3d_TOA_COMPUTE | |
2072 | } | |
2073 | ||
2074 | void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& AStructure) { | |
2075 | ||
2076 | if (IsDeleted ()) return; | |
2077 | ||
2078 | Erase (AStructure, MyViewManager->UpdateMode ()); | |
2079 | ||
2080 | } | |
2081 | ||
2082 | void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode) { | |
2083 | ||
2084 | Standard_Integer StructId; | |
2085 | ||
2086 | if (IsDeleted ()) return; | |
2087 | ||
bf75be98 | 2088 | // No test on window as the structure is displayed only if |
81bba717 | 2089 | // the window exists, so only one test is enough. |
7fd59977 | 2090 | if (IsDisplayed (AStructure)) { |
2091 | Visual3d_TypeOfAnswer Answer = AcceptDisplay (AStructure); | |
2092 | ||
de75ed09 | 2093 | if (!ComputedMode()) |
2094 | { | |
2095 | Answer = Visual3d_TOA_YES; | |
2096 | } | |
7fd59977 | 2097 | |
2098 | if (Answer != Visual3d_TOA_COMPUTE) { | |
2099 | MyGraphicDriver->EraseStructure ( | |
2100 | MyCView, | |
2101 | *(Graphic3d_CStructure *)AStructure->CStructure () | |
2102 | ); | |
2103 | } | |
2104 | ||
2105 | if (Answer == Visual3d_TOA_COMPUTE) { | |
2106 | Standard_Integer Index = IsComputed (AStructure); | |
2107 | #ifdef TRACE_COMP | |
2108 | cout << "Visual3d_View" << MyCView.ViewId << "::Erase (" | |
2109 | << AStructure->Identification () << ");\n"; | |
2110 | cout << "Index : " << Index << "\n"; | |
2111 | cout << flush; | |
2112 | #endif | |
de75ed09 | 2113 | |
2114 | if (Index != 0 && ComputedMode()) | |
7fd59977 | 2115 | { |
2116 | StructId = | |
2117 | MyCOMPUTEDSequence.Value (Index)->Identification (); | |
2118 | #ifdef TRACE_COMP | |
2119 | cout << "Structure " << AStructure->Identification () | |
81bba717 | 2120 | << " calculated, in the view " |
2121 | << Identification () << ", by the structure " | |
2122 | << StructId << " is removed. \n"; | |
7fd59977 | 2123 | cout << flush; |
2124 | #endif | |
2125 | MyGraphicDriver->EraseStructure | |
2126 | (MyCView, *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ()); | |
2127 | } | |
81bba717 | 2128 | // else is impossible |
7fd59977 | 2129 | } |
2130 | MyDisplayedStructure.Remove (AStructure); | |
2131 | if (AnUpdateMode == Aspect_TOU_ASAP) Update (); | |
2132 | } | |
2133 | ||
2134 | } | |
2135 | ||
2136 | void Visual3d_View::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) { | |
2137 | ||
2138 | #ifdef TRACE_HIGH | |
2139 | cout << "Visual3d_View" << MyCView.ViewId << "::Highlight (" | |
2140 | << AStructure->Identification () << ")\n"; | |
2141 | cout << flush; | |
2142 | #endif | |
2143 | ||
2144 | Standard_Integer Index = IsComputed (AStructure); | |
2145 | if (Index != 0) { | |
2146 | #ifdef TRACE_HIGH | |
81bba717 | 2147 | cout << "Structure " << AStructure->Identification () |
2148 | << " calculated, in the view " | |
2149 | << Identification () << ", by the structure " | |
7fd59977 | 2150 | << MyCOMPUTEDSequence.Value (Index)->Identification () |
81bba717 | 2151 | << " passes in highlight mode.\n"; |
7fd59977 | 2152 | cout << flush; |
2153 | #endif | |
2154 | (MyCOMPUTEDSequence.Value (Index))->SetHighlightColor | |
2155 | (AStructure->HighlightColor ()); | |
2156 | (MyCOMPUTEDSequence.Value (Index))->GraphicHighlight (AMethod); | |
2157 | } | |
2158 | ||
2159 | } | |
2160 | ||
2161 | void Visual3d_View::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) { | |
2162 | ||
2163 | #ifdef TRACE_TRSF | |
2164 | cout << "Visual3d_View" << MyCView.ViewId << "::Transform (" | |
2165 | << AStructure->Identification () << ")\n"; | |
2166 | cout << flush; | |
2167 | #endif | |
2168 | ||
2169 | Standard_Integer Index = IsComputed (AStructure); | |
2170 | if (Index != 0) { | |
2171 | #ifdef TRACE_TRSF | |
81bba717 | 2172 | cout << "The structure " << AStructure->Identification () |
2173 | << " calculated, in the view " | |
2174 | << Identification () << ", by the structure " | |
7fd59977 | 2175 | << MyCOMPUTEDSequence.Value (Index)->Identification () |
81bba717 | 2176 | << " is transformed.\n"; |
7fd59977 | 2177 | cout << flush; |
2178 | #endif | |
81bba717 | 2179 | // Test is somewhat light ! |
2180 | // trsf is transferred only if it is : | |
2181 | // a translation | |
2182 | // a scale | |
7fd59977 | 2183 | if (ATrsf (0, 1) != 0. || ATrsf (0, 2) != 0. |
2184 | || ATrsf (1, 0) != 0. || ATrsf (1, 2) != 0. | |
2185 | || ATrsf (2, 0) != 0. || ATrsf (2, 1) != 0.) | |
2186 | ReCompute (AStructure); | |
2187 | else | |
2188 | MyCOMPUTEDSequence.Value (Index)->GraphicTransform (ATrsf); | |
2189 | } | |
2190 | ||
2191 | } | |
2192 | ||
2193 | void Visual3d_View::UnHighlight (const Handle(Graphic3d_Structure)& AStructure) { | |
2194 | ||
2195 | #ifdef TRACE_HIGH | |
2196 | cout << "Visual3d_View" << MyCView.ViewId << "::UnHighlight (" | |
2197 | << AStructure->Identification () << ")\n"; | |
2198 | cout << flush; | |
2199 | #endif | |
2200 | ||
2201 | Standard_Integer Index = IsComputed (AStructure); | |
2202 | if (Index != 0) { | |
2203 | #ifdef TRACE_HIGH | |
81bba717 | 2204 | cout << "Structure " << AStructure->Identification () |
2205 | << " calculated, in the view " | |
2206 | << Identification () << ", by the structure " | |
7fd59977 | 2207 | << MyCOMPUTEDSequence.Value (Index)->Identification () |
81bba717 | 2208 | << " passes in unhighlight mode.\n"; |
7fd59977 | 2209 | cout << flush; |
2210 | #endif | |
2211 | MyCOMPUTEDSequence.Value (Index)->GraphicUnHighlight (); | |
2212 | } | |
2213 | ||
2214 | ||
2215 | } | |
2216 | ||
2217 | Standard_Integer Visual3d_View::IsComputed (const Handle(Graphic3d_Structure)& AStructure) const { | |
2218 | ||
2219 | Standard_Integer StrId = AStructure->Identification (); | |
2220 | ||
2221 | Standard_Integer Result = 0; | |
2222 | Standard_Integer Length = MyTOCOMPUTESequence.Length (); | |
2223 | ||
2224 | // Recherche de la structure <AStructure> dans la | |
2225 | // sequence des structures deja calculees | |
2226 | for (Standard_Integer i=1; i<=Length && Result==0; i++) | |
2227 | if ((MyTOCOMPUTESequence.Value (i))->Identification () | |
2228 | == StrId) Result = i; | |
2229 | #ifdef TRACE_ISCOMP | |
81bba717 | 2230 | cout << "\n In the view " << Identification () << " the structure "; |
7fd59977 | 2231 | if (Result != 0) |
81bba717 | 2232 | cout << StrId << " is calculated by " |
7fd59977 | 2233 | << MyCOMPUTEDSequence.Value (Result)->Identification () |
2234 | << "\n" << flush; | |
2235 | else | |
81bba717 | 2236 | cout << StrId << " is not calculated\n" << flush; |
7fd59977 | 2237 | #endif |
2238 | ||
2239 | #ifdef TRACE_LENGTH | |
2240 | if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) { | |
2241 | cout << "In Visual3d_View::IsComputed, "; | |
2242 | cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length () | |
2243 | << " != COMPUTED " << MyCOMPUTEDSequence.Length () | |
2244 | << "\n" << flush; | |
2245 | } | |
2246 | #endif | |
2247 | ||
2248 | return (Result); | |
2249 | ||
2250 | } | |
2251 | ||
2252 | Standard_Boolean Visual3d_View::IsDisplayed (const Handle(Graphic3d_Structure)& AStructure) const { | |
2253 | ||
2254 | Standard_Boolean Result = Standard_False; | |
2255 | ||
2256 | if (IsDeleted ()) return Result; | |
2257 | ||
2258 | Result = MyDisplayedStructure.Contains (AStructure); | |
2259 | ||
2260 | return Result; | |
2261 | ||
2262 | } | |
2263 | ||
2264 | #ifdef IMPLEMENTED | |
2265 | Standard_Boolean Visual3d_View::ContainsComputedStructure () const { | |
2266 | ||
2267 | Standard_Boolean Result = Standard_False; | |
2268 | ||
2269 | if (MyDisplayedStructure.IsEmpty ()) return Result; | |
2270 | ||
2271 | Graphic3d_MapIteratorOfMapOfStructure Iterator (MyDisplayedStructure); | |
2272 | ||
2273 | Standard_Integer i = MyDisplayedStructure.Extent (); | |
2274 | ||
81bba717 | 2275 | // Stop at the first structure of type TOS_COMPUTED |
7fd59977 | 2276 | while (! Result && Iterator.More ()) { |
2277 | Result = | |
2278 | (((Iterator.Key ())->Visual ()) == Graphic3d_TOS_COMPUTED); | |
2279 | ||
bf75be98 | 2280 | // Iterator.Next () is located on the |
81bba717 | 2281 | // next structure |
7fd59977 | 2282 | Iterator.Next (); |
2283 | } | |
2284 | ||
2285 | return Result; | |
2286 | ||
2287 | } | |
2288 | #endif | |
2289 | ||
2290 | Standard_Boolean Visual3d_View::ContainsFacet () const { | |
2291 | ||
2292 | return ContainsFacet (MyDisplayedStructure); | |
2293 | ||
2294 | } | |
2295 | ||
2296 | Standard_Boolean Visual3d_View::ContainsFacet (const Graphic3d_MapOfStructure& ASet) const { | |
2297 | ||
2298 | Standard_Boolean Result = Standard_False; | |
2299 | ||
2300 | if (ASet.IsEmpty ()) return Result; | |
2301 | ||
2302 | Graphic3d_MapIteratorOfMapOfStructure Iterator (ASet); | |
2303 | ||
81bba717 | 2304 | // Stop at the first structure containing a facet |
7fd59977 | 2305 | for ( Iterator.Initialize (ASet); |
2306 | Iterator.More () && ! Result; | |
2307 | Iterator.Next ()) | |
2308 | Result = (Iterator.Key ())->ContainsFacet (); | |
2309 | ||
2310 | return Result; | |
2311 | ||
2312 | } | |
2313 | ||
2314 | void Visual3d_View::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const { | |
2315 | ||
2316 | MinMaxValues | |
2317 | (MyDisplayedStructure, XMin, YMin, ZMin, XMax, YMax, ZMax); | |
2318 | ||
2319 | } | |
2320 | ||
2321 | void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& ASet, Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const { | |
2322 | ||
2323 | if (ASet.IsEmpty ()) { | |
2324 | XMin = RealFirst (); | |
2325 | YMin = RealFirst (); | |
2326 | ZMin = RealFirst (); | |
2327 | ||
2328 | XMax = RealLast (); | |
2329 | YMax = RealLast (); | |
2330 | ZMax = RealLast (); | |
2331 | } | |
2332 | else { | |
2333 | ||
2334 | Standard_Real Xm, Ym, Zm, XM, YM, ZM; | |
2335 | Graphic3d_MapIteratorOfMapOfStructure Iterator (ASet); | |
2336 | ||
2337 | XMin = RealLast (); | |
2338 | YMin = RealLast (); | |
2339 | ZMin = RealLast (); | |
2340 | ||
2341 | XMax = RealFirst (); | |
2342 | YMax = RealFirst (); | |
2343 | ZMax = RealFirst (); | |
2344 | ||
2345 | for ( Iterator.Initialize (ASet); | |
2346 | Iterator.More (); | |
2347 | Iterator.Next ()) { | |
2348 | ||
eb4320f2 | 2349 | if (!Iterator.Key()->IsVisible()) |
2350 | { | |
2351 | continue; | |
2352 | } | |
2353 | ||
7fd59977 | 2354 | if ( (Iterator.Key ())->IsInfinite ()){ |
2355 | //XMin, YMin .... ZMax are initialized by means of infinite line data | |
2356 | (Iterator.Key ())->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM); | |
2357 | if ( Xm != RealFirst() && Xm < XMin ) | |
2358 | XMin = Xm ; | |
2359 | if ( Ym != RealFirst() && Ym < YMin ) | |
2360 | YMin = Ym ; | |
2361 | if ( Zm != RealFirst() && Zm < ZMin ) | |
2362 | ZMin = Zm ; | |
2363 | if ( XM != RealLast() && XM > XMax ) | |
2364 | XMax = XM ; | |
2365 | if ( YM != RealLast() && YM > YMax ) | |
2366 | YMax = YM ; | |
2367 | if ( ZM != RealLast() && ZM > ZMax ) | |
2368 | ZMax = ZM ; | |
2369 | } | |
bf75be98 | 2370 | // Only non-empty and non-infinite structures |
81bba717 | 2371 | // are taken into account for calculation of MinMax |
7fd59977 | 2372 | if (! (Iterator.Key ())->IsInfinite () && |
2373 | ! (Iterator.Key ())->IsEmpty ()) { | |
2374 | (Iterator.Key ())->MinMaxValues(Xm, Ym, Zm, XM, YM, ZM); | |
2375 | /* ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */ | |
2376 | //"FitAll" operation ignores object with transform persitence parameter | |
2377 | if( (Iterator.Key ())->TransformPersistenceMode() == Graphic3d_TMF_None ) | |
2378 | { | |
2379 | if (Xm < XMin) XMin = Xm; | |
2380 | if (Ym < YMin) YMin = Ym; | |
2381 | if (Zm < ZMin) ZMin = Zm; | |
2382 | if (XM > XMax) XMax = XM; | |
2383 | if (YM > YMax) YMax = YM; | |
2384 | if (ZM > ZMax) ZMax = ZM; | |
2385 | } | |
2386 | } | |
2387 | } | |
2388 | ||
81bba717 | 2389 | // The following cases are relevant |
2390 | // For exemple if all structures are empty or infinite | |
7fd59977 | 2391 | if (XMax < XMin) { Xm = XMin; XMin = XMax; XMax = Xm; } |
2392 | if (YMax < YMin) { Ym = YMin; YMin = YMax; YMax = Ym; } | |
2393 | if (ZMax < ZMin) { Zm = ZMin; ZMin = ZMax; ZMax = Zm; } | |
2394 | } | |
2395 | Standard_Real Sx, Sy, Sz; | |
2396 | MyViewOrientation.AxialScale(Sx, Sy, Sz); | |
2397 | XMin = (Sx > 1. && XMin < RealFirst ()/Sx)?RealFirst (): XMin*Sx; | |
2398 | XMax = (Sx > 1. && XMax > RealLast ()/Sx)?RealLast (): XMax*Sx; | |
2399 | YMin = (Sy > 1. && YMin < RealFirst ()/Sy)?RealFirst (): YMin*Sy; | |
2400 | YMax = (Sy > 1. && YMax > RealLast ()/Sy)?RealLast (): YMax*Sy; | |
2401 | ZMin = (Sz > 1. && ZMin < RealFirst ()/Sz)?RealFirst (): ZMin*Sz; | |
2402 | ZMax = (Sz > 1. && ZMax > RealLast ()/Sz)?RealLast (): ZMax*Sz; | |
2403 | } | |
2404 | ||
2405 | void Visual3d_View::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& XMax, Standard_Real& YMax) { | |
2406 | ||
2407 | MinMaxValues (MyDisplayedStructure, XMin, YMin, XMax, YMax); | |
2408 | ||
2409 | } | |
2410 | ||
2411 | void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& ASet, Standard_Real& XMin, Standard_Real& YMin, Standard_Real& XMax, Standard_Real& YMax) { | |
2412 | ||
2413 | Standard_Real Xm, Ym, Zm, XM, YM, ZM; | |
2414 | Standard_Real Xp, Yp, Zp; | |
2415 | ||
2416 | MinMaxValues (ASet, Xm, Ym, Zm, XM, YM, ZM); | |
2417 | ||
2418 | Projects (Xm, Ym, Zm, Xp, Yp, Zp); | |
2419 | XMin = Xp; | |
2420 | YMin = Yp; | |
2421 | ||
2422 | Projects (XM, YM, ZM, Xp, Yp, Zp); | |
2423 | XMax = Xp; | |
2424 | YMax = Yp; | |
2425 | ||
2426 | if (XMax < XMin) { Xp = XMax; XMax = XMin; XMin = Xp; } | |
2427 | if (YMax < YMin) { Yp = YMax; YMax = YMin; YMin = Yp; } | |
2428 | } | |
2429 | ||
2430 | const TColStd_Array2OfReal& Visual3d_View::MatrixOfOrientation () { | |
2431 | ||
2432 | if (! MyMatOfOriIsEvaluated) { | |
2433 | MyGraphicDriver->InquireMat | |
2434 | (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping); | |
2435 | MyMatOfMapIsEvaluated = Standard_True; | |
2436 | MyMatOfOriIsEvaluated = Standard_True; | |
2437 | } | |
2438 | ||
2439 | return (MyMatrixOfOrientation); | |
2440 | ||
2441 | } | |
2442 | ||
2443 | const TColStd_Array2OfReal& Visual3d_View::MatrixOfMapping () { | |
2444 | ||
2445 | if (! MyMatOfMapIsEvaluated) { | |
2446 | MyGraphicDriver->InquireMat | |
2447 | (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping); | |
2448 | MyMatOfMapIsEvaluated = Standard_True; | |
2449 | MyMatOfOriIsEvaluated = Standard_True; | |
2450 | } | |
2451 | ||
2452 | return (MyMatrixOfMapping); | |
2453 | ||
2454 | } | |
2455 | ||
2456 | Standard_Integer Visual3d_View::NumberOfDisplayedStructures () const { | |
2457 | ||
2458 | Standard_Integer Result = MyDisplayedStructure.Extent (); | |
2459 | ||
2460 | return (Result); | |
2461 | ||
2462 | } | |
2463 | ||
2464 | #ifdef OLD_METHOD | |
2465 | void Visual3d_View::Projects (const Standard_Real AX, const Standard_Real AY, const Standard_Real AZ, Standard_Real& APX, Standard_Real& APY, Standard_Real& APZ) const { | |
2466 | ||
2467 | math_Vector PtDC (0,3), PtWC (0,3); | |
2468 | ||
2469 | // RLE method: | |
81bba717 | 2470 | // Otherwise use new on Visual3d_View (constructor+destructor) |
2471 | // as Projects is a const method or MatrixOfOrientation and | |
2472 | // MatrixOfMapping is not. | |
7fd59977 | 2473 | Visual3d_View * const newthis = (Visual3d_View * const) this; |
2474 | newthis->MatrixOfOrientation (); | |
2475 | newthis->MatrixOfMapping (); | |
2476 | ||
2477 | // World Coordinate Space | |
2478 | PtWC (0) = AX; | |
2479 | PtWC (1) = AY; | |
2480 | PtWC (2) = AZ; | |
2481 | PtWC (3) = 1.0; | |
2482 | ||
2483 | // WCS -> View Reference Coordinate Space | |
2484 | math_Vector PtVRC(0,3); | |
2485 | PtVRC = MyMatrixOfOrientation.Multiplied (PtWC); | |
2486 | ||
2487 | // VRCS -> Normalized Projection Coordinate Space | |
2488 | math_Vector PtNPC(0,3); | |
2489 | PtNPC = MyMatrixOfMapping.Multiplied (PtVRC); | |
2490 | for (Standard_Integer i=0; i<3; i++) PtNPC (i) = PtNPC (i) / PtNPC (3); | |
2491 | ||
2492 | #ifdef DEBUG | |
2493 | printf("Display coordinates PtNPC: %f,%f,%f,%f\n", | |
2494 | PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3)); | |
2495 | #endif // DEBUG | |
2496 | ||
2497 | Standard_Real Ratio; | |
2498 | #ifdef DEBUG | |
2499 | // NPCS -> Device Coordinate Space | |
2500 | Standard_Real Dx = Standard_Real (MyCView.DefWindow.dx); | |
2501 | Standard_Real Dy = Standard_Real (MyCView.DefWindow.dy); | |
2502 | ||
2503 | Ratio = Dx / Dy; | |
2504 | PtDC (0) = PtNPC (0) * Dx; | |
2505 | PtDC (1) = Dy - PtNPC (1) * Dy * Ratio; | |
2506 | ||
2507 | printf("Display coordinates : %f,%f,%f,%f\n", | |
2508 | PtDC(0),PtDC(1),PtDC(2),PtDC(3)); | |
2509 | #endif // DEBUG | |
2510 | ||
2511 | // NPCS -> Window Space | |
2512 | Standard_Real um, vm, uM, vM; | |
2513 | MyViewMapping.WindowLimit (um, vm, uM, vM); | |
2514 | ||
2515 | Ratio = (uM - um) / (vM - vm); | |
2516 | if (Ratio >= 1.0) | |
2517 | PtNPC (1) = PtNPC (1) * Ratio; | |
2518 | else | |
2519 | PtNPC (0) = PtNPC (0) / Ratio; | |
2520 | ||
2521 | #ifdef DEBUG | |
2522 | printf("Display coordinates PtNPC: %f,%f,%f,%f\n", | |
2523 | PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3)); | |
2524 | #endif // DEBUG | |
2525 | ||
2526 | Standard_Real fpd = MyViewMapping.FrontPlaneDistance (); | |
2527 | Standard_Real bpd = MyViewMapping.BackPlaneDistance (); | |
2528 | ||
2529 | /* | |
81bba717 | 2530 | * Coordinates of PtNPC are described in the space |
7fd59977 | 2531 | * [0-1]x[0-1]x[0-1]. |
81bba717 | 2532 | * It is necessary to transform x and y in the window space. |
2533 | * It is necessary to transform z in the space of back and front | |
2534 | * plane, taking into account clipping planes. | |
2535 | * Z clipping planes are defined between 0 and 1. | |
7fd59977 | 2536 | */ |
2537 | ||
2538 | APX = PtNPC (0) * (uM - um) + um; | |
2539 | APY = PtNPC (1) * (vM - vm) + vm; | |
2540 | APZ = PtNPC (2) * (fpd - bpd) + bpd; | |
2541 | ||
2542 | #ifdef DEBUG | |
2543 | Standard_Integer l,c; | |
2544 | printf("OrientationMatrix :"); | |
2545 | for( l=0 ; l<4 ; l++ ) { | |
2546 | printf("\n %d->",l); | |
2547 | for( c=0 ; c<4 ; c++ ) { | |
2548 | printf(" %f ,",MyMatrixOfOrientation(c,l)); | |
2549 | } | |
2550 | } | |
2551 | printf("\n\n"); | |
2552 | printf("MappingMatrix :"); | |
2553 | for( l=0 ; l<4 ; l++ ) { | |
2554 | printf("\n %d->",l); | |
2555 | for( c=0 ; c<4 ; c++ ) { | |
2556 | printf(" %f ,",MyMatrixOfMapping(c,l)); | |
2557 | } | |
2558 | } | |
2559 | printf("\n\n"); | |
2560 | printf("World coordinates : %f,%f,%f,%f\n", | |
2561 | PtWC(0),PtWC(1),PtWC(2),PtWC(3)); | |
2562 | printf("View coordinates : %f,%f,%f,%f\n", | |
2563 | PtVRC(0),PtVRC(1),PtVRC(2),PtVRC(3)); | |
2564 | printf("Display coordinates : %f,%f,%f,%f\n", | |
2565 | PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3)); | |
2566 | printf("Window limit : %f,%f,%f,%f\n",um,vm,uM,vM); | |
2567 | printf("Ratio : %f\n",Ratio); | |
2568 | printf("Front-plane : %f back-plane : %f\n",fpd,bpd); | |
2569 | printf("Projection : %f,%f,%f\n \n",APX,APY,APZ); | |
2570 | #endif | |
2571 | ||
2572 | } | |
2573 | #endif /* OLD_METHOD */ | |
2574 | ||
2575 | // OCC18942: This method is likely to duplicate Visual3d_ViewManager::ConvertCoord() one, | |
2576 | // therefore it is necessary to consider merging the two methods or making them call the same | |
2577 | // graphic driver's method after OCCT 6.3. | |
2578 | void Visual3d_View::Projects (const Standard_Real AX, const Standard_Real AY, const Standard_Real AZ, Standard_Real& APX, Standard_Real& APY, Standard_Real& APZ) { | |
2579 | ||
2580 | Standard_Real PtX, PtY, PtZ, PtT; | |
2581 | Standard_Real APT; | |
2582 | static Standard_Real Ratio, um, vm, uM, vM; | |
2583 | static Standard_Real fpd, bpd; | |
2584 | ||
2585 | if (! MyMatOfOriIsEvaluated || ! MyMatOfMapIsEvaluated) { | |
2586 | MyGraphicDriver->InquireMat | |
2587 | (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping); | |
2588 | MyMatOfOriIsEvaluated = MyMatOfMapIsEvaluated = Standard_True; | |
2589 | } | |
2590 | ||
2591 | // WCS -> View Reference Coordinate Space | |
2592 | PtX = MyMatrixOfOrientation (0, 0) * AX | |
2593 | + MyMatrixOfOrientation (0, 1) * AY | |
2594 | + MyMatrixOfOrientation (0, 2) * AZ | |
2595 | + MyMatrixOfOrientation (0, 3); | |
2596 | PtY = MyMatrixOfOrientation (1, 0) * AX | |
2597 | + MyMatrixOfOrientation (1, 1) * AY | |
2598 | + MyMatrixOfOrientation (1, 2) * AZ | |
2599 | + MyMatrixOfOrientation (1, 3); | |
2600 | PtZ = MyMatrixOfOrientation (2, 0) * AX | |
2601 | + MyMatrixOfOrientation (2, 1) * AY | |
2602 | + MyMatrixOfOrientation (2, 2) * AZ | |
2603 | + MyMatrixOfOrientation (2, 3); | |
2604 | PtT = MyMatrixOfOrientation (3, 0) * AX | |
2605 | + MyMatrixOfOrientation (3, 1) * AY | |
2606 | + MyMatrixOfOrientation (3, 2) * AZ | |
2607 | + MyMatrixOfOrientation (3, 3); | |
2608 | ||
2609 | // VRCS -> Normalized Projection Coordinate Space | |
2610 | APX = MyMatrixOfMapping (0, 0) * PtX | |
2611 | + MyMatrixOfMapping (0, 1) * PtY | |
2612 | + MyMatrixOfMapping (0, 2) * PtZ | |
2613 | + MyMatrixOfMapping (0, 3) * PtT; | |
2614 | APY = MyMatrixOfMapping (1, 0) * PtX | |
2615 | + MyMatrixOfMapping (1, 1) * PtY | |
2616 | + MyMatrixOfMapping (1, 2) * PtZ | |
2617 | + MyMatrixOfMapping (1, 3) * PtT; | |
2618 | APZ = MyMatrixOfMapping (2, 0) * PtX | |
2619 | + MyMatrixOfMapping (2, 1) * PtY | |
2620 | + MyMatrixOfMapping (2, 2) * PtZ | |
2621 | + MyMatrixOfMapping (2, 3) * PtT; | |
2622 | APT = MyMatrixOfMapping (3, 0) * PtX | |
2623 | + MyMatrixOfMapping (3, 1) * PtY | |
2624 | + MyMatrixOfMapping (3, 2) * PtZ | |
2625 | + MyMatrixOfMapping (3, 3) * PtT; | |
2626 | ||
2627 | APX /= APT; | |
2628 | APY /= APT; | |
2629 | APZ /= APT; | |
2630 | ||
2631 | // NPCS -> Window Space | |
2632 | MyViewMapping.WindowLimit (um, vm, uM, vM); | |
2633 | fpd = MyViewMapping.FrontPlaneDistance (); | |
2634 | bpd = MyViewMapping.BackPlaneDistance (); | |
2635 | ||
2636 | if(MyCView.Mapping.IsCustomMatrix) { | |
2637 | // OCC18942: SAN - If orientation and mapping matrices are those used by OpenGL | |
2638 | // visualization, then X, Y and Z coordinates normally vary between -1 and 1 | |
2639 | APX = ( APX + 1 ) * 0.5 * (uM - um) + um; | |
2640 | APY = ( APY + 1 ) * 0.5 * (vM - vm) + vm; | |
2641 | } else { | |
2642 | Ratio = (uM - um) / (vM - vm); | |
2643 | if (Ratio >= 1.0) | |
2644 | APY *= Ratio; | |
2645 | else | |
2646 | APX /= Ratio; | |
2647 | ||
2648 | /* | |
81bba717 | 2649 | * Coordinates of APX, APY, APZ are described in the space |
2650 | * [0-1]x[0-1]x[0-1]. | |
2651 | * It is necessary to transform x and y in the window space. | |
2652 | * It is necessary to transform z in the space of back and front | |
2653 | * plane, taking into account clipping planes. | |
2654 | * Z clipping planes are defined between 0 and 1. | |
2655 | */ | |
7fd59977 | 2656 | APX = APX * (uM - um) + um; |
2657 | APY = APY * (vM - vm) + vm; | |
2658 | } | |
2659 | APZ = APZ * (fpd - bpd) + bpd; | |
2660 | } | |
2661 | ||
2662 | Standard_Integer Visual3d_View::Identification () const { | |
2663 | ||
2664 | return (Standard_Integer (MyCView.ViewId)); | |
2665 | ||
2666 | } | |
2667 | ||
7fd59977 | 2668 | |
2669 | Standard_Boolean Visual3d_View::ZBufferIsActivated () const { | |
2670 | ||
2671 | if (IsDeleted ()) return (Standard_False); | |
2672 | ||
2673 | if ((! IsDefined ()) || (! IsActive ())) return (Standard_False); | |
2674 | ||
81bba717 | 2675 | // -1 => not forced by the programmer => depends on the type of visualisation |
2676 | // 0 ou 1 => forced by the programmer | |
7fd59977 | 2677 | |
2678 | if (MyCView.Context.ZBufferActivity == -1) | |
2679 | if (MyContext.Visualization () == Visual3d_TOV_SHADING) | |
2680 | return (Standard_True); | |
2681 | else | |
2682 | return (Standard_False); | |
2683 | else | |
2684 | if (MyCView.Context.ZBufferActivity) | |
2685 | return (Standard_True); | |
2686 | else | |
2687 | return (Standard_False); | |
2688 | ||
2689 | } | |
2690 | ||
2691 | void Visual3d_View::SetTransparency (const Standard_Boolean AnActivity) { | |
2692 | ||
2693 | if (IsDeleted ()) return; | |
2694 | ||
2695 | if ((! IsDefined ()) || (! IsActive ())) return; | |
2696 | ||
2697 | MyGraphicDriver->Transparency (MyCView, AnActivity); | |
2698 | ||
2699 | } | |
2700 | ||
2701 | void Visual3d_View::SetZBufferActivity (const Standard_Integer AnActivity) { | |
2702 | ||
2703 | if (MyCView.Context.ZBufferActivity == AnActivity) return; | |
2704 | ||
2705 | if (IsDeleted ()) return; | |
2706 | ||
2707 | if ((! IsDefined ()) || (! IsActive ())) return; | |
2708 | ||
2709 | MyCView.Context.ZBufferActivity = AnActivity; | |
2710 | MyGraphicDriver->SetVisualisation (MyCView); | |
2711 | ||
2712 | } | |
2713 | ||
2714 | void Visual3d_View::UpdateView () { | |
2715 | ||
2716 | MyCView.Context.Aliasing = (MyContext.AliasingIsOn () ? 1:0); | |
2717 | MyCView.Context.BackZClipping = | |
2718 | (MyContext.BackZClippingIsOn () ? 1:0); | |
2719 | MyCView.Context.FrontZClipping = | |
2720 | (MyContext.FrontZClippingIsOn() ? 1:0); | |
2721 | MyCView.Context.DepthCueing = | |
2722 | (MyContext.DepthCueingIsOn () ? 1:0); | |
2723 | ||
2724 | MyCView.Context.ZClipFrontPlane = | |
2725 | float (MyContext.ZClippingFrontPlane ()); | |
2726 | MyCView.Context.ZClipBackPlane = | |
2727 | float (MyContext.ZClippingBackPlane ()); | |
2728 | MyCView.Context.DepthFrontPlane = | |
2729 | float (MyContext.DepthCueingFrontPlane ()); | |
2730 | MyCView.Context.DepthBackPlane = | |
2731 | float (MyContext.DepthCueingBackPlane ()); | |
2732 | ||
2733 | MyCView.Context.Model = int (MyContext.Model ()); | |
2734 | MyCView.Context.Visualization = int (MyContext.Visualization ()); | |
2735 | ||
bf75be98 | 2736 | MyCView.Context.TextureEnv = MyContext.TextureEnv(); |
7fd59977 | 2737 | MyCView.Context.SurfaceDetail = MyContext.SurfaceDetail(); |
2738 | ||
2739 | } | |
2740 | ||
2741 | void Visual3d_View::Compute () { | |
2742 | ||
2743 | Standard_Integer i; | |
2744 | Standard_Integer Length = MyCOMPUTEDSequence.Length (); | |
2745 | for (i=1; i<=Length; i++) | |
2746 | (MyCOMPUTEDSequence.Value (i))->SetHLRValidation (Standard_False); | |
2747 | ||
de75ed09 | 2748 | if (!ComputedMode()) |
2749 | { | |
2750 | return; | |
2751 | } | |
7fd59977 | 2752 | |
2753 | /* | |
81bba717 | 2754 | * Force HLRValidation to False on all structures |
2755 | * calculated in the view. | |
7fd59977 | 2756 | */ |
2757 | #ifdef TRACE_LENGTH | |
2758 | if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) { | |
2759 | cout << "In Visual3d_View::Compute, "; | |
2760 | cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length () | |
2761 | << " != COMPUTED " << MyCOMPUTEDSequence.Length () | |
2762 | << "\n" << flush; | |
2763 | } | |
2764 | #endif | |
2765 | ||
2766 | /* | |
81bba717 | 2767 | * Change of orientation or of projection type => |
2768 | * Remove structures that were calculated for the | |
2769 | * previous orientation. | |
2770 | * Recalculation of new structures. | |
7fd59977 | 2771 | */ |
2772 | Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure); | |
2773 | Visual3d_TypeOfAnswer Answer; | |
2774 | ||
2775 | i = MyDisplayedStructure.Extent (); | |
2776 | ||
2777 | Graphic3d_SequenceOfStructure FooSequence; | |
2778 | ||
2779 | while (S1Iterator.More ()) { | |
2780 | Answer = AcceptDisplay (S1Iterator.Key ()); | |
81bba717 | 2781 | // If the structure was calculated, it is recalculated. |
7fd59977 | 2782 | if (Answer == Visual3d_TOA_COMPUTE) { |
2783 | #ifdef TRACE | |
2784 | cout << "AcceptDisplay (" | |
2785 | << (S1Iterator.Key ())->Identification () | |
2786 | << ") == Visual3d_TOA_COMPUTE;\n"; | |
2787 | cout << flush; | |
2788 | #endif | |
2789 | //Display (S1Iterator.Key (), Aspect_TOU_WAIT); | |
2790 | FooSequence.Append (S1Iterator.Key ()); | |
2791 | } | |
2792 | ||
81bba717 | 2793 | // S1Iterator.Next () is located on the next structure |
7fd59977 | 2794 | S1Iterator.Next (); |
2795 | } | |
2796 | ||
2797 | Length = FooSequence.Length (); | |
81bba717 | 2798 | // All stored structures are displayed |
7fd59977 | 2799 | for (i=1; i<=Length; i++) |
2800 | Display (FooSequence.Value (i), Aspect_TOU_WAIT); | |
2801 | if (Length != 0) FooSequence.Clear (); | |
2802 | ||
2803 | } | |
2804 | ||
2805 | void Visual3d_View::ReCompute (const Handle(Graphic3d_Structure)& AStructure) { | |
de75ed09 | 2806 | if (!ComputedMode()) return; |
7fd59977 | 2807 | |
2808 | if (IsDeleted ()) return; | |
2809 | ||
2810 | if ((! IsDefined ()) || (! IsActive ())) return; | |
2811 | ||
2812 | if (! MyWindow->IsMapped ()) return; | |
2813 | ||
2814 | if (! AStructure->IsDisplayed ()) return; | |
2815 | ||
2816 | Visual3d_TypeOfAnswer Answer; | |
2817 | ||
2818 | Answer = AcceptDisplay (AStructure); | |
2819 | ||
2820 | if (Answer == Visual3d_TOA_COMPUTE) { | |
2821 | Standard_Integer Index = IsComputed (AStructure); | |
2822 | if (Index == 0) { | |
2823 | #ifdef TRACE_COMP | |
81bba717 | 2824 | cout << "Structure " << AStructure->Identification () |
2825 | << " is not calculated in the view " | |
7fd59977 | 2826 | << Identification () << "\n"; |
2827 | cout << flush; | |
2828 | #endif | |
2829 | } | |
2830 | else { | |
2831 | Standard_Integer OldStructId, NewStructId; | |
2832 | OldStructId = | |
2833 | MyCOMPUTEDSequence.Value (Index)->Identification (); | |
2834 | #ifdef TRACE_COMP | |
2835 | Standard_Integer StructId = AStructure->Identification (); | |
81bba717 | 2836 | cout << "Structure " << StructId |
2837 | << " calculated, in the view " | |
2838 | << Identification () << ", by the structure " | |
2839 | << OldStructId << " is recalculated.\n"; | |
7fd59977 | 2840 | cout << flush; |
2841 | #endif | |
2842 | ||
2843 | // Compute + Validation | |
2844 | #ifdef OLD | |
2845 | Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this); | |
2846 | #else | |
2847 | Handle(Graphic3d_Structure) TheStructure; | |
2848 | TColStd_Array2OfReal ATrsf (0, 3, 0, 3); | |
2849 | AStructure->Transform (ATrsf); | |
2850 | if (Index != 0) { | |
2851 | TColStd_Array2OfReal Ident (0, 3, 0, 3); | |
2852 | Standard_Integer ii, jj; | |
2853 | for (ii=0; ii<=3; ii++) | |
2854 | for (jj=0; jj<=3; jj++) | |
2855 | Ident (ii, jj) = (ii == jj ? 1.0 : 0.0); | |
2856 | TheStructure = MyCOMPUTEDSequence.Value (Index); | |
2857 | TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE); | |
2858 | if (AStructure->IsTransformed ()) { | |
2859 | AStructure->Compute (this, ATrsf, TheStructure); | |
2860 | } | |
2861 | else { | |
2862 | AStructure->Compute (this, TheStructure); | |
2863 | } | |
2864 | } | |
2865 | else { | |
2866 | if (AStructure->IsTransformed ()) { | |
2867 | TheStructure = AStructure->Compute (this, ATrsf); | |
2868 | } | |
2869 | else { | |
2870 | TheStructure = AStructure->Compute (this); | |
2871 | } | |
2872 | } | |
2873 | #endif | |
2874 | TheStructure->SetHLRValidation (Standard_True); | |
2875 | ||
81bba717 | 2876 | // Return type of visualisation of the view |
7fd59977 | 2877 | Visual3d_TypeOfVisualization ViewType = MyContext.Visualization (); |
2878 | ||
81bba717 | 2879 | // Of which type will be the computed ? |
7fd59977 | 2880 | Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) && |
2881 | (AStructure->ComputeVisual () != Graphic3d_TOS_SHADING)); | |
2882 | ||
2883 | Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) && | |
2884 | (AStructure->ComputeVisual () != Graphic3d_TOS_WIREFRAME)); | |
2885 | ||
2886 | if (ComputeWireframe) | |
2887 | TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME); | |
2888 | if (ComputeShading) | |
2889 | TheStructure->SetVisual (Graphic3d_TOS_SHADING); | |
2890 | ||
2891 | if (AStructure->IsHighlighted ()) { | |
2892 | TheStructure->SetHighlightColor | |
2893 | (AStructure->HighlightColor ()); | |
2894 | TheStructure->GraphicHighlight (Aspect_TOHM_COLOR); | |
2895 | } | |
2896 | ||
81bba717 | 2897 | // Ot is ranged |
2898 | // Find structure <AStructure> | |
2899 | // in the sequence of structures to be calculated. | |
7fd59977 | 2900 | NewStructId = TheStructure->Identification (); |
2901 | ||
81bba717 | 2902 | // The previous calculation is removed and the new one is dislayed |
7fd59977 | 2903 | MyGraphicDriver->EraseStructure ( |
2904 | MyCView, | |
2905 | *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ()); | |
2906 | MyGraphicDriver->DisplayStructure ( | |
2907 | MyCView, | |
2908 | *(Graphic3d_CStructure *)TheStructure->CStructure (), | |
2909 | int (AStructure->DisplayPriority ()) | |
2910 | ); | |
2911 | ||
2912 | #ifdef TRACE_LENGTH | |
2913 | if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) { | |
2914 | cout << "In Visual3d_View::ReCompute, "; | |
2915 | cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length () | |
2916 | << " != COMPUTED " << MyCOMPUTEDSequence.Length () | |
2917 | << "\n" << flush; | |
2918 | } | |
2919 | #endif | |
2920 | ||
81bba717 | 2921 | // hlhsr and the new associated compute are added |
7fd59977 | 2922 | MyTOCOMPUTESequence.Append (AStructure); |
2923 | MyCOMPUTEDSequence.Append (TheStructure); | |
2924 | ||
2925 | #ifdef TRACE_LENGTH | |
2926 | if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) | |
2927 | cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length () | |
2928 | << " != COMPUTED " << MyCOMPUTEDSequence.Length () | |
2929 | << "\n" << flush; | |
2930 | #endif | |
2931 | ||
bf75be98 | 2932 | // hlhsr and the new associated compute are removed |
7fd59977 | 2933 | |
2934 | MyTOCOMPUTESequence.Remove (Index); | |
2935 | MyCOMPUTEDSequence.Remove (Index); | |
2936 | ||
2937 | #ifdef TRACE_LENGTH | |
2938 | if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) | |
2939 | cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length () | |
2940 | << " != COMPUTED " << MyCOMPUTEDSequence.Length () | |
2941 | << "\n" << flush; | |
2942 | #endif | |
2943 | } | |
2944 | } | |
2945 | ||
2946 | } | |
2947 | ||
6942f04a | 2948 | const Handle(Graphic3d_GraphicDriver)& Visual3d_View::GraphicDriver () const { |
7fd59977 | 2949 | |
2950 | return MyGraphicDriver; | |
2951 | ||
2952 | } | |
2953 | ||
de75ed09 | 2954 | void Visual3d_View::Plot (const Handle(Graphic3d_Plotter)& thePlotter) const |
2955 | { | |
2956 | for (Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure); S1Iterator.More(); S1Iterator.Next()) | |
2957 | { | |
2958 | Standard_Integer Index = IsComputed (S1Iterator.Key ()); | |
2959 | // displayed structure is plotted as if it was not calculated | |
2960 | if (Index == 0) | |
2961 | (S1Iterator.Key ())->Plot (thePlotter); | |
2962 | else | |
2963 | (MyCOMPUTEDSequence.Value (Index))->Plot (thePlotter); | |
2964 | } | |
7fd59977 | 2965 | } |
2966 | ||
2967 | Standard_Integer Visual3d_View::HaveTheSameOwner (const Handle(Graphic3d_Structure)& AStructure) const { | |
2968 | ||
2969 | Standard_Integer Result = 0; | |
2970 | Standard_Integer Length = MyTOCOMPUTESequence.Length (); | |
2971 | ||
bf75be98 | 2972 | // Find in the sequence of already calculated structures |
81bba717 | 2973 | // 1/ Structure with the same Owner as <AStructure> |
2974 | // 2/ Which is not <AStructure> | |
2975 | // 3/ COMPUTED which of is valid | |
7fd59977 | 2976 | for (Standard_Integer i=1; i<=Length && Result==0; i++) |
2977 | if ((MyTOCOMPUTESequence.Value (i)->Owner () == AStructure->Owner ()) | |
2978 | && (MyTOCOMPUTESequence.Value (i)->Identification () != | |
2979 | AStructure->Identification ()) | |
2980 | && (MyCOMPUTEDSequence.Value (i)->HLRValidation ())) Result = i; | |
2981 | ||
2982 | return (Result); | |
2983 | ||
2984 | } | |
2985 | ||
2986 | Standard_Address Visual3d_View::CView () const { | |
2987 | ||
2988 | return Standard_Address (&MyCView); | |
2989 | ||
2990 | } | |
2991 | ||
2992 | ||
2993 | // Triedron methods : the Triedron is a non-zoomable object. | |
2994 | ||
2995 | void Visual3d_View::ZBufferTriedronSetup(const Quantity_NameOfColor XColor, | |
2996 | const Quantity_NameOfColor YColor, | |
2997 | const Quantity_NameOfColor ZColor, | |
2998 | const Standard_Real SizeRatio, | |
2999 | const Standard_Real AxisDiametr, | |
3000 | const Standard_Integer NbFacettes) { | |
3001 | MyGraphicDriver->ZBufferTriedronSetup(XColor, YColor, ZColor, | |
3002 | SizeRatio, AxisDiametr, NbFacettes); | |
3003 | } | |
3004 | ||
3005 | ||
3006 | ||
3007 | void Visual3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition APosition, | |
3008 | const Quantity_NameOfColor AColor, const Standard_Real AScale, const Standard_Boolean AsWireframe ) { | |
3009 | ||
3010 | MyGraphicDriver->TriedronDisplay (MyCView,APosition, AColor, AScale, AsWireframe); | |
3011 | ||
3012 | } | |
3013 | ||
3014 | void Visual3d_View::TriedronErase () { | |
3015 | ||
3016 | MyGraphicDriver->TriedronErase (MyCView); | |
3017 | ||
3018 | ||
3019 | } | |
3020 | ||
3021 | void Visual3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho AType ) { | |
3022 | ||
3023 | MyGraphicDriver->TriedronEcho (MyCView,AType); | |
3024 | ||
3025 | } | |
3026 | ||
3027 | Standard_Boolean checkFloat(const Standard_Real value) | |
3028 | { | |
3029 | return value > -FLT_MAX && value < FLT_MAX; | |
3030 | } | |
3031 | ||
3032 | void SetMinMaxValuesCallback(void* Visual3dView) | |
3033 | { | |
3034 | Standard_Real xmin, ymin, zmin, xmax, ymax, zmax; | |
3035 | ||
3036 | Handle(Visual3d_View) view = (Handle(Visual3d_View)&) Visual3dView; | |
3037 | view->MinMaxValues(xmin, ymin, zmin, xmax, ymax, zmax); | |
3038 | ||
3039 | if (checkFloat(xmin) && checkFloat(ymin) && checkFloat(zmin) && | |
3040 | checkFloat(xmax) && checkFloat(ymax) && checkFloat(zmax)) | |
3041 | { | |
3042 | Handle(Graphic3d_GraphicDriver) driver = Handle(Graphic3d_GraphicDriver)::DownCast(view->GraphicDriver()); | |
3043 | driver->GraduatedTrihedronMinMaxValues((Standard_ShortReal)xmin, (Standard_ShortReal)ymin, (Standard_ShortReal)zmin, | |
3044 | (Standard_ShortReal)xmax, (Standard_ShortReal)ymax, (Standard_ShortReal)zmax); | |
3045 | } | |
3046 | } | |
3047 | ||
13a22457 S |
3048 | Standard_Boolean Visual3d_View::GetGraduatedTrihedron |
3049 | (/* Names of axes */ | |
3050 | TCollection_ExtendedString& xname, | |
3051 | TCollection_ExtendedString& yname, | |
3052 | TCollection_ExtendedString& zname, | |
3053 | /* Draw names */ | |
3054 | Standard_Boolean& xdrawname, | |
3055 | Standard_Boolean& ydrawname, | |
3056 | Standard_Boolean& zdrawname, | |
3057 | /* Draw values */ | |
3058 | Standard_Boolean& xdrawvalues, | |
3059 | Standard_Boolean& ydrawvalues, | |
3060 | Standard_Boolean& zdrawvalues, | |
3061 | /* Draw grid */ | |
3062 | Standard_Boolean& drawgrid, | |
3063 | /* Draw axes */ | |
3064 | Standard_Boolean& drawaxes, | |
3065 | /* Number of splits along axes */ | |
3066 | Standard_Integer& nbx, | |
3067 | Standard_Integer& nby, | |
3068 | Standard_Integer& nbz, | |
3069 | /* Offset for drawing values */ | |
3070 | Standard_Integer& xoffset, | |
3071 | Standard_Integer& yoffset, | |
3072 | Standard_Integer& zoffset, | |
3073 | /* Offset for drawing names of axes */ | |
3074 | Standard_Integer& xaxisoffset, | |
3075 | Standard_Integer& yaxisoffset, | |
3076 | Standard_Integer& zaxisoffset, | |
3077 | /* Draw tickmarks */ | |
3078 | Standard_Boolean& xdrawtickmarks, | |
3079 | Standard_Boolean& ydrawtickmarks, | |
3080 | Standard_Boolean& zdrawtickmarks, | |
3081 | /* Length of tickmarks */ | |
3082 | Standard_Integer& xtickmarklength, | |
3083 | Standard_Integer& ytickmarklength, | |
3084 | Standard_Integer& ztickmarklength, | |
3085 | /* Grid color */ | |
3086 | Quantity_Color& gridcolor, | |
3087 | /* Colors of axis names */ | |
3088 | Quantity_Color& xnamecolor, | |
3089 | Quantity_Color& ynamecolor, | |
3090 | Quantity_Color& znamecolor, | |
3091 | /* Colors of axis and values */ | |
3092 | Quantity_Color& xcolor, | |
3093 | Quantity_Color& ycolor, | |
3094 | Quantity_Color& zcolor, | |
3095 | /* Name of font for names of axes */ | |
3096 | TCollection_AsciiString& fontOfNames, | |
3097 | /* Style of names of axes */ | |
eeaaaefb | 3098 | Font_FontAspect& styleOfNames, |
13a22457 S |
3099 | /* Size of names of axes */ |
3100 | Standard_Integer& sizeOfNames, | |
3101 | /* Name of font for values */ | |
3102 | TCollection_AsciiString& fontOfValues, | |
3103 | /* Style of values */ | |
eeaaaefb | 3104 | Font_FontAspect& styleOfValues, |
13a22457 S |
3105 | /* Size of values */ |
3106 | Standard_Integer& sizeOfValues) const | |
7fd59977 | 3107 | { |
13a22457 S |
3108 | if (!MyGTrihedron.ptrVisual3dView) |
3109 | return Standard_False; | |
3110 | ||
3111 | /* Names of axes */ | |
3112 | xname = MyGTrihedron.xname; | |
bf75be98 | 3113 | yname = MyGTrihedron.yname; |
13a22457 S |
3114 | zname = MyGTrihedron.zname; |
3115 | /* Draw names */ | |
bf75be98 | 3116 | xdrawname = MyGTrihedron.xdrawname; |
3117 | ydrawname = MyGTrihedron.ydrawname; | |
13a22457 S |
3118 | zdrawname = MyGTrihedron.zdrawname; |
3119 | /* Draw values */ | |
bf75be98 | 3120 | xdrawvalues = MyGTrihedron.xdrawvalues; |
3121 | ydrawvalues = MyGTrihedron.ydrawvalues; | |
13a22457 S |
3122 | zdrawvalues = MyGTrihedron.zdrawvalues; |
3123 | /* Draw grid */ | |
3124 | drawgrid = MyGTrihedron.drawgrid; | |
3125 | /* Draw axes */ | |
3126 | drawaxes = MyGTrihedron.drawaxes; | |
3127 | /* Number of splits along axes */ | |
3128 | nbx = MyGTrihedron.nbx; | |
3129 | nby = MyGTrihedron.nby; | |
3130 | nbz = MyGTrihedron.nbz; | |
3131 | /* Offset for drawing values */ | |
3132 | xoffset = MyGTrihedron.xoffset; | |
3133 | yoffset = MyGTrihedron.yoffset; | |
3134 | zoffset = MyGTrihedron.zoffset; | |
3135 | /* Offset for drawing names of axes */ | |
3136 | xaxisoffset = MyGTrihedron.xaxisoffset; | |
3137 | yaxisoffset = MyGTrihedron.yaxisoffset; | |
3138 | zaxisoffset = MyGTrihedron.zaxisoffset; | |
3139 | /* Draw tickmarks */ | |
3140 | xdrawtickmarks = MyGTrihedron.xdrawtickmarks; | |
3141 | ydrawtickmarks = MyGTrihedron.ydrawtickmarks; | |
3142 | zdrawtickmarks = MyGTrihedron.zdrawtickmarks; | |
3143 | /* Length of tickmarks */ | |
3144 | xtickmarklength = MyGTrihedron.xtickmarklength; | |
3145 | ytickmarklength = MyGTrihedron.ytickmarklength; | |
3146 | ztickmarklength = MyGTrihedron.ztickmarklength; | |
3147 | /* Grid color */ | |
3148 | gridcolor = MyGTrihedron.gridcolor; | |
3149 | /* Colors of axis names */ | |
3150 | xnamecolor = MyGTrihedron.xnamecolor; | |
3151 | ynamecolor = MyGTrihedron.ynamecolor; | |
3152 | znamecolor = MyGTrihedron.znamecolor; | |
3153 | /* Colors of axis and values */ | |
3154 | xcolor = MyGTrihedron.xcolor; | |
3155 | ycolor = MyGTrihedron.ycolor; | |
3156 | zcolor = MyGTrihedron.zcolor; | |
3157 | /* Name of font for names of axes */ | |
3158 | fontOfNames = MyGTrihedron.fontOfNames; | |
3159 | /* Style of names of axes */ | |
3160 | styleOfNames = MyGTrihedron.styleOfNames; | |
3161 | /* Size of names of axes */ | |
3162 | sizeOfNames = MyGTrihedron.sizeOfNames; | |
3163 | /* Name of font for values */ | |
3164 | fontOfValues = MyGTrihedron.fontOfValues; | |
3165 | /* Style of values */ | |
3166 | styleOfValues = MyGTrihedron.styleOfValues; | |
3167 | /* Size of values */ | |
3168 | sizeOfValues = MyGTrihedron.sizeOfValues; | |
3169 | ||
3170 | return Standard_True; | |
3171 | } | |
3172 | ||
3173 | void Visual3d_View::GraduatedTrihedronDisplay | |
3174 | (/* Names of axes */ | |
3175 | const TCollection_ExtendedString &xname, | |
3176 | const TCollection_ExtendedString &yname, | |
3177 | const TCollection_ExtendedString &zname, | |
3178 | /* Draw names */ | |
3179 | const Standard_Boolean xdrawname, | |
3180 | const Standard_Boolean ydrawname, | |
3181 | const Standard_Boolean zdrawname, | |
3182 | /* Draw values */ | |
3183 | const Standard_Boolean xdrawvalues, | |
3184 | const Standard_Boolean ydrawvalues, | |
3185 | const Standard_Boolean zdrawvalues, | |
3186 | /* Draw grid */ | |
3187 | const Standard_Boolean drawgrid, | |
3188 | /* Draw axes */ | |
3189 | const Standard_Boolean drawaxes, | |
3190 | /* Number of splits along axes */ | |
3191 | const Standard_Integer nbx, | |
3192 | const Standard_Integer nby, | |
3193 | const Standard_Integer nbz, | |
3194 | /* Offset for drawing values */ | |
3195 | const Standard_Integer xoffset, | |
3196 | const Standard_Integer yoffset, | |
3197 | const Standard_Integer zoffset, | |
3198 | /* Offset for drawing names of axes */ | |
3199 | const Standard_Integer xaxisoffset, | |
3200 | const Standard_Integer yaxisoffset, | |
3201 | const Standard_Integer zaxisoffset, | |
3202 | /* Draw tickmarks */ | |
3203 | const Standard_Boolean xdrawtickmarks, | |
3204 | const Standard_Boolean ydrawtickmarks, | |
3205 | const Standard_Boolean zdrawtickmarks, | |
3206 | /* Length of tickmarks */ | |
3207 | const Standard_Integer xtickmarklength, | |
3208 | const Standard_Integer ytickmarklength, | |
3209 | const Standard_Integer ztickmarklength, | |
3210 | /* Grid color */ | |
3211 | const Quantity_Color& gridcolor, | |
3212 | /* Colors of axis names */ | |
3213 | const Quantity_Color& xnamecolor, | |
3214 | const Quantity_Color& ynamecolor, | |
3215 | const Quantity_Color& znamecolor, | |
3216 | /* Colors of axis and values */ | |
3217 | const Quantity_Color& xcolor, | |
3218 | const Quantity_Color& ycolor, | |
3219 | const Quantity_Color& zcolor, | |
3220 | /* Name of font for names of axes */ | |
3221 | const TCollection_AsciiString &fontOfNames, | |
3222 | /* Style of names of axes */ | |
eeaaaefb | 3223 | const Font_FontAspect styleOfNames, |
13a22457 S |
3224 | /* Size of names of axes */ |
3225 | const Standard_Integer sizeOfNames, | |
3226 | /* Name of font for values */ | |
3227 | const TCollection_AsciiString &fontOfValues, | |
3228 | /* Style of values */ | |
eeaaaefb | 3229 | const Font_FontAspect styleOfValues, |
13a22457 S |
3230 | /* Size of values */ |
3231 | const Standard_Integer sizeOfValues) | |
7fd59977 | 3232 | { |
13a22457 S |
3233 | /* Names of axes */ |
3234 | MyGTrihedron.xname = xname; | |
3235 | MyGTrihedron.yname = yname; | |
3236 | MyGTrihedron.zname = zname; | |
3237 | /* Draw names */ | |
3238 | MyGTrihedron.xdrawname = xdrawname; | |
3239 | MyGTrihedron.ydrawname = ydrawname; | |
3240 | MyGTrihedron.zdrawname = zdrawname; | |
3241 | /* Draw values */ | |
3242 | MyGTrihedron.xdrawvalues = xdrawvalues; | |
3243 | MyGTrihedron.ydrawvalues = ydrawvalues; | |
3244 | MyGTrihedron.zdrawvalues = zdrawvalues; | |
3245 | /* Draw grid */ | |
3246 | MyGTrihedron.drawgrid = drawgrid; | |
3247 | /* Draw axes */ | |
3248 | MyGTrihedron.drawaxes = drawaxes; | |
3249 | /* Number of splits along axes */ | |
3250 | MyGTrihedron.nbx = nbx; | |
3251 | MyGTrihedron.nby = nby; | |
3252 | MyGTrihedron.nbz = nbz; | |
3253 | /* Offset for drawing values */ | |
3254 | MyGTrihedron.xoffset = xoffset; | |
3255 | MyGTrihedron.yoffset = yoffset; | |
3256 | MyGTrihedron.zoffset = zoffset; | |
3257 | /* Offset for drawing names of axes */ | |
3258 | MyGTrihedron.xaxisoffset = xaxisoffset; | |
3259 | MyGTrihedron.yaxisoffset = yaxisoffset; | |
3260 | MyGTrihedron.zaxisoffset = zaxisoffset; | |
3261 | /* Draw tickmarks */ | |
3262 | MyGTrihedron.xdrawtickmarks = xdrawtickmarks; | |
3263 | MyGTrihedron.ydrawtickmarks = ydrawtickmarks; | |
3264 | MyGTrihedron.zdrawtickmarks = zdrawtickmarks; | |
3265 | /* Length of tickmarks */ | |
3266 | MyGTrihedron.xtickmarklength = xtickmarklength; | |
3267 | MyGTrihedron.ytickmarklength = ytickmarklength; | |
3268 | MyGTrihedron.ztickmarklength = ztickmarklength; | |
3269 | /* Grid color */ | |
3270 | MyGTrihedron.gridcolor = gridcolor; | |
3271 | /* Colors of axis names */ | |
3272 | MyGTrihedron.xnamecolor = xnamecolor; | |
3273 | MyGTrihedron.ynamecolor = ynamecolor; | |
3274 | MyGTrihedron.znamecolor = znamecolor; | |
3275 | /* Colors of axis and values */ | |
3276 | MyGTrihedron.xcolor = xcolor; | |
3277 | MyGTrihedron.ycolor = ycolor; | |
3278 | MyGTrihedron.zcolor = zcolor; | |
3279 | /* Name of font for names of axes */ | |
3280 | MyGTrihedron.fontOfNames = fontOfNames; | |
3281 | /* Style of names of axes */ | |
3282 | MyGTrihedron.styleOfNames = styleOfNames; | |
3283 | /* Size of names of axes */ | |
3284 | MyGTrihedron.sizeOfNames = sizeOfNames; | |
3285 | /* Name of font for values */ | |
3286 | MyGTrihedron.fontOfValues = fontOfValues; | |
3287 | /* Style of values */ | |
3288 | MyGTrihedron.styleOfValues = styleOfValues; | |
3289 | /* Size of values */ | |
3290 | MyGTrihedron.sizeOfValues = sizeOfValues; | |
3291 | ||
3292 | MyGTrihedron.ptrVisual3dView = this; | |
3293 | MyGTrihedron.cbCubicAxes = SetMinMaxValuesCallback; | |
3294 | MyGraphicDriver->GraduatedTrihedronDisplay(MyCView,MyGTrihedron); | |
7fd59977 | 3295 | } |
3296 | ||
3297 | void Visual3d_View::GraduatedTrihedronErase() | |
3298 | { | |
13a22457 | 3299 | MyGTrihedron.ptrVisual3dView = NULL; |
7fd59977 | 3300 | MyGraphicDriver->GraduatedTrihedronErase(MyCView); |
3301 | } | |
3302 | ||
3303 | const Handle(Visual3d_Layer)& Visual3d_View::UnderLayer () const { | |
3304 | ||
3305 | return (MyViewManager->UnderLayer ()); | |
3306 | ||
3307 | } | |
3308 | ||
3309 | const Handle(Visual3d_Layer)& Visual3d_View::OverLayer () const { | |
3310 | ||
3311 | return (MyViewManager->OverLayer ()); | |
3312 | ||
3313 | } | |
3314 | ||
3315 | Standard_Integer Visual3d_View::LightLimit() const { | |
3316 | ||
3317 | Standard_Integer maxlight = MyGraphicDriver->InquireLightLimit (); | |
3318 | // printf(" $$$ Visual3d_View::LightLimit() is %d\n",maxlight); | |
3319 | return maxlight; | |
3320 | } | |
3321 | ||
3322 | Standard_Integer Visual3d_View::PlaneLimit() const { | |
3323 | ||
3324 | Standard_Integer maxplane = MyGraphicDriver->InquirePlaneLimit (); | |
3325 | // printf(" $$$ Visual3d_View::PlaneLimit() is %d\n",maxplane); | |
3326 | return maxplane; | |
3327 | } | |
3328 | ||
bf75be98 | 3329 | Handle(Visual3d_ViewManager) Visual3d_View::ViewManager() const |
3330 | { | |
3331 | return MyPtrViewManager; | |
7fd59977 | 3332 | } |
7fd59977 | 3333 | |
de75ed09 | 3334 | void Visual3d_View :: SetComputedMode ( const Standard_Boolean aMode ) |
3335 | { | |
3336 | if ((aMode && ComputedModeIsActive) || | |
3337 | (!aMode && !ComputedModeIsActive)) | |
3338 | { | |
3339 | return; | |
3340 | } | |
7fd59977 | 3341 | |
3342 | Graphic3d_MapIteratorOfMapOfStructure S1Iterator ( MyDisplayedStructure ); | |
3343 | Visual3d_TypeOfAnswer Answer; | |
3344 | Standard_Integer StructId; | |
3345 | Standard_Integer i = MyDisplayedStructure.Extent (); | |
773f53f1 | 3346 | ComputedModeIsActive = aMode; |
3347 | if (!ComputedModeIsActive) { | |
7fd59977 | 3348 | |
3349 | while ( S1Iterator.More () ) { | |
3350 | ||
3351 | Answer = AcceptDisplay ( S1Iterator.Key () ); | |
3352 | ||
3353 | if ( Answer == Visual3d_TOA_COMPUTE ) { | |
3354 | ||
3355 | Standard_Integer Index = IsComputed ( S1Iterator.Key () ); | |
3356 | ||
3357 | if ( Index != 0 ) { | |
3358 | ||
3359 | StructId = MyCOMPUTEDSequence.Value ( Index ) -> Identification (); | |
3360 | ||
3361 | MyGraphicDriver -> EraseStructure ( | |
3362 | MyCView, | |
3363 | *( Graphic3d_CStructure* ) | |
3364 | MyCOMPUTEDSequence.Value ( Index ) -> CStructure () | |
3365 | ); | |
3366 | MyGraphicDriver -> DisplayStructure ( | |
3367 | MyCView, | |
3368 | *( Graphic3d_CStructure* ) | |
3369 | S1Iterator.Key () -> CStructure (), | |
3370 | int ( S1Iterator.Key () -> DisplayPriority () ) | |
3371 | ); | |
3372 | } // end if ( Index != 0 ) . . . | |
3373 | ||
3374 | } // end if ( Answer . . . ) | |
3375 | ||
3376 | S1Iterator.Next (); | |
3377 | ||
3378 | } // end while | |
3379 | ||
3380 | } else { | |
3381 | ||
3382 | while ( S1Iterator.More () ) { | |
3383 | ||
3384 | Answer = AcceptDisplay ( S1Iterator.Key () ); | |
3385 | ||
3386 | if ( Answer == Visual3d_TOA_COMPUTE ) { | |
3387 | ||
3388 | Standard_Integer Index = IsComputed ( S1Iterator.Key () ); | |
3389 | ||
3390 | if ( Index != 0 ) { | |
3391 | ||
3392 | StructId = MyCOMPUTEDSequence.Value ( Index ) -> Identification (); | |
3393 | ||
3394 | MyGraphicDriver -> EraseStructure ( | |
3395 | MyCView, | |
3396 | *( Graphic3d_CStructure* ) | |
3397 | S1Iterator.Key () -> CStructure () | |
3398 | ); | |
3399 | MyGraphicDriver -> DisplayStructure ( | |
3400 | MyCView, | |
3401 | *( Graphic3d_CStructure* ) | |
3402 | MyCOMPUTEDSequence.Value ( Index ) -> CStructure (), | |
3403 | int ( S1Iterator.Key () -> DisplayPriority () ) | |
3404 | ); | |
3405 | ||
3406 | Display ( S1Iterator.Key (), Aspect_TOU_WAIT ); | |
3407 | ||
3408 | if ( S1Iterator.Key () -> IsHighlighted () ) { | |
3409 | ||
3410 | if ( !MyCOMPUTEDSequence.Value ( Index ) -> IsHighlighted () ) { | |
3411 | ||
3412 | MyCOMPUTEDSequence.Value ( Index ) -> SetHighlightColor ( | |
3413 | S1Iterator.Key () -> | |
3414 | HighlightColor () | |
3415 | ); | |
3416 | MyCOMPUTEDSequence.Value ( Index ) -> GraphicHighlight ( | |
3417 | Aspect_TOHM_COLOR | |
3418 | ); | |
3419 | } // end if | |
3420 | ||
3421 | } // end if | |
3422 | ||
3423 | } else { | |
3424 | ||
3425 | Handle( Graphic3d_Structure ) AStructure = S1Iterator.Key (); | |
3426 | #ifdef OLD | |
3427 | Handle( Graphic3d_Structure ) TheStructure = AStructure -> Compute ( this ); | |
3428 | #else | |
3429 | Handle( Graphic3d_Structure ) TheStructure; | |
3430 | TColStd_Array2OfReal ATrsf ( 0, 3, 0, 3 ); | |
3431 | ||
3432 | AStructure -> Transform ( ATrsf ); | |
3433 | ||
3434 | if ( Index != 0 ) { | |
3435 | ||
3436 | TColStd_Array2OfReal Ident ( 0, 3, 0, 3 ); | |
3437 | Standard_Integer ii, jj; | |
3438 | ||
3439 | for ( ii = 0; ii <= 3; ++ii ) | |
3440 | ||
3441 | for ( jj = 0; jj <= 3; ++jj ) | |
3442 | ||
3443 | Ident ( ii, jj ) = ( ii == jj ? 1.0 : 0.0 ); | |
3444 | ||
3445 | TheStructure = MyCOMPUTEDSequence.Value ( Index ); | |
3446 | ||
3447 | TheStructure -> SetTransform ( Ident, Graphic3d_TOC_REPLACE ); | |
3448 | ||
3449 | if ( AStructure->IsTransformed () ) | |
3450 | ||
3451 | AStructure -> Compute ( this, ATrsf, TheStructure ); | |
3452 | ||
3453 | else | |
3454 | ||
3455 | AStructure -> Compute ( this, TheStructure ); | |
3456 | ||
3457 | } else { | |
3458 | ||
3459 | if ( AStructure -> IsTransformed () ) | |
3460 | ||
3461 | TheStructure = AStructure -> Compute ( this, ATrsf ); | |
3462 | ||
3463 | else | |
3464 | ||
3465 | TheStructure = AStructure -> Compute ( this ); | |
3466 | ||
3467 | } // end else | |
3468 | #endif // OLD | |
3469 | TheStructure -> SetHLRValidation ( Standard_True ); | |
3470 | ||
3471 | Visual3d_TypeOfVisualization ViewType = MyContext.Visualization (); | |
3472 | ||
3473 | Standard_Boolean ComputeWireframe = | |
3474 | ( ( ViewType == Visual3d_TOV_WIREFRAME ) && | |
3475 | ( S1Iterator.Key () -> ComputeVisual () != Graphic3d_TOS_SHADING ) | |
3476 | ); | |
3477 | ||
3478 | Standard_Boolean ComputeShading = | |
3479 | ( ( ViewType == Visual3d_TOV_SHADING ) && | |
3480 | ( S1Iterator.Key () -> ComputeVisual () != Graphic3d_TOS_WIREFRAME ) | |
3481 | ); | |
3482 | ||
3483 | if ( ComputeWireframe ) TheStructure -> SetVisual ( Graphic3d_TOS_WIREFRAME ); | |
3484 | if ( ComputeShading ) TheStructure -> SetVisual ( Graphic3d_TOS_SHADING ); | |
3485 | ||
3486 | if ( S1Iterator.Key () -> IsHighlighted () ) { | |
3487 | ||
3488 | TheStructure -> SetHighlightColor ( | |
3489 | S1Iterator.Key () -> HighlightColor () | |
3490 | ); | |
3491 | TheStructure -> GraphicHighlight ( Aspect_TOHM_COLOR ); | |
3492 | ||
3493 | } // end if | |
3494 | ||
3495 | Standard_Integer Result = 0; | |
3496 | Standard_Integer Length = MyTOCOMPUTESequence.Length (); | |
3497 | StructId = S1Iterator.Key () -> Identification (); | |
3498 | ||
3499 | for ( i = 1; i <= Length && Result == 0; ++i ) | |
3500 | ||
3501 | if ( MyTOCOMPUTESequence.Value ( i ) -> Identification () == StructId ) | |