From 112da7828ee7f33a18308415f6550a7adb796c1a Mon Sep 17 00:00:00 2001 From: Roberto Fernandez Bautista Date: Sun, 6 Sep 2020 23:16:02 +0100 Subject: [PATCH] CADSTAR PCB Archive Importer: Load Dimensions --- .../cadstar/cadstar_pcb_archive_loader.cpp | 71 ++++++++++++++++++- .../cadstar/cadstar_pcb_archive_loader.h | 1 + 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp index 895ab5367d..5462f10f9e 100644 --- a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp +++ b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.cpp @@ -82,6 +82,7 @@ void CADSTAR_PCB_ARCHIVE_LOADER::Load( ::BOARD* aBoard ) loadBoards(); loadFigures(); loadTexts(); + loadDimensions(); loadAreas(); loadComponents(); loadDocumentationSymbols(); @@ -711,6 +712,74 @@ void CADSTAR_PCB_ARCHIVE_LOADER::loadTexts() } +void CADSTAR_PCB_ARCHIVE_LOADER::loadDimensions() +{ + for( std::pair dimPair : Layout.Dimensions ) + { + DIMENSION& csDim = dimPair.second; + + switch( csDim.Type ) + { + case DIMENSION::TYPE::LINEARDIM: + switch( csDim.Subtype ) + { + case DIMENSION::SUBTYPE::DIRECT: + case DIMENSION::SUBTYPE::ORTHOGONAL: + { + ::DIMENSION* dimension = new ::DIMENSION( mBoard ); + TEXTCODE& dimText = getTextCode( csDim.Text.TextCodeID ); + mBoard->Add( dimension, ADD_MODE::APPEND ); + + dimension->SetLayer( getKiCadLayer( csDim.LayerID ) ); + dimension->SetOrigin( + getKiCadPoint( csDim.Line.Start ), csDim.Precision ); + dimension->SetEnd( getKiCadPoint( csDim.Line.End ), csDim.Precision ); + dimension->Text().SetTextThickness( getKiCadLength( dimText.LineWidth ) ); + dimension->Text().SetTextSize( wxSize( + getKiCadLength( dimText.Width ), getKiCadLength( dimText.Height ) ) ); + + switch( csDim.LinearUnits ) + { + case UNITS::METER: + case UNITS::CENTIMETER: + case UNITS::MM: + case UNITS::MICROMETRE: + dimension->SetUnits( EDA_UNITS::MILLIMETRES, false ); + break; + + case UNITS::INCH: + dimension->SetUnits( EDA_UNITS::INCHES, false ); + break; + + case UNITS::THOU: + dimension->SetUnits( EDA_UNITS::INCHES, true ); + break; + } + + dimension->AdjustDimensionDetails( csDim.Precision ); + } + continue; + + default: //all others + wxLogError( wxString::Format( + _( "Dimension ID %s has no KiCad equivalent. This was not imported" ), + csDim.ID ) ); + break; + } + break; + + case DIMENSION::TYPE::ANGLEDIM: + case DIMENSION::TYPE::LEADERDIM: + default: + wxLogError( wxString::Format( + _( "Dimension ID %s has no KiCad equivalent. This was not imported" ), + csDim.ID ) ); + break; + } + } +} + + void CADSTAR_PCB_ARCHIVE_LOADER::loadAreas() { for( std::pair areaPair : Layout.Areas ) @@ -2383,7 +2452,7 @@ LSET CADSTAR_PCB_ARCHIVE_LOADER::getKiCadLayerSet( const LAYER_ID& aCadstarLayer void CADSTAR_PCB_ARCHIVE_LOADER::addToGroup( const GROUP_ID& aCadstarGroupID, BOARD_ITEM* aKiCadItem ) { - wxCHECK( mGroupMap.find( aCadstarGroupID ) != mGroupMap.end() ); + wxCHECK( mGroupMap.find( aCadstarGroupID ) != mGroupMap.end(), ); PCB_GROUP* parentGroup = mGroupMap.at( aCadstarGroupID ); parentGroup->AddItem( aKiCadItem ); diff --git a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.h b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.h index aa077a6172..817aea1241 100644 --- a/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.h +++ b/pcbnew/plugins/cadstar/cadstar_pcb_archive_loader.h @@ -111,6 +111,7 @@ private: void loadBoards(); void loadFigures(); void loadTexts(); + void loadDimensions(); void loadAreas(); void loadComponents(); void loadDocumentationSymbols();