gattrib

s_sheet_data.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 
00020 /*--------------------------------------------------------------*/
00034 #include <config.h>
00035 
00036 #include <stdio.h>
00037 #ifdef HAVE_STRING_H
00038 #include <string.h>
00039 #endif
00040 #include <math.h>
00041 
00042 /*------------------------------------------------------------------
00043  * Gattrib specific includes
00044  *------------------------------------------------------------------*/
00045 #include <libgeda/libgeda.h>       /* geda library fcns  */
00046 #include "../include/struct.h"     /* typdef and struct declarations */
00047 #include "../include/prototype.h"  /* function prototypes */
00048 #include "../include/globals.h"
00049 
00050 #ifdef HAVE_LIBDMALLOC
00051 #include <dmalloc.h>
00052 #endif
00053 
00054 
00055 /*------------------------------------------------------------------*/
00062 SHEET_DATA *s_sheet_data_new()
00063 {
00064   SHEET_DATA *new_sheet;
00065 
00066   new_sheet = (SHEET_DATA *) g_malloc(sizeof(SHEET_DATA));
00067 
00068   /* We will malloc and fill out the comp table later. */
00069   new_sheet->component_table = NULL;
00070 
00071   /* We will malloc and fill out the net table later. */
00072   new_sheet->net_table = NULL;
00073 
00074   /* We will malloc and fill out the pin table later. */
00075   new_sheet->pin_table = NULL;
00076 
00077   /* Now we create the first cell in each master list. */
00078   new_sheet->master_comp_list_head = (STRING_LIST *) s_string_list_new();
00079   new_sheet->master_comp_attrib_list_head = (STRING_LIST *) s_string_list_new();
00080   new_sheet->comp_count = 0;
00081   new_sheet->comp_attrib_count = 0;
00082 
00083   new_sheet->master_net_list_head = (STRING_LIST *) s_string_list_new();
00084   new_sheet->master_net_attrib_list_head = (STRING_LIST *) s_string_list_new();
00085   new_sheet->net_count = 0;
00086   new_sheet->net_attrib_count = 0;
00087 
00088   new_sheet->master_pin_list_head = (STRING_LIST *) s_string_list_new();
00089   new_sheet->master_pin_attrib_list_head = (STRING_LIST *) s_string_list_new();
00090   new_sheet->pin_count = 0;
00091   new_sheet->pin_attrib_count = 0;
00092 
00093   new_sheet->CHANGED = FALSE;
00094 
00095   return (new_sheet);
00096 
00097 }
00098 
00099 
00100 
00101 /*------------------------------------------------------------------*/
00110 void s_sheet_data_add_master_comp_list_items (const GList *obj_list) {
00111   char *temp_uref;
00112   const GList *iter;
00113   
00114 #ifdef DEBUG
00115   printf("=========== Just entered  s_sheet_data_add_master_comp_list_items!  ==============\n");
00116 #endif
00117 
00118   if (verbose_mode) {
00119     printf("- Starting master comp list creation.\n");
00120   }
00121 
00122   /* -----  Iterate through all objects found on page looking for components  ----- */
00123   for (iter = obj_list;
00124        iter != NULL;
00125        iter = g_list_next (iter)) {
00126     OBJECT *o_current = iter->data;
00127 
00128 #ifdef DEBUG
00129       printf("In s_sheet_data_add_master_comp_list_items, examining o_current->name = %s\n", o_current->name);
00130 #endif
00131 
00132       /*-----  only process if this is a component with attributes ----*/
00133       if (o_current->type == OBJ_COMPLEX &&
00134           o_current->attribs != NULL) {
00135 
00136 #if DEBUG
00137     printf("      In s_sheet_data_add_master_comp_list_items; found component on page\n");
00138     printf(". . . . complex_basename = %s.\n", o_current->complex_basename);
00139 #endif
00140     verbose_print(" C");
00141       
00142     temp_uref = s_attrib_get_refdes(o_current);
00143     
00144     /* Now that we have refdes, store refdes and attach attrib list to component */
00145     if (temp_uref) {
00146 #if DEBUG
00147       printf("       In s_sheet_add_master_comp_list, about to add to master list refdes = %s\n", temp_uref);
00148 #endif
00149       s_string_list_add_item(sheet_head->master_comp_list_head, 
00150                   &(sheet_head->comp_count), temp_uref);
00151       g_free(temp_uref);
00152     }
00153     
00154       } /*  if (o_current->type == OBJ_COMPLEX . . . . .) */
00155       
00156   }
00157   
00158   return;
00159 }
00160 
00161 
00162 /*------------------------------------------------------------------*/
00173 void s_sheet_data_add_master_comp_attrib_list_items (const GList *obj_list) {
00174   char *attrib_text;
00175   char *attrib_name;
00176   const GList *o_iter;
00177   GList *a_iter;
00178   OBJECT *a_current;
00179   
00180 #ifdef DEBUG
00181   fflush(stderr);
00182   fflush(stdout);
00183   printf("=========== Just entered  s_sheet_data_add_master_comp_attrib_list_items!  ==============\n");
00184 #endif
00185 
00186   if (verbose_mode) {
00187     printf("- Starting master comp attrib list creation.\n");
00188   }
00189 
00190   /* -----  Iterate through all objects found on page looking for components (OBJ_COMPLEX) ----- */
00191   for (o_iter = obj_list; o_iter != NULL; o_iter = g_list_next (o_iter)) {
00192     OBJECT *o_current = o_iter->data;
00193 
00194 #ifdef DEBUG
00195       printf("In s_sheet_data_add_master_comp_attrib_list_items, examining o_current->name = %s\n", o_current->name);
00196 #endif
00197 
00198       /*-----  only process if this is a component with attributes ----*/
00199       if (o_current->type == OBJ_COMPLEX &&
00200           o_current->attribs != NULL) {
00201 
00202     verbose_print(" C");
00203     
00204     /*------ Iterate through all attribs found on component -----*/
00205     a_iter = o_current->attribs; /* This has a side effect.  Why? */
00206     while (a_iter != NULL) {
00207       a_current = a_iter->data;
00208       if (a_current->type == OBJ_TEXT
00209           && a_current->text != NULL) {  /* found an attribute */
00210         attrib_text = g_strdup(a_current->text->string);
00211         attrib_name = u_basic_breakup_string(attrib_text, '=', 0);
00212 
00213           /* Don't include "refdes" or "slot" because they form the row name */
00214           /* Also don't include "net" per bug found by Steve W. -- 4.3.2007, SDB */
00215         if ( (strcmp(attrib_name, "refdes") != 0) &&
00216          (strcmp(attrib_name, "net") != 0) &&
00217          (strcmp(attrib_name, "slot") != 0) ) {  
00218 #if DEBUG
00219           printf(" . . . from this component, about to add to master comp attrib list attrib = %s\n", attrib_name);
00220 #endif
00221           s_string_list_add_item(sheet_head->master_comp_attrib_list_head, 
00222                      &(sheet_head->comp_attrib_count), attrib_name);
00223         }   /* if (strcmp(attrib_name, "refdes") != 0) */ 
00224         g_free(attrib_name);
00225         g_free(attrib_text);
00226       }
00227       a_iter = g_list_next (a_iter);
00228     }   /*  while  */
00229     
00230       }   /* if (o_current->type == OBJ_COMPLEX) */
00231       
00232   }
00233   
00234   /* -----  Now sort component list into alphabetical order  ----- */
00235   
00236   return;
00237 }
00238 
00239 
00240 
00241 /*------------------------------------------------------------------*/
00250 void s_sheet_data_add_master_net_list_items (const GList *obj_start) {
00251   return;
00252 }
00253 
00254 
00255 /*------------------------------------------------------------------*/
00262 void s_sheet_data_add_master_net_attrib_list_items (const GList *obj_start) {
00263   return;
00264 }
00265 
00266 
00267 /*------------------------------------------------------------------*/
00286 void s_sheet_data_add_master_pin_list_items (const GList *obj_list) {
00287   char *temp_uref;
00288   char *temp_pinnumber;
00289   char *row_label;
00290   const GList *o_iter;
00291   GList *o_lower_iter;
00292 
00293 #ifdef DEBUG
00294   fflush(stderr);
00295   fflush(stdout);
00296   printf("=========== Just entered  s_sheet_data_add_master_pin_list_items!  ==============\n");
00297 #endif
00298 
00299   if (verbose_mode) {
00300     printf("- Starting master pin list creation.\n");
00301   }
00302 
00303   /* -----  Iterate through all objects found on page looking for components  ----- */
00304   for (o_iter = obj_list; o_iter != NULL; o_iter = g_list_next (o_iter)) {
00305     OBJECT *o_current = o_iter->data;
00306 
00307 #ifdef DEBUG
00308     printf ("In s_sheet_data_add_master_pin_list_items, examining o_current->name = %s\n", o_current->name);
00309 #endif
00310 
00311     if (o_current->type == OBJ_COMPLEX) {
00312       temp_uref = s_attrib_get_refdes (o_current);
00313       if (temp_uref != NULL) {      /* make sure object complex has a refdes  */
00314 
00315         /* -----  Now iterate through lower level objects looking for pins.  ----- */
00316         for (o_lower_iter = o_current->complex->prim_objs;
00317              o_lower_iter != NULL;
00318              o_lower_iter = g_list_next (o_lower_iter)) {
00319           OBJECT *o_lower_current = o_lower_iter->data;
00320 #if DEBUG
00321           printf ("In s_sheet_data_add_master_pin_list_items, examining object name %s\n", o_lower_current->name);
00322 #endif
00323           if (o_lower_current->type == OBJ_PIN) {
00324             temp_pinnumber = o_attrib_search_object_attribs_by_name (o_lower_current, "pinnumber", 0);
00325 
00326             if (temp_pinnumber != NULL) {
00327               row_label = g_strconcat (temp_uref, ":", temp_pinnumber, NULL);
00328 #if DEBUG
00329               printf ("In s_sheet_data_add_master_pin_list_items, about to add to master pin list row_label = %s\n", row_label);
00330 #endif
00331               s_string_list_add_item (sheet_head->master_pin_list_head, &(sheet_head->pin_count), row_label);
00332 
00333             } else {      /* didn't find pinnumber.  Report error to log. */
00334               fprintf (stderr, "In s_sheet_data_add_master_pin_list_items, found component pin with no pinnumber.\n");
00335 #ifdef DEBUG
00336               fprintf (stderr, ". . . . refdes = %s.\n", temp_uref);
00337 #endif
00338             }
00339             g_free (temp_pinnumber);
00340 
00341           }
00342         }
00343 
00344       } else {          /* didn't find refdes.  Report error to log. */
00345 #ifdef DEBUG
00346         fprintf (stderr, "In s_sheet_data_add_master_pin_list_items, found component with no refdes.\n");
00347         fprintf (stderr, ". . . . complex_basename = %s.\n", o_current->complex_basename);
00348 #endif
00349       }
00350       g_free (temp_uref);
00351 
00352     }  /*  if (o_current->type == OBJ_COMPLEX)  */
00353   }
00354       
00355   return;
00356 }
00357 
00358 
00359 /*------------------------------------------------------------------*/
00376 void s_sheet_data_add_master_pin_attrib_list_items (const GList *obj_list) {
00377   char *temp_uref;
00378   char *attrib_text;
00379   char *attrib_name;
00380   char *attrib_value;
00381   const GList *o_iter;
00382   GList *o_lower_iter, *a_iter;
00383   OBJECT *pin_attrib;
00384   
00385 #ifdef DEBUG
00386   fflush(stderr);
00387   fflush(stdout);
00388   printf("=========== Just entered  s_sheet_data_add_master_pin_attrib_list_items!  ==============\n");
00389 #endif
00390 
00391   if (verbose_mode) {
00392     printf("- Starting master pin attrib list creation.\n");
00393   }
00394 
00395   /* -----  Iterate through all objects found on page looking for components  ----- */
00396   for (o_iter = obj_list; o_iter != NULL; o_iter = g_list_next (o_iter)) {
00397     OBJECT *o_current = o_iter->data;
00398 
00399 #ifdef DEBUG
00400       printf("In s_sheet_data_add_master_pin_attrib_list_items, examining o_current->name = %s\n", o_current->name);
00401 #endif
00402 
00403       if (o_current->type == OBJ_COMPLEX) {
00404     temp_uref = s_attrib_get_refdes(o_current);
00405     if (temp_uref != NULL) {      /* make sure object complex has a refdes  */
00406       
00407       /* -----  Now iterate through lower level objects looking for pins.  ----- */
00408           for (o_lower_iter = o_current->complex->prim_objs;
00409                o_lower_iter != NULL;
00410                o_lower_iter = g_list_next (o_lower_iter)) {
00411             OBJECT *o_lower_current = o_lower_iter->data;
00412 #if DEBUG
00413         printf("In s_sheet_data_add_master_pin_attrib_list_items, examining component refdes =  %s\n", temp_uref);
00414 #endif
00415         if (o_lower_current->type == OBJ_PIN) {
00416           /* -----  Found a pin.  Now get attrib head and loop on attribs.  ----- */
00417           a_iter = o_lower_current->attribs;
00418           while (a_iter != NULL) {
00419         pin_attrib = a_iter->data;
00420         if (pin_attrib->type == OBJ_TEXT
00421             && pin_attrib->text != NULL) {  /* found an attribute */
00422           attrib_text = g_strdup(pin_attrib->text->string);
00423           attrib_name = u_basic_breakup_string(attrib_text, '=', 0);
00424           attrib_value = s_misc_remaining_string(attrib_text, '=', 1);
00425           if ( (strcmp(attrib_name, "pinnumber") != 0) 
00426                && (attrib_value != NULL) ) {  
00427             /* Don't include "pinnumber" because it is already in other master list.
00428              * Also guard against pathalogical symbols which have non-attrib text inside pins. */
00429 
00430 #if DEBUG
00431         printf("In s_sheet_data_add_master_pin_attrib_list_items, found pin attrib =  %s\n", attrib_name);
00432         printf(". . . . . adding it to master_pin_attrib_list\n");
00433 #endif
00434 
00435             s_string_list_add_item(sheet_head->master_pin_attrib_list_head, 
00436                        &(sheet_head->pin_attrib_count), attrib_name);
00437           }   /* if (strcmp(attrib_name, "pinnumber") != 0) */ 
00438           g_free(attrib_value);
00439           g_free(attrib_name);
00440           g_free(attrib_text);
00441         }
00442         a_iter = g_list_next (a_iter);
00443           }   /*   while (pin_attrib != NULL)  */
00444         }
00445       }
00446 
00447       g_free(temp_uref);
00448     }  /*  if (temp_uref != NULL )  */
00449     
00450       }  /* if (o_current->type == OBJ_COMPLEX)  */
00451   }
00452   return;
00453 
00454 }
00455 
00456 
00457 
00458 
00459 /*------------------------------------------------------------------*/
00468 void s_sheet_data_gtksheet_to_sheetdata() {
00469   s_table_gtksheet_to_all_tables();
00470   /* do I need to do anything else here? */
00471 
00472   return;
00473 }
00474 
00475 
00476 
00477 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines