You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

199 lines
5.6 KiB

17 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
  1. /*****************************************************************/
  2. /* Cross probing function: handle communication to/from eeschema */
  3. /*****************************************************************/
  4. /* cross-probing.cpp */
  5. /** Handle messages between pcbnew and eeschema via a socket,
  6. * the port number is
  7. * KICAD_PCB_PORT_SERVICE_NUMBER (currently 4242) (eeschema to pcbnew)
  8. * KICAD_SCH_PORT_SERVICE_NUMBER (currently 4243) (pcbnew to eeschema)
  9. * Note: these ports must be enabled for firewall protection
  10. */
  11. #include "fctsys.h"
  12. #include "appl_wxstruct.h"
  13. #include "common.h"
  14. #include "pcbnew.h"
  15. #include "wxPcbStruct.h"
  16. #include "eda_dde.h"
  17. #include "pcbnew_id.h"
  18. #include "collectors.h"
  19. #include "protos.h"
  20. /*******************************************/
  21. void RemoteCommand( const char* cmdline )
  22. /*******************************************/
  23. /** Read a remote command send by eeschema via a socket,
  24. * port KICAD_PCB_PORT_SERVICE_NUMBER (currently 4242)
  25. * @param cmdline = received command from eeschema
  26. * Commands are
  27. * $PART: "reference" put cursor on component
  28. * $PIN: "pin name" $PART: "reference" put cursor on the footprint pin
  29. */
  30. {
  31. char line[1024];
  32. wxString msg;
  33. wxString modName;
  34. char* idcmd;
  35. char* text;
  36. MODULE* module = 0;
  37. PCB_EDIT_FRAME* frame = (PCB_EDIT_FRAME*)wxGetApp().GetTopWindow();
  38. wxPoint pos;
  39. strncpy( line, cmdline, sizeof(line) - 1 );
  40. idcmd = strtok( line, " \n\r" );
  41. text = strtok( NULL, " \n\r" );
  42. if( !idcmd || !text )
  43. return;
  44. if( strcmp( idcmd, "$PART:" ) == 0 )
  45. {
  46. modName = FROM_UTF8( text );
  47. module = frame->GetBoard()->FindModuleByReference( modName );
  48. if( module )
  49. msg.Printf( _( "%s found" ), GetChars( modName ) );
  50. else
  51. msg.Printf( _( "%s not found" ), GetChars( modName ) );
  52. frame->SetStatusText( msg );
  53. if( module )
  54. pos = module->GetPosition();
  55. }
  56. else if( strcmp( idcmd, "$PIN:" ) == 0 )
  57. {
  58. wxString pinName;
  59. D_PAD* pad = NULL;
  60. int netcode = -1;
  61. pinName = FROM_UTF8( text );
  62. text = strtok( NULL, " \n\r" );
  63. if( text && strcmp( text, "$PART:" ) == 0 )
  64. text = strtok( NULL, "\n\r" );
  65. modName = FROM_UTF8( text );
  66. module = frame->GetBoard()->FindModuleByReference( modName );
  67. if( module )
  68. pad = module->FindPadByName( pinName );
  69. if( pad )
  70. {
  71. netcode = pad->GetNet();
  72. // put cursor on the pad:
  73. pos = pad->GetPosition();
  74. }
  75. if( netcode > 0 ) /* highlight the pad net*/
  76. {
  77. g_HighLight_Status = 1;
  78. g_HighLight_NetCode = netcode;
  79. }
  80. else
  81. {
  82. g_HighLight_Status = 0;
  83. g_HighLight_NetCode = 0;
  84. }
  85. if( module == NULL )
  86. msg.Printf( _( "%s not found" ), GetChars( modName ) );
  87. else if( pad == NULL )
  88. {
  89. msg.Printf( _( "%s pin %s not found" ), GetChars( modName ), GetChars( pinName ) );
  90. frame->SetCurItem( module );
  91. }
  92. else
  93. {
  94. msg.Printf( _( "%s pin %s found" ), GetChars( modName ), GetChars( pinName ) );
  95. frame->SetCurItem( pad );
  96. }
  97. frame->SetStatusText( msg );
  98. }
  99. if( module ) // if found, center the module on screen, and redraw the screen.
  100. {
  101. frame->GetScreen()->SetCrossHairPosition(pos);
  102. frame->RedrawScreen( pos, false );
  103. }
  104. }
  105. // see wxstruct.h
  106. /**************************************************************************/
  107. void PCB_EDIT_FRAME::SendMessageToEESCHEMA( BOARD_ITEM* objectToSync )
  108. /**************************************************************************/
  109. /** Send a remote command to eeschema via a socket,
  110. * @param objectToSync = item to be located on schematic (module, pin or text)
  111. * Commands are
  112. * $PART: "reference" put cursor on component anchor
  113. * $PART: "reference" $PAD: "pad number" put cursor on the component pin
  114. * $PART: "reference" $REF: "reference" put cursor on the component ref
  115. * $PART: "reference" $VAL: "value" put cursor on the component value
  116. */
  117. {
  118. char cmd[1024];
  119. const char* text_key;
  120. MODULE* module = NULL;
  121. D_PAD* pad;
  122. TEXTE_MODULE* text_mod;
  123. wxString msg;
  124. if( objectToSync == NULL )
  125. return;
  126. switch( objectToSync->Type() )
  127. {
  128. case TYPE_MODULE:
  129. module = (MODULE*) objectToSync;
  130. sprintf( cmd, "$PART: \"%s\"",
  131. TO_UTF8( module->m_Reference->m_Text ) );
  132. break;
  133. case TYPE_PAD:
  134. module = (MODULE*) objectToSync->GetParent();
  135. pad = (D_PAD*) objectToSync;
  136. msg = pad->ReturnStringPadName();
  137. sprintf( cmd, "$PART: \"%s\" $PAD: \"%s\"",
  138. TO_UTF8( module->m_Reference->m_Text ),
  139. TO_UTF8( msg ) );
  140. break;
  141. case TYPE_TEXTE_MODULE:
  142. #define REFERENCE 0
  143. #define VALUE 1
  144. module = (MODULE*) objectToSync->GetParent();
  145. text_mod = (TEXTE_MODULE*) objectToSync;
  146. if( text_mod->m_Type == REFERENCE )
  147. text_key = "$REF:";
  148. else if( text_mod->m_Type == VALUE )
  149. text_key = "$VAL:";
  150. else
  151. break;
  152. sprintf( cmd, "$PART: \"%s\" %s \"%s\"",
  153. TO_UTF8( module->m_Reference->m_Text ),
  154. text_key,
  155. TO_UTF8( text_mod->m_Text ) );
  156. break;
  157. default:
  158. break;
  159. }
  160. if( module )
  161. {
  162. SendCommand( MSG_TO_SCH, cmd );
  163. }
  164. }