kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #32898
[PATCH] Add bidirectional net highlight cross-probing
I implemented this in response to a bug report:
https://bugs.launchpad.net/kicad/+bug/1738875
But it is kind of on a blurred line between bug fix and new feature.
I'll leave it up to Wayne et. al. to decide on if to merge this for V5.
Basically, beforehand, cross-probing highlighted nets only if you clicked
on a component pad.
Now there is a separate cross-probing message for a net name, so that if
the highlight tool is selected in both eeschema and pcbnew, selecting any
part of a net will cross-probe.
-Jon
From bb1148b959a05fb973fd5207ecd8dd9fa6a5f56d Mon Sep 17 00:00:00 2001
From: Jon Evans <jon@xxxxxxxxxxxxx>
Date: Sat, 6 Jan 2018 15:50:49 -0500
Subject: [PATCH] Add bidirectional net highlight cross-probing
Fixes: lp:1738875
* https://bugs.launchpad.net/kicad/+bug/1738875
---
eeschema/cross-probing.cpp | 39 ++++++++++++++++++++++-
eeschema/highlight_connection.cpp | 1 +
eeschema/schframe.h | 7 +++++
pcbnew/cross-probing.cpp | 62 ++++++++++++++++++++++++++++++++++++-
pcbnew/tools/pcb_editor_control.cpp | 2 ++
pcbnew/wxPcbStruct.h | 7 +++++
6 files changed, 116 insertions(+), 2 deletions(-)
diff --git a/eeschema/cross-probing.cpp b/eeschema/cross-probing.cpp
index 3175038ae..d0e71d2fc 100644
--- a/eeschema/cross-probing.cpp
+++ b/eeschema/cross-probing.cpp
@@ -56,6 +56,7 @@
* \li \c \$PART: \c "reference" \c \$REF: \c "ref" Put cursor on component reference.
* \li \c \$PART: \c "reference" \c \$VAL: \c "value" Put cursor on component value.
* \li \c \$PART: \c "reference" \c \$PAD: \c "pin name" Put cursor on the component pin.
+ * \li \c \$NET: \c "netname" Highlight a specified net
* <p>
* @param cmdline = received command from Pcbnew
*/
@@ -69,7 +70,24 @@ void SCH_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
char* idcmd = strtok( line, " \n\r" );
char* text = strtok( NULL, "\"\n\r" );
- if( (idcmd == NULL) || (text == NULL) )
+ if( idcmd == NULL )
+ return;
+
+ if( strcmp( idcmd, "$NET:" ) == 0 )
+ {
+ if( GetToolId() == ID_HIGHLIGHT )
+ {
+ m_SelectedNetName = FROM_UTF8( text );
+
+ SetStatusText( _( "Selected net: " ) + m_SelectedNetName );
+ SetCurrentSheetHighlightFlags();
+ m_canvas->Refresh();
+ }
+
+ return;
+ }
+
+ if( text == NULL )
return;
if( strcmp( idcmd, "$PART:" ) != 0 )
@@ -185,6 +203,25 @@ void SCH_EDIT_FRAME::SendMessageToPCBNEW( EDA_ITEM* aObjectToSync, SCH_COMPONENT
}
+void SCH_EDIT_FRAME::SendCrossProbeNetName( const wxString& aNetName )
+{
+ std::string packet = StrPrintf( "$NET: %s", TO_UTF8( aNetName ) );
+
+ if( packet.size() )
+ {
+ if( Kiface().IsSingle() )
+ SendCommand( MSG_TO_PCB, 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_PCB, MAIL_CROSS_PROBE, packet, this );
+ }
+ }
+}
+
+
void SCH_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
{
const std::string& payload = mail.GetPayload();
diff --git a/eeschema/highlight_connection.cpp b/eeschema/highlight_connection.cpp
index 367bd3e35..78f50b2d2 100644
--- a/eeschema/highlight_connection.cpp
+++ b/eeschema/highlight_connection.cpp
@@ -66,6 +66,7 @@ bool SCH_EDIT_FRAME::HighlightConnectionAtPosition( wxPoint aPosition )
}
}
+ SendCrossProbeNetName( m_SelectedNetName );
SetStatusText( "selected net: " + m_SelectedNetName );
SetCurrentSheetHighlightFlags();
m_canvas->Refresh();
diff --git a/eeschema/schframe.h b/eeschema/schframe.h
index 78410407b..bee8da0f1 100644
--- a/eeschema/schframe.h
+++ b/eeschema/schframe.h
@@ -511,6 +511,13 @@ public:
*/
void SendMessageToPCBNEW( EDA_ITEM* aObjectToSync, SCH_COMPONENT* aPart );
+ /**
+ * Sends a net name to eeschema for highlighting
+ *
+ * @param aNetName is the name of a net, or empty string to clear highlight
+ */
+ void SendCrossProbeNetName( const wxString& aNetName );
+
/**
* Create a flat list which stores all connected objects.
*
diff --git a/pcbnew/cross-probing.cpp b/pcbnew/cross-probing.cpp
index e552482ae..b914cd310 100644
--- a/pcbnew/cross-probing.cpp
+++ b/pcbnew/cross-probing.cpp
@@ -32,6 +32,7 @@
#include <tool/tool_manager.h>
#include <tools/selection_tool.h>
#include <pcb_draw_panel_gal.h>
+#include <pcb_painter.h>
/* Execute a remote command send by Eeschema via a socket,
* port KICAD_PCB_PORT_SERVICE_NUMBER
@@ -39,6 +40,7 @@
* Commands are
* $PART: "reference" put cursor on component
* $PIN: "pin name" $PART: "reference" put cursor on the footprint pin
+ * $NET: "net name" highlight the given net (if highlight tool is active)
*/
void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
{
@@ -58,7 +60,46 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
idcmd = strtok( line, " \n\r" );
text = strtok( NULL, " \n\r" );
- if( !idcmd || !text )
+ if( idcmd == NULL )
+ return;
+
+ if( strcmp( idcmd, "$NET:" ) == 0 )
+ {
+ if( GetToolId() == ID_PCB_HIGHLIGHT_BUTT )
+ {
+ wxString net_name = FROM_UTF8( text );
+ NETINFO_ITEM* netinfo = pcb->FindNet( net_name );
+ int netcode = 0;
+
+ if( netinfo )
+ netcode = netinfo->GetNet();
+
+ if( IsGalCanvasActive() )
+ {
+ auto rs = m_toolManager->GetView()->GetPainter()->GetSettings();
+ rs->SetHighlight( true, netcode );
+ m_toolManager->GetView()->UpdateAllLayersColor();
+ GetGalCanvas()->Refresh();
+ }
+ else
+ {
+ if( netcode > 0 )
+ {
+ pcb->HighLightON();
+ pcb->SetHighLightNet( netcode );
+ }
+ else
+ {
+ pcb->HighLightOFF();
+ pcb->SetHighLightNet( -1 );
+ }
+ }
+ }
+
+ return;
+ }
+
+ if( text == NULL )
return;
if( strcmp( idcmd, "$PART:" ) == 0 )
@@ -246,6 +287,25 @@ void PCB_EDIT_FRAME::SendMessageToEESCHEMA( BOARD_ITEM* aSyncItem )
}
+void PCB_EDIT_FRAME::SendCrossProbeNetName( const wxString& aNetName )
+{
+ std::string packet = StrPrintf( "$NET: \"%s\"", TO_UTF8( aNetName ) );
+
+ if( packet.size() )
+ {
+ 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::KiwayMailIn( KIWAY_EXPRESS& mail )
{
const std::string& payload = mail.GetPayload();
diff --git a/pcbnew/tools/pcb_editor_control.cpp b/pcbnew/tools/pcb_editor_control.cpp
index 96ca451e5..b43301b68 100644
--- a/pcbnew/tools/pcb_editor_control.cpp
+++ b/pcbnew/tools/pcb_editor_control.cpp
@@ -902,12 +902,14 @@ static bool highlightNet( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition )
MSG_PANEL_ITEMS items;
netinfo->GetMsgPanelInfo( items );
frame->SetMsgPanel( items );
+ frame->SendCrossProbeNetName( netinfo->GetNetname() );
}
}
else
{
board->ResetHighLight();
frame->SetMsgPanel( board );
+ frame->SendCrossProbeNetName( "" );
}
return true;
diff --git a/pcbnew/wxPcbStruct.h b/pcbnew/wxPcbStruct.h
index b1fe57c98..0ca3bcee0 100644
--- a/pcbnew/wxPcbStruct.h
+++ b/pcbnew/wxPcbStruct.h
@@ -1667,6 +1667,13 @@ public:
*/
void SendMessageToEESCHEMA( BOARD_ITEM* objectToSync );
+ /**
+ * Sends a net name to eeschema for highlighting
+ *
+ * @param aNetName is the name of a net, or empty string to clear highlight
+ */
+ void SendCrossProbeNetName( const wxString& aNetName );
+
/**
* Function Edit_Gap
* edits the GAP module if it has changed the position and/or size of the pads that
--
2.14.1
Follow ups