From f3e171797c55c7dfefa8064416b235466759557c Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 18 Apr 2012 09:07:13 +0200 Subject: [PATCH] Make Gerbview working with USE_PCBNEW_NANOMETRES option ON --- gerbview/class_GERBER.cpp | 10 +- gerbview/class_aperture_macro.cpp | 48 +-- gerbview/dcode.cpp | 6 +- .../dialog_layers_select_to_pcb_base.fbp | 120 +++--- .../dialog_print_using_printer_base.fbp | 366 +++++++++++++++++- .../dialogs/dialog_show_page_borders_base.fbp | 56 +-- ...view_dialog_display_options_frame_base.fbp | 40 +- gerbview/excellon_read_drill_file.cpp | 7 +- gerbview/export_to_pcbnew.cpp | 44 ++- gerbview/gerbview.cpp | 23 ++ gerbview/gerbview_frame.cpp | 3 +- gerbview/rs274_read_XY_and_IJ_coordinates.cpp | 77 ++-- gerbview/rs274d.cpp | 17 - gerbview/rs274x.cpp | 7 +- 14 files changed, 564 insertions(+), 260 deletions(-) diff --git a/gerbview/class_GERBER.cpp b/gerbview/class_GERBER.cpp index c702f90586..47200fbfad 100644 --- a/gerbview/class_GERBER.cpp +++ b/gerbview/class_GERBER.cpp @@ -38,10 +38,10 @@ /** - * Function scale - * converts a distance given in floating point to our deci-mils + * Function scaletoIU + * converts a distance given in floating point to our internal units */ -extern int scale( double aCoord, bool isMetric ); // defined it rs274d.cpp +extern int scaletoIU( double aCoord, bool isMetric ); // defined it rs274d_read_XY_and_IJ_coordiantes.cpp /* Format Gerber: NOTES: * Tools and D_CODES @@ -301,9 +301,9 @@ void GERBER_IMAGE::StepAndRepeatItem( const GERBER_DRAW_ITEM& aItem ) continue; GERBER_DRAW_ITEM* dupItem = new GERBER_DRAW_ITEM( aItem ); wxPoint move_vector; - move_vector.x = scale( ii * GetLayerParams().m_StepForRepeat.x, + move_vector.x = scaletoIU( ii * GetLayerParams().m_StepForRepeat.x, GetLayerParams().m_StepForRepeatMetric ); - move_vector.y = scale( jj * GetLayerParams().m_StepForRepeat.y, + move_vector.y = scaletoIU( jj * GetLayerParams().m_StepForRepeat.y, GetLayerParams().m_StepForRepeatMetric ); dupItem->MoveXY( move_vector ); m_Parent->GetBoard()->m_Drawings.Append( dupItem ); diff --git a/gerbview/class_aperture_macro.cpp b/gerbview/class_aperture_macro.cpp index ce1886d104..12661308d9 100644 --- a/gerbview/class_aperture_macro.cpp +++ b/gerbview/class_aperture_macro.cpp @@ -39,10 +39,10 @@ /** - * Function scale - * converts a distance given in floating point to our deci-mils + * Function scaletoIU + * converts a distance given in floating point to our internal units */ -extern int scale( double aCoord, bool isMetric ); // defined it rs274d.cpp +extern int scaletoIU( double aCoord, bool isMetric ); // defined it rs274d_read_XY_and_IJ_coordiantes.cpp /** * Function mapPt @@ -52,7 +52,7 @@ extern int scale( double aCoord, bool isMetric ); // defined it rs274d */ static wxPoint mapPt( double x, double y, bool isMetric ) { - wxPoint ret( scale( x, isMetric ), scale( y, isMetric ) ); + wxPoint ret( scaletoIU( x, isMetric ), scaletoIU( y, isMetric ) ); return ret; } @@ -157,7 +157,7 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent, */ curPos += mapPt( params[2].GetValue( tool ), params[3].GetValue( tool ), m_GerbMetric ); curPos = aParent->GetABPosition( curPos ); - int radius = scale( params[1].GetValue( tool ), m_GerbMetric ) / 2; + int radius = scaletoIU( params[1].GetValue( tool ), m_GerbMetric ) / 2; if( !aFilledShape ) GRCircle( aClipBox, aDC, curPos, radius, 0, aColor ); else @@ -300,9 +300,9 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent, * type(6), pos.x, pos.y, diam, penwidth, gap, circlecount, crosshair thickness, crosshaire len, rotation * type is not stored in parameters list, so the first parameter is pos.x */ - int outerDiam = scale( params[2].GetValue( tool ), m_GerbMetric ); - int penThickness = scale( params[3].GetValue( tool ), m_GerbMetric ); - int gap = scale( params[4].GetValue( tool ), m_GerbMetric ); + int outerDiam = scaletoIU( params[2].GetValue( tool ), m_GerbMetric ); + int penThickness = scaletoIU( params[3].GetValue( tool ), m_GerbMetric ); + int gap = scaletoIU( params[4].GetValue( tool ), m_GerbMetric ); int numCircles = wxRound( params[5].GetValue( tool ) ); // Draw circles: @@ -358,8 +358,8 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent, for( int i = 0; i #include #include +#include #include #include @@ -155,7 +156,7 @@ int D_CODE::GetShapeDim( GERBER_DRAW_ITEM* aParent ) int GERBVIEW_FRAME::ReadDCodeDefinitionFile( const wxString& D_Code_FullFileName ) { - int current_Dcode, ii, dcode_scale; + int current_Dcode, ii; char* ptcar; int dimH, dimV, drill, dummy; float fdimH, fdimV, fdrill; @@ -174,8 +175,7 @@ int GERBVIEW_FRAME::ReadDCodeDefinitionFile( const wxString& D_Code_FullFileName /* Updating gerber scale: */ - dcode_scale = 10; /* By uniting dCode = mil, internal unit = 0.1 mil - * -> 1 unite dcode = 10 unit PCB */ + double dcode_scale = MILS_TO_IU_SCALAR; // By uniting dCode = mil, internal unit = MILS_TO_IU_SCALAR current_Dcode = 0; if( D_Code_FullFileName.IsEmpty() ) diff --git a/gerbview/dialogs/dialog_layers_select_to_pcb_base.fbp b/gerbview/dialogs/dialog_layers_select_to_pcb_base.fbp index 4856eb8d8a..dc710fe612 100644 --- a/gerbview/dialogs/dialog_layers_select_to_pcb_base.fbp +++ b/gerbview/dialogs/dialog_layers_select_to_pcb_base.fbp @@ -1,12 +1,14 @@ - + C++ 1 source_name + 0 0 + res UTF-8 table dialog_layers_select_to_pcb_base @@ -18,68 +20,44 @@ . 1 + 1 1 1 0 - 1 - 1 - 1 - 1 0 - + wxAUI_MGR_DEFAULT - - 1 wxBOTH - 0 - 1 1 - 0 - Dock - 0 - Left 1 impl_virtual - 1 - 0 0 ID_LAYERS_MAP_DIALOG_BASE - - 0 - 0 - 1 LAYERS_MAP_DIALOG_BASE - 1 - - - 1 - - Resizable - - 1 400,286 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER Layer selection: - 0 - - wxFILTER_NONE - wxDefaultValidator - + + + + + + @@ -161,7 +139,11 @@ 1 1 1 + + + + 1 @@ -180,9 +162,10 @@ 0 0 ID_M_STATICLINESEP - + 0 + 0 1 @@ -193,19 +176,13 @@ protected 1 - Resizable - 1 wxLI_VERTICAL 0 - - wxFILTER_NONE - wxDefaultValidator - @@ -263,7 +240,11 @@ 1 1 1 + + + + 1 @@ -283,9 +264,10 @@ 0 ID_M_STATICTEXTCOPPERLAYERCOUNT Copper layers count: - + 0 + 0 1 @@ -296,19 +278,13 @@ protected 1 - Resizable - 1 0 - - wxFILTER_NONE - wxDefaultValidator - @@ -347,7 +323,11 @@ 1 1 1 + + + + 1 @@ -367,9 +347,10 @@ 0 0 ID_M_COMBOCOPPERLAYERSCOUNT - + 0 + 0 1 @@ -380,9 +361,8 @@ protected 1 - Resizable - + -1 1 @@ -455,7 +435,11 @@ 1 1 1 + + + + 1 @@ -476,9 +460,10 @@ 0 ID_STORE_CHOICE Store Choice - + 0 + 0 1 @@ -489,9 +474,7 @@ protected 1 - Resizable - 1 @@ -540,7 +523,11 @@ 1 1 1 + + + + 1 @@ -561,9 +548,10 @@ 0 ID_GET_PREVIOUS_CHOICE Get Stored Choice - + 0 + 0 1 @@ -574,9 +562,7 @@ protected 1 - Resizable - 1 @@ -625,7 +611,11 @@ 1 1 1 + + + + 1 @@ -646,9 +636,10 @@ 0 ID_RESET_CHOICE Reset - + 0 + 0 1 @@ -659,9 +650,7 @@ protected 1 - Resizable - 1 @@ -716,7 +705,11 @@ 1 1 1 + + + + 1 @@ -735,9 +728,10 @@ 0 0 wxID_ANY - + 0 + 0 1 @@ -748,19 +742,13 @@ protected 1 - Resizable - 1 wxLI_HORIZONTAL 0 - - wxFILTER_NONE - wxDefaultValidator - diff --git a/gerbview/dialogs/dialog_print_using_printer_base.fbp b/gerbview/dialogs/dialog_print_using_printer_base.fbp index db3d6e6963..724b188815 100644 --- a/gerbview/dialogs/dialog_print_using_printer_base.fbp +++ b/gerbview/dialogs/dialog_print_using_printer_base.fbp @@ -1,12 +1,14 @@ - + C++ 1 source_name + 0 0 + res UTF-8 connect dialog_print_using_printer_base @@ -18,10 +20,13 @@ . 1 + 1 1 1 0 + 0 + wxAUI_MGR_DEFAULT @@ -42,15 +47,17 @@ Print - - wxFILTER_NONE - wxDefaultValidator - + + + + + + OnCloseWindow @@ -151,26 +158,57 @@ wxALL 0 + 1 + 1 + 1 + 1 + + + + + + + 1 + 0 "fit in page" "Scale 0.5" "Scale 0.7" "Approx. Scale 1" "Accurate Scale 1" "Scale 1.4" "Scale 2" "Scale 3" "Scale 4" + 1 1 + 0 + Dock + 0 + Left 1 + 1 + 0 0 wxID_ANY Approx. Scale: 1 + + 0 + + 0 + 1 m_ScaleOption + 1 + + protected + 1 + Resizable 3 + 1 wxRA_SPECIFY_COLS + 0 wxFILTER_NONE @@ -210,28 +248,55 @@ wxRIGHT|wxLEFT 0 + 1 + 1 + 1 + 1 + + + + + + + 1 + 0 + 1 1 + 0 + Dock + 0 + Left 1 + 1 + 0 0 wxID_ANY X Scale Adjust + + 0 + + 0 + 1 m_FineAdjustXscaleTitle + 1 + + protected + 1 + Resizable + 1 + 0 - - wxFILTER_NONE - wxDefaultValidator - @@ -266,23 +331,54 @@ wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND 0 + 1 + 1 + 1 + 1 + + + + + + + 1 + 0 + 1 1 + 0 + Dock + 0 + Left 1 + 1 + 0 0 wxID_ANY + + 0 0 + + 0 + 1 m_FineAdjustXscaleOpt + 1 + + protected + 1 + Resizable + 1 + 0 Set X scale adjust for exact scale plotting wxFILTER_NONE @@ -326,28 +422,55 @@ wxRIGHT|wxLEFT 0 + 1 + 1 + 1 + 1 + + + + + + + 1 + 0 + 1 1 + 0 + Dock + 0 + Left 1 + 1 + 0 0 wxID_ANY Y Scale Adjust + + 0 + + 0 + 1 m_FineAdjustYscaleTitle + 1 + + protected + 1 + Resizable + 1 + 0 - - wxFILTER_NONE - wxDefaultValidator - @@ -382,23 +505,54 @@ wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND 0 + 1 + 1 + 1 + 1 + + + + + + + 1 + 0 + 1 1 + 0 + Dock + 0 + Left 1 + 1 + 0 0 wxID_ANY + + 0 0 + + 0 + 1 m_FineAdjustYscaleOpt + 1 + + protected + 1 + Resizable + 1 + 0 Set Y scale adjust for exact scale plotting wxFILTER_NONE @@ -465,24 +619,55 @@ wxALL 0 + 1 + 1 + 1 + 1 + + + + + + + 1 + 0 0 + 1 1 + 0 + Dock + 0 + Left 1 + 1 + 0 0 wxID_ANY Mirror + + 0 + + 0 + 1 m_Print_Mirror + 1 + + protected + 1 + Resizable + 1 + 0 wxFILTER_NONE @@ -524,26 +709,57 @@ wxALL|wxEXPAND 0 + 1 + 1 + 1 + 1 + + + + + + + 1 + 0 "Color" "Black and white" + 1 1 + 0 + Dock + 0 + Left 1 + 1 + 0 0 wxID_PRINT_MODE Print Mode 1 + + 0 + + 0 + 1 m_ModeColorOption + 1 + + protected + 1 + Resizable 0 + 1 wxRA_SPECIFY_COLS + 0 Choose if you want to print sheets in color, or force the black and white mode. wxFILTER_NONE @@ -594,24 +810,55 @@ wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND 0 + 1 + 1 + 1 + 1 + + + + + + + 1 + 0 + 1 1 0 + 0 + Dock + 0 + Left 1 + 1 + 0 0 wxID_PRINT_OPTIONS Page Options + + 0 + + 0 + 1 m_buttonOption + 1 + + protected + 1 + Resizable + 1 + 0 wxFILTER_NONE @@ -651,24 +898,55 @@ wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND 0 + 1 + 1 + 1 + 1 + + + + + + + 1 + 0 + 1 1 0 + 0 + Dock + 0 + Left 1 + 1 + 0 0 wxID_PREVIEW Preview + + 0 + + 0 + 1 m_buttonPreview + 1 + + protected + 1 + Resizable + 1 + 0 wxFILTER_NONE @@ -708,24 +986,55 @@ wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND 0 + 1 + 1 + 1 + 1 + + + + + + + 1 + 0 + 1 1 0 + 0 + Dock + 0 + Left 1 + 1 + 0 0 wxID_PRINT_ALL Print + + 0 + + 0 + 1 m_buttonPrint + 1 + + protected + 1 + Resizable + 1 + 0 wxFILTER_NONE @@ -765,24 +1074,55 @@ wxALL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND 0 + 1 + 1 + 1 + 1 + + + + + + + 1 + 0 + 1 1 0 + 0 + Dock + 0 + Left 1 + 1 + 0 0 wxID_CANCEL Close + + 0 + + 0 + 1 m_buttonQuit + 1 + + protected + 1 + Resizable + 1 + 0 wxFILTER_NONE diff --git a/gerbview/dialogs/dialog_show_page_borders_base.fbp b/gerbview/dialogs/dialog_show_page_borders_base.fbp index a5235414bf..80828042e8 100644 --- a/gerbview/dialogs/dialog_show_page_borders_base.fbp +++ b/gerbview/dialogs/dialog_show_page_borders_base.fbp @@ -1,11 +1,12 @@ - + C++ 1 source_name + 0 0 res UTF-8 @@ -19,66 +20,33 @@ . 1 + 1 1 0 0 - 1 - 1 - 1 - 1 0 - - + wxAUI_MGR_DEFAULT - - 1 - 0 - 1 1 - 0 - Dock - 0 - Left 1 impl_virtual - 1 - 0 0 wxID_ANY - - - 0 - - 0 - 1 DIALOG_PAGE_SHOW_PAGE_BORDERS_BASE - 1 - - - 1 - - Resizable - - 1 263,254 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER Page Borders - 0 - - wxFILTER_NONE - wxDefaultValidator - @@ -150,7 +118,10 @@ 1 1 1 + + + @@ -172,7 +143,6 @@ 0 wxID_ANY Show Page Limits: - 1 0 @@ -188,9 +158,7 @@ protected 1 - Resizable - 0 1 @@ -244,7 +212,10 @@ 1 1 1 + + + @@ -264,7 +235,6 @@ 0 0 wxID_ANY - 0 @@ -279,19 +249,13 @@ protected 1 - Resizable - 1 wxLI_HORIZONTAL 0 - - wxFILTER_NONE - wxDefaultValidator - diff --git a/gerbview/dialogs/gerbview_dialog_display_options_frame_base.fbp b/gerbview/dialogs/gerbview_dialog_display_options_frame_base.fbp index f4560f63d1..00d74864b4 100644 --- a/gerbview/dialogs/gerbview_dialog_display_options_frame_base.fbp +++ b/gerbview/dialogs/gerbview_dialog_display_options_frame_base.fbp @@ -25,62 +25,28 @@ 0 0 - 1 - 1 - 1 - 1 - 0 - - - - + wxAUI_MGR_DEFAULT - - 1 - 0 - 1 1 - 0 - Dock - 0 - Left 1 impl_virtual - 1 - 0 0 wxID_ANY - - 0 - - 0 - 1 DIALOG_DISPLAY_OPTIONS_BASE - 1 - - - 1 - Resizable - 1 446,330 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER Gerbview Options - 0 - - wxFILTER_NONE - wxDefaultValidator - @@ -1140,10 +1106,6 @@ 0 - - wxFILTER_NONE - wxDefaultValidator - diff --git a/gerbview/excellon_read_drill_file.cpp b/gerbview/excellon_read_drill_file.cpp index bb15e13d20..4d3f01ce29 100644 --- a/gerbview/excellon_read_drill_file.cpp +++ b/gerbview/excellon_read_drill_file.cpp @@ -63,6 +63,7 @@ #include #include #include +#include #include #include #include @@ -430,7 +431,11 @@ bool EXCELLON_IMAGE::Execute_HEADER_Command( char*& text ) dcode = GetDCODE( iprm + FIRST_DCODE ); // Remember: dcodes are >= FIRST_DCODE if( dcode == NULL ) break; - double conv_scale = m_GerbMetric ? PCB_INTERNAL_UNIT / 25.4 : PCB_INTERNAL_UNIT; + // conv_scale = scaling factor from inch to Internal Unit + double conv_scale = MILS_TO_IU_SCALAR*1000; + if( m_GerbMetric ) + conv_scale /= 25.4; + dcode->m_Size.x = dcode->m_Size.y = wxRound( dprm * conv_scale ); dcode->m_Shape = APT_CIRCLE; break; diff --git a/gerbview/export_to_pcbnew.cpp b/gerbview/export_to_pcbnew.cpp index b59bd3e82b..23cefae601 100644 --- a/gerbview/export_to_pcbnew.cpp +++ b/gerbview/export_to_pcbnew.cpp @@ -20,7 +20,8 @@ #include #include #include -#include // BOARD_FILE_VERSION +#include +#include /* A helper class to export a Gerber set of files to Pcbnew @@ -88,29 +89,24 @@ void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event ) return; } - wxString fileName, msg; + wxString fileName; + wxString path = wxGetCwd();; - wxString PcbExt( wxT( ".brd" ) ); + wxFileDialog filedlg( this, _( "Board file name:" ), + path, fileName, LegacyPcbFileWildcard, + wxFD_OPEN ); - msg = wxT( "*" ) + PcbExt; - fileName = EDA_FileSelector( _( "Board file name:" ), - wxEmptyString, - wxEmptyString, - PcbExt, - msg, - this, - wxFD_SAVE, - false - ); - if( fileName == wxEmptyString ) + if( filedlg.ShowModal() == wxID_CANCEL ) return; + fileName = filedlg.GetPath(); + /* Install a dialog frame to choose the mapping * between gerber layers and Pcbnew layers */ - LAYERS_MAP_DIALOG* dlg = new LAYERS_MAP_DIALOG( this ); - int ok = dlg->ShowModal(); - dlg->Destroy(); + LAYERS_MAP_DIALOG* layerdlg = new LAYERS_MAP_DIALOG( this ); + int ok = layerdlg->ShowModal(); + layerdlg->Destroy(); if( ok != wxID_OK ) return; @@ -123,7 +119,7 @@ void GERBVIEW_FRAME::ExportDataInPcbnewFormat( wxCommandEvent& event ) GBR_TO_PCB_EXPORTER gbr_exporter( this, fileName ); - gbr_exporter.ExportPcb( dlg->GetLayersLookUpTable() ); + gbr_exporter.ExportPcb( layerdlg->GetLayersLookUpTable() ); } @@ -184,8 +180,18 @@ bool GBR_TO_PCB_EXPORTER::ExportPcb( int* LayerLookUpTable ) try { + wxFileName pcbFileName( m_file_name ); + PROPERTIES props; + + wxString header = wxString::Format( + wxT( "PCBNEW-BOARD Version %d date %s\n\n# Created by GerbView%s\n\n" ), + LEGACY_BOARD_FILE_VERSION, DateAndTime().GetData(), + GetBuildVersion().GetData() ); + + props["header"] = header; + PLUGIN::RELEASER pi( IO_MGR::PluginFind( IO_MGR::LEGACY ) ); - pi->Save( m_file_name, m_pcb ); + pi->Save( m_file_name, m_pcb, &props ); } catch( IO_ERROR ioe ) { diff --git a/gerbview/gerbview.cpp b/gerbview/gerbview.cpp index c31dd68c20..1ee5148df8 100644 --- a/gerbview/gerbview.cpp +++ b/gerbview/gerbview.cpp @@ -3,6 +3,29 @@ * @brief GERBVIEW main file. */ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 1992-2012 KiCad Developers, see change_log.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + #include #include #include diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index adda132947..e922cf548c 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -407,7 +408,7 @@ void GERBVIEW_FRAME::Liste_D_Codes() D_CODE* pt_D_code; wxString Line; wxArrayString list; - int scale = 10000; + double scale = MILS_TO_IU_SCALAR * 1000; int curr_layer = getActiveLayer(); for( int layer = 0; layer < 32; layer++ ) diff --git a/gerbview/rs274_read_XY_and_IJ_coordinates.cpp b/gerbview/rs274_read_XY_and_IJ_coordinates.cpp index 7453234730..001cd4947e 100644 --- a/gerbview/rs274_read_XY_and_IJ_coordinates.cpp +++ b/gerbview/rs274_read_XY_and_IJ_coordinates.cpp @@ -8,11 +8,50 @@ #include #include #include +#include /* These routines read the text string point from Text. * On exit, Text points the beginning of the sequence unread */ + +// convertion scale from gerber file units to Gerbview internal units +// depending on the gerber file format +// this scale list assumes gerber units are imperial. +// 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 +}; + + +/** + * Function scale + * converts a distance given in floating point to our internal units + * (deci-mils or nano units) + */ +int scaletoIU( double aCoord, bool isMetric ) +{ + int ret; + + if( isMetric ) + ret = wxRound( aCoord * MILS_TO_IU_SCALAR / 0.00254 ); + else + ret = wxRound( aCoord * MILS_TO_IU_SCALAR ); + + return ret; +} + + wxPoint GERBER_IMAGE::ReadXYCoord( char*& Text ) { wxPoint pos; @@ -53,10 +92,11 @@ wxPoint GERBER_IMAGE::ReadXYCoord( char*& Text ) *text = 0; if( is_float ) { - if( m_GerbMetric ) - current_coord = wxRound( atof( line ) / 0.00254 ); - else - current_coord = wxRound( atof( line ) * PCB_INTERNAL_UNIT ); + // When X or Y values are float numbers, they are given in mm or inches + if( m_GerbMetric ) // units are mm + current_coord = wxRound( atof( line ) * MILS_TO_IU_SCALAR / 0.0254 ); + else // units are inches + current_coord = wxRound( atof( line ) * MILS_TO_IU_SCALAR * 1000 ); } else { @@ -74,14 +114,7 @@ wxPoint GERBER_IMAGE::ReadXYCoord( char*& Text ) *text = 0; } current_coord = atoi( line ); - double real_scale = 1.0; - double scale_list[10] = - { - 10000.0, 1000.0, 100.0, 10.0, - 1, - 0.1, 0.01, 0.001, 0.0001,0.00001 - }; - real_scale = scale_list[fmt_scale]; + double real_scale = scale_list[fmt_scale]; if( m_GerbMetric ) real_scale = real_scale / 25.4; @@ -150,10 +183,11 @@ wxPoint GERBER_IMAGE::ReadIJCoord( char*& Text ) *text = 0; if( is_float ) { - if( m_GerbMetric ) - current_coord = wxRound( atof( line ) / 0.00254 ); - else - current_coord = wxRound( atof( line ) * PCB_INTERNAL_UNIT ); + // When X or Y values are float numbers, they are given in mm or inches + if( m_GerbMetric ) // units are mm + current_coord = wxRound( atof( line ) * MILS_TO_IU_SCALAR / 0.0254 ); + else // units are inches + current_coord = wxRound( atof( line ) * MILS_TO_IU_SCALAR * 1000 ); } else { @@ -172,18 +206,11 @@ wxPoint GERBER_IMAGE::ReadIJCoord( char*& Text ) *text = 0; } current_coord = atoi( line ); - double real_scale = 1.0; + if( fmt_scale < 0 || fmt_scale > 9 ) fmt_scale = 4; // select scale 1.0 - double scale_list[10] = - { - 10000.0, 1000.0, 100.0, 10.0, - 1, - 0.1, 0.01, 0.001, 0.0001,0.00001 - }; - real_scale = scale_list[fmt_scale]; - + double real_scale = scale_list[fmt_scale]; if( m_GerbMetric ) real_scale = real_scale / 25.4; current_coord = wxRound( current_coord * real_scale ); diff --git a/gerbview/rs274d.cpp b/gerbview/rs274d.cpp index 9d91924ee9..db58560e01 100644 --- a/gerbview/rs274d.cpp +++ b/gerbview/rs274d.cpp @@ -543,23 +543,6 @@ bool GERBER_IMAGE::Execute_G_Command( char*& text, int G_command ) } -/** - * Function scale - * converts a distance given in floating point to our deci-mils - */ -int scale( double aCoord, bool isMetric ) -{ - int ret; - - if( isMetric ) - ret = wxRound( aCoord / 0.00254 ); - else - ret = wxRound( aCoord * PCB_INTERNAL_UNIT ); - - return ret; -} - - bool GERBER_IMAGE::Execute_DCODE_Command( char*& text, int D_commande ) { wxSize size( 15, 15 ); diff --git a/gerbview/rs274x.cpp b/gerbview/rs274x.cpp index ce43d29a29..ab539e6ec6 100644 --- a/gerbview/rs274x.cpp +++ b/gerbview/rs274x.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -157,7 +158,11 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, char line[GERBER_BUFZ]; wxString msg; double fcoord; - double conv_scale = m_GerbMetric ? PCB_INTERNAL_UNIT / 25.4 : PCB_INTERNAL_UNIT; + + // conv_scale = scaling factor from inch to Internal Unit + double conv_scale = MILS_TO_IU_SCALAR*1000; + if( m_GerbMetric ) + conv_scale /= 25.4; // D( printf( "%22s: Command <%c%c>\n", __func__, (command >> 8) & 0xFF, command & 0xFF ); )