kicad/pcbnew/cross-probing.cpp

249 lines
6.5 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>
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
2014-03-20 00:42:08 +00:00
#include <pgm_base.h>
#include <kiface_i.h>
#include <kiway_express.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>
2007-10-07 09:49:08 +00:00
2015-02-14 20:52:22 +00:00
#include <tools/common_actions.h>
#include <tool/tool_manager.h>
2015-02-14 20:52:22 +00:00
#include <pcb_draw_panel_gal.h>
2007-10-07 09:49:08 +00:00
/* Execute a remote command send by Eeschema via a socket,
* port KICAD_PCB_PORT_SERVICE_NUMBER
* 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 PCB_EDIT_FRAME::ExecuteRemoteCommand( 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;
BOARD* pcb = GetBoard();
wxPoint pos;
2007-10-07 09:49:08 +00:00
strncpy( line, cmdline, sizeof(line) - 1 );
2015-01-19 19:03:50 +00:00
line[sizeof(line) - 1] = 0;
2007-10-07 09:49:08 +00:00
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 = pcb->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
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 )
{
netcode = pad->GetNetCode();
// 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 ) );
SetCurItem( module );
2008-02-23 01:27:50 +00:00
}
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 ) );
SetCurItem( pad );
2008-02-23 01:27:50 +00:00
}
2007-10-07 09:49:08 +00:00
SetStatusText( msg );
2007-10-07 09:49:08 +00:00
}
if( module ) // if found, center the module on screen, and redraw the screen.
{
2015-02-14 20:52:22 +00:00
if( IsGalCanvasActive() )
{
GetGalCanvas()->GetView()->SetCenter( VECTOR2D( module->GetPosition() ) );
m_toolManager->RunAction( COMMON_ACTIONS::selectionClear, true );
m_toolManager->RunAction( COMMON_ACTIONS::selectItem, true, module );
}
else
{
SetCrossHairPosition( pos );
RedrawScreen( pos, false );
}
}
2007-10-07 09:49:08 +00:00
}
2014-04-21 06:28:17 +00:00
std::string FormatProbeItem( BOARD_ITEM* aItem )
2007-10-07 09:49:08 +00:00
{
2014-04-21 06:28:17 +00:00
MODULE* module;
2007-10-07 09:49:08 +00:00
2014-04-21 06:28:17 +00:00
switch( aItem->Type() )
2007-10-07 09:49:08 +00:00
{
case PCB_MODULE_T:
2014-04-21 06:28:17 +00:00
module = (MODULE*) aItem;
return StrPrintf( "$PART: \"%s\"", TO_UTF8( module->GetReference() ) );
2007-10-07 09:49:08 +00:00
case PCB_PAD_T:
2014-04-21 06:28:17 +00:00
{
module = (MODULE*) aItem->GetParent();
wxString pad = ((D_PAD*)aItem)->GetPadName();
return StrPrintf( "$PART: \"%s\" $PAD: \"%s\"",
TO_UTF8( module->GetReference() ),
TO_UTF8( pad ) );
}
2007-10-07 09:49:08 +00:00
case PCB_MODULE_TEXT_T:
2014-04-21 06:28:17 +00:00
{
module = static_cast<MODULE*>( aItem->GetParent() );
TEXTE_MODULE* text_mod = static_cast<TEXTE_MODULE*>( aItem );
2007-10-07 09:49:08 +00:00
2014-04-21 06:28:17 +00:00
const char* text_key;
/* This can't be a switch since the break need to pull out
* from the outer switch! */
2014-04-21 06:28:17 +00:00
if( text_mod->GetType() == TEXTE_MODULE::TEXT_is_REFERENCE )
text_key = "$REF:";
else if( text_mod->GetType() == TEXTE_MODULE::TEXT_is_VALUE )
text_key = "$VAL:";
else
break;
return StrPrintf( "$PART: \"%s\" %s \"%s\"",
TO_UTF8( module->GetReference() ),
text_key,
TO_UTF8( text_mod->GetText() ) );
}
2007-10-07 09:49:08 +00:00
default:
break;
}
2014-04-21 06:28:17 +00:00
return "";
}
/* Send a remote command to Eeschema via a socket,
* aSyncItem = item to be located on schematic (module, pin or text)
2014-04-21 06:28:17 +00:00
* Commands are
* $PART: "reference" put cursor on component anchor
* $PART: "reference" $PAD: "pad number" put cursor on the component pin
* $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* aSyncItem )
{
#if 1
wxASSERT( aSyncItem ); // can't we fix the caller?
#else
if( !aSyncItem )
return;
#endif
std::string packet = FormatProbeItem( aSyncItem );
if( packet.size() )
2007-10-07 09:49:08 +00:00
{
if( Kiface().IsSingle() )
2014-04-21 06:28:17 +00:00
SendCommand( MSG_TO_SCH, packet.c_str() );
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_SCH, MAIL_CROSS_PROBE, packet, this );
}
2007-10-07 09:49:08 +00:00
}
}
2014-04-21 06:28:17 +00:00
void PCB_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
{
const std::string& payload = mail.GetPayload();
switch( mail.Command() )
{
case MAIL_CROSS_PROBE:
ExecuteRemoteCommand( payload.c_str() );
break;
// many many others.
default:
;
}
}