1 /* Lepton EDA attribute editor
2 * Copyright (C) 2003-2010 Stuart D. Brorson.
3 * Copyright (C) 2003-2013 gEDA Contributors
4 * Copyright (C) 2017-2021 Lepton EDA Contributors
5 *
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.
10 *
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.
15 *
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
19 */
20 /*------------------------------------------------------------------*/
21 /*! \file
22 * \brief Functions to manipulate attribute visibility
23 *
24 * This file holds widgets and functions used in conjunction
25 * with setting attribute visibility.
26 * \todo There seems to be a lot of duplicated code in this file -
27 * a good candidate for refactoring.
28 */
29
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33
34 /*------------------------------------------------------------------
35 * Includes required to run graphical widgets.
36 *------------------------------------------------------------------*/
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <gtk/gtk.h>
40 #include <gdk/gdk.h>
41 #include <gdk/gdkkeysyms.h>
42
43 #include <glib.h>
44 #include <glib-object.h>
45
46 #include <sys/types.h>
47
48 #ifdef HAVE_SYS_PARAM_H
49 #include <sys/param.h>
50 #endif
51
52 #include <sys/stat.h>
53
54 #ifdef HAVE_UNISTD_H
55 #include <unistd.h>
56 #endif
57
58 #ifdef HAVE_STRING_H
59 #include <string.h>
60 #endif
61
62
63 /*------------------------------------------------------------------
64 * Gattrib specific includes
65 *------------------------------------------------------------------*/
66 #include <liblepton/liblepton.h>
67 #include "../include/struct.h" /* typdef and struct declarations */
68 #include "../include/prototype.h" /* function prototypes */
69 #include "../include/globals.h"
70
71
72 /* ----- s_visibility stuff begins here ----- */
73
74
75
76 /* ---------------------------------------------------------------------- */
77 /* \brief Set the selected cells to INVISIBLE
78 *
79 *
80 * This sets the selected cells to INVISIBLE.
81 * This function is called from the menu, it assumes you have
82 * selected a range of cells which are carried in the global
83 * variable "sheet".
84 */
s_visibility_set_invisible()85 void s_visibility_set_invisible() {
86 gint i, j;
87 gint row_start, row_end, col_start, col_end;
88 GtkSheet *sheet;
89 gint cur_page;
90
91 cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
92 sheet = sheets[cur_page];
93
94 g_return_if_fail (sheet != NULL);
95 g_return_if_fail (GTK_IS_SHEET (sheet));
96
97 switch (sheet->state) {
98
99 case GTK_SHEET_RANGE_SELECTED:
100 case GTK_SHEET_COLUMN_SELECTED:
101 case GTK_SHEET_ROW_SELECTED:
102
103 g_debug ("s_visibility_set_invisible: Range/col/row selected.\n");
104
105 row_start = sheet->range.row0;
106 row_end = sheet->range.rowi;
107 col_start = sheet->range.col0;
108 col_end = sheet->range.coli;
109 for (i=row_start; i<=row_end; i++) {
110 for (j=col_start; j<=col_end; j++) {
111 /* first set cell in SHEET_DATA to invisible */
112 s_visibility_set_cell(cur_page, i, j,
113 INVISIBLE,
114 LEAVE_NAME_VALUE_ALONE);
115 /* Now set cell in gtksheet to desired color */
116 /* Color names are defined
117 * in liblepton/include/colors.h */
118 x_gtksheet_set_cell_text_color(sheet, i, j, GREY);
119
120 }
121 }
122 /* Now return sheet to normal -- unselect range */
123 gtk_sheet_unselect_range (sheet);
124 break;
125
126 case GTK_SHEET_NORMAL:
127 g_debug ("s_visibility_set_invisible: Normal selection.\n");
128 s_visibility_set_cell(cur_page,
129 sheet->active_cell.row,
130 sheet->active_cell.col,
131 INVISIBLE,
132 LEAVE_NAME_VALUE_ALONE);
133
134 x_gtksheet_set_cell_text_color(sheet,
135 sheet->active_cell.row,
136 sheet->active_cell.col,
137 GREY);
138
139 break;
140
141 }
142
143
144 }
145
146 /* ---------------------------------------------------------------------- */
147 /*! \brief Set the visibility of the selected cells to NAME_ONLY.
148 *
149 * This sets the selected cells to NAME_ONLY.
150 * This function is invoked from the menu, it assumes you have
151 * selected a range of cells which are carried in the global
152 * variable "sheet".
153 */
s_visibility_set_name_only()154 void s_visibility_set_name_only() {
155 gint i, j;
156 gint row_start, row_end, col_start, col_end;
157 GtkSheet *sheet;
158 gint cur_page;
159
160 cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
161 sheet = sheets[cur_page];
162
163 g_return_if_fail (sheet != NULL);
164 g_return_if_fail (GTK_IS_SHEET (sheet));
165
166 switch (sheet->state) {
167
168 case GTK_SHEET_RANGE_SELECTED:
169 case GTK_SHEET_COLUMN_SELECTED:
170 case GTK_SHEET_ROW_SELECTED:
171 g_debug ("s_visibility_set_name_only: Range/col/row selected.\n");
172 row_start = sheet->range.row0;
173 row_end = sheet->range.rowi;
174 col_start = sheet->range.col0;
175 col_end = sheet->range.coli;
176 for (i=row_start; i<=row_end; i++) {
177 for (j=col_start; j<=col_end; j++) {
178 s_visibility_set_cell(cur_page, i, j, VISIBLE, SHOW_NAME);
179 /* Color names are defined
180 * in liblepton/include/colors.h */
181 x_gtksheet_set_cell_text_color(sheet, i, j, RED);
182
183 }
184 }
185 /* Now return sheet to normal -- unselect range */
186 gtk_sheet_unselect_range (sheet);
187
188 break;
189
190 case GTK_SHEET_NORMAL:
191 s_visibility_set_cell(cur_page,
192 sheet->active_cell.row,
193 sheet->active_cell.col,
194 VISIBLE, SHOW_NAME);
195 x_gtksheet_set_cell_text_color(sheet,
196 sheet->active_cell.row,
197 sheet->active_cell.col,
198 RED);
199
200 break;
201
202 }
203 }
204
205 /* ---------------------------------------------------------------------- */
206 /* \brief Set the selected cells' visibility to VALUE_ONLY
207 *
208 * s_visibility_set_value_only -- This sets the selected cells to VALUE_ONLY.
209 * This fcn is invoked from the menu, it assumes you have
210 * selected a range of cells which are carried in the global
211 * variable "sheet".
212 */
s_visibility_set_value_only()213 void s_visibility_set_value_only() {
214 gint i, j;
215 gint row_start, row_end, col_start, col_end;
216 GtkSheet *sheet;
217 gint cur_page;
218
219 cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
220 sheet = sheets[cur_page];
221
222 g_return_if_fail (sheet != NULL);
223 g_return_if_fail (GTK_IS_SHEET (sheet));
224
225 switch (sheet->state) {
226
227 case GTK_SHEET_RANGE_SELECTED:
228 case GTK_SHEET_COLUMN_SELECTED:
229 case GTK_SHEET_ROW_SELECTED:
230 g_debug ("s_visibility_set_value_only: Range/col/row selected.\n");
231 row_start = sheet->range.row0;
232 row_end = sheet->range.rowi;
233 col_start = sheet->range.col0;
234 col_end = sheet->range.coli;
235 for (i=row_start; i<=row_end; i++) {
236 for (j=col_start; j<=col_end; j++) {
237 s_visibility_set_cell(cur_page, i, j, VISIBLE, SHOW_VALUE);
238 /* Color names are defined
239 * in liblepton/include/colors.h */
240 x_gtksheet_set_cell_text_color(sheet, i, j, BLACK);
241
242 }
243 }
244 /* Now return sheet to normal -- unselect range */
245 gtk_sheet_unselect_range (sheet);
246
247 break;
248
249 case GTK_SHEET_NORMAL:
250 g_debug ("s_visibility_set_value_only: Sheet normal selected.\n");
251 s_visibility_set_cell(cur_page,
252 sheet->active_cell.row,
253 sheet->active_cell.col,
254 VISIBLE, SHOW_VALUE);
255 x_gtksheet_set_cell_text_color(sheet,
256 sheet->active_cell.row,
257 sheet->active_cell.col,
258 BLACK);
259 break;
260
261 }
262 }
263
264 /* ---------------------------------------------------------------------- */
265 /* \brief Set the visibility of the selected cells to NAME_AND_VALUE
266 *
267 * This sets the selected cells
268 * to NAME_AND_VALUE
269 * This fcn is invoked from the menu, it assumes you have
270 * selected a range of cells which are carried in the global
271 * variable "sheet".
272 *
273 */
s_visibility_set_name_and_value()274 void s_visibility_set_name_and_value() {
275 gint i, j;
276 gint row_start, row_end, col_start, col_end;
277 GtkSheet *sheet;
278 gint cur_page;
279
280 cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
281 sheet = sheets[cur_page];
282
283 g_return_if_fail (sheet != NULL);
284 g_return_if_fail (GTK_IS_SHEET (sheet));
285
286 switch (sheet->state) {
287
288 case GTK_SHEET_RANGE_SELECTED:
289 case GTK_SHEET_COLUMN_SELECTED:
290 case GTK_SHEET_ROW_SELECTED:
291 row_start = sheet->range.row0;
292 row_end = sheet->range.rowi;
293 col_start = sheet->range.col0;
294 col_end = sheet->range.coli;
295 for (i=row_start; i<=row_end; i++) {
296 for (j=col_start; j<=col_end; j++) {
297 s_visibility_set_cell(cur_page, i, j, VISIBLE, SHOW_NAME_VALUE);
298 /* Color names are defined
299 * in liblepton/include/colors.h */
300 x_gtksheet_set_cell_text_color(sheet, i, j, BLUE);
301
302 }
303 }
304 /* Now return sheet to normal -- unselect range */
305 gtk_sheet_unselect_range (sheet);
306
307 break;
308
309 case GTK_SHEET_NORMAL:
310 s_visibility_set_cell(cur_page,
311 sheet->active_cell.row,
312 sheet->active_cell.col,
313 VISIBLE,
314 SHOW_NAME_VALUE);
315 x_gtksheet_set_cell_text_color(sheet,
316 sheet->active_cell.row,
317 sheet->active_cell.col,
318 BLUE);
319
320 break;
321
322 }
323 }
324
325
326 /* ================== Private functions =================== */
327
328 /* ---------------------------------------------------------------------- */
329 /* \brief set the visibility of an individual cell
330 *
331 * Set the visibility of an individual cell
332 * to "state". The cell is identified by (row, col)
333 * \param cur_page index of spreadsheet tab
334 * \param row Row index of target cell
335 * \param col Column index of target cell
336 * \param visibility Visibility value to set cell to
337 * \param show_name_value Name, Value visibility flag
338 */
s_visibility_set_cell(gint cur_page,gint row,gint col,gint visibility,gint show_name_value)339 void s_visibility_set_cell(gint cur_page, gint row, gint col,
340 gint visibility,
341 gint show_name_value) {
342 TABLE **local_table = NULL;
343
344 g_debug ("s_visibility_set_cell: Setting row = %d, col = %d.\n",
345 row, col);
346
347 switch (cur_page) {
348
349 case 0:
350 local_table = sheet_head->component_table;
351 break;
352
353 case 1:
354 local_table = sheet_head->net_table;
355 break;
356
357 case 2:
358 local_table = sheet_head->pin_table;
359 break;
360 }
361
362 /* Question: how to sanity check (row, col) selection? */
363 local_table[row][col].visibility = visibility;
364 /* cell has been updated. */
365 s_sheet_data_set_changed (sheet_head, TRUE);
366
367 if (show_name_value != LEAVE_NAME_VALUE_ALONE) {
368 local_table[row][col].show_name_value = show_name_value;
369 /* cell has been updated. */
370 s_sheet_data_set_changed (sheet_head, TRUE);
371 }
372 }
373