2020-09-08 19:51:22 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-01-31 20:47:36 +00:00
|
|
|
* Copyright (C) 2020-2021 Roberto Fernandez Bautista <roberto.fer.bau@gmail.com>
|
|
|
|
* Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-09-08 19:51:22 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file cadstar_sch_archive_loader.cpp
|
|
|
|
* @brief Loads a csa file into a KiCad SCHEMATIC object
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sch_plugins/cadstar/cadstar_sch_archive_loader.h>
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2020-11-26 18:11:06 +00:00
|
|
|
#include <bus_alias.h>
|
2020-11-18 01:21:04 +00:00
|
|
|
#include <core/mirror.h>
|
2020-09-20 21:08:46 +00:00
|
|
|
#include <eda_text.h>
|
2021-07-18 23:08:54 +00:00
|
|
|
#include <lib_shape.h>
|
2020-09-20 21:08:46 +00:00
|
|
|
#include <lib_text.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <macros.h>
|
2021-09-09 21:15:38 +00:00
|
|
|
#include <progress_reporter.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2020-09-26 13:27:03 +00:00
|
|
|
#include <sch_bus_entry.h>
|
2021-06-10 14:10:55 +00:00
|
|
|
#include <sch_edit_frame.h> //SYMBOL_ORIENTATION_T
|
2020-09-20 21:08:46 +00:00
|
|
|
#include <sch_io_mgr.h>
|
2020-09-23 20:39:11 +00:00
|
|
|
#include <sch_junction.h>
|
|
|
|
#include <sch_line.h>
|
2020-09-19 22:05:02 +00:00
|
|
|
#include <sch_screen.h>
|
|
|
|
#include <sch_sheet.h>
|
2020-11-22 19:55:21 +00:00
|
|
|
#include <sch_sheet_path.h>
|
2021-04-06 21:15:49 +00:00
|
|
|
#include <sch_sheet_pin.h>
|
2020-09-23 20:39:11 +00:00
|
|
|
#include <sch_text.h>
|
2020-09-20 21:08:46 +00:00
|
|
|
#include <schematic.h>
|
2020-09-19 22:05:02 +00:00
|
|
|
#include <trigo.h>
|
2020-09-20 21:08:46 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2020-09-08 19:51:22 +00:00
|
|
|
|
|
|
|
|
2022-02-08 23:14:18 +00:00
|
|
|
const wxString PartNameFieldName = wxT( "Part Name" );
|
2021-02-28 13:28:23 +00:00
|
|
|
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::Load( SCHEMATIC* aSchematic, SCH_SHEET* aRootSheet,
|
2020-10-27 00:25:08 +00:00
|
|
|
SCH_PLUGIN::SCH_PLUGIN_RELEASER* aSchPlugin, const wxFileName& aLibraryFileName )
|
2020-09-08 19:51:22 +00:00
|
|
|
{
|
2021-09-09 21:15:38 +00:00
|
|
|
if( m_progressReporter )
|
|
|
|
m_progressReporter->SetNumPhases( 3 ); // (0) Read file, (1) Parse file, (2) Load file
|
|
|
|
|
2020-09-08 19:51:22 +00:00
|
|
|
Parse();
|
|
|
|
|
2020-09-19 22:05:02 +00:00
|
|
|
LONGPOINT designLimit = Assignments.Settings.DesignLimit;
|
|
|
|
|
|
|
|
//Note: can't use getKiCadPoint() due wxPoint being int - need long long to make the check
|
2021-02-18 18:02:49 +00:00
|
|
|
long long designSizeXkicad = (long long) designLimit.x / KiCadUnitDivider;
|
|
|
|
long long designSizeYkicad = (long long) designLimit.y / KiCadUnitDivider;
|
2020-09-19 22:05:02 +00:00
|
|
|
|
|
|
|
// Max size limited by the positive dimension of wxPoint (which is an int)
|
2020-09-20 21:08:46 +00:00
|
|
|
constexpr long long maxDesignSizekicad = std::numeric_limits<int>::max();
|
2020-09-19 22:05:02 +00:00
|
|
|
|
|
|
|
if( designSizeXkicad > maxDesignSizekicad || designSizeYkicad > maxDesignSizekicad )
|
2020-09-20 21:08:46 +00:00
|
|
|
{
|
2020-09-19 22:05:02 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format(
|
|
|
|
_( "The design is too large and cannot be imported into KiCad. \n"
|
|
|
|
"Please reduce the maximum design size in CADSTAR by navigating to: \n"
|
|
|
|
"Design Tab -> Properties -> Design Options -> Maximum Design Size. \n"
|
|
|
|
"Current Design size: %.2f, %.2f millimeters. \n"
|
|
|
|
"Maximum permitted design size: %.2f, %.2f millimeters.\n" ),
|
|
|
|
(double) designSizeXkicad / SCH_IU_PER_MM,
|
|
|
|
(double) designSizeYkicad / SCH_IU_PER_MM,
|
|
|
|
(double) maxDesignSizekicad / SCH_IU_PER_MM,
|
|
|
|
(double) maxDesignSizekicad / SCH_IU_PER_MM ) );
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
2020-09-19 22:05:02 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
// Assume the center at 0,0 since we are going to be translating the design afterwards anyway
|
2021-02-13 20:00:17 +00:00
|
|
|
m_designCenter = { 0, 0 };
|
2020-09-19 22:05:02 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_schematic = aSchematic;
|
|
|
|
m_rootSheet = aRootSheet;
|
|
|
|
m_plugin = aSchPlugin;
|
|
|
|
m_libraryFileName = aLibraryFileName;
|
2020-09-19 22:05:02 +00:00
|
|
|
|
2021-09-09 21:15:38 +00:00
|
|
|
if( m_progressReporter )
|
|
|
|
{
|
|
|
|
m_progressReporter->BeginPhase( 2 );
|
|
|
|
long numSteps = 11; // one step for each of below functions + one at the end of import
|
|
|
|
|
|
|
|
// Step 4 is by far the longest - add granularity in reporting
|
|
|
|
numSteps += Parts.PartDefinitions.size();
|
|
|
|
|
|
|
|
m_progressReporter->SetMaxProgress( numSteps );
|
|
|
|
}
|
|
|
|
|
2021-04-02 18:50:30 +00:00
|
|
|
loadTextVariables(); // Load text variables right at the start to ensure bounding box
|
|
|
|
// calculations work correctly for text items
|
2021-12-09 00:14:04 +00:00
|
|
|
checkPoint(); // Step 1
|
2020-09-19 22:05:02 +00:00
|
|
|
loadSheets();
|
2021-12-09 00:14:04 +00:00
|
|
|
checkPoint(); // Step 2
|
2020-09-23 20:39:11 +00:00
|
|
|
loadHierarchicalSheetPins();
|
2021-12-09 00:14:04 +00:00
|
|
|
checkPoint(); // Step 3
|
2020-09-20 21:08:46 +00:00
|
|
|
loadPartsLibrary();
|
2021-12-09 00:14:04 +00:00
|
|
|
checkPoint(); // Step 4, Subdivided into extra steps
|
2020-09-20 21:08:46 +00:00
|
|
|
loadSchematicSymbolInstances();
|
2021-12-09 00:14:04 +00:00
|
|
|
checkPoint(); // Step 5
|
2020-09-26 13:27:03 +00:00
|
|
|
loadBusses();
|
2021-12-09 00:14:04 +00:00
|
|
|
checkPoint(); // Step 6
|
2020-09-23 20:39:11 +00:00
|
|
|
loadNets();
|
2021-12-09 00:14:04 +00:00
|
|
|
checkPoint(); // Step 7
|
2020-09-26 18:23:13 +00:00
|
|
|
loadFigures();
|
2021-12-09 00:14:04 +00:00
|
|
|
checkPoint(); // Step 8
|
2020-09-27 02:35:24 +00:00
|
|
|
loadTexts();
|
2021-12-09 00:14:04 +00:00
|
|
|
checkPoint(); // Step 9
|
2020-09-27 12:19:51 +00:00
|
|
|
loadDocumentationSymbols();
|
2021-12-09 00:14:04 +00:00
|
|
|
checkPoint(); // Step 10
|
2020-10-14 11:03:58 +00:00
|
|
|
|
2020-09-27 13:10:59 +00:00
|
|
|
if( Schematic.VariantHierarchy.Variants.size() > 0 )
|
|
|
|
{
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "The CADSTAR design contains variants which has "
|
|
|
|
"no KiCad equivalent. Only the master variant "
|
|
|
|
"('%s') was loaded." ),
|
2022-02-08 23:14:18 +00:00
|
|
|
Schematic.VariantHierarchy.Variants.at( wxT( "V0" ) ).Name ),
|
2021-03-31 21:33:30 +00:00
|
|
|
RPT_SEVERITY_WARNING );
|
2020-09-27 13:10:59 +00:00
|
|
|
}
|
2020-10-14 11:03:58 +00:00
|
|
|
|
2020-09-27 13:10:59 +00:00
|
|
|
if( Schematic.Groups.size() > 0 )
|
|
|
|
{
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( _( "The CADSTAR design contains grouped items which has no KiCad "
|
|
|
|
"equivalent. Any grouped items have been ungrouped." ),
|
|
|
|
RPT_SEVERITY_WARNING );
|
2020-09-27 13:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( Schematic.ReuseBlocks.size() > 0 )
|
|
|
|
{
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( _( "The CADSTAR design contains re-use blocks which has no KiCad "
|
|
|
|
"equivalent. The re-use block information has been discarded during "
|
|
|
|
"the import." ),
|
|
|
|
RPT_SEVERITY_WARNING );
|
2020-09-27 13:10:59 +00:00
|
|
|
}
|
|
|
|
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
// For all sheets, center all elements and re calculate the page size:
|
2021-02-13 20:00:17 +00:00
|
|
|
for( std::pair<LAYER_ID, SCH_SHEET*> sheetPair : m_sheetMap )
|
2020-09-20 21:08:46 +00:00
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = sheetPair.second;
|
|
|
|
|
|
|
|
// Calculate the new sheet size.
|
|
|
|
EDA_RECT sheetBoundingBox;
|
|
|
|
|
|
|
|
for( auto item : sheet->GetScreen()->Items() )
|
2021-02-04 17:48:07 +00:00
|
|
|
{
|
|
|
|
EDA_RECT bbox;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// Only use the visible fields of the symbols to calculate their bounding box
|
2021-02-04 17:48:07 +00:00
|
|
|
// (hidden fields could be very long and artificially enlarge the sheet bounding box)
|
2021-06-10 14:10:55 +00:00
|
|
|
if( item->Type() == SCH_SYMBOL_T )
|
2021-02-17 17:04:19 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* comp = static_cast<SCH_SYMBOL*>( item );
|
2021-09-23 21:07:19 +00:00
|
|
|
bbox = comp->GetBodyAndPinsBoundingBox();
|
2021-02-17 17:04:19 +00:00
|
|
|
|
|
|
|
for( const SCH_FIELD& field : comp->GetFields() )
|
|
|
|
{
|
|
|
|
if( field.IsVisible() )
|
|
|
|
bbox.Merge( field.GetBoundingBox() );
|
|
|
|
}
|
|
|
|
}
|
2021-10-30 20:46:32 +00:00
|
|
|
else if( item->Type() == SCH_TEXT_T )
|
|
|
|
{
|
|
|
|
SCH_TEXT* txtItem = static_cast<SCH_TEXT*>( item );
|
|
|
|
wxString txt = txtItem->GetText();
|
|
|
|
|
2022-02-08 23:14:18 +00:00
|
|
|
if( txt.Contains( wxT( "${" ) ) )
|
2021-10-30 20:46:32 +00:00
|
|
|
continue; // We can't calculate bounding box of text items with variables
|
|
|
|
else
|
|
|
|
bbox = txtItem->GetBoundingBox();
|
|
|
|
}
|
2021-02-04 17:48:07 +00:00
|
|
|
else
|
2021-02-17 17:04:19 +00:00
|
|
|
{
|
2021-02-04 17:48:07 +00:00
|
|
|
bbox = item->GetBoundingBox();
|
2021-02-17 17:04:19 +00:00
|
|
|
}
|
2021-02-04 17:48:07 +00:00
|
|
|
|
|
|
|
sheetBoundingBox.Merge( bbox );
|
|
|
|
}
|
|
|
|
|
2021-02-17 17:02:57 +00:00
|
|
|
// Find the working grid of the original CADSTAR design
|
|
|
|
int grid = Assignments.Grids.WorkingGrid.Param1;
|
|
|
|
|
|
|
|
if( Assignments.Grids.WorkingGrid.Type == GRID_TYPE::FRACTIONALGRID )
|
|
|
|
grid = grid / Assignments.Grids.WorkingGrid.Param2;
|
|
|
|
else if( Assignments.Grids.WorkingGrid.Param2 > grid )
|
|
|
|
grid = Assignments.Grids.WorkingGrid.Param2;
|
|
|
|
|
|
|
|
grid = getKiCadLength( grid );
|
|
|
|
|
|
|
|
auto roundToNearestGrid =
|
|
|
|
[&]( int aNumber ) -> int
|
2021-02-04 17:48:07 +00:00
|
|
|
{
|
2021-02-17 17:02:57 +00:00
|
|
|
int error = aNumber % grid;
|
|
|
|
int absError = sign( error ) * error;
|
2021-02-04 17:48:07 +00:00
|
|
|
|
2021-02-17 17:02:57 +00:00
|
|
|
if( absError > ( grid / 2 ) )
|
|
|
|
return aNumber + ( sign( error ) * grid ) - error;
|
2021-02-04 17:48:07 +00:00
|
|
|
else
|
|
|
|
return aNumber - error;
|
|
|
|
};
|
|
|
|
|
|
|
|
// When exporting to pdf, CADSTAR applies a margin of 3% of the longest dimension (height
|
|
|
|
// or width) to all 4 sides (top, bottom, left right). For the import, we are also rounding
|
2021-02-17 17:02:57 +00:00
|
|
|
// the margin to the nearest grid, ensuring all items remain on the grid.
|
2020-09-20 21:08:46 +00:00
|
|
|
wxSize targetSheetSize = sheetBoundingBox.GetSize();
|
2021-02-04 17:48:07 +00:00
|
|
|
int longestSide = std::max( targetSheetSize.x, targetSheetSize.y );
|
|
|
|
int margin = ( (double) longestSide * 0.03);
|
2021-02-17 17:02:57 +00:00
|
|
|
margin = roundToNearestGrid( margin );
|
2021-02-04 17:48:07 +00:00
|
|
|
targetSheetSize.IncBy( margin * 2, margin * 2 );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2021-02-04 17:48:07 +00:00
|
|
|
// Update page size always
|
2020-09-20 21:08:46 +00:00
|
|
|
PAGE_INFO pageInfo = sheet->GetScreen()->GetPageSettings();
|
2021-02-04 17:48:07 +00:00
|
|
|
pageInfo.SetWidthMils( Iu2Mils( targetSheetSize.x ) );
|
|
|
|
pageInfo.SetHeightMils( Iu2Mils( targetSheetSize.y ) );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
// Set the new sheet size.
|
|
|
|
sheet->GetScreen()->SetPageSettings( pageInfo );
|
|
|
|
|
2021-02-04 17:48:07 +00:00
|
|
|
wxSize pageSizeIU = sheet->GetScreen()->GetPageSettings().GetSizeIU();
|
2020-09-20 21:08:46 +00:00
|
|
|
wxPoint sheetcentre( pageSizeIU.x / 2, pageSizeIU.y / 2 );
|
|
|
|
wxPoint itemsCentre = sheetBoundingBox.Centre();
|
|
|
|
|
2021-02-17 17:02:57 +00:00
|
|
|
// round the translation to nearest point on the grid
|
2020-09-20 21:08:46 +00:00
|
|
|
wxPoint translation = sheetcentre - itemsCentre;
|
2021-02-17 17:02:57 +00:00
|
|
|
translation.x = roundToNearestGrid( translation.x );
|
|
|
|
translation.y = roundToNearestGrid( translation.y );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
// Translate the items.
|
|
|
|
std::vector<SCH_ITEM*> allItems;
|
|
|
|
|
|
|
|
std::copy( sheet->GetScreen()->Items().begin(), sheet->GetScreen()->Items().end(),
|
|
|
|
std::back_inserter( allItems ) );
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : allItems )
|
|
|
|
{
|
2021-10-30 19:12:28 +00:00
|
|
|
item->Move( translation );
|
2020-09-20 21:08:46 +00:00
|
|
|
item->ClearFlags();
|
|
|
|
sheet->GetScreen()->Update( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-09 21:15:38 +00:00
|
|
|
checkPoint();
|
|
|
|
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( _( "The CADSTAR design has been imported successfully.\n"
|
|
|
|
"Please review the import errors and warnings (if any)." ) );
|
2020-09-19 22:05:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::loadSheets()
|
|
|
|
{
|
|
|
|
const std::vector<LAYER_ID>& orphanSheets = findOrphanSheets();
|
2020-11-22 19:55:21 +00:00
|
|
|
SCH_SHEET_PATH rootPath;
|
2021-02-13 20:00:17 +00:00
|
|
|
rootPath.push_back( m_rootSheet );
|
2021-12-08 18:36:23 +00:00
|
|
|
m_rootSheet->AddInstance( rootPath );
|
2021-12-06 12:47:18 +00:00
|
|
|
m_rootSheet->SetPageNumber( rootPath, wxT( "1" ) );
|
2020-09-19 22:05:02 +00:00
|
|
|
|
|
|
|
if( orphanSheets.size() > 1 )
|
|
|
|
{
|
|
|
|
int x = 1;
|
|
|
|
int y = 1;
|
|
|
|
|
|
|
|
for( LAYER_ID sheetID : orphanSheets )
|
|
|
|
{
|
|
|
|
wxPoint pos( x * Mils2iu( 1000 ), y * Mils2iu( 1000 ) );
|
|
|
|
wxSize siz( Mils2iu( 1000 ), Mils2iu( 1000 ) );
|
|
|
|
|
2020-11-22 19:55:21 +00:00
|
|
|
loadSheetAndChildSheets( sheetID, pos, siz, rootPath );
|
2020-09-19 22:05:02 +00:00
|
|
|
|
|
|
|
x += 2;
|
|
|
|
|
|
|
|
if( x > 10 ) // start next row
|
|
|
|
{
|
|
|
|
x = 1;
|
|
|
|
y += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( orphanSheets.size() > 0 )
|
|
|
|
{
|
|
|
|
LAYER_ID rootSheetID = orphanSheets.at( 0 );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
wxFileName loadedFilePath = wxFileName( Filename );
|
|
|
|
|
|
|
|
std::string filename = wxString::Format(
|
2022-02-08 23:14:18 +00:00
|
|
|
wxT( "%s_%02d" ), loadedFilePath.GetName(), getSheetNumber( rootSheetID ) )
|
2020-09-20 21:08:46 +00:00
|
|
|
.ToStdString();
|
|
|
|
ReplaceIllegalFileNameChars( &filename );
|
|
|
|
filename += wxT( "." ) + KiCadSchematicFileExtension;
|
|
|
|
|
2021-05-28 16:06:22 +00:00
|
|
|
wxFileName fn( m_schematic->Prj().GetProjectPath() + filename );
|
2021-02-13 20:00:17 +00:00
|
|
|
m_rootSheet->GetScreen()->SetFileName( fn.GetFullPath() );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_sheetMap.insert( { rootSheetID, m_rootSheet } );
|
2020-11-22 19:55:21 +00:00
|
|
|
loadChildSheets( rootSheetID, rootPath );
|
2020-09-19 22:05:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( _( "The CADSTAR schematic might be corrupt: there is no root sheet." ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-23 20:39:11 +00:00
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::loadHierarchicalSheetPins()
|
|
|
|
{
|
|
|
|
for( std::pair<BLOCK_ID, BLOCK> blockPair : Schematic.Blocks )
|
|
|
|
{
|
|
|
|
BLOCK& block = blockPair.second;
|
|
|
|
LAYER_ID sheetID = "";
|
|
|
|
|
|
|
|
if( block.Type == BLOCK::TYPE::PARENT )
|
|
|
|
sheetID = block.LayerID;
|
|
|
|
else if( block.Type == BLOCK::TYPE::CHILD )
|
|
|
|
sheetID = block.AssocLayerID;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
if( m_sheetMap.find( sheetID ) != m_sheetMap.end() )
|
2020-09-23 20:39:11 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
SCH_SHEET* sheet = m_sheetMap.at( sheetID );
|
2020-09-23 20:39:11 +00:00
|
|
|
|
|
|
|
for( std::pair<TERMINAL_ID, TERMINAL> termPair : block.Terminals )
|
|
|
|
{
|
|
|
|
TERMINAL term = termPair.second;
|
2022-02-08 23:14:18 +00:00
|
|
|
wxString name = wxT( "YOU SHOULDN'T SEE THIS TEXT. THIS IS A BUG." );
|
2020-09-23 20:39:11 +00:00
|
|
|
|
|
|
|
SCH_HIERLABEL* sheetPin = nullptr;
|
|
|
|
|
|
|
|
if( block.Type == BLOCK::TYPE::PARENT )
|
|
|
|
sheetPin = new SCH_HIERLABEL();
|
|
|
|
else if( block.Type == BLOCK::TYPE::CHILD )
|
|
|
|
sheetPin = new SCH_SHEET_PIN( sheet );
|
|
|
|
|
|
|
|
sheetPin->SetText( name );
|
|
|
|
sheetPin->SetShape( PINSHEETLABEL_SHAPE::PS_UNSPECIFIED );
|
|
|
|
sheetPin->SetLabelSpinStyle( getSpinStyle( term.OrientAngle, false ) );
|
|
|
|
sheetPin->SetPosition( getKiCadPoint( term.Position ) );
|
|
|
|
|
|
|
|
if( sheetPin->Type() == SCH_SHEET_PIN_T )
|
|
|
|
sheet->AddPin( (SCH_SHEET_PIN*) sheetPin );
|
|
|
|
else
|
|
|
|
sheet->GetScreen()->Append( sheetPin );
|
|
|
|
|
|
|
|
BLOCK_PIN_ID blockPinID = std::make_pair( block.ID, term.ID );
|
2021-02-13 20:00:17 +00:00
|
|
|
m_sheetPinMap.insert( { blockPinID, sheetPin } );
|
2020-09-23 20:39:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-20 21:08:46 +00:00
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::loadPartsLibrary()
|
|
|
|
{
|
|
|
|
for( std::pair<PART_ID, PART> partPair : Parts.PartDefinitions )
|
|
|
|
{
|
2021-03-28 18:47:48 +00:00
|
|
|
PART_ID partID = partPair.first;
|
2020-09-20 21:08:46 +00:00
|
|
|
PART part = partPair.second;
|
|
|
|
|
2021-09-01 19:24:59 +00:00
|
|
|
wxString escapedPartName = EscapeString( part.Name, CTX_LIBID );
|
|
|
|
LIB_SYMBOL* kiPart = new LIB_SYMBOL( escapedPartName );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
kiPart->SetUnitCount( part.Definition.GateSymbols.size() );
|
2021-03-28 18:47:48 +00:00
|
|
|
bool ok = true;
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
for( std::pair<GATE_ID, PART::DEFINITION::GATE> gatePair : part.Definition.GateSymbols )
|
|
|
|
{
|
|
|
|
GATE_ID gateID = gatePair.first;
|
|
|
|
PART::DEFINITION::GATE gate = gatePair.second;
|
|
|
|
SYMDEF_ID symbolID = getSymDefFromName( gate.Name, gate.Alternate );
|
|
|
|
|
|
|
|
if( symbolID.IsEmpty() )
|
|
|
|
{
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Part definition '%s' references symbol "
|
|
|
|
"'%s' (alternate '%s') which could not be "
|
|
|
|
"found in the symbol library. The part has "
|
|
|
|
"not been loaded into the KiCad library." ),
|
|
|
|
part.Name,
|
|
|
|
gate.Name,
|
|
|
|
gate.Alternate ),
|
|
|
|
RPT_SEVERITY_WARNING);
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2021-03-28 18:47:48 +00:00
|
|
|
ok = false;
|
|
|
|
break;
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
|
2022-06-15 18:47:29 +00:00
|
|
|
m_partSymbolsMap.insert( { { partID, gateID }, symbolID } );
|
2020-09-20 21:08:46 +00:00
|
|
|
loadSymDefIntoLibrary( symbolID, &part, gateID, kiPart );
|
|
|
|
}
|
|
|
|
|
2022-06-15 18:47:29 +00:00
|
|
|
if( ok && part.Definition.GateSymbols.size() != 0 )
|
2021-03-28 18:47:48 +00:00
|
|
|
{
|
|
|
|
( *m_plugin )->SaveSymbol( m_libraryFileName.GetFullPath(), kiPart );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* loadedPart =
|
2021-03-28 18:47:48 +00:00
|
|
|
( *m_plugin )->LoadSymbol( m_libraryFileName.GetFullPath(), kiPart->GetName() );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2021-03-28 18:47:48 +00:00
|
|
|
m_partMap.insert( { partID, loadedPart } );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-01 10:00:36 +00:00
|
|
|
// We can't add new strings onto 6.0 branch, so no error reporting
|
|
|
|
|
2022-06-15 18:47:29 +00:00
|
|
|
|
2021-03-28 18:47:48 +00:00
|
|
|
// Don't save in the library, but still keep it cached as some of the units might have
|
2022-06-15 18:47:29 +00:00
|
|
|
// been loaded correctly (saving us time later on), plus the part definition contains
|
|
|
|
// the part name, which is important to load
|
2021-03-28 18:47:48 +00:00
|
|
|
m_partMap.insert( { partID, kiPart } );
|
|
|
|
}
|
2021-09-09 21:15:38 +00:00
|
|
|
|
|
|
|
checkPoint();
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbolInstances()
|
|
|
|
{
|
|
|
|
for( std::pair<SYMBOL_ID, SYMBOL> symPair : Schematic.Symbols )
|
|
|
|
{
|
|
|
|
SYMBOL sym = symPair.second;
|
|
|
|
|
2020-11-21 12:55:58 +00:00
|
|
|
if( !sym.VariantID.empty() && sym.VariantParentSymbolID != sym.ID )
|
|
|
|
continue; // Only load master Variant
|
|
|
|
|
2020-09-20 21:08:46 +00:00
|
|
|
if( sym.IsComponent )
|
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
if( m_partMap.find( sym.PartRef.RefID ) == m_partMap.end() )
|
2020-09-20 21:08:46 +00:00
|
|
|
{
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Symbol '%s' references part '%s' which "
|
|
|
|
"could not be found in the library. The "
|
|
|
|
"symbol was not loaded" ),
|
|
|
|
sym.ComponentRef.Designator,
|
|
|
|
sym.PartRef.RefID ),
|
|
|
|
RPT_SEVERITY_ERROR);
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-03-29 15:00:28 +00:00
|
|
|
if( sym.GateID.IsEmpty() )
|
|
|
|
sym.GateID = wxT( "A" ); // Assume Gate "A" if unspecified
|
|
|
|
|
2021-03-28 18:47:48 +00:00
|
|
|
PART_GATE_ID partSymbolID = { sym.PartRef.RefID, sym.GateID };
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* kiPart = m_partMap.at( sym.PartRef.RefID );
|
2021-03-28 18:47:48 +00:00
|
|
|
bool copy = false;
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2021-03-28 18:47:48 +00:00
|
|
|
// The symbol definition in the part either does not exist for this gate number
|
|
|
|
// or is different to the symbol instance. We need to load a new symbol
|
|
|
|
if( m_partSymbolsMap.find( partSymbolID ) == m_partSymbolsMap.end()
|
|
|
|
|| m_partSymbolsMap.at( partSymbolID ) != sym.SymdefID )
|
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
kiPart = new LIB_SYMBOL( *kiPart ); // Make a copy
|
2021-03-28 18:47:48 +00:00
|
|
|
copy = true;
|
|
|
|
const PART& part = Parts.PartDefinitions.at( sym.PartRef.RefID );
|
|
|
|
loadSymDefIntoLibrary( sym.SymdefID, &part, sym.GateID, kiPart );
|
|
|
|
}
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* scaledPart = getScaledLibPart( kiPart, sym.ScaleRatioNumerator,
|
2021-07-16 20:13:26 +00:00
|
|
|
sym.ScaleRatioDenominator );
|
2021-05-28 15:19:04 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
double symOrientDeciDeg = 0.0;
|
|
|
|
SCH_SYMBOL* symbol = loadSchematicSymbol( sym, *scaledPart, symOrientDeciDeg );
|
2021-05-28 15:19:04 +00:00
|
|
|
|
|
|
|
delete scaledPart;
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2021-03-28 18:47:48 +00:00
|
|
|
if( copy )
|
|
|
|
delete kiPart;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_FIELD* refField = symbol->GetField( REFERENCE_FIELD );
|
2021-01-27 00:09:58 +00:00
|
|
|
|
|
|
|
sym.ComponentRef.Designator.Replace( wxT( "\n" ), wxT( "\\n" ) );
|
|
|
|
sym.ComponentRef.Designator.Replace( wxT( "\r" ), wxT( "\\r" ) );
|
|
|
|
sym.ComponentRef.Designator.Replace( wxT( "\t" ), wxT( "\\t" ) );
|
|
|
|
sym.ComponentRef.Designator.Replace( wxT( " " ), wxT( "_" ) );
|
|
|
|
|
2020-09-20 21:08:46 +00:00
|
|
|
refField->SetText( sym.ComponentRef.Designator );
|
2021-01-27 00:09:58 +00:00
|
|
|
loadSymbolFieldAttribute( sym.ComponentRef.AttrLoc, symOrientDeciDeg,
|
|
|
|
sym.Mirror, refField );
|
|
|
|
|
|
|
|
if( sym.HasPartRef )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_FIELD* partField = symbol->FindField( PartNameFieldName );
|
2021-01-27 00:09:58 +00:00
|
|
|
|
|
|
|
if( !partField )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
int fieldID = symbol->GetFieldCount();
|
|
|
|
partField = symbol->AddField( SCH_FIELD( wxPoint(), fieldID, symbol,
|
|
|
|
PartNameFieldName ) );
|
2021-01-27 00:09:58 +00:00
|
|
|
}
|
|
|
|
|
2021-03-28 18:03:11 +00:00
|
|
|
wxASSERT( partField->GetName() == PartNameFieldName );
|
|
|
|
|
2021-01-27 00:09:58 +00:00
|
|
|
wxString partname = getPart( sym.PartRef.RefID ).Name;
|
|
|
|
partname.Replace( wxT( "\n" ), wxT( "\\n" ) );
|
|
|
|
partname.Replace( wxT( "\r" ), wxT( "\\r" ) );
|
|
|
|
partname.Replace( wxT( "\t" ), wxT( "\\t" ) );
|
|
|
|
partField->SetText( partname );
|
|
|
|
|
|
|
|
loadSymbolFieldAttribute( sym.PartRef.AttrLoc, symOrientDeciDeg,
|
|
|
|
sym.Mirror, partField );
|
2021-02-02 13:39:40 +00:00
|
|
|
|
|
|
|
partField->SetVisible( SymbolPartNameColor.IsVisible );
|
2021-01-27 00:09:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( auto attr : sym.AttributeValues )
|
|
|
|
{
|
|
|
|
ATTRIBUTE_VALUE attrVal = attr.second;
|
|
|
|
|
|
|
|
if( attrVal.HasLocation )
|
|
|
|
{
|
|
|
|
wxString attrName = getAttributeName( attrVal.AttributeID );
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_FIELD* attrField = symbol->FindField( attrName );
|
2021-01-27 00:09:58 +00:00
|
|
|
|
|
|
|
if( !attrField )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
int fieldID = symbol->GetFieldCount();
|
|
|
|
attrField = symbol->AddField( SCH_FIELD( wxPoint(), fieldID,
|
|
|
|
symbol, attrName ) );
|
2021-01-27 00:09:58 +00:00
|
|
|
}
|
|
|
|
|
2021-03-28 18:03:11 +00:00
|
|
|
wxASSERT( attrField->GetName() == attrName );
|
|
|
|
|
2021-01-27 00:09:58 +00:00
|
|
|
attrVal.Value.Replace( wxT( "\n" ), wxT( "\\n" ) );
|
|
|
|
attrVal.Value.Replace( wxT( "\r" ), wxT( "\\r" ) );
|
|
|
|
attrVal.Value.Replace( wxT( "\t" ), wxT( "\\t" ) );
|
|
|
|
attrField->SetText( attrVal.Value );
|
|
|
|
|
|
|
|
loadSymbolFieldAttribute( attrVal.AttributeLocation, symOrientDeciDeg,
|
|
|
|
sym.Mirror, attrField );
|
|
|
|
attrField->SetVisible( isAttributeVisible( attrVal.AttributeID ) );
|
|
|
|
}
|
|
|
|
}
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
else if( sym.IsSymbolVariant )
|
|
|
|
{
|
|
|
|
if( Library.SymbolDefinitions.find( sym.SymdefID ) == Library.SymbolDefinitions.end() )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format(
|
|
|
|
_( "Symbol ID '%s' references library symbol '%s' which could not be "
|
|
|
|
"found in the library. Did you export all items of the design?" ),
|
|
|
|
sym.ID, sym.PartRef.RefID ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
SYMDEF_SCM libSymDef = Library.SymbolDefinitions.at( sym.SymdefID );
|
|
|
|
|
|
|
|
if( libSymDef.Terminals.size() != 1 )
|
|
|
|
{
|
|
|
|
THROW_IO_ERROR( wxString::Format(
|
|
|
|
_( "Symbol ID '%s' is a signal reference or global signal but it has too "
|
|
|
|
"many pins. The expected number of pins is 1 but %d were found." ),
|
|
|
|
sym.ID, libSymDef.Terminals.size() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( sym.SymbolVariant.Type == SYMBOLVARIANT::TYPE::GLOBALSIGNAL )
|
|
|
|
{
|
2020-09-23 20:39:11 +00:00
|
|
|
SYMDEF_ID symID = sym.SymdefID;
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* kiPart = nullptr;
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2021-02-26 18:37:59 +00:00
|
|
|
// In CADSTAR "GlobalSignal" is a special type of symbol which defines
|
|
|
|
// a Power Symbol. The "Alternate" name defines the default net name of
|
2021-06-09 19:32:58 +00:00
|
|
|
// the power symbol but this can be overridden in the design itself.
|
2021-02-26 18:37:59 +00:00
|
|
|
wxString libraryNetName = Library.SymbolDefinitions.at( symID ).Alternate;
|
|
|
|
|
|
|
|
// Name of the net that the symbol instance in CADSTAR refers to:
|
|
|
|
wxString symbolInstanceNetName = sym.SymbolVariant.Reference;
|
2021-06-30 10:53:04 +00:00
|
|
|
symbolInstanceNetName = EscapeString( symbolInstanceNetName, CTX_LIBID );
|
2021-02-26 18:37:59 +00:00
|
|
|
|
|
|
|
// Name of the symbol we will use for saving the part in KiCad
|
|
|
|
// Note: In CADSTAR all power symbols will start have the reference name be
|
|
|
|
// "GLOBALSIGNAL" followed by the default net name, so it makes sense to save
|
|
|
|
// the symbol in KiCad as the default net name as well.
|
|
|
|
wxString libPartName = libraryNetName;
|
|
|
|
|
|
|
|
// In CADSTAR power symbol instances can refer to a different net to that defined
|
|
|
|
// in the library. This causes problems in KiCad v6 as it breaks connectivity when
|
|
|
|
// the user decides to update all symbols from library. We handle this by creating
|
|
|
|
// individual versions of the power symbol for each net name.
|
|
|
|
if( libPartName != symbolInstanceNetName )
|
|
|
|
{
|
|
|
|
libPartName += wxT( " (" ) + symbolInstanceNetName + wxT( ")" );
|
|
|
|
}
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2021-02-26 18:37:59 +00:00
|
|
|
if( m_powerSymLibMap.find( libPartName ) == m_powerSymLibMap.end() )
|
2020-09-20 21:08:46 +00:00
|
|
|
{
|
2021-02-26 18:37:59 +00:00
|
|
|
SYMDEF_SCM symbolDef = Library.SymbolDefinitions.at( symID );
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
kiPart = new LIB_SYMBOL( libPartName );
|
2020-09-20 21:08:46 +00:00
|
|
|
kiPart->SetPower();
|
2022-02-08 23:14:18 +00:00
|
|
|
loadSymDefIntoLibrary( symID, nullptr, wxT( "A" ), kiPart );
|
2020-09-23 20:39:11 +00:00
|
|
|
|
2021-02-26 18:37:59 +00:00
|
|
|
kiPart->GetValueField().SetText( symbolInstanceNetName );
|
2020-09-23 20:39:11 +00:00
|
|
|
|
|
|
|
if( symbolDef.TextLocations.find( SIGNALNAME_ORIGIN_ATTRID )
|
|
|
|
!= symbolDef.TextLocations.end() )
|
|
|
|
{
|
2021-02-26 18:37:59 +00:00
|
|
|
TEXT_LOCATION txtLoc =
|
2020-09-23 20:39:11 +00:00
|
|
|
symbolDef.TextLocations.at( SIGNALNAME_ORIGIN_ATTRID );
|
2021-02-26 18:37:59 +00:00
|
|
|
|
|
|
|
wxPoint valPos = getKiCadLibraryPoint( txtLoc.Position, symbolDef.Origin );
|
|
|
|
|
|
|
|
kiPart->GetValueField().SetPosition( valPos );
|
2021-02-02 13:39:40 +00:00
|
|
|
kiPart->GetValueField().SetVisible( true );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
kiPart->GetValueField().SetVisible( false );
|
2020-09-23 20:39:11 +00:00
|
|
|
}
|
|
|
|
|
2022-02-08 23:14:18 +00:00
|
|
|
kiPart->GetReferenceField().SetText( wxT( "#PWR" ) );
|
2021-02-02 13:39:40 +00:00
|
|
|
kiPart->GetReferenceField().SetVisible( false );
|
2021-02-13 20:00:17 +00:00
|
|
|
( *m_plugin )->SaveSymbol( m_libraryFileName.GetFullPath(), kiPart );
|
2021-02-26 18:37:59 +00:00
|
|
|
m_powerSymLibMap.insert( { libPartName, kiPart } );
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-26 18:37:59 +00:00
|
|
|
kiPart = m_powerSymLibMap.at( libPartName );
|
|
|
|
wxASSERT( kiPart->GetValueField().GetText() == symbolInstanceNetName );
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* scaledPart = getScaledLibPart( kiPart, sym.ScaleRatioNumerator,
|
|
|
|
sym.ScaleRatioDenominator );
|
2021-05-28 15:19:04 +00:00
|
|
|
|
|
|
|
double returnedOrient = 0.0;
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = loadSchematicSymbol( sym, *scaledPart, returnedOrient );
|
|
|
|
m_powerSymMap.insert( { sym.ID, symbol } );
|
2021-05-28 15:19:04 +00:00
|
|
|
|
|
|
|
delete scaledPart;
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
else if( sym.SymbolVariant.Type == SYMBOLVARIANT::TYPE::SIGNALREF )
|
|
|
|
{
|
|
|
|
// There should only be one pin and we'll use that to set the position
|
2021-02-04 17:51:27 +00:00
|
|
|
TERMINAL& symbolTerminal = libSymDef.Terminals.begin()->second;
|
2020-09-20 21:08:46 +00:00
|
|
|
wxPoint terminalPosOffset = symbolTerminal.Position - libSymDef.Origin;
|
2021-02-04 17:51:27 +00:00
|
|
|
double rotateDeciDegree = getAngleTenthDegree( sym.OrientAngle );
|
|
|
|
|
|
|
|
if( sym.Mirror )
|
|
|
|
rotateDeciDegree += 1800.0;
|
|
|
|
|
|
|
|
RotatePoint( &terminalPosOffset, -rotateDeciDegree );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
SCH_GLOBALLABEL* netLabel = new SCH_GLOBALLABEL;
|
|
|
|
netLabel->SetPosition( getKiCadPoint( sym.Origin + terminalPosOffset ) );
|
2022-02-08 23:14:18 +00:00
|
|
|
netLabel->SetText( wxT( "***UNKNOWN NET****" ) ); // This should be later updated when we load the netlist
|
2020-09-20 21:08:46 +00:00
|
|
|
netLabel->SetTextSize( wxSize( Mils2iu( 50 ), Mils2iu( 50 ) ) );
|
2021-09-01 19:12:56 +00:00
|
|
|
|
|
|
|
SYMDEF_SCM symbolDef = Library.SymbolDefinitions.at( sym.SymdefID );
|
|
|
|
|
|
|
|
if( symbolDef.TextLocations.count( LINK_ORIGIN_ATTRID ) )
|
|
|
|
{
|
|
|
|
TEXT_LOCATION linkOrigin = symbolDef.TextLocations.at( LINK_ORIGIN_ATTRID );
|
|
|
|
applyTextSettings( netLabel, linkOrigin.TextCodeID, linkOrigin.Alignment,
|
|
|
|
linkOrigin.Justification );
|
|
|
|
}
|
|
|
|
|
2020-09-20 21:08:46 +00:00
|
|
|
netLabel->SetLabelSpinStyle( getSpinStyle( sym.OrientAngle, sym.Mirror ) );
|
|
|
|
|
2022-02-08 23:14:18 +00:00
|
|
|
if( libSymDef.Alternate.Lower().Contains( wxT( "in" ) ) )
|
2020-09-20 21:08:46 +00:00
|
|
|
netLabel->SetShape( PINSHEETLABEL_SHAPE::PS_INPUT );
|
2022-02-08 23:14:18 +00:00
|
|
|
else if( libSymDef.Alternate.Lower().Contains( wxT( "bi" ) ) )
|
2020-09-20 21:08:46 +00:00
|
|
|
netLabel->SetShape( PINSHEETLABEL_SHAPE::PS_BIDI );
|
2022-02-08 23:14:18 +00:00
|
|
|
else if( libSymDef.Alternate.Lower().Contains( wxT( "out" ) ) )
|
2020-09-20 21:08:46 +00:00
|
|
|
netLabel->SetShape( PINSHEETLABEL_SHAPE::PS_OUTPUT );
|
|
|
|
else
|
|
|
|
netLabel->SetShape( PINSHEETLABEL_SHAPE::PS_UNSPECIFIED );
|
|
|
|
|
2021-10-30 19:12:28 +00:00
|
|
|
SCH_SCREEN* screen = m_sheetMap.at( sym.LayerID )->GetScreen();
|
|
|
|
|
|
|
|
// autoplace intersheet refs
|
|
|
|
netLabel->AutoplaceFields( screen, false );
|
|
|
|
|
|
|
|
screen->Append( netLabel );
|
2021-02-13 20:00:17 +00:00
|
|
|
m_globalLabelsMap.insert( { sym.ID, netLabel } );
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-08 23:14:18 +00:00
|
|
|
wxASSERT_MSG( false, wxT( "Unknown Symbol Variant." ) );
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Symbol ID '%s' is of an unknown type. It is "
|
2021-06-10 14:10:55 +00:00
|
|
|
"neither a symbol or a net power / symbol. "
|
2021-03-31 21:33:30 +00:00
|
|
|
"The symbol was not loaded." ),
|
|
|
|
sym.ID ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
2020-11-23 20:54:34 +00:00
|
|
|
|
|
|
|
if( sym.ScaleRatioDenominator != 1 || sym.ScaleRatioNumerator != 1 )
|
|
|
|
{
|
|
|
|
wxString symbolName = sym.ComponentRef.Designator;
|
|
|
|
|
|
|
|
if( symbolName.empty() )
|
2022-02-08 23:14:18 +00:00
|
|
|
symbolName = wxString::Format( wxT( "ID: %s" ), sym.ID );
|
2021-10-30 19:11:49 +00:00
|
|
|
else
|
|
|
|
symbolName += sym.GateID;
|
2020-11-23 20:54:34 +00:00
|
|
|
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Symbol '%s' is scaled in the original "
|
|
|
|
"CADSTAR schematic but this is not supported "
|
2021-05-28 15:19:04 +00:00
|
|
|
"in KiCad. When the symbol is reloaded from "
|
|
|
|
"the library, it will revert to the original "
|
|
|
|
"1:1 scale." ),
|
2021-03-31 21:33:30 +00:00
|
|
|
symbolName,
|
|
|
|
sym.PartRef.RefID ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
2020-11-23 20:54:34 +00:00
|
|
|
}
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-26 13:27:03 +00:00
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::loadBusses()
|
|
|
|
{
|
|
|
|
for( std::pair<BUS_ID, BUS> busPair : Schematic.Buses )
|
|
|
|
{
|
|
|
|
BUS bus = busPair.second;
|
|
|
|
bool firstPt = true;
|
|
|
|
VERTEX last;
|
|
|
|
|
2020-11-26 18:11:06 +00:00
|
|
|
if( bus.LayerID != wxT( "NO_SHEET" ) )
|
2020-09-26 13:27:03 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
SCH_SCREEN* screen = m_sheetMap.at( bus.LayerID )->GetScreen();
|
2020-11-26 18:11:06 +00:00
|
|
|
std::shared_ptr<BUS_ALIAS> kiBusAlias = std::make_shared<BUS_ALIAS>();
|
|
|
|
|
|
|
|
kiBusAlias->SetName( bus.Name );
|
|
|
|
kiBusAlias->SetParent( screen );
|
|
|
|
screen->AddBusAlias( kiBusAlias );
|
2021-02-13 20:00:17 +00:00
|
|
|
m_busesMap.insert( { bus.ID, kiBusAlias } );
|
2020-11-26 18:11:06 +00:00
|
|
|
|
|
|
|
SCH_LABEL* label = new SCH_LABEL();
|
2021-09-01 18:24:42 +00:00
|
|
|
|
|
|
|
wxString busname = HandleTextOverbar( bus.Name );
|
|
|
|
|
|
|
|
label->SetText( wxT( "{" ) + busname + wxT( "}" ) );
|
2020-11-26 18:11:06 +00:00
|
|
|
label->SetVisible( true );
|
|
|
|
screen->Append( label );
|
2020-09-26 13:27:03 +00:00
|
|
|
|
2020-11-26 18:11:06 +00:00
|
|
|
SHAPE_LINE_CHAIN busLineChain; // to compute nearest segment to bus label
|
|
|
|
|
|
|
|
for( const VERTEX& cur : bus.Shape.Vertices )
|
2020-09-26 13:27:03 +00:00
|
|
|
{
|
2020-11-26 18:11:06 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-26 13:27:03 +00:00
|
|
|
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 ) );
|
2020-11-26 18:11:06 +00:00
|
|
|
screen->Append( kiBus );
|
2020-09-26 13:27:03 +00:00
|
|
|
|
|
|
|
last = cur;
|
2020-11-26 18:11:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
2020-09-26 13:27:03 +00:00
|
|
|
|
2020-11-26 18:11:06 +00:00
|
|
|
label->SetPosition( nearestPt );
|
2021-04-02 18:50:30 +00:00
|
|
|
|
|
|
|
applyTextSettings( label,
|
|
|
|
bus.BusLabel.TextCodeID,
|
|
|
|
bus.BusLabel.Alignment,
|
|
|
|
bus.BusLabel.Justification );
|
|
|
|
|
2021-09-01 18:24:42 +00:00
|
|
|
// Re-set bus name as it might have been "double-escaped" after applyTextSettings
|
|
|
|
label->SetText( wxT( "{" ) + busname + wxT( "}" ) );
|
|
|
|
|
2021-04-02 18:50:30 +00:00
|
|
|
// Note orientation of the bus label will be determined in loadNets
|
|
|
|
// (the position of the wire will determine how best to place the bus label)
|
2020-09-26 13:27:03 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-26 18:11:06 +00:00
|
|
|
|
2020-09-26 13:27:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-23 20:39:11 +00:00
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::loadNets()
|
|
|
|
{
|
|
|
|
for( std::pair<NET_ID, NET_SCH> netPair : Schematic.Nets )
|
|
|
|
{
|
2020-09-26 13:27:03 +00:00
|
|
|
NET_SCH net = netPair.second;
|
|
|
|
wxString netName = net.Name;
|
|
|
|
std::map<NETELEMENT_ID, SCH_LABEL*> netlabels;
|
2020-09-23 20:39:11 +00:00
|
|
|
|
|
|
|
if( netName.IsEmpty() )
|
2022-02-08 23:14:18 +00:00
|
|
|
netName = wxString::Format( wxT( "$%ld" ), net.SignalNum );
|
2020-09-23 20:39:11 +00:00
|
|
|
|
2021-09-01 18:24:42 +00:00
|
|
|
netName = HandleTextOverbar( netName );
|
2020-09-23 20:39:11 +00:00
|
|
|
|
|
|
|
for( std::pair<NETELEMENT_ID, NET_SCH::SYM_TERM> terminalPair : net.Terminals )
|
|
|
|
{
|
|
|
|
NET_SCH::SYM_TERM netTerm = terminalPair.second;
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
if( m_powerSymMap.find( netTerm.SymbolID ) != m_powerSymMap.end() )
|
2020-09-23 20:39:11 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
SCH_FIELD* val = m_powerSymMap.at( netTerm.SymbolID )->GetField( VALUE_FIELD );
|
2020-12-29 23:38:51 +00:00
|
|
|
val->SetText( netName );
|
|
|
|
val->SetBold( false );
|
|
|
|
val->SetVisible( false );
|
|
|
|
|
|
|
|
if( netTerm.HasNetLabel )
|
2020-09-23 20:39:11 +00:00
|
|
|
{
|
2020-12-29 23:38:51 +00:00
|
|
|
val->SetVisible( true );
|
2020-09-23 20:39:11 +00:00
|
|
|
val->SetPosition( getKiCadPoint( netTerm.NetLabel.Position ) );
|
|
|
|
|
2021-04-02 18:50:30 +00:00
|
|
|
applyTextSettings( val,
|
|
|
|
netTerm.NetLabel.TextCodeID,
|
|
|
|
netTerm.NetLabel.Alignment,
|
|
|
|
netTerm.NetLabel.Justification,
|
|
|
|
netTerm.NetLabel.OrientAngle,
|
|
|
|
netTerm.NetLabel.Mirror );
|
2020-09-23 20:39:11 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-13 20:00:17 +00:00
|
|
|
else if( m_globalLabelsMap.find( netTerm.SymbolID ) != m_globalLabelsMap.end() )
|
2020-12-29 23:38:51 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
m_globalLabelsMap.at( netTerm.SymbolID )->SetText( netName );
|
2021-10-30 19:12:28 +00:00
|
|
|
|
|
|
|
LAYER_ID sheet = Schematic.Symbols.at( netTerm.SymbolID ).LayerID;
|
|
|
|
|
|
|
|
if( m_sheetMap.count( sheet ) )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = m_sheetMap.at( sheet )->GetScreen();
|
|
|
|
|
|
|
|
// autoplace intersheet refs again since we've changed the name
|
|
|
|
m_globalLabelsMap.at( netTerm.SymbolID )->AutoplaceFields( screen, false );
|
|
|
|
}
|
2020-12-29 23:38:51 +00:00
|
|
|
}
|
2021-10-11 17:29:17 +00:00
|
|
|
else if( !net.Name.IsEmpty() && Schematic.Symbols.count( netTerm.SymbolID )
|
|
|
|
&& netTerm.HasNetLabel )
|
|
|
|
{
|
|
|
|
// This is a named net that connects to a schematic symbol pin - we need to put a label
|
|
|
|
SCH_LABEL* label = new SCH_LABEL();
|
|
|
|
label->SetText( netName );
|
|
|
|
|
|
|
|
POINT pinLocation = getLocationOfNetElement( net, netTerm.ID );
|
|
|
|
label->SetPosition( getKiCadPoint( pinLocation ) );
|
|
|
|
label->SetVisible( true );
|
|
|
|
|
|
|
|
applyTextSettings( label, netTerm.NetLabel.TextCodeID, netTerm.NetLabel.Alignment,
|
|
|
|
netTerm.NetLabel.Justification );
|
|
|
|
|
|
|
|
netlabels.insert( { netTerm.ID, label } );
|
|
|
|
|
|
|
|
LAYER_ID sheet = Schematic.Symbols.at( netTerm.SymbolID ).LayerID;
|
|
|
|
m_sheetMap.at( sheet )->GetScreen()->Append( label );
|
|
|
|
}
|
2020-09-23 20:39:11 +00:00
|
|
|
}
|
|
|
|
|
2021-03-24 12:04:26 +00:00
|
|
|
auto getHierarchicalLabel =
|
|
|
|
[&]( NETELEMENT_ID aNode ) -> SCH_HIERLABEL*
|
|
|
|
{
|
2022-02-08 23:14:18 +00:00
|
|
|
if( aNode.Contains( wxT( "BLKT" ) ) )
|
2021-03-24 12:04:26 +00:00
|
|
|
{
|
|
|
|
NET_SCH::BLOCK_TERM blockTerm = net.BlockTerminals.at( aNode );
|
2021-06-10 18:51:46 +00:00
|
|
|
BLOCK_PIN_ID blockPinID = std::make_pair( blockTerm.BlockID,
|
|
|
|
blockTerm.TerminalID );
|
2021-03-24 12:04:26 +00:00
|
|
|
|
|
|
|
if( m_sheetPinMap.find( blockPinID )
|
|
|
|
!= m_sheetPinMap.end() )
|
|
|
|
{
|
|
|
|
return m_sheetPinMap.at( blockPinID );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
};
|
2020-11-27 18:05:57 +00:00
|
|
|
|
2020-09-26 13:27:03 +00:00
|
|
|
//Add net name to all hierarchical pins (block terminals in CADSTAR)
|
2020-09-23 20:39:11 +00:00
|
|
|
for( std::pair<NETELEMENT_ID, NET_SCH::BLOCK_TERM> blockPair : net.BlockTerminals )
|
|
|
|
{
|
2020-11-27 18:05:57 +00:00
|
|
|
SCH_HIERLABEL* label = getHierarchicalLabel( blockPair.first );
|
2020-09-23 20:39:11 +00:00
|
|
|
|
2021-09-01 18:24:42 +00:00
|
|
|
if( label )
|
2020-11-27 18:05:57 +00:00
|
|
|
label->SetText( netName );
|
2020-09-23 20:39:11 +00:00
|
|
|
}
|
|
|
|
|
2020-09-26 13:27:03 +00:00
|
|
|
// Load all bus entries and add net label if required
|
|
|
|
for( std::pair<NETELEMENT_ID, NET_SCH::BUS_TERM> busPair : net.BusTerminals )
|
|
|
|
{
|
|
|
|
NET_SCH::BUS_TERM busTerm = busPair.second;
|
|
|
|
BUS bus = Schematic.Buses.at( busTerm.BusID );
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
if( !m_busesMap.at( bus.ID )->Contains( netName ) )
|
|
|
|
m_busesMap.at( bus.ID )->AddMember( netName );
|
2020-11-26 18:11:06 +00:00
|
|
|
|
2020-09-26 13:27:03 +00:00
|
|
|
SCH_BUS_WIRE_ENTRY* busEntry =
|
|
|
|
new SCH_BUS_WIRE_ENTRY( getKiCadPoint( busTerm.FirstPoint ), false );
|
|
|
|
|
|
|
|
wxPoint size =
|
|
|
|
getKiCadPoint( busTerm.SecondPoint ) - getKiCadPoint( busTerm.FirstPoint );
|
|
|
|
busEntry->SetSize( wxSize( size.x, size.y ) );
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_sheetMap.at( bus.LayerID )->GetScreen()->Append( busEntry );
|
2020-09-26 13:27:03 +00:00
|
|
|
|
2021-02-19 12:38:47 +00:00
|
|
|
// Always add a label at bus terminals to ensure connectivity.
|
|
|
|
// If the original design does not have a label, just make it very small
|
|
|
|
// to keep connectivity but make the design look visually similar to
|
|
|
|
// the original.
|
|
|
|
SCH_LABEL* label = new SCH_LABEL();
|
|
|
|
label->SetText( netName );
|
|
|
|
label->SetPosition( getKiCadPoint( busTerm.SecondPoint ) );
|
|
|
|
label->SetVisible( true );
|
|
|
|
|
2020-09-26 13:27:03 +00:00
|
|
|
if( busTerm.HasNetLabel )
|
|
|
|
{
|
2021-04-02 18:50:30 +00:00
|
|
|
applyTextSettings( label,
|
|
|
|
busTerm.NetLabel.TextCodeID,
|
|
|
|
busTerm.NetLabel.Alignment,
|
|
|
|
busTerm.NetLabel.Justification );
|
2020-09-26 13:27:03 +00:00
|
|
|
}
|
2021-02-19 12:38:47 +00:00
|
|
|
else
|
|
|
|
{
|
2021-09-01 19:12:56 +00:00
|
|
|
label->SetTextSize( wxSize( SMALL_LABEL_SIZE, SMALL_LABEL_SIZE ) );
|
2021-02-19 12:38:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
netlabels.insert( { busTerm.ID, label } );
|
|
|
|
m_sheetMap.at( bus.LayerID )->GetScreen()->Append( label );
|
2020-09-26 13:27:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( std::pair<NETELEMENT_ID, NET_SCH::DANGLER> danglerPair : net.Danglers )
|
|
|
|
{
|
|
|
|
NET_SCH::DANGLER dangler = danglerPair.second;
|
|
|
|
|
|
|
|
SCH_LABEL* label = new SCH_LABEL();
|
|
|
|
label->SetPosition( getKiCadPoint( dangler.Position ) );
|
|
|
|
label->SetVisible( true );
|
2021-09-01 19:12:56 +00:00
|
|
|
|
|
|
|
if( dangler.HasNetLabel )
|
|
|
|
{
|
|
|
|
applyTextSettings( label,
|
|
|
|
dangler.NetLabel.TextCodeID,
|
|
|
|
dangler.NetLabel.Alignment,
|
|
|
|
dangler.NetLabel.Justification );
|
|
|
|
}
|
|
|
|
|
|
|
|
label->SetText( netName ); // set text after applying settings to avoid double-escaping
|
2020-09-26 13:27:03 +00:00
|
|
|
netlabels.insert( { dangler.ID, label } );
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_sheetMap.at( dangler.LayerID )->GetScreen()->Append( label );
|
2020-09-26 13:27:03 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 20:39:11 +00:00
|
|
|
for( NET_SCH::CONNECTION_SCH conn : net.Connections )
|
|
|
|
{
|
2020-11-27 18:05:57 +00:00
|
|
|
if( conn.LayerID == wxT( "NO_SHEET" ) )
|
|
|
|
continue; // No point loading virtual connections. KiCad handles that internally
|
|
|
|
|
2021-02-04 17:50:21 +00:00
|
|
|
POINT start = getLocationOfNetElement( net, conn.StartNode );
|
|
|
|
POINT end = getLocationOfNetElement( net, conn.EndNode );
|
2020-09-23 20:39:11 +00:00
|
|
|
|
2021-02-04 17:50:21 +00:00
|
|
|
if( start.x == UNDEFINED_VALUE || end.x == UNDEFINED_VALUE )
|
|
|
|
continue;
|
2020-09-23 20:39:11 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
// Connections in CADSTAR are always implied between symbols even if the route
|
2021-02-04 17:50:21 +00:00
|
|
|
// doesn't start and end exactly at the connection points
|
|
|
|
if( conn.Path.size() < 1 || conn.Path.front() != start )
|
|
|
|
conn.Path.insert( conn.Path.begin(), start );
|
|
|
|
|
|
|
|
if( conn.Path.size() < 2 || conn.Path.back() != end )
|
2020-09-23 20:39:11 +00:00
|
|
|
conn.Path.push_back( end );
|
|
|
|
|
2020-09-26 13:27:03 +00:00
|
|
|
bool firstPt = true;
|
|
|
|
bool secondPt = false;
|
2020-11-27 18:05:57 +00:00
|
|
|
wxPoint last;
|
2020-09-26 13:27:03 +00:00
|
|
|
SCH_LINE* wire = nullptr;
|
2020-11-29 11:57:29 +00:00
|
|
|
|
2020-11-27 18:05:57 +00:00
|
|
|
SHAPE_LINE_CHAIN wireChain; // Create a temp. line chain representing the connection
|
2020-09-23 20:39:11 +00:00
|
|
|
|
|
|
|
for( POINT pt : conn.Path )
|
2020-11-27 18:05:57 +00:00
|
|
|
{
|
|
|
|
wireChain.Append( getKiCadPoint( pt ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// AUTO-FIX SHEET PINS
|
|
|
|
//--------------------
|
|
|
|
// KiCad constrains the sheet pin on the edge of the sheet object whereas in
|
|
|
|
// CADSTAR it can be anywhere. Let's find the intersection of the wires with the sheet
|
|
|
|
// and place the hierarchical
|
|
|
|
std::vector<NETELEMENT_ID> nodes;
|
|
|
|
nodes.push_back( conn.StartNode );
|
|
|
|
nodes.push_back( conn.EndNode );
|
|
|
|
|
|
|
|
for( NETELEMENT_ID node : nodes )
|
|
|
|
{
|
|
|
|
SCH_HIERLABEL* sheetPin = getHierarchicalLabel( node );
|
|
|
|
|
|
|
|
if( sheetPin )
|
|
|
|
{
|
|
|
|
if( sheetPin->Type() == SCH_SHEET_PIN_T
|
|
|
|
&& SCH_SHEET::ClassOf( sheetPin->GetParent() ) )
|
|
|
|
{
|
|
|
|
SCH_SHEET* parentSheet = static_cast<SCH_SHEET*>( sheetPin->GetParent() );
|
|
|
|
wxSize sheetSize = parentSheet->GetSize();
|
|
|
|
wxPoint sheetPosition = parentSheet->GetPosition();
|
|
|
|
|
|
|
|
int leftSide = sheetPosition.x;
|
|
|
|
int rightSide = sheetPosition.x + sheetSize.x;
|
|
|
|
int topSide = sheetPosition.y;
|
|
|
|
int botSide = sheetPosition.y + sheetSize.y;
|
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN sheetEdge;
|
|
|
|
|
|
|
|
sheetEdge.Append( leftSide, topSide );
|
|
|
|
sheetEdge.Append( rightSide, topSide );
|
|
|
|
sheetEdge.Append( rightSide, botSide );
|
|
|
|
sheetEdge.Append( leftSide, botSide );
|
|
|
|
sheetEdge.Append( leftSide, topSide );
|
|
|
|
|
|
|
|
SHAPE_LINE_CHAIN::INTERSECTIONS wireToSheetIntersects;
|
|
|
|
|
|
|
|
if( !wireChain.Intersect( sheetEdge, wireToSheetIntersects ) )
|
|
|
|
{
|
2020-11-29 11:57:29 +00:00
|
|
|
// The block terminal is outside the block shape in the original
|
2020-11-27 18:05:57 +00:00
|
|
|
// CADSTAR design. Since KiCad's Sheet Pin will already be constrained
|
|
|
|
// on the edge, we will simply join to it with a straight line.
|
|
|
|
if( node == conn.StartNode )
|
|
|
|
wireChain = wireChain.Reverse();
|
|
|
|
|
|
|
|
wireChain.Append( sheetPin->GetPosition() );
|
2020-11-29 11:57:29 +00:00
|
|
|
|
2020-11-27 18:05:57 +00:00
|
|
|
if( node == conn.StartNode )
|
|
|
|
wireChain = wireChain.Reverse();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
// The block terminal is either inside or on the shape edge. Lets use
|
|
|
|
// the first intersection point.
|
2020-11-27 18:05:57 +00:00
|
|
|
VECTOR2I intsctPt = wireToSheetIntersects.at( 0 ).p;
|
|
|
|
int intsctIndx = wireChain.FindSegment( intsctPt );
|
2022-02-08 23:14:18 +00:00
|
|
|
wxASSERT_MSG( intsctIndx != -1, wxT( "Can't find intersecting segment" ) );
|
2020-11-27 18:05:57 +00:00
|
|
|
|
|
|
|
if( node == conn.StartNode )
|
|
|
|
wireChain.Replace( 0, intsctIndx, intsctPt );
|
|
|
|
else
|
|
|
|
wireChain.Replace( intsctIndx + 1, /*end index*/ -1, intsctPt );
|
|
|
|
|
|
|
|
sheetPin->SetPosition( (wxPoint) intsctPt );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-24 12:04:26 +00:00
|
|
|
auto fixNetLabelsAndSheetPins =
|
|
|
|
[&]( double aWireAngleDeciDeg, NETELEMENT_ID& aNetEleID )
|
|
|
|
{
|
|
|
|
LABEL_SPIN_STYLE spin = getSpinStyleDeciDeg( aWireAngleDeciDeg );
|
|
|
|
|
|
|
|
if( netlabels.find( aNetEleID ) != netlabels.end() )
|
2021-03-25 19:10:49 +00:00
|
|
|
netlabels.at( aNetEleID )->SetLabelSpinStyle( spin.MirrorY() );
|
2021-03-24 12:04:26 +00:00
|
|
|
|
|
|
|
SCH_HIERLABEL* sheetPin = getHierarchicalLabel( aNetEleID );
|
|
|
|
|
|
|
|
if( sheetPin )
|
|
|
|
sheetPin->SetLabelSpinStyle( spin.MirrorX() );
|
|
|
|
};
|
|
|
|
|
|
|
|
// Now we can load the wires and fix the label orientations
|
2020-12-01 01:10:58 +00:00
|
|
|
for( const VECTOR2I& pt : wireChain.CPoints() )
|
2020-09-23 20:39:11 +00:00
|
|
|
{
|
|
|
|
if( firstPt )
|
|
|
|
{
|
2020-11-27 18:05:57 +00:00
|
|
|
last = (wxPoint) pt;
|
2020-09-26 13:27:03 +00:00
|
|
|
firstPt = false;
|
|
|
|
secondPt = true;
|
2020-09-23 20:39:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-09-26 13:27:03 +00:00
|
|
|
if( secondPt )
|
|
|
|
{
|
|
|
|
secondPt = false;
|
|
|
|
|
2020-11-27 18:05:57 +00:00
|
|
|
|
2021-03-24 12:04:26 +00:00
|
|
|
wxPoint kiLast = last;
|
|
|
|
wxPoint kiCurrent = (wxPoint) pt;
|
|
|
|
double wireangleDeciDeg = getPolarAngle( kiLast - kiCurrent );
|
|
|
|
fixNetLabelsAndSheetPins( wireangleDeciDeg, conn.StartNode );
|
2020-11-27 18:05:57 +00:00
|
|
|
}
|
2020-09-23 20:39:11 +00:00
|
|
|
|
2020-11-27 18:05:57 +00:00
|
|
|
wire = new SCH_LINE();
|
2020-09-23 20:39:11 +00:00
|
|
|
|
2020-11-27 18:05:57 +00:00
|
|
|
wire->SetStartPoint( last );
|
|
|
|
wire->SetEndPoint( (wxPoint) pt );
|
|
|
|
wire->SetLayer( LAYER_WIRE );
|
2020-09-26 13:27:03 +00:00
|
|
|
|
2020-11-27 18:05:57 +00:00
|
|
|
if( !conn.ConnectionLineCode.IsEmpty() )
|
|
|
|
wire->SetLineWidth( getLineThickness( conn.ConnectionLineCode ) );
|
2020-09-23 20:39:11 +00:00
|
|
|
|
2020-11-27 18:05:57 +00:00
|
|
|
last = (wxPoint) pt;
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_sheetMap.at( conn.LayerID )->GetScreen()->Append( wire );
|
2020-09-23 20:39:11 +00:00
|
|
|
}
|
2020-09-26 13:27:03 +00:00
|
|
|
|
2020-11-27 18:05:57 +00:00
|
|
|
//Fix labels on the end wire
|
|
|
|
if( wire )
|
2020-09-26 13:27:03 +00:00
|
|
|
{
|
2021-03-24 12:04:26 +00:00
|
|
|
wxPoint kiLast = wire->GetEndPoint();
|
|
|
|
wxPoint kiCurrent = wire->GetStartPoint();
|
|
|
|
double wireangleDeciDeg = getPolarAngle( kiLast - kiCurrent );
|
|
|
|
fixNetLabelsAndSheetPins( wireangleDeciDeg, conn.EndNode );
|
2020-09-26 13:27:03 +00:00
|
|
|
}
|
2020-09-23 20:39:11 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 19:38:16 +00:00
|
|
|
for( std::pair<NETELEMENT_ID, NET_SCH::JUNCTION_SCH> juncPair : net.Junctions )
|
2020-09-23 20:39:11 +00:00
|
|
|
{
|
2020-12-29 19:38:16 +00:00
|
|
|
NET_SCH::JUNCTION_SCH junc = juncPair.second;
|
2020-09-23 20:39:11 +00:00
|
|
|
|
|
|
|
SCH_JUNCTION* kiJunc = new SCH_JUNCTION();
|
|
|
|
|
|
|
|
kiJunc->SetPosition( getKiCadPoint( junc.Location ) );
|
2021-02-13 20:00:17 +00:00
|
|
|
m_sheetMap.at( junc.LayerID )->GetScreen()->Append( kiJunc );
|
2020-12-29 19:38:16 +00:00
|
|
|
|
|
|
|
if( junc.HasNetLabel )
|
|
|
|
{
|
|
|
|
// In CADSTAR the label can be placed anywhere, but in KiCad it has to be placed
|
|
|
|
// in the same location as the junction for it to be connected to it.
|
|
|
|
SCH_LABEL* label = new SCH_LABEL();
|
|
|
|
label->SetText( netName );
|
|
|
|
label->SetPosition( getKiCadPoint( junc.Location ) );
|
|
|
|
label->SetVisible( true );
|
|
|
|
|
|
|
|
double labelAngleDeciDeg = getAngleTenthDegree( junc.NetLabel.OrientAngle );
|
|
|
|
LABEL_SPIN_STYLE spin = getSpinStyleDeciDeg( labelAngleDeciDeg );
|
|
|
|
label->SetLabelSpinStyle( spin );
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_sheetMap.at( junc.LayerID )->GetScreen()->Append( label );
|
2020-12-29 19:38:16 +00:00
|
|
|
}
|
2020-09-23 20:39:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-26 18:23:13 +00:00
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::loadFigures()
|
|
|
|
{
|
|
|
|
for( std::pair<FIGURE_ID, FIGURE> figPair : Schematic.Figures )
|
|
|
|
{
|
|
|
|
FIGURE fig = figPair.second;
|
|
|
|
|
2020-09-27 02:35:24 +00:00
|
|
|
loadFigure( fig, fig.LayerID, LAYER_NOTES );
|
|
|
|
}
|
|
|
|
}
|
2020-09-26 18:23:13 +00:00
|
|
|
|
2020-09-27 02:35:24 +00:00
|
|
|
|
|
|
|
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 );
|
2020-09-26 18:23:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-27 12:19:51 +00:00
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::loadDocumentationSymbols()
|
|
|
|
{
|
|
|
|
for( std::pair<DOCUMENTATION_SYMBOL_ID, DOCUMENTATION_SYMBOL> docSymPair :
|
|
|
|
Schematic.DocumentationSymbols )
|
|
|
|
{
|
|
|
|
DOCUMENTATION_SYMBOL docSym = docSymPair.second;
|
|
|
|
|
|
|
|
if( Library.SymbolDefinitions.find( docSym.SymdefID ) == Library.SymbolDefinitions.end() )
|
|
|
|
{
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Documentation Symbol '%s' refers to symbol "
|
|
|
|
"definition ID '%s' which does not exist in "
|
|
|
|
"the library. The symbol was not loaded." ),
|
|
|
|
docSym.ID,
|
|
|
|
docSym.SymdefID ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
2020-09-27 12:19:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
SYMDEF_SCM docSymDef = Library.SymbolDefinitions.at( docSym.SymdefID );
|
|
|
|
wxPoint moveVector = getKiCadPoint( docSym.Origin ) - getKiCadPoint( docSymDef.Origin );
|
|
|
|
double rotationAngle = getAngleTenthDegree( docSym.OrientAngle );
|
|
|
|
double scalingFactor =
|
|
|
|
(double) docSym.ScaleRatioNumerator / (double) docSym.ScaleRatioDenominator;
|
|
|
|
wxPoint centreOfTransform = getKiCadPoint( docSymDef.Origin );
|
|
|
|
bool mirrorInvert = docSym.Mirror;
|
|
|
|
|
|
|
|
for( std::pair<FIGURE_ID, FIGURE> figPair : docSymDef.Figures )
|
|
|
|
{
|
|
|
|
FIGURE fig = figPair.second;
|
|
|
|
|
|
|
|
loadFigure( fig, docSym.LayerID, LAYER_NOTES, moveVector, rotationAngle, scalingFactor,
|
2021-07-16 20:13:26 +00:00
|
|
|
centreOfTransform, mirrorInvert );
|
2020-09-27 12:19:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( std::pair<TEXT_ID, TEXT> textPair : docSymDef.Texts )
|
|
|
|
{
|
|
|
|
TEXT txt = textPair.second;
|
|
|
|
|
2021-04-02 18:50:30 +00:00
|
|
|
txt.Mirror = ( txt.Mirror ) ? !mirrorInvert : mirrorInvert;
|
|
|
|
txt.OrientAngle = docSym.OrientAngle - txt.OrientAngle;
|
|
|
|
|
2020-09-27 12:19:51 +00:00
|
|
|
SCH_TEXT* kiTxt = getKiCadSchText( txt );
|
|
|
|
|
|
|
|
wxPoint newPosition = applyTransform( kiTxt->GetPosition(), moveVector, rotationAngle,
|
2021-04-02 18:50:30 +00:00
|
|
|
scalingFactor, centreOfTransform, mirrorInvert );
|
|
|
|
|
2020-09-27 12:19:51 +00:00
|
|
|
int newTxtWidth = KiROUND( kiTxt->GetTextWidth() * scalingFactor );
|
|
|
|
int newTxtHeight = KiROUND( kiTxt->GetTextHeight() * scalingFactor );
|
|
|
|
int newTxtThickness = KiROUND( kiTxt->GetTextThickness() * scalingFactor );
|
|
|
|
|
|
|
|
kiTxt->SetPosition( newPosition );
|
|
|
|
kiTxt->SetTextWidth( newTxtWidth );
|
|
|
|
kiTxt->SetTextHeight( newTxtHeight );
|
|
|
|
kiTxt->SetTextThickness( newTxtThickness );
|
|
|
|
|
|
|
|
loadItemOntoKiCadSheet( docSym.LayerID, kiTxt );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-13 17:28:00 +00:00
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::loadTextVariables()
|
|
|
|
{
|
|
|
|
auto findAndReplaceTextField = [&]( TEXT_FIELD_NAME aField, wxString aValue ) {
|
2021-02-13 20:00:17 +00:00
|
|
|
if( m_context.TextFieldToValuesMap.find( aField ) != m_context.TextFieldToValuesMap.end() )
|
2020-12-13 17:28:00 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
if( m_context.TextFieldToValuesMap.at( aField ) != aValue )
|
2020-12-13 17:28:00 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
m_context.TextFieldToValuesMap.at( aField ) = aValue;
|
|
|
|
m_context.InconsistentTextFields.insert( aField );
|
2020-12-13 17:28:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
m_context.TextFieldToValuesMap.insert( { aField, aValue } );
|
2020-12-13 17:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
PROJECT* pj = &m_schematic->Prj();
|
2020-12-13 17:28:00 +00:00
|
|
|
|
|
|
|
if( pj )
|
|
|
|
{
|
|
|
|
std::map<wxString, wxString>& txtVars = pj->GetTextVars();
|
|
|
|
|
|
|
|
// Most of the design text fields can be derived from other elements
|
|
|
|
if( Schematic.VariantHierarchy.Variants.size() > 0 )
|
|
|
|
{
|
|
|
|
VARIANT loadedVar = Schematic.VariantHierarchy.Variants.begin()->second;
|
|
|
|
|
|
|
|
findAndReplaceTextField( TEXT_FIELD_NAME::VARIANT_NAME, loadedVar.Name );
|
|
|
|
findAndReplaceTextField( TEXT_FIELD_NAME::VARIANT_DESCRIPTION, loadedVar.Description );
|
|
|
|
}
|
|
|
|
|
|
|
|
findAndReplaceTextField( TEXT_FIELD_NAME::DESIGN_TITLE, Header.JobTitle );
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
for( std::pair<TEXT_FIELD_NAME, wxString> txtvalue : m_context.TextFieldToValuesMap )
|
2020-12-13 17:28:00 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
wxString varName = CADSTAR_TO_KICAD_FIELDS.at( txtvalue.first );
|
2020-12-13 17:28:00 +00:00
|
|
|
wxString varValue = txtvalue.second;
|
|
|
|
|
|
|
|
txtVars.insert( { varName, varValue } );
|
|
|
|
}
|
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
for( std::pair<wxString, wxString> txtvalue : m_context.FilenamesToTextMap )
|
2020-12-13 17:28:00 +00:00
|
|
|
{
|
|
|
|
wxString varName = txtvalue.first;
|
|
|
|
wxString varValue = txtvalue.second;
|
|
|
|
|
|
|
|
txtVars.insert( { varName, varValue } );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( _( "Text Variables could not be set as there is no project attached." ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
2020-12-13 17:28:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-20 21:08:46 +00:00
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::loadSymDefIntoLibrary( const SYMDEF_ID& aSymdefID,
|
2021-06-10 18:51:46 +00:00
|
|
|
const PART* aCadstarPart, const GATE_ID& aGateID, LIB_SYMBOL* aSymbol )
|
2020-09-20 21:08:46 +00:00
|
|
|
{
|
|
|
|
wxCHECK( Library.SymbolDefinitions.find( aSymdefID ) != Library.SymbolDefinitions.end(), );
|
|
|
|
|
|
|
|
SYMDEF_SCM symbol = Library.SymbolDefinitions.at( aSymdefID );
|
2021-01-27 00:09:58 +00:00
|
|
|
int gateNumber = getKiCadUnitNumberFromGate( aGateID );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2022-04-12 20:33:52 +00:00
|
|
|
// Ensure there are no items on this unit (e.g. if we already previously loaded the symbol from
|
|
|
|
// the part definition)
|
|
|
|
std::vector<LIB_ITEM*> drawItems = aSymbol->GetUnitDrawItems( gateNumber, 0 );
|
|
|
|
|
|
|
|
for( LIB_ITEM* item : drawItems )
|
|
|
|
aSymbol->RemoveDrawItem( item );
|
|
|
|
|
2020-09-20 21:08:46 +00:00
|
|
|
for( std::pair<FIGURE_ID, FIGURE> figPair : symbol.Figures )
|
|
|
|
{
|
|
|
|
FIGURE fig = figPair.second;
|
2021-08-29 18:55:47 +00:00
|
|
|
int lineThickness = getLineThickness( fig.LineCodeID );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2021-08-29 18:55:47 +00:00
|
|
|
loadLibrarySymbolShapeVertices( fig.Shape.Vertices, symbol.Origin, aSymbol, gateNumber,
|
|
|
|
lineThickness );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
for( CUTOUT c : fig.Shape.Cutouts )
|
|
|
|
{
|
2021-08-29 18:55:47 +00:00
|
|
|
loadLibrarySymbolShapeVertices( c.Vertices, symbol.Origin, aSymbol, gateNumber,
|
|
|
|
lineThickness );
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-03 20:06:41 +00:00
|
|
|
TERMINAL_TO_PINNUM_MAP pinNumMap;
|
|
|
|
|
2020-09-20 21:08:46 +00:00
|
|
|
for( std::pair<TERMINAL_ID, TERMINAL> termPair : symbol.Terminals )
|
|
|
|
{
|
|
|
|
TERMINAL term = termPair.second;
|
2022-02-08 23:14:18 +00:00
|
|
|
wxString pinNum = wxString::Format( wxT( "%ld" ), term.ID );
|
2020-09-20 21:08:46 +00:00
|
|
|
wxString pinName = wxEmptyString;
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_PIN* pin = new LIB_PIN( aSymbol );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
if( aCadstarPart )
|
|
|
|
{
|
|
|
|
PART::DEFINITION::PIN csPin = getPartDefinitionPin( *aCadstarPart, aGateID, term.ID );
|
|
|
|
|
2021-09-01 18:24:42 +00:00
|
|
|
pinName = HandleTextOverbar( csPin.Label );
|
|
|
|
pinNum = HandleTextOverbar( csPin.Name );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2020-11-18 23:26:27 +00:00
|
|
|
if( pinNum.IsEmpty() )
|
2020-09-20 21:08:46 +00:00
|
|
|
{
|
|
|
|
if( !csPin.Identifier.IsEmpty() )
|
2020-11-18 23:26:27 +00:00
|
|
|
pinNum = csPin.Identifier;
|
2021-02-02 15:35:45 +00:00
|
|
|
else if( csPin.ID == UNDEFINED_VALUE )
|
2022-02-08 23:14:18 +00:00
|
|
|
pinNum = wxString::Format( wxT( "%ld" ), term.ID );
|
2020-11-18 23:26:27 +00:00
|
|
|
else
|
2022-02-08 23:14:18 +00:00
|
|
|
pinNum = wxString::Format( wxT( "%ld" ), csPin.ID );
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
|
2021-02-02 15:37:10 +00:00
|
|
|
pin->SetType( getKiCadPinType( csPin.Type ) );
|
2021-02-03 20:06:41 +00:00
|
|
|
|
|
|
|
pinNumMap.insert( { term.ID, pinNum } );
|
2021-02-02 15:37:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If no part is defined, we don't know the pin type. Assume passive pin
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_PASSIVE );
|
|
|
|
}
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
pin->SetPosition( getKiCadLibraryPoint( term.Position, symbol.Origin ) );
|
|
|
|
pin->SetLength( 0 ); //CADSTAR Pins are just a point (have no length)
|
|
|
|
pin->SetShape( GRAPHIC_PINSHAPE::LINE );
|
|
|
|
pin->SetUnit( gateNumber );
|
|
|
|
pin->SetNumber( pinNum );
|
2020-09-26 13:27:03 +00:00
|
|
|
pin->SetName( pinName );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2021-09-01 19:12:56 +00:00
|
|
|
int pinNumberHeight = getTextHeightFromTextCode( wxT( "TC0" ) ); // TC0 is the default CADSTAR text size for name/number
|
|
|
|
int pinNameHeight = getTextHeightFromTextCode( wxT( "TC0" ) );
|
|
|
|
|
|
|
|
if( symbol.PinNumberLocations.count( term.ID ) )
|
|
|
|
{
|
|
|
|
PIN_NUM_LABEL_LOC pinNumLocation = symbol.PinNumberLocations.at( term.ID );
|
|
|
|
pinNumberHeight = getTextHeightFromTextCode( pinNumLocation.TextCodeID );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( symbol.PinLabelLocations.count( term.ID ) )
|
|
|
|
{
|
|
|
|
PIN_NUM_LABEL_LOC pinNameLocation = symbol.PinLabelLocations.at( term.ID );
|
|
|
|
pinNameHeight = getTextHeightFromTextCode( pinNameLocation.TextCodeID );
|
|
|
|
}
|
|
|
|
|
|
|
|
pin->SetNumberTextSize( pinNumberHeight );
|
|
|
|
pin->SetNameTextSize( pinNameHeight );
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
if( aSymbol->IsPower() )
|
2020-09-20 21:08:46 +00:00
|
|
|
{
|
|
|
|
pin->SetVisible( false );
|
|
|
|
pin->SetType( ELECTRICAL_PINTYPE::PT_POWER_IN );
|
2021-06-10 18:51:46 +00:00
|
|
|
pin->SetName( aSymbol->GetName() );
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
aSymbol->AddDrawItem( pin );
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
fixUpLibraryPins( aSymbol, gateNumber );
|
2021-05-28 18:39:08 +00:00
|
|
|
|
2021-02-03 20:06:41 +00:00
|
|
|
if(aCadstarPart)
|
2021-02-13 20:00:17 +00:00
|
|
|
m_pinNumsMap.insert( { aCadstarPart->ID + aGateID, pinNumMap } );
|
2021-02-03 20:06:41 +00:00
|
|
|
|
2020-09-20 21:08:46 +00:00
|
|
|
for( std::pair<TEXT_ID, TEXT> textPair : symbol.Texts )
|
|
|
|
{
|
2021-04-09 19:11:12 +00:00
|
|
|
TEXT csText = textPair.second;
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_TEXT* libtext = new LIB_TEXT( aSymbol );
|
2020-09-20 21:08:46 +00:00
|
|
|
libtext->SetText( csText.Text );
|
|
|
|
libtext->SetUnit( gateNumber );
|
|
|
|
libtext->SetPosition( getKiCadLibraryPoint( csText.Position, symbol.Origin ) );
|
2021-04-09 19:11:12 +00:00
|
|
|
libtext->SetMultilineAllowed( true ); // temporarily so that we calculate bbox correctly
|
2021-04-02 18:50:30 +00:00
|
|
|
|
|
|
|
applyTextSettings( libtext,
|
|
|
|
csText.TextCodeID,
|
|
|
|
csText.Alignment,
|
|
|
|
csText.Justification,
|
|
|
|
csText.OrientAngle,
|
|
|
|
csText.Mirror );
|
|
|
|
|
2021-04-09 19:11:12 +00:00
|
|
|
// Split out multi line text items into individual text elements
|
2022-02-08 23:14:18 +00:00
|
|
|
if( csText.Text.Contains( wxT( "\n" ) ) )
|
2021-04-09 19:11:12 +00:00
|
|
|
{
|
|
|
|
wxArrayString strings;
|
|
|
|
wxStringSplit( csText.Text, strings, '\n' );
|
|
|
|
wxPoint firstLinePos;
|
|
|
|
|
2021-04-15 17:47:06 +00:00
|
|
|
for( size_t ii = 0; ii < strings.size(); ++ii )
|
2021-04-09 19:11:12 +00:00
|
|
|
{
|
|
|
|
EDA_RECT bbox = libtext->GetTextBox( ii, true );
|
|
|
|
wxPoint linePos = { bbox.GetLeft(), -bbox.GetBottom() };
|
|
|
|
|
|
|
|
RotatePoint( &linePos, libtext->GetTextPos(), -libtext->GetTextAngle() );
|
|
|
|
|
|
|
|
LIB_TEXT* line = static_cast<LIB_TEXT*>( libtext->Clone() );
|
|
|
|
line->SetText( strings[ii] );
|
|
|
|
line->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
line->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
line->SetTextPos( linePos );
|
|
|
|
|
|
|
|
// Multiline text not allowed in LIB_TEXT
|
|
|
|
line->SetMultilineAllowed( false );
|
2021-06-10 18:51:46 +00:00
|
|
|
aSymbol->AddDrawItem( line );
|
2021-04-09 19:11:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delete libtext;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Multiline text not allowed in LIB_TEXT
|
|
|
|
libtext->SetMultilineAllowed( false );
|
2021-06-10 18:51:46 +00:00
|
|
|
aSymbol->AddDrawItem( libtext );
|
2021-04-09 19:11:12 +00:00
|
|
|
}
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( symbol.TextLocations.find( SYMBOL_NAME_ATTRID ) != symbol.TextLocations.end() )
|
|
|
|
{
|
|
|
|
TEXT_LOCATION textLoc = symbol.TextLocations.at( SYMBOL_NAME_ATTRID );
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_FIELD* field = &aSymbol->GetReferenceField();
|
2021-01-27 00:09:58 +00:00
|
|
|
applyToLibraryFieldAttribute( textLoc, symbol.Origin, field );
|
2020-09-20 21:08:46 +00:00
|
|
|
field->SetUnit( gateNumber );
|
|
|
|
}
|
|
|
|
|
2021-02-02 13:39:40 +00:00
|
|
|
// Hide the value field for now (it might get unhidden if an attribute exists in the cadstar
|
|
|
|
// design with the text "Value"
|
2021-06-10 18:51:46 +00:00
|
|
|
aSymbol->GetValueField().SetVisible( false );
|
2021-02-02 13:39:40 +00:00
|
|
|
|
2020-09-20 21:08:46 +00:00
|
|
|
if( symbol.TextLocations.find( PART_NAME_ATTRID ) != symbol.TextLocations.end() )
|
|
|
|
{
|
|
|
|
TEXT_LOCATION textLoc = symbol.TextLocations.at( PART_NAME_ATTRID );
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_FIELD* field = aSymbol->FindField( PartNameFieldName );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
if( !field )
|
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
int fieldID = aSymbol->GetFieldCount();
|
|
|
|
field = new LIB_FIELD( aSymbol, fieldID );
|
2021-03-28 18:03:11 +00:00
|
|
|
field->SetName( PartNameFieldName );
|
2021-06-10 18:51:46 +00:00
|
|
|
aSymbol->AddField( field );
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
|
2021-03-28 18:03:11 +00:00
|
|
|
wxASSERT( field->GetName() == PartNameFieldName );
|
2021-01-27 00:09:58 +00:00
|
|
|
applyToLibraryFieldAttribute( textLoc, symbol.Origin, field );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
if( aCadstarPart )
|
2021-01-27 00:09:58 +00:00
|
|
|
{
|
|
|
|
wxString partName = aCadstarPart->Name;
|
|
|
|
partName.Replace( wxT( "\n" ), wxT( "\\n" ) );
|
|
|
|
partName.Replace( wxT( "\r" ), wxT( "\\r" ) );
|
|
|
|
partName.Replace( wxT( "\t" ), wxT( "\\t" ) );
|
|
|
|
field->SetText( partName );
|
|
|
|
}
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
field->SetUnit( gateNumber );
|
2021-02-02 13:39:40 +00:00
|
|
|
field->SetVisible( SymbolPartNameColor.IsVisible );
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
2020-09-26 13:27:03 +00:00
|
|
|
|
2021-01-27 00:09:58 +00:00
|
|
|
if( aCadstarPart )
|
|
|
|
{
|
|
|
|
wxString footprintRefName = wxEmptyString;
|
|
|
|
wxString footprintAlternateName = wxEmptyString;
|
|
|
|
|
|
|
|
auto loadLibraryField =
|
|
|
|
[&]( ATTRIBUTE_VALUE& aAttributeVal )
|
|
|
|
{
|
2021-03-28 18:03:11 +00:00
|
|
|
wxString attrName = getAttributeName( aAttributeVal.AttributeID );
|
2021-01-27 00:09:58 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
// Remove invalid field characters
|
2021-01-27 00:09:58 +00:00
|
|
|
aAttributeVal.Value.Replace( wxT( "\n" ), wxT( "\\n" ) );
|
|
|
|
aAttributeVal.Value.Replace( wxT( "\r" ), wxT( "\\r" ) );
|
|
|
|
aAttributeVal.Value.Replace( wxT( "\t" ), wxT( "\\t" ) );
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
//TODO: Handle "links": In cadstar a field can be a "link" if its name starts
|
|
|
|
// with the characters "Link ". Need to figure out how to convert them to
|
|
|
|
// equivalent in KiCad.
|
2021-01-27 00:09:58 +00:00
|
|
|
|
|
|
|
if( attrName == wxT( "(PartDefinitionNameStem)" ) )
|
|
|
|
{
|
|
|
|
//Space not allowed in Reference field
|
|
|
|
aAttributeVal.Value.Replace( wxT( " " ), "_" );
|
2021-06-10 18:51:46 +00:00
|
|
|
aSymbol->GetReferenceField().SetText( aAttributeVal.Value );
|
2021-01-27 00:09:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if( attrName == wxT( "(PartDescription)" ) )
|
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
aSymbol->SetDescription( aAttributeVal.Value );
|
2021-01-27 00:09:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if( attrName == wxT( "(PartDefinitionReferenceName)" ) )
|
|
|
|
{
|
|
|
|
footprintRefName = aAttributeVal.Value;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if( attrName == wxT( "(PartDefinitionAlternateName)" ) )
|
|
|
|
{
|
|
|
|
footprintAlternateName = aAttributeVal.Value;
|
|
|
|
return;
|
|
|
|
}
|
2021-03-28 18:03:11 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_FIELD* attrField = aSymbol->FindField( attrName );
|
2021-01-27 00:09:58 +00:00
|
|
|
|
|
|
|
if( !attrField )
|
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
int fieldID = aSymbol->GetFieldCount();
|
|
|
|
attrField = new LIB_FIELD( aSymbol, fieldID );
|
2021-01-27 00:09:58 +00:00
|
|
|
attrField->SetName( attrName );
|
2021-06-10 18:51:46 +00:00
|
|
|
aSymbol->AddField( attrField );
|
2021-01-27 00:09:58 +00:00
|
|
|
}
|
|
|
|
|
2021-03-28 18:03:11 +00:00
|
|
|
wxASSERT( attrField->GetName() == attrName );
|
2021-01-27 00:09:58 +00:00
|
|
|
attrField->SetText( aAttributeVal.Value );
|
|
|
|
attrField->SetUnit( gateNumber );
|
|
|
|
|
2021-04-02 18:50:30 +00:00
|
|
|
ATTRIBUTE_ID& attrid = aAttributeVal.AttributeID;
|
|
|
|
attrField->SetVisible( isAttributeVisible( attrid ) );
|
|
|
|
|
2021-01-27 00:09:58 +00:00
|
|
|
if( aAttributeVal.HasLocation )
|
|
|
|
{
|
|
|
|
// #1 Check if the part itself defined a location for the field
|
|
|
|
applyToLibraryFieldAttribute( aAttributeVal.AttributeLocation, symbol.Origin,
|
|
|
|
attrField );
|
|
|
|
}
|
|
|
|
else if( symbol.TextLocations.find( aAttributeVal.AttributeID )
|
|
|
|
!= symbol.TextLocations.end() )
|
|
|
|
{
|
|
|
|
// #2 Look in the symbol definition: Text locations
|
|
|
|
TEXT_LOCATION symTxtLoc = symbol.TextLocations.at( aAttributeVal.AttributeID );
|
|
|
|
applyToLibraryFieldAttribute( symTxtLoc, symbol.Origin, attrField );
|
|
|
|
}
|
2021-04-02 18:50:30 +00:00
|
|
|
else if( symbol.AttributeValues.find( attrid ) != symbol.AttributeValues.end()
|
|
|
|
&& symbol.AttributeValues.at( attrid ).HasLocation )
|
2021-01-27 00:09:58 +00:00
|
|
|
{
|
|
|
|
// #3 Look in the symbol definition: Attribute values
|
2021-04-02 18:50:30 +00:00
|
|
|
ATTRIBUTE_VALUE symAttrVal = symbol.AttributeValues.at( attrid );
|
|
|
|
applyToLibraryFieldAttribute( symAttrVal.AttributeLocation, symbol.Origin,
|
|
|
|
attrField );
|
2021-01-27 00:09:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
attrField->SetVisible( false );
|
2021-04-02 18:50:30 +00:00
|
|
|
applyTextSettings( attrField, wxT( "TC1" ), ALIGNMENT::NO_ALIGNMENT,
|
|
|
|
JUSTIFICATION::LEFT );
|
2021-01-27 00:09:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Load all attributes in the Part Definition
|
2021-07-16 20:13:26 +00:00
|
|
|
for( std::pair<ATTRIBUTE_ID,
|
|
|
|
ATTRIBUTE_VALUE> attr : aCadstarPart->Definition.AttributeValues )
|
2021-01-27 00:09:58 +00:00
|
|
|
{
|
|
|
|
ATTRIBUTE_VALUE attrVal = attr.second;
|
|
|
|
loadLibraryField( attrVal );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load all attributes in the Part itself.
|
|
|
|
for( std::pair<ATTRIBUTE_ID, ATTRIBUTE_VALUE> attr : aCadstarPart->AttributeValues )
|
|
|
|
{
|
|
|
|
ATTRIBUTE_VALUE attrVal = attr.second;
|
|
|
|
loadLibraryField( attrVal );
|
|
|
|
}
|
|
|
|
|
2022-06-15 18:47:29 +00:00
|
|
|
wxString fpNameInLibrary = generateLibName( footprintRefName, footprintAlternateName );
|
2021-01-27 00:09:58 +00:00
|
|
|
|
2022-06-15 18:47:29 +00:00
|
|
|
if( !fpNameInLibrary.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxArrayString fpFilters;
|
|
|
|
fpFilters.Add( fpNameInLibrary );
|
|
|
|
aSymbol->SetFPFilters( fpFilters );
|
|
|
|
|
|
|
|
// Assume that the PCB footprint library name will be the same as the schematic filename
|
|
|
|
wxFileName schFilename( Filename );
|
|
|
|
wxString libName = schFilename.GetName();
|
|
|
|
aSymbol->GetFootprintField().SetText( libName + wxT( ":" ) + fpNameInLibrary );
|
|
|
|
}
|
2021-01-27 00:09:58 +00:00
|
|
|
}
|
|
|
|
|
2020-09-26 13:27:03 +00:00
|
|
|
if( aCadstarPart && aCadstarPart->Definition.HidePinNames )
|
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
aSymbol->SetShowPinNames( false );
|
|
|
|
aSymbol->SetShowPinNumbers( false );
|
2020-09-26 13:27:03 +00:00
|
|
|
}
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::loadLibrarySymbolShapeVertices( const std::vector<VERTEX>& aCadstarVertices,
|
|
|
|
wxPoint aSymbolOrigin,
|
|
|
|
LIB_SYMBOL* aSymbol,
|
|
|
|
int aGateNumber,
|
|
|
|
int aLineThickness )
|
2020-09-20 21:08:46 +00:00
|
|
|
{
|
|
|
|
const VERTEX* prev = &aCadstarVertices.at( 0 );
|
|
|
|
const VERTEX* cur;
|
|
|
|
|
2022-02-08 23:14:18 +00:00
|
|
|
wxASSERT_MSG( prev->Type == VERTEX_TYPE::POINT, wxT( "First vertex should always be a point." ) );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
for( size_t i = 1; i < aCadstarVertices.size(); i++ )
|
|
|
|
{
|
|
|
|
cur = &aCadstarVertices.at( i );
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
LIB_SHAPE* shape = nullptr;
|
|
|
|
bool cw = false;
|
|
|
|
wxPoint startPoint = getKiCadLibraryPoint( prev->End, aSymbolOrigin );
|
|
|
|
wxPoint endPoint = getKiCadLibraryPoint( cur->End, aSymbolOrigin );
|
|
|
|
wxPoint centerPoint;
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
if( cur->Type == VERTEX_TYPE::ANTICLOCKWISE_SEMICIRCLE
|
|
|
|
|| cur->Type == VERTEX_TYPE::CLOCKWISE_SEMICIRCLE )
|
|
|
|
{
|
|
|
|
centerPoint = ( startPoint + endPoint ) / 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
centerPoint = getKiCadLibraryPoint( cur->Center, aSymbolOrigin );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch( cur->Type )
|
|
|
|
{
|
|
|
|
case VERTEX_TYPE::POINT:
|
2021-07-18 23:08:54 +00:00
|
|
|
shape = new LIB_SHAPE( aSymbol, SHAPE_T::POLY );
|
|
|
|
shape->AddPoint( startPoint );
|
|
|
|
shape->AddPoint( endPoint );
|
2020-09-20 21:08:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VERTEX_TYPE::CLOCKWISE_SEMICIRCLE:
|
|
|
|
case VERTEX_TYPE::CLOCKWISE_ARC:
|
|
|
|
cw = true;
|
|
|
|
KI_FALLTHROUGH;
|
|
|
|
|
|
|
|
case VERTEX_TYPE::ANTICLOCKWISE_SEMICIRCLE:
|
|
|
|
case VERTEX_TYPE::ANTICLOCKWISE_ARC:
|
2021-07-18 23:08:54 +00:00
|
|
|
shape = new LIB_SHAPE( aSymbol, SHAPE_T::ARC );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
shape->SetPosition( centerPoint );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
if( cw )
|
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
shape->SetStart( endPoint );
|
|
|
|
shape->SetEnd( startPoint );
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
shape->SetStart( startPoint );
|
|
|
|
shape->SetEnd( endPoint );
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
shape->SetUnit( aGateNumber );
|
|
|
|
shape->SetWidth( aLineThickness );
|
|
|
|
aSymbol->AddDrawItem( shape );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
prev = cur;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-27 00:09:58 +00:00
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::applyToLibraryFieldAttribute(
|
2020-09-20 21:08:46 +00:00
|
|
|
const ATTRIBUTE_LOCATION& aCadstarAttrLoc, wxPoint aSymbolOrigin, LIB_FIELD* aKiCadField )
|
|
|
|
{
|
|
|
|
aKiCadField->SetTextPos( getKiCadLibraryPoint( aCadstarAttrLoc.Position, aSymbolOrigin ) );
|
|
|
|
|
2021-04-02 18:50:30 +00:00
|
|
|
applyTextSettings( aKiCadField,
|
|
|
|
aCadstarAttrLoc.TextCodeID,
|
|
|
|
aCadstarAttrLoc.Alignment,
|
|
|
|
aCadstarAttrLoc.Justification,
|
|
|
|
aCadstarAttrLoc.OrientAngle,
|
|
|
|
aCadstarAttrLoc.Mirror );
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbol( const SYMBOL& aCadstarSymbol,
|
2021-06-10 18:51:46 +00:00
|
|
|
const LIB_SYMBOL& aKiCadPart,
|
2021-06-10 14:10:55 +00:00
|
|
|
double& aComponentOrientationDeciDeg )
|
2020-09-20 21:08:46 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
LIB_ID libId( m_libraryFileName.GetName(), aKiCadPart.GetName() );
|
2021-01-31 19:32:39 +00:00
|
|
|
int unit = getKiCadUnitNumberFromGate( aCadstarSymbol.GateID );
|
|
|
|
|
|
|
|
SCH_SHEET_PATH sheetpath;
|
2021-02-13 20:00:17 +00:00
|
|
|
SCH_SHEET* kiSheet = m_sheetMap.at( aCadstarSymbol.LayerID );
|
|
|
|
m_rootSheet->LocatePathOfScreen( kiSheet->GetScreen(), &sheetpath );
|
2021-01-31 19:32:39 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = new SCH_SYMBOL( aKiCadPart, libId, &sheetpath, unit );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2021-02-02 13:39:40 +00:00
|
|
|
if( aCadstarSymbol.IsComponent )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
symbol->SetRef( &sheetpath, aCadstarSymbol.ComponentRef.Designator );
|
2021-02-02 13:39:40 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
symbol->SetPosition( getKiCadPoint( aCadstarSymbol.Origin ) );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2020-11-22 01:50:04 +00:00
|
|
|
double compAngleDeciDeg = getAngleTenthDegree( aCadstarSymbol.OrientAngle );
|
|
|
|
int compOrientation = 0;
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
if( aCadstarSymbol.Mirror )
|
2020-11-22 01:50:04 +00:00
|
|
|
{
|
|
|
|
compAngleDeciDeg = -compAngleDeciDeg;
|
2021-06-10 14:10:55 +00:00
|
|
|
compOrientation += SYMBOL_ORIENTATION_T::SYM_MIRROR_Y;
|
2020-11-22 01:50:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
compOrientation += getComponentOrientation( compAngleDeciDeg, aComponentOrientationDeciDeg );
|
|
|
|
|
|
|
|
if( NormalizeAngle180( compAngleDeciDeg ) != NormalizeAngle180( aComponentOrientationDeciDeg ) )
|
|
|
|
{
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Symbol '%s' is rotated by an angle of %.1f "
|
|
|
|
"degrees in the original CADSTAR design but "
|
|
|
|
"KiCad only supports rotation angles multiples "
|
|
|
|
"of 90 degrees. The connecting wires will need "
|
|
|
|
"manual fixing." ),
|
|
|
|
aCadstarSymbol.ComponentRef.Designator,
|
|
|
|
compAngleDeciDeg / 10.0 ),
|
|
|
|
RPT_SEVERITY_ERROR);
|
2020-11-22 01:50:04 +00:00
|
|
|
}
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
symbol->SetOrientation( compOrientation );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
if( m_sheetMap.find( aCadstarSymbol.LayerID ) == m_sheetMap.end() )
|
2020-09-20 21:08:46 +00:00
|
|
|
{
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Symbol '%s' references sheet ID '%s' which does "
|
|
|
|
"not exist in the design. The symbol was not "
|
|
|
|
"loaded." ),
|
|
|
|
aCadstarSymbol.ComponentRef.Designator,
|
|
|
|
aCadstarSymbol.LayerID ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
delete symbol;
|
2020-09-20 21:08:46 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-02-03 20:06:41 +00:00
|
|
|
wxString gate = ( aCadstarSymbol.GateID.IsEmpty() ) ? wxT( "A" ) : aCadstarSymbol.GateID;
|
|
|
|
wxString partGateIndex = aCadstarSymbol.PartRef.RefID + gate;
|
|
|
|
|
|
|
|
//Handle pin swaps
|
2021-02-13 20:00:17 +00:00
|
|
|
if( m_pinNumsMap.find( partGateIndex ) != m_pinNumsMap.end() )
|
2021-02-03 20:06:41 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
TERMINAL_TO_PINNUM_MAP termNumMap = m_pinNumsMap.at( partGateIndex );
|
2021-02-03 20:06:41 +00:00
|
|
|
|
|
|
|
std::map<wxString, LIB_PIN*> pinNumToLibPinMap;
|
|
|
|
|
|
|
|
for( auto& term : termNumMap )
|
|
|
|
{
|
|
|
|
wxString pinNum = term.second;
|
2021-06-15 12:31:28 +00:00
|
|
|
pinNumToLibPinMap.insert( { pinNum,
|
|
|
|
symbol->GetLibSymbolRef()->GetPin( term.second ) } );
|
2021-02-03 20:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto replacePinNumber = [&]( wxString aOldPinNum, wxString aNewPinNum )
|
|
|
|
{
|
|
|
|
if( aOldPinNum == aNewPinNum )
|
|
|
|
return;
|
|
|
|
|
|
|
|
LIB_PIN* libpin = pinNumToLibPinMap.at( aOldPinNum );
|
2021-09-01 18:24:42 +00:00
|
|
|
libpin->SetNumber( HandleTextOverbar( aNewPinNum ) );
|
2021-02-03 20:06:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//Older versions of Cadstar used pin numbers
|
|
|
|
for( auto& pinPair : aCadstarSymbol.PinNumbers )
|
|
|
|
{
|
|
|
|
SYMBOL::PIN_NUM pin = pinPair.second;
|
|
|
|
|
|
|
|
replacePinNumber( termNumMap.at( pin.TerminalID ),
|
2022-02-08 23:14:18 +00:00
|
|
|
wxString::Format( wxT( "%ld" ), pin.PinNum ) );
|
2021-02-03 20:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Newer versions of Cadstar use pin names
|
|
|
|
for( auto& pinPair : aCadstarSymbol.PinNames )
|
|
|
|
{
|
|
|
|
SYMPINNAME_LABEL pin = pinPair.second;
|
|
|
|
replacePinNumber( termNumMap.at( pin.TerminalID ), pin.NameOrLabel );
|
|
|
|
}
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
symbol->UpdatePins();
|
2021-02-03 20:06:41 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
kiSheet->GetScreen()->Append( symbol );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
return symbol;
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 20:39:11 +00:00
|
|
|
|
2020-09-20 21:08:46 +00:00
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::loadSymbolFieldAttribute(
|
|
|
|
const ATTRIBUTE_LOCATION& aCadstarAttrLoc, const double& aComponentOrientationDeciDeg,
|
2021-01-27 00:09:58 +00:00
|
|
|
bool aIsMirrored, SCH_FIELD* aKiCadField )
|
2020-09-20 21:08:46 +00:00
|
|
|
{
|
|
|
|
aKiCadField->SetPosition( getKiCadPoint( aCadstarAttrLoc.Position ) );
|
|
|
|
aKiCadField->SetVisible( true );
|
|
|
|
|
2021-04-02 18:50:30 +00:00
|
|
|
ALIGNMENT alignment = aCadstarAttrLoc.Alignment;
|
|
|
|
|
2021-05-28 16:25:37 +00:00
|
|
|
double textAngle = getAngleTenthDegree( aCadstarAttrLoc.OrientAngle );
|
|
|
|
long long cadstarAngle = getCadstarAngle( textAngle - aComponentOrientationDeciDeg );
|
2021-01-27 00:09:58 +00:00
|
|
|
|
|
|
|
if( aIsMirrored )
|
|
|
|
{
|
2021-10-31 16:12:08 +00:00
|
|
|
// We need to change the aligment when the symbol is mirrored based on the text orientation
|
|
|
|
// To ensure the anchor point is the same in KiCad.
|
2021-01-27 00:09:58 +00:00
|
|
|
|
2021-10-31 16:12:08 +00:00
|
|
|
int textIsVertical = KiROUND( textAngle / 900.0 ) % 2;
|
|
|
|
|
|
|
|
if( textIsVertical )
|
|
|
|
alignment = rotate180( alignment );
|
|
|
|
|
|
|
|
alignment = mirrorX( alignment );
|
2021-01-27 00:09:58 +00:00
|
|
|
}
|
|
|
|
|
2021-04-02 18:50:30 +00:00
|
|
|
applyTextSettings( aKiCadField,
|
|
|
|
aCadstarAttrLoc.TextCodeID,
|
|
|
|
alignment,
|
|
|
|
aCadstarAttrLoc.Justification,
|
|
|
|
cadstarAngle,
|
|
|
|
aCadstarAttrLoc.Mirror );
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-23 20:39:11 +00:00
|
|
|
int CADSTAR_SCH_ARCHIVE_LOADER::getComponentOrientation(
|
2020-11-22 01:50:04 +00:00
|
|
|
double aOrientAngleDeciDeg, double& aReturnedOrientationDeciDeg )
|
2020-09-23 20:39:11 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
int compOrientation = SYMBOL_ORIENTATION_T::SYM_ORIENT_0;
|
2020-09-23 20:39:11 +00:00
|
|
|
|
2020-11-22 01:50:04 +00:00
|
|
|
int oDeg = (int) NormalizeAngle180( aOrientAngleDeciDeg );
|
2020-09-23 20:39:11 +00:00
|
|
|
|
|
|
|
if( oDeg >= -450 && oDeg <= 450 )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
compOrientation = SYMBOL_ORIENTATION_T::SYM_ORIENT_0;
|
2020-09-23 20:39:11 +00:00
|
|
|
aReturnedOrientationDeciDeg = 0.0;
|
|
|
|
}
|
|
|
|
else if( oDeg >= 450 && oDeg <= 1350 )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
compOrientation = SYMBOL_ORIENTATION_T::SYM_ORIENT_90;
|
2020-09-23 20:39:11 +00:00
|
|
|
aReturnedOrientationDeciDeg = 900.0;
|
|
|
|
}
|
|
|
|
else if( oDeg >= 1350 || oDeg <= -1350 )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
compOrientation = SYMBOL_ORIENTATION_T::SYM_ORIENT_180;
|
2020-09-23 20:39:11 +00:00
|
|
|
aReturnedOrientationDeciDeg = 1800.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
compOrientation = SYMBOL_ORIENTATION_T::SYM_ORIENT_270;
|
2020-09-23 20:39:11 +00:00
|
|
|
aReturnedOrientationDeciDeg = 2700.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return compOrientation;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CADSTAR_SCH_ARCHIVE_LOADER::POINT CADSTAR_SCH_ARCHIVE_LOADER::getLocationOfNetElement(
|
|
|
|
const NET_SCH& aNet, const NETELEMENT_ID& aNetElementID )
|
|
|
|
{
|
|
|
|
// clang-format off
|
2020-10-14 11:03:58 +00:00
|
|
|
auto logUnknownNetElementError =
|
2020-09-23 20:39:11 +00:00
|
|
|
[&]()
|
|
|
|
{
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "Net %s references unknown net element %s. "
|
|
|
|
"The net was not properly loaded and may "
|
|
|
|
"require manual fixing." ),
|
|
|
|
getNetName( aNet ),
|
|
|
|
aNetElementID ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
2020-09-23 20:39:11 +00:00
|
|
|
|
|
|
|
return POINT();
|
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
2022-02-08 23:14:18 +00:00
|
|
|
if( aNetElementID.Contains( wxT( "J" ) ) ) // Junction
|
2020-09-23 20:39:11 +00:00
|
|
|
{
|
|
|
|
if( aNet.Junctions.find( aNetElementID ) == aNet.Junctions.end() )
|
|
|
|
return logUnknownNetElementError();
|
|
|
|
|
|
|
|
return aNet.Junctions.at( aNetElementID ).Location;
|
|
|
|
}
|
2022-02-08 23:14:18 +00:00
|
|
|
else if( aNetElementID.Contains( wxT( "P" ) ) ) // Terminal/Pin of a symbol
|
2020-09-23 20:39:11 +00:00
|
|
|
{
|
|
|
|
if( aNet.Terminals.find( aNetElementID ) == aNet.Terminals.end() )
|
|
|
|
return logUnknownNetElementError();
|
|
|
|
|
|
|
|
SYMBOL_ID symid = aNet.Terminals.at( aNetElementID ).SymbolID;
|
|
|
|
TERMINAL_ID termid = aNet.Terminals.at( aNetElementID ).TerminalID;
|
|
|
|
|
|
|
|
if( Schematic.Symbols.find( symid ) == Schematic.Symbols.end() )
|
|
|
|
return logUnknownNetElementError();
|
|
|
|
|
|
|
|
SYMBOL sym = Schematic.Symbols.at( symid );
|
|
|
|
SYMDEF_ID symdefid = sym.SymdefID;
|
|
|
|
wxPoint symbolOrigin = sym.Origin;
|
|
|
|
|
|
|
|
if( Library.SymbolDefinitions.find( symdefid ) == Library.SymbolDefinitions.end() )
|
|
|
|
return logUnknownNetElementError();
|
|
|
|
|
|
|
|
wxPoint libpinPosition =
|
|
|
|
Library.SymbolDefinitions.at( symdefid ).Terminals.at( termid ).Position;
|
|
|
|
wxPoint libOrigin = Library.SymbolDefinitions.at( symdefid ).Origin;
|
2021-05-28 15:19:04 +00:00
|
|
|
|
|
|
|
wxPoint pinOffset = libpinPosition - libOrigin;
|
|
|
|
pinOffset.x = ( pinOffset.x * sym.ScaleRatioNumerator ) / sym.ScaleRatioDenominator;
|
|
|
|
pinOffset.y = ( pinOffset.y * sym.ScaleRatioNumerator ) / sym.ScaleRatioDenominator;
|
|
|
|
|
2020-09-23 20:39:11 +00:00
|
|
|
wxPoint pinPosition = symbolOrigin + pinOffset;
|
|
|
|
|
2020-11-22 01:50:04 +00:00
|
|
|
double compAngleDeciDeg = getAngleTenthDegree( sym.OrientAngle );
|
|
|
|
|
2020-09-23 20:39:11 +00:00
|
|
|
if( sym.Mirror )
|
|
|
|
pinPosition.x = ( 2 * symbolOrigin.x ) - pinPosition.x;
|
|
|
|
|
|
|
|
double adjustedOrientationDecideg;
|
2020-11-22 01:50:04 +00:00
|
|
|
getComponentOrientation( compAngleDeciDeg, adjustedOrientationDecideg );
|
2020-09-23 20:39:11 +00:00
|
|
|
|
|
|
|
RotatePoint( &pinPosition, symbolOrigin, -adjustedOrientationDecideg );
|
|
|
|
|
|
|
|
POINT retval;
|
|
|
|
retval.x = pinPosition.x;
|
|
|
|
retval.y = pinPosition.y;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2022-02-08 23:14:18 +00:00
|
|
|
else if( aNetElementID.Contains( wxT( "BT" ) ) ) // Bus Terminal
|
2020-09-23 20:39:11 +00:00
|
|
|
{
|
|
|
|
if( aNet.BusTerminals.find( aNetElementID ) == aNet.BusTerminals.end() )
|
|
|
|
return logUnknownNetElementError();
|
|
|
|
|
|
|
|
return aNet.BusTerminals.at( aNetElementID ).SecondPoint;
|
|
|
|
}
|
2022-02-08 23:14:18 +00:00
|
|
|
else if( aNetElementID.Contains( wxT( "BLKT" ) ) ) // Block Terminal (sheet hierarchy connection)
|
2020-09-23 20:39:11 +00:00
|
|
|
{
|
|
|
|
if( aNet.BlockTerminals.find( aNetElementID ) == aNet.BlockTerminals.end() )
|
|
|
|
return logUnknownNetElementError();
|
|
|
|
|
|
|
|
BLOCK_ID blockid = aNet.BlockTerminals.at( aNetElementID ).BlockID;
|
|
|
|
TERMINAL_ID termid = aNet.BlockTerminals.at( aNetElementID ).TerminalID;
|
|
|
|
|
|
|
|
if( Schematic.Blocks.find( blockid ) == Schematic.Blocks.end() )
|
|
|
|
return logUnknownNetElementError();
|
|
|
|
|
|
|
|
return Schematic.Blocks.at( blockid ).Terminals.at( termid ).Position;
|
|
|
|
}
|
2022-02-08 23:14:18 +00:00
|
|
|
else if( aNetElementID.Contains( wxT( "D" ) ) ) // Dangler
|
2020-09-26 13:27:03 +00:00
|
|
|
{
|
|
|
|
if( aNet.Danglers.find( aNetElementID ) == aNet.Danglers.end() )
|
|
|
|
return logUnknownNetElementError();
|
|
|
|
|
|
|
|
return aNet.Danglers.at( aNetElementID ).Position;
|
|
|
|
}
|
2020-09-23 20:39:11 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return logUnknownNetElementError();
|
|
|
|
}
|
|
|
|
|
|
|
|
return POINT();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString CADSTAR_SCH_ARCHIVE_LOADER::getNetName( const NET_SCH& aNet )
|
|
|
|
{
|
|
|
|
wxString netname = aNet.Name;
|
|
|
|
|
|
|
|
if( netname.IsEmpty() )
|
2022-02-08 23:14:18 +00:00
|
|
|
netname = wxString::Format( wxT( "$%ld" ), aNet.SignalNum );
|
2020-09-23 20:39:11 +00:00
|
|
|
|
|
|
|
return netname;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-21 22:56:56 +00:00
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::loadGraphicStaightSegment( const wxPoint& aStartPoint,
|
|
|
|
const wxPoint& aEndPoint, const LINECODE_ID& aCadstarLineCodeID,
|
|
|
|
const LAYER_ID& aCadstarSheetID, const SCH_LAYER_ID& aKiCadSchLayerID,
|
|
|
|
const wxPoint& aMoveVector, const double& aRotationAngleDeciDeg,
|
|
|
|
const double& aScalingFactor, const wxPoint& aTransformCentre, const bool& aMirrorInvert )
|
|
|
|
{
|
|
|
|
SCH_LINE* segment = new SCH_LINE();
|
|
|
|
|
|
|
|
segment->SetLayer( aKiCadSchLayerID );
|
|
|
|
segment->SetLineWidth( KiROUND( getLineThickness( aCadstarLineCodeID ) * aScalingFactor ) );
|
|
|
|
segment->SetLineStyle( getLineStyle( aCadstarLineCodeID ) );
|
|
|
|
|
|
|
|
//Apply transforms
|
2021-06-10 18:51:46 +00:00
|
|
|
wxPoint startPoint = applyTransform( aStartPoint, aMoveVector, aRotationAngleDeciDeg,
|
|
|
|
aScalingFactor, aTransformCentre, aMirrorInvert );
|
|
|
|
wxPoint endPoint = applyTransform( aEndPoint, aMoveVector, aRotationAngleDeciDeg,
|
|
|
|
aScalingFactor, aTransformCentre, aMirrorInvert );
|
2020-11-21 22:56:56 +00:00
|
|
|
|
|
|
|
segment->SetStartPoint( startPoint );
|
|
|
|
segment->SetEndPoint( endPoint );
|
|
|
|
|
|
|
|
loadItemOntoKiCadSheet( aCadstarSheetID, segment );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-26 18:23:13 +00:00
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices( const std::vector<VERTEX>& aCadstarVertices,
|
2020-09-27 12:19:51 +00:00
|
|
|
LINECODE_ID aCadstarLineCodeID, LAYER_ID aCadstarSheetID, SCH_LAYER_ID aKiCadSchLayerID,
|
|
|
|
const wxPoint& aMoveVector, const double& aRotationAngleDeciDeg,
|
|
|
|
const double& aScalingFactor, const wxPoint& aTransformCentre, const bool& aMirrorInvert )
|
2020-09-26 18:23:13 +00:00
|
|
|
{
|
|
|
|
const VERTEX* prev = &aCadstarVertices.at( 0 );
|
|
|
|
const VERTEX* cur;
|
|
|
|
|
|
|
|
wxASSERT_MSG(
|
2022-02-08 23:14:18 +00:00
|
|
|
prev->Type == VERTEX_TYPE::POINT, wxT( "First vertex should always be a point vertex" ) );
|
2020-09-26 18:23:13 +00:00
|
|
|
|
2020-11-29 11:57:29 +00:00
|
|
|
for( size_t ii = 1; ii < aCadstarVertices.size(); ii++ )
|
2020-09-26 18:23:13 +00:00
|
|
|
{
|
2020-11-29 11:57:29 +00:00
|
|
|
cur = &aCadstarVertices.at( ii );
|
2020-09-26 18:23:13 +00:00
|
|
|
|
2020-11-21 22:56:56 +00:00
|
|
|
wxPoint startPoint = getKiCadPoint( prev->End );
|
|
|
|
wxPoint endPoint = getKiCadPoint( cur->End );
|
|
|
|
wxPoint centerPoint = getKiCadPoint( cur->Center );
|
|
|
|
bool cw = false;
|
2020-09-26 18:23:13 +00:00
|
|
|
|
2020-11-21 22:56:56 +00:00
|
|
|
if( cur->Type == VERTEX_TYPE::ANTICLOCKWISE_SEMICIRCLE
|
|
|
|
|| cur->Type == VERTEX_TYPE::CLOCKWISE_SEMICIRCLE )
|
|
|
|
{
|
|
|
|
centerPoint = ( startPoint + endPoint ) / 2;
|
|
|
|
}
|
2020-09-26 18:23:13 +00:00
|
|
|
|
2020-11-21 22:56:56 +00:00
|
|
|
switch( cur->Type )
|
|
|
|
{
|
|
|
|
case VERTEX_TYPE::CLOCKWISE_SEMICIRCLE:
|
|
|
|
case VERTEX_TYPE::CLOCKWISE_ARC:
|
|
|
|
cw = true;
|
|
|
|
KI_FALLTHROUGH;
|
|
|
|
case VERTEX_TYPE::ANTICLOCKWISE_SEMICIRCLE:
|
|
|
|
case VERTEX_TYPE::ANTICLOCKWISE_ARC:
|
|
|
|
{
|
|
|
|
double arcStartAngle = getPolarAngle( startPoint - centerPoint );
|
|
|
|
double arcEndAngle = getPolarAngle( endPoint - centerPoint );
|
|
|
|
double arcAngleDeciDeg = arcEndAngle - arcStartAngle;
|
2020-09-27 12:19:51 +00:00
|
|
|
|
2020-11-21 22:56:56 +00:00
|
|
|
if( cw )
|
|
|
|
arcAngleDeciDeg = NormalizeAnglePos( arcAngleDeciDeg );
|
|
|
|
else
|
|
|
|
arcAngleDeciDeg = NormalizeAngleNeg( arcAngleDeciDeg );
|
2020-09-27 12:19:51 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
SHAPE_ARC tempArc( centerPoint, startPoint, arcAngleDeciDeg / 10.0 );
|
2020-11-21 22:56:56 +00:00
|
|
|
SHAPE_LINE_CHAIN arcSegments = tempArc.ConvertToPolyline( Millimeter2iu( 0.1 ) );
|
|
|
|
|
|
|
|
// Load the arc as a series of piece-wise segments
|
2020-09-26 18:23:13 +00:00
|
|
|
|
2020-11-29 11:57:29 +00:00
|
|
|
for( int jj = 0; jj < arcSegments.SegmentCount(); jj++ )
|
2020-11-21 22:56:56 +00:00
|
|
|
{
|
2020-11-29 11:57:29 +00:00
|
|
|
wxPoint segStart = (wxPoint) arcSegments.Segment( jj ).A;
|
|
|
|
wxPoint segEnd = (wxPoint) arcSegments.Segment( jj ).B;
|
2020-11-21 22:56:56 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
loadGraphicStaightSegment( segStart, segEnd, aCadstarLineCodeID, aCadstarSheetID,
|
|
|
|
aKiCadSchLayerID, aMoveVector, aRotationAngleDeciDeg,
|
|
|
|
aScalingFactor, aTransformCentre, aMirrorInvert );
|
2020-11-21 22:56:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VERTEX_TYPE::POINT:
|
|
|
|
loadGraphicStaightSegment( startPoint, endPoint, aCadstarLineCodeID, aCadstarSheetID,
|
2021-07-16 20:13:26 +00:00
|
|
|
aKiCadSchLayerID, aMoveVector, aRotationAngleDeciDeg,
|
|
|
|
aScalingFactor, aTransformCentre, aMirrorInvert );
|
2020-11-21 22:56:56 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-02-08 23:14:18 +00:00
|
|
|
wxFAIL_MSG( wxT( "Unknown CADSTAR Vertex type" ) );
|
2020-11-21 22:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
prev = cur;
|
2020-09-27 02:35:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::loadFigure( const FIGURE& aCadstarFigure,
|
2020-09-27 12:19:51 +00:00
|
|
|
const LAYER_ID& aCadstarSheetIDOverride, SCH_LAYER_ID aKiCadSchLayerID,
|
|
|
|
const wxPoint& aMoveVector, const double& aRotationAngleDeciDeg,
|
|
|
|
const double& aScalingFactor, const wxPoint& aTransformCentre, const bool& aMirrorInvert )
|
2020-09-27 02:35:24 +00:00
|
|
|
{
|
|
|
|
loadShapeVertices( aCadstarFigure.Shape.Vertices, aCadstarFigure.LineCodeID,
|
2021-07-16 20:13:26 +00:00
|
|
|
aCadstarSheetIDOverride, aKiCadSchLayerID, aMoveVector,
|
|
|
|
aRotationAngleDeciDeg, aScalingFactor, aTransformCentre, aMirrorInvert );
|
2020-09-27 02:35:24 +00:00
|
|
|
|
|
|
|
for( CUTOUT cutout : aCadstarFigure.Shape.Cutouts )
|
|
|
|
{
|
2020-09-27 12:19:51 +00:00
|
|
|
loadShapeVertices( cutout.Vertices, aCadstarFigure.LineCodeID, aCadstarSheetIDOverride,
|
2021-07-16 20:13:26 +00:00
|
|
|
aKiCadSchLayerID, aMoveVector, aRotationAngleDeciDeg, aScalingFactor,
|
|
|
|
aTransformCentre, aMirrorInvert );
|
2020-09-26 18:23:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-19 22:05:02 +00:00
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::loadSheetAndChildSheets(
|
2021-07-26 19:35:12 +00:00
|
|
|
LAYER_ID aCadstarSheetID, const wxPoint& aPosition, wxSize aSheetSize,
|
2021-06-10 18:51:46 +00:00
|
|
|
const SCH_SHEET_PATH& aParentSheet )
|
2020-09-19 22:05:02 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
wxCHECK_MSG( m_sheetMap.find( aCadstarSheetID ) == m_sheetMap.end(), ,
|
2022-02-08 23:14:18 +00:00
|
|
|
wxT( "Sheet already loaded!" ) );
|
2020-09-19 22:05:02 +00:00
|
|
|
|
2020-11-22 19:55:21 +00:00
|
|
|
SCH_SHEET* sheet = new SCH_SHEET( aParentSheet.Last(), aPosition );
|
2021-02-13 20:00:17 +00:00
|
|
|
SCH_SCREEN* screen = new SCH_SCREEN( m_schematic );
|
2020-11-22 19:55:21 +00:00
|
|
|
SCH_SHEET_PATH instance( aParentSheet );
|
2020-09-19 22:05:02 +00:00
|
|
|
|
|
|
|
sheet->SetSize( aSheetSize );
|
|
|
|
sheet->SetScreen( screen );
|
|
|
|
|
2020-09-20 21:08:46 +00:00
|
|
|
wxString name = Sheets.SheetNames.at( aCadstarSheetID );
|
2020-09-19 22:05:02 +00:00
|
|
|
|
|
|
|
SCH_FIELD& sheetNameField = sheet->GetFields()[SHEETNAME];
|
|
|
|
SCH_FIELD& filenameField = sheet->GetFields()[SHEETFILENAME];
|
|
|
|
|
|
|
|
sheetNameField.SetText( name );
|
|
|
|
|
2020-11-22 19:55:21 +00:00
|
|
|
int sheetNum = getSheetNumber( aCadstarSheetID );
|
|
|
|
wxString loadedFilename = wxFileName( Filename ).GetName();
|
2022-02-08 23:14:18 +00:00
|
|
|
std::string filename = wxString::Format( wxT( "%s_%02d" ), loadedFilename, sheetNum ).ToStdString();
|
2020-09-19 22:05:02 +00:00
|
|
|
|
|
|
|
ReplaceIllegalFileNameChars( &filename );
|
2020-09-20 21:08:46 +00:00
|
|
|
filename += wxT( "." ) + KiCadSchematicFileExtension;
|
2020-09-19 22:05:02 +00:00
|
|
|
|
|
|
|
filenameField.SetText( filename );
|
2021-02-17 19:12:47 +00:00
|
|
|
|
2021-05-28 16:06:22 +00:00
|
|
|
wxFileName fn( m_schematic->Prj().GetProjectPath() + filename );
|
2020-09-19 22:05:02 +00:00
|
|
|
sheet->GetScreen()->SetFileName( fn.GetFullPath() );
|
2020-11-22 19:55:21 +00:00
|
|
|
aParentSheet.Last()->GetScreen()->Append( sheet );
|
|
|
|
instance.push_back( sheet );
|
2021-12-08 18:36:23 +00:00
|
|
|
sheet->AddInstance( instance );
|
2020-11-22 19:55:21 +00:00
|
|
|
|
2022-02-08 23:14:18 +00:00
|
|
|
wxString pageNumStr = wxString::Format( wxT( "%d" ), getSheetNumber( aCadstarSheetID ) );
|
2021-12-06 12:47:18 +00:00
|
|
|
sheet->SetPageNumber( instance, pageNumStr );
|
2020-09-19 22:05:02 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
sheet->AutoplaceFields( /* aScreen */ nullptr, /* aManual */ false );
|
2021-02-17 19:12:47 +00:00
|
|
|
|
2021-02-13 20:00:17 +00:00
|
|
|
m_sheetMap.insert( { aCadstarSheetID, sheet } );
|
2020-09-19 22:05:02 +00:00
|
|
|
|
2020-11-22 19:55:21 +00:00
|
|
|
loadChildSheets( aCadstarSheetID, instance );
|
2020-09-19 22:05:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::loadChildSheets( LAYER_ID aCadstarSheetID,
|
|
|
|
const SCH_SHEET_PATH& aSheet )
|
2020-09-19 22:05:02 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
wxCHECK_MSG( m_sheetMap.find( aCadstarSheetID ) != m_sheetMap.end(), ,
|
2022-02-08 23:14:18 +00:00
|
|
|
wxT( "FIXME! Parent sheet should be loaded before attempting to load subsheets" ) );
|
2020-09-19 22:05:02 +00:00
|
|
|
|
|
|
|
for( std::pair<BLOCK_ID, BLOCK> blockPair : Schematic.Blocks )
|
|
|
|
{
|
|
|
|
BLOCK& block = blockPair.second;
|
|
|
|
|
|
|
|
if( block.LayerID == aCadstarSheetID && block.Type == BLOCK::TYPE::CHILD )
|
|
|
|
{
|
2020-12-29 23:35:57 +00:00
|
|
|
if( block.AssocLayerID == wxT( "NO_LINK" ) )
|
|
|
|
{
|
|
|
|
if( block.Figures.size() > 0 )
|
|
|
|
{
|
2021-03-31 21:33:30 +00:00
|
|
|
m_reporter->Report( wxString::Format( _( "The block ID %s (Block name: '%s') "
|
|
|
|
"is drawn on sheet '%s' but is not "
|
|
|
|
"linked to another sheet in the "
|
|
|
|
"design. KiCad requires all sheet "
|
|
|
|
"symbols to be associated to a sheet, "
|
|
|
|
"so the block was not loaded." ),
|
|
|
|
block.ID, block.Name,
|
|
|
|
Sheets.SheetNames.at( aCadstarSheetID ) ),
|
|
|
|
RPT_SEVERITY_ERROR );
|
2020-12-29 23:35:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-09-19 22:05:02 +00:00
|
|
|
// In KiCad you can only draw rectangular shapes whereas in Cadstar arbitrary shapes
|
|
|
|
// are allowed. We will calculate the extents of the Cadstar shape and draw a rectangle
|
|
|
|
|
|
|
|
std::pair<wxPoint, wxSize> blockExtents;
|
|
|
|
|
|
|
|
if( block.Figures.size() > 0 )
|
|
|
|
{
|
|
|
|
blockExtents = getFigureExtentsKiCad( block.Figures.begin()->second );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-31 21:33:30 +00:00
|
|
|
THROW_IO_ERROR( wxString::Format( _( "The CADSTAR schematic might be corrupt: "
|
|
|
|
"Block %s references a child sheet but has no "
|
|
|
|
"Figure defined." ),
|
|
|
|
block.ID ) );
|
2020-09-19 22:05:02 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
loadSheetAndChildSheets( block.AssocLayerID, blockExtents.first, blockExtents.second,
|
|
|
|
aSheet );
|
2020-09-19 22:05:02 +00:00
|
|
|
|
2021-10-17 17:31:42 +00:00
|
|
|
// Hide all KiCad sheet properties (sheet name/filename is not applicable in CADSTAR)
|
|
|
|
SCH_SHEET* loadedSheet = m_sheetMap.at( block.AssocLayerID );
|
|
|
|
SCH_FIELDS fields = loadedSheet->GetFields();
|
|
|
|
|
|
|
|
for( SCH_FIELD& field : fields )
|
|
|
|
{
|
|
|
|
field.SetVisible( false );
|
|
|
|
}
|
|
|
|
|
2020-09-19 22:05:02 +00:00
|
|
|
if( block.HasBlockLabel )
|
|
|
|
{
|
2021-10-29 17:59:07 +00:00
|
|
|
//@todo use below code when KiCad supports multi-line fields
|
|
|
|
/*
|
2020-09-19 22:05:02 +00:00
|
|
|
// Add the block label as a separate field
|
|
|
|
SCH_FIELD blockNameField( getKiCadPoint( block.BlockLabel.Position ), 2,
|
2022-02-08 23:14:18 +00:00
|
|
|
loadedSheet, wxString( wxT( "Block name" ) ) );
|
2020-09-19 22:05:02 +00:00
|
|
|
blockNameField.SetText( block.Name );
|
|
|
|
blockNameField.SetVisible( true );
|
2021-04-02 18:50:30 +00:00
|
|
|
|
|
|
|
applyTextSettings( &blockNameField,
|
|
|
|
block.BlockLabel.TextCodeID,
|
|
|
|
block.BlockLabel.Alignment,
|
|
|
|
block.BlockLabel.Justification,
|
|
|
|
block.BlockLabel.OrientAngle,
|
|
|
|
block.BlockLabel.Mirror );
|
|
|
|
|
2021-10-29 17:59:07 +00:00
|
|
|
fields.push_back( blockNameField );*/
|
|
|
|
|
|
|
|
// For now as as a text item (supports multi-line properly)
|
|
|
|
SCH_TEXT* kiTxt = new SCH_TEXT();
|
|
|
|
|
|
|
|
kiTxt->SetParent( m_schematic );
|
|
|
|
kiTxt->SetPosition( getKiCadPoint( block.BlockLabel.Position ) );
|
|
|
|
kiTxt->SetText( block.Name );
|
|
|
|
|
|
|
|
applyTextSettings( kiTxt,
|
|
|
|
block.BlockLabel.TextCodeID,
|
|
|
|
block.BlockLabel.Alignment,
|
|
|
|
block.BlockLabel.Justification,
|
|
|
|
block.BlockLabel.OrientAngle,
|
|
|
|
block.BlockLabel.Mirror );
|
|
|
|
|
|
|
|
loadItemOntoKiCadSheet( aCadstarSheetID, kiTxt );
|
2020-09-19 22:05:02 +00:00
|
|
|
}
|
2021-10-17 17:31:42 +00:00
|
|
|
|
|
|
|
loadedSheet->SetFields( fields );
|
2020-09-19 22:05:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<CADSTAR_SCH_ARCHIVE_LOADER::LAYER_ID> CADSTAR_SCH_ARCHIVE_LOADER::findOrphanSheets()
|
|
|
|
{
|
|
|
|
std::vector<LAYER_ID> childSheets, orphanSheets;
|
|
|
|
|
|
|
|
//Find all sheets that are child of another
|
|
|
|
for( std::pair<BLOCK_ID, BLOCK> blockPair : Schematic.Blocks )
|
|
|
|
{
|
|
|
|
BLOCK& block = blockPair.second;
|
|
|
|
LAYER_ID& assocSheetID = block.AssocLayerID;
|
|
|
|
|
|
|
|
if( block.Type == BLOCK::TYPE::CHILD )
|
|
|
|
childSheets.push_back( assocSheetID );
|
|
|
|
}
|
|
|
|
|
|
|
|
//Add sheets that do not have a parent
|
|
|
|
for( LAYER_ID sheetID : Sheets.SheetOrder )
|
|
|
|
{
|
|
|
|
if( std::find( childSheets.begin(), childSheets.end(), sheetID ) == childSheets.end() )
|
|
|
|
orphanSheets.push_back( sheetID );
|
|
|
|
}
|
|
|
|
|
|
|
|
return orphanSheets;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CADSTAR_SCH_ARCHIVE_LOADER::getSheetNumber( LAYER_ID aCadstarSheetID )
|
|
|
|
{
|
|
|
|
int i = 1;
|
|
|
|
|
|
|
|
for( LAYER_ID sheetID : Sheets.SheetOrder )
|
|
|
|
{
|
|
|
|
if( sheetID == aCadstarSheetID )
|
|
|
|
return i;
|
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-27 02:35:24 +00:00
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::loadItemOntoKiCadSheet( LAYER_ID aCadstarSheetID, SCH_ITEM* aItem )
|
|
|
|
{
|
2022-02-08 23:14:18 +00:00
|
|
|
wxCHECK_MSG( aItem, /*void*/, wxT( "aItem is null" ) );
|
2020-09-27 02:35:24 +00:00
|
|
|
|
2022-02-08 23:14:18 +00:00
|
|
|
if( aCadstarSheetID == wxT( "ALL_SHEETS" ) )
|
2020-09-27 02:35:24 +00:00
|
|
|
{
|
|
|
|
SCH_ITEM* duplicateItem;
|
|
|
|
|
|
|
|
for( std::pair<LAYER_ID, SHEET_NAME> sheetPair : Sheets.SheetNames )
|
|
|
|
{
|
|
|
|
LAYER_ID sheetID = sheetPair.first;
|
|
|
|
duplicateItem = aItem->Duplicate();
|
2021-02-13 20:00:17 +00:00
|
|
|
m_sheetMap.at( sheetID )->GetScreen()->Append( aItem->Duplicate() );
|
2020-09-27 02:35:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Get rid of the extra copy:
|
|
|
|
delete aItem;
|
|
|
|
aItem = duplicateItem;
|
|
|
|
}
|
2022-02-08 23:14:18 +00:00
|
|
|
else if( aCadstarSheetID == wxT( "NO_SHEET" ) )
|
2020-09-27 02:35:24 +00:00
|
|
|
{
|
|
|
|
wxASSERT_MSG(
|
2022-02-08 23:14:18 +00:00
|
|
|
false, wxT( "Trying to add an item to NO_SHEET? This might be a documentation symbol." ) );
|
2020-09-27 02:35:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
if( m_sheetMap.find( aCadstarSheetID ) != m_sheetMap.end() )
|
2020-09-27 02:35:24 +00:00
|
|
|
{
|
2021-02-13 20:00:17 +00:00
|
|
|
m_sheetMap.at( aCadstarSheetID )->GetScreen()->Append( aItem );
|
2020-09-27 02:35:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete aItem;
|
2022-02-08 23:14:18 +00:00
|
|
|
wxASSERT_MSG( false, wxT( "Unknown Sheet ID." ) );
|
2020-09-27 02:35:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-20 21:08:46 +00:00
|
|
|
CADSTAR_SCH_ARCHIVE_LOADER::SYMDEF_ID CADSTAR_SCH_ARCHIVE_LOADER::getSymDefFromName(
|
|
|
|
const wxString& aSymdefName, const wxString& aSymDefAlternate )
|
|
|
|
{
|
2021-02-02 15:38:46 +00:00
|
|
|
// Do a case-insensitive comparison
|
2020-09-20 21:08:46 +00:00
|
|
|
for( std::pair<SYMDEF_ID, SYMDEF_SCM> symPair : Library.SymbolDefinitions )
|
|
|
|
{
|
|
|
|
SYMDEF_ID id = symPair.first;
|
|
|
|
SYMDEF_SCM symdef = symPair.second;
|
|
|
|
|
2021-02-02 15:38:46 +00:00
|
|
|
if( symdef.ReferenceName.Lower() == aSymdefName.Lower()
|
|
|
|
&& symdef.Alternate.Lower() == aSymDefAlternate.Lower() )
|
|
|
|
{
|
2020-09-20 21:08:46 +00:00
|
|
|
return id;
|
2021-02-02 15:38:46 +00:00
|
|
|
}
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return SYMDEF_ID();
|
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2021-01-27 00:09:58 +00:00
|
|
|
bool CADSTAR_SCH_ARCHIVE_LOADER::isAttributeVisible( const ATTRIBUTE_ID& aCadstarAttributeID )
|
2020-09-20 21:08:46 +00:00
|
|
|
{
|
2021-01-27 00:09:58 +00:00
|
|
|
// Use CADSTAR visibility settings to determine if an attribute is visible
|
|
|
|
if( AttrColors.AttributeColors.find( aCadstarAttributeID ) != AttrColors.AttributeColors.end() )
|
|
|
|
{
|
|
|
|
return AttrColors.AttributeColors.at( aCadstarAttributeID ).IsVisible;
|
|
|
|
}
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2021-01-27 00:09:58 +00:00
|
|
|
return false; // If there is no visibility setting, assume not displayed
|
2020-09-20 21:08:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-19 22:05:02 +00:00
|
|
|
int CADSTAR_SCH_ARCHIVE_LOADER::getLineThickness( const LINECODE_ID& aCadstarLineCodeID )
|
|
|
|
{
|
|
|
|
wxCHECK( Assignments.Codedefs.LineCodes.find( aCadstarLineCodeID )
|
|
|
|
!= Assignments.Codedefs.LineCodes.end(),
|
2021-11-13 22:55:46 +00:00
|
|
|
Mils2iu( DEFAULT_WIRE_WIDTH_MILS ) );
|
2020-09-19 22:05:02 +00:00
|
|
|
|
|
|
|
return getKiCadLength( Assignments.Codedefs.LineCodes.at( aCadstarLineCodeID ).Width );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-26 18:23:13 +00:00
|
|
|
PLOT_DASH_TYPE CADSTAR_SCH_ARCHIVE_LOADER::getLineStyle( const LINECODE_ID& aCadstarLineCodeID )
|
|
|
|
{
|
|
|
|
wxCHECK( Assignments.Codedefs.LineCodes.find( aCadstarLineCodeID )
|
|
|
|
!= Assignments.Codedefs.LineCodes.end(),
|
2021-07-16 20:13:26 +00:00
|
|
|
PLOT_DASH_TYPE::SOLID );
|
2020-09-26 18:23:13 +00:00
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
switch( Assignments.Codedefs.LineCodes.at( aCadstarLineCodeID ).Style )
|
|
|
|
{
|
|
|
|
case LINESTYLE::DASH: return PLOT_DASH_TYPE::DASH;
|
|
|
|
case LINESTYLE::DASHDOT: return PLOT_DASH_TYPE::DASHDOT;
|
|
|
|
case LINESTYLE::DASHDOTDOT: return PLOT_DASH_TYPE::DASHDOT; //TODO: update in future
|
|
|
|
case LINESTYLE::DOT: return PLOT_DASH_TYPE::DOT;
|
|
|
|
case LINESTYLE::SOLID: return PLOT_DASH_TYPE::SOLID;
|
|
|
|
default: return PLOT_DASH_TYPE::DEFAULT;
|
|
|
|
}
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
return PLOT_DASH_TYPE();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-19 22:05:02 +00:00
|
|
|
CADSTAR_SCH_ARCHIVE_LOADER::TEXTCODE CADSTAR_SCH_ARCHIVE_LOADER::getTextCode(
|
|
|
|
const TEXTCODE_ID& aCadstarTextCodeID )
|
|
|
|
{
|
|
|
|
wxCHECK( Assignments.Codedefs.TextCodes.find( aCadstarTextCodeID )
|
|
|
|
!= Assignments.Codedefs.TextCodes.end(),
|
2021-07-16 20:13:26 +00:00
|
|
|
TEXTCODE() );
|
2020-09-19 22:05:02 +00:00
|
|
|
|
|
|
|
return Assignments.Codedefs.TextCodes.at( aCadstarTextCodeID );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-01 19:12:56 +00:00
|
|
|
int CADSTAR_SCH_ARCHIVE_LOADER::getTextHeightFromTextCode( const TEXTCODE_ID& aCadstarTextCodeID )
|
|
|
|
{
|
|
|
|
TEXTCODE txtCode = getTextCode( aCadstarTextCodeID );
|
|
|
|
|
|
|
|
return KiROUND( (double) getKiCadLength( txtCode.Height ) * TXT_HEIGHT_RATIO );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-19 22:05:02 +00:00
|
|
|
wxString CADSTAR_SCH_ARCHIVE_LOADER::getAttributeName( const ATTRIBUTE_ID& aCadstarAttributeID )
|
|
|
|
{
|
|
|
|
wxCHECK( Assignments.Codedefs.AttributeNames.find( aCadstarAttributeID )
|
|
|
|
!= Assignments.Codedefs.AttributeNames.end(),
|
2021-07-16 20:13:26 +00:00
|
|
|
wxEmptyString );
|
2020-09-19 22:05:02 +00:00
|
|
|
|
|
|
|
return Assignments.Codedefs.AttributeNames.at( aCadstarAttributeID ).Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CADSTAR_SCH_ARCHIVE_LOADER::PART CADSTAR_SCH_ARCHIVE_LOADER::getPart(
|
|
|
|
const PART_ID& aCadstarPartID )
|
|
|
|
{
|
|
|
|
wxCHECK( Parts.PartDefinitions.find( aCadstarPartID ) != Parts.PartDefinitions.end(), PART() );
|
|
|
|
|
|
|
|
return Parts.PartDefinitions.at( aCadstarPartID );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CADSTAR_SCH_ARCHIVE_LOADER::ROUTECODE CADSTAR_SCH_ARCHIVE_LOADER::getRouteCode(
|
|
|
|
const ROUTECODE_ID& aCadstarRouteCodeID )
|
|
|
|
{
|
|
|
|
wxCHECK( Assignments.Codedefs.RouteCodes.find( aCadstarRouteCodeID )
|
|
|
|
!= Assignments.Codedefs.RouteCodes.end(),
|
2021-07-16 20:13:26 +00:00
|
|
|
ROUTECODE() );
|
2020-09-19 22:05:02 +00:00
|
|
|
|
|
|
|
return Assignments.Codedefs.RouteCodes.at( aCadstarRouteCodeID );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-20 21:08:46 +00:00
|
|
|
CADSTAR_SCH_ARCHIVE_LOADER::PART::DEFINITION::PIN CADSTAR_SCH_ARCHIVE_LOADER::getPartDefinitionPin(
|
|
|
|
const PART& aCadstarPart, const GATE_ID& aGateID, const TERMINAL_ID& aTerminalID )
|
|
|
|
{
|
|
|
|
for( std::pair<PART_DEFINITION_PIN_ID, PART::DEFINITION::PIN> pinPair :
|
|
|
|
aCadstarPart.Definition.Pins )
|
|
|
|
{
|
|
|
|
PART::DEFINITION::PIN partPin = pinPair.second;
|
|
|
|
|
|
|
|
if( partPin.TerminalGate == aGateID && partPin.TerminalPin == aTerminalID )
|
|
|
|
return partPin;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PART::DEFINITION::PIN();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-02 15:37:10 +00:00
|
|
|
ELECTRICAL_PINTYPE CADSTAR_SCH_ARCHIVE_LOADER::getKiCadPinType( const PART::PIN_TYPE& aPinType )
|
|
|
|
{
|
|
|
|
switch( aPinType )
|
|
|
|
{
|
|
|
|
case PART::PIN_TYPE::UNCOMMITTED: return ELECTRICAL_PINTYPE::PT_PASSIVE;
|
|
|
|
case PART::PIN_TYPE::INPUT: return ELECTRICAL_PINTYPE::PT_INPUT;
|
|
|
|
case PART::PIN_TYPE::OUTPUT_OR: return ELECTRICAL_PINTYPE::PT_OPENCOLLECTOR;
|
|
|
|
case PART::PIN_TYPE::OUTPUT_NOT_OR: return ELECTRICAL_PINTYPE::PT_OUTPUT;
|
|
|
|
case PART::PIN_TYPE::OUTPUT_NOT_NORM_OR: return ELECTRICAL_PINTYPE::PT_OUTPUT;
|
|
|
|
case PART::PIN_TYPE::POWER: return ELECTRICAL_PINTYPE::PT_POWER_IN;
|
|
|
|
case PART::PIN_TYPE::GROUND: return ELECTRICAL_PINTYPE::PT_POWER_IN;
|
|
|
|
case PART::PIN_TYPE::TRISTATE_BIDIR: return ELECTRICAL_PINTYPE::PT_BIDI;
|
|
|
|
case PART::PIN_TYPE::TRISTATE_INPUT: return ELECTRICAL_PINTYPE::PT_INPUT;
|
|
|
|
case PART::PIN_TYPE::TRISTATE_DRIVER: return ELECTRICAL_PINTYPE::PT_OUTPUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ELECTRICAL_PINTYPE::PT_UNSPECIFIED;
|
|
|
|
}
|
|
|
|
|
2020-09-19 22:05:02 +00:00
|
|
|
int CADSTAR_SCH_ARCHIVE_LOADER::getKiCadUnitNumberFromGate( const GATE_ID& aCadstarGateID )
|
|
|
|
{
|
|
|
|
if( aCadstarGateID.IsEmpty() )
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return (int) aCadstarGateID.Upper().GetChar( 0 ) - (int) wxUniChar( 'A' ) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
LABEL_SPIN_STYLE CADSTAR_SCH_ARCHIVE_LOADER::getSpinStyle( const long long& aCadstarOrientation,
|
|
|
|
bool aMirror )
|
2020-09-26 13:27:03 +00:00
|
|
|
{
|
|
|
|
double orientationDeciDegree = getAngleTenthDegree( aCadstarOrientation );
|
|
|
|
LABEL_SPIN_STYLE spinStyle = getSpinStyleDeciDeg( orientationDeciDegree );
|
|
|
|
|
|
|
|
if( aMirror )
|
|
|
|
{
|
|
|
|
spinStyle = spinStyle.RotateCCW();
|
|
|
|
spinStyle = spinStyle.RotateCCW();
|
|
|
|
}
|
|
|
|
|
|
|
|
return spinStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LABEL_SPIN_STYLE CADSTAR_SCH_ARCHIVE_LOADER::getSpinStyleDeciDeg(
|
|
|
|
const double& aOrientationDeciDeg )
|
2020-09-20 21:08:46 +00:00
|
|
|
{
|
|
|
|
LABEL_SPIN_STYLE spinStyle = LABEL_SPIN_STYLE::LEFT;
|
2020-09-26 13:27:03 +00:00
|
|
|
|
|
|
|
int oDeg = (int) NormalizeAngle180( aOrientationDeciDeg );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
if( oDeg >= -450 && oDeg <= 450 )
|
|
|
|
spinStyle = LABEL_SPIN_STYLE::RIGHT; // 0deg
|
|
|
|
else if( oDeg >= 450 && oDeg <= 1350 )
|
2021-02-04 17:51:27 +00:00
|
|
|
spinStyle = LABEL_SPIN_STYLE::UP; // 90deg
|
2020-09-20 21:08:46 +00:00
|
|
|
else if( oDeg >= 1350 || oDeg <= -1350 )
|
|
|
|
spinStyle = LABEL_SPIN_STYLE::LEFT; // 180deg
|
|
|
|
else
|
2021-02-04 17:51:27 +00:00
|
|
|
spinStyle = LABEL_SPIN_STYLE::BOTTOM; // 270deg
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
return spinStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-02 18:50:30 +00:00
|
|
|
CADSTAR_SCH_ARCHIVE_LOADER::ALIGNMENT
|
|
|
|
CADSTAR_SCH_ARCHIVE_LOADER::mirrorX( const ALIGNMENT& aCadstarAlignment )
|
|
|
|
{
|
|
|
|
switch( aCadstarAlignment )
|
|
|
|
{
|
|
|
|
// Change left to right:
|
|
|
|
case ALIGNMENT::NO_ALIGNMENT:
|
|
|
|
case ALIGNMENT::BOTTOMLEFT: return ALIGNMENT::BOTTOMRIGHT;
|
|
|
|
case ALIGNMENT::CENTERLEFT: return ALIGNMENT::CENTERRIGHT;
|
|
|
|
case ALIGNMENT::TOPLEFT: return ALIGNMENT::TOPRIGHT;
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2021-04-02 18:50:30 +00:00
|
|
|
//Change right to left:
|
|
|
|
case ALIGNMENT::BOTTOMRIGHT: return ALIGNMENT::BOTTOMLEFT;
|
|
|
|
case ALIGNMENT::CENTERRIGHT: return ALIGNMENT::CENTERLEFT;
|
|
|
|
case ALIGNMENT::TOPRIGHT: return ALIGNMENT::TOPLEFT;
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2021-04-02 18:50:30 +00:00
|
|
|
// Center alignment does not mirror:
|
|
|
|
case ALIGNMENT::BOTTOMCENTER:
|
|
|
|
case ALIGNMENT::CENTERCENTER:
|
|
|
|
case ALIGNMENT::TOPCENTER: return aCadstarAlignment;
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2021-04-02 18:50:30 +00:00
|
|
|
// Shouldn't be here
|
2022-02-08 23:14:18 +00:00
|
|
|
default: wxFAIL_MSG( wxT( "Unknown Cadstar Alignment" ) ); return aCadstarAlignment;
|
2021-04-02 18:50:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CADSTAR_SCH_ARCHIVE_LOADER::ALIGNMENT
|
|
|
|
CADSTAR_SCH_ARCHIVE_LOADER::rotate180( const ALIGNMENT& aCadstarAlignment )
|
|
|
|
{
|
|
|
|
switch( aCadstarAlignment )
|
|
|
|
{
|
|
|
|
case ALIGNMENT::NO_ALIGNMENT:
|
|
|
|
case ALIGNMENT::BOTTOMLEFT: return ALIGNMENT::TOPRIGHT;
|
|
|
|
case ALIGNMENT::BOTTOMCENTER: return ALIGNMENT::TOPCENTER;
|
|
|
|
case ALIGNMENT::BOTTOMRIGHT: return ALIGNMENT::TOPLEFT;
|
|
|
|
case ALIGNMENT::TOPLEFT: return ALIGNMENT::BOTTOMRIGHT;
|
|
|
|
case ALIGNMENT::TOPCENTER: return ALIGNMENT::BOTTOMCENTER;
|
|
|
|
case ALIGNMENT::TOPRIGHT: return ALIGNMENT::BOTTOMLEFT;
|
|
|
|
case ALIGNMENT::CENTERLEFT: return ALIGNMENT::CENTERRIGHT;
|
|
|
|
case ALIGNMENT::CENTERCENTER: return ALIGNMENT::CENTERCENTER;
|
|
|
|
case ALIGNMENT::CENTERRIGHT: return ALIGNMENT::CENTERLEFT;
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2021-04-02 18:50:30 +00:00
|
|
|
// Shouldn't be here
|
2022-02-08 23:14:18 +00:00
|
|
|
default: wxFAIL_MSG( wxT( "Unknown Cadstar Alignment" ) ); return aCadstarAlignment;
|
2021-04-02 18:50:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::applyTextSettings( EDA_TEXT* aKiCadTextItem,
|
|
|
|
const TEXTCODE_ID& aCadstarTextCodeID,
|
|
|
|
const ALIGNMENT& aCadstarAlignment,
|
|
|
|
const JUSTIFICATION& aCadstarJustification,
|
|
|
|
const long long aCadstarOrientAngle,
|
|
|
|
bool aMirrored )
|
2020-09-19 22:05:02 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
// Justification ignored for now as not supported in Eeschema, but leaving this code in
|
2021-04-02 18:50:30 +00:00
|
|
|
// place for future upgrades.
|
2021-07-16 20:13:26 +00:00
|
|
|
// TODO update this when Eeschema supports justification independent of anchor position.
|
2021-04-02 18:50:30 +00:00
|
|
|
|
2020-09-19 22:05:02 +00:00
|
|
|
TEXTCODE textCode = getTextCode( aCadstarTextCodeID );
|
2020-12-30 02:04:19 +00:00
|
|
|
int textHeight = KiROUND( (double) getKiCadLength( textCode.Height ) * TXT_HEIGHT_RATIO );
|
2021-02-04 18:57:09 +00:00
|
|
|
int textWidth = getKiCadLength( textCode.Width );
|
|
|
|
|
2021-09-01 18:24:42 +00:00
|
|
|
// Ensure we have no Cadstar overbar characters
|
|
|
|
wxString escapedText = HandleTextOverbar( aKiCadTextItem->GetText() );
|
2021-03-28 15:45:26 +00:00
|
|
|
aKiCadTextItem->SetText( escapedText );
|
|
|
|
|
|
|
|
// The width is zero for all non-cadstar fonts. Using a width equal to 2/3 the height seems
|
2021-02-04 18:57:09 +00:00
|
|
|
// to work well for most fonts.
|
|
|
|
if( textWidth == 0 )
|
2021-03-28 15:45:26 +00:00
|
|
|
textWidth = getKiCadLength( 2 * textCode.Height / 3 );
|
2021-02-04 18:57:09 +00:00
|
|
|
|
|
|
|
aKiCadTextItem->SetTextWidth( textWidth );
|
2020-12-30 02:04:19 +00:00
|
|
|
aKiCadTextItem->SetTextHeight( textHeight );
|
2020-09-19 22:05:02 +00:00
|
|
|
aKiCadTextItem->SetTextThickness( getKiCadLength( textCode.LineWidth ) );
|
2021-04-02 18:50:30 +00:00
|
|
|
aKiCadTextItem->SetTextAngle( getAngleTenthDegree( aCadstarOrientAngle ) );
|
|
|
|
aKiCadTextItem->SetBold( textCode.Font.Modifier1 == FONT_BOLD );
|
|
|
|
aKiCadTextItem->SetItalic( textCode.Font.Italic );
|
2020-09-19 22:05:02 +00:00
|
|
|
|
2021-04-02 18:50:30 +00:00
|
|
|
ALIGNMENT textAlignment = aCadstarAlignment;
|
|
|
|
|
|
|
|
// KiCad mirrors the justification and alignment when the symbol is mirrored but CADSTAR
|
|
|
|
// specifies it post-mirroring. In contrast, if the text item itself is mirrored (not
|
|
|
|
// supported in KiCad), CADSTAR specifies the alignment and justification pre-mirroring
|
|
|
|
if( aMirrored )
|
|
|
|
textAlignment = mirrorX( aCadstarAlignment );
|
|
|
|
|
|
|
|
auto setAlignment = [&]( EDA_TEXT* aText, ALIGNMENT aAlignment )
|
|
|
|
{
|
|
|
|
switch( aAlignment )
|
|
|
|
{
|
|
|
|
case ALIGNMENT::NO_ALIGNMENT: // Bottom left of the first line
|
|
|
|
//No exact KiCad equivalent, so lets move the position of the text
|
|
|
|
FixTextPositionNoAlignment( aText );
|
|
|
|
KI_FALLTHROUGH;
|
|
|
|
case ALIGNMENT::BOTTOMLEFT:
|
|
|
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::BOTTOMCENTER:
|
|
|
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::BOTTOMRIGHT:
|
|
|
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM );
|
|
|
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::CENTERLEFT:
|
|
|
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
|
|
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::CENTERCENTER:
|
|
|
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
|
|
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::CENTERRIGHT:
|
|
|
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER );
|
|
|
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::TOPLEFT:
|
|
|
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::TOPCENTER:
|
|
|
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGNMENT::TOPRIGHT:
|
|
|
|
aText->SetVertJustify( GR_TEXT_VJUSTIFY_TOP );
|
|
|
|
aText->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
LABEL_SPIN_STYLE spin = getSpinStyle( aCadstarOrientAngle, aMirrored );
|
|
|
|
EDA_ITEM* textEdaItem = dynamic_cast<EDA_ITEM*>( aKiCadTextItem );
|
|
|
|
wxCHECK( textEdaItem, /* void */ ); // ensure this is a EDA_ITEM
|
|
|
|
|
|
|
|
switch( textEdaItem->Type() )
|
|
|
|
{
|
|
|
|
// Some KiCad schematic text items only permit a limited amount of angles
|
|
|
|
// and text justifications
|
2021-04-09 19:11:12 +00:00
|
|
|
case LIB_TEXT_T:
|
2021-04-02 18:50:30 +00:00
|
|
|
case SCH_FIELD_T:
|
|
|
|
case LIB_FIELD_T:
|
|
|
|
{
|
|
|
|
// Spin style not used. All text justifications are permitted. However, only orientations
|
|
|
|
// of 0 deg or 90 deg are supported
|
|
|
|
double angleDeciDeg = NormalizeAnglePos( aKiCadTextItem->GetTextAngle() );
|
|
|
|
int quadrant = KiROUND( angleDeciDeg / 900.0 );
|
|
|
|
quadrant %= 4;
|
|
|
|
|
|
|
|
switch( quadrant )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
angleDeciDeg = 0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
angleDeciDeg = 900;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
angleDeciDeg = 0;
|
|
|
|
textAlignment = rotate180( textAlignment );
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
angleDeciDeg = 900;
|
|
|
|
textAlignment = rotate180( textAlignment );
|
|
|
|
break;
|
2022-02-08 23:14:18 +00:00
|
|
|
default: wxFAIL_MSG( wxT( "Unknown Quadrant" ) );
|
2021-04-02 18:50:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aKiCadTextItem->SetTextAngle( angleDeciDeg );
|
|
|
|
setAlignment( aKiCadTextItem, textAlignment );
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case SCH_TEXT_T:
|
2020-09-19 22:05:02 +00:00
|
|
|
{
|
2021-04-02 18:50:30 +00:00
|
|
|
// Note spin style in a SCH_TEXT results in a vertical alignment GR_TEXT_VJUSTIFY_BOTTOM
|
|
|
|
// so need to adjust the location of the text element based on Cadstar's original text
|
|
|
|
// alignment (anchor position).
|
|
|
|
setAlignment( aKiCadTextItem, textAlignment );
|
|
|
|
EDA_RECT bb = textEdaItem->GetBoundingBox();
|
|
|
|
int off = static_cast<SCH_TEXT*>( aKiCadTextItem )->GetTextOffset();
|
|
|
|
wxPoint pos;
|
2020-09-19 22:05:02 +00:00
|
|
|
|
2021-04-02 18:50:30 +00:00
|
|
|
// Change the anchor point of the text item to make it match the same bounding box
|
2021-06-09 19:32:58 +00:00
|
|
|
// And correct the error introduced by the text offsetting in KiCad
|
2021-04-02 18:50:30 +00:00
|
|
|
switch( spin )
|
|
|
|
{
|
|
|
|
case LABEL_SPIN_STYLE::BOTTOM: pos = { bb.GetRight() - off, bb.GetTop() }; break;
|
|
|
|
case LABEL_SPIN_STYLE::UP: pos = { bb.GetRight() - off, bb.GetBottom() }; break;
|
|
|
|
case LABEL_SPIN_STYLE::LEFT: pos = { bb.GetRight() , bb.GetBottom() + off }; break;
|
|
|
|
case LABEL_SPIN_STYLE::RIGHT: pos = { bb.GetLeft() , bb.GetBottom() + off }; break;
|
|
|
|
}
|
2020-09-19 22:05:02 +00:00
|
|
|
|
2021-04-02 18:50:30 +00:00
|
|
|
aKiCadTextItem->SetTextPos( pos );
|
|
|
|
}
|
|
|
|
KI_FALLTHROUGH;
|
2020-09-19 22:05:02 +00:00
|
|
|
|
2021-04-02 18:50:30 +00:00
|
|
|
// We don't want to change position of net labels as that would break connectivity
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
|
|
|
case SCH_HIER_LABEL_T:
|
|
|
|
case SCH_SHEET_PIN_T:
|
|
|
|
static_cast<SCH_TEXT*>( aKiCadTextItem )->SetLabelSpinStyle( spin );
|
|
|
|
return;
|
2020-09-19 22:05:02 +00:00
|
|
|
|
2021-04-02 18:50:30 +00:00
|
|
|
default:
|
2022-02-08 23:14:18 +00:00
|
|
|
wxFAIL_MSG( wxT( "Unexpected item type" ) );
|
2021-04-02 18:50:30 +00:00
|
|
|
return;
|
2020-09-19 22:05:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2020-09-27 02:35:24 +00:00
|
|
|
SCH_TEXT* CADSTAR_SCH_ARCHIVE_LOADER::getKiCadSchText( const TEXT& aCadstarTextElement )
|
|
|
|
{
|
|
|
|
SCH_TEXT* kiTxt = new SCH_TEXT();
|
|
|
|
|
2021-04-02 18:50:30 +00:00
|
|
|
kiTxt->SetParent( m_schematic ); // set to the schematic for now to avoid asserts
|
2020-09-27 02:35:24 +00:00
|
|
|
kiTxt->SetPosition( getKiCadPoint( aCadstarTextElement.Position ) );
|
|
|
|
kiTxt->SetText( aCadstarTextElement.Text );
|
2021-04-02 18:50:30 +00:00
|
|
|
|
|
|
|
applyTextSettings( kiTxt,
|
|
|
|
aCadstarTextElement.TextCodeID,
|
|
|
|
aCadstarTextElement.Alignment,
|
|
|
|
aCadstarTextElement.Justification,
|
|
|
|
aCadstarTextElement.OrientAngle,
|
|
|
|
aCadstarTextElement.Mirror );
|
2020-09-27 02:35:24 +00:00
|
|
|
|
|
|
|
return kiTxt;
|
|
|
|
}
|
|
|
|
|
2020-09-19 22:05:02 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* CADSTAR_SCH_ARCHIVE_LOADER::getScaledLibPart( const LIB_SYMBOL* aSymbol,
|
|
|
|
long long aScalingFactorNumerator,
|
|
|
|
long long aScalingFactorDenominator )
|
2021-05-28 15:19:04 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* retval = new LIB_SYMBOL( *aSymbol );
|
2021-05-28 15:19:04 +00:00
|
|
|
|
|
|
|
if( aScalingFactorNumerator == aScalingFactorDenominator )
|
|
|
|
return retval; // 1:1 scale, nothing to do
|
|
|
|
|
|
|
|
auto scaleLen =
|
|
|
|
[&]( int aLength ) -> int
|
|
|
|
{
|
|
|
|
return( aLength * aScalingFactorNumerator ) / aScalingFactorDenominator;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto scalePt =
|
|
|
|
[&]( wxPoint aCoord ) -> wxPoint
|
|
|
|
{
|
|
|
|
return wxPoint( scaleLen( aCoord.x ), scaleLen( aCoord.y ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
auto scaleSize =
|
|
|
|
[&]( wxSize aSize ) -> wxSize
|
|
|
|
{
|
|
|
|
return wxSize( scaleLen( aSize.x ), scaleLen( aSize.y ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
LIB_ITEMS_CONTAINER& items = retval->GetDrawItems();
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
for( LIB_ITEM& item : items )
|
2021-05-28 15:19:04 +00:00
|
|
|
{
|
|
|
|
switch( item.Type() )
|
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
case KICAD_T::LIB_SHAPE_T:
|
2021-05-28 15:19:04 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
LIB_SHAPE& shape = static_cast<LIB_SHAPE&>( item );
|
2021-05-28 15:19:04 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
if( shape.GetShape() == SHAPE_T::ARC )
|
|
|
|
{
|
|
|
|
shape.SetPosition( scalePt( shape.GetPosition() ) );
|
|
|
|
shape.SetStart( scalePt( shape.GetStart() ) );
|
|
|
|
shape.SetEnd( scalePt( shape.GetEnd() ) );
|
|
|
|
}
|
|
|
|
else if( shape.GetShape() == SHAPE_T::POLY )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN& poly = shape.GetPolyShape().Outline( 0 );
|
2021-05-28 15:19:04 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
for( size_t ii = 0; ii < poly.GetPointCount(); ++ii )
|
|
|
|
poly.SetPoint( ii, scalePt( (wxPoint) poly.CPoint( ii ) ) );
|
|
|
|
}
|
2021-05-28 15:19:04 +00:00
|
|
|
}
|
2021-07-18 23:08:54 +00:00
|
|
|
break;
|
2021-05-28 15:19:04 +00:00
|
|
|
|
|
|
|
case KICAD_T::LIB_PIN_T:
|
|
|
|
{
|
|
|
|
LIB_PIN& pin = static_cast<LIB_PIN&>( item );
|
|
|
|
|
|
|
|
pin.SetPosition( scalePt( pin.GetPosition() ) );
|
|
|
|
pin.SetLength( scaleLen( pin.GetLength() ) );
|
|
|
|
}
|
2021-07-18 23:08:54 +00:00
|
|
|
break;
|
2021-05-28 15:19:04 +00:00
|
|
|
|
|
|
|
case KICAD_T::LIB_TEXT_T:
|
|
|
|
{
|
|
|
|
LIB_TEXT& txt = static_cast<LIB_TEXT&>( item );
|
|
|
|
|
|
|
|
txt.SetPosition( scalePt( txt.GetPosition() ) );
|
|
|
|
txt.SetTextSize( scaleSize( txt.GetTextSize() ) );
|
|
|
|
}
|
2021-07-18 23:08:54 +00:00
|
|
|
break;
|
2021-05-28 15:19:04 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
default:
|
|
|
|
break;
|
2021-05-28 15:19:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2021-05-28 18:39:08 +00:00
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void CADSTAR_SCH_ARCHIVE_LOADER::fixUpLibraryPins( LIB_SYMBOL* aSymbolToFix, int aGateNumber )
|
2021-05-28 18:39:08 +00:00
|
|
|
{
|
2021-10-30 18:20:52 +00:00
|
|
|
auto compLambda = []( const VECTOR2I& aA, const VECTOR2I& aB )
|
|
|
|
{
|
|
|
|
return LexicographicalCompare( aA, aB ) < 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Store a list of vertical or horizontal segments in the symbol
|
|
|
|
// Note: Need the custom comparison function to ensure the map is sorted correctly
|
|
|
|
std::map<VECTOR2I, SHAPE_LINE_CHAIN, decltype( compLambda )> uniqueSegments( compLambda );
|
2021-05-28 18:39:08 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
LIB_ITEMS_CONTAINER::ITERATOR shapeIt = aSymbolToFix->GetDrawItems().begin( LIB_SHAPE_T );
|
2021-05-28 18:39:08 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
for( ; shapeIt != aSymbolToFix->GetDrawItems().end( LIB_SHAPE_T ); ++shapeIt )
|
2021-05-28 18:39:08 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
LIB_SHAPE& shape = static_cast<LIB_SHAPE&>( *shapeIt );
|
2021-05-28 18:39:08 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
if( aGateNumber > 0 && shape.GetUnit() != aGateNumber )
|
2021-05-28 18:39:08 +00:00
|
|
|
continue;
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
if( shape.GetShape() != SHAPE_T::POLY )
|
|
|
|
continue;
|
2021-05-28 18:39:08 +00:00
|
|
|
|
2021-10-30 18:20:52 +00:00
|
|
|
SHAPE_LINE_CHAIN poly = shape.GetPolyShape().Outline( 0 );
|
2021-05-28 18:39:08 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
if( poly.GetPointCount() == 2 )
|
2021-05-28 18:39:08 +00:00
|
|
|
{
|
2021-10-30 18:20:52 +00:00
|
|
|
VECTOR2I pt0 = poly.CPoint( 0 );
|
|
|
|
VECTOR2I pt1 = poly.CPoint( 1 );
|
2021-05-28 18:39:08 +00:00
|
|
|
|
2021-10-30 18:20:52 +00:00
|
|
|
if( pt0 != pt1 && uniqueSegments.count( pt0 ) == 0 && uniqueSegments.count( pt1 ) == 0 )
|
2021-05-28 18:39:08 +00:00
|
|
|
{
|
2021-10-17 12:43:01 +00:00
|
|
|
// we are only interested in vertical or horizontal segments
|
2021-05-28 18:39:08 +00:00
|
|
|
if( pt0.x == pt1.x || pt0.y == pt1.y )
|
|
|
|
{
|
2021-10-30 18:20:52 +00:00
|
|
|
uniqueSegments.insert( { pt0, poly } );
|
|
|
|
uniqueSegments.insert( { pt1, poly } );
|
2021-05-28 18:39:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LIB_PINS pins;
|
2021-06-10 18:51:46 +00:00
|
|
|
aSymbolToFix->GetPins( pins, aGateNumber );
|
2021-05-28 18:39:08 +00:00
|
|
|
|
|
|
|
for( auto& pin : pins )
|
|
|
|
{
|
|
|
|
auto setPinOrientation =
|
|
|
|
[&]( double aAngleRad )
|
|
|
|
{
|
2021-05-28 19:37:57 +00:00
|
|
|
int oDeg = (int) NormalizeAngle180( RAD2DEG( aAngleRad ) );
|
2021-05-28 18:39:08 +00:00
|
|
|
|
|
|
|
if( oDeg >= -45 && oDeg <= 45 )
|
|
|
|
pin->SetOrientation( 'R' ); // 0 degrees
|
|
|
|
else if( oDeg >= 45 && oDeg <= 135 )
|
|
|
|
pin->SetOrientation( 'U' ); // 90 degrees
|
|
|
|
else if( oDeg >= 135 || oDeg <= -135 )
|
|
|
|
pin->SetOrientation( 'L' ); // 180 degrees
|
|
|
|
else
|
|
|
|
pin->SetOrientation( 'D' ); // -90 degrees
|
|
|
|
};
|
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
if( uniqueSegments.count( pin->GetPosition() ) )
|
2021-05-28 18:39:08 +00:00
|
|
|
{
|
2021-07-18 23:08:54 +00:00
|
|
|
SHAPE_LINE_CHAIN& poly = uniqueSegments.at( pin->GetPosition() );
|
2021-05-28 18:39:08 +00:00
|
|
|
|
2021-07-18 23:08:54 +00:00
|
|
|
VECTOR2I otherPt = poly.CPoint( 0 );
|
2021-05-28 18:39:08 +00:00
|
|
|
|
|
|
|
if( otherPt == pin->GetPosition() )
|
2021-07-18 23:08:54 +00:00
|
|
|
otherPt = poly.CPoint( 1 );
|
2021-05-28 18:39:08 +00:00
|
|
|
|
|
|
|
VECTOR2I vec( otherPt - pin->GetPosition() );
|
|
|
|
|
|
|
|
pin->SetLength( vec.EuclideanNorm() );
|
|
|
|
setPinOrientation( vec.Angle() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
std::pair<wxPoint, wxSize> CADSTAR_SCH_ARCHIVE_LOADER::getFigureExtentsKiCad(
|
2020-09-19 22:05:02 +00:00
|
|
|
const FIGURE& aCadstarFigure )
|
|
|
|
{
|
|
|
|
wxPoint upperLeft( Assignments.Settings.DesignLimit.x, 0 );
|
|
|
|
wxPoint lowerRight( 0, Assignments.Settings.DesignLimit.y );
|
|
|
|
|
|
|
|
for( const VERTEX& v : aCadstarFigure.Shape.Vertices )
|
|
|
|
{
|
|
|
|
if( upperLeft.x > v.End.x )
|
|
|
|
upperLeft.x = v.End.x;
|
|
|
|
|
|
|
|
if( upperLeft.y < v.End.y )
|
|
|
|
upperLeft.y = v.End.y;
|
|
|
|
|
|
|
|
if( lowerRight.x < v.End.x )
|
|
|
|
lowerRight.x = v.End.x;
|
|
|
|
|
|
|
|
if( lowerRight.y > v.End.y )
|
|
|
|
lowerRight.y = v.End.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( CUTOUT cutout : aCadstarFigure.Shape.Cutouts )
|
|
|
|
{
|
|
|
|
for( const VERTEX& v : aCadstarFigure.Shape.Vertices )
|
|
|
|
{
|
|
|
|
if( upperLeft.x > v.End.x )
|
|
|
|
upperLeft.x = v.End.x;
|
|
|
|
|
|
|
|
if( upperLeft.y < v.End.y )
|
|
|
|
upperLeft.y = v.End.y;
|
|
|
|
|
|
|
|
if( lowerRight.x < v.End.x )
|
|
|
|
lowerRight.x = v.End.x;
|
|
|
|
|
|
|
|
if( lowerRight.y > v.End.y )
|
|
|
|
lowerRight.y = v.End.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxPoint upperLeftKiCad = getKiCadPoint( upperLeft );
|
|
|
|
wxPoint lowerRightKiCad = getKiCadPoint( lowerRight );
|
|
|
|
|
|
|
|
wxPoint size = lowerRightKiCad - upperLeftKiCad;
|
|
|
|
|
|
|
|
return { upperLeftKiCad, wxSize( abs( size.x ), abs( size.y ) ) };
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-26 19:35:12 +00:00
|
|
|
wxPoint CADSTAR_SCH_ARCHIVE_LOADER::getKiCadPoint( const wxPoint& aCadstarPoint )
|
2020-09-19 22:05:02 +00:00
|
|
|
{
|
|
|
|
wxPoint retval;
|
|
|
|
|
2021-02-18 18:02:49 +00:00
|
|
|
retval.x = getKiCadLength( aCadstarPoint.x - m_designCenter.x );
|
|
|
|
retval.y = -getKiCadLength( aCadstarPoint.y - m_designCenter.y );
|
2020-09-19 22:05:02 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-26 19:35:12 +00:00
|
|
|
wxPoint CADSTAR_SCH_ARCHIVE_LOADER::getKiCadLibraryPoint( const wxPoint& aCadstarPoint,
|
|
|
|
const wxPoint& aCadstarCentre )
|
2020-09-19 22:05:02 +00:00
|
|
|
{
|
2020-09-20 21:08:46 +00:00
|
|
|
wxPoint retval;
|
|
|
|
|
2021-02-18 18:02:49 +00:00
|
|
|
retval.x = getKiCadLength( aCadstarPoint.x - aCadstarCentre.x );
|
|
|
|
retval.y = getKiCadLength( aCadstarPoint.y - aCadstarCentre.y );
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2020-09-08 19:51:22 +00:00
|
|
|
|
2020-09-20 21:08:46 +00:00
|
|
|
|
2020-09-27 12:19:51 +00:00
|
|
|
wxPoint CADSTAR_SCH_ARCHIVE_LOADER::applyTransform( const wxPoint& aPoint,
|
|
|
|
const wxPoint& aMoveVector, const double& aRotationAngleDeciDeg,
|
|
|
|
const double& aScalingFactor, const wxPoint& aTransformCentre, const bool& aMirrorInvert )
|
|
|
|
{
|
|
|
|
wxPoint retVal = aPoint;
|
|
|
|
|
|
|
|
if( aScalingFactor != 1.0 )
|
|
|
|
{
|
|
|
|
//scale point
|
|
|
|
retVal -= aTransformCentre;
|
|
|
|
retVal.x = KiROUND( retVal.x * aScalingFactor );
|
|
|
|
retVal.y = KiROUND( retVal.y * aScalingFactor );
|
|
|
|
retVal += aTransformCentre;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aMirrorInvert )
|
|
|
|
{
|
|
|
|
MIRROR( retVal.x, aTransformCentre.x );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aRotationAngleDeciDeg != 0.0 )
|
|
|
|
{
|
|
|
|
RotatePoint( &retVal, aTransformCentre, aRotationAngleDeciDeg );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aMoveVector != wxPoint{ 0, 0 } )
|
|
|
|
{
|
|
|
|
retVal += aMoveVector;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-26 19:35:12 +00:00
|
|
|
double CADSTAR_SCH_ARCHIVE_LOADER::getPolarAngle( const wxPoint& aPoint )
|
2020-09-20 21:08:46 +00:00
|
|
|
{
|
2020-09-19 22:05:02 +00:00
|
|
|
return NormalizeAnglePos( ArcTangente( aPoint.y, aPoint.x ) );
|
2020-09-08 19:51:22 +00:00
|
|
|
}
|
2020-09-20 21:08:46 +00:00
|
|
|
|
|
|
|
|
2021-07-26 19:35:12 +00:00
|
|
|
double CADSTAR_SCH_ARCHIVE_LOADER::getPolarRadius( const wxPoint& aPoint )
|
2020-09-20 21:08:46 +00:00
|
|
|
{
|
|
|
|
return sqrt(
|
|
|
|
( (double) aPoint.x * (double) aPoint.x ) + ( (double) aPoint.y * (double) aPoint.y ) );
|
|
|
|
}
|