1 /* NMshowcell.c -
2  *
3  *	This file provides procedures that highlight all the paint
4  *	in a given cell by drawing it on the highlight layer.  It
5  *	is used for things like displaying all the wiring in a net,
6  *	or for displaying splotches around labels with a given name.
7  *
8  *     *********************************************************************
9  *     * Copyright (C) 1985, 1990 Regents of the University of California. *
10  *     * Permission to use, copy, modify, and distribute this              *
11  *     * software and its documentation for any purpose and without        *
12  *     * fee is hereby granted, provided that the above copyright          *
13  *     * notice appear in all copies.  The University of California        *
14  *     * makes no representations about the suitability of this            *
15  *     * software for any purpose.  It is provided "as is" without         *
16  *     * express or implied warranty.  Export of this software outside     *
17  *     * of the United States of America may require an export license.    *
18  *     *********************************************************************
19  */
20 
21 #ifndef lint
22 static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/netmenu/NMshowcell.c,v 1.1.1.1 2008/02/03 20:43:50 tim Exp $";
23 #endif  /* not lint */
24 
25 #include <stdio.h>
26 
27 #include "utils/magic.h"
28 #include "utils/geometry.h"
29 #include "tiles/tile.h"
30 #include "utils/hash.h"
31 #include "database/database.h"
32 #include "windows/windows.h"
33 #include "graphics/graphics.h"
34 #include "dbwind/dbwind.h"
35 #include "utils/styles.h"
36 #include "textio/textio.h"
37 #include "utils/main.h"
38 #include "select/select.h"
39 #include "netmenu/nmInt.h"
40 
41 /* The following owns describe the cell currently being highlighted,
42  * and the root cell that identifies windows in which the highlighting
43  * is to occur.  The cell's coordinate system is assumed to be the
44  * same as the coordinate system of the root cell.
45  */
46 
47 static CellUse *nmscUse = NULL;
48 static CellDef *nmscRootDef = NULL;	/* NULL means no cell currently
49 					 * being highlighted.
50 					 */
51 
52 /* The use and def below are used for highlighting nets and
53  * labels.
54  */
55 
56 static CellUse *nmscShowUse = NULL;
57 static CellDef *nmscShowDef = NULL;
58 
59 /*
60  * ----------------------------------------------------------------------------
61  *
62  * NMRedrawCell --
63  *
64  * 	This procedure is invoked by the highlight code to redraw
65  *	the highlights managed by this file.  The window has been
66  *	already locked by the highlight code.
67  *
68  * Results:
69  *	None.
70  *
71  * Side effects:
72  *	Highlights are redrawn, if there is a cell to be highlighted
73  *	and if it contains information in the area to be redrawn.
74  *
75  * ----------------------------------------------------------------------------
76  */
77 
78 static Plane *nmscPlane;	/* Shared between procs below. */
79 extern int nmscRedrawFunc();	/* Forward declaration. */
80 
81 int
NMRedrawCell(window,plane)82 NMRedrawCell(window, plane)
83     MagWindow *window;		/* Window in which to redisplay. */
84     Plane *plane;		/* Non-space tiles on this plane indicate,
85 				 * in root cell coordinates, the areas where
86 				 * highlight information must be redrawn.
87 				 */
88 {
89     int i;
90     Rect area;
91 
92     /* Make sure that cell highlights are supposed to appear in
93      * this window.
94      */
95 
96     if (((CellUse *)(window->w_surfaceID))->cu_def != nmscRootDef) return 0;
97 
98     /* If this window is zoomed way out (less than 1 pixel per lambda)
99      * use solid highlighting to maximize visibility.  It the window
100      * is at a reasonably high magnification, then use a paler stipple
101      * so that the material type is easy to see through the highlighting.
102      */
103 
104     if (window->w_scale > SUBPIXEL)
105 	GrSetStuff(STYLE_PALEHIGHLIGHTS);
106     else
107 	GrSetStuff(STYLE_SOLIDHIGHLIGHTS);
108 
109     /* Find all paint on all layers in the area where we may have to
110      * redraw.
111      */
112 
113     if (!DBBoundPlane(plane, &area)) return 0;
114     nmscPlane = plane;
115     for (i = PL_TECHDEPBASE; i < DBNumPlanes; i += 1)
116     {
117 	(void) DBSrPaintArea((Tile *) NULL, nmscUse->cu_def->cd_planes[i],
118 	    &area, &DBAllButSpaceAndDRCBits,
119 	    nmscRedrawFunc, (ClientData) window);
120     }
121     return 0;
122 }
123 
124 int
nmscRedrawFunc(tile,window)125 nmscRedrawFunc(tile, window)
126     Tile *tile;			/* Tile to be redisplayed on highlight layer.*/
127     MagWindow *window;		/* Window in which to redisplay. */
128 {
129     Rect area, screenArea;
130     extern int nmscAlways1();	/* Forward reference. */
131 
132     TiToRect(tile, &area);
133     if (!DBSrPaintArea((Tile *) NULL, nmscPlane, &area,
134 	    &DBAllButSpaceBits, nmscAlways1, (ClientData) NULL))
135 	return 0;
136     WindSurfaceToScreen(window, &area, &screenArea);
137     GrFastBox(&screenArea);
138     return 0;
139 }
140 
141 int
nmscAlways1()142 nmscAlways1()
143 {
144     return 1;
145 }
146 
147 /*
148  * ----------------------------------------------------------------------------
149  *
150  * NMUnsetCell --
151  *
152  * 	This procedure causes us to forget about the cell currently
153  *	being highlighted, and erase the highlights from the screen.
154  *
155  * Results:
156  *	None.
157  *
158  * Side effects:
159  *	From now on, no cell will be highlighted.  The screen is
160  *	redrawn to remove existing cell highlights.
161  *
162  * ----------------------------------------------------------------------------
163  */
164 
165 void
NMUnsetCell()166 NMUnsetCell()
167 {
168     CellDef *oldDef;
169 
170     if (nmscRootDef == NULL) return;
171     oldDef = nmscRootDef;
172     nmscRootDef = NULL;
173     DBWHLRedraw(oldDef, &nmscUse->cu_def->cd_bbox, TRUE);
174 }
175 
176 /*
177  * ----------------------------------------------------------------------------
178  *
179  * NMShowCell --
180  *
181  * 	This procedure sets up a particular cell to be highlighted,
182  *	and draws its paint on the highlight layer.
183  *
184  * Results:
185  *	None.
186  *
187  * Side effects:
188  *	If there was already a cell being highlighted, it is unset
189  *	and erased.  Then the new cell is remembered, and the screen
190  *	is redisplayed.
191  *
192  * Notes:
193  *	When using this, make sure the highlight use's bounds are
194  *	properly recomputed.
195  *
196  * ----------------------------------------------------------------------------
197  */
198 
199 void
NMShowCell(use,rootDef)200 NMShowCell(use, rootDef)
201     CellUse *use;		/* Cell whose contents are to be drawn
202 				 * on the highlight plane.
203 				 */
204     CellDef *rootDef;		/* Highlights will appear in all windows
205 				 * with this root definition.
206 				 */
207 {
208     if (nmscRootDef != NULL) NMUnsetCell();
209     nmscRootDef = rootDef;
210     nmscUse = use;
211     DBWHLRedraw(nmscRootDef, &nmscUse->cu_def->cd_bbox, FALSE);
212 }
213 
214 /*
215  * ----------------------------------------------------------------------------
216  *
217  *  nmGetShowCell --
218  *
219  * 	This procedure makes sure that nmscShowUse and nmscShowDef
220  *	have been properlay initialized to refer to a cell definition
221  *	named "__SHOW__".
222  *
223  * Results:
224  *	None.
225  *
226  * Side effects:
227  *	A new cell use and/or def are created if necessary.
228  *
229  * ----------------------------------------------------------------------------
230  */
231 
232 void
nmGetShowCell()233 nmGetShowCell()
234 {
235     if (nmscShowUse != NULL) return;
236     nmscShowDef = DBCellLookDef("__SHOW__");
237     if (nmscShowDef == NULL)
238     {
239 	nmscShowDef = DBCellNewDef("__SHOW__");
240 	ASSERT (nmscShowDef != (CellDef *) NULL, "nmGetShowCell");
241 	DBCellSetAvail(nmscShowDef);
242 	nmscShowDef->cd_flags |= CDINTERNAL;
243     }
244     nmscShowUse = DBCellNewUse(nmscShowDef, (char *) NULL);
245     DBSetTrans(nmscShowUse, &GeoIdentityTransform);
246     nmscShowUse->cu_expandMask = CU_DESCEND_SPECIAL;
247 }
248 
249 /*
250  * ----------------------------------------------------------------------------
251  *
252  * NMShowUnderBox --
253  *
254  * 	This procedure copies into the show cell all paint connected to
255  *	anything underneath the box.  The show cell is then highlighted.
256  *
257  * Results:
258  *	None.
259  *
260  * Side effects:
261  *	Any previous highlighted cell is unset, and any previous contents
262  *	of the show cell are destroyed.
263  *
264  * ----------------------------------------------------------------------------
265  */
266 
267 void
NMShowUnderBox()268 NMShowUnderBox()
269 {
270     CellDef *rootDef;
271     MagWindow *w;
272     SearchContext scx;
273 
274     NMUnsetCell();
275     nmGetShowCell();
276 
277     w = ToolGetBoxWindow(&scx.scx_area, (int *) NULL); if (w == NULL)
278     {
279 	TxError("There's no box!  Please use the box to select one\n");
280 	TxError("or more nets to be highlighted.\n");
281 	return;
282     }
283 
284     scx.scx_use = (CellUse *) w->w_surfaceID;
285     scx.scx_trans = GeoIdentityTransform;
286 
287     /* Expand the box area by one so we'll get everything that even
288      * touches it.
289      */
290 
291     GEO_EXPAND(&scx.scx_area, 1, &scx.scx_area);
292     rootDef = scx.scx_use->cu_def;
293 
294     DBWAreaChanged(nmscShowDef, &nmscShowDef->cd_bbox, DBW_ALLWINDOWS,
295 	&DBAllButSpaceBits);
296     DBCellClearDef(nmscShowUse->cu_def);
297     DBTreeCopyConnect(&scx, &DBAllButSpaceAndDRCBits, 0,
298 	    DBConnectTbl, &TiPlaneRect, SEL_DO_LABELS, nmscShowUse);
299     DBWAreaChanged(nmscShowDef, &nmscShowDef->cd_bbox, DBW_ALLWINDOWS,
300 	&DBAllButSpaceBits);
301     NMShowCell(nmscShowUse, rootDef);
302 }
303 
304 /*
305  * ----------------------------------------------------------------------------
306  *
307  * NMShowRoutedNet --
308  *
309  * 	This procedure copies into the show cell all paint connected to
310  *	any terminal of the currently selected net.  The show cell is then
311  *	highlighted.  If an argument is given, that net is selected and then
312  *	highlighted, instead.
313  *
314  * Results:
315  *	None.
316  *
317  * Side effects:
318  *	Any previous highlighted cell is unset, and any previous contents
319  *	of the show cell are destroyed.
320  *
321  * ----------------------------------------------------------------------------
322  */
323 
324 int
NMShowRoutedNet(netName)325 NMShowRoutedNet(netName)
326     char * netName;
327 {
328     int nmShowRoutedNetFunc();
329 
330     if (netName == NULL)
331     {
332 	if (NMCurNetName == NULL)
333 	{
334 	    TxError("You must select a net before you can trace it.\n");
335 	    return 0;
336 	}
337 	else netName = NMCurNetName;
338     }
339     NMUnsetCell();
340     nmGetShowCell();
341     DBWAreaChanged(nmscShowDef, &nmscShowDef->cd_bbox, DBW_ALLWINDOWS,
342 	 &DBAllButSpaceBits);
343     DBCellClearDef(nmscShowUse->cu_def);
344     NMSelectNet(netName);
345     if(NMCurNetName==NULL)
346     {
347 	TxError("The net list has no net containing the terminal \"%s\"\n",
348 	    netName);
349 	return 0;
350     }
351     (void) NMEnumTerms(NMCurNetName, nmShowRoutedNetFunc,
352 	    (ClientData) EditCellUse);
353     DBWAreaChanged(nmscShowDef, &nmscShowDef->cd_bbox, DBW_ALLWINDOWS,
354 	&DBAllButSpaceBits);
355     NMShowCell(nmscShowUse, EditCellUse->cu_def);
356     return 0;
357 }
358 
359 /*
360  * ----------------------------------------------------------------------------
361  *
362  * nmShowRoutedNetFunc --
363  *
364  * 	This procedure simply calls nmSRNFunc with the name of a terminal.
365  *
366  * Results:
367  *	Returns 0.
368  *
369  * Side effects:
370  *	Paints into the highlight cell.
371  *
372  * ----------------------------------------------------------------------------
373  */
374 int
nmShowRoutedNetFunc(name,clientData)375 nmShowRoutedNetFunc(name, clientData)
376     char *name;
377     ClientData clientData;
378 {
379     int nmSRNFunc();
380 
381     (void) DBSrLabelLoc((CellUse *) clientData, name, nmSRNFunc, clientData);
382     return(0);
383 }
384 
385 /*
386  * ----------------------------------------------------------------------------
387  *
388  * nmSRNFunc --
389  *
390  *	This procedure copies into the show cell all paint connected to
391  *	anything underneath the terminal.
392  *
393  * Results:
394  *	Returns 0.
395  *
396  * Side effects:
397  *	None.
398  *
399  * ----------------------------------------------------------------------------
400  */
401 
402     /*ARGSUSED*/
403 int
nmSRNFunc(rect,name,label,cdarg)404 nmSRNFunc(rect, name, label, cdarg)
405     Rect *rect;
406     char *name;		/* Unused */
407     Label *label;
408     ClientData cdarg;
409 {
410     SearchContext scx;
411 
412     /* Expand the box area by one so we'll get everything that even
413      * touches it.  Search on layers connected to the layer of the label.
414      */
415 
416     scx.scx_area = *rect;
417     GEO_EXPAND(&scx.scx_area, 1, &scx.scx_area);
418     scx.scx_use = (CellUse *) cdarg;
419     scx.scx_trans = GeoIdentityTransform;
420 
421     DBTreeCopyConnect(&scx, &DBConnectTbl[label->lab_type], 0,
422 	    DBConnectTbl, &TiPlaneRect, SEL_DO_LABELS, nmscShowUse);
423     return(0);
424 }
425