Browse Source
initial work on PCBNew PLUGIN support, in preparation for nanometer board load and save
pull/1/head
initial work on PCBNew PLUGIN support, in preparation for nanometer board load and save
pull/1/head
16 changed files with 938 additions and 25 deletions
-
8CHANGELOG.txt
-
14Documentation/biu-plan.txt
-
6copyright.h
-
2cvpcb/class_DisplayFootprintsFrame.cpp
-
2gerbview/export_to_pcbnew.cpp
-
2gerbview/gerbview_frame.cpp
-
2pcbnew/CMakeLists.txt
-
8pcbnew/class_board.cpp
-
8pcbnew/class_board.h
-
2pcbnew/initpcb.cpp
-
125pcbnew/io_mgr.cpp
-
267pcbnew/io_mgr.h
-
408pcbnew/kicad_plugin.cpp
-
105pcbnew/kicad_plugin.h
-
2pcbnew/moduleframe.cpp
-
2pcbnew/pcbframe.cpp
@ -0,0 +1,125 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2011 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> |
|||
* Copyright (C) 2011 KiCad Developers, see change_log.txt for contributors. |
|||
* |
|||
* 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>
|
|||
#include <kicad_plugin.h>
|
|||
|
|||
|
|||
// some day plugins could be in separate DLL/DSOs, until then, use the simplest method:
|
|||
|
|||
// This implementation is one of two which could be done.
|
|||
// the other one would cater to DLL/DSO's. But since it would be nearly
|
|||
// impossible to link a KICAD type DLL/DSO right now without pulling in all
|
|||
// ::Draw() functions, I forgo that option.
|
|||
|
|||
// Some day it may be possible to have some built in AND some DLL/DSO, but
|
|||
// only when we can keep things clean enough to link a DLL/DSO without
|
|||
// pulling in the world.
|
|||
|
|||
static KICAD_PLUGIN kicad_plugin; |
|||
//static EAGLE_PLUGIN eagle_plugin;
|
|||
|
|||
PLUGIN* IO_MGR::PluginFind( PCB_FILE_T aFileType ) |
|||
{ |
|||
switch( aFileType ) |
|||
{ |
|||
case KICAD: return &kicad_plugin; |
|||
|
|||
// case EAGLE: return &eagle_plugin;
|
|||
} |
|||
|
|||
return NULL; |
|||
} |
|||
|
|||
|
|||
void IO_MGR::PluginRelease( PLUGIN* aPlugin ) |
|||
{ |
|||
// This function is a place holder for a future point in time where
|
|||
// the plugin is a DLL/DSO. It could do reference counting, and then
|
|||
// unload the DLL/DSO when count goes to zero.
|
|||
} |
|||
|
|||
|
|||
const wxString& IO_MGR::ShowType( PCB_FILE_T aFileType ) |
|||
{ |
|||
static const wxString kicad = wxT( "KiCad" ); |
|||
static const wxString unknown = _( "Unknown" ); |
|||
|
|||
switch( aFileType ) |
|||
{ |
|||
case KICAD: |
|||
return kicad; |
|||
default: |
|||
return unknown; // could Printf() the numeric value of aFileType
|
|||
} |
|||
} |
|||
|
|||
|
|||
BOARD* IO_MGR::Load( PCB_FILE_T aFileType, const wxString& aFileName, |
|||
BOARD* aAppendToMe, PROPERTIES* aProperties ) |
|||
{ |
|||
// release the PLUGIN even if an exception is thrown.
|
|||
PLUGIN::RELEASER pi = PluginFind( aFileType ); |
|||
|
|||
if( (PLUGIN*) pi ) // test pi->plugin
|
|||
{ |
|||
return pi->Load( aFileName, aAppendToMe, aProperties ); // virtual
|
|||
} |
|||
|
|||
wxString msg; |
|||
|
|||
msg.Printf( _( "Plugin type '%s' is not found.\n" ), ShowType( aFileType ).GetData() ); |
|||
|
|||
THROW_IO_ERROR( msg ); |
|||
} |
|||
|
|||
|
|||
BOARD* PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, PROPERTIES* aProperties ) |
|||
{ |
|||
// not pure virtual so that plugins only have to implement subset of the PLUGIN interface,
|
|||
// e.g. Load() or Save() but not both.
|
|||
|
|||
wxString msg; |
|||
|
|||
msg.Printf( _( "Plugin %s does not implement the BOARD Load() function.\n" ), |
|||
Name().GetData() ); |
|||
|
|||
THROW_IO_ERROR( msg ); |
|||
} |
|||
|
|||
|
|||
void PLUGIN::Save( const wxString* aFileName, BOARD* aBoard, PROPERTIES* aProperties ) |
|||
{ |
|||
// not pure virtual so that plugins only have to implement subset of the PLUGIN interface,
|
|||
// e.g. Load() or Save() but not both.
|
|||
|
|||
wxString msg; |
|||
|
|||
msg.Printf( _( "Plugin %s does not implement the BOARD Save() function.\n" ), |
|||
Name().GetData() ); |
|||
|
|||
THROW_IO_ERROR( msg ); |
|||
} |
|||
|
|||
@ -0,0 +1,267 @@ |
|||
#ifndef IO_MGR_H_ |
|||
#define IO_MGR_H_ |
|||
|
|||
/* |
|||
* This program source code file is part of KICAD, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2011 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> |
|||
* Copyright (C) 2011 Kicad Developers, see change_log.txt for contributors. |
|||
* |
|||
* 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 <wx/string.h> |
|||
#include <wx/hashmap.h> |
|||
#include <richio.h> |
|||
|
|||
|
|||
// http://docs.wxwidgets.org/trunk/classwx_hash_map.html |
|||
WX_DECLARE_STRING_HASH_MAP( wxString, PROPERTIES ); |
|||
|
|||
class BOARD; |
|||
class SCHEMATIC; |
|||
class PLUGIN; |
|||
|
|||
|
|||
/** |
|||
* Class IO_MGR |
|||
* is factory which returns an instance of a PLUGIN DSO/DLL. |
|||
*/ |
|||
class IO_MGR |
|||
{ |
|||
public: |
|||
|
|||
/** |
|||
* Enum PCB_FILE_T |
|||
* is a set of file types that the IO_MGR knows about, and for which there |
|||
* has been a plugin written. |
|||
*/ |
|||
enum PCB_FILE_T |
|||
{ |
|||
KICAD, |
|||
// EAGLE, |
|||
// ALTIUM, |
|||
// etc. |
|||
}; |
|||
|
|||
/** |
|||
* Function PluginFind |
|||
* returns a PLUGIN which the caller can use to import, export, save, or load |
|||
* design documents. The returned PLUGIN, may be reference counted, so please |
|||
* call PluginRelease() when you are done using the returned PLUGIN. |
|||
* |
|||
* @param aFileType is from PCB_FILE_T and tells which plugin to find. |
|||
* |
|||
* @return PLUGIN* - the plugin corresponding to aFileType or NULL if not found. |
|||
* Caller owns the returned object, and must call PluginRelease when done using it. |
|||
*/ |
|||
static PLUGIN* PluginFind( PCB_FILE_T aFileType ); |
|||
|
|||
/** |
|||
* Function PluginRelease |
|||
* releases a PLUGIN back to the system, and may cause it to be unloaded from memory. |
|||
* |
|||
* @param aPlugin is the one to be released, and which is no longer usable. |
|||
*/ |
|||
static void PluginRelease( PLUGIN* aPlugin ); |
|||
|
|||
/** |
|||
* Function ShowType |
|||
* returns a brief name for a plugin, given aFileType enum. |
|||
*/ |
|||
static const wxString& ShowType( PCB_FILE_T aFileType ); |
|||
|
|||
/** |
|||
* Function Load |
|||
* finds the requested plugin and loads a BOARD, or throws an exception trying. |
|||
* |
|||
* @param aFileType is the type of file to load. |
|||
* |
|||
* @param aFileName is the name of the file to load. |
|||
* |
|||
* @param aAppendToMe is an existing BOARD to append to, use NULL if fresh |
|||
* board load wanted. |
|||
* |
|||
* @param aProperties is an associative array that allows the caller to |
|||
* pass additional tuning parameters to the plugin. |
|||
* |
|||
* @return BOARD* - caller owns it, never NULL because exception thrown if error. |
|||
* |
|||
* @throw IO_ERROR if the pluging cannot be found, file cannot be found, |
|||
* or file cannot be loaded. |
|||
*/ |
|||
static BOARD* Load( PCB_FILE_T aFileType, const wxString& aFileName, |
|||
BOARD* aAppendToMe = NULL, PROPERTIES* aProperties = NULL ); |
|||
|
|||
// etc. |
|||
}; |
|||
|
|||
|
|||
/** |
|||
* Class PLUGIN |
|||
* is a base class that BOARD loading and saving plugins should derive from. |
|||
* Implementations can provide either Load() or Save() functions, or both. |
|||
* PLUGINs throw exceptions, so it is best that you wrap your calls to these |
|||
* functions in a try catch block, and also do the switching to stardard C locale |
|||
* and back, outside the region in which an exception can be thrown. This means |
|||
* the PLUGINs do not deal with the locale, the caller does. |
|||
* |
|||
* <pre> |
|||
* |
|||
* // Switch the locale to standard C (needed to read floating point numbers |
|||
* // like 1.3) |
|||
* |
|||
* SetLocaleTo_C_standard(); |
|||
* try |
|||
* { |
|||
* pi->Load(...); |
|||
* } |
|||
* catch( IO_ERROR ioe ) |
|||
* { |
|||
* // grab text from ioe, show in error window. |
|||
* } |
|||
* SetLocaleTo_Default(); // revert to the current locale |
|||
* |
|||
* </pre> |
|||
*/ |
|||
class PLUGIN |
|||
{ |
|||
public: |
|||
|
|||
virtual ~PLUGIN() {} |
|||
|
|||
/** |
|||
* Class RELEASER |
|||
* releases a PLUGIN in the context of a potential thrown exception, through |
|||
* its destructor. |
|||
*/ |
|||
class RELEASER |
|||
{ |
|||
PLUGIN* plugin; |
|||
|
|||
public: |
|||
RELEASER( PLUGIN* aPlugin = NULL ) : |
|||
plugin( aPlugin ) |
|||
{ |
|||
} |
|||
|
|||
~RELEASER() |
|||
{ |
|||
if( plugin ) |
|||
IO_MGR::PluginRelease( plugin ); |
|||
} |
|||
|
|||
operator PLUGIN* () |
|||
{ |
|||
return plugin; |
|||
} |
|||
|
|||
PLUGIN* operator -> () |
|||
{ |
|||
return plugin; |
|||
} |
|||
}; |
|||
|
|||
virtual const wxString& Name() = 0; |
|||
|
|||
//-----<BOARD STUFF>---------------------------------------------------- |
|||
|
|||
/** |
|||
* Function Load |
|||
* loads a board file from some input file format that this implementation |
|||
* knows about. |
|||
* |
|||
* @param aFileName is the name of the file to load and may be foreign in |
|||
* nature or native in nature. |
|||
* |
|||
* @param aAppendToMe is an existing BOARD to append to but is often NULL |
|||
* meaning do not append. |
|||
* |
|||
* @param aProperties is an associative array that can be used to tell the |
|||
* loader how to load the file, because it can take any number of |
|||
* additional named arguments that the plugin is known to support. |
|||
* |
|||
* @return BOARD* - the successfully loaded board, and caller owns it. |
|||
* |
|||
* @throw IO_ERROR if there is a problem loading, and its contents should |
|||
* say what went wrong. |
|||
*/ |
|||
virtual BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe, |
|||
PROPERTIES* aProperties = NULL ); |
|||
|
|||
/** |
|||
* Function Save |
|||
* will write a full aBoard to a storage file in a format that only this |
|||
* implementation knows about. Or it can be used to write a portion of |
|||
* aBoard to a special kind of export file. |
|||
* |
|||
* @param aFileName is the name of a file to save to on disk. |
|||
* @param aBoard is the BOARD document (data tree) to save or export to disk. |
|||
* |
|||
* @param aProperties is an associative array that can be used to tell the |
|||
* saver how to save the file, because it can take any number of |
|||
* additional named arguments that the plugin is known to support. |
|||
* |
|||
* @throw IO_ERROR if there is a problem loading. |
|||
*/ |
|||
virtual void Save( const wxString* aFileName, BOARD* aBoard, |
|||
PROPERTIES* aProperties = NULL ); |
|||
|
|||
//-----</BOARD STUFF>--------------------------------------------------- |
|||
|
|||
#if 0 |
|||
///--------- Should split into two PLUGIN base types here, rather than being combined like this |
|||
|
|||
//-----<SCHEMATIC STUFF>------------------------------------------------ |
|||
|
|||
/** |
|||
* Function Load |
|||
* loads a file from some special input file format that |
|||
* only this implementation knows about. |
|||
* @param aFileName is the name of the file to load and may be foreign in nature or native in nature. |
|||
* @param aAppendToMe is an existing SCHEMATIC to append to but may be NULL. |
|||
*/ |
|||
virtual SCHEMATIC* Load( const wxString& aFileName, SCHEMATIC* aAppendToMe, |
|||
PROPERTIES* aProperties = NULL ) |
|||
{ |
|||
// not pure virtual so that plugins only have to implement |
|||
// Load() or Save() but not both. |
|||
} |
|||
|
|||
/** |
|||
* Function Save |
|||
* will write aBoard to a storage file in a format that only this |
|||
* implementation knows about. |
|||
* |
|||
* @param aFileName is the name of a file to save to on disk. |
|||
* |
|||
* @param aBoard is the SCHEMATIC document (ram data tree) to save or export to disk. |
|||
*/ |
|||
virtual void Save( const wxString* aFileName, SCHEMATIC* aSchematic, |
|||
PROPERTIES* aProperties = NULL ) |
|||
{ |
|||
// not pure virtual so that plugins only have to implement |
|||
// Load() or Save() but not both. |
|||
} |
|||
|
|||
//-----</SCHEMATIC STUFF>---------------------------------------------- |
|||
#endif |
|||
}; |
|||
|
|||
#endif // IO_MGR_H_ |
|||
|
|||
@ -0,0 +1,408 @@ |
|||
|
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 1992-2011 KiCad Developers, see change_log.txt for contributors. |
|||
* |
|||
* 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 |
|||
*/ |
|||
|
|||
|
|||
/* This implements loading and saving a BOARD, behind the PLUGIN interface.
|
|||
*/ |
|||
|
|||
#include <math.h>
|
|||
#include <stdio.h>
|
|||
#include <string.h>
|
|||
|
|||
#include <kicad_plugin.h> // I implement this
|
|||
|
|||
#include <auto_ptr.h>
|
|||
#include <kicad_string.h>
|
|||
|
|||
|
|||
//#include <fctsys.h>
|
|||
//#include <confirm.h>
|
|||
//#include <build_version.h>
|
|||
//#include <wxPcbStruct.h">
|
|||
//#include <macros.h>
|
|||
//#include <pcbcommon.h>
|
|||
|
|||
#include <zones.h>
|
|||
|
|||
#ifdef CVPCB
|
|||
//#include <cvpcb.h>
|
|||
#endif
|
|||
|
|||
#include <class_board.h>
|
|||
#include <class_module.h>
|
|||
#include <class_track.h>
|
|||
#include <class_pcb_text.h>
|
|||
#include <class_zone.h>
|
|||
#include <class_dimension.h>
|
|||
#include <class_drawsegment.h>
|
|||
#include <class_mire.h>
|
|||
#include <3d_struct.h>
|
|||
|
|||
|
|||
/*
|
|||
#include <pcbnew.h>
|
|||
#include <pcbnew_id.h>
|
|||
#include <autorout.h>
|
|||
#include <pcb_plot_params.h>
|
|||
*/ |
|||
|
|||
|
|||
/* ASCII format of structures:
|
|||
* |
|||
* Structure PAD: |
|||
* |
|||
* $PAD |
|||
* Sh "name" form DIMVA dimH dV dH East: general form dV, dH = delta size |
|||
* Dr. diam dV dH: drill: diameter drilling offsets |
|||
* At Type S / N layers: standard, cms, conn, hole, meca., |
|||
* Stack / Normal, 32-bit hexadecimal: occupation layers |
|||
* Nm net_code netname |
|||
* Po posrefX posrefy: reFX position, Y (0 = east position / anchor) |
|||
* $EndPAD |
|||
* |
|||
* Module Structure |
|||
* |
|||
* $MODULE namelib |
|||
* Po ax ay east layer masquelayer m_TimeCode |
|||
* ax ay ord = anchor (position module) |
|||
* east = east to 0.1 degree |
|||
* layer = layer number |
|||
* masquelayer = silkscreen layer for |
|||
* m_TimeCode internal use (groups) |
|||
* Li <namelib> |
|||
* |
|||
* Cd <text> description of the component (Component Doc) |
|||
* Kw <text> List of key words |
|||
* |
|||
* Sc schematic timestamp, reference schematic |
|||
* |
|||
* Op rot90 rot180 placement Options Auto (court rot 90, 180) |
|||
* rot90 is about 2x4-bit: |
|||
* lsb = cost rot 90, rot court msb = -90; |
|||
* |
|||
* Tn px py DIMVA dimh East thickness mirror visible "text" |
|||
* n = type (0 = ref, val = 1,> 1 = qcq |
|||
* Texts POS x, y / anchor and orient module 0 |
|||
* DIMVA dimh East |
|||
* mirror thickness (Normal / Mirror) |
|||
* Visible V / I |
|||
* DS ox oy fx fy w |
|||
* Edge: coord segment ox, oy has fx, fy, on |
|||
* was the anchor and orient 0 |
|||
* thickness w |
|||
* DC ox oy fx fy w descr circle (center, 1 point, thickness) |
|||
* $PAD |
|||
* $EndPAD section pads if available |
|||
* $Endmodule |
|||
*/ |
|||
|
|||
|
|||
#define MM_PER_BIU 1e-6
|
|||
#define UM_PER_BIU 1e-3
|
|||
|
|||
|
|||
using namespace std; |
|||
|
|||
BOARD* KICAD_PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, PROPERTIES* aProperties ) |
|||
{ |
|||
wxString msg; |
|||
BOARD* board = aAppendToMe ? aAppendToMe : new BOARD( NULL ); |
|||
|
|||
// delete on exception, iff I own it, according to aAppendToMe
|
|||
auto_ptr<BOARD> deleter( aAppendToMe ? NULL : board ); |
|||
|
|||
FILE* fp = wxFopen( aFileName, wxT( "rt" ) ); |
|||
if( !fp ) |
|||
{ |
|||
msg.Printf( _( "Unable to open file '%s'" ), aFileName.GetData() ); |
|||
THROW_IO_ERROR( msg ); |
|||
} |
|||
|
|||
FILE_LINE_READER reader( fp, aFileName ); |
|||
|
|||
aReader = &reader; |
|||
|
|||
init( board, aProperties ); |
|||
|
|||
// Put a dollar sign in front, and test for a specific length of characters
|
|||
// The -1 is to omit the trailing \0 which is included in sizeof() on a
|
|||
// string.
|
|||
#define TESTLINE( x ) (strncmp( line, "$" x, sizeof("$" x) - 1 ) == 0)
|
|||
|
|||
while( aReader->ReadLine() ) |
|||
{ |
|||
char* line = aReader->Line(); |
|||
|
|||
// put the more frequent ones at the top
|
|||
|
|||
if( TESTLINE( "MODULE" ) ) |
|||
{ |
|||
MODULE* module = new MODULE( board ); |
|||
board->Add( module, ADD_APPEND ); |
|||
load( module ); |
|||
continue; |
|||
} |
|||
|
|||
if( TESTLINE( "DRAWSEGMENT" ) ) |
|||
{ |
|||
DRAWSEGMENT* dseg = new DRAWSEGMENT( board ); |
|||
board->Add( dseg, ADD_APPEND ); |
|||
load( dseg ); |
|||
continue; |
|||
} |
|||
|
|||
if( TESTLINE( "EQUIPOT" ) ) |
|||
{ |
|||
NETINFO_ITEM* net = new NETINFO_ITEM( board ); |
|||
board->m_NetInfo->AppendNet( net ); |
|||
load( net ); |
|||
continue; |
|||
} |
|||
|
|||
if( TESTLINE( "TEXTPCB" ) ) |
|||
{ |
|||
TEXTE_PCB* pcbtxt = new TEXTE_PCB( board ); |
|||
board->Add( pcbtxt, ADD_APPEND ); |
|||
load( pcbtxt ); |
|||
continue; |
|||
} |
|||
|
|||
if( TESTLINE( "TRACK" ) ) |
|||
{ |
|||
#if 0 && defined(PCBNEW)
|
|||
TRACK* insertBeforeMe = Append ? NULL : board->m_Track.GetFirst(); |
|||
ReadListeSegmentDescr( aReader, insertBeforeMe, PCB_TRACE_T, NbTrack ); |
|||
#endif
|
|||
continue; |
|||
} |
|||
|
|||
if( TESTLINE( BRD_NETCLASS ) ) |
|||
{ |
|||
/*
|
|||
// create an empty NETCLASS without a name.
|
|||
NETCLASS* netclass = new NETCLASS( board, wxEmptyString ); |
|||
|
|||
// fill it from the *.brd file, and establish its name.
|
|||
netclass->ReadDescr( aReader ); |
|||
|
|||
if( !board->m_NetClasses.Add( netclass ) ) |
|||
{ |
|||
// Must have been a name conflict, this is a bad board file.
|
|||
// User may have done a hand edit to the file.
|
|||
// Delete netclass if board could not take ownership of it.
|
|||
delete netclass; |
|||
|
|||
// @todo: throw an exception here, this is a bad board file.
|
|||
} |
|||
*/ |
|||
continue; |
|||
} |
|||
|
|||
if( TESTLINE( "CZONE_OUTLINE" ) ) |
|||
{ |
|||
auto_ptr<ZONE_CONTAINER> zone_descr( new ZONE_CONTAINER( board ) ); |
|||
|
|||
load( zone_descr.get() ); |
|||
|
|||
if( zone_descr->GetNumCorners() > 2 ) // should always occur
|
|||
board->Add( zone_descr.release() ); |
|||
|
|||
// else delete zone_descr; done by auto_ptr
|
|||
|
|||
continue; |
|||
} |
|||
|
|||
if( TESTLINE( "COTATION" ) ) |
|||
{ |
|||
DIMENSION* dim = new DIMENSION( board ); |
|||
board->Add( dim, ADD_APPEND ); |
|||
load( dim ); |
|||
continue; |
|||
} |
|||
|
|||
if( TESTLINE( "PCB_TARGET" ) ) |
|||
{ |
|||
PCB_TARGET* t = new PCB_TARGET( board ); |
|||
board->Add( t, ADD_APPEND ); |
|||
load( t ); |
|||
continue; |
|||
} |
|||
|
|||
if( TESTLINE( "ZONE" ) ) |
|||
{ |
|||
#if 0 && defined(PCBNEW)
|
|||
SEGZONE* insertBeforeMe = Append ? NULL : board->m_Zone.GetFirst(); |
|||
|
|||
ReadListeSegmentDescr( aReader, insertBeforeMe, PCB_ZONE_T, NbZone ); |
|||
#endif
|
|||
continue; |
|||
} |
|||
|
|||
if( TESTLINE( "GENERAL" ) ) |
|||
{ |
|||
loadGeneral( board ); |
|||
continue; |
|||
} |
|||
|
|||
if( TESTLINE( "SHEETDESCR" ) ) |
|||
{ |
|||
loadSheet( board ); |
|||
continue; |
|||
} |
|||
|
|||
if( TESTLINE( "SETUP" ) ) |
|||
{ |
|||
if( !aAppendToMe ) |
|||
{ |
|||
loadSetup( board ); |
|||
} |
|||
else |
|||
{ |
|||
while( aReader->ReadLine() ) |
|||
{ |
|||
line = aReader->Line(); |
|||
|
|||
if( TESTLINE( "EndSETUP" ) ) |
|||
break; |
|||
} |
|||
} |
|||
continue; |
|||
} |
|||
|
|||
if( TESTLINE( "EndPCB" ) ) |
|||
break; |
|||
} |
|||
|
|||
deleter.release(); // no exceptions possible between here and return
|
|||
return board; |
|||
} |
|||
|
|||
|
|||
void KICAD_PLUGIN::load( MODULE* me ) |
|||
{ |
|||
char* line = aReader->Line(); |
|||
char* text = line + 3; |
|||
|
|||
S3D_MASTER* t3D = me->m_3D_Drawings; |
|||
|
|||
if( !t3D->m_Shape3DName.IsEmpty() ) |
|||
{ |
|||
S3D_MASTER* n3D = new S3D_MASTER( me ); |
|||
|
|||
me->m_3D_Drawings.PushBack( n3D ); |
|||
|
|||
t3D = n3D; |
|||
} |
|||
|
|||
while( aReader->ReadLine() ) |
|||
{ |
|||
line = aReader->Line(); |
|||
|
|||
switch( line[0] ) |
|||
{ |
|||
case '$': |
|||
if( line[1] == 'E' ) |
|||
{ |
|||
return 0; |
|||
} |
|||
return 1; |
|||
|
|||
case 'N': // Shape File Name
|
|||
{ |
|||
char buf[512]; |
|||
ReadDelimitedText( buf, text, 512 ); |
|||
|
|||
t3D->m_Shape3DName = FROM_UTF8( buf ); |
|||
break; |
|||
} |
|||
|
|||
case 'S': // Scale
|
|||
sscanf( text, "%lf %lf %lf\n", |
|||
&t3D->m_MatScale.x, |
|||
&t3D->m_MatScale.y, |
|||
&t3D->m_MatScale.z ); |
|||
break; |
|||
|
|||
case 'O': // Offset
|
|||
sscanf( text, "%lf %lf %lf\n", |
|||
&t3D->m_MatPosition.x, |
|||
&t3D->m_MatPosition.y, |
|||
&t3D->m_MatPosition.z ); |
|||
break; |
|||
|
|||
case 'R': // Rotation
|
|||
sscanf( text, "%lf %lf %lf\n", |
|||
&t3D->m_MatRotation.x, |
|||
&t3D->m_MatRotation.y, |
|||
&t3D->m_MatRotation.z ); |
|||
break; |
|||
|
|||
default: |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
std::string KICAD_PLUGIN::biuFmt( BIU aValue ) |
|||
{ |
|||
BFU engUnits = biuToDiskUnits * aValue; |
|||
char temp[48]; |
|||
|
|||
if( engUnits != 0.0 && fabsl( engUnits ) <= 0.0001 ) |
|||
{ |
|||
// printf( "f: " );
|
|||
sprintf( temp, "%.10f", engUnits ); |
|||
|
|||
int len = strlen( temp ); |
|||
|
|||
while( --len > 0 && temp[len] == '0' ) |
|||
temp[len] = '\0'; |
|||
} |
|||
else |
|||
{ |
|||
// printf( "g: " );
|
|||
sprintf( temp, "%.10g", engUnits ); |
|||
} |
|||
|
|||
return temp; |
|||
} |
|||
|
|||
|
|||
void KICAD_PLUGIN::init( BOARD* aBoard, PROPERTIES* aProperties ) |
|||
{ |
|||
NbDraw = NbTrack = NbZone = NbMod = NbNets = -1; |
|||
|
|||
aBoard->m_Status_Pcb = 0; |
|||
aBoard->m_NetClasses.Clear(); |
|||
} |
|||
|
|||
|
|||
void KICAD_PLUGIN::Save( const wxString* aFileName, BOARD* aBoard, PROPERTIES* aProperties ) |
|||
{ |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
@ -0,0 +1,105 @@ |
|||
#ifndef KICAD_PLUGIN_H_ |
|||
#define KICAD_PLUGIN_H_ |
|||
|
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 1992-2011 KiCad Developers, see change_log.txt for contributors. |
|||
* |
|||
* 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> |
|||
#include <string> |
|||
|
|||
typedef int BIU; |
|||
typedef double BFU; |
|||
|
|||
class PCB_TARGET; |
|||
class MODULE; |
|||
class DRAWSEGMENT; |
|||
class NETINFO; |
|||
class TEXTE_PCB; |
|||
class TRACK; |
|||
class NETCLASS; |
|||
class ZONE_CONTAINER; |
|||
class DIMENSION; |
|||
class NETINFO_ITEM; |
|||
|
|||
|
|||
class KICAD_PLUGIN : public PLUGIN |
|||
{ |
|||
|
|||
public: |
|||
|
|||
//-----<PLUGIN>--------------------------------------------------------------------- |
|||
|
|||
BOARD* Load( const wxString& aFileName, BOARD* aAppendToMe, PROPERTIES* aProperties = NULL ); |
|||
|
|||
void Save( const wxString* aFileName, BOARD* aBoard, PROPERTIES* aProperties = NULL ); |
|||
|
|||
const wxString& Name() |
|||
{ |
|||
static const wxString name = wxT( "KiCad" ); |
|||
return name; |
|||
} |
|||
|
|||
//-----</PLUGIN>-------------------------------------------------------------------- |
|||
|
|||
protected: |
|||
|
|||
wxString m_Error; ///< for throwing exceptions |
|||
|
|||
LINE_READER* m_Reader; ///< no ownership here. |
|||
|
|||
/// initialize PLUGIN like a constructor would, and futz with fresh BOARD if needed. |
|||
void init( BOARD* board, PROPERTIES* aProperties ); |
|||
|
|||
int NbDraw; |
|||
int NbTrack; |
|||
int NbZone; |
|||
int NbMod; |
|||
int NbNets; |
|||
|
|||
BFU biuToDisk; ///< convert from BIUs to disk engineering units with this scale factor |
|||
BFU diskToBiu; ///< convert from disk engineering units to BIUs with this scale factor |
|||
|
|||
/// convert a BIU to engineering units by scaling and formatting to ASCII. |
|||
std::string biuFmt( BIU aValue ); |
|||
|
|||
// load / parse functions |
|||
|
|||
void loadGeneral( BOARD* me ); |
|||
void loadSetup( BOARD* me ); |
|||
void loadSheet( BOARD* me ); |
|||
|
|||
void load( PCB_TARGET* me ); |
|||
void load( MODULE* me ); |
|||
void load( DRAWSEGMENT* me ); |
|||
void load( NETINFO* me ); |
|||
void load( TEXTE_PCB* me ); |
|||
void load( TRACK* me ); |
|||
void load( NETCLASS* me ); |
|||
void load( ZONE_CONTAINER* me ); |
|||
void load( DIMENSION* me ); |
|||
void load( NETINFO_ITEM* me ); |
|||
// void load( SEGZONE* me ); |
|||
|
|||
}; |
|||
|
|||
#endif // KICAD_PLUGIN_H_ |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue