2014-07-09 11:50:27 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 CERN
|
2017-03-02 19:46:02 +00:00
|
|
|
* Copyright (C) 2014-2017 KiCad Developers, see AUTHORS.txt for contributors.
|
2014-07-09 11:50:27 +00:00
|
|
|
* @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
|
|
|
|
*/
|
2016-09-21 19:22:19 +00:00
|
|
|
#include <cstdint>
|
2017-11-23 16:20:27 +00:00
|
|
|
#include <thread>
|
|
|
|
#include <mutex>
|
2014-07-09 11:50:27 +00:00
|
|
|
|
|
|
|
#include "pcb_editor_control.h"
|
2017-02-21 12:42:08 +00:00
|
|
|
#include "pcb_actions.h"
|
2015-05-05 18:39:41 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2017-05-04 13:47:43 +00:00
|
|
|
#include <wx/progdlg.h>
|
2014-07-09 11:50:27 +00:00
|
|
|
|
2018-01-05 23:44:37 +00:00
|
|
|
#include "edit_tool.h"
|
2014-07-09 14:57:01 +00:00
|
|
|
#include "selection_tool.h"
|
2017-01-09 17:29:40 +00:00
|
|
|
#include "drawing_tool.h"
|
2015-06-18 15:51:51 +00:00
|
|
|
#include "picker_tool.h"
|
2014-07-09 14:57:01 +00:00
|
|
|
|
2015-06-18 15:51:50 +00:00
|
|
|
#include <painter.h>
|
2015-03-10 15:58:26 +00:00
|
|
|
#include <project.h>
|
|
|
|
#include <pcbnew_id.h>
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2014-07-09 11:50:27 +00:00
|
|
|
#include <class_board.h>
|
2014-07-09 14:57:01 +00:00
|
|
|
#include <class_zone.h>
|
2017-08-01 13:20:40 +00:00
|
|
|
#include <pcb_draw_panel_gal.h>
|
2015-03-10 15:58:26 +00:00
|
|
|
#include <class_module.h>
|
2017-10-31 15:38:10 +00:00
|
|
|
#include <class_pcb_target.h>
|
2017-11-15 17:33:06 +00:00
|
|
|
#include <connectivity_data.h>
|
2015-06-18 15:51:50 +00:00
|
|
|
#include <collectors.h>
|
2015-06-19 15:32:33 +00:00
|
|
|
#include <zones_functions_for_undo_redo.h>
|
2016-06-21 15:06:28 +00:00
|
|
|
#include <board_commit.h>
|
2017-02-06 03:45:56 +00:00
|
|
|
#include <confirm.h>
|
2017-02-20 12:20:39 +00:00
|
|
|
#include <bitmaps.h>
|
2017-02-20 18:10:20 +00:00
|
|
|
#include <hotkeys.h>
|
2015-03-10 15:58:26 +00:00
|
|
|
|
|
|
|
#include <view/view_group.h>
|
|
|
|
#include <view/view_controls.h>
|
2015-06-18 15:51:54 +00:00
|
|
|
#include <origin_viewitem.h>
|
2017-08-01 13:20:40 +00:00
|
|
|
#include <profile.h>
|
2014-07-09 11:50:27 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
#include <widgets/progress_reporter.h>
|
|
|
|
|
|
|
|
#ifdef USE_OPENMP
|
|
|
|
#include <omp.h>
|
|
|
|
#endif /* USE_OPENMP */
|
|
|
|
|
2017-02-04 05:09:50 +00:00
|
|
|
#include <tools/tool_event_utils.h>
|
|
|
|
|
2016-06-29 10:23:11 +00:00
|
|
|
#include <functional>
|
|
|
|
using namespace std::placeholders;
|
2015-06-19 15:32:33 +00:00
|
|
|
|
2014-07-09 14:57:01 +00:00
|
|
|
|
2017-02-20 18:10:20 +00:00
|
|
|
// Track & via size control
|
|
|
|
TOOL_ACTION PCB_ACTIONS::trackWidthInc( "pcbnew.EditorControl.trackWidthInc",
|
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_SWITCH_TRACK_WIDTH_TO_NEXT ),
|
|
|
|
"", "" );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::trackWidthDec( "pcbnew.EditorControl.trackWidthDec",
|
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_SWITCH_TRACK_WIDTH_TO_PREVIOUS ),
|
|
|
|
"", "" );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::viaSizeInc( "pcbnew.EditorControl.viaSizeInc",
|
2017-06-30 12:59:16 +00:00
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_VIA_SIZE_INC ),
|
2017-02-20 18:10:20 +00:00
|
|
|
"", "" );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::viaSizeDec( "pcbnew.EditorControl.viaSizeDec",
|
2017-06-30 12:59:16 +00:00
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_VIA_SIZE_DEC ),
|
2017-02-20 18:10:20 +00:00
|
|
|
"", "" );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::trackViaSizeChanged( "pcbnew.EditorControl.trackViaSizeChanged",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
"", "", NULL, AF_NOTIFY );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::zoneMerge( "pcbnew.EditorControl.zoneMerge",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
_( "Merge Zones" ), _( "Merge zones" ) );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::zoneDuplicate( "pcbnew.EditorControl.zoneDuplicate",
|
|
|
|
AS_GLOBAL, 0,
|
2018-02-09 16:28:33 +00:00
|
|
|
_( "Duplicate Zone onto Layer..." ), _( "Duplicate zone outline onto a different layer" ),
|
2017-02-20 18:10:20 +00:00
|
|
|
zone_duplicate_xpm );
|
|
|
|
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::placeTarget( "pcbnew.EditorControl.placeTarget",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
_( "Add Layer Alignment Target" ), _( "Add a layer alignment target" ), NULL, AF_ACTIVATE );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::placeModule( "pcbnew.EditorControl.placeModule",
|
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_ADD_MODULE ),
|
|
|
|
_( "Add Footprint" ), _( "Add a footprint" ), NULL, AF_ACTIVATE );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::drillOrigin( "pcbnew.EditorControl.drillOrigin",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
"", "" );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::crossProbeSchToPcb( "pcbnew.EditorControl.crossProbSchToPcb",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
"", "" );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::toggleLock( "pcbnew.EditorControl.toggleLock",
|
2017-06-30 12:30:10 +00:00
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_LOCK_UNLOCK_FOOTPRINT ),
|
2018-05-22 12:36:20 +00:00
|
|
|
"Toggle Lock", "", lock_unlock_xpm );
|
2017-02-20 18:10:20 +00:00
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::lock( "pcbnew.EditorControl.lock",
|
|
|
|
AS_GLOBAL, 0,
|
2018-05-22 12:36:20 +00:00
|
|
|
_( "Lock" ), "", locked_xpm );
|
2017-02-20 18:10:20 +00:00
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::unlock( "pcbnew.EditorControl.unlock",
|
|
|
|
AS_GLOBAL, 0,
|
2018-05-22 12:36:20 +00:00
|
|
|
_( "Unlock" ), "", unlocked_xpm );
|
2017-02-20 18:10:20 +00:00
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::appendBoard( "pcbnew.EditorControl.appendBoard",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
"", "" );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::highlightNet( "pcbnew.EditorControl.highlightNet",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
"", "" );
|
|
|
|
|
|
|
|
TOOL_ACTION PCB_ACTIONS::highlightNetCursor( "pcbnew.EditorControl.highlightNetCursor",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
"", "" );
|
|
|
|
|
2018-03-27 03:09:38 +00:00
|
|
|
TOOL_ACTION PCB_ACTIONS::highlightNetSelection( "pcbnew.EditorControl.highlightNetSelection",
|
|
|
|
AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_HIGHLIGHT_NET_SELECTION ),
|
|
|
|
"", "" );
|
|
|
|
|
2017-03-28 16:30:49 +00:00
|
|
|
TOOL_ACTION PCB_ACTIONS::showLocalRatsnest( "pcbnew.Control.showLocalRatsnest",
|
|
|
|
AS_GLOBAL, 0,
|
|
|
|
"", "" );
|
|
|
|
|
2014-07-09 14:57:01 +00:00
|
|
|
class ZONE_CONTEXT_MENU : public CONTEXT_MENU
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ZONE_CONTEXT_MENU()
|
|
|
|
{
|
2015-04-02 14:09:48 +00:00
|
|
|
SetIcon( add_zone_xpm );
|
2017-01-23 13:47:49 +00:00
|
|
|
SetTitle( _( "Zones" ) );
|
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
Add( PCB_ACTIONS::zoneFill );
|
|
|
|
Add( PCB_ACTIONS::zoneFillAll );
|
|
|
|
Add( PCB_ACTIONS::zoneUnfill );
|
|
|
|
Add( PCB_ACTIONS::zoneUnfillAll );
|
2017-02-06 03:45:56 +00:00
|
|
|
|
|
|
|
AppendSeparator();
|
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
Add( PCB_ACTIONS::zoneMerge );
|
|
|
|
Add( PCB_ACTIONS::zoneDuplicate );
|
|
|
|
Add( PCB_ACTIONS::drawZoneCutout );
|
|
|
|
Add( PCB_ACTIONS::drawSimilarZone );
|
2015-06-19 15:32:33 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
|
2017-01-20 17:33:11 +00:00
|
|
|
protected:
|
|
|
|
CONTEXT_MENU* create() const override
|
|
|
|
{
|
|
|
|
return new ZONE_CONTEXT_MENU();
|
|
|
|
}
|
|
|
|
|
2015-06-19 15:32:33 +00:00
|
|
|
private:
|
2017-01-20 17:33:11 +00:00
|
|
|
void update() override
|
2015-06-19 15:32:33 +00:00
|
|
|
{
|
|
|
|
SELECTION_TOOL* selTool = getToolManager()->GetTool<SELECTION_TOOL>();
|
|
|
|
|
2017-02-06 03:45:56 +00:00
|
|
|
// enable zone actions that act on a single zone
|
|
|
|
bool singleZoneActionsEnabled = ( SELECTION_CONDITIONS::Count( 1 )
|
|
|
|
&& SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T )
|
|
|
|
)( selTool->GetSelection() );
|
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
Enable( getMenuId( PCB_ACTIONS::zoneDuplicate ), singleZoneActionsEnabled );
|
|
|
|
Enable( getMenuId( PCB_ACTIONS::drawZoneCutout ), singleZoneActionsEnabled );
|
|
|
|
Enable( getMenuId( PCB_ACTIONS::drawSimilarZone ), singleZoneActionsEnabled );
|
2017-02-06 03:45:56 +00:00
|
|
|
|
2017-01-09 17:29:40 +00:00
|
|
|
// enable zone actions that ably to a specific set of zones (as opposed to all of them)
|
|
|
|
bool nonGlobalActionsEnabled = ( SELECTION_CONDITIONS::MoreThan( 0 ) )( selTool->GetSelection() );
|
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
Enable( getMenuId( PCB_ACTIONS::zoneFill ), nonGlobalActionsEnabled );
|
|
|
|
Enable( getMenuId( PCB_ACTIONS::zoneUnfill ), nonGlobalActionsEnabled );
|
2017-01-09 17:29:40 +00:00
|
|
|
|
2015-06-19 15:32:33 +00:00
|
|
|
// lines like this make me really think about a better name for SELECTION_CONDITIONS class
|
|
|
|
bool mergeEnabled = ( SELECTION_CONDITIONS::MoreThan( 1 ) &&
|
|
|
|
/*SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T ) &&*/
|
2017-02-28 03:04:44 +00:00
|
|
|
PCB_SELECTION_CONDITIONS::SameNet( true ) &&
|
|
|
|
PCB_SELECTION_CONDITIONS::SameLayer() )( selTool->GetSelection() );
|
2015-06-19 15:32:33 +00:00
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
Enable( getMenuId( PCB_ACTIONS::zoneMerge ), mergeEnabled );
|
2014-07-09 14:57:01 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-05-09 08:29:06 +00:00
|
|
|
class LOCK_CONTEXT_MENU : public CONTEXT_MENU
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LOCK_CONTEXT_MENU()
|
|
|
|
{
|
|
|
|
SetIcon( locked_xpm );
|
2017-01-23 13:47:49 +00:00
|
|
|
SetTitle( _( "Locking" ) );
|
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
Add( PCB_ACTIONS::lock );
|
|
|
|
Add( PCB_ACTIONS::unlock );
|
|
|
|
Add( PCB_ACTIONS::toggleLock );
|
2016-05-09 08:29:06 +00:00
|
|
|
}
|
2017-01-20 17:33:11 +00:00
|
|
|
|
|
|
|
CONTEXT_MENU* create() const override
|
|
|
|
{
|
|
|
|
return new LOCK_CONTEXT_MENU();
|
|
|
|
}
|
2016-05-09 08:29:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
PCB_EDITOR_CONTROL::PCB_EDITOR_CONTROL() :
|
2017-02-24 12:26:43 +00:00
|
|
|
PCB_TOOL( "pcbnew.EditorControl" ),
|
2018-02-11 01:15:16 +00:00
|
|
|
m_frame( nullptr ),
|
|
|
|
m_menu( *this )
|
2014-07-09 11:50:27 +00:00
|
|
|
{
|
2017-03-02 22:57:13 +00:00
|
|
|
m_placeOrigin.reset( new KIGFX::ORIGIN_VIEWITEM( KIGFX::COLOR4D( 0.8, 0.0, 0.0, 1.0 ),
|
|
|
|
KIGFX::ORIGIN_VIEWITEM::CIRCLE_CROSS ) );
|
2015-06-26 15:32:48 +00:00
|
|
|
m_probingSchToPcb = false;
|
2017-08-01 13:20:40 +00:00
|
|
|
m_slowRatsnest = false;
|
2015-06-18 15:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PCB_EDITOR_CONTROL::~PCB_EDITOR_CONTROL()
|
|
|
|
{
|
2014-07-09 11:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_EDITOR_CONTROL::Reset( RESET_REASON aReason )
|
|
|
|
{
|
|
|
|
m_frame = getEditFrame<PCB_EDIT_FRAME>();
|
2015-06-18 15:51:54 +00:00
|
|
|
|
|
|
|
if( aReason == MODEL_RELOAD || aReason == GAL_SWITCH )
|
|
|
|
{
|
|
|
|
m_placeOrigin->SetPosition( getModel<BOARD>()->GetAuxOrigin() );
|
2017-03-02 22:57:13 +00:00
|
|
|
getView()->Remove( m_placeOrigin.get() );
|
|
|
|
getView()->Add( m_placeOrigin.get() );
|
2015-06-18 15:51:54 +00:00
|
|
|
}
|
2014-07-09 11:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PCB_EDITOR_CONTROL::Init()
|
|
|
|
{
|
2018-02-11 01:15:16 +00:00
|
|
|
auto activeToolCondition = [ this ] ( const SELECTION& aSel ) {
|
|
|
|
return ( m_frame->GetToolId() != ID_NO_TOOL_SELECTED );
|
|
|
|
};
|
|
|
|
|
|
|
|
auto inactiveStateCondition = [ this ] ( const SELECTION& aSel ) {
|
|
|
|
return ( m_frame->GetToolId() == ID_NO_TOOL_SELECTED && aSel.Size() == 0 );
|
|
|
|
};
|
|
|
|
|
|
|
|
auto placeModuleCondition = [ this ] ( const SELECTION& aSel ) {
|
|
|
|
return ( m_frame->GetToolId() == ID_PCB_MODULE_BUTT && aSel.GetSize() == 0 );
|
|
|
|
};
|
|
|
|
|
|
|
|
auto& ctxMenu = m_menu.GetMenu();
|
|
|
|
|
|
|
|
// "Cancel" goes at the top of the context menu when a tool is active
|
|
|
|
ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolCondition, 1000 );
|
|
|
|
ctxMenu.AddSeparator( activeToolCondition, 1000 );
|
|
|
|
|
|
|
|
// "Get and Place Footprint" should be available for Place Footprint tool
|
|
|
|
ctxMenu.AddItem( PCB_ACTIONS::findMove, placeModuleCondition, 1000 );
|
|
|
|
ctxMenu.AddSeparator( placeModuleCondition, 1000 );
|
|
|
|
|
|
|
|
// Finally, add the standard zoom & grid items
|
|
|
|
m_menu.AddStandardSubMenus( *getEditFrame<PCB_BASE_FRAME>() );
|
|
|
|
|
2017-01-12 10:07:52 +00:00
|
|
|
auto zoneMenu = std::make_shared<ZONE_CONTEXT_MENU>();
|
|
|
|
zoneMenu->SetTool( this );
|
2017-01-09 17:29:40 +00:00
|
|
|
|
2017-01-12 10:07:52 +00:00
|
|
|
auto lockMenu = std::make_shared<LOCK_CONTEXT_MENU>();
|
|
|
|
lockMenu->SetTool( this );
|
2017-01-09 17:29:40 +00:00
|
|
|
|
|
|
|
// Add the PCB control menus to relevant other tools
|
|
|
|
|
2014-07-09 14:57:01 +00:00
|
|
|
SELECTION_TOOL* selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
|
|
|
|
|
|
|
if( selTool )
|
|
|
|
{
|
2017-01-12 10:07:52 +00:00
|
|
|
auto& toolMenu = selTool->GetToolMenu();
|
|
|
|
auto& menu = toolMenu.GetMenu();
|
2016-05-09 08:29:06 +00:00
|
|
|
|
2018-02-11 01:15:16 +00:00
|
|
|
// Add "Get and Place Footprint" when Selection tool is in an inactive state
|
|
|
|
menu.AddItem( PCB_ACTIONS::findMove, inactiveStateCondition );
|
|
|
|
menu.AddSeparator( inactiveStateCondition );
|
|
|
|
|
2017-01-12 10:07:52 +00:00
|
|
|
toolMenu.AddSubMenu( zoneMenu );
|
|
|
|
toolMenu.AddSubMenu( lockMenu );
|
|
|
|
|
2017-01-23 13:47:49 +00:00
|
|
|
menu.AddMenu( zoneMenu.get(), false,
|
|
|
|
SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T ) );
|
2017-01-12 10:07:52 +00:00
|
|
|
|
2017-01-23 13:47:49 +00:00
|
|
|
menu.AddMenu( lockMenu.get(), false,
|
2018-05-02 15:34:13 +00:00
|
|
|
SELECTION_CONDITIONS::OnlyTypes( GENERAL_COLLECTOR::LockableItems ) );
|
2014-07-09 14:57:01 +00:00
|
|
|
}
|
|
|
|
|
2017-01-09 17:29:40 +00:00
|
|
|
DRAWING_TOOL* drawingTool = m_toolMgr->GetTool<DRAWING_TOOL>();
|
|
|
|
|
|
|
|
if( drawingTool )
|
|
|
|
{
|
2017-01-12 10:07:52 +00:00
|
|
|
auto& toolMenu = drawingTool->GetToolMenu();
|
|
|
|
auto& menu = toolMenu.GetMenu();
|
|
|
|
|
|
|
|
toolMenu.AddSubMenu( zoneMenu );
|
|
|
|
|
2017-01-09 17:29:40 +00:00
|
|
|
// Functor to say if the PCB_EDIT_FRAME is in a given mode
|
|
|
|
// Capture the tool pointer and tool mode by value
|
|
|
|
auto toolActiveFunctor = [=]( DRAWING_TOOL::MODE aMode )
|
|
|
|
{
|
|
|
|
return [=]( const SELECTION& sel )
|
|
|
|
{
|
|
|
|
return drawingTool->GetDrawingMode() == aMode;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-01-23 13:47:49 +00:00
|
|
|
menu.AddMenu( zoneMenu.get(), false, toolActiveFunctor( DRAWING_TOOL::MODE::ZONE ) );
|
2017-01-09 17:29:40 +00:00
|
|
|
}
|
|
|
|
|
2017-08-01 13:20:40 +00:00
|
|
|
m_ratsnestTimer.SetOwner( this );
|
|
|
|
Connect( m_ratsnestTimer.GetId(), wxEVT_TIMER,
|
|
|
|
wxTimerEventHandler( PCB_EDITOR_CONTROL::ratsnestTimer ), NULL, this );
|
|
|
|
|
2014-07-09 11:50:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Track & via size control
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCB_EDITOR_CONTROL::TrackWidthInc( const TOOL_EVENT& aEvent )
|
2014-07-09 11:50:27 +00:00
|
|
|
{
|
|
|
|
BOARD* board = getModel<BOARD>();
|
|
|
|
int widthIndex = board->GetDesignSettings().GetTrackWidthIndex() + 1;
|
|
|
|
|
|
|
|
if( widthIndex >= (int) board->GetDesignSettings().m_TrackWidthList.size() )
|
|
|
|
widthIndex = board->GetDesignSettings().m_TrackWidthList.size() - 1;
|
|
|
|
|
|
|
|
board->GetDesignSettings().SetTrackWidthIndex( widthIndex );
|
|
|
|
board->GetDesignSettings().UseCustomTrackViaSize( false );
|
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::trackViaSizeChanged );
|
2014-07-09 11:50:27 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCB_EDITOR_CONTROL::TrackWidthDec( const TOOL_EVENT& aEvent )
|
2014-07-09 11:50:27 +00:00
|
|
|
{
|
|
|
|
BOARD* board = getModel<BOARD>();
|
|
|
|
int widthIndex = board->GetDesignSettings().GetTrackWidthIndex() - 1;
|
|
|
|
|
|
|
|
if( widthIndex < 0 )
|
|
|
|
widthIndex = 0;
|
|
|
|
|
|
|
|
board->GetDesignSettings().SetTrackWidthIndex( widthIndex );
|
|
|
|
board->GetDesignSettings().UseCustomTrackViaSize( false );
|
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::trackViaSizeChanged );
|
2014-07-09 11:50:27 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCB_EDITOR_CONTROL::ViaSizeInc( const TOOL_EVENT& aEvent )
|
2014-07-09 11:50:27 +00:00
|
|
|
{
|
|
|
|
BOARD* board = getModel<BOARD>();
|
|
|
|
int sizeIndex = board->GetDesignSettings().GetViaSizeIndex() + 1;
|
|
|
|
|
|
|
|
if( sizeIndex >= (int) board->GetDesignSettings().m_ViasDimensionsList.size() )
|
|
|
|
sizeIndex = board->GetDesignSettings().m_ViasDimensionsList.size() - 1;
|
|
|
|
|
|
|
|
board->GetDesignSettings().SetViaSizeIndex( sizeIndex );
|
|
|
|
board->GetDesignSettings().UseCustomTrackViaSize( false );
|
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::trackViaSizeChanged );
|
2014-07-09 11:50:27 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-14 20:28:47 +00:00
|
|
|
int PCB_EDITOR_CONTROL::ViaSizeDec( const TOOL_EVENT& aEvent )
|
2014-07-09 11:50:27 +00:00
|
|
|
{
|
|
|
|
BOARD* board = getModel<BOARD>();
|
|
|
|
int sizeIndex = board->GetDesignSettings().GetViaSizeIndex() - 1;
|
|
|
|
|
|
|
|
if( sizeIndex < 0 )
|
|
|
|
sizeIndex = 0;
|
|
|
|
|
|
|
|
board->GetDesignSettings().SetViaSizeIndex( sizeIndex );
|
|
|
|
board->GetDesignSettings().UseCustomTrackViaSize( false );
|
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::trackViaSizeChanged );
|
2014-07-09 11:50:27 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-10 15:58:26 +00:00
|
|
|
int PCB_EDITOR_CONTROL::PlaceModule( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2017-05-18 17:21:30 +00:00
|
|
|
MODULE* module = aEvent.Parameter<MODULE*>();
|
2015-03-10 15:58:26 +00:00
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
2017-12-14 16:10:06 +00:00
|
|
|
SELECTION_TOOL* selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
|
|
|
SELECTION& selection = selTool->GetSelection();
|
|
|
|
BOARD_COMMIT commit( m_frame );
|
2015-03-10 15:58:26 +00:00
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2015-03-10 15:58:26 +00:00
|
|
|
controls->ShowCursor( true );
|
|
|
|
controls->SetSnapping( true );
|
|
|
|
|
|
|
|
Activate();
|
2017-06-12 14:17:48 +00:00
|
|
|
m_frame->SetToolID( ID_PCB_MODULE_BUTT, wxCURSOR_PENCIL, _( "Add footprint" ) );
|
2015-03-10 15:58:26 +00:00
|
|
|
|
2017-05-18 17:21:30 +00:00
|
|
|
// Add all the drawable parts to preview
|
2017-09-17 17:49:06 +00:00
|
|
|
VECTOR2I cursorPos = controls->GetCursorPosition();
|
2017-12-14 16:10:06 +00:00
|
|
|
|
2017-05-18 17:21:30 +00:00
|
|
|
if( module )
|
|
|
|
{
|
2017-09-17 17:49:06 +00:00
|
|
|
module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
|
2017-12-14 16:10:06 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, module );
|
2017-05-18 17:21:30 +00:00
|
|
|
}
|
|
|
|
|
2018-01-19 13:20:15 +00:00
|
|
|
bool reselect = false;
|
|
|
|
|
2015-03-10 15:58:26 +00:00
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
2017-09-17 17:49:06 +00:00
|
|
|
cursorPos = controls->GetCursorPosition();
|
2015-03-10 15:58:26 +00:00
|
|
|
|
2018-01-19 13:20:15 +00:00
|
|
|
if( reselect && module )
|
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, module );
|
|
|
|
|
2018-02-11 01:15:16 +00:00
|
|
|
if( evt->IsCancel() || TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
|
2015-03-10 15:58:26 +00:00
|
|
|
{
|
|
|
|
if( module )
|
|
|
|
{
|
2017-12-14 16:10:06 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
|
|
|
commit.Revert();
|
2015-03-10 15:58:26 +00:00
|
|
|
module = NULL;
|
|
|
|
}
|
2017-12-14 16:10:06 +00:00
|
|
|
else // let's have another chance placing a module
|
2015-03-10 15:58:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if( evt->IsActivate() ) // now finish unconditionally
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
if( !module )
|
|
|
|
{
|
2015-09-21 08:16:23 +00:00
|
|
|
// Pick the module to be placed
|
2018-04-02 21:31:45 +00:00
|
|
|
module = m_frame->LoadModuleFromLibrary( wxEmptyString );
|
2016-08-16 14:56:20 +00:00
|
|
|
|
2015-03-10 15:58:26 +00:00
|
|
|
if( module == NULL )
|
|
|
|
continue;
|
|
|
|
|
2018-04-02 21:31:45 +00:00
|
|
|
m_frame->AddModuleToBoard( module );
|
2017-12-14 16:10:06 +00:00
|
|
|
commit.Added( module );
|
2015-03-10 15:58:26 +00:00
|
|
|
module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
|
2017-12-14 16:10:06 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, module );
|
|
|
|
controls->SetCursorPosition( cursorPos, false );
|
2015-03-10 15:58:26 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-12-14 16:10:06 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2016-06-21 15:06:28 +00:00
|
|
|
commit.Push( _( "Place a module" ) );
|
2015-03-10 15:58:26 +00:00
|
|
|
module = NULL; // to indicate that there is no module that we currently modify
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-11 01:15:16 +00:00
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
|
|
|
m_menu.ShowContextMenu( selTool->GetSelection() );
|
|
|
|
}
|
|
|
|
|
2015-03-10 15:58:26 +00:00
|
|
|
else if( module && evt->IsMotion() )
|
|
|
|
{
|
|
|
|
module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
|
2017-12-14 16:10:06 +00:00
|
|
|
selection.SetReferencePoint( cursorPos );
|
|
|
|
getView()->Update( &selection );
|
2015-03-10 15:58:26 +00:00
|
|
|
}
|
2018-01-19 13:20:15 +00:00
|
|
|
|
|
|
|
else if( module && evt->IsAction( &PCB_ACTIONS::properties ) )
|
|
|
|
{
|
|
|
|
// Calling 'Properties' action clears the selection, so we need to restore it
|
|
|
|
reselect = true;
|
|
|
|
}
|
2018-02-15 10:53:17 +00:00
|
|
|
|
|
|
|
// Enable autopanning and cursor capture only when there is a module to be placed
|
|
|
|
controls->SetAutoPan( !!module );
|
|
|
|
controls->CaptureCursor( !!module );
|
2015-03-10 15:58:26 +00:00
|
|
|
}
|
|
|
|
|
2017-06-12 13:10:43 +00:00
|
|
|
m_frame->SetNoToolSelected();
|
2015-03-10 15:58:26 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-09 08:29:06 +00:00
|
|
|
int PCB_EDITOR_CONTROL::ToggleLockSelected( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
return modifyLockSelected( TOGGLE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PCB_EDITOR_CONTROL::LockSelected( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
return modifyLockSelected( ON );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PCB_EDITOR_CONTROL::UnlockSelected( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
return modifyLockSelected( OFF );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PCB_EDITOR_CONTROL::modifyLockSelected( MODIFY_MODE aMode )
|
2015-09-03 15:35:41 +00:00
|
|
|
{
|
|
|
|
SELECTION_TOOL* selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
|
|
|
const SELECTION& selection = selTool->GetSelection();
|
|
|
|
|
2016-05-09 08:29:06 +00:00
|
|
|
if( selection.Empty() )
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionCursor, true );
|
2015-09-03 15:35:41 +00:00
|
|
|
|
2016-05-09 08:29:06 +00:00
|
|
|
bool modified = false;
|
|
|
|
|
2017-02-28 03:04:44 +00:00
|
|
|
for( auto i : selection )
|
2015-09-03 15:35:41 +00:00
|
|
|
{
|
2017-02-28 03:04:44 +00:00
|
|
|
auto item = static_cast<BOARD_ITEM*>( i );
|
2016-05-09 08:29:06 +00:00
|
|
|
bool prevState = item->IsLocked();
|
|
|
|
|
|
|
|
switch( aMode )
|
2015-09-03 15:35:41 +00:00
|
|
|
{
|
2016-05-09 08:29:06 +00:00
|
|
|
case ON:
|
|
|
|
item->SetLocked( true );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OFF:
|
|
|
|
item->SetLocked( false );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOGGLE:
|
|
|
|
item->SetLocked( !prevState );
|
|
|
|
break;
|
2015-09-03 15:35:41 +00:00
|
|
|
}
|
2016-05-09 08:29:06 +00:00
|
|
|
|
|
|
|
// Check if we really modified an item
|
|
|
|
if( !modified && prevState != item->IsLocked() )
|
|
|
|
modified = true;
|
2015-09-03 15:35:41 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 08:29:06 +00:00
|
|
|
if( modified )
|
|
|
|
m_frame->OnModify();
|
2015-09-03 15:35:41 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-10 15:58:26 +00:00
|
|
|
int PCB_EDITOR_CONTROL::PlaceTarget( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2018-02-11 01:15:16 +00:00
|
|
|
auto selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
2015-03-10 15:58:26 +00:00
|
|
|
KIGFX::VIEW* view = getView();
|
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
|
|
|
BOARD* board = getModel<BOARD>();
|
|
|
|
PCB_TARGET* target = new PCB_TARGET( board );
|
|
|
|
|
|
|
|
// Init the new item attributes
|
|
|
|
target->SetLayer( Edge_Cuts );
|
|
|
|
target->SetWidth( board->GetDesignSettings().m_EdgeSegmentWidth );
|
|
|
|
target->SetSize( Millimeter2iu( 5 ) );
|
|
|
|
VECTOR2I cursorPos = controls->GetCursorPosition();
|
|
|
|
target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
|
|
|
|
|
|
|
|
// Add a VIEW_GROUP that serves as a preview for the new item
|
|
|
|
KIGFX::VIEW_GROUP preview( view );
|
|
|
|
preview.Add( target );
|
|
|
|
view->Add( &preview );
|
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2015-03-10 15:58:26 +00:00
|
|
|
controls->SetSnapping( true );
|
|
|
|
|
|
|
|
Activate();
|
2017-10-31 15:38:10 +00:00
|
|
|
m_frame->SetToolID( ID_PCB_TARGET_BUTT, wxCURSOR_PENCIL, _( "Add layer alignment target" ) );
|
2015-03-10 15:58:26 +00:00
|
|
|
|
|
|
|
// Main loop: keep receiving events
|
|
|
|
while( OPT_TOOL_EVENT evt = Wait() )
|
|
|
|
{
|
|
|
|
cursorPos = controls->GetCursorPosition();
|
|
|
|
|
2018-02-11 01:15:16 +00:00
|
|
|
if( evt->IsCancel() || TOOL_EVT_UTILS::IsCancelInteractive( *evt ) || evt->IsActivate() )
|
2015-03-10 15:58:26 +00:00
|
|
|
break;
|
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
|
2015-03-10 15:58:26 +00:00
|
|
|
{
|
|
|
|
target->SetWidth( target->GetWidth() + WIDTH_STEP );
|
2016-12-02 17:58:12 +00:00
|
|
|
view->Update( &preview );
|
2015-03-10 15:58:26 +00:00
|
|
|
}
|
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
else if( evt->IsAction( &PCB_ACTIONS::decWidth ) )
|
2015-03-10 15:58:26 +00:00
|
|
|
{
|
|
|
|
int width = target->GetWidth();
|
|
|
|
|
|
|
|
if( width > WIDTH_STEP )
|
|
|
|
{
|
|
|
|
target->SetWidth( width - WIDTH_STEP );
|
2016-12-02 17:58:12 +00:00
|
|
|
view->Update( &preview );
|
2015-03-10 15:58:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if( evt->IsClick( BUT_LEFT ) )
|
|
|
|
{
|
|
|
|
assert( target->GetSize() > 0 );
|
|
|
|
assert( target->GetWidth() > 0 );
|
|
|
|
|
2016-06-21 15:06:28 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
|
|
|
commit.Add( target );
|
|
|
|
commit.Push( _( "Place a layer alignment target" ) );
|
2015-03-10 15:58:26 +00:00
|
|
|
|
|
|
|
preview.Remove( target );
|
|
|
|
|
|
|
|
// Create next PCB_TARGET
|
|
|
|
target = new PCB_TARGET( *target );
|
|
|
|
preview.Add( target );
|
|
|
|
}
|
|
|
|
|
2018-02-11 01:15:16 +00:00
|
|
|
else if( evt->IsClick( BUT_RIGHT ) )
|
|
|
|
{
|
|
|
|
m_menu.ShowContextMenu( selTool->GetSelection() );
|
|
|
|
}
|
|
|
|
|
2015-03-10 15:58:26 +00:00
|
|
|
else if( evt->IsMotion() )
|
|
|
|
{
|
|
|
|
target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
|
2016-12-02 17:58:12 +00:00
|
|
|
view->Update( &preview );
|
2015-03-10 15:58:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete target;
|
|
|
|
|
|
|
|
controls->SetSnapping( false );
|
|
|
|
view->Remove( &preview );
|
|
|
|
|
2017-06-12 13:10:43 +00:00
|
|
|
m_frame->SetNoToolSelected();
|
2015-03-10 15:58:26 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
static bool mergeZones( BOARD_COMMIT& aCommit, std::vector<ZONE_CONTAINER *>& aOriginZones,
|
|
|
|
std::vector<ZONE_CONTAINER *>& aMergedZones )
|
2016-11-04 21:29:47 +00:00
|
|
|
{
|
2016-12-09 11:04:32 +00:00
|
|
|
for( unsigned int i = 1; i < aOriginZones.size(); i++ )
|
2016-11-04 21:29:47 +00:00
|
|
|
{
|
2017-03-07 12:06:00 +00:00
|
|
|
aOriginZones[0]->Outline()->BooleanAdd( *aOriginZones[i]->Outline(),
|
|
|
|
SHAPE_POLY_SET::PM_FAST );
|
2016-11-04 21:29:47 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
aOriginZones[0]->Outline()->Simplify( SHAPE_POLY_SET::PM_FAST );
|
2016-11-04 21:29:47 +00:00
|
|
|
|
|
|
|
// We should have one polygon with hole
|
|
|
|
// We can have 2 polygons with hole, if the 2 initial polygons have only one common corner
|
|
|
|
// and therefore cannot be merged (they are dectected as intersecting)
|
|
|
|
// but we should never have more than 2 polys
|
2017-03-07 12:06:00 +00:00
|
|
|
if( aOriginZones[0]->Outline()->OutlineCount() > 1 )
|
2016-11-04 21:29:47 +00:00
|
|
|
{
|
2016-12-09 11:04:32 +00:00
|
|
|
wxLogMessage( wxT( "BOARD::CombineAreas error: more than 2 polys after merging" ) );
|
2016-11-04 21:29:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
for( unsigned int i = 1; i < aOriginZones.size(); i++ )
|
2016-11-04 21:29:47 +00:00
|
|
|
{
|
|
|
|
aCommit.Remove( aOriginZones[i] );
|
|
|
|
}
|
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
aCommit.Modify( aOriginZones[0] );
|
2016-11-04 21:29:47 +00:00
|
|
|
aMergedZones.push_back( aOriginZones[0] );
|
|
|
|
|
|
|
|
aOriginZones[0]->SetLocalFlags( 1 );
|
2017-03-07 12:06:00 +00:00
|
|
|
aOriginZones[0]->Hatch();
|
2017-11-23 16:20:27 +00:00
|
|
|
aOriginZones[0]->CacheTriangulation();
|
2016-11-04 21:29:47 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2014-12-08 22:41:47 +00:00
|
|
|
|
2018-05-04 12:01:26 +00:00
|
|
|
|
2015-06-19 15:32:33 +00:00
|
|
|
int PCB_EDITOR_CONTROL::ZoneMerge( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2017-03-03 12:42:28 +00:00
|
|
|
const SELECTION& selection = m_toolMgr->GetTool<SELECTION_TOOL>()->GetSelection();
|
2015-06-19 15:32:33 +00:00
|
|
|
BOARD* board = getModel<BOARD>();
|
2016-06-21 15:06:28 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
2015-06-19 15:32:33 +00:00
|
|
|
|
|
|
|
if( selection.Size() < 2 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
int netcode = -1;
|
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
ZONE_CONTAINER* firstZone = nullptr;
|
|
|
|
std::vector<ZONE_CONTAINER*> toMerge, merged;
|
2016-11-04 21:29:47 +00:00
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
for( auto item : selection )
|
2015-06-19 15:32:33 +00:00
|
|
|
{
|
2016-11-04 21:29:47 +00:00
|
|
|
auto curr_area = dynamic_cast<ZONE_CONTAINER*>( item );
|
2015-06-19 15:32:33 +00:00
|
|
|
|
|
|
|
if( !curr_area )
|
|
|
|
continue;
|
|
|
|
|
2016-11-04 21:29:47 +00:00
|
|
|
if( !firstZone )
|
|
|
|
firstZone = curr_area;
|
2015-06-19 15:32:33 +00:00
|
|
|
|
2016-11-04 21:29:47 +00:00
|
|
|
netcode = curr_area->GetNetCode();
|
2015-06-19 15:32:33 +00:00
|
|
|
|
2018-05-04 12:01:26 +00:00
|
|
|
if( firstZone->GetNetCode() != netcode )
|
|
|
|
continue;
|
2015-06-19 15:32:33 +00:00
|
|
|
|
2018-05-04 12:01:26 +00:00
|
|
|
if( curr_area->GetPriority() != firstZone->GetPriority() )
|
|
|
|
continue;
|
2015-06-19 15:32:33 +00:00
|
|
|
|
2018-05-04 12:01:26 +00:00
|
|
|
if( curr_area->GetIsKeepout() != firstZone->GetIsKeepout() )
|
|
|
|
continue;
|
2015-06-19 15:32:33 +00:00
|
|
|
|
2018-05-04 12:01:26 +00:00
|
|
|
if( curr_area->GetLayer() != firstZone->GetLayer() )
|
|
|
|
continue;
|
2015-06-19 15:32:33 +00:00
|
|
|
|
2018-05-04 12:01:26 +00:00
|
|
|
if( !board->TestAreaIntersection( curr_area, firstZone ) )
|
|
|
|
continue;
|
2015-06-19 15:32:33 +00:00
|
|
|
|
2018-05-04 12:01:26 +00:00
|
|
|
toMerge.push_back( curr_area );
|
2015-06-19 15:32:33 +00:00
|
|
|
}
|
|
|
|
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2016-06-21 15:06:28 +00:00
|
|
|
|
2016-12-09 11:04:32 +00:00
|
|
|
if( mergeZones( commit, toMerge, merged ) )
|
2015-06-19 15:32:33 +00:00
|
|
|
{
|
2016-11-04 21:29:47 +00:00
|
|
|
commit.Push( _( "Merge zones" ) );
|
2016-12-09 11:04:32 +00:00
|
|
|
|
|
|
|
for( auto item : merged )
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, item );
|
2015-06-19 15:32:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-06 03:45:56 +00:00
|
|
|
int PCB_EDITOR_CONTROL::ZoneDuplicate( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
auto selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
|
|
|
const auto& selection = selTool->GetSelection();
|
|
|
|
|
2018-05-25 14:56:04 +00:00
|
|
|
// because this pops up the zone editor, it would be confusing to handle multiple zones,
|
|
|
|
// so just handle single selections containing exactly one zone
|
2017-02-06 03:45:56 +00:00
|
|
|
if( selection.Size() != 1 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
auto oldZone = dyn_cast<ZONE_CONTAINER*>( selection[0] );
|
|
|
|
|
|
|
|
if( !oldZone )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ZONE_SETTINGS zoneSettings;
|
|
|
|
zoneSettings << *oldZone;
|
2018-05-25 14:56:04 +00:00
|
|
|
int dialogResult;
|
2017-02-06 03:45:56 +00:00
|
|
|
|
|
|
|
if( oldZone->GetIsKeepout() )
|
2018-05-25 14:56:04 +00:00
|
|
|
dialogResult = InvokeKeepoutAreaEditor( m_frame, &zoneSettings );
|
2017-02-06 03:45:56 +00:00
|
|
|
else if( oldZone->IsOnCopperLayer() )
|
2018-05-25 14:56:04 +00:00
|
|
|
dialogResult = InvokeCopperZonesEditor( m_frame, &zoneSettings );
|
2017-02-06 03:45:56 +00:00
|
|
|
else
|
2018-05-25 14:56:04 +00:00
|
|
|
dialogResult = InvokeNonCopperZonesEditor( m_frame, &zoneSettings );
|
|
|
|
|
|
|
|
if( dialogResult != wxID_OK )
|
|
|
|
return 0;
|
2017-02-06 03:45:56 +00:00
|
|
|
|
|
|
|
// duplicate the zone
|
2018-05-25 14:56:04 +00:00
|
|
|
BOARD_COMMIT commit( m_frame );
|
|
|
|
|
|
|
|
auto newZone = std::make_unique<ZONE_CONTAINER>( *oldZone );
|
|
|
|
newZone->ClearSelected();
|
|
|
|
newZone->UnFill();
|
|
|
|
zoneSettings.ExportSetting( *newZone );
|
|
|
|
|
|
|
|
// If the new zone is on the same layer(s) as the the initial zone,
|
|
|
|
// offset it a bit so it can more easily be picked.
|
|
|
|
if( oldZone->GetIsKeepout() && ( oldZone->GetLayerSet() == zoneSettings.m_Layers ) )
|
|
|
|
newZone->Move( wxPoint( IU_PER_MM, IU_PER_MM ) );
|
|
|
|
else if( !oldZone->GetIsKeepout() && ( oldZone->GetLayer() == zoneSettings.m_CurrentZone_Layer ) )
|
|
|
|
newZone->Move( wxPoint( IU_PER_MM, IU_PER_MM ) );
|
|
|
|
|
|
|
|
commit.Add( newZone.release() );
|
|
|
|
commit.Push( _( "Duplicate zone" ) );
|
2017-02-06 03:45:56 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-26 15:32:48 +00:00
|
|
|
int PCB_EDITOR_CONTROL::CrossProbePcbToSch( const TOOL_EVENT& aEvent )
|
2015-02-14 20:52:22 +00:00
|
|
|
{
|
2015-06-26 15:32:48 +00:00
|
|
|
if( m_probingSchToPcb )
|
|
|
|
{
|
|
|
|
m_probingSchToPcb = false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-14 20:52:22 +00:00
|
|
|
SELECTION_TOOL* selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
|
|
|
const SELECTION& selection = selTool->GetSelection();
|
|
|
|
|
|
|
|
if( selection.Size() == 1 )
|
2017-02-28 03:04:44 +00:00
|
|
|
m_frame->SendMessageToEESCHEMA( static_cast<BOARD_ITEM*>( selection.Front() ) );
|
2015-02-14 20:52:22 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-26 15:32:48 +00:00
|
|
|
int PCB_EDITOR_CONTROL::CrossProbeSchToPcb( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
BOARD_ITEM* item = aEvent.Parameter<BOARD_ITEM*>();
|
|
|
|
|
|
|
|
if( item )
|
|
|
|
{
|
|
|
|
m_probingSchToPcb = true;
|
|
|
|
getView()->SetCenter( VECTOR2D( item->GetPosition() ) );
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2016-01-25 15:16:05 +00:00
|
|
|
|
|
|
|
// If it is a pad and the net highlighting tool is enabled, highlight the net
|
|
|
|
if( item->Type() == PCB_PAD_T && m_frame->GetToolId() == ID_PCB_HIGHLIGHT_BUTT )
|
|
|
|
{
|
|
|
|
int net = static_cast<D_PAD*>( item )->GetNetCode();
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::highlightNet, false, net );
|
2016-01-25 15:16:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
// Otherwise simply select the corresponding item
|
|
|
|
{
|
2017-02-21 12:42:08 +00:00
|
|
|
m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, item );
|
2018-02-16 10:52:59 +00:00
|
|
|
// Ensure the display is refreshed, because in some installs
|
|
|
|
// the refresh is done only when the gal canvas has the focus, and
|
|
|
|
// that is not the case when crossprobing from Eeschema:
|
|
|
|
m_frame->GetGalCanvas()->Refresh();
|
2016-01-25 15:16:05 +00:00
|
|
|
}
|
2015-06-26 15:32:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-24 10:19:33 +00:00
|
|
|
bool PCB_EDITOR_CONTROL::DoSetDrillOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame,
|
|
|
|
BOARD_ITEM* originViewItem, const VECTOR2D& aPosition )
|
2015-06-18 15:51:51 +00:00
|
|
|
{
|
|
|
|
aFrame->SetAuxOrigin( wxPoint( aPosition.x, aPosition.y ) );
|
2018-01-24 10:19:33 +00:00
|
|
|
originViewItem->SetPosition( wxPoint( aPosition.x, aPosition.y ) );
|
2015-06-18 15:51:54 +00:00
|
|
|
aView->MarkDirty();
|
2018-01-24 21:27:56 +00:00
|
|
|
aFrame->OnModify();
|
2015-06-18 15:51:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-24 10:19:33 +00:00
|
|
|
bool PCB_EDITOR_CONTROL::SetDrillOrigin( KIGFX::VIEW* aView, PCB_BASE_FRAME* aFrame,
|
|
|
|
BOARD_ITEM* originViewItem, const VECTOR2D& aPosition )
|
|
|
|
{
|
|
|
|
aFrame->SaveCopyInUndoList( originViewItem, UR_DRILLORIGIN );
|
2018-01-24 21:27:56 +00:00
|
|
|
return DoSetDrillOrigin( aView, aFrame, originViewItem, aPosition );
|
2018-01-24 10:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-18 15:51:51 +00:00
|
|
|
int PCB_EDITOR_CONTROL::DrillOrigin( 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 );
|
|
|
|
|
2017-06-12 13:10:43 +00:00
|
|
|
m_frame->SetToolID( ID_PCB_PLACE_OFFSET_COORD_BUTT, wxCURSOR_HAND, _( "Adjust zero" ) );
|
2018-01-24 10:19:33 +00:00
|
|
|
picker->SetClickHandler( std::bind( SetDrillOrigin, getView(), m_frame, m_placeOrigin.get(), _1 ) );
|
2015-06-18 15:51:51 +00:00
|
|
|
picker->Activate();
|
2015-07-24 08:58:47 +00:00
|
|
|
Wait();
|
2015-06-18 15:51:51 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-18 15:51:50 +00:00
|
|
|
/**
|
|
|
|
* Function highlightNet()
|
|
|
|
* Looks for a BOARD_CONNECTED_ITEM in a given spot, and if one is found - it enables
|
|
|
|
* highlight for its net.
|
2017-07-08 19:13:32 +00:00
|
|
|
* @param aToolMgr is the TOOL_MANAGER currently in use.
|
2017-06-22 07:01:29 +00:00
|
|
|
* @param aPosition is the point where an item is expected (world coordinates).
|
2018-03-27 03:09:38 +00:00
|
|
|
* @param aUseSelection is true if we should use the current selection to pick the netcode
|
2015-06-18 15:51:50 +00:00
|
|
|
*/
|
2018-03-27 03:09:38 +00:00
|
|
|
static bool highlightNet( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition,
|
|
|
|
bool aUseSelection = false )
|
2015-06-18 15:51:50 +00:00
|
|
|
{
|
2017-03-02 13:43:11 +00:00
|
|
|
auto render = aToolMgr->GetView()->GetPainter()->GetSettings();
|
|
|
|
auto frame = static_cast<PCB_EDIT_FRAME*>( aToolMgr->GetEditFrame() );
|
2018-03-27 03:09:38 +00:00
|
|
|
|
2015-06-18 15:51:50 +00:00
|
|
|
BOARD* board = static_cast<BOARD*>( aToolMgr->GetModel() );
|
|
|
|
|
2018-03-27 03:09:38 +00:00
|
|
|
int net = -1;
|
|
|
|
bool enableHighlight = false;
|
2017-03-02 13:43:11 +00:00
|
|
|
|
2018-03-27 03:09:38 +00:00
|
|
|
if( aUseSelection )
|
2017-03-02 13:43:11 +00:00
|
|
|
{
|
2018-03-27 03:09:38 +00:00
|
|
|
auto selectionTool = aToolMgr->GetTool<SELECTION_TOOL>();
|
|
|
|
|
|
|
|
const SELECTION& selection = selectionTool->GetSelection();
|
|
|
|
|
|
|
|
for( auto item : selection )
|
2017-03-02 13:43:11 +00:00
|
|
|
{
|
2018-03-27 03:09:38 +00:00
|
|
|
if( BOARD_CONNECTED_ITEM::ClassOf( item ) )
|
|
|
|
{
|
|
|
|
auto ci = static_cast<BOARD_CONNECTED_ITEM*>( item );
|
|
|
|
|
|
|
|
int item_net = ci->GetNetCode();
|
|
|
|
|
|
|
|
if( net < 0 )
|
|
|
|
{
|
|
|
|
net = item_net;
|
|
|
|
}
|
|
|
|
else if( net != item_net )
|
|
|
|
{
|
|
|
|
// more than one net selected: do nothing
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2017-03-02 13:43:11 +00:00
|
|
|
}
|
2018-03-27 03:09:38 +00:00
|
|
|
|
|
|
|
enableHighlight = ( net >= 0 && net != render->GetHighlightNetCode() );
|
2017-03-02 13:43:11 +00:00
|
|
|
}
|
|
|
|
|
2018-03-27 03:09:38 +00:00
|
|
|
// If we didn't get a net to highlight from the selection, use the cursor
|
|
|
|
if( net < 0 )
|
|
|
|
{
|
|
|
|
auto guide = frame->GetCollectorsGuide();
|
|
|
|
GENERAL_COLLECTOR collector;
|
|
|
|
|
|
|
|
// Find a connected item for which we are going to highlight a net
|
|
|
|
collector.Collect( board, GENERAL_COLLECTOR::PadsTracksOrZones,
|
|
|
|
wxPoint( aPosition.x, aPosition.y ), guide );
|
|
|
|
|
|
|
|
for( int i = 0; i < collector.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
if( collector[i]->Type() == PCB_PAD_T )
|
|
|
|
{
|
|
|
|
frame->SendMessageToEESCHEMA( static_cast<BOARD_CONNECTED_ITEM*>( collector[i] ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enableHighlight = ( collector.GetCount() > 0 );
|
2015-06-18 15:51:50 +00:00
|
|
|
|
2018-03-27 03:09:38 +00:00
|
|
|
// Obtain net code for the clicked item
|
|
|
|
if( enableHighlight )
|
|
|
|
net = static_cast<BOARD_CONNECTED_ITEM*>( collector[0] )->GetNetCode();
|
|
|
|
}
|
2015-06-18 15:51:50 +00:00
|
|
|
|
2015-09-03 15:56:30 +00:00
|
|
|
// Toggle highlight when the same net was picked
|
|
|
|
if( net > 0 && net == render->GetHighlightNetCode() )
|
|
|
|
enableHighlight = !render->IsHighlightEnabled();
|
|
|
|
|
|
|
|
if( enableHighlight != render->IsHighlightEnabled() || net != render->GetHighlightNetCode() )
|
2015-06-18 15:51:50 +00:00
|
|
|
{
|
|
|
|
render->SetHighlight( enableHighlight, net );
|
|
|
|
aToolMgr->GetView()->UpdateAllLayersColor();
|
|
|
|
}
|
|
|
|
|
2016-10-14 19:07:04 +00:00
|
|
|
// Store the highlighted netcode in the current board (for dialogs for instance)
|
|
|
|
if( enableHighlight && net >= 0 )
|
2017-11-28 02:07:59 +00:00
|
|
|
{
|
2016-10-14 19:07:04 +00:00
|
|
|
board->SetHighLightNet( net );
|
2017-11-28 02:07:59 +00:00
|
|
|
|
|
|
|
NETINFO_ITEM* netinfo = board->FindNet( net );
|
|
|
|
|
|
|
|
if( netinfo )
|
|
|
|
{
|
|
|
|
MSG_PANEL_ITEMS items;
|
2018-04-10 10:52:12 +00:00
|
|
|
netinfo->GetMsgPanelInfo( frame->GetUserUnits(), items );
|
2017-11-28 02:07:59 +00:00
|
|
|
frame->SetMsgPanel( items );
|
2018-01-06 20:50:49 +00:00
|
|
|
frame->SendCrossProbeNetName( netinfo->GetNetname() );
|
2017-11-28 02:07:59 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-14 19:07:04 +00:00
|
|
|
else
|
2017-11-28 02:07:59 +00:00
|
|
|
{
|
2016-10-14 19:07:04 +00:00
|
|
|
board->ResetHighLight();
|
2017-11-28 02:07:59 +00:00
|
|
|
frame->SetMsgPanel( board );
|
2018-01-06 20:50:49 +00:00
|
|
|
frame->SendCrossProbeNetName( "" );
|
2017-11-28 02:07:59 +00:00
|
|
|
}
|
2016-10-14 19:07:04 +00:00
|
|
|
|
2015-06-18 15:51:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PCB_EDITOR_CONTROL::HighlightNet( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2016-09-21 19:22:19 +00:00
|
|
|
int netcode = aEvent.Parameter<intptr_t>();
|
2016-01-25 15:16:05 +00:00
|
|
|
|
|
|
|
if( netcode > 0 )
|
|
|
|
{
|
|
|
|
KIGFX::RENDER_SETTINGS* render = m_toolMgr->GetView()->GetPainter()->GetSettings();
|
|
|
|
render->SetHighlight( true, netcode );
|
|
|
|
m_toolMgr->GetView()->UpdateAllLayersColor();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No net code specified, pick the net code belonging to the item under the cursor
|
2017-06-12 13:27:10 +00:00
|
|
|
highlightNet( m_toolMgr, getViewControls()->GetMousePosition() );
|
2016-01-25 15:16:05 +00:00
|
|
|
}
|
2015-06-18 15:51:50 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-18 15:51:51 +00:00
|
|
|
int PCB_EDITOR_CONTROL::HighlightNetCursor( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2018-03-27 03:09:38 +00:00
|
|
|
// If the keyboard hotkey was triggered, the behavior is as follows:
|
|
|
|
// If we are already in the highlight tool, behave the same as a left click.
|
|
|
|
// If we are not, highlight the net of the selected item(s), or if there is
|
|
|
|
// no selection, then behave like a Ctrl+Left Click.
|
|
|
|
if( aEvent.IsAction( &PCB_ACTIONS::highlightNetSelection ) )
|
|
|
|
{
|
|
|
|
bool use_selection = ( m_frame->GetToolId() != ID_PCB_HIGHLIGHT_BUTT );
|
|
|
|
highlightNet( m_toolMgr, getViewControls()->GetMousePosition(),
|
|
|
|
use_selection );
|
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
|
2017-06-12 13:10:43 +00:00
|
|
|
m_frame->SetToolID( ID_PCB_HIGHLIGHT_BUTT, wxCURSOR_HAND, _( "Highlight net" ) );
|
2018-03-27 03:09:38 +00:00
|
|
|
picker->SetClickHandler( std::bind( highlightNet, m_toolMgr, _1, false ) );
|
2015-07-24 08:58:47 +00:00
|
|
|
picker->SetSnapping( false );
|
2015-06-18 15:51:51 +00:00
|
|
|
picker->Activate();
|
2015-07-24 08:58:47 +00:00
|
|
|
Wait();
|
2015-06-18 15:51:51 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
|
2018-06-19 05:14:21 +00:00
|
|
|
static bool showLocalRatsnest( TOOL_MANAGER* aToolMgr, BOARD* aBoard, const VECTOR2D& aPosition )
|
2017-03-22 13:43:10 +00:00
|
|
|
{
|
2017-03-28 16:30:49 +00:00
|
|
|
auto selectionTool = aToolMgr->GetTool<SELECTION_TOOL>();
|
2018-06-19 05:14:21 +00:00
|
|
|
auto modules = aBoard->Modules();
|
2017-03-28 16:30:49 +00:00
|
|
|
|
|
|
|
aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
2018-01-05 23:44:37 +00:00
|
|
|
aToolMgr->RunAction( PCB_ACTIONS::selectionCursor, true, EDIT_TOOL::FootprintFilter );
|
2017-03-28 16:30:49 +00:00
|
|
|
|
|
|
|
const SELECTION& selection = selectionTool->GetSelection();
|
|
|
|
|
|
|
|
if( selection.Empty() )
|
2018-06-19 05:14:21 +00:00
|
|
|
{
|
|
|
|
// Clear the previous local ratsnest if we click off all items
|
|
|
|
for( auto mod : modules )
|
|
|
|
{
|
|
|
|
for( auto pad : mod->Pads() )
|
|
|
|
{
|
|
|
|
pad->SetLocalRatsnestVisible( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-28 16:30:49 +00:00
|
|
|
return true;
|
2018-06-19 05:14:21 +00:00
|
|
|
}
|
2017-03-28 16:30:49 +00:00
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
for( auto item : selection )
|
2017-03-28 16:30:49 +00:00
|
|
|
{
|
2017-06-23 11:56:28 +00:00
|
|
|
if( item->Type() == PCB_MODULE_T )
|
2017-03-28 16:30:49 +00:00
|
|
|
{
|
2017-06-23 11:56:28 +00:00
|
|
|
for( auto pad : static_cast<MODULE *> (item)->Pads() )
|
2017-03-28 16:30:49 +00:00
|
|
|
{
|
2018-06-19 05:14:21 +00:00
|
|
|
pad->SetLocalRatsnestVisible( !pad->GetLocalRatsnestVisible() );
|
2017-03-28 16:30:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-22 13:43:10 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
|
2017-03-22 13:43:10 +00:00
|
|
|
int PCB_EDITOR_CONTROL::ShowLocalRatsnest( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
Activate();
|
|
|
|
|
|
|
|
auto picker = m_toolMgr->GetTool<PICKER_TOOL>();
|
2018-06-19 05:14:21 +00:00
|
|
|
auto board = getModel<BOARD>();
|
|
|
|
wxASSERT( picker );
|
|
|
|
wxASSERT( board );
|
2017-03-22 13:43:10 +00:00
|
|
|
|
|
|
|
m_frame->SetToolID( ID_PCB_SHOW_1_RATSNEST_BUTT, wxCURSOR_PENCIL, _( "Pick Components for Local Ratsnest" ) );
|
2018-06-19 05:14:21 +00:00
|
|
|
picker->SetClickHandler( std::bind( showLocalRatsnest, m_toolMgr, board, _1 ) );
|
2017-03-22 13:43:10 +00:00
|
|
|
picker->SetSnapping( false );
|
|
|
|
picker->Activate();
|
|
|
|
Wait();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-06-18 15:51:51 +00:00
|
|
|
|
2017-06-23 11:56:28 +00:00
|
|
|
|
2017-04-20 12:43:42 +00:00
|
|
|
int PCB_EDITOR_CONTROL::UpdateSelectionRatsnest( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2017-08-01 11:11:07 +00:00
|
|
|
auto selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
|
|
|
auto& selection = selectionTool->GetSelection();
|
2017-08-01 13:20:40 +00:00
|
|
|
auto connectivity = getModel<BOARD>()->GetConnectivity();
|
2017-08-01 11:11:07 +00:00
|
|
|
|
|
|
|
if( selection.Empty() )
|
|
|
|
{
|
2017-08-01 13:20:40 +00:00
|
|
|
connectivity->ClearDynamicRatsnest();
|
|
|
|
}
|
|
|
|
else if( m_slowRatsnest )
|
|
|
|
{
|
|
|
|
// Compute ratsnest only when user stops dragging for a moment
|
|
|
|
connectivity->HideDynamicRatsnest();
|
2017-08-01 15:57:18 +00:00
|
|
|
m_ratsnestTimer.Start( 20 );
|
2017-08-01 11:11:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-01 13:20:40 +00:00
|
|
|
// Check how much time doest it take to calculate ratsnest
|
|
|
|
PROF_COUNTER counter;
|
|
|
|
calculateSelectionRatsnest();
|
|
|
|
counter.Stop();
|
|
|
|
|
|
|
|
// If it is too slow, then switch to 'slow ratsnest' mode when
|
|
|
|
// ratsnest is calculated when user stops dragging items for a moment
|
2017-08-01 15:57:18 +00:00
|
|
|
if( counter.msecs() > 25 )
|
2017-08-01 13:20:40 +00:00
|
|
|
{
|
|
|
|
m_slowRatsnest = true;
|
|
|
|
connectivity->HideDynamicRatsnest();
|
|
|
|
}
|
2017-08-01 11:11:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int PCB_EDITOR_CONTROL::HideSelectionRatsnest( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
getModel<BOARD>()->GetConnectivity()->ClearDynamicRatsnest();
|
2017-08-01 13:20:40 +00:00
|
|
|
m_slowRatsnest = false;
|
2017-04-24 20:26:11 +00:00
|
|
|
return 0;
|
2017-04-20 12:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-01 13:20:40 +00:00
|
|
|
void PCB_EDITOR_CONTROL::ratsnestTimer( wxTimerEvent& aEvent )
|
|
|
|
{
|
|
|
|
m_ratsnestTimer.Stop();
|
|
|
|
calculateSelectionRatsnest();
|
|
|
|
static_cast<PCB_DRAW_PANEL_GAL*>( m_frame->GetGalCanvas() )->RedrawRatsnest();
|
|
|
|
m_frame->GetGalCanvas()->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_EDITOR_CONTROL::calculateSelectionRatsnest()
|
|
|
|
{
|
|
|
|
auto selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
|
|
|
|
auto& selection = selectionTool->GetSelection();
|
2017-09-28 16:38:54 +00:00
|
|
|
auto connectivity = board()->GetConnectivity();
|
|
|
|
|
2017-08-01 13:20:40 +00:00
|
|
|
std::vector<BOARD_ITEM*> items;
|
|
|
|
items.reserve( selection.Size() );
|
|
|
|
|
|
|
|
for( auto item : selection )
|
|
|
|
items.push_back( static_cast<BOARD_ITEM*>( item ) );
|
|
|
|
|
|
|
|
connectivity->ComputeDynamicRatsnest( items );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-31 12:30:51 +00:00
|
|
|
void PCB_EDITOR_CONTROL::setTransitions()
|
2014-07-09 11:50:27 +00:00
|
|
|
{
|
|
|
|
// Track & via size control
|
2017-02-21 12:42:08 +00:00
|
|
|
Go( &PCB_EDITOR_CONTROL::TrackWidthInc, PCB_ACTIONS::trackWidthInc.MakeEvent() );
|
|
|
|
Go( &PCB_EDITOR_CONTROL::TrackWidthDec, PCB_ACTIONS::trackWidthDec.MakeEvent() );
|
|
|
|
Go( &PCB_EDITOR_CONTROL::ViaSizeInc, PCB_ACTIONS::viaSizeInc.MakeEvent() );
|
|
|
|
Go( &PCB_EDITOR_CONTROL::ViaSizeDec, PCB_ACTIONS::viaSizeDec.MakeEvent() );
|
2014-07-09 14:57:01 +00:00
|
|
|
|
|
|
|
// Zone actions
|
2017-02-21 12:42:08 +00:00
|
|
|
Go( &PCB_EDITOR_CONTROL::ZoneMerge, PCB_ACTIONS::zoneMerge.MakeEvent() );
|
|
|
|
Go( &PCB_EDITOR_CONTROL::ZoneDuplicate, PCB_ACTIONS::zoneDuplicate.MakeEvent() );
|
2015-02-14 20:52:22 +00:00
|
|
|
|
2015-03-10 15:58:26 +00:00
|
|
|
// Placing tools
|
2017-02-21 12:42:08 +00:00
|
|
|
Go( &PCB_EDITOR_CONTROL::PlaceTarget, PCB_ACTIONS::placeTarget.MakeEvent() );
|
|
|
|
Go( &PCB_EDITOR_CONTROL::PlaceModule, PCB_ACTIONS::placeModule.MakeEvent() );
|
2015-03-10 15:58:26 +00:00
|
|
|
|
2015-06-18 15:51:50 +00:00
|
|
|
// Other
|
2017-02-21 12:42:08 +00:00
|
|
|
Go( &PCB_EDITOR_CONTROL::ToggleLockSelected, PCB_ACTIONS::toggleLock.MakeEvent() );
|
|
|
|
Go( &PCB_EDITOR_CONTROL::LockSelected, PCB_ACTIONS::lock.MakeEvent() );
|
|
|
|
Go( &PCB_EDITOR_CONTROL::UnlockSelected, PCB_ACTIONS::unlock.MakeEvent() );
|
2015-09-03 15:35:41 +00:00
|
|
|
Go( &PCB_EDITOR_CONTROL::CrossProbePcbToSch, SELECTION_TOOL::SelectedEvent );
|
2017-02-21 12:42:08 +00:00
|
|
|
Go( &PCB_EDITOR_CONTROL::CrossProbeSchToPcb, PCB_ACTIONS::crossProbeSchToPcb.MakeEvent() );
|
|
|
|
Go( &PCB_EDITOR_CONTROL::DrillOrigin, PCB_ACTIONS::drillOrigin.MakeEvent() );
|
|
|
|
Go( &PCB_EDITOR_CONTROL::HighlightNet, PCB_ACTIONS::highlightNet.MakeEvent() );
|
|
|
|
Go( &PCB_EDITOR_CONTROL::HighlightNetCursor, PCB_ACTIONS::highlightNetCursor.MakeEvent() );
|
2018-03-27 03:09:38 +00:00
|
|
|
Go( &PCB_EDITOR_CONTROL::HighlightNetCursor, PCB_ACTIONS::highlightNetSelection.MakeEvent() );
|
2017-06-23 11:56:28 +00:00
|
|
|
Go( &PCB_EDITOR_CONTROL::ShowLocalRatsnest, PCB_ACTIONS::showLocalRatsnest.MakeEvent() );
|
2017-04-20 12:43:42 +00:00
|
|
|
Go( &PCB_EDITOR_CONTROL::UpdateSelectionRatsnest, PCB_ACTIONS::selectionModified.MakeEvent() );
|
2017-08-01 11:11:07 +00:00
|
|
|
Go( &PCB_EDITOR_CONTROL::HideSelectionRatsnest, SELECTION_TOOL::ClearedEvent );
|
2014-07-09 11:50:27 +00:00
|
|
|
}
|
2015-03-10 15:58:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
const int PCB_EDITOR_CONTROL::WIDTH_STEP = 100000;
|