summaryrefslogtreecommitdiff
path: root/xc/unsupported/lib/PHIGS/ws/wsa_inp.c
blob: 3c67121469bf77690aec8d498dc4b13cc2526c30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/* $XConsortium: wsa_inp.c,v 5.3 91/10/01 02:55:55 hersh Exp $ */

/***********************************************************

Copyright (c) 1989, 1990, 1991  X Consortium

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of the X Consortium shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from the X Consortium.

Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. 

                        All Rights Reserved

Permission to use, copy, modify, and distribute this software and its 
documentation for any purpose and without fee is hereby granted, 
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in 
supporting documentation, and that the name of Sun Microsystems,
not be used in advertising or publicity pertaining to distribution of 
the software without specific, written prior permission.  

SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT 
SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

******************************************************************/

/* PEX/PHIGS workstation input utility functions for the A model (server
 * side workstations and structure storage).  Code in this file must be
 * independent of any PM code.
 */

#include "phg.h"
#include "cp.h"
#include "ws.h"
#include "PEX.h"
#include "PEXproto.h"
#include "PEXmacs.h"
#include "PEXfuncs.h"
#include "phigspex.h"


int
phg_wsa_resolve_stroke( ws, num_pts, dc_pts, determine_z, view_index, wc_pts )
    Ws			*ws;
    int			num_pts;
    pexDeviceCoord      *dc_pts;
    int			determine_z;
    Pint		*view_index;
    Ppoint_list3	*wc_pts;
{
    int			status = 0;
    CARD16		view;
    CARD32		count;
    pexCoord3D		*pex_points;
    pexViewport		*vp;
    Pfloat		z_DC;
    pexBitmask		mask[PEXMSGetWksInfo];

    register int	i;

    if ( determine_z ) {
	bzero((char *)mask, sizeof(mask));   
	PEX_BITSET(mask, PEXPWCurWksViewport);
	if ( PEXGetWksInfo( ws->display, ws->rid, mask, (char **)&vp ) ) {
	    z_DC = vp->maxval.z;
	    for ( i = 0; i < num_pts; i++ )
		dc_pts[i].z = z_DC;
	}
    }

    if ( PEXMapDCtoWC( ws->display, ws->rid, (CARD32)num_pts, dc_pts, &view,
	    &count, &pex_points ) && count > 0 ) {
	for ( i = 0; i < count; i++ ) {
	    wc_pts->points[i].x = pex_points[i].x;
	    wc_pts->points[i].y = pex_points[i].y;
	    wc_pts->points[i].z = pex_points[i].z;
	}
	wc_pts->num_points = count;
	*view_index = view;
	status = 1;

    } else {
	wc_pts->num_points = 0;
    }

    return status;
}


int
phg_wsa_resolve_locator( ws, dc_pt, determine_z, view_index, wc_pt )
    Ws			*ws;
    pexDeviceCoord      *dc_pt;
    int			determine_z;
    Pint		*view_index;
    Ppoint3		*wc_pt;
{
    Ppoint_list3	wc_pts;

    wc_pts.points = wc_pt;
    return phg_wsa_resolve_stroke( ws, 1, dc_pt, determine_z, view_index,
	&wc_pts );
}


int
phg_wsa_resolve_pick( ws, dev, dc_pt, status, depth, path )
    Ws			*ws;
    Ws_inp_pick		*dev;
    pexDeviceCoord	*dc_pt;
    CARD16		*status;
    CARD32		*depth;
    pexPickPath		**path;
{
    pexViewport		*vp;
    pexNpcSubvolume	*win;
    Plimit3		ws_win, ws_vp;
    Ws_xform		ws_xform;
    pexBitmask		mask[PEXMSGetWksInfo];
    pexPD_DC_HitBox	dc_box;
    pexPD_NPC_HitVolume npc_volume;
    pexDeviceCoord2D	dc_vol[2];
    Ppoint		npc_pt[2];
    char		*buf;

    *depth = 0;
    *status = PEXNoPick;

    /* Compute the aperture. */
    bzero((char *)mask, sizeof(mask));   
    switch ( dev->dev_type ) {
	case PEXPickDeviceDC_HitBox:
	    PEX_BITSET(mask, PEXPWCurWksViewport);
	    if ( PEXGetWksInfo( ws->display, ws->rid, mask, (char **)&vp )){
		ws_vp.x_min = vp->minval.x; ws_vp.x_max = vp->maxval.x;
		ws_vp.y_min = vp->minval.y; ws_vp.y_max = vp->maxval.y;
		if ( !WS_PT_IN_LIMIT2( &ws_vp, dc_pt ) )
		    return 0;

		/* Compute the aperture. */
		dc_box.position.x = dc_pt->x;
		dc_box.position.y = dc_pt->y;
		dc_box.distance = dev->ap_size;

		(void)PEXUpdatePickMeasure( ws->display, dev->measure,
		    (CARD32)sizeof(dc_box), (CARD8 *)&dc_box );
	    } else
		return 0;
	    break;

	case PEXPickDeviceNPC_HitVolume:
	    /* Compute the workstation transform, transform the DC point
	     * and DC aperture size to an NPC volume.
	     */
	    PEX_BITSET(mask, PEXPWCurNpcSubvolume);
	    PEX_BITSET(mask, PEXPWCurWksViewport);
	    if ( PEXGetWksInfo( ws->display, ws->rid, mask, (char **)&win)){
		/* Build the current workstation transform. */
		vp = (pexViewport *)(win + 1);
		ws_win.x_min = win->minval.x; ws_win.x_max = win->maxval.x;
		ws_win.y_min = win->minval.y; ws_win.y_max = win->maxval.y;
		ws_win.z_min = win->minval.z; ws_win.z_max = win->maxval.z;
		ws_vp.x_min = vp->minval.x; ws_vp.x_max = vp->maxval.x;
		ws_vp.y_min = vp->minval.y; ws_vp.y_max = vp->maxval.y;
		ws_vp.z_min = vp->minval.z; ws_vp.z_max = vp->maxval.z;
		if ( !WS_PT_IN_LIMIT2( &ws_vp, dc_pt ) )
		    return 0;

		/* Compute the aperture. */
		dc_vol[0].x = dc_pt->x - dev->ap_size;
		dc_vol[0].y = dc_pt->y - dev->ap_size;
		dc_vol[1].x = dc_pt->x + dev->ap_size;
		dc_vol[1].y = dc_pt->y + dev->ap_size;
		phg_wsx_compute_ws_transform( &ws_win, &ws_vp, &ws_xform );
		WS_DC_TO_NPC2(&ws_xform, &dc_vol[0], &npc_pt[0])
		WS_DC_TO_NPC2(&ws_xform, &dc_vol[1], &npc_pt[1])
		npc_volume.minval.x = npc_pt[0].x;
		npc_volume.minval.y = npc_pt[0].y;
		npc_volume.maxval.x = npc_pt[1].x;
		npc_volume.maxval.y = npc_pt[1].y;
		/* The volume extends the full depth of the window. */
		npc_volume.minval.z = win->minval.z;
		npc_volume.maxval.z = win->maxval.z;

		(void)PEXUpdatePickMeasure( ws->display, dev->measure,
		    (CARD32)sizeof(npc_volume), (CARD8 *)&npc_volume );
	    } else
		return 0;
	    break;
    }

    mask[0] = PEXPDPickStatus | PEXPDPickPath;
    if ( !PEXGetPickMeasure( ws->display, dev->measure, mask[0], &buf ) )
	return 0;	/* TODO: use phg_pex_errno */

    *status = (CARD16) *((CARD32 *)buf);
    *depth = *((CARD32 *)(buf + sizeof(CARD32)));
    *path = (pexPickPath *)(buf + 2 * sizeof(CARD32));

    return 1;
}


int
phg_wsa_pick_enable( ws, dev, init_path_size, init_path )
    Ws			*ws;
    Ws_inp_pick		*dev;
    CARD32		init_path_size;
    char		*init_path;	/* must be PEX encoded */
{
    pexBitmask		mask = 0;
    CARD32		size, *card32_p;
    XID			*xid_p;
    CARD16		*card16_p;
    INT16		*int16_p;
    pexViewport		*ev;
    char		buffer[6 * sizeof(CARD32) + sizeof(pexViewport)];

    register char	*buf = buffer;

    /* Set the device data and create a pick measure for this interaction. */
    mask |= PEXPDPickStatus;
    card32_p = (CARD32 *)buf; 
    *card32_p = dev->pick.status == PIN_STATUS_OK ? PEXOk : PEXNoPick;
    buf += sizeof(CARD32);

    mask |= PEXPDPickPathOrder;
    card32_p = (CARD32 *)buf; 
    *card32_p = dev->order == PORDER_TOP_FIRST ? PEXTopFirst : PEXBottomFirst;
    buf += sizeof(CARD32);

    mask |= PEXPDPickIncl;
    xid_p = (XID *)buf; 
    *xid_p = dev->filter.incl;
    buf += sizeof(CARD32);

    mask |= PEXPDPickExcl;
    xid_p = (XID *)buf; 
    *xid_p = dev->filter.excl;
    buf += sizeof(CARD32);

    mask |= PEXPDPickPromptEchoType;
    card32_p = (CARD32 *)buf; 
    *card32_p = (CARD32)dev->pet;
    buf += sizeof(CARD32);

    mask |= PEXPDPickEchoVolume;
    ev = (pexViewport *)buf; 
    ev->minval.x = dev->e_volume.x_min;
    ev->minval.y = dev->e_volume.y_min;
    ev->minval.z = dev->e_volume.z_min;
    ev->maxval.x = dev->e_volume.x_max;
    ev->maxval.y = dev->e_volume.y_max;
    ev->maxval.z = dev->e_volume.z_max;
    ev->useDrawable = 0;
    buf += sizeof(pexViewport);

    mask |= PEXPDPickEchoSwitch;
    card32_p = (CARD32 *)buf; 
    *card32_p = dev->esw == PSWITCH_ECHO ? PEXEcho : PEXNoEcho;
    buf += sizeof(CARD32);

    (void)PEXChangePickDevice( ws->display, ws->rid, dev->dev_type, mask,
															(CARD32)sizeof(buffer), buffer );

    if ( dev->pick.status == PIN_STATUS_OK ) {
	mask = PEXPDPickPath;
	(void)PEXChangePickDevice( ws->display, ws->rid, dev->dev_type, mask,
	    init_path_size, init_path );
    }

    (void)PEXCreatePickMeasure( ws->display, ws->rid,
	dev->measure = XAllocID(ws->display), (pexEnumTypeIndex)dev->dev_type );
    XFlush( ws->display );

    return 1;
}


void
phg_wsa_pick_disable( ws, dev )
    Ws			*ws;
    Ws_inp_pick		*dev;
{
    /* Free and clear the pick measure. */
    if ( dev->measure ) {
	(void)PEXFreePickMeasure( ws->display, dev->measure );
	dev->measure = 0;
    }
}