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
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)
42 * flag is either NORMAL_FLAG or SELECTION_FLAG
44 * \param [in] toplevel The TOPLEVEL object.
45 * \param [in] selected
47 * \return OBJECT pointer.
49 OBJECT
*o_object_copy (TOPLEVEL
*toplevel
,
50 OBJECT
*selected
, int flag
)
54 /* are we adding a selection or the real object list */
55 toplevel
->ADDING_SEL
= flag
;
57 switch(selected
->type
) {
60 new_obj
= o_line_copy (toplevel
, selected
);
64 new_obj
= o_net_copy (toplevel
, selected
);
68 new_obj
= o_bus_copy (toplevel
, selected
);
72 new_obj
= o_box_copy (toplevel
, selected
);
76 new_obj
= o_picture_copy (toplevel
, selected
);
80 new_obj
= o_circle_copy (toplevel
, selected
);
84 case(OBJ_PLACEHOLDER
):
85 new_obj
= o_complex_copy (toplevel
, selected
);
89 new_obj
= o_text_copy (toplevel
, selected
);
93 new_obj
= o_path_copy (toplevel
, selected
);
97 new_obj
= o_pin_copy (toplevel
, selected
);
101 new_obj
= o_arc_copy (toplevel
, selected
);
105 g_critical ("o_list_copy_to: object %p has bad type '%c'\n",
106 selected
, selected
->type
);
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! */
116 new_obj
->sid
= selected
->sid
;
119 /* I don't think this is a good idea at all */
120 /* toplevel->ADDING_SEL = 0; */
126 /*! \todo Finish function description!!!
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.
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
)
149 OBJECT
*src_object
, *dst_object
;
154 /* Reverse any existing items, as we will prepend, then reverse at the end */
155 dest
= g_list_reverse (dest_list
);
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 */
166 src_object
= (OBJECT
*) src
->data
;
168 /* unselect the object before the copy */
169 selected_save
= src_object
->selected
;
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
);
181 o_selection_select (toplevel
, src_object
);
183 src
= g_list_next(src
);
188 /* then do all text items */
190 src_object
= (OBJECT
*) src
->data
;
192 /* unselect the object before the copy */
193 selected_save
= src_object
->selected
;
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
);
214 o_selection_select (toplevel
, src_object
);
216 src
= g_list_next(src
);
219 /* Clean up dangling copied_to pointers */
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
;
236 /*! \todo Finish function description!!!
238 * \par Function Description
240 void o_glist_translate_world(TOPLEVEL
*toplevel
, int dx
, int dy
, const GList
*list
)
242 const GList
*iter
= list
;
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!!!
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
;
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!!!
272 * \par Function Description
274 void o_glist_mirror_world (TOPLEVEL
*toplevel
, int x
, int y
, const GList
*list
)
276 const GList
*iter
= list
;
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
)
300 for (iter
= list
; iter
!= NULL
; iter
= g_list_next (iter
))
301 o_set_color (toplevel
, iter
->data
, color
);