KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_tool_utils.h File Reference
#include <optional>
#include <set>
#include <sch_item.h>
#include <tool/selection.h>

Go to the source code of this file.

Functions

wxString GetSchItemAsText (const SCH_ITEM &aItem)
 
wxString GetSelectedItemsAsText (const SELECTION &aSel)
 
std::set< int > GetUnplacedUnitsForSymbol (const SCH_SYMBOL &aSym)
 Get a list of unplaced (i.e.
 
std::optional< SCH_REFERENCEFindSymbolByRefAndUnit (const SCHEMATIC &aSheet, const wxString &aRef, int aUnit)
 Find a symbol by reference and unit.
 
std::vector< SCH_SYMBOL * > GetSameSymbolMultiUnitSelection (const SELECTION &aSel)
 Validates and gathers a selection containing multiple symbol units that all belong to the same reference designator and originate from the same library symbol (LIB_ID).
 
bool SwapPinGeometry (SCH_PIN *aFirst, SCH_PIN *aSecond)
 Swap the positions/lengths/etc.
 
bool SymbolHasSheetInstances (const SCH_SYMBOL &aSymbol, const wxString &aCurrentProject, std::set< wxString > *aSheetPaths=nullptr, std::set< wxString > *aProjectNames=nullptr)
 Returns true when the given symbol has instances, e.g.
 
std::set< wxString > GetSheetNamesFromPaths (const std::set< wxString > &aSheetPaths, const SCHEMATIC &aSchematic)
 Get human-readable sheet names from a set of sheet paths, e.g.
 

Function Documentation

◆ FindSymbolByRefAndUnit()

std::optional< SCH_REFERENCE > FindSymbolByRefAndUnit ( const SCHEMATIC & aSheet,
const wxString & aRef,
int aUnit )

Find a symbol by reference and unit.

Returns
A SCH_REFERENCE to the found symbol, or std::nullopt if not found.

Definition at line 164 of file sch_tool_utils.cpp.

References SCH_SHEET_LIST::GetSymbols(), and SCHEMATIC::Hierarchy().

Referenced by SCH_EDIT_FRAME::SelectUnit().

◆ GetSameSymbolMultiUnitSelection()

std::vector< SCH_SYMBOL * > GetSameSymbolMultiUnitSelection ( const SELECTION & aSel)

Validates and gathers a selection containing multiple symbol units that all belong to the same reference designator and originate from the same library symbol (LIB_ID).

Used by gate label swap.

Returns
a SELECTION of SCH_SYMBOL* if valid, or an empty vector if not valid.

Definition at line 182 of file sch_tool_utils.cpp.

References SCHEMATIC::CurrentSheet(), SELECTION::GetItemsSortedBySelectionOrder(), SCH_SYMBOL::GetLibId(), SCH_SYMBOL::GetLibSymbolRef(), SCH_SYMBOL::GetPins(), SCH_SYMBOL::GetRef(), SELECTION::GetSize(), LIB_SYMBOL::GetUnitCount(), SELECTION::OnlyContains(), result, and SCH_ITEM::Schematic().

Referenced by SCH_SELECTION_TOOL::Init(), and SCH_EDIT_TOOL::SwapUnitLabels().

◆ GetSchItemAsText()

◆ GetSelectedItemsAsText()

wxString GetSelectedItemsAsText ( const SELECTION & aSel)

◆ GetSheetNamesFromPaths()

std::set< wxString > GetSheetNamesFromPaths ( const std::set< wxString > & aSheetPaths,
const SCHEMATIC & aSchematic )

Get human-readable sheet names from a set of sheet paths, e.g.

the SHEETNAME field

Parameters
aSheetPathsset of sheet paths to convert
aSchematicthe schematic to search for sheet names
Returns
a set of human-readable sheet names, or the original sheet path if no name can be resolved in this schmatic (this happens when sheets are shared across projects)

Definition at line 331 of file sch_tool_utils.cpp.

References SCH_SHEET::GetField(), SCH_FIELD::GetShownText(), SCHEMATIC::Hierarchy(), name, and SHEET_NAME.

Referenced by BACK_ANNOTATE::applyPinSwaps(), and SCH_EDIT_TOOL::SwapPins().

◆ GetUnplacedUnitsForSymbol()

std::set< int > GetUnplacedUnitsForSymbol ( const SCH_SYMBOL & aSym)

Get a list of unplaced (i.e.

not in schamtic) unit numbers for a symbol.

Definition at line 135 of file sch_tool_utils.cpp.

References SCHEMATIC::CurrentSheet(), SCH_SYMBOL::GetRef(), SCH_SHEET_LIST::GetSymbols(), SCH_SYMBOL::GetUnitCount(), SCHEMATIC::Hierarchy(), and SCH_ITEM::Schematic().

Referenced by SCH_DRAWING_TOOLS::PlaceNextSymbolUnit(), and SYMBOL_UNIT_MENU::update().

◆ SwapPinGeometry()

bool SwapPinGeometry ( SCH_PIN * aFirst,
SCH_PIN * aSecond )

Swap the positions/lengths/etc.

between two pins in a symbol in such a way that connectivity is maintained.

The swap operates on the owning library pins when available so that callers may refresh symbol instances afterwards via SCH_SYMBOL::UpdatePins().

Returns
true if the swap touched a shared library pin.

Definition at line 251 of file sch_tool_utils.cpp.

References SCH_PIN::GetLength(), SCH_PIN::GetLibPin(), SCH_PIN::GetLocalPosition(), SCH_PIN::GetOperatingPoint(), SCH_PIN::GetOrientation(), SCH_PIN::SetLength(), SCH_PIN::SetOperatingPoint(), SCH_PIN::SetOrientation(), and SCH_PIN::SetPosition().

Referenced by BACK_ANNOTATE::applyPinSwaps(), and SCH_EDIT_TOOL::SwapPins().

◆ SymbolHasSheetInstances()

bool SymbolHasSheetInstances ( const SCH_SYMBOL & aSymbol,
const wxString & aCurrentProject,
std::set< wxString > * aSheetPaths = nullptr,
std::set< wxString > * aProjectNames = nullptr )

Returns true when the given symbol has instances, e.g.

is used by more than one sheet instance in this project or by more than one project.

Parameters
aSheetNamesif not nullptr, will be filled with the sheet paths that have instances of aSymbol.
aProjectNamesif not nullptr, will be filled with the names of other projects that have instances of aSymbol.
Returns
true if the symbol has shared instances.

Definition at line 287 of file sch_tool_utils.cpp.

References SCH_SYMBOL::GetInstances().

Referenced by BACK_ANNOTATE::applyPinSwaps(), and SCH_EDIT_TOOL::SwapPins().