diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp index 38283befa4..af9505e225 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.cpp @@ -25,6 +25,7 @@ #include +#include #include #include #include @@ -475,29 +476,66 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadBusses() bool firstPt = true; VERTEX last; - for( const VERTEX& cur : bus.Shape.Vertices ) + if( bus.LayerID != wxT( "NO_SHEET" ) ) { - if( firstPt ) - { - last = cur; - firstPt = false; - continue; - } + SCH_SCREEN* screen = mSheetMap.at( bus.LayerID )->GetScreen(); + std::shared_ptr kiBusAlias = std::make_shared(); - if( bus.LayerID != wxT( "NO_SHEET" ) ) + kiBusAlias->SetName( bus.Name ); + kiBusAlias->SetParent( screen ); + screen->AddBusAlias( kiBusAlias ); + mBusesMap.insert( { bus.ID, kiBusAlias } ); + + SCH_LABEL* label = new SCH_LABEL(); + label->SetText( wxT( "{" ) + bus.Name + wxT( "}" ) ); + label->SetVisible( true ); + screen->Append( label ); + + SHAPE_LINE_CHAIN busLineChain; // to compute nearest segment to bus label + + for( const VERTEX& cur : bus.Shape.Vertices ) { + busLineChain.Append( getKiCadPoint( cur.End ) ); + + if( firstPt ) + { + last = cur; + firstPt = false; + + if( !bus.HasBusLabel ) + { + // Add a bus label on the starting point if the original CADSTAR design + // does not have an explicit label + label->SetPosition( getKiCadPoint( last.End ) ); + } + + continue; + } + + SCH_LINE* kiBus = new SCH_LINE(); kiBus->SetStartPoint( getKiCadPoint( last.End ) ); kiBus->SetEndPoint( getKiCadPoint( cur.End ) ); kiBus->SetLayer( LAYER_BUS ); kiBus->SetLineWidth( getLineThickness( bus.LineCodeID ) ); + screen->Append( kiBus ); last = cur; + } - mSheetMap.at( bus.LayerID )->GetScreen()->Append( kiBus ); + if( bus.HasBusLabel ) + { + //lets find the closest point in the busline to the label + VECTOR2I busLabelLoc = getKiCadPoint( bus.BusLabel.Position ); + wxPoint nearestPt = (wxPoint) busLineChain.NearestPoint( busLabelLoc ); + + label->SetPosition( nearestPt ); + applyTextSettings( bus.BusLabel.TextCodeID, bus.BusLabel.Alignment, + bus.BusLabel.Justification, label ); } } + } } @@ -555,6 +593,9 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadNets() NET_SCH::BUS_TERM busTerm = busPair.second; BUS bus = Schematic.Buses.at( busTerm.BusID ); + if( !mBusesMap.at( bus.ID )->Contains( netName ) ) + mBusesMap.at( bus.ID )->AddMember( netName ); + SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( getKiCadPoint( busTerm.FirstPoint ), false ); diff --git a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h index 996372f2ff..de3a08b93a 100644 --- a/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h +++ b/eeschema/sch_plugins/cadstar/cadstar_sch_archive_loader.h @@ -33,6 +33,7 @@ #include #include +class BUS_ALIAS; class EDA_TEXT; class LABEL_SPIN_STYLE; class LIB_FIELD; @@ -96,6 +97,7 @@ private: mPowerSymMap; ///< Map between Cadstar and KiCad Power Symbols std::map mGlobLabelMap; ///< Map between Cadstar and KiCad Global Labels + std::map> mBusesMap; ///< Map between Cadstar and KiCad Buses void loadSheets(); void loadHierarchicalSheetPins();