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 <Standard_Integer.hxx> |
20 | |
21 | #include <Xw_Extension.h> |
22 | |
b311480e |
23 | /* ifdef then trace on */ |
7fd59977 |
24 | #ifdef TRACE |
25 | #define TRACE_DRAW_ARC |
26 | #endif |
27 | |
28 | /* |
29 | STATUS Xw_draw_arc (awindow,xc,yc,xradius,yradius,start,angle): |
30 | XW_EXT_WINDOW *awindow |
31 | float xc,yc Arc center defined in User Space |
32 | float xradius Horizontal arc radius defined in User Space |
33 | float xradius Vertical Arc radius defined in User Space |
34 | float start Start angle defined in RADIAN |
35 | float angle Arc angle defined in RADIAN |
36 | |
37 | Display arc in current QG set by set_line_attrib . |
38 | or retain arc in buffer. |
39 | |
40 | return ERROR if bad parameter |
41 | returns SUCCESS if successful |
42 | |
43 | */ |
44 | |
45 | #define MAXCOORD 32767 |
46 | #define MINCOORD -32768 |
47 | |
48 | static int BeginArcs = False; |
49 | static XW_EXT_ARC *parclist ; |
50 | |
51 | #ifdef XW_PROTOTYPE |
52 | XW_STATUS Xw_draw_arc (void* awindow,float xc,float yc, |
53 | float xradius,float yradius,float start,float angle) |
54 | #else |
55 | XW_STATUS Xw_draw_arc (awindow,xc,yc,xradius,yradius,start,angle) |
56 | void *awindow; |
57 | float xc,yc,xradius,yradius,start,angle ; |
58 | #endif /*XW_PROTOTYPE*/ |
59 | { |
60 | XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*) awindow ; |
61 | XW_EXT_BUFFER *pbuffer ; |
62 | int narc,bindex,angle1,angle2,x,y,width,height ; |
63 | |
64 | if( !Xw_isdefine_window(pwindow) ) { |
65 | /*ERROR*Bad EXT_WINDOW Address*/ |
66 | Xw_set_error(24,"Xw_draw_arc",pwindow) ; |
67 | return (XW_ERROR) ; |
68 | } |
69 | |
70 | if( xradius <= 0. ) { |
71 | /*ERROR*Bad arc radius*/ |
72 | Xw_set_error(115,"Xw_draw_arc",&xradius) ; |
73 | return (XW_ERROR) ; |
74 | } |
75 | |
76 | if( yradius <= 0. ) { |
77 | /*ERROR*Bad arc radius*/ |
78 | Xw_set_error(115,"Xw_draw_arc",&yradius) ; |
79 | return (XW_ERROR) ; |
80 | } |
81 | |
82 | bindex = _BINDEX ; |
83 | pbuffer = &_BUFFER(bindex) ; |
84 | for( parclist = pbuffer->plarclist ; parclist ; |
85 | parclist = (XW_EXT_ARC*) parclist->link ) { |
86 | if( parclist->narc < MAXARCS ) break ; |
87 | } |
88 | |
89 | if( !parclist ) { |
90 | parclist = Xw_add_arc_structure(pbuffer) ; |
91 | } |
92 | |
93 | if( !parclist ) return XW_ERROR ; |
94 | |
95 | angle1 = (Standard_Integer )( start*64./DRAD ); |
96 | if( angle1 > 0 ) { |
97 | while( angle1 > MAXANGLE ) angle1 -= MAXANGLE ; |
98 | } else if( angle1 < 0 ) { |
99 | while( angle1 < -MAXANGLE ) angle1 += MAXANGLE ; |
100 | } |
101 | angle2 = (Standard_Integer ) ( angle*64./DRAD ); |
102 | if( angle2 > 0 ) { |
103 | while( angle2 > MAXANGLE ) angle2 -= MAXANGLE ; |
104 | } else if( angle2 < 0 ) { |
105 | while( angle2 < -MAXANGLE ) angle2 += MAXANGLE ; |
106 | } |
107 | //OCC186 |
108 | width = 2*PVALUE(xradius, pwindow->xratio, pwindow->yratio); |
109 | height = 2*PVALUE(yradius, pwindow->xratio, pwindow->yratio); |
110 | x = PXPOINT(xc, pwindow->xratio); |
111 | y = PYPOINT(yc, pwindow->attributes.height, pwindow->yratio); |
112 | //OCC186 |
113 | x = max(min(x,MAXCOORD),MINCOORD); |
114 | y = max(min(y,MAXCOORD),MINCOORD); |
115 | if( width < 0xFFFF && height < 0xFFFF ) { |
116 | narc = parclist->narc ; |
117 | parclist->rarcs[narc].width = width ; |
118 | parclist->rarcs[narc].height = height ; |
119 | parclist->rarcs[narc].x = x - width/2 ; |
120 | parclist->rarcs[narc].y = y - height/2 ; |
121 | parclist->rarcs[narc].angle1 = angle1 ; |
122 | parclist->rarcs[narc].angle2 = angle2 ; |
123 | parclist->narc++ ; |
124 | if( bindex > 0 ) { |
125 | pbuffer->isempty = False ; |
126 | width = (width+1)/2 ; |
127 | height = (height+1)/2 ; |
128 | pbuffer->rxmin = min(pbuffer->rxmin,x-width) ; |
129 | pbuffer->rymin = min(pbuffer->rymin,y-height) ; |
130 | pbuffer->rxmax = max(pbuffer->rxmax,x+width) ; |
131 | pbuffer->rymax = max(pbuffer->rymax,y+height) ; |
132 | } else if( !BeginArcs ) { |
133 | int index = pwindow->lineindex ; |
134 | Xw_draw_pixel_arcs(pwindow,parclist,pwindow->qgline[index].gc) ; |
135 | parclist->narc = 0 ; |
136 | } |
137 | } else { |
138 | /*ERROR*Too big arc radius*/ |
139 | Xw_set_error(116,"Xw_draw_arc",0) ; |
140 | return (XW_ERROR) ; |
141 | } |
142 | |
143 | #ifdef TRACE_DRAW_ARC |
144 | if( Xw_get_trace() > 2 ) { |
145 | printf(" Xw_draw_arc(%lx,%f,%f,%f,%f,%f,%f\n", |
146 | (long ) pwindow,xc,yc,xradius,yradius,start,angle); |
147 | } |
148 | #endif |
149 | |
150 | return (XW_SUCCESS); |
151 | } |
152 | |
153 | /* |
154 | STATUS Xw_begin_arcs (awindow,narc): |
155 | XW_EXT_WINDOW *awindow |
156 | int narc Not used |
157 | |
158 | |
159 | Begin a set of arcs which must be filled by Xw_draw_arc and |
160 | closed by Xw_close_arcs |
161 | |
162 | returns ERROR if bad extended window address |
163 | returns SUCCESS if successful |
164 | |
165 | */ |
166 | |
167 | #ifdef XW_PROTOTYPE |
168 | XW_STATUS Xw_begin_arcs(void* awindow,int narc) |
169 | #else |
170 | XW_STATUS Xw_begin_arcs(awindow,narc) |
171 | void *awindow ; |
172 | int narc ; |
173 | #endif /*XW_PROTOTYPE*/ |
174 | { |
175 | XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow ; |
176 | |
177 | if( !Xw_isdefine_window(pwindow) ) { |
178 | /*ERROR*Bad EXT_WINDOW Address*/ |
179 | Xw_set_error(24,"Xw_begin_arcs",pwindow) ; |
180 | return (XW_ERROR) ; |
181 | } |
182 | |
183 | if( BeginArcs ) Xw_close_arcs(pwindow); |
184 | |
185 | BeginArcs = True; |
186 | |
187 | #ifdef TRACE_DRAW_ARC |
188 | if( Xw_get_trace() > 2 ) { |
189 | printf(" Xw_begin_arcs(%lx,%d)\n",(long ) pwindow,narc) ; |
190 | } |
191 | #endif |
192 | return (XW_SUCCESS) ; |
193 | } |
194 | |
195 | /* |
196 | STATUS Xw_close_arcs (awindow): |
197 | XW_EXT_WINDOW *awindow |
198 | |
199 | Close the set of arcs |
200 | |
201 | returns ERROR if bad extended window address |
202 | returns SUCCESS successful |
203 | |
204 | */ |
205 | |
206 | #ifdef XW_PROTOTYPE |
207 | XW_STATUS Xw_close_arcs(void* awindow) |
208 | #else |
209 | XW_STATUS Xw_close_arcs(awindow) |
210 | void *awindow ; |
211 | #endif /*XW_PROTOTYPE*/ |
212 | { |
213 | XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow ; |
214 | int bindex ; |
215 | |
216 | if( !Xw_isdefine_window(pwindow) ) { |
217 | /*ERROR*Bad EXT_WINDOW Address*/ |
218 | Xw_set_error(24,"Xw_close_arcs",pwindow) ; |
219 | return (XW_ERROR) ; |
220 | } |
221 | |
222 | bindex = _BINDEX ; |
223 | if( BeginArcs && !bindex ) { |
224 | int index = pwindow->lineindex ; |
225 | for( parclist = _BUFFER(bindex).plarclist ; parclist ; |
226 | parclist = (XW_EXT_ARC*) parclist->link ) { |
227 | if( parclist->narc > 0 ) { |
228 | Xw_draw_pixel_arcs(pwindow,parclist,pwindow->qgline[index].gc) ; |
229 | parclist->narc = 0 ; |
230 | } else break ; |
231 | } |
232 | } |
233 | |
234 | BeginArcs = False; |
235 | |
236 | #ifdef TRACE_DRAW_ARC |
237 | if( Xw_get_trace() > 2 ) { |
238 | printf(" Xw_close_arcs(%lx)\n",(long ) pwindow) ; |
239 | } |
240 | #endif |
241 | return (XW_SUCCESS) ; |
242 | } |
243 | |
244 | |
245 | #ifdef XW_PROTOTYPE |
246 | void Xw_draw_pixel_arcs (XW_EXT_WINDOW* pwindow,XW_EXT_ARC* parclist,GC gc) |
247 | #else |
248 | void Xw_draw_pixel_arcs (pwindow,parclist,gc) |
249 | XW_EXT_WINDOW *pwindow; |
250 | XW_EXT_ARC *parclist; |
251 | GC gc; |
252 | #endif /*XW_PROTOTYPE*/ |
253 | { |
254 | if( parclist->isupdated ) { |
255 | XDrawArcs(_DISPLAY,_DRAWABLE,gc,parclist->uarcs,parclist->narc) ; |
256 | } else { |
257 | XDrawArcs(_DISPLAY,_DRAWABLE,gc,parclist->rarcs,parclist->narc) ; |
258 | } |
259 | |
260 | } |
261 | |
262 | #ifdef XW_PROTOTYPE |
263 | XW_EXT_ARC* Xw_add_arc_structure(XW_EXT_BUFFER* pbuflist ) |
264 | #else |
265 | XW_EXT_ARC* Xw_add_arc_structure(pbuflist ) |
266 | XW_EXT_BUFFER *pbuflist ; |
267 | #endif /*XW_PROTOTYPE*/ |
268 | /* |
269 | Create and Insert at end one Extended arc structure in the |
270 | arc List |
271 | |
272 | returns Extended arc address if successful |
273 | or NULL if Bad Allocation |
274 | */ |
275 | { |
276 | XW_EXT_ARC *parc ; |
277 | |
278 | parc = (XW_EXT_ARC*) Xw_malloc(sizeof(XW_EXT_ARC)) ; |
279 | if( parc ) { |
280 | parc->link = pbuflist->plarclist ; |
281 | parc->isupdated = False ; |
282 | parc->narc = 0 ; |
283 | pbuflist->plarclist = parc ; |
284 | } else { |
285 | /*ERROR*EXT_ARC Allocation failed*/ |
286 | Xw_set_error(35,"Xw_add_arc_structure",NULL) ; |
287 | } |
288 | |
289 | return (parc) ; |
290 | } |
291 | |
292 | #ifdef XW_PROTOTYPE |
293 | XW_STATUS Xw_del_arc_structure(XW_EXT_BUFFER* pbuflist) |
294 | #else |
295 | XW_STATUS Xw_del_arc_structure(pbuflist) |
296 | XW_EXT_BUFFER *pbuflist ; |
297 | #endif /*XW_PROTOTYPE*/ |
298 | /* |
299 | Remove ALL Extended arc structure in the |
300 | arc List |
301 | |
302 | SUCCESS always |
303 | */ |
304 | { |
305 | XW_EXT_ARC *parc,*qarc ; |
306 | |
307 | for( parc = pbuflist->plarclist ; parc ; parc = qarc ) { |
308 | qarc = (XW_EXT_ARC*)parc->link ; |
309 | Xw_free(parc) ; |
310 | } |
311 | pbuflist->plarclist = NULL ; |
312 | |
313 | return (XW_SUCCESS) ; |
314 | } |