1 /* gEDA - GPL Electronic Design Automation
2 * gattrib -- gEDA component and net attribute manipulation using spreadsheet.
3 * Copyright (C) 2003-2008 Stuart D. Brorson.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
21 * \brief Import/export functions
23 * This file holds fcns used for import/export of attribute sheets.
24 * At the moment, this is only component sheets.
35 /*------------------------------------------------------------------
36 * Gattrib specific includes
37 *------------------------------------------------------------------*/
38 #include <libgeda/libgeda.h> /* geda library fcns */
39 #include "../include/struct.h" /* typdef and struct declarations */
40 #include "../include/prototype.h" /* function prototypes */
41 #include "../include/globals.h"
43 #ifdef HAVE_LIBDMALLOC
48 /* =================== Public Functions ====================== */
49 /* ------------------------------------------------------------- */
50 /* \brief Export components to CSV
52 * This function is invoked when the user selects file ->
53 * export from the pull-down menu. It writes out a CSV file
54 * of the design for external processing.
56 * \param filename The name of the file to export to
58 void f_export_components(gchar
*filename
)
68 /* ----- Check that we have a component ----- */
69 cur_page
= gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook
));
71 /* We only export the component table */
72 /* XXXXX Maybe throw up error message in window instead? */
73 x_dialog_unimplemented_feature();
78 /* ----- First try to open file for writing ----- */
81 printf("In f_export_components, trying to open %s.\n", filename
);
83 fp
= fopen(filename
, "wb");
85 s_log_message("o_save: Could not open [%s]\n", filename
);
86 /* XXXXX Throw up error message in window */
91 /* ----- Now write out data ----- */
92 num_rows
= sheet_head
->comp_count
;
93 num_cols
= sheet_head
->comp_attrib_count
;
95 /* First export top row -- attribute names */
96 /* Print out "refdes" since that's always the first column */
97 fprintf(fp
, "refdes, ");
98 /* Print out optional attrib names */
99 for (j
= 0; j
< num_cols
-1; j
++) {
100 text
= g_strdup( s_string_list_get_data_at_index(
101 sheet_head
->master_comp_attrib_list_head
, j
) );
102 fprintf(fp
, "%s, ", text
);
105 /* Print out last attrib name with no comma and with \n. */
106 text
= g_strdup( s_string_list_get_data_at_index(
107 sheet_head
->master_comp_attrib_list_head
, j
) );
108 fprintf(fp
, "%s\n", text
);
112 /* Now export the contents of the sheet */
113 for (i
= 0; i
< num_rows
; i
++) {
115 /* First output the component refdes */
116 text
= g_strdup( s_string_list_get_data_at_index(
117 sheet_head
->master_comp_list_head
, i
) );
119 printf("In f_export_components, getting refes, i = %d.\n", i
);
120 printf("In f_export_components, output component refdes %s.\n", text
);
122 fprintf(fp
, "%s, ",text
);
125 /* Now export the attrib values for first n-1 cols */
126 for (j
= 0; j
< num_cols
-1; j
++) {
127 if ( (sheet_head
->component_table
)[i
][j
].attrib_value
) { /* found a string */
128 text
= (gchar
*) g_strdup( (sheet_head
->component_table
)[i
][j
].attrib_value
);
130 printf("In f_export_components, output attribute %s.\n", text
);
132 fprintf(fp
, "%s, ", text
);
134 } else { /* no attrib string */
136 printf("In f_export_components, output blank attrib space\n");
140 } /* end of for over cols */
141 /* Now export attrib value for last col (with no "," and with "\n" */
142 if ( (sheet_head
->component_table
)[i
][j
].attrib_value
) { /* found a string */
143 text
= (gchar
*) g_strdup( (sheet_head
->component_table
)[i
][j
].attrib_value
);
145 printf("In f_export_components, output final attribute %s.\n", text
);
147 fprintf(fp
, "%s\n", text
);
149 } else { /* no attrib string */
151 printf("In f_export_components, output blank at end of line.\n");
156 printf("In f_export_components, Go to next row.\n");
158 } /* close of for over rows */