pcb 4.1.1
An interactive printed circuit board layout editor.
|
File save, load, merge ... routines. More...
#include "global.h"
#include <dirent.h>
#include <time.h>
#include <sys/stat.h>
#include <stdio.h>
#include "buffer.h"
#include "change.h"
#include "create.h"
#include "crosshair.h"
#include "data.h"
#include "edif_parse.h"
#include "error.h"
#include "file.h"
#include "hid.h"
#include "layerflags.h"
#include "misc.h"
#include "mymem.h"
#include "parse_l.h"
#include "pcb-printf.h"
#include "polygon.h"
#include "rats.h"
#include "remove.h"
#include "set.h"
#include "strflags.h"
Go to the source code of this file.
Defines | |
#define | F2S(OBJ, TYPE) flags_to_string ((OBJ)->Flags, TYPE) |
#define | PCB_FILE_VERSION_BURIED_VIAS 20170218 |
#define | PCB_FILE_VERSION_HOLES 20100606 |
#define | PCB_FILE_VERSION_BASELINE 20091103 |
#define | BLANK(x) |
Functions | |
static void | PrintQuotedString (FILE *FP, char *S) |
Writes the quoted string created by another subroutine. | |
static void | WritePCBInfoHeader (FILE *FP) |
Writes layout header information. | |
static void | WritePCBDataHeader (FILE *FP) |
Writes data header. | |
static void | WritePCBFontData (FILE *FP) |
Writes font data of non empty symbols. | |
static void | WriteViaData (FILE *FP, DataType *Data) |
Writes via data. | |
static void | WritePCBRatData (FILE *FP) |
Writes rat-line data. | |
static void | WriteElementData (FILE *FP, DataType *Data) |
Writes element data. | |
static void | WriteLayerData (FILE *FP, Cardinal Number, LayerType *layer) |
Writes layer data. | |
static int | WritePCB (FILE *FP) |
Writes PCB to file. | |
static int | WritePCBFile (char *Filename) |
Writes PCB to file. | |
static int | WritePipe (char *Filename, bool thePcb) |
Writes to pipe using the command defined by Settings.SaveCommand f are replaced by the passed filename. | |
static int | ParseLibraryTree (void) |
This function loads the newlib footprints into the Library. | |
static int | LoadNewlibFootprintsFromDir (char *libpath, char *toppath, bool recursive) |
Parse the directory tree where newlib footprints are found. | |
int | PCBFileVersionNeeded (void) |
static int | string_cmp (const char *a, const char *b) |
static int | netlist_sort (const void *va, const void *vb) |
static int | netnode_sort (const void *va, const void *vb) |
static void | sort_library (LibraryType *lib) |
void | sort_netlist () |
FILE * | CheckAndOpenFile (char *Filename, bool Confirm, bool AllButton, bool *WasAllButton, bool *WasCancelButton) |
Opens a file and check if it exists. | |
FILE * | OpenConnectionDataFile (void) |
Opens a file for saving connection data. | |
int | SaveBufferElements (char *Filename) |
Save elements in the current buffer. | |
int | SavePCB (char *file) |
Save PCB. | |
static void | set_some_route_style () |
Set the route style to the first one, if the current one doesn't happen to match any. | |
static int | real_load_pcb (char *Filename, bool revert) |
Load PCB. | |
int | LoadPCB (char *file) |
Load PCB. | |
int | RevertPCB (void) |
Revert PCB. | |
static void | WriteAttributeList (FILE *FP, AttributeListType *list, char *prefix) |
Writes out an attribute list. | |
static void | WritePCBNetlistData (FILE *FP) |
Writes netlist data. | |
static int | WriteBuffer (FILE *FP) |
Writes just the elements in the buffer to file. | |
void | SaveInTMP (void) |
Saves the layout in a temporary file. | |
void | EmergencySave (void) |
void | DisableEmergencySave (void) |
static void | backup_cb (hidval data) |
Callback for the autosave. | |
void | EnableAutosave (void) |
void | Backup (void) |
Creates a backup file. | |
void | SaveTMPData (void) |
Makes a temporary copy of the data. | |
void | RemoveTMPData (void) |
Removes the temporary copy of the data file. | |
int | ReadLibraryContents (void) |
Read contents of the library description file (for M4) and then read in M4 libs. | |
int | ReadNetlist (char *filename) |
Read in a netlist and store it in the netlist menu. | |
static int | ReadEdifNetlist (char *filename) |
int | ImportNetlist (char *filename) |
Variables | |
static char | TMPFilename [80] |
static int | netlist_sort_offset = 0 |
static bool | dont_save_any_more = false |
Front-end for 'SaveInTMP()'. | |
static hidval | backup_timer |
File save, load, merge ... routines.
PCB, interactive printed circuit board design
Copyright (C) 1994,1995,1996,1997,1998,2005,2006 Thomas Nau
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Contact addresses for paper mail and Email: Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany Thomas.Nau@rz.uni-ulm.de
Definition in file file.c.
#define BLANK | ( | x | ) |
#define F2S | ( | OBJ, | |
TYPE | |||
) | flags_to_string ((OBJ)->Flags, TYPE) |
Definition at line 134 of file file.c.
Referenced by WriteElementData(), WriteLayerData(), WritePCBRatData(), and WriteViaData().
#define PCB_FILE_VERSION_BASELINE 20091103 |
First version ever saved.
Definition at line 164 of file file.c.
Referenced by PCBFileVersionNeeded().
#define PCB_FILE_VERSION_BURIED_VIAS 20170218 |
#define PCB_FILE_VERSION_HOLES 20100606 |
void Backup | ( | void | ) |
Creates a backup file.
The default is to use the pcb file name with a "~" appended (like "foo.pcb~") and if we don't have a pcb file name then use the template in BACKUP_NAME.
Definition at line 1084 of file file.c.
References PCBType::Filename, filename, malloc(), PCB, and WritePCBFile().
Referenced by backup_cb().
static void backup_cb | ( | hidval | data | ) | [static] |
Callback for the autosave.
If the backup interval is > 0 then set another timer.
Otherwise we do nothing and it is up to the GUI to call EnableAutosave() after setting Settings.
BackupInterval > 0 again.
Definition at line 1048 of file file.c.
References hid_st::add_timer, Backup(), SettingType::BackupInterval, gui, hidval::ptr, and Settings.
Referenced by EnableAutosave().
FILE* CheckAndOpenFile | ( | char * | Filename, |
bool | Confirm, | ||
bool | AllButton, | ||
bool * | WasAllButton, | ||
bool * | WasCancelButton | ||
) |
Opens a file and check if it exists.
Definition at line 262 of file file.c.
References _, hid_st::confirm_dialog, fp, gui, and OpenErrorMessage().
Referenced by ActionSaveTo(), and OpenConnectionDataFile().
void DisableEmergencySave | ( | void | ) |
Definition at line 1032 of file file.c.
References dont_save_any_more.
Referenced by QuitApplication().
void EmergencySave | ( | void | ) |
Definition at line 1021 of file file.c.
References dont_save_any_more, and SaveInTMP().
Referenced by main(), MyFatal(), and QuitApplication().
void EnableAutosave | ( | void | ) |
Definition at line 1058 of file file.c.
References hid_st::add_timer, backup_cb(), SettingType::BackupInterval, gui, hidval::ptr, Settings, hid_st::stop_timer, and x.
Referenced by config_backup_spin_button_cb(), and main().
int ImportNetlist | ( | char * | filename | ) |
Definition at line 1659 of file file.c.
References fp, ReadEdifNetlist(), and ReadNetlist().
Referenced by ActionLoadFrom().
static int LoadNewlibFootprintsFromDir | ( | char * | libpath, |
char * | toppath, | ||
bool | recursive | ||
) | [static] |
Parse the directory tree where newlib footprints are found.
This is a helper function for ParseLibrary Tree.
Given a char *path, it finds all newlib footprints in that dir, sticks them into the library menu structure named entry, and recurses into subdirectories.
Definition at line 1149 of file file.c.
References _, LibraryEntryType::AllocatedMemory, ChdirErrorMessage(), GetLibraryEntryMemory(), GetLibraryMenuMemory(), GetWorkingDirectory(), len, Library, LibraryEntryType::ListEntry, Message(), NSTRCMP, OpendirErrorMessage(), and LibraryEntryType::Template.
Referenced by ParseLibraryTree().
int LoadPCB | ( | char * | file | ) |
Load PCB.
Definition at line 498 of file file.c.
References real_load_pcb().
Referenced by ActionLoadFrom(), and main().
static int netlist_sort | ( | const void * | va, |
const void * | vb | ||
) | [static] |
Definition at line 217 of file file.c.
References LibraryMenuType::Name, and string_cmp().
Referenced by sort_library().
static int netnode_sort | ( | const void * | va, |
const void * | vb | ||
) | [static] |
Definition at line 231 of file file.c.
References LibraryEntryType::ListEntry, and string_cmp().
Referenced by sort_library().
FILE* OpenConnectionDataFile | ( | void | ) |
Opens a file for saving connection data.
Definition at line 308 of file file.c.
References _, CheckAndOpenFile(), hid_st::fileselect, fp, and gui.
static int ParseLibraryTree | ( | void | ) | [static] |
This function loads the newlib footprints into the Library.
It examines all directories pointed to by Settings.LibraryTree. It calls the subfunction LoadNewlibFootprintsFromDir to put the footprints into PCB's internal datastructures.
Definition at line 1330 of file file.c.
References _, ChdirErrorMessage(), GetWorkingDirectory(), SettingType::LibraryTree, LoadNewlibFootprintsFromDir(), Message(), and Settings.
Referenced by ReadLibraryContents().
int PCBFileVersionNeeded | ( | void | ) |
This is the version needed by the file we're saving.
Definition at line 167 of file file.c.
References ALLPOLYGON_LOOP, PCBType::Data, END_LOOP, ENDALL_LOOP, PCB, PCB_FILE_VERSION_BASELINE, PCB_FILE_VERSION_BURIED_VIAS, PCB_FILE_VERSION_HOLES, and VIA_LOOP.
Referenced by WritePCBDataHeader().
static void PrintQuotedString | ( | FILE * | FP, |
char * | S | ||
) | [static] |
Writes the quoted string created by another subroutine.
Definition at line 516 of file file.c.
References CreateQuotedString(), and DynamicStringType::Data.
Referenced by WriteAttributeList(), WriteElementData(), WriteLayerData(), WritePCBDataHeader(), WritePCBNetlistData(), and WriteViaData().
static int ReadEdifNetlist | ( | char * | filename | ) | [static] |
Definition at line 1684 of file file.c.
References _, Message(), and ParseEDIF().
Referenced by ImportNetlist().
int ReadLibraryContents | ( | void | ) |
Read contents of the library description file (for M4) and then read in M4 libs.
Then call a fcn to read the newlib footprints.
Definition at line 1425 of file file.c.
References LibraryEntryType::AllocatedMemory, command, LibraryEntryType::Description, LibraryMenuType::directory, EMPTY, EvaluateFilename(), GetLibraryEntryMemory(), GetLibraryMenuMemory(), len, Library, SettingType::LibraryContentsCommand, SettingType::LibraryFilename, SettingType::LibraryPath, LibraryEntryType::ListEntry, Message(), LibraryMenuType::Name, LibraryEntryType::Package, ParseLibraryTree(), PopenErrorMessage(), Settings, sort_library(), LibraryEntryType::Template, UNKNOWN, and LibraryEntryType::Value.
Referenced by main().
int ReadNetlist | ( | char * | filename | ) |
Read in a netlist and store it in the netlist menu.
Definition at line 1538 of file file.c.
References _, BLANK, command, EMPTY_STRING_P, EvaluateFilename(), LibraryMenuType::flag, fp, GetLibraryEntryMemory(), GetLibraryMenuMemory(), len, lines, LibraryEntryType::ListEntry, Message(), LibraryMenuType::Name, PCBType::NetlistLib, PCB, PopenErrorMessage(), SettingType::RatCommand, SettingType::RatPath, Settings, sort_netlist(), and LibraryMenuType::Style.
Referenced by ImportNetlist().
static int real_load_pcb | ( | char * | Filename, |
bool | revert | ||
) | [static] |
Load PCB.
Parse the file with enabled 'PCB mode' (see parser) if successful, update some other stuff.
If revert is true, we pass "revert" as a parameter to the HID's PCBChanged action.
Definition at line 399 of file file.c.
References _, AssignDefaultLayerTypes(), AttributeGet, AttributePut, ChangePCBSize(), CreateNewPCB(), CreateNewPCBPost(), Crosshair, PCBType::CursorX, PCBType::CursorY, unit::family, PCBType::Filename, PCBType::Font, get_increments_struct(), get_unit_struct(), GetValue(), PCBType::Grid, SettingType::grid_unit, gui, hid_action(), hid_actionl(), SettingType::increments, hid_st::log, PCBType::MaxHeight, PCBType::MaxWidth, Message(), ParsePCB(), PCB, RemovePCB(), ResetStackAndVisibility(), set_some_route_style(), SetChangedFlag(), Settings, sort_netlist(), unit::suffix, FontType::Valid, CrosshairType::X, and CrosshairType::Y.
Referenced by LoadPCB(), and RevertPCB().
void RemoveTMPData | ( | void | ) |
Removes the temporary copy of the data file.
Definition at line 1134 of file file.c.
References TMPFilename.
Referenced by Parse().
int RevertPCB | ( | void | ) |
Revert PCB.
Definition at line 507 of file file.c.
References PCBType::Filename, PCB, and real_load_pcb().
Referenced by ActionLoadFrom(), and info_bar_response_cb().
int SaveBufferElements | ( | char * | Filename | ) |
Save elements in the current buffer.
Definition at line 342 of file file.c.
References SWAP_IDENT, SwapBuffers(), and WritePipe().
Referenced by ActionPasteBuffer(), and ActionSaveTo().
void SaveInTMP | ( | void | ) |
Saves the layout in a temporary file.
This is used for fatal errors and does not call the program specified in 'saveCommand' for safety reasons.
Definition at line 1001 of file file.c.
References _, PCBType::Changed, filename, Message(), PCB, and WritePCBFile().
Referenced by ActionNew(), and EmergencySave().
int SavePCB | ( | char * | file | ) |
Save PCB.
Definition at line 358 of file file.c.
References gui, hid_st::notify_save_pcb, and WritePipe().
Referenced by ActionSaveTo().
void SaveTMPData | ( | void | ) |
Makes a temporary copy of the data.
This is useful for systems which doesn't support calling functions on exit.
We use this to save the data before LEX and YACC functions are called because they are able to abort the program.
Definition at line 1124 of file file.c.
References TMPFilename, and WritePCBFile().
Referenced by Parse().
static void set_some_route_style | ( | ) | [static] |
Set the route style to the first one, if the current one doesn't happen to match any.
This way, "revert" won't change the route style.
Definition at line 379 of file file.c.
References RouteStyleType::Diameter, hid_get_flag(), RouteStyleType::Hole, RouteStyleType::Keepaway, PCB, PCBType::RouteStyle, SetKeepawayWidth(), SetLineSize(), SetViaDrillingHole(), SetViaSize(), and RouteStyleType::Thick.
Referenced by real_load_pcb().
static void sort_library | ( | LibraryType * | lib | ) | [static] |
Definition at line 241 of file file.c.
References LibraryMenuType::Entry, LibraryMenuType::EntryN, LibraryType::Menu, LibraryType::MenuN, netlist_sort(), and netnode_sort().
Referenced by ReadLibraryContents(), and sort_netlist().
void sort_netlist | ( | void | ) |
Definition at line 251 of file file.c.
References netlist_sort_offset, PCBType::NetlistLib, PCB, and sort_library().
Referenced by Netlist(), ReadNetlist(), and real_load_pcb().
static int string_cmp | ( | const char * | a, |
const char * | b | ||
) | [static] |
Definition at line 187 of file file.c.
Referenced by netlist_sort(), and netnode_sort().
static void WriteAttributeList | ( | FILE * | FP, |
AttributeListType * | list, | ||
char * | prefix | ||
) | [static] |
Writes out an attribute list.
Definition at line 528 of file file.c.
References AttributeListType::List, AttributeType::name, AttributeListType::Number, PrintQuotedString(), and AttributeType::value.
Referenced by WriteElementData(), WriteLayerData(), and WritePCB().
static int WriteBuffer | ( | FILE * | FP | ) | [static] |
Writes just the elements in the buffer to file.
Definition at line 872 of file file.c.
References max_copper_layer, PASTEBUFFER, SILK_LAYER, STATUS_OK, WriteElementData(), WriteLayerData(), and WriteViaData().
Referenced by WritePipe().
static void WriteElementData | ( | FILE * | FP, |
DataType * | Data | ||
) | [static] |
Writes element data.
Definition at line 710 of file file.c.
References ElementType::Arc, ElementType::ArcN, ElementType::Attributes, pin_st::Clearance, ArcType::Delta, DESCRIPTION_NAME, DESCRIPTION_TEXT, pin_st::DrillingHole, DataType::Element, EMPTY, F2S, ArcType::Height, line, ElementType::Line, ElementType::LineN, ElementType::MarkX, ElementType::MarkY, pad_st::Mask, pin_st::Mask, n, pad_st::Name, pin_st::Name, NAMEONPCB_NAME, pad_st::Number, pin_st::Number, ElementType::Pad, ElementType::PadN, pcb_fprintf(), pin, ElementType::Pin, ElementType::PinN, PrintQuotedString(), ArcType::StartAngle, ArcType::Thickness, pin_st::Thickness, VALUE_NAME, ArcType::Width, WriteAttributeList(), ArcType::X, pin_st::X, X, ArcType::Y, pin_st::Y, and Y.
Referenced by WriteBuffer(), WritePCB(), and WritePipe().
Writes layer data.
Definition at line 793 of file file.c.
References LayerType::Arc, LayerType::ArcN, LayerType::Attributes, ArcType::Clearance, ArcType::Delta, TextType::Direction, EMPTY, F2S, ArcType::Height, polygon_st::HoleIndex, layertype_to_string(), line, LayerType::Line, LayerType::LineN, n, LayerType::Name, pcb_fprintf(), polygon_st::PointN, polygon_st::Points, LayerType::Polygon, LayerType::PolygonN, PrintQuotedString(), TextType::Scale, ArcType::StartAngle, LayerType::Text, LayerType::TextN, TextType::TextString, ArcType::Thickness, LayerType::Type, ArcType::Width, WriteAttributeList(), PointType::X, TextType::X, ArcType::X, PointType::Y, TextType::Y, and ArcType::Y.
Referenced by WriteBuffer(), and WritePCB().
static int WritePCB | ( | FILE * | FP | ) | [static] |
Writes PCB to file.
Definition at line 887 of file file.c.
References ALLOW_MM, ALLOW_READABLE, PCBType::Attributes, PCBType::Data, DataType::Layer, max_copper_layer, PCB, SettingType::SaveMetricOnly, set_allow_readable(), Settings, SILK_LAYER, STATUS_OK, WriteAttributeList(), WriteElementData(), WriteLayerData(), WritePCBDataHeader(), WritePCBFontData(), WritePCBInfoHeader(), WritePCBNetlistData(), WritePCBRatData(), and WriteViaData().
Referenced by WritePCBFile(), and WritePipe().
static void WritePCBDataHeader | ( | FILE * | FP | ) | [static] |
Writes data header.
The name of the PCB, cursor location, zoom and grid layergroups and some flags.
Definition at line 563 of file file.c.
References PCBType::Bloat, c_dtostr(), COORD_TO_MIL, RouteStyleType::Diameter, SettingType::DrawGrid, EMPTY, PCBType::Flags, PCBType::Grid, PCBType::GridOffsetX, PCBType::GridOffsetY, RouteStyleType::Hole, PCBType::IsleArea, RouteStyleType::Keepaway, PCBType::LayerGroups, LayerGroupsToString(), PCBType::MaxHeight, PCBType::MaxWidth, PCBType::minDrill, PCBType::minRing, PCBType::minSlk, PCBType::minWid, RouteStyleType::Name, PCBType::Name, PCB, pcb_fprintf(), PCBFileVersionNeeded(), pcbflags_to_string(), PrintQuotedString(), PCBType::RouteStyle, Settings, PCBType::Shrink, PCBType::ThermScale, and RouteStyleType::Thick.
Referenced by WritePCB().
static int WritePCBFile | ( | char * | Filename | ) | [static] |
Writes PCB to file.
Definition at line 913 of file file.c.
References fp, OpenErrorMessage(), STATUS_ERROR, and WritePCB().
Referenced by Backup(), SaveInTMP(), and SaveTMPData().
static void WritePCBFontData | ( | FILE * | FP | ) | [static] |
Writes font data of non empty symbols.
Definition at line 610 of file file.c.
References SymbolType::Delta, PCBType::Font, SymbolType::Line, line, SymbolType::LineN, PCB, pcb_fprintf(), FontType::Symbol, and SymbolType::Valid.
Referenced by WritePCB().
static void WritePCBInfoHeader | ( | FILE * | FP | ) | [static] |
Writes layout header information.
Definition at line 546 of file file.c.
References Progname.
Referenced by WritePCB().
static void WritePCBNetlistData | ( | FILE * | FP | ) | [static] |
Writes netlist data.
Definition at line 677 of file file.c.
References LibraryMenuType::Entry, LibraryMenuType::EntryN, LibraryEntryType::ListEntry, LibraryType::Menu, LibraryType::MenuN, n, LibraryMenuType::Name, PCBType::NetlistLib, PCB, PrintQuotedString(), LibraryMenuType::Style, and UNKNOWN.
Referenced by WritePCB().
static void WritePCBRatData | ( | FILE * | FP | ) | [static] |
Writes rat-line data.
Definition at line 659 of file file.c.
References PCBType::Data, F2S, RatType::group1, RatType::group2, line, PCB, pcb_fprintf(), and DataType::Rat.
Referenced by WritePCB().
static int WritePipe | ( | char * | Filename, |
bool | thePcb | ||
) | [static] |
Writes to pipe using the command defined by Settings.SaveCommand f are replaced by the passed filename.
Definition at line 933 of file file.c.
References command, PCBType::Data, DynamicStringType::Data, DSAddCharacter(), DSAddString(), DSClearString(), EMPTY_STRING_P, fp, PCBType::is_footprint, Message(), PCB, PopenErrorMessage(), SettingType::SaveCommand, Settings, STATUS_ERROR, WriteBuffer(), WriteElementData(), and WritePCB().
Referenced by SaveBufferElements(), and SavePCB().
static void WriteViaData | ( | FILE * | FP, |
DataType * | Data | ||
) | [static] |
Writes via data.
Definition at line 639 of file file.c.
References pin_st::BuriedFrom, pin_st::BuriedTo, pin_st::Clearance, pin_st::DrillingHole, EMPTY, F2S, pin_st::Mask, pin_st::Name, pcb_fprintf(), PrintQuotedString(), pin_st::Thickness, DataType::Via, pin_st::X, and pin_st::Y.
Referenced by WriteBuffer(), and WritePCB().
hidval backup_timer [static] |
bool dont_save_any_more = false [static] |
Front-end for 'SaveInTMP()'.
Just makes sure that the routine is only called once.
Definition at line 1019 of file file.c.
Referenced by DisableEmergencySave(), and EmergencySave().
int netlist_sort_offset = 0 [static] |
Definition at line 214 of file file.c.
Referenced by sort_netlist().
char TMPFilename[80] [static] |
Definition at line 110 of file file.c.
Referenced by RemoveTMPData(), and SaveTMPData().