kicad/pcbnew/cross-probing.cpp

199 lines
5.3 KiB
C++
Raw Normal View History

/**
* @file pcbnew/cross-probing.cpp
* @brief Cross probing functions to handle communication to andfrom Eeschema.
*/
/**
* 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)
* Note: these ports must be enabled for firewall protection
*/
2007-10-07 09:49:08 +00:00
#include <fctsys.h>
#include <appl_wxstruct.h>
#include <wxPcbStruct.h>
#include <eda_dde.h>
#include <macros.h>
#include <pcbnew_id.h>
#include <class_board.h>
#include <class_module.h>
#include <collectors.h>
#include <pcbnew.h>
#include <protos.h>
2007-10-07 09:49:08 +00:00
/**
* Read a remote command send by Eeschema via a socket,
* port KICAD_PCB_PORT_SERVICE_NUMBER (currently 4242)
* @param cmdline = received command from Eeschema
2007-10-07 09:49:08 +00:00
* Commands are
* $PART: "reference" put cursor on component
* $PIN: "pin name" $PART: "reference" put cursor on the footprint pin
2007-10-07 09:49:08 +00:00
*/
void RemoteCommand( const char* cmdline )
2007-10-07 09:49:08 +00:00
{
char line[1024];
wxString msg;
wxString modName;
char* idcmd;
char* text;
MODULE* module = 0;
PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*)wxGetApp().GetTopWindow();
BOARD* pcb = frame->GetBoard();
wxPoint pos;
2007-10-07 09:49:08 +00:00
strncpy( line, cmdline, sizeof(line) - 1 );
idcmd = strtok( line, " \n\r" );
text = strtok( NULL, " \n\r" );
2008-02-19 07:06:58 +00:00
if( !idcmd || !text )
2007-10-07 09:49:08 +00:00
return;
if( strcmp( idcmd, "$PART:" ) == 0 )
{
modName = FROM_UTF8( text );
2007-10-07 09:49:08 +00:00
module = frame->GetBoard()->FindModuleByReference( modName );
2007-10-07 09:49:08 +00:00
2008-02-19 07:06:58 +00:00
if( module )
msg.Printf( _( "%s found" ), GetChars( modName ) );
2008-02-19 07:06:58 +00:00
else
msg.Printf( _( "%s not found" ), GetChars( modName ) );
2007-10-07 09:49:08 +00:00
frame->SetStatusText( msg );
2007-10-07 09:49:08 +00:00
if( module )
pos = module->GetPosition();
2007-10-07 09:49:08 +00:00
}
2008-02-19 07:06:58 +00:00
else if( strcmp( idcmd, "$PIN:" ) == 0 )
2007-10-07 09:49:08 +00:00
{
2008-02-19 07:06:58 +00:00
wxString pinName;
2007-10-07 09:49:08 +00:00
D_PAD* pad = NULL;
int netcode = -1;
pinName = FROM_UTF8( text );
2007-10-07 09:49:08 +00:00
text = strtok( NULL, " \n\r" );
if( text && strcmp( text, "$PART:" ) == 0 )
text = strtok( NULL, "\n\r" );
modName = FROM_UTF8( text );
2008-02-19 07:06:58 +00:00
module = pcb->FindModuleByReference( modName );
2007-10-07 09:49:08 +00:00
if( module )
2008-03-04 04:22:27 +00:00
pad = module->FindPadByName( pinName );
2007-10-07 09:49:08 +00:00
if( pad )
{
2007-10-13 06:18:44 +00:00
netcode = pad->GetNet();
// put cursor on the pad:
pos = pad->GetPosition();
}
2007-10-07 09:49:08 +00:00
if( netcode > 0 ) // highlight the pad net
2007-10-07 09:49:08 +00:00
{
pcb->HighLightON();
pcb->SetHighLightNet( netcode );
}
else
{
pcb->HighLightOFF();
pcb->SetHighLightNet( -1 );
2007-10-07 09:49:08 +00:00
}
if( module == NULL )
{
msg.Printf( _( "%s not found" ), GetChars( modName ) );
}
2007-10-07 09:49:08 +00:00
else if( pad == NULL )
2008-02-23 01:27:50 +00:00
{
msg.Printf( _( "%s pin %s not found" ), GetChars( modName ), GetChars( pinName ) );
2008-02-23 01:27:50 +00:00
frame->SetCurItem( module );
}
2007-10-07 09:49:08 +00:00
else
2008-02-23 01:27:50 +00:00
{
msg.Printf( _( "%s pin %s found" ), GetChars( modName ), GetChars( pinName ) );
2008-02-23 01:27:50 +00:00
frame->SetCurItem( pad );
}
2007-10-07 09:49:08 +00:00
frame->SetStatusText( msg );
2007-10-07 09:49:08 +00:00
}
if( module ) // if found, center the module on screen, and redraw the screen.
{
frame->SetCrossHairPosition( pos );
frame->RedrawScreen( pos, false );
}
2007-10-07 09:49:08 +00:00
}
/**
* Send a remote command to Eeschema via a socket,
2007-10-07 09:49:08 +00:00
* @param objectToSync = item to be located on schematic (module, pin or text)
* Commands are
* $PART: "reference" put cursor on component anchor
* $PART: "reference" $PAD: "pad number" put cursor on the component pin
2007-10-07 09:49:08 +00:00
* $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* objectToSync )
2007-10-07 09:49:08 +00:00
{
char cmd[1024];
const char* text_key;
MODULE* module = NULL;
D_PAD* pad;
TEXTE_MODULE* text_mod;
wxString msg;
if( objectToSync == NULL )
return;
switch( objectToSync->Type() )
{
case PCB_MODULE_T:
2007-10-07 09:49:08 +00:00
module = (MODULE*) objectToSync;
sprintf( cmd, "$PART: \"%s\"", TO_UTF8( module->GetReference() ) );
2007-10-07 09:49:08 +00:00
break;
case PCB_PAD_T:
module = (MODULE*) objectToSync->GetParent();
2007-10-07 09:49:08 +00:00
pad = (D_PAD*) objectToSync;
2011-12-12 08:37:05 +00:00
msg = pad->GetPadName();
2007-10-07 09:49:08 +00:00
sprintf( cmd, "$PART: \"%s\" $PAD: \"%s\"",
TO_UTF8( module->GetReference() ),
TO_UTF8( msg ) );
2007-10-07 09:49:08 +00:00
break;
case PCB_MODULE_TEXT_T:
module = (MODULE*) objectToSync->GetParent();
2007-10-07 09:49:08 +00:00
text_mod = (TEXTE_MODULE*) objectToSync;
if( text_mod->GetType() == TEXTE_MODULE::TEXT_is_REFERENCE )
2007-10-07 09:49:08 +00:00
text_key = "$REF:";
else if( text_mod->GetType() == TEXTE_MODULE::TEXT_is_VALUE )
2007-10-07 09:49:08 +00:00
text_key = "$VAL:";
else
break;
sprintf( cmd, "$PART: \"%s\" %s \"%s\"",
TO_UTF8( module->GetReference() ),
text_key,
TO_UTF8( text_mod->GetText() ) );
2007-10-07 09:49:08 +00:00
break;
default:
break;
}
if( module )
{
SendCommand( MSG_TO_SCH, cmd );
}
}