KiCad PCB EDA Suite
Loading...
Searching...
No Matches
cadstar_pcb_archive_loader.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) 2020-2021 Roberto Fernandez Bautista <[email protected]>
5 * Copyright (C) 2020-2024 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
27
29#include <board_stackup_manager/stackup_predefined_prms.h> // KEY_COPPER, KEY_CORE, KEY_PREPREG
30#include <board.h>
32#include <pcb_dimension.h>
33#include <pcb_shape.h>
34#include <footprint.h>
35#include <pad.h>
36#include <pcb_group.h>
37#include <pcb_text.h>
38#include <project.h>
39#include <pcb_track.h>
40#include <progress_reporter.h>
41#include <zone.h>
43#include <trigo.h>
44#include <macros.h>
45#include <wx/debug.h>
46#include <wx/log.h>
47
48#include <limits> // std::numeric_limits
49
50
52{
53 m_board = aBoard;
54 m_project = aProject;
55
57 m_progressReporter->SetNumPhases( 3 ); // (0) Read file, (1) Parse file, (2) Load file
58
59 Parse();
60
62
63 //Note: can't use getKiCadPoint() due wxPoint being int - need long long to make the check
64 long long designSizeXkicad = (long long) designLimit.x * KiCadUnitMultiplier;
65 long long designSizeYkicad = (long long) designLimit.y * KiCadUnitMultiplier;
66
67 // Max size limited by the positive dimension of wxPoint (which is an int)
68 long long maxDesignSizekicad = std::numeric_limits<int>::max();
69
70 if( designSizeXkicad > maxDesignSizekicad || designSizeYkicad > maxDesignSizekicad )
71 {
72 THROW_IO_ERROR( wxString::Format(
73 _( "The design is too large and cannot be imported into KiCad. \n"
74 "Please reduce the maximum design size in CADSTAR by navigating to: \n"
75 "Design Tab -> Properties -> Design Options -> Maximum Design Size. \n"
76 "Current Design size: %.2f, %.2f millimeters. \n"
77 "Maximum permitted design size: %.2f, %.2f millimeters.\n" ),
78 (double) designSizeXkicad / PCB_IU_PER_MM,
79 (double) designSizeYkicad / PCB_IU_PER_MM,
80 (double) maxDesignSizekicad / PCB_IU_PER_MM,
81 (double) maxDesignSizekicad / PCB_IU_PER_MM ) );
82 }
83
86 / 2;
87
89 {
90 wxLogWarning(
91 _( "The selected file indicates that nets might be out of synchronisation "
92 "with the schematic. It is recommended that you carry out an 'Align Nets' "
93 "procedure in CADSTAR and re-import, to avoid inconsistencies between the "
94 "PCB and the schematic. " ) );
95 }
96
98 {
100
101 // Significantly most amount of time spent loading coppers compared to all the other steps
102 // (39 seconds vs max of 100ms in other steps). This is due to requirement of boolean
103 // operations to join them together into a single polygon.
104 long numSteps = Layout.Coppers.size();
105
106 // A large amount is also spent calculating zone priorities
107 numSteps += ( Layout.Templates.size() * Layout.Templates.size() ) / 2;
108
110 }
111
116 loadGroups();
117 loadBoards();
118 loadFigures();
119 loadTexts();
121 loadAreas();
125 loadCoppers(); // Progress reporting is here as significantly most amount of time spent
126
128 {
129 if( !calculateZonePriorities( id ) )
130 {
131 wxLogError( wxString::Format( _( "Unable to determine zone fill priorities for layer "
132 "'%s'. A best attempt has been made but it is "
133 "possible that DRC errors exist and that manual "
134 "editing of the zone priorities is required." ),
135 m_board->GetLayerName( id ) ) );
136 }
137 }
138
139 loadNets();
141
142 if( Layout.Trunks.size() > 0 )
143 {
144 wxLogWarning(
145 _( "The CADSTAR design contains Trunk routing elements, which have no KiCad "
146 "equivalent. These elements were not loaded." ) );
147 }
148
149 if( Layout.VariantHierarchy.Variants.size() > 0 )
150 {
151 wxLogWarning( wxString::Format(
152 _( "The CADSTAR design contains variants which has no KiCad equivalent. Only "
153 "the variant '%s' was loaded." ),
154 Layout.VariantHierarchy.Variants.begin()->second.Name ) );
155 }
156
157 if( Layout.ReuseBlocks.size() > 0 )
158 {
159 wxLogWarning(
160 _( "The CADSTAR design contains re-use blocks which has no KiCad equivalent. The "
161 "re-use block information has been discarded during the import." ) );
162 }
163
164 wxLogWarning( _( "CADSTAR fonts are different to the ones in KiCad. This will likely result "
165 "in alignment issues that may cause DRC errors. Please review the imported "
166 "text elements carefully and correct manually if required." ) );
167
168 wxLogMessage(
169 _( "The CADSTAR design has been imported successfully.\n"
170 "Please review the import errors and warnings (if any)." ) );
171}
172
174{
175 std::vector<FOOTPRINT*> retval;
176
177 for( std::pair<SYMDEF_ID, FOOTPRINT*> fpPair : m_libraryMap )
178 {
179 retval.push_back( static_cast<FOOTPRINT*>( fpPair.second->Clone() ) );
180 }
181
182 return retval;
183}
184
185
186std::vector<std::unique_ptr<FOOTPRINT>> CADSTAR_PCB_ARCHIVE_LOADER::LoadLibrary()
187{
188 // loading the library after parsing takes almost no time in comparison
190 m_progressReporter->SetNumPhases( 2 ); // (0) Read file, (1) Parse file
191
192 Parse( true /*aLibrary*/);
193
194 // Some memory handling
195 for( std::pair<SYMDEF_ID, FOOTPRINT*> libItem : m_libraryMap )
196 {
197 FOOTPRINT* footprint = libItem.second;
198
199 if( footprint )
200 delete footprint;
201 }
202
203 m_libraryMap.clear();
204
205 if( m_board )
206 delete m_board;
207
208 m_board = new BOARD(); // dummy board for loading
209 m_project = nullptr;
210 m_designCenter = { 0, 0 }; // load footprints at 0,0
211
215
216 std::vector<std::unique_ptr<FOOTPRINT>> retval;
217
218 for( auto& [id, footprint] : m_libraryMap )
219 {
220 footprint->SetParent( nullptr ); // remove association to m_board
221 retval.emplace_back( footprint );
222 }
223
224 delete m_board;
225
226 // Don't delete the generated footprints, but empty the map
227 // (the destructor of this class would end up deleting them if not)
228 m_libraryMap.clear();
229
230 return retval;
231}
232
233
234void CADSTAR_PCB_ARCHIVE_LOADER::logBoardStackupWarning( const wxString& aCadstarLayerName,
235 const PCB_LAYER_ID& aKiCadLayer )
236{
238 {
239 wxLogWarning( wxString::Format(
240 _( "The CADSTAR layer '%s' has no KiCad equivalent. All elements on this "
241 "layer have been mapped to KiCad layer '%s' instead." ),
242 aCadstarLayerName, LSET::Name( aKiCadLayer ) ) );
243 }
244}
245
246
247void CADSTAR_PCB_ARCHIVE_LOADER::logBoardStackupMessage( const wxString& aCadstarLayerName,
248 const PCB_LAYER_ID& aKiCadLayer )
249{
251 {
252 wxLogMessage( wxString::Format(
253 _( "The CADSTAR layer '%s' has been assumed to be a technical layer. All "
254 "elements on this layer have been mapped to KiCad layer '%s'." ),
255 aCadstarLayerName, LSET::Name( aKiCadLayer ) ) );
256 }
257}
258
259
261 BOARD_STACKUP_ITEM* aKiCadItem,
262 int aDielectricSublayer )
263{
264 if( !aCadstarLayer.MaterialId.IsEmpty() )
265 {
266 MATERIAL material = Assignments.Layerdefs.Materials.at( aCadstarLayer.MaterialId );
267
268 aKiCadItem->SetMaterial( material.Name, aDielectricSublayer );
269 aKiCadItem->SetEpsilonR( material.Permittivity.GetDouble(), aDielectricSublayer );
270 aKiCadItem->SetLossTangent( material.LossTangent.GetDouble(), aDielectricSublayer );
271 //TODO add Resistivity when KiCad supports it
272 }
273
274 if( !aCadstarLayer.Name.IsEmpty() )
275 aKiCadItem->SetLayerName( aCadstarLayer.Name );
276
277 if( aCadstarLayer.Thickness != 0 )
278 aKiCadItem->SetThickness( getKiCadLength( aCadstarLayer.Thickness ), aDielectricSublayer );
279}
280
281
283{
284 // Structure describing an electrical layer with optional dielectric layers below it
285 // (construction layers in CADSTAR)
286 struct LAYER_BLOCK
287 {
288 LAYER_ID ElecLayerID = wxEmptyString; // Normally not empty, but could be empty if the
289 // first layer in the stackup is a construction
290 // layer
291 std::vector<LAYER_ID> ConstructionLayers; // Normally empty for the last electrical layer
292 // but it is possible to build a board in CADSTAR
293 // with no construction layers or with the bottom
294 // layer being a construction layer
295
296 bool IsInitialised() { return !ElecLayerID.IsEmpty() || ConstructionLayers.size() > 0; };
297 };
298
299 std::vector<LAYER_BLOCK> cadstarBoardStackup;
300 LAYER_BLOCK currentBlock;
301 bool first = true;
302
303 // Find the electrical and construction (dielectric) layers in the stackup
304 for( LAYER_ID cadstarLayerID : Assignments.Layerdefs.LayerStack )
305 {
306 LAYER cadstarLayer = Assignments.Layerdefs.Layers.at( cadstarLayerID );
307
308 if( cadstarLayer.Type == LAYER_TYPE::JUMPERLAYER ||
309 cadstarLayer.Type == LAYER_TYPE::POWER ||
310 cadstarLayer.Type == LAYER_TYPE::ELEC )
311 {
312 if( currentBlock.IsInitialised() )
313 {
314 cadstarBoardStackup.push_back( currentBlock );
315 currentBlock = LAYER_BLOCK(); // reset the block
316 }
317
318 currentBlock.ElecLayerID = cadstarLayerID;
319 first = false;
320 }
321 else if( cadstarLayer.Type == LAYER_TYPE::CONSTRUCTION )
322 {
323 if( first )
324 {
325 wxLogWarning( wxString::Format( _( "The CADSTAR construction layer '%s' is on "
326 "the outer surface of the board. It has been "
327 "ignored." ),
328 cadstarLayer.Name ) );
329 }
330 else
331 {
332 currentBlock.ConstructionLayers.push_back( cadstarLayerID );
333 }
334 }
335 }
336
337 if( currentBlock.IsInitialised() )
338 cadstarBoardStackup.push_back( currentBlock );
339
340 m_numCopperLayers = cadstarBoardStackup.size();
341
342 // Special case: last layer in the stackup is a construction layer, drop it
343 if( cadstarBoardStackup.back().ConstructionLayers.size() > 0 )
344 {
345 for( const LAYER_ID& layerID : cadstarBoardStackup.back().ConstructionLayers )
346 {
347 LAYER cadstarLayer = Assignments.Layerdefs.Layers.at( layerID );
348
349 wxLogWarning( wxString::Format( _( "The CADSTAR construction layer '%s' is on "
350 "the outer surface of the board. It has been "
351 "ignored." ),
352 cadstarLayer.Name ) );
353 }
354
355 cadstarBoardStackup.back().ConstructionLayers.clear();
356 }
357
358 // Make sure it is an even number of layers (KiCad doesn't yet support unbalanced stack-ups)
359 if( ( m_numCopperLayers % 2 ) != 0 )
360 {
361 LAYER_BLOCK bottomLayer = cadstarBoardStackup.back();
362 cadstarBoardStackup.pop_back();
363
364 LAYER_BLOCK secondToLastLayer = cadstarBoardStackup.back();
365 cadstarBoardStackup.pop_back();
366
367 LAYER_BLOCK dummyLayer;
368
369 if( secondToLastLayer.ConstructionLayers.size() > 0 )
370 {
371 LAYER_ID lastConstruction = secondToLastLayer.ConstructionLayers.back();
372
373 if( secondToLastLayer.ConstructionLayers.size() > 1 )
374 {
375 // At least two construction layers, lets remove one here and use the
376 // other in the dummy layer
377 secondToLastLayer.ConstructionLayers.pop_back();
378 }
379 else
380 {
381 // There is only one construction layer, lets halve its thickness so it is split
382 // evenly between this layer and the dummy layer
383 Assignments.Layerdefs.Layers.at( lastConstruction ).Thickness /= 2;
384 }
385
386 dummyLayer.ConstructionLayers.push_back( lastConstruction );
387 }
388
389 cadstarBoardStackup.push_back( secondToLastLayer );
390 cadstarBoardStackup.push_back( dummyLayer );
391 cadstarBoardStackup.push_back( bottomLayer );
393 }
394
395 wxASSERT( m_numCopperLayers == cadstarBoardStackup.size() );
396 wxASSERT( cadstarBoardStackup.back().ConstructionLayers.size() == 0 );
397
398 // Create a new stackup from default stackup list
399 BOARD_DESIGN_SETTINGS& boardDesignSettings = m_board->GetDesignSettings();
400 BOARD_STACKUP& stackup = boardDesignSettings.GetStackupDescriptor();
401 stackup.RemoveAll();
406
407 size_t stackIndex = 0;
408
409 for( BOARD_STACKUP_ITEM* item : stackup.GetList() )
410 {
411 if( item->GetType() == BOARD_STACKUP_ITEM_TYPE::BS_ITEM_TYPE_COPPER )
412 {
413 LAYER_ID layerID = cadstarBoardStackup.at( stackIndex ).ElecLayerID;
414
415 if( layerID.IsEmpty() )
416 {
417 // Loading a dummy layer. Make zero thickness so it doesn't affect overall stackup
418 item->SetThickness( 0 );
419 }
420 else
421 {
422 LAYER copperLayer = Assignments.Layerdefs.Layers.at( layerID );
423 initStackupItem( copperLayer, item, 0 );
424 LAYER_T copperType = LAYER_T::LT_SIGNAL;
425
426 switch( copperLayer.Type )
427 {
429 copperType = LAYER_T::LT_JUMPER;
430 break;
431
432 case LAYER_TYPE::ELEC:
433 copperType = LAYER_T::LT_SIGNAL;
434 break;
435
437 copperType = LAYER_T::LT_POWER;
438 m_powerPlaneLayers.push_back( copperLayer.ID ); //need to add a Copper zone
439 break;
440
441 default:
442 wxFAIL_MSG( wxT( "Unexpected Layer type. Was expecting an electrical type" ) );
443 break;
444 }
445
446 m_board->SetLayerType( item->GetBrdLayerId(), copperType );
447 m_board->SetLayerName( item->GetBrdLayerId(), item->GetLayerName() );
448 m_layermap.insert( { copperLayer.ID, item->GetBrdLayerId() } );
449 }
450 }
451 else if( item->GetType() == BOARD_STACKUP_ITEM_TYPE::BS_ITEM_TYPE_DIELECTRIC )
452 {
453 LAYER_BLOCK layerBlock = cadstarBoardStackup.at( stackIndex );
454 LAYER_BLOCK layerBlockBelow = cadstarBoardStackup.at( stackIndex + 1 );
455
456 if( layerBlock.ConstructionLayers.size() == 0 )
457 {
458 ++stackIndex;
459 continue; // Older cadstar designs have no construction layers - use KiCad defaults
460 }
461
462 int dielectricId = stackIndex + 1;
463 item->SetDielectricLayerId( dielectricId );
464
465 //Prepreg or core?
466 //Look at CADSTAR layer embedding (see LAYER->Embedding) to check whether the electrical
467 //layer embeds above and below to decide if current layer is prepreg or core
468 if( layerBlock.ElecLayerID.IsEmpty() )
469 {
470 //Dummy electrical layer, assume prepreg
471 item->SetTypeName( KEY_PREPREG );
472 }
473 else
474 {
475 LAYER copperLayer = Assignments.Layerdefs.Layers.at( layerBlock.ElecLayerID );
476
477 if( layerBlockBelow.ElecLayerID.IsEmpty() )
478 {
479 // Dummy layer below, just use current layer to decide
480
481 if( copperLayer.Embedding == EMBEDDING::ABOVE )
482 item->SetTypeName( KEY_CORE );
483 else
484 item->SetTypeName( KEY_PREPREG );
485 }
486 else
487 {
488 LAYER copperLayerBelow =
489 Assignments.Layerdefs.Layers.at( layerBlockBelow.ElecLayerID );
490
491 if( copperLayer.Embedding == EMBEDDING::ABOVE )
492 {
493 // Need to check layer below is embedding downwards
494 if( copperLayerBelow.Embedding == EMBEDDING::BELOW )
495 item->SetTypeName( KEY_CORE );
496 else
497 item->SetTypeName( KEY_PREPREG );
498 }
499 else
500 {
501 item->SetTypeName( KEY_PREPREG );
502 }
503 }
504 }
505
506 int dielectricSublayer = 0;
507
508 for( LAYER_ID constructionLaID : layerBlock.ConstructionLayers )
509 {
510 LAYER dielectricLayer = Assignments.Layerdefs.Layers.at( constructionLaID );
511
512 if( dielectricSublayer )
513 item->AddDielectricPrms( dielectricSublayer );
514
515 initStackupItem( dielectricLayer, item, dielectricSublayer );
516 m_board->SetLayerName( item->GetBrdLayerId(), item->GetLayerName() );
517 m_layermap.insert( { dielectricLayer.ID, item->GetBrdLayerId() } );
518 ++dielectricSublayer;
519 }
520
521 ++stackIndex;
522 }
523 else if( item->GetType() == BOARD_STACKUP_ITEM_TYPE::BS_ITEM_TYPE_SILKSCREEN )
524 {
525 item->SetColor( wxT( "White" ) );
526 }
527 else if( item->GetType() == BOARD_STACKUP_ITEM_TYPE::BS_ITEM_TYPE_SOLDERMASK )
528 {
529 item->SetColor( wxT( "Green" ) );
530 }
531 }
532
533 int thickness = stackup.BuildBoardThicknessFromStackup();
534 boardDesignSettings.SetBoardThickness( thickness );
535 boardDesignSettings.m_HasStackup = true;
536
537 int numElecLayersProcessed = 0;
538
539 // Map CADSTAR documentation layers to KiCad "User layers"
540 int currentDocLayer = 0;
541 std::vector<PCB_LAYER_ID> docLayers = { Dwgs_User, Cmts_User, User_1, User_2, User_3, User_4,
543
544 for( LAYER_ID cadstarLayerID : Assignments.Layerdefs.LayerStack )
545 {
546 LAYER curLayer = Assignments.Layerdefs.Layers.at( cadstarLayerID );
547 PCB_LAYER_ID kicadLayerID = PCB_LAYER_ID::UNDEFINED_LAYER;
548 wxString layerName = curLayer.Name.Lower();
549
550 enum class LOG_LEVEL
551 {
552 NONE,
553 MSG,
554 WARN
555 };
556
557 auto selectLayerID =
558 [&]( PCB_LAYER_ID aFront, PCB_LAYER_ID aBack, LOG_LEVEL aLogType )
559 {
560 if( numElecLayersProcessed >= m_numCopperLayers )
561 kicadLayerID = aBack;
562 else
563 kicadLayerID = aFront;
564
565 switch( aLogType )
566 {
567 case LOG_LEVEL::NONE:
568 break;
569
570 case LOG_LEVEL::MSG:
571 logBoardStackupMessage( curLayer.Name, kicadLayerID );
572 break;
573
574 case LOG_LEVEL::WARN:
575 logBoardStackupWarning( curLayer.Name, kicadLayerID );
576 break;
577 }
578 };
579
580 switch( curLayer.Type )
581 {
587 //Shouldn't be here if CPA file is correctly parsed and not corrupt
588 THROW_IO_ERROR( wxString::Format( _( "Unexpected layer '%s' in layer stack." ),
589 curLayer.Name ) );
590 break;
591
593 case LAYER_TYPE::ELEC:
595 ++numElecLayersProcessed;
598 //Already dealt with these when loading board stackup
599 break;
600
601 case LAYER_TYPE::DOC:
602
603 if( currentDocLayer >= docLayers.size() )
604 currentDocLayer = 0;
605
606 kicadLayerID = docLayers.at( currentDocLayer++ );
607 logBoardStackupMessage( curLayer.Name, kicadLayerID );
608 break;
609
611 switch( curLayer.SubType )
612 {
614 selectLayerID( PCB_LAYER_ID::F_Fab, PCB_LAYER_ID::B_Fab, LOG_LEVEL::NONE );
615 break;
616
618 selectLayerID( PCB_LAYER_ID::F_CrtYd, PCB_LAYER_ID::B_CrtYd, LOG_LEVEL::NONE );
619 break;
620
622 // Generic Non-electrical layer (older CADSTAR versions).
623 // Attempt to detect technical layers by string matching.
624 if( layerName.Contains( wxT( "glue" ) ) || layerName.Contains( wxT( "adhesive" ) ) )
625 {
626 selectLayerID( PCB_LAYER_ID::F_Adhes, PCB_LAYER_ID::B_Adhes, LOG_LEVEL::MSG );
627 }
628 else if( layerName.Contains( wxT( "silk" ) ) || layerName.Contains( wxT( "legend" ) ) )
629 {
630 selectLayerID( PCB_LAYER_ID::F_SilkS, PCB_LAYER_ID::B_SilkS, LOG_LEVEL::MSG );
631 }
632 else if( layerName.Contains( wxT( "assembly" ) ) || layerName.Contains( wxT( "fabrication" ) ) )
633 {
634 selectLayerID( PCB_LAYER_ID::F_Fab, PCB_LAYER_ID::B_Fab, LOG_LEVEL::MSG );
635 }
636 else if( layerName.Contains( wxT( "resist" ) ) || layerName.Contains( wxT( "mask" ) ) )
637 {
638 selectLayerID( PCB_LAYER_ID::F_Mask, PCB_LAYER_ID::B_Mask, LOG_LEVEL::MSG );
639 }
640 else if( layerName.Contains( wxT( "paste" ) ) )
641 {
642 selectLayerID( PCB_LAYER_ID::F_Paste, PCB_LAYER_ID::B_Paste, LOG_LEVEL::MSG );
643 }
644 else
645 {
646 // Does not appear to be a technical layer - Map to Eco layers for now.
647 selectLayerID( PCB_LAYER_ID::Eco1_User, PCB_LAYER_ID::Eco2_User,
648 LOG_LEVEL::WARN );
649 }
650 break;
651
653 selectLayerID( PCB_LAYER_ID::F_Paste, PCB_LAYER_ID::B_Paste, LOG_LEVEL::MSG );
654 break;
655
657 selectLayerID( PCB_LAYER_ID::F_SilkS, PCB_LAYER_ID::B_SilkS, LOG_LEVEL::MSG );
658 break;
659
661 selectLayerID( PCB_LAYER_ID::F_Mask, PCB_LAYER_ID::B_Mask, LOG_LEVEL::MSG );
662 break;
663
666 //Unsure what these layer types are used for. Map to Eco layers for now.
667 selectLayerID( PCB_LAYER_ID::Eco1_User, PCB_LAYER_ID::Eco2_User, LOG_LEVEL::WARN );
668 break;
669
670 default:
671 wxFAIL_MSG( wxT( "Unknown CADSTAR Layer Sub-type" ) );
672 break;
673 }
674 break;
675
676 default:
677 wxFAIL_MSG( wxT( "Unknown CADSTAR Layer Type" ) );
678 break;
679 }
680
681 m_layermap.insert( { curLayer.ID, kicadLayerID } );
682 }
683}
684
685
687{
688 LSET enabledLayers = m_board->GetEnabledLayers();
689 LSET validRemappingLayers = enabledLayers | LSET::AllBoardTechMask() |
691
692 std::vector<INPUT_LAYER_DESC> inputLayers;
693 std::map<wxString, LAYER_ID> cadstarLayerNameMap;
694
695 for( std::pair<LAYER_ID, PCB_LAYER_ID> layerPair : m_layermap )
696 {
697 LAYER* curLayer = &Assignments.Layerdefs.Layers.at( layerPair.first );
698
699 //Only remap documentation and non-electrical layers
700 if( curLayer->Type == LAYER_TYPE::NONELEC || curLayer->Type == LAYER_TYPE::DOC )
701 {
702 INPUT_LAYER_DESC iLdesc;
703 iLdesc.Name = curLayer->Name;
704 iLdesc.PermittedLayers = validRemappingLayers;
705 iLdesc.AutoMapLayer = layerPair.second;
706
707 inputLayers.push_back( iLdesc );
708 cadstarLayerNameMap.insert( { curLayer->Name, curLayer->ID } );
709 }
710 }
711
712 if( inputLayers.size() == 0 )
713 return;
714
715 // Callback:
716 std::map<wxString, PCB_LAYER_ID> reMappedLayers = m_layerMappingHandler( inputLayers );
717
718 for( std::pair<wxString, PCB_LAYER_ID> layerPair : reMappedLayers )
719 {
720 if( layerPair.second == PCB_LAYER_ID::UNDEFINED_LAYER )
721 {
722 wxFAIL_MSG( wxT( "Unexpected Layer ID" ) );
723 continue;
724 }
725
726 LAYER_ID cadstarLayerID = cadstarLayerNameMap.at( layerPair.first );
727 m_layermap.at( cadstarLayerID ) = layerPair.second;
728 enabledLayers |= LSET( { layerPair.second } );
729 }
730
731 m_board->SetEnabledLayers( enabledLayers );
732 m_board->SetVisibleLayers( enabledLayers );
733}
734
735
737{
739 std::map<SPACINGCODE_ID, SPACINGCODE>& spacingCodes = Assignments.Codedefs.SpacingCodes;
740
741 auto applyRule =
742 [&]( wxString aID, int* aVal )
743 {
744 if( spacingCodes.find( aID ) == spacingCodes.end() )
745 wxLogWarning( _( "Design rule %s was not found. This was ignored." ) );
746 else
747 *aVal = getKiCadLength( spacingCodes.at( aID ).Spacing );
748 };
749
750 //Note: for details on the different spacing codes see SPACINGCODE::ID
751
752 applyRule( "T_T", &bds.m_MinClearance );
753 applyRule( "C_B", &bds.m_CopperEdgeClearance );
754 applyRule( "H_H", &bds.m_HoleToHoleMin );
755
757 bds.m_ViasMinSize = bds.m_TrackMinWidth; // Not specified, assumed same as track width
758 bds.m_ViasMinAnnularWidth = bds.m_TrackMinWidth / 2; // Not specified, assumed half track width
759 bds.m_MinThroughDrill = PCB_IU_PER_MM * 0.0508; // CADSTAR does not specify a minimum hole size
760 // so set to minimum permitted in KiCad (2 mils)
761 bds.m_HoleClearance = 0; // Testing suggests cadstar might not have a copper-to-hole clearance
762
763 auto applyNetClassRule = [&]( wxString aID, const std::shared_ptr<NETCLASS>& aNetClassPtr )
764 {
765 int value = -1;
766 applyRule( aID, &value );
767
768 if( value != -1 )
769 aNetClassPtr->SetClearance( value );
770 };
771
772 applyNetClassRule( "T_T", bds.m_NetSettings->GetDefaultNetclass() );
773
774 wxLogWarning( _( "KiCad design rules are different from CADSTAR ones. Only the compatible "
775 "design rules were imported. It is recommended that you review the design "
776 "rules that have been applied." ) );
777}
778
779
781{
782 for( std::pair<SYMDEF_ID, SYMDEF_PCB> symPair : Library.ComponentDefinitions )
783 {
784 SYMDEF_ID key = symPair.first;
785 SYMDEF_PCB component = symPair.second;
786
787 // Check that we are not loading a documentation symbol.
788 // Documentation symbols in CADSTAR are graphical "footprints" that can be assigned
789 // to any layer. The definition in the library assigns all elements to an undefined layer.
790 LAYER_ID componentLayer;
791
792 if( component.Figures.size() > 0 )
793 {
794 FIGURE firstFigure = component.Figures.begin()->second;
795 componentLayer = firstFigure.LayerID;
796 }
797 else if( component.Texts.size() > 0 )
798 {
799 TEXT firstText = component.Texts.begin()->second;
800 componentLayer = firstText.LayerID;
801 }
802
803 if( !componentLayer.IsEmpty() && getLayerType( componentLayer ) == LAYER_TYPE::NOLAYER )
804 continue; // don't process documentation symbols
805
806 FOOTPRINT* footprint = new FOOTPRINT( m_board );
807 footprint->SetPosition( getKiCadPoint( component.Origin ) );
808
809 LIB_ID libID;
810 libID.Parse( component.BuildLibName(), true );
811
812 footprint->SetFPID( libID );
813 loadLibraryFigures( component, footprint );
814 loadLibraryAreas( component, footprint );
815 loadLibraryPads( component, footprint );
816 loadLibraryCoppers( component, footprint ); // Load coppers after pads to ensure correct
817 // ordering of pads in footprint->Pads()
818
819 footprint->SetPosition( { 0, 0 } ); // KiCad expects library footprints at 0,0
820 footprint->SetReference( wxT( "REF**" ) );
821 footprint->SetValue( libID.GetLibItemName() );
822 footprint->AutoPositionFields();
823 m_libraryMap.insert( std::make_pair( key, footprint ) );
824 }
825}
826
827
829 FOOTPRINT* aFootprint )
830{
831 for( std::pair<FIGURE_ID, FIGURE> figPair : aComponent.Figures )
832 {
833 FIGURE& fig = figPair.second;
834
835 for( const PCB_LAYER_ID& layer : getKiCadLayerSet( fig.LayerID ).Seq() )
836 {
838 layer,
840 wxString::Format( wxT( "Component %s:%s -> Figure %s" ),
841 aComponent.ReferenceName,
842 aComponent.Alternate,
843 fig.ID ),
844 aFootprint );
845 }
846 }
847}
848
849
851 FOOTPRINT* aFootprint )
852{
853 bool compCopperError = false;
854
855 for( COMPONENT_COPPER compCopper : aComponent.ComponentCoppers )
856 {
857 int lineThickness = getKiCadLength( getCopperCode( compCopper.CopperCodeID ).CopperWidth );
858 LSET layers = getKiCadLayerSet( compCopper.LayerID );
859 LSET copperLayers = LSET::AllCuMask() & layers;
860 LSET remainingLayers = layers;
861
862 if( !compCopperError && copperLayers.count() > 1 && compCopper.AssociatedPadIDs.size() > 0 )
863 {
864 // TODO: Fix when we have full padstacks
865 wxLogError( _( "Footprint definition '%s' has component copper associated to a pad on "
866 "multiple layers. Custom padstacks are not supported in KiCad. The "
867 "copper items have been imported as graphical elements." ),
868 aComponent.BuildLibName() );
869
870 compCopperError = true;
871 }
872
873 if( compCopper.AssociatedPadIDs.size() > 0 && copperLayers.count() == 1
874 && compCopper.Shape.Type == SHAPE_TYPE::SOLID )
875 {
876 // The copper is associated with pads and in an electrical layer which means it can
877 // have a net associated with it. Load as a pad instead.
878 // Note: we can only handle SOLID copper shapes. If the copper shape is an outline or
879 // hatched or outline, then we give up and load as a graphical shape instead.
880
881 // Find the first non-PCB-only pad. If there are none, use the first one
882 COMPONENT_PAD anchorPad;
883 bool found = false;
884
885 for( PAD_ID padID : compCopper.AssociatedPadIDs )
886 {
887 anchorPad = aComponent.ComponentPads.at( padID );
888
889 if( !anchorPad.PCBonlyPad )
890 {
891 found = true;
892 break;
893 }
894 }
895
896 if( !found )
897 anchorPad = aComponent.ComponentPads.at( compCopper.AssociatedPadIDs.front() );
898
899 std::unique_ptr<PAD> pad = std::make_unique<PAD>( aFootprint );
900 pad->SetAttribute( PAD_ATTRIB::SMD );
901 pad->SetLayerSet( copperLayers );
902 pad->SetNumber( anchorPad.Identifier.IsEmpty()
903 ? wxString::Format( wxT( "%ld" ), anchorPad.ID )
904 : anchorPad.Identifier );
905
906 // Custom pad shape with an anchor at the position of one of the associated
907 // pads and same size as the pad. Shape circle as it fits inside a rectangle
908 // but not the other way round
909 PADCODE anchorpadcode = getPadCode( anchorPad.PadCodeID );
910 int anchorSize = getKiCadLength( anchorpadcode.Shape.Size );
911 VECTOR2I anchorPos = getKiCadPoint( anchorPad.Position );
912
913 if( anchorSize <= 0 )
914 anchorSize = 1;
915
916 pad->SetShape( PADSTACK::ALL_LAYERS, PAD_SHAPE::CUSTOM );
917 pad->SetAnchorPadShape( PADSTACK::ALL_LAYERS, PAD_SHAPE::CIRCLE );
918 pad->SetSize( PADSTACK::ALL_LAYERS, { anchorSize, anchorSize } );
919 pad->SetPosition( anchorPos );
920
921 SHAPE_POLY_SET shapePolys = getPolySetFromCadstarShape( compCopper.Shape, lineThickness,
922 aFootprint );
923 shapePolys.Move( -anchorPos );
924 pad->AddPrimitivePoly( PADSTACK::ALL_LAYERS, shapePolys, 0, true );
925
926 // Now renumber all the associated pads
927 COMPONENT_PAD associatedPad;
928
929 for( PAD_ID padID : compCopper.AssociatedPadIDs )
930 {
931 PAD* assocPad = getPadReference( aFootprint, padID );
932 assocPad->SetNumber( pad->GetNumber() );
933 }
934
935 aFootprint->Add( pad.release(), ADD_MODE::APPEND ); // Append so that we get the correct behaviour
936 // when finding pads by PAD_ID. See loadNets()
937
938 m_librarycopperpads[aComponent.ID][anchorPad.ID].push_back( aFootprint->Pads().size() );
939
940 remainingLayers ^= copperLayers; // don't process copper layers again!
941 }
942
943 if( remainingLayers.any() )
944 {
945 for( const PCB_LAYER_ID& layer : remainingLayers.Seq() )
946 {
947 drawCadstarShape( compCopper.Shape, layer, lineThickness,
948 wxString::Format( wxT( "Component %s:%s -> Copper element" ),
949 aComponent.ReferenceName, aComponent.Alternate ),
950 aFootprint );
951 }
952 }
953 }
954}
955
956
958 FOOTPRINT* aFootprint )
959{
960 for( std::pair<COMP_AREA_ID, COMPONENT_AREA> areaPair : aComponent.ComponentAreas )
961 {
962 COMPONENT_AREA& area = areaPair.second;
963
964 if( area.NoVias || area.NoTracks )
965 {
966 int lineThickness = 0; // CADSTAR areas only use the line width for display purpose
967 ZONE* zone = getZoneFromCadstarShape( area.Shape, lineThickness, aFootprint );
968
969 aFootprint->Add( zone, ADD_MODE::APPEND );
970
971 if( isLayerSet( area.LayerID ) )
972 zone->SetLayerSet( getKiCadLayerSet( area.LayerID ) );
973 else
974 zone->SetLayer( getKiCadLayer( area.LayerID ) );
975
976 zone->SetIsRuleArea( true ); //import all CADSTAR areas as Keepout zones
977 zone->SetDoNotAllowPads( false ); //no CADSTAR equivalent
978 zone->SetZoneName( area.ID );
979
980 //There is no distinction between tracks and copper pours in CADSTAR Keepout zones
981 zone->SetDoNotAllowTracks( area.NoTracks );
982 zone->SetDoNotAllowCopperPour( area.NoTracks );
983
984 zone->SetDoNotAllowVias( area.NoVias );
985 }
986 else
987 {
988 wxString libName = aComponent.ReferenceName;
989
990 if( !aComponent.Alternate.IsEmpty() )
991 libName << wxT( " (" ) << aComponent.Alternate << wxT( ")" );
992
993 wxLogError(
994 wxString::Format( _( "The CADSTAR area '%s' in library component '%s' does not "
995 "have a KiCad equivalent. The area is neither a via nor "
996 "route keepout area. The area was not imported." ),
997 area.ID, libName ) );
998 }
999 }
1000}
1001
1002
1004 FOOTPRINT* aFootprint )
1005{
1006 for( std::pair<PAD_ID, COMPONENT_PAD> padPair : aComponent.ComponentPads )
1007 {
1008 if( PAD* pad = getKiCadPad( padPair.second, aFootprint ) )
1009 aFootprint->Add( pad, ADD_MODE::APPEND ); // Append so that we get correct behaviour
1010 // when finding pads by PAD_ID - see loadNets()
1011 }
1012}
1013
1014
1016{
1017 PADCODE csPadcode = getPadCode( aCadstarPad.PadCodeID );
1018 wxString errorMSG;
1019
1020 std::unique_ptr<PAD> pad = std::make_unique<PAD>( aParent );
1021 LSET padLayerSet;
1022
1023 switch( aCadstarPad.Side )
1024 {
1025 case PAD_SIDE::MAXIMUM: //Bottom side
1026 padLayerSet |= LSET( { B_Cu, B_Paste, B_Mask } );
1027 break;
1028
1029 case PAD_SIDE::MINIMUM: //TOP side
1030 padLayerSet |= LSET( { F_Cu, F_Paste, F_Mask } );
1031 break;
1032
1034 padLayerSet = LSET::AllCuMask() | LSET( { F_Mask, B_Mask, F_Paste, B_Paste } );
1035 break;
1036
1037 default:
1038 wxFAIL_MSG( wxT( "Unknown Pad type" ) );
1039 }
1040
1041 pad->SetAttribute( PAD_ATTRIB::SMD ); // assume SMD pad for now
1042 pad->SetLocalSolderMaskMargin( 0 );
1043 pad->SetLocalSolderPasteMargin( 0 );
1044 pad->SetLocalSolderPasteMarginRatio( 0.0 );
1045 bool complexPadErrorLogged = false;
1046
1047 for( auto& reassign : csPadcode.Reassigns )
1048 {
1049 PCB_LAYER_ID kiLayer = getKiCadLayer( reassign.first );
1050 CADSTAR_PAD_SHAPE shape = reassign.second;
1051
1052 if( shape.Size == 0 )
1053 {
1054 padLayerSet.reset( kiLayer );
1055 }
1056 else
1057 {
1058 int newMargin = getKiCadLength( shape.Size - csPadcode.Shape.Size ) / 2;
1059
1060 if( kiLayer == F_Mask || kiLayer == B_Mask )
1061 {
1062 std::optional<int> localMargin = pad->GetLocalSolderMaskMargin();
1063
1064 if( !localMargin.has_value() )
1065 pad->SetLocalSolderMaskMargin( newMargin );
1066 else if( std::abs( localMargin.value() ) < std::abs( newMargin ) )
1067 pad->SetLocalSolderMaskMargin( newMargin );
1068 }
1069 else if( kiLayer == F_Paste || kiLayer == B_Paste )
1070 {
1071 std::optional<int> localMargin = pad->GetLocalSolderPasteMargin();
1072
1073 if( !localMargin.has_value() )
1074 pad->SetLocalSolderPasteMargin( newMargin );
1075 else if( std::abs( localMargin.value() ) < std::abs( newMargin ) )
1076 pad->SetLocalSolderPasteMargin( newMargin );
1077 }
1078 else
1079 {
1080 //TODO fix properly when KiCad supports full padstacks
1081
1082 if( !complexPadErrorLogged )
1083 {
1084 complexPadErrorLogged = true;
1085 errorMSG +=
1086 wxT( "\n - " )
1087 + wxString::Format(
1088 _( "The CADSTAR pad definition '%s' is a complex pad stack, "
1089 "which is not supported in KiCad. Please review the "
1090 "imported pads as they may require manual correction." ),
1091 csPadcode.Name );
1092 }
1093 }
1094 }
1095 }
1096
1097 pad->SetLayerSet( padLayerSet );
1098
1099 if( aCadstarPad.PCBonlyPad )
1100 {
1101 // PCB Only pads in CADSTAR do not have a representation in the schematic - they are
1102 // purely mechanical pads that have no net associated with them. Make the pad name
1103 // empty to avoid warnings when importing from the schematic
1104 pad->SetNumber( wxT( "" ) );
1105 }
1106 else
1107 {
1108 pad->SetNumber( aCadstarPad.Identifier.IsEmpty()
1109 ? wxString::Format( wxT( "%ld" ), aCadstarPad.ID )
1110 : aCadstarPad.Identifier );
1111 }
1112
1113 if( csPadcode.Shape.Size == 0 )
1114 {
1115 if( csPadcode.DrillDiameter == UNDEFINED_VALUE
1116 && aCadstarPad.Side == PAD_SIDE::THROUGH_HOLE )
1117 {
1118 // Through-hole, zero sized pad?. Lets load this just on the F_Mask for now to
1119 // prevent DRC errors.
1120 // TODO: This could be a custom padstack, update when KiCad supports padstacks
1121 pad->SetAttribute( PAD_ATTRIB::SMD );
1122 pad->SetLayerSet( LSET( { F_Mask } ) );
1123 }
1124
1125 // zero sized pads seems to break KiCad so lets make it very small instead
1126 csPadcode.Shape.Size = 1;
1127 }
1128
1129 VECTOR2I padOffset = { 0, 0 }; // offset of the pad origin (before rotating)
1130 VECTOR2I drillOffset = { 0, 0 }; // offset of the drill origin w.r.t. the pad (before rotating)
1131
1132 switch( csPadcode.Shape.ShapeType )
1133 {
1135 //todo fix: use custom shape instead (Donught shape, i.e. a circle with a hole)
1136 pad->SetShape( PADSTACK::ALL_LAYERS, PAD_SHAPE::CIRCLE );
1137 pad->SetSize( PADSTACK::ALL_LAYERS, { getKiCadLength( csPadcode.Shape.Size ),
1138 getKiCadLength( csPadcode.Shape.Size ) } );
1139 break;
1140
1142 pad->SetShape( PADSTACK::ALL_LAYERS, PAD_SHAPE::CHAMFERED_RECT );
1143 pad->SetSize( PADSTACK::ALL_LAYERS,
1144 { getKiCadLength( (long long) csPadcode.Shape.Size
1145 + (long long) csPadcode.Shape.LeftLength
1146 + (long long) csPadcode.Shape.RightLength ),
1147 getKiCadLength( csPadcode.Shape.Size ) } );
1148 pad->SetChamferPositions( PADSTACK::ALL_LAYERS,
1149 RECT_CHAMFER_POSITIONS::RECT_CHAMFER_BOTTOM_LEFT
1150 | RECT_CHAMFER_POSITIONS::RECT_CHAMFER_TOP_LEFT );
1151 pad->SetRoundRectRadiusRatio( PADSTACK::ALL_LAYERS, 0.5 );
1152 pad->SetChamferRectRatio( PADSTACK::ALL_LAYERS, 0.0 );
1153
1154 padOffset.x = getKiCadLength( ( (long long) csPadcode.Shape.LeftLength / 2 ) -
1155 ( (long long) csPadcode.Shape.RightLength / 2 ) );
1156 break;
1157
1159 pad->SetShape( PADSTACK::ALL_LAYERS, PAD_SHAPE::CIRCLE );
1160 pad->SetSize( PADSTACK::ALL_LAYERS, { getKiCadLength( csPadcode.Shape.Size ),
1161 getKiCadLength( csPadcode.Shape.Size ) } );
1162 break;
1163
1165 {
1166 // Cadstar diamond shape is a square rotated 45 degrees
1167 // We convert it in KiCad to a square with chamfered edges
1168 int sizeOfSquare = (double) getKiCadLength( csPadcode.Shape.Size ) * sqrt(2.0);
1169 pad->SetShape( PADSTACK::ALL_LAYERS, PAD_SHAPE::RECTANGLE );
1170 pad->SetChamferRectRatio( PADSTACK::ALL_LAYERS, 0.5 );
1171 pad->SetSize( PADSTACK::ALL_LAYERS, { sizeOfSquare, sizeOfSquare } );
1172
1173 padOffset.x = getKiCadLength( ( (long long) csPadcode.Shape.LeftLength / 2 ) -
1174 ( (long long) csPadcode.Shape.RightLength / 2 ) );
1175 }
1176 break;
1177
1179 pad->SetShape( PADSTACK::ALL_LAYERS, PAD_SHAPE::OVAL );
1180 pad->SetSize( PADSTACK::ALL_LAYERS,
1181 { getKiCadLength( (long long) csPadcode.Shape.Size
1182 + (long long) csPadcode.Shape.LeftLength
1183 + (long long) csPadcode.Shape.RightLength ),
1184 getKiCadLength( csPadcode.Shape.Size ) } );
1185
1186 padOffset.x = getKiCadLength( ( (long long) csPadcode.Shape.LeftLength / 2 ) -
1187 ( (long long) csPadcode.Shape.RightLength / 2 ) );
1188 break;
1189
1191 pad->SetShape( PADSTACK::ALL_LAYERS, PAD_SHAPE::CHAMFERED_RECT );
1192 pad->SetChamferPositions( PADSTACK::ALL_LAYERS, RECT_CHAMFER_POSITIONS::RECT_CHAMFER_ALL );
1193 pad->SetChamferRectRatio( PADSTACK::ALL_LAYERS, 0.25 );
1194 pad->SetSize( PADSTACK::ALL_LAYERS, { getKiCadLength( csPadcode.Shape.Size ),
1195 getKiCadLength( csPadcode.Shape.Size ) } );
1196 break;
1197
1199 pad->SetShape( PADSTACK::ALL_LAYERS, PAD_SHAPE::RECTANGLE );
1200 pad->SetSize( PADSTACK::ALL_LAYERS,
1201 { getKiCadLength( (long long) csPadcode.Shape.Size
1202 + (long long) csPadcode.Shape.LeftLength
1203 + (long long) csPadcode.Shape.RightLength ),
1204 getKiCadLength( csPadcode.Shape.Size ) } );
1205
1206 padOffset.x = getKiCadLength( ( (long long) csPadcode.Shape.LeftLength / 2 ) -
1207 ( (long long) csPadcode.Shape.RightLength / 2 ) );
1208 break;
1209
1211 pad->SetShape( PADSTACK::ALL_LAYERS, PAD_SHAPE::ROUNDRECT );
1212 pad->SetRoundRectCornerRadius( PADSTACK::ALL_LAYERS,
1213 getKiCadLength( csPadcode.Shape.InternalFeature ) );
1214 pad->SetSize( PADSTACK::ALL_LAYERS,
1215 { getKiCadLength( (long long) csPadcode.Shape.Size
1216 + (long long) csPadcode.Shape.LeftLength
1217 + (long long) csPadcode.Shape.RightLength ),
1218 getKiCadLength( csPadcode.Shape.Size ) } );
1219
1220 padOffset.x = getKiCadLength( ( (long long) csPadcode.Shape.LeftLength / 2 ) -
1221 ( (long long) csPadcode.Shape.RightLength / 2 ) );
1222 break;
1223
1224
1226 pad->SetShape( PADSTACK::ALL_LAYERS, PAD_SHAPE::RECTANGLE );
1227 pad->SetSize( PADSTACK::ALL_LAYERS, { getKiCadLength( csPadcode.Shape.Size ),
1228 getKiCadLength( csPadcode.Shape.Size ) } );
1229 break;
1230
1231 default:
1232 wxFAIL_MSG( wxT( "Unknown Pad Shape" ) );
1233 }
1234
1235 if( csPadcode.ReliefClearance != UNDEFINED_VALUE )
1236 pad->SetThermalGap( getKiCadLength( csPadcode.ReliefClearance ) );
1237
1238 if( csPadcode.ReliefWidth != UNDEFINED_VALUE )
1239 pad->SetThermalSpokeWidth( getKiCadLength( csPadcode.ReliefWidth ) );
1240
1241 if( csPadcode.DrillDiameter != UNDEFINED_VALUE )
1242 {
1243 if( csPadcode.SlotLength != UNDEFINED_VALUE )
1244 {
1245 pad->SetDrillShape( PAD_DRILL_SHAPE::OBLONG );
1246 pad->SetDrillSize( { getKiCadLength( (long long) csPadcode.SlotLength +
1247 (long long) csPadcode.DrillDiameter ),
1248 getKiCadLength( csPadcode.DrillDiameter ) } );
1249 }
1250 else
1251 {
1252 pad->SetDrillShape( PAD_DRILL_SHAPE::CIRCLE );
1253 pad->SetDrillSize( { getKiCadLength( csPadcode.DrillDiameter ),
1254 getKiCadLength( csPadcode.DrillDiameter ) } );
1255 }
1256
1257 drillOffset.x = -getKiCadLength( csPadcode.DrillXoffset );
1258 drillOffset.y = getKiCadLength( csPadcode.DrillYoffset );
1259
1260 if( csPadcode.Plated )
1261 pad->SetAttribute( PAD_ATTRIB::PTH );
1262 else
1263 pad->SetAttribute( PAD_ATTRIB::NPTH );
1264 }
1265 else
1266 {
1267 pad->SetDrillSize( { 0, 0 } );
1268 }
1269
1270 if( csPadcode.SlotOrientation != 0 )
1271 {
1272 LSET lset = pad->GetLayerSet();
1273 lset &= LSET::AllCuMask();
1274
1275 if( lset.size() > 0 )
1276 {
1277 SHAPE_POLY_SET padOutline;
1278 PCB_LAYER_ID layer = lset.Seq().at( 0 );
1279 int maxError = m_board->GetDesignSettings().m_MaxError;
1280
1281 pad->SetPosition( { 0, 0 } );
1282 pad->TransformShapeToPolygon( padOutline, layer, 0, maxError, ERROR_INSIDE );
1283
1284 PCB_SHAPE* padShape = new PCB_SHAPE;
1285 padShape->SetShape( SHAPE_T::POLY );
1286 padShape->SetFilled( true );
1287 padShape->SetPolyShape( padOutline );
1288 padShape->SetStroke( STROKE_PARAMS( 0 ) );
1289 padShape->Move( padOffset - drillOffset );
1290 padShape->Rotate( VECTOR2I( 0, 0 ), ANGLE_180 - getAngle( csPadcode.SlotOrientation ) );
1291
1292 SHAPE_POLY_SET editedPadOutline = padShape->GetPolyShape();
1293
1294 if( editedPadOutline.Contains( { 0, 0 } ) )
1295 {
1296 pad->SetAnchorPadShape( PADSTACK::ALL_LAYERS, PAD_SHAPE::RECTANGLE );
1297 pad->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( { 4, 4 } ) );
1298 pad->SetShape( PADSTACK::ALL_LAYERS, PAD_SHAPE::CUSTOM );
1299 pad->AddPrimitive( PADSTACK::ALL_LAYERS, padShape );
1300 padOffset = { 0, 0 };
1301 }
1302 else
1303 {
1304 // The CADSTAR pad has the hole shape outside the pad shape
1305 // Lets just put the hole in the center of the pad instead
1306 csPadcode.SlotOrientation = 0;
1307 drillOffset = { 0, 0 };
1308
1309 errorMSG +=
1310 wxT( "\n - " )
1311 + wxString::Format(
1312 _( "The CADSTAR pad definition '%s' has the hole shape outside the "
1313 "pad shape. The hole has been moved to the center of the pad." ),
1314 csPadcode.Name );
1315 }
1316 }
1317 else
1318 {
1319 wxFAIL_MSG( wxT( "No copper layers defined in the pad?" ) );
1320 csPadcode.SlotOrientation = 0;
1321 pad->SetOffset( PADSTACK::ALL_LAYERS, drillOffset );
1322 }
1323 }
1324 else
1325 {
1326 pad->SetOffset( PADSTACK::ALL_LAYERS, drillOffset );
1327 }
1328
1329 EDA_ANGLE padOrientation = getAngle( aCadstarPad.OrientAngle )
1330 + getAngle( csPadcode.Shape.OrientAngle );
1331
1332 RotatePoint( padOffset, padOrientation );
1333 RotatePoint( drillOffset, padOrientation );
1334 pad->SetPosition( getKiCadPoint( aCadstarPad.Position ) - padOffset - drillOffset );
1335 pad->SetOrientation( padOrientation + getAngle( csPadcode.SlotOrientation ) );
1336
1337 //TODO handle csPadcode.Reassigns when KiCad supports full padstacks
1338
1339 //log warnings:
1340 if( m_padcodesTested.find( csPadcode.ID ) == m_padcodesTested.end() && !errorMSG.IsEmpty() )
1341 {
1342 wxLogError( _( "The CADSTAR pad definition '%s' has import errors: %s" ),
1343 csPadcode.Name,
1344 errorMSG );
1345
1346 m_padcodesTested.insert( csPadcode.ID );
1347 }
1348
1349 return pad.release();
1350}
1351
1352
1354 const PAD_ID aCadstarPadID )
1355{
1356 size_t index = aCadstarPadID - (long) 1;
1357
1358 if( !( index < aFootprint->Pads().size() ) )
1359 {
1360 THROW_IO_ERROR( wxString::Format( _( "Unable to find pad index '%d' in footprint '%s'." ),
1361 (long) aCadstarPadID,
1362 aFootprint->GetReference() ) );
1363 }
1364
1365 return aFootprint->Pads().at( index );
1366}
1367
1368
1370{
1371 for( std::pair<GROUP_ID, GROUP> groupPair : Layout.Groups )
1372 {
1373 GROUP& csGroup = groupPair.second;
1374
1375 PCB_GROUP* kiGroup = new PCB_GROUP( m_board );
1376
1377 m_board->Add( kiGroup );
1378 kiGroup->SetName( csGroup.Name );
1379 kiGroup->SetLocked( csGroup.Fixed );
1380
1381 m_groupMap.insert( { csGroup.ID, kiGroup } );
1382 }
1383
1384 //now add any groups to their parent group
1385 for( std::pair<GROUP_ID, GROUP> groupPair : Layout.Groups )
1386 {
1387 GROUP& csGroup = groupPair.second;
1388
1389 if( !csGroup.GroupID.IsEmpty() )
1390 {
1391 if( m_groupMap.find( csGroup.ID ) == m_groupMap.end() )
1392 {
1393 THROW_IO_ERROR( wxString::Format( _( "Unable to find group ID %s in the group "
1394 "definitions." ),
1395 csGroup.ID ) );
1396 }
1397 else if( m_groupMap.find( csGroup.ID ) == m_groupMap.end() )
1398 {
1399 THROW_IO_ERROR( wxString::Format( _( "Unable to find sub group %s in the group "
1400 "map (parent group ID=%s, Name=%s)." ),
1401 csGroup.GroupID,
1402 csGroup.ID,
1403 csGroup.Name ) );
1404 }
1405 else
1406 {
1407 PCB_GROUP* kiCadGroup = m_groupMap.at( csGroup.ID );
1408 PCB_GROUP* parentGroup = m_groupMap.at( csGroup.GroupID );
1409 parentGroup->AddItem( kiCadGroup );
1410 }
1411 }
1412 }
1413}
1414
1415
1417{
1418 for( std::pair<BOARD_ID, CADSTAR_BOARD> boardPair : Layout.Boards )
1419 {
1420 CADSTAR_BOARD& board = boardPair.second;
1421 GROUP_ID boardGroup = createUniqueGroupID( wxT( "Board" ) );
1422 drawCadstarShape( board.Shape, PCB_LAYER_ID::Edge_Cuts,
1424 wxString::Format( wxT( "BOARD %s" ), board.ID ),
1425 m_board, boardGroup );
1426
1427 if( !board.GroupID.IsEmpty() )
1428 {
1429 addToGroup( board.GroupID, getKiCadGroup( boardGroup ) );
1430 }
1431
1432 //TODO process board attributes when KiCad supports them
1433 }
1434}
1435
1436
1438{
1439 for( std::pair<FIGURE_ID, FIGURE> figPair : Layout.Figures )
1440 {
1441 FIGURE& fig = figPair.second;
1442
1443 for( const PCB_LAYER_ID& layer : getKiCadLayerSet( fig.LayerID ).Seq() )
1444 {
1446 layer,
1448 wxString::Format( wxT( "FIGURE %s" ), fig.ID ),
1449 m_board, fig.GroupID );
1450 }
1451
1452 //TODO process "swaprule" (doesn't seem to apply to Layout Figures?)
1453 //TODO process re-use block when KiCad Supports it
1454 //TODO process attributes when KiCad Supports attributes in figures
1455 }
1456}
1457
1458
1460{
1461 for( std::pair<TEXT_ID, TEXT> txtPair : Layout.Texts )
1462 {
1463 TEXT& csTxt = txtPair.second;
1464 drawCadstarText( csTxt, m_board );
1465 }
1466}
1467
1468
1470{
1471 for( std::pair<DIMENSION_ID, DIMENSION> dimPair : Layout.Dimensions )
1472 {
1473 DIMENSION& csDim = dimPair.second;
1474
1475 switch( csDim.Type )
1476 {
1477 case DIMENSION::TYPE::LINEARDIM:
1478 switch( csDim.Subtype )
1479 {
1480 case DIMENSION::SUBTYPE::ANGLED:
1481 wxLogWarning( wxString::Format( _( "Dimension ID %s is an angled dimension, which "
1482 "has no KiCad equivalent. An aligned dimension "
1483 "was loaded instead." ),
1484 csDim.ID ) );
1486 case DIMENSION::SUBTYPE::DIRECT:
1487 case DIMENSION::SUBTYPE::ORTHOGONAL:
1488 {
1489 if( csDim.Line.Style == DIMENSION::LINE::STYLE::EXTERNAL )
1490 {
1491 wxLogWarning( wxString::Format(
1492 _( "Dimension ID %s has 'External' style in CADSTAR. External "
1493 "dimension styles are not yet supported in KiCad. The dimension "
1494 "object was imported with an internal dimension style instead." ),
1495 csDim.ID ) );
1496 }
1497
1498 PCB_DIM_ALIGNED* dimension = nullptr;
1499
1500 if( csDim.Subtype == DIMENSION::SUBTYPE::ORTHOGONAL )
1501 {
1502 dimension = new PCB_DIM_ORTHOGONAL( m_board );
1503 PCB_DIM_ORTHOGONAL* orDim = static_cast<PCB_DIM_ORTHOGONAL*>( dimension );
1504
1505 if( csDim.ExtensionLineParams.Start.x == csDim.Line.Start.x )
1507 else
1509 }
1510 else
1511 {
1512 dimension = new PCB_DIM_ALIGNED( m_board, PCB_DIM_ALIGNED_T );
1513 }
1514
1515 m_board->Add( dimension, ADD_MODE::APPEND );
1516 applyDimensionSettings( csDim, dimension );
1517
1518 dimension->SetExtensionHeight(
1520
1521 // Calculate height:
1522 VECTOR2I crossbarStart = getKiCadPoint( csDim.Line.Start );
1523 VECTOR2I crossbarEnd = getKiCadPoint( csDim.Line.End );
1524 VECTOR2I crossbarVector = crossbarEnd - crossbarStart;
1525 VECTOR2I heightVector = crossbarStart - dimension->GetStart();
1526 double height = 0.0;
1527
1528 if( csDim.Subtype == DIMENSION::SUBTYPE::ORTHOGONAL )
1529 {
1530 if( csDim.ExtensionLineParams.Start.x == csDim.Line.Start.x )
1531 height = heightVector.y;
1532 else
1533 height = heightVector.x;
1534 }
1535 else
1536 {
1537 EDA_ANGLE angle( crossbarVector );
1538 angle += ANGLE_90;
1539 height = heightVector.x * angle.Cos() + heightVector.y * angle.Sin();
1540 }
1541
1542 dimension->SetHeight( height );
1543 }
1544 break;
1545
1546 default:
1547 // Radius and diameter dimensions are LEADERDIM (even if not actually leader)
1548 // Angular dimensions are always ANGLEDIM
1549 wxLogError( _( "Unexpected Dimension type (ID %s). This was not imported." ),
1550 csDim.ID );
1551 continue;
1552 }
1553 break;
1554
1555 case DIMENSION::TYPE::LEADERDIM:
1556 //TODO: update import when KiCad supports radius and diameter dimensions
1557
1558 if( csDim.Line.Style == DIMENSION::LINE::STYLE::INTERNAL )
1559 {
1560 // "internal" is a simple double sided arrow from start to end (no extension lines)
1562 m_board->Add( dimension, ADD_MODE::APPEND );
1563 applyDimensionSettings( csDim, dimension );
1564
1565 // Lets set again start/end:
1566 dimension->SetStart( getKiCadPoint( csDim.Line.Start ) );
1567 dimension->SetEnd( getKiCadPoint( csDim.Line.End ) );
1568
1569 // Do not use any extension lines:
1570 dimension->SetExtensionOffset( 0 );
1571 dimension->SetExtensionHeight( 0 );
1572 dimension->SetHeight( 0 );
1573 }
1574 else
1575 {
1576 // "external" is a "leader" style dimension
1577 PCB_DIM_LEADER* leaderDim = new PCB_DIM_LEADER( m_board );
1578 m_board->Add( leaderDim, ADD_MODE::APPEND );
1579
1580 applyDimensionSettings( csDim, leaderDim );
1581 leaderDim->SetStart( getKiCadPoint( csDim.Line.End ) );
1582
1583 /*
1584 * In CADSTAR, the resulting shape orientation of the leader dimension depends on
1585 * on the positions of the #Start (S) and #End (E) points as shown below. In the
1586 * diagrams below, the leader angle (angRad) is represented by HEV
1587 *
1588 * Orientation 1: (orientX = -1, | Orientation 2: (orientX = 1,
1589 * orientY = 1) | orientY = 1)
1590 * |
1591 * --------V | V----------
1592 * \ | /
1593 * \ | /
1594 * H _E/ | \E_ H
1595 * |
1596 * S | S
1597 * |
1598 *
1599 * Orientation 3: (orientX = -1, | Orientation 4: (orientX = 1,
1600 * orientY = -1) | orientY = -1)
1601 * |
1602 * S | S
1603 * _ | _
1604 * H E\ | /E H
1605 * / | \
1606 * / | \
1607 * ----------V | V-----------
1608 * |
1609 *
1610 * Corner cases:
1611 *
1612 * It is not possible to generate a leader object with start and end point being
1613 * identical. Assume Orientation 2 if start and end points are identical.
1614 *
1615 * If start and end points are aligned vertically (i.e. S.x == E.x):
1616 * - If E.y > S.y - Orientation 2
1617 * - If E.y < S.y - Orientation 4
1618 *
1619 * If start and end points are aligned horitontally (i.e. S.y == E.y):
1620 * - If E.x > S.x - Orientation 2
1621 * - If E.x < S.x - Orientation 1
1622 */
1623 double angRad = DEG2RAD( getAngleDegrees( csDim.Line.LeaderAngle ) );
1624
1625 double orientX = 1;
1626 double orientY = 1;
1627
1628 if( csDim.Line.End.x >= csDim.Line.Start.x )
1629 {
1630 if( csDim.Line.End.y >= csDim.Line.Start.y )
1631 {
1632 //Orientation 2
1633 orientX = 1;
1634 orientY = 1;
1635 }
1636 else
1637 {
1638 //Orientation 4
1639 orientX = 1;
1640 orientY = -1;
1641 }
1642 }
1643 else
1644 {
1645 if( csDim.Line.End.y >= csDim.Line.Start.y )
1646 {
1647 //Orientation 1
1648 orientX = -1;
1649 orientY = 1;
1650 }
1651 else
1652 {
1653 //Orientation 3
1654 orientX = -1;
1655 orientY = -1;
1656 }
1657 }
1658
1659 VECTOR2I endOffset( csDim.Line.LeaderLineLength * cos( angRad ) * orientX,
1660 csDim.Line.LeaderLineLength * sin( angRad ) * orientY );
1661
1662 VECTOR2I endPoint = VECTOR2I( csDim.Line.End ) + endOffset;
1663 VECTOR2I txtPoint( endPoint.x + ( csDim.Line.LeaderLineExtensionLength * orientX ),
1664 endPoint.y );
1665
1666 leaderDim->SetEnd( getKiCadPoint( endPoint ) );
1667 leaderDim->SetTextPos( getKiCadPoint( txtPoint ) );
1668 leaderDim->SetOverrideText( ParseTextFields( csDim.Text.Text, &m_context ) );
1669 leaderDim->SetPrefix( wxEmptyString );
1670 leaderDim->SetSuffix( wxEmptyString );
1671 leaderDim->SetUnitsFormat( DIM_UNITS_FORMAT::NO_SUFFIX );
1672
1673 if( orientX == 1 )
1675 else
1677
1678 leaderDim->SetExtensionOffset( 0 );
1679 }
1680 break;
1681
1682 case DIMENSION::TYPE::ANGLEDIM:
1683 //TODO: update import when KiCad supports angular dimensions
1684 wxLogError( _( "Dimension %s is an angular dimension which has no KiCad equivalent. "
1685 "The object was not imported." ),
1686 csDim.ID );
1687 break;
1688 }
1689 }
1690}
1691
1692
1694{
1695 for( std::pair<AREA_ID, AREA> areaPair : Layout.Areas )
1696 {
1697 AREA& area = areaPair.second;
1698
1699 if( area.NoVias || area.NoTracks || area.Keepout || area.Routing )
1700 {
1701 int lineThickness = 0; // CADSTAR areas only use the line width for display purpose
1702 ZONE* zone = getZoneFromCadstarShape( area.Shape, lineThickness, m_board );
1703
1704 m_board->Add( zone, ADD_MODE::APPEND );
1705
1706 if( isLayerSet( area.LayerID ) )
1707 zone->SetLayerSet( getKiCadLayerSet( area.LayerID ) );
1708 else
1709 zone->SetLayer( getKiCadLayer( area.LayerID ) );
1710
1711 zone->SetIsRuleArea( true ); //import all CADSTAR areas as Keepout zones
1712 zone->SetDoNotAllowPads( false ); //no CADSTAR equivalent
1713 zone->SetZoneName( area.Name );
1714
1715 zone->SetDoNotAllowFootprints( area.Keepout );
1716
1717 zone->SetDoNotAllowTracks( area.NoTracks );
1718 zone->SetDoNotAllowCopperPour( area.NoTracks );
1719
1720 zone->SetDoNotAllowVias( area.NoVias );
1721
1722 if( area.Placement )
1723 {
1724 wxLogWarning( wxString::Format( _( "The CADSTAR area '%s' is marked as a placement "
1725 "area in CADSTAR. Placement areas are not "
1726 "supported in KiCad. Only the supported elements "
1727 "for the area were imported." ),
1728 area.Name ) );
1729 }
1730 }
1731 else
1732 {
1733 wxLogError( wxString::Format( _( "The CADSTAR area '%s' does not have a KiCad "
1734 "equivalent. Pure Placement areas are not supported." ),
1735 area.Name ) );
1736 }
1737
1738 //todo Process area.AreaHeight when KiCad supports 3D design rules
1739 //TODO process attributes
1740 //TODO process addition to a group
1741 //TODO process "swaprule"
1742 //TODO process re-use block
1743 }
1744}
1745
1746
1748{
1749 for( std::pair<COMPONENT_ID, COMPONENT> compPair : Layout.Components )
1750 {
1751 COMPONENT& comp = compPair.second;
1752
1753 if( !comp.VariantID.empty() && comp.VariantParentComponentID != comp.ID )
1754 continue; // Only load master Variant
1755
1756 auto fpIter = m_libraryMap.find( comp.SymdefID );
1757
1758 if( fpIter == m_libraryMap.end() )
1759 {
1760 THROW_IO_ERROR( wxString::Format( _( "Unable to find component '%s' in the library"
1761 "(Symdef ID: '%s')" ),
1762 comp.Name,
1763 comp.SymdefID ) );
1764 }
1765
1766 FOOTPRINT* libFootprint = fpIter->second;
1767
1768 // Use Duplicate() to ensure unique KIID for all objects
1769 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( libFootprint->Duplicate() );
1770
1771 m_board->Add( footprint, ADD_MODE::APPEND );
1772
1773 // First lets fix the pad names on the footprint.
1774 // CADSTAR defines the pad name in the PART definition and the SYMDEF (i.e. the PCB
1775 // footprint definition) uses a numerical sequence. COMP is the only object that has
1776 // visibility of both the SYMDEF and PART.
1777 if( Parts.PartDefinitions.find( comp.PartID ) != Parts.PartDefinitions.end() )
1778 {
1779 PART part = Parts.PartDefinitions.at( comp.PartID );
1780
1781 // Only do this when the number of pins in the part definition equals the number of
1782 // pads in the footprint.
1783 if( part.Definition.Pins.size() == footprint->Pads().size() )
1784 {
1785 for( std::pair<PART_DEFINITION_PIN_ID, PART::DEFINITION::PIN> pinPair :
1786 part.Definition.Pins )
1787 {
1788 PART::DEFINITION::PIN pin = pinPair.second;
1789 wxString pinName = pin.Name;
1790
1791 if( pinName.empty() )
1792 pinName = pin.Identifier;
1793
1794 if( pinName.empty() )
1795 pinName = wxString::Format( wxT( "%ld" ), pin.ID );
1796
1797 getPadReference( footprint, pin.ID )->SetNumber( pinName );
1798 }
1799 }
1800 }
1801
1802 //Override pads with pad exceptions
1803 if( comp.PadExceptions.size() > 0 )
1804 {
1805 SYMDEF_PCB fpLibEntry = Library.ComponentDefinitions.at( comp.SymdefID );
1806
1807 for( std::pair<PAD_ID, PADEXCEPTION> padPair : comp.PadExceptions )
1808 {
1809 PADEXCEPTION& padEx = padPair.second;
1810 COMPONENT_PAD csPad = fpLibEntry.ComponentPads.at( padPair.first );
1811
1812 // Reset the pad to be around 0,0
1813 csPad.Position -= fpLibEntry.Origin;
1814 csPad.Position += m_designCenter;
1815
1816 if( !padEx.PadCode.IsEmpty() )
1817 csPad.PadCodeID = padEx.PadCode;
1818
1819 if( padEx.OverrideExits )
1820 csPad.Exits = padEx.Exits;
1821
1822 if( padEx.OverrideOrientation )
1823 csPad.OrientAngle = padEx.OrientAngle;
1824
1825 if( padEx.OverrideSide )
1826 csPad.Side = padEx.Side;
1827
1828 // Find the pad in the footprint definition
1829 PAD* kiPad = getPadReference( footprint, padEx.ID );
1830
1831 wxString padNumber = kiPad->GetNumber();
1832
1833 delete kiPad;
1834
1835 if( ( kiPad = getKiCadPad( csPad, footprint ) ) )
1836 {
1837 kiPad->SetNumber( padNumber );
1838
1839 // Change the pointer in the footprint to the newly created pad
1840 getPadReference( footprint, padEx.ID ) = kiPad;
1841 }
1842 }
1843 }
1844
1845 //set to empty string to avoid duplication when loading attributes:
1846 footprint->SetValue( wxEmptyString );
1847
1848 footprint->SetPosition( getKiCadPoint( comp.Origin ) );
1849 footprint->SetOrientation( getAngle( comp.OrientAngle ) );
1850 footprint->SetReference( comp.Name );
1851
1852 if( comp.Mirror )
1853 {
1854 EDA_ANGLE mirroredAngle = - getAngle( comp.OrientAngle );
1855 mirroredAngle.Normalize180();
1856 footprint->SetOrientation( mirroredAngle );
1857 footprint->Flip( getKiCadPoint( comp.Origin ), FLIP_DIRECTION::LEFT_RIGHT );
1858 }
1859
1860 loadComponentAttributes( comp, footprint );
1861
1862 if( !comp.PartID.IsEmpty() && comp.PartID != wxT( "NO_PART" ) )
1863 footprint->SetLibDescription( getPart( comp.PartID ).Definition.Name );
1864
1865 m_componentMap.insert( { comp.ID, footprint } );
1866 }
1867}
1868
1869
1871{
1872 //No KiCad equivalent. Loaded as graphic and text elements instead
1873
1874 for( std::pair<DOCUMENTATION_SYMBOL_ID, DOCUMENTATION_SYMBOL> docPair :
1876 {
1877 DOCUMENTATION_SYMBOL& docSymInstance = docPair.second;
1878
1879
1880 auto docSymIter = Library.ComponentDefinitions.find( docSymInstance.SymdefID );
1881
1882 if( docSymIter == Library.ComponentDefinitions.end() )
1883 {
1884 THROW_IO_ERROR( wxString::Format( _( "Unable to find documentation symbol in the "
1885 "library (Symdef ID: '%s')" ),
1886 docSymInstance.SymdefID ) );
1887 }
1888
1889 SYMDEF_PCB& docSymDefinition = ( *docSymIter ).second;
1890 VECTOR2I moveVector =
1891 getKiCadPoint( docSymInstance.Origin ) - getKiCadPoint( docSymDefinition.Origin );
1892 double rotationAngle = getAngleTenthDegree( docSymInstance.OrientAngle );
1893 double scalingFactor = (double) docSymInstance.ScaleRatioNumerator
1894 / (double) docSymInstance.ScaleRatioDenominator;
1895 VECTOR2I centreOfTransform = getKiCadPoint( docSymDefinition.Origin );
1896 bool mirrorInvert = docSymInstance.Mirror;
1897
1898 //create a group to store the items in
1899 wxString groupName = docSymDefinition.ReferenceName;
1900
1901 if( !docSymDefinition.Alternate.IsEmpty() )
1902 groupName += wxT( " (" ) + docSymDefinition.Alternate + wxT( ")" );
1903
1904 GROUP_ID groupID = createUniqueGroupID( groupName );
1905
1906 LSEQ layers = getKiCadLayerSet( docSymInstance.LayerID ).Seq();
1907
1908 for( PCB_LAYER_ID layer : layers )
1909 {
1910 for( std::pair<FIGURE_ID, FIGURE> figPair : docSymDefinition.Figures )
1911 {
1912 FIGURE fig = figPair.second;
1914 wxString::Format( wxT( "DOCUMENTATION SYMBOL %s, FIGURE %s" ),
1915 docSymDefinition.ReferenceName, fig.ID ),
1916 m_board, groupID, moveVector, rotationAngle, scalingFactor,
1917 centreOfTransform, mirrorInvert );
1918 }
1919 }
1920
1921 for( std::pair<TEXT_ID, TEXT> textPair : docSymDefinition.Texts )
1922 {
1923 TEXT txt = textPair.second;
1924 drawCadstarText( txt, m_board, groupID, docSymInstance.LayerID, moveVector,
1925 rotationAngle, scalingFactor, centreOfTransform, mirrorInvert );
1926 }
1927 }
1928}
1929
1930
1932{
1933 for( std::pair<TEMPLATE_ID, TEMPLATE> tempPair : Layout.Templates )
1934 {
1935 TEMPLATE& csTemplate = tempPair.second;
1936
1937 int zonelinethickness = 0; // The line thickness in CADSTAR is only for display purposes but
1938 // does not affect the end copper result.
1939 ZONE* zone = getZoneFromCadstarShape( csTemplate.Shape, zonelinethickness, m_board );
1940
1941 m_board->Add( zone, ADD_MODE::APPEND );
1942
1943 zone->SetZoneName( csTemplate.Name );
1944 zone->SetLayer( getKiCadLayer( csTemplate.LayerID ) );
1945 zone->SetAssignedPriority( 1 ); // initially 1, we will increase in calculateZonePriorities
1946
1947 if( !( csTemplate.NetID.IsEmpty() || csTemplate.NetID == wxT( "NONE" ) ) )
1948 zone->SetNet( getKiCadNet( csTemplate.NetID ) );
1949
1950 if( csTemplate.Pouring.AllowInNoRouting )
1951 {
1952 wxLogWarning( wxString::Format(
1953 _( "The CADSTAR template '%s' has the setting 'Allow in No Routing Areas' "
1954 "enabled. This setting has no KiCad equivalent, so it has been ignored." ),
1955 csTemplate.Name ) );
1956 }
1957
1958 if( csTemplate.Pouring.BoxIsolatedPins )
1959 {
1960 wxLogWarning( wxString::Format(
1961 _( "The CADSTAR template '%s' has the setting 'Box Isolated Pins' "
1962 "enabled. This setting has no KiCad equivalent, so it has been ignored." ),
1963 csTemplate.Name ) );
1964 }
1965
1966 if( csTemplate.Pouring.AutomaticRepour )
1967 {
1968 wxLogWarning( wxString::Format(
1969 _( "The CADSTAR template '%s' has the setting 'Automatic Repour' "
1970 "enabled. This setting has no KiCad equivalent, so it has been ignored." ),
1971 csTemplate.Name ) );
1972 }
1973
1974 // Sliver width has different behaviour to KiCad Zone's minimum thickness
1975 // In Cadstar 'Sliver width' has to be greater than the Copper thickness, whereas in
1976 // Kicad it is the opposite.
1977 if( csTemplate.Pouring.SliverWidth != 0 )
1978 {
1979 wxLogWarning( wxString::Format(
1980 _( "The CADSTAR template '%s' has a non-zero value defined for the "
1981 "'Sliver Width' setting. There is no KiCad equivalent for "
1982 "this, so this setting was ignored." ),
1983 csTemplate.Name ) );
1984 }
1985
1986
1987 if( csTemplate.Pouring.MinIsolatedCopper != csTemplate.Pouring.MinDisjointCopper )
1988 {
1989 wxLogWarning( wxString::Format(
1990 _( "The CADSTAR template '%s' has different settings for 'Retain Poured Copper "
1991 "- Disjoint' and 'Retain Poured Copper - Isolated'. KiCad does not "
1992 "distinguish between these two settings. The setting for disjoint copper "
1993 "has been applied as the minimum island area of the KiCad Zone." ),
1994 csTemplate.Name ) );
1995 }
1996
1997 long long minIslandArea = -1;
1998
1999 if( csTemplate.Pouring.MinDisjointCopper != UNDEFINED_VALUE )
2000 {
2001 minIslandArea = (long long) getKiCadLength( csTemplate.Pouring.MinDisjointCopper )
2002 * (long long) getKiCadLength( csTemplate.Pouring.MinDisjointCopper );
2003
2004 zone->SetIslandRemovalMode( ISLAND_REMOVAL_MODE::AREA );
2005 }
2006 else
2007 {
2008 zone->SetIslandRemovalMode( ISLAND_REMOVAL_MODE::ALWAYS );
2009 }
2010
2011 zone->SetMinIslandArea( minIslandArea );
2012
2013 // In cadstar zone clearance is in addition to the global clearance.
2014 // TODO: need to create custom rules for individual items: zone to pad, zone to track, etc.
2015 int clearance = getKiCadLength( csTemplate.Pouring.AdditionalIsolation );
2017
2018 zone->SetLocalClearance( clearance );
2019
2020 COPPERCODE pouringCopperCode = getCopperCode( csTemplate.Pouring.CopperCodeID );
2021 int minThickness = getKiCadLength( pouringCopperCode.CopperWidth );
2022 zone->SetMinThickness( minThickness );
2023
2024 if( csTemplate.Pouring.FillType == TEMPLATE::POURING::COPPER_FILL_TYPE::HATCHED )
2025 {
2026 zone->SetFillMode( ZONE_FILL_MODE::HATCH_PATTERN );
2027 zone->SetHatchGap( getKiCadHatchCodeGap( csTemplate.Pouring.HatchCodeID ) );
2030 }
2031 else
2032 {
2033 zone->SetFillMode( ZONE_FILL_MODE::POLYGONS );
2034 }
2035
2036 if( csTemplate.Pouring.ThermalReliefOnPads != csTemplate.Pouring.ThermalReliefOnVias
2037 || csTemplate.Pouring.ThermalReliefPadsAngle
2038 != csTemplate.Pouring.ThermalReliefViasAngle )
2039 {
2040 wxLogWarning( wxString::Format(
2041 _( "The CADSTAR template '%s' has different settings for thermal relief "
2042 "in pads and vias. KiCad only supports one single setting for both. The "
2043 "setting for pads has been applied." ),
2044 csTemplate.Name ) );
2045 }
2046
2047 COPPERCODE reliefCopperCode = getCopperCode( csTemplate.Pouring.ReliefCopperCodeID );
2048 int spokeWidth = getKiCadLength( reliefCopperCode.CopperWidth );
2049 int reliefWidth = getKiCadLength( csTemplate.Pouring.ClearanceWidth );
2050
2051 // Cadstar supports having a spoke width thinner than the minimum thickness of the zone, but
2052 // this is not permitted in KiCad. We load it as solid fill instead.
2053 if( csTemplate.Pouring.ThermalReliefOnPads && reliefWidth > 0 )
2054 {
2055 if( spokeWidth < minThickness )
2056 {
2057 wxLogWarning( wxString::Format(
2058 _( "The CADSTAR template '%s' has thermal reliefs in the original design "
2059 "but the spoke width (%.2f mm) is thinner than the minimum thickness of "
2060 "the zone (%.2f mm). KiCad requires the minimum thickness of the zone "
2061 "to be preserved. Therefore the minimum thickness has been applied as "
2062 "the new spoke width and will be applied next time the zones are "
2063 "filled." ),
2064 csTemplate.Name, (double) getKiCadLength( spokeWidth ) / 1E6,
2065 (double) getKiCadLength( minThickness ) / 1E6 ) );
2066
2067 spokeWidth = minThickness;
2068 }
2069
2070 zone->SetThermalReliefGap( reliefWidth );
2071 zone->SetThermalReliefSpokeWidth( spokeWidth );
2072 zone->SetPadConnection( ZONE_CONNECTION::THERMAL );
2073 }
2074 else
2075 {
2076 zone->SetPadConnection( ZONE_CONNECTION::FULL );
2077 }
2078
2079 m_zonesMap.insert( { csTemplate.ID, zone } );
2080 }
2081
2082 //Now create power plane layers:
2083 for( LAYER_ID layer : m_powerPlaneLayers )
2084 {
2085 wxASSERT(
2086 Assignments.Layerdefs.Layers.find( layer ) != Assignments.Layerdefs.Layers.end() );
2087
2088 //The net name will equal the layer name
2089 wxString powerPlaneLayerName = Assignments.Layerdefs.Layers.at( layer ).Name;
2090 NET_ID netid = wxEmptyString;
2091
2092 for( std::pair<NET_ID, NET_PCB> netPair : Layout.Nets )
2093 {
2094 NET_PCB net = netPair.second;
2095
2096 if( net.Name == powerPlaneLayerName )
2097 {
2098 netid = net.ID;
2099 break;
2100 }
2101 }
2102
2103 if( netid.IsEmpty() )
2104 {
2105 wxLogError( _( "The CADSTAR layer '%s' is defined as a power plane layer. However no "
2106 "net with such name exists. The layer has been loaded but no copper "
2107 "zone was created." ),
2108 powerPlaneLayerName );
2109 }
2110 else
2111 {
2112 for( std::pair<BOARD_ID, CADSTAR_BOARD> boardPair : Layout.Boards )
2113 {
2114 //create a zone in each board shape
2116 CADSTAR_BOARD& board = boardPair.second;
2117 int defaultLineThicknesss = bds.GetLineThickness( PCB_LAYER_ID::Edge_Cuts );
2118 ZONE* zone = getZoneFromCadstarShape( board.Shape, defaultLineThicknesss, m_board );
2119
2120 m_board->Add( zone, ADD_MODE::APPEND );
2121
2122 zone->SetZoneName( powerPlaneLayerName );
2123 zone->SetLayer( getKiCadLayer( layer ) );
2124 zone->SetFillMode( ZONE_FILL_MODE::POLYGONS );
2125 zone->SetPadConnection( ZONE_CONNECTION::FULL );
2126 zone->SetMinIslandArea( -1 );
2127 zone->SetAssignedPriority( 0 ); // Priority always 0 (lowest priority) for implied power planes.
2128 zone->SetNet( getKiCadNet( netid ) );
2129 }
2130 }
2131 }
2132}
2133
2134
2136{
2137 for( std::pair<COPPER_ID, COPPER> copPair : Layout.Coppers )
2138 {
2139 COPPER& csCopper = copPair.second;
2140
2141 checkPoint();
2142
2143 if( !csCopper.PouredTemplateID.IsEmpty() )
2144 {
2145 ZONE* pouredZone = m_zonesMap.at( csCopper.PouredTemplateID );
2146 SHAPE_POLY_SET fill;
2147
2148 int copperWidth = getKiCadLength( getCopperCode( csCopper.CopperCodeID ).CopperWidth );
2149
2150 if( csCopper.Shape.Type == SHAPE_TYPE::OPENSHAPE )
2151 {
2152 // This is usually for themal reliefs. They are lines of copper with a thickness.
2153 // We convert them to an oval in most cases, but handle also the possibility of
2154 // encountering arcs in here.
2155
2156 std::vector<PCB_SHAPE*> outlineShapes = getShapesFromVertices( csCopper.Shape.Vertices );
2157
2158 for( PCB_SHAPE* shape : outlineShapes )
2159 {
2160 SHAPE_POLY_SET poly;
2161
2162 if( shape->GetShape() == SHAPE_T::ARC )
2163 {
2164 TransformArcToPolygon( poly, shape->GetStart(), shape->GetArcMid(),
2165 shape->GetEnd(), copperWidth, ARC_HIGH_DEF,
2166 ERROR_LOC::ERROR_INSIDE );
2167 }
2168 else
2169 {
2170 TransformOvalToPolygon( poly, shape->GetStart(), shape->GetEnd(),
2171 copperWidth, ARC_HIGH_DEF,
2172 ERROR_LOC::ERROR_INSIDE );
2173 }
2174
2175 poly.ClearArcs();
2176 fill.BooleanAdd( poly );
2177 }
2178
2179 }
2180 else
2181 {
2182 fill = getPolySetFromCadstarShape( csCopper.Shape, -1 );
2183 fill.ClearArcs();
2184 fill.Inflate( copperWidth / 2, CORNER_STRATEGY::ROUND_ALL_CORNERS, ARC_HIGH_DEF );
2185 }
2186
2187 if( pouredZone->HasFilledPolysForLayer( getKiCadLayer( csCopper.LayerID ) ) )
2188 {
2189 fill.BooleanAdd( *pouredZone->GetFill( getKiCadLayer( csCopper.LayerID ) ) );
2190 }
2191
2192 fill.Fracture();
2193
2194 pouredZone->SetFilledPolysList( getKiCadLayer( csCopper.LayerID ), fill );
2195 pouredZone->SetIsFilled( true );
2196 pouredZone->SetNeedRefill( false );
2197 continue;
2198 }
2199
2200 // For now we are going to load coppers to a KiCad zone however this isn't perfect
2201 //TODO: Load onto a graphical polygon with a net (when KiCad has this feature)
2202
2203 if( !m_doneCopperWarning )
2204 {
2205 wxLogWarning(
2206 _( "The CADSTAR design contains COPPER elements, which have no direct KiCad "
2207 "equivalent. These have been imported as a KiCad Zone if solid or hatch "
2208 "filled, or as a KiCad Track if the shape was an unfilled outline (open or "
2209 "closed)." ) );
2210 m_doneCopperWarning = true;
2211 }
2212
2213
2214 if( csCopper.Shape.Type == SHAPE_TYPE::OPENSHAPE
2215 || csCopper.Shape.Type == SHAPE_TYPE::OUTLINE )
2216 {
2217 std::vector<PCB_SHAPE*> outlineShapes = getShapesFromVertices( csCopper.Shape.Vertices );
2218
2219 std::vector<PCB_TRACK*> outlineTracks = makeTracksFromShapes( outlineShapes, m_board,
2220 getKiCadNet( csCopper.NetRef.NetID ),
2221 getKiCadLayer( csCopper.LayerID ),
2223
2224 //cleanup
2225 for( PCB_SHAPE* shape : outlineShapes )
2226 delete shape;
2227
2228 for( CUTOUT cutout : csCopper.Shape.Cutouts )
2229 {
2230 std::vector<PCB_SHAPE*> cutoutShapes = getShapesFromVertices( cutout.Vertices );
2231
2232 std::vector<PCB_TRACK*> cutoutTracks = makeTracksFromShapes( cutoutShapes, m_board,
2233 getKiCadNet( csCopper.NetRef.NetID ),
2234 getKiCadLayer( csCopper.LayerID ),
2236
2237 //cleanup
2238 for( PCB_SHAPE* shape : cutoutShapes )
2239 delete shape;
2240 }
2241 }
2242 else
2243 {
2244 ZONE* zone = getZoneFromCadstarShape( csCopper.Shape,
2246 m_board );
2247
2248 m_board->Add( zone, ADD_MODE::APPEND );
2249
2250 zone->SetZoneName( csCopper.ID );
2251 zone->SetLayer( getKiCadLayer( csCopper.LayerID ) );
2252 zone->SetHatchStyle( ZONE_BORDER_DISPLAY_STYLE::NO_HATCH );
2253
2254 if( csCopper.Shape.Type == SHAPE_TYPE::HATCHED )
2255 {
2256 zone->SetFillMode( ZONE_FILL_MODE::HATCH_PATTERN );
2260 }
2261 else
2262 {
2263 zone->SetFillMode( ZONE_FILL_MODE::POLYGONS );
2264 }
2265
2266 zone->SetIslandRemovalMode( ISLAND_REMOVAL_MODE::NEVER );
2267 zone->SetPadConnection( ZONE_CONNECTION::FULL );
2268 zone->SetNet( getKiCadNet( csCopper.NetRef.NetID ) );
2269 zone->SetAssignedPriority( m_zonesMap.size() + 1 ); // Highest priority (always fill first)
2270
2271 SHAPE_POLY_SET fill( *zone->Outline() );
2272 fill.Fracture();
2273
2274 zone->SetFilledPolysList( getKiCadLayer( csCopper.LayerID ), fill );
2275 }
2276 }
2277}
2278
2279
2281{
2282 for( std::pair<NET_ID, NET_PCB> netPair : Layout.Nets )
2283 {
2284 NET_PCB net = netPair.second;
2285 wxString netnameForErrorReporting = net.Name;
2286
2287 std::map<NETELEMENT_ID, long> netelementSizes;
2288
2289 if( netnameForErrorReporting.IsEmpty() )
2290 netnameForErrorReporting = wxString::Format( wxT( "$%ld" ), net.SignalNum );
2291
2292 for( std::pair<NETELEMENT_ID, NET_PCB::VIA> viaPair : net.Vias )
2293 {
2294 NET_PCB::VIA via = viaPair.second;
2295
2296 // viasize is used for calculating route offset (as done in CADSTAR post processor)
2297 int viaSize = loadNetVia( net.ID, via );
2298 netelementSizes.insert( { viaPair.first, viaSize } );
2299 }
2300
2301 for( std::pair<NETELEMENT_ID, NET_PCB::PIN> pinPair : net.Pins )
2302 {
2303 NET_PCB::PIN pin = pinPair.second;
2304 FOOTPRINT* footprint = getFootprintFromCadstarID( pin.ComponentID );
2305
2306 if( footprint == nullptr )
2307 {
2308 wxLogWarning( wxString::Format(
2309 _( "The net '%s' references component ID '%s' which does not exist. "
2310 "This has been ignored." ),
2311 netnameForErrorReporting, pin.ComponentID ) );
2312 }
2313 else if( ( pin.PadID - (long) 1 ) > footprint->Pads().size() )
2314 {
2315 wxLogWarning( wxString::Format( _( "The net '%s' references non-existent pad index"
2316 " '%d' in component '%s'. This has been "
2317 "ignored." ),
2318 netnameForErrorReporting,
2319 pin.PadID,
2320 footprint->GetReference() ) );
2321 }
2322 else
2323 {
2324 // The below works because we have added the pads in the correct order to the
2325 // footprint and the PAD_ID in Cadstar is a sequential, numerical ID
2326 PAD* pad = getPadReference( footprint, pin.PadID );
2327 pad->SetNet( getKiCadNet( net.ID ) );
2328
2329 // also set the net to any copper pads (i.e. copper elements that we have imported
2330 // as pads instead:
2331 SYMDEF_ID symdefid = Layout.Components.at( pin.ComponentID ).SymdefID;
2332
2333 if( m_librarycopperpads.find( symdefid ) != m_librarycopperpads.end() )
2334 {
2335 ASSOCIATED_COPPER_PADS assocPads = m_librarycopperpads.at( symdefid );
2336
2337 if( assocPads.find( pin.PadID ) != assocPads.end() )
2338 {
2339 for( PAD_ID copperPadID : assocPads.at( pin.PadID ) )
2340 {
2341 PAD* copperpad = getPadReference( footprint, copperPadID );
2342 copperpad->SetNet( getKiCadNet( net.ID ) );
2343 }
2344 }
2345 }
2346
2347 // padsize is used for calculating route offset (as done in CADSTAR post processor)
2348 int padsize = std::min( pad->GetSizeX(), pad->GetSizeY() );
2349 netelementSizes.insert( { pinPair.first, padsize } );
2350 }
2351 }
2352
2353 // For junction points we need to find out the biggest size of the other routes connecting
2354 // at the junction in order to correctly apply the same "route offset" operation that the
2355 // CADSTAR post processor applies when generating Manufacturing output. The only exception
2356 // is if there is just a single route at the junction point, we use that route width
2357 auto getJunctionSize =
2358 [&]( NETELEMENT_ID aJptNetElemId, const NET_PCB::CONNECTION_PCB& aConnectionToIgnore ) -> int
2359 {
2360 int jptsize = std::numeric_limits<int>::max();
2361
2362 for( NET_PCB::CONNECTION_PCB connection : net.Connections )
2363 {
2364 if( connection.Route.RouteVertices.size() == 0 )
2365 continue;
2366
2367 if( connection.StartNode == aConnectionToIgnore.StartNode
2368 && connection.EndNode == aConnectionToIgnore.EndNode )
2369 {
2370 continue;
2371 }
2372
2373 if( connection.StartNode == aJptNetElemId )
2374 {
2375 int s = getKiCadLength( connection.Route.RouteVertices.front().RouteWidth );
2376 jptsize = std::max( jptsize, s );
2377 }
2378 else if( connection.EndNode == aJptNetElemId )
2379 {
2380 int s = getKiCadLength( connection.Route.RouteVertices.back().RouteWidth );
2381 jptsize = std::max( jptsize, s );
2382 }
2383 }
2384
2385 if( jptsize == std::numeric_limits<int>::max()
2386 && !aConnectionToIgnore.Route.RouteVertices.empty() )
2387 {
2388 // aConnectionToIgnore is actually the only one that has a route, so lets use that
2389 // to determine junction size
2390 NET_PCB::ROUTE_VERTEX vertex = aConnectionToIgnore.Route.RouteVertices.front();
2391
2392 if( aConnectionToIgnore.EndNode == aJptNetElemId )
2393 vertex = aConnectionToIgnore.Route.RouteVertices.back();
2394
2395 jptsize = getKiCadLength( vertex.RouteWidth );
2396 }
2397
2398 return jptsize;
2399 };
2400
2401 for( NET_PCB::CONNECTION_PCB connection : net.Connections )
2402 {
2403 int startSize = std::numeric_limits<int>::max();
2404 int endSize = std::numeric_limits<int>::max();
2405
2406 if( netelementSizes.find( connection.StartNode ) != netelementSizes.end() )
2407 startSize = netelementSizes.at( connection.StartNode );
2408 else if( net.Junctions.find( connection.StartNode ) != net.Junctions.end() )
2409 startSize = getJunctionSize( connection.StartNode, connection );
2410
2411 if( netelementSizes.find( connection.EndNode ) != netelementSizes.end() )
2412 endSize = netelementSizes.at( connection.EndNode );
2413 else if( net.Junctions.find( connection.EndNode ) != net.Junctions.end() )
2414 endSize = getJunctionSize( connection.EndNode, connection );
2415
2416 startSize /= KiCadUnitMultiplier;
2417 endSize /= KiCadUnitMultiplier;
2418
2419 if( !connection.Unrouted )
2420 loadNetTracks( net.ID, connection.Route, startSize, endSize );
2421 }
2422 }
2423}
2424
2425
2427{
2428 auto findAndReplaceTextField =
2429 [&]( TEXT_FIELD_NAME aField, wxString aValue )
2430 {
2431 if( m_context.TextFieldToValuesMap.find( aField ) !=
2433 {
2434 if( m_context.TextFieldToValuesMap.at( aField ) != aValue )
2435 {
2436 m_context.TextFieldToValuesMap.at( aField ) = aValue;
2437 m_context.InconsistentTextFields.insert( aField );
2438 return false;
2439 }
2440 }
2441 else
2442 {
2443 m_context.TextFieldToValuesMap.insert( { aField, aValue } );
2444 }
2445
2446 return true;
2447 };
2448
2449 if( m_project )
2450 {
2451 std::map<wxString, wxString>& txtVars = m_project->GetTextVars();
2452
2453 // Most of the design text fields can be derived from other elements
2454 if( Layout.VariantHierarchy.Variants.size() > 0 )
2455 {
2456 VARIANT loadedVar = Layout.VariantHierarchy.Variants.begin()->second;
2457
2458 findAndReplaceTextField( TEXT_FIELD_NAME::VARIANT_NAME, loadedVar.Name );
2459 findAndReplaceTextField( TEXT_FIELD_NAME::VARIANT_DESCRIPTION, loadedVar.Description );
2460 }
2461
2462 findAndReplaceTextField( TEXT_FIELD_NAME::DESIGN_TITLE, Header.JobTitle );
2463
2464 for( std::pair<TEXT_FIELD_NAME, wxString> txtvalue : m_context.TextFieldToValuesMap )
2465 {
2466 wxString varName = CADSTAR_TO_KICAD_FIELDS.at( txtvalue.first );
2467 wxString varValue = txtvalue.second;
2468
2469 txtVars.insert( { varName, varValue } );
2470 }
2471
2472 for( std::pair<wxString, wxString> txtvalue : m_context.FilenamesToTextMap )
2473 {
2474 wxString varName = txtvalue.first;
2475 wxString varValue = txtvalue.second;
2476
2477 txtVars.insert( { varName, varValue } );
2478 }
2479 }
2480 else
2481 {
2482 wxLogError( _( "Text Variables could not be set as there is no project loaded." ) );
2483 }
2484}
2485
2486
2488 FOOTPRINT* aFootprint )
2489{
2490 for( std::pair<ATTRIBUTE_ID, ATTRIBUTE_VALUE> attrPair : aComponent.AttributeValues )
2491 {
2492 ATTRIBUTE_VALUE& attrval = attrPair.second;
2493
2494 if( attrval.HasLocation ) //only import attributes with location. Ignore the rest
2495 {
2496 addAttribute( attrval.AttributeLocation, attrval.AttributeID, aFootprint,
2497 attrval.Value );
2498 }
2499 }
2500
2501 for( std::pair<ATTRIBUTE_ID, TEXT_LOCATION> textlocPair : aComponent.TextLocations )
2502 {
2503 TEXT_LOCATION& textloc = textlocPair.second;
2504 wxString attrval;
2505
2506 if( textloc.AttributeID == COMPONENT_NAME_ATTRID )
2507 {
2508 attrval = wxEmptyString; // Designator is loaded separately
2509 }
2510 else if( textloc.AttributeID == COMPONENT_NAME_2_ATTRID )
2511 {
2512 attrval = wxT( "${REFERENCE}" );
2513 }
2514 else if( textloc.AttributeID == PART_NAME_ATTRID )
2515 {
2516 attrval = getPart( aComponent.PartID ).Name;
2517 }
2518 else
2519 attrval = getAttributeValue( textloc.AttributeID, aComponent.AttributeValues );
2520
2521 addAttribute( textloc, textloc.AttributeID, aFootprint, attrval );
2522 }
2523}
2524
2525
2527 const NET_PCB::ROUTE& aCadstarRoute,
2528 long aStartWidth, long aEndWidth )
2529{
2530 if( aCadstarRoute.RouteVertices.size() == 0 )
2531 return;
2532
2533 std::vector<PCB_SHAPE*> shapes;
2534 std::vector<NET_PCB::ROUTE_VERTEX> routeVertices = aCadstarRoute.RouteVertices;
2535
2536 // Add thin route at front so that route offsetting works as expected
2537 if( aStartWidth < routeVertices.front().RouteWidth )
2538 {
2539 NET_PCB::ROUTE_VERTEX newFrontVertex = aCadstarRoute.RouteVertices.front();
2540 newFrontVertex.RouteWidth = aStartWidth;
2541 newFrontVertex.Vertex.End = aCadstarRoute.StartPoint;
2542 routeVertices.insert( routeVertices.begin(), newFrontVertex );
2543 }
2544
2545 // Add thin route at the back if required
2546 if( aEndWidth < routeVertices.back().RouteWidth )
2547 {
2548 NET_PCB::ROUTE_VERTEX newBackVertex = aCadstarRoute.RouteVertices.back();
2549 newBackVertex.RouteWidth = aEndWidth;
2550 routeVertices.push_back( newBackVertex );
2551 }
2552
2553 POINT prevEnd = aCadstarRoute.StartPoint;
2554
2555 for( const NET_PCB::ROUTE_VERTEX& v : routeVertices )
2556 {
2557 PCB_SHAPE* shape = getShapeFromVertex( prevEnd, v.Vertex );
2558 shape->SetLayer( getKiCadLayer( aCadstarRoute.LayerID ) );
2559 shape->SetStroke( STROKE_PARAMS( getKiCadLength( v.RouteWidth ), LINE_STYLE::SOLID ) );
2560 shape->SetLocked( v.Fixed );
2561 shapes.push_back( shape );
2562 prevEnd = v.Vertex.End;
2563
2564 if( !m_doneTearDropWarning && ( v.TeardropAtEnd || v.TeardropAtStart ) )
2565 {
2566 // TODO: load teardrops
2567 wxLogError( _( "The CADSTAR design contains teardrops. This importer does not yet "
2568 "support them, so the teardrops in the design have been ignored." ) );
2569
2570 m_doneTearDropWarning = true;
2571 }
2572 }
2573
2574 NETINFO_ITEM* net = getKiCadNet( aCadstarNetID );
2575 std::vector<PCB_TRACK*> tracks = makeTracksFromShapes( shapes, m_board, net );
2576
2577 //cleanup
2578 for( PCB_SHAPE* shape : shapes )
2579 delete shape;
2580}
2581
2582
2584 const NET_ID& aCadstarNetID, const NET_PCB::VIA& aCadstarVia )
2585{
2586 PCB_VIA* via = new PCB_VIA( m_board );
2587 m_board->Add( via, ADD_MODE::APPEND );
2588
2589 VIACODE csViaCode = getViaCode( aCadstarVia.ViaCodeID );
2590 LAYERPAIR csLayerPair = getLayerPair( aCadstarVia.LayerPairID );
2591
2592 via->SetPosition( getKiCadPoint( aCadstarVia.Location ) );
2593 via->SetDrill( getKiCadLength( csViaCode.DrillDiameter ) );
2594 via->SetLocked( aCadstarVia.Fixed );
2595
2596 if( csViaCode.Shape.ShapeType != PAD_SHAPE_TYPE::CIRCLE )
2597 {
2598 wxLogError( _( "The CADSTAR via code '%s' has different shape from a circle defined. "
2599 "KiCad only supports circular vias so this via type has been changed to "
2600 "be a via with circular shape of %.2f mm diameter." ),
2601 csViaCode.Name,
2602 (double) ( (double) getKiCadLength( csViaCode.Shape.Size ) / 1E6 ) );
2603 }
2604
2605 via->SetWidth( PADSTACK::ALL_LAYERS, getKiCadLength( csViaCode.Shape.Size ) );
2606
2607 bool start_layer_outside =
2608 csLayerPair.PhysicalLayerStart == 1
2610 bool end_layer_outside =
2611 csLayerPair.PhysicalLayerEnd == 1
2613
2614 if( start_layer_outside && end_layer_outside )
2615 {
2616 via->SetViaType( VIATYPE::THROUGH );
2617 }
2618 else if( ( !start_layer_outside ) && ( !end_layer_outside ) )
2619 {
2620 via->SetViaType( VIATYPE::BLIND_BURIED );
2621 }
2622 else
2623 {
2624 via->SetViaType( VIATYPE::MICROVIA );
2625 }
2626
2627 via->SetLayerPair( getKiCadCopperLayerID( csLayerPair.PhysicalLayerStart ),
2628 getKiCadCopperLayerID( csLayerPair.PhysicalLayerEnd ) );
2629 via->SetNet( getKiCadNet( aCadstarNetID ) );
2631
2632 return via->GetWidth( PADSTACK::ALL_LAYERS );
2633}
2634
2635
2637 BOARD_ITEM_CONTAINER* aContainer,
2638 const GROUP_ID& aCadstarGroupID,
2639 const LAYER_ID& aCadstarLayerOverride,
2640 const VECTOR2I& aMoveVector,
2641 double aRotationAngle, double aScalingFactor,
2642 const VECTOR2I& aTransformCentre,
2643 bool aMirrorInvert )
2644{
2645 PCB_TEXT* txt = new PCB_TEXT( aContainer );
2646 aContainer->Add( txt );
2647 txt->SetText( aCadstarText.Text );
2648
2649 EDA_ANGLE rotationAngle( aRotationAngle, TENTHS_OF_A_DEGREE_T );
2650 VECTOR2I rotatedTextPos = getKiCadPoint( aCadstarText.Position );
2651 RotatePoint( rotatedTextPos, aTransformCentre, rotationAngle );
2652 rotatedTextPos.x = KiROUND( ( rotatedTextPos.x - aTransformCentre.x ) * aScalingFactor );
2653 rotatedTextPos.y = KiROUND( ( rotatedTextPos.y - aTransformCentre.y ) * aScalingFactor );
2654 rotatedTextPos += aTransformCentre;
2655 txt->SetTextPos( rotatedTextPos );
2656 txt->SetPosition( rotatedTextPos );
2657
2658 txt->SetTextAngle( getAngle( aCadstarText.OrientAngle ) + rotationAngle );
2659
2660 txt->SetMirrored( aCadstarText.Mirror );
2661
2662 applyTextCode( txt, aCadstarText.TextCodeID );
2663
2664 switch( aCadstarText.Alignment )
2665 {
2666 case ALIGNMENT::NO_ALIGNMENT: // Default for Single line text is Bottom Left
2670 break;
2671
2675 break;
2676
2680 break;
2681
2685 break;
2686
2690 break;
2691
2695 break;
2696
2697 case ALIGNMENT::TOPLEFT:
2700 break;
2701
2705 break;
2706
2710 break;
2711
2712 default:
2713 wxFAIL_MSG( wxT( "Unknown Alignment - needs review!" ) );
2714 }
2715
2716 if( aMirrorInvert )
2717 txt->Flip( aTransformCentre, FLIP_DIRECTION::LEFT_RIGHT );
2718
2719 //scale it after flipping:
2720 if( aScalingFactor != 1.0 )
2721 {
2722 VECTOR2I unscaledTextSize = txt->GetTextSize();
2723 int unscaledThickness = txt->GetTextThickness();
2724
2725 VECTOR2I scaledTextSize;
2726 scaledTextSize.x = KiROUND( (double) unscaledTextSize.x * aScalingFactor );
2727 scaledTextSize.y = KiROUND( (double) unscaledTextSize.y * aScalingFactor );
2728
2729 txt->SetTextSize( scaledTextSize );
2730 txt->SetTextThickness( KiROUND( (double) unscaledThickness * aScalingFactor ) );
2731 }
2732
2733 txt->Move( aMoveVector );
2734
2735 if( aCadstarText.Alignment == ALIGNMENT::NO_ALIGNMENT )
2737
2738 LAYER_ID layersToDrawOn = aCadstarLayerOverride;
2739
2740 if( layersToDrawOn.IsEmpty() )
2741 layersToDrawOn = aCadstarText.LayerID;
2742
2743 if( isLayerSet( layersToDrawOn ) )
2744 {
2745 //Make a copy on each layer
2746 for( PCB_LAYER_ID layer : getKiCadLayerSet( layersToDrawOn ).Seq() )
2747 {
2748 txt->SetLayer( layer );
2749 PCB_TEXT* newtxt = static_cast<PCB_TEXT*>( txt->Duplicate() );
2750 m_board->Add( newtxt, ADD_MODE::APPEND );
2751
2752 if( !aCadstarGroupID.IsEmpty() )
2753 addToGroup( aCadstarGroupID, newtxt );
2754 }
2755
2756 m_board->Remove( txt );
2757 delete txt;
2758 }
2759 else
2760 {
2761 txt->SetLayer( getKiCadLayer( layersToDrawOn ) );
2762
2763 if( !aCadstarGroupID.IsEmpty() )
2764 addToGroup( aCadstarGroupID, txt );
2765 }
2766 //TODO Handle different font types when KiCad can support it.
2767}
2768
2769
2771 const PCB_LAYER_ID& aKiCadLayer,
2772 int aLineThickness,
2773 const wxString& aShapeName,
2774 BOARD_ITEM_CONTAINER* aContainer,
2775 const GROUP_ID& aCadstarGroupID,
2776 const VECTOR2I& aMoveVector,
2777 double aRotationAngle, double aScalingFactor,
2778 const VECTOR2I& aTransformCentre,
2779 bool aMirrorInvert )
2780{
2781 auto drawAsOutline = [&]()
2782 {
2783 drawCadstarVerticesAsShapes( aCadstarShape.Vertices, aKiCadLayer, aLineThickness,
2784 aContainer, aCadstarGroupID, aMoveVector, aRotationAngle,
2785 aScalingFactor, aTransformCentre, aMirrorInvert );
2786 drawCadstarCutoutsAsShapes( aCadstarShape.Cutouts, aKiCadLayer, aLineThickness, aContainer,
2787 aCadstarGroupID, aMoveVector, aRotationAngle, aScalingFactor,
2788 aTransformCentre, aMirrorInvert );
2789 };
2790
2791 switch( aCadstarShape.Type )
2792 {
2796 drawAsOutline();
2797 break;
2798
2801 wxLogWarning( wxString::Format(
2802 _( "The shape for '%s' is Hatch filled in CADSTAR, which has no KiCad equivalent. "
2803 "Using solid fill instead." ),
2804 aShapeName ) );
2805
2806 case SHAPE_TYPE::SOLID:
2807 {
2808 // Special case solid shapes that are effectively a single line
2809 if( aCadstarShape.Vertices.size() < 3 )
2810 {
2811 drawAsOutline();
2812 break;
2813 }
2814
2815 PCB_SHAPE* shape = new PCB_SHAPE( aContainer, SHAPE_T::POLY );
2816
2817 shape->SetFilled( true );
2818
2819 SHAPE_POLY_SET shapePolys = getPolySetFromCadstarShape( aCadstarShape, -1, aContainer,
2820 aMoveVector, aRotationAngle,
2821 aScalingFactor, aTransformCentre,
2822 aMirrorInvert );
2823
2824 shapePolys.Fracture();
2825
2826 shape->SetPolyShape( shapePolys );
2827 shape->SetStroke( STROKE_PARAMS( aLineThickness, LINE_STYLE::SOLID ) );
2828 shape->SetLayer( aKiCadLayer );
2829 aContainer->Add( shape, ADD_MODE::APPEND );
2830
2831 if( !aCadstarGroupID.IsEmpty() )
2832 addToGroup( aCadstarGroupID, shape );
2833 }
2834 break;
2835 }
2836}
2837
2838
2839void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarCutoutsAsShapes( const std::vector<CUTOUT>& aCutouts,
2840 const PCB_LAYER_ID& aKiCadLayer,
2841 int aLineThickness,
2842 BOARD_ITEM_CONTAINER* aContainer,
2843 const GROUP_ID& aCadstarGroupID,
2844 const VECTOR2I& aMoveVector,
2845 double aRotationAngle,
2846 double aScalingFactor,
2847 const VECTOR2I& aTransformCentre,
2848 bool aMirrorInvert )
2849{
2850 for( const CUTOUT& cutout : aCutouts )
2851 {
2852 drawCadstarVerticesAsShapes( cutout.Vertices, aKiCadLayer, aLineThickness, aContainer,
2853 aCadstarGroupID, aMoveVector, aRotationAngle, aScalingFactor,
2854 aTransformCentre, aMirrorInvert );
2855 }
2856}
2857
2858
2859void CADSTAR_PCB_ARCHIVE_LOADER::drawCadstarVerticesAsShapes( const std::vector<VERTEX>& aCadstarVertices,
2860 const PCB_LAYER_ID& aKiCadLayer,
2861 int aLineThickness,
2862 BOARD_ITEM_CONTAINER* aContainer,
2863 const GROUP_ID& aCadstarGroupID,
2864 const VECTOR2I& aMoveVector,
2865 double aRotationAngle,
2866 double aScalingFactor,
2867 const VECTOR2I& aTransformCentre,
2868 bool aMirrorInvert )
2869{
2870 std::vector<PCB_SHAPE*> shapes = getShapesFromVertices( aCadstarVertices, aContainer,
2871 aCadstarGroupID, aMoveVector,
2872 aRotationAngle, aScalingFactor,
2873 aTransformCentre, aMirrorInvert );
2874
2875 for( PCB_SHAPE* shape : shapes )
2876 {
2877 shape->SetStroke( STROKE_PARAMS( aLineThickness, LINE_STYLE::SOLID ) );
2878 shape->SetLayer( aKiCadLayer );
2879 shape->SetParent( aContainer );
2880 aContainer->Add( shape, ADD_MODE::APPEND );
2881 }
2882}
2883
2884
2885std::vector<PCB_SHAPE*>
2886CADSTAR_PCB_ARCHIVE_LOADER::getShapesFromVertices( const std::vector<VERTEX>& aCadstarVertices,
2887 BOARD_ITEM_CONTAINER* aContainer,
2888 const GROUP_ID& aCadstarGroupID,
2889 const VECTOR2I& aMoveVector,
2890 double aRotationAngle, double aScalingFactor,
2891 const VECTOR2I& aTransformCentre,
2892 bool aMirrorInvert )
2893{
2894 std::vector<PCB_SHAPE*> shapes;
2895
2896 if( aCadstarVertices.size() < 2 )
2897 //need at least two points to draw a segment! (unlikely but possible to have only one)
2898 return shapes;
2899
2900 const VERTEX* prev = &aCadstarVertices.at( 0 ); // first one should always be a point vertex
2901 const VERTEX* cur;
2902
2903 for( size_t i = 1; i < aCadstarVertices.size(); i++ )
2904 {
2905 cur = &aCadstarVertices.at( i );
2906 shapes.push_back( getShapeFromVertex( prev->End, *cur, aContainer, aCadstarGroupID,
2907 aMoveVector, aRotationAngle, aScalingFactor,
2908 aTransformCentre, aMirrorInvert ) );
2909 prev = cur;
2910 }
2911
2912 return shapes;
2913}
2914
2915
2917 const VERTEX& aCadstarVertex,
2918 BOARD_ITEM_CONTAINER* aContainer,
2919 const GROUP_ID& aCadstarGroupID,
2920 const VECTOR2I& aMoveVector,
2921 double aRotationAngle,
2922 double aScalingFactor,
2923 const VECTOR2I& aTransformCentre,
2924 bool aMirrorInvert )
2925{
2926 PCB_SHAPE* shape = nullptr;
2927 bool cw = false;
2928
2929 VECTOR2I startPoint = getKiCadPoint( aCadstarStartPoint );
2930 VECTOR2I endPoint = getKiCadPoint( aCadstarVertex.End );
2931 VECTOR2I centerPoint;
2932
2933 if( aCadstarVertex.Type == VERTEX_TYPE::ANTICLOCKWISE_SEMICIRCLE
2934 || aCadstarVertex.Type == VERTEX_TYPE::CLOCKWISE_SEMICIRCLE )
2935 {
2936 centerPoint = ( startPoint + endPoint ) / 2;
2937 }
2938 else
2939 {
2940 centerPoint = getKiCadPoint( aCadstarVertex.Center );
2941 }
2942
2943 switch( aCadstarVertex.Type )
2944 {
2945
2946 case VERTEX_TYPE::POINT:
2947 shape = new PCB_SHAPE( aContainer, SHAPE_T::SEGMENT );
2948
2949 shape->SetStart( startPoint );
2950 shape->SetEnd( endPoint );
2951 break;
2952
2955 cw = true;
2957
2960 {
2961 shape = new PCB_SHAPE( aContainer, SHAPE_T::ARC );
2962
2963 shape->SetCenter( centerPoint );
2964 shape->SetStart( startPoint );
2965
2966 EDA_ANGLE arcStartAngle( startPoint - centerPoint );
2967 EDA_ANGLE arcEndAngle( endPoint - centerPoint );
2968 EDA_ANGLE arcAngle = ( arcEndAngle - arcStartAngle ).Normalize();
2969 //TODO: detect if we are supposed to draw a circle instead (i.e. two SEMICIRCLEs
2970 // with opposite start/end points and same centre point)
2971
2972 if( !cw )
2973 arcAngle.NormalizeNegative(); // anticlockwise arc
2974
2975 shape->SetArcAngleAndEnd( arcAngle, true );
2976
2977 break;
2978 }
2979 }
2980
2981 //Apply transforms
2982 if( aMirrorInvert )
2983 shape->Flip( aTransformCentre, FLIP_DIRECTION::LEFT_RIGHT );
2984
2985 if( aScalingFactor != 1.0 )
2986 {
2987 shape->Move( -1*aTransformCentre );
2988 shape->Scale( aScalingFactor );
2989 shape->Move( aTransformCentre );
2990 }
2991
2992 if( aRotationAngle != 0.0 )
2993 shape->Rotate( aTransformCentre, EDA_ANGLE( aRotationAngle, TENTHS_OF_A_DEGREE_T ) );
2994
2995 if( aMoveVector != VECTOR2I{ 0, 0 } )
2996 shape->Move( aMoveVector );
2997
2998 if( !aCadstarGroupID.IsEmpty() )
2999 addToGroup( aCadstarGroupID, shape );
3000
3001 return shape;
3002}
3003
3004
3006 const int& aLineThickness,
3007 BOARD_ITEM_CONTAINER* aParentContainer )
3008{
3009 ZONE* zone = new ZONE( aParentContainer );
3010
3011 if( aCadstarShape.Type == SHAPE_TYPE::HATCHED )
3012 {
3013 zone->SetFillMode( ZONE_FILL_MODE::HATCH_PATTERN );
3014 zone->SetHatchStyle( ZONE_BORDER_DISPLAY_STYLE::DIAGONAL_FULL );
3015 }
3016 else
3017 {
3018 zone->SetHatchStyle( ZONE_BORDER_DISPLAY_STYLE::NO_HATCH );
3019 }
3020
3021 SHAPE_POLY_SET polygon = getPolySetFromCadstarShape( aCadstarShape, aLineThickness );
3022
3023 zone->AddPolygon( polygon.COutline( 0 ) );
3024
3025 for( int i = 0; i < polygon.HoleCount( 0 ); i++ )
3026 zone->AddPolygon( polygon.CHole( 0, i ) );
3027
3028 return zone;
3029}
3030
3031
3033 int aLineThickness,
3034 BOARD_ITEM_CONTAINER* aContainer,
3035 const VECTOR2I& aMoveVector,
3036 double aRotationAngle,
3037 double aScalingFactor,
3038 const VECTOR2I& aTransformCentre,
3039 bool aMirrorInvert )
3040{
3041 GROUP_ID noGroup = wxEmptyString;
3042
3043 std::vector<PCB_SHAPE*> outlineShapes = getShapesFromVertices( aCadstarShape.Vertices,
3044 aContainer, noGroup, aMoveVector,
3045 aRotationAngle, aScalingFactor,
3046 aTransformCentre, aMirrorInvert );
3047
3048 SHAPE_POLY_SET polySet( getLineChainFromShapes( outlineShapes ) );
3049
3050 //cleanup
3051 for( PCB_SHAPE* shape : outlineShapes )
3052 delete shape;
3053
3054 for( const CUTOUT& cutout : aCadstarShape.Cutouts )
3055 {
3056 std::vector<PCB_SHAPE*> cutoutShapes = getShapesFromVertices( cutout.Vertices, aContainer,
3057 noGroup, aMoveVector,
3058 aRotationAngle, aScalingFactor,
3059 aTransformCentre, aMirrorInvert );
3060
3061 polySet.AddHole( getLineChainFromShapes( cutoutShapes ) );
3062
3063 //cleanup
3064 for( PCB_SHAPE* shape : cutoutShapes )
3065 delete shape;
3066 }
3067
3068 polySet.ClearArcs();
3069
3070 if( aLineThickness > 0 )
3071 polySet.Inflate( aLineThickness / 2, CORNER_STRATEGY::ROUND_ALL_CORNERS, ARC_HIGH_DEF );
3072
3073#ifdef DEBUG
3074 for( int i = 0; i < polySet.OutlineCount(); ++i )
3075 {
3076 wxASSERT( polySet.Outline( i ).PointCount() > 2 );
3077
3078 for( int j = 0; j < polySet.HoleCount( i ); ++j )
3079 {
3080 wxASSERT( polySet.Hole( i, j ).PointCount() > 2 );
3081 }
3082 }
3083#endif
3084
3085 return polySet;
3086}
3087
3088
3090{
3091 SHAPE_LINE_CHAIN lineChain;
3092
3093 for( PCB_SHAPE* shape : aShapes )
3094 {
3095 switch( shape->GetShape() )
3096 {
3097 case SHAPE_T::ARC:
3098 {
3099 SHAPE_ARC arc( shape->GetCenter(), shape->GetStart(), shape->GetArcAngle() );
3100
3101 if( shape->EndsSwapped() )
3102 arc.Reverse();
3103
3104 lineChain.Append( arc );
3105 break;
3106 }
3107
3108 case SHAPE_T::SEGMENT:
3109 lineChain.Append( shape->GetStartX(), shape->GetStartY() );
3110 lineChain.Append( shape->GetEndX(), shape->GetEndY() );
3111 break;
3112
3113 default:
3114 wxFAIL_MSG( wxT( "Drawsegment type is unexpected. Ignored." ) );
3115 }
3116 }
3117
3118 // Shouldn't have less than 3 points to make a closed shape!
3119 wxASSERT( lineChain.PointCount() > 2 );
3120
3121 // Check if it is closed
3122 if( lineChain.GetPoint( 0 ) != lineChain.GetPoint( lineChain.PointCount() - 1 ) )
3123 {
3124 lineChain.Append( lineChain.GetPoint( 0 ) );
3125 }
3126
3127 lineChain.SetClosed( true );
3128
3129 return lineChain;
3130}
3131
3132
3134 const std::vector<PCB_SHAPE*>& aShapes,
3135 BOARD_ITEM_CONTAINER* aParentContainer,
3136 NETINFO_ITEM* aNet, PCB_LAYER_ID aLayerOverride,
3137 int aWidthOverride )
3138{
3139 std::vector<PCB_TRACK*> tracks;
3140 PCB_TRACK* prevTrack = nullptr;
3141 PCB_TRACK* track = nullptr;
3142
3143 auto addTrack =
3144 [&]( PCB_TRACK* aTrack )
3145 {
3146 // Ignore zero length tracks in the same way as the CADSTAR postprocessor does
3147 // when generating gerbers. Note that CADSTAR reports these as "Route offset
3148 // errors" when running a DRC within CADSTAR, so we shouldn't be getting this in
3149 // general, however it is used to remove any synthetic points added to
3150 // aDrawSegments by the caller of this function.
3151 if( aTrack->GetLength() != 0 )
3152 {
3153 tracks.push_back( aTrack );
3154 aParentContainer->Add( aTrack, ADD_MODE::APPEND );
3155 }
3156 else
3157 {
3158 delete aTrack;
3159 }
3160 };
3161
3162 for( PCB_SHAPE* shape : aShapes )
3163 {
3164 switch( shape->GetShape() )
3165 {
3166 case SHAPE_T::ARC:
3167 {
3168 SHAPE_ARC arc( shape->GetStart(), shape->GetArcMid(), shape->GetEnd(), 0 );
3169
3170 if( shape->EndsSwapped() )
3171 arc.Reverse();
3172
3173 track = new PCB_ARC( aParentContainer, &arc );
3174 break;
3175 }
3176
3177 case SHAPE_T::SEGMENT:
3178 track = new PCB_TRACK( aParentContainer );
3179 track->SetStart( shape->GetStart() );
3180 track->SetEnd( shape->GetEnd() );
3181 break;
3182
3183 default:
3184 wxFAIL_MSG( wxT( "Drawsegment type is unexpected. Ignored." ) );
3185 continue;
3186 }
3187
3188 if( aWidthOverride == -1 )
3189 track->SetWidth( shape->GetWidth() );
3190 else
3191 track->SetWidth( aWidthOverride );
3192
3193 if( aLayerOverride == PCB_LAYER_ID::UNDEFINED_LAYER )
3194 track->SetLayer( shape->GetLayer() );
3195 else
3196 track->SetLayer( aLayerOverride );
3197
3198 if( aNet != nullptr )
3199 track->SetNet( aNet );
3200 else
3201 track->SetNetCode( -1 );
3202
3203 track->SetLocked( shape->IsLocked() );
3204
3205 // Apply route offsetting, mimmicking the behaviour of the CADSTAR post processor
3206 if( prevTrack != nullptr )
3207 {
3208 int offsetAmount = ( track->GetWidth() / 2 ) - ( prevTrack->GetWidth() / 2 );
3209
3210 if( offsetAmount > 0 )
3211 {
3212 // modify the start of the current track
3213 VECTOR2I newStart = track->GetStart();
3214 applyRouteOffset( &newStart, track->GetEnd(), offsetAmount );
3215 track->SetStart( newStart );
3216 }
3217 else if( offsetAmount < 0 )
3218 {
3219 // amend the end of the previous track
3220 VECTOR2I newEnd = prevTrack->GetEnd();
3221 applyRouteOffset( &newEnd, prevTrack->GetStart(), -offsetAmount );
3222 prevTrack->SetEnd( newEnd );
3223 } // don't do anything if offsetAmount == 0
3224
3225 // Add a synthetic track of the thinnest width between the tracks
3226 // to ensure KiCad features works as expected on the imported design
3227 // (KiCad expects tracks are contiguous segments)
3228 if( track->GetStart() != prevTrack->GetEnd() )
3229 {
3230 int minWidth = std::min( track->GetWidth(), prevTrack->GetWidth() );
3231 PCB_TRACK* synthTrack = new PCB_TRACK( aParentContainer );
3232 synthTrack->SetStart( prevTrack->GetEnd() );
3233 synthTrack->SetEnd( track->GetStart() );
3234 synthTrack->SetWidth( minWidth );
3235 synthTrack->SetLocked( track->IsLocked() );
3236 synthTrack->SetNet( track->GetNet() );
3237 synthTrack->SetLayer( track->GetLayer() );
3238 addTrack( synthTrack );
3239 }
3240 }
3241
3242 if( prevTrack )
3243 addTrack( prevTrack );
3244
3245 prevTrack = track;
3246 }
3247
3248 if( track )
3249 addTrack( track );
3250
3251 return tracks;
3252}
3253
3254
3256 const ATTRIBUTE_ID& aCadstarAttributeID,
3257 FOOTPRINT* aFootprint,
3258 const wxString& aAttributeValue )
3259{
3260 PCB_TEXT* txt;
3261
3262 if( aCadstarAttributeID == COMPONENT_NAME_ATTRID )
3263 {
3264 txt = &aFootprint->Reference(); //text should be set outside this function
3265 }
3266 else if( aCadstarAttributeID == PART_NAME_ATTRID )
3267 {
3268 if( aFootprint->Value().GetText().IsEmpty() )
3269 {
3270 // Use PART_NAME_ATTRID as the value is value field is blank
3271 aFootprint->SetValue( aAttributeValue );
3272 txt = &aFootprint->Value();
3273 }
3274 else
3275 {
3276 txt = new PCB_TEXT( aFootprint );
3277 aFootprint->Add( txt );
3278 txt->SetText( aAttributeValue );
3279 }
3280 txt->SetVisible( false ); //make invisible to avoid clutter.
3281 }
3282 else if( aCadstarAttributeID != COMPONENT_NAME_2_ATTRID
3283 && getAttributeName( aCadstarAttributeID ) == wxT( "Value" ) )
3284 {
3285 if( !aFootprint->Value().GetText().IsEmpty() )
3286 {
3287 //copy the object
3288 aFootprint->Add( aFootprint->Value().Duplicate() );
3289 }
3290
3291 aFootprint->SetValue( aAttributeValue );
3292 txt = &aFootprint->Value();
3293 txt->SetVisible( false ); //make invisible to avoid clutter.
3294 }
3295 else
3296 {
3297 txt = new PCB_TEXT( aFootprint );
3298 aFootprint->Add( txt );
3299 txt->SetText( aAttributeValue );
3300 txt->SetVisible( false ); //make all user attributes invisible to avoid clutter.
3301 //TODO: Future improvement - allow user to decide what to do with attributes
3302 }
3303
3304 txt->SetPosition( getKiCadPoint( aCadstarAttrLoc.Position ) );
3305 txt->SetLayer( getKiCadLayer( aCadstarAttrLoc.LayerID ) );
3306 txt->SetMirrored( aCadstarAttrLoc.Mirror );
3307 txt->SetTextAngle( getAngle( aCadstarAttrLoc.OrientAngle ) );
3308
3309 if( aCadstarAttrLoc.Mirror ) // If mirroring, invert angle to match CADSTAR
3310 txt->SetTextAngle( -txt->GetTextAngle() );
3311
3312 applyTextCode( txt, aCadstarAttrLoc.TextCodeID );
3313
3314 txt->SetKeepUpright( false ); //Keeping it upright seems to result in incorrect orientation
3315
3316 switch( aCadstarAttrLoc.Alignment )
3317 {
3318 case ALIGNMENT::NO_ALIGNMENT: // Default for Single line text is Bottom Left
3324 break;
3325
3329 break;
3330
3334 break;
3335
3339 break;
3340
3344 break;
3345
3349 break;
3350
3351 case ALIGNMENT::TOPLEFT:
3354 break;
3355
3359 break;
3360
3364 break;
3365
3366 default:
3367 wxFAIL_MSG( wxT( "Unknown Alignment - needs review!" ) );
3368 }
3369
3370 //TODO Handle different font types when KiCad can support it.
3371}
3372
3373
3375 const VECTOR2I& aRefPoint,
3376 const long& aOffsetAmount )
3377{
3378 VECTOR2I v( *aPointToOffset - aRefPoint );
3379 int newLength = v.EuclideanNorm() - aOffsetAmount;
3380
3381 if( newLength > 0 )
3382 {
3383 VECTOR2I offsetted = v.Resize( newLength ) + VECTOR2I( aRefPoint );
3384 aPointToOffset->x = offsetted.x;
3385 aPointToOffset->y = offsetted.y;
3386 }
3387 else
3388 {
3389 *aPointToOffset = aRefPoint; // zero length track. Needs to be removed to mimmick
3390 // cadstar behaviour
3391 }
3392}
3393
3394
3396 const TEXTCODE_ID& aCadstarTextCodeID )
3397{
3398 TEXTCODE tc = getTextCode( aCadstarTextCodeID );
3399
3400 aKiCadText->SetTextThickness( getKiCadLength( tc.LineWidth ) );
3401
3402 VECTOR2I textSize;
3403 textSize.x = getKiCadLength( tc.Width );
3404
3405 // The width is zero for all non-cadstar fonts. Using a width equal to the height seems
3406 // to work well for most fonts.
3407 if( textSize.x == 0 )
3408 textSize.x = getKiCadLength( tc.Height );
3409
3410 textSize.y = KiROUND( TXT_HEIGHT_RATIO * (double) getKiCadLength( tc.Height ) );
3411
3412 if( textSize.x == 0 || textSize.y == 0 )
3413 {
3414 // Make zero sized text not visible
3415
3416 aKiCadText->SetTextSize(
3419
3420 aKiCadText->SetVisible( false );
3421 }
3422 else
3423 {
3424 aKiCadText->SetTextSize( textSize );
3425 }
3426}
3427
3428
3430{
3431 wxCHECK( Assignments.Codedefs.LineCodes.find( aCadstarLineCodeID )
3433 m_board->GetDesignSettings().GetLineThickness( PCB_LAYER_ID::Edge_Cuts ) );
3434
3435 return getKiCadLength( Assignments.Codedefs.LineCodes.at( aCadstarLineCodeID ).Width );
3436}
3437
3438
3440 const COPPERCODE_ID& aCadstaCopperCodeID )
3441{
3442 wxCHECK( Assignments.Codedefs.CopperCodes.find( aCadstaCopperCodeID )
3444 COPPERCODE() );
3445
3446 return Assignments.Codedefs.CopperCodes.at( aCadstaCopperCodeID );
3447}
3448
3449
3451 const TEXTCODE_ID& aCadstarTextCodeID )
3452{
3453 wxCHECK( Assignments.Codedefs.TextCodes.find( aCadstarTextCodeID )
3455 TEXTCODE() );
3456
3457 return Assignments.Codedefs.TextCodes.at( aCadstarTextCodeID );
3458}
3459
3460
3462 const PADCODE_ID& aCadstarPadCodeID )
3463{
3464 wxCHECK( Assignments.Codedefs.PadCodes.find( aCadstarPadCodeID )
3465 != Assignments.Codedefs.PadCodes.end(),
3466 PADCODE() );
3467
3468 return Assignments.Codedefs.PadCodes.at( aCadstarPadCodeID );
3469}
3470
3471
3473 const VIACODE_ID& aCadstarViaCodeID )
3474{
3475 wxCHECK( Assignments.Codedefs.ViaCodes.find( aCadstarViaCodeID )
3476 != Assignments.Codedefs.ViaCodes.end(),
3477 VIACODE() );
3478
3479 return Assignments.Codedefs.ViaCodes.at( aCadstarViaCodeID );
3480}
3481
3482
3484 const LAYERPAIR_ID& aCadstarLayerPairID )
3485{
3486 wxCHECK( Assignments.Codedefs.LayerPairs.find( aCadstarLayerPairID )
3488 LAYERPAIR() );
3489
3490 return Assignments.Codedefs.LayerPairs.at( aCadstarLayerPairID );
3491}
3492
3493
3495{
3496 wxCHECK( Assignments.Codedefs.AttributeNames.find( aCadstarAttributeID )
3498 wxEmptyString );
3499
3500 return Assignments.Codedefs.AttributeNames.at( aCadstarAttributeID ).Name;
3501}
3502
3503
3505 const std::map<ATTRIBUTE_ID, ATTRIBUTE_VALUE>& aCadstarAttributeMap )
3506{
3507 wxCHECK( aCadstarAttributeMap.find( aCadstarAttributeID ) != aCadstarAttributeMap.end(),
3508 wxEmptyString );
3509
3510 return aCadstarAttributeMap.at( aCadstarAttributeID ).Value;
3511}
3512
3513
3516{
3517 if( Assignments.Layerdefs.Layers.find( aCadstarLayerID ) != Assignments.Layerdefs.Layers.end() )
3518 {
3519 return Assignments.Layerdefs.Layers.at( aCadstarLayerID ).Type;
3520 }
3521
3522 return LAYER_TYPE::UNDEFINED;
3523}
3524
3525
3527 const PART_ID& aCadstarPartID )
3528{
3529 wxCHECK( Parts.PartDefinitions.find( aCadstarPartID ) != Parts.PartDefinitions.end(), PART() );
3530
3531 return Parts.PartDefinitions.at( aCadstarPartID );
3532}
3533
3534
3536 const ROUTECODE_ID& aCadstarRouteCodeID )
3537{
3538 wxCHECK( Assignments.Codedefs.RouteCodes.find( aCadstarRouteCodeID )
3540 ROUTECODE() );
3541
3542 return Assignments.Codedefs.RouteCodes.at( aCadstarRouteCodeID );
3543}
3544
3545
3547 const HATCHCODE_ID& aCadstarHatchcodeID )
3548{
3549 wxCHECK( Assignments.Codedefs.HatchCodes.find( aCadstarHatchcodeID )
3551 HATCHCODE() );
3552
3553 return Assignments.Codedefs.HatchCodes.at( aCadstarHatchcodeID );
3554}
3555
3556
3558{
3559 checkAndLogHatchCode( aCadstarHatchcodeID );
3560 HATCHCODE hcode = getHatchCode( aCadstarHatchcodeID );
3561
3562 if( hcode.Hatches.size() < 1 )
3564 else
3565 return getAngle( hcode.Hatches.at( 0 ).OrientAngle );
3566}
3567
3568
3570 const HATCHCODE_ID& aCadstarHatchcodeID )
3571{
3572 checkAndLogHatchCode( aCadstarHatchcodeID );
3573 HATCHCODE hcode = getHatchCode( aCadstarHatchcodeID );
3574
3575 if( hcode.Hatches.size() < 1 )
3577 else
3578 return getKiCadLength( hcode.Hatches.at( 0 ).LineWidth );
3579}
3580
3581
3583{
3584 checkAndLogHatchCode( aCadstarHatchcodeID );
3585 HATCHCODE hcode = getHatchCode( aCadstarHatchcodeID );
3586
3587 if( hcode.Hatches.size() < 1 )
3589 else
3590 return getKiCadLength( hcode.Hatches.at( 0 ).Step );
3591}
3592
3593
3595{
3596 wxCHECK( m_groupMap.find( aCadstarGroupID ) != m_groupMap.end(), nullptr );
3597
3598 return m_groupMap.at( aCadstarGroupID );
3599}
3600
3601
3603{
3604 if( m_hatchcodesTested.find( aCadstarHatchcodeID ) != m_hatchcodesTested.end() )
3605 {
3606 return; //already checked
3607 }
3608 else
3609 {
3610 HATCHCODE hcode = getHatchCode( aCadstarHatchcodeID );
3611
3612 if( hcode.Hatches.size() != 2 )
3613 {
3614 wxLogWarning( wxString::Format(
3615 _( "The CADSTAR Hatching code '%s' has %d hatches defined. "
3616 "KiCad only supports 2 hatches (crosshatching) 90 degrees apart. "
3617 "The imported hatching is crosshatched." ),
3618 hcode.Name, (int) hcode.Hatches.size() ) );
3619 }
3620 else
3621 {
3622 if( hcode.Hatches.at( 0 ).LineWidth != hcode.Hatches.at( 1 ).LineWidth )
3623 {
3624 wxLogWarning( wxString::Format(
3625 _( "The CADSTAR Hatching code '%s' has different line widths for each "
3626 "hatch. KiCad only supports one width for the hatching. The imported "
3627 "hatching uses the width defined in the first hatch definition, i.e. "
3628 "%.2f mm." ),
3629 hcode.Name,
3630 (double) ( (double) getKiCadLength( hcode.Hatches.at( 0 ).LineWidth ) )
3631 / 1E6 ) );
3632 }
3633
3634 if( hcode.Hatches.at( 0 ).Step != hcode.Hatches.at( 1 ).Step )
3635 {
3636 wxLogWarning( wxString::Format(
3637 _( "The CADSTAR Hatching code '%s' has different step sizes for each "
3638 "hatch. KiCad only supports one step size for the hatching. The imported "
3639 "hatching uses the step size defined in the first hatching definition, "
3640 "i.e. %.2f mm." ),
3641 hcode.Name,
3642 (double) ( (double) getKiCadLength( hcode.Hatches.at( 0 ).Step ) )
3643 / 1E6 ) );
3644 }
3645
3646 if( abs( hcode.Hatches.at( 0 ).OrientAngle - hcode.Hatches.at( 1 ).OrientAngle )
3647 != 90000 )
3648 {
3649 wxLogWarning( wxString::Format(
3650 _( "The hatches in CADSTAR Hatching code '%s' have an angle "
3651 "difference of %.1f degrees. KiCad only supports hatching 90 "
3652 "degrees apart. The imported hatching has two hatches 90 "
3653 "degrees apart, oriented %.1f degrees from horizontal." ),
3654 hcode.Name,
3655 getAngle( abs( hcode.Hatches.at( 0 ).OrientAngle
3656 - hcode.Hatches.at( 1 ).OrientAngle ) ).AsDegrees(),
3657 getAngle( hcode.Hatches.at( 0 ).OrientAngle ).AsDegrees() ) );
3658 }
3659 }
3660
3661 m_hatchcodesTested.insert( aCadstarHatchcodeID );
3662 }
3663}
3664
3665
3667 PCB_DIMENSION_BASE* aKiCadDim )
3668{
3669 UNITS dimensionUnits = aCadstarDim.LinearUnits;
3670 LINECODE linecode = Assignments.Codedefs.LineCodes.at( aCadstarDim.Line.LineCodeID );
3671
3672 aKiCadDim->SetLayer( getKiCadLayer( aCadstarDim.LayerID ) );
3673 aKiCadDim->SetPrecision( static_cast<DIM_PRECISION>( aCadstarDim.Precision ) );
3674 aKiCadDim->SetStart( getKiCadPoint( aCadstarDim.ExtensionLineParams.Start ) );
3675 aKiCadDim->SetEnd( getKiCadPoint( aCadstarDim.ExtensionLineParams.End ) );
3676 aKiCadDim->SetExtensionOffset( getKiCadLength( aCadstarDim.ExtensionLineParams.Offset ) );
3677 aKiCadDim->SetLineThickness( getKiCadLength( linecode.Width ) );
3678
3679 applyTextCode( aKiCadDim, aCadstarDim.Text.TextCodeID );
3680
3681 // Find prefix and suffix:
3682 wxString prefix = wxEmptyString;
3683 wxString suffix = wxEmptyString;
3684 size_t startpos = aCadstarDim.Text.Text.Find( wxT( "<@DISTANCE" ) );
3685
3686 if( startpos != wxNOT_FOUND )
3687 {
3688 prefix = ParseTextFields( aCadstarDim.Text.Text.SubString( 0, startpos - 1 ), &m_context );
3689 wxString remainingStr = aCadstarDim.Text.Text.Mid( startpos );
3690 size_t endpos = remainingStr.Find( "@>" );
3691 suffix = ParseTextFields( remainingStr.Mid( endpos + 2 ), &m_context );
3692 }
3693
3694 if( suffix.StartsWith( wxT( "mm" ) ) )
3695 {
3696 aKiCadDim->SetUnitsFormat( DIM_UNITS_FORMAT::BARE_SUFFIX );
3697 suffix = suffix.Mid( 2 );
3698 }
3699 else
3700 {
3701 aKiCadDim->SetUnitsFormat( DIM_UNITS_FORMAT::NO_SUFFIX );
3702 }
3703
3704 aKiCadDim->SetPrefix( prefix );
3705 aKiCadDim->SetSuffix( suffix );
3706
3707 if( aCadstarDim.LinearUnits == UNITS::DESIGN )
3708 {
3709 // For now we will hardcode the units as per the original CADSTAR design.
3710 // TODO: update this when KiCad supports design units
3712 dimensionUnits = Assignments.Technology.Units;
3713 }
3714
3715 switch( dimensionUnits )
3716 {
3717 case UNITS::METER:
3718 case UNITS::CENTIMETER:
3719 case UNITS::MICROMETRE:
3720 wxLogWarning( wxString::Format( _( "Dimension ID %s uses a type of unit that "
3721 "is not supported in KiCad. Millimeters were "
3722 "applied instead." ),
3723 aCadstarDim.ID ) );
3725 case UNITS::MM:
3726 aKiCadDim->SetUnitsMode( DIM_UNITS_MODE::MILLIMETRES );
3727 break;
3728
3729 case UNITS::INCH:
3730 aKiCadDim->SetUnitsMode( DIM_UNITS_MODE::INCHES );
3731 break;
3732
3733 case UNITS::THOU:
3734 aKiCadDim->SetUnitsMode( DIM_UNITS_MODE::MILS );
3735 break;
3736
3737 case UNITS::DESIGN:
3738 wxFAIL_MSG( wxT( "We should have handled design units before coming here!" ) );
3739 break;
3740 }
3741}
3742
3744{
3745 std::map<TEMPLATE_ID, std::set<TEMPLATE_ID>> winningOverlaps;
3746
3747 auto inflateValue =
3748 [&]( ZONE* aZoneA, ZONE* aZoneB )
3749 {
3750 int extra = getKiCadLength( Assignments.Codedefs.SpacingCodes.at( wxT( "C_C" ) ).Spacing )
3752
3753 int retval = std::max( aZoneA->GetLocalClearance().value(),
3754 aZoneB->GetLocalClearance().value() );
3755
3756 retval += extra;
3757
3758 return retval;
3759 };
3760
3761 // Find the error in fill area when guessing that aHigherZone gets filled before aLowerZone
3762 auto errorArea =
3763 [&]( ZONE* aLowerZone, ZONE* aHigherZone ) -> double
3764 {
3765 SHAPE_POLY_SET intersectShape( *aHigherZone->Outline() );
3766 intersectShape.Inflate( inflateValue( aLowerZone, aHigherZone ),
3767 CORNER_STRATEGY::ROUND_ALL_CORNERS, ARC_HIGH_DEF );
3768
3769 SHAPE_POLY_SET lowerZoneFill( *aLowerZone->GetFilledPolysList( aLayer ) );
3770 SHAPE_POLY_SET lowerZoneOutline( *aLowerZone->Outline() );
3771
3772 lowerZoneOutline.BooleanSubtract( intersectShape );
3773
3774 lowerZoneFill.BooleanSubtract( lowerZoneOutline );
3775
3776 double leftOverArea = lowerZoneFill.Area();
3777
3778 return leftOverArea;
3779 };
3780
3781 auto intersectionAreaOfZoneOutlines =
3782 [&]( ZONE* aZoneA, ZONE* aZoneB ) -> double
3783 {
3784 SHAPE_POLY_SET outLineA( *aZoneA->Outline() );
3785 outLineA.Inflate( inflateValue( aZoneA, aZoneB ), CORNER_STRATEGY::ROUND_ALL_CORNERS,
3786 ARC_HIGH_DEF );
3787
3788 SHAPE_POLY_SET outLineB( *aZoneA->Outline() );
3789 outLineB.Inflate( inflateValue( aZoneA, aZoneB ), CORNER_STRATEGY::ROUND_ALL_CORNERS,
3790 ARC_HIGH_DEF );
3791
3792 outLineA.BooleanIntersection( outLineB );
3793
3794 return outLineA.Area();
3795 };
3796
3797 // Lambda to determine if the zone with template ID 'a' is lower priority than 'b'
3798 auto isLowerPriority =
3799 [&]( const TEMPLATE_ID& a, const TEMPLATE_ID& b ) -> bool
3800 {
3801 return winningOverlaps[b].count( a ) > 0;
3802 };
3803
3804 for( std::map<TEMPLATE_ID, ZONE*>::iterator it1 = m_zonesMap.begin();
3805 it1 != m_zonesMap.end(); ++it1 )
3806 {
3807 TEMPLATE& thisTemplate = Layout.Templates.at( it1->first );
3808 ZONE* thisZone = it1->second;
3809
3810 if( !thisZone->GetLayerSet().Contains( aLayer ) )
3811 continue;
3812
3813 for( std::map<TEMPLATE_ID, ZONE*>::iterator it2 = it1;
3814 it2 != m_zonesMap.end(); ++it2 )
3815 {
3816 TEMPLATE& otherTemplate = Layout.Templates.at( it2->first );
3817 ZONE* otherZone = it2->second;
3818
3819 if( thisTemplate.ID == otherTemplate.ID )
3820 continue;
3821
3822 if( !otherZone->GetLayerSet().Contains( aLayer ) )
3823 {
3824 checkPoint();
3825 continue;
3826 }
3827
3828 if( intersectionAreaOfZoneOutlines( thisZone, otherZone ) == 0 )
3829 {
3830 checkPoint();
3831 continue; // The zones do not interact in any way
3832 }
3833
3834 SHAPE_POLY_SET thisZonePolyFill = *thisZone->GetFilledPolysList( aLayer );
3835 SHAPE_POLY_SET otherZonePolyFill = *otherZone->GetFilledPolysList( aLayer );
3836
3837 if( thisZonePolyFill.Area() > 0.0 && otherZonePolyFill.Area() > 0.0 )
3838 {
3839 // Test if this zone were lower priority than other zone, what is the error?
3840 double areaThis = errorArea( thisZone, otherZone );
3841 // Vice-versa
3842 double areaOther = errorArea( otherZone, thisZone );
3843
3844 if( areaThis > areaOther )
3845 {
3846 // thisTemplate is filled before otherTemplate
3847 winningOverlaps[thisTemplate.ID].insert( otherTemplate.ID );
3848 }
3849 else
3850 {
3851 // thisTemplate is filled AFTER otherTemplate
3852 winningOverlaps[otherTemplate.ID].insert( thisTemplate.ID );
3853 }
3854 }
3855 else if( thisZonePolyFill.Area() > 0.0 )
3856 {
3857 // The other template is not filled, this one wins
3858 winningOverlaps[thisTemplate.ID].insert( otherTemplate.ID );
3859 }
3860 else if( otherZonePolyFill.Area() > 0.0 )
3861 {
3862 // This template is not filled, the other one wins
3863 winningOverlaps[otherTemplate.ID].insert( thisTemplate.ID );
3864 }
3865 else
3866 {
3867 // Neither of the templates is poured - use zone outlines instead (bigger outlines
3868 // get a lower priority)
3869 if( intersectionAreaOfZoneOutlines( thisZone, otherZone ) != 0 )
3870 {
3871 if( thisZone->Outline()->Area() > otherZone->Outline()->Area() )
3872 winningOverlaps[otherTemplate.ID].insert( thisTemplate.ID );
3873 else
3874 winningOverlaps[thisTemplate.ID].insert( otherTemplate.ID );
3875 }
3876 }
3877
3878 checkPoint();
3879 }
3880 }
3881
3882 // Build a set of unique TEMPLATE_IDs of all the zones that intersect with another one
3883 std::set<TEMPLATE_ID> intersectingIDs;
3884
3885 for( const std::pair<TEMPLATE_ID, std::set<TEMPLATE_ID>>& idPair : winningOverlaps )
3886 {
3887 intersectingIDs.insert( idPair.first );
3888 intersectingIDs.insert( idPair.second.begin(), idPair.second.end() );
3889 }
3890
3891 // Now store them in a vector
3892 std::vector<TEMPLATE_ID> sortedIDs;
3893
3894 for( const TEMPLATE_ID& id : intersectingIDs )
3895 {
3896 sortedIDs.push_back( id );
3897 }
3898
3899 // sort by priority
3900 std::sort( sortedIDs.begin(), sortedIDs.end(), isLowerPriority );
3901
3902 TEMPLATE_ID prevID = wxEmptyString;
3903
3904 for( const TEMPLATE_ID& id : sortedIDs )
3905 {
3906 if( prevID.IsEmpty() )
3907 {
3908 prevID = id;
3909 continue;
3910 }
3911
3912 wxASSERT( !isLowerPriority( id, prevID ) );
3913
3914 int newPriority = m_zonesMap.at( prevID )->GetAssignedPriority();
3915
3916 // Only increase priority of the current zone
3917 if( isLowerPriority( prevID, id ) )
3918 newPriority++;
3919
3920 m_zonesMap.at( id )->SetAssignedPriority( newPriority );
3921 prevID = id;
3922 }
3923
3924 // Verify
3925 for( const std::pair<TEMPLATE_ID, std::set<TEMPLATE_ID>>& idPair : winningOverlaps )
3926 {
3927 const TEMPLATE_ID& winningID = idPair.first;
3928
3929 for( const TEMPLATE_ID& losingID : idPair.second )
3930 {
3931 if( m_zonesMap.at( losingID )->GetAssignedPriority()
3932 > m_zonesMap.at( winningID )->GetAssignedPriority() )
3933 {
3934 return false;
3935 }
3936 }
3937 }
3938
3939 return true;
3940}
3941
3942
3944 const COMPONENT_ID& aCadstarComponentID )
3945{
3946 if( m_componentMap.find( aCadstarComponentID ) == m_componentMap.end() )
3947 return nullptr;
3948 else
3949 return m_componentMap.at( aCadstarComponentID );
3950}
3951
3952
3954{
3955 VECTOR2I retval;
3956
3957 retval.x = ( aCadstarPoint.x - m_designCenter.x ) * KiCadUnitMultiplier;
3958 retval.y = -( aCadstarPoint.y - m_designCenter.y ) * KiCadUnitMultiplier;
3959
3960 return retval;
3961}
3962
3963
3965{
3966 if( aCadstarNetID.IsEmpty() )
3967 {
3968 return nullptr;
3969 }
3970 else if( m_netMap.find( aCadstarNetID ) != m_netMap.end() )
3971 {
3972 return m_netMap.at( aCadstarNetID );
3973 }
3974 else
3975 {
3976 wxCHECK( Layout.Nets.find( aCadstarNetID ) != Layout.Nets.end(), nullptr );
3977
3978 NET_PCB csNet = Layout.Nets.at( aCadstarNetID );
3979 wxString newName = csNet.Name;
3980
3981 if( csNet.Name.IsEmpty() )
3982 {
3983 if( csNet.Pins.size() > 0 )
3984 {
3985 // Create default KiCad net naming:
3986
3987 NET_PCB::PIN firstPin = ( *csNet.Pins.begin() ).second;
3988 //we should have already loaded the component with loadComponents() :
3989 FOOTPRINT* m = getFootprintFromCadstarID( firstPin.ComponentID );
3990 newName = wxT( "Net-(" );
3991 newName << m->Reference().GetText();
3992 newName << wxT( "-Pad" ) << wxString::Format( wxT( "%ld" ), firstPin.PadID );
3993 newName << wxT( ")" );
3994 }
3995 else
3996 {
3997 wxFAIL_MSG( wxT( "A net with no pins associated?" ) );
3998 newName = wxT( "csNet-" );
3999 newName << wxString::Format( wxT( "%i" ), csNet.SignalNum );
4000 }
4001 }
4002
4003 if( !m_doneNetClassWarning && !csNet.NetClassID.IsEmpty()
4004 && csNet.NetClassID != wxT( "NONE" ) )
4005 {
4006 wxLogMessage( _( "The CADSTAR design contains nets with a 'Net Class' assigned. KiCad "
4007 "does not have an equivalent to CADSTAR's Net Class so these elements "
4008 "were not imported. Note: KiCad's version of 'Net Class' is closer to "
4009 "CADSTAR's 'Net Route Code' (which has been imported for all nets)." ) );
4010 m_doneNetClassWarning = true;
4011 }
4012
4013 if( !m_doneSpacingClassWarning && !csNet.SpacingClassID.IsEmpty()
4014 && csNet.SpacingClassID != wxT( "NONE" ) )
4015 {
4016 wxLogWarning( _( "The CADSTAR design contains nets with a 'Spacing Class' assigned. "
4017 "KiCad does not have an equivalent to CADSTAR's Spacing Class so "
4018 "these elements were not imported. Please review the design rules as "
4019 "copper pours will affected by this." ) );
4021 }
4022
4023 std::shared_ptr<NET_SETTINGS>& netSettings = m_board->GetDesignSettings().m_NetSettings;
4024 NETINFO_ITEM* netInfo = new NETINFO_ITEM( m_board, newName, ++m_numNets );
4025 std::shared_ptr<NETCLASS> netclass;
4026
4027 std::tuple<ROUTECODE_ID, NETCLASS_ID, SPACING_CLASS_ID> key = { csNet.RouteCodeID,
4028 csNet.NetClassID,
4029 csNet.SpacingClassID };
4030
4031 if( m_netClassMap.find( key ) != m_netClassMap.end() )
4032 {
4033 netclass = m_netClassMap.at( key );
4034 }
4035 else
4036 {
4037 wxString netClassName;
4038
4039 ROUTECODE rc = getRouteCode( csNet.RouteCodeID );
4040 netClassName += wxT( "Route code: " ) + rc.Name;
4041
4042 if( !csNet.NetClassID.IsEmpty() )
4043 {
4045 netClassName += wxT( " | Net class: " ) + nc.Name;
4046 }
4047
4048 if( !csNet.SpacingClassID.IsEmpty() )
4049 {
4051 netClassName += wxT( " | Spacing class: " ) + sp.Name;
4052 }
4053
4054 netclass.reset( new NETCLASS( *netSettings->GetDefaultNetclass() ) );
4055 netclass->SetName( netClassName );
4056 netSettings->SetNetclass( netClassName, netclass );
4057 netclass->SetTrackWidth( getKiCadLength( rc.OptimalWidth ) );
4058 m_netClassMap.insert( { key, netclass } );
4059 }
4060
4061 m_board->GetDesignSettings().m_NetSettings->SetNetclassPatternAssignment(
4062 newName, netclass->GetName() );
4063
4064 netInfo->SetNetClass( netclass );
4065 m_board->Add( netInfo, ADD_MODE::APPEND );
4066 m_netMap.insert( { aCadstarNetID, netInfo } );
4067 return netInfo;
4068 }
4069
4070 return nullptr;
4071}
4072
4073
4075 bool aDetectMaxLayer )
4076{
4077 if( aDetectMaxLayer && aLayerNum == m_numCopperLayers )
4078 return PCB_LAYER_ID::B_Cu;
4079
4080 switch( aLayerNum )
4081 {
4082 case 1: return PCB_LAYER_ID::F_Cu;
4083 case 2: return PCB_LAYER_ID::In1_Cu;
4084 case 3: return PCB_LAYER_ID::In2_Cu;
4085 case 4: return PCB_LAYER_ID::In3_Cu;
4086 case 5: return PCB_LAYER_ID::In4_Cu;
4087 case 6: return PCB_LAYER_ID::In5_Cu;
4088 case 7: return PCB_LAYER_ID::In6_Cu;
4089 case 8: return PCB_LAYER_ID::In7_Cu;
4090 case 9: return PCB_LAYER_ID::In8_Cu;
4091 case 10: return PCB_LAYER_ID::In9_Cu;
4092 case 11: return PCB_LAYER_ID::In10_Cu;
4093 case 12: return PCB_LAYER_ID::In11_Cu;
4094 case 13: return PCB_LAYER_ID::In12_Cu;
4095 case 14: return PCB_LAYER_ID::In13_Cu;
4096 case 15: return PCB_LAYER_ID::In14_Cu;
4097 case 16: return PCB_LAYER_ID::In15_Cu;
4098 case 17: return PCB_LAYER_ID::In16_Cu;
4099 case 18: return PCB_LAYER_ID::In17_Cu;
4100 case 19: return PCB_LAYER_ID::In18_Cu;
4101 case 20: return PCB_LAYER_ID::In19_Cu;
4102 case 21: return PCB_LAYER_ID::In20_Cu;
4103 case 22: return PCB_LAYER_ID::In21_Cu;
4104 case 23: return PCB_LAYER_ID::In22_Cu;
4105 case 24: return PCB_LAYER_ID::In23_Cu;
4106 case 25: return PCB_LAYER_ID::In24_Cu;
4107 case 26: return PCB_LAYER_ID::In25_Cu;
4108 case 27: return PCB_LAYER_ID::In26_Cu;
4109 case 28: return PCB_LAYER_ID::In27_Cu;
4110 case 29: return PCB_LAYER_ID::In28_Cu;
4111 case 30: return PCB_LAYER_ID::In29_Cu;
4112 case 31: return PCB_LAYER_ID::In30_Cu;
4113 case 32: return PCB_LAYER_ID::B_Cu;
4114 }
4115
4116 return PCB_LAYER_ID::UNDEFINED_LAYER;
4117}
4118
4119
4121{
4122 wxCHECK( Assignments.Layerdefs.Layers.find( aCadstarLayerID )
4123 != Assignments.Layerdefs.Layers.end(),
4124 false );
4125
4126 LAYER& layer = Assignments.Layerdefs.Layers.at( aCadstarLayerID );
4127
4128 switch( layer.Type )
4129 {
4130 case LAYER_TYPE::ALLDOC:
4133 return true;
4134
4135 default:
4136 return false;
4137 }
4138
4139 return false;
4140}
4141
4142
4144{
4145 if( getLayerType( aCadstarLayerID ) == LAYER_TYPE::NOLAYER )
4146 {
4147 //The "no layer" is common for CADSTAR documentation symbols
4148 //map it to undefined layer for later processing
4149 return PCB_LAYER_ID::UNDEFINED_LAYER;
4150 }
4151
4152 wxCHECK( m_layermap.find( aCadstarLayerID ) != m_layermap.end(),
4153 PCB_LAYER_ID::UNDEFINED_LAYER );
4154
4155 return m_layermap.at( aCadstarLayerID );
4156}
4157
4158
4160{
4161 LAYER_TYPE layerType = getLayerType( aCadstarLayerID );
4162
4163 switch( layerType )
4164 {
4165 case LAYER_TYPE::ALLDOC:
4166 return LSET( { PCB_LAYER_ID::Dwgs_User,
4167 PCB_LAYER_ID::Cmts_User,
4168 PCB_LAYER_ID::Eco1_User,
4169 PCB_LAYER_ID::Eco2_User } )
4171
4174
4177 | LSET( { PCB_LAYER_ID::Dwgs_User,
4178 PCB_LAYER_ID::Cmts_User,
4179 PCB_LAYER_ID::Eco1_User,
4180 PCB_LAYER_ID::Eco2_User } )
4183
4184 default:
4185 return LSET( { getKiCadLayer( aCadstarLayerID ) } );
4186 }
4187}
4188
4189
4191 const GROUP_ID& aCadstarGroupID, BOARD_ITEM* aKiCadItem )
4192{
4193 wxCHECK( m_groupMap.find( aCadstarGroupID ) != m_groupMap.end(), );
4194
4195 PCB_GROUP* parentGroup = m_groupMap.at( aCadstarGroupID );
4196 parentGroup->AddItem( aKiCadItem );
4197}
4198
4199
4201 const wxString& aName )
4202{
4203 wxString groupName = aName;
4204 int num = 0;
4205
4206 while( m_groupMap.find( groupName ) != m_groupMap.end() )
4207 {
4208 groupName = aName + wxT( "_" ) + wxString::Format( wxT( "%i" ), ++num );
4209 }
4210
4211 PCB_GROUP* docSymGroup = new PCB_GROUP( m_board );
4212 m_board->Add( docSymGroup );
4213 docSymGroup->SetName( groupName );
4214 GROUP_ID groupID( groupName );
4215 m_groupMap.insert( { groupID, docSymGroup } );
4216
4217 return groupID;
4218}
@ ERROR_INSIDE
Definition: approximation.h:34
constexpr int ARC_HIGH_DEF
Definition: base_units.h:120
constexpr double PCB_IU_PER_MM
Definition: base_units.h:70
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
LAYER_T
The allowed types of layers, same as Specctra DSN spec.
Definition: board.h:153
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition: box2.h:990
#define COMPONENT_NAME_2_ATTRID
Component Name 2 Attribute ID - typically used for indicating the placement of designators in placeme...
#define COMPONENT_NAME_ATTRID
Component Name Attribute ID - typically used for placement of designators on silk screen.
#define PART_NAME_ATTRID
Loads a cpa file into a KiCad BOARD object.
BASE_SET & reset(size_t pos)
Definition: base_set.h:142
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
NETINFO_ITEM * GetNet() const
Return #NET_INFO object for a given item.
void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
Container for design settings for a BOARD object.
std::shared_ptr< NET_SETTINGS > m_NetSettings
BOARD_STACKUP & GetStackupDescriptor()
void SetBoardThickness(int aThickness)
int GetLineThickness(PCB_LAYER_ID aLayer) const
Return the default graphic segment thickness from the layer class for the given layer.
ZONE_SETTINGS & GetDefaultZoneSettings()
Abstract interface for BOARD_ITEMs capable of storing other items inside.
virtual void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false)=0
Adds an item to the container.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:237
virtual void SetLocked(bool aLocked)
Definition: board_item.h:328
virtual BOARD_ITEM * Duplicate() const
Create a copy of this BOARD_ITEM.
Definition: board_item.cpp:243
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:288
virtual bool IsLocked() const
Definition: board_item.cpp:75
Manage one layer needed to make a physical board.
Definition: board_stackup.h:96
void SetThickness(int aThickness, int aDielectricSubLayer=0)
void SetMaterial(const wxString &aName, int aDielectricSubLayer=0)
void SetLossTangent(double aTg, int aDielectricSubLayer=0)
void SetEpsilonR(double aEpsilon, int aDielectricSubLayer=0)
void SetLayerName(const wxString &aName)
Manage layers needed to make a physical board.
void RemoveAll()
Delete all items in list and clear the list.
const std::vector< BOARD_STACKUP_ITEM * > & GetList() const
int BuildBoardThicknessFromStackup() const
void BuildDefaultStackupList(const BOARD_DESIGN_SETTINGS *aSettings, int aActiveCopperLayersCount=0)
Create a default stackup, according to the current BOARD_DESIGN_SETTINGS settings.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:778
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: board.cpp:1003
void SetEnabledLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
Definition: board.cpp:798
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Changes the name of the layer given by aLayer.
Definition: board.cpp:592
void SetVisibleLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings changes the bit-mask of vis...
Definition: board.cpp:810
void SetCopperLayerCount(int aCount)
Definition: board.cpp:747
bool SetLayerType(PCB_LAYER_ID aLayer, LAYER_T aLayerType)
Change the type of the layer given by aLayer.
Definition: board.cpp:631
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:574
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:895
void Remove(BOARD_ITEM *aBoardItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL) override
Removes an item from the container.
Definition: board.cpp:1137
static const std::map< TEXT_FIELD_NAME, wxString > CADSTAR_TO_KICAD_FIELDS
Map between CADSTAR fields and KiCad text variables.
TEXT_FIELD_NAME
These are special fields in text objects enclosed between the tokens '<@' and '>' such as <@[FIELD_NA...
@ NO_ALIGNMENT
NO_ALIGNMENT has different meaning depending on the object type.
static const long UNDEFINED_VALUE
static wxString ParseTextFields(const wxString &aTextString, PARSER_CONTEXT *aParserContext)
Replaces CADSTAR fields for the equivalent in KiCad and stores the field values in aParserContext.
wxString LAYER_ID
ID of a Sheet (if schematic) or board Layer (if PCB)
static void FixTextPositionNoAlignment(EDA_TEXT *aKiCadTextItem)
Corrects the position of a text element that had NO_ALIGNMENT in CADSTAR.
@ OUTLINE
Unfilled closed shape.
@ OPENSHAPE
Unfilled open shape. Cannot have cutouts.
@ SOLID
Filled closed shape (solid fill).
@ HATCHED
Filled closed shape (hatch fill).
static const double TXT_HEIGHT_RATIO
CADSTAR fonts are drawn on a 24x24 integer matrix, where the each axis goes from 0 to 24.
void checkPoint()
Updates m_progressReporter or throws if user cancelled.
@ DESIGN
Inherits from design units (assumed Assignments->Technology->Units)
PROGRESS_REPORTER * m_progressReporter
std::map< TEMPLATE_ID, ZONE * > m_zonesMap
Map between Cadstar and KiCad zones.
std::map< std::tuple< ROUTECODE_ID, NETCLASS_ID, SPACING_CLASS_ID >, std::shared_ptr< NETCLASS > > m_netClassMap
Map between Cadstar and KiCad classes.
bool m_doneCopperWarning
Used by loadCoppers() to avoid multiple duplicate warnings.
std::set< PADCODE_ID > m_padcodesTested
Used by getKiCadPad() to avoid multiple duplicate warnings.
int getKiCadLength(long long aCadstarLength)
void initStackupItem(const LAYER &aCadstarLayer, BOARD_STACKUP_ITEM *aKiCadItem, int aDielectricSublayer)
int m_numCopperLayers
Number of layers in the design.
std::vector< LAYER_ID > m_powerPlaneLayers
List of layers that are marked as power plane in CADSTAR.
void drawCadstarText(const TEXT &aCadstarText, BOARD_ITEM_CONTAINER *aContainer, const GROUP_ID &aCadstarGroupID=wxEmptyString, const LAYER_ID &aCadstarLayerOverride=wxEmptyString, const VECTOR2I &aMoveVector={ 0, 0 }, double aRotationAngle=0.0, double aScalingFactor=1.0, const VECTOR2I &aTransformCentre={ 0, 0 }, bool aMirrorInvert=false)
bool isLayerSet(const LAYER_ID &aCadstarLayerID)
LAYERPAIR getLayerPair(const LAYERPAIR_ID &aCadstarLayerPairID)
FOOTPRINT * getFootprintFromCadstarID(const COMPONENT_ID &aCadstarComponentID)
PADCODE getPadCode(const PADCODE_ID &aCadstarPadCodeID)
int loadNetVia(const NET_ID &aCadstarNetID, const NET_PCB::VIA &aCadstarVia)
Load via and return via size.
EDA_ANGLE getAngle(const long long &aCadstarAngle)
std::vector< PCB_SHAPE * > getShapesFromVertices(const std::vector< VERTEX > &aCadstarVertices, BOARD_ITEM_CONTAINER *aContainer=nullptr, const GROUP_ID &aCadstarGroupID=wxEmptyString, const VECTOR2I &aMoveVector={ 0, 0 }, double aRotationAngle=0.0, double aScalingFactor=1.0, const VECTOR2I &aTransformCentre={ 0, 0 }, bool aMirrorInvert=false)
Returns a vector of pointers to PCB_SHAPE objects.
void applyTextCode(EDA_TEXT *aKiCadText, const TEXTCODE_ID &aCadstarTextCodeID)
Apply cadstar textcode parameters to a KiCad text object.
std::map< COMPONENT_ID, FOOTPRINT * > m_componentMap
Map between Cadstar and KiCad components on the board.
SHAPE_LINE_CHAIN getLineChainFromShapes(const std::vector< PCB_SHAPE * > &aShapes)
Returns a SHAPE_LINE_CHAIN object from a series of PCB_SHAPE objects.
void applyDimensionSettings(const DIMENSION &aCadstarDim, PCB_DIMENSION_BASE *aKiCadDim)
void loadNetTracks(const NET_ID &aCadstarNetID, const NET_PCB::ROUTE &aCadstarRoute, long aStartWidth=std::numeric_limits< long >::max(), long aEndWidth=std::numeric_limits< long >::max())
ZONE * getZoneFromCadstarShape(const SHAPE &aCadstarShape, const int &aLineThickness, BOARD_ITEM_CONTAINER *aParentContainer)
PCB_LAYER_ID getKiCadCopperLayerID(unsigned int aLayerNum, bool aDetectMaxLayer=true)
std::vector< PCB_TRACK * > makeTracksFromShapes(const std::vector< PCB_SHAPE * > &aShapes, BOARD_ITEM_CONTAINER *aParentContainer, NETINFO_ITEM *aNet=nullptr, PCB_LAYER_ID aLayerOverride=UNDEFINED_LAYER, int aWidthOverride=-1)
Returns a vector of pointers to TRACK/ARC objects.
VIACODE getViaCode(const VIACODE_ID &aCadstarViaCodeID)
VECTOR2I m_designCenter
Used for calculating the required offset to apply to the Cadstar design so that it fits in KiCad canv...
void Load(BOARD *aBoard, PROJECT *aProject)
Loads a CADSTAR PCB Archive file into the KiCad BOARD object given.
void drawCadstarCutoutsAsShapes(const std::vector< CUTOUT > &aCutouts, const PCB_LAYER_ID &aKiCadLayer, int aLineThickness, BOARD_ITEM_CONTAINER *aContainer, const GROUP_ID &aCadstarGroupID=wxEmptyString, const VECTOR2I &aMoveVector={ 0, 0 }, double aRotationAngle=0.0, double aScalingFactor=1.0, const VECTOR2I &aTransformCentre={ 0, 0 }, bool aMirrorInvert=false)
Uses PCB_SHAPEs to draw the cutouts on m_board object.
void logBoardStackupWarning(const wxString &aCadstarLayerName, const PCB_LAYER_ID &aKiCadLayer)
std::vector< FOOTPRINT * > GetLoadedLibraryFootpints() const
Return a copy of the loaded library footprints (caller owns the objects)
PCB_SHAPE * getShapeFromVertex(const POINT &aCadstarStartPoint, const VERTEX &aCadstarVertex, BOARD_ITEM_CONTAINER *aContainer=nullptr, const GROUP_ID &aCadstarGroupID=wxEmptyString, const VECTOR2I &aMoveVector={ 0, 0 }, double aRotationAngle=0.0, double aScalingFactor=1.0, const VECTOR2I &aTransformCentre={ 0, 0 }, bool aMirrorInvert=false)
Returns a pointer to a PCB_SHAPE object.
void checkAndLogHatchCode(const HATCHCODE_ID &aCadstarHatchcodeID)
bool m_doneSpacingClassWarning
Used by getKiCadNet() to avoid multiple duplicate warnings.
int m_numNets
Number of nets loaded so far.
void loadLibraryPads(const SYMDEF_PCB &aComponent, FOOTPRINT *aFootprint)
PAD * getKiCadPad(const COMPONENT_PAD &aCadstarPad, FOOTPRINT *aParent)
void drawCadstarShape(const SHAPE &aCadstarShape, const PCB_LAYER_ID &aKiCadLayer, int aLineThickness, const wxString &aShapeName, BOARD_ITEM_CONTAINER *aContainer, const GROUP_ID &aCadstarGroupID=wxEmptyString, const VECTOR2I &aMoveVector={ 0, 0 }, double aRotationAngle=0.0, double aScalingFactor=1.0, const VECTOR2I &aTransformCentre={ 0, 0 }, bool aMirrorInvert=false)
NETINFO_ITEM * getKiCadNet(const NET_ID &aCadstarNetID)
Searches m_netMap and returns the NETINFO_ITEM pointer if exists.
void logBoardStackupMessage(const wxString &aCadstarLayerName, const PCB_LAYER_ID &aKiCadLayer)
int getLineThickness(const LINECODE_ID &aCadstarLineCodeID)
std::map< NET_ID, NETINFO_ITEM * > m_netMap
Map between Cadstar and KiCad Nets.
void loadComponentAttributes(const COMPONENT &aComponent, FOOTPRINT *aFootprint)
PCB_GROUP * getKiCadGroup(const GROUP_ID &aCadstarGroupID)
bool m_logLayerWarnings
Used in loadBoardStackup()
HATCHCODE getHatchCode(const HATCHCODE_ID &aCadstarHatchcodeID)
void loadLibraryCoppers(const SYMDEF_PCB &aComponent, FOOTPRINT *aFootprint)
LAYER_TYPE getLayerType(const LAYER_ID aCadstarLayerID)
void loadLibraryFigures(const SYMDEF_PCB &aComponent, FOOTPRINT *aFootprint)
TEXTCODE getTextCode(const TEXTCODE_ID &aCadstarTextCodeID)
wxString getAttributeName(const ATTRIBUTE_ID &aCadstarAttributeID)
wxString getAttributeValue(const ATTRIBUTE_ID &aCadstarAttributeID, const std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > &aCadstarAttributeMap)
void applyRouteOffset(VECTOR2I *aPointToOffset, const VECTOR2I &aRefPoint, const long &aOffsetAmount)
CADSTAR's Post Processor does an action called "Route Offset" which is applied when a route is wider ...
VECTOR2I getKiCadPoint(const VECTOR2I &aCadstarPoint)
Scales, offsets and inverts y axis to make the point usable directly in KiCad.
void remapUnsureLayers()
Callback m_layerMappingHandler for layers we aren't sure of.
double getAngleTenthDegree(const long long &aCadstarAngle)
LSET getKiCadLayerSet(const LAYER_ID &aCadstarLayerID)
void addToGroup(const GROUP_ID &aCadstarGroupID, BOARD_ITEM *aKiCadItem)
std::map< SYMDEF_ID, FOOTPRINT * > m_libraryMap
Map between Cadstar and KiCad components in the library.
COPPERCODE getCopperCode(const COPPERCODE_ID &aCadstaCopperCodeID)
SHAPE_POLY_SET getPolySetFromCadstarShape(const SHAPE &aCadstarShape, int aLineThickness=-1, BOARD_ITEM_CONTAINER *aContainer=nullptr, const VECTOR2I &aMoveVector={ 0, 0 }, double aRotationAngle=0.0, double aScalingFactor=1.0, const VECTOR2I &aTransformCentre={ 0, 0 }, bool aMirrorInvert=false)
Returns a SHAPE_POLY_SET object from a Cadstar SHAPE.
std::map< PAD_ID, std::vector< PAD_ID > > ASSOCIATED_COPPER_PADS
Map of pad anchor points (first) to copper pads (second).
EDA_ANGLE getHatchCodeAngle(const HATCHCODE_ID &aCadstarHatchcodeID)
int getKiCadHatchCodeThickness(const HATCHCODE_ID &aCadstarHatchcodeID)
PCB_LAYER_ID getKiCadLayer(const LAYER_ID &aCadstarLayerID)
std::set< HATCHCODE_ID > m_hatchcodesTested
Used by checkAndLogHatchCode() to avoid multiple duplicate warnings.
void loadLibraryAreas(const SYMDEF_PCB &aComponent, FOOTPRINT *aFootprint)
GROUP_ID createUniqueGroupID(const wxString &aName)
Adds a new PCB_GROUP* to m_groupMap.
int getKiCadHatchCodeGap(const HATCHCODE_ID &aCadstarHatchcodeID)
std::vector< std::unique_ptr< FOOTPRINT > > LoadLibrary()
Parse a CADSTAR PCB Archive and load the footprints contained within.
ROUTECODE getRouteCode(const ROUTECODE_ID &aCadstarRouteCodeID)
void drawCadstarVerticesAsShapes(const std::vector< VERTEX > &aCadstarVertices, const PCB_LAYER_ID &aKiCadLayer, int aLineThickness, BOARD_ITEM_CONTAINER *aContainer, const GROUP_ID &aCadstarGroupID=wxEmptyString, const VECTOR2I &aMoveVector={ 0, 0 }, double aRotationAngle=0.0, double aScalingFactor=1.0, const VECTOR2I &aTransformCentre={ 0, 0 }, bool aMirrorInvert=false)
Uses PCB_SHAPE to draw the vertices on m_board object.
void addAttribute(const ATTRIBUTE_LOCATION &aCadstarAttrLoc, const ATTRIBUTE_ID &aCadstarAttributeID, FOOTPRINT *aFootprint, const wxString &aAttributeValue)
Adds a CADSTAR Attribute to a KiCad footprint.
std::map< GROUP_ID, PCB_GROUP * > m_groupMap
Map between Cadstar and KiCad groups.
bool calculateZonePriorities(PCB_LAYER_ID &aLayer)
Tries to make a best guess as to the zone priorities based on the pour status.
std::map< LAYER_ID, PCB_LAYER_ID > m_layermap
Map between Cadstar and KiCad Layers.
PAD *& getPadReference(FOOTPRINT *aFootprint, const PAD_ID aCadstarPadID)
bool m_doneNetClassWarning
Used by getKiCadNet() to avoid multiple duplicate warnings.
double getAngleDegrees(const long long &aCadstarAngle)
PART getPart(const PART_ID &aCadstarPartID)
LAYER_MAPPING_HANDLER m_layerMappingHandler
Callback to get layer mapping.
std::map< SYMDEF_ID, ASSOCIATED_COPPER_PADS > m_librarycopperpads
Associated copper pads (if any) for each component library definition.
long PAD_ID
Pad identifier (pin) in the PCB.
void Parse(bool aLibrary=false)
Parses the file.
int KiCadUnitMultiplier
Use this value to convert units in this CPA file to KiCad units.
@ UNDEFINED
Only used for error detection.
@ ALLELEC
Inbuilt layer type (cannot be assigned to user layers)
@ ALLDOC
Inbuilt layer type (cannot be assigned to user layers)
@ NONELEC
This type has subtypes.
@ NOLAYER
Inbuilt layer type (cannot be assigned to user layers)
@ JUMPERLAYER
Inbuilt layer type (cannot be assigned to user layers)
@ ALLLAYER
Inbuilt layer type (cannot be assigned to user layers)
@ ASSCOMPCOPP
Inbuilt layer type (cannot be assigned to user layers)
@ MAXIMUM
The highest PHYSICAL_LAYER_ID currently defined (i.e.
@ MINIMUM
PHYSICAL_LAYER_ID 1 (i.e.
@ THROUGH_HOLE
All physical layers currently defined.
EDA_ANGLE NormalizeNegative()
Definition: eda_angle.h:238
double Sin() const
Definition: eda_angle.h:170
double AsDegrees() const
Definition: eda_angle.h:113
EDA_ANGLE Normalize180()
Definition: eda_angle.h:260
double Cos() const
Definition: eda_angle.h:189
void SetCenter(const VECTOR2I &aCenter)
Definition: eda_shape.cpp:778
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:286
void SetPolyShape(const SHAPE_POLY_SET &aShape)
Definition: eda_shape.h:294
virtual void SetFilled(bool aFlag)
Definition: eda_shape.h:108
void SetStart(const VECTOR2I &aStart)
Definition: eda_shape.h:141
void SetShape(SHAPE_T aShape)
Definition: eda_shape.h:131
void SetEnd(const VECTOR2I &aEnd)
Definition: eda_shape.h:178
void SetArcAngleAndEnd(const EDA_ANGLE &aAngle, bool aCheckNegativeAngle=false)
Set the end point from the angle center and start.
Definition: eda_shape.cpp:924
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:80
const EDA_ANGLE & GetTextAngle() const
Definition: eda_text.h:134
void SetTextSize(VECTOR2I aNewSize, bool aEnforceMinTextSize=true)
Definition: eda_text.cpp:515
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:98
void SetTextPos(const VECTOR2I &aPoint)
Definition: eda_text.cpp:560
void SetMirrored(bool isMirrored)
Definition: eda_text.cpp:384
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:408
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:377
void SetTextThickness(int aWidth)
The TextThickness is that set by the user.
Definition: eda_text.cpp:283
void SetKeepUpright(bool aKeepUpright)
Definition: eda_text.cpp:416
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:269
virtual void SetTextAngle(const EDA_ANGLE &aAngle)
Definition: eda_text.cpp:291
int GetTextThickness() const
Definition: eda_text.h:126
VECTOR2I GetTextSize() const
Definition: eda_text.h:249
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:400
void SetPosition(const VECTOR2I &aPos) override
Definition: footprint.cpp:2388
void SetFPID(const LIB_ID &aFPID)
Definition: footprint.h:249
void SetOrientation(const EDA_ANGLE &aNewAngle)
Definition: footprint.cpp:2458
PCB_FIELD & Value()
read/write accessors:
Definition: footprint.h:658
BOARD_ITEM * Duplicate() const override
Create a copy of this BOARD_ITEM.
Definition: footprint.cpp:2484
std::deque< PAD * > & Pads()
Definition: footprint.h:206
void SetReference(const wxString &aReference)
Definition: footprint.h:628
void SetValue(const wxString &aValue)
Definition: footprint.h:649
PCB_FIELD & Reference()
Definition: footprint.h:659
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: footprint.cpp:1025
void AutoPositionFields()
Position Reference and Value fields at the top and bottom of footprint's bounding box.
Definition: footprint.cpp:2644
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
Definition: footprint.cpp:2330
void SetLibDescription(const wxString &aDesc)
Definition: footprint.h:258
const wxString & GetReference() const
Definition: footprint.h:622
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:51
const UTF8 & GetLibItemName() const
Definition: lib_id.h:102
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: lseq.h:47
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:36
static LSET AllBoardTechMask()
Return a mask holding board technical layers (no CU layer) on both side.
Definition: lset.cpp:751
static LSET AllLayersMask()
Definition: lset.cpp:711
static LSET UserDefinedLayers()
Return a mask with all of the allowable user defined layers.
Definition: lset.cpp:773
static LSET UserMask()
Definition: lset.cpp:758
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:686
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:420
static wxString Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:193
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition: lset.h:62
Handle the data for a net.
Definition: netinfo.h:56
void SetNetClass(const std::shared_ptr< NETCLASS > &aNetClass)
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
Definition: padstack.h:144
Definition: pad.h:54
const wxString & GetNumber() const
Definition: pad.h:134
void SetNumber(const wxString &aNumber)
Set the pad number (note that it can be alphanumeric, such as the array reference "AA12").
Definition: pad.h:133
Abstract dimension API.
void SetUnitsFormat(const DIM_UNITS_FORMAT aFormat)
void SetPrefix(const wxString &aPrefix)
void SetExtensionOffset(int aOffset)
void SetSuffix(const wxString &aSuffix)
void SetLineThickness(int aWidth)
virtual const VECTOR2I & GetStart() const
The dimension's origin is the first feature point for the dimension.
virtual void SetEnd(const VECTOR2I &aPoint)
void SetPrecision(DIM_PRECISION aPrecision)
virtual void SetStart(const VECTOR2I &aPoint)
void SetOverrideText(const wxString &aValue)
void SetUnitsMode(DIM_UNITS_MODE aMode)
For better understanding of the points that make a dimension:
void SetExtensionHeight(int aHeight)
void SetHeight(int aHeight)
Set the distance from the feature points to the crossbar line.
A leader is a dimension-like object pointing to a specific point.
An orthogonal dimension is like an aligned dimension, but the extension lines are locked to the X or ...
void SetOrientation(DIR aOrientation)
Set the orientation of the dimension line (so, perpendicular to the feature lines).
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:52
void SetName(const wxString &aName)
Definition: pcb_group.h:67
virtual bool AddItem(BOARD_ITEM *aItem)
Add item to group.
Definition: pcb_group.cpp:81
void SetLocked(bool aLocked) override
Definition: pcb_group.cpp:184
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition: pcb_shape.cpp:480
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
Definition: pcb_shape.cpp:486
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition: pcb_shape.cpp:170
void Move(const VECTOR2I &aMoveVector) override
Move this object.
Definition: pcb_shape.cpp:387
void Scale(double aScale)
Definition: pcb_shape.cpp:393
void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: pcb_shape.h:90
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
Definition: pcb_text.cpp:406
virtual void SetPosition(const VECTOR2I &aPos) override
Definition: pcb_text.h:87
void Move(const VECTOR2I &aMoveVector) override
Move this object.
Definition: pcb_text.h:92
void SetEnd(const VECTOR2I &aEnd)
Definition: pcb_track.h:118
void SetStart(const VECTOR2I &aStart)
Definition: pcb_track.h:121
const VECTOR2I & GetStart() const
Definition: pcb_track.h:122
const VECTOR2I & GetEnd() const
Definition: pcb_track.h:119
virtual void SetWidth(int aWidth)
Definition: pcb_track.h:115
virtual int GetWidth() const
Definition: pcb_track.h:116
virtual void SetNumPhases(int aNumPhases)=0
Set the number of phases.
virtual void BeginPhase(int aPhase)=0
Initialize the aPhase virtual zone of the dialog progress bar.
virtual void SetMaxProgress(int aMaxProgress)=0
Fix the value that gives the 100 percent progress bar length (inside the current virtual zone).
Container for project specific data.
Definition: project.h:64
virtual std::map< wxString, wxString > & GetTextVars() const
Definition: project.cpp:84
void Reverse()
Definition: shape_arc.cpp:674
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
virtual const VECTOR2I GetPoint(int aIndex) const override
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
int PointCount() const
Return the number of points (vertices) in this line chain.
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.
void BooleanAdd(const SHAPE_POLY_SET &b)
Perform boolean polyset union.
void ClearArcs()
Removes all arc references from all the outlines and holes in the polyset.
double Area()
Return the area of this poly set.
void Fracture()
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
void Inflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError, bool aSimplify=false)
Perform outline inflation/deflation.
int HoleCount(int aOutline) const
Returns the number of holes in a given outline.
int AddHole(const SHAPE_LINE_CHAIN &aHole, int aOutline=-1)
Adds a new hole to the given outline (default: last) and returns its index.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
SHAPE_LINE_CHAIN & Hole(int aOutline, int aHole)
Return the reference to aHole-th hole in the aIndex-th outline.
void BooleanIntersection(const SHAPE_POLY_SET &b)
Perform boolean polyset intersection.
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
int OutlineCount() const
Return the number of outlines in the set.
void Move(const VECTOR2I &aVector) override
bool Contains(const VECTOR2I &aP, int aSubpolyIndex=-1, int aAccuracy=0, bool aUseBBoxCaches=false) const
Return true if a given subpolygon contains the point aP.
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
Simple container to manage line stroke parameters.
Definition: stroke_params.h:79
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector2d.h:283
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:385
EDA_ANGLE m_HatchOrientation
Definition: zone_settings.h:96
Handle a list of polygons defining a copper zone.
Definition: zone.h:73
void SetHatchThickness(int aThickness)
Definition: zone.h:289
void SetNeedRefill(bool aNeedRefill)
Definition: zone.h:268
void SetDoNotAllowPads(bool aEnable)
Definition: zone.h:750
std::optional< int > GetLocalClearance() const override
Definition: zone.cpp:714
void SetLocalClearance(std::optional< int > aClearance)
Definition: zone.h:158
void AddPolygon(std::vector< VECTOR2I > &aPolygon)
Add a polygon to the zone outline.
Definition: zone.cpp:1014
const std::shared_ptr< SHAPE_POLY_SET > & GetFilledPolysList(PCB_LAYER_ID aLayer) const
Definition: zone.h:620
void SetMinThickness(int aMinThickness)
Definition: zone.h:274
void SetHatchOrientation(const EDA_ANGLE &aStep)
Definition: zone.h:295
void SetDoNotAllowCopperPour(bool aEnable)
Definition: zone.h:747
void SetThermalReliefSpokeWidth(int aThermalReliefSpokeWidth)
Definition: zone.h:209
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition: zone.cpp:481
SHAPE_POLY_SET * Outline()
Definition: zone.h:340
void SetHatchStyle(ZONE_BORDER_DISPLAY_STYLE aStyle)
Definition: zone.h:610
SHAPE_POLY_SET * GetFill(PCB_LAYER_ID aLayer)
Definition: zone.h:626
void SetIsRuleArea(bool aEnable)
Definition: zone.h:737
void SetDoNotAllowTracks(bool aEnable)
Definition: zone.h:749
void SetFilledPolysList(PCB_LAYER_ID aLayer, const SHAPE_POLY_SET &aPolysList)
Set the list of filled polygons.
Definition: zone.h:641
void SetIsFilled(bool isFilled)
Definition: zone.h:265
void SetFillMode(ZONE_FILL_MODE aFillMode)
Definition: zone.h:195
bool HasFilledPolysForLayer(PCB_LAYER_ID aLayer) const
Definition: zone.h:612
void SetLayerSet(const LSET &aLayerSet) override
Definition: zone.cpp:487
void SetDoNotAllowVias(bool aEnable)
Definition: zone.h:748
void SetThermalReliefGap(int aThermalReliefGap)
Definition: zone.h:198
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.h:133
void SetDoNotAllowFootprints(bool aEnable)
Definition: zone.h:751
void SetAssignedPriority(unsigned aPriority)
Definition: zone.h:118
void SetPadConnection(ZONE_CONNECTION aPadConnection)
Definition: zone.h:271
void SetZoneName(const wxString &aName)
Definition: zone.h:136
void SetIslandRemovalMode(ISLAND_REMOVAL_MODE aRemove)
Definition: zone.h:754
void SetMinIslandArea(long long int aArea)
Definition: zone.h:757
void SetHatchGap(int aStep)
Definition: zone.h:292
void TransformArcToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc)
Convert arc to multiple straight segments.
void TransformOvalToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
#define _(s)
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:403
@ TENTHS_OF_A_DEGREE_T
Definition: eda_angle.h:30
static constexpr EDA_ANGLE ANGLE_180
Definition: eda_angle.h:405
#define DEFAULT_SIZE_TEXT
This is the "default-of-the-default" hardcoded text size; individual application define their own def...
Definition: eda_text.h:70
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:39
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ User_8
Definition: layer_ids.h:131
@ Dwgs_User
Definition: layer_ids.h:107
@ F_Paste
Definition: layer_ids.h:104
@ Cmts_User
Definition: layer_ids.h:108
@ User_6
Definition: layer_ids.h:129
@ User_7
Definition: layer_ids.h:130
@ B_Mask
Definition: layer_ids.h:98
@ B_Cu
Definition: layer_ids.h:65
@ User_5
Definition: layer_ids.h:128
@ F_Mask
Definition: layer_ids.h:97
@ B_Paste
Definition: layer_ids.h:105
@ User_9
Definition: layer_ids.h:132
@ User_3
Definition: layer_ids.h:126
@ User_1
Definition: layer_ids.h:124
@ User_4
Definition: layer_ids.h:127
@ User_2
Definition: layer_ids.h:125
@ F_Cu
Definition: layer_ids.h:64
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:83
constexpr int Mils2IU(const EDA_IU_SCALE &aIuScale, int mils)
Definition: eda_units.h:157
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:390
DIM_PRECISION
Definition: pcb_dimension.h:47
Class to handle a set of BOARD_ITEMs.
#define KEY_PREPREG
#define KEY_CORE
ALIGNMENT Alignment
In CADSTAR The default alignment for a TEXT object (when "(No Alignment()" is selected) Bottom Left o...
bool HasLocation
Flag to know if this ATTRIBUTE_VALUE has a location i.e.
std::map< SPACING_CLASS_ID, SPCCLASSNAME > SpacingClassNames
std::map< LINECODE_ID, LINECODE > LineCodes
std::map< NETCLASS_ID, CADSTAR_NETCLASS > NetClasses
std::map< HATCHCODE_ID, HATCHCODE > HatchCodes
std::map< ATTRIBUTE_ID, ATTRNAME > AttributeNames
std::map< ROUTECODE_ID, ROUTECODE > RouteCodes
std::map< TEXTCODE_ID, TEXTCODE > TextCodes
Represents a cutout in a closed shape (e.g.
long ScaleRatioNumerator
Documentation symbols can be arbitrarily scaled when added to a design.
long ScaleRatioDenominator
Documentation symbols can be arbitrarily scaled when added to a design.
POINT Origin
Origin of the component (this is used as the reference point when placing the component in the design...
LAYER_ID LayerID
Move all objects in the Symdef to this layer.
SYMDEF_ID SymdefID
Normally documentation symbols only have TEXT, FIGURE and TEXT_LOCATION objects which are all drawn o...
GROUP_ID GroupID
If not empty, this FIGURE is part of a group.
GROUP_ID GroupID
If not empty, this GROUP is part of another GROUP.
ROUTECODE_ID RouteCodeID
"NETCODE" subnode
wxString Name
This is undefined (wxEmptyString) if the net is unnamed.
NETCLASS_ID NetClassID
The net might not have a net class, in which case it will be wxEmptyString ("NETCLASSREF" subnode)
SPACING_CLASS_ID SpacingClassID
The net might not have a spacing class, in which case it will be wxEmptyString ("SPACINGCLASS" subnod...
long SignalNum
This is undefined if the net has been given a name.
std::map< TEXT_FIELD_NAME, wxString > TextFieldToValuesMap
Values for the text field elements used in the CADSTAR design extracted from the text element instanc...
std::map< wxString, wxString > FilenamesToTextMap
CADSTAR doesn't have user defined text fields but does allow loading text from a file.
std::set< TEXT_FIELD_NAME > InconsistentTextFields
Text fields need to be updated in CADSTAR and it is possible that they are not consistent across text...
std::map< PART_ID, PART > PartDefinitions
wxString Name
This name can be different to the PART name.
std::map< PART_DEFINITION_PIN_ID, PIN > Pins
Represents a point in x,y coordinates.
UNITS Units
Units to display for linear dimensions.
std::pair< POINT, POINT > DesignArea
long UnitDisplPrecision
Number of decimal points to display for linear dimensions.
wxString HatchCodeID
Only Applicable for HATCHED Type.
std::vector< CUTOUT > Cutouts
Not Applicable to OPENSHAPE Type.
std::map< FIGURE_ID, FIGURE > Figures
POINT Origin
Origin of the component (this is used as the reference point when placing the component in the design...
wxString Alternate
This is in addition to ReferenceName.
wxString ReferenceName
This is the name which identifies the symbol in the library Multiple components may exist with the sa...
long Width
Defaults to 0 if using system fonts or, if using CADSTAR font, default to equal height (1:1 aspect ra...
Corresponds to CADSTAR "origin".
ALIGNMENT Alignment
In CADSTAR The default alignment for a TEXT object (when "(No Alignment()" is selected) Bottom Left o...
< Nodename = "VARIANT" or "VMASTER" (master variant
Represents a vertex in a shape.
From CADSTAR Help: "Area is for creating areas within which, and nowhere else, certain operations are...
bool Keepout
From CADSTAR Help: "Auto Placement cannot place components within this area.
bool Placement
From CADSTAR Help: "Auto Placement can place components within this area.
bool NoVias
From CADSTAR Help: "No vias will be placed within this area by the automatic router.
bool Routing
From CADSTAR Help: "Area can be used to place routes during Automatic Routing.
bool NoTracks
From CADSTAR Help: "Area cannot be used to place routes during automatic routing.
GROUP_ID GroupID
Normally CADSTAR_BOARD cannot be part of a reuseblock, but included for completeness.
std::map< COPPERCODE_ID, COPPERCODE > CopperCodes
std::map< SPACINGCODE_ID, SPACINGCODE > SpacingCodes
Spacing Design Rules.
std::map< LAYERPAIR_ID, LAYERPAIR > LayerPairs
Default vias to use between pairs of layers.
From CADSTAR Help: "Area is for creating areas within which, and nowhere else, certain operations are...
bool NoVias
From CADSTAR Help: "Check this button to specify that any area created by the Rectangle,...
bool NoTracks
From CADSTAR Help: "Check this button to specify that any area created by the Rectangle,...
A shape of copper in the component footprint.
bool PCBonlyPad
From CADSTAR Help: "The PCB Only Pad property can be used to stop ECO Update, Back Annotation,...
POINT Position
Pad position within the component's coordinate frame.
wxString Identifier
This is an identifier that is displayed to the user.
wxString Name
Designator e.g. "C1", "R1", etc.
POINT Origin
Origin of the component (this is used as the reference point when placing the component in the design...
std::map< ATTRIBUTE_ID, ATTRIBUTE_VALUE > AttributeValues
std::map< PAD_ID, PADEXCEPTION > PadExceptions
Override pad definitions for this instance.
std::map< ATTRIBUTE_ID, TEXT_LOCATION > TextLocations
This contains location of any attributes, including designator position.
TEMPLATE_ID PouredTemplateID
If not empty, it means this COPPER is part of a poured template.
long Overshoot
Overshoot of the extension line past the arrow line.
long LeaderLineExtensionLength
Only for TYPE=LEADERLINE Length of the horizontal part of the leader line [param6].
long LeaderLineLength
Only for TYPE=LEADERLINE Length of the angled part of the leader line [param5].
long LeaderAngle
Only for TYPE=LEADERLINE subnode "LEADERANG".
Linear, leader (radius/diameter) or angular dimension.
LAYER_ID LayerID
ID on which to draw this [param1].
EXTENSION_LINE ExtensionLineParams
Not applicable to TYPE=LEADERDIM.
DIMENSION_ID ID
Some ID (doesn't seem to be used) subnode="DIMREF".
long Precision
Number of decimal points to display in the measurement [param3].
std::map< MATERIAL_ID, MATERIAL > Materials
long Thickness
Note: Units of length are defined in file header.
std::map< TEMPLATE_ID, TEMPLATE > Templates
std::map< BOARD_ID, CADSTAR_BOARD > Boards
Normally CADSTAR only allows one board but.
std::map< NET_ID, NET_PCB > Nets
Contains tracks and vias.
std::map< COMPONENT_ID, COMPONENT > Components
std::map< DOCUMENTATION_SYMBOL_ID, DOCUMENTATION_SYMBOL > DocumentationSymbols
std::map< DIMENSION_ID, DIMENSION > Dimensions
std::map< REUSEBLOCK_ID, REUSEBLOCK > ReuseBlocks
std::map< SYMDEF_ID, SYMDEF_PCB > ComponentDefinitions
std::map< NETELEMENT_ID, JUNCTION_PCB > Junctions
long ReliefWidth
if undefined inherits from design
std::map< LAYER_ID, CADSTAR_PAD_SHAPE > Reassigns
long ReliefClearance
if undefined inherits from design
PADCODE_ID PadCode
If not empty, override padcode.
std::map< PAD_ID, COMPONENT_PAD > ComponentPads
std::vector< COMPONENT_COPPER > ComponentCoppers
std::map< COMP_AREA_ID, COMPONENT_AREA > ComponentAreas
long MinRouteWidth
Manufacturing Design Rule. Corresponds to "Thin Route Width".
long MaxPhysicalLayer
Should equal number of copper layers.
long AdditionalIsolation
This is the gap to apply in routes and pads in addition to the existing pad-to-copper or route-to-cop...
bool ThermalReliefOnVias
false when subnode "NOVIARELIEF" is present
HATCHCODE_ID HatchCodeID
Only for FillType = HATCHED.
bool ThermalReliefOnPads
false when subnode "NOPINRELIEF" is present
long ThermalReliefPadsAngle
Orientation for the thermal reliefs.
long MinDisjointCopper
The value is the length of one side of a notional square.
bool AutomaticRepour
true when subnode "REGENERATE" is present
bool AllowInNoRouting
true when subnode "IGNORETRN" is present
bool BoxIsolatedPins
true when subnode "BOXPINS" is present
long ClearanceWidth
Specifies the space around pads when pouring (i.e.
COPPERCODE_ID ReliefCopperCodeID
From CADSTAR Help: "Relief Copper Code is for selecting the width of line used to draw the thermal re...
COPPERCODE_ID CopperCodeID
From CADSTAR Help: "Copper Code is for selecting the width of the line used to draw the outline and f...
long ThermalReliefViasAngle
Disabled when !ThermalReliefOnVias (param6)
long MinIsolatedCopper
The value is the length of one side of a notional square.
long SliverWidth
Minimum width of copper that may be created.
Templates are CADSTAR's equivalent to a "filled zone".
POURING Pouring
Copper pour settings (e.g. relief / hatching /etc.)
Describes an imported layer and how it could be mapped to KiCad Layers.
PCB_LAYER_ID AutoMapLayer
Best guess as to what the equivalent KiCad layer might be.
LSET PermittedLayers
KiCad layers that the imported layer can be mapped onto.
wxString Name
Imported layer name as displayed in original application.
@ 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
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:229
double DEG2RAD(double deg)
Definition: trigo.h:166
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:101
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691