1 /* -----------------------------------------------------------------
2 FILE:	    draw.h
3 DESCRIPTION:include file for draw programs and utilities
4 CONTENTS:   typedefs, and external routines for draw facility
5 DATE:	    Jan 25, 1989 - major rewrite of version 1.0
6 REVISIONS:  Jan 27, 1989 - added frame num
7 	    Oct 8,  1989 - separated menu reading function for
8 		user friendliness.
9 	    May 12, 1990 - added TWsetFrame to include file.
10 	    Oct  5, 1990 - added prototypes.
11 	    Oct 12, 1990 - added TWforceRedraw.
12 	    Fri Jan 25 15:38:41 PST 1991 - fixed inconsistent def.
13 	    Sun Feb 17 17:11:57 EST 1991 - added 3D graphics functions.
14 	    Tue May 21 17:14:39 CDT 1991 - fixed problem with
15 		initgraphics prototype.
16 ----------------------------------------------------------------- */
17 #ifndef DRAW_H
18 #define DRAW_H
19 
20 
21 #include <yalecad/base.h>  /* need for BOOL definitions used below */
22 
23 /****  THE MODES *******/
24 #define TWDRAWONLY   0
25 #define TWWRITEONLY  1
26 #define TWWRITENDRAW 2
27 
28 /* defininition necessary for menus */
29 typedef struct {
30     char *item ;         /* menu or menu item */
31     char *bool_item ;    /* used for Boolean items */
32     BOOL bool_init ;     /* which item is initialized */
33     BOOL menuNotItem ;   /* true if menu; false if menu item */
34     INT  action_index ;  /* when selected returns this number */
35     INT  action_indexb ; /* when selected returns this number */
36 } TWMENUBOX, *TWMENUPTR ;
37 
38 /* the switchable routines */
39 extern VOID (*_TWdrawRect)(P7( INT ref_num, INT x1, INT y1, INT x2, INT y2, INT color,
40 		    char *label )) ;
41 extern VOID (*_TWdrawLine)(P7( INT ref_num, INT x1, INT y1, INT x2, INT y2, INT color,
42 		    char *label )) ;
43 extern VOID (*_TWdrawArb)(P3( INT ref_num, INT color, char *label )) ;
44 
45 /* make calls easier for the user so he doesn't know that the */
46 /* routines are switchable according to mode */
47 #define TWdrawRect(a_xz, b_xz, c_xz, d_xz, e_xz, f_xz, g_xz )\
48     (  (*_TWdrawRect)(a_xz, b_xz, c_xz, d_xz, e_xz, f_xz, g_xz) )
49 #define TWdrawLine(a_xz, b_xz, c_xz, d_xz, e_xz, f_xz, g_xz )\
50     (  (*_TWdrawLine)(a_xz, b_xz, c_xz, d_xz, e_xz, f_xz, g_xz) )
51 #define TWdrawArb(a_xz, b_xz, c_xz )\
52     (  (*_TWdrawArb)(a_xz, b_xz, c_xz) )
53 #define TWdrawPin(a_xz, b_xz, c_xz, d_xz, e_xz, f_xz, g_xz )\
54     (  (*_TWdrawRect)(a_xz, b_xz, c_xz, d_xz, e_xz, f_xz, g_xz) )
55 #define TWdrawNet(a_xz, b_xz, c_xz, d_xz, e_xz, f_xz, g_xz )\
56     (  (*_TWdrawLine)(a_xz, b_xz, c_xz, d_xz, e_xz, f_xz, g_xz) )
57 #define TWdrawCell(a_xz, b_xz, c_xz, d_xz, e_xz, f_xz, g_xz )\
58     (  (*_TWdrawRect)(a_xz, b_xz, c_xz, d_xz, e_xz, f_xz, g_xz) )
59 
60 /* new defines for 3D graphics */
61 #define TW3DdrawAxis()                    _TW3DdrawAxis( TRUE )
62 #define TW3Darb_init()                    TWarb_init()
63 #define TW3DdrawArb( ref, color, label )  TWdrawArb( ref, color, label )
64 #define TW3Darb_addpt( x1, y1, z1 )            \
65 {   DOUBLE X1, Y1 ; \
66     TW3Dperspective( (DOUBLE)x1, (DOUBLE)y1, (DOUBLE)z1, &X1, &Y1 ); \
67     TWarb_addpt( (INT)X1, (INT)Y1 ); \
68 }
69 
70 #define TW3DdrawLine( ref_num, x1, y1, z1, x2, y2, z2, color, label) \
71 {   DOUBLE X1, Y1, X2, Y2 ;  \
72     TW3Dperspective( (DOUBLE)x1, (DOUBLE)y1, (DOUBLE)z1, &X1, &Y1 ); \
73     TW3Dperspective( (DOUBLE)x2, (DOUBLE)y2, (DOUBLE)z2, &X2, &Y2 ); \
74     TWdrawLine(ref_num,(INT)X1,(INT)Y1,(INT)X2,(INT)Y2,color, label) ; \
75 }
76 
77 extern  void _TW3DdrawAxis( P1(BOOL drawNotErase) ) ;
78 
79 
80 /******** FUNCTIONS NORMALLY USED BY GRAPHIC PROGRAM USERS *********/
81 extern BOOL TWinitGraphics( P7(INT argc, char *argv[], INT numC, char *colors[],
82 		BOOL dumpOnly, TWMENUPTR menu, INT (*refresh_func)() )) ;
83 /*
84 Function:
85     Initialization of graphics package.  Needs to be called first.
86     Argc is the number of arguments passed on the command line.
87     Argv is the argument vector.
88     Colors is an array of strings of the desired colors.  The
89     colors must agree with the standard color map of the machine and
90     in addition element 1 must be "white" and element two "black". Also
91     element 0 is not used at this time.  Use TWstdcolors to use
92     the graphics packages builtin standard colors.
93     NumC is the number of colors in the color array counting white and
94     black.
95     DumpOnly should normally be set to FALSE.  It should be only set to
96     TRUE if you wish to only dump the DATA to the DATADIRECTORY.
97     MenuPath is the pathname of the menu file.
98     Refresh_func is the address of the function which repaints
99     the entire drawing area.
100     NOTE: it is advised that the TimberWolf standard colors be used if
101     possible.  Use TWstdcolors() for argument colors and TWnumcolors()
102     for numC arg and use include file <yalecad/colors.h>.
103 */
104 
105 extern BOOL TWinitParasite( P8( INT argc, char *argv[], INT numC, char **colors,
106     BOOL dumpOnly,TWMENUPTR menu, INT (*refresh_func)(), INT w) ) ;
107 /*
108 Function:
109     Take over the control of a window already created by
110     TWinitGraphics by another process.  One additional parameter to the
111     TWinitGraphics argument list, windowId which is the top window Id.
112     It is found by calling TWsaveState in the calling processs.
113 */
114 
115 extern void TWcloseGraphics() ;
116 /*
117 Function:
118     Closes graphics display and performs cleanup operations.
119     Should be performed before end of program.
120 */
121 
122 extern void TWsetMode( P1(INT mode) ) ;
123 /*
124 Function:
125     Allows user to change mode during run.  Helpful to dump the current
126     state to the binary files and then continue drawing to the screen.
127     WARNING: This should only be used if TWinitGraphics was called with
128     mode TWWRITENDRAW; otherwise, error results.
129 */
130 
131 extern BOOL TWcheckServer() ;
132 /*
133 Function:
134     Returns TRUE if a connection can be made to server. False otherwise.
135 */
136 
137 /* The following draw routines have been defined using macro calls */
138 /* so it is convenient for the user.  Use the form shown in comments. */
139 
140 /* TWdrawRect(ref_num, x1, y1, x2, y2, color, label ) */
141 /*
142 Arguments:
143     INT ref_num, x1, y1, x2, y2, color ;
144     char *label ;
145 Function:
146     Draws a rectangle to screen and/or file.
147     Ref_num is a reference number to associate rectangle - currently
148     not used.
149     X1, y1, x2, y2 are the lower left, upper right points of rectangle.
150     Color is the element number in color array. For example white is 1
151     and black is 2.
152     Label is optional - a label is attached to figure if non-null.
153 */
154 
155 /* TWdrawLine(ref_num, x1, y1, x2, y2, color, label ) */
156 /*
157 Arguments:
158     INT ref_num, x1, y1, x2, y2, color ;
159     char *label ;
160 Function:
161     Draws a line to screen and/or file.
162     Ref_num is a reference number to associate line - currently
163     not used.
164     X1, y1, x2, y2 are the two points of the line.
165     Color is the element number in color array. For example white is 1
166     and black is 2.
167     Label is optional - a label is attached to figure if non-null.
168 */
169 
170 /* TWdrawNet(ref_num, x1, y1, x2, y2, color, label ) */
171 /*
172 Arguments:
173     INT ref_num, x1, y1, x2, y2, color ;
174     char *label ;
175 Function:
176     Draws a net to screen and/or file.
177     Ref_num is a reference number to associate all lines of a net -
178 	currently not used.
179     X1, y1, x2, y2 are the two points of the line of a net.
180     Color is the element number in color array. For example white is 1
181     and black is 2.
182     Label is optional - a label is attached to figure if non-null.
183 */
184 
185 /* TWdrawCell(ref_num, x1, y1, x2, y2, color, label ) */
186 /*
187 Arguments:
188     INT ref_num, x1, y1, x2, y2, color ;
189     char *label ;
190 Function:
191     Draws a cell to screen and/or file.
192     Ref_num is a reference number to associate cell - currently
193 	not used.
194     X1, y1, x2, y2 are the lower left, upper right points of cell.
195     Color is the element number in color array. For example white is 1
196     and black is 2.
197     Label is optional - a label is attached to figure if non-null.
198 */
199 
200 /* TWdrawPin(ref_num, x1, y1, x2, y2, color, label ) */
201 /*
202 Function:
203     Draws a pin to screen and/or file.
204     Ref_num is a reference number to associate pin - currently
205 	not used.
206     X1, y1, x2, y2 are the lower left, upper right points of pin.
207     Color is the element number in color array. For example white is 1
208     and black is 2.
209     Label is optional - a label is attached to figure if non-null.
210 */
211 
212 extern void TWarb_init() ;
213 /*
214 Arguments:
215     none
216 Function:
217     Start a new arbitrary figure.
218 */
219 
220 extern void TWarb_addpt( P2( INT xpos, INT ypos ) ) ;
221 /*
222 Function:
223     Add a new point to the current arbitrary figure
224 */
225 
226 /* TWdrawArb( ref_num, color, label ) */
227 /*
228 Function:
229     Draws a arbitrary figure to screen and/or file.
230     Ref_num is a reference number to associate figure - currently
231 	not used.
232     The points of the arbitrary figure are first added using TWarb_init
233     and the TWarb_addpt.  There is no need to close the figure.
234     Color is the element number in color array. For example white is 1
235     and black is 2.
236     Label is optional - a label is attached to figure if non-null.
237 */
238 
239 /* copy pixmap to screen and flush screen output buffer */
240 extern void TWflushFrame() ;
241 /*
242 Arguments: None.
243 Function:
244     Flush the screen output and/or file buffer.
245     This call must be made after all data of a screen is written, that is
246     after all TWdraws have performed.
247 */
248 
249 extern void TWstartFrame() ;
250 /*
251 Arguments: None.
252 Function:
253     Start a new screen and/or file frame.
254     This call must be made before data is written, that is
255     before any TWdraws are performed for a given screen or frame.
256 */
257 
258 /********** ROUTINES USED BY SCREEN GRAPHICS ONLY ******************/
259 extern void TWzoom() ;
260 /*
261 Arguments: None
262 Function:
263     Performs a zoom in main graphics window.
264 */
265 
266 extern void TWtranslate() ;
267 /*
268 Arguments: None
269 Function:
270     Translate center to picked or entered point in main graphics window.
271 */
272 
273 extern void TWfullView() ;
274 /*
275 Arguments: None
276 Function:
277     Returns to full screen after zoom.  Full screen size is size
278     determined by TWsetWindow.
279 */
280 
281 extern void TWsetwindow( P4( INT left, INT bottom, INT right, INT top ) ) ;
282 /*
283 Function:
284     set the boundary of the visible window according to user coordinates
285     Must call this function before draws.
286 */
287 
288 extern void TWcolorXOR( P2( INT color, BOOL exorFlag ) ) ;
289 /*
290 Function:
291     set a particular colors draw function.  If exorFlag is set to TRUE,
292     then X will exor the next drawing with the current contents of the
293     display.  If exorFlag is set to FALSE, X will copy the new figure
294     over any current contents blocking the view.  The default is copy mode.
295 */
296 
297 extern void TWhighLightRect( P4( INT x1,INT y1,INT x2,INT y2 )) ;
298 /*
299 Function:
300     Highlight the given area in black.
301 */
302 
303 extern void TWsync( ) ;
304 /*
305 Arguments: None
306 Function:
307     Make program wait until XServer has processed all requests.  This
308     function should not be need by the user normally.  It is used
309     internally in the graphics module.
310 */
311 
312 extern void TWmoveRect( P6( INT *x1, INT *y1, INT *x2, INT *y2, INT ptx, INT pty )) ;
313 /*
314 Function:
315     Draw ghost figure of rectangle as the user moves it on the screen.
316     X1, y1, x2, y2 are pointer to the original position of the rectangle
317     in user data coordinates.  Ptx, and pty are the reference point of
318     the mouse pointer.  The figure will move relative to the offset
319     between the pointer and the given rectangle coordinates.  The
320     routine will return in x1, y1, x2, y2 the new position of the
321     rectangle when the mouse button is pushed.
322 */
323 
324 
325 /********** MENU ROUTINES-USED BY SCREEN GRAPHICS ONLY ******************/
326 extern INT TWcheckMouse() ;
327 /*
328 Arguments: None
329 Function:
330     Check to see if mouse button was clicked in menu window.  If so,
331     put up appropriate menu and wait for user response.  Return integer
332     value corresponding to the function value given in the menu file.
333 */
334 
335 extern void TWgetPt( P2( INT *x, INT *y )) ;
336 /*
337 Function:
338     Wait for user to enter point with a mouse pointer.  Returns x,y
339     position of pointer when clicked in user coordinate system.
340 */
341 
342 extern void TWmessage( P1( char *message ) ) ;
343 /*
344 Function:
345     Write messsage to the message window.
346 */
347 
348 extern char *TWgetString( P1( char *directions ) ) ;
349 /*
350 Function:
351     Write directions on what to do to message window and then return
352     back a string in what the user entered in the window.
353 */
354 
355 
356 extern BOOL TWgetPt2( P2( INT *x, INT *y ) ) ;
357 /*
358 Function:
359     Wait for user to enter point with a mouse pointer or by entering
360     string in message window.  Returns x,y position in user coordinate
361     system.  Returns TRUE (1) if user entered data from keyboard and
362     FALSE (0) if entered by picking with the mouse.
363 */
364 
365 /* check to see if main window has been covered by another window */
366 extern BOOL TWcheckExposure() ;
367 /*
368 Arguments:None
369 Function:
370     Check to see if main window has been covered by another window.
371     Returns TRUE (1) if this has occurred and FALSE (0) otherwise.
372     User uses this knowledge for redraw of window data.
373 */
374 
375 extern INT TWsaveState() ;
376 /*
377 Arguments:None
378 Function:
379     Save the graphics state before calling a grahics parasite.  Returns
380     the window ID which is needed in the TWinitParasite argument list.
381 */
382 
383 extern void TWrestoreState() ;
384 /*
385 Arguments:None
386 Function:
387     Return the graphics state to the state before the graphics parasite
388     was called.
389 */
390 
391 /* check to see if main window has been requested to change size */
392 extern void TWcheckReconfig() ;
393 /*
394 Arguments:None
395 Function:
396     Check to see if main window has been requested to change size
397     and perform necessary modifications to windows.  Note: normally
398     the user will not need to call this function since it is performed
399     during each call of TWcheckMouse.
400 */
401 
402 
403 extern void TWsetFrame( P1(INT number) ) ;
404 /*
405 Function:
406     Set the dump file to the given frame number.  Valid frame numbers start
407     at 1.  If 0 is passed, the frame will be set to the next available frame
408     in the DATADIR.
409 */
410 
411 extern TWMENUPTR TWread_menus( P1(char *filename) ) ;
412 /*
413 Function:
414     This convenience function reads a menu file and create the menu
415     box structure necessary for TWinitgraphics.  Upon execution of
416     the function,  a menus.h file will be created in the current
417     directory with all the necessary definitions for creating the
418     menus.
419 */
420 
421 extern void TWforceRedraw() ;
422 /*
423 Function:
424     This function forces a redraw by sending an exposure event
425     to the server.  This is added so the user can control
426     exposure events.
427 */
428 
429 extern void TWdrawString( P4(INT x, INT y, INT color, char *label ) ) ;
430 /*
431 Function:
432     Draw a string left justified from the given location.
433 */
434 
435 /* *************** NEW 3D TRANSFORMATIONS ********************* */
436 /* TW3DdrawAxis()  */
437 /*
438 Function:
439     TW3DdrawAxis draws the x y z axis.
440 */
441 
442 extern VOID TW3Dnormal_view() ;
443 /*
444 Function:
445     Turn off the 3D viewing.
446 */
447 
448 extern VOID TW3DsetCamera() ;
449 /*
450 Function:
451     Turn on the 3D viewing.  The view is set with the mouse.
452 */
453 
454 /*------------------
455   Perform a 3D transformation.
456   ------------------*/
457 extern VOID TW3Dperspective(P5(DOUBLE x, DOUBLE y, DOUBLE z, DOUBLE *pX, DOUBLE *pY));
458 /*
459   Perform a 3D transformation.
460 */
461 
462 extern VOID TW3DperspectiveOn() ;
463 /*
464 Function:
465     Turn on the 3D perspective.  Make things farther away smaller.
466 */
467 
468 extern VOID TW3DperspectiveOff() ;
469 /*
470 Function:
471     Turns off the 3D perspective.
472 */
473 
474 /* TW3DdrawLine( INT ref_num, INT x1, INT y1, INT z1,
475 		 INT x2, INT y2, INT z2, INT color, char *label) */
476 /*
477 Function:
478     Draws a line in 3 dimensions.
479 */
480 
481 extern void TW3DdrawCube( P9(INT ref_num, INT x1, INT y1, INT z1,
482     INT x2, INT y2, INT z2, INT color, char *label ) ) ;
483 /*
484 Function:
485     Draws a 3 dimensional cube.
486 */
487 
488 /* TW3Darb_init()  */
489 /*
490 Function:
491     Starts an arbitrary figure in 3 dimensions.
492 */
493 
494 /* TW3Darb_addptr()  */
495 /*
496 Function:
497     Adds another point to current arbitrary figure in 3D.
498 */
499 
500 /* TW3DdrawArb( INT ref, INT color, char *label )  */
501 /*
502 Function:
503     Finished arbitrary point and draws it to the screen.
504 */
505 
506 extern void TWarb_fill( P1(BOOL flag ) ) ;
507 /*
508 Function:
509     If flag is true, arbitrary figures (both 2D and 3D) will be filled.
510     Otherwise, no fill will be added.
511 */
512 
513 BOOL TWget_arb_fill();
514 
515 #endif /* DRAW_H */
516