KiCad PCB EDA Suite
Loading...
Searching...
No Matches
PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER Class Reference

Builder class to create KiCad schematic elements from parsed PADS data. More...

#include <pads_sch_schematic_builder.h>

Public Member Functions

 PADS_SCH_SCHEMATIC_BUILDER (const PARAMETERS &aParams, SCHEMATIC *aSchematic)
 
 ~PADS_SCH_SCHEMATIC_BUILDER ()
 
int CreateWires (const std::vector< SCH_SIGNAL > &aSignals, SCH_SCREEN *aScreen)
 Create wire segments from signal definitions and add to screen.
 
SCH_LINECreateWire (const WIRE_SEGMENT &aWire)
 Create a single wire segment.
 
int CreateJunctions (const std::vector< SCH_SIGNAL > &aSignals, SCH_SCREEN *aScreen)
 Create junctions at wire intersection points.
 
int CreateNetLabels (const std::vector< SCH_SIGNAL > &aSignals, SCH_SCREEN *aScreen, const std::set< std::string > &aSignalOpcIds, const std::set< std::string > &aSkipSignals={})
 Create net labels for named signals.
 
SCH_GLOBALLABELCreateNetLabel (const SCH_SIGNAL &aSignal, const VECTOR2I &aPosition, SPIN_STYLE aOrientation=SPIN_STYLE::RIGHT)
 Create a global net label for a signal.
 
int CreateBusWires (const std::vector< SCH_SIGNAL > &aSignals, SCH_SCREEN *aScreen)
 Create bus wires and entries for bus signals.
 
SCH_LINECreateBusWire (const WIRE_SEGMENT &aWire)
 Create a single bus wire segment.
 
void ApplyPartAttributes (SCH_SYMBOL *aSymbol, const PART_PLACEMENT &aPlacement)
 Apply part attributes to a symbol instance.
 
void ApplyFieldSettings (SCH_SYMBOL *aSymbol, const PART_PLACEMENT &aPlacement)
 Apply field visibility and position from PADS attribute settings.
 
int CreateCustomFields (SCH_SYMBOL *aSymbol, const PART_PLACEMENT &aPlacement)
 Create custom fields from non-standard PADS attributes.
 
void CreateTitleBlock (SCH_SCREEN *aScreen)
 Create title block from parsed PADS parameters.
 
SCH_SHEETCreateHierarchicalSheet (int aSheetNumber, int aTotalSheets, SCH_SHEET *aParentSheet, const wxString &aBaseFilename)
 Create hierarchical sheet for a sub-schematic page.
 
VECTOR2I GetDefaultSheetSize () const
 Get standard sheet size for a given sheet number.
 
VECTOR2I CalculateSheetPosition (int aSheetIndex, int aTotalSheets) const
 Calculate position for a sheet symbol on the parent sheet.
 
SCH_SHEET_PINCreateSheetPin (SCH_SHEET *aSheet, const std::string &aSignalName, int aPinIndex)
 Create hierarchical sheet pin on a sheet symbol.
 
SCH_HIERLABELCreateHierLabel (const std::string &aSignalName, const VECTOR2I &aPosition, SCH_SCREEN *aScreen)
 Create hierarchical label in a sub-schematic.
 

Static Public Member Functions

static bool IsBusSignal (const std::string &aName)
 Check if a signal name indicates a bus.
 
static bool IsGlobalSignal (const std::string &aSignalName, const std::set< int > &aSheetNumbers)
 Check if a signal name represents a global signal.
 

Private Member Functions

int toKiCadUnits (double aPadsValue) const
 Convert PADS coordinate to KiCad internal units.
 
int toKiCadY (double aPadsY) const
 Convert PADS Y coordinate to KiCad Y, accounting for Y-axis inversion and page offset.
 
std::vector< VECTOR2IfindJunctionPoints (const std::vector< SCH_SIGNAL > &aSignals)
 Find junction points where 3+ wire segments meet.
 
VECTOR2I chooseLabelPosition (const SCH_SIGNAL &aSignal)
 Choose best position for net label on a signal's wires.
 
SPIN_STYLE computeLabelOrientation (const VECTOR2I &aLabelPos, const VECTOR2I &aAdjacentPos)
 Compute label orientation from the wire direction at the label position.
 
wxString convertNetName (const std::string &aName) const
 Convert a PADS net name for use as a KiCad label.
 

Private Attributes

const PARAMETERSm_params
 
SCHEMATICm_schematic
 
int m_pageHeightIU
 

Detailed Description

Builder class to create KiCad schematic elements from parsed PADS data.

This class handles the conversion of parsed PADS signals and connectivity into KiCad schematic wire segments, junctions, and labels.

Definition at line 52 of file pads_sch_schematic_builder.h.

Constructor & Destructor Documentation

◆ PADS_SCH_SCHEMATIC_BUILDER()

PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::PADS_SCH_SCHEMATIC_BUILDER ( const PARAMETERS & aParams,
SCHEMATIC * aSchematic )

Definition at line 49 of file pads_sch_schematic_builder.cpp.

References m_pageHeightIU, m_params, m_schematic, and schIUScale.

◆ ~PADS_SCH_SCHEMATIC_BUILDER()

PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::~PADS_SCH_SCHEMATIC_BUILDER ( )

Definition at line 58 of file pads_sch_schematic_builder.cpp.

Member Function Documentation

◆ ApplyFieldSettings()

◆ ApplyPartAttributes()

void PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::ApplyPartAttributes ( SCH_SYMBOL * aSymbol,
const PART_PLACEMENT & aPlacement )

Apply part attributes to a symbol instance.

Sets the reference designator, value, footprint, and other fields from the parsed PADS part placement attributes.

Parameters
aSymbolTarget symbol instance to update.
aPlacementParsed part placement with attributes.

Definition at line 469 of file pads_sch_schematic_builder.cpp.

References ApplyFieldSettings(), PADS_SCH::PART_PLACEMENT::attributes, m_schematic, PADS_SCH::PART_PLACEMENT::part_type, PADS_SCH::PART_PLACEMENT::reference, SCH_SYMBOL::SetFootprintFieldText(), SCH_SYMBOL::SetRef(), and SCH_SYMBOL::SetValueFieldText().

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and SCH_IO_PADS::LoadSchematicFile().

◆ CalculateSheetPosition()

VECTOR2I PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::CalculateSheetPosition ( int aSheetIndex,
int aTotalSheets ) const

Calculate position for a sheet symbol on the parent sheet.

Arranges sheets in a grid layout.

Parameters
aSheetIndexZero-based sheet index.
aTotalSheetsTotal number of sub-sheets.
Returns
Position for the sheet symbol.

Definition at line 823 of file pads_sch_schematic_builder.cpp.

References schIUScale.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and CreateHierarchicalSheet().

◆ chooseLabelPosition()

VECTOR2I PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::chooseLabelPosition ( const SCH_SIGNAL & aSignal)
private

Choose best position for net label on a signal's wires.

Definition at line 286 of file pads_sch_schematic_builder.cpp.

References toKiCadUnits(), toKiCadY(), and PADS_SCH::SCH_SIGNAL::wires.

◆ computeLabelOrientation()

SPIN_STYLE PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::computeLabelOrientation ( const VECTOR2I & aLabelPos,
const VECTOR2I & aAdjacentPos )
private

Compute label orientation from the wire direction at the label position.

The label extends opposite to the wire direction.

Definition at line 250 of file pads_sch_schematic_builder.cpp.

References std::abs(), SPIN_STYLE::BOTTOM, SPIN_STYLE::LEFT, SPIN_STYLE::RIGHT, SPIN_STYLE::UP, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by CreateNetLabels().

◆ convertNetName()

wxString PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::convertNetName ( const std::string & aName) const
private

Convert a PADS net name for use as a KiCad label.

Handles "/" prefix → "~{}" overbar conversion for inverted signals.

Definition at line 92 of file pads_sch_schematic_builder.cpp.

References PADS_COMMON::ConvertInvertedNetName().

Referenced by CreateNetLabel().

◆ CreateBusWire()

SCH_LINE * PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::CreateBusWire ( const WIRE_SEGMENT & aWire)

Create a single bus wire segment.

Parameters
aWireWire segment data.
Returns
New SCH_LINE object with bus layer. Caller takes ownership.

Definition at line 409 of file pads_sch_schematic_builder.cpp.

References end, PADS_SCH::WIRE_SEGMENT::end, LAYER_BUS, SCH_LINE::SetEndPoint(), PADS_SCH::WIRE_SEGMENT::start, toKiCadUnits(), toKiCadY(), PADS_SCH::POINT::x, and PADS_SCH::POINT::y.

Referenced by BOOST_AUTO_TEST_CASE(), and CreateBusWires().

◆ CreateBusWires()

int PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::CreateBusWires ( const std::vector< SCH_SIGNAL > & aSignals,
SCH_SCREEN * aScreen )

Create bus wires and entries for bus signals.

Parameters
aSignalsVector of parsed signal definitions.
aScreenTarget screen to add bus wires to.
Returns
Number of bus wires created.

Definition at line 382 of file pads_sch_schematic_builder.cpp.

References SCH_SCREEN::Append(), CreateBusWire(), IS_NEW, IsBusSignal(), and EDA_ITEM::SetFlags().

◆ CreateCustomFields()

int PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::CreateCustomFields ( SCH_SYMBOL * aSymbol,
const PART_PLACEMENT & aPlacement )

Create custom fields from non-standard PADS attributes.

Creates KiCad custom fields for PADS attributes that don't map to standard fields (Reference, Value, Footprint, Datasheet, Description). Uses PADS_ATTRIBUTE_MAPPER for name normalization.

Parameters
aSymbolTarget symbol instance.
aPlacementParsed part placement with attributes.
Returns
Number of custom fields created.

Definition at line 598 of file pads_sch_schematic_builder.cpp.

References PADS_SCH::PART_PLACEMENT::attr_overrides, PADS_SCH::PART_PLACEMENT::attributes, SCH_SYMBOL::GetField(), SCH_SYMBOL::GetFields(), PADS_ATTRIBUTE_MAPPER::GetKiCadFieldName(), SCH_SYMBOL::GetPosition(), PADS_ATTRIBUTE_MAPPER::IsStandardField(), name, SCH_FIELD::SetPosition(), SCH_FIELD::SetText(), EDA_TEXT::SetTextAngleDegrees(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetVisible(), toKiCadUnits(), and USER.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and SCH_IO_PADS::LoadSchematicFile().

◆ CreateHierarchicalSheet()

SCH_SHEET * PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::CreateHierarchicalSheet ( int aSheetNumber,
int aTotalSheets,
SCH_SHEET * aParentSheet,
const wxString & aBaseFilename )

Create hierarchical sheet for a sub-schematic page.

Creates a SCH_SHEET object representing a sub-sheet in the hierarchy. The sheet is positioned on the parent sheet and linked with a screen for the sub-schematic content.

Parameters
aSheetNumberSheet number (1-based).
aTotalSheetsTotal number of sheets in the design.
aParentSheetParent sheet to contain this sub-sheet.
aBaseFilenameBase filename for generating sheet filenames.
Returns
New SCH_SHEET object. Caller takes ownership.

Definition at line 761 of file pads_sch_schematic_builder.cpp.

References SCH_SCREEN::Append(), CalculateSheetPosition(), GetDefaultSheetSize(), SCH_SHEET::GetField(), SCH_SHEET::GetScreen(), IS_NEW, FILEEXT::KiCadSchematicFileExtension, m_schematic, SCH_SCREEN::SetFileName(), EDA_ITEM::SetFlags(), SCH_SHEET::SetScreen(), SCH_FIELD::SetText(), SHEET_FILENAME, and SHEET_NAME.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and SCH_IO_PADS::LoadSchematicFile().

◆ CreateHierLabel()

SCH_HIERLABEL * PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::CreateHierLabel ( const std::string & aSignalName,
const VECTOR2I & aPosition,
SCH_SCREEN * aScreen )

Create hierarchical label in a sub-schematic.

Hierarchical labels connect to sheet pins on the parent sheet.

Parameters
aSignalNameName of the signal.
aPositionLabel position.
aScreenTarget screen to add label to.
Returns
New SCH_HIERLABEL object. Caller takes ownership.

Definition at line 874 of file pads_sch_schematic_builder.cpp.

References SCH_SCREEN::Append(), IS_NEW, L_UNSPECIFIED, name, EDA_ITEM::SetFlags(), and SCH_LABEL_BASE::SetShape().

Referenced by BOOST_AUTO_TEST_CASE().

◆ CreateJunctions()

int PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::CreateJunctions ( const std::vector< SCH_SIGNAL > & aSignals,
SCH_SCREEN * aScreen )

Create junctions at wire intersection points.

Parameters
aSignalsVector of parsed signal definitions.
aScreenTarget screen to add junctions to.
Returns
Number of junctions created.

Definition at line 134 of file pads_sch_schematic_builder.cpp.

References SCH_SCREEN::Append(), findJunctionPoints(), IS_NEW, and EDA_ITEM::SetFlags().

◆ CreateNetLabel()

SCH_GLOBALLABEL * PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::CreateNetLabel ( const SCH_SIGNAL & aSignal,
const VECTOR2I & aPosition,
SPIN_STYLE aOrientation = SPIN_STYLE::RIGHT )

Create a global net label for a signal.

PADS signals are global by nature, so all net labels are created as SCH_GLOBALLABEL to avoid sheet-path prefix issues with local labels.

Parameters
aSignalSignal definition.
aPositionLabel position.
aOrientationLabel spin style (default RIGHT).
Returns
New SCH_GLOBALLABEL object. Caller takes ownership.

Definition at line 269 of file pads_sch_schematic_builder.cpp.

References convertNetName(), L_BIDI, PADS_SCH::SCH_SIGNAL::name, schIUScale, SCH_LABEL_BASE::SetShape(), SCH_GLOBALLABEL::SetSpinStyle(), and EDA_TEXT::SetTextSize().

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and CreateNetLabels().

◆ CreateNetLabels()

int PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::CreateNetLabels ( const std::vector< SCH_SIGNAL > & aSignals,
SCH_SCREEN * aScreen,
const std::set< std::string > & aSignalOpcIds,
const std::set< std::string > & aSkipSignals = {} )

Create net labels for named signals.

For signals with OPC endpoints, one label is created per OPC connection point with orientation derived from the adjacent wire direction. Signals without OPC endpoints fall back to a single label at a dangling wire end.

Parameters
aSignalsVector of parsed signal definitions.
aScreenTarget screen to add labels to.
aSignalOpcIdsSet of OPC reference strings (e.g. "@@@O48") for signal OPCs.
aSkipSignalsSignal names to skip (e.g. power nets handled elsewhere).
Returns
Number of labels created.

Definition at line 183 of file pads_sch_schematic_builder.cpp.

References SCH_SCREEN::Append(), computeLabelOrientation(), CreateNetLabel(), IS_NEW, EDA_ITEM::SetFlags(), toKiCadUnits(), and toKiCadY().

Referenced by SCH_IO_PADS::LoadSchematicFile().

◆ CreateSheetPin()

SCH_SHEET_PIN * PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::CreateSheetPin ( SCH_SHEET * aSheet,
const std::string & aSignalName,
int aPinIndex )

Create hierarchical sheet pin on a sheet symbol.

Sheet pins connect to hierarchical labels inside the sub-schematic.

Parameters
aSheetTarget sheet to add pin to.
aSignalNameName of the signal crossing the hierarchy.
aPinIndexIndex for positioning the pin on the sheet edge.
Returns
New SCH_SHEET_PIN object. Ownership transferred to sheet.

Definition at line 847 of file pads_sch_schematic_builder.cpp.

References SCH_SHEET::AddPin(), SCH_SHEET::GetPosition(), L_UNSPECIFIED, LEFT, name, pin, schIUScale, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ CreateTitleBlock()

void PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::CreateTitleBlock ( SCH_SCREEN * aScreen)

Create title block from parsed PADS parameters.

Maps PADS FIELDS section entries to KiCad TITLE_BLOCK, checking both standard and custom field names since PADS designs often leave standard names empty and use custom variants instead (e.g. "TITLE1" instead of "Title").

Parameters
aScreenTarget screen to set title block on.

Definition at line 693 of file pads_sch_schematic_builder.cpp.

References m_params, name, TITLE_BLOCK::SetComment(), TITLE_BLOCK::SetCompany(), TITLE_BLOCK::SetDate(), TITLE_BLOCK::SetRevision(), TITLE_BLOCK::SetTitle(), and SCH_SCREEN::SetTitleBlock().

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and SCH_IO_PADS::LoadSchematicFile().

◆ CreateWire()

SCH_LINE * PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::CreateWire ( const WIRE_SEGMENT & aWire)

Create a single wire segment.

Parameters
aWireWire segment data.
Returns
New SCH_LINE object. Caller takes ownership.

Definition at line 122 of file pads_sch_schematic_builder.cpp.

References end, PADS_SCH::WIRE_SEGMENT::end, LAYER_WIRE, SCH_LINE::SetEndPoint(), PADS_SCH::WIRE_SEGMENT::start, toKiCadUnits(), toKiCadY(), PADS_SCH::POINT::x, and PADS_SCH::POINT::y.

Referenced by BOOST_AUTO_TEST_CASE(), and CreateWires().

◆ CreateWires()

int PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::CreateWires ( const std::vector< SCH_SIGNAL > & aSignals,
SCH_SCREEN * aScreen )

Create wire segments from signal definitions and add to screen.

Parameters
aSignalsVector of parsed signal definitions.
aScreenTarget screen to add wires to.
Returns
Number of wires created.

Definition at line 98 of file pads_sch_schematic_builder.cpp.

References SCH_SCREEN::Append(), CreateWire(), IS_NEW, and EDA_ITEM::SetFlags().

◆ findJunctionPoints()

std::vector< VECTOR2I > PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::findJunctionPoints ( const std::vector< SCH_SIGNAL > & aSignals)
private

Find junction points where 3+ wire segments meet.

Definition at line 150 of file pads_sch_schematic_builder.cpp.

References end, toKiCadUnits(), toKiCadY(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by CreateJunctions().

◆ GetDefaultSheetSize()

VECTOR2I PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::GetDefaultSheetSize ( ) const

Get standard sheet size for a given sheet number.

Returns a default sheet symbol size suitable for display on the parent.

Definition at line 816 of file pads_sch_schematic_builder.cpp.

References schIUScale.

Referenced by BOOST_AUTO_TEST_CASE(), and CreateHierarchicalSheet().

◆ IsBusSignal()

bool PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::IsBusSignal ( const std::string & aName)
static

Check if a signal name indicates a bus.

Parameters
aNameSignal name to check.
Returns
True if the name matches bus naming patterns.

Definition at line 421 of file pads_sch_schematic_builder.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and CreateBusWires().

◆ IsGlobalSignal()

bool PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::IsGlobalSignal ( const std::string & aSignalName,
const std::set< int > & aSheetNumbers )
static

Check if a signal name represents a global signal.

Global signals include power nets (VCC, GND) and signals that appear on multiple sheets.

Parameters
aSignalNameSignal name to check.
aSheetNumbersSet of sheet numbers where signal appears.
Returns
True if this should be a global label.

Definition at line 894 of file pads_sch_schematic_builder.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ toKiCadUnits()

int PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::toKiCadUnits ( double aPadsValue) const
private

◆ toKiCadY()

int PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::toKiCadY ( double aPadsY) const
private

Convert PADS Y coordinate to KiCad Y, accounting for Y-axis inversion and page offset.

Definition at line 86 of file pads_sch_schematic_builder.cpp.

References m_pageHeightIU, and toKiCadUnits().

Referenced by chooseLabelPosition(), CreateBusWire(), CreateNetLabels(), CreateWire(), and findJunctionPoints().

Member Data Documentation

◆ m_pageHeightIU

int PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::m_pageHeightIU
private

Definition at line 293 of file pads_sch_schematic_builder.h.

Referenced by PADS_SCH_SCHEMATIC_BUILDER(), and toKiCadY().

◆ m_params

const PARAMETERS& PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::m_params
private

◆ m_schematic

SCHEMATIC* PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::m_schematic
private

The documentation for this class was generated from the following files: