From bfeaeafe50f538e27421c4cd3a75d3a688fba8a3 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 17 Oct 2010 18:42:06 +0200 Subject: [PATCH] Gerbview: enhancements. --- gerbview/class_GERBER.cpp | 29 +++++++++------- gerbview/class_GERBER.h | 6 ++-- gerbview/class_gerber_draw_item.cpp | 33 +++++++++++-------- gerbview/class_gerber_draw_item.h | 2 +- gerbview/edit.cpp | 1 + gerbview/files.cpp | 13 +++++--- .../gerber_test_files/test-layer-rotation.gbr | 2 +- gerbview/gerberframe.cpp | 2 ++ gerbview/initpcb.cpp | 4 +-- gerbview/rs274x.cpp | 13 +++++--- 10 files changed, 62 insertions(+), 43 deletions(-) diff --git a/gerbview/class_GERBER.cpp b/gerbview/class_GERBER.cpp index d33ee21d66..9effed15e5 100644 --- a/gerbview/class_GERBER.cpp +++ b/gerbview/class_GERBER.cpp @@ -159,8 +159,8 @@ void GERBER_IMAGE::ResetDefaultValues() // true = relative Coord m_NoTrailingZeros = false; // true: trailing zeros deleted m_ImageOffset.x = m_ImageOffset.y = 0; // Coord Offset, from IO command - m_ImageRotation = 0; // Allowed 0, 900, 1800, 2700 (in 0.1 degree - m_LocalRotation = 0; // Layer totation from RO command (in 0.1 degree) + m_ImageRotation = 0; // Allowed 0, 90, 180, 270 (in degree) + m_LocalRotation = 0.0; // Layer totation from RO command (in 0.1 degree) m_Offset.x = 0; m_Offset.y = 0; // Coord Offset, from OF command m_Scale.x = m_Scale.y = 1.0; // scale (A and B) this layer @@ -276,10 +276,12 @@ void GERBER_IMAGE::StepAndRepeatItem( const GERBER_DRAW_ITEM& aItem ) } -/** Function DisplayInfo +/** Function DisplayImageInfo * has knowledge about the frame and how and where to put status information * about this object into the frame's message panel. * Display info about Image Parameters. + * These parameters are valid for the entire file, and must set only once + * (If more than once, only the last value is used) */ void GERBER_IMAGE::DisplayImageInfo( void ) { @@ -287,20 +289,23 @@ void GERBER_IMAGE::DisplayImageInfo( void ) m_Parent->ClearMsgPanel(); - // Display Image name - m_Parent->AppendMsgPanel( _( "Image name" ), m_ImageName, BROWN ); + // Display Image name (Image specific) + m_Parent->AppendMsgPanel( _( "Image name" ), m_ImageName, CYAN ); - // Display graphic layer number + // Display graphic layer number used to draw this Image + // (not a Gerber parameter but is also image specific) msg.Printf( wxT( "%d" ), m_GraphicLayer + 1 ); m_Parent->AppendMsgPanel( _( "Graphic layer" ), msg, BROWN ); - // This next info can be see as debug info, so it can be disabled + // Display Image rotation (Image specific) + msg.Printf( wxT( "%d" ), m_ImageRotation ); + m_Parent->AppendMsgPanel( _( "Img Rot." ), msg, CYAN ); - // Display rotation - msg.Printf( wxT( "%d" ), m_ImageRotation / 10 ); - m_Parent->AppendMsgPanel( _( "Rotation" ), msg, CYAN ); + // Display Image polarity (Image specific) + msg = m_ImageNegative ? _("Negative") : _("Normal"); + m_Parent->AppendMsgPanel( _( "Polarity" ), msg, BROWN ); - // Display Image justification; + // Display Image justification and offset for justification (Image specific) msg = m_ImageJustifyXCenter ? _("Center") : _("Normal"); m_Parent->AppendMsgPanel( _( "X Justify" ), msg, DARKRED ); @@ -313,6 +318,6 @@ void GERBER_IMAGE::DisplayImageInfo( void ) else msg.Printf( wxT( "X=%f Y=%f" ), (double) m_ImageJustifyOffset.x*2.54/1000, (double) m_ImageJustifyOffset.y*2.54/1000 ); - m_Parent->AppendMsgPanel( _( "Image Justify Offset" ), msg, CYAN ); + m_Parent->AppendMsgPanel( _( "Image Justify Offset" ), msg, DARKRED ); } diff --git a/gerbview/class_GERBER.h b/gerbview/class_GERBER.h index 024b33b4f1..52f5446de0 100644 --- a/gerbview/class_GERBER.h +++ b/gerbview/class_GERBER.h @@ -95,10 +95,8 @@ public: wxPoint m_ImageOffset; // Coord Offset, from IO command wxSize m_FmtScale; // Fmt 2.3: m_FmtScale = 3, fmt 3.4: m_FmtScale = 4 wxSize m_FmtLen; // Nb chars per coord. ex fmt 2.3, m_FmtLen = 5 - int m_ImageRotation; // Image rotation (0, 90, 180, 270 - // Note these values are stored in 0.1 degrees - - int m_LocalRotation; // Local rotation, added to m_ImageRotation + int m_ImageRotation; // Image rotation (0, 90, 180, 270 only) in degrees + double m_LocalRotation; // Local rotation, in degrees, added to m_ImageRotation // Note this value is stored in 0.1 degrees wxPoint m_Offset; // Coord Offset, from OF command wxRealPoint m_Scale; // scale (X and Y) of layer. diff --git a/gerbview/class_gerber_draw_item.cpp b/gerbview/class_gerber_draw_item.cpp index 356fc2bfa5..b34aaef67a 100644 --- a/gerbview/class_gerber_draw_item.cpp +++ b/gerbview/class_gerber_draw_item.cpp @@ -57,7 +57,7 @@ GERBER_DRAW_ITEM::GERBER_DRAW_ITEM( BOARD_ITEM* aParent, GERBER_IMAGE* aGerberpa m_mirrorA = false; m_mirrorB = false; m_drawScale.x = m_drawScale.y = 1.0; - m_layerRotation = 0; + m_lyrRotation = 0; if( m_imageParams ) SetLayerParameters(); } @@ -90,7 +90,7 @@ GERBER_DRAW_ITEM::GERBER_DRAW_ITEM( const GERBER_DRAW_ITEM& aSource ) : m_layerOffset = aSource.m_layerOffset; m_drawScale.x = aSource.m_drawScale.x; m_drawScale.y = aSource.m_drawScale.y; - m_layerRotation = aSource.m_layerRotation; + m_lyrRotation = aSource.m_lyrRotation; } @@ -127,13 +127,15 @@ wxPoint GERBER_DRAW_ITEM::GetABPosition( const wxPoint& aXYPosition ) abPos += m_layerOffset + m_imageParams->m_ImageOffset; abPos.x = wxRound( abPos.x * m_drawScale.x ); abPos.y = wxRound( abPos.y * m_drawScale.y ); - int rotation = m_layerRotation + m_imageParams->m_ImageRotation; + int rotation = wxRound(m_lyrRotation*10) + (m_imageParams->m_ImageRotation*10); if( rotation ) RotatePoint( &abPos, -rotation ); + + // Negate A axis if mirrored if( m_mirrorA ) NEGATE( abPos.x ); - // abPos.y must be negated, because draw axis is top to bottom + // abPos.y must be negated when no mirror, because draw axis is top to bottom if( !m_mirrorB ) NEGATE( abPos.y ); return abPos; @@ -157,7 +159,7 @@ wxPoint GERBER_DRAW_ITEM::GetXYPosition( const wxPoint& aABPosition ) NEGATE( xyPos.x ); if( !m_mirrorB ) NEGATE( xyPos.y ); - int rotation = m_layerRotation + m_imageParams->m_ImageRotation; + int rotation = wxRound(m_lyrRotation*10) + (m_imageParams->m_ImageRotation*10); if( rotation ) RotatePoint( &xyPos, rotation ); xyPos.x = wxRound( xyPos.x / m_drawScale.x ); @@ -186,7 +188,7 @@ void GERBER_DRAW_ITEM::SetLayerParameters() m_drawScale = m_imageParams->m_Scale; // A and B scaling factor m_layerOffset = m_imageParams->m_Offset; // Offset from OF command // Rotation from RO command: - m_layerRotation = m_imageParams->m_LocalRotation; + m_lyrRotation = m_imageParams->m_LocalRotation; m_LayerNegative = m_imageParams->GetLayerParams().m_LayerNegative; } @@ -477,23 +479,26 @@ void GERBER_DRAW_ITEM::DisplayInfo( WinEDA_DrawFrame* frame ) msg.Printf( wxT( "%d" ), GetLayer() + 1 ); frame->AppendMsgPanel( _( "Graphic layer" ), msg, BROWN ); - // This next info can be see as debug info, so it can be disabled -#if 1 + // Display item rotation + // The full rotation is Image rotation + m_lyrRotation + // but m_lyrRotation is specific to this object + // so we display only this parameter + msg.Printf( wxT( "%f" ), m_lyrRotation ); + frame->AppendMsgPanel( _( "Rotation" ), msg, BLUE ); - // Display rotation - msg.Printf( wxT( "%.1f" ), (double)(m_imageParams->m_ImageRotation+m_layerRotation) / 10 ); - frame->AppendMsgPanel( _( "Rotation" ), msg, DARKRED ); + // Display item polarity (item specific) + msg = m_LayerNegative ? _("Clear") : _("Dark"); + frame->AppendMsgPanel( _( "Polarity" ), msg, BLUE ); - // Display mirroring + // Display mirroring (item specific) msg.Printf( wxT( "A:%s B:%s" ), m_mirrorA ? _("Yes") : _("No"), m_mirrorB ? _("Yes") : _("No")); frame->AppendMsgPanel( _( "Mirror" ), msg, DARKRED ); - // Display AB axis swap + // Display AB axis swap (item specific) msg = m_swapAxis ? wxT( "A=Y B=X" ) : wxT( "A=X B=Y" ); frame->AppendMsgPanel( _( "AB axis" ), msg, DARKRED ); -#endif } diff --git a/gerbview/class_gerber_draw_item.h b/gerbview/class_gerber_draw_item.h index ad3d41298d..c59bc654d0 100644 --- a/gerbview/class_gerber_draw_item.h +++ b/gerbview/class_gerber_draw_item.h @@ -92,7 +92,7 @@ private: bool m_mirrorB; // true: mirror / axe B wxRealPoint m_drawScale; // A and B scaling factor wxPoint m_layerOffset; // Offset for A and B axis, from OF parameter - int m_layerRotation; // Fine rotation, from OR parameter + double m_lyrRotation; // Fine rotation, from OR parameter, in degrees public: GERBER_DRAW_ITEM( BOARD_ITEM* aParent, GERBER_IMAGE* aGerberparams ); diff --git a/gerbview/edit.cpp b/gerbview/edit.cpp index a23c696d3c..8d083de535 100644 --- a/gerbview/edit.cpp +++ b/gerbview/edit.cpp @@ -124,6 +124,7 @@ void WinEDA_GerberFrame::Process_Special_Functions( wxCommandEvent& event ) case ID_GERBVIEW_GLOBAL_DELETE: Erase_Current_Layer( TRUE ); + ClearMsgPanel(); break; case ID_NO_SELECT_BUTT: diff --git a/gerbview/files.cpp b/gerbview/files.cpp index 06cfa234c6..9e947931dd 100644 --- a/gerbview/files.cpp +++ b/gerbview/files.cpp @@ -16,7 +16,7 @@ static void LoadDCodeFile( WinEDA_GerberFrame* frame, const wxString& FullFileName ); -/* Load agerber file selected from history list on current layer +/* Load a Gerber file selected from history list on current layer * Previous data is deleted */ void WinEDA_GerberFrame::OnFileHistory( wxCommandEvent& event ) @@ -56,10 +56,8 @@ void WinEDA_GerberFrame::Files_io( wxCommandEvent& event ) { setActiveLayer(origLayer+1); Erase_Current_Layer( false ); - if( !LoadOneGerberFile( wxEmptyString ) ) setActiveLayer(origLayer); - SetToolbars(); } else @@ -76,6 +74,7 @@ delete an existing layer to load any new layers." ), NB_LAYERS ); Clear_Pcb( true ); Zoom_Automatique( false ); DrawPanel->Refresh(); + ClearMsgPanel(); break; case ID_GERBVIEW_LOAD_DRILL_FILE: @@ -105,10 +104,14 @@ bool WinEDA_GerberFrame::LoadOneGerberFile( const wxString& aFullFileName, bool /* Standard gerber filetypes * (See http://en.wikipedia.org/wiki/Gerber_File) * the .pho extension is the default used in Pcbnew + * However there are a lot of other extensions used for gerber files + * Because the first letter is usually g, we accept g* as extension + * (Mainly internal copper layers do not have specific extention, + * and filenames are like *.g1, *.g2 *.gb1 ...). */ - filetypes = _( "Gerber files (.gb* .gt* .lgr .ger .pho)" ); + filetypes = _( "Gerber files (.g* .lgr .pho)" ); filetypes << wxT("|"); - filetypes += wxT("*.gb*;*.GB*;*.gt*;*.GT*;*.gko;*.GKO;*.GPB;*.gpb;*.lgr;*.LGR;*.ger;*.GER;*.pho;*.PHO" ); + filetypes += wxT("*.g*;*.G*;*.lgr;*.LGR;*.pho;*.PHO" ); filetypes << wxT("|"); /* Special gerber filetypes */ diff --git a/gerbview/gerber_test_files/test-layer-rotation.gbr b/gerbview/gerber_test_files/test-layer-rotation.gbr index d49e39c774..1c3696a4c5 100644 --- a/gerbview/gerber_test_files/test-layer-rotation.gbr +++ b/gerbview/gerber_test_files/test-layer-rotation.gbr @@ -4,7 +4,7 @@ G04 the center line straight up * G04 Handcoded by Julian Lamb * %MOIN*% %FSLAX23Y23*% -%RO45*% +%RO45.0*% %ADD10C,0.025*% G04 Quarter star * diff --git a/gerbview/gerberframe.cpp b/gerbview/gerberframe.cpp index 32892c3acd..09c6f288dd 100644 --- a/gerbview/gerberframe.cpp +++ b/gerbview/gerberframe.cpp @@ -497,6 +497,7 @@ void WinEDA_GerberFrame::UpdateTitleAndInfo() SetTitle( text ); SetStatusText( wxEmptyString, 0 ); m_TextInfo->Clear(); + ClearMsgPanel(); return; } @@ -504,6 +505,7 @@ void WinEDA_GerberFrame::UpdateTitleAndInfo() text << wxT( " " ) << gerber->m_FileName; SetTitle( text ); + gerber->DisplayImageInfo( ); // Display Image Name and Layer Name (from the current gerber data): text.Printf( _("Image name: \"%s\" Layer name \"%s\""), diff --git a/gerbview/initpcb.cpp b/gerbview/initpcb.cpp index c74f9a53f0..e0f2b807d8 100644 --- a/gerbview/initpcb.cpp +++ b/gerbview/initpcb.cpp @@ -25,6 +25,8 @@ bool WinEDA_GerberFrame::Clear_Pcb( bool query ) if( !IsOK( this, _( "Current data will be lost?" ) ) ) return FALSE; } + + SetCurItem( NULL ); GetBoard()->m_Drawings.DeleteAll(); for( layer = 0; layer < 32; layer++ ) @@ -45,8 +47,6 @@ bool WinEDA_GerberFrame::Clear_Pcb( bool query ) SetBaseScreen( ActiveScreen = ScreenPcb ); GetScreen()->Init(); setActiveLayer(LAYER_N_BACK); - - SetCurItem( NULL ); return TRUE; } diff --git a/gerbview/rs274x.cpp b/gerbview/rs274x.cpp index 5f91e75325..7cbd4c4e9e 100644 --- a/gerbview/rs274x.cpp +++ b/gerbview/rs274x.cpp @@ -53,6 +53,7 @@ enum RS274X_PARAMETERS { // Layer specific parameters // May be used singly or may be layer specfic // theses parameters are at the beginning of the file or layer + // and reset some layer parameters (like interpolation) LAYER_NAME = CODE( 'L', 'N' ), // Default: Positive LAYER_POLARITY = CODE( 'L', 'P' ), KNOCKOUT = CODE( 'K', 'O' ), // Default: off @@ -389,16 +390,17 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, if( strnicmp( text, "0*", 2 ) == 0 ) m_ImageRotation = 0; if( strnicmp( text, "90*", 2 ) == 0 ) - m_ImageRotation = 900; + m_ImageRotation = 90; if( strnicmp( text, "180*", 2 ) == 0 ) - m_ImageRotation = 1800; + m_ImageRotation = 180; if( strnicmp( text, "270*", 2 ) == 0 ) - m_ImageRotation = 2700; + m_ImageRotation = 270; else ReportMessage( _( "RS274X: Command \"IR\" rotation value not allowed" ) ); break; case STEP_AND_REPEAT: // command SR, like %SRX3Y2I5.0J2*% + m_Iterpolation = GERB_INTERPOL_LINEAR_1X; // Start a new Gerber layer GetLayerParams().m_StepForRepeat.x = 0.0; GetLayerParams().m_StepForRepeat.x = 0.0; // offset for Step and Repeat command GetLayerParams().m_XRepeatCount = 1; @@ -484,6 +486,7 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, break; case KNOCKOUT: + m_Iterpolation = GERB_INTERPOL_LINEAR_1X; // Start a new Gerber layer msg = _( "RS274X: Command KNOCKOUT ignored by Gerbview" ) ; ReportMessage( msg ); break; @@ -500,7 +503,8 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, break; case ROTATE: // Layer rotation: command like %RO45*% - m_LocalRotation = wxRound(ReadDouble( text ) * 10 ); + m_Iterpolation = GERB_INTERPOL_LINEAR_1X; // Start a new Gerber layer + m_LocalRotation =ReadDouble( text ); // Store layer rotation in degrees break; case IMAGE_NAME: @@ -513,6 +517,7 @@ bool GERBER_IMAGE::ExecuteRS274XCommand( int command, break; case LAYER_NAME: + m_Iterpolation = GERB_INTERPOL_LINEAR_1X; // Start a new Gerber layer GetLayerParams( ).m_LayerName.Empty(); while( *text != '*' ) {