From fa3ebc40432c95a991e64db1304405ce96f39098 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 25 Apr 2012 21:33:24 +0200 Subject: [PATCH] Define MM_TO_IU_SCALING_FACTOR (scaling factor from mm to internal units) only in convert_to_biu.h Other scaling factors (MILS_TO_IU_SCALING_FACTOR and DECIMILS_TO_IU_SCALING_FACTOR) also defined only in convert_to_biu.h. Allows different scaling value for Gerbview. Needs more tests. --- common/CMakeLists.txt | 2 -- common/base_units.cpp | 24 ++++--------- common/dialogs/dialog_page_settings.cpp | 3 +- common/eda_text.cpp | 6 +--- cvpcb/CMakeLists.txt | 1 + eeschema/dialogs/dialog_SVG_print.cpp | 2 +- .../dialogs/dialog_print_using_printer.cpp | 2 +- eeschema/eeredraw.cpp | 2 +- eeschema/schframe.cpp | 2 +- gerbview/CMakeLists.txt | 4 ++- gerbview/dcode.cpp | 5 +-- gerbview/draw_gerber_screen.cpp | 2 +- gerbview/excellon_read_drill_file.cpp | 2 +- gerbview/gerbview_frame.cpp | 13 ++++--- gerbview/gerbview_frame.h | 12 +++---- gerbview/onleftclick.cpp | 4 +-- gerbview/onrightclick.cpp | 4 +-- gerbview/options.cpp | 16 +++------ gerbview/rs274_read_XY_and_IJ_coordinates.cpp | 32 ++++++++--------- gerbview/rs274x.cpp | 19 +++++------ include/base_units.h | 14 +------- include/common.h | 16 +++------ include/convert_to_biu.h | 34 +++++++++++++++---- pcbnew/CMakeLists.txt | 5 ++- pcbnew/classpcb.cpp | 23 ++++--------- pcbnew/dialogs/dialog_SVG_print.cpp | 2 +- pcbnew/legacy_plugin.cpp | 9 ++--- pcbnew/printout_controler.cpp | 11 +++--- pcbnew/specctra_export.cpp | 10 ++---- pcbnew/tracepcb.cpp | 4 +-- polygon/PolyLine.cpp | 7 ++-- polygon/PolyLine.h | 3 +- 32 files changed, 126 insertions(+), 169 deletions(-) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 7f8b5ded35..4841471478 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -83,7 +83,6 @@ add_library(common STATIC ${COMMON_SRCS}) set(PCB_COMMON_SRCS base_screen.cpp - base_units.cpp eda_text.cpp class_page_info.cpp pcbcommon.cpp @@ -120,7 +119,6 @@ set(PCB_COMMON_SRCS ../pcbnew/legacy_plugin.cpp ../pcbnew/kicad_plugin.cpp pcb_plot_params_keywords.cpp - dialogs/dialog_page_settings.cpp ) diff --git a/common/base_units.cpp b/common/base_units.cpp index d020791fd7..e8f19ba119 100644 --- a/common/base_units.cpp +++ b/common/base_units.cpp @@ -40,25 +40,13 @@ #include -#if defined( PCBNEW ) -#if defined( USE_PCBNEW_NANOMETRES ) -#define IU_TO_MM( x ) ( x * 1e-6 ) -#define IU_TO_IN( x ) ( ( x * 1e-6 ) / 25.4 ) -#define MM_TO_IU( x ) ( x * 1e6 ) -#define IN_TO_IU( x ) ( ( x * 25.4 ) * 1e6 ) +#if defined( PCBNEW ) || defined( CVPCB ) || defined( EESCHEMA ) +#define IU_TO_MM( x ) ( x / MM_TO_IU_SCALING_FACTOR ) +#define IU_TO_IN( x ) ( x / MILS_TO_IU_SCALING_FACTOR / 1000 ) +#define MM_TO_IU( x ) ( x * MM_TO_IU_SCALING_FACTOR ) +#define IN_TO_IU( x ) ( x * MILS_TO_IU_SCALING_FACTOR * 1000 ) #else -#define IU_TO_MM( x ) ( ( x * 0.0001 ) * 25.4 ) -#define IU_TO_IN( x ) ( x * 0.0001 ) -#define MM_TO_IU( x ) ( ( x / 25.4 ) * 10000.0 ) -#define IN_TO_IU( x ) ( x * 10000.0 ) -#endif -#elif defined( EESCHEMA ) -#define IU_TO_MM( x ) ( ( x * 0.001 ) * 25.4 ) -#define IU_TO_IN( x ) ( x * 0.001 ) -#define MM_TO_IU( x ) ( ( x / 25.4 ) * 1000.0 ) -#define IN_TO_IU( x ) ( x * 1000.0 ) -#else -#error "Cannot resolve internal units due to no definition of EESCHEMA or PCBNEW." +#error "Cannot resolve internal units due to no definition of EESCHEMA, CVPCB or PCBNEW." #endif diff --git a/common/dialogs/dialog_page_settings.cpp b/common/dialogs/dialog_page_settings.cpp index a5cee66249..c8c32d5523 100644 --- a/common/dialogs/dialog_page_settings.cpp +++ b/common/dialogs/dialog_page_settings.cpp @@ -34,7 +34,6 @@ #include #include #include -#include // MILS_TO_IU_SCALAR #include #include @@ -617,7 +616,7 @@ 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 = MILS_TO_IU_SCALAR; + int appScale = m_Screen->MilsToIuScalar(); double scaleW = (double) lyWidth / clamped_layout_size.x / appScale; double scaleH = (double) lyHeight / clamped_layout_size.y / appScale; diff --git a/common/eda_text.cpp b/common/eda_text.cpp index 546a5deecf..1ade6a903c 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -37,11 +37,7 @@ // Conversion to application internal units defined at build time. #if defined( PCBNEW ) #include -#if defined( USE_PCBNEW_NANOMETRES ) -#define MILS_TO_IU( x ) ( x * 25400 ); -#else -#define MILS_TO_IU( x ) ( x * 10 ) -#endif +#define MILS_TO_IU( x ) ( x * MILS_TO_IU_SCALING_FACTOR ); #elif defined( EESCHEMA ) #include #define MILS_TO_IU( x ) ( x ) diff --git a/cvpcb/CMakeLists.txt b/cvpcb/CMakeLists.txt index 3256bb8935..64c10f9aa0 100644 --- a/cvpcb/CMakeLists.txt +++ b/cvpcb/CMakeLists.txt @@ -26,6 +26,7 @@ set(CVPCB_DIALOGS ) set(CVPCB_SRCS + ../common/base_units.cpp ../pcbnew/netlist_reader_common.cpp ../pcbnew/netlist_reader_kicad.cpp ../pcbnew/netlist_reader_firstformat.cpp diff --git a/eeschema/dialogs/dialog_SVG_print.cpp b/eeschema/dialogs/dialog_SVG_print.cpp index 4dfb675f2e..81dd581af5 100644 --- a/eeschema/dialogs/dialog_SVG_print.cpp +++ b/eeschema/dialogs/dialog_SVG_print.cpp @@ -237,7 +237,7 @@ bool DIALOG_SVG_PRINT::DrawSVGPage( EDA_DRAW_FRAME* frame, sheetSize.y/2) ); if( aPrint_Sheet_Ref ) - frame->TraceWorkSheet( &dc, screen, g_DrawDefaultLineThickness, MILS_TO_IU_SCALAR ); + frame->TraceWorkSheet( &dc, screen, g_DrawDefaultLineThickness, MILS_TO_IU_SCALING_FACTOR ); screen->m_IsPrinting = false; panel->SetClipBox( tmp ); diff --git a/eeschema/dialogs/dialog_print_using_printer.cpp b/eeschema/dialogs/dialog_print_using_printer.cpp index d9c787714f..91f9c80eaa 100644 --- a/eeschema/dialogs/dialog_print_using_printer.cpp +++ b/eeschema/dialogs/dialog_print_using_printer.cpp @@ -378,7 +378,7 @@ void SCH_PRINTOUT::DrawPage( SCH_SCREEN* aScreen ) aScreen->Draw( panel, dc, GR_DEFAULT_DRAWMODE ); if( printReference ) - parent->TraceWorkSheet( dc, aScreen, g_DrawDefaultLineThickness, MILS_TO_IU_SCALAR ); + parent->TraceWorkSheet( dc, aScreen, g_DrawDefaultLineThickness, MILS_TO_IU_SCALING_FACTOR ); g_DrawBgColor = bg_color; aScreen->m_IsPrinting = false; diff --git a/eeschema/eeredraw.cpp b/eeschema/eeredraw.cpp index b571711594..62dfba469c 100644 --- a/eeschema/eeredraw.cpp +++ b/eeschema/eeredraw.cpp @@ -71,7 +71,7 @@ void SCH_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) GetScreen()->Draw( m_canvas, DC, GR_DEFAULT_DRAWMODE ); - TraceWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness, MILS_TO_IU_SCALAR ); + TraceWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness, MILS_TO_IU_SCALING_FACTOR ); #ifdef USE_WX_OVERLAY if( IsShown() ) diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index 20d4adc4f4..dddbf29ff7 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -863,7 +863,7 @@ void SCH_EDIT_FRAME::SVG_Print( wxCommandEvent& event ) void SCH_EDIT_FRAME::PrintPage( wxDC* aDC, int aPrintMask, bool aPrintMirrorMode, void* aData ) { GetScreen()->Draw( m_canvas, aDC, GR_DEFAULT_DRAWMODE ); - TraceWorkSheet( aDC, GetScreen(), g_DrawDefaultLineThickness, MILS_TO_IU_SCALAR ); + TraceWorkSheet( aDC, GetScreen(), g_DrawDefaultLineThickness, MILS_TO_IU_SCALING_FACTOR ); } diff --git a/gerbview/CMakeLists.txt b/gerbview/CMakeLists.txt index f44c34125d..51bfd7988e 100644 --- a/gerbview/CMakeLists.txt +++ b/gerbview/CMakeLists.txt @@ -33,6 +33,7 @@ set(GERBVIEW_SRCS class_am_param.cpp class_aperture_macro.cpp class_DCodeSelectionbox.cpp + class_gbr_screen.cpp class_GERBER.cpp class_gerber_draw_item.cpp class_gerbview_layer_widget.cpp @@ -63,9 +64,10 @@ set(GERBVIEW_SRCS ) ### -# We need some extra sources from pcbnew +# We need some extra sources from common and pcbnew ### set(GERBVIEW_EXTRA_SRCS + ../common/base_units.cpp ../pcbnew/layer_widget.cpp ../pcbnew/printout_controler.cpp ../pcbnew/class_drc_item.cpp diff --git a/gerbview/dcode.cpp b/gerbview/dcode.cpp index beb64ef5e5..dd00855ff6 100644 --- a/gerbview/dcode.cpp +++ b/gerbview/dcode.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com + * Copyright (C) 2009 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.fr * Copyright (C) 2011 Wayne Stambaugh * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. * @@ -175,7 +175,8 @@ int GERBVIEW_FRAME::ReadDCodeDefinitionFile( const wxString& D_Code_FullFileName /* Updating gerber scale: */ - double dcode_scale = MILS_TO_IU_SCALAR; // By uniting dCode = mil, internal unit = MILS_TO_IU_SCALAR + double dcode_scale = MILS_TO_IU_SCALING_FACTOR; // By uniting dCode = mil, + // internal unit = MILS_TO_IU_SCALING_FACTOR current_Dcode = 0; if( D_Code_FullFileName.IsEmpty() ) diff --git a/gerbview/draw_gerber_screen.cpp b/gerbview/draw_gerber_screen.cpp index 7a6821a4ab..4f54dc047d 100644 --- a/gerbview/draw_gerber_screen.cpp +++ b/gerbview/draw_gerber_screen.cpp @@ -107,7 +107,7 @@ void GERBVIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) if( IsElementVisible( DCODES_VISIBLE ) ) DrawItemsDCodeID( DC, GR_COPY ); - TraceWorkSheet( DC, screen, 0, MILS_TO_IU_SCALAR ); + TraceWorkSheet( DC, screen, 0, MILS_TO_IU_SCALING_FACTOR ); if( m_canvas->IsMouseCaptured() ) m_canvas->CallMouseCapture( DC, wxDefaultPosition, false ); diff --git a/gerbview/excellon_read_drill_file.cpp b/gerbview/excellon_read_drill_file.cpp index 64e40a4305..ccfada1cf2 100644 --- a/gerbview/excellon_read_drill_file.cpp +++ b/gerbview/excellon_read_drill_file.cpp @@ -432,7 +432,7 @@ bool EXCELLON_IMAGE::Execute_HEADER_Command( char*& text ) if( dcode == NULL ) break; // conv_scale = scaling factor from inch to Internal Unit - double conv_scale = MILS_TO_IU_SCALAR*1000; + double conv_scale = MILS_TO_IU_SCALING_FACTOR * 1000; if( m_GerbMetric ) conv_scale /= 25.4; diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index e922cf548c..d6eeb122da 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -44,6 +44,7 @@ #include #include #include +#include @@ -93,7 +94,7 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( wxWindow* father, PAGE_INFO pageInfo( wxT( "GERBER" ) ); GetBoard()->SetPageSettings( pageInfo ); - SetScreen( new PCB_SCREEN( pageInfo.GetSizeIU() ) ); + SetScreen( new GBR_SCREEN( pageInfo.GetSizeIU() ) ); // Create the PCB_LAYER_WIDGET *after* SetBoard(): wxFont font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); @@ -179,7 +180,7 @@ double GERBVIEW_FRAME::BestZoom() { // gives a minimal value to zoom, if no item in list if( GetBoard()->m_Drawings == NULL ) - return 160.0; + return ZOOM_FACTOR( 160.0 ); EDA_RECT bbox; BOARD_ITEM* item = GetBoard()->m_Drawings; @@ -210,7 +211,8 @@ void GERBVIEW_FRAME::LoadSettings() if( config == NULL ) return; - PCB_BASE_FRAME::LoadSettings(); +// PCB_BASE_FRAME::LoadSettings(); + EDA_DRAW_FRAME::LoadSettings(); wxGetApp().ReadCurrentSetupValues( GetConfigurationSettings() ); @@ -255,7 +257,8 @@ void GERBVIEW_FRAME::SaveSettings() if( config == NULL ) return; - PCB_BASE_FRAME::SaveSettings(); +// PCB_BASE_FRAME::SaveSettings(); + EDA_DRAW_FRAME::SaveSettings(); wxGetApp().SaveCurrentSetupValues( GetConfigurationSettings() ); @@ -408,7 +411,7 @@ void GERBVIEW_FRAME::Liste_D_Codes() D_CODE* pt_D_code; wxString Line; wxArrayString list; - double scale = MILS_TO_IU_SCALAR * 1000; + double scale = MILS_TO_IU_SCALING_FACTOR * 1000; int curr_layer = getActiveLayer(); for( int layer = 0; layer < 32; layer++ ) diff --git a/gerbview/gerbview_frame.h b/gerbview/gerbview_frame.h index 58925dd8aa..d3e9559331 100644 --- a/gerbview/gerbview_frame.h +++ b/gerbview/gerbview_frame.h @@ -35,6 +35,7 @@ #include #include <../pcbnew/class_board.h> +#include class DCODE_SELECTION_BOX; @@ -53,7 +54,6 @@ class GERBER_DRAW_ITEM; class GERBVIEW_FRAME : public PCB_BASE_FRAME { - friend class PCB_LAYER_WIDGET; protected: GERBER_LAYER_WIDGET* m_LayersManager; @@ -62,7 +62,7 @@ protected: wxFileHistory m_drillFileHistory; public: - LAYER_BOX_SELECTOR* m_SelLayerBox; + LAYER_BOX_SELECTOR* m_SelLayerBox; DCODE_SELECTION_BOX* m_DCodeSelector; // a list box to select the dcode Id to highlight. wxTextCtrl* m_TextInfo; // a wxTextCtrl used to display some info about // gerber data (format..) @@ -84,7 +84,7 @@ private: bool m_show_layer_manager_tools; - // An array sting to store warning messages when reaging a gerber file. + // An array string to store warning messages when reading a gerber file. wxArrayString m_Messages; public: GERBVIEW_FRAME( wxWindow* father, const wxString& title, @@ -226,7 +226,7 @@ public: GERBVIEW_FRAME( wxWindow* father, const wxString& title, */ void setActiveLayer( int aLayer, bool doLayerWidgetUpdate = true ) { - ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer = aLayer; + ( (GBR_SCREEN*) GetScreen() )->m_Active_Layer = aLayer; if( doLayerWidgetUpdate ) syncLayerWidget(); @@ -239,7 +239,7 @@ public: GERBVIEW_FRAME( wxWindow* father, const wxString& title, */ int getActiveLayer() { - return ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer; + return ( (GBR_SCREEN*) GetScreen() )->m_Active_Layer; } @@ -440,8 +440,6 @@ public: GERBVIEW_FRAME( wxWindow* father, const wxString& title, */ void Block_Duplicate( wxDC* DC ); - void ToPostProcess( wxCommandEvent& event ); - /** * Function ToPlotter * Open a dialog frame to create plot and drill files diff --git a/gerbview/onleftclick.cpp b/gerbview/onleftclick.cpp index 8dee3d8b7d..41cb6126c5 100644 --- a/gerbview/onleftclick.cpp +++ b/gerbview/onleftclick.cpp @@ -21,7 +21,7 @@ */ void GERBVIEW_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition ) { - BOARD_ITEM* DrawStruct = GetScreen()->GetCurItem(); + EDA_ITEM* DrawStruct = GetScreen()->GetCurItem(); wxString msg; if( GetToolId() == ID_NO_TOOL_SELECTED ) @@ -36,7 +36,7 @@ void GERBVIEW_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition ) else { DrawStruct = Locate( aPosition, CURSEUR_OFF_GRILLE ); - GetScreen()->SetCurItem( DrawStruct ); + GetScreen()->SetCurItem( (BOARD_ITEM*)DrawStruct ); if( DrawStruct == NULL ) { GERBER_IMAGE* gerber = g_GERBER_List[getActiveLayer() ]; diff --git a/gerbview/onrightclick.cpp b/gerbview/onrightclick.cpp index bf9e24ca66..4fae60fe21 100644 --- a/gerbview/onrightclick.cpp +++ b/gerbview/onrightclick.cpp @@ -16,7 +16,7 @@ */ bool GERBVIEW_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) { - BOARD_ITEM* DrawStruct = GetScreen()->GetCurItem(); + EDA_ITEM* DrawStruct = GetScreen()->GetCurItem(); wxString msg; bool BlockActive = !GetScreen()->m_BlockLocate.IsIdle(); bool busy = DrawStruct && DrawStruct->GetFlags(); @@ -71,7 +71,7 @@ bool GERBVIEW_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) return true; if( DrawStruct ) - GetScreen()->SetCurItem( DrawStruct ); + GetScreen()->SetCurItem( (BOARD_ITEM*)DrawStruct ); return true; } diff --git a/gerbview/options.cpp b/gerbview/options.cpp index 0aa3dcbff9..b47edde65e 100644 --- a/gerbview/options.cpp +++ b/gerbview/options.cpp @@ -36,28 +36,20 @@ void GERBVIEW_FRAME::OnSelectOptionToolbar( wxCommandEvent& event ) { case ID_TB_OPTIONS_SHOW_FLASHED_ITEMS_SKETCH: if( state ) - { - DisplayOpt.DisplayPadFill = m_DisplayPadFill = false; - } + DisplayOpt.DisplayPadFill = false; else - { - DisplayOpt.DisplayPadFill = m_DisplayPadFill = true; - } + DisplayOpt.DisplayPadFill = true; + m_DisplayPadFill = DisplayOpt.DisplayPadFill; m_canvas->Refresh( true ); break; case ID_TB_OPTIONS_SHOW_LINES_SKETCH: if(state ) - { - m_DisplayPcbTrackFill = false; DisplayOpt.DisplayPcbTrackFill = false; - } else - { - m_DisplayPcbTrackFill = true; DisplayOpt.DisplayPcbTrackFill = true; - } + m_DisplayPcbTrackFill = DisplayOpt.DisplayPcbTrackFill; m_canvas->Refresh( true ); break; diff --git a/gerbview/rs274_read_XY_and_IJ_coordinates.cpp b/gerbview/rs274_read_XY_and_IJ_coordinates.cpp index eea3b618ca..bf3b04c33b 100644 --- a/gerbview/rs274_read_XY_and_IJ_coordinates.cpp +++ b/gerbview/rs274_read_XY_and_IJ_coordinates.cpp @@ -21,16 +21,16 @@ // for metric gerber units, the imperial to metric conversion is made in read functions static double scale_list[10] = { - 1000.0 * MILS_TO_IU_SCALAR, - 100.0 * MILS_TO_IU_SCALAR, - 10.0 * MILS_TO_IU_SCALAR, - 1.0 * MILS_TO_IU_SCALAR, - 0.1 * MILS_TO_IU_SCALAR, - 0.01 * MILS_TO_IU_SCALAR, - 0.001 * MILS_TO_IU_SCALAR, - 0.0001 * MILS_TO_IU_SCALAR, - 0.00001 * MILS_TO_IU_SCALAR, - 0.000001 * MILS_TO_IU_SCALAR + 1000.0 * MILS_TO_IU_SCALING_FACTOR, + 100.0 * MILS_TO_IU_SCALING_FACTOR, + 10.0 * MILS_TO_IU_SCALING_FACTOR, + 1.0 * MILS_TO_IU_SCALING_FACTOR, + 0.1 * MILS_TO_IU_SCALING_FACTOR, + 0.01 * MILS_TO_IU_SCALING_FACTOR, + 0.001 * MILS_TO_IU_SCALING_FACTOR, + 0.0001 * MILS_TO_IU_SCALING_FACTOR, + 0.00001 * MILS_TO_IU_SCALING_FACTOR, + 0.000001 * MILS_TO_IU_SCALING_FACTOR }; @@ -44,9 +44,9 @@ int scaletoIU( double aCoord, bool isMetric ) int ret; if( isMetric ) - ret = KiROUND( aCoord * MILS_TO_IU_SCALAR / 0.00254 ); + ret = KiROUND( aCoord * MILS_TO_IU_SCALING_FACTOR / 0.00254 ); else - ret = KiROUND( aCoord * MILS_TO_IU_SCALAR ); + ret = KiROUND( aCoord * MILS_TO_IU_SCALING_FACTOR ); return ret; } @@ -94,9 +94,9 @@ wxPoint GERBER_IMAGE::ReadXYCoord( char*& Text ) { // When X or Y values are float numbers, they are given in mm or inches if( m_GerbMetric ) // units are mm - current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALAR / 0.0254 ); + current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALING_FACTOR / 0.0254 ); else // units are inches - current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALAR * 1000 ); + current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALING_FACTOR * 1000 ); } else { @@ -185,9 +185,9 @@ wxPoint GERBER_IMAGE::ReadIJCoord( char*& Text ) { // When X or Y values are float numbers, they are given in mm or inches if( m_GerbMetric ) // units are mm - current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALAR / 0.0254 ); + current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALING_FACTOR / 0.0254 ); else // units are inches - current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALAR * 1000 ); + current_coord = KiROUND( atof( line ) * MILS_TO_IU_SCALING_FACTOR * 1000 ); } else { diff --git a/gerbview/rs274x.cpp b/gerbview/rs274x.cpp index 311566f0dc..3c9140795e 100644 --- a/gerbview/rs274x.cpp +++ b/gerbview/rs274x.cpp @@ -160,7 +160,7 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, double fcoord; // conv_scale = scaling factor from inch to Internal Unit - double conv_scale = MILS_TO_IU_SCALAR*1000; + double conv_scale = MILS_TO_IU_SCALING_FACTOR * 1000; if( m_GerbMetric ) conv_scale /= 25.4; @@ -294,7 +294,7 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, m_GerbMetric = false; else if( code == MILLIMETER ) m_GerbMetric = true; - conv_scale = m_GerbMetric ? PCB_INTERNAL_UNIT / 25.4 : PCB_INTERNAL_UNIT; + conv_scale = m_GerbMetric ? MILS_TO_IU_SCALING_FACTOR / 25.4 : MILS_TO_IU_SCALING_FACTOR; break; case OFFSET: // command: OFAnnBnn (nn = float number) = layer Offset @@ -579,8 +579,8 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, text += 2; // skip "C," for example - dcode->m_Size.x = dcode->m_Size.y = - KiROUND( ReadDouble( text ) * conv_scale ); + dcode->m_Size.x = KiROUND( ReadDouble( text ) * conv_scale ); + dcode->m_Size.y = dcode->m_Size.x; switch( stdAperture ) // Aperture desceiption has optional parameters. Read them { @@ -631,8 +631,8 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, if( *text == 'X' ) { text++; - dcode->m_Drill.x = dcode->m_Drill.y = - KiROUND( ReadDouble( text ) * conv_scale ); + dcode->m_Drill.x = KiROUND( ReadDouble( text ) * conv_scale ); + dcode->m_Drill.y = dcode->m_Drill.x; dcode->m_DrillShape = APT_DEF_ROUND_HOLE; } @@ -679,8 +679,8 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, if( *text == 'X' ) { text++; - dcode->m_Drill.x = dcode->m_Drill.y = - KiROUND( ReadDouble( text ) * conv_scale ); + dcode->m_Drill.x = KiROUND( ReadDouble( text ) * conv_scale ); + dcode->m_Drill.y = dcode->m_Drill.x = dcode->m_DrillShape = APT_DEF_ROUND_HOLE; } @@ -690,8 +690,7 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, if( *text == 'X' ) { text++; - dcode->m_Drill.y = - KiROUND( ReadDouble( text ) * conv_scale ); + dcode->m_Drill.y = KiROUND( ReadDouble( text ) * conv_scale ); dcode->m_DrillShape = APT_DEF_RECT_HOLE; } dcode->m_Defined = true; diff --git a/include/base_units.h b/include/base_units.h index 0d505d81ec..16276e64fb 100644 --- a/include/base_units.h +++ b/include/base_units.h @@ -35,19 +35,7 @@ #include - - - -/// Scalar to convert mils to internal units. -#if defined( PCBNEW ) -#if defined( USE_PCBNEW_NANOMETRES ) -#define MILS_TO_IU_SCALAR 25.4e3 // Pcbnew in nanometers. -#else -#define MILS_TO_IU_SCALAR 10.0 // Pcbnew in deci-mils. -#endif -#else -#define MILS_TO_IU_SCALAR 1.0 // Eeschema and anything else. -#endif +#include /** diff --git a/include/common.h b/include/common.h index ff33adfafa..e60cf9a6fc 100644 --- a/include/common.h +++ b/include/common.h @@ -39,6 +39,7 @@ #include #include +#include #if !wxUSE_PRINTING_ARCHITECTURE # error "You must use '--enable-printarch' in your wx library configuration." @@ -296,18 +297,9 @@ public: // Accessors returning "Internal Units (IU)". IUs are mils in EESCHEMA, // and either deci-mils or nanometers in PCBNew. -#if defined(PCBNEW) -# if defined(KICAD_NANOMETRE) - int GetWidthIU() const { return 25400 * GetWidthMils(); } - int GetHeightIU() const { return 25400 * GetHeightMils(); } -# else - int GetWidthIU() const { return 10 * GetWidthMils(); } - int GetHeightIU() const { return 10 * GetHeightMils(); } -# endif - const wxSize GetSizeIU() const { return wxSize( GetWidthIU(), GetHeightIU() ); } -#elif defined(EESCHEMA) - int GetWidthIU() const { return GetWidthMils(); } - int GetHeightIU() const { return GetHeightMils(); } +#if defined(PCBNEW) || defined(EESCHEMA) || defined(GERBVIEW) + int GetWidthIU() const { return MILS_TO_IU_SCALING_FACTOR * GetWidthMils(); } + int GetHeightIU() const { return MILS_TO_IU_SCALING_FACTOR * GetHeightMils(); } const wxSize GetSizeIU() const { return wxSize( GetWidthIU(), GetHeightIU() ); } #endif diff --git a/include/convert_to_biu.h b/include/convert_to_biu.h index c6c537c6e7..333e5423e6 100644 --- a/include/convert_to_biu.h +++ b/include/convert_to_biu.h @@ -9,20 +9,37 @@ /** - * @brief inline convert functions to convert a value in decimils (or mils) - * to the internal unit used in pcbnew or cvpcb(nanometer or decimil) + * @brief some define and functions to convert a value in mils, decimils or mm + * to the internal unit used in pcbnew, cvpcb or gerbview (nanometer or decimil) * depending on compil option */ -#if defined(PCBNEW) || defined(CVPCB) + + +/// Scaling factor to convert mils to internal units. +#if defined(PCBNEW) || defined(CVPCB) || defined(GERBVIEW) + #if defined( USE_PCBNEW_NANOMETRES ) + #if defined(GERBVIEW) + #define MM_TO_IU_SCALING_FACTOR 1e5 // Gerbview uses 10 micrometer. + #else + #define MM_TO_IU_SCALING_FACTOR 1e6 // Pcbnew uses nanometers. + #endif + #define MILS_TO_IU_SCALING_FACTOR ( MM_TO_IU_SCALING_FACTOR * 0.0254 ) + #define DECIMILS_TO_IU_SCALING_FACTOR (MM_TO_IU_SCALING_FACTOR * 0.00254 ) + #else // Pcbnew in deci-mils. + #define DECIMILS_TO_IU_SCALING_FACTOR 1 + #define MILS_TO_IU_SCALING_FACTOR 10.0 + #define MM_TO_IU_SCALING_FACTOR (1e4 / 25.4) + #endif + /// Convert mils to PCBNEW internal units (iu). inline int Mils2iu( int mils ) { #if defined( USE_PCBNEW_NANOMETRES ) - double x = mils * 25.4e3; + double x = mils * MILS_TO_IU_SCALING_FACTOR; return int( x < 0 ? x - 0.5 : x + 0.5 ); #else - return mils * 10; + return mils * MILS_TO_IU_SCALING_FACTOR; #endif } @@ -30,14 +47,17 @@ inline int Mils2iu( int mils ) inline int DMils2iu( int dmils ) { #if defined( USE_PCBNEW_NANOMETRES ) - double x = dmils * 25.4e2; + double x = dmils * DECIMILS_TO_IU_SCALING_FACTOR; return int( x < 0 ? x - 0.5 : x + 0.5 ); #else return dmils; #endif } -#elif defined(EESCHEMA) +#else // Eeschema and anything else. +#define MILS_TO_IU_SCALING_FACTOR 1.0 +#define MM_TO_IU_SCALING_FACTOR (MILS_TO_IU_SCALING_FACTOR / 0.0254) + inline int Mils2iu( int mils ) { return mils; diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 365cfa7971..104a46e3e2 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -203,7 +203,10 @@ set(PCBNEW_SRCS ### # We need some extra sources from common ### -#set(PCBNEW_COMMON_SRCS ../common/dialogs/dialog_page_settings.cpp ) +set(PCBNEW_COMMON_SRCS + ../common/dialogs/dialog_page_settings.cpp + ../common/base_units.cpp + ) ### diff --git a/pcbnew/classpcb.cpp b/pcbnew/classpcb.cpp index c12497f27e..13a621bfde 100644 --- a/pcbnew/classpcb.cpp +++ b/pcbnew/classpcb.cpp @@ -19,15 +19,11 @@ #include -#if defined( USE_PCBNEW_NANOMETRES ) -#define ZOOM_FACTOR( x ) ( x * 25.4e2 ) -#define DMIL_GRID( x ) wxRealPoint( x * 25.4e2, x * 25.4e2 ) -#define MM_GRID( x ) wxRealPoint( x * 1e6, x * 1e6 ) -#else -#define ZOOM_FACTOR( x ) x -#define DMIL_GRID( x ) wxRealPoint( x , x ) -#define MM_GRID( x ) wxRealPoint( x * 1e4 / 25.4, x * 1e4 / 25.4 ) -#endif +#define ZOOM_FACTOR( x ) ( x * DECIMILS_TO_IU_SCALING_FACTOR ) +#define DMIL_GRID( x ) wxRealPoint( x * DECIMILS_TO_IU_SCALING_FACTOR,\ + x * DECIMILS_TO_IU_SCALING_FACTOR ) +#define MM_GRID( x ) wxRealPoint( x * MM_TO_IU_SCALING_FACTOR,\ + x * MM_TO_IU_SCALING_FACTOR ) /** @@ -110,7 +106,6 @@ PCB_SCREEN::PCB_SCREEN( const wxSize& aPageSizeIU ) : { wxSize displayz = wxGetDisplaySize(); - for( unsigned i = 0; i < DIM( pcbZoomList ); ++i ) m_ZoomList.Add( pcbZoomList[i] ); @@ -124,7 +119,7 @@ PCB_SCREEN::PCB_SCREEN( const wxSize& aPageSizeIU ) : m_Route_Layer_TOP = LAYER_N_FRONT; // default layers pair for vias (bottom to top) m_Route_Layer_BOTTOM = LAYER_N_BACK; - SetZoom( ZOOM_FACTOR( 150 ) ); // a default value for zoom + SetZoom( ZOOM_FACTOR( 120 ) ); // a default value for zoom InitDataPoints( aPageSizeIU ); } @@ -138,11 +133,7 @@ PCB_SCREEN::~PCB_SCREEN() int PCB_SCREEN::MilsToIuScalar() { -#if defined( USE_PCBNEW_NANOMETRES ) - return 25400; -#else - return 10; -#endif + return (int)MILS_TO_IU_SCALING_FACTOR; } diff --git a/pcbnew/dialogs/dialog_SVG_print.cpp b/pcbnew/dialogs/dialog_SVG_print.cpp index 19eea912fa..9f3b3e946b 100644 --- a/pcbnew/dialogs/dialog_SVG_print.cpp +++ b/pcbnew/dialogs/dialog_SVG_print.cpp @@ -271,7 +271,7 @@ bool DIALOG_SVG_PRINT::DrawPage( const wxString& FullFileName, g_DrawBgColor = WHITE; if( aPrint_Frame_Ref ) - m_Parent->TraceWorkSheet( &dc, screen, s_Parameters.m_PenDefaultSize, MILS_TO_IU_SCALAR ); + m_Parent->TraceWorkSheet( &dc, screen, s_Parameters.m_PenDefaultSize, MILS_TO_IU_SCALING_FACTOR ); m_Parent->PrintPage( &dc, m_PrintMaskLayer, false, &s_Parameters); g_DrawBgColor = bg_color; diff --git a/pcbnew/legacy_plugin.cpp b/pcbnew/legacy_plugin.cpp index 263a9b4127..2894ece448 100644 --- a/pcbnew/legacy_plugin.cpp +++ b/pcbnew/legacy_plugin.cpp @@ -2682,7 +2682,7 @@ void LEGACY_PLUGIN::init( PROPERTIES* aProperties ) // conversion factor for saving RAM BIUs to KICAD legacy file format. #if defined( USE_PCBNEW_NANOMETRES ) - biuToDisk = 1/1000000.0; // BIUs are nanometers & file is mm + biuToDisk = 1/MM_TO_IU_SCALING_FACTOR; // BIUs are nanometers & file is mm #else biuToDisk = 1.0; // BIUs are deci-mils #endif @@ -2694,11 +2694,8 @@ void LEGACY_PLUGIN::init( PROPERTIES* aProperties ) // then, during the file loading process, to start a conversion from // mm to nanometers. -#if defined( USE_PCBNEW_NANOMETRES ) - diskToBiu = 2540.0; // BIUs are nanometers -#else - diskToBiu = 1.0; // BIUs are deci-mils -#endif + diskToBiu = DECIMILS_TO_IU_SCALING_FACTOR; // BIUs are nanometers if USE_PCBNEW_NANOMETRES + // or BIUs are deci-mils } diff --git a/pcbnew/printout_controler.cpp b/pcbnew/printout_controler.cpp index 9df8d4b409..a098593ddd 100644 --- a/pcbnew/printout_controler.cpp +++ b/pcbnew/printout_controler.cpp @@ -180,12 +180,8 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage() if( userscale == 0 ) // fit in page { - // Margin = 0.4 inch -#if defined(KICAD_NANOMETRE) - int extra_margin = int( 0.4 * 25400 ); // nanometers -#else - int extra_margin = int( 0.4 * 1000 ); // deci-mils -#endif + // Margin = 10mm + int extra_margin = int( 10 * MM_TO_IU_SCALING_FACTOR ); // deci-mils pageSizeIU.x = bbbox.GetWidth() + extra_margin * 2; pageSizeIU.y = bbbox.GetHeight() + extra_margin * 2; @@ -278,7 +274,8 @@ void BOARD_PRINTOUT_CONTROLER::DrawPage() int bg_color = g_DrawBgColor; if( m_PrintParams.m_Print_Sheet_Ref ) - m_Parent->TraceWorkSheet( dc, screen, m_PrintParams.m_PenDefaultSize, MILS_TO_IU_SCALAR ); + m_Parent->TraceWorkSheet( dc, screen, m_PrintParams.m_PenDefaultSize, + MILS_TO_IU_SCALING_FACTOR ); if( printMirror ) { diff --git a/pcbnew/specctra_export.cpp b/pcbnew/specctra_export.cpp index d30579ad35..02169a65b1 100644 --- a/pcbnew/specctra_export.cpp +++ b/pcbnew/specctra_export.cpp @@ -171,10 +171,10 @@ static inline double scale( int kicadDist ) #if defined(USE_PCBNEW_NANOMETRES) // nanometers to um - return kicadDist / 1000.0; + return kicadDist / ( MM_TO_IU_SCALING_FACTOR / 1000.0 ); // nanometers to mils - // return kicadDist/25400.0; + // return kicadDist/MILS_TO_IU_SCALING_FACTOR; #else // deci-mils to mils. @@ -185,11 +185,7 @@ static inline double scale( int kicadDist ) /// Convert integer internal units to float um static inline double IU2um( int kicadDist ) { -#if defined(USE_PCBNEW_NANOMETRES) - return kicadDist / 1000.0; -#else - return kicadDist * 25.4e-1; -#endif + return kicadDist * (1000.0 / MM_TO_IU_SCALING_FACTOR); } diff --git a/pcbnew/tracepcb.cpp b/pcbnew/tracepcb.cpp index e24b92a36e..7858d08356 100644 --- a/pcbnew/tracepcb.cpp +++ b/pcbnew/tracepcb.cpp @@ -67,7 +67,7 @@ void FOOTPRINT_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) GRSetDrawMode( DC, GR_COPY ); m_canvas->DrawBackGround( DC ); - TraceWorkSheet( DC, screen, 0, MILS_TO_IU_SCALAR ); + TraceWorkSheet( DC, screen, 0, MILS_TO_IU_SCALING_FACTOR ); // Redraw the footprints for( MODULE* module = GetBoard()->m_Modules; module; module = module->Next() ) @@ -105,7 +105,7 @@ void PCB_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) m_canvas->DrawBackGround( DC ); - TraceWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness, MILS_TO_IU_SCALAR ); + TraceWorkSheet( DC, GetScreen(), g_DrawDefaultLineThickness, MILS_TO_IU_SCALING_FACTOR ); GetBoard()->Draw( m_canvas, DC, GR_OR | GR_ALLOW_HIGHCONTRAST); diff --git a/polygon/PolyLine.cpp b/polygon/PolyLine.cpp index ff4753c749..113bd0eba4 100644 --- a/polygon/PolyLine.cpp +++ b/polygon/PolyLine.cpp @@ -357,9 +357,7 @@ int CPolyLine::MakeKboolPoly( int aStart_contour, int aEnd_contour, std::vector< else { // style is ARC_CW or ARC_CCW - int n; // number of steps for arcs - n = ( abs( x2 - x1 ) + abs( y2 - y1 ) ) / (CArc::MAX_STEP); - n = MAX( n, CArc::MIN_STEPS ); // or at most 5 degrees of arc + int n = CArc::ARC_STEPS; n_vertices += n; n_arcs++; } @@ -392,8 +390,7 @@ int CPolyLine::MakeKboolPoly( int aStart_contour, int aEnd_contour, std::vector< { // style is arc_cw or arc_ccw int n; // number of steps for arcs - n = ( abs( x2 - x1 ) + abs( y2 - y1 ) ) / (CArc::MAX_STEP); - n = MAX( n, CArc::MIN_STEPS ); // or at most 5 degrees of arc + n = CArc::ARC_STEPS; double xo, yo, theta1, theta2, a, b; a = fabs( (double) (x1 - x2) ); b = fabs( (double) (y1 - y2) ); diff --git a/polygon/PolyLine.h b/polygon/PolyLine.h index fc44f87755..3aa6ba60f3 100644 --- a/polygon/PolyLine.h +++ b/polygon/PolyLine.h @@ -77,8 +77,7 @@ public: class CArc { public: - enum { MAX_STEP = 50 * 25400 }; // max step is 20 mils - enum { MIN_STEPS = 18 }; // min step is 5 degrees + enum { ARC_STEPS = 16 }; // arc approximation step is 16 segm / 90 degres int style; int xi, yi, xf, yf; int n_steps; // number of straight-line segments in gpc_poly