2019-01-23 10:30:10 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2020-02-20 12:11:04 +00:00
|
|
|
* Copyright (C) 2019-2020 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>
|
|
|
|
#include <footprint.h>
|
|
|
|
#include <track.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <collectors.h>
|
2020-05-24 17:30:23 +00:00
|
|
|
#include <eda_dde.h>
|
|
|
|
#include <kiface_i.h>
|
|
|
|
#include <kiway_express.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>
|
2017-03-02 23:42:23 +00:00
|
|
|
#include <tools/selection_tool.h>
|
2020-07-16 17:31:36 +00:00
|
|
|
#include <netlist_reader/netlist_reader.h>
|
2007-10-07 09:49:08 +00:00
|
|
|
|
2014-01-08 14:18:51 +00:00
|
|
|
/* Execute a remote command send by Eeschema via a socket,
|
|
|
|
* port KICAD_PCB_PORT_SERVICE_NUMBER
|
|
|
|
* cmdline = received command from Eeschema
|
2007-10-07 09:49:08 +00:00
|
|
|
* Commands are
|
|
|
|
* $PART: "reference" put cursor on component
|
2007-10-07 18:24:15 +00:00
|
|
|
* $PIN: "pin name" $PART: "reference" put cursor on the footprint pin
|
2018-01-06 20:50:49 +00:00
|
|
|
* $NET: "net name" highlight the given net (if highlight tool is active)
|
2019-05-04 20:18:41 +00:00
|
|
|
* $CLEAR Clear existing highlight
|
2019-01-23 10:30:10 +00:00
|
|
|
* They are a keyword followed by a quoted string.
|
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
|
|
|
|
2020-06-28 02:48:48 +00:00
|
|
|
CROSS_PROBING_SETTINGS& crossProbingSettings = GetPcbNewSettings()->m_CrossProbing;
|
|
|
|
|
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" );
|
2019-01-23 10:30:10 +00:00
|
|
|
text = strtok( NULL, "\"\n\r" );
|
2008-02-19 07:06:58 +00:00
|
|
|
|
2018-01-06 20:50:49 +00:00
|
|
|
if( idcmd == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( strcmp( idcmd, "$NET:" ) == 0 )
|
|
|
|
{
|
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
|
|
|
|
2019-06-26 18:35:56 +00:00
|
|
|
MSG_PANEL_ITEMS items;
|
2020-04-24 13:36:10 +00:00
|
|
|
netinfo->GetMsgPanelInfo( this, items );
|
2019-06-26 18:35:56 +00:00
|
|
|
SetMsgPanel( items );
|
|
|
|
}
|
|
|
|
}
|
2020-05-24 17:30:23 +00:00
|
|
|
if( strcmp( idcmd, "$NETS:" ) == 0 )
|
|
|
|
{
|
2020-06-28 02:48:48 +00:00
|
|
|
if( !crossProbingSettings.auto_highlight )
|
|
|
|
return;
|
|
|
|
|
2020-05-24 17:30:23 +00:00
|
|
|
wxStringTokenizer netsTok = wxStringTokenizer( FROM_UTF8( text ), "," );
|
|
|
|
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
|
|
|
|
MSG_PANEL_ITEMS items;
|
|
|
|
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;
|
|
|
|
}
|
2019-06-26 18:35:56 +00:00
|
|
|
else if( strcmp( idcmd, "$PIN:" ) == 0 )
|
|
|
|
{
|
|
|
|
wxString pinName = FROM_UTF8( text );
|
2018-01-07 02:30:31 +00:00
|
|
|
|
2019-06-26 18:35:56 +00:00
|
|
|
text = strtok( NULL, " \n\r" );
|
2018-01-07 02:30:31 +00:00
|
|
|
|
2019-06-26 18:35:56 +00:00
|
|
|
if( text && strcmp( text, "$PART:" ) == 0 )
|
|
|
|
text = strtok( NULL, "\"\n\r" );
|
2019-05-27 16:16:54 +00:00
|
|
|
|
2019-06-26 18:35:56 +00:00
|
|
|
modName = FROM_UTF8( text );
|
2018-01-06 20:50:49 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint = pcb->FindFootprintByReference( modName );
|
2019-05-04 20:18:41 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
if( footprint )
|
|
|
|
pad = footprint->FindPadByName( pinName );
|
2019-05-04 20:18:41 +00:00
|
|
|
|
2019-06-26 18:35:56 +00:00
|
|
|
if( pad )
|
|
|
|
netcode = pad->GetNetCode();
|
2018-01-06 20:50:49 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
if( footprint == NULL )
|
2019-06-26 18:35:56 +00:00
|
|
|
msg.Printf( _( "%s not found" ), modName );
|
|
|
|
else if( pad == NULL )
|
|
|
|
msg.Printf( _( "%s pin %s not found" ), modName, pinName );
|
|
|
|
else
|
|
|
|
msg.Printf( _( "%s pin %s found" ), modName, pinName );
|
2007-10-07 09:49:08 +00:00
|
|
|
|
2019-06-26 18:35:56 +00:00
|
|
|
SetStatusText( msg );
|
|
|
|
}
|
|
|
|
else if( strcmp( idcmd, "$PART:" ) == 0 )
|
2007-10-07 09:49:08 +00:00
|
|
|
{
|
2019-06-26 18:35:56 +00:00
|
|
|
pcb->ResetNetHighLight();
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
modName = FROM_UTF8( text );
|
2007-10-07 09:49:08 +00:00
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint = pcb->FindFootprintByReference( modName );
|
2007-10-07 09:49:08 +00:00
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
if( footprint )
|
2019-01-23 10:30:10 +00:00
|
|
|
msg.Printf( _( "%s found" ), modName );
|
2008-02-19 07:06:58 +00:00
|
|
|
else
|
2019-01-23 10:30:10 +00:00
|
|
|
msg.Printf( _( "%s not found" ), modName );
|
2007-10-07 09:49:08 +00:00
|
|
|
|
2014-01-08 14:18:51 +00:00
|
|
|
SetStatusText( msg );
|
2007-10-07 09:49:08 +00:00
|
|
|
}
|
2017-03-02 23:42:23 +00:00
|
|
|
else if( strcmp( idcmd, "$SHEET:" ) == 0 )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Selecting all from sheet \"%s\"" ), FROM_UTF8( text ) );
|
2020-02-20 12:11:04 +00:00
|
|
|
wxString sheetUIID( FROM_UTF8( text ) );
|
2017-03-02 23:42:23 +00:00
|
|
|
SetStatusText( msg );
|
2017-03-04 16:30:44 +00:00
|
|
|
GetToolManager()->RunAction( PCB_ACTIONS::selectOnSheetFromEeschema, true,
|
2020-02-20 12:11:04 +00:00
|
|
|
static_cast<void*>( &sheetUIID ) );
|
2017-03-02 23:42:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-06-26 18:35:56 +00:00
|
|
|
else if( strcmp( idcmd, "$CLEAR" ) == 0 )
|
2007-10-07 09:49:08 +00:00
|
|
|
{
|
2020-07-06 10:51:04 +00:00
|
|
|
if( renderSettings->IsHighlightEnabled() )
|
|
|
|
{
|
|
|
|
renderSettings->SetHighlight( false );
|
|
|
|
view->UpdateAllLayersColor();
|
|
|
|
}
|
2007-10-07 09:49:08 +00:00
|
|
|
|
2020-07-06 10:51:04 +00:00
|
|
|
if( pcb->IsHighLightNetON() )
|
|
|
|
{
|
|
|
|
pcb->ResetNetHighLight();
|
|
|
|
SetMsgPanel( pcb );
|
|
|
|
}
|
2007-10-07 09:49:08 +00:00
|
|
|
|
2019-06-26 18:35:56 +00:00
|
|
|
GetCanvas()->Refresh();
|
|
|
|
return;
|
|
|
|
}
|
2019-01-23 10:30:10 +00:00
|
|
|
|
2019-07-16 19:15:07 +00:00
|
|
|
BOX2I bbox = { { 0, 0 }, { 0, 0 } };
|
|
|
|
|
2020-11-13 02:57:11 +00:00
|
|
|
if( footprint )
|
2019-06-26 18:35:56 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
bbox = footprint->GetBoundingBox( false ); // No invisible text in bbox calc
|
2020-01-20 17:35:20 +00:00
|
|
|
|
|
|
|
if( pad )
|
|
|
|
m_toolManager->RunAction( PCB_ACTIONS::highlightItem, true, (void*) pad );
|
|
|
|
else
|
2020-11-13 02:57:11 +00:00
|
|
|
m_toolManager->RunAction( PCB_ACTIONS::highlightItem, true, (void*) 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 =
|
|
|
|
[netcode, &bbox]( BOARD_CONNECTED_ITEM* aItem )
|
2020-10-02 00:56:52 +00:00
|
|
|
{
|
2019-06-26 18:35:56 +00:00
|
|
|
if( aItem->GetNetCode() == netcode )
|
|
|
|
{
|
|
|
|
if( bbox.GetWidth() == 0 )
|
|
|
|
bbox = aItem->GetBoundingBox();
|
|
|
|
else
|
|
|
|
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
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
for( 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
|
|
|
|
2020-06-28 02:48:48 +00:00
|
|
|
if( crossProbingSettings.center_on_items && bbox.GetWidth() > 0 && bbox.GetHeight() > 0 )
|
2019-07-16 19:15:07 +00:00
|
|
|
{
|
2020-10-02 00:56:52 +00:00
|
|
|
|
|
|
|
//#define DEFAULT_PCBNEW_CODE // Un-comment for normal full zoom KiCad algorithm
|
|
|
|
#ifdef DEFAULT_PCBNEW_CODE
|
|
|
|
auto bbSize = bbox.Inflate( bbox.GetWidth() * 0.2f ).GetSize();
|
2019-07-16 19:15:07 +00:00
|
|
|
auto screenSize = view->ToWorld( GetCanvas()->GetClientSize(), false );
|
2020-10-02 00:56:52 +00:00
|
|
|
|
2020-09-27 07:09:23 +00:00
|
|
|
// The "fabs" on x ensures the right answer when the view is flipped
|
|
|
|
screenSize.x = std::max( 10.0, fabs( screenSize.x ) );
|
2020-03-04 20:33:42 +00:00
|
|
|
screenSize.y = std::max( 10.0, screenSize.y );
|
2020-10-02 00:56:52 +00:00
|
|
|
double ratio = std::max( fabs( bbSize.x / screenSize.x ), fabs( bbSize.y / screenSize.y ) );
|
2019-07-16 19:15:07 +00:00
|
|
|
|
|
|
|
// Try not to zoom on every cross-probe; it gets very noisy
|
2020-08-12 21:27:20 +00:00
|
|
|
if( crossProbingSettings.zoom_to_fit && ( ratio < 0.5 || ratio > 1.0 ) )
|
2019-07-16 19:15:07 +00:00
|
|
|
view->SetScale( view->GetScale() / ratio );
|
2020-10-02 00:56:52 +00:00
|
|
|
#endif // DEFAULT_PCBNEW_CODE
|
|
|
|
|
|
|
|
#ifndef DEFAULT_PCBNEW_CODE // Do the scaled zoom
|
|
|
|
auto bbSize = bbox.Inflate( bbox.GetWidth() * 0.2f ).GetSize();
|
|
|
|
auto screenSize = view->ToWorld( GetCanvas()->GetClientSize(), false );
|
|
|
|
|
|
|
|
// This code tries to come up with a zoom factor that doesn't simply zoom in
|
|
|
|
// to the cross probed component, but instead shows a reasonable amount of the
|
|
|
|
// circuit around it to provide context. This reduces or eliminates the need
|
|
|
|
// to manually change the zoom because it's too close.
|
|
|
|
|
|
|
|
// Using the default text height as a constant to compare against, use the
|
|
|
|
// height of the bounding box of visible items for a footprint to figure out
|
|
|
|
// if this is a big footprint (like a processor) or a small footprint (like a resistor).
|
|
|
|
// This ratio is not useful by itself as a scaling factor. It must be "bent" to
|
|
|
|
// provide good scaling at varying component sizes. Bigger components need less
|
|
|
|
// scaling than small ones.
|
|
|
|
double currTextHeight = Millimeter2iu( DEFAULT_TEXT_SIZE );
|
|
|
|
|
|
|
|
double compRatio = bbSize.y / currTextHeight; // Ratio of component to text height
|
|
|
|
double compRatioBent = 1.0; // This will end up as the scaling factor we apply to "ratio"
|
|
|
|
|
|
|
|
// This is similar to the original KiCad code that scaled the zoom to make sure components
|
|
|
|
// were visible on screen. It's simply a ratio of screen size to component size, and its
|
|
|
|
// job is to zoom in to make the component fullscreen. Earlier in the code the
|
|
|
|
// component BBox is given a 20% margin to add some breathing room. We compare
|
|
|
|
// the height of this enlarged component bbox to the default text height. If a component
|
|
|
|
// will end up with the sides clipped, we adjust later to make sure it fits on screen.
|
|
|
|
//
|
|
|
|
// The "fabs" on x ensures the right answer when the view is flipped
|
|
|
|
screenSize.x = std::max( 10.0, fabs( screenSize.x ) );
|
|
|
|
screenSize.y = std::max( 10.0, screenSize.y );
|
|
|
|
double ratio = std::max( -1.0, fabs( bbSize.y / screenSize.y ) );
|
|
|
|
// Original KiCad code for how much to scale the zoom
|
2020-10-02 12:29:17 +00:00
|
|
|
double kicadRatio = std::max( fabs( bbSize.x / screenSize.x ),
|
2020-10-02 00:56:52 +00:00
|
|
|
fabs( bbSize.y / screenSize.y ) );
|
|
|
|
|
|
|
|
// LUT to scale zoom ratio to provide reasonable schematic context. Must work
|
|
|
|
// with footprints of varying sizes (e.g. 0402 package and 200 pin BGA).
|
|
|
|
// "first" is used as the input and "second" as the output
|
|
|
|
//
|
|
|
|
// "first" = compRatio (footprint height / default text height)
|
|
|
|
// "second" = Amount to scale ratio by
|
|
|
|
std::vector<std::pair<double, double>> lut{
|
|
|
|
{ 1, 8 },
|
|
|
|
{ 1.5, 5 },
|
|
|
|
{ 3, 3 },
|
|
|
|
{ 4.5, 2.5 },
|
|
|
|
{ 8, 2.0 },
|
|
|
|
{ 12, 1.7 },
|
|
|
|
{ 16, 1.5 },
|
|
|
|
{ 24, 1.3 },
|
|
|
|
{ 32, 1.0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::pair<double, double>>::iterator it;
|
|
|
|
|
|
|
|
compRatioBent = lut.back().second; // Large component default
|
|
|
|
|
|
|
|
if( compRatio >= lut.front().first )
|
|
|
|
{
|
|
|
|
// Use LUT to do linear interpolation of "compRatio" within "first", then
|
|
|
|
// use that result to linearly interpolate "second" which gives the scaling
|
|
|
|
// factor needed.
|
|
|
|
|
|
|
|
for( it = lut.begin(); it < lut.end() - 1; it++ )
|
|
|
|
{
|
|
|
|
if( it->first <= compRatio && next( it )->first >= compRatio )
|
|
|
|
{
|
|
|
|
double diffx = compRatio - it->first;
|
|
|
|
double diffn = next( it )->first - it->first;
|
|
|
|
|
|
|
|
compRatioBent =
|
|
|
|
it->second + ( next( it )->second - it->second ) * diffx / diffn;
|
|
|
|
break; // We have our interpolated value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
compRatioBent = lut.front().second; // Small component default
|
|
|
|
|
|
|
|
// If the width of the part we're probing is bigger than what the screen width will be
|
|
|
|
// after the zoom, then punt and use the KiCad zoom algorithm since it guarantees the
|
|
|
|
// part's width will be encompassed within the screen. This will apply to parts that are
|
|
|
|
// much wider than they are tall.
|
|
|
|
|
|
|
|
if( bbSize.x > screenSize.x * ratio * compRatioBent )
|
|
|
|
{
|
|
|
|
ratio = kicadRatio; // Use standard KiCad zoom algorithm for parts too wide to fit screen
|
|
|
|
compRatioBent = 1.0; // Reset so we don't modify the "KiCad" ratio
|
|
|
|
wxLogTrace( "CROSS_PROBE_SCALE",
|
|
|
|
"Part TOO WIDE for screen. Using normal KiCad zoom ratio: %1.5f", ratio );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now that "compRatioBent" holds our final scaling factor we apply it to the original
|
|
|
|
// fullscreen zoom ratio to arrive at the final ratio itself.
|
|
|
|
ratio *= compRatioBent;
|
|
|
|
|
|
|
|
bool alwaysZoom = false; // DEBUG - allows us to minimize zooming or not
|
|
|
|
// Try not to zoom on every cross-probe; it gets very noisy
|
|
|
|
if( ( ratio < 0.5 || ratio > 1.0 ) || alwaysZoom )
|
|
|
|
view->SetScale( view->GetScale() / ratio );
|
|
|
|
#endif // ifndef DEFAULT_PCBNEW_CODE
|
2019-07-16 19:15:07 +00:00
|
|
|
|
|
|
|
view->SetCenter( bbox.Centre() );
|
|
|
|
}
|
|
|
|
|
2019-06-26 18:35:56 +00:00
|
|
|
view->UpdateAllLayersColor();
|
|
|
|
// 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
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
FOOTPRINT* footprint;
|
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:
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint = (FOOTPRINT*) aItem;
|
2020-11-13 02:57:11 +00:00
|
|
|
return StrPrintf( "$PART: \"%s\"", TO_UTF8( footprint->GetReference() ) );
|
2007-10-07 09:49:08 +00:00
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_PAD_T:
|
2014-04-21 06:28:17 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint = static_cast<FOOTPRINT*>( aItem->GetParent() );
|
2020-11-12 22:30:02 +00:00
|
|
|
wxString pad = static_cast<PAD*>( aItem )->GetName();
|
2014-04-21 06:28:17 +00:00
|
|
|
|
|
|
|
return StrPrintf( "$PART: \"%s\" $PAD: \"%s\"",
|
2020-11-13 02:57:11 +00:00
|
|
|
TO_UTF8( footprint->GetReference() ),
|
2019-06-03 23:50:44 +00:00
|
|
|
TO_UTF8( pad ) );
|
2014-04-21 06:28:17 +00:00
|
|
|
}
|
2007-10-07 09:49:08 +00:00
|
|
|
|
2020-10-04 14:19:33 +00:00
|
|
|
case PCB_FP_TEXT_T:
|
2014-04-21 06:28:17 +00:00
|
|
|
{
|
2020-11-13 15:15:52 +00:00
|
|
|
footprint = static_cast<FOOTPRINT*>( aItem->GetParent() );
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2020-10-04 23:34:59 +00:00
|
|
|
FP_TEXT* text = static_cast<FP_TEXT*>( aItem );
|
|
|
|
const char* text_key;
|
2014-04-21 06:28:17 +00:00
|
|
|
|
2014-09-10 15:18:42 +00:00
|
|
|
/* This can't be a switch since the break need to pull out
|
|
|
|
* from the outer switch! */
|
2020-10-04 23:34:59 +00:00
|
|
|
if( text->GetType() == FP_TEXT::TEXT_is_REFERENCE )
|
2014-04-21 06:28:17 +00:00
|
|
|
text_key = "$REF:";
|
2020-10-04 23:34:59 +00:00
|
|
|
else if( text->GetType() == FP_TEXT::TEXT_is_VALUE )
|
2014-04-21 06:28:17 +00:00
|
|
|
text_key = "$VAL:";
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
|
|
|
|
return StrPrintf( "$PART: \"%s\" %s \"%s\"",
|
2020-11-13 02:57:11 +00:00
|
|
|
TO_UTF8( footprint->GetReference() ),
|
2019-06-03 23:50:44 +00:00
|
|
|
text_key,
|
2020-10-04 23:34:59 +00:00
|
|
|
TO_UTF8( text->GetText() ) );
|
2014-04-21 06:28:17 +00:00
|
|
|
}
|
2007-10-07 09:49:08 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-04-21 06:28:17 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-02 16:25:04 +00:00
|
|
|
/* Send a remote command to Eeschema via a socket,
|
2020-11-13 02:57:11 +00:00
|
|
|
* aSyncItem = item to be located on schematic (footprint, pin or text)
|
2014-04-21 06:28:17 +00:00
|
|
|
* Commands are
|
|
|
|
* $PART: "reference" put cursor on component anchor
|
|
|
|
* $PART: "reference" $PAD: "pad number" put cursor on the component pin
|
|
|
|
* $PART: "reference" $REF: "reference" put cursor on the component ref
|
|
|
|
* $PART: "reference" $VAL: "value" put cursor on the component value
|
|
|
|
*/
|
|
|
|
void PCB_EDIT_FRAME::SendMessageToEESCHEMA( BOARD_ITEM* aSyncItem )
|
|
|
|
{
|
|
|
|
std::string packet = FormatProbeItem( aSyncItem );
|
|
|
|
|
2019-07-17 20:21:22 +00:00
|
|
|
if( !packet.empty() )
|
2018-01-06 20:50:49 +00:00
|
|
|
{
|
|
|
|
if( Kiface().IsSingle() )
|
|
|
|
SendCommand( MSG_TO_SCH, packet.c_str() );
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PCB_EDIT_FRAME::SendCrossProbeNetName( const wxString& aNetName )
|
|
|
|
{
|
|
|
|
std::string packet = StrPrintf( "$NET: \"%s\"", TO_UTF8( aNetName ) );
|
|
|
|
|
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() )
|
2014-04-21 06:28:17 +00:00
|
|
|
SendCommand( MSG_TO_SCH, packet.c_str() );
|
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
|
|
|
|
|
|
|
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
|
|
|
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : this->GetBoard()->Footprints() )
|
2020-01-29 16:33:57 +00:00
|
|
|
{
|
2020-11-13 02:57:11 +00:00
|
|
|
COMPONENT* component = new COMPONENT( footprint->GetFPID(), footprint->GetReference(),
|
|
|
|
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() )
|
|
|
|
component->AddNet( pad->GetName(), netname, wxEmptyString );
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
case MAIL_PCB_UPDATE_LINKS:
|
|
|
|
try
|
|
|
|
{
|
|
|
|
NETLIST netlist;
|
|
|
|
FetchNetlistFromSchematic( netlist, NO_ANNOTATION );
|
|
|
|
|
|
|
|
BOARD_NETLIST_UPDATER updater( this, GetBoard() );
|
|
|
|
updater.SetLookupByTimestamp( false );
|
|
|
|
updater.SetDeleteUnusedComponents ( false );
|
|
|
|
updater.SetReplaceFootprints( false );
|
|
|
|
updater.SetDeleteSinglePadNets( false );
|
|
|
|
updater.SetWarnPadNoNetInNetlist( false );
|
|
|
|
updater.UpdateNetlist( netlist );
|
|
|
|
|
|
|
|
bool dummy;
|
|
|
|
OnNetlistChanged( updater, &dummy );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& )
|
|
|
|
{
|
|
|
|
assert( false ); // should never happen
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2019-03-27 22:37:26 +00:00
|
|
|
case MAIL_PCB_UPDATE:
|
2019-06-03 13:49:17 +00:00
|
|
|
m_toolManager->RunAction( ACTIONS::updatePcbFromSchematic, true );
|
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 );
|
|
|
|
}
|
2020-07-16 17:31:36 +00:00
|
|
|
break;
|
2018-02-26 10:34:36 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|