diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 12b360faab..b2d70f8a15 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -490,6 +490,11 @@ set( PCB_COMMON_SRCS ${CMAKE_SOURCE_DIR}/pcbnew/ratsnest_viewitem.cpp ${CMAKE_SOURCE_DIR}/pcbnew/sel_layer.cpp ${CMAKE_SOURCE_DIR}/pcbnew/zone_settings.cpp + + ${CMAKE_SOURCE_DIR}/pcbnew/tools/grid_helper.cpp + ${CMAKE_SOURCE_DIR}/pcbnew/tools/pcb_actions.cpp + ${CMAKE_SOURCE_DIR}/pcbnew/tools/pcb_viewer_tools.cpp + widgets/net_selector.cpp ) diff --git a/cvpcb/CMakeLists.txt b/cvpcb/CMakeLists.txt index 6755cdfad7..b4142f255b 100644 --- a/cvpcb/CMakeLists.txt +++ b/cvpcb/CMakeLists.txt @@ -28,7 +28,6 @@ set( CVPCB_DIALOGS set( CVPCB_SRCS ${CMAKE_SOURCE_DIR}/common/base_units.cpp - ${CMAKE_SOURCE_DIR}/pcbnew/tools/grid_helper.cpp ${CMAKE_SOURCE_DIR}/pcbnew/board_stackup_manager/stackup_predefined_prms.cpp auto_associate.cpp cfg.cpp @@ -45,7 +44,6 @@ set( CVPCB_SRCS tools/cvpcb_actions.cpp tools/cvpcb_association_tool.cpp tools/cvpcb_control.cpp - tools/cvpcb_fpviewer_control.cpp tools/cvpcb_fpviewer_selection_tool.cpp ) diff --git a/cvpcb/cvpcb_settings.cpp b/cvpcb/cvpcb_settings.cpp index 864914d29e..5dfa4f6f93 100644 --- a/cvpcb/cvpcb_settings.cpp +++ b/cvpcb/cvpcb_settings.cpp @@ -35,6 +35,10 @@ CVPCB_SETTINGS::CVPCB_SETTINGS() : // Make Coverity happy: m_FilterFootprint = 0; + m_FootprintViewerMagneticSettings.pads = MAGNETIC_OPTIONS::NO_EFFECT; + m_FootprintViewerMagneticSettings.tracks = MAGNETIC_OPTIONS::NO_EFFECT; + m_FootprintViewerMagneticSettings.graphics = false; + // Init settings: m_params.emplace_back( new PARAM( "filter_footprint", &m_FilterFootprint, 0 ) ); @@ -52,6 +56,13 @@ CVPCB_SETTINGS::CVPCB_SETTINGS() : m_params.emplace_back( new PARAM( "footprint_viewer.graphic_items_fill", &m_FootprintViewerDisplayOptions.m_DisplayDrawItemsFill, true ) ); + + m_params.emplace_back( new PARAM( "footprint_viewer.magnetic_graphics", + &m_FootprintViewerMagneticSettings.graphics, false ) ); + + m_params.emplace_back( new PARAM( "footprint_viewer.magnetic_pads", + reinterpret_cast( &m_FootprintViewerMagneticSettings.pads ), + static_cast( MAGNETIC_OPTIONS::NO_EFFECT ) ) ); } diff --git a/cvpcb/cvpcb_settings.h b/cvpcb/cvpcb_settings.h index 63a6dba309..fb689f2967 100644 --- a/cvpcb/cvpcb_settings.h +++ b/cvpcb/cvpcb_settings.h @@ -25,6 +25,7 @@ #define _CVPCB_SETTINGS_H #include +#include #include class CVPCB_SETTINGS : public APP_SETTINGS_BASE @@ -40,6 +41,8 @@ public: PCB_DISPLAY_OPTIONS m_FootprintViewerDisplayOptions; + MAGNETIC_SETTINGS m_FootprintViewerMagneticSettings; + int m_FilterFootprint; protected: diff --git a/cvpcb/dialogs/dialog_display_options.cpp b/cvpcb/dialogs/dialog_display_options.cpp index e1b004b956..ffd9fd24fd 100644 --- a/cvpcb/dialogs/dialog_display_options.cpp +++ b/cvpcb/dialogs/dialog_display_options.cpp @@ -57,11 +57,13 @@ void DIALOG_FOOTPRINTS_DISPLAY_OPTIONS::initDialog() auto& displ_opts = m_Parent->GetDisplayOptions(); - m_EdgesDisplayOption->SetValue( not displ_opts.m_DisplayModEdgeFill ); - m_TextDisplayOption->SetValue( not displ_opts.m_DisplayModTextFill ); - m_ShowPadSketch->SetValue( not displ_opts.m_DisplayPadFill ); m_ShowPadNum->SetValue( displ_opts.m_DisplayPadNum ); + MAGNETIC_SETTINGS* magSettings = m_Parent->GetMagneticItemsSettings(); + + m_MagneticPads->SetValue( magSettings->pads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS ); + m_MagneticGraphics->SetValue( magSettings->graphics ); + m_autoZoomOption->SetValue( m_Parent->GetAutoZoom() ); } @@ -70,13 +72,17 @@ void DIALOG_FOOTPRINTS_DISPLAY_OPTIONS::UpdateObjectSettings( void ) { PCB_DISPLAY_OPTIONS displ_opts = m_Parent->GetDisplayOptions(); - displ_opts.m_DisplayModEdgeFill = not m_EdgesDisplayOption->GetValue(); - displ_opts.m_DisplayModTextFill = not m_TextDisplayOption->GetValue(); displ_opts.m_DisplayPadNum = m_ShowPadNum->GetValue(); - displ_opts.m_DisplayPadFill = not m_ShowPadSketch->GetValue(); + m_Parent->ApplyDisplaySettingsToGAL(); m_Parent->SetDisplayOptions( displ_opts ); + MAGNETIC_SETTINGS* magSettings = m_Parent->GetMagneticItemsSettings(); + + magSettings->pads = m_MagneticPads->GetValue() ? MAGNETIC_OPTIONS::CAPTURE_ALWAYS + : MAGNETIC_OPTIONS::NO_EFFECT; + magSettings->graphics = m_MagneticGraphics->GetValue(); + m_Parent->SetAutoZoom( m_autoZoomOption->GetValue() ); } diff --git a/cvpcb/dialogs/dialog_display_options_base.cpp b/cvpcb/dialogs/dialog_display_options_base.cpp index df4ace01c8..dcb053e243 100644 --- a/cvpcb/dialogs/dialog_display_options_base.cpp +++ b/cvpcb/dialogs/dialog_display_options_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,50 +12,56 @@ DIALOG_FOOTPRINTS_DISPLAY_OPTIONS_BASE::DIALOG_FOOTPRINTS_DISPLAY_OPTIONS_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 ); - + + wxBoxSizer* bSizerLeft; + bSizerLeft = new wxBoxSizer( wxVERTICAL ); + + wxStaticBoxSizer* sbMagneticPoints; + sbMagneticPoints = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Magnetic Points") ), wxVERTICAL ); + + m_MagneticPads = new wxCheckBox( sbMagneticPoints->GetStaticBox(), wxID_ANY, _("Snap to pads"), wxDefaultPosition, wxDefaultSize, 0 ); + sbMagneticPoints->Add( m_MagneticPads, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 ); + + m_MagneticGraphics = new wxCheckBox( sbMagneticPoints->GetStaticBox(), wxID_ANY, _("Snap to graphics"), wxDefaultPosition, wxDefaultSize, 0 ); + sbMagneticPoints->Add( m_MagneticGraphics, 0, wxBOTTOM|wxLEFT|wxRIGHT, 5 ); + + + bSizerLeft->Add( sbMagneticPoints, 1, wxALL|wxEXPAND, 5 ); + wxStaticBoxSizer* sbSizerDrawMode; sbSizerDrawMode = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Drawing Options") ), wxVERTICAL ); - - m_EdgesDisplayOption = new wxCheckBox( sbSizerDrawMode->GetStaticBox(), wxID_ANY, _("Graphic items sketch mode"), wxDefaultPosition, wxDefaultSize, 0 ); - sbSizerDrawMode->Add( m_EdgesDisplayOption, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - - m_TextDisplayOption = new wxCheckBox( sbSizerDrawMode->GetStaticBox(), wxID_ANY, _("Texts sketch mode"), wxDefaultPosition, wxDefaultSize, 0 ); - sbSizerDrawMode->Add( m_TextDisplayOption, 0, wxBOTTOM|wxLEFT|wxRIGHT, 5 ); - - m_ShowPadSketch = new wxCheckBox( sbSizerDrawMode->GetStaticBox(), ID_PADFILL_OPT, _("Pad sketch mode"), wxDefaultPosition, wxDefaultSize, 0 ); - sbSizerDrawMode->Add( m_ShowPadSketch, 0, wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT, 5 ); - - - sbSizerDrawMode->Add( 0, 0, 1, wxEXPAND|wxTOP|wxBOTTOM, 5 ); - + m_ShowPadNum = new wxCheckBox( sbSizerDrawMode->GetStaticBox(), wxID_ANY, _("Show pad &numbers"), wxDefaultPosition, wxDefaultSize, 0 ); sbSizerDrawMode->Add( m_ShowPadNum, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - - - bUpperSizer->Add( sbSizerDrawMode, 1, wxEXPAND|wxALL, 5 ); - + + + bSizerLeft->Add( sbSizerDrawMode, 1, wxEXPAND|wxALL, 5 ); + + + bUpperSizer->Add( bSizerLeft, 1, wxEXPAND, 5 ); + wxStaticBoxSizer* sbSizerViewOpt; sbSizerViewOpt = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Auto-zoom") ), wxVERTICAL ); - + m_autoZoomOption = new wxCheckBox( sbSizerViewOpt->GetStaticBox(), wxID_ANY, _("Zoom to fit when changing footprint"), wxDefaultPosition, wxDefaultSize, 0 ); - m_autoZoomOption->SetValue(true); + m_autoZoomOption->SetValue(true); sbSizerViewOpt->Add( m_autoZoomOption, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - - + + bUpperSizer->Add( sbSizerViewOpt, 1, wxALL|wxEXPAND, 5 ); - - + + bSizerMain->Add( bUpperSizer, 1, wxEXPAND|wxALL, 5 ); - + m_staticline1 = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); bSizerMain->Add( m_staticline1, 0, wxEXPAND|wxRIGHT|wxLEFT, 5 ); - + m_sdbSizer = new wxStdDialogButtonSizer(); m_sdbSizerOK = new wxButton( this, wxID_OK ); m_sdbSizer->AddButton( m_sdbSizerOK ); @@ -64,14 +70,14 @@ DIALOG_FOOTPRINTS_DISPLAY_OPTIONS_BASE::DIALOG_FOOTPRINTS_DISPLAY_OPTIONS_BASE( m_sdbSizerCancel = new wxButton( this, wxID_CANCEL ); m_sdbSizer->AddButton( m_sdbSizerCancel ); m_sdbSizer->Realize(); - + bSizerMain->Add( m_sdbSizer, 0, wxEXPAND|wxALL, 5 ); - - + + this->SetSizer( bSizerMain ); this->Layout(); bSizerMain->Fit( this ); - + // Connect Events m_sdbSizerApply->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINTS_DISPLAY_OPTIONS_BASE::OnApplyClick ), NULL, this ); } @@ -80,5 +86,5 @@ DIALOG_FOOTPRINTS_DISPLAY_OPTIONS_BASE::~DIALOG_FOOTPRINTS_DISPLAY_OPTIONS_BASE( { // Disconnect Events m_sdbSizerApply->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FOOTPRINTS_DISPLAY_OPTIONS_BASE::OnApplyClick ), NULL, this ); - + } diff --git a/cvpcb/dialogs/dialog_display_options_base.fbp b/cvpcb/dialogs/dialog_display_options_base.fbp index 0f503c2b7d..34f85b0080 100644 --- a/cvpcb/dialogs/dialog_display_options_base.fbp +++ b/cvpcb/dialogs/dialog_display_options_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -14,6 +14,7 @@ dialog_display_options_base 1000 none + 1 dialog_display_options_base @@ -52,42 +53,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bSizerMain @@ -104,377 +69,231 @@ none 5 - wxEXPAND|wxALL + wxEXPAND 1 - - wxID_ANY - Drawing Options + - sbSizerDrawMode + bSizerLeft wxVERTICAL - 1 none - 5 - wxBOTTOM|wxRIGHT|wxLEFT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Graphic items sketch mode - - 0 - - - 0 - - 1 - m_EdgesDisplayOption - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxBOTTOM|wxLEFT|wxRIGHT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - wxID_ANY - Texts sketch mode - - 0 - - - 0 - - 1 - m_TextDisplayOption - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 - ID_PADFILL_OPT - Pad sketch mode - - 0 - - - 0 - - 1 - m_ShowPadSketch - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 5 - wxEXPAND|wxTOP|wxBOTTOM + wxALL|wxEXPAND 1 - - 0 - protected - 0 + + wxID_ANY + Magnetic Points + + sbMagneticPoints + wxVERTICAL + 1 + none + + 5 + wxBOTTOM|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Snap to pads + + 0 + + + 0 + + 1 + m_MagneticPads + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + 5 + wxBOTTOM|wxLEFT|wxRIGHT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Snap to graphics + + 0 + + + 0 + + 1 + m_MagneticGraphics + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + 5 - wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT - 0 - - 1 - 1 - 1 - 1 - - - - - - - - 1 - 0 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 1 - - 1 - - 0 - 0 + wxEXPAND|wxALL + 1 + wxID_ANY - Show pad &numbers - - 0 - - - 0 + Drawing Options - 1 - m_ShowPadNum - 1 - - - protected - 1 - - Resizable - 1 - - - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - - - - - - - - - - - - - - - - - - - - - - - - + sbSizerDrawMode + wxVERTICAL + 1 + none + + 5 + wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Show pad &numbers + + 0 + + + 0 + + 1 + m_ShowPadNum + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + @@ -491,7 +310,6 @@ wxVERTICAL 1 none - 5 wxBOTTOM|wxRIGHT|wxLEFT @@ -554,30 +372,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -640,29 +434,6 @@ - - - - - - - - - - - - - - - - - - - - - - - @@ -682,13 +453,6 @@ m_sdbSizer protected OnApplyClick - - - - - - - diff --git a/cvpcb/dialogs/dialog_display_options_base.h b/cvpcb/dialogs/dialog_display_options_base.h index 790450ce54..9cbabf4988 100644 --- a/cvpcb/dialogs/dialog_display_options_base.h +++ b/cvpcb/dialogs/dialog_display_options_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_DISPLAY_OPTIONS_BASE_H__ -#define __DIALOG_DISPLAY_OPTIONS_BASE_H__ +#pragma once #include #include @@ -26,7 +25,6 @@ /////////////////////////////////////////////////////////////////////////// -#define ID_PADFILL_OPT 1000 /////////////////////////////////////////////////////////////////////////////// /// Class DIALOG_FOOTPRINTS_DISPLAY_OPTIONS_BASE @@ -34,11 +32,10 @@ class DIALOG_FOOTPRINTS_DISPLAY_OPTIONS_BASE : public DIALOG_SHIM { private: - + protected: - wxCheckBox* m_EdgesDisplayOption; - wxCheckBox* m_TextDisplayOption; - wxCheckBox* m_ShowPadSketch; + wxCheckBox* m_MagneticPads; + wxCheckBox* m_MagneticGraphics; wxCheckBox* m_ShowPadNum; wxCheckBox* m_autoZoomOption; wxStaticLine* m_staticline1; @@ -46,16 +43,15 @@ class DIALOG_FOOTPRINTS_DISPLAY_OPTIONS_BASE : public DIALOG_SHIM wxButton* m_sdbSizerOK; wxButton* m_sdbSizerApply; wxButton* m_sdbSizerCancel; - + // Virtual event handlers, overide them in your derived class virtual void OnApplyClick( wxCommandEvent& event ) { event.Skip(); } - - + + public: - - DIALOG_FOOTPRINTS_DISPLAY_OPTIONS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Display Options"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + + DIALOG_FOOTPRINTS_DISPLAY_OPTIONS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Display Options"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); ~DIALOG_FOOTPRINTS_DISPLAY_OPTIONS_BASE(); - + }; -#endif //__DIALOG_DISPLAY_OPTIONS_BASE_H__ diff --git a/cvpcb/display_footprints_frame.cpp b/cvpcb/display_footprints_frame.cpp index 69b63ea133..c45711456f 100644 --- a/cvpcb/display_footprints_frame.cpp +++ b/cvpcb/display_footprints_frame.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -47,7 +48,8 @@ #include #include #include -#include +#include +#include // shared tools with other pcbnew frames #include @@ -113,8 +115,11 @@ DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME( KIWAY* aKiway, wxWindow* aPa m_toolManager->RegisterTool( new COMMON_TOOLS ); m_toolManager->RegisterTool( new ZOOM_TOOL ); - m_toolManager->RegisterTool( new CVPCB_FOOTPRINT_VIEWER_CONTROL ); m_toolManager->RegisterTool( new CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL ); + m_toolManager->RegisterTool( new PCB_VIEWER_TOOLS ); + + m_toolManager->GetTool()->SetFootprintFrame( true ); + m_toolManager->InitTools(); // Run the control tool, it is supposed to be always active @@ -190,28 +195,20 @@ void DISPLAY_FOOTPRINTS_FRAME::ReCreateOptToolbar() // TODO: these can be moved to the 'proper' right vertical toolbar if and when there are // actual tools to put there. That, or I'll get around to implementing configurable // toolbars. - m_optionsToolBar->Add( ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE ); - m_optionsToolBar->Add( ACTIONS::measureTool, ACTION_TOOLBAR::TOGGLE ); + m_optionsToolBar->Add( ACTIONS::selectionTool, ACTION_TOOLBAR::TOGGLE ); + m_optionsToolBar->Add( ACTIONS::measureTool, ACTION_TOOLBAR::TOGGLE ); m_optionsToolBar->AddSeparator(); - m_optionsToolBar->Add( ACTIONS::toggleGrid, ACTION_TOOLBAR::TOGGLE ); - m_optionsToolBar->Add( ACTIONS::togglePolarCoords, ACTION_TOOLBAR::TOGGLE ); - m_optionsToolBar->Add( ACTIONS::imperialUnits, ACTION_TOOLBAR::TOGGLE ); - m_optionsToolBar->Add( ACTIONS::metricUnits, ACTION_TOOLBAR::TOGGLE ); - m_optionsToolBar->Add( ACTIONS::toggleCursorStyle, ACTION_TOOLBAR::TOGGLE ); + m_optionsToolBar->Add( ACTIONS::toggleGrid, ACTION_TOOLBAR::TOGGLE ); + m_optionsToolBar->Add( ACTIONS::togglePolarCoords, ACTION_TOOLBAR::TOGGLE ); + m_optionsToolBar->Add( ACTIONS::imperialUnits, ACTION_TOOLBAR::TOGGLE ); + m_optionsToolBar->Add( ACTIONS::metricUnits, ACTION_TOOLBAR::TOGGLE ); + m_optionsToolBar->Add( ACTIONS::toggleCursorStyle, ACTION_TOOLBAR::TOGGLE ); m_optionsToolBar->AddSeparator(); - m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_PADS_SKETCH, wxEmptyString, - KiScaledBitmap( pad_sketch_xpm, this ), - _( "Show pads in outline mode" ), wxITEM_CHECK ); - - m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_MODULE_TEXT_SKETCH, wxEmptyString, - KiScaledBitmap( text_sketch_xpm, this ), - _( "Show texts in line mode" ), wxITEM_CHECK ); - - m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_MODULE_EDGE_SKETCH, wxEmptyString, - KiScaledBitmap( show_mod_edge_xpm, this ), - _( "Show outlines in line mode" ), wxITEM_CHECK ); + m_optionsToolBar->Add( PCB_ACTIONS::padDisplayMode, ACTION_TOOLBAR::TOGGLE ); + m_optionsToolBar->Add( PCB_ACTIONS::moduleTextOutlines, ACTION_TOOLBAR::TOGGLE ); + m_optionsToolBar->Add( PCB_ACTIONS::moduleEdgeOutlines, ACTION_TOOLBAR::TOGGLE ); m_optionsToolBar->Realize(); } @@ -296,6 +293,14 @@ WINDOW_SETTINGS* DISPLAY_FOOTPRINTS_FRAME::GetWindowSettings( APP_SETTINGS_BASE* } +MAGNETIC_SETTINGS* DISPLAY_FOOTPRINTS_FRAME::GetMagneticItemsSettings() +{ + auto cfg = dynamic_cast( Kiface().KifaceSettings() ); + wxCHECK( cfg, nullptr ); + return &cfg->m_FootprintViewerMagneticSettings; +} + + void DISPLAY_FOOTPRINTS_FRAME::ApplyDisplaySettingsToGAL() { auto painter = static_cast( GetCanvas()->GetView()->GetPainter() ); @@ -449,7 +454,7 @@ void DISPLAY_FOOTPRINTS_FRAME::SyncToolbars() m_optionsToolBar->Toggle( ACTIONS::toggleGrid, IsGridVisible() ); m_optionsToolBar->Toggle( ACTIONS::selectionTool, IsCurrentTool( ACTIONS::selectionTool ) ); m_optionsToolBar->Toggle( ACTIONS::measureTool, IsCurrentTool( ACTIONS::measureTool ) ); - m_optionsToolBar->Toggle( ACTIONS::metricUnits, GetUserUnits() != EDA_UNITS::INCHES ); + m_optionsToolBar->Toggle( ACTIONS::metricUnits, GetUserUnits() != EDA_UNITS::INCHES ); m_optionsToolBar->Toggle( ACTIONS::imperialUnits, GetUserUnits() == EDA_UNITS::INCHES ); m_optionsToolBar->Refresh(); } @@ -464,3 +469,9 @@ COLOR_SETTINGS* DISPLAY_FOOTPRINTS_FRAME::GetColorSettings() else return Pgm().GetSettingsManager().GetColorSettings(); } + + +BOARD_ITEM_CONTAINER* DISPLAY_FOOTPRINTS_FRAME::GetModel() const +{ + return GetBoard()->GetFirstModule(); +} diff --git a/cvpcb/display_footprints_frame.h b/cvpcb/display_footprints_frame.h index c9be09cea9..009e57c559 100644 --- a/cvpcb/display_footprints_frame.h +++ b/cvpcb/display_footprints_frame.h @@ -29,6 +29,7 @@ #define DISPLAY_FOOTPRINTS_FRAME_H #include +#include // The name (for wxWidgets) of the footprint viewer frame #define FOOTPRINTVIEWER_FRAME_NAME wxT( "FootprintViewerFrame" ) @@ -61,6 +62,9 @@ public: */ void InitDisplay(); + ///> @copydoc PCB_BASE_FRAME::GetModel() + BOARD_ITEM_CONTAINER* GetModel() const override; + /** * update the gal canvas (view, colors ...) */ @@ -71,6 +75,8 @@ public: WINDOW_SETTINGS* GetWindowSettings( APP_SETTINGS_BASE* aCfg ) override; + MAGNETIC_SETTINGS* GetMagneticItemsSettings() override; + /// Updates the GAL with display settings changes void ApplyDisplaySettingsToGAL(); diff --git a/cvpcb/tools/cvpcb_fpviewer_control.cpp b/cvpcb/tools/cvpcb_fpviewer_control.cpp deleted file mode 100644 index f1f83b1d40..0000000000 --- a/cvpcb/tools/cvpcb_fpviewer_control.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2014-2016 CERN - * @author Maciej Suminski - * Copyright (C) 2007-2019 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 Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include -using namespace std::placeholders; - -#include -#include - - -CVPCB_FOOTPRINT_VIEWER_CONTROL::CVPCB_FOOTPRINT_VIEWER_CONTROL() : - TOOL_INTERACTIVE( "cvpcb.FootprintViewerControl" ), - m_frame( nullptr ) -{ -} - - -void CVPCB_FOOTPRINT_VIEWER_CONTROL::Reset( RESET_REASON aReason ) -{ - m_frame = getEditFrame(); -} - - -int CVPCB_FOOTPRINT_VIEWER_CONTROL::Show3DViewer( const TOOL_EVENT& aEvent ) -{ - m_frame->CreateAndShow3D_Frame(); - return 0; -} - - -void CVPCB_FOOTPRINT_VIEWER_CONTROL::setTransitions() -{ - Go( &CVPCB_FOOTPRINT_VIEWER_CONTROL::Show3DViewer, ACTIONS::show3DViewer.MakeEvent() ); -} diff --git a/cvpcb/tools/cvpcb_fpviewer_control.h b/cvpcb/tools/cvpcb_fpviewer_control.h deleted file mode 100644 index d3c764f135..0000000000 --- a/cvpcb/tools/cvpcb_fpviewer_control.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2014-2016 CERN - * @author Maciej Suminski - * Copyright (C) 2007-2019 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 Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#ifndef CVPCB_FOOTPRINT_VIEWER_CONTROL_H_ -#define CVPCB_FOOTPRINT_VIEWER_CONTROL_H_ - -#include -#include - - -/** - * CVPCB_FOOTPRINT_VIEWER_CONTROL - * - * Handles control actions for the cvpcb footprint display frame. - */ - -class CVPCB_FOOTPRINT_VIEWER_CONTROL : public TOOL_INTERACTIVE -{ -public: - CVPCB_FOOTPRINT_VIEWER_CONTROL(); - ~CVPCB_FOOTPRINT_VIEWER_CONTROL() {} - - /// @copydoc TOOL_INTERACTIVE::Reset() - void Reset( RESET_REASON aReason ) override; - - ///> Show the 3D viewer with the currently selected footprint - int Show3DViewer( const TOOL_EVENT& aEvent ); - - ///> Sets up handlers for various events. - void setTransitions() override; - -private: - ///> Pointer to the currently used edit/draw frame. - DISPLAY_FOOTPRINTS_FRAME* m_frame; -}; - -#endif diff --git a/cvpcb/tools/cvpcb_fpviewer_selection_tool.cpp b/cvpcb/tools/cvpcb_fpviewer_selection_tool.cpp index 4a1ef8f087..11c53b2a68 100644 --- a/cvpcb/tools/cvpcb_fpviewer_selection_tool.cpp +++ b/cvpcb/tools/cvpcb_fpviewer_selection_tool.cpp @@ -96,130 +96,24 @@ int CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) } -int CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) +int CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::UpdateMenu( const TOOL_EVENT& aEvent ) { - auto& view = *getView(); - auto& controls = *getViewControls(); - auto previous_settings = controls.GetSettings(); + ACTION_MENU* actionMenu = aEvent.Parameter(); + CONDITIONAL_MENU* conditionalMenu = dynamic_cast( actionMenu ); - std::string tool = aEvent.GetCommandStr().get(); - m_frame->PushTool( tool ); - Activate(); + if( conditionalMenu ) + conditionalMenu->Evaluate( m_selection ); - KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER twoPtMgr; - KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, m_frame->GetUserUnits() ); + if( actionMenu ) + actionMenu->UpdateAll(); - view.Add( &ruler ); - view.SetVisible( &ruler, false ); - - bool originSet = false; - - controls.ShowCursor( true ); - controls.SetSnapping( true ); - controls.SetAdditionalPanButtons( false, true ); - - while( TOOL_EVENT* evt = Wait() ) - { - m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW ); - const VECTOR2I cursorPos = controls.GetCursorPosition(); - - auto clearRuler = [&]() { - view.SetVisible( &ruler, false ); - controls.SetAutoPan( false ); - controls.CaptureCursor( false ); - originSet = false; - }; - - if( evt->IsCancelInteractive() ) - { - if( originSet ) - clearRuler(); - else - { - m_frame->PopTool( tool ); - break; - } - } - - else if( evt->IsActivate() ) - { - if( originSet ) - clearRuler(); - - if( evt->IsMoveTool() ) - { - // leave ourselves on the stack so we come back after the move - break; - } - else - { - m_frame->PopTool( tool ); - break; - } - } - - // click or drag starts - else if( !originSet && ( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) ) - { - if( !evt->IsDrag( BUT_LEFT ) ) - { - twoPtMgr.SetOrigin( cursorPos ); - twoPtMgr.SetEnd( cursorPos ); - } - - controls.CaptureCursor( true ); - controls.SetAutoPan( true ); - - originSet = true; - } - - else if( !originSet && evt->IsMotion() ) - { - // make sure the origin is set before a drag starts - // otherwise you can miss a step - twoPtMgr.SetOrigin( cursorPos ); - twoPtMgr.SetEnd( cursorPos ); - } - - // second click or mouse up after drag ends - else if( originSet && ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) ) - { - originSet = false; - - controls.SetAutoPan( false ); - controls.CaptureCursor( false ); - - view.SetVisible( &ruler, false ); - } - - // move or drag when origin set updates rules - else if( originSet && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) ) - { - twoPtMgr.SetAngleSnap( evt->Modifier( MD_CTRL ) ); - twoPtMgr.SetEnd( cursorPos ); - - view.SetVisible( &ruler, true ); - view.Update( &ruler, KIGFX::GEOMETRY ); - } - - else if( evt->IsClick( BUT_RIGHT ) ) - { - m_menu.ShowContextMenu( m_selection ); - } - - else - evt->SetPassEvent(); - } - - view.SetVisible( &ruler, false ); - view.Remove( &ruler ); - controls.ApplySettings( previous_settings ); return 0; } + void CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::setTransitions() { + Go( &CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::UpdateMenu, ACTIONS::updateMenu.MakeEvent() ); Go( &CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main, CVPCB_ACTIONS::selectionActivate.MakeEvent() ); - Go( &CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool, ACTIONS::measureTool.MakeEvent() ); } diff --git a/cvpcb/tools/cvpcb_fpviewer_selection_tool.h b/cvpcb/tools/cvpcb_fpviewer_selection_tool.h index fc1b3c652f..1ce9518a0b 100644 --- a/cvpcb/tools/cvpcb_fpviewer_selection_tool.h +++ b/cvpcb/tools/cvpcb_fpviewer_selection_tool.h @@ -62,8 +62,12 @@ public: void clearSelection() {} - ///> Launches a tool to measure between points - int MeasureTool( const TOOL_EVENT& aEvent ); + /** + * Update the menu to reflect the current tool states. + * + * @param aEvent is the event generated by the tool framework + */ + int UpdateMenu( const TOOL_EVENT& aEvent ); ///> Sets up handlers for various events. void setTransitions() override; diff --git a/include/footprint_editor_settings.h b/include/footprint_editor_settings.h index 472fc7141b..57648bfb6d 100644 --- a/include/footprint_editor_settings.h +++ b/include/footprint_editor_settings.h @@ -46,7 +46,8 @@ public: BOARD_DESIGN_SETTINGS m_DesignSettings; - MAGNETIC_OPTIONS m_MagneticPads; + // Only the magneticPads element is used + MAGNETIC_SETTINGS m_MagneticItems; PCB_DISPLAY_OPTIONS m_Display; diff --git a/include/id.h b/include/id.h index 4f31b15ba1..7fd4e28993 100644 --- a/include/id.h +++ b/include/id.h @@ -210,16 +210,10 @@ enum main_id ID_OFFCENTER_ZOOM_OUT, ID_ZOOM_END, - + // KiFace server for standalone operation ID_EDA_SOCKET_EVENT_SERV, ID_EDA_SOCKET_EVENT, - // Common to Pcbnew and CvPcb - ID_TB_OPTIONS_SHOW_MODULE_TEXT_SKETCH, - ID_TB_OPTIONS_SHOW_MODULE_EDGE_SKETCH, - ID_TB_OPTIONS_SHOW_GRAPHIC_SKETCH, - ID_TB_OPTIONS_SHOW_PADS_SKETCH, - ID_DIALOG_ERC, ///< eeschema ERC modeless dialog ID // IDs specifics to a sub-application (Eeschema, Kicad manager....) start here diff --git a/include/pcb_base_frame.h b/include/pcb_base_frame.h index bd5ad0812b..fa965b6bed 100644 --- a/include/pcb_base_frame.h +++ b/include/pcb_base_frame.h @@ -61,6 +61,7 @@ class PCB_PLOT_PARAMS; class FP_LIB_TABLE; class PCBNEW_SETTINGS; class FOOTPRINT_EDITOR_SETTINGS; +struct MAGNETIC_SETTINGS; wxDECLARE_EVENT( BOARD_CHANGED, wxCommandEvent ); @@ -219,6 +220,12 @@ public: return m_Pcb; } + /** + * Function GetModel() + * @return the primary data model. + */ + virtual BOARD_ITEM_CONTAINER* GetModel() const = 0; + EDA_ITEM* GetItem( const KIID& aId ) override; void FocusOnItem( BOARD_ITEM* aItem ); @@ -414,12 +421,9 @@ public: FOOTPRINT_EDITOR_SETTINGS* GetFootprintEditorSettings(); - void CommonSettingsChanged( bool aEnvVarsChanged ) override; + virtual MAGNETIC_SETTINGS* GetMagneticItemsSettings(); - void OnTogglePadDrawMode( wxCommandEvent& aEvent ); - void OnToggleGraphicDrawMode( wxCommandEvent& aEvent ); - void OnToggleEdgeDrawMode( wxCommandEvent& aEvent ); - void OnToggleTextDrawMode( wxCommandEvent& aEvent ); + void CommonSettingsChanged( bool aEnvVarsChanged ) override; // User interface update event handlers. void OnUpdateSelectZoom( wxUpdateUIEvent& aEvent ); diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 79fbb2eb9a..f3ad5a8c0f 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -317,10 +317,8 @@ set( PCBNEW_CLASS_SRCS tools/drawing_tool.cpp tools/edit_tool.cpp tools/global_edit_tool.cpp - tools/grid_helper.cpp tools/footprint_editor_tools.cpp tools/pad_tool.cpp - tools/pcb_actions.cpp tools/pcb_bright_box.cpp tools/pcb_editor_control.cpp tools/pcb_inspection_tool.cpp diff --git a/pcbnew/dialogs/panel_modedit_settings.cpp b/pcbnew/dialogs/panel_modedit_settings.cpp index 32f1b5ad5a..00eba22cca 100644 --- a/pcbnew/dialogs/panel_modedit_settings.cpp +++ b/pcbnew/dialogs/panel_modedit_settings.cpp @@ -48,7 +48,7 @@ bool PANEL_MODEDIT_SETTINGS::TransferDataToWindow() // Editing options m_Segments_45_Only_Ctrl->SetValue( m_frame->Settings().m_Use45DegreeGraphicSegments ); m_MagneticPads->SetValue( - m_frame->Settings().m_MagneticPads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS ); + m_frame->GetMagneticItemsSettings()->pads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS ); return true; } @@ -63,7 +63,7 @@ bool PANEL_MODEDIT_SETTINGS::TransferDataFromWindow() // Editing options m_frame->Settings().m_Use45DegreeGraphicSegments = m_Segments_45_Only_Ctrl->GetValue(); - m_frame->Settings().m_MagneticPads = m_MagneticPads->GetValue() ? + m_frame->GetMagneticItemsSettings()->pads = m_MagneticPads->GetValue() ? MAGNETIC_OPTIONS::CAPTURE_ALWAYS : MAGNETIC_OPTIONS::NO_EFFECT; return true; diff --git a/pcbnew/dialogs/panel_pcbnew_settings.cpp b/pcbnew/dialogs/panel_pcbnew_settings.cpp index 514503fc6e..663f9dadba 100644 --- a/pcbnew/dialogs/panel_pcbnew_settings.cpp +++ b/pcbnew/dialogs/panel_pcbnew_settings.cpp @@ -57,9 +57,9 @@ bool PANEL_PCBNEW_SETTINGS::TransferDataToWindow() m_RotationAngle->SetValue( rotationAngle ); m_Segments_45_Only_Ctrl->SetValue( general_opts.m_Use45DegreeGraphicSegments ); - m_magneticPadChoice->SetSelection( static_cast( general_opts.m_MagneticPads ) ); - m_magneticTrackChoice->SetSelection( static_cast( general_opts.m_MagneticTracks ) ); - m_magneticGraphicsChoice->SetSelection( !general_opts.m_MagneticGraphics ); + m_magneticPadChoice->SetSelection( static_cast( general_opts.m_MagneticItems.pads ) ); + m_magneticTrackChoice->SetSelection( static_cast( general_opts.m_MagneticItems.tracks ) ); + m_magneticGraphicsChoice->SetSelection( !general_opts.m_MagneticItems.graphics ); m_FlipLeftRight->SetValue( general_opts.m_FlipLeftRight ); m_Show_Page_Limits->SetValue( m_Frame->ShowPageLimits() ); @@ -76,12 +76,14 @@ bool PANEL_PCBNEW_SETTINGS::TransferDataFromWindow() m_Frame->SetRotationAngle( wxRound( 10.0 * wxAtof( m_RotationAngle->GetValue() ) ) ); - /* Updating the combobox to display the active layer. */ - m_Frame->Settings().m_Use45DegreeGraphicSegments = m_Segments_45_Only_Ctrl->GetValue(); - m_Frame->Settings().m_MagneticPads = (MAGNETIC_OPTIONS) m_magneticPadChoice->GetSelection(); - m_Frame->Settings().m_MagneticTracks = (MAGNETIC_OPTIONS) m_magneticTrackChoice->GetSelection(); - m_Frame->Settings().m_MagneticGraphics = !m_magneticGraphicsChoice->GetSelection(); + + m_Frame->Settings().m_MagneticItems.pads = + static_cast( m_magneticPadChoice->GetSelection() ); + m_Frame->Settings().m_MagneticItems.tracks = + static_cast( m_magneticTrackChoice->GetSelection() ); + m_Frame->Settings().m_MagneticItems.graphics = !m_magneticGraphicsChoice->GetSelection(); + m_Frame->Settings().m_FlipLeftRight = m_FlipLeftRight->GetValue(); m_Frame->SetShowPageLimits( m_Show_Page_Limits->GetValue() ); diff --git a/pcbnew/footprint_edit_frame.cpp b/pcbnew/footprint_edit_frame.cpp index d7f3fca30e..d050dd9b9b 100644 --- a/pcbnew/footprint_edit_frame.cpp +++ b/pcbnew/footprint_edit_frame.cpp @@ -64,6 +64,7 @@ #include #include #include +#include #include #include #include @@ -476,6 +477,15 @@ COLOR_SETTINGS* FOOTPRINT_EDIT_FRAME::GetColorSettings() } +MAGNETIC_SETTINGS* FOOTPRINT_EDIT_FRAME::GetMagneticItemsSettings() +{ + // Get the actual frame settings for magnetic items + FOOTPRINT_EDITOR_SETTINGS* cfg = GetSettings(); + wxCHECK( cfg, nullptr ); + return &cfg->m_MagneticItems; +} + + const BOX2I FOOTPRINT_EDIT_FRAME::GetDocumentExtents() const { MODULE* module = GetBoard()->GetFirstModule(); @@ -868,6 +878,7 @@ void FOOTPRINT_EDIT_FRAME::setupTools() m_toolManager->RegisterTool( new ALIGN_DISTRIBUTE_TOOL ); m_toolManager->RegisterTool( new PCBNEW_PICKER_TOOL ); m_toolManager->RegisterTool( new POSITION_RELATIVE_TOOL ); + m_toolManager->RegisterTool( new PCB_VIEWER_TOOLS ); m_toolManager->GetTool()->SetEditModules( true ); m_toolManager->GetTool()->SetEditModules( true ); @@ -878,6 +889,7 @@ void FOOTPRINT_EDIT_FRAME::setupTools() m_toolManager->GetTool()->SetEditModules( true ); m_toolManager->GetTool()->SetEditModules( true ); + m_toolManager->GetTool()->SetFootprintFrame( true ); m_toolManager->InitTools(); m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" ); diff --git a/pcbnew/footprint_edit_frame.h b/pcbnew/footprint_edit_frame.h index e6857dd5f8..348fb54b45 100644 --- a/pcbnew/footprint_edit_frame.h +++ b/pcbnew/footprint_edit_frame.h @@ -59,7 +59,7 @@ public: */ static const wxChar* GetFootprintEditorFrameName(); - ///> @copydoc PCB_BASE_EDIT_FRAME::GetModel() + ///> @copydoc PCB_BASE_FRAME::GetModel() BOARD_ITEM_CONTAINER* GetModel() const override; /** @@ -79,6 +79,8 @@ public: const PCB_PLOT_PARAMS& GetPlotSettings() const override; void SetPlotSettings( const PCB_PLOT_PARAMS& aSettings ) override; + MAGNETIC_SETTINGS* GetMagneticItemsSettings() override; + void LoadSettings( APP_SETTINGS_BASE* aCfg ) override; void SaveSettings( APP_SETTINGS_BASE* aCfg ) override; diff --git a/pcbnew/footprint_editor_settings.cpp b/pcbnew/footprint_editor_settings.cpp index 5e6ad96e00..1d2e79536b 100644 --- a/pcbnew/footprint_editor_settings.cpp +++ b/pcbnew/footprint_editor_settings.cpp @@ -38,7 +38,7 @@ const int fpEditSchemaVersion = 1; FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS() : APP_SETTINGS_BASE( "fpedit", fpEditSchemaVersion ), m_DesignSettings(), - m_MagneticPads(), + m_MagneticItems(), m_Display(), m_UserGrid(), m_PolarCoords( false ), @@ -47,6 +47,10 @@ FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS() : m_LastImportExportPath(), m_FootprintTextShownColumns() { + m_MagneticItems.pads = MAGNETIC_OPTIONS::CAPTURE_CURSOR_IN_TRACK_TOOL; + m_MagneticItems.tracks = MAGNETIC_OPTIONS::CAPTURE_CURSOR_IN_TRACK_TOOL; + m_MagneticItems.graphics = false; + m_params.emplace_back( new PARAM( "window.lib_width", &m_LibWidth, 250 ) ); @@ -57,7 +61,7 @@ FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS() : &m_FootprintTextShownColumns, "0 1 2 3 4 5 6" ) ); m_params.emplace_back( new PARAM( "editing.magnetic_pads", - reinterpret_cast( &m_MagneticPads ), + reinterpret_cast( &m_MagneticItems.pads ), static_cast( MAGNETIC_OPTIONS::CAPTURE_CURSOR_IN_TRACK_TOOL ) ) ); m_params.emplace_back( new PARAM( "editing.polar_coords", &m_PolarCoords, false ) ); diff --git a/pcbnew/footprint_viewer_frame.cpp b/pcbnew/footprint_viewer_frame.cpp index 27ca15408b..2bb69520de 100644 --- a/pcbnew/footprint_viewer_frame.cpp +++ b/pcbnew/footprint_viewer_frame.cpp @@ -1014,3 +1014,9 @@ void FOOTPRINT_VIEWER_FRAME::CloseFootprintViewer( wxCommandEvent& event ) { Close( false ); } + + +BOARD_ITEM_CONTAINER* FOOTPRINT_VIEWER_FRAME::GetModel() const +{ + return GetBoard()->GetFirstModule(); +} diff --git a/pcbnew/footprint_viewer_frame.h b/pcbnew/footprint_viewer_frame.h index 79292c337a..76c6ba6cd3 100644 --- a/pcbnew/footprint_viewer_frame.h +++ b/pcbnew/footprint_viewer_frame.h @@ -50,6 +50,9 @@ protected: public: ~FOOTPRINT_VIEWER_FRAME(); + ///> @copydoc PCB_BASE_FRAME::GetModel() + BOARD_ITEM_CONTAINER* GetModel() const override; + /// Updates the GAL with display settings changes void ApplyDisplaySettingsToGAL(); diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp index 37eb2508da..9c2a22c361 100644 --- a/pcbnew/footprint_wizard_frame.cpp +++ b/pcbnew/footprint_wizard_frame.cpp @@ -646,6 +646,12 @@ void FOOTPRINT_WIZARD_FRAME::ReCreateHToolbar() } +BOARD_ITEM_CONTAINER* FOOTPRINT_WIZARD_FRAME::GetModel() const +{ + return GetBoard()->GetFirstModule(); +} + + void FOOTPRINT_WIZARD_FRAME::ReCreateVToolbar() { // Currently, there is no vertical toolbar diff --git a/pcbnew/footprint_wizard_frame.h b/pcbnew/footprint_wizard_frame.h index 1980e3e8d6..84486bd542 100644 --- a/pcbnew/footprint_wizard_frame.h +++ b/pcbnew/footprint_wizard_frame.h @@ -76,6 +76,9 @@ public: ~FOOTPRINT_WIZARD_FRAME(); + ///> @copydoc PCB_BASE_FRAME::GetModel() + BOARD_ITEM_CONTAINER* GetModel() const override; + MODULE* GetBuiltFootprint(); /** diff --git a/pcbnew/pcb_base_edit_frame.cpp b/pcbnew/pcb_base_edit_frame.cpp index 26ca903470..3b7d892f31 100644 --- a/pcbnew/pcb_base_edit_frame.cpp +++ b/pcbnew/pcb_base_edit_frame.cpp @@ -117,9 +117,6 @@ void PCB_BASE_EDIT_FRAME::unitsChangeRefresh() PCB_BASE_FRAME::unitsChangeRefresh(); ReCreateAuxiliaryToolbar(); - - if( m_toolManager ) - m_toolManager->RunAction( PCB_ACTIONS::updateUnits, true ); } diff --git a/pcbnew/pcb_base_edit_frame.h b/pcbnew/pcb_base_edit_frame.h index 0dfa4e9cbb..d8efddc427 100644 --- a/pcbnew/pcb_base_edit_frame.h +++ b/pcbnew/pcb_base_edit_frame.h @@ -42,12 +42,6 @@ public: virtual ~PCB_BASE_EDIT_FRAME(); - /** - * Function GetModel() - * @return the primary data model. - */ - virtual BOARD_ITEM_CONTAINER* GetModel() const = 0; - /** * Function CreateNewLibrary * If a library name is given, creates a new footprint library in the project folder diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index 101a4cc930..9735d0a4da 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -54,15 +54,11 @@ #include #include #include +#include wxDEFINE_EVENT( BOARD_CHANGED, wxCommandEvent ); BEGIN_EVENT_TABLE( PCB_BASE_FRAME, EDA_DRAW_FRAME ) - EVT_TOOL( ID_TB_OPTIONS_SHOW_PADS_SKETCH, PCB_BASE_FRAME::OnTogglePadDrawMode ) - EVT_TOOL( ID_TB_OPTIONS_SHOW_GRAPHIC_SKETCH, PCB_BASE_FRAME::OnToggleGraphicDrawMode ) - EVT_TOOL( ID_TB_OPTIONS_SHOW_MODULE_EDGE_SKETCH, PCB_BASE_FRAME::OnToggleEdgeDrawMode ) - EVT_TOOL( ID_TB_OPTIONS_SHOW_MODULE_TEXT_SKETCH, PCB_BASE_FRAME::OnToggleTextDrawMode ) - EVT_UPDATE_UI( ID_ON_GRID_SELECT, PCB_BASE_FRAME::OnUpdateSelectGrid ) EVT_UPDATE_UI( ID_ON_ZOOM_SELECT, PCB_BASE_FRAME::OnUpdateSelectZoom ) END_EVENT_TABLE() @@ -467,77 +463,6 @@ void PCB_BASE_FRAME::SwitchLayer( wxDC* DC, PCB_LAYER_ID layer ) } -void PCB_BASE_FRAME::OnTogglePadDrawMode( wxCommandEvent& aEvent ) -{ - auto displ_opts = GetDisplayOptions(); - - displ_opts.m_DisplayPadFill = !displ_opts.m_DisplayPadFill; - - if( GetCanvas() ) - { - // Apply new display options to the GAL canvas - auto view = static_cast( GetCanvas()->GetView() ); - view->UpdateDisplayOptions( displ_opts ); - - // Update pads - BOARD* board = GetBoard(); - for( auto module : board->Modules() ) - { - for( auto pad : module->Pads() ) - view->Update( pad, KIGFX::GEOMETRY ); - } - } - - SetDisplayOptions( displ_opts ); - GetCanvas()->Refresh(); -} - - -void PCB_BASE_FRAME::OnToggleGraphicDrawMode( wxCommandEvent& aEvent ) -{ - auto displ_opts = GetDisplayOptions(); - displ_opts.m_DisplayDrawItemsFill = !displ_opts.m_DisplayDrawItemsFill; - SetDisplayOptions( displ_opts ); - GetCanvas()->Refresh(); -} - - -void PCB_BASE_FRAME::OnToggleEdgeDrawMode( wxCommandEvent& aEvent ) -{ - auto displ_opts = GetDisplayOptions(); - displ_opts.m_DisplayModEdgeFill = !displ_opts.m_DisplayModEdgeFill; - - if( GetCanvas() ) - { - // Apply new display options to the GAL canvas - auto view = static_cast( GetCanvas()->GetView() ); - view->UpdateDisplayOptions( displ_opts ); - view->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); - } - - SetDisplayOptions( displ_opts ); - GetCanvas()->Refresh(); -} - - -void PCB_BASE_FRAME::OnToggleTextDrawMode( wxCommandEvent& aEvent ) -{ - auto displ_opts = GetDisplayOptions(); - displ_opts.m_DisplayModTextFill = !displ_opts.m_DisplayModTextFill; - - if( GetCanvas() ) - { - // Apply new display options to the canvas - auto view = static_cast( GetCanvas()->GetView() ); - view->UpdateDisplayOptions( displ_opts ); - view->MarkTargetDirty( KIGFX::TARGET_NONCACHED ); - } - - SetDisplayOptions( displ_opts ); - GetCanvas()->Refresh(); -} - - void PCB_BASE_FRAME::OnUpdateSelectZoom( wxUpdateUIEvent& aEvent ) { if( m_zoomSelectBox == NULL || m_zoomSelectBox->GetParent() == NULL ) @@ -717,6 +642,10 @@ void PCB_BASE_FRAME::unitsChangeRefresh() { EDA_DRAW_FRAME::unitsChangeRefresh(); // Update the status bar. + // Notify all tools the units have changed + if( m_toolManager ) + m_toolManager->RunAction( PCB_ACTIONS::updateUnits, true ); + UpdateGridSelectBox(); } @@ -775,6 +704,12 @@ FOOTPRINT_EDITOR_SETTINGS* PCB_BASE_FRAME::GetFootprintEditorSettings() return Pgm().GetSettingsManager().GetAppSettings(); } +MAGNETIC_SETTINGS* PCB_BASE_FRAME::GetMagneticItemsSettings() +{ + wxCHECK( m_Settings, nullptr ); + return &m_Settings->m_MagneticItems; +} + void PCB_BASE_FRAME::CommonSettingsChanged( bool aEnvVarsChanged ) { diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 984bc5e6a8..a53e3ce085 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -71,6 +71,7 @@ #include #include #include +#include #include #include #include @@ -455,6 +456,7 @@ void PCB_EDIT_FRAME::setupTools() m_toolManager->RegisterTool( new ZONE_FILLER_TOOL ); m_toolManager->RegisterTool( new AUTOPLACE_TOOL ); m_toolManager->RegisterTool( new DRC ); + m_toolManager->RegisterTool( new PCB_VIEWER_TOOLS ); m_toolManager->InitTools(); // Run the selection tool, it is supposed to be always active diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index 01c08f0358..97da6fc2fe 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -668,7 +668,7 @@ public: ///> @copydoc PCB_BASE_FRAME::SetBoard() void SetBoard( BOARD* aBoard ) override; - ///> @copydoc PCB_BASE_EDIT_FRAME::GetModel() + ///> @copydoc PCB_BASE_FRAME::GetModel() BOARD_ITEM_CONTAINER* GetModel() const override; ///> @copydoc EDA_BASE_FRAME::GetSeverity() diff --git a/pcbnew/pcbnew_settings.cpp b/pcbnew/pcbnew_settings.cpp index 0786fc8b5f..39cddab644 100644 --- a/pcbnew/pcbnew_settings.cpp +++ b/pcbnew/pcbnew_settings.cpp @@ -47,11 +47,12 @@ PCBNEW_SETTINGS::PCBNEW_SETTINGS() : APP_SETTINGS_BASE( "pcbnew", pcbnewSchemaVe m_Use45DegreeGraphicSegments( false ), m_FlipLeftRight( false ), m_ShowPageLimits( true ), - m_MagneticPads( MAGNETIC_OPTIONS::CAPTURE_CURSOR_IN_TRACK_TOOL ), - m_MagneticTracks( MAGNETIC_OPTIONS::CAPTURE_CURSOR_IN_TRACK_TOOL ), - m_MagneticGraphics( true ), m_PnsSettings( nullptr ) { + m_MagneticItems.pads = MAGNETIC_OPTIONS::CAPTURE_CURSOR_IN_TRACK_TOOL; + m_MagneticItems.tracks = MAGNETIC_OPTIONS::CAPTURE_CURSOR_IN_TRACK_TOOL; + m_MagneticItems.graphics = false; + m_params.emplace_back( new PARAM( "aui.show_layer_manager", &m_AuiPanels.show_layer_manager, true ) ); @@ -81,14 +82,14 @@ PCBNEW_SETTINGS::PCBNEW_SETTINGS() : APP_SETTINGS_BASE( "pcbnew", pcbnewSchemaVe m_params.emplace_back( new PARAM( "editing.flip_left_right", &m_FlipLeftRight, true ) ); m_params.emplace_back( - new PARAM( "editing.magnetic_graphics", &m_MagneticGraphics, true ) ); + new PARAM( "editing.magnetic_graphics", &m_MagneticItems.graphics, true ) ); m_params.emplace_back( new PARAM( "editing.magnetic_pads", - reinterpret_cast( &m_MagneticPads ), + reinterpret_cast( &m_MagneticItems.pads ), static_cast( MAGNETIC_OPTIONS::CAPTURE_CURSOR_IN_TRACK_TOOL ) ) ); m_params.emplace_back( new PARAM( "editing.magnetic_tracks", - reinterpret_cast( &m_MagneticTracks ), + reinterpret_cast( &m_MagneticItems.tracks ), static_cast( MAGNETIC_OPTIONS::CAPTURE_CURSOR_IN_TRACK_TOOL ) ) ); m_params.emplace_back( new PARAM( "editing.polar_coords", &m_PolarCoords, false ) ); diff --git a/pcbnew/pcbnew_settings.h b/pcbnew/pcbnew_settings.h index d2ac6ef1ee..ca3b61dcde 100644 --- a/pcbnew/pcbnew_settings.h +++ b/pcbnew/pcbnew_settings.h @@ -36,6 +36,20 @@ enum class MAGNETIC_OPTIONS CAPTURE_ALWAYS }; +struct MAGNETIC_SETTINGS +{ + MAGNETIC_OPTIONS pads; + MAGNETIC_OPTIONS tracks; + bool graphics; + + MAGNETIC_SETTINGS() + : pads( MAGNETIC_OPTIONS::CAPTURE_CURSOR_IN_TRACK_TOOL ), + tracks( MAGNETIC_OPTIONS::CAPTURE_CURSOR_IN_TRACK_TOOL ), + graphics( false ) + { + } +}; + #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU) typedef std::vector> ACTION_PLUGIN_SETTINGS_LIST; #endif @@ -235,6 +249,8 @@ public: PCB_DISPLAY_OPTIONS m_Display; + MAGNETIC_SETTINGS m_MagneticItems; + int m_FastGrid1; int m_FastGrid2; @@ -254,12 +270,6 @@ public: wxString m_FootprintTextShownColumns; - MAGNETIC_OPTIONS m_MagneticPads; - - MAGNETIC_OPTIONS m_MagneticTracks; - - bool m_MagneticGraphics; - std::unique_ptr m_PnsSettings; #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU) diff --git a/pcbnew/router/pns_tool_base.cpp b/pcbnew/router/pns_tool_base.cpp index 017c55182d..d561324ed0 100644 --- a/pcbnew/router/pns_tool_base.cpp +++ b/pcbnew/router/pns_tool_base.cpp @@ -251,12 +251,12 @@ bool TOOL_BASE::checkSnap( ITEM *aItem ) auto& pnss = m_router->Settings(); pnss.SetSnapToPads( - frame()->Settings().m_MagneticPads == MAGNETIC_OPTIONS::CAPTURE_CURSOR_IN_TRACK_TOOL || - frame()->Settings().m_MagneticPads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS ); + frame()->GetMagneticItemsSettings()->pads == MAGNETIC_OPTIONS::CAPTURE_CURSOR_IN_TRACK_TOOL || + frame()->GetMagneticItemsSettings()->pads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS ); pnss.SetSnapToTracks( - frame()->Settings().m_MagneticTracks == MAGNETIC_OPTIONS::CAPTURE_CURSOR_IN_TRACK_TOOL - || frame()->Settings().m_MagneticTracks == MAGNETIC_OPTIONS::CAPTURE_ALWAYS ); + frame()->GetMagneticItemsSettings()->tracks == MAGNETIC_OPTIONS::CAPTURE_CURSOR_IN_TRACK_TOOL + || frame()->GetMagneticItemsSettings()->tracks == MAGNETIC_OPTIONS::CAPTURE_ALWAYS ); if( aItem ) { diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index ab413182a3..e14ec8f6a1 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -56,7 +56,6 @@ using namespace std::placeholders; #include #include #include -#include #include #include @@ -203,7 +202,7 @@ bool EDIT_TOOL::Init() // Populate the context menu displayed during the edit tool (primarily the measure tool) auto activeToolCondition = [ this ] ( const SELECTION& aSel ) { - return frame()->ToolStackIsEmpty(); + return !frame()->ToolStackIsEmpty(); }; auto frame = getEditFrame(); @@ -1286,134 +1285,6 @@ void EDIT_TOOL::FootprintFilter( const VECTOR2I&, GENERAL_COLLECTOR& aCollector } -int EDIT_TOOL::MeasureTool( const TOOL_EVENT& aEvent ) -{ - if( EditingModules() && !frame()->GetModel()) - return 0; - - auto& view = *getView(); - auto& controls = *getViewControls(); - - std::string tool = aEvent.GetCommandStr().get(); - frame()->PushTool( tool ); - Activate(); - - EDA_UNITS units = frame()->GetUserUnits(); - KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER twoPtMgr; - KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, units ); - - view.Add( &ruler ); - view.SetVisible( &ruler, false ); - - GRID_HELPER grid( frame() ); - - bool originSet = false; - - controls.ShowCursor( true ); - controls.SetAutoPan( false ); - controls.CaptureCursor( false ); - - while( auto evt = Wait() ) - { - frame()->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW ); - grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); - grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); - controls.SetSnapping( !evt->Modifier( MD_ALT ) ); - const VECTOR2I cursorPos = grid.BestSnapAnchor( controls.GetMousePosition(), nullptr ); - controls.ForceCursorPosition(true, cursorPos ); - - auto clearRuler = [&] () { - view.SetVisible( &ruler, false ); - controls.SetAutoPan( false ); - controls.CaptureCursor( false ); - originSet = false; - }; - - if( evt->IsCancelInteractive() ) - { - if( originSet ) - clearRuler(); - else - { - frame()->PopTool( tool ); - break; - } - } - - else if( evt->IsActivate() ) - { - if( originSet ) - clearRuler(); - - if( evt->IsMoveTool() ) - { - // leave ourselves on the stack so we come back after the move - break; - } - else - { - frame()->PopTool( tool ); - break; - } - } - - // click or drag starts - else if( !originSet && ( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) ) - { - twoPtMgr.SetOrigin( cursorPos ); - twoPtMgr.SetEnd( cursorPos ); - - controls.CaptureCursor( true ); - controls.SetAutoPan( true ); - - originSet = true; - } - - // second click or mouse up after drag ends - else if( originSet && ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) ) - { - originSet = false; - - controls.SetAutoPan( false ); - controls.CaptureCursor( false ); - } - - // move or drag when origin set updates rules - else if( originSet && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) ) - { - twoPtMgr.SetAngleSnap( evt->Modifier( MD_CTRL ) ); - twoPtMgr.SetEnd( cursorPos ); - - view.SetVisible( &ruler, true ); - view.Update( &ruler, KIGFX::GEOMETRY ); - } - - else if( evt->IsAction( &ACTIONS::toggleUnits ) - || evt->IsAction( &PCB_ACTIONS::updateUnits ) ) - { - if( frame()->GetUserUnits() != units ) - { - units = frame()->GetUserUnits(); - ruler.SwitchUnits(); - view.Update( &ruler, KIGFX::GEOMETRY ); - } - } - - else if( evt->IsClick( BUT_RIGHT ) ) - { - m_menu.ShowContextMenu(); - } - - else - evt->SetPassEvent(); - } - - view.SetVisible( &ruler, false ); - view.Remove( &ruler ); - return 0; -} - - bool EDIT_TOOL::updateModificationPoint( PCBNEW_SELECTION& aSelection ) { if( m_dragging && aSelection.HasReferencePoint() ) @@ -1589,7 +1460,6 @@ void EDIT_TOOL::setTransitions() Go( &EDIT_TOOL::ChangeTrackWidth, PCB_ACTIONS::changeTrackWidth.MakeEvent() ); Go( &EDIT_TOOL::EditFpInFpEditor, PCB_ACTIONS::editFootprintInFpEditor.MakeEvent() ); - Go( &EDIT_TOOL::MeasureTool, ACTIONS::measureTool.MakeEvent() ); Go( &EDIT_TOOL::copyToClipboard, ACTIONS::copy.MakeEvent() ); Go( &EDIT_TOOL::cutToClipboard, ACTIONS::cut.MakeEvent() ); diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index a60bf7f40d..4e9e44f308 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -140,9 +140,6 @@ public: */ int CreateArray( const TOOL_EVENT& aEvent ); - ///> Launches a tool to measure between points - int MeasureTool( const TOOL_EVENT& aEvent ); - /** * Function FootprintFilter() * A selection filter which prunes the selection to contain only items of type PCB_MODULE_T diff --git a/pcbnew/tools/grid_helper.cpp b/pcbnew/tools/grid_helper.cpp index ec8bd390e9..4870081f03 100644 --- a/pcbnew/tools/grid_helper.cpp +++ b/pcbnew/tools/grid_helper.cpp @@ -403,7 +403,7 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bo { // Getting pads from the module requires re-checking that the pad is shown if( ( aFrom || - m_frame->Settings().m_MagneticPads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS ) + m_frame->GetMagneticItemsSettings()->pads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS ) && pad->GetBoundingBox().Contains( wxPoint( aRefPos.x, aRefPos.y ) ) && view->IsVisible( pad ) && ( !isHighContrast || activeLayers.count( pad->GetLayer() ) ) @@ -421,7 +421,7 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bo case PCB_PAD_T: { - if( aFrom || m_frame->Settings().m_MagneticPads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS ) + if( aFrom || m_frame->GetMagneticItemsSettings()->pads == MAGNETIC_OPTIONS::CAPTURE_ALWAYS ) { D_PAD* pad = static_cast( aItem ); addAnchor( pad->GetPosition(), CORNER | SNAPPABLE, pad ); @@ -433,7 +433,7 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bo case PCB_MODULE_EDGE_T: case PCB_LINE_T: { - if( !m_frame->Settings().m_MagneticGraphics ) + if( !m_frame->GetMagneticItemsSettings()->graphics ) break; DRAWSEGMENT* dseg = static_cast( aItem ); @@ -498,7 +498,7 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bo case PCB_TRACE_T: case PCB_ARC_T: { - if( aFrom || m_frame->Settings().m_MagneticTracks == MAGNETIC_OPTIONS::CAPTURE_ALWAYS ) + if( aFrom || m_frame->GetMagneticItemsSettings()->tracks == MAGNETIC_OPTIONS::CAPTURE_ALWAYS ) { TRACK* track = static_cast( aItem ); VECTOR2I start = track->GetStart(); @@ -520,7 +520,7 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bo case PCB_VIA_T: { - if( aFrom || m_frame->Settings().m_MagneticTracks == MAGNETIC_OPTIONS::CAPTURE_ALWAYS ) + if( aFrom || m_frame->GetMagneticItemsSettings()->tracks == MAGNETIC_OPTIONS::CAPTURE_ALWAYS ) addAnchor( aItem->GetPosition(), ORIGIN | CORNER | SNAPPABLE, aItem ); break; diff --git a/pcbnew/tools/pcb_viewer_tools.cpp b/pcbnew/tools/pcb_viewer_tools.cpp new file mode 100644 index 0000000000..dc0025a66c --- /dev/null +++ b/pcbnew/tools/pcb_viewer_tools.cpp @@ -0,0 +1,300 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 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 Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +bool PCB_VIEWER_TOOLS::Init() +{ + // Populate the context menu displayed during the tool (primarily the measure tool) + auto activeToolCondition = + [ this ] ( const SELECTION& aSel ) + { + return !frame()->ToolStackIsEmpty(); + }; + + auto& ctxMenu = m_menu.GetMenu(); + + // "Cancel" goes at the top of the context menu when a tool is active + ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolCondition, 1 ); + ctxMenu.AddSeparator( 1 ); + + frame()->AddStandardSubMenus( m_menu ); + + return true; +} + + +void PCB_VIEWER_TOOLS::Reset( RESET_REASON aReason ) +{ +} + + +int PCB_VIEWER_TOOLS::Show3DViewer( const TOOL_EVENT& aEvent ) +{ + EDA_3D_VIEWER* draw3DFrame = frame()->CreateAndShow3D_Frame(); + + // Suppress warnings on non-Mac systems + [&draw3DFrame] {}(); + + if( frame()->IsType( FRAME_FOOTPRINT_VIEWER ) + || frame()->IsType( FRAME_FOOTPRINT_VIEWER_MODAL ) + || frame()->IsType( FRAME_FOOTPRINT_WIZARD ) ) + { + frame()->Update3DView( true ); + +#ifdef __WXMAC__ + // A stronger version of Raise() which promotes the window to its parent's level. + draw3DFrame->ReparentQuasiModal(); +#endif + } + return 0; +} + + +template void Flip( T& aValue ) +{ + aValue = !aValue; +} + + +int PCB_VIEWER_TOOLS::PadDisplayMode( const TOOL_EVENT& aEvent ) +{ + auto opts = displayOptions(); + + Flip( opts.m_DisplayPadFill ); + frame()->SetDisplayOptions( opts ); + view()->UpdateDisplayOptions( opts ); + + for( auto module : board()->Modules() ) + { + for( auto pad : module->Pads() ) + view()->Update( pad, KIGFX::GEOMETRY ); + } + + canvas()->Refresh(); + + return 0; +} + + +int PCB_VIEWER_TOOLS::ModuleEdgeOutlines( const TOOL_EVENT& aEvent ) +{ + auto opts = displayOptions(); + + Flip( opts.m_DisplayModEdgeFill ); + frame()->SetDisplayOptions( opts ); + view()->UpdateDisplayOptions( opts ); + + for( auto module : board()->Modules() ) + { + for( auto item : module->GraphicalItems() ) + { + if( item->Type() == PCB_MODULE_EDGE_T ) + view()->Update( item, KIGFX::GEOMETRY ); + } + } + + canvas()->Refresh(); + + return 0; +} + + +int PCB_VIEWER_TOOLS::ModuleTextOutlines( const TOOL_EVENT& aEvent ) +{ + auto opts = displayOptions(); + + Flip( opts.m_DisplayModTextFill ); + frame()->SetDisplayOptions( opts ); + view()->UpdateDisplayOptions( opts ); + + for( auto module : board()->Modules() ) + { + view()->Update( &module->Reference(), KIGFX::GEOMETRY ); + view()->Update( &module->Value(), KIGFX::GEOMETRY ); + + for( auto item : module->GraphicalItems() ) + { + if( item->Type() == PCB_MODULE_TEXT_T ) + view()->Update( item, KIGFX::GEOMETRY ); + } + } + + canvas()->Refresh(); + + return 0; +} + + +int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent ) +{ + if( IsFootprintFrame() && !frame()->GetModel() ) + return 0; + + auto& view = *getView(); + auto& controls = *getViewControls(); + + std::string tool = aEvent.GetCommandStr().get(); + frame()->PushTool( tool ); + Activate(); + + KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER twoPtMgr; + + EDA_UNITS units = frame()->GetUserUnits(); + KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, units ); + + view.Add( &ruler ); + view.SetVisible( &ruler, false ); + + GRID_HELPER grid( frame() ); + + bool originSet = false; + + controls.ShowCursor( true ); + controls.SetAutoPan( false ); + controls.CaptureCursor( false ); + + while( auto evt = Wait() ) + { + frame()->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW ); + grid.SetSnap( !evt->Modifier( MD_SHIFT ) ); + grid.SetUseGrid( !evt->Modifier( MD_ALT ) ); + controls.SetSnapping( !evt->Modifier( MD_ALT ) ); + const VECTOR2I cursorPos = grid.BestSnapAnchor( controls.GetMousePosition(), nullptr ); + controls.ForceCursorPosition(true, cursorPos ); + + auto clearRuler = + [&] () + { + view.SetVisible( &ruler, false ); + controls.SetAutoPan( false ); + controls.CaptureCursor( false ); + originSet = false; + }; + + if( evt->IsCancelInteractive() ) + { + if( originSet ) + clearRuler(); + else + { + frame()->PopTool( tool ); + break; + } + } + + else if( evt->IsActivate() ) + { + if( originSet ) + clearRuler(); + + if( evt->IsMoveTool() ) + { + // leave ourselves on the stack so we come back after the move + break; + } + else + { + frame()->PopTool( tool ); + break; + } + } + + // click or drag starts + else if( !originSet && ( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) ) + { + twoPtMgr.SetOrigin( cursorPos ); + twoPtMgr.SetEnd( cursorPos ); + + controls.CaptureCursor( true ); + controls.SetAutoPan( true ); + + originSet = true; + } + + // second click or mouse up after drag ends + else if( originSet && ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) ) + { + originSet = false; + + controls.SetAutoPan( false ); + controls.CaptureCursor( false ); + } + + // move or drag when origin set updates rules + else if( originSet && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) ) + { + twoPtMgr.SetAngleSnap( evt->Modifier( MD_CTRL ) ); + twoPtMgr.SetEnd( cursorPos ); + + view.SetVisible( &ruler, true ); + view.Update( &ruler, KIGFX::GEOMETRY ); + } + + else if( evt->IsAction( &ACTIONS::toggleUnits ) + || evt->IsAction( &PCB_ACTIONS::updateUnits ) ) + { + if( frame()->GetUserUnits() != units ) + { + units = frame()->GetUserUnits(); + ruler.SwitchUnits(); + view.Update( &ruler, KIGFX::GEOMETRY ); + canvas()->Refresh(); + } + } + + else if( evt->IsClick( BUT_RIGHT ) ) + { + m_menu.ShowContextMenu(); + } + + else + evt->SetPassEvent(); + } + + view.SetVisible( &ruler, false ); + view.Remove( &ruler ); + return 0; +} + + +void PCB_VIEWER_TOOLS::setTransitions() +{ + Go( &PCB_VIEWER_TOOLS::Show3DViewer, ACTIONS::show3DViewer.MakeEvent() ); + + // Display modes + Go( &PCB_VIEWER_TOOLS::PadDisplayMode, PCB_ACTIONS::padDisplayMode.MakeEvent() ); + Go( &PCB_VIEWER_TOOLS::ModuleEdgeOutlines, PCB_ACTIONS::moduleEdgeOutlines.MakeEvent() ); + Go( &PCB_VIEWER_TOOLS::ModuleTextOutlines, PCB_ACTIONS::moduleTextOutlines.MakeEvent() ); + + Go( &PCB_VIEWER_TOOLS::MeasureTool, ACTIONS::measureTool.MakeEvent() ); +} diff --git a/pcbnew/tools/pcb_viewer_tools.h b/pcbnew/tools/pcb_viewer_tools.h new file mode 100644 index 0000000000..7c74aab4fb --- /dev/null +++ b/pcbnew/tools/pcb_viewer_tools.h @@ -0,0 +1,117 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 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 Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef PCB_VIEWER_TOOLS_H_ +#define PCB_VIEWER_TOOLS_H_ + +#include +#include + +class PCB_BASE_FRAME; + +/** + * PCB_VIEWER_TOOLS + * + * Tools useful for viewing footprints. + * This tool is designed to be lighter-weight so that it doesn't + * bring in as many pcbnew dependencies (since it is used in cvpcb). + */ +class PCB_VIEWER_TOOLS : public TOOL_INTERACTIVE +{ +public: + PCB_VIEWER_TOOLS() : + TOOL_INTERACTIVE( "pcbnew.PCBViewerTools" ), + m_footprintFrame( false ) + {} + + ~PCB_VIEWER_TOOLS() override {} + + bool Init() override; + + /// @copydoc TOOL_BASE::Reset() + void Reset( RESET_REASON aReason ) override; + + ///> Launches a tool to measure between points + int MeasureTool( const TOOL_EVENT& aEvent ); + + // Display modes + int PadDisplayMode( const TOOL_EVENT& aEvent ); + int ModuleEdgeOutlines( const TOOL_EVENT& aEvent ); + int ModuleTextOutlines( const TOOL_EVENT& aEvent ); + + /// Show the 3D viewer + int Show3DViewer( const TOOL_EVENT& aEvent ); + + ///> Sets up handlers for various events. + void setTransitions() override; + + /** + * Toggles edit module mode. When enabled, one may select parts of modules individually + * (graphics, pads, etc.), so they can be modified. + * @param aEnabled decides if the mode should be enabled. + */ + void SetFootprintFrame( bool aIsFrame ) + { + m_footprintFrame = aIsFrame; + } + + bool IsFootprintFrame() const + { + return m_footprintFrame; + } + +protected: + bool m_footprintFrame; ///< Is this tool associated with a footprint frame + + PCB_BASE_FRAME* frame() const + { + return getEditFrame(); + } + + KIGFX::PCB_VIEW* view() const + { + return static_cast( getView() ); + } + + const PCB_DISPLAY_OPTIONS& displayOptions() const + { + return frame()->GetDisplayOptions(); + } + + PCB_DRAW_PANEL_GAL* canvas() const + { + return static_cast( frame()->GetCanvas() ); + } + + BOARD* board() const + { + return getModel(); + } + + MODULE* module() const + { + return board()->GetFirstModule(); + } +}; + +#endif diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 7507cf844d..ffcad4b553 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -169,26 +169,6 @@ int PCBNEW_CONTROL::ToggleRatsnest( const TOOL_EVENT& aEvent ) } -int PCBNEW_CONTROL::PadDisplayMode( const TOOL_EVENT& aEvent ) -{ - auto opts = displayOptions(); - - Flip( opts.m_DisplayPadFill ); - m_frame->SetDisplayOptions( opts ); - view()->UpdateDisplayOptions( opts ); - - for( auto module : board()->Modules() ) // fixme: move to PCB_VIEW - { - for( auto pad : module->Pads() ) - view()->Update( pad, KIGFX::GEOMETRY ); - } - - canvas()->Refresh(); - - return 0; -} - - int PCBNEW_CONTROL::ViaDisplayMode( const TOOL_EVENT& aEvent ) { auto opts = displayOptions(); @@ -228,55 +208,6 @@ int PCBNEW_CONTROL::GraphicDisplayMode( const TOOL_EVENT& aEvent ) } -int PCBNEW_CONTROL::ModuleEdgeOutlines( const TOOL_EVENT& aEvent ) -{ - auto opts = displayOptions(); - - Flip( opts.m_DisplayModEdgeFill ); - m_frame->SetDisplayOptions( opts ); - view()->UpdateDisplayOptions( opts ); - - for( auto module : board()->Modules() ) - { - for( auto item : module->GraphicalItems() ) - { - if( item->Type() == PCB_MODULE_EDGE_T ) - view()->Update( item, KIGFX::GEOMETRY ); - } - } - - canvas()->Refresh(); - - return 0; -} - - -int PCBNEW_CONTROL::ModuleTextOutlines( const TOOL_EVENT& aEvent ) -{ - auto opts = displayOptions(); - - Flip( opts.m_DisplayModTextFill ); - m_frame->SetDisplayOptions( opts ); - view()->UpdateDisplayOptions( opts ); - - for( auto module : board()->Modules() ) - { - view()->Update( &module->Reference(), KIGFX::GEOMETRY ); - view()->Update( &module->Value(), KIGFX::GEOMETRY ); - - for( auto item : module->GraphicalItems() ) - { - if( item->Type() == PCB_MODULE_TEXT_T ) - view()->Update( item, KIGFX::GEOMETRY ); - } - } - - canvas()->Refresh(); - - return 0; -} - - int PCBNEW_CONTROL::ZoneDisplayMode( const TOOL_EVENT& aEvent ) { auto opts = displayOptions(); @@ -1049,29 +980,6 @@ int PCBNEW_CONTROL::Redo( const TOOL_EVENT& aEvent ) } -int PCBNEW_CONTROL::Show3DViewer( const TOOL_EVENT& aEvent ) -{ - EDA_3D_VIEWER* draw3DFrame = m_frame->CreateAndShow3D_Frame(); - - // Suppress warnings on non-Mac systems - [&draw3DFrame] {}(); - - if( m_frame->IsType( FRAME_FOOTPRINT_VIEWER ) - || m_frame->IsType( FRAME_FOOTPRINT_VIEWER_MODAL ) - || m_frame->IsType( FRAME_FOOTPRINT_WIZARD ) ) - { - m_frame->Update3DView( true ); - -#ifdef __WXMAC__ - // A stronger version of Raise() which promotes the window to its parent's level. - draw3DFrame->ReparentQuasiModal(); -#endif - } - - return 0; -} - - void PCBNEW_CONTROL::updateGrid() { BASE_SCREEN* screen = m_frame->GetScreen(); @@ -1157,11 +1065,8 @@ void PCBNEW_CONTROL::setTransitions() Go( &PCBNEW_CONTROL::TrackDisplayMode, PCB_ACTIONS::trackDisplayMode.MakeEvent() ); Go( &PCBNEW_CONTROL::ToggleRatsnest, PCB_ACTIONS::showRatsnest.MakeEvent() ); Go( &PCBNEW_CONTROL::ToggleRatsnest, PCB_ACTIONS::ratsnestLineMode.MakeEvent() ); - Go( &PCBNEW_CONTROL::PadDisplayMode, PCB_ACTIONS::padDisplayMode.MakeEvent() ); Go( &PCBNEW_CONTROL::ViaDisplayMode, PCB_ACTIONS::viaDisplayMode.MakeEvent() ); Go( &PCBNEW_CONTROL::GraphicDisplayMode, PCB_ACTIONS::graphicDisplayMode.MakeEvent() ); - Go( &PCBNEW_CONTROL::ModuleEdgeOutlines, PCB_ACTIONS::moduleEdgeOutlines.MakeEvent() ); - Go( &PCBNEW_CONTROL::ModuleTextOutlines, PCB_ACTIONS::moduleTextOutlines.MakeEvent() ); Go( &PCBNEW_CONTROL::ZoneDisplayMode, PCB_ACTIONS::zoneDisplayEnable.MakeEvent() ); Go( &PCBNEW_CONTROL::ZoneDisplayMode, PCB_ACTIONS::zoneDisplayDisable.MakeEvent() ); Go( &PCBNEW_CONTROL::ZoneDisplayMode, PCB_ACTIONS::zoneDisplayOutlines.MakeEvent() ); @@ -1218,7 +1123,6 @@ void PCBNEW_CONTROL::setTransitions() // Miscellaneous Go( &PCBNEW_CONTROL::DeleteItemCursor, ACTIONS::deleteTool.MakeEvent() ); - Go( &PCBNEW_CONTROL::Show3DViewer, ACTIONS::show3DViewer.MakeEvent() ); // Append control Go( &PCBNEW_CONTROL::AppendBoardFromFile, PCB_ACTIONS::appendBoard.MakeEvent() ); diff --git a/pcbnew/tools/pcbnew_control.h b/pcbnew/tools/pcbnew_control.h index 5a0f94f42b..984512b3b6 100644 --- a/pcbnew/tools/pcbnew_control.h +++ b/pcbnew/tools/pcbnew_control.h @@ -58,11 +58,8 @@ public: int ToggleRatsnest( const TOOL_EVENT& aEvent ); int ZoneDisplayMode( const TOOL_EVENT& aEvent ); int TrackDisplayMode( const TOOL_EVENT& aEvent ); - int PadDisplayMode( const TOOL_EVENT& aEvent ); int ViaDisplayMode( const TOOL_EVENT& aEvent ); int GraphicDisplayMode( const TOOL_EVENT& aEvent ); - int ModuleEdgeOutlines( const TOOL_EVENT& aEvent ); - int ModuleTextOutlines( const TOOL_EVENT& aEvent ); int HighContrastMode( const TOOL_EVENT& aEvent ); // Layer control @@ -91,7 +88,6 @@ public: int Paste( const TOOL_EVENT& aEvent ); int AppendBoardFromFile( const TOOL_EVENT& aEvent ); int AppendBoard( PLUGIN& pi, wxString& fileName ); - int Show3DViewer( const TOOL_EVENT& aEvent ); int UpdateMessagePanel( const TOOL_EVENT& aEvent ); ///> Sets up handlers for various events.