summaryrefslogtreecommitdiff
path: root/src/Graphic3d/Graphic3d_Group_13.cxx
blob: f607fff7dce7122444a971eb444ae2db034d6537 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// File		Graphic3d_Graoup_13.cxx
// Created	16/06/2000 : ATS,SPK,GG : G005: Calculate bounding box coordinates for ARRAY primitives

#include <Graphic3d_Group.jxx>
#include <Graphic3d_Group.pxx>
#include <gp_Pnt.hxx>

void Graphic3d_Group :: AddPrimitiveArray ( const Handle(Graphic3d_ArrayOfPrimitives)& elem,const Standard_Boolean EvalMinMax )  
{
	if (IsDeleted () ) return;

        if( !elem->IsValid() ) return;

	if( !MyContainsFacet && 
		(elem->Type() != Graphic3d_TOPA_POLYLINES) &&
		(elem->Type() != Graphic3d_TOPA_SEGMENTS) &&
		(elem->Type() != Graphic3d_TOPA_POINTS) ) {
	  MyStructure->GroupsWithFacet (+1);
	  MyContainsFacet = Standard_True;
	}

	MyIsEmpty	= Standard_False;

	MyListOfPArray.Append(elem);

	// Min-Max Update
	if (EvalMinMax) {
	  Standard_Real x,y,z;

	  for (int k=1; k<=elem->VertexNumber() ; k++) {
	    elem->Vertice(k,x,y,z);

	    if (x < MyBounds.XMin) MyBounds.XMin	= Standard_ShortReal(x);
	    if (y < MyBounds.YMin) MyBounds.YMin	= Standard_ShortReal(y);
	    if (z < MyBounds.ZMin) MyBounds.ZMin	= Standard_ShortReal(z);
	    if (x > MyBounds.XMax) MyBounds.XMax	= Standard_ShortReal(x);
	    if (y > MyBounds.YMax) MyBounds.YMax	= Standard_ShortReal(y);
	    if (z > MyBounds.ZMax) MyBounds.ZMax	= Standard_ShortReal(z);
	  }
	}

	MyGraphicDriver->PrimitiveArray(MyCGroup, elem->Array());

	Update ();
}

void Graphic3d_Group :: RemovePrimitiveArrays () {
  // clear primitives array's visualization data in graphics driver and remove
  // references to it in driver
  if (!IsEmpty() && !MyGraphicDriver.IsNull())
  {
    for (Graphic3d_ListIteratorOfListOfPArray it (MyListOfPArray);
         it.More(); it.Next())
      MyGraphicDriver->RemovePrimitiveArray (MyCGroup, it.Value()->Array());
  }

  // remove references to primitives arrays
  MyListOfPArray.Clear();
}

Standard_Integer Graphic3d_Group :: ArrayNumber () const {

  	return MyListOfPArray.Extent();
}

void Graphic3d_Group :: InitDefinedArray() {
	MyListOfPArrayIterator.Initialize(MyListOfPArray);
}

void Graphic3d_Group :: NextDefinedArray() {
	MyListOfPArrayIterator.Next();
}

Standard_Boolean Graphic3d_Group :: MoreDefinedArray() {
	return MyListOfPArrayIterator.More();
}

Handle(Graphic3d_ArrayOfPrimitives) Graphic3d_Group :: DefinedArray() const {

	return MyListOfPArrayIterator.Value();
}

void Graphic3d_Group :: RemovePrimitiveArray ( const Standard_Integer aRank ) {

	if( aRank < 1 || aRank > ArrayNumber() ) {
	  Standard_OutOfRange::Raise(" BAD ARRAY index");
	}
	Graphic3d_ListIteratorOfListOfPArray it(MyListOfPArray);
	for( Standard_Integer i=1 ; it.More() ; it.Next(),i++ ) {
	  if( aRank == i ) break;
	}

  // clear primitives array's visualization data in graphics driver and remove
  // references to it in driver
  if (!IsEmpty() && !MyGraphicDriver.IsNull())
    MyGraphicDriver->RemovePrimitiveArray (MyCGroup, it.Value()->Array());

  // remove references to primitives array
  MyListOfPArray.Remove (it);
}

void Graphic3d_Group :: UserDraw ( const Standard_Address AnObject,				   
				   const Standard_Boolean EvalMinMax,
				   const Standard_Boolean ContainsFacet )
{
	if (IsDeleted ()) return;

	// SAMTECH contribution 5 July 2007 -- BEGIN
	// Without this modification, the group assumes the primitive contains
	// no polygons and does not require the Z-buffer for display.
	if (!MyContainsFacet && ContainsFacet) {
	  MyStructure->GroupsWithFacet (+1);
	  MyContainsFacet = Standard_True;
	}
	// SAMTECH contribution 5 July 2007 -- END

	MyIsEmpty	= Standard_False;

        Graphic3d_CUserDraw AUserDraw;
        AUserDraw.Data = AnObject;
        AUserDraw.Bounds = ( EvalMinMax? &MyBounds : NULL );
	MyGraphicDriver->UserDraw (MyCGroup, AUserDraw);

	Update ();
}