2012-04-07 18:05:56 +00:00
|
|
|
#ifndef LEGACY_PLUGIN_H_
|
|
|
|
#define LEGACY_PLUGIN_H_
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-04-17 14:18:14 +00:00
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
|
|
|
* Copyright (C) 2012 KiCad Developers, see change_log.txt for contributors.
|
2012-04-07 18:05:56 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <io_mgr.h>
|
2014-05-20 09:29:37 +00:00
|
|
|
#include <boost/shared_ptr.hpp>
|
2012-04-07 18:05:56 +00:00
|
|
|
#include <string>
|
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
|
|
|
|
#define FOOTPRINT_LIBRARY_HEADER "PCBNEW-LibModule-V1"
|
|
|
|
#define FOOTPRINT_LIBRARY_HEADER_CNT 18
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
class PCB_TARGET;
|
|
|
|
class MODULE;
|
|
|
|
class DRAWSEGMENT;
|
|
|
|
class NETINFO;
|
|
|
|
class TEXTE_PCB;
|
|
|
|
class TRACK;
|
|
|
|
class NETCLASS;
|
2012-04-17 02:58:03 +00:00
|
|
|
class NETCLASSES;
|
2012-04-07 18:05:56 +00:00
|
|
|
class ZONE_CONTAINER;
|
|
|
|
class DIMENSION;
|
|
|
|
class NETINFO_ITEM;
|
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;
|
2012-04-07 18:05:56 +00:00
|
|
|
class TEXTE_MODULE;
|
|
|
|
class EDGE_MODULE;
|
|
|
|
class TRACK;
|
|
|
|
class SEGZONE;
|
|
|
|
class D_PAD;
|
2013-09-22 04:38:22 +00:00
|
|
|
struct LP_CACHE;
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class LEGACY_PLUGIN
|
|
|
|
* is a PLUGIN derivation which could possibly be put into a DLL/DSO.
|
2012-04-17 06:13:22 +00:00
|
|
|
* As with any PLUGIN, there is no UI, i.e. windowing calls allowed.
|
2012-04-07 18:05:56 +00:00
|
|
|
*/
|
|
|
|
class LEGACY_PLUGIN : public PLUGIN
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
//-----<PLUGIN IMPLEMENTATION>----------------------------------------------
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-11-27 06:04:04 +00:00
|
|
|
const wxString PluginName() const
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2013-11-27 06:04:04 +00:00
|
|
|
return wxT( "KiCad-Legacy" );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
2013-11-27 06:04:04 +00:00
|
|
|
const wxString GetFileExtension() const
|
2012-04-07 18:05:56 +00:00
|
|
|
{
|
2013-11-27 06:04:04 +00:00
|
|
|
return wxT( "brd" );
|
2012-04-07 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPERTIES* aProperties = NULL );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
void Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties = NULL );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
wxArrayString FootprintEnumerate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL);
|
2012-04-16 03:18:41 +00:00
|
|
|
|
|
|
|
MODULE* FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
|
2013-09-25 19:17:06 +00:00
|
|
|
const PROPERTIES* aProperties = NULL );
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2012-04-17 01:35:43 +00:00
|
|
|
void FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint,
|
2013-09-25 19:17:06 +00:00
|
|
|
const PROPERTIES* aProperties = NULL );
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
void FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties = NULL );
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
void FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
|
2012-04-17 01:35:43 +00:00
|
|
|
|
2013-09-25 19:17:06 +00:00
|
|
|
bool FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties = NULL );
|
2012-04-17 01:35:43 +00:00
|
|
|
|
|
|
|
bool IsFootprintLibWritable( const wxString& aLibraryPath );
|
2012-04-16 03:18:41 +00:00
|
|
|
|
|
|
|
//-----</PLUGIN IMPLEMENTATION>---------------------------------------------
|
|
|
|
|
2012-05-20 13:14:46 +00:00
|
|
|
typedef int BIU;
|
|
|
|
|
2012-04-17 06:13:22 +00:00
|
|
|
LEGACY_PLUGIN();
|
2012-04-16 03:18:41 +00:00
|
|
|
~LEGACY_PLUGIN();
|
|
|
|
|
|
|
|
void SetReader( LINE_READER* aReader ) { m_reader = aReader; }
|
|
|
|
void SetFilePtr( FILE* aFile ) { m_fp = aFile; }
|
|
|
|
|
2013-06-13 16:09:35 +00:00
|
|
|
void LoadMODULE( MODULE* aModule );
|
2012-04-17 01:35:43 +00:00
|
|
|
void SaveMODULE( const MODULE* aModule ) const;
|
|
|
|
void SaveModule3D( const MODULE* aModule ) const;
|
2012-04-17 02:58:03 +00:00
|
|
|
void SaveBOARD( const BOARD* aBoard ) const;
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
wxString m_error; ///< for throwing exceptions
|
|
|
|
BOARD* m_board; ///< which BOARD, no ownership here
|
2013-09-25 19:17:06 +00:00
|
|
|
const PROPERTIES* m_props; ///< passed via Save() or Load(), no ownership, may be NULL.
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
LINE_READER* m_reader; ///< no ownership here.
|
|
|
|
FILE* m_fp; ///< no ownership here.
|
|
|
|
wxString m_filename; ///< for saves only, name is in m_reader for loads
|
|
|
|
|
|
|
|
wxString m_field; ///< reused to stuff MODULE fields.
|
|
|
|
int m_loading_format_version; ///< which BOARD_FORMAT_VERSION am I Load()ing?
|
2013-09-22 04:38:22 +00:00
|
|
|
LP_CACHE* m_cache;
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2014-06-02 09:41:54 +00:00
|
|
|
NETINFO_MAPPING* m_mapping; ///< mapping for net codes, so only not empty nets
|
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
|
|
|
///< are stored with consecutive integers as net codes
|
2014-06-02 09:41:54 +00:00
|
|
|
std::vector<int> m_netCodes; ///< net codes mapping for boards being loaded
|
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
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
/// initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed.
|
2013-09-25 19:17:06 +00:00
|
|
|
void init( const PROPERTIES* aProperties );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2012-06-24 18:41:37 +00:00
|
|
|
double biuToDisk; ///< convert from BIUs to disk engineering units
|
2012-06-23 23:21:03 +00:00
|
|
|
///< with this scale factor
|
|
|
|
|
2012-06-24 18:41:37 +00:00
|
|
|
double diskToBiu; ///< convert from disk engineering units to BIUs
|
2012-06-23 23:21:03 +00:00
|
|
|
///< with this scale factor
|
2012-04-07 18:05:56 +00:00
|
|
|
|
2014-06-03 07:32:57 +00:00
|
|
|
///> Converts net code using the mapping table if available,
|
|
|
|
///> otherwise returns unchanged net code
|
|
|
|
inline int getNetCode( int aNetCode )
|
|
|
|
{
|
|
|
|
if( aNetCode < (int) m_netCodes.size() )
|
|
|
|
return m_netCodes[aNetCode];
|
|
|
|
|
|
|
|
return aNetCode;
|
|
|
|
}
|
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
/**
|
|
|
|
* Function biuParse
|
|
|
|
* parses an ASCII decimal floating point value and scales it into a BIU
|
|
|
|
* according to the current value of diskToBui. This fuction is the complement of
|
|
|
|
* fmtBIU(). One has to know what the other is doing.
|
|
|
|
*
|
|
|
|
* @param aValue is the ASCII value in C locale form with possible leading whitespace
|
|
|
|
*
|
|
|
|
* @param nptrptr may be NULL, but if not, then it tells where to put a
|
|
|
|
* pointer to the next unconsumed input text. See "man strtod" for more information.
|
|
|
|
*
|
|
|
|
* @return BIU - the converted Board Internal Unit.
|
|
|
|
*/
|
|
|
|
BIU biuParse( const char* aValue, const char** nptrptr = NULL );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function degParse
|
|
|
|
* parses an ASCII decimal floating point value which is certainly an angle. This
|
|
|
|
* is a dedicated function for encapsulating support for the migration from
|
|
|
|
* tenths of degrees to degrees in floating point. This function is the complement of
|
|
|
|
* fmtDEG(). One has to know what the other is doing.
|
|
|
|
*
|
|
|
|
* @param aValue is the ASCII value in C locale form with possible leading whitespace
|
|
|
|
*
|
|
|
|
* @param nptrptr may be NULL, but if not, then it tells where to put a
|
|
|
|
* pointer to the next unconsumed input text. See "man strtod" for more information.
|
|
|
|
*
|
|
|
|
* @return double - the string converted to a primitive double type
|
|
|
|
*/
|
|
|
|
double degParse( const char* aValue, const char** nptrptr = NULL );
|
|
|
|
|
|
|
|
//-----<load/parse functions>-----------------------------------------------
|
|
|
|
|
|
|
|
void checkVersion();
|
|
|
|
|
|
|
|
void loadAllSections( bool doAppend );
|
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
|
2012-04-07 18:05:56 +00:00
|
|
|
void loadGENERAL();
|
|
|
|
void loadSETUP();
|
|
|
|
void loadSHEET();
|
|
|
|
|
|
|
|
void load3D( MODULE* aModule );
|
|
|
|
void loadPAD( MODULE* aModule );
|
|
|
|
void loadMODULE_TEXT( TEXTE_MODULE* aText );
|
|
|
|
void loadMODULE_EDGE( MODULE* aModule );
|
|
|
|
|
|
|
|
void loadPCB_LINE();
|
|
|
|
void loadNETINFO_ITEM();
|
|
|
|
void loadPCB_TEXT();
|
|
|
|
void loadNETCLASS();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function loadTrackList
|
|
|
|
* reads a list of segments (Tracks and Vias, or Segzones)
|
|
|
|
*
|
|
|
|
* @param aStructType is either PCB_TRACE_T to indicate tracks and vias, or
|
|
|
|
* PCB_ZONE_T to indicate oldschool zone segments (before polygons came to be).
|
|
|
|
*/
|
2012-06-10 00:39:40 +00:00
|
|
|
void loadTrackList( int aStructType );
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
void loadZONE_CONTAINER(); // "$CZONE_OUTLINE"
|
|
|
|
void loadDIMENSION(); // "$COTATION"
|
|
|
|
void loadPCB_TARGET(); // "$PCB_TARGET"
|
|
|
|
|
|
|
|
//-----</ load/parse functions>---------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
//-----<save functions>-----------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function writeError
|
|
|
|
* returns an error message wxString containing the filename being
|
|
|
|
* currently written.
|
|
|
|
*/
|
|
|
|
wxString writeError() const;
|
|
|
|
|
|
|
|
/// encapsulate the BIU formatting tricks in one place.
|
|
|
|
int biuSprintf( char* buf, BIU aValue ) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function fmtBIU
|
|
|
|
* converts a BIU to engineering units by scaling and formatting to ASCII.
|
|
|
|
* This function is the complement of biuParse(). One has to know what the
|
|
|
|
* other is doing.
|
|
|
|
*/
|
|
|
|
std::string fmtBIU( BIU aValue ) const;
|
|
|
|
|
|
|
|
std::string fmtBIUPair( BIU first, BIU second ) const;
|
|
|
|
|
|
|
|
std::string fmtBIUPoint( const wxPoint& aPoint ) const
|
|
|
|
{
|
|
|
|
return fmtBIUPair( aPoint.x, aPoint.y );
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string fmtBIUSize( const wxSize& aSize ) const
|
|
|
|
{
|
|
|
|
return fmtBIUPair( aSize.x, aSize.y );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function fmtDEG
|
|
|
|
* formats an angle in a way particular to a board file format. This function
|
|
|
|
* is the opposite or complement of degParse(). One has to know what the
|
|
|
|
* other is doing.
|
|
|
|
*/
|
|
|
|
std::string fmtDEG( double aAngle ) const;
|
|
|
|
|
2012-04-17 02:58:03 +00:00
|
|
|
void saveGENERAL( const BOARD* aBoard ) const;
|
|
|
|
void saveSHEET( const BOARD* aBoard ) const;
|
|
|
|
void saveSETUP( const BOARD* aBoard ) const;
|
|
|
|
void saveBOARD_ITEMS( const BOARD* aBoard ) const;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
void saveMODULE_TEXT( const TEXTE_MODULE* aText ) const;
|
|
|
|
void saveMODULE_EDGE( const EDGE_MODULE* aGraphic ) const;
|
|
|
|
void savePAD( const D_PAD* aPad ) const;
|
|
|
|
|
|
|
|
void saveNETINFO_ITEM( const NETINFO_ITEM* aNet ) const;
|
2012-04-17 02:58:03 +00:00
|
|
|
void saveNETCLASSES( const NETCLASSES* aNetClasses ) const;
|
2014-05-20 09:29:37 +00:00
|
|
|
void saveNETCLASS( const boost::shared_ptr<NETCLASS> aNetclass ) const;
|
2012-04-07 18:05:56 +00:00
|
|
|
|
|
|
|
void savePCB_TEXT( const TEXTE_PCB* aText ) const;
|
|
|
|
void savePCB_TARGET( const PCB_TARGET* aTarget ) const;
|
|
|
|
void savePCB_LINE( const DRAWSEGMENT* aStroke ) const;
|
2014-05-13 09:22:51 +00:00
|
|
|
void saveDIMENSION( const DIMENSION* aDimension ) const;
|
2012-04-07 18:05:56 +00:00
|
|
|
void saveTRACK( const TRACK* aTrack ) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function saveZONE_CONTAINER
|
|
|
|
* saves the new polygon zones.
|
|
|
|
*/
|
|
|
|
void saveZONE_CONTAINER( const ZONE_CONTAINER* aZone ) const;
|
|
|
|
|
|
|
|
//-----</save functions>----------------------------------------------------
|
|
|
|
|
2012-04-16 03:18:41 +00:00
|
|
|
/// we only cache one footprint library for now, this determines which one.
|
|
|
|
void cacheLib( const wxString& aLibraryPath );
|
2012-04-17 14:18:14 +00:00
|
|
|
|
2013-09-22 04:38:22 +00:00
|
|
|
friend struct LP_CACHE;
|
2012-04-07 18:05:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LEGACY_PLUGIN_H_
|