From 1d3f2d520ca407da38a5ab43bed290c68bfa47b0 Mon Sep 17 00:00:00 2001 From: charras Date: Sat, 7 Feb 2009 14:13:16 +0000 Subject: [PATCH] Pcbnew : refinements for user grig --- CHANGELOG.txt | 3 +-- common/base_screen.cpp | 16 +++++++++------- pcbnew/ioascii.cpp | 36 ------------------------------------ pcbnew/moduleframe.cpp | 29 +++++++++-------------------- pcbnew/pcbcfg.h | 31 +++---------------------------- pcbnew/pcbframe.cpp | 38 ++++++++++++++++++++++++++++---------- pcbnew/tool_pcb.cpp | 3 --- 7 files changed, 50 insertions(+), 106 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index aa57c8cf42..ccdae7f98a 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -12,8 +12,7 @@ email address. This is mandatory in Pcbnew to handle metric user grids without error (was unusable before, using integer grid size). A lot of footprints uses not metric grid. - TODO: - more refinements for user grid (mainly in read/wrire config). + refinements for user grid (mainly in read/write config). 2009-Feb-06 UPDATE Dick Hollenbeck diff --git a/common/base_screen.cpp b/common/base_screen.cpp index d908233261..7bc6ffcbd6 100644 --- a/common/base_screen.cpp +++ b/common/base_screen.cpp @@ -11,6 +11,7 @@ #include "base_struct.h" #include "sch_item_struct.h" #include "class_base_screen.h" +#include "id.h" /* Implement wxSize array for grid list implementation. */ #include @@ -356,7 +357,7 @@ void BASE_SCREEN::SetGrid( int id ) m_Grid = m_GridList[0].m_Size; wxLogWarning( _( "Grid ID %d not in grid list, falling back to " \ - "grid size( %f, %f )." ), id, m_Grid.x, m_Grid.y ); + "grid size( %g, %g )." ), id, m_Grid.x, m_Grid.y ); } void BASE_SCREEN::AddGrid( const GRID_TYPE& grid ) @@ -365,16 +366,17 @@ void BASE_SCREEN::AddGrid( const GRID_TYPE& grid ) for( i = 0; i < m_GridList.GetCount(); i++ ) { - if( m_GridList[i].m_Size == grid.m_Size ) + if( m_GridList[i].m_Size == grid.m_Size && + grid.m_Id != ID_POPUP_GRID_USER) { - wxLogDebug( wxT( "Discarding duplicate grid size( %d, %d )." ), + wxLogDebug( wxT( "Discarding duplicate grid size( %g, %g )." ), grid.m_Size.x, grid.m_Size.y ); return; } if( m_GridList[i].m_Id == grid.m_Id ) { - wxLogDebug( wxT( "Changing grid ID %d from size( %d, %d ) to " \ - "size( %d, %d )." ), + wxLogDebug( wxT( "Changing grid ID %d from size( %g, %g ) to " \ + "size( %g, %g )." ), grid.m_Id, m_GridList[i].m_Size.x, m_GridList[i].m_Size.y, grid.m_Size.x, grid.m_Size.y ); m_GridList[i].m_Size = grid.m_Size; @@ -418,8 +420,8 @@ void BASE_SCREEN::AddGrid( const wxRealPoint& size, int units, int id ) y = size.y; } - new_size = wxRealPoint( x * (double) GetInternalUnits(), - y * (double) GetInternalUnits() ); + new_size.x = x * GetInternalUnits(); + new_size.y = y * GetInternalUnits(); new_grid.m_Id = id; new_grid.m_Size = new_size; diff --git a/pcbnew/ioascii.cpp b/pcbnew/ioascii.cpp index ef03881be1..f97a38c7b8 100644 --- a/pcbnew/ioascii.cpp +++ b/pcbnew/ioascii.cpp @@ -362,38 +362,6 @@ int WinEDA_BasePcbFrame::ReadSetup( FILE* File, int* LineNum ) continue; } - if( stricmp( Line, "UserGridSize" ) == 0 ) - { - wxString msg; - if( data ) - { - msg = CONV_FROM_UTF8( data ); - msg.ToDouble( &g_UserGrid.x ); - } - else - continue; - - data = strtok( NULL, " =\n\r" ); - if( data ) - { - msg = CONV_FROM_UTF8( data ); - msg.ToDouble( &g_UserGrid.y ); - } - else - g_UserGrid.y = g_UserGrid.x; - - data = strtok( NULL, " =\n\r" ); - if( data ) - { - if( stricmp( data, "mm" ) == 0 ) - g_UserGrid_Unit = MILLIMETRE; - else - g_UserGrid_Unit = INCHES; - GetScreen()->AddGrid( g_UserGrid, g_UserGrid_Unit, - ID_POPUP_GRID_USER ); - } - continue; - } if( stricmp( Line, "DrawSegmWidth" ) == 0 ) { @@ -512,10 +480,6 @@ static int WriteSetup( FILE* aFile, WinEDA_BasePcbFrame* aFrame, BOARD* aBoard ) sprintf( text, "InternalUnit %f INCH\n", 1.0 / PCB_INTERNAL_UNIT ); fprintf( aFile, text ); - sprintf( text, "UserGridSize %lf %lf %s\n", g_UserGrid.x, g_UserGrid.y, - ( g_UserGrid_Unit == 0 ) ? "INCH" : "mm" ); - fprintf( aFile, text ); - fprintf( aFile, "ZoneGridSize %d\n", g_GridRoutingSize ); fprintf( aFile, "Layers %d\n", aBoard->GetCopperLayerCount() ); diff --git a/pcbnew/moduleframe.cpp b/pcbnew/moduleframe.cpp index dc002be9b6..8cb5d32c1a 100644 --- a/pcbnew/moduleframe.cpp +++ b/pcbnew/moduleframe.cpp @@ -19,8 +19,7 @@ #include "3d_viewer.h" // Keys used in read/write config -#define MODEDIT_CURR_GRID_X wxT( "ModEditCurrGrid_X" ) -#define MODEDIT_CURR_GRID_Y wxT( "ModEditCurrGrid_Y" ) +#define MODEDIT_CURR_GRID wxT( "ModEditCurrGrid" ) /********************************/ /* class WinEDA_ModuleEditFrame */ @@ -188,23 +187,8 @@ WinEDA_ModuleEditFrame::WinEDA_ModuleEditFrame( wxWindow* father, GetScreen()->SetCurItem( NULL ); GetSettings(); - wxRealPoint GridSize( 500, 500 ); - if( config ) - { - double SizeX, SizeY; - if( config->Read( MODEDIT_CURR_GRID_X, &SizeX ) - && config->Read( MODEDIT_CURR_GRID_Y, &SizeY ) ) - { - GridSize.x = SizeX; - GridSize.y = SizeY; - } - - } - GetScreen()->AddGrid( g_UserGrid, g_UserGrid_Unit, ID_POPUP_GRID_USER ); - GetScreen()->SetGrid( GridSize ); - SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); ReCreateMenuBar(); ReCreateHToolbar(); @@ -212,6 +196,13 @@ WinEDA_ModuleEditFrame::WinEDA_ModuleEditFrame( wxWindow* father, ReCreateVToolbar(); ReCreateOptToolbar(); + if( config ) + { + long gridselection = 1; + config->Read( MODEDIT_CURR_GRID, &gridselection ); + GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + gridselection ); + } + if( DrawPanel ) DrawPanel->m_Block_Enable = TRUE; } @@ -244,9 +235,7 @@ void WinEDA_ModuleEditFrame::OnCloseWindow( wxCloseEvent& Event ) SaveSettings(); if( config ) { - wxRealPoint GridSize = GetScreen()->GetGrid(); - config->Write( MODEDIT_CURR_GRID_X, GridSize.x ); - config->Write( MODEDIT_CURR_GRID_Y, GridSize.y ); + config->Write( MODEDIT_CURR_GRID, m_SelGridBox->GetSelection() ); } Destroy(); } diff --git a/pcbnew/pcbcfg.h b/pcbnew/pcbcfg.h index cc6663dfe6..98fa246b2c 100644 --- a/pcbnew/pcbcfg.h +++ b/pcbnew/pcbcfg.h @@ -719,31 +719,6 @@ static PARAM_CFG_INT WTraitSerigraphiePlotCfg 1, 10000 /* Min and max values*/ ); -static PARAM_CFG_DOUBLE UserGrilleXCfg -( - wxT( "UserGrX" ), /* Keyword */ - &g_UserGrid.x, /* Parameter address */ - 0.01, /* Default value */ - 0.0001, 100.0 /* Min and max values(inches)*/ -); - -static PARAM_CFG_DOUBLE UserGrilleYCfg -( - wxT( "UserGrY" ), /* Keyword */ - &g_UserGrid.y, /* Parameter address */ - 0.01, /* Default value */ - 0.0001, 100.0 /* Min and max values (inches)*/ -); - -static PARAM_CFG_INT UserGrilleUnitCfg -( - wxT( "UserGrU" ), /* Keyword */ - &g_UserGrid_Unit, /* Parameter address */ - 1, /* Default value */ - 0, 1 /* Min and max values*/ -); - - static PARAM_CFG_INT TimeOutCfg //Duree entre Sauvegardes auto en secondes ( INSETUP, @@ -803,6 +778,9 @@ static PARAM_CFG_BOOL TwoSegmentTrackBuildCfg TRUE /* Default value */ ); + +/* parameters in this list will be saved on request (when saving config). +*/ PARAM_CFG_BASE* ParamCfgList[] = { &UserLibDirBufCfg, @@ -893,9 +871,6 @@ PARAM_CFG_BASE* ParamCfgList[] = &TexteSegmLargeurCfg, &ModuleSegmWidthCfg, &WTraitSerigraphiePlotCfg, - &UserGrilleXCfg, - &UserGrilleYCfg, - &UserGrilleUnitCfg, &TimeOutCfg, &DisplPolairCfg, &CursorShapeCfg, diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index f964e9a681..f67b092140 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -17,12 +17,15 @@ #include "kbool/include/kbool/booleng.h" // Keys used in read/write config -#define PCB_CURR_GRID_X wxT( "PcbCurrGrid_X" ) -#define PCB_CURR_GRID_Y wxT( "PcbCurrGrid_Y" ) +#define PCB_CURR_GRID wxT( "PcbCurrGrid" ) #define PCB_MAGNETIC_PADS_OPT wxT( "PcbMagPadOpt" ) #define PCB_MAGNETIC_TRACKS_OPT wxT( "PcbMagTrackOpt" ) #define SHOW_MICROWAVE_TOOLS wxT( "ShowMicrowaveTools" ) +#define PCB_USER_GRID_X wxT( "PcbUserGrid_X" ) +#define PCB_USER_GRID_Y wxT( "PcbUserGrid_Y" ) +#define PCB_USER_GRID_UNIT wxT( "PcbUserGrid_Unit" ) + /*******************************/ /* class WinEDA_PcbFrame */ /*******************************/ @@ -238,21 +241,30 @@ WinEDA_PcbFrame::WinEDA_PcbFrame( wxWindow* father, GetSettings(); SetSize( m_FramePos.x, m_FramePos.y, m_FrameSize.x, m_FrameSize.y ); - wxRealPoint GridSize( 500, 500 ); + // Read some parameters from config + g_UserGrid.x = g_UserGrid.y = 0.5; // Default user grid size + g_UserGrid_Unit = 1; // Default user grid unit (0 = inch, 1 = mm) + + wxRealPoint GridSize( 500, 500 ); // Default current grid size if( config ) { double SizeX, SizeY; - if( config->Read( PCB_CURR_GRID_X, &SizeX ) - && config->Read( PCB_CURR_GRID_Y, &SizeY ) ) + if( config->Read( PCB_USER_GRID_X, &SizeX ) + && config->Read( PCB_USER_GRID_Y, &SizeY ) ) { - GridSize.x = SizeX; - GridSize.y = SizeY; + g_UserGrid.x = SizeX; + g_UserGrid.y = SizeY; } + config->Read( PCB_USER_GRID_UNIT, &g_UserGrid_Unit ); + config->Read( PCB_MAGNETIC_PADS_OPT, &g_MagneticPadOption ); config->Read( PCB_MAGNETIC_TRACKS_OPT, &g_MagneticTrackOption ); } + + GetScreen()->AddGrid( g_UserGrid, g_UserGrid_Unit, ID_POPUP_GRID_USER ); + GetScreen()->SetGrid( GridSize ); if( DrawPanel ) @@ -263,6 +275,9 @@ WinEDA_PcbFrame::WinEDA_PcbFrame( wxWindow* father, ReCreateVToolbar(); if( config ) { + long gridselection = 1; + config->Read( PCB_CURR_GRID, &gridselection ); + GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + gridselection ); long display_microwave_tools = 0; config->Read( SHOW_MICROWAVE_TOOLS, &display_microwave_tools ); if ( display_microwave_tools ) @@ -328,7 +343,7 @@ void WinEDA_PcbFrame::OnCloseWindow( wxCloseEvent& Event ) } } - while( screen ) // suppression flag modify pour eviter d'autres message + while( screen ) // Remove modify flag, to avoi others messages { screen->ClrModify(); screen = screen->Next(); @@ -342,8 +357,11 @@ void WinEDA_PcbFrame::OnCloseWindow( wxCloseEvent& Event ) if( config ) { wxRealPoint GridSize = GetScreen()->GetGrid(); - config->Write( PCB_CURR_GRID_X, GridSize.x ); - config->Write( PCB_CURR_GRID_Y, GridSize.y ); + + config->Write( PCB_USER_GRID_X, g_UserGrid.x ); + config->Write( PCB_USER_GRID_Y, g_UserGrid.y ); + config->Write( PCB_USER_GRID_UNIT, g_UserGrid_Unit ); + config->Write( PCB_CURR_GRID, m_SelGridBox->GetSelection() ); config->Write( PCB_MAGNETIC_PADS_OPT, (long) g_MagneticPadOption ); config->Write( PCB_MAGNETIC_TRACKS_OPT, (long) g_MagneticTrackOption ); config->Write( SHOW_MICROWAVE_TOOLS, (long) m_AuxVToolBar ? 1 : 0 ); diff --git a/pcbnew/tool_pcb.cpp b/pcbnew/tool_pcb.cpp index b73d03eae5..6a42a998bc 100644 --- a/pcbnew/tool_pcb.cpp +++ b/pcbnew/tool_pcb.cpp @@ -631,10 +631,7 @@ void WinEDA_PcbFrame::ReCreateAuxiliaryToolbar() msg.Printf( format.GetData(), value ); } else - { msg = _( "User Grid" ); - } - m_SelGridBox->Append( msg ); }