2013-09-18 17:55:16 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 CERN
|
|
|
|
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* 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 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* 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.
|
2013-09-26 21:53:54 +00:00
|
|
|
*
|
2013-09-18 17:55:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
2014-05-14 13:53:54 +00:00
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-09-18 17:55:16 +00:00
|
|
|
*/
|
|
|
|
|
2014-06-24 16:17:18 +00:00
|
|
|
#include <wx/numdlg.h>
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
#include <boost/optional.hpp>
|
2014-05-14 13:53:54 +00:00
|
|
|
#include <boost/bind.hpp>
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-04-04 09:56:04 +00:00
|
|
|
#include "class_draw_panel_gal.h"
|
2013-09-18 17:55:16 +00:00
|
|
|
#include "class_board.h"
|
|
|
|
|
|
|
|
#include <wxPcbStruct.h>
|
2014-02-19 12:51:32 +00:00
|
|
|
#include <id.h>
|
2014-05-14 13:53:54 +00:00
|
|
|
#include <macros.h>
|
2014-04-04 09:50:15 +00:00
|
|
|
#include <pcbnew_id.h>
|
2013-09-18 17:55:16 +00:00
|
|
|
#include <view/view_controls.h>
|
2014-11-14 18:15:58 +00:00
|
|
|
#include <pcbcommon.h>
|
2013-09-18 17:55:16 +00:00
|
|
|
#include <pcb_painter.h>
|
2014-05-14 13:53:54 +00:00
|
|
|
#include <dialogs/dialog_pns_settings.h>
|
2015-02-18 00:29:54 +00:00
|
|
|
#include <dialogs/dialog_pns_diff_pair_dimensions.h>
|
2014-05-14 13:53:54 +00:00
|
|
|
#include <dialogs/dialog_track_via_size.h>
|
|
|
|
#include <base_units.h>
|
2015-05-18 11:48:11 +00:00
|
|
|
#include <hotkeys.h>
|
2015-09-24 09:04:42 +00:00
|
|
|
#include <confirm.h>
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
#include <tool/context_menu.h>
|
2015-05-05 18:39:41 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2015-07-02 14:09:51 +00:00
|
|
|
#include <tool/tool_settings.h>
|
2014-02-17 17:21:00 +00:00
|
|
|
#include <tools/common_actions.h>
|
2015-07-07 16:36:56 +00:00
|
|
|
#include <tools/size_menu.h>
|
2015-11-03 16:19:42 +00:00
|
|
|
#include <tools/selection_tool.h>
|
|
|
|
#include <tools/edit_tool.h>
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-01-31 17:05:11 +00:00
|
|
|
#include <ratsnest_data.h>
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
#include "router_tool.h"
|
|
|
|
#include "pns_segment.h"
|
|
|
|
#include "pns_router.h"
|
|
|
|
#include "trace.h"
|
|
|
|
|
2013-10-14 14:13:35 +00:00
|
|
|
using namespace KIGFX;
|
2013-09-18 17:55:16 +00:00
|
|
|
using boost::optional;
|
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
static TOOL_ACTION ACT_NewTrack( "pcbnew.InteractiveRouter.NewTrack", AS_CONTEXT,
|
|
|
|
TOOL_ACTION::LegacyHotKey( HK_ADD_NEW_TRACK ),
|
2015-04-02 14:09:48 +00:00
|
|
|
_( "New Track" ), _( "Starts laying a new track." ), add_tracks_xpm );
|
2015-04-02 14:09:26 +00:00
|
|
|
|
|
|
|
static TOOL_ACTION ACT_EndTrack( "pcbnew.InteractiveRouter.EndTrack", AS_CONTEXT, WXK_END,
|
2015-04-02 14:09:48 +00:00
|
|
|
_( "End Track" ), _( "Stops laying the current track." ), checked_ok_xpm );
|
2015-04-02 14:09:26 +00:00
|
|
|
|
|
|
|
static TOOL_ACTION ACT_AutoEndRoute( "pcbnew.InteractiveRouter.AutoEndRoute", AS_CONTEXT, 'F',
|
|
|
|
_( "Auto-end Track" ), _( "Automagically finishes currently routed track." ) );
|
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
static TOOL_ACTION ACT_Drag( "pcbnew.InteractiveRouter.Drag", AS_CONTEXT,
|
|
|
|
TOOL_ACTION::LegacyHotKey( HK_DRAG_TRACK_KEEP_SLOPE ),
|
2015-04-02 14:09:48 +00:00
|
|
|
_( "Drag Track/Via" ), _( "Drags a track or a via." ), drag_track_segment_xpm );
|
2015-04-02 14:09:26 +00:00
|
|
|
|
2015-05-03 18:43:07 +00:00
|
|
|
static TOOL_ACTION ACT_PlaceThroughVia( "pcbnew.InteractiveRouter.PlaceVia",
|
2015-05-18 11:48:11 +00:00
|
|
|
AS_CONTEXT, TOOL_ACTION::LegacyHotKey( HK_ADD_THROUGH_VIA ),
|
2015-05-03 18:43:07 +00:00
|
|
|
_( "Place Through Via" ),
|
|
|
|
_( "Adds a through-hole via at the end of currently routed track." ),
|
|
|
|
via_xpm );
|
|
|
|
|
|
|
|
static TOOL_ACTION ACT_PlaceBlindVia( "pcbnew.InteractiveRouter.PlaceBlindVia",
|
2015-05-18 11:48:11 +00:00
|
|
|
AS_CONTEXT, TOOL_ACTION::LegacyHotKey( HK_ADD_BLIND_BURIED_VIA ),
|
2015-05-03 18:43:07 +00:00
|
|
|
_( "Place Blind/Buried Via" ),
|
|
|
|
_( "Adds a blind or buried via at the end of currently routed track."),
|
|
|
|
via_buried_xpm );
|
|
|
|
|
|
|
|
static TOOL_ACTION ACT_PlaceMicroVia( "pcbnew.InteractiveRouter.PlaceMicroVia",
|
2015-05-18 11:48:11 +00:00
|
|
|
AS_CONTEXT, TOOL_ACTION::LegacyHotKey( HK_ADD_MICROVIA ),
|
2015-05-03 18:43:07 +00:00
|
|
|
_( "Place Microvia" ), _( "Adds a microvia at the end of currently routed track." ),
|
|
|
|
via_microvia_xpm );
|
|
|
|
|
2015-07-07 16:36:56 +00:00
|
|
|
static TOOL_ACTION ACT_CustomTrackWidth( "pcbnew.InteractiveRouter.CustomTrackViaSize",
|
2015-10-07 09:10:34 +00:00
|
|
|
AS_CONTEXT, 'Q',
|
2015-07-07 16:36:56 +00:00
|
|
|
_( "Custom Track/Via Size" ),
|
2015-05-03 18:43:07 +00:00
|
|
|
_( "Shows a dialog for changing the track width and via size." ),
|
|
|
|
width_track_xpm );
|
2015-04-02 14:09:26 +00:00
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
static TOOL_ACTION ACT_SwitchPosture( "pcbnew.InteractiveRouter.SwitchPosture", AS_CONTEXT,
|
|
|
|
TOOL_ACTION::LegacyHotKey( HK_SWITCH_TRACK_POSTURE ),
|
2015-05-03 18:43:07 +00:00
|
|
|
_( "Switch Track Posture" ),
|
|
|
|
_( "Switches posture of the currenly routed track." ),
|
|
|
|
change_entry_orient_xpm );
|
|
|
|
|
|
|
|
static TOOL_ACTION ACT_SetDpDimensions( "pcbnew.InteractiveRouter.SetDpDimensions",
|
2015-07-07 16:36:54 +00:00
|
|
|
AS_CONTEXT, 'P',
|
2015-05-03 18:43:07 +00:00
|
|
|
_( "Differential Pair Dimensions..." ),
|
|
|
|
_( "Sets the width and gap of the currently routed differential pair." ),
|
|
|
|
ps_diff_pair_tune_length_xpm );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
ROUTER_TOOL::ROUTER_TOOL() :
|
2015-02-18 00:29:54 +00:00
|
|
|
PNS_TOOL_BASE( "pcbnew.InteractiveRouter" )
|
2015-02-18 16:53:46 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2015-07-07 16:36:56 +00:00
|
|
|
class CONTEXT_TRACK_WIDTH_MENU: public CONTEXT_TRACK_VIA_SIZE_MENU
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CONTEXT_TRACK_WIDTH_MENU()
|
2015-07-07 16:36:56 +00:00
|
|
|
: CONTEXT_TRACK_VIA_SIZE_MENU( true, true ), m_board( NULL )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-04-30 08:46:05 +00:00
|
|
|
SetMenuHandler( boost::bind( &CONTEXT_TRACK_WIDTH_MENU::EventHandler, this, _1 ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-10-11 12:26:09 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void SetBoard( BOARD* aBoard )
|
|
|
|
{
|
|
|
|
m_board = aBoard;
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
Append( ID_POPUP_PCB_SELECT_CUSTOM_WIDTH, _( "Custom size" ),
|
|
|
|
wxEmptyString, wxITEM_CHECK );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
Append( ID_POPUP_PCB_SELECT_AUTO_WIDTH, _( "Use the starting track width" ),
|
2014-05-16 11:37:31 +00:00
|
|
|
_( "Route using the width of the starting track." ), wxITEM_CHECK );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-07-07 16:36:56 +00:00
|
|
|
Append( ID_POPUP_PCB_SELECT_USE_NETCLASS_VALUES, _( "Use net class values" ),
|
2014-05-16 11:37:31 +00:00
|
|
|
_( "Use track and via sizes from the net class" ), wxITEM_CHECK );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
AppendSeparator();
|
|
|
|
|
2015-07-07 16:36:56 +00:00
|
|
|
// Append the list of tracks & via sizes
|
|
|
|
AppendSizes( aBoard );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2015-04-30 08:46:05 +00:00
|
|
|
OPT_TOOL_EVENT EventHandler( const wxMenuEvent& aEvent )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
#if ID_POPUP_PCB_SELECT_VIASIZE1 < ID_POPUP_PCB_SELECT_WIDTH1
|
2014-05-16 11:37:31 +00:00
|
|
|
#error You have changed event ids order, it breaks code. Check the source code for more details.
|
2014-05-14 13:53:54 +00:00
|
|
|
// Recognising type of event (track width/via size) is based on comparison if the event id is
|
|
|
|
// within a specific range. If ranges of event ids changes, then the following is not valid anymore.
|
|
|
|
#endif
|
|
|
|
BOARD_DESIGN_SETTINGS &bds = m_board->GetDesignSettings();
|
|
|
|
|
|
|
|
int id = aEvent.GetId();
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
// Initial settings, to be modified below
|
2014-05-14 13:53:54 +00:00
|
|
|
bds.m_UseConnectedTrackWidth = false;
|
|
|
|
bds.UseCustomTrackViaSize( false );
|
|
|
|
|
|
|
|
if( id == ID_POPUP_PCB_SELECT_CUSTOM_WIDTH )
|
|
|
|
{
|
|
|
|
bds.UseCustomTrackViaSize( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( id == ID_POPUP_PCB_SELECT_AUTO_WIDTH )
|
|
|
|
{
|
|
|
|
bds.m_UseConnectedTrackWidth = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( id == ID_POPUP_PCB_SELECT_USE_NETCLASS_VALUES )
|
|
|
|
{
|
|
|
|
bds.SetViaSizeIndex( 0 );
|
|
|
|
bds.SetTrackWidthIndex( 0 );
|
|
|
|
}
|
|
|
|
|
2015-01-25 18:11:02 +00:00
|
|
|
else if( id >= ID_POPUP_PCB_SELECT_VIASIZE1 ) // via size has changed
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
assert( id < ID_POPUP_PCB_SELECT_WIDTH_END_RANGE );
|
|
|
|
|
|
|
|
bds.SetViaSizeIndex( id - ID_POPUP_PCB_SELECT_VIASIZE1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
else // track width has changed
|
|
|
|
{
|
|
|
|
assert( id >= ID_POPUP_PCB_SELECT_WIDTH1 );
|
|
|
|
assert( id < ID_POPUP_PCB_SELECT_VIASIZE );
|
|
|
|
|
|
|
|
bds.SetTrackWidthIndex( id - ID_POPUP_PCB_SELECT_WIDTH1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPT_TOOL_EVENT( COMMON_ACTIONS::trackViaSizeChanged.MakeEvent() );
|
|
|
|
}
|
|
|
|
|
2015-07-07 16:36:56 +00:00
|
|
|
private:
|
2014-05-14 13:53:54 +00:00
|
|
|
BOARD* m_board;
|
|
|
|
};
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
class ROUTER_TOOL_MENU: public CONTEXT_MENU
|
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
public:
|
2015-02-18 00:29:54 +00:00
|
|
|
ROUTER_TOOL_MENU( BOARD* aBoard, PNS_ROUTER_MODE aMode )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-04-02 14:09:26 +00:00
|
|
|
SetTitle( _( "Interactive Router" ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
Add( ACT_NewTrack );
|
|
|
|
Add( ACT_EndTrack );
|
|
|
|
// Add( ACT_AutoEndRoute ); // fixme: not implemented yet. Sorry.
|
|
|
|
Add( ACT_Drag );
|
|
|
|
Add( ACT_PlaceThroughVia );
|
2014-09-30 14:46:19 +00:00
|
|
|
Add( ACT_PlaceBlindVia );
|
|
|
|
Add( ACT_PlaceMicroVia );
|
2014-05-14 13:53:54 +00:00
|
|
|
Add( ACT_SwitchPosture );
|
|
|
|
|
2014-07-09 14:57:01 +00:00
|
|
|
AppendSeparator();
|
2014-08-24 07:05:07 +00:00
|
|
|
|
2015-07-24 07:42:46 +00:00
|
|
|
m_widthMenu.SetBoard( aBoard );
|
|
|
|
Add( &m_widthMenu, _( "Select Track/Via Width" ) );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
|
|
|
Add( ACT_CustomTrackWidth );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
if( aMode == PNS_MODE_ROUTE_DIFF_PAIR )
|
2015-02-18 00:29:54 +00:00
|
|
|
Add( ACT_SetDpDimensions );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-07-09 12:23:13 +00:00
|
|
|
AppendSeparator();
|
2015-02-18 00:29:54 +00:00
|
|
|
Add( PNS_TOOL_BASE::ACT_RouterOptions );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2015-07-24 07:42:46 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
CONTEXT_TRACK_WIDTH_MENU m_widthMenu;
|
2014-05-14 13:53:54 +00:00
|
|
|
};
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
ROUTER_TOOL::~ROUTER_TOOL()
|
|
|
|
{
|
2015-07-02 14:09:51 +00:00
|
|
|
m_savedSettings.Save( GetSettings() );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ROUTER_TOOL::Init()
|
|
|
|
{
|
|
|
|
m_savedSettings.Load( GetSettings() );
|
|
|
|
return true;
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-09 09:42:38 +00:00
|
|
|
void ROUTER_TOOL::Reset( RESET_REASON aReason )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
PNS_TOOL_BASE::Reset( aReason );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
Go( &ROUTER_TOOL::RouteSingleTrace, COMMON_ACTIONS::routerActivateSingle.MakeEvent() );
|
|
|
|
Go( &ROUTER_TOOL::RouteDiffPair, COMMON_ACTIONS::routerActivateDiffPair.MakeEvent() );
|
|
|
|
Go( &ROUTER_TOOL::DpDimensionsDialog, COMMON_ACTIONS::routerActivateDpDimensionsDialog.MakeEvent() );
|
|
|
|
Go( &ROUTER_TOOL::SettingsDialog, COMMON_ACTIONS::routerActivateSettingsDialog.MakeEvent() );
|
2015-07-02 14:09:56 +00:00
|
|
|
Go( &ROUTER_TOOL::InlineDrag, COMMON_ACTIONS::routerInlineDrag.MakeEvent() );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
int ROUTER_TOOL::getDefaultWidth( int aNetCode )
|
|
|
|
{
|
|
|
|
int w, d1, d2;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
getNetclassDimensions( aNetCode, w, d1, d2 );
|
2014-05-16 11:37:31 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2013-10-14 11:43:57 +00:00
|
|
|
void ROUTER_TOOL::getNetclassDimensions( int aNetCode, int& aWidth,
|
2014-05-31 14:04:25 +00:00
|
|
|
int& aViaDiameter, int& aViaDrill )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
BOARD_DESIGN_SETTINGS &bds = m_board->GetDesignSettings();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-05-20 09:29:37 +00:00
|
|
|
NETCLASSPTR netClass;
|
2015-02-18 00:29:54 +00:00
|
|
|
NETINFO_ITEM* ni = m_board->FindNet( aNetCode );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
if( ni )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
|
|
|
wxString netClassName = ni->GetClassName();
|
2014-05-14 13:53:54 +00:00
|
|
|
netClass = bds.m_NetClasses.Find( netClassName );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !netClass )
|
2014-05-15 08:51:08 +00:00
|
|
|
netClass = bds.GetDefault();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
aWidth = netClass->GetTrackWidth();
|
|
|
|
aViaDiameter = netClass->GetViaDiameter();
|
|
|
|
aViaDrill = netClass->GetViaDrill();
|
|
|
|
}
|
|
|
|
|
2015-07-07 16:36:45 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
void ROUTER_TOOL::handleCommonEvents( const TOOL_EVENT& aEvent )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
#ifdef DEBUG
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aEvent.IsKeyPressed() )
|
|
|
|
{
|
|
|
|
switch( aEvent.KeyCode() )
|
|
|
|
{
|
2015-10-05 16:28:41 +00:00
|
|
|
case '0':
|
|
|
|
TRACEn( 2, "saving drag/route log...\n" );
|
|
|
|
m_router->DumpLog();
|
|
|
|
break;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
2014-06-24 16:17:18 +00:00
|
|
|
else
|
2014-05-14 13:53:54 +00:00
|
|
|
#endif
|
2014-05-16 11:37:31 +00:00
|
|
|
if( aEvent.IsAction( &ACT_RouterOptions ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
DIALOG_PNS_SETTINGS settingsDlg( m_frame, m_router->Settings() );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-10-16 15:56:50 +00:00
|
|
|
if( settingsDlg.ShowModal() == wxID_OK )
|
2015-07-07 16:36:45 +00:00
|
|
|
{
|
2014-11-14 18:15:58 +00:00
|
|
|
// FIXME: do we need an explicit update?
|
2014-11-14 19:19:00 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
else if( aEvent.IsAction( &ACT_SetDpDimensions ) )
|
|
|
|
{
|
|
|
|
PNS_SIZES_SETTINGS sizes = m_router->Sizes();
|
|
|
|
DIALOG_PNS_DIFF_PAIR_DIMENSIONS settingsDlg( m_frame, sizes );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
if( settingsDlg.ShowModal() )
|
|
|
|
{
|
|
|
|
m_router->UpdateSizes( sizes );
|
|
|
|
}
|
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
else if( aEvent.IsAction( &ACT_CustomTrackWidth ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
|
|
|
DIALOG_TRACK_VIA_SIZE sizeDlg( m_frame, bds );
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
if( sizeDlg.ShowModal() )
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
|
|
|
bds.UseCustomTrackViaSize( true );
|
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::trackViaSizeChanged );
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
else if( aEvent.IsAction( &COMMON_ACTIONS::trackViaSizeChanged ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
PNS_SIZES_SETTINGS sizes( m_router->Sizes() );
|
|
|
|
sizes.ImportCurrent( m_board->GetDesignSettings() );
|
|
|
|
m_router->UpdateSizes( sizes );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
int ROUTER_TOOL::getStartLayer( const PNS_ITEM* aItem )
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
|
|
|
int tl = getView()->GetTopLayer();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
if( m_startItem )
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
|
|
|
const PNS_LAYERSET& ls = m_startItem->Layers();
|
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
if( ls.Overlaps( tl ) )
|
2014-11-14 18:15:58 +00:00
|
|
|
return tl;
|
|
|
|
else
|
|
|
|
return ls.Start();
|
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
return tl;
|
|
|
|
}
|
2015-05-18 11:48:11 +00:00
|
|
|
|
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
void ROUTER_TOOL::switchLayerOnViaPlacement()
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
int al = m_frame->GetActiveLayer();
|
2014-11-14 18:15:58 +00:00
|
|
|
int cl = m_router->GetCurrentLayer();
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
if( cl != al )
|
|
|
|
{
|
|
|
|
m_router->SwitchLayer( al );
|
|
|
|
}
|
|
|
|
|
|
|
|
optional<int> newLayer = m_router->Sizes().PairedLayer( cl );
|
|
|
|
|
2015-09-24 16:34:22 +00:00
|
|
|
if( !newLayer )
|
|
|
|
newLayer = m_router->Sizes().GetLayerTop();
|
|
|
|
|
|
|
|
m_router->SwitchLayer( *newLayer );
|
|
|
|
m_frame->SetActiveLayer( ToLAYER_ID( *newLayer ) );
|
2014-11-14 18:15:58 +00:00
|
|
|
}
|
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
|
2015-11-18 14:35:17 +00:00
|
|
|
bool ROUTER_TOOL::onViaCommand( TOOL_EVENT& aEvent, VIATYPE_T aType )
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
const int layerCount = bds.GetCopperLayerCount();
|
|
|
|
int currentLayer = m_router->GetCurrentLayer();
|
2015-09-24 16:34:22 +00:00
|
|
|
LAYER_ID pairTop = m_frame->GetScreen()->m_Route_Layer_TOP;
|
|
|
|
LAYER_ID pairBottom = m_frame->GetScreen()->m_Route_Layer_BOTTOM;
|
2014-11-14 18:15:58 +00:00
|
|
|
|
|
|
|
PNS_SIZES_SETTINGS sizes = m_router->Sizes();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
// fixme: P&S supports more than one fixed layer pair. Update the dialog?
|
2014-11-14 18:15:58 +00:00
|
|
|
sizes.ClearLayerPairs();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
if( !m_router->IsPlacingVia() )
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
|
|
|
// Cannot place microvias or blind vias if not allowed (obvious)
|
|
|
|
if( ( aType == VIA_BLIND_BURIED ) && ( !bds.m_BlindBuriedViaAllowed ) )
|
2015-09-24 09:04:42 +00:00
|
|
|
{
|
|
|
|
DisplayError( m_frame, _( "Blind/buried vias have to be enabled in the design settings." ) );
|
2014-11-14 18:15:58 +00:00
|
|
|
return false;
|
2015-09-24 09:04:42 +00:00
|
|
|
}
|
2015-05-18 11:48:11 +00:00
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
if( ( aType == VIA_MICROVIA ) && ( !bds.m_MicroViasAllowed ) )
|
2015-09-24 09:04:42 +00:00
|
|
|
{
|
|
|
|
DisplayError( m_frame, _( "Microvias have to be enabled in the design settings." ) );
|
2014-11-14 18:15:58 +00:00
|
|
|
return false;
|
2015-09-24 09:04:42 +00:00
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-09-24 09:04:42 +00:00
|
|
|
// Can only place through vias on 2-layer boards
|
2014-11-14 18:15:58 +00:00
|
|
|
if( ( aType != VIA_THROUGH ) && ( layerCount <= 2 ) )
|
2015-09-24 09:04:42 +00:00
|
|
|
{
|
|
|
|
DisplayError( m_frame, _( "Only through vias are allowed on 2 layer boards." ) );
|
2014-11-14 18:15:58 +00:00
|
|
|
return false;
|
2015-09-24 09:04:42 +00:00
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-09-24 09:04:42 +00:00
|
|
|
// Can only place microvias if we're on an outer layer, or directly adjacent to one
|
|
|
|
if( ( aType == VIA_MICROVIA ) && ( currentLayer > In1_Cu ) && ( currentLayer < layerCount - 2 ) )
|
|
|
|
{
|
2015-09-24 16:34:22 +00:00
|
|
|
DisplayError( m_frame, _( "Microvias can be placed only between the outer layers " \
|
|
|
|
"(F.Cu/B.Cu) and the ones directly adjacent to them." ) );
|
2014-11-14 18:15:58 +00:00
|
|
|
return false;
|
2015-09-24 09:04:42 +00:00
|
|
|
}
|
2015-09-24 16:34:22 +00:00
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-09-24 16:34:22 +00:00
|
|
|
// Convert blind/buried via to a through hole one, if it goes through all layers
|
|
|
|
if( aType == VIA_BLIND_BURIED && ( ( currentLayer == B_Cu ) || ( currentLayer == F_Cu ) )
|
|
|
|
&& ( ( pairTop == B_Cu && pairBottom == F_Cu )
|
|
|
|
|| ( pairTop == F_Cu && pairBottom == B_Cu ) ) )
|
|
|
|
{
|
|
|
|
aType = VIA_THROUGH;
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-09-24 16:34:22 +00:00
|
|
|
switch( aType )
|
2015-06-18 18:22:23 +00:00
|
|
|
{
|
2015-10-05 16:28:41 +00:00
|
|
|
case VIA_THROUGH:
|
|
|
|
sizes.SetViaDiameter( bds.GetCurrentViaSize() );
|
|
|
|
sizes.SetViaDrill( bds.GetCurrentViaDrill() );
|
|
|
|
sizes.AddLayerPair( pairTop, pairBottom );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIA_MICROVIA:
|
|
|
|
sizes.SetViaDiameter( bds.GetCurrentMicroViaSize() );
|
|
|
|
sizes.SetViaDrill( bds.GetCurrentMicroViaDrill() );
|
|
|
|
|
|
|
|
if( currentLayer == F_Cu || currentLayer == In1_Cu )
|
|
|
|
sizes.AddLayerPair( F_Cu, In1_Cu );
|
|
|
|
else if( currentLayer == B_Cu || currentLayer == layerCount - 2 )
|
|
|
|
sizes.AddLayerPair( B_Cu, layerCount - 2 );
|
|
|
|
else
|
|
|
|
wxASSERT( false );
|
|
|
|
break;
|
2015-09-24 16:34:22 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
case VIA_BLIND_BURIED:
|
|
|
|
sizes.SetViaDiameter( bds.GetCurrentViaSize() );
|
|
|
|
sizes.SetViaDrill( bds.GetCurrentViaDrill() );
|
2015-09-24 16:34:22 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
if( currentLayer == pairTop || currentLayer == pairBottom )
|
|
|
|
sizes.AddLayerPair( pairTop, pairBottom );
|
|
|
|
else
|
|
|
|
sizes.AddLayerPair( pairTop, currentLayer );
|
|
|
|
break;
|
2015-09-24 16:34:22 +00:00
|
|
|
|
2015-10-05 16:28:41 +00:00
|
|
|
default:
|
|
|
|
wxASSERT( false );
|
|
|
|
break;
|
2015-06-18 18:22:23 +00:00
|
|
|
}
|
2015-07-02 14:09:51 +00:00
|
|
|
|
2015-09-24 16:34:22 +00:00
|
|
|
sizes.SetViaType( aType );
|
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
m_router->UpdateSizes( sizes );
|
2015-06-18 18:22:23 +00:00
|
|
|
m_router->ToggleViaPlacement();
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-11-18 14:35:17 +00:00
|
|
|
updateEndItem( aEvent );
|
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
m_router->Move( m_endSnapPoint, m_endItem ); // refresh
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
bool ROUTER_TOOL::prepareInteractive()
|
2014-11-14 18:15:58 +00:00
|
|
|
{
|
2015-05-18 11:48:11 +00:00
|
|
|
int routingLayer = getStartLayer( m_startItem );
|
|
|
|
m_frame->SetActiveLayer( ToLAYER_ID( routingLayer ) );
|
2014-11-14 18:15:58 +00:00
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
// fixme: switch on invisible layer
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-08-19 15:27:23 +00:00
|
|
|
// for some reason I don't understand, GetNetclass() may return null sometimes...
|
|
|
|
if( m_startItem &&
|
|
|
|
m_startItem->Net() >= 0 &&
|
|
|
|
m_startItem->Parent() &&
|
|
|
|
m_startItem->Parent()->GetNetClass() )
|
2014-09-28 14:44:47 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
highlightNet( true, m_startItem->Net() );
|
2014-09-28 14:44:47 +00:00
|
|
|
// Update track width and via size shown in main toolbar comboboxes
|
2015-02-18 00:29:54 +00:00
|
|
|
m_frame->SetCurrentNetClass( m_startItem->Parent()->GetNetClass()->GetName() );
|
2014-09-28 14:44:47 +00:00
|
|
|
}
|
|
|
|
else
|
2015-02-18 00:29:54 +00:00
|
|
|
m_frame->SetCurrentNetClass( NETCLASS::Default );
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
m_ctls->ForceCursorPosition( false );
|
|
|
|
m_ctls->SetAutoPan( true );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
PNS_SIZES_SETTINGS sizes( m_router->Sizes() );
|
2014-11-14 19:19:00 +00:00
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
sizes.Init( m_board, m_startItem );
|
|
|
|
sizes.AddLayerPair( m_frame->GetScreen()->m_Route_Layer_TOP,
|
2015-09-24 16:34:22 +00:00
|
|
|
m_frame->GetScreen()->m_Route_Layer_BOTTOM );
|
2015-02-18 00:29:54 +00:00
|
|
|
m_router->UpdateSizes( sizes );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
if( !m_router->StartRouting( m_startSnapPoint, m_startItem, routingLayer ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-09-24 09:04:42 +00:00
|
|
|
DisplayError( m_frame, m_router->FailureReason() );
|
2015-05-18 11:48:11 +00:00
|
|
|
highlightNet( false );
|
2015-02-18 00:29:54 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
|
|
|
m_endItem = NULL;
|
|
|
|
m_endSnapPoint = m_startSnapPoint;
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
|
2015-08-04 21:08:13 +00:00
|
|
|
bool ROUTER_TOOL::finishInteractive()
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_router->StopRouting();
|
|
|
|
|
2015-08-04 21:08:13 +00:00
|
|
|
// Save the recent changes in the undo buffer
|
|
|
|
m_frame->SaveCopyInUndoList( m_router->GetUndoBuffer(), UR_UNSPECIFIED );
|
|
|
|
m_router->ClearUndoBuffer();
|
|
|
|
m_frame->OnModify();
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
m_ctls->SetAutoPan( false );
|
|
|
|
m_ctls->ForceCursorPosition( false );
|
|
|
|
highlightNet( false );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
void ROUTER_TOOL::performRouting()
|
|
|
|
{
|
2015-07-10 21:42:05 +00:00
|
|
|
if( !prepareInteractive() )
|
2015-02-18 00:29:54 +00:00
|
|
|
return;
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
if( evt->IsCancel() || evt->IsActivate() )
|
2013-09-26 21:53:54 +00:00
|
|
|
break;
|
|
|
|
else if( evt->IsMotion() )
|
|
|
|
{
|
2015-05-18 11:48:11 +00:00
|
|
|
m_router->SetOrthoMode( evt->Modifier( MD_CTRL ) );
|
2015-11-03 16:19:42 +00:00
|
|
|
updateEndItem( *evt );
|
2013-09-26 21:53:54 +00:00
|
|
|
m_router->Move( m_endSnapPoint, m_endItem );
|
|
|
|
}
|
2013-10-15 08:41:00 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2013-09-18 17:55:16 +00:00
|
|
|
updateEndItem( *evt );
|
2014-11-14 18:15:58 +00:00
|
|
|
bool needLayerSwitch = m_router->IsPlacingVia();
|
2013-09-26 21:53:54 +00:00
|
|
|
|
|
|
|
if( m_router->FixRoute( m_endSnapPoint, m_endItem ) )
|
2013-09-18 17:55:16 +00:00
|
|
|
break;
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2014-11-14 19:19:00 +00:00
|
|
|
if( needLayerSwitch )
|
2014-11-14 18:15:58 +00:00
|
|
|
switchLayerOnViaPlacement();
|
|
|
|
|
2014-07-09 14:50:31 +00:00
|
|
|
// Synchronize the indicated layer
|
2015-02-18 00:29:54 +00:00
|
|
|
m_frame->SetActiveLayer( ToLAYER_ID( m_router->GetCurrentLayer() ) );
|
2015-11-03 16:19:42 +00:00
|
|
|
updateEndItem( *evt );
|
2013-09-26 21:53:54 +00:00
|
|
|
m_router->Move( m_endSnapPoint, m_endItem );
|
2015-08-18 09:38:17 +00:00
|
|
|
m_startItem = NULL;
|
2014-05-16 11:37:31 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsAction( &ACT_PlaceThroughVia ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-11-18 14:35:17 +00:00
|
|
|
onViaCommand( *evt, VIA_THROUGH );
|
2014-09-30 14:46:19 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsAction( &ACT_PlaceBlindVia ) )
|
|
|
|
{
|
2015-11-18 14:35:17 +00:00
|
|
|
onViaCommand( *evt, VIA_BLIND_BURIED );
|
2014-09-30 14:46:19 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsAction( &ACT_PlaceMicroVia ) )
|
|
|
|
{
|
2015-11-18 14:35:17 +00:00
|
|
|
onViaCommand( *evt, VIA_MICROVIA );
|
2013-09-26 21:53:54 +00:00
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
else if( evt->IsAction( &ACT_SwitchPosture ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
{
|
2014-05-14 13:53:54 +00:00
|
|
|
m_router->FlipPosture();
|
2015-11-03 16:19:42 +00:00
|
|
|
updateEndItem( *evt );
|
2014-07-09 14:50:31 +00:00
|
|
|
m_router->Move( m_endSnapPoint, m_endItem ); // refresh
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2014-07-09 14:50:31 +00:00
|
|
|
else if( evt->IsAction( &COMMON_ACTIONS::layerChanged ) )
|
2014-05-14 13:53:54 +00:00
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
m_router->SwitchLayer( m_frame->GetActiveLayer() );
|
2015-11-03 16:19:42 +00:00
|
|
|
updateEndItem( *evt );
|
2014-07-09 14:50:31 +00:00
|
|
|
m_router->Move( m_endSnapPoint, m_endItem ); // refresh
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsAction( &ACT_EndTrack ) )
|
|
|
|
{
|
|
|
|
if( m_router->FixRoute( m_endSnapPoint, m_endItem ) )
|
2013-09-26 21:53:54 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-08-24 07:05:07 +00:00
|
|
|
|
2014-07-09 14:50:31 +00:00
|
|
|
handleCommonEvents( *evt );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2015-08-04 21:08:13 +00:00
|
|
|
finishInteractive();
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
2013-09-26 21:53:54 +00:00
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
int ROUTER_TOOL::DpDimensionsDialog( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
Activate();
|
|
|
|
|
|
|
|
PNS_SIZES_SETTINGS sizes = m_router->Sizes();
|
|
|
|
DIALOG_PNS_DIFF_PAIR_DIMENSIONS settingsDlg( m_frame, sizes );
|
|
|
|
|
|
|
|
if( settingsDlg.ShowModal() )
|
2014-01-30 16:11:40 +00:00
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
m_router->UpdateSizes( sizes );
|
|
|
|
m_savedSizes = sizes;
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
int ROUTER_TOOL::SettingsDialog( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
Activate();
|
|
|
|
|
|
|
|
DIALOG_PNS_SETTINGS settingsDlg( m_frame, m_router->Settings() );
|
|
|
|
|
|
|
|
if( settingsDlg.ShowModal() )
|
2014-01-30 16:11:40 +00:00
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
m_savedSettings = m_router->Settings();
|
2014-01-30 16:11:40 +00:00
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-01-30 10:32:08 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
int ROUTER_TOOL::RouteSingleTrace( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_frame->SetToolID( ID_TRACK_BUTT, wxCURSOR_PENCIL, _( "Route Track" ) );
|
|
|
|
return mainLoop( PNS_MODE_ROUTE_SINGLE );
|
2013-09-18 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
int ROUTER_TOOL::RouteDiffPair( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_frame->SetToolID( ID_TRACK_BUTT, wxCURSOR_PENCIL, _( "Router Differential Pair" ) );
|
|
|
|
return mainLoop( PNS_MODE_ROUTE_DIFF_PAIR );
|
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
int ROUTER_TOOL::mainLoop( PNS_ROUTER_MODE aMode )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
2014-11-14 18:15:58 +00:00
|
|
|
PCB_EDIT_FRAME* frame = getEditFrame<PCB_EDIT_FRAME>();
|
2014-06-06 12:59:25 +00:00
|
|
|
BOARD* board = getModel<BOARD>();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-05-14 17:15:25 +00:00
|
|
|
// Deselect all items
|
2014-07-09 14:50:31 +00:00
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
|
2014-05-14 17:15:25 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
Activate();
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
m_router->SetMode( aMode );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
m_ctls->SetSnapping( true );
|
|
|
|
m_ctls->ShowCursor( true );
|
2015-08-04 21:08:13 +00:00
|
|
|
frame->UndoRedoBlock( true );
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2015-07-07 16:36:45 +00:00
|
|
|
m_startSnapPoint = getViewControls()->GetCursorPosition();
|
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
std::auto_ptr<ROUTER_TOOL_MENU> ctxMenu( new ROUTER_TOOL_MENU( board, aMode ) );
|
|
|
|
SetContextMenu( ctxMenu.get() );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
2014-01-31 15:08:20 +00:00
|
|
|
if( m_needsSync )
|
|
|
|
{
|
|
|
|
m_router->SyncWorld();
|
2014-06-01 16:44:38 +00:00
|
|
|
m_router->SetView( getView() );
|
2014-01-31 15:08:20 +00:00
|
|
|
m_needsSync = false;
|
|
|
|
}
|
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
if( evt->IsCancel() || evt->IsActivate() )
|
2013-09-26 21:53:54 +00:00
|
|
|
break; // Finish
|
|
|
|
else if( evt->IsMotion() )
|
2013-09-18 17:55:16 +00:00
|
|
|
updateStartItem( *evt );
|
2014-05-14 13:53:54 +00:00
|
|
|
else if( evt->IsClick( BUT_LEFT ) || evt->IsAction( &ACT_NewTrack ) )
|
2013-09-18 17:55:16 +00:00
|
|
|
{
|
|
|
|
updateStartItem( *evt );
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
if( evt->Modifier( MD_CTRL ) )
|
|
|
|
performDragging();
|
|
|
|
else
|
|
|
|
performRouting();
|
2014-07-09 11:50:27 +00:00
|
|
|
}
|
2014-11-14 19:19:00 +00:00
|
|
|
else if( evt->IsAction( &ACT_Drag ) )
|
2015-08-04 09:37:16 +00:00
|
|
|
{
|
|
|
|
updateStartItem( *evt );
|
2014-05-14 13:53:54 +00:00
|
|
|
performDragging();
|
2015-08-04 09:37:16 +00:00
|
|
|
}
|
2015-09-03 16:25:48 +00:00
|
|
|
else if( evt->IsAction( &ACT_PlaceThroughVia ) )
|
|
|
|
{
|
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::layerToggle, true );
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
handleCommonEvents( *evt );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
2013-09-18 17:55:16 +00:00
|
|
|
|
2014-11-14 18:15:58 +00:00
|
|
|
frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
|
2015-08-04 21:08:13 +00:00
|
|
|
frame->UndoRedoBlock( false );
|
2014-02-19 12:51:32 +00:00
|
|
|
|
2014-05-14 16:45:59 +00:00
|
|
|
// Store routing settings till the next invocation
|
2015-02-18 00:29:54 +00:00
|
|
|
m_savedSettings = m_router->Settings();
|
|
|
|
m_savedSizes = m_router->Sizes();
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-12-03 13:26:12 +00:00
|
|
|
// Disable the context menu before it is destroyed
|
|
|
|
SetContextMenu( NULL, CMENU_OFF );
|
|
|
|
|
2013-09-18 17:55:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-05-14 13:53:54 +00:00
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
void ROUTER_TOOL::performDragging()
|
|
|
|
{
|
2014-05-14 16:45:59 +00:00
|
|
|
PCB_EDIT_FRAME* frame = getEditFrame<PCB_EDIT_FRAME>();
|
2014-05-14 13:53:54 +00:00
|
|
|
VIEW_CONTROLS* ctls = getViewControls();
|
|
|
|
|
|
|
|
bool dragStarted = m_router->StartDragging( m_startSnapPoint, m_startItem );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2014-05-16 11:37:31 +00:00
|
|
|
if( !dragStarted )
|
2014-05-14 13:53:54 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if( m_startItem && m_startItem->Net() >= 0 )
|
|
|
|
highlightNet( true, m_startItem->Net() );
|
|
|
|
|
|
|
|
ctls->SetAutoPan( true );
|
2014-06-24 16:17:18 +00:00
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
2015-11-03 16:19:42 +00:00
|
|
|
ctls->ForceCursorPosition( false );
|
|
|
|
|
|
|
|
if( evt->IsCancel() || evt->IsActivate() )
|
2014-05-14 13:53:54 +00:00
|
|
|
break;
|
|
|
|
else if( evt->IsMotion() )
|
|
|
|
{
|
|
|
|
updateEndItem( *evt );
|
|
|
|
m_router->Move( m_endSnapPoint, m_endItem );
|
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
if( m_router->FixRoute( m_endSnapPoint, m_endItem ) )
|
|
|
|
break;
|
|
|
|
}
|
2014-05-16 11:37:31 +00:00
|
|
|
|
|
|
|
handleCommonEvents( *evt );
|
2014-05-14 13:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( m_router->RoutingInProgress() )
|
|
|
|
m_router->StopRouting();
|
|
|
|
|
2015-08-04 21:08:13 +00:00
|
|
|
// Save the recent changes in the undo buffer
|
|
|
|
frame->SaveCopyInUndoList( m_router->GetUndoBuffer(), UR_UNSPECIFIED );
|
|
|
|
m_router->ClearUndoBuffer();
|
|
|
|
frame->OnModify();
|
2014-05-14 16:45:59 +00:00
|
|
|
|
2015-08-04 09:37:16 +00:00
|
|
|
m_startItem = NULL;
|
|
|
|
|
2014-05-14 13:53:54 +00:00
|
|
|
ctls->SetAutoPan( false );
|
|
|
|
ctls->ForceCursorPosition( false );
|
|
|
|
highlightNet( false );
|
|
|
|
}
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-05-18 11:48:11 +00:00
|
|
|
|
|
|
|
int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-07-02 14:09:56 +00:00
|
|
|
const BOARD_CONNECTED_ITEM *item = aEvent.Parameter<const BOARD_CONNECTED_ITEM*>();
|
|
|
|
PCB_EDIT_FRAME* frame = getEditFrame<PCB_EDIT_FRAME>();
|
|
|
|
VIEW_CONTROLS* ctls = getViewControls();
|
|
|
|
|
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
|
|
|
|
|
|
|
|
Activate();
|
|
|
|
|
|
|
|
m_router->SyncWorld();
|
|
|
|
m_router->SetView( getView() );
|
|
|
|
|
|
|
|
m_startItem = m_router->GetWorld()->FindItemByParent( item );
|
|
|
|
|
|
|
|
VECTOR2I p0 = ctls->GetCursorPosition();
|
|
|
|
|
|
|
|
bool dragStarted = m_router->StartDragging( p0, m_startItem );
|
|
|
|
|
|
|
|
if( !dragStarted )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ctls->ForceCursorPosition( false );
|
|
|
|
ctls->SetAutoPan( true );
|
2015-08-04 21:08:13 +00:00
|
|
|
frame->UndoRedoBlock( true );
|
2015-07-02 14:09:56 +00:00
|
|
|
|
|
|
|
bool saveUndoBuffer = true;
|
|
|
|
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
|
|
|
p0 = ctls->GetCursorPosition();
|
|
|
|
|
|
|
|
if( evt->IsCancel() )
|
|
|
|
{
|
|
|
|
saveUndoBuffer = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
m_router->Move( p0, NULL );
|
|
|
|
}
|
|
|
|
else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
saveUndoBuffer = m_router->FixRoute( p0, NULL );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-10 10:14:27 +00:00
|
|
|
if( m_router->RoutingInProgress() )
|
|
|
|
m_router->StopRouting();
|
|
|
|
|
2015-07-02 14:11:15 +00:00
|
|
|
if( saveUndoBuffer )
|
2015-07-02 14:09:56 +00:00
|
|
|
{
|
|
|
|
frame->SaveCopyInUndoList( m_router->GetUndoBuffer(), UR_UNSPECIFIED );
|
|
|
|
m_router->ClearUndoBuffer();
|
|
|
|
frame->OnModify();
|
|
|
|
}
|
|
|
|
|
|
|
|
ctls->SetAutoPan( false );
|
2015-07-07 16:36:47 +00:00
|
|
|
ctls->ShowCursor( false );
|
2015-08-04 21:08:13 +00:00
|
|
|
frame->UndoRedoBlock( false );
|
2015-07-02 14:09:56 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|