0023533: Unitialized variables used, IntTools_TopolTool.cxx
[occt.git] / src / Xw / Xw_draw_polyarc.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 #include <Xw_Extension.h>
19
20 /* ifdef then trace on */
21 #ifdef TRACE
22 #define TRACE_DRAW_POLYARC
23 #endif
24
25 /*
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
33
34         Display arc in current QG set by set_poly_attrib .
35         or retain arcs in buffer.
36
37         returns ERROR if bad parameter
38         returns SUCCESS if successfull
39
40 */
41
42 #define MAXCOORD 32767
43 #define MINCOORD -32768
44
45 static int BeginArcs = False;
46 static XW_EXT_ARC *parclist ;
47
48 #ifdef XW_PROTOTYPE
49 XW_STATUS Xw_draw_polyarc (void* awindow,float xc,float yc,
50                         float xradius,float yradius,float start,float angle)
51 #else
52 XW_STATUS Xw_draw_polyarc (awindow,xc,yc,xradius,yradius,start,angle)
53 void *awindow;
54 float xc,yc,xradius,yradius,start,angle ;
55 #endif /*XW_PROTOTYPE*/
56 {
57 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*) awindow ;
58 XW_EXT_BUFFER *pbuffer ;
59 int narc,bindex,angle1,angle2,x,y,width,height ;
60
61         if( !Xw_isdefine_window(pwindow) ) {
62             /*ERROR*Bad EXT_WINDOW Address*/
63             Xw_set_error(24,"Xw_draw_polyarc",pwindow) ;
64             return (XW_ERROR) ;
65         }
66
67         if( xradius <= 0. ) {
68             /*ERROR*Bad arc radius*/
69             Xw_set_error(115,"Xw_draw_polyarc",&xradius) ;
70             return (XW_ERROR) ;
71         }
72
73         if( yradius <= 0. ) {
74             /*ERROR*Bad arc radius*/
75             Xw_set_error(115,"Xw_draw_polyarc",&yradius) ;
76             return (XW_ERROR) ;
77         }
78
79         bindex = _BINDEX ;
80         pbuffer = &_BUFFER(bindex) ;
81         for( parclist = pbuffer->pparclist ; parclist ;
82                            parclist = (XW_EXT_ARC*) parclist->link ) {
83             if( parclist->narc < MAXARCS ) break ;
84         }
85
86         if( !parclist ) {
87             parclist = Xw_add_polyarc_structure(pbuffer) ;
88         }
89
90         if( !parclist ) return XW_ERROR ;
91
92         angle1 = (int )( start*64./DRAD );
93         if( angle1 > 0 ) {
94             while( angle1 > MAXANGLE ) angle1 -= MAXANGLE ;
95         } else if( angle1 < 0 ) {
96             while( angle1 < -MAXANGLE ) angle1 += MAXANGLE ;
97         }
98         angle2 = (int )( angle*64./DRAD );
99         if( angle2 > 0 ) {
100             while( angle2 > MAXANGLE ) angle2 -= MAXANGLE ;
101         } else if( angle2 < 0 ) {
102             while( angle2 < -MAXANGLE ) angle2 += MAXANGLE ;
103         }
104 //OCC186
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) ; 
109 //OCC186
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 ;
120             parclist->narc++ ;
121             if( bindex > 0 ) {
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);
136               parclist->narc = 0 ;
137             }
138         } else {
139             /*ERROR*Too big arc radius*/
140             Xw_set_error(116,"Xw_draw_polyarc",0) ;
141             return (XW_ERROR) ;
142         }
143
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);
148 }
149 #endif
150
151         return (XW_SUCCESS);
152 }
153
154 /*
155    STATUS Xw_begin_polyarcs (awindow,narc):
156    XW_EXT_WINDOW *awindow
157    int narc           Not used
158
159
160         Begin a set of arcs which must be filled by Xw_draw_polyarc and
161                                      closed by Xw_close_polyarcs
162
163         returns ERROR if bad extended window address
164         returns SUCCESS if successful
165
166 */
167  
168 #ifdef XW_PROTOTYPE
169 XW_STATUS Xw_begin_polyarcs(void* awindow,int narc)
170 #else
171 XW_STATUS Xw_begin_polyarcs(awindow,narc)
172 void *awindow ;
173 int narc ;
174 #endif /*XW_PROTOTYPE*/
175 {
176 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow ;
177  
178         if( !Xw_isdefine_window(pwindow) ) {
179             /*ERROR*Bad EXT_WINDOW Address*/
180             Xw_set_error(24,"Xw_begin_polyarcs",pwindow) ;
181             return (XW_ERROR) ;
182         }    
183  
184         if( BeginArcs ) Xw_close_polyarcs(pwindow);
185         
186         BeginArcs = True;
187  
188 #ifdef  TRACE_DRAW_POLYARC
189 if( Xw_get_trace() > 2 ) {
190     printf(" Xw_begin_polyarcs(%lx,%d)\n",(long ) pwindow,narc) ;
191 }
192 #endif
193         return (XW_SUCCESS) ;
194 }
195  
196 /*
197    STATUS Xw_close_polyarcs (awindow):
198    XW_EXT_WINDOW *awindow
199  
200         Close the set of arcs
201  
202         returns ERROR if bad extended window address
203         returns SUCCESS successful
204  
205 */
206  
207 #ifdef XW_PROTOTYPE
208 XW_STATUS Xw_close_polyarcs(void* awindow)
209 #else
210 XW_STATUS Xw_close_polyarcs(awindow)
211 void *awindow ;
212 #endif /*XW_PROTOTYPE*/
213 {
214 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow ;
215 int bindex ;
216  
217         if( !Xw_isdefine_window(pwindow) ) {
218             /*ERROR*Bad EXT_WINDOW Address*/
219             Xw_set_error(24,"Xw_close_polyarcs",pwindow) ;
220             return (XW_ERROR) ;
221         }    
222
223         bindex = _BINDEX ; 
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);
234               parclist->narc = 0 ;
235             } else break ;
236           }
237         }    
238  
239         BeginArcs = False;
240  
241 #ifdef  TRACE_DRAW_POLYARC
242 if( Xw_get_trace() > 2 ) {
243     printf(" Xw_close_polyarcs(%lx)\n",(long ) pwindow) ;
244 }
245 #endif
246         return (XW_SUCCESS) ;
247 }
248
249
250 #ifdef XW_PROTOTYPE
251 void Xw_draw_pixel_polyarcs (XW_EXT_WINDOW* pwindow,XW_EXT_ARC* parclist,
252                                                         GC gcpoly,GC gcline)
253 #else
254 void Xw_draw_pixel_polyarcs (pwindow,parclist,gcpoly,gcline)
255 XW_EXT_WINDOW *pwindow;
256 XW_EXT_ARC *parclist;
257 GC gcpoly,gcline;
258 #endif /*XW_PROTOTYPE*/
259 {
260
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) ;
265      }
266    } else {
267      XFillArcs(_DISPLAY,_DRAWABLE,gcpoly,parclist->rarcs,parclist->narc) ;
268      if( gcline && (gcpoly != gcline) ) {
269        XDrawArcs(_DISPLAY,_DRAWABLE,gcline,parclist->rarcs,parclist->narc) ;
270      }
271    }
272 }
273
274 #ifdef XW_PROTOTYPE
275 XW_EXT_ARC* Xw_add_polyarc_structure(XW_EXT_BUFFER* pbuflist )
276 #else
277 XW_EXT_ARC* Xw_add_polyarc_structure(pbuflist )
278 XW_EXT_BUFFER *pbuflist ;
279 #endif /*XW_PROTOTYPE*/
280 /*
281         Create and Insert at end one Extended arc structure in the
282         arc List
283
284         returns Extended arc address if successful
285                 or NULL if Bad Allocation
286 */
287 {
288 XW_EXT_ARC *parc ;
289  
290         parc = (XW_EXT_ARC*) Xw_malloc(sizeof(XW_EXT_ARC)) ;
291         if( parc ) {
292             parc->link = pbuflist->pparclist ;
293             parc->isupdated = 0 ;
294             parc->narc = 0 ;
295             pbuflist->pparclist = parc ;
296         } else {
297             /*ERROR*EXT_ARC Allocation failed*/
298             Xw_set_error(35,"Xw_add_polyarc_structure",NULL) ;
299         }
300
301         return (parc) ;
302 }
303
304 #ifdef XW_PROTOTYPE
305 XW_STATUS Xw_del_polyarc_structure(XW_EXT_BUFFER* pbuflist)
306 #else
307 XW_STATUS Xw_del_polyarc_structure(pbuflist)
308 XW_EXT_BUFFER *pbuflist ;
309 #endif /*XW_PROTOTYPE*/
310 /*
311         Remove ALL Extended arc structure in the
312         arc List
313
314         SUCCESS always
315 */
316 {
317 XW_EXT_ARC *parc,*qarc ;
318
319         for( parc = pbuflist->pparclist ; parc ; parc = qarc ) {
320             qarc = (XW_EXT_ARC*)parc->link ;
321             Xw_free(parc) ;
322         }
323         pbuflist->pparclist = NULL ;
324         
325         return (XW_SUCCESS) ;
326 }