d1cbaaadc1d8e314784f09b2a3e2007dee8bdecf
[occt.git] / src / Graphic3d / Graphic3d_Group_13.cxx
1 // Created on: 2000-06-16
2 // Copyright (c) 2000-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #include <Graphic3d_Group.jxx>
16 #include <Graphic3d_Group.pxx>
17
18 #include <Graphic3d_ArrayOfPoints.hxx>
19 #include <gp_Pnt.hxx>
20
21 // =======================================================================
22 // function : AddPrimitiveArray
23 // purpose  :
24 // =======================================================================
25
26 void Graphic3d_Group :: AddPrimitiveArray ( const Handle(Graphic3d_ArrayOfPrimitives)& elem,const Standard_Boolean EvalMinMax )  
27 {
28         if (IsDeleted () ) return;
29
30         if( !elem->IsValid() ) return;
31
32         if( !MyContainsFacet && 
33                 (elem->Type() != Graphic3d_TOPA_POLYLINES) &&
34                 (elem->Type() != Graphic3d_TOPA_SEGMENTS) &&
35                 (elem->Type() != Graphic3d_TOPA_POINTS) ) {
36           MyStructure->GroupsWithFacet (+1);
37           MyContainsFacet = Standard_True;
38         }
39
40         MyIsEmpty       = Standard_False;
41
42         MyListOfPArray.Append(elem);
43
44         // Min-Max Update
45         if (EvalMinMax) {
46           Standard_Real x,y,z;
47
48           for (int k=1; k<=elem->VertexNumber() ; k++) {
49             elem->Vertice(k,x,y,z);
50
51             if (x < MyBounds.XMin) MyBounds.XMin        = Standard_ShortReal(x);
52             if (y < MyBounds.YMin) MyBounds.YMin        = Standard_ShortReal(y);
53             if (z < MyBounds.ZMin) MyBounds.ZMin        = Standard_ShortReal(z);
54             if (x > MyBounds.XMax) MyBounds.XMax        = Standard_ShortReal(x);
55             if (y > MyBounds.YMax) MyBounds.YMax        = Standard_ShortReal(y);
56             if (z > MyBounds.ZMax) MyBounds.ZMax        = Standard_ShortReal(z);
57           }
58         }
59
60         MyGraphicDriver->PrimitiveArray(MyCGroup, elem->Array());
61
62         Update ();
63 }
64
65 // =======================================================================
66 // function : Marker
67 // purpose  :
68 // =======================================================================
69
70 void Graphic3d_Group::Marker (const Graphic3d_Vertex& thePoint,
71                               const Standard_Boolean  theToEvalMinMax)
72 {
73   Handle(Graphic3d_ArrayOfPoints) aPoints = new Graphic3d_ArrayOfPoints (1);
74   aPoints->AddVertex (thePoint.X(), thePoint.Y(), thePoint.Z());
75   AddPrimitiveArray (aPoints, theToEvalMinMax);
76 }
77
78 // =======================================================================
79 // function : UserDraw
80 // purpose  :
81 // =======================================================================
82
83 void Graphic3d_Group :: UserDraw ( const Standard_Address AnObject,                                
84                                    const Standard_Boolean EvalMinMax,
85                                    const Standard_Boolean ContainsFacet )
86 {
87         if (IsDeleted ()) return;
88
89         // Without this modification, the group assumes the primitive contains
90         // no polygons and does not require the Z-buffer for display.
91         if (!MyContainsFacet && ContainsFacet) {
92           MyStructure->GroupsWithFacet (+1);
93           MyContainsFacet = Standard_True;
94         }
95
96         MyIsEmpty       = Standard_False;
97
98         Graphic3d_CUserDraw AUserDraw;
99         AUserDraw.Data = AnObject;
100         AUserDraw.Bounds = ( EvalMinMax? &MyBounds : NULL );
101         MyGraphicDriver->UserDraw (MyCGroup, AUserDraw);
102
103         Update ();
104 }
105
106 // =======================================================================
107 // function : SetFlippingOptions
108 // purpose  :
109 // =======================================================================
110
111 void Graphic3d_Group::SetFlippingOptions (const Standard_Boolean theIsEnabled,
112                                           const gp_Ax2&          theRefPlane)
113 {
114   MyGraphicDriver->SetFlippingOptions (MyCGroup, theIsEnabled, theRefPlane);
115 }
116
117 // =======================================================================
118 // function : SetStencilTestOptions
119 // purpose  :
120 // =======================================================================
121 void Graphic3d_Group::SetStencilTestOptions (const Standard_Boolean theIsEnabled)
122 {
123   MyGraphicDriver->SetStencilTestOptions (MyCGroup, theIsEnabled);
124 }