From 60e9546b627ad5d5f0b0ead3c4cdf5d728bd8856 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Mon, 24 Mar 2014 17:20:23 +0100 Subject: [PATCH] PCB_EDIT_FRAME::SetHighContrastLayer() went public. Refactored code that handled zooming events. Added PCB_RENDER_SETTINGS::Get/SetSketchMode(). PCBNEW_CONTROL reacts to hot keys changing display modes (sketch via/tracks, high contrast). --- common/tool/tool_dispatcher.cpp | 34 +++++-- common/zoom.cpp | 27 +++-- include/tool/tool_dispatcher.h | 2 +- include/wxPcbStruct.h | 14 +-- include/wxstruct.h | 12 +++ pcbnew/dialogs/dialog_general_options.cpp | 2 +- pcbnew/hotkeys_board_editor.cpp | 4 +- pcbnew/initpcb.cpp | 2 +- pcbnew/menubar_pcbframe.cpp | 4 +- pcbnew/pcb_painter.cpp | 21 ++-- pcbnew/pcb_painter.h | 30 +++++- pcbnew/pcbframe.cpp | 4 +- pcbnew/tools/common_actions.cpp | 9 ++ pcbnew/tools/common_actions.h | 2 + pcbnew/tools/pcb_tools.cpp | 15 ++- pcbnew/tools/pcbnew_control.cpp | 115 +++++++++++++++++++--- pcbnew/tools/pcbnew_control.h | 13 ++- 17 files changed, 242 insertions(+), 68 deletions(-) diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index 1085534eec..8f36386766 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -27,16 +27,16 @@ #include #include +#include #include #include #include +#include #include #include -using boost::optional; - ///> Stores information about a mouse button state struct TOOL_DISPATCHER::BUTTON_STATE { @@ -126,7 +126,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti { BUTTON_STATE* st = m_buttons[aIndex]; wxEventType type = aEvent.GetEventType(); - optional evt; + boost::optional evt; bool isClick = false; bool up = type == st->upEvent; @@ -205,7 +205,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) { bool motion = false, buttonEvents = false; - optional evt; + boost::optional evt; int type = aEvent.GetEventType(); @@ -270,7 +270,29 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent ) } -void TOOL_DISPATCHER::DispatchWxCommand( const wxCommandEvent& aEvent ) +void TOOL_DISPATCHER::DispatchWxCommand( wxCommandEvent& aEvent ) { - // no events to dispatch currently + boost::optional evt; + + switch( aEvent.GetId() ) + { + case ID_ZOOM_IN: // toolbar button "Zoom In" + evt = COMMON_ACTIONS::zoomInCenter.MakeEvent(); + break; + + case ID_ZOOM_OUT: // toolbar button "Zoom In" + evt = COMMON_ACTIONS::zoomOutCenter.MakeEvent(); + break; + + case ID_ZOOM_PAGE: // toolbar button "Fit on Screen" + evt = COMMON_ACTIONS::zoomFitScreen.MakeEvent(); + break; + + default: + aEvent.Skip(); + break; + } + + if( evt ) + m_toolMgr->ProcessEvent( *evt ); } diff --git a/common/zoom.cpp b/common/zoom.cpp index 859d5a4872..b85cc0cc2a 100644 --- a/common/zoom.cpp +++ b/common/zoom.cpp @@ -194,25 +194,22 @@ void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event ) RedrawScreen( center, true ); } - if( IsGalCanvasActive() ) - { - // Apply computed view settings to GAL - KIGFX::VIEW* view = GetGalCanvas()->GetView(); - KIGFX::GAL* gal = GetGalCanvas()->GetGAL(); - - double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); - double zoom = 1.0 / ( zoomFactor * GetZoom() ); - - VECTOR2D cursorWorld( GetCrossHairPosition() ); - view->SetScale( zoom, cursorWorld ); - - GetGalCanvas()->Refresh(); - } - UpdateStatusBar(); } +void EDA_DRAW_FRAME::SetNextZoom() +{ + GetScreen()->SetNextZoom(); +} + + +void EDA_DRAW_FRAME::SetPrevZoom() +{ + GetScreen()->SetPreviousZoom(); +} + + /* add the zoom list menu the the MasterMenu. * used in OnRightClick(wxMouseEvent& event) */ diff --git a/include/tool/tool_dispatcher.h b/include/tool/tool_dispatcher.h index 3a9be1ac64..8ecd893db1 100644 --- a/include/tool/tool_dispatcher.h +++ b/include/tool/tool_dispatcher.h @@ -79,7 +79,7 @@ public: * specified tool). * @param aEvent is the wxCommandEvent to be processed. */ - virtual void DispatchWxCommand( const wxCommandEvent& aEvent ); + virtual void DispatchWxCommand( wxCommandEvent& aEvent ); private: ///> Number of mouse buttons that is handled in events. diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 03038aece4..022a591930 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -134,12 +134,6 @@ protected: void createPopUpBlockMenu( wxMenu* menu ); void createPopUpMenuForMarkers( MARKER_PCB* aMarker, wxMenu* aPopMenu ); - /** - * Function setHighContrastLayer - * takes care of display settings for the given layer to be displayed in high contrast mode. - */ - void setHighContrastLayer( LAYER_NUM aLayer ); - /** * Function syncLayerWidgetLayer * updates the currently layer "selection" within the PCB_LAYER_WIDGET. @@ -555,6 +549,12 @@ public: */ virtual void OnModify(); + /** + * Function SetHighContrastLayer + * takes care of display settings for the given layer to be displayed in high contrast mode. + */ + void SetHighContrastLayer( LAYER_NUM aLayer ); + /** * Function SetTopLayer * moves the selected layer to the top, so it is displayed above all others. @@ -572,7 +572,7 @@ public: * Function GetActiveLayer * returns the active layer */ - LAYER_NUM GetActiveLayer() + LAYER_NUM GetActiveLayer() const { return ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer; } diff --git a/include/wxstruct.h b/include/wxstruct.h index 5564fe6050..1047a04302 100644 --- a/include/wxstruct.h +++ b/include/wxstruct.h @@ -796,6 +796,18 @@ public: virtual void OnZoom( wxCommandEvent& event ); + /** + * Function SetNextZoom() + * changes the zoom to the next one available. + */ + void SetNextZoom(); + + /** + * Function SetPrevZoom() + * changes the zoom to the previous one available. + */ + void SetPrevZoom(); + /** * Function RedrawScreen * redraws the entire screen area by updating the scroll bars and mouse pointer in diff --git a/pcbnew/dialogs/dialog_general_options.cpp b/pcbnew/dialogs/dialog_general_options.cpp index fd7b1aa847..af29d9796a 100644 --- a/pcbnew/dialogs/dialog_general_options.cpp +++ b/pcbnew/dialogs/dialog_general_options.cpp @@ -228,7 +228,7 @@ void PCB_EDIT_FRAME::OnSelectOptionToolbar( wxCommandEvent& event ) // Apply new display options to the GAL canvas (this is faster than recaching) settings->LoadDisplayOptions( DisplayOpt ); - setHighContrastLayer( GetActiveLayer() ); + SetHighContrastLayer( GetActiveLayer() ); m_canvas->Refresh(); break; diff --git a/pcbnew/hotkeys_board_editor.cpp b/pcbnew/hotkeys_board_editor.cpp index 42ab76ac75..a1dae36662 100644 --- a/pcbnew/hotkeys_board_editor.cpp +++ b/pcbnew/hotkeys_board_editor.cpp @@ -152,7 +152,6 @@ void PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit cmd.SetEventObject( this ); LAYER_NUM ll; - unsigned int cnt; switch( hk_id ) { @@ -355,8 +354,7 @@ void PCB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotkeyCode, const wxPoint& aPosit break; case HK_SWITCH_TRACK_DISPLAY_MODE: - DisplayOpt.DisplayPcbTrackFill ^= 1; - DisplayOpt.DisplayPcbTrackFill &= 1; + DisplayOpt.DisplayPcbTrackFill = !DisplayOpt.DisplayPcbTrackFill; m_DisplayPcbTrackFill = DisplayOpt.DisplayPcbTrackFill; m_canvas->Refresh(); break; diff --git a/pcbnew/initpcb.cpp b/pcbnew/initpcb.cpp index 8b3b398995..0cb84ac8fb 100644 --- a/pcbnew/initpcb.cpp +++ b/pcbnew/initpcb.cpp @@ -74,7 +74,7 @@ bool PCB_EDIT_FRAME::Clear_Pcb( bool aQuery ) GetBoard()->SetVisibleLayers( ALL_LAYERS ); // Set currently selected layer to be shown in high contrast mode, when enabled` - setHighContrastLayer( GetScreen()->m_Active_Layer ); + SetHighContrastLayer( GetScreen()->m_Active_Layer ); ReFillLayerWidget(); diff --git a/pcbnew/menubar_pcbframe.cpp b/pcbnew/menubar_pcbframe.cpp index f75bd16aaf..780d876ee6 100644 --- a/pcbnew/menubar_pcbframe.cpp +++ b/pcbnew/menubar_pcbframe.cpp @@ -328,12 +328,12 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() */ // Zoom In text = AddHotkeyName( _( "Zoom &In" ), g_Pcbnew_Editor_Hokeys_Descr, - HK_ZOOM_IN ); + HK_ZOOM_IN, IS_ACCELERATOR ); AddMenuItem( viewMenu, ID_ZOOM_IN, text, HELP_ZOOM_IN, KiBitmap( zoom_in_xpm ) ); // Zoom Out text = AddHotkeyName( _( "Zoom &Out" ), g_Pcbnew_Editor_Hokeys_Descr, - HK_ZOOM_OUT ); + HK_ZOOM_OUT, IS_ACCELERATOR ); AddMenuItem( viewMenu, ID_ZOOM_OUT, text, HELP_ZOOM_OUT, KiBitmap( zoom_out_xpm ) ); // Fit on Screen diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 6aa9e54929..e47e2b3686 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -46,7 +46,7 @@ PCB_RENDER_SETTINGS::PCB_RENDER_SETTINGS() // By default everything should be displayed as filled for( unsigned int i = 0; i < END_PCB_VISIBLE_LIST; ++i ) { - m_sketchModeSelect[i] = false; + m_sketchMode[i] = false; } update(); @@ -94,9 +94,9 @@ void PCB_RENDER_SETTINGS::LoadDisplayOptions( const DISPLAY_OPTIONS& aOptions ) m_padNumbers = aOptions.DisplayPadNum; // Whether to draw tracks, vias & pads filled or as outlines - m_sketchModeSelect[PADS_VISIBLE] = !aOptions.DisplayPadFill; - m_sketchModeSelect[VIA_THROUGH_VISIBLE] = !aOptions.DisplayViaFill; - m_sketchModeSelect[TRACKS_VISIBLE] = !aOptions.DisplayPcbTrackFill; + m_sketchMode[PADS_VISIBLE] = !aOptions.DisplayPadFill; + m_sketchMode[VIA_THROUGH_VISIBLE] = !aOptions.DisplayViaFill; + m_sketchMode[TRACKS_VISIBLE] = !aOptions.DisplayPcbTrackFill; switch( aOptions.DisplayNetNamesMode ) { @@ -248,6 +248,7 @@ bool PCB_PAINTER::Draw( const VIEW_ITEM* aItem, int aLayer ) case PCB_MARKER_T: draw( (MARKER_PCB*) aItem ); + break; default: // Painter does not know how to draw the object @@ -308,7 +309,7 @@ void PCB_PAINTER::draw( const TRACK* aTrack, int aLayer ) m_gal->SetStrokeColor( color ); m_gal->SetIsStroke( true ); - if( m_pcbSettings->m_sketchModeSelect[TRACKS_VISIBLE] ) + if( m_pcbSettings->m_sketchMode[TRACKS_VISIBLE] ) { // Outline mode m_gal->SetLineWidth( m_pcbSettings->m_outlineWidth ); @@ -344,7 +345,7 @@ void PCB_PAINTER::draw( const SEGVIA* aVia, int aLayer ) const COLOR4D& color = m_pcbSettings->GetColor( aVia, aLayer ); - if( m_pcbSettings->m_sketchModeSelect[VIA_THROUGH_VISIBLE] ) + if( m_pcbSettings->m_sketchMode[VIA_THROUGH_VISIBLE] ) { // Outline mode m_gal->SetIsFill( false ); @@ -475,7 +476,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) // Pad drawing const COLOR4D& color = m_pcbSettings->GetColor( aPad, aLayer ); - if( m_pcbSettings->m_sketchModeSelect[PADS_VISIBLE] ) + if( m_pcbSettings->m_sketchMode[PADS_VISIBLE] ) { // Outline mode m_gal->SetIsFill( false ); @@ -538,7 +539,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) m = ( size.y - size.x ); n = size.x; - if( m_pcbSettings->m_sketchModeSelect[PADS_VISIBLE] ) + if( m_pcbSettings->m_sketchMode[PADS_VISIBLE] ) { // Outline mode m_gal->DrawArc( VECTOR2D( 0, -m ), n, -M_PI, 0 ); @@ -559,7 +560,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) m = ( size.x - size.y ); n = size.y; - if( m_pcbSettings->m_sketchModeSelect[PADS_VISIBLE] ) + if( m_pcbSettings->m_sketchMode[PADS_VISIBLE] ) { // Outline mode m_gal->DrawArc( VECTOR2D( -m, 0 ), n, M_PI / 2, 3 * M_PI / 2 ); @@ -595,7 +596,7 @@ void PCB_PAINTER::draw( const D_PAD* aPad, int aLayer ) pointList.push_back( VECTOR2D( corners[2] ) ); pointList.push_back( VECTOR2D( corners[3] ) ); - if( m_pcbSettings->m_sketchModeSelect[PADS_VISIBLE] ) + if( m_pcbSettings->m_sketchMode[PADS_VISIBLE] ) { // Add the beginning point to close the outline pointList.push_back( pointList.front() ); diff --git a/pcbnew/pcb_painter.h b/pcbnew/pcb_painter.h index efa9cc061b..820c4077a5 100644 --- a/pcbnew/pcb_painter.h +++ b/pcbnew/pcb_painter.h @@ -99,6 +99,34 @@ public: */ const COLOR4D& GetLayerColor( int aLayer ) const; + /** + * Function SetSketchMode + * Turns on/off sketch mode for given item layer. + * @param aItemLayer is the item layer that is changed. + * @param aEnabled decides if it is drawn in sketch mode (true for sketched mode, + * false for filled mode). + */ + void SetSketchMode( int aItemLayer, bool aEnabled ) + { + // It is supposed to work only with item layers + assert( aItemLayer >= ITEM_GAL_LAYER( 0 ) ); + + m_sketchMode[aItemLayer] = aEnabled; + } + + /** + * Function GetSketchMode + * Returns sketch mode setting for a given item layer. + * @param aItemLayer is the item layer that is changed. + */ + bool GetSketchMode( int aItemLayer ) const + { + // It is supposed to work only with item layers + assert( aItemLayer >= ITEM_GAL_LAYER( 0 ) ); + + return m_sketchMode[aItemLayer]; + } + protected: ///> @copydoc RENDER_SETTINGS::Update() void update(); @@ -116,7 +144,7 @@ protected: COLOR4D m_layerColorsDark[TOTAL_LAYER_COUNT]; ///> Flag determining if items on a given layer should be drawn as an outline or a filled item - bool m_sketchModeSelect[TOTAL_LAYER_COUNT]; + bool m_sketchMode[TOTAL_LAYER_COUNT]; ///> Flag determining if pad numbers should be visible bool m_padNumbers; diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 8c39655d8b..b168e54300 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -860,7 +860,7 @@ bool PCB_EDIT_FRAME::IsMicroViaAcceptable( void ) } -void PCB_EDIT_FRAME::setHighContrastLayer( LAYER_NUM aLayer ) +void PCB_EDIT_FRAME::SetHighContrastLayer( LAYER_NUM aLayer ) { // Set display settings for high contrast mode KIGFX::VIEW* view = GetGalCanvas()->GetView(); @@ -950,7 +950,7 @@ void PCB_EDIT_FRAME::SetActiveLayer( LAYER_NUM aLayer, bool doLayerWidgetUpdate { ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer = aLayer; - setHighContrastLayer( aLayer ); + SetHighContrastLayer( aLayer ); if( doLayerWidgetUpdate ) syncLayerWidgetLayer(); diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index f409cc610d..11e527d552 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -112,6 +112,14 @@ TOOL_ACTION COMMON_ACTIONS::zoomOut( "pcbnew.zoomOut", AS_GLOBAL, WXK_F2, "", "" ); +TOOL_ACTION COMMON_ACTIONS::zoomInCenter( "pcbnew.zoomInCenter", + AS_GLOBAL, 0, + "", "" ); + +TOOL_ACTION COMMON_ACTIONS::zoomOutCenter( "pcbnew.zoomOutCenter", + AS_GLOBAL, 0, + "", "" ); + TOOL_ACTION COMMON_ACTIONS::zoomCenter( "pcbnew.zoomCenter", AS_GLOBAL, WXK_F4, "", "" ); @@ -120,6 +128,7 @@ TOOL_ACTION COMMON_ACTIONS::zoomFitScreen( "pcbnew.zoomFitScreen", AS_GLOBAL, WXK_HOME, "", "" ); + // Display modes TOOL_ACTION COMMON_ACTIONS::trackDisplayMode( "pcbnew.trackDisplayMode", AS_GLOBAL, 'K', diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h index c97fa154cf..097400b9c7 100644 --- a/pcbnew/tools/common_actions.h +++ b/pcbnew/tools/common_actions.h @@ -98,6 +98,8 @@ public: // View controls static TOOL_ACTION zoomIn; static TOOL_ACTION zoomOut; + static TOOL_ACTION zoomInCenter; + static TOOL_ACTION zoomOutCenter; static TOOL_ACTION zoomCenter; static TOOL_ACTION zoomFitScreen; diff --git a/pcbnew/tools/pcb_tools.cpp b/pcbnew/tools/pcb_tools.cpp index 45a46a9cdd..4d618615dc 100644 --- a/pcbnew/tools/pcb_tools.cpp +++ b/pcbnew/tools/pcb_tools.cpp @@ -49,6 +49,16 @@ void PCB_EDIT_FRAME::setupTools() m_toolDispatcher = new TOOL_DISPATCHER( &m_toolManager, this ); GetGalCanvas()->SetEventDispatcher( m_toolDispatcher ); + // Connect handlers to toolbar buttons +#if wxCHECK_VERSION( 3, 0, 0 ) + Connect( wxEVT_TOOL, wxCommandEventHandler( PCB_EDIT_FRAME::onGenericCommand ), NULL, this ); +#else + Connect( wxEVT_COMMAND_MENU_SELECTED, + wxCommandEventHandler( PCB_EDIT_FRAME::onGenericCommand ), NULL, this ); + Connect( wxEVT_COMMAND_TOOL_CLICKED, + wxCommandEventHandler( PCB_EDIT_FRAME::onGenericCommand ), NULL, this ); +#endif + // Register tools m_toolManager.RegisterTool( new SELECTION_TOOL ); m_toolManager.RegisterTool( new ROUTER_TOOL ); @@ -75,5 +85,8 @@ void PCB_EDIT_FRAME::destroyTools() void PCB_EDIT_FRAME::onGenericCommand( wxCommandEvent& aEvent ) { - m_toolDispatcher->DispatchWxCommand( aEvent ); + if( IsGalCanvasActive() ) + m_toolDispatcher->DispatchWxCommand( aEvent ); + else + aEvent.Skip(); } diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index c3ffab9c9c..92e29f2ee7 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -28,12 +28,14 @@ #include #include #include +#include #include #include -#include +#include -using namespace KIGFX; -using boost::optional; +#include +#include +#include PCBNEW_CONTROL::PCBNEW_CONTROL() : TOOL_INTERACTIVE( "pcbnew.Settings" ) @@ -41,6 +43,12 @@ PCBNEW_CONTROL::PCBNEW_CONTROL() : } +void PCBNEW_CONTROL::Reset( RESET_REASON aReason ) +{ + m_frame = getEditFrame(); +} + + bool PCBNEW_CONTROL::Init() { setTransitions(); @@ -49,18 +57,40 @@ bool PCBNEW_CONTROL::Init() } -int PCBNEW_CONTROL::ZoomIn( TOOL_EVENT& aEvent ) +int PCBNEW_CONTROL::ZoomInOut( TOOL_EVENT& aEvent ) { - std::cout << __PRETTY_FUNCTION__ << std::endl; + KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); + KIGFX::GAL* gal = m_frame->GetGalCanvas()->GetGAL(); + + if( aEvent.IsAction( &COMMON_ACTIONS::zoomIn ) ) + m_frame->SetPrevZoom(); + else if( aEvent.IsAction( &COMMON_ACTIONS::zoomOut ) ) + m_frame->SetNextZoom(); + + double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); + double zoom = 1.0 / ( zoomFactor * m_frame->GetZoom() ); + + view->SetScale( zoom, getViewControls()->GetCursorPosition() ); setTransitions(); return 0; } -int PCBNEW_CONTROL::ZoomOut( TOOL_EVENT& aEvent ) +int PCBNEW_CONTROL::ZoomInOutCenter( TOOL_EVENT& aEvent ) { - std::cout << __PRETTY_FUNCTION__ << std::endl; + KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); + KIGFX::GAL* gal = m_frame->GetGalCanvas()->GetGAL(); + + if( aEvent.IsAction( &COMMON_ACTIONS::zoomInCenter ) ) + m_frame->SetPrevZoom(); + else if( aEvent.IsAction( &COMMON_ACTIONS::zoomOutCenter ) ) + m_frame->SetNextZoom(); + + double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); + double zoom = 1.0 / ( zoomFactor * m_frame->GetZoom() ); + + view->SetScale( zoom ); setTransitions(); return 0; @@ -69,7 +99,8 @@ int PCBNEW_CONTROL::ZoomOut( TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::ZoomCenter( TOOL_EVENT& aEvent ) { - std::cout << __PRETTY_FUNCTION__ << std::endl; + KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); + view->SetCenter( getViewControls()->GetCursorPosition() ); setTransitions(); return 0; @@ -78,7 +109,24 @@ int PCBNEW_CONTROL::ZoomCenter( TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::ZoomFitScreen( TOOL_EVENT& aEvent ) { - std::cout << __PRETTY_FUNCTION__ << std::endl; + KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); + KIGFX::GAL* gal = m_frame->GetGalCanvas()->GetGAL(); + BOX2I boardBBox = getModel( PCB_T )->ViewBBox(); + VECTOR2I screenSize = gal->GetScreenPixelSize(); + + double iuPerX = screenSize.x ? boardBBox.GetWidth() / screenSize.x : 1.0; + double iuPerY = screenSize.y ? boardBBox.GetHeight() / screenSize.y : 1.0; + + double bestZoom = std::max( iuPerX, iuPerY ); + // This is needed to avoid "jumpy" zooms if first hot key was used and then mouse scroll + // (or other way round). + m_frame->GetScreen()->SetZoom( bestZoom ); + + double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); + double zoom = 1.0 / ( zoomFactor * bestZoom ); + + view->SetScale( zoom ); + view->SetCenter( boardBBox.Centre() ); setTransitions(); return 0; @@ -87,7 +135,20 @@ int PCBNEW_CONTROL::ZoomFitScreen( TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::TrackDisplayMode( TOOL_EVENT& aEvent ) { - std::cout << __PRETTY_FUNCTION__ << std::endl; + KIGFX::PCB_PAINTER* painter = + static_cast( m_frame->GetGalCanvas()->GetView()->GetPainter() ); + KIGFX::PCB_RENDER_SETTINGS* settings = + static_cast ( painter->GetSettings() ); + + // Apply new display options to the GAL canvas + DisplayOpt.DisplayPcbTrackFill = !DisplayOpt.DisplayPcbTrackFill; + m_frame->m_DisplayPcbTrackFill = DisplayOpt.DisplayPcbTrackFill; + settings->LoadDisplayOptions( DisplayOpt ); + + BOARD* board = getModel( PCB_T ); + for( TRACK* track = board->m_Track; track; track = track->Next() ) + track->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); + setTransitions(); return 0; @@ -106,7 +167,23 @@ int PCBNEW_CONTROL::PadDisplayMode( TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::ViaDisplayMode( TOOL_EVENT& aEvent ) { - std::cout << __PRETTY_FUNCTION__ << std::endl; + KIGFX::PCB_PAINTER* painter = + static_cast( m_frame->GetGalCanvas()->GetView()->GetPainter() ); + KIGFX::PCB_RENDER_SETTINGS* settings = + static_cast ( painter->GetSettings() ); + + // Apply new display options to the GAL canvas + DisplayOpt.DisplayViaFill = !DisplayOpt.DisplayViaFill; + m_frame->m_DisplayViaFill = DisplayOpt.DisplayViaFill; + settings->LoadDisplayOptions( DisplayOpt ); + + BOARD* board = getModel( PCB_T ); + for( TRACK* track = board->m_Track; track; track = track->Next() ) + { + if( track->Type() == PCB_VIA_T ) + track->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); + } + setTransitions(); return 0; @@ -115,7 +192,15 @@ int PCBNEW_CONTROL::ViaDisplayMode( TOOL_EVENT& aEvent ) int PCBNEW_CONTROL::HighContrastMode( TOOL_EVENT& aEvent ) { - std::cout << __PRETTY_FUNCTION__ << std::endl; + KIGFX::PCB_PAINTER* painter = + static_cast( m_frame->GetGalCanvas()->GetView()->GetPainter() ); + KIGFX::PCB_RENDER_SETTINGS* settings = + static_cast ( painter->GetSettings() ); + + DisplayOpt.ContrastModeDisplay = !DisplayOpt.ContrastModeDisplay; + settings->LoadDisplayOptions( DisplayOpt ); + m_frame->SetHighContrastLayer( m_frame->GetActiveLayer() ); + setTransitions(); return 0; @@ -412,8 +497,10 @@ int PCBNEW_CONTROL::ShowHelp( TOOL_EVENT& aEvent ) void PCBNEW_CONTROL::setTransitions() { // View controls - Go( &PCBNEW_CONTROL::ZoomIn, COMMON_ACTIONS::zoomIn.MakeEvent() ); - Go( &PCBNEW_CONTROL::ZoomOut, COMMON_ACTIONS::zoomOut.MakeEvent() ); + Go( &PCBNEW_CONTROL::ZoomInOut, COMMON_ACTIONS::zoomIn.MakeEvent() ); + Go( &PCBNEW_CONTROL::ZoomInOut, COMMON_ACTIONS::zoomOut.MakeEvent() ); + Go( &PCBNEW_CONTROL::ZoomInOutCenter, COMMON_ACTIONS::zoomInCenter.MakeEvent() ); + Go( &PCBNEW_CONTROL::ZoomInOutCenter, COMMON_ACTIONS::zoomOutCenter.MakeEvent() ); Go( &PCBNEW_CONTROL::ZoomCenter, COMMON_ACTIONS::zoomCenter.MakeEvent() ); Go( &PCBNEW_CONTROL::ZoomFitScreen, COMMON_ACTIONS::zoomFitScreen.MakeEvent() ); diff --git a/pcbnew/tools/pcbnew_control.h b/pcbnew/tools/pcbnew_control.h index 41861cd3c0..8acc0fba8c 100644 --- a/pcbnew/tools/pcbnew_control.h +++ b/pcbnew/tools/pcbnew_control.h @@ -27,10 +27,12 @@ #include +class PCB_EDIT_FRAME; + /** * Class PCBNEW_CONTROL * - * TODO + * Handles hot keys that are not accepted by any other tool. */ class PCBNEW_CONTROL : public TOOL_INTERACTIVE @@ -39,14 +41,14 @@ public: PCBNEW_CONTROL(); /// @copydoc TOOL_INTERACTIVE::Reset() - void Reset( RESET_REASON aReason ) {}; + void Reset( RESET_REASON aReason ); /// @copydoc TOOL_INTERACTIVE::Init() bool Init(); // View controls - int ZoomIn( TOOL_EVENT& aEvent ); - int ZoomOut( TOOL_EVENT& aEvent ); + int ZoomInOut( TOOL_EVENT& aEvent ); + int ZoomInOutCenter( TOOL_EVENT& aEvent ); int ZoomCenter( TOOL_EVENT& aEvent ); int ZoomFitScreen( TOOL_EVENT& aEvent ); @@ -92,6 +94,9 @@ public: private: ///> Sets up handlers for various events. void setTransitions(); + + ///> Pointerto the currently used edit frame. + PCB_EDIT_FRAME* m_frame; }; #endif