2019-04-14 00:44:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-08-14 08:28:07 +00:00
|
|
|
* Copyright (C) 2019 CERN
|
2021-01-17 08:41:49 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-04-14 00:44:05 +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
|
|
|
|
*/
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <class_library.h>
|
|
|
|
#include <confirm.h>
|
2020-08-31 13:19:57 +00:00
|
|
|
#include <widgets/infobar.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <connection_graph.h>
|
|
|
|
#include <dialogs/dialog_fields_editor_global.h>
|
2020-12-19 15:08:31 +00:00
|
|
|
#include <dialogs/dialog_eeschema_page_settings.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <dialogs/dialog_paste_special.h>
|
2020-05-12 17:12:38 +00:00
|
|
|
#include <dialogs/dialog_plot_schematic.h>
|
|
|
|
#include <dialogs/dialog_symbol_remap.h>
|
|
|
|
#include <project_rescue.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <erc.h>
|
|
|
|
#include <invoke_sch_dialog.h>
|
2020-10-15 22:48:53 +00:00
|
|
|
#include <kicad_string.h>
|
2019-04-23 17:12:26 +00:00
|
|
|
#include <kiway.h>
|
2021-03-18 13:28:04 +00:00
|
|
|
#include <kiway_player.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <netlist_exporters/netlist_exporter_pspice.h>
|
2020-07-07 10:17:30 +00:00
|
|
|
#include <project/project_file.h>
|
|
|
|
#include <project/net_settings.h>
|
2019-04-14 00:44:05 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2020-10-05 18:38:40 +00:00
|
|
|
#include <sch_plugins/kicad/sch_sexpr_plugin.h>
|
2019-08-12 14:42:11 +00:00
|
|
|
#include <sch_line.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <sch_painter.h>
|
|
|
|
#include <sch_sheet.h>
|
2021-04-06 21:15:49 +00:00
|
|
|
#include <sch_sheet_pin.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <sch_view.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <advanced_config.h>
|
|
|
|
#include <sim/sim_plot_frame.h>
|
2020-12-25 23:37:01 +00:00
|
|
|
#include <symbol_viewer_frame.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <status_popup.h>
|
2019-07-15 23:44:01 +00:00
|
|
|
#include <tool/picker_tool.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2019-05-10 17:19:48 +00:00
|
|
|
#include <tools/ee_actions.h>
|
2019-06-09 21:57:23 +00:00
|
|
|
#include <tools/ee_selection.h>
|
2019-05-10 17:19:48 +00:00
|
|
|
#include <tools/ee_selection_tool.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <tools/sch_editor_control.h>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_proxy_undo_item.h>
|
2020-01-29 16:33:57 +00:00
|
|
|
#include <dialog_update_from_pcb.h>
|
2020-07-07 10:17:30 +00:00
|
|
|
#include <dialog_helpers.h>
|
2020-05-12 17:12:38 +00:00
|
|
|
|
2020-08-31 15:06:23 +00:00
|
|
|
|
2019-05-24 23:36:31 +00:00
|
|
|
int SCH_EDITOR_CONTROL::New( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_frame->NewProject();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::Open( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_frame->LoadProject();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::Save( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-08-28 03:19:20 +00:00
|
|
|
m_frame->SaveProject();
|
2019-05-24 23:36:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::SaveAs( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_frame->Save_File( true );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-10 18:46:57 +00:00
|
|
|
int SCH_EDITOR_CONTROL::ShowSchematicSetup( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2020-05-24 14:54:26 +00:00
|
|
|
m_frame->ShowSchematicSetupDialog();
|
2020-03-10 18:46:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-24 23:36:31 +00:00
|
|
|
int SCH_EDITOR_CONTROL::PageSetup( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-05-26 15:36:40 +00:00
|
|
|
PICKED_ITEMS_LIST undoCmd;
|
2021-02-22 23:47:17 +00:00
|
|
|
DS_PROXY_UNDO_ITEM* undoItem = new DS_PROXY_UNDO_ITEM( m_frame );
|
2020-08-26 18:04:32 +00:00
|
|
|
ITEM_PICKER wrapper( m_frame->GetScreen(), undoItem, UNDO_REDO::PAGESETTINGS );
|
2019-05-26 15:36:40 +00:00
|
|
|
|
|
|
|
undoCmd.PushItem( wrapper );
|
2020-08-26 18:04:32 +00:00
|
|
|
m_frame->SaveCopyInUndoList( undoCmd, UNDO_REDO::PAGESETTINGS, false );
|
2019-05-26 15:36:40 +00:00
|
|
|
|
2020-12-19 15:08:31 +00:00
|
|
|
DIALOG_EESCHEMA_PAGE_SETTINGS dlg( m_frame, wxSize( MAX_PAGE_SIZE_MILS, MAX_PAGE_SIZE_MILS ) );
|
2021-05-30 22:56:24 +00:00
|
|
|
dlg.SetWksFileName( BASE_SCREEN::m_DrawingSheetFileName );
|
2019-05-26 15:36:40 +00:00
|
|
|
|
2019-07-07 23:05:59 +00:00
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
2019-05-26 15:36:40 +00:00
|
|
|
m_frame->RollbackSchematicFromUndo();
|
|
|
|
|
2019-05-24 23:36:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-12 17:12:38 +00:00
|
|
|
int SCH_EDITOR_CONTROL::RescueSymbols( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2020-05-13 02:00:37 +00:00
|
|
|
SCH_SCREENS schematic( m_frame->Schematic().Root() );
|
2020-05-12 17:12:38 +00:00
|
|
|
|
|
|
|
if( schematic.HasNoFullyDefinedLibIds() )
|
|
|
|
RescueLegacyProject( true );
|
|
|
|
else
|
|
|
|
RescueSymbolLibTableProject( true );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_EDITOR_CONTROL::RescueLegacyProject( bool aRunningOnDemand )
|
|
|
|
{
|
2020-05-13 02:00:37 +00:00
|
|
|
LEGACY_RESCUER rescuer( m_frame->Prj(), &m_frame->Schematic(), &m_frame->GetCurrentSheet(),
|
2020-05-12 17:12:38 +00:00
|
|
|
m_frame->GetCanvas()->GetBackend() );
|
|
|
|
|
|
|
|
return rescueProject( rescuer, aRunningOnDemand );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_EDITOR_CONTROL::RescueSymbolLibTableProject( bool aRunningOnDemand )
|
|
|
|
{
|
2020-05-13 02:00:37 +00:00
|
|
|
SYMBOL_LIB_TABLE_RESCUER rescuer( m_frame->Prj(), &m_frame->Schematic(),
|
|
|
|
&m_frame->GetCurrentSheet(),
|
2020-05-12 17:12:38 +00:00
|
|
|
m_frame->GetCanvas()->GetBackend() );
|
|
|
|
|
|
|
|
return rescueProject( rescuer, aRunningOnDemand );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_EDITOR_CONTROL::rescueProject( RESCUER& aRescuer, bool aRunningOnDemand )
|
|
|
|
{
|
|
|
|
if( !RESCUER::RescueProject( m_frame, aRescuer, aRunningOnDemand ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( aRescuer.GetCandidateCount() )
|
|
|
|
{
|
|
|
|
KIWAY_PLAYER* viewer = m_frame->Kiway().Player( FRAME_SCH_VIEWER, false );
|
|
|
|
|
|
|
|
if( viewer )
|
2020-12-25 23:37:01 +00:00
|
|
|
static_cast<SYMBOL_VIEWER_FRAME*>( viewer )->ReCreateLibList();
|
2020-05-12 17:12:38 +00:00
|
|
|
|
|
|
|
if( aRunningOnDemand )
|
|
|
|
{
|
2020-05-13 02:00:37 +00:00
|
|
|
SCH_SCREENS schematic( m_frame->Schematic().Root() );
|
2020-05-12 17:12:38 +00:00
|
|
|
|
|
|
|
schematic.UpdateSymbolLinks();
|
|
|
|
m_frame->RecalculateConnections( GLOBAL_CLEANUP );
|
|
|
|
}
|
|
|
|
|
2020-07-13 11:21:40 +00:00
|
|
|
m_frame->ClearUndoRedoList();
|
2020-05-12 17:12:38 +00:00
|
|
|
m_frame->SyncView();
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
m_frame->OnModify();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::RemapSymbols( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
DIALOG_SYMBOL_REMAP dlgRemap( m_frame );
|
|
|
|
|
|
|
|
dlgRemap.ShowQuasiModal();
|
|
|
|
|
|
|
|
m_frame->GetCanvas()->Refresh( true );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-24 23:36:31 +00:00
|
|
|
int SCH_EDITOR_CONTROL::Print( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2020-05-12 17:12:38 +00:00
|
|
|
InvokeDialogPrintUsingPrinter( m_frame );
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
wxFileName fn = m_frame->Prj().AbsolutePath( m_frame->Schematic().RootScreen()->GetFileName() );
|
2020-05-12 17:12:38 +00:00
|
|
|
|
|
|
|
if( fn.GetName() != NAMELESS_PROJECT )
|
|
|
|
m_frame->SaveProjectSettings();
|
|
|
|
|
2019-05-24 23:36:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::Plot( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2020-05-12 17:12:38 +00:00
|
|
|
DIALOG_PLOT_SCHEMATIC dlg( m_frame );
|
|
|
|
|
|
|
|
dlg.ShowModal();
|
|
|
|
|
|
|
|
// save project config if the prj config has changed:
|
|
|
|
if( dlg.PrjConfigChanged() )
|
|
|
|
m_frame->SaveProjectSettings();
|
|
|
|
|
2019-05-24 23:36:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::Quit( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_frame->Close( false );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
// A dummy wxFindReplaceData signaling any marker should be found
|
2019-05-19 21:04:04 +00:00
|
|
|
static wxFindReplaceData g_markersOnly;
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::FindAndReplace( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2020-11-24 22:16:41 +00:00
|
|
|
m_frame->ShowFindReplaceDialog( aEvent.IsAction( &ACTIONS::findAndReplace ) );
|
2019-05-19 21:04:04 +00:00
|
|
|
return UpdateFind( aEvent );
|
|
|
|
}
|
|
|
|
|
2020-08-31 15:06:23 +00:00
|
|
|
|
2019-10-24 17:07:01 +00:00
|
|
|
int SCH_EDITOR_CONTROL::NavigateHierarchy( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_frame->UpdateHierarchyNavigator( true );
|
|
|
|
return 0;
|
|
|
|
}
|
2019-05-19 21:04:04 +00:00
|
|
|
|
2020-08-31 15:06:23 +00:00
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
int SCH_EDITOR_CONTROL::UpdateFind( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
wxFindReplaceData* data = m_frame->GetFindReplaceData();
|
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
auto visit =
|
|
|
|
[&]( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheet )
|
|
|
|
{
|
|
|
|
if( data && aItem->Matches( *data, aSheet ) )
|
|
|
|
{
|
|
|
|
aItem->SetForceVisible( true );
|
|
|
|
m_selectionTool->BrightenItem( aItem );
|
|
|
|
}
|
|
|
|
else if( aItem->IsBrightened() )
|
|
|
|
{
|
|
|
|
aItem->SetForceVisible( false );
|
|
|
|
m_selectionTool->UnbrightenItem( aItem );
|
|
|
|
}
|
|
|
|
};
|
2020-04-18 11:04:52 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
if( aEvent.IsAction( &ACTIONS::find ) || aEvent.IsAction( &ACTIONS::findAndReplace )
|
|
|
|
|| aEvent.IsAction( &ACTIONS::updateFind ) )
|
2019-05-19 21:04:04 +00:00
|
|
|
{
|
|
|
|
m_selectionTool->ClearSelection();
|
|
|
|
|
2020-04-18 11:04:52 +00:00
|
|
|
for( SCH_ITEM* item : m_frame->GetScreen()->Items() )
|
2019-05-19 21:04:04 +00:00
|
|
|
{
|
2020-09-20 17:52:56 +00:00
|
|
|
visit( item, &m_frame->GetCurrentSheet() );
|
2020-04-18 11:04:52 +00:00
|
|
|
|
2020-11-17 16:02:47 +00:00
|
|
|
item->RunOnChildren(
|
|
|
|
[&]( SCH_ITEM* aChild )
|
|
|
|
{
|
|
|
|
visit( aChild, &m_frame->GetCurrentSheet() );
|
|
|
|
} );
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
2019-05-19 21:04:04 +00:00
|
|
|
}
|
|
|
|
else if( aEvent.Matches( EVENTS::SelectedItemsModified ) )
|
|
|
|
{
|
|
|
|
for( EDA_ITEM* item : m_selectionTool->GetSelection() )
|
2020-09-20 17:52:56 +00:00
|
|
|
visit( item, &m_frame->GetCurrentSheet() );
|
2019-05-19 21:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getView()->UpdateItems();
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
2019-11-24 01:24:32 +00:00
|
|
|
m_frame->UpdateTitle();
|
2019-05-19 21:04:04 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-20 17:52:56 +00:00
|
|
|
SCH_ITEM* SCH_EDITOR_CONTROL::nextMatch( SCH_SCREEN* aScreen, SCH_SHEET_PATH* aSheet,
|
|
|
|
SCH_ITEM* aAfter, wxFindReplaceData* aData )
|
2019-05-19 21:04:04 +00:00
|
|
|
{
|
2020-03-03 17:34:04 +00:00
|
|
|
bool past_item = true;
|
|
|
|
|
|
|
|
if( aAfter != nullptr )
|
|
|
|
{
|
|
|
|
past_item = false;
|
|
|
|
|
|
|
|
if( aAfter->Type() == SCH_PIN_T || aAfter->Type() == SCH_FIELD_T )
|
|
|
|
aAfter = static_cast<SCH_ITEM*>( aAfter->GetParent() );
|
|
|
|
}
|
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
|
2020-03-29 12:22:22 +00:00
|
|
|
for( SCH_ITEM* item : aScreen->Items() )
|
2019-05-19 21:04:04 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
if( item == aAfter )
|
2020-03-03 17:34:04 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
past_item = true;
|
2020-03-03 17:34:04 +00:00
|
|
|
}
|
|
|
|
else if( past_item )
|
|
|
|
{
|
|
|
|
if( aData == &g_markersOnly && item->Type() == SCH_MARKER_T )
|
|
|
|
return item;
|
|
|
|
|
2020-09-20 17:52:56 +00:00
|
|
|
if( item->Matches( *aData, aSheet ) )
|
2020-03-03 17:34:04 +00:00
|
|
|
return item;
|
|
|
|
|
|
|
|
if( item->Type() == SCH_COMPONENT_T )
|
|
|
|
{
|
2020-03-29 12:22:22 +00:00
|
|
|
SCH_COMPONENT* cmp = static_cast<SCH_COMPONENT*>( item );
|
2020-03-03 17:34:04 +00:00
|
|
|
|
2020-03-29 12:22:22 +00:00
|
|
|
for( SCH_FIELD& field : cmp->GetFields() )
|
2020-03-03 17:34:04 +00:00
|
|
|
{
|
2020-09-20 17:52:56 +00:00
|
|
|
if( field.Matches( *aData, aSheet ) )
|
2020-03-26 11:02:59 +00:00
|
|
|
return &field;
|
2020-03-03 17:34:04 +00:00
|
|
|
}
|
|
|
|
|
2020-08-21 15:54:24 +00:00
|
|
|
for( SCH_PIN* pin : cmp->GetPins() )
|
2020-03-03 17:34:04 +00:00
|
|
|
{
|
2020-09-20 17:52:56 +00:00
|
|
|
if( pin->Matches( *aData, aSheet ) )
|
2020-03-03 17:34:04 +00:00
|
|
|
return pin;
|
2020-03-06 12:05:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( item->Type() == SCH_SHEET_T )
|
|
|
|
{
|
2020-03-29 12:22:22 +00:00
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
|
2020-03-06 12:05:21 +00:00
|
|
|
|
|
|
|
for( SCH_FIELD& field : sheet->GetFields() )
|
|
|
|
{
|
2020-09-20 17:52:56 +00:00
|
|
|
if( field.Matches( *aData, aSheet ) )
|
2020-03-06 12:05:21 +00:00
|
|
|
return &field;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( SCH_SHEET_PIN* pin : sheet->GetPins() )
|
|
|
|
{
|
2020-09-20 17:52:56 +00:00
|
|
|
if( pin->Matches( *aData, aSheet ) )
|
2020-03-06 12:05:21 +00:00
|
|
|
return pin;
|
2020-03-03 17:34:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
2019-05-19 21:04:04 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
return nullptr;
|
2019-05-19 21:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::FindNext( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-05-23 09:41:06 +00:00
|
|
|
// A timer during which a subsequent FindNext will result in a wrap-around
|
|
|
|
static wxTimer wrapAroundTimer;
|
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
wxFindReplaceData* data = m_frame->GetFindReplaceData();
|
|
|
|
|
|
|
|
if( aEvent.IsAction( &ACTIONS::findNextMarker ) )
|
|
|
|
{
|
|
|
|
if( data )
|
|
|
|
g_markersOnly.SetFlags( data->GetFlags() );
|
|
|
|
|
|
|
|
data = &g_markersOnly;
|
|
|
|
}
|
|
|
|
else if( !data )
|
|
|
|
{
|
|
|
|
return FindAndReplace( ACTIONS::find.MakeEvent() );
|
|
|
|
}
|
|
|
|
|
2019-06-08 21:48:22 +00:00
|
|
|
bool searchAllSheets = !( data->GetFlags() & FR_CURRENT_SHEET_ONLY );
|
2020-11-22 22:21:41 +00:00
|
|
|
EE_SELECTION& selection = m_selectionTool->GetSelection();
|
|
|
|
SCH_SCREEN* afterScreen = m_frame->GetScreen();
|
2019-06-25 23:39:58 +00:00
|
|
|
SCH_ITEM* afterItem = dynamic_cast<SCH_ITEM*>( selection.Front() );
|
|
|
|
SCH_ITEM* item = nullptr;
|
2019-05-19 21:04:04 +00:00
|
|
|
|
2019-05-23 09:41:06 +00:00
|
|
|
if( wrapAroundTimer.IsRunning() )
|
2019-05-19 21:04:04 +00:00
|
|
|
{
|
|
|
|
afterScreen = nullptr;
|
|
|
|
afterItem = nullptr;
|
2019-05-23 09:41:06 +00:00
|
|
|
wrapAroundTimer.Stop();
|
2019-05-19 21:04:04 +00:00
|
|
|
m_frame->ClearFindReplaceStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_selectionTool->ClearSelection();
|
|
|
|
|
|
|
|
if( afterScreen || !searchAllSheets )
|
2020-09-20 17:52:56 +00:00
|
|
|
item = nextMatch( m_frame->GetScreen(), &m_frame->GetCurrentSheet(), afterItem, data );
|
2019-05-19 21:04:04 +00:00
|
|
|
|
|
|
|
if( !item && searchAllSheets )
|
|
|
|
{
|
2020-05-13 02:00:37 +00:00
|
|
|
SCH_SHEET_LIST schematic = m_frame->Schematic().GetSheets();
|
|
|
|
SCH_SCREENS screens( m_frame->Schematic().Root() );
|
2019-05-19 21:04:04 +00:00
|
|
|
|
|
|
|
for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
|
|
|
|
{
|
|
|
|
if( afterScreen )
|
|
|
|
{
|
|
|
|
if( afterScreen == screen )
|
|
|
|
afterScreen = nullptr;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-09-20 17:52:56 +00:00
|
|
|
SCH_SHEET_PATH* sheet = schematic.FindSheetForScreen( screen );
|
|
|
|
|
|
|
|
item = nextMatch( screen, sheet, nullptr, data );
|
2019-05-19 21:04:04 +00:00
|
|
|
|
|
|
|
if( item )
|
|
|
|
{
|
|
|
|
wxCHECK_MSG( sheet, 0, "Sheet not found for " + screen->GetFileName() );
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
m_frame->Schematic().SetCurrentSheet( *sheet );
|
|
|
|
m_frame->GetCurrentSheet().UpdateAllScreenReferences();
|
2019-05-19 21:04:04 +00:00
|
|
|
|
|
|
|
screen->TestDanglingEnds();
|
|
|
|
|
|
|
|
m_frame->SetScreen( screen );
|
|
|
|
UpdateFind( ACTIONS::updateFind.MakeEvent() );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( item )
|
|
|
|
{
|
|
|
|
m_selectionTool->AddItemToSel( item );
|
2020-02-24 17:18:23 +00:00
|
|
|
m_frame->FocusOnLocation( item->GetBoundingBox().GetCenter() );
|
2019-05-19 21:04:04 +00:00
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-15 23:44:01 +00:00
|
|
|
wxString msg = searchAllSheets ? _( "Reached end of schematic." )
|
|
|
|
: _( "Reached end of sheet." );
|
2019-05-19 21:04:04 +00:00
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
// Show the popup during the time period the user can wrap the search
|
2020-10-20 19:05:04 +00:00
|
|
|
m_frame->ShowFindReplaceStatus( msg + wxS( " " ) + _( "Find again to wrap around to the start." ),
|
2020-05-20 10:43:50 +00:00
|
|
|
4000 );
|
2019-05-23 09:41:06 +00:00
|
|
|
wrapAroundTimer.StartOnce( 4000 );
|
2019-05-19 21:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_EDITOR_CONTROL::HasMatch()
|
|
|
|
{
|
|
|
|
wxFindReplaceData* data = m_frame->GetFindReplaceData();
|
|
|
|
EDA_ITEM* item = m_selectionTool->GetSelection().Front();
|
|
|
|
|
2020-09-20 17:52:56 +00:00
|
|
|
return data && item && item->Matches( *data, &m_frame->GetCurrentSheet() );
|
2019-05-19 21:04:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::ReplaceAndFindNext( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
wxFindReplaceData* data = m_frame->GetFindReplaceData();
|
|
|
|
EDA_ITEM* item = m_selectionTool->GetSelection().Front();
|
2020-09-20 17:52:56 +00:00
|
|
|
SCH_SHEET_PATH* sheet = &m_frame->GetCurrentSheet();
|
2019-05-19 21:04:04 +00:00
|
|
|
|
|
|
|
if( !data )
|
|
|
|
return FindAndReplace( ACTIONS::find.MakeEvent() );
|
|
|
|
|
2020-09-20 17:52:56 +00:00
|
|
|
if( item && item->Matches( *data, sheet ) )
|
2019-05-19 21:04:04 +00:00
|
|
|
{
|
2020-09-20 17:52:56 +00:00
|
|
|
if( item->Replace( *data, sheet ) )
|
2020-04-18 11:04:52 +00:00
|
|
|
{
|
2020-08-10 11:40:58 +00:00
|
|
|
m_frame->UpdateItem( item );
|
2021-04-30 16:54:15 +00:00
|
|
|
m_frame->GetCurrentSheet().UpdateAllScreenReferences();
|
2020-04-18 11:04:52 +00:00
|
|
|
m_frame->OnModify();
|
|
|
|
}
|
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
FindNext( ACTIONS::findNext.MakeEvent() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::ReplaceAll( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
wxFindReplaceData* data = m_frame->GetFindReplaceData();
|
2021-04-30 16:54:15 +00:00
|
|
|
bool modified = false;
|
2019-05-19 21:04:04 +00:00
|
|
|
|
|
|
|
if( !data )
|
|
|
|
return FindAndReplace( ACTIONS::find.MakeEvent() );
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
SCH_SHEET_LIST schematic = m_frame->Schematic().GetSheets();
|
|
|
|
SCH_SCREENS screens( m_frame->Schematic().Root() );
|
2019-05-19 21:04:04 +00:00
|
|
|
|
|
|
|
for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
|
|
|
|
{
|
2020-09-20 17:52:56 +00:00
|
|
|
SCH_SHEET_PATH* sheet = schematic.FindSheetForScreen( screen );
|
|
|
|
|
|
|
|
for( EDA_ITEM* item = nextMatch( screen, sheet, nullptr, data ); item; )
|
2020-04-18 11:04:52 +00:00
|
|
|
{
|
2020-09-20 17:52:56 +00:00
|
|
|
if( item->Replace( *data, sheet ) )
|
2020-04-18 11:04:52 +00:00
|
|
|
{
|
2020-08-10 11:40:58 +00:00
|
|
|
m_frame->UpdateItem( item );
|
2021-04-30 16:54:15 +00:00
|
|
|
modified = true;
|
2020-04-18 11:04:52 +00:00
|
|
|
}
|
|
|
|
|
2020-09-20 17:52:56 +00:00
|
|
|
item = nextMatch( screen, sheet, dynamic_cast<SCH_ITEM*>( item ), data );
|
2020-04-18 11:04:52 +00:00
|
|
|
}
|
2019-05-19 21:04:04 +00:00
|
|
|
}
|
|
|
|
|
2021-04-30 16:54:15 +00:00
|
|
|
if( modified )
|
|
|
|
{
|
|
|
|
m_frame->GetCurrentSheet().UpdateAllScreenReferences();
|
|
|
|
m_frame->OnModify();
|
|
|
|
}
|
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-30 18:36:11 +00:00
|
|
|
int SCH_EDITOR_CONTROL::CrossProbeToPcb( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
doCrossProbeSchToPcb( aEvent, false );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::ExplicitCrossProbeToPcb( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
doCrossProbeSchToPcb( aEvent, true );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_EDITOR_CONTROL::doCrossProbeSchToPcb( const TOOL_EVENT& aEvent, bool aForce )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
|
|
|
// Don't get in an infinite loop SCH -> PCB -> SCH -> PCB -> SCH -> ...
|
2019-07-17 20:21:22 +00:00
|
|
|
if( m_probingPcbToSch )
|
2019-04-30 18:36:11 +00:00
|
|
|
return;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
|
|
|
SCH_ITEM* item = nullptr;
|
2021-03-29 10:46:05 +00:00
|
|
|
SCH_COMPONENT* symbol = nullptr;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-04-30 18:36:11 +00:00
|
|
|
if( aForce )
|
2019-04-21 23:45:34 +00:00
|
|
|
{
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& selection = selTool->RequestSelection();
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-04-30 18:36:11 +00:00
|
|
|
if( selection.GetSize() >= 1 )
|
|
|
|
item = (SCH_ITEM*) selection.Front();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& selection = selTool->GetSelection();
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-04-30 18:36:11 +00:00
|
|
|
if( selection.GetSize() >= 1 )
|
|
|
|
item = (SCH_ITEM*) selection.Front();
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-04-30 18:36:11 +00:00
|
|
|
if( !item )
|
|
|
|
{
|
|
|
|
if( aForce )
|
|
|
|
m_frame->SendMessageToPCBNEW( nullptr, nullptr );
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2019-04-30 18:36:11 +00:00
|
|
|
return;
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-30 18:36:11 +00:00
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case SCH_FIELD_T:
|
|
|
|
case LIB_FIELD_T:
|
2020-03-06 20:02:58 +00:00
|
|
|
if( item->GetParent() && item->GetParent()->Type() == SCH_COMPONENT_T )
|
|
|
|
{
|
2021-03-29 10:46:05 +00:00
|
|
|
symbol = (SCH_COMPONENT*) item->GetParent();
|
|
|
|
m_frame->SendMessageToPCBNEW( item, symbol );
|
2020-03-06 20:02:58 +00:00
|
|
|
}
|
2019-04-30 18:36:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_COMPONENT_T:
|
2021-03-29 10:46:05 +00:00
|
|
|
symbol = (SCH_COMPONENT*) item;
|
|
|
|
m_frame->SendMessageToPCBNEW( item, symbol );
|
2019-04-30 18:36:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_PIN_T:
|
2021-03-29 10:46:05 +00:00
|
|
|
symbol = (SCH_COMPONENT*) item->GetParent();
|
|
|
|
m_frame->SendMessageToPCBNEW( static_cast<SCH_PIN*>( item ), symbol );
|
2019-04-30 18:36:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_SHEET_T:
|
|
|
|
if( aForce )
|
|
|
|
m_frame->SendMessageToPCBNEW( item, nullptr );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-23 17:12:26 +00:00
|
|
|
#ifdef KICAD_SPICE
|
2019-08-05 06:47:38 +00:00
|
|
|
|
2019-08-05 22:34:47 +00:00
|
|
|
static KICAD_T wires[] = { SCH_LINE_LOCATE_WIRE_T, EOT };
|
|
|
|
static KICAD_T wiresAndPins[] = { SCH_LINE_LOCATE_WIRE_T, SCH_PIN_T, SCH_SHEET_PIN_T, EOT };
|
2019-08-05 06:47:38 +00:00
|
|
|
static KICAD_T fieldsAndComponents[] = { SCH_COMPONENT_T, SCH_FIELD_T, EOT };
|
|
|
|
|
|
|
|
#define HITTEST_THRESHOLD_PIXELS 5
|
|
|
|
|
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent )
|
2019-04-23 17:12:26 +00:00
|
|
|
{
|
2020-06-02 09:19:16 +00:00
|
|
|
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
|
|
|
|
SIM_PLOT_FRAME* simFrame = (SIM_PLOT_FRAME*) m_frame->Kiway().Player( FRAME_SIMULATOR, false );
|
2019-08-05 22:34:47 +00:00
|
|
|
|
|
|
|
if( !simFrame ) // Defensive coding; shouldn't happen.
|
|
|
|
return 0;
|
2019-04-23 17:12:26 +00:00
|
|
|
|
2019-07-19 20:47:33 +00:00
|
|
|
// Deactivate other tools; particularly important if another PICKER is currently running
|
|
|
|
Activate();
|
|
|
|
|
2020-10-08 00:50:28 +00:00
|
|
|
picker->SetCursor( KICURSOR::VOLTAGE_PROBE );
|
2021-01-31 14:50:19 +00:00
|
|
|
picker->SetSnapping( false );
|
2019-04-23 17:12:26 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
picker->SetClickHandler(
|
2020-11-22 22:21:41 +00:00
|
|
|
[this, simFrame]( const VECTOR2D& aPosition )
|
2019-07-15 23:44:01 +00:00
|
|
|
{
|
2020-11-22 22:21:41 +00:00
|
|
|
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
|
|
|
EDA_ITEM* item = nullptr;
|
|
|
|
selTool->SelectPoint( aPosition, wiresAndPins, &item );
|
2019-08-05 22:34:47 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
if( !item )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( item->IsType( wires ) )
|
|
|
|
{
|
|
|
|
if( SCH_CONNECTION* conn = static_cast<SCH_ITEM*>( item )->Connection() )
|
|
|
|
simFrame->AddVoltagePlot( UnescapeString( conn->Name() ) );
|
|
|
|
}
|
|
|
|
else if( item->Type() == SCH_PIN_T )
|
|
|
|
{
|
|
|
|
SCH_PIN* pin = (SCH_PIN*) item;
|
2021-01-19 23:50:18 +00:00
|
|
|
SCH_COMPONENT* symbol = (SCH_COMPONENT*) item->GetParent();
|
2020-11-22 22:21:41 +00:00
|
|
|
wxString param;
|
|
|
|
wxString primitive;
|
|
|
|
|
2021-01-19 23:50:18 +00:00
|
|
|
primitive = NETLIST_EXPORTER_PSPICE::GetSpiceField( SF_PRIMITIVE, symbol, 0 );
|
2020-11-22 22:21:41 +00:00
|
|
|
primitive.LowerCase();
|
|
|
|
|
|
|
|
if( primitive == "c" || primitive == "l" || primitive == "r" )
|
|
|
|
param = wxT( "I" );
|
|
|
|
else if( primitive == "d" )
|
|
|
|
param = wxT( "Id" );
|
|
|
|
else
|
|
|
|
param = wxString::Format( wxT( "I%s" ), pin->GetName().Lower() );
|
|
|
|
|
2021-01-19 23:50:18 +00:00
|
|
|
simFrame->AddCurrentPlot( symbol->GetRef( &m_frame->GetCurrentSheet() ),
|
|
|
|
param );
|
2020-11-22 22:21:41 +00:00
|
|
|
}
|
2019-04-23 17:12:26 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
return true;
|
|
|
|
} );
|
2019-04-23 17:12:26 +00:00
|
|
|
|
2019-08-05 06:47:38 +00:00
|
|
|
picker->SetMotionHandler(
|
2020-11-22 22:21:41 +00:00
|
|
|
[this, picker]( const VECTOR2D& aPos )
|
|
|
|
{
|
|
|
|
EE_COLLECTOR collector;
|
|
|
|
collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
|
|
|
|
collector.Collect( m_frame->GetScreen(), wiresAndPins, (wxPoint) aPos );
|
2019-08-05 06:47:38 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
|
|
|
selectionTool->GuessSelectionCandidates( collector, aPos );
|
2019-08-05 06:47:38 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
|
|
|
|
SCH_LINE* wire = dynamic_cast<SCH_LINE*>( item );
|
2020-05-24 14:46:05 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
const SCH_CONNECTION* conn = nullptr;
|
2019-08-12 14:42:11 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
if( wire )
|
|
|
|
{
|
|
|
|
item = nullptr;
|
|
|
|
conn = wire->Connection();
|
|
|
|
}
|
2019-08-12 14:42:11 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
if( item && item->Type() == SCH_PIN_T )
|
|
|
|
picker->SetCursor( KICURSOR::CURRENT_PROBE );
|
|
|
|
else
|
|
|
|
picker->SetCursor( KICURSOR::VOLTAGE_PROBE );
|
2019-08-05 06:47:38 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
if( m_pickerItem != item )
|
|
|
|
{
|
2019-08-05 22:34:47 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
if( m_pickerItem )
|
|
|
|
selectionTool->UnbrightenItem( m_pickerItem );
|
2019-08-05 06:47:38 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
m_pickerItem = item;
|
2019-08-05 06:47:38 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
if( m_pickerItem )
|
|
|
|
selectionTool->BrightenItem( m_pickerItem );
|
|
|
|
}
|
2019-08-12 14:42:11 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
if( m_frame->GetHighlightedConnection() != conn )
|
|
|
|
{
|
|
|
|
m_frame->SetHighlightedConnection( conn );
|
2019-08-12 14:42:11 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
TOOL_EVENT dummyEvent;
|
|
|
|
UpdateNetHighlighting( dummyEvent );
|
|
|
|
}
|
|
|
|
} );
|
2019-08-05 06:47:38 +00:00
|
|
|
|
|
|
|
picker->SetFinalizeHandler(
|
2020-11-22 22:21:41 +00:00
|
|
|
[this]( const int& aFinalState )
|
2019-08-12 14:42:11 +00:00
|
|
|
{
|
2020-11-22 22:21:41 +00:00
|
|
|
if( m_pickerItem )
|
|
|
|
m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
|
2019-08-12 14:42:11 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
if( m_frame->GetHighlightedConnection() )
|
|
|
|
{
|
|
|
|
m_frame->SetHighlightedConnection( nullptr );
|
|
|
|
|
|
|
|
TOOL_EVENT dummyEvent;
|
|
|
|
UpdateNetHighlighting( dummyEvent );
|
|
|
|
}
|
2020-10-11 17:12:13 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
// Wake the selection tool after exiting to ensure the cursor gets updated
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::selectionActivate, false );
|
|
|
|
} );
|
2019-08-05 06:47:38 +00:00
|
|
|
|
2019-07-22 01:06:06 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
2019-07-15 23:44:01 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
|
2019-07-15 12:15:58 +00:00
|
|
|
|
2019-04-23 17:12:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
int SCH_EDITOR_CONTROL::SimTune( const TOOL_EVENT& aEvent )
|
2019-04-23 17:12:26 +00:00
|
|
|
{
|
2019-07-22 01:06:06 +00:00
|
|
|
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
|
2019-04-23 17:12:26 +00:00
|
|
|
|
2019-07-19 20:47:33 +00:00
|
|
|
// Deactivate other tools; particularly important if another PICKER is currently running
|
|
|
|
Activate();
|
|
|
|
|
2020-10-08 00:50:28 +00:00
|
|
|
picker->SetCursor( KICURSOR::TUNE );
|
2021-01-31 14:50:19 +00:00
|
|
|
picker->SetSnapping( false );
|
2019-04-23 17:12:26 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
picker->SetClickHandler(
|
2020-11-22 22:21:41 +00:00
|
|
|
[this]( const VECTOR2D& aPosition )
|
2019-07-15 23:44:01 +00:00
|
|
|
{
|
2020-11-22 22:21:41 +00:00
|
|
|
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
2020-12-29 12:13:58 +00:00
|
|
|
EDA_ITEM* item = nullptr;
|
2020-11-22 22:21:41 +00:00
|
|
|
selTool->SelectPoint( aPosition, fieldsAndComponents, &item );
|
2019-04-23 17:12:26 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
if( !item )
|
2019-07-15 23:44:01 +00:00
|
|
|
return false;
|
2019-04-23 17:12:26 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
if( item->Type() != SCH_COMPONENT_T )
|
|
|
|
{
|
|
|
|
item = item->GetParent();
|
|
|
|
|
|
|
|
if( item->Type() != SCH_COMPONENT_T )
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-19 08:12:54 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
SIM_PLOT_FRAME* simFrame =
|
|
|
|
(SIM_PLOT_FRAME*) m_frame->Kiway().Player( FRAME_SIMULATOR, false );
|
2019-04-23 17:12:26 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
if( simFrame )
|
|
|
|
simFrame->AddTuner( static_cast<SCH_COMPONENT*>( item ) );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} );
|
2019-04-23 17:12:26 +00:00
|
|
|
|
2019-08-05 06:47:38 +00:00
|
|
|
picker->SetMotionHandler(
|
2020-11-22 22:21:41 +00:00
|
|
|
[this]( const VECTOR2D& aPos )
|
|
|
|
{
|
|
|
|
EE_COLLECTOR collector;
|
|
|
|
collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
|
|
|
|
collector.Collect( m_frame->GetScreen(), fieldsAndComponents, (wxPoint) aPos );
|
2019-08-05 06:47:38 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
|
|
|
selectionTool->GuessSelectionCandidates( collector, aPos );
|
2019-08-05 06:47:38 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
|
2019-08-05 06:47:38 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
if( m_pickerItem != item )
|
|
|
|
{
|
|
|
|
if( m_pickerItem )
|
|
|
|
selectionTool->UnbrightenItem( m_pickerItem );
|
2019-08-05 06:47:38 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
m_pickerItem = item;
|
2019-08-05 06:47:38 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
if( m_pickerItem )
|
|
|
|
selectionTool->BrightenItem( m_pickerItem );
|
|
|
|
}
|
|
|
|
} );
|
2019-08-05 06:47:38 +00:00
|
|
|
|
|
|
|
picker->SetFinalizeHandler(
|
2020-11-22 22:21:41 +00:00
|
|
|
[this]( const int& aFinalState )
|
|
|
|
{
|
|
|
|
if( m_pickerItem )
|
|
|
|
m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
|
2020-10-11 17:12:13 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
// Wake the selection tool after exiting to ensure the cursor gets updated
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::selectionActivate, false );
|
|
|
|
} );
|
2019-08-05 06:47:38 +00:00
|
|
|
|
2019-07-19 08:12:54 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
2019-07-15 23:44:01 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
|
2019-07-15 12:15:58 +00:00
|
|
|
|
2019-04-23 17:12:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* KICAD_SPICE */
|
|
|
|
|
|
|
|
|
2019-04-30 13:54:32 +00:00
|
|
|
// A singleton reference for clearing the highlight
|
2019-04-21 23:45:34 +00:00
|
|
|
static VECTOR2D CLEAR;
|
|
|
|
|
|
|
|
|
2019-04-14 00:44:05 +00:00
|
|
|
static bool highlightNet( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition )
|
|
|
|
{
|
2020-05-24 14:46:05 +00:00
|
|
|
SCH_EDIT_FRAME* editFrame = static_cast<SCH_EDIT_FRAME*>( aToolMgr->GetToolHolder() );
|
|
|
|
EE_SELECTION_TOOL* selTool = aToolMgr->GetTool<EE_SELECTION_TOOL>();
|
2019-05-10 23:13:40 +00:00
|
|
|
SCH_EDITOR_CONTROL* editorControl = aToolMgr->GetTool<SCH_EDITOR_CONTROL>();
|
2020-05-24 14:46:05 +00:00
|
|
|
SCH_CONNECTION* conn = nullptr;
|
|
|
|
bool retVal = true;
|
2019-04-14 00:44:05 +00:00
|
|
|
|
2019-04-30 13:54:32 +00:00
|
|
|
if( aPosition != CLEAR )
|
2019-04-14 00:44:05 +00:00
|
|
|
{
|
2020-07-03 21:08:17 +00:00
|
|
|
ERC_TESTER erc( &editFrame->Schematic() );
|
|
|
|
|
|
|
|
if( erc.TestDuplicateSheetNames( false ) > 0 )
|
2019-04-14 00:44:05 +00:00
|
|
|
{
|
|
|
|
wxMessageBox( _( "Error: duplicate sub-sheet names found in current sheet." ) );
|
|
|
|
retVal = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-30 15:28:15 +00:00
|
|
|
SCH_ITEM* item = static_cast<SCH_ITEM*>( selTool->GetNode( aPosition ) );
|
|
|
|
SCH_COMPONENT* symbol = dynamic_cast<SCH_COMPONENT*>( item );
|
2020-04-11 20:55:49 +00:00
|
|
|
|
2020-04-12 10:18:40 +00:00
|
|
|
if( item )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_FIELD_T )
|
2021-01-19 23:50:18 +00:00
|
|
|
symbol = dynamic_cast<SCH_COMPONENT*>( item->GetParent() );
|
2020-05-24 14:46:05 +00:00
|
|
|
|
2021-01-19 23:50:18 +00:00
|
|
|
if( symbol && symbol->GetPartRef() && symbol->GetPartRef()->IsPower() )
|
2020-07-05 00:58:58 +00:00
|
|
|
{
|
2021-01-19 23:50:18 +00:00
|
|
|
std::vector<SCH_PIN*> pins = symbol->GetPins();
|
2020-07-05 00:58:58 +00:00
|
|
|
|
|
|
|
if( pins.size() == 1 )
|
2020-10-07 14:40:12 +00:00
|
|
|
conn = pins[0]->Connection();
|
2020-07-05 00:58:58 +00:00
|
|
|
}
|
2020-04-12 10:18:40 +00:00
|
|
|
else
|
2020-11-22 22:21:41 +00:00
|
|
|
{
|
2020-10-07 14:40:12 +00:00
|
|
|
conn = item->Connection();
|
2020-11-22 22:21:41 +00:00
|
|
|
}
|
2020-04-12 10:18:40 +00:00
|
|
|
}
|
2019-04-14 00:44:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-24 14:46:05 +00:00
|
|
|
if( !conn )
|
2019-05-04 20:18:41 +00:00
|
|
|
{
|
|
|
|
editFrame->SetStatusText( wxT( "" ) );
|
|
|
|
editFrame->SendCrossProbeClearHighlight();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-24 17:30:23 +00:00
|
|
|
editFrame->SetCrossProbeConnection( conn );
|
2019-05-04 20:18:41 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 14:46:05 +00:00
|
|
|
editFrame->SetHighlightedConnection( conn );
|
2020-08-13 21:30:30 +00:00
|
|
|
editFrame->UpdateNetHighlightStatus();
|
|
|
|
|
2019-05-10 23:13:40 +00:00
|
|
|
TOOL_EVENT dummy;
|
2019-05-12 17:03:17 +00:00
|
|
|
editorControl->UpdateNetHighlighting( dummy );
|
2019-04-14 00:44:05 +00:00
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::HighlightNet( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
2021-05-09 19:17:01 +00:00
|
|
|
VECTOR2D cursorPos = controls->GetCursorPosition( !aEvent.DisableGridSnapping() );
|
2019-04-14 00:44:05 +00:00
|
|
|
|
2019-04-30 13:54:32 +00:00
|
|
|
highlightNet( m_toolMgr, cursorPos );
|
2019-04-14 00:44:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-21 23:45:34 +00:00
|
|
|
int SCH_EDITOR_CONTROL::ClearHighlight( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
highlightNet( m_toolMgr, CLEAR );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-07 10:17:30 +00:00
|
|
|
int SCH_EDITOR_CONTROL::AssignNetclass( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
|
|
|
KIGFX::VIEW_CONTROLS* controls = getViewControls();
|
2021-05-09 19:17:01 +00:00
|
|
|
VECTOR2D cursorPos = controls->GetCursorPosition( !aEvent.DisableGridSnapping() );
|
2020-07-07 10:17:30 +00:00
|
|
|
|
2020-07-07 13:45:14 +00:00
|
|
|
// TODO remove once real-time connectivity is a given
|
2020-11-16 11:16:44 +00:00
|
|
|
if( !ADVANCED_CFG::GetCfg().m_RealTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
|
2020-07-07 13:45:14 +00:00
|
|
|
// Ensure the netlist data is up to date:
|
|
|
|
m_frame->RecalculateConnections( NO_CLEANUP );
|
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
// Remove selection in favor of highlighting so the whole net is highlighted
|
2020-07-07 10:17:30 +00:00
|
|
|
selectionTool->ClearSelection();
|
|
|
|
highlightNet( m_toolMgr, cursorPos );
|
|
|
|
|
|
|
|
const SCH_CONNECTION* conn = m_frame->GetHighlightedConnection();
|
|
|
|
|
|
|
|
if( conn )
|
|
|
|
{
|
2020-10-07 14:40:12 +00:00
|
|
|
if( !conn->Driver() || CONNECTION_SUBGRAPH::GetDriverPriority( conn->Driver() )
|
|
|
|
< CONNECTION_SUBGRAPH::PRIORITY::SHEET_PIN )
|
2020-07-07 10:17:30 +00:00
|
|
|
{
|
2020-10-18 20:30:37 +00:00
|
|
|
m_frame->ShowInfoBarError( _( "Net must be labeled to assign a netclass." ) );
|
2020-07-07 10:17:30 +00:00
|
|
|
highlightNet( m_toolMgr, CLEAR );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-10-07 14:40:12 +00:00
|
|
|
wxString netName = conn->Name();
|
2020-07-07 10:17:30 +00:00
|
|
|
NET_SETTINGS& netSettings = m_frame->Schematic().Prj().GetProjectFile().NetSettings();
|
2020-10-07 14:40:12 +00:00
|
|
|
wxString netclassName = netSettings.GetNetclassName( netName );
|
2020-07-07 10:17:30 +00:00
|
|
|
|
|
|
|
wxArrayString headers;
|
|
|
|
std::vector<wxArrayString> items;
|
|
|
|
|
|
|
|
headers.Add( _( "Netclasses" ) );
|
|
|
|
|
|
|
|
wxArrayString defaultItem;
|
|
|
|
defaultItem.Add( _( "Default" ) );
|
|
|
|
items.emplace_back( defaultItem );
|
|
|
|
|
|
|
|
for( const auto& ii : netSettings.m_NetClasses )
|
|
|
|
{
|
|
|
|
wxArrayString item;
|
|
|
|
item.Add( ii.first );
|
|
|
|
items.emplace_back( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
EDA_LIST_DIALOG dlg( m_frame, _( "Assign Netclass" ), headers, items, netclassName );
|
|
|
|
dlg.SetListLabel( _( "Select netclass:" ) );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
{
|
|
|
|
netclassName = dlg.GetTextSelection();
|
|
|
|
|
|
|
|
// Remove from old netclass membership list
|
|
|
|
if( netSettings.m_NetClassAssignments.count( netName ) )
|
|
|
|
{
|
|
|
|
const wxString oldNetclassName = netSettings.m_NetClassAssignments[ netName ];
|
|
|
|
NETCLASSPTR oldNetclass = netSettings.m_NetClasses.Find( oldNetclassName );
|
|
|
|
|
|
|
|
if( oldNetclass )
|
|
|
|
oldNetclass->Remove( netName );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add to new netclass membership list
|
|
|
|
NETCLASSPTR newNetclass = netSettings.m_NetClasses.Find( netclassName );
|
|
|
|
|
|
|
|
if( newNetclass )
|
|
|
|
newNetclass->Add( netName );
|
|
|
|
|
|
|
|
netSettings.m_NetClassAssignments[ netName ] = netclassName;
|
|
|
|
netSettings.ResolveNetClassAssignments();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
highlightNet( m_toolMgr, CLEAR );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-12 17:03:17 +00:00
|
|
|
int SCH_EDITOR_CONTROL::UpdateNetHighlighting( const TOOL_EVENT& aEvent )
|
2019-04-14 00:44:05 +00:00
|
|
|
{
|
2020-05-13 02:00:37 +00:00
|
|
|
SCH_SCREEN* screen = m_frame->GetCurrentSheet().LastScreen();
|
2020-06-02 09:19:16 +00:00
|
|
|
CONNECTION_GRAPH* connectionGraph = m_frame->Schematic().ConnectionGraph();
|
2019-04-14 00:44:05 +00:00
|
|
|
std::vector<EDA_ITEM*> itemsToRedraw;
|
2020-05-24 14:46:05 +00:00
|
|
|
const SCH_CONNECTION* selectedConn = m_frame->GetHighlightedConnection();
|
2019-04-14 00:44:05 +00:00
|
|
|
|
|
|
|
if( !screen )
|
|
|
|
return 0;
|
|
|
|
|
2020-05-24 14:46:05 +00:00
|
|
|
bool selectedIsBus = selectedConn ? selectedConn->IsBus() : false;
|
|
|
|
wxString selectedName = selectedConn ? selectedConn->Name() : "";
|
|
|
|
|
|
|
|
bool selectedIsNoNet = false;
|
|
|
|
CONNECTION_SUBGRAPH* selectedSubgraph = nullptr;
|
|
|
|
|
|
|
|
if( selectedConn && selectedConn->Driver() == nullptr )
|
|
|
|
{
|
|
|
|
selectedIsNoNet = true;
|
2020-06-02 09:19:16 +00:00
|
|
|
selectedSubgraph = connectionGraph->GetSubgraphForItem( selectedConn->Parent() );
|
2020-05-24 14:46:05 +00:00
|
|
|
}
|
|
|
|
|
2020-03-29 12:22:22 +00:00
|
|
|
for( SCH_ITEM* item : screen->Items() )
|
2019-04-14 00:44:05 +00:00
|
|
|
{
|
2020-05-24 14:46:05 +00:00
|
|
|
SCH_CONNECTION* itemConn = nullptr;
|
2021-01-19 23:50:18 +00:00
|
|
|
SCH_COMPONENT* symbol = nullptr;
|
2020-05-24 14:46:05 +00:00
|
|
|
bool redraw = item->IsBrightened();
|
|
|
|
bool highlight = false;
|
2019-04-14 00:44:05 +00:00
|
|
|
|
2020-04-10 13:08:14 +00:00
|
|
|
if( item->Type() == SCH_COMPONENT_T )
|
2021-01-19 23:50:18 +00:00
|
|
|
symbol = static_cast<SCH_COMPONENT*>( item );
|
2020-04-10 13:08:14 +00:00
|
|
|
|
2021-01-19 23:50:18 +00:00
|
|
|
if( symbol && symbol->GetPartRef() && symbol->GetPartRef()->IsPower() )
|
|
|
|
itemConn = symbol->Connection();
|
2020-05-24 14:46:05 +00:00
|
|
|
else
|
2020-10-07 14:40:12 +00:00
|
|
|
itemConn = item->Connection();
|
2020-05-24 14:46:05 +00:00
|
|
|
|
|
|
|
if( selectedIsNoNet && selectedSubgraph )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* subgraphItem : selectedSubgraph->m_items )
|
|
|
|
{
|
|
|
|
if( item == subgraphItem )
|
|
|
|
{
|
|
|
|
highlight = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( selectedIsBus && itemConn && itemConn->IsNet() )
|
2020-04-10 13:08:14 +00:00
|
|
|
{
|
2020-06-02 09:19:16 +00:00
|
|
|
for( const std::shared_ptr<SCH_CONNECTION>& member : selectedConn->Members() )
|
2020-05-24 14:46:05 +00:00
|
|
|
{
|
|
|
|
if( member->Name() == itemConn->Name() )
|
|
|
|
{
|
|
|
|
highlight = true;
|
|
|
|
break;
|
|
|
|
}
|
2020-05-24 20:15:22 +00:00
|
|
|
else if( member->IsBus() )
|
|
|
|
{
|
2020-06-02 09:19:16 +00:00
|
|
|
for( const std::shared_ptr<SCH_CONNECTION>& child_member : member->Members() )
|
2020-05-24 20:15:22 +00:00
|
|
|
{
|
|
|
|
if( child_member->Name() == itemConn->Name() )
|
|
|
|
{
|
|
|
|
highlight = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-24 14:46:05 +00:00
|
|
|
}
|
2020-04-10 13:08:14 +00:00
|
|
|
}
|
2020-05-24 14:46:05 +00:00
|
|
|
else if( selectedConn && itemConn && selectedName == itemConn->Name() )
|
2020-04-10 13:08:14 +00:00
|
|
|
{
|
2020-05-24 14:46:05 +00:00
|
|
|
highlight = true;
|
2020-04-10 13:08:14 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 14:46:05 +00:00
|
|
|
if( highlight )
|
2019-04-19 16:15:14 +00:00
|
|
|
item->SetBrightened();
|
|
|
|
else
|
|
|
|
item->ClearBrightened();
|
2019-04-14 00:44:05 +00:00
|
|
|
|
2019-04-19 16:15:14 +00:00
|
|
|
redraw |= item->IsBrightened();
|
2019-04-14 00:44:05 +00:00
|
|
|
|
2021-01-19 23:50:18 +00:00
|
|
|
// symbol is only non-null if the item is a SCH_COMPONENT_T
|
|
|
|
if( symbol )
|
2019-04-14 00:44:05 +00:00
|
|
|
{
|
2021-01-19 23:50:18 +00:00
|
|
|
redraw |= symbol->HasBrightenedPins();
|
2019-04-14 00:44:05 +00:00
|
|
|
|
2021-01-19 23:50:18 +00:00
|
|
|
symbol->ClearBrightenedPins();
|
2019-04-14 00:44:05 +00:00
|
|
|
|
2021-01-19 23:50:18 +00:00
|
|
|
for( SCH_PIN* pin : symbol->GetPins() )
|
2019-04-14 00:44:05 +00:00
|
|
|
{
|
2020-10-07 14:40:12 +00:00
|
|
|
SCH_CONNECTION* pin_conn = pin->Connection();
|
2019-04-14 00:44:05 +00:00
|
|
|
|
2020-06-02 09:19:16 +00:00
|
|
|
if( pin_conn && pin_conn->Name() == selectedName )
|
2019-04-14 00:44:05 +00:00
|
|
|
{
|
2020-08-21 15:54:24 +00:00
|
|
|
pin->SetBrightened();
|
2019-04-14 00:44:05 +00:00
|
|
|
redraw = true;
|
|
|
|
}
|
|
|
|
}
|
2020-04-10 13:08:14 +00:00
|
|
|
|
2021-01-19 23:50:18 +00:00
|
|
|
if( symbol->GetPartRef() && symbol->GetPartRef()->IsPower() )
|
2020-04-10 13:08:14 +00:00
|
|
|
{
|
2021-01-19 23:50:18 +00:00
|
|
|
std::vector<SCH_FIELD>& fields = symbol->GetFields();
|
2020-04-10 13:08:14 +00:00
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
for( int id : { REFERENCE_FIELD, VALUE_FIELD } )
|
2020-04-10 13:08:14 +00:00
|
|
|
{
|
|
|
|
if( item->IsBrightened() && fields[id].IsVisible() )
|
|
|
|
fields[id].SetBrightened();
|
|
|
|
else
|
|
|
|
fields[id].ClearBrightened();
|
|
|
|
}
|
|
|
|
}
|
2019-04-14 00:44:05 +00:00
|
|
|
}
|
2019-04-19 16:15:14 +00:00
|
|
|
else if( item->Type() == SCH_SHEET_T )
|
2019-04-14 00:44:05 +00:00
|
|
|
{
|
2020-01-12 18:40:50 +00:00
|
|
|
for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( item )->GetPins() )
|
2019-04-14 00:44:05 +00:00
|
|
|
{
|
2020-10-07 14:40:12 +00:00
|
|
|
SCH_CONNECTION* pin_conn = pin->Connection();
|
2020-03-29 12:22:22 +00:00
|
|
|
bool redrawPin = pin->IsBrightened();
|
2019-04-14 00:44:05 +00:00
|
|
|
|
2020-05-24 14:46:05 +00:00
|
|
|
if( pin_conn && pin_conn->Name() == selectedName )
|
2020-01-12 18:40:50 +00:00
|
|
|
pin->SetBrightened();
|
2019-04-19 16:15:14 +00:00
|
|
|
else
|
2020-01-12 18:40:50 +00:00
|
|
|
pin->ClearBrightened();
|
2019-04-14 00:44:05 +00:00
|
|
|
|
2020-05-24 14:46:05 +00:00
|
|
|
redrawPin ^= pin->IsBrightened();
|
|
|
|
redraw |= redrawPin;
|
2019-04-14 00:44:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( redraw )
|
2019-04-19 16:15:14 +00:00
|
|
|
itemsToRedraw.push_back( item );
|
2019-04-14 00:44:05 +00:00
|
|
|
}
|
|
|
|
|
2019-08-20 17:22:30 +00:00
|
|
|
// Be sure highlight change will be redrawn
|
2019-04-14 00:44:05 +00:00
|
|
|
KIGFX::VIEW* view = getView();
|
|
|
|
|
2020-03-29 12:22:22 +00:00
|
|
|
for( EDA_ITEM* redrawItem : itemsToRedraw )
|
2019-04-19 16:15:14 +00:00
|
|
|
view->Update( (KIGFX::VIEW_ITEM*)redrawItem, KIGFX::VIEW_UPDATE_FLAGS::REPAINT );
|
2019-04-14 00:44:05 +00:00
|
|
|
|
2019-06-13 17:28:55 +00:00
|
|
|
m_frame->GetCanvas()->Refresh();
|
2019-04-14 00:44:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::HighlightNetCursor( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-04-15 23:56:41 +00:00
|
|
|
// TODO(JE) remove once real-time connectivity is a given
|
2020-11-16 11:16:44 +00:00
|
|
|
if( !ADVANCED_CFG::GetCfg().m_RealTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
|
2019-11-10 23:24:27 +00:00
|
|
|
m_frame->RecalculateConnections( NO_CLEANUP );
|
2019-04-15 23:56:41 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
std::string tool = aEvent.GetCommandStr().get();
|
|
|
|
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
|
2019-07-09 14:01:43 +00:00
|
|
|
|
2019-07-19 20:47:33 +00:00
|
|
|
// Deactivate other tools; particularly important if another PICKER is currently running
|
|
|
|
Activate();
|
|
|
|
|
2020-10-08 00:50:28 +00:00
|
|
|
picker->SetCursor( KICURSOR::BULLSEYE );
|
2021-01-31 14:50:19 +00:00
|
|
|
picker->SetSnapping( false );
|
2019-04-14 00:44:05 +00:00
|
|
|
|
2019-07-15 23:44:01 +00:00
|
|
|
picker->SetClickHandler(
|
2019-07-22 01:06:06 +00:00
|
|
|
[this] ( const VECTOR2D& aPos )
|
2019-07-15 23:44:01 +00:00
|
|
|
{
|
|
|
|
return highlightNet( m_toolMgr, aPos );
|
|
|
|
} );
|
|
|
|
|
|
|
|
m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
|
2019-07-15 12:15:58 +00:00
|
|
|
|
2019-04-14 00:44:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
int SCH_EDITOR_CONTROL::Undo( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2020-07-13 11:21:40 +00:00
|
|
|
if( m_frame->GetUndoCommandCount() <= 0 )
|
2019-05-14 19:21:10 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Inform tools that undo command was issued
|
|
|
|
m_toolMgr->ProcessEvent( { TC_MESSAGE, TA_UNDO_REDO_PRE, AS_GLOBAL } );
|
|
|
|
|
|
|
|
/* Get the old list */
|
2020-07-13 11:21:40 +00:00
|
|
|
PICKED_ITEMS_LIST* List = m_frame->PopCommandFromUndoList();
|
2019-05-14 19:21:10 +00:00
|
|
|
|
|
|
|
/* Undo the command */
|
2021-02-15 14:02:41 +00:00
|
|
|
m_frame->PutDataInPreviousState( List );
|
2019-05-14 19:21:10 +00:00
|
|
|
|
|
|
|
/* Put the old list in RedoList */
|
|
|
|
List->ReversePickersListOrder();
|
2020-07-13 11:21:40 +00:00
|
|
|
m_frame->PushCommandToRedoList( List );
|
2019-05-14 19:21:10 +00:00
|
|
|
|
|
|
|
m_frame->SetSheetNumberAndCount();
|
|
|
|
m_frame->TestDanglingEnds();
|
2020-10-18 20:30:37 +00:00
|
|
|
m_frame->OnPageSettingsChange();
|
2021-05-27 13:24:06 +00:00
|
|
|
|
|
|
|
m_toolMgr->GetTool<EE_SELECTION_TOOL>()->RebuildSelection();
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
m_frame->SyncView();
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
m_frame->OnModify();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::Redo( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2020-07-13 11:21:40 +00:00
|
|
|
if( m_frame->GetRedoCommandCount() == 0 )
|
2019-05-14 19:21:10 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Inform tools that undo command was issued
|
|
|
|
m_toolMgr->ProcessEvent( { TC_MESSAGE, TA_UNDO_REDO_PRE, AS_GLOBAL } );
|
|
|
|
|
|
|
|
/* Get the old list */
|
2021-02-15 14:02:41 +00:00
|
|
|
PICKED_ITEMS_LIST* list = m_frame->PopCommandFromRedoList();
|
2019-05-14 19:21:10 +00:00
|
|
|
|
|
|
|
/* Redo the command: */
|
2021-02-15 14:02:41 +00:00
|
|
|
m_frame->PutDataInPreviousState( list );
|
2019-05-14 19:21:10 +00:00
|
|
|
|
|
|
|
/* Put the old list in UndoList */
|
2021-02-15 14:02:41 +00:00
|
|
|
list->ReversePickersListOrder();
|
|
|
|
m_frame->PushCommandToUndoList( list );
|
2019-05-14 19:21:10 +00:00
|
|
|
|
2019-06-29 18:57:23 +00:00
|
|
|
m_frame->SetSheetNumberAndCount();
|
2019-05-14 19:21:10 +00:00
|
|
|
m_frame->TestDanglingEnds();
|
2020-10-18 20:30:37 +00:00
|
|
|
m_frame->OnPageSettingsChange();
|
2021-05-27 13:24:06 +00:00
|
|
|
|
|
|
|
m_toolMgr->GetTool<EE_SELECTION_TOOL>()->RebuildSelection();
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
m_frame->SyncView();
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
m_frame->OnModify();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-21 16:43:34 +00:00
|
|
|
bool SCH_EDITOR_CONTROL::doCopy( bool aUseLocalClipboard )
|
2019-04-28 16:36:31 +00:00
|
|
|
{
|
2019-05-10 17:19:48 +00:00
|
|
|
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
2019-07-09 20:38:18 +00:00
|
|
|
EE_SELECTION& selection = selTool->RequestSelection();
|
2020-09-06 10:31:53 +00:00
|
|
|
SCHEMATIC& schematic = m_frame->Schematic();
|
2019-04-28 16:36:31 +00:00
|
|
|
|
|
|
|
if( !selection.GetSize() )
|
|
|
|
return false;
|
|
|
|
|
2020-05-15 19:53:59 +00:00
|
|
|
selection.SetScreen( m_frame->GetScreen() );
|
2019-08-30 20:55:04 +00:00
|
|
|
m_supplementaryClipboard.clear();
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : selection )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_SHEET_T )
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) item;
|
|
|
|
m_supplementaryClipboard[ sheet->GetFileName() ] = sheet->GetScreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
STRING_FORMATTER formatter;
|
2020-05-13 21:58:30 +00:00
|
|
|
SCH_SEXPR_PLUGIN plugin;
|
2021-05-01 22:56:37 +00:00
|
|
|
SCH_SHEET_LIST hiearchy = schematic.GetSheets();
|
|
|
|
SCH_SHEET_PATH selPath = m_frame->GetCurrentSheet();
|
2019-04-28 16:36:31 +00:00
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
plugin.Format( &selection, &selPath, &hiearchy, &formatter );
|
2019-04-28 16:36:31 +00:00
|
|
|
|
2021-05-21 16:43:34 +00:00
|
|
|
if( aUseLocalClipboard )
|
|
|
|
{
|
|
|
|
m_localClipboard = formatter.GetString();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
return m_toolMgr->SaveClipboard( formatter.GetString() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-30 20:55:04 +00:00
|
|
|
bool SCH_EDITOR_CONTROL::searchSupplementaryClipboard( const wxString& aSheetFilename,
|
|
|
|
SCH_SCREEN** aScreen )
|
|
|
|
{
|
|
|
|
if( m_supplementaryClipboard.count( aSheetFilename ) > 0 )
|
|
|
|
{
|
|
|
|
*aScreen = m_supplementaryClipboard[ aSheetFilename ];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-21 16:43:34 +00:00
|
|
|
int SCH_EDITOR_CONTROL::Duplicate( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
doCopy( true ); // Use the local clipboard
|
|
|
|
Paste( aEvent );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
int SCH_EDITOR_CONTROL::Cut( const TOOL_EVENT& aEvent )
|
2019-04-23 13:06:37 +00:00
|
|
|
{
|
2019-08-08 10:12:04 +00:00
|
|
|
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
|
|
|
|
|
|
|
|
if( textEntry )
|
|
|
|
{
|
|
|
|
textEntry->Cut();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
if( doCopy() )
|
2019-07-31 12:48:00 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::doDelete, true );
|
2019-04-28 16:36:31 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::Copy( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-08-08 10:12:04 +00:00
|
|
|
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
|
|
|
|
|
|
|
|
if( textEntry )
|
|
|
|
{
|
|
|
|
textEntry->Copy();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
doCopy();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
void SCH_EDITOR_CONTROL::updatePastedSymbol( SCH_COMPONENT* aSymbol, SCH_SCREEN* aPasteScreen,
|
|
|
|
const SCH_SHEET_PATH& aPastePath,
|
|
|
|
const KIID_PATH& aClipPath,
|
|
|
|
bool aForceKeepAnnotations )
|
2020-09-06 10:31:53 +00:00
|
|
|
{
|
2021-05-01 22:56:37 +00:00
|
|
|
KIID_PATH clipItemPath = aClipPath;
|
|
|
|
clipItemPath.push_back( aSymbol->m_Uuid );
|
|
|
|
|
|
|
|
wxString reference, value, footprint;
|
|
|
|
int unit;
|
|
|
|
|
|
|
|
if( m_clipboardSymbolInstances.count( clipItemPath ) > 0 )
|
2020-09-06 10:31:53 +00:00
|
|
|
{
|
2021-05-01 22:56:37 +00:00
|
|
|
SYMBOL_INSTANCE_REFERENCE instance = m_clipboardSymbolInstances.at( clipItemPath );
|
2020-09-06 10:31:53 +00:00
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
unit = instance.m_Unit;
|
|
|
|
reference = instance.m_Reference;
|
|
|
|
value = instance.m_Value;
|
|
|
|
footprint = instance.m_Footprint;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Pasted from notepad or an older instance of eeschema.
|
|
|
|
// Use the values in the fields instead
|
|
|
|
reference = aSymbol->GetField( REFERENCE_FIELD )->GetText();
|
|
|
|
value = aSymbol->GetField( VALUE_FIELD )->GetText();
|
|
|
|
footprint = aSymbol->GetField( FOOTPRINT_FIELD )->GetText();
|
|
|
|
unit = aSymbol->GetUnit();
|
|
|
|
}
|
2020-09-06 10:31:53 +00:00
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
if( aForceKeepAnnotations && !reference.IsEmpty() )
|
|
|
|
{
|
|
|
|
aSymbol->SetRef( &aPastePath, reference );
|
|
|
|
aSymbol->SetValue( &aPastePath, value );
|
|
|
|
aSymbol->SetFootprint( &aPastePath, footprint );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
aSymbol->ClearAnnotation( &aPastePath );
|
|
|
|
}
|
2020-09-06 10:31:53 +00:00
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
// We might clear annotations but always leave the original unit number from the paste
|
|
|
|
aSymbol->SetUnitSelection( &aPastePath, unit );
|
|
|
|
aSymbol->SetUnit( unit );
|
|
|
|
}
|
2020-09-06 10:31:53 +00:00
|
|
|
|
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
SCH_SHEET_PATH SCH_EDITOR_CONTROL::updatePastedSheet( const SCH_SHEET_PATH& aPastePath,
|
|
|
|
const KIID_PATH& aClipPath, SCH_SHEET* aSheet,
|
|
|
|
bool aForceKeepAnnotations,
|
|
|
|
SCH_SHEET_LIST* aPastedSheetsSoFar,
|
|
|
|
SCH_REFERENCE_LIST* aPastedSymbolsSoFar )
|
|
|
|
{
|
|
|
|
SCH_SHEET_PATH sheetPath = aPastePath;
|
|
|
|
sheetPath.push_back( aSheet );
|
2021-01-21 17:36:59 +00:00
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
aSheet->AddInstance( sheetPath.Path() );
|
|
|
|
|
|
|
|
wxString pageNum;
|
|
|
|
|
|
|
|
if( m_clipboardSheetInstances.count( aClipPath ) > 0 )
|
|
|
|
pageNum = m_clipboardSheetInstances.at( aClipPath ).m_PageNumber;
|
|
|
|
else
|
|
|
|
pageNum = wxString::Format( "%d", static_cast<int>( aPastedSheetsSoFar->size() ) );
|
|
|
|
|
|
|
|
aSheet->SetPageNumber( sheetPath, pageNum );
|
|
|
|
aPastedSheetsSoFar->push_back( sheetPath );
|
|
|
|
|
|
|
|
if( aSheet->GetScreen() == nullptr )
|
|
|
|
return sheetPath; // We can only really set the page number but not load any items
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : aSheet->GetScreen()->Items() )
|
|
|
|
{
|
|
|
|
if( item->Type() == SCH_COMPONENT_T )
|
|
|
|
{
|
|
|
|
SCH_COMPONENT* symbol = static_cast<SCH_COMPONENT*>( item );
|
|
|
|
|
|
|
|
updatePastedSymbol( symbol, aSheet->GetScreen(), sheetPath, aClipPath,
|
|
|
|
aForceKeepAnnotations );
|
2020-09-06 10:31:53 +00:00
|
|
|
}
|
|
|
|
else if( item->Type() == SCH_SHEET_T )
|
|
|
|
{
|
2021-05-01 22:56:37 +00:00
|
|
|
SCH_SHEET* subsheet = static_cast<SCH_SHEET*>( item );
|
2020-09-06 10:31:53 +00:00
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
KIID_PATH newClipPath = aClipPath;
|
|
|
|
newClipPath.push_back( subsheet->m_Uuid );
|
|
|
|
|
|
|
|
updatePastedSheet( sheetPath, newClipPath, subsheet, aForceKeepAnnotations,
|
|
|
|
aPastedSheetsSoFar, aPastedSymbolsSoFar );
|
2020-09-06 10:31:53 +00:00
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
SCH_SHEET_PATH subSheetPath = sheetPath;
|
|
|
|
subSheetPath.push_back( subsheet );
|
|
|
|
|
|
|
|
subSheetPath.GetSymbols( *aPastedSymbolsSoFar );
|
2020-09-06 10:31:53 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-01 22:56:37 +00:00
|
|
|
|
|
|
|
return sheetPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_EDITOR_CONTROL::setClipboardInstances( const SCH_SCREEN* aPastedScreen )
|
|
|
|
{
|
|
|
|
m_clipboardSheetInstances.clear();
|
|
|
|
|
2021-05-06 20:56:21 +00:00
|
|
|
for( const SCH_SHEET_INSTANCE& sheet : aPastedScreen->GetSheetInstances() )
|
2021-05-01 22:56:37 +00:00
|
|
|
m_clipboardSheetInstances[sheet.m_Path] = sheet;
|
|
|
|
|
|
|
|
m_clipboardSymbolInstances.clear();
|
|
|
|
|
2021-05-06 20:56:21 +00:00
|
|
|
for( const SYMBOL_INSTANCE_REFERENCE& symbol : aPastedScreen->GetSymbolInstances() )
|
2021-05-01 22:56:37 +00:00
|
|
|
m_clipboardSymbolInstances[symbol.m_Path] = symbol;
|
2020-09-06 10:31:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-08-08 10:12:04 +00:00
|
|
|
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
|
|
|
|
|
|
|
|
if( textEntry )
|
|
|
|
{
|
|
|
|
textEntry->Paste();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
2021-05-21 16:43:34 +00:00
|
|
|
std::string text;
|
|
|
|
|
|
|
|
if( aEvent.IsAction( &ACTIONS::duplicate ) )
|
|
|
|
text = m_localClipboard;
|
|
|
|
else
|
|
|
|
text = m_toolMgr->GetClipboardUTF8();
|
2019-08-15 07:19:15 +00:00
|
|
|
|
|
|
|
if( text.empty() )
|
|
|
|
return 0;
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
STRING_LINE_READER reader( text, "Clipboard" );
|
2020-05-13 21:58:30 +00:00
|
|
|
SCH_SEXPR_PLUGIN plugin;
|
2019-04-28 16:36:31 +00:00
|
|
|
|
2020-05-13 21:58:30 +00:00
|
|
|
SCH_SHEET paste_sheet;
|
2020-05-21 02:27:48 +00:00
|
|
|
SCH_SCREEN* paste_screen = new SCH_SCREEN( &m_frame->Schematic() );
|
2020-05-13 21:58:30 +00:00
|
|
|
|
|
|
|
// Screen object on heap is owned by the sheet.
|
|
|
|
paste_sheet.SetScreen( paste_screen );
|
2019-06-25 23:39:58 +00:00
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
try
|
|
|
|
{
|
2020-05-13 21:58:30 +00:00
|
|
|
plugin.LoadContent( reader, &paste_sheet );
|
2019-04-28 16:36:31 +00:00
|
|
|
}
|
2021-02-20 16:50:10 +00:00
|
|
|
catch( IO_ERROR& )
|
2019-04-28 16:36:31 +00:00
|
|
|
{
|
2019-08-15 07:19:15 +00:00
|
|
|
// If it wasn't content, then paste as text
|
2020-05-13 21:58:30 +00:00
|
|
|
paste_screen->Append( new SCH_TEXT( wxPoint( 0, 0 ), text ) );
|
2019-04-28 16:36:31 +00:00
|
|
|
}
|
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
// Save loaded screen instances to m_clipboardSheetInstances
|
|
|
|
setClipboardInstances( paste_screen );
|
|
|
|
|
2021-05-01 22:44:22 +00:00
|
|
|
PASTE_MODE pasteMode = PASTE_MODE::REMOVE_ANNOTATIONS;
|
|
|
|
|
2019-09-02 18:23:46 +00:00
|
|
|
if( aEvent.IsAction( &ACTIONS::pasteSpecial ) )
|
|
|
|
{
|
2021-05-01 22:44:22 +00:00
|
|
|
DIALOG_PASTE_SPECIAL dlg( m_frame, &pasteMode );
|
2019-09-02 18:23:46 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-05-01 22:44:22 +00:00
|
|
|
bool forceKeepAnnotations = pasteMode != PASTE_MODE::REMOVE_ANNOTATIONS;
|
2021-05-01 22:39:16 +00:00
|
|
|
|
2020-05-13 21:58:30 +00:00
|
|
|
// SCH_SEXP_PLUGIN added the items to the paste screen, but not to the view or anything
|
2019-04-28 16:36:31 +00:00
|
|
|
// else. Pull them back out to start with.
|
|
|
|
//
|
2020-05-13 02:00:37 +00:00
|
|
|
EDA_ITEMS loadedItems;
|
|
|
|
bool sheetsPasted = false;
|
2021-05-01 22:44:22 +00:00
|
|
|
SCH_SHEET_LIST hierarchy = m_frame->Schematic().GetSheets();
|
|
|
|
SCH_SHEET_PATH& pasteRoot = m_frame->GetCurrentSheet();
|
|
|
|
wxFileName destFn = pasteRoot.Last()->GetFileName();
|
2019-04-23 13:06:37 +00:00
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
if( destFn.IsRelative() )
|
|
|
|
destFn.MakeAbsolute( m_frame->Prj().GetProjectPath() );
|
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
// List of paths in the hierarchy that refer to the destination sheet of the paste
|
|
|
|
SCH_SHEET_LIST pasteInstances = hierarchy.FindAllSheetsForScreen( pasteRoot.LastScreen() );
|
|
|
|
pasteInstances.SortByPageNumbers();
|
|
|
|
|
|
|
|
// Build a list of screens from the current design (to avoid loading sheets that already exist)
|
|
|
|
std::map<wxString, SCH_SCREEN*> loadedScreens;
|
|
|
|
|
|
|
|
for( const SCH_SHEET_PATH& item : hierarchy )
|
|
|
|
{
|
|
|
|
if( item.LastScreen() )
|
|
|
|
loadedScreens[item.Last()->GetFileName()] = item.LastScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build symbol list for reannotation of duplicates
|
|
|
|
SCH_SHEET_LIST sheets = m_frame->Schematic().GetSheets();
|
|
|
|
SCH_REFERENCE_LIST existingRefs;
|
|
|
|
sheets.GetSymbols( existingRefs );
|
|
|
|
existingRefs.SortByReferenceOnly();
|
|
|
|
|
|
|
|
// Keep track of pasted sheets and symbols for the different
|
|
|
|
// paths to the hiearchy
|
|
|
|
std::map<SCH_SHEET_PATH, SCH_REFERENCE_LIST> pastedSymbols;
|
|
|
|
std::map<SCH_SHEET_PATH, SCH_SHEET_LIST> pastedSheets;
|
|
|
|
|
2020-05-13 21:58:30 +00:00
|
|
|
for( SCH_ITEM* item : paste_screen->Items() )
|
2019-04-23 13:06:37 +00:00
|
|
|
{
|
2019-04-28 16:36:31 +00:00
|
|
|
loadedItems.push_back( item );
|
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
//@todo: we might want to sort the sheets by page number before adding to loadedItems
|
2020-08-29 17:17:57 +00:00
|
|
|
if( item->Type() == SCH_SHEET_T )
|
2019-04-23 13:06:37 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
|
2019-04-28 16:36:31 +00:00
|
|
|
wxFileName srcFn = sheet->GetFileName();
|
|
|
|
|
|
|
|
if( srcFn.IsRelative() )
|
|
|
|
srcFn.MakeAbsolute( m_frame->Prj().GetProjectPath() );
|
|
|
|
|
|
|
|
SCH_SHEET_LIST sheetHierarchy( sheet );
|
|
|
|
|
|
|
|
if( hierarchy.TestForRecursion( sheetHierarchy, destFn.GetFullPath( wxPATH_UNIX ) ) )
|
|
|
|
{
|
|
|
|
auto msg = wxString::Format( _( "The pasted sheet \"%s\"\n"
|
|
|
|
"was dropped because the destination already has "
|
|
|
|
"the sheet or one of its subsheets as a parent." ),
|
|
|
|
sheet->GetFileName() );
|
|
|
|
DisplayError( m_frame, msg );
|
|
|
|
loadedItems.pop_back();
|
|
|
|
}
|
2019-04-23 13:06:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
// Remove the references from our temporary screen to prevent freeing on the DTOR
|
2020-05-13 21:58:30 +00:00
|
|
|
paste_screen->Clear( false );
|
2019-04-23 13:06:37 +00:00
|
|
|
|
2019-05-11 09:12:39 +00:00
|
|
|
for( unsigned i = 0; i < loadedItems.size(); ++i )
|
2019-04-28 16:36:31 +00:00
|
|
|
{
|
2019-05-03 22:46:44 +00:00
|
|
|
EDA_ITEM* item = loadedItems[i];
|
2021-05-01 22:56:37 +00:00
|
|
|
KIID_PATH clipPath( wxT("/") ); // clipboard is at root
|
2019-04-23 13:06:37 +00:00
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
if( item->Type() == SCH_COMPONENT_T )
|
|
|
|
{
|
2021-03-29 10:46:05 +00:00
|
|
|
SCH_COMPONENT* symbol = static_cast<SCH_COMPONENT*>( item );
|
2019-09-02 18:23:46 +00:00
|
|
|
|
2020-05-13 21:58:30 +00:00
|
|
|
// The library symbol gets set from the cached library symbols in the current
|
|
|
|
// schematic not the symbol libraries. The cached library symbol may have
|
|
|
|
// changed from the original library symbol which would cause the copy to
|
|
|
|
// be incorrect.
|
|
|
|
SCH_SCREEN* currentScreen = m_frame->GetScreen();
|
|
|
|
|
|
|
|
wxCHECK2( currentScreen, continue );
|
|
|
|
|
2021-03-29 10:46:05 +00:00
|
|
|
auto it = currentScreen->GetLibSymbols().find( symbol->GetSchSymbolLibraryName() );
|
2021-05-01 22:56:37 +00:00
|
|
|
auto end = currentScreen->GetLibSymbols().end();
|
|
|
|
|
|
|
|
if( it == end )
|
|
|
|
{
|
|
|
|
// If can't find library definition in the design, use the pasted library
|
|
|
|
it = paste_screen->GetLibSymbols().find( symbol->GetSchSymbolLibraryName() );
|
|
|
|
end = paste_screen->GetLibSymbols().end();
|
|
|
|
}
|
|
|
|
|
|
|
|
LIB_PART* libPart = nullptr;
|
2020-05-13 21:58:30 +00:00
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
if( it != end )
|
|
|
|
{
|
|
|
|
libPart = new LIB_PART( *it->second );
|
|
|
|
symbol->SetLibSymbol( libPart );
|
|
|
|
}
|
2020-05-13 21:58:30 +00:00
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
for( SCH_SHEET_PATH& instance : pasteInstances )
|
2019-09-02 18:23:46 +00:00
|
|
|
{
|
2021-05-01 22:56:37 +00:00
|
|
|
updatePastedSymbol( symbol, paste_screen, instance, clipPath,
|
|
|
|
forceKeepAnnotations );
|
2019-09-02 18:23:46 +00:00
|
|
|
}
|
2021-04-19 01:53:38 +00:00
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
// Assign a new KIID
|
|
|
|
const_cast<KIID&>( item->m_Uuid ) = KIID();
|
|
|
|
|
2021-04-19 01:53:38 +00:00
|
|
|
// Make sure pins get a new UUID
|
|
|
|
for( SCH_PIN* pin : symbol->GetPins() )
|
|
|
|
const_cast<KIID&>( pin->m_Uuid ) = KIID();
|
2020-02-20 12:11:04 +00:00
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
for( SCH_SHEET_PATH& instance : pasteInstances )
|
|
|
|
{
|
|
|
|
// Ignore pseudo-symbols (e.g. power symbols) and symbols from a non-existant library
|
|
|
|
if( libPart && symbol->GetRef( &instance )[0] != wxT( '#' ) )
|
|
|
|
{
|
|
|
|
SCH_REFERENCE schReference( symbol, libPart, instance );
|
|
|
|
schReference.SetSheetNumber( instance.GetVirtualPageNumber() );
|
|
|
|
pastedSymbols[instance].AddItem( schReference );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( item->Type() == SCH_SHEET_T )
|
2019-05-03 11:49:59 +00:00
|
|
|
{
|
2020-09-06 10:31:53 +00:00
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) item;
|
|
|
|
SCH_FIELD& nameField = sheet->GetFields()[SHEETNAME];
|
|
|
|
wxString baseName = nameField.GetText();
|
|
|
|
wxString candidateName = baseName;
|
2020-10-23 16:48:07 +00:00
|
|
|
wxString number;
|
|
|
|
|
|
|
|
while( !baseName.IsEmpty() && wxIsdigit( baseName.Last() ) )
|
|
|
|
{
|
|
|
|
number = baseName.Last() + number;
|
|
|
|
baseName.RemoveLast();
|
|
|
|
}
|
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
//@todo: it might be better to just iterate through the sheet names
|
|
|
|
// in this screen instead of the whole hiearchy.
|
2020-10-23 16:48:07 +00:00
|
|
|
int uniquifier = std::max( 0, wxAtoi( number ) ) + 1;
|
2020-02-29 00:05:50 +00:00
|
|
|
|
2020-03-13 09:53:44 +00:00
|
|
|
while( hierarchy.NameExists( candidateName ) )
|
|
|
|
candidateName = wxString::Format( wxT( "%s%d" ), baseName, uniquifier++ );
|
2019-09-02 18:23:46 +00:00
|
|
|
|
2020-03-13 09:53:44 +00:00
|
|
|
nameField.SetText( candidateName );
|
2019-09-02 18:23:46 +00:00
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
wxFileName fn = sheet->GetFileName();
|
|
|
|
SCH_SCREEN* existingScreen = nullptr;
|
|
|
|
|
2020-09-06 10:31:53 +00:00
|
|
|
sheet->SetParent( pasteRoot.Last() );
|
2019-09-02 18:23:46 +00:00
|
|
|
sheet->SetScreen( nullptr );
|
2019-06-12 13:23:53 +00:00
|
|
|
|
2019-06-26 01:44:00 +00:00
|
|
|
if( !fn.IsAbsolute() )
|
|
|
|
{
|
2020-09-06 10:31:53 +00:00
|
|
|
wxFileName currentSheetFileName = pasteRoot.LastScreen()->GetFileName();
|
2019-06-26 01:44:00 +00:00
|
|
|
fn.Normalize( wxPATH_NORM_ALL, currentSheetFileName.GetPath() );
|
|
|
|
}
|
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
// Try to find the screen for the pasted sheet by several means
|
2020-09-06 10:31:53 +00:00
|
|
|
if( !m_frame->Schematic().Root().SearchHierarchy( fn.GetFullPath( wxPATH_UNIX ),
|
|
|
|
&existingScreen ) )
|
|
|
|
{
|
2021-05-01 22:56:37 +00:00
|
|
|
if( loadedScreens.count( sheet->GetFileName() ) > 0 )
|
|
|
|
existingScreen = loadedScreens.at( sheet->GetFileName() );
|
|
|
|
else
|
|
|
|
searchSupplementaryClipboard( sheet->GetFileName(), &existingScreen );
|
2020-09-06 10:31:53 +00:00
|
|
|
}
|
2019-09-02 18:23:46 +00:00
|
|
|
|
|
|
|
if( existingScreen )
|
2019-06-26 01:44:00 +00:00
|
|
|
{
|
2019-06-12 13:23:53 +00:00
|
|
|
sheet->SetScreen( existingScreen );
|
2019-06-26 01:44:00 +00:00
|
|
|
}
|
2019-06-12 13:23:53 +00:00
|
|
|
else
|
2019-06-26 01:44:00 +00:00
|
|
|
{
|
2020-09-06 10:31:53 +00:00
|
|
|
if( !m_frame->LoadSheetFromFile( sheet, &pasteRoot, fn.GetFullPath() ) )
|
2019-08-29 22:25:52 +00:00
|
|
|
m_frame->InitSheet( sheet, sheet->GetFileName() );
|
2019-06-26 01:44:00 +00:00
|
|
|
}
|
2020-09-06 10:31:53 +00:00
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
sheetsPasted = true;
|
|
|
|
|
2020-09-06 10:31:53 +00:00
|
|
|
// Push it to the clipboard path while it still has its old KIID
|
|
|
|
clipPath.push_back( sheet->m_Uuid );
|
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
// Assign a new KIID to the pasted sheet
|
|
|
|
const_cast<KIID&>( sheet->m_Uuid ) = KIID();
|
2021-04-19 02:14:15 +00:00
|
|
|
|
|
|
|
// Make sure pins get a new UUID
|
|
|
|
for( SCH_SHEET_PIN* pin : sheet->GetPins() )
|
|
|
|
const_cast<KIID&>( pin->m_Uuid ) = KIID();
|
2021-05-01 22:56:37 +00:00
|
|
|
|
|
|
|
// Once we have our new KIID we can update all pasted instances. This will either
|
|
|
|
// reset the annotations or copy "kept" annotations from the supplementary clipboard.
|
|
|
|
for( SCH_SHEET_PATH& instance : pasteInstances )
|
|
|
|
{
|
|
|
|
SCH_SHEET_PATH sheetPath = updatePastedSheet( instance, clipPath, sheet,
|
|
|
|
forceKeepAnnotations,
|
|
|
|
&pastedSheets[instance],
|
|
|
|
&pastedSymbols[instance] );
|
|
|
|
|
|
|
|
sheetPath.GetSymbols( pastedSymbols[instance] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Everything gets a new KIID
|
|
|
|
const_cast<KIID&>( item->m_Uuid ) = KIID();
|
2019-05-03 11:49:59 +00:00
|
|
|
}
|
2019-04-23 13:06:37 +00:00
|
|
|
|
2021-05-30 21:04:07 +00:00
|
|
|
item->SetFlags( IS_NEW | IS_PASTED | IS_MOVING );
|
2020-07-13 11:21:40 +00:00
|
|
|
m_frame->AddItemToScreenAndUndoList( m_frame->GetScreen(), (SCH_ITEM*) item, i > 0 );
|
2019-05-06 15:58:53 +00:00
|
|
|
|
|
|
|
// Reset flags for subsequent move operation
|
2021-05-30 21:04:07 +00:00
|
|
|
item->SetFlags( IS_NEW | IS_PASTED | IS_MOVING );
|
2019-08-29 22:55:25 +00:00
|
|
|
// Start out hidden so the pasted items aren't "ghosted" in their original location
|
|
|
|
// before being moved to the current location.
|
|
|
|
getView()->Hide( item, true );
|
2019-04-28 16:36:31 +00:00
|
|
|
}
|
2019-04-23 13:06:37 +00:00
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
pasteInstances.SortByPageNumbers();
|
2021-05-01 22:39:16 +00:00
|
|
|
|
2021-05-01 22:44:22 +00:00
|
|
|
if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS )
|
2021-05-01 22:39:16 +00:00
|
|
|
{
|
|
|
|
for( SCH_SHEET_PATH& instance : pasteInstances )
|
|
|
|
{
|
|
|
|
pastedSymbols[instance].SortByReferenceOnly();
|
|
|
|
pastedSymbols[instance].ReannotateDuplicates( existingRefs );
|
|
|
|
pastedSymbols[instance].UpdateAnnotation();
|
|
|
|
|
|
|
|
// Update existing refs for next iteration
|
|
|
|
for( size_t i = 0; i < pastedSymbols[instance].GetCount(); i++ )
|
|
|
|
existingRefs.AddItem( pastedSymbols[instance][i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
m_frame->GetCurrentSheet().UpdateAllScreenReferences();
|
|
|
|
|
2019-05-03 11:49:59 +00:00
|
|
|
if( sheetsPasted )
|
2019-10-24 17:07:01 +00:00
|
|
|
{
|
2021-05-01 22:56:37 +00:00
|
|
|
// Update page numbers: Find next free numeric page number
|
|
|
|
for( SCH_SHEET_PATH& instance : pasteInstances )
|
|
|
|
{
|
|
|
|
pastedSheets[instance].SortByPageNumbers();
|
|
|
|
|
|
|
|
for( SCH_SHEET_PATH& pastedSheet : pastedSheets[instance] )
|
|
|
|
{
|
|
|
|
int page = 1;
|
|
|
|
wxString pageNum = wxString::Format( "%d", page );
|
|
|
|
|
|
|
|
while( hierarchy.PageNumberExists( pageNum ) )
|
|
|
|
pageNum = wxString::Format( "%d", ++page );
|
|
|
|
|
|
|
|
pastedSheet.SetPageNumber( pageNum );
|
|
|
|
hierarchy.push_back( pastedSheet );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-03 11:49:59 +00:00
|
|
|
m_frame->SetSheetNumberAndCount();
|
2019-10-24 17:07:01 +00:00
|
|
|
m_frame->UpdateHierarchyNavigator();
|
|
|
|
}
|
2019-04-28 16:36:31 +00:00
|
|
|
|
|
|
|
// Now clear the previous selection, select the pasted items, and fire up the "move"
|
|
|
|
// tool.
|
|
|
|
//
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::addItemsToSel, true, &loadedItems );
|
2019-04-28 16:36:31 +00:00
|
|
|
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& selection = selTool->GetSelection();
|
2019-04-28 16:36:31 +00:00
|
|
|
|
|
|
|
if( !selection.Empty() )
|
|
|
|
{
|
|
|
|
SCH_ITEM* item = (SCH_ITEM*) selection.GetTopLeftItem();
|
|
|
|
|
|
|
|
selection.SetReferencePoint( item->GetPosition() );
|
2019-05-10 17:19:48 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::move, false );
|
2019-04-28 16:36:31 +00:00
|
|
|
}
|
2019-04-23 13:06:37 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-14 18:29:27 +00:00
|
|
|
int SCH_EDITOR_CONTROL::EditWithSymbolEditor( const TOOL_EVENT& aEvent )
|
2019-04-29 22:24:30 +00:00
|
|
|
{
|
2019-05-10 17:19:48 +00:00
|
|
|
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION& selection = selTool->RequestSelection( EE_COLLECTOR::ComponentsOnly );
|
2021-02-16 21:00:12 +00:00
|
|
|
SCH_COMPONENT* symbol = nullptr;
|
2020-10-31 01:27:16 +00:00
|
|
|
SYMBOL_EDIT_FRAME* symbolEditor;
|
2019-04-29 22:24:30 +00:00
|
|
|
|
|
|
|
if( selection.GetSize() >= 1 )
|
2021-02-16 21:00:12 +00:00
|
|
|
symbol = (SCH_COMPONENT*) selection.Front();
|
2019-04-29 22:24:30 +00:00
|
|
|
|
2021-02-16 21:00:12 +00:00
|
|
|
if( !symbol || symbol->GetEditFlags() != 0 )
|
2019-04-29 22:24:30 +00:00
|
|
|
return 0;
|
|
|
|
|
2019-06-06 11:45:28 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::showSymbolEditor, true );
|
2020-10-31 01:27:16 +00:00
|
|
|
symbolEditor = (SYMBOL_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, false );
|
2019-04-29 22:24:30 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
if( symbolEditor )
|
2021-02-16 21:00:12 +00:00
|
|
|
symbolEditor->LoadSymbolFromSchematic( symbol );
|
2019-04-29 22:24:30 +00:00
|
|
|
|
2019-05-13 20:42:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-01 15:28:39 +00:00
|
|
|
int SCH_EDITOR_CONTROL::Annotate( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
wxCommandEvent dummy;
|
|
|
|
m_frame->OnAnnotate( dummy );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::ShowCvpcb( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
wxCommandEvent dummy;
|
|
|
|
m_frame->OnOpenCvpcb( dummy );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::EditSymbolFields( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
DIALOG_FIELDS_EDITOR_GLOBAL dlg( m_frame );
|
|
|
|
dlg.ShowQuasiModal();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-01 18:36:49 +00:00
|
|
|
int SCH_EDITOR_CONTROL::EditSymbolLibraryLinks( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-07-09 11:38:10 +00:00
|
|
|
if( InvokeDialogEditComponentsLibId( m_frame ) )
|
|
|
|
m_frame->HardRedraw();
|
|
|
|
|
2019-06-01 18:36:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-01 15:28:39 +00:00
|
|
|
int SCH_EDITOR_CONTROL::ShowPcbNew( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
wxCommandEvent dummy;
|
|
|
|
m_frame->OnOpenPcbnew( dummy );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::UpdatePCB( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
wxCommandEvent dummy;
|
|
|
|
m_frame->OnUpdatePCB( dummy );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-29 16:33:57 +00:00
|
|
|
int SCH_EDITOR_CONTROL::UpdateFromPCB( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
DIALOG_UPDATE_FROM_PCB dlg( m_frame );
|
|
|
|
dlg.ShowModal();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-16 13:42:40 +00:00
|
|
|
int SCH_EDITOR_CONTROL::ExportNetlist( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
int result = NET_PLUGIN_CHANGE;
|
|
|
|
|
|
|
|
// If a plugin is removed or added, rebuild and reopen the new dialog
|
|
|
|
while( result == NET_PLUGIN_CHANGE )
|
|
|
|
result = InvokeDialogNetList( m_frame );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-01 15:28:39 +00:00
|
|
|
int SCH_EDITOR_CONTROL::GenerateBOM( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
InvokeDialogCreateBOM( m_frame );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-16 16:07:15 +00:00
|
|
|
int SCH_EDITOR_CONTROL::DrawSheetOnClipboard( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_frame->DrawCurrentSheetToClipboard();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-01 15:28:39 +00:00
|
|
|
int SCH_EDITOR_CONTROL::ShowBusManager( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
InvokeDialogBusManager( m_frame );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-30 14:46:29 +00:00
|
|
|
int SCH_EDITOR_CONTROL::EnterSheet( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2019-06-08 21:48:22 +00:00
|
|
|
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
|
|
|
const EE_SELECTION& selection = selTool->RequestSelection( EE_COLLECTOR::SheetsOnly );
|
2019-04-30 14:46:29 +00:00
|
|
|
|
|
|
|
if( selection.GetSize() == 1 )
|
|
|
|
{
|
2019-06-13 21:04:31 +00:00
|
|
|
SCH_SHEET* sheet = (SCH_SHEET*) selection.Front();
|
|
|
|
|
|
|
|
m_toolMgr->RunAction( ACTIONS::cancelInteractive, true );
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
|
2021-01-17 08:41:49 +00:00
|
|
|
// Store the current zoom level into the current screen before switching
|
|
|
|
m_frame->GetScreen()->m_LastZoomLevel = m_frame->GetCanvas()->GetView()->GetScale();
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
m_frame->GetCurrentSheet().push_back( sheet );
|
2019-04-30 14:46:29 +00:00
|
|
|
m_frame->DisplayCurrentSheet();
|
2019-10-24 17:07:01 +00:00
|
|
|
m_frame->UpdateHierarchyNavigator();
|
2019-04-30 14:46:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::LeaveSheet( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2020-05-13 02:00:37 +00:00
|
|
|
if( m_frame->GetCurrentSheet().Last() != &m_frame->Schematic().Root() )
|
2019-04-30 14:46:29 +00:00
|
|
|
{
|
2019-06-13 21:04:31 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::cancelInteractive, true );
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection, true );
|
|
|
|
|
2021-01-17 08:41:49 +00:00
|
|
|
// Store the current zoom level into the current screen before switching
|
|
|
|
m_frame->GetScreen()->m_LastZoomLevel = m_frame->GetCanvas()->GetView()->GetScale();
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
m_frame->GetCurrentSheet().pop_back();
|
2019-04-30 14:46:29 +00:00
|
|
|
m_frame->DisplayCurrentSheet();
|
2019-10-24 17:07:01 +00:00
|
|
|
m_frame->UpdateHierarchyNavigator();
|
2019-04-30 14:46:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-13 20:42:40 +00:00
|
|
|
int SCH_EDITOR_CONTROL::ToggleHiddenPins( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2020-04-12 23:09:17 +00:00
|
|
|
EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
|
|
|
|
cfg->m_Appearance.show_hidden_pins = !cfg->m_Appearance.show_hidden_pins;
|
2019-05-13 20:42:40 +00:00
|
|
|
|
2020-03-29 12:22:22 +00:00
|
|
|
KIGFX::SCH_PAINTER* painter = static_cast<KIGFX::SCH_PAINTER*>( getView()->GetPainter() );
|
2019-05-13 20:42:40 +00:00
|
|
|
painter->GetSettings()->m_ShowHiddenPins = m_frame->GetShowAllPins();
|
|
|
|
|
|
|
|
getView()->UpdateAllItems( KIGFX::REPAINT );
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-18 15:36:29 +00:00
|
|
|
int SCH_EDITOR_CONTROL::ToggleHiddenFields( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
|
|
|
|
cfg->m_Appearance.show_hidden_fields = !cfg->m_Appearance.show_hidden_fields;
|
|
|
|
|
|
|
|
KIGFX::SCH_PAINTER* painter = static_cast<KIGFX::SCH_PAINTER*>( getView()->GetPainter() );
|
|
|
|
painter->GetSettings()->m_ShowHiddenText = cfg->m_Appearance.show_hidden_fields;
|
|
|
|
|
|
|
|
getView()->UpdateAllItems( KIGFX::REPAINT );
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-13 21:49:05 +00:00
|
|
|
int SCH_EDITOR_CONTROL::ToggleForceHV( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2020-04-12 23:09:17 +00:00
|
|
|
m_frame->eeconfig()->m_Drawing.hv_lines_only = !m_frame->eeconfig()->m_Drawing.hv_lines_only;
|
2019-05-13 21:49:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 13:28:04 +00:00
|
|
|
int SCH_EDITOR_CONTROL::TogglePythonConsole( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
|
|
|
|
m_frame->ScriptingConsoleEnableDisable();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-14 00:44:05 +00:00
|
|
|
void SCH_EDITOR_CONTROL::setTransitions()
|
|
|
|
{
|
2019-05-24 23:36:31 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::New, ACTIONS::doNew.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::Open, ACTIONS::open.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::SaveAs, ACTIONS::saveAs.MakeEvent() );
|
2020-03-10 18:46:57 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::ShowSchematicSetup, EE_ACTIONS::schematicSetup.MakeEvent() );
|
2019-05-26 15:36:40 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::PageSetup, ACTIONS::pageSettings.MakeEvent() );
|
2019-05-24 23:36:31 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::Print, ACTIONS::print.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::Quit, ACTIONS::quit.MakeEvent() );
|
|
|
|
|
2020-05-12 17:12:38 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::RescueSymbols, EE_ACTIONS::rescueSymbols.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::RemapSymbols, EE_ACTIONS::remapSymbols.MakeEvent() );
|
|
|
|
|
2019-05-19 21:04:04 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::FindAndReplace, ACTIONS::find.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::FindAndReplace, ACTIONS::findAndReplace.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::FindNext, ACTIONS::findNext.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::FindNext, ACTIONS::findNextMarker.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::ReplaceAndFindNext, ACTIONS::replaceAndFindNext.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::ReplaceAll, ACTIONS::replaceAll.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::UpdateFind, ACTIONS::updateFind.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::UpdateFind, EVENTS::SelectedItemsModified );
|
|
|
|
|
2019-04-30 18:36:11 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::CrossProbeToPcb, EVENTS::SelectedEvent );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::CrossProbeToPcb, EVENTS::UnselectedEvent );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::CrossProbeToPcb, EVENTS::ClearedEvent );
|
2019-05-10 17:19:48 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::ExplicitCrossProbeToPcb, EE_ACTIONS::explicitCrossProbe.MakeEvent() );
|
2019-04-29 21:17:26 +00:00
|
|
|
|
2019-04-23 17:12:26 +00:00
|
|
|
#ifdef KICAD_SPICE
|
2019-05-10 17:19:48 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::SimProbe, EE_ACTIONS::simProbe.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::SimTune, EE_ACTIONS::simTune.MakeEvent() );
|
2019-04-23 17:12:26 +00:00
|
|
|
#endif /* KICAD_SPICE */
|
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::HighlightNet, EE_ACTIONS::highlightNet.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::ClearHighlight, EE_ACTIONS::clearHighlight.MakeEvent() );
|
2019-07-26 15:28:59 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::HighlightNetCursor, EE_ACTIONS::highlightNetTool.MakeEvent() );
|
2019-05-12 17:03:17 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::UpdateNetHighlighting, EVENTS::SelectedItemsModified );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::UpdateNetHighlighting, EE_ACTIONS::updateNetHighlighting.MakeEvent() );
|
2019-06-27 11:47:24 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::ClearHighlight, ACTIONS::cancelInteractive.MakeEvent() );
|
2019-04-23 13:06:37 +00:00
|
|
|
|
2020-07-07 10:17:30 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::AssignNetclass, EE_ACTIONS::assignNetclass.MakeEvent() );
|
|
|
|
|
2019-05-14 19:21:10 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::Undo, ACTIONS::undo.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::Redo, ACTIONS::redo.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::Cut, ACTIONS::cut.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::Copy, ACTIONS::copy.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::Paste, ACTIONS::paste.MakeEvent() );
|
2019-09-02 18:23:46 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::Paste, ACTIONS::pasteSpecial.MakeEvent() );
|
2021-05-21 16:43:34 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::Duplicate, ACTIONS::duplicate.MakeEvent() );
|
2019-04-29 22:24:30 +00:00
|
|
|
|
2021-02-14 18:29:27 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::EditWithSymbolEditor, EE_ACTIONS::editWithLibEdit.MakeEvent() );
|
2019-06-01 15:28:39 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::ShowCvpcb, EE_ACTIONS::assignFootprints.MakeEvent() );
|
2019-06-16 16:07:15 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::ImportFPAssignments, EE_ACTIONS::importFPAssignments.MakeEvent() );
|
2019-06-01 15:28:39 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::Annotate, EE_ACTIONS::annotate.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::EditSymbolFields, EE_ACTIONS::editSymbolFields.MakeEvent() );
|
2019-06-01 18:36:49 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::EditSymbolLibraryLinks,EE_ACTIONS::editSymbolLibraryLinks.MakeEvent() );
|
2019-06-01 15:28:39 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::ShowPcbNew, EE_ACTIONS::showPcbNew.MakeEvent() );
|
2019-06-03 13:49:17 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::UpdatePCB, ACTIONS::updatePcbFromSchematic.MakeEvent() );
|
2020-01-29 16:33:57 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::UpdateFromPCB, ACTIONS::updateSchematicFromPcb.MakeEvent() );
|
2019-06-16 13:42:40 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::ExportNetlist, EE_ACTIONS::exportNetlist.MakeEvent() );
|
2019-06-01 15:28:39 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::GenerateBOM, EE_ACTIONS::generateBOM.MakeEvent() );
|
2019-06-16 16:07:15 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::DrawSheetOnClipboard, EE_ACTIONS::drawSheetOnClipboard.MakeEvent() );
|
2019-06-01 15:28:39 +00:00
|
|
|
|
|
|
|
Go( &SCH_EDITOR_CONTROL::ShowBusManager, EE_ACTIONS::showBusManager.MakeEvent() );
|
2019-04-30 14:46:29 +00:00
|
|
|
|
2019-05-10 17:19:48 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::EnterSheet, EE_ACTIONS::enterSheet.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::LeaveSheet, EE_ACTIONS::leaveSheet.MakeEvent() );
|
2019-05-13 20:42:40 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::NavigateHierarchy, EE_ACTIONS::navigateHierarchy.MakeEvent() );
|
|
|
|
|
|
|
|
Go( &SCH_EDITOR_CONTROL::ToggleHiddenPins, EE_ACTIONS::toggleHiddenPins.MakeEvent() );
|
2020-04-18 15:36:29 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::ToggleHiddenFields, EE_ACTIONS::toggleHiddenFields.MakeEvent() );
|
2019-05-13 21:49:05 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::ToggleForceHV, EE_ACTIONS::toggleForceHV.MakeEvent() );
|
2021-03-18 13:28:04 +00:00
|
|
|
|
|
|
|
Go( &SCH_EDITOR_CONTROL::TogglePythonConsole, EE_ACTIONS::showPythonConsole.MakeEvent() );
|
2019-04-14 00:44:05 +00:00
|
|
|
}
|