gschem

o_slot.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-2011 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 
00022 #include <stdio.h>
00023 #ifdef HAVE_STRING_H
00024 #include <string.h>
00025 #endif
00026 
00027 #include "gschem.h"
00028 
00029 #ifdef HAVE_LIBDMALLOC
00030 #include <dmalloc.h>
00031 #endif
00032 
00033 #define MAX_SLOT_SIZE 10
00034 
00040 void o_slot_start (GSCHEM_TOPLEVEL *w_current, OBJECT *object)
00041 {
00042   char *slot_value;
00043 
00044   /* single object for now */
00045   if (object->type != OBJ_COMPLEX)
00046     return;
00047 
00048   slot_value = o_attrib_search_object_attribs_by_name (object, "slot", 0);
00049 
00050   if (slot_value == NULL) {
00051     /* we didn't find a slot=? attribute, make something up */
00052     /* for now.. this is an error condition */
00053     slot_value = g_strdup ("1");
00054   }
00055 
00056   slot_edit_dialog (w_current, slot_value);
00057   g_free (slot_value);
00058 }
00059 
00065 void o_slot_end(GSCHEM_TOPLEVEL *w_current, OBJECT *object, const char *string)
00066 {
00067   TOPLEVEL *toplevel = w_current->toplevel;
00068   OBJECT *new_obj;
00069   char *slot_value;
00070   char *numslots_value;
00071   OBJECT *o_slot;
00072   char *value = NULL;
00073   int numslots;
00074   int new_slot_number;
00075   int status;
00076 
00077   g_return_if_fail (object != NULL);
00078 
00079   status = o_attrib_string_get_name_value (string, NULL, &value);
00080   if (!status) {
00081     s_log_message (_("Slot attribute malformed\n"));
00082     return;
00083   }
00084 
00085   numslots_value =
00086     o_attrib_search_object_attribs_by_name (object, "numslots", 0);
00087 
00088   if (!numslots_value) {
00089     s_log_message (_("numslots attribute missing\n"));
00090     s_log_message (_("Slotting not allowed for this component\n"));
00091     g_free (value);
00092     return;
00093   }
00094 
00095   numslots = atoi (numslots_value);
00096   g_free (numslots_value);
00097 
00098   new_slot_number = atoi (value);
00099 
00100 #if DEBUG
00101   printf ("numslots = %d\n", numslots);
00102 #endif
00103 
00104   if (new_slot_number > numslots || new_slot_number <=0 ) {
00105     s_log_message (_("New slot number out of range\n"));
00106     g_free (value);
00107     return;
00108   }
00109 
00110   /* first see if slot attribute already exists outside
00111    * complex */
00112   slot_value = s_slot_search_slot (object, &o_slot);
00113   g_free (slot_value);
00114 
00115   if (o_slot != NULL && !o_attrib_is_inherited (o_slot)) {
00116     o_text_set_string (toplevel, o_slot, string);
00117   } else {
00118     /* here you need to do the add the slot
00119        attribute since it doesn't exist */
00120     new_obj = o_text_new (toplevel, OBJ_TEXT, ATTRIBUTE_COLOR,
00121                           object->complex->x, object->complex->y,
00122                           LOWER_LEFT, 0, /* zero is angle */
00123                           string, 10, INVISIBLE, SHOW_NAME_VALUE);
00124     s_page_append (toplevel, toplevel->page_current, new_obj);
00125 
00126     /* manually attach attribute */
00127     o_attrib_attach (toplevel, new_obj, object, FALSE);
00128 
00129     /* Call add-objects-hook */
00130     g_run_hook_object (w_current, "%add-objects-hook", new_obj);
00131   }
00132 
00133   s_slot_update_object (toplevel, object);
00134 
00135   toplevel->page_current->CHANGED = 1;
00136   g_free (value);
00137 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines