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
27 #include "libgeda_priv.h"
29 #ifdef HAVE_LIBDMALLOC
33 /*! global which is used in o_list_copy_all */
34 extern int global_sid
;
36 /*! \todo Finish documentation!!!!
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
,
52 g_return_val_if_fail (toplevel
!= NULL
, NULL
);
53 g_return_val_if_fail (selected
!= NULL
, NULL
);
55 switch(selected
->type
) {
58 new_obj
= o_line_copy (toplevel
, selected
);
62 new_obj
= o_net_copy (toplevel
, selected
);
66 new_obj
= o_bus_copy (toplevel
, selected
);
70 new_obj
= o_box_copy (toplevel
, selected
);
74 new_obj
= o_picture_copy (toplevel
, selected
);
78 new_obj
= o_circle_copy (toplevel
, selected
);
82 case(OBJ_PLACEHOLDER
):
83 new_obj
= o_complex_copy (toplevel
, selected
);
87 new_obj
= o_text_copy (toplevel
, selected
);
91 new_obj
= o_path_copy (toplevel
, selected
);
95 new_obj
= o_pin_copy (toplevel
, selected
);
99 new_obj
= o_arc_copy (toplevel
, selected
);
103 g_critical ("o_list_copy_to: object %p has bad type '%c'\n",
104 selected
, selected
->type
);
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! */
114 new_obj
->sid
= selected
->sid
;
121 /*! \todo Finish function description!!!
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
,
143 OBJECT
*src_object
, *dst_object
;
147 /* Reverse any existing items, as we will prepend, then reverse at the end */
148 dest
= g_list_reverse (dest_list
);
154 /* first do all NON text items */
156 src_object
= (OBJECT
*) src
->data
;
158 /* unselect the object before the copy */
159 selected_save
= src_object
->selected
;
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
);
171 o_selection_select (toplevel
, src_object
);
173 src
= g_list_next(src
);
178 /* then do all text items */
180 src_object
= (OBJECT
*) src
->data
;
182 /* unselect the object before the copy */
183 selected_save
= src_object
->selected
;
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
);
204 o_selection_select (toplevel
, src_object
);
206 src
= g_list_next(src
);
209 /* Clean up dangling copied_to pointers */
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
);
224 /*! \todo Finish function description!!!
226 * \par Function Description
228 void o_glist_translate_world(TOPLEVEL
*toplevel
, int dx
, int dy
, const GList
*list
)
230 const GList
*iter
= list
;
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!!!
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
;
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!!!
260 * \par Function Description
262 void o_glist_mirror_world (TOPLEVEL
*toplevel
, int x
, int y
, const GList
*list
)
264 const GList
*iter
= list
;
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
)
288 for (iter
= list
; iter
!= NULL
; iter
= g_list_next (iter
))
289 o_set_color (toplevel
, iter
->data
, color
);