gschem

o_buffer.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * gschem - gEDA Schematic Capture
00003  * Copyright (C) 1998-2010 Ales Hvezda
00004  * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 #include <config.h>
00021 #include <stdio.h>
00022 
00023 #include "gschem.h"
00024 
00025 #ifdef HAVE_LIBDMALLOC
00026 #include <dmalloc.h>
00027 #endif
00028 
00029 static void
00030 selection_to_buffer(GSCHEM_TOPLEVEL *w_current, int buf_num)
00031 {
00032   TOPLEVEL *toplevel = w_current->toplevel;
00033   GList *s_current = NULL;
00034 
00035   s_current = geda_list_get_glist( toplevel->page_current->selection_list );
00036 
00037   if (object_buffer[buf_num] != NULL) {
00038     s_delete_object_glist(toplevel, object_buffer[buf_num]);
00039     object_buffer[buf_num] = NULL;
00040   }
00041 
00042   object_buffer[buf_num] = o_glist_copy_all (toplevel, s_current,
00043                                              object_buffer[buf_num]);
00044 }
00045 
00051 void o_buffer_copy(GSCHEM_TOPLEVEL *w_current, int buf_num)
00052 {
00053   if (buf_num < 0 || buf_num >= MAX_BUFFERS) {
00054     g_warning (_("o_buffer_copy: Invalid buffer %i\n"), buf_num);
00055     return;
00056   }
00057 
00058   selection_to_buffer (w_current, buf_num);
00059 }
00060 
00066 void o_buffer_cut(GSCHEM_TOPLEVEL *w_current, int buf_num)
00067 {
00068   if (buf_num < 0 || buf_num >= MAX_BUFFERS) {
00069     g_warning (_("o_buffer_cut: Invalid buffer %i\n"), buf_num);
00070     return;
00071   }
00072 
00073   selection_to_buffer (w_current, buf_num);
00074   o_delete_selected(w_current);
00075 }
00076 
00082 void o_buffer_paste_start(GSCHEM_TOPLEVEL *w_current, int w_x, int w_y,
00083                           int buf_num)
00084 {
00085   TOPLEVEL *toplevel = w_current->toplevel;
00086   int rleft, rtop, rbottom, rright;
00087   int x, y;
00088 
00089   if (buf_num < 0 || buf_num >= MAX_BUFFERS) {
00090     fprintf(stderr, _("Got an invalid buffer_number [o_buffer_paste_start]\n"));
00091     return;
00092   }
00093 
00094   w_current->last_drawb_mode = LAST_DRAWB_MODE_NONE;
00095 
00096   /* remove the old place list if it exists */
00097   s_delete_object_glist(toplevel, toplevel->page_current->place_list);
00098   toplevel->page_current->place_list = NULL;
00099 
00100   toplevel->page_current->place_list =
00101     o_glist_copy_all (toplevel, object_buffer[buf_num],
00102                       toplevel->page_current->place_list);
00103 
00104   if (!world_get_object_glist_bounds (toplevel,
00105                                       toplevel->page_current->place_list,
00106                                      &rleft, &rtop,
00107                                      &rright, &rbottom)) {
00108     /* If the place buffer doesn't have any objects
00109      * to define its any bounds, we drop out here */
00110     return;
00111   }
00112 
00113   /* Place the objects into the buffer at the mouse origin, (w_x, w_y). */
00114 
00115   w_current->first_wx = w_x;
00116   w_current->first_wy = w_y;
00117 
00118   /* snap x and y to the grid, pointed out by Martin Benes */
00119   x = snap_grid (w_current, rleft);
00120   y = snap_grid (w_current, rtop);
00121 
00122   o_glist_translate_world (toplevel, w_x - x, w_y - y,
00123                            toplevel->page_current->place_list);
00124 
00125   w_current->inside_action = 1;
00126   i_set_state(w_current, ENDPASTE);
00127   o_place_start (w_current, w_x, w_y);
00128 }
00129 
00130 
00136 void o_buffer_init(void)
00137 {
00138   int i;
00139 
00140   for (i = 0 ; i < MAX_BUFFERS; i++) {
00141     object_buffer[i] = NULL;
00142   }
00143 }
00144 
00150 void o_buffer_free(GSCHEM_TOPLEVEL *w_current)
00151 {
00152   TOPLEVEL *toplevel = w_current->toplevel;
00153   int i;
00154 
00155   for (i = 0 ; i < MAX_BUFFERS; i++) {
00156     if (object_buffer[i]) {
00157       s_delete_object_glist(toplevel, object_buffer[i]);
00158       object_buffer[i] = NULL;
00159     }
00160   }
00161 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines