Updated copyright text/header in most source files.
[geda-gaf.git] / gschem / src / o_buffer.c
blobddf32b1867e225861caa2b3c36f31e8d5a9e87b4
1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
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>
21 #include <stdio.h>
23 #include "gschem.h"
25 #ifdef HAVE_LIBDMALLOC
26 #include <dmalloc.h>
27 #endif
29 static void
30 selection_to_buffer(GSCHEM_TOPLEVEL *w_current, int buf_num)
32 TOPLEVEL *toplevel = w_current->toplevel;
33 GList *s_current = NULL;
35 s_current = geda_list_get_glist( toplevel->page_current->selection_list );
37 if (object_buffer[buf_num] != NULL) {
38 s_delete_object_glist(toplevel, object_buffer[buf_num]);
39 object_buffer[buf_num] = NULL;
42 toplevel->ADDING_SEL = 1;
43 object_buffer[buf_num] = o_glist_copy_all (toplevel, s_current,
44 object_buffer[buf_num],
45 SELECTION_FLAG);
46 toplevel->ADDING_SEL = 0;
49 /*! \todo Finish function documentation!!!
50 * \brief
51 * \par Function Description
54 void o_buffer_copy(GSCHEM_TOPLEVEL *w_current, int buf_num)
56 if (buf_num < 0 || buf_num > MAX_BUFFERS) {
57 g_warning (_("o_buffer_copy: Invalid buffer %i\n"), buf_num);
58 return;
61 selection_to_buffer (w_current, buf_num);
64 /*! \todo Finish function documentation!!!
65 * \brief
66 * \par Function Description
69 void o_buffer_cut(GSCHEM_TOPLEVEL *w_current, int buf_num)
71 if (buf_num < 0 || buf_num > MAX_BUFFERS) {
72 g_warning (_("o_buffer_cut: Invalid buffer %i\n"), buf_num);
73 return;
76 selection_to_buffer (w_current, buf_num);
77 o_delete_selected(w_current);
80 /*! \todo Finish function documentation!!!
81 * \brief
82 * \par Function Description
85 void o_buffer_paste_start(GSCHEM_TOPLEVEL *w_current, int w_x, int w_y,
86 int buf_num)
88 TOPLEVEL *toplevel = w_current->toplevel;
89 int rleft, rtop, rbottom, rright;
90 int x, y;
92 if (buf_num < 0 || buf_num > MAX_BUFFERS) {
93 fprintf(stderr, _("Got an invalid buffer_number [o_buffer_paste_start]\n"));
94 return;
97 w_current->last_drawb_mode = LAST_DRAWB_MODE_NONE;
99 /* remove the old place list if it exists */
100 s_delete_object_glist(toplevel, toplevel->page_current->place_list);
101 toplevel->page_current->place_list = NULL;
103 toplevel->ADDING_SEL = 1;
104 toplevel->page_current->place_list =
105 o_glist_copy_all (toplevel, object_buffer[buf_num],
106 toplevel->page_current->place_list,
107 SELECTION_FLAG);
109 if (!world_get_object_glist_bounds (toplevel,
110 toplevel->page_current->place_list,
111 &rleft, &rtop,
112 &rright, &rbottom)) {
113 /* If the place buffer doesn't have any objects
114 * to define its any bounds, we drop out here */
115 return;
118 /* Place the objects into the buffer at the mouse origin, (w_x, w_y). */
120 w_current->first_wx = w_x;
121 w_current->first_wy = w_y;
123 /* snap x and y to the grid, pointed out by Martin Benes */
124 x = snap_grid (w_current, rleft);
125 y = snap_grid (w_current, rtop);
127 o_glist_translate_world (toplevel, w_x - x, w_y - y,
128 toplevel->page_current->place_list);
129 toplevel->ADDING_SEL = 0;
131 w_current->inside_action = 1;
132 i_set_state(w_current, ENDPASTE);
133 o_place_start (w_current, w_x, w_y);
137 /*! \todo Finish function documentation!!!
138 * \brief
139 * \par Function Description
142 void o_buffer_init(void)
144 int i;
146 for (i = 0 ; i < MAX_BUFFERS; i++) {
147 object_buffer[i] = NULL;
151 /*! \todo Finish function documentation!!!
152 * \brief
153 * \par Function Description
156 void o_buffer_free(GSCHEM_TOPLEVEL *w_current)
158 TOPLEVEL *toplevel = w_current->toplevel;
159 int i;
161 for (i = 0 ; i < MAX_BUFFERS; i++) {
162 if (object_buffer[i]) {
163 s_delete_object_glist(toplevel, object_buffer[i]);
164 object_buffer[i] = NULL;