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
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
)
41 /* single object for now */
42 if (object
->type
!= OBJ_COMPLEX
)
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
);
60 /*! \todo Finish function documentation!!!
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
);
77 g_return_if_fail (object
!= NULL
);
79 status
= o_attrib_string_get_name_value (string
, NULL
, &value
);
81 s_log_message (_("Slot attribute malformed\n"));
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"));
95 numslots
= atoi (numslots_value
);
96 g_free (numslots_value
);
98 new_slot_number
= atoi (value
);
101 printf ("numslots = %d\n", numslots
);
104 if (new_slot_number
> numslots
|| new_slot_number
<=0 ) {
105 s_log_message (_("New slot number out of range\n"));
110 /* first see if slot attribute already exists outside
112 slot_value
= s_slot_search_slot (object
, &o_slot
);
115 if (o_slot
!= NULL
&& !o_attrib_is_inherited (o_slot
)) {
116 o_text_set_string (toplevel
, o_slot
, string
);
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"));