97 aScreen->
Append( schLine );
124 for(
const VECTOR2I& pt : junctionPoints )
128 aScreen->
Append( junction );
131 return static_cast<int>( junctionPoints.size() );
137 std::vector<VECTOR2I> junctions;
142 std::map<std::pair<int, int>,
int> pointCount;
149 pointCount[{ start.
x, start.
y }]++;
150 pointCount[{
end.x,
end.y }]++;
154 for(
const auto& [coords, count] : pointCount )
157 junctions.emplace_back( coords.first, coords.second );
166 const std::set<std::string>& aSignalOpcIds,
167 const std::set<std::string>& aSkipSignals,
168 const std::map<std::string, NETNAME_LABEL>& aNetNameLabels )
174 if( signal.name.empty() || signal.name[0] ==
'$' )
177 if( aSkipSignals.count( signal.name ) )
180 if( signal.wires.empty() )
190 std::string anchorRef;
193 std::vector<PLACEMENT> opcPlacements;
208 opcPlacements.push_back( { labelPos, adjPos, wire.
endpoint_a } );
214 size_t last = wire.
vertices.size() - 1;
219 opcPlacements.push_back( { labelPos, adjPos, wire.
endpoint_b } );
223 for(
const PLACEMENT& placement : opcPlacements )
228 auto nnIt = aNetNameLabels.find( placement.anchorRef );
271 int dx = aAdjacentPos.
x - aLabelPos.
x;
272 int dy = aAdjacentPos.
y - aLabelPos.
y;
304 if( aSignal.
wires.empty() )
310 std::map<std::pair<int, int>,
int> endpointCount;
320 endpointCount[{
static_cast<int>( first.
x * 1000 ),
static_cast<int>( first.
y * 1000 ) }]++;
321 endpointCount[{
static_cast<int>( last.
x * 1000 ),
static_cast<int>( last.
y * 1000 ) }]++;
325 std::set<std::pair<int, int>> pinEndpoints;
338 pinEndpoints.insert( {
static_cast<int>( pt.
x * 1000 ),
static_cast<int>( pt.
y * 1000 ) } );
344 pinEndpoints.insert( {
static_cast<int>( pt.
x * 1000 ),
static_cast<int>( pt.
y * 1000 ) } );
356 auto key = std::make_pair(
static_cast<int>( vtx->x * 1000 ),
static_cast<int>( vtx->y * 1000 ) );
358 if( endpointCount[key] == 1 && pinEndpoints.count( key ) == 0 )
371 auto key = std::make_pair(
static_cast<int>( vtx->x * 1000 ),
static_cast<int>( vtx->y * 1000 ) );
373 if( endpointCount[key] == 1 )
409 aScreen->
Append( busLine );
438 size_t bracketPos = aName.find(
'[' );
440 if( bracketPos != std::string::npos )
442 size_t closeBracket = aName.find(
']', bracketPos );
444 if( closeBracket != std::string::npos )
446 std::string range = aName.substr( bracketPos + 1, closeBracket - bracketPos - 1 );
448 if( range.find(
':' ) != std::string::npos || range.find(
".." ) != std::string::npos )
454 size_t anglePos = aName.find(
'<' );
456 if( anglePos != std::string::npos )
458 size_t closeAngle = aName.find(
'>', anglePos );
460 if( closeAngle != std::string::npos )
462 std::string range = aName.substr( anglePos + 1, closeAngle - anglePos - 1 );
464 if( range.find(
':' ) != std::string::npos || range.find(
".." ) != std::string::npos )
483 size_t sepPos = ref.rfind(
'-' );
485 if( sepPos == std::string::npos )
486 sepPos = ref.rfind(
'.' );
488 if( sepPos != std::string::npos
489 && sepPos + 1 < ref.size()
490 && std::isalpha(
static_cast<unsigned char>( ref[sepPos + 1] ) ) )
492 ref = ref.substr( 0, sepPos );
506 if( attr.
name ==
"PCB DECAL" || attr.
name ==
"PCB_DECAL" || attr.
name ==
"FOOTPRINT" )
508 if( !attr.
value.empty() )
531 bool isRefOrValue =
false;
581 int fieldTextSize =
schIUScale.MilsToIU( 50 );
613 int fieldsCreated = 0;
616 std::set<std::string> processedNames;
625 if( attr.
value.empty() )
628 processedNames.insert( attr.
name );
639 existingField->
SetText( wxString::FromUTF8( attr.
value ) );
661 if( attr.
size > 0.0 )
667 aSymbol->
GetFields().push_back( newField );
683 existingField->
SetText( wxString::FromUTF8( value ) );
689 newField.
SetText( wxString::FromUTF8( value ) );
693 aSymbol->
GetFields().push_back( newField );
698 return fieldsCreated;
709 [
this](
const std::initializer_list<const char*>& aCandidates ) -> std::string
711 for(
const char*
name : aCandidates )
715 if( it !=
m_params.fields.end() && !it->second.empty() )
724 std::string title =
findField( {
"Title",
"TITLE1" } );
730 tb.
SetTitle( wxString::FromUTF8( title ) );
732 std::string date =
findField( {
"DATE",
"Release Date",
"Drawn Date" } );
735 tb.
SetDate( wxString::FromUTF8( date ) );
737 std::string revision =
findField( {
"Revision",
"VER" } );
739 if( !revision.empty() )
742 std::string company =
findField( {
"Company Name" } );
744 if( !company.empty() )
745 tb.
SetCompany( wxString::FromUTF8( company ) );
747 std::string drawingNumber =
findField( {
"DN",
"Drawing Number" } );
749 if( !drawingNumber.empty() )
750 tb.
SetComment( 0, wxString::FromUTF8( drawingNumber ) );
752 std::string designer =
findField( {
"DESIGNER" } );
754 if( !designer.empty() )
755 tb.
SetComment( 1, wxString::FromUTF8( designer ) );
757 std::string drawnBy =
findField( {
"DRAWNBY",
"Drawn By" } );
759 if( !drawnBy.empty() )
760 tb.
SetComment( 2, wxString::FromUTF8( drawnBy ) );
762 std::string builtFor =
findField( {
"BUILTFOR" } );
764 if( !builtFor.empty() )
765 tb.
SetComment( 3, wxString::FromUTF8( builtFor ) );
773 const wxString& aBaseFilename )
788 wxFileName fn( aBaseFilename );
789 wxString sheetFilename = wxString::Format( wxT(
"%s_sheet%d.%s" ),
798 wxString sheetName = wxString::Format( wxT(
"Sheet %d" ), aSheetNumber );
804 wxFileName screenFn(
m_schematic->Project().GetProjectPath(), sheetFilename );
819 parentScreen->
Append( sheet );
837 const int startX =
schIUScale.MilsToIU( 500 );
838 const int startY =
schIUScale.MilsToIU( 500 );
841 const int spacingX =
schIUScale.MilsToIU( 2500 );
842 const int spacingY =
schIUScale.MilsToIU( 2000 );
845 int columns =
static_cast<int>( std::ceil( std::sqrt(
static_cast<double>( aTotalSheets ) ) ) );
850 int row = aSheetIndex / columns;
851 int col = aSheetIndex % columns;
853 return VECTOR2I( startX + col * spacingX, startY + row * spacingY );
858 const std::string& aSignalName,
864 wxString
name = wxString::FromUTF8( aSignalName );
870 int yOffset =
schIUScale.MilsToIU( 100 ) + aPinIndex * pinSpacing;
872 VECTOR2I pinPos( sheetPos.
x, sheetPos.
y + yOffset );
891 wxString
name = wxString::FromUTF8( aSignalName );
905 const std::set<int>& aSheetNumbers )
907 if( aSignalName.empty() )
911 if( aSheetNumbers.size() > 1 )
915 std::string upperName = aSignalName;
916 std::transform( upperName.begin(), upperName.end(), upperName.begin(), ::toupper );
918 static const std::set<std::string> globalPatterns = {
919 "VCC",
"VDD",
"VEE",
"VSS",
"GND",
"AGND",
"DGND",
"PGND",
920 "V+",
"V-",
"VBAT",
"VBUS",
"VIN",
"VOUT",
921 "+5V",
"+3V3",
"+3.3V",
"+12V",
"-12V",
"+24V",
922 "0V",
"EARTH",
"CHASSIS"
925 if( globalPatterns.count( upperName ) > 0 )
929 if( ( upperName[0] ==
'+' || upperName[0] ==
'-' ) && upperName.length() >= 3 )
931 bool hasDigit =
false;
934 for(
char c : upperName.substr( 1 ) )
936 if( std::isdigit( c ) )
943 if( hasDigit && hasV )
constexpr EDA_IU_SCALE schIUScale
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void SetFlags(EDA_ITEM_FLAGS aMask)
virtual void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
virtual void SetVisible(bool aVisible)
virtual void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
void SetTextAngleDegrees(double aOrientation)
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Maps PADS attribute names to KiCad field names and identifies which attributes are standard KiCad fie...
bool IsReferenceField(const std::string &aPadsAttr) const
std::string GetKiCadFieldName(const std::string &aPadsAttr) const
Get the KiCad field name for a PADS attribute, or the original name unchanged when no mapping exists.
bool IsFootprintField(const std::string &aPadsAttr) const
bool IsStandardField(const std::string &aPadsAttr) const
Check if a PADS attribute maps to a standard KiCad field (Reference, Value, or Footprint).
bool IsValueField(const std::string &aPadsAttr) const
SCH_LINE * CreateWire(const WIRE_SEGMENT &aWire)
std::vector< VECTOR2I > findJunctionPoints(const std::vector< SCH_SIGNAL > &aSignals)
Find points where 3+ wire segments meet.
static SPIN_STYLE SpinFromNetNameLabel(const NETNAME_LABEL &aLabel)
Map a PADS NETNAMES label entry to a KiCad global-label spin style.
int toKiCadY(double aPadsY) const
Convert PADS Y coordinate to KiCad Y, accounting for Y-axis inversion and page offset.
SCH_SHEET_PIN * CreateSheetPin(SCH_SHEET *aSheet, const std::string &aSignalName, int aPinIndex)
Create a sheet pin that connects to a hierarchical label in the sub-schematic.
int CreateJunctions(const std::vector< SCH_SIGNAL > &aSignals, SCH_SCREEN *aScreen)
void ApplyPartAttributes(SCH_SYMBOL *aSymbol, const PART_PLACEMENT &aPlacement)
Set reference, value, footprint and other fields on a symbol from a part placement.
PADS_SCH_SCHEMATIC_BUILDER(const PARAMETERS &aParams, SCHEMATIC *aSchematic)
void CreateTitleBlock(SCH_SCREEN *aScreen)
Set the title block from PADS fields, checking custom names too because PADS designs often leave the ...
const PARAMETERS & m_params
VECTOR2I CalculateSheetPosition(int aSheetIndex, int aTotalSheets) const
Position a sheet symbol in a roughly square grid on the parent.
static SPIN_STYLE computeLabelOrientation(const VECTOR2I &aLabelPos, const VECTOR2I &aAdjacentPos)
Orient a label opposite to the wire direction at its position so it clears the wire.
int toKiCadUnits(double aPadsValue) const
int CreateCustomFields(SCH_SYMBOL *aSymbol, const PART_PLACEMENT &aPlacement)
Create KiCad user fields for PADS attributes that have no standard-field mapping.
VECTOR2I chooseLabelPosition(const SCH_SIGNAL &aSignal)
SCH_LINE * CreateBusWire(const WIRE_SEGMENT &aWire)
SCH_HIERLABEL * CreateHierLabel(const std::string &aSignalName, const VECTOR2I &aPosition, SCH_SCREEN *aScreen)
Create a hierarchical label that connects to a sheet pin on the parent.
void ApplyFieldSettings(SCH_SYMBOL *aSymbol, const PART_PLACEMENT &aPlacement)
int CreateWires(const std::vector< SCH_SIGNAL > &aSignals, SCH_SCREEN *aScreen)
SCH_GLOBALLABEL * CreateNetLabel(const SCH_SIGNAL &aSignal, const VECTOR2I &aPosition, SPIN_STYLE aOrientation=SPIN_STYLE::RIGHT)
Create a net label.
static bool IsGlobalSignal(const std::string &aSignalName, const std::set< int > &aSheetNumbers)
A signal is global when it spans multiple sheets or is a common power net.
int CreateBusWires(const std::vector< SCH_SIGNAL > &aSignals, SCH_SCREEN *aScreen)
wxString convertNetName(const std::string &aName) const
Convert a PADS net name to a KiCad label, mapping a "/" prefix to a "~{}" overbar.
SCH_SHEET * CreateHierarchicalSheet(int aSheetNumber, int aTotalSheets, SCH_SHEET *aParentSheet, const wxString &aBaseFilename)
Create a sub-sheet positioned on its parent and backed by its own screen.
VECTOR2I GetDefaultSheetSize() const
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.
~PADS_SCH_SCHEMATIC_BUILDER()
static bool IsBusSignal(const std::string &aName)
Holds all the data relating to one schematic.
void SetPosition(const VECTOR2I &aPosition) override
void SetText(const wxString &aText) override
void SetSpinStyle(SPIN_STYLE aSpinStyle) override
void SetShape(LABEL_FLAG_SHAPE aShape)
Segment description base class to describe items which have 2 end points (track, wire,...
void SetEndPoint(const VECTOR2I &aPosition)
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
void AddPin(SCH_SHEET_PIN *aSheetPin)
Add aSheetPin to the sheet.
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this sheet.
SCH_SCREEN * GetScreen() const
VECTOR2I GetPosition() const override
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
void SetFootprintFieldText(const wxString &aFootprint)
VECTOR2I GetPosition() const override
void SetValueFieldText(const wxString &aValue, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString)
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
Hold the information shown in the lower right corner of a plot, printout, or editing view.
void SetRevision(const wxString &aRevision)
void SetComment(int aIdx, const wxString &aComment)
void SetTitle(const wxString &aTitle)
void SetCompany(const wxString &aCompany)
void SetDate(const wxString &aDate)
Set the date field, and defaults to the current time and date.
#define IS_NEW
New item, just created.
static const std::string KiCadSchematicFileExtension
void DecodeJustification(int aJustification, GR_TEXT_H_ALIGN_T &aHJustify, GR_TEXT_V_ALIGN_T &aVJustify)
Decode a PADS text justification code into KiCad horizontal and vertical alignment.
wxString ConvertInvertedNetName(const std::string &aNetName)
Convert a PADS net name to KiCad notation.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
std::map< std::string, std::string > attr_overrides
std::vector< PART_ATTRIBUTE > attributes
std::vector< WIRE_SEGMENT > wires
Wire segment connecting two endpoints through coordinate vertices.
std::vector< POINT > vertices
@ USER
The field ID hasn't been set yet; field is invalid.
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
static const HTTP_LIB_PART::field_type * findField(const HTTP_LIB_PART &aPart, const std::string &aName)
Issue #23023.
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
GR_TEXT_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.
constexpr GR_TEXT_H_ALIGN_T GetFlippedAlignment(GR_TEXT_H_ALIGN_T aAlign)
Get the reverse alignment: left-right are swapped, others are unchanged.
VECTOR2< int32_t > VECTOR2I
Definition of file extensions used in Kicad.