Cvpcb, DISPLAY_FOOTPRINTS_FRAME: add measurement and zoom to selection tools.

This commit is contained in:
jean-pierre charras 2018-08-08 21:23:31 +02:00
parent 274572bf20
commit 3eb3db02c3
7 changed files with 90 additions and 34 deletions

View File

@ -71,7 +71,7 @@ struct TOOL_MANAGER::TOOL_STATE
~TOOL_STATE()
{
assert( stateStack.empty() );
wxASSERT( stateStack.empty() );
}
/// The tool itself
@ -509,7 +509,7 @@ OPT<TOOL_EVENT> TOOL_MANAGER::ScheduleWait( TOOL_BASE* aTool, const TOOL_EVENT_L
{
TOOL_STATE* st = m_toolState[aTool];
assert( !st->pendingWait ); // everything collapses on two KiYield() in a row
wxASSERT( !st->pendingWait ); // everything collapses on two KiYield() in a row
// indicate to the manager that we are going to sleep and we shall be
// woken up when an event matching aConditions arrive

View File

@ -68,6 +68,10 @@ BEGIN_EVENT_TABLE( DISPLAY_FOOTPRINTS_FRAME, PCB_BASE_FRAME )
EVT_TOOL( ID_OPTIONS_SETUP, DISPLAY_FOOTPRINTS_FRAME::InstallOptionsDisplay )
EVT_TOOL( ID_CVPCB_SHOW3D_FRAME, DISPLAY_FOOTPRINTS_FRAME::Show3D_Frame )
EVT_UPDATE_UI( ID_NO_TOOL_SELECTED, DISPLAY_FOOTPRINTS_FRAME::OnUIToolSelection )
EVT_UPDATE_UI( ID_TB_MEASUREMENT_TOOL, DISPLAY_FOOTPRINTS_FRAME::OnUIToolSelection )
EVT_UPDATE_UI( ID_ZOOM_SELECTION, DISPLAY_FOOTPRINTS_FRAME::OnUIToolSelection )
/*
EVT_TOOL and EVT_UPDATE_UI for:
ID_TB_OPTIONS_SHOW_MODULE_TEXT_SKETCH,
@ -184,7 +188,16 @@ DISPLAY_FOOTPRINTS_FRAME::DISPLAY_FOOTPRINTS_FRAME( KIWAY* aKiway, wxWindow* aPa
DISPLAY_FOOTPRINTS_FRAME::~DISPLAY_FOOTPRINTS_FRAME()
{
if( IsGalCanvasActive() )
{
GetGalCanvas()->StopDrawing();
GetGalCanvas()->GetView()->Clear();
// 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();
delete GetScreen();
SetScreen( NULL ); // Be sure there is no double deletion
@ -193,8 +206,7 @@ DISPLAY_FOOTPRINTS_FRAME::~DISPLAY_FOOTPRINTS_FRAME()
void DISPLAY_FOOTPRINTS_FRAME::OnCloseWindow( wxCloseEvent& event )
{
// Currently, do nothing
event.Skip();
Destroy();
}
@ -214,43 +226,57 @@ void DISPLAY_FOOTPRINTS_FRAME::ReCreateOptToolbar()
m_optionsToolBar = new wxAuiToolBar( this, ID_OPT_TOOLBAR, wxDefaultPosition, wxDefaultSize,
KICAD_AUI_TB_STYLE | wxAUI_TB_VERTICAL );
m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_GRID, wxEmptyString, KiBitmap( grid_xpm ),
// 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->AddTool( ID_NO_TOOL_SELECTED, wxEmptyString,
KiScaledBitmap( cursor_xpm, this ),
wxEmptyString, wxITEM_CHECK );
m_optionsToolBar->AddTool( ID_TB_MEASUREMENT_TOOL, wxEmptyString,
KiScaledBitmap( measurement_xpm, this ),
_( "Measure distance between two points" ),
wxITEM_CHECK );
KiScaledSeparator( m_optionsToolBar, this );
m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_GRID, wxEmptyString, KiScaledBitmap( grid_xpm, this ),
_( "Hide grid" ), wxITEM_CHECK );
m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_POLAR_COORD, wxEmptyString,
KiBitmap( polar_coord_xpm ),
KiScaledBitmap( polar_coord_xpm, this ),
_( "Display polar coordinates" ), wxITEM_CHECK );
m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_INCH, wxEmptyString,
KiBitmap( unit_inch_xpm ),
KiScaledBitmap( unit_inch_xpm, this ),
_( "Set units to inches" ), wxITEM_CHECK );
m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_UNIT_MM, wxEmptyString,
KiBitmap( unit_mm_xpm ),
KiScaledBitmap( unit_mm_xpm, this ),
_( "Set units to millimeters" ), wxITEM_CHECK );
#ifndef __APPLE__
m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_CURSOR, wxEmptyString,
KiBitmap( cursor_shape_xpm ),
KiScaledBitmap( cursor_shape_xpm, this ),
_( "Change cursor shape" ), wxITEM_CHECK );
#else
m_optionsToolBar->AddTool( ID_TB_OPTIONS_SELECT_CURSOR, wxEmptyString,
KiBitmap( cursor_shape_xpm ),
KiScaledBitmap( cursor_shape_xpm, this ),
_( "Change cursor shape (not supported in Legacy Toolset)" ),
wxITEM_CHECK );
#endif
m_optionsToolBar->AddSeparator();
m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_PADS_SKETCH, wxEmptyString,
KiBitmap( pad_sketch_xpm ),
KiScaledBitmap( pad_sketch_xpm, this ),
_( "Show pads in outline mode" ), wxITEM_CHECK );
m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_MODULE_TEXT_SKETCH, wxEmptyString,
KiBitmap( text_sketch_xpm ),
KiScaledBitmap( text_sketch_xpm, this ),
_( "Show texts in line mode" ), wxITEM_CHECK );
m_optionsToolBar->AddTool( ID_TB_OPTIONS_SHOW_MODULE_EDGE_SKETCH, wxEmptyString,
KiBitmap( show_mod_edge_xpm ),
KiScaledBitmap( show_mod_edge_xpm, this ),
_( "Show outlines in line mode" ), wxITEM_CHECK );
m_optionsToolBar->Realize();
@ -265,25 +291,28 @@ void DISPLAY_FOOTPRINTS_FRAME::ReCreateHToolbar()
m_mainToolBar = new wxAuiToolBar( this, ID_H_TOOLBAR, wxDefaultPosition, wxDefaultSize,
KICAD_AUI_TB_STYLE | wxAUI_TB_HORZ_LAYOUT );
m_mainToolBar->AddTool( ID_OPTIONS_SETUP, wxEmptyString, KiBitmap( display_options_xpm ),
m_mainToolBar->AddTool( ID_OPTIONS_SETUP, wxEmptyString, KiScaledBitmap( display_options_xpm, this ),
_( "Display options" ) );
m_mainToolBar->AddSeparator();
m_mainToolBar->AddTool( ID_ZOOM_IN, wxEmptyString, KiBitmap( zoom_in_xpm ),
m_mainToolBar->AddTool( ID_ZOOM_IN, wxEmptyString, KiScaledBitmap( zoom_in_xpm, this ),
_( "Zoom in (F1)" ) );
m_mainToolBar->AddTool( ID_ZOOM_OUT, wxEmptyString, KiBitmap( zoom_out_xpm ),
m_mainToolBar->AddTool( ID_ZOOM_OUT, wxEmptyString, KiScaledBitmap( zoom_out_xpm, this ),
_( "Zoom out (F2)" ) );
m_mainToolBar->AddTool( ID_ZOOM_REDRAW, wxEmptyString, KiBitmap( zoom_redraw_xpm ),
m_mainToolBar->AddTool( ID_ZOOM_REDRAW, wxEmptyString, KiScaledBitmap( zoom_redraw_xpm, this ),
_( "Redraw view (F3)" ) );
m_mainToolBar->AddTool( ID_ZOOM_PAGE, wxEmptyString, KiBitmap( zoom_fit_in_page_xpm ),
m_mainToolBar->AddTool( ID_ZOOM_PAGE, wxEmptyString, KiScaledBitmap( zoom_fit_in_page_xpm, this ),
_( "Zoom to fit footprint (Home)" ) );
m_mainToolBar->AddTool( ID_ZOOM_SELECTION, wxEmptyString, KiScaledBitmap( zoom_area_xpm, this ),
_( "Zoom to selection" ), wxITEM_CHECK );
m_mainToolBar->AddSeparator();
m_mainToolBar->AddTool( ID_CVPCB_SHOW3D_FRAME, wxEmptyString, KiBitmap( three_d_xpm ),
m_mainToolBar->AddTool( ID_CVPCB_SHOW3D_FRAME, wxEmptyString, KiScaledBitmap( three_d_xpm, this ),
_( "3D Display (Alt+3)" ) );
// after adding the buttons to the toolbar, must call Realize() to reflect
@ -559,6 +588,28 @@ void DISPLAY_FOOTPRINTS_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
}
void DISPLAY_FOOTPRINTS_FRAME::OnUIToolSelection( wxUpdateUIEvent& aEvent )
{
switch( aEvent.GetId() )
{
case ID_TB_MEASUREMENT_TOOL:
aEvent.Check( GetToolId() == ID_TB_MEASUREMENT_TOOL );
break;
case ID_NO_TOOL_SELECTED:
aEvent.Check( GetToolId() == ID_NO_TOOL_SELECTED );
break;
case ID_ZOOM_SELECTION:
aEvent.Check( GetToolId() == ID_ZOOM_SELECTION );
break;
default:
break;
}
}
/*
* Redraw the BOARD items but not cursors, axis or grid.
*/

View File

@ -48,6 +48,10 @@ public:
void OnCloseWindow( wxCloseEvent& Event ) override;
/** UI events:
*/
void OnUIToolSelection( wxUpdateUIEvent& aEvent );
/*
* Draws the current highlighted footprint.
*/

View File

@ -40,6 +40,7 @@ void CVPCB_ACTIONS::RegisterAllTools( TOOL_MANAGER* aToolManager )
aToolManager->RegisterTool( new CVPCB_CONTROL );
}
OPT<TOOL_EVENT> CVPCB_ACTIONS::TranslateLegacyId( int aId )
{
switch( aId )
@ -59,6 +60,11 @@ OPT<TOOL_EVENT> CVPCB_ACTIONS::TranslateLegacyId( int aId )
case ID_ZOOM_SELECTION:
return ACTIONS::zoomTool.MakeEvent();
case ID_TB_MEASUREMENT_TOOL:
return CVPCB_ACTIONS::measureTool.MakeEvent();
case ID_NO_TOOL_SELECTED:
return CVPCB_ACTIONS::no_selectionTool.MakeEvent();
}
return OPT<TOOL_EVENT>();

View File

@ -46,6 +46,8 @@ public:
/// Activation of the selection tool
static TOOL_ACTION selectionActivate;
/// Tool selection
static TOOL_ACTION no_selectionTool;
static TOOL_ACTION measureTool;
/// Cursor control with keyboard

View File

@ -36,9 +36,7 @@
#include <cvpcb_id.h>
#include <tool/tool_manager.h>
//#include <gal/graphics_abstraction_layer.h>
#include <view/view_controls.h>
//#include <pcb_painter.h>
#include <tools/grid_helper.h> // from pcbnew
#include <functional>
@ -89,6 +87,12 @@ TOOL_ACTION CVPCB_ACTIONS::switchUnits( "cvpcb.Control.switchUnits",
AS_GLOBAL, 'U',//TOOL_ACTION::LegacyHotKey( HK_SWITCH_UNITS ),
"", "" );
TOOL_ACTION CVPCB_ACTIONS::no_selectionTool( "cvpcb.Control.no_selectionTool",
AS_GLOBAL, ESC,
"", "", NULL, AF_ACTIVATE );
///////////////
CVPCB_CONTROL::CVPCB_CONTROL() :
TOOL_INTERACTIVE( "cvpcb.Control" ), m_frame( NULL )
{
@ -276,13 +280,3 @@ void CVPCB_CONTROL::setTransitions()
Go( &CVPCB_CONTROL::SwitchCursor, CVPCB_ACTIONS::switchCursor.MakeEvent() );
Go( &CVPCB_CONTROL::SwitchUnits, CVPCB_ACTIONS::switchUnits.MakeEvent() );
}
/*
void CVPCB_CONTROL::updateGrid()
{
BASE_SCREEN* screen = m_frame->GetScreen();
//GRID_TYPE grid = screen->GetGrid( idx );
getView()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGridSize() ) );
getView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
}
*/

View File

@ -136,7 +136,7 @@ void CVPCB_SELECTION_TOOL::setTransitions()
Go( &CVPCB_SELECTION_TOOL::MeasureTool, CVPCB_ACTIONS::measureTool.MakeEvent() );
}
/*
void CVPCB_SELECTION_TOOL::zoomFitSelection( void )
{
//Should recalculate the view to zoom in on the selection
@ -158,7 +158,7 @@ void CVPCB_SELECTION_TOOL::zoomFitSelection( void )
m_frame->GetGalCanvas()->ForceRefresh();
}
*/
int CVPCB_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
{
@ -254,7 +254,6 @@ int CVPCB_SELECTION_TOOL::MeasureTool( const TOOL_EVENT& aEvent )
return 0;
}
const BOX2I SELECTION::ViewBBox() const
{
EDA_RECT eda_bbox;