1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
18 #define S3593 /*GG_130398
20 Activer le clipping de maniere optionnelle
23 #include <Xw_Extension.h>
25 /* ifdef then trace on */
27 #define TRACE_DRAW_LINE
31 STATUS Xw_draw_line (awindow,npoint,x,y):
32 XW_EXT_WINDOW *awindow
33 int npoint Polyline point number
34 float *x,*y Points Arrays
37 Display continuous line in current QG set by set_line_attrib .
38 Note that lines can be buffered depending of the DisplayMode context
39 and Flush at Xw_flush time .
41 returns ERROR if npoint > MAXPOINTS
42 returns SUCCESS always
46 static int BeginLine = -1 ;
47 static XW_EXT_LINE *plinelist ;
48 static XW_EXT_POINT *plinedesc ;
49 static XSegment segment;
52 XW_STATUS Xw_draw_line (void* awindow,int npoint,float* px,float* py)
54 XW_STATUS Xw_draw_line (awindow,npoint,px,py)
58 #endif /*XW_PROTOTYPE*/
60 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*) awindow ;
61 XW_EXT_BUFFER *pbuffer ;
62 int i,nline,ldesc,bindex;
65 if( !Xw_isdefine_window(pwindow) ) {
66 /*ERROR*Bad EXT_WINDOW Address*/
67 Xw_set_error(24,"Xw_draw_line",pwindow) ;
71 if( npoint > MAXPOINTS ) {
73 /*ERROR*Too many points in LINE*/
74 Xw_set_error(28,"Xw_draw_line",&npoint) ;
79 pbuffer = &_BUFFER(bindex) ;
80 for( plinelist = pbuffer->plinelist ; plinelist ;
81 plinelist = (XW_EXT_LINE*)plinelist->link ) {
82 if( plinelist->nline < MAXLINES ) break ;
86 plinelist = Xw_add_polyline_structure(pbuffer) ;
89 if( !plinelist ) return XW_ERROR ;
91 for( plinedesc = pbuffer->plinedesc ; plinedesc ;
92 plinedesc = (XW_EXT_POINT*)plinedesc->link ) {
93 if( plinedesc->npoint + npoint <= MAXPOINTS ) break ;
97 plinedesc = Xw_add_line_desc_structure(pbuffer) ;
100 if( !plinedesc ) return XW_ERROR ;
102 nline = plinelist->nline ;
103 ldesc = plinedesc->npoint ;
104 plinelist->plines[nline] = &plinedesc->rpoints[ldesc] ;
105 for( i=0 ; i<npoint ; i++ ) {
107 x = PXPOINT(px[i], pwindow->xratio) ;
108 y = PYPOINT(py[i], pwindow->attributes.height, pwindow->yratio) ;
111 if( pwindow->clipflag ) {
115 status = Xw_clip_segment(pwindow,lx,ly,x,y,&segment);
117 if( (i < 2) || (status & 0xF ) ) {
118 plinedesc->rpoints[ldesc].x = segment.x1 ;
119 plinedesc->rpoints[ldesc].y = segment.y1 ;
122 int xx = segment.x1,yy = segment.y1;
123 pbuffer->rxmin = min(pbuffer->rxmin,xx) ;
124 pbuffer->rymin = min(pbuffer->rymin,yy) ;
125 pbuffer->rxmax = max(pbuffer->rxmax,xx) ;
126 pbuffer->rymax = max(pbuffer->rymax,yy) ;
129 plinedesc->rpoints[ldesc].x = segment.x2 ;
130 plinedesc->rpoints[ldesc].y = segment.y2 ;
133 int xx = segment.x2,yy = segment.y2;
134 pbuffer->rxmin = min(pbuffer->rxmin,xx) ;
135 pbuffer->rymin = min(pbuffer->rymin,yy) ;
136 pbuffer->rxmax = max(pbuffer->rxmax,xx) ;
137 pbuffer->rymax = max(pbuffer->rymax,yy) ;
144 plinedesc->rpoints[ldesc].x = x ;
145 plinedesc->rpoints[ldesc].y = y ;
148 pbuffer->rxmin = min(pbuffer->rxmin,x) ;
149 pbuffer->rymin = min(pbuffer->rymin,y) ;
150 pbuffer->rxmax = max(pbuffer->rxmax,x) ;
151 pbuffer->rymax = max(pbuffer->rymax,y) ;
156 plinelist->lines[nline] = ldesc - plinedesc->npoint ;
157 if( plinelist->lines[nline] > 1 ) {
158 plinedesc->npoint = ldesc ;
161 pbuffer->isempty = False ;
162 } else if( BeginLine < 0 ) {
163 int index = pwindow->lineindex ;
164 Xw_draw_pixel_lines(pwindow,plinelist,pwindow->qgline[index].gc);
165 plinelist->nline = 0 ;
166 plinedesc->npoint = 0 ;
170 #ifdef TRACE_DRAW_LINE
171 if( Xw_get_trace() > 2 ) {
172 printf(" Xw_draw_line(%lx,%d)\n",(long ) pwindow,npoint) ;
173 for( i=0 ; i<npoint ; i++ ) {
174 printf(" Point(%d) = {%f,%f}\n",i,px[i],py[i]) ;
183 void Xw_draw_pixel_lines (XW_EXT_WINDOW* pwindow,XW_EXT_LINE *plinelist,GC gc)
185 void Xw_draw_pixel_lines (pwindow,plinelist,gc)
186 XW_EXT_WINDOW *pwindow;
187 XW_EXT_LINE *plinelist;
189 #endif /*XW_PROTOTYPE*/
194 for( i=0 ; i<plinelist->nline ; i++ ) {
195 npoint = plinelist->lines[i] ;
196 ppoint = plinelist->plines[i] ;
197 if( plinelist->isupdated ) {
198 ppoint += MAXPOINTS ;
200 if( ppoint && npoint > 1 ) {
201 XDrawLines(_DISPLAY,_DRAWABLE,gc,ppoint,npoint,CoordModeOrigin) ;
207 STATUS Xw_begin_line (awindow,npoint):
208 XW_EXT_WINDOW *awindow
209 int npoint Polyline point number
212 Begin Polyline which must be filled by Xw_line_point and
213 closed by Xw_close_line
215 returns ERROR if npoint > MAXPOINTS
216 returns SUCCESS if successful
220 static int Npoint = 0;
223 XW_STATUS Xw_begin_line(void* awindow,int npoint)
225 XW_STATUS Xw_begin_line(awindow,npoint)
228 #endif /*XW_PROTOTYPE*/
230 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow ;
231 XW_EXT_BUFFER *pbuffer ;
232 int nline,ldesc,bindex ;
234 if( !Xw_isdefine_window(pwindow) ) {
235 /*ERROR*Bad EXT_WINDOW Address*/
236 Xw_set_error(24,"Xw_begin_line",pwindow) ;
240 if( npoint > MAXPOINTS ) {
242 /*ERROR*Too many points in LINE*/
243 Xw_set_error(28,"Xw_begin_line",&npoint) ;
247 if( BeginLine >= 0 ) Xw_close_line(pwindow);
250 pbuffer = &_BUFFER(bindex) ;
251 for( plinelist = pbuffer->plinelist ; plinelist ;
252 plinelist = (XW_EXT_LINE*)plinelist->link ) {
253 if( plinelist->nline < MAXLINES ) break ;
257 plinelist = Xw_add_polyline_structure(pbuffer) ;
260 if( !plinelist ) return XW_ERROR ;
262 for( plinedesc = pbuffer->plinedesc ; plinedesc ;
263 plinedesc = (XW_EXT_POINT*)plinedesc->link ) {
264 if( plinedesc->npoint + npoint <= MAXPOINTS ) break ;
268 plinedesc = Xw_add_line_desc_structure(pbuffer) ;
271 if( !plinedesc ) return XW_ERROR ;
273 nline = plinelist->nline ;
274 ldesc = plinedesc->npoint ;
275 plinelist->lines[nline] = Npoint = 0 ;
276 plinelist->plines[nline] = &plinedesc->rpoints[ldesc] ;
279 #ifdef TRACE_DRAW_LINE
280 if( Xw_get_trace() > 2 ) {
281 printf(" Xw_begin_line(%lx,%d)\n",(long ) pwindow,npoint) ;
284 return (XW_SUCCESS) ;
288 STATUS Xw_line_point (awindow,x,y):
289 XW_EXT_WINDOW *awindow
290 float x,y New point to add in polyline in user-space coordinates
292 Fill Polyline with one point more
294 returns ERROR if Too Many Points in polylines
295 returns SUCCESS if successful
300 XW_STATUS Xw_line_point(void* awindow,float x,float y)
302 XW_STATUS Xw_line_point(awindow,x,y)
305 #endif /*XW_PROTOTYPE*/
307 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow ;
308 XW_EXT_BUFFER *pbuffer ;
311 if( BeginLine >= 0 ) {
312 int ldesc = plinedesc->npoint ;
313 if( ldesc >= MAXPOINTS ) {
314 /*ERROR*Too many points in LINE*/
315 Xw_set_error(28,"Xw_line_point",&ldesc) ;
316 Xw_close_line(pwindow) ;
321 pbuffer = &_BUFFER(bindex) ;
323 xi = PXPOINT(x, pwindow->xratio) ;
324 yi = PYPOINT(y, pwindow->attributes.height, pwindow->yratio) ;
327 if( pwindow->clipflag ) {
331 status = Xw_clip_segment(pwindow,Lx,Ly,xi,yi,&segment);
333 if( (Npoint < 2) || (status & 0xF ) ) {
334 plinedesc->rpoints[ldesc].x = segment.x1 ;
335 plinedesc->rpoints[ldesc].y = segment.y1 ;
338 int xx = segment.x1,yy = segment.y1;
339 pbuffer->isempty = False ;
340 pbuffer->rxmin = min(pbuffer->rxmin,xx) ;
341 pbuffer->rymin = min(pbuffer->rymin,yy) ;
342 pbuffer->rxmax = max(pbuffer->rxmax,xx) ;
343 pbuffer->rymax = max(pbuffer->rymax,yy) ;
346 plinedesc->rpoints[ldesc].x = segment.x2 ;
347 plinedesc->rpoints[ldesc].y = segment.y2 ;
350 int xx = segment.x2,yy = segment.y2;
351 pbuffer->isempty = False ;
352 pbuffer->rxmin = min(pbuffer->rxmin,xx) ;
353 pbuffer->rymin = min(pbuffer->rymin,yy) ;
354 pbuffer->rxmax = max(pbuffer->rxmax,xx) ;
355 pbuffer->rymax = max(pbuffer->rymax,yy) ;
362 plinedesc->rpoints[ldesc].x = xi ;
363 plinedesc->rpoints[ldesc].y = yi ;
366 pbuffer->isempty = False ;
367 pbuffer->rxmin = min(pbuffer->rxmin,xi) ;
368 pbuffer->rymin = min(pbuffer->rymin,yi) ;
369 pbuffer->rxmax = max(pbuffer->rxmax,xi) ;
370 pbuffer->rymax = max(pbuffer->rymax,yi) ;
375 plinedesc->npoint = ldesc ;
378 #ifdef TRACE_DRAW_LINE
379 if( Xw_get_trace() > 3 ) {
380 printf(" Xw_line_point(%lx,%f,%f)\n",(long ) pwindow,x,y) ;
383 return (XW_SUCCESS) ;
387 STATUS Xw_close_line (awindow):
388 XW_EXT_WINDOW *awindow
392 returns ERROR if Polyline is empty
393 returns SUCCESS if successful
398 XW_STATUS Xw_close_line(void* awindow)
400 XW_STATUS Xw_close_line(awindow)
402 #endif /*XW_PROTOTYPE*/
404 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow ;
406 if( BeginLine >= 0 ) {
407 int nline = plinelist->nline ;
408 int ldesc = plinedesc->npoint ;
409 int bindex = _BINDEX ;
410 plinelist->lines[nline] = ldesc - BeginLine ;
414 int index = pwindow->lineindex ;
415 Xw_draw_pixel_lines(pwindow,plinelist,pwindow->qgline[index].gc) ;
416 plinelist->nline = 0 ;
417 plinedesc->npoint = 0 ;
422 #ifdef TRACE_DRAW_LINE
423 if( Xw_get_trace() > 2 ) {
424 printf(" Xw_close_line(%lx)\n",(long ) pwindow) ;
427 return (XW_SUCCESS) ;
431 XW_EXT_LINE* Xw_add_polyline_structure(XW_EXT_BUFFER* pbuflist )
433 XW_EXT_LINE* Xw_add_polyline_structure(pbuflist )
434 XW_EXT_BUFFER *pbuflist ;
435 #endif /*XW_PROTOTYPE*/
437 Create and Insert at end one Extended polyline structure in the
440 returns Extended polyline address if successful
441 or NULL if Bad Allocation
446 pline = (XW_EXT_LINE*) Xw_malloc(sizeof(XW_EXT_LINE)) ;
448 pline->link = pbuflist->plinelist ;
449 pline->isupdated = False ;
451 pbuflist->plinelist = pline ;
453 /*ERROR*EXT_LINE allocation failed*/
454 Xw_set_error(30,"Xw_add_polyline_structure",NULL) ;
461 XW_STATUS Xw_del_polyline_structure(XW_EXT_BUFFER* pbuflist)
463 XW_STATUS Xw_del_polyline_structure(pbuflist)
464 XW_EXT_BUFFER *pbuflist ;
465 #endif /*XW_PROTOTYPE*/
467 Remove ALL Extended polyline structure in the
473 XW_EXT_LINE *pline,*qline ;
475 for( pline = pbuflist->plinelist ; pline ; pline = qline ) {
476 qline = (XW_EXT_LINE*)pline->link ;
479 pbuflist->plinelist = NULL ;
481 return (XW_SUCCESS) ;
485 XW_EXT_POINT* Xw_add_line_desc_structure(XW_EXT_BUFFER* pbuflist )
487 XW_EXT_POINT* Xw_add_line_desc_structure(pbuflist )
488 XW_EXT_BUFFER *pbuflist ;
489 #endif /*XW_PROTOTYPE*/
491 Create and Insert at end one Extended line_desc structure in the
494 returns Extended line_desc address if successful
495 or NULL if Bad Allocation
498 XW_EXT_POINT *pdesc ;
500 pdesc = (XW_EXT_POINT*) Xw_malloc(sizeof(XW_EXT_POINT)) ;
502 pdesc->link = pbuflist->plinedesc ;
504 pbuflist->plinedesc = pdesc ;
506 /*ERROR*EXT_POINT allocation failed*/
507 Xw_set_error(117,"Xw_add_line_desc_structure",NULL) ;
514 XW_STATUS Xw_del_line_desc_structure(XW_EXT_BUFFER* pbuflist)
516 XW_STATUS Xw_del_line_desc_structure(pbuflist)
517 XW_EXT_BUFFER *pbuflist ;
518 #endif /*XW_PROTOTYPE*/
520 Remove ALL Extended line_desc structure in the
526 XW_EXT_POINT *pdesc,*qdesc ;
528 for( pdesc = pbuflist->plinedesc ; pdesc ; pdesc = qdesc ) {
529 qdesc = (XW_EXT_POINT*)pdesc->link ;
532 pbuflist->plinedesc = NULL ;
534 return (XW_SUCCESS) ;