Updated copyright text/header in most source files.
[geda-gaf.git] / libgeda / src / o_list.c
blobbb1d7db6e36457251f00ba62a85a8710b458fdbb
1 /* gEDA - GPL Electronic Design Automation
2 * libgeda - gEDA's library
3 * Copyright (C) 1998-2007 Ales Hvezda
4 * Copyright (C) 1998-2007 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
20 #include <config.h>
22 #include <stdio.h>
23 #ifdef HAVE_STRING_H
24 #include <string.h>
25 #endif
27 #include <gtk/gtk.h>
28 #include <libguile.h>
30 #include "defines.h"
31 #include "struct.h"
32 #include "globals.h"
33 #include "o_types.h"
34 #include "colors.h"
36 #include "../include/prototype.h"
38 #ifdef HAVE_LIBDMALLOC
39 #include <dmalloc.h>
40 #endif
42 /*! global which is used in o_list_copy_all */
43 extern int global_sid;
45 /*! \todo Finish documentation!!!!
46 * \brief
47 * \par Function Description
48 * returns head !!!!!!!!!!!!!!!!!!!
49 * look at above.. this returns what was passed in!!!!
50 * copies selected to list_head (!! returns new list)
51 * flag is either NORMAL_FLAG or SELECTION_FLAG
53 * \param [in] w_current The TOPLEVEL object.
54 * \param [in] list_head
55 * \param [in] selected
56 * \param [in] flag
57 * \param [out] return_end
58 * \return OBJECT pointer.
60 OBJECT *o_list_copy_to(TOPLEVEL *w_current, OBJECT *list_head,
61 OBJECT *selected, int flag, OBJECT **return_end)
63 OBJECT *end=NULL;
65 /* are we adding a selection or the real object list */
66 w_current->ADDING_SEL = flag;
68 end = (OBJECT *) return_tail(list_head);
70 switch(selected->type) {
72 case(OBJ_LINE):
73 /* do we do anything with the return value) ? */
74 end = (OBJECT *) o_line_copy(w_current, end, selected);
75 break;
77 case(OBJ_NET):
78 end = (OBJECT *) o_net_copy(w_current, end, selected);
79 break;
81 case(OBJ_BUS):
82 end = (OBJECT *) o_bus_copy(w_current, end, selected);
83 break;
85 case(OBJ_BOX):
86 end = (OBJECT *) o_box_copy(w_current, end, selected);
87 break;
89 case(OBJ_PICTURE):
90 end = (OBJECT *) o_picture_copy(w_current, end, selected);
91 break;
93 case(OBJ_CIRCLE):
94 end = (OBJECT *) o_circle_copy(w_current, end, selected);
95 break;
97 case(OBJ_COMPLEX):
98 case(OBJ_PLACEHOLDER):
99 if (o_complex_is_embedded (selected)) {
100 end = (OBJECT *) o_complex_copy_embedded(w_current, end, selected);
101 } else {
102 end = (OBJECT *) o_complex_copy(w_current, end, selected);
104 break;
106 case(OBJ_TEXT):
107 end = (OBJECT *) o_text_copy(w_current, end, selected);
108 if (selected->attribute &&
109 selected->visibility == INVISIBLE) {
110 end->visibility = INVISIBLE;
112 break;
114 case(OBJ_PIN):
115 end = (OBJECT *) o_pin_copy(w_current, end, selected);
116 break;
118 case(OBJ_ARC):
119 end = (OBJECT *) o_arc_copy(w_current, end, selected);
120 break;
123 if (list_head == NULL)
124 list_head = end;
126 /* make sure sid is the same! */
127 if (selected) {
128 end->sid = selected->sid;
131 /* I don't think this is a good idea at all */
132 /* w_current->ADDING_SEL = 0; */
134 if (return_end) {
135 *return_end = end;
138 return(list_head);
141 /*! \todo Finish function description!!!
142 * \brief
143 * \par Function Description
144 * you need to pass in a head_node for dest_list_head
145 * flag is either NORMAL_FLAG or SELECTION_FLAG
147 * \param [in] w_current The TOPLEVEL object.
148 * \param [in] src_list_head
149 * \param [in] dest_list_head
150 * \param [in] flag
151 * \return OBJECT pointer.
153 OBJECT *o_list_copy_all(TOPLEVEL *w_current, OBJECT *src_list_head,
154 OBJECT *dest_list_head, int flag)
156 OBJECT *src;
157 OBJECT *dest;
158 OBJECT *temp_parent=NULL;
159 int adding_sel_save;
161 src = src_list_head;
162 dest = dest_list_head;
163 temp_parent = w_current->page_current->object_parent;
164 w_current->page_current->object_parent = dest_list_head;
166 if (dest == NULL) {
167 w_current->page_current->object_parent = temp_parent;
168 return(NULL);
171 if (src == NULL) {
172 w_current->page_current->object_parent = temp_parent;
173 return(NULL);
176 adding_sel_save = w_current->ADDING_SEL;
178 /* first do all NON text items */
179 while(src != NULL) {
181 if (src->type != OBJ_TEXT) {
182 dest->next = o_list_copy_to(w_current, NULL, src, flag,
183 NULL);
185 dest->next->prev = dest;
186 dest = dest->next;
187 dest->sid = global_sid++;
190 src = src->next;
193 src = src_list_head;
194 /*dest = dest_list_head; out since we want to add to the end */
196 if (dest == NULL) {
197 w_current->page_current->object_parent = temp_parent;
198 return(NULL);
201 if (src == NULL) {
202 w_current->page_current->object_parent = temp_parent;
203 return(NULL);
206 /* then do all text items */
207 while(src != NULL) {
209 if (src->type == OBJ_TEXT) {
210 dest->next = o_list_copy_to(w_current, NULL, src, flag,
211 NULL);
213 dest->next->prev = dest;
214 dest = dest->next;
215 dest->sid = global_sid++;
217 if (src->attached_to /*&& !w_current->ADDING_SEL*/) {
218 if (src->attached_to->copied_to) {
219 o_attrib_attach(w_current,
220 w_current->page_current->object_parent,
221 dest, src->attached_to->copied_to);
223 /* satisfied copy request */
224 src->attached_to->copied_to = NULL;
229 src = src->next;
232 w_current->ADDING_SEL = adding_sel_save;
233 w_current->page_current->object_parent = temp_parent;
235 return(dest);
238 /*! \todo Finish function description!!!
239 * \brief
240 * \par Function Description
241 * you need to pass in a head_node for dest_list_head
242 * flag is either NORMAL_FLAG or SELECTION_FLAG
243 * this function copies the objects in the src SELECTION list
244 * to the OBJECT list in dest_list_head
245 * this routine assumes that objects in src_list_head are selected
246 * objects are unselected before they are copied and then reselected
247 * this is necessary to preserve the color info
249 * \param [in] w_current The TOPLEVEL object.
250 * \param [in] src_list_head
251 * \param [in] dest_list_head
252 * \param [in] flag
253 * \return OBJECT pointer.
255 OBJECT *o_list_copy_all_selection2(TOPLEVEL *w_current,
256 GList *src_list_head,
257 OBJECT *dest_list_head, int flag)
259 GList *src;
260 OBJECT *object;
261 OBJECT *dest;
262 OBJECT *temp_parent=NULL;
263 int adding_sel_save;
265 src = src_list_head;
266 dest = dest_list_head;
268 temp_parent = w_current->page_current->object_parent;
269 w_current->page_current->object_parent = dest_list_head;
271 if (dest == NULL) {
272 w_current->page_current->object_parent = temp_parent;
273 return(NULL);
276 if (src == NULL) {
277 w_current->page_current->object_parent = temp_parent;
278 return(NULL);
281 adding_sel_save = w_current->ADDING_SEL;
283 /* first do all NON text items */
284 while(src != NULL) {
286 object = (OBJECT *) src->data;
288 /* unselect the object before the copy */
289 o_selection_unselect(object);
291 if (object->type != OBJ_TEXT && object->type != OBJ_HEAD) {
292 dest->next = o_list_copy_to(w_current, NULL, object,
293 flag, NULL);
294 dest->next->prev = dest;
295 dest = dest->next;
296 dest->sid = global_sid++;
299 /* reselect it */
300 o_selection_select(object, SELECT_COLOR);
302 src = src->next;
305 src = src_list_head;
306 /*dest = dest_list_head; out since we want to add to the end */
308 if (dest == NULL) {
309 w_current->page_current->object_parent = temp_parent;
310 return(NULL);
313 if (src == NULL) {
314 w_current->page_current->object_parent = temp_parent;
315 return(NULL);
318 /* then do all text items */
319 while(src != NULL) {
321 object = (OBJECT *) src->data;
323 /* unselect the object before the copy */
324 o_selection_unselect(object);
326 if (object->type == OBJ_TEXT) {
327 dest->next = o_list_copy_to(w_current, NULL, object,
328 flag, NULL);
330 dest->next->prev = dest;
331 dest = dest->next;
332 dest->sid = global_sid++;
334 if (object->attached_to /*&& !w_current->ADDING_SEL*/) {
335 if (object->attached_to->copied_to) {
336 o_attrib_attach(w_current,
337 w_current->page_current->object_parent,
338 dest, object->attached_to->copied_to);
339 /* satisfied copy request */
340 object->attached_to->copied_to = NULL;
345 /* reselect it */
346 o_selection_select(object, SELECT_COLOR);
348 src = src->next;
351 w_current->ADDING_SEL = adding_sel_save;
352 w_current->page_current->object_parent = temp_parent;
354 return(dest);
357 /*! \todo Finish function description!!!
358 * \brief
359 * \par Function Description
360 * returns entry in the list
362 * \param [in] list
363 * \param [in] current
364 * \return OBJECT pointer.
366 OBJECT *o_list_search(OBJECT *list, OBJECT *current)
368 OBJECT *o_current;
370 o_current = list ;
372 if (current == NULL) {
373 return(NULL);
376 if (list == NULL) {
377 return(NULL);
380 while(o_current != NULL) {
381 /* look for uniq sid */
382 if (current->sid == o_current->sid) {
383 return(o_current);
385 o_current = o_current->next;
387 return(NULL);
390 /*! \todo Finish function description!!!
391 * \brief
392 * \par Function Description
394 * \param [in] w_current The TOPLEVEL object.
395 * \param [in] list
396 * \param [in] delete
398 void o_list_delete(TOPLEVEL *w_current, OBJECT *list, OBJECT *delete)
400 OBJECT *find;
402 find = o_list_search(list, delete);
404 if (find != NULL)
405 s_delete(w_current, find);
409 /*! \todo Finish function description!!!
410 * \brief
411 * \par Function Description
412 * assuming list is head
413 * head will NOT be deleted
415 * \param [in] w_current The TOPLEVEL object.
416 * \param [in] list
418 void o_list_delete_rest(TOPLEVEL *w_current, OBJECT *list)
420 OBJECT *o_current=NULL;
421 OBJECT *o_prev=NULL;
423 o_current = (OBJECT *) return_tail(list);
425 w_current->REMOVING_SEL = 1;
426 /* remove list backwards */
427 while(o_current != NULL) {
428 if (o_current->type != OBJ_HEAD) {
429 o_prev = o_current->prev;
430 s_delete(w_current, o_current);
431 o_current = o_prev;
432 } else {
433 o_current->next = NULL; /* set sel_head->next to be empty */
434 o_current = NULL;
437 w_current->REMOVING_SEL = 0;