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
36 #include "../include/prototype.h"
38 #ifdef HAVE_LIBDMALLOC
42 /*! global which is used in o_list_copy_all */
43 extern int global_sid
;
45 /*! \todo Finish documentation!!!!
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
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
)
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
) {
73 /* do we do anything with the return value) ? */
74 end
= (OBJECT
*) o_line_copy(w_current
, end
, selected
);
78 end
= (OBJECT
*) o_net_copy(w_current
, end
, selected
);
82 end
= (OBJECT
*) o_bus_copy(w_current
, end
, selected
);
86 end
= (OBJECT
*) o_box_copy(w_current
, end
, selected
);
90 end
= (OBJECT
*) o_picture_copy(w_current
, end
, selected
);
94 end
= (OBJECT
*) o_circle_copy(w_current
, end
, selected
);
98 case(OBJ_PLACEHOLDER
):
99 if (o_complex_is_embedded (selected
)) {
100 end
= (OBJECT
*) o_complex_copy_embedded(w_current
, end
, selected
);
102 end
= (OBJECT
*) o_complex_copy(w_current
, end
, selected
);
107 end
= (OBJECT
*) o_text_copy(w_current
, end
, selected
);
108 if (selected
->attribute
&&
109 selected
->visibility
== INVISIBLE
) {
110 end
->visibility
= INVISIBLE
;
115 end
= (OBJECT
*) o_pin_copy(w_current
, end
, selected
);
119 end
= (OBJECT
*) o_arc_copy(w_current
, end
, selected
);
123 if (list_head
== NULL
)
126 /* make sure sid is the same! */
128 end
->sid
= selected
->sid
;
131 /* I don't think this is a good idea at all */
132 /* w_current->ADDING_SEL = 0; */
141 /*! \todo Finish function description!!!
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
151 * \return OBJECT pointer.
153 OBJECT
*o_list_copy_all(TOPLEVEL
*w_current
, OBJECT
*src_list_head
,
154 OBJECT
*dest_list_head
, int flag
)
158 OBJECT
*temp_parent
=NULL
;
162 dest
= dest_list_head
;
163 temp_parent
= w_current
->page_current
->object_parent
;
164 w_current
->page_current
->object_parent
= dest_list_head
;
167 w_current
->page_current
->object_parent
= temp_parent
;
172 w_current
->page_current
->object_parent
= temp_parent
;
176 adding_sel_save
= w_current
->ADDING_SEL
;
178 /* first do all NON text items */
181 if (src
->type
!= OBJ_TEXT
) {
182 dest
->next
= o_list_copy_to(w_current
, NULL
, src
, flag
,
185 dest
->next
->prev
= dest
;
187 dest
->sid
= global_sid
++;
194 /*dest = dest_list_head; out since we want to add to the end */
197 w_current
->page_current
->object_parent
= temp_parent
;
202 w_current
->page_current
->object_parent
= temp_parent
;
206 /* then do all text items */
209 if (src
->type
== OBJ_TEXT
) {
210 dest
->next
= o_list_copy_to(w_current
, NULL
, src
, flag
,
213 dest
->next
->prev
= dest
;
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
;
232 w_current
->ADDING_SEL
= adding_sel_save
;
233 w_current
->page_current
->object_parent
= temp_parent
;
238 /*! \todo Finish function description!!!
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
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
)
262 OBJECT
*temp_parent
=NULL
;
266 dest
= dest_list_head
;
268 temp_parent
= w_current
->page_current
->object_parent
;
269 w_current
->page_current
->object_parent
= dest_list_head
;
272 w_current
->page_current
->object_parent
= temp_parent
;
277 w_current
->page_current
->object_parent
= temp_parent
;
281 adding_sel_save
= w_current
->ADDING_SEL
;
283 /* first do all NON text items */
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
,
294 dest
->next
->prev
= dest
;
296 dest
->sid
= global_sid
++;
300 o_selection_select(object
, SELECT_COLOR
);
306 /*dest = dest_list_head; out since we want to add to the end */
309 w_current
->page_current
->object_parent
= temp_parent
;
314 w_current
->page_current
->object_parent
= temp_parent
;
318 /* then do all text items */
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
,
330 dest
->next
->prev
= dest
;
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
;
346 o_selection_select(object
, SELECT_COLOR
);
351 w_current
->ADDING_SEL
= adding_sel_save
;
352 w_current
->page_current
->object_parent
= temp_parent
;
357 /*! \todo Finish function description!!!
359 * \par Function Description
360 * returns entry in the list
363 * \param [in] current
364 * \return OBJECT pointer.
366 OBJECT
*o_list_search(OBJECT
*list
, OBJECT
*current
)
372 if (current
== NULL
) {
380 while(o_current
!= NULL
) {
381 /* look for uniq sid */
382 if (current
->sid
== o_current
->sid
) {
385 o_current
= o_current
->next
;
390 /*! \todo Finish function description!!!
392 * \par Function Description
394 * \param [in] w_current The TOPLEVEL object.
398 void o_list_delete(TOPLEVEL
*w_current
, OBJECT
*list
, OBJECT
*delete)
402 find
= o_list_search(list
, delete);
405 s_delete(w_current
, find
);
409 /*! \todo Finish function description!!!
411 * \par Function Description
412 * assuming list is head
413 * head will NOT be deleted
415 * \param [in] w_current The TOPLEVEL object.
418 void o_list_delete_rest(TOPLEVEL
*w_current
, OBJECT
*list
)
420 OBJECT
*o_current
=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
);
433 o_current
->next
= NULL
; /* set sel_head->next to be empty */
437 w_current
->REMOVING_SEL
= 0;