0023830: BRepExtrema_DistShapeShape does not find intersection of face with edge
[occt.git] / src / Xw / Xw_set_soft_cursor.cxx
CommitLineData
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 <Xw_Extension.h>
20
b311480e 21/* ifdef then trace on */
7fd59977 22#ifdef TRACE
23#define TRACE_SET_SOFT_CURSOR
24#endif
25
26/*
27 XW_STATUS Xw_set_soft_cursor (awindow,type,button)
28 XW_EXT_WINDOW *awindow
29 XW_CURSORTYPE type
30 int button Mouse Button number (1 to 3)
31
32 Associate the soft cursor to the window and a mouse button
33 Soft cursor is activated when Mouse Button is press
34 drawn when mouse move with button press
35 and Unactivated when Mouse Button is Release
36
37 Returns XW_ERROR if button is out of range
38 Returns XW_SUCCESS if successful
39
40*/
41
42static int Start = False ;
43static XPoint points[100] ;
44
45#ifdef XW_PROTOTYPE
46static XW_STATUS Xw_rubberline_cursor(XW_EVENT *event) ;
47static XW_STATUS Xw_rubberband_cursor(XW_EVENT *event) ;
48static XW_STATUS Xw_userdefined_cursor(XW_EVENT *event) ;
49static void DrawLines(XW_EXT_WINDOW *pwindow,XPoint *points,int npoint) ;
50XW_STATUS Xw_set_soft_cursor (void *awindow,XW_CURSORTYPE type,int button)
51#else
52static XW_STATUS Xw_rubberline_cursor() ;
53static XW_STATUS Xw_rubberband_cursor() ;
54static XW_STATUS Xw_userdefined_cursor() ;
55static void DrawLines() ;
56XW_STATUS Xw_set_soft_cursor (awindow,type,button)
57void *awindow ;
58XW_CURSORTYPE type;
59int button ;
60#endif /*XW_PROTOTYPE*/
61{
62XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow ;
63XW_STATUS status ;
64XW_EVENTTYPE mask1=(XW_EVENTTYPE ) 0 ,mask2=(XW_EVENTTYPE ) 0 ;
65
66 if( !Xw_isdefine_window(pwindow) ) {
67 /*ERROR*Bad EXT_WINDOW Address*/
68 Xw_set_error(24,"Xw_set_soft_cursor",pwindow) ;
69 return (XW_ERROR) ;
70 }
71
72 if( button <= 0 || button > 3 ) {
73 /*WARNING*Bad Mouse button number*/
74 Xw_set_error(70,"Xw_set_soft_cursor",&button) ;
75 return (XW_ERROR) ;
76 }
77
78 if( button == 1 ) {
79 mask1 = XW_MOUSEBUTTON1 ; mask2 = XW_MOUSEMOVEWITHBUTTON1 ;
80 } else if( button == 2 ) {
81 mask1 = XW_MOUSEBUTTON2 ; mask2 = XW_MOUSEMOVEWITHBUTTON2 ;
82 } else if( button == 3 ) {
83 mask1 = XW_MOUSEBUTTON3 ; mask2 = XW_MOUSEMOVEWITHBUTTON3 ;
84 }
85
86 switch (type) {
87
88 case XW_WITHOUT_CURSOR :
89 status = Xw_set_internal_event(pwindow,mask1,NULL) ;
90 status = Xw_set_internal_event(pwindow,mask2,NULL) ;
91 break ;
92 case XW_RUBBERLINE_CURSOR :
93 status = Xw_set_internal_event(pwindow,mask1,
94 Xw_rubberline_cursor) ;
95 status = Xw_set_internal_event(pwindow,mask2,
96 Xw_rubberline_cursor) ;
97 break ;
98 case XW_RUBBERBAND_CURSOR :
99 status = Xw_set_internal_event(pwindow,mask1,
100 Xw_rubberband_cursor) ;
101 status = Xw_set_internal_event(pwindow,mask2,
102 Xw_rubberband_cursor) ;
103 break ;
104 case XW_USERDEFINED_CURSOR :
105 status = Xw_set_internal_event(pwindow,mask1,
106 Xw_userdefined_cursor) ;
107 status = Xw_set_internal_event(pwindow,mask2,
108 Xw_userdefined_cursor) ;
109 break ;
110#ifndef DEB
111 default:
112 break ;
113#endif
114 }
115
116
117#ifdef TRACE_SET_SOFT_CURSOR
118if( Xw_get_trace() ) {
119 printf (" Xw_set_soft_cursor(%lx,%d,%d)\n",(long ) pwindow,type,button) ;
120}
121#endif
122 return (XW_SUCCESS);
123
124}
125
126#ifdef XW_PROTOTYPE
127static XW_STATUS Xw_rubberline_cursor(XW_EVENT *event)
128#else
129static XW_STATUS Xw_rubberline_cursor(event)
130XW_EVENT *event ;
131#endif /*XW_PROTOTYPE*/
132{
133XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*) event->any.awindow ;
134
135#ifdef TRACE_SET_SOFT_CURSOR
136if( Xw_get_trace() > 2 ) {
137 printf (" Xw_rubberline_cursor(%lx,%d)\n",
138 (long ) event->any.awindow,event->any.type) ;
139}
140#endif
141
142 switch (event->any.type) {
143
144 case XW_MOUSEBUTTON1 :
145 case XW_MOUSEBUTTON2 :
146 case XW_MOUSEBUTTON3 :
147 if( Start ) {
148 Start = False ;
149 DrawLines(pwindow,points,2) ;
150 } else {
151 points[0].x = event->mousebutton.x ;
152 points[0].y = event->mousebutton.y ;
153 }
154 break ;
155
156 case XW_MOUSEMOVEWITHBUTTON1 :
157 case XW_MOUSEMOVEWITHBUTTON2 :
158 case XW_MOUSEMOVEWITHBUTTON3 :
159 if( Start ) {
160 DrawLines(pwindow,points,2) ;
161 }
162 Start = True ;
163 points[1].x = event->mousemovewithbutton.x - points[0].x ;
164 points[1].y = event->mousemovewithbutton.y - points[0].y ;
165 DrawLines(pwindow,points,2) ;
166 XFlush(_DISPLAY) ;
167 break ;
168#ifndef DEB
169 default:
170 break ;
171#endif
172 }
173
174 return (XW_SUCCESS) ;
175}
176
177#ifdef XW_PROTOTYPE
178static XW_STATUS Xw_rubberband_cursor(XW_EVENT *event)
179#else
180static XW_STATUS Xw_rubberband_cursor(event)
181XW_EVENT *event ;
182#endif /*XW_PROTOTYPE*/
183{
184XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*) event->any.awindow ;
185
186#ifdef TRACE_SET_SOFT_CURSOR
187if( Xw_get_trace() > 2 ) {
188 printf (" Xw_rubberband_cursor(%lx,%d)\n",
189 (long ) event->any.awindow,event->any.type) ;
190}
191#endif
192
193 switch (event->any.type) {
194
195 case XW_MOUSEBUTTON1 :
196 case XW_MOUSEBUTTON2 :
197 case XW_MOUSEBUTTON3 :
198 if( Start ) {
199 Start = False ;
200 DrawLines(pwindow,points,5) ;
201 } else {
202 points[0].x = event->mousebutton.x ;
203 points[0].y = event->mousebutton.y ;
204 }
205 break ;
206
207 case XW_MOUSEMOVEWITHBUTTON1 :
208 case XW_MOUSEMOVEWITHBUTTON2 :
209 case XW_MOUSEMOVEWITHBUTTON3 :
210 if( Start ) {
211 DrawLines(pwindow,points,5) ;
212 }
213 Start = True ;
214 points[1].x = 0 ;
215 points[1].y = event->mousemovewithbutton.y - points[0].y ;
216 points[2].x = event->mousemovewithbutton.x - points[0].x ;
217 points[2].y = 0 ;
218 points[3].x = 0 ;
219 points[3].y = -points[1].y ;
220 points[4].x = -points[2].x ;
221 points[4].y = 0 ;
222 DrawLines(pwindow,points,5) ;
223 XFlush(_DISPLAY) ;
224 break ;
225#ifndef DEB
226 default:
227 break ;
228#endif
229 }
230
231 return (XW_SUCCESS) ;
232}
233
234#ifdef XW_PROTOTYPE
235static XW_STATUS Xw_userdefined_cursor(XW_EVENT *event)
236#else
237static XW_STATUS Xw_userdefined_cursor(event)
238XW_EVENT *event ;
239#endif /*XW_PROTOTYPE*/
240{
241#ifdef TRACE_SET_SOFT_CURSOR
242if( Xw_get_trace() > 2 ) {
243 printf (" Xw_userdefined_cursor(%lx,%d)\n",
244 (long ) event->any.awindow,event->any.type) ;
245}
246#endif
247 Xw_set_error(97,"Xw_userdefined_cursor",&event->any.type) ;
248
249 return (XW_SUCCESS) ;
250}
251
252#ifdef XW_PROTOTYPE
253static void DrawLines(XW_EXT_WINDOW *pwindow,XPoint *points,int npoint)
254#else
255static void DrawLines(pwindow,points,npoint)
256XW_EXT_WINDOW *pwindow ;
257XPoint *points ;
258int npoint ;
259#endif /*XW_PROTOTYPE*/
260{
261XW_EXT_DISPLAY *pdisplay = pwindow->connexion ;
262
263 if( _DGRAB ) {
264 int xs = points[0].x,ys = points[0].y ;
265
266 points[0].x += _X ; points[0].y += _Y ;
267 XDrawLines(_DISPLAY,_DROOT,_DGC,points,npoint,CoordModePrevious) ;
268 points[0].x = xs ; points[0].y = ys ;
269 } else {
270 XDrawLines(_DISPLAY,_WINDOW,pwindow->qgwind.gchigh,
271 points,npoint,CoordModePrevious) ;
272 }
273}