0023426: Tool to compare two runs of tests on the same station
[occt.git] / src / Xw / Xw_set_poly_attrib.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18
19#define PRO4391 /*GG_040696
20// Traitement des polygones transparents.
21*/
22
23#include <Xw_Extension.h>
24
25 /* ifdef then trace on */
26#ifdef TRACE
27#define TRACE_SET_POLY_ATTRIB
28#define TRACE_GET_POLY_ATTRIB
29#endif
30
31/*
32 XW_ATTRIB Xw_set_poly_attrib (awindow,color,type,tile,mode):
33 XW_EXT_WINDOW *awindow
34 int color ; Color index to used 0 >= x < MAXCOLOR
35 int type ; Type can be TRUE if EDGES must be Draw with the
36 set_line_attrib attributes
37 int tile ; Tile index to used x < MAXTILE
38 DRAWMODE mode ; Draw Mode must be one of DRAWMODE enum
39
40 Set Poly Color,Type and Tile current graphic attrib .
41 NOTE than if tile is < 0 the poly background is transparente.
42
43 Returns Selected Polygon Attribute Index if successful
44 Returns 0 if Bad Color,Type or Tile Index
45
46*/
47
48#ifdef XW_PROTOTYPE
49XW_ATTRIB Xw_set_poly_attrib (void *awindow,int color,int type,int tile,XW_DRAWMODE mode)
50#else
51XW_ATTRIB Xw_set_poly_attrib (awindow,color,type,tile,mode)
52void *awindow;
53int color,tile ;
54int type ;
55XW_DRAWMODE mode ;
56#endif /*XW_PROTOTYPE*/
57{
58XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
59XGCValues gc_values ;
60XW_ATTRIB code ;
61int i,j,k,function,mask = 0 ;
62unsigned long planemask,hcolor ;
63
64 if( !Xw_isdefine_window(pwindow) ) {
65 /*ERROR*Bad EXT_WINDOW Address*/
66 Xw_set_error(24,"Xw_set_poly_attrib",pwindow) ;
67 return (0) ;
68 }
69
70 if( _BINDEX > 0 ) return (1) ;
71
72 if ( !Xw_isdefine_color(_COLORMAP,color) ) {
73 /*ERROR*Bad Defined Color*/
74 Xw_set_error(41,"Xw_set_poly_attrib",&color) ;
75 return (0) ;
76 }
77
78 if( tile > 0 ) {
79 if ( !Xw_isdefine_tile(_TILEMAP,tile) ) {
80 /*WARNING*Bad Defined Tile*/
81 Xw_set_error(78,"Xw_set_poly_attrib",&tile) ;
82#ifdef PRO4391
83 tile = 1 ;
84 }
85 } else if( tile < 0 ) {
86 tile = 0;
87 } else {
88 tile = 1;
89 }
90#else
91 tile = 0 ;
92 }
93 }
94
95 if( !_TILEMAP || !_TILEMAP->tiles[tile] ) tile = 0 ;
96#endif
97
98 code = QGCODE(color,type,tile,mode) ;
99 if( code == pwindow->qgpoly[pwindow->polyindex].code ) {
100 /* The last index computed is already set*/
101 pwindow->qgpoly[pwindow->polyindex].count++ ;
102 return (pwindow->polyindex+1) ;
103 }
104
105 for( i=j=0,k=MAXQG ; i<MAXQG ; i++ ) {
106 if( code == pwindow->qgpoly[i].code ) k = i ;
107 if( pwindow->qgpoly[i].count < pwindow->qgpoly[j].count ) j = i;
108 }
109
110 if( k < MAXQG ) {
111 /* A GC index already exist,use it */
112 pwindow->polyindex = k ;
113 pwindow->qgpoly[k].count++ ;
114 return (k+1) ;
115 }
116
117 pwindow->polyindex = j ;
118 pwindow->qgpoly[j].count = 1 ;
119
120 Xw_get_color_attrib(pwindow,mode,color,&hcolor,&function,&planemask);
121 if( mode != QGMODE(pwindow->qgpoly[j].code) ) {
122 mask |= GCFunction | GCPlaneMask | GCForeground ;
123 gc_values.function = function ;
124 gc_values.plane_mask = planemask ;
125 gc_values.foreground = hcolor ;
126 } else if( color != QGCOLOR(pwindow->qgpoly[j].code) ) {
127 mask |= GCForeground;
128 gc_values.foreground = hcolor ;
129 }
130
131 if( tile != QGTILE(pwindow->qgpoly[j].code) ) {
132 mask |= GCFillStyle ;
133#ifdef PRO4391
134 if( (tile > 0) && _TILEMAP && _TILEMAP->tiles[tile] ) {
135#else
136 if( tile > 0 ) {
137#endif
138 mask |= GCStipple ;
139 gc_values.fill_style = FillOpaqueStippled ;
140 gc_values.stipple = _TILEMAP->tiles[tile] ;
141 } else {
142 gc_values.fill_style = FillSolid ;
143 }
144 }
145
146 k = j+1 ;
147
148 if( mask ) {
149 XChangeGC(_DISPLAY,pwindow->qgpoly[j].gc,mask,&gc_values) ;
150 pwindow->qgpoly[j].code = code ;
151
152#ifdef TRACE_SET_POLY_ATTRIB
153if( Xw_get_trace() > 1 ) {
154 printf(" %d = Xw_set_poly_attrib(%lx,%d,%d,%d,%d)\n",
155 k,(long ) pwindow,color,type,tile,mode) ;
156}
157#endif
158 }
159
160 return (k) ;
161}
162
163/*
164 XW_ATTRIB Xw_get_poly_attrib (awindow,color,type,tile,mode):
165 XW_EXT_WINDOW *awindow
166 int *color ; Returns current Color index
167 int *type ; Returns current Type
168 int *tile ; Returns current Tile index
169 DRAWMODE *mode ; Returns current Draw Mode
170
171 Returns Selected Polygon Attribute Index
172
173*/
174
175#ifdef XW_PROTOTYPE
176XW_ATTRIB Xw_get_poly_attrib (void *awindow,int *color,int *type,int *tile,XW_DRAWMODE *mode)
177#else
178XW_ATTRIB Xw_get_poly_attrib (awindow,color,type,tile,mode)
179void *awindow;
180int *color,*tile ;
181int *type ;
182XW_DRAWMODE *mode ;
183#endif /*XW_PROTOTYPE*/
184{
185XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
186XW_ATTRIB code;
187int j,k;
188
189 j = pwindow->polyindex; k = j+1;
190
191 code = pwindow->qgpoly[j].code;
192
193 *color = QGCOLOR(code);
194 *type = QGTYPE(code);
195 *tile = QGTILE(code) > 1 ? QGTILE(code) : QGTILE(code) - 1;
196 *mode = (XW_DRAWMODE) QGMODE(code);
197
198#ifdef TRACE_GET_POLY_ATTRIB
199if( Xw_get_trace() > 1 ) {
200 printf(" %d = Xw_get_poly_attrib(%lx,%d,%d,%d,%d)\n",
201 k,(long ) pwindow,*color,*type,*tile,*mode) ;
202}
203#endif
204
205 return code;
206}