CADSTAR Schematic Archive Importer: Load Texts

This commit is contained in:
Roberto Fernandez Bautista 2020-09-27 03:35:24 +01:00
parent da791c5298
commit c6bc72d579
2 changed files with 89 additions and 25 deletions

View File

@ -85,6 +85,7 @@ void CADSTAR_SCH_ARCHIVE_LOADER::Load( ::SCHEMATIC* aSchematic, ::SCH_SHEET* aRo
loadBusses();
loadNets();
loadFigures();
loadTexts();
// TODO Load other elements!
// For all sheets, centre all elements and re calculate the page size:
@ -639,23 +640,19 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadFigures()
{
FIGURE fig = figPair.second;
if( fig.LayerID == "ALL_SHEETS" )
{
for( std::pair<LAYER_ID, SHEET_NAME> sheetPair : Sheets.SheetNames )
{
LAYER_ID sheetID = sheetPair.first;
loadFigure( fig, fig.LayerID, LAYER_NOTES );
}
}
loadShapeVertices( fig.Shape.Vertices, fig.LineCodeID, sheetID, LAYER_NOTES );
}
}
else if( fig.LayerID == "NO_SHEET" )
{
continue;
}
else
{
loadShapeVertices( fig.Shape.Vertices, fig.LineCodeID, fig.LayerID, LAYER_NOTES );
}
void CADSTAR_SCH_ARCHIVE_LOADER::loadTexts()
{
for( std::pair<TEXT_ID, TEXT> textPair : Schematic.Texts )
{
TEXT txt = textPair.second;
SCH_TEXT* kiTxt = getKiCadSchText( txt );
loadItemOntoKiCadSheet( txt.LayerID, kiTxt );
}
}
@ -1100,15 +1097,21 @@ void CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices( const std::vector<VERTEX>& a
prev = cur;
if( mSheetMap.find( aCadstarSheetID ) != mSheetMap.end() )
{
mSheetMap.at( aCadstarSheetID )->GetScreen()->Append( segment );
}
else
{
delete segment;
wxASSERT_MSG( false, "Unknown Sheet ID." );
}
loadItemOntoKiCadSheet( aCadstarSheetID, segment );
}
}
void CADSTAR_SCH_ARCHIVE_LOADER::loadFigure( const FIGURE& aCadstarFigure,
const LAYER_ID& aCadstarSheetIDOverride, SCH_LAYER_ID aKiCadSchLayerID )
{
loadShapeVertices( aCadstarFigure.Shape.Vertices, aCadstarFigure.LineCodeID,
aCadstarFigure.LayerID, aKiCadSchLayerID );
for( CUTOUT cutout : aCadstarFigure.Shape.Cutouts )
{
loadShapeVertices( cutout.Vertices, aCadstarFigure.LineCodeID, aCadstarFigure.LayerID,
aKiCadSchLayerID );
}
}
@ -1248,6 +1251,45 @@ int CADSTAR_SCH_ARCHIVE_LOADER::getSheetNumber( LAYER_ID aCadstarSheetID )
}
void CADSTAR_SCH_ARCHIVE_LOADER::loadItemOntoKiCadSheet( LAYER_ID aCadstarSheetID, SCH_ITEM* aItem )
{
wxCHECK_MSG( aItem, /*void*/, "aItem is null" );
if( aCadstarSheetID == "ALL_SHEETS" )
{
SCH_ITEM* duplicateItem;
for( std::pair<LAYER_ID, SHEET_NAME> sheetPair : Sheets.SheetNames )
{
LAYER_ID sheetID = sheetPair.first;
duplicateItem = aItem->Duplicate();
mSheetMap.at( sheetID )->GetScreen()->Append( aItem->Duplicate() );
}
//Get rid of the extra copy:
delete aItem;
aItem = duplicateItem;
}
else if( aCadstarSheetID == "NO_SHEET" )
{
wxASSERT_MSG(
false, "Trying to add an item to NO_SHEET? This might be a documentation symbol." );
}
else
{
if( mSheetMap.find( aCadstarSheetID ) != mSheetMap.end() )
{
mSheetMap.at( aCadstarSheetID )->GetScreen()->Append( aItem );
}
else
{
delete aItem;
wxASSERT_MSG( false, "Unknown Sheet ID." );
}
}
}
CADSTAR_SCH_ARCHIVE_LOADER::SYMDEF_ID CADSTAR_SCH_ARCHIVE_LOADER::getSymDefFromName(
const wxString& aSymdefName, const wxString& aSymDefAlternate )
{
@ -1484,6 +1526,20 @@ void CADSTAR_SCH_ARCHIVE_LOADER::applyTextSettings( const TEXTCODE_ID& aCadstarT
}
}
SCH_TEXT* CADSTAR_SCH_ARCHIVE_LOADER::getKiCadSchText( const TEXT& aCadstarTextElement )
{
SCH_TEXT* kiTxt = new SCH_TEXT();
kiTxt->SetPosition( getKiCadPoint( aCadstarTextElement.Position ) );
kiTxt->SetText( aCadstarTextElement.Text );
applyTextSettings( aCadstarTextElement.TextCodeID, aCadstarTextElement.Alignment,
aCadstarTextElement.Justification, kiTxt );
kiTxt->SetTextAngle( getAngleTenthDegree( aCadstarTextElement.OrientAngle ) );
kiTxt->SetMirrored( aCadstarTextElement.Mirror );
return kiTxt;
}
std::pair<wxPoint, wxSize> CADSTAR_SCH_ARCHIVE_LOADER::getFigureExtentsKiCad(
const FIGURE& aCadstarFigure )

View File

@ -37,10 +37,12 @@ class LABEL_SPIN_STYLE;
class LIB_FIELD;
class LIB_PART;
class SCH_COMPONENT;
class SCH_ITEM;
class SCH_FIELD;
class SCH_GLOBALLABEL;
class SCH_HIERLABEL;
class SCH_SHEET;
class SCH_TEXT;
class SCHEMATIC;
class CADSTAR_SCH_ARCHIVE_LOADER : public CADSTAR_SCH_ARCHIVE_PARSER
@ -100,6 +102,7 @@ private:
void loadBusses();
void loadNets();
void loadFigures();
void loadTexts();
//Helper Functions for loading sheets
void loadSheetAndChildSheets( LAYER_ID aCadstarSheetID, wxPoint aPosition, wxSize aSheetSize,
@ -107,6 +110,7 @@ private:
void loadChildSheets( LAYER_ID aCadstarSheetID );
std::vector<LAYER_ID> findOrphanSheets();
int getSheetNumber( LAYER_ID aCadstarSheetID );
void loadItemOntoKiCadSheet( LAYER_ID aCadstarSheetID, SCH_ITEM* aItem );
//Helper Functions for loading library items
void loadSymDefIntoLibrary( const SYMDEF_ID& aSymdefID, const PART* aCadstarPart,
@ -132,6 +136,8 @@ private:
void loadShapeVertices( const std::vector<VERTEX>& aCadstarVertices,
LINECODE_ID aCadstarLineCodeID, LAYER_ID aCadstarSheetID,
SCH_LAYER_ID aKiCadSchLayerID );
void loadFigure( const FIGURE& aCadstarFigure, const LAYER_ID& aCadstarSheetIDOverride,
SCH_LAYER_ID aKiCadSchLayerID );
//Helper Functions for obtaining CADSTAR elements from the parsed structures
SYMDEF_ID getSymDefFromName( const wxString& aSymdefName, const wxString& aSymDefAlternate );
@ -155,6 +161,8 @@ private:
void applyTextSettings( const TEXTCODE_ID& aCadstarTextCodeID,
const ALIGNMENT& aCadstarAlignment, const JUSTIFICATION& aCadstarJustification,
EDA_TEXT* aKiCadTextItem );
SCH_TEXT* getKiCadSchText( const TEXT& aCadstarTextElement );
std::pair<wxPoint, wxSize> getFigureExtentsKiCad( const FIGURE& aCadstarFigure );