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 | #define BUC0056 /*GG_300496 |
b311480e |
20 | Protection contre zoom trop grand*/ |
7fd59977 |
21 | |
22 | #include <Xw_Extension.h> |
23 | |
24 | /* ifdef then trace on */ |
25 | #ifdef TRACE |
26 | #define TRACE_DRAW_POINT |
27 | #endif |
28 | |
29 | /* |
30 | STATUS Xw_draw_point (awindow,x,y): |
31 | XW_EXT_WINDOW *awindow |
32 | float x,y Point position in user space |
33 | |
34 | |
35 | Display point in current QG set by set_marker_attrib . |
36 | Note that points can be buffered depending of the DisplayMode context |
37 | and Flush at Xw_flush time . |
38 | |
39 | returns SUCCESS always |
40 | |
41 | */ |
42 | |
43 | #ifdef BUC0056 |
44 | #define MAXCOORD 32767 |
45 | #define MINCOORD -32768 |
46 | #endif |
47 | |
48 | static int BeginPoints = False ; |
49 | static XW_EXT_POINT *ppntlist = NULL ; |
50 | |
51 | #ifdef XW_PROTOTYPE |
52 | XW_STATUS Xw_draw_point (void* awindow,float x,float y) |
53 | #else |
54 | XW_STATUS Xw_draw_point (awindow,x,y) |
55 | void *awindow; |
56 | float x,y ; |
57 | #endif /*XW_PROTOTYPE*/ |
58 | { |
59 | XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow; |
60 | XW_EXT_BUFFER *pbuffer ; |
61 | int npnt,bindex,ix,iy ; |
62 | |
63 | if( !Xw_isdefine_window(pwindow) ) { |
64 | /*ERROR*Bad EXT_WINDOW Address*/ |
65 | Xw_set_error(24,"Xw_draw_point",pwindow) ; |
66 | return (XW_ERROR) ; |
67 | } |
68 | |
69 | bindex = _BINDEX ; |
70 | pbuffer = &_BUFFER(bindex) ; |
71 | for( ppntlist = pbuffer->ppntlist ; ppntlist ; |
72 | ppntlist = (XW_EXT_POINT*) ppntlist->link ) { |
73 | if( ppntlist->npoint < MAXPOINTS ) break ; |
74 | } |
75 | |
76 | if( !ppntlist ) { |
77 | ppntlist = Xw_add_point_structure(pbuffer) ; |
78 | } |
79 | |
80 | if( !ppntlist ) return XW_ERROR ; |
81 | |
82 | //OCC186 |
83 | ix = PXPOINT(x, pwindow->xratio) ; |
84 | iy = PYPOINT(y, pwindow->attributes.height, pwindow->yratio) ; |
85 | //OCC186 |
86 | |
87 | #ifdef BUC0056 |
88 | if( ix < MINCOORD || ix > MAXCOORD ) return XW_SUCCESS; |
89 | if( iy < MINCOORD || iy > MAXCOORD ) return XW_SUCCESS; |
90 | #endif |
91 | npnt = ppntlist->npoint ; |
92 | ppntlist->rpoints[npnt].x = ix ; |
93 | ppntlist->rpoints[npnt].y = iy ; |
94 | ppntlist->npoint++ ; |
95 | |
96 | if( bindex > 0 ) { |
97 | pbuffer->isempty = False ; |
98 | pbuffer->rxmin = min(pbuffer->rxmin,ix) ; |
99 | pbuffer->rymin = min(pbuffer->rymin,iy) ; |
100 | pbuffer->rxmax = max(pbuffer->rxmax,ix) ; |
101 | pbuffer->rymax = max(pbuffer->rymax,iy) ; |
102 | } else if( !BeginPoints ) { |
103 | int index = pwindow->markindex ; |
104 | Xw_draw_pixel_points(pwindow,ppntlist,pwindow->qgmark[index].gc) ; |
105 | ppntlist->npoint = 0 ; |
106 | } |
107 | |
108 | #ifdef TRACE_DRAW_POINT |
109 | if( Xw_get_trace() > 2 ) { |
110 | printf(" Xw_draw_point(%lx,%f,%f)\n",(long ) pwindow,x,y) ; |
111 | } |
112 | #endif |
113 | |
114 | return (XW_SUCCESS); |
115 | } |
116 | |
117 | /* |
118 | STATUS Xw_begin_points (awindow,npoint): |
119 | XW_EXT_WINDOW *awindow |
120 | int npoint Not used |
121 | |
122 | |
123 | Begin a set of points which must be filled by Xw_draw_point and |
124 | closed by Xw_close_points |
125 | |
126 | returns ERROR if bad extended window address |
127 | returns SUCCESS if successful |
128 | |
129 | */ |
130 | |
131 | #ifdef XW_PROTOTYPE |
132 | XW_STATUS Xw_begin_points(void* awindow,int npoint) |
133 | #else |
134 | XW_STATUS Xw_begin_points(awindow,npoint) |
135 | void *awindow ; |
136 | int npoint ; |
137 | #endif /*XW_PROTOTYPE*/ |
138 | { |
139 | XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow ; |
140 | |
141 | if( !Xw_isdefine_window(pwindow) ) { |
142 | /*ERROR*Bad EXT_WINDOW Address*/ |
143 | Xw_set_error(24,"Xw_begin_points",pwindow) ; |
144 | return (XW_ERROR) ; |
145 | } |
146 | |
147 | if( BeginPoints ) Xw_close_points(pwindow); |
148 | |
149 | BeginPoints = True; |
150 | |
151 | #ifdef TRACE_DRAW_POINT |
152 | if( Xw_get_trace() > 2 ) { |
153 | printf(" Xw_begin_points(%lx,%d)\n",(long ) pwindow,npoint) ; |
154 | } |
155 | #endif |
156 | return (XW_SUCCESS) ; |
157 | } |
158 | |
159 | /* |
160 | STATUS Xw_close_points (awindow): |
161 | XW_EXT_WINDOW *awindow |
162 | |
163 | Close the set of points |
164 | |
165 | returns ERROR if bad extended window address |
166 | returns SUCCESS successful |
167 | |
168 | */ |
169 | |
170 | #ifdef XW_PROTOTYPE |
171 | XW_STATUS Xw_close_points(void* awindow) |
172 | #else |
173 | XW_STATUS Xw_close_points(awindow) |
174 | void *awindow ; |
175 | #endif /*XW_PROTOTYPE*/ |
176 | { |
177 | XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow ; |
178 | XW_EXT_BUFFER *pbuffer ; |
179 | int bindex ; |
180 | |
181 | bindex = _BINDEX ; |
182 | pbuffer = &_BUFFER(bindex) ; |
183 | if( BeginPoints && !bindex ) { |
184 | int index = pwindow->lineindex ; |
185 | for( ppntlist = pbuffer->ppntlist ; ppntlist ; |
186 | ppntlist = (XW_EXT_POINT*) ppntlist->link ) { |
187 | if( ppntlist->npoint > 0 ) { |
188 | Xw_draw_pixel_points(pwindow,ppntlist,pwindow->qgmark[index].gc) ; |
189 | ppntlist->npoint = 0 ; |
190 | } else break ; |
191 | } |
192 | } |
193 | |
194 | BeginPoints = False; |
195 | |
196 | #ifdef TRACE_DRAW_POINT |
197 | if( Xw_get_trace() > 2 ) { |
198 | printf(" Xw_close_points(%lx)\n",(long ) pwindow) ; |
199 | } |
200 | #endif |
201 | return (XW_SUCCESS) ; |
202 | } |
203 | |
204 | #ifdef XW_PROTOTYPE |
205 | void Xw_draw_pixel_points(XW_EXT_WINDOW *pwindow,XW_EXT_POINT* ppntlist,GC gc) |
206 | #else |
207 | void Xw_draw_pixel_points(pwindow,ppntlist,gc) |
208 | XW_EXT_WINDOW *pwindow ; |
209 | XW_EXT_POINT *ppntlist ; |
210 | GC gc ; |
211 | #endif /*XW_PROTOTYPE*/ |
212 | { |
213 | |
214 | if( ppntlist->isupdated ) { |
215 | XDrawPoints(_DISPLAY,_DRAWABLE,gc,ppntlist->upoints, |
216 | ppntlist->npoint,CoordModeOrigin) ; |
217 | } else { |
218 | XDrawPoints(_DISPLAY,_DRAWABLE,gc,ppntlist->rpoints, |
219 | ppntlist->npoint,CoordModeOrigin) ; |
220 | } |
221 | } |
222 | |
223 | #ifdef XW_PROTOTYPE |
224 | XW_STATUS Xw_del_point_structure(XW_EXT_BUFFER* pbuflist) |
225 | #else |
226 | XW_STATUS Xw_del_point_structure(pbuflist) |
227 | XW_EXT_BUFFER *pbuflist ; |
228 | #endif /*XW_PROTOTYPE*/ |
229 | /* |
230 | Remove ALL Extended point structure in the |
231 | point List |
232 | |
233 | SUCCESS always |
234 | */ |
235 | { |
236 | XW_EXT_POINT *ppoint,*qpoint ; |
237 | |
238 | for( ppoint = pbuflist->ppntlist ; ppoint ; ppoint = qpoint ) { |
239 | qpoint = (XW_EXT_POINT*)ppoint->link ; |
240 | Xw_free(ppoint) ; |
241 | } |
242 | pbuflist->ppntlist = NULL ; |
243 | |
244 | return (XW_SUCCESS) ; |
245 | } |
246 | |
247 | #ifdef XW_PROTOTYPE |
248 | XW_EXT_POINT* Xw_add_point_structure(XW_EXT_BUFFER* pbuflist ) |
249 | #else |
250 | XW_EXT_POINT* Xw_add_point_structure(pbuflist ) |
251 | XW_EXT_BUFFER *pbuflist ; |
252 | #endif /*XW_PROTOTYPE*/ |
253 | /* |
254 | Create and Insert at end one Extended point structure in the |
255 | point List |
256 | |
257 | returns Extended point address if successful |
258 | or NULL if Bad Allocation |
259 | */ |
260 | { |
261 | XW_EXT_POINT *ppoint ; |
262 | |
263 | ppoint = (XW_EXT_POINT*) Xw_malloc(sizeof(XW_EXT_POINT)) ; |
264 | if( ppoint ) { |
265 | ppoint->link = pbuflist->ppntlist ; |
266 | ppoint->isupdated = False ; |
267 | ppoint->npoint = 0 ; |
268 | pbuflist->ppntlist = ppoint ; |
269 | } else { |
270 | /*ERROR*EXT_POINT Allocation failed*/ |
271 | Xw_set_error(117,"Xw_add_point_structure",NULL) ; |
272 | } |
273 | |
274 | return (ppoint) ; |
275 | } |