KiCad PCB EDA Suite
eeschema/cross-probing.cpp File Reference
#include <fctsys.h>
#include <pgm_base.h>
#include <kiface_i.h>
#include <kiway_express.h>
#include <macros.h>
#include <eda_dde.h>
#include <connection_graph.h>
#include <sch_edit_frame.h>
#include <general.h>
#include <lib_item.h>
#include <lib_pin.h>
#include <sch_component.h>
#include <sch_sheet.h>
#include <sch_view.h>
#include <schematic.h>
#include <reporter.h>
#include <netlist_exporters/netlist_exporter_kicad.h>
#include <tools/ee_actions.h>
#include <tools/sch_editor_control.h>

Go to the source code of this file.

Functions

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

Function Documentation

◆ FormatProbeItem()

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

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

262 {
263  // This is a keyword followed by a quoted string.
264 
265  // Cross probing to Pcbnew if a pin or a component is found
266  switch( aItem->Type() )
267  {
268  case SCH_FIELD_T:
269  if( aComp )
270  return StrPrintf( "$PART: \"%s\"", TO_UTF8( aComp->GetField( REFERENCE )->GetText() ) );
271  break;
272 
273  case SCH_COMPONENT_T:
274  aComp = (SCH_COMPONENT*) aItem;
275  return StrPrintf( "$PART: \"%s\"", TO_UTF8( aComp->GetField( REFERENCE )->GetText() ) );
276 
277  case SCH_SHEET_T:
278  {
279  // For cross probing, we need the full path of the sheet, because
280  // in complex hierarchies the sheet uuid of not unique
281  SCH_SHEET* sheet = (SCH_SHEET*)aItem;
282  wxString full_path;
283 
284  SCH_SHEET* parent = sheet;
285  while( (parent = dynamic_cast<SCH_SHEET*>( parent->GetParent() ) ) )
286  {
287  if( parent->GetParent() ) // The root sheet has no parent and path is just "/"
288  {
289  full_path.Prepend( parent->m_Uuid.AsString() );
290  full_path.Prepend( "/" );
291  }
292  }
293 
294  full_path += "/" + sheet->m_Uuid.AsString();
295 
296  return StrPrintf( "$SHEET: \"%s\"", TO_UTF8( full_path ) );
297  }
298 
299  case SCH_PIN_T:
300  {
301  SCH_PIN* pin = (SCH_PIN*) aItem;
302  aComp = pin->GetParentComponent();
303 
304  if( !pin->GetNumber().IsEmpty() )
305  {
306  return StrPrintf( "$PIN: \"%s\" $PART: \"%s\"",
307  TO_UTF8( pin->GetNumber() ),
308  TO_UTF8( aComp->GetField( REFERENCE )->GetText() ) );
309  }
310  else
311  {
312  return StrPrintf( "$PART: \"%s\"",
313  TO_UTF8( aComp->GetField( REFERENCE )->GetText() ) );
314  }
315  }
316 
317  default:
318  break;
319  }
320 
321  return "";
322 }
int StrPrintf(std::string *aResult, const char *aFormat,...)
Function StrPrintf is like sprintf() but the output is appended to a std::string instead of to a char...
Definition: richio.cpp:74
wxString AsString() const
Definition: common.cpp:157
Field Reference of part, i.e. "IC21".
const wxString & GetNumber() const
Definition: sch_pin.h:104
EDA_ITEM * GetParent() const
Definition: base_struct.h:199
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:216
const KIID m_Uuid
Definition: base_struct.h:166
SCH_FIELD * GetField(int aFieldNdx)
Returns a field in this symbol.
Schematic symbol object.
Definition: sch_component.h:88
#define TO_UTF8(wxstring)
SCH_COMPONENT * GetParentComponent() const
Definition: sch_pin.cpp:64
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:126
KICAD_T Type() const
Function Type()
Definition: base_struct.h:197

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

Referenced by SCH_EDIT_FRAME::SendMessageToPCBNEW().