|
KiCad PCB EDA Suite
|
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_LINE * | CreateWire (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={}, const std::map< std::string, NETNAME_LABEL > &aNetNameLabels={}) |
| Create net labels for named signals. | |
| SCH_GLOBALLABEL * | CreateNetLabel (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_LINE * | CreateBusWire (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_SHEET * | CreateHierarchicalSheet (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_PIN * | CreateSheetPin (SCH_SHEET *aSheet, const std::string &aSignalName, int aPinIndex) |
| Create hierarchical sheet pin on a sheet symbol. | |
| SCH_HIERLABEL * | CreateHierLabel (const std::string &aSignalName, const VECTOR2I &aPosition, SCH_SCREEN *aScreen) |
| Create hierarchical label in a sub-schematic. | |
Static Public Member Functions | |
| static SPIN_STYLE | SpinFromNetNameLabel (const NETNAME_LABEL &aLabel) |
| Map a PADS NETNAMES label entry to a KiCad global-label spin style. | |
| 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< VECTOR2I > | findJunctionPoints (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 PARAMETERS & | m_params |
| SCHEMATIC * | m_schematic |
| int | m_pageHeightIU |
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 53 of file pads_sch_schematic_builder.h.
| 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::PADS_SCH_SCHEMATIC_BUILDER::~PADS_SCH_SCHEMATIC_BUILDER | ( | ) |
Definition at line 58 of file pads_sch_schematic_builder.cpp.
| void PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::ApplyFieldSettings | ( | SCH_SYMBOL * | aSymbol, |
| const PART_PLACEMENT & | aPlacement ) |
Apply field visibility and position from PADS attribute settings.
| aSymbol | Target symbol instance. |
| aPlacement | Parsed part placement with attribute visibility settings. |
Definition at line 539 of file pads_sch_schematic_builder.cpp.
References PADS_SCH::PART_PLACEMENT::attributes, PADS_COMMON::DecodeJustification(), FOOTPRINT, ADVANCED_CFG::GetCfg(), SCH_SYMBOL::GetField(), GetFlippedAlignment(), SCH_SYMBOL::GetPosition(), GR_TEXT_H_ALIGN_LEFT, GR_TEXT_V_ALIGN_BOTTOM, PADS_ATTRIBUTE_MAPPER::IsFootprintField(), PADS_ATTRIBUTE_MAPPER::IsReferenceField(), PADS_ATTRIBUTE_MAPPER::IsValueField(), PADS_SCH::PART_PLACEMENT::mirror_flags, REFERENCE, schIUScale, EDA_TEXT::SetHorizJustify(), SCH_FIELD::SetPosition(), EDA_TEXT::SetTextAngleDegrees(), EDA_TEXT::SetTextSize(), EDA_TEXT::SetTextThickness(), EDA_TEXT::SetVertJustify(), EDA_TEXT::SetVisible(), toKiCadUnits(), and VALUE.
Referenced by 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.
| aSymbol | Target symbol instance to update. |
| aPlacement | Parsed part placement with attributes. |
Definition at line 489 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().
| 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.
| aSheetIndex | Zero-based sheet index. |
| aTotalSheets | Total number of sub-sheets. |
Definition at line 855 of file pads_sch_schematic_builder.cpp.
References schIUScale.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and CreateHierarchicalSheet().
|
private |
Choose best position for net label on a signal's wires.
Definition at line 306 of file pads_sch_schematic_builder.cpp.
References toKiCadUnits(), toKiCadY(), and PADS_SCH::SCH_SIGNAL::wires.
|
private |
Compute label orientation from the wire direction at the label position.
The label extends opposite to the wire direction.
Definition at line 270 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().
|
private |
Convert a PADS net name for use as a KiCad label.
Handles "/" prefix → "~{}" overbar conversion for inverted signals.
Definition at line 77 of file pads_sch_schematic_builder.cpp.
References PADS_COMMON::ConvertInvertedNetName().
Referenced by CreateNetLabel().
| SCH_LINE * PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::CreateBusWire | ( | const WIRE_SEGMENT & | aWire | ) |
Create a single bus wire segment.
| aWire | Wire segment data. |
Definition at line 429 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().
| 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.
| aSignals | Vector of parsed signal definitions. |
| aScreen | Target screen to add bus wires to. |
Definition at line 402 of file pads_sch_schematic_builder.cpp.
References SCH_SCREEN::Append(), CreateBusWire(), IS_NEW, IsBusSignal(), and EDA_ITEM::SetFlags().
| 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.
| aSymbol | Target symbol instance. |
| aPlacement | Parsed part placement with attributes. |
Definition at line 630 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().
| 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.
| aSheetNumber | Sheet number (1-based). |
| aTotalSheets | Total number of sheets in the design. |
| aParentSheet | Parent sheet to contain this sub-sheet. |
| aBaseFilename | Base filename for generating sheet filenames. |
Definition at line 793 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().
| 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.
| aSignalName | Name of the signal. |
| aPosition | Label position. |
| aScreen | Target screen to add label to. |
Definition at line 906 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().
| int PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::CreateJunctions | ( | const std::vector< SCH_SIGNAL > & | aSignals, |
| SCH_SCREEN * | aScreen ) |
Create junctions at wire intersection points.
| aSignals | Vector of parsed signal definitions. |
| aScreen | Target screen to add junctions to. |
Definition at line 119 of file pads_sch_schematic_builder.cpp.
References SCH_SCREEN::Append(), findJunctionPoints(), IS_NEW, and EDA_ITEM::SetFlags().
| 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.
| aSignal | Signal definition. |
| aPosition | Label position. |
| aOrientation | Label spin style (default RIGHT). |
Definition at line 289 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().
| 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 = {}, | ||
| const std::map< std::string, NETNAME_LABEL > & | aNetNameLabels = {} ) |
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.
| aSignals | Vector of parsed signal definitions. |
| aScreen | Target screen to add labels to. |
| aSignalOpcIds | Set of OPC reference strings (e.g. "@@@O48") for signal OPCs. |
| aSkipSignals | Signal names to skip (e.g. power nets handled elsewhere). |
Definition at line 168 of file pads_sch_schematic_builder.cpp.
References SCH_SCREEN::Append(), computeLabelOrientation(), CreateNetLabel(), IS_NEW, EDA_ITEM::SetFlags(), SpinFromNetNameLabel(), toKiCadUnits(), and toKiCadY().
Referenced by SCH_IO_PADS::LoadSchematicFile().
| 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.
| aSheet | Target sheet to add pin to. |
| aSignalName | Name of the signal crossing the hierarchy. |
| aPinIndex | Index for positioning the pin on the sheet edge. |
Definition at line 879 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().
| 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").
| aScreen | Target screen to set title block on. |
Definition at line 725 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().
| SCH_LINE * PADS_SCH::PADS_SCH_SCHEMATIC_BUILDER::CreateWire | ( | const WIRE_SEGMENT & | aWire | ) |
Create a single wire segment.
| aWire | Wire segment data. |
Definition at line 107 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().
| 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.
| aSignals | Vector of parsed signal definitions. |
| aScreen | Target screen to add wires to. |
Definition at line 83 of file pads_sch_schematic_builder.cpp.
References SCH_SCREEN::Append(), CreateWire(), IS_NEW, and EDA_ITEM::SetFlags().
|
private |
Find junction points where 3+ wire segments meet.
Definition at line 135 of file pads_sch_schematic_builder.cpp.
References end, toKiCadUnits(), toKiCadY(), VECTOR2< T >::x, and VECTOR2< T >::y.
Referenced by CreateJunctions().
| 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 848 of file pads_sch_schematic_builder.cpp.
References schIUScale.
Referenced by BOOST_AUTO_TEST_CASE(), and CreateHierarchicalSheet().
|
static |
Check if a signal name indicates a bus.
| aName | Signal name to check. |
Definition at line 441 of file pads_sch_schematic_builder.cpp.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and CreateBusWires().
|
static |
Check if a signal name represents a global signal.
Global signals include power nets (VCC, GND) and signals that appear on multiple sheets.
| aSignalName | Signal name to check. |
| aSheetNumbers | Set of sheet numbers where signal appears. |
Definition at line 926 of file pads_sch_schematic_builder.cpp.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().
|
static |
Map a PADS NETNAMES label entry to a KiCad global-label spin style.
PADS encodes the label side via the offset of the text from the anchor point. The dominant offset axis and its sign tell which way the text reads away from the connection, which is exactly what the spin style controls.
Definition at line 253 of file pads_sch_schematic_builder.cpp.
References std::abs(), SPIN_STYLE::BOTTOM, SPIN_STYLE::LEFT, SPIN_STYLE::RIGHT, SPIN_STYLE::UP, PADS_SCH::NETNAME_LABEL::x_offset, and PADS_SCH::NETNAME_LABEL::y_offset.
Referenced by CreateNetLabels().
|
private |
Convert PADS coordinate to KiCad internal units.
Definition at line 63 of file pads_sch_schematic_builder.cpp.
References schIUScale.
Referenced by ApplyFieldSettings(), chooseLabelPosition(), CreateBusWire(), CreateCustomFields(), CreateNetLabels(), CreateWire(), findJunctionPoints(), and toKiCadY().
|
private |
Convert PADS Y coordinate to KiCad Y, accounting for Y-axis inversion and page offset.
Definition at line 71 of file pads_sch_schematic_builder.cpp.
References m_pageHeightIU, and toKiCadUnits().
Referenced by chooseLabelPosition(), CreateBusWire(), CreateNetLabels(), CreateWire(), and findJunctionPoints().
|
private |
Definition at line 305 of file pads_sch_schematic_builder.h.
Referenced by PADS_SCH_SCHEMATIC_BUILDER(), and toKiCadY().
|
private |
Definition at line 303 of file pads_sch_schematic_builder.h.
Referenced by CreateTitleBlock(), and PADS_SCH_SCHEMATIC_BUILDER().
|
private |
Definition at line 304 of file pads_sch_schematic_builder.h.
Referenced by ApplyPartAttributes(), CreateHierarchicalSheet(), and PADS_SCH_SCHEMATIC_BUILDER().