42 std::vector<LTSPICE_SCHEMATIC::LT_ASC>& outLT_ASCs,
43 const std::vector<wxString>& aAsyFileNames )
49 bbox.
Merge( asc.BoundingBox );
57 int margin =
grid * 10;
61 if( bbox.
GetWidth() > pageSize.
x - margin )
84 for( wxString& line : wxSplit( lt_text.
Value,
'\n' ) )
86 if( line.StartsWith( wxS(
".inc " ), &
path ) )
88 path.Replace(
'\\',
'/' );
89 wxFileName fileName(
path );
91 if( fileName.IsAbsolute() )
93 m_includes[ fileName.GetName() ] = fileName.GetFullPath();
97 wxFileName absolute( ltSubDir +
path );
98 m_includes[ absolute.GetName() ] = absolute.GetFullPath();
136 std::vector<LTSPICE_SCHEMATIC::LT_ASC>& outLT_ASCs,
137 const std::vector<wxString>& aAsyFiles )
141 std::vector<LTSPICE_SCHEMATIC::LT_SYMBOL> symbols = lt_asc.Symbols;
142 std::map<wxString, LIB_SYMBOL*> existingSymbol;
143 std::map<wxString, SCH_SYMBOL*> existingSchematicSymbol;
151 if( existingSymbol.count( lt_symbol.Name ) == 0 )
153 lib_symbol =
new LIB_SYMBOL( lt_symbol.Name );
157 existingSymbol.emplace( lt_symbol.Name, lib_symbol );
161 lib_symbol = existingSymbol[lt_symbol.Name];
164 LIB_ID libId( wxS(
"ltspice" ), lt_symbol.Name );
169 for(
int j = 0; j < (int) lt_symbol.Wires.size(); j++ )
179 for(
int j = 0; j < (int) lt_symbol.Lines.size(); j++ )
182 for(
int j = 0; j < (int) lt_symbol.Circles.size(); j++ )
185 for(
int j = 0; j < (int) lt_symbol.Arcs.size(); j++ )
188 for(
int j = 0; j < (int) lt_symbol.Rectangles.size(); j++ )
194 std::vector<LTSPICE_FILE> tempVector;
196 LTSPICE_FILE tempAsyFile( lt_symbol.Name +
".asy", { 0, 0 } );
199 tempVector.push_back( tempAsyFile );
210 int botRightX = lt_symbol.Offset.x
213 int botRightY = lt_symbol.Offset.y
223 if( wire.
Start == ( pinPos + lt_symbol.Offset ) )
226 if( wire.
End.
x == ( pinPos + lt_symbol.Offset ).x )
228 if( wire.
End.
y <= topLeftY )
230 else if( wire.
End.
y >= botRightY )
232 else if( wire.
End.
y < botRightY && wire.
End.
y > topLeftY )
236 else if( wire.
End.
y == ( pinPos + lt_symbol.Offset ).y )
238 if( wire.
End.
x <= topLeftX )
240 else if( wire.
End.
x >= botRightX )
242 else if( wire.
End.
x < botRightX && wire.
End.
x > topLeftX )
246 else if( wire.
End == ( pinPos + lt_symbol.Offset ) )
249 if( wire.
Start.
x == ( pinPos + lt_symbol.Offset ).x )
251 if( wire.
Start.
y <= topLeftY )
253 else if( wire.
Start.
y > botRightY )
255 else if( wire.
Start.
y < botRightY && wire.
End.
y > topLeftY )
259 else if( wire.
Start.
y == ( pinPos + lt_symbol.Offset ).y )
261 if( wire.
Start.
x <= topLeftX )
263 else if( wire.
Start.
x >= botRightX )
265 else if( wire.
Start.
x < botRightX && wire.
Start.
x > topLeftX )
280 for(
int j = 0; j < (int) aLtSymbol.
Lines.size(); j++ )
288 for(
int j = 0; j < (int) aLtSymbol.
Circles.size(); j++ )
296 for(
int j = 0; j < (int) aLtSymbol.
Arcs.size(); j++ )
304 for(
int j = 0; j < (int) aLtSymbol.
Rectangles.size(); j++ )
312 for(
int j = 0; j < (int) aLtSymbol.
Pins.size(); j++ )
350 if( aLTFontSize == 1 )
return MILS_SIZE( 36 );
351 else if( aLTFontSize == 2 )
return MILS_SIZE( 42 );
352 else if( aLTFontSize == 3 )
return MILS_SIZE( 50 );
353 else if( aLTFontSize == 4 )
return MILS_SIZE( 60 );
354 else if( aLTFontSize == 5 )
return MILS_SIZE( 72 );
355 else if( aLTFontSize == 6 )
return MILS_SIZE( 88 );
356 else if( aLTFontSize == 7 )
return MILS_SIZE( 108 );
465 std::vector<LTSPICE_SCHEMATIC::LT_ASC>& outLT_ASCs )
471 for(
int j = 0; j < (int) lt_asc.Lines.size(); j++ )
474 for(
int j = 0; j < (int) lt_asc.Circles.size(); j++ )
477 for(
int j = 0; j < (int) lt_asc.Arcs.size(); j++ )
480 for(
int j = 0; j < (int) lt_asc.Rectangles.size(); j++ )
483 for(
int j = 0; j < (int) lt_asc.Bustap.size(); j++ )
505 for(
int j = 0; j < (int) lt_asc.Wires.size(); j++ )
506 CreateWire( lt_asc, j, aSheet, SCH_LAYER_ID::LAYER_WIRE );
508 for(
int j = 0; j < (int) lt_asc.Iopins.size(); j++ )
513 if( lt_flag.
Value == wxS(
"0" ) )
516 aSheet, lt_asc.Wires ) );
534 lt_flag.Expression, lt_flag.
FontSize ) );
545 for(
int k = 0; k < (int) aAscfile.
Wires.size(); k++ )
547 if( ( aAscfile.
Wires[k].Start == bustap.
Start )
548 || ( aAscfile.
Wires[k].End == bustap.
Start ) )
550 CreateWire( aAscfile, k, aSheet, SCH_LAYER_ID::LAYER_BUS );
551 aAscfile.
Wires.erase( aAscfile.
Wires.begin() + k );
556 bustap.
Start.
y - 16 } ) );
581 for(
unsigned int k = 0; k < aAscfile.
Flags.size(); k++ )
586 ioPinName = aAscfile.
Flags[k].Value;
587 aAscfile.
Flags.erase( aAscfile.
Flags.begin() + k );
684 default:
return PLOT_DASH_TYPE::SOLID;
699 switch( aJustification )
734 switch( aJustification )
756 if( wxSplit( aText->
GetText(),
'\n',
'\0' ).size() > 1 )
758 switch( aJustification )
815 std::vector<LTSPICE_SCHEMATIC::WIRE>& aWires )
828 PLOT_DASH_TYPE::SOLID ) );
835 pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
838 pin->SetShape( GRAPHIC_PINSHAPE::LINE );
841 LIB_ID libId( wxS(
"ltspice" ), wxS(
"GND" ) );
854 if( aOffset == wire.Start )
856 if( wire.Start.x == wire.End.x )
858 if( wire.Start.y < wire.End.y )
866 if( wire.Start.x < wire.End.x )
868 else if( wire.Start.x > wire.End.x )
872 else if( aOffset == wire.End )
874 if( wire.Start.x == wire.End.x )
876 if( wire.Start.y > wire.End.y )
884 if( wire.Start.x < wire.End.x )
886 else if( wire.Start.x > wire.End.x )
897 const wxString& aValue,
int aFontSize )
915 SCH_FIELD field( { 0, 0 }, -1, label, wxS(
"DATAFLAG" ) );
918 field.SetVisible(
true );
942 wxString symbolName = aLTSymbol.
Name.Upper();
943 wxString type = aLTSymbol.
SymAttributes[ wxS(
"TYPE" ) ].Upper();
944 wxString prefix = aLTSymbol.
SymAttributes[ wxS(
"PREFIX" ) ].Upper();
945 wxString instName = aLTSymbol.
SymAttributes[ wxS(
"INSTNAME" ) ].Upper();
948 aSymbol->
SetRef( aSheet, instName );
951 auto setupNonInferredPassive =
952 [&](
const wxString& aPrefix )
954 SCH_FIELD deviceField( { 0, 0 }, -1, aSymbol, wxS(
"Sim.Device" ) );
955 deviceField.
SetText( aPrefix );
958 SCH_FIELD paramsField( { 0, 0 }, -1, aSymbol, wxS(
"Sim.Params" ) );
959 paramsField.
SetText( aPrefix + wxS(
"=${VALUE}" ) );
963 if( symbolName == wxS(
"RES" ) )
965 if( !instName.StartsWith(
'R' ) )
966 setupNonInferredPassive( wxS(
"R" ) );
968 else if( symbolName == wxS(
"CAP" ) )
970 if( !instName.StartsWith(
'C' ) )
971 setupNonInferredPassive( wxS(
"C" ) );
973 else if( symbolName == wxS(
"IND" ) )
975 if( !instName.StartsWith(
'L' ) )
976 setupNonInferredPassive( wxS(
"L" ) );
978 else if( symbolName == wxS(
"VOLTAGE" ) || symbolName == wxS(
"CURRENT" ) )
984 wxString libFile = aLTSymbol.
SymAttributes[ wxS(
"MODELFILE" ) ];
986 if( prefix == wxS(
"X" ) )
991 else if( libFile.IsEmpty() )
996 if( type ==
"DIODE" )
997 libFile = libPath + wxS(
"cmp/standard.dio" );
998 else if( type ==
"NPN" || type ==
"PNP" )
999 libFile = libPath + wxS(
"cmp/standard.bjt" );
1000 else if( type ==
"NJF" || type ==
"PJF" )
1001 libFile = libPath + wxS(
"cmp/standard.jft" );
1002 else if( type ==
"NMOS" || type ==
"PMOS" )
1003 libFile = libPath + wxS(
"cmp/standard.mos" );
1006 if( libFile.IsEmpty() )
1009 if( !libFile.IsEmpty() )
1011 SCH_FIELD libField( { 0, 0 }, -1, aSymbol, wxS(
"Sim.Library" ) );
1016 SCH_FIELD nameField( { 0, 0 }, -1, aSymbol, wxS(
"Sim.Name" ) );
1017 nameField.
SetText( wxS(
"${VALUE}" ) );
1020 if( type == wxS(
"X" ) )
1022 SCH_FIELD deviceField( { 0, 0 }, -1, aSymbol, wxS(
"Sim.Device" ) );
1023 deviceField.
SetText( wxS(
"SUBCKT" ) );
1027 wxString spiceLine = aLTSymbol.
SymAttributes[ wxS(
"SPICELINE" ) ];
1029 if( !spiceLine.IsEmpty() )
1031 SCH_FIELD paramsField( { 0, 0 }, -1, aSymbol, wxS(
"Sim.Params" ) );
1032 paramsField.
SetText( spiceLine );
1057 case 38: field = aSymbol->
FindField( wxS(
"Sim.Name" ) );
break;
1058 case 39: field = aSymbol->
FindField( wxS(
"Sim.Params" ) );
break;
1181 if( aLTSymbol.
SymAttributes[wxS(
"Prefix" )] == wxS(
"X" ) )
1182 aRectangle->
SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR );
1207 wxString device = aLTSymbol.
Name.Lower();
1209 if( aLTSymbol.
Pins.size() == 2 && ( device == wxS(
"res" )
1210 || device == wxS(
"cap" )
1211 || device == wxS(
"ind" ) ) )
1224 aPin->
SetNumber( wxString::Format( wxS(
"%d" ), aIndex + 1 ) );
1225 aPin->
SetType( ELECTRICAL_PINTYPE::PT_PASSIVE );
1228 aPin->
SetShape( GRAPHIC_PINSHAPE::LINE );
constexpr EDA_IU_SCALE schIUScale
void SetOrigin(const Vec &pos)
const Vec & GetOrigin() const
void Offset(coord_type dx, coord_type dy)
const Vec GetCenter() const
coord_type GetTop() const
coord_type GetHeight() const
coord_type GetWidth() const
void SetSize(const Vec &size)
coord_type GetLeft() const
const Vec & GetSize() const
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
void SetCenter(const VECTOR2I &aCenter)
void SetStart(const VECTOR2I &aStart)
void SetEnd(const VECTOR2I &aEnd)
void SetFillMode(FILL_T aFill)
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
int GetTextHeight() const
void SetTextSize(VECTOR2I aNewSize)
virtual const wxString & GetText() const
Return the string associated with the text object.
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
void Offset(const VECTOR2I &aOffset)
virtual void SetVisible(bool aVisible)
virtual void SetText(const wxString &aText)
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
void SetMultilineAllowed(bool aAllow)
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
A logical library item identifier and consists of various portions much like a URI.
void SetShape(GRAPHIC_PINSHAPE aShape)
void SetPosition(const VECTOR2I &aPos) override
void SetName(const wxString &aName)
void SetNameTextSize(int aSize)
void SetType(ELECTRICAL_PINTYPE aType)
void SetOrientation(PIN_ORIENTATION aOrientation)
void SetNumber(const wxString &aNumber)
void SetLength(int aLength)
void SetStroke(const STROKE_PARAMS &aStroke)
void AddPoint(const VECTOR2I &aPosition)
void SetPosition(const VECTOR2I &aPosition) override
Define a library symbol object.
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
void SetShowPinNumbers(bool aShow)
Set or clear the pin number visibility flag.
void AddDrawItem(LIB_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
LT_SYMBOL SymbolBuilder(const wxString &aAscFileName, LT_ASC &aAscFile)
POLARITY
Polarity enum represents polarity of pin.
const wxFileName & GetLTspiceDataDir()
JUSTIFICATION
Defines in what ways the PIN or TEXT can be justified.
void CreateFields(LTSPICE_SCHEMATIC::LT_SYMBOL &aLTSymbol, SCH_SYMBOL *aSymbol, SCH_SHEET_PATH *aSheet)
void setTextJustification(EDA_TEXT *aText, LTSPICE_SCHEMATIC::JUSTIFICATION aJustification)
void CreateBusEntry(LTSPICE_SCHEMATIC::LT_ASC &aAscfile, int aIndex, SCH_SHEET_PATH *aSheet)
Method for plotting Bustap from Asc files.
int ToKicadCoords(int aCoordinate)
Method converts ltspice coordinate(i.e scale) to kicad coordinates.
void CreateCircle(LTSPICE_SCHEMATIC::LT_ASC &aAscfile, int aIndex, SCH_SHEET_PATH *aSheet)
Method for plotting circle from Asc files.
LTSPICE_SCHEMATIC * m_lt_schematic
VECTOR2I ToKicadFontSize(int aLTFontSize)
SCH_SYMBOL * CreatePowerSymbol(const VECTOR2I &aOffset, const wxString &aValue, int aFontSize, SCH_SHEET_PATH *aSheet, std::vector< LTSPICE_SCHEMATIC::WIRE > &aWires)
Create a power symbol.
PLOT_DASH_TYPE getLineStyle(const LTSPICE_SCHEMATIC::LINESTYLE &aLineStyle)
void RotateMirror(LTSPICE_SCHEMATIC::LT_SYMBOL &aLTSymbol, SCH_SYMBOL *aSchSymbol)
Methods for rotating and mirroring objects.
void CreateLine(LTSPICE_SCHEMATIC::LT_ASC &aAscfile, int aIndex, SCH_SHEET_PATH *aSheet)
Method for plotting Line from Asc files.
void CreateKicadSCH_ITEMs(SCH_SHEET_PATH *aSheet, std::vector< LTSPICE_SCHEMATIC::LT_ASC > &outLT_ASCs)
Main method for loading intermediate data structure from Asc file to kicad.
void CreateLines(LIB_SYMBOL *aSymbol, LTSPICE_SCHEMATIC::LT_SYMBOL &aLTSymbol, int aIndex, LIB_SHAPE *aShape)
Method for plotting Lines from Asy files.
SCH_TEXT * CreateSCH_TEXT(VECTOR2I aOffset, const wxString &aText, int aFontSize, LTSPICE_SCHEMATIC::JUSTIFICATION aJustification)
Create schematic text.
void CreateWire(LTSPICE_SCHEMATIC::LT_ASC &aAscfile, int aIndex, SCH_SHEET_PATH *aSheet, SCH_LAYER_ID aLayer)
Create a schematic wire.
int ToLtSpiceCoords(int aCoordinate)
Method converts kicad coordinate(i.e scale) to ltspice coordinates.
void CreateRect(LTSPICE_SCHEMATIC::LT_ASC &aAscfile, int aIndex, SCH_SHEET_PATH *aSheet)
Method for plotting rectangle from Asc files.
VECTOR2I ToInvertedKicadCoords(const VECTOR2I &aPos)
std::map< wxString, wxString > m_includes
void CreateKicadSYMBOLs(SCH_SHEET_PATH *aSheet, std::vector< LTSPICE_SCHEMATIC::LT_ASC > &outLT_ASCs, const std::vector< wxString > &aAsyFiles)
Main Method for loading indermediate data to kicacd object from asy files.
void CreateWires(LTSPICE_SCHEMATIC::LT_SYMBOL &aLTSymbol, int aIndex, SCH_SHEET_PATH *aSheet)
Method for plotting wires.
void RotateMirrorShape(LTSPICE_SCHEMATIC::LT_SYMBOL &aLTSymbol, SCH_SHAPE *aShape)
void CreatePin(LTSPICE_SCHEMATIC::LT_ASC &aAscfile, int aIndex, SCH_SHEET_PATH *aSheet)
Method for plotting Iopin from Asc files.
void readIncludes(std::vector< LTSPICE_SCHEMATIC::LT_ASC > &outLT_ASCs)
int getLineWidth(const LTSPICE_SCHEMATIC::LINEWIDTH &aLineWidth)
void CreateArc(LTSPICE_SCHEMATIC::LT_ASC &aAscfile, int aIndex, SCH_SHEET_PATH *aSheet)
Method for plotting Arc from Asc files.
void Parse(SCH_SHEET_PATH *aSheet, std::vector< LTSPICE_SCHEMATIC::LT_ASC > &outLT_ASCs, const std::vector< wxString > &aAsyFileNames)
Function responsible for loading the .asc and .asy files in intermediate data structure.
void CreateSymbol(LTSPICE_SCHEMATIC::LT_SYMBOL &aLtSymbol, LIB_SYMBOL *aLibSymbol)
SCH_LABEL_BASE * CreateSCH_LABEL(KICAD_T aType, const VECTOR2I &aOffset, const wxString &aValue, int aFontSize)
Create a label.
STROKE_PARAMS getStroke(const LTSPICE_SCHEMATIC::LINEWIDTH &aLineWidth, const LTSPICE_SCHEMATIC::LINESTYLE &aLineStyle)
const VECTOR2I GetSizeIU(double aIUScale) const
Gets the page size in internal units.
void SetSize(const VECTOR2I &aSize)
Class for a wire to bus entry.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
void SetPosition(const VECTOR2I &aPosition) override
void SetText(const wxString &aText) override
void SetLayer(SCH_LAYER_ID aLayer)
Set the layer this item is on.
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
void AddField(const SCH_FIELD &aField)
void SetShape(LABEL_FLAG_SHAPE aShape)
void SetPosition(const VECTOR2I &aPosition) override
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual) override
virtual void SetSpinStyle(SPIN_STYLE aSpinStyle)
Segment description base class to describe items which have 2 end points (track, wire,...
void SetStartPoint(const VECTOR2I &aPosition)
void SetLineWidth(const int aSize)
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
virtual void SetStroke(const STROKE_PARAMS &aStroke) override
void SetEndPoint(const VECTOR2I &aPosition)
const PAGE_INFO & GetPageSettings() const
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
void SetPosition(const VECTOR2I &aPos) override
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
void Move(const VECTOR2I &aOffset) override
Move the item by aMoveVector to a new position.
void SetStroke(const STROKE_PARAMS &aStroke) override
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
void Rotate(const VECTOR2I &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
void AddPoint(const VECTOR2I &aPosition)
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()
void SetValueFieldText(const wxString &aValue)
SCH_FIELD * FindField(const wxString &aFieldName, bool aIncludeDefaultFields=true, bool aCaseInsensitive=false)
Search for a SCH_FIELD with aFieldName.
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
void SetOrientation(int aOrientation)
Compute the new transform matrix based on aOrientation for the symbol which is applied to the current...
SCH_FIELD * AddField(const SCH_FIELD &aField)
Add a field to the symbol.
Simple container to manage line stroke parameters.
static constexpr EDA_ANGLE & ANGLE_HORIZONTAL
static constexpr EDA_ANGLE & ANGLE_VERTICAL
SCH_LAYER_ID
Eeschema drawing layers.
LABEL_FLAG_SHAPE getLabelShape(LTSPICE_SCHEMATIC::POLARITY aPolarity)
#define UNIMPLEMENTED_FOR(type)
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
@ SYM_ROTATE_COUNTERCLOCKWISE
PLOT_DASH_TYPE
Dashed line types.
constexpr int IUToMils(int iu) const
constexpr int MilsToIU(int mils) const
The ARC is represented inside a rectangle whose opposite site are given.
The CIRCLE is represented in Ltpsice inside a rectangle whose two opposite points and line style are ...
IOPIN is special contact on symbol used for IO operations.
A struct to hold .asc file definition.
std::vector< CIRCLE > Circles
std::vector< IOPIN > Iopins
std::vector< BUSTAP > Bustap
std::vector< LINE > Lines
std::vector< WIRE > Wires
std::vector< RECTANGLE > Rectangles
std::vector< FLAG > Flags
JUSTIFICATION PinJustification
std::map< wxString, wxString > PinAttribute
A struct to hold SYMBOL definition.
std::map< wxString, wxString > SymAttributes
std::vector< RECTANGLE > Rectangles
std::vector< LT_WINDOW > Windows
std::vector< LT_PIN > Pins
std::vector< WIRE > Wires
ORIENTATION SymbolOrientation
std::vector< CIRCLE > Circles
std::vector< LINE > Lines
JUSTIFICATION Justification
A 4-sided polygon with opposite equal sides, used in representing shapes.
JUSTIFICATION Justification
A metallic connection, used for transfer, between two points or pin.
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
T rescale(T aNumerator, T aValue, T aDenominator)
Scale a number (value) by rational (numerator/denominator).