2014-03-24 07:45:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 CERN
|
|
|
|
* @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
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pcbnew_control.h"
|
|
|
|
#include "common_actions.h"
|
2015-06-18 15:51:51 +00:00
|
|
|
#include "selection_tool.h"
|
|
|
|
#include "picker_tool.h"
|
2015-06-30 12:08:24 +00:00
|
|
|
#include "grid_helper.h"
|
2014-03-24 07:45:05 +00:00
|
|
|
|
|
|
|
#include <class_board.h>
|
2014-07-09 13:02:56 +00:00
|
|
|
#include <class_module.h>
|
2014-03-24 16:20:23 +00:00
|
|
|
#include <class_track.h>
|
2014-07-09 13:02:56 +00:00
|
|
|
#include <class_zone.h>
|
2014-03-24 07:45:05 +00:00
|
|
|
#include <class_pcb_screen.h>
|
2015-08-07 16:24:42 +00:00
|
|
|
|
2014-03-24 17:28:21 +00:00
|
|
|
#include <confirm.h>
|
2015-06-18 15:51:52 +00:00
|
|
|
#include <hotkeys_basic.h>
|
2015-08-07 16:24:42 +00:00
|
|
|
#include <io_mgr.h>
|
2014-03-24 07:45:05 +00:00
|
|
|
|
2015-08-07 16:24:42 +00:00
|
|
|
#include <pcbnew_id.h>
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <pcb_draw_panel_gal.h>
|
|
|
|
#include <ratsnest_data.h>
|
2015-06-18 15:51:52 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2014-03-24 16:20:23 +00:00
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
|
|
|
#include <view/view_controls.h>
|
|
|
|
#include <pcb_painter.h>
|
2015-06-18 15:51:53 +00:00
|
|
|
#include <origin_viewitem.h>
|
2014-03-24 07:45:05 +00:00
|
|
|
|
2015-06-18 15:51:51 +00:00
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
2014-07-09 14:57:01 +00:00
|
|
|
|
2015-08-07 16:24:42 +00:00
|
|
|
// files.cpp
|
|
|
|
extern bool AskLoadBoardFileName( wxWindow* aParent, int* aCtl, wxString* aFileName,
|
|
|
|
bool aKicadFilesOnly = false );
|
|
|
|
extern IO_MGR::PCB_FILE_T plugin_type( const wxString& aFileName, int aCtl );
|
|
|
|
|
|
|
|
|
2014-03-24 07:45:05 +00:00
|
|
|
PCBNEW_CONTROL::PCBNEW_CONTROL() :
|
2015-02-15 22:21:52 +00:00
|
|
|
TOOL_INTERACTIVE( "pcbnew.Control" ), m_frame( NULL )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
2015-06-18 15:51:53 +00:00
|
|
|
m_gridOrigin = new KIGFX::ORIGIN_VIEWITEM();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PCBNEW_CONTROL::~PCBNEW_CONTROL()
|
|
|
|
{
|
|
|
|
delete m_gridOrigin;
|
2014-03-24 07:45:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-24 16:20:23 +00:00
|
|
|
void PCBNEW_CONTROL::Reset( RESET_REASON aReason )
|
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
m_frame = getEditFrame<PCB_BASE_FRAME>();
|
2015-06-18 15:51:53 +00:00
|
|
|
|
|
|
|
if( aReason == MODEL_RELOAD || aReason == GAL_SWITCH )
|
|
|
|
{
|
|
|
|
m_gridOrigin->SetPosition( getModel<BOARD>()->GetGridOrigin() );
|
|
|
|
getView()->Remove( m_gridOrigin );
|
|
|
|
getView()->Add( m_gridOrigin );
|
|
|
|
}
|
2014-03-24 16:20:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::ZoomInOut( const TOOL_EVENT& aEvent )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
2014-03-24 16:20:23 +00:00
|
|
|
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
|
2015-07-24 07:42:45 +00:00
|
|
|
KIGFX::VIEW_CONTROLS* ctls = getViewControls();
|
2014-05-13 09:22:51 +00:00
|
|
|
double zoomScale = 1.0;
|
2014-03-24 16:20:23 +00:00
|
|
|
|
|
|
|
if( aEvent.IsAction( &COMMON_ACTIONS::zoomIn ) )
|
2014-05-13 09:22:51 +00:00
|
|
|
zoomScale = 1.3;
|
2014-03-24 16:20:23 +00:00
|
|
|
else if( aEvent.IsAction( &COMMON_ACTIONS::zoomOut ) )
|
2014-05-13 09:22:51 +00:00
|
|
|
zoomScale = 0.7;
|
2014-03-24 16:20:23 +00:00
|
|
|
|
2015-07-24 07:42:45 +00:00
|
|
|
view->SetScale( view->GetScale() * zoomScale, getViewControls()->GetCursorPosition() );
|
|
|
|
|
|
|
|
if( ctls->IsCursorWarpingEnabled() )
|
|
|
|
ctls->CenterOnCursor();
|
2014-03-24 07:45:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::ZoomInOutCenter( const TOOL_EVENT& aEvent )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
2015-07-24 07:42:45 +00:00
|
|
|
KIGFX::VIEW* view = getView();
|
2014-05-13 09:22:51 +00:00
|
|
|
double zoomScale = 1.0;
|
2014-03-24 16:20:23 +00:00
|
|
|
|
2014-07-09 09:22:42 +00:00
|
|
|
if( aEvent.IsAction( &COMMON_ACTIONS::zoomInCenter ) )
|
2014-05-13 09:22:51 +00:00
|
|
|
zoomScale = 1.3;
|
2014-07-09 09:22:42 +00:00
|
|
|
else if( aEvent.IsAction( &COMMON_ACTIONS::zoomOutCenter ) )
|
2014-05-13 09:22:51 +00:00
|
|
|
zoomScale = 0.7;
|
2014-03-24 16:20:23 +00:00
|
|
|
|
2014-05-13 09:22:51 +00:00
|
|
|
view->SetScale( view->GetScale() * zoomScale );
|
2014-03-24 07:45:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::ZoomCenter( const TOOL_EVENT& aEvent )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
2015-07-24 07:42:45 +00:00
|
|
|
KIGFX::VIEW_CONTROLS* ctls = getViewControls();
|
2014-03-24 07:45:05 +00:00
|
|
|
|
2015-07-24 07:42:45 +00:00
|
|
|
if( ctls->IsCursorWarpingEnabled() )
|
|
|
|
ctls->CenterOnCursor();
|
|
|
|
else
|
|
|
|
getView()->SetCenter( getViewControls()->GetCursorPosition() );
|
2015-07-09 15:09:34 +00:00
|
|
|
|
2014-03-24 07:45:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::ZoomFitScreen( const TOOL_EVENT& aEvent )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
2015-07-01 01:46:42 +00:00
|
|
|
KIGFX::VIEW* view = getView();
|
|
|
|
EDA_DRAW_PANEL_GAL* galCanvas = m_frame->GetGalCanvas();
|
2014-07-23 10:06:24 +00:00
|
|
|
BOARD* board = getModel<BOARD>();
|
|
|
|
board->ComputeBoundingBox();
|
2015-07-01 01:46:42 +00:00
|
|
|
|
2014-07-23 10:06:24 +00:00
|
|
|
BOX2I boardBBox = board->ViewBBox();
|
2015-07-03 18:58:13 +00:00
|
|
|
VECTOR2D scrollbarSize = VECTOR2D( galCanvas->GetSize() - galCanvas->GetClientSize() );
|
2015-07-24 07:42:45 +00:00
|
|
|
VECTOR2D screenSize = view->ToWorld( galCanvas->GetClientSize(), false );
|
2014-03-24 16:20:23 +00:00
|
|
|
|
2015-07-01 01:46:42 +00:00
|
|
|
if( boardBBox.GetWidth() == 0 || boardBBox.GetHeight() == 0 )
|
2014-07-09 13:10:32 +00:00
|
|
|
{
|
|
|
|
// Empty view
|
2015-07-03 18:58:13 +00:00
|
|
|
view->SetScale( 17.0 ); // works fine for the standard worksheet frame
|
|
|
|
|
|
|
|
view->SetCenter( screenSize / 2.0 );
|
2014-07-09 13:10:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-03 18:58:13 +00:00
|
|
|
VECTOR2D vsize = boardBBox.GetSize();
|
|
|
|
double scale = view->GetScale() / std::max( fabs( vsize.x / screenSize.x ),
|
|
|
|
fabs( vsize.y / screenSize.y ) );
|
|
|
|
|
|
|
|
view->SetScale( scale );
|
|
|
|
view->SetCenter( boardBBox.Centre() );
|
2014-07-09 13:10:32 +00:00
|
|
|
}
|
2014-03-24 16:20:23 +00:00
|
|
|
|
2015-07-03 18:58:13 +00:00
|
|
|
|
|
|
|
// Take scrollbars into account
|
|
|
|
VECTOR2D worldScrollbarSize = view->ToWorld( scrollbarSize, false );
|
|
|
|
view->SetCenter( view->GetCenter() + worldScrollbarSize / 2.0 );
|
|
|
|
|
2014-03-24 07:45:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-30 08:46:02 +00:00
|
|
|
int PCBNEW_CONTROL::ZoomPreset( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
unsigned int idx = aEvent.Parameter<long>();
|
2015-05-01 09:31:23 +00:00
|
|
|
std::vector<double>& zoomList = m_frame->GetScreen()->m_ZoomList;
|
2015-04-30 08:46:02 +00:00
|
|
|
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
|
|
|
|
KIGFX::GAL* gal = m_frame->GetGalCanvas()->GetGAL();
|
|
|
|
|
|
|
|
m_frame->SetPresetZoom( idx );
|
|
|
|
|
2015-04-30 08:46:06 +00:00
|
|
|
if( idx == 0 ) // Zoom Auto
|
|
|
|
{
|
2015-04-30 08:46:02 +00:00
|
|
|
return ZoomFitScreen( aEvent );
|
2015-04-30 08:46:06 +00:00
|
|
|
}
|
2015-05-03 06:31:14 +00:00
|
|
|
else if( idx >= zoomList.size() )
|
2015-04-30 08:46:06 +00:00
|
|
|
{
|
|
|
|
assert( false );
|
2015-04-30 08:46:02 +00:00
|
|
|
return 0;
|
2015-04-30 08:46:06 +00:00
|
|
|
}
|
2015-04-30 08:46:02 +00:00
|
|
|
|
|
|
|
double selectedZoom = zoomList[idx];
|
|
|
|
double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor();
|
|
|
|
view->SetScale( 1.0 / ( zoomFactor * selectedZoom ) );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::TrackDisplayMode( const TOOL_EVENT& aEvent )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
2014-03-24 16:20:23 +00:00
|
|
|
KIGFX::PCB_PAINTER* painter =
|
|
|
|
static_cast<KIGFX::PCB_PAINTER*>( m_frame->GetGalCanvas()->GetView()->GetPainter() );
|
|
|
|
KIGFX::PCB_RENDER_SETTINGS* settings =
|
2014-07-09 13:02:56 +00:00
|
|
|
static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() );
|
2014-03-24 16:20:23 +00:00
|
|
|
|
|
|
|
// Apply new display options to the GAL canvas
|
2015-01-10 10:27:49 +00:00
|
|
|
DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)m_frame->GetDisplayOptions();
|
|
|
|
displ_opts->m_DisplayPcbTrackFill = !displ_opts->m_DisplayPcbTrackFill;
|
|
|
|
settings->LoadDisplayOptions( displ_opts );
|
2014-03-24 16:20:23 +00:00
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
for( TRACK* track = getModel<BOARD>()->m_Track; track; track = track->Next() )
|
|
|
|
{
|
|
|
|
if( track->Type() == PCB_TRACE_T )
|
|
|
|
track->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
|
|
|
}
|
2014-03-24 16:20:23 +00:00
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
m_frame->GetGalCanvas()->Refresh();
|
2014-03-24 07:45:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::PadDisplayMode( const TOOL_EVENT& aEvent )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
2014-07-09 13:02:56 +00:00
|
|
|
KIGFX::PCB_PAINTER* painter =
|
|
|
|
static_cast<KIGFX::PCB_PAINTER*>( m_frame->GetGalCanvas()->GetView()->GetPainter() );
|
|
|
|
KIGFX::PCB_RENDER_SETTINGS* settings =
|
|
|
|
static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() );
|
2015-01-10 10:27:49 +00:00
|
|
|
DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)m_frame->GetDisplayOptions();
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
// Apply new display options to the GAL canvas
|
2015-01-10 10:27:49 +00:00
|
|
|
displ_opts->m_DisplayPadFill = !displ_opts->m_DisplayPadFill;
|
|
|
|
settings->LoadDisplayOptions( displ_opts );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
for( MODULE* module = getModel<BOARD>()->m_Modules; module; module = module->Next() )
|
|
|
|
{
|
|
|
|
for( D_PAD* pad = module->Pads(); pad; pad = pad->Next() )
|
|
|
|
pad->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_frame->GetGalCanvas()->Refresh();
|
2014-03-24 07:45:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::ViaDisplayMode( const TOOL_EVENT& aEvent )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
2014-03-24 16:20:23 +00:00
|
|
|
KIGFX::PCB_PAINTER* painter =
|
|
|
|
static_cast<KIGFX::PCB_PAINTER*>( m_frame->GetGalCanvas()->GetView()->GetPainter() );
|
|
|
|
KIGFX::PCB_RENDER_SETTINGS* settings =
|
2014-07-09 13:02:56 +00:00
|
|
|
static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() );
|
2015-01-10 10:27:49 +00:00
|
|
|
DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)m_frame->GetDisplayOptions();
|
2014-03-24 16:20:23 +00:00
|
|
|
|
|
|
|
// Apply new display options to the GAL canvas
|
2015-01-10 10:27:49 +00:00
|
|
|
displ_opts->m_DisplayViaFill = !displ_opts->m_DisplayViaFill;
|
|
|
|
settings->LoadDisplayOptions( displ_opts );
|
2014-03-24 16:20:23 +00:00
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
for( TRACK* track = getModel<BOARD>()->m_Track; track; track = track->Next() )
|
2014-03-24 16:20:23 +00:00
|
|
|
{
|
|
|
|
if( track->Type() == PCB_VIA_T )
|
|
|
|
track->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
|
|
|
}
|
|
|
|
|
2014-07-09 13:02:56 +00:00
|
|
|
m_frame->GetGalCanvas()->Refresh();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::ZoneDisplayMode( const TOOL_EVENT& aEvent )
|
2014-07-09 13:02:56 +00:00
|
|
|
{
|
|
|
|
KIGFX::PCB_PAINTER* painter =
|
|
|
|
static_cast<KIGFX::PCB_PAINTER*>( m_frame->GetGalCanvas()->GetView()->GetPainter() );
|
|
|
|
KIGFX::PCB_RENDER_SETTINGS* settings =
|
|
|
|
static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() );
|
2015-01-10 10:27:49 +00:00
|
|
|
DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)m_frame->GetDisplayOptions();
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
// Apply new display options to the GAL canvas
|
|
|
|
if( aEvent.IsAction( &COMMON_ACTIONS::zoneDisplayEnable ) )
|
2015-01-10 10:27:49 +00:00
|
|
|
displ_opts->m_DisplayZonesMode = 0;
|
2014-07-09 13:02:56 +00:00
|
|
|
else if( aEvent.IsAction( &COMMON_ACTIONS::zoneDisplayDisable ) )
|
2015-01-10 10:27:49 +00:00
|
|
|
displ_opts->m_DisplayZonesMode = 1;
|
2014-07-09 13:02:56 +00:00
|
|
|
else if( aEvent.IsAction( &COMMON_ACTIONS::zoneDisplayOutlines ) )
|
2015-01-10 10:27:49 +00:00
|
|
|
displ_opts->m_DisplayZonesMode = 2;
|
2014-07-09 13:02:56 +00:00
|
|
|
else
|
|
|
|
assert( false );
|
|
|
|
|
2015-01-10 10:27:49 +00:00
|
|
|
settings->LoadDisplayOptions( displ_opts );
|
2014-07-09 13:02:56 +00:00
|
|
|
|
|
|
|
BOARD* board = getModel<BOARD>();
|
|
|
|
for( int i = 0; i < board->GetAreaCount(); ++i )
|
|
|
|
board->GetArea( i )->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
|
|
|
|
|
|
|
|
m_frame->GetGalCanvas()->Refresh();
|
2014-03-24 07:45:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::HighContrastMode( const TOOL_EVENT& aEvent )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
2014-03-24 16:20:23 +00:00
|
|
|
KIGFX::PCB_PAINTER* painter =
|
|
|
|
static_cast<KIGFX::PCB_PAINTER*>( m_frame->GetGalCanvas()->GetView()->GetPainter() );
|
|
|
|
KIGFX::PCB_RENDER_SETTINGS* settings =
|
|
|
|
static_cast<KIGFX::PCB_RENDER_SETTINGS*> ( painter->GetSettings() );
|
2015-01-10 10:27:49 +00:00
|
|
|
DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)m_frame->GetDisplayOptions();
|
2014-03-24 16:20:23 +00:00
|
|
|
|
2015-01-10 10:27:49 +00:00
|
|
|
displ_opts->m_ContrastModeDisplay = !displ_opts->m_ContrastModeDisplay;
|
|
|
|
settings->LoadDisplayOptions( displ_opts );
|
2014-07-09 08:57:32 +00:00
|
|
|
m_frame->GetGalCanvas()->SetHighContrastLayer( m_frame->GetActiveLayer() );
|
2014-03-24 16:20:23 +00:00
|
|
|
|
2014-03-24 07:45:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::HighContrastInc( const TOOL_EVENT& aEvent )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
|
|
|
std::cout << __PRETTY_FUNCTION__ << std::endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::HighContrastDec( const TOOL_EVENT& aEvent )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
|
|
|
std::cout << __PRETTY_FUNCTION__ << std::endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Layer control
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::LayerSwitch( const TOOL_EVENT& aEvent )
|
2014-07-09 14:25:50 +00:00
|
|
|
{
|
2015-04-30 08:46:01 +00:00
|
|
|
m_frame->SwitchLayer( NULL, (LAYER_ID) aEvent.Parameter<long>() );
|
2014-03-24 07:45:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::LayerNext( const TOOL_EVENT& aEvent )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
PCB_BASE_FRAME* editFrame = m_frame;
|
|
|
|
LAYER_NUM layer = editFrame->GetActiveLayer();
|
2014-06-06 12:59:55 +00:00
|
|
|
|
2014-07-09 14:25:50 +00:00
|
|
|
if( layer < F_Cu || layer > B_Cu )
|
2014-06-06 12:59:55 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-07-09 14:25:50 +00:00
|
|
|
int layerCount = getModel<BOARD>()->GetCopperLayerCount();
|
|
|
|
|
|
|
|
if( layer == layerCount - 2 || layerCount < 2 )
|
2014-06-24 16:17:18 +00:00
|
|
|
layer = B_Cu;
|
2014-07-09 14:25:50 +00:00
|
|
|
else if( layer == B_Cu )
|
2014-07-09 09:50:27 +00:00
|
|
|
layer = F_Cu;
|
2014-06-06 12:59:55 +00:00
|
|
|
else
|
|
|
|
++layer;
|
2014-03-24 07:45:05 +00:00
|
|
|
|
2014-07-09 14:44:22 +00:00
|
|
|
assert( IsCopperLayer( layer ) );
|
2014-06-29 13:05:51 +00:00
|
|
|
editFrame->SwitchLayer( NULL, ToLAYER_ID( layer ) );
|
2014-03-24 07:45:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::LayerPrev( const TOOL_EVENT& aEvent )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
PCB_BASE_FRAME* editFrame = m_frame;
|
|
|
|
LAYER_NUM layer = editFrame->GetActiveLayer();
|
2014-03-24 07:45:05 +00:00
|
|
|
|
2014-07-09 14:25:50 +00:00
|
|
|
if( layer < F_Cu || layer > B_Cu )
|
2014-06-06 12:59:55 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-07-09 14:25:50 +00:00
|
|
|
int layerCount = getModel<BOARD>()->GetCopperLayerCount();
|
|
|
|
|
|
|
|
if( layer == F_Cu || layerCount < 2 )
|
2014-06-24 16:17:18 +00:00
|
|
|
layer = B_Cu;
|
|
|
|
else if( layer == B_Cu )
|
2014-07-09 14:25:50 +00:00
|
|
|
layer = layerCount - 2;
|
2014-06-06 12:59:55 +00:00
|
|
|
else
|
|
|
|
--layer;
|
2014-03-24 07:45:05 +00:00
|
|
|
|
|
|
|
assert( IsCopperLayer( layer ) );
|
2014-06-29 13:05:51 +00:00
|
|
|
editFrame->SwitchLayer( NULL, ToLAYER_ID( layer ) );
|
2014-03-24 07:45:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
int PCBNEW_CONTROL::LayerToggle( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
LAYER_NUM currentLayer = m_frame->GetActiveLayer();
|
|
|
|
PCB_SCREEN* screen = m_frame->GetScreen();
|
|
|
|
|
|
|
|
if( currentLayer == screen->m_Route_Layer_TOP )
|
|
|
|
m_frame->SwitchLayer( NULL, screen->m_Route_Layer_BOTTOM );
|
|
|
|
else
|
|
|
|
m_frame->SwitchLayer( NULL, screen->m_Route_Layer_TOP );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::LayerAlphaInc( const TOOL_EVENT& aEvent )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
2014-03-24 17:28:21 +00:00
|
|
|
KIGFX::PCB_PAINTER* painter =
|
|
|
|
static_cast<KIGFX::PCB_PAINTER*>( m_frame->GetGalCanvas()->GetView()->GetPainter() );
|
|
|
|
KIGFX::PCB_RENDER_SETTINGS* settings =
|
|
|
|
static_cast<KIGFX::PCB_RENDER_SETTINGS*> ( painter->GetSettings() );
|
|
|
|
|
|
|
|
LAYER_NUM currentLayer = m_frame->GetActiveLayer();
|
|
|
|
KIGFX::COLOR4D currentColor = settings->GetLayerColor( currentLayer );
|
|
|
|
|
|
|
|
if( currentColor.a <= 0.95 )
|
|
|
|
{
|
|
|
|
currentColor.a += 0.05;
|
|
|
|
settings->SetLayerColor( currentLayer, currentColor );
|
|
|
|
m_frame->GetGalCanvas()->GetView()->UpdateLayerColor( currentLayer );
|
|
|
|
}
|
|
|
|
|
2014-03-24 07:45:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::LayerAlphaDec( const TOOL_EVENT& aEvent )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
2014-03-24 17:28:21 +00:00
|
|
|
KIGFX::PCB_PAINTER* painter =
|
|
|
|
static_cast<KIGFX::PCB_PAINTER*>( m_frame->GetGalCanvas()->GetView()->GetPainter() );
|
|
|
|
KIGFX::PCB_RENDER_SETTINGS* settings =
|
|
|
|
static_cast<KIGFX::PCB_RENDER_SETTINGS*> ( painter->GetSettings() );
|
|
|
|
|
|
|
|
LAYER_NUM currentLayer = m_frame->GetActiveLayer();
|
|
|
|
KIGFX::COLOR4D currentColor = settings->GetLayerColor( currentLayer );
|
|
|
|
|
|
|
|
if( currentColor.a >= 0.05 )
|
|
|
|
{
|
|
|
|
currentColor.a -= 0.05;
|
|
|
|
settings->SetLayerColor( currentLayer, currentColor );
|
|
|
|
m_frame->GetGalCanvas()->GetView()->UpdateLayerColor( currentLayer );
|
|
|
|
}
|
|
|
|
|
2014-03-24 07:45:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-30 12:08:24 +00:00
|
|
|
// Cursor control
|
|
|
|
int PCBNEW_CONTROL::CursorControl( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
long type = aEvent.Parameter<long>();
|
|
|
|
bool fastMove = type & COMMON_ACTIONS::CURSOR_FAST_MOVE;
|
|
|
|
type &= ~COMMON_ACTIONS::CURSOR_FAST_MOVE;
|
|
|
|
|
|
|
|
GRID_HELPER gridHelper( m_frame );
|
|
|
|
VECTOR2D cursor = getViewControls()->GetCursorPosition();
|
|
|
|
VECTOR2I gridSize = gridHelper.GetGrid();
|
|
|
|
VECTOR2D newCursor = gridHelper.Align( cursor );
|
|
|
|
|
|
|
|
if( fastMove )
|
|
|
|
gridSize = gridSize * 10;
|
|
|
|
|
|
|
|
switch( type )
|
|
|
|
{
|
|
|
|
case COMMON_ACTIONS::CURSOR_UP:
|
|
|
|
newCursor -= VECTOR2D( 0, gridSize.y );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COMMON_ACTIONS::CURSOR_DOWN:
|
|
|
|
newCursor += VECTOR2D( 0, gridSize.y );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COMMON_ACTIONS::CURSOR_LEFT:
|
|
|
|
newCursor -= VECTOR2D( gridSize.x, 0 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COMMON_ACTIONS::CURSOR_RIGHT:
|
|
|
|
newCursor += VECTOR2D( gridSize.x, 0 );
|
|
|
|
break;
|
|
|
|
|
2015-07-07 16:36:52 +00:00
|
|
|
case COMMON_ACTIONS::CURSOR_CLICK: // fall through
|
2015-06-30 12:08:24 +00:00
|
|
|
case COMMON_ACTIONS::CURSOR_DBL_CLICK:
|
2015-07-07 16:36:52 +00:00
|
|
|
{
|
|
|
|
TOOL_ACTIONS action;
|
|
|
|
int modifiers = 0;
|
|
|
|
|
|
|
|
modifiers |= wxGetKeyState( WXK_SHIFT ) ? MD_SHIFT : 0;
|
|
|
|
modifiers |= wxGetKeyState( WXK_CONTROL ) ? MD_CTRL : 0;
|
|
|
|
modifiers |= wxGetKeyState( WXK_ALT ) ? MD_ALT : 0;
|
|
|
|
|
|
|
|
if( type == COMMON_ACTIONS::CURSOR_CLICK )
|
|
|
|
action = TA_MOUSE_CLICK;
|
|
|
|
else if( type == COMMON_ACTIONS::CURSOR_DBL_CLICK )
|
|
|
|
action = TA_MOUSE_DBLCLICK;
|
|
|
|
else
|
|
|
|
assert( false );
|
|
|
|
|
|
|
|
TOOL_EVENT evt( TC_MOUSE, action, BUT_LEFT | modifiers );
|
|
|
|
evt.SetMousePosition( getViewControls()->GetCursorPosition() );
|
|
|
|
m_toolMgr->ProcessEvent( evt );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2015-06-30 12:08:24 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 16:36:52 +00:00
|
|
|
// Handler cursor movement
|
|
|
|
KIGFX::VIEW* view = getView();
|
|
|
|
newCursor = view->ToScreen( newCursor );
|
2015-07-17 08:26:48 +00:00
|
|
|
newCursor.x = KiROUND( newCursor.x );
|
|
|
|
newCursor.y = KiROUND( newCursor.y );
|
2015-07-07 16:36:52 +00:00
|
|
|
|
|
|
|
// Pan the screen if required
|
|
|
|
const VECTOR2I& screenSize = view->GetGAL()->GetScreenPixelSize();
|
|
|
|
BOX2I screenBox( VECTOR2I( 0, 0 ), screenSize );
|
2015-06-30 12:08:24 +00:00
|
|
|
|
2015-07-07 16:36:52 +00:00
|
|
|
if( !screenBox.Contains( newCursor ) )
|
|
|
|
{
|
|
|
|
VECTOR2D delta( 0, 0 );
|
2015-06-30 12:08:24 +00:00
|
|
|
|
2015-07-07 16:36:52 +00:00
|
|
|
if( newCursor.x < screenBox.GetLeft() )
|
|
|
|
{
|
|
|
|
delta.x = newCursor.x - screenBox.GetLeft();
|
|
|
|
newCursor.x = screenBox.GetLeft();
|
|
|
|
}
|
|
|
|
else if( newCursor.x > screenBox.GetRight() )
|
2015-06-30 12:08:24 +00:00
|
|
|
{
|
2015-07-07 16:36:52 +00:00
|
|
|
delta.x = newCursor.x - screenBox.GetRight();
|
|
|
|
// -1 is to keep the cursor within the drawing area,
|
|
|
|
// so the cursor coordinates are still updated
|
|
|
|
newCursor.x = screenBox.GetRight() - 1;
|
2015-06-30 12:08:24 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 16:36:52 +00:00
|
|
|
if( newCursor.y < screenBox.GetTop() )
|
|
|
|
{
|
|
|
|
delta.y = newCursor.y - screenBox.GetTop();
|
|
|
|
newCursor.y = screenBox.GetTop();
|
|
|
|
}
|
|
|
|
else if( newCursor.y > screenBox.GetBottom() )
|
|
|
|
{
|
|
|
|
delta.y = newCursor.y - screenBox.GetBottom();
|
|
|
|
// -1 is to keep the cursor within the drawing area,
|
|
|
|
// so the cursor coordinates are still updated
|
|
|
|
newCursor.y = screenBox.GetBottom() - 1;
|
|
|
|
}
|
2015-07-03 18:58:12 +00:00
|
|
|
|
2015-07-07 16:36:52 +00:00
|
|
|
view->SetCenter( view->GetCenter() + view->ToWorld( delta, false ) );
|
2015-06-30 12:08:24 +00:00
|
|
|
}
|
|
|
|
|
2015-07-07 16:36:52 +00:00
|
|
|
m_frame->GetGalCanvas()->WarpPointer( newCursor.x, newCursor.y );
|
|
|
|
|
2015-06-30 12:08:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-30 12:08:29 +00:00
|
|
|
int PCBNEW_CONTROL::PanControl( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
long type = aEvent.Parameter<long>();
|
|
|
|
KIGFX::VIEW* view = getView();
|
|
|
|
GRID_HELPER gridHelper( m_frame );
|
|
|
|
VECTOR2D center = view->GetCenter();
|
|
|
|
VECTOR2I gridSize = gridHelper.GetGrid() * 10;
|
|
|
|
|
|
|
|
switch( type )
|
|
|
|
{
|
|
|
|
case COMMON_ACTIONS::CURSOR_UP:
|
|
|
|
center -= VECTOR2D( 0, gridSize.y );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COMMON_ACTIONS::CURSOR_DOWN:
|
|
|
|
center += VECTOR2D( 0, gridSize.y );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COMMON_ACTIONS::CURSOR_LEFT:
|
|
|
|
center -= VECTOR2D( gridSize.x, 0 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COMMON_ACTIONS::CURSOR_RIGHT:
|
|
|
|
center += VECTOR2D( gridSize.x, 0 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert( false );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
view->SetCenter( center );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-24 07:45:05 +00:00
|
|
|
// Grid control
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::GridFast1( const TOOL_EVENT& aEvent )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
m_frame->SetFastGrid1();
|
2015-05-12 10:03:39 +00:00
|
|
|
updateGrid();
|
2014-03-24 07:45:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::GridFast2( const TOOL_EVENT& aEvent )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
m_frame->SetFastGrid2();
|
2015-05-12 10:03:39 +00:00
|
|
|
updateGrid();
|
2014-03-24 07:45:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::GridNext( const TOOL_EVENT& aEvent )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
m_frame->SetNextGrid();
|
2015-05-12 10:03:39 +00:00
|
|
|
updateGrid();
|
2014-03-24 07:45:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::GridPrev( const TOOL_EVENT& aEvent )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
m_frame->SetPrevGrid();
|
2015-05-12 10:03:39 +00:00
|
|
|
updateGrid();
|
2014-03-24 07:45:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-18 15:51:53 +00:00
|
|
|
static bool setOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame,
|
|
|
|
KIGFX::ORIGIN_VIEWITEM* aItem, const VECTOR2D& aPoint )
|
2014-06-04 15:46:43 +00:00
|
|
|
{
|
2015-06-18 15:51:51 +00:00
|
|
|
aFrame->SetGridOrigin( wxPoint( aPoint.x, aPoint.y ) );
|
|
|
|
aView->GetGAL()->SetGridOrigin( aPoint );
|
2015-06-18 15:51:53 +00:00
|
|
|
aItem->SetPosition( aPoint );
|
2015-06-18 15:51:51 +00:00
|
|
|
aView->MarkDirty();
|
2014-06-04 15:46:43 +00:00
|
|
|
|
2015-06-18 15:51:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-06-04 15:46:43 +00:00
|
|
|
|
|
|
|
|
2015-06-18 15:51:51 +00:00
|
|
|
int PCBNEW_CONTROL::GridSetOrigin( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2015-06-30 12:08:03 +00:00
|
|
|
VECTOR2D* origin = aEvent.Parameter<VECTOR2D*>();
|
2015-06-18 15:51:51 +00:00
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
if( origin )
|
|
|
|
{
|
|
|
|
setOrigin( getView(), m_frame, m_gridOrigin, *origin );
|
|
|
|
delete origin;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-24 08:58:47 +00:00
|
|
|
Activate();
|
|
|
|
|
2015-06-30 12:08:03 +00:00
|
|
|
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
|
|
|
|
assert( picker );
|
|
|
|
|
|
|
|
// TODO it will not check the toolbar button in module editor, as it uses a different ID..
|
|
|
|
m_frame->SetToolID( ID_PCB_PLACE_GRID_COORD_BUTT, wxCURSOR_PENCIL, _( "Adjust grid origin" ) );
|
|
|
|
picker->SetClickHandler( boost::bind( setOrigin, getView(), m_frame, m_gridOrigin, _1 ) );
|
|
|
|
picker->Activate();
|
2015-07-24 08:58:47 +00:00
|
|
|
Wait();
|
2015-06-30 12:08:03 +00:00
|
|
|
}
|
2014-06-04 15:46:43 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-30 08:46:04 +00:00
|
|
|
int PCBNEW_CONTROL::GridPreset( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
long idx = aEvent.Parameter<long>();
|
|
|
|
|
|
|
|
m_frame->SetPresetGrid( idx );
|
2015-05-12 10:03:39 +00:00
|
|
|
updateGrid();
|
2015-04-30 08:46:04 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-24 07:45:05 +00:00
|
|
|
// Miscellaneous
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::ResetCoords( const TOOL_EVENT& aEvent )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
2014-03-24 17:28:21 +00:00
|
|
|
VECTOR2I cursorPos = getViewControls()->GetCursorPosition();
|
|
|
|
|
|
|
|
m_frame->GetScreen()->m_O_Curseur = wxPoint( cursorPos.x, cursorPos.y );
|
|
|
|
m_frame->UpdateStatusBar();
|
2014-03-24 07:45:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::SwitchCursor( const TOOL_EVENT& aEvent )
|
2014-07-09 13:10:32 +00:00
|
|
|
{
|
2015-06-26 15:30:41 +00:00
|
|
|
const unsigned int BIG_CURSOR = 8000;
|
2014-07-09 13:10:32 +00:00
|
|
|
const unsigned int SMALL_CURSOR = 80;
|
|
|
|
|
2015-06-26 15:30:41 +00:00
|
|
|
PCB_BASE_FRAME* frame = getEditFrame<PCB_BASE_FRAME>();
|
|
|
|
KIGFX::GAL* gal = frame->GetGalCanvas()->GetGAL();
|
|
|
|
gal->SetCursorSize( frame->GetCursorShape() ? BIG_CURSOR : SMALL_CURSOR );
|
2014-07-09 13:10:32 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::SwitchUnits( const TOOL_EVENT& aEvent )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
2014-03-24 17:28:21 +00:00
|
|
|
// TODO should not it be refactored to pcb_frame member function?
|
|
|
|
wxCommandEvent evt( wxEVT_COMMAND_MENU_SELECTED );
|
|
|
|
|
|
|
|
if( g_UserUnit == INCHES )
|
|
|
|
evt.SetId( ID_TB_OPTIONS_SELECT_UNIT_MM );
|
|
|
|
else
|
|
|
|
evt.SetId( ID_TB_OPTIONS_SELECT_UNIT_INCH );
|
|
|
|
|
|
|
|
m_frame->ProcessEvent( evt );
|
2014-03-24 07:45:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-18 15:51:51 +00:00
|
|
|
static bool deleteItem( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition )
|
|
|
|
{
|
|
|
|
SELECTION_TOOL* selectionTool = aToolMgr->GetTool<SELECTION_TOOL>();
|
|
|
|
assert( selectionTool );
|
|
|
|
|
|
|
|
aToolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
|
|
|
|
aToolMgr->RunAction( COMMON_ACTIONS::selectionCursor, true );
|
|
|
|
selectionTool->SanitizeSelection();
|
|
|
|
|
2015-09-08 09:17:30 +00:00
|
|
|
const SELECTION& selection = selectionTool->GetSelection();
|
|
|
|
|
|
|
|
if( selection.Empty() )
|
2015-06-18 15:51:51 +00:00
|
|
|
return true;
|
|
|
|
|
2015-09-08 09:17:30 +00:00
|
|
|
bool canBeRemoved = ( selection.Item<EDA_ITEM>( 0 )->Type() != PCB_MODULE_T );
|
|
|
|
|
|
|
|
if( canBeRemoved || IsOK( aToolMgr->GetEditFrame(), _( "Are you sure you want to delete item?" ) ) )
|
2015-06-18 15:51:51 +00:00
|
|
|
aToolMgr->RunAction( COMMON_ACTIONS::remove, true );
|
2015-07-24 08:58:47 +00:00
|
|
|
else
|
|
|
|
aToolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
|
2015-06-18 15:51:51 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PCBNEW_CONTROL::DeleteItemCursor( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2015-07-24 08:58:47 +00:00
|
|
|
Activate();
|
|
|
|
|
2015-06-18 15:51:51 +00:00
|
|
|
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
|
|
|
|
assert( picker );
|
|
|
|
|
|
|
|
// TODO it will not check the toolbar button in the module editor, as it uses a different ID..
|
|
|
|
m_frame->SetToolID( ID_PCB_DELETE_ITEM_BUTT, wxCURSOR_PENCIL, _( "Delete item" ) );
|
|
|
|
picker->SetSnapping( false );
|
|
|
|
picker->SetClickHandler( boost::bind( deleteItem, m_toolMgr, _1 ) );
|
|
|
|
picker->Activate();
|
2015-07-24 08:58:47 +00:00
|
|
|
Wait();
|
2015-06-18 15:51:51 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-07 16:24:42 +00:00
|
|
|
int PCBNEW_CONTROL::AppendBoard( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
int open_ctl;
|
|
|
|
wxString fileName;
|
|
|
|
PICKED_ITEMS_LIST undoListPicker;
|
|
|
|
ITEM_PICKER picker( NULL, UR_NEW );
|
|
|
|
|
|
|
|
PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame );
|
|
|
|
BOARD* board = getModel<BOARD>();
|
|
|
|
KIGFX::VIEW* view = getView();
|
|
|
|
|
|
|
|
if( !editFrame )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Pick a file to append
|
|
|
|
if( !AskLoadBoardFileName( editFrame, &open_ctl, &fileName, true ) )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
IO_MGR::PCB_FILE_T pluginType = plugin_type( fileName, open_ctl );
|
|
|
|
PLUGIN::RELEASER pi( IO_MGR::PluginFind( pluginType ) );
|
|
|
|
|
|
|
|
// keep track of existing items, in order to know what are the new items
|
|
|
|
// (for undo command for instance)
|
|
|
|
|
|
|
|
// Tracks are inserted, not appended, so mark the existing tracks to know what are the new tracks
|
|
|
|
for( TRACK* track = board->m_Track; track; track = track->Next() )
|
|
|
|
track->SetFlags( FLAG0 );
|
|
|
|
|
|
|
|
// Other items are appended to the item list, so keep trace to the last existing item is enough
|
|
|
|
MODULE* module = board->m_Modules.GetLast();
|
|
|
|
BOARD_ITEM* drawing = board->m_Drawings.GetLast();
|
|
|
|
int zonescount = board->GetAreaCount();
|
|
|
|
|
|
|
|
// Keep also the count of copper layers, to adjust if necessary
|
|
|
|
int initialCopperLayerCount = board->GetCopperLayerCount();
|
|
|
|
LSET initialEnabledLayers = board->GetEnabledLayers();
|
|
|
|
|
|
|
|
// Load the data
|
|
|
|
try
|
|
|
|
{
|
|
|
|
PROPERTIES props;
|
|
|
|
char xbuf[30];
|
|
|
|
char ybuf[30];
|
|
|
|
|
|
|
|
// EAGLE_PLUGIN can use this info to center the BOARD, but it does not yet.
|
|
|
|
sprintf( xbuf, "%d", editFrame->GetPageSizeIU().x );
|
|
|
|
sprintf( ybuf, "%d", editFrame->GetPageSizeIU().y );
|
|
|
|
|
|
|
|
props["page_width"] = xbuf;
|
|
|
|
props["page_height"] = ybuf;
|
|
|
|
|
|
|
|
editFrame->GetDesignSettings().m_NetClasses.Clear();
|
|
|
|
pi->Load( fileName, board, &props );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
wxString msg = wxString::Format( _( "Error loading board.\n%s" ), GetChars( ioe.errorText ));
|
|
|
|
DisplayError( editFrame, msg );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
|
|
|
|
|
|
|
|
// Process the new items
|
|
|
|
for( TRACK* track = board->m_Track; track; track = track->Next() )
|
|
|
|
{
|
|
|
|
if( track->GetFlags() & FLAG0 )
|
|
|
|
{
|
|
|
|
track->ClearFlags( FLAG0 );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
picker.SetItem( track );
|
|
|
|
undoListPicker.PushItem( picker );
|
|
|
|
view->Add( track );
|
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, track );
|
|
|
|
}
|
|
|
|
|
|
|
|
module = module ? module->Next() : board->m_Modules;
|
|
|
|
|
|
|
|
for( ; module; module = module->Next() )
|
|
|
|
{
|
|
|
|
picker.SetItem( module );
|
|
|
|
undoListPicker.PushItem( picker );
|
|
|
|
|
|
|
|
module->RunOnChildren( boost::bind( &KIGFX::VIEW::Add, view, _1 ) );
|
|
|
|
view->Add( module );
|
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, module );
|
|
|
|
}
|
|
|
|
|
|
|
|
drawing = drawing ? drawing->Next() : board->m_Drawings;
|
|
|
|
|
|
|
|
for( ; drawing; drawing = drawing->Next() )
|
|
|
|
{
|
|
|
|
picker.SetItem( drawing );
|
|
|
|
undoListPicker.PushItem( picker );
|
|
|
|
view->Add( drawing );
|
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, drawing );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( ZONE_CONTAINER* zone = board->GetArea( zonescount ); zone;
|
|
|
|
zone = board->GetArea( zonescount ) )
|
|
|
|
{
|
|
|
|
picker.SetItem( zone );
|
|
|
|
undoListPicker.PushItem( picker );
|
|
|
|
zonescount++;
|
|
|
|
view->Add( zone );
|
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectItem, true, zone );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( undoListPicker.GetCount() == 0 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
editFrame->SaveCopyInUndoList( undoListPicker, UR_NEW );
|
|
|
|
|
|
|
|
// Synchronize layers
|
|
|
|
// we should not ask PLUGINs to do these items:
|
|
|
|
int copperLayerCount = board->GetCopperLayerCount();
|
|
|
|
|
|
|
|
if( copperLayerCount > initialCopperLayerCount )
|
|
|
|
board->SetCopperLayerCount( copperLayerCount );
|
|
|
|
|
|
|
|
// Enable all used layers, and make them visible:
|
|
|
|
LSET enabledLayers = board->GetEnabledLayers();
|
|
|
|
enabledLayers |= initialEnabledLayers;
|
|
|
|
board->SetEnabledLayers( enabledLayers );
|
|
|
|
board->SetVisibleLayers( enabledLayers );
|
|
|
|
editFrame->ReCreateLayerBox();
|
|
|
|
editFrame->ReFillLayerWidget();
|
|
|
|
static_cast<PCB_DRAW_PANEL_GAL*>( editFrame->GetGalCanvas() )->SyncLayersVisibility( board );
|
|
|
|
|
|
|
|
// Ratsnest
|
|
|
|
board->BuildListOfNets();
|
|
|
|
board->SynchronizeNetsAndNetClasses();
|
|
|
|
board->GetRatsnest()->Recalculate();
|
|
|
|
|
|
|
|
// Start dragging the appended board
|
|
|
|
VECTOR2D v( static_cast<BOARD_ITEM*>( undoListPicker.GetPickedItem( 0 ) )->GetPosition() );
|
|
|
|
getViewControls()->WarpCursor( v, true, true );
|
|
|
|
m_toolMgr->InvokeTool( "pcbnew.InteractiveEdit" );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::ShowHelp( const TOOL_EVENT& aEvent )
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
2015-06-18 15:51:52 +00:00
|
|
|
DisplayHotkeyList( m_frame, m_frame->GetHotkeyConfig() );
|
2014-03-24 07:45:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCBNEW_CONTROL::ToBeDone( const TOOL_EVENT& aEvent )
|
2014-07-09 11:50:27 +00:00
|
|
|
{
|
2015-06-18 15:51:51 +00:00
|
|
|
DisplayInfoMessage( m_frame, _( "Not available in OpenGL/Cairo canvases." ) );
|
2014-07-09 11:50:27 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-30 08:46:03 +00:00
|
|
|
void PCBNEW_CONTROL::SetTransitions()
|
2014-03-24 07:45:05 +00:00
|
|
|
{
|
|
|
|
// View controls
|
2014-03-24 16:20:23 +00:00
|
|
|
Go( &PCBNEW_CONTROL::ZoomInOut, COMMON_ACTIONS::zoomIn.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::ZoomInOut, COMMON_ACTIONS::zoomOut.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::ZoomInOutCenter, COMMON_ACTIONS::zoomInCenter.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::ZoomInOutCenter, COMMON_ACTIONS::zoomOutCenter.MakeEvent() );
|
2014-03-24 07:45:05 +00:00
|
|
|
Go( &PCBNEW_CONTROL::ZoomCenter, COMMON_ACTIONS::zoomCenter.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::ZoomFitScreen, COMMON_ACTIONS::zoomFitScreen.MakeEvent() );
|
2015-04-30 08:46:02 +00:00
|
|
|
Go( &PCBNEW_CONTROL::ZoomPreset, COMMON_ACTIONS::zoomPreset.MakeEvent() );
|
2014-03-24 07:45:05 +00:00
|
|
|
|
|
|
|
// Display modes
|
|
|
|
Go( &PCBNEW_CONTROL::TrackDisplayMode, COMMON_ACTIONS::trackDisplayMode.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::PadDisplayMode, COMMON_ACTIONS::padDisplayMode.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::ViaDisplayMode, COMMON_ACTIONS::viaDisplayMode.MakeEvent() );
|
2014-07-09 13:02:56 +00:00
|
|
|
Go( &PCBNEW_CONTROL::ZoneDisplayMode, COMMON_ACTIONS::zoneDisplayEnable.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::ZoneDisplayMode, COMMON_ACTIONS::zoneDisplayDisable.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::ZoneDisplayMode, COMMON_ACTIONS::zoneDisplayOutlines.MakeEvent() );
|
2014-03-24 07:45:05 +00:00
|
|
|
Go( &PCBNEW_CONTROL::HighContrastMode, COMMON_ACTIONS::highContrastMode.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::HighContrastInc, COMMON_ACTIONS::highContrastInc.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::HighContrastDec, COMMON_ACTIONS::highContrastDec.MakeEvent() );
|
|
|
|
|
|
|
|
// Layer control
|
2014-07-09 14:25:50 +00:00
|
|
|
Go( &PCBNEW_CONTROL::LayerSwitch, COMMON_ACTIONS::layerTop.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::LayerSwitch, COMMON_ACTIONS::layerInner1.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::LayerSwitch, COMMON_ACTIONS::layerInner2.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::LayerSwitch, COMMON_ACTIONS::layerInner3.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::LayerSwitch, COMMON_ACTIONS::layerInner4.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::LayerSwitch, COMMON_ACTIONS::layerInner5.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::LayerSwitch, COMMON_ACTIONS::layerInner6.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::LayerSwitch, COMMON_ACTIONS::layerBottom.MakeEvent() );
|
2014-03-24 07:45:05 +00:00
|
|
|
Go( &PCBNEW_CONTROL::LayerNext, COMMON_ACTIONS::layerNext.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::LayerPrev, COMMON_ACTIONS::layerPrev.MakeEvent() );
|
2015-05-18 11:48:11 +00:00
|
|
|
Go( &PCBNEW_CONTROL::LayerToggle, COMMON_ACTIONS::layerToggle.MakeEvent() );
|
2014-03-24 07:45:05 +00:00
|
|
|
Go( &PCBNEW_CONTROL::LayerAlphaInc, COMMON_ACTIONS::layerAlphaInc.MakeEvent() );
|
2015-05-18 11:48:11 +00:00
|
|
|
Go( &PCBNEW_CONTROL::LayerAlphaDec, COMMON_ACTIONS::layerAlphaDec.MakeEvent() );
|
2014-03-24 07:45:05 +00:00
|
|
|
|
2015-06-30 12:08:24 +00:00
|
|
|
// Cursor control
|
|
|
|
Go( &PCBNEW_CONTROL::CursorControl, COMMON_ACTIONS::cursorUp.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::CursorControl, COMMON_ACTIONS::cursorDown.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::CursorControl, COMMON_ACTIONS::cursorLeft.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::CursorControl, COMMON_ACTIONS::cursorRight.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::CursorControl, COMMON_ACTIONS::cursorUpFast.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::CursorControl, COMMON_ACTIONS::cursorDownFast.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::CursorControl, COMMON_ACTIONS::cursorLeftFast.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::CursorControl, COMMON_ACTIONS::cursorRightFast.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::CursorControl, COMMON_ACTIONS::cursorClick.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::CursorControl, COMMON_ACTIONS::cursorDblClick.MakeEvent() );
|
|
|
|
|
2015-06-30 12:08:29 +00:00
|
|
|
// Pan control
|
|
|
|
Go( &PCBNEW_CONTROL::PanControl, COMMON_ACTIONS::panUp.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::PanControl, COMMON_ACTIONS::panDown.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::PanControl, COMMON_ACTIONS::panLeft.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::PanControl, COMMON_ACTIONS::panRight.MakeEvent() );
|
|
|
|
|
2014-03-24 07:45:05 +00:00
|
|
|
// Grid control
|
|
|
|
Go( &PCBNEW_CONTROL::GridFast1, COMMON_ACTIONS::gridFast1.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::GridFast2, COMMON_ACTIONS::gridFast2.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::GridNext, COMMON_ACTIONS::gridNext.MakeEvent() );
|
|
|
|
Go( &PCBNEW_CONTROL::GridPrev, COMMON_ACTIONS::gridPrev.MakeEvent() );
|
2014-06-04 15:46:43 +00:00
|
|
|
Go( &PCBNEW_CONTROL::GridSetOrigin, COMMON_ACTIONS::gridSetOrigin.MakeEvent() );
|
2015-04-30 08:46:04 +00:00
|
|
|
Go( &PCBNEW_CONTROL::GridPreset, COMMON_ACTIONS::gridPreset.MakeEvent() );
|
2014-03-24 07:45:05 +00:00
|
|
|
|
|
|
|
// Miscellaneous
|
|
|
|
Go( &PCBNEW_CONTROL::ResetCoords, COMMON_ACTIONS::resetCoords.MakeEvent() );
|
2014-07-09 13:10:32 +00:00
|
|
|
Go( &PCBNEW_CONTROL::SwitchCursor, COMMON_ACTIONS::switchCursor.MakeEvent() );
|
2014-03-24 07:45:05 +00:00
|
|
|
Go( &PCBNEW_CONTROL::SwitchUnits, COMMON_ACTIONS::switchUnits.MakeEvent() );
|
2015-06-18 15:51:51 +00:00
|
|
|
Go( &PCBNEW_CONTROL::DeleteItemCursor, COMMON_ACTIONS::deleteItemCursor.MakeEvent() );
|
2015-08-07 16:24:42 +00:00
|
|
|
Go( &PCBNEW_CONTROL::AppendBoard, COMMON_ACTIONS::appendBoard.MakeEvent() );
|
2014-03-24 07:45:05 +00:00
|
|
|
Go( &PCBNEW_CONTROL::ShowHelp, COMMON_ACTIONS::showHelp.MakeEvent() );
|
2014-07-09 11:50:27 +00:00
|
|
|
Go( &PCBNEW_CONTROL::ToBeDone, COMMON_ACTIONS::toBeDone.MakeEvent() );
|
2014-03-24 07:45:05 +00:00
|
|
|
}
|
2015-05-12 10:03:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
void PCBNEW_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 );
|
|
|
|
}
|