From fc4bc10d2779f1510bd8f7796332f50a7c96927e Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 25 Oct 2023 13:59:12 +0100 Subject: [PATCH] Separate out axes definitions between ModEdit and PCBNew. Fixes https://gitlab.com/kicad/code/kicad/-/issues/5711 --- common/dialogs/panel_grid_settings.cpp | 4 +- common/eda_base_frame.cpp | 3 +- include/footprint_editor_settings.h | 2 + include/frame_type.h | 1 + .../dialogs/panel_pcbnew_display_origin.cpp | 89 +++++++++++++------ pcbnew/dialogs/panel_pcbnew_display_origin.h | 9 +- pcbnew/footprint_editor_settings.cpp | 8 ++ pcbnew/pcb_origin_transforms.cpp | 13 ++- pcbnew/pcbnew.cpp | 17 +++- pcbnew/tools/pcb_viewer_tools.cpp | 27 ++++-- 10 files changed, 131 insertions(+), 42 deletions(-) diff --git a/common/dialogs/panel_grid_settings.cpp b/common/dialogs/panel_grid_settings.cpp index 24ede1d01c..d4da0b298b 100644 --- a/common/dialogs/panel_grid_settings.cpp +++ b/common/dialogs/panel_grid_settings.cpp @@ -41,7 +41,9 @@ PANEL_GRID_SETTINGS::PANEL_GRID_SETTINGS( wxWindow* aParent, UNITS_PROVIDER* aUn wxWindow* aEventSource, APP_SETTINGS_BASE* aCfg, FRAME_T aFrameType ) : PANEL_GRID_SETTINGS_BASE( aParent ), - m_unitsProvider( aUnitsProvider ), m_cfg( aCfg ), m_frameType( aFrameType ), + m_unitsProvider( aUnitsProvider ), + m_cfg( aCfg ), + m_frameType( aFrameType ), m_eventSource( aEventSource ) { RebuildGridSizes(); diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index 37212b08d2..459ca39a9e 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -1140,6 +1140,7 @@ if( ADVANCED_CFG::GetCfg().m_EnableGit && false ) book->AddPage( new wxPanel( book ), _( "Footprint Editor" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_FP_DISPLAY_OPTIONS ), _( "Display Options" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_FP_GRIDS ), _( "Grids" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_FP_ORIGINS_AXES ), _( "Origins & Axes" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_FP_EDIT_OPTIONS ), _( "Editing Options" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_FP_COLORS ), _( "Colors" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_FP_DEFAULT_VALUES ), _( "Default Values" ) ); @@ -1150,10 +1151,10 @@ if( ADVANCED_CFG::GetCfg().m_EnableGit && false ) book->AddPage( new wxPanel( book ), _( "PCB Editor" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_DISPLAY_OPTS ), _( "Display Options" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_GRIDS ), _( "Grids" ) ); + book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_ORIGINS_AXES ), _( "Origins & Axes" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_EDIT_OPTIONS ), _( "Editing Options" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_COLORS ), _( "Colors" ) ); book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_ACTION_PLUGINS ), _( "Action Plugins" ) ); - book->AddLazySubPage( LAZY_CTOR( PANEL_PCB_ORIGINS_AXES ), _( "Origins & Axes" ) ); if( GetFrameType() == FRAME_PCB_DISPLAY3D ) expand.push_back( (int) book->GetPageCount() ); diff --git a/include/footprint_editor_settings.h b/include/footprint_editor_settings.h index cb626374ce..4bf17965b4 100644 --- a/include/footprint_editor_settings.h +++ b/include/footprint_editor_settings.h @@ -69,6 +69,8 @@ public: USER_GRID m_UserGrid; bool m_PolarCoords; + bool m_DisplayInvertXAxis; + bool m_DisplayInvertYAxis; EDA_ANGLE m_RotationAngle; diff --git a/include/frame_type.h b/include/frame_type.h index 9970d58da6..803bd89e0f 100644 --- a/include/frame_type.h +++ b/include/frame_type.h @@ -86,6 +86,7 @@ enum FRAME_T PANEL_FP_EDIT_OPTIONS, PANEL_FP_COLORS, PANEL_FP_DEFAULT_VALUES, + PANEL_FP_ORIGINS_AXES, PANEL_PCB_DISPLAY_OPTS, PANEL_PCB_GRIDS, diff --git a/pcbnew/dialogs/panel_pcbnew_display_origin.cpp b/pcbnew/dialogs/panel_pcbnew_display_origin.cpp index 3c5c177ce4..6d68be4653 100644 --- a/pcbnew/dialogs/panel_pcbnew_display_origin.cpp +++ b/pcbnew/dialogs/panel_pcbnew_display_origin.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 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 @@ -25,37 +25,52 @@ #include #include #include +#include #include -PANEL_PCBNEW_DISPLAY_ORIGIN::PANEL_PCBNEW_DISPLAY_ORIGIN( wxWindow* aParent ) : - PANEL_PCBNEW_DISPLAY_ORIGIN_BASE( aParent ) +PANEL_PCBNEW_DISPLAY_ORIGIN::PANEL_PCBNEW_DISPLAY_ORIGIN( wxWindow* aParent, + APP_SETTINGS_BASE* aCfg, + FRAME_T aFrameType ) : + PANEL_PCBNEW_DISPLAY_ORIGIN_BASE( aParent ), + m_cfg( aCfg ), + m_frameType( aFrameType ) { + m_DisplayOrigin->Show( m_frameType == FRAME_PCB_EDITOR ); } -void PANEL_PCBNEW_DISPLAY_ORIGIN::loadPCBSettings( PCBNEW_SETTINGS* aCfg ) +void PANEL_PCBNEW_DISPLAY_ORIGIN::loadSettings( APP_SETTINGS_BASE* aCfg ) { - int origin = 0; + if( m_frameType == FRAME_FOOTPRINT_EDITOR ) + { + FOOTPRINT_EDITOR_SETTINGS* cfg = static_cast( aCfg ); - switch( aCfg->m_Display.m_DisplayOrigin ) + m_XAxisDirection->SetSelection( cfg->m_DisplayInvertXAxis ? 1 : 0 ); + m_YAxisDirection->SetSelection( cfg->m_DisplayInvertYAxis ? 0 : 1 ); + } + else { - case PCB_DISPLAY_ORIGIN::PCB_ORIGIN_PAGE: origin = 0; break; - case PCB_DISPLAY_ORIGIN::PCB_ORIGIN_AUX: origin = 1; break; - case PCB_DISPLAY_ORIGIN::PCB_ORIGIN_GRID: origin = 2; break; + PCBNEW_SETTINGS* cfg = static_cast( aCfg ); + int origin = 0; + + switch( cfg->m_Display.m_DisplayOrigin ) + { + case PCB_DISPLAY_ORIGIN::PCB_ORIGIN_PAGE: origin = 0; break; + case PCB_DISPLAY_ORIGIN::PCB_ORIGIN_AUX: origin = 1; break; + case PCB_DISPLAY_ORIGIN::PCB_ORIGIN_GRID: origin = 2; break; + } + + m_DisplayOrigin->SetSelection( origin ); + m_XAxisDirection->SetSelection( cfg->m_Display.m_DisplayInvertXAxis ? 1 : 0 ); + m_YAxisDirection->SetSelection( cfg->m_Display.m_DisplayInvertYAxis ? 0 : 1 ); } - - m_DisplayOrigin->SetSelection( origin ); - m_XAxisDirection->SetSelection( aCfg->m_Display.m_DisplayInvertXAxis ? 1 : 0 ); - m_YAxisDirection->SetSelection( aCfg->m_Display.m_DisplayInvertYAxis ? 0 : 1 ); } bool PANEL_PCBNEW_DISPLAY_ORIGIN::TransferDataToWindow() { - PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); - - loadPCBSettings( cfg ); + loadSettings( m_cfg ); return true; } @@ -63,17 +78,27 @@ bool PANEL_PCBNEW_DISPLAY_ORIGIN::TransferDataToWindow() bool PANEL_PCBNEW_DISPLAY_ORIGIN::TransferDataFromWindow() { - PCBNEW_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings(); - - switch( m_DisplayOrigin->GetSelection() ) + if( m_frameType == FRAME_FOOTPRINT_EDITOR ) { - case 0: cfg->m_Display.m_DisplayOrigin = PCB_DISPLAY_ORIGIN::PCB_ORIGIN_PAGE; break; - case 1: cfg->m_Display.m_DisplayOrigin = PCB_DISPLAY_ORIGIN::PCB_ORIGIN_AUX; break; - case 2: cfg->m_Display.m_DisplayOrigin = PCB_DISPLAY_ORIGIN::PCB_ORIGIN_GRID; break; + FOOTPRINT_EDITOR_SETTINGS* cfg = static_cast( m_cfg ); + + cfg->m_DisplayInvertXAxis = m_XAxisDirection->GetSelection() != 0; + cfg->m_DisplayInvertYAxis = m_YAxisDirection->GetSelection() == 0; } + else + { + PCBNEW_SETTINGS* cfg = static_cast( m_cfg ); - cfg->m_Display.m_DisplayInvertXAxis = m_XAxisDirection->GetSelection() != 0; - cfg->m_Display.m_DisplayInvertYAxis = m_YAxisDirection->GetSelection() == 0; + switch( m_DisplayOrigin->GetSelection() ) + { + case 0: cfg->m_Display.m_DisplayOrigin = PCB_DISPLAY_ORIGIN::PCB_ORIGIN_PAGE; break; + case 1: cfg->m_Display.m_DisplayOrigin = PCB_DISPLAY_ORIGIN::PCB_ORIGIN_AUX; break; + case 2: cfg->m_Display.m_DisplayOrigin = PCB_DISPLAY_ORIGIN::PCB_ORIGIN_GRID; break; + } + + cfg->m_Display.m_DisplayInvertXAxis = m_XAxisDirection->GetSelection() != 0; + cfg->m_Display.m_DisplayInvertYAxis = m_YAxisDirection->GetSelection() == 0; + } return true; } @@ -81,10 +106,20 @@ bool PANEL_PCBNEW_DISPLAY_ORIGIN::TransferDataFromWindow() void PANEL_PCBNEW_DISPLAY_ORIGIN::ResetPanel() { - PCBNEW_SETTINGS cfg; - cfg.Load(); // Loading without a file will init to defaults + if( m_frameType == FRAME_FOOTPRINT_EDITOR ) + { + FOOTPRINT_EDITOR_SETTINGS cfg; + cfg.Load(); // Loading without a file will init to defaults - loadPCBSettings( &cfg ); + loadSettings( &cfg ); + } + else + { + PCBNEW_SETTINGS cfg; + cfg.Load(); // Loading without a file will init to defaults + + loadSettings( &cfg ); + } } diff --git a/pcbnew/dialogs/panel_pcbnew_display_origin.h b/pcbnew/dialogs/panel_pcbnew_display_origin.h index 1c2e57ce44..ddf75a8b8e 100644 --- a/pcbnew/dialogs/panel_pcbnew_display_origin.h +++ b/pcbnew/dialogs/panel_pcbnew_display_origin.h @@ -25,13 +25,14 @@ #ifndef PANEL_PCBNEW_DISPLAY_ORIGIN_H #define PANEL_PCBNEW_DISPLAY_ORIGIN_H 1 +#include #include "panel_pcbnew_display_origin_base.h" class PANEL_PCBNEW_DISPLAY_ORIGIN : public PANEL_PCBNEW_DISPLAY_ORIGIN_BASE { public: - PANEL_PCBNEW_DISPLAY_ORIGIN( wxWindow* aParent ); + PANEL_PCBNEW_DISPLAY_ORIGIN( wxWindow* aParent, APP_SETTINGS_BASE* aCfg, FRAME_T aFrameType ); bool TransferDataToWindow() override; bool TransferDataFromWindow() override; @@ -39,7 +40,11 @@ public: void ResetPanel() override; private: - void loadPCBSettings( PCBNEW_SETTINGS* aCfg ); + void loadSettings( APP_SETTINGS_BASE* aCfg ); + +private: + APP_SETTINGS_BASE* m_cfg; + FRAME_T m_frameType; }; diff --git a/pcbnew/footprint_editor_settings.cpp b/pcbnew/footprint_editor_settings.cpp index e097d84b41..02477bce80 100644 --- a/pcbnew/footprint_editor_settings.cpp +++ b/pcbnew/footprint_editor_settings.cpp @@ -43,6 +43,8 @@ FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS() : m_Display(), m_UserGrid(), m_PolarCoords( false ), + m_DisplayInvertXAxis( false ), + m_DisplayInvertYAxis( false ), m_RotationAngle( ANGLE_90 ), m_Use45Limit( true ), m_ArcEditMode( ARC_EDIT_MODE::KEEP_CENTER_ADJUST_ANGLE_RADIUS ), @@ -102,6 +104,12 @@ FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS() : m_params.emplace_back( new PARAM( "editing.polar_coords", &m_PolarCoords, false ) ); + m_params.emplace_back( new PARAM( "origin_invert_x_axis", + &m_DisplayInvertXAxis, false ) ); + + m_params.emplace_back( new PARAM( "origin_invert_y_axis", + &m_DisplayInvertYAxis, false ) ); + m_params.emplace_back( new PARAM_LAMBDA( "editing.rotation_angle", [this] () -> int { diff --git a/pcbnew/pcb_origin_transforms.cpp b/pcbnew/pcb_origin_transforms.cpp index 3407df186a..34b1c6acf1 100644 --- a/pcbnew/pcb_origin_transforms.cpp +++ b/pcbnew/pcb_origin_transforms.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2019-2020 Reece R. Pollack - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2023 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 @@ -25,6 +25,7 @@ #include // for wxASSERT #include #include +#include #include using COORD_TYPE = ORIGIN_TRANSFORMS::COORD_TYPES_T; @@ -119,10 +120,16 @@ int PCB_ORIGIN_TRANSFORMS::getUserYOrigin() const bool PCB_ORIGIN_TRANSFORMS::invertXAxis() const { - return m_pcbBaseFrame.GetPcbNewSettings()->m_Display.m_DisplayInvertXAxis; + if( m_pcbBaseFrame.GetFrameType() == FRAME_PCB_EDITOR ) + return m_pcbBaseFrame.GetPcbNewSettings()->m_Display.m_DisplayInvertXAxis; + else + return m_pcbBaseFrame.GetFootprintEditorSettings()->m_DisplayInvertXAxis; } bool PCB_ORIGIN_TRANSFORMS::invertYAxis() const { - return m_pcbBaseFrame.GetPcbNewSettings()->m_Display.m_DisplayInvertYAxis; + if( m_pcbBaseFrame.GetFrameType() == FRAME_PCB_EDITOR ) + return m_pcbBaseFrame.GetPcbNewSettings()->m_Display.m_DisplayInvertYAxis; + else + return m_pcbBaseFrame.GetFootprintEditorSettings()->m_DisplayInvertYAxis; } diff --git a/pcbnew/pcbnew.cpp b/pcbnew/pcbnew.cpp index 29dd43daaf..7463dc0aaa 100644 --- a/pcbnew/pcbnew.cpp +++ b/pcbnew/pcbnew.cpp @@ -210,11 +210,19 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER case PANEL_PCB_DISPLAY_OPTS: { SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); - APP_SETTINGS_BASE* cfg = mgr.GetAppSettings(); + APP_SETTINGS_BASE* cfg = mgr.GetAppSettings(); return new PANEL_PCB_DISPLAY_OPTIONS( aParent, cfg ); } + case PANEL_FP_ORIGINS_AXES: + { + SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); + APP_SETTINGS_BASE* cfg = mgr.GetAppSettings(); + + return new PANEL_PCBNEW_DISPLAY_ORIGIN( aParent, cfg, FRAME_FOOTPRINT_EDITOR ); + } + case PANEL_PCB_GRIDS: { SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); @@ -264,7 +272,12 @@ static struct IFACE : public KIFACE_BASE, public UNITS_PROVIDER return new PANEL_PCBNEW_ACTION_PLUGINS( aParent ); case PANEL_PCB_ORIGINS_AXES: - return new PANEL_PCBNEW_DISPLAY_ORIGIN( aParent ); + { + SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); + APP_SETTINGS_BASE* cfg = mgr.GetAppSettings(); + + return new PANEL_PCBNEW_DISPLAY_ORIGIN( aParent, cfg, FRAME_PCB_EDITOR ); + } case PANEL_3DV_DISPLAY_OPTIONS: return new PANEL_3D_DISPLAY_OPTIONS( aParent ); diff --git a/pcbnew/tools/pcb_viewer_tools.cpp b/pcbnew/tools/pcb_viewer_tools.cpp index b8adb44bfa..72bbd9a3b7 100644 --- a/pcbnew/tools/pcb_viewer_tools.cpp +++ b/pcbnew/tools/pcb_viewer_tools.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2023 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 @@ -199,13 +199,20 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent ) frame()->PushTool( aEvent ); + bool invertXAxis = displayOptions().m_DisplayInvertXAxis; + bool invertYAxis = displayOptions().m_DisplayInvertYAxis; + + if( IsFootprintFrame() ) + { + invertXAxis = frame()->GetFootprintEditorSettings()->m_DisplayInvertXAxis; + invertYAxis = frame()->GetFootprintEditorSettings()->m_DisplayInvertYAxis; + } + TWO_POINT_GEOMETRY_MANAGER twoPtMgr; PCB_GRID_HELPER grid( m_toolMgr, frame()->GetMagneticItemsSettings() ); bool originSet = false; EDA_UNITS units = frame()->GetUserUnits(); - KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, pcbIUScale, units, - displayOptions().m_DisplayInvertXAxis, - displayOptions().m_DisplayInvertYAxis ); + KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, pcbIUScale, units, invertXAxis, invertYAxis ); view.Add( &ruler ); view.SetVisible( &ruler, false ); @@ -323,8 +330,16 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent ) } else if( evt->IsAction( &ACTIONS::updatePreferences ) ) { - ruler.UpdateDir( displayOptions().m_DisplayInvertXAxis, - displayOptions().m_DisplayInvertYAxis ); + invertXAxis = displayOptions().m_DisplayInvertXAxis; + invertYAxis = displayOptions().m_DisplayInvertYAxis; + + if( IsFootprintFrame() ) + { + invertXAxis = frame()->GetFootprintEditorSettings()->m_DisplayInvertXAxis; + invertYAxis = frame()->GetFootprintEditorSettings()->m_DisplayInvertYAxis; + } + + ruler.UpdateDir( invertXAxis, invertYAxis ); view.Update( &ruler, KIGFX::GEOMETRY ); canvas()->Refresh();