1 // Created on: 2000-06-16
2 // Copyright (c) 2000-2012 OPEN CASCADE SAS
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.
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.
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.
20 #include <Graphic3d_Group.jxx>
21 #include <Graphic3d_Group.pxx>
24 void Graphic3d_Group :: AddPrimitiveArray ( const Handle(Graphic3d_ArrayOfPrimitives)& elem,const Standard_Boolean EvalMinMax )
26 if (IsDeleted () ) return;
28 if( !elem->IsValid() ) return;
30 if( !MyContainsFacet &&
31 (elem->Type() != Graphic3d_TOPA_POLYLINES) &&
32 (elem->Type() != Graphic3d_TOPA_SEGMENTS) &&
33 (elem->Type() != Graphic3d_TOPA_POINTS) ) {
34 MyStructure->GroupsWithFacet (+1);
35 MyContainsFacet = Standard_True;
38 MyIsEmpty = Standard_False;
40 MyListOfPArray.Append(elem);
46 for (int k=1; k<=elem->VertexNumber() ; k++) {
47 elem->Vertice(k,x,y,z);
49 if (x < MyBounds.XMin) MyBounds.XMin = Standard_ShortReal(x);
50 if (y < MyBounds.YMin) MyBounds.YMin = Standard_ShortReal(y);
51 if (z < MyBounds.ZMin) MyBounds.ZMin = Standard_ShortReal(z);
52 if (x > MyBounds.XMax) MyBounds.XMax = Standard_ShortReal(x);
53 if (y > MyBounds.YMax) MyBounds.YMax = Standard_ShortReal(y);
54 if (z > MyBounds.ZMax) MyBounds.ZMax = Standard_ShortReal(z);
58 MyGraphicDriver->PrimitiveArray(MyCGroup, elem->Array());
63 void Graphic3d_Group :: RemovePrimitiveArrays () {
64 // clear primitives array's visualization data in graphics driver and remove
65 // references to it in driver
66 if (!IsEmpty() && !MyGraphicDriver.IsNull())
68 for (Graphic3d_ListIteratorOfListOfPArray it (MyListOfPArray);
70 MyGraphicDriver->RemovePrimitiveArray (MyCGroup, it.Value()->Array());
73 // remove references to primitives arrays
74 MyListOfPArray.Clear();
77 Standard_Integer Graphic3d_Group :: ArrayNumber () const {
79 return MyListOfPArray.Extent();
82 void Graphic3d_Group :: InitDefinedArray() {
83 MyListOfPArrayIterator.Initialize(MyListOfPArray);
86 void Graphic3d_Group :: NextDefinedArray() {
87 MyListOfPArrayIterator.Next();
90 Standard_Boolean Graphic3d_Group :: MoreDefinedArray() {
91 return MyListOfPArrayIterator.More();
94 Handle(Graphic3d_ArrayOfPrimitives) Graphic3d_Group :: DefinedArray() const {
96 return MyListOfPArrayIterator.Value();
99 void Graphic3d_Group :: RemovePrimitiveArray ( const Standard_Integer aRank ) {
101 if( aRank < 1 || aRank > ArrayNumber() ) {
102 Standard_OutOfRange::Raise(" BAD ARRAY index");
104 Graphic3d_ListIteratorOfListOfPArray it(MyListOfPArray);
105 for( Standard_Integer i=1 ; it.More() ; it.Next(),i++ ) {
106 if( aRank == i ) break;
109 // clear primitives array's visualization data in graphics driver and remove
110 // references to it in driver
111 if (!IsEmpty() && !MyGraphicDriver.IsNull())
112 MyGraphicDriver->RemovePrimitiveArray (MyCGroup, it.Value()->Array());
114 // remove references to primitives array
115 MyListOfPArray.Remove (it);
118 void Graphic3d_Group :: UserDraw ( const Standard_Address AnObject,
119 const Standard_Boolean EvalMinMax,
120 const Standard_Boolean ContainsFacet )
122 if (IsDeleted ()) return;
124 // Without this modification, the group assumes the primitive contains
125 // no polygons and does not require the Z-buffer for display.
126 if (!MyContainsFacet && ContainsFacet) {
127 MyStructure->GroupsWithFacet (+1);
128 MyContainsFacet = Standard_True;
131 MyIsEmpty = Standard_False;
133 Graphic3d_CUserDraw AUserDraw;
134 AUserDraw.Data = AnObject;
135 AUserDraw.Bounds = ( EvalMinMax? &MyBounds : NULL );
136 MyGraphicDriver->UserDraw (MyCGroup, AUserDraw);