0023830: BRepExtrema_DistShapeShape does not find intersection of face with edge
[occt.git] / src / Xw / Xw_set_line_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#include <Xw_Extension.h>
20
b311480e 21/* ifdef then trace on */
7fd59977 22#ifdef TRACE
23#define TRACE_SET_LINE_ATTRIB
24#define TRACE_GET_LINE_ATTRIB
25#endif
26
27/*
28 XW_ATTRIB Xw_set_line_attrib (awindow,color,type,width,mode):
29 XW_EXT_WINDOW *awindow
30 int color ; Color index to used 0 >= x < MAXCOLOR
31 int type ; Type index to used 0 >= x < MAXTYPE
32 int width ; Width index to used 0 >= x < MAXWIDTH
33 XW_DRAWMODE mode ; Draw Mode must be one of DRAWMODE enum
34
35 Set Line Color,Type and Width current graphic attrib .
36
37 Returns Selected Line Graphic Attribute Index if successful
38 Returns 0 if Bad Color,Type or Width Index
39
40*/
41
42#ifdef XW_PROTOTYPE
43XW_ATTRIB Xw_set_line_attrib (void *awindow,int color,int type,int width,XW_DRAWMODE mode)
44#else
45XW_ATTRIB Xw_set_line_attrib (awindow,color,type,width,mode)
46void *awindow;
47int color,type,width ;
48XW_DRAWMODE mode ;
49#endif /*XW_PROTOTYPE*/
50{
51XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
52XGCValues gc_values ;
53XW_ATTRIB code ;
54int i,j,k,function,mask = 0 ;
55unsigned long planemask,hcolor ;
56
57 if( !Xw_isdefine_window(pwindow) ) {
58 /*ERROR*Bad EXT_WINDOW Address*/
59 Xw_set_error(24,"Xw_set_line_attrib",pwindow) ;
60 return (0) ;
61 }
62
63 if( _BINDEX > 0 ) return (1) ;
64
65 if ( !Xw_isdefine_color(_COLORMAP,color) ) {
66 /*ERROR*Bad Defined Color*/
67 Xw_set_error(41,"Xw_set_line_attrib",&color) ;
68 return (0) ;
69 }
70 if ( !Xw_isdefine_type(_TYPEMAP,type) ) {
71 /*WARNING*Bad Defined Type*/
72 Xw_set_error(50,"Xw_set_line_attrib",&type) ;
73 type = 0 ;
74 }
75 if ( !Xw_isdefine_width(_WIDTHMAP,width) ) {
76 /*WARNING*Bad Defined Width*/
77 Xw_set_error(52,"Xw_set_line_attrib",&width) ;
78 width = 0 ;
79 }
80
81 if( !_TYPEMAP || !_TYPEMAP->types[type] ) type = 0 ;
82 if( !_WIDTHMAP || (_WIDTHMAP->widths[width] <= 1) ) width = 0 ;
83
84 code = QGCODE(color,type,width,mode) ;
85 if( code == pwindow->qgline[pwindow->lineindex].code ) {
86 /* The last index computed is already set*/
87 pwindow->qgline[pwindow->lineindex].count++ ;
88 return (pwindow->lineindex+1) ;
89 }
90
91 for( i=j=0,k=MAXQG ; i<MAXQG ; i++ ) {
92 if( code == pwindow->qgline[i].code ) k = i ;
93 if( pwindow->qgline[i].count < pwindow->qgline[j].count ) j = i;
94 }
95
96 if( k < MAXQG ) {
97 /* A GC index already exist,use it */
98 pwindow->lineindex = k ;
99 pwindow->qgline[k].count++ ;
100 return (k+1) ;
101 }
102
103 pwindow->lineindex = j ;
104 pwindow->qgline[j].count = 1 ;
105
106 Xw_get_color_attrib(pwindow,mode,color,&hcolor,&function,&planemask);
107 if( mode != QGMODE(pwindow->qgline[j].code) ) {
108 mask |= GCFunction | GCPlaneMask | GCForeground ;
109 gc_values.function = function ;
110 gc_values.plane_mask = planemask ;
111 gc_values.foreground = hcolor ;
112 } else if( color != QGCOLOR(pwindow->qgline[j].code) ) {
113 mask |= GCForeground ;
114 gc_values.foreground = hcolor ;
115 }
116
117 if( width != QGWIDTH(pwindow->qgline[j].code) ) {
118 mask |= GCLineWidth ;
119 if( width > 0 ) {
120 gc_values.line_width = (_WIDTHMAP->widths[width] > 1) ?
121 _WIDTHMAP->widths[width] : 0 ;
122 } else {
123 gc_values.line_width = 0 ;
124 }
125 }
126
127 if( type != QGTYPE(pwindow->qgline[j].code) ) {
128 mask |= GCLineStyle ;
129 if( type > 0 ) {
130 gc_values.line_style = LineOnOffDash ;
131 XSetDashes(_DISPLAY,pwindow->qgline[j].gc,0,
132 (char*)_TYPEMAP->types[type],strlen((char*)_TYPEMAP->types[type])) ;
133 } else {
134 gc_values.line_style = LineSolid ;
135 }
136 }
137
138 k = j+1 ;
139
140 if( mask ) {
141 XChangeGC(_DISPLAY,pwindow->qgline[j].gc,mask,&gc_values) ;
142 pwindow->qgline[j].code = code ;
143
144#ifdef TRACE_SET_LINE_ATTRIB
145if( Xw_get_trace() ) {
146 printf(" %d = Xw_set_line_attrib(%lx,%d,%d,%d,%d)\n",
147 k,(long ) pwindow,color,type,width,mode) ;
148}
149#endif
150 }
151
152 return (k) ;
153}
154
155/*
156 XW_ATTRIB Xw_get_poly_attrib (awindow,color,type,width,mode):
157 XW_EXT_WINDOW *awindow
158 int *color ; Returns current Color index
159 int *type ; Returns current Type
160 int *width ; Returns current Width index
161 DRAWMODE *mode ; Returns current Draw Mode
162
163 Returns Selected Polyline Attribute Index
164
165*/
166
167#ifdef XW_PROTOTYPE
168XW_ATTRIB Xw_get_line_attrib (void *awindow,int *color,int *type,int *width,XW_DRAWMODE *mode)
169#else
170XW_ATTRIB Xw_get_line_attrib (awindow,color,type,width,mode)
171void *awindow;
172int *color,*width ;
173int *type ;
174XW_DRAWMODE *mode ;
175#endif /*XW_PROTOTYPE*/
176{
177XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
178XW_ATTRIB code;
179int j,k;
180
181 j = pwindow->lineindex; k = j+1;
182
183 code = pwindow->qgline[j].code;
184
185 *color = QGCOLOR(code);
186 *type = QGTYPE(code);
187 *width = QGWIDTH(code);
188 *mode = (XW_DRAWMODE) QGMODE(code);
189
190#ifdef TRACE_GET_LINE_ATTRIB
191if( Xw_get_trace() > 1 ) {
192 printf(" %d = Xw_get_line_attrib(%lx,%d,%d,%d,%d)\n",
193 k,(long ) pwindow,*color,*type,*width,*mode) ;
194}
195#endif
196
197 return code;
198}