2019-01-23 10:30:10 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-03-09 11:25:32 +00:00
|
|
|
* Copyright (C) 2019-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-01-23 10:30:10 +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-3.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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
/**
|
|
|
|
* @file pcbnew/cross-probing.cpp
|
2019-07-17 20:21:22 +00:00
|
|
|
* @brief Cross probing functions to handle communication to and from Eeschema.
|
2011-09-30 18:15:37 +00:00
|
|
|
* Handle messages between Pcbnew and Eeschema via a socket, the port numbers are
|
|
|
|
* KICAD_PCB_PORT_SERVICE_NUMBER (currently 4242) (Eeschema to Pcbnew)
|
|
|
|
* KICAD_SCH_PORT_SERVICE_NUMBER (currently 4243) (Pcbnew to Eeschema)
|
2008-11-06 17:55:32 +00:00
|
|
|
* Note: these ports must be enabled for firewall protection
|
|
|
|
*/
|
2007-10-07 09:49:08 +00:00
|
|
|
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <board_design_settings.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <footprint.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad.h>
|
2021-06-11 21:07:02 +00:00
|
|
|
#include <pcb_track.h>
|
2022-07-19 15:00:35 +00:00
|
|
|
#include <pcb_group.h>
|
2021-06-03 18:05:43 +00:00
|
|
|
#include <zone.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <collectors.h>
|
2020-05-24 17:30:23 +00:00
|
|
|
#include <eda_dde.h>
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2020-05-24 17:30:23 +00:00
|
|
|
#include <kiway_express.h>
|
2022-01-16 20:29:03 +00:00
|
|
|
#include <string_utils.h>
|
2019-11-17 12:58:38 +00:00
|
|
|
#include <netlist_reader/pcb_netlist.h>
|
2020-07-16 17:31:36 +00:00
|
|
|
#include <netlist_reader/board_netlist_updater.h>
|
2020-10-14 11:29:36 +00:00
|
|
|
#include <painter.h>
|
2020-05-24 17:30:23 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2020-06-28 02:48:48 +00:00
|
|
|
#include <pcbnew_settings.h>
|
2020-10-14 11:29:36 +00:00
|
|
|
#include <render_settings.h>
|
2015-05-05 18:39:41 +00:00
|
|
|
#include <tool/tool_manager.h>
|
2020-05-24 17:30:23 +00:00
|
|
|
#include <tools/pcb_actions.h>
|
2020-12-16 13:31:32 +00:00
|
|
|
#include <tools/pcb_selection_tool.h>
|
2020-07-16 17:31:36 +00:00
|
|
|
#include <netlist_reader/netlist_reader.h>
|
2021-06-03 12:11:15 +00:00
|
|
|
#include <wx/log.h>
|
2007-10-07 09:49:08 +00:00
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
/* Execute a remote command sent via a socket on port KICAD_PCB_PORT_SERVICE_NUMBER
|
|
|
|
*
|
2022-05-09 20:21:49 +00:00
|
|
|
* Commands are:
|
2023-03-09 11:25:32 +00:00
|
|
|
*
|
|
|
|
* $NET: "net name" Highlight the given net
|
2022-05-09 20:21:49 +00:00
|
|
|
* $NETS: "net name 1,net name 2" Highlight all given nets
|
2023-03-09 11:25:32 +00:00
|
|
|
* $CLEAR Clear existing highlight
|
|
|
|
*
|
|
|
|
* $CONFIG Show the Manage Footprint Libraries dialog
|
|
|
|
* $CUSTOM_RULES Show the "Custom Rules" page of the Board Setup dialog
|
|
|
|
* $DRC Show the DRC dialog
|
2007-10-07 09:49:08 +00:00
|
|
|
*/
|
2014-01-08 14:18:51 +00:00
|
|
|
void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
|
2007-10-07 09:49:08 +00:00
|
|
|
{
|
2016-01-25 15:16:05 +00:00
|
|
|
char line[1024];
|
|
|
|
wxString msg;
|
|
|
|
wxString modName;
|
|
|
|
char* idcmd;
|
|
|
|
char* text;
|
2019-06-26 18:35:56 +00:00
|
|
|
int netcode = -1;
|
2020-05-24 17:30:23 +00:00
|
|
|
bool multiHighlight = false;
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint = nullptr;
|
2020-11-13 02:57:11 +00:00
|
|
|
PAD* pad = nullptr;
|
2016-01-25 15:16:05 +00:00
|
|
|
BOARD* pcb = GetBoard();
|
2019-06-26 18:35:56 +00:00
|
|
|
|
2022-07-24 15:49:46 +00:00
|
|
|
CROSS_PROBING_SETTINGS& crossProbingSettings = GetPcbNewSettings()->m_CrossProbing;
|
2020-06-28 02:48:48 +00:00
|
|
|
|
2019-06-26 18:35:56 +00:00
|
|
|
KIGFX::VIEW* view = m_toolManager->GetView();
|
|
|
|
KIGFX::RENDER_SETTINGS* renderSettings = view->GetPainter()->GetSettings();
|
2007-10-07 09:49:08 +00:00
|
|
|
|
|
|
|
strncpy( line, cmdline, sizeof(line) - 1 );
|
2015-01-19 19:03:50 +00:00
|
|
|
line[sizeof(line) - 1] = 0;
|
2007-10-07 09:49:08 +00:00
|
|
|
|
|
|
|
idcmd = strtok( line, " \n\r" );
|
2021-07-19 23:56:05 +00:00
|
|
|
text = strtok( nullptr, "\"\n\r" );
|
2008-02-19 07:06:58 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( idcmd == nullptr )
|
2018-01-06 20:50:49 +00:00
|
|
|
return;
|
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
if( strcmp( idcmd, "$CONFIG" ) == 0 )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
GetToolManager()->RunAction( ACTIONS::showSymbolLibTable );
|
2023-03-09 11:25:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if( strcmp( idcmd, "$CUSTOM_RULES" ) == 0 )
|
|
|
|
{
|
|
|
|
ShowBoardSetupDialog( _( "Custom Rules" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if( strcmp( idcmd, "$DRC" ) == 0 )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
GetToolManager()->RunAction( PCB_ACTIONS::runDRC );
|
2023-03-09 11:25:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if( strcmp( idcmd, "$CLEAR" ) == 0 )
|
|
|
|
{
|
|
|
|
if( renderSettings->IsHighlightEnabled() )
|
|
|
|
{
|
|
|
|
renderSettings->SetHighlight( false );
|
|
|
|
view->UpdateAllLayersColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( pcb->IsHighLightNetON() )
|
|
|
|
{
|
|
|
|
pcb->ResetNetHighLight();
|
|
|
|
SetMsgPanel( pcb );
|
|
|
|
}
|
|
|
|
|
|
|
|
GetCanvas()->Refresh();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if( strcmp( idcmd, "$NET:" ) == 0 )
|
2018-01-06 20:50:49 +00:00
|
|
|
{
|
2020-06-28 02:48:48 +00:00
|
|
|
if( !crossProbingSettings.auto_highlight )
|
|
|
|
return;
|
|
|
|
|
2019-06-26 18:35:56 +00:00
|
|
|
wxString net_name = FROM_UTF8( text );
|
2018-01-06 20:50:49 +00:00
|
|
|
|
2019-06-26 18:35:56 +00:00
|
|
|
NETINFO_ITEM* netinfo = pcb->FindNet( net_name );
|
2018-01-06 20:50:49 +00:00
|
|
|
|
2019-06-26 18:35:56 +00:00
|
|
|
if( netinfo )
|
|
|
|
{
|
2020-12-08 13:02:08 +00:00
|
|
|
netcode = netinfo->GetNetCode();
|
2019-05-04 20:18:41 +00:00
|
|
|
|
2021-09-26 23:22:32 +00:00
|
|
|
std::vector<MSG_PANEL_ITEM> items;
|
2020-04-24 13:36:10 +00:00
|
|
|
netinfo->GetMsgPanelInfo( this, items );
|
2019-06-26 18:35:56 +00:00
|
|
|
SetMsgPanel( items );
|
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
// fall through to hihglighting section
|
|
|
|
}
|
|
|
|
else if( strcmp( idcmd, "$NETS:" ) == 0 )
|
2020-05-24 17:30:23 +00:00
|
|
|
{
|
2020-06-28 02:48:48 +00:00
|
|
|
if( !crossProbingSettings.auto_highlight )
|
|
|
|
return;
|
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
wxStringTokenizer netsTok = wxStringTokenizer( FROM_UTF8( text ), wxT( "," ) );
|
2020-05-24 17:30:23 +00:00
|
|
|
bool first = true;
|
|
|
|
|
|
|
|
while( netsTok.HasMoreTokens() )
|
|
|
|
{
|
|
|
|
NETINFO_ITEM* netinfo = pcb->FindNet( netsTok.GetNextToken() );
|
|
|
|
|
|
|
|
if( netinfo )
|
|
|
|
{
|
|
|
|
if( first )
|
|
|
|
{
|
|
|
|
// TODO: Once buses are included in netlist, show bus name
|
2021-09-26 23:22:32 +00:00
|
|
|
std::vector<MSG_PANEL_ITEM> items;
|
2020-05-24 17:30:23 +00:00
|
|
|
netinfo->GetMsgPanelInfo( this, items );
|
|
|
|
SetMsgPanel( items );
|
|
|
|
first = false;
|
|
|
|
|
2020-12-08 13:02:08 +00:00
|
|
|
pcb->SetHighLightNet( netinfo->GetNetCode() );
|
|
|
|
renderSettings->SetHighlight( true, netinfo->GetNetCode() );
|
2020-05-24 17:30:23 +00:00
|
|
|
multiHighlight = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-08 13:02:08 +00:00
|
|
|
pcb->SetHighLightNet( netinfo->GetNetCode(), true );
|
|
|
|
renderSettings->SetHighlight( true, netinfo->GetNetCode(), true );
|
2020-05-24 17:30:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
netcode = -1;
|
2007-10-07 09:49:08 +00:00
|
|
|
|
2023-03-09 11:25:32 +00:00
|
|
|
// fall through to highlighting section
|
2019-06-26 18:35:56 +00:00
|
|
|
}
|
2019-01-23 10:30:10 +00:00
|
|
|
|
2022-08-31 09:15:42 +00:00
|
|
|
BOX2I bbox;
|
2019-07-16 19:15:07 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
if( footprint )
|
2019-06-26 18:35:56 +00:00
|
|
|
{
|
2021-02-26 13:49:40 +00:00
|
|
|
bbox = footprint->GetBoundingBox( true, false ); // No invisible text in bbox calc
|
2020-01-20 17:35:20 +00:00
|
|
|
|
|
|
|
if( pad )
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolManager->RunAction<BOARD_ITEM*>( PCB_ACTIONS::highlightItem, pad );
|
2020-01-20 17:35:20 +00:00
|
|
|
else
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolManager->RunAction<BOARD_ITEM*>( PCB_ACTIONS::highlightItem, footprint );
|
2019-06-26 18:35:56 +00:00
|
|
|
}
|
2020-05-24 17:30:23 +00:00
|
|
|
else if( netcode > 0 || multiHighlight )
|
2019-06-26 18:35:56 +00:00
|
|
|
{
|
2020-05-24 17:30:23 +00:00
|
|
|
if( !multiHighlight )
|
|
|
|
{
|
|
|
|
renderSettings->SetHighlight( ( netcode >= 0 ), netcode );
|
|
|
|
pcb->SetHighLightNet( netcode );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Just pick the first one for area calculation
|
|
|
|
netcode = *pcb->GetHighLightNetCodes().begin();
|
|
|
|
}
|
2007-10-07 09:49:08 +00:00
|
|
|
|
2020-04-13 11:37:42 +00:00
|
|
|
pcb->HighLightON();
|
2008-12-08 15:27:13 +00:00
|
|
|
|
2020-10-02 12:29:17 +00:00
|
|
|
auto merge_area =
|
2022-08-31 09:15:42 +00:00
|
|
|
[netcode, &bbox]( BOARD_CONNECTED_ITEM* aItem )
|
|
|
|
{
|
|
|
|
if( aItem->GetNetCode() == netcode )
|
|
|
|
bbox.Merge( aItem->GetBoundingBox() );
|
|
|
|
};
|
2007-10-07 09:49:08 +00:00
|
|
|
|
2020-06-28 02:48:48 +00:00
|
|
|
if( crossProbingSettings.center_on_items )
|
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
for( ZONE* zone : pcb->Zones() )
|
2020-06-28 02:48:48 +00:00
|
|
|
merge_area( zone );
|
2007-10-07 09:49:08 +00:00
|
|
|
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* track : pcb->Tracks() )
|
2020-06-28 02:48:48 +00:00
|
|
|
merge_area( track );
|
2007-10-07 09:49:08 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* fp : pcb->Footprints() )
|
2020-11-12 23:50:33 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
for( PAD* p : fp->Pads() )
|
|
|
|
merge_area( p );
|
2020-11-12 23:50:33 +00:00
|
|
|
}
|
2020-06-28 02:48:48 +00:00
|
|
|
}
|
2019-06-26 18:35:56 +00:00
|
|
|
}
|
|
|
|
else
|
2011-02-25 19:09:42 +00:00
|
|
|
{
|
2019-06-26 18:35:56 +00:00
|
|
|
renderSettings->SetHighlight( false );
|
2011-02-25 19:09:42 +00:00
|
|
|
}
|
2019-06-26 18:35:56 +00:00
|
|
|
|
2022-07-19 15:00:35 +00:00
|
|
|
if( crossProbingSettings.center_on_items && bbox.GetWidth() != 0 && bbox.GetHeight() != 0 )
|
2019-07-16 19:15:07 +00:00
|
|
|
{
|
2021-02-28 15:39:51 +00:00
|
|
|
if( crossProbingSettings.zoom_to_fit )
|
2022-07-19 15:00:35 +00:00
|
|
|
GetToolManager()->GetTool<PCB_SELECTION_TOOL>()->ZoomFitCrossProbeBBox( bbox );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2022-08-30 14:13:51 +00:00
|
|
|
FocusOnLocation( bbox.Centre() );
|
2019-07-16 19:15:07 +00:00
|
|
|
}
|
|
|
|
|
2019-06-26 18:35:56 +00:00
|
|
|
view->UpdateAllLayersColor();
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-06-26 18:35:56 +00:00
|
|
|
// Ensure the display is refreshed, because in some installs the refresh is done only
|
|
|
|
// when the gal canvas has the focus, and that is not the case when crossprobing from
|
|
|
|
// Eeschema:
|
|
|
|
GetCanvas()->Refresh();
|
2007-10-07 09:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-21 06:28:17 +00:00
|
|
|
std::string FormatProbeItem( BOARD_ITEM* aItem )
|
2007-10-07 09:49:08 +00:00
|
|
|
{
|
2018-12-24 11:17:35 +00:00
|
|
|
if( !aItem )
|
2018-12-31 12:54:26 +00:00
|
|
|
return "$CLEAR: \"HIGHLIGHTED\""; // message to clear highlight state
|
2018-12-24 11:17:35 +00:00
|
|
|
|
2014-04-21 06:28:17 +00:00
|
|
|
switch( aItem->Type() )
|
2007-10-07 09:49:08 +00:00
|
|
|
{
|
2020-11-13 12:21:02 +00:00
|
|
|
case PCB_FOOTPRINT_T:
|
2023-03-30 11:49:23 +00:00
|
|
|
{
|
|
|
|
FOOTPRINT* footprint = static_cast<FOOTPRINT*>( aItem );
|
2020-11-13 02:57:11 +00:00
|
|
|
return StrPrintf( "$PART: \"%s\"", TO_UTF8( footprint->GetReference() ) );
|
2023-03-30 11:49:23 +00:00
|
|
|
}
|
2007-10-07 09:49:08 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_PAD_T:
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
PAD* pad = static_cast<PAD*>( aItem );
|
|
|
|
FOOTPRINT* footprint = pad->GetParentFootprint();
|
2014-04-21 06:28:17 +00:00
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
return StrPrintf( "$PART: \"%s\" $PAD: \"%s\"",
|
|
|
|
TO_UTF8( footprint->GetReference() ),
|
2023-03-30 11:49:23 +00:00
|
|
|
TO_UTF8( pad->GetNumber() ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2007-10-07 09:49:08 +00:00
|
|
|
|
2023-06-06 15:09:34 +00:00
|
|
|
case PCB_FIELD_T:
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2023-06-06 17:30:03 +00:00
|
|
|
PCB_FIELD* field = static_cast<PCB_FIELD*>( aItem );
|
|
|
|
FOOTPRINT* footprint = field->GetParentFootprint();
|
2021-07-19 23:56:05 +00:00
|
|
|
const char* text_key;
|
2014-04-21 06:28:17 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
/* This can't be a switch since the break need to pull out
|
|
|
|
* from the outer switch! */
|
2023-06-06 17:30:03 +00:00
|
|
|
if( field->IsReference() )
|
2021-07-19 23:56:05 +00:00
|
|
|
text_key = "$REF:";
|
2023-06-06 17:30:03 +00:00
|
|
|
else if( field->IsValue() )
|
2021-07-19 23:56:05 +00:00
|
|
|
text_key = "$VAL:";
|
|
|
|
else
|
|
|
|
break;
|
2014-04-21 06:28:17 +00:00
|
|
|
|
2022-01-30 10:52:52 +00:00
|
|
|
return StrPrintf( "$PART: \"%s\" %s \"%s\"",
|
|
|
|
TO_UTF8( footprint->GetReference() ),
|
|
|
|
text_key,
|
2023-06-06 17:30:03 +00:00
|
|
|
TO_UTF8( field->GetText() ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2007-10-07 09:49:08 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-04-21 06:28:17 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-19 15:00:35 +00:00
|
|
|
template <typename ItemContainer>
|
|
|
|
void collectItemsForSyncParts( ItemContainer& aItems, std::set<wxString>& parts )
|
2014-04-21 06:28:17 +00:00
|
|
|
{
|
2022-07-19 15:00:35 +00:00
|
|
|
for( EDA_ITEM* item : aItems )
|
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case PCB_GROUP_T:
|
|
|
|
{
|
|
|
|
PCB_GROUP* group = static_cast<PCB_GROUP*>( item );
|
|
|
|
|
|
|
|
collectItemsForSyncParts( group->GetItems(), parts );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PCB_FOOTPRINT_T:
|
|
|
|
{
|
|
|
|
FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
|
|
|
|
wxString ref = footprint->GetReference();
|
|
|
|
|
|
|
|
parts.emplace( wxT( "F" ) + EscapeString( ref, CTX_IPC ) );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case PCB_PAD_T:
|
|
|
|
{
|
2023-03-30 11:49:23 +00:00
|
|
|
PAD* pad = static_cast<PAD*>( item );
|
|
|
|
wxString ref = pad->GetParentFootprint()->GetReference();
|
2022-07-19 15:00:35 +00:00
|
|
|
|
|
|
|
parts.emplace( wxT( "P" ) + EscapeString( ref, CTX_IPC ) + wxT( "/" )
|
|
|
|
+ EscapeString( pad->GetNumber(), CTX_IPC ) );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_EDIT_FRAME::SendSelectItemsToSch( const std::deque<EDA_ITEM*>& aItems,
|
|
|
|
EDA_ITEM* aFocusItem, bool aForce )
|
|
|
|
{
|
|
|
|
std::string command = "$SELECT: ";
|
|
|
|
|
|
|
|
if( aFocusItem )
|
|
|
|
{
|
|
|
|
std::deque<EDA_ITEM*> focusItems = { aFocusItem };
|
|
|
|
std::set<wxString> focusParts;
|
|
|
|
collectItemsForSyncParts( focusItems, focusParts );
|
|
|
|
|
|
|
|
if( focusParts.size() > 0 )
|
|
|
|
{
|
|
|
|
command += "1,";
|
|
|
|
command += *focusParts.begin();
|
|
|
|
command += ",";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
command += "0,";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
command += "0,";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::set<wxString> parts;
|
|
|
|
collectItemsForSyncParts( aItems, parts );
|
|
|
|
|
|
|
|
if( parts.empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
for( wxString part : parts )
|
|
|
|
{
|
|
|
|
command += part;
|
|
|
|
command += ",";
|
|
|
|
}
|
|
|
|
|
|
|
|
command.pop_back();
|
|
|
|
|
|
|
|
if( Kiface().IsSingle() )
|
|
|
|
{
|
|
|
|
SendCommand( MSG_TO_PCB, command );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Typically ExpressMail is going to be s-expression packets, but since
|
|
|
|
// we have existing interpreter of the selection packet on the other
|
|
|
|
// side in place, we use that here.
|
|
|
|
Kiway().ExpressMail( FRAME_SCH, aForce ? MAIL_SELECTION_FORCE : MAIL_SELECTION, command,
|
|
|
|
this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_EDIT_FRAME::SendCrossProbeNetName( const wxString& aNetName )
|
|
|
|
{
|
|
|
|
std::string packet = StrPrintf( "$NET: \"%s\"", TO_UTF8( aNetName ) );
|
2014-04-21 06:28:17 +00:00
|
|
|
|
2019-07-17 20:21:22 +00:00
|
|
|
if( !packet.empty() )
|
2018-01-06 20:50:49 +00:00
|
|
|
{
|
|
|
|
if( Kiface().IsSingle() )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2021-03-22 01:58:53 +00:00
|
|
|
SendCommand( MSG_TO_SCH, packet );
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2018-01-06 20:50:49 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Typically ExpressMail is going to be s-expression packets, but since
|
|
|
|
// we have existing interpreter of the cross probe packet on the other
|
|
|
|
// side in place, we use that here.
|
|
|
|
Kiway().ExpressMail( FRAME_SCH, MAIL_CROSS_PROBE, packet, this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-19 15:00:35 +00:00
|
|
|
void PCB_EDIT_FRAME::SendCrossProbeItem( BOARD_ITEM* aSyncItem )
|
2018-01-06 20:50:49 +00:00
|
|
|
{
|
2022-07-19 15:00:35 +00:00
|
|
|
std::string packet = FormatProbeItem( aSyncItem );
|
2018-01-06 20:50:49 +00:00
|
|
|
|
2019-07-17 20:21:22 +00:00
|
|
|
if( !packet.empty() )
|
2007-10-07 09:49:08 +00:00
|
|
|
{
|
2014-04-20 04:35:34 +00:00
|
|
|
if( Kiface().IsSingle() )
|
2021-07-19 23:56:05 +00:00
|
|
|
{
|
2021-03-22 01:58:53 +00:00
|
|
|
SendCommand( MSG_TO_SCH, packet );
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2014-04-20 04:35:34 +00:00
|
|
|
else
|
|
|
|
{
|
2014-04-21 14:49:33 +00:00
|
|
|
// Typically ExpressMail is going to be s-expression packets, but since
|
|
|
|
// we have existing interpreter of the cross probe packet on the other
|
|
|
|
// side in place, we use that here.
|
|
|
|
Kiway().ExpressMail( FRAME_SCH, MAIL_CROSS_PROBE, packet, this );
|
2014-04-20 04:35:34 +00:00
|
|
|
}
|
2007-10-07 09:49:08 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-21 06:28:17 +00:00
|
|
|
|
2014-04-21 06:51:33 +00:00
|
|
|
|
2022-01-16 20:29:03 +00:00
|
|
|
std::vector<BOARD_ITEM*> PCB_EDIT_FRAME::FindItemsFromSyncSelection( std::string syncStr )
|
|
|
|
{
|
|
|
|
wxArrayString syncArray = wxStringTokenize( syncStr, "," );
|
|
|
|
|
2022-09-20 19:06:11 +00:00
|
|
|
std::vector<std::pair<int, BOARD_ITEM*>> orderPairs;
|
2022-01-16 20:29:03 +00:00
|
|
|
|
|
|
|
for( FOOTPRINT* footprint : GetBoard()->Footprints() )
|
|
|
|
{
|
|
|
|
if( footprint == nullptr )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
wxString fpSheetPath = footprint->GetPath().AsString().BeforeLast( '/' );
|
|
|
|
wxString fpUUID = footprint->m_Uuid.AsString();
|
|
|
|
|
|
|
|
if( fpSheetPath.IsEmpty() )
|
|
|
|
fpSheetPath += '/';
|
|
|
|
|
|
|
|
if( fpUUID.empty() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
wxString fpRefEscaped = EscapeString( footprint->GetReference(), CTX_IPC );
|
|
|
|
|
2022-09-20 19:06:11 +00:00
|
|
|
for( unsigned index = 0; index < syncArray.size(); ++index )
|
2022-01-16 20:29:03 +00:00
|
|
|
{
|
2022-09-20 19:06:11 +00:00
|
|
|
wxString syncEntry = syncArray[index];
|
|
|
|
|
2022-01-16 20:29:03 +00:00
|
|
|
if( syncEntry.empty() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
wxString syncData = syncEntry.substr( 1 );
|
|
|
|
|
|
|
|
switch( syncEntry.GetChar( 0 ).GetValue() )
|
|
|
|
{
|
|
|
|
case 'S': // Select sheet with subsheets: S<Sheet path>
|
|
|
|
if( fpSheetPath.StartsWith( syncData ) )
|
|
|
|
{
|
2022-09-20 19:06:11 +00:00
|
|
|
orderPairs.emplace_back( index, footprint );
|
2022-01-16 20:29:03 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'F': // Select footprint: F<Reference>
|
|
|
|
if( syncData == fpRefEscaped )
|
|
|
|
{
|
2022-09-20 19:06:11 +00:00
|
|
|
orderPairs.emplace_back( index, footprint );
|
2022-01-16 20:29:03 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'P': // Select pad: P<Footprint reference>/<Pad number>
|
|
|
|
{
|
|
|
|
if( syncData.StartsWith( fpRefEscaped ) )
|
|
|
|
{
|
|
|
|
wxString selectPadNumberEscaped =
|
|
|
|
syncData.substr( fpRefEscaped.size() + 1 ); // Skips the slash
|
|
|
|
|
|
|
|
wxString selectPadNumber = UnescapeString( selectPadNumberEscaped );
|
|
|
|
|
|
|
|
for( PAD* pad : footprint->Pads() )
|
|
|
|
{
|
|
|
|
if( selectPadNumber == pad->GetNumber() )
|
|
|
|
{
|
2022-09-20 19:06:11 +00:00
|
|
|
orderPairs.emplace_back( index, pad );
|
2022-01-16 20:29:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-20 19:06:11 +00:00
|
|
|
std::sort(
|
|
|
|
orderPairs.begin(), orderPairs.end(),
|
|
|
|
[]( const std::pair<int, BOARD_ITEM*>& a, const std::pair<int, BOARD_ITEM*>& b ) -> bool
|
|
|
|
{
|
|
|
|
return a.first < b.first;
|
|
|
|
} );
|
|
|
|
|
|
|
|
std::vector<BOARD_ITEM*> items;
|
|
|
|
items.reserve( orderPairs.size() );
|
|
|
|
|
|
|
|
for( const std::pair<int, BOARD_ITEM*>& pair : orderPairs )
|
|
|
|
items.push_back( pair.second );
|
|
|
|
|
2022-01-16 20:29:03 +00:00
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-21 06:51:33 +00:00
|
|
|
void PCB_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
|
|
|
|
{
|
2020-01-29 16:33:57 +00:00
|
|
|
std::string& payload = mail.GetPayload();
|
2014-04-21 14:49:33 +00:00
|
|
|
|
|
|
|
switch( mail.Command() )
|
|
|
|
{
|
2020-01-29 16:33:57 +00:00
|
|
|
case MAIL_PCB_GET_NETLIST:
|
|
|
|
{
|
|
|
|
NETLIST netlist;
|
|
|
|
STRING_FORMATTER sf;
|
2020-06-08 18:36:25 +00:00
|
|
|
|
2021-02-09 16:35:43 +00:00
|
|
|
for( FOOTPRINT* footprint : GetBoard()->Footprints() )
|
2020-01-29 16:33:57 +00:00
|
|
|
{
|
2021-01-19 23:17:13 +00:00
|
|
|
if( footprint->GetAttributes() & FP_BOARD_ONLY )
|
|
|
|
continue; // Don't add board-only footprints to the netlist
|
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
COMPONENT* component = new COMPONENT( footprint->GetFPID(), footprint->GetReference(),
|
2021-02-21 04:03:56 +00:00
|
|
|
footprint->GetValue(), footprint->GetPath(), {} );
|
2020-06-08 18:36:25 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2020-06-08 18:36:25 +00:00
|
|
|
{
|
|
|
|
const wxString& netname = pad->GetShortNetname();
|
|
|
|
|
|
|
|
if( !netname.IsEmpty() )
|
2021-01-21 21:46:03 +00:00
|
|
|
{
|
2021-08-23 23:10:21 +00:00
|
|
|
component->AddNet( pad->GetNumber(), netname, pad->GetPinFunction(),
|
2021-01-21 21:46:03 +00:00
|
|
|
pad->GetPinType() );
|
|
|
|
}
|
2020-06-08 18:36:25 +00:00
|
|
|
}
|
|
|
|
|
2023-07-31 14:38:02 +00:00
|
|
|
std::map<wxString, wxString> fields;
|
|
|
|
for( PCB_FIELD* field : footprint->Fields() )
|
|
|
|
fields[field->GetCanonicalName()] = field->GetText();
|
|
|
|
|
|
|
|
component->SetFields( fields );
|
|
|
|
|
2023-05-01 12:53:36 +00:00
|
|
|
// Add DNP and Exclude from BOM properties
|
|
|
|
std::map<wxString, wxString> properties;
|
|
|
|
|
|
|
|
if( footprint->GetAttributes() & FP_DNP )
|
|
|
|
properties.emplace( "dnp", "" );
|
|
|
|
|
|
|
|
if( footprint->GetAttributes() & FP_EXCLUDE_FROM_BOM )
|
|
|
|
properties.emplace( "exclude_from_bom", "" );
|
|
|
|
|
|
|
|
component->SetProperties( properties );
|
|
|
|
|
2020-06-08 18:36:25 +00:00
|
|
|
netlist.AddComponent( component );
|
2020-01-29 16:33:57 +00:00
|
|
|
}
|
2020-06-08 18:36:25 +00:00
|
|
|
|
|
|
|
netlist.Format( "pcb_netlist", &sf, 0, CTL_OMIT_FILTERS );
|
2020-01-29 16:33:57 +00:00
|
|
|
payload = sf.GetString();
|
2020-07-16 17:31:36 +00:00
|
|
|
break;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2020-07-16 17:31:36 +00:00
|
|
|
|
|
|
|
case MAIL_PCB_UPDATE_LINKS:
|
|
|
|
try
|
|
|
|
{
|
|
|
|
NETLIST netlist;
|
2021-01-30 16:30:35 +00:00
|
|
|
FetchNetlistFromSchematic( netlist, wxEmptyString );
|
2020-07-16 17:31:36 +00:00
|
|
|
|
|
|
|
BOARD_NETLIST_UPDATER updater( this, GetBoard() );
|
|
|
|
updater.SetLookupByTimestamp( false );
|
2021-05-23 21:21:34 +00:00
|
|
|
updater.SetDeleteUnusedFootprints( false );
|
2020-07-16 17:31:36 +00:00
|
|
|
updater.SetReplaceFootprints( false );
|
|
|
|
updater.UpdateNetlist( netlist );
|
|
|
|
|
|
|
|
bool dummy;
|
|
|
|
OnNetlistChanged( updater, &dummy );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& )
|
|
|
|
{
|
|
|
|
assert( false ); // should never happen
|
|
|
|
return;
|
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-07-16 17:31:36 +00:00
|
|
|
break;
|
|
|
|
|
2014-04-21 14:49:33 +00:00
|
|
|
case MAIL_CROSS_PROBE:
|
|
|
|
ExecuteRemoteCommand( payload.c_str() );
|
|
|
|
break;
|
2014-04-21 06:51:33 +00:00
|
|
|
|
2022-07-01 23:45:19 +00:00
|
|
|
|
2022-01-16 20:29:03 +00:00
|
|
|
case MAIL_SELECTION:
|
2022-07-24 15:49:46 +00:00
|
|
|
if( !GetPcbNewSettings()->m_CrossProbing.on_selection )
|
2022-07-01 23:45:19 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
KI_FALLTHROUGH;
|
|
|
|
|
|
|
|
case MAIL_SELECTION_FORCE:
|
2022-01-16 20:29:03 +00:00
|
|
|
{
|
|
|
|
// $SELECT: <mode 0 - only footprints, 1 - with connections>,<spec1>,<spec2>,<spec3>
|
|
|
|
std::string prefix = "$SELECT: ";
|
|
|
|
|
|
|
|
if( !payload.compare( 0, prefix.size(), prefix ) )
|
|
|
|
{
|
|
|
|
std::string del = ",";
|
|
|
|
std::string paramStr = payload.substr( prefix.size() );
|
|
|
|
int modeEnd = paramStr.find( del );
|
|
|
|
bool selectConnections = false;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if( std::stoi( paramStr.substr( 0, modeEnd ) ) == 1 )
|
|
|
|
selectConnections = true;
|
|
|
|
}
|
|
|
|
catch( std::invalid_argument& )
|
|
|
|
{
|
|
|
|
wxFAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<BOARD_ITEM*> items =
|
|
|
|
FindItemsFromSyncSelection( paramStr.substr( modeEnd + 1 ) );
|
|
|
|
|
2022-07-19 15:00:35 +00:00
|
|
|
m_probingSchToPcb = true; // recursion guard
|
2022-01-16 20:29:03 +00:00
|
|
|
|
|
|
|
if( selectConnections )
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
GetToolManager()->RunAction( PCB_ACTIONS::syncSelectionWithNets, &items );
|
2022-01-16 20:29:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-26 22:16:51 +00:00
|
|
|
GetToolManager()->RunAction( PCB_ACTIONS::syncSelection, &items );
|
2022-01-16 20:29:03 +00:00
|
|
|
}
|
|
|
|
|
2023-01-19 15:09:40 +00:00
|
|
|
// Update 3D viewer highlighting
|
|
|
|
Update3DView( false, GetPcbNewSettings()->m_Display.m_Live3DRefresh );
|
|
|
|
|
2022-07-19 15:00:35 +00:00
|
|
|
m_probingSchToPcb = false;
|
2022-01-16 20:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-03-27 22:37:26 +00:00
|
|
|
case MAIL_PCB_UPDATE:
|
2023-06-26 22:16:51 +00:00
|
|
|
m_toolManager->RunAction( ACTIONS::updatePcbFromSchematic );
|
2016-01-29 10:24:39 +00:00
|
|
|
break;
|
|
|
|
|
2018-02-26 10:34:36 +00:00
|
|
|
case MAIL_IMPORT_FILE:
|
|
|
|
{
|
|
|
|
// Extract file format type and path (plugin type and path separated with \n)
|
|
|
|
size_t split = payload.find( '\n' );
|
|
|
|
wxCHECK( split != std::string::npos, /*void*/ );
|
|
|
|
int importFormat;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
importFormat = std::stoi( payload.substr( 0, split ) );
|
|
|
|
}
|
2018-04-18 07:10:29 +00:00
|
|
|
catch( std::invalid_argument& )
|
2018-02-26 10:34:36 +00:00
|
|
|
{
|
|
|
|
wxFAIL;
|
|
|
|
importFormat = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string path = payload.substr( split + 1 );
|
|
|
|
wxASSERT( !path.empty() );
|
|
|
|
|
|
|
|
if( importFormat >= 0 )
|
|
|
|
importFile( path, importFormat );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2020-07-16 17:31:36 +00:00
|
|
|
break;
|
2021-07-19 23:56:05 +00:00
|
|
|
}
|
2018-02-26 10:34:36 +00:00
|
|
|
|
2023-01-19 00:14:31 +00:00
|
|
|
case MAIL_RELOAD_PLUGINS:
|
2023-06-26 22:16:51 +00:00
|
|
|
GetToolManager()->RunAction( PCB_ACTIONS::pluginsReload );
|
2023-01-19 00:14:31 +00:00
|
|
|
break;
|
|
|
|
|
2014-04-21 14:49:33 +00:00
|
|
|
// many many others.
|
2014-07-07 04:12:04 +00:00
|
|
|
default:
|
|
|
|
;
|
2014-04-21 14:49:33 +00:00
|
|
|
}
|
2014-04-21 06:51:33 +00:00
|
|
|
}
|
|
|
|
|