Skip to content

Commit

Permalink
Allow plugins to be reloaded without closing/opening pcbnew, next ste…
Browse files Browse the repository at this point in the history
…p is plugin editor, just a few lines away...
  • Loading branch information
Miguel Angel Ajo committed Mar 16, 2013
1 parent ecc6a69 commit 9a8baa0
Show file tree
Hide file tree
Showing 9 changed files with 297 additions and 165 deletions.
43 changes: 34 additions & 9 deletions pcbnew/class_footprint_wizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
67 changes: 40 additions & 27 deletions pcbnew/class_footprint_wizard.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/

#ifndef CLASS_FOOTPRINT_WIZARD_H
#define CLASS_FOOTPRINT_WIZARD_H
#define CLASS_FOOTPRINT_WIZARD_H
#include <vector>
#include <wxPcbStruct.h>

Expand All @@ -39,106 +39,110 @@
* 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
* @param aPage is the page we want the parameter types of
* @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;


/**
* Function GetParameterValues
* @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
* @param aPage is the page we want to set the parameters in
* @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
* It's the standard method of a "FOOTPRINT_WIZARD" to register itself into
* the FOOTPRINT_WIZARDS singleton manager
*
*/
void register_wizard();

void register_wizard();
};


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:

/**
Expand All @@ -149,31 +153,40 @@ class FOOTPRINT_WIZARDS
* @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
* @param aName is the footprint wizard name
* @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
* @return a wizard object by it's number or NULL if it isn't available.
* @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 */
57 changes: 44 additions & 13 deletions pcbnew/footprint_wizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -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
{
Expand All @@ -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();
Expand All @@ -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++ )
{
Expand All @@ -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 );

Expand All @@ -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();
Expand Down
Loading

0 comments on commit 9a8baa0

Please sign in to comment.