2019-06-03 20:06:58 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-07-27 19:41:50 +00:00
|
|
|
* Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.TXT for contributors.
|
2019-06-03 20:06:58 +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 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
|
|
|
|
*/
|
|
|
|
|
2021-06-03 18:05:43 +00:00
|
|
|
#include <footprint.h>
|
2021-06-11 21:07:02 +00:00
|
|
|
#include <pcb_track.h>
|
2021-06-03 18:05:43 +00:00
|
|
|
#include <zone.h>
|
2024-02-24 15:10:50 +00:00
|
|
|
#include <zones.h>
|
2019-06-03 20:06:58 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tools/pcb_actions.h>
|
|
|
|
#include <tools/edit_tool.h>
|
|
|
|
#include <dialogs/dialog_exchange_footprints.h>
|
2020-06-17 12:46:50 +00:00
|
|
|
#include <dialogs/dialog_cleanup_tracks_and_vias.h>
|
2019-06-03 20:06:58 +00:00
|
|
|
#include <dialogs/dialog_swap_layers.h>
|
2020-07-27 19:41:50 +00:00
|
|
|
#include <dialogs/dialog_unused_pad_layers.h>
|
2019-06-03 20:06:58 +00:00
|
|
|
#include <tools/global_edit_tool.h>
|
|
|
|
#include <board_commit.h>
|
2020-06-17 12:46:50 +00:00
|
|
|
#include <dialogs/dialog_cleanup_graphics.h>
|
2024-02-24 15:10:50 +00:00
|
|
|
#include <tools/pcb_actions.h>
|
|
|
|
#include <board_design_settings.h>
|
|
|
|
|
2019-06-03 20:06:58 +00:00
|
|
|
|
|
|
|
GLOBAL_EDIT_TOOL::GLOBAL_EDIT_TOOL() :
|
2020-01-13 19:39:49 +00:00
|
|
|
PCB_TOOL_BASE( "pcbnew.GlobalEdit" ),
|
|
|
|
m_selectionTool( nullptr )
|
2019-06-03 20:06:58 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GLOBAL_EDIT_TOOL::Reset( RESET_REASON aReason )
|
|
|
|
{
|
|
|
|
if( aReason != RUN )
|
2019-12-05 13:43:55 +00:00
|
|
|
m_commit = std::make_unique<BOARD_COMMIT>( this );
|
2019-06-03 20:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GLOBAL_EDIT_TOOL::Init()
|
|
|
|
{
|
|
|
|
// Find the selection tool, so they can cooperate
|
2020-12-16 13:31:32 +00:00
|
|
|
m_selectionTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
|
2019-06-03 20:06:58 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int GLOBAL_EDIT_TOOL::ExchangeFootprints( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2020-12-16 13:31:32 +00:00
|
|
|
PCB_SELECTION& selection = m_selectionTool->GetSelection();
|
|
|
|
FOOTPRINT* footprint = nullptr;
|
|
|
|
bool updateMode = false;
|
|
|
|
bool currentMode = false;
|
2019-06-03 20:06:58 +00:00
|
|
|
|
2020-08-05 22:39:54 +00:00
|
|
|
if( aEvent.HasPosition() )
|
|
|
|
selection = m_selectionTool->RequestSelection( EDIT_TOOL::FootprintFilter );
|
|
|
|
|
|
|
|
if( !selection.Empty() )
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint = selection.FirstOfKind<FOOTPRINT>();
|
2020-08-05 22:39:54 +00:00
|
|
|
|
2019-06-03 20:06:58 +00:00
|
|
|
if( aEvent.IsAction( &PCB_ACTIONS::updateFootprint ) )
|
|
|
|
{
|
|
|
|
updateMode = true;
|
|
|
|
currentMode = true;
|
|
|
|
}
|
|
|
|
else if( aEvent.IsAction( &PCB_ACTIONS::updateFootprints ) )
|
|
|
|
{
|
|
|
|
updateMode = true;
|
2023-09-11 20:16:47 +00:00
|
|
|
currentMode = selection.CountType( PCB_FOOTPRINT_T ) > 0;
|
2019-06-03 20:06:58 +00:00
|
|
|
}
|
|
|
|
else if( aEvent.IsAction( &PCB_ACTIONS::changeFootprint ) )
|
|
|
|
{
|
|
|
|
updateMode = false;
|
|
|
|
currentMode = true;
|
|
|
|
}
|
|
|
|
else if( aEvent.IsAction( &PCB_ACTIONS::changeFootprints ) )
|
|
|
|
{
|
|
|
|
updateMode = false;
|
2023-09-11 20:16:47 +00:00
|
|
|
currentMode = selection.CountType( PCB_FOOTPRINT_T ) > 0;
|
2019-06-03 20:06:58 +00:00
|
|
|
}
|
|
|
|
else
|
2021-09-13 16:18:58 +00:00
|
|
|
{
|
2022-02-05 13:25:43 +00:00
|
|
|
wxFAIL_MSG( wxT( "ExchangeFootprints: unexpected action" ) );
|
2021-09-13 16:18:58 +00:00
|
|
|
}
|
2019-06-03 20:06:58 +00:00
|
|
|
|
|
|
|
// invoke the exchange dialog process
|
|
|
|
{
|
2019-06-09 23:21:50 +00:00
|
|
|
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
|
2020-11-08 21:29:04 +00:00
|
|
|
DIALOG_EXCHANGE_FOOTPRINTS dialog( editFrame, footprint, updateMode, currentMode );
|
2019-06-03 20:06:58 +00:00
|
|
|
dialog.ShowQuasiModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-03-12 23:32:40 +00:00
|
|
|
bool GLOBAL_EDIT_TOOL::swapBoardItem( BOARD_ITEM* aItem,
|
|
|
|
std::map<PCB_LAYER_ID, PCB_LAYER_ID>& aLayerMap )
|
2019-06-03 20:06:58 +00:00
|
|
|
{
|
2024-03-12 23:32:40 +00:00
|
|
|
PCB_LAYER_ID original = aItem->GetLayer();
|
|
|
|
|
|
|
|
if( aLayerMap.count( original ) && aLayerMap.at( original ) != original )
|
2019-06-03 20:06:58 +00:00
|
|
|
{
|
|
|
|
m_commit->Modify( aItem );
|
2024-03-12 23:32:40 +00:00
|
|
|
aItem->SetLayer( aLayerMap.at( original ) );
|
2019-06-13 17:28:55 +00:00
|
|
|
frame()->GetCanvas()->GetView()->Update( aItem, KIGFX::GEOMETRY );
|
2019-06-03 20:06:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int GLOBAL_EDIT_TOOL::SwapLayers( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2024-03-12 23:32:40 +00:00
|
|
|
std::map<PCB_LAYER_ID, PCB_LAYER_ID> layerMap;
|
2019-06-03 20:06:58 +00:00
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
DIALOG_SWAP_LAYERS dlg( frame(), layerMap );
|
2019-06-03 20:06:58 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bool hasChanges = false;
|
|
|
|
|
|
|
|
// Change tracks.
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* segm : frame()->GetBoard()->Tracks() )
|
2019-06-03 20:06:58 +00:00
|
|
|
{
|
|
|
|
if( segm->Type() == PCB_VIA_T )
|
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
PCB_VIA* via = static_cast<PCB_VIA*>( segm );
|
2019-06-03 20:06:58 +00:00
|
|
|
PCB_LAYER_ID top_layer, bottom_layer;
|
|
|
|
|
2019-12-28 00:55:11 +00:00
|
|
|
if( via->GetViaType() == VIATYPE::THROUGH )
|
2019-06-03 20:06:58 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
via->LayerPair( &top_layer, &bottom_layer );
|
|
|
|
|
2020-11-08 21:29:04 +00:00
|
|
|
if( layerMap[bottom_layer] != bottom_layer || layerMap[top_layer] != top_layer )
|
2019-06-03 20:06:58 +00:00
|
|
|
{
|
|
|
|
m_commit->Modify( via );
|
2020-11-08 21:29:04 +00:00
|
|
|
via->SetLayerPair( layerMap[top_layer], layerMap[bottom_layer] );
|
2019-06-13 17:28:55 +00:00
|
|
|
frame()->GetCanvas()->GetView()->Update( via, KIGFX::GEOMETRY );
|
2019-06-03 20:06:58 +00:00
|
|
|
hasChanges = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-08 21:29:04 +00:00
|
|
|
hasChanges |= swapBoardItem( segm, layerMap );
|
2019-06-03 20:06:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( BOARD_ITEM* zone : frame()->GetBoard()->Zones() )
|
2020-11-08 21:29:04 +00:00
|
|
|
hasChanges |= swapBoardItem( zone, layerMap );
|
2019-06-03 20:06:58 +00:00
|
|
|
|
|
|
|
for( BOARD_ITEM* drawing : frame()->GetBoard()->Drawings() )
|
2020-11-08 21:29:04 +00:00
|
|
|
hasChanges |= swapBoardItem( drawing, layerMap );
|
2019-06-03 20:06:58 +00:00
|
|
|
|
|
|
|
if( hasChanges )
|
|
|
|
{
|
|
|
|
frame()->OnModify();
|
2023-07-15 16:37:17 +00:00
|
|
|
m_commit->Push( wxT( "Swap Layers" ) );
|
2019-06-13 17:28:55 +00:00
|
|
|
frame()->GetCanvas()->Refresh();
|
2019-06-03 20:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-17 12:46:50 +00:00
|
|
|
int GLOBAL_EDIT_TOOL::CleanupTracksAndVias( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
|
|
|
|
DIALOG_CLEANUP_TRACKS_AND_VIAS dlg( editFrame );
|
|
|
|
|
|
|
|
dlg.ShowModal();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int GLOBAL_EDIT_TOOL::CleanupGraphics( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
|
|
|
|
DIALOG_CLEANUP_GRAPHICS dlg( editFrame, false );
|
|
|
|
|
|
|
|
dlg.ShowModal();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-27 19:41:50 +00:00
|
|
|
int GLOBAL_EDIT_TOOL::RemoveUnusedPads( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
|
2020-12-16 13:31:32 +00:00
|
|
|
PCB_SELECTION& selection = m_selectionTool->RequestSelection(
|
|
|
|
[]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
|
2020-07-27 19:41:50 +00:00
|
|
|
{
|
2021-04-28 22:53:31 +00:00
|
|
|
sTool->FilterCollectorForHierarchy( aCollector, true );
|
2020-07-27 19:41:50 +00:00
|
|
|
} );
|
|
|
|
DIALOG_UNUSED_PAD_LAYERS dlg( editFrame, selection, *m_commit );
|
|
|
|
|
|
|
|
dlg.ShowModal();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-02-24 15:10:50 +00:00
|
|
|
int GLOBAL_EDIT_TOOL::ZonesManager( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
PCB_EDIT_FRAME* editFrame = getEditFrame<PCB_EDIT_FRAME>();
|
|
|
|
|
|
|
|
BOARD_COMMIT commit( editFrame );
|
|
|
|
BOARD* board = editFrame->GetBoard();
|
|
|
|
|
|
|
|
for( ZONE* zone : board->Zones() )
|
|
|
|
commit.Modify( zone );
|
|
|
|
|
|
|
|
ZONE_SETTINGS zoneInfo = board->GetDesignSettings().GetDefaultZoneSettings();
|
|
|
|
int dialogResult = InvokeZonesManager( editFrame, &zoneInfo );
|
|
|
|
|
|
|
|
if( dialogResult == wxID_CANCEL )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
wxBusyCursor dummy;
|
|
|
|
|
|
|
|
// Undraw old zone outlines
|
|
|
|
for( ZONE* zone : board->Zones() )
|
|
|
|
editFrame->GetCanvas()->GetView()->Update( zone );
|
|
|
|
|
|
|
|
|
|
|
|
board->GetDesignSettings().SetDefaultZoneSettings( zoneInfo );
|
|
|
|
commit.Push( _( "Modify zones properties with zone manager" ), SKIP_CONNECTIVITY );
|
|
|
|
editFrame->OnModify();
|
|
|
|
|
|
|
|
//rebuildConnectivity
|
|
|
|
board->BuildConnectivity();
|
|
|
|
|
|
|
|
if( TOOL_MANAGER* manger = GetManager() )
|
|
|
|
{
|
|
|
|
manger->PostEvent( EVENTS::ConnectivityChangedEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
editFrame->GetCanvas()->RedrawRatsnest();
|
|
|
|
|
|
|
|
if( dialogResult == ZONE_MANAGER_REPOUR )
|
|
|
|
{
|
|
|
|
if( TOOL_MANAGER* manger = GetManager() )
|
|
|
|
{
|
|
|
|
manger->PostAction( PCB_ACTIONS::zoneFillAll );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-27 19:41:50 +00:00
|
|
|
|
2019-06-03 20:06:58 +00:00
|
|
|
void GLOBAL_EDIT_TOOL::setTransitions()
|
|
|
|
{
|
|
|
|
Go( &GLOBAL_EDIT_TOOL::ExchangeFootprints, PCB_ACTIONS::updateFootprint.MakeEvent() );
|
|
|
|
Go( &GLOBAL_EDIT_TOOL::ExchangeFootprints, PCB_ACTIONS::updateFootprints.MakeEvent() );
|
|
|
|
Go( &GLOBAL_EDIT_TOOL::ExchangeFootprints, PCB_ACTIONS::changeFootprint.MakeEvent() );
|
|
|
|
Go( &GLOBAL_EDIT_TOOL::ExchangeFootprints, PCB_ACTIONS::changeFootprints.MakeEvent() );
|
|
|
|
|
|
|
|
Go( &GLOBAL_EDIT_TOOL::SwapLayers, PCB_ACTIONS::swapLayers.MakeEvent() );
|
|
|
|
|
|
|
|
Go( &GLOBAL_EDIT_TOOL::EditTracksAndVias, PCB_ACTIONS::editTracksAndVias.MakeEvent() );
|
|
|
|
Go( &GLOBAL_EDIT_TOOL::EditTextAndGraphics, PCB_ACTIONS::editTextAndGraphics.MakeEvent() );
|
2023-05-12 21:03:54 +00:00
|
|
|
Go( &GLOBAL_EDIT_TOOL::EditTeardrops, PCB_ACTIONS::editTeardrops.MakeEvent() );
|
2019-06-03 20:06:58 +00:00
|
|
|
Go( &GLOBAL_EDIT_TOOL::GlobalDeletions, PCB_ACTIONS::globalDeletions.MakeEvent() );
|
|
|
|
Go( &GLOBAL_EDIT_TOOL::CleanupTracksAndVias, PCB_ACTIONS::cleanupTracksAndVias.MakeEvent() );
|
2020-06-17 12:46:50 +00:00
|
|
|
Go( &GLOBAL_EDIT_TOOL::CleanupGraphics, PCB_ACTIONS::cleanupGraphics.MakeEvent() );
|
2020-07-27 19:41:50 +00:00
|
|
|
Go( &GLOBAL_EDIT_TOOL::RemoveUnusedPads, PCB_ACTIONS::removeUnusedPads.MakeEvent() );
|
2024-02-24 15:10:50 +00:00
|
|
|
Go( &GLOBAL_EDIT_TOOL::ZonesManager, PCB_ACTIONS::zonesManager.MakeEvent() );
|
2019-06-03 20:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|