KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_easyeda_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) 2023 Alex Shvartzkop <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <font/font.h>
22#include "sch_easyeda_parser.h"
23
24#include <sch_io/sch_io_mgr.h>
25#include <schematic.h>
26#include <sch_sheet.h>
27#include <sch_line.h>
28#include <sch_no_connect.h>
29#include <sch_label.h>
30#include <sch_junction.h>
31#include <sch_edit_frame.h>
32#include <sch_shape.h>
33#include <sch_bitmap.h>
34#include <reporter.h>
35#include <string_utils.h>
36#include <bezier_curves.h>
37#include <wx/base64.h>
38#include <wx/mstream.h>
39#include <core/map_helpers.h>
40#include <gfx_import_utils.h>
44
45
46// clang-format off
47static const std::vector<wxString> c_attributesWhitelist = { "Datasheet",
48 "Manufacturer Part",
49 "Manufacturer",
50 "BOM_Manufacturer Part",
51 "BOM_Manufacturer",
52 "Supplier Part",
53 "Supplier",
54 "BOM_Supplier Part",
55 "BOM_Supplier",
56 "LCSC Part Name" };
57// clang-format on
58
59
61 REPORTER* aReporter )
62{
63 m_schematic = aSchematic;
64 m_reporter = aReporter;
65}
66
67
68// Fields past the text are optional and some exports omit them
69static constexpr size_t TEXT_MIN_FIELDS = 13;
70
71
72static wxString optionalField( const wxArrayString& aArr, size_t aIndex )
73{
74 return aIndex < aArr.size() ? aArr[aIndex] : wxString();
75}
76
77
78bool SCH_EASYEDA_PARSER::checkTextFields( const wxArrayString& aArr )
79{
80 if( aArr.size() >= TEXT_MIN_FIELDS )
81 return true;
82
83 if( m_reporter )
84 {
85 m_reporter->Report( wxString::Format( _( "Skipped a text with %d of %d fields." ), (int) aArr.size(),
86 (int) TEXT_MIN_FIELDS ),
88 }
89
90 return false;
91}
92
93
97
98
99static std::vector<std::vector<wxString>> RegexMatchAll( wxRegEx& aRegex, const wxString& aString )
100{
101 std::vector<std::vector<wxString>> allMatches;
102
103 size_t start = 0;
104 size_t len = 0;
105 size_t prevstart = 0;
106
107 wxString str = aString;
108
109 while( aRegex.Matches( str ) )
110 {
111 std::vector<wxString> matches;
112 aRegex.GetMatch( &start, &len );
113
114 for( size_t i = 0; i < aRegex.GetMatchCount(); i++ )
115 matches.emplace_back( aRegex.GetMatch( str, i ) );
116
117 allMatches.emplace_back( matches );
118
119 prevstart = start + len;
120 str = str.Mid( prevstart );
121 }
122
123 return allMatches;
124}
125
126
134static std::vector<std::pair<wxString, std::vector<double>>>
135ParseImageTransform( const wxString& transformData )
136{
137 wxRegEx transformRegex( "(rotate|translate|scale)\\(([\\w\\s,\\.\\-]*)\\)", wxRE_ICASE );
138 std::vector<std::vector<wxString>> allMatches = RegexMatchAll( transformRegex, transformData );
139
140 std::vector<std::pair<wxString, std::vector<double>>> transformCmds;
141
142 for( int cmdId = allMatches.size() - 1; cmdId >= 0; cmdId-- )
143 {
144 std::vector<wxString>& groups = allMatches[cmdId];
145
146 if( groups.size() != 3 )
147 continue;
148
149 const wxString& cmdName = groups[1].Strip( wxString::both ).Lower();
150 const wxString& cmdArgsStr = groups[2];
151
152 wxArrayString cmdParts = wxSplit( cmdArgsStr, ',', '\0' );
153 std::vector<double> cmdArgs;
154
155 for( const wxString& cmdPart : cmdParts )
156 {
157 double arg = 0;
158 wxASSERT( cmdPart.Strip( wxString::both ).ToCDouble( &arg ) );
159
160 cmdArgs.push_back( arg );
161 }
162
163 transformCmds.emplace_back( cmdName, cmdArgs );
164 }
165
166 return transformCmds;
167}
168
169
170static LIB_ID EasyEdaToKiCadLibID( const wxString& aLibName, const wxString& aLibReference )
171{
172 wxString libReference = EscapeString( aLibReference, CTX_LIBID );
173
174 wxString key = !aLibName.empty() ? ( aLibName + ':' + libReference ) : libReference;
175
176 LIB_ID libId;
177 libId.Parse( key, true );
178
179 return libId;
180}
181
182
183static LINE_STYLE ConvertStrokeStyle( const wxString& aStyle )
184{
185 if( aStyle == wxS( "0" ) )
186 return LINE_STYLE::SOLID;
187 else if( aStyle == wxS( "1" ) )
188 return LINE_STYLE::DASH;
189 else if( aStyle == wxS( "2" ) )
190 return LINE_STYLE::DOT;
191
192 return LINE_STYLE::DEFAULT;
193}
194
195
196static ELECTRICAL_PINTYPE ConvertElecType( const wxString& aType )
197{
198 if( aType == wxS( "0" ) )
200 else if( aType == wxS( "1" ) )
202 else if( aType == wxS( "2" ) )
204 else if( aType == wxS( "3" ) )
206 else if( aType == wxS( "4" ) )
208
210}
211
212
214 REPORTER* aReporter )
215{
217 {
219 line1->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
220 line1->AddPoint( { 0, 0 } );
221 line1->AddPoint( { 0, schIUScale.MilsToIU( 50 ) } );
222 aKsymbol->AddDrawItem( line1, false );
223
225 {
227 circle->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 5 ), LINE_STYLE::SOLID ) );
228 circle->SetPosition( { schIUScale.MilsToIU( 0 ), schIUScale.MilsToIU( 75 ) } );
229 circle->SetEnd( circle->GetPosition() + VECTOR2I( schIUScale.MilsToIU( 25 ), 0 ) );
230 aKsymbol->AddDrawItem( circle, false );
231 }
232 else
233 {
235 line2->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
236 line2->AddPoint( { schIUScale.MilsToIU( -25 ), schIUScale.MilsToIU( 50 ) } );
237 line2->AddPoint( { schIUScale.MilsToIU( 25 ), schIUScale.MilsToIU( 50 ) } );
238 line2->AddPoint( { schIUScale.MilsToIU( 0 ), schIUScale.MilsToIU( 100 ) } );
239 line2->AddPoint( { schIUScale.MilsToIU( -25 ), schIUScale.MilsToIU( 50 ) } );
240 aKsymbol->AddDrawItem( line2, false );
241 }
242
243 return { 0, schIUScale.MilsToIU( 150 ) };
244 }
245 else if( aStyle == EASYEDA::POWER_FLAG_STYLE::WAVE )
246 {
248 line->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
249 line->AddPoint( { 0, 0 } );
250 line->AddPoint( { 0, schIUScale.MilsToIU( 72 ) } );
251 aKsymbol->AddDrawItem( line, false );
252
254 bezier->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 5 ), LINE_STYLE::SOLID ) );
255 bezier->SetStart( { schIUScale.MilsToIU( 30 ), schIUScale.MilsToIU( 50 ) } );
256 bezier->SetBezierC1( { schIUScale.MilsToIU( 30 ), schIUScale.MilsToIU( 87 ) } );
257 bezier->SetBezierC2( { schIUScale.MilsToIU( -30 ), schIUScale.MilsToIU( 63 ) } );
258 bezier->SetEnd( { schIUScale.MilsToIU( -30 ), schIUScale.MilsToIU( 100 ) } );
259 aKsymbol->AddDrawItem( bezier, false );
260
261 return { 0, schIUScale.MilsToIU( 150 ) };
262 }
267 {
269 line1->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
270 line1->AddPoint( { 0, 0 } );
271 line1->AddPoint( { 0, schIUScale.MilsToIU( 100 ) } );
272 aKsymbol->AddDrawItem( line1, false );
273
275 {
277 line2->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
278 line2->AddPoint( { schIUScale.MilsToIU( -100 ), schIUScale.MilsToIU( 100 ) } );
279 line2->AddPoint( { schIUScale.MilsToIU( 100 ), schIUScale.MilsToIU( 100 ) } );
280 aKsymbol->AddDrawItem( line2, false );
281
283 line3->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
284 line3->AddPoint( { schIUScale.MilsToIU( -70 ), schIUScale.MilsToIU( 120 ) } );
285 line3->AddPoint( { schIUScale.MilsToIU( 70 ), schIUScale.MilsToIU( 120 ) } );
286 aKsymbol->AddDrawItem( line3, false );
287
289 line4->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
290 line4->AddPoint( { schIUScale.MilsToIU( -40 ), schIUScale.MilsToIU( 140 ) } );
291 line4->AddPoint( { schIUScale.MilsToIU( 40 ), schIUScale.MilsToIU( 140 ) } );
292 aKsymbol->AddDrawItem( line4, false );
293
295 line5->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
296 line5->AddPoint( { schIUScale.MilsToIU( -10 ), schIUScale.MilsToIU( 160 ) } );
297 line5->AddPoint( { schIUScale.MilsToIU( 10 ), schIUScale.MilsToIU( 160 ) } );
298 aKsymbol->AddDrawItem( line5, false );
299 }
301 {
303 line2->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
304 line2->AddPoint( { schIUScale.MilsToIU( -100 ), schIUScale.MilsToIU( 100 ) } );
305 line2->AddPoint( { schIUScale.MilsToIU( 100 ), schIUScale.MilsToIU( 100 ) } );
306 line2->AddPoint( { schIUScale.MilsToIU( 0 ), schIUScale.MilsToIU( 160 ) } );
307 line2->AddPoint( { schIUScale.MilsToIU( -100 ), schIUScale.MilsToIU( 100 ) } );
308 aKsymbol->AddDrawItem( line2, false );
309 }
310 else if( aStyle == EASYEDA::POWER_FLAG_STYLE::EARTH )
311 {
313 line2->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
314 line2->AddPoint( { schIUScale.MilsToIU( -150 ), schIUScale.MilsToIU( 200 ) } );
315 line2->AddPoint( { schIUScale.MilsToIU( -100 ), schIUScale.MilsToIU( 100 ) } );
316 line2->AddPoint( { schIUScale.MilsToIU( 100 ), schIUScale.MilsToIU( 100 ) } );
317 line2->AddPoint( { schIUScale.MilsToIU( 50 ), schIUScale.MilsToIU( 200 ) } );
318 aKsymbol->AddDrawItem( line2, false );
319
321 line3->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
322 line3->AddPoint( { schIUScale.MilsToIU( 0 ), schIUScale.MilsToIU( 100 ) } );
323 line3->AddPoint( { schIUScale.MilsToIU( -50 ), schIUScale.MilsToIU( 200 ) } );
324 aKsymbol->AddDrawItem( line3, false );
325 }
326 else // EASYEDA::POWER_FLAG_STYLE::GOST_ARROW
327 {
329 line2->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
330 line2->AddPoint( { schIUScale.MilsToIU( -25 ), schIUScale.MilsToIU( 50 ) } );
331 line2->AddPoint( { schIUScale.MilsToIU( 0 ), schIUScale.MilsToIU( 100 ) } );
332 line2->AddPoint( { schIUScale.MilsToIU( 25 ), schIUScale.MilsToIU( 50 ) } );
333 aKsymbol->AddDrawItem( line2, false );
334
335 return { 0, schIUScale.MilsToIU( 150 ) }; // special case
336 }
337
338 return { 0, schIUScale.MilsToIU( 250 ) };
339 }
342 {
344 line1->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
345 line1->AddPoint( { 0, 0 } );
346 line1->AddPoint( { 0, schIUScale.MilsToIU( 160 ) } );
347 aKsymbol->AddDrawItem( line1, false );
348
350 line2->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
351 line2->AddPoint( { schIUScale.MilsToIU( -100 ), schIUScale.MilsToIU( 160 ) } );
352 line2->AddPoint( { schIUScale.MilsToIU( 100 ), schIUScale.MilsToIU( 160 ) } );
353 aKsymbol->AddDrawItem( line2, false );
354
356 line3->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
357 line3->AddPoint( { schIUScale.MilsToIU( -60 ), schIUScale.MilsToIU( 200 ) } );
358 line3->AddPoint( { schIUScale.MilsToIU( 60 ), schIUScale.MilsToIU( 200 ) } );
359 aKsymbol->AddDrawItem( line3, false );
360
362 line4->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
363 line4->AddPoint( { schIUScale.MilsToIU( -20 ), schIUScale.MilsToIU( 240 ) } );
364 line4->AddPoint( { schIUScale.MilsToIU( 20 ), schIUScale.MilsToIU( 240 ) } );
365 aKsymbol->AddDrawItem( line4, false );
366
368 return { 0, schIUScale.MilsToIU( -300 ) };
369
371 circle->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
372 circle->SetPosition( { schIUScale.MilsToIU( 0 ), schIUScale.MilsToIU( 160 ) } );
373 circle->SetEnd( circle->GetPosition() + VECTOR2I( schIUScale.MilsToIU( 120 ), 0 ) );
374 aKsymbol->AddDrawItem( circle, false );
375
376 return { 0, schIUScale.MilsToIU( 350 ) };
377 }
378 else if( aStyle == EASYEDA::POWER_FLAG_STYLE::GOST_BAR )
379 {
381 line1->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
382 line1->AddPoint( { 0, 0 } );
383 line1->AddPoint( { 0, schIUScale.MilsToIU( 200 ) } );
384 aKsymbol->AddDrawItem( line1, false );
385
387 line2->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
388 line2->AddPoint( { schIUScale.MilsToIU( -100 ), schIUScale.MilsToIU( 200 ) } );
389 line2->AddPoint( { schIUScale.MilsToIU( 100 ), schIUScale.MilsToIU( 200 ) } );
390 aKsymbol->AddDrawItem( line2, false );
391
392 return { 0, schIUScale.MilsToIU( 250 ) };
393 }
394 else
395 {
396 if( aStyle != EASYEDA::POWER_FLAG_STYLE::BAR )
397 {
398 aReporter->Report( _( "Power Port with unknown style imported as 'Bar' type." ),
400 }
401
403 line1->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
404 line1->AddPoint( { 0, 0 } );
405 line1->AddPoint( { 0, schIUScale.MilsToIU( 100 ) } );
406 aKsymbol->AddDrawItem( line1, false );
407
409 line2->SetStroke( STROKE_PARAMS( schIUScale.MilsToIU( 10 ), LINE_STYLE::SOLID ) );
410 line2->AddPoint( { schIUScale.MilsToIU( -50 ), schIUScale.MilsToIU( 100 ) } );
411 line2->AddPoint( { schIUScale.MilsToIU( 50 ), schIUScale.MilsToIU( 100 ) } );
412 aKsymbol->AddDrawItem( line2, false );
413
414 return { 0, schIUScale.MilsToIU( 150 ) };
415 }
416}
417
418
420 std::map<wxString, wxString> paramMap,
421 wxArrayString aShapes )
422{
423 for( wxString shapeStr : aShapes )
424 {
425 wxArrayString arr = wxSplit( shapeStr, '~', '\0' );
426
427 wxString elType = arr[0];
428 if( elType == wxS( "PL" ) || elType == wxS( "PG" ) )
429 {
430 wxArrayString ptArr = wxSplit( arr[1], ' ', '\0' );
431 wxString strokeColor = arr[2];
432 double lineWidth = Convert( arr[3] );
433 LINE_STYLE strokeStyle = ConvertStrokeStyle( arr[4] );
434 wxString fillColor = arr[5].Lower();
435 //bool locked = arr[7] != wxS( "0" );
436
438
439 for( size_t i = 1; i < ptArr.size(); i += 2 )
440 {
441 chain.Append(
442 RelPosSym( VECTOR2I( Convert( ptArr[i - 1] ), Convert( ptArr[i] ) ) ) );
443 }
444
445 auto line = std::make_unique<SCH_SHAPE>( SHAPE_T::POLY, LAYER_DEVICE );
446
447 if( elType == wxS( "PG" ) )
448 chain.SetClosed( true );
449
450 if( chain.PointCount() < 2 )
451 continue;
452
453 for( int i = 0; i < chain.PointCount(); i++ )
454 line->AddPoint( chain.CPoint( i ) );
455
456 if( chain.IsClosed() )
457 line->AddPoint( chain.CPoint( 0 ) );
458
459 line->SetUnit( 0 );
460 line->SetStroke( STROKE_PARAMS( ScaleSize( lineWidth ), strokeStyle ) );
461
462 if( fillColor != wxS( "none" ) )
463 {
464 line->SetFilled( true );
465
466 if( fillColor == strokeColor )
467 line->SetFillMode( FILL_T::FILLED_SHAPE );
468 else
469 line->SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR );
470 }
471
472 aSymbol->AddDrawItem( line.release() );
473 }
474 else if( elType == wxS( "PT" ) ) // Freedraw
475 {
476 wxString pointsData = arr[1];
477 wxString strokeColor = arr[2];
478 double lineWidth = Convert( arr[3] );
479 LINE_STYLE strokeStyle = ConvertStrokeStyle( arr[4] );
480 wxString fillColor = arr[5].Lower();
481 //bool locked = arr[7] != wxS( "0" );
482
483 std::vector<SHAPE_LINE_CHAIN> lineChains =
484 ParseLineChains( pointsData, schIUScale.MilsToIU( 10 ), false );
485
486 for( SHAPE_LINE_CHAIN outline : lineChains )
487 {
488 auto shape = std::make_unique<SCH_SHAPE>( SHAPE_T::POLY, LAYER_DEVICE );
489
490 if( outline.IsClosed() )
491 outline.Append( outline.CPoint( 0 ), true );
492
493 for( const VECTOR2I& pt : outline.CPoints() )
494 shape->AddPoint( pt );
495
496 shape->SetUnit( 0 );
497 shape->SetStroke( STROKE_PARAMS( ScaleSize( lineWidth ), strokeStyle ) );
498
499 if( fillColor != wxS( "none" ) )
500 {
501 shape->SetFilled( true );
502
503 if( fillColor == strokeColor )
504 shape->SetFillMode( FILL_T::FILLED_SHAPE );
505 else
506 shape->SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR );
507 }
508
509 aSymbol->AddDrawItem( shape.release() );
510 }
511 }
512 else if( elType == wxS( "Pimage" ) )
513 {
514 //double angle = Convert( arr[4] ); // TODO
515 VECTOR2D start( Convert( arr[6] ), Convert( arr[7] ) );
516 VECTOR2D size( Convert( arr[8] ), Convert( arr[9] ) );
517 wxString imageUrl = arr[10];
518
519 if( imageUrl.BeforeFirst( ':' ) == wxS( "data" ) )
520 {
521 wxArrayString paramsArr =
522 wxSplit( imageUrl.AfterFirst( ':' ).BeforeFirst( ',' ), ';', '\0' );
523
524 wxString data = imageUrl.AfterFirst( ',' );
525
526 if( paramsArr.size() > 0 )
527 {
528 wxString mimeType = paramsArr[0];
529 wxMemoryBuffer buf = wxBase64Decode( data );
530
531 if( mimeType == wxS( "image/svg+xml" ) )
532 {
533 VECTOR2D offset = RelPosSym( start );
534
535 SVG_IMPORT_PLUGIN svgImportPlugin;
536 GRAPHICS_IMPORTER_LIB_SYMBOL libsymImporter( aSymbol, 0 );
537
538 svgImportPlugin.SetImporter( &libsymImporter );
539 svgImportPlugin.LoadFromMemory( buf );
540
541 VECTOR2D imSize( svgImportPlugin.GetImageWidth(),
542 svgImportPlugin.GetImageHeight() );
543
544 VECTOR2D pixelScale( schIUScale.IUTomm( ScaleSize( size.x ) ) / imSize.x,
545 schIUScale.IUTomm( ScaleSize( size.y ) ) / imSize.y );
546
547 libsymImporter.SetScale( pixelScale );
548
549 VECTOR2D offsetMM( schIUScale.IUTomm( offset.x ),
550 schIUScale.IUTomm( offset.y ) );
551
552 libsymImporter.SetImportOffsetMM( offsetMM );
553
554 svgImportPlugin.Import();
555
556 for( std::unique_ptr<EDA_ITEM>& item : libsymImporter.GetItems() )
557 aSymbol->AddDrawItem( static_cast<SCH_ITEM*>( item.release() ) );
558 }
559 else
560 {
561 wxMemoryInputStream memis( buf.GetData(), buf.GetDataLen() );
562
563 wxImage::SetDefaultLoadFlags( wxImage::GetDefaultLoadFlags()
564 & ~wxImage::Load_Verbose );
565 wxImage img;
566 if( img.LoadFile( memis, mimeType ) )
567 {
568 int dimMul = img.GetWidth() * img.GetHeight();
569 double maxPixels = 30000;
570
571 if( dimMul > maxPixels )
572 {
573 double scale = sqrt( maxPixels / dimMul );
574 img.Rescale( img.GetWidth() * scale, img.GetHeight() * scale );
575 }
576
577 VECTOR2D pixelScale( ScaleSize( size.x ) / img.GetWidth(),
578 ScaleSize( size.y ) / img.GetHeight() );
579
580 ConvertImageToLibShapes( aSymbol, 0, img, pixelScale,
581 RelPosSym( start ) );
582 }
583 }
584 }
585 }
586 }
587 else if( elType == wxS( "A" ) )
588 {
589 wxString data = arr[1];
590 wxString strokeColor = arr[3];
591 double lineWidth = Convert( arr[4] );
592 LINE_STYLE strokeStyle = ConvertStrokeStyle( arr[5] );
593 wxString fillColor = arr[6].Lower();
594 //bool locked = arr[8] != wxS( "0" );
595
596 std::vector<SHAPE_LINE_CHAIN> chains =
597 ParseLineChains( data, schIUScale.MilsToIU( 10 ), false );
598
599 auto transform = []( VECTOR2I aVec )
600 {
601 return VECTOR2I( aVec.x, aVec.y );
602 };
603
604 for( const SHAPE_LINE_CHAIN& chain : chains )
605 {
606 for( int i = 0; i <= chain.PointCount() && i != -1; i = chain.NextShape( i ) )
607 {
608 if( chain.IsArcStart( i ) )
609 {
610 SHAPE_ARC arc = chain.Arc( chain.ArcIndex( i ) );
611
612 std::unique_ptr<SCH_SHAPE> shape =
613 std::make_unique<SCH_SHAPE>( SHAPE_T::ARC, LAYER_DEVICE );
614
615 shape->SetArcGeometry( transform( arc.GetP0() ),
616 transform( arc.GetArcMid() ),
617 transform( arc.GetP1() ) );
618
619 shape->SetUnit( 0 );
620 shape->SetStroke( STROKE_PARAMS( ScaleSize( lineWidth ), strokeStyle ) );
621
622 if( fillColor != wxS( "none" ) )
623 {
624 shape->SetFilled( true );
625
626 if( fillColor == strokeColor )
627 shape->SetFillMode( FILL_T::FILLED_SHAPE );
628 else
629 shape->SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR );
630 }
631
632 aSymbol->AddDrawItem( shape.release() );
633 }
634 else
635 {
636 SEG seg = chain.CSegment( i );
637
638 std::unique_ptr<SCH_SHAPE> shape =
639 std::make_unique<SCH_SHAPE>( SHAPE_T::POLY, LAYER_DEVICE );
640
641 shape->AddPoint( transform( seg.A ) );
642 shape->AddPoint( transform( seg.B ) );
643
644 shape->SetUnit( 0 );
645 shape->SetStroke( STROKE_PARAMS( ScaleSize( lineWidth ), strokeStyle ) );
646
647 aSymbol->AddDrawItem( shape.release() );
648 }
649 }
650 }
651 }
652 else if( elType == wxS( "R" ) )
653 {
654 VECTOR2D start( Convert( arr[1] ), Convert( arr[2] ) );
655
656 VECTOR2D cr;
657 cr.x = !arr[3].empty() ? Convert( arr[3] ) : 0,
658 cr.y = !arr[4].empty() ? Convert( arr[4] ) : 0; // TODO: corner radius
659
660 VECTOR2D size( Convert( arr[5] ), Convert( arr[6] ) );
661 wxString strokeColor = arr[7];
662 double lineWidth = Convert( arr[8] );
663 LINE_STYLE strokeStyle = ConvertStrokeStyle( arr[9] );
664 wxString fillColor = arr[10].Lower();
665 //bool locked = arr[12] != wxS( "0" );
666
667 //if( cr.x == 0 )
668 {
669 auto rect = std::make_unique<SCH_SHAPE>( SHAPE_T::RECTANGLE, LAYER_DEVICE );
670
671 rect->SetStart( RelPosSym( start ) );
672 rect->SetEnd( RelPosSym( start + size ) );
673
674 rect->SetUnit( 0 );
675 rect->SetStroke( STROKE_PARAMS( ScaleSize( lineWidth ), strokeStyle ) );
676
677 if( fillColor != wxS( "none" ) )
678 {
679 rect->SetFilled( true );
680
681 if( fillColor == strokeColor )
682 rect->SetFillMode( FILL_T::FILLED_SHAPE );
683 else
685 }
686
687 aSymbol->AddDrawItem( rect.release() );
688 }
689 // TODO: rounded rectangles
690 }
691 else if( elType == wxS( "E" ) )
692 {
693 auto circle = std::make_unique<SCH_SHAPE>( SHAPE_T::CIRCLE, LAYER_DEVICE );
694
695 VECTOR2D center( Convert( arr[1] ), Convert( arr[2] ) );
696 VECTOR2D radius( Convert( arr[3] ), Convert( arr[4] ) ); // TODO: corner radius
697 wxString strokeColor = arr[5];
698 double lineWidth = Convert( arr[6] );
699 LINE_STYLE strokeStyle = ConvertStrokeStyle( arr[7] );
700 wxString fillColor = arr[8].Lower();
701 //bool locked = arr[10] != wxS( "0" );
702
703 circle->SetCenter( RelPosSym( center ) );
704 circle->SetEnd( RelPosSym( center + VECTOR2I( radius.x, 0 ) ) );
705
706 circle->SetUnit( 0 );
707 circle->SetStroke( STROKE_PARAMS( ScaleSize( lineWidth ), strokeStyle ) );
708
709 if( fillColor != wxS( "none" ) )
710 {
711 circle->SetFilled( true );
712
713 if( fillColor == strokeColor )
714 circle->SetFillMode( FILL_T::FILLED_SHAPE );
715 else
717 }
718
719 aSymbol->AddDrawItem( circle.release() );
720 }
721 else if( elType == wxS( "P" ) )
722 {
723 wxString sepShapeStr = shapeStr;
724 sepShapeStr.Replace( wxS( "^^" ), wxS( "\n" ) );
725
726 wxArrayString segments = wxSplit( sepShapeStr, '\n', '\0' );
727 wxArrayString mainParts = wxSplit( segments[0], '~', '\0' );
728 wxArrayString pinDotParts = wxSplit( segments[1], '~', '\0' );
729 wxArrayString pinPathColorParts = wxSplit( segments[2], '~', '\0' );
730 wxArrayString pinNameParts = wxSplit( segments[3], '~', '\0' );
731 wxArrayString pinNumParts = wxSplit( segments[4], '~', '\0' );
732
733 //bool show = mainParts[1].Lower() != wxS( "none" );
734 ELECTRICAL_PINTYPE elecType = ConvertElecType( mainParts[2] );
735 wxString pinNumber = mainParts[3];
736 //int pinRot = Convert( mainParts[6] );
737
738 // The dot is where wires attach. The record's own position drifts from it in some exports
739 VECTOR2D pinPos( Convert( pinDotParts[0] ), Convert( pinDotParts[1] ) );
740
741 bool nameVisible = pinNameParts[0] != wxS( "0" );
742 wxString pinName = pinNameParts[4];
743
744 bool numVisible = pinNumParts[0] != wxS( "0" );
745 // wxString ptSize = pinNumParts[4];
746
747 // The shown number is the one the board's pads carry, and it can differ from the record's id
748 if( pinNumParts.size() > 4 && !pinNumParts[4].Trim().IsEmpty() )
749 pinNumber = pinNumParts[4].Trim();
750
751 VECTOR2D startPoint;
752 bool vertical = false;
753 double pinLen = 0;
754
755 // M360,290h10 or M 420 300 h -5
756 wxString lineData = pinPathColorParts[0];
757 wxRegEx regex( wxS( "^M\\s*([-\\d.]+)[,\\s]([-\\d.]+)\\s*([h|v])\\s*([-\\d.]+)\\s*$" ) );
758
759 if( regex.Matches( lineData ) )
760 {
761 startPoint.x = Convert( regex.GetMatch( lineData, 1 ) );
762 startPoint.y = Convert( regex.GetMatch( lineData, 2 ) );
763
764 vertical = regex.GetMatch( lineData, 3 ).Contains( wxS( "v" ) );
765 pinLen = Convert( regex.GetMatch( lineData, 4 ) );
766 }
767
768 int pinRotation = 0;
769
770 if( !vertical )
771 {
772 if( startPoint.x == pinPos.x && pinLen < 0 )
773 pinRotation = 180;
774 else if( startPoint.x == pinPos.x && pinLen > 0 )
775 pinRotation = 0;
776 else if( startPoint.x != pinPos.x && pinLen < 0 )
777 pinRotation = 0;
778 else if( startPoint.x != pinPos.x && pinLen > 0 )
779 pinRotation = 180;
780 }
781 else
782 {
783 if( startPoint.y == pinPos.y && pinLen < 0 )
784 pinRotation = 90;
785 else if( startPoint.y == pinPos.y && pinLen > 0 )
786 pinRotation = 270;
787 else if( startPoint.y != pinPos.y && pinLen < 0 )
788 pinRotation = 270;
789 else if( startPoint.y != pinPos.y && pinLen > 0 )
790 pinRotation = 90;
791 }
792
794
795 if( pinRotation == 0 )
797 else if( pinRotation == 90 )
799 else if( pinRotation == 180 )
801 else if( pinRotation == 270 )
803
804 int pinUnit = 0;
805 int kPinLen = ScaleSize( std::abs( pinLen ) );
806
807 if( segments.size() > 5 )
808 {
809 wxArrayString dotParts = wxSplit( segments[5], '~', '\0' );
810 wxArrayString clockParts = wxSplit( segments[6], '~', '\0' );
811
812 if( dotParts.size() == 3 && clockParts.size() == 2 )
813 {
814 if( dotParts[0] == wxS( "1" ) )
815 {
816 VECTOR2D dotPos( Convert( dotParts[1] ), Convert( dotParts[2] ) );
817
818 auto circle = std::make_unique<SCH_SHAPE>( SHAPE_T::CIRCLE, LAYER_DEVICE );
819
820 circle->SetCenter( RelPosSym( dotPos ) );
821 circle->SetEnd( RelPosSym(
822 pinPos + ( dotPos - pinPos ).Resize( std::abs( pinLen ) ) ) );
823
824 circle->SetUnit( 0 );
825
826 aSymbol->AddDrawItem( circle.release() );
827 }
828
829 if( clockParts[0] == wxS( "1" ) )
830 {
831 std::vector<SHAPE_LINE_CHAIN> lineChains =
832 ParseLineChains( clockParts[1], schIUScale.MilsToIU( 10 ), false );
833
834 for( SHAPE_LINE_CHAIN outline : lineChains )
835 {
836 auto shape = std::make_unique<SCH_SHAPE>( SHAPE_T::POLY, LAYER_DEVICE );
837
838 if( outline.IsClosed() )
839 outline.Append( outline.CPoint( 0 ), true );
840
841 for( const VECTOR2I& pt : outline.CPoints() )
842 shape->AddPoint( pt );
843
844 shape->SetUnit( 0 );
845
846 aSymbol->AddDrawItem( shape.release() );
847 }
848 }
849 }
850 }
851
852 std::unique_ptr<SCH_PIN> pin = std::make_unique<SCH_PIN>( aSymbol );
853
854 pin->SetName( pinName );
855 pin->SetNumber( pinNumber );
856 pin->SetOrientation( orient );
857 pin->SetType( elecType );
858 pin->SetLength( kPinLen );
859 pin->SetPosition( RelPosSym( pinPos ) );
860 pin->SetUnit( pinUnit );
861
862 if( pin->GetNumberTextSize() * int( pinNumber.size() ) > kPinLen )
863 pin->SetNumberTextSize( kPinLen / pinNumber.size() );
864
865 if( !nameVisible )
866 pin->SetNameTextSize( schIUScale.MilsToIU( 1 ) );
867
868 if( !numVisible )
869 pin->SetNumberTextSize( schIUScale.MilsToIU( 1 ) );
870
871 aSymbol->AddDrawItem( pin.release() );
872 }
873 else if( elType == wxS( "T" ) )
874 {
875 if( !checkTextFields( arr ) )
876 continue;
877
878 wxString textType = arr[1];
879 VECTOR2D pos( Convert( arr[2] ), Convert( arr[3] ) );
880 int angle = Convert( arr[4] );
881 // wxString color = arr[5];
882 wxString fontname = arr[6];
883 wxString fontSize = arr[7];
884 wxString baselineAlign = arr[10];
885 wxString textStr = arr[12];
886 bool visible = optionalField( arr, 13 ) != wxS( "0" );
887
888 textStr.Replace( wxS( "\\n" ), wxS( "\n" ) );
889 textStr = UnescapeHTML( textStr );
890
891 wxString halignStr = optionalField( arr, 14 ); // Empty, start, middle, end, inherit
892
893 bool added = false;
894 EDA_TEXT* textItem = nullptr;
895
896 if( textType == wxS( "P" ) )
897 {
898 textItem = &aSymbol->GetReferenceField();
899 textItem->SetTextPos( RelPosSym( pos ) );
900 textItem->SetText( textStr );
901 }
902 else if( textType == wxS( "N" ) )
903 {
904 textItem = &aSymbol->GetValueField();
905 textItem->SetTextPos( RelPosSym( pos ) );
906 textItem->SetText( textStr );
907 }
908 else
909 {
910 textItem = new SCH_TEXT( RelPosSym( pos ), textStr, LAYER_DEVICE );
911 added = true;
912 }
913
914 textItem->SetTextAngleDegrees( ( 360 - angle ) % 360 );
916
917 if( halignStr == wxS( "middle" ) )
919 else if( halignStr == wxS( "end" ) )
921 else
923
924 textItem->SetFont( KIFONT::FONT::GetFont( fontname ) );
925 textItem->SetVisible( visible );
926
927 double ptSize = 7;
928
929 if( !fontSize.IsEmpty() )
930 {
931 if( fontSize.EndsWith( wxS( "pt" ) ) )
932 ptSize = Convert( fontSize.BeforeFirst( 'p' ) );
933 else if( fontSize.IsNumber() )
934 ptSize = Convert( fontSize );
935 }
936
937 double ktextSize = ScaleSize( ptSize );
938
939 if( textStr.Contains( wxS( "\n" ) ) )
940 ktextSize *= 0.8;
941 else
942 ktextSize *= 0.95;
943
944 textItem->SetTextSize( VECTOR2I( ktextSize, ktextSize ) );
945
946 TransformTextToBaseline( textItem, baselineAlign );
947
948 if( added )
949 aSymbol->AddDrawItem( dynamic_cast<SCH_ITEM*>( textItem ) );
950 }
951 }
952}
953
954
956 std::map<wxString, wxString> aParams,
957 wxArrayString aShapes )
958{
959 std::unique_ptr<LIB_SYMBOL> ksymbol = std::make_unique<LIB_SYMBOL>( wxEmptyString );
960
961 m_relOrigin = aOrigin;
962
963 std::optional<wxString> valOpt;
964 wxString symbolName = wxS( "Unknown" );
965
966 if( ( valOpt = get_opt( aParams, wxS( "name" ) ) ) )
967 symbolName = *valOpt;
968 else if( ( valOpt = get_opt( aParams, wxS( "spiceSymbolName" ) ) ) )
969 symbolName = *valOpt;
970
971 wxString symbolPrefix;
972
973 if( ( valOpt = get_opt( aParams, wxS( "pre" ) ) ) )
974 symbolPrefix = *valOpt;
975 else if( ( valOpt = get_opt( aParams, wxS( "spicePre" ) ) ) )
976 symbolPrefix = *valOpt;
977
978 LIB_ID libId = EasyEdaToKiCadLibID( wxEmptyString, symbolName );
979
980 ksymbol->SetLibId( libId );
981 ksymbol->SetName( symbolName );
982
983 ksymbol->GetReferenceField().SetText( symbolPrefix );
984 ksymbol->GetValueField().SetText( symbolName );
985
986 // Frames and other parts with no package never reach the board
987 if( ( valOpt = get_opt( aParams, wxS( "package" ) ) ) && *valOpt == wxS( "NONE" ) )
988 {
989 ksymbol->SetExcludedFromBoard( true );
990 ksymbol->SetExcludedFromBOM( true );
991 }
992
993 for( wxString attrName : c_attributesWhitelist )
994 {
995 wxString srcName = attrName;
996
997 if( srcName == wxS( "Datasheet" ) )
998 srcName = wxS( "link" );
999
1000 if( ( valOpt = get_opt( aParams, srcName ) ) )
1001 {
1002 if( valOpt->empty() )
1003 continue;
1004
1005 SCH_FIELD* fd = ksymbol->FindFieldCaseInsensitive( attrName );
1006
1007 if( !fd )
1008 {
1009 fd = new SCH_FIELD( ksymbol.get(), FIELD_T::USER, attrName );
1010 ksymbol->AddField( fd );
1011 }
1012
1013 fd->SetText( *valOpt );
1014 fd->SetVisible( false );
1015 }
1016 }
1017
1018 ParseSymbolShapes( ksymbol.get(), aParams, aShapes );
1019
1020 return ksymbol.release();
1021}
1022
1023std::pair<LIB_SYMBOL*, bool> SCH_EASYEDA_PARSER::MakePowerSymbol( const wxString& aFlagTypename,
1024 const wxString& aNetname )
1025{
1026 std::unique_ptr<LIB_SYMBOL> ksymbol = std::make_unique<LIB_SYMBOL>( wxEmptyString );
1027
1029
1030 LIB_ID libId = EasyEdaToKiCadLibID( wxEmptyString, aNetname );
1031
1032 ksymbol->SetGlobalPower();
1033 ksymbol->SetLibId( libId );
1034 ksymbol->SetName( aNetname );
1035 ksymbol->GetReferenceField().SetText( wxS( "#PWR" ) );
1036 ksymbol->GetReferenceField().SetVisible( false );
1037 ksymbol->GetValueField().SetText( aNetname );
1038 ksymbol->GetValueField().SetVisible( true );
1039 ksymbol->SetDescription( wxString::Format( _( "Power symbol creates a global "
1040 "label with name '%s'" ),
1041 aNetname ) );
1042 ksymbol->SetKeyWords( wxS( "power-flag" ) );
1043 ksymbol->SetShowPinNames( false );
1044 ksymbol->SetShowPinNumbers( false );
1045
1046 std::unique_ptr<SCH_PIN> pin = std::make_unique<SCH_PIN>( ksymbol.get() );
1047
1048 pin->SetName( aNetname );
1049 pin->SetNumber( wxS( "1" ) );
1050 pin->SetOrientation( PIN_ORIENTATION::PIN_DOWN );
1052 pin->SetLength( 0 );
1053
1054 ksymbol->AddDrawItem( pin.release() );
1055
1057
1058 bool flip = false;
1059
1060 if( aFlagTypename == wxS( "part_netLabel_gnD" ) )
1061 {
1063 }
1064 else if( aFlagTypename == wxS( "part_netLabel_GNd" ) )
1065 {
1067 }
1068 else if( aFlagTypename == wxS( "part_netLabel_gNd" ) )
1069 {
1071 }
1072 else if( aFlagTypename == wxS( "part_netLabel_GnD" ) )
1073 {
1075 }
1076 else if( aFlagTypename == wxS( "part_netLabel_VCC" ) )
1077 {
1079 flip = true;
1080 }
1081 else if( aFlagTypename == wxS( "part_netLabel_+5V" ) )
1082 {
1084 flip = true;
1085 }
1086 else if( aFlagTypename == wxS( "part_netLabel_VEE" ) )
1087 {
1089 }
1090 else if( aFlagTypename == wxS( "part_netLabel_-5V" ) )
1091 {
1093 }
1094 else if( aFlagTypename == wxS( "part_netLabel_Bar" ) )
1095 {
1097 flip = true;
1098 }
1099
1100 VECTOR2I valueFieldPos = HelperGeneratePowerPortGraphics( ksymbol.get(), flagStyle, nullptr );
1101 ksymbol->GetValueField().SetPosition( valueFieldPos );
1102
1103 return std::make_pair( ksymbol.release(), flip );
1104}
1105
1107 const wxString& aFileName, wxArrayString aShapes )
1108{
1109 std::map<wxString, std::unique_ptr<LIB_SYMBOL>> loadedSymbols;
1110 std::map<wxString, int> namesCounter;
1111 std::vector<std::unique_ptr<SCH_ITEM>> createdItems;
1112
1113 for( wxString shap : aShapes )
1114 {
1115 shap.Replace( wxS( "#@$" ), wxS( "\n" ) );
1116 wxArrayString parts = wxSplit( shap, '\n', '\0' );
1117
1118 if( parts.size() < 1 )
1119 continue;
1120
1121 wxArrayString arr = wxSplit( parts[0], '~', '\0' );
1122
1123 if( arr.size() < 1 )
1124 continue;
1125
1126 wxString rootType = arr[0];
1127
1128 if( rootType == wxS( "LIB" ) )
1129 {
1130 if( arr.size() < 4 )
1131 continue;
1132
1133 VECTOR2D origin( Convert( arr[1] ), Convert( arr[2] ) );
1134
1135 wxString symbolName = wxString::Format( wxS( "Unknown_%s_%s" ), arr[1], arr[2] );
1136
1137 wxArrayString paramParts = wxSplit( arr[3], '`', '\0' );
1138
1139 std::map<wxString, wxString> paramMap;
1140
1141 for( size_t i = 1; i < paramParts.size(); i += 2 )
1142 {
1143 wxString key = paramParts[i - 1];
1144 wxString value = paramParts[i];
1145
1146 if( key == wxS( "spiceSymbolName" ) && !value.IsEmpty() )
1147 symbolName = value;
1148
1149 paramMap[key] = value;
1150 }
1151
1152 int& serial = namesCounter[symbolName];
1153
1154 if( serial > 0 )
1155 symbolName << wxS( "_" ) << serial;
1156
1157 serial++;
1158
1159 paramMap[wxS( "spiceSymbolName" )] = symbolName;
1160
1161 parts.RemoveAt( 0 );
1162
1163 VECTOR2D pcbOrigin = m_relOrigin;
1164
1165 LIB_SYMBOL* sym = ParseSymbol( origin, paramMap, parts );
1166 loadedSymbols.emplace( symbolName, sym );
1167
1168 wxString referenceStr = sym->GetReferenceField().GetText();
1169
1170 // A frame can share its designator with a real part, which hides that part from the netlist
1171 if( sym->GetExcludedFromBoard() )
1172 referenceStr = wxS( "#" ) + referenceStr;
1173
1174 m_relOrigin = pcbOrigin;
1175 LIB_ID libId = EasyEdaToKiCadLibID( wxEmptyString, symbolName );
1176
1177 std::unique_ptr<SCH_SYMBOL> schSym =
1178 std::make_unique<SCH_SYMBOL>( *sym, libId, &aSchematic->CurrentSheet(), 0 );
1179
1180 schSym->SetPosition( RelPos( origin ) );
1181 schSym->SetRef( &aSchematic->CurrentSheet(), referenceStr );
1182
1183 createdItems.push_back( std::move( schSym ) );
1184 }
1185 else if( rootType == wxS( "F" ) )
1186 {
1187 wxString sepShapeStr = parts[0];
1188 sepShapeStr.Replace( wxS( "^^" ), wxS( "\n" ) );
1189
1190 wxArrayString segments = wxSplit( sepShapeStr, '\n', '\0' );
1191 // wxArrayString mainParts = wxSplit( segments[0], '~', '\0' );
1192 // wxArrayString uselessParts = wxSplit( segments[1], '~', '\0' );
1193 wxArrayString valueParts = wxSplit( segments[2], '~', '\0' );
1194
1195 wxString flagTypename = arr[1];
1196 VECTOR2D pos( Convert( arr[2] ), Convert( arr[3] ) );
1197 double angle = Convert( arr[4] );
1198
1199 wxString netnameValue = valueParts[0];
1200 VECTOR2D valuePos( Convert( valueParts[2] ), Convert( valueParts[3] ) );
1201 double textAngle = Convert( valueParts[4] );
1202 wxString halignStr = valueParts[5];
1203 wxString valueFontname = valueParts[7];
1204 wxString valueFontsize = valueParts[8];
1205
1206 if( flagTypename == wxS( "part_netLabel_netPort" ) )
1207 {
1208 std::unique_ptr<SCH_GLOBALLABEL> label =
1209 std::make_unique<SCH_GLOBALLABEL>( RelPos( pos ), netnameValue );
1210
1212
1213 for( double i = angle; i > 0; i -= 90 )
1214 spin = spin.RotateCCW();
1215
1216 // If the shape was mirrored, we can't rely on angle value to determine direction.
1217 if( segments.size() > 3 )
1218 {
1219 wxArrayString shapeParts = wxSplit( segments[3], '~', '\0' );
1220 if( shapeParts[0] == wxS( "PL" ) )
1221 {
1222 wxArrayString ptArr = wxSplit( shapeParts[1], ' ', '\0' );
1223
1225
1226 for( size_t i = 1; i < ptArr.size(); i += 2 )
1227 {
1228 chain.Append( RelPos(
1229 VECTOR2I( Convert( ptArr[i - 1] ), Convert( ptArr[i] ) ) ) );
1230 }
1231
1232 chain.Move( -RelPos( pos ) );
1233
1234 VECTOR2I shapeCenter = chain.Centre();
1235
1236 if( std::abs( shapeCenter.x ) >= std::abs( shapeCenter.y ) )
1237 {
1238 if( shapeCenter.x >= 0 )
1239 spin = SPIN_STYLE::RIGHT;
1240 else
1241 spin = SPIN_STYLE::LEFT;
1242 }
1243 else
1244 {
1245 if( shapeCenter.y >= 0 )
1246 spin = SPIN_STYLE::BOTTOM;
1247 else
1248 spin = SPIN_STYLE::UP;
1249 }
1250 }
1251 }
1252
1253 label->SetSpinStyle( spin );
1254 label->SetShape( LABEL_FLAG_SHAPE::L_INPUT );
1255
1256 createdItems.push_back( std::move( label ) );
1257 }
1258 else
1259 {
1260 auto pair = MakePowerSymbol( flagTypename, netnameValue );
1261 LIB_SYMBOL* pwrLibSym = pair.first;
1262 bool flip = pair.second;
1263
1264 LIB_ID libId = EasyEdaToKiCadLibID( wxEmptyString, netnameValue );
1265
1266 std::unique_ptr<SCH_SYMBOL> schSym = std::make_unique<SCH_SYMBOL>(
1267 *pwrLibSym, libId, &aSchematic->CurrentSheet(), 0 );
1268
1269 if( flip )
1270 schSym->SetOrientation( SYM_MIRROR_X );
1271
1272 if( angle == 0 )
1273 {
1274 }
1275 else if( angle == 90 )
1276 {
1277 schSym->SetOrientation( SYM_ROTATE_COUNTERCLOCKWISE );
1278 }
1279 if( angle == 180 )
1280 {
1281 schSym->SetOrientation( SYM_ROTATE_COUNTERCLOCKWISE );
1282 schSym->SetOrientation( SYM_ROTATE_COUNTERCLOCKWISE );
1283 }
1284 if( angle == 270 )
1285 {
1286 schSym->SetOrientation( SYM_ROTATE_CLOCKWISE );
1287 }
1288
1289 schSym->SetPosition( RelPos( pos ) );
1290
1291 SCH_FIELD* valField = schSym->GetField( FIELD_T::VALUE );
1292
1293 valField->SetPosition( RelPos( valuePos ) );
1294 valField->SetTextAngleDegrees( textAngle - angle );
1295
1296 if( !flip )
1298 else
1300
1301 if( halignStr == wxS( "middle" ) )
1303 else if( halignStr == wxS( "end" ) )
1305 else
1307
1308 if( flip && ( angle == 90 || angle == 270 ) )
1309 {
1310 if( valField->GetVertJustify() == GR_TEXT_V_ALIGN_BOTTOM )
1312 else if( valField->GetVertJustify() == GR_TEXT_V_ALIGN_TOP )
1314
1315 if( valField->GetHorizJustify() == GR_TEXT_H_ALIGN_RIGHT )
1317 else if( valField->GetHorizJustify() == GR_TEXT_H_ALIGN_LEFT )
1319
1320 if( flagTypename == wxS( "part_netLabel_Bar" ) ) // "Circle"
1322 }
1323
1324 if( angle == 0 && flagTypename == wxS( "part_netLabel_Bar" ) ) // "Circle"
1326
1327 valField->SetFont( KIFONT::FONT::GetFont( valueFontname ) );
1328
1329 double ptSize = 7;
1330
1331 if( valueFontsize.EndsWith( wxS( "pt" ) ) )
1332 ptSize = Convert( valueFontsize.BeforeFirst( 'p' ) );
1333
1334 double ktextSize = ScaleSize( ptSize );
1335
1336 if( netnameValue.Contains( wxS( "\n" ) ) )
1337 ktextSize *= 0.8;
1338 else
1339 ktextSize *= 0.95;
1340
1341 valField->SetTextSize( VECTOR2I( ktextSize, ktextSize ) );
1342
1343 //TransformTextToBaseline( valField, wxS( "" ), true );
1344
1345 createdItems.push_back( std::move( schSym ) );
1346 }
1347 }
1348 else if( rootType == wxS( "W" ) )
1349 {
1350 wxArrayString ptArr = wxSplit( arr[1], ' ', '\0' );
1351 //wxString strokeColor = arr[2];
1352 //double lineWidth = Convert( arr[3] );
1353 //LINE_STYLE strokeStyle = ConvertStrokeStyle( arr[4] );
1354 //wxString fillColor = arr[5].Lower();
1355 //bool locked = arr[7] != wxS( "0" );
1356
1358
1359 for( size_t i = 1; i < ptArr.size(); i += 2 )
1360 chain.Append( VECTOR2I( RelPosX( ptArr[i - 1] ), RelPosY( ptArr[i] ) ) );
1361
1362 for( int segId = 0; segId < chain.SegmentCount(); segId++ )
1363 {
1364 const SEG& seg = chain.CSegment( segId );
1365
1366 std::unique_ptr<SCH_LINE> line = std::make_unique<SCH_LINE>( seg.A, LAYER_WIRE );
1367 line->SetEndPoint( seg.B );
1368
1369 createdItems.push_back( std::move( line ) );
1370 }
1371 }
1372 else if( rootType == wxS( "N" ) )
1373 {
1374 VECTOR2D pos( Convert( arr[1] ), Convert( arr[2] ) );
1375 double angle = Convert( arr[3] );
1376 wxString netname = arr[5];
1377 wxString halignStr = arr[7];
1378 VECTOR2D text_pos( Convert( arr[8] ),
1379 Convert( arr[9] ) ); // TODO: detect top/bottom align
1380
1381 // wxString fontname = arr[10];
1382 // wxString fontSize = arr[11];
1383
1384 std::unique_ptr<SCH_LABEL> label =
1385 std::make_unique<SCH_LABEL>( RelPos( pos ), netname );
1386
1387 if( halignStr == wxS( "middle" ) )
1388 label->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
1389 else if( halignStr == wxS( "end" ) )
1390 label->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
1391 else
1392 label->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
1393
1394 for( int left = angle; left > 0; left -= 90 )
1395 label->Rotate90( false );
1396
1397 createdItems.push_back( std::move( label ) );
1398 }
1399 else if( rootType == wxS( "O" ) )
1400 {
1401 VECTOR2D pos( Convert( arr[1] ), Convert( arr[2] ) );
1402
1403 std::unique_ptr<SCH_NO_CONNECT> noConn =
1404 std::make_unique<SCH_NO_CONNECT>( RelPos( pos ) );
1405
1406 createdItems.push_back( std::move( noConn ) );
1407 }
1408 else if( rootType == wxS( "J" ) )
1409 {
1410 VECTOR2D pos( Convert( arr[1] ), Convert( arr[2] ) );
1411 //double dia = Convert( arr[3] );
1412
1413 std::unique_ptr<SCH_JUNCTION> junction =
1414 std::make_unique<SCH_JUNCTION>( RelPos( pos ) /*, ScaleSizeUnit( dia )*/ );
1415
1416 createdItems.push_back( std::move( junction ) );
1417 }
1418 else if( rootType == wxS( "T" ) )
1419 {
1420 if( !checkTextFields( arr ) )
1421 continue;
1422
1423 VECTOR2D pos( Convert( arr[2] ), Convert( arr[3] ) );
1424 int angle = Convert( arr[4] );
1425 // wxString color = arr[5];
1426 wxString fontname = arr[6];
1427 wxString fontSize = arr[7];
1428 wxString baselineAlign = arr[10];
1429 wxString textStr = arr[12];
1430
1431 textStr.Replace( wxS( "\\n" ), wxS( "\n" ) );
1432 textStr = UnescapeHTML( textStr );
1433
1434 wxString halignStr = optionalField( arr, 14 ); // Empty, start, middle, end, inherit
1435
1436 std::unique_ptr<SCH_TEXT> textItem =
1437 std::make_unique<SCH_TEXT>( RelPos( pos ), textStr );
1438
1439 textItem->SetTextAngleDegrees( ( 360 - angle ) % 360 );
1440 textItem->SetVertJustify( GR_TEXT_V_ALIGN_TOP );
1441
1442 if( halignStr == wxS( "middle" ) )
1443 textItem->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
1444 else if( halignStr == wxS( "end" ) )
1445 textItem->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
1446 else
1447 textItem->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
1448
1449 textItem->SetFont( KIFONT::FONT::GetFont( fontname ) );
1450
1451 double ptSize = 7;
1452
1453 if( fontSize.EndsWith( wxS( "pt" ) ) )
1454 ptSize = Convert( fontSize.BeforeFirst( 'p' ) );
1455
1456 double ktextSize = ScaleSize( ptSize );
1457
1458 if( textStr.Contains( wxS( "\n" ) ) )
1459 ktextSize *= 0.8;
1460 else
1461 ktextSize *= 0.95;
1462
1463 textItem->SetTextSize( VECTOR2I( ktextSize, ktextSize ) );
1464
1465 TransformTextToBaseline( textItem.get(), baselineAlign );
1466
1467 createdItems.push_back( std::move( textItem ) );
1468 }
1469 else if( rootType == wxS( "R" ) )
1470 {
1471 VECTOR2D start( Convert( arr[1] ), Convert( arr[2] ) );
1472
1473 VECTOR2D cr;
1474 cr.x = !arr[3].empty() ? Convert( arr[3] ) : 0,
1475 cr.y = !arr[4].empty() ? Convert( arr[4] ) : 0; // TODO: corner radius
1476
1477 VECTOR2D size( Convert( arr[5] ), Convert( arr[6] ) );
1478 wxString strokeColor = arr[7];
1479 double lineWidth = Convert( arr[8] );
1480 LINE_STYLE strokeStyle = ConvertStrokeStyle( arr[9] );
1481 wxString fillColor = arr[10].Lower();
1482 //bool locked = arr[12] != wxS( "0" );
1483
1484 //if( cr.x == 0 )
1485 {
1486 std::unique_ptr<SCH_SHAPE> rect = std::make_unique<SCH_SHAPE>( SHAPE_T::RECTANGLE );
1487
1488 rect->SetStart( RelPos( start ) );
1489 rect->SetEnd( RelPos( start + size ) );
1490
1491 rect->SetStroke( STROKE_PARAMS( ScaleSize( lineWidth ), strokeStyle ) );
1492
1493 if( fillColor != wxS( "none" ) )
1494 {
1495 rect->SetFilled( true );
1496
1497 if( fillColor == strokeColor )
1498 rect->SetFillMode( FILL_T::FILLED_SHAPE );
1499 else
1500 rect->SetFillMode( FILL_T::FILLED_WITH_BG_BODYCOLOR );
1501 }
1502
1503 createdItems.push_back( std::move( rect ) );
1504 }
1505 /*else
1506 {
1507 }*/
1508 }
1509 else if( rootType == wxS( "I" ) )
1510 {
1511 VECTOR2D start( Convert( arr[1] ), Convert( arr[2] ) );
1512 VECTOR2D size( Convert( arr[3] ), Convert( arr[4] ) );
1513 //double angle = Convert( arr[5] ); // CSS-like transformations are used instead.
1514 wxString imageUrl = arr[6];
1515 wxString transformData = arr[9];
1516
1517 VECTOR2D kstart = RelPos( start );
1518 VECTOR2D ksize = ScalePos( size );
1519
1520 std::vector<std::pair<wxString, std::vector<double>>> transformCmds =
1521 ParseImageTransform( transformData );
1522
1523 auto applyTransform = [&]( SCH_ITEM* aSchItem )
1524 {
1525 for( const auto& cmd : transformCmds )
1526 {
1527 if( cmd.first == wxS( "rotate" ) )
1528 {
1529 if( cmd.second.size() != 3 )
1530 continue;
1531
1532 double cmdAngle = 360 - cmd.second[0];
1533 VECTOR2D cmdAround( cmd.second[1], cmd.second[2] );
1534
1535 for( double i = cmdAngle; i > 0; i -= 90 )
1536 {
1537 if( aSchItem->Type() == SCH_LINE_T )
1538 {
1539 // Lines need special handling for some reason
1540 aSchItem->SetFlags( STARTPOINT );
1541 aSchItem->Rotate( RelPos( cmdAround ), false );
1542 aSchItem->ClearFlags( STARTPOINT );
1543
1544 aSchItem->SetFlags( ENDPOINT );
1545 aSchItem->Rotate( RelPos( cmdAround ), false );
1546 aSchItem->ClearFlags( ENDPOINT );
1547 }
1548 else
1549 {
1550 aSchItem->Rotate( RelPos( cmdAround ), false );
1551 }
1552 }
1553 }
1554 else if( cmd.first == wxS( "translate" ) )
1555 {
1556 if( cmd.second.size() != 2 )
1557 continue;
1558
1559 VECTOR2D cmdOffset( cmd.second[0], cmd.second[1] );
1560 aSchItem->Move( ScalePos( cmdOffset ) );
1561 }
1562 else if( cmd.first == wxS( "scale" ) )
1563 {
1564 if( cmd.second.size() != 2 )
1565 continue;
1566
1567 double cmdScaleX = cmd.second[0];
1568 double cmdScaleY = cmd.second[1];
1569
1570 // Lines need special handling for some reason
1571 if( aSchItem->Type() == SCH_LINE_T )
1572 aSchItem->SetFlags( STARTPOINT | ENDPOINT );
1573
1574 if( cmdScaleX < 0 && cmdScaleY > 0 )
1575 {
1576 aSchItem->MirrorHorizontally( 0 );
1577 }
1578 else if( cmdScaleX > 0 && cmdScaleY < 0 )
1579 {
1580 aSchItem->MirrorVertically( 0 );
1581 }
1582 else if( cmdScaleX < 0 && cmdScaleY < 0 )
1583 {
1584 aSchItem->MirrorHorizontally( 0 );
1585 aSchItem->MirrorVertically( 0 );
1586 }
1587
1588 if( aSchItem->Type() == SCH_LINE_T )
1589 aSchItem->ClearFlags( STARTPOINT | ENDPOINT );
1590 }
1591 }
1592 };
1593
1594 if( imageUrl.BeforeFirst( ':' ) == wxS( "data" ) )
1595 {
1596 wxArrayString paramsArr =
1597 wxSplit( imageUrl.AfterFirst( ':' ).BeforeFirst( ',' ), ';', '\0' );
1598
1599 wxString data = imageUrl.AfterFirst( ',' );
1600
1601 if( paramsArr.size() > 0 )
1602 {
1603 wxString mimeType = paramsArr[0];
1604 wxMemoryBuffer buf = wxBase64Decode( data );
1605
1606 if( mimeType == wxS( "image/svg+xml" ) )
1607 {
1608 VECTOR2D offset = RelPos( start );
1609
1610 SVG_IMPORT_PLUGIN svgImportPlugin;
1611 GRAPHICS_IMPORTER_SCH schImporter;
1612
1613 svgImportPlugin.SetImporter( &schImporter );
1614 svgImportPlugin.LoadFromMemory( buf );
1615
1616 VECTOR2D imSize( svgImportPlugin.GetImageWidth(),
1617 svgImportPlugin.GetImageHeight() );
1618
1619 VECTOR2D pixelScale( schIUScale.IUTomm( ScaleSize( size.x ) ) / imSize.x,
1620 schIUScale.IUTomm( ScaleSize( size.y ) ) / imSize.y );
1621
1622 schImporter.SetScale( pixelScale );
1623
1624 VECTOR2D offsetMM( schIUScale.IUTomm( offset.x ),
1625 schIUScale.IUTomm( offset.y ) );
1626
1627 schImporter.SetImportOffsetMM( offsetMM );
1628
1629 svgImportPlugin.Import();
1630
1631 for( std::unique_ptr<EDA_ITEM>& item : schImporter.GetItems() )
1632 {
1633 SCH_ITEM* schItem = static_cast<SCH_ITEM*>( item.release() );
1634
1635 applyTransform( schItem );
1636
1637 createdItems.emplace_back( schItem );
1638 }
1639 }
1640 else
1641 {
1642 std::unique_ptr<SCH_BITMAP> bitmap = std::make_unique<SCH_BITMAP>();
1643 REFERENCE_IMAGE& refImage = bitmap->GetReferenceImage();
1644
1645 wxImage::SetDefaultLoadFlags( wxImage::GetDefaultLoadFlags()
1646 & ~wxImage::Load_Verbose );
1647
1648 if( refImage.ReadImageFile( buf ) )
1649 {
1650 VECTOR2D kcenter = kstart + ksize / 2;
1651
1652 double scaleFactor = ScaleSize( size.x ) / refImage.GetSize().x;
1653 refImage.SetImageScale( scaleFactor );
1654 bitmap->SetPosition( kcenter );
1655
1656 applyTransform( bitmap.get() );
1657
1658 createdItems.push_back( std::move( bitmap ) );
1659 }
1660 }
1661 }
1662 }
1663 }
1664 }
1665
1666 BOX2I sheetBBox;
1667
1668 for( std::unique_ptr<SCH_ITEM>& ptr : createdItems )
1669 if( ptr->Type() == SCH_SYMBOL_T )
1670 sheetBBox.Merge( static_cast<SCH_SYMBOL*>( ptr.get() )->GetBodyBoundingBox() );
1671
1672 SCH_SCREEN* screen = aRootSheet->GetScreen();
1673 PAGE_INFO pageInfo = screen->GetPageSettings();
1674
1675 int alignGrid = schIUScale.MilsToIU( 50 );
1676
1677 VECTOR2D offset( -sheetBBox.GetLeft(), -sheetBBox.GetTop() );
1678 offset.x = KiROUND( offset.x / alignGrid ) * alignGrid;
1679 offset.y = KiROUND( offset.y / alignGrid ) * alignGrid;
1680
1681 pageInfo.SetWidthMils( schIUScale.IUToMils( sheetBBox.GetWidth() ) );
1682 pageInfo.SetHeightMils( schIUScale.IUToMils( sheetBBox.GetHeight() ) );
1683
1684 screen->SetPageSettings( pageInfo );
1685
1686 for( std::unique_ptr<SCH_ITEM>& ptr : createdItems )
1687 {
1688 ptr->Move( offset );
1689 screen->Append( ptr.release() );
1690 }
1691}
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:130
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
constexpr size_type GetWidth() const
Definition box2.h:217
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:597
constexpr size_type GetHeight() const
Definition box2.h:218
constexpr coord_type GetLeft() const
Definition box2.h:231
constexpr coord_type GetTop() const
Definition box2.h:232
static double Convert(const wxString &aValue)
double RelPosX(double aValue)
double RelPosY(double aValue)
VECTOR2< T > RelPos(const VECTOR2< T > &aVec)
VECTOR2< T > ScalePos(const VECTOR2< T > &aValue)
void TransformTextToBaseline(EDA_TEXT *textItem, const wxString &baselineAlign)
std::vector< SHAPE_LINE_CHAIN > ParseLineChains(const wxString &aData, int aMaxError, bool aForceClosed)
virtual void SetEnd(const VECTOR2I &aEnd)
Definition eda_shape.h:338
virtual void SetBezierC2(const VECTOR2I &aPt)
Definition eda_shape.h:376
virtual void SetBezierC1(const VECTOR2I &aPt)
Definition eda_shape.h:373
virtual void SetStart(const VECTOR2I &aStart)
Definition eda_shape.h:288
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:94
virtual void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition eda_text.cpp:513
virtual void SetTextPos(const VECTOR2I &aPoint)
Definition eda_text.cpp:557
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition eda_text.cpp:379
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition eda_text.h:239
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:348
void SetTextAngleDegrees(double aOrientation)
Definition eda_text.h:181
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition eda_text.h:242
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:237
void SetFont(KIFONT::FONT *aFont)
Definition eda_text.cpp:472
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition eda_text.cpp:371
void SetImportOffsetMM(const VECTOR2D &aOffset)
Set the offset in millimeters to add to coordinates when importing graphic items.
void SetScale(const VECTOR2D &aScale)
Set the scale factor affecting the imported shapes.
std::list< std::unique_ptr< EDA_ITEM > > & GetItems()
Return the list of objects representing the imported shapes.
virtual void SetImporter(GRAPHICS_IMPORTER *aImporter)
Set the receiver of the imported shapes.
static FONT * GetFont(const wxString &aFontName=wxEmptyString, bool aBold=false, bool aItalic=false, const std::vector< wxString > *aEmbeddedFiles=nullptr, bool aForDrawingSheet=false)
Definition font.cpp:144
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition lib_id.cpp:65
Define a library symbol object.
Definition lib_symbol.h:114
SCH_FIELD & GetValueField()
Definition lib_symbol.h:449
void AddDrawItem(SCH_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
SCH_FIELD & GetReferenceField()
Definition lib_symbol.h:453
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:75
void SetHeightMils(double aHeightInMils)
void SetWidthMils(double aWidthInMils)
A progress reporter interface for use in multi-threaded environments.
A REFERENCE_IMAGE is a wrapper around a BITMAP_IMAGE that is displayed in an editor as a reference fo...
bool ReadImageFile(const wxString &aFullFilename)
Read and store an image file.
VECTOR2I GetSize() const
void SetImageScale(double aScale)
Set the image "zoom" value.
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:102
Holds all the data relating to one schematic.
Definition schematic.h:155
SCH_SHEET_PATH & CurrentSheet() const
Definition schematic.h:399
void ParseSymbolShapes(LIB_SYMBOL *aContainer, std::map< wxString, wxString > paramMap, wxArrayString aShapes)
std::pair< LIB_SYMBOL *, bool > MakePowerSymbol(const wxString &aFlagTypename, const wxString &aNetname)
double ScaleSize(double aValue) override
void ParseSchematic(SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet, const wxString &aFileName, wxArrayString aShapes)
VECTOR2< T > RelPosSym(const VECTOR2< T > &aVec)
bool checkTextFields(const wxArrayString &aArr)
SCH_EASYEDA_PARSER(SCHEMATIC *aSchematic, PROGRESS_REPORTER *aProgressReporter, REPORTER *aReporter)
LIB_SYMBOL * ParseSymbol(const VECTOR2D &aOrigin, std::map< wxString, wxString > aParams, wxArrayString aShapes)
virtual const wxString & GetText() const override
Return the string associated with the text object.
Definition sch_field.h:139
void SetPosition(const VECTOR2I &aPosition) override
void SetText(const wxString &aText) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
const PAGE_INFO & GetPageSettings() const
Definition sch_screen.h:144
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition sch_screen.h:145
void SetStroke(const STROKE_PARAMS &aStroke) override
void AddPoint(const VECTOR2I &aPosition)
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:50
SCH_SCREEN * GetScreen() const
Definition sch_sheet.h:187
Schematic symbol object.
Definition sch_symbol.h:76
BOX2I GetBodyBoundingBox() const override
Return a bounding box for the symbol body but not the pins or fields.
Definition seg.h:38
VECTOR2I A
Definition seg.h:45
VECTOR2I B
Definition seg.h:46
const VECTOR2I & GetArcMid() const
Definition shape_arc.h:116
const VECTOR2I & GetP1() const
Definition shape_arc.h:115
const VECTOR2I & GetP0() const
Definition shape_arc.h:114
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Spin style for labels of all kinds on schematics.
Definition sch_label.h:38
SPIN_STYLE RotateCCW()
Simple container to manage line stroke parameters.
bool Import() override
Actually imports the file.
virtual double GetImageWidth() const override
Return image width from original imported file.
bool LoadFromMemory(const wxMemoryBuffer &aMemBuffer) override
Set memory buffer with content for import.
virtual double GetImageHeight() const override
Return image height from original imported file.
bool GetExcludedFromBoard(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Definition symbol.h:216
#define _(s)
@ FILLED_WITH_BG_BODYCOLOR
Definition eda_fill.h:32
@ FILLED_SHAPE
Fill with object color.
Definition eda_fill.h:31
#define ENDPOINT
ends. (Used to support dragging.)
#define STARTPOINT
When a line is selected, these flags indicate which.
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:58
void ConvertImageToLibShapes(LIB_SYMBOL *aSymbol, int unit, wxImage img, VECTOR2D pixelScale, VECTOR2D offset)
@ LAYER_DEVICE
Definition layer_ids.h:497
@ LAYER_WIRE
Definition layer_ids.h:483
std::optional< V > get_opt(const std::map< wxString, V > &aMap, const wxString &aKey)
Definition map_helpers.h:30
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:461
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition pin_type.h:32
@ PT_INPUT
usual pin input: must be connected
Definition pin_type.h:33
@ PT_OUTPUT
usual output
Definition pin_type.h:34
@ PT_BIDI
input or output (like port for a microprocessor)
Definition pin_type.h:35
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
Definition pin_type.h:42
@ PT_UNSPECIFIED
unknown electrical properties: creates always a warning when connected
Definition pin_type.h:41
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin.
Definition pin_type.h:39
PIN_ORIENTATION
The symbol library pin object orientations.
Definition pin_type.h:101
@ PIN_UP
The pin extends upwards from the connection point: Probably on the bottom side of the symbol.
Definition pin_type.h:123
@ PIN_RIGHT
The pin extends rightwards from the connection point.
Definition pin_type.h:107
@ PIN_LEFT
The pin extends leftwards from the connection point: Probably on the right side of the symbol.
Definition pin_type.h:114
@ PIN_DOWN
The pin extends downwards from the connection: Probably on the top side of the symbol.
Definition pin_type.h:131
@ RPT_SEVERITY_WARNING
static std::vector< std::vector< wxString > > RegexMatchAll(wxRegEx &aRegex, const wxString &aString)
static const std::vector< wxString > c_attributesWhitelist
static ELECTRICAL_PINTYPE ConvertElecType(const wxString &aType)
static wxString optionalField(const wxArrayString &aArr, size_t aIndex)
VECTOR2I HelperGeneratePowerPortGraphics(LIB_SYMBOL *aKsymbol, EASYEDA::POWER_FLAG_STYLE aStyle, REPORTER *aReporter)
static constexpr size_t TEXT_MIN_FIELDS
static LIB_ID EasyEdaToKiCadLibID(const wxString &aLibName, const wxString &aLibReference)
static std::vector< std::pair< wxString, std::vector< double > > > ParseImageTransform(const wxString &transformData)
EasyEDA image transformations are in the form of:
static LINE_STYLE ConvertStrokeStyle(const wxString &aStyle)
VECTOR2I HelperGeneratePowerPortGraphics(LIB_SYMBOL *aKsymbol, ASCH_POWER_PORT_STYLE aStyle, REPORTER *aReporter)
@ L_INPUT
Definition sch_label.h:98
const int scale
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
wxString UnescapeHTML(const wxString &aString)
Return a new wxString unescaped from HTML format.
@ CTX_LIBID
LINE_STYLE
Dashed line types.
@ SYM_ROTATE_CLOCKWISE
Definition symbol.h:34
@ SYM_ROTATE_COUNTERCLOCKWISE
Definition symbol.h:35
@ SYM_MIRROR_X
Definition symbol.h:40
@ USER
The field ID hasn't been set yet; field is invalid.
@ VALUE
Field Value of part, i.e. "3.3K".
KIBIS_PIN * pin
VECTOR2I center
const SHAPE_LINE_CHAIN chain
int radius
SHAPE_CIRCLE circle(c.m_circle_center, c.m_circle_radius)
@ 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
@ SCH_LINE_T
Definition typeinfo.h:159
@ SCH_SYMBOL_T
Definition typeinfo.h:168
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)