1 /*
2 * gEDA - GNU Electronic Design Automation
3 *
4 * selection.c -- this file is a part of gerbv.
5 *
6 * Copyright (C) 2014 Sergey Alyoshin <alyoshin.s@gmail.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 51
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /** \file selection.c
24 \brief Selection support functions for libgerbv
25 \ingroup libgerbv
26 */
27
28 #include "gerbv.h"
29
selection_new_array(void)30 GArray *selection_new_array (void)
31 {
32 return g_array_new (FALSE, FALSE, sizeof (gerbv_selection_item_t));
33 }
34
selection_free_array(gerbv_selection_info_t * sel_info)35 gchar *selection_free_array (gerbv_selection_info_t *sel_info)
36 {
37 return g_array_free (sel_info->selectedNodeArray, FALSE);
38 }
39
selection_length(gerbv_selection_info_t * sel_info)40 guint selection_length (gerbv_selection_info_t *sel_info)
41 {
42 return sel_info->selectedNodeArray->len;
43 }
44
selection_get_item_by_index(gerbv_selection_info_t * sel_info,guint idx)45 gerbv_selection_item_t selection_get_item_by_index (
46 gerbv_selection_info_t *sel_info, guint idx)
47 {
48 return g_array_index (sel_info->selectedNodeArray,
49 gerbv_selection_item_t, idx);
50 }
51
selection_clear_item_by_index(gerbv_selection_info_t * sel_info,guint idx)52 void selection_clear_item_by_index (
53 gerbv_selection_info_t *sel_info, guint idx)
54 {
55 g_array_remove_index (sel_info->selectedNodeArray, idx);
56 }
57
selection_clear(gerbv_selection_info_t * sel_info)58 void selection_clear (gerbv_selection_info_t *sel_info)
59 {
60 if (selection_length(sel_info))
61 g_array_remove_range (sel_info->selectedNodeArray, 0,
62 sel_info->selectedNodeArray->len);
63 }
64
selection_add_item(gerbv_selection_info_t * sel_info,gerbv_selection_item_t * item)65 void selection_add_item (gerbv_selection_info_t *sel_info,
66 gerbv_selection_item_t *item)
67 {
68 g_array_append_val (sel_info->selectedNodeArray, *item);
69 }
70