From c59fa1b672fe639c657252dd21b1537c8c6ceb77 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 31 Oct 2019 21:03:17 +0100 Subject: [PATCH] Gerbview: Fix outdated warning message about missing D-Codes and old RS274D files. RS274X Gerber files using only regions (polygons) can be valid, and are not old RS274D files Now a warning is raised only if there are some missing D codes definitions (RS274D file or broken RS274X file) Remove unused var and add comments Fixes: lp:1850821 https://bugs.launchpad.net/kicad/+bug/1850821 --- common/gbr_metadata.cpp | 5 +++-- gerbview/gerber_file_image.cpp | 5 +++-- gerbview/gerber_file_image.h | 4 +++- gerbview/readgerb.cpp | 18 ++++++++++++------ gerbview/rs274d.cpp | 6 ++++++ 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/common/gbr_metadata.cpp b/common/gbr_metadata.cpp index 5f73966317..e73144c3f9 100644 --- a/common/gbr_metadata.cpp +++ b/common/gbr_metadata.cpp @@ -336,10 +336,11 @@ int char2Hex( unsigned aCode ) wxString FormatStringFromGerber( const wxString& aString ) { // make the inverse conversion of FormatStringToGerber() - // It converts a "normalized" gerber string and convert it to a 16 bits sequence unicode + // It converts a "normalized" gerber string containing escape sequences + // and convert it to a 16 bits unicode char // and return a wxString (unicode 16) from the gerber string + // Note the initial gerber string can already contain unicode chars. wxString txt; // The string converted from Gerber string - wxString uniString; // the unicode string from UTF8 Gerber string but without converted escape sequence unsigned count = aString.Length(); diff --git a/gerbview/gerber_file_image.cpp b/gerbview/gerber_file_image.cpp index 052055056d..5e81d1acc2 100644 --- a/gerbview/gerber_file_image.cpp +++ b/gerbview/gerber_file_image.cpp @@ -202,8 +202,9 @@ void GERBER_FILE_IMAGE::ResetDefaultValues() m_MirrorB = false; // true: miror / axe B (default = Y) m_SwapAxis = false; // false if A = X, B = Y; true if A =Y, B = Y m_Has_DCode = false; // true = DCodes in file - // false = no DCode-> - // search for separate DCode file + // false = no DCode-> perhaps deprecated RS274D file + m_Has_MissingDCode = false; // true = some D_Codes are used, but not defined + // perhaps deprecated RS274D file m_FmtScale.x = m_FmtScale.y = 4; // Initialize default format to 3.4 => 4 m_FmtLen.x = m_FmtLen.y = 3 + 4; // Initialize default format len = 3+4 diff --git a/gerbview/gerber_file_image.h b/gerbview/gerber_file_image.h index 9cae2e0838..939b0e8c01 100644 --- a/gerbview/gerber_file_image.h +++ b/gerbview/gerber_file_image.h @@ -162,7 +162,9 @@ public: int m_Selected_Tool; // For highlight: current selected Dcode bool m_Has_DCode; // true = DCodes in file - // (false = no DCode -> separate DCode file + // false = no DCode -> perhaps deprecated RS274D file + bool m_Has_MissingDCode; // true = some DCodes in file are not defined + // (broken file or deprecated RS274D file) bool m_360Arc_enbl; // Enbl 360 deg circular interpolation bool m_PolygonFillMode; // Enable polygon mode (read coord as a polygon descr) int m_PolygonFillModeState; // In polygon mode: 0 = first segm, 1 = next segm diff --git a/gerbview/readgerb.cpp b/gerbview/readgerb.cpp index 5d466fb1e3..c0a9fe9336 100644 --- a/gerbview/readgerb.cpp +++ b/gerbview/readgerb.cpp @@ -74,14 +74,20 @@ bool GERBVIEW_FRAME::Read_GERBER_File( const wxString& GERBER_FullFileName ) dlg.ShowModal(); } - /* if the gerber file is only a RS274D file - * (i.e. without any aperture information, but with items), warn the user: + /* if the gerber file has items using D codes but missing D codes definitions, + * it can be a deprecated RS274D file (i.e. without any aperture information), + * or has missing definitions, + * warn the user: */ - if( !gerber->m_Has_DCode && gerber->GetItemsList() ) + if( gerber->GetItemsList() && gerber->m_Has_MissingDCode ) { - msg = _("Warning: this file has no D-Code definition\n" - "It is perhaps an old RS274D file\n" - "Therefore the size of items is undefined"); + if( !gerber->m_Has_DCode ) + msg = _("Warning: this file has no D-Code definition\n" + "Therefore the size of some items is undefined"); + else + msg = _("Warning: this file has some missing D-Code definitions\n" + "Therefore the size of some items is undefined"); + wxMessageBox( msg ); } diff --git a/gerbview/rs274d.cpp b/gerbview/rs274d.cpp index 0fce16b5dc..24c2141c0a 100644 --- a/gerbview/rs274d.cpp +++ b/gerbview/rs274d.cpp @@ -505,14 +505,17 @@ bool GERBER_FILE_IMAGE::Execute_G_Command( char*& text, int G_command ) case GC_SELECT_TOOL: { int D_commande = DCodeNumber( text ); + if( D_commande < FIRST_DCODE ) return false; if( D_commande > (TOOLS_MAX_COUNT - 1) ) D_commande = TOOLS_MAX_COUNT - 1; m_Current_Tool = D_commande; D_CODE* pt_Dcode = GetDCODE( D_commande ); + if( pt_Dcode ) pt_Dcode->m_InUse = true; + break; } @@ -597,8 +600,11 @@ bool GERBER_FILE_IMAGE::Execute_DCODE_Command( char*& text, int D_commande ) m_Current_Tool = D_commande; D_CODE* pt_Dcode = GetDCODE( D_commande ); + if( pt_Dcode ) pt_Dcode->m_InUse = true; + else + m_Has_MissingDCode = true; return true; }