From 9259b21ffae579644c06734563614d83343777ce Mon Sep 17 00:00:00 2001 From: Miguel Angel Ajo Date: Mon, 23 Jul 2012 00:23:17 +0200 Subject: [PATCH] Footprint wizard converts from user units to internal units back and forth, so user can type in mm or mils now --- common/base_units.cpp | 9 +++ include/base_units.h | 14 +++- pcbnew/class_footprint_wizard.h | 9 +++ pcbnew/footprint_wizard.cpp | 22 ++++++- pcbnew/footprint_wizard_frame.cpp | 66 +++++++++++++++---- pcbnew/scripting/pcbnew_footprint_wizards.cpp | 41 ++++++++++++ pcbnew/scripting/pcbnew_footprint_wizards.h | 1 + .../scripting/plugins/fpc_footprint_wizard.py | 37 +++++------ 8 files changed, 164 insertions(+), 35 deletions(-) diff --git a/common/base_units.cpp b/common/base_units.cpp index 2b6bd7ecf6..bb6e4e6fdd 100644 --- a/common/base_units.cpp +++ b/common/base_units.cpp @@ -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; diff --git a/include/base_units.h b/include/base_units.h index 790025fff8..3a2d22aafa 100644 --- a/include/base_units.h +++ b/include/base_units.h @@ -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 diff --git a/pcbnew/class_footprint_wizard.h b/pcbnew/class_footprint_wizard.h index 7e0e3bf347..f675ad8e04 100644 --- a/pcbnew/class_footprint_wizard.h +++ b/pcbnew/class_footprint_wizard.h @@ -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 diff --git a/pcbnew/footprint_wizard.cpp b/pcbnew/footprint_wizard.cpp index 6509f61b26..6e2df7d7ae 100644 --- a/pcbnew/footprint_wizard.cpp +++ b/pcbnew/footprint_wizard.cpp @@ -18,6 +18,7 @@ #include "footprint_wizard_frame.h" #include #include +#include #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;iGetCellValue(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); diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp index d795d85816..869789814f 100644 --- a/pcbnew/footprint_wizard_frame.cpp +++ b/pcbnew/footprint_wizard_frame.cpp @@ -47,6 +47,7 @@ #include #include +#include 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;iSetCellValue( 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; + } diff --git a/pcbnew/scripting/pcbnew_footprint_wizards.cpp b/pcbnew/scripting/pcbnew_footprint_wizards.cpp index d0b6dbaeeb..87494a53c0 100644 --- a/pcbnew/scripting/pcbnew_footprint_wizards.cpp +++ b/pcbnew/scripting/pcbnew_footprint_wizards.cpp @@ -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