0023533: Unitialized variables used, IntTools_TopolTool.cxx
[occt.git] / src / Xw / Xw_set_marker_attrib.cxx
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
18
19 #include <Xw_Extension.h>
20
21 /* ifdef then trace on */
22 #ifdef TRACE
23 #define TRACE_SET_MARKER_ATTRIB
24 #endif
25
26 /*
27    XW_ATTRIB Xw_set_marker_attrib (awindow,color,type,width,mode):
28    XW_EXT_WINDOW *awindow
29    int color ;          Color index to used 0 >= x < MAXCOLOR
30    int type ;           Type can be TRUE if marker must be filled with the
31                                         set_poly_attrib attributes 
32    int width ;          Width index to used 0 >= x < MAXWIDTH
33    DRAWMODE mode ;      Draw Mode must be one of DRAWMODE enum 
34
35         Set Marker Color,Type and Marker current graphic attrib .
36
37         Returns Selected Marker Attribute Index if successful
38         Returns 0 if Bad Color,Type or Marker Index
39
40 */
41
42 #ifdef XW_PROTOTYPE
43 XW_ATTRIB Xw_set_marker_attrib (void *awindow,int color,int type,int width,XW_DRAWMODE mode)
44 #else
45 XW_ATTRIB Xw_set_marker_attrib (awindow,color,type,width,mode)
46 void *awindow;
47 int color,type ;
48 int width ;
49 XW_DRAWMODE mode ;
50 #endif /*XW_PROTOTYPE*/
51 {
52 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
53 XGCValues gc_values ;
54 XW_ATTRIB code ;
55 int i,j,k,function,mask = 0;
56 unsigned long planemask,hcolor ;
57
58         if( !Xw_isdefine_window(pwindow) ) {
59             /*ERROR*Bad EXT_WINDOW Address*/
60             Xw_set_error(24,"Xw_set_marker_attrib",pwindow) ;
61             return (0) ;
62         }
63
64         if( _BINDEX > 0 ) return (1) ;
65
66         if ( !Xw_isdefine_color(_COLORMAP,color) ) {
67             /*ERROR*Bad Defined Color*/
68             Xw_set_error(41,"Xw_set_marker_attrib",&color) ;
69             return (0) ;
70         }
71
72         if ( !Xw_isdefine_width(_WIDTHMAP,width) ) {
73             /*WARNING*Bad Defined Width*/
74             Xw_set_error(52,"Xw_set_marker_attrib",&width) ;
75             width = 0 ;
76         }
77
78         if( !_WIDTHMAP || (_WIDTHMAP->widths[width] <= 1) ) width = 0 ;
79  
80         code = QGCODE(color,type,width,mode) ;
81         if( code == pwindow->qgmark[pwindow->markindex].code ) {
82                                 /* The last index computed is already set*/
83             pwindow->qgmark[pwindow->markindex].count++ ;
84             return (pwindow->markindex+1) ;
85         }
86
87         for( i=j=0,k=MAXQG ; i<MAXQG ; i++ ) {
88              if( code == pwindow->qgmark[i].code ) k = i ;
89              if( pwindow->qgmark[i].count < pwindow->qgmark[j].count ) j = i;
90         }
91
92         if( k < MAXQG ) {
93                                         /* A GC index already exist,use it */
94             pwindow->markindex = k ;
95             pwindow->qgmark[k].count++ ;
96             return (k+1) ;      
97         }
98
99         pwindow->markindex = j ;
100         pwindow->qgmark[j].count = 1 ;
101
102         Xw_get_color_attrib(pwindow,mode,color,&hcolor,&function,&planemask);
103         if( mode != QGMODE(pwindow->qgmark[j].code) ) {
104             mask |= GCFunction | GCPlaneMask | GCForeground ;
105             gc_values.function = function ;
106             gc_values.plane_mask = planemask ;
107             gc_values.foreground = hcolor ;
108         } else if( color != QGCOLOR(pwindow->qgmark[j].code) ) {
109             mask |= GCForeground;
110             gc_values.foreground = hcolor ;
111         }
112
113         if( width != QGWIDTH(pwindow->qgmark[j].code) ) {
114             mask |= GCLineWidth ;
115             if( width > 0 ) {
116                 gc_values.line_width = _WIDTHMAP->widths[width] ;
117             } else {   
118                 gc_values.line_width = 0 ;
119             }
120         }
121  
122         k = j+1 ;
123
124         if( mask ) {
125             XChangeGC(_DISPLAY,pwindow->qgmark[j].gc,mask,&gc_values) ;
126             pwindow->qgmark[j].code = code ; 
127
128 #ifdef  TRACE_SET_MARKER_ATTRIB
129 if( Xw_get_trace() > 1 ) {
130     printf(" %d = Xw_set_marker_attrib(%lx,%d,%d,%d,%d)\n",
131                                 k,(long ) pwindow,color,type,width,mode) ;
132 }
133 #endif
134         }
135
136         return (k) ;    
137 }