Commit 9259b21f authored by Miguel Angel Ajo's avatar Miguel Angel Ajo

Footprint wizard converts from user units to internal units back and forth, so...

Footprint wizard converts from user units to internal units back and forth, so user can type in mm or mils now
parent 894e6eb5
......@@ -245,6 +245,15 @@ int ReturnValueFromString( EDA_UNITS_T aUnits, const wxString& aTextValue )
}
int ReturnValueFromString( const wxString& aTextValue )
{
int value;
value = ReturnValueFromString( g_UserUnit, aTextValue);
return value;
}
int ReturnValueFromTextCtrl( const wxTextCtrl& aTextCtr )
{
int value;
......
......@@ -108,7 +108,7 @@ void PutValueInLocalUnits( wxTextCtrl& aTextCtr, int aValue );
double From_User_Unit( EDA_UNITS_T aUnit, double aValue );
/**
* Function ReturnValueFromeString
* Function ReturnValueFromString
* converts \a aTextValue in \a aUnits to internal units used by the application.
*
* @param aUnits The units of \a aTextValue.
......@@ -117,6 +117,18 @@ double From_User_Unit( EDA_UNITS_T aUnit, double aValue );
*/
int ReturnValueFromString( EDA_UNITS_T aUnits, const wxString& aTextValue );
/**
* Function ReturnValueFromString
* converts \a aTextValue in \a aUnits to internal units used by the application,
* unit type will be obtained from g_UserUnit.
*
* @param aTextValue A reference to a wxString object containing the string to convert.
* @return The string from Value, according to units (inch, mm ...) for display,
*/
int ReturnValueFromString( const wxString& aTextValue );
/**
* Convert the number Value in a string according to the internal units
* and the selected unit (g_UserUnit) and put it in the wxTextCtrl TextCtrl
......
......@@ -57,6 +57,15 @@ public:
*/
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;
/**
* Function GetParameterValues
* @param aPage is the page we want the parameter values of
......
......@@ -18,6 +18,7 @@
#include "footprint_wizard_frame.h"
#include <wildcards_and_files_ext.h>
#include <dialogs/dialog_footprint_wizard_list.h>
#include <base_units.h>
#define NEXT_PART 1
#define NEW_PART 0
......@@ -153,11 +154,28 @@ void FOOTPRINT_WIZARD_FRAME::ParametersUpdated( wxGridEvent& event )
int n=m_ParameterGrid->GetNumberRows();
wxArrayString arr;
wxArrayString ptList = m_FootprintWizard->GetParameterTypes(page);
for (int i=0;i<n;i++)
{
wxString val = m_ParameterGrid->GetCellValue(i,1);
arr.Add(val);
wxString value = m_ParameterGrid->GetCellValue(i,1);
// if this parameter is expected to be an internal
// unit convert it back from the user format
if (ptList[i]==wxT("IU"))
{
double dValue;
value.ToDouble(&dValue);
// convert from mils to inches where it's needed
if (g_UserUnit==INCHES) dValue = dValue / 1000.0;
dValue = From_User_Unit(g_UserUnit,dValue);
value.Printf(wxT("%lf"),dValue);
}
arr.Add(value);
}
wxString res = m_FootprintWizard->SetParameterValues(page,arr);
......
......@@ -47,6 +47,7 @@
#include <hotkeys.h>
#include <wildcards_and_files_ext.h>
#include <base_units.h>
BEGIN_EVENT_TABLE( FOOTPRINT_WIZARD_FRAME, EDA_DRAW_FRAME )
......@@ -177,9 +178,11 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( wxWindow* parent, wxSemaphore* s
m_ParameterGridWindow->SetSashVisible( wxSASH_RIGHT, true );
m_ParameterGridWindow->SetExtraBorderSize( EXTRA_BORDER_SIZE );
m_ParameterGrid = new wxGrid(m_ParameterGridWindow,ID_FOOTPRINT_WIZARD_PARAMETER_LIST,
m_ParameterGrid = new wxGrid(m_ParameterGridWindow,
ID_FOOTPRINT_WIZARD_PARAMETER_LIST,
wxPoint(0,0),wxDefaultSize);
printf("pws.x=%d pws.y=%d\n",m_ParameterGridSize.x, m_ParameterGridSize.y);
ReCreatePageList();
DisplayWizardInfos();
......@@ -239,7 +242,7 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( wxWindow* parent, wxSemaphore* s
pane.MinSize(wxSize(m_ParameterGridSize.x, -1));
m_auimgr.Update();
// Now Drawpanel is sized, we can use BestZoom to show the component (if any)
#ifdef USE_WX_GRAPHICS_CONTEXT
GetScreen()->SetZoom( BestZoom() );
......@@ -390,34 +393,74 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateParameterList()
m_ParameterGrid->ClearGrid();
// Columns
m_ParameterGrid->AutoSizeColumns();
m_ParameterGrid->SetColLabelSize( 20 );
m_ParameterGrid->SetColLabelValue( 0, _("Parameter") );
m_ParameterGrid->SetColLabelValue( 1, _("Value") );
m_ParameterGrid->SetColLabelValue( 2, _("Units") );
m_ParameterGrid->SetColLabelAlignment( wxALIGN_LEFT, wxALIGN_CENTRE );
// Rows
m_ParameterGrid->AutoSizeRows();
m_ParameterGrid->EnableDragRowSize( true );
m_ParameterGrid->SetRowLabelSize( 1 );
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);
m_ParameterGrid->CreateGrid(fpList.size(),2);
// Dimension the wxGrid
m_ParameterGrid->CreateGrid(fpList.size(),3);
for (unsigned int i=0;i<fpList.size();i++)
{
m_ParameterGrid->SetCellValue( i, 0, fpList[i] );
wxString name,value,units;
name = fpList[i];
value = fvList[i];
m_ParameterGrid->SetCellValue( i, 0, name);
m_ParameterGrid->SetReadOnly( i, 0 );
m_ParameterGrid->SetCellValue( i, 1 , fvList[i] );
if (ptList[i]==wxT("IU"))
{
// We are handling internal units, so convert them to the current
// system selected units and store into value.
double dValue;
value.ToDouble(&dValue);
dValue = To_User_Unit(g_UserUnit,dValue);
if (g_UserUnit==INCHES) // we convert inches into mils for more detail
{
dValue = dValue*1000.0;
units = wxT("mils");
}
else if (g_UserUnit==MILLIMETRES)
{
units = wxT("mm");
}
value.Printf(wxT("%lf"),dValue);
}
else if (ptList[i]==wxT("UNITS")) // 1,2,3,4,5 ... N
{
units = wxT("");
}
m_ParameterGrid->SetCellValue( i, 1 , value );
m_ParameterGrid->SetCellValue( i, 2 , units );
m_ParameterGrid->SetReadOnly( i, 2 );
}
m_ParameterGrid->AutoSizeColumns();
......@@ -452,7 +495,7 @@ void FOOTPRINT_WIZARD_FRAME::LoadSettings( )
cfg = wxGetApp().GetSettings();
m_PageListSize.x = 150; // default width of libs list
m_ParameterGridSize.x = 250; // default width of component list
m_ParameterGridSize.x = 350; // default width of component list
cfg->Read( PARTLIST_WIDTH_KEY , &m_PageListSize.x );
cfg->Read( PARAMLIST_WIDTH_KEY, &m_ParameterGridSize.x );
......@@ -463,6 +506,7 @@ void FOOTPRINT_WIZARD_FRAME::LoadSettings( )
if ( m_ParameterGridSize.x > m_FrameSize.x/2 )
m_ParameterGridSize.x = m_FrameSize.x/2;
}
......
......@@ -170,10 +170,51 @@ wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterNames(int aPage)
arglist = Py_BuildValue("(i)", aPage);
ret = CallRetArrayStrMethod("GetParameterNames",arglist);
Py_DECREF(arglist);
for (unsigned i=0;i<ret.GetCount();i++)
{
wxString rest;
wxString item = ret[i];
if (item.StartsWith(wxT("*"),&rest))
{
ret[i]=rest;
}
}
return ret;
}
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterTypes(int aPage)
{
PyObject *arglist;
wxArrayString ret;
arglist = Py_BuildValue("(i)", aPage);
ret = CallRetArrayStrMethod("GetParameterNames",arglist);
Py_DECREF(arglist);
for (unsigned i=0;i<ret.GetCount();i++)
{
wxString rest;
wxString item = ret[i];
if (item.StartsWith(wxT("*"),&rest))
{
ret[i]=wxT("UNITS"); /* units */
}
else
{
ret[i]=wxT("IU"); /* internal units */
}
}
return ret;
}
wxArrayString PYTHON_FOOTPRINT_WIZARD::GetParameterValues(int aPage)
{
PyObject *arglist;
......
......@@ -29,6 +29,7 @@ public:
int GetNumParameterPages();
wxString GetParameterPageName(int aPage);
wxArrayString GetParameterNames(int aPage);
wxArrayString GetParameterTypes(int aPage);
wxArrayString GetParameterValues(int aPage);
wxArrayString GetParameterErrors(int aPage);
wxString SetParameterValues(int aPage,wxArrayString& aValues); //< must return "OK" or error description
......
......@@ -9,26 +9,22 @@ class FPCFootprintWizard(FootprintWizardPlugin):
self.description = "FPC Footprint Wizard"
self.parameters = {
"Pads":
{"n":40,"pitch":FromMM(0.5),
"width":FromMM(0.25),"height":FromMM(1.6)},
{"*n":40, # not internal units preceded by "*"
"pitch": FromMM(0.5),
"width": FromMM(0.25),
"height": FromMM(1.6)},
"Shield":
{"shield_to_pad":FromMM(1.6),"from_top":FromMM(1.3),
"width":FromMM(1.5),"height":FromMM(2)},
{"shield_to_pad": FromMM(1.6),
"from_top": FromMM(1.3),
"width": FromMM(1.5),
"height": FromMM(2)},
}
self.ClearErrors()
def GetParameterValues(self,page_n):
name = self.GetParameterPageName(page_n)
values = self.parameters[name].values()
str_values = map( lambda x: str(x) , values)
print values,str_values
return str_values
# build a rectangular pad
def smdRectPad(self,module,size,pos,name):
pad = D_PAD(module)
# print "smdRectPad( size=",size,"pos=",pos,"name=",name,")"
pad.SetSize(size)
pad.SetShape(PAD_RECT)
pad.SetAttribute(PAD_SMD)
......@@ -37,10 +33,11 @@ class FPCFootprintWizard(FootprintWizardPlugin):
pad.SetPosition(pos)
pad.SetPadName(name)
return pad
# This method checks the parameters provided to wizard and set errors
def CheckParameters(self):
p = self.parameters
pads = p["Pads"]["n"]
pads = p["Pads"]["*n"]
errors = ""
if (pads<1):
self.parameter_errors["Pads"]["n"]="Must be positive"
......@@ -57,12 +54,10 @@ class FPCFootprintWizard(FootprintWizardPlugin):
return errors
def SetParameterValues(self,page,values):
print "SetParameterValues("+str(page)+","+str(values)+")"
FootprintWizardPlugin.SetParameterValues(self,page,values)
# build the footprint from parameters
def BuildFootprint(self):
print "parameters:",self.parameters
#self.ClearErrors()
#print "errors:",self.parameter_errors
......@@ -71,7 +66,7 @@ class FPCFootprintWizard(FootprintWizardPlugin):
self.module = module
p = self.parameters
pads = int(p["Pads"]["n"])
pads = int(p["Pads"]["*n"])
pad_width = p["Pads"]["width"]
pad_height = p["Pads"]["height"]
pad_pitch = p["Pads"]["pitch"]
......
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