2020-05-13 02:00:37 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-02-01 19:14:26 +00:00
|
|
|
* Copyright (C) 2020-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-05-13 02:00:37 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <bus_alias.h>
|
2023-11-29 02:57:41 +00:00
|
|
|
#include <commit.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <connection_graph.h>
|
2023-08-13 23:50:05 +00:00
|
|
|
#include <core/ignore.h>
|
2023-02-01 19:14:26 +00:00
|
|
|
#include <core/kicad_algo.h>
|
2023-11-29 02:57:41 +00:00
|
|
|
#include <ee_collectors.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <erc_settings.h>
|
2020-11-18 22:55:38 +00:00
|
|
|
#include <sch_marker.h>
|
2020-06-08 02:19:46 +00:00
|
|
|
#include <project.h>
|
|
|
|
#include <project/project_file.h>
|
2020-07-06 10:51:04 +00:00
|
|
|
#include <project/net_settings.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2022-08-18 21:19:28 +00:00
|
|
|
#include <sch_junction.h>
|
|
|
|
#include <sch_line.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <sch_screen.h>
|
2021-03-22 21:42:54 +00:00
|
|
|
#include <sim/spice_settings.h>
|
2022-11-03 04:12:53 +00:00
|
|
|
#include <sch_label.h>
|
2023-02-05 20:47:27 +00:00
|
|
|
#include <sim/spice_value.h>
|
2023-02-09 17:18:56 +00:00
|
|
|
#include <netlist_exporter_spice.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
|
2020-05-21 02:27:48 +00:00
|
|
|
SCHEMATIC::SCHEMATIC( PROJECT* aPrj ) :
|
2020-05-13 02:00:37 +00:00
|
|
|
EDA_ITEM( nullptr, SCHEMATIC_T ),
|
2020-07-03 12:21:19 +00:00
|
|
|
m_project( nullptr ),
|
2020-05-13 02:00:37 +00:00
|
|
|
m_rootSheet( nullptr )
|
|
|
|
{
|
|
|
|
m_currentSheet = new SCH_SHEET_PATH();
|
|
|
|
m_connectionGraph = new CONNECTION_GRAPH( this );
|
2020-06-08 02:19:46 +00:00
|
|
|
|
|
|
|
SetProject( aPrj );
|
2023-11-29 02:57:41 +00:00
|
|
|
|
|
|
|
PROPERTY_MANAGER::Instance().RegisterListener( TYPE_HASH( SCH_FIELD ),
|
|
|
|
[&]( INSPECTABLE* aItem, PROPERTY_BASE* aProperty, COMMIT* aCommit )
|
|
|
|
{
|
|
|
|
// Special case: propagate value, footprint, and datasheet fields to other units
|
|
|
|
// of a given symbol if they aren't in the selection
|
|
|
|
|
|
|
|
SCH_FIELD* field = dynamic_cast<SCH_FIELD*>( aItem );
|
|
|
|
|
|
|
|
if( !field || !IsValid() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( field->GetParent() );
|
|
|
|
|
|
|
|
if( !symbol || aProperty->Name() != _HKI( "Text" ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// TODO(JE) This will need to get smarter to enable API access
|
|
|
|
SCH_SHEET_PATH sheetPath = CurrentSheet();
|
|
|
|
|
|
|
|
wxString newValue = aItem->Get<wxString>( aProperty );
|
|
|
|
|
|
|
|
wxString ref = symbol->GetRef( &sheetPath );
|
|
|
|
int unit = symbol->GetUnit();
|
|
|
|
LIB_ID libId = symbol->GetLibId();
|
|
|
|
|
|
|
|
for( SCH_SHEET_PATH& sheet : GetSheets() )
|
|
|
|
{
|
|
|
|
std::vector<SCH_SYMBOL*> otherUnits;
|
|
|
|
|
|
|
|
CollectOtherUnits( ref, unit, libId, sheet, &otherUnits );
|
|
|
|
|
|
|
|
for( SCH_SYMBOL* otherUnit : otherUnits )
|
|
|
|
{
|
|
|
|
switch( field->GetId() )
|
|
|
|
{
|
|
|
|
case VALUE_FIELD:
|
|
|
|
{
|
|
|
|
if( aCommit )
|
|
|
|
aCommit->Modify( otherUnit, sheet.LastScreen() );
|
|
|
|
|
|
|
|
otherUnit->SetValueFieldText( newValue );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case FOOTPRINT_FIELD:
|
|
|
|
{
|
|
|
|
if( aCommit )
|
|
|
|
aCommit->Modify( otherUnit, sheet.LastScreen() );
|
|
|
|
|
|
|
|
otherUnit->SetFootprintFieldText( newValue );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DATASHEET_FIELD:
|
|
|
|
{
|
|
|
|
if( aCommit )
|
|
|
|
aCommit->Modify( otherUnit, sheet.LastScreen() );
|
|
|
|
|
|
|
|
otherUnit->GetField( DATASHEET_FIELD )->SetText( newValue );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
2020-05-13 02:00:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCHEMATIC::~SCHEMATIC()
|
|
|
|
{
|
|
|
|
delete m_currentSheet;
|
|
|
|
delete m_connectionGraph;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCHEMATIC::Reset()
|
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
if( m_project )
|
|
|
|
{
|
|
|
|
PROJECT_FILE& project = m_project->GetProjectFile();
|
|
|
|
|
2023-08-18 21:15:33 +00:00
|
|
|
// d'tor will save settings to file
|
2020-06-08 02:19:46 +00:00
|
|
|
delete project.m_ErcSettings;
|
2023-08-18 21:15:33 +00:00
|
|
|
project.m_ErcSettings = nullptr;
|
2020-06-08 02:19:46 +00:00
|
|
|
|
2023-08-18 21:15:33 +00:00
|
|
|
// d'tor will save settings to file
|
|
|
|
delete project.m_SchematicSettings;
|
2020-06-08 02:19:46 +00:00
|
|
|
project.m_SchematicSettings = nullptr;
|
2021-05-01 22:27:23 +00:00
|
|
|
|
|
|
|
m_project = nullptr; // clear the project, so we don't do this again when setting a new one
|
2020-06-08 02:19:46 +00:00
|
|
|
}
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
delete m_rootSheet;
|
|
|
|
|
|
|
|
m_rootSheet = nullptr;
|
|
|
|
|
|
|
|
m_connectionGraph->Reset();
|
|
|
|
m_currentSheet->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
void SCHEMATIC::SetProject( PROJECT* aPrj )
|
|
|
|
{
|
2020-07-03 03:55:46 +00:00
|
|
|
if( m_project )
|
|
|
|
{
|
|
|
|
PROJECT_FILE& project = m_project->GetProjectFile();
|
|
|
|
|
2023-08-18 21:15:33 +00:00
|
|
|
// d'tor will save settings to file
|
2020-07-03 03:55:46 +00:00
|
|
|
delete project.m_ErcSettings;
|
2023-08-18 21:15:33 +00:00
|
|
|
project.m_ErcSettings = nullptr;
|
2020-07-03 03:55:46 +00:00
|
|
|
|
2023-08-18 21:15:33 +00:00
|
|
|
// d'tor will save settings to file
|
|
|
|
delete project.m_SchematicSettings;
|
2020-07-03 03:55:46 +00:00
|
|
|
project.m_SchematicSettings = nullptr;
|
|
|
|
}
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
m_project = aPrj;
|
|
|
|
|
|
|
|
if( m_project )
|
|
|
|
{
|
|
|
|
PROJECT_FILE& project = m_project->GetProjectFile();
|
|
|
|
project.m_ErcSettings = new ERC_SETTINGS( &project, "erc" );
|
|
|
|
project.m_SchematicSettings = new SCHEMATIC_SETTINGS( &project, "schematic" );
|
|
|
|
|
|
|
|
project.m_SchematicSettings->LoadFromFile();
|
2023-07-14 09:21:58 +00:00
|
|
|
project.m_SchematicSettings->m_NgspiceSettings->LoadFromFile();
|
2020-06-08 02:19:46 +00:00
|
|
|
project.m_ErcSettings->LoadFromFile();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-23 19:11:02 +00:00
|
|
|
void SCHEMATIC::SetRoot( SCH_SHEET* aRootSheet )
|
|
|
|
{
|
2023-01-17 04:14:38 +00:00
|
|
|
wxCHECK_RET( aRootSheet, wxS( "Call to SetRoot with null SCH_SHEET!" ) );
|
2020-05-23 19:11:02 +00:00
|
|
|
|
|
|
|
m_rootSheet = aRootSheet;
|
|
|
|
|
2020-07-05 00:48:55 +00:00
|
|
|
m_currentSheet->clear();
|
|
|
|
m_currentSheet->push_back( m_rootSheet );
|
|
|
|
|
2020-05-23 19:11:02 +00:00
|
|
|
m_connectionGraph->Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
SCH_SCREEN* SCHEMATIC::RootScreen() const
|
|
|
|
{
|
|
|
|
return IsValid() ? m_rootSheet->GetScreen() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-01 19:14:26 +00:00
|
|
|
void SCHEMATIC::GetContextualTextVars( wxArrayString* aVars ) const
|
|
|
|
{
|
|
|
|
auto add =
|
|
|
|
[&]( const wxString& aVar )
|
|
|
|
{
|
|
|
|
if( !alg::contains( *aVars, aVar ) )
|
|
|
|
aVars->push_back( aVar );
|
|
|
|
};
|
|
|
|
|
|
|
|
add( wxT( "#" ) );
|
|
|
|
add( wxT( "##" ) );
|
|
|
|
add( wxT( "SHEETPATH" ) );
|
|
|
|
add( wxT( "SHEETNAME" ) );
|
|
|
|
add( wxT( "FILENAME" ) );
|
2023-11-29 14:55:17 +00:00
|
|
|
add( wxT( "FILEPATH" ) );
|
2023-02-01 19:14:26 +00:00
|
|
|
add( wxT( "PROJECTNAME" ) );
|
|
|
|
|
|
|
|
if( !CurrentSheet().empty() )
|
|
|
|
CurrentSheet().LastScreen()->GetTitleBlock().GetContextualTextVars( aVars );
|
|
|
|
|
|
|
|
for( std::pair<wxString, wxString> entry : Prj().GetTextVars() )
|
|
|
|
add( entry.first );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-12 14:14:41 +00:00
|
|
|
bool SCHEMATIC::ResolveTextVar( const SCH_SHEET_PATH* aSheetPath, wxString* token,
|
|
|
|
int aDepth ) const
|
2021-07-06 12:27:36 +00:00
|
|
|
{
|
2023-11-12 14:14:41 +00:00
|
|
|
wxCHECK( aSheetPath, false );
|
|
|
|
|
|
|
|
if( token->IsSameAs( wxT( "#" ) ) )
|
|
|
|
{
|
|
|
|
*token = aSheetPath->GetPageNumber();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( token->IsSameAs( wxT( "##" ) ) )
|
2021-07-06 12:27:36 +00:00
|
|
|
{
|
2023-11-12 14:14:41 +00:00
|
|
|
*token = wxString::Format( "%i", Root().CountSheets() );
|
|
|
|
return true;
|
2021-07-06 12:27:36 +00:00
|
|
|
}
|
2023-11-12 14:14:41 +00:00
|
|
|
else if( token->IsSameAs( wxT( "SHEETPATH" ) ) )
|
|
|
|
{
|
|
|
|
*token = aSheetPath->PathHumanReadable();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( token->IsSameAs( wxT( "SHEETNAME" ) ) )
|
|
|
|
{
|
|
|
|
*token = aSheetPath->Last()->GetName();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if( token->IsSameAs( wxT( "FILENAME" ) ) )
|
|
|
|
{
|
|
|
|
wxFileName fn( GetFileName() );
|
|
|
|
*token = fn.GetFullName();
|
|
|
|
return true;
|
|
|
|
}
|
2023-11-29 14:55:17 +00:00
|
|
|
else if( token->IsSameAs( wxT( "FILEPATH" ) ) )
|
|
|
|
{
|
|
|
|
wxFileName fn( GetFileName() );
|
|
|
|
*token = fn.GetFullPath();
|
|
|
|
return true;
|
|
|
|
}
|
2023-11-12 14:14:41 +00:00
|
|
|
else if( token->IsSameAs( wxT( "PROJECTNAME" ) ) )
|
|
|
|
{
|
|
|
|
*token = Prj().GetProjectName();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( aSheetPath->LastScreen()->GetTitleBlock().TextVarResolver( token, m_project ) )
|
|
|
|
return true;
|
2021-07-06 12:27:36 +00:00
|
|
|
|
2023-01-17 16:54:08 +00:00
|
|
|
if( Prj().TextVarResolver( token ) )
|
|
|
|
return true;
|
|
|
|
|
2021-07-07 20:52:55 +00:00
|
|
|
return false;
|
2021-07-06 12:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
wxString SCHEMATIC::GetFileName() const
|
|
|
|
{
|
|
|
|
return IsValid() ? m_rootSheet->GetScreen()->GetFileName() : wxString( wxEmptyString );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
SCHEMATIC_SETTINGS& SCHEMATIC::Settings() const
|
2020-05-13 02:00:37 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
wxASSERT( m_project );
|
|
|
|
return *m_project->GetProjectFile().m_SchematicSettings;
|
2020-05-13 02:00:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
ERC_SETTINGS& SCHEMATIC::ErcSettings() const
|
2020-05-13 02:00:37 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
wxASSERT( m_project );
|
|
|
|
return *m_project->GetProjectFile().m_ErcSettings;
|
2020-05-13 02:00:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-18 22:55:38 +00:00
|
|
|
std::vector<SCH_MARKER*> SCHEMATIC::ResolveERCExclusions()
|
|
|
|
{
|
|
|
|
SCH_SHEET_LIST sheetList = GetSheets();
|
|
|
|
ERC_SETTINGS& settings = ErcSettings();
|
|
|
|
|
2023-01-21 23:25:40 +00:00
|
|
|
// Migrate legacy marker exclusions to new format to ensure exclusion matching functions across
|
|
|
|
// file versions. Silently drops any legacy exclusions which can not be mapped to the new format
|
|
|
|
// without risking an incorrect exclusion - this is preferable to silently dropping
|
|
|
|
// new ERC errors / warnings due to an incorrect match between a legacy and new
|
|
|
|
// marker serialization format
|
|
|
|
std::set<wxString> migratedExclusions;
|
|
|
|
|
|
|
|
for( auto it = settings.m_ErcExclusions.begin(); it != settings.m_ErcExclusions.end(); )
|
|
|
|
{
|
2023-01-29 18:06:05 +00:00
|
|
|
SCH_MARKER* testMarker = SCH_MARKER::DeserializeFromString( this, *it );
|
2024-01-29 11:51:06 +00:00
|
|
|
|
2023-01-21 23:25:40 +00:00
|
|
|
if( testMarker->IsLegacyMarker() )
|
|
|
|
{
|
|
|
|
const wxString settingsKey = testMarker->GetRCItem()->GetSettingsKey();
|
|
|
|
|
2024-01-29 11:51:06 +00:00
|
|
|
if( settingsKey != wxT( "pin_to_pin" )
|
|
|
|
&& settingsKey != wxT( "hier_label_mismatch" )
|
2023-01-21 23:25:40 +00:00
|
|
|
&& settingsKey != wxT( "different_unit_net" ) )
|
|
|
|
{
|
2023-01-29 18:06:05 +00:00
|
|
|
migratedExclusions.insert( testMarker->SerializeToString() );
|
2023-01-21 23:25:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
it = settings.m_ErcExclusions.erase( it );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++it;
|
|
|
|
}
|
2024-01-29 11:51:06 +00:00
|
|
|
|
2023-01-21 23:25:40 +00:00
|
|
|
delete testMarker;
|
|
|
|
}
|
|
|
|
|
|
|
|
settings.m_ErcExclusions.insert( migratedExclusions.begin(), migratedExclusions.end() );
|
|
|
|
|
|
|
|
// End of legacy exclusion removal / migrations
|
|
|
|
|
2020-11-18 22:55:38 +00:00
|
|
|
for( const SCH_SHEET_PATH& sheet : sheetList )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_MARKER_T ) )
|
|
|
|
{
|
2024-01-29 11:51:06 +00:00
|
|
|
SCH_MARKER* marker = static_cast<SCH_MARKER*>( item );
|
2023-01-29 18:06:05 +00:00
|
|
|
wxString serialized = marker->SerializeToString();
|
2024-01-29 11:51:06 +00:00
|
|
|
std::set<wxString>::iterator it = settings.m_ErcExclusions.find( serialized );
|
2020-11-18 22:55:38 +00:00
|
|
|
|
2020-12-16 23:54:53 +00:00
|
|
|
if( it != settings.m_ErcExclusions.end() )
|
2020-11-18 22:55:38 +00:00
|
|
|
{
|
2024-01-29 15:59:28 +00:00
|
|
|
marker->SetExcluded( true, settings.m_ErcExclusionComments[serialized] );
|
2020-11-18 22:55:38 +00:00
|
|
|
settings.m_ErcExclusions.erase( it );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<SCH_MARKER*> newMarkers;
|
|
|
|
|
2024-01-29 11:51:06 +00:00
|
|
|
for( const wxString& serialized : settings.m_ErcExclusions )
|
2020-11-18 22:55:38 +00:00
|
|
|
{
|
2023-01-29 18:06:05 +00:00
|
|
|
SCH_MARKER* marker = SCH_MARKER::DeserializeFromString( this, serialized );
|
2020-11-18 22:55:38 +00:00
|
|
|
|
|
|
|
if( marker )
|
|
|
|
{
|
2024-01-29 15:59:28 +00:00
|
|
|
marker->SetExcluded( true, settings.m_ErcExclusionComments[serialized] );
|
2020-11-18 22:55:38 +00:00
|
|
|
newMarkers.push_back( marker );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
settings.m_ErcExclusions.clear();
|
|
|
|
|
|
|
|
return newMarkers;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
std::shared_ptr<BUS_ALIAS> SCHEMATIC::GetBusAlias( const wxString& aLabel ) const
|
2020-05-13 02:00:37 +00:00
|
|
|
{
|
2022-09-11 17:41:54 +00:00
|
|
|
for( const SCH_SHEET_PATH& sheet : GetSheets() )
|
2020-05-13 02:00:37 +00:00
|
|
|
{
|
2022-09-11 17:41:54 +00:00
|
|
|
for( const std::shared_ptr<BUS_ALIAS>& alias : sheet.LastScreen()->GetBusAliases() )
|
2020-05-13 02:00:37 +00:00
|
|
|
{
|
2020-06-08 02:19:46 +00:00
|
|
|
if( alias->GetName() == aLabel )
|
|
|
|
return alias;
|
2020-05-13 02:00:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-08 02:19:46 +00:00
|
|
|
return nullptr;
|
2020-05-13 02:00:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-03 18:29:02 +00:00
|
|
|
std::set<wxString> SCHEMATIC::GetNetClassAssignmentCandidates()
|
2020-07-06 10:51:04 +00:00
|
|
|
{
|
2022-09-03 18:29:02 +00:00
|
|
|
std::set<wxString> names;
|
2020-07-06 10:51:04 +00:00
|
|
|
|
2022-09-03 18:29:02 +00:00
|
|
|
for( const auto& [ key, subgraphList ] : m_connectionGraph->GetNetMap() )
|
2020-10-11 23:29:06 +00:00
|
|
|
{
|
2022-09-03 18:29:02 +00:00
|
|
|
CONNECTION_SUBGRAPH* firstSubgraph = subgraphList[0];
|
2020-10-11 23:29:06 +00:00
|
|
|
|
2023-03-03 22:06:41 +00:00
|
|
|
if( !firstSubgraph->GetDriverConnection()->IsBus()
|
2022-09-03 18:29:02 +00:00
|
|
|
&& firstSubgraph->GetDriverPriority() >= CONNECTION_SUBGRAPH::PRIORITY::PIN )
|
2021-09-17 20:25:05 +00:00
|
|
|
{
|
2022-09-03 18:29:02 +00:00
|
|
|
names.insert( key.Name );
|
2021-09-17 20:25:05 +00:00
|
|
|
}
|
2020-10-11 23:29:06 +00:00
|
|
|
}
|
2020-07-06 10:51:04 +00:00
|
|
|
|
|
|
|
return names;
|
|
|
|
}
|
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
|
2020-07-29 17:02:39 +00:00
|
|
|
bool SCHEMATIC::ResolveCrossReference( wxString* token, int aDepth ) const
|
|
|
|
{
|
|
|
|
SCH_SHEET_LIST sheetList = GetSheets();
|
|
|
|
wxString remainder;
|
|
|
|
wxString ref = token->BeforeFirst( ':', &remainder );
|
2021-06-30 11:32:23 +00:00
|
|
|
SCH_SHEET_PATH sheetPath;
|
|
|
|
SCH_ITEM* refItem = sheetList.GetItem( KIID( ref ), &sheetPath );
|
2020-07-29 17:02:39 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( refItem && refItem->Type() == SCH_SYMBOL_T )
|
2020-07-29 17:02:39 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* refSymbol = static_cast<SCH_SYMBOL*>( refItem );
|
2020-07-29 17:02:39 +00:00
|
|
|
|
2023-05-06 18:22:14 +00:00
|
|
|
if( refSymbol->ResolveTextVar( &sheetPath, &remainder, aDepth + 1 ) )
|
2020-07-29 17:02:39 +00:00
|
|
|
*token = remainder;
|
2021-06-30 11:32:23 +00:00
|
|
|
else
|
2023-01-17 04:14:38 +00:00
|
|
|
*token = refSymbol->GetRef( &sheetPath, true ) + wxS( ":" ) + remainder;
|
2021-06-30 11:32:23 +00:00
|
|
|
|
|
|
|
return true; // Cross-reference is resolved whether or not the actual textvar was
|
2020-07-29 17:02:39 +00:00
|
|
|
}
|
|
|
|
else if( refItem && refItem->Type() == SCH_SHEET_T )
|
|
|
|
{
|
|
|
|
SCH_SHEET* refSheet = static_cast<SCH_SHEET*>( refItem );
|
|
|
|
|
2023-11-11 17:41:44 +00:00
|
|
|
sheetPath.push_back( refSheet );
|
|
|
|
|
|
|
|
if( refSheet->ResolveTextVar( &sheetPath, &remainder, aDepth + 1 ) )
|
2020-07-29 17:02:39 +00:00
|
|
|
*token = remainder;
|
2021-06-30 11:32:23 +00:00
|
|
|
|
|
|
|
return true; // Cross-reference is resolved whether or not the actual textvar was
|
2020-07-29 17:02:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-04 20:58:15 +00:00
|
|
|
std::map<int, wxString> SCHEMATIC::GetVirtualPageToSheetNamesMap() const
|
|
|
|
{
|
|
|
|
std::map<int, wxString> namesMap;
|
|
|
|
|
|
|
|
for( const SCH_SHEET_PATH& sheet : GetSheets() )
|
|
|
|
{
|
|
|
|
if( sheet.size() == 1 )
|
|
|
|
namesMap[sheet.GetVirtualPageNumber()] = _( "<root sheet>" );
|
|
|
|
else
|
|
|
|
namesMap[sheet.GetVirtualPageNumber()] = sheet.Last()->GetName();
|
|
|
|
}
|
|
|
|
|
|
|
|
return namesMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::map<int, wxString> SCHEMATIC::GetVirtualPageToSheetPagesMap() const
|
|
|
|
{
|
|
|
|
std::map<int, wxString> pagesMap;
|
|
|
|
|
|
|
|
for( const SCH_SHEET_PATH& sheet : GetSheets() )
|
|
|
|
pagesMap[sheet.GetVirtualPageNumber()] = sheet.GetPageNumber();
|
|
|
|
|
|
|
|
return pagesMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-29 17:02:39 +00:00
|
|
|
wxString SCHEMATIC::ConvertRefsToKIIDs( const wxString& aSource ) const
|
|
|
|
{
|
|
|
|
wxString newbuf;
|
|
|
|
size_t sourceLen = aSource.length();
|
|
|
|
|
|
|
|
for( size_t i = 0; i < sourceLen; ++i )
|
|
|
|
{
|
|
|
|
if( aSource[i] == '$' && i + 1 < sourceLen && aSource[i+1] == '{' )
|
|
|
|
{
|
|
|
|
wxString token;
|
|
|
|
bool isCrossRef = false;
|
2022-06-03 23:34:14 +00:00
|
|
|
int nesting = 0;
|
2020-07-29 17:02:39 +00:00
|
|
|
|
|
|
|
for( i = i + 2; i < sourceLen; ++i )
|
|
|
|
{
|
2022-06-03 23:34:14 +00:00
|
|
|
if( aSource[i] == '{'
|
|
|
|
&& ( aSource[i-1] == '_' || aSource[i-1] == '^' || aSource[i-1] == '~' ) )
|
|
|
|
{
|
|
|
|
nesting++;
|
|
|
|
}
|
|
|
|
|
2020-07-29 17:02:39 +00:00
|
|
|
if( aSource[i] == '}' )
|
2022-06-03 23:34:14 +00:00
|
|
|
{
|
|
|
|
nesting--;
|
|
|
|
|
|
|
|
if( nesting < 0 )
|
|
|
|
break;
|
|
|
|
}
|
2020-07-29 17:02:39 +00:00
|
|
|
|
|
|
|
if( aSource[i] == ':' )
|
|
|
|
isCrossRef = true;
|
|
|
|
|
|
|
|
token.append( aSource[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( isCrossRef )
|
|
|
|
{
|
|
|
|
SCH_SHEET_LIST sheetList = GetSheets();
|
|
|
|
wxString remainder;
|
|
|
|
wxString ref = token.BeforeFirst( ':', &remainder );
|
|
|
|
SCH_REFERENCE_LIST references;
|
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
sheetList.GetSymbols( references );
|
2020-07-29 17:02:39 +00:00
|
|
|
|
|
|
|
for( size_t jj = 0; jj < references.GetCount(); jj++ )
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* refSymbol = references[ jj ].GetSymbol();
|
2020-07-29 17:02:39 +00:00
|
|
|
|
2020-11-15 16:08:31 +00:00
|
|
|
if( ref == refSymbol->GetRef( &references[ jj ].GetSheetPath(), true ) )
|
2020-07-29 17:02:39 +00:00
|
|
|
{
|
2023-01-17 04:14:38 +00:00
|
|
|
token = refSymbol->m_Uuid.AsString() + wxS( ":" ) + remainder;
|
2020-07-29 17:02:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-17 04:14:38 +00:00
|
|
|
newbuf.append( wxS( "${" ) + token + wxS( "}" ) );
|
2020-07-29 17:02:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newbuf.append( aSource[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString SCHEMATIC::ConvertKIIDsToRefs( const wxString& aSource ) const
|
|
|
|
{
|
|
|
|
wxString newbuf;
|
|
|
|
size_t sourceLen = aSource.length();
|
|
|
|
|
|
|
|
for( size_t i = 0; i < sourceLen; ++i )
|
|
|
|
{
|
|
|
|
if( aSource[i] == '$' && i + 1 < sourceLen && aSource[i+1] == '{' )
|
|
|
|
{
|
|
|
|
wxString token;
|
|
|
|
bool isCrossRef = false;
|
|
|
|
|
|
|
|
for( i = i + 2; i < sourceLen; ++i )
|
|
|
|
{
|
|
|
|
if( aSource[i] == '}' )
|
|
|
|
break;
|
|
|
|
|
|
|
|
if( aSource[i] == ':' )
|
|
|
|
isCrossRef = true;
|
|
|
|
|
|
|
|
token.append( aSource[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( isCrossRef )
|
|
|
|
{
|
|
|
|
SCH_SHEET_LIST sheetList = GetSheets();
|
|
|
|
wxString remainder;
|
|
|
|
wxString ref = token.BeforeFirst( ':', &remainder );
|
|
|
|
|
|
|
|
SCH_SHEET_PATH refSheetPath;
|
|
|
|
SCH_ITEM* refItem = sheetList.GetItem( KIID( ref ), &refSheetPath );
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
if( refItem && refItem->Type() == SCH_SYMBOL_T )
|
2020-07-29 17:02:39 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* refSymbol = static_cast<SCH_SYMBOL*>( refItem );
|
2023-01-17 04:14:38 +00:00
|
|
|
token = refSymbol->GetRef( &refSheetPath, true ) + wxS( ":" ) + remainder;
|
2020-07-29 17:02:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-17 04:14:38 +00:00
|
|
|
newbuf.append( wxS( "${" ) + token + wxS( "}" ) );
|
2020-07-29 17:02:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newbuf.append( aSource[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
SCH_SHEET_LIST& SCHEMATIC::GetFullHierarchy() const
|
|
|
|
{
|
|
|
|
static SCH_SHEET_LIST hierarchy;
|
|
|
|
|
|
|
|
hierarchy.clear();
|
|
|
|
hierarchy.BuildSheetList( m_rootSheet, false );
|
|
|
|
|
|
|
|
return hierarchy;
|
|
|
|
}
|
2022-08-17 15:31:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCHEMATIC::SetLegacySymbolInstanceData()
|
|
|
|
{
|
|
|
|
SCH_SCREENS screens( m_rootSheet );
|
|
|
|
|
|
|
|
screens.SetLegacySymbolInstanceData();
|
|
|
|
}
|
2022-10-26 21:59:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
wxString SCHEMATIC::GetUniqueFilenameForCurrentSheet()
|
|
|
|
{
|
|
|
|
// Filename is rootSheetName-sheetName-...-sheetName
|
|
|
|
// Note that we need to fetch the rootSheetName out of its filename, as the root SCH_SHEET's
|
|
|
|
// name is just a timestamp.
|
|
|
|
|
|
|
|
wxFileName rootFn( CurrentSheet().at( 0 )->GetFileName() );
|
|
|
|
wxString filename = rootFn.GetName();
|
|
|
|
|
|
|
|
for( unsigned i = 1; i < CurrentSheet().size(); i++ )
|
|
|
|
filename += wxT( "-" ) + CurrentSheet().at( i )->GetName();
|
|
|
|
|
|
|
|
return filename;
|
2022-11-03 03:38:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCHEMATIC::SetSheetNumberAndCount()
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen;
|
|
|
|
SCH_SCREENS s_list( Root() );
|
|
|
|
|
|
|
|
// Set the sheet count, and the sheet number (1 for root sheet)
|
|
|
|
int sheet_count = Root().CountSheets();
|
|
|
|
int sheet_number = 1;
|
|
|
|
const KIID_PATH& current_sheetpath = CurrentSheet().Path();
|
|
|
|
|
|
|
|
// @todo Remove all pseudo page number system is left over from prior to real page number
|
|
|
|
// implementation.
|
|
|
|
for( const SCH_SHEET_PATH& sheet : GetSheets() )
|
|
|
|
{
|
|
|
|
if( sheet.Path() == current_sheetpath ) // Current sheet path found
|
|
|
|
break;
|
|
|
|
|
|
|
|
sheet_number++; // Not found, increment before this current path
|
|
|
|
}
|
|
|
|
|
|
|
|
for( screen = s_list.GetFirst(); screen != nullptr; screen = s_list.GetNext() )
|
|
|
|
screen->SetPageCount( sheet_count );
|
|
|
|
|
|
|
|
CurrentSheet().SetVirtualPageNumber( sheet_number );
|
|
|
|
CurrentSheet().LastScreen()->SetVirtualPageNumber( sheet_number );
|
|
|
|
CurrentSheet().LastScreen()->SetPageNumber( CurrentSheet().GetPageNumber() );
|
2022-11-03 04:12:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-03 13:25:20 +00:00
|
|
|
void SCHEMATIC::RecomputeIntersheetRefs( const std::function<void( SCH_GLOBALLABEL* )>& aItemCallback )
|
2022-11-03 04:12:53 +00:00
|
|
|
{
|
|
|
|
std::map<wxString, std::set<int>>& pageRefsMap = GetPageRefsMap();
|
|
|
|
|
|
|
|
pageRefsMap.clear();
|
|
|
|
|
2024-03-23 16:50:00 +00:00
|
|
|
for( const SCH_SHEET_PATH& sheet : GetSheets() )
|
2022-11-03 04:12:53 +00:00
|
|
|
{
|
2024-03-23 16:50:00 +00:00
|
|
|
for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_GLOBAL_LABEL_T ) )
|
2022-11-03 04:12:53 +00:00
|
|
|
{
|
2024-03-23 16:50:00 +00:00
|
|
|
SCH_GLOBALLABEL* global = static_cast<SCH_GLOBALLABEL*>( item );
|
|
|
|
wxString resolvedLabel = global->GetShownText( &sheet, false );
|
2022-11-03 04:12:53 +00:00
|
|
|
|
2024-03-23 16:50:00 +00:00
|
|
|
pageRefsMap[ resolvedLabel ].insert( sheet.GetVirtualPageNumber() );
|
2022-11-03 04:12:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool show = Settings().m_IntersheetRefsShow;
|
|
|
|
|
2024-03-23 16:50:00 +00:00
|
|
|
// Refresh all visible global labels. Note that we have to collect them first as the
|
2022-11-03 04:12:53 +00:00
|
|
|
// SCH_SCREEN::Update() call is going to invalidate the RTree iterator.
|
|
|
|
|
2022-12-03 13:25:20 +00:00
|
|
|
std::vector<SCH_GLOBALLABEL*> currentSheetGlobalLabels;
|
2022-11-03 04:12:53 +00:00
|
|
|
|
|
|
|
for( EDA_ITEM* item : CurrentSheet().LastScreen()->Items().OfType( SCH_GLOBAL_LABEL_T ) )
|
2022-12-03 13:25:20 +00:00
|
|
|
currentSheetGlobalLabels.push_back( static_cast<SCH_GLOBALLABEL*>( item ) );
|
2022-11-03 04:12:53 +00:00
|
|
|
|
2022-12-03 13:25:20 +00:00
|
|
|
for( SCH_GLOBALLABEL* globalLabel : currentSheetGlobalLabels )
|
2022-11-03 04:12:53 +00:00
|
|
|
{
|
|
|
|
std::vector<SCH_FIELD>& fields = globalLabel->GetFields();
|
|
|
|
|
|
|
|
fields[0].SetVisible( show );
|
|
|
|
|
|
|
|
if( show )
|
|
|
|
{
|
|
|
|
if( fields.size() == 1 && fields[0].GetTextPos() == globalLabel->GetPosition() )
|
|
|
|
globalLabel->AutoplaceFields( CurrentSheet().LastScreen(), false );
|
|
|
|
|
|
|
|
CurrentSheet().LastScreen()->Update( globalLabel );
|
|
|
|
aItemCallback( globalLabel );
|
|
|
|
}
|
|
|
|
}
|
2022-08-18 21:19:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-05 20:47:27 +00:00
|
|
|
wxString SCHEMATIC::GetOperatingPoint( const wxString& aNetName, int aPrecision,
|
|
|
|
const wxString& aRange )
|
|
|
|
{
|
2023-02-09 17:18:56 +00:00
|
|
|
std::string spiceNetName( aNetName.Lower().ToStdString() );
|
|
|
|
NETLIST_EXPORTER_SPICE::ConvertToSpiceMarkup( spiceNetName );
|
|
|
|
|
|
|
|
if( spiceNetName == "gnd" || spiceNetName == "0" )
|
|
|
|
return wxEmptyString;
|
|
|
|
|
|
|
|
auto it = m_operatingPoints.find( spiceNetName );
|
2023-02-05 20:47:27 +00:00
|
|
|
|
|
|
|
if( it != m_operatingPoints.end() )
|
2023-02-11 20:39:50 +00:00
|
|
|
return SPICE_VALUE( it->second ).ToString( { aPrecision, aRange } );
|
2023-02-05 20:47:27 +00:00
|
|
|
else if( m_operatingPoints.empty() )
|
|
|
|
return wxS( "--" );
|
|
|
|
else
|
|
|
|
return wxS( "?" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-18 21:19:28 +00:00
|
|
|
void SCHEMATIC::FixupJunctions()
|
|
|
|
{
|
|
|
|
for( const SCH_SHEET_PATH& sheet : GetSheets() )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen = sheet.LastScreen();
|
|
|
|
|
|
|
|
std::deque<EDA_ITEM*> allItems;
|
|
|
|
|
|
|
|
for( auto item : screen->Items() )
|
|
|
|
allItems.push_back( item );
|
|
|
|
|
|
|
|
// Add missing junctions and breakup wires as needed
|
|
|
|
for( const VECTOR2I& point : screen->GetNeededJunctions( allItems ) )
|
|
|
|
{
|
|
|
|
SCH_JUNCTION* junction = new SCH_JUNCTION( point );
|
|
|
|
screen->Append( junction );
|
|
|
|
|
|
|
|
// Breakup wires
|
|
|
|
for( SCH_LINE* wire : screen->GetBusesAndWires( point, true ) )
|
|
|
|
{
|
|
|
|
SCH_LINE* newSegment = wire->BreakAt( point );
|
|
|
|
screen->Append( newSegment );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-05-11 02:53:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCHEMATIC::OnItemsAdded( std::vector<SCH_ITEM*>& aNewItems )
|
|
|
|
{
|
|
|
|
InvokeListeners( &SCHEMATIC_LISTENER::OnSchItemsAdded, *this, aNewItems );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCHEMATIC::OnItemsRemoved( std::vector<SCH_ITEM*>& aRemovedItems )
|
|
|
|
{
|
|
|
|
InvokeListeners( &SCHEMATIC_LISTENER::OnSchItemsRemoved, *this, aRemovedItems );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-20 20:13:07 +00:00
|
|
|
void SCHEMATIC::OnItemsChanged( std::vector<SCH_ITEM*>& aItems )
|
|
|
|
{
|
|
|
|
InvokeListeners( &SCHEMATIC_LISTENER::OnSchItemsChanged, *this, aItems );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCHEMATIC::OnSchSheetChanged()
|
|
|
|
{
|
|
|
|
InvokeListeners( &SCHEMATIC_LISTENER::OnSchSheetChanged, *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-11 02:53:10 +00:00
|
|
|
void SCHEMATIC::AddListener( SCHEMATIC_LISTENER* aListener )
|
|
|
|
{
|
|
|
|
if( !alg::contains( m_listeners, aListener ) )
|
|
|
|
m_listeners.push_back( aListener );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCHEMATIC::RemoveListener( SCHEMATIC_LISTENER* aListener )
|
|
|
|
{
|
|
|
|
auto i = std::find( m_listeners.begin(), m_listeners.end(), aListener );
|
|
|
|
|
|
|
|
if( i != m_listeners.end() )
|
|
|
|
{
|
|
|
|
std::iter_swap( i, m_listeners.end() - 1 );
|
|
|
|
m_listeners.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCHEMATIC::RemoveAllListeners()
|
|
|
|
{
|
|
|
|
m_listeners.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-13 23:50:05 +00:00
|
|
|
void SCHEMATIC::RecordERCExclusions()
|
|
|
|
{
|
|
|
|
SCH_SHEET_LIST sheetList = GetSheets();
|
|
|
|
ERC_SETTINGS& ercSettings = ErcSettings();
|
|
|
|
|
|
|
|
ercSettings.m_ErcExclusions.clear();
|
2024-01-29 15:59:28 +00:00
|
|
|
ercSettings.m_ErcExclusionComments.clear();
|
2023-08-13 23:50:05 +00:00
|
|
|
|
|
|
|
for( unsigned i = 0; i < sheetList.size(); i++ )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : sheetList[i].LastScreen()->Items().OfType( SCH_MARKER_T ) )
|
|
|
|
{
|
|
|
|
SCH_MARKER* marker = static_cast<SCH_MARKER*>( item );
|
|
|
|
|
|
|
|
if( marker->IsExcluded() )
|
2024-01-29 15:59:28 +00:00
|
|
|
{
|
2023-01-29 18:06:05 +00:00
|
|
|
wxString serialized = marker->SerializeToString();
|
2024-01-29 15:59:28 +00:00
|
|
|
ercSettings.m_ErcExclusions.insert( serialized );
|
|
|
|
ercSettings.m_ErcExclusionComments[ serialized ] = marker->GetComment();
|
|
|
|
}
|
2023-08-13 23:50:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCHEMATIC::ResolveERCExclusionsPostUpdate()
|
|
|
|
{
|
|
|
|
SCH_SHEET_LIST sheetList = GetSheets();
|
|
|
|
|
|
|
|
for( SCH_MARKER* marker : ResolveERCExclusions() )
|
|
|
|
{
|
|
|
|
SCH_SHEET_PATH errorPath;
|
|
|
|
ignore_unused( sheetList.GetItem( marker->GetRCItem()->GetMainItemID(), &errorPath ) );
|
|
|
|
|
|
|
|
if( errorPath.LastScreen() )
|
|
|
|
errorPath.LastScreen()->Append( marker );
|
|
|
|
else
|
|
|
|
RootScreen()->Append( marker );
|
|
|
|
}
|
2023-08-20 20:13:07 +00:00
|
|
|
}
|