Update README with new Automake requirement.
[geda-gaf.git] / libgeda / src / o_list.c
blob764cfca657618540176e53d4b2c2654a385e919d
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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)
43 * \param [in] toplevel The TOPLEVEL object.
44 * \param [in] selected
45 * \return OBJECT pointer.
47 OBJECT *o_object_copy (TOPLEVEL *toplevel,
48 OBJECT *selected)
50 OBJECT *new_obj;
52 g_return_val_if_fail (toplevel != NULL, NULL);
53 g_return_val_if_fail (selected != NULL, NULL);
55 switch(selected->type) {
57 case(OBJ_LINE):
58 new_obj = o_line_copy (toplevel, selected);
59 break;
61 case(OBJ_NET):
62 new_obj = o_net_copy (toplevel, selected);
63 break;
65 case(OBJ_BUS):
66 new_obj = o_bus_copy (toplevel, selected);
67 break;
69 case(OBJ_BOX):
70 new_obj = o_box_copy (toplevel, selected);
71 break;
73 case(OBJ_PICTURE):
74 new_obj = o_picture_copy (toplevel, selected);
75 break;
77 case(OBJ_CIRCLE):
78 new_obj = o_circle_copy (toplevel, selected);
79 break;
81 case(OBJ_COMPLEX):
82 case(OBJ_PLACEHOLDER):
83 new_obj = o_complex_copy (toplevel, selected);
84 break;
86 case(OBJ_TEXT):
87 new_obj = o_text_copy (toplevel, selected);
88 break;
90 case(OBJ_PATH):
91 new_obj = o_path_copy (toplevel, selected);
92 break;
94 case(OBJ_PIN):
95 new_obj = o_pin_copy (toplevel, selected);
96 break;
98 case(OBJ_ARC):
99 new_obj = o_arc_copy (toplevel, selected);
100 break;
102 default:
103 g_critical ("o_list_copy_to: object %p has bad type '%c'\n",
104 selected, selected->type);
105 return NULL;
108 /* Store a reference in the copied object to where it was copied.
109 * Used to retain associations when copying attributes */
110 selected->copied_to = new_obj;
112 /* make sure sid is the same! */
113 if (selected) {
114 new_obj->sid = selected->sid;
117 return new_obj;
121 /*! \todo Finish function description!!!
122 * \brief
123 * \par Function Description
124 * you need to pass in a head_node for dest_list_head
125 * flag is either NORMAL_FLAG or SELECTION_FLAG
126 * this function copies the objects in the src GList src_list
127 * to the destination GList dest_list
128 * this routine assumes that objects in src_list are selected
129 * objects are unselected before they are copied and then reselected
130 * this is necessary to preserve the color info
132 * \param [in] toplevel The TOPLEVEL object.
133 * \param [in] src_list The GList to copy from.
134 * \param [in] dest_list The GList to copy to.
135 * \return the dest_list GList with objects appended to it.
137 GList *o_glist_copy_all (TOPLEVEL *toplevel,
138 const GList *src_list,
139 GList *dest_list)
141 const GList *src;
142 GList *dest;
143 OBJECT *src_object, *dst_object;
144 int selected_save;
146 src = src_list;
147 /* Reverse any existing items, as we will prepend, then reverse at the end */
148 dest = g_list_reverse (dest_list);
150 if (src == NULL) {
151 return(NULL);
154 /* first do all NON text items */
155 while(src != NULL) {
156 src_object = (OBJECT *) src->data;
158 /* unselect the object before the copy */
159 selected_save = src_object->selected;
160 if (selected_save)
161 o_selection_unselect (toplevel, src_object);
163 if (src_object->type != OBJ_TEXT) {
164 dst_object = o_object_copy (toplevel, src_object);
165 dst_object->sid = global_sid++;
166 dest = g_list_prepend (dest, dst_object);
169 /* reselect it */
170 if (selected_save)
171 o_selection_select (toplevel, src_object);
173 src = g_list_next(src);
176 src = src_list;
178 /* then do all text items */
179 while(src != NULL) {
180 src_object = (OBJECT *) src->data;
182 /* unselect the object before the copy */
183 selected_save = src_object->selected;
184 if (selected_save)
185 o_selection_unselect (toplevel, src_object);
187 if (src_object->type == OBJ_TEXT) {
188 dst_object = o_object_copy (toplevel, src_object);
189 dst_object->sid = global_sid++;
190 dest = g_list_prepend (dest, dst_object);
192 if (src_object->attached_to != NULL &&
193 src_object->attached_to->copied_to != NULL) {
194 o_attrib_attach(toplevel, dst_object,
195 src_object->attached_to->copied_to, FALSE);
196 /* handle slot= attribute, it's a special case */
197 if (g_ascii_strncasecmp (dst_object->text->string, "slot=", 5) == 0)
198 s_slot_update_object (toplevel, src_object->attached_to->copied_to);
202 /* reselect it */
203 if (selected_save)
204 o_selection_select (toplevel, src_object);
206 src = g_list_next(src);
209 /* Clean up dangling copied_to pointers */
210 src = src_list;
211 while(src != NULL) {
212 src_object = src->data;
213 src_object->copied_to = NULL;
214 src = g_list_next (src);
217 /* Reverse the list to be in the correct order */
218 dest = g_list_reverse (dest);
220 return(dest);
224 /*! \todo Finish function description!!!
225 * \brief
226 * \par Function Description
228 void o_glist_translate_world(TOPLEVEL *toplevel, int dx, int dy, const GList *list)
230 const GList *iter = list;
231 OBJECT *o_current;
233 while ( iter != NULL ) {
234 o_current = (OBJECT *)iter->data;
235 o_translate_world(toplevel, dx, dy, o_current);
236 iter = g_list_next (iter);
241 /*! \todo Finish function description!!!
242 * \brief
243 * \par Function Description
245 void o_glist_rotate_world (TOPLEVEL *toplevel, int x, int y, int angle, const GList *list)
247 const GList *iter = list;
248 OBJECT *o_current;
250 while ( iter != NULL ) {
251 o_current = (OBJECT *)iter->data;
252 o_rotate_world (toplevel, x, y, angle, o_current);
253 iter = g_list_next (iter);
258 /*! \todo Finish function description!!!
259 * \brief
260 * \par Function Description
262 void o_glist_mirror_world (TOPLEVEL *toplevel, int x, int y, const GList *list)
264 const GList *iter = list;
265 OBJECT *o_current;
267 while ( iter != NULL ) {
268 o_current = (OBJECT *)iter->data;
269 o_mirror_world (toplevel, x, y, o_current);
270 iter = g_list_next (iter);
275 /*! \brief Change the color of a list of objects
277 * \par Function Description
278 * This function changes the the new color of a list of objects
280 * \param [in] toplevel The TOPLEVEL structure.
281 * \param [in] list The list of OBJECTs to change color.
282 * \param [in] color The new color.
284 void o_glist_set_color (TOPLEVEL *toplevel, const GList *list, int color)
286 const GList *iter;
288 for (iter = list; iter != NULL; iter = g_list_next (iter))
289 o_set_color (toplevel, iter->data, color);