File: coords.c

package info (click to toggle)
irsim 9.7.75-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 2,596 kB
  • sloc: ansic: 24,733; sh: 6,803; makefile: 411; csh: 269; tcl: 76
file content (354 lines) | stat: -rw-r--r-- 9,031 bytes parent folder | download | duplicates (7)
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/*
 *     ********************************************************************* 
 *     * Copyright (C) 1988, 1990 Stanford University.                     * 
 *     * 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.  Stanford University                 * 
 *     * makes no representations about the suitability of this            * 
 *     * software for any purpose.  It is provided "as is" without         * 
 *     * express or implied warranty.  Export of this software outside     * 
 *     * of the United States of America may require an export license.    * 
 *     *********************************************************************
 */

/*
 * Calculate the Position/bounding-boxes of all the objects on the screen.
 */
#include <string.h>  /* for strlen() */
#include "ana.h"
#include "ana_glob.h"


#define	TRACEGAP	4			/* separation between traces */
#define	MAX_INCR	( 3*CHARWIDTH+TRACEGAP )   /* max. height of a trace */
#define	MINWIDTH	( 14 * CHARWIDTH )	   /* minimum traces width */
#define	MINHEIGHT	(7 * CHARHEIGHT)

#ifdef TCL_IRSIM
#define	BOX_SIZE	0
#else
#define	BOX_SIZE	13			/* size of banner icons */
#endif


        /* this is the same as traceBox.bot - traceBox.top + 1 */
#define TracesHeight() ( YWINDOWSIZE - SCROLLBARHEIGHT - 2 * CHARHEIGHT - 4 - \
  max( CHARHEIGHT + 3, BOX_SIZE + 6 - 1 ) )


public	int     XWINDOWSIZE = 0;
public	int     YWINDOWSIZE = 0;

public	BBox    traceBox;

/* Note:  These should be got rid of in the Tcl/Tk version. . . */
public	BBox    bannerBox;
public	BBox    scrollBox;
public	BBox    barPos;
public	BBox    namesBox;
public	BBox    cursorBox;
public	BBox    timesBox;
public	BBox    textBox;
public	BBox    iconBox;
public	BBox    sizeBox;
public	BBox    selectBox;
public	BBox    menuBox;

private	int     tw_left = 0;
private	int     tw_right = 0;

#ifdef TCL_IRSIM

private void SetWindowCoords()
{
    traceBox.left = 0;
    traceBox.bot = YWINDOWSIZE - 1;
    traceBox.right = XWINDOWSIZE - 1;
    traceBox.top = 0;
}

#else /* (!TCL_IRSIM) */

/*
 * Set the Bounding Box/Location of all the objects in the analyzer window.
 */
private void SetWindowCoords()
  {
    bannerBox.left = 0;
    bannerBox.top = 0;
    bannerBox.bot = max( bannerBox.top + CHARHEIGHT + 3, (BOX_SIZE + 6 - 1) );
    bannerBox.right = XWINDOWSIZE - 1;

    iconBox.top = bannerBox.top + 2;
    iconBox.bot = iconBox.top + BOX_SIZE - 1;
    iconBox.left = 2;
    iconBox.right = iconBox.left + BOX_SIZE - 1;

    sizeBox.top = iconBox.top;
    sizeBox.bot = iconBox.top;
    sizeBox.right = XWINDOWSIZE - 4;
    sizeBox.left = sizeBox.right - (BOX_SIZE - 1);

      {
	register Menu  *mp;
	Coord          x, x1;

        menuBox.bot = bannerBox.bot - 2;
        menuBox.top = menuBox.bot - CHARHEIGHT;
	for( mp = menu; mp->str != NULL; mp++ );

	menuBox.right = sizeBox.left - 3;
	for( mp--, x = menuBox.right + 1 ; mp >= menu; mp-- )
	  {
	    mp->box.top = menuBox.top;
	    mp->box.bot = menuBox.bot;
	    mp->box.right = x - 1;
	    mp->box.left = x - CHARWIDTH * (mp->len + 1);
	    x = mp->box.left - 3;
	  }
	menuBox.left = x + 1;
	selectBox.right = x - 4;
      }
    
    selectBox.top = iconBox.top;
    selectBox.bot = iconBox.bot;
    selectBox.left = iconBox.right + bannerLen * CHARWIDTH + 4 + 3;

    timesBox.left = tw_left - 1;
    timesBox.top = bannerBox.bot + 1;
    timesBox.right = tw_right + 1;
    timesBox.bot = timesBox.top + CHARHEIGHT + 2 - 1;

    textBox.left = 0;
    textBox.top = YWINDOWSIZE - CHARHEIGHT - 3;
    textBox.right = XWINDOWSIZE - 1;
    textBox.bot = YWINDOWSIZE - 1;

    namesBox.left = 0;
    namesBox.top = timesBox.bot + 1;
    namesBox.right = tw_left - 1;
    namesBox.bot = textBox.top - SCROLLBARHEIGHT;

    cursorBox.top = namesBox.top;
    cursorBox.right = XWINDOWSIZE - 1;
    cursorBox.left = tw_right + 1;
    cursorBox.bot = namesBox.bot;

    traceBox.left = tw_left;
    traceBox.bot = namesBox.bot + 1;
    traceBox.right = tw_right;
    traceBox.top = namesBox.top;

    scrollBox.left = traceBox.left - ARROW_WIDTH + 1;
    scrollBox.bot = textBox.top;
    scrollBox.right = traceBox.right + ARROW_WIDTH;
    scrollBox.top = scrollBox.bot - SCROLLBARHEIGHT + 1;

    barPos.bot = scrollBox.bot - (SCROLLBARHEIGHT / 2) + 2;
    barPos.top = barPos.bot - 7;
  }

#endif /* (!TCL_IRSIM) */
					/* char + 2 spaces + 2 lines */
#define	MINBUSHEIGHT		( CHARHEIGHT + 4 + TRACEGAP )
					/* a bit smaller that a char */
#define	MINSIGHEIGHT		( CHARHEIGHT + TRACEGAP - 3 )

/*
 * Calculate the number of traces that will fit (vertically).
 */
private int VisibleTraces()
  {
    register Trptr  t;
    register int    Ysize, n, i, busHeight, logicHeight;

    Ysize = TracesHeight();

    Ysize -= TRACEGAP;
    busHeight = MINBUSHEIGHT;
    logicHeight = MINSIGHEIGHT;

    for( i = 0, n = traces.total, t = traces.first; i < n; i++, t = t->next )
      {
	Ysize -= ( IsVector( t ) ) ? busHeight : logicHeight;
	if( Ysize < 0 )
	    return( i );
      }
    return( n );
  }


/*
 * Calculate vertical position of traces.
 */
public void SetSignalPos()
  {
    register Trptr    t;
    register int      i, pos;
    int               busHeight, logicHeight, incr, Ysize;

    if( traces.disp == 0 )
	return;

    Ysize = TracesHeight();
    pos = TRACEGAP;
    busHeight = MINBUSHEIGHT;
    logicHeight = MINSIGHEIGHT;

    for( i = traces.disp, t = traces.first; i != 0 ; i--, t = t->next )
	pos += ( IsVector( t ) ) ? busHeight : logicHeight;

    incr = (Ysize - pos) / traces.disp;
    if( incr > MAX_INCR )
	incr = MAX_INCR;

    busHeight += (incr - TRACEGAP);
    logicHeight += (incr - TRACEGAP);

    pos = traceBox.top + TRACEGAP;
    
    for( t = traces.first, i = traces.disp; i != 0; i--, t = t->next )
      {
        t->top = pos;
	pos += ( IsVector( t ) ) ? busHeight : logicHeight;
        t->bot = pos;
	pos += TRACEGAP;
      }
  }


/*
 * Return the maximum number of digits required to display a trace value.
 */
private int MaxTraceDigits( n )
  register int  n;
  {
    register int     ndigits, maxDigits;
    register Trptr   t;
    
    maxDigits = 1;
    for( t = traces.first; n != 0; n--, t = t->next )
      {
	if( IsVector( t ) )
	  {
	    if (t->bdigit == 5)
	       ndigits = (t->n.vec->nbits + 2) / 3;
	    else if (t->bdigit == 6)
	       ndigits = 1 + ((t->n.vec->nbits + 2) / 3);
	    else
	       ndigits = (t->n.vec->nbits + t->bdigit - 1) / t->bdigit;
	    if( ndigits > maxDigits )
		maxDigits = ndigits;
	  }
      }
    return( maxDigits );
  }


/*
 * Return the length of the longest trace name.
 */
private int MaxTraceName( n )
  register int  n;
  {
    register int      len, maxLen;
    register Trptr    t;
    
    maxLen = 0;
    for( t = traces.first; n != 0; n--, t = t->next )
      {
	len = strlen( t->name );
	if( len > maxLen )
	    maxLen = len;
      }
    return( maxLen );
  }


public void GetMinWsize( w, h )
  int  *w, *h;
  {
    int  maxDigits, maxName;

    maxDigits = MaxTraceDigits( traces.total );
    maxDigits = max( maxDigits, 16 );
    maxName = MaxTraceName( traces.total );
    maxName = max( maxName, 15 );

    *w = max( (CHARWIDTH * maxName) + 2, ARROW_WIDTH + 4 ) + 2 +
	 max( (CHARWIDTH * maxDigits) + 2, ARROW_WIDTH ) + 2 + MINWIDTH;
    *h = MINHEIGHT;
  }


public
#define	NTRACE_CHANGE		0x01	/* # of visible traces changed */
public
#define	WIDTH_CHANGE		0x02	/* change in width of trace window */
public
#define	HEIGHT_CHANGE		0x04	/* change in height of trace window */
public
#define	RESIZED			0x10	/* window is too small,should resize */

public int WindowChanges()
  {
    int         left, right, tooSmall;
    int         ndisp, maxDigits, maxName, ret;
    static int  lastY = -1;

    ndisp = VisibleTraces();
    maxDigits = MaxTraceDigits( ndisp );
    maxName = MaxTraceName( ndisp );

    left = max( (CHARWIDTH * maxName) + 2, ARROW_WIDTH + 4 ) + 2;
    right = XWINDOWSIZE - max( (CHARWIDTH * maxDigits) + 2, ARROW_WIDTH ) - 2;

    tooSmall = FALSE;
    if( right - left < MINWIDTH )
	tooSmall = TRUE;

    if( YWINDOWSIZE < MINHEIGHT )
	tooSmall = TRUE;

    if( tooSmall )
      {
	windowState.tooSmall = TRUE;
	lastY = 0;
	return( RESIZED );
      }

    windowState.tooSmall = FALSE;	/* could have been set before */

    ret = 0;
    if( ndisp != traces.disp )
      {
	int  last_disp = traces.disp;

	traces.disp = ndisp;
	ret |= NTRACE_CHANGE;
	if( ndisp > last_disp )
	    UpdateTraceCache( last_disp );
      }

    if( (left != tw_left or right != tw_right) )
      {
	tw_left = left;
	tw_right = right;
	ret |= WIDTH_CHANGE;
      }

    if( lastY != YWINDOWSIZE )
      {
	lastY = YWINDOWSIZE;
	ret |= HEIGHT_CHANGE;
      }

    if( ret & (HEIGHT_CHANGE | WIDTH_CHANGE) )
	SetWindowCoords();

    if( ret & (HEIGHT_CHANGE | NTRACE_CHANGE) )
	SetSignalPos();

    return( ret );
  }