2012-06-09 17:00:13 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 CERN.
|
2023-03-30 11:49:23 +00:00
|
|
|
* Copyright (C) 1992-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-06-09 17:00:13 +00:00
|
|
|
*
|
|
|
|
* 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, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
#ifndef PCB_IO_KICAD_SEXPR_H_
|
|
|
|
#define PCB_IO_KICAD_SEXPR_H_
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2023-12-19 17:39:26 +00:00
|
|
|
#include <pcb_io/pcb_io.h>
|
|
|
|
#include <pcb_io/pcb_io_mgr.h>
|
|
|
|
|
2023-08-13 02:26:06 +00:00
|
|
|
#include <richio.h>
|
2012-06-09 17:00:13 +00:00
|
|
|
#include <string>
|
2021-07-29 09:47:43 +00:00
|
|
|
#include <layer_ids.h>
|
2022-11-28 02:27:34 +00:00
|
|
|
#include <boost/ptr_container/ptr_map.hpp>
|
|
|
|
#include <wx_filename.h>
|
2022-02-11 21:38:31 +00:00
|
|
|
#include "widgets/report_severity.h"
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
class BOARD;
|
|
|
|
class BOARD_ITEM;
|
2012-10-07 15:37:25 +00:00
|
|
|
class FP_CACHE;
|
2023-12-24 01:21:58 +00:00
|
|
|
class PCB_IO_KICAD_SEXPR_PARSER;
|
Added NETINFO_MAPPING, to ease saving nets with consecutive net codes (without modifying the net codes during the run time).
Now, nets are saved with consecutive net codes (both modern & legacy plugins).
Zones are saved together with their nets, without depending on the fact if there are any pads with such net. Therefore validation of zone net names was removed (pcbnew/class_board.cpp).
Performed tests:
- Changed a pad's net name from empty to existent - ok, name was changed.
- Changed a pad's net name from empty to nonexistent - ok, error message is displayed, net name stays empty.
- Changed a pad's net name from existent to empty - ok, net name became empty
- Changed a pad's net name from existent to nonexistent - ok, error message is displayed, net name is not changed.
- Drawn a zone that belongs to a net, then modified schematics so the net does not exist anymore. After reloading the net list, all pads/tracks are updated. Zones still belongs to the net that does not exist in the schematic (but still exists in .kicad_pcb file). After running DRC, the zone becomes not filled.
- Undo & redo affects assignment of a polygon to a specific net (you may change net of a polygon, refill it and undo/redo the changes).
- KiCad s-expr & legacy, Eagle, P-CAD boards seem to load without any problem (they also contain correct net names assigned to the appropriate pads). All types of board file formats were loaded, then saved in sexpr format and reopened with a KiCad built from the master branch (without my modifications).
- A few boards were also saved using the legacy format and were opened with the master KiCad without any issues.
- Change a net name for a pad, restore with undo/redo - ok
- Remove everything, restore with undo - ok
- Remove everything, reload netlist - ok
Differences observed between files saved by the master branch KiCad and this one:
- list of nets are not saved in any particular order, so net codes may differ
- the default net class does not contain the unconnected net
2014-01-28 09:19:51 +00:00
|
|
|
class NETINFO_MAPPING;
|
2019-07-03 21:19:09 +00:00
|
|
|
class BOARD_DESIGN_SETTINGS;
|
2021-06-11 16:59:28 +00:00
|
|
|
class PCB_DIMENSION_BASE;
|
2020-10-04 23:34:59 +00:00
|
|
|
class PCB_SHAPE;
|
2023-10-23 17:23:24 +00:00
|
|
|
class PCB_REFERENCE_IMAGE;
|
2019-07-03 21:19:09 +00:00
|
|
|
class PCB_TARGET;
|
2020-11-12 22:30:02 +00:00
|
|
|
class PAD;
|
2020-08-12 11:23:30 +00:00
|
|
|
class PCB_GROUP;
|
2023-10-07 01:55:45 +00:00
|
|
|
class PCB_GENERATOR;
|
2021-06-11 21:07:02 +00:00
|
|
|
class PCB_TRACK;
|
2020-11-11 23:05:59 +00:00
|
|
|
class ZONE;
|
2020-10-04 23:34:59 +00:00
|
|
|
class PCB_TEXT;
|
2022-01-30 10:52:52 +00:00
|
|
|
class PCB_TEXTBOX;
|
2022-01-04 23:00:00 +00:00
|
|
|
class EDA_TEXT;
|
|
|
|
class SHAPE_LINE_CHAIN;
|
2023-05-12 21:03:54 +00:00
|
|
|
class TEARDROP_PARAMETERS;
|
2023-12-24 01:21:58 +00:00
|
|
|
class PCB_IO_KICAD_SEXPR; // forward decl
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2012-11-10 06:39:18 +00:00
|
|
|
/// Current s-expression file format version. 2 was the last legacy format version.
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2016-08-15 15:55:36 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 3 // first s-expression format, used legacy cu stack
|
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 4 // reversed cu stack, changed Inner* to In* in reverse order
|
|
|
|
// // went to 32 Cu layers from 16.
|
2023-08-27 19:42:09 +00:00
|
|
|
//----------------- Start of 5.0 development -----------------
|
2017-01-27 12:26:42 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20160815 // differential pair settings per net class
|
2017-09-19 11:21:38 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20170123 // EDA_TEXT refactor, moved 'hide'
|
2018-02-05 20:55:00 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20170920 // long pad names and custom pad shape
|
2017-11-14 09:53:59 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20170922 // Keepout zones can exist on multiple layers
|
2017-11-25 19:55:32 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20171114 // Save 3D model offset in mm, instead of inches
|
2020-10-04 23:34:59 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20171125 // Locked/unlocked FP_TEXT
|
2019-03-31 06:46:36 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20171130 // 3D model offset written using "offset" parameter
|
2023-08-27 19:42:09 +00:00
|
|
|
//----------------- Start of 6.0 development -----------------
|
2019-04-14 17:58:35 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20190331 // hatched zones and chamfered round rect pads
|
2019-05-16 13:46:54 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20190421 // curves in custom pads
|
2019-07-03 21:19:09 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20190516 // Remove segment count from zones
|
2019-07-27 19:09:43 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20190605 // Add layer defaults
|
2019-11-23 09:07:56 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20190905 // Add board physical stackup info in setup section
|
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20190907 // Keepout areas in footprints
|
2019-12-11 10:36:45 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20191123 // pin function in pads
|
2020-05-12 19:38:29 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200104 // pad property for fabrication
|
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200119 // arcs in tracks
|
2020-05-18 22:55:10 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200512 // page -> paper
|
2020-06-15 19:50:20 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200518 // save hole_to_hole_min
|
2020-06-24 01:09:15 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200614 // Add support for fp_rects and gr_rects
|
2020-05-31 21:42:04 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200625 // Multilayer zones, zone names, island controls
|
2020-07-24 22:42:23 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200628 // remove visibility settings
|
2020-11-14 21:21:54 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200724 // Add KIID to footprints
|
2020-08-08 21:47:57 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200807 // Add zone hatch advanced settings
|
2020-10-21 03:48:06 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200808 // Add properties to footprints
|
2020-08-11 19:37:07 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200809 // Add REMOVE_UNUSED_LAYERS option to vias and THT pads
|
2020-08-18 13:08:32 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200811 // Add groups
|
2020-08-19 18:21:24 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200818 // Remove Status flag bitmap and setup counts
|
2020-08-25 22:25:08 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200819 // Add board-level properties
|
2020-08-26 21:43:38 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200825 // Remove host information
|
2020-08-28 19:32:11 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200828 // Add new fabrication attributes
|
2020-09-09 03:17:08 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200829 // Remove library name from exported footprints
|
2020-09-12 20:09:40 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200909 // Change DIMENSION format
|
2020-09-17 00:54:58 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200913 // Add leader dimension
|
2020-09-22 02:32:40 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200916 // Add center dimension
|
2020-10-03 11:16:29 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200921 // Add orthogonal dimension
|
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20200922 // Add user name to layer definition.
|
2020-11-14 01:16:02 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20201002 // Add groups in footprints (for footprint editor).
|
2020-11-15 12:20:59 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20201114 // Add first-class support for filled shapes.
|
2020-11-16 23:19:09 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20201115 // module -> footprint and change fill syntax.
|
2020-12-20 21:29:43 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20201116 // Write version and generator string in footprint files.
|
2021-01-08 16:32:28 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20201220 // Add free via token
|
2021-01-26 15:27:42 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20210108 // Pad locking moved from footprint to pads
|
2021-02-28 19:04:28 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20210126 // Store pintype alongside pinfunction (in pads).
|
2020-08-14 00:10:40 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20210228 // Move global margins back to board file
|
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20210424 // Correct locked flag syntax (remove parens).
|
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20210606 // Change overbar syntax from `~...~` to `~{...}`.
|
2021-07-22 11:45:33 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20210623 // Add support for reading/writing arcs in polygons
|
2021-08-24 10:17:28 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20210722 // Reading/writing group locked flags
|
2021-09-25 19:37:34 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20210824 // Opacity in 3D colors
|
2021-10-14 23:39:31 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20210925 // Locked flag for fp_text
|
2021-07-13 18:46:33 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20211014 // Arc formatting
|
2023-08-27 19:42:09 +00:00
|
|
|
//----------------- Start of 7.0 development -----------------
|
2021-08-08 13:37:14 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20211226 // Add radial dimension
|
2021-08-12 16:58:30 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20211227 // Add thermal relief spoke angle overrides
|
2021-08-25 23:14:36 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20211228 // Add allow_soldermask_bridges footprint attribute
|
2021-12-04 23:52:00 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20211229 // Stroke formatting
|
2021-12-05 21:56:55 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20211230 // Dimensions in footprints
|
2022-01-20 21:01:50 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20211231 // Private footprint layers
|
2022-01-31 19:11:21 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20211232 // Fonts
|
2022-02-11 12:42:09 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20220131 // Textboxes
|
2022-02-25 23:09:27 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20220211 // End support for V5 zone fill strategy
|
2022-03-08 13:16:39 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20220225 // Remove TEDIT
|
2022-04-02 13:36:20 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20220308 // Knockout text and Locked graphic text property saved
|
2022-04-17 13:02:19 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20220331 // Plot on all layers selection setting
|
2022-04-27 16:13:50 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20220417 // Automatic dimension precisions
|
2022-06-17 17:41:53 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20220427 // Exclude Edge.Cuts & Margin from fp private layers
|
2022-02-08 19:29:54 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20220609 // Add teardrop keywords to identify teardrop zones
|
2022-08-15 17:02:31 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20220621 // Add Image support
|
2022-08-19 17:34:53 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20220815 // Add allow-soldermask-bridges-in-FPs flag
|
2022-09-14 10:34:10 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20220818 // First-class storage for net-ties
|
2022-10-18 12:00:37 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20220914 // Number boxes for custom-shape pads
|
2023-04-10 17:10:42 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20221018 // Via & pad zone-layer-connections
|
2023-08-27 19:42:09 +00:00
|
|
|
//----------------- Start of 8.0 development -----------------
|
2023-05-12 21:03:54 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20230410 // DNP attribute propagated from schematic to attr
|
2023-06-12 14:02:28 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20230517 // Teardrop parameters for pads and vias
|
2023-07-30 19:39:07 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20230620 // PCB Fields
|
2023-08-31 02:33:55 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20230730 // Connectivity for graphic shapes
|
2023-06-07 02:59:17 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20230825 // Textbox explicit border flag
|
2023-09-13 17:27:00 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20230906 // Multiple image type support in files
|
2023-10-07 01:55:45 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20230913 // Custom-shaped-pad spoke templates
|
2023-09-24 16:53:34 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20231007 // Generative objects
|
2023-12-12 20:36:15 +00:00
|
|
|
//#define SEXPR_BOARD_FILE_VERSION 20231014 // V8 file format normalization
|
|
|
|
#define SEXPR_BOARD_FILE_VERSION 20231212 // Reference image locking/UUIDs, footprint boolean format
|
2020-09-22 21:50:59 +00:00
|
|
|
|
|
|
|
#define BOARD_FILE_HOST_VERSION 20200825 ///< Earlier files than this include the host tag
|
2021-10-14 23:39:31 +00:00
|
|
|
#define LEGACY_ARC_FORMATTING 20210925 ///< These were the last to use old arc formatting
|
2022-08-19 17:34:53 +00:00
|
|
|
#define LEGACY_NET_TIES 20220815 ///< These were the last to use the keywords field
|
|
|
|
///< to indicate a net-tie.
|
2023-09-24 16:53:34 +00:00
|
|
|
#define FIRST_NORMALIZED_VERISON 20230924 ///< Earlier files did not have normalized bools
|
2012-11-10 06:39:18 +00:00
|
|
|
|
2020-12-28 00:42:04 +00:00
|
|
|
#define CTL_OMIT_PAD_NETS (1 << 1) ///< Omit pads net names (useless in library)
|
2023-09-27 23:05:30 +00:00
|
|
|
#define CTL_OMIT_UUIDS (1 << 2) ///< Omit component unique ids (useless in library)
|
2020-11-13 21:07:01 +00:00
|
|
|
#define CTL_OMIT_INITIAL_COMMENTS (1 << 3) ///< omit FOOTPRINT initial comments
|
2014-06-02 10:46:29 +00:00
|
|
|
#define CTL_OMIT_PATH (1 << 4) ///< Omit component sheet time stamp (useless in library)
|
2020-12-18 15:40:13 +00:00
|
|
|
#define CTL_OMIT_AT (1 << 5) ///< Omit position and rotation. (always saved
|
Fix typos in pcbnew sub-directory
Found via `codespell -q 3 -S *.po,./thirdparty,./Documentation/changelogs -L aactual,acount,aline,alocation,alog,anormal,anumber,aother,apoints,aparent,aray,ba,busses,dout,einstance,leaded,modul,ontext,ot,overide,serie,te,,tesselate,tesselator,tht`
2022-06-29 20:21:10 +00:00
|
|
|
///< with position 0,0 and rotation = 0 in library).
|
2017-01-29 08:29:49 +00:00
|
|
|
//#define CTL_OMIT_HIDE (1 << 6) // found and defined in eda_text.h
|
2020-12-18 15:40:13 +00:00
|
|
|
#define CTL_OMIT_LIBNAME (1 << 7) ///< Omit lib alias when saving (used for
|
|
|
|
///< board/not library).
|
|
|
|
#define CTL_OMIT_FOOTPRINT_VERSION (1 << 8) ///< Omit the version string from the (footprint)
|
|
|
|
///<sexpr group
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2012-11-14 07:15:59 +00:00
|
|
|
// common combinations of the above:
|
|
|
|
|
|
|
|
/// Format output for the clipboard instead of footprint library or BOARD
|
2020-11-16 23:19:09 +00:00
|
|
|
#define CTL_FOR_CLIPBOARD (CTL_OMIT_INITIAL_COMMENTS) // (CTL_OMIT_NETS)
|
2012-11-14 07:15:59 +00:00
|
|
|
|
|
|
|
/// Format output for a footprint library instead of clipboard or BOARD
|
2020-12-18 15:40:13 +00:00
|
|
|
#define CTL_FOR_LIBRARY \
|
2023-09-27 23:05:30 +00:00
|
|
|
( CTL_OMIT_PAD_NETS | CTL_OMIT_UUIDS | CTL_OMIT_PATH | CTL_OMIT_AT | CTL_OMIT_LIBNAME )
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2021-11-25 12:22:40 +00:00
|
|
|
/// The zero arg constructor when PCB_PLUGIN is used for PLUGIN::Load() and PLUGIN::Save()ing
|
2013-06-24 05:30:22 +00:00
|
|
|
/// a BOARD file underneath IO_MGR.
|
2020-11-16 23:19:09 +00:00
|
|
|
#define CTL_FOR_BOARD (CTL_OMIT_INITIAL_COMMENTS|CTL_OMIT_FOOTPRINT_VERSION)
|
2013-06-24 05:30:22 +00:00
|
|
|
|
2022-11-28 02:27:34 +00:00
|
|
|
/**
|
|
|
|
* Helper class for creating a footprint library cache.
|
|
|
|
*
|
|
|
|
* The new footprint library design is a file path of individual footprint files that contain
|
|
|
|
* a single footprint per file. This class is a helper only for the footprint portion of the
|
|
|
|
* PLUGIN API, and only for the #PCB_PLUGIN plugin. It is private to this implementation file so
|
|
|
|
* it is not placed into a header.
|
|
|
|
*/
|
|
|
|
class FP_CACHE_ITEM
|
|
|
|
{
|
|
|
|
WX_FILENAME m_filename;
|
|
|
|
std::unique_ptr<FOOTPRINT> m_footprint;
|
|
|
|
|
|
|
|
public:
|
|
|
|
FP_CACHE_ITEM( FOOTPRINT* aFootprint, const WX_FILENAME& aFileName );
|
|
|
|
|
|
|
|
const WX_FILENAME& GetFileName() const { return m_filename; }
|
2022-12-07 02:20:19 +00:00
|
|
|
void SetFilePath( const wxString& aFilePath ) { m_filename.SetPath( aFilePath ); }
|
2022-11-28 02:27:34 +00:00
|
|
|
const FOOTPRINT* GetFootprint() const { return m_footprint.get(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef boost::ptr_map<wxString, FP_CACHE_ITEM> FP_CACHE_FOOTPRINT_MAP;
|
|
|
|
|
|
|
|
class FP_CACHE
|
|
|
|
{
|
2023-12-24 01:21:58 +00:00
|
|
|
PCB_IO_KICAD_SEXPR* m_owner; // Plugin object that owns the cache.
|
2022-11-28 02:27:34 +00:00
|
|
|
wxFileName m_lib_path; // The path of the library.
|
|
|
|
wxString m_lib_raw_path; // For quick comparisons.
|
|
|
|
FP_CACHE_FOOTPRINT_MAP m_footprints; // Map of footprint filename to FOOTPRINT*.
|
|
|
|
|
|
|
|
bool m_cache_dirty; // Stored separately because it's expensive to check
|
|
|
|
// m_cache_timestamp against all the files.
|
|
|
|
long long m_cache_timestamp; // A hash of the timestamps for all the footprint
|
|
|
|
// files.
|
|
|
|
|
|
|
|
public:
|
2023-12-24 01:21:58 +00:00
|
|
|
FP_CACHE( PCB_IO_KICAD_SEXPR* aOwner, const wxString& aLibraryPath );
|
2022-11-28 02:27:34 +00:00
|
|
|
|
|
|
|
wxString GetPath() const { return m_lib_raw_path; }
|
|
|
|
|
|
|
|
bool IsWritable() const { return m_lib_path.IsOk() && m_lib_path.IsDirWritable(); }
|
|
|
|
|
|
|
|
bool Exists() const { return m_lib_path.IsOk() && m_lib_path.DirExists(); }
|
|
|
|
|
|
|
|
FP_CACHE_FOOTPRINT_MAP& GetFootprints() { return m_footprints; }
|
|
|
|
|
|
|
|
// Most all functions in this class throw IO_ERROR exceptions. There are no
|
|
|
|
// error codes nor user interface calls from here, nor in any PLUGIN.
|
|
|
|
// Catch these exceptions higher up please.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the footprint cache or a single footprint from it to disk
|
|
|
|
*
|
|
|
|
* @param aFootprint if set, save only this footprint, otherwise, save the full library
|
|
|
|
*/
|
|
|
|
void Save( FOOTPRINT* aFootprint = nullptr );
|
|
|
|
|
|
|
|
void Load();
|
|
|
|
|
|
|
|
void Remove( const wxString& aFootprintName );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate a timestamp representing all source files in the cache (including the
|
|
|
|
* parent directory).
|
|
|
|
* Timestamps should not be considered ordered. They either match or they don't.
|
|
|
|
*/
|
|
|
|
static long long GetTimestamp( const wxString& aLibPath );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if the cache is not up-to-date.
|
|
|
|
*/
|
|
|
|
bool IsModified();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if \a aPath is the same as the current cache path.
|
|
|
|
*
|
|
|
|
* This tests paths by converting \a aPath using the native separators. Internally
|
|
|
|
* #FP_CACHE stores the current path using native separators. This prevents path
|
|
|
|
* miscompares on Windows due to the fact that paths can be stored with / instead of \\
|
|
|
|
* in the footprint library table.
|
|
|
|
*
|
|
|
|
* @param aPath is the library path to test against.
|
|
|
|
* @return true if \a aPath is the same as the cache path.
|
|
|
|
*/
|
|
|
|
bool IsPath( const wxString& aPath ) const;
|
2022-12-07 02:20:19 +00:00
|
|
|
|
|
|
|
void SetPath( const wxString& aPath );
|
2022-11-28 02:27:34 +00:00
|
|
|
};
|
|
|
|
|
2013-09-21 07:30:23 +00:00
|
|
|
|
2012-06-09 17:00:13 +00:00
|
|
|
/**
|
2020-12-18 15:40:13 +00:00
|
|
|
* A #PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
|
2012-06-09 17:00:13 +00:00
|
|
|
*
|
|
|
|
* @note This class is not thread safe, but it is re-entrant multiple times in sequence.
|
|
|
|
*/
|
2023-12-24 01:21:58 +00:00
|
|
|
class PCB_IO_KICAD_SEXPR : public PCB_IO
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
|
|
|
public:
|
2023-08-13 02:26:06 +00:00
|
|
|
PLUGIN_FILE_DESC GetBoardFileDesc() const override
|
2012-06-09 17:00:13 +00:00
|
|
|
{
|
2012-12-14 16:54:54 +00:00
|
|
|
// Would have used wildcards_and_files_ext.cpp's KiCadPcbFileExtension,
|
|
|
|
// but to be pure, a plugin should not assume that it will always be linked
|
2020-09-22 21:50:59 +00:00
|
|
|
// with the core of the Pcbnew code. (Might someday be a DLL/DSO.) Besides,
|
2012-12-14 16:54:54 +00:00
|
|
|
// file extension policy should be controlled by the plugin.
|
2023-08-13 02:26:06 +00:00
|
|
|
return PLUGIN_FILE_DESC( _HKI( "KiCad printed circuit board files" ), { "kicad_pcb" } );
|
|
|
|
}
|
|
|
|
|
|
|
|
PLUGIN_FILE_DESC GetFootprintFileDesc() const override
|
|
|
|
{
|
|
|
|
return PLUGIN_FILE_DESC( _HKI( "KiCad footprint file" ), { "kicad_mod" } );
|
|
|
|
}
|
|
|
|
|
|
|
|
PLUGIN_FILE_DESC GetFootprintLibDesc() const override
|
|
|
|
{
|
|
|
|
return PLUGIN_FILE_DESC( _HKI( "KiCad footprint files" ), {}, { "kicad_mod" }, false );
|
2012-06-09 17:00:13 +00:00
|
|
|
}
|
|
|
|
|
2022-02-11 21:38:31 +00:00
|
|
|
void SetQueryUserCallback( std::function<bool( wxString aTitle, int aIcon, wxString aMessage,
|
|
|
|
wxString aOKButtonTitle )> aCallback ) override
|
|
|
|
{
|
2023-05-21 10:23:56 +00:00
|
|
|
m_queryUserCallback = std::move( aCallback );
|
2022-02-11 21:38:31 +00:00
|
|
|
}
|
|
|
|
|
2023-08-13 02:26:06 +00:00
|
|
|
bool CanReadBoard( const wxString& aFileName ) const override;
|
|
|
|
|
2023-08-13 02:11:58 +00:00
|
|
|
void SaveBoard( const wxString& aFileName, BOARD* aBoard,
|
2023-06-12 18:12:39 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr,
|
|
|
|
PROGRESS_REPORTER* aProgressReporter = nullptr ) override;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2023-08-13 02:11:58 +00:00
|
|
|
BOARD* LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
|
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr, PROJECT* aProject = nullptr,
|
|
|
|
PROGRESS_REPORTER* aProgressReporter = nullptr ) override;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2022-11-06 16:51:52 +00:00
|
|
|
BOARD* DoLoad( LINE_READER& aReader, BOARD* aAppendToMe, const STRING_UTF8_MAP* aProperties,
|
2021-06-23 22:53:08 +00:00
|
|
|
PROGRESS_REPORTER* aProgressReporter, unsigned aLineCount );
|
2020-08-06 18:37:43 +00:00
|
|
|
|
2017-06-11 20:20:44 +00:00
|
|
|
void FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
|
2022-11-06 16:51:52 +00:00
|
|
|
bool aBestEfforts, const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
const FOOTPRINT* GetEnumeratedFootprint( const wxString& aLibraryPath,
|
|
|
|
const wxString& aFootprintName,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2018-02-23 12:21:06 +00:00
|
|
|
|
2019-07-11 21:59:14 +00:00
|
|
|
bool FootprintExists( const wxString& aLibraryPath, const wxString& aFootprintName,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2019-07-11 21:59:14 +00:00
|
|
|
|
2023-08-13 02:26:06 +00:00
|
|
|
FOOTPRINT* ImportFootprint( const wxString& aFootprintPath, wxString& aFootprintNameOut,
|
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
|
2021-03-30 09:38:03 +00:00
|
|
|
bool aKeepUUID = false,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
void FootprintSave( const wxString& aLibraryPath, const FOOTPRINT* aFootprint,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2017-06-11 20:20:44 +00:00
|
|
|
void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2018-03-04 01:13:09 +00:00
|
|
|
long long GetLibraryTimestamp( const wxString& aLibraryPath ) const override;
|
2018-02-05 20:55:00 +00:00
|
|
|
|
2023-12-27 00:25:41 +00:00
|
|
|
void CreateLibrary( const wxString& aLibraryPath,
|
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr) override;
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2023-12-27 00:25:41 +00:00
|
|
|
bool DeleteLibrary( const wxString& aLibraryPath,
|
|
|
|
const STRING_UTF8_MAP* aProperties = nullptr ) override;
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2023-12-27 00:25:41 +00:00
|
|
|
bool IsLibraryWritable( const wxString& aLibraryPath ) override;
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
PCB_IO_KICAD_SEXPR( int aControlFlags = CTL_FOR_BOARD );
|
2012-10-22 20:41:26 +00:00
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
virtual ~PCB_IO_KICAD_SEXPR();
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2012-06-09 17:00:13 +00:00
|
|
|
/**
|
2020-09-22 21:50:59 +00:00
|
|
|
* Output \a aItem to \a aFormatter in s-expression format.
|
2012-06-09 17:00:13 +00:00
|
|
|
*
|
|
|
|
* @param aItem A pointer the an #BOARD_ITEM object to format.
|
|
|
|
* @param aNestLevel The indentation nest level.
|
|
|
|
* @throw IO_ERROR on write error.
|
|
|
|
*/
|
2020-12-20 18:44:13 +00:00
|
|
|
void Format( const BOARD_ITEM* aItem, int aNestLevel = 0 ) const;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
|
|
|
std::string GetStringOutput( bool doClear )
|
|
|
|
{
|
|
|
|
std::string ret = m_sf.GetString();
|
2020-11-15 12:20:59 +00:00
|
|
|
|
2012-06-09 17:00:13 +00:00
|
|
|
if( doClear )
|
|
|
|
m_sf.Clear();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-10-07 15:37:25 +00:00
|
|
|
void SetOutputFormatter( OUTPUTFORMATTER* aFormatter ) { m_out = aFormatter; }
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
BOARD_ITEM* Parse( const wxString& aClipboardSourceInput );
|
2012-10-22 20:41:26 +00:00
|
|
|
|
2012-06-09 17:00:13 +00:00
|
|
|
protected:
|
2018-02-24 17:41:44 +00:00
|
|
|
void validateCache( const wxString& aLibraryPath, bool checkModified = true );
|
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
const FOOTPRINT* getFootprint( const wxString& aLibraryPath, const wxString& aFootprintName,
|
2022-11-06 16:51:52 +00:00
|
|
|
const STRING_UTF8_MAP* aProperties, bool checkModified );
|
2013-11-27 06:04:04 +00:00
|
|
|
|
2022-11-06 16:51:52 +00:00
|
|
|
void init( const STRING_UTF8_MAP* aProperties );
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2017-05-18 17:21:30 +00:00
|
|
|
/// formats the board setup information
|
2020-12-20 18:44:13 +00:00
|
|
|
void formatSetup( const BOARD* aBoard, int aNestLevel = 0 ) const;
|
2017-05-18 16:43:01 +00:00
|
|
|
|
2017-05-18 17:21:30 +00:00
|
|
|
/// formats the General section of the file
|
2020-12-20 18:44:13 +00:00
|
|
|
void formatGeneral( const BOARD* aBoard, int aNestLevel = 0 ) const;
|
2017-05-18 16:43:01 +00:00
|
|
|
|
2017-05-18 17:21:30 +00:00
|
|
|
/// formats the board layer information
|
2020-12-20 18:44:13 +00:00
|
|
|
void formatBoardLayers( const BOARD* aBoard, int aNestLevel = 0 ) const;
|
2017-05-18 16:43:01 +00:00
|
|
|
|
2017-05-18 17:21:30 +00:00
|
|
|
/// formats the Nets and Netclasses
|
2020-12-20 18:44:13 +00:00
|
|
|
void formatNetInformation( const BOARD* aBoard, int aNestLevel = 0 ) const;
|
2017-05-18 16:43:01 +00:00
|
|
|
|
2020-08-19 18:21:24 +00:00
|
|
|
/// formats the Nets and Netclasses
|
2020-12-20 18:44:13 +00:00
|
|
|
void formatProperties( const BOARD* aBoard, int aNestLevel = 0 ) const;
|
2020-08-19 18:21:24 +00:00
|
|
|
|
2017-04-15 16:08:23 +00:00
|
|
|
/// writes everything that comes before the board_items, like settings and layers etc
|
2020-12-20 18:44:13 +00:00
|
|
|
void formatHeader( const BOARD* aBoard, int aNestLevel = 0 ) const;
|
2017-04-15 16:08:23 +00:00
|
|
|
|
2023-05-12 21:03:54 +00:00
|
|
|
void formatTeardropParameters( const TEARDROP_PARAMETERS& tdParams, int aNestLevel = 0 ) const;
|
|
|
|
|
2012-06-09 17:00:13 +00:00
|
|
|
private:
|
2020-12-20 18:44:13 +00:00
|
|
|
void format( const BOARD* aBoard, int aNestLevel = 0 ) const;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2021-06-11 16:59:28 +00:00
|
|
|
void format( const PCB_DIMENSION_BASE* aDimension, int aNestLevel = 0 ) const;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2023-10-23 17:23:24 +00:00
|
|
|
void format( const PCB_REFERENCE_IMAGE* aBitmap, int aNestLevel = 0 ) const;
|
2022-02-08 19:29:54 +00:00
|
|
|
|
2020-12-20 18:44:13 +00:00
|
|
|
void format( const PCB_GROUP* aGroup, int aNestLevel = 0 ) const;
|
2020-08-11 19:37:07 +00:00
|
|
|
|
2020-12-20 18:44:13 +00:00
|
|
|
void format( const PCB_SHAPE* aSegment, int aNestLevel = 0 ) const;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2020-12-20 18:44:13 +00:00
|
|
|
void format( const PCB_TARGET* aTarget, int aNestLevel = 0 ) const;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2020-12-20 18:44:13 +00:00
|
|
|
void format( const FOOTPRINT* aFootprint, int aNestLevel = 0 ) const;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2020-12-20 18:44:13 +00:00
|
|
|
void format( const PAD* aPad, int aNestLevel = 0 ) const;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2020-12-20 18:44:13 +00:00
|
|
|
void format( const PCB_TEXT* aText, int aNestLevel = 0 ) const;
|
2022-01-30 10:52:52 +00:00
|
|
|
void format( const PCB_TEXTBOX* aTextBox, int aNestLevel = 0 ) const;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2023-10-07 01:55:45 +00:00
|
|
|
void format( const PCB_GENERATOR* aGenerator, int aNestLevel = 0 ) const;
|
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
void format( const PCB_TRACK* aTrack, int aNestLevel = 0 ) const;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2020-12-20 18:44:13 +00:00
|
|
|
void format( const ZONE* aZone, int aNestLevel = 0 ) const;
|
2012-06-09 17:00:13 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
void formatPolyPts( const SHAPE_LINE_CHAIN& outline, int aNestLevel, bool aCompact,
|
|
|
|
const FOOTPRINT* aParentFP = nullptr ) const;
|
2022-01-04 23:00:00 +00:00
|
|
|
|
|
|
|
void formatRenderCache( const EDA_TEXT* aText, int aNestLevel ) const;
|
|
|
|
|
2022-03-08 13:16:39 +00:00
|
|
|
void formatLayer( PCB_LAYER_ID aLayer, bool aIsKnockout = false ) const;
|
2012-10-07 15:37:25 +00:00
|
|
|
|
2017-06-08 21:47:21 +00:00
|
|
|
void formatLayers( LSET aLayerMask, int aNestLevel = 0 ) const;
|
2020-12-18 15:40:13 +00:00
|
|
|
|
|
|
|
friend class FP_CACHE;
|
|
|
|
|
|
|
|
protected:
|
2023-03-30 11:49:23 +00:00
|
|
|
wxString m_error; ///< for throwing exceptions
|
2020-12-18 15:40:13 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
FP_CACHE* m_cache; ///< Footprint library cache
|
2020-12-18 15:40:13 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
LINE_READER* m_reader; ///< no ownership
|
|
|
|
wxString m_filename; ///< for saves only, name is in m_reader for loads
|
2020-12-18 15:40:13 +00:00
|
|
|
|
2023-03-30 11:49:23 +00:00
|
|
|
STRING_FORMATTER m_sf;
|
|
|
|
OUTPUTFORMATTER* m_out; ///< output any Format()s to this, no ownership
|
|
|
|
int m_ctl;
|
|
|
|
NETINFO_MAPPING* m_mapping; ///< mapping for net codes, so only not empty net codes
|
|
|
|
///< are stored with consecutive integers as net codes
|
2022-02-11 21:38:31 +00:00
|
|
|
|
2023-05-20 04:00:09 +00:00
|
|
|
std::function<bool( wxString aTitle, int aIcon, wxString aMsg, wxString aAction )> m_queryUserCallback;
|
2012-06-09 17:00:13 +00:00
|
|
|
};
|
|
|
|
|
2023-12-24 01:21:58 +00:00
|
|
|
#endif // PCB_IO_KICAD_SEXPR_H_
|