Cleaned up and consolidated code which creates new pages.
[geda-gaf.git] / gschem / src / o_slot.c
blob95c278467c58eeda914eabbc896d98144fd9b958
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
19 #include <config.h>
21 #include <stdio.h>
22 #ifdef HAVE_STRING_H
23 #include <string.h>
24 #endif
26 #include <libgeda/libgeda.h>
28 #include "../include/globals.h"
29 #include "../include/prototype.h"
31 #ifdef HAVE_LIBDMALLOC
32 #include <dmalloc.h>
33 #endif
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)
44 OBJECT *object;
45 OBJECT *slot_text_object;
46 char *default_slot_value;
47 char *slot_value;
49 /* shouldn't happen */
50 if (list == NULL) {
51 /* this is an error condition hack */
52 w_current->inside_action = 0;
53 i_set_state(w_current, SELECT);
54 return;
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
62 * complex */
63 slot_value = o_attrib_search_slot(object, &slot_text_object);
65 if (slot_value) {
66 #if DEBUG
67 printf("slot=%s\n", slot_value);
68 printf("text string : %s\n",
69 slot_text_object->text->string);
70 #endif
71 slot_edit_dialog(w_current,
72 slot_text_object->text->string);
73 g_free(slot_value);
74 } else {
75 /* we didn't find an attached slot=? attribute */
77 /* See if there is a default value */
78 default_slot_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)*(
84 strlen("slot")+
85 strlen(default_slot_value)+
86 2));
87 sprintf(slot_value, "slot=%s",
88 default_slot_value);
89 } else {
90 /* no default, make something up? */
91 /* for now.. this is an error
92 condition */
93 slot_value = g_strdup ("slot=1");
96 #if DEBUG
97 printf("slot value: %s\n", slot_value);
98 #endif
100 slot_edit_dialog(w_current, slot_value);
101 g_free(slot_value);
102 g_free(default_slot_value);
107 /*! \todo Finish function documentation!!!
108 * \brief
109 * \par Function Description
112 void o_slot_end(TOPLEVEL *w_current, char *string, int len)
114 OBJECT *object;
115 OBJECT *temp;
116 char *slot_value;
117 char *numslots_value;
118 OBJECT *slot_text_object;
119 char *name = NULL;
120 char *value = NULL;
121 int numslots;
122 int new_slot_number;
123 int status;
125 status = o_attrib_get_name_value(string, &name, &value);
126 if (!status) {
127 s_log_message(_("Slot attribute malformed\n"));
128 return;
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"));
146 s_log_message(
147 _("Slotting not allowed for this component\n"));
148 if (name) g_free(name);
149 if (value) g_free(value);
150 return;
153 numslots = atoi(numslots_value);
154 g_free(numslots_value);
156 new_slot_number = atoi(value);
158 #if DEBUG
159 printf("numslots = %d\n", numslots);
160 #endif
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);
166 return;
169 /* first see if slot attribute already exists outside
170 * complex */
171 slot_value = o_attrib_search_slot(object, &slot_text_object);
173 if (slot_value) {
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
190 * item */
191 if (temp->visibility == VISIBLE ||
192 (temp->visibility == INVISIBLE && w_current->show_hidden_text)) {
193 o_redraw_single(w_current,temp);
196 g_free(slot_value);
198 } else {
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(
203 w_current,
204 w_current->page_current->object_tail,
205 OBJ_TEXT, w_current->text_color,
206 object->complex->x, object->complex->y,
207 LOWER_LEFT,
208 0, /* zero is angle */
209 string,
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,
219 object);
221 slot_text_object =
222 w_current->page_current->object_tail;
225 o_erase_single(w_current, object);
226 o_attrib_slot_update(w_current, object);
229 #if 0 /* NEWSEL */
230 /* why? */
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);
237 #endif
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);
245 } else {
246 fprintf(stderr,
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);
250 exit(-1);