Updated copyright text/header in most source files.
[geda-gaf/peter-b.git] / libgeda / src / o_list.c
blobd924df5de48ce9e46e6d00c8fbf4f8d387daf30d
1 /* gEDA - GPL Electronic Design Automation
2 * libgeda - gEDA's library
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2010 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 "libgeda_priv.h"
29 #ifdef HAVE_LIBDMALLOC
30 #include <dmalloc.h>
31 #endif
33 /*! global which is used in o_list_copy_all */
34 extern int global_sid;
36 /*! \todo Finish documentation!!!!
37 * \brief
38 * \par Function Description
39 * returns head !!!!!!!!!!!!!!!!!!!
40 * look at above.. this returns what was passed in!!!!
41 * copies selected to list_head (!! returns new list)
42 * flag is either NORMAL_FLAG or SELECTION_FLAG
44 * \param [in] toplevel The TOPLEVEL object.
45 * \param [in] selected
46 * \param [in] flag
47 * \return OBJECT pointer.
49 OBJECT *o_object_copy (TOPLEVEL *toplevel,
50 OBJECT *selected, int flag)
52 OBJECT *new_obj;
54 /* are we adding a selection or the real object list */
55 toplevel->ADDING_SEL = flag;
57 switch(selected->type) {
59 case(OBJ_LINE):
60 new_obj = o_line_copy (toplevel, selected);
61 break;
63 case(OBJ_NET):
64 new_obj = o_net_copy (toplevel, selected);
65 break;
67 case(OBJ_BUS):
68 new_obj = o_bus_copy (toplevel, selected);
69 break;
71 case(OBJ_BOX):
72 new_obj = o_box_copy (toplevel, selected);
73 break;
75 case(OBJ_PICTURE):
76 new_obj = o_picture_copy (toplevel, selected);
77 break;
79 case(OBJ_CIRCLE):
80 new_obj = o_circle_copy (toplevel, selected);
81 break;
83 case(OBJ_COMPLEX):
84 case(OBJ_PLACEHOLDER):
85 new_obj = o_complex_copy (toplevel, selected);
86 break;
88 case(OBJ_TEXT):
89 new_obj = o_text_copy (toplevel, selected);
90 break;
92 case(OBJ_PATH):
93 new_obj = o_path_copy (toplevel, selected);
94 break;
96 case(OBJ_PIN):
97 new_obj = o_pin_copy (toplevel, selected);
98 break;
100 case(OBJ_ARC):
101 new_obj = o_arc_copy (toplevel, selected);
102 break;
104 default:
105 g_critical ("o_list_copy_to: object %p has bad type '%c'\n",
106 selected, selected->type);
107 return NULL;
110 /* Store a reference in the copied object to where it was copied.
111 * Used to retain associations when copying attributes */
112 selected->copied_to = new_obj;
114 /* make sure sid is the same! */
115 if (selected) {
116 new_obj->sid = selected->sid;
119 /* I don't think this is a good idea at all */
120 /* toplevel->ADDING_SEL = 0; */
122 return new_obj;
126 /*! \todo Finish function description!!!
127 * \brief
128 * \par Function Description
129 * you need to pass in a head_node for dest_list_head
130 * flag is either NORMAL_FLAG or SELECTION_FLAG
131 * this function copies the objects in the src GList src_list
132 * to the destination GList dest_list
133 * this routine assumes that objects in src_list are selected
134 * objects are unselected before they are copied and then reselected
135 * this is necessary to preserve the color info
137 * \param [in] toplevel The TOPLEVEL object.
138 * \param [in] src_list The GList to copy from.
139 * \param [in] dest_list The GList to copy to.
140 * \param [in] flag
141 * \return the dest_list GList with objects appended to it.
143 GList *o_glist_copy_all (TOPLEVEL *toplevel,
144 const GList *src_list,
145 GList *dest_list, int flag)
147 const GList *src;
148 GList *dest;
149 OBJECT *src_object, *dst_object;
150 int adding_sel_save;
151 int selected_save;
153 src = src_list;
154 /* Reverse any existing items, as we will prepend, then reverse at the end */
155 dest = g_list_reverse (dest_list);
157 if (src == NULL) {
158 return(NULL);
161 /* Save ADDING_SEL as o_list_copy_to() sets it */
162 adding_sel_save = toplevel->ADDING_SEL;
164 /* first do all NON text items */
165 while(src != NULL) {
166 src_object = (OBJECT *) src->data;
168 /* unselect the object before the copy */
169 selected_save = src_object->selected;
170 if (selected_save)
171 o_selection_unselect (toplevel, src_object);
173 if (src_object->type != OBJ_TEXT) {
174 dst_object = o_object_copy (toplevel, src_object, flag);
175 dst_object->sid = global_sid++;
176 dest = g_list_prepend (dest, dst_object);
179 /* reselect it */
180 if (selected_save)
181 o_selection_select (toplevel, src_object);
183 src = g_list_next(src);
186 src = src_list;
188 /* then do all text items */
189 while(src != NULL) {
190 src_object = (OBJECT *) src->data;
192 /* unselect the object before the copy */
193 selected_save = src_object->selected;
194 if (selected_save)
195 o_selection_unselect (toplevel, src_object);
197 if (src_object->type == OBJ_TEXT) {
198 dst_object = o_object_copy (toplevel, src_object, flag);
199 dst_object->sid = global_sid++;
200 dest = g_list_prepend (dest, dst_object);
202 if (src_object->attached_to != NULL &&
203 src_object->attached_to->copied_to != NULL) {
204 o_attrib_attach(toplevel, dst_object,
205 src_object->attached_to->copied_to, FALSE);
206 /* handle slot= attribute, it's a special case */
207 if (g_ascii_strncasecmp (dst_object->text->string, "slot=", 5) == 0)
208 s_slot_update_object (toplevel, src_object->attached_to->copied_to);
212 /* reselect it */
213 if (selected_save)
214 o_selection_select (toplevel, src_object);
216 src = g_list_next(src);
219 /* Clean up dangling copied_to pointers */
220 src = src_list;
221 while(src != NULL) {
222 src_object = src->data;
223 src_object->copied_to = NULL;
224 src = g_list_next (src);
227 /* Reverse the list to be in the correct order */
228 dest = g_list_reverse (dest);
230 toplevel->ADDING_SEL = adding_sel_save;
232 return(dest);
236 /*! \todo Finish function description!!!
237 * \brief
238 * \par Function Description
240 void o_glist_translate_world(TOPLEVEL *toplevel, int dx, int dy, const GList *list)
242 const GList *iter = list;
243 OBJECT *o_current;
245 while ( iter != NULL ) {
246 o_current = (OBJECT *)iter->data;
247 o_translate_world(toplevel, dx, dy, o_current);
248 iter = g_list_next (iter);
253 /*! \todo Finish function description!!!
254 * \brief
255 * \par Function Description
257 void o_glist_rotate_world (TOPLEVEL *toplevel, int x, int y, int angle, const GList *list)
259 const GList *iter = list;
260 OBJECT *o_current;
262 while ( iter != NULL ) {
263 o_current = (OBJECT *)iter->data;
264 o_rotate_world (toplevel, x, y, angle, o_current);
265 iter = g_list_next (iter);
270 /*! \todo Finish function description!!!
271 * \brief
272 * \par Function Description
274 void o_glist_mirror_world (TOPLEVEL *toplevel, int x, int y, const GList *list)
276 const GList *iter = list;
277 OBJECT *o_current;
279 while ( iter != NULL ) {
280 o_current = (OBJECT *)iter->data;
281 o_mirror_world (toplevel, x, y, o_current);
282 iter = g_list_next (iter);
287 /*! \brief Change the color of a list of objects
289 * \par Function Description
290 * This function changes the the new color of a list of objects
292 * \param [in] toplevel The TOPLEVEL structure.
293 * \param [in] list The list of OBJECTs to change color.
294 * \param [in] color The new color.
296 void o_glist_set_color (TOPLEVEL *toplevel, const GList *list, int color)
298 const GList *iter;
300 for (iter = list; iter != NULL; iter = g_list_next (iter))
301 o_set_color (toplevel, iter->data, color);