From 7848c3acf330bd833c0291f1729f03e3e89026f4 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 24 Jan 2019 16:59:34 +0100 Subject: [PATCH] Fix cross-probing issue (not working) when a net name or a pin name contains a space. --- eeschema/cross-probing.cpp | 21 ++++++++++++-------- pcbnew/cross-probing.cpp | 40 +++++++++++++++++++++++++++++++------- 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/eeschema/cross-probing.cpp b/eeschema/cross-probing.cpp index a257069f24..9cb372a6dc 100644 --- a/eeschema/cross-probing.cpp +++ b/eeschema/cross-probing.cpp @@ -1,9 +1,9 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com + * Copyright (C) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2004-2019 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -58,6 +58,7 @@ * \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 *

+ * They are a keyword followed by a quoted string. * @param cmdline = received command from Pcbnew */ void SCH_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) @@ -132,24 +133,26 @@ void SCH_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) std::string FormatProbeItem( EDA_ITEM* aItem, SCH_COMPONENT* aPart ) { + // This is a keyword followed by a quoted string. + // Cross probing to Pcbnew if a pin or a component is found switch( aItem->Type() ) { case SCH_FIELD_T: case LIB_FIELD_T: if( aPart ) - return StrPrintf( "$PART: %s", + return StrPrintf( "$PART: \"%s\"", TO_UTF8( aPart->GetField( REFERENCE )->GetText() ) ); break; case SCH_COMPONENT_T: aPart = (SCH_COMPONENT*) aItem; - return StrPrintf( "$PART: %s", TO_UTF8( aPart->GetField( REFERENCE )->GetText() ) ); + return StrPrintf( "$PART: \"%s\"", TO_UTF8( aPart->GetField( REFERENCE )->GetText() ) ); case SCH_SHEET_T: { SCH_SHEET* sheet = (SCH_SHEET*)aItem; - return StrPrintf( "$SHEET: %8.8lX", (unsigned long) sheet->GetTimeStamp() ); + return StrPrintf( "$SHEET: \"%8.8lX\"", (unsigned long) sheet->GetTimeStamp() ); } case LIB_PIN_T: @@ -161,12 +164,12 @@ std::string FormatProbeItem( EDA_ITEM* aItem, SCH_COMPONENT* aPart ) if( !pin->GetNumber().IsEmpty() ) { - return StrPrintf( "$PIN: %s $PART: %s", TO_UTF8( pin->GetNumber() ), + return StrPrintf( "$PIN: \"%s\" $PART: \"%s\"", TO_UTF8( pin->GetNumber() ), TO_UTF8( aPart->GetField( REFERENCE )->GetText() ) ); } else { - return StrPrintf( "$PART: %s", TO_UTF8( aPart->GetField( REFERENCE )->GetText() ) ); + return StrPrintf( "$PART: \"%s\"", TO_UTF8( aPart->GetField( REFERENCE )->GetText() ) ); } } break; @@ -205,7 +208,9 @@ 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 ) ); + // The command is a keyword followed by a quoted string. + + std::string packet = StrPrintf( "$NET: \"%s\"", TO_UTF8( aNetName ) ); if( packet.size() ) { diff --git a/pcbnew/cross-probing.cpp b/pcbnew/cross-probing.cpp index f9c1527857..0d87d0555e 100644 --- a/pcbnew/cross-probing.cpp +++ b/pcbnew/cross-probing.cpp @@ -1,3 +1,27 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. + * + * 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 + */ + + /** * @file pcbnew/cross-probing.cpp * @brief Cross probing functions to handle communication to andfrom Eeschema. @@ -44,6 +68,7 @@ * $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) + * They are a keyword followed by a quoted string. */ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) { @@ -61,7 +86,7 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) line[sizeof(line) - 1] = 0; idcmd = strtok( line, " \n\r" ); - text = strtok( NULL, " \n\r" ); + text = strtok( NULL, "\"\n\r" ); if( idcmd == NULL ) return; @@ -155,9 +180,9 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) module = pcb->FindModuleByReference( modName ); if( module ) - msg.Printf( _( "%s found" ), GetChars( modName ) ); + msg.Printf( _( "%s found" ), modName ); else - msg.Printf( _( "%s not found" ), GetChars( modName ) ); + msg.Printf( _( "%s not found" ), modName ); SetStatusText( msg ); @@ -181,8 +206,9 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) pinName = FROM_UTF8( text ); text = strtok( NULL, " \n\r" ); + if( text && strcmp( text, "$PART:" ) == 0 ) - text = strtok( NULL, "\n\r" ); + text = strtok( NULL, "\"\n\r" ); modName = FROM_UTF8( text ); @@ -212,16 +238,16 @@ void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline ) if( module == NULL ) { - msg.Printf( _( "%s not found" ), GetChars( modName ) ); + msg.Printf( _( "%s not found" ), modName ); } else if( pad == NULL ) { - msg.Printf( _( "%s pin %s not found" ), GetChars( modName ), GetChars( pinName ) ); + msg.Printf( _( "%s pin %s not found" ), modName, pinName ); SetCurItem( module ); } else { - msg.Printf( _( "%s pin %s found" ), GetChars( modName ), GetChars( pinName ) ); + msg.Printf( _( "%s pin %s found" ), modName, pinName ); SetCurItem( pad ); }