[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gEDA-dev: [PATCH 05/17] Add new function to delete any object.



I'm still TRYING (losing hope though) to get this patch into one of my
branches so as not to get too far out of sync with master.  I wish you
had commented on the thread where the Peters and I were talking about
putting more knowledge of grips' locations into libgeda.  So far it's
proving to be a big win.

On Fri, Jul 25, 2008 at 5:52 PM, Patrick Bernaud <b-patrick@wanadoo.fr> wrote:
> Added o_delete() as replacement for individual object deletion
> function. Adapted o_delete_selected() accordingly.
> ---
>  gschem/include/prototype.h |    5 +-
>  gschem/src/i_callbacks.c   |    1 +
>  gschem/src/o_delete.c      |  312 +++++++-------------------------------------
>  gschem/src/o_move.c        |    4 +-
>  gschem/src/x_autonumber.c  |    2 +-
>  gschem/src/x_multiattrib.c |    2 +-
>  6 files changed, 51 insertions(+), 275 deletions(-)
>
> diff --git a/gschem/include/prototype.h b/gschem/include/prototype.h
> index 1bdc549..c8c4185 100644
> --- a/gschem/include/prototype.h
> +++ b/gschem/include/prototype.h
> @@ -566,10 +566,7 @@ void o_cue_draw_list(GSCHEM_TOPLEVEL *w_current, GList *object_list);
>  void o_cue_undraw_list(GSCHEM_TOPLEVEL *w_current, GList *object_list);
>  void o_cue_undraw_objects(GSCHEM_TOPLEVEL *w_current, OBJECT *list);
>  /* o_delete.c */
> -void o_delete_net(GSCHEM_TOPLEVEL *w_current, OBJECT *obj);
> -void o_delete_bus(GSCHEM_TOPLEVEL *w_current, OBJECT *obj);
> -void o_delete_complex(GSCHEM_TOPLEVEL *w_current, OBJECT *obj);
> -void o_delete_text(GSCHEM_TOPLEVEL *w_current, OBJECT *obj);
> +void o_delete(GSCHEM_TOPLEVEL *w_current, OBJECT *object);
>  void o_delete_selected(GSCHEM_TOPLEVEL *w_current);
>  /* o_find.c */
>  gboolean o_find_object(GSCHEM_TOPLEVEL *w_current, int x, int y,
> diff --git a/gschem/src/i_callbacks.c b/gschem/src/i_callbacks.c
> index a11fef1..d2c2553 100644
> --- a/gschem/src/i_callbacks.c
> +++ b/gschem/src/i_callbacks.c
> @@ -721,6 +721,7 @@ DEFINE_I_CALLBACK(edit_delete)
>     w_current->inside_action = 0;
>     i_set_state(w_current, SELECT);
>     i_update_toolbar(w_current);
> +    i_update_menus(w_current);
>   }
>  }
>
> diff --git a/gschem/src/o_delete.c b/gschem/src/o_delete.c
> index 3103ef3..e9249c1 100644
> --- a/gschem/src/o_delete.c
> +++ b/gschem/src/o_delete.c
> @@ -31,293 +31,71 @@
>  #include <dmalloc.h>
>  #endif
>
> -/*! \todo Finish function documentation!!!
> - *  \brief
> +/*! \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 GSCHEM_TOPLEVEL object.
> + *  \param [in] object    The object to delete.
>  */
> -void o_delete_net(GSCHEM_TOPLEVEL *w_current, OBJECT *obj)
> +void o_delete (GSCHEM_TOPLEVEL *w_current, OBJECT *object)
>  {
>   TOPLEVEL *toplevel = w_current->toplevel;
>   GList *other_objects = NULL;
> +  gboolean do_conn;
>
> -  o_cue_undraw(w_current, obj);
> +  g_return_if_fail (object != NULL);
>
> -  o_erase_single(w_current, obj);
> -  o_line_erase_grips(w_current, obj);
> -
> -  other_objects = s_conn_return_others(other_objects, obj);
> -
> -  s_delete(toplevel, obj);
> -
> -  toplevel->page_current->object_tail =
> -    (OBJECT *) return_tail(toplevel->page_current->object_head);
> -
> -  o_cue_undraw_list(w_current, other_objects);
> -  o_cue_draw_list(w_current, other_objects);
> -  g_list_free(other_objects);
> -}
> -
> -/*! \todo Finish function documentation!!!
> - *  \brief
> - *  \par Function Description
> - *
> - */
> -void o_delete_bus(GSCHEM_TOPLEVEL *w_current, OBJECT *obj)
> -{
> -  TOPLEVEL *toplevel = w_current->toplevel;
> -  GList *other_objects = NULL;
> -
> -  o_cue_undraw(w_current, obj);
> -  o_erase_single(w_current, obj);
> -  o_line_erase_grips(w_current, obj);
> -
> -  other_objects = s_conn_return_others(other_objects, obj);
> -
> -  s_delete(toplevel, obj);
> -
> -  toplevel->page_current->object_tail =
> -    (OBJECT *) return_tail(toplevel->page_current->object_head);
> -
> -  o_cue_undraw_list(w_current, other_objects);
> -  o_cue_draw_list(w_current, other_objects);
> -  g_list_free(other_objects);
> -
> -}
> -
> -/*! \todo Finish function documentation!!!
> - *  \brief
> - *  \par Function Description
> - *
> - */
> -static void o_delete_pin(GSCHEM_TOPLEVEL *w_current, OBJECT *obj)
> -{
> -  TOPLEVEL *toplevel = w_current->toplevel;
> -  GList *other_objects = NULL;
> -
> -  o_cue_undraw(w_current, obj);
> -  o_erase_single(w_current, obj);
> -  o_line_erase_grips(w_current, obj);
> -
> -  other_objects = s_conn_return_others(other_objects, obj);
> -
> -  s_delete(toplevel, obj);
> -  toplevel->page_current->object_tail =
> -    (OBJECT *) return_tail(toplevel->page_current->object_head);
> -
> -  o_cue_undraw_list(w_current, other_objects);
> -  o_cue_draw_list(w_current, other_objects);
> -  g_list_free(other_objects);
> -
> -}
> -
> -/*! \todo Finish function documentation!!!
> - *  \brief
> - *  \par Function Description
> - *
> - */
> -void o_delete_complex(GSCHEM_TOPLEVEL *w_current, OBJECT *obj)
> -{
> -  TOPLEVEL *toplevel = w_current->toplevel;
> -  GList *other_objects = NULL;
> -
> -  o_cue_undraw(w_current, obj);
> -  o_erase_single(w_current, obj);
> -
> -  other_objects = s_conn_return_complex_others(other_objects, obj);
> -
> -  s_delete(toplevel, obj);
> -
> -  /*! \todo special case hack no return_tail. why? */
> -  o_cue_undraw_list(w_current, other_objects);
> -  o_cue_draw_list(w_current, other_objects);
> -  g_list_free(other_objects);
> -}
> -
> -/*! \todo Finish function documentation!!!
> - *  \brief
> - *  \par Function Description
> - *
> - */
> -static void o_delete_line(GSCHEM_TOPLEVEL *w_current, OBJECT *obj)
> -{
> -  TOPLEVEL *toplevel = w_current->toplevel;
> -  o_erase_single(w_current, obj);
> -  o_line_erase_grips(w_current, obj);
> +  do_conn =
> +    object->type == OBJ_NET || object->type == OBJ_BUS ||
> +    object->type == OBJ_PIN || object->type == OBJ_COMPLEX;
>
> -  s_delete(toplevel, obj);
> -  toplevel->page_current->object_tail =
> -    (OBJECT *) return_tail(toplevel->page_current->object_head);
> -}
> -
> -/*! \todo Finish function documentation!!!
> - *  \brief
> - *  \par Function Description
> - *
> - */
> -static void o_delete_box(GSCHEM_TOPLEVEL *w_current, OBJECT *obj)
> -{
> -  TOPLEVEL *toplevel = w_current->toplevel;
> -  o_erase_single(w_current, obj);
> -  o_box_erase_grips(w_current, obj);
> -
> -  s_delete(toplevel, obj);
> -  toplevel->page_current->object_tail =
> -  (OBJECT *) return_tail(toplevel->page_current->object_head);
> -}
> -
> -
> -/*! \todo Finish function documentation!!!
> - *  \brief
> - *  \par Function Description
> - *
> - */
> -static void o_delete_picture(GSCHEM_TOPLEVEL *w_current, OBJECT *obj)
> -{
> -  TOPLEVEL *toplevel = w_current->toplevel;
> -  o_erase_single(w_current, obj);
> -  o_picture_erase_grips(w_current, obj);
> -
> -  s_delete(toplevel, obj);
> -  toplevel->page_current->object_tail =
> -  (OBJECT *) return_tail(toplevel->page_current->object_head);
> -}
> -
> -/*! \todo Finish function documentation!!!
> - *  \brief
> - *  \par Function Description
> - *
> - */
> -static void o_delete_circle(GSCHEM_TOPLEVEL *w_current, OBJECT *obj)
> -{
> -  TOPLEVEL *toplevel = w_current->toplevel;
> -       o_erase_single(w_current, obj);
> -       o_circle_erase_grips(w_current, obj);
> -
> -       s_delete(toplevel, obj);
> -
> -       toplevel->page_current->object_tail =
> -               (OBJECT *) return_tail(toplevel->page_current->object_head);
> -}
> -
> -/*! \todo Finish function documentation!!!
> - *  \brief
> - *  \par Function Description
> - *
> - */
> -void o_delete_text(GSCHEM_TOPLEVEL *w_current, OBJECT *obj)
> -{
> -  TOPLEVEL *toplevel = w_current->toplevel;
> -  OBJECT *o_parent = obj->attached_to;
> -
> -  o_erase_single(w_current, obj);
> -
> -  s_delete(toplevel, obj);
> -  toplevel->page_current->object_tail =
> -    (OBJECT *) return_tail(toplevel->page_current->object_head);
> -
> -  if (o_parent != NULL && o_parent->type == OBJ_COMPLEX)
> -    o_attrib_slot_update(toplevel, o_parent);
> -}
> +  if (do_conn) {
> +    o_cue_undraw (w_current, object);
> +    other_objects = s_conn_return_others (other_objects, object);
> +  }
> +  o_erase_single (w_current, object);
> +  o_erase_grips (w_current, object);
>
> -/*! \todo Finish function documentation!!!
> - *  \brief
> - *  \par Function Description
> - *
> - */
> -static void o_delete_arc(GSCHEM_TOPLEVEL *w_current, OBJECT *obj)
> -{
> -  TOPLEVEL *toplevel = w_current->toplevel;
> -  o_erase_single(w_current, obj);
> +  s_delete (toplevel, object);
>
> -  s_delete(toplevel, obj);
> -  toplevel->page_current->object_tail =
> -  (OBJECT *) return_tail(toplevel->page_current->object_head);
> +  if (do_conn) {
> +    o_cue_undraw_list (w_current, other_objects);
> +    o_cue_draw_list (w_current, other_objects);
> +    g_list_free (other_objects);
> +  }
> +
> +  toplevel->page_current->CHANGED = 1;
> +   toplevel->page_current->object_tail =
> +     (OBJECT *) return_tail(toplevel->page_current->object_head);
>  }
>
> -/*! \todo Finish function documentation!!!
> - *  \brief
> +/*! \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 GSCHEM_TOPLEVEL object.
>  */
> -void o_delete_selected(GSCHEM_TOPLEVEL *w_current)
> +void o_delete_selected (GSCHEM_TOPLEVEL *w_current)
>  {
> -  TOPLEVEL *toplevel = w_current->toplevel;
> -  GList *s_current = NULL;
> -  OBJECT *object = NULL;
> -
> -  object = o_select_return_first_object(w_current);
> -  if (object == NULL) {
> -    /*! \todo error condition */
> -    w_current->inside_action = 0;
> -    i_set_state(w_current, SELECT);
> -    return;
> -  }
> -
> -
> -  /* skip over head node */
> -  s_current = geda_list_get_glist( toplevel->page_current->selection_list );
> -
> -  while(s_current != NULL) {
> +  SELECTION *selection = w_current->toplevel->page_current->selection_list;
> +  GList *s_current;
>
> -    object = (OBJECT *) s_current->data;
> -    g_assert (object != NULL);
> +  g_return_if_fail (o_select_selected (w_current));
>
> -    switch(object->type) {
> -      case(OBJ_LINE):
> -        o_delete_line(w_current, object);
> -        break;
>
> -      case(OBJ_NET):
> -        o_delete_net(w_current, object);
> -        break;
> -
> -      case(OBJ_BUS):
> -        o_delete_bus(w_current, object);
> -        break;
> -
> -      case(OBJ_BOX):
> -        o_delete_box(w_current, object);
> -        break;
> -
> -      case(OBJ_PICTURE):
> -        o_delete_picture(w_current, object);
> -        break;
> -
> -      case(OBJ_CIRCLE):
> -        o_delete_circle(w_current, object);
> -        break;
> -
> -      case(OBJ_COMPLEX):
> -      case(OBJ_PLACEHOLDER):
> -        o_delete_complex(w_current, object);
> -        break;
> -
> -      case(OBJ_PIN):
> -        o_delete_pin(w_current, object);
> -        break;
> -
> -      case(OBJ_TEXT):
> -        o_delete_text(w_current, object);
> -        break;
> -
> -      case(OBJ_ARC):
> -        o_delete_arc(w_current, object);
> -        break;
> -    }
> -    s_current = g_list_next(s_current);
> +  for (s_current = geda_list_get_glist (selection);
> +       s_current != NULL;
> +       s_current = g_list_next (s_current)) {
> +    o_delete (w_current, (OBJECT*)s_current->data);
>   }
> -
> +  /* Objects in the selection list have been deleted. */
> +  /* Empty the list without touching the objects */
> +  geda_list_remove_all (selection);
> +
>   w_current->inside_action = 0;
> -
> -  /* Objects in the selection list have been deleted. Empty the list without touching the objects */
> -  geda_list_remove_all( toplevel->page_current->selection_list );
> -
> -  toplevel->page_current->CHANGED=1;
> -
> -  /* no longer needed */
> -  /* o_redraw(w_current, toplevel->page_current->object_head);*/
> -
> -  o_undo_savestate(w_current, UNDO_ALL);
> -  i_update_menus(w_current);
> +  o_undo_savestate (w_current, UNDO_ALL);
> +  i_update_menus (w_current);
>  }
> diff --git a/gschem/src/o_move.c b/gschem/src/o_move.c
> index 1054f06..93da77d 100644
> --- a/gschem/src/o_move.c
> +++ b/gschem/src/o_move.c
> @@ -500,7 +500,7 @@ void o_move_end_rubberband(GSCHEM_TOPLEVEL *w_current, int world_diff_x,
>
>
>           if (o_move_zero_length(object)) {
> -            o_delete_net(w_current, object);
> +            o_delete(w_current, object);
>           } else {
>             o_net_recalc(toplevel, object);
>             s_tile_update_object(toplevel, object);
> @@ -542,7 +542,7 @@ void o_move_end_rubberband(GSCHEM_TOPLEVEL *w_current, int world_diff_x,
>           object->line->y[whichone] = y;
>
>           if (o_move_zero_length(object)) {
> -            o_delete_bus(w_current, object);
> +            o_delete(w_current, object);
>           } else {
>             o_bus_recalc(toplevel, object);
>             s_tile_update_object(toplevel, object);
> diff --git a/gschem/src/x_autonumber.c b/gschem/src/x_autonumber.c
> index b58b3f5..318e05e 100644
> --- a/gschem/src/x_autonumber.c
> +++ b/gschem/src/x_autonumber.c
> @@ -586,7 +586,7 @@ void autonumber_remove_number(AUTONUMBER_TEXT * autotext, OBJECT *o_current)
>        g_free(slot_str);
>        /* delete the slot attribute */
>        o_selection_remove (autotext->w_current->toplevel->page_current->selection_list, o_slot);
> -       o_delete_text (autotext->w_current, o_slot);
> +       o_delete (autotext->w_current, o_slot);
>       }
>     }
>   }
> diff --git a/gschem/src/x_multiattrib.c b/gschem/src/x_multiattrib.c
> index 679d428..6519fb0 100644
> --- a/gschem/src/x_multiattrib.c
> +++ b/gschem/src/x_multiattrib.c
> @@ -518,7 +518,7 @@ static void multiattrib_action_delete_attribute(GSCHEM_TOPLEVEL *w_current,
>  {
>   /* actually deletes the attribute */
>   o_selection_remove ( w_current->toplevel->page_current->selection_list, o_attrib);
> -  o_delete_text (w_current, o_attrib);
> +  o_delete (w_current, o_attrib);
>   w_current->toplevel->page_current->CHANGED=1;
>   o_undo_savestate (w_current, UNDO_ALL);
>
> --
> 1.5.6
>
>
>
>
> _______________________________________________
> geda-dev mailing list
> geda-dev@moria.seul.org
> http://www.seul.org/cgi-bin/mailman/listinfo/geda-dev
>


_______________________________________________
geda-dev mailing list
geda-dev@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-dev