2011-09-30 18:15:37 +00:00
|
|
|
/**
|
|
|
|
* @file pcbnew/cross-probing.cpp
|
|
|
|
* @brief Cross probing functions to handle communication to andfrom Eeschema.
|
|
|
|
*/
|
2008-12-08 15:27:13 +00:00
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
/**
|
|
|
|
* 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)
|
2008-11-06 17:55:32 +00:00
|
|
|
* Note: these ports must be enabled for firewall protection
|
|
|
|
*/
|
2007-10-07 09:49:08 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2009-07-30 11:04:07 +00:00
|
|
|
#include "wxPcbStruct.h"
|
2007-10-07 09:49:08 +00:00
|
|
|
#include "eda_dde.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "macros.h"
|
|
|
|
|
2009-09-22 12:27:57 +00:00
|
|
|
#include "pcbnew_id.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "class_board.h"
|
|
|
|
#include "class_module.h"
|
|
|
|
|
2007-10-07 09:49:08 +00:00
|
|
|
#include "collectors.h"
|
2011-09-23 13:57:12 +00:00
|
|
|
#include "pcbnew.h"
|
2007-10-07 09:49:08 +00:00
|
|
|
#include "protos.h"
|
|
|
|
|
|
|
|
|
2011-09-30 18:15:37 +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
|
2007-10-07 18:24:15 +00:00
|
|
|
* $PIN: "pin name" $PART: "reference" put cursor on the footprint pin
|
2007-10-07 09:49:08 +00:00
|
|
|
*/
|
2011-09-23 13:57:12 +00:00
|
|
|
void RemoteCommand( const char* cmdline )
|
2007-10-07 09:49:08 +00:00
|
|
|
{
|
2011-03-01 19:26:17 +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();
|
2011-04-05 17:49:14 +00:00
|
|
|
BOARD* pcb = frame->GetBoard();
|
2011-03-01 19:26:17 +00:00
|
|
|
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 )
|
|
|
|
{
|
2011-02-28 18:36:19 +00:00
|
|
|
modName = FROM_UTF8( text );
|
2007-10-07 09:49:08 +00:00
|
|
|
|
2009-01-05 05:21:35 +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 )
|
2009-10-14 18:14:58 +00:00
|
|
|
msg.Printf( _( "%s found" ), GetChars( modName ) );
|
2008-02-19 07:06:58 +00:00
|
|
|
else
|
2009-10-14 18:14:58 +00:00
|
|
|
msg.Printf( _( "%s not found" ), GetChars( modName ) );
|
2007-10-07 09:49:08 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
frame->SetStatusText( msg );
|
|
|
|
|
2007-10-07 09:49:08 +00:00
|
|
|
if( module )
|
2011-02-11 20:48:13 +00:00
|
|
|
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;
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
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" );
|
|
|
|
|
2011-02-28 18:36:19 +00:00
|
|
|
modName = FROM_UTF8( text );
|
2008-02-19 07:06:58 +00:00
|
|
|
|
2011-04-05 17:49:14 +00:00
|
|
|
module = pcb->FindModuleByReference( modName );
|
2011-02-11 20:48:13 +00:00
|
|
|
|
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 )
|
2008-11-06 17:55:32 +00:00
|
|
|
{
|
2007-10-13 06:18:44 +00:00
|
|
|
netcode = pad->GetNet();
|
2008-12-08 15:27:13 +00:00
|
|
|
|
2008-11-06 17:55:32 +00:00
|
|
|
// put cursor on the pad:
|
2011-02-11 20:48:13 +00:00
|
|
|
pos = pad->GetPosition();
|
2008-11-06 17:55:32 +00:00
|
|
|
}
|
2007-10-07 09:49:08 +00:00
|
|
|
|
2008-11-06 17:55:32 +00:00
|
|
|
if( netcode > 0 ) /* highlight the pad net*/
|
2007-10-07 09:49:08 +00:00
|
|
|
{
|
2011-09-14 20:04:58 +00:00
|
|
|
pcb->HighLightON();
|
|
|
|
pcb->SetHighLightNet( netcode );
|
2008-11-06 17:55:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-14 20:04:58 +00:00
|
|
|
pcb->HighLightOFF();
|
|
|
|
pcb->SetHighLightNet( -1 );
|
2007-10-07 09:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( module == NULL )
|
2011-09-14 20:04:58 +00:00
|
|
|
{
|
2009-10-14 18:14:58 +00:00
|
|
|
msg.Printf( _( "%s not found" ), GetChars( modName ) );
|
2011-09-14 20:04:58 +00:00
|
|
|
}
|
2007-10-07 09:49:08 +00:00
|
|
|
else if( pad == NULL )
|
2008-02-23 01:27:50 +00:00
|
|
|
{
|
2011-02-11 20:48:13 +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
|
|
|
{
|
2011-02-11 20:48:13 +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
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
frame->SetStatusText( msg );
|
2007-10-07 09:49:08 +00:00
|
|
|
}
|
|
|
|
|
2008-11-06 17:55:32 +00:00
|
|
|
if( module ) // if found, center the module on screen, and redraw the screen.
|
2011-02-25 19:09:42 +00:00
|
|
|
{
|
|
|
|
frame->GetScreen()->SetCrossHairPosition(pos);
|
2011-02-11 20:48:13 +00:00
|
|
|
frame->RedrawScreen( pos, false );
|
2011-02-25 19:09:42 +00:00
|
|
|
}
|
2007-10-07 09:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-30 18:15:37 +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
|
2007-10-07 18:24:15 +00:00
|
|
|
* $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
|
|
|
|
*/
|
2011-09-23 13:57:12 +00:00
|
|
|
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() )
|
|
|
|
{
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_MODULE_T:
|
2007-10-07 09:49:08 +00:00
|
|
|
module = (MODULE*) objectToSync;
|
2011-09-23 13:57:12 +00:00
|
|
|
sprintf( cmd, "$PART: \"%s\"", TO_UTF8( module->m_Reference->m_Text ) );
|
2007-10-07 09:49:08 +00:00
|
|
|
break;
|
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_PAD_T:
|
2008-11-24 06:53:43 +00:00
|
|
|
module = (MODULE*) objectToSync->GetParent();
|
2007-10-07 09:49:08 +00:00
|
|
|
pad = (D_PAD*) objectToSync;
|
|
|
|
msg = pad->ReturnStringPadName();
|
|
|
|
sprintf( cmd, "$PART: \"%s\" $PAD: \"%s\"",
|
2011-02-28 18:36:19 +00:00
|
|
|
TO_UTF8( module->m_Reference->m_Text ),
|
|
|
|
TO_UTF8( msg ) );
|
2007-10-07 09:49:08 +00:00
|
|
|
break;
|
|
|
|
|
2011-10-01 19:24:27 +00:00
|
|
|
case PCB_MODULE_TEXT_T:
|
2008-11-06 17:55:32 +00:00
|
|
|
#define REFERENCE 0
|
|
|
|
#define VALUE 1
|
2008-11-24 06:53:43 +00:00
|
|
|
module = (MODULE*) objectToSync->GetParent();
|
2007-10-07 09:49:08 +00:00
|
|
|
text_mod = (TEXTE_MODULE*) objectToSync;
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2007-10-07 09:49:08 +00:00
|
|
|
if( text_mod->m_Type == REFERENCE )
|
|
|
|
text_key = "$REF:";
|
|
|
|
else if( text_mod->m_Type == VALUE )
|
|
|
|
text_key = "$VAL:";
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
|
|
|
|
sprintf( cmd, "$PART: \"%s\" %s \"%s\"",
|
2011-02-28 18:36:19 +00:00
|
|
|
TO_UTF8( module->m_Reference->m_Text ),
|
2008-12-08 15:27:13 +00:00
|
|
|
text_key,
|
2011-02-28 18:36:19 +00:00
|
|
|
TO_UTF8( text_mod->m_Text ) );
|
2007-10-07 09:49:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( module )
|
|
|
|
{
|
|
|
|
SendCommand( MSG_TO_SCH, cmd );
|
|
|
|
}
|
|
|
|
}
|