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 #include <Xw_Extension.h>
20 /* ifdef then trace on */
22 #define TRACE_DRAW_POLYARC
26 STATUS Xw_draw_polyarc (awindow,xc,yc,xradius,yradius,start,angle):
27 XW_EXT_WINDOW *awindow
28 float xc,yc Arc center defined in User Space
29 float xradius Horizontal arc radius defined in User Space
30 float xradius Vertical Arc radius defined in User Space
31 float start Start angle defined in RADIAN
32 float angle Arc angle defined in RADIAN
34 Display arc in current QG set by set_poly_attrib .
35 or retain arcs in buffer.
37 returns ERROR if bad parameter
38 returns SUCCESS if successfull
42 #define MAXCOORD 32767
43 #define MINCOORD -32768
45 static int BeginArcs = False;
46 static XW_EXT_ARC *parclist ;
49 XW_STATUS Xw_draw_polyarc (void* awindow,float xc,float yc,
50 float xradius,float yradius,float start,float angle)
52 XW_STATUS Xw_draw_polyarc (awindow,xc,yc,xradius,yradius,start,angle)
54 float xc,yc,xradius,yradius,start,angle ;
55 #endif /*XW_PROTOTYPE*/
57 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*) awindow ;
58 XW_EXT_BUFFER *pbuffer ;
59 int narc,bindex,angle1,angle2,x,y,width,height ;
61 if( !Xw_isdefine_window(pwindow) ) {
62 /*ERROR*Bad EXT_WINDOW Address*/
63 Xw_set_error(24,"Xw_draw_polyarc",pwindow) ;
68 /*ERROR*Bad arc radius*/
69 Xw_set_error(115,"Xw_draw_polyarc",&xradius) ;
74 /*ERROR*Bad arc radius*/
75 Xw_set_error(115,"Xw_draw_polyarc",&yradius) ;
80 pbuffer = &_BUFFER(bindex) ;
81 for( parclist = pbuffer->pparclist ; parclist ;
82 parclist = (XW_EXT_ARC*) parclist->link ) {
83 if( parclist->narc < MAXARCS ) break ;
87 parclist = Xw_add_polyarc_structure(pbuffer) ;
90 if( !parclist ) return XW_ERROR ;
92 angle1 = (int )( start*64./DRAD );
94 while( angle1 > MAXANGLE ) angle1 -= MAXANGLE ;
95 } else if( angle1 < 0 ) {
96 while( angle1 < -MAXANGLE ) angle1 += MAXANGLE ;
98 angle2 = (int )( angle*64./DRAD );
100 while( angle2 > MAXANGLE ) angle2 -= MAXANGLE ;
101 } else if( angle2 < 0 ) {
102 while( angle2 < -MAXANGLE ) angle2 += MAXANGLE ;
105 width = 2*PVALUE(xradius, pwindow->xratio, pwindow->yratio) ;
106 height = 2*PVALUE(yradius, pwindow->xratio, pwindow->yratio) ;
107 x = PXPOINT(xc, pwindow->xratio) ;
108 y = PYPOINT(yc, pwindow->attributes.height, pwindow->yratio) ;
110 x = max(min(x,MAXCOORD),MINCOORD);
111 y = max(min(y,MAXCOORD),MINCOORD);
112 if( width < 0xFFFF && height < 0xFFFF ) {
113 narc = parclist->narc ;
114 parclist->rarcs[narc].width = width ;
115 parclist->rarcs[narc].height = height ;
116 parclist->rarcs[narc].x = x - width/2 ;
117 parclist->rarcs[narc].y = y - height/2 ;
118 parclist->rarcs[narc].angle1 = angle1 ;
119 parclist->rarcs[narc].angle2 = angle2 ;
122 pbuffer->isempty = False ;
123 width = (width+1)/2 ;
124 height = (height+1)/2 ;
125 pbuffer->rxmin = min(pbuffer->rxmin,x-width) ;
126 pbuffer->rymin = min(pbuffer->rymin,y-height) ;
127 pbuffer->rxmax = max(pbuffer->rxmax,x+width) ;
128 pbuffer->rymax = max(pbuffer->rymax,y+height) ;
129 } else if( !BeginArcs ) {
130 int polyindex = pwindow->polyindex ;
131 int lineindex = pwindow->lineindex ;
132 GC gcpoly = pwindow->qgpoly[polyindex].gc ;
133 GC gcline = (QGTYPE(pwindow->qgpoly[polyindex].code)) ?
134 pwindow->qgline[lineindex].gc : NULL ;
135 Xw_draw_pixel_polyarcs(pwindow,parclist,gcpoly,gcline);
139 /*ERROR*Too big arc radius*/
140 Xw_set_error(116,"Xw_draw_polyarc",0) ;
144 #ifdef TRACE_DRAW_POLYARC
145 if( Xw_get_trace() > 2 ) {
146 printf(" Xw_draw_polyarc(%lx,%f,%f,%f,%f,%f,%f\n",
147 (long ) pwindow,xc,yc,xradius,yradius,start,angle);
155 STATUS Xw_begin_polyarcs (awindow,narc):
156 XW_EXT_WINDOW *awindow
160 Begin a set of arcs which must be filled by Xw_draw_polyarc and
161 closed by Xw_close_polyarcs
163 returns ERROR if bad extended window address
164 returns SUCCESS if successful
169 XW_STATUS Xw_begin_polyarcs(void* awindow,int narc)
171 XW_STATUS Xw_begin_polyarcs(awindow,narc)
174 #endif /*XW_PROTOTYPE*/
176 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow ;
178 if( !Xw_isdefine_window(pwindow) ) {
179 /*ERROR*Bad EXT_WINDOW Address*/
180 Xw_set_error(24,"Xw_begin_polyarcs",pwindow) ;
184 if( BeginArcs ) Xw_close_polyarcs(pwindow);
188 #ifdef TRACE_DRAW_POLYARC
189 if( Xw_get_trace() > 2 ) {
190 printf(" Xw_begin_polyarcs(%lx,%d)\n",(long ) pwindow,narc) ;
193 return (XW_SUCCESS) ;
197 STATUS Xw_close_polyarcs (awindow):
198 XW_EXT_WINDOW *awindow
200 Close the set of arcs
202 returns ERROR if bad extended window address
203 returns SUCCESS successful
208 XW_STATUS Xw_close_polyarcs(void* awindow)
210 XW_STATUS Xw_close_polyarcs(awindow)
212 #endif /*XW_PROTOTYPE*/
214 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow ;
217 if( !Xw_isdefine_window(pwindow) ) {
218 /*ERROR*Bad EXT_WINDOW Address*/
219 Xw_set_error(24,"Xw_close_polyarcs",pwindow) ;
224 if( BeginArcs && !bindex ) {
225 int polyindex = pwindow->polyindex ;
226 int lineindex = pwindow->lineindex ;
227 GC gcpoly = pwindow->qgpoly[polyindex].gc ;
228 GC gcline = (QGTYPE(pwindow->qgpoly[polyindex].code)) ?
229 pwindow->qgline[lineindex].gc : NULL ;
230 for( parclist = _BUFFER(bindex).pparclist ; parclist ;
231 parclist = (XW_EXT_ARC*) parclist->link ) {
232 if( parclist->narc > 0 ) {
233 Xw_draw_pixel_polyarcs(pwindow,parclist,gcpoly,gcline);
241 #ifdef TRACE_DRAW_POLYARC
242 if( Xw_get_trace() > 2 ) {
243 printf(" Xw_close_polyarcs(%lx)\n",(long ) pwindow) ;
246 return (XW_SUCCESS) ;
251 void Xw_draw_pixel_polyarcs (XW_EXT_WINDOW* pwindow,XW_EXT_ARC* parclist,
254 void Xw_draw_pixel_polyarcs (pwindow,parclist,gcpoly,gcline)
255 XW_EXT_WINDOW *pwindow;
256 XW_EXT_ARC *parclist;
258 #endif /*XW_PROTOTYPE*/
261 if( parclist->isupdated ) {
262 XFillArcs(_DISPLAY,_DRAWABLE,gcpoly,parclist->uarcs,parclist->narc) ;
263 if( gcline && (gcpoly != gcline) ) {
264 XDrawArcs(_DISPLAY,_DRAWABLE,gcline,parclist->uarcs,parclist->narc) ;
267 XFillArcs(_DISPLAY,_DRAWABLE,gcpoly,parclist->rarcs,parclist->narc) ;
268 if( gcline && (gcpoly != gcline) ) {
269 XDrawArcs(_DISPLAY,_DRAWABLE,gcline,parclist->rarcs,parclist->narc) ;
275 XW_EXT_ARC* Xw_add_polyarc_structure(XW_EXT_BUFFER* pbuflist )
277 XW_EXT_ARC* Xw_add_polyarc_structure(pbuflist )
278 XW_EXT_BUFFER *pbuflist ;
279 #endif /*XW_PROTOTYPE*/
281 Create and Insert at end one Extended arc structure in the
284 returns Extended arc address if successful
285 or NULL if Bad Allocation
290 parc = (XW_EXT_ARC*) Xw_malloc(sizeof(XW_EXT_ARC)) ;
292 parc->link = pbuflist->pparclist ;
293 parc->isupdated = 0 ;
295 pbuflist->pparclist = parc ;
297 /*ERROR*EXT_ARC Allocation failed*/
298 Xw_set_error(35,"Xw_add_polyarc_structure",NULL) ;
305 XW_STATUS Xw_del_polyarc_structure(XW_EXT_BUFFER* pbuflist)
307 XW_STATUS Xw_del_polyarc_structure(pbuflist)
308 XW_EXT_BUFFER *pbuflist ;
309 #endif /*XW_PROTOTYPE*/
311 Remove ALL Extended arc structure in the
317 XW_EXT_ARC *parc,*qarc ;
319 for( parc = pbuflist->pparclist ; parc ; parc = qarc ) {
320 qarc = (XW_EXT_ARC*)parc->link ;
323 pbuflist->pparclist = NULL ;
325 return (XW_SUCCESS) ;