/*! \brief Change visibility status of attribute object. * \par Function Description * This function toggles the visibility status of the attribute \a * object and updates it. The object is erased or redrawn if * necessary. * * \param [in] w_current The GschemToplevel object. * \param [in] object The attribute object. */ void o_attrib_toggle_visibility(GschemToplevel *w_current, OBJECT *object) { TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current); g_return_if_fail (object != NULL && object->type == OBJ_TEXT); if (o_is_visible (object)) { /* only erase if we are not showing hidden text */ if (!toplevel->show_hidden_text) { o_invalidate (w_current, object); } o_set_visibility (toplevel, object, INVISIBLE); if (toplevel->show_hidden_text) { /* draw text so that little I is drawn */ o_invalidate (w_current, object); } } else { /* if we are in the special show hidden mode, then erase text first */ /* to get rid of the little I */ if (toplevel->show_hidden_text) { o_invalidate (w_current, object); } o_set_visibility (toplevel, object, VISIBLE); o_text_recreate(toplevel, object); } gschem_toplevel_page_content_changed (w_current, toplevel->page_current); }
/*! \todo Finish function documentation!!! * \brief * \par Function Description * * \note * The object passed in should be the REAL object, NOT any copy in any * selection list */ void o_text_change(GschemToplevel *w_current, OBJECT *object, char *string, int visibility, int show) { GschemPageView *page_view = gschem_toplevel_get_current_page_view (w_current); TOPLEVEL *toplevel = gschem_page_view_get_toplevel (page_view); PAGE *page = gschem_page_view_get_page (page_view); g_return_if_fail (toplevel != NULL); g_return_if_fail (page != NULL); if (object == NULL) { return; } if (object->type != OBJ_TEXT) { return; } o_text_set_string (toplevel, object, string); o_set_visibility (toplevel, object, visibility); object->show_name_value = show; o_text_recreate(toplevel, object); /* handle slot= attribute, it's a special case */ if (object->attached_to != NULL && g_ascii_strncasecmp (string, "slot=", 5) == 0) { o_slot_end (w_current, object->attached_to, string); } gschem_toplevel_page_content_changed (w_current, page); }
/*! \todo Finish function documentation!!! * \brief * \par Function Description * */ void o_edit_show_specific_text (GSCHEM_TOPLEVEL *w_current, const GList *o_list, char *stext) { TOPLEVEL *toplevel = w_current->toplevel; OBJECT *o_current; const GList *iter; iter = o_list; while (iter != NULL) { o_current = (OBJECT *)iter->data; if (o_current->type == OBJ_TEXT) { const gchar *str = o_text_get_string (w_current->toplevel, o_current); if (!strncmp (stext, str, strlen (stext))) { if (!o_is_visible (toplevel, o_current)) { o_set_visibility (toplevel, o_current, VISIBLE); o_text_recreate(toplevel, o_current); toplevel->page_current->CHANGED = 1; } } } iter = g_list_next (iter); } o_undo_savestate(w_current, UNDO_ALL); }
/*! \todo Finish function documentation!!! * \brief * \par Function Description * */ void o_edit_show_specific_text (GschemToplevel *w_current, const GList *o_list, const char *stext) { TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current); OBJECT *o_current; const GList *iter; iter = o_list; while (iter != NULL) { o_current = (OBJECT *)iter->data; if (o_current->type == OBJ_TEXT) { const gchar *str = o_text_get_string (w_current->toplevel, o_current); if (!strncmp (stext, str, strlen (stext))) { if (!o_is_visible (toplevel, o_current)) { o_set_visibility (toplevel, o_current, VISIBLE); o_text_recreate(toplevel, o_current); gschem_toplevel_page_content_changed (w_current, toplevel->page_current); } } } iter = g_list_next (iter); } o_undo_savestate_old(w_current, UNDO_ALL); }
/*! \brief Replace attribute value in object * * Find the instance of attrib_name on o_current, and * replace its value with the new_attrib_value. * \param toplevel TOPLEVEL object * \param o_current object to operate on * \param new_attrib_name name of attribute to replace * \param new_attrib_value value to set attribute to * \param visibility set visibility of attribute * \param show_name_value set visibility of attribute name and value */ void s_object_replace_attrib_in_object(TOPLEVEL *toplevel, OBJECT *o_current, char *new_attrib_name, char *new_attrib_value, gint visibility, gint show_name_value) { GList *a_iter; OBJECT *a_current; char *old_attrib_text; char *old_attrib_name; char *new_attrib_text; a_iter = o_current->attribs; while (a_iter != NULL) { a_current = a_iter->data; if (a_current->type == OBJ_TEXT && a_current->text != NULL) { /* found an attribute */ /* may need to check more thoroughly here. . . . */ old_attrib_text = g_strdup(a_current->text->string); old_attrib_name = u_basic_breakup_string(old_attrib_text, '=', 0); if (strcmp(old_attrib_name, new_attrib_name) == 0) { /* create attrib=value text string & stuff it back into toplevel */ new_attrib_text = g_strconcat(new_attrib_name, "=", new_attrib_value, NULL); g_free(a_current->text->string); /* remove old attrib string */ a_current->text->string = g_strdup(new_attrib_text); /* insert new attrib string */ if (visibility != LEAVE_VISIBILITY_ALONE) o_set_visibility (toplevel, a_current, visibility); if (show_name_value != LEAVE_NAME_VALUE_ALONE) a_current->show_name_value = show_name_value; g_free(new_attrib_text); g_free(old_attrib_text); g_free(old_attrib_name); return; /* we are done -- leave. */ } else { g_free(old_attrib_text); g_free(old_attrib_name); } /* if (strcmp . . . . */ } /* if (a_current . . . . */ a_iter = g_list_next (a_iter); } /* while */ /* if we get here, it's because we have failed to find the attrib on the component. * This is an error condition. */ fprintf(stderr, _("In s_object_replace_attrib_in_object, we have failed to find the attrib %s on the component. Exiting . . .\n"), new_attrib_name); exit(-1); }
/*! \brief Creates a text OBJECT and the graphical objects representing it * \par Function Description * Create an OBJECT of type OBJ_TEXT. * * \param [in] toplevel The TOPLEVEL object. * \param [in] type OBJ_TEXT (TODO: why bother) * \param [in] color The color of the text. * \param [in] x World x coord of text. * \param [in] y World y coord of text. * \param [in] alignment How text bounding box aligns on (x, y). * \param [in] angle Angle at which text will appear. * \param [in] string The text (TODO: can be char const *)! * \param [in] size Text size. * \param [in] visibility VISIBLE or INVISIBLE. * \param [in] show_name_value SHOW_NAME_VALUE or friends. * \return Pointer to text OBJECT. * * \note * Caller is responsible for string; this function allocates its own copy. */ GedaObject* geda_text_object_new (TOPLEVEL *toplevel, gint color, gint x, gint y, gint alignment, gint angle, const gchar *string, gint size, gint visibility, gint show_name_value) { GedaObject *new_node=NULL; TEXT *text; g_return_val_if_fail (string != NULL, NULL); new_node = s_basic_new_object (OBJ_TEXT, "text"); text = (TEXT *) g_malloc(sizeof(TEXT)); text->string = g_strdup (string); text->disp_string = NULL; /* We'll fix this up later */ text->length = strlen(string); text->size = size; text->alignment = alignment; text->x = x; text->y = y; text->angle = angle; text->name = NULL; new_node->text = text; new_node->color = color; o_set_visibility (toplevel, new_node, visibility); new_node->show_name_value = show_name_value; update_disp_string (new_node); /* Update bounding box */ new_node->w_bounds_valid_for = NULL; return new_node; }
/*! \brief Promote attributes from a complex OBJECT * \par Function Description * Selects promotable attributes from \a object, and returns a new * #GList containing them (suitable for appending to a #PAGE). * * \param [in] toplevel The #TOPLEVEL environment. * \param [in] object The complex #OBJECT to promote from. * \return A #GList of promoted attributes. */ GList *o_complex_promote_attribs (TOPLEVEL *toplevel, OBJECT *object) { GList *promoted = NULL; GList *promotable = NULL; GList *iter = NULL; promotable = o_complex_get_promotable (toplevel, object, FALSE); /* Run through the attributes deciding if we want to keep them (in * which case we copy them and make them invisible) or if we want to * remove them. */ if (toplevel->keep_invisible) { for (iter = promotable; iter != NULL; iter = g_list_next (iter)) { OBJECT *o_kept = (OBJECT *) iter->data; OBJECT *o_copy = o_object_copy (toplevel, o_kept); o_set_visibility (toplevel, o_kept, INVISIBLE); o_copy->parent = NULL; promoted = g_list_prepend (promoted, o_copy); } promoted = g_list_reverse (promoted); } else { for (iter = promotable; iter != NULL; iter = g_list_next (iter)) { OBJECT *o_removed = (OBJECT *) iter->data; o_removed->parent = NULL; object->complex->prim_objs = g_list_remove (object->complex->prim_objs, o_removed); } promoted = promotable; /* Invalidate the object's bounds since we may have * stolen objects from inside it. */ o_bounds_invalidate (toplevel, object); } /* Attach promoted attributes to the original complex object */ o_attrib_attach_list (toplevel, promoted, object, TRUE); return promoted; }
/*! \brief Delete or hide promotable from the passed OBJECT * * \par Function Description * Deletes or hides promotable attributes from the passed OBJECT. * This is used when loading symbols during the load of a schematic from * disk. The schematic will already contain local copies of symbol's * promotable objects, so we delete or hide the symbol's copies. * * Deletion / hiding is dependant on the setting of * toplevel->keep_invisible. If true, attributes eligible for * promotion are kept in memory but flagged as invisible. * * \param [in] toplevel The toplevel environment. * \param [in] object The complex object being altered. */ static void o_complex_remove_promotable_attribs (TOPLEVEL *toplevel, OBJECT *object) { GList *promotable, *iter; promotable = o_complex_get_promotable (toplevel, object, FALSE); if (promotable == NULL) return; for (iter = promotable; iter != NULL; iter = g_list_next (iter)) { OBJECT *a_object = iter->data; if (toplevel->keep_invisible == TRUE) { /* Hide promotable attributes */ o_set_visibility (toplevel, a_object, INVISIBLE); } else { /* Delete promotable attributes */ object->complex->prim_objs = g_list_remove (object->complex->prim_objs, a_object); s_delete_object (toplevel, a_object); } } o_bounds_invalidate (toplevel, object); g_list_free (promotable); }