gattrib

s_visibility.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * gattrib -- gEDA component and net attribute manipulation using spreadsheet.
00003  * Copyright (C) 2003-2010 Stuart D. Brorson.
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00018  */
00019 /*------------------------------------------------------------------*/
00029 #ifdef HAVE_CONFIG_H
00030 #include "config.h"
00031 #endif
00032 
00033 /*------------------------------------------------------------------
00034  * Includes required to run graphical widgets.
00035  *------------------------------------------------------------------*/
00036 #include <stdio.h>
00037 #include <stdlib.h>
00038 #include <gtk/gtk.h>
00039 #include <gdk/gdk.h>
00040 #include <gdk/gdkkeysyms.h>
00041 
00042 #include <glib.h>
00043 #include <glib-object.h>
00044 
00045 #include <sys/types.h>
00046 
00047 #ifdef HAVE_SYS_PARAM_H
00048 #include <sys/param.h>
00049 #endif
00050 
00051 #include <sys/stat.h>
00052 
00053 #ifdef HAVE_UNISTD_H
00054 #include <unistd.h>
00055 #endif
00056 
00057 #ifdef HAVE_STRING_H
00058 #include <string.h>
00059 #endif
00060 
00061 
00062 /*------------------------------------------------------------------
00063  * Gattrib specific includes
00064  *------------------------------------------------------------------*/
00065 #include <libgeda/libgeda.h>       /* geda library fcns  */
00066 #include "../include/struct.h"     /* typdef and struct declarations */
00067 #include "../include/prototype.h"  /* function prototypes */
00068 #include "../include/globals.h"
00069 
00070 #ifdef HAVE_LIBDMALLOC
00071 #include <dmalloc.h>
00072 #endif
00073 
00074 
00075 /* ----- s_visibility stuff begins here ----- */
00076 
00077 
00078 
00079 /* ---------------------------------------------------------------------- */
00080 /* \brief Set the selected cells to INVISIBLE
00081  *
00082  *
00083  * This sets the selected cells to INVISIBLE.
00084  * This function is called from the menu, it assumes you have
00085  * selected a range of cells which are carried in the global 
00086  * variable "sheet".
00087  */
00088 void s_visibility_set_invisible() {
00089   gint i, j;
00090   gint row_start, row_end, col_start, col_end;
00091   GtkSheet *sheet;
00092   gint cur_page;
00093 
00094   cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
00095   sheet = sheets[cur_page];
00096   
00097   g_return_if_fail (sheet != NULL);
00098   g_return_if_fail (GTK_IS_SHEET (sheet));
00099 
00100   switch (sheet->state) {
00101 
00102   case GTK_SHEET_RANGE_SELECTED: 
00103   case GTK_SHEET_COLUMN_SELECTED:  
00104   case GTK_SHEET_ROW_SELECTED: 
00105 
00106 #ifdef DEBUG
00107     printf("In s_visibility_set_invisible, range/col/row selected.\n");
00108 #endif
00109 
00110     row_start = sheet->range.row0;
00111     row_end = sheet->range.rowi;
00112     col_start = sheet->range.col0;
00113     col_end = sheet->range.coli;
00114     for (i=row_start; i<=row_end; i++) {
00115       for (j=col_start; j<=col_end; j++) {
00116     /* first set cell in SHEET_DATA to invisible */
00117     s_visibility_set_cell(cur_page, i, j, 
00118                   INVISIBLE, 
00119                   LEAVE_NAME_VALUE_ALONE);
00120     /* Now set cell in gtksheet to desired color */
00121     /* Color names are defined 
00122      * in libgeda/include/colors.h */
00123     x_gtksheet_set_cell_text_color(sheet, i, j, GREY); 
00124 
00125       }
00126     }
00127     /* Now return sheet to normal -- unselect range */
00128     gtk_sheet_unselect_range (sheet);
00129     break;
00130 
00131   case GTK_SHEET_NORMAL:
00132 #ifdef DEBUG
00133     printf("In s_visibility_set_invisible, normal selection.\n");
00134 #endif
00135     s_visibility_set_cell(cur_page, 
00136               sheet->active_cell.row, 
00137               sheet->active_cell.col, 
00138               INVISIBLE, 
00139               LEAVE_NAME_VALUE_ALONE);
00140 
00141     x_gtksheet_set_cell_text_color(sheet, 
00142                    sheet->active_cell.row, 
00143                    sheet->active_cell.col, 
00144                    GREY);
00145 
00146     break;
00147 
00148   }
00149 
00150 
00151 }
00152 
00153 /* ---------------------------------------------------------------------- */
00161 void s_visibility_set_name_only() {
00162   gint i, j;
00163   gint row_start, row_end, col_start, col_end;
00164   GtkSheet *sheet;
00165   gint cur_page;
00166 
00167   cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
00168   sheet = sheets[cur_page];
00169 
00170   g_return_if_fail (sheet != NULL);
00171   g_return_if_fail (GTK_IS_SHEET (sheet));
00172 
00173   switch (sheet->state) {
00174  
00175   case GTK_SHEET_RANGE_SELECTED:
00176   case GTK_SHEET_COLUMN_SELECTED:  
00177   case GTK_SHEET_ROW_SELECTED: 
00178 #ifdef DEBUG
00179     printf("In s_visibility_set_name_only, range/col/row selected.\n");
00180 #endif
00181     row_start = sheet->range.row0;
00182     row_end = sheet->range.rowi;
00183     col_start = sheet->range.col0;
00184     col_end = sheet->range.coli;
00185     for (i=row_start; i<=row_end; i++) {
00186       for (j=col_start; j<=col_end; j++) {
00187     s_visibility_set_cell(cur_page, i, j, VISIBLE, SHOW_NAME);
00188     /* Color names are defined 
00189      * in libgeda/include/colors.h */
00190     x_gtksheet_set_cell_text_color(sheet, i, j, RED); 
00191 
00192       }
00193     }
00194     /* Now return sheet to normal -- unselect range */
00195     gtk_sheet_unselect_range (sheet);
00196 
00197     break;
00198 
00199   case GTK_SHEET_NORMAL:
00200     s_visibility_set_cell(cur_page,
00201               sheet->active_cell.row, 
00202               sheet->active_cell.col, 
00203               VISIBLE, SHOW_NAME);
00204     x_gtksheet_set_cell_text_color(sheet, 
00205                    sheet->active_cell.row, 
00206                    sheet->active_cell.col, 
00207                    RED);
00208 
00209     break;
00210 
00211   }
00212 }
00213 
00214 /* ---------------------------------------------------------------------- */
00215 /* \brief Set the selected cells' visibility to VALUE_ONLY
00216  *
00217  * s_visibility_set_value_only -- This sets the selected cells to VALUE_ONLY.
00218  * This fcn is invoked from the menu, it assumes you have
00219  * selected a range of cells which are carried in the global 
00220  * variable "sheet".
00221  */
00222 void s_visibility_set_value_only() {
00223   gint i, j;
00224   gint row_start, row_end, col_start, col_end;
00225   GtkSheet *sheet;
00226   gint cur_page;
00227 
00228   cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
00229   sheet = sheets[cur_page];
00230 
00231   g_return_if_fail (sheet != NULL);
00232   g_return_if_fail (GTK_IS_SHEET (sheet));
00233 
00234   switch (sheet->state) {
00235  
00236   case GTK_SHEET_RANGE_SELECTED:
00237   case GTK_SHEET_COLUMN_SELECTED:  
00238   case GTK_SHEET_ROW_SELECTED: 
00239 #ifdef DEBUG
00240     printf("In s_visibility_set_value_only, range/col/row selected.\n");
00241 #endif
00242     row_start = sheet->range.row0;
00243     row_end = sheet->range.rowi;
00244     col_start = sheet->range.col0;
00245     col_end = sheet->range.coli;
00246     for (i=row_start; i<=row_end; i++) {
00247       for (j=col_start; j<=col_end; j++) {
00248     s_visibility_set_cell(cur_page, i, j, VISIBLE, SHOW_VALUE);
00249     /* Color names are defined 
00250      * in libgeda/include/colors.h */
00251     x_gtksheet_set_cell_text_color(sheet, i, j, BLACK); 
00252 
00253       }
00254     }
00255     /* Now return sheet to normal -- unselect range */
00256     gtk_sheet_unselect_range (sheet);
00257 
00258     break;
00259 
00260   case GTK_SHEET_NORMAL:
00261 #ifdef DEBUG
00262     printf("In s_visibility_set_value_only, sheet normal selected.\n");
00263 #endif
00264     s_visibility_set_cell(cur_page, 
00265               sheet->active_cell.row, 
00266               sheet->active_cell.col, 
00267               VISIBLE, SHOW_VALUE);
00268     x_gtksheet_set_cell_text_color(sheet, 
00269                    sheet->active_cell.row, 
00270                    sheet->active_cell.col, 
00271                    BLACK);
00272     break;
00273 
00274   }
00275 }
00276 
00277 /* ---------------------------------------------------------------------- */
00278 /* \brief Set the visibility of the selected cells to NAME_AND_VALUE
00279  *
00280  * This sets the selected cells
00281  * to NAME_AND_VALUE
00282  * This fcn is invoked from the menu, it assumes you have
00283  * selected a range of cells which are carried in the global 
00284  * variable "sheet".
00285  *
00286  */
00287 void s_visibility_set_name_and_value() {
00288   gint i, j;
00289   gint row_start, row_end, col_start, col_end;
00290   GtkSheet *sheet;
00291   gint cur_page;
00292 
00293   cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
00294   sheet = sheets[cur_page];
00295   
00296   g_return_if_fail (sheet != NULL);
00297   g_return_if_fail (GTK_IS_SHEET (sheet));
00298 
00299   switch (sheet->state) {
00300 
00301   case GTK_SHEET_RANGE_SELECTED:
00302   case GTK_SHEET_COLUMN_SELECTED:  
00303   case GTK_SHEET_ROW_SELECTED: 
00304     row_start = sheet->range.row0;
00305     row_end = sheet->range.rowi;
00306     col_start = sheet->range.col0;
00307     col_end = sheet->range.coli;
00308     for (i=row_start; i<=row_end; i++) {
00309       for (j=col_start; j<=col_end; j++) {
00310     s_visibility_set_cell(cur_page, i, j, VISIBLE, SHOW_NAME_VALUE);
00311     /* Color names are defined 
00312      * in libgeda/include/colors.h */
00313     x_gtksheet_set_cell_text_color(sheet, i, j, BLUE); 
00314 
00315       }
00316     }
00317     /* Now return sheet to normal -- unselect range */
00318     gtk_sheet_unselect_range (sheet);
00319 
00320     break;
00321 
00322   case GTK_SHEET_NORMAL:
00323     s_visibility_set_cell(cur_page, 
00324               sheet->active_cell.row, 
00325               sheet->active_cell.col, 
00326               VISIBLE, 
00327               SHOW_NAME_VALUE);
00328     x_gtksheet_set_cell_text_color(sheet, 
00329                    sheet->active_cell.row, 
00330                    sheet->active_cell.col, 
00331                    BLUE);
00332 
00333     break;
00334 
00335   }
00336 }
00337 
00338 
00339 /* ==================  Private functions  =================== */
00340 
00341 /* ---------------------------------------------------------------------- */
00342 /* \brief set the visibility of an individual cell
00343  *
00344  * Set the visibility of an individual cell
00345  * to "state".  The cell is identified by (row, col)
00346  * \param cur_page index of spreadsheet tab
00347  * \param row Row index of target cell
00348  * \param col Column index of target cell
00349  * \param visibility Visibility value to set cell to
00350  * \param show_name_value Name, Value visibility flag
00351  */
00352 void s_visibility_set_cell(gint cur_page, gint row, gint col, 
00353                gint visibility, 
00354                gint show_name_value) {
00355   TABLE **local_table = NULL;
00356 
00357 #ifdef DEBUG
00358     printf("In s_visibility_set_cell, setting row = %d, col = %d.\n", 
00359        row, col);
00360 #endif
00361 
00362   switch (cur_page) {
00363 
00364   case 0:
00365     local_table = sheet_head->component_table;
00366     break;
00367 
00368   case 1:
00369     local_table = sheet_head->net_table;
00370     break;
00371 
00372   case 2:
00373     local_table = sheet_head->pin_table;
00374     break;
00375   }
00376 
00377   /* Question:  how to sanity check (row, col) selection? */
00378   local_table[row][col].visibility = visibility;
00379   sheet_head->CHANGED = 1;  /* cell has been updated.  */
00380 
00381   if (show_name_value != LEAVE_NAME_VALUE_ALONE) { 
00382     local_table[row][col].show_name_value = show_name_value;
00383     sheet_head->CHANGED = 1;  /* cell has been updated.  */
00384   }
00385 }
00386 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines