Add type assertions near where objects are assumed to be text.
[geda-gaf/berndj.git] / gschem / src / o_find.c
blob3a1c22d3db15fd9b85276e2f7b61083068f2d7d0
1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2007 Ales Hvezda
4 * Copyright (C) 1998-2007 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 <math.h>
23 #include <stdio.h>
25 #include "gschem.h"
27 #ifdef HAVE_LIBDMALLOC
28 #include <dmalloc.h>
29 #endif
31 static gboolean o_find_test(GSCHEM_TOPLEVEL *w_current, OBJECT *o_current,
32 int w_x, int w_y, int w_slack)
34 if (inside_region(o_current->w_left - w_slack, o_current->w_top - w_slack,
35 o_current->w_right + w_slack, o_current->w_bottom + w_slack,
36 w_x, w_y) &&
37 o_shortest_distance(o_current, w_x, w_y) < w_slack) {
38 if (o_current->selectable &&
39 o_current->type != OBJ_HEAD &&
40 (o_current->type != OBJ_TEXT ||
41 o_current->visibility == VISIBLE ||
42 (o_current->visibility == INVISIBLE && o_current->show_hidden))) {
43 /* FIXME: should this switch be moved to o_select_object()? (Werner) */
44 /* FIXME: Move side effects out of this function. */
45 if (o_current->type == OBJ_NET && w_current->net_selection_mode) {
46 o_select_connected_nets(w_current, o_current);
47 } else {
48 o_select_object(w_current, o_current, SINGLE, 0); /* 0 is count */
50 i_update_menus(w_current);
51 return TRUE;
55 return FALSE;
58 /*! \todo Finish function documentation!!!
59 * \brief
60 * \par Function Description
63 gboolean o_find_object(GSCHEM_TOPLEVEL *w_current, int w_x, int w_y)
65 TOPLEVEL *toplevel = w_current->toplevel;
66 PAGE *page = toplevel->page_current;
67 OBJECT *o_current=NULL;
68 int w_slack;
70 w_slack = WORLDabs(page, w_current->select_slack_pixels);
72 /* Decide whether to iterate over all object or start at the last
73 found object. If there is more than one object below the
74 (w_x/w_y) position, this will select the next object below the
75 position point. You can change the selected object by clicking
76 at the same place multiple times. */
77 if (page->object_lastfound == NULL) {
78 /* Start at the beginning of the page's object list. */
79 o_current = page->object_head->next;
80 } else {
81 /* Start at the next object after the last found one. */
82 o_current = page->object_lastfound->next;
85 /* do first search */
86 for (; o_current != NULL; o_current = o_current->next) {
87 if (o_find_test(w_current, o_current, w_x, w_y, w_slack)) {
88 page->object_lastfound = o_current;
89 return TRUE;
93 if (GEDA_DEBUG) {
94 printf("SEARCHING AGAIN\n");
97 if (page->object_lastfound != NULL) {
98 /* Cycle back to the head of the object list, up to object_lastfound. */
99 for (o_current = page->object_head->next;
100 o_current != NULL && o_current != page->object_lastfound;
101 o_current = o_current->next) {
102 if (o_find_test(w_current, o_current, w_x, w_y, w_slack)) {
103 page->object_lastfound = o_current;
104 return TRUE;
107 /* object_lastfound should be in the object list. */
108 g_warn_if_fail(o_current == page->object_lastfound);
111 /* Didn't find anything; reset state. */
112 page->object_lastfound = NULL;
114 /* deselect everything only if shift key isn't pressed and
115 the caller allows it */
116 if (!w_current->SHIFTKEY) {
117 o_select_unselect_all (w_current);
120 i_update_menus(w_current);
122 return FALSE;
125 /*! \todo Finish function documentation!!!
126 * \brief
127 * \par Function Description
130 gboolean o_find_selected_object(GSCHEM_TOPLEVEL *w_current,
131 int w_x, int w_y)
133 TOPLEVEL *toplevel = w_current->toplevel;
134 PAGE *page = toplevel->page_current;
135 OBJECT *o_current=NULL;
136 GList *s_current;
137 int w_slack;
139 w_slack = WORLDabs(page, w_current->select_slack_pixels);
141 s_current = geda_list_get_glist(page->selection_list);
142 /* do first search */
143 while (s_current != NULL) {
144 o_current = s_current->data;
145 if (inside_region(o_current->w_left - w_slack, o_current->w_top - w_slack,
146 o_current->w_right + w_slack, o_current->w_bottom + w_slack,
147 w_x, w_y)) {
149 if (GEDA_DEBUG) {
150 printf("o_find_selected_object:\n");
151 printf("Object bounds:\n\tL: %i\tR: %i\n\tT: %i\tB: %i.\n",
152 o_current->w_left, o_current->w_right, o_current->w_top, o_current->w_bottom);
153 printf("Screen pointer at: (%i,%i)\n", w_x, w_y);
155 if (o_current->selectable &&
156 o_current->type != OBJ_HEAD &&
157 (o_current->type != OBJ_TEXT ||
158 o_current->visibility == VISIBLE ||
159 (o_current->visibility == INVISIBLE && o_current->show_hidden))) {
160 return TRUE;
164 s_current = g_list_next(s_current);
167 return (FALSE);