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.

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