Commit 70df1517 authored by Miguel Angel Ajo's avatar Miguel Angel Ajo

Footprint wizard, plus fixes

parent 4dc70b2f
......@@ -290,6 +290,7 @@ if (KICAD_SCRIPTING)
DEPENDS ../scripting/dlist.i
DEPENDS ../scripting/kicad.i
DEPENDS ../scripting/wx.i
DEPENDS ../scripting/kicadplugins.i
# DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/pcbnew
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 wxArrayString GetParameterNames(int aPage)=0;
virtual wxArrayString GetParameterValues(int aPage)=0;
virtual wxArrayString GetParameterErrors(int aPage)=0;
virtual wxString SetParameterValues(int aPage,wxArrayString& aValues)=0;
virtual MODULE *GetModule()=0;
void register_wizard();
......
......@@ -28,6 +28,9 @@ DIALOG_FOOTPRINT_WIZARD_LIST::DIALOG_FOOTPRINT_WIZARD_LIST( wxWindow* aParent )
m_FootprintWizard = FOOTPRINT_WIZARDS::GetWizard(0);
// 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->InsertRows(0,n_wizards,true);
......
......@@ -134,31 +134,28 @@ void FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard( wxCommandEvent& event )
* Function SelectCurrentFootprint
* 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
MODULE * module = new MODULE(NULL);
if( module )
{
module->SetPosition( wxPoint( 0, 0 ) );
// Only one fotprint allowed: remove the previous footprint (if exists)
if( oldmodule )
{
GetBoard()->Remove( oldmodule );
delete oldmodule;
}
m_footprintName = module->GetLibRef();
module->ClearFlags();
SetCurItem( NULL );
Zoom_Automatique( false );
m_canvas->Refresh( );
Update3D_Frame();
m_FootprintList->SetStringSelection( m_footprintName );
}
* */
int page = m_PageList->GetSelection();
if (page<0)
return;
int n=m_ParameterGrid->GetNumberRows();
wxArrayString arr;
for (int i=0;i<n;i++)
{
wxString val = m_ParameterGrid->GetCellValue(i,1);
arr.Add(val);
}
wxString res = m_FootprintWizard->SetParameterValues(page,arr);
ReloadFootprint();
DisplayWizardInfos();
}
......
......@@ -74,7 +74,7 @@ BEGIN_EVENT_TABLE( FOOTPRINT_WIZARD_FRAME, EDA_DRAW_FRAME )
/* listbox events */
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 )
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 PARAMLIST_WIDTH_KEY wxT( "Paramlist_width" )
......
......@@ -37,6 +37,7 @@ class wxSashLayoutWindow;
class wxListBox;
class wxSemaphore;
class wxGrid;
class wxGridEvent;
/**
......@@ -104,7 +105,6 @@ private:
void ReCreateVToolbar();
void OnLeftClick( wxDC* DC, const wxPoint& MousePos );
void ClickOnPageList( wxCommandEvent& event );
void ClickOnParameterGrid( wxCommandEvent& event );
void OnSetRelativeOffset( wxCommandEvent& event );
void GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aHotKey = 0 );
......@@ -137,7 +137,7 @@ private:
void SelectCurrentWizard( wxCommandEvent& event );
void ParametersUpdated( wxCommandEvent& event );
void ParametersUpdated( wxGridEvent& event );
......
......@@ -36,7 +36,8 @@
def GetPads(self): return self.m_Pads
def GetDrawings(self): return self.m_Drawings
def GetReferenceObj(self): return self.m_Reference
def GetValueObj(self): return self.m_Value
#def SaveToLibrary(self,filename):
# return SaveModuleToLibrary(filename,self)
......@@ -113,4 +114,4 @@ def FootprintIsWritable(lpath):
}
%}
\ No newline at end of file
%}
......@@ -186,12 +186,44 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterValues(int aPage)
return ret;
}
wxString PYTHON_FOOTPRINT_WIZARD::SetParameterValues(int aPage,wxArrayString& aValues)
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterErrors(int aPage)
{
wxString ret;
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)
{
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*/
MODULE *PyModule_to_MODULE(PyObject *obj0);
......@@ -201,14 +233,18 @@ MODULE *PYTHON_FOOTPRINT_WIZARD::GetModule()
result = CallMethod("GetModule",NULL);
if (!result) return NULL;
obj = PyObject_GetAttrString(result, "this");
if (PyErr_Occurred())
{
/*
PyObject *t, *v, *b;
PyErr_Fetch(&t, &v, &b);
printf ("calling GetModule()\n");
printf ("Exception: %s\n",PyString_AsString(PyObject_Str(v)));
printf (" : %s\n",PyString_AsString(PyObject_Str(b)));
*/
PyErr_Print();
}
......
......@@ -30,9 +30,9 @@ public:
wxString GetParameterPageName(int aPage);
wxArrayString GetParameterNames(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();
};
......
......@@ -16,6 +16,7 @@ class FPCFootprintWizard(FootprintWizardPlugin):
"width":FromMM(1.5),"height":FromMM(2)},
}
self.ClearErrors()
def GetParameterValues(self,page_n):
name = self.GetParameterPageName(page_n)
......@@ -37,10 +38,40 @@ class FPCFootprintWizard(FootprintWizardPlugin):
pad.SetPadName(name)
return pad
def CheckParameters(self):
p = self.parameters
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 = p["Pads"]["n"]
pads = int(p["Pads"]["n"])
pad_width = p["Pads"]["width"]
pad_height = p["Pads"]["height"]
pad_pitch = p["Pads"]["pitch"]
......@@ -52,9 +83,6 @@ class FPCFootprintWizard(FootprintWizardPlugin):
size_pad = wxSize(pad_width,pad_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.m_Reference.SetPos0(wxPointMM(-1,-2))
module.m_Reference.SetPosition(wxPointMM(-1,-2))
......@@ -84,11 +112,9 @@ class FPCFootprintWizard(FootprintWizardPlugin):
e.SetShape(S_SEGMENT)
module.Add(e)
# save the PCB to disk
module.SetLibRef("FPC"+str(pads))
self.module = module
# print "Module built and set:", module
# create our footprint wizard
fpc_wizard = FPCFootprintWizard()
......
......@@ -61,6 +61,7 @@ class FootprintWizardPlugin(KiCadPlugin):
def defaults(self):
self.module = None
self.parameters = {}
self.parameter_errors={}
self.name = "Undefined Footprint Wizard plugin"
self.description = ""
self.image = ""
......@@ -88,16 +89,50 @@ class FootprintWizardPlugin(KiCadPlugin):
def GetParameterValues(self,page_n):
name = self.GetParameterPageName(page_n)
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):
name = self.GetParameterPageName(pagen_n)
keys = self.parameters[name].values()
name = self.GetParameterPageName(page_n)
keys = self.parameters[name].keys()
n=0
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
# 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):
self.BuildFootprint()
......
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