gschem

g_select.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * gschem - gEDA Schematic Capture
00003  * Copyright (C) 2010 Peter Brett <peter@peter-b.co.uk>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
00018  */
00019 #include <config.h>
00020 
00021 #include "gschem.h"
00022 
00023 SCM_SYMBOL (object_state_sym, "object-state");
00024 
00035 SCM_DEFINE (page_selection, "%page-selection", 1, 0, 0,
00036             (SCM page_s), "Get a list of a page's selected objects")
00037 {
00038   /* Ensure that the argument is a page smob */
00039   SCM_ASSERT (edascm_is_page (page_s), page_s,
00040               SCM_ARG1, s_page_selection);
00041 
00042   PAGE *page = edascm_to_page (page_s);
00043   GList *iter;
00044   SCM result = SCM_EOL;
00045   for (iter = geda_list_get_glist (page->selection_list);
00046        iter != NULL; iter = g_list_next (iter)) {
00047     result = scm_cons (edascm_from_object ((OBJECT *) iter->data), result);
00048   }
00049 
00050   return result;
00051 }
00052 
00066 SCM_DEFINE (select_object_x, "%select-object!", 1, 0, 0,
00067             (SCM obj_s), "Select an object.")
00068 {
00069   /* Ensure that the argument is an object smob */
00070   SCM_ASSERT (edascm_is_object (obj_s), obj_s,
00071               SCM_ARG1, s_select_object_x);
00072 
00073   TOPLEVEL *toplevel = edascm_c_current_toplevel ();
00074   OBJECT *obj = edascm_to_object (obj_s);
00075   PAGE *page = o_get_page (toplevel, obj);
00076   if ((page == NULL) || (obj->parent != NULL)) {
00077     scm_error (object_state_sym,
00078                s_select_object_x,
00079                _("Object ~A is not directly included in a page."),
00080                scm_list_1 (obj_s), SCM_EOL);
00081   }
00082 
00083   if (!obj->selected) {
00084     o_selection_add (toplevel, page->selection_list, obj);
00085   }
00086 
00087   return obj_s;
00088 }
00089 
00103 SCM_DEFINE (deselect_object_x, "%deselect-object!", 1, 0, 0,
00104             (SCM obj_s), "Deselect an object.")
00105 {
00106   /* Ensure that the argument is an object smob */
00107   SCM_ASSERT (edascm_is_object (obj_s), obj_s,
00108               SCM_ARG1, s_deselect_object_x);
00109 
00110   TOPLEVEL *toplevel = edascm_c_current_toplevel ();
00111   OBJECT *obj = edascm_to_object (obj_s);
00112   PAGE *page = o_get_page (toplevel, obj);
00113   if ((page == NULL) || (obj->parent != NULL)) {
00114     scm_error (object_state_sym,
00115                s_deselect_object_x,
00116                _("Object ~A is not directly included in a page."),
00117                scm_list_1 (obj_s), SCM_EOL);
00118   }
00119 
00120   if (obj->selected) {
00121     o_selection_remove (toplevel, page->selection_list, obj);
00122   }
00123 
00124   return obj_s;
00125 }
00126 
00139 SCM_DEFINE (object_selected_p, "%object-selected?", 1, 0, 0,
00140             (SCM obj_s), "Test if an object is selected.")
00141 {
00142   /* Ensure that the argument is an object smob */
00143   SCM_ASSERT (edascm_is_object (obj_s), obj_s,
00144               SCM_ARG1, s_object_selected_p);
00145 
00146   TOPLEVEL *toplevel = edascm_c_current_toplevel ();
00147   OBJECT *obj = edascm_to_object (obj_s);
00148   PAGE *page = o_get_page (toplevel, obj);
00149   if ((page == NULL) || (obj->parent != NULL)) {
00150     scm_error (object_state_sym,
00151                s_object_selected_p,
00152                _("Object ~A is not directly included in a page."),
00153                scm_list_1 (obj_s), SCM_EOL);
00154   }
00155   return (obj->selected ? SCM_BOOL_T : SCM_BOOL_F);
00156 }
00157 
00163 static void
00164 init_module_gschem_core_select ()
00165 {
00166   /* Register the functions */
00167   #include "g_select.x"
00168 
00169   /* Add them to the module's public definitions. */
00170   scm_c_export (s_page_selection, s_select_object_x, s_deselect_object_x,
00171                 s_object_selected_p, NULL);
00172 }
00173 
00179 void
00180 g_init_select ()
00181 {
00182   /* Define the (gschem core selection) module */
00183   scm_c_define_module ("gschem core selection",
00184                        init_module_gschem_core_select,
00185                        NULL);
00186 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines