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.

195 lines
5.1 KiB

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. * @file pcbnew/cross-probing.cpp
  3. * @brief Cross probing functions to handle communication to andfrom Eeschema.
  4. */
  5. /**
  6. * Handle messages between Pcbnew and Eeschema via a socket, the port numbers are
  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 <wxPcbStruct.h>
  14. #include <eda_dde.h>
  15. #include <macros.h>
  16. #include <pcbnew_id.h>
  17. #include <class_board.h>
  18. #include <class_module.h>
  19. #include <collectors.h>
  20. #include <pcbnew.h>
  21. /* Execute a remote command send by Eeschema via a socket,
  22. * port KICAD_PCB_PORT_SERVICE_NUMBER
  23. * cmdline = received command from Eeschema
  24. * Commands are
  25. * $PART: "reference" put cursor on component
  26. * $PIN: "pin name" $PART: "reference" put cursor on the footprint pin
  27. */
  28. void PCB_EDIT_FRAME::ExecuteRemoteCommand( const char* cmdline )
  29. {
  30. char line[1024];
  31. wxString msg;
  32. wxString modName;
  33. char* idcmd;
  34. char* text;
  35. MODULE* module = 0;
  36. BOARD* pcb = GetBoard();
  37. wxPoint pos;
  38. strncpy( line, cmdline, sizeof(line) - 1 );
  39. idcmd = strtok( line, " \n\r" );
  40. text = strtok( NULL, " \n\r" );
  41. if( !idcmd || !text )
  42. return;
  43. if( strcmp( idcmd, "$PART:" ) == 0 )
  44. {
  45. modName = FROM_UTF8( text );
  46. module = pcb->FindModuleByReference( modName );
  47. if( module )
  48. msg.Printf( _( "%s found" ), GetChars( modName ) );
  49. else
  50. msg.Printf( _( "%s not found" ), GetChars( modName ) );
  51. SetStatusText( msg );
  52. if( module )
  53. pos = module->GetPosition();
  54. }
  55. else if( strcmp( idcmd, "$PIN:" ) == 0 )
  56. {
  57. wxString pinName;
  58. D_PAD* pad = NULL;
  59. int netcode = -1;
  60. pinName = FROM_UTF8( text );
  61. text = strtok( NULL, " \n\r" );
  62. if( text && strcmp( text, "$PART:" ) == 0 )
  63. text = strtok( NULL, "\n\r" );
  64. modName = FROM_UTF8( text );
  65. module = pcb->FindModuleByReference( modName );
  66. if( module )
  67. pad = module->FindPadByName( pinName );
  68. if( pad )
  69. {
  70. netcode = pad->GetNet();
  71. // put cursor on the pad:
  72. pos = pad->GetPosition();
  73. }
  74. if( netcode > 0 ) // highlight the pad net
  75. {
  76. pcb->HighLightON();
  77. pcb->SetHighLightNet( netcode );
  78. }
  79. else
  80. {
  81. pcb->HighLightOFF();
  82. pcb->SetHighLightNet( -1 );
  83. }
  84. if( module == NULL )
  85. {
  86. msg.Printf( _( "%s not found" ), GetChars( modName ) );
  87. }
  88. else if( pad == NULL )
  89. {
  90. msg.Printf( _( "%s pin %s not found" ), GetChars( modName ), GetChars( pinName ) );
  91. SetCurItem( module );
  92. }
  93. else
  94. {
  95. msg.Printf( _( "%s pin %s found" ), GetChars( modName ), GetChars( pinName ) );
  96. SetCurItem( pad );
  97. }
  98. SetStatusText( msg );
  99. }
  100. if( module ) // if found, center the module on screen, and redraw the screen.
  101. {
  102. SetCrossHairPosition( pos );
  103. RedrawScreen( pos, false );
  104. }
  105. }
  106. /**
  107. * Send a remote command to Eeschema via a socket,
  108. * @param objectToSync = item to be located on schematic (module, pin or text)
  109. * Commands are
  110. * $PART: "reference" put cursor on component anchor
  111. * $PART: "reference" $PAD: "pad number" put cursor on the component pin
  112. * $PART: "reference" $REF: "reference" put cursor on the component ref
  113. * $PART: "reference" $VAL: "value" put cursor on the component value
  114. */
  115. void PCB_EDIT_FRAME::SendMessageToEESCHEMA( BOARD_ITEM* objectToSync )
  116. {
  117. char cmd[1024];
  118. const char* text_key;
  119. MODULE* module = NULL;
  120. D_PAD* pad;
  121. TEXTE_MODULE* text_mod;
  122. wxString msg;
  123. if( objectToSync == NULL )
  124. return;
  125. switch( objectToSync->Type() )
  126. {
  127. case PCB_MODULE_T:
  128. module = (MODULE*) objectToSync;
  129. sprintf( cmd, "$PART: \"%s\"", TO_UTF8( module->GetReference() ) );
  130. break;
  131. case PCB_PAD_T:
  132. module = (MODULE*) objectToSync->GetParent();
  133. pad = (D_PAD*) objectToSync;
  134. msg = pad->GetPadName();
  135. sprintf( cmd, "$PART: \"%s\" $PAD: \"%s\"",
  136. TO_UTF8( module->GetReference() ),
  137. TO_UTF8( msg ) );
  138. break;
  139. case PCB_MODULE_TEXT_T:
  140. module = (MODULE*) objectToSync->GetParent();
  141. text_mod = (TEXTE_MODULE*) objectToSync;
  142. if( text_mod->GetType() == TEXTE_MODULE::TEXT_is_REFERENCE )
  143. text_key = "$REF:";
  144. else if( text_mod->GetType() == TEXTE_MODULE::TEXT_is_VALUE )
  145. text_key = "$VAL:";
  146. else
  147. break;
  148. sprintf( cmd, "$PART: \"%s\" %s \"%s\"",
  149. TO_UTF8( module->GetReference() ),
  150. text_key,
  151. TO_UTF8( text_mod->GetText() ) );
  152. break;
  153. default:
  154. break;
  155. }
  156. if( module )
  157. {
  158. SendCommand( MSG_TO_SCH, cmd );
  159. }
  160. }