KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ltspice_sch_parser.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2022 Chetan Subhash Shinde<[email protected]>
5 * Copyright (C) 2023 CERN
6 * Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
29#include <sch_io_mgr.h>
30#include <schematic.h>
31#include <sch_sheet.h>
32#include <sch_sheet_pin.h>
33#include <sch_line.h>
34#include <lib_shape.h>
35#include <sch_label.h>
36#include <sch_edit_frame.h>
37#include <sch_shape.h>
38#include <sch_bus_entry.h>
39
40
42 std::vector<LTSPICE_SCHEMATIC::LT_ASC>& outLT_ASCs,
43 const std::vector<wxString>& aAsyFileNames )
44{
45 // Center created objects in Kicad page
46 BOX2I bbox;
47
48 for( const LTSPICE_SCHEMATIC::LT_ASC& asc : outLT_ASCs )
49 bbox.Merge( asc.BoundingBox );
50
51 m_originOffset = { 0, 0 };
52 bbox.SetOrigin( ToKicadCoords( bbox.GetOrigin() ) );
53 bbox.SetSize( ToKicadCoords( bbox.GetSize() ) );
54
56 int grid = schIUScale.MilsToIU( 50 );
57 int margin = grid * 10;
58
59 m_originOffset = ( pageSize / 2 ) - bbox.GetCenter();
60
61 if( bbox.GetWidth() > pageSize.x - margin )
62 m_originOffset.x = margin - bbox.GetLeft();
63
64 if( bbox.GetHeight() > pageSize.y - margin )
65 m_originOffset.y = margin - bbox.GetTop();
66
68
69 readIncludes( outLT_ASCs );
70 CreateKicadSYMBOLs( aSheet, outLT_ASCs, aAsyFileNames );
71 CreateKicadSCH_ITEMs( aSheet, outLT_ASCs );
72}
73
74
75void LTSPICE_SCH_PARSER::readIncludes( std::vector<LTSPICE_SCHEMATIC::LT_ASC>& outLT_ASCs )
76{
77 wxString ltSubDir = m_lt_schematic->GetLTspiceDataDir().GetFullPath() + wxS( "lib/sub/" );
78 wxString path;
79
80 for( const LTSPICE_SCHEMATIC::LT_ASC& asc : outLT_ASCs )
81 {
82 for( const LTSPICE_SCHEMATIC::TEXT& lt_text : asc.Texts )
83 {
84 for( wxString& line : wxSplit( lt_text.Value, '\n' ) )
85 {
86 if( line.StartsWith( wxS( ".inc " ), &path ) )
87 {
88 path.Replace( '\\', '/' );
89 wxFileName fileName( path );
90
91 if( fileName.IsAbsolute() )
92 {
93 m_includes[ fileName.GetName() ] = fileName.GetFullPath();
94 }
95 else
96 {
97 wxFileName absolute( ltSubDir + path );
98 m_includes[ absolute.GetName() ] = absolute.GetFullPath();
99 }
100 }
101 }
102 }
103 }
104}
105
106
108 int aIndex, LIB_SHAPE* shape )
109{
110 LTSPICE_SCHEMATIC::LINE& lt_line = aLTSymbol.Lines[aIndex];
111
112 shape->AddPoint( ToInvertedKicadCoords( lt_line.End ) );
113 shape->AddPoint( ToInvertedKicadCoords( lt_line.Start ) );
114 shape->SetStroke( getStroke( lt_line.LineWidth, lt_line.LineStyle ) );
115}
116
117
119 SCH_SHEET_PATH* aSheet )
120{
121 LTSPICE_SCHEMATIC::LINE& lt_line = aLTSymbol.Lines[aIndex];
122 SCH_SHAPE* shape = new SCH_SHAPE( SHAPE_T::POLY );
123
124 shape->AddPoint( ToKicadCoords( lt_line.End ) );
125 shape->AddPoint( ToKicadCoords( lt_line.Start ) );
126 shape->SetStroke( getStroke( lt_line.LineWidth, lt_line.LineStyle ) );
127
128 shape->Move( ToKicadCoords( aLTSymbol.Offset ) + m_originOffset );
129 RotateMirrorShape( aLTSymbol, shape );
130
131 aSheet->LastScreen()->Append( shape );
132}
133
134
136 std::vector<LTSPICE_SCHEMATIC::LT_ASC>& outLT_ASCs,
137 const std::vector<wxString>& aAsyFiles )
138{
139 for( LTSPICE_SCHEMATIC::LT_ASC& lt_asc : outLT_ASCs )
140 {
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;
144
145 for( LTSPICE_SCHEMATIC::LT_SYMBOL& lt_symbol : symbols )
146 {
147 if( !alg::contains( aAsyFiles, lt_symbol.Name ) )
148 {
149 LIB_SYMBOL* lib_symbol;
150
151 if( existingSymbol.count( lt_symbol.Name ) == 0 )
152 {
153 lib_symbol = new LIB_SYMBOL( lt_symbol.Name );
154
155 CreateSymbol( lt_symbol, lib_symbol );
156
157 existingSymbol.emplace( lt_symbol.Name, lib_symbol );
158 }
159 else
160 {
161 lib_symbol = existingSymbol[lt_symbol.Name];
162 }
163
164 LIB_ID libId( wxS( "ltspice" ), lt_symbol.Name );
165 SCH_SYMBOL* sch_symbol = new SCH_SYMBOL( *lib_symbol, libId, aSheet, 1 );
166
167 CreateFields( lt_symbol, sch_symbol, aSheet );
168
169 for( int j = 0; j < (int) lt_symbol.Wires.size(); j++ )
170 CreateWires( lt_symbol, j, aSheet );
171
172 sch_symbol->Move( ToKicadCoords( lt_symbol.Offset ) + m_originOffset );
173 RotateMirror( lt_symbol, sch_symbol );
174
175 aSheet->LastScreen()->Append( sch_symbol );
176 }
177 else
178 {
179 for( int j = 0; j < (int) lt_symbol.Lines.size(); j++ )
180 CreateLines( lt_symbol, j, aSheet );
181
182 for( int j = 0; j < (int) lt_symbol.Circles.size(); j++ )
183 CreateCircle( lt_symbol, j, aSheet );
184
185 for( int j = 0; j < (int) lt_symbol.Arcs.size(); j++ )
186 CreateArc( lt_symbol, j, aSheet );
187
188 for( int j = 0; j < (int) lt_symbol.Rectangles.size(); j++ )
189 CreateRect( lt_symbol, j, aSheet );
190
191 // Calculating bounding box
192 BOX2I bbox;
193
194 std::vector<LTSPICE_FILE> tempVector;
196 LTSPICE_FILE tempAsyFile( lt_symbol.Name + ".asy", { 0, 0 } );
198
199 tempVector.push_back( tempAsyFile );
200
201 tempSymbol = m_lt_schematic->SymbolBuilder( lt_symbol.Name, dummyAsc );
202
203 LIB_SYMBOL* tempLibSymbol = new LIB_SYMBOL( lt_symbol.Name );
204 CreateSymbol( tempSymbol, tempLibSymbol );
205
206 bbox = tempLibSymbol->GetBoundingBox();
207
208 int topLeftX = lt_symbol.Offset.x + ToLtSpiceCoords( bbox.GetOrigin().x );
209 int topLeftY = lt_symbol.Offset.y + ToLtSpiceCoords( bbox.GetOrigin().y );
210 int botRightX = lt_symbol.Offset.x
211 + ToLtSpiceCoords( bbox.GetOrigin().x )
212 + ToLtSpiceCoords( bbox.GetSize().x );
213 int botRightY = lt_symbol.Offset.y
214 + ToLtSpiceCoords( bbox.GetOrigin().y )
215 + ToLtSpiceCoords( bbox.GetSize().y );
216
217 for( LTSPICE_SCHEMATIC::LT_PIN& pin : lt_symbol.Pins )
218 {
219 VECTOR2I pinPos = pin.PinLocation;
220
221 for( LTSPICE_SCHEMATIC::WIRE& wire : lt_asc.Wires )
222 {
223 if( wire.Start == ( pinPos + lt_symbol.Offset ) )
224 {
225 //wire is vertical
226 if( wire.End.x == ( pinPos + lt_symbol.Offset ).x )
227 {
228 if( wire.End.y <= topLeftY )
229 wire.Start = VECTOR2I( wire.Start.x, topLeftY + 3 );
230 else if( wire.End.y >= botRightY )
231 wire.Start = VECTOR2I( wire.Start.x, botRightY );
232 else if( wire.End.y < botRightY && wire.End.y > topLeftY )
233 wire.Start = VECTOR2I( topLeftX, wire.Start.y );
234 }
235 //wire is horizontal
236 else if( wire.End.y == ( pinPos + lt_symbol.Offset ).y )
237 {
238 if( wire.End.x <= topLeftX )
239 wire.Start = VECTOR2I( topLeftX, wire.Start.y );
240 else if( wire.End.x >= botRightX )
241 wire.Start = VECTOR2I( botRightX, wire.Start.y );
242 else if( wire.End.x < botRightX && wire.End.x > topLeftX )
243 wire.Start = VECTOR2I( botRightX, wire.Start.y );
244 }
245 }
246 else if( wire.End == ( pinPos + lt_symbol.Offset ) )
247 {
248 //wire is Vertical
249 if( wire.Start.x == ( pinPos + lt_symbol.Offset ).x )
250 {
251 if( wire.Start.y <= topLeftY )
252 wire.End = VECTOR2I( wire.End.x, topLeftY );
253 else if( wire.Start.y > botRightY )
254 wire.End = VECTOR2I( wire.End.x, botRightY );
255 else if( wire.Start.y < botRightY && wire.End.y > topLeftY )
256 wire.End = VECTOR2I( wire.End.x, botRightY );
257 }
258 //wire is Horizontal
259 else if( wire.Start.y == ( pinPos + lt_symbol.Offset ).y )
260 {
261 if( wire.Start.x <= topLeftX )
262 wire.End = VECTOR2I( topLeftX, wire.End.y );
263 else if( wire.Start.x >= botRightX )
264 wire.End = VECTOR2I( botRightX, wire.End.y );
265 else if( wire.Start.x < botRightX && wire.Start.x > topLeftX )
266 wire.End = VECTOR2I( botRightX, wire.End.y );
267 }
268 }
269 }
270 }
271 }
272 }
273 }
274}
275
276
278 LIB_SYMBOL* aLibSymbol )
279{
280 for( int j = 0; j < (int) aLtSymbol.Lines.size(); j++ )
281 {
282 LIB_SHAPE* line = new LIB_SHAPE( aLibSymbol, SHAPE_T::POLY );
283
284 CreateLines( aLibSymbol, aLtSymbol, j, line );
285 aLibSymbol->AddDrawItem( line );
286 }
287
288 for( int j = 0; j < (int) aLtSymbol.Circles.size(); j++ )
289 {
290 LIB_SHAPE* circle = new LIB_SHAPE( aLibSymbol, SHAPE_T::CIRCLE );
291
292 CreateCircle( aLtSymbol, j, circle );
293 aLibSymbol->AddDrawItem( circle );
294 }
295
296 for( int j = 0; j < (int) aLtSymbol.Arcs.size(); j++ )
297 {
298 LIB_SHAPE* arc = new LIB_SHAPE( aLibSymbol, SHAPE_T::ARC );
299
300 CreateArc( aLtSymbol, j, arc );
301 aLibSymbol->AddDrawItem( arc );
302 }
303
304 for( int j = 0; j < (int) aLtSymbol.Rectangles.size(); j++ )
305 {
306 LIB_SHAPE* rectangle = new LIB_SHAPE( aLibSymbol, SHAPE_T::RECTANGLE );
307
308 CreateRect( aLtSymbol, j, rectangle );
309 aLibSymbol->AddDrawItem( rectangle );
310 }
311
312 for( int j = 0; j < (int) aLtSymbol.Pins.size(); j++ )
313 {
314 LIB_PIN* pin = new LIB_PIN( aLibSymbol );
315
316 CreatePin( aLtSymbol, j, pin );
317 aLibSymbol->AddDrawItem( pin );
318 }
319
320 aLibSymbol->SetShowPinNumbers( false );
321}
322
323
325{
326 return schIUScale.MilsToIU( rescale( 50, aCoordinate, 16 ) );
327}
328
329
331{
332 return VECTOR2I( ToKicadCoords( aPos.x ), ToKicadCoords( aPos.y ) );
333}
334
335
337{
338 return VECTOR2I( ToKicadCoords( aPos.x ), -ToKicadCoords( aPos.y ) );
339}
340
341
343{
344 auto MILS_SIZE =
345 []( int mils )
346 {
347 return VECTOR2I( schIUScale.MilsToIU( mils ), schIUScale.MilsToIU( mils ) );
348 };
349
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 );
357 else return ToKicadFontSize( 2 );
358}
359
360
362{
363 return schIUScale.IUToMils( rescale( 16, aCoordinate, 50 ) );
364}
365
366
368 SCH_SHAPE* aShape )
369{
371 {
372 aShape->Rotate( VECTOR2I() );
373 aShape->Rotate( VECTOR2I() );
374 aShape->Rotate( VECTOR2I() );
375 }
377 {
378 aShape->Rotate( VECTOR2I() );
379 aShape->Rotate( VECTOR2I() );
380 }
382 {
383 aShape->Rotate( VECTOR2I() );
384 }
386 {
387 aShape->MirrorVertically( 0 );
388 }
390 {
391 aShape->MirrorVertically( 0 );
392 aShape->Rotate( VECTOR2I() );
393 }
395 {
396 aShape->MirrorHorizontally( 0 );
397 }
399 {
400 aShape->MirrorVertically( 0 );
401 aShape->Rotate( VECTOR2I() );
402 aShape->Rotate( VECTOR2I() );
403 aShape->Rotate( VECTOR2I() );
404 }
405}
406
407
409 SCH_SYMBOL* aSchSymbol )
410{
412 {
413 aSchSymbol->SetOrientation( SYM_ORIENT_0 );
414 }
416 {
417 aSchSymbol->SetOrientation( SYM_ORIENT_180 );
419 }
421 {
422 aSchSymbol->SetOrientation( SYM_ORIENT_180 );
423 }
425 {
427 }
429 {
430 aSchSymbol->SetOrientation( SYM_MIRROR_Y );
431 }
433 {
434 aSchSymbol->SetOrientation( SYM_MIRROR_Y );
436 }
438 {
439 aSchSymbol->SetOrientation( SYM_MIRROR_X );
440 }
442 {
443 aSchSymbol->SetOrientation( SYM_MIRROR_Y );
445 }
446}
447
448
450 SCH_SHEET_PATH* aSheet )
451{
452 SCH_LINE* segment = new SCH_LINE();
453
455 segment->SetLineStyle( PLOT_DASH_TYPE::SOLID );
456
457 segment->SetStartPoint( aLTSymbol.Wires[aIndex].Start );
458 segment->SetEndPoint( aLTSymbol.Wires[aIndex].End );
459
460 aSheet->LastScreen()->Append( segment );
461}
462
463
465 std::vector<LTSPICE_SCHEMATIC::LT_ASC>& outLT_ASCs )
466{
467 SCH_SCREEN* screen = aSheet->LastScreen();
468
469 for( LTSPICE_SCHEMATIC::LT_ASC& lt_asc : outLT_ASCs )
470 {
471 for( int j = 0; j < (int) lt_asc.Lines.size(); j++ )
472 CreateLine( lt_asc, j, aSheet );
473
474 for( int j = 0; j < (int) lt_asc.Circles.size(); j++ )
475 CreateCircle( lt_asc, j, aSheet );
476
477 for( int j = 0; j < (int) lt_asc.Arcs.size(); j++ )
478 CreateArc( lt_asc, j, aSheet );
479
480 for( int j = 0; j < (int) lt_asc.Rectangles.size(); j++ )
481 CreateRect( lt_asc, j, aSheet );
482
483 for( int j = 0; j < (int) lt_asc.Bustap.size(); j++ )
484 CreateBusEntry( lt_asc, j, aSheet );
485
505 for( int j = 0; j < (int) lt_asc.Wires.size(); j++ )
506 CreateWire( lt_asc, j, aSheet, SCH_LAYER_ID::LAYER_WIRE );
507
508 for( int j = 0; j < (int) lt_asc.Iopins.size(); j++ )
509 CreatePin( lt_asc, j, aSheet );
510
511 for( const LTSPICE_SCHEMATIC::FLAG& lt_flag : lt_asc.Flags )
512 {
513 if( lt_flag.Value == wxS( "0" ) )
514 {
515 screen->Append( CreatePowerSymbol( lt_flag.Offset, lt_flag.Value, lt_flag.FontSize,
516 aSheet, lt_asc.Wires ) );
517 }
518 else
519 {
520 screen->Append( CreateSCH_LABEL( SCH_LABEL_T, lt_flag.Offset, lt_flag.Value,
521 lt_flag.FontSize ) );
522 }
523 }
524
525 for( const LTSPICE_SCHEMATIC::TEXT& lt_text : lt_asc.Texts )
526 {
527 screen->Append( CreateSCH_TEXT( lt_text.Offset, lt_text.Value, lt_text.FontSize,
528 lt_text.Justification ) );
529 }
530
531 for( const LTSPICE_SCHEMATIC::DATAFLAG& lt_flag : lt_asc.DataFlags )
532 {
534 lt_flag.Expression, lt_flag.FontSize ) );
535 }
536 }
537}
538
539
541 SCH_SHEET_PATH* aSheet )
542{
543 LTSPICE_SCHEMATIC::BUSTAP& bustap = aAscfile.Bustap[aIndex];
544
545 for( int k = 0; k < (int) aAscfile.Wires.size(); k++ )
546 {
547 if( ( aAscfile.Wires[k].Start == bustap.Start )
548 || ( aAscfile.Wires[k].End == bustap.Start ) )
549 {
550 CreateWire( aAscfile, k, aSheet, SCH_LAYER_ID::LAYER_BUS );
551 aAscfile.Wires.erase( aAscfile.Wires.begin() + k );
552 }
553 }
554
555 SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( ToKicadCoords( { bustap.Start.x,
556 bustap.Start.y - 16 } ) );
557
558 busEntry->SetSize( { ToKicadCoords( 16 ), ToKicadCoords( 16 ) } );
559
560 aSheet->LastScreen()->Append( busEntry );
561}
562
563
565{
566 if( aPolarity == LTSPICE_SCHEMATIC::POLARITY::INPUT )
568 else if( aPolarity == LTSPICE_SCHEMATIC::POLARITY::OUTPUT )
570 else
572}
573
574
576 SCH_SHEET_PATH* aSheet )
577{
578 LTSPICE_SCHEMATIC::IOPIN& iopin = aAscfile.Iopins[aIndex];
579 wxString ioPinName;
580
581 for( unsigned int k = 0; k < aAscfile.Flags.size(); k++ )
582 {
583 if( ( aAscfile.Flags[k].Offset.x == iopin.Location.x )
584 && ( aAscfile.Flags[k].Offset.y == iopin.Location.y ) )
585 {
586 ioPinName = aAscfile.Flags[k].Value;
587 aAscfile.Flags.erase( aAscfile.Flags.begin() + k );
588 }
589 }
590
591 SCH_HIERLABEL* sheetPin =
592 new SCH_HIERLABEL( ToKicadCoords( iopin.Location ), ioPinName, SCH_HIER_LABEL_T );
593
594 sheetPin->Move( m_originOffset );
595
596 sheetPin->SetShape( getLabelShape( iopin.Polarity ) );
597 aSheet->LastScreen()->Append( sheetPin );
598}
599
600
602 SCH_SHEET_PATH* aSheet )
603{
604 LTSPICE_SCHEMATIC::LINE& lt_line = aAscfile.Lines[aIndex];
605 SCH_LINE* line = new SCH_LINE( ToKicadCoords( lt_line.Start ), SCH_LAYER_ID::LAYER_NOTES );
606
607 line->SetEndPoint( ToKicadCoords( lt_line.End ) );
608 line->SetStroke( getStroke( lt_line.LineWidth, lt_line.LineStyle ) );
609 line->Move( m_originOffset );
610
611 aSheet->LastScreen()->Append( line );
612}
613
614
616 SCH_SHEET_PATH* aSheet )
617{
618 LTSPICE_SCHEMATIC::CIRCLE& lt_circle = aAscfile.Circles[aIndex];
619 SCH_SHAPE* circle = new SCH_SHAPE( SHAPE_T::CIRCLE );
620
621 VECTOR2I c = ( lt_circle.TopLeft + lt_circle.BotRight ) / 2;
622 int r = ( lt_circle.TopLeft.x - lt_circle.BotRight.x ) / 2;
623
624 circle->SetPosition( ToKicadCoords( c ) );
625 circle->SetEnd( ToKicadCoords( c ) + VECTOR2I( abs( ToKicadCoords( r ) ), 0 ) );
626 circle->SetStroke( getStroke( lt_circle.LineWidth, lt_circle.LineStyle ) );
627 circle->Move( m_originOffset );
628
629 aSheet->LastScreen()->Append( circle );
630}
631
632
634 SCH_SHEET_PATH* aSheet )
635{
636 LTSPICE_SCHEMATIC::ARC& lt_arc = aAscfile.Arcs[aIndex];
637 SCH_SHAPE* arc = new SCH_SHAPE( SHAPE_T::ARC );
638
639 arc->SetCenter( ToKicadCoords( ( lt_arc.TopLeft + lt_arc.BotRight ) / 2 ) );
640 arc->SetEnd( ToKicadCoords( lt_arc.ArcEnd ) );
641 arc->SetStart( ToKicadCoords( lt_arc.ArcStart ) );
642 arc->SetStroke( getStroke( lt_arc.LineWidth, lt_arc.LineStyle ) );
643 arc->Move( m_originOffset );
644
645 aSheet->LastScreen()->Append( arc );
646}
647
648
650 SCH_SHEET_PATH* aSheet )
651{
652 LTSPICE_SCHEMATIC::RECTANGLE& lt_rect = aAscfile.Rectangles[aIndex];
653 SCH_SHAPE* rectangle = new SCH_SHAPE( SHAPE_T::RECTANGLE );
654
655 rectangle->SetPosition( ToKicadCoords( lt_rect.TopLeft ) );
656 rectangle->SetEnd( ToKicadCoords( lt_rect.BotRight ) );
657 rectangle->SetStroke( getStroke( lt_rect.LineWidth, lt_rect.LineStyle ) );
658 rectangle->Move( m_originOffset );
659
660 aSheet->LastScreen()->Append( rectangle );
661}
662
663
665{
666 if( aLineWidth == LTSPICE_SCHEMATIC::LINEWIDTH::Normal )
667 return schIUScale.MilsToIU( 6 );
668 else if( aLineWidth == LTSPICE_SCHEMATIC::LINEWIDTH::Wide )
669 return schIUScale.MilsToIU( 12 );
670 else
671 return schIUScale.MilsToIU( 6 );
672}
673
674
676{
677 switch( aLineStyle )
678 {
679 case LTSPICE_SCHEMATIC::LINESTYLE::SOLID: return PLOT_DASH_TYPE::SOLID;
680 case LTSPICE_SCHEMATIC::LINESTYLE::DOT: return PLOT_DASH_TYPE::DOT;
681 case LTSPICE_SCHEMATIC::LINESTYLE::DASHDOTDOT: return PLOT_DASH_TYPE::DASHDOTDOT;
682 case LTSPICE_SCHEMATIC::LINESTYLE::DASHDOT: return PLOT_DASH_TYPE::DASHDOT;
683 case LTSPICE_SCHEMATIC::LINESTYLE::DASH: return PLOT_DASH_TYPE::DASH;
684 default: return PLOT_DASH_TYPE::SOLID;
685 }
686}
687
688
690 const LTSPICE_SCHEMATIC::LINESTYLE& aLineStyle )
691{
692 return STROKE_PARAMS( getLineWidth( aLineWidth ), getLineStyle( aLineStyle ) );
693}
694
695
697 LTSPICE_SCHEMATIC::JUSTIFICATION aJustification )
698{
699 switch( aJustification )
700 {
705 break;
706
711 break;
712
717 break;
718
723 break;
724
729 break;
730
731 default: break;
732 }
733
734 switch( aJustification )
735 {
742 break;
743
750 break;
751
752 default: break;
753 }
754
755 // Center, Left, Right aligns by first line in multiline text
756 if( wxSplit( aText->GetText(), '\n', '\0' ).size() > 1 )
757 {
758 switch( aJustification )
759 {
764 aText->Offset( VECTOR2I( 0, -aText->GetTextHeight() / 2 ) );
765 break;
766
771 aText->Offset( VECTOR2I( -aText->GetTextHeight() / 2, 0 ) );
772 break;
773
774 default: break;
775 }
776 }
777}
778
779
780SCH_TEXT* LTSPICE_SCH_PARSER::CreateSCH_TEXT( VECTOR2I aOffset, const wxString& aText,
781 int aFontSize,
782 LTSPICE_SCHEMATIC::JUSTIFICATION aJustification )
783{
784 VECTOR2I pos = ToKicadCoords( aOffset ) + m_originOffset;
785 SCH_TEXT* textItem = new SCH_TEXT( pos, aText, SCH_TEXT_T );
786
787 textItem->SetTextSize( ToKicadFontSize( aFontSize ) );
788 textItem->SetVisible( true );
789 textItem->SetMultilineAllowed( true );
790
791 setTextJustification( textItem, aJustification );
792
793 return textItem;
794}
795
796
798 SCH_SHEET_PATH* aSheet, SCH_LAYER_ID aLayer )
799{
800 SCH_LINE* segment = new SCH_LINE();
801
803 segment->SetLineStyle( PLOT_DASH_TYPE::SOLID );
804 segment->SetLayer( aLayer );
805
806 segment->SetStartPoint( ToKicadCoords( aAscfile.Wires[aIndex].Start ) + m_originOffset );
807 segment->SetEndPoint( ToKicadCoords( aAscfile.Wires[aIndex].End ) + m_originOffset );
808
809 aSheet->LastScreen()->Append( segment );
810}
811
812
813SCH_SYMBOL* LTSPICE_SCH_PARSER::CreatePowerSymbol( const VECTOR2I& aOffset, const wxString& aValue,
814 int aFontSize, SCH_SHEET_PATH* aSheet,
815 std::vector<LTSPICE_SCHEMATIC::WIRE>& aWires )
816{
817 LIB_SYMBOL* lib_symbol = new LIB_SYMBOL( wxS( "GND" ) );
818 LIB_SHAPE* shape = new LIB_SHAPE( lib_symbol, SHAPE_T::POLY );
819
820 shape->AddPoint( ToInvertedKicadCoords( { 16, 0 } ) );
821 shape->AddPoint( ToInvertedKicadCoords( { -16, 0 } ) );
822 shape->AddPoint( ToInvertedKicadCoords( { 0, 15 } ) );
823 shape->AddPoint( ToInvertedKicadCoords( { 16, 0 } ) );
824 shape->AddPoint( ToInvertedKicadCoords( { -16, 0 } ) );
825 shape->AddPoint( ToInvertedKicadCoords( { 0, 15 } ) );
826
828 PLOT_DASH_TYPE::SOLID ) );
829
830 lib_symbol->AddDrawItem( shape );
831 lib_symbol->SetPower();
832
833 LIB_PIN* pin = new LIB_PIN( lib_symbol );
834
835 pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
836 pin->SetPosition( ToInvertedKicadCoords( { 0, 0 } ) );
837 pin->SetLength( 5 );
838 pin->SetShape( GRAPHIC_PINSHAPE::LINE );
839 lib_symbol->AddDrawItem( pin );
840
841 LIB_ID libId( wxS( "ltspice" ), wxS( "GND" ) );
842 SCH_SYMBOL* sch_symbol = new SCH_SYMBOL( *lib_symbol, libId, aSheet, 1 );
843
844 sch_symbol->SetRef( aSheet, wxString::Format( wxS( "#GND%03d" ), m_powerSymbolIndex++ ) );
845 sch_symbol->GetField( REFERENCE_FIELD )->SetVisible( false );
846 sch_symbol->SetValueFieldText( wxS( "0" ) );
847 sch_symbol->GetField( VALUE_FIELD )->SetTextSize( ToKicadFontSize( aFontSize ) );
848 sch_symbol->GetField( VALUE_FIELD )->SetVisible( false );
849
850 sch_symbol->Move( ToKicadCoords( aOffset ) + m_originOffset );
851
852 for( LTSPICE_SCHEMATIC::WIRE& wire : aWires )
853 {
854 if( aOffset == wire.Start )
855 {
856 if( wire.Start.x == wire.End.x )
857 {
858 if( wire.Start.y < wire.End.y )
859 {
862 }
863 }
864 else
865 {
866 if( wire.Start.x < wire.End.x )
868 else if( wire.Start.x > wire.End.x )
870 }
871 }
872 else if( aOffset == wire.End )
873 {
874 if( wire.Start.x == wire.End.x )
875 {
876 if( wire.Start.y > wire.End.y )
877 {
880 }
881 }
882 else
883 {
884 if( wire.Start.x < wire.End.x )
886 else if( wire.Start.x > wire.End.x )
888 }
889 }
890 }
891
892 return sch_symbol;
893}
894
895
897 const wxString& aValue, int aFontSize )
898{
899 SCH_LABEL_BASE* label = nullptr;
900
901 if( aType == SCH_LABEL_T )
902 {
903 label = new SCH_LABEL();
904
905 label->SetText( aValue );
906 label->SetTextSize( ToKicadFontSize( aFontSize ) );
908 }
909 else if( aType == SCH_DIRECTIVE_LABEL_T )
910 {
911 label = new SCH_DIRECTIVE_LABEL();
912
914
915 SCH_FIELD field( { 0, 0 }, -1, label, wxS( "DATAFLAG" ) );
916 field.SetText( aValue );
917 field.SetTextSize( ToKicadFontSize( aFontSize ) );
918 field.SetVisible( true );
919
920 label->AddField( field );
921 label->AutoplaceFields( nullptr, false );
922 }
923 else
924 {
925 UNIMPLEMENTED_FOR( aType );
926 }
927
928 if( label )
929 {
930 label->SetPosition( ToKicadCoords( aOffset ) + m_originOffset );
931 label->SetVisible( true );
932 }
933
934 return label;
935}
936
937
939 SCH_SYMBOL* aSymbol, SCH_SHEET_PATH* aSheet )
940{
941 wxString libPath = m_lt_schematic->GetLTspiceDataDir().GetFullPath() + wxS( "lib/" );
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();
946 wxString value = aLTSymbol.SymAttributes[ wxS( "VALUE" ) ];
947
948 aSymbol->SetRef( aSheet, instName );
949 aSymbol->SetValueFieldText( value );
950
951 auto setupNonInferredPassive =
952 [&]( const wxString& aPrefix )
953 {
954 SCH_FIELD deviceField( { 0, 0 }, -1, aSymbol, wxS( "Sim.Device" ) );
955 deviceField.SetText( aPrefix );
956 aSymbol->AddField( deviceField );
957
958 SCH_FIELD paramsField( { 0, 0 }, -1, aSymbol, wxS( "Sim.Params" ) );
959 paramsField.SetText( aPrefix + wxS( "=${VALUE}" ) );
960 aSymbol->AddField( paramsField );
961 };
962
963 if( symbolName == wxS( "RES" ) )
964 {
965 if( !instName.StartsWith( 'R' ) )
966 setupNonInferredPassive( wxS( "R" ) );
967 }
968 else if( symbolName == wxS( "CAP" ) )
969 {
970 if( !instName.StartsWith( 'C' ) )
971 setupNonInferredPassive( wxS( "C" ) );
972 }
973 else if( symbolName == wxS( "IND" ) )
974 {
975 if( !instName.StartsWith( 'L' ) )
976 setupNonInferredPassive( wxS( "L" ) );
977 }
978 else if( symbolName == wxS( "VOLTAGE" ) || symbolName == wxS( "CURRENT" ) )
979 {
980 // inference had better work....
981 }
982 else
983 {
984 wxString libFile = aLTSymbol.SymAttributes[ wxS( "MODELFILE" ) ];
985
986 if( prefix == wxS( "X" ) )
987 {
988 // A prefix of X overrides the simulation model for other symbols (npn, etc.)
989 type = wxS( "X" );
990 }
991 else if( libFile.IsEmpty() )
992 {
993 if( type.IsEmpty() )
994 type = symbolName;
995
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" );
1004 }
1005
1006 if( libFile.IsEmpty() )
1007 libFile = m_includes[ value ];
1008
1009 if( !libFile.IsEmpty() )
1010 {
1011 SCH_FIELD libField( { 0, 0 }, -1, aSymbol, wxS( "Sim.Library" ) );
1012 libField.SetText( libFile );
1013 aSymbol->AddField( libField );
1014 }
1015
1016 SCH_FIELD nameField( { 0, 0 }, -1, aSymbol, wxS( "Sim.Name" ) );
1017 nameField.SetText( wxS( "${VALUE}" ) );
1018 aSymbol->AddField( nameField );
1019
1020 if( type == wxS( "X" ) )
1021 {
1022 SCH_FIELD deviceField( { 0, 0 }, -1, aSymbol, wxS( "Sim.Device" ) );
1023 deviceField.SetText( wxS( "SUBCKT" ) );
1024 aSymbol->AddField( deviceField );
1025 }
1026
1027 wxString spiceLine = aLTSymbol.SymAttributes[ wxS( "SPICELINE" ) ];
1028
1029 if( !spiceLine.IsEmpty() )
1030 {
1031 SCH_FIELD paramsField( { 0, 0 }, -1, aSymbol, wxS( "Sim.Params" ) );
1032 paramsField.SetText( spiceLine );
1033 aSymbol->AddField( paramsField );
1034 }
1035 }
1036
1037 for( LTSPICE_SCHEMATIC::LT_WINDOW& lt_window : aLTSymbol.Windows )
1038 {
1039 SCH_FIELD* field = nullptr;
1040
1041 switch( lt_window.WindowNumber )
1042 {
1043 case -1: /* PartNum */ break;
1044 case 0: /* InstName */ field = aSymbol->GetField( REFERENCE_FIELD ); break;
1045 case 1: /* Type */ break;
1046 case 2: /* RefName */ break;
1047 case 3: /* Value */ field = aSymbol->GetField( VALUE_FIELD ); break;
1048
1049 case 5: /* QArea */ break;
1050
1051 case 8: /* Width */ break;
1052 case 9: /* Length */ break;
1053 case 10: /* Multi */ break;
1054
1055 case 16: /* Nec */ break;
1056
1057 case 38: /* SpiceModel */ field = aSymbol->FindField( wxS( "Sim.Name" ) ); break;
1058 case 39: /* SpiceLine */ field = aSymbol->FindField( wxS( "Sim.Params" ) ); break;
1059 case 40: /* SpiceLine2 */ break;
1060
1061 /*
1062 47 Def_Sub
1063
1064 50 Digital_Timing_Model
1065 51 Digital_Extracts
1066 52 Digital_IO_Model
1067 53 Digital_Line
1068 54 Digital_Primitive
1069 55 Digital_MNTYMXDLY
1070 56 Digital_IO_LEVEL
1071 57 Digital_StdCell
1072 58 Digital_File
1073
1074 105 Cell
1075 106 W/L
1076 107 PSIZE
1077 108 NSIZE
1078 109 sheets
1079 110 sh#
1080 111 Em_Scale
1081 112 Epi
1082 113 Sinker
1083 114 Multi5
1084
1085 118 AQ
1086 119 AQSUB
1087 120 ZSIZE
1088 121 ESR
1089 123 Value2
1090 124 COUPLE
1091 125 Voltage
1092 126 Area1
1093 127 Area2
1094 128 Area3
1095 129 Area4
1096 130 Multi1
1097 131 Multi2
1098 132 Multi3
1099 133 Multi4
1100 134 DArea
1101 135 DPerim
1102 136 CArea
1103 137 CPerim
1104 138 Shrink
1105 139 Gate_Resize
1106
1107 142 BP
1108 143 BN
1109 144 Sim_Level
1110
1111 146 G_Voltage
1112
1113 150 SpiceLine3
1114
1115 153 D_VOLTAGES
1116
1117 156 Version
1118 157 Comment
1119 158 XDef_Sub
1120 159 LVS_Area
1121
1122 162 User1
1123 163 User2
1124 164 User3
1125 165 User4
1126 166 User5
1127 167 Root
1128 168 Class
1129 169 Geometry
1130 170 WL_Delimiter
1131
1132 175 T1
1133 176 T2
1134
1135 184 DsgnName
1136 185 Designer
1137
1138 190 RTN
1139 191 PWR
1140 192 BW
1141
1142 201 CAPROWS
1143 202 CAPCOLS
1144 203 NF
1145 204 SLICES
1146 205 CUR
1147 206 TEMPRISE
1148 207 STRIPS
1149 208 WEM
1150 209 LEM
1151 210 BASES
1152 211 COLS
1153 212 XDef_Tub
1154 */
1155 default: break;
1156 }
1157
1158 if( field )
1159 {
1160 field->SetPosition( ToKicadCoords( lt_window.Position ) );
1161 field->SetTextSize( ToKicadFontSize( lt_window.FontSize ) );
1162
1163 if( lt_window.FontSize == 0 )
1164 field->SetVisible( false );
1165
1166 setTextJustification( field, lt_window.Justification );
1167 }
1168 }
1169}
1170
1171
1173 LIB_SHAPE* aRectangle )
1174{
1175 LTSPICE_SCHEMATIC::RECTANGLE& lt_rect = aLTSymbol.Rectangles[aIndex];
1176
1177 aRectangle->SetPosition( ToInvertedKicadCoords( lt_rect.BotRight ) );
1178 aRectangle->SetEnd( ToInvertedKicadCoords( lt_rect.TopLeft ) );
1179 aRectangle->SetStroke( getStroke( lt_rect.LineWidth, lt_rect.LineStyle ) );
1180
1181 if( aLTSymbol.SymAttributes[wxS( "Prefix" )] == wxS( "X" ) )
1182 aRectangle->SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR );
1183}
1184
1185
1187 SCH_SHEET_PATH* aSheet )
1188{
1189 LTSPICE_SCHEMATIC::RECTANGLE& lt_rect = aLTSymbol.Rectangles[aIndex];
1190 SCH_SHAPE* rectangle = new SCH_SHAPE( SHAPE_T::RECTANGLE );
1191
1192 rectangle->SetPosition( ToInvertedKicadCoords( lt_rect.BotRight ) );
1193 rectangle->SetEnd( ToInvertedKicadCoords( lt_rect.TopLeft ) );
1194 rectangle->SetStroke( getStroke( lt_rect.LineWidth, lt_rect.LineStyle ) );
1195
1196 rectangle->Move( aLTSymbol.Offset );
1197 RotateMirrorShape( aLTSymbol, rectangle );
1198
1199 aSheet->LastScreen()->Append( rectangle );
1200}
1201
1202
1204 LIB_PIN* aPin )
1205{
1206 LTSPICE_SCHEMATIC::LT_PIN& lt_pin = aLTSymbol.Pins[aIndex];
1207 wxString device = aLTSymbol.Name.Lower();
1208
1209 if( aLTSymbol.Pins.size() == 2 && ( device == wxS( "res" )
1210 || device == wxS( "cap" )
1211 || device == wxS( "ind" ) ) )
1212 {
1213 // drop A/B pin names from simple LRCs as they're not terribly useful (and prevent
1214 // other pin names on the net from driving the net name).
1215 }
1216 else
1217 {
1218 aPin->SetName( lt_pin.PinAttribute[ wxS( "PinName" ) ] );
1219
1221 aPin->SetNameTextSize( 0 );
1222 }
1223
1224 aPin->SetNumber( wxString::Format( wxS( "%d" ), aIndex + 1 ) );
1225 aPin->SetType( ELECTRICAL_PINTYPE::PT_PASSIVE );
1227 aPin->SetLength( 5 );
1228 aPin->SetShape( GRAPHIC_PINSHAPE::LINE );
1229
1230 switch( lt_pin.PinJustification )
1231 {
1234 aPin->SetOrientation( PIN_ORIENTATION::PIN_RIGHT );
1235 break;
1236
1239 aPin->SetOrientation( PIN_ORIENTATION::PIN_LEFT );
1240 break;
1241
1244 aPin->SetOrientation( PIN_ORIENTATION::PIN_UP );
1245 break;
1246
1249 aPin->SetOrientation( PIN_ORIENTATION::PIN_DOWN );
1250 break;
1251
1252 default: break;
1253 }
1254}
1255
1256
1258 LIB_SHAPE* aArc )
1259{
1260 LTSPICE_SCHEMATIC::ARC& lt_arc = aLTSymbol.Arcs[aIndex];
1261
1262 aArc->SetCenter( ToInvertedKicadCoords( ( lt_arc.TopLeft + lt_arc.BotRight ) / 2 ) );
1263 aArc->SetEnd( ToInvertedKicadCoords( lt_arc.ArcEnd ) );
1264 aArc->SetStart( ToInvertedKicadCoords( lt_arc.ArcStart ) );
1265 aArc->SetStroke( getStroke( lt_arc.LineWidth, lt_arc.LineStyle ) );
1266}
1267
1268
1270 SCH_SHEET_PATH* aSheet )
1271{
1272 LTSPICE_SCHEMATIC::ARC& lt_arc = aLTSymbol.Arcs[aIndex];
1273 SCH_SHAPE* arc = new SCH_SHAPE( SHAPE_T::ARC );
1274
1275 arc->SetCenter( ToInvertedKicadCoords( ( lt_arc.TopLeft + lt_arc.BotRight ) / 2 ) );
1276 arc->SetEnd( ToInvertedKicadCoords( lt_arc.ArcEnd ) );
1277 arc->SetStart( ToInvertedKicadCoords( lt_arc.ArcStart ) );
1278 arc->SetStroke( getStroke( lt_arc.LineWidth, lt_arc.LineStyle ) );
1279
1280 arc->Move( ToKicadCoords( aLTSymbol.Offset ) + m_originOffset );
1281 RotateMirrorShape( aLTSymbol, arc );
1282
1283 aSheet->LastScreen()->Append( arc );
1284}
1285
1286
1288 SCH_SHEET_PATH* aSheet )
1289{
1290 LTSPICE_SCHEMATIC::CIRCLE& lt_circle = aLTSymbol.Circles[aIndex];
1291 SCH_SHAPE* circle = new SCH_SHAPE( SHAPE_T::CIRCLE );
1292
1293 VECTOR2I c = ( lt_circle.TopLeft + lt_circle.BotRight ) / 2;
1294 int r = ( lt_circle.TopLeft.x - lt_circle.BotRight.x ) / 2;
1295
1296 circle->SetPosition( ToInvertedKicadCoords( c ) );
1297 circle->SetEnd( ToInvertedKicadCoords( c ) + VECTOR2I( abs( ToKicadCoords( r ) ), 0 ) );
1298 circle->SetStroke( getStroke( lt_circle.LineWidth, lt_circle.LineStyle ) );
1299
1300 circle->Move( aLTSymbol.Offset );
1301 RotateMirrorShape( aLTSymbol, circle );
1302
1303 aSheet->LastScreen()->Append( circle );
1304}
1305
1306
1308 LIB_SHAPE* aCircle )
1309{
1310 LTSPICE_SCHEMATIC::CIRCLE& lt_circle = aLTSymbol.Circles[aIndex];
1311
1312 VECTOR2I c = ( lt_circle.TopLeft + lt_circle.BotRight ) / 2;
1313 int r = ( lt_circle.TopLeft.x - lt_circle.BotRight.x ) / 2;
1314
1315 aCircle->SetPosition( ToInvertedKicadCoords( c ) );
1316 aCircle->SetEnd( ToInvertedKicadCoords( c ) + VECTOR2I( abs( ToKicadCoords( r ) ), 0 ) );
1317 aCircle->SetStroke( getStroke( lt_circle.LineWidth, lt_circle.LineStyle ) );
1318}
1319
1320
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
void SetOrigin(const Vec &pos)
Definition: box2.h:203
const Vec & GetOrigin() const
Definition: box2.h:184
void Offset(coord_type dx, coord_type dy)
Definition: box2.h:225
const Vec GetCenter() const
Definition: box2.h:196
coord_type GetTop() const
Definition: box2.h:195
coord_type GetHeight() const
Definition: box2.h:189
coord_type GetWidth() const
Definition: box2.h:188
void SetSize(const Vec &size)
Definition: box2.h:214
coord_type GetLeft() const
Definition: box2.h:194
const Vec & GetSize() const
Definition: box2.h:180
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:589
void SetCenter(const VECTOR2I &aCenter)
Definition: eda_shape.cpp:540
void SetStart(const VECTOR2I &aStart)
Definition: eda_shape.h:128
void SetEnd(const VECTOR2I &aEnd)
Definition: eda_shape.h:153
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:101
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:80
int GetTextHeight() const
Definition: eda_text.h:213
void SetTextSize(VECTOR2I aNewSize)
Definition: eda_text.cpp:355
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:95
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:257
void Offset(const VECTOR2I &aOffset)
Definition: eda_text.cpp:416
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:226
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:180
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:202
void SetMultilineAllowed(bool aAllow)
Definition: eda_text.cpp:241
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:249
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
void SetShape(GRAPHIC_PINSHAPE aShape)
Definition: lib_pin.h:72
void SetPosition(const VECTOR2I &aPos) override
Definition: lib_pin.h:233
void SetName(const wxString &aName)
Definition: lib_pin.h:108
void SetNameTextSize(int aSize)
Definition: lib_pin.h:129
void SetType(ELECTRICAL_PINTYPE aType)
Definition: lib_pin.h:85
void SetOrientation(PIN_ORIENTATION aOrientation)
Definition: lib_pin.h:69
void SetNumber(const wxString &aNumber)
Definition: lib_pin.h:119
void SetLength(int aLength)
Definition: lib_pin.h:75
void SetStroke(const STROKE_PARAMS &aStroke)
Definition: lib_shape.h:58
void AddPoint(const VECTOR2I &aPosition)
Definition: lib_shape.cpp:505
void SetPosition(const VECTOR2I &aPosition) override
Definition: lib_shape.h:91
Define a library symbol object.
Definition: lib_symbol.h:99
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: lib_symbol.h:264
void SetPower()
Definition: lib_symbol.cpp:728
void SetShowPinNumbers(bool aShow)
Set or clear the pin number visibility flag.
Definition: lib_symbol.h:676
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.
Definition: page_info.h:161
void SetSize(const VECTOR2I &aSize)
Definition: sch_bus_entry.h:74
Class for a wire to bus entry.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:52
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_field.cpp:1233
void SetText(const wxString &aText) override
Definition: sch_field.cpp:982
void SetLayer(SCH_LAYER_ID aLayer)
Set the layer this item is on.
Definition: sch_item.h:264
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_label.cpp:417
void AddField(const SCH_FIELD &aField)
Definition: sch_label.h:185
void SetShape(LABEL_FLAG_SHAPE aShape)
Definition: sch_label.h:148
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_label.cpp:410
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual) override
Definition: sch_label.cpp:582
virtual void SetSpinStyle(SPIN_STYLE aSpinStyle)
Definition: sch_label.cpp:337
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:40
void SetStartPoint(const VECTOR2I &aPosition)
Definition: sch_line.h:141
void SetLineWidth(const int aSize)
Definition: sch_line.cpp:315
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_line.cpp:150
void SetLineStyle(const PLOT_DASH_TYPE aStyle)
Definition: sch_line.cpp:286
virtual void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: sch_line.h:181
void SetEndPoint(const VECTOR2I &aPosition)
Definition: sch_line.h:146
const PAGE_INFO & GetPageSettings() const
Definition: sch_screen.h:131
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Definition: sch_screen.cpp:152
void SetPosition(const VECTOR2I &aPos) override
Definition: sch_shape.h:78
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
Definition: sch_shape.cpp:96
void Move(const VECTOR2I &aOffset) override
Move the item by aMoveVector to a new position.
Definition: sch_shape.cpp:69
void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: sch_shape.cpp:63
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
Definition: sch_shape.cpp:102
void Rotate(const VECTOR2I &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_shape.cpp:108
void AddPoint(const VECTOR2I &aPosition)
Definition: sch_shape.cpp:494
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()
Schematic symbol object.
Definition: sch_symbol.h:81
void SetValueFieldText(const wxString &aValue)
Definition: sch_symbol.cpp:891
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.
Definition: sch_symbol.h:623
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:913
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
Definition: sch_symbol.cpp:762
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.
Definition: sch_symbol.cpp:988
Simple container to manage line stroke parameters.
Definition: stroke_params.h:81
static constexpr EDA_ANGLE & ANGLE_HORIZONTAL
Definition: eda_angle.h:433
static constexpr EDA_ANGLE & ANGLE_VERTICAL
Definition: eda_angle.h:434
SCH_LAYER_ID
Eeschema drawing layers.
Definition: layer_ids.h:346
LABEL_FLAG_SHAPE getLabelShape(LTSPICE_SCHEMATIC::POLARITY aPolarity)
#define UNIMPLEMENTED_FOR(type)
Definition: macros.h:96
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:99
@ SYM_ROTATE_CLOCKWISE
@ SYM_ROTATE_COUNTERCLOCKWISE
@ SYM_MIRROR_Y
@ SYM_ORIENT_180
@ SYM_MIRROR_X
@ SYM_ORIENT_0
LABEL_FLAG_SHAPE
Definition: sch_label.h:91
@ L_BIDI
Definition: sch_label.h:94
@ L_OUTPUT
Definition: sch_label.h:93
@ L_INPUT
Definition: sch_label.h:92
PLOT_DASH_TYPE
Dashed line types.
Definition: stroke_params.h:48
constexpr int IUToMils(int iu) const
Definition: base_units.h:100
const double IU_PER_MILS
Definition: base_units.h:78
constexpr int MilsToIU(int mils) const
Definition: base_units.h:94
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
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< CIRCLE > Circles
A 4-sided polygon with opposite equal sides, used in representing shapes.
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".
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_CENTER
@ GR_TEXT_V_ALIGN_TOP
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ SCH_DIRECTIVE_LABEL_T
Definition: typeinfo.h:153
@ SCH_LABEL_T
Definition: typeinfo.h:150
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:152
@ SCH_TEXT_T
Definition: typeinfo.h:149
T rescale(T aNumerator, T aValue, T aDenominator)
Scale a number (value) by rational (numerator/denominator).
Definition: util.h:118
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588