1 /*****************************************************************************
2 FILE : $Source: /projects/higgs1/SNNS/CVS/SNNS/xgui/sources/ui_display.c,v $
3 SHORTNAME : display.c
4 SNNS VERSION : 4.2
5
6 PURPOSE : contains routines to handle the list of all network displays
7 NOTES :
8
9 AUTHOR : Tilman Sommer
10 DATE : 26.7.1990
11
12 CHANGED BY :
13
14 RCS VERSION : $Revision: 2.7 $
15 LAST CHANGE : $Date: 1998/03/03 14:10:19 $
16
17 Copyright (c) 1990-1995 SNNS Group, IPVR, Univ. Stuttgart, FRG
18 Copyright (c) 1996-1998 SNNS Group, WSI, Univ. Tuebingen, FRG
19
20 ******************************************************************************/
21 #include <config.h>
22
23 #include <stdio.h>
24 #include <stdlib.h>
25
26 #include "ui.h"
27 #include "ui_utilP.h"
28 #include "ui_funcdispl.h"
29 #include "ui_netUpdate.h"
30 #include "ui_setupP.h"
31 #include "ui_setup.h"
32 #include "ui_mainP.h"
33
34 #include "ui_display.ph" /* private include-file */
35
36
37 /*****************************************************************************
38 FUNCTION : ui_displ_createItem
39
40 PURPOSE : allocate size for one item from the heap and set default values
41 RETURNS : pointer to that new item
42 NOTES :
43
44 UPDATES :
45 *****************************************************************************/
46
ui_displ_createItem(void)47 static struct Ui_DisplayType *ui_displ_createItem(void)
48
49 {
50 struct Ui_DisplayType *displPtr;
51
52 displPtr = (struct Ui_DisplayType *) malloc(sizeof(struct Ui_DisplayType));
53 if (displPtr != NULL) {
54 (*displPtr).x = 1;
55 (*displPtr).y = 1;
56 (*displPtr).origin.x = 0;
57 (*displPtr).origin.y = 0;
58 (*displPtr).width = 450;
59 (*displPtr).height = 300;
60 (*displPtr).gridSize = 37;
61 (*displPtr).unitsInX = (*displPtr).width / (*displPtr).gridSize;
62 (*displPtr).unitsInY = (*displPtr).height / (*displPtr).gridSize;
63 (*displPtr).frozen = FALSE;
64 (*displPtr).subNetNo = 0;
65 (*displPtr).layers = 1;
66 ui_set_initData(displPtr);
67 (*displPtr).updateType = UI_INTELLIGENT;
68 (*displPtr).flags = UI_CLOSED + 1; /*!*/ /* mapped */
69 (*displPtr).nextPtr = NULL;
70 (*displPtr).displayNo = ui_displ_numberOfItems;
71 }
72 return (displPtr);
73 }
74
75
76 /*****************************************************************************
77 FUNCTION : ui_displ_initDisplayList
78
79 PURPOSE : initialize the Display list and Display counters
80 RETURNS : void
81 NOTES :
82
83 UPDATES :
84 *****************************************************************************/
85
ui_displ_initDisplayList(void)86 void ui_displ_initDisplayList(void)
87
88 {
89 ui_displ_numberOfItems = 1;
90 ui_displ_listPtr = NULL;
91 ui_displ_freeListPtr = ui_displ_createItem();
92 ui_currentDisplay = ui_displ_listPtr;
93 ui_displ_numberOfItems = 0;
94 }
95
96
97 /*****************************************************************************
98 FUNCTION : ui_displ_resetList
99
100 PURPOSE : links all items in the free list and closes the displays
101 RETURNS : void
102 NOTES :
103
104 UPDATE :
105 *****************************************************************************/
106
ui_displ_resetList(void)107 void ui_displ_resetList(void)
108
109 {
110 struct Ui_DisplayType *displPtr;
111
112 while (ui_displ_listPtr != NULL) {
113 displPtr = ui_displ_listPtr;
114 ui_displayDone(NULL, displPtr, NULL);
115 /* ui_displ_freeItem() is performed in ui_displayDone() ! */
116 }
117 }
118
119
120 /*****************************************************************************
121 FUNCTION : ui_displ_freeItem
122
123 PURPOSE : links the item in the free list
124 RETURNS : void
125 NOTES :
126
127 UPDATES :
128 *****************************************************************************/
129
ui_displ_freeItem(struct Ui_DisplayType * displayPtr)130 void ui_displ_freeItem(struct Ui_DisplayType *displayPtr)
131
132 {
133 struct Ui_DisplayType *displPtr;
134
135 if (ui_displ_listPtr == displayPtr) { /* is first element */
136 ui_displ_listPtr = displayPtr->nextPtr;
137 displayPtr->nextPtr = ui_displ_freeListPtr;
138 ui_displ_freeListPtr = displayPtr;
139 ui_displ_numberOfItems -= 1;
140 } else { /* second, third, ... element */
141 displPtr = ui_displ_listPtr;
142 while ((displPtr->nextPtr != displayPtr) AND
143 (displPtr->nextPtr != NULL))
144 displPtr = displPtr->nextPtr;
145
146 if (displPtr->nextPtr == displayPtr) { /* item was found */
147 displPtr->nextPtr = displayPtr->nextPtr;
148 displayPtr->nextPtr = ui_displ_freeListPtr;
149 ui_displ_freeListPtr = displayPtr;
150 ui_displ_numberOfItems -= 1;
151 }
152 }
153 }
154
155
156 /*****************************************************************************
157 FUNCTION : Ui_DisplayType
158
159 PURPOSE : looks in the free list for an item. If no one is found,
160 ui_displ_createItem() is called to create a new one.
161 RETURNS : a pointer to a free item or NULL if malloc() fails
162 NOTES :
163
164 UPDATES :
165 *****************************************************************************/
166
ui_displ_getFreeItem(void)167 struct Ui_DisplayType *ui_displ_getFreeItem(void)
168
169 {
170 struct Ui_DisplayType *displPtr;
171
172 ui_displ_numberOfItems++;
173 if (ui_displ_freeListPtr == NULL) { /* no free item */
174 displPtr = ui_displ_createItem(); /* create a new item */
175 } else {
176 displPtr = ui_displ_freeListPtr;
177 ui_displ_freeListPtr = displPtr->nextPtr;
178 }
179 if (displPtr != NULL) {
180 /* link it in the list as the first element */
181 (*displPtr).nextPtr = ui_displ_listPtr;
182 ui_displ_listPtr = displPtr;
183 }
184 return(displPtr);
185 }
186
187
188 #ifdef _UNUSED_FUNCTIONS_
189
190 /*****************************************************************************
191 FUNCTION : ui_displ_getDisplayPtrViaDrawable
192
193 PURPOSE : search through the display list for a display with the specified
194 drawable ID
195 RETURNS : struct Ui_DisplayType
196 NOTES : !!! function is not used yet
197
198 UPDATE : 1.2.1990
199 ******************************************************************************/
200
201 /*!*/ /* not used */
ui_displ_getDisplayPtrViaDrawable(Widget w)202 static struct Ui_DisplayType *ui_displ_getDisplayPtrViaDrawable(Widget w)
203
204
205 {
206 struct Ui_DisplayType *dPtr;
207
208 dPtr = ui_displ_listPtr;
209 while((dPtr != NULL) AND (dPtr->widget != w))
210 dPtr = dPtr->nextPtr;
211
212 return(dPtr);
213 }
214
215 #endif /* _UNUSED_FUNCTIONS_ */
216
217
218 #ifdef _UNUSED_FUNCTIONS_
219
220 /*****************************************************************************
221 FUNCTION : ui_displ_getDisplayPtrViaFrameWidget
222
223 PURPOSE : search through the display list for a display with the specified
224 frame widget
225 RETURNS : struct Ui_DisplayType
226 NOTES : !!! function is not used yet
227
228 UPDATE : 1.2.1990
229 ******************************************************************************/
230
231 /*!*/ /* not used */
ui_displ_getDisplayPtrViaFrameWidget(Widget w)232 static struct Ui_DisplayType *ui_displ_getDisplayPtrViaFrameWidget(Widget w)
233
234 {
235 struct Ui_DisplayType *dPtr;
236
237 dPtr = ui_displ_listPtr;
238 while((dPtr != NULL) AND (dPtr->frameWidget != w))
239 dPtr = dPtr->nextPtr;
240
241 return(dPtr);
242 }
243
244 #endif /* _UNUSED_FUNCTIONS_ */
245
246
247 /*****************************************************************************
248 FUNCTION : ui_displ_isSomeWhereToShowWeights
249
250 PURPOSE : Returns TRUE if there is to show the weights of links
251 in any display.
252 RETURNS : Bool
253 NOTES :
254
255 UPDATE : 1.2.1990
256 ******************************************************************************/
257
ui_displ_isSomeWhereToShowWeights(void)258 Bool ui_displ_isSomeWhereToShowWeights(void)
259
260 {
261 struct Ui_DisplayType *dPtr;
262
263 dPtr = ui_displ_listPtr;
264 while((dPtr != NULL)) {
265 if (dPtr->setup.showWeightFlg) return(TRUE);
266 dPtr = dPtr->nextPtr;
267 }
268 return(FALSE);
269 }
270
271
272 /*****************************************************************************
273 FUNCTION : ui_displ_isSomeWhereToShowValues
274
275 PURPOSE : Returns TRUE if there is to show the unit value numerically
276 in any display.
277 RETURNS : Bool
278 NOTES :
279
280 UPDATE : 1.2.1990
281 ******************************************************************************/
282
ui_displ_isSomeWhereToShowValues(void)283 Bool ui_displ_isSomeWhereToShowValues(void)
284
285 {
286 struct Ui_DisplayType *dPtr;
287
288 dPtr = ui_displ_listPtr;
289 while((dPtr != NULL)) {
290 if (dPtr->setup.showValueFlg) return(TRUE);
291 dPtr = dPtr->nextPtr;
292 }
293 return(FALSE);
294 }
295
296
297 /*****************************************************************************
298 FUNCTION : ui_displ_freezeDisplay
299
300 PURPOSE : sets the freeze flag in the display structure
301 RETURNS : void
302 NOTES :
303
304 UPDATES :
305 *****************************************************************************/
306
ui_displ_freezeDisplay(Widget w,struct Ui_DisplayType * displayPtr,caddr_t call_data)307 void ui_displ_freezeDisplay(Widget w, struct Ui_DisplayType *displayPtr,
308 caddr_t call_data)
309
310 {
311 displayPtr->frozen = NOT displayPtr->frozen;
312 ui_net_completeRefresh(displayPtr, UI_LOCAL);
313 }
314
315
316
317
318
319
320 /* end of file */
321 /* lines: 301 */
322