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

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
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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;
+13 −1
Original line number Diff line number Diff line
@@ -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
+9 −0
Original line number Diff line number Diff line
@@ -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
+20 −2
Original line number Diff line number Diff line
@@ -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);
+55 −11
Original line number Diff line number Diff line
@@ -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();
@@ -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;
     
}


Loading