2019-04-14 00:44:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-11-05 12:19:51 +00:00
|
|
|
* Copyright (C) 2019-2023 CERN
|
2024-01-06 12:56:16 +00:00
|
|
|
* Copyright (C) 1992-2024 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
|
|
|
|
*/
|
|
|
|
|
2021-06-15 13:24:55 +00:00
|
|
|
#include <symbol_library.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <confirm.h>
|
|
|
|
#include <connection_graph.h>
|
2021-07-03 20:43:30 +00:00
|
|
|
#include <dialogs/dialog_symbol_fields_table.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>
|
2022-08-14 11:03:18 +00:00
|
|
|
#include <dialogs/dialog_assign_netclass.h>
|
2023-06-09 16:24:49 +00:00
|
|
|
#include <dialogs/dialog_update_from_pcb.h>
|
2023-05-31 02:06:49 +00:00
|
|
|
#include <dialogs/hotkey_cycle_popup.h>
|
2020-05-12 17:12:38 +00:00
|
|
|
#include <project_rescue.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <erc.h>
|
|
|
|
#include <invoke_sch_dialog.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2019-04-23 17:12:26 +00:00
|
|
|
#include <kiway.h>
|
2022-04-12 14:37:06 +00:00
|
|
|
#include <netlist_exporters/netlist_exporter_spice.h>
|
2022-09-16 03:06:23 +00:00
|
|
|
#include <paths.h>
|
2023-05-31 02:06:49 +00:00
|
|
|
#include <pgm_base.h>
|
2020-07-07 10:17:30 +00:00
|
|
|
#include <project/project_file.h>
|
|
|
|
#include <project/net_settings.h>
|
2023-09-28 03:04:53 +00:00
|
|
|
#include <project_sch.h>
|
2019-04-14 00:44:05 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2023-12-24 00:31:24 +00:00
|
|
|
#include <sch_io/kicad_sexpr/sch_io_kicad_sexpr.h>
|
2019-08-12 14:42:11 +00:00
|
|
|
#include <sch_line.h>
|
2022-11-29 15:17:38 +00:00
|
|
|
#include <sch_junction.h>
|
|
|
|
#include <sch_bus_entry.h>
|
2022-10-03 22:28:21 +00:00
|
|
|
#include <sch_shape.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>
|
2023-06-09 21:41:33 +00:00
|
|
|
#include <sch_commit.h>
|
2023-05-31 02:06:49 +00:00
|
|
|
#include <advanced_config.h>
|
|
|
|
#include <settings/common_settings.h>
|
2023-03-03 22:36:07 +00:00
|
|
|
#include <sim/simulator_frame.h>
|
2022-09-15 03:25:57 +00:00
|
|
|
#include <sim/spice_generator.h>
|
2022-10-05 15:18:33 +00:00
|
|
|
#include <sim/sim_lib_mgr.h>
|
2023-06-09 16:24:49 +00:00
|
|
|
#include <symbol_library_manager.h>
|
2020-12-25 23:37:01 +00:00
|
|
|
#include <symbol_viewer_frame.h>
|
2023-05-31 02:06:49 +00:00
|
|
|
#include <tool/common_tools.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>
|
2023-06-09 16:24:49 +00:00
|
|
|
#include <tools/sch_move_tool.h>
|
2021-02-22 23:47:17 +00:00
|
|
|
#include <drawing_sheet/ds_proxy_undo_item.h>
|
2021-08-03 00:11:11 +00:00
|
|
|
#include <eda_list_dialog.h>
|
2021-09-27 16:22:46 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2022-08-14 17:36:40 +00:00
|
|
|
#include <wx_filename.h>
|
2021-09-27 16:22:46 +00:00
|
|
|
#include <sch_sheet_path.h>
|
|
|
|
#include <wx/filedlg.h>
|
2023-05-20 17:47:12 +00:00
|
|
|
#include <wx/treectrl.h>
|
2024-02-03 13:43:41 +00:00
|
|
|
#include "sch_edit_table_tool.h"
|
2021-09-27 16:22:46 +00:00
|
|
|
|
2024-01-20 23:35:29 +00:00
|
|
|
#ifdef KICAD_IPC_API
|
|
|
|
#include <api/api_plugin_manager.h>
|
|
|
|
#endif
|
|
|
|
|
2020-08-31 15:06:23 +00:00
|
|
|
|
2024-03-13 14:48:44 +00:00
|
|
|
/**
|
|
|
|
* Flag to enable schematic paste debugging output.
|
|
|
|
*
|
|
|
|
* @ingroup trace_env_vars
|
|
|
|
*/
|
|
|
|
static const wxChar traceSchPaste[] = wxT( "KICAD_SCH_PASTE" );
|
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2021-08-24 03:01:08 +00:00
|
|
|
m_frame->SaveProject( true );
|
2019-05-24 23:36:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-27 16:22:46 +00:00
|
|
|
int SCH_EDITOR_CONTROL::SaveCurrSheetCopyAs( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
SCH_SHEET* curr_sheet = m_frame->GetCurrentSheet().Last();
|
|
|
|
wxFileName curr_fn = curr_sheet->GetFileName();
|
2023-12-28 02:10:01 +00:00
|
|
|
wxFileDialog dlg( m_frame, _( "Schematic Files" ), curr_fn.GetPath(), curr_fn.GetFullName(),
|
|
|
|
FILEEXT::KiCadSchematicFileWildcard(),
|
2021-09-27 16:22:46 +00:00
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return false;
|
|
|
|
|
2023-12-28 02:10:01 +00:00
|
|
|
wxString newFilename =
|
|
|
|
EnsureFileExtension( dlg.GetPath(), FILEEXT::KiCadSchematicFileExtension );
|
2021-09-27 16:22:46 +00:00
|
|
|
|
2023-03-12 14:49:57 +00:00
|
|
|
m_frame->saveSchematicFile( curr_sheet, newFilename );
|
2021-09-27 16:22:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-17 17:14:50 +00:00
|
|
|
int SCH_EDITOR_CONTROL::Revert( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
SCHEMATIC& schematic = m_frame->Schematic();
|
|
|
|
SCH_SHEET& root = schematic.Root();
|
|
|
|
|
|
|
|
if( m_frame->GetCurrentSheet().Last() != &root )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::cancelInteractive );
|
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2022-04-17 17:14:50 +00:00
|
|
|
|
|
|
|
// Store the current zoom level into the current screen before switching
|
|
|
|
m_frame->GetScreen()->m_LastZoomLevel = m_frame->GetCanvas()->GetView()->GetScale();
|
|
|
|
|
|
|
|
SCH_SHEET_PATH rootSheetPath;
|
|
|
|
rootSheetPath.push_back( &root );
|
|
|
|
m_frame->SetCurrentSheet( rootSheetPath );
|
|
|
|
m_frame->DisplayCurrentSheet();
|
|
|
|
|
|
|
|
wxSafeYield();
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Revert '%s' (and all sub-sheets) to last version saved?" ),
|
|
|
|
schematic.GetFileName() );
|
|
|
|
|
|
|
|
if( !IsOK( m_frame, msg ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
SCH_SCREENS screenList( schematic.Root() );
|
|
|
|
|
|
|
|
for( SCH_SCREEN* screen = screenList.GetFirst(); screen; screen = screenList.GetNext() )
|
|
|
|
screen->SetContentModified( false ); // do not prompt the user for changes
|
|
|
|
|
2022-04-26 21:28:10 +00:00
|
|
|
m_frame->ReleaseFile();
|
2023-11-05 12:19:51 +00:00
|
|
|
m_frame->OpenProjectFiles( std::vector<wxString>( 1, schematic.GetFileName() ), KICTL_REVERT );
|
2022-04-17 17:14:50 +00:00
|
|
|
|
|
|
|
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 );
|
2023-08-27 16:11:23 +00:00
|
|
|
undoCmd.SetDescription( _( "Page Settings" ) );
|
2022-03-16 13:43:19 +00:00
|
|
|
m_frame->SaveCopyInUndoList( undoCmd, UNDO_REDO::PAGESETTINGS, false, false );
|
2019-05-26 15:36:40 +00:00
|
|
|
|
2023-02-19 03:40:07 +00:00
|
|
|
DIALOG_EESCHEMA_PAGE_SETTINGS dlg( m_frame, VECTOR2I( MAX_PAGE_SIZE_EESCHEMA_MILS,
|
|
|
|
MAX_PAGE_SIZE_EESCHEMA_MILS ) );
|
2021-05-30 22:56:24 +00:00
|
|
|
dlg.SetWksFileName( BASE_SCREEN::m_DrawingSheetFileName );
|
2019-05-26 15:36:40 +00:00
|
|
|
|
2023-01-22 12:17:05 +00:00
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
2022-02-04 00:12:59 +00:00
|
|
|
{
|
|
|
|
// Update text variables
|
|
|
|
m_frame->GetCanvas()->GetView()->MarkDirty();
|
|
|
|
m_frame->GetCanvas()->GetView()->UpdateAllItems( KIGFX::REPAINT );
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
|
2021-12-06 23:07:46 +00:00
|
|
|
m_frame->OnModify();
|
2022-02-04 00:12:59 +00:00
|
|
|
}
|
2021-12-06 23:07:46 +00:00
|
|
|
else
|
2022-02-04 00:12:59 +00:00
|
|
|
{
|
2019-05-26 15:36:40 +00:00
|
|
|
m_frame->RollbackSchematicFromUndo();
|
2022-02-04 00:12:59 +00:00
|
|
|
}
|
2019-05-26 15:36:40 +00:00
|
|
|
|
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();
|
2023-06-09 16:24:49 +00:00
|
|
|
m_frame->RecalculateConnections( nullptr, GLOBAL_CLEANUP );
|
2020-05-12 17:12:38 +00:00
|
|
|
}
|
|
|
|
|
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 );
|
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() )
|
2023-03-04 19:25:07 +00:00
|
|
|
m_frame->OnModify();
|
2020-05-12 17:12:38 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 -> ...
|
2022-07-19 15:00:35 +00:00
|
|
|
if( m_probingPcbToSch || m_frame->IsSyncingSelection() )
|
2019-04-30 18:36:11 +00:00
|
|
|
return;
|
2019-04-21 23:45:34 +00:00
|
|
|
|
2022-01-16 20:29:03 +00:00
|
|
|
EE_SELECTION_TOOL* selTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
2019-04-30 18:36:11 +00:00
|
|
|
|
2022-01-16 20:29:03 +00:00
|
|
|
EE_SELECTION& selection = aForce ? selTool->RequestSelection() : selTool->GetSelection();
|
2019-04-30 18:36:11 +00:00
|
|
|
|
2022-09-20 19:06:11 +00:00
|
|
|
m_frame->SendSelectItemsToPcb( selection.GetItemsSortedBySelectionOrder(), aForce );
|
2019-04-21 23:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-16 03:06:23 +00:00
|
|
|
int SCH_EDITOR_CONTROL::ExportSymbolsToLibrary( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2023-12-26 17:49:34 +00:00
|
|
|
bool savePowerSymbols = IsOK( m_frame,
|
|
|
|
_( "Include power symbols in schematic to the library?" ) );
|
2023-12-04 17:12:51 +00:00
|
|
|
|
2022-09-16 03:06:23 +00:00
|
|
|
bool createNew = aEvent.IsAction( &EE_ACTIONS::exportSymbolsToNewLibrary );
|
|
|
|
|
|
|
|
SCH_REFERENCE_LIST symbols;
|
2023-12-04 17:12:51 +00:00
|
|
|
m_frame->Schematic().GetSheets().GetSymbols( symbols, savePowerSymbols );
|
2022-09-16 03:06:23 +00:00
|
|
|
|
|
|
|
std::map<LIB_ID, LIB_SYMBOL*> libSymbols;
|
|
|
|
std::map<LIB_ID, std::vector<SCH_SYMBOL*>> symbolMap;
|
|
|
|
|
|
|
|
for( size_t i = 0; i < symbols.GetCount(); ++i )
|
|
|
|
{
|
|
|
|
SCH_SYMBOL* symbol = symbols[i].GetSymbol();
|
|
|
|
LIB_SYMBOL* libSymbol = symbol->GetLibSymbolRef().get();
|
|
|
|
LIB_ID id = libSymbol->GetLibId();
|
|
|
|
|
|
|
|
if( libSymbols.count( id ) )
|
|
|
|
{
|
2024-04-06 13:14:44 +00:00
|
|
|
wxASSERT_MSG( libSymbols[id]->Compare( *libSymbol, SCH_ITEM::COMPARE_FLAGS::ERC ) == 0,
|
2022-09-16 03:06:23 +00:00
|
|
|
"Two symbols have the same LIB_ID but are different!" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
libSymbols[id] = libSymbol;
|
|
|
|
}
|
|
|
|
|
|
|
|
symbolMap[id].emplace_back( symbol );
|
|
|
|
}
|
|
|
|
|
|
|
|
SYMBOL_LIBRARY_MANAGER mgr( *m_frame );
|
|
|
|
|
|
|
|
wxString targetLib;
|
|
|
|
|
|
|
|
if( createNew )
|
|
|
|
{
|
|
|
|
wxFileName fn;
|
|
|
|
SYMBOL_LIB_TABLE* libTable = m_frame->SelectSymLibTable();
|
|
|
|
|
2023-07-27 13:12:41 +00:00
|
|
|
if( !libTable ) // Cancelled by user
|
|
|
|
return 0;
|
|
|
|
|
2023-12-28 02:10:01 +00:00
|
|
|
if( !m_frame->LibraryFileBrowser( false, fn, FILEEXT::KiCadSymbolLibFileWildcard(),
|
|
|
|
FILEEXT::KiCadSymbolLibFileExtension, false,
|
2022-09-16 03:06:23 +00:00
|
|
|
( libTable == &SYMBOL_LIB_TABLE::GetGlobalLibTable() ),
|
|
|
|
PATHS::GetDefaultUserSymbolsPath() ) )
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
targetLib = fn.GetName();
|
|
|
|
|
|
|
|
if( libTable->HasLibrary( targetLib, false ) )
|
|
|
|
{
|
|
|
|
DisplayError( m_frame, wxString::Format( _( "Library '%s' already exists." ),
|
|
|
|
targetLib ) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-02-05 17:41:00 +00:00
|
|
|
// if the "new" library is in fact an existing library and the used asked for replacing
|
|
|
|
// it by the recreated lib, erase it:
|
|
|
|
if( fn.FileExists() )
|
|
|
|
wxRemoveFile( fn.GetFullPath() );
|
|
|
|
|
2022-09-16 03:06:23 +00:00
|
|
|
if( !mgr.CreateLibrary( fn.GetFullPath(), libTable ) )
|
|
|
|
{
|
2023-02-05 18:39:53 +00:00
|
|
|
DisplayError( m_frame, wxString::Format( _( "Could not add library '%s'." ),
|
2022-09-16 03:06:23 +00:00
|
|
|
targetLib ) );
|
2023-02-05 18:39:53 +00:00
|
|
|
return 0;
|
2022-09-16 03:06:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
targetLib = m_frame->SelectLibraryFromList();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( targetLib.IsEmpty() )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bool map = IsOK( m_frame, _( "Update symbols in schematic to refer to new library?" ) );
|
2023-01-12 00:04:24 +00:00
|
|
|
bool append = false;
|
2022-09-16 03:06:23 +00:00
|
|
|
|
|
|
|
SYMBOL_LIB_TABLE_ROW* row = mgr.GetLibrary( targetLib );
|
|
|
|
SCH_IO_MGR::SCH_FILE_T type = SCH_IO_MGR::EnumFromStr( row->GetType() );
|
2023-12-27 20:39:29 +00:00
|
|
|
IO_RELEASER<SCH_IO> pi( SCH_IO_MGR::FindPlugin( type ) );
|
2022-09-16 03:06:23 +00:00
|
|
|
|
|
|
|
wxFileName dest = row->GetFullURI( true );
|
|
|
|
dest.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS );
|
|
|
|
|
|
|
|
for( const std::pair<const LIB_ID, LIB_SYMBOL*>& it : libSymbols )
|
|
|
|
{
|
|
|
|
LIB_SYMBOL* origSym = it.second;
|
|
|
|
LIB_SYMBOL* newSym = origSym->Flatten().release();
|
|
|
|
|
2023-12-26 17:49:34 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
pi->SaveSymbol( dest.GetFullPath(), newSym );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Error saving symbol %s to library '%s'." ),
|
|
|
|
newSym->GetName(), row->GetNickName() );
|
|
|
|
msg += wxS( "\n\n" ) + ioe.What();
|
|
|
|
wxLogWarning( msg );
|
|
|
|
return 0;
|
|
|
|
}
|
2022-09-16 03:06:23 +00:00
|
|
|
|
|
|
|
if( map )
|
|
|
|
{
|
|
|
|
LIB_ID id = it.first;
|
|
|
|
id.SetLibNickname( targetLib );
|
|
|
|
|
|
|
|
for( SCH_SYMBOL* symbol : symbolMap[it.first] )
|
2023-01-12 00:04:24 +00:00
|
|
|
{
|
2023-05-20 17:47:12 +00:00
|
|
|
m_frame->SaveCopyInUndoList( m_frame->GetScreen(), symbol, UNDO_REDO::CHANGED,
|
|
|
|
append, false );
|
2022-09-16 03:06:23 +00:00
|
|
|
symbol->SetLibId( id );
|
2023-01-12 00:04:24 +00:00
|
|
|
append = true;
|
|
|
|
}
|
2022-09-16 03:06:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-30 21:36:59 +00:00
|
|
|
// Save the modified symbol library table. We need to look this up by name in each table to find
|
|
|
|
// whether the new library is a global or project entity as the code above to choose the library
|
|
|
|
// returns a different type depending on whether a global or project library is chosen.
|
|
|
|
SYMBOL_LIB_TABLE* globalTable = &SYMBOL_LIB_TABLE::GetGlobalLibTable();
|
|
|
|
SYMBOL_LIB_TABLE* projectTable = nullptr;
|
|
|
|
|
|
|
|
if( !m_frame->Prj().IsNullProject() )
|
2023-09-28 03:04:53 +00:00
|
|
|
projectTable = PROJECT_SCH::SchSymbolLibTable( &m_frame->Prj() );
|
2023-01-30 21:36:59 +00:00
|
|
|
|
|
|
|
if( globalTable->FindRow( targetLib ) )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
wxString globalTablePath = SYMBOL_LIB_TABLE::GetGlobalTableFileName();
|
|
|
|
globalTable->Save( globalTablePath );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Error saving global library table:\n\n%s" ), ioe.What() );
|
|
|
|
wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( projectTable && projectTable->FindRow( targetLib ) )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
wxString projectPath = m_frame->Prj().GetProjectPath();
|
|
|
|
wxFileName projectTableFn( projectPath, SYMBOL_LIB_TABLE::GetSymbolLibTableFileName() );
|
|
|
|
projectTable->Save( projectTableFn.GetFullPath() );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Error saving project-specific library table:\n\n%s" ), ioe.What() );
|
|
|
|
wxMessageBox( msg, _( "File Save Error" ), wxOK | wxICON_ERROR );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-12 00:04:24 +00:00
|
|
|
if( append )
|
2023-01-30 21:36:59 +00:00
|
|
|
{
|
|
|
|
std::set<SCH_SCREEN*> processedScreens;
|
|
|
|
SCH_SHEET_LIST sheets = m_frame->Schematic().GetSheets();
|
|
|
|
|
|
|
|
for( SCH_SHEET_PATH& sheet : sheets )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = sheet.LastScreen();
|
2023-12-04 17:12:51 +00:00
|
|
|
|
2023-01-30 21:36:59 +00:00
|
|
|
if( processedScreens.find( ( screen ) ) == processedScreens.end() )
|
|
|
|
{
|
|
|
|
processedScreens.insert( screen );
|
|
|
|
screen->UpdateSymbolLinks();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-12 00:04:24 +00:00
|
|
|
m_frame->OnModify();
|
2023-01-30 21:36:59 +00:00
|
|
|
}
|
2023-01-12 00:04:24 +00:00
|
|
|
|
2022-09-16 03:06:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-05 06:47:38 +00:00
|
|
|
#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
|
|
|
{
|
2023-03-03 22:36:07 +00:00
|
|
|
PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
|
2023-05-20 17:47:12 +00:00
|
|
|
SIMULATOR_FRAME* simFrame = (SIMULATOR_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
|
|
|
|
2022-07-12 21:44:53 +00:00
|
|
|
if( wxWindow* blocking_win = simFrame->Kiway().GetBlockingDialog() )
|
|
|
|
blocking_win->Close( true );
|
|
|
|
|
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>();
|
2021-07-06 18:16:00 +00:00
|
|
|
EDA_ITEM* item = selTool->GetNode( aPosition );
|
2022-12-05 02:07:45 +00:00
|
|
|
SCH_SHEET_PATH& sheet = m_frame->GetCurrentSheet();
|
2019-08-05 22:34:47 +00:00
|
|
|
|
2020-11-22 22:21:41 +00:00
|
|
|
if( !item )
|
|
|
|
return false;
|
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
if( item->Type() == SCH_PIN_T )
|
2020-11-22 22:21:41 +00:00
|
|
|
{
|
2022-10-06 07:47:03 +00:00
|
|
|
try
|
|
|
|
{
|
2024-04-20 09:44:34 +00:00
|
|
|
SCH_PIN* pin = static_cast<SCH_PIN*>( item )->GetLibPin();
|
2022-10-06 07:47:03 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item->GetParent() );
|
2022-04-12 14:37:06 +00:00
|
|
|
|
2023-01-12 12:46:52 +00:00
|
|
|
wxString msg;
|
|
|
|
WX_STRING_REPORTER reporter( &msg );
|
2023-09-06 10:37:50 +00:00
|
|
|
SIM_LIB_MGR mgr( &m_frame->Prj() );
|
2023-01-12 12:46:52 +00:00
|
|
|
|
2023-09-06 10:37:50 +00:00
|
|
|
SIM_MODEL& model = mgr.CreateModel( &sheet, *symbol, reporter ).model;
|
2022-04-12 14:37:06 +00:00
|
|
|
|
2023-01-12 12:46:52 +00:00
|
|
|
if( reporter.HasMessage() )
|
|
|
|
THROW_IO_ERROR( msg );
|
|
|
|
|
2022-10-10 23:23:00 +00:00
|
|
|
SPICE_ITEM spiceItem;
|
2023-03-03 22:36:07 +00:00
|
|
|
spiceItem.refName = symbol->GetRef( &sheet ).ToStdString();
|
2022-10-06 07:47:03 +00:00
|
|
|
std::vector<std::string> currentNames =
|
2022-10-10 23:23:00 +00:00
|
|
|
model.SpiceGenerator().CurrentNames( spiceItem );
|
2022-08-22 05:40:23 +00:00
|
|
|
|
2022-10-06 07:47:03 +00:00
|
|
|
if( currentNames.size() == 0 )
|
2023-03-03 22:36:07 +00:00
|
|
|
{
|
2022-10-06 07:47:03 +00:00
|
|
|
return true;
|
2023-03-03 22:36:07 +00:00
|
|
|
}
|
2022-10-06 07:47:03 +00:00
|
|
|
else if( currentNames.size() == 1 )
|
|
|
|
{
|
2023-03-03 22:36:07 +00:00
|
|
|
simFrame->AddCurrentTrace( currentNames.at( 0 ) );
|
2022-10-06 07:47:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
2022-04-12 14:37:06 +00:00
|
|
|
|
2023-03-03 22:36:07 +00:00
|
|
|
int modelPinIndex = model.FindModelPinIndex( pin->GetNumber().ToStdString() );
|
2022-04-12 14:37:06 +00:00
|
|
|
|
2022-10-06 07:47:03 +00:00
|
|
|
if( modelPinIndex != SIM_MODEL::PIN::NOT_CONNECTED )
|
|
|
|
{
|
|
|
|
wxString name = currentNames.at( modelPinIndex );
|
2023-03-03 22:36:07 +00:00
|
|
|
simFrame->AddCurrentTrace( name );
|
2022-10-06 07:47:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& e )
|
2022-04-12 14:37:06 +00:00
|
|
|
{
|
2022-10-06 07:47:03 +00:00
|
|
|
DisplayErrorMessage( m_frame, e.What() );
|
2022-04-12 14:37:06 +00:00
|
|
|
}
|
2020-11-22 22:21:41 +00:00
|
|
|
}
|
2023-01-30 23:13:24 +00:00
|
|
|
else if( item->IsType( { SCH_ITEM_LOCATE_WIRE_T } )
|
|
|
|
|| item->IsType( { SCH_JUNCTION_T } ) )
|
2020-11-22 22:21:41 +00:00
|
|
|
{
|
2022-04-12 14:37:06 +00:00
|
|
|
if( SCH_CONNECTION* conn = static_cast<SCH_ITEM*>( item )->Connection() )
|
|
|
|
{
|
2023-03-03 22:36:07 +00:00
|
|
|
std::string spiceNet = UnescapeString( conn->Name() ).ToStdString();
|
2022-12-11 15:52:48 +00:00
|
|
|
NETLIST_EXPORTER_SPICE::ConvertToSpiceMarkup( spiceNet );
|
2020-11-22 22:21:41 +00:00
|
|
|
|
2023-03-03 22:36:07 +00:00
|
|
|
simFrame->AddVoltageTrace( wxString::Format( "V(%s)", spiceNet ) );
|
2022-04-12 14:37:06 +00:00
|
|
|
}
|
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 ) );
|
2022-08-20 09:27:35 +00:00
|
|
|
collector.Collect( m_frame->GetScreen(), { SCH_ITEM_LOCATE_WIRE_T,
|
|
|
|
SCH_PIN_T,
|
|
|
|
SCH_SHEET_PIN_T }, 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 )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2023-05-17 01:49:55 +00:00
|
|
|
wxString connectionName = ( conn ) ? conn->Name() : wxString( wxS( "" ) );
|
2023-05-17 00:06:21 +00:00
|
|
|
|
|
|
|
if( m_frame->GetHighlightedConnection() != connectionName )
|
2020-11-22 22:21:41 +00:00
|
|
|
{
|
2023-05-17 00:06:21 +00:00
|
|
|
m_frame->SetHighlightedConnection( connectionName );
|
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
|
|
|
|
2023-05-17 00:06:21 +00:00
|
|
|
if( !m_frame->GetHighlightedConnection().IsEmpty() )
|
2020-11-22 22:21:41 +00:00
|
|
|
{
|
2023-05-17 00:06:21 +00:00
|
|
|
m_frame->SetHighlightedConnection( wxEmptyString );
|
2020-11-22 22:21:41 +00:00
|
|
|
|
|
|
|
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
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( EE_ACTIONS::selectionActivate );
|
2020-11-22 22:21:41 +00:00
|
|
|
} );
|
2019-08-05 06:47:38 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::pickerTool, &aEvent );
|
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;
|
2022-08-20 09:27:35 +00:00
|
|
|
selTool->SelectPoint( aPosition, { SCH_SYMBOL_T, SCH_FIELD_T }, &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
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( item->Type() != SCH_SYMBOL_T )
|
2020-11-22 22:21:41 +00:00
|
|
|
{
|
|
|
|
item = item->GetParent();
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( item->Type() != SCH_SYMBOL_T )
|
2020-11-22 22:21:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-07-19 08:12:54 +00:00
|
|
|
|
2022-12-23 22:02:59 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
|
|
|
SCH_SHEET_PATH sheetPath = symbol->Schematic()->CurrentSheet();
|
|
|
|
KIWAY_PLAYER* simFrame = 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 )
|
2022-07-12 21:44:53 +00:00
|
|
|
{
|
|
|
|
if( wxWindow* blocking_win = simFrame->Kiway().GetBlockingDialog() )
|
|
|
|
blocking_win->Close( true );
|
|
|
|
|
2023-03-03 22:36:07 +00:00
|
|
|
static_cast<SIMULATOR_FRAME*>( simFrame )->AddTuner( sheetPath, symbol );
|
2022-07-12 21:44:53 +00:00
|
|
|
}
|
2020-11-22 22:21:41 +00:00
|
|
|
|
2021-10-22 15:40:40 +00:00
|
|
|
// We do not really want to keep a symbol selected in schematic,
|
|
|
|
// so clear the current selection
|
|
|
|
selTool->ClearSelection();
|
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]( const VECTOR2D& aPos )
|
|
|
|
{
|
|
|
|
EE_COLLECTOR collector;
|
|
|
|
collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
|
2022-08-20 09:27:35 +00:00
|
|
|
collector.Collect( m_frame->GetScreen(), { SCH_SYMBOL_T, SCH_FIELD_T }, 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
|
2021-10-22 15:40:40 +00:00
|
|
|
// and deselect previous selection from simulator to avoid any issue
|
|
|
|
// ( avoid crash in some cases when the SimTune tool is deselected )
|
|
|
|
EE_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<EE_SELECTION_TOOL>();
|
|
|
|
selectionTool->ClearSelection();
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( EE_ACTIONS::selectionActivate );
|
2020-11-22 22:21:41 +00:00
|
|
|
} );
|
2019-08-05 06:47:38 +00:00
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::pickerTool, &aEvent );
|
2019-07-15 12:15:58 +00:00
|
|
|
|
2019-04-23 17:12:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2023-06-09 18:34:40 +00:00
|
|
|
SCH_ITEM* item = nullptr;
|
2020-05-24 14:46:05 +00:00
|
|
|
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
|
|
|
|
{
|
2023-06-09 18:34:40 +00:00
|
|
|
item = static_cast<SCH_ITEM*>( selTool->GetNode( aPosition ) );
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
|
2020-04-11 20:55:49 +00:00
|
|
|
|
2020-04-12 10:18:40 +00:00
|
|
|
if( item )
|
|
|
|
{
|
2022-09-25 05:32:12 +00:00
|
|
|
if( item->IsConnectivityDirty() )
|
2023-06-09 16:24:49 +00:00
|
|
|
editFrame->RecalculateConnections( nullptr, NO_CLEANUP );
|
2022-09-25 05:32:12 +00:00
|
|
|
|
2020-04-12 10:18:40 +00:00
|
|
|
if( item->Type() == SCH_FIELD_T )
|
2021-06-10 14:10:55 +00:00
|
|
|
symbol = dynamic_cast<SCH_SYMBOL*>( item->GetParent() );
|
2020-05-24 14:46:05 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
if( symbol && symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-17 12:15:43 +00:00
|
|
|
wxString connName = ( conn ) ? conn->Name() : wxString( wxS( "" ) );
|
2023-05-17 00:06:21 +00:00
|
|
|
|
2023-06-14 13:57:55 +00:00
|
|
|
if( !conn )
|
2019-05-04 20:18:41 +00:00
|
|
|
{
|
|
|
|
editFrame->SetStatusText( wxT( "" ) );
|
|
|
|
editFrame->SendCrossProbeClearHighlight();
|
2023-05-17 00:06:21 +00:00
|
|
|
editFrame->SetHighlightedConnection( wxEmptyString );
|
2023-11-17 12:15:43 +00:00
|
|
|
editorControl->SetHighlightBusMembers( false );
|
2019-05-04 20:18:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-09 18:34:40 +00:00
|
|
|
NET_NAVIGATOR_ITEM_DATA itemData( editFrame->GetCurrentSheet(), item );
|
2023-06-14 13:57:55 +00:00
|
|
|
|
2023-11-17 12:15:43 +00:00
|
|
|
if( connName != editFrame->GetHighlightedConnection() )
|
2023-06-14 13:57:55 +00:00
|
|
|
{
|
2023-11-17 12:15:43 +00:00
|
|
|
editorControl->SetHighlightBusMembers( false );
|
2023-06-14 13:57:55 +00:00
|
|
|
editFrame->SetCrossProbeConnection( conn );
|
2023-11-17 12:15:43 +00:00
|
|
|
editFrame->SetHighlightedConnection( connName, &itemData );
|
2023-06-14 13:57:55 +00:00
|
|
|
}
|
2023-11-17 12:15:43 +00:00
|
|
|
else
|
2023-06-14 13:57:55 +00:00
|
|
|
{
|
2023-11-17 12:15:43 +00:00
|
|
|
editorControl->SetHighlightBusMembers( !editorControl->GetHighlightBusMembers() );
|
|
|
|
|
|
|
|
if( item != editFrame->GetSelectedNetNavigatorItem() )
|
|
|
|
editFrame->SelectNetNavigatorItem( &itemData );
|
2023-06-14 13:57:55 +00:00
|
|
|
}
|
2019-05-04 20:18:41 +00:00
|
|
|
}
|
|
|
|
|
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>();
|
2022-09-03 20:33:56 +00:00
|
|
|
SCHEMATIC& schematic = m_frame->Schematic();
|
|
|
|
SCH_SCREEN* screen = m_frame->GetCurrentSheet().LastScreen();
|
2020-07-07 10:17:30 +00:00
|
|
|
|
2022-12-22 15:15:48 +00:00
|
|
|
const SCH_CONNECTION* conn = nullptr;
|
|
|
|
VECTOR2D connPos;
|
|
|
|
|
|
|
|
for( EDA_ITEM* item : selectionTool->GetSelection() )
|
|
|
|
{
|
|
|
|
conn = static_cast<SCH_ITEM*>( item )->Connection();
|
|
|
|
connPos = item->GetPosition();
|
|
|
|
|
|
|
|
if( conn )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !conn )
|
|
|
|
{
|
|
|
|
m_frame->ShowInfoBarError( _( "No net selected." ) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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();
|
2022-12-22 15:15:48 +00:00
|
|
|
highlightNet( m_toolMgr, connPos );
|
2020-07-07 10:17:30 +00:00
|
|
|
|
2022-12-22 15:15:48 +00:00
|
|
|
wxString netName = conn->Name();
|
2020-07-07 10:17:30 +00:00
|
|
|
|
2022-12-22 15:15:48 +00:00
|
|
|
if( conn->IsBus() )
|
2020-07-07 10:17:30 +00:00
|
|
|
{
|
2022-12-22 15:15:48 +00:00
|
|
|
wxString prefix;
|
2021-07-26 15:20:45 +00:00
|
|
|
|
2022-12-22 15:15:48 +00:00
|
|
|
if( NET_SETTINGS::ParseBusVector( netName, &prefix, nullptr ) )
|
2021-07-26 15:20:45 +00:00
|
|
|
{
|
2022-12-22 15:15:48 +00:00
|
|
|
netName = prefix + wxT( "*" );
|
2021-07-26 15:20:45 +00:00
|
|
|
}
|
2022-12-22 15:15:48 +00:00
|
|
|
else if( NET_SETTINGS::ParseBusGroup( netName, &prefix, nullptr ) )
|
2021-07-26 15:20:45 +00:00
|
|
|
{
|
2022-12-22 15:15:48 +00:00
|
|
|
netName = prefix + wxT( ".*" );
|
2021-07-26 15:20:45 +00:00
|
|
|
}
|
2022-12-22 15:15:48 +00:00
|
|
|
}
|
|
|
|
else if( !conn->Driver() || CONNECTION_SUBGRAPH::GetDriverPriority( conn->Driver() )
|
|
|
|
< CONNECTION_SUBGRAPH::PRIORITY::SHEET_PIN )
|
|
|
|
{
|
|
|
|
m_frame->ShowInfoBarError( _( "Net must be labeled to assign a netclass." ) );
|
|
|
|
highlightNet( m_toolMgr, CLEAR );
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-07 10:17:30 +00:00
|
|
|
|
2022-12-22 15:15:48 +00:00
|
|
|
DIALOG_ASSIGN_NETCLASS dlg( m_frame, netName, schematic.GetNetClassAssignmentCandidates(),
|
|
|
|
[&]( const std::vector<wxString>& aNetNames )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : screen->Items() )
|
2022-09-03 20:33:56 +00:00
|
|
|
{
|
2022-12-22 15:15:48 +00:00
|
|
|
bool redraw = item->IsBrightened();
|
|
|
|
SCH_CONNECTION* itemConn = item->Connection();
|
2022-09-03 20:33:56 +00:00
|
|
|
|
2022-12-22 15:15:48 +00:00
|
|
|
if( itemConn && alg::contains( aNetNames, itemConn->Name() ) )
|
|
|
|
item->SetBrightened();
|
|
|
|
else
|
|
|
|
item->ClearBrightened();
|
2022-09-03 20:33:56 +00:00
|
|
|
|
2022-12-22 15:15:48 +00:00
|
|
|
redraw |= item->IsBrightened();
|
2022-09-03 20:33:56 +00:00
|
|
|
|
2022-12-22 15:15:48 +00:00
|
|
|
if( item->Type() == SCH_SYMBOL_T )
|
|
|
|
{
|
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
2022-09-03 20:33:56 +00:00
|
|
|
|
2022-12-22 15:15:48 +00:00
|
|
|
redraw |= symbol->HasBrightenedPins();
|
2022-09-03 20:33:56 +00:00
|
|
|
|
2022-12-22 15:15:48 +00:00
|
|
|
symbol->ClearBrightenedPins();
|
2022-09-03 20:33:56 +00:00
|
|
|
|
2022-12-22 15:15:48 +00:00
|
|
|
for( SCH_PIN* pin : symbol->GetPins() )
|
|
|
|
{
|
|
|
|
SCH_CONNECTION* pin_conn = pin->Connection();
|
2022-09-03 20:33:56 +00:00
|
|
|
|
2022-12-22 15:15:48 +00:00
|
|
|
if( pin_conn && alg::contains( aNetNames, pin_conn->Name() ) )
|
|
|
|
{
|
|
|
|
pin->SetBrightened();
|
|
|
|
redraw = true;
|
2022-09-03 20:33:56 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-22 15:15:48 +00:00
|
|
|
}
|
|
|
|
else if( item->Type() == SCH_SHEET_T )
|
|
|
|
{
|
|
|
|
for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( item )->GetPins() )
|
2022-09-03 20:33:56 +00:00
|
|
|
{
|
2022-12-22 15:15:48 +00:00
|
|
|
SCH_CONNECTION* pin_conn = pin->Connection();
|
2022-09-03 20:33:56 +00:00
|
|
|
|
2022-12-22 15:15:48 +00:00
|
|
|
redraw |= pin->IsBrightened();
|
2022-09-03 20:33:56 +00:00
|
|
|
|
2022-12-22 15:15:48 +00:00
|
|
|
if( pin_conn && alg::contains( aNetNames, pin_conn->Name() ) )
|
|
|
|
pin->SetBrightened();
|
|
|
|
else
|
|
|
|
pin->ClearBrightened();
|
2022-09-03 20:33:56 +00:00
|
|
|
|
2022-12-22 15:15:48 +00:00
|
|
|
redraw |= pin->IsBrightened();
|
2022-09-03 20:33:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-22 15:15:48 +00:00
|
|
|
if( redraw )
|
|
|
|
getView()->Update( item, KIGFX::VIEW_UPDATE_FLAGS::REPAINT );
|
|
|
|
}
|
2020-07-07 10:17:30 +00:00
|
|
|
|
2022-12-22 15:15:48 +00:00
|
|
|
m_frame->GetCanvas()->ForceRefresh();
|
|
|
|
} );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() )
|
|
|
|
{
|
|
|
|
getView()->UpdateAllItemsConditionally(
|
2023-02-07 15:09:24 +00:00
|
|
|
[&]( KIGFX::VIEW_ITEM* aItem ) -> int
|
2022-12-22 15:15:48 +00:00
|
|
|
{
|
2023-02-05 20:50:24 +00:00
|
|
|
int flags = 0;
|
|
|
|
|
2022-12-22 15:15:48 +00:00
|
|
|
// Netclass coloured items
|
|
|
|
//
|
|
|
|
if( dynamic_cast<SCH_LINE*>( aItem ) )
|
2023-02-05 20:50:24 +00:00
|
|
|
flags |= KIGFX::REPAINT;
|
2022-12-22 15:15:48 +00:00
|
|
|
else if( dynamic_cast<SCH_JUNCTION*>( aItem ) )
|
2023-02-05 20:50:24 +00:00
|
|
|
flags |= KIGFX::REPAINT;
|
2022-12-22 15:15:48 +00:00
|
|
|
else if( dynamic_cast<SCH_BUS_ENTRY_BASE*>( aItem ) )
|
2023-02-05 20:50:24 +00:00
|
|
|
flags |= KIGFX::REPAINT;
|
2022-12-22 15:15:48 +00:00
|
|
|
|
|
|
|
// Items that might reference an item's netclass name
|
|
|
|
//
|
2023-02-05 20:50:24 +00:00
|
|
|
if( SCH_ITEM* item = dynamic_cast<SCH_ITEM*>( aItem ) )
|
2022-10-01 21:57:32 +00:00
|
|
|
{
|
2023-02-05 20:50:24 +00:00
|
|
|
item->RunOnChildren(
|
|
|
|
[&flags]( SCH_ITEM* aChild )
|
|
|
|
{
|
|
|
|
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aChild );
|
|
|
|
|
|
|
|
if( text && text->HasTextVars() )
|
|
|
|
{
|
|
|
|
text->ClearRenderCache();
|
|
|
|
text->ClearBoundingBoxCache();
|
|
|
|
flags |= KIGFX::GEOMETRY | KIGFX::REPAINT;
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
EDA_TEXT* text = dynamic_cast<EDA_TEXT*>( aItem );
|
|
|
|
|
|
|
|
if( text && text->HasTextVars() )
|
|
|
|
{
|
|
|
|
text->ClearRenderCache();
|
|
|
|
text->ClearBoundingBoxCache();
|
|
|
|
flags |= KIGFX::GEOMETRY | KIGFX::REPAINT;
|
|
|
|
}
|
2023-02-07 15:09:24 +00:00
|
|
|
|
|
|
|
if( flags & KIGFX::GEOMETRY )
|
|
|
|
m_frame->GetScreen()->Update( item, false ); // Refresh RTree
|
2022-12-22 15:15:48 +00:00
|
|
|
}
|
2022-11-29 15:17:38 +00:00
|
|
|
|
2023-02-05 20:50:24 +00:00
|
|
|
return flags;
|
2022-12-22 15:15:48 +00:00
|
|
|
} );
|
2020-07-07 10:17:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2023-11-17 12:15:43 +00:00
|
|
|
wxCHECK( m_frame, 0 );
|
|
|
|
|
|
|
|
const SCH_SHEET_PATH& sheetPath = m_frame->GetCurrentSheet();
|
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();
|
2023-11-17 12:15:43 +00:00
|
|
|
wxString selectedName = m_frame->GetHighlightedConnection();
|
|
|
|
|
|
|
|
std::set<wxString> connNames;
|
2019-04-14 00:44:05 +00:00
|
|
|
std::vector<EDA_ITEM*> itemsToRedraw;
|
|
|
|
|
2023-05-17 00:06:21 +00:00
|
|
|
wxCHECK( screen && connectionGraph, 0 );
|
2019-04-14 00:44:05 +00:00
|
|
|
|
2023-11-17 12:15:43 +00:00
|
|
|
if( !selectedName.IsEmpty() )
|
2019-04-14 00:44:05 +00:00
|
|
|
{
|
2023-11-17 12:15:43 +00:00
|
|
|
connNames.emplace( selectedName );
|
2019-04-14 00:44:05 +00:00
|
|
|
|
2023-11-30 16:28:43 +00:00
|
|
|
CONNECTION_SUBGRAPH* sg = connectionGraph->FindSubgraphByName( selectedName, sheetPath );
|
2022-08-23 11:25:36 +00:00
|
|
|
|
2023-11-30 16:28:43 +00:00
|
|
|
if( sg && m_highlightBusMembers )
|
|
|
|
{
|
2023-11-17 12:15:43 +00:00
|
|
|
for( const SCH_ITEM* item : sg->GetItems() )
|
2020-05-24 14:46:05 +00:00
|
|
|
{
|
2023-11-17 12:15:43 +00:00
|
|
|
wxCHECK2( item, continue );
|
2023-05-17 00:06:21 +00:00
|
|
|
|
2023-11-17 12:15:43 +00:00
|
|
|
SCH_CONNECTION* connection = item->Connection();
|
2023-05-17 00:06:21 +00:00
|
|
|
|
2023-11-17 12:15:43 +00:00
|
|
|
wxCHECK2( connection, continue );
|
|
|
|
|
|
|
|
for( const std::shared_ptr<SCH_CONNECTION>& member : connection->AllMembers() )
|
2023-05-17 00:06:21 +00:00
|
|
|
{
|
2023-11-17 12:15:43 +00:00
|
|
|
if( member )
|
|
|
|
connNames.emplace( member->Name() );
|
2023-05-17 00:06:21 +00:00
|
|
|
}
|
2022-08-23 11:25:36 +00:00
|
|
|
}
|
2020-04-10 13:08:14 +00:00
|
|
|
}
|
2023-11-17 12:15:43 +00:00
|
|
|
}
|
2020-04-10 13:08:14 +00:00
|
|
|
|
2023-11-17 12:15:43 +00:00
|
|
|
for( SCH_ITEM* item : screen->Items() )
|
|
|
|
{
|
|
|
|
wxCHECK2( item, continue );
|
2019-04-14 00:44:05 +00:00
|
|
|
|
2023-11-17 12:15:43 +00:00
|
|
|
if( !item->IsConnectable() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SCH_ITEM* redrawItem = nullptr;
|
2019-04-14 00:44:05 +00:00
|
|
|
|
2022-08-23 11:25:36 +00:00
|
|
|
if( item->Type() == SCH_SYMBOL_T )
|
2019-04-14 00:44:05 +00:00
|
|
|
{
|
2022-08-23 11:25:36 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
|
|
|
|
2023-11-17 12:15:43 +00:00
|
|
|
wxCHECK2( symbol, continue );
|
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
|
|
|
|
2023-11-17 12:15:43 +00:00
|
|
|
wxCHECK2( pin_conn, continue );
|
|
|
|
|
|
|
|
if( !pin->IsBrightened() && connNames.count( pin_conn->Name() ) )
|
2019-04-14 00:44:05 +00:00
|
|
|
{
|
2020-08-21 15:54:24 +00:00
|
|
|
pin->SetBrightened();
|
2023-11-17 12:15:43 +00:00
|
|
|
redrawItem = symbol;
|
|
|
|
}
|
|
|
|
else if( pin->IsBrightened() && !connNames.count( pin_conn->Name() ) )
|
|
|
|
{
|
|
|
|
pin->ClearBrightened();
|
|
|
|
redrawItem = symbol;
|
2019-04-14 00:44:05 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-10 13:08:14 +00:00
|
|
|
|
2023-11-17 12:15:43 +00:00
|
|
|
if( symbol->IsPower() )
|
2020-04-10 13:08:14 +00:00
|
|
|
{
|
2023-11-17 12:15:43 +00:00
|
|
|
wxCHECK2( symbol->GetPins().size(), continue );
|
|
|
|
|
|
|
|
SCH_CONNECTION* pinConn = symbol->GetPins()[0]->Connection();
|
|
|
|
|
|
|
|
wxCHECK2( pinConn, continue );
|
|
|
|
|
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
|
|
|
{
|
2023-11-17 12:15:43 +00:00
|
|
|
if( !fields[id].IsVisible() )
|
|
|
|
continue;
|
|
|
|
|
2023-11-23 22:28:43 +00:00
|
|
|
if( !fields[id].IsBrightened() && connNames.count( pinConn->Name() ) )
|
2023-11-17 12:15:43 +00:00
|
|
|
{
|
2020-04-10 13:08:14 +00:00
|
|
|
fields[id].SetBrightened();
|
2023-11-17 12:15:43 +00:00
|
|
|
redrawItem = symbol;
|
|
|
|
}
|
2023-11-23 22:28:43 +00:00
|
|
|
else if( fields[id].IsBrightened() && !connNames.count( pinConn->Name() ) )
|
2023-11-17 12:15:43 +00:00
|
|
|
{
|
2020-04-10 13:08:14 +00:00
|
|
|
fields[id].ClearBrightened();
|
2023-11-17 12:15:43 +00:00
|
|
|
redrawItem = symbol;
|
|
|
|
}
|
2020-04-10 13:08:14 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
{
|
2023-11-17 12:15:43 +00:00
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
|
|
|
|
|
|
|
|
wxCHECK2( sheet, continue );
|
|
|
|
|
|
|
|
for( SCH_SHEET_PIN* pin : sheet->GetPins() )
|
2019-04-14 00:44:05 +00:00
|
|
|
{
|
2023-11-17 12:15:43 +00:00
|
|
|
wxCHECK2( pin, continue );
|
|
|
|
|
2020-10-07 14:40:12 +00:00
|
|
|
SCH_CONNECTION* pin_conn = pin->Connection();
|
2019-04-14 00:44:05 +00:00
|
|
|
|
2023-11-17 12:15:43 +00:00
|
|
|
wxCHECK2( pin_conn, continue );
|
|
|
|
|
|
|
|
if( !pin->IsBrightened() && connNames.count( pin_conn->Name() ) )
|
|
|
|
{
|
2020-01-12 18:40:50 +00:00
|
|
|
pin->SetBrightened();
|
2023-11-17 12:15:43 +00:00
|
|
|
redrawItem = sheet;
|
|
|
|
}
|
|
|
|
else if( pin->IsBrightened() && !connNames.count( pin_conn->Name() ) )
|
|
|
|
{
|
2020-01-12 18:40:50 +00:00
|
|
|
pin->ClearBrightened();
|
2023-11-17 12:15:43 +00:00
|
|
|
redrawItem = sheet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCH_CONNECTION* itemConn = item->Connection();
|
|
|
|
|
|
|
|
wxCHECK2( itemConn, continue );
|
|
|
|
|
2023-11-30 16:28:43 +00:00
|
|
|
if( !item->IsBrightened() && connNames.count( itemConn->Name() ) )
|
2023-11-17 12:15:43 +00:00
|
|
|
{
|
2023-11-30 16:28:43 +00:00
|
|
|
item->SetBrightened();
|
|
|
|
redrawItem = item;
|
2023-11-17 12:15:43 +00:00
|
|
|
}
|
2023-11-30 16:28:43 +00:00
|
|
|
else if( item->IsBrightened() && !connNames.count( itemConn->Name() ) )
|
2023-11-17 12:15:43 +00:00
|
|
|
{
|
2023-11-30 16:28:43 +00:00
|
|
|
item->ClearBrightened();
|
|
|
|
redrawItem = item;
|
2019-04-14 00:44:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-17 12:15:43 +00:00
|
|
|
if( redrawItem )
|
|
|
|
itemsToRedraw.push_back( redrawItem );
|
2019-04-14 00:44:05 +00:00
|
|
|
}
|
|
|
|
|
2023-11-17 12:15:43 +00:00
|
|
|
if( itemsToRedraw.size() )
|
|
|
|
{
|
|
|
|
// Be sure highlight change will be redrawn
|
|
|
|
KIGFX::VIEW* view = getView();
|
2019-04-14 00:44:05 +00:00
|
|
|
|
2023-11-17 12:15:43 +00:00
|
|
|
for( EDA_ITEM* redrawItem : itemsToRedraw )
|
|
|
|
view->Update( (KIGFX::VIEW_ITEM*)redrawItem, KIGFX::VIEW_UPDATE_FLAGS::REPAINT );
|
2019-04-14 00:44:05 +00:00
|
|
|
|
2023-11-17 12:15:43 +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-07-15 23:44:01 +00:00
|
|
|
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 );
|
|
|
|
} );
|
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::pickerTool, &aEvent );
|
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 )
|
|
|
|
{
|
2024-01-06 12:56:16 +00:00
|
|
|
wxCHECK( m_frame, 0 );
|
|
|
|
|
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 } );
|
|
|
|
|
2021-10-30 18:57:30 +00:00
|
|
|
// Get the old list
|
2023-05-01 22:25:31 +00:00
|
|
|
PICKED_ITEMS_LIST* undo_list = m_frame->PopCommandFromUndoList();
|
2019-05-14 19:21:10 +00:00
|
|
|
|
2024-01-06 12:56:16 +00:00
|
|
|
wxCHECK( undo_list, 0 );
|
|
|
|
|
2023-05-01 22:25:31 +00:00
|
|
|
m_frame->PutDataInPreviousState( undo_list );
|
2024-01-06 12:56:16 +00:00
|
|
|
|
2021-07-08 18:41:28 +00:00
|
|
|
// Now push the old command to the RedoList
|
2023-05-01 22:25:31 +00:00
|
|
|
undo_list->ReversePickersListOrder();
|
|
|
|
m_frame->PushCommandToRedoList( undo_list );
|
2021-07-08 18:41:28 +00:00
|
|
|
|
2021-05-27 13:24:06 +00:00
|
|
|
m_toolMgr->GetTool<EE_SELECTION_TOOL>()->RebuildSelection();
|
|
|
|
|
2023-07-08 17:37:47 +00:00
|
|
|
m_frame->GetCanvas()->Refresh();
|
2019-05-14 19:21:10 +00:00
|
|
|
m_frame->OnModify();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::Redo( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2024-01-06 12:56:16 +00:00
|
|
|
wxCHECK( m_frame, 0 );
|
|
|
|
|
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
|
|
|
|
2024-01-06 12:56:16 +00:00
|
|
|
wxCHECK( list, 0 );
|
|
|
|
|
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
|
|
|
|
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->GetCanvas()->Refresh();
|
|
|
|
m_frame->OnModify();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-15 13:47:28 +00:00
|
|
|
bool SCH_EDITOR_CONTROL::doCopy( bool aUseDuplicateClipboard )
|
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
|
|
|
|
2022-12-15 13:47:28 +00:00
|
|
|
if( selection.Empty() )
|
2019-04-28 16:36:31 +00:00
|
|
|
return false;
|
|
|
|
|
2022-12-15 13:47:28 +00:00
|
|
|
if( aUseDuplicateClipboard )
|
|
|
|
m_duplicateIsHoverSelection = selection.IsHover();
|
|
|
|
|
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();
|
|
|
|
}
|
2023-01-18 18:52:49 +00:00
|
|
|
else if( item->Type() == SCH_FIELD_T && selection.IsHover() )
|
2023-01-18 18:35:52 +00:00
|
|
|
{
|
|
|
|
// Most of the time the user is trying to duplicate the parent symbol
|
|
|
|
// and the field text is in it
|
|
|
|
selection.Add( item->GetParent() );
|
|
|
|
}
|
2023-12-11 22:22:19 +00:00
|
|
|
else if( item->Type() == SCH_MARKER_T )
|
|
|
|
{
|
|
|
|
// Don't let the markers be copied
|
|
|
|
selection.Remove( item );
|
|
|
|
}
|
2019-08-30 20:55:04 +00:00
|
|
|
}
|
|
|
|
|
2024-03-28 14:31:20 +00:00
|
|
|
STRING_FORMATTER formatter;
|
2023-12-24 00:31:24 +00:00
|
|
|
SCH_IO_KICAD_SEXPR plugin;
|
2024-03-28 14:31:20 +00:00
|
|
|
SCH_SHEET_LIST hierarchy = schematic.GetSheets();
|
|
|
|
SCH_SHEET_PATH selPath = m_frame->GetCurrentSheet();
|
2019-04-28 16:36:31 +00:00
|
|
|
|
2022-10-04 21:45:59 +00:00
|
|
|
plugin.Format( &selection, &selPath, schematic, &formatter, true );
|
2019-04-28 16:36:31 +00:00
|
|
|
|
2022-12-15 13:47:28 +00:00
|
|
|
if( selection.IsHover() )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2022-12-15 13:47:28 +00:00
|
|
|
|
|
|
|
if( aUseDuplicateClipboard )
|
2021-05-21 16:43:34 +00:00
|
|
|
{
|
2022-12-15 13:47:28 +00:00
|
|
|
m_duplicateClipboard = formatter.GetString();
|
2021-05-21 16:43:34 +00:00
|
|
|
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() )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::doDelete );
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-25 21:34:49 +00:00
|
|
|
void SCH_EDITOR_CONTROL::updatePastedSymbol( SCH_SYMBOL* aSymbol,
|
2021-05-01 22:56:37 +00:00
|
|
|
const SCH_SHEET_PATH& aPastePath,
|
2021-09-23 21:40:33 +00:00
|
|
|
const KIID_PATH& aClipPath,
|
|
|
|
bool aForceKeepAnnotations )
|
2020-09-06 10:31:53 +00:00
|
|
|
{
|
2024-01-25 21:34:49 +00:00
|
|
|
wxCHECK( m_frame && aSymbol, /* void */ );
|
2023-01-03 21:08:36 +00:00
|
|
|
|
2024-01-25 21:34:49 +00:00
|
|
|
SCH_SYMBOL_INSTANCE newInstance;
|
|
|
|
bool instanceFound = false;
|
2023-12-11 13:29:10 +00:00
|
|
|
KIID_PATH pasteLookupPath = aClipPath;
|
2021-05-01 22:56:37 +00:00
|
|
|
|
2023-12-11 13:29:10 +00:00
|
|
|
m_pastedSymbols.insert( aSymbol );
|
2021-05-01 22:56:37 +00:00
|
|
|
|
2024-01-25 21:34:49 +00:00
|
|
|
for( const SCH_SYMBOL_INSTANCE& tmp : aSymbol->GetInstances() )
|
|
|
|
{
|
2024-03-13 13:39:41 +00:00
|
|
|
if( ( tmp.m_Path.empty() && aClipPath.empty() )
|
|
|
|
|| ( !aClipPath.empty() && tmp.m_Path.EndsWith( aClipPath ) ) )
|
2024-01-25 21:34:49 +00:00
|
|
|
{
|
|
|
|
newInstance = tmp;
|
|
|
|
instanceFound = true;
|
|
|
|
|
2024-03-13 14:48:44 +00:00
|
|
|
wxLogTrace( traceSchPaste,
|
|
|
|
wxS( "Pasting found symbol instance with reference %s, unit %d:"
|
2024-03-13 13:39:41 +00:00
|
|
|
"\n\tClipboard path: %s\n\tSymbol UUID: %s." ),
|
|
|
|
tmp.m_Reference, tmp.m_Unit,
|
2024-01-25 21:34:49 +00:00
|
|
|
aClipPath.AsString(), aSymbol->m_Uuid.AsString() );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-11 13:29:10 +00:00
|
|
|
// The pasted symbol look up paths include the symbol UUID.
|
|
|
|
pasteLookupPath.push_back( aSymbol->m_Uuid );
|
2023-12-01 19:18:47 +00:00
|
|
|
|
2024-01-25 21:34:49 +00:00
|
|
|
if( !instanceFound )
|
2021-05-01 22:56:37 +00:00
|
|
|
{
|
2024-03-13 14:48:44 +00:00
|
|
|
wxLogTrace( traceSchPaste,
|
|
|
|
wxS( "Clipboard symbol instance **not** found:\n\tClipboard path: %s\n\t"
|
2024-03-13 13:39:41 +00:00
|
|
|
"Symbol UUID: %s." ),
|
2024-01-25 21:34:49 +00:00
|
|
|
aClipPath.AsString(), aSymbol->m_Uuid.AsString() );
|
|
|
|
|
2022-03-13 18:55:55 +00:00
|
|
|
// Some legacy versions saved value fields escaped. While we still do in the symbol
|
|
|
|
// editor, we don't anymore in the schematic, so be sure to unescape them.
|
|
|
|
SCH_FIELD* valueField = aSymbol->GetField( VALUE_FIELD );
|
|
|
|
valueField->SetText( UnescapeString( valueField->GetText() ) );
|
|
|
|
|
|
|
|
// Pasted from notepad or an older instance of eeschema. Use the values in the fields
|
|
|
|
// instead.
|
2024-01-25 21:34:49 +00:00
|
|
|
newInstance.m_Reference = aSymbol->GetField( REFERENCE_FIELD )->GetText();
|
|
|
|
newInstance.m_Unit = aSymbol->GetUnit();
|
2021-05-01 22:56:37 +00:00
|
|
|
}
|
2020-09-06 10:31:53 +00:00
|
|
|
|
2024-01-25 21:34:49 +00:00
|
|
|
newInstance.m_Path = aPastePath.Path();
|
|
|
|
newInstance.m_ProjectName = m_frame->Prj().GetProjectName();
|
2023-12-11 13:29:10 +00:00
|
|
|
|
2024-01-25 21:34:49 +00:00
|
|
|
aSymbol->AddHierarchicalReference( newInstance );
|
2023-12-11 13:29:10 +00:00
|
|
|
|
|
|
|
if( !aForceKeepAnnotations )
|
2022-04-13 22:37:42 +00:00
|
|
|
aSymbol->ClearAnnotation( &aPastePath, false );
|
2020-09-06 10:31:53 +00:00
|
|
|
|
2022-11-25 14:25:39 +00:00
|
|
|
// We might clear annotations but always leave the original unit number from the paste.
|
2024-01-25 21:34:49 +00:00
|
|
|
aSymbol->SetUnit( newInstance.m_Unit );
|
2021-05-01 22:56:37 +00:00
|
|
|
}
|
2020-09-06 10:31:53 +00:00
|
|
|
|
|
|
|
|
2024-01-25 21:34:49 +00:00
|
|
|
SCH_SHEET_PATH SCH_EDITOR_CONTROL::updatePastedSheet( SCH_SHEET* aSheet,
|
|
|
|
const SCH_SHEET_PATH& aPastePath,
|
2024-01-22 21:55:29 +00:00
|
|
|
const KIID_PATH& aClipPath,
|
2021-09-23 21:40:33 +00:00
|
|
|
bool aForceKeepAnnotations,
|
2024-01-25 21:34:49 +00:00
|
|
|
SCH_SHEET_LIST* aPastedSheets,
|
2024-03-13 13:39:41 +00:00
|
|
|
std::map<SCH_SHEET_PATH,
|
|
|
|
SCH_REFERENCE_LIST>& aPastedSymbols )
|
2021-05-01 22:56:37 +00:00
|
|
|
{
|
2024-01-25 21:34:49 +00:00
|
|
|
wxCHECK( aSheet && aPastedSheets, aPastePath );
|
2023-01-03 21:08:36 +00:00
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
SCH_SHEET_PATH sheetPath = aPastePath;
|
|
|
|
sheetPath.push_back( aSheet );
|
2021-01-21 17:36:59 +00:00
|
|
|
|
2024-01-25 21:34:49 +00:00
|
|
|
aPastedSheets->push_back( sheetPath );
|
2021-05-01 22:56:37 +00:00
|
|
|
|
|
|
|
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() )
|
|
|
|
{
|
2024-01-21 16:53:05 +00:00
|
|
|
if( item->IsConnectable() )
|
|
|
|
item->SetConnectivityDirty();
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( item->Type() == SCH_SYMBOL_T )
|
2021-05-01 22:56:37 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
2021-05-01 22:56:37 +00:00
|
|
|
|
2024-01-21 16:53:05 +00:00
|
|
|
wxCHECK2( symbol, continue );
|
|
|
|
|
|
|
|
// Only do this once if the symbol is shared across multiple sheets.
|
|
|
|
if( !m_pastedSymbols.count( symbol ) )
|
|
|
|
{
|
|
|
|
for( SCH_PIN* pin : symbol->GetPins() )
|
|
|
|
{
|
|
|
|
const_cast<KIID&>( pin->m_Uuid ) = KIID();
|
|
|
|
pin->SetConnectivityDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-25 21:34:49 +00:00
|
|
|
updatePastedSymbol( symbol, 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
|
|
|
|
2024-01-21 16:53:05 +00:00
|
|
|
wxCHECK2( subsheet, continue );
|
|
|
|
|
|
|
|
// Make sure pins get a new UUID and set the dirty connectivity flag.
|
2024-01-25 21:34:49 +00:00
|
|
|
if( !aPastedSheets->ContainsSheet( subsheet ) )
|
2024-01-21 16:53:05 +00:00
|
|
|
{
|
|
|
|
for( SCH_SHEET_PIN* pin : subsheet->GetPins() )
|
|
|
|
{
|
|
|
|
const_cast<KIID&>( pin->m_Uuid ) = KIID();
|
|
|
|
pin->SetConnectivityDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
KIID_PATH newClipPath = aClipPath;
|
|
|
|
newClipPath.push_back( subsheet->m_Uuid );
|
|
|
|
|
2024-01-25 21:34:49 +00:00
|
|
|
updatePastedSheet( subsheet, sheetPath, newClipPath, aForceKeepAnnotations,
|
|
|
|
aPastedSheets, aPastedSymbols );
|
2020-09-06 10:31:53 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-01 22:56:37 +00:00
|
|
|
|
2024-01-25 21:34:49 +00:00
|
|
|
sheetPath.GetSymbols( aPastedSymbols[aPastePath] );
|
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
return sheetPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-15 17:15:30 +00:00
|
|
|
void SCH_EDITOR_CONTROL::setPastedSymbolInstances( const SCH_SCREEN* aScreen )
|
2021-05-01 22:56:37 +00:00
|
|
|
{
|
2024-01-15 17:15:30 +00:00
|
|
|
wxCHECK( aScreen, /* void */ );
|
2021-05-01 22:56:37 +00:00
|
|
|
|
2024-01-15 17:15:30 +00:00
|
|
|
for( const SCH_ITEM* item : aScreen->Items() )
|
2023-12-01 19:18:47 +00:00
|
|
|
{
|
2024-01-15 17:15:30 +00:00
|
|
|
if( item->Type() == SCH_SYMBOL_T )
|
2023-12-01 19:18:47 +00:00
|
|
|
{
|
2024-01-15 17:15:30 +00:00
|
|
|
const SCH_SYMBOL* symbol = static_cast<const SCH_SYMBOL*>( item );
|
2021-05-01 22:56:37 +00:00
|
|
|
|
2024-01-15 17:15:30 +00:00
|
|
|
wxCHECK2( symbol, continue );
|
2023-12-01 19:18:47 +00:00
|
|
|
|
2024-01-15 17:15:30 +00:00
|
|
|
for( const SCH_SYMBOL_INSTANCE& symbolInstance : symbol->GetInstances() )
|
2023-12-01 19:18:47 +00:00
|
|
|
{
|
2024-01-15 17:15:30 +00:00
|
|
|
KIID_PATH pathWithSymbol = symbolInstance.m_Path;
|
2023-12-01 19:18:47 +00:00
|
|
|
|
2024-01-15 17:15:30 +00:00
|
|
|
pathWithSymbol.push_back( symbol->m_Uuid );
|
2023-12-01 19:18:47 +00:00
|
|
|
|
2024-01-15 17:15:30 +00:00
|
|
|
m_clipboardSymbolInstances[pathWithSymbol] = symbolInstance;
|
2023-12-01 19:18:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-06 10:31:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-11 13:29:10 +00:00
|
|
|
void SCH_EDITOR_CONTROL::prunePastedSymbolInstances()
|
|
|
|
{
|
|
|
|
wxCHECK( m_frame, /* void */ );
|
|
|
|
|
|
|
|
for( SCH_SYMBOL* symbol : m_pastedSymbols )
|
|
|
|
{
|
|
|
|
wxCHECK2( symbol, continue );
|
|
|
|
|
|
|
|
std::vector<KIID_PATH> instancePathsToRemove;
|
|
|
|
|
2023-12-28 23:25:47 +00:00
|
|
|
for( const SCH_SYMBOL_INSTANCE& instance : symbol->GetInstances() )
|
2023-12-11 13:29:10 +00:00
|
|
|
{
|
|
|
|
if( ( instance.m_ProjectName != m_frame->Prj().GetProjectName() )
|
|
|
|
|| instance.m_Path.empty() )
|
|
|
|
instancePathsToRemove.emplace_back( instance.m_Path );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( const KIID_PATH& path : instancePathsToRemove )
|
|
|
|
symbol->RemoveInstance( path );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-11-28 15:07:38 +00:00
|
|
|
std::string content;
|
2022-10-03 22:28:21 +00:00
|
|
|
VECTOR2I eventPos;
|
2021-05-21 16:43:34 +00:00
|
|
|
|
|
|
|
if( aEvent.IsAction( &ACTIONS::duplicate ) )
|
2022-12-15 13:47:28 +00:00
|
|
|
content = m_duplicateClipboard;
|
2021-05-21 16:43:34 +00:00
|
|
|
else
|
2021-11-28 15:07:38 +00:00
|
|
|
content = m_toolMgr->GetClipboardUTF8();
|
2019-08-15 07:19:15 +00:00
|
|
|
|
2021-11-28 15:07:38 +00:00
|
|
|
if( content.empty() )
|
2019-08-15 07:19:15 +00:00
|
|
|
return 0;
|
|
|
|
|
2022-10-03 22:28:21 +00:00
|
|
|
if( aEvent.IsAction( &ACTIONS::duplicate ) )
|
|
|
|
eventPos = getViewControls()->GetCursorPosition( false );
|
|
|
|
|
2021-11-28 15:07:38 +00:00
|
|
|
STRING_LINE_READER reader( content, "Clipboard" );
|
2024-01-25 21:34:49 +00:00
|
|
|
SCH_IO_KICAD_SEXPR plugin;
|
2019-04-28 16:36:31 +00:00
|
|
|
|
2021-11-28 15:07:38 +00:00
|
|
|
SCH_SHEET tempSheet;
|
|
|
|
SCH_SCREEN* tempScreen = new SCH_SCREEN( &m_frame->Schematic() );
|
2020-05-13 21:58:30 +00:00
|
|
|
|
2022-03-30 17:41:40 +00:00
|
|
|
EESCHEMA_SETTINGS::PANEL_ANNOTATE& annotate = m_frame->eeconfig()->m_AnnotatePanel;
|
|
|
|
int annotateStartNum = m_frame->Schematic().Settings().m_AnnotateStartNum;
|
|
|
|
|
2020-05-13 21:58:30 +00:00
|
|
|
// Screen object on heap is owned by the sheet.
|
2021-11-28 15:07:38 +00:00
|
|
|
tempSheet.SetScreen( tempScreen );
|
2019-06-25 23:39:58 +00:00
|
|
|
|
2019-04-28 16:36:31 +00:00
|
|
|
try
|
|
|
|
{
|
2021-11-28 15:07:38 +00:00
|
|
|
plugin.LoadContent( reader, &tempSheet );
|
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
|
|
|
{
|
2022-11-22 19:35:27 +00:00
|
|
|
// If it wasn't content, then paste as text object.
|
2023-02-19 03:40:07 +00:00
|
|
|
SCH_TEXT* text_item = new SCH_TEXT( VECTOR2I( 0, 0 ), content );
|
2021-11-28 15:07:38 +00:00
|
|
|
tempScreen->Append( text_item );
|
2019-04-28 16:36:31 +00:00
|
|
|
}
|
|
|
|
|
2023-12-11 13:29:10 +00:00
|
|
|
m_pastedSymbols.clear();
|
2023-12-01 19:18:47 +00:00
|
|
|
m_clipboardSymbolInstances.clear();
|
|
|
|
|
2024-01-15 17:15:30 +00:00
|
|
|
// Save pasted symbol instances in case the user chooses to keep existing symbol annotation.
|
|
|
|
setPastedSymbolInstances( tempScreen );
|
2021-05-01 22:56:37 +00:00
|
|
|
|
2022-12-07 23:40:05 +00:00
|
|
|
tempScreen->MigrateSimModels();
|
|
|
|
|
2022-10-03 22:28:21 +00:00
|
|
|
PASTE_MODE pasteMode = annotate.automatic ? PASTE_MODE::RESPECT_OPTIONS
|
|
|
|
: PASTE_MODE::REMOVE_ANNOTATIONS;
|
2021-05-01 22:44:22 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-04-25 17:10:33 +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.
|
2023-07-24 16:37:25 +00:00
|
|
|
SCH_COMMIT commit( m_toolMgr );
|
|
|
|
EDA_ITEMS loadedItems;
|
|
|
|
std::vector<SCH_ITEM*> sortedLoadedItems;
|
|
|
|
bool sheetsPasted = false;
|
|
|
|
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
|
2023-06-09 16:24:49 +00:00
|
|
|
SCH_SHEET_LIST sheetPathsForScreen = hierarchy.FindAllSheetsForScreen( pasteRoot.LastScreen() );
|
|
|
|
sheetPathsForScreen.SortByPageNumbers();
|
2021-05-01 22:56:37 +00:00
|
|
|
|
|
|
|
// 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_REFERENCE_LIST existingRefs;
|
2021-11-28 17:08:30 +00:00
|
|
|
hierarchy.GetSymbols( existingRefs );
|
2021-05-01 22:56:37 +00:00
|
|
|
existingRefs.SortByReferenceOnly();
|
|
|
|
|
2021-11-28 17:08:30 +00:00
|
|
|
// Build UUID map for fetching last-resolved-properties
|
|
|
|
std::map<KIID, EDA_ITEM*> itemMap;
|
|
|
|
hierarchy.FillItemMap( itemMap );
|
|
|
|
|
2022-11-22 19:35:27 +00:00
|
|
|
// Keep track of pasted sheets and symbols for the different paths to the hierarchy.
|
2021-05-01 22:56:37 +00:00
|
|
|
std::map<SCH_SHEET_PATH, SCH_REFERENCE_LIST> pastedSymbols;
|
|
|
|
std::map<SCH_SHEET_PATH, SCH_SHEET_LIST> pastedSheets;
|
|
|
|
|
2021-11-28 15:07:38 +00:00
|
|
|
for( SCH_ITEM* item : tempScreen->Items() )
|
2023-07-24 16:37:25 +00:00
|
|
|
{
|
|
|
|
if( item->Type() == SCH_SHEET_T )
|
|
|
|
sortedLoadedItems.push_back( item );
|
|
|
|
else
|
|
|
|
loadedItems.push_back( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
sort( sortedLoadedItems.begin(), sortedLoadedItems.end(),
|
|
|
|
[]( SCH_ITEM* firstItem, SCH_ITEM* secondItem )
|
|
|
|
{
|
|
|
|
SCH_SHEET* firstSheet = static_cast<SCH_SHEET*>( firstItem );
|
|
|
|
SCH_SHEET* secondSheet = static_cast<SCH_SHEET*>( secondItem );
|
|
|
|
return StrNumCmp( firstSheet->GetName(), secondSheet->GetName(), false ) < 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : sortedLoadedItems )
|
2019-04-23 13:06:37 +00:00
|
|
|
{
|
2019-04-28 16:36:31 +00:00
|
|
|
loadedItems.push_back( item );
|
|
|
|
|
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 );
|
2023-07-24 16:37:25 +00:00
|
|
|
SCH_FIELD& nameField = sheet->GetFields()[SHEETNAME];
|
|
|
|
wxString baseName = nameField.GetText();
|
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 ) ) )
|
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
auto msg = wxString::Format( _( "The pasted sheet '%s'\n"
|
2019-04-28 16:36:31 +00:00
|
|
|
"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
|
2021-11-28 15:07:38 +00:00
|
|
|
tempScreen->Clear( false );
|
2019-04-23 13:06:37 +00:00
|
|
|
|
2023-06-09 16:24:49 +00:00
|
|
|
for( EDA_ITEM* item : loadedItems )
|
2019-04-28 16:36:31 +00:00
|
|
|
{
|
2023-01-03 21:08:36 +00:00
|
|
|
KIID_PATH clipPath( wxT( "/" ) ); // clipboard is at root
|
2019-04-23 13:06:37 +00:00
|
|
|
|
2024-01-21 16:53:05 +00:00
|
|
|
SCH_ITEM* schItem = static_cast<SCH_ITEM*>( item );
|
|
|
|
|
|
|
|
wxCHECK2( schItem, continue );
|
|
|
|
|
|
|
|
if( schItem->IsConnectable() )
|
|
|
|
schItem->SetConnectivityDirty();
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( item->Type() == SCH_SYMBOL_T )
|
2019-04-28 16:36:31 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( 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
|
2021-11-28 15:07:38 +00:00
|
|
|
it = tempScreen->GetLibSymbols().find( symbol->GetSchSymbolLibraryName() );
|
|
|
|
end = tempScreen->GetLibSymbols().end();
|
2021-05-01 22:56:37 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* libSymbol = nullptr;
|
2020-05-13 21:58:30 +00:00
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
if( it != end )
|
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
libSymbol = new LIB_SYMBOL( *it->second );
|
|
|
|
symbol->SetLibSymbol( libSymbol );
|
2021-05-01 22:56:37 +00:00
|
|
|
}
|
2020-05-13 21:58:30 +00:00
|
|
|
|
2023-06-09 16:24:49 +00:00
|
|
|
for( SCH_SHEET_PATH& sheetPath : sheetPathsForScreen )
|
2024-01-25 21:34:49 +00:00
|
|
|
updatePastedSymbol( symbol, sheetPath, clipPath, forceKeepAnnotations );
|
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() )
|
2024-01-21 16:53:05 +00:00
|
|
|
{
|
2021-04-19 01:53:38 +00:00
|
|
|
const_cast<KIID&>( pin->m_Uuid ) = KIID();
|
2024-01-21 16:53:05 +00:00
|
|
|
pin->SetConnectivityDirty();
|
|
|
|
}
|
2020-02-20 12:11:04 +00:00
|
|
|
|
2023-06-09 16:24:49 +00:00
|
|
|
for( SCH_SHEET_PATH& sheetPath : sheetPathsForScreen )
|
2021-05-01 22:56:37 +00:00
|
|
|
{
|
2023-01-06 18:55:13 +00:00
|
|
|
// Ignore symbols from a non-existant library.
|
|
|
|
if( libSymbol )
|
2021-05-01 22:56:37 +00:00
|
|
|
{
|
2023-06-09 16:24:49 +00:00
|
|
|
SCH_REFERENCE schReference( symbol, libSymbol, sheetPath );
|
|
|
|
schReference.SetSheetNumber( sheetPath.GetVirtualPageNumber() );
|
|
|
|
pastedSymbols[sheetPath].AddItem( schReference );
|
2021-05-01 22:56:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
}
|
2022-11-22 19:35:27 +00:00
|
|
|
|
2021-06-22 20:41:50 +00:00
|
|
|
// Update hierarchy to include any other sheets we already added, avoiding
|
|
|
|
// duplicate sheet names
|
|
|
|
hierarchy = m_frame->Schematic().GetSheets();
|
2020-10-23 16:48:07 +00:00
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
//@todo: it might be better to just iterate through the sheet names
|
2021-06-10 01:24:15 +00:00
|
|
|
// in this screen instead of the whole hierarchy.
|
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();
|
2022-08-14 17:36:40 +00:00
|
|
|
fn.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS,
|
|
|
|
currentSheetFileName.GetPath() );
|
2019-06-26 01:44:00 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2024-01-15 17:15:30 +00:00
|
|
|
// Save the symbol instances in case the user chooses to keep the existing
|
|
|
|
// symbol annotation.
|
|
|
|
setPastedSymbolInstances( sheet->GetScreen() );
|
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() )
|
2024-01-21 16:53:05 +00:00
|
|
|
{
|
2021-04-19 02:14:15 +00:00
|
|
|
const_cast<KIID&>( pin->m_Uuid ) = KIID();
|
2024-01-21 16:53:05 +00:00
|
|
|
pin->SetConnectivityDirty();
|
|
|
|
}
|
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.
|
2023-06-09 16:24:49 +00:00
|
|
|
for( SCH_SHEET_PATH& sheetPath : sheetPathsForScreen )
|
2021-05-01 22:56:37 +00:00
|
|
|
{
|
2024-01-25 21:34:49 +00:00
|
|
|
SCH_SHEET_PATH subPath = updatePastedSheet( sheet, sheetPath, clipPath,
|
2023-06-09 16:24:49 +00:00
|
|
|
( forceKeepAnnotations && annotate.automatic ),
|
|
|
|
&pastedSheets[sheetPath],
|
2024-01-25 21:34:49 +00:00
|
|
|
pastedSymbols );
|
2021-05-01 22:56:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-11-28 17:08:30 +00:00
|
|
|
SCH_ITEM* srcItem = dynamic_cast<SCH_ITEM*>( itemMap[ item->m_Uuid ] );
|
|
|
|
SCH_ITEM* destItem = dynamic_cast<SCH_ITEM*>( item );
|
|
|
|
|
2021-05-01 22:56:37 +00:00
|
|
|
// Everything gets a new KIID
|
|
|
|
const_cast<KIID&>( item->m_Uuid ) = KIID();
|
2021-11-28 17:08:30 +00:00
|
|
|
|
|
|
|
if( srcItem && destItem )
|
|
|
|
{
|
|
|
|
destItem->SetConnectivityDirty( true );
|
|
|
|
destItem->SetLastResolvedState( srcItem );
|
|
|
|
}
|
2019-05-03 11:49:59 +00:00
|
|
|
}
|
2019-04-23 13:06:37 +00:00
|
|
|
|
2022-11-22 19:35:27 +00:00
|
|
|
// Lines need both ends selected for a move after paste so the whole line moves.
|
2022-02-10 18:38:40 +00:00
|
|
|
if( item->Type() == SCH_LINE_T )
|
|
|
|
item->SetFlags( STARTPOINT | ENDPOINT );
|
|
|
|
|
2021-11-07 14:52:11 +00:00
|
|
|
item->SetFlags( IS_NEW | IS_PASTED | IS_MOVING );
|
2023-06-12 18:33:52 +00:00
|
|
|
|
|
|
|
if( !m_frame->GetScreen()->CheckIfOnDrawList( (SCH_ITEM*) item ) ) // don't want a loop!
|
|
|
|
m_frame->AddToScreen( item, m_frame->GetScreen() );
|
|
|
|
|
|
|
|
commit.Added( (SCH_ITEM*) item, m_frame->GetScreen() );
|
2022-11-22 19:35:27 +00:00
|
|
|
|
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
|
|
|
|
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
|
2023-06-09 16:24:49 +00:00
|
|
|
for( SCH_SHEET_PATH& sheetPath : sheetPathsForScreen )
|
2021-05-01 22:56:37 +00:00
|
|
|
{
|
2023-06-09 16:24:49 +00:00
|
|
|
for( SCH_SHEET_PATH& pastedSheet : pastedSheets[sheetPath] )
|
2021-05-01 22:56:37 +00:00
|
|
|
{
|
|
|
|
int page = 1;
|
|
|
|
wxString pageNum = wxString::Format( "%d", page );
|
|
|
|
|
|
|
|
while( hierarchy.PageNumberExists( pageNum ) )
|
|
|
|
pageNum = wxString::Format( "%d", ++page );
|
|
|
|
|
2024-01-22 21:55:29 +00:00
|
|
|
SCH_SHEET_INSTANCE sheetInstance;
|
|
|
|
|
|
|
|
sheetInstance.m_Path = pastedSheet.Path();
|
|
|
|
|
|
|
|
// Don't include the actual sheet in the instance path.
|
|
|
|
sheetInstance.m_Path.pop_back();
|
|
|
|
sheetInstance.m_PageNumber = pageNum;
|
|
|
|
sheetInstance.m_ProjectName = m_frame->Prj().GetProjectName();
|
2023-12-28 17:18:54 +00:00
|
|
|
|
|
|
|
SCH_SHEET* sheet = pastedSheet.Last();
|
|
|
|
|
|
|
|
wxCHECK2( sheet, continue );
|
|
|
|
|
2024-01-22 21:55:29 +00:00
|
|
|
sheet->AddInstance( sheetInstance );
|
|
|
|
hierarchy.push_back( pastedSheet );
|
|
|
|
|
|
|
|
// Remove all pasted sheet instance data that is not part of the current project.
|
|
|
|
std::vector<KIID_PATH> instancesToRemove;
|
|
|
|
|
2023-12-28 17:18:54 +00:00
|
|
|
for( const SCH_SHEET_INSTANCE& instance : sheet->GetInstances() )
|
|
|
|
{
|
2024-01-23 12:44:45 +00:00
|
|
|
if( !hierarchy.HasPath( instance.m_Path ) )
|
2023-12-28 17:18:54 +00:00
|
|
|
instancesToRemove.push_back( instance.m_Path );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( const KIID_PATH& instancePath : instancesToRemove )
|
|
|
|
sheet->RemoveInstance( instancePath );
|
2021-05-01 22:56:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-03 11:49:59 +00:00
|
|
|
m_frame->SetSheetNumberAndCount();
|
2022-07-20 15:39:15 +00:00
|
|
|
|
|
|
|
// Get a version with correct sheet numbers since we've pasted sheets,
|
|
|
|
// we'll need this when annotating next
|
|
|
|
hierarchy = m_frame->Schematic().GetSheets();
|
2019-10-24 17:07:01 +00:00
|
|
|
}
|
2019-04-28 16:36:31 +00:00
|
|
|
|
2023-01-03 21:08:36 +00:00
|
|
|
std::map<SCH_SHEET_PATH, SCH_REFERENCE_LIST> annotatedSymbols;
|
2022-11-21 21:28:51 +00:00
|
|
|
|
2023-01-03 21:08:36 +00:00
|
|
|
// Update the list of symbol instances that satisfy the annotation criteria.
|
2023-06-09 16:24:49 +00:00
|
|
|
for( const SCH_SHEET_PATH& sheetPath : sheetPathsForScreen )
|
2023-01-03 21:08:36 +00:00
|
|
|
{
|
|
|
|
for( size_t i = 0; i < pastedSymbols[sheetPath].GetCount(); i++ )
|
2022-11-21 21:28:51 +00:00
|
|
|
{
|
2023-01-03 21:08:36 +00:00
|
|
|
if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS
|
|
|
|
|| pasteMode == PASTE_MODE::RESPECT_OPTIONS
|
|
|
|
|| pastedSymbols[sheetPath][i].AlwaysAnnotate() )
|
2022-11-21 21:28:51 +00:00
|
|
|
{
|
2023-01-03 21:08:36 +00:00
|
|
|
annotatedSymbols[sheetPath].AddItem( pastedSymbols[sheetPath][i] );
|
2022-11-21 21:28:51 +00:00
|
|
|
}
|
|
|
|
}
|
2024-01-25 21:34:49 +00:00
|
|
|
|
|
|
|
for( const SCH_SHEET_PATH& pastedSheetPath : pastedSheets[sheetPath] )
|
|
|
|
{
|
|
|
|
for( size_t i = 0; i < pastedSymbols[pastedSheetPath].GetCount(); i++ )
|
|
|
|
{
|
|
|
|
if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS
|
|
|
|
|| pasteMode == PASTE_MODE::RESPECT_OPTIONS
|
|
|
|
|| pastedSymbols[pastedSheetPath][i].AlwaysAnnotate() )
|
|
|
|
{
|
|
|
|
annotatedSymbols[pastedSheetPath].AddItem( pastedSymbols[pastedSheetPath][i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-01-03 21:08:36 +00:00
|
|
|
}
|
2022-11-21 21:28:51 +00:00
|
|
|
|
2023-01-03 21:08:36 +00:00
|
|
|
if( !annotatedSymbols.empty() )
|
|
|
|
{
|
2023-06-09 16:24:49 +00:00
|
|
|
for( SCH_SHEET_PATH& path : sheetPathsForScreen )
|
2022-07-19 17:09:38 +00:00
|
|
|
{
|
2023-06-09 16:24:49 +00:00
|
|
|
annotatedSymbols[path].SortByReferenceOnly();
|
2022-07-19 17:09:38 +00:00
|
|
|
|
|
|
|
if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS )
|
2023-06-09 16:24:49 +00:00
|
|
|
{
|
|
|
|
annotatedSymbols[path].ReannotateDuplicates( existingRefs );
|
|
|
|
}
|
2022-07-19 17:09:38 +00:00
|
|
|
else
|
2023-06-09 16:24:49 +00:00
|
|
|
{
|
|
|
|
annotatedSymbols[path].ReannotateByOptions( (ANNOTATE_ORDER_T) annotate.sort_order,
|
|
|
|
(ANNOTATE_ALGO_T) annotate.method,
|
|
|
|
annotateStartNum, existingRefs, false,
|
|
|
|
&hierarchy );
|
|
|
|
}
|
2022-07-19 17:09:38 +00:00
|
|
|
|
2023-06-09 16:24:49 +00:00
|
|
|
annotatedSymbols[path].UpdateAnnotation();
|
2022-07-19 17:09:38 +00:00
|
|
|
|
|
|
|
// Update existing refs for next iteration
|
2023-06-09 16:24:49 +00:00
|
|
|
for( size_t i = 0; i < annotatedSymbols[path].GetCount(); i++ )
|
|
|
|
existingRefs.AddItem( annotatedSymbols[path][i] );
|
2024-01-25 21:34:49 +00:00
|
|
|
|
|
|
|
for( const SCH_SHEET_PATH& pastedSheetPath : pastedSheets[path] )
|
|
|
|
{
|
|
|
|
annotatedSymbols[pastedSheetPath].SortByReferenceOnly();
|
|
|
|
|
|
|
|
if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS )
|
|
|
|
{
|
|
|
|
annotatedSymbols[pastedSheetPath].ReannotateDuplicates( existingRefs );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
annotatedSymbols[pastedSheetPath].ReannotateByOptions( (ANNOTATE_ORDER_T) annotate.sort_order,
|
|
|
|
(ANNOTATE_ALGO_T) annotate.method,
|
|
|
|
annotateStartNum, existingRefs,
|
|
|
|
false,
|
|
|
|
&hierarchy );
|
|
|
|
}
|
|
|
|
|
|
|
|
annotatedSymbols[pastedSheetPath].UpdateAnnotation();
|
|
|
|
|
|
|
|
// Update existing refs for next iteration
|
|
|
|
for( size_t i = 0; i < annotatedSymbols[pastedSheetPath].GetCount(); i++ )
|
|
|
|
existingRefs.AddItem( annotatedSymbols[pastedSheetPath][i] );
|
|
|
|
}
|
2022-07-19 17:09:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_frame->GetCurrentSheet().UpdateAllScreenReferences();
|
|
|
|
|
2023-12-03 12:47:57 +00:00
|
|
|
// The copy operation creates instance paths that are not valid for the current project or
|
|
|
|
// saved as part of another project. Prune them now so they do not accumulate in the saved
|
|
|
|
// schematic file.
|
2023-12-28 17:18:54 +00:00
|
|
|
prunePastedSymbolInstances();
|
|
|
|
|
2023-12-03 12:47:57 +00:00
|
|
|
SCH_SCREENS allScreens( m_frame->Schematic().Root() );
|
|
|
|
|
|
|
|
allScreens.PruneOrphanedSymbolInstances( m_frame->Prj().GetProjectName(),
|
|
|
|
m_frame->Schematic().GetSheets() );
|
2023-12-28 17:18:54 +00:00
|
|
|
allScreens.PruneOrphanedSheetInstances( m_frame->Prj().GetProjectName(),
|
|
|
|
m_frame->Schematic().GetSheets() );
|
2023-12-03 12:47:57 +00:00
|
|
|
|
2022-11-22 19:35:27 +00:00
|
|
|
// Now clear the previous selection, select the pasted items, and fire up the "move" tool.
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
|
|
|
m_toolMgr->RunAction<EDA_ITEMS*>( EE_ACTIONS::addItemsToSel, &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() )
|
|
|
|
{
|
2022-10-03 22:28:21 +00:00
|
|
|
if( aEvent.IsAction( &ACTIONS::duplicate ) )
|
|
|
|
{
|
|
|
|
int closest_dist = INT_MAX;
|
|
|
|
|
|
|
|
auto processPt =
|
|
|
|
[&]( const VECTOR2I& pt )
|
|
|
|
{
|
|
|
|
int dist = ( eventPos - pt ).EuclideanNorm();
|
|
|
|
|
|
|
|
if( dist < closest_dist )
|
|
|
|
{
|
|
|
|
selection.SetReferencePoint( pt );
|
|
|
|
closest_dist = dist;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Prefer connection points (which should remain on grid)
|
|
|
|
for( EDA_ITEM* item : selection.Items() )
|
|
|
|
{
|
|
|
|
SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( item );
|
2024-04-20 09:44:34 +00:00
|
|
|
SCH_PIN* pin = dynamic_cast<SCH_PIN*>( item );
|
2022-10-03 22:28:21 +00:00
|
|
|
|
|
|
|
if( sch_item && sch_item->IsConnectable() )
|
|
|
|
{
|
|
|
|
for( const VECTOR2I& pt : sch_item->GetConnectionPoints() )
|
|
|
|
processPt( pt );
|
|
|
|
}
|
2024-04-20 09:44:34 +00:00
|
|
|
else if( pin )
|
2022-10-03 22:28:21 +00:00
|
|
|
{
|
2024-04-20 09:44:34 +00:00
|
|
|
processPt( pin->GetPosition() );
|
2022-10-03 22:28:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only process other points if we didn't find any connection points
|
|
|
|
if( closest_dist == INT_MAX )
|
|
|
|
{
|
|
|
|
for( EDA_ITEM* item : selection.Items() )
|
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case SCH_LINE_T:
|
|
|
|
processPt( static_cast<SCH_LINE*>( item )->GetStartPoint() );
|
|
|
|
processPt( static_cast<SCH_LINE*>( item )->GetEndPoint() );
|
|
|
|
break;
|
2019-04-28 16:36:31 +00:00
|
|
|
|
2022-10-03 22:28:21 +00:00
|
|
|
case SCH_SHAPE_T:
|
|
|
|
{
|
|
|
|
SCH_SHAPE* shape = static_cast<SCH_SHAPE*>( item );
|
|
|
|
|
|
|
|
switch( shape->GetShape() )
|
|
|
|
{
|
2023-07-24 16:07:56 +00:00
|
|
|
case SHAPE_T::RECTANGLE:
|
2022-10-03 22:28:21 +00:00
|
|
|
for( const VECTOR2I& pt : shape->GetRectCorners() )
|
|
|
|
processPt( pt );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::CIRCLE:
|
|
|
|
processPt( shape->GetCenter() );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SHAPE_T::POLY:
|
|
|
|
for( int ii = 0; ii < shape->GetPolyShape().TotalVertices(); ++ii )
|
|
|
|
processPt( shape->GetPolyShape().CVertex( ii ) );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
processPt( shape->GetStart() );
|
|
|
|
processPt( shape->GetEnd() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
processPt( item->GetPosition() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-15 13:47:28 +00:00
|
|
|
|
|
|
|
selection.SetIsHover( m_duplicateIsHoverSelection );
|
2022-10-03 22:28:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.GetTopLeftItem() );
|
|
|
|
|
|
|
|
selection.SetReferencePoint( item->GetPosition() );
|
|
|
|
}
|
2021-11-07 14:52:11 +00:00
|
|
|
|
2023-06-30 17:57:01 +00:00
|
|
|
if( m_toolMgr->RunSynchronousAction( EE_ACTIONS::move, &commit ) )
|
2024-01-15 17:15:30 +00:00
|
|
|
{
|
|
|
|
// Pushing the commit will update the connectivity.
|
2023-06-09 16:24:49 +00:00
|
|
|
commit.Push( _( "Paste" ) );
|
2024-01-27 17:02:22 +00:00
|
|
|
|
|
|
|
if( sheetsPasted )
|
|
|
|
m_frame->UpdateHierarchyNavigator();
|
2024-04-03 18:44:40 +00:00
|
|
|
// UpdateHierarchyNavigator() will call RefreshNetNavigator()
|
|
|
|
else
|
|
|
|
m_frame->RefreshNetNavigator();
|
2024-01-15 17:15:30 +00:00
|
|
|
}
|
2023-06-30 17:57:01 +00:00
|
|
|
else
|
2024-01-15 17:15:30 +00:00
|
|
|
{
|
2023-06-30 17:57:01 +00:00
|
|
|
commit.Revert();
|
2024-01-15 17:15:30 +00:00
|
|
|
}
|
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>();
|
2022-08-20 09:27:35 +00:00
|
|
|
EE_SELECTION& selection = selTool->RequestSelection( { SCH_SYMBOL_T } );
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* 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-06-10 14:10:55 +00:00
|
|
|
symbol = (SCH_SYMBOL*) selection.Front();
|
2019-04-29 22:24:30 +00:00
|
|
|
|
2022-12-15 13:47:28 +00:00
|
|
|
if( selection.IsHover() )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
|
2022-12-15 13:47:28 +00:00
|
|
|
|
2024-02-03 13:43:41 +00:00
|
|
|
if( !symbol )
|
|
|
|
{
|
|
|
|
// Giant hack: by default we assign Edit Table to the same hotkey, so give the table
|
|
|
|
// tool a chance to handle it if we can't.
|
|
|
|
if( SCH_EDIT_TABLE_TOOL* tableTool = m_toolMgr->GetTool<SCH_EDIT_TABLE_TOOL>() )
|
|
|
|
tableTool->EditTable( aEvent );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( symbol->GetEditFlags() != 0 )
|
2019-04-29 22:24:30 +00:00
|
|
|
return 0;
|
|
|
|
|
2022-09-04 14:00:03 +00:00
|
|
|
if( symbol->IsMissingLibSymbol() )
|
|
|
|
{
|
|
|
|
m_frame->ShowInfoBarError( _( "Symbols with broken library symbol links cannot "
|
|
|
|
"be edited." ) );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->RunAction( ACTIONS::showSymbolEditor );
|
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-10-26 19:59:59 +00:00
|
|
|
{
|
2022-07-12 21:44:53 +00:00
|
|
|
if( wxWindow* blocking_win = symbolEditor->Kiway().GetBlockingDialog() )
|
|
|
|
blocking_win->Close( true );
|
|
|
|
|
2021-10-26 19:59:59 +00:00
|
|
|
if( aEvent.IsAction( &EE_ACTIONS::editWithLibEdit ) )
|
2022-09-03 18:29:02 +00:00
|
|
|
{
|
2021-10-26 19:59:59 +00:00
|
|
|
symbolEditor->LoadSymbolFromSchematic( symbol );
|
2022-09-03 18:29:02 +00:00
|
|
|
}
|
2021-10-26 19:59:59 +00:00
|
|
|
else if( aEvent.IsAction( &EE_ACTIONS::editLibSymbolWithLibEdit ) )
|
|
|
|
{
|
2024-01-26 16:16:13 +00:00
|
|
|
symbolEditor->LoadSymbol( symbol->GetLibId(), symbol->GetUnit(),
|
|
|
|
symbol->GetBodyStyle() );
|
2021-10-26 19:59:59 +00:00
|
|
|
|
|
|
|
if( !symbolEditor->IsSymbolTreeShown() )
|
|
|
|
{
|
|
|
|
wxCommandEvent evt;
|
|
|
|
symbolEditor->OnToggleSymbolTree( evt );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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 )
|
|
|
|
{
|
2023-08-14 14:41:28 +00:00
|
|
|
DIALOG_SYMBOL_FIELDS_TABLE* dlg = m_frame->GetSymbolFieldsTableDialog();
|
|
|
|
|
|
|
|
wxCHECK( dlg, 0 );
|
|
|
|
|
|
|
|
// Needed at least on Windows. Raise() is not enough
|
|
|
|
dlg->Show( true );
|
|
|
|
|
|
|
|
// Bring it to the top if already open. Dual monitor users need this.
|
|
|
|
dlg->Raise();
|
|
|
|
|
2023-09-20 18:54:14 +00:00
|
|
|
dlg->ShowEditTab();
|
|
|
|
|
2019-06-01 15:28:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-01 18:36:49 +00:00
|
|
|
int SCH_EDITOR_CONTROL::EditSymbolLibraryLinks( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2021-06-14 18:00:08 +00:00
|
|
|
if( InvokeDialogEditSymbolsLibId( m_frame ) )
|
2019-07-09 11:38:10 +00:00
|
|
|
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 )
|
2023-09-20 15:12:03 +00:00
|
|
|
{
|
2024-03-21 19:08:23 +00:00
|
|
|
DIALOG_SYMBOL_FIELDS_TABLE* dlg = m_frame->GetSymbolFieldsTableDialog();
|
|
|
|
|
|
|
|
wxCHECK( dlg, 0 );
|
|
|
|
|
|
|
|
// Needed at least on Windows. Raise() is not enough
|
|
|
|
dlg->Show( true );
|
|
|
|
|
|
|
|
// Bring it to the top if already open. Dual monitor users need this.
|
|
|
|
dlg->Raise();
|
|
|
|
|
|
|
|
dlg->ShowExportTab();
|
|
|
|
|
2023-09-20 15:12:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::GenerateBOMLegacy( const TOOL_EVENT& aEvent )
|
2019-06-01 15:28:39 +00:00
|
|
|
{
|
|
|
|
InvokeDialogCreateBOM( m_frame );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-16 16:07:15 +00:00
|
|
|
int SCH_EDITOR_CONTROL::DrawSheetOnClipboard( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2023-06-09 16:24:49 +00:00
|
|
|
m_frame->RecalculateConnections( nullptr, LOCAL_CLEANUP );
|
2019-06-16 16:07:15 +00:00
|
|
|
m_frame->DrawCurrentSheetToClipboard();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-15 01:35:39 +00:00
|
|
|
int SCH_EDITOR_CONTROL::ShowSearch( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
getEditFrame<SCH_EDIT_FRAME>()->ToggleSearch();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-02 21:56:17 +00:00
|
|
|
int SCH_EDITOR_CONTROL::ShowHierarchy( const TOOL_EVENT& aEvent )
|
2019-04-30 14:46:29 +00:00
|
|
|
{
|
2022-06-02 21:56:17 +00:00
|
|
|
getEditFrame<SCH_EDIT_FRAME>()->ToggleSchematicHierarchy();
|
2019-04-30 14:46:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-20 17:47:12 +00:00
|
|
|
int SCH_EDITOR_CONTROL::ShowNetNavigator( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
getEditFrame<SCH_EDIT_FRAME>()->ToggleNetNavigator();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-21 01:57:20 +00:00
|
|
|
int SCH_EDITOR_CONTROL::ToggleProperties( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
getEditFrame<SCH_EDIT_FRAME>()->ToggleProperties();
|
|
|
|
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
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
getView()->UpdateAllItems( KIGFX::REPAINT );
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-27 16:59:53 +00:00
|
|
|
int SCH_EDITOR_CONTROL::ToggleDirectiveLabels( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
|
|
|
|
cfg->m_Appearance.show_directive_labels = !cfg->m_Appearance.show_directive_labels;
|
|
|
|
|
|
|
|
getView()->UpdateAllItems( KIGFX::REPAINT );
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-05 21:16:26 +00:00
|
|
|
int SCH_EDITOR_CONTROL::ToggleERCWarnings( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
|
|
|
|
cfg->m_Appearance.show_erc_warnings = !cfg->m_Appearance.show_erc_warnings;
|
|
|
|
|
|
|
|
getView()->SetLayerVisible( LAYER_ERC_WARN, cfg->m_Appearance.show_erc_warnings );
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::ToggleERCErrors( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
|
|
|
|
cfg->m_Appearance.show_erc_errors = !cfg->m_Appearance.show_erc_errors;
|
|
|
|
|
|
|
|
getView()->SetLayerVisible( LAYER_ERC_ERR, cfg->m_Appearance.show_erc_errors );
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::ToggleERCExclusions( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
|
|
|
|
cfg->m_Appearance.show_erc_exclusions = !cfg->m_Appearance.show_erc_exclusions;
|
|
|
|
|
|
|
|
getView()->SetLayerVisible( LAYER_ERC_EXCLUSION, cfg->m_Appearance.show_erc_exclusions );
|
|
|
|
m_frame->GetCanvas()->Refresh();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-09 17:18:56 +00:00
|
|
|
int SCH_EDITOR_CONTROL::ToggleOPVoltages( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
|
|
|
|
cfg->m_Appearance.show_op_voltages = !cfg->m_Appearance.show_op_voltages;
|
|
|
|
|
|
|
|
getView()->SetLayerVisible( LAYER_OP_VOLTAGES, cfg->m_Appearance.show_op_voltages );
|
|
|
|
m_frame->RefreshOperatingPointDisplay();
|
2023-03-05 01:33:07 +00:00
|
|
|
m_frame->GetCanvas()->Refresh();
|
2023-02-09 17:18:56 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::ToggleOPCurrents( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
|
|
|
|
cfg->m_Appearance.show_op_currents = !cfg->m_Appearance.show_op_currents;
|
|
|
|
|
|
|
|
getView()->SetLayerVisible( LAYER_OP_CURRENTS, cfg->m_Appearance.show_op_currents );
|
|
|
|
m_frame->RefreshOperatingPointDisplay();
|
2023-03-05 01:33:07 +00:00
|
|
|
m_frame->GetCanvas()->Refresh();
|
2023-02-09 17:18:56 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-22 16:49:38 +00:00
|
|
|
int SCH_EDITOR_CONTROL::ChangeLineMode( const TOOL_EVENT& aEvent )
|
2019-05-13 21:49:05 +00:00
|
|
|
{
|
2023-06-25 12:43:32 +00:00
|
|
|
m_frame->eeconfig()->m_Drawing.line_mode = aEvent.Parameter<LINE_MODE>();
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( ACTIONS::refreshPreview );
|
2022-03-22 16:49:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int SCH_EDITOR_CONTROL::NextLineMode( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
m_frame->eeconfig()->m_Drawing.line_mode++;
|
|
|
|
m_frame->eeconfig()->m_Drawing.line_mode %= LINE_MODE::LINE_MODE_COUNT;
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolMgr->PostAction( ACTIONS::refreshPreview );
|
2022-03-22 16:49:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-21 17:06:28 +00:00
|
|
|
int SCH_EDITOR_CONTROL::ToggleAnnotateAuto( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
|
|
|
|
cfg->m_AnnotatePanel.automatic = !cfg->m_AnnotatePanel.automatic;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-22 11:55:00 +00:00
|
|
|
int SCH_EDITOR_CONTROL::ToggleAnnotateRecursive( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
EESCHEMA_SETTINGS* cfg = m_frame->eeconfig();
|
|
|
|
cfg->m_AnnotatePanel.recursive = !cfg->m_AnnotatePanel.recursive;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 13:28:04 +00:00
|
|
|
int SCH_EDITOR_CONTROL::TogglePythonConsole( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
2023-06-25 12:37:58 +00:00
|
|
|
|
2021-03-18 13:28:04 +00:00
|
|
|
m_frame->ScriptingConsoleEnableDisable();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-20 23:35:29 +00:00
|
|
|
int SCH_EDITOR_CONTROL::ReloadPlugins( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
#ifdef KICAD_IPC_API
|
|
|
|
Pgm().GetPluginManager().ReloadPlugins();
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-24 11:04:07 +00:00
|
|
|
int SCH_EDITOR_CONTROL::RepairSchematic( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
int errors = 0;
|
|
|
|
wxString details;
|
|
|
|
bool quiet = aEvent.Parameter<bool>();
|
|
|
|
|
|
|
|
// Repair duplicate IDs.
|
|
|
|
std::map<KIID, EDA_ITEM*> ids;
|
|
|
|
int duplicates = 0;
|
|
|
|
|
|
|
|
auto processItem =
|
|
|
|
[&]( EDA_ITEM* aItem )
|
|
|
|
{
|
|
|
|
auto it = ids.find( aItem->m_Uuid );
|
|
|
|
|
|
|
|
if( it != ids.end() && it->second != aItem )
|
|
|
|
{
|
|
|
|
duplicates++;
|
|
|
|
const_cast<KIID&>( aItem->m_Uuid ) = KIID();
|
|
|
|
}
|
|
|
|
|
|
|
|
ids[ aItem->m_Uuid ] = aItem;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Symbol IDs are the most important, so give them the first crack at "claiming" a
|
|
|
|
// particular KIID.
|
|
|
|
|
|
|
|
for( const SCH_SHEET_PATH& sheet : m_frame->Schematic().GetSheets() )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = sheet.LastScreen();
|
|
|
|
|
2021-11-25 12:16:42 +00:00
|
|
|
for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
|
2021-11-24 11:04:07 +00:00
|
|
|
{
|
2021-11-25 12:16:42 +00:00
|
|
|
processItem( item );
|
2021-11-24 11:04:07 +00:00
|
|
|
|
2021-11-25 12:16:42 +00:00
|
|
|
for( SCH_PIN* pin : static_cast<SCH_SYMBOL*>( item )->GetPins( &sheet ) )
|
2021-11-24 11:04:07 +00:00
|
|
|
processItem( pin );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( const SCH_SHEET_PATH& sheet : m_frame->Schematic().GetSheets() )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = sheet.LastScreen();
|
|
|
|
|
2021-11-25 12:16:42 +00:00
|
|
|
for( SCH_ITEM* item : screen->Items() )
|
2021-11-24 11:04:07 +00:00
|
|
|
{
|
2021-11-25 12:16:42 +00:00
|
|
|
processItem( item );
|
2021-11-24 11:04:07 +00:00
|
|
|
|
2021-11-25 12:16:42 +00:00
|
|
|
item->RunOnChildren(
|
2021-11-24 11:04:07 +00:00
|
|
|
[&]( SCH_ITEM* aChild )
|
|
|
|
{
|
2021-11-25 12:16:42 +00:00
|
|
|
processItem( item );
|
2021-11-24 11:04:07 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************
|
|
|
|
* Your test here
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*******************************
|
|
|
|
* Inform the user
|
|
|
|
*/
|
|
|
|
|
|
|
|
if( duplicates )
|
|
|
|
{
|
|
|
|
errors += duplicates;
|
|
|
|
details += wxString::Format( _( "%d duplicate IDs replaced.\n" ), duplicates );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( errors )
|
|
|
|
{
|
|
|
|
m_frame->OnModify();
|
|
|
|
|
|
|
|
wxString msg = wxString::Format( _( "%d potential problems repaired." ), errors );
|
|
|
|
|
|
|
|
if( !quiet )
|
|
|
|
DisplayInfoMessage( m_frame, msg, details );
|
|
|
|
}
|
|
|
|
else if( !quiet )
|
|
|
|
{
|
|
|
|
DisplayInfoMessage( m_frame, _( "No errors found." ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-31 02:06:49 +00:00
|
|
|
int SCH_EDITOR_CONTROL::GridFeedback( const TOOL_EVENT& aEvent )
|
|
|
|
{
|
|
|
|
if( !Pgm().GetCommonSettings()->m_Input.hotkey_feedback )
|
|
|
|
return 0;
|
|
|
|
|
2023-08-30 15:21:56 +00:00
|
|
|
GRID_SETTINGS& gridSettings = m_toolMgr->GetSettings()->m_Window.grid;
|
2023-05-31 02:06:49 +00:00
|
|
|
int currentIdx = m_toolMgr->GetSettings()->m_Window.grid.last_size_idx;
|
|
|
|
|
|
|
|
wxArrayString gridsLabels;
|
|
|
|
|
2023-08-30 15:21:56 +00:00
|
|
|
for( const GRID& grid : gridSettings.grids )
|
|
|
|
gridsLabels.Add( grid.UserUnitsMessageText( m_frame ) );
|
2023-05-31 02:06:49 +00:00
|
|
|
|
|
|
|
if( !m_frame->GetHotkeyPopup() )
|
|
|
|
m_frame->CreateHotkeyPopup();
|
|
|
|
|
|
|
|
HOTKEY_CYCLE_POPUP* popup = m_frame->GetHotkeyPopup();
|
|
|
|
|
|
|
|
if( popup )
|
|
|
|
popup->Popup( _( "Grid" ), gridsLabels, currentIdx );
|
|
|
|
|
|
|
|
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() );
|
2021-11-24 11:04:07 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::SaveCurrSheetCopyAs, EE_ACTIONS::saveCurrSheetCopyAs.MakeEvent() );
|
2022-04-17 17:14:50 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::Revert, ACTIONS::revert.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() );
|
|
|
|
|
2022-07-19 15:00:35 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::CrossProbeToPcb, EVENTS::PointSelectedEvent );
|
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 );
|
2022-01-16 20:29:03 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::ExplicitCrossProbeToPcb, EE_ACTIONS::selectOnPCB.MakeEvent() );
|
2019-04-29 21:17:26 +00:00
|
|
|
|
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
|
|
|
|
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-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
|
|
|
|
2023-05-31 02:06:49 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::GridFeedback, EVENTS::GridChangedByKeyEvent );
|
|
|
|
|
2021-02-14 18:29:27 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::EditWithSymbolEditor, EE_ACTIONS::editWithLibEdit.MakeEvent() );
|
2023-12-28 23:25:47 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::EditWithSymbolEditor,
|
|
|
|
EE_ACTIONS::editLibSymbolWithLibEdit.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() );
|
2023-12-28 23:25:47 +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() );
|
2023-09-20 15:12:03 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::GenerateBOMLegacy, EE_ACTIONS::generateBOMLegacy.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
|
|
|
|
2023-05-15 01:35:39 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::ShowSearch, EE_ACTIONS::showSearch.MakeEvent() );
|
2022-06-02 21:56:17 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::ShowHierarchy, EE_ACTIONS::showHierarchy.MakeEvent() );
|
2023-05-20 17:47:12 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::ShowNetNavigator, EE_ACTIONS::showNetNavigator.MakeEvent() );
|
2023-06-21 01:57:20 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::ToggleProperties, ACTIONS::showProperties.MakeEvent() );
|
2019-05-13 20:42:40 +00:00
|
|
|
|
|
|
|
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() );
|
2023-04-27 16:59:53 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::ToggleDirectiveLabels, EE_ACTIONS::toggleDirectiveLabels.MakeEvent() );
|
2021-11-05 21:16:26 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::ToggleERCWarnings, EE_ACTIONS::toggleERCWarnings.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::ToggleERCErrors, EE_ACTIONS::toggleERCErrors.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::ToggleERCExclusions, EE_ACTIONS::toggleERCExclusions.MakeEvent() );
|
2023-02-09 17:18:56 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::ToggleOPVoltages, EE_ACTIONS::toggleOPVoltages.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::ToggleOPCurrents, EE_ACTIONS::toggleOPCurrents.MakeEvent() );
|
2022-03-22 16:49:38 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::ChangeLineMode, EE_ACTIONS::lineModeFree.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::ChangeLineMode, EE_ACTIONS::lineMode90.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::ChangeLineMode, EE_ACTIONS::lineMode45.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::NextLineMode, EE_ACTIONS::lineModeNext.MakeEvent() );
|
2022-04-21 17:06:28 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::ToggleAnnotateAuto, EE_ACTIONS::toggleAnnotateAuto.MakeEvent() );
|
2021-03-18 13:28:04 +00:00
|
|
|
|
2021-11-24 11:04:07 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::TogglePythonConsole, EE_ACTIONS::showPythonConsole.MakeEvent() );
|
2024-01-20 23:35:29 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::ReloadPlugins, ACTIONS::pluginsReload.MakeEvent() );
|
2021-11-24 11:04:07 +00:00
|
|
|
|
|
|
|
Go( &SCH_EDITOR_CONTROL::RepairSchematic, EE_ACTIONS::repairSchematic.MakeEvent() );
|
2022-09-16 03:06:23 +00:00
|
|
|
|
2023-05-20 17:47:12 +00:00
|
|
|
Go( &SCH_EDITOR_CONTROL::ExportSymbolsToLibrary,
|
|
|
|
EE_ACTIONS::exportSymbolsToLibrary.MakeEvent() );
|
|
|
|
Go( &SCH_EDITOR_CONTROL::ExportSymbolsToLibrary,
|
|
|
|
EE_ACTIONS::exportSymbolsToNewLibrary.MakeEvent() );
|
2019-04-14 00:44:05 +00:00
|
|
|
}
|