diff --git a/3d-viewer/3d_cache/dialogs/panel_prev_3d.cpp b/3d-viewer/3d_cache/dialogs/panel_prev_3d.cpp index 697973d4c1..a3b4947a70 100644 --- a/3d-viewer/3d_cache/dialogs/panel_prev_3d.cpp +++ b/3d-viewer/3d_cache/dialogs/panel_prev_3d.cpp @@ -92,7 +92,7 @@ PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent, PCB_BASE_FRAME* aFrame, MODULE* // Create the manager m_toolManager = new TOOL_MANAGER; - m_toolManager->SetEnvironment( m_dummyBoard, nullptr, nullptr, this ); + m_toolManager->SetEnvironment( m_dummyBoard, nullptr, nullptr, nullptr, this ); m_actions = new EDA_3D_ACTIONS(); m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions ); diff --git a/3d-viewer/3d_viewer/eda_3d_viewer.cpp b/3d-viewer/3d_viewer/eda_3d_viewer.cpp index fbf6109cd2..4831cc2c8d 100644 --- a/3d-viewer/3d_viewer/eda_3d_viewer.cpp +++ b/3d-viewer/3d_viewer/eda_3d_viewer.cpp @@ -121,7 +121,7 @@ EDA_3D_VIEWER::EDA_3D_VIEWER( KIWAY *aKiway, PCB_BASE_FRAME *aParent, const wxSt // Create the manager m_toolManager = new TOOL_MANAGER; - m_toolManager->SetEnvironment( GetBoard(), nullptr, nullptr, this ); + m_toolManager->SetEnvironment( GetBoard(), nullptr, nullptr, config, this ); m_actions = new EDA_3D_ACTIONS(); m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions ); diff --git a/common/base_screen.cpp b/common/base_screen.cpp index 7876f83161..4e90f3bbd6 100644 --- a/common/base_screen.cpp +++ b/common/base_screen.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2012 Wayne Stambaugh - * Copyright (C) 1992-2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.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 @@ -24,20 +24,10 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file base_screen.cpp - * @brief BASE_SCREEN object implementation. - */ - - #include #include -#include -#include #include #include -#include // for KiROUND -#include #include @@ -52,10 +42,7 @@ BASE_SCREEN::BASE_SCREEN( EDA_ITEM* aParent, KICAD_T aType ) : m_ScreenNumber = 1; m_NumberOfScreens = 1; // Hierarchy: Root: ScreenNumber = 1 m_Zoom = 32.0; - m_Grid.m_Size = wxRealPoint( 50, 50 ); // Default grid size - m_Grid.m_CmdId = ID_POPUP_GRID_LEVEL_50; m_Center = true; - m_IsPrinting = false; m_FlagModified = false; // Set when any change is made on board. m_FlagSave = false; // Used in auto save set when an auto save is required. @@ -104,180 +91,6 @@ bool BASE_SCREEN::SetZoom( double iu_per_du ) } -int BASE_SCREEN::BuildGridsChoiceList( wxArrayString& aGridsList, bool aMmFirst) const -{ - wxString msg; - wxRealPoint curr_grid_size = GetGridSize(); - int idx = -1; - int idx_usergrid = -1; - - for( size_t i = 0; i < GetGridCount(); i++ ) - { - const GRID_TYPE& grid = m_grids[i]; - double gridValueMils = To_User_Unit( EDA_UNITS::INCHES, grid.m_Size.x ) * 1000; - double gridValue_mm = To_User_Unit( EDA_UNITS::MILLIMETRES, grid.m_Size.x ); - - if( grid.m_CmdId == ID_POPUP_GRID_USER ) - { - if( aMmFirst ) - msg.Printf( _( "User grid: %.4f mm (%.2f mils)" ), - gridValue_mm, gridValueMils ); - else - msg.Printf( _( "User grid: %.2f mils (%.4f mm)" ), - gridValueMils, gridValue_mm ); - idx_usergrid = i; - } - else - { - if( aMmFirst ) - msg.Printf( _( "Grid: %.4f mm (%.2f mils)" ), - gridValue_mm, gridValueMils ); - else - msg.Printf( _( "Grid: %.2f mils (%.4f mm)" ), - gridValueMils, gridValue_mm ); - } - - aGridsList.Add( msg ); - - if( curr_grid_size == grid.m_Size ) - idx = i; - } - - if( idx < 0 ) - idx = idx_usergrid; - - return idx; -} - - -int BASE_SCREEN::SetGrid( const wxRealPoint& size ) -{ - wxASSERT( !m_grids.empty() ); - - GRID_TYPE nearest_grid = m_grids[0]; - int gridIdx = 0; - - for( GRID_TYPE& grid : m_grids ) - { - if( grid.m_Size == size ) - { - m_Grid = grid; - return grid.m_CmdId - ID_POPUP_GRID_LEVEL_1000; - } - - // keep track of the nearest larger grid size, if the exact size is not found - if ( size.x < grid.m_Size.x ) - { - gridIdx = grid.m_CmdId - ID_POPUP_GRID_LEVEL_1000; - nearest_grid = grid; - } - } - - m_Grid = nearest_grid; - return gridIdx; -} - - -int BASE_SCREEN::SetGrid( int aCommandId ) -{ - wxASSERT( !m_grids.empty() ); - - for( GRID_TYPE& grid : m_grids ) - { - if( grid.m_CmdId == aCommandId ) - { - m_Grid = grid; - return grid.m_CmdId - ID_POPUP_GRID_LEVEL_1000; - } - } - - m_Grid = m_grids[0]; - return m_grids[0].m_CmdId - ID_POPUP_GRID_LEVEL_1000; -} - - -void BASE_SCREEN::AddGrid( const GRID_TYPE& aGrid ) -{ - for( GRID_TYPE& existing : m_grids ) - { - if( existing.m_Size == aGrid.m_Size && aGrid.m_CmdId != ID_POPUP_GRID_USER ) - { - wxLogTrace( traceScreen, "Discarding duplicate grid size( %g, %g ).", - aGrid.m_Size.x, aGrid.m_Size.y ); - return; - } - - if( existing.m_CmdId == aGrid.m_CmdId ) - { - wxLogTrace( traceScreen, wxT( "Changing grid ID %d from size( %g, %g ) to " ) \ - wxT( "size( %g, %g )." ), - aGrid.m_CmdId, existing.m_Size.x, - existing.m_Size.y, aGrid.m_Size.x, aGrid.m_Size.y ); - existing.m_Size = aGrid.m_Size; - return; - } - } - - m_grids.push_back( aGrid ); -} - - -void BASE_SCREEN::AddGrid( const wxRealPoint& size, EDA_UNITS aUnit, int id ) -{ - wxRealPoint new_size; - GRID_TYPE new_grid; - - new_size.x = From_User_Unit( aUnit, size.x ); - new_size.y = From_User_Unit( aUnit, size.y ); - new_grid.m_CmdId = id; - new_grid.m_Size = new_size; - - AddGrid( new_grid ); -} - - -GRID_TYPE& BASE_SCREEN::GetGrid( size_t aIndex ) -{ - wxCHECK_MSG( !m_grids.empty() && aIndex < m_grids.size(), m_Grid, - wxT( "Cannot get grid object outside the bounds of the grid list." ) ); - - return m_grids[ aIndex ]; -} - - -bool BASE_SCREEN::GridExists( int aCommandId ) -{ - // tests for grid command ID (not an index in grid list, but a wxID) exists in grid list. - for( GRID_TYPE& grid : m_grids) - { - if( grid.m_CmdId == aCommandId ) - return true; - } - - return false; -} - - -wxPoint BASE_SCREEN::getNearestGridPosition( const wxPoint& aPosition, - const wxPoint& aGridOrigin ) const -{ - wxPoint pt; - wxRealPoint gridSize = GetGridSize(); - - double offset = fmod( aGridOrigin.x, gridSize.x ); - int x = KiROUND( (aPosition.x - offset) / gridSize.x ); - - pt.x = KiROUND( x * gridSize.x + offset ); - - offset = fmod( aGridOrigin.y, gridSize.y ); - - int y = KiROUND( (aPosition.y - offset) / gridSize.y ); - pt.y = KiROUND ( y * gridSize.y + offset ); - - return pt; -} - - void BASE_SCREEN::ClearUndoRedoList() { ClearUndoORRedoList( m_UndoList ); @@ -334,13 +147,6 @@ void BASE_SCREEN::Show( int nestLevel, std::ostream& os ) const // for now, make it look like XML, expand on this later. NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << ">\n"; - /* this class will eventually go away, but here's a place holder until then. - for( EDA_ITEM* item = m_drawList; item; item = item->Next() ) - { - item->Show( nestLevel+1, os ); - } - */ - NestedSpace( nestLevel, os ) << "\n"; } diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index 11b277f378..6236e7b6ac 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -367,7 +367,9 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType ) if( aGalType == m_backend && m_gal != NULL ) return true; - bool result = true; // assume everything will be fine + VECTOR2D grid_size = m_gal ? m_gal->GetGridSize() : VECTOR2D(); + bool grid_visibility = m_gal ? m_gal->GetGridVisibility() : true; + bool result = true; // assume everything will be fine // Prevent refreshing canvas during backend switch StopDrawing(); @@ -437,6 +439,11 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GAL_TYPE aGalType ) clientSize.y = std::max( 10, clientSize.y ); m_gal->ResizeScreen( clientSize.GetX(), clientSize.GetY() ); + if( grid_size.x > 0 && grid_size.y > 0 ) + m_gal->SetGridSize( grid_size ); + + m_gal->SetGridVisibility( grid_visibility ); + if( m_painter ) m_painter->SetGAL( m_gal ); diff --git a/common/eda_draw_frame.cpp b/common/eda_draw_frame.cpp index d97f7f33fe..143134816b 100644 --- a/common/eda_draw_frame.cpp +++ b/common/eda_draw_frame.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2004-2017 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008 Wayne Stambaugh - * Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2020 KiCad Developers, see AUTHORS.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 @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -82,8 +81,6 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame m_messagePanel = NULL; m_currentScreen = NULL; m_showBorderAndTitleBlock = false; // true to display reference sheet. - m_LastGridSizeId = 0; - m_drawGrid = true; // hide/Show grid. default = show m_gridColor = COLOR4D( DARKGRAY ); // Default grid color m_showPageLimits = false; m_drawBgColor = COLOR4D( BLACK ); // the background color of the draw canvas: @@ -242,19 +239,10 @@ void EDA_DRAW_FRAME::OnUpdateSelectGrid( wxUpdateUIEvent& aEvent ) if( m_gridSelectBox == NULL ) return; - int select = wxNOT_FOUND; + int idx = config()->m_Window.grid.last_size_idx; - for( size_t i = 0; i < GetScreen()->GetGridCount(); i++ ) - { - if( GetScreen()->GetGridCmdId() == GetScreen()->GetGrid( i ).m_CmdId ) - { - select = (int) i; - break; - } - } - - if( select != m_gridSelectBox->GetSelection() ) - m_gridSelectBox->SetSelection( select ); + if( idx >= 0 && idx < m_gridSelectBox->GetCount() && idx != m_gridSelectBox->GetSelection() ) + m_gridSelectBox->SetSelection( idx ); } @@ -271,28 +259,28 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event ) { wxCHECK_RET( m_gridSelectBox, "m_gridSelectBox uninitialized" ); - int id = m_gridSelectBox->GetCurrentSelection() + ID_POPUP_GRID_FIRST; + int idx = m_gridSelectBox->GetCurrentSelection(); - if( id == ID_POPUP_GRID_SEPARATOR ) + if( idx == m_gridSelectBox->GetCount() - 2 ) { // wxWidgets will check the separator, which we don't want. // Re-check the current grid. wxUpdateUIEvent dummy; OnUpdateSelectGrid( dummy ); } - else if( id == ID_POPUP_GRID_SETTINGS ) + else if( idx == m_gridSelectBox->GetCount() - 1 ) { // wxWidgets will check the Grid Settings... entry, which we don't want. - // R-check the current grid. + // Re-check the current grid. wxUpdateUIEvent dummy; OnUpdateSelectGrid( dummy ); // Now run the Grid Settings... dialog wxCommandEvent dummy2; OnGridSettings( dummy2 ); } - else if( id >= ID_POPUP_GRID_FIRST && id < ID_POPUP_GRID_SEPARATOR ) + else { - m_toolManager->RunAction( ACTIONS::gridPreset, true, id - ID_POPUP_GRID_FIRST ); + m_toolManager->RunAction( ACTIONS::gridPreset, true, idx ); } UpdateStatusBar(); @@ -300,6 +288,32 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event ) } +bool EDA_DRAW_FRAME::IsGridVisible() const +{ + return config()->m_Window.grid.show; +} + + +void EDA_DRAW_FRAME::SetGridVisibility( bool aVisible ) +{ + config()->m_Window.grid.show = aVisible; + + // Update the display with the new grid + if( GetCanvas() ) + { + // Check to ensure these exist, since this function could be called before + // the GAL and View have been created + if( GetCanvas()->GetGAL() ) + GetCanvas()->GetGAL()->SetGridVisibility( aVisible ); + + if( GetCanvas()->GetView() ) + GetCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); + + GetCanvas()->Refresh(); + } +} + + void EDA_DRAW_FRAME::InitExitKey() { wxAcceleratorEntry entries[1]; @@ -392,21 +406,12 @@ void EDA_DRAW_FRAME::DisplayGridMsg() switch( m_userUnits ) { - case EDA_UNITS::INCHES: - gridformatter = "grid %.3f"; - break; - - case EDA_UNITS::MILLIMETRES: - gridformatter = "grid %.4f"; - break; - - default: - gridformatter = "grid %f"; - break; + case EDA_UNITS::INCHES: gridformatter = "grid %.3f"; break; + case EDA_UNITS::MILLIMETRES: gridformatter = "grid %.4f"; break; + default: gridformatter = "grid %f"; break; } - wxRealPoint curr_grid_size = GetScreen()->GetGridSize(); - double grid = To_User_Unit( m_userUnits, curr_grid_size.x ); + double grid = To_User_Unit( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().x ); line.Printf( gridformatter, grid ); SetStatusText( line, 4 ); @@ -419,13 +424,9 @@ void EDA_DRAW_FRAME::DisplayUnitsMsg() switch( m_userUnits ) { - case EDA_UNITS::INCHES: - msg = _( "Inches" ); - break; - case EDA_UNITS::MILLIMETRES: - msg = _( "mm" ); - break; - default: msg = _( "Units" ); break; + case EDA_UNITS::INCHES: msg = _( "Inches" ); break; + case EDA_UNITS::MILLIMETRES: msg = _( "mm" ); break; + default: msg = _( "Units" ); break; } SetStatusText( msg, 5 ); @@ -470,15 +471,6 @@ void EDA_DRAW_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) // Read units used in dialogs and toolbars SetUserUnits( static_cast( aCfg->m_System.units ) ); - // Read show/hide grid entry - SetGridVisibility( window->grid.show ); - - m_LastGridSizeId = window->grid.last_size; - - // m_LastGridSizeId is an offset, expected to be >= 0 - if( m_LastGridSizeId < 0 ) - m_LastGridSizeId = 0; - m_UndoRedoCountMax = aCfg->m_System.max_undo_items; m_firstRunDialogSetting = aCfg->m_System.first_run_shown; @@ -505,9 +497,6 @@ void EDA_DRAW_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) aCfg->m_System.units = static_cast( m_userUnits ); aCfg->m_System.first_run_shown = m_firstRunDialogSetting; - window->grid.show = IsGridVisible(); - window->grid.last_size = m_LastGridSizeId; - if( GetScreen() ) aCfg->m_System.max_undo_items = GetScreen()->GetMaxUndoItems(); @@ -660,14 +649,20 @@ bool EDA_DRAW_FRAME::saveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvas return false; } -//-----< BASE_SCREEN API moved here >-------------------------------------------- wxPoint EDA_DRAW_FRAME::GetNearestGridPosition( const wxPoint& aPosition ) const { - return GetScreen()->getNearestGridPosition( aPosition, GetGridOrigin() ); + const wxPoint& gridOrigin = GetGridOrigin(); + VECTOR2D gridSize = GetCanvas()->GetGAL()->GetGridSize(); + + double xOffset = fmod( gridOrigin.x, gridSize.x ); + int x = KiROUND( (aPosition.x - xOffset) / gridSize.x ); + double yOffset = fmod( gridOrigin.y, gridSize.y ); + int y = KiROUND( (aPosition.y - yOffset) / gridSize.y ); + + return wxPoint( KiROUND( x * gridSize.x + xOffset ), KiROUND( y * gridSize.y + yOffset ) ); } -//------------------------------------------------- const BOX2I EDA_DRAW_FRAME::GetDocumentExtents() const { diff --git a/common/settings/app_settings.cpp b/common/settings/app_settings.cpp index 9421837c4b..320d99827e 100644 --- a/common/settings/app_settings.cpp +++ b/common/settings/app_settings.cpp @@ -26,13 +26,12 @@ #include #include - ///! Update the schema version whenever a migration is required const int appSettingsSchemaVersion = 0; -APP_SETTINGS_BASE::APP_SETTINGS_BASE( std::string aFilename, int aSchemaVersion ) : - JSON_SETTINGS( std::move( aFilename ), SETTINGS_LOC::USER, aSchemaVersion ), +APP_SETTINGS_BASE::APP_SETTINGS_BASE( const std::string& aFilename, int aSchemaVersion ) : + JSON_SETTINGS( aFilename, SETTINGS_LOC::USER, aSchemaVersion ), m_Printing(), m_System(), m_Window(), m_appSettingsSchemaVersion( aSchemaVersion ) { // Make Coverity happy: @@ -211,6 +210,19 @@ bool APP_SETTINGS_BASE::migrateWindowConfig( wxConfigBase* aCfg, const std::stri ret &= fromLegacy( aCfg, aFrame + "_LastGridSize", aJsonPath + ".grid.last_size" ); + +#if defined( PCBNEW ) + double x, y; + + if( aCfg->Read( aFrame + "PcbUserGrid_X", &x ) && aCfg->Read( aFrame + "PcbUserGrid_Y", &y ) ) + { + EDA_UNITS u = (EDA_UNITS)aCfg->Read( aFrame + "PcbUserGrid_Unit", (int)EDA_UNITS::INCHES ); + + ( *this )[PointerFromString( ".grid.user_grid_x" )] = StringFromValue( u, x, true, true ); + ( *this )[PointerFromString( ".grid.user_grid_y" )] = StringFromValue( u, y, true, true ); + } +#endif + ret &= fromLegacy( aCfg, aFrame + gd + "GridAxesEnabled", aJsonPath + ".grid.axes_enabled" ); ret &= fromLegacy( aCfg, @@ -227,17 +239,18 @@ bool APP_SETTINGS_BASE::migrateWindowConfig( wxConfigBase* aCfg, const std::stri void APP_SETTINGS_BASE::addParamsForWindow( WINDOW_SETTINGS* aWindow, const std::string& aJsonPath ) { - m_params.emplace_back( - new PARAM( aJsonPath + ".maximized", &aWindow->maximized, false ) ); + m_params.emplace_back( new PARAM( aJsonPath + ".maximized", + &aWindow->maximized, false ) ); - m_params.emplace_back( new PARAM( aJsonPath + ".mru_path", &aWindow->mru_path, "" ) ); + m_params.emplace_back( new PARAM( aJsonPath + ".mru_path", + &aWindow->mru_path, "" ) ); m_params.emplace_back( new PARAM( aJsonPath + ".size_x", &aWindow->size_x, 0 ) ); m_params.emplace_back( new PARAM( aJsonPath + ".size_y", &aWindow->size_y, 0 ) ); - m_params.emplace_back( - new PARAM( aJsonPath + ".perspective", &aWindow->perspective, "" ) ); + m_params.emplace_back( new PARAM( aJsonPath + ".perspective", + &aWindow->perspective, "" ) ); m_params.emplace_back( new PARAM( aJsonPath + ".pos_x", &aWindow->pos_x, 0 ) ); @@ -246,18 +259,28 @@ void APP_SETTINGS_BASE::addParamsForWindow( WINDOW_SETTINGS* aWindow, const std: m_params.emplace_back( new PARAM( aJsonPath + ".grid.axes_enabled", &aWindow->grid.axes_enabled, false ) ); - m_params.emplace_back( - new PARAM( aJsonPath + ".grid.last_size", &aWindow->grid.last_size, 0 ) ); + m_params.emplace_back( new PARAM( aJsonPath + ".grid.last_size", + &aWindow->grid.last_size_idx, 0 ) ); - m_params.emplace_back( - new PARAM( aJsonPath + ".grid.line_width", &aWindow->grid.line_width, 1.0 ) ); + m_params.emplace_back( new PARAM_LIST( aJsonPath + ".grid.sizes", + &aWindow->grid.sizes, {} ) ); - m_params.emplace_back( - new PARAM( aJsonPath + ".grid.min_spacing", &aWindow->grid.min_spacing, 10 ) ); + m_params.emplace_back( new PARAM( aJsonPath + ".grid.user_grid_x", + &aWindow->grid.user_grid_x, "12.5 mil" ) ); + m_params.emplace_back( new PARAM( aJsonPath + ".grid.user_grid_x", + &aWindow->grid.user_grid_x, "12.5 mil" ) ); - m_params.emplace_back( new PARAM( aJsonPath + ".grid.show", &aWindow->grid.show, true ) ); + m_params.emplace_back( new PARAM( aJsonPath + ".grid.line_width", + &aWindow->grid.line_width, 1.0 ) ); - m_params.emplace_back( new PARAM( aJsonPath + ".grid.style", &aWindow->grid.style, 0 ) ); + m_params.emplace_back( new PARAM( aJsonPath + ".grid.min_spacing", + &aWindow->grid.min_spacing, 10 ) ); + + m_params.emplace_back( new PARAM( aJsonPath + ".grid.show", + &aWindow->grid.show, true ) ); + + m_params.emplace_back( new PARAM( aJsonPath + ".grid.style", + &aWindow->grid.style, 0 ) ); m_params.emplace_back( new PARAM( aJsonPath + ".cursor.always_show_cursor", &aWindow->cursor.always_show_cursor, true ) ); diff --git a/common/tool/common_tools.cpp b/common/tool/common_tools.cpp index f379be24f7..b316452735 100644 --- a/common/tool/common_tools.cpp +++ b/common/tool/common_tools.cpp @@ -30,16 +30,30 @@ #include #include #include +#include #include #include #include #include #include #include +#include + void COMMON_TOOLS::Reset( RESET_REASON aReason ) { m_frame = getEditFrame(); + + m_grids.clear(); + + for( const wxString& gridDef : m_toolMgr->GetSettings()->m_Window.grid.sizes ) + { + int gridSize = (int) ValueFromString( EDA_UNITS::MILLIMETRES, gridDef, true ); + m_grids.emplace_back( gridSize, gridSize ); + } + + if( aReason == GAL_SWITCH ) + OnGridChanged(); } @@ -62,7 +76,7 @@ int COMMON_TOOLS::CursorControl( const TOOL_EVENT& aEvent ) bool mirroredX = getView()->IsMirroredX(); VECTOR2D cursor = getViewControls()->GetRawCursorPosition( false ); - VECTOR2I gridSize = VECTOR2D( m_frame->GetScreen()->GetGridSize() ); + VECTOR2D gridSize = getView()->GetGAL()->GetGridSize(); if( fastMove ) gridSize = gridSize * 10; @@ -125,7 +139,7 @@ int COMMON_TOOLS::PanControl( const TOOL_EVENT& aEvent ) long type = aEvent.Parameter(); KIGFX::VIEW* view = getView(); VECTOR2D center = view->GetCenter(); - VECTOR2I gridSize = VECTOR2D( m_frame->GetScreen()->GetGridSize() ) * 10; + VECTOR2D gridSize = getView()->GetGAL()->GetGridSize() * 10; bool mirroredX = view->IsMirroredX(); switch( type ) @@ -336,56 +350,26 @@ int COMMON_TOOLS::doZoomToPreset( int idx, bool aCenterOnCursor ) } -/** - * Advance a BASE_SCREEN's grid forwards or backwards by the given offset and - * return the cmd ID of that grid (doesn't change the grid). - * - * This works even if the base screen's grid do not have consecutive command IDs. - * - * @param aScreen the base screen to use - * @param aOffset how many grids to advance by (negative to go backwards) - * @return the cmd ID of the requested grid, or empty if it can't be found - */ -static OPT getNextPreviousGrid( const BASE_SCREEN& aScreen, int aOffset ) -{ - const GRIDS& grids = aScreen.GetGrids(); - const GRID_TYPE& currGrid = aScreen.GetGrid(); - - auto iter = std::find_if( grids.begin(), grids.end(), - [&]( const GRID_TYPE& aCandidate ) { return aCandidate.m_CmdId == currGrid.m_CmdId; } ); - - wxCHECK_MSG( iter != grids.end(), {}, "Grid not found in screen's grid list" ); - - int index = std::distance( grids.begin(), iter ) + aOffset; - - // If we go off the end, return invalid, but we could also wrap around if wanted. - if( index < 0 || static_cast( index ) >= grids.size() ) - return {}; - - return grids[index].m_CmdId; -} - - // Grid control int COMMON_TOOLS::GridNext( const TOOL_EVENT& aEvent ) { - const OPT next_grid_id = getNextPreviousGrid( *m_frame->GetScreen(), 1 ); + int& currentGrid = m_toolMgr->GetSettings()->m_Window.grid.last_size_idx; - if( next_grid_id ) - return GridPreset( *next_grid_id - ID_POPUP_GRID_LEVEL_1000 ); + if( currentGrid + 1 < m_grids.size() ) + currentGrid++; - return 1; + return OnGridChanged(); } int COMMON_TOOLS::GridPrev( const TOOL_EVENT& aEvent ) { - const OPT next_grid_id = getNextPreviousGrid( *m_frame->GetScreen(), -1 ); + int& currentGrid = m_toolMgr->GetSettings()->m_Window.grid.last_size_idx; - if( next_grid_id ) - return GridPreset( *next_grid_id - ID_POPUP_GRID_LEVEL_1000 ); + if( currentGrid > 0 ) + currentGrid--; - return 1; + return OnGridChanged(); } @@ -397,27 +381,31 @@ int COMMON_TOOLS::GridPreset( const TOOL_EVENT& aEvent ) int COMMON_TOOLS::GridPreset( int idx ) { - BASE_SCREEN* screen = m_frame->GetScreen(); + int& currentGrid = m_toolMgr->GetSettings()->m_Window.grid.last_size_idx; - if( !screen->GridExists( idx + ID_POPUP_GRID_LEVEL_1000 ) ) - idx = 0; + currentGrid = std::max( 0, std::min( idx, (int) m_grids.size() - 1 ) ); - screen->SetGrid( idx + ID_POPUP_GRID_LEVEL_1000 ); + return OnGridChanged(); +} - // Be sure m_LastGridSizeId is up to date. - m_frame->SetLastGridSizeId( idx ); + +int COMMON_TOOLS::OnGridChanged() +{ + int& currentGrid = m_toolMgr->GetSettings()->m_Window.grid.last_size_idx; // Update the combobox (if any) wxUpdateUIEvent dummy; m_frame->OnUpdateSelectGrid( dummy ); // Update GAL canvas from screen - getView()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGridSize() ) ); + getView()->GetGAL()->SetGridSize( m_grids[ currentGrid ] ); + getView()->GetGAL()->SetGridVisibility( m_toolMgr->GetSettings()->m_Window.grid.show ); getView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); // Put cursor on new grid VECTOR2D gridCursor = getViewControls()->GetCursorPosition( true ); getViewControls()->SetCrossHairCursorPosition( gridCursor, false ); + return 0; } @@ -426,10 +414,6 @@ int COMMON_TOOLS::ToggleGrid( const TOOL_EVENT& aEvent ) { m_frame->SetGridVisibility( !m_frame->IsGridVisible() ); - m_frame->GetCanvas()->GetGAL()->SetGridVisibility( m_frame->IsGridVisible() ); - getView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); - m_frame->GetCanvas()->Refresh(); - return 0; } diff --git a/common/tool/grid_menu.cpp b/common/tool/grid_menu.cpp index 047dcdebf7..a6e9a95ab0 100644 --- a/common/tool/grid_menu.cpp +++ b/common/tool/grid_menu.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2015 CERN * @author Maciej Suminski - * Copyright (C) 2015-2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2015-2020 KiCad Developers, see AUTHORS.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 @@ -27,57 +27,89 @@ #include #include #include +#include #include #include +#include -#include using namespace std::placeholders; GRID_MENU::GRID_MENU( EDA_DRAW_FRAME* aParent ) : ACTION_MENU( true ), m_parent( aParent ) { - BASE_SCREEN* screen = m_parent->GetScreen(); - SetTitle( _( "Grid" ) ); SetIcon( grid_select_xpm ); - wxArrayString gridsList; - screen->BuildGridsChoiceList( gridsList, m_parent->GetUserUnits() != EDA_UNITS::INCHES ); + APP_SETTINGS_BASE* settings = m_parent->config(); + wxArrayString gridsList; + int i = 0; - for( unsigned int i = 0; i < gridsList.GetCount(); ++i ) - { - GRID_TYPE& grid = screen->GetGrid( i ); - Append( grid.m_CmdId, gridsList[i], wxEmptyString, wxITEM_CHECK ); - } + BuildChoiceList( &gridsList, settings, m_parent->GetUserUnits() != EDA_UNITS::INCHES ); + + for( const wxString& grid : gridsList ) + Append( i++, grid, wxEmptyString, wxITEM_CHECK ); } OPT_TOOL_EVENT GRID_MENU::eventHandler( const wxMenuEvent& aEvent ) { OPT_TOOL_EVENT event( ACTIONS::gridPreset.MakeEvent() ); - intptr_t idx = aEvent.GetId() - ID_POPUP_GRID_SELECT - 1; - event->SetParameter( idx ); - + event->SetParameter( (intptr_t) aEvent.GetId() ); return event; } void GRID_MENU::update() { - BASE_SCREEN* screen = m_parent->GetScreen(); - int currentId = screen->GetGridCmdId(); - wxArrayString gridsList; + APP_SETTINGS_BASE* settings = m_parent->config(); + int current = settings->m_Window.grid.last_size_idx; + wxArrayString gridsList; - screen->BuildGridsChoiceList( gridsList, m_parent->GetUserUnits() != EDA_UNITS::INCHES ); + BuildChoiceList( &gridsList, settings, m_parent->GetUserUnits() != EDA_UNITS::INCHES ); for( unsigned int i = 0; i < GetMenuItemCount(); ++i ) { - GRID_TYPE& grid = screen->GetGrid( i ); wxMenuItem* menuItem = FindItemByPosition( i ); - menuItem->SetId( grid.m_CmdId ); - menuItem->SetItemLabel( gridsList[ i ] ); // Refresh label in case units have changed - menuItem->Check( grid.m_CmdId == currentId ); // Refresh checkmark + menuItem->SetItemLabel( gridsList[ i ] ); // Refresh label in case units have changed + menuItem->Check( i == current ); // Refresh checkmark } } + + +void GRID_MENU::BuildChoiceList( wxArrayString* aGridsList, APP_SETTINGS_BASE* aCfg, bool mmFirst ) +{ + wxString msg; + + for( const wxString& gridSize : aCfg->m_Window.grid.sizes ) + { + int val = (int) ValueFromString( EDA_UNITS::MILLIMETRES, gridSize, true ); + double gridValueMils = To_User_Unit( EDA_UNITS::INCHES, val ) * 1000; + double gridValue_mm = To_User_Unit( EDA_UNITS::MILLIMETRES, val ); + + if( mmFirst ) + msg.Printf( _( "Grid: %.4f mm (%.2f mils)" ), gridValue_mm, gridValueMils ); + else + msg.Printf( _( "Grid: %.2f mils (%.4f mm)" ), gridValueMils, gridValue_mm ); + + aGridsList->Add( msg ); + } + + + if( !aCfg->m_Window.grid.user_grid_x.empty() ) + { + int val = (int) ValueFromString( EDA_UNITS::INCHES, aCfg->m_Window.grid.user_grid_x, true ); + double gridValueMils = To_User_Unit( EDA_UNITS::INCHES, val ) * 1000; + double gridValue_mm = To_User_Unit( EDA_UNITS::MILLIMETRES, val ); + + if( mmFirst ) + msg.Printf( _( "User grid: %.4f mm (%.2f mils)" ), gridValue_mm, gridValueMils ); + else + msg.Printf( _( "User grid: %.2f mils (%.4f mm)" ), gridValueMils, gridValue_mm ); + + aGridsList->Add( msg ); + } +} + + diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp index 62e0ca228c..e13d252ddf 100644 --- a/common/tool/tool_manager.cpp +++ b/common/tool/tool_manager.cpp @@ -1013,12 +1013,14 @@ TOOL_ID TOOL_MANAGER::MakeToolId( const std::string& aToolName ) void TOOL_MANAGER::SetEnvironment( EDA_ITEM* aModel, KIGFX::VIEW* aView, - KIGFX::VIEW_CONTROLS* aViewControls, TOOLS_HOLDER* aFrame ) + KIGFX::VIEW_CONTROLS* aViewControls, + APP_SETTINGS_BASE* aSettings, TOOLS_HOLDER* aFrame ) { m_model = aModel; m_view = aView; m_viewControls = aViewControls; m_frame = aFrame; + m_settings = aSettings; } diff --git a/cvpcb/cvpcb_mainframe.cpp b/cvpcb/cvpcb_mainframe.cpp index 8b402e54d7..4966a369dd 100644 --- a/cvpcb/cvpcb_mainframe.cpp +++ b/cvpcb/cvpcb_mainframe.cpp @@ -190,7 +190,7 @@ void CVPCB_MAINFRAME::setupTools() // Create the manager m_actions = new CVPCB_ACTIONS(); m_toolManager = new TOOL_MANAGER; - m_toolManager->SetEnvironment( nullptr, nullptr, nullptr, this ); + m_toolManager->SetEnvironment( nullptr, nullptr, nullptr, config(), this ); m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions ); // Register tools diff --git a/cvpcb/display_footprints_frame.cpp b/cvpcb/display_footprints_frame.cpp index 0eec6d0bdd..34e5f61c43 100644 --- a/cvpcb/display_footprints_frame.cpp +++ b/cvpcb/display_footprints_frame.cpp @@ -92,12 +92,6 @@ DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME( KIWAY* aKiway, wxWindow* aPa LoadSettings( config() ); - // Initialize grid id to a default value if not found in config or incorrect: - if( !( GetScreen()->GridExists( m_LastGridSizeId + ID_POPUP_GRID_LEVEL_1000 ) ) ) - m_LastGridSizeId = ID_POPUP_GRID_LEVEL_500 - ID_POPUP_GRID_LEVEL_1000; - - GetScreen()->SetGrid( m_LastGridSizeId + ID_POPUP_GRID_LEVEL_1000 ); - // Initialize some display options auto displ_opts = GetDisplayOptions(); displ_opts.m_DisplayPadIsol = false; // Pad clearance has no meaning here @@ -109,7 +103,7 @@ DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME( KIWAY* aKiway, wxWindow* aPa // Create the manager and dispatcher & route draw panel events to the dispatcher m_toolManager = new TOOL_MANAGER; m_toolManager->SetEnvironment( GetBoard(), gal_drawPanel->GetView(), - gal_drawPanel->GetViewControls(), this ); + gal_drawPanel->GetViewControls(), config(), this ); m_actions = new CVPCB_ACTIONS(); m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions ); gal_drawPanel->SetEventDispatcher( m_toolDispatcher ); @@ -135,16 +129,11 @@ DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME( KIWAY* aKiway, wxWindow* aPa m_auimgr.SetManagedWindow( this ); - m_auimgr.AddPane( m_mainToolBar, - EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) ); - m_auimgr.AddPane( m_optionsToolBar, - EDA_PANE().VToolbar().Name( "OptToolbar" ).Left().Layer(3) ); - m_auimgr.AddPane( m_infoBar, - EDA_PANE().InfoBar().Name( "InfoBar" ).Top().Layer(1) ); - m_auimgr.AddPane( GetCanvas(), - EDA_PANE().Canvas().Name( "DrawFrame" ).Center() ); - m_auimgr.AddPane( m_messagePanel, - EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) ); + m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) ); + m_auimgr.AddPane( m_optionsToolBar, EDA_PANE().VToolbar().Name( "OptToolbar" ).Left().Layer(3) ); + m_auimgr.AddPane( m_infoBar, EDA_PANE().InfoBar().Name( "InfoBar" ).Top().Layer(1) ); + m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() ); + m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ).Bottom().Layer(6) ); // Call Update() to fix all pane default sizes, especially the "InfoBar" pane before // hidding it. @@ -199,7 +188,6 @@ void DISPLAY_FOOTPRINTS_FRAME::OnCloseWindow( wxCloseEvent& event ) void DISPLAY_FOOTPRINTS_FRAME::ReCreateVToolbar() { // Currently, no vertical right toolbar. - // So do nothing } @@ -280,7 +268,7 @@ void DISPLAY_FOOTPRINTS_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) // We don't allow people to change this right now, so make sure it's on GetWindowSettings( cfg )->cursor.always_show_cursor = true; - EDA_DRAW_FRAME::LoadSettings( cfg ); + PCB_BASE_FRAME::LoadSettings( cfg ); SetDisplayOptions( cfg->m_FootprintViewerDisplayOptions ); } @@ -291,7 +279,7 @@ void DISPLAY_FOOTPRINTS_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) auto cfg = dynamic_cast( aCfg ); wxCHECK( cfg, /* void */ ); - EDA_DRAW_FRAME::SaveSettings( cfg ); + PCB_BASE_FRAME::SaveSettings( cfg ); cfg->m_FootprintViewerDisplayOptions = GetDisplayOptions(); @@ -315,17 +303,6 @@ MAGNETIC_SETTINGS* DISPLAY_FOOTPRINTS_FRAME::GetMagneticItemsSettings() } -void DISPLAY_FOOTPRINTS_FRAME::ApplyDisplaySettingsToGAL() -{ - auto painter = static_cast( GetCanvas()->GetView()->GetPainter() ); - - painter->GetSettings()->LoadDisplayOptions( GetDisplayOptions(), false ); - - GetCanvas()->GetView()->UpdateAllItems( KIGFX::ALL ); - GetCanvas()->Refresh(); -} - - /** * Virtual function needed by the PCB_SCREEN class derived from BASE_SCREEN * this is a virtual pure function in BASE_SCREEN diff --git a/cvpcb/display_footprints_frame.h b/cvpcb/display_footprints_frame.h index 90013cd796..8c96a79fbe 100644 --- a/cvpcb/display_footprints_frame.h +++ b/cvpcb/display_footprints_frame.h @@ -76,9 +76,6 @@ public: MAGNETIC_SETTINGS* GetMagneticItemsSettings() override; - /// Updates the GAL with display settings changes - void ApplyDisplaySettingsToGAL(); - ///> @copydoc EDA_DRAW_FRAME::UpdateMsgPanel() void UpdateMsgPanel() override; diff --git a/eeschema/dialogs/dialog_print_using_printer.cpp b/eeschema/dialogs/dialog_print_using_printer.cpp index 23c2f6d92e..e83129f99f 100644 --- a/eeschema/dialogs/dialog_print_using_printer.cpp +++ b/eeschema/dialogs/dialog_print_using_printer.cpp @@ -486,8 +486,6 @@ void SCH_PRINTOUT::PrintPage( SCH_SCREEN* aScreen ) dc->SetLogicalFunction( wxCOPY ); GRResetPenAndBrush( dc ); - aScreen->m_IsPrinting = true; - COLOR4D savedBgColor = m_parent->GetDrawBgColor(); COLOR4D bgColor = m_parent->GetColorSettings()->GetColor( LAYER_SCHEMATIC_BACKGROUND ); @@ -529,7 +527,6 @@ void SCH_PRINTOUT::PrintPage( SCH_SCREEN* aScreen ) aScreen->Print( &renderSettings ); m_parent->SetDrawBgColor( savedBgColor ); - aScreen->m_IsPrinting = false; GRForceBlackPen( false ); diff --git a/eeschema/dialogs/dialog_set_grid.cpp b/eeschema/dialogs/dialog_set_grid.cpp index dca6c7c930..32bbb8c1f6 100644 --- a/eeschema/dialogs/dialog_set_grid.cpp +++ b/eeschema/dialogs/dialog_set_grid.cpp @@ -23,11 +23,10 @@ #include #include +#include +#include #include -#include -#include -#include - +#include class DIALOG_SET_GRID : public DIALOG_SET_GRID_BASE { @@ -53,16 +52,16 @@ DIALOG_SET_GRID::DIALOG_SET_GRID( SCH_BASE_FRAME* aParent ): bool DIALOG_SET_GRID::TransferDataToWindow() { - const GRIDS& gridSizes = m_frame->GetScreen()->GetGrids(); + int idx = m_frame->config()->m_Window.grid.last_size_idx; + wxArrayString grids; - for( size_t i = 0; i < gridSizes.size(); i++ ) - { - m_choiceGridSize->Append( wxString::Format( "%0.1f", - static_cast( Iu2Mils( gridSizes[i].m_Size.x ) ) ) ); + GRID_MENU::BuildChoiceList( &grids, m_frame->config(), GetUserUnits() != EDA_UNITS::INCHES ); - if( gridSizes[i].m_CmdId == m_frame->GetScreen()->GetGridCmdId() ) - m_choiceGridSize->SetSelection( (int) i ); - } + for( const wxString& grid : grids ) + m_choiceGridSize->Append( grid ); + + if( idx >= 0 && idx < m_choiceGridSize->GetCount() ) + m_choiceGridSize->SetSelection( idx ); return true; } @@ -70,12 +69,9 @@ bool DIALOG_SET_GRID::TransferDataToWindow() bool DIALOG_SET_GRID::TransferDataFromWindow() { - const GRIDS& gridSizes = m_frame->GetScreen()->GetGrids(); - wxRealPoint gridSize = gridSizes[ (size_t) m_choiceGridSize->GetSelection() ].m_Size; - m_frame->SetLastGridSizeId( m_frame->GetScreen()->SetGrid( gridSize ) ); + int idx = m_choiceGridSize->GetSelection(); - m_frame->GetCanvas()->GetView()->GetGAL()->SetGridSize( VECTOR2D( gridSize ) ); - m_frame->GetCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); + m_frame->GetToolManager()->RunAction( "common.Control.gridPreset", true, idx ); return true; } diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index 72c74f268c..fff04f88da 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -416,23 +416,44 @@ void SCH_BASE_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) EDA_DRAW_FRAME::LoadSettings( aCfg ); - if( eeconfig() ) + EESCHEMA_SETTINGS* cfg = dynamic_cast( aCfg ); + wxCHECK( cfg, /*void*/ ); + + if( cfg->m_Window.grid.sizes.empty() ) { - wxString templateFieldNames = eeconfig()->m_Drawing.field_names; + /* + * Do NOT add others values (mainly grid values in mm), because they can break the + * schematic: Because wires and pins are considered as connected when the are to the + * same coordinate we cannot mix coordinates in mils (internal units) and mm (that + * cannot exactly converted in mils in many cases). In fact schematic must only use + * 50 and 25 mils to place labels, wires and components others values are useful only + * for graphic items (mainly in library editor) so use integer values in mils only. + * The 100 mil grid is added to help conform to the KiCad Library Convention which + * states: "Using a 100mil grid, pin ends and origin must lie on grid nodes IEC-60617" + */ + cfg->m_Window.grid.sizes = { "100 mil", + "50 mil", + "25 mil", + "10 mil", + "5 mil", + "2 mil", + "1 mil" }; + } - if( !templateFieldNames.IsEmpty() ) + wxString templateFieldNames = cfg->m_Drawing.field_names; + + if( !templateFieldNames.IsEmpty() ) + { + TEMPLATE_FIELDNAMES_LEXER lexer( TO_UTF8( templateFieldNames ) ); + + try { - TEMPLATE_FIELDNAMES_LEXER lexer( TO_UTF8( templateFieldNames ) ); - - try - { - m_templateFieldNames.Parse( &lexer, true ); - } - catch( const IO_ERROR& DBG( e ) ) - { - // @todo show error msg - DBG( printf( "templatefieldnames parsing error: '%s'\n", TO_UTF8( e.What() ) ); ) - } + m_templateFieldNames.Parse( &lexer, true ); + } + catch( const IO_ERROR& DBG( e ) ) + { + // @todo show error msg + DBG( printf( "templatefieldnames parsing error: '%s'\n", TO_UTF8( e.What() ) ); ) } } } diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 3dffa6a14c..057c6531c9 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -481,7 +481,6 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in GetScreen()->m_Initialized = true; } - GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); m_toolManager->RunAction( ACTIONS::zoomFitScreen, true ); SetSheetNumberAndCount(); @@ -538,7 +537,6 @@ bool SCH_EDIT_FRAME::AppendSchematic() SCH_SCREENS screens( GetCurrentSheet().Last() ); screens.TestDanglingEnds(); - GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); m_toolManager->RunAction( ACTIONS::zoomFitScreen, true ); SetSheetNumberAndCount(); @@ -844,7 +842,6 @@ bool SCH_EDIT_FRAME::importFile( const wxString& aFileName, int aFileType ) GetScreen()->ClearUndoORRedoList( GetScreen()->m_UndoList, 1 ); - GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); m_toolManager->RunAction( ACTIONS::zoomFitScreen, true ); SetSheetNumberAndCount(); SyncView(); diff --git a/eeschema/hierarch.cpp b/eeschema/hierarch.cpp index 39004578ff..123bd82ddf 100644 --- a/eeschema/hierarch.cpp +++ b/eeschema/hierarch.cpp @@ -235,10 +235,7 @@ void SCH_EDIT_FRAME::DisplayCurrentSheet() wxASSERT( screen ); - // Switch to current sheet, - // and update the grid size, because it can be modified in latest screen SetScreen( screen ); - GetScreen()->SetGrid( m_LastGridSizeId + ID_POPUP_GRID_LEVEL_1000 ); // update the References GetCurrentSheet().UpdateAllScreenReferences(); diff --git a/eeschema/lib_view_frame.cpp b/eeschema/lib_view_frame.cpp index ee34b47867..bb1673c88e 100644 --- a/eeschema/lib_view_frame.cpp +++ b/eeschema/lib_view_frame.cpp @@ -126,9 +126,6 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame m_cmpListWidth = 300; m_listPowerCmpOnly = false; - // Initialize grid id to the default value (50 mils): - m_LastGridSizeId = ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000; - SetScreen( new SCH_SCREEN ); GetScreen()->m_Center = true; // Axis origin centered on screen. LoadSettings( config() ); @@ -137,7 +134,6 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame KIGFX::GAL_DISPLAY_OPTIONS& gal_opts = GetGalDisplayOptions(); gal_opts.m_axesEnabled = true; GetCanvas()->GetGAL()->SetAxesEnabled( true ); - GetCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() ); GetRenderSettings()->m_ShowHiddenText = true; GetRenderSettings()->m_ShowHiddenPins = true; @@ -188,8 +184,6 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame m_auimgr.Update(); - GetToolManager()->RunAction( ACTIONS::gridPreset, true, m_LastGridSizeId ); - if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame { Raise(); @@ -228,7 +222,7 @@ void LIB_VIEW_FRAME::setupTools() // Create the manager and dispatcher & route draw panel events to the dispatcher m_toolManager = new TOOL_MANAGER; m_toolManager->SetEnvironment( GetScreen(), GetCanvas()->GetView(), - GetCanvas()->GetViewControls(), this ); + GetCanvas()->GetViewControls(), config(), this ); m_actions = new EE_ACTIONS(); m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions ); @@ -618,7 +612,7 @@ void LIB_VIEW_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) { auto cfg = Pgm().GetSettingsManager().GetAppSettings(); - EDA_DRAW_FRAME::LoadSettings( cfg ); + SCH_BASE_FRAME::LoadSettings( cfg ); // Grid shape, etc. GetGalDisplayOptions().ReadWindowSettings( cfg->m_LibViewPanel.window ); @@ -641,7 +635,7 @@ void LIB_VIEW_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg) { EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); - EDA_DRAW_FRAME::SaveSettings( cfg ); + SCH_BASE_FRAME::SaveSettings( cfg ); if( m_libListWidth && m_libList ) m_libListWidth = m_libList->GetSize().x; diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp index c2a8b582c9..3747f6ef4b 100644 --- a/eeschema/libedit/lib_edit_frame.cpp +++ b/eeschema/libedit/lib_edit_frame.cpp @@ -103,9 +103,6 @@ LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : m_convert = 1; m_AboutTitle = "LibEdit"; - // Initialize grid id to the default value 50 mils: - m_LastGridSizeId = ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000; - wxIcon icon; icon.CopyFromBitmap( KiBitmap( icon_libedit_xpm ) ); SetIcon( icon ); @@ -168,15 +165,12 @@ LIB_EDIT_FRAME::LIB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : m_auimgr.GetPane( "InfoBar" ).Hide(); m_auimgr.Update(); - GetToolManager()->RunAction( "common.Control.gridPreset", true, m_LastGridSizeId ); - Raise(); Show( true ); SyncView(); GetCanvas()->GetViewControls()->SetSnapping( true ); GetCanvas()->GetView()->UseDrawPriority( true ); - GetCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() ); GetCanvas()->GetGAL()->SetAxesEnabled( true ); // Set the working/draw area size to display a symbol to a reasonable value: @@ -255,7 +249,7 @@ void LIB_EDIT_FRAME::setupTools() // Create the manager and dispatcher & route draw panel events to the dispatcher m_toolManager = new TOOL_MANAGER; m_toolManager->SetEnvironment( GetScreen(), GetCanvas()->GetView(), - GetCanvas()->GetViewControls(), this ); + GetCanvas()->GetViewControls(), config(), this ); m_actions = new EE_ACTIONS(); m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions ); diff --git a/eeschema/libedit/libedit.cpp b/eeschema/libedit/libedit.cpp index add4b0e3fd..061f251090 100644 --- a/eeschema/libedit/libedit.cpp +++ b/eeschema/libedit/libedit.cpp @@ -34,15 +34,11 @@ #include #include #include -#include #include #include #include #include #include -#include -#include -#include #include #include #include @@ -200,23 +196,6 @@ bool LIB_EDIT_FRAME::LoadComponentFromCurrentLib( const wxString& aAliasName, in return true; } -/** - * Synchronize screen settings from a current screen into another screen. - * - * This can be used, for example, when loading a new screen into a frame, - * but you want the new screen to inherit some settings (e.g. grids) from the - * frame's current screen. - * - * @param aCurrentScreen the existing frame screen - * @param aIncomingScreen a screen that is intended to replace the current screen - */ -static void synchronizeLibEditScreenSettings( const SCH_SCREEN& aCurrentScreen, - SCH_SCREEN& aIncomingScreen ) -{ - aIncomingScreen.SetGrid( aCurrentScreen.GetGridSize() ); -} - - bool LIB_EDIT_FRAME::LoadOneLibraryPartAux( LIB_PART* aEntry, const wxString& aLibrary, int aUnit, int aConvert ) { @@ -240,14 +219,6 @@ bool LIB_EDIT_FRAME::LoadOneLibraryPartAux( LIB_PART* aEntry, const wxString& aL // The buffered screen for the part SCH_SCREEN* part_screen = m_libMgr->GetScreen( lib_part->GetName(), aLibrary ); - const SCH_SCREEN* curr_screen = GetScreen(); - - // Before we set the frame screen, transfer any settings from the current - // screen that we want to keep to the incoming (buffered) part's screen - // which could be out of date relative to the current screen. - if( curr_screen ) - synchronizeLibEditScreenSettings( *curr_screen, *part_screen ); - SetScreen( part_screen ); SetCurPart( new LIB_PART( *lib_part ) ); SetCurLib( aLibrary ); diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index 1756cf2348..8a2dc0831e 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -442,8 +442,6 @@ void SCH_BASE_FRAME::RemoveFromScreen( EDA_ITEM* aItem, SCH_SCREEN* aScreen ) void SCH_BASE_FRAME::SyncView() { - auto gs = GetScreen()->GetGridSize(); - GetCanvas()->GetGAL()->SetGridSize( VECTOR2D( gs.x, gs.y )); GetCanvas()->GetView()->UpdateAllItems( KIGFX::ALL ); } diff --git a/eeschema/sch_draw_panel.cpp b/eeschema/sch_draw_panel.cpp index 2bb5d6d8b2..5991d1278f 100644 --- a/eeschema/sch_draw_panel.cpp +++ b/eeschema/sch_draw_panel.cpp @@ -137,18 +137,10 @@ void SCH_DRAW_PANEL::setDefaultLayerOrder() bool SCH_DRAW_PANEL::SwitchBackend( GAL_TYPE aGalType ) { - VECTOR2D grid_size = m_gal->GetGridSize(); bool rv = EDA_DRAW_PANEL_GAL::SwitchBackend( aGalType ); setDefaultLayerDeps(); m_gal->SetWorldUnitLength( SCH_WORLD_UNIT ); - // Keep grid size and grid visibility: - m_gal->SetGridSize( grid_size ); - SCH_BASE_FRAME* frame = dynamic_cast( GetParentEDAFrame() ); - - if( frame ) - m_gal->SetGridVisibility( frame->IsGridVisible() ); - Refresh(); return rv; diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 93379990f8..f14a0130ee 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -226,9 +226,6 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ): icon.CopyFromBitmap( KiBitmap( icon_eeschema_xpm ) ); SetIcon( icon ); - // Initialize grid id to the default value (50 mils): - m_LastGridSizeId = ID_POPUP_GRID_LEVEL_50 - ID_POPUP_GRID_LEVEL_1000; - LoadSettings( eeconfig() ); CreateScreens(); @@ -273,12 +270,8 @@ SCH_EDIT_FRAME::SCH_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ): GetToolManager()->RunAction( ACTIONS::zoomFitScreen, true ); - // Init grid size and visibility - GetToolManager()->RunAction( ACTIONS::gridPreset, true, m_LastGridSizeId ); - if( GetCanvas() ) { - GetCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() ); GetCanvas()->GetGAL()->SetAxesEnabled( false ); if( auto p = dynamic_cast( GetCanvas()->GetView()->GetPainter() ) ) @@ -319,7 +312,7 @@ void SCH_EDIT_FRAME::setupTools() // Create the manager and dispatcher & route draw panel events to the dispatcher m_toolManager = new TOOL_MANAGER; m_toolManager->SetEnvironment( &Schematic(), GetCanvas()->GetView(), - GetCanvas()->GetViewControls(), this ); + GetCanvas()->GetViewControls(), config(), this ); m_actions = new EE_ACTIONS(); m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions ); diff --git a/eeschema/sch_screen.cpp b/eeschema/sch_screen.cpp index 38d995754e..1890524b50 100644 --- a/eeschema/sch_screen.cpp +++ b/eeschema/sch_screen.cpp @@ -66,7 +66,6 @@ // TODO(JE) Debugging only #include -#define EESCHEMA_FILE_STAMP "EESchema" #define ZOOM_FACTOR( x ) ( x * IU_PER_MILS ) @@ -97,29 +96,6 @@ static double SchematicZoomList[] = }; -/* Default grid sizes for the schematic editor. - * Do NOT add others values (mainly grid values in mm), because they - * can break the schematic: Because wires and pins are considered as - * connected when the are to the same coordinate we cannot mix - * coordinates in mils (internal units) and mm (that cannot exactly - * converted in mils in many cases). In fact schematic must only use - * 50 and 25 mils to place labels, wires and components others values - * are useful only for graphic items (mainly in library editor) so use - * integer values in mils only. The 100 mil grid is added to help - * conform to the KiCad Library Convention. Which states: "Using a - * 100mil grid, pin ends and origin must lie on grid nodes IEC-60617" -*/ -static GRID_TYPE SchematicGridList[] = { - { ID_POPUP_GRID_LEVEL_100, wxRealPoint( Mils2iu( 100 ), Mils2iu( 100 ) ) }, - { ID_POPUP_GRID_LEVEL_50, wxRealPoint( Mils2iu( 50 ), Mils2iu( 50 ) ) }, - { ID_POPUP_GRID_LEVEL_25, wxRealPoint( Mils2iu( 25 ), Mils2iu( 25 ) ) }, - { ID_POPUP_GRID_LEVEL_10, wxRealPoint( Mils2iu( 10 ), Mils2iu( 10 ) ) }, - { ID_POPUP_GRID_LEVEL_5, wxRealPoint( Mils2iu( 5 ), Mils2iu( 5 ) ) }, - { ID_POPUP_GRID_LEVEL_2, wxRealPoint( Mils2iu( 2 ), Mils2iu( 2 ) ) }, - { ID_POPUP_GRID_LEVEL_1, wxRealPoint( Mils2iu( 1 ), Mils2iu( 1 ) ) }, -}; - - SCH_SCREEN::SCH_SCREEN( EDA_ITEM* aParent ) : BASE_SCREEN( aParent, SCH_SCREEN_T ), m_paper( wxT( "A4" ) ) @@ -131,12 +107,6 @@ SCH_SCREEN::SCH_SCREEN( EDA_ITEM* aParent ) : for( unsigned zoom : SchematicZoomList ) m_ZoomList.push_back( zoom ); - for( GRID_TYPE grid : SchematicGridList ) - AddGrid( grid ); - - // Set the default grid size, now that the grid list is populated - SetGrid( wxRealPoint( Mils2iu( 50 ), Mils2iu( 50 ) ) ); - m_refCount = 0; // Suitable for schematic only. For libedit and viewlib, must be set to true diff --git a/eeschema/sch_screen.h b/eeschema/sch_screen.h index 3979848836..8eb87bd59f 100644 --- a/eeschema/sch_screen.h +++ b/eeschema/sch_screen.h @@ -115,7 +115,7 @@ private: /// Origin of the auxiliary axis, which is used in exports mostly, but not yet in EESCHEMA wxPoint m_aux_origin; - EE_RTREE m_rtree; + EE_RTREE m_rtree; int m_modification_sync; ///< inequality with PART_LIBS::GetModificationHash() ///< will trigger ResolveAll(). @@ -159,15 +159,8 @@ public: SCHEMATIC* Schematic() const; - EE_RTREE& Items() - { - return m_rtree; - } - - const EE_RTREE& Items() const - { - return m_rtree; - } + EE_RTREE& Items() { return m_rtree; } + const EE_RTREE& Items() const { return m_rtree; } bool IsEmpty() { @@ -203,9 +196,7 @@ public: void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) { m_titles = aTitleBlock; } void DecRefCount(); - void IncRefCount(); - int GetRefCount() const { return m_refCount; } /** @@ -254,8 +245,8 @@ public: * @param aType The type of item to find. * @return The item found that meets the search criteria or NULL if none found. */ - SCH_ITEM* GetItem( - const wxPoint& aPosition, int aAccuracy = 0, KICAD_T aType = SCH_LOCATE_ANY_T ); + SCH_ITEM* GetItem( const wxPoint& aPosition, int aAccuracy = 0, + KICAD_T aType = SCH_LOCATE_ANY_T ); void Place( SCH_EDIT_FRAME* frame, wxDC* DC ) { }; @@ -405,7 +396,7 @@ public: * @return The pin item if found, otherwise NULL. */ LIB_PIN* GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent = NULL, - bool aEndPointOnly = false ); + bool aEndPointOnly = false ); /** * Test the screen if \a aPosition is a sheet label object. diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index a594b8a576..6247bb533c 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -598,7 +598,6 @@ void SCH_EDIT_FRAME::DrawCurrentSheetToClipboard() GRResetPenAndBrush( &dc ); GRForceBlackPen( false ); - screen->m_IsPrinting = true; dc.SetUserScale( scale, scale ); dc.Clear(); @@ -606,8 +605,6 @@ void SCH_EDIT_FRAME::DrawCurrentSheetToClipboard() PrintPage( GetRenderSettings() ); - screen->m_IsPrinting = false; - if( wxTheClipboard->Open() ) { // This data objects are held by the clipboard, so do not delete them in the app. diff --git a/eeschema/tools/ee_inspection_tool.cpp b/eeschema/tools/ee_inspection_tool.cpp index c2f0d8e9e2..8e185fb887 100644 --- a/eeschema/tools/ee_inspection_tool.cpp +++ b/eeschema/tools/ee_inspection_tool.cpp @@ -116,9 +116,8 @@ void EE_INSPECTION_TOOL::checkPart( LIB_PART* aPart ) return; wxString msg; - wxRealPoint curr_grid_size = m_frame->GetScreen()->GetGridSize(); const int min_grid_size = 25; - const int grid_size = KiROUND( curr_grid_size.x ); + const int grid_size = KiROUND( getView()->GetGAL()->GetGridSize().x ); const int clamped_grid_size = ( grid_size < min_grid_size ) ? min_grid_size : grid_size; LIB_PINS pinList; diff --git a/eeschema/tools/sch_line_wire_bus_tool.cpp b/eeschema/tools/sch_line_wire_bus_tool.cpp index 319a9aa300..3faae3c6ea 100644 --- a/eeschema/tools/sch_line_wire_bus_tool.cpp +++ b/eeschema/tools/sch_line_wire_bus_tool.cpp @@ -434,7 +434,7 @@ void SCH_LINE_WIRE_BUS_TOOL::computeBreakPoint( const std::pairGetPosition().x ) // push outside sheet boundary { int direction = ( force == SHEET_LEFT_SIDE ) ? -1 : 1; - aPosition.x += int( m_frame->GetScreen()->GetGridSize().x * direction ); + aPosition.x += KiROUND( getView()->GetGAL()->GetGridSize().x * direction ); } midPoint.x = aPosition.x; diff --git a/gerbview/gbr_screen.cpp b/gerbview/gbr_screen.cpp index 7da8081842..a657a02dd0 100644 --- a/gerbview/gbr_screen.cpp +++ b/gerbview/gbr_screen.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012-2014 Jean-Pierre Charras jp.charras at wanadoo.fr - * Copyright (C) 1992-2014 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 1992-2020 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 @@ -22,19 +22,9 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file gbr_screen.cpp - */ - #include -#include #include #include -#include - - -#define MIL_GRID( x ) wxRealPoint( x * IU_PER_MILS, x * IU_PER_MILS) -#define MM_GRID( x ) wxRealPoint( x * IU_PER_MM, x * IU_PER_MM ) /** @@ -67,67 +57,15 @@ static const double gbrZoomList[] = }; -// Default grid sizes for PCB editor screens. -static GRID_TYPE gbrGridList[] = -{ - // predefined grid list in mils - { ID_POPUP_GRID_LEVEL_1000, MIL_GRID( 100 ) }, - { ID_POPUP_GRID_LEVEL_500, MIL_GRID( 50 ) }, - { ID_POPUP_GRID_LEVEL_250, MIL_GRID( 25 ) }, - { ID_POPUP_GRID_LEVEL_200, MIL_GRID( 20 ) }, - { ID_POPUP_GRID_LEVEL_100, MIL_GRID( 10 ) }, - { ID_POPUP_GRID_LEVEL_50, MIL_GRID( 5 ) }, - { ID_POPUP_GRID_LEVEL_25, MIL_GRID( 2.5 ) }, - { ID_POPUP_GRID_LEVEL_20, MIL_GRID( 2 ) }, - { ID_POPUP_GRID_LEVEL_10, MIL_GRID( 1 ) }, - { ID_POPUP_GRID_LEVEL_5, MIL_GRID( 0.5 ) }, - { ID_POPUP_GRID_LEVEL_2, MIL_GRID( 0.2 ) }, - { ID_POPUP_GRID_LEVEL_1, MIL_GRID( 0.1 ) }, - - // predefined grid list in mm - { ID_POPUP_GRID_LEVEL_5MM, MM_GRID( 5.0 ) }, - { ID_POPUP_GRID_LEVEL_2_5MM, MM_GRID( 2.5 ) }, - { ID_POPUP_GRID_LEVEL_1MM, MM_GRID( 1.0 ) }, - { ID_POPUP_GRID_LEVEL_0_5MM, MM_GRID( 0.5 ) }, - { ID_POPUP_GRID_LEVEL_0_25MM, MM_GRID( 0.25 ) }, - { ID_POPUP_GRID_LEVEL_0_2MM, MM_GRID( 0.2 ) }, - { ID_POPUP_GRID_LEVEL_0_1MM, MM_GRID( 0.1 ) }, - { ID_POPUP_GRID_LEVEL_0_0_5MM, MM_GRID( 0.05 ) }, - { ID_POPUP_GRID_LEVEL_0_0_25MM, MM_GRID( 0.025 ) }, - { ID_POPUP_GRID_LEVEL_0_0_1MM, MM_GRID( 0.01 ) } -}; - - GBR_SCREEN::GBR_SCREEN( const wxSize& aPageSizeIU ) : BASE_SCREEN( SCREEN_T ) { for( unsigned i = 0; i < arrayDim( gbrZoomList ); ++i ) m_ZoomList.push_back( gbrZoomList[i] ); - for( unsigned i = 0; i < arrayDim( gbrGridList ); ++i ) - AddGrid( gbrGridList[i] ); - - // Set the working grid size to a reasonable value - SetGrid( MIL_GRID( 50 ) ); SetZoom( ZOOM_FACTOR( 350 ) ); // a default value for zoom m_Active_Layer = 0; // default active layer = first graphic layer InitDataPoints( aPageSizeIU ); } - - -GBR_SCREEN::~GBR_SCREEN() -{ - ClearUndoRedoList(); -} - - -/* Virtual function needed by classes derived from BASE_SCREEN - * this is a virtual pure function in BASE_SCREEN - * do nothing in GerbView - * could be removed later - */ -void GBR_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER&, int ) -{ -} diff --git a/gerbview/gbr_screen.h b/gerbview/gbr_screen.h index ca06053d29..186b0df891 100644 --- a/gerbview/gbr_screen.h +++ b/gerbview/gbr_screen.h @@ -22,17 +22,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -/** - * @file gbr_screen.h - */ - #ifndef GBR_SCREEN_H #define GBR_SCREEN_H #include - #include -#include #define ZOOM_FACTOR( x ) ( x * IU_PER_MILS ) @@ -46,13 +40,13 @@ public: * @param aPageSizeIU is the size of the initial paper page in internal units. */ GBR_SCREEN( const wxSize& aPageSizeIU ); - ~GBR_SCREEN(); /** * Function ClearUndoORRedoList * virtual pure in BASE_SCREEN, so it must be defined here */ - void ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount = -1 ) override; + void ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount = -1 ) override + { } }; diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index c8a8653272..3fc280329e 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.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 @@ -57,6 +57,7 @@ #include #include #include +#include GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent ) : EDA_DRAW_FRAME( aKiway, aParent, FRAME_GERBER, wxT( "GerbView" ), wxDefaultPosition, @@ -123,12 +124,6 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent ) // initialize parameters in m_LayersManager LoadSettings( config() ); - if( m_LastGridSizeId < 0 ) - m_LastGridSizeId = 0; - - if( m_LastGridSizeId > ID_POPUP_GRID_LEVEL_0_0_1MM-ID_POPUP_GRID_LEVEL_1000 ) - m_LastGridSizeId = ID_POPUP_GRID_LEVEL_0_0_1MM-ID_POPUP_GRID_LEVEL_1000; - setupTools(); ReCreateMenuBar(); ReCreateHToolbar(); @@ -206,10 +201,6 @@ GERBVIEW_FRAME::GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent ) m_LayersManager->ReFillRender(); // Update colors in Render after the config is read GetToolManager()->RunAction( ACTIONS::zoomFitScreen, true ); - GetToolManager()->RunAction( ACTIONS::gridPreset, true, m_LastGridSizeId ); - - if( GetCanvas() ) - GetCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() ); // Update the checked state of tools SyncToolbars(); @@ -312,6 +303,32 @@ void GERBVIEW_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) GERBVIEW_SETTINGS* cfg = dynamic_cast( aCfg ); wxCHECK( cfg, /*void*/ ); + if( cfg->m_Window.grid.sizes.empty() ) + { + cfg->m_Window.grid.sizes = { "100 mil", + "50 mil", + "25 mil", + "20 mil", + "10 mil", + "5 mil", + "2.5 mil", + "2 mil", + "1 mil", + "0.5 mil", + "0.2 mil", + "0.1 mil", + "5.0 mm", + "2.5 mm", + "1.0 mm", + "0.5 mm", + "0.25 mm", + "0.2 mm", + "0.1 mm", + "0.05 mm", + "0.025 mm", + "0.01 mm" }; + } + SetElementVisibility( LAYER_WORKSHEET, cfg->m_Appearance.show_border_and_titleblock ); PAGE_INFO pageInfo( wxT( "GERBER" ) ); @@ -953,26 +970,13 @@ void GERBVIEW_FRAME::DisplayGridMsg() switch( m_userUnits ) { - case EDA_UNITS::INCHES: - gridformatter = "grid X %.6f Y %.6f"; - break; - - case EDA_UNITS::MILLIMETRES: - gridformatter = "grid X %.6f Y %.6f"; - break; - - default: - gridformatter = "grid X %f Y %f"; - break; + case EDA_UNITS::INCHES: gridformatter = "grid X %.6f Y %.6f"; break; + case EDA_UNITS::MILLIMETRES: gridformatter = "grid X %.6f Y %.6f"; break; + default: gridformatter = "grid X %f Y %f"; break; } - BASE_SCREEN* screen = GetScreen(); - wxArrayString gridsList; - - int icurr = screen->BuildGridsChoiceList( gridsList, m_userUnits != EDA_UNITS::INCHES ); - GRID_TYPE& grid = screen->GetGrid( icurr ); - double grid_x = To_User_Unit( m_userUnits, grid.m_Size.x ); - double grid_y = To_User_Unit( m_userUnits, grid.m_Size.y ); + double grid_x = To_User_Unit( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().x ); + double grid_y = To_User_Unit( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().y ); line.Printf( gridformatter, grid_x, grid_y ); SetStatusText( line, 4 ); @@ -1001,16 +1005,10 @@ void GERBVIEW_FRAME::UpdateStatusBar() switch( GetUserUnits() ) { - case EDA_UNITS::INCHES: - formatter = wxT( "r %.6f theta %.1f" ); - break; - case EDA_UNITS::MILLIMETRES: - formatter = wxT( "r %.5f theta %.1f" ); - break; - case EDA_UNITS::UNSCALED: - formatter = wxT( "r %f theta %f" ); - break; - default: wxASSERT( false ); break; + case EDA_UNITS::INCHES: formatter = wxT( "r %.6f theta %.1f" ); break; + case EDA_UNITS::MILLIMETRES: formatter = wxT( "r %.5f theta %.1f" ); break; + case EDA_UNITS::UNSCALED: formatter = wxT( "r %f theta %f" ); break; + default: wxASSERT( false ); break; } line.Printf( formatter, To_User_Unit( GetUserUnits(), ro ), theta ); @@ -1101,7 +1099,7 @@ void GERBVIEW_FRAME::ActivateGalCanvas() if( m_toolManager ) { m_toolManager->SetEnvironment( m_gerberLayout, GetCanvas()->GetView(), - GetCanvas()->GetViewControls(), this ); + GetCanvas()->GetViewControls(), config(), this ); m_toolManager->ResetTools( TOOL_BASE::GAL_SWITCH ); } @@ -1143,7 +1141,7 @@ void GERBVIEW_FRAME::setupTools() // Create the manager and dispatcher & route draw panel events to the dispatcher m_toolManager = new TOOL_MANAGER; m_toolManager->SetEnvironment( m_gerberLayout, GetCanvas()->GetView(), - GetCanvas()->GetViewControls(), this ); + GetCanvas()->GetViewControls(), config(), this ); m_actions = new GERBVIEW_ACTIONS(); m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions ); @@ -1171,15 +1169,13 @@ void GERBVIEW_FRAME::updateGridSelectBox() // Update grid values with the current units setting. m_gridSelectBox->Clear(); wxArrayString gridsList; - int icurr = GetScreen()->BuildGridsChoiceList( gridsList, GetUserUnits() != EDA_UNITS::INCHES ); - for( size_t i = 0; i < GetScreen()->GetGridCount(); i++ ) - { - GRID_TYPE& grid = GetScreen()->GetGrid( i ); - m_gridSelectBox->Append( gridsList[i], (void*) &grid.m_CmdId ); - } + GRID_MENU::BuildChoiceList( &gridsList, config(), GetUserUnits() != EDA_UNITS::INCHES ); - m_gridSelectBox->SetSelection( icurr ); + for( const wxString& grid : gridsList ) + m_gridSelectBox->Append( grid ); + + m_gridSelectBox->SetSelection( config()->m_Window.grid.last_size_idx ); } @@ -1210,30 +1206,6 @@ void GERBVIEW_FRAME::updateZoomSelectBox() } -void GERBVIEW_FRAME::OnUpdateSelectZoom( wxUpdateUIEvent& aEvent ) -{ - if( m_zoomSelectBox == NULL || m_auxiliaryToolBar == NULL ) - return; - - int current = 0; // display Auto if no match found - - // check for a match within 1% - double zoom = GetCanvas()->GetLegacyZoom(); - - for( unsigned i = 0; i < GetScreen()->m_ZoomList.size(); i++ ) - { - if( std::fabs( zoom - GetScreen()->m_ZoomList[i] ) < ( zoom / 100.0 ) ) - { - current = i + 1; - break; - } - } - - if( current != m_zoomSelectBox->GetSelection() ) - m_zoomSelectBox->SetSelection( current ); -} - - void GERBVIEW_FRAME::CommonSettingsChanged( bool aEnvVarsChanged ) { EDA_DRAW_FRAME::CommonSettingsChanged( aEnvVarsChanged ); diff --git a/gerbview/gerbview_frame.h b/gerbview/gerbview_frame.h index 0cc55c81ca..1ace732882 100644 --- a/gerbview/gerbview_frame.h +++ b/gerbview/gerbview_frame.h @@ -60,20 +60,8 @@ class GERBVIEW_FRAME : public EDA_DRAW_FRAME // PCB_BASE_FRAME GBR_DISPLAY_OPTIONS m_DisplayOptions; public: - - /** - * Function GetDisplayOptions - * returns the display options current in use - */ - const GBR_DISPLAY_OPTIONS& GetDisplayOptions() const - { - return m_DisplayOptions; - } - - void SetDisplayOptions( const GBR_DISPLAY_OPTIONS& aOptions ) - { - m_DisplayOptions = aOptions; - } + const GBR_DISPLAY_OPTIONS& GetDisplayOptions() const { return m_DisplayOptions; } + void SetDisplayOptions( const GBR_DISPLAY_OPTIONS& aOptions ) { m_DisplayOptions = aOptions; } /** * Function SetLayout @@ -164,8 +152,6 @@ public: // gerber data (format..) private: - std::vector m_configSettings; - int m_displayMode; // Gerber images ("layers" in Gerbview) can be drawn: // - in fast mode (write mode) but if there are negative // items only the last image is correctly drawn (no @@ -224,18 +210,15 @@ public: /** * Function ReCreateVToolbar * creates or updates the right vertical toolbar. - * - * @note This is currently not used. */ void ReCreateVToolbar() override; /** - * Create or update the left vertical toolbar (option toolbar + * Create or update the left vertical toolbar (option toolbar) */ void ReCreateOptToolbar() override; void ReCreateMenuBar() override; - void OnUpdateSelectZoom( wxUpdateUIEvent& aEvent ); void UpdateStatusBar() override; /** @@ -317,37 +300,26 @@ public: void SetVisibleElementColor( int aLayerID, COLOR4D aColor ); - /** - * Function GetLayerColor - * gets a layer color for any valid layer. - */ COLOR4D GetLayerColor( int aLayer ) const; - - /** - * Function SetLayerColor - * changes a layer color for any valid layer. - */ void SetLayerColor( int aLayer, COLOR4D aColor ); /** * Function GetNegativeItemsColor * @return the color of negative items. - * This is usually the background color, but can be another color - * in order to see negative objects + * This is usually the background color, but can be another color in order to see + * negative objects */ COLOR4D GetNegativeItemsColor(); /** * Function ReFillLayerWidget - * changes out all the layers in m_Layers and may be called upon - * loading new gerber files. + * changes out all the layers in m_Layers; called upon loading new gerber files. */ void ReFillLayerWidget(); /** * Function SetActiveLayer - * will change the currently active layer to \a aLayer and also - * update the GERBER_LAYER_WIDGET. + * will change the currently active layer to \a aLayer and update the GERBER_LAYER_WIDGET. */ void SetActiveLayer( int aLayer, bool doLayerWidgetUpdate = true ); @@ -366,26 +338,20 @@ public: */ int getNextAvailableLayer( int aLayer = 0 ) const; - bool hasAvailableLayers() const - { - return getNextAvailableLayer() != NO_AVAILABLE_LAYERS; - } - /** * Function syncLayerWidget * updates the currently "selected" layer within the GERBER_LAYER_WIDGET. * The currently active layer is defined by the return value of GetActiveLayer(). *

- * This function cannot be inline without including layer_widget.h in - * here and we do not want to do that. + * This function cannot be inline without including layer_widget.h in here and we do not + * want to do that. */ void syncLayerWidget(); /** * Function syncLayerBox * updates the currently "selected" layer within m_SelLayerBox - * The currently active layer, as defined by the return value of - * GetActiveLayer(). + * The currently active layer, as defined by the return value of GetActiveLayer(). * @param aRebuildLayerBox = true to rebuild the layer box * false to just updates the selection. */ @@ -393,9 +359,8 @@ public: /** * Function UpdateTitleAndInfo - * displays the short filename (if exists) of the selected layer - * on the caption of the main GerbView window - * and some other parameters + * displays the short filename (if exists) of the selected layer on the caption of the main + * GerbView window and some other parameters * Name of the layer (found in the gerber file: LN <name> command) in the status bar * Name of the Image (found in the gerber file: IN <name> command) in the status bar * and other data in toolbar @@ -407,7 +372,7 @@ public: * * Display the current grid pane on the status bar. */ - void DisplayGridMsg(); + void DisplayGridMsg() override; void LoadSettings( APP_SETTINGS_BASE* aCfg ) override; diff --git a/include/base_screen.h b/include/base_screen.h index 678541b27a..eb4d0bc5ed 100644 --- a/include/base_screen.h +++ b/include/base_screen.h @@ -3,7 +3,7 @@ * * Copyright (C) 2015 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.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 @@ -36,36 +36,6 @@ #include #include -/** - * GRID_TYPE - * is for grid arrays. - */ -class GRID_TYPE -{ -public: - int m_CmdId; // The command id of this grid ( first id is ID_POPUP_GRID_LEVEL_1000 ) - wxRealPoint m_Size; // the size in internal unit of the grid (can differ for X and Y axis) - - GRID_TYPE& operator=( const GRID_TYPE& item ) - { - if( this != &item ) - { - m_CmdId = item.m_CmdId; - m_Size = item.m_Size; - } - - return *this; - } - - const bool operator==( const GRID_TYPE& item ) const - { - return m_Size == item.m_Size && m_CmdId == item.m_CmdId; - } -}; - - -typedef std::vector GRIDS; - /** * BASE_SCREEN @@ -85,26 +55,8 @@ private: */ wxPoint m_crossHairPosition; - GRIDS m_grids; ///< List of valid grid sizes. - GRID_TYPE m_Grid; ///< Current grid selection. double m_Zoom; ///< Current zoom coefficient. - //----< Old public API now is private, and migratory>------------------------ - // called only from EDA_DRAW_FRAME - friend class EDA_DRAW_FRAME; - - /** - * Function getNearestGridPosition - * returns the nearest \a aGridSize location to \a aPosition. - * @param aPosition The position to check. - * @param aGridOrigin The origin point of the snap grid. - * @return The nearst grid position. - */ - wxPoint getNearestGridPosition( const wxPoint& aPosition, const wxPoint& aGridOrigin ) const; - - //---------------------------- - - public: static wxString m_PageLayoutDescrFileName; ///< the name of the page layout descr file, ///< or emty to used the default pagelayout @@ -136,7 +88,6 @@ public: int m_NumberOfScreens; std::vector m_ZoomList; ///< standard zoom (i.e. scale) coefficients. - bool m_IsPrinting; public: BASE_SCREEN( EDA_ITEM* aParent, KICAD_T aType = SCREEN_T ); @@ -267,97 +218,6 @@ public: */ double GetMinAllowedZoom() const { return m_ZoomList.size() ? *m_ZoomList.begin() : 1.0; } - //-------------------------------------------------------------- - - /** - * Return the command ID of the currently selected grid. - * - * @return int - Currently selected grid command ID. - */ - int GetGridCmdId() const { return m_Grid.m_CmdId; } - - /** - * Return the grid size of the currently selected grid. - * - * @return wxRealPoint - The currently selected grid size. - */ - const wxRealPoint& GetGridSize() const { return m_Grid.m_Size; } - - /** - * Return the grid object of the currently selected grid. - * - * @return GRID_TYPE - The currently selected grid. - */ - const GRID_TYPE& GetGrid() const { return m_Grid; } - - /** - * set the current grid size m_Grid. - * The size must be existing in grid list (in m_grids) - * If not, the near existing grid size is used - * @param size = the size of the new grid - * @return the grid id offset (id from ID_POPUP_GRID_LEVEL_1000 ) - * of the currently selected grid. - */ - int SetGrid( const wxRealPoint& size ); - - /** - * Function SetGrid - * sets the grid size from command ID (not an index in grid list, but a wxID). - * @param aCommandId = the wxWidgets command ID - * @return the grid id offset (id from ID_POPUP_GRID_LEVEL_1000 ) - * of the currently selected grid. - */ - int SetGrid( int aCommandId ); - - void AddGrid( const GRID_TYPE& aGrid ); - void AddGrid( const wxRealPoint& size, EDA_UNITS aUnit, int id ); - - /** - * Function GridExists - * tests for grid command ID (not an index in grid list, but a wxID) exists in grid list. - * @param aCommandId = the wxWidgets command ID - * @return true if the grid exists in grid list. - */ - bool GridExists( int aCommandId ); - - /** - * Function GetGridCount(). - * Return the size of the grid list. - * - * @returns - The size of the grid list. - */ - size_t GetGridCount() const { return m_grids.size(); } - - /** - * Function GetGrid() - * Returns the grid object at \a aIndex. - * - * @param aIndex - The grid list index. - * @return - The grid object at \a aIndex or the current grid if the grid list is empty. - */ - GRID_TYPE& GetGrid( size_t aIndex ); - - /** - * Function GetGrids(). - * Returns the current list of grids. - */ - const GRIDS& GetGrids() const - { - return m_grids; - } - - /** - * Function BuildGridsChoiceList(). - * Build the human readable list of grid list, for menus or combo boxes - * the list shows the grid size both in mils or mm. - * @param aGridsList = a wxArrayString to populate - * @param aMmFirst = true to have mm first and mils after - * false to have mils first and mm after - * @return the index of the curr grid in list, if found or -1 - */ - int BuildGridsChoiceList( wxArrayString& aGridsList, bool aMmFirst) const; - - /** * Function GetClass * returns the class name. diff --git a/include/eda_draw_frame.h b/include/eda_draw_frame.h index b2d59c7819..90706624f3 100644 --- a/include/eda_draw_frame.h +++ b/include/eda_draw_frame.h @@ -40,7 +40,6 @@ class ACTION_TOOLBAR; class COLOR_SETTINGS; class TOOL_MENU; class APP_SETTINGS_BASE; -class EDA_INFOBAR_PANEL; namespace KIGFX { @@ -81,10 +80,6 @@ protected: std::unique_ptr m_file_checker; ///< prevents opening same file multiple times. - int m_LastGridSizeId; // The command id offset (>= 0) of the last selected - // grid 0 is for the grid corresponding to a - // wxCommand ID = ID_POPUP_GRID_LEVEL_1000. - bool m_drawGrid; // Hide/Show grid bool m_showPageLimits; // True to display the page limits COLOR4D m_gridColor; // Grid color COLOR4D m_drawBgColor; // The background color of the draw canvas; BLACK for @@ -207,9 +202,6 @@ public: virtual const wxPoint& GetGridOrigin() const = 0; virtual void SetGridOrigin( const wxPoint& aPosition ) = 0; - int GetLastGridSizeId() const { return m_LastGridSizeId; } - void SetLastGridSizeId( int aId ) { m_LastGridSizeId = aId; } - /** * Return the nearest \a aGridSize location to \a aPosition. * @@ -223,14 +215,7 @@ public: // the background color of the draw canvas: // Virtual because some frames can have a specific way to get/set the bg color - /** - * @return the COLOR4D for the canvas background - */ virtual COLOR4D GetDrawBgColor() const { return m_drawBgColor; } - - /** - * @param aColor: the COLOR4D for the canvas background - */ virtual void SetDrawBgColor( COLOR4D aColor) { m_drawBgColor= aColor ; } /// Returns a pointer to the active color theme settings @@ -242,9 +227,8 @@ public: virtual wxString GetScreenDesc() const; /** - * Return a pointer to a BASE_SCREEN or one of its - * derivatives. It is overloaded by derived classes to return - * SCH_SCREEN or PCB_SCREEN. + * Return a pointer to a BASE_SCREEN or one of its derivatives. It is overloaded by + * derived classes to return SCH_SCREEN or PCB_SCREEN. */ virtual BASE_SCREEN* GetScreen() const { return m_currentScreen; } @@ -260,8 +244,7 @@ public: virtual void ExecuteRemoteCommand( const char* cmdline ){} /** - * Return a human readable value which can be displayed as zoom - * level indicator in dialogs. + * Return a human readable value for display in dialogs. * this can be a percentage or other indicator. * it is virtual because it could be different for pcbnew, gerbview or eeschema * (different internal units and different purposes) @@ -286,8 +269,8 @@ public: * These 4 functions provide a basic way to show/hide grid and /get/set grid color. * These parameters are saved in KiCad config for each main frame. */ - virtual bool IsGridVisible() const { return m_drawGrid; } - virtual void SetGridVisibility( bool aVisible ) { m_drawGrid = aVisible; } + bool IsGridVisible() const; + virtual void SetGridVisibility( bool aVisible ); virtual COLOR4D GetGridColor() { return m_gridColor; } virtual void SetGridColor( COLOR4D aColor ) { m_gridColor = aColor; } @@ -345,9 +328,6 @@ public: */ void FocusOnLocation( const wxPoint& aPos ); - /** - * @return The current zoom level. - */ double GetZoom(); /** @@ -388,14 +368,14 @@ public: void UpdateStatusBar() override; /** - * Display current unit pane on the status bar. + * Display current unit pane in the status bar. */ void DisplayUnitsMsg(); /** - * Display current grid pane on the status bar. + * Display current grid size in the status bar. */ - void DisplayGridMsg(); + virtual void DisplayGridMsg(); /* interprocess communication */ void CreateServer( int service, bool local = true ); diff --git a/include/gal/graphics_abstraction_layer.h b/include/gal/graphics_abstraction_layer.h index 7b374c5534..7af5387f85 100644 --- a/include/gal/graphics_abstraction_layer.h +++ b/include/gal/graphics_abstraction_layer.h @@ -847,10 +847,9 @@ public: * * @param aVisibility is the new visibility setting of the grid. */ - inline void SetGridVisibility( bool aVisibility ) - { - gridVisibility = aVisibility; - } + void SetGridVisibility( bool aVisibility ) { gridVisibility = aVisibility; } + + bool GetGridVisibility() const { return gridVisibility; } /** * @brief Set the origin point for the grid. @@ -868,6 +867,11 @@ public: (long) gridOrigin.y % (long) gridSize.y ); } + inline const VECTOR2D& GetGridOrigin() const + { + return gridOrigin; + } + /** * @brief Set the grid size. * diff --git a/include/pcb_base_frame.h b/include/pcb_base_frame.h index 98334dd33c..dae6f62dbb 100644 --- a/include/pcb_base_frame.h +++ b/include/pcb_base_frame.h @@ -72,12 +72,6 @@ wxDECLARE_EVENT( BOARD_CHANGED, wxCommandEvent ); */ class PCB_BASE_FRAME : public EDA_DRAW_FRAME { -public: - wxPoint m_UserGridSize; - - int m_FastGrid1; // 1st fast grid setting (index in EDA_DRAW_FRAME::m_gridSelectBox) - int m_FastGrid2; // 2nd fast grid setting (index in EDA_DRAW_FRAME::m_gridSelectBox) - protected: BOARD* m_Pcb; @@ -181,19 +175,11 @@ public: /** * Function GetDisplayOptions - * returns the display options current in use - * Display options are relative to the way tracks, vias, outlines - * and other things are shown (for instance solid or sketch mode) + * Display options control the way tracks, vias, outlines and other things are shown + * (for instance solid or sketch mode) */ - const PCB_DISPLAY_OPTIONS& GetDisplayOptions() const - { - return m_DisplayOptions; - } - - void SetDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions ) - { - m_DisplayOptions = aOptions; - } + const PCB_DISPLAY_OPTIONS& GetDisplayOptions() const { return m_DisplayOptions; } + void SetDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions ) { m_DisplayOptions = aOptions; } const ZONE_SETTINGS& GetZoneSettings() const; void SetZoneSettings( const ZONE_SETTINGS& aSettings ); @@ -243,9 +229,7 @@ public: /** * Function GetZoomLevelIndicator - * returns a human readable value which can be displayed as zoom - * level indicator in dialogs. - * Virtual from the base class + * returns a human readable value for display in dialogs. */ const wxString GetZoomLevelIndicator() const override; @@ -258,8 +242,7 @@ public: /** * Function GetCollectorsGuide - * @return GENERAL_COLLECTORS_GUIDE - that considers the global - *configuration options. + * @return GENERAL_COLLECTORS_GUIDE - that considers the global configuration options. */ GENERAL_COLLECTORS_GUIDE GetCollectorsGuide(); @@ -274,20 +257,18 @@ public: /** * Function GetFootprintFromBoardByReference - * @return a reference to the footprint found by its refence - * on the curent board. the reference is entered by the user from - * a dialog (by awxTextCtlr, or a list of available references) + * @return a reference to the footprint found by its refence on the curent board. The + * reference is entered by the user from a dialog (by awxTextCtlr, or a list of + * available references) */ MODULE* GetFootprintFromBoardByReference(); /** * Function OnModify - * Virtual - * Must be called after a change - * in order to set the "modify" flag of the current screen - * and update the date in frame reference - * do not forget to call this basic OnModify function to update info - * in derived OnModify functions + * Must be called after a change in order to set the "modify" flag of the current screen + * and update the date in frame reference. + * Do not forget to call this basic OnModify function to update info in derived OnModify + * functions. */ virtual void OnModify(); @@ -306,8 +287,6 @@ public: */ MODULE* CreateNewModule( const wxString& aModuleName ); - void Edit_Module( MODULE* module, wxDC* DC ); - /** * Function PlaceModule * places \a aModule at the current cursor position and updates module coordinates @@ -343,7 +322,6 @@ public: */ wxString SelectFootprintFromLibBrowser(); - // ratsnest functions /** * Function Compile_Ratsnest * Create the entire board ratsnest. @@ -365,8 +343,7 @@ public: * @param aTransformPoint = the reference point of the transformation, for * commands like move */ - virtual void SaveCopyInUndoList( BOARD_ITEM* aItemToCopy, - UNDO_REDO_T aTypeCommand, + virtual void SaveCopyInUndoList( BOARD_ITEM* aItemToCopy, UNDO_REDO_T aTypeCommand, const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) = 0; /** @@ -378,8 +355,7 @@ public: * @param aTransformPoint = the reference point of the transformation, * for commands like move */ - virtual void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, - UNDO_REDO_T aTypeCommand, + virtual void SaveCopyInUndoList( const PICKED_ITEMS_LIST& aItemsList, UNDO_REDO_T aTypeCommand, const wxPoint& aTransformPoint = wxPoint( 0, 0 ) ) = 0; @@ -390,9 +366,8 @@ public: * @param aDlgPosition = position of dialog ( defualt = centered) * @return the selected layer id */ - PCB_LAYER_ID SelectLayer( PCB_LAYER_ID aDefaultLayer, - LSET aNotAllowedLayersMask = LSET(), - wxPoint aDlgPosition = wxDefaultPosition ); + PCB_LAYER_ID SelectLayer( PCB_LAYER_ID aDefaultLayer, LSET aNotAllowedLayersMask = LSET(), + wxPoint aDlgPosition = wxDefaultPosition ); virtual void SwitchLayer( wxDC* DC, PCB_LAYER_ID layer ); @@ -430,43 +405,12 @@ public: virtual void OnUpdateLayerAlpha( wxUpdateUIEvent& aEvent ) {} - /** - * Function SetFastGrid1() - * - * Switches grid settings to the 1st "fast" setting predefined by user. - */ - void SetFastGrid1(); - - /** - * Function SetFastGrid2() - * - * Switches grid settings to the 1st "fast" setting predefined by user. - */ - void SetFastGrid2(); - - /** - * Function IsGridVisible() - * - * @return true if the grid is shown - */ - virtual bool IsGridVisible() const override; - - /** - * Function SetGridVisibility() - * Turn the display of the canvas grid on/off - * - * Note: After calling, the view must be refreshed to update the grid display - * - * @param aVisible = true if the grid is shown - */ - virtual void SetGridVisibility( bool aVisible ) override; - /** * Function DisplayGridMsg() * * Display the current grid pane on the status bar. */ - void DisplayGridMsg(); + void DisplayGridMsg() override; PCB_DRAW_PANEL_GAL* GetCanvas() const override; @@ -474,14 +418,12 @@ public: virtual void ActivateGalCanvas() override; /** - * Doesn't do anything. Should be overrided in child classes if they - * support an auto zoom setting. + * Does nothing. Should be overriden in derived classes which support autozoom. */ virtual void SetAutoZoom( bool aAutoZoom ) {} /** - * Always returns false. Should be overriden in child classes if they - * support an autozoom setting. + * Always returns false. Should be overriden in derived classes which support autozoom. */ virtual bool GetAutoZoom() { return false; } diff --git a/include/settings/app_settings.h b/include/settings/app_settings.h index 885b4a902d..9144896245 100644 --- a/include/settings/app_settings.h +++ b/include/settings/app_settings.h @@ -39,13 +39,17 @@ struct CURSOR_SETTINGS struct GRID_SETTINGS { bool axes_enabled; - int last_size; + std::vector sizes; + wxString user_grid_x; + wxString user_grid_y; + int last_size_idx; double line_width; double min_spacing; bool show; int style; }; + /** * Stores the common settings that are saved and loaded for each window / frame */ @@ -113,7 +117,7 @@ public: int units; }; - APP_SETTINGS_BASE( std::string aFilename, int aSchemaVersion ); + APP_SETTINGS_BASE( const std::string& aFilename, int aSchemaVersion ); virtual ~APP_SETTINGS_BASE() {} diff --git a/include/tool/common_tools.h b/include/tool/common_tools.h index 104ffee3c4..7721bb787c 100644 --- a/include/tool/common_tools.h +++ b/include/tool/common_tools.h @@ -81,6 +81,7 @@ public: int ToggleGrid( const TOOL_EVENT& aEvent ); int GridProperties( const TOOL_EVENT& aEvent ); int GridPreset( int idx ); + int OnGridChanged(); int SwitchCanvas( const TOOL_EVENT& aEvent ); @@ -95,6 +96,8 @@ private: ///> Note: idx == 0 is Auto; idx == 1 is first entry in zoomList int doZoomToPreset( int idx, bool aCenterOnCursor ); + + std::vector m_grids; // grids from APP_SETTINGS converted to internal units }; #endif diff --git a/include/tool/grid_menu.h b/include/tool/grid_menu.h index ee03c6f76e..c28cf332f2 100644 --- a/include/tool/grid_menu.h +++ b/include/tool/grid_menu.h @@ -28,12 +28,15 @@ #include class EDA_DRAW_FRAME; +class APP_SETTINGS_BASE; class GRID_MENU : public ACTION_MENU { public: GRID_MENU( EDA_DRAW_FRAME* aParent ); + static void BuildChoiceList( wxArrayString* aGridsList, APP_SETTINGS_BASE* aCfg, bool mmFirst ); + private: ACTION_MENU* create() const override { diff --git a/include/tool/tool_manager.h b/include/tool/tool_manager.h index 64afa2b7bc..610cca8fc4 100644 --- a/include/tool/tool_manager.h +++ b/include/tool/tool_manager.h @@ -38,6 +38,7 @@ class TOOLS_HOLDER; class TOOL_BASE; class ACTION_MANAGER; class ACTION_MENU; +class APP_SETTINGS_BASE; /** @@ -274,28 +275,24 @@ public: * These are made available to the tool. Called by the parent frame when it is set up. */ void SetEnvironment( EDA_ITEM* aModel, KIGFX::VIEW* aView, - KIGFX::VIEW_CONTROLS* aViewControls, TOOLS_HOLDER* aFrame ); + KIGFX::VIEW_CONTROLS* aViewControls, APP_SETTINGS_BASE* aSettings, + TOOLS_HOLDER* aFrame ); - /* Accessors for the environment objects (view, model, etc.) */ - KIGFX::VIEW* GetView() const - { - return m_view; - } + /* + * Accessors for the environment objects (view, model, etc.) + * */ + KIGFX::VIEW* GetView() const { return m_view; } - inline KIGFX::VIEW_CONTROLS* GetViewControls() const - { - return m_viewControls; - } + KIGFX::VIEW_CONTROLS* GetViewControls() const { return m_viewControls; } VECTOR2D GetMousePosition(); VECTOR2D GetCursorPosition(); - inline EDA_ITEM* GetModel() const - { - return m_model; - } + EDA_ITEM* GetModel() const { return m_model; } - inline TOOLS_HOLDER* GetToolHolder() const { return m_frame; } + APP_SETTINGS_BASE* GetSettings() const { return m_settings; } + + TOOLS_HOLDER* GetToolHolder() const { return m_frame; } /** * Returns id of the tool that is on the top of the active tools stack @@ -545,6 +542,7 @@ private: KIGFX::VIEW* m_view; KIGFX::VIEW_CONTROLS* m_viewControls; TOOLS_HOLDER* m_frame; + APP_SETTINGS_BASE* m_settings; /// Queue that stores events to be processed at the end of the event processing cycle. std::list m_eventQueue; diff --git a/kicad/kicad_manager_frame.cpp b/kicad/kicad_manager_frame.cpp index 5d5af884dc..d821996805 100644 --- a/kicad/kicad_manager_frame.cpp +++ b/kicad/kicad_manager_frame.cpp @@ -127,7 +127,7 @@ KICAD_MANAGER_FRAME::KICAD_MANAGER_FRAME( wxWindow* parent, const wxString& titl // Create the manager m_toolManager = new TOOL_MANAGER; - m_toolManager->SetEnvironment( nullptr, nullptr, nullptr, this ); + m_toolManager->SetEnvironment( nullptr, nullptr, nullptr, config(), this ); m_actions = new KICAD_MANAGER_ACTIONS(); // Register tools diff --git a/pagelayout_editor/dialogs/dialogs_for_printing.cpp b/pagelayout_editor/dialogs/dialogs_for_printing.cpp index 4844108554..8b62da7d47 100644 --- a/pagelayout_editor/dialogs/dialogs_for_printing.cpp +++ b/pagelayout_editor/dialogs/dialogs_for_printing.cpp @@ -173,7 +173,6 @@ void PLEDITOR_PRINTOUT::PrintPage( int aPageNum ) GRResetPenAndBrush( dc ); GRForceBlackPen( true ); - screen->m_IsPrinting = true; COLOR4D bg_color = m_parent->GetDrawBgColor(); m_parent->SetDrawBgColor( MakeColour( WHITE ) ); @@ -201,7 +200,6 @@ void PLEDITOR_PRINTOUT::PrintPage( int aPageNum ) m_parent->PrintWorkSheet( &renderSettings, screen, IU_PER_MILS, wxEmptyString ); m_parent->SetDrawBgColor( bg_color ); - screen->m_IsPrinting = false; GRForceBlackPen( false ); diff --git a/pagelayout_editor/pl_editor_frame.cpp b/pagelayout_editor/pl_editor_frame.cpp index 49a4ff9cd3..1bbe94e48b 100644 --- a/pagelayout_editor/pl_editor_frame.cpp +++ b/pagelayout_editor/pl_editor_frame.cpp @@ -197,11 +197,6 @@ PL_EDITOR_FRAME::PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) : wxPoint originCoord = ReturnCoordOriginCorner(); SetGridOrigin( originCoord ); - if( !GetScreen()->GridExists( m_LastGridSizeId + ID_POPUP_GRID_LEVEL_1000 ) ) - m_LastGridSizeId = ID_POPUP_GRID_LEVEL_1MM - ID_POPUP_GRID_LEVEL_1000; - - GetToolManager()->RunAction( "common.Control.gridPreset", true, m_LastGridSizeId ); - // Initialize the current page layout WS_DATA_MODEL& pglayout = WS_DATA_MODEL::GetTheInstance(); #if 0 //start with empty layout @@ -229,7 +224,7 @@ void PL_EDITOR_FRAME::setupTools() // Create the manager and dispatcher & route draw panel events to the dispatcher m_toolManager = new TOOL_MANAGER; m_toolManager->SetEnvironment( nullptr, GetCanvas()->GetView(), - GetCanvas()->GetViewControls(), this ); + GetCanvas()->GetViewControls(), config(), this ); m_actions = new PL_ACTIONS(); m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions ); @@ -428,7 +423,17 @@ void PL_EDITOR_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) { EDA_DRAW_FRAME::LoadSettings( aCfg ); - auto cfg = static_cast( aCfg ); + PL_EDITOR_SETTINGS* cfg = dynamic_cast( aCfg ); + wxCHECK( cfg, /*void*/ ); + + if( cfg->m_Window.grid.sizes.empty() ) + { + cfg->m_Window.grid.sizes = { "1.0 mm", + "0.50 mm", + "0.25 mm", + "0.20 mm", + "0.10 mm" }; + } m_propertiesFrameWidth = cfg->m_PropertiesFrameWidth; m_originSelectChoice = cfg->m_CornerOrigin; @@ -571,17 +576,12 @@ void PL_EDITOR_FRAME::DisplayGridMsg() switch( m_userUnits ) { - case EDA_UNITS::INCHES: - gridformatter = "grid %.3f"; - break; - case EDA_UNITS::MILLIMETRES: - gridformatter = "grid %.4f"; - break; - default: gridformatter = "grid %f"; break; + case EDA_UNITS::INCHES: gridformatter = "grid %.3f"; break; + case EDA_UNITS::MILLIMETRES: gridformatter = "grid %.4f"; break; + default: gridformatter = "grid %f"; break; } - wxRealPoint curr_grid_size = GetScreen()->GetGridSize(); - double grid = To_User_Unit( m_userUnits, curr_grid_size.x ); + double grid = To_User_Unit( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().x ); line.Printf( gridformatter, grid ); SetStatusText( line, 4 ); diff --git a/pagelayout_editor/pl_editor_frame.h b/pagelayout_editor/pl_editor_frame.h index 138eee6c89..839c10b045 100644 --- a/pagelayout_editor/pl_editor_frame.h +++ b/pagelayout_editor/pl_editor_frame.h @@ -57,13 +57,8 @@ class PL_EDITOR_FRAME : public EDA_DRAW_FRAME protected: /// The last filename chosen to be proposed to the user - wxString m_lastFileName; PROPERTIES_FRAME* m_propertiesPagelayout; -private: - // list of PARAM_CFG_xxx to read/write parameters saved in config - std::vector m_configSettings; - public: PL_EDITOR_FRAME( KIWAY* aKiway, wxWindow* aParent ); ~PL_EDITOR_FRAME(); @@ -147,15 +142,8 @@ public: } void SetAuxOrigin( const wxPoint& aPosition ) override {} - const wxPoint& GetGridOrigin() const override - { - return m_grid_origin; - } - - void SetGridOrigin( const wxPoint& aPoint ) override - { - m_grid_origin = aPoint; - } + const wxPoint& GetGridOrigin() const override { return m_grid_origin; } + void SetGridOrigin( const wxPoint& aPoint ) override { m_grid_origin = aPoint; } /** * calculate the position (in page, in iu) of the corner used as coordinate origin @@ -166,7 +154,7 @@ public: const TITLE_BLOCK& GetTitleBlock() const override; void SetTitleBlock( const TITLE_BLOCK& aTitleBlock ) override; - void DisplayGridMsg(); + void DisplayGridMsg() override; void UpdateStatusBar() override; diff --git a/pagelayout_editor/pl_editor_screen.cpp b/pagelayout_editor/pl_editor_screen.cpp index f7f9861bf9..95dd52c9b3 100644 --- a/pagelayout_editor/pl_editor_screen.cpp +++ b/pagelayout_editor/pl_editor_screen.cpp @@ -24,14 +24,10 @@ */ #include -#include -#include #include #include -#include -#define MM_GRID( x ) wxRealPoint( x * IU_PER_MM, x * IU_PER_MM ) #define ZOOM_FACTOR( x ) ( x * IU_PER_MM / 1000 ) @@ -62,33 +58,15 @@ static const double pl_editorZoomList[] = }; -// Default grid sizes for page layout editor screens. -static GRID_TYPE pl_editorGridList[] = -{ - // predefined grid list in mm - { ID_POPUP_GRID_LEVEL_1MM, MM_GRID( 1.0 ) }, - { ID_POPUP_GRID_LEVEL_0_5MM, MM_GRID( 0.5 ) }, - { ID_POPUP_GRID_LEVEL_0_25MM, MM_GRID( 0.25 ) }, - { ID_POPUP_GRID_LEVEL_0_2MM, MM_GRID( 0.2 ) }, - { ID_POPUP_GRID_LEVEL_0_1MM, MM_GRID( 0.1 ) }, -}; - - PL_EDITOR_SCREEN::PL_EDITOR_SCREEN( const wxSize& aPageSizeIU ) : BASE_SCREEN( SCREEN_T ) { for( double zoom : pl_editorZoomList ) m_ZoomList.push_back( zoom ); - for( GRID_TYPE grid : pl_editorGridList ) - AddGrid( grid ); - // pl_editor uses the same frame position as schematic and board editors m_Center = false; - // Set the working grid size to a reasonable value - SetGrid( MM_GRID( 1.0 ) ); - InitDataPoints( aPageSizeIU ); m_NumberOfScreens = 2; } diff --git a/pagelayout_editor/pl_editor_screen.h b/pagelayout_editor/pl_editor_screen.h index d2123e4bc4..487fcf0808 100644 --- a/pagelayout_editor/pl_editor_screen.h +++ b/pagelayout_editor/pl_editor_screen.h @@ -1,7 +1,3 @@ -/** - * @file pl_editor_screen.h - */ - /* * This program source code file is part of KiCad, a free EDA CAD application. * @@ -30,13 +26,11 @@ #define CLASS_PL_EDITOR_SCREEN_H_ -#include #include class WS_DATA_ITEM; -/* Handle info to display a board */ class PL_EDITOR_SCREEN : public BASE_SCREEN { public: diff --git a/pcbnew/dialogs/dialog_set_grid.cpp b/pcbnew/dialogs/dialog_set_grid.cpp index bf287e6a47..412b5d930d 100644 --- a/pcbnew/dialogs/dialog_set_grid.cpp +++ b/pcbnew/dialogs/dialog_set_grid.cpp @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include #include @@ -31,6 +33,7 @@ #include #include #include // for KiROUND +#include // Max values for grid size static const int MAX_GRID_SIZE = KiROUND( 1000.0 * IU_PER_MM ); @@ -40,11 +43,10 @@ static const int MIN_GRID_SIZE = KiROUND( 0.001 * IU_PER_MM ); class DIALOG_SET_GRID : public DIALOG_SET_GRID_BASE { PCB_BASE_FRAME* m_parent; - wxArrayString m_fast_grid_opts; public: /// This has no dependencies on calling wxFrame derivative, such as PCB_BASE_FRAME. - DIALOG_SET_GRID( PCB_BASE_FRAME* aParent, const wxArrayString& aGridChoices ); + DIALOG_SET_GRID( PCB_BASE_FRAME* aParent ); bool TransferDataFromWindow() override; bool TransferDataToWindow() override; @@ -59,17 +61,18 @@ private: }; -DIALOG_SET_GRID::DIALOG_SET_GRID( PCB_BASE_FRAME* aParent, const wxArrayString& aGridChoices ): +DIALOG_SET_GRID::DIALOG_SET_GRID( PCB_BASE_FRAME* aParent ): DIALOG_SET_GRID_BASE( aParent ), m_parent( aParent ), - m_fast_grid_opts( aGridChoices ), m_gridOriginX( aParent, m_staticTextGridPosX, m_GridOriginXCtrl, m_TextPosXUnits ), m_gridOriginY( aParent, m_staticTextGridPosY, m_GridOriginYCtrl, m_TextPosYUnits ), - m_userGridX( aParent, m_staticTextSizeX, m_OptGridSizeX, m_TextSizeXUnits ), - m_userGridY( aParent, m_staticTextSizeY, m_OptGridSizeY, m_TextSizeYUnits ) + m_userGridX( aParent, m_staticTextSizeX, m_OptGridSizeX, m_TextSizeXUnits, true ), + m_userGridY( aParent, m_staticTextSizeY, m_OptGridSizeY, m_TextSizeYUnits, true ) { - m_grid1Ctrl->Append( m_fast_grid_opts ); - m_grid2Ctrl->Append( m_fast_grid_opts ); + wxArrayString grids; + GRID_MENU::BuildChoiceList( &grids, m_parent->config(), GetUserUnits() != EDA_UNITS::INCHES ); + m_grid1Ctrl->Append( grids ); + m_grid2Ctrl->Append( grids ); m_sdbSizerOK->SetDefault(); // set OK button as default response to 'Enter' key SetInitialFocus( m_GridOriginXCtrl ); @@ -91,26 +94,19 @@ bool DIALOG_SET_GRID::TransferDataFromWindow() return false; // Apply the new settings + GRID_SETTINGS& gridCfg = m_parent->config()->m_Window.grid; // Because grid origin is saved in board, show as modified m_parent->OnModify(); m_parent->SetGridOrigin( wxPoint( m_gridOriginX.GetValue(), m_gridOriginY.GetValue() ) ); - m_parent->m_UserGridSize = wxPoint( m_userGridX.GetValue(), m_userGridY.GetValue() ); - m_parent->m_FastGrid1 = m_grid1Ctrl->GetSelection(); - m_parent->m_FastGrid2 = m_grid2Ctrl->GetSelection(); - - // User grid - BASE_SCREEN* screen = m_parent->GetScreen(); - screen->AddGrid( m_parent->m_UserGridSize, EDA_UNITS::UNSCALED, ID_POPUP_GRID_USER ); - - // If the user grid is the current option, recall SetGrid() - // to force new values put in list as current grid value - if( screen->GetGridCmdId() == ID_POPUP_GRID_USER ) - screen->SetGrid( ID_POPUP_GRID_USER ); + gridCfg.user_grid_x = StringFromValue( GetUserUnits(), m_userGridX.GetValue(), true, true ); + gridCfg.user_grid_y = StringFromValue( GetUserUnits(), m_userGridY.GetValue(), true, true ); + m_parent->Settings().m_FastGrid1 = m_grid1Ctrl->GetSelection(); + m_parent->Settings().m_FastGrid2 = m_grid2Ctrl->GetSelection(); // Notify GAL TOOL_MANAGER* mgr = m_parent->GetToolManager(); - mgr->GetTool()->GridPreset( screen->GetGridCmdId() - ID_POPUP_GRID_LEVEL_1000 ); + mgr->RunAction( ACTIONS::gridPreset, true, gridCfg.last_size_idx ); mgr->RunAction( ACTIONS::gridSetOrigin, true, new VECTOR2D( m_parent->GetGridOrigin() ) ); m_parent->UpdateGridSelectBox(); @@ -121,14 +117,16 @@ bool DIALOG_SET_GRID::TransferDataFromWindow() bool DIALOG_SET_GRID::TransferDataToWindow() { - m_userGridX.SetValue( m_parent->m_UserGridSize.x ); - m_userGridY.SetValue( m_parent->m_UserGridSize.y ); + GRID_SETTINGS& settings = m_parent->config()->m_Window.grid; + + m_userGridX.SetValue( ValueFromString( GetUserUnits(), settings.user_grid_x, true ) ); + m_userGridY.SetValue( ValueFromString( GetUserUnits(), settings.user_grid_y, true ) ); m_gridOriginX.SetValue( m_parent->GetGridOrigin().x ); m_gridOriginY.SetValue( m_parent->GetGridOrigin().y ); - m_grid1Ctrl->SetSelection( m_parent->m_FastGrid1 ); - m_grid2Ctrl->SetSelection( m_parent->m_FastGrid2 ); + m_grid1Ctrl->SetSelection( m_parent->Settings().m_FastGrid1 ); + m_grid2Ctrl->SetSelection( m_parent->Settings().m_FastGrid2 ); int hk1 = ACTIONS::gridFast1.GetHotKey(); int hk2 = ACTIONS::gridFast2.GetHotKey(); @@ -148,7 +146,7 @@ void DIALOG_SET_GRID::OnResetGridOrgClick( wxCommandEvent& event ) void PCB_BASE_EDIT_FRAME::OnGridSettings( wxCommandEvent& event ) { - DIALOG_SET_GRID dlg( this, m_gridSelectBox->GetStrings() ); + DIALOG_SET_GRID dlg( this ); dlg.ShowModal(); diff --git a/pcbnew/dialogs/dialog_set_grid_base.cpp b/pcbnew/dialogs/dialog_set_grid_base.cpp index 0f6442f139..7d10567315 100644 --- a/pcbnew/dialogs/dialog_set_grid_base.cpp +++ b/pcbnew/dialogs/dialog_set_grid_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Dec 30 2017) +// C++ code generated with wxFormBuilder (version Oct 26 2018) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -12,164 +12,164 @@ DIALOG_SET_GRID_BASE::DIALOG_SET_GRID_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); - + wxBoxSizer* bSizerMain; bSizerMain = new wxBoxSizer( wxVERTICAL ); - + wxBoxSizer* bUpperSizer; bUpperSizer = new wxBoxSizer( wxHORIZONTAL ); - + wxStaticBoxSizer* sbLeftSizer; sbLeftSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Grid Origin") ), wxVERTICAL ); - + wxFlexGridSizer* fgSizerGridOrigin; fgSizerGridOrigin = new wxFlexGridSizer( 2, 3, 0, 0 ); fgSizerGridOrigin->AddGrowableCol( 1 ); fgSizerGridOrigin->SetFlexibleDirection( wxBOTH ); fgSizerGridOrigin->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); - + m_staticTextGridPosX = new wxStaticText( sbLeftSizer->GetStaticBox(), wxID_ANY, _("X:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextGridPosX->Wrap( -1 ); fgSizerGridOrigin->Add( m_staticTextGridPosX, 0, wxALIGN_CENTER_VERTICAL, 5 ); - + m_GridOriginXCtrl = new wxTextCtrl( sbLeftSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizerGridOrigin->Add( m_GridOriginXCtrl, 0, wxEXPAND|wxLEFT, 5 ); - + m_TextPosXUnits = new wxStaticText( sbLeftSizer->GetStaticBox(), wxID_ANY, _("mm"), wxDefaultPosition, wxDefaultSize, 0 ); m_TextPosXUnits->Wrap( -1 ); - fgSizerGridOrigin->Add( m_TextPosXUnits, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT, 5 ); - + fgSizerGridOrigin->Add( m_TextPosXUnits, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxLEFT, 5 ); + m_staticTextGridPosY = new wxStaticText( sbLeftSizer->GetStaticBox(), wxID_ANY, _("Y:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextGridPosY->Wrap( -1 ); fgSizerGridOrigin->Add( m_staticTextGridPosY, 0, wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM, 5 ); - + m_GridOriginYCtrl = new wxTextCtrl( sbLeftSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizerGridOrigin->Add( m_GridOriginYCtrl, 0, wxEXPAND|wxTOP|wxBOTTOM|wxLEFT, 5 ); - + m_TextPosYUnits = new wxStaticText( sbLeftSizer->GetStaticBox(), wxID_ANY, _("mm"), wxDefaultPosition, wxDefaultSize, 0 ); m_TextPosYUnits->Wrap( -1 ); - fgSizerGridOrigin->Add( m_TextPosYUnits, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT, 5 ); - - + fgSizerGridOrigin->Add( m_TextPosYUnits, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxLEFT, 5 ); + + sbLeftSizer->Add( fgSizerGridOrigin, 0, wxEXPAND|wxALL, 5 ); - - + + bUpperSizer->Add( sbLeftSizer, 1, wxEXPAND|wxALL, 5 ); - + wxStaticBoxSizer* sbUserGridSizer; sbUserGridSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("User Defined Grid") ), wxVERTICAL ); - + wxFlexGridSizer* fgSizer31; fgSizer31 = new wxFlexGridSizer( 2, 3, 0, 0 ); fgSizer31->AddGrowableCol( 1 ); fgSizer31->SetFlexibleDirection( wxBOTH ); fgSizer31->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); - + m_staticTextSizeX = new wxStaticText( sbUserGridSizer->GetStaticBox(), wxID_ANY, _("Size X:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextSizeX->Wrap( -1 ); fgSizer31->Add( m_staticTextSizeX, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 5 ); - + m_OptGridSizeX = new wxTextCtrl( sbUserGridSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer31->Add( m_OptGridSizeX, 0, wxEXPAND|wxBOTTOM|wxLEFT, 5 ); - + m_TextSizeXUnits = new wxStaticText( sbUserGridSizer->GetStaticBox(), wxID_ANY, _("mm"), wxDefaultPosition, wxDefaultSize, 0 ); m_TextSizeXUnits->Wrap( -1 ); - fgSizer31->Add( m_TextSizeXUnits, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM, 5 ); - + fgSizer31->Add( m_TextSizeXUnits, 0, wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT, 5 ); + m_staticTextSizeY = new wxStaticText( sbUserGridSizer->GetStaticBox(), wxID_ANY, _("Size Y:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextSizeY->Wrap( -1 ); fgSizer31->Add( m_staticTextSizeY, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 ); - + m_OptGridSizeY = new wxTextCtrl( sbUserGridSizer->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer31->Add( m_OptGridSizeY, 0, wxEXPAND|wxLEFT, 5 ); - + m_TextSizeYUnits = new wxStaticText( sbUserGridSizer->GetStaticBox(), wxID_ANY, _("mm"), wxDefaultPosition, wxDefaultSize, 0 ); m_TextSizeYUnits->Wrap( -1 ); - fgSizer31->Add( m_TextSizeYUnits, 0, wxALIGN_CENTER_VERTICAL, 5 ); - - + fgSizer31->Add( m_TextSizeYUnits, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); + + sbUserGridSizer->Add( fgSizer31, 0, wxEXPAND|wxALL, 5 ); - - + + bUpperSizer->Add( sbUserGridSizer, 1, wxEXPAND|wxTOP|wxBOTTOM|wxLEFT, 5 ); - - + + bSizerMain->Add( bUpperSizer, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 ); - + wxStaticBoxSizer* sbFastSwitchSizer; sbFastSwitchSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Fast Switching") ), wxVERTICAL ); - + wxFlexGridSizer* fgSizer3; fgSizer3 = new wxFlexGridSizer( 2, 3, 0, 5 ); fgSizer3->AddGrowableCol( 1 ); fgSizer3->SetFlexibleDirection( wxBOTH ); fgSizer3->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); - + m_staticTextGrid1 = new wxStaticText( sbFastSwitchSizer->GetStaticBox(), wxID_ANY, _("Grid 1:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextGrid1->Wrap( -1 ); fgSizer3->Add( m_staticTextGrid1, 0, wxALIGN_CENTER_VERTICAL, 5 ); - + wxArrayString m_grid1CtrlChoices; m_grid1Ctrl = new wxChoice( sbFastSwitchSizer->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, m_grid1CtrlChoices, 0 ); m_grid1Ctrl->SetSelection( 0 ); m_grid1Ctrl->SetMinSize( wxSize( 240,-1 ) ); - + fgSizer3->Add( m_grid1Ctrl, 1, wxALL, 5 ); - + m_grid1HotKey = new wxStaticText( sbFastSwitchSizer->GetStaticBox(), wxID_ANY, _("(hotkey)"), wxDefaultPosition, wxDefaultSize, 0 ); m_grid1HotKey->Wrap( -1 ); fgSizer3->Add( m_grid1HotKey, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); - + m_staticTextGrid2 = new wxStaticText( sbFastSwitchSizer->GetStaticBox(), wxID_ANY, _("Grid 2:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticTextGrid2->Wrap( -1 ); fgSizer3->Add( m_staticTextGrid2, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); - + wxArrayString m_grid2CtrlChoices; m_grid2Ctrl = new wxChoice( sbFastSwitchSizer->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, m_grid2CtrlChoices, 0 ); m_grid2Ctrl->SetSelection( 0 ); m_grid2Ctrl->SetMinSize( wxSize( 240,-1 ) ); - + fgSizer3->Add( m_grid2Ctrl, 1, wxALL, 5 ); - + m_grid2HotKey = new wxStaticText( sbFastSwitchSizer->GetStaticBox(), wxID_ANY, _("(hotkey)"), wxDefaultPosition, wxDefaultSize, 0 ); m_grid2HotKey->Wrap( -1 ); fgSizer3->Add( m_grid2HotKey, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); - - + + sbFastSwitchSizer->Add( fgSizer3, 0, wxEXPAND|wxTOP|wxBOTTOM|wxLEFT, 5 ); - - + + bSizerMain->Add( sbFastSwitchSizer, 0, wxEXPAND|wxALL, 10 ); - + m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); bSizerMain->Add( m_staticline1, 0, wxEXPAND|wxRIGHT|wxLEFT, 5 ); - + wxBoxSizer* bButtonSizer; bButtonSizer = new wxBoxSizer( wxHORIZONTAL ); - + m_buttonReset = new wxButton( this, wxID_ANY, _("Reset Grid Origin"), wxDefaultPosition, wxDefaultSize, 0 ); bButtonSizer->Add( m_buttonReset, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); - - + + bButtonSizer->Add( 0, 0, 1, wxEXPAND, 5 ); - + m_sdbSizer = new wxStdDialogButtonSizer(); m_sdbSizerOK = new wxButton( this, wxID_OK ); m_sdbSizer->AddButton( m_sdbSizerOK ); m_sdbSizerCancel = new wxButton( this, wxID_CANCEL ); m_sdbSizer->AddButton( m_sdbSizerCancel ); m_sdbSizer->Realize(); - + bButtonSizer->Add( m_sdbSizer, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); - - + + bSizerMain->Add( bButtonSizer, 0, wxEXPAND|wxLEFT, 10 ); - - + + this->SetSizer( bSizerMain ); this->Layout(); bSizerMain->Fit( this ); - + // Connect Events this->Connect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( DIALOG_SET_GRID_BASE::OnInitDlg ) ); m_buttonReset->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SET_GRID_BASE::OnResetGridOrgClick ), NULL, this ); @@ -184,5 +184,5 @@ DIALOG_SET_GRID_BASE::~DIALOG_SET_GRID_BASE() m_buttonReset->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SET_GRID_BASE::OnResetGridOrgClick ), NULL, this ); m_sdbSizerCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SET_GRID_BASE::OnCancelClick ), NULL, this ); m_sdbSizerOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SET_GRID_BASE::OnOkClick ), NULL, this ); - + } diff --git a/pcbnew/dialogs/dialog_set_grid_base.fbp b/pcbnew/dialogs/dialog_set_grid_base.fbp index 251c8a6ba5..7cb14fcf90 100644 --- a/pcbnew/dialogs/dialog_set_grid_base.fbp +++ b/pcbnew/dialogs/dialog_set_grid_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -14,6 +14,7 @@ dialog_set_grid_base 1000 none + 1 dialog_set_grid @@ -52,42 +53,7 @@ - - - - - - - - - - - - - - - OnInitDlg - - - - - - - - - - - - - - - - - - - - bSizerMain @@ -114,7 +80,6 @@ wxVERTICAL 1 none - 5 wxEXPAND|wxALL @@ -164,6 +129,7 @@ 0 wxID_ANY X: + 0 0 @@ -189,29 +155,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -276,38 +219,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT + wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxLEFT 0 1 @@ -338,6 +254,7 @@ 0 wxID_ANY mm + 0 0 @@ -363,29 +280,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -421,6 +315,7 @@ 0 wxID_ANY Y: + 0 0 @@ -446,29 +341,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -533,38 +405,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT + wxALIGN_CENTER_VERTICAL|wxALIGN_LEFT|wxLEFT 0 1 @@ -595,6 +440,7 @@ 0 wxID_ANY mm + 0 0 @@ -620,29 +466,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -661,7 +484,6 @@ wxVERTICAL 1 none - 5 wxEXPAND|wxALL @@ -711,6 +533,7 @@ 0 wxID_ANY Size X: + 0 0 @@ -736,29 +559,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -823,38 +623,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxALIGN_CENTER_VERTICAL|wxBOTTOM + wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxLEFT 0 1 @@ -885,6 +658,7 @@ 0 wxID_ANY mm + 0 0 @@ -910,29 +684,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -968,6 +719,7 @@ 0 wxID_ANY Size Y: + 0 0 @@ -993,29 +745,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -1080,38 +809,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxALIGN_CENTER_VERTICAL + wxALIGN_CENTER_VERTICAL|wxLEFT 0 1 @@ -1142,6 +844,7 @@ 0 wxID_ANY mm + 0 0 @@ -1167,29 +870,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -1210,7 +890,6 @@ wxVERTICAL 1 none - 5 wxEXPAND|wxTOP|wxBOTTOM|wxLEFT @@ -1260,6 +939,7 @@ 0 wxID_ANY Grid 1: + 0 0 @@ -1285,29 +965,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -1372,30 +1029,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -1431,6 +1064,7 @@ 0 wxID_ANY (hotkey) + 0 0 @@ -1456,29 +1090,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -1514,6 +1125,7 @@ 0 wxID_ANY Grid 2: + 0 0 @@ -1539,29 +1151,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -1626,30 +1215,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -1685,6 +1250,7 @@ 0 wxID_ANY (hotkey) + 0 0 @@ -1710,29 +1276,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -1795,29 +1338,6 @@ - - - - - - - - - - - - - - - - - - - - - - - @@ -1844,25 +1364,31 @@ + 1 0 1 1 + 0 0 + Dock 0 Left 1 1 + 0 0 wxID_ANY Reset Grid Origin + + 0 0 @@ -1877,6 +1403,8 @@ protected 1 + + Resizable 1 @@ -1892,29 +1420,6 @@ OnResetGridOrgClick - - - - - - - - - - - - - - - - - - - - - - - @@ -1943,14 +1448,8 @@ m_sdbSizer protected - OnCancelClick - - - OnOkClick - - diff --git a/pcbnew/dialogs/dialog_set_grid_base.h b/pcbnew/dialogs/dialog_set_grid_base.h index b561415b11..792deb7111 100644 --- a/pcbnew/dialogs/dialog_set_grid_base.h +++ b/pcbnew/dialogs/dialog_set_grid_base.h @@ -1,12 +1,11 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Dec 30 2017) +// C++ code generated with wxFormBuilder (version Oct 26 2018) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// -#ifndef __DIALOG_SET_GRID_BASE_H__ -#define __DIALOG_SET_GRID_BASE_H__ +#pragma once #include #include @@ -23,6 +22,9 @@ #include #include #include +#include +#include +#include #include #include @@ -35,7 +37,7 @@ class DIALOG_SET_GRID_BASE : public DIALOG_SHIM { private: - + protected: wxStaticText* m_staticTextGridPosX; wxTextCtrl* m_GridOriginXCtrl; @@ -60,19 +62,18 @@ class DIALOG_SET_GRID_BASE : public DIALOG_SHIM wxStdDialogButtonSizer* m_sdbSizer; wxButton* m_sdbSizerOK; wxButton* m_sdbSizerCancel; - + // Virtual event handlers, overide them in your derived class virtual void OnInitDlg( wxInitDialogEvent& event ) { event.Skip(); } virtual void OnResetGridOrgClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnCancelClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnOkClick( wxCommandEvent& event ) { event.Skip(); } - - + + public: - - DIALOG_SET_GRID_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Grid Settings"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + + DIALOG_SET_GRID_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Grid Settings"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); ~DIALOG_SET_GRID_BASE(); - + }; -#endif //__DIALOG_SET_GRID_BASE_H__ diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index d050dd9b9b..032aa38ca1 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -174,9 +174,6 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, SetScreen( new PCB_SCREEN( GetPageSettings().GetSizeIU() ) ); GetScreen()->SetMaxUndoItems( m_UndoRedoCountMax ); - GetScreen()->AddGrid( m_UserGridSize, EDA_UNITS::UNSCALED, ID_POPUP_GRID_USER ); - GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); - // In modedit, set the default paper size to A4 for plot/print SetPageSettings( PAGE_INFO( PAGE_INFO::A4 ) ); @@ -233,7 +230,6 @@ FOOTPRINT_EDIT_FRAME::FOOTPRINT_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent, m_auimgr.GetPane( "InfoBar" ).Hide(); m_auimgr.Update(); - GetToolManager()->RunAction( ACTIONS::gridPreset, true, m_LastGridSizeId ); GetToolManager()->RunAction( ACTIONS::zoomFitScreen, false ); updateTitle(); InitExitKey(); @@ -272,7 +268,6 @@ void FOOTPRINT_EDIT_FRAME::SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasTyp PCB_BASE_FRAME::SwitchCanvas( aCanvasType ); GetCanvas()->GetGAL()->SetAxesEnabled( true ); - GetCanvas()->GetGAL()->SetGridSize( VECTOR2D( GetScreen()->GetGridSize() ) ); // The base class method *does not reinit* the layers manager. We must upate the layer // widget to match board visibility states, both layers and render columns, and and some @@ -448,7 +443,7 @@ void FOOTPRINT_EDIT_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) // aCfg will be the PCBNEW_SETTINGS FOOTPRINT_EDITOR_SETTINGS* cfg = GetSettings(); - EDA_DRAW_FRAME::LoadSettings( cfg ); + PCB_BASE_FRAME::LoadSettings( cfg ); GetDesignSettings() = cfg->m_DesignSettings; @@ -462,7 +457,7 @@ void FOOTPRINT_EDIT_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) // aCfg will be the PCBNEW_SETTINGS auto cfg = GetSettings(); - EDA_DRAW_FRAME::SaveSettings( cfg ); + PCB_BASE_FRAME::SaveSettings( cfg ); cfg->m_DesignSettings = GetDesignSettings(); cfg->m_Display = m_DisplayOptions; @@ -859,7 +854,7 @@ void FOOTPRINT_EDIT_FRAME::setupTools() // Create the manager and dispatcher & route draw panel events to the dispatcher m_toolManager = new TOOL_MANAGER; m_toolManager->SetEnvironment( GetBoard(), GetCanvas()->GetView(), - GetCanvas()->GetViewControls(), this ); + GetCanvas()->GetViewControls(), config(), this ); m_actions = new PCB_ACTIONS(); m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions ); diff --git a/pcbnew/footprint_preview_panel.cpp b/pcbnew/footprint_preview_panel.cpp index 695491747b..e054c21e0b 100644 --- a/pcbnew/footprint_preview_panel.cpp +++ b/pcbnew/footprint_preview_panel.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -419,23 +418,17 @@ FOOTPRINT_PREVIEW_PANEL* FOOTPRINT_PREVIEW_PANEL::New( KIWAY* aKiway, wxWindow* auto panel = new FOOTPRINT_PREVIEW_PANEL( aKiway, aParent, std::move( gal_opts ), canvasType ); if( pcbnew ) - { - panel->GetGAL()->SetGridVisibility( pcbnew->IsGridVisible() ); - panel->GetGAL()->SetGridSize( VECTOR2D( pcbnew->GetScreen()->GetGridSize() ) ); - panel->GetView()->GetPainter()->GetSettings()->LoadColors( pcbnew->GetColorSettings() ); - } else - { - panel->GetGAL()->SetGridVisibility( cfg->m_Window.grid.show ); - - // Read grid size: - std::unique_ptr temp_screen = std::make_unique( wxSize() ); - temp_screen->SetGrid( ID_POPUP_GRID_LEVEL_1000 + cfg->m_Window.grid.last_size ); - panel->GetGAL()->SetGridSize( VECTOR2D( temp_screen->GetGridSize() ) ); - panel->UpdateColors(); - } + + const GRID_SETTINGS& gridCfg = cfg->m_Window.grid; + + panel->GetGAL()->SetGridVisibility( gridCfg.show ); + + int gridIdx = std::max( 0, std::min( gridCfg.last_size_idx, (int) gridCfg.sizes.size() ) ); + int gridSize = (int) ValueFromString( EDA_UNITS::INCHES, gridCfg.sizes[ gridIdx ], true ); + panel->GetGAL()->SetGridSize( VECTOR2D( gridSize, gridSize ) ); return panel; } diff --git a/pcbnew/footprint_viewer_frame.cpp b/pcbnew/footprint_viewer_frame.cpp index a4a726080e..98c0361e29 100644 --- a/pcbnew/footprint_viewer_frame.cpp +++ b/pcbnew/footprint_viewer_frame.cpp @@ -195,8 +195,6 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent LoadSettings( config() ); GetGalDisplayOptions().m_axesEnabled = true; - GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); - // Create GAL canvas m_canvasType = LoadCanvasTypeSetting(); auto drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize, @@ -206,7 +204,7 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent // Create the manager and dispatcher & route draw panel events to the dispatcher m_toolManager = new TOOL_MANAGER; m_toolManager->SetEnvironment( GetBoard(), drawPanel->GetView(), - drawPanel->GetViewControls(), this ); + drawPanel->GetViewControls(), config(), this ); m_actions = new PCB_ACTIONS(); m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions ); drawPanel->SetEventDispatcher( m_toolDispatcher ); @@ -730,8 +728,6 @@ void FOOTPRINT_VIEWER_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) // Fetch grid settings from Footprint Editor auto fpedit = Pgm().GetSettingsManager().GetAppSettings(); - SetGridVisibility( fpedit->m_Window.grid.show ); - GetGalDisplayOptions().ReadWindowSettings( fpedit->m_Window ); } @@ -742,7 +738,7 @@ void FOOTPRINT_VIEWER_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) wxCHECK( cfg, /*void*/ ); // We don't want to store anything other than the window settings - EDA_BASE_FRAME::SaveSettings( cfg ); + PCB_BASE_FRAME::SaveSettings( cfg ); cfg->m_FootprintViewerZoom = GetCanvas()->GetView()->GetScale(); } @@ -1009,17 +1005,6 @@ void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode ) } -void FOOTPRINT_VIEWER_FRAME::ApplyDisplaySettingsToGAL() -{ - auto painter = static_cast( GetCanvas()->GetView()->GetPainter() ); - KIGFX::PCB_RENDER_SETTINGS* settings = painter->GetSettings(); - settings->LoadDisplayOptions( m_DisplayOptions, false ); - - GetCanvas()->GetView()->UpdateAllItems( KIGFX::ALL ); - GetCanvas()->Refresh(); -} - - void FOOTPRINT_VIEWER_FRAME::updateView() { GetCanvas()->UpdateColors(); diff --git a/pcbnew/footprint_viewer_frame.h b/pcbnew/footprint_viewer_frame.h index 99df0a6cd0..246f8a4fa2 100644 --- a/pcbnew/footprint_viewer_frame.h +++ b/pcbnew/footprint_viewer_frame.h @@ -56,9 +56,6 @@ public: ///> @copydoc PCB_BASE_FRAME::GetModel() BOARD_ITEM_CONTAINER* GetModel() const override; - /// Updates the GAL with display settings changes - void ApplyDisplaySettingsToGAL(); - virtual COLOR4D GetGridColor() override; bool GetAutoZoom() override; diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp index 9c2a22c361..f2961fe8c5 100644 --- a/pcbnew/footprint_wizard_frame.cpp +++ b/pcbnew/footprint_wizard_frame.cpp @@ -132,8 +132,6 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( KIWAY* aKiway, wxWindow* aParent GetBoard()->SetElementVisibility( LAYER_NO_CONNECTS, false ); - GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); - // Create GAL canvas #ifdef __WXMAC__ // Cairo renderer doesn't handle Retina displays @@ -148,7 +146,7 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( KIWAY* aKiway, wxWindow* aParent // Create the manager and dispatcher & route draw panel events to the dispatcher m_toolManager = new TOOL_MANAGER; m_toolManager->SetEnvironment( GetBoard(), gal_drawPanel->GetView(), - gal_drawPanel->GetViewControls(), this ); + gal_drawPanel->GetViewControls(), config(), this ); m_actions = new PCB_ACTIONS(); m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions ); gal_drawPanel->SetEventDispatcher( m_toolDispatcher ); @@ -520,29 +518,23 @@ void FOOTPRINT_WIZARD_FRAME::ClickOnPageList( wxCommandEvent& event ) void FOOTPRINT_WIZARD_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) { - auto cfg = dynamic_cast( aCfg ); - wxASSERT( cfg ); + PCBNEW_SETTINGS* cfg = dynamic_cast( aCfg ); + wxCHECK( cfg, /*void*/ ); - if( cfg ) - { - EDA_DRAW_FRAME::LoadSettings( cfg ); + PCB_BASE_FRAME::LoadSettings( cfg ); - m_auiPerspective = cfg->m_FootprintViewer.perspective; - } + m_auiPerspective = cfg->m_FootprintViewer.perspective; } void FOOTPRINT_WIZARD_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) { - auto cfg = dynamic_cast( aCfg ); - wxASSERT( cfg ); + PCBNEW_SETTINGS* cfg = dynamic_cast( aCfg ); + wxCHECK( cfg, /*void*/ ); - if( cfg ) - { - EDA_DRAW_FRAME::SaveSettings( cfg ); + PCB_BASE_FRAME::SaveSettings( cfg ); - cfg->m_FootprintViewer.perspective = m_auimgr.SavePerspective().ToStdString(); - } + cfg->m_FootprintViewer.perspective = m_auimgr.SavePerspective().ToStdString(); } diff --git a/pcbnew/pcb_base_edit_frame.cpp b/pcbnew/pcb_base_edit_frame.cpp index 3b7d892f31..4385160414 100644 --- a/pcbnew/pcb_base_edit_frame.cpp +++ b/pcbnew/pcb_base_edit_frame.cpp @@ -104,7 +104,7 @@ void PCB_BASE_EDIT_FRAME::SetBoard( BOARD* aBoard ) GetCanvas()->UpdateColors(); m_toolManager->SetEnvironment( aBoard, GetCanvas()->GetView(), - GetCanvas()->GetViewControls(), this ); + GetCanvas()->GetViewControls(), config(), this ); if( new_board ) m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD ); diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index 9735d0a4da..e147b31129 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -55,6 +55,7 @@ #include #include #include +#include wxDEFINE_EVENT( BOARD_CHANGED, wxCommandEvent ); @@ -70,11 +71,6 @@ PCB_BASE_FRAME::PCB_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame EDA_DRAW_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ), m_Pcb( nullptr ) { - m_UserGridSize = wxPoint( (int) 10 * IU_PER_MILS, (int) 10 * IU_PER_MILS ); - - m_FastGrid1 = 0; - m_FastGrid2 = 0; - m_zoomLevelCoeff = 11.0 * IU_PER_MILS; // Adjusted to roughly displays zoom level = 1 // when the screen shows a 1:1 image // obviously depends on the monitor, @@ -522,26 +518,13 @@ void PCB_BASE_FRAME::DisplayGridMsg() switch( m_userUnits ) { - case EDA_UNITS::INCHES: - gridformatter = "grid X %.6f Y %.6f"; - break; - - case EDA_UNITS::MILLIMETRES: - gridformatter = "grid X %.6f Y %.6f"; - break; - - default: - gridformatter = "grid X %f Y %f"; - break; + case EDA_UNITS::INCHES: gridformatter = "grid X %.6f Y %.6f"; break; + case EDA_UNITS::MILLIMETRES: gridformatter = "grid X %.6f Y %.6f"; break; + default: gridformatter = "grid X %f Y %f"; break; } - BASE_SCREEN* screen = GetScreen(); - wxArrayString gridsList; - - int icurr = screen->BuildGridsChoiceList( gridsList, m_userUnits != EDA_UNITS::INCHES ); - GRID_TYPE& grid = screen->GetGrid( icurr ); - double grid_x = To_User_Unit( m_userUnits, grid.m_Size.x ); - double grid_y = To_User_Unit( m_userUnits, grid.m_Size.y ); + double grid_x = To_User_Unit( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().x ); + double grid_y = To_User_Unit( m_userUnits, GetCanvas()->GetGAL()->GetGridSize().y ); line.Printf( gridformatter, grid_x, grid_y ); SetStatusText( line, 4 ); @@ -654,23 +637,40 @@ void PCB_BASE_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg ) { EDA_DRAW_FRAME::LoadSettings( aCfg ); - auto cfg = dynamic_cast( aCfg ); - wxCHECK( cfg, /*void*/ ); + if( aCfg->m_Window.grid.sizes.empty() ) + { + aCfg->m_Window.grid.sizes = { "1000 mil", + "500 mil", + "250 mil", + "200 mil", + "100 mil", + "50 mil", + "25 mil", + "20 mil", + "10 mil", + "5 mil", + "2 mil", + "1 mil", + "5.0 mm", + "2.5 mm", + "1.0 mm", + "0.5 mm", + "0.25 mm", + "0.2 mm", + "0.1 mm", + "0.05 mm", + "0.025 mm", + "0.01 mm" }; + } - // Ensure grid id is an existent grid id: - if( (m_LastGridSizeId <= 0) || - (m_LastGridSizeId > (ID_POPUP_GRID_USER - ID_POPUP_GRID_LEVEL_1000)) ) - m_LastGridSizeId = ID_POPUP_GRID_LEVEL_500 - ID_POPUP_GRID_LEVEL_1000; + // Some, but not all derived classes have a PCBNEW_SETTINGS. + PCBNEW_SETTINGS* cfg = dynamic_cast( aCfg ); - EDA_UNITS userGridUnits = static_cast( cfg->m_UserGrid.units ); - m_UserGridSize.x = (int) From_User_Unit( userGridUnits, cfg->m_UserGrid.size_x ); - m_UserGridSize.y = (int) From_User_Unit( userGridUnits, cfg->m_UserGrid.size_y ); - - m_DisplayOptions = cfg->m_Display; - m_PolarCoords = cfg->m_PolarCoords; - - m_FastGrid1 = cfg->m_FastGrid1; - m_FastGrid2 = cfg->m_FastGrid2; + if( cfg ) + { + m_DisplayOptions = cfg->m_Display; + m_PolarCoords = cfg->m_PolarCoords; + } } @@ -678,18 +678,14 @@ void PCB_BASE_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg ) { EDA_DRAW_FRAME::SaveSettings( aCfg ); - auto cfg = dynamic_cast( aCfg ); - wxCHECK( cfg, /*void*/ ); + // Some, but not all derived classes have a PCBNEW_SETTINGS. + PCBNEW_SETTINGS* cfg = dynamic_cast( aCfg ); - cfg->m_UserGrid.size_x = To_User_Unit( m_userUnits, m_UserGridSize.x ); - cfg->m_UserGrid.size_y = To_User_Unit( m_userUnits, m_UserGridSize.y ); - cfg->m_UserGrid.units = static_cast( m_userUnits ); - - cfg->m_Display = m_DisplayOptions; - cfg->m_PolarCoords = m_PolarCoords; - - cfg->m_FastGrid1 = m_FastGrid1; - cfg->m_FastGrid2 = m_FastGrid2; + if( cfg ) + { + cfg->m_Display = m_DisplayOptions; + cfg->m_PolarCoords = m_PolarCoords; + } } @@ -752,18 +748,16 @@ void PCB_BASE_FRAME::UpdateGridSelectBox() // Update grid values with the current units setting. m_gridSelectBox->Clear(); wxArrayString gridsList; - int icurr = GetScreen()->BuildGridsChoiceList( gridsList, GetUserUnits() != EDA_UNITS::INCHES ); - for( size_t i = 0; i < GetScreen()->GetGridCount(); i++ ) - { - GRID_TYPE& grid = GetScreen()->GetGrid( i ); - m_gridSelectBox->Append( gridsList[i], (void*) &grid.m_CmdId ); - } + GRID_MENU::BuildChoiceList( &gridsList, config(), GetUserUnits() != EDA_UNITS::INCHES ); + + for( const wxString& grid : gridsList ) + m_gridSelectBox->Append( grid ); m_gridSelectBox->Append( wxT( "---" ) ); m_gridSelectBox->Append( _( "Edit User Grid..." ) ); - m_gridSelectBox->SetSelection( icurr ); + m_gridSelectBox->SetSelection( config()->m_Window.grid.last_size_idx ); } @@ -794,52 +788,6 @@ void PCB_BASE_FRAME::updateZoomSelectBox() } -void PCB_BASE_FRAME::SetFastGrid1() -{ - if( m_FastGrid1 >= (int)GetScreen()->GetGridCount() ) - return; - - int cmdId = GetScreen()->GetGrids()[m_FastGrid1].m_CmdId - ID_POPUP_GRID_LEVEL_1000; - GetToolManager()->RunAction( "common.Control.gridPreset", true, cmdId ); -} - - -void PCB_BASE_FRAME::SetFastGrid2() -{ - if( m_FastGrid2 >= (int)GetScreen()->GetGridCount() ) - return; - - int cmdId = GetScreen()->GetGrids()[m_FastGrid2].m_CmdId - ID_POPUP_GRID_LEVEL_1000; - GetToolManager()->RunAction( "common.Control.gridPreset", true, cmdId ); -} - - -bool PCB_BASE_FRAME::IsGridVisible() const -{ - return m_drawGrid; -} - - -void PCB_BASE_FRAME::SetGridVisibility( bool aVisible ) -{ - m_drawGrid = aVisible; - - // Update the display with the new grid - if( GetCanvas() ) - { - // Check to ensure these exist, since this function could be called before - // the GAL and View have been created - if( GetCanvas()->GetGAL() ) - GetCanvas()->GetGAL()->SetGridVisibility( aVisible ); - - if( GetCanvas()->GetView() ) - GetCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); - - GetCanvas()->Refresh(); - } -} - - PCB_DRAW_PANEL_GAL* PCB_BASE_FRAME::GetCanvas() const { return static_cast( EDA_DRAW_FRAME::GetCanvas() ); @@ -855,7 +803,7 @@ void PCB_BASE_FRAME::ActivateGalCanvas() if( m_toolManager ) { m_toolManager->SetEnvironment( m_Pcb, GetCanvas()->GetView(), - GetCanvas()->GetViewControls(), this ); + GetCanvas()->GetViewControls(), config(), this ); } SetBoard( m_Pcb ); @@ -873,9 +821,5 @@ void PCB_BASE_FRAME::ActivateGalCanvas() canvas->GetView()->RecacheAllItems(); canvas->SetEventDispatcher( m_toolDispatcher ); canvas->StartDrawing(); - - // Initialize the grid settings - GetCanvas()->GetGAL()->SetGridSize( VECTOR2D( GetScreen()->GetGridSize() ) ); - GetCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() ); } diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 5b55c40e37..15d071b9bf 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -44,7 +44,6 @@ #include #include #include -#include #include #include #include @@ -67,7 +66,6 @@ #include #include #include -#include #include #include #include @@ -213,9 +211,6 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : // PCB drawings start in the upper left corner. GetScreen()->m_Center = false; - GetScreen()->AddGrid( m_UserGridSize, EDA_UNITS::UNSCALED, ID_POPUP_GRID_USER ); - GetScreen()->SetGrid( ID_POPUP_GRID_LEVEL_1000 + m_LastGridSizeId ); - setupTools(); ReCreateMenuBar(); ReCreateHToolbar(); @@ -270,7 +265,6 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : m_auimgr.GetPane( "InfoBar" ).Hide(); m_auimgr.Update(); - GetToolManager()->RunAction( ACTIONS::gridPreset, true, m_LastGridSizeId ); GetToolManager()->RunAction( ACTIONS::zoomFitScreen, false ); m_canvasType = LoadCanvasTypeSetting(); @@ -430,7 +424,7 @@ void PCB_EDIT_FRAME::setupTools() // Create the manager and dispatcher & route draw panel events to the dispatcher m_toolManager = new TOOL_MANAGER; m_toolManager->SetEnvironment( m_Pcb, GetCanvas()->GetView(), - GetCanvas()->GetViewControls(), this ); + GetCanvas()->GetViewControls(), config(), this ); m_actions = new PCB_ACTIONS(); m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions ); @@ -961,9 +955,7 @@ void PCB_EDIT_FRAME::SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType ) // switches currently used canvas (Cairo / OpenGL). PCB_BASE_FRAME::SwitchCanvas( aCanvasType ); - GetCanvas()->GetGAL()->SetGridSize( VECTOR2D( GetScreen()->GetGridSize() ) ); - - // The base class method *does not reinit* the layers manager. We must upate the + // The base class method *does not* reinitialize the layers manager. We must upate the // layer widget to match board visibility states, both layers and render columns. syncLayerVisibilities(); syncLayerWidgetLayer(); diff --git a/pcbnew/pcb_screen.cpp b/pcbnew/pcb_screen.cpp index 03c2f20271..31a5481d28 100644 --- a/pcbnew/pcb_screen.cpp +++ b/pcbnew/pcb_screen.cpp @@ -25,24 +25,12 @@ */ #include -#include -#include -#include #include -#include // FILLED #include - -#include -#include #include -#include - #define ZOOM_FACTOR( x ) ( x * IU_PER_MILS / 10 ) -#define DMIL_GRID( x ) wxRealPoint( x * IU_PER_MILS / 10, x * IU_PER_MILS / 10 ) -#define MM_GRID( x ) wxRealPoint( x * IU_PER_MM, x * IU_PER_MM ) - /** Default Pcbnew zoom values. @@ -122,49 +110,12 @@ static const double pcbZoomList[] = }; -// Default grid sizes for PCB editor screens. -static GRID_TYPE pcbGridList[] = -{ - // predefined grid list in 0.0001 inches - { ID_POPUP_GRID_LEVEL_1000, DMIL_GRID( 1000 ) }, - { ID_POPUP_GRID_LEVEL_500, DMIL_GRID( 500 ) }, - { ID_POPUP_GRID_LEVEL_250, DMIL_GRID( 250 ) }, - { ID_POPUP_GRID_LEVEL_200, DMIL_GRID( 200 ) }, - { ID_POPUP_GRID_LEVEL_100, DMIL_GRID( 100 ) }, - { ID_POPUP_GRID_LEVEL_50, DMIL_GRID( 50 ) }, - { ID_POPUP_GRID_LEVEL_25, DMIL_GRID( 25 ) }, - { ID_POPUP_GRID_LEVEL_20, DMIL_GRID( 20 ) }, - { ID_POPUP_GRID_LEVEL_10, DMIL_GRID( 10 ) }, - { ID_POPUP_GRID_LEVEL_5, DMIL_GRID( 5 ) }, - { ID_POPUP_GRID_LEVEL_2, DMIL_GRID( 2 ) }, - { ID_POPUP_GRID_LEVEL_1, DMIL_GRID( 1 ) }, - - // predefined grid list in mm - { ID_POPUP_GRID_LEVEL_5MM, MM_GRID( 5.0 ) }, - { ID_POPUP_GRID_LEVEL_2_5MM, MM_GRID( 2.5 ) }, - { ID_POPUP_GRID_LEVEL_1MM, MM_GRID( 1.0 ) }, - { ID_POPUP_GRID_LEVEL_0_5MM, MM_GRID( 0.5 ) }, - { ID_POPUP_GRID_LEVEL_0_25MM, MM_GRID( 0.25 ) }, - { ID_POPUP_GRID_LEVEL_0_2MM, MM_GRID( 0.2 ) }, - { ID_POPUP_GRID_LEVEL_0_1MM, MM_GRID( 0.1 ) }, - { ID_POPUP_GRID_LEVEL_0_0_5MM, MM_GRID( 0.05 ) }, - { ID_POPUP_GRID_LEVEL_0_0_25MM, MM_GRID( 0.025 ) }, - { ID_POPUP_GRID_LEVEL_0_0_1MM, MM_GRID( 0.01 ) } -}; - - PCB_SCREEN::PCB_SCREEN( const wxSize& aPageSizeIU ) : BASE_SCREEN( SCREEN_T ) { for( double zoom : pcbZoomList ) m_ZoomList.push_back( zoom ); - for( GRID_TYPE grid : pcbGridList ) - AddGrid( grid ); - - // Set the working grid size to a reasonable value (in 1/10000 inch) - SetGrid( DMIL_GRID( 500 ) ); - m_Active_Layer = F_Cu; // default active layer = front layer m_Route_Layer_TOP = F_Cu; // default layers pair for vias (bottom to top) m_Route_Layer_BOTTOM = B_Cu; diff --git a/pcbnew/pcbnew_settings.cpp b/pcbnew/pcbnew_settings.cpp index c41f158d5e..fd65ec6610 100644 --- a/pcbnew/pcbnew_settings.cpp +++ b/pcbnew/pcbnew_settings.cpp @@ -59,7 +59,6 @@ PCBNEW_SETTINGS::PCBNEW_SETTINGS() m_PlaceFile(), m_Plot(), m_FootprintChooser(), - m_UserGrid(), m_Zones(), m_FootprintViewer(), m_FootprintWizard(), @@ -120,13 +119,6 @@ PCBNEW_SETTINGS::PCBNEW_SETTINGS() m_params.emplace_back( new PARAM( "editing.use_45_degree_graphic_segments", &m_Use45DegreeGraphicSegments, false ) ); - m_params.emplace_back( new PARAM( "grid.user.units", - &m_UserGrid.units, static_cast( EDA_UNITS::INCHES ) ) ); - - m_params.emplace_back( new PARAM( "grid.user.size_x", &m_UserGrid.size_x, 0.01 ) ); - - m_params.emplace_back( new PARAM( "grid.user.size_y", &m_UserGrid.size_y, 0.01 ) ); - m_params.emplace_back( new PARAM( "pcb_display.graphic_items_fill", &m_Display.m_DisplayGraphicsFill, true ) ); @@ -460,10 +452,6 @@ bool PCBNEW_SETTINGS::MigrateFromLegacy( wxConfigBase* aCfg ) ret &= fromLegacy( aCfg, "Use45DegreeGraphicSegments", "editing.use_45_degree_graphic_segments" ); - ret &= fromLegacy( aCfg, f + "PcbUserGrid_X", "grid.user.size_x" ); - ret &= fromLegacy( aCfg, f + "PcbUserGrid_Y", "grid.user.size_y" ); - ret &= fromLegacy( aCfg, f + "PcbUserGrid_Unit", "grid.user.units" ); - ret &= fromLegacy( aCfg, "PcbAffT", "pcb_display.graphic_items_fill" ); ret &= fromLegacy( aCfg, "MaxLnkS", "pcb_display.max_links_shown" ); ret &= fromLegacy( aCfg, "ModAffC", "pcb_display.footprint_edge_fill" ); diff --git a/pcbnew/pcbnew_settings.h b/pcbnew/pcbnew_settings.h index a10315e407..2d6af30d77 100644 --- a/pcbnew/pcbnew_settings.h +++ b/pcbnew/pcbnew_settings.h @@ -187,13 +187,6 @@ public: int sash_v; }; - struct USER_GRID - { - double size_x; - double size_y; - int units; - }; - struct ZONES { int hatching_style; @@ -239,8 +232,6 @@ public: FOOTPRINT_CHOOSER m_FootprintChooser; - USER_GRID m_UserGrid; - ZONES m_Zones; WINDOW_SETTINGS m_FootprintViewer; diff --git a/pcbnew/tools/grid_helper.cpp b/pcbnew/tools/grid_helper.cpp index 4870081f03..15d006d35f 100644 --- a/pcbnew/tools/grid_helper.cpp +++ b/pcbnew/tools/grid_helper.cpp @@ -27,16 +27,13 @@ using namespace std::placeholders; #include - #include #include -#include #include #include #include #include - -#include +#include #include #include #include // for KiROUND @@ -50,14 +47,15 @@ using namespace std::placeholders; GRID_HELPER::GRID_HELPER( PCB_BASE_FRAME* aFrame ) : - m_frame( aFrame ) + m_frame( aFrame ), + m_toolMgr( aFrame->GetToolManager() ) { m_enableSnap = true; m_enableGrid = true; m_enableSnapLine = true; m_snapSize = 100; m_snapItem = nullptr; - KIGFX::VIEW* view = m_frame->GetCanvas()->GetView(); + KIGFX::VIEW* view = m_toolMgr->GetView(); m_viewAxis.SetSize( 20000 ); m_viewAxis.SetStyle( KIGFX::ORIGIN_VIEWITEM::CROSS ); @@ -87,9 +85,7 @@ GRID_HELPER::~GRID_HELPER() VECTOR2I GRID_HELPER::GetGrid() const { - PCB_SCREEN* screen = m_frame->GetScreen(); - - const wxRealPoint& size = screen->GetGridSize(); + VECTOR2D size = m_toolMgr->GetView()->GetGAL()->GetGridSize(); return VECTOR2I( KiROUND( size.x ), KiROUND( size.y ) ); } @@ -97,7 +93,9 @@ VECTOR2I GRID_HELPER::GetGrid() const VECTOR2I GRID_HELPER::GetOrigin() const { - return VECTOR2I( m_frame->GetGridOrigin() ); + VECTOR2D origin = m_toolMgr->GetView()->GetGAL()->GetGridOrigin(); + + return VECTOR2I( origin ); } @@ -107,12 +105,12 @@ void GRID_HELPER::SetAuxAxes( bool aEnable, const VECTOR2I& aOrigin ) { m_auxAxis = aOrigin; m_viewAxis.SetPosition( aOrigin ); - m_frame->GetCanvas()->GetView()->SetVisible( &m_viewAxis, true ); + m_toolMgr->GetView()->SetVisible( &m_viewAxis, true ); } else { m_auxAxis = OPT(); - m_frame->GetCanvas()->GetView()->SetVisible( &m_viewAxis, false ); + m_toolMgr->GetView()->SetVisible( &m_viewAxis, false ); } } @@ -219,7 +217,7 @@ VECTOR2I GRID_HELPER::BestDragOrigin( const VECTOR2I &aMousePos, std::vectorGetCanvas()->GetGAL()->GetWorldScale(); + double worldScale = m_toolMgr->GetView()->GetGAL()->GetWorldScale(); double lineSnapMinCornerDistance = 50.0 / worldScale; ANCHOR* nearestOutline = nearestAnchor( aMousePos, OUTLINE, LSET::AllLayersMask() ); @@ -263,9 +261,11 @@ std::set GRID_HELPER::queryVisible( const BOX2I& aArea, std::set items; std::vector selectedItems; - auto view = m_frame->GetCanvas()->GetView(); - auto activeLayers = view->GetPainter()->GetSettings()->GetActiveLayers(); - bool isHighContrast = view->GetPainter()->GetSettings()->GetHighContrast(); + KIGFX::VIEW* view = m_toolMgr->GetView(); + RENDER_SETTINGS* settings = view->GetPainter()->GetSettings(); + const std::set& activeLayers = settings->GetActiveLayers(); + bool isHighContrast = settings->GetHighContrast(); + view->Query( aArea, selectedItems ); for( auto it : selectedItems ) @@ -273,9 +273,12 @@ std::set GRID_HELPER::queryVisible( const BOX2I& aArea, BOARD_ITEM* item = static_cast( it.first ); // The item must be visible and on an active layer - if( view->IsVisible( item ) && ( !isHighContrast || activeLayers.count( it.second ) ) + if( view->IsVisible( item ) + && ( !isHighContrast || activeLayers.count( it.second ) ) && item->ViewGetLOD( it.second, view ) < view->GetScale() ) + { items.insert ( item ); + } } @@ -306,7 +309,7 @@ VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, BOARD_ITEM* aDrag VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLayers, const std::vector& aSkip ) { - double worldScale = m_frame->GetCanvas()->GetGAL()->GetWorldScale(); + double worldScale = m_toolMgr->GetView()->GetGAL()->GetWorldScale(); int snapRange = (int) ( m_snapSize / worldScale ); BOX2I bb( VECTOR2I( aOrigin.x - snapRange / 2, aOrigin.y - snapRange / 2 ), VECTOR2I( snapRange, snapRange ) ); @@ -328,12 +331,12 @@ VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLaye { m_viewSnapPoint.SetPosition( nearest->pos ); m_viewSnapLine.SetPosition( nearest->pos ); - m_frame->GetCanvas()->GetView()->SetVisible( &m_viewSnapLine, false ); + m_toolMgr->GetView()->SetVisible( &m_viewSnapLine, false ); - if( m_frame->GetCanvas()->GetView()->IsVisible( &m_viewSnapPoint ) ) - m_frame->GetCanvas()->GetView()->Update( &m_viewSnapPoint, KIGFX::GEOMETRY); + if( m_toolMgr->GetView()->IsVisible( &m_viewSnapPoint ) ) + m_toolMgr->GetView()->Update( &m_viewSnapPoint, KIGFX::GEOMETRY); else - m_frame->GetCanvas()->GetView()->SetVisible( &m_viewSnapPoint, true ); + m_toolMgr->GetView()->SetVisible( &m_viewSnapPoint, true ); m_snapItem = nearest; return nearest->pos; @@ -359,20 +362,20 @@ VECTOR2I GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& aLaye if( snapLine && m_skipPoint != VECTOR2I( m_viewSnapLine.GetPosition() ) ) { m_viewSnapLine.SetEndPosition( nearestGrid ); - m_frame->GetCanvas()->GetView()->SetVisible( &m_viewSnapPoint, false ); + m_toolMgr->GetView()->SetVisible( &m_viewSnapPoint, false ); - if( m_frame->GetCanvas()->GetView()->IsVisible( &m_viewSnapLine ) ) - m_frame->GetCanvas()->GetView()->Update( &m_viewSnapLine, KIGFX::GEOMETRY ); + if( m_toolMgr->GetView()->IsVisible( &m_viewSnapLine ) ) + m_toolMgr->GetView()->Update( &m_viewSnapLine, KIGFX::GEOMETRY ); else - m_frame->GetCanvas()->GetView()->SetVisible( &m_viewSnapLine, true ); + m_toolMgr->GetView()->SetVisible( &m_viewSnapLine, true ); return nearestGrid; } } m_snapItem = nullptr; - m_frame->GetCanvas()->GetView()->SetVisible( &m_viewSnapPoint, false ); - m_frame->GetCanvas()->GetView()->SetVisible( &m_viewSnapLine, false ); + m_toolMgr->GetView()->SetVisible( &m_viewSnapPoint, false ); + m_toolMgr->GetView()->SetVisible( &m_viewSnapLine, false ); return nearestGrid; } @@ -389,9 +392,10 @@ BOARD_ITEM* GRID_HELPER::GetSnapped( void ) const void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom ) { VECTOR2I origin; - auto view = m_frame->GetCanvas()->GetView(); - auto activeLayers = view->GetPainter()->GetSettings()->GetActiveLayers(); - bool isHighContrast = view->GetPainter()->GetSettings()->GetHighContrast(); + KIGFX::VIEW* view = m_toolMgr->GetView(); + RENDER_SETTINGS* settings = view->GetPainter()->GetSettings(); + const std::set& activeLayers = settings->GetActiveLayers(); + bool isHighContrast = settings->GetHighContrast(); switch( aItem->Type() ) { @@ -399,7 +403,7 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bo { MODULE* mod = static_cast( aItem ); - for( auto pad : mod->Pads() ) + for( D_PAD* pad : mod->Pads() ) { // Getting pads from the module requires re-checking that the pad is shown if( ( aFrom || diff --git a/pcbnew/tools/grid_helper.h b/pcbnew/tools/grid_helper.h index 451a519108..697082cbcb 100644 --- a/pcbnew/tools/grid_helper.h +++ b/pcbnew/tools/grid_helper.h @@ -150,6 +150,7 @@ private: } PCB_BASE_FRAME* m_frame; + TOOL_MANAGER* m_toolMgr; OPT m_auxAxis; bool m_enableSnap; ///< If true, allow snapping to other items on the layers diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 7ffb43fb44..f4d604e3f8 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -42,13 +42,11 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include #include @@ -121,6 +119,7 @@ template void Flip( T& aValue ) aValue = !aValue; } + int PCBNEW_CONTROL::TrackDisplayMode( const TOOL_EVENT& aEvent ) { auto opts = displayOptions(); @@ -368,16 +367,14 @@ int PCBNEW_CONTROL::LayerAlphaDec( const TOOL_EVENT& aEvent ) // Grid control int PCBNEW_CONTROL::GridFast1( const TOOL_EVENT& aEvent ) { - m_frame->SetFastGrid1(); - updateGrid(); + m_toolMgr->RunAction( "common.Control.gridPreset", true, m_frame->Settings().m_FastGrid1 ); return 0; } int PCBNEW_CONTROL::GridFast2( const TOOL_EVENT& aEvent ) { - m_frame->SetFastGrid2(); - updateGrid(); + m_toolMgr->RunAction( "common.Control.gridPreset", true, m_frame->Settings().m_FastGrid2 ); return 0; } @@ -961,14 +958,6 @@ int PCBNEW_CONTROL::Redo( const TOOL_EVENT& aEvent ) } -void PCBNEW_CONTROL::updateGrid() -{ - BASE_SCREEN* screen = m_frame->GetScreen(); - getView()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGridSize() ) ); - getView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); -} - - int PCBNEW_CONTROL::UpdateMessagePanel( const TOOL_EVENT& aEvent ) { SELECTION_TOOL* selTool = m_toolMgr->GetTool(); diff --git a/pcbnew/tools/pcbnew_control.h b/pcbnew/tools/pcbnew_control.h index c998bcba0e..03e6b5fd99 100644 --- a/pcbnew/tools/pcbnew_control.h +++ b/pcbnew/tools/pcbnew_control.h @@ -112,9 +112,6 @@ private: std::unique_ptr m_gridOrigin; BOARD_ITEM* m_pickerItem; - - ///> Applies the legacy canvas grid settings for GAL. - void updateGrid(); }; #endif diff --git a/qa/qa_utils/pcb_test_frame.cpp b/qa/qa_utils/pcb_test_frame.cpp index 385585f11f..24ce295d29 100644 --- a/qa/qa_utils/pcb_test_frame.cpp +++ b/qa/qa_utils/pcb_test_frame.cpp @@ -128,7 +128,7 @@ void PCB_TEST_FRAME::SetBoard( BOARD* b ) m_galPanel->DisplayBoard( m_board.get() ); #ifdef USE_TOOL_MANAGER m_toolManager->SetEnvironment( m_board.get(), m_galPanel->GetView(), - m_galPanel->GetViewControls(), nullptr ); + m_galPanel->GetViewControls(), nullptr, nullptr ); m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD ); #endif @@ -204,7 +204,7 @@ PCB_TEST_FRAME::PCB_TEST_FRAME( wxFrame* frame, const wxString& title, const wxP #ifdef USE_TOOL_MANAGER m_toolManager = std::make_unique( ); m_toolManager->SetEnvironment( m_board.get(), m_galPanel->GetView(), - m_galPanel->GetViewControls(), nullptr ); + m_galPanel->GetViewControls(), nullptr, nullptr ); m_pcbActions = std::make_unique( ); m_toolDispatcher = std::make_unique( m_toolManager.get(), m_pcbActions.get() );