From 595666d46ecefbe242bd6ddf8432ce1ab3bf26fd Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sat, 11 Aug 2018 08:25:09 +0200 Subject: [PATCH] Add support of GAL in FOOTPRINT_WIZARD_FRAME. Some refinements are needed (for instance the context menu shows the filter command if something is selected, that is useless in the footprint wizard. --- pcbnew/footprint_wizard_frame.cpp | 110 +++++++++++++++++++- pcbnew/footprint_wizard_frame.h | 34 ++++-- pcbnew/footprint_wizard_frame_functions.cpp | 3 +- pcbnew/hotkeys.cpp | 88 ++++++++++++++++ 4 files changed, 224 insertions(+), 11 deletions(-) diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp index 2ea5ccde7a..bb8ba6b7fb 100644 --- a/pcbnew/footprint_wizard_frame.cpp +++ b/pcbnew/footprint_wizard_frame.cpp @@ -2,9 +2,9 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012-2015 Miguel Angel Ajo Pelayo - * Copyright (C) 2012-2017 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2012-2018 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008-2015 Wayne Stambaugh - * Copyright (C) 2004-2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2004-2018 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 @@ -30,7 +30,9 @@ #include #include +#include #include +#include #include #include #include <3d_viewer/eda_3d_viewer.h> @@ -56,6 +58,14 @@ #include #include +#include +#include +#include +#include "tools/selection_tool.h" +#include "tools/pcbnew_control.h" +#include "tools/pcb_actions.h" + + BEGIN_EVENT_TABLE( FOOTPRINT_WIZARD_FRAME, EDA_DRAW_FRAME ) // Window events @@ -142,8 +152,23 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( KIWAY* aKiway, // Set some display options here, because the FOOTPRINT_WIZARD_FRAME // does not have a config menu to do that: + + // the footprint wizard frame has no config menu. so use some settings + // from the caller, or force some options: + PCB_BASE_FRAME* caller = dynamic_cast( aParent ); + + if( caller ) + { + SetUserUnits( caller->GetUserUnits() ); + } + auto disp_opts = (PCB_DISPLAY_OPTIONS*)GetDisplayOptions(); - disp_opts->m_DisplayPadIsol = false; + // In viewer, the default net clearance is not known (it depends on the actual board). + // So we do not show the default clearance, by setting it to 0 + // The footprint or pad specific clearance will be shown + GetBoard()->GetDesignSettings().GetDefault()->SetClearance(0); + + disp_opts->m_DisplayPadIsol = true; disp_opts->m_DisplayPadNum = true; GetBoard()->SetElementVisibility( LAYER_NO_CONNECTS, false ); @@ -151,7 +176,13 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( KIWAY* aKiway, ReCreateHToolbar(); ReCreateVToolbar(); - SetActiveLayer( F_Cu ); + + // Create GAL canvas + EDA_DRAW_PANEL_GAL::GAL_TYPE backend = EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO; + //EDA_DRAW_PANEL_GAL::GAL_TYPE backend = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE; + PCB_DRAW_PANEL_GAL* gal_drawPanel = new PCB_DRAW_PANEL_GAL( this, -1, wxPoint( 0, 0 ), m_FrameSize, + GetGalDisplayOptions(), backend ); + SetGalCanvas( gal_drawPanel ); // Create the parameters panel m_parametersPanel = new wxPanel( this, wxID_ANY ); @@ -196,6 +227,34 @@ FOOTPRINT_WIZARD_FRAME::FOOTPRINT_WIZARD_FRAME( KIWAY* aKiway, m_auimgr.AddPane( m_canvas, EDA_PANE().Canvas().Name( "DrawFrame" ).Center() ); + m_auimgr.AddPane( (wxWindow*) GetGalCanvas(), + wxAuiPaneInfo().Name( "DrawFrameGal" ).CentrePane().Hide() ); + + // Create the manager and dispatcher & route draw panel events to the dispatcher + m_toolManager = new TOOL_MANAGER; + m_toolManager->SetEnvironment( GetBoard(), gal_drawPanel->GetView(), + gal_drawPanel->GetViewControls(), this ); + m_actions = new PCB_ACTIONS(); + m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager, m_actions ); + gal_drawPanel->SetEventDispatcher( m_toolDispatcher ); + + m_toolManager->RegisterTool( new PCBNEW_CONTROL ); + m_toolManager->RegisterTool( new SELECTION_TOOL ); // for std context menus (zoom & grid) + m_toolManager->RegisterTool( new COMMON_TOOLS ); + m_toolManager->InitTools(); + + // Run the control tool, it is supposed to be always active + m_toolManager->InvokeTool( "pcbnew.InteractiveSelection" ); + + auto& galOpts = GetGalDisplayOptions(); + galOpts.m_fullscreenCursor = true; + galOpts.m_forceDisplayCursor = true; + galOpts.m_axesEnabled = true; + + UseGalCanvas( backend != EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE ); + updateView(); + + SetActiveLayer( F_Cu ); // Now Drawpanel is sized, we can use BestZoom to show the component (if any) #ifdef USE_WX_GRAPHICS_CONTEXT GetScreen()->SetScalingFactor( BestZoom() ); @@ -217,10 +276,23 @@ FOOTPRINT_WIZARD_FRAME::~FOOTPRINT_WIZARD_FRAME() // Delete the GRID_TRICKS. m_parameterGrid->PopEventHandler( true ); + if( IsGalCanvasActive() ) + { + GetGalCanvas()->StopDrawing(); + // Be sure any event cannot be fired after frame deletion: + GetGalCanvas()->SetEvtHandlerEnabled( false ); + } + + // Be sure a active tool (if exists) is desactivated: + if( m_toolManager ) + m_toolManager->DeactivateTool(); + EDA_3D_VIEWER* draw3DFrame = Get3DViewerFrame(); if( draw3DFrame ) draw3DFrame->Destroy(); + + // Now this frame can be deleted } @@ -274,6 +346,36 @@ void FOOTPRINT_WIZARD_FRAME::OnSetRelativeOffset( wxCommandEvent& event ) } +void FOOTPRINT_WIZARD_FRAME::updateView() +{ + if( IsGalCanvasActive() ) + { + auto dp = static_cast( GetGalCanvas() ); + dp->UseColorScheme( &Settings().Colors() ); + dp->DisplayBoard( GetBoard() ); + m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD ); + m_toolManager->RunAction( ACTIONS::zoomFitScreen, true ); + UpdateMsgPanel(); + } +} + + +void FOOTPRINT_WIZARD_FRAME::UpdateMsgPanel() +{ + BOARD_ITEM* footprint = GetBoard()->m_Modules; + + if( footprint ) + { + MSG_PANEL_ITEMS items; + + footprint->GetMsgPanelInfo( m_UserUnits, items ); + SetMsgPanel( items ); + } + else + ClearMsgPanel(); +} + + void FOOTPRINT_WIZARD_FRAME::initParameterGrid() { m_parameterGridPage = -1; diff --git a/pcbnew/footprint_wizard_frame.h b/pcbnew/footprint_wizard_frame.h index 1edc35675a..dab8cc4927 100644 --- a/pcbnew/footprint_wizard_frame.h +++ b/pcbnew/footprint_wizard_frame.h @@ -2,8 +2,8 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012 Miguel Angel Ajo Pelayo, miguelangel@nbee.es - * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2004-2017 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr + * Copyright (C) 2004-2018 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 @@ -86,9 +86,21 @@ public: private: void OnSize( wxSizeEvent& event ) override; - void OnGridSize( wxSizeEvent& aSizeEvent ); + /** + * redraws the message panel. + * display the current footprint info, or + * clear the message panel if nothing is loaded + */ + void UpdateMsgPanel() override; + + /** + * rebuild the GAL view (reint tool manager, colors and drawings) + * must be run after any footprint change. + */ + void updateView(); + /** * Function ExportSelectedFootprint(); * will let the caller exit from the wait loop, and get the built footprint @@ -171,12 +183,22 @@ private: bool GeneralControl( wxDC* aDC, const wxPoint& aPosition, EDA_KEY aHotKey = 0 ) override; + ///> @copydoc EDA_DRAW_FRAME::GetHotKeyDescription() + EDA_HOTKEY* GetHotKeyDescription( int aCommand ) const override; + + /** + * Function OnHotKey + * handle hot key events. + * + */ + bool OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem = NULL ) override; + void LoadSettings( wxConfigBase* aCfg ) override; void SaveSettings( wxConfigBase* aCfg ) override; - ///> @copydoc EDA_DRAW_FRAME::GetHotKeyDescription() - EDA_HOTKEY* GetHotKeyDescription( int aCommand ) const override { return NULL; } - /** * Function OnActivate * is called when the frame frame is activate to reload the libraries and component lists diff --git a/pcbnew/footprint_wizard_frame_functions.cpp b/pcbnew/footprint_wizard_frame_functions.cpp index d3ae1a4e12..c9f519e172 100644 --- a/pcbnew/footprint_wizard_frame_functions.cpp +++ b/pcbnew/footprint_wizard_frame_functions.cpp @@ -140,6 +140,7 @@ void FOOTPRINT_WIZARD_FRAME::ReloadFootprint() DBG(printf( "footprintWizard->GetFootprint() returns NULL\n" );) } + updateView(); m_canvas->Refresh(); } @@ -217,6 +218,7 @@ void FOOTPRINT_WIZARD_FRAME::SelectFootprintWizard() void FOOTPRINT_WIZARD_FRAME::SelectCurrentWizard( wxCommandEvent& event ) { SelectFootprintWizard(); + updateView(); } void FOOTPRINT_WIZARD_FRAME::DefaultParameters( wxCommandEvent& event ) @@ -232,7 +234,6 @@ void FOOTPRINT_WIZARD_FRAME::DefaultParameters( wxCommandEvent& event ) ReCreateParameterList(); ReloadFootprint(); DisplayWizardInfos(); - } diff --git a/pcbnew/hotkeys.cpp b/pcbnew/hotkeys.cpp index 32fcc31925..b717e6348c 100644 --- a/pcbnew/hotkeys.cpp +++ b/pcbnew/hotkeys.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -626,3 +627,90 @@ bool FOOTPRINT_VIEWER_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aP return true; } + + + +EDA_HOTKEY* FOOTPRINT_WIZARD_FRAME::GetHotKeyDescription( int aCommand ) const +{ + EDA_HOTKEY* HK_Descr = GetDescriptorFromCommand( aCommand, common_Hotkey_List ); + + return HK_Descr; +} + + +bool FOOTPRINT_WIZARD_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, + EDA_ITEM* aItem ) +{ + if( aHotKey == 0 ) + return false; + + wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); + cmd.SetEventObject( this ); + + /* Convert lower to upper case (the usual toupper function has problem with non ascii + * codes like function keys */ + if( (aHotKey >= 'a') && (aHotKey <= 'z') ) + aHotKey += 'A' - 'a'; + + EDA_HOTKEY* HK_Descr = GetDescriptorFromHotkey( aHotKey, common_Hotkey_List ); + + if( HK_Descr == NULL ) + return false; + + switch( HK_Descr->m_Idcommand ) + { + default: + case HK_NOT_FOUND: + return false; + + case HK_HELP: // Display Current hotkey list + DisplayHotkeyList( this, g_Module_Viewer_Hotkeys_Descr ); + break; + + case HK_RESET_LOCAL_COORD: // set local (relative) coordinate origin + GetScreen()->m_O_Curseur = GetCrossHairPosition(); + break; + + case HK_LEFT_CLICK: + OnLeftClick( aDC, aPosition ); + break; + + case HK_LEFT_DCLICK: // Simulate a double left click: generate 2 events + OnLeftClick( aDC, aPosition ); + OnLeftDClick( aDC, aPosition ); + break; + + case HK_SWITCH_UNITS: + cmd.SetId( (GetUserUnits() == INCHES) ? + ID_TB_OPTIONS_SELECT_UNIT_MM : ID_TB_OPTIONS_SELECT_UNIT_INCH ); + GetEventHandler()->ProcessEvent( cmd ); + break; + + case HK_ZOOM_IN: + cmd.SetId( ID_KEY_ZOOM_IN ); + GetEventHandler()->ProcessEvent( cmd ); + break; + + case HK_ZOOM_OUT: + cmd.SetId( ID_KEY_ZOOM_OUT ); + GetEventHandler()->ProcessEvent( cmd ); + break; + + case HK_ZOOM_REDRAW: + cmd.SetId( ID_ZOOM_REDRAW ); + GetEventHandler()->ProcessEvent( cmd ); + break; + + case HK_ZOOM_CENTER: + cmd.SetId( ID_POPUP_ZOOM_CENTER ); + GetEventHandler()->ProcessEvent( cmd ); + break; + + case HK_ZOOM_AUTO: + cmd.SetId( ID_ZOOM_PAGE ); + GetEventHandler()->ProcessEvent( cmd ); + break; + } + + return true; +}