KiCad PCB EDA Suite
eeschema/cross-probing.cpp File Reference
#include <kiface_i.h>
#include <kiway_express.h>
#include <eda_dde.h>
#include <connection_graph.h>
#include <sch_symbol.h>
#include <schematic.h>
#include <reporter.h>
#include <kicad_string.h>
#include <netlist_exporters/netlist_exporter_kicad.h>
#include <project/project_file.h>
#include <project/net_settings.h>
#include <tools/ee_actions.h>
#include <tools/reannotate.h>
#include <tools/sch_editor_control.h>
#include <advanced_config.h>
#include <netclass.h>

Go to the source code of this file.

Functions

std::string FormatProbeItem (EDA_ITEM *aItem, SCH_COMPONENT *aSymbol)
 

Function Documentation

◆ FormatProbeItem()

std::string FormatProbeItem ( EDA_ITEM aItem,
SCH_COMPONENT aSymbol 
)

Definition at line 372 of file eeschema/cross-probing.cpp.

373 {
374  // This is a keyword followed by a quoted string.
375 
376  // Cross probing to Pcbnew if a pin or a component is found
377  switch( aItem->Type() )
378  {
379  case SCH_FIELD_T:
380  if( aSymbol )
381  {
382  return StrPrintf( "$PART: \"%s\"",
383  TO_UTF8( aSymbol->GetField( REFERENCE_FIELD )->GetText() ) );
384  }
385  break;
386 
387  case SCH_COMPONENT_T:
388  aSymbol = (SCH_COMPONENT*) aItem;
389  return StrPrintf( "$PART: \"%s\"",
390  TO_UTF8( aSymbol->GetField( REFERENCE_FIELD )->GetText() ) );
391 
392  case SCH_SHEET_T:
393  {
394  // For cross probing, we need the full path of the sheet, because
395  // in complex hierarchies the sheet uuid of not unique
396  SCH_SHEET* sheet = (SCH_SHEET*)aItem;
397  wxString full_path;
398 
399  SCH_SHEET* parent = sheet;
400  while( (parent = dynamic_cast<SCH_SHEET*>( parent->GetParent() ) ) )
401  {
402  if( parent->GetParent() ) // The root sheet has no parent and path is just "/"
403  {
404  full_path.Prepend( parent->m_Uuid.AsString() );
405  full_path.Prepend( "/" );
406  }
407  }
408 
409  full_path += "/" + sheet->m_Uuid.AsString();
410 
411  return StrPrintf( "$SHEET: \"%s\"", TO_UTF8( full_path ) );
412  }
413 
414  case SCH_PIN_T:
415  {
416  SCH_PIN* pin = (SCH_PIN*) aItem;
417  aSymbol = pin->GetParentSymbol();
418 
419  if( !pin->GetNumber().IsEmpty() )
420  {
421  return StrPrintf( "$PIN: \"%s\" $PART: \"%s\"",
422  TO_UTF8( pin->GetNumber() ),
423  TO_UTF8( aSymbol->GetField( REFERENCE_FIELD )->GetText() ) );
424  }
425  else
426  {
427  return StrPrintf( "$PART: \"%s\"",
428  TO_UTF8( aSymbol->GetField( REFERENCE_FIELD )->GetText() ) );
429  }
430  }
431 
432  default:
433  break;
434  }
435 
436  return "";
437 }
Field Reference of part, i.e. "IC21".
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Returns a mandatory field in this symbol.
Definition: sch_symbol.cpp:688
SCH_COMPONENT * GetParentSymbol() const
Definition: sch_pin.cpp:141
wxString AsString() const
Definition: kiid.cpp:213
wxString GetNumber() const
Definition: sch_pin.h:116
int StrPrintf(std::string *result, const char *format,...)
This is like sprintf() but the output is appended to a std::string instead of to a character array.
Definition: richio.cpp:78
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
EDA_ITEM * GetParent() const
Definition: eda_item.h:164
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:219
const KIID m_Uuid
Definition: eda_item.h:524
Schematic symbol object.
Definition: sch_symbol.h:79
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:162

References KIID::AsString(), SCH_COMPONENT::GetField(), SCH_PIN::GetNumber(), EDA_ITEM::GetParent(), SCH_PIN::GetParentSymbol(), EDA_TEXT::GetText(), EDA_ITEM::m_Uuid, REFERENCE_FIELD, SCH_COMPONENT_T, SCH_FIELD_T, SCH_PIN_T, SCH_SHEET_T, StrPrintf(), TO_UTF8, and EDA_ITEM::Type().

Referenced by SCH_EDIT_FRAME::SendMessageToPCBNEW().