gschem

g_attrib.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * gschem - gEDA Schematic Capture
00003  * Copyright (C) 2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00018  */
00019 
00026 #include <config.h>
00027 #include <missing.h>
00028 
00029 #include "gschem.h"
00030 
00031 SCM_SYMBOL (name_sym , "name");
00032 SCM_SYMBOL (value_sym , "value");
00033 SCM_SYMBOL (both_sym , "both");
00034 SCM_SYMBOL (object_state_sym, "object-state");
00035 
00070 SCM_DEFINE (add_attrib_x, "%add-attrib!", 5, 0, 0,
00071             (SCM target_s, SCM name_s, SCM value_s, SCM visible_s, SCM show_s),
00072             "Add an attribute to an object, or floating")
00073 {
00074   SCM_ASSERT ((edascm_is_page (target_s) ||
00075                edascm_is_object (target_s) ||
00076                scm_is_false (target_s)),
00077               target_s, SCM_ARG1, s_add_attrib_x);
00078   SCM_ASSERT (scm_is_string (name_s), name_s, SCM_ARG2, s_add_attrib_x);
00079   SCM_ASSERT (scm_is_string (value_s), value_s, SCM_ARG3, s_add_attrib_x);
00080   SCM_ASSERT (scm_is_symbol (show_s), show_s, SCM_ARG5, s_add_attrib_x);
00081 
00082   GSCHEM_TOPLEVEL *w_current = g_current_window ();
00083   TOPLEVEL *toplevel = w_current->toplevel;
00084 
00085   /* Check target object, if present */
00086   OBJECT *obj = NULL;
00087   if (edascm_is_object (target_s)) {
00088     obj = edascm_to_object (target_s);
00089     if (o_get_page (toplevel, obj) != toplevel->page_current) {
00090       scm_error (object_state_sym,
00091                  s_add_attrib_x,
00092                  _("Object ~A is not included in the current gschem page."),
00093                  scm_list_1 (target_s), SCM_EOL);
00094     }
00095   }
00096 
00097   /* Visibility */
00098   int visibility;
00099   if (scm_is_false (visible_s)) {
00100     visibility = INVISIBLE;
00101   } else {
00102     visibility = VISIBLE;
00103   }
00104 
00105   /* Name/value visibility */
00106   int show;
00107   if      (show_s == name_sym)  { show = SHOW_NAME;       }
00108   else if (show_s == value_sym) { show = SHOW_VALUE;      }
00109   else if (show_s == both_sym)  { show = SHOW_NAME_VALUE; }
00110   else {
00111     scm_misc_error (s_add_attrib_x,
00112                     _("Invalid text name/value visibility ~A."),
00113                     scm_list_1 (show_s));
00114   }
00115 
00116 
00117   scm_dynwind_begin (0);
00118 
00119   char *name;
00120   name = scm_to_utf8_string (name_s);
00121   scm_dynwind_free (name);
00122 
00123   char *value;
00124   value = scm_to_utf8_string (value_s);
00125   scm_dynwind_free (value);
00126 
00127   gchar *str = g_strdup_printf ("%s=%s", name, value);
00128   scm_dynwind_unwind_handler (g_free, str, SCM_F_WIND_EXPLICITLY);
00129 
00130   OBJECT *result = o_attrib_add_attrib (w_current, str, visibility, show, obj);
00131 
00132   scm_dynwind_end ();
00133 
00134   return edascm_from_object (result);
00135 }
00136 
00143 static void
00144 init_module_gschem_core_attrib ()
00145 {
00146   /* Register the functions and symbols */
00147   #include "g_attrib.x"
00148 
00149   /* Add them to the module's public definitions. */
00150   scm_c_export (s_add_attrib_x, NULL);
00151 }
00152 
00160 void
00161 g_init_attrib ()
00162 {
00163   /* Define the (gschem core attrib) module */
00164   scm_c_define_module ("gschem core attrib",
00165                        init_module_gschem_core_attrib,
00166                        NULL);
00167 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines