gschem
|
00001 /* gEDA - GPL Electronic Design Automation 00002 * gschem - gEDA Schematic Capture 00003 * Copyright (C) 1998-2010 Ales Hvezda 00004 * Copyright (C) 1998-2011 gEDA Contributors (see ChangeLog for details) 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 #include <config.h> 00021 00022 #include <stdio.h> 00023 #ifdef HAVE_STRING_H 00024 #include <string.h> 00025 #endif 00026 #include <math.h> 00027 00028 #include "gschem.h" 00029 00030 #ifdef HAVE_LIBDMALLOC 00031 #include <dmalloc.h> 00032 #endif 00033 00034 /* No special type for attributes */ 00035 /* You can only edit text attributes */ 00036 00037 /* be sure in o_copy o_move o_delete you maintain the attributes */ 00038 /* delete is a bare, because you will have to unattach the other end */ 00039 /* and in o_save o_read as well */ 00040 /* and in o_select when selecting objects, select the attributes */ 00041 00042 /* there needs to be a modifier (in struct.h, such as a flag) which 00043 * signifies that this is an attribute */ 00044 00052 void o_attrib_add_selected(GSCHEM_TOPLEVEL *w_current, SELECTION *selection, 00053 OBJECT *selected) 00054 { 00055 OBJECT *a_current; 00056 GList *a_iter; 00057 GList *selected_objects = NULL; 00058 00059 g_assert( selection != NULL ); 00060 00061 for (a_iter = selected->attribs; a_iter != NULL; 00062 a_iter = g_list_next (a_iter)) { 00063 a_current = a_iter->data; 00064 00065 /* make sure object isn't selected already */ 00066 if (!a_current->selected) { 00067 o_selection_add (w_current->toplevel, selection, a_current); 00068 selected_objects = g_list_prepend (selected_objects, a_current); 00069 } 00070 } 00071 00072 if (selected_objects != NULL) { 00073 /* Run select-objects-hook */ 00074 g_run_hook_object_list (w_current, "%select-objects-hook", 00075 selected_objects); 00076 g_list_free (selected_objects); 00077 } 00078 } 00079 00091 void o_attrib_deselect_invisible (GSCHEM_TOPLEVEL *w_current, 00092 SELECTION *selection, 00093 OBJECT *selected) 00094 { 00095 OBJECT *a_current; 00096 GList *a_iter; 00097 00098 g_assert( selection != NULL ); 00099 00100 if (w_current->toplevel->show_hidden_text) { 00101 return; 00102 } 00103 00104 for (a_iter = selected->attribs; a_iter != NULL; 00105 a_iter = g_list_next (a_iter)) { 00106 a_current = a_iter->data; 00107 00108 if (a_current->selected && !o_is_visible(w_current->toplevel, a_current)) { 00109 o_selection_remove (w_current->toplevel, selection, a_current); 00110 } 00111 } 00112 } 00113 00125 void o_attrib_select_invisible (GSCHEM_TOPLEVEL *w_current, 00126 SELECTION *selection, 00127 OBJECT *selected) 00128 { 00129 OBJECT *a_current; 00130 GList *a_iter; 00131 00132 g_assert( selection != NULL ); 00133 00134 if (w_current->toplevel->show_hidden_text) { 00135 return; 00136 } 00137 00138 for (a_iter = selected->attribs; a_iter != NULL; 00139 a_iter = g_list_next (a_iter)) { 00140 a_current = a_iter->data; 00141 00142 if (!a_current->selected && !o_is_visible(w_current->toplevel, a_current)) { 00143 o_selection_add (w_current->toplevel, selection, a_current); 00144 } 00145 } 00146 } 00147 00157 void o_attrib_toggle_visibility(GSCHEM_TOPLEVEL *w_current, OBJECT *object) 00158 { 00159 TOPLEVEL *toplevel = w_current->toplevel; 00160 00161 g_return_if_fail (object != NULL && object->type == OBJ_TEXT); 00162 00163 if (o_is_visible (toplevel, object)) { 00164 /* only erase if we are not showing hidden text */ 00165 if (!toplevel->show_hidden_text) { 00166 o_invalidate (w_current, object); 00167 } 00168 00169 o_set_visibility (toplevel, object, INVISIBLE); 00170 00171 if (toplevel->show_hidden_text) { 00172 /* draw text so that little I is drawn */ 00173 o_invalidate (w_current, object); 00174 } 00175 00176 } else { 00177 /* if we are in the special show hidden mode, then erase text first */ 00178 /* to get rid of the little I */ 00179 if (toplevel->show_hidden_text) { 00180 o_invalidate (w_current, object); 00181 } 00182 00183 o_set_visibility (toplevel, object, VISIBLE); 00184 o_text_recreate(toplevel, object); 00185 } 00186 00187 toplevel->page_current->CHANGED = 1; 00188 } 00189 00200 void o_attrib_toggle_show_name_value(GSCHEM_TOPLEVEL *w_current, 00201 OBJECT *object, int show_name_value) 00202 { 00203 TOPLEVEL *toplevel = w_current->toplevel; 00204 00205 g_return_if_fail (object != NULL && object->type == OBJ_TEXT); 00206 00207 o_invalidate (w_current, object); 00208 object->show_name_value = show_name_value; 00209 o_text_recreate(toplevel, object); 00210 00211 toplevel->page_current->CHANGED = 1; 00212 } 00213 00214 00220 /* This function no longer returns NULL, but will always return the new */ 00221 /* text item */ 00222 OBJECT *o_attrib_add_attrib(GSCHEM_TOPLEVEL *w_current, 00223 const char *text_string, int visibility, 00224 int show_name_value, OBJECT *object) 00225 { 00226 TOPLEVEL *toplevel = w_current->toplevel; 00227 OBJECT *new_obj; 00228 int world_x = - 1, world_y = -1; 00229 int color; 00230 int left, right, top, bottom; 00231 OBJECT *o_current; 00232 00233 color = DETACHED_ATTRIBUTE_COLOR; 00234 00235 o_current = object; 00236 00237 /* creating a toplevel or unattached attribute */ 00238 if (o_current) { 00239 /* get coordinates of where to place the text object */ 00240 switch(o_current->type) { 00241 case(OBJ_COMPLEX): 00242 case(OBJ_PLACEHOLDER): 00243 world_x = o_current->complex->x; 00244 world_y = o_current->complex->y; 00245 color = ATTRIBUTE_COLOR; 00246 break; 00247 00248 case(OBJ_ARC): 00249 world_x = o_current->arc->x; 00250 world_y = o_current->arc->y; 00251 color = ATTRIBUTE_COLOR; 00252 break; 00253 00254 case(OBJ_CIRCLE): 00255 world_x = o_current->circle->center_x; 00256 world_y = o_current->circle->center_y; 00257 color = ATTRIBUTE_COLOR; 00258 break; 00259 00260 case(OBJ_BOX): 00261 world_x = o_current->box->upper_x; 00262 world_y = o_current->box->upper_y; 00263 color = ATTRIBUTE_COLOR; 00264 break; 00265 00266 case(OBJ_LINE): 00267 case(OBJ_NET): 00268 case(OBJ_PIN): 00269 case(OBJ_BUS): 00270 world_x = o_current->line->x[0]; 00271 world_y = o_current->line->y[0]; 00272 color = ATTRIBUTE_COLOR; 00273 break; 00274 00275 case(OBJ_TEXT): 00276 world_x = o_current->text->x; 00277 world_y = o_current->text->y; 00278 color = DETACHED_ATTRIBUTE_COLOR; 00279 o_current = NULL; 00280 break; 00281 } 00282 } else { 00283 world_get_object_glist_bounds (toplevel, 00284 s_page_objects (toplevel->page_current), 00285 &left, &top, &right, &bottom); 00286 00287 /* this really is the lower left hand corner */ 00288 world_x = left; 00289 world_y = top; 00290 00291 /* printf("%d %d\n", world_x, world_y); */ 00292 color = DETACHED_ATTRIBUTE_COLOR; 00293 } 00294 00295 /* first create text item */ 00296 new_obj = o_text_new(toplevel, OBJ_TEXT, color, world_x, world_y, 00297 LOWER_LEFT, 0, text_string, /* zero is angle */ 00298 w_current->text_size, /* current text size */ 00299 visibility, show_name_value); 00300 s_page_append (toplevel, toplevel->page_current, new_obj); 00301 00302 /* now attach the attribute to the object (if o_current is not NULL) */ 00303 /* remember that o_current contains the object to get the attribute */ 00304 if (o_current) { 00305 o_attrib_attach (toplevel, new_obj, o_current, FALSE); 00306 } 00307 00308 o_selection_add (toplevel, toplevel->page_current->selection_list, new_obj); 00309 00310 /* handle slot= attribute, it's a special case */ 00311 if (o_current != NULL && 00312 g_ascii_strncasecmp (text_string, "slot=", 5) == 0) { 00313 o_slot_end (w_current, o_current, text_string); 00314 } 00315 00316 /* Call add-objects-hook. */ 00317 g_run_hook_object (w_current, "%add-objects-hook", new_obj); 00318 g_run_hook_object (w_current, "%select-objects-hook", new_obj); 00319 00320 toplevel->page_current->CHANGED = 1; 00321 00322 return new_obj; 00323 }