libgeda: Remove some exit() calls and assertions.
[geda-gaf/peter-b.git] / libgeda / src / o_selection.c
blob8381f643a048032069e005ad74699ea3d0b6d617
1 /* gEDA - GPL Electronic Design Automation
2 * libgeda - gEDA's library
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <config.h>
22 #include <stdio.h>
23 #include <ctype.h>
24 #ifdef HAVE_STDLIB_H
25 #include <stdlib.h>
26 #endif
28 #include "libgeda_priv.h"
30 #ifdef HAVE_LIBDMALLOC
31 #include <dmalloc.h>
32 #endif
34 /*! \brief Returns a pointer to a new SELECTION object.
35 * \par Returns a pointer to a new SELECTION object.
36 * \return pointer to the new SELECTION object.
38 SELECTION *o_selection_new( void )
40 return (SELECTION*)geda_list_new();
43 /*! \brief Selects the given object and adds it to the selection list
44 * \par Selects the given object and does the needed work to make the
45 * object visually selected.
46 * Skip objects that are already selected.
48 * \param [in] toplevel The TOPLEVEL object
49 * \param [in] selection Pointer to the selection list
50 * \param [in] o_selected Object to select.
52 void o_selection_add (TOPLEVEL *toplevel, SELECTION *selection, OBJECT *o_selected)
54 if (o_selected->selected == FALSE)
56 o_selection_select (toplevel, o_selected);
57 geda_list_add( (GedaList *)selection, o_selected );
61 /*! \brief Removes the given object from the selection list
62 * \par Removes the given object from the selection list and does the
63 * needed work to make the object visually unselected.
64 * It's ok to call this function with an object which is not necessarily
65 * selected.
67 * \param [in] toplevel The TOPLEVEL object
68 * \param [in] selection Pointer to the selection list
69 * \param [in] o_selected Object to unselect and remove from the list.
71 void o_selection_remove (TOPLEVEL *toplevel, SELECTION *selection, OBJECT *o_selected)
73 if (o_selected == NULL) {
74 fprintf(stderr, "Got NULL for o_selected in o_selection_remove\n");
75 return;
78 if (g_list_find( geda_list_get_glist( selection ), o_selected ) != NULL) {
79 o_selection_unselect (toplevel, o_selected);
80 geda_list_remove( (GedaList *)selection, o_selected );
85 /*! \brief Prints the given selection list.
86 * \par Prints the given selection list.
87 * \param [in] selection Pointer to selection list to print.
90 void o_selection_print_all(const SELECTION *selection)
92 const GList *s_current;
94 s_current = geda_list_get_glist( selection );
96 printf("START printing selection ********************\n");
97 while(s_current != NULL) {
98 if (s_current->data) {
99 printf("Selected object: %d\n", ((OBJECT *)s_current->data)->sid );
101 s_current = g_list_next( s_current );
103 printf("DONE printing selection ********************\n");
104 printf("\n");
107 /*! \brief Selects the given object.
108 * \par Sets the select flag, saves the color, and then selects the
109 * given object
111 * \param [in] toplevel The TOPLEVEL object
112 * \param [in] object Object to select.
114 void o_selection_select(TOPLEVEL *toplevel, OBJECT *object)
116 if (object->selected == TRUE)
117 return;
119 o_emit_pre_change_notify (toplevel, object);
120 object->selected = TRUE;
121 o_emit_change_notify (toplevel, object);
124 /*! \brief Unselects the given object.
125 * \par Unsets the select flag, restores the original color of the
126 * given object.
127 * This function should not be called by anybody outside of this file.
129 * \param [in] toplevel The TOPLEVEL object
130 * \param [in] object Object to unselect.
132 void o_selection_unselect (TOPLEVEL *toplevel, OBJECT *object)
134 if (object->selected == FALSE)
135 return;
137 o_emit_pre_change_notify (toplevel, object);
138 object->selected = FALSE;
139 o_emit_change_notify (toplevel, object);