CADSTAR PCB Archive Importer: Load TEXTS and fix loading speed

Loading speed fixed by changing the way CADSTAR_ARCHIVE_PARSER::InsertAttributeAtEnd works (we now have a new attribute in each node to keep track of how many attributes there are). Now loads a 30,000 line file in 10seconds instead of 25 minutes!
This commit is contained in:
Roberto Fernandez Bautista 2020-09-02 22:48:18 +01:00 committed by Seth Hillbrand
parent fe3e20ddc7
commit 7e65d443e8
5 changed files with 155 additions and 7 deletions

View File

@ -124,15 +124,21 @@ double CADSTAR_ARCHIVE_PARSER::EVALUE::GetDouble()
void CADSTAR_ARCHIVE_PARSER::InsertAttributeAtEnd( XNODE* aNode, wxString aValue ) void CADSTAR_ARCHIVE_PARSER::InsertAttributeAtEnd( XNODE* aNode, wxString aValue )
{ {
wxString result, paramName = "attr0"; wxString result;
int i = 0; int numAttributes = 0;
while( aNode->GetAttribute( paramName, &result ) ) if( aNode->GetAttribute( wxT( "numAttributes" ), &result ) )
{ {
paramName = wxT( "attr" ); numAttributes = wxAtoi( result );
paramName << i++; aNode->DeleteAttribute( wxT( "numAttributes" ) );
++numAttributes;
} }
aNode->AddAttribute( wxT( "numAttributes" ), wxString::Format( wxT( "%i" ), numAttributes ) );
wxString paramName = wxT( "attr" );
paramName << numAttributes;
aNode->AddAttribute( paramName, aValue ); aNode->AddAttribute( paramName, aValue );
} }
@ -226,6 +232,13 @@ XNODE* CADSTAR_ARCHIVE_PARSER::LoadArchiveFile(
return NULL; return NULL;
} }
bool CADSTAR_ARCHIVE_PARSER::IsValidAttribute( wxXmlAttribute* aAttribute )
{
return aAttribute->GetName() != wxT( "numAttributes" );
}
wxString CADSTAR_ARCHIVE_PARSER::GetXmlAttributeIDString( XNODE* aNode, unsigned int aID ) wxString CADSTAR_ARCHIVE_PARSER::GetXmlAttributeIDString( XNODE* aNode, unsigned int aID )
{ {
wxString attrName, retVal; wxString attrName, retVal;

View File

@ -163,6 +163,13 @@ public:
*/ */
static XNODE* LoadArchiveFile( const wxString& aFileName, const wxString& aFileTypeIdentifier ); static XNODE* LoadArchiveFile( const wxString& aFileName, const wxString& aFileTypeIdentifier );
/**
* @brief
* @param aAttribute
* @return
*/
static bool IsValidAttribute( wxXmlAttribute* aAttribute );
/** /**
* @brief * @brief

View File

@ -79,6 +79,7 @@ void CADSTAR_PCB_ARCHIVE_LOADER::Load( ::BOARD* aBoard )
loadComponentLibrary(); loadComponentLibrary();
loadBoards(); loadBoards();
loadFigures(); loadFigures();
loadTexts();
loadAreas(); loadAreas();
loadComponents(); loadComponents();
loadTemplates(); loadTemplates();
@ -641,6 +642,106 @@ void CADSTAR_PCB_ARCHIVE_LOADER::loadFigures()
} }
} }
void CADSTAR_PCB_ARCHIVE_LOADER::loadTexts()
{
for( std::pair<TEXT_ID, TEXT> txtPair : Layout.Texts )
{
TEXT& csTxt = txtPair.second;
TEXTE_PCB* txt = new TEXTE_PCB( mBoard );
mBoard->Add( txt );
txt->SetText( csTxt.Text );
/*wxPoint rotatedTextPos = getKiCadPoint( aCadstarAttrLoc.Position ) - aModule->GetPosition();
RotatePoint( &rotatedTextPos, -aModule->GetOrientation() );*/
txt->SetTextPos( getKiCadPoint( csTxt.Position ) );
txt->SetPosition( getKiCadPoint( csTxt.Position ) );
txt->SetMirrored( csTxt.Mirror );
txt->SetTextAngle( getAngleTenthDegree( csTxt.OrientAngle ) );
TEXTCODE tc = getTextCode( csTxt.TextCodeID );
txt->SetTextThickness( getKiCadLength( tc.LineWidth ) );
txt->SetTextSize( { getKiCadLength( tc.Width ), getKiCadLength( tc.Height ) } );
switch( csTxt.Alignment )
{
case ALIGNMENT::NO_ALIGNMENT: // Default for Single line text is Bottom Left
case ALIGNMENT::BOTTOMLEFT:
txt->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
break;
case ALIGNMENT::BOTTOMCENTER:
txt->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
break;
case ALIGNMENT::BOTTOMRIGHT:
txt->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
break;
case ALIGNMENT::CENTERLEFT:
txt->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
break;
case ALIGNMENT::CENTERCENTER:
txt->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
break;
case ALIGNMENT::CENTERRIGHT:
txt->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
break;
case ALIGNMENT::TOPLEFT:
txt->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
break;
case ALIGNMENT::TOPCENTER:
txt->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
break;
case ALIGNMENT::TOPRIGHT:
txt->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
txt->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
break;
default:
wxASSERT_MSG( true, "Unknown Aligment - needs review!" );
}
if( isLayerSet( csTxt.LayerID ) )
{
//Make a copy on each layer
LSEQ layers = getKiCadLayerSet( csTxt.LayerID ).Seq();
TEXTE_PCB* newtxt;
for( PCB_LAYER_ID layer : layers )
{
txt->SetLayer( layer );
newtxt = new TEXTE_PCB( *txt );
mBoard->Add( newtxt, ADD_MODE::APPEND );
}
mBoard->Remove( txt );
delete txt;
}
else
txt->SetLayer( getKiCadLayer( csTxt.LayerID ) );
//TODO Handle different font types when KiCad can support it.
}
}
void CADSTAR_PCB_ARCHIVE_LOADER::loadAreas() void CADSTAR_PCB_ARCHIVE_LOADER::loadAreas()
{ {
@ -1851,11 +1952,16 @@ NETINFO_ITEM* CADSTAR_PCB_ARCHIVE_LOADER::getKiCadNet( const NET_ID& aCadstarNet
wxCHECK( Layout.Nets.find( aCadstarNetID ) != Layout.Nets.end(), nullptr ); wxCHECK( Layout.Nets.find( aCadstarNetID ) != Layout.Nets.end(), nullptr );
NET csNet = Layout.Nets.at( aCadstarNetID ); NET csNet = Layout.Nets.at( aCadstarNetID );
wxString newName = wxEmptyString;
if( csNet.Name.IsEmpty() )
newName = "CSNET" + ( csNet.SignalNum );
NETINFO_ITEM* netInfo = new NETINFO_ITEM( mBoard, csNet.Name, ++mNumNets ); NETINFO_ITEM* netInfo = new NETINFO_ITEM( mBoard, csNet.Name, ++mNumNets );
mBoard->Add( netInfo, ADD_MODE::APPEND ); mBoard->Add( netInfo, ADD_MODE::APPEND );
//todo also add the Netclass //todo also add the Netclass
mNetMap.insert( { aCadstarNetID, netInfo } );
return netInfo; return netInfo;
} }

View File

@ -96,6 +96,7 @@ private:
void loadComponentLibrary(); void loadComponentLibrary();
void loadBoards(); void loadBoards();
void loadFigures(); void loadFigures();
void loadTexts();
void loadAreas(); void loadAreas();
void loadComponents(); void loadComponents();
void loadTemplates(); void loadTemplates();

View File

@ -217,7 +217,10 @@ void CADSTAR_PCB_ARCHIVE_PARSER::LAYERDEFS::Parse( XNODE* aNode )
for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() ) for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() )
{ {
LayerStack.push_back( (LAYER_ID) xmlAttribute->GetValue() ); if( !IsValidAttribute( xmlAttribute ) )
continue;
else
LayerStack.push_back( (LAYER_ID) xmlAttribute->GetValue() );
} }
CheckNoChildNodes( cNode ); CheckNoChildNodes( cNode );
@ -1580,6 +1583,9 @@ void CADSTAR_PCB_ARCHIVE_PARSER::COMPONENT_COPPER::Parse( XNODE* aNode )
for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() ) for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() )
{ {
if( !IsValidAttribute( xmlAttribute ) )
continue;
long padId; long padId;
if( !xmlAttribute->GetValue().ToLong( &padId ) ) if( !xmlAttribute->GetValue().ToLong( &padId ) )
@ -1630,6 +1636,9 @@ void CADSTAR_PCB_ARCHIVE_PARSER::COMPONENT_AREA::Parse( XNODE* aNode )
for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() ) for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() )
{ {
if( !IsValidAttribute( xmlAttribute ) )
continue;
if( xmlAttribute->GetValue() == wxT( "NO_TRACKS" ) ) if( xmlAttribute->GetValue() == wxT( "NO_TRACKS" ) )
NoTracks = true; NoTracks = true;
else if( xmlAttribute->GetValue() == wxT( "NO_VIAS" ) ) else if( xmlAttribute->GetValue() == wxT( "NO_VIAS" ) )
@ -1654,6 +1663,9 @@ void CADSTAR_PCB_ARCHIVE_PARSER::PAD_EXITS::Parse( XNODE* aNode )
for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() ) for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() )
{ {
if( !IsValidAttribute( xmlAttribute ) )
continue;
if( xmlAttribute->GetValue() == wxT( "FREE" ) ) if( xmlAttribute->GetValue() == wxT( "FREE" ) )
FreeAngle = true; FreeAngle = true;
else if( xmlAttribute->GetValue() == wxT( "N" ) ) else if( xmlAttribute->GetValue() == wxT( "N" ) )
@ -2391,6 +2403,9 @@ void CADSTAR_PCB_ARCHIVE_PARSER::PART::DEFINITION::PIN_EQUIVALENCE::Parse( XNODE
for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() ) for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() )
{ {
if( !IsValidAttribute( xmlAttribute ) )
continue;
long pinId; long pinId;
if( !xmlAttribute->GetValue().ToLong( &pinId ) ) if( !xmlAttribute->GetValue().ToLong( &pinId ) )
@ -2411,6 +2426,9 @@ void CADSTAR_PCB_ARCHIVE_PARSER::PART::DEFINITION::SWAP_GATE::Parse( XNODE* aNod
for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() ) for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() )
{ {
if( !IsValidAttribute( xmlAttribute ) )
continue;
long pinId; long pinId;
if( !xmlAttribute->GetValue().ToLong( &pinId ) ) if( !xmlAttribute->GetValue().ToLong( &pinId ) )
@ -2636,6 +2654,9 @@ void CADSTAR_PCB_ARCHIVE_PARSER::AREA::Parse( XNODE* aNode )
for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() ) for( ; xmlAttribute; xmlAttribute = xmlAttribute->GetNext() )
{ {
if( !IsValidAttribute( xmlAttribute ) )
continue;
if( xmlAttribute->GetValue() == wxT( "PLACEMENT" ) ) if( xmlAttribute->GetValue() == wxT( "PLACEMENT" ) )
Placement = true; Placement = true;
else if( xmlAttribute->GetValue() == wxT( "ROUTING" ) ) else if( xmlAttribute->GetValue() == wxT( "ROUTING" ) )