Updated copyright text/header in most source files.
[geda-gaf/peter-b.git] / libgeda / src / o_selection.c
blob8e8f9c9b2e5d2147677e5f9095fb455748a54db6
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., 59 Temple Place, Suite 330, Boston, MA 02111 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.
47 * \param [in] toplevel The TOPLEVEL object
48 * \param [in] selection Pointer to the selection list
49 * \param [in] o_selected Object to select.
51 void o_selection_add (TOPLEVEL *toplevel, SELECTION *selection, OBJECT *o_selected)
53 o_selection_select (toplevel, o_selected);
54 geda_list_add( (GedaList *)selection, o_selected );
57 /*! \brief Removes the given object from the selection list
58 * \par Removes the given object from the selection list and does the
59 * needed work to make the object visually unselected.
60 * It's ok to call this function with an object which is not necessarily
61 * selected.
63 * \param [in] toplevel The TOPLEVEL object
64 * \param [in] selection Pointer to the selection list
65 * \param [in] o_selected Object to unselect and remove from the list.
67 void o_selection_remove (TOPLEVEL *toplevel, SELECTION *selection, OBJECT *o_selected)
69 if (o_selected == NULL) {
70 fprintf(stderr, "Got NULL for o_selected in o_selection_remove\n");
71 return;
74 if (g_list_find( geda_list_get_glist( selection ), o_selected ) != NULL) {
75 o_selection_unselect (toplevel, o_selected);
76 geda_list_remove( (GedaList *)selection, o_selected );
81 /*! \brief Prints the given selection list.
82 * \par Prints the given selection list.
83 * \param [in] selection Pointer to selection list to print.
86 void o_selection_print_all(const SELECTION *selection)
88 const GList *s_current;
90 s_current = geda_list_get_glist( selection );
92 printf("START printing selection ********************\n");
93 while(s_current != NULL) {
94 if (s_current->data) {
95 printf("Selected object: %d\n", ((OBJECT *)s_current->data)->sid );
97 s_current = g_list_next( s_current );
99 printf("DONE printing selection ********************\n");
100 printf("\n");
103 /*! \brief Selects the given object.
104 * \par Sets the select flag, saves the color, and then selects the
105 * given object
107 * \param [in] toplevel The TOPLEVEL object
108 * \param [in] object Object to select.
110 void o_selection_select(TOPLEVEL *toplevel, OBJECT *object)
112 if (object->selected == TRUE) {
113 printf("object already selected == TRUE\n");
114 return;
117 object->selected = TRUE;
120 /*! \brief Unselects the given object.
121 * \par Unsets the select flag, restores the original color of the
122 * given object.
123 * This function should not be called by anybody outside of this file.
125 * \param [in] toplevel The TOPLEVEL object
126 * \param [in] object Object to unselect.
128 void o_selection_unselect (TOPLEVEL *toplevel, OBJECT *object)
130 object->selected = FALSE;