1 /* NMundo.c -
2 *
3 * Provides procedures and data structures to make net-list
4 * modifications undo-able.
5 *
6 * *********************************************************************
7 * * Copyright (C) 1985, 1990 Regents of the University of California. *
8 * * Permission to use, copy, modify, and distribute this *
9 * * software and its documentation for any purpose and without *
10 * * fee is hereby granted, provided that the above copyright *
11 * * notice appear in all copies. The University of California *
12 * * makes no representations about the suitability of this *
13 * * software for any purpose. It is provided "as is" without *
14 * * express or implied warranty. Export of this software outside *
15 * * of the United States of America may require an export license. *
16 * *********************************************************************
17 */
18
19 #ifndef lint
20 static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/netmenu/NMundo.c,v 1.1.1.1 2008/02/03 20:43:50 tim Exp $";
21 #endif /* not lint */
22
23 #include <stdio.h>
24 #include <string.h>
25
26 #include "utils/magic.h"
27 #include "utils/geometry.h"
28 #include "windows/windows.h"
29 #include "netmenu/netmenu.h"
30 #include "netmenu/nmInt.h"
31 #include "utils/undo.h"
32 #include "utils/utils.h"
33
34 /* Handle for our kind of undo operation. */
35
36 static UndoType nmUndoClientID;
37
38 /* The following structure describes undo information about a
39 * single net-list undo event.
40 */
41
42 typedef struct
43 {
44 int nmue_type; /* Type of undo event; see the header for
45 * NMUndo for a description.
46 */
47 char *nmue_term; /* A name of a terminal or new net-list. */
48 char *nmue_curNet; /* Name of current net or net-list. */
49 char nmue_storage[4]; /* Used to store the actual strings for
50 * nmue_term and nmue_curNet. May have
51 * any length.
52 */
53 } NMUndoEvent;
54
55 /* The following variable merely records whether any net-list-related
56 * undo events have been processed.
57 */
58
59 bool nmUndoCalled = FALSE;
60
61 /*
62 * ----------------------------------------------------------------------------
63 *
64 * NMUndo --
65 *
66 * Records an undo event. Type selects which of three net-list
67 * modifications is being recorded:
68 * NMUE_ADD: term was added to the net of curNet
69 * NMUE_REMORE: term was removed from net of curNet
70 * NMUE_SELECT: the net of term replaces the net of curNet as
71 * current net.
72 * NMUE_NETLIST: term is used as the name of a new current net-list
73 * which replaces the current net-list, given by
74 * curNet.
75 *
76 * Results:
77 * None.
78 *
79 * Side effects:
80 * An event is added to the undo list, so that the modifications
81 * can be undone and/or redone later.
82 *
83 * ----------------------------------------------------------------------------
84 */
85
86 void
NMUndo(term,curNet,type)87 NMUndo(term, curNet, type)
88 char *term; /* A name of a terminal. */
89 char *curNet; /* The name of the current net-list. */
90 int type; /* The type of thing that is being logged */
91 {
92 NMUndoEvent *u;
93 int l1, l2;
94
95 if (term != NULL) l1 = strlen(term);
96 else l1 = 0;
97 if (curNet != NULL) l2 = strlen(curNet);
98 else l2 = 0;
99
100 u = (NMUndoEvent *) UndoNewEvent(nmUndoClientID,
101 (unsigned) (sizeof(NMUndoEvent) + l1 + l2 + 2));
102 if (u == NULL) return;
103
104 u->nmue_type = type;
105 if (term != NULL)
106 {
107 u->nmue_term = u->nmue_storage;
108 (void) strcpy(u->nmue_term, term);
109 }
110 else u->nmue_term = NULL;
111 if (curNet != NULL)
112 {
113 u->nmue_curNet = u->nmue_storage + l1 + 1;
114 (void) strcpy(u->nmue_curNet, curNet);
115 }
116 else u->nmue_curNet = NULL;
117 }
118
119 /*
120 * ----------------------------------------------------------------------------
121 *
122 * nmUndoForw --
123 * nmUndoBack --
124 *
125 * These procedures play net-list undo events forward or backwards.
126 *
127 * Results:
128 * None.
129 *
130 * Side effects:
131 * A net is modified or the current net is changed.
132 *
133 * ----------------------------------------------------------------------------
134 */
135
136 void
nmUndoForw(u)137 nmUndoForw(u)
138 NMUndoEvent *u; /* Pointer to an undo event. */
139 {
140 nmUndoCalled = TRUE;
141 switch (u->nmue_type)
142 {
143 case NMUE_ADD:
144 (void) NMAddTerm(u->nmue_term, u->nmue_curNet);
145 break;
146 case NMUE_REMOVE:
147 (void) NMDeleteTerm(u->nmue_term);
148 break;
149 case NMUE_SELECT:
150 (void) NMSelectNet(u->nmue_term);
151 break;
152 case NMUE_NETLIST:
153 (void) NMNewNetlist(u->nmue_term);
154 break;
155 }
156 }
157
158 void
nmUndoBack(u)159 nmUndoBack(u)
160 NMUndoEvent *u; /* Pointer to an undo event. */
161 {
162 nmUndoCalled = TRUE;
163 switch(u->nmue_type)
164 {
165 case NMUE_ADD:
166 (void) NMDeleteTerm(u->nmue_term);
167 break;
168 case NMUE_REMOVE:
169 (void) NMAddTerm(u->nmue_term, u->nmue_curNet);
170 break;
171 case NMUE_SELECT:
172 (void) NMSelectNet(u->nmue_curNet);
173 break;
174 case NMUE_NETLIST:
175 (void) NMNewNetlist(u->nmue_curNet);
176 break;
177 }
178 }
179
180 /*
181 * ----------------------------------------------------------------------------
182 *
183 * nmUndoDone --
184 *
185 * This procedure is called at the very end of undoing or
186 * redoing something. It just redisplays the current net
187 * if there have been any net-list-related events processed.
188 *
189 * Results:
190 * None.
191 *
192 * Side effects:
193 * The current net is redisplayed.
194 *
195 * ----------------------------------------------------------------------------
196 */
197
198 void
nmUndoDone()199 nmUndoDone()
200 {
201 if (nmUndoCalled)
202 {
203 UndoDisable();
204 NMSelectNet(NMCurNetName);
205 UndoEnable();
206 }
207 nmUndoCalled = FALSE;
208 }
209
210 /*
211 * ----------------------------------------------------------------------------
212 *
213 * NMUndoInit --
214 *
215 * Sets up this module to handle undo-ing and redo-ing of net-list
216 * stuff.
217 *
218 * Results:
219 * None.
220 *
221 * Side effects:
222 * Stuff gets initialized in the undo package.
223 *
224 * ----------------------------------------------------------------------------
225 */
226
227 void
NMUndoInit()228 NMUndoInit()
229 {
230 nmUndoClientID = UndoAddClient((void (*)()) NULL, nmUndoDone,
231 (UndoEvent *(*)()) NULL, (int (*)()) NULL,
232 nmUndoForw, nmUndoBack, "net-list");
233 }
234