KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_io_pads_binary.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) 2026 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include "pcb_io_pads_binary.h"
21#include "pads_binary_parser.h"
22#include "pads_layer_mapper.h"
23#include "pads_pcb_shapes.h"
24
25#include <algorithm>
26#include <memory>
27#include <cmath>
28#include <functional>
29#include <set>
30
31#include <board.h>
32#include <pcb_track.h>
33#include <footprint.h>
34#include <pcb_group.h>
35#include <zone.h>
36
38#include <io/pads/pads_common.h>
39
40#include <netinfo.h>
41#include <wx/log.h>
42#include <pad.h>
43#include <pcb_shape.h>
45#include <netclass.h>
47#include <geometry/eda_angle.h>
48#include <string_utils.h>
49#include <progress_reporter.h>
50#include <reporter.h>
51#include <locale_io.h>
52#include <advanced_config.h>
53#include <geometry/shape_arc.h>
54
55
64
65
67
68
70{
71 IO_FILE_DESC desc;
72 desc.m_FileExtensions.emplace_back( "pcb" );
73 desc.m_Description = "PADS Binary";
74 return desc;
75}
76
77
79{
80 return IO_FILE_DESC( "PADS Binary Library", { "pcb" } );
81}
82
83
84long long PCB_IO_PADS_BINARY::GetLibraryTimestamp( const wxString& aLibraryPath ) const
85{
86 return 0;
87}
88
89
90bool PCB_IO_PADS_BINARY::CanReadBoard( const wxString& aFileName ) const
91{
92 if( !PCB_IO::CanReadBoard( aFileName ) )
93 return false;
94
96}
97
98
99bool PCB_IO_PADS_BINARY::CanReadLibrary( const wxString& aFileName ) const
100{
101 // The .pcb extension is shared with other tools, so a non-PADS .pcb must not be
102 // mis-identified; content-check the magic rather than trusting the extension.
103 if( !PCB_IO::CanReadLibrary( aFileName ) )
104 return false;
105
107}
108
109
110void PCB_IO_PADS_BINARY::loadBoard( const wxString& aFileName, BOARD& aBoard, bool aIsNewLoad,
111 const std::map<std::string, UTF8>* aProperties, PROJECT* aProject )
112{
113 LOCALE_IO setlocale;
114
115 if( m_reporter )
116 m_reporter->Report( _( "Starting PADS binary PCB import" ), RPT_SEVERITY_INFO );
117
119 m_progressReporter->SetNumPhases( 3 );
120
122
123 try
124 {
125 parser.Parse( aFileName );
126 }
127 catch( const std::exception& e )
128 {
129 THROW_IO_ERROR( wxString::Format( "Error parsing PADS binary file: %s", e.what() ) );
130 }
131
132 m_loadBoard = &aBoard;
133 m_parser = &parser;
134 m_converter = std::make_unique<PADS_PCB_CONVERTER>( m_loadBoard, m_reporter );
135
136 try
137 {
139 m_progressReporter->BeginPhase( 1 );
140
142
143 // Nets are created before the geometry that references them; loadTracksAndVias resolves
144 // each track and via net against this table.
145 loadNets();
146
148 m_progressReporter->BeginPhase( 2 );
149
151
152 // Cluster groups reference the footprints loadFootprints just added, so they follow it.
157 m_converter->LoadTexts( m_parser->GetTexts() );
159 loadZones();
160 m_converter->LoadKeepouts( m_parser->GetKeepouts() );
161 m_converter->LoadDimensions( m_parser->GetDimensions() );
162
163 // Appending merges into a board that already has its own rule file, so nothing would
164 // ever load rules written beside the PADS source
165 if( aIsNewLoad )
166 m_converter->WriteDiffPairRules( aFileName, m_parser->GetDiffPairs() );
167
168 m_converter->ReportStatistics();
169 }
170 catch( ... )
171 {
173 throw;
174 }
175
177}
178
179
181{
182 std::vector<PADS_IO::LAYER_INFO> padsLayerInfos = m_parser->GetLayerInfos();
183
184 // Binary layer records often carry no function code, so the layer name is the only
185 // remaining clue to what the layer is for.
186 m_converter->SetupLayers( padsLayerInfos, m_parser->GetParameters().layer_count, m_layer_mapping_handler, true );
187
188 // Binary files always use BASIC units, and the stackup thicknesses are BASIC too, so the
189 // units have to be settled before anything is scaled.
190 m_converter->UnitConverter().SetBasicUnitsMode( true );
192
193 m_converter->BuildStackup( padsLayerInfos );
194
195 const PADS_IO::POINT& origin = m_parser->GetParameters().origin;
196
197 m_converter->SetOrigin( origin.x, origin.y );
198
199 // Fall back to the board-outline center only when there is no DFT origin; the DFT origin
200 // gives exact coordinates and overriding it would shift all parts.
201 if( origin.x == 0.0 && origin.y == 0.0 )
202 m_converter->SetOriginFromOutlines( m_parser->GetBoardOutlines() );
203}
204
205
207{
208 const auto& nets = m_parser->GetNets();
209
210 for( const auto& padsNet : nets )
211 m_converter->EnsureNet( padsNet.name );
212
213 // Key on the decoded text so buildPad() can match against the reference it already built.
214 // ToStdString() would re-encode through the locale, which LOCALE_IO has pinned to "C"
215 for( const auto& padsNet : nets )
216 {
217 for( const PADS_IO::NET_PIN& pin : padsNet.pins )
218 {
219 wxString key = PADS_COMMON::ConvertText( pin.ref_des ) + wxT( "." )
220 + PADS_COMMON::ConvertText( pin.pin_name );
221 m_pinToNetMap[key] = padsNet.name;
222 }
223 }
224
225 // One KiCad NETCLASS per PADS net class, with its member nets. Empty on boards with no
226 // net classes (such as the v0x2021 dialect), where this is a no-op.
227 const std::vector<PADS_IO::BIN_NET_CLASS_DEF>& netClasses = m_parser->GetNetClasses();
228 const std::vector<PADS_IO::DIFF_PAIR_DEF>& diffPairs = m_parser->GetDiffPairs();
229
230 if( netClasses.empty() && diffPairs.empty() )
231 return;
232
233 std::shared_ptr<NET_SETTINGS> netSettings = m_loadBoard->GetDesignSettings().m_NetSettings;
234
235 // Without this flag BOARD::SetProject drops the imported net classes
236 m_loadBoard->m_LegacyNetclassesLoaded = true;
237
238 for( const PADS_IO::BIN_NET_CLASS_DEF& nc : netClasses )
239 {
240 if( nc.name.empty() || nc.nets.empty() )
241 continue;
242
243 wxString className = PADS_COMMON::ConvertText( nc.name );
244
245 if( !netSettings->HasNetclass( className ) )
246 {
247 std::shared_ptr<NETCLASS> kicadClass = std::make_shared<NETCLASS>( className );
248
249 // KiCad's netclass carries one clearance and one track width; the PADS min/max
250 // values are advisory and dropped.
251 if( nc.hasRuleValues )
252 {
253 if( nc.clearance > 0 )
254 kicadClass->SetClearance( scaleSize( nc.clearance ) );
255
256 if( nc.trackWidth > 0 )
257 kicadClass->SetTrackWidth( scaleSize( nc.trackWidth ) );
258 }
259
260 netSettings->SetNetclass( className, kicadClass );
261 }
262
263 // Label assignments are rebuilt from schematic labels on every connectivity pass, so a
264 // board-side membership has to be a pattern assignment to survive
265 for( const std::string& netname : nc.nets )
266 {
267 wxString kicadNetname = PADS_COMMON::ConvertInvertedNetName( netname );
268 wxString literalNetnamePattern = EscapeString( kicadNetname, CTX_REGEX );
269 netSettings->SetNetclassPatternAssignment( literalNetnamePattern, className );
270 }
271 }
272
273 // Each differential pair becomes one DiffPair_<name> net class.
274 for( const PADS_IO::DIFF_PAIR_DEF& dp : diffPairs )
275 {
276 if( dp.name.empty() )
277 continue;
278
279 wxString dpClassName = wxString::Format( wxT( "DiffPair_%s" ), PADS_COMMON::ConvertText( dp.name ) );
280 std::shared_ptr<NETCLASS> dpNetclass = std::make_shared<NETCLASS>( dpClassName );
281
282 if( dp.gap > 0 )
283 dpNetclass->SetDiffPairGap( scaleSize( dp.gap ) );
284
285 if( dp.width > 0 )
286 {
287 dpNetclass->SetDiffPairWidth( scaleSize( dp.width ) );
288 dpNetclass->SetTrackWidth( scaleSize( dp.width ) );
289 }
290
291 netSettings->SetNetclass( dpClassName, dpNetclass );
292
293 if( !dp.positive_net.empty() )
294 netSettings->SetNetclassPatternAssignment( PADS_COMMON::ConvertInvertedNetName( dp.positive_net ),
295 dpClassName );
296
297 if( !dp.negative_net.empty() )
298 netSettings->SetNetclassPatternAssignment( PADS_COMMON::ConvertInvertedNetName( dp.negative_net ),
299 dpClassName );
300 }
301}
302
303
305{
306 const auto& decals = m_parser->GetPartDecals();
307 const auto& parts = m_parser->GetParts();
308
309 for( const auto& padsPart : parts )
310 {
311 FOOTPRINT* footprint = new FOOTPRINT( m_loadBoard );
312 footprint->SetReference( PADS_COMMON::ConvertText( padsPart.name ) );
313
314 KIID symbolUuid = PADS_COMMON::GenerateDeterministicUuid( padsPart.name );
316 path.push_back( symbolUuid );
317 footprint->SetPath( path );
318
319 std::string decalName = padsPart.decal;
320
321 LIB_ID fpid;
322
323 if( !decalName.empty() )
324 fpid.SetLibItemName( PADS_COMMON::ConvertText( decalName ) );
325 else
326 fpid.SetLibItemName( PADS_COMMON::ConvertText( padsPart.name ) );
327
328 footprint->SetFPID( fpid );
329
330 // A part referencing a *PARTTYPE alias (often a manufacturer part number) shows that
331 // alias as its value, not the physical decal it resolves to; see linkPartsToDecals().
332 footprint->SetValue( PADS_COMMON::ConvertText( padsPart.value.empty() ? padsPart.decal
333 : padsPart.value ) );
334
335 footprint->SetPosition( scalePoint( padsPart.location.x, padsPart.location.y ) );
336 footprint->SetOrientation( EDA_ANGLE( padsPart.rotation, DEGREES_T ) );
337 footprint->SetLayer( F_Cu );
338 footprint->Reference().SetLayer( F_Fab );
339 footprint->Reference().SetVisible( false );
340 footprint->Value().SetLayer( F_Fab );
341 footprint->Value().SetVisible( false );
342
343 auto decalIt = decals.find( decalName );
344
345 if( decalIt == decals.end() )
346 {
347 if( m_reporter )
348 {
349 m_reporter->Report( wxString::Format( _( "Part '%s': decal '%s' not found, no pads created" ),
350 padsPart.name, decalName ),
352 }
353 }
354
355 if( decalIt != decals.end() )
356 {
357 const PADS_IO::PART_DECAL& decal = decalIt->second;
358 EDA_ANGLE partOrient( padsPart.rotation, DEGREES_T );
359
360 for( size_t termIdx = 0; termIdx < decal.terminals.size(); ++termIdx )
361 buildPad( footprint, decal, termIdx, partOrient );
362 }
363
364 for( const PADS_IO::ATTRIBUTE& attribute : padsPart.attributes )
365 {
366 PCB_FIELD* field = nullptr;
367
368 if( attribute.name == "Ref.Des." )
369 field = &footprint->Reference();
370 else if( attribute.name == "Part Type" )
371 field = &footprint->Value();
372
373 if( !field )
374 continue;
375
376 int scaledSize = scaleSize( attribute.height );
377 int charHeight = static_cast<int>( scaledSize * ADVANCED_CFG::GetCfg().m_PadsPcbTextHeightScale );
378 int charWidth = static_cast<int>( scaledSize * ADVANCED_CFG::GetCfg().m_PadsPcbTextWidthScale );
379 field->SetTextSize( VECTOR2I( charWidth, charHeight ) );
380
381 if( attribute.width > 0 )
382 field->SetTextThickness( scaleSize( attribute.width ) );
383
384 VECTOR2I offset( scaleSize( attribute.x ), -scaleSize( attribute.y ) );
385 EDA_ANGLE partAngle( padsPart.rotation, DEGREES_T );
386 RotatePoint( offset, partAngle );
387
388 EDA_ANGLE textAngle( attribute.orientation + padsPart.rotation, DEGREES_T );
389 VECTOR2I textShift( -ADVANCED_CFG::GetCfg().m_PadsTextAnchorOffsetNm, 0 );
390 RotatePoint( textShift, textAngle );
391
392 field->SetPosition( footprint->GetPosition() + offset + textShift );
393 field->SetTextAngle( textAngle );
394 field->SetKeepUpright( false );
395 field->SetVisible( attribute.visible );
396 field->SetLayer( F_Fab );
397
398 if( attribute.hjust == "LEFT" )
400 else if( attribute.hjust == "RIGHT" )
402 else
404
405 if( attribute.vjust == "UP" )
407 else if( attribute.vjust == "DOWN" )
409 else
411 }
412
413 m_loadBoard->Add( footprint );
414
415 if( padsPart.bottom_layer )
416 {
417 footprint->Flip( footprint->GetPosition(), FLIP_DIRECTION::LEFT_RIGHT );
418
419 for( PAD* pad : footprint->Pads() )
420 {
421 if( pad->GetAttribute() == PAD_ATTRIB::PTH && pad->Padstack().Mode() == PADSTACK::MODE::NORMAL )
422 {
423 pad->SetLayerSet( PAD::PTHMask() | ( pad->GetLayerSet() & LSET( { F_Paste, B_Paste } ) ) );
424 }
425 }
426 }
427
428 m_partFootprints.push_back( footprint );
429 }
430}
431
432
433void PCB_IO_PADS_BINARY::buildPad( FOOTPRINT* aFootprint, const PADS_IO::PART_DECAL& aDecal, size_t aTermIdx,
434 const EDA_ANGLE& aPartOrient )
435{
436 const auto& term = aDecal.terminals[aTermIdx];
437 PAD* pad = new PAD( aFootprint );
438 aFootprint->Add( pad );
439
440 pad->SetNumber( PADS_COMMON::ConvertText( term.name ) );
441
442 VECTOR2I padPos( scaleSize( term.x ), -scaleSize( term.y ) );
443 RotatePoint( padPos, aPartOrient );
444 pad->SetPosition( aFootprint->GetPosition() + padPos );
445
446 int pinNum = static_cast<int>( aTermIdx + 1 );
447 auto stackIt = aDecal.pad_stacks.find( pinNum );
448
449 if( stackIt == aDecal.pad_stacks.end() )
450 stackIt = aDecal.pad_stacks.find( 0 );
451
452 if( stackIt != aDecal.pad_stacks.end() && !stackIt->second.empty() )
453 {
454 const std::vector<PADS_IO::PAD_STACK_LAYER>& stack = stackIt->second;
455 const PADS_IO::PAD_STACK_LAYER& layerDef = stack[0];
456
457 std::set<int> serializedLayers;
458 bool ambiguousLayers = false;
459
460 // A relief or anti-pad row repeats the layer ordinal of the copper row it qualifies, so
461 // counting it here would read every plane-relief padstack as ambiguous
462 for( auto it = std::next( stack.begin() ); it != stack.end(); ++it )
463 {
464 if( PADS_IO::IsCopperPadRow( *it ) )
465 ambiguousLayers |= !serializedLayers.insert( it->layer ).second;
466 }
467
468 bool modernZeroDefaultSmd = m_parser->GetVersion() == 0x2024 && layerDef.drill == 0 && layerDef.sizeA <= 0;
469 bool legacyZeroDefaultSmd = m_parser->GetVersion() == 0x2022 && layerDef.drill == 0
470 && layerDef.sizeA <= 0;
471 bool zeroDefaultSmd = modernZeroDefaultSmd || legacyZeroDefaultSmd;
472 bool hasExplicitLayers = stack.size() > 1 && ( layerDef.drill > 0 || zeroDefaultSmd ) && !ambiguousLayers;
473 LSET layerSet;
474
475 if( hasExplicitLayers )
476 {
477 pad->Padstack().SetMode( PADSTACK::MODE::FRONT_INNER_BACK );
478 bool appliedExplicitLayer = false;
479 const PADS_IO::PAD_STACK_LAYER* inheritedLegacyShape = nullptr;
480
481 if( legacyZeroDefaultSmd )
482 {
483 auto inherited = std::find_if( stack.begin(), stack.end(),
484 []( const PADS_IO::PAD_STACK_LAYER& aLayer )
485 {
486 return aLayer.layer == 0 && aLayer.sizeA > 0;
487 } );
488
489 if( inherited != stack.end() )
490 inheritedLegacyShape = &*inherited;
491 }
492
493 for( const PADS_IO::PAD_STACK_LAYER& stackLayer : stack )
494 {
495 if( stackLayer.sizeA <= 0 )
496 continue;
497
498 // RT/ST are plane thermal-relief spoke patterns and RA/SA are anti-pad
499 // clearances. Neither is pad copper, so they must not reach the shape below.
500 // KiCad derives the relief geometry from the zone, so an RT/ST row only says
501 // that this pad connects through spokes rather than solid copper.
502 if( PADS_IO::IsThermalReliefPadRow( stackLayer ) )
503 {
504 pad->SetLocalZoneConnection( ZONE_CONNECTION::THERMAL );
505 continue;
506 }
507
508 if( PADS_IO::IsAntiPadRow( stackLayer ) )
509 continue;
510
511 if( modernZeroDefaultSmd && stackLayer.layer == 0 )
512 continue;
513
514 if( legacyZeroDefaultSmd && stackLayer.layer <= 0 )
515 continue;
516
517 PCB_LAYER_ID kicadLayer = UNDEFINED_LAYER;
518
519 if( modernZeroDefaultSmd && stackLayer.layer == -1 )
520 {
521 kicadLayer = B_Paste;
522 layerSet.set( B_Paste );
523 }
524 else if( stackLayer.layer == -2 )
525 {
526 kicadLayer = F_Cu;
527 layerSet.set( F_Cu );
528 }
529 else if( stackLayer.layer == -1 )
530 {
531 kicadLayer = B_Cu;
532 layerSet.set( B_Cu );
533 }
534 else if( stackLayer.layer == 0 )
535 {
536 if( m_loadBoard->GetCopperLayerCount() > 2 )
537 {
538 kicadLayer = In1_Cu;
539
540 for( int layer = 2; layer < m_parser->GetParameters().layer_count; ++layer )
541 {
542 PCB_LAYER_ID inner = getMappedLayer( layer );
543
544 if( IsCopperLayer( inner ) )
545 layerSet.set( inner );
546 }
547 }
548 }
549 else
550 {
551 int padsLayer = stackLayer.layer;
552 kicadLayer = getMappedLayer( padsLayer );
553
554 if( kicadLayer != UNDEFINED_LAYER )
555 layerSet.set( kicadLayer );
556 }
557
558 if( kicadLayer != UNDEFINED_LAYER )
559 {
560 PADS_IO::PAD_STACK_LAYER appliedLayer = stackLayer;
561
562 if( modernZeroDefaultSmd )
563 {
564 appliedLayer.sizeA *= 1.5;
565 appliedLayer.sizeB *= 1.5;
566 appliedLayer.corner_radius *= 1.5;
567 }
568 else if( inheritedLegacyShape )
569 {
570 appliedLayer.shape = inheritedLegacyShape->shape;
571 appliedLayer.sizeA = inheritedLegacyShape->sizeA * 1.5;
572 appliedLayer.sizeB = inheritedLegacyShape->sizeB * 1.5;
573 }
574
575 applyPadShape( pad, appliedLayer, kicadLayer );
576 appliedExplicitLayer = true;
577
578 if( zeroDefaultSmd && appliedLayer.shape == "R" )
579 pad->SetRoundRectRadiusRatio( kicadLayer, 0.25 );
580 }
581 }
582
583 if( zeroDefaultSmd && !appliedExplicitLayer )
584 {
585 applyPadShape( pad, layerDef, F_Cu );
586 applyPadShape( pad, layerDef, F_Mask );
587 applyPadShape( pad, layerDef, F_Paste );
588 layerSet = LSET( { F_Cu, F_Mask, F_Paste } );
589 }
590 }
591 else
592 {
593 applyPadShape( pad, layerDef, F_Cu );
594 }
595
596 pad->SetOrientation( aPartOrient + EDA_ANGLE( layerDef.rotation, DEGREES_T ) );
597
598 int drill = scaleSize( layerDef.drill );
599
600 if( layerDef.slot_length > 0 && layerDef.slot_length != layerDef.drill )
601 {
602 pad->SetDrillShape( PAD_DRILL_SHAPE::OBLONG );
603
604 int drillMajor = scaleSize( layerDef.slot_length );
605 double relativeAngle = std::fmod( layerDef.slot_orientation - layerDef.rotation, 360.0 );
606
607 if( relativeAngle < 0 )
608 relativeAngle += 360.0;
609
610 bool vertical = ( relativeAngle > 45.0 && relativeAngle < 135.0 )
611 || ( relativeAngle > 225.0 && relativeAngle < 315.0 );
612 pad->SetDrillSize( vertical ? VECTOR2I( drill, drillMajor ) : VECTOR2I( drillMajor, drill ) );
613 }
614 else
615 {
616 pad->SetDrillSize( VECTOR2I( drill, drill ) );
617 }
618
619 if( drill == 0 )
620 {
621 pad->SetAttribute( PAD_ATTRIB::SMD );
622
623 if( hasExplicitLayers )
624 {
625 if( !zeroDefaultSmd )
626 {
627 if( layerSet.test( F_Cu ) )
628 layerSet |= LSET( { F_Mask, F_Paste } );
629
630 if( layerSet.test( B_Cu ) )
631 layerSet |= LSET( { B_Mask, B_Paste } );
632 }
633
634 pad->SetLayerSet( layerSet );
635 }
636 else
637 {
638 pad->SetLayerSet( LSET( { F_Cu, F_Mask, F_Paste } ) );
639 }
640 }
641 else
642 {
643 // Keep whatever mask and paste rows the stack carried, the way the ASCII path does
644 LSET maskPasteBits = layerSet & LSET( { F_Mask, B_Mask, F_Paste, B_Paste } );
645
646 pad->Padstack().SetMode( PADSTACK::MODE::NORMAL );
647 applyPadShape( pad, layerDef, F_Cu );
648
649 if( layerDef.plated )
650 {
651 pad->SetAttribute( PAD_ATTRIB::PTH );
652 pad->SetLayerSet( PAD::PTHMask() | maskPasteBits );
653 }
654 else
655 {
656 pad->SetAttribute( PAD_ATTRIB::NPTH );
657 pad->SetNumber( wxString() );
658 pad->SetLayerSet( PAD::UnplatedHoleMask() | maskPasteBits );
659 }
660 }
661 }
662 else
663 {
664 // 38100 basic units = 1 mil; default 60 mil pad.
665 int defaultPad = scaleSize( 60.0 * PADS_IO::SDB_BASIC_PER_MIL );
666 pad->SetSize( F_Cu, VECTOR2I( defaultPad, defaultPad ) );
667 pad->SetShape( F_Cu, PAD_SHAPE::CIRCLE );
668 pad->SetAttribute( PAD_ATTRIB::PTH );
669 pad->SetLayerSet( PAD::PTHMask() );
670 }
671
672 // An unplated hole is mechanical; joining it to a net pulls ratsnest to a mounting hole
673 if( pad->GetAttribute() == PAD_ATTRIB::NPTH )
674 return;
675
676 auto netIt = m_pinToNetMap.find( aFootprint->GetReference() + wxT( "." )
677 + PADS_COMMON::ConvertText( term.name ) );
678
679 if( netIt != m_pinToNetMap.end() )
680 {
681 NETINFO_ITEM* net = m_loadBoard->FindNet( PADS_COMMON::ConvertInvertedNetName( netIt->second ) );
682
683 if( net )
684 pad->SetNet( net );
685 }
686}
687
688
690 PCB_LAYER_ID aKiCadLayer )
691{
692 auto scaledPadSize = [&]( double aValue )
693 {
694 return std::max( m_minObjectSize, scaleSize( aValue ) );
695 };
696
697 VECTOR2I size( scaledPadSize( aLayer.sizeA ), scaledPadSize( aLayer.sizeA ) );
698
699 auto applyCornerRadius = [&]( const VECTOR2I& aSize, bool aDefaultRound )
700 {
701 if( aLayer.corner_radius > 0 )
702 {
703 int radius = scaledPadSize( aLayer.corner_radius );
704 int minimumDimension = std::min( aSize.x, aSize.y );
705 double ratio = minimumDimension > 0
706 ? std::min( static_cast<double>( radius ) / minimumDimension, 0.5 )
707 : 0.25;
708
709 aPad->SetShape( aKiCadLayer, PAD_SHAPE::ROUNDRECT );
710 aPad->SetRoundRectRadiusRatio( aKiCadLayer, ratio );
711 }
712 else if( aDefaultRound )
713 {
714 aPad->SetShape( aKiCadLayer, PAD_SHAPE::ROUNDRECT );
715 aPad->SetRoundRectRadiusRatio( aKiCadLayer, 0.25 );
716 }
717 };
718
719 aPad->SetShape( aKiCadLayer, PADS_PCB::PadsShapeToKiCad( aLayer.shape ) );
720
721 if( aLayer.shape == "O" || aLayer.shape == "OF" )
722 {
723 VECTOR2I ovalSize( scaledPadSize( aLayer.sizeB ), scaledPadSize( aLayer.sizeA ) );
724 aPad->SetSize( aKiCadLayer, ovalSize );
725 }
726 else if( aLayer.shape == "RF" )
727 {
728 VECTOR2I rectSize( scaledPadSize( aLayer.sizeB ), scaledPadSize( aLayer.sizeA ) );
729 aPad->SetSize( aKiCadLayer, rectSize );
730 applyCornerRadius( rectSize, false );
731
732 if( aLayer.finger_offset != 0 )
733 {
734 int offset = scaleSize( aLayer.finger_offset );
735 VECTOR2I padOffset( offset, 0 );
736 RotatePoint( padOffset, EDA_ANGLE( aLayer.rotation, DEGREES_T ) );
737 aPad->SetOffset( aKiCadLayer, padOffset );
738 }
739 }
740 else if( aLayer.shape == "RC" || aLayer.shape == "OC" )
741 {
742 VECTOR2I rrSize( scaledPadSize( aLayer.sizeB ), scaledPadSize( aLayer.sizeA ) );
743 aPad->SetSize( aKiCadLayer, rrSize );
744 applyCornerRadius( rrSize, true );
745 }
746 else
747 {
748 aPad->SetSize( aKiCadLayer, size );
749
750 if( aLayer.shape == "S" || aLayer.shape == "ST" )
751 applyCornerRadius( size, false );
752 }
753}
754
755
757{
758 const std::vector<PADS_IO::PART_CLUSTER>& clusters = m_parser->GetClusters();
759
760 if( clusters.empty() )
761 return;
762
763 // One PCB_GROUP per cluster, keyed by the 1-based CLSTID the membership field references.
764 std::map<int, PCB_GROUP*> clusterGroups;
765
766 for( const PADS_IO::PART_CLUSTER& cluster : clusters )
767 {
769 group->SetName( PADS_COMMON::ConvertText( cluster.name ) );
770 m_loadBoard->Add( group );
771 clusterGroups[cluster.id] = group;
772 }
773
774 // m_partFootprints is indexed by part index, so the part-index-keyed membership map
775 // resolves directly to a footprint.
776 const std::map<size_t, int>& partClusterIds = m_parser->GetPartClusterIds();
777
778 for( size_t i = 0; i < m_partFootprints.size(); ++i )
779 {
780 auto idIt = partClusterIds.find( i );
781
782 if( idIt == partClusterIds.end() || idIt->second <= 0 )
783 continue;
784
785 auto groupIt = clusterGroups.find( idIt->second );
786
787 if( groupIt != clusterGroups.end() )
788 groupIt->second->AddItem( m_partFootprints[i] );
789 }
790}
791
792
794 const PADS_IO::ARC_POINT& aCurr )
795{
796 aShape->SetShape( SHAPE_T::ARC );
797
798 // A start/end/center triple is ambiguous (minor vs major arc) for shallow arcs, so
799 // sample a midpoint at the sweep midpoint and pass start/mid/end; scaleCoord applies the
800 // Y-axis flip uniformly.
801 double midAngle = ( aCurr.arc.start_angle + aCurr.arc.delta_angle / 2.0 ) * M_PI / 180.0;
802 double midX = aCurr.arc.cx + aCurr.arc.radius * std::cos( midAngle );
803 double midY = aCurr.arc.cy + aCurr.arc.radius * std::sin( midAngle );
804
805 VECTOR2I start = scalePoint( aPrev.x, aPrev.y );
806 VECTOR2I mid = scalePoint( midX, midY );
807 VECTOR2I end = scalePoint( aCurr.x, aCurr.y );
808
809 aShape->SetArcGeometry( start, mid, end );
810}
811
812
814{
815 for( const PADS_IO::POLYLINE& polyline : m_parser->GetBoardOutlines() )
816 {
817 const auto& pts = polyline.points;
818
819 if( pts.size() < 2 )
820 continue;
821
822 for( size_t i = 0; i < pts.size() - 1; ++i )
823 {
824 const PADS_IO::ARC_POINT& p1 = pts[i];
825 const PADS_IO::ARC_POINT& p2 = pts[i + 1];
826
827 if( std::abs( p1.x - p2.x ) < 0.001 && std::abs( p1.y - p2.y ) < 0.001 )
828 continue;
829
830 PCB_SHAPE* shape = new PCB_SHAPE( m_loadBoard );
831
832 if( p2.is_arc )
833 {
834 setBoardOutlineArc( shape, p1, p2 );
835 }
836 else
837 {
838 shape->SetShape( SHAPE_T::SEGMENT );
839 shape->SetStart( scalePoint( p1.x, p1.y ) );
840 shape->SetEnd( scalePoint( p2.x, p2.y ) );
841 }
842
843 shape->SetWidth( scaleSize( polyline.width ) );
844 shape->SetLayer( Edge_Cuts );
845 m_loadBoard->Add( shape );
846 }
847
848 if( polyline.closed && pts.size() > 2 )
849 {
850 const PADS_IO::ARC_POINT& pLast = pts.back();
851 const PADS_IO::ARC_POINT& pFirst = pts.front();
852
853 bool needsClosing = ( std::abs( pLast.x - pFirst.x ) > 0.001 || std::abs( pLast.y - pFirst.y ) > 0.001 );
854
855 if( needsClosing )
856 {
857 PCB_SHAPE* shape = new PCB_SHAPE( m_loadBoard );
858
859 if( pFirst.is_arc )
860 {
861 setBoardOutlineArc( shape, pLast, pFirst );
862 }
863 else
864 {
865 shape->SetShape( SHAPE_T::SEGMENT );
866 shape->SetStart( scalePoint( pLast.x, pLast.y ) );
867 shape->SetEnd( scalePoint( pFirst.x, pFirst.y ) );
868 }
869
870 shape->SetWidth( scaleSize( polyline.width ) );
871 shape->SetLayer( Edge_Cuts );
872 m_loadBoard->Add( shape );
873 }
874 }
875 }
876}
877
878
880{
881 for( const PADS_IO::GRAPHIC_LINE& graphic : m_parser->GetGraphicLines() )
882 {
883 PCB_LAYER_ID layer = getMappedLayer( graphic.layer );
884
885 if( layer == UNDEFINED_LAYER )
886 continue;
887
888 const std::vector<PADS_IO::ARC_POINT>& points = graphic.points;
889
890 if( points.size() == 1 && points[0].is_arc && std::abs( points[0].arc.delta_angle - 360.0 ) < 0.1 )
891 {
892 PCB_SHAPE* shape = new PCB_SHAPE( m_loadBoard );
893 VECTOR2I center = scalePoint( points[0].arc.cx, points[0].arc.cy );
894 int radius = std::max( scaleSize( points[0].arc.radius ), m_minObjectSize );
895 shape->SetShape( SHAPE_T::CIRCLE );
896 shape->SetCenter( center );
897 shape->SetEnd( VECTOR2I( center.x + radius, center.y ) );
898 shape->SetWidth( scaleSize( graphic.width ) );
899 shape->SetLayer( layer );
900 m_loadBoard->Add( shape );
901 continue;
902 }
903
904 if( points.size() < 2 )
905 continue;
906
907 for( size_t index = 1; index < points.size(); ++index )
908 {
909 const PADS_IO::ARC_POINT& previous = points[index - 1];
910 const PADS_IO::ARC_POINT& current = points[index];
911
912 if( std::abs( previous.x - current.x ) < 0.001 && std::abs( previous.y - current.y ) < 0.001 )
913 continue;
914
915 PCB_SHAPE* shape = new PCB_SHAPE( m_loadBoard );
916
917 if( current.is_arc )
918 {
919 setBoardOutlineArc( shape, previous, current );
920 }
921 else
922 {
923 shape->SetShape( SHAPE_T::SEGMENT );
924 shape->SetStart( scalePoint( previous.x, previous.y ) );
925 shape->SetEnd( scalePoint( current.x, current.y ) );
926 }
927
928 shape->SetWidth( scaleSize( graphic.width ) );
929 shape->SetLayer( layer );
930 m_loadBoard->Add( shape );
931 }
932 }
933}
934
935
937{
938 const auto& routes = m_parser->GetRoutes();
939 for( const auto& route : routes )
940 {
941 NETINFO_ITEM* net = nullptr;
942
943 if( !route.net_name.empty() )
944 {
945 net = m_loadBoard->FindNet( PADS_COMMON::ConvertInvertedNetName( route.net_name ) );
946
947 if( !net )
948 {
949 if( m_reporter )
950 {
951 m_reporter->Report( wxString::Format( _( "Route net '%s' not found, skipping" ), route.net_name ),
953 }
954
955 continue;
956 }
957 }
958
959 for( const auto& track_def : route.tracks )
960 {
961 if( track_def.points.size() < 2 )
962 continue;
963
964 PCB_LAYER_ID track_layer = getMappedLayer( track_def.layer );
965
966 // An importer is best effort, and a route layer the user mapped to a non-copper
967 // layer is ordinary input, so drop the track rather than the whole board
968 if( !IsCopperLayer( track_layer ) )
969 {
970 if( m_reporter )
971 {
972 m_reporter->Report( wxString::Format( _( "Skipped a route on non-copper or unmapped "
973 "PADS layer %d." ),
974 track_def.layer ),
976 }
977
978 continue;
979 }
980
981 int track_width = scaleSize( track_def.width );
982
983 if( track_width <= 0 )
984 {
985 if( m_reporter )
986 {
987 m_reporter->Report( wxString::Format( _( "Skipped a non-positive-width route on PADS layer %d." ),
988 track_def.layer ),
990 }
991
992 continue;
993 }
994
995 for( size_t i = 0; i < track_def.points.size() - 1; ++i )
996 {
997 const PADS_IO::ARC_POINT& p1 = track_def.points[i];
998 const PADS_IO::ARC_POINT& p2 = track_def.points[i + 1];
999
1000 VECTOR2I start = scalePoint( p1.x, p1.y );
1001 VECTOR2I end = scalePoint( p2.x, p2.y );
1002
1003 // Route-cell endpoints retain quantization residue that the PADS writer
1004 // collapses when exporting the same route to ASCII.
1005 constexpr int MIN_ROUTE_LENGTH = 500;
1006 int64_t deltaX = static_cast<int64_t>( end.x ) - start.x;
1007 int64_t deltaY = static_cast<int64_t>( end.y ) - start.y;
1008
1009 if( deltaX * deltaX + deltaY * deltaY < MIN_ROUTE_LENGTH * MIN_ROUTE_LENGTH )
1010 continue;
1011
1012 if( p2.is_arc )
1013 {
1014 VECTOR2I center = scalePoint( p2.arc.cx, p2.arc.cy );
1015
1016 bool clockwise = ( p2.arc.delta_angle < 0 );
1017
1018 SHAPE_ARC shapeArc;
1019 shapeArc.ConstructFromStartEndCenter( start, end, center, clockwise, track_width );
1020
1021 PCB_ARC* arc = new PCB_ARC( m_loadBoard, &shapeArc );
1022
1023 if( net )
1024 arc->SetNet( net );
1025
1026 arc->SetWidth( track_width );
1027 arc->SetLayer( track_layer );
1028 m_loadBoard->Add( arc );
1029 }
1030 else
1031 {
1032 PCB_TRACK* track = new PCB_TRACK( m_loadBoard );
1033
1034 if( net )
1035 track->SetNet( net );
1036
1037 track->SetWidth( track_width );
1038 track->SetLayer( track_layer );
1039 track->SetStart( start );
1040 track->SetEnd( end );
1041 m_loadBoard->Add( track );
1042 }
1043 }
1044 }
1045
1046 for( const auto& via_def : route.vias )
1047 {
1048 VECTOR2I pos = scalePoint( via_def.location.x, via_def.location.y );
1049
1050 std::unique_ptr<PCB_VIA> via = std::make_unique<PCB_VIA>( m_loadBoard );
1051
1052 if( net )
1053 via->SetNet( net );
1054
1055 via->SetPosition( pos );
1056
1057 const double viaDrill = via_def.stack.front().drill;
1058 via->Padstack().SetMode( PADSTACK::MODE::FRONT_INNER_BACK );
1059
1060 for( const PADS_IO::PAD_STACK_LAYER& layer : via_def.stack )
1061 {
1062 if( layer.sizeA <= 0 || !PADS_IO::IsCopperPadRow( layer ) )
1063 continue;
1064
1065 int width = scaleSize( layer.sizeA );
1066
1067 if( layer.layer == -2 )
1068 via->SetWidth( F_Cu, width );
1069 else if( layer.layer == 0 )
1070 via->SetWidth( PADSTACK::INNER_LAYERS, width );
1071 else if( layer.layer == -1 )
1072 via->SetWidth( B_Cu, width );
1073 }
1074
1075 via->SetDrill( scaleSize( viaDrill ) );
1076 PCB_LAYER_ID startLayer = getMappedLayer( via_def.start_layer );
1077 PCB_LAYER_ID endLayer = getMappedLayer( via_def.end_layer );
1078
1079 // A one-layer file defaults every via to the same span, so a whole board must not be
1080 // lost to a via the layer table cannot place
1081 if( !IsCopperLayer( startLayer ) || !IsCopperLayer( endLayer ) || startLayer == endLayer )
1082 {
1083 if( m_reporter )
1084 {
1085 m_reporter->Report( wxString::Format( _( "Skipped a via on net '%s' with an unusable "
1086 "PADS layer span %d,%d." ),
1087 PADS_COMMON::ConvertText( route.net_name ),
1088 via_def.start_layer, via_def.end_layer ),
1090 }
1091
1092 continue;
1093 }
1094
1095 // SetLayerPair sanitizes the span against the current via type and PCB_VIA is
1096 // constructed as THROUGH, so the type has to be set first or the decoded span is
1097 // overwritten with F_Cu/B_Cu and every blind or buried via becomes full stack
1098 if( ( startLayer == F_Cu && endLayer == B_Cu )
1099 || ( startLayer == B_Cu && endLayer == F_Cu ) )
1100 via->SetViaType( VIATYPE::THROUGH );
1101 else if( std::abs( via_def.start_layer - via_def.end_layer ) == 1
1102 && ( startLayer == F_Cu || startLayer == B_Cu || endLayer == F_Cu || endLayer == B_Cu ) )
1103 via->SetViaType( VIATYPE::MICROVIA );
1104 else if( startLayer == F_Cu || startLayer == B_Cu || endLayer == F_Cu || endLayer == B_Cu )
1105 via->SetViaType( VIATYPE::BLIND );
1106 else
1107 via->SetViaType( VIATYPE::BURIED );
1108
1109 via->SetLayerPair( startLayer, endLayer );
1110
1111 m_loadBoard->Add( via.release() );
1112 }
1113 }
1114}
1115
1116
1118{
1119 const auto& copperShapes = m_parser->GetCopperShapes();
1120
1121 for( const PADS_IO::COPPER_SHAPE& copper : copperShapes )
1122 {
1123 if( !copper.filled || copper.is_cutout || copper.outline.size() < 3 )
1124 continue;
1125
1126 PCB_LAYER_ID layer = getMappedLayer( copper.layer );
1127
1128 if( layer == UNDEFINED_LAYER )
1129 {
1130 if( m_reporter )
1131 {
1132 m_reporter->Report( wxString::Format( _( "COPPER item on unmapped layer %d" ), copper.layer ),
1134 }
1135
1136 continue;
1137 }
1138
1139 SHAPE_LINE_CHAIN outline;
1140
1141 for( const PADS_IO::ARC_POINT& pt : copper.outline )
1142 outline.Append( scalePoint( pt.x, pt.y ) );
1143
1144 outline.SetClosed( true );
1145
1146 if( !IsCopperLayer( layer ) )
1147 {
1149 shape->SetLayer( layer );
1150 shape->SetFilled( true );
1151 shape->SetPolyShape( SHAPE_POLY_SET( outline ) );
1152 m_loadBoard->Add( shape );
1153 continue;
1154 }
1155
1156 ZONE* zone = new ZONE( m_loadBoard );
1157 zone->SetLayer( layer );
1158 zone->SetIsRuleArea( false );
1159 zone->Outline()->AddOutline( outline );
1161
1162 m_loadBoard->Add( zone );
1163 }
1164}
1165
1166
1168{
1169 const auto& pours = m_parser->GetPours();
1170 const auto& params = m_parser->GetParameters();
1171
1172 int maxPriority = 0;
1173
1174 for( const auto& pour_def : pours )
1175 {
1176 if( pour_def.priority > maxPriority )
1177 maxPriority = pour_def.priority;
1178 }
1179
1180 for( const auto& pour_def : pours )
1181 {
1182 if( pour_def.points.size() < 3 )
1183 continue;
1184
1185 PCB_LAYER_ID pourLayer = getMappedLayer( pour_def.layer );
1186
1187 if( pourLayer == UNDEFINED_LAYER )
1188 {
1189 if( m_reporter )
1190 {
1191 m_reporter->Report( wxString::Format( _( "Skipping pour on unmapped layer %d" ), pour_def.layer ),
1193 }
1194
1195 continue;
1196 }
1197
1198 if( !IsCopperLayer( pourLayer ) )
1199 {
1200 SHAPE_LINE_CHAIN outline;
1201
1202 for( const auto& point : pour_def.points )
1203 outline.Append( scalePoint( point.x, point.y ) );
1204
1205 outline.SetClosed( true );
1206
1208 shape->SetLayer( pourLayer );
1209 shape->SetFilled( true );
1210 shape->SetPolyShape( SHAPE_POLY_SET( outline ) );
1211 m_loadBoard->Add( shape );
1212 continue;
1213 }
1214
1215 ZONE* zone = new ZONE( m_loadBoard );
1216 zone->SetLayer( pourLayer );
1217
1218 zone->Outline()->NewOutline();
1219
1220 for( const auto& pt : pour_def.points )
1221 {
1222 zone->Outline()->Append( scalePoint( pt.x, pt.y ) );
1223 }
1224
1225 if( zone->GetNumCorners() == 0 )
1226 {
1227 delete zone;
1228 continue;
1229 }
1230
1231 m_converter->ApplyPourSettings( zone, pour_def, maxPriority, params );
1232
1233 m_loadBoard->Add( zone );
1234 }
1235}
1236
1237
1238std::map<wxString, PCB_LAYER_ID>
1239PCB_IO_PADS_BINARY::DefaultLayerMappingCallback( const std::vector<INPUT_LAYER_DESC>& aInputLayerDescriptionVector )
1240{
1241 std::map<wxString, PCB_LAYER_ID> layerMap;
1242
1243 for( const INPUT_LAYER_DESC& layer : aInputLayerDescriptionVector )
1244 layerMap[layer.Name] = layer.AutoMapLayer;
1245
1246 return layerMap;
1247}
1248
1249
1251{
1252 m_loadBoard = nullptr;
1253 m_parser = nullptr;
1254 m_converter.reset();
1255 m_pinToNetMap.clear();
1256 m_partFootprints.clear();
1257}
int index
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
BASE_SET & set(size_t pos)
Definition base_set.h:126
virtual void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:397
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
virtual void SetFilled(bool aFlag)
Definition eda_shape.h:145
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition eda_text.cpp:379
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:348
void SetKeepUpright(bool aKeepUpright)
Definition eda_text.cpp:387
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition eda_text.cpp:371
void SetPosition(const VECTOR2I &aPos) override
void SetFPID(const LIB_ID &aFPID)
Definition footprint.h:418
void SetOrientation(const EDA_ANGLE &aNewAngle)
void SetPath(const KIID_PATH &aPath)
Definition footprint.h:456
PCB_FIELD & Value()
read/write accessors:
Definition footprint.h:831
std::deque< PAD * > & Pads()
Definition footprint.h:355
void SetReference(const wxString &aReference)
Definition footprint.h:799
void SetValue(const wxString &aValue)
Definition footprint.h:822
PCB_FIELD & Reference()
Definition footprint.h:832
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Adds an item to the container.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
const wxString & GetReference() const
Definition footprint.h:793
VECTOR2I GetPosition() const override
Definition footprint.h:379
REPORTER * m_reporter
Reporter to log errors/warnings to, may be nullptr.
Definition io_base.h:264
PROGRESS_REPORTER * m_progressReporter
Progress reporter to track the progress of the operation, may be nullptr.
Definition io_base.h:267
virtual bool CanReadLibrary(const wxString &aFileName) const
Checks if this IO object can read the specified library file/directory.
Definition io_base.cpp:71
Definition kiid.h:46
virtual void RegisterCallback(LAYER_MAPPING_HANDLER aLayerMappingHandler)
Register a different handler to be called when mapping of input layers to KiCad layers occurs.
LAYER_MAPPING_HANDLER m_layer_mapping_handler
Callback to get layer mapping.
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
int SetLibItemName(const UTF8 &aLibItemName)
Override the library item name portion of the LIB_ID to aLibItemName.
Definition lib_id.cpp:124
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
Handle the data for a net.
Definition netinfo.h:50
@ NORMAL
Shape is the same on all layers.
Definition padstack.h:175
@ FRONT_INNER_BACK
Up to three shapes can be defined (F_Cu, inner copper layers, B_Cu)
Definition padstack.h:176
static constexpr PCB_LAYER_ID INNER_LAYERS
! The layer identifier to use for "inner layers" on top/inner/bottom padstacks
Definition padstack.h:187
Reader for the PADS PowerPCB binary .pcb format.
static bool IsBinaryPadsFile(const wxString &aFileName)
Check if a file appears to be a PADS binary PCB file.
void Parse(const wxString &aFileName)
static constexpr double BASIC_TO_NM
Definition pad.h:61
static LSET PTHMask()
layer set for a through hole pad
Definition pad.cpp:620
void SetShape(PCB_LAYER_ID aLayer, PAD_SHAPE aShape)
Set the new shape of this pad.
Definition pad.h:196
static LSET UnplatedHoleMask()
layer set for a mechanical unplated through hole pad
Definition pad.cpp:641
void SetOffset(PCB_LAYER_ID aLayer, const VECTOR2I &aOffset)
Definition pad.cpp:837
void SetSize(PCB_LAYER_ID aLayer, const VECTOR2I &aSize)
Definition pad.cpp:264
void SetRoundRectRadiusRatio(PCB_LAYER_ID aLayer, double aRadiusScale)
Has meaning only for rounded rectangle pads.
Definition pad.cpp:1065
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:51
long long GetLibraryTimestamp(const wxString &aLibraryPath) const override
Generate a timestamp representing all the files in the library (including the library directory).
void loadClusterGroups()
Build one PCB_GROUP per PADS part cluster and add each footprint to the group named by its part's CLS...
void setBoardOutlineArc(PCB_SHAPE *aShape, const PADS_IO::ARC_POINT &aPrev, const PADS_IO::ARC_POINT &aCurr)
const IO_FILE_DESC GetBoardFileDesc() const override
Return board file description for the PCB_IO.
bool CanReadBoard(const wxString &aFileName) const override
~PCB_IO_PADS_BINARY() override
int scaleSize(double aVal) const
Shorthands for the converter's transform, which the loaders below use everywhere.
const IO_FILE_DESC GetLibraryDesc() const override
Get the descriptor for the library container that this IO plugin operates on.
void buildPad(FOOTPRINT *aFootprint, const PADS_IO::PART_DECAL &aDecal, size_t aTermIdx, const EDA_ANGLE &aPartOrient)
Build one terminal's pad on aFootprint from decal terminal aTermIdx, oriented by the part orientation...
const PADS_IO::BINARY_PARSER * m_parser
std::map< wxString, std::string > m_pinToNetMap
"<refdes>.<pin>" to PADS net name
PCB_LAYER_ID getMappedLayer(int aPadsLayer) const
std::unique_ptr< PADS_PCB_CONVERTER > m_converter
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this IO object can read the specified library file/directory.
void loadBoard(const wxString &aFileName, BOARD &aBoard, bool aIsNewLoad, const std::map< std::string, UTF8 > *aProperties, PROJECT *aProject) override
Parse aFileName into aBoard.
void applyPadShape(PAD *aPad, const PADS_IO::PAD_STACK_LAYER &aLayer, PCB_LAYER_ID aKiCadLayer)
Apply a pad-stack layer's shape, size and finger offset to aPad.
std::vector< FOOTPRINT * > m_partFootprints
VECTOR2I scalePoint(double aX, double aY) const
Scale a board point to a KiCad position, applying the per-axis origin and the Y-flip.
std::map< wxString, PCB_LAYER_ID > DefaultLayerMappingCallback(const std::vector< INPUT_LAYER_DESC > &aInputLayerDescriptionVector)
virtual bool CanReadBoard(const wxString &aFileName) const
Definition pcb_io.cpp:40
PCB_IO(const wxString &aName)
Definition pcb_io.h:383
void SetCenter(const VECTOR2I &aCenter) override
void SetWidth(int aWidth) override
void SetShape(SHAPE_T aShape) override
Definition pcb_shape.h:214
void SetEnd(const VECTOR2I &aEnd) override
void SetPolyShape(const SHAPE_POLY_SET &aShape) override
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetStart(const VECTOR2I &aStart) override
void SetArcGeometry(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd) override
Set the three controlling points for an arc.
void SetTextThickness(int aWidth) override
The TextThickness is that set by the user.
Definition pcb_text.cpp:514
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true) override
Definition pcb_text.cpp:486
void SetPosition(const VECTOR2I &aPos) override
Definition pcb_text.h:103
void SetTextAngle(const EDA_ANGLE &aAngle) override
Definition pcb_text.cpp:574
void SetEnd(const VECTOR2I &aEnd)
Definition pcb_track.h:96
void SetStart(const VECTOR2I &aStart)
Definition pcb_track.h:99
virtual void SetWidth(int aWidth)
Definition pcb_track.h:93
Container for project specific data.
Definition project.h:63
SHAPE_ARC & ConstructFromStartEndCenter(const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter, bool aClockwise=false, double aWidth=0)
Constructs this arc from the given start, end and center.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
Represent a set of closed polygons.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
int NewOutline()
Creates a new empty polygon in the set and returns its index.
Handle a list of polygons defining a copper zone.
Definition zone.h:70
void SetBorderDisplayStyle(ZONE_BORDER_DISPLAY_STYLE aBorderHatchStyle, int aBorderHatchPitch, bool aRebuildBorderHatch)
Set all hatch parameters for the zone.
Definition zone.cpp:1618
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition zone.cpp:677
SHAPE_POLY_SET * Outline()
Definition zone.h:421
void SetIsRuleArea(bool aEnable)
Definition zone.h:835
static int GetDefaultHatchPitch()
Definition zone.cpp:1695
int GetNumCorners(void) const
Access to m_Poly parameters.
Definition zone.h:619
#define _(s)
@ DEGREES_T
Definition eda_angle.h:30
@ SEGMENT
Definition eda_shape.h:57
double m_PadsPcbTextWidthScale
PADS text width scale factor for PCB imports.
double m_PadsPcbTextHeightScale
PADS text height scale factor for PCB imports.
int m_PcbImportMinObjectSizeNm
Minimum object size in nanometers for PCB imports.
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:744
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ Edge_Cuts
Definition layer_ids.h:108
@ F_Paste
Definition layer_ids.h:100
@ B_Mask
Definition layer_ids.h:94
@ B_Cu
Definition layer_ids.h:61
@ F_Mask
Definition layer_ids.h:93
@ B_Paste
Definition layer_ids.h:101
@ F_Fab
Definition layer_ids.h:115
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ In1_Cu
Definition layer_ids.h:62
@ F_Cu
Definition layer_ids.h:60
@ LEFT_RIGHT
Flip left to right (around the Y axis)
Definition mirror.h:27
wxString ConvertText(const std::string &aText)
Decode text from a PADS file, which uses an 8-bit codepage rather than UTF-8.
wxString ConvertInvertedNetName(const std::string &aNetName)
Convert a PADS net name to KiCad notation.
KIID GenerateDeterministicUuid(const std::string &aIdentifier)
Generate a deterministic KIID from a PADS component identifier.
constexpr double SDB_BASIC_PER_MIL
bool IsAntiPadRow(const PAD_STACK_LAYER &aLayer)
RA and SA rows carry a plane's anti-pad clearance rather than the pad's own copper.
bool IsThermalReliefPadRow(const PAD_STACK_LAYER &aLayer)
RT and ST rows carry a plane's thermal-relief spoke pattern rather than the pad's own copper.
bool IsCopperPadRow(const PAD_STACK_LAYER &aLayer)
True when the row describes pad or via copper.
PAD_SHAPE PadsShapeToKiCad(const std::string &aShape)
Map a PADS pad-stack shape code to a KiCad pad shape, shared by both PADS PCB importers.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:461
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition padstack.h:104
@ SMD
Smd pad, appears on the solder paste layer (default)
Definition padstack.h:100
@ PTH
Plated through hole pad.
Definition padstack.h:99
@ ROUNDRECT
Definition padstack.h:58
Class to handle a set of BOARD_ITEMs.
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_INFO
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_REGEX
Describes an imported layer and how it could be mapped to KiCad Layers.
Container that describes file type info.
Definition io_base.h:43
wxString m_Description
Description shown in the file picker dialog.
Definition io_base.h:44
std::vector< std::string > m_FileExtensions
Filter used for file pickers if m_IsFile is true.
Definition io_base.h:47
A polyline point that may instead be an arc segment.
Definition pads_parser.h:64
ARC arc
Only valid when is_arc is true.
Definition pads_parser.h:68
double radius
Definition pads_parser.h:53
double delta_angle
Definition pads_parser.h:55
double start_angle
Definition pads_parser.h:54
std::string hjust
std::string vjust
A PADS net class recovered from the binary design-rule graph.
Standalone copper area from the LINES section (type=COPPER), not part of a pour.
Non-electrical drawing item from the LINES section (type=LINES).
double drill
0 for SMD
std::string shape
R, S, A, O, OF, RF, RT, ST, RA, SA, RC, OC.
bool plated
PTH vs NPTH.
double slot_orientation
0-179.999 degrees
double finger_offset
Along orientation axis.
double sizeB
Height for rectangles/ovals.
double corner_radius
Always positive.
double sizeA
Diameter or width.
A PADS part cluster (named group of parts).
std::vector< TERMINAL > terminals
std::map< int, std::vector< PAD_STACK_LAYER > > pad_stacks
A polyline that may contain arc segments, used for board outlines and graphics.
std::string path
KIBIS_PIN * pin
VECTOR2I center
int radius
VECTOR2I end
@ 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
#define M_PI
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition trigo.cpp:227
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
@ THERMAL
Use thermal relief for pads.
Definition zones.h:46