kicad/eeschema/cross-probing.cpp

147 lines
4.2 KiB
C++
Raw Normal View History

2007-10-08 16:14:16 +00:00
/*********************/
/* cross-probing.cpp */
/*********************/
#include "fctsys.h"
#include "common.h"
#include "program.h"
#include "libcmp.h"
#include "general.h"
#include "eda_dde.h"
#include "id.h"
#include "protos.h"
#include "schframe.h"
2007-10-08 16:14:16 +00:00
/***************************************************************/
void RemoteCommand( const char* cmdline )
/***************************************************************/
/** Read a remote command sent by pcbnew (via a socket connection) ,
* so when user selects a module or pin in pcbnew,
* eeschema shows that same component or pin.
* The cursor is put on the item
* port KICAD_SCH_PORT_SERVICE_NUMBER (currently 4243)
* @param cmdline = received command from pcbnew
* commands are:
* $PART: "reference" put cursor on component
* $PART: "reference" $REF: "ref" put cursor on reference component
* $PART: "reference" $VAL: "value" put cursor on value component
* $PART: "reference" $PAD: "pin name" put cursor on the component pin
*/
{
char line[1024];
char* idcmd;
char* text;
WinEDA_SchematicFrame* frame = g_EDA_Appl->m_SchematicFrame;
2007-10-08 16:14:16 +00:00
wxString part_ref, msg;
strncpy( line, cmdline, sizeof(line) - 1 );
idcmd = strtok( line, " \n\r" );
text = strtok( NULL, "\"\n\r" );
if( (idcmd == NULL) || (text == NULL) )
return;
if( strcmp( idcmd, "$PART:" ) != 0 )
return;
part_ref = CONV_FROM_UTF8( text );
/* look for a complement */
idcmd = strtok( NULL, " \n\r" );
if( idcmd == NULL ) // component only
{
frame->FindComponentAndItem( part_ref, true, 0, wxEmptyString, false );
return;
}
text = strtok( NULL, "\"\n\r" );
if( text == NULL )
return;
msg = CONV_FROM_UTF8( text );
if( strcmp( idcmd, "$REF:" ) == 0 )
{
frame->FindComponentAndItem( part_ref, true, 2, msg, false );
}
else if( strcmp( idcmd, "$VAL:" ) == 0 )
{
frame->FindComponentAndItem( part_ref, true, 3, msg, false );
}
else if( strcmp( idcmd, "$PAD:" ) == 0 )
{
frame->FindComponentAndItem( part_ref, true, 1, msg, false );
}
else
frame->FindComponentAndItem( part_ref, true, 0, wxEmptyString, false );
}
/*****************************************************************************/
void WinEDA_SchematicFrame::SendMessageToPCBNEW( EDA_BaseStruct* objectToSync,
EDA_SchComponentStruct* LibItem )
2007-10-08 16:14:16 +00:00
/*****************************************************************************/
/** Send a remote command to eeschema via a socket,
* @param objectToSync = item to be located on board (footprint, pad or text)
* @param LibItem = component in lib if objectToSync is a sub item of a component
2007-10-08 16:14:16 +00:00
* Commands are
* $PART: reference put cursor on footprint anchor
* $PIN: number $PART: reference put cursor on the footprint pad
*/
{
2007-10-09 13:10:58 +00:00
if( objectToSync == NULL )
return;
2007-10-08 16:14:16 +00:00
LibDrawPin* Pin = NULL;
char Line[1024];
2007-10-08 16:14:16 +00:00
/* Cross probing to pcbnew if a pin or a component is found */
switch( objectToSync->Type() )
{
case DRAW_PART_TEXT_STRUCT_TYPE:
2007-10-08 16:14:16 +00:00
case COMPONENT_FIELD_DRAW_TYPE:
2008-02-19 07:06:58 +00:00
{
if( LibItem == NULL )
break;
sprintf( Line, "$PART: %s", CONV_TO_UTF8( LibItem->m_Field[REFERENCE].m_Text ) );
SendCommand( MSG_TO_PCB, Line );
}
2007-10-08 16:14:16 +00:00
break;
case DRAW_LIB_ITEM_STRUCT_TYPE:
LibItem = (EDA_SchComponentStruct*) objectToSync;
sprintf( Line, "$PART: %s", CONV_TO_UTF8( LibItem->m_Field[REFERENCE].m_Text ) );
SendCommand( MSG_TO_PCB, Line );
break;
case COMPONENT_PIN_DRAW_TYPE:
2007-10-09 13:10:58 +00:00
if( LibItem == NULL )
break;
2008-02-19 07:06:58 +00:00
Pin = (LibDrawPin*) objectToSync;
2007-10-09 13:10:58 +00:00
if( Pin->m_PinNum )
2007-10-08 16:14:16 +00:00
{
wxString pinnum;
Pin->ReturnPinStringNum( pinnum );
sprintf( Line, "$PIN: %s $PART: %s", CONV_TO_UTF8( pinnum ),
CONV_TO_UTF8( LibItem->m_Field[REFERENCE].m_Text ) );
}
2007-10-09 13:10:58 +00:00
else
sprintf( Line, "$PART: %s", CONV_TO_UTF8( LibItem->m_Field[REFERENCE].m_Text ) );
SendCommand( MSG_TO_PCB, Line );
break;
2007-10-08 16:14:16 +00:00
default:
break;
}
}