~ubuntu-branches/ubuntu/trusty/geda-gsymcheck/trusty

« back to all changes in this revision

Viewing changes to src/s_project.c

  • Committer: Bazaar Package Importer
  • Author(s): Hamish Moffatt
  • Date: 2005-03-15 23:03:40 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050315230340-se821zvek59ipkz9
Tags: 20050313-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* gEDA - GPL Electronic Design Automation
2
 
 * gsymcheck - gEDA Symbol Check
3
 
 * Copyright (C) 1998-2000 Ales V. Hvezda
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License as published by
7
 
 * the Free Software Foundation; either version 2 of the License, or
8
 
 * (at your option) any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
 
 */
19
 
 
20
 
#include <config.h>
21
 
#include <stdio.h>
22
 
#include <signal.h>
23
 
 
24
 
#include <libgeda/libgeda.h>
25
 
 
26
 
#include "../include/papersizes.h"
27
 
#include "../include/prototype.h"
28
 
 
29
 
 
30
 
/* global_wid always increments, it needs to be unique per gsymcheck run */
31
 
static int num_projects=0;
32
 
static int global_wid=0;
33
 
 
34
 
/* head pointer to window structure, this points to all the windows that
35
 
   currently exist */
36
 
static TOPLEVEL *project_head=NULL; 
37
 
static TOPLEVEL *project_tail=NULL; 
38
 
 
39
 
/* add to the end of the list */
40
 
TOPLEVEL *
41
 
s_project_add(TOPLEVEL *w_head, TOPLEVEL *pr_current)
42
 
{
43
 
        if (w_head == NULL) {
44
 
                pr_current->prev = NULL;
45
 
                pr_current->next = NULL;
46
 
                return(pr_current);     
47
 
        } else {
48
 
                pr_current->prev = w_head;
49
 
                pr_current->next = NULL;
50
 
                w_head->next = pr_current;
51
 
                return(w_head->next);
52
 
        }
53
 
}
54
 
 
55
 
void
56
 
s_project_add_head()
57
 
{
58
 
        project_tail = project_head = (TOPLEVEL *) malloc(sizeof(TOPLEVEL));            
59
 
        project_head->wid = -1;
60
 
}
61
 
 
62
 
void
63
 
s_project_free_head()
64
 
{
65
 
        free(project_head);
66
 
}
67
 
 
68
 
/* deletes specified window from w_head list */ 
69
 
/* doesn't do the actual destroy though */
70
 
void
71
 
s_project_delete(TOPLEVEL *w_head, TOPLEVEL *pr_current) 
72
 
{
73
 
 
74
 
        if (w_head == NULL || pr_current == NULL) {
75
 
                /* error condition hack */
76
 
                return;
77
 
        }
78
 
 
79
 
        if (pr_current->next)
80
 
                pr_current->next->prev = pr_current->prev;      
81
 
        
82
 
        if (pr_current->prev)
83
 
                pr_current->prev->next = pr_current->next;
84
 
 
85
 
        s_page_free_all(pr_current, pr_current->page_tail); 
86
 
 
87
 
}
88
 
 
89
 
void
90
 
s_project_setup_world(TOPLEVEL *pr_current)
91
 
{
92
 
        pr_current->init_left = 0;
93
 
        pr_current->init_top = 0;
94
 
        /* init_right and _bottom are set before this function is called */
95
 
        pr_current->min_zoom = 0;
96
 
        pr_current->max_zoom = 8;    
97
 
 
98
 
 
99
 
/* part of page mechanism addition commented out
100
 
        pr_current->zoom_factor = 0;
101
 
*/
102
 
}
103
 
 
104
 
void
105
 
s_project_setup_rest(TOPLEVEL *pr_current)
106
 
{
107
 
        pr_current->num_untitled=0;
108
 
 
109
 
        pr_current->start_x=-1;
110
 
        pr_current->start_y=-1;
111
 
        pr_current->save_x=-1;
112
 
        pr_current->save_y=-1;
113
 
        pr_current->last_x=-1;
114
 
        pr_current->last_y=-1;
115
 
        pr_current->loc_x=-1;
116
 
        pr_current->loc_y=-1;
117
 
        pr_current->distance=-1;
118
 
        pr_current->event_state=-1;
119
 
        pr_current->inside_action=0;
120
 
        pr_current->snap=1;
121
 
        pr_current->grid=1;             
122
 
 
123
 
        pr_current->current_attribute=NULL;
124
 
        pr_current->current_visible=-1; /* not sure on these */
125
 
        pr_current->current_show=-1;
126
 
 
127
 
        pr_current->internal_basename=NULL;
128
 
        pr_current->internal_clib=NULL;
129
 
 
130
 
        pr_current->series_name = NULL;
131
 
        pr_current->untitled_name = NULL;
132
 
        pr_current->font_directory = NULL;
133
 
        pr_current->scheme_directory = NULL;
134
 
 
135
 
/* part of page mechanism addition commented out 
136
 
        pr_current->zoom_factor=0;
137
 
*/
138
 
        pr_current->override_color=-1;
139
 
        pr_current->inside_redraw=0;
140
 
 
141
 
 
142
 
        /* Don't init these to zero here... once we are done with all init
143
 
         *  will these be inited to zero 
144
 
         * pr_current->DONT_DRAW_CONN=0;
145
 
         * pr_current->DONT_RESIZE=0;
146
 
         * pr_current->DONT_EXPOSE=0;
147
 
         * pr_current->DONT_RECALC=0;
148
 
         */
149
 
 
150
 
        pr_current->FORCE_CONN_UPDATE=0;
151
 
        pr_current->ADDING_SEL=0;
152
 
        pr_current->REMOVING_SEL=0;
153
 
 
154
 
        pr_current->drawbounding_action_mode=FREE;
155
 
        pr_current->last_drawb_mode = -1;
156
 
        pr_current->CONTROLKEY=0;
157
 
        pr_current->SHIFTKEY=0;
158
 
        pr_current->last_callback=NULL; 
159
 
        
160
 
        pr_current->cswindow = NULL;
161
 
        pr_current->aswindow = NULL;
162
 
        pr_current->fowindow = NULL;
163
 
        pr_current->fswindow = NULL;    
164
 
 
165
 
        pr_current->tiwindow = NULL;    
166
 
        pr_current->tewindow = NULL;    
167
 
        pr_current->exwindow = NULL;    
168
 
        pr_current->aawindow = NULL;    
169
 
        pr_current->trwindow = NULL;    
170
 
        pr_current->tswindow = NULL;    
171
 
        pr_current->pswindow = NULL;    
172
 
        pr_current->pwindow = NULL;     
173
 
        pr_current->abwindow = NULL;    
174
 
        pr_current->hkwindow = NULL;    
175
 
        pr_current->cowindow = NULL;    
176
 
 
177
 
        pr_current->coord_world = NULL;
178
 
        pr_current->coord_screen = NULL;
179
 
        /* pr_current->preview = NULL;experimental widget */
180
 
 
181
 
        pr_current->width = 1;
182
 
        pr_current->height = 1;
183
 
        pr_current->snap_size = 100;
184
 
 
185
 
        /* The following is an attempt at getting (deterministic) defaults */
186
 
        /* for the following variables */
187
 
        pr_current->attribute_promotion = FALSE;
188
 
        pr_current->promote_invisible = FALSE;
189
 
        pr_current->keep_invisible = FALSE;
190
 
}
191
 
 
192
 
/* stays the same */ 
193
 
TOPLEVEL *
194
 
s_project_create_new(void)
195
 
{
196
 
        TOPLEVEL *pr_current=NULL; 
197
 
 
198
 
        /* allocate new window structure */
199
 
        pr_current = (TOPLEVEL *) malloc(sizeof(TOPLEVEL));             
200
 
 
201
 
        pr_current->wid = global_wid;
202
 
 
203
 
        /* make sure none of these events happen till we are done */
204
 
#if 0
205
 
        pr_current->DONT_DRAW_CONN=1;
206
 
        pr_current->DONT_RESIZE=1;
207
 
        pr_current->DONT_EXPOSE=1;
208
 
        pr_current->DONT_RECALC=1;
209
 
#endif
210
 
        
211
 
        /* the default coord sizes */
212
 
        /* real ones set in rc file */
213
 
        pr_current->init_right = WIDTH_C; 
214
 
        pr_current->init_bottom = HEIGHT_C;
215
 
 
216
 
 
217
 
#if 0 /* X related stuff */
218
 
        pr_current->display_height = gdk_screen_height();
219
 
        pr_current->display_width = gdk_screen_width();
220
 
#endif
221
 
 
222
 
        s_project_setup_world(pr_current);      
223
 
 
224
 
#if 0 /* X related stuff */
225
 
        /* do X fill in first */
226
 
        s_project_create_main(pr_current);
227
 
#endif
228
 
 
229
 
        /* do other var fill in */
230
 
        s_project_setup_rest(pr_current);
231
 
 
232
 
        /* do default interface variables */
233
 
#if 0
234
 
        i_vars_setdefault(pr_current);
235
 
#endif
236
 
 
237
 
        /* Put head node on page list... be sure to free this somewhere hack */
238
 
        s_page_add_head(pr_current);
239
 
 
240
 
        /* Now create a blank page */
241
 
        pr_current->page_tail = s_page_add(pr_current,
242
 
                                          pr_current->page_tail, 
243
 
                                          "unknown"); 
244
 
                                        /* this is correct */
245
 
 
246
 
        s_page_setup(pr_current->page_tail);
247
 
 
248
 
        /* setup page_current link */
249
 
        pr_current->page_current = pr_current->page_tail;
250
 
 
251
 
        /* Special case init */
252
 
        /* move this elsewhere eventually */
253
 
        /* pr_current->page_current->object_parent=NULL; not this one */
254
 
#if 0
255
 
        pr_current->page_current->object_lastplace=NULL;
256
 
        pr_current->page_current->object_selected=NULL;
257
 
#endif
258
 
        set_window(pr_current, pr_current->init_left, pr_current->init_right, 
259
 
                   pr_current->init_top, pr_current->init_bottom);
260
 
 
261
 
#if 0 /* X related stuff */
262
 
        /* now update the scrollbars */
263
 
        x_hscrollbar_update(pr_current);
264
 
        x_vscrollbar_update(pr_current);
265
 
#endif
266
 
 
267
 
        global_wid++;
268
 
        num_projects++;
269
 
 
270
 
        project_tail = s_project_add(project_tail, pr_current); 
271
 
 
272
 
#if 0
273
 
        i_vars_setdefault(pr_current);
274
 
#endif
275
 
 
276
 
        /* no longer doing the old rc files */
277
 
        /* f_rc_parse(pr_current);*/
278
 
 
279
 
        g_rc_parse(pr_current);
280
 
 
281
 
        /* renable the events */
282
 
        pr_current->DONT_DRAW_CONN=0;
283
 
        pr_current->DONT_RESIZE=0;
284
 
        pr_current->DONT_EXPOSE=0;
285
 
        pr_current->DONT_RECALC=0;
286
 
 
287
 
        return(pr_current);
288
 
}
289
 
 
290
 
/* stays the same ???????????? */
291
 
void
292
 
s_project_close(TOPLEVEL *pr_current)
293
 
{
294
 
 
295
 
        /* make sure project_tail stays correct and doesn't dangle */
296
 
        /* project_head can't dangle since it has a head node, which is */
297
 
        /* NEVER deallocated (only at the very end) */
298
 
        if (project_tail == pr_current) {
299
 
                project_tail = pr_current->prev;
300
 
        }
301
 
        
302
 
 
303
 
        if (pr_current->series_name) {
304
 
                free(pr_current->series_name);
305
 
        }
306
 
 
307
 
        if (pr_current->untitled_name) {
308
 
                free(pr_current->untitled_name);
309
 
        }
310
 
 
311
 
        if (pr_current->font_directory) {
312
 
                free(pr_current->font_directory);
313
 
        }
314
 
 
315
 
        if (pr_current->scheme_directory) {
316
 
                free(pr_current->scheme_directory);
317
 
        }
318
 
 
319
 
        /* close the log file */
320
 
        s_log_close();
321
 
        
322
 
        /* free all fonts */
323
 
        /* if you close a window, then you free the font set... */
324
 
        /* this is probably a bad idea... */
325
 
        o_text_freeallfonts(pr_current);
326
 
 
327
 
        s_project_delete(project_head, pr_current);
328
 
 
329
 
        num_projects = num_projects - 1;
330
 
 
331
 
        free(pr_current);
332
 
 
333
 
        /* just closed last window, so quit */
334
 
        if (num_projects == 0) {
335
 
                gsymcheck_quit();
336
 
        }
337
 
}
338
 
 
339
 
void
340
 
s_project_close_all()
341
 
{
342
 
        TOPLEVEL *pr_current;
343
 
        TOPLEVEL *w_prev;
344
 
 
345
 
        pr_current = project_tail;
346
 
 
347
 
        /* loop over all windows to close */
348
 
        /* going backwards */
349
 
        /* wid == -1 is the head and we are done. */
350
 
        while(pr_current != NULL && pr_current->wid != -1) {
351
 
                w_prev = pr_current->prev;
352
 
                s_project_close(pr_current);
353
 
                pr_current = w_prev;
354
 
        }
355
 
 
356
 
        /* now free the head */
357
 
        /* only if all the windows are gone */
358
 
 
359
 
        if (project_head->next == NULL && num_projects == 0)  {
360
 
                s_project_free_head();
361
 
        }
362
 
}
363
 
 
364
 
TOPLEVEL *
365
 
s_project_get_ptr(int wid)
366
 
{
367
 
        TOPLEVEL *pr_current;
368
 
 
369
 
        pr_current = project_head;
370
 
 
371
 
        while(pr_current != NULL) {
372
 
                if (pr_current->wid == wid) {
373
 
                        return(pr_current);     
374
 
                }
375
 
 
376
 
                pr_current = pr_current->next;  
377
 
        }
378
 
 
379
 
        return(NULL);
380
 
}
381
 
 
382