Commit bf5802f1 authored by Wayne Stambaugh's avatar Wayne Stambaugh
Browse files

Removal of internal units.

* Remove internal units from BASE_SCREEN and it's derivatives.
* Remove internal units from EDA_DRAW_FRAME and it's derivatives.
* Use build time code to replace internal units conversions.
* Fix scaling bug in page layout sample window that I created in my
  last commit.
parent 6468805c
Loading
Loading
Loading
Loading
+4 −25
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#include <base_struct.h>
#include <class_base_screen.h>
#include <id.h>
#include <base_units.h>


#define CURSOR_SIZE     12      /// size of the cross cursor.
@@ -86,12 +87,6 @@ void BASE_SCREEN::InitDataPoints( const wxSize& aPageSizeIU )
}


int BASE_SCREEN::GetInternalUnits( void )
{
    return EESCHEMA_INTERNAL_UNIT;
}


double BASE_SCREEN::GetScalingFactor() const
{
    double scale = 1.0 / GetZoom();
@@ -320,30 +315,14 @@ void BASE_SCREEN::AddGrid( const wxRealPoint& size, int id )

void BASE_SCREEN::AddGrid( const wxRealPoint& size, EDA_UNITS_T aUnit, int id )
{
    double x, y;
    wxRealPoint new_size;
    GRID_TYPE new_grid;

    switch( aUnit )
    {
    case MILLIMETRES:
        x = size.x / 25.4;
        y = size.y / 25.4;
        break;

    default:
    case INCHES:
    case UNSCALED_UNITS:
        x = size.x;
        y = size.y;
        break;
    }

    new_size.x = x * GetInternalUnits();
    new_size.y = y * GetInternalUnits();

    new_size.x = From_User_Unit( aUnit, size.x );
    new_size.y = From_User_Unit( aUnit, size.y );
    new_grid.m_Id = id;
    new_grid.m_Size = new_size;

    AddGrid( new_grid );
}

+2 −2
Original line number Diff line number Diff line
@@ -167,7 +167,7 @@ void PutValueInLocalUnits( wxTextCtrl& aTextCtr, int aValue )
}


int From_User_Unit( EDA_UNITS_T aUnit, double aValue )
double From_User_Unit( EDA_UNITS_T aUnit, double aValue )
{
    double value;

@@ -187,7 +187,7 @@ int From_User_Unit( EDA_UNITS_T aUnit, double aValue )
        value = aValue;
    }

    return wxRound( value );
    return value;
}


+2 −3
Original line number Diff line number Diff line
@@ -30,9 +30,8 @@ void EDA_DRAW_FRAME::PlotWorkSheet( PLOTTER* plotter, BASE_SCREEN* screen )
    wxPoint             pos, ref;
    EDA_COLOR_T         color;

    // paper is sized in mils.  Here is a conversion factor to
    // scale mils to internal units.
    int      conv_unit = screen->GetInternalUnits() / 1000;
    // Paper is sized in mils.  Here is a conversion factor to scale mils to internal units.
    int      conv_unit = screen->MilsToIuScalar();

    wxString msg;
    wxSize   text_size;
+1 −1
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ bool DrawPageOnClipboard( EDA_DRAW_FRAME* aFrame )
    BASE_SCREEN* screen = aFrame->GetCanvas()->GetScreen();

    /* scale is the ratio resolution/internal units */
    float   scale = 82.0 / aFrame->GetInternalUnits();
    float   scale = 82.0 / 1000.0 / (double) screen->MilsToIuScalar();

    if( screen->IsBlockActive() )
    {
+28 −8
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#include <class_title_block.h>
#include <wxstruct.h>
#include <class_base_screen.h>
#include <base_units.h>          // MILS_TO_IU_SCALAR

#include <wx/valgen.h>
#include <wx/tokenzr.h>
@@ -118,10 +119,12 @@ void DIALOG_PAGES_SETTINGS::initDialog()
    // initalize page format choice box and page format list.
    // The first shows translated strings, the second contains not tralated strings
    m_paperSizeComboBox->Clear();

    for( unsigned ii = 0; ; ii++ )
    {
        if( pageFmts[ii].IsEmpty() )
            break;

        m_pageFmt.Add( pageFmts[ii] );
        m_paperSizeComboBox->Append( wxGetTranslation( pageFmts[ii] ) );
    }
@@ -251,6 +254,7 @@ void DIALOG_PAGES_SETTINGS::OnOkClick( wxCommandEvent& event )
{
    m_save_flag = false;
    SavePageSettings( event );

    if( m_save_flag )
    {
        m_modified = true;
@@ -268,9 +272,12 @@ void DIALOG_PAGES_SETTINGS::OnCancelClick( wxCommandEvent& event )
void DIALOG_PAGES_SETTINGS::OnPaperSizeChoice( wxCommandEvent& event )
{
    int idx = m_paperSizeComboBox->GetSelection();

    if( idx < 0 )
        idx = 0;

    const wxString paperType = m_pageFmt[idx];

    if( paperType.Contains( PAGE_INFO::Custom ) )
    {
        m_orientationComboBox->Enable( false );
@@ -280,14 +287,17 @@ void DIALOG_PAGES_SETTINGS::OnPaperSizeChoice( wxCommandEvent& event )
    else
    {
        m_orientationComboBox->Enable( true );

        if( paperType.Contains( wxT( "A4" ) ) && IsGOST() )
        {
            m_orientationComboBox->SetStringSelection( _( "Portrait" ) );
            m_orientationComboBox->Enable( false );
        }

        m_TextUserSizeX->Enable( false );
        m_TextUserSizeY->Enable( false );
    }

    GetPageLayoutInfoFromDialog();
    UpdatePageLayoutExample();
}
@@ -407,8 +417,10 @@ void DIALOG_PAGES_SETTINGS::SavePageSettings( wxCommandEvent& event )
    m_save_flag = true;

    int idx = m_paperSizeComboBox->GetSelection();

    if( idx < 0 )
        idx = 0;

    const wxString paperType = m_pageFmt[idx];

    if( paperType.Contains( PAGE_INFO::Custom ) )
@@ -416,6 +428,7 @@ void DIALOG_PAGES_SETTINGS::SavePageSettings( wxCommandEvent& event )
        GetCustomSizeMilsFromDialog();

        retSuccess = m_pageInfo.SetType( PAGE_INFO::Custom );

        if( retSuccess )
        {
            if( m_layout_size.x < MIN_PAGE_SIZE || m_layout_size.y < MIN_PAGE_SIZE ||
@@ -432,6 +445,7 @@ limits\n%.1f - %.1f %s!\nSelect another custom paper size?" ),
                    m_save_flag = false;
                    return;
                }

                m_layout_size.x = Clamp( MIN_PAGE_SIZE, m_layout_size.x, MAX_PAGE_SIZE );
                m_layout_size.y = Clamp( MIN_PAGE_SIZE, m_layout_size.y, MAX_PAGE_SIZE );
            }
@@ -595,6 +609,7 @@ void DIALOG_PAGES_SETTINGS::UpdatePageLayoutExample()
    }

    m_page_bitmap = new wxBitmap( lyWidth + 1, lyHeight + 1 );

    if( m_page_bitmap->IsOk() )
    {
        // Save current clip box and temporary expand it.
@@ -602,7 +617,8 @@ void DIALOG_PAGES_SETTINGS::UpdatePageLayoutExample()
        m_Parent->GetCanvas()->SetClipBox( EDA_RECT( wxPoint( 0, 0 ),
                                                     wxSize( INT_MAX / 2, INT_MAX / 2 ) ) );
        // Calculate layout preview scale.
        int appScale = m_Parent->GetInternalUnits() / 1000;
        int appScale = MILS_TO_IU_SCALAR;

        double scaleW = (double) lyWidth  / clamped_layout_size.x / appScale;
        double scaleH = (double) lyHeight / clamped_layout_size.y / appScale;

@@ -630,7 +646,7 @@ void DIALOG_PAGES_SETTINGS::UpdatePageLayoutExample()

        m_Parent->TraceWorkSheet( (wxDC*) &memDC, dummySize, pointLeftTop, pointRightBottom,
                                  emptyString, emptyString, m_tb, m_Screen->m_NumberOfScreen,
                                  m_Screen->m_ScreenNumber, 1, LIGHTGRAY, RED );
                                  m_Screen->m_ScreenNumber, 1, appScale, LIGHTGRAY, RED );

        memDC.SelectObject( wxNullBitmap );
        m_PageLayoutExampleBitmap->SetBitmap( *m_page_bitmap );
@@ -648,14 +664,17 @@ void DIALOG_PAGES_SETTINGS::UpdatePageLayoutExample()
void DIALOG_PAGES_SETTINGS::GetPageLayoutInfoFromDialog()
{
    int idx = m_paperSizeComboBox->GetSelection();

    if( idx < 0 )
        idx = 0;

    const wxString paperType = m_pageFmt[idx];

    // here we assume translators will keep original paper size spellings
    if( paperType.Contains( PAGE_INFO::Custom ) )
    {
        GetCustomSizeMilsFromDialog();

        if( m_layout_size.x && m_layout_size.y )
        {
            if( m_layout_size.x < m_layout_size.y )
@@ -687,6 +706,7 @@ void DIALOG_PAGES_SETTINGS::GetPageLayoutInfoFromDialog()
        };

        unsigned i;

        for( i=0;  i < DIM( papers );  ++i )
        {
            if( paperType.Contains( *papers[i] ) )
Loading