Updated copyright text/header in most source files.
[geda-gaf/peter-b.git] / gschem / src / o_slot.c
blob6c0f71288871d691ad8e155e56285a535f04a92c
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>
22 #include <stdio.h>
23 #ifdef HAVE_STRING_H
24 #include <string.h>
25 #endif
27 #include "gschem.h"
29 #ifdef HAVE_LIBDMALLOC
30 #include <dmalloc.h>
31 #endif
33 #define MAX_SLOT_SIZE 10
35 /*! \todo Finish function documentation!!!
36 * \brief Change slot of selected component
37 * \par Function Description
40 void o_slot_start (GSCHEM_TOPLEVEL *w_current, OBJECT *object)
42 char *slot_value;
44 /* single object for now */
45 if (object->type != OBJ_COMPLEX)
46 return;
48 slot_value = o_attrib_search_object_attribs_by_name (object, "slot", 0);
50 if (slot_value == NULL) {
51 /* we didn't find a slot=? attribute, make something up */
52 /* for now.. this is an error condition */
53 slot_value = g_strdup ("1");
56 slot_edit_dialog (w_current, slot_value);
57 g_free (slot_value);
60 /*! \todo Finish function documentation!!!
61 * \brief
62 * \par Function Description
65 void o_slot_end(GSCHEM_TOPLEVEL *w_current, OBJECT *object, const char *string)
67 TOPLEVEL *toplevel = w_current->toplevel;
68 OBJECT *new_obj;
69 char *slot_value;
70 char *numslots_value;
71 OBJECT *o_slot;
72 char *value = NULL;
73 int numslots;
74 int new_slot_number;
75 int status;
77 g_return_if_fail (object != NULL);
79 status = o_attrib_string_get_name_value (string, NULL, &value);
80 if (!status) {
81 s_log_message (_("Slot attribute malformed\n"));
82 return;
85 numslots_value =
86 o_attrib_search_object_attribs_by_name (object, "numslots", 0);
88 if (!numslots_value) {
89 s_log_message (_("numslots attribute missing\n"));
90 s_log_message (_("Slotting not allowed for this component\n"));
91 g_free (value);
92 return;
95 numslots = atoi (numslots_value);
96 g_free (numslots_value);
98 new_slot_number = atoi (value);
100 #if DEBUG
101 printf ("numslots = %d\n", numslots);
102 #endif
104 if (new_slot_number > numslots || new_slot_number <=0 ) {
105 s_log_message (_("New slot number out of range\n"));
106 g_free (value);
107 return;
110 /* first see if slot attribute already exists outside
111 * complex */
112 slot_value = s_slot_search_slot (object, &o_slot);
113 g_free (slot_value);
115 if (o_slot != NULL && !o_attrib_is_inherited (o_slot)) {
116 o_text_set_string (toplevel, o_slot, string);
118 if (o_slot->visibility == VISIBLE ||
119 (o_slot->visibility == INVISIBLE && toplevel->show_hidden_text)) {
120 o_invalidate (w_current, o_slot);
123 o_text_recreate (toplevel, o_slot);
125 /* this doesn't deal with the selection list
126 * item */
127 if (o_slot->visibility == VISIBLE ||
128 (o_slot->visibility == INVISIBLE && toplevel->show_hidden_text)) {
129 o_invalidate (w_current, o_slot);
132 } else {
133 /* here you need to do the add the slot
134 attribute since it doesn't exist */
135 new_obj = o_text_new (toplevel, OBJ_TEXT, ATTRIBUTE_COLOR,
136 object->complex->x, object->complex->y,
137 LOWER_LEFT, 0, /* zero is angle */
138 string, 10, INVISIBLE, SHOW_NAME_VALUE);
139 s_page_append (toplevel, toplevel->page_current, new_obj);
141 /* manually attach attribute */
142 o_attrib_attach (toplevel, new_obj, object, FALSE);
145 o_invalidate (w_current, object);
146 s_slot_update_object (toplevel, object);
148 o_invalidate (w_current,object);
150 toplevel->page_current->CHANGED = 1;
151 g_free (value);