Commit 9a8baa00 authored by Miguel Angel Ajo's avatar Miguel Angel Ajo

Allow plugins to be reloaded without closing/opening pcbnew, next step is...

Allow plugins to be reloaded without closing/opening pcbnew, next step is plugin editor, just a few lines away...
parent ecc6a69f
......@@ -31,48 +31,73 @@
#include "class_footprint_wizard.h"
#include <stdio.h>
FOOTPRINT_WIZARD::~FOOTPRINT_WIZARD()
{
}
void FOOTPRINT_WIZARD::register_wizard()
{
FOOTPRINT_WIZARDS::register_wizard( this );
}
std::vector<FOOTPRINT_WIZARD*> FOOTPRINT_WIZARDS::m_FootprintWizards;
std::vector<FOOTPRINT_WIZARD*> FOOTPRINT_WIZARDS::m_FootprintWizards;
FOOTPRINT_WIZARD* FOOTPRINT_WIZARDS::GetWizard( int aIndex )
{
return m_FootprintWizards[aIndex];
}
FOOTPRINT_WIZARD* FOOTPRINT_WIZARDS::GetWizard( wxString aName )
{
int max = GetSize();
for( int i=0; i<max; i++ )
for( int i = 0; i<max; i++ )
{
FOOTPRINT_WIZARD *wizard = GetWizard( i );
FOOTPRINT_WIZARD* wizard = GetWizard( i );
wxString name = wizard->GetName();
wxString name = wizard->GetName();
if ( name.Cmp( aName ) )
return wizard;
if( name.Cmp( aName )==0 )
return wizard;
}
return NULL;
}
int FOOTPRINT_WIZARDS::GetSize()
{
return m_FootprintWizards.size();
}
void FOOTPRINT_WIZARDS::register_wizard(FOOTPRINT_WIZARD *aWizard)
{
void FOOTPRINT_WIZARDS::register_wizard( FOOTPRINT_WIZARD* aWizard )
{
wxString name = aWizard->GetName();
m_FootprintWizards.push_back( aWizard );
m_FootprintWizards.push_back( aWizard );
}
bool FOOTPRINT_WIZARDS::deregister_object( void* aObject )
{
int max = GetSize();
for( int i = 0; i<max; i++ )
{
FOOTPRINT_WIZARD* wizard = GetWizard( i );
if( wizard->GetObject() == aObject )
{
m_FootprintWizards.erase( m_FootprintWizards.begin() + i );
delete wizard;
return true;
}
}
return false;
}
......@@ -29,7 +29,7 @@
*/
#ifndef CLASS_FOOTPRINT_WIZARD_H
#define CLASS_FOOTPRINT_WIZARD_H
#define CLASS_FOOTPRINT_WIZARD_H
#include <vector>
#include <wxPcbStruct.h>
......@@ -39,48 +39,47 @@
* derive */
class FOOTPRINT_WIZARD
{
public:
FOOTPRINT_WIZARD() {}
~FOOTPRINT_WIZARD() {}
virtual ~FOOTPRINT_WIZARD();
/**
* Function GetName
* @return the name of the wizard
*/
virtual wxString GetName()=0;
virtual wxString GetName() = 0;
/**
* Function GetImage
* @return an svg image of the wizard to be rendered
*/
virtual wxString GetImage()=0;
virtual wxString GetImage() = 0;
/**
* Function GetDescription
* @return a description of the footprint wizard
*/
virtual wxString GetDescription()=0;
virtual wxString GetDescription() = 0;
/**
* Function GetNumParameterPages
* @return the number of parameter pages that this wizard will show to the user
*/
virtual int GetNumParameterPages()=0;
virtual int GetNumParameterPages() = 0;
/**
* Function GetParameterPageName
* @param aPage is the page we want the name of
* @return a string with the page name
*/
virtual wxString GetParameterPageName(int aPage)=0;
virtual wxString GetParameterPageName( int aPage ) = 0;
/**
* Function GetParameterNames
* @param aPage is the page we want the parameter names of
* @return an array string with the parameter names on a certain page
*/
virtual wxArrayString GetParameterNames(int aPage)=0;
virtual wxArrayString GetParameterNames( int aPage ) = 0;
/**
* Function GetParameterTypes
......@@ -88,7 +87,7 @@ public:
* @return an array string with the parameter types on a certain page
* "IU" for internal units, "UNITS" for units (0,1,2,3...,N)
*/
virtual wxArrayString GetParameterTypes(int aPage)=0;
virtual wxArrayString GetParameterTypes( int aPage ) = 0;
/**
......@@ -96,14 +95,14 @@ public:
* @param aPage is the page we want the parameter values of
* @return an array of parameter values
*/
virtual wxArrayString GetParameterValues(int aPage)=0;
virtual wxArrayString GetParameterValues( int aPage ) = 0;
/**
* Function GetParameterErrors
* @param aPage is the page we want to know the errors of
* @return an array of errors (if any) for the parameters, empty strings for OK parameters
*/
virtual wxArrayString GetParameterErrors(int aPage)=0;
virtual wxArrayString GetParameterErrors( int aPage ) = 0;
/**
* Function SetParameterValues
......@@ -111,14 +110,21 @@ public:
* @param aValues are the values we want to set into the parameters
* @return an array of parameter values
*/
virtual wxString SetParameterValues(int aPage,wxArrayString& aValues)=0;
virtual wxString SetParameterValues( int aPage, wxArrayString& aValues ) = 0;
/**
* Function GetModule
* This method builds the module itself and returns it to the caller function
* @return PCB module built from the parameters given to the class
*/
virtual MODULE *GetModule()=0;
virtual MODULE* GetModule() = 0;
/**
* Function GetObject
* This method gets the pointer to the object from where this wizard constructs
* @return it's a void pointer, as it could be a PyObject or any other
*/
virtual void* GetObject() = 0;
/**
* Function register_wizard
......@@ -126,8 +132,7 @@ public:
* the FOOTPRINT_WIZARDS singleton manager
*
*/
void register_wizard();
void register_wizard();
};
......@@ -135,10 +140,9 @@ class FOOTPRINT_WIZARDS
{
private:
/**
* FOOTPRINT_WIZARD system wide static list
*/
static std::vector<FOOTPRINT_WIZARD*> m_FootprintWizards;
* FOOTPRINT_WIZARD system wide static list
*/
static std::vector<FOOTPRINT_WIZARD*> m_FootprintWizards;
public:
/**
......@@ -149,7 +153,18 @@ public:
* @param aWizard is the footprint wizard to be registered
*
*/
static void register_wizard(FOOTPRINT_WIZARD *aWizard);
static void register_wizard( FOOTPRINT_WIZARD* aWizard );
/**
* Function deregister_object
* Anyone calls this method to deregister an object which builds a wizard,
* it will lookup on the vector calling GetObject until find, then removed
* and deleted
*
* @param aObject is the footprint wizard object to be deregistered
*
*/
static bool deregister_object( void* aObject );
/**
* Function GetWizard
......@@ -157,7 +172,7 @@ public:
* @return a wizard object by it's name or NULL if it isn't available.
*
*/
static FOOTPRINT_WIZARD* GetWizard(wxString aName);
static FOOTPRINT_WIZARD* GetWizard( wxString aName );
/**
* Function GetWizard
......@@ -165,15 +180,13 @@ public:
* @param aIndex is the wizard index in list
*
*/
static FOOTPRINT_WIZARD* GetWizard( int aIndex );
static FOOTPRINT_WIZARD* GetWizard( int aIndex );
/**
* Function GetSize
* @return the number of wizards available into the system
*/
static int GetSize();
static int GetSize();
};
#endif /* PCBNEW_FOOTPRINT_WIZARDS_H */
#endif /* PCBNEW_FOOTPRINT_WIZARDS_H */
......@@ -94,13 +94,15 @@ void FOOTPRINT_WIZARD_FRAME::DisplayWizardInfos()
void FOOTPRINT_WIZARD_FRAME::ReloadFootprint()
{
if( m_FootprintWizard == NULL )
FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
if( !footprintWizard )
return;
SetCurItem( NULL );
// Delete the current footprint
GetBoard()->m_Modules.DeleteAll();
MODULE* m = m_FootprintWizard->GetModule();
MODULE* m = footprintWizard->GetModule();
if( m )
{
......@@ -112,18 +114,37 @@ void FOOTPRINT_WIZARD_FRAME::ReloadFootprint()
}
else
{
printf( "m_FootprintWizard->GetModule() returns NULL\n" );
printf( "footprintWizard->GetModule() returns NULL\n" );
}
m_canvas->Refresh();
}
FOOTPRINT_WIZARD* FOOTPRINT_WIZARD_FRAME::GetMyWizard()
{
if( m_wizardName.Length()==0 )
return NULL;
FOOTPRINT_WIZARD* footprintWizard = FOOTPRINT_WIZARDS::GetWizard( m_wizardName );
if( !footprintWizard )
{
wxMessageBox( _( "Couldn't reload footprint wizard" ) );
return NULL;
}
return footprintWizard;
}
MODULE* FOOTPRINT_WIZARD_FRAME::GetBuiltFootprint()
{
if( m_FootprintWizard )
FOOTPRINT_WIZARD* footprintWizard = FOOTPRINT_WIZARDS::GetWizard( m_wizardName );
if( footprintWizard )
{
return m_FootprintWizard->GetModule();
return footprintWizard->GetModule();
}
else
{
......@@ -139,12 +160,17 @@ void FOOTPRINT_WIZARD_FRAME::SelectFootprintWizard()
selectWizard->ShowModal();
m_FootprintWizard = selectWizard->GetWizard();
FOOTPRINT_WIZARD* footprintWizard = selectWizard->GetWizard();
if( m_FootprintWizard )
if( footprintWizard )
{
m_wizardName = m_FootprintWizard->GetName();
m_wizardDescription = m_FootprintWizard->GetDescription();
m_wizardName = footprintWizard->GetName();
m_wizardDescription = footprintWizard->GetDescription();
}
else
{
m_wizardName = wxT( "" );
m_wizardDescription = wxT( "" );
}
ReloadFootprint();
......@@ -169,12 +195,17 @@ void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event )
{
int page = m_PageList->GetSelection();
FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
if( !footprintWizard )
return;
if( page<0 )
return;
int n = m_ParameterGrid->GetNumberRows();
wxArrayString arr;
wxArrayString ptList = m_FootprintWizard->GetParameterTypes( page );
wxArrayString ptList = footprintWizard->GetParameterTypes( page );
for( int i = 0; i<n; i++ )
{
......@@ -184,8 +215,8 @@ void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event )
// unit convert it back from the user format
if( ptList[i]==wxT( "IU" ) )
{
LOCALE_IO toggle;
double dValue;
LOCALE_IO toggle;
double dValue;
value.ToDouble( &dValue );
......@@ -205,7 +236,7 @@ void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event )
arr.Add( value );
}
wxString res = m_FootprintWizard->SetParameterValues( page, arr );
wxString res = footprintWizard->SetParameterValues( page, arr );
ReloadFootprint();
DisplayWizardInfos();
......
......@@ -52,37 +52,39 @@
BEGIN_EVENT_TABLE( FOOTPRINT_WIZARD_FRAME, EDA_DRAW_FRAME )
/* Window events */
EVT_CLOSE( FOOTPRINT_WIZARD_FRAME::OnCloseWindow )
EVT_SIZE( FOOTPRINT_WIZARD_FRAME::OnSize )
EVT_ACTIVATE( FOOTPRINT_WIZARD_FRAME::OnActivate )
/* Window events */
EVT_CLOSE( FOOTPRINT_WIZARD_FRAME::OnCloseWindow )
EVT_SIZE( FOOTPRINT_WIZARD_FRAME::OnSize )
EVT_ACTIVATE( FOOTPRINT_WIZARD_FRAME::OnActivate )
/* Sash drag events */
EVT_SASH_DRAGGED( ID_FOOTPRINT_WIZARD_PAGES, FOOTPRINT_WIZARD_FRAME::OnSashDrag )
EVT_SASH_DRAGGED( ID_FOOTPRINT_WIZARD_PARAMETERS, FOOTPRINT_WIZARD_FRAME::OnSashDrag )
/* Sash drag events */
EVT_SASH_DRAGGED( ID_FOOTPRINT_WIZARD_PAGES, FOOTPRINT_WIZARD_FRAME::OnSashDrag )
EVT_SASH_DRAGGED( ID_FOOTPRINT_WIZARD_PARAMETERS, FOOTPRINT_WIZARD_FRAME::OnSashDrag )
/* Toolbar events */
EVT_TOOL( ID_FOOTPRINT_WIZARD_SELECT_WIZARD,
FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard )
/* Toolbar events */
EVT_TOOL( ID_FOOTPRINT_WIZARD_SELECT_WIZARD,
FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard )
EVT_TOOL( ID_FOOTPRINT_WIZARD_NEXT,
FOOTPRINT_WIZARD_FRAME::Process_Special_Functions )
EVT_TOOL( ID_FOOTPRINT_WIZARD_NEXT,
FOOTPRINT_WIZARD_FRAME::Process_Special_Functions )
EVT_TOOL( ID_FOOTPRINT_WIZARD_PREVIOUS,
FOOTPRINT_WIZARD_FRAME::Process_Special_Functions )
EVT_TOOL( ID_FOOTPRINT_WIZARD_PREVIOUS,
FOOTPRINT_WIZARD_FRAME::Process_Special_Functions )
EVT_TOOL( ID_FOOTPRINT_WIZARD_DONE,
FOOTPRINT_WIZARD_FRAME::ExportSelectedFootprint )
EVT_TOOL( ID_FOOTPRINT_WIZARD_DONE,
FOOTPRINT_WIZARD_FRAME::ExportSelectedFootprint )
EVT_TOOL( ID_FOOTPRINT_WIZARD_SHOW_3D_VIEW,
FOOTPRINT_WIZARD_FRAME::Show3D_Frame )
EVT_TOOL( ID_FOOTPRINT_WIZARD_SHOW_3D_VIEW,
FOOTPRINT_WIZARD_FRAME::Show3D_Frame )
/* listbox events */
EVT_LISTBOX( ID_FOOTPRINT_WIZARD_PAGE_LIST, FOOTPRINT_WIZARD_FRAME::ClickOnPageList )
EVT_GRID_CMD_CELL_CHANGE( ID_FOOTPRINT_WIZARD_PARAMETER_LIST,
FOOTPRINT_WIZARD_FRAME::ParametersUpdated )
/* listbox events */
EVT_LISTBOX( ID_FOOTPRINT_WIZARD_PAGE_LIST, FOOTPRINT_WIZARD_FRAME::ClickOnPageList )
EVT_GRID_CMD_CELL_CHANGE( ID_FOOTPRINT_WIZARD_PARAMETER_LIST,
FOOTPRINT_WIZARD_FRAME::ParametersUpdated )
EVT_GRID_CMD_EDITOR_HIDDEN( ID_FOOTPRINT_WIZARD_PARAMETER_LIST,
FOOTPRINT_WIZARD_FRAME::ParametersUpdated )
EVT_MENU( ID_SET_RELATIVE_OFFSET, FOOTPRINT_WIZARD_FRAME::OnSetRelativeOffset )
EVT_MENU( ID_SET_RELATIVE_OFFSET, FOOTPRINT_WIZARD_FRAME::OnSetRelativeOffset )
END_EVENT_TABLE()
......@@ -131,7 +133,6 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent,
// SetIcon( icon );
m_HotkeysZoomAndGridList = g_Module_Viewer_Hokeys_Descr;
m_FootprintWizard = NULL;
m_PageList = NULL;
m_ParameterGrid = NULL;
m_PageListWindow = NULL;
......@@ -386,15 +387,18 @@ void FOOTPRINT_WIZARD_FRAME::ReCreatePageList()
if( m_PageList == NULL )
return;
if( m_FootprintWizard == NULL )
FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
if( !footprintWizard )
return;
m_PageList->Clear();
int max_page = m_FootprintWizard->GetNumParameterPages();
int max_page = footprintWizard->GetNumParameterPages();
for( int i = 0; i<max_page; i++ )
{
wxString name = m_FootprintWizard->GetParameterPageName( i );
wxString name = footprintWizard->GetParameterPageName( i );
m_PageList->Append( name );
}
......@@ -417,7 +421,9 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList()
if( m_ParameterGrid == NULL )
return;
if( m_FootprintWizard == NULL )
FOOTPRINT_WIZARD* footprintWizard = GetMyWizard();
if( footprintWizard == NULL )
return;
int page = m_PageList->GetSelection();
......@@ -435,9 +441,9 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList()
m_ParameterGrid->SetRowLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
// Get the list of names, values, and types
wxArrayString fpList = m_FootprintWizard->GetParameterNames( page );
wxArrayString fvList = m_FootprintWizard->GetParameterValues( page );
wxArrayString ptList = m_FootprintWizard->GetParameterTypes( page );
wxArrayString fpList = footprintWizard->GetParameterNames( page );
wxArrayString fvList = footprintWizard->GetParameterValues( page );
wxArrayString ptList = footprintWizard->GetParameterTypes( page );
// Dimension the wxGrid
m_ParameterGrid->DeleteRows( 0, m_ParameterGrid->GetNumberRows() );
......@@ -580,9 +586,9 @@ void FOOTPRINT_WIZARD_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition
cmd.SetEventObject( this );
pos = screen->GetNearestGridPosition( pos );
oldpos = screen->GetCrossHairPosition();
gridSize = screen->GetGridSize();
pos = screen->GetNearestGridPosition( pos );
oldpos = screen->GetCrossHairPosition();
gridSize = screen->GetGridSize();
switch( aHotKey )
{
......
......@@ -55,17 +55,15 @@ private:
wxSashLayoutWindow* m_ParameterGridWindow; // < List of components in the selected library
wxGrid* m_ParameterGrid; // < The list of parameters
wxSize m_ParameterGridSize; // < size of the window
wxSize m_ParameterGridSize; // < size of the window
// Flags
wxSemaphore* m_Semaphore; // < != NULL if the frame must emulate a modal dialog
wxString m_configPath; // < subpath for configuration
FOOTPRINT_WIZARD* m_FootprintWizard;
wxSemaphore* m_Semaphore; // < != NULL if the frame must emulate a modal dialog
wxString m_configPath; // < subpath for configuration
protected:
wxString m_wizardName; // < name of the current wizard
wxString m_wizardDescription; // < description of the wizard
wxString m_wizardStatus; // < current wizard status
wxString m_wizardName; // < name of the current wizard
wxString m_wizardDescription; // < description of the wizard
wxString m_wizardStatus; // < current wizard status
public:
FOOTPRINT_WIZARD_FRAME( FOOTPRINT_EDIT_FRAME* parent,
wxSemaphore* semaphore = NULL,
......@@ -73,70 +71,76 @@ public:
~FOOTPRINT_WIZARD_FRAME();
MODULE* GetBuiltFootprint( void );
MODULE* GetBuiltFootprint( void );
private:
void OnSize( wxSizeEvent& event );
void OnSize( wxSizeEvent& event );
/**
* Function ExportSelectedFootprint();
* will let the caller exit from the wait loop, and get the built footprint
*
*/
void ExportSelectedFootprint( wxCommandEvent& aEvent );
void ExportSelectedFootprint( wxCommandEvent& aEvent );
/**
* Function OnSashDrag
* resizes the child windows when dragging a sash window border.
*/
void OnSashDrag( wxSashEvent& event );
void OnSashDrag( wxSashEvent& event );
/**
* Function ReCreatePageList
* Creates or recreates the list of parameter pages for the current wizard.
* This list is sorted
*/
void ReCreatePageList();
void ReCreatePageList();
/**
* Function ReCreateParameterList
* Creates the list of parameters for the current page
*/
void ReCreateParameterList();
void ReCreateParameterList();
/**
* Function SelectFootprintWizard
* Shows the list of footprint wizards available into the system
*/
void SelectFootprintWizard();
void SelectFootprintWizard();
/**
* Function ReloadFootprint
* Reloads the current footprint
*/
void ReloadFootprint();
void ReloadFootprint();
/**
* Function GetMyWizard
* Reloads the wizard by name
*/
FOOTPRINT_WIZARD* GetMyWizard();
void Process_Special_Functions( wxCommandEvent& event );
void Process_Special_Functions( wxCommandEvent& event );
/**
* Function DisplayWizardInfos
* Shows all the details about the current wizard
*/
void DisplayWizardInfos();
void DisplayWizardInfos();
void RedrawActiveWindow( wxDC* DC, bool EraseBg );
void OnCloseWindow( wxCloseEvent& Event );
void ReCreateHToolbar();
void ReCreateVToolbar();
void OnLeftClick( wxDC* DC, const wxPoint& MousePos );
void ClickOnPageList( wxCommandEvent& event );
void OnSetRelativeOffset( wxCommandEvent& event );
void RedrawActiveWindow( wxDC* DC, bool EraseBg );
void OnCloseWindow( wxCloseEvent& Event );
void ReCreateHToolbar();
void ReCreateVToolbar();
void OnLeftClick( wxDC* DC, const wxPoint& MousePos );
void ClickOnPageList( wxCommandEvent& event );
void OnSetRelativeOffset( wxCommandEvent& event );
void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 );
void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 );
/**
* Function LoadSettings
......@@ -145,7 +149,7 @@ private:
* Don't forget to call this base method from any derived classes or the
* settings will not get loaded.
*/
void LoadSettings();
void LoadSettings();
/**
* Function SaveSettings
......@@ -154,7 +158,7 @@ private:
* Don't forget to call this base method from any derived classes or the
* settings will not get saved.
*/
void SaveSettings();
void SaveSettings();
/**
......@@ -162,20 +166,20 @@ private:
* is called when the frame frame is activate to reload the libraries and component lists
* that can be changed by the schematic editor or the library editor.
*/
virtual void OnActivate( wxActivateEvent& event );
virtual void OnActivate( wxActivateEvent& event );
void SelectCurrentWizard( wxCommandEvent& event );
void SelectCurrentWizard( wxCommandEvent& event );
void ParametersUpdated( wxGridEvent& event );
void ParametersUpdated( wxGridEvent& event );
bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu );
bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu );
/**
* Function Show3D_Frame (virtual)
* displays 3D view of the footprint (module) being edited.
*/
void Show3D_Frame( wxCommandEvent& event );
void Show3D_Frame( wxCommandEvent& event );
/**
* Function Update3D_Frame
......@@ -184,7 +188,7 @@ private:
* @param aForceReloadFootprint = true to reload data (default)
* = false to update title only -(aftre creating the 3D viewer)
*/
void Update3D_Frame( bool aForceReloadFootprint = true );
void Update3D_Frame( bool aForceReloadFootprint = true );
/*
* Virtual functions, not used here, but needed by PCB_BASE_FRAME
......
......@@ -51,10 +51,11 @@ PYTHON_FOOTPRINT_WIZARD::~PYTHON_FOOTPRINT_WIZARD()
PyObject* PYTHON_FOOTPRINT_WIZARD::CallMethod( const char* aMethod, PyObject* aArglist )
{
PyLOCK lock;
PyLOCK lock;
PyErr_Clear();
// pFunc is a new reference to the desired method
PyObject* pFunc = PyObject_GetAttrString( this->m_PyWizard, aMethod );
PyObject* pFunc = PyObject_GetAttrString( this->m_PyWizard, aMethod );
if( pFunc && PyCallable_Check( pFunc ) )
{
......@@ -79,6 +80,8 @@ PyObject* PYTHON_FOOTPRINT_WIZARD::CallMethod( const char* aMethod, PyObject* aA
wxMessageBox( message,
wxT( "Exception on python footprint wizard code" ),
wxICON_ERROR | wxOK );
PyErr_Clear();
}
if( result )
......@@ -346,7 +349,10 @@ MODULE* PYTHON_FOOTPRINT_WIZARD::GetModule()
PyObject* obj = PyObject_GetAttrString( result, "this" );
if( PyErr_Occurred() )
{
PyErr_Print();
PyErr_Clear();
}
MODULE* mod = PyModule_to_MODULE( obj );
......@@ -354,9 +360,22 @@ MODULE* PYTHON_FOOTPRINT_WIZARD::GetModule()
}
void* PYTHON_FOOTPRINT_WIZARD::GetObject()
{
return (void*) m_PyWizard;
}
void PYTHON_FOOTPRINT_WIZARDS::register_wizard( PyObject* aPyWizard )
{
PYTHON_FOOTPRINT_WIZARD* fw = new PYTHON_FOOTPRINT_WIZARD( aPyWizard );
fw->register_wizard();
}
void PYTHON_FOOTPRINT_WIZARDS::deregister_wizard( PyObject* aPyWizard )
{
// deregister also destroyes the previously created "PYTHON_FOOTPRINT_WIZARD object"
FOOTPRINT_WIZARDS::deregister_object( (void*) aPyWizard );
}
......@@ -56,6 +56,7 @@ public:
wxArrayString GetParameterErrors( int aPage );
wxString SetParameterValues( int aPage, wxArrayString& aValues ); // < must return "OK" or error description
MODULE* GetModule();
void* GetObject();
};
......@@ -63,6 +64,7 @@ class PYTHON_FOOTPRINT_WIZARDS
{
public:
static void register_wizard( PyObject* aPyWizard );
static void deregister_wizard( PyObject* aPyWizard );
};
#endif /* PCBNEW_FOOTPRINT_WIZARDS_H */
......@@ -26,9 +26,10 @@
#include <scripting/pcbnew_footprint_wizards.h>
%}
class PYTHON_FOOTPRINT_WIZARDS
class PYTHON_FOOTPRINT_WIZARDS
{
public:
static void register_wizard(PyObject *wizard);
static void deregister_wizard(PyObject *wizard);
};
......@@ -32,77 +32,110 @@
* |
* |\-FilePlugin
* |\-FootprintWizardPlugin
* |\-ActionPlugin
* |\-ActionPlugin
*
* It defines the LoadPlugins() function that loads all the plugins
* available in the system
*
*/
%pythoncode
%pythoncode
{
def LoadPlugins():
KICAD_PLUGINS={}
def ReloadPlugin(name):
if not KICAD_PLUGINS.has_key(name):
return False
KICAD_PLUGINS[name]["wizard"].deregister()
mod = reload(KICAD_PLUGINS[name]["module"])
KICAD_PLUGINS[name]["wizard"]= mod.register()
def LoadPlugins():
import os
import sys
# Use environment variable KICAD_PATH to derive path to plugins as a temporary solution
kicad_path = os.environ.get('KICAD_PATH')
plugin_directories=[]
if kicad_path and os.path.isdir(kicad_path):
plugin_directories.append(os.path.join(kicad_path, 'scripting', 'plugins'))
if sys.platform.startswith('linux'):
if sys.platform.startswith('linux') or sys.platform.startswith('darwin'):
plugin_directories.append(os.environ['HOME']+'/.kicad_plugins/')
plugin_directories.append(os.environ['HOME']+'/.kicad/scripting/plugins/')
# scan all possible directories for plugins, and load them
for plugins_dir in plugin_directories:
sys.path.append(plugins_dir)
if not os.path.isdir(plugins_dir):
if not os.path.isdir(plugins_dir):
continue
for module in os.listdir(plugins_dir):
if os.path.isdir(plugins_dir+module):
__import__(module, locals(), globals())
if module == '__init__.py' or module[-3:] != '.py':
continue
__import__(module[:-3], locals(), globals())
mod = __import__(module[:-3], locals(), globals())
if hasattr(mod,'register'):
KICAD_PLUGINS[module]={"filename":plugins_dir+"/"+module,
"wizard":mod.register(),
"module":mod}
# KiCadPlugin base class will register any plugin into the right place
class KiCadPlugin:
def __init__(self):
pass
def register(self):
if isinstance(self,FilePlugin):
pass # register to file plugins in C++
if isinstance(self,FootprintWizardPlugin):
PYTHON_FOOTPRINT_WIZARDS.register_wizard(self)
return
if isinstance(self,ActionPlugin):
pass # register to action plugins in C++
return
def deregister(self):
if isinstance(self,FilePlugin):
pass # register to file plugins in C++
if isinstance(self,FootprintWizardPlugin):
PYTHON_FOOTPRINT_WIZARDS.deregister_wizard(self)
return
if isinstance(self,ActionPlugin):
pass # register to action plugins in C++
return
# This will be the file io scripting based plugins class
class FilePlugin(KiCadPlugin):
def __init__(self):
KiCadPlugin.__init__(self)
# Scriping footprint wizards
class FootprintWizardPlugin(KiCadPlugin):
def __init__(self):
KiCadPlugin.__init__(self)
self.defaults()
def defaults(self):
self.module = None
self.parameters = {}
......@@ -110,50 +143,50 @@ class FootprintWizardPlugin(KiCadPlugin):
self.name = "Undefined Footprint Wizard plugin"
self.description = ""
self.image = ""
def GetName(self):
return self.name
def GetImage(self):
return self.image
def GetDescription(self):
return self.description
def GetNumParameterPages(self):
return len(self.parameters)
def GetParameterPageName(self,page_n):
return self.parameters.keys()[page_n]
def GetParameterNames(self,page_n):
name = self.GetParameterPageName(page_n)
return self.parameters[name].keys()
def GetParameterValues(self,page_n):
name = self.GetParameterPageName(page_n)
values = self.parameters[name].values()
return map( lambda x: str(x) , values) # list elements as strings
def GetParameterErrors(self,page_n):
self.CheckParameters()
name = self.GetParameterPageName(page_n)
values = self.parameter_errors[name].values()
return map( lambda x: str(x) , values) # list elements as strings
def CheckParameters(self):
return ""
def TryConvertToFloat(self,value):
v = value
try:
v = float(value)
except:
pass
return v
def SetParameterValues(self,page_n,values):
name = self.GetParameterPageName(page_n)
keys = self.parameters[name].keys()
......@@ -163,29 +196,29 @@ class FootprintWizardPlugin(KiCadPlugin):
self.parameters[name][key] = val
print "[%s][%s]<="%(name,key),val
n+=1
# copies the parameter list on parameter_errors but empty
def ClearErrors(self):
errs={}
for page in self.parameters.keys():
page_dict = self.parameters[page]
page_params = {}
for param in page_dict.keys():
page_params[param]=""
errs[page]=page_params
self.parameter_errors = errs
self.parameter_errors = errs
def GetModule(self):
self.BuildFootprint()
return self.module
def BuildFootprint(self):
return
def Show(self):
print "Footprint Wizard Name: ",self.GetName()
print "Footprint Wizard Description: ",self.GetDescription()
......@@ -203,6 +236,4 @@ class ActionPlugin(KiCadPlugin):
def __init__(self):
KiCadPlugin.__init__(self)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment