CADSTAR Schematic Importer: Fix loading of buses
Place bus labels and correctly group nets for the bus in a BUS_ALIAS
This commit is contained in:
parent
0691e942f4
commit
ba77bf662c
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include <sch_plugins/cadstar/cadstar_sch_archive_loader.h>
|
#include <sch_plugins/cadstar/cadstar_sch_archive_loader.h>
|
||||||
|
|
||||||
|
#include <bus_alias.h>
|
||||||
#include <core/mirror.h>
|
#include <core/mirror.h>
|
||||||
#include <eda_text.h>
|
#include <eda_text.h>
|
||||||
#include <lib_arc.h>
|
#include <lib_arc.h>
|
||||||
|
@ -475,29 +476,66 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadBusses()
|
||||||
bool firstPt = true;
|
bool firstPt = true;
|
||||||
VERTEX last;
|
VERTEX last;
|
||||||
|
|
||||||
|
if( bus.LayerID != wxT( "NO_SHEET" ) )
|
||||||
|
{
|
||||||
|
SCH_SCREEN* screen = mSheetMap.at( bus.LayerID )->GetScreen();
|
||||||
|
std::shared_ptr<BUS_ALIAS> kiBusAlias = std::make_shared<BUS_ALIAS>();
|
||||||
|
|
||||||
|
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 )
|
for( const VERTEX& cur : bus.Shape.Vertices )
|
||||||
{
|
{
|
||||||
|
busLineChain.Append( getKiCadPoint( cur.End ) );
|
||||||
|
|
||||||
if( firstPt )
|
if( firstPt )
|
||||||
{
|
{
|
||||||
last = cur;
|
last = cur;
|
||||||
firstPt = false;
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( bus.LayerID != wxT( "NO_SHEET" ) )
|
|
||||||
{
|
|
||||||
SCH_LINE* kiBus = new SCH_LINE();
|
SCH_LINE* kiBus = new SCH_LINE();
|
||||||
|
|
||||||
kiBus->SetStartPoint( getKiCadPoint( last.End ) );
|
kiBus->SetStartPoint( getKiCadPoint( last.End ) );
|
||||||
kiBus->SetEndPoint( getKiCadPoint( cur.End ) );
|
kiBus->SetEndPoint( getKiCadPoint( cur.End ) );
|
||||||
kiBus->SetLayer( LAYER_BUS );
|
kiBus->SetLayer( LAYER_BUS );
|
||||||
kiBus->SetLineWidth( getLineThickness( bus.LineCodeID ) );
|
kiBus->SetLineWidth( getLineThickness( bus.LineCodeID ) );
|
||||||
|
screen->Append( kiBus );
|
||||||
|
|
||||||
last = cur;
|
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;
|
NET_SCH::BUS_TERM busTerm = busPair.second;
|
||||||
BUS bus = Schematic.Buses.at( busTerm.BusID );
|
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 =
|
SCH_BUS_WIRE_ENTRY* busEntry =
|
||||||
new SCH_BUS_WIRE_ENTRY( getKiCadPoint( busTerm.FirstPoint ), false );
|
new SCH_BUS_WIRE_ENTRY( getKiCadPoint( busTerm.FirstPoint ), false );
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#include <sch_io_mgr.h>
|
#include <sch_io_mgr.h>
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
|
|
||||||
|
class BUS_ALIAS;
|
||||||
class EDA_TEXT;
|
class EDA_TEXT;
|
||||||
class LABEL_SPIN_STYLE;
|
class LABEL_SPIN_STYLE;
|
||||||
class LIB_FIELD;
|
class LIB_FIELD;
|
||||||
|
@ -96,6 +97,7 @@ private:
|
||||||
mPowerSymMap; ///< Map between Cadstar and KiCad Power Symbols
|
mPowerSymMap; ///< Map between Cadstar and KiCad Power Symbols
|
||||||
std::map<SYMBOL_ID, SCH_GLOBALLABEL*>
|
std::map<SYMBOL_ID, SCH_GLOBALLABEL*>
|
||||||
mGlobLabelMap; ///< Map between Cadstar and KiCad Global Labels
|
mGlobLabelMap; ///< Map between Cadstar and KiCad Global Labels
|
||||||
|
std::map<BUS_ID, std::shared_ptr<BUS_ALIAS>> mBusesMap; ///< Map between Cadstar and KiCad Buses
|
||||||
|
|
||||||
void loadSheets();
|
void loadSheets();
|
||||||
void loadHierarchicalSheetPins();
|
void loadHierarchicalSheetPins();
|
||||||
|
|
Loading…
Reference in New Issue