1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2000 Ales V. Hvezda
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
26 #include <libgeda/libgeda.h>
28 #include "../include/globals.h"
29 #include "../include/prototype.h"
31 #ifdef HAVE_LIBDMALLOC
35 #define MAX_SLOT_SIZE 10
37 /*! \todo Finish function documentation!!!
38 * \brief Change slot of selected component
39 * \par Function Description
42 void o_slot_start(TOPLEVEL
*w_current
, OBJECT
*list
)
45 OBJECT
*slot_text_object
;
46 char *default_slot_value
;
49 /* shouldn't happen */
51 /* this is an error condition hack */
52 w_current
->inside_action
= 0;
53 i_set_state(w_current
, SELECT
);
57 object
= o_select_return_first_object(w_current
);
59 /* single object for now */
60 if (object
->type
== OBJ_COMPLEX
) {
61 /* first see if slot attribute already exists outside
63 slot_value
= o_attrib_search_slot(object
, &slot_text_object
);
67 printf("slot=%s\n", slot_value
);
68 printf("text string : %s\n",
69 slot_text_object
->text
->string
);
71 slot_edit_dialog(w_current
,
72 slot_text_object
->text
->string
);
75 /* we didn't find an attached slot=? attribute */
77 /* See if there is a default value */
79 o_attrib_search_default_slot(object
);
81 if (default_slot_value
) {
82 /* two is for null and equals sign */
83 slot_value
= (char *) g_malloc(sizeof(char)*(
85 strlen(default_slot_value
)+
87 sprintf(slot_value
, "slot=%s",
90 /* no default, make something up? */
91 /* for now.. this is an error
93 slot_value
= g_strdup ("slot=1");
97 printf("slot value: %s\n", slot_value
);
100 slot_edit_dialog(w_current
, slot_value
);
102 g_free(default_slot_value
);
107 /*! \todo Finish function documentation!!!
109 * \par Function Description
112 void o_slot_end(TOPLEVEL
*w_current
, char *string
, int len
)
117 char *numslots_value
;
118 OBJECT
*slot_text_object
;
125 status
= o_attrib_get_name_value(string
, &name
, &value
);
127 s_log_message(_("Slot attribute malformed\n"));
131 object
= o_select_return_first_object(w_current
);
133 /* get the parent object if the selection is only a text object */
134 if (object
!= NULL
&& object
->type
== OBJ_TEXT
) {
135 if (object
->attached_to
!= NULL
) {
136 object
=o_attrib_return_parent(object
->attached_to
);
140 /* now find the slot attribute on the outside first */
141 if (object
!= NULL
) {
142 numslots_value
= o_attrib_search_numslots(object
, NULL
);
144 if (!numslots_value
) {
145 s_log_message(_("numslots attribute missing\n"));
147 _("Slotting not allowed for this component\n"));
148 if (name
) g_free(name
);
149 if (value
) g_free(value
);
153 numslots
= atoi(numslots_value
);
154 g_free(numslots_value
);
156 new_slot_number
= atoi(value
);
159 printf("numslots = %d\n", numslots
);
162 if (new_slot_number
> numslots
|| new_slot_number
<=0 ) {
163 s_log_message(_("New slot number out of range\n"));
164 if (name
) g_free(name
);
165 if (value
) g_free(value
);
169 /* first see if slot attribute already exists outside
171 slot_value
= o_attrib_search_slot(object
, &slot_text_object
);
174 if (slot_text_object
->text
->string
) {
175 g_free(slot_text_object
->text
->string
);
178 slot_text_object
->text
->string
= g_strdup (string
);
180 temp
= slot_text_object
;
182 if (temp
->visibility
== VISIBLE
||
183 (temp
->visibility
== INVISIBLE
&& w_current
->show_hidden_text
)) {
184 o_erase_single(w_current
,temp
);
187 o_text_recreate(w_current
, temp
);
189 /* this doesn't deal with the selection list
191 if (temp
->visibility
== VISIBLE
||
192 (temp
->visibility
== INVISIBLE
&& w_current
->show_hidden_text
)) {
193 o_redraw_single(w_current
,temp
);
199 /* here you need to do the add the slot
200 attribute since it doesn't exist */
201 w_current
->page_current
->object_tail
=
202 (OBJECT
*) o_text_add(
204 w_current
->page_current
->object_tail
,
205 OBJ_TEXT
, w_current
->text_color
,
206 object
->complex->x
, object
->complex->y
,
208 0, /* zero is angle */
211 INVISIBLE
, SHOW_NAME_VALUE
);
213 /* manually attach attribute */
215 /* NEWSEL this is okay too, since tail is single obj */
216 o_attrib_attach(w_current
,
217 w_current
->page_current
->object_head
,
218 w_current
->page_current
->object_tail
,
222 w_current
->page_current
->object_tail
;
225 o_erase_single(w_current
, object
);
226 o_attrib_slot_update(w_current
, object
);
231 /* erase the selection list */
232 o_erase_selected(w_current
);
234 o_attrib_slot_copy(w_current
, object
,
235 w_current
->page_current
->selection_list
);
236 o_redraw_single(w_current
,object
);
239 o_redraw_single(w_current
,object
);
241 w_current
->page_current
->CHANGED
= 1;
242 if (name
) g_free(name
);
243 if (value
) g_free(value
);
247 _("uggg! you tried to slot edit something that doesn't exist!\n"));
248 if (name
) g_free(name
);
249 if (value
) g_free(value
);