2015-02-18 00:29:54 +00:00
|
|
|
/*
|
|
|
|
* KiRouter - a push-and-(sometimes-)shove PCB router
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2015 CERN
|
|
|
|
* Author: Tomasz Wlostowski <tomasz.wlostowski@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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
#include <boost/optional.hpp>
|
|
|
|
|
|
|
|
#include "class_draw_panel_gal.h"
|
|
|
|
#include "class_board.h"
|
|
|
|
|
|
|
|
#include <wxPcbStruct.h>
|
|
|
|
#include <pcbnew_id.h>
|
|
|
|
#include <view/view_controls.h>
|
|
|
|
#include <pcb_painter.h>
|
|
|
|
#include <dialogs/dialog_pns_settings.h>
|
|
|
|
#include <dialogs/dialog_pns_length_tuning_settings.h>
|
|
|
|
|
|
|
|
#include <tool/context_menu.h>
|
2015-05-05 18:39:41 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2015-02-18 00:29:54 +00:00
|
|
|
#include <tools/common_actions.h>
|
|
|
|
|
|
|
|
#include "pns_segment.h"
|
|
|
|
#include "pns_router.h"
|
|
|
|
#include "pns_meander_placer.h" // fixme: move settings to separate header
|
|
|
|
#include "pns_tune_status_popup.h"
|
|
|
|
|
|
|
|
#include "length_tuner_tool.h"
|
|
|
|
|
|
|
|
#include "trace.h"
|
|
|
|
|
|
|
|
using namespace KIGFX;
|
|
|
|
using boost::optional;
|
|
|
|
|
2015-04-02 14:09:26 +00:00
|
|
|
static TOOL_ACTION ACT_StartTuning( "pcbnew.LengthTuner.StartTuning", AS_CONTEXT, 'X',
|
|
|
|
_( "New Track" ), _( "Starts laying a new track." ) );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-04-02 14:09:26 +00:00
|
|
|
static TOOL_ACTION ACT_EndTuning( "pcbnew.LengthTuner.EndTuning", AS_CONTEXT, WXK_END,
|
|
|
|
_( "End Track" ), _( "Stops laying the current meander." ) );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-04-02 14:09:26 +00:00
|
|
|
static TOOL_ACTION ACT_Settings( "pcbnew.LengthTuner.Settings", AS_CONTEXT, 'L',
|
|
|
|
_( "Length Tuning Settings" ), _( "Sets the length tuning parameters for currently routed item." ) );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-04-02 14:09:26 +00:00
|
|
|
static TOOL_ACTION ACT_SpacingIncrease( "pcbnew.LengthTuner.SpacingIncrease", AS_CONTEXT, '1',
|
|
|
|
_( "Increase spacing" ), _( "Increase meander spacing by one step." ) );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-04-02 14:09:26 +00:00
|
|
|
static TOOL_ACTION ACT_SpacingDecrease( "pcbnew.LengthTuner.SpacingDecrease", AS_CONTEXT, '2',
|
|
|
|
_( "Decrease spacing" ), _( "Decrease meander spacing by one step." ) );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-04-02 14:09:26 +00:00
|
|
|
static TOOL_ACTION ACT_AmplIncrease( "pcbnew.LengthTuner.AmplIncrease", AS_CONTEXT, '3',
|
|
|
|
_( "Increase amplitude" ), _( "Increase meander amplitude by one step." ) );
|
|
|
|
|
|
|
|
static TOOL_ACTION ACT_AmplDecrease( "pcbnew.LengthTuner.AmplDecrease", AS_CONTEXT, '4',
|
|
|
|
_( "Decrease amplitude" ), _( "Decrease meander amplitude by one step." ) );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
LENGTH_TUNER_TOOL::LENGTH_TUNER_TOOL() :
|
|
|
|
PNS_TOOL_BASE( "pcbnew.LengthTuner" )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class TUNER_TOOL_MENU: public CONTEXT_MENU
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TUNER_TOOL_MENU( BOARD* aBoard )
|
|
|
|
{
|
2015-04-02 14:09:26 +00:00
|
|
|
SetTitle( _( "Length Tuner" ) );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
//Add( ACT_StartTuning );
|
|
|
|
//Add( ACT_EndTuning );
|
|
|
|
|
|
|
|
//AppendSeparator();
|
|
|
|
|
|
|
|
Add( ACT_SpacingIncrease );
|
|
|
|
Add( ACT_SpacingDecrease );
|
|
|
|
Add( ACT_AmplIncrease );
|
|
|
|
Add( ACT_AmplDecrease );
|
2015-02-18 16:53:46 +00:00
|
|
|
Add( ACT_Settings );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
LENGTH_TUNER_TOOL::~LENGTH_TUNER_TOOL()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
void LENGTH_TUNER_TOOL::Reset( RESET_REASON aReason )
|
|
|
|
{
|
|
|
|
PNS_TOOL_BASE::Reset( aReason );
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
Go( &LENGTH_TUNER_TOOL::TuneSingleTrace, COMMON_ACTIONS::routerActivateTuneSingleTrace.MakeEvent() );
|
|
|
|
Go( &LENGTH_TUNER_TOOL::TuneDiffPair, COMMON_ACTIONS::routerActivateTuneDiffPair.MakeEvent() );
|
|
|
|
Go( &LENGTH_TUNER_TOOL::TuneDiffPairSkew, COMMON_ACTIONS::routerActivateTuneDiffPairSkew.MakeEvent() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LENGTH_TUNER_TOOL::handleCommonEvents( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
if( aEvent.IsAction( &ACT_RouterOptions ) )
|
|
|
|
{
|
|
|
|
DIALOG_PNS_SETTINGS settingsDlg( m_frame, m_router->Settings() );
|
|
|
|
|
|
|
|
if( settingsDlg.ShowModal() )
|
|
|
|
{
|
|
|
|
// FIXME: do we need an explicit update?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
PNS_MEANDER_PLACER_BASE* placer = static_cast<PNS_MEANDER_PLACER_BASE*>( m_router->Placer() );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !placer )
|
2015-02-18 00:29:54 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if( aEvent.IsAction( &ACT_Settings ) )
|
|
|
|
{
|
|
|
|
PNS_MEANDER_SETTINGS settings = placer->MeanderSettings();
|
|
|
|
DIALOG_PNS_LENGTH_TUNING_SETTINGS settingsDlg( m_frame, settings, m_router->Mode() );
|
|
|
|
|
|
|
|
if( settingsDlg.ShowModal() )
|
|
|
|
{
|
2015-03-09 10:06:54 +00:00
|
|
|
placer->UpdateSettings( settings );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
m_savedMeanderSettings = placer->MeanderSettings();
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-05 09:02:29 +00:00
|
|
|
void LENGTH_TUNER_TOOL::updateStatusPopup( PNS_TUNE_STATUS_POPUP& aPopup )
|
|
|
|
{
|
2015-03-09 10:06:54 +00:00
|
|
|
wxPoint p = wxGetMousePosition();
|
2015-03-05 09:02:29 +00:00
|
|
|
|
|
|
|
p.x += 20;
|
|
|
|
p.y += 20;
|
|
|
|
|
2015-03-09 10:06:54 +00:00
|
|
|
aPopup.UpdateStatus( m_router );
|
2015-03-05 09:02:29 +00:00
|
|
|
aPopup.Move( p );
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
void LENGTH_TUNER_TOOL::performTuning()
|
|
|
|
{
|
|
|
|
bool saveUndoBuffer = true;
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
if( m_startItem )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_frame->SetActiveLayer( ToLAYER_ID ( m_startItem->Layers().Start() ) );
|
|
|
|
|
|
|
|
if( m_startItem->Net() >= 0 )
|
|
|
|
highlightNet( true, m_startItem->Net() );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_ctls->ForceCursorPosition( false );
|
|
|
|
m_ctls->SetAutoPan( true );
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
if( !m_router->StartRouting( m_startSnapPoint, m_startItem, 0 ) )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
2015-02-18 16:53:46 +00:00
|
|
|
wxMessageBox( m_router->FailureReason(), _( "Error" ) );
|
|
|
|
highlightNet( false );
|
2015-02-18 00:29:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-05 09:02:29 +00:00
|
|
|
PNS_MEANDER_PLACER_BASE* placer = static_cast<PNS_MEANDER_PLACER_BASE*>( m_router->Placer() );
|
2015-03-09 10:06:54 +00:00
|
|
|
|
2015-03-05 09:02:29 +00:00
|
|
|
placer->UpdateSettings( m_savedMeanderSettings );
|
|
|
|
|
|
|
|
VECTOR2I end( m_startSnapPoint );
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
PNS_TUNE_STATUS_POPUP statusPopup( m_frame );
|
2015-03-04 19:22:33 +00:00
|
|
|
statusPopup.Popup();
|
|
|
|
|
2015-03-05 09:02:29 +00:00
|
|
|
m_router->Move( end, NULL );
|
|
|
|
updateStatusPopup( statusPopup );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
2015-03-09 10:06:54 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
|
|
|
if( evt->IsCancel() || evt->IsActivate() )
|
|
|
|
break;
|
|
|
|
else if( evt->Action() == TA_UNDO_REDO )
|
|
|
|
{
|
|
|
|
saveUndoBuffer = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( evt->IsMotion() )
|
|
|
|
{
|
|
|
|
end = evt->Position();
|
|
|
|
m_router->Move( end, NULL );
|
2015-03-05 09:02:29 +00:00
|
|
|
updateStatusPopup( statusPopup );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
if( m_router->FixRoute( evt->Position(), NULL ) )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if( evt->IsAction( &ACT_EndTuning ) )
|
|
|
|
{
|
|
|
|
if( m_router->FixRoute( end, NULL ) )
|
|
|
|
break;
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsAction( &ACT_AmplDecrease ) )
|
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
placer->AmplitudeStep( -1 );
|
|
|
|
m_router->Move( end, NULL );
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsAction( &ACT_AmplIncrease ) )
|
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
placer->AmplitudeStep( 1 );
|
|
|
|
m_router->Move( end, NULL );
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
|
|
|
else if(evt->IsAction( &ACT_SpacingDecrease ) )
|
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
placer->SpacingStep( -1 );
|
|
|
|
m_router->Move( end, NULL );
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|
|
|
|
else if( evt->IsAction( &ACT_SpacingIncrease ) )
|
|
|
|
{
|
2015-02-18 00:29:54 +00:00
|
|
|
placer->SpacingStep( 1 );
|
|
|
|
m_router->Move( end, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
handleCommonEvents( *evt );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_router->StopRouting();
|
|
|
|
|
|
|
|
if( saveUndoBuffer )
|
|
|
|
{
|
|
|
|
// Save the recent changes in the undo buffer
|
|
|
|
m_frame->SaveCopyInUndoList( m_router->GetUndoBuffer(), UR_UNSPECIFIED );
|
|
|
|
m_router->ClearUndoBuffer();
|
|
|
|
m_frame->OnModify();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// It was interrupted by TA_UNDO_REDO event, so we have to sync the world now
|
|
|
|
m_needsSync = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_ctls->SetAutoPan( false );
|
|
|
|
m_ctls->ForceCursorPosition( false );
|
|
|
|
highlightNet( false );
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
int LENGTH_TUNER_TOOL::TuneSingleTrace( const TOOL_EVENT& aEvent )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_frame->SetToolID( ID_TRACK_BUTT, wxCURSOR_PENCIL, _( "Tune Trace Length" ) );
|
|
|
|
return mainLoop( PNS_MODE_TUNE_SINGLE );
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
int LENGTH_TUNER_TOOL::TuneDiffPair( const TOOL_EVENT& aEvent )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_frame->SetToolID( ID_TRACK_BUTT, wxCURSOR_PENCIL, _( "Tune Diff Pair Length" ) );
|
|
|
|
return mainLoop( PNS_MODE_TUNE_DIFF_PAIR );
|
|
|
|
}
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
|
|
|
|
int LENGTH_TUNER_TOOL::TuneDiffPairSkew( const TOOL_EVENT& aEvent )
|
2015-02-18 00:29:54 +00:00
|
|
|
{
|
|
|
|
m_frame->SetToolID( ID_TRACK_BUTT, wxCURSOR_PENCIL, _( "Tune Diff Pair Skew" ) );
|
|
|
|
return mainLoop( PNS_MODE_TUNE_DIFF_PAIR_SKEW );
|
|
|
|
}
|
2015-02-18 16:53:46 +00:00
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
int LENGTH_TUNER_TOOL::mainLoop( PNS_ROUTER_MODE aMode )
|
|
|
|
{
|
|
|
|
// Deselect all items
|
|
|
|
m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true );
|
|
|
|
|
|
|
|
Activate();
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
m_router->SetMode( aMode );
|
|
|
|
|
2015-02-18 00:29:54 +00:00
|
|
|
m_ctls->SetSnapping( true );
|
|
|
|
m_ctls->ShowCursor( true );
|
|
|
|
|
2015-02-18 16:53:46 +00:00
|
|
|
std::auto_ptr<TUNER_TOOL_MENU> ctxMenu( new TUNER_TOOL_MENU( m_board ) );
|
|
|
|
SetContextMenu( ctxMenu.get() );
|
2015-02-18 00:29:54 +00:00
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
|
|
|
if( m_needsSync )
|
|
|
|
{
|
|
|
|
m_router->SyncWorld();
|
|
|
|
m_router->SetView( getView() );
|
|
|
|
m_needsSync = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( evt->IsCancel() || evt->IsActivate() )
|
|
|
|
break; // Finish
|
|
|
|
else if( evt->Action() == TA_UNDO_REDO )
|
|
|
|
m_needsSync = true;
|
|
|
|
else if( evt->IsMotion() )
|
|
|
|
updateStartItem( *evt );
|
|
|
|
else if( evt->IsClick( BUT_LEFT ) || evt->IsAction( &ACT_StartTuning ) )
|
|
|
|
{
|
|
|
|
updateStartItem( *evt );
|
2015-02-18 16:53:46 +00:00
|
|
|
performTuning( );
|
2015-02-18 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleCommonEvents( *evt );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restore the default settings
|
|
|
|
m_ctls->SetAutoPan( false );
|
|
|
|
m_ctls->ShowCursor( false );
|
|
|
|
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
|
|
|
|
|
|
|
|
// Store routing settings till the next invocation
|
|
|
|
m_savedSettings = m_router->Settings();
|
|
|
|
m_savedSizes = m_router->Sizes();
|
|
|
|
|
|
|
|
return 0;
|
2015-02-18 16:53:46 +00:00
|
|
|
}
|