Fix cross-probing in complex hierarchies, remove unused code.

Fixes https://gitlab.com/kicad/code/kicad/issues/11493
This commit is contained in:
dsa-t 2022-05-09 23:21:49 +03:00
parent e85105a907
commit ad066ef09a
3 changed files with 30 additions and 220 deletions

View File

@ -379,103 +379,8 @@ void SCH_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
}
std::string FormatProbeItem( EDA_ITEM* aItem, SCH_SYMBOL* aSymbol )
void SCH_EDIT_FRAME::SendSelectItems( bool aSelectConnections, const std::deque<EDA_ITEM*>& aItems )
{
// This is a keyword followed by a quoted string.
// Cross probing to Pcbnew if a pin or a symbol is found.
switch( aItem->Type() )
{
case SCH_FIELD_T:
if( aSymbol )
{
return StrPrintf( "$PART: \"%s\"",
TO_UTF8( aSymbol->GetField( REFERENCE_FIELD )->GetText() ) );
}
break;
case SCH_SYMBOL_T:
aSymbol = (SCH_SYMBOL*) aItem;
return StrPrintf( "$PART: \"%s\"",
TO_UTF8( aSymbol->GetField( REFERENCE_FIELD )->GetText() ) );
case SCH_SHEET_T:
{
// For cross probing, we need the full path of the sheet, because
// in complex hierarchies the sheet uuid of not unique
SCH_SHEET* sheet = (SCH_SHEET*)aItem;
wxString full_path;
SCH_SHEET* parent = sheet;
while( (parent = dynamic_cast<SCH_SHEET*>( parent->GetParent() ) ) )
{
if( parent->GetParent() ) // The root sheet has no parent and path is just "/"
{
full_path.Prepend( parent->m_Uuid.AsString() );
full_path.Prepend( "/" );
}
}
full_path += "/" + sheet->m_Uuid.AsString();
return StrPrintf( "$SHEET: \"%s\"", TO_UTF8( full_path ) );
}
case SCH_PIN_T:
{
SCH_PIN* pin = (SCH_PIN*) aItem;
aSymbol = pin->GetParentSymbol();
if( !pin->GetShownNumber().IsEmpty() )
{
return StrPrintf( "$PIN: \"%s\" $PART: \"%s\"",
TO_UTF8( pin->GetShownNumber() ),
TO_UTF8( aSymbol->GetField( REFERENCE_FIELD )->GetText() ) );
}
else
{
return StrPrintf( "$PART: \"%s\"",
TO_UTF8( aSymbol->GetField( REFERENCE_FIELD )->GetText() ) );
}
}
default:
break;
}
return "";
}
void SCH_EDIT_FRAME::SendMessageToPCBNEW( EDA_ITEM* aObjectToSync, SCH_SYMBOL* aLibItem )
{
wxASSERT( aObjectToSync ); // fix the caller
if( !aObjectToSync )
return;
std::string packet = FormatProbeItem( aObjectToSync, aLibItem );
if( !packet.empty() )
{
if( Kiface().IsSingle() )
{
SendCommand( MSG_TO_PCB, packet );
}
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_EDITOR, MAIL_CROSS_PROBE, packet, this );
}
}
}
std::string FormatProbeItems( bool aSelectConnections, const std::deque<EDA_ITEM*>& aItems )
{
std::string command = "";
std::set<wxString> parts;
for( EDA_ITEM* item : aItems )
@ -484,7 +389,7 @@ std::string FormatProbeItems( bool aSelectConnections, const std::deque<EDA_ITEM
{
case SCH_SYMBOL_T:
{
SCH_SYMBOL* symbol = (SCH_SYMBOL*) item;
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
wxString ref = symbol->GetField( REFERENCE_FIELD )->GetText();
@ -496,24 +401,9 @@ std::string FormatProbeItems( bool aSelectConnections, const std::deque<EDA_ITEM
case SCH_SHEET_T:
{
// For cross probing, we need the full path of the sheet, because
// in complex hierarchies the sheet uuid of not unique
SCH_SHEET* sheet = (SCH_SHEET*) item;
wxString full_path;
// we search by the footprint path prefix in the PCB editor
SCH_SHEET* parent = sheet;
while( ( parent = dynamic_cast<SCH_SHEET*>( parent->GetParent() ) ) )
{
if( parent->GetParent() && parent->GetParent()->Type() == SCH_SHEET_T )
{
// The root sheet has no parent sheet and path is just "/"
full_path.Prepend( parent->m_Uuid.AsString() );
full_path.Prepend( "/" );
}
}
full_path += "/" + sheet->m_Uuid.AsString();
wxString full_path = GetCurrentSheet().PathAsString() + item->m_Uuid.AsString();
parts.emplace( wxT( "S" ) + full_path );
@ -522,7 +412,7 @@ std::string FormatProbeItems( bool aSelectConnections, const std::deque<EDA_ITEM
case SCH_PIN_T:
{
SCH_PIN* pin = (SCH_PIN*) item;
SCH_PIN* pin = static_cast<SCH_PIN*>( item );
SCH_SYMBOL* symbol = pin->GetParentSymbol();
wxString ref = symbol->GetField( REFERENCE_FIELD )->GetText();
@ -537,48 +427,34 @@ std::string FormatProbeItems( bool aSelectConnections, const std::deque<EDA_ITEM
}
}
if( !parts.empty() )
if( parts.empty() )
{
command = "$SELECT: ";
if( aSelectConnections )
command += "1";
else
command += "0";
command += ",";
for( wxString part : parts )
{
command += part;
command += ",";
}
command.pop_back();
return;
}
return command;
}
std::string command = "$SELECT: ";
command += aSelectConnections ? "1" : "0";
command += ",";
void SCH_EDIT_FRAME::SendSelectItems( bool aSelectConnections, const std::deque<EDA_ITEM*>& aItems )
{
std::string packet = FormatProbeItems( aSelectConnections, aItems );
if( !packet.empty() )
for( wxString part : parts )
{
if( Kiface().IsSingle() )
{
SendCommand( MSG_TO_PCB, packet );
}
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_PCB_EDITOR, MAIL_SELECTION, packet, this );
}
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_PCB_EDITOR, MAIL_SELECTION, command, this );
}
}

View File

@ -294,19 +294,6 @@ public:
*/
void TestDanglingEnds();
/**
* Send a message to Pcbnew via a socket connection.
*
* Commands are:
* - $PART: reference put cursor on footprint anchor
* - $PIN: number $PART: reference put cursor on the footprint pad
* - $SHEET: time_stamp select all footprints of symbols is the schematic sheet path
*
* @param aObjectToSync is the item to be located on board.
* @param aPart is the symbol if \a aObjectToSync is a sub item of a symbol (like a pin).
*/
void SendMessageToPCBNEW( EDA_ITEM* aObjectToSync, SCH_SYMBOL* aPart );
/**
* Sends items to Pcbnew for selection
*

View File

@ -57,10 +57,9 @@
/* Execute a remote command send by Eeschema via a socket,
* port KICAD_PCB_PORT_SERVICE_NUMBER
* cmdline = received command from Eeschema
* 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)
* Commands are:
* $NET: "net name" Highlight the given net
* $NETS: "net name 1,net name 2" Highlight all given nets
* $CLEAR Clear existing highlight
* They are a keyword followed by a quoted string.
*/
@ -146,58 +145,6 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
netcode = -1;
}
else if( strcmp( idcmd, "$PIN:" ) == 0 )
{
wxString pinName = FROM_UTF8( text );
text = strtok( nullptr, " \n\r" );
if( text && strcmp( text, "$PART:" ) == 0 )
text = strtok( nullptr, "\"\n\r" );
modName = FROM_UTF8( text );
footprint = pcb->FindFootprintByReference( modName );
if( footprint )
pad = footprint->FindPadByNumber( pinName );
if( pad )
netcode = pad->GetNetCode();
if( footprint == nullptr )
msg.Printf( _( "%s not found" ), modName );
else if( pad == nullptr )
msg.Printf( _( "%s pin %s not found" ), modName, pinName );
else
msg.Printf( _( "%s pin %s found" ), modName, pinName );
SetStatusText( msg );
}
else if( strcmp( idcmd, "$PART:" ) == 0 )
{
pcb->ResetNetHighLight();
modName = FROM_UTF8( text );
footprint = pcb->FindFootprintByReference( modName );
if( footprint )
msg.Printf( _( "%s found" ), modName );
else
msg.Printf( _( "%s not found" ), modName );
SetStatusText( msg );
}
else if( strcmp( idcmd, "$SHEET:" ) == 0 )
{
msg.Printf( _( "Selecting all from sheet \"%s\"" ), FROM_UTF8( text ) );
wxString sheetUIID( FROM_UTF8( text ) );
SetStatusText( msg );
GetToolManager()->RunAction( PCB_ACTIONS::selectOnSheetFromEeschema, true,
static_cast<void*>( &sheetUIID ) );
return;
}
else if( strcmp( idcmd, "$CLEAR" ) == 0 )
{
if( renderSettings->IsHighlightEnabled() )