Footprint wizard, plus fixes
This commit is contained in:
parent
4dc70b2fc8
commit
70df15175b
|
@ -290,6 +290,7 @@ if (KICAD_SCRIPTING)
|
||||||
DEPENDS ../scripting/dlist.i
|
DEPENDS ../scripting/dlist.i
|
||||||
DEPENDS ../scripting/kicad.i
|
DEPENDS ../scripting/kicad.i
|
||||||
DEPENDS ../scripting/wx.i
|
DEPENDS ../scripting/wx.i
|
||||||
|
DEPENDS ../scripting/kicadplugins.i
|
||||||
# DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/pcbnew
|
# DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/pcbnew
|
||||||
|
|
||||||
COMMAND ${SWIG_EXECUTABLE} ${SWIG_OPTS} -o ${CMAKE_CURRENT_BINARY_DIR}/pcbnew_wrap.cxx scripting/pcbnew.i
|
COMMAND ${SWIG_EXECUTABLE} ${SWIG_OPTS} -o ${CMAKE_CURRENT_BINARY_DIR}/pcbnew_wrap.cxx scripting/pcbnew.i
|
||||||
|
|
|
@ -23,6 +23,7 @@ public:
|
||||||
virtual wxString GetParameterPageName(int aPage)=0;
|
virtual wxString GetParameterPageName(int aPage)=0;
|
||||||
virtual wxArrayString GetParameterNames(int aPage)=0;
|
virtual wxArrayString GetParameterNames(int aPage)=0;
|
||||||
virtual wxArrayString GetParameterValues(int aPage)=0;
|
virtual wxArrayString GetParameterValues(int aPage)=0;
|
||||||
|
virtual wxArrayString GetParameterErrors(int aPage)=0;
|
||||||
virtual wxString SetParameterValues(int aPage,wxArrayString& aValues)=0;
|
virtual wxString SetParameterValues(int aPage,wxArrayString& aValues)=0;
|
||||||
virtual MODULE *GetModule()=0;
|
virtual MODULE *GetModule()=0;
|
||||||
void register_wizard();
|
void register_wizard();
|
||||||
|
|
|
@ -28,6 +28,9 @@ DIALOG_FOOTPRINT_WIZARD_LIST::DIALOG_FOOTPRINT_WIZARD_LIST( wxWindow* aParent )
|
||||||
m_FootprintWizard = FOOTPRINT_WIZARDS::GetWizard(0);
|
m_FootprintWizard = FOOTPRINT_WIZARDS::GetWizard(0);
|
||||||
|
|
||||||
// Choose selection mode and insert the needed rows
|
// Choose selection mode and insert the needed rows
|
||||||
|
|
||||||
|
m_footprintWizardsGrid->SetColSize( 0, 0 ); // hide the preview for now
|
||||||
|
|
||||||
m_footprintWizardsGrid->SetSelectionMode(wxGrid::wxGridSelectRows);
|
m_footprintWizardsGrid->SetSelectionMode(wxGrid::wxGridSelectRows);
|
||||||
m_footprintWizardsGrid->InsertRows(0,n_wizards,true);
|
m_footprintWizardsGrid->InsertRows(0,n_wizards,true);
|
||||||
|
|
||||||
|
|
|
@ -134,31 +134,28 @@ void FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard( wxCommandEvent& event )
|
||||||
* Function SelectCurrentFootprint
|
* Function SelectCurrentFootprint
|
||||||
* Selects the current footprint name and display it
|
* Selects the current footprint name and display it
|
||||||
*/
|
*/
|
||||||
void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxCommandEvent& event )
|
void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event )
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
// will pick it from the wizard
|
int page = m_PageList->GetSelection();
|
||||||
MODULE * module = new MODULE(NULL);
|
|
||||||
if( module )
|
if (page<0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int n=m_ParameterGrid->GetNumberRows();
|
||||||
|
wxArrayString arr;
|
||||||
|
|
||||||
|
for (int i=0;i<n;i++)
|
||||||
{
|
{
|
||||||
module->SetPosition( wxPoint( 0, 0 ) );
|
wxString val = m_ParameterGrid->GetCellValue(i,1);
|
||||||
|
arr.Add(val);
|
||||||
|
}
|
||||||
|
|
||||||
// Only one fotprint allowed: remove the previous footprint (if exists)
|
wxString res = m_FootprintWizard->SetParameterValues(page,arr);
|
||||||
if( oldmodule )
|
|
||||||
{
|
ReloadFootprint();
|
||||||
GetBoard()->Remove( oldmodule );
|
DisplayWizardInfos();
|
||||||
delete oldmodule;
|
|
||||||
}
|
|
||||||
m_footprintName = module->GetLibRef();
|
|
||||||
module->ClearFlags();
|
|
||||||
SetCurItem( NULL );
|
|
||||||
|
|
||||||
Zoom_Automatique( false );
|
|
||||||
m_canvas->Refresh( );
|
|
||||||
Update3D_Frame();
|
|
||||||
m_FootprintList->SetStringSelection( m_footprintName );
|
|
||||||
}
|
|
||||||
* */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ BEGIN_EVENT_TABLE( FOOTPRINT_WIZARD_FRAME, EDA_DRAW_FRAME )
|
||||||
|
|
||||||
/* listbox events */
|
/* listbox events */
|
||||||
EVT_LISTBOX( ID_FOOTPRINT_WIZARD_PAGE_LIST, FOOTPRINT_WIZARD_FRAME::ClickOnPageList )
|
EVT_LISTBOX( ID_FOOTPRINT_WIZARD_PAGE_LIST, FOOTPRINT_WIZARD_FRAME::ClickOnPageList )
|
||||||
EVT_LISTBOX( ID_FOOTPRINT_WIZARD_PARAMETER_LIST, FOOTPRINT_WIZARD_FRAME::ClickOnParameterGrid )
|
EVT_GRID_CMD_CELL_CHANGE( 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()
|
END_EVENT_TABLE()
|
||||||
|
@ -412,21 +412,6 @@ void FOOTPRINT_WIZARD_FRAME::ClickOnPageList( wxCommandEvent& event )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FOOTPRINT_WIZARD_FRAME::ClickOnParameterGrid( wxCommandEvent& event )
|
|
||||||
{
|
|
||||||
int n=m_ParameterGrid->GetNumberRows();
|
|
||||||
|
|
||||||
for (int i=0;i<n;i++)
|
|
||||||
{
|
|
||||||
// Get values, send them to the object..
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ReloadFootprint();
|
|
||||||
DisplayWizardInfos();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define PARTLIST_WIDTH_KEY wxT( "Partlist_width" )
|
#define PARTLIST_WIDTH_KEY wxT( "Partlist_width" )
|
||||||
#define PARAMLIST_WIDTH_KEY wxT( "Paramlist_width" )
|
#define PARAMLIST_WIDTH_KEY wxT( "Paramlist_width" )
|
||||||
|
|
|
@ -37,6 +37,7 @@ class wxSashLayoutWindow;
|
||||||
class wxListBox;
|
class wxListBox;
|
||||||
class wxSemaphore;
|
class wxSemaphore;
|
||||||
class wxGrid;
|
class wxGrid;
|
||||||
|
class wxGridEvent;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,7 +105,6 @@ private:
|
||||||
void ReCreateVToolbar();
|
void ReCreateVToolbar();
|
||||||
void OnLeftClick( wxDC* DC, const wxPoint& MousePos );
|
void OnLeftClick( wxDC* DC, const wxPoint& MousePos );
|
||||||
void ClickOnPageList( wxCommandEvent& event );
|
void ClickOnPageList( wxCommandEvent& event );
|
||||||
void ClickOnParameterGrid( wxCommandEvent& event );
|
|
||||||
void OnSetRelativeOffset( 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 );
|
||||||
|
@ -137,7 +137,7 @@ private:
|
||||||
|
|
||||||
void SelectCurrentWizard( wxCommandEvent& event );
|
void SelectCurrentWizard( wxCommandEvent& event );
|
||||||
|
|
||||||
void ParametersUpdated( wxCommandEvent& event );
|
void ParametersUpdated( wxGridEvent& event );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
def GetPads(self): return self.m_Pads
|
def GetPads(self): return self.m_Pads
|
||||||
def GetDrawings(self): return self.m_Drawings
|
def GetDrawings(self): return self.m_Drawings
|
||||||
def GetReferenceObj(self): return self.m_Reference
|
def GetReferenceObj(self): return self.m_Reference
|
||||||
|
def GetValueObj(self): return self.m_Value
|
||||||
|
|
||||||
#def SaveToLibrary(self,filename):
|
#def SaveToLibrary(self,filename):
|
||||||
# return SaveModuleToLibrary(filename,self)
|
# return SaveModuleToLibrary(filename,self)
|
||||||
|
|
|
@ -186,10 +186,42 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterValues(int aPage)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterErrors(int aPage)
|
||||||
|
{
|
||||||
|
PyObject *arglist;
|
||||||
|
wxArrayString ret;
|
||||||
|
|
||||||
|
arglist = Py_BuildValue("(i)", aPage);
|
||||||
|
ret = CallRetArrayStrMethod("GetParameterErrors",arglist);
|
||||||
|
Py_DECREF(arglist);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
wxString PYTHON_FOOTPRINT_WIZARD::SetParameterValues(int aPage,wxArrayString& aValues)
|
wxString PYTHON_FOOTPRINT_WIZARD::SetParameterValues(int aPage,wxArrayString& aValues)
|
||||||
{
|
{
|
||||||
wxString ret;
|
|
||||||
return ret;
|
int len = aValues.size();
|
||||||
|
PyObject *py_list;
|
||||||
|
|
||||||
|
py_list = PyList_New(len);
|
||||||
|
|
||||||
|
for (int i=0;i<len;i++)
|
||||||
|
{
|
||||||
|
wxString str = aValues[i];
|
||||||
|
PyObject *py_str = PyString_FromString((const char*)str.mb_str());
|
||||||
|
PyList_SetItem(py_list, i, py_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
PyObject *arglist;
|
||||||
|
|
||||||
|
arglist = Py_BuildValue("(i,O)", aPage,py_list);
|
||||||
|
wxString res = CallRetStrMethod("SetParameterValues",arglist);
|
||||||
|
Py_DECREF(arglist);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this is a SWIG function declaration -from module.i*/
|
/* this is a SWIG function declaration -from module.i*/
|
||||||
|
@ -201,14 +233,18 @@ MODULE *PYTHON_FOOTPRINT_WIZARD::GetModule()
|
||||||
result = CallMethod("GetModule",NULL);
|
result = CallMethod("GetModule",NULL);
|
||||||
if (!result) return NULL;
|
if (!result) return NULL;
|
||||||
|
|
||||||
|
|
||||||
obj = PyObject_GetAttrString(result, "this");
|
obj = PyObject_GetAttrString(result, "this");
|
||||||
if (PyErr_Occurred())
|
if (PyErr_Occurred())
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
PyObject *t, *v, *b;
|
PyObject *t, *v, *b;
|
||||||
PyErr_Fetch(&t, &v, &b);
|
PyErr_Fetch(&t, &v, &b);
|
||||||
printf ("calling GetModule()\n");
|
printf ("calling GetModule()\n");
|
||||||
printf ("Exception: %s\n",PyString_AsString(PyObject_Str(v)));
|
printf ("Exception: %s\n",PyString_AsString(PyObject_Str(v)));
|
||||||
printf (" : %s\n",PyString_AsString(PyObject_Str(b)));
|
printf (" : %s\n",PyString_AsString(PyObject_Str(b)));
|
||||||
|
*/
|
||||||
|
PyErr_Print();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,9 +30,9 @@ public:
|
||||||
wxString GetParameterPageName(int aPage);
|
wxString GetParameterPageName(int aPage);
|
||||||
wxArrayString GetParameterNames(int aPage);
|
wxArrayString GetParameterNames(int aPage);
|
||||||
wxArrayString GetParameterValues(int aPage);
|
wxArrayString GetParameterValues(int aPage);
|
||||||
wxString SetParameterValues(int aPage,wxArrayString& aValues);
|
wxArrayString GetParameterErrors(int aPage);
|
||||||
|
wxString SetParameterValues(int aPage,wxArrayString& aValues); //< must return "OK" or error description
|
||||||
MODULE *GetModule();
|
MODULE *GetModule();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ class FPCFootprintWizard(FootprintWizardPlugin):
|
||||||
"width":FromMM(1.5),"height":FromMM(2)},
|
"width":FromMM(1.5),"height":FromMM(2)},
|
||||||
|
|
||||||
}
|
}
|
||||||
|
self.ClearErrors()
|
||||||
|
|
||||||
def GetParameterValues(self,page_n):
|
def GetParameterValues(self,page_n):
|
||||||
name = self.GetParameterPageName(page_n)
|
name = self.GetParameterPageName(page_n)
|
||||||
|
@ -37,10 +38,40 @@ class FPCFootprintWizard(FootprintWizardPlugin):
|
||||||
pad.SetPadName(name)
|
pad.SetPadName(name)
|
||||||
return pad
|
return pad
|
||||||
|
|
||||||
def BuildFootprint(self):
|
def CheckParameters(self):
|
||||||
|
|
||||||
p = self.parameters
|
p = self.parameters
|
||||||
pads = p["Pads"]["n"]
|
pads = p["Pads"]["n"]
|
||||||
|
errors = ""
|
||||||
|
if (pads<1):
|
||||||
|
self.parameter_errors["Pads"]["n"]="Must be positive"
|
||||||
|
errors +="Pads/n has wrong value, "
|
||||||
|
p["Pads"]["n"] = int(pads) # make sure it stays as int (default is float)
|
||||||
|
|
||||||
|
pad_width = p["Pads"]["width"]
|
||||||
|
pad_height = p["Pads"]["height"]
|
||||||
|
pad_pitch = p["Pads"]["pitch"]
|
||||||
|
shl_width = p["Shield"]["width"]
|
||||||
|
shl_height = p["Shield"]["height"]
|
||||||
|
shl_to_pad = p["Shield"]["shield_to_pad"]
|
||||||
|
shl_from_top = p["Shield"]["from_top"]
|
||||||
|
|
||||||
|
return errors
|
||||||
|
|
||||||
|
def SetParameterValues(self,page,values):
|
||||||
|
print "SetParameterValues("+str(page)+","+str(values)+")"
|
||||||
|
FootprintWizardPlugin.SetParameterValues(self,page,values)
|
||||||
|
|
||||||
|
def BuildFootprint(self):
|
||||||
|
|
||||||
|
print "parameters:",self.parameters
|
||||||
|
#self.ClearErrors()
|
||||||
|
#print "errors:",self.parameter_errors
|
||||||
|
|
||||||
|
module = MODULE(None) # create a new module
|
||||||
|
self.module = module
|
||||||
|
|
||||||
|
p = self.parameters
|
||||||
|
pads = int(p["Pads"]["n"])
|
||||||
pad_width = p["Pads"]["width"]
|
pad_width = p["Pads"]["width"]
|
||||||
pad_height = p["Pads"]["height"]
|
pad_height = p["Pads"]["height"]
|
||||||
pad_pitch = p["Pads"]["pitch"]
|
pad_pitch = p["Pads"]["pitch"]
|
||||||
|
@ -52,9 +83,6 @@ class FPCFootprintWizard(FootprintWizardPlugin):
|
||||||
size_pad = wxSize(pad_width,pad_height)
|
size_pad = wxSize(pad_width,pad_height)
|
||||||
size_shld = wxSize(shl_width,shl_height)
|
size_shld = wxSize(shl_width,shl_height)
|
||||||
|
|
||||||
|
|
||||||
# create a new module
|
|
||||||
module = MODULE(None)
|
|
||||||
module.SetReference("FPC"+str(pads)) # give it a reference name
|
module.SetReference("FPC"+str(pads)) # give it a reference name
|
||||||
module.m_Reference.SetPos0(wxPointMM(-1,-2))
|
module.m_Reference.SetPos0(wxPointMM(-1,-2))
|
||||||
module.m_Reference.SetPosition(wxPointMM(-1,-2))
|
module.m_Reference.SetPosition(wxPointMM(-1,-2))
|
||||||
|
@ -84,11 +112,9 @@ class FPCFootprintWizard(FootprintWizardPlugin):
|
||||||
e.SetShape(S_SEGMENT)
|
e.SetShape(S_SEGMENT)
|
||||||
module.Add(e)
|
module.Add(e)
|
||||||
|
|
||||||
# save the PCB to disk
|
|
||||||
module.SetLibRef("FPC"+str(pads))
|
module.SetLibRef("FPC"+str(pads))
|
||||||
|
|
||||||
self.module = module
|
|
||||||
# print "Module built and set:", module
|
|
||||||
|
|
||||||
# create our footprint wizard
|
# create our footprint wizard
|
||||||
fpc_wizard = FPCFootprintWizard()
|
fpc_wizard = FPCFootprintWizard()
|
||||||
|
|
|
@ -61,6 +61,7 @@ class FootprintWizardPlugin(KiCadPlugin):
|
||||||
def defaults(self):
|
def defaults(self):
|
||||||
self.module = None
|
self.module = None
|
||||||
self.parameters = {}
|
self.parameters = {}
|
||||||
|
self.parameter_errors={}
|
||||||
self.name = "Undefined Footprint Wizard plugin"
|
self.name = "Undefined Footprint Wizard plugin"
|
||||||
self.description = ""
|
self.description = ""
|
||||||
self.image = ""
|
self.image = ""
|
||||||
|
@ -88,17 +89,51 @@ class FootprintWizardPlugin(KiCadPlugin):
|
||||||
def GetParameterValues(self,page_n):
|
def GetParameterValues(self,page_n):
|
||||||
name = self.GetParameterPageName(page_n)
|
name = self.GetParameterPageName(page_n)
|
||||||
values = self.parameters[name].values()
|
values = self.parameters[name].values()
|
||||||
return map( lambda x: str(x) , 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):
|
def SetParameterValues(self,page_n,values):
|
||||||
name = self.GetParameterPageName(pagen_n)
|
name = self.GetParameterPageName(page_n)
|
||||||
keys = self.parameters[name].values()
|
keys = self.parameters[name].keys()
|
||||||
n=0
|
n=0
|
||||||
for key in keys:
|
for key in keys:
|
||||||
self.parameters[name][key] = values[n]
|
val = self.TryConvertToFloat(values[n])
|
||||||
|
self.parameters[name][key] = val
|
||||||
|
print "[%s][%s]<="%(name,key),val
|
||||||
n+=1
|
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
|
||||||
|
|
||||||
|
|
||||||
def GetModule(self):
|
def GetModule(self):
|
||||||
self.BuildFootprint()
|
self.BuildFootprint()
|
||||||
return self.module
|
return self.module
|
||||||
|
|
Loading…
Reference in New Issue