From bf5802f1f74a6d0753c098bb921ec353b00d433d Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Mon, 16 Apr 2012 19:31:29 -0400 Subject: [PATCH] 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. --- common/base_screen.cpp | 29 +++----------------- common/base_units.cpp | 4 +-- common/common_plot_functions.cpp | 5 ++-- common/copy_to_clipboard.cpp | 2 +- common/dialogs/dialog_page_settings.cpp | 36 +++++++++++++++++++------ common/drawframe.cpp | 1 - eeschema/dialogs/dialog_SVG_print.cpp | 3 ++- include/base_units.h | 2 +- include/class_base_screen.h | 12 ++++----- include/class_pcb_screen.h | 3 +-- include/wxstruct.h | 6 ----- pcbnew/basepcbframe.cpp | 1 - pcbnew/classpcb.cpp | 8 ++++-- pcbnew/dialogs/dialog_SVG_print.cpp | 9 ++++++- pcbnew/dialogs/dialog_design_rules.cpp | 14 +++++----- pcbnew/pcbframe.cpp | 2 -- pcbnew/set_grid.cpp | 4 --- 17 files changed, 68 insertions(+), 73 deletions(-) diff --git a/common/base_screen.cpp b/common/base_screen.cpp index 89c757134b..17dca59278 100644 --- a/common/base_screen.cpp +++ b/common/base_screen.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #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 ); } diff --git a/common/base_units.cpp b/common/base_units.cpp index 985912e708..d020791fd7 100644 --- a/common/base_units.cpp +++ b/common/base_units.cpp @@ -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; } diff --git a/common/common_plot_functions.cpp b/common/common_plot_functions.cpp index cd140a1ae7..b74ac9f8ea 100644 --- a/common/common_plot_functions.cpp +++ b/common/common_plot_functions.cpp @@ -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; diff --git a/common/copy_to_clipboard.cpp b/common/copy_to_clipboard.cpp index e09e2a83a1..973768033f 100644 --- a/common/copy_to_clipboard.cpp +++ b/common/copy_to_clipboard.cpp @@ -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() ) { diff --git a/common/dialogs/dialog_page_settings.cpp b/common/dialogs/dialog_page_settings.cpp index e2421ac537..7adb5c73b0 100644 --- a/common/dialogs/dialog_page_settings.cpp +++ b/common/dialogs/dialog_page_settings.cpp @@ -26,7 +26,7 @@ */ #include -#include // DIM() +#include // DIM() #include #include #include @@ -34,6 +34,7 @@ #include #include #include +#include // MILS_TO_IU_SCALAR #include #include @@ -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] ) ); } @@ -137,8 +140,8 @@ void DIALOG_PAGES_SETTINGS::initDialog() msg.Printf( format, m_Screen->m_ScreenNumber ); m_TextSheetNumber->SetLabel( msg ); #else - m_TextSheetCount->Show(false); - m_TextSheetNumber->Show(false); + m_TextSheetCount->Show( false ); + m_TextSheetNumber->Show( false ); #endif m_pageInfo = m_Parent->GetPageSettings(); @@ -251,10 +254,11 @@ void DIALOG_PAGES_SETTINGS::OnOkClick( wxCommandEvent& event ) { m_save_flag = false; SavePageSettings( event ); + if( m_save_flag ) { - m_modified = true; - Close( true ); + m_modified = true; + Close( 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] ) ) diff --git a/common/drawframe.cpp b/common/drawframe.cpp index 14ca16430d..26bf5767b0 100644 --- a/common/drawframe.cpp +++ b/common/drawframe.cpp @@ -110,7 +110,6 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( wxWindow* father, int idtype, const wxString& ti m_snapToGrid = true; // Internal units per inch: = 1000 for schema, = 10000 for PCB - m_internalUnits = EESCHEMA_INTERNAL_UNIT; minsize.x = 470; minsize.y = 350 + m_MsgFrameHeight; diff --git a/eeschema/dialogs/dialog_SVG_print.cpp b/eeschema/dialogs/dialog_SVG_print.cpp index ed26eb9ec1..4dfb675f2e 100644 --- a/eeschema/dialogs/dialog_SVG_print.cpp +++ b/eeschema/dialogs/dialog_SVG_print.cpp @@ -215,7 +215,7 @@ bool DIALOG_SVG_PRINT::DrawSVGPage( EDA_DRAW_FRAME* frame, LOCALE_IO toggle; - float dpi = (float) frame->GetInternalUnits(); + float dpi = 1000.0; KicadSVGFileDC dc( FullFileName, sheetSize.x, sheetSize.y, dpi ); EDA_RECT tmp = *panel->GetClipBox(); @@ -227,6 +227,7 @@ bool DIALOG_SVG_PRINT::DrawSVGPage( EDA_DRAW_FRAME* frame, wxSize( 0x7FFFFF0, 0x7FFFFF0 ) ) ); screen->m_IsPrinting = true; + if( frame->IsType( SCHEMATIC_FRAME ) ) screen->Draw( panel, &dc, GR_COPY ); diff --git a/include/base_units.h b/include/base_units.h index 99f0301808..0d505d81ec 100644 --- a/include/base_units.h +++ b/include/base_units.h @@ -96,7 +96,7 @@ void PutValueInLocalUnits( wxTextCtrl& aTextCtr, int aValue ); /** * Return in internal units the value "val" given in inch or mm */ -int From_User_Unit( EDA_UNITS_T aUnit, double aValue ); +double From_User_Unit( EDA_UNITS_T aUnit, double aValue ); /** * Function ReturnValueFromeString diff --git a/include/class_base_screen.h b/include/class_base_screen.h index 3c8abc128f..e3cac015de 100644 --- a/include/class_base_screen.h +++ b/include/class_base_screen.h @@ -158,14 +158,14 @@ public: wxString GetFileName() const { return m_fileName; } /** - * Function GetInternalUnits - * @return the screen units scalar. + * Function MilsToIuScalar + * returns the scalar required to convert mils to internal units. * - * Default implementation returns scalar used for schematic screen. The - * internal units used by the schematic screen is 1 mil (0.001"). Override - * this in derived classes that require internal units other than 1 mil. + * @note This is a temporary hack until the derived objects SCH_SCREEN and PCB_SCREEN + * no longer need to be derived from BASE_SCREEN. I does allow removal of the + * obsolete GetInternalUnits function. */ - virtual int GetInternalUnits( void ); + virtual int MilsToIuScalar() { return 1; } /** * Function GetCrossHairPosition diff --git a/include/class_pcb_screen.h b/include/class_pcb_screen.h index 46971bf64c..c7381f32af 100644 --- a/include/class_pcb_screen.h +++ b/include/class_pcb_screen.h @@ -37,7 +37,7 @@ public: void SetPreviousZoom(); void SetLastZoom(); - virtual int GetInternalUnits(); + virtual int MilsToIuScalar(); /** * Function GetCurItem @@ -57,7 +57,6 @@ public: */ void SetCurItem( BOARD_ITEM* aItem ) { BASE_SCREEN::SetCurItem( (EDA_ITEM*)aItem ); } - /* full undo redo management : */ // use BASE_SCREEN::ClearUndoRedoList() diff --git a/include/wxstruct.h b/include/wxstruct.h index 3439658654..0638ae84e2 100644 --- a/include/wxstruct.h +++ b/include/wxstruct.h @@ -387,10 +387,6 @@ protected: /// The area to draw on. EDA_DRAW_PANEL* m_canvas; - /// Internal units count that is equivalent to 1 inch. Set to 1000 (0.001") for - /// schematic drawing and 10000 (0.0001") for PCB drawing. - int m_internalUnits; - /// Tool ID of previously active draw tool bar button. int m_lastDrawToolId; @@ -477,8 +473,6 @@ public: void SetShowBorderAndTitleBlock( bool aShow ) { m_showBorderAndTitleBlock = aShow; } - int GetInternalUnits() const { return m_internalUnits; } - EDA_DRAW_PANEL* GetCanvas() { return m_canvas; } virtual wxString GetScreenDesc(); diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index 3f0713e4e8..8e25126426 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -82,7 +82,6 @@ PCB_BASE_FRAME::PCB_BASE_FRAME( wxWindow* father, long style) : EDA_DRAW_FRAME( father, idtype, title, pos, size, style ) { - m_internalUnits = PCB_INTERNAL_UNIT; // Internal unit = 1/10000 inch m_Pcb = NULL; m_DisplayPadFill = true; // How to draw pads diff --git a/pcbnew/classpcb.cpp b/pcbnew/classpcb.cpp index 2fe09eecbc..b15e236ad4 100644 --- a/pcbnew/classpcb.cpp +++ b/pcbnew/classpcb.cpp @@ -125,9 +125,13 @@ PCB_SCREEN::~PCB_SCREEN() } -int PCB_SCREEN::GetInternalUnits() +int PCB_SCREEN::MilsToIuScalar() { - return PCB_INTERNAL_UNIT; +#if defined( USE_PCBNEW_NANOMETRES ) + return 25400; +#else + return 10; +#endif } diff --git a/pcbnew/dialogs/dialog_SVG_print.cpp b/pcbnew/dialogs/dialog_SVG_print.cpp index 8b1196b269..19eea912fa 100644 --- a/pcbnew/dialogs/dialog_SVG_print.cpp +++ b/pcbnew/dialogs/dialog_SVG_print.cpp @@ -239,7 +239,14 @@ bool DIALOG_SVG_PRINT::DrawPage( const wxString& FullFileName, screen->m_StartVisu.x = screen->m_StartVisu.y = 0; screen->SetScalingFactor( 1.0 ); - float dpi = (float)m_Parent->GetInternalUnits(); + + float dpi; + +#if defined( USE_PCBNEW_NANOMETRES ) + dpi = 25.4e6; +#else + dpi = 10000.0; +#endif EDA_DRAW_PANEL* panel = m_Parent->GetCanvas(); diff --git a/pcbnew/dialogs/dialog_design_rules.cpp b/pcbnew/dialogs/dialog_design_rules.cpp index fb4f6b8827..568d22149c 100644 --- a/pcbnew/dialogs/dialog_design_rules.cpp +++ b/pcbnew/dialogs/dialog_design_rules.cpp @@ -473,7 +473,7 @@ void DIALOG_DESIGN_RULES::InitializeRulesSelectionBoxes() /* Initialize the rules list from board */ -static void class2gridRow( wxGrid* grid, int row, NETCLASS* nc, int units ) +static void class2gridRow( wxGrid* grid, int row, NETCLASS* nc ) { wxString msg; @@ -515,7 +515,7 @@ void DIALOG_DESIGN_RULES::InitRulesList() } // enter the Default NETCLASS. - class2gridRow( m_grid, 0, netclasses.GetDefault(), m_Parent->GetInternalUnits() ); + class2gridRow( m_grid, 0, netclasses.GetDefault() ); // enter others netclasses int row = 1; @@ -523,12 +523,12 @@ void DIALOG_DESIGN_RULES::InitRulesList() { NETCLASS* netclass = i->second; - class2gridRow( m_grid, row, netclass, m_Parent->GetInternalUnits() ); + class2gridRow( m_grid, row, netclass ); } } -static void gridRow2class( wxGrid* grid, int row, NETCLASS* nc, int units ) +static void gridRow2class( wxGrid* grid, int row, NETCLASS* nc ) { #define MYCELL( col ) \ ReturnValueFromString( g_UserUnit, grid->GetCellValue( row, col ) ) @@ -552,7 +552,7 @@ void DIALOG_DESIGN_RULES::CopyRulesListToBoard() netclasses.Clear(); // Copy the default NetClass: - gridRow2class( m_grid, 0, netclasses.GetDefault(), m_Parent->GetInternalUnits() ); + gridRow2class( m_grid, 0, netclasses.GetDefault() ); // Copy other NetClasses : for( int row = 1; row < m_grid->GetNumberRows(); ++row ) @@ -565,13 +565,13 @@ void DIALOG_DESIGN_RULES::CopyRulesListToBoard() // Should not occur because OnAddNetclassClick() tests for existing NetClass names wxString msg; msg.Printf( wxT( "CopyRulesListToBoard(): The NetClass \"%s\" already exists. Skip" ), - GetChars( m_grid->GetRowLabelValue( row ) ) ); + GetChars( m_grid->GetRowLabelValue( row ) ) ); wxMessageBox( msg ); delete nc; continue; } - gridRow2class( m_grid, row, nc, m_Parent->GetInternalUnits() ); + gridRow2class( m_grid, row, nc ); } // Now read all nets and push them in the corresponding netclass net buffer diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index c774239236..ed8e9d788d 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -315,8 +315,6 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( wxWindow* parent, const wxString& title, icon.CopyFromBitmap( KiBitmap( icon_pcbnew_xpm ) ); SetIcon( icon ); - m_internalUnits = PCB_INTERNAL_UNIT; // Unites internes = 1/10000 inch - SetScreen( new PCB_SCREEN( GetPageSettings().GetSizeIU() ) ); // PCB drawings start in the upper left corner. diff --git a/pcbnew/set_grid.cpp b/pcbnew/set_grid.cpp index 1a230ad4ee..0ed158024a 100644 --- a/pcbnew/set_grid.cpp +++ b/pcbnew/set_grid.cpp @@ -16,9 +16,6 @@ class DIALOG_SET_GRID : public DIALOG_SET_GRID_BASE { -public: - int m_internalUnits; - public: DIALOG_SET_GRID( wxWindow* parent, const wxPoint& pos ); ~DIALOG_SET_GRID() { } @@ -41,7 +38,6 @@ void PCB_BASE_FRAME::InstallGridFrame( const wxPoint& pos ) { DIALOG_SET_GRID dlg( this, pos ); - dlg.m_internalUnits = m_internalUnits; dlg.SetGridUnits( m_UserGridUnit ); dlg.SetGridSize( m_UserGridSize ); dlg.SetGridOrigin( GetScreen()->m_GridOrigin );