0025027: Visualization - 2D layer viewport is updated incorrectly on resize
[occt.git] / src / Graphic3d / Graphic3d_Group.cxx
CommitLineData
b311480e 1// Created by: NW,JPB,CAL
2// Copyright (c) 1991-1999 Matra Datavision
973c2be1 3// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
b64d84be 16#include <Graphic3d_Group.ixx>
7fd59977 17
b64d84be 18#include <gp_Pnt.hxx>
19#include <Graphic3d_ArrayOfPoints.hxx>
20#include <Graphic3d_StructureManager.hxx>
21#include <Graphic3d_ShaderProgram.hxx>
22#include <Graphic3d_TransModeFlags.hxx>
23#include <Graphic3d_TextureMap.hxx>
24#include <Message.hxx>
25#include <Message_Messenger.hxx>
26#include <NCollection_String.hxx>
27#include <TCollection_AsciiString.hxx>
7fd59977 28
b64d84be 29#include <Graphic3d_CStructure.hxx>
30#include <Graphic3d_Structure.pxx>
7fd59977 31
b64d84be 32#define MyIsEmpty myCBitFields.bool1
33#define MyContainsFacet myCBitFields.bool2
7fd59977 34
b64d84be 35// =======================================================================
36// function : Graphic3d_Group
37// purpose :
38// =======================================================================
39Graphic3d_Group::Graphic3d_Group (const Handle(Graphic3d_Structure)& theStruct)
31c0e219 40: myIsClosed (Standard_False)
b64d84be 41{
42 myBounds.XMin = ShortRealLast();
43 myBounds.YMin = ShortRealLast();
44 myBounds.ZMin = ShortRealLast();
45 myBounds.XMax = ShortRealFirst();
46 myBounds.YMax = ShortRealFirst();
47 myBounds.ZMax = ShortRealFirst();
7fd59977 48
b64d84be 49 //
50 // A small commentary on the usage of This!
51 //
52 // Graphic3d_Group is created in a structure. Graphic3d_Structure is a
53 // manager of Graphic3d_Group. In the constructor of Graphic3d_Group
54 // a method Add of Graphic3d_Structure is called. It allows adding
55 // the instance of Graphic3d_Group in its manager. So there are 2 references
56 // to <me> and everything works well.
57 //
58 // This () is the instance of the class, the current group
59 //Handle(Graphic3d_Group) me = Handle(Graphic3d_Group)::DownCast (This());
7fd59977 60
b64d84be 61 myStructure = theStruct.operator->();
7fd59977 62
b64d84be 63 MyContainsFacet = Standard_False,
64 MyIsEmpty = Standard_True;
7fd59977 65
b64d84be 66 ContextLine.IsDef = 0;
67 ContextText.IsDef = 0;
68 ContextMarker.IsDef = 0;
69 ContextFillArea.IsDef = 0;
7fd59977 70
b64d84be 71 ContextLine.IsSet = 0;
72 ContextText.IsSet = 0;
73 ContextMarker.IsSet = 0;
74 ContextFillArea.IsSet = 0;
75}
76
77// =======================================================================
78// function : Clear
79// purpose :
80// =======================================================================
81void Graphic3d_Group::Clear (Standard_Boolean theUpdateStructureMgr)
82{
83 if (IsDeleted())
84 {
85 return;
86 }
87
88 ContextLine.IsSet = 0,
89 ContextText.IsSet = 0,
90 ContextMarker.IsSet = 0,
91 ContextFillArea.IsSet = 0;
7fd59977 92
b64d84be 93 ContextLine.IsDef = 0,
94 ContextText.IsDef = 0,
95 ContextMarker.IsDef = 0,
96 ContextFillArea.IsDef = 0;
7fd59977 97
b64d84be 98 myBounds.XMin = ShortRealLast();
99 myBounds.YMin = ShortRealLast();
100 myBounds.ZMin = ShortRealLast();
101 myBounds.XMax = ShortRealFirst();
102 myBounds.YMax = ShortRealFirst();
103 myBounds.ZMax = ShortRealFirst();
7fd59977 104
b64d84be 105 if (MyContainsFacet)
106 {
107 myStructure->GroupsWithFacet (-1);
108 MyContainsFacet = Standard_False;
109 }
110 MyIsEmpty = Standard_True;
7fd59977 111
b64d84be 112 // clear method could be used on Graphic3d_Structure destruction,
113 // and its structure manager could be already destroyed, in that
114 // case we don't need to update it;
115 if (theUpdateStructureMgr)
116 {
117 Update();
118 }
119}
7fd59977 120
b64d84be 121// =======================================================================
122// function : Destroy
123// purpose :
124// =======================================================================
125void Graphic3d_Group::Destroy()
126{
127 // tell graphics driver to clear internal resources of the group
128 Clear (Standard_False);
129}
7fd59977 130
b64d84be 131// =======================================================================
132// function : Remove
133// purpose :
134// =======================================================================
135void Graphic3d_Group::Remove()
7fd59977 136{
b64d84be 137 if (IsDeleted())
138 {
139 return;
140 }
7fd59977 141
b64d84be 142 if (MyContainsFacet)
143 {
144 myStructure->GroupsWithFacet (-1);
145 MyContainsFacet = Standard_False;
146 }
147 myStructure->Remove (this);
7fd59977 148
b64d84be 149 Update();
7fd59977 150
b64d84be 151 myBounds.XMin = ShortRealLast();
152 myBounds.YMin = ShortRealLast();
153 myBounds.ZMin = ShortRealLast();
154 myBounds.XMax = ShortRealFirst();
155 myBounds.YMax = ShortRealFirst();
156 myBounds.ZMax = ShortRealFirst();
7fd59977 157
b64d84be 158 MyIsEmpty = Standard_True;
159}
160
161// =======================================================================
162// function : IsDeleted
163// purpose :
164// =======================================================================
165Standard_Boolean Graphic3d_Group::IsDeleted() const
166{
167 return myStructure == NULL
168 || myStructure->IsDeleted();
169}
170
171// =======================================================================
172// function : ContainsFacet
173// purpose :
174// =======================================================================
175Standard_Boolean Graphic3d_Group::ContainsFacet() const
176{
177 return MyContainsFacet;
178}
179
180// =======================================================================
181// function : IsEmpty
182// purpose :
183// =======================================================================
184Standard_Boolean Graphic3d_Group::IsEmpty() const
185{
186 if (IsDeleted())
187 {
188 return Standard_True;
189 }
190
191 const Standard_ShortReal RL = ShortRealLast();
192 const Standard_ShortReal RF = ShortRealFirst();
193 const Standard_Boolean isEmpty = ((myBounds.XMin == RL) && (myBounds.YMin == RL)
194 && (myBounds.ZMin == RL) && (myBounds.XMax == RF)
195 && (myBounds.YMax == RF) && (myBounds.ZMax == RF));
196 if (isEmpty != MyIsEmpty)
197 {
198 ::Message::DefaultMessenger()->Send ("Graphic3d_Group: MyIsEmpty != IsEmpty()", Message_Trace);
199 }
200 return isEmpty;
201}
202
203// =======================================================================
204// function : SetMinMaxValues
205// purpose :
206// =======================================================================
207void Graphic3d_Group::SetMinMaxValues (const Standard_Real theXMin, const Standard_Real theYMin, const Standard_Real theZMin,
208 const Standard_Real theXMax, const Standard_Real theYMax, const Standard_Real theZMax)
209{
210 myBounds.XMin = Standard_ShortReal (theXMin);
211 myBounds.YMin = Standard_ShortReal (theYMin);
212 myBounds.ZMin = Standard_ShortReal (theZMin);
213 myBounds.XMax = Standard_ShortReal (theXMax);
214 myBounds.YMax = Standard_ShortReal (theYMax);
215 myBounds.ZMax = Standard_ShortReal (theZMax);
216}
217
218// =======================================================================
219// function : MinMaxValues
220// purpose :
221// =======================================================================
222void Graphic3d_Group::MinMaxValues (Standard_Real& theXMin, Standard_Real& theYMin, Standard_Real& theZMin,
223 Standard_Real& theXMax, Standard_Real& theYMax, Standard_Real& theZMax) const
224{
225 MinMaxCoord (theXMin, theYMin, theZMin,
226 theXMax, theYMax, theZMax);
227}
228
229// =======================================================================
230// function : Structure
231// purpose :
232// =======================================================================
233Handle(Graphic3d_Structure) Graphic3d_Group::Structure() const
234{
235 return myStructure;
236}
237
238// =======================================================================
239// function : MinMaxCoord
240// purpose :
241// =======================================================================
242void Graphic3d_Group::MinMaxCoord (Standard_Real& theXMin, Standard_Real& theYMin, Standard_Real& theZMin,
243 Standard_Real& theXMax, Standard_Real& theYMax, Standard_Real& theZMax) const
244{
245 if (IsEmpty())
246 {
247 // Empty Group
248 theXMin = theYMin = theZMin = ShortRealFirst();
249 theXMax = theYMax = theZMax = ShortRealLast();
250 }
251 else
252 {
253 theXMin = Standard_Real (myBounds.XMin);
254 theYMin = Standard_Real (myBounds.YMin);
255 theZMin = Standard_Real (myBounds.ZMin);
256 theXMax = Standard_Real (myBounds.XMax);
257 theYMax = Standard_Real (myBounds.YMax);
258 theZMax = Standard_Real (myBounds.ZMax);
259 }
260}
261
262// =======================================================================
263// function : Update
264// purpose :
265// =======================================================================
266void Graphic3d_Group::Update() const
267{
268 if (IsDeleted())
269 {
270 return;
271 }
272
273 if (myStructure->StructureManager()->UpdateMode() == Aspect_TOU_ASAP)
274 {
275 myStructure->StructureManager()->Update();
276 }
277}
278
279// =======================================================================
280// function : SetGroupPrimitivesAspect
281// purpose :
282// =======================================================================
283void Graphic3d_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine)
284{
285 if (IsDeleted())
286 {
287 return;
288 }
289
290 Standard_Real aWidth;
291 Quantity_Color aColor;
292 Aspect_TypeOfLine aLType;
293 theAspLine->Values (aColor, aLType, aWidth);
294
295 ContextLine.IsDef = 1;
296 ContextLine.Color.r = float (aColor.Red());
297 ContextLine.Color.g = float (aColor.Green());
298 ContextLine.Color.b = float (aColor.Blue());
299 ContextLine.LineType = aLType;
300 ContextLine.Width = float (aWidth);
301 ContextLine.ShaderProgram = theAspLine->ShaderProgram();
7fd59977 302
b64d84be 303 UpdateAspectLine (Standard_True);
7fd59977 304
b64d84be 305 ContextLine.IsSet = 1;
7fd59977 306
b64d84be 307 Update();
308}
309
310// =======================================================================
311// function : SetGroupPrimitivesAspect
312// purpose :
313// =======================================================================
314void Graphic3d_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspFill)
315{
316 if (IsDeleted())
317 {
318 return;
319 }
320
321 Standard_Real anRGB[3];
322 Standard_Real aWidth;
323 Quantity_Color anIntColor;
324 Quantity_Color aBackIntColor;
325 Quantity_Color anEdgeColor;
326 Aspect_TypeOfLine aLType;
327 Aspect_InteriorStyle aStyle;
328 theAspFill->Values (aStyle, anIntColor, aBackIntColor, anEdgeColor, aLType, aWidth);
329
330 anIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
331 ContextFillArea.Style = aStyle;
332 ContextFillArea.IntColor.r = float (anRGB[0]);
333 ContextFillArea.IntColor.g = float (anRGB[1]);
334 ContextFillArea.IntColor.b = float (anRGB[2]);
335
336 if (theAspFill->Distinguish())
337 {
338 aBackIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
339 }
340 ContextFillArea.BackIntColor.r = float (anRGB[0]);
341 ContextFillArea.BackIntColor.g = float (anRGB[1]);
342 ContextFillArea.BackIntColor.b = float (anRGB[2]);
343
344 // Edges
345 ContextFillArea.Edge = theAspFill->Edge() ? 1 : 0;
346 ContextFillArea.EdgeColor.r = float (anEdgeColor.Red());
347 ContextFillArea.EdgeColor.g = float (anEdgeColor.Green());
348 ContextFillArea.EdgeColor.b = float (anEdgeColor.Blue());
349 ContextFillArea.LineType = aLType;
350 ContextFillArea.Width = float (aWidth);
351 ContextFillArea.Hatch = theAspFill->HatchStyle();
352
353 // Front and Back face
354 ContextFillArea.Distinguish = theAspFill->Distinguish() ? 1 : 0;
355 ContextFillArea.BackFace = theAspFill->BackFace() ? 1 : 0;
356
357 // Back Material
358 const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial();
359
360 // Light specificity
361 ContextFillArea.Back.Shininess = float (aBack.Shininess());
362 ContextFillArea.Back.Ambient = float (aBack.Ambient());
363 ContextFillArea.Back.Diffuse = float (aBack.Diffuse());
364 ContextFillArea.Back.Specular = float (aBack.Specular());
365 ContextFillArea.Back.Transparency = float (aBack.Transparency());
366 ContextFillArea.Back.Emission = float (aBack.Emissive());
dc9ef964 367 ContextFillArea.Back.RefractionIndex = float (aBack.RefractionIndex());
b64d84be 368
369 // Reflection mode
370 ContextFillArea.Back.IsAmbient = aBack.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0;
371 ContextFillArea.Back.IsDiffuse = aBack.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0;
372 ContextFillArea.Back.IsSpecular = aBack.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0;
373 ContextFillArea.Back.IsEmission = aBack.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0;
374
375 // Material type
376 ContextFillArea.Back.IsPhysic = aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0;
377
378 // Specular color
379 ContextFillArea.Back.ColorSpec.r = float (aBack.SpecularColor().Red());
380 ContextFillArea.Back.ColorSpec.g = float (aBack.SpecularColor().Green());
381 ContextFillArea.Back.ColorSpec.b = float (aBack.SpecularColor().Blue());
382
383 // Ambient color
384 ContextFillArea.Back.ColorAmb.r = float (aBack.AmbientColor().Red());
385 ContextFillArea.Back.ColorAmb.g = float (aBack.AmbientColor().Green());
386 ContextFillArea.Back.ColorAmb.b = float (aBack.AmbientColor().Blue());
387
388 // Diffuse color
389 ContextFillArea.Back.ColorDif.r = float (aBack.DiffuseColor().Red());
390 ContextFillArea.Back.ColorDif.g = float (aBack.DiffuseColor().Green());
391 ContextFillArea.Back.ColorDif.b = float (aBack.DiffuseColor().Blue());
392
393 // Emissive color
394 ContextFillArea.Back.ColorEms.r = float (aBack.EmissiveColor().Red());
395 ContextFillArea.Back.ColorEms.g = float (aBack.EmissiveColor().Green());
396 ContextFillArea.Back.ColorEms.b = float (aBack.EmissiveColor().Blue());
397
398 ContextFillArea.Back.EnvReflexion = float (aBack.EnvReflexion());
399
400 // Front Material
401 const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
402 // Light specificity
403 ContextFillArea.Front.Shininess = float (aFront.Shininess());
404 ContextFillArea.Front.Ambient = float (aFront.Ambient());
405 ContextFillArea.Front.Diffuse = float (aFront.Diffuse());
406 ContextFillArea.Front.Specular = float (aFront.Specular());
407 ContextFillArea.Front.Transparency = float (aFront.Transparency());
408 ContextFillArea.Front.Emission = float (aFront.Emissive());
dc9ef964 409 ContextFillArea.Front.RefractionIndex = float (aFront.RefractionIndex());
b64d84be 410
411 // Reflection mode
412 ContextFillArea.Front.IsAmbient = aFront.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0;
413 ContextFillArea.Front.IsDiffuse = aFront.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0;
414 ContextFillArea.Front.IsSpecular = aFront.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0;
415 ContextFillArea.Front.IsEmission = aFront.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0;
416
417 // Material type
418 ContextFillArea.Front.IsPhysic = aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0;
419
420 // Specular color
421 ContextFillArea.Front.ColorSpec.r = float (aFront.SpecularColor().Red());
422 ContextFillArea.Front.ColorSpec.g = float (aFront.SpecularColor().Green());
423 ContextFillArea.Front.ColorSpec.b = float (aFront.SpecularColor().Blue());
424
425 // Ambient color
426 ContextFillArea.Front.ColorAmb.r = float (aFront.AmbientColor().Red());
427 ContextFillArea.Front.ColorAmb.g = float (aFront.AmbientColor().Green());
428 ContextFillArea.Front.ColorAmb.b = float (aFront.AmbientColor().Blue());
429
430 // Diffuse color
431 ContextFillArea.Front.ColorDif.r = float (aFront.DiffuseColor().Red());
432 ContextFillArea.Front.ColorDif.g = float (aFront.DiffuseColor().Green());
433 ContextFillArea.Front.ColorDif.b = float (aFront.DiffuseColor().Blue());
434
435 // Emissive color
436 ContextFillArea.Front.ColorEms.r = float (aFront.EmissiveColor().Red());
437 ContextFillArea.Front.ColorEms.g = float (aFront.EmissiveColor().Green());
438 ContextFillArea.Front.ColorEms.b = float (aFront.EmissiveColor().Blue());
439
440 ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
441
442 ContextFillArea.IsDef = 1; // Definition material ok
443
444 // Texture map
445 ContextFillArea.Texture.TextureMap = theAspFill->TextureMap();
446 ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0;
447
448 Standard_Integer aPolyMode;
449 Standard_ShortReal aPolyFactor, aPolyUnits;
450 theAspFill->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits);
451 ContextFillArea.PolygonOffsetMode = aPolyMode;
452 ContextFillArea.PolygonOffsetFactor = aPolyFactor;
453 ContextFillArea.PolygonOffsetUnits = aPolyUnits;
454
455 ContextFillArea.ShaderProgram = theAspFill->ShaderProgram();
456
457 UpdateAspectFace (Standard_True);
458
459 ContextFillArea.IsSet = 1;
460
461 Update();
462}
463
464// =======================================================================
465// function : SetGroupPrimitivesAspect
466// purpose :
467// =======================================================================
468void Graphic3d_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& theAspMarker)
469{
470 if (IsDeleted())
471 {
472 return;
473 }
474
475 Standard_Real aScale;
476 Quantity_Color aColor;
477 Aspect_TypeOfMarker aMarkerType;
478 theAspMarker->Values (aColor, aMarkerType, aScale);
479
480 ContextMarker.IsDef = 1;
481 ContextMarker.Color.r = Standard_ShortReal (aColor.Red());
482 ContextMarker.Color.g = Standard_ShortReal (aColor.Green());
483 ContextMarker.Color.b = Standard_ShortReal (aColor.Blue());
484 ContextMarker.MarkerType = aMarkerType;
485 ContextMarker.Scale = Standard_ShortReal (aScale);
486 ContextMarker.MarkerImage = theAspMarker->GetMarkerImage();
487 ContextMarker.ShaderProgram = theAspMarker->ShaderProgram();
488
489 UpdateAspectMarker (Standard_True);
490
491 ContextMarker.IsSet = 1;
492
493 Update();
494}
495
496// =======================================================================
497// function : SetGroupPrimitivesAspect
498// purpose :
499// =======================================================================
500void Graphic3d_Group::SetGroupPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& theAspText)
501{
502 if (IsDeleted())
503 {
504 return;
505 }
506
507 Standard_Real anExpansion, aSpace, aTextAngle;
508 Quantity_Color aColor, aColorSubTitle;
509 Standard_CString aFont;
510 Aspect_TypeOfStyleText aStyle;
511 Aspect_TypeOfDisplayText aDisplayType;
512 Standard_Boolean isTextZoomable;
513 Font_FontAspect aTextFontAspect;
514 theAspText->Values (aColor, aFont, anExpansion, aSpace, aStyle, aDisplayType,
515 aColorSubTitle, isTextZoomable, aTextAngle, aTextFontAspect);
516
517 ContextText.IsDef = 1;
518 ContextText.Color.r = float (aColor.Red());
519 ContextText.Color.g = float (aColor.Green());
520 ContextText.Color.b = float (aColor.Blue());
521 ContextText.Font = (char* )aFont;
522 ContextText.Expan = float (anExpansion);
523 ContextText.Space = float (aSpace);
524 ContextText.Style = aStyle;
525 ContextText.DisplayType = aDisplayType;
526 ContextText.ColorSubTitle.r = float (aColorSubTitle.Red());
527 ContextText.ColorSubTitle.g = float (aColorSubTitle.Green());
528 ContextText.ColorSubTitle.b = float (aColorSubTitle.Blue());
529 ContextText.TextZoomable = isTextZoomable;
530 ContextText.TextAngle = float (aTextAngle);
531 ContextText.TextFontAspect = aTextFontAspect;
532 ContextText.ShaderProgram = theAspText->ShaderProgram();
533
534 UpdateAspectText (Standard_True);
535
536 ContextText.IsSet = 1;
537
538 Update();
539}
540
541// =======================================================================
542// function : SetPrimitivesAspect
543// purpose :
544// =======================================================================
545void Graphic3d_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine)
546{
547 if (IsDeleted())
548 {
549 return;
550 }
7fd59977 551
b64d84be 552 Standard_Real aWidth;
553 Quantity_Color aColor;
554 Aspect_TypeOfLine aLType;
555 theAspLine->Values (aColor, aLType, aWidth);
7fd59977 556
b64d84be 557 ContextLine.IsDef = 1;
558 ContextLine.Color.r = float (aColor.Red());
559 ContextLine.Color.g = float (aColor.Green());
560 ContextLine.Color.b = float (aColor.Blue());
561 ContextLine.LineType = aLType;
562 ContextLine.Width = float (aWidth);
563 ContextLine.ShaderProgram = theAspLine->ShaderProgram();
7fd59977 564
b64d84be 565 UpdateAspectLine (Standard_False);
7fd59977 566
b64d84be 567 ContextLine.IsSet = 1;
7fd59977 568
b64d84be 569 Update();
570}
571
572// =======================================================================
573// function : SetPrimitivesAspect
574// purpose :
575// =======================================================================
576void Graphic3d_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& theAspFill)
577{
578 if (IsDeleted())
579 {
580 return;
581 }
582
583 Standard_Real anRGB[3];
584 Standard_Real aWidth;
585 Quantity_Color anIntColor;
586 Quantity_Color aBackIntColor;
587 Quantity_Color anEdgeColor;
588 Aspect_TypeOfLine aLType;
589 Aspect_InteriorStyle aStyle;
590 theAspFill->Values (aStyle, anIntColor, aBackIntColor, anEdgeColor, aLType, aWidth);
591
592 anIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
593 ContextFillArea.Style = aStyle;
594 ContextFillArea.IntColor.r = float (anRGB[0]);
595 ContextFillArea.IntColor.g = float (anRGB[1]);
596 ContextFillArea.IntColor.b = float (anRGB[2]);
597
598 if (theAspFill->Distinguish())
599 {
600 aBackIntColor.Values (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
601 }
602 ContextFillArea.BackIntColor.r = float(anRGB[0]);
603 ContextFillArea.BackIntColor.g = float(anRGB[1]);
604 ContextFillArea.BackIntColor.b = float(anRGB[2]);
605
606 // Edges
607 ContextFillArea.Edge = theAspFill->Edge() ? 1 : 0;
608 ContextFillArea.EdgeColor.r = float (anEdgeColor.Red());
609 ContextFillArea.EdgeColor.g = float (anEdgeColor.Green());
610 ContextFillArea.EdgeColor.b = float (anEdgeColor.Blue());
611 ContextFillArea.LineType = aLType;
612 ContextFillArea.Width = float (aWidth);
613 ContextFillArea.Hatch = theAspFill->HatchStyle();
614
615 // Front and Back face
616 ContextFillArea.Distinguish = theAspFill->Distinguish() ? 1 : 0;
617 ContextFillArea.BackFace = theAspFill->BackFace() ? 1 : 0;
618
619 // Back Material
620 const Graphic3d_MaterialAspect& aBack = theAspFill->BackMaterial();
621 // Material state
622 ContextFillArea.Back.Shininess = float (aBack.Shininess());
623 ContextFillArea.Back.Ambient = float (aBack.Ambient());
624 ContextFillArea.Back.Diffuse = float (aBack.Diffuse());
625 ContextFillArea.Back.Specular = float (aBack.Specular());
626 ContextFillArea.Back.Transparency = float (aBack.Transparency());
627 ContextFillArea.Back.Emission = float (aBack.Emissive());
628
629 // Reflection mode
630 ContextFillArea.Back.IsAmbient = aBack.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0;
631 ContextFillArea.Back.IsDiffuse = aBack.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0;
632 ContextFillArea.Back.IsSpecular = aBack.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0;
633 ContextFillArea.Back.IsEmission = aBack.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0;
634
635 // Material type
636 ContextFillArea.Back.IsPhysic = aBack.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0;
637
638 // Specular color
639 ContextFillArea.Back.ColorSpec.r = float (aBack.SpecularColor().Red());
640 ContextFillArea.Back.ColorSpec.g = float (aBack.SpecularColor().Green());
641 ContextFillArea.Back.ColorSpec.b = float (aBack.SpecularColor().Blue());
642
643 // Ambient color
644 ContextFillArea.Back.ColorAmb.r = float (aBack.AmbientColor().Red());
645 ContextFillArea.Back.ColorAmb.g = float (aBack.AmbientColor().Green());
646 ContextFillArea.Back.ColorAmb.b = float (aBack.AmbientColor().Blue());
647
648 // Diffuse color
649 ContextFillArea.Back.ColorDif.r = float (aBack.DiffuseColor().Red());
650 ContextFillArea.Back.ColorDif.g = float (aBack.DiffuseColor().Green());
651 ContextFillArea.Back.ColorDif.b = float (aBack.DiffuseColor().Blue());
652
653 // Emissive color
654 ContextFillArea.Back.ColorEms.r = float (aBack.EmissiveColor().Red());
655 ContextFillArea.Back.ColorEms.g = float (aBack.EmissiveColor().Green());
656 ContextFillArea.Back.ColorEms.b = float (aBack.EmissiveColor().Blue());
657
658 ContextFillArea.Back.EnvReflexion = float (aBack.EnvReflexion());
659
660 // Front Material
661 const Graphic3d_MaterialAspect& aFront = theAspFill->FrontMaterial();
662 // Light specificity
663 ContextFillArea.Front.Shininess = float (aFront.Shininess());
664 ContextFillArea.Front.Ambient = float (aFront.Ambient());
665 ContextFillArea.Front.Diffuse = float (aFront.Diffuse());
666 ContextFillArea.Front.Specular = float (aFront.Specular());
667 ContextFillArea.Front.Transparency = float (aFront.Transparency());
668 ContextFillArea.Front.Emission = float (aFront.Emissive());
669
670 // Reflection mode
671 ContextFillArea.Front.IsAmbient = aFront.ReflectionMode (Graphic3d_TOR_AMBIENT) ? 1 : 0;
672 ContextFillArea.Front.IsDiffuse = aFront.ReflectionMode (Graphic3d_TOR_DIFFUSE) ? 1 : 0;
673 ContextFillArea.Front.IsSpecular = aFront.ReflectionMode (Graphic3d_TOR_SPECULAR) ? 1 : 0;
674 ContextFillArea.Front.IsEmission = aFront.ReflectionMode (Graphic3d_TOR_EMISSION) ? 1 : 0;
675
676 // Material type
677 ContextFillArea.Front.IsPhysic = aFront.MaterialType (Graphic3d_MATERIAL_PHYSIC) ? 1 : 0;
678
679 // Specular color
680 ContextFillArea.Front.ColorSpec.r = float (aFront.SpecularColor().Red());
681 ContextFillArea.Front.ColorSpec.g = float (aFront.SpecularColor().Green());
682 ContextFillArea.Front.ColorSpec.b = float (aFront.SpecularColor().Blue());
683
684 // Ambient color
685 ContextFillArea.Front.ColorAmb.r = float (aFront.AmbientColor().Red());
686 ContextFillArea.Front.ColorAmb.g = float (aFront.AmbientColor().Green());
687 ContextFillArea.Front.ColorAmb.b = float (aFront.AmbientColor().Blue());
688
689 // Diffuse color
690 ContextFillArea.Front.ColorDif.r = float (aFront.DiffuseColor().Red());
691 ContextFillArea.Front.ColorDif.g = float (aFront.DiffuseColor().Green());
692 ContextFillArea.Front.ColorDif.b = float (aFront.DiffuseColor().Blue());
693
694 // Emissive color
695 ContextFillArea.Front.ColorEms.r = float (aFront.EmissiveColor().Red());
696 ContextFillArea.Front.ColorEms.g = float (aFront.EmissiveColor().Green());
697 ContextFillArea.Front.ColorEms.b = float (aFront.EmissiveColor().Blue());
698
699 ContextFillArea.Front.EnvReflexion = float (aFront.EnvReflexion());
700
701 ContextFillArea.IsDef = 1; // Material definition ok
702
703 ContextFillArea.Texture.TextureMap = theAspFill->TextureMap();
704 ContextFillArea.Texture.doTextureMap = theAspFill->TextureMapState() ? 1 : 0;
705
706 Standard_Integer aPolyMode;
707 Standard_ShortReal aPolyFactor, aPolyUnits;
708 theAspFill->PolygonOffsets (aPolyMode, aPolyFactor, aPolyUnits);
709 ContextFillArea.PolygonOffsetMode = aPolyMode;
710 ContextFillArea.PolygonOffsetFactor = aPolyFactor;
711 ContextFillArea.PolygonOffsetUnits = aPolyUnits;
712
713 ContextFillArea.ShaderProgram = theAspFill->ShaderProgram();
714
715 UpdateAspectFace (Standard_False);
716
717 ContextFillArea.IsSet = 1;
718
719 Update();
720}
721
722// =======================================================================
723// function : SetPrimitivesAspect
724// purpose :
725// =======================================================================
726void Graphic3d_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& theAspMarker)
727{
728 if (IsDeleted())
729 {
730 return;
731 }
732
733 Standard_Real aScale;
734 Quantity_Color aColor;
735 Aspect_TypeOfMarker aMarkerType;
736 theAspMarker->Values (aColor, aMarkerType, aScale);
737
738 ContextMarker.IsDef = 1;
739 ContextMarker.Color.r = Standard_ShortReal (aColor.Red());
740 ContextMarker.Color.g = Standard_ShortReal (aColor.Green());
741 ContextMarker.Color.b = Standard_ShortReal (aColor.Blue());
742 ContextMarker.MarkerType = aMarkerType;
743 ContextMarker.Scale = Standard_ShortReal (aScale);
744 ContextMarker.MarkerImage = theAspMarker->GetMarkerImage();
745
746 ContextMarker.ShaderProgram = theAspMarker->ShaderProgram();
747
748 UpdateAspectMarker (Standard_False);
749
750 ContextMarker.IsSet = 1;
751
752 Update();
753}
754
755// =======================================================================
756// function : SetPrimitivesAspect
757// purpose :
758// =======================================================================
759void Graphic3d_Group::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& theAspText)
760{
761 if (IsDeleted())
762 {
763 return;
764 }
765
766 Standard_CString aFont;
767 Standard_Real aSpace, anExpansion, aTextAngle;
768 Quantity_Color aColor, aColorSubTitle;
769 Aspect_TypeOfStyleText aStyle;
770 Aspect_TypeOfDisplayText aDisplayType;
771 Standard_Boolean aTextZoomable;
772 Font_FontAspect aTextFontAspect;
773 theAspText->Values (aColor, aFont, anExpansion, aSpace, aStyle, aDisplayType,
774 aColorSubTitle, aTextZoomable, aTextAngle, aTextFontAspect);
775
776 ContextText.IsDef = 1;
777 ContextText.Color.r = float (aColor.Red());
778 ContextText.Color.g = float (aColor.Green());
779 ContextText.Color.b = float (aColor.Blue());
780 ContextText.Font = (char* )aFont;
781 ContextText.Expan = float (anExpansion);
782 ContextText.Space = float (aSpace);
783 ContextText.Style = aStyle;
784 ContextText.DisplayType = aDisplayType;
785 ContextText.ColorSubTitle.r = float (aColorSubTitle.Red());
786 ContextText.ColorSubTitle.g = float (aColorSubTitle.Green());
787 ContextText.ColorSubTitle.b = float (aColorSubTitle.Blue());
788 ContextText.TextZoomable = aTextZoomable;
789 ContextText.TextAngle = float (aTextAngle);
790 ContextText.TextFontAspect = aTextFontAspect;
791 ContextText.ShaderProgram = theAspText->ShaderProgram();
792
793 UpdateAspectText (Standard_False);
794
795 ContextText.IsSet = 1;
796
797 Update();
798}
799
800// =======================================================================
801// function : IsGroupPrimitivesAspectSet
802// purpose :
803// =======================================================================
804Standard_Boolean Graphic3d_Group::IsGroupPrimitivesAspectSet (const Graphic3d_GroupAspect theAspect) const
805{
806 switch (theAspect)
807 {
808 case Graphic3d_ASPECT_LINE: return ContextLine.IsSet;
809 case Graphic3d_ASPECT_TEXT: return ContextText.IsSet;
810 case Graphic3d_ASPECT_MARKER: return ContextMarker.IsSet;
811 case Graphic3d_ASPECT_FILL_AREA: return ContextFillArea.IsSet;
812 default: return Standard_False;
813 }
814}
815
816// =======================================================================
817// function : GroupPrimitivesAspect
818// purpose :
819// =======================================================================
820void Graphic3d_Group::GroupPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine,
821 const Handle(Graphic3d_AspectText3d)& theAspText,
822 const Handle(Graphic3d_AspectMarker3d)& theAspMarker,
823 const Handle(Graphic3d_AspectFillArea3d)& theAspFill) const
824{
825 Quantity_Color aColor;
826 Graphic3d_MaterialAspect aFront, aBack;
827
828 const CALL_DEF_CONTEXTLINE& anAspLine = ContextLine.IsSet ? ContextLine : myStructure->CStructure()->ContextLine;
829 aColor.SetValues (Standard_Real (anAspLine.Color.r),
830 Standard_Real (anAspLine.Color.g),
831 Standard_Real (anAspLine.Color.b), Quantity_TOC_RGB);
832 theAspLine->SetColor (aColor);
833 theAspLine->SetType (Aspect_TypeOfLine (anAspLine.LineType));
834 theAspLine->SetWidth (Standard_Real (anAspLine.Width));
835 theAspLine->SetShaderProgram (anAspLine.ShaderProgram);
836
837 const CALL_DEF_CONTEXTTEXT& anAspText = ContextText.IsSet ? ContextText : myStructure->CStructure()->ContextText;
838 aColor.SetValues (Standard_Real (anAspText.Color.r),
839 Standard_Real (anAspText.Color.g),
840 Standard_Real (anAspText.Color.b), Quantity_TOC_RGB);
841 theAspText->SetColor (aColor);
842 aColor.SetValues (Standard_Real (anAspText.ColorSubTitle.r),
843 Standard_Real (anAspText.ColorSubTitle.g),
844 Standard_Real (anAspText.ColorSubTitle.b), Quantity_TOC_RGB);
845 theAspText->SetColorSubTitle (aColor);
846 theAspText->SetFont (anAspText.Font);
847 theAspText->SetSpace (Standard_Real (anAspText.Space));
848 theAspText->SetExpansionFactor (Standard_Real (anAspText.Expan));
849 theAspText->SetStyle (Aspect_TypeOfStyleText (anAspText.Style));
850 theAspText->SetDisplayType (Aspect_TypeOfDisplayText (anAspText.DisplayType));
851 theAspText->SetShaderProgram (anAspText.ShaderProgram);
852
853 const CALL_DEF_CONTEXTMARKER& anAspMarker = ContextMarker.IsSet ? ContextMarker : myStructure->CStructure()->ContextMarker;
854 aColor.SetValues (Standard_Real (anAspMarker.Color.r),
855 Standard_Real (anAspMarker.Color.g),
856 Standard_Real (anAspMarker.Color.b), Quantity_TOC_RGB);
857 theAspMarker->SetColor (aColor);
858 theAspMarker->SetType (anAspMarker.MarkerType);
859 theAspMarker->SetScale (Standard_Real (anAspMarker.Scale));
860 theAspMarker->SetShaderProgram (anAspMarker.ShaderProgram);
861 if (anAspMarker.MarkerType == Aspect_TOM_USERDEFINED)
862 {
863 theAspMarker->SetMarkerImage (ContextMarker.MarkerImage);
864 }
865
866 const CALL_DEF_CONTEXTFILLAREA& anAspFill = ContextFillArea.IsSet ? ContextFillArea : myStructure->CStructure()->ContextFillArea;
867 // Interior
868 theAspFill->SetInteriorStyle (Aspect_InteriorStyle (anAspFill.Style));
869 aColor.SetValues (Standard_Real (anAspFill.IntColor.r),
870 Standard_Real (anAspFill.IntColor.g),
871 Standard_Real (anAspFill.IntColor.b), Quantity_TOC_RGB);
872 theAspFill->SetInteriorColor (aColor);
873
874 // Edges
875 aColor.SetValues (Standard_Real (anAspFill.EdgeColor.r),
876 Standard_Real (anAspFill.EdgeColor.g),
877 Standard_Real (anAspFill.EdgeColor.b), Quantity_TOC_RGB);
878 theAspFill->SetEdgeColor (aColor);
879 theAspFill->SetEdgeLineType (Aspect_TypeOfLine (anAspFill.LineType));
880 theAspFill->SetEdgeWidth (Standard_Real (anAspFill.Width));
881
882 // Back Material
883 aBack.SetShininess (Standard_Real (anAspFill.Back.Shininess));
884 aBack.SetAmbient (Standard_Real (anAspFill.Back.Ambient));
885 aBack.SetDiffuse (Standard_Real (anAspFill.Back.Diffuse));
886 aBack.SetSpecular (Standard_Real (anAspFill.Back.Specular));
887 aBack.SetTransparency (Standard_Real (anAspFill.Back.Transparency));
888 aBack.SetEmissive (Standard_Real (anAspFill.Back.Emission));
889 anAspFill.Back.IsAmbient == 1 ? aBack.SetReflectionModeOn (Graphic3d_TOR_AMBIENT) : aBack.SetReflectionModeOff (Graphic3d_TOR_AMBIENT);
890 anAspFill.Back.IsDiffuse == 1 ? aBack.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE) : aBack.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
891 anAspFill.Back.IsSpecular == 1 ? aBack.SetReflectionModeOn (Graphic3d_TOR_SPECULAR) : aBack.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
892 anAspFill.Back.IsEmission == 1 ? aBack.SetReflectionModeOn (Graphic3d_TOR_EMISSION) : aBack.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
893
894 aColor.SetValues (Standard_Real (anAspFill.Back.ColorSpec.r),
895 Standard_Real (anAspFill.Back.ColorSpec.g),
896 Standard_Real (anAspFill.Back.ColorSpec.b), Quantity_TOC_RGB);
897 aBack.SetSpecularColor (aColor);
898
899 aColor.SetValues (Standard_Real (anAspFill.Back.ColorAmb.r),
900 Standard_Real (anAspFill.Back.ColorAmb.g),
901 Standard_Real (anAspFill.Back.ColorAmb.b), Quantity_TOC_RGB);
902 aBack.SetAmbientColor (aColor);
903
904 aColor.SetValues (Standard_Real (anAspFill.Back.ColorDif.r),
905 Standard_Real (anAspFill.Back.ColorDif.g),
906 Standard_Real (anAspFill.Back.ColorDif.b), Quantity_TOC_RGB);
907 aBack.SetDiffuseColor (aColor);
908
909 aColor.SetValues (Standard_Real (anAspFill.Back.ColorEms.r),
910 Standard_Real (anAspFill.Back.ColorEms.g),
911 Standard_Real (anAspFill.Back.ColorEms.b), Quantity_TOC_RGB);
912 aBack.SetEmissiveColor (aColor);
913
914 aBack.SetEnvReflexion (anAspFill.Back.EnvReflexion);
915
916 // Front Material
917 aFront.SetShininess (Standard_Real (anAspFill.Front.Shininess));
918 aFront.SetAmbient (Standard_Real (anAspFill.Front.Ambient));
919 aFront.SetDiffuse (Standard_Real (anAspFill.Front.Diffuse));
920 aFront.SetSpecular (Standard_Real (anAspFill.Front.Specular));
921 aFront.SetTransparency (Standard_Real (anAspFill.Front.Transparency));
922 aFront.SetEmissive (Standard_Real (anAspFill.Back.Emission));
923 anAspFill.Front.IsAmbient == 1 ? aFront.SetReflectionModeOn (Graphic3d_TOR_AMBIENT) : aFront.SetReflectionModeOff (Graphic3d_TOR_AMBIENT);
924 anAspFill.Front.IsDiffuse == 1 ? aFront.SetReflectionModeOn (Graphic3d_TOR_DIFFUSE) : aFront.SetReflectionModeOff (Graphic3d_TOR_DIFFUSE);
925 anAspFill.Front.IsSpecular == 1 ? aFront.SetReflectionModeOn (Graphic3d_TOR_SPECULAR) : aFront.SetReflectionModeOff (Graphic3d_TOR_SPECULAR);
926 anAspFill.Front.IsEmission == 1 ? aFront.SetReflectionModeOn (Graphic3d_TOR_EMISSION) : aFront.SetReflectionModeOff (Graphic3d_TOR_EMISSION);
927
928 aColor.SetValues (Standard_Real (anAspFill.Front.ColorSpec.r),
929 Standard_Real (anAspFill.Front.ColorSpec.g),
930 Standard_Real (anAspFill.Front.ColorSpec.b), Quantity_TOC_RGB);
931 aFront.SetSpecularColor (aColor);
932
933 aColor.SetValues (Standard_Real (anAspFill.Front.ColorAmb.r),
934 Standard_Real (anAspFill.Front.ColorAmb.g),
935 Standard_Real (anAspFill.Front.ColorAmb.b), Quantity_TOC_RGB);
936 aFront.SetAmbientColor (aColor);
937
938 aColor.SetValues (Standard_Real (anAspFill.Front.ColorDif.r),
939 Standard_Real (anAspFill.Front.ColorDif.g),
940 Standard_Real (anAspFill.Front.ColorDif.b), Quantity_TOC_RGB);
941 aFront.SetDiffuseColor (aColor);
942
943 aColor.SetValues (Standard_Real (anAspFill.Front.ColorEms.r),
944 Standard_Real (anAspFill.Front.ColorEms.g),
945 Standard_Real (anAspFill.Front.ColorEms.b), Quantity_TOC_RGB);
946 aFront.SetEmissiveColor (aColor);
947
948 aFront.SetEnvReflexion (anAspFill.Front.EnvReflexion);
949
950 // Edges
951 anAspFill.Edge == 1 ? theAspFill->SetEdgeOn() : theAspFill->SetEdgeOff();
952 // Hatch
953 theAspFill->SetHatchStyle (Aspect_HatchStyle (anAspFill.Hatch));
954 // Materials
955 // Front and Back face
956 anAspFill.Distinguish == 1 ? theAspFill->SetDistinguishOn() : theAspFill->SetDistinguishOff();
957 anAspFill.BackFace == 1 ? theAspFill->SuppressBackFace() : theAspFill->AllowBackFace();
958 // Texture
959 theAspFill->SetTextureMap (anAspFill.Texture.TextureMap);
960 anAspFill.Texture.doTextureMap == 1 ? theAspFill->SetTextureMapOn() : theAspFill->SetTextureMapOff();
961 theAspFill->SetShaderProgram (anAspFill.ShaderProgram);
962 theAspFill->SetPolygonOffsets (anAspFill.PolygonOffsetMode,
963 anAspFill.PolygonOffsetFactor,
964 anAspFill.PolygonOffsetUnits);
965 theAspFill->SetBackMaterial (aBack);
966 theAspFill->SetFrontMaterial (aFront);
967}
968
969// =======================================================================
970// function : PrimitivesAspect
971// purpose :
972// =======================================================================
973void Graphic3d_Group::PrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& theAspLine,
974 const Handle(Graphic3d_AspectText3d)& theAspText,
975 const Handle(Graphic3d_AspectMarker3d)& theAspMarker,
976 const Handle(Graphic3d_AspectFillArea3d)& theAspFill) const
977{
978 GroupPrimitivesAspect (theAspLine, theAspText, theAspMarker, theAspFill);
979}
980
981// =======================================================================
982// function : AddPrimitiveArray
983// purpose :
984// =======================================================================
985void Graphic3d_Group::AddPrimitiveArray (const Handle(Graphic3d_ArrayOfPrimitives)& thePrim,
986 const Standard_Boolean theToEvalMinMax)
987{
988 if (IsDeleted()
989 || !thePrim->IsValid())
990 {
991 return;
992 }
993
871fa103 994 AddPrimitiveArray (thePrim->Type(), thePrim->Indices(), thePrim->Attributes(), thePrim->Bounds(), theToEvalMinMax);
995}
996
997// =======================================================================
998// function : AddPrimitiveArray
999// purpose :
1000// =======================================================================
1001void Graphic3d_Group::AddPrimitiveArray (const Graphic3d_TypeOfPrimitiveArray theType,
1002 const Handle(Graphic3d_IndexBuffer)& ,
1003 const Handle(Graphic3d_Buffer)& theAttribs,
1004 const Handle(Graphic3d_BoundBuffer)& ,
1005 const Standard_Boolean theToEvalMinMax)
1006{
1007 if (IsDeleted()
1008 || theAttribs.IsNull())
1009 {
1010 return;
1011 }
1012
b64d84be 1013 if (!MyContainsFacet
871fa103 1014 && theType != Graphic3d_TOPA_POLYLINES
1015 && theType != Graphic3d_TOPA_SEGMENTS
1016 && theType != Graphic3d_TOPA_POINTS)
b64d84be 1017 {
1018 myStructure->GroupsWithFacet (1);
1019 MyContainsFacet = Standard_True;
1020 }
1021
1022 MyIsEmpty = Standard_False;
b64d84be 1023 if (theToEvalMinMax)
1024 {
871fa103 1025 const Standard_Integer aNbVerts = theAttribs->NbElements;
1026 for (Standard_Integer anAttribIter = 0; anAttribIter < theAttribs->NbAttributes; ++anAttribIter)
b64d84be 1027 {
871fa103 1028 const Graphic3d_Attribute& anAttrib = theAttribs->Attribute (anAttribIter);
1029 if (anAttrib.Id != Graphic3d_TOA_POS)
1030 {
1031 continue;
1032 }
1033
1034 const size_t anOffset = theAttribs->AttributeOffset (anAttribIter);
1035 switch (anAttrib.DataType)
1036 {
1037 case Graphic3d_TOD_VEC2:
1038 {
1039 for (Standard_Integer aVertIter = 0; aVertIter < aNbVerts; ++aVertIter)
1040 {
1041 const Graphic3d_Vec2& aVert = *reinterpret_cast<const Graphic3d_Vec2* >(theAttribs->value (aVertIter) + anOffset);
1042 if (aVert.x() < myBounds.XMin) myBounds.XMin = aVert.x();
1043 if (aVert.y() < myBounds.YMin) myBounds.YMin = aVert.y();
1044 if (aVert.x() > myBounds.XMax) myBounds.XMax = aVert.x();
1045 if (aVert.y() > myBounds.YMax) myBounds.YMax = aVert.y();
1046 }
1047 break;
1048 }
1049 case Graphic3d_TOD_VEC3:
1050 case Graphic3d_TOD_VEC4:
1051 {
1052 for (Standard_Integer aVertIter = 0; aVertIter < aNbVerts; ++aVertIter)
1053 {
1054 const Graphic3d_Vec3& aVert = *reinterpret_cast<const Graphic3d_Vec3* >(theAttribs->value (aVertIter) + anOffset);
1055 if (aVert.x() < myBounds.XMin) myBounds.XMin = aVert.x();
1056 if (aVert.y() < myBounds.YMin) myBounds.YMin = aVert.y();
1057 if (aVert.z() < myBounds.ZMin) myBounds.ZMin = aVert.z();
1058 if (aVert.x() > myBounds.XMax) myBounds.XMax = aVert.x();
1059 if (aVert.y() > myBounds.YMax) myBounds.YMax = aVert.y();
1060 if (aVert.z() > myBounds.ZMax) myBounds.ZMax = aVert.z();
1061 }
1062 break;
1063 }
1064 default: break;
1065 }
1066 break;
b64d84be 1067 }
1068 }
1069
1070 Update();
1071}
1072
1073// =======================================================================
1074// function : Marker
1075// purpose :
1076// =======================================================================
1077void Graphic3d_Group::Marker (const Graphic3d_Vertex& thePoint,
1078 const Standard_Boolean theToEvalMinMax)
1079{
1080 Handle(Graphic3d_ArrayOfPoints) aPoints = new Graphic3d_ArrayOfPoints (1);
1081 aPoints->AddVertex (thePoint.X(), thePoint.Y(), thePoint.Z());
1082 AddPrimitiveArray (aPoints, theToEvalMinMax);
1083}
1084
1085// =======================================================================
1086// function : UserDraw
1087// purpose :
1088// =======================================================================
1089void Graphic3d_Group::UserDraw (const Standard_Address /*theObject*/,
1090 const Standard_Boolean /*theToEvalMinMax*/,
1091 const Standard_Boolean theContainsFacet)
1092{
1093 if (IsDeleted())
1094 {
1095 return;
1096 }
1097
1098 // Without this modification, the group assumes the primitive contains
1099 // no polygons and does not require the Z-buffer for display.
1100 if (!MyContainsFacet && theContainsFacet)
1101 {
1102 myStructure->GroupsWithFacet (1);
1103 MyContainsFacet = Standard_True;
1104 }
1105
1106 MyIsEmpty = Standard_False;
1107 Update();
1108}
1109
1110// =======================================================================
1111// function : Text
1112// purpose :
1113// =======================================================================
1114void Graphic3d_Group::Text (const Standard_CString /*theText*/,
1115 const Graphic3d_Vertex& thePoint,
1116 const Standard_Real /*theHeight*/,
1117 const Quantity_PlaneAngle /*theAngle*/,
1118 const Graphic3d_TextPath /*theTp*/,
1119 const Graphic3d_HorizontalTextAlignment /*theHta*/,
1120 const Graphic3d_VerticalTextAlignment /*theVta*/,
1121 const Standard_Boolean theToEvalMinMax)
1122{
1123 if (IsDeleted())
1124 {
1125 return;
1126 }
1127
1128 MyIsEmpty = Standard_False;
1129 if (theToEvalMinMax)
1130 {
1131 Standard_ShortReal x, y, z;
1132 thePoint.Coord (x, y, z);
1133 if (x < myBounds.XMin) myBounds.XMin = x;
1134 if (y < myBounds.YMin) myBounds.YMin = y;
1135 if (z < myBounds.ZMin) myBounds.ZMin = z;
1136 if (x > myBounds.XMax) myBounds.XMax = x;
1137 if (y > myBounds.YMax) myBounds.YMax = y;
1138 if (z > myBounds.ZMax) myBounds.ZMax = z;
1139 }
1140 Update();
1141}
1142
1143// =======================================================================
1144// function : Text
1145// purpose :
1146// =======================================================================
1147void Graphic3d_Group::Text (const Standard_CString theText,
1148 const Graphic3d_Vertex& thePoint,
1149 const Standard_Real theHeight,
1150 const Standard_Boolean theToEvalMinMax)
1151{
1152 Text (theText, thePoint, theHeight, 0.0,
1153 Graphic3d_TP_RIGHT, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM, theToEvalMinMax);
1154}
1155
1156// =======================================================================
1157// function : Text
1158// purpose :
1159// =======================================================================
1160void Graphic3d_Group::Text (const TCollection_ExtendedString& theText,
1161 const Graphic3d_Vertex& thePoint,
1162 const Standard_Real theHeight,
1163 const Quantity_PlaneAngle theAngle,
1164 const Graphic3d_TextPath theTp,
1165 const Graphic3d_HorizontalTextAlignment theHta,
1166 const Graphic3d_VerticalTextAlignment theVta,
1167 const Standard_Boolean theToEvalMinMax)
1168{
1169 const NCollection_String aText ((Standard_Utf16Char* )theText.ToExtString());
1170 Text (aText.ToCString(), thePoint, theHeight, theAngle,
1171 theTp, theHta, theVta, theToEvalMinMax);
1172}
1173
1174// =======================================================================
1175// function : Text
1176// purpose :
1177// =======================================================================
1178void Graphic3d_Group::Text (const TCollection_ExtendedString& theText,
1179 const Graphic3d_Vertex& thePoint,
1180 const Standard_Real theHeight,
1181 const Standard_Boolean theToEvalMinMax)
1182{
1183 const NCollection_String aText ((Standard_Utf16Char* )theText.ToExtString());
1184 Text (aText.ToCString(), thePoint, theHeight, 0.0,
1185 Graphic3d_TP_RIGHT, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM, theToEvalMinMax);
7fd59977 1186}
31c0e219 1187
1188// =======================================================================
1189// function : SetClosed
1190// purpose :
1191// =======================================================================
1192void Graphic3d_Group::SetClosed (const Standard_Boolean theIsClosed)
1193{
1194 myIsClosed = theIsClosed;
1195}
1196
1197// =======================================================================
1198// function : IsClosed
1199// purpose :
1200// =======================================================================
1201Standard_Boolean Graphic3d_Group::IsClosed() const
1202{
1203 return myIsClosed;
1204}