Zoom & grid menu for GAL.

This commit is contained in:
Maciej Suminski 2015-04-30 10:58:57 +02:00
commit f261bf3878
44 changed files with 681 additions and 727 deletions

View File

@ -31,6 +31,8 @@ install_manifest.txt
Documentation/doxygen
Documentation/development/doxygen
*.bak
.*.swp
*.~*
common/pcb_plot_params_keywords.cpp
include/pcb_plot_params_lexer.h
pcbnew/specctra_keywords.cpp

View File

@ -56,9 +56,14 @@ set( GAL_SRCS
add_library( gal STATIC ${GAL_SRCS} )
add_dependencies( gal shader_headers )
add_dependencies( gal lib-dependencies )
add_dependencies( shader_headers lib-dependencies )
target_link_libraries( gal
${GLEW_LIBRARIES}
${CAIRO_LIBRARIES}
${PIXMAN_LIBRARY}
${OPENGL_LIBRARIES}
)
# Only for win32 cross compilation using MXE
@ -247,7 +252,7 @@ set( COMMON_SRCS
)
add_library( common STATIC ${COMMON_SRCS} )
add_dependencies( common lib-dependencies )
target_link_libraries( common ${Boost_LIBRARIES} )
set( PCB_COMMON_SRCS
base_screen.cpp

View File

@ -51,6 +51,8 @@
#include <view/view.h>
#include <view/view_controls.h>
#include <gal/graphics_abstraction_layer.h>
#include <tool/tool_manager.h>
#include <tool/tool_dispatcher.h>
/**
* Definition for enabling and disabling scroll bar setting trace output. See the
@ -110,6 +112,8 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent,
m_canvas = NULL;
m_galCanvas = NULL;
m_galCanvasActive = false;
m_toolManager = NULL;
m_toolDispatcher = NULL;
m_messagePanel = NULL;
m_currentScreen = NULL;
m_toolId = ID_NO_TOOL_SELECTED;
@ -180,6 +184,10 @@ EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent,
EDA_DRAW_FRAME::~EDA_DRAW_FRAME()
{
delete m_toolManager;
delete m_toolDispatcher;
delete m_galCanvas;
delete m_currentScreen;
m_currentScreen = NULL;
@ -379,47 +387,17 @@ void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
else
{
eventId = event.GetId();
/* Update the grid select combobox if the grid size was changed
* by menu event.
*/
if( m_gridSelectBox != NULL )
{
for( size_t i = 0; i < m_gridSelectBox->GetCount(); i++ )
{
clientData = (int*) m_gridSelectBox->wxItemContainer::GetClientData( i );
if( clientData && eventId == *clientData )
{
m_gridSelectBox->SetSelection( i );
break;
}
}
}
}
// Be sure m_LastGridSizeId is up to date.
m_LastGridSizeId = eventId - ID_POPUP_GRID_LEVEL_1000;
int idx = eventId - ID_POPUP_GRID_LEVEL_1000;
BASE_SCREEN* screen = GetScreen();
// Notify GAL
TOOL_MANAGER* mgr = GetToolManager();
if( screen->GetGridId() == eventId )
return;
/*
* This allows for saving non-sequential command ID offsets used that
* may be used in the grid size combobox. Do not use the selection
* index returned by GetSelection().
*/
screen->SetGrid( eventId );
SetCrossHairPosition( RefPos( true ) );
if( IsGalCanvasActive() )
{
GetGalCanvas()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGrid().m_Size.x,
screen->GetGrid().m_Size.y ) );
GetGalCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
}
if( mgr && IsGalCanvasActive() )
mgr->RunAction( "common.Control.gridPreset", true, idx );
else
SetPresetGrid( idx );
m_canvas->Refresh();
}
@ -448,22 +426,14 @@ void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
return;
GetScreen()->SetZoom( selectedZoom );
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() );
view->SetScale( zoom );
GetGalCanvas()->Refresh();
}
else
RedrawScreen( GetScrollCenterPosition(), false );
RedrawScreen( GetScrollCenterPosition(), false );
}
// Notify GAL
TOOL_MANAGER* mgr = GetToolManager();
if( mgr && IsGalCanvasActive() )
mgr->RunAction( "common.Control.zoomPreset", true, id );
}
@ -557,14 +527,7 @@ wxPoint EDA_DRAW_FRAME::GetGridPosition( const wxPoint& aPosition ) const
void EDA_DRAW_FRAME::SetNextGrid()
{
if( m_gridSelectBox )
{
m_gridSelectBox->SetSelection( ( m_gridSelectBox->GetSelection() + 1 ) %
m_gridSelectBox->GetCount() );
wxCommandEvent cmd( wxEVT_COMMAND_COMBOBOX_SELECTED );
// cmd.SetEventObject( this );
OnSelectGrid( cmd );
}
SetPresetGrid( ( m_gridSelectBox->GetSelection() + 1 ) % m_gridSelectBox->GetCount() );
}
@ -572,20 +535,34 @@ void EDA_DRAW_FRAME::SetPrevGrid()
{
if( m_gridSelectBox )
{
int cnt = m_gridSelectBox->GetSelection();
int idx = m_gridSelectBox->GetSelection();
if( --cnt < 0 )
cnt = m_gridSelectBox->GetCount() - 1;
if( --idx < 0 )
idx = m_gridSelectBox->GetCount() - 1;
m_gridSelectBox->SetSelection( cnt );
wxCommandEvent cmd( wxEVT_COMMAND_COMBOBOX_SELECTED );
// cmd.SetEventObject( this );
OnSelectGrid( cmd );
SetPresetGrid( idx );
}
}
void EDA_DRAW_FRAME::SetPresetGrid( int aIndex )
{
if( aIndex < 0 || aIndex >= (int) m_gridSelectBox->GetCount() )
{
wxASSERT_MSG( false, "Invalid grid index" );
return;
}
if( m_gridSelectBox )
m_gridSelectBox->SetSelection( aIndex );
// Be sure m_LastGridSizeId is up to date.
m_LastGridSizeId = aIndex;
GetScreen()->SetGrid( aIndex + ID_POPUP_GRID_LEVEL_1000 );
SetCrossHairPosition( RefPos( true ) );
}
int EDA_DRAW_FRAME::BlockCommand( int key )
{
return 0;
@ -1018,38 +995,29 @@ void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable )
KIGFX::GAL* gal = GetGalCanvas()->GetGAL();
double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor();
BASE_SCREEN* screen = GetScreen();
// Display the same view after canvas switching
if( aEnable )
if( aEnable ) // Switch to GAL rendering
{
BASE_SCREEN* screen = GetScreen();
// Switch to GAL rendering
if( !IsGalCanvasActive() )
{
// Set up viewport
double zoom = 1.0 / ( zoomFactor * m_canvas->GetZoom() );
view->SetScale( zoom );
view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) );
}
// Set up viewport
double zoom = 1.0 / ( zoomFactor * m_canvas->GetZoom() );
view->SetScale( zoom );
view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) );
// Set up grid settings
gal->SetGridVisibility( IsGridVisible() );
gal->SetGridSize( VECTOR2D( screen->GetGridSize().x, screen->GetGridSize().y ) );
gal->SetGridSize( VECTOR2D( screen->GetGridSize() ) );
gal->SetGridOrigin( VECTOR2D( GetGridOrigin() ) );
}
else
else // Switch to standard rendering
{
// Switch to standard rendering
if( IsGalCanvasActive() )
{
// Change view settings only if GAL was active previously
double zoom = 1.0 / ( zoomFactor * view->GetScale() );
m_canvas->SetZoom( zoom );
// Change view settings only if GAL was active previously
double zoom = 1.0 / ( zoomFactor * view->GetScale() );
m_canvas->SetZoom( zoom );
VECTOR2D center = view->GetCenter();
RedrawScreen( wxPoint( center.x, center.y ), false );
}
VECTOR2D center = view->GetCenter();
AdjustScrollBars( wxPoint( center.x, center.y ) );
}
m_canvas->SetEvtHandlerEnabled( !aEnable );

View File

@ -99,17 +99,10 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
EDA_DRAW_PANEL_GAL::~EDA_DRAW_PANEL_GAL()
{
if( m_painter )
delete m_painter;
if( m_viewControls )
delete m_viewControls;
if( m_view )
delete m_view;
if( m_gal )
delete m_gal;
delete m_painter;
delete m_viewControls;
delete m_view;
delete m_gal;
}
@ -194,42 +187,29 @@ void EDA_DRAW_PANEL_GAL::SetEventDispatcher( TOOL_DISPATCHER* aEventDispatcher )
m_eventDispatcher = aEventDispatcher;
#if wxCHECK_VERSION( 3, 0, 0 )
if( m_eventDispatcher )
{
m_parent->Connect( wxEVT_TOOL,
wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ),
NULL, m_eventDispatcher );
}
else
{
// While loops are used to be sure, that we are removing all event handlers
while( m_parent->Disconnect( wxEVT_TOOL,
wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ),
NULL, m_eventDispatcher ) );
}
const wxEventType eventTypes[] = { wxEVT_TOOL };
#else
const wxEventType eventTypes[] = { wxEVT_COMMAND_MENU_SELECTED, wxEVT_COMMAND_TOOL_CLICKED };
#endif
if( m_eventDispatcher )
{
m_parent->Connect( wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ),
NULL, m_eventDispatcher );
m_parent->Connect( wxEVT_COMMAND_TOOL_CLICKED,
wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ),
NULL, m_eventDispatcher );
BOOST_FOREACH( wxEventType type, eventTypes )
{
m_parent->Connect( type, wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ),
NULL, m_eventDispatcher );
}
}
else
{
// While loops are used to be sure, that we are removing all event handlers
while( m_parent->Disconnect( wxEVT_COMMAND_MENU_SELECTED,
wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ),
NULL, m_eventDispatcher ) );
while( m_parent->Disconnect( wxEVT_COMMAND_TOOL_CLICKED,
wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ),
NULL, m_eventDispatcher ) );
BOOST_FOREACH( wxEventType type, eventTypes )
{
// While loop is used to be sure that all event handlers are removed.
while( m_parent->Disconnect( type,
wxCommandEventHandler( TOOL_DISPATCHER::DispatchWxCommand ),
NULL, m_eventDispatcher ) );
}
}
#endif
}
@ -316,7 +296,7 @@ bool EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType )
m_backend = aGalType;
}
catch (std::runtime_error& err)
catch( std::runtime_error& err )
{
DisplayError( m_parent, wxString( err.what() ) );
return false;

View File

@ -1,8 +1,9 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* Copyright (C) 2013-2015 CERN
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -31,34 +32,37 @@
#include <cassert>
CONTEXT_MENU::CONTEXT_MENU() :
m_titleSet( false ), m_selected( -1 ), m_tool( NULL ), m_icon( NULL )
m_titleSet( false ), m_selected( -1 ), m_tool( NULL ), m_parent( NULL ), m_icon( NULL ),
m_menu_handler( CONTEXT_MENU::menuHandlerStub ),
m_update_handler( CONTEXT_MENU::updateHandlerStub )
{
setCustomEventHandler( boost::bind( &CONTEXT_MENU::handleCustomEvent, this, _1 ) );
setupEvents();
}
CONTEXT_MENU::CONTEXT_MENU( const CONTEXT_MENU& aMenu ) :
m_titleSet( aMenu.m_titleSet ), m_selected( -1 ), m_tool( aMenu.m_tool ),
m_toolActions( aMenu.m_toolActions ), m_customHandler( aMenu.m_customHandler )
CONTEXT_MENU::CONTEXT_MENU( const CONTEXT_MENU& aMenu )
{
copyFrom( aMenu );
setupEvents();
}
CONTEXT_MENU::~CONTEXT_MENU()
{
// Set parent to NULL to prevent submenus from unregistering from a notexisting object
for( std::list<CONTEXT_MENU*>::iterator it = m_submenus.begin(); it != m_submenus.end(); ++it )
(*it)->m_parent = NULL;
if( m_parent )
m_parent->m_submenus.remove( this );
}
CONTEXT_MENU& CONTEXT_MENU::operator=( const CONTEXT_MENU& aMenu )
{
Clear();
m_titleSet = aMenu.m_titleSet;
m_selected = aMenu.m_selected;
m_tool = aMenu.m_tool;
m_toolActions = aMenu.m_toolActions;
m_customHandler = aMenu.m_customHandler;
copyFrom( aMenu );
setupEvents();
return *this;
}
@ -90,31 +94,31 @@ void CONTEXT_MENU::SetTitle( const wxString& aTitle )
}
void CONTEXT_MENU::Add( const wxString& aLabel, int aId, const BITMAP_OPAQUE* aIcon )
wxMenuItem* CONTEXT_MENU::Add( const wxString& aLabel, int aId, const BITMAP_OPAQUE* aIcon )
{
#ifdef DEBUG
if( FindItem( aId ) != NULL )
wxLogWarning( wxT( "Adding more than one menu entry with the same ID may result in"
"undefined behaviour" ) );
#endif
wxMenuItem* item = new wxMenuItem( this, aId, aLabel, wxEmptyString, wxITEM_NORMAL );
if( aIcon )
item->SetBitmap( KiBitmap( aIcon ) );
Append( item );
return Append( item );
}
void CONTEXT_MENU::Add( const TOOL_ACTION& aAction )
wxMenuItem* CONTEXT_MENU::Add( const TOOL_ACTION& aAction )
{
/// ID numbers for tool actions need to have a value higher than m_actionId
int id = m_actionId + aAction.GetId();
/// ID numbers for tool actions need to have a value higher than ACTION_ID
int id = ACTION_ID + aAction.GetId();
const BITMAP_OPAQUE* icon = aAction.GetIcon();
wxMenuItem* item = new wxMenuItem( this, id,
aAction.GetMenuItem(), aAction.GetDescription(), wxITEM_NORMAL );
wxMenuItem* item = new wxMenuItem( this, id, aAction.GetMenuItem(),
aAction.GetDescription(), wxITEM_NORMAL );
if( icon )
item->SetBitmap( KiBitmap( icon ) );
@ -136,24 +140,43 @@ void CONTEXT_MENU::Add( const TOOL_ACTION& aAction )
item->SetAccel( &accel );
}
Append( item );
m_toolActions[id] = &aAction;
return Append( item );
}
void CONTEXT_MENU::Add( CONTEXT_MENU* aMenu, const wxString& aLabel )
std::list<wxMenuItem*> CONTEXT_MENU::Add( CONTEXT_MENU* aMenu, const wxString& aLabel, bool aExpand )
{
if( aMenu->m_icon )
std::list<wxMenuItem*> items;
if( aExpand )
{
wxMenuItem* newItem = new wxMenuItem( this, -1, aLabel, wxEmptyString, wxITEM_NORMAL );
newItem->SetBitmap( KiBitmap( aMenu->m_icon ) );
newItem->SetSubMenu( aMenu );
Append( newItem );
for( int i = 0; i < (int) aMenu->GetMenuItemCount(); ++i )
{
wxMenuItem* item = aMenu->FindItemByPosition( i );
items.push_back( appendCopy( item ) );
}
}
else
{
AppendSubMenu( aMenu, aLabel );
if( aMenu->m_icon )
{
wxMenuItem* newItem = new wxMenuItem( this, -1, aLabel, wxEmptyString, wxITEM_NORMAL );
newItem->SetBitmap( KiBitmap( aMenu->m_icon ) );
newItem->SetSubMenu( aMenu );
items.push_back( Append( newItem ) );
}
else
{
items.push_back( AppendSubMenu( aMenu, aLabel ) );
}
}
m_submenus.push_back( aMenu );
aMenu->m_parent = this;
return items;
}
@ -161,15 +184,25 @@ void CONTEXT_MENU::Clear()
{
m_titleSet = false;
GetMenuItems().DeleteContents( true );
GetMenuItems().Clear();
for( int i = GetMenuItemCount() - 1; i >= 0; --i )
Destroy( FindItemByPosition( i ) );
m_toolActions.clear();
GetMenuItems().DeleteContents( false ); // restore the default so destructor does not go wild
m_submenus.clear();
m_parent = NULL;
assert( GetMenuItemCount() == 0 );
}
void CONTEXT_MENU::UpdateAll()
{
m_update_handler();
runOnSubmenus( boost::bind( &CONTEXT_MENU::UpdateAll, _1 ) );
}
void CONTEXT_MENU::onMenuEvent( wxMenuEvent& aEvent )
{
OPT_TOOL_EVENT evt;
@ -195,8 +228,10 @@ void CONTEXT_MENU::onMenuEvent( wxMenuEvent& aEvent )
}
else
{
// Under Linux, every submenu can have a separate event handler, under
// Windows all submenus are handled by the main menu.
runEventHandlers( aEvent, evt );
// Under Linux, every submenu can have a separate event handler, under
// Windows all submenus are handled by the main menu.
#ifdef __WINDOWS__
if( !evt )
{
@ -211,7 +246,6 @@ void CONTEXT_MENU::onMenuEvent( wxMenuEvent& aEvent )
}
}
#endif
evt = m_customHandler( aEvent );
// Handling non-action menu entries (e.g. items in clarification list)
if( !evt )
@ -231,62 +265,88 @@ void CONTEXT_MENU::setTool( TOOL_INTERACTIVE* aTool )
{
m_tool = aTool;
for( unsigned i = 0; i < GetMenuItemCount(); ++i )
{
wxMenuItem* item = FindItemByPosition( i );
if( item->IsSubMenu() )
{
CONTEXT_MENU* menu = static_cast<CONTEXT_MENU*>( item->GetSubMenu() );
menu->setTool( aTool );
}
}
runOnSubmenus( boost::bind( &CONTEXT_MENU::setTool, _1, aTool ) );
}
void CONTEXT_MENU::copyItem( const wxMenuItem* aSource, wxMenuItem* aDest ) const
void CONTEXT_MENU::runEventHandlers( const wxMenuEvent& aMenuEvent, OPT_TOOL_EVENT& aToolEvent )
{
assert( !aSource->IsSubMenu() ); // it does not transfer submenus
aToolEvent = m_menu_handler( aMenuEvent );
aDest->SetKind( aSource->GetKind() );
aDest->SetHelp( aSource->GetHelp() );
aDest->Enable( aSource->IsEnabled() );
if( !aToolEvent )
runOnSubmenus( boost::bind( &CONTEXT_MENU::runEventHandlers, _1, aMenuEvent, aToolEvent ) );
}
if( aSource->IsCheckable() )
aDest->Check( aSource->IsChecked() );
void CONTEXT_MENU::runOnSubmenus( boost::function<void(CONTEXT_MENU*)> aFunction )
{
std::for_each( m_submenus.begin(), m_submenus.end(), aFunction );
}
wxMenuItem* CONTEXT_MENU::appendCopy( const wxMenuItem* aSource )
{
wxMenuItem* newItem = new wxMenuItem( this, aSource->GetId(), aSource->GetItemLabel(),
aSource->GetHelp(), aSource->GetKind() );
if( aSource->GetKind() == wxITEM_NORMAL )
newItem->SetBitmap( aSource->GetBitmap() );
if( aSource->IsSubMenu() )
{
#ifdef DEBUG
// Submenus of a CONTEXT_MENU are supposed to be CONTEXT_MENUs as well
assert( dynamic_cast<CONTEXT_MENU*>( aSource->GetSubMenu() ) );
#endif
CONTEXT_MENU* menu = new CONTEXT_MENU( static_cast<const CONTEXT_MENU&>( *aSource->GetSubMenu() ) );
newItem->SetSubMenu( menu );
Append( newItem );
m_submenus.push_back( menu );
menu->m_parent = this;
}
else
{
Append( newItem );
newItem->SetKind( aSource->GetKind() );
newItem->SetHelp( aSource->GetHelp() );
newItem->Enable( aSource->IsEnabled() );
if( aSource->IsCheckable() )
newItem->Check( aSource->IsChecked() );
}
return newItem;
}
void CONTEXT_MENU::copyFrom( const CONTEXT_MENU& aMenu )
{
m_icon = aMenu.m_icon;
m_titleSet = aMenu.m_titleSet;
m_selected = -1; // aMenu.m_selected;
m_tool = aMenu.m_tool;
m_toolActions = aMenu.m_toolActions;
m_parent = NULL; // aMenu.m_parent;
m_menu_handler = aMenu.m_menu_handler;
m_update_handler = aMenu.m_update_handler;
// Copy all the menu entries
for( unsigned i = 0; i < aMenu.GetMenuItemCount(); ++i )
for( int i = 0; i < (int) aMenu.GetMenuItemCount(); ++i )
{
wxMenuItem* item = aMenu.FindItemByPosition( i );
wxMenuItem* newItem = new wxMenuItem( this, item->GetId(), item->GetItemLabel(),
item->GetHelp(), item->GetKind() );
if( item->GetKind() == wxITEM_NORMAL )
newItem->SetBitmap( item->GetBitmap() );
if( item->IsSubMenu() )
{
#ifdef DEBUG
// Submenus of a CONTEXT_MENU are supposed to be CONTEXT_MENUs as well
assert( dynamic_cast<CONTEXT_MENU*>( item->GetSubMenu() ) );
#endif
CONTEXT_MENU* menu = new CONTEXT_MENU( static_cast<const CONTEXT_MENU&>( *item->GetSubMenu() ) );
newItem->SetSubMenu( menu );
Append( newItem );
}
else
{
Append( newItem );
copyItem( item, newItem );
}
appendCopy( item );
}
}
OPT_TOOL_EVENT CONTEXT_MENU::menuHandlerStub( const wxMenuEvent& )
{
return OPT_TOOL_EVENT();
}
void CONTEXT_MENU::updateHandlerStub()
{
}

View File

@ -303,7 +303,10 @@ bool TOOL_MANAGER::RunAction( const std::string& aActionName, bool aNow, void* a
if( action )
{
TOOL_EVENT event = action->MakeEvent();
event.SetParameter( aParam );
// Allow to override the action parameter
if( aParam )
event.SetParameter( aParam );
if( aNow )
ProcessEvent( event );
@ -313,6 +316,8 @@ bool TOOL_MANAGER::RunAction( const std::string& aActionName, bool aNow, void* a
return true;
}
wxASSERT_MSG( action != NULL, wxString::Format( _( "Could not find action %s." ), aActionName ) );
return false;
}
@ -320,7 +325,10 @@ bool TOOL_MANAGER::RunAction( const std::string& aActionName, bool aNow, void* a
void TOOL_MANAGER::RunAction( const TOOL_ACTION& aAction, bool aNow, void* aParam )
{
TOOL_EVENT event = aAction.MakeEvent();
event.SetParameter( aParam );
// Allow to override the action parameter
if( aParam )
event.SetParameter( aParam );
if( aNow )
ProcessEvent( event );
@ -383,6 +391,7 @@ bool TOOL_MANAGER::runTool( TOOL_BASE* aTool )
}
aTool->Reset( TOOL_INTERACTIVE::RUN );
aTool->SetTransitions();
// Add the tool on the front of the processing queue (it gets events first)
m_activeTools.push_front( aTool->GetId() );
@ -419,7 +428,10 @@ void TOOL_MANAGER::ResetTools( TOOL_BASE::RESET_REASON aReason )
ProcessEvent( evt );
BOOST_FOREACH( TOOL_BASE* tool, m_toolState | boost::adaptors::map_keys )
{
tool->Reset( aReason );
tool->SetTransitions();
}
}
@ -584,8 +596,13 @@ void TOOL_MANAGER::dispatchContextMenu( const TOOL_EVENT& aEvent )
// Temporarily store the cursor position, so the tools could execute actions
// using the point where the user has invoked a context menu
bool forcedCursor = m_viewControls->IsCursorPositionForced();
VECTOR2D cursorPos = m_viewControls->GetCursorPosition();
m_viewControls->ForceCursorPosition( true, m_viewControls->GetCursorPosition() );
// Run update handlers
st->contextMenu->UpdateAll();
boost::scoped_ptr<CONTEXT_MENU> menu( new CONTEXT_MENU( *st->contextMenu ) );
GetEditFrame()->PopupMenu( menu.get() );
@ -596,7 +613,10 @@ void TOOL_MANAGER::dispatchContextMenu( const TOOL_EVENT& aEvent )
dispatchInternal( evt );
}
m_viewControls->ForceCursorPosition( false );
TOOL_EVENT evt( TC_COMMAND, TA_CONTEXT_MENU_CLOSED );
dispatchInternal( evt );
m_viewControls->ForceCursorPosition( forcedCursor, cursorPos );
break;
}
@ -615,6 +635,8 @@ void TOOL_MANAGER::finishTool( TOOL_STATE* aState )
if( tool != m_activeTools.end() )
m_activeTools.erase( tool );
}
aState->theTool->SetTransitions();
}

View File

@ -33,8 +33,6 @@
#include <fctsys.h>
#include <id.h>
#include <class_drawpanel.h>
#include <class_draw_panel_gal.h>
#include <gal/graphics_abstraction_layer.h>
#include <view/view.h>
#include <class_base_screen.h>
#include <draw_frame.h>
@ -42,10 +40,14 @@
#include <hotkeys_basic.h>
#include <menus_helpers.h>
#include <base_units.h>
#include <tool/tool_manager.h>
void EDA_DRAW_FRAME::RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointer )
{
if( IsGalCanvasActive() )
return;
AdjustScrollBars( aCenterPoint );
// Move the mouse cursor to the on grid graphic cursor position
@ -58,6 +60,9 @@ void EDA_DRAW_FRAME::RedrawScreen( const wxPoint& aCenterPoint, bool aWarpPointe
void EDA_DRAW_FRAME::RedrawScreen2( const wxPoint& posBefore )
{
if( IsGalCanvasActive() )
return;
wxPoint dPos = posBefore - m_canvas->GetClientSize() / 2; // relative screen position to center before zoom
wxPoint newScreenPos = m_canvas->ToDeviceXY( GetCrossHairPosition() ); // screen position of crosshair after zoom
wxPoint newCenter = m_canvas->ToLogicalXY( newScreenPos - dPos );
@ -86,6 +91,8 @@ void EDA_DRAW_FRAME::Zoom_Automatique( bool aWarpPointer )
if( !IsGalCanvasActive() )
RedrawScreen( GetScrollCenterPosition(), aWarpPointer );
else
m_toolManager->RunAction( "common.Control.zoomFitScreen", true );
}
@ -186,18 +193,7 @@ void EDA_DRAW_FRAME::OnZoom( wxCommandEvent& event )
break;
default:
unsigned i;
i = id - ID_POPUP_ZOOM_LEVEL_START;
if( i >= screen->m_ZoomList.size() )
{
wxLogDebug( wxT( "%s %d: index %d is outside the bounds of the zoom list." ),
__TFILE__, __LINE__, i );
return;
}
if( screen->SetZoom( screen->m_ZoomList[i] ) )
RedrawScreen( center, true );
SetPresetZoom( id - ID_POPUP_ZOOM_LEVEL_START );
}
UpdateStatusBar();
@ -216,6 +212,26 @@ void EDA_DRAW_FRAME::SetPrevZoom()
}
void EDA_DRAW_FRAME::SetPresetZoom( int aIndex )
{
BASE_SCREEN* screen = GetScreen();
if( aIndex >= (int) screen->m_ZoomList.size() )
{
wxLogDebug( wxT( "%s %d: index %d is outside the bounds of the zoom list." ),
__TFILE__, __LINE__, aIndex );
return;
}
m_zoomSelectBox->SetSelection( aIndex );
if( screen->SetZoom( screen->m_ZoomList[aIndex] ) )
RedrawScreen( GetScrollCenterPosition(), true );
UpdateStatusBar();
}
/* add the zoom list menu the the MasterMenu.
* used in OnRightClick(wxMouseEvent& event)
*/

View File

@ -117,26 +117,9 @@ target_link_libraries( cvpcb_kiface
polygon
gal
${wxWidgets_LIBRARIES}
${OPENGL_LIBRARIES}
${GDI_PLUS_LIBRARIES}
${GLEW_LIBRARIES}
${CAIRO_LIBRARIES}
${PIXMAN_LIBRARY}
${OPENMP_LIBRARIES}
)
# Only for win32 cross compilation using MXE
if( WIN32 AND MSYS AND CMAKE_CROSSCOMPILING )
target_link_libraries( cvpcb_kiface
opengl32
glu32
pixman-1
fontconfig
freetype
bz2
)
endif()
if( BUILD_GITHUB_PLUGIN )
target_link_libraries( cvpcb_kiface github_plugin )
endif()

View File

@ -131,7 +131,6 @@ target_link_libraries( gerbview_kiface
common
polygon
bitmaps
${OPENGL_LIBRARIES}
${wxWidgets_LIBRARIES}
${GDI_PLUS_LIBRARIES}
)

View File

@ -215,7 +215,7 @@ public:
int m_ScreenNumber;
int m_NumberOfScreens;
std::vector<double> m_ZoomList; ///< standard zoom (i.e. scale) coefficients.
std::vector<int> m_ZoomList; ///< standard zoom (i.e. scale) coefficients.
bool m_IsPrinting;
public:

View File

@ -72,6 +72,9 @@ protected:
/// The area to draw on.
EDA_DRAW_PANEL* m_canvas;
TOOL_MANAGER* m_toolManager;
TOOL_DISPATCHER* m_toolDispatcher;
/// Tool ID of previously active draw tool bar button.
int m_lastDrawToolId;
@ -343,6 +346,12 @@ public:
*/
virtual const wxString GetZoomLevelIndicator() const;
/**
* Function GetZoomLevelCoeff
* returns the coefficient to convert internal display scale factor to zoom level.
*/
inline double GetZoomLevelCoeff() const { return m_zoomLevelCoeff; }
void EraseMsgBox();
void Process_PageSettings( wxCommandEvent& event );
@ -430,6 +439,13 @@ public:
*/
virtual void SetPrevGrid();
/**
* Function SetPresetGrid()
* changes the grid size to one of the preset values.
* @param aIndex is the index from the list.
*/
void SetPresetGrid( int aIndex );
/**
* Command event handler for selecting grid sizes.
*
@ -502,6 +518,13 @@ public:
*/
void SetPrevZoom();
/**
* Function SetPresetZoom()
* changes zoom to one of the preset values.
* @param aIndex is the zoom index from the list.
*/
void SetPresetZoom( int aIndex );
/**
* Function RedrawScreen
* redraws the entire screen area by updating the scroll bars and mouse pointer in
@ -730,6 +753,12 @@ public:
EDA_DRAW_PANEL_GAL* GetGalCanvas() const { return m_galCanvas; }
void SetGalCanvas( EDA_DRAW_PANEL_GAL* aPanel ) { m_galCanvas = aPanel; }
/**
* Function GetToolManager
* returns the tool manager instance, if any.
*/
TOOL_MANAGER* GetToolManager() const { return m_toolManager; }
/**
* Function GetDisplayOptions
* A way to pass info to draw functions. the base class has no knowledge about

View File

@ -1,8 +1,9 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* Copyright (C) 2013-2015 CERN
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -47,9 +48,9 @@ public:
///> Copy constructor
CONTEXT_MENU( const CONTEXT_MENU& aMenu );
CONTEXT_MENU& operator=( const CONTEXT_MENU& aMenu );
virtual ~CONTEXT_MENU();
virtual ~CONTEXT_MENU() {}
CONTEXT_MENU& operator=( const CONTEXT_MENU& aMenu );
/**
* Function SetTitle()
@ -64,7 +65,7 @@ public:
* Assigns an icon for the entry.
* @param aIcon is the icon to be assigned. NULL is used to remove icon.
*/
void SetIcon( const BITMAP_OPAQUE* aIcon )
inline void SetIcon( const BITMAP_OPAQUE* aIcon )
{
m_icon = aIcon;
}
@ -77,7 +78,7 @@ public:
* @param aId is the ID that is sent in the TOOL_EVENT. It should be unique for every entry.
* @param aIcon is an optional icon.
*/
void Add( const wxString& aLabel, int aId, const BITMAP_OPAQUE* aIcon = NULL );
wxMenuItem* Add( const wxString& aLabel, int aId, const BITMAP_OPAQUE* aIcon = NULL );
/**
* Function Add()
@ -85,7 +86,7 @@ public:
* a TOOL_EVENT command containing name of the action is sent.
* @param aAction is the action to be added to menu entry.
*/
void Add( const TOOL_ACTION& aAction );
wxMenuItem* Add( const TOOL_ACTION& aAction );
/**
* Function Add()
@ -93,8 +94,10 @@ public:
* is the capability to handle icons.
* @param aMenu is the submenu to be added.
* @param aLabel is the caption displayed for the menu entry.
* @param aExpand allows to add all entries from the menu as individual entries rather than
* add everything as a submenu.
*/
void Add( CONTEXT_MENU* aMenu, const wxString& aLabel );
std::list<wxMenuItem*> Add( CONTEXT_MENU* aMenu, const wxString& aLabel, bool aExpand = false );
/**
* Function Clear()
@ -109,28 +112,48 @@ public:
* menu was dismissed.
* @return The position of selected item in the context menu.
*/
int GetSelected() const
inline int GetSelected() const
{
return m_selected;
}
protected:
void setCustomEventHandler( boost::function<OPT_TOOL_EVENT(const wxMenuEvent&)> aHandler )
/**
* Function UpdateAll()
* Runs update handlers for the menu and its submenus.
*/
void UpdateAll();
typedef boost::function<OPT_TOOL_EVENT(const wxMenuEvent&)> MENU_HANDLER;
typedef boost::function<void()> UPDATE_HANDLER;
/**
* Function SetMenuHandler()
* Sets the menu event handler to another function.
*/
inline void SetMenuHandler( MENU_HANDLER aMenuHandler )
{
m_customHandler = aHandler;
m_menu_handler = aMenuHandler;
}
virtual OPT_TOOL_EVENT handleCustomEvent( const wxMenuEvent& aEvent )
/**
* Function SetUpdateHandler()
* Sets the update handler to a different function.
*/
inline void SetUpdateHandler( UPDATE_HANDLER aUpdateHandler )
{
return OPT_TOOL_EVENT();
m_update_handler = aUpdateHandler;
}
private:
// Empty stubs used by the default constructor
static OPT_TOOL_EVENT menuHandlerStub(const wxMenuEvent& );
static void updateHandlerStub();
/**
* Function copyItem
* Copies all properties of a menu entry to another.
* Function appendCopy
* Appends a copy of wxMenuItem.
*/
void copyItem( const wxMenuItem* aSource, wxMenuItem* aDest ) const;
wxMenuItem* appendCopy( const wxMenuItem* aSource );
///> Common part of copy constructor and assignment operator.
void copyFrom( const CONTEXT_MENU& aMenu );
@ -138,7 +161,7 @@ private:
///> Initializes handlers for events.
void setupEvents();
///> Event handler.
///> The default menu event handler.
void onMenuEvent( wxMenuEvent& aEvent );
/**
@ -148,30 +171,43 @@ private:
*/
void setTool( TOOL_INTERACTIVE* aTool );
///> Traverses the submenus tree looking for a submenu capable of handling a particular menu
///> event. In case it is handled, it is returned the aToolEvent parameter.
void runEventHandlers( const wxMenuEvent& aMenuEvent, OPT_TOOL_EVENT& aToolEvent );
///> Runs a function on the menu and all its submenus.
void runOnSubmenus( boost::function<void(CONTEXT_MENU*)> aFunction );
///> Flag indicating that the menu title was set up.
bool m_titleSet;
///> Stores the id number of selected item.
int m_selected;
///> Instance of menu event handler.
//CMEventHandler m_handler;
///> Creator of the menu
TOOL_INTERACTIVE* m_tool;
/// Menu items with ID higher than that are considered TOOL_ACTIONs
static const int m_actionId = 10000;
///> Menu items with ID higher than that are considered TOOL_ACTIONs
static const int ACTION_ID = 30000;
/// Associates tool actions with menu item IDs. Non-owning.
///> Associates tool actions with menu item IDs. Non-owning.
std::map<int, const TOOL_ACTION*> m_toolActions;
/// Custom events handler, allows to translate wxEvents to TOOL_EVENTs.
boost::function<OPT_TOOL_EVENT(const wxMenuEvent& aEvent)> m_customHandler;
///> List of submenus.
std::list<CONTEXT_MENU*> m_submenus;
/// Optional icon
///> Parent CONTEXT_MENU.
CONTEXT_MENU* m_parent;
///> Optional icon
const BITMAP_OPAQUE* m_icon;
///> Optional callback to translate wxMenuEvents to TOOL_EVENTs.
MENU_HANDLER m_menu_handler;
///> Optional callback to update the menu state before it is displayed.
UPDATE_HANDLER m_update_handler;
friend class TOOL_INTERACTIVE;
};

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* Copyright (C) 2013-2015 CERN
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
@ -41,7 +41,7 @@ struct BITMAP_OPAQUE;
* - running the DRC from the menu
* and so on, and so forth....
* Action class groups all necessary properties of an action, including explanation,
* icons, hotkeys,.menu items, etc.
* icons, hotkeys, menu items, etc.
*/
class TOOL_ACTION
{
@ -49,10 +49,10 @@ public:
TOOL_ACTION( const std::string& aName, TOOL_ACTION_SCOPE aScope = AS_CONTEXT,
int aDefaultHotKey = 0, const wxString aMenuItem = wxEmptyString,
const wxString& aMenuDesc = wxEmptyString, const BITMAP_OPAQUE* aIcon = NULL,
TOOL_ACTION_FLAGS aFlags = AF_NONE ) :
TOOL_ACTION_FLAGS aFlags = AF_NONE, void* aParam = NULL ) :
m_name( aName ), m_scope( aScope ), m_defaultHotKey( aDefaultHotKey ),
m_currentHotKey( aDefaultHotKey ), m_menuItem( aMenuItem ),
m_menuDescription( aMenuDesc ), m_icon( aIcon ), m_id( -1 ), m_flags( aFlags )
m_currentHotKey( aDefaultHotKey ), m_menuItem( aMenuItem ), m_menuDescription( aMenuDesc ),
m_icon( aIcon ), m_id( -1 ), m_flags( aFlags ), m_param( aParam )
{
TOOL_MANAGER::GetActionList().push_back( this );
}
@ -150,11 +150,11 @@ public:
TOOL_EVENT MakeEvent() const
{
if( IsActivation() )
return TOOL_EVENT( TC_COMMAND, TA_ACTIVATE, m_name, m_scope );
return TOOL_EVENT( TC_COMMAND, TA_ACTIVATE, m_name, m_scope, m_param );
else if( IsNotification() )
return TOOL_EVENT( TC_MESSAGE, TA_NONE, m_name, m_scope );
return TOOL_EVENT( TC_MESSAGE, TA_NONE, m_name, m_scope, m_param );
else
return TOOL_EVENT( TC_COMMAND, TA_ACTION, m_name, m_scope );
return TOOL_EVENT( TC_COMMAND, TA_ACTION, m_name, m_scope, m_param );
}
const wxString& GetMenuItem() const
@ -219,7 +219,7 @@ private:
/// Name of the action (convention is: app.[tool.]action.name)
std::string m_name;
/// Scope of the action (i.e. the event that is issued after activation).
/// Scope of the action
TOOL_ACTION_SCOPE m_scope;
/// Default hot key that activates the action.
@ -243,11 +243,8 @@ private:
/// Action flags
TOOL_ACTION_FLAGS m_flags;
/// Origin of the action
// const TOOL_BASE* m_origin;
/// Originating UI object
// wxWindow* m_uiOrigin;
/// Generic parameter
void* m_param;
};
#endif

View File

@ -140,6 +140,13 @@ public:
return m_toolMgr;
}
/**
* Function SetTransitions()
* This method is meant to be overridden in order to specify handlers for events. It is called
* every time tool is reset or finished.
*/
virtual void SetTransitions() {};
protected:
friend class TOOL_MANAGER;

View File

@ -88,14 +88,19 @@ enum TOOL_ACTIONS
// closed it without selecting anything.
TA_CONTEXT_MENU_CHOICE = 0x8000,
// Context menu is closed, no matter whether anything has been chosen or not.
TA_CONTEXT_MENU_CLOSED = 0x10000,
TA_CONTEXT_MENU = TA_CONTEXT_MENU_UPDATE | TA_CONTEXT_MENU_CHOICE | TA_CONTEXT_MENU_CLOSED,
// This event is sent *before* undo/redo command is performed.
TA_UNDO_REDO = 0x10000,
TA_UNDO_REDO = 0x20000,
// Tool action (allows to control tools).
TA_ACTION = 0x20000,
TA_ACTION = 0x40000,
// Tool activation event.
TA_ACTIVATE = 0x40000,
TA_ACTIVATE = 0x80000,
TA_ANY = 0xffffffff
};
@ -159,24 +164,24 @@ public:
const std::string Format() const;
TOOL_EVENT( TOOL_EVENT_CATEGORY aCategory = TC_NONE, TOOL_ACTIONS aAction = TA_NONE,
TOOL_ACTION_SCOPE aScope = AS_GLOBAL ) :
TOOL_ACTION_SCOPE aScope = AS_GLOBAL, void* aParameter = NULL ) :
m_category( aCategory ),
m_actions( aAction ),
m_scope( aScope ),
m_mouseButtons( 0 ),
m_keyCode( 0 ),
m_modifiers( 0 ),
m_param( NULL ) {}
m_param( aParameter ) {}
TOOL_EVENT( TOOL_EVENT_CATEGORY aCategory, TOOL_ACTIONS aAction, int aExtraParam,
TOOL_ACTION_SCOPE aScope = AS_GLOBAL ) :
TOOL_ACTION_SCOPE aScope = AS_GLOBAL, void* aParameter = NULL ) :
m_category( aCategory ),
m_actions( aAction ),
m_scope( aScope ),
m_mouseButtons( 0 ),
m_keyCode( 0 ),
m_modifiers( 0 ),
m_param( NULL )
m_param( aParameter )
{
if( aCategory == TC_MOUSE )
{
@ -198,14 +203,15 @@ public:
}
TOOL_EVENT( TOOL_EVENT_CATEGORY aCategory, TOOL_ACTIONS aAction,
const std::string& aExtraParam, TOOL_ACTION_SCOPE aScope = AS_GLOBAL ) :
const std::string& aExtraParam, TOOL_ACTION_SCOPE aScope = AS_GLOBAL,
void* aParameter = NULL ) :
m_category( aCategory ),
m_actions( aAction ),
m_scope( aScope ),
m_mouseButtons( 0 ),
m_keyCode( 0 ),
m_modifiers( 0 ),
m_param( NULL )
m_param( aParameter )
{
if( aCategory == TC_COMMAND || aCategory == TC_MESSAGE )
m_commandStr = aExtraParam;
@ -360,9 +366,10 @@ public:
* Returns a non-standard parameter assigned to the event. Its meaning depends on the
* target tool.
*/
void* Parameter() const
template<typename T>
inline T Parameter() const
{
return m_param;
return reinterpret_cast<T>( m_param );
}
/**
@ -371,9 +378,10 @@ public:
* target tool.
* @param aParam is the new parameter.
*/
void SetParameter(void* aParam)
template<typename T>
void SetParameter(T aParam)
{
m_param = aParam;
m_param = (void*) aParam;
}
boost::optional<int> GetCommandId() const

View File

@ -110,7 +110,18 @@ public:
* depends on the action.
* @return False if the action was not found.
*/
bool RunAction( const std::string& aActionName, bool aNow = false, void* aParam = NULL );
template<typename T>
bool RunAction( const std::string& aActionName, bool aNow = false, T aParam = NULL )
{
return RunAction( aActionName, aNow, reinterpret_cast<void*>( aParam ) );
}
bool RunAction( const std::string& aActionName, bool aNow, void* aParam );
bool RunAction( const std::string& aActionName, bool aNow = false )
{
return RunAction( aActionName, aNow, (void*) NULL );
}
/**
* Function RunAction()
@ -122,7 +133,18 @@ public:
* @param aParam is an optional parameter that might be used by the invoked action. Its meaning
* depends on the action.
*/
void RunAction( const TOOL_ACTION& aAction, bool aNow = false, void* aParam = NULL );
template<typename T>
void RunAction( const TOOL_ACTION& aAction, bool aNow = false, T aParam = NULL )
{
RunAction( aAction, aNow, reinterpret_cast<void*>( aParam ) );
}
void RunAction( const TOOL_ACTION& aAction, bool aNow, void* aParam );
void RunAction( const TOOL_ACTION& aAction, bool aNow = false )
{
RunAction( aAction, aNow, (void*) NULL );
}
/**
* Function FindTool()

View File

@ -152,7 +152,6 @@ public:
*/
virtual VECTOR2D GetCursorPosition() const = 0;
/**
* Function ForceCursorPosition()
* Places the cursor immediately at a given point. Mouse movement is ignored.
@ -182,6 +181,11 @@ public:
m_cursorCaptured = aEnabled;
}
inline bool IsCursorPositionForced() const
{
return m_forceCursorPosition;
}
protected:
/// Sets center for VIEW, takes into account panning boundaries.
void setCenter( const VECTOR2D& aCenter );

View File

@ -203,10 +203,15 @@ public:
*/
virtual void ViewUpdate( int aUpdateFlags = ALL )
{
if( m_view && m_requiredUpdate == NONE )
m_view->MarkForUpdate( this );
if( m_view )
{
assert( aUpdateFlags != NONE );
m_requiredUpdate |= aUpdateFlags;
if( m_requiredUpdate == NONE )
m_view->MarkForUpdate( this );
m_requiredUpdate |= aUpdateFlags;
}
}
/**

View File

@ -86,9 +86,6 @@ protected:
/// main window.
wxAuiToolBar* m_auxiliaryToolBar;
TOOL_MANAGER* m_toolManager;
TOOL_DISPATCHER* m_toolDispatcher;
void updateGridSelectBox();
void updateZoomSelectBox();
virtual void unitsChangeRefresh();

View File

@ -72,6 +72,8 @@ class PAGE_INFO;
class PLOTTER;
class TITLE_BLOCK;
class MSG_PANEL_ITEM;
class TOOL_MANAGER;
class TOOL_DISPATCHER;
enum id_librarytype {

View File

@ -100,7 +100,6 @@ target_link_libraries( pl_editor_kiface
common
polygon
bitmaps
${OPENGL_LIBRARIES}
${wxWidgets_LIBRARIES}
${GDI_PLUS_LIBRARIES}
)

View File

@ -271,6 +271,7 @@ set( PCBNEW_CLASS_SRCS
tools/selection_tool.cpp
tools/selection_area.cpp
tools/selection_conditions.cpp
tools/conditional_menu.cpp
tools/bright_box.cpp
tools/edit_points.cpp
tools/edit_constraints.cpp
@ -284,6 +285,9 @@ set( PCBNEW_CLASS_SRCS
tools/common_actions.cpp
tools/grid_helper.cpp
tools/tools_common.cpp
tools/grid_menu.cpp
tools/zoom_menu.cpp
)
set( PCBNEW_SRCS ${PCBNEW_AUTOROUTER_SRCS} ${PCBNEW_CLASS_SRCS} ${PCBNEW_DIALOGS} )
@ -413,11 +417,7 @@ if( KICAD_SCRIPTING_MODULES )
polygon
bitmaps
gal
${GLEW_LIBRARIES}
${CAIRO_LIBRARIES}
${PIXMAN_LIBRARY}
${wxWidgets_LIBRARIES}
${OPENGL_LIBRARIES}
${GDI_PLUS_LIBRARIES}
${PYTHON_LIBRARIES}
${PCBNEW_EXTRA_LIBS}
@ -583,12 +583,8 @@ target_link_libraries( pcbnew_kiface
idf3
${GITHUB_PLUGIN_LIBRARIES}
${wxWidgets_LIBRARIES}
${OPENGL_LIBRARIES}
${GDI_PLUS_LIBRARIES}
${PYTHON_LIBRARIES}
${GLEW_LIBRARIES}
${CAIRO_LIBRARIES}
${PIXMAN_LIBRARY}
${Boost_LIBRARIES} # must follow GITHUB
${PCBNEW_EXTRA_LIBS} # -lrt must follow Boost
${OPENMP_LIBRARIES}

View File

@ -96,8 +96,6 @@ PCB_BASE_FRAME::PCB_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame
EDA_DRAW_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName )
{
m_Pcb = NULL;
m_toolManager = NULL;
m_toolDispatcher = NULL;
m_Draw3DFrame = NULL; // Display Window in 3D mode (OpenGL)
m_UserGridSize = wxRealPoint( 100.0, 100.0 );
@ -119,12 +117,7 @@ PCB_BASE_FRAME::PCB_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame
PCB_BASE_FRAME::~PCB_BASE_FRAME()
{
delete m_Collector;
delete m_toolManager;
delete m_toolDispatcher;
delete m_Pcb;
delete GetGalCanvas();
}

View File

@ -34,8 +34,10 @@
#include <pcbnew_id.h>
#include <dialog_set_grid_base.h>
#include <invoke_pcb_dialog.h>
#include <gal/graphics_abstraction_layer.h>
#include <class_draw_panel_gal.h>
#include <tool/tool_manager.h>
class DIALOG_SET_GRID : public DIALOG_SET_GRID_BASE
@ -227,12 +229,12 @@ bool PCB_BASE_FRAME::InvokeDialogGrid()
if( screen->GetGridId() == ID_POPUP_GRID_USER )
screen->SetGrid( ID_POPUP_GRID_USER );
if( IsGalCanvasActive() )
{
GetGalCanvas()->GetGAL()->SetGridSize( VECTOR2D( screen->GetGrid().m_Size.x,
screen->GetGrid().m_Size.y ) );
GetGalCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
}
// Notify GAL
TOOL_MANAGER* mgr = GetToolManager();
if( mgr && IsGalCanvasActive() )
mgr->RunAction( "common.Control.gridPreset", true,
ID_POPUP_GRID_USER - ID_POPUP_GRID_LEVEL_1000 );
m_canvas->Refresh();

View File

@ -1182,9 +1182,10 @@ void RN_DATA::Recalculate( int aNet )
if( netCount > m_nets.size() )
m_nets.resize( netCount );
if( aNet < 0 ) // Recompute everything
if( aNet < 0 && netCount > 1 ) // Recompute everything
{
unsigned int i;
#ifdef USE_OPENMP
#pragma omp parallel shared(netCount) private(i)
{

View File

@ -96,8 +96,7 @@ public:
{
m_board = NULL;
SetIcon( width_track_via_xpm );
setCustomEventHandler( boost::bind( &CONTEXT_TRACK_WIDTH_MENU::handleCustomEvent,
this, _1 ) );
SetMenuHandler( boost::bind( &CONTEXT_TRACK_WIDTH_MENU::EventHandler, this, _1 ) );
}
void SetBoard( BOARD* aBoard )
@ -153,8 +152,7 @@ public:
}
}
protected:
OPT_TOOL_EVENT handleCustomEvent( const wxMenuEvent& aEvent )
OPT_TOOL_EVENT EventHandler( const wxMenuEvent& aEvent )
{
#if ID_POPUP_PCB_SELECT_VIASIZE1 < ID_POPUP_PCB_SELECT_WIDTH1
#error You have changed event ids order, it breaks code. Check the source code for more details.

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* Copyright (C) 2013-2015 CERN
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
@ -25,6 +25,7 @@
#include "common_actions.h"
#include <tool/action_manager.h>
#include <pcbnew_id.h>
#include <layers_id_colors_and_visibility.h>
#include <wx/defs.h>
// These members are static in class COMMON_ACTIONS: Build them here:
@ -121,7 +122,7 @@ TOOL_ACTION COMMON_ACTIONS::flip( "pcbnew.InteractiveEdit.flip",
TOOL_ACTION COMMON_ACTIONS::remove( "pcbnew.InteractiveEdit.remove",
AS_GLOBAL, WXK_DELETE,
_( "Remove" ), _( "Deletes selected item(s)" ), delete_track_xpm );
_( "Remove" ), _( "Deletes selected item(s)" ), delete_xpm );
TOOL_ACTION COMMON_ACTIONS::properties( "pcbnew.InteractiveEdit.properties",
AS_GLOBAL, 'E',
@ -180,28 +181,32 @@ TOOL_ACTION COMMON_ACTIONS::arcPosture( "pcbnew.InteractiveDrawing.arcPosture",
// View Controls
TOOL_ACTION COMMON_ACTIONS::zoomIn( "pcbnew.Control.zoomIn",
TOOL_ACTION COMMON_ACTIONS::zoomIn( "common.Control.zoomIn",
AS_GLOBAL, WXK_F1,
"", "" );
"Zoom In", "", zoom_in_xpm );
TOOL_ACTION COMMON_ACTIONS::zoomOut( "pcbnew.Control.zoomOut",
TOOL_ACTION COMMON_ACTIONS::zoomOut( "common.Control.zoomOut",
AS_GLOBAL, WXK_F2,
"", "" );
"Zoom Out", "", zoom_out_xpm );
TOOL_ACTION COMMON_ACTIONS::zoomInCenter( "pcbnew.Control.zoomInCenter",
TOOL_ACTION COMMON_ACTIONS::zoomInCenter( "common.Control.zoomInCenter",
AS_GLOBAL, 0,
"", "" );
TOOL_ACTION COMMON_ACTIONS::zoomOutCenter( "pcbnew.Control.zoomOutCenter",
TOOL_ACTION COMMON_ACTIONS::zoomOutCenter( "common.Control.zoomOutCenter",
AS_GLOBAL, 0,
"", "" );
TOOL_ACTION COMMON_ACTIONS::zoomCenter( "pcbnew.Control.zoomCenter",
TOOL_ACTION COMMON_ACTIONS::zoomCenter( "common.Control.zoomCenter",
AS_GLOBAL, WXK_F4,
"", "" );
"Center", "", zoom_center_on_screen_xpm );
TOOL_ACTION COMMON_ACTIONS::zoomFitScreen( "pcbnew.Control.zoomFitScreen",
TOOL_ACTION COMMON_ACTIONS::zoomFitScreen( "common.Control.zoomFitScreen",
AS_GLOBAL, WXK_HOME,
"Zoom Auto", "", zoom_fit_in_page_xpm );
TOOL_ACTION COMMON_ACTIONS::zoomPreset( "common.Control.zoomPreset",
AS_GLOBAL, 0,
"", "" );
@ -246,35 +251,35 @@ TOOL_ACTION COMMON_ACTIONS::highContrastDec( "pcbnew.Control.highContrastDec",
// Layer control
TOOL_ACTION COMMON_ACTIONS::layerTop( "pcbnew.Control.layerTop",
AS_GLOBAL, WXK_PAGEUP,
"", "" );
"", "", NULL, AF_NONE, (void*) F_Cu );
TOOL_ACTION COMMON_ACTIONS::layerInner1( "pcbnew.Control.layerInner1",
AS_GLOBAL, WXK_F5,
"", "" );
"", "", NULL, AF_NONE, (void*) In1_Cu );
TOOL_ACTION COMMON_ACTIONS::layerInner2( "pcbnew.Control.layerInner2",
AS_GLOBAL, WXK_F6,
"", "" );
"", "", NULL, AF_NONE, (void*) In2_Cu );
TOOL_ACTION COMMON_ACTIONS::layerInner3( "pcbnew.Control.layerInner3",
AS_GLOBAL, WXK_F7,
"", "" );
"", "", NULL, AF_NONE, (void*) In3_Cu );
TOOL_ACTION COMMON_ACTIONS::layerInner4( "pcbnew.Control.layerInner4",
AS_GLOBAL, WXK_F8,
"", "" );
"", "", NULL, AF_NONE, (void*) In4_Cu );
TOOL_ACTION COMMON_ACTIONS::layerInner5( "pcbnew.Control.layerInner5",
AS_GLOBAL, WXK_F9,
"", "" );
"", "", NULL, AF_NONE, (void*) In5_Cu );
TOOL_ACTION COMMON_ACTIONS::layerInner6( "pcbnew.Control.layerInner6",
AS_GLOBAL, WXK_F10,
"", "" );
"", "", NULL, AF_NONE, (void*) In6_Cu );
TOOL_ACTION COMMON_ACTIONS::layerBottom( "pcbnew.Control.layerBottom",
AS_GLOBAL, WXK_PAGEDOWN,
"", "" );
"", "", NULL, AF_NONE, (void*) B_Cu );
TOOL_ACTION COMMON_ACTIONS::layerNext( "pcbnew.Control.layerNext",
AS_GLOBAL, '+',
@ -298,26 +303,29 @@ TOOL_ACTION COMMON_ACTIONS::layerChanged( "pcbnew.Control.layerChanged",
// Grid control
TOOL_ACTION COMMON_ACTIONS::gridFast1( "pcbnew.Control.gridFast1",
TOOL_ACTION COMMON_ACTIONS::gridFast1( "common.Control.gridFast1",
AS_GLOBAL, MD_ALT + int( '1' ),
"", "" );
TOOL_ACTION COMMON_ACTIONS::gridFast2( "pcbnew.Control.gridFast2",
TOOL_ACTION COMMON_ACTIONS::gridFast2( "common.Control.gridFast2",
AS_GLOBAL, MD_ALT + int( '2' ),
"", "" );
TOOL_ACTION COMMON_ACTIONS::gridNext( "pcbnew.Control.gridNext",
TOOL_ACTION COMMON_ACTIONS::gridNext( "common.Control.gridNext",
AS_GLOBAL, '`',
"", "" );
TOOL_ACTION COMMON_ACTIONS::gridPrev( "pcbnew.Control.gridPrev",
TOOL_ACTION COMMON_ACTIONS::gridPrev( "common.Control.gridPrev",
AS_GLOBAL, MD_CTRL + int( '`' ),
"", "" );
TOOL_ACTION COMMON_ACTIONS::gridSetOrigin( "pcbnew.Control.gridSetOrigin",
TOOL_ACTION COMMON_ACTIONS::gridSetOrigin( "common.Control.gridSetOrigin",
AS_GLOBAL, 0,
"", "" );
TOOL_ACTION COMMON_ACTIONS::gridPreset( "common.Control.gridPreset",
AS_GLOBAL, 0,
"", "" );
// Track & via size control
TOOL_ACTION COMMON_ACTIONS::trackWidthInc( "pcbnew.EditorControl.trackWidthInc",

View File

@ -188,6 +188,7 @@ public:
static TOOL_ACTION zoomOutCenter;
static TOOL_ACTION zoomCenter;
static TOOL_ACTION zoomFitScreen;
static TOOL_ACTION zoomPreset;
// Display modes
static TOOL_ACTION trackDisplayMode;
@ -222,6 +223,7 @@ public:
static TOOL_ACTION gridNext;
static TOOL_ACTION gridPrev;
static TOOL_ACTION gridSetOrigin;
static TOOL_ACTION gridPreset;
// Track & via size control
static TOOL_ACTION trackWidthInc;

View File

@ -66,8 +66,6 @@ void DRAWING_TOOL::Reset( RESET_REASON aReason )
m_controls = getViewControls();
m_board = getModel<BOARD>();
m_frame = getEditFrame<PCB_EDIT_FRAME>();
setTransitions();
}
@ -124,7 +122,6 @@ int DRAWING_TOOL::DrawLine( const TOOL_EVENT& aEvent )
}
}
setTransitions();
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
return 0;
@ -172,7 +169,6 @@ int DRAWING_TOOL::DrawCircle( const TOOL_EVENT& aEvent )
}
}
setTransitions();
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
return 0;
@ -220,7 +216,6 @@ int DRAWING_TOOL::DrawArc( const TOOL_EVENT& aEvent )
}
}
setTransitions();
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
return 0;
@ -411,7 +406,6 @@ int DRAWING_TOOL::DrawDimension( const TOOL_EVENT& aEvent )
m_controls->CaptureCursor( false );
m_view->Remove( &preview );
setTransitions();
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
return 0;
@ -442,11 +436,7 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent )
const std::list<BOARD_ITEM*>& list = dlg.GetImportedItems();
if( dlgResult != wxID_OK || m_board->m_Modules == NULL || list.empty() )
{
setTransitions();
return 0;
}
VECTOR2I cursorPos = m_controls->GetCursorPosition();
VECTOR2I delta = cursorPos - (*list.begin())->GetPosition();
@ -617,8 +607,6 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent )
m_controls->CaptureCursor( false );
m_view->Remove( &preview );
setTransitions();
return 0;
}
@ -663,7 +651,6 @@ int DRAWING_TOOL::SetAnchor( const TOOL_EVENT& aEvent )
m_controls->SetSnapping( false );
m_controls->ShowCursor( false );
setTransitions();
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
return 0;
@ -1230,7 +1217,6 @@ int DRAWING_TOOL::drawZone( bool aKeepout )
m_controls->CaptureCursor( false );
m_view->Remove( &preview );
setTransitions();
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
return 0;
@ -1351,7 +1337,6 @@ int DRAWING_TOOL::placeTextModule()
m_controls->CaptureCursor( true );
m_view->Remove( &preview );
setTransitions();
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
return 0;
@ -1461,7 +1446,6 @@ int DRAWING_TOOL::placeTextPcb()
m_controls->CaptureCursor( false );
m_view->Remove( &preview );
setTransitions();
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
return 0;
@ -1490,7 +1474,7 @@ void DRAWING_TOOL::make45DegLine( DRAWSEGMENT* aSegment, DRAWSEGMENT* aHelper )
}
void DRAWING_TOOL::setTransitions()
void DRAWING_TOOL::SetTransitions()
{
Go( &DRAWING_TOOL::DrawLine, COMMON_ACTIONS::drawLine.MakeEvent() );
Go( &DRAWING_TOOL::DrawCircle, COMMON_ACTIONS::drawCircle.MakeEvent() );

View File

@ -132,6 +132,9 @@ public:
m_editModules = aEnabled;
}
///> Sets up handlers for various events.
void SetTransitions();
private:
///> Starts drawing a selected shape (i.e. DRAWSEGMENT).
///> @param aShape is the type of created shape (@see STROKE_T).
@ -176,9 +179,6 @@ private:
*/
void make45DegLine( DRAWSEGMENT* aSegment, DRAWSEGMENT* aHelper ) const;
///> Sets up handlers for various events.
void setTransitions();
///> Returns the appropriate width for a segment depending on the settings.
int getSegmentWidth( unsigned int aLayer ) const;

View File

@ -79,25 +79,23 @@ bool EDIT_TOOL::Init()
}
// Add context menu entries that are displayed when selection tool is active
m_selectionTool->AddMenuItem( COMMON_ACTIONS::editActivate, SELECTION_CONDITIONS::NotEmpty );
m_selectionTool->AddMenuItem( COMMON_ACTIONS::rotate, SELECTION_CONDITIONS::NotEmpty );
m_selectionTool->AddMenuItem( COMMON_ACTIONS::flip, SELECTION_CONDITIONS::NotEmpty );
m_selectionTool->AddMenuItem( COMMON_ACTIONS::remove, SELECTION_CONDITIONS::NotEmpty );
m_selectionTool->AddMenuItem( COMMON_ACTIONS::properties, SELECTION_CONDITIONS::NotEmpty );
m_selectionTool->AddMenuItem( COMMON_ACTIONS::moveExact, SELECTION_CONDITIONS::NotEmpty );
m_selectionTool->AddMenuItem( COMMON_ACTIONS::duplicate, SELECTION_CONDITIONS::NotEmpty );
m_selectionTool->AddMenuItem( COMMON_ACTIONS::createArray, SELECTION_CONDITIONS::NotEmpty );
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::editActivate, SELECTION_CONDITIONS::NotEmpty );
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::rotate, SELECTION_CONDITIONS::NotEmpty );
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::flip, SELECTION_CONDITIONS::NotEmpty );
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::remove, SELECTION_CONDITIONS::NotEmpty );
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::properties, SELECTION_CONDITIONS::NotEmpty );
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::moveExact, SELECTION_CONDITIONS::NotEmpty );
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::duplicate, SELECTION_CONDITIONS::NotEmpty );
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::createArray, SELECTION_CONDITIONS::NotEmpty );
// Footprint actions
m_selectionTool->AddMenuItem( COMMON_ACTIONS::editFootprintInFpEditor,
SELECTION_CONDITIONS::OnlyType ( PCB_MODULE_T ) &&
SELECTION_CONDITIONS::Count ( 1 ) );
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::editFootprintInFpEditor,
SELECTION_CONDITIONS::OnlyType( PCB_MODULE_T ) &&
SELECTION_CONDITIONS::Count( 1 ) );
m_offset.x = 0;
m_offset.y = 0;
setTransitions();
return true;
}
@ -128,10 +126,7 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
// Be sure that there is at least one item that we can modify. If nothing was selected before,
// try looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection)
if( !hoverSelection( selection ) )
{
setTransitions();
return 0;
}
Activate();
@ -345,8 +340,6 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent )
controls->SetAutoPan( false );
controls->ForceCursorPosition( false );
setTransitions();
return 0;
}
@ -357,11 +350,7 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
if( !hoverSelection( selection, false ) )
{
setTransitions();
return 0;
}
// Properties are displayed when there is only one item selected
if( selection.Size() == 1 )
@ -398,8 +387,6 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
item->SetFlags( flags );
}
setTransitions();
return 0;
}
@ -413,11 +400,7 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
bool unselect = selection.Empty();
if( !hoverSelection( selection ) )
{
setTransitions();
return 0;
}
wxPoint rotatePoint = getModificationPoint( selection );
@ -453,7 +436,6 @@ int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true );
setTransitions();
return 0;
}
@ -468,11 +450,7 @@ int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent )
bool unselect = selection.Empty();
if( !hoverSelection( selection ) )
{
setTransitions();
return 0;
}
wxPoint flipPoint = getModificationPoint( selection );
@ -507,7 +485,6 @@ int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true );
setTransitions();
return 0;
}
@ -518,11 +495,7 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent )
const SELECTION& selection = m_selectionTool->GetSelection();
if( !hoverSelection( selection ) )
{
setTransitions();
return 0;
}
// Get a copy of the selected items set
PICKED_ITEMS_LIST selectedItems = selection.items;
@ -544,8 +517,6 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent )
getModel<BOARD>()->GetRatsnest()->Recalculate();
setTransitions();
return 0;
}
@ -655,11 +626,7 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent )
bool unselect = selection.Empty();
if( !hoverSelection( selection ) )
{
setTransitions();
return 0;
}
wxPoint translation;
double rotation = 0;
@ -705,8 +672,6 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent )
m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true );
}
setTransitions();
return 0;
}
@ -721,10 +686,7 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
// Be sure that there is at least one item that we can modify
if( !hoverSelection( selection ) )
{
setTransitions();
return 0;
}
// we have a selection to work on now, so start the tool process
@ -803,8 +765,6 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
// and re-enable undos
decUndoInhibit();
setTransitions();
return 0;
}
@ -817,10 +777,7 @@ int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent )
// Be sure that there is at least one item that we can modify
if( !hoverSelection( selection ) )
{
setTransitions();
return 0;
}
bool originalItemsModified = false;
@ -980,13 +937,12 @@ int EDIT_TOOL::CreateArray( const TOOL_EVENT& aEvent )
}
getModel<BOARD>()->GetRatsnest()->Recalculate();
setTransitions();
return 0;
}
void EDIT_TOOL::setTransitions()
void EDIT_TOOL::SetTransitions()
{
Go( &EDIT_TOOL::Main, COMMON_ACTIONS::editActivate.MakeEvent() );
Go( &EDIT_TOOL::Rotate, COMMON_ACTIONS::rotate.MakeEvent() );
@ -1125,6 +1081,5 @@ int EDIT_TOOL::editFootprintInFpEditor( const TOOL_EVENT& aEvent )
editor->Show( true );
editor->Raise(); // Iconize( false );
setTransitions();
return 0;
}

View File

@ -126,6 +126,9 @@ public:
m_editModules = aEnabled;
}
///> Sets up handlers for various events.
void SetTransitions();
private:
///> Selection tool used for obtaining selected items
SELECTION_TOOL* m_selectionTool;
@ -149,9 +152,6 @@ private:
///> Removes and frees a single BOARD_ITEM.
void remove( BOARD_ITEM* aItem );
///> Sets up handlers for various events.
void setTransitions();
///> The required update flag for modified items
KIGFX::VIEW_ITEM::VIEW_UPDATE_FLAGS m_updateFlag;

View File

@ -74,9 +74,7 @@ bool MODULE_TOOLS::Init()
return false;
}
selectionTool->AddMenuItem( COMMON_ACTIONS::enumeratePads );
setTransitions();
selectionTool->GetMenu().AddItem( COMMON_ACTIONS::enumeratePads );
return true;
}
@ -170,7 +168,6 @@ int MODULE_TOOLS::PlacePad( const TOOL_EVENT& aEvent )
m_controls->SetAutoPan( false );
m_view->Remove( &preview );
setTransitions();
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
return 0;
@ -200,11 +197,7 @@ int MODULE_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent )
DIALOG_ENUM_PADS settingsDlg( m_frame );
if( settingsDlg.ShowModal() == wxID_CANCEL )
{
setTransitions();
return 0;
}
int padNumber = settingsDlg.GetStartNumber();
wxString padPrefix = settingsDlg.GetPrefix();
@ -312,8 +305,6 @@ int MODULE_TOOLS::EnumeratePads( const TOOL_EVENT& aEvent )
m_frame->DisplayToolMsg( wxEmptyString );
m_controls->ShowCursor( false );
setTransitions();
return 0;
}
@ -384,8 +375,6 @@ int MODULE_TOOLS::CopyItems( const TOOL_EVENT& aEvent )
m_controls->ShowCursor( false );
m_controls->SetAutoPan( false );
setTransitions();
return 0;
}
@ -406,8 +395,6 @@ int MODULE_TOOLS::PasteItems( const TOOL_EVENT& aEvent )
catch( ... )
{
m_frame->DisplayToolMsg( _( "Invalid clipboard contents" ) );
setTransitions();
return 0;
}
@ -516,8 +503,6 @@ int MODULE_TOOLS::PasteItems( const TOOL_EVENT& aEvent )
m_controls->SetAutoPan( false );
m_view->Remove( &preview );
setTransitions();
return 0;
}
@ -553,7 +538,6 @@ int MODULE_TOOLS::ModuleTextOutlines( const TOOL_EVENT& aEvent )
}
m_frame->GetGalCanvas()->Refresh();
setTransitions();
return 0;
}
@ -585,13 +569,12 @@ int MODULE_TOOLS::ModuleEdgeOutlines( const TOOL_EVENT& aEvent )
}
m_frame->GetGalCanvas()->Refresh();
setTransitions();
return 0;
}
void MODULE_TOOLS::setTransitions()
void MODULE_TOOLS::SetTransitions()
{
Go( &MODULE_TOOLS::PlacePad, COMMON_ACTIONS::placePad.MakeEvent() );
Go( &MODULE_TOOLS::EnumeratePads, COMMON_ACTIONS::enumeratePads.MakeEvent() );

View File

@ -98,10 +98,10 @@ public:
*/
int ModuleEdgeOutlines( const TOOL_EVENT& aEvent );
private:
///> Sets up handlers for various events.
void setTransitions();
void SetTransitions();
private:
KIGFX::VIEW* m_view;
KIGFX::VIEW_CONTROLS* m_controls;
BOARD* m_board;

View File

@ -74,12 +74,10 @@ bool PCB_EDITOR_CONTROL::Init()
if( selTool )
{
selTool->AddSubMenu( new ZONE_CONTEXT_MENU, _( "Zones" ),
SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T ) );
selTool->GetMenu().AddMenu( new ZONE_CONTEXT_MENU, _( "Zones" ), false,
SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T ) );
}
setTransitions();
return true;
}
@ -98,8 +96,6 @@ int PCB_EDITOR_CONTROL::TrackWidthInc( const TOOL_EVENT& aEvent )
wxUpdateUIEvent dummy;
m_frame->OnUpdateSelectTrackWidth( dummy );
setTransitions();
m_toolMgr->RunAction( COMMON_ACTIONS::trackViaSizeChanged );
return 0;
@ -119,8 +115,6 @@ int PCB_EDITOR_CONTROL::TrackWidthDec( const TOOL_EVENT& aEvent )
wxUpdateUIEvent dummy;
m_frame->OnUpdateSelectTrackWidth( dummy );
setTransitions();
m_toolMgr->RunAction( COMMON_ACTIONS::trackViaSizeChanged );
return 0;
@ -140,8 +134,6 @@ int PCB_EDITOR_CONTROL::ViaSizeInc( const TOOL_EVENT& aEvent )
wxUpdateUIEvent dummy;
m_frame->OnUpdateSelectViaSize( dummy );
setTransitions();
m_toolMgr->RunAction( COMMON_ACTIONS::trackViaSizeChanged );
return 0;
@ -161,8 +153,6 @@ int PCB_EDITOR_CONTROL::ViaSizeDec( const TOOL_EVENT& aEvent )
wxUpdateUIEvent dummy;
m_frame->OnUpdateSelectViaSize( dummy );
setTransitions();
m_toolMgr->RunAction( COMMON_ACTIONS::trackViaSizeChanged );
return 0;
@ -277,7 +267,6 @@ int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent )
controls->CaptureCursor( false );
view->Remove( &preview );
setTransitions();
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
return 0;
@ -370,7 +359,6 @@ int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent )
controls->CaptureCursor( false );
view->Remove( &preview );
setTransitions();
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
return 0;
@ -393,8 +381,6 @@ int PCB_EDITOR_CONTROL::ZoneFill( const TOOL_EVENT& aEvent )
zone->ViewUpdate();
}
setTransitions();
return 0;
}
@ -411,8 +397,6 @@ int PCB_EDITOR_CONTROL::ZoneFillAll( const TOOL_EVENT& aEvent )
zone->ViewUpdate();
}
setTransitions();
return 0;
}
@ -432,8 +416,6 @@ int PCB_EDITOR_CONTROL::ZoneUnfill( const TOOL_EVENT& aEvent )
zone->ViewUpdate();
}
setTransitions();
return 0;
}
@ -450,8 +432,6 @@ int PCB_EDITOR_CONTROL::ZoneUnfillAll( const TOOL_EVENT& aEvent )
zone->ViewUpdate();
}
setTransitions();
return 0;
}
@ -464,13 +444,11 @@ int PCB_EDITOR_CONTROL::SelectionCrossProbe( const TOOL_EVENT& aEvent )
if( selection.Size() == 1 )
m_frame->SendMessageToEESCHEMA( selection.Item<BOARD_ITEM>( 0 ) );
setTransitions();
return 0;
}
void PCB_EDITOR_CONTROL::setTransitions()
void PCB_EDITOR_CONTROL::SetTransitions()
{
// Track & via size control
Go( &PCB_EDITOR_CONTROL::TrackWidthInc, COMMON_ACTIONS::trackWidthInc.MakeEvent() );

View File

@ -72,10 +72,10 @@ public:
///> Notifies eeschema about the selected item.
int SelectionCrossProbe( const TOOL_EVENT& aEvent );
private:
///> Sets up handlers for various events.
void setTransitions();
void SetTransitions();
private:
///> Pointer to the currently used edit frame.
PCB_EDIT_FRAME* m_frame;

View File

@ -52,14 +52,6 @@ void PCBNEW_CONTROL::Reset( RESET_REASON aReason )
}
bool PCBNEW_CONTROL::Init()
{
setTransitions();
return true;
}
int PCBNEW_CONTROL::ZoomInOut( const TOOL_EVENT& aEvent )
{
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
@ -71,7 +63,6 @@ int PCBNEW_CONTROL::ZoomInOut( const TOOL_EVENT& aEvent )
zoomScale = 0.7;
view->SetScale( view->GetScale() * zoomScale, getViewControls()->GetCursorPosition() );
setTransitions();
return 0;
}
@ -88,7 +79,6 @@ int PCBNEW_CONTROL::ZoomInOutCenter( const TOOL_EVENT& aEvent )
zoomScale = 0.7;
view->SetScale( view->GetScale() * zoomScale );
setTransitions();
return 0;
}
@ -98,7 +88,6 @@ int PCBNEW_CONTROL::ZoomCenter( const TOOL_EVENT& aEvent )
{
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
view->SetCenter( getViewControls()->GetCursorPosition() );
setTransitions();
return 0;
}
@ -111,18 +100,17 @@ int PCBNEW_CONTROL::ZoomFitScreen( const TOOL_EVENT& aEvent )
BOARD* board = getModel<BOARD>();
board->ComputeBoundingBox();
BOX2I boardBBox = board->ViewBBox();
VECTOR2I screenSize = gal->GetScreenPixelSize();
if( boardBBox.GetSize().x == 0 || boardBBox.GetSize().y == 0 )
{
// Empty view
view->SetScale( 100000.0 );
view->SetCenter( VECTOR2D( 0, 0 ) );
view->SetCenter( view->ToWorld( VECTOR2D( screenSize.x / 2, screenSize.y / 2 ) ) );
view->SetScale( 17.0 );
}
else
{
// Autozoom to board
VECTOR2I screenSize = gal->GetScreenPixelSize();
double iuPerX = screenSize.x ? boardBBox.GetWidth() / screenSize.x : 1.0;
double iuPerY = screenSize.y ? boardBBox.GetHeight() / screenSize.y : 1.0;
@ -130,11 +118,36 @@ int PCBNEW_CONTROL::ZoomFitScreen( const TOOL_EVENT& aEvent )
double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor();
double zoom = 1.0 / ( zoomFactor * bestZoom );
view->SetScale( zoom );
view->SetCenter( boardBBox.Centre() );
view->SetScale( zoom );
}
setTransitions();
return 0;
}
int PCBNEW_CONTROL::ZoomPreset( const TOOL_EVENT& aEvent )
{
unsigned int idx = aEvent.Parameter<long>();
std::vector<int>& zoomList = m_frame->GetScreen()->m_ZoomList;
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
KIGFX::GAL* gal = m_frame->GetGalCanvas()->GetGAL();
m_frame->SetPresetZoom( idx );
if( idx == 0 ) // Zoom Auto
{
return ZoomFitScreen( aEvent );
}
else if( idx < 0 || idx >= zoomList.size() )
{
assert( false );
return 0;
}
double selectedZoom = zoomList[idx];
double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor();
view->SetScale( 1.0 / ( zoomFactor * selectedZoom ) );
return 0;
}
@ -159,7 +172,6 @@ int PCBNEW_CONTROL::TrackDisplayMode( const TOOL_EVENT& aEvent )
}
m_frame->GetGalCanvas()->Refresh();
setTransitions();
return 0;
}
@ -184,7 +196,6 @@ int PCBNEW_CONTROL::PadDisplayMode( const TOOL_EVENT& aEvent )
}
m_frame->GetGalCanvas()->Refresh();
setTransitions();
return 0;
}
@ -209,7 +220,6 @@ int PCBNEW_CONTROL::ViaDisplayMode( const TOOL_EVENT& aEvent )
}
m_frame->GetGalCanvas()->Refresh();
setTransitions();
return 0;
}
@ -240,7 +250,6 @@ int PCBNEW_CONTROL::ZoneDisplayMode( const TOOL_EVENT& aEvent )
board->GetArea( i )->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
m_frame->GetGalCanvas()->Refresh();
setTransitions();
return 0;
}
@ -258,8 +267,6 @@ int PCBNEW_CONTROL::HighContrastMode( const TOOL_EVENT& aEvent )
settings->LoadDisplayOptions( displ_opts );
m_frame->GetGalCanvas()->SetHighContrastLayer( m_frame->GetActiveLayer() );
setTransitions();
return 0;
}
@ -267,7 +274,6 @@ int PCBNEW_CONTROL::HighContrastMode( const TOOL_EVENT& aEvent )
int PCBNEW_CONTROL::HighContrastInc( const TOOL_EVENT& aEvent )
{
std::cout << __PRETTY_FUNCTION__ << std::endl;
setTransitions();
return 0;
}
@ -276,7 +282,6 @@ int PCBNEW_CONTROL::HighContrastInc( const TOOL_EVENT& aEvent )
int PCBNEW_CONTROL::HighContrastDec( const TOOL_EVENT& aEvent )
{
std::cout << __PRETTY_FUNCTION__ << std::endl;
setTransitions();
return 0;
}
@ -285,24 +290,7 @@ int PCBNEW_CONTROL::HighContrastDec( const TOOL_EVENT& aEvent )
// Layer control
int PCBNEW_CONTROL::LayerSwitch( const TOOL_EVENT& aEvent )
{
if( aEvent.IsAction( &COMMON_ACTIONS::layerTop ) )
m_frame->SwitchLayer( NULL, F_Cu );
else if( aEvent.IsAction( &COMMON_ACTIONS::layerInner1 ) )
m_frame->SwitchLayer( NULL, In1_Cu );
else if( aEvent.IsAction( &COMMON_ACTIONS::layerInner2 ) )
m_frame->SwitchLayer( NULL, In2_Cu );
else if( aEvent.IsAction( &COMMON_ACTIONS::layerInner3 ) )
m_frame->SwitchLayer( NULL, In3_Cu );
else if( aEvent.IsAction( &COMMON_ACTIONS::layerInner4 ) )
m_frame->SwitchLayer( NULL, In4_Cu );
else if( aEvent.IsAction( &COMMON_ACTIONS::layerInner5 ) )
m_frame->SwitchLayer( NULL, In5_Cu );
else if( aEvent.IsAction( &COMMON_ACTIONS::layerInner6 ) )
m_frame->SwitchLayer( NULL, In6_Cu );
else if( aEvent.IsAction( &COMMON_ACTIONS::layerBottom ) )
m_frame->SwitchLayer( NULL, B_Cu );
setTransitions();
m_frame->SwitchLayer( NULL, (LAYER_ID) aEvent.Parameter<long>() );
return 0;
}
@ -314,10 +302,7 @@ int PCBNEW_CONTROL::LayerNext( const TOOL_EVENT& aEvent )
LAYER_NUM layer = editFrame->GetActiveLayer();
if( layer < F_Cu || layer > B_Cu )
{
setTransitions();
return 0;
}
int layerCount = getModel<BOARD>()->GetCopperLayerCount();
@ -330,7 +315,6 @@ int PCBNEW_CONTROL::LayerNext( const TOOL_EVENT& aEvent )
assert( IsCopperLayer( layer ) );
editFrame->SwitchLayer( NULL, ToLAYER_ID( layer ) );
setTransitions();
return 0;
}
@ -342,10 +326,7 @@ int PCBNEW_CONTROL::LayerPrev( const TOOL_EVENT& aEvent )
LAYER_NUM layer = editFrame->GetActiveLayer();
if( layer < F_Cu || layer > B_Cu )
{
setTransitions();
return 0;
}
int layerCount = getModel<BOARD>()->GetCopperLayerCount();
@ -358,7 +339,6 @@ int PCBNEW_CONTROL::LayerPrev( const TOOL_EVENT& aEvent )
assert( IsCopperLayer( layer ) );
editFrame->SwitchLayer( NULL, ToLAYER_ID( layer ) );
setTransitions();
return 0;
}
@ -381,8 +361,6 @@ int PCBNEW_CONTROL::LayerAlphaInc( const TOOL_EVENT& aEvent )
m_frame->GetGalCanvas()->GetView()->UpdateLayerColor( currentLayer );
}
setTransitions();
return 0;
}
@ -404,8 +382,6 @@ int PCBNEW_CONTROL::LayerAlphaDec( const TOOL_EVENT& aEvent )
m_frame->GetGalCanvas()->GetView()->UpdateLayerColor( currentLayer );
}
setTransitions();
return 0;
}
@ -414,7 +390,6 @@ int PCBNEW_CONTROL::LayerAlphaDec( const TOOL_EVENT& aEvent )
int PCBNEW_CONTROL::GridFast1( const TOOL_EVENT& aEvent )
{
m_frame->SetFastGrid1();
setTransitions();
return 0;
}
@ -423,7 +398,6 @@ int PCBNEW_CONTROL::GridFast1( const TOOL_EVENT& aEvent )
int PCBNEW_CONTROL::GridFast2( const TOOL_EVENT& aEvent )
{
m_frame->SetFastGrid2();
setTransitions();
return 0;
}
@ -432,7 +406,6 @@ int PCBNEW_CONTROL::GridFast2( const TOOL_EVENT& aEvent )
int PCBNEW_CONTROL::GridNext( const TOOL_EVENT& aEvent )
{
m_frame->SetNextGrid();
setTransitions();
return 0;
}
@ -441,7 +414,6 @@ int PCBNEW_CONTROL::GridNext( const TOOL_EVENT& aEvent )
int PCBNEW_CONTROL::GridPrev( const TOOL_EVENT& aEvent )
{
m_frame->SetPrevGrid();
setTransitions();
return 0;
}
@ -450,8 +422,7 @@ int PCBNEW_CONTROL::GridPrev( const TOOL_EVENT& aEvent )
int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent )
{
Activate();
m_frame->SetToolID( ID_PCB_PLACE_GRID_COORD_BUTT, wxCURSOR_PENCIL,
_( "Adjust grid origin" ) );
m_frame->SetToolID( ID_PCB_PLACE_GRID_COORD_BUTT, wxCURSOR_PENCIL, _( "Adjust grid origin" ) );
KIGFX::VIEW_CONTROLS* controls = getViewControls();
controls->ShowCursor( true );
@ -473,13 +444,27 @@ int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent )
controls->SetAutoPan( false );
controls->SetSnapping( false );
controls->ShowCursor( false );
setTransitions();
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
return 0;
}
int PCBNEW_CONTROL::GridPreset( const TOOL_EVENT& aEvent )
{
long idx = aEvent.Parameter<long>();
m_frame->SetPresetGrid( idx );
BASE_SCREEN* screen = m_frame->GetScreen();
GRID_TYPE grid = screen->GetGrid( idx );
getView()->GetGAL()->SetGridSize( VECTOR2D( grid.m_Size ) );
getView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
return 0;
}
// Miscellaneous
int PCBNEW_CONTROL::ResetCoords( const TOOL_EVENT& aEvent )
{
@ -487,7 +472,6 @@ int PCBNEW_CONTROL::ResetCoords( const TOOL_EVENT& aEvent )
m_frame->GetScreen()->m_O_Curseur = wxPoint( cursorPos.x, cursorPos.y );
m_frame->UpdateStatusBar();
setTransitions();
return 0;
}
@ -505,8 +489,6 @@ int PCBNEW_CONTROL::SwitchCursor( const TOOL_EVENT& aEvent )
else
gal->SetCursorSize( BIG_CURSOR );
setTransitions();
return 0;
}
@ -522,7 +504,6 @@ int PCBNEW_CONTROL::SwitchUnits( const TOOL_EVENT& aEvent )
evt.SetId( ID_TB_OPTIONS_SELECT_UNIT_INCH );
m_frame->ProcessEvent( evt );
setTransitions();
return 0;
}
@ -532,7 +513,6 @@ int PCBNEW_CONTROL::ShowHelp( const TOOL_EVENT& aEvent )
{
// TODO
DisplayInfoMessage( m_frame, _( "Not implemented yet." ) );
setTransitions();
return 0;
}
@ -541,13 +521,12 @@ int PCBNEW_CONTROL::ShowHelp( const TOOL_EVENT& aEvent )
int PCBNEW_CONTROL::ToBeDone( const TOOL_EVENT& aEvent )
{
DisplayInfoMessage( m_frame, _( "Not implemented yet." ) );
setTransitions();
return 0;
}
void PCBNEW_CONTROL::setTransitions()
void PCBNEW_CONTROL::SetTransitions()
{
// View controls
Go( &PCBNEW_CONTROL::ZoomInOut, COMMON_ACTIONS::zoomIn.MakeEvent() );
@ -556,6 +535,7 @@ void PCBNEW_CONTROL::setTransitions()
Go( &PCBNEW_CONTROL::ZoomInOutCenter, COMMON_ACTIONS::zoomOutCenter.MakeEvent() );
Go( &PCBNEW_CONTROL::ZoomCenter, COMMON_ACTIONS::zoomCenter.MakeEvent() );
Go( &PCBNEW_CONTROL::ZoomFitScreen, COMMON_ACTIONS::zoomFitScreen.MakeEvent() );
Go( &PCBNEW_CONTROL::ZoomPreset, COMMON_ACTIONS::zoomPreset.MakeEvent() );
// Display modes
Go( &PCBNEW_CONTROL::TrackDisplayMode, COMMON_ACTIONS::trackDisplayMode.MakeEvent() );
@ -588,6 +568,7 @@ void PCBNEW_CONTROL::setTransitions()
Go( &PCBNEW_CONTROL::GridNext, COMMON_ACTIONS::gridNext.MakeEvent() );
Go( &PCBNEW_CONTROL::GridPrev, COMMON_ACTIONS::gridPrev.MakeEvent() );
Go( &PCBNEW_CONTROL::GridSetOrigin, COMMON_ACTIONS::gridSetOrigin.MakeEvent() );
Go( &PCBNEW_CONTROL::GridPreset, COMMON_ACTIONS::gridPreset.MakeEvent() );
// Miscellaneous
Go( &PCBNEW_CONTROL::ResetCoords, COMMON_ACTIONS::resetCoords.MakeEvent() );

View File

@ -43,14 +43,12 @@ public:
/// @copydoc TOOL_INTERACTIVE::Reset()
void Reset( RESET_REASON aReason );
/// @copydoc TOOL_INTERACTIVE::Init()
bool Init();
// View controls
int ZoomInOut( const TOOL_EVENT& aEvent );
int ZoomInOutCenter( const TOOL_EVENT& aEvent );
int ZoomCenter( const TOOL_EVENT& aEvent );
int ZoomFitScreen( const TOOL_EVENT& aEvent );
int ZoomPreset( const TOOL_EVENT& aEvent );
// Display modes
int TrackDisplayMode( const TOOL_EVENT& aEvent );
@ -74,6 +72,7 @@ public:
int GridNext( const TOOL_EVENT& aEvent );
int GridPrev( const TOOL_EVENT& aEvent );
int GridSetOrigin( const TOOL_EVENT& aEvent );
int GridPreset( const TOOL_EVENT& aEvent );
// Miscellaneous
int ResetCoords( const TOOL_EVENT& aEvent );
@ -82,10 +81,10 @@ public:
int ShowHelp( const TOOL_EVENT& aEvent );
int ToBeDone( const TOOL_EVENT& aEvent );
private:
///> Sets up handlers for various events.
void setTransitions();
void SetTransitions();
private:
///> Pointer to the currently used edit frame.
PCB_BASE_FRAME* m_frame;
};

View File

@ -63,10 +63,8 @@ bool PLACEMENT_TOOL::Init()
menu->AppendSeparator();
menu->Add( COMMON_ACTIONS::distributeHorizontally );
menu->Add( COMMON_ACTIONS::distributeVertically );
m_selectionTool->AddSubMenu( menu, _( "Align/distribute" ),
SELECTION_CONDITIONS::MoreThan( 1 ) );
setTransitions();
m_selectionTool->GetMenu().AddMenu( menu, _( "Align/distribute" ), false,
SELECTION_CONDITIONS::MoreThan( 1 ) );
return true;
}
@ -109,8 +107,6 @@ int PLACEMENT_TOOL::AlignTop( const TOOL_EVENT& aEvent )
getModel<BOARD>()->GetRatsnest()->Recalculate();
}
setTransitions();
return 0;
}
@ -152,8 +148,6 @@ int PLACEMENT_TOOL::AlignBottom( const TOOL_EVENT& aEvent )
getModel<BOARD>()->GetRatsnest()->Recalculate();
}
setTransitions();
return 0;
}
@ -195,8 +189,6 @@ int PLACEMENT_TOOL::AlignLeft( const TOOL_EVENT& aEvent )
getModel<BOARD>()->GetRatsnest()->Recalculate();
}
setTransitions();
return 0;
}
@ -238,8 +230,6 @@ int PLACEMENT_TOOL::AlignRight( const TOOL_EVENT& aEvent )
getModel<BOARD>()->GetRatsnest()->Recalculate();
}
setTransitions();
return 0;
}
@ -299,8 +289,6 @@ int PLACEMENT_TOOL::DistributeHorizontally( const TOOL_EVENT& aEvent )
getModel<BOARD>()->GetRatsnest()->Recalculate();
}
setTransitions();
return 0;
}
@ -348,13 +336,11 @@ int PLACEMENT_TOOL::DistributeVertically( const TOOL_EVENT& aEvent )
getModel<BOARD>()->GetRatsnest()->Recalculate();
}
setTransitions();
return 0;
}
void PLACEMENT_TOOL::setTransitions()
void PLACEMENT_TOOL::SetTransitions()
{
Go( &PLACEMENT_TOOL::AlignTop, COMMON_ACTIONS::alignTop.MakeEvent() );
Go( &PLACEMENT_TOOL::AlignBottom, COMMON_ACTIONS::alignBottom.MakeEvent() );

View File

@ -77,10 +77,10 @@ public:
*/
int DistributeVertically( const TOOL_EVENT& aEvent );
private:
///> Sets up handlers for various events.
void setTransitions();
void SetTransitions();
private:
SELECTION_TOOL* m_selectionTool;
};

View File

@ -210,10 +210,8 @@ bool POINT_EDITOR::Init()
return false;
}
m_selectionTool->AddMenuItem( COMMON_ACTIONS::pointEditorBreakOutline,
POINT_EDITOR::breakOutlineCondition );
setTransitions();
m_selectionTool->GetMenu().AddItem( COMMON_ACTIONS::pointEditorBreakOutline,
POINT_EDITOR::breakOutlineCondition );
return true;
}
@ -233,11 +231,9 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
EDA_ITEM* item = selection.items.GetPickedItem( 0 );
m_editPoints = EDIT_POINTS_FACTORY::Make( item, getView()->GetGAL() );
if( !m_editPoints )
{
setTransitions();
return 0;
}
view->Add( m_editPoints.get() );
m_dragPoint = NULL;
@ -363,8 +359,6 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
controls->ForceCursorPosition( false );
}
setTransitions();
return 0;
}
@ -795,7 +789,7 @@ void POINT_EDITOR::breakOutline( const VECTOR2I& aBreakPoint )
}
void POINT_EDITOR::setTransitions()
void POINT_EDITOR::SetTransitions()
{
Go( &POINT_EDITOR::OnSelectionChange, SELECTION_TOOL::SelectedEvent );
Go( &POINT_EDITOR::OnSelectionChange, SELECTION_TOOL::UnselectedEvent );

View File

@ -55,6 +55,9 @@ public:
*/
int OnSelectionChange( const TOOL_EVENT& aEvent );
///> Sets up handlers for various events.
void SetTransitions();
private:
///> Selection tool used for obtaining selected items
SELECTION_TOOL* m_selectionTool;
@ -98,9 +101,6 @@ private:
///> Adds a new edit point on a zone outline/line.
void breakOutline( const VECTOR2I& aBreakPoint );
///> Sets up handlers for various events.
void setTransitions();
///> Condition to display "Create corner" context menu entry.
static bool breakOutlineCondition( const SELECTION& aSelection );
};

View File

@ -51,6 +51,8 @@
#include "selection_tool.h"
#include "selection_area.h"
#include "zoom_menu.h"
#include "grid_menu.h"
#include "bright_box.h"
#include "common_actions.h"
@ -70,22 +72,39 @@ SELECTION_TOOL::SELECTION_TOOL() :
m_frame( NULL ), m_additive( false ), m_multiple( false ),
m_editModules( false ), m_locked( true )
{
m_selArea = new SELECTION_AREA;
m_selection.group = new KIGFX::VIEW_GROUP;
AddSubMenu( new SELECT_MENU, _( "Select..." ),
(SELECTION_CONDITION) SELECTION_CONDITIONS::OnlyConnectedItems &&
SELECTION_CONDITIONS::Count( 1 ) );
}
SELECTION_TOOL::~SELECTION_TOOL()
{
delete m_selArea;
delete m_selection.group;
}
bool SELECTION_TOOL::Init()
{
m_selection.group = new KIGFX::VIEW_GROUP;
m_menu.AddMenu( new SELECT_MENU, _( "Select..." ), false,
(SELECTION_CONDITION) SELECTION_CONDITIONS::OnlyConnectedItems &&
SELECTION_CONDITIONS::Count( 1 ) );
m_menu.AddSeparator( SELECTION_CONDITIONS::ShowAlways, 1000 );
m_menu.AddItem( COMMON_ACTIONS::zoomCenter, SELECTION_CONDITIONS::ShowAlways, 1000 );
m_menu.AddItem( COMMON_ACTIONS::zoomIn, SELECTION_CONDITIONS::ShowAlways, 1000 );
m_menu.AddItem( COMMON_ACTIONS::zoomOut , SELECTION_CONDITIONS::ShowAlways, 1000 );
m_menu.AddItem( COMMON_ACTIONS::zoomFitScreen , SELECTION_CONDITIONS::ShowAlways, 1000 );
m_menu.AddMenu( new ZOOM_MENU( getEditFrame<PCB_BASE_FRAME>() ), "Zoom",
false, SELECTION_CONDITIONS::ShowAlways, 1000 );
m_menu.AddMenu( new GRID_MENU( getEditFrame<PCB_BASE_FRAME>() ), "Grid",
false, SELECTION_CONDITIONS::ShowAlways, 1000 );
return true;
}
void SELECTION_TOOL::Reset( RESET_REASON aReason )
{
if( aReason == TOOL_BASE::MODEL_RELOAD )
@ -93,7 +112,6 @@ void SELECTION_TOOL::Reset( RESET_REASON aReason )
// Remove pointers to the selected items from containers
// without changing their properties (as they are already deleted
// while a new board is loaded)
m_selection.group->Clear();
m_selection.clear();
}
else
@ -102,12 +120,11 @@ void SELECTION_TOOL::Reset( RESET_REASON aReason )
m_frame = getEditFrame<PCB_BASE_FRAME>();
m_locked = true;
m_preliminary = true;
// Reinsert the VIEW_GROUP, in case it was removed from the VIEW
getView()->Remove( m_selection.group );
getView()->Add( m_selection.group );
setTransitions();
}
@ -139,10 +156,17 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
// right click? if there is any object - show the context menu
else if( evt->IsClick( BUT_RIGHT ) )
{
if( m_selection.Empty() )
bool emptySelection = m_selection.Empty();
if( emptySelection )
selectCursor( evt->Position() );
generateMenu();
CONTEXT_MENU& contextMenu = m_menu.Generate( m_selection );
if( contextMenu.GetMenuItemCount() > 0 )
SetContextMenu( &contextMenu, CMENU_NOW );
m_preliminary = emptySelection;
}
// double click? Display the properties window
@ -159,10 +183,14 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
{
if( m_additive )
{
m_preliminary = false;
selectMultiple();
}
else if( m_selection.Empty() )
{
m_preliminary = false;
// There is nothing selected, so try to select something
if( !selectCursor( getView()->ToWorld( getViewControls()->GetMousePosition() ), false ) )
{
@ -233,6 +261,12 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
{
selectNet( *evt );
}
else if( evt->Action() == TA_CONTEXT_MENU_CLOSED )
{
if( m_preliminary )
clearSelection();
}
}
// This tool is supposed to be active forever
@ -242,23 +276,6 @@ int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent )
}
void SELECTION_TOOL::AddMenuItem( const TOOL_ACTION& aAction, const SELECTION_CONDITION& aCondition )
{
assert( aAction.GetId() > 0 ); // Check if the action was registered before in ACTION_MANAGER
m_menu.Add( aAction );
m_menuConditions.push_back( aCondition );
}
void SELECTION_TOOL::AddSubMenu( CONTEXT_MENU* aMenu, const wxString& aLabel,
const SELECTION_CONDITION& aCondition )
{
m_menu.Add( aMenu, aLabel );
m_menuConditions.push_back( aCondition );
}
void SELECTION_TOOL::toggleSelection( BOARD_ITEM* aItem )
{
if( aItem->IsSelected() )
@ -334,7 +351,7 @@ bool SELECTION_TOOL::selectCursor( const VECTOR2I& aWhere, bool aOnDrag )
else if( collector.GetCount() > 1 )
{
if( aOnDrag )
Wait ( TOOL_EVENT( TC_ANY, TA_MOUSE_UP, BUT_LEFT ) );
Wait( TOOL_EVENT( TC_ANY, TA_MOUSE_UP, BUT_LEFT ) );
item = disambiguationMenu( &collector );
@ -359,7 +376,8 @@ bool SELECTION_TOOL::selectMultiple()
KIGFX::VIEW* view = getView();
getViewControls()->SetAutoPan( true );
view->Add( m_selArea );
SELECTION_AREA area;
view->Add( &area );
while( OPT_TOOL_EVENT evt = Wait() )
{
@ -375,20 +393,20 @@ bool SELECTION_TOOL::selectMultiple()
clearSelection();
// Start drawing a selection box
m_selArea->SetOrigin( evt->DragOrigin() );
m_selArea->SetEnd( evt->Position() );
m_selArea->ViewSetVisible( true );
m_selArea->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
area.SetOrigin( evt->DragOrigin() );
area.SetEnd( evt->Position() );
area.ViewSetVisible( true );
area.ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
}
if( evt->IsMouseUp( BUT_LEFT ) )
{
// End drawing the selection box
m_selArea->ViewSetVisible( false );
area.ViewSetVisible( false );
// Mark items within the selection box as selected
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR> selectedItems;
BOX2I selectionBox = m_selArea->ViewBBox();
BOX2I selectionBox = area.ViewBBox();
view->Query( selectionBox, selectedItems ); // Get the list of selected items
std::vector<KIGFX::VIEW::LAYER_ITEM_PAIR>::iterator it, it_end;
@ -419,8 +437,8 @@ bool SELECTION_TOOL::selectMultiple()
}
// Stop drawing the selection box
m_selArea->ViewSetVisible( false );
view->Remove( m_selArea );
area.ViewSetVisible( false );
view->Remove( &area );
m_multiple = false; // Multiple selection mode is inactive
getViewControls()->SetAutoPan( false );
@ -428,7 +446,7 @@ bool SELECTION_TOOL::selectMultiple()
}
void SELECTION_TOOL::setTransitions()
void SELECTION_TOOL::SetTransitions()
{
Go( &SELECTION_TOOL::Main, COMMON_ACTIONS::selectionActivate.MakeEvent() );
Go( &SELECTION_TOOL::CursorSelection, COMMON_ACTIONS::selectionCursor.MakeEvent() );
@ -489,10 +507,10 @@ SELECTION_LOCK_FLAGS SELECTION_TOOL::CheckLock()
return SELECTION_UNLOCKED;
}
int SELECTION_TOOL::CursorSelection( const TOOL_EVENT& aEvent )
{
selectCursor( getView()->ToWorld( getViewControls()->GetMousePosition() ) );
setTransitions();
return 0;
}
@ -501,15 +519,15 @@ int SELECTION_TOOL::CursorSelection( const TOOL_EVENT& aEvent )
int SELECTION_TOOL::ClearSelection( const TOOL_EVENT& aEvent )
{
clearSelection();
setTransitions();
return 0;
}
int SELECTION_TOOL::SelectItem( const TOOL_EVENT& aEvent )
{
// Check if there is an item to be selected
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aEvent.Parameter() );
BOARD_ITEM* item = aEvent.Parameter<BOARD_ITEM*>();
if( item )
{
@ -519,15 +537,14 @@ int SELECTION_TOOL::SelectItem( const TOOL_EVENT& aEvent )
m_toolMgr->ProcessEvent( SelectedEvent );
}
setTransitions();
return 0;
}
int SELECTION_TOOL::UnselectItem( const TOOL_EVENT& aEvent )
{
// Check if there is an item to be selected
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aEvent.Parameter() );
BOARD_ITEM* item = aEvent.Parameter<BOARD_ITEM*>();
if( item )
{
@ -537,8 +554,6 @@ int SELECTION_TOOL::UnselectItem( const TOOL_EVENT& aEvent )
m_toolMgr->ProcessEvent( UnselectedEvent );
}
setTransitions();
return 0;
}
@ -562,8 +577,6 @@ int SELECTION_TOOL::selectConnection( const TOOL_EVENT& aEvent )
m_toolMgr->ProcessEvent( selectEvent );
}
setTransitions();
return 0;
}
@ -588,8 +601,6 @@ int SELECTION_TOOL::selectNet( const TOOL_EVENT& aEvent )
m_toolMgr->ProcessEvent( selectEvent );
}
setTransitions();
return 0;
}
@ -618,7 +629,6 @@ int SELECTION_TOOL::find( const TOOL_EVENT& aEvent )
dlg.EnableWarp( false );
dlg.SetCallback( boost::bind( &SELECTION_TOOL::findCallback, this, _1 ) );
dlg.ShowModal();
setTransitions();
return 0;
}
@ -635,8 +645,6 @@ int SELECTION_TOOL::findMove( const TOOL_EVENT& aEvent )
m_toolMgr->InvokeTool( "pcbnew.InteractiveEdit" );
}
setTransitions();
return 0;
}
@ -1293,38 +1301,6 @@ bool SELECTION_TOOL::SanitizeSelection()
}
void SELECTION_TOOL::generateMenu()
{
// Create a copy of the master context menu
m_menuCopy = m_menu;
assert( m_menuCopy.GetMenuItemCount() == m_menuConditions.size() );
// Filter out entries that does not apply to the current selection
for( int i = m_menuCopy.GetMenuItemCount() - 1; i >= 0; --i )
{
try
{
if( !m_menuConditions[i]( m_selection ) )
{
wxMenuItem* item = m_menuCopy.FindItemByPosition( i );
m_menuCopy.Destroy( item );
}
}
catch( boost::bad_function_call )
{
// If it is not possible to determine if a menu entry should be
// shown or not - do not let users pick non-existing options
wxMenuItem* item = m_menuCopy.FindItemByPosition( i );
m_menuCopy.Destroy( item );
}
}
if( m_menuCopy.GetMenuItemCount() > 0 )
SetContextMenu( &m_menuCopy, CMENU_NOW );
}
void SELECTION::clear()
{
items.ClearItemsList();

View File

@ -32,6 +32,7 @@
#include <class_undoredo_container.h>
#include "selection_conditions.h"
#include "conditional_menu.h"
class PCB_BASE_FRAME;
class SELECTION_AREA;
@ -104,7 +105,10 @@ public:
SELECTION_TOOL();
~SELECTION_TOOL();
/// @copydoc TOOL_INTERACTIVE::Reset()
/// @copydoc TOOL_BASE::Init()
bool Init();
/// @copydoc TOOL_BASE::Reset()
void Reset( RESET_REASON aReason );
/**
@ -119,32 +123,13 @@ public:
*
* Returns the set of currently selected items.
*/
const SELECTION& GetSelection() const
inline const SELECTION& GetSelection()
{
// The selected items list has been requested, so it is no longer preliminary
m_preliminary = false;
return m_selection;
}
/**
* Function AddMenuItem()
*
* Adds a menu entry to run a TOOL_ACTION on selected items.
* @param aAction is a menu entry to be added.
* @param aCondition is a condition that has to be fulfilled to enable the menu entry.
*/
void AddMenuItem( const TOOL_ACTION& aAction,
const SELECTION_CONDITION& aCondition = SELECTION_CONDITIONS::ShowAlways );
/**
* Function AddSubMenu()
*
* Adds a submenu to the selection tool right-click context menu.
* @param aMenu is the submenu to be added.
* @param aLabel is the label of added submenu.
* @param aCondition is a condition that has to be fulfilled to enable the submenu entry.
*/
void AddSubMenu( CONTEXT_MENU* aMenu, const wxString& aLabel,
const SELECTION_CONDITION& aCondition = SELECTION_CONDITIONS::ShowAlways );
/**
* Function EditModules()
*
@ -152,11 +137,16 @@ public:
* (graphics, pads, etc.), so they can be modified.
* @param aEnabled decides if the mode should be enabled.
*/
void EditModules( bool aEnabled )
inline void EditModules( bool aEnabled )
{
m_editModules = aEnabled;
}
inline CONDITIONAL_MENU& GetMenu()
{
return m_menu;
}
///> Checks if the user has agreed to modify locked items for the given selection.
SELECTION_LOCK_FLAGS CheckLock();
@ -166,8 +156,8 @@ public:
///> Clear current selection event handler.
int ClearSelection( const TOOL_EVENT& aEvent );
///> Makes sure a group selection does not contain items that would cause
///> conflicts when moving/rotating together (e.g. a footprint and one of the same footprint's pads)
///> Makes sure a group selection does not contain items that would cause
///> conflicts when moving/rotating together (e.g. a footprint and one of the same footprint's pads)
bool SanitizeSelection();
///> Item selection event handler.
@ -185,6 +175,9 @@ public:
///> Event sent after selection is cleared.
static const TOOL_EVENT ClearedEvent;
///> Sets up handlers for various events.
void SetTransitions();
private:
/**
* Function selectCursor()
@ -221,9 +214,6 @@ private:
///> Find an item and start moving.
int findMove( const TOOL_EVENT& aEvent );
///> Sets up handlers for various events.
void setTransitions();
/**
* Function clearSelection()
* Clears the current selection.
@ -317,19 +307,9 @@ private:
*/
void guessSelectionCandidates( GENERAL_COLLECTOR& aCollector ) const;
/**
* Function generateMenu()
* Creates a copy of context menu that is filtered by menu conditions and displayed to
* the user.
*/
void generateMenu();
/// Pointer to the parent frame.
PCB_BASE_FRAME* m_frame;
/// Visual representation of selection box.
SELECTION_AREA* m_selArea;
/// Current state of selection.
SELECTION m_selection;
@ -339,20 +319,17 @@ private:
/// Flag saying if multiple selection mode is active.
bool m_multiple;
/// Right click popup menu (master instance).
CONTEXT_MENU m_menu;
/// Copy of the context menu that is filtered by menu conditions and displayed to the user.
CONTEXT_MENU m_menuCopy;
/// Edit module mode flag.
bool m_editModules;
/// Can other tools modify locked items.
bool m_locked;
/// Conditions for specific context menu entries.
std::deque<SELECTION_CONDITION> m_menuConditions;
/// Determines if the selection is preliminary or final.
bool m_preliminary;
/// Menu displayed by the tool.
CONDITIONAL_MENU m_menu;
};
#endif