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 <eeschema_settings.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 <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 *aComp)
 

Function Documentation

◆ FormatProbeItem()

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

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

270 {
271  // This is a keyword followed by a quoted string.
272 
273  // Cross probing to Pcbnew if a pin or a component is found
274  switch( aItem->Type() )
275  {
276  case SCH_FIELD_T:
277  if( aComp )
278  return StrPrintf( "$PART: \"%s\"", TO_UTF8( aComp->GetField( REFERENCE )->GetText() ) );
279  break;
280 
281  case SCH_COMPONENT_T:
282  aComp = (SCH_COMPONENT*) aItem;
283  return StrPrintf( "$PART: \"%s\"", TO_UTF8( aComp->GetField( REFERENCE )->GetText() ) );
284 
285  case SCH_SHEET_T:
286  {
287  // For cross probing, we need the full path of the sheet, because
288  // in complex hierarchies the sheet uuid of not unique
289  SCH_SHEET* sheet = (SCH_SHEET*)aItem;
290  wxString full_path;
291 
292  SCH_SHEET* parent = sheet;
293  while( (parent = dynamic_cast<SCH_SHEET*>( parent->GetParent() ) ) )
294  {
295  if( parent->GetParent() ) // The root sheet has no parent and path is just "/"
296  {
297  full_path.Prepend( parent->m_Uuid.AsString() );
298  full_path.Prepend( "/" );
299  }
300  }
301 
302  full_path += "/" + sheet->m_Uuid.AsString();
303 
304  return StrPrintf( "$SHEET: \"%s\"", TO_UTF8( full_path ) );
305  }
306 
307  case SCH_PIN_T:
308  {
309  SCH_PIN* pin = (SCH_PIN*) aItem;
310  aComp = pin->GetParentComponent();
311 
312  if( !pin->GetNumber().IsEmpty() )
313  {
314  return StrPrintf( "$PIN: \"%s\" $PART: \"%s\"",
315  TO_UTF8( pin->GetNumber() ),
316  TO_UTF8( aComp->GetField( REFERENCE )->GetText() ) );
317  }
318  else
319  {
320  return StrPrintf( "$PART: \"%s\"",
321  TO_UTF8( aComp->GetField( REFERENCE )->GetText() ) );
322  }
323  }
324 
325  default:
326  break;
327  }
328 
329  return "";
330 }
wxString AsString() const
Definition: common.cpp:165
Field Reference of part, i.e. "IC21".
int StrPrintf(std::string *result, const char *format,...)
Function StrPrintf is like sprintf() but the output is appended to a std::string instead of to a char...
Definition: richio.cpp:74
const wxString & GetNumber() const
Definition: sch_pin.h:106
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:100
EDA_ITEM * GetParent() const
Definition: base_struct.h:195
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:162
SCH_FIELD * GetField(int aFieldNdx)
Returns a field in this symbol.
Schematic symbol object.
Definition: sch_component.h:88
SCH_COMPONENT * GetParentComponent() const
Definition: sch_pin.cpp:81
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:127
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

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, StrPrintf(), TO_UTF8, and EDA_ITEM::Type().

Referenced by SCH_EDIT_FRAME::SendMessageToPCBNEW().