Bump gEDA version
[geda-gaf.git] / gschem / src / o_slot.c
blob133d55502672b4e0fb966880f578774521f47150
1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2020 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 #define MAX_SLOT_SIZE 10
31 /*! \todo Finish function documentation!!!
32 * \brief Change slot of selected component
33 * \par Function Description
36 void o_slot_start (GschemToplevel *w_current, OBJECT *object)
38 char *slot_count;
39 char *slot_value;
41 /* single object for now */
42 if (object->type != OBJ_COMPLEX)
43 return;
45 slot_count = o_attrib_search_object_attribs_by_name (object, "numslots", 0);
46 slot_value = o_attrib_search_object_attribs_by_name (object, "slot", 0);
48 if (slot_value == NULL) {
49 /* we didn't find a slot=? attribute, make something up */
50 /* for now.. this is an error condition */
51 slot_value = g_strdup ("1");
54 slot_edit_dialog (w_current, slot_count, slot_value);
56 g_free (slot_count);
57 g_free (slot_value);
60 /*! \todo Finish function documentation!!!
61 * \brief
62 * \par Function Description
65 void o_slot_end(GschemToplevel *w_current, OBJECT *object, const char *string)
67 TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current);
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);
117 } else {
118 /* here you need to do the add the slot
119 attribute since it doesn't exist */
120 new_obj = o_text_new (toplevel, ATTRIBUTE_COLOR,
121 object->complex->x, object->complex->y,
122 LOWER_LEFT, 0, /* zero is angle */
123 string, 10, INVISIBLE, SHOW_NAME_VALUE);
124 s_page_append (toplevel, toplevel->page_current, new_obj);
126 /* manually attach attribute */
127 o_attrib_attach (toplevel, new_obj, object, FALSE);
129 /* Call add-objects-hook */
130 g_run_hook_object (w_current, "%add-objects-hook", new_obj);
133 s_slot_update_object (toplevel, object);
135 gschem_toplevel_page_content_changed (w_current, toplevel->page_current);
136 o_undo_savestate_old (w_current, UNDO_ALL, _("Change Slot"));
137 g_free (value);