/*! \brief Delete text object * * Delete the text object pointed to by text_object. This function * was shamelessly stolen from gschem/src/o_delete.c and hacked * for gattrib by SDB. * \param toplevel TOPLEVEL to be operated on * \param test_object text object to be deleted */ void s_object_delete_text_object_in_object (TOPLEVEL *toplevel, OBJECT * text_object) { s_page_remove (toplevel, toplevel->page_current, text_object); s_delete_object (toplevel, text_object); toplevel->page_current->CHANGED = 1; }
/*! \brief Delete an object. * \par Function Description * This function erases the object \a object before deleting it. It * deals with connection and object connected to it. * * \param [in] w_current The GschemToplevel object. * \param [in] object The object to delete. */ void o_delete (GschemToplevel *w_current, OBJECT *object) { TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current); g_return_if_fail (object != NULL); o_selection_remove (toplevel, toplevel->page_current->selection_list, object); s_page_remove (toplevel, toplevel->page_current, object); g_run_hook_object (w_current, "%remove-objects-hook", object); s_delete_object (toplevel, object); gschem_toplevel_page_content_changed (w_current, toplevel->page_current); }
/*! \todo Finish function documentation!!! * \brief * \par Function Description * */ void s_delete_object(TOPLEVEL *toplevel, OBJECT *o_current) { if (o_current != NULL) { /* If currently attached to a page, remove it from the page */ if (o_current->page != NULL) { s_page_remove (toplevel, o_current->page, o_current); } s_conn_remove_object_connections (toplevel, o_current); if (o_current->attached_to != NULL) { /* do the actual remove */ o_attrib_remove(toplevel, &o_current->attached_to->attribs, o_current); } /* printf("sdeleting line\n"); */ geda_line_free (o_current->line); o_current->line = NULL; geda_path_free (o_current->path); o_current->path = NULL; /* printf("sdeleting circle\n");*/ geda_circle_free (o_current->circle); o_current->circle = NULL; /* printf("sdeleting arc\n");*/ geda_arc_free (o_current->arc); o_current->arc = NULL; /* printf("sdeleting box\n");*/ geda_box_free (o_current->box); o_current->box = NULL; geda_picture_free (o_current->picture); o_current->picture = NULL; if (o_current->text) { /*printf("sdeleting text->string\n");*/ g_free(o_current->text->string); o_current->text->string = NULL; g_free(o_current->text->disp_string); /* printf("sdeleting text\n");*/ g_free(o_current->text); } o_current->text = NULL; /* printf("sdeleting name\n");*/ g_free(o_current->name); o_current->name = NULL; /* printf("sdeleting complex_basename\n");*/ g_free(o_current->complex_basename); o_current->complex_basename = NULL; if (o_current->complex) { if (o_current->complex->prim_objs) { /* printf("sdeleting complex->primitive_objects\n");*/ geda_object_list_delete (toplevel, o_current->complex->prim_objs); o_current->complex->prim_objs = NULL; } g_free(o_current->complex); o_current->complex = NULL; } o_attrib_detach_all (toplevel, o_current); o_current->weak_refs = s_weakref_notify (o_current, o_current->weak_refs); g_free(o_current); /* assuming it is not null */ o_current=NULL; /* misc clean up */ } }
/*! \brief try to consolidate a net object * \par Function Description * This function tries to consolidate a net with any other object * that is connected to the current \a object. * * \param toplevel The TOPLEVEL object * \param object The object to consolidate * \return 0 if no consolidation was possible, -1 otherwise * */ int o_net_consolidate_segments(TOPLEVEL *toplevel, OBJECT *object) { int object_orient; int other_orient; GList *c_current; CONN *conn; OBJECT *other_object; int changed = 0; int reselect_new=FALSE; if (object == NULL) { return(0); } if (object->type != OBJ_NET) { return(0); } object_orient = o_net_orientation(object); c_current = object->conn_list; while(c_current != NULL) { conn = (CONN *) c_current->data; other_object = conn->other_object; /* only look at end points which have a valid end on the other side */ if (other_object != NULL && conn->type == CONN_ENDPOINT && conn->other_whichone != -1 && conn->whichone != -1 && o_net_consolidate_nomidpoint(object, conn->x, conn->y) ) { if (other_object->type == OBJ_NET) { other_orient = o_net_orientation(other_object); /* - both objects have the same orientation (either vert or horiz) */ /* - it's not the same object */ if (object_orient == other_orient && object->sid != other_object->sid && other_orient != NEITHER) { #if DEBUG printf("consolidating %s to %s\n", object->name, other_object->name); #endif o_net_consolidate_lowlevel(object, other_object, other_orient); changed++; if (other_object->selected == TRUE ) { o_selection_remove( toplevel->page_current->selection_list, other_object ); reselect_new=TRUE; } if (reselect_new == TRUE) { o_selection_remove( toplevel->page_current->selection_list, object ); o_selection_add( toplevel->page_current->selection_list, object ); } s_conn_remove_object (toplevel, other_object); s_page_remove (toplevel->page_current, other_object); s_delete_object (toplevel, other_object); o_net_recalc(toplevel, object); s_tile_update_object(toplevel, object); s_conn_update_object (toplevel, object); return(-1); } } } c_current = g_list_next (c_current); } return(0); }
/*! \brief Delete objects from the selection. * \par Function Description * This function deletes the objects selected on the current page of * toplevel \a w_current. * * \param [in] w_current The GschemToplevel object. */ void o_delete_selected (GschemToplevel *w_current) { TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current); SELECTION *selection = toplevel->page_current->selection_list; GList *to_remove; GList *iter; OBJECT *obj; unsigned int locked_num = 0; g_return_if_fail (o_select_selected (w_current)); to_remove = g_list_copy (geda_list_get_glist (selection)); for (iter = to_remove; iter != NULL; iter = g_list_next (iter)) { obj = (OBJECT *) iter->data; if (obj->selectable == FALSE) locked_num++; } if (locked_num > 0) { GList *non_locked = NULL; gint resp; GtkWidget *dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, ngettext ("Delete locked object?", "Delete %u locked objects?", locked_num), locked_num); gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_YES, GTK_RESPONSE_YES, GTK_STOCK_NO, GTK_RESPONSE_NO, NULL); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_NO); resp = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); switch (resp) { case GTK_RESPONSE_YES: /* Remove all */ break; case GTK_RESPONSE_NO: /* Remove non locked */ for (iter = to_remove; iter != NULL; iter = g_list_next (iter)) { obj = (OBJECT *) iter->data; if (obj->selectable == TRUE) non_locked = g_list_append (non_locked, iter->data); } g_list_free (to_remove); to_remove = non_locked; break; default: /* Cancel */ g_list_free (to_remove); return; } } for (iter = to_remove; iter != NULL; iter = g_list_next (iter)) { obj = (OBJECT *) iter->data; o_selection_remove (toplevel, selection, obj); s_page_remove (toplevel, toplevel->page_current, obj); } g_run_hook_object_list (w_current, "%remove-objects-hook", to_remove); for (iter = to_remove; iter != NULL; iter = g_list_next (iter)) { obj = (OBJECT *) iter->data; s_delete_object (toplevel, obj); } g_list_free (to_remove); gschem_toplevel_page_content_changed (w_current, toplevel->page_current); w_current->inside_action = 0; o_undo_savestate_old (w_current, UNDO_ALL); i_update_menus (w_current); }