2011-10-07 14:41:30 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2013-05-18 09:38:23 +00:00
|
|
|
* Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2017-11-18 13:10:32 +00:00
|
|
|
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
|
2024-01-11 20:41:58 +00:00
|
|
|
* Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-10-07 14:41:30 +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 2
|
|
|
|
* 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, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2023-09-18 23:52:27 +00:00
|
|
|
#include <stack>
|
2021-05-27 18:36:47 +00:00
|
|
|
#include <wx/filefn.h>
|
|
|
|
|
2021-06-06 14:41:02 +00:00
|
|
|
#include <eda_item.h>
|
2020-01-03 16:04:54 +00:00
|
|
|
#include <id.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2015-04-09 19:37:48 +00:00
|
|
|
#include <kiway.h>
|
2021-08-18 20:38:14 +00:00
|
|
|
#include <plotters/plotter.h>
|
2023-10-21 20:52:51 +00:00
|
|
|
#include <sch_plotter.h>
|
2019-06-25 23:39:58 +00:00
|
|
|
#include <project.h>
|
2023-09-28 03:04:53 +00:00
|
|
|
#include <project_sch.h>
|
2020-04-16 16:43:50 +00:00
|
|
|
#include <reporter.h>
|
2023-12-01 19:18:47 +00:00
|
|
|
#include <trace_helpers.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2019-06-25 23:39:58 +00:00
|
|
|
#include <sch_item.h>
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2021-06-15 13:24:55 +00:00
|
|
|
#include <symbol_library.h>
|
2019-12-11 23:53:10 +00:00
|
|
|
#include <connection_graph.h>
|
2019-06-25 23:39:58 +00:00
|
|
|
#include <lib_pin.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2019-06-25 23:39:58 +00:00
|
|
|
#include <sch_junction.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_line.h>
|
|
|
|
#include <sch_marker.h>
|
|
|
|
#include <sch_sheet.h>
|
2021-04-06 21:15:49 +00:00
|
|
|
#include <sch_sheet_pin.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_text.h>
|
2020-05-13 02:00:37 +00:00
|
|
|
#include <schematic.h>
|
2017-09-01 20:42:20 +00:00
|
|
|
#include <symbol_lib_table.h>
|
2018-09-03 13:58:47 +00:00
|
|
|
#include <tool/common_tools.h>
|
2022-12-06 14:00:11 +00:00
|
|
|
#include <sim/sim_model.h> // For V6 to V7 simulation model migration.
|
|
|
|
#include <locale_io.h>
|
2010-11-10 15:30:12 +00:00
|
|
|
|
2019-04-06 01:14:15 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
// TODO(JE) Debugging only
|
2023-09-07 11:22:10 +00:00
|
|
|
#include <core/profile.h>
|
2020-08-10 11:40:58 +00:00
|
|
|
#include "sch_bus_entry.h"
|
2019-12-30 18:28:00 +00:00
|
|
|
|
2023-08-30 21:21:58 +00:00
|
|
|
/*
|
|
|
|
* Flag to enable profiling of the TestDanglingEnds() function.
|
|
|
|
* @ingroup trace_env_vars
|
|
|
|
*/
|
|
|
|
static const wxChar DanglingProfileMask[] = wxT( "DANGLING_PROFILE" );
|
|
|
|
|
2020-05-21 02:27:48 +00:00
|
|
|
SCH_SCREEN::SCH_SCREEN( EDA_ITEM* aParent ) :
|
|
|
|
BASE_SCREEN( aParent, SCH_SCREEN_T ),
|
2021-01-31 22:58:34 +00:00
|
|
|
m_fileFormatVersionAtLoad( 0 ),
|
2021-10-14 13:12:40 +00:00
|
|
|
m_paper( wxT( "A4" ) ),
|
|
|
|
m_isReadOnly( false ),
|
|
|
|
m_fileExists( false )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2015-02-28 20:50:35 +00:00
|
|
|
m_modification_sync = 0;
|
2011-01-12 21:47:54 +00:00
|
|
|
m_refCount = 0;
|
Mark null project initial screen as zoom-initialized
The variable `m_Initialized` in `BASE_SCREEN` is used by
`SCH_EDIT_FRAME` to mark whether a screen had its zoom level initialized
by the "zoom to fit screen" action. When this variable is `false`, the
function `SCH_EDIT_FRAME::DisplayCurrentSheet()` performs "zoom to fit
screen", modifying the zoom level. This function is indirectly called in
the undo routines, so if `m_Initialized` is not set to `true`, a zoom
change will occur when the user undoes an operation, a behavior that is
undesired.
`m_Initialized` was not initialized to `true` for the null schematic
(the schematic that is loaded if no project is loaded), causing the
aforementioned undesired behavior.
To prevent this, I've changed the `SCH_EDIT_FRAME` constructor to set
`m_Initialized` to `true`, since it zooms to fit screen already. I've
moved `m_Initialized` from `BASE_SCREEN` to `SCH_SCREEN`, as it is used
only in Eeschema, and renamed it to `m_zoomInitialized`, a name I
believe that better describes what this variable does.
I've also introduced the function `SCH_EDIT_FRAME::initScreenZoom()` to
group the "zoom to fit screen" action with setting `m_Initialized` to
`true`, as they often should occur together.
I'd also like to say that I'm not confident whether
`SCH_EDIT_FRAME::DisplayCurrentSheet()` should perform the zoom level
initialization at this point, but I have decided to not change this
behavior for now, as the commit history suggests it's several years old.
Fixes https://gitlab.com/kicad/code/kicad/issues/7343
2021-01-30 22:47:39 +00:00
|
|
|
m_zoomInitialized = false;
|
2021-01-17 08:41:49 +00:00
|
|
|
m_LastZoomLevel = 1.0;
|
2011-12-22 21:57:50 +00:00
|
|
|
|
2020-10-31 01:27:16 +00:00
|
|
|
// Suitable for schematic only. For symbol_editor and viewlib, must be set to true
|
2011-12-31 05:44:00 +00:00
|
|
|
m_Center = false;
|
|
|
|
|
2022-09-16 23:25:07 +00:00
|
|
|
InitDataPoints( m_paper.GetSizeIU( schIUScale.IU_PER_MILS ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
SCH_SCREEN::~SCH_SCREEN()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-04-16 16:43:50 +00:00
|
|
|
clearLibSymbols();
|
2019-06-25 23:39:58 +00:00
|
|
|
FreeDrawList();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
SCHEMATIC* SCH_SCREEN::Schematic() const
|
|
|
|
{
|
|
|
|
wxCHECK_MSG( GetParent() && GetParent()->Type() == SCHEMATIC_T, nullptr,
|
2022-08-20 09:27:35 +00:00
|
|
|
wxT( "SCH_SCREEN must have a SCHEMATIC parent!" ) );
|
2020-05-13 02:00:37 +00:00
|
|
|
|
|
|
|
return static_cast<SCHEMATIC*>( GetParent() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
void SCH_SCREEN::clearLibSymbols()
|
|
|
|
{
|
2022-07-29 21:02:35 +00:00
|
|
|
for( const std::pair<const wxString, LIB_SYMBOL*>& libSymbol : m_libSymbols )
|
2020-04-16 16:43:50 +00:00
|
|
|
delete libSymbol.second;
|
|
|
|
|
|
|
|
m_libSymbols.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-27 18:36:47 +00:00
|
|
|
void SCH_SCREEN::SetFileName( const wxString& aFileName )
|
|
|
|
{
|
|
|
|
wxASSERT( aFileName.IsEmpty() || wxIsAbsolutePath( aFileName ) );
|
|
|
|
|
|
|
|
m_fileName = aFileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
void SCH_SCREEN::IncRefCount()
|
|
|
|
{
|
|
|
|
m_refCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-12 21:47:54 +00:00
|
|
|
void SCH_SCREEN::DecRefCount()
|
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
wxCHECK_RET( m_refCount != 0, wxT( "Screen reference count already zero. Bad programmer!" ) );
|
2011-01-12 21:47:54 +00:00
|
|
|
m_refCount--;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-26 20:53:29 +00:00
|
|
|
bool SCH_SCREEN::HasItems( KICAD_T aItemType ) const
|
|
|
|
{
|
2020-12-20 18:59:07 +00:00
|
|
|
EE_RTREE::EE_TYPE sheets = m_rtree.OfType( aItemType );
|
2020-04-26 20:53:29 +00:00
|
|
|
|
|
|
|
return sheets.begin() != sheets.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-06 14:41:02 +00:00
|
|
|
bool SCH_SCREEN::ClassOf( const EDA_ITEM* aItem )
|
|
|
|
{
|
|
|
|
return aItem && SCH_SCREEN_T == aItem->Type();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-02 20:53:57 +00:00
|
|
|
void SCH_SCREEN::Append( SCH_ITEM* aItem, bool aUpdateLibSymbol )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2020-01-25 17:32:05 +00:00
|
|
|
if( aItem->Type() != SCH_SHEET_PIN_T && aItem->Type() != SCH_FIELD_T )
|
|
|
|
{
|
2020-05-25 21:47:50 +00:00
|
|
|
// Ensure the item can reach the SCHEMATIC through this screen
|
|
|
|
aItem->SetParent( this );
|
|
|
|
|
2023-02-02 20:53:57 +00:00
|
|
|
if( aItem->Type() == SCH_SYMBOL_T && aUpdateLibSymbol )
|
2020-04-16 16:43:50 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( aItem );
|
2020-04-16 16:43:50 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
if( symbol->GetLibSymbolRef() )
|
2020-04-16 16:43:50 +00:00
|
|
|
{
|
2021-06-15 12:31:28 +00:00
|
|
|
symbol->GetLibSymbolRef()->GetDrawItems().sort();
|
2021-03-04 22:59:24 +00:00
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
auto it = m_libSymbols.find( symbol->GetSchSymbolLibraryName() );
|
|
|
|
|
2021-02-02 23:09:17 +00:00
|
|
|
if( it == m_libSymbols.end() || !it->second )
|
2020-04-16 16:43:50 +00:00
|
|
|
{
|
|
|
|
m_libSymbols[symbol->GetSchSymbolLibraryName()] =
|
2021-06-15 12:31:28 +00:00
|
|
|
new LIB_SYMBOL( *symbol->GetLibSymbolRef() );
|
2020-04-16 16:43:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The original library symbol may have changed since the last time
|
|
|
|
// it was added to the schematic. If it has changed, then a new name
|
|
|
|
// must be created for the library symbol list to prevent all of the
|
|
|
|
// other schematic symbols referencing that library symbol from changing.
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* foundSymbol = it->second;
|
2020-04-16 16:43:50 +00:00
|
|
|
|
2021-03-04 22:59:24 +00:00
|
|
|
foundSymbol->GetDrawItems().sort();
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
if( *foundSymbol != *symbol->GetLibSymbolRef() )
|
2020-04-16 16:43:50 +00:00
|
|
|
{
|
|
|
|
wxString newName;
|
2023-02-02 20:53:57 +00:00
|
|
|
std::vector<wxString> matches;
|
2020-04-16 16:43:50 +00:00
|
|
|
|
2023-02-02 20:53:57 +00:00
|
|
|
getLibSymbolNameMatches( *symbol, matches );
|
|
|
|
foundSymbol = nullptr;
|
2020-04-16 16:43:50 +00:00
|
|
|
|
2023-02-02 20:53:57 +00:00
|
|
|
for( const wxString& libSymbolName : matches )
|
2020-04-16 16:43:50 +00:00
|
|
|
{
|
2023-02-02 20:53:57 +00:00
|
|
|
it = m_libSymbols.find( libSymbolName );
|
|
|
|
|
|
|
|
if( it == m_libSymbols.end() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
foundSymbol = it->second;
|
|
|
|
|
|
|
|
wxCHECK2( foundSymbol, continue );
|
|
|
|
|
2023-04-08 19:28:45 +00:00
|
|
|
wxString tmp = symbol->GetLibSymbolRef()->GetName();
|
|
|
|
|
|
|
|
// Temporarily update the new symbol library symbol name so it
|
|
|
|
// doesn't fail on the name comparison below.
|
|
|
|
symbol->GetLibSymbolRef()->SetName( foundSymbol->GetName() );
|
|
|
|
|
2023-02-02 20:53:57 +00:00
|
|
|
if( *foundSymbol == *symbol->GetLibSymbolRef() )
|
|
|
|
{
|
|
|
|
newName = libSymbolName;
|
2023-04-08 19:28:45 +00:00
|
|
|
symbol->GetLibSymbolRef()->SetName( tmp );
|
2023-02-02 20:53:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-04-08 19:28:45 +00:00
|
|
|
symbol->GetLibSymbolRef()->SetName( tmp );
|
2023-02-02 20:53:57 +00:00
|
|
|
foundSymbol = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !foundSymbol )
|
|
|
|
{
|
|
|
|
int cnt = 1;
|
|
|
|
|
|
|
|
newName.Printf( wxT( "%s_%d" ),
|
|
|
|
symbol->GetLibId().GetUniStringLibItemName(),
|
2021-07-30 22:37:18 +00:00
|
|
|
cnt );
|
2023-02-02 20:53:57 +00:00
|
|
|
|
|
|
|
while( m_libSymbols.find( newName ) != m_libSymbols.end() )
|
|
|
|
{
|
|
|
|
cnt += 1;
|
|
|
|
newName.Printf( wxT( "%s_%d" ),
|
|
|
|
symbol->GetLibId().GetUniStringLibItemName(),
|
|
|
|
cnt );
|
|
|
|
}
|
2020-04-16 16:43:50 +00:00
|
|
|
}
|
|
|
|
|
2021-07-30 22:37:18 +00:00
|
|
|
// Update the schematic symbol library link as this symbol only exists
|
|
|
|
// in the schematic.
|
2020-04-16 16:43:50 +00:00
|
|
|
symbol->SetSchSymbolLibraryName( newName );
|
2021-07-30 22:37:18 +00:00
|
|
|
|
2023-02-02 20:53:57 +00:00
|
|
|
if( !foundSymbol )
|
|
|
|
{
|
|
|
|
// Update the schematic symbol library link as this symbol does not
|
|
|
|
// exist in any symbol library.
|
|
|
|
LIB_ID newLibId( wxEmptyString, newName );
|
|
|
|
LIB_SYMBOL* newLibSymbol = new LIB_SYMBOL( *symbol->GetLibSymbolRef() );
|
|
|
|
|
|
|
|
newLibSymbol->SetLibId( newLibId );
|
|
|
|
newLibSymbol->SetName( newName );
|
|
|
|
symbol->SetLibSymbol( newLibSymbol->Flatten().release() );
|
|
|
|
m_libSymbols[newName] = newLibSymbol;
|
|
|
|
}
|
2020-04-16 16:43:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-25 17:32:05 +00:00
|
|
|
m_rtree.insert( aItem );
|
|
|
|
--m_modification_sync;
|
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-17 17:00:04 +00:00
|
|
|
void SCH_SCREEN::Append( SCH_SCREEN* aScreen )
|
|
|
|
{
|
|
|
|
wxCHECK_RET( aScreen, "Invalid screen object." );
|
|
|
|
|
Fix source comment/doc typos (follow-up)
Found via `codespell -q 3 -S *.po,./thirdparty -L aactual,acount,aline,alocation,alog,anormal,anumber,aother,apoints,aparent,aray,dout,einstance,modul,ot,overide,serie,te,,tesselate,tesselator,tht`
2021-07-03 22:37:31 +00:00
|
|
|
// No need to descend the hierarchy. Once the top level screen is copied, all of its
|
2017-11-17 17:00:04 +00:00
|
|
|
// children are copied as well.
|
2021-11-23 21:18:04 +00:00
|
|
|
for( SCH_ITEM* aItem : aScreen->m_rtree )
|
2020-01-25 17:32:05 +00:00
|
|
|
Append( aItem );
|
2017-11-17 17:00:04 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
aScreen->Clear( false );
|
2017-11-17 17:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
void SCH_SCREEN::Clear( bool aFree )
|
2011-06-15 18:44:24 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
if( aFree )
|
2020-04-16 16:43:50 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
FreeDrawList();
|
2020-04-16 16:43:50 +00:00
|
|
|
clearLibSymbols();
|
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
else
|
2020-04-16 16:43:50 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
m_rtree.clear();
|
2020-04-16 16:43:50 +00:00
|
|
|
}
|
2011-06-15 18:44:24 +00:00
|
|
|
|
2012-05-27 00:19:12 +00:00
|
|
|
// Clear the project settings
|
2020-10-18 20:30:37 +00:00
|
|
|
m_virtualPageNumber = m_pageCount = 1;
|
2012-01-09 08:35:06 +00:00
|
|
|
|
|
|
|
m_titles.Clear();
|
2011-06-15 18:44:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
void SCH_SCREEN::FreeDrawList()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
// We don't know which order we will encounter dependent items (e.g. pins or fields), so
|
|
|
|
// we store the items to be deleted until we've fully cleared the tree before deleting
|
|
|
|
std::vector<SCH_ITEM*> delete_list;
|
|
|
|
|
|
|
|
std::copy_if( m_rtree.begin(), m_rtree.end(), std::back_inserter( delete_list ),
|
2020-03-16 11:05:01 +00:00
|
|
|
[]( SCH_ITEM* aItem )
|
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
return ( aItem->Type() != SCH_SHEET_PIN_T && aItem->Type() != SCH_FIELD_T );
|
|
|
|
} );
|
|
|
|
|
|
|
|
m_rtree.clear();
|
|
|
|
|
2021-11-23 21:18:04 +00:00
|
|
|
for( SCH_ITEM* item : delete_list )
|
2019-06-25 23:39:58 +00:00
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-02 20:53:57 +00:00
|
|
|
void SCH_SCREEN::Update( SCH_ITEM* aItem, bool aUpdateLibSymbol )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2023-02-02 20:53:57 +00:00
|
|
|
if( Remove( aItem, aUpdateLibSymbol ) )
|
|
|
|
Append( aItem, aUpdateLibSymbol );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2023-02-02 20:53:57 +00:00
|
|
|
bool SCH_SCREEN::Remove( SCH_ITEM* aItem, bool aUpdateLibSymbol )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2020-04-16 16:43:50 +00:00
|
|
|
bool retv = m_rtree.remove( aItem );
|
|
|
|
|
|
|
|
// Check if the library symbol for the removed schematic symbol is still required.
|
2023-02-02 20:53:57 +00:00
|
|
|
if( retv && aItem->Type() == SCH_SYMBOL_T && aUpdateLibSymbol )
|
2020-04-16 16:43:50 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* removedSymbol = static_cast<SCH_SYMBOL*>( aItem );
|
2020-04-16 16:43:50 +00:00
|
|
|
|
|
|
|
bool removeUnusedLibSymbol = true;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
for( SCH_ITEM* item : Items().OfType( SCH_SYMBOL_T ) )
|
2020-04-16 16:43:50 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
2020-04-16 16:43:50 +00:00
|
|
|
|
|
|
|
if( removedSymbol->GetSchSymbolLibraryName() == symbol->GetSchSymbolLibraryName() )
|
|
|
|
{
|
|
|
|
removeUnusedLibSymbol = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( removeUnusedLibSymbol )
|
|
|
|
{
|
|
|
|
auto it = m_libSymbols.find( removedSymbol->GetSchSymbolLibraryName() );
|
|
|
|
|
|
|
|
if( it != m_libSymbols.end() )
|
|
|
|
{
|
|
|
|
delete it->second;
|
|
|
|
m_libSymbols.erase( it );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return retv;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2008-02-26 19:19:54 +00:00
|
|
|
|
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
void SCH_SCREEN::DeleteItem( SCH_ITEM* aItem )
|
|
|
|
{
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
wxCHECK_RET( aItem, wxT( "Cannot delete invalid item from screen." ) );
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2020-09-01 02:05:46 +00:00
|
|
|
// Markers are not saved in the file, no need to flag as modified.
|
|
|
|
// TODO: Maybe we should have a listing somewhere of items that aren't saved?
|
|
|
|
if( aItem->Type() != SCH_MARKER_T )
|
2021-05-28 19:07:04 +00:00
|
|
|
SetContentModified();
|
2020-09-01 02:05:46 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
Remove( aItem );
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
if( aItem->Type() == SCH_SHEET_PIN_T )
|
2011-03-10 19:36:30 +00:00
|
|
|
{
|
|
|
|
// This structure is attached to a sheet, get the parent sheet object.
|
2011-03-30 19:26:05 +00:00
|
|
|
SCH_SHEET_PIN* sheetPin = (SCH_SHEET_PIN*) aItem;
|
|
|
|
SCH_SHEET* sheet = sheetPin->GetParent();
|
2020-12-13 18:09:53 +00:00
|
|
|
wxCHECK_RET( sheet, wxT( "Sheet pin parent not properly set, bad programmer!" ) );
|
2011-03-30 19:26:05 +00:00
|
|
|
sheet->RemovePin( sheetPin );
|
2011-03-10 19:36:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-04-16 16:43:50 +00:00
|
|
|
|
|
|
|
delete aItem;
|
2011-03-10 19:36:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
bool SCH_SCREEN::CheckIfOnDrawList( const SCH_ITEM* aItem ) const
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
return m_rtree.contains( aItem, true );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2008-02-26 19:19:54 +00:00
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
SCH_ITEM* SCH_SCREEN::GetItem( const VECTOR2I& aPosition, int aAccuracy, KICAD_T aType ) const
|
2011-01-11 20:34:29 +00:00
|
|
|
{
|
2022-08-31 22:57:24 +00:00
|
|
|
BOX2I bbox;
|
2019-06-25 23:39:58 +00:00
|
|
|
bbox.SetOrigin( aPosition );
|
|
|
|
bbox.Inflate( aAccuracy );
|
2019-05-06 02:32:01 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
for( SCH_ITEM* item : Items().Overlapping( aType, bbox ) )
|
2011-01-11 20:34:29 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
if( item->HitTest( aPosition, aAccuracy ) )
|
2019-05-06 02:32:01 +00:00
|
|
|
return item;
|
2011-03-10 19:36:30 +00:00
|
|
|
}
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
return nullptr;
|
2011-03-10 19:36:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-15 15:27:54 +00:00
|
|
|
std::set<SCH_ITEM*> SCH_SCREEN::MarkConnections( SCH_LINE* aSegment, bool aSecondPass )
|
2011-02-05 02:21:11 +00:00
|
|
|
{
|
2022-06-15 15:27:54 +00:00
|
|
|
#define PROCESSED CANDIDATE // Don't use SKIP_STRUCT; IsConnected() returns false if it's set.
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
std::set<SCH_ITEM*> retval;
|
|
|
|
std::stack<SCH_LINE*> to_search;
|
2011-02-05 02:21:11 +00:00
|
|
|
|
2020-08-10 11:40:58 +00:00
|
|
|
wxCHECK_MSG( aSegment && aSegment->Type() == SCH_LINE_T, retval, wxT( "Invalid pointer." ) );
|
2011-02-05 02:21:11 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
to_search.push( aSegment );
|
2011-02-05 02:21:11 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
while( !to_search.empty() )
|
2011-03-10 19:36:30 +00:00
|
|
|
{
|
2022-06-15 15:27:54 +00:00
|
|
|
SCH_ITEM* item = to_search.top();
|
2019-06-25 23:39:58 +00:00
|
|
|
to_search.pop();
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2022-06-15 15:27:54 +00:00
|
|
|
if( item->HasFlag( PROCESSED ) )
|
|
|
|
continue;
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2022-06-15 15:27:54 +00:00
|
|
|
item->SetFlags( PROCESSED );
|
|
|
|
|
|
|
|
for( SCH_ITEM* candidate : Items().Overlapping( SCH_LINE_T, item->GetBoundingBox() ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2022-06-15 15:27:54 +00:00
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( candidate );
|
|
|
|
|
|
|
|
if( line->HasFlag( PROCESSED ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
continue;
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2022-06-15 15:27:54 +00:00
|
|
|
// Skip connecting lines on different layers (e.g. buses)
|
|
|
|
if( item->GetLayer() != line->GetLayer() )
|
2022-09-10 19:56:17 +00:00
|
|
|
continue;
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2022-06-15 15:27:54 +00:00
|
|
|
for( VECTOR2I pt : { line->GetStartPoint(), line->GetEndPoint() } )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2022-06-15 15:27:54 +00:00
|
|
|
if( item->IsConnected( pt ) )
|
|
|
|
{
|
|
|
|
SCH_ITEM* junction = GetItem( pt, 0, SCH_JUNCTION_T );
|
|
|
|
SCH_ITEM* pin = GetItem( pt, 0, SCH_PIN_T );
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2022-06-15 15:27:54 +00:00
|
|
|
if( item->IsSelected() && aSecondPass )
|
|
|
|
{
|
|
|
|
if( junction )
|
|
|
|
retval.insert( junction );
|
|
|
|
|
|
|
|
retval.insert( line );
|
|
|
|
to_search.push( line );
|
|
|
|
}
|
|
|
|
else if( !junction && !pin )
|
|
|
|
{
|
|
|
|
retval.insert( line );
|
|
|
|
to_search.push( line );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2023-08-02 01:22:35 +00:00
|
|
|
else if( line->GetLayer() == LAYER_NOTES && item->GetLayer() == LAYER_NOTES )
|
|
|
|
{
|
|
|
|
retval.insert( line );
|
|
|
|
to_search.push( line );
|
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
2011-03-10 19:36:30 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
|
2022-06-15 15:27:54 +00:00
|
|
|
for( SCH_ITEM* item : Items() )
|
|
|
|
item->ClearTempFlags();
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
return retval;
|
2011-03-10 19:36:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool SCH_SCREEN::IsJunction( const VECTOR2I& aPosition ) const
|
2021-11-04 12:38:15 +00:00
|
|
|
{
|
|
|
|
bool hasExplicitJunction;
|
|
|
|
bool hasBusEntry;
|
|
|
|
bool isJunction = doIsJunction( aPosition, false, &hasExplicitJunction, &hasBusEntry );
|
|
|
|
|
|
|
|
return isJunction;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool SCH_SCREEN::IsExplicitJunction( const VECTOR2I& aPosition ) const
|
2021-11-04 12:38:15 +00:00
|
|
|
{
|
|
|
|
bool hasExplicitJunction;
|
|
|
|
bool hasBusEntry;
|
|
|
|
bool isJunction = doIsJunction( aPosition, false, &hasExplicitJunction, &hasBusEntry );
|
|
|
|
|
|
|
|
return isJunction && !hasBusEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool SCH_SCREEN::IsExplicitJunctionNeeded( const VECTOR2I& aPosition ) const
|
2021-11-04 12:38:15 +00:00
|
|
|
{
|
|
|
|
bool hasExplicitJunction;
|
|
|
|
bool hasBusEntry;
|
|
|
|
bool isJunction = doIsJunction( aPosition, false, &hasExplicitJunction, &hasBusEntry );
|
|
|
|
|
|
|
|
return isJunction && !hasBusEntry && !hasExplicitJunction;
|
|
|
|
}
|
|
|
|
|
2023-09-07 16:09:53 +00:00
|
|
|
SPIN_STYLE SCH_SCREEN::GetLabelOrientationForPoint( const VECTOR2I& aPosition,
|
|
|
|
SPIN_STYLE aDefaultOrientation,
|
|
|
|
const SCH_SHEET_PATH* aSheet ) const
|
2022-03-26 16:27:45 +00:00
|
|
|
{
|
|
|
|
auto ret = aDefaultOrientation;
|
|
|
|
for( SCH_ITEM* item : Items().Overlapping( aPosition ) )
|
|
|
|
{
|
|
|
|
if( item->GetEditFlags() & STRUCT_DELETED )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
|
|
|
{
|
|
|
|
auto busEntry = static_cast<const SCH_BUS_WIRE_ENTRY*>( item );
|
|
|
|
if( busEntry->m_connected_bus_item )
|
|
|
|
{
|
|
|
|
// bus connected, take the bus direction into consideration ony if it is
|
|
|
|
// vertical or horizontal
|
|
|
|
auto bus = static_cast<const SCH_LINE*>( busEntry->m_connected_bus_item );
|
|
|
|
if( bus->Angle().AsDegrees() == 90.0 )
|
|
|
|
{
|
|
|
|
// bus is vertical -> label shall be horizontal and
|
|
|
|
// shall be placed to the side where the bus entry is
|
|
|
|
if( aPosition.x < bus->GetPosition().x )
|
2023-09-07 16:09:53 +00:00
|
|
|
ret = SPIN_STYLE::LEFT;
|
2022-03-26 16:27:45 +00:00
|
|
|
else if( aPosition.x > bus->GetPosition().x )
|
2023-09-07 16:09:53 +00:00
|
|
|
ret = SPIN_STYLE::RIGHT;
|
2022-03-26 16:27:45 +00:00
|
|
|
}
|
|
|
|
else if( bus->Angle().AsDegrees() == 0.0 )
|
|
|
|
{
|
|
|
|
// bus is horizontal -> label shall be vertical and
|
|
|
|
// shall be placed to the side where the bus entry is
|
|
|
|
if( aPosition.y < bus->GetPosition().y )
|
2023-09-07 16:09:53 +00:00
|
|
|
ret = SPIN_STYLE::UP;
|
2022-03-26 16:27:45 +00:00
|
|
|
else if( aPosition.y > bus->GetPosition().y )
|
2023-09-07 16:09:53 +00:00
|
|
|
ret = SPIN_STYLE::BOTTOM;
|
2022-03-26 16:27:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_LINE_T:
|
|
|
|
{
|
|
|
|
auto line = static_cast<const SCH_LINE*>( item );
|
|
|
|
// line angles goes between -90 and 90 degrees, but normalize
|
|
|
|
auto angle = line->Angle().Normalize90().AsDegrees();
|
|
|
|
|
|
|
|
if( -45 < angle && angle <= 45 )
|
|
|
|
{
|
|
|
|
if( line->GetStartPoint().x <= line->GetEndPoint().x )
|
2023-09-07 16:09:53 +00:00
|
|
|
ret = line->GetEndPoint() == aPosition ? SPIN_STYLE::RIGHT : SPIN_STYLE::LEFT;
|
2022-03-26 16:27:45 +00:00
|
|
|
else
|
2023-09-07 16:09:53 +00:00
|
|
|
ret = line->GetEndPoint() == aPosition ? SPIN_STYLE::LEFT : SPIN_STYLE::RIGHT;
|
2022-03-26 16:27:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( line->GetStartPoint().y <= line->GetEndPoint().y )
|
2023-09-07 16:09:53 +00:00
|
|
|
ret = line->GetEndPoint() == aPosition ? SPIN_STYLE::BOTTOM : SPIN_STYLE::UP;
|
2022-03-26 16:27:45 +00:00
|
|
|
else
|
2023-09-07 16:09:53 +00:00
|
|
|
ret = line->GetEndPoint() == aPosition ? SPIN_STYLE::UP : SPIN_STYLE::BOTTOM;
|
2022-03-26 16:27:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_SYMBOL_T:
|
|
|
|
{
|
2022-07-29 21:02:35 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
|
|
|
|
|
|
|
for( SCH_PIN* pin : symbol->GetPins( aSheet ) )
|
2022-03-26 16:27:45 +00:00
|
|
|
{
|
|
|
|
if( pin->GetPosition() == aPosition )
|
|
|
|
{
|
2023-07-27 03:46:15 +00:00
|
|
|
if( pin->GetOrientation() == PIN_ORIENTATION::PIN_RIGHT )
|
2023-09-07 16:09:53 +00:00
|
|
|
ret = SPIN_STYLE::LEFT;
|
2023-07-27 03:46:15 +00:00
|
|
|
else if( pin->GetOrientation() == PIN_ORIENTATION::PIN_LEFT )
|
2023-09-07 16:09:53 +00:00
|
|
|
ret = SPIN_STYLE::RIGHT;
|
2023-07-27 03:46:15 +00:00
|
|
|
else if( pin->GetOrientation() == PIN_ORIENTATION::PIN_UP )
|
2023-09-07 16:09:53 +00:00
|
|
|
ret = SPIN_STYLE::BOTTOM;
|
2023-07-27 03:46:15 +00:00
|
|
|
else if( pin->GetOrientation() == PIN_ORIENTATION::PIN_DOWN )
|
2023-09-07 16:09:53 +00:00
|
|
|
ret = SPIN_STYLE::UP;
|
2022-03-26 16:27:45 +00:00
|
|
|
|
|
|
|
switch( static_cast<SYMBOL_ORIENTATION_T>(
|
|
|
|
symbol->GetOrientation() & ( ~( SYM_MIRROR_X | SYM_MIRROR_Y ) ) ) )
|
|
|
|
{
|
|
|
|
case SYM_ROTATE_CLOCKWISE:
|
|
|
|
case SYM_ORIENT_90:
|
2023-09-07 16:09:53 +00:00
|
|
|
if( ret == SPIN_STYLE::UP )
|
|
|
|
ret = SPIN_STYLE::LEFT;
|
|
|
|
else if( ret == SPIN_STYLE::BOTTOM )
|
|
|
|
ret = SPIN_STYLE::RIGHT;
|
|
|
|
else if( ret == SPIN_STYLE::LEFT )
|
|
|
|
ret = SPIN_STYLE::BOTTOM;
|
|
|
|
else if( ret == SPIN_STYLE::RIGHT )
|
|
|
|
ret = SPIN_STYLE::UP;
|
2022-03-26 16:27:45 +00:00
|
|
|
|
|
|
|
if( symbol->GetOrientation() & SYM_MIRROR_X )
|
|
|
|
{
|
2023-09-07 16:09:53 +00:00
|
|
|
if( ret == SPIN_STYLE::UP )
|
|
|
|
ret = SPIN_STYLE::BOTTOM;
|
|
|
|
else if( ret == SPIN_STYLE::BOTTOM )
|
|
|
|
ret = SPIN_STYLE::UP;
|
2022-03-26 16:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( symbol->GetOrientation() & SYM_MIRROR_Y )
|
|
|
|
{
|
2023-09-07 16:09:53 +00:00
|
|
|
if( ret == SPIN_STYLE::LEFT )
|
|
|
|
ret = SPIN_STYLE::RIGHT;
|
|
|
|
else if( ret == SPIN_STYLE::RIGHT )
|
|
|
|
ret = SPIN_STYLE::LEFT;
|
2022-03-26 16:27:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SYM_ROTATE_COUNTERCLOCKWISE:
|
|
|
|
case SYM_ORIENT_270:
|
2023-09-07 16:09:53 +00:00
|
|
|
if( ret == SPIN_STYLE::UP )
|
|
|
|
ret = SPIN_STYLE::RIGHT;
|
|
|
|
else if( ret == SPIN_STYLE::BOTTOM )
|
|
|
|
ret = SPIN_STYLE::LEFT;
|
|
|
|
else if( ret == SPIN_STYLE::LEFT )
|
|
|
|
ret = SPIN_STYLE::UP;
|
|
|
|
else if( ret == SPIN_STYLE::RIGHT )
|
|
|
|
ret = SPIN_STYLE::BOTTOM;
|
2022-03-26 16:27:45 +00:00
|
|
|
|
|
|
|
if( symbol->GetOrientation() & SYM_MIRROR_X )
|
|
|
|
{
|
2023-09-07 16:09:53 +00:00
|
|
|
if( ret == SPIN_STYLE::UP )
|
|
|
|
ret = SPIN_STYLE::BOTTOM;
|
|
|
|
else if( ret == SPIN_STYLE::BOTTOM )
|
|
|
|
ret = SPIN_STYLE::UP;
|
2022-03-26 16:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( symbol->GetOrientation() & SYM_MIRROR_Y )
|
|
|
|
{
|
2023-09-07 16:09:53 +00:00
|
|
|
if( ret == SPIN_STYLE::LEFT )
|
|
|
|
ret = SPIN_STYLE::RIGHT;
|
|
|
|
else if( ret == SPIN_STYLE::RIGHT )
|
|
|
|
ret = SPIN_STYLE::LEFT;
|
2022-03-26 16:27:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SYM_ORIENT_180:
|
2023-09-07 16:09:53 +00:00
|
|
|
if( ret == SPIN_STYLE::UP )
|
|
|
|
ret = SPIN_STYLE::BOTTOM;
|
|
|
|
else if( ret == SPIN_STYLE::BOTTOM )
|
|
|
|
ret = SPIN_STYLE::UP;
|
|
|
|
else if( ret == SPIN_STYLE::LEFT )
|
|
|
|
ret = SPIN_STYLE::RIGHT;
|
|
|
|
else if( ret == SPIN_STYLE::RIGHT )
|
|
|
|
ret = SPIN_STYLE::LEFT;
|
2022-03-26 16:27:45 +00:00
|
|
|
|
|
|
|
if( symbol->GetOrientation() & SYM_MIRROR_X )
|
|
|
|
{
|
2023-09-07 16:09:53 +00:00
|
|
|
if( ret == SPIN_STYLE::UP )
|
|
|
|
ret = SPIN_STYLE::BOTTOM;
|
|
|
|
else if( ret == SPIN_STYLE::BOTTOM )
|
|
|
|
ret = SPIN_STYLE::UP;
|
2022-03-26 16:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( symbol->GetOrientation() & SYM_MIRROR_Y )
|
|
|
|
{
|
2023-09-07 16:09:53 +00:00
|
|
|
if( ret == SPIN_STYLE::LEFT )
|
|
|
|
ret = SPIN_STYLE::RIGHT;
|
|
|
|
else if( ret == SPIN_STYLE::RIGHT )
|
|
|
|
ret = SPIN_STYLE::LEFT;
|
2022-03-26 16:27:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SYM_ORIENT_0:
|
|
|
|
case SYM_NORMAL:
|
|
|
|
default:
|
|
|
|
if( symbol->GetOrientation() & SYM_MIRROR_X )
|
|
|
|
{
|
2023-09-07 16:09:53 +00:00
|
|
|
if( ret == SPIN_STYLE::UP )
|
|
|
|
ret = SPIN_STYLE::BOTTOM;
|
|
|
|
else if( ret == SPIN_STYLE::BOTTOM )
|
|
|
|
ret = SPIN_STYLE::UP;
|
2022-03-26 16:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( symbol->GetOrientation() & SYM_MIRROR_Y )
|
|
|
|
{
|
2023-09-07 16:09:53 +00:00
|
|
|
if( ret == SPIN_STYLE::LEFT )
|
|
|
|
ret = SPIN_STYLE::RIGHT;
|
|
|
|
else if( ret == SPIN_STYLE::RIGHT )
|
|
|
|
ret = SPIN_STYLE::LEFT;
|
2022-03-26 16:27:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-11-04 12:38:15 +00:00
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool SCH_SCREEN::IsExplicitJunctionAllowed( const VECTOR2I& aPosition ) const
|
2021-11-04 12:38:15 +00:00
|
|
|
{
|
|
|
|
bool hasExplicitJunction;
|
|
|
|
bool hasBusEntry;
|
|
|
|
bool isJunction = doIsJunction( aPosition, true, &hasExplicitJunction, &hasBusEntry );
|
|
|
|
|
|
|
|
return isJunction && !hasBusEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool SCH_SCREEN::doIsJunction( const VECTOR2I& aPosition, bool aBreakCrossings,
|
2021-11-04 12:38:15 +00:00
|
|
|
bool* aHasExplicitJunctionDot, bool* aHasBusEntry ) const
|
2011-03-10 19:36:30 +00:00
|
|
|
{
|
2021-03-19 21:00:24 +00:00
|
|
|
enum layers { WIRES = 0, BUSES };
|
2021-03-18 18:31:16 +00:00
|
|
|
|
2021-11-04 12:38:15 +00:00
|
|
|
*aHasExplicitJunctionDot = false;
|
|
|
|
*aHasBusEntry = false;
|
|
|
|
|
2021-03-18 23:48:52 +00:00
|
|
|
bool breakLines[ 2 ] = { false };
|
|
|
|
std::unordered_set<int> exitAngles[ 2 ];
|
|
|
|
std::vector<const SCH_LINE*> midPointLines[ 2 ];
|
2019-05-17 09:29:52 +00:00
|
|
|
|
2022-01-08 13:23:32 +00:00
|
|
|
// A pin at 90° still shouldn't match a line at 90° so just give pins unique numbers
|
2021-03-18 16:37:53 +00:00
|
|
|
int uniqueAngle = 10000;
|
2017-11-27 19:27:24 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
for( const SCH_ITEM* item : Items().Overlapping( aPosition ) )
|
2011-03-10 19:36:30 +00:00
|
|
|
{
|
2019-04-22 08:58:06 +00:00
|
|
|
if( item->GetEditFlags() & STRUCT_DELETED )
|
2017-11-27 19:27:24 +00:00
|
|
|
continue;
|
2017-12-07 20:19:53 +00:00
|
|
|
|
2020-08-10 11:40:58 +00:00
|
|
|
switch( item->Type() )
|
2017-12-13 05:12:06 +00:00
|
|
|
{
|
2020-08-10 11:40:58 +00:00
|
|
|
case SCH_JUNCTION_T:
|
2021-11-04 12:38:15 +00:00
|
|
|
if( item->HitTest( aPosition, -1 ) )
|
|
|
|
*aHasExplicitJunctionDot = true;
|
2020-08-10 11:40:58 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_LINE_T:
|
2021-03-18 16:37:53 +00:00
|
|
|
{
|
|
|
|
const SCH_LINE* line = static_cast<const SCH_LINE*>( item );
|
2021-03-18 18:31:16 +00:00
|
|
|
int layer;
|
|
|
|
|
2021-03-18 23:48:52 +00:00
|
|
|
if( line->GetStartPoint() == line->GetEndPoint() )
|
|
|
|
break;
|
|
|
|
else if( line->GetLayer() == LAYER_WIRE )
|
2021-03-18 18:31:16 +00:00
|
|
|
layer = WIRES;
|
|
|
|
else if( line->GetLayer() == LAYER_BUS )
|
|
|
|
layer = BUSES;
|
|
|
|
else
|
|
|
|
break;
|
2021-03-18 16:37:53 +00:00
|
|
|
|
|
|
|
if( line->IsConnected( aPosition ) )
|
|
|
|
{
|
2021-03-18 18:31:16 +00:00
|
|
|
breakLines[ layer ] = true;
|
|
|
|
exitAngles[ layer ].insert( line->GetAngleFrom( aPosition ) );
|
2021-03-18 16:37:53 +00:00
|
|
|
}
|
2021-03-18 23:48:52 +00:00
|
|
|
else if( line->HitTest( aPosition, -1 ) )
|
2020-08-10 11:40:58 +00:00
|
|
|
{
|
2021-11-04 12:38:15 +00:00
|
|
|
if( aBreakCrossings )
|
2021-10-29 18:08:24 +00:00
|
|
|
breakLines[ layer ] = true;
|
|
|
|
|
2021-03-18 16:37:53 +00:00
|
|
|
// Defer any line midpoints until we know whether or not we're breaking them
|
2021-03-18 18:31:16 +00:00
|
|
|
midPointLines[ layer ].push_back( line );
|
2020-08-10 11:40:58 +00:00
|
|
|
}
|
2021-03-18 16:37:53 +00:00
|
|
|
}
|
2020-08-10 11:40:58 +00:00
|
|
|
break;
|
2017-12-07 20:19:53 +00:00
|
|
|
|
2020-08-10 11:40:58 +00:00
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
2021-10-30 18:57:30 +00:00
|
|
|
if( item->IsConnected( aPosition ) )
|
|
|
|
{
|
|
|
|
breakLines[ BUSES ] = true;
|
|
|
|
exitAngles[ BUSES ].insert( uniqueAngle++ );
|
|
|
|
breakLines[ WIRES ] = true;
|
|
|
|
exitAngles[ WIRES ].insert( uniqueAngle++ );
|
2021-11-04 12:38:15 +00:00
|
|
|
*aHasBusEntry = true;
|
2021-10-30 18:57:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
case SCH_SYMBOL_T:
|
2020-08-10 11:40:58 +00:00
|
|
|
case SCH_SHEET_T:
|
|
|
|
if( item->IsConnected( aPosition ) )
|
2021-03-18 16:37:53 +00:00
|
|
|
{
|
2021-03-18 18:31:16 +00:00
|
|
|
breakLines[ WIRES ] = true;
|
|
|
|
exitAngles[ WIRES ].insert( uniqueAngle++ );
|
2021-03-18 16:37:53 +00:00
|
|
|
}
|
2020-08-10 11:40:58 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-03-10 19:36:30 +00:00
|
|
|
}
|
|
|
|
|
2021-03-18 18:31:16 +00:00
|
|
|
for( int layer : { WIRES, BUSES } )
|
2017-11-27 19:27:24 +00:00
|
|
|
{
|
2021-03-18 18:31:16 +00:00
|
|
|
if( breakLines[ layer ] )
|
2017-11-27 19:27:24 +00:00
|
|
|
{
|
2021-03-18 18:31:16 +00:00
|
|
|
for( const SCH_LINE* line : midPointLines[ layer ] )
|
|
|
|
{
|
|
|
|
exitAngles[ layer ].insert( line->GetAngleFrom( aPosition ) );
|
|
|
|
exitAngles[ layer ].insert( line->GetReverseAngleFrom( aPosition ) );
|
|
|
|
}
|
2017-11-27 19:27:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-18 18:31:16 +00:00
|
|
|
return exitAngles[ WIRES ].size() >= 3 || exitAngles[ BUSES ].size() >= 3;
|
2011-03-10 19:36:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
bool SCH_SCREEN::IsTerminalPoint( const VECTOR2I& aPosition, int aLayer ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
|
|
|
wxCHECK_MSG( aLayer == LAYER_NOTES || aLayer == LAYER_BUS || aLayer == LAYER_WIRE, false,
|
|
|
|
wxT( "Invalid layer type passed to SCH_SCREEN::IsTerminalPoint()." ) );
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
SCH_SHEET_PIN* sheetPin;
|
|
|
|
SCH_LABEL_BASE* label;
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
switch( aLayer )
|
|
|
|
{
|
|
|
|
case LAYER_BUS:
|
|
|
|
if( GetBus( aPosition ) )
|
|
|
|
return true;
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
sheetPin = GetSheetPin( aPosition );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2021-02-26 00:21:33 +00:00
|
|
|
if( sheetPin && sheetPin->IsConnected( aPosition ) )
|
2011-03-25 19:16:05 +00:00
|
|
|
return true;
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
label = GetLabel( aPosition );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2023-08-05 17:50:12 +00:00
|
|
|
if( label && !label->IsNew() && label->IsConnected( aPosition ) )
|
2011-03-25 19:16:05 +00:00
|
|
|
return true;
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_NOTES:
|
|
|
|
if( GetLine( aPosition ) )
|
|
|
|
return true;
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_WIRE:
|
2023-08-05 17:50:12 +00:00
|
|
|
if( GetItem( aPosition, 1, SCH_BUS_WIRE_ENTRY_T ) )
|
2013-04-01 10:35:20 +00:00
|
|
|
return true;
|
|
|
|
|
2021-02-26 00:21:33 +00:00
|
|
|
if( GetItem( aPosition, 1, SCH_JUNCTION_T ) )
|
2011-03-25 19:16:05 +00:00
|
|
|
return true;
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
if( GetPin( aPosition, nullptr, true ) )
|
2011-03-25 19:16:05 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if( GetWire( aPosition ) )
|
|
|
|
return true;
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
label = GetLabel( aPosition, 1 );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2023-08-05 17:50:12 +00:00
|
|
|
if( label && !label->IsNew() && label->IsConnected( aPosition ) )
|
2011-03-25 19:16:05 +00:00
|
|
|
return true;
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
sheetPin = GetSheetPin( aPosition );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2021-02-26 00:21:33 +00:00
|
|
|
if( sheetPin && sheetPin->IsConnected( aPosition ) )
|
2011-03-25 19:16:05 +00:00
|
|
|
return true;
|
2022-01-25 22:33:37 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
void SCH_SCREEN::UpdateSymbolLinks( REPORTER* aReporter )
|
2011-01-11 20:34:29 +00:00
|
|
|
{
|
2020-05-21 02:27:48 +00:00
|
|
|
wxCHECK_RET( Schematic(), "Cannot call SCH_SCREEN::UpdateSymbolLinks with no SCHEMATIC" );
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
wxString msg;
|
2021-06-10 18:51:46 +00:00
|
|
|
std::unique_ptr< LIB_SYMBOL > libSymbol;
|
2021-06-10 14:10:55 +00:00
|
|
|
std::vector<SCH_SYMBOL*> symbols;
|
2023-09-28 03:04:53 +00:00
|
|
|
SYMBOL_LIB_TABLE* libs = PROJECT_SCH::SchSymbolLibTable( &Schematic()->Prj() );
|
2020-04-16 16:43:50 +00:00
|
|
|
|
|
|
|
// This will be a nullptr if an s-expression schematic is loaded.
|
2023-09-28 03:04:53 +00:00
|
|
|
SYMBOL_LIBS* legacyLibs = PROJECT_SCH::SchLibs( &Schematic()->Prj() );
|
2020-04-16 16:43:50 +00:00
|
|
|
|
2021-11-23 21:18:04 +00:00
|
|
|
for( SCH_ITEM* item : Items().OfType( SCH_SYMBOL_T ) )
|
2021-06-10 14:10:55 +00:00
|
|
|
symbols.push_back( static_cast<SCH_SYMBOL*>( item ) );
|
2020-04-16 16:43:50 +00:00
|
|
|
|
|
|
|
// Remove them from the R tree. There bounding box size may change.
|
2021-11-23 21:18:04 +00:00
|
|
|
for( SCH_SYMBOL* symbol : symbols )
|
2020-04-16 16:43:50 +00:00
|
|
|
Remove( symbol );
|
|
|
|
|
|
|
|
// Clear all existing symbol links.
|
|
|
|
clearLibSymbols();
|
|
|
|
|
2021-07-28 15:39:40 +00:00
|
|
|
for( SCH_SYMBOL* symbol : symbols )
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
{
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* tmp = nullptr;
|
2020-04-16 16:43:50 +00:00
|
|
|
libSymbol.reset();
|
|
|
|
|
|
|
|
// If the symbol is already in the internal library, map the symbol to it.
|
|
|
|
auto it = m_libSymbols.find( symbol->GetSchSymbolLibraryName() );
|
|
|
|
|
|
|
|
if( ( it != m_libSymbols.end() ) )
|
|
|
|
{
|
|
|
|
if( aReporter )
|
|
|
|
{
|
2021-07-28 15:39:40 +00:00
|
|
|
msg.Printf( _( "Setting schematic symbol '%s %s' library identifier to '%s'." ),
|
2020-11-12 21:31:41 +00:00
|
|
|
symbol->GetField( REFERENCE_FIELD )->GetText(),
|
|
|
|
symbol->GetField( VALUE_FIELD )->GetText(),
|
2021-07-28 15:39:40 +00:00
|
|
|
UnescapeString( symbol->GetLibId().Format() ) );
|
2020-04-16 16:43:50 +00:00
|
|
|
aReporter->ReportTail( msg, RPT_SEVERITY_INFO );
|
|
|
|
}
|
2017-12-11 03:28:34 +00:00
|
|
|
|
2020-05-05 22:35:27 +00:00
|
|
|
// Internal library symbols are already flattened so just make a copy.
|
2021-06-10 18:51:46 +00:00
|
|
|
symbol->SetLibSymbol( new LIB_SYMBOL( *it->second ) );
|
2020-04-16 16:43:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !symbol->GetLibId().IsValid() )
|
|
|
|
{
|
|
|
|
if( aReporter )
|
|
|
|
{
|
2021-07-28 15:39:40 +00:00
|
|
|
msg.Printf( _( "Schematic symbol reference '%s' library identifier is not valid. "
|
|
|
|
"Unable to link library symbol." ),
|
|
|
|
UnescapeString( symbol->GetLibId().Format() ) );
|
2020-04-16 16:43:50 +00:00
|
|
|
aReporter->ReportTail( msg, RPT_SEVERITY_WARNING );
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
// LIB_TABLE_BASE::LoadSymbol() throws an IO_ERROR if the library nickname
|
2020-04-16 16:43:50 +00:00
|
|
|
// is not found in the table so check if the library still exists in the table
|
|
|
|
// before attempting to load the symbol.
|
|
|
|
if( !libs->HasLibrary( symbol->GetLibId().GetLibNickname() ) && !legacyLibs )
|
|
|
|
{
|
|
|
|
if( aReporter )
|
|
|
|
{
|
2021-07-28 15:39:40 +00:00
|
|
|
msg.Printf( _( "Symbol library '%s' not found and no fallback cache library "
|
|
|
|
"available. Unable to link library symbol." ),
|
2020-04-16 16:43:50 +00:00
|
|
|
symbol->GetLibId().GetLibNickname().wx_str() );
|
|
|
|
aReporter->ReportTail( msg, RPT_SEVERITY_WARNING );
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
if( libs->HasLibrary( symbol->GetLibId().GetLibNickname() ) )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
tmp = libs->LoadSymbol( symbol->GetLibId() );
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& ioe )
|
|
|
|
{
|
2020-08-18 13:34:34 +00:00
|
|
|
if( aReporter )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "I/O error %s resolving library symbol %s" ), ioe.What(),
|
2021-07-28 15:39:40 +00:00
|
|
|
UnescapeString( symbol->GetLibId().Format() ) );
|
2020-08-18 13:34:34 +00:00
|
|
|
aReporter->ReportTail( msg, RPT_SEVERITY_ERROR );
|
|
|
|
}
|
2020-04-16 16:43:50 +00:00
|
|
|
}
|
|
|
|
}
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2021-03-10 14:52:41 +00:00
|
|
|
if( !tmp && legacyLibs && legacyLibs->GetLibraryCount() )
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
{
|
2022-10-11 20:16:11 +00:00
|
|
|
SYMBOL_LIB& legacyCacheLib = legacyLibs->back();
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
|
2021-03-10 14:52:41 +00:00
|
|
|
// It better be the cache library.
|
2020-04-16 16:43:50 +00:00
|
|
|
wxCHECK2( legacyCacheLib.IsCache(), continue );
|
|
|
|
|
|
|
|
wxString id = symbol->GetLibId().Format();
|
|
|
|
|
|
|
|
id.Replace( ':', '_' );
|
|
|
|
|
|
|
|
if( aReporter )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Falling back to cache to set symbol '%s:%s' link '%s'." ),
|
2020-11-12 21:31:41 +00:00
|
|
|
symbol->GetField( REFERENCE_FIELD )->GetText(),
|
|
|
|
symbol->GetField( VALUE_FIELD )->GetText(),
|
2021-07-28 15:39:40 +00:00
|
|
|
UnescapeString( id ) );
|
2020-04-16 16:43:50 +00:00
|
|
|
aReporter->ReportTail( msg, RPT_SEVERITY_WARNING );
|
|
|
|
}
|
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
tmp = legacyCacheLib.FindSymbol( id );
|
2020-04-16 16:43:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( tmp )
|
|
|
|
{
|
|
|
|
// We want a full symbol not just the top level child symbol.
|
|
|
|
libSymbol = tmp->Flatten();
|
|
|
|
libSymbol->SetParent();
|
|
|
|
|
|
|
|
m_libSymbols.insert( { symbol->GetSchSymbolLibraryName(),
|
2021-06-10 18:51:46 +00:00
|
|
|
new LIB_SYMBOL( *libSymbol.get() ) } );
|
2020-04-16 16:43:50 +00:00
|
|
|
|
|
|
|
if( aReporter )
|
|
|
|
{
|
2020-12-27 14:54:37 +00:00
|
|
|
msg.Printf( _( "Setting schematic symbol '%s %s' library identifier to '%s'." ),
|
2020-11-12 21:31:41 +00:00
|
|
|
symbol->GetField( REFERENCE_FIELD )->GetText(),
|
|
|
|
symbol->GetField( VALUE_FIELD )->GetText(),
|
2021-07-28 15:39:40 +00:00
|
|
|
UnescapeString( symbol->GetLibId().Format() ) );
|
2020-04-16 16:43:50 +00:00
|
|
|
aReporter->ReportTail( msg, RPT_SEVERITY_INFO );
|
|
|
|
}
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
}
|
2017-12-11 03:28:34 +00:00
|
|
|
else
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2020-04-16 16:43:50 +00:00
|
|
|
if( aReporter )
|
|
|
|
{
|
2020-12-27 14:54:37 +00:00
|
|
|
msg.Printf( _( "No library symbol found for schematic symbol '%s %s'." ),
|
2020-11-12 21:31:41 +00:00
|
|
|
symbol->GetField( REFERENCE_FIELD )->GetText(),
|
|
|
|
symbol->GetField( VALUE_FIELD )->GetText() );
|
2020-04-16 16:43:50 +00:00
|
|
|
aReporter->ReportTail( msg, RPT_SEVERITY_ERROR );
|
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
2020-01-23 14:05:12 +00:00
|
|
|
|
2023-12-04 17:12:51 +00:00
|
|
|
if( libSymbol.get() ) // Only change the old link if the new link exists
|
|
|
|
symbol->SetLibSymbol( libSymbol.release() );
|
2020-04-16 16:43:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Changing the symbol may adjust the bbox of the symbol. This re-inserts the
|
|
|
|
// item with the new bbox
|
2021-11-23 21:18:04 +00:00
|
|
|
for( SCH_SYMBOL* symbol : symbols )
|
2020-04-16 16:43:50 +00:00
|
|
|
Append( symbol );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SCREEN::UpdateLocalLibSymbolLinks()
|
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
std::vector<SCH_SYMBOL*> symbols;
|
2020-05-20 22:50:09 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
for( SCH_ITEM* item : Items().OfType( SCH_SYMBOL_T ) )
|
|
|
|
symbols.push_back( static_cast<SCH_SYMBOL*>( item ) );
|
2020-05-20 22:50:09 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
for( SCH_SYMBOL* symbol : symbols )
|
2020-04-16 16:43:50 +00:00
|
|
|
{
|
2020-05-20 22:50:09 +00:00
|
|
|
// Changing the symbol may adjust the bbox of the symbol; remove and reinsert it afterwards.
|
|
|
|
m_rtree.remove( symbol );
|
2020-04-16 16:43:50 +00:00
|
|
|
|
|
|
|
auto it = m_libSymbols.find( symbol->GetSchSymbolLibraryName() );
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
LIB_SYMBOL* libSymbol = nullptr;
|
2020-04-16 16:43:50 +00:00
|
|
|
|
|
|
|
if( it != m_libSymbols.end() )
|
2021-06-10 18:51:46 +00:00
|
|
|
libSymbol = new LIB_SYMBOL( *it->second );
|
2020-04-16 16:43:50 +00:00
|
|
|
|
|
|
|
symbol->SetLibSymbol( libSymbol );
|
2020-05-20 22:50:09 +00:00
|
|
|
|
|
|
|
m_rtree.insert( symbol );
|
Modular KiCad Blueprint Milestone B), major portions:
*) When kicad.exe closes a project, close any open KIFACEs so that they cannot
get disassociated from their true PROJECT.
*) Allow loading eeschema library editor from kicad.exe
*) Allow loading pcbnew library editor from kicad.exe
*) Rename LIB_COMPONENT to LIB_PART.
*) Add class PART_LIBS, and PART_LIB.
*) Make PART_LIBS non-global, i.e. PROJECT specific.
*) Implement "data on demand" for PART_LIBS
*) Implement "data on demand" for schematic SEARCH_STACK.
*) Use RSTRINGs to retain eeschema editor's notion of last library and part being edited.
*) Get rid of library search on every SCH_COMPONENT::Draw() call, instead use
a weak pointer.
*) Remove all chdir() calls so projects don't need to be CWD.
*) Romove APPEND support from OpenProjectFiles().
*) Make OpenProjectFiles() robust, even for creating new projects.
*) Load EESCHEMA colors in the KIWAY::OnKiwayStart() rather in window open,
and save them in the .eeschema config file, not in the project file.
*) Fix bug with wxDir() while accessing protected dirs in kicad.exe
*) Consolidate template copying into PROJECT class, not in kicad.exe source.
*) Generally untangle eeschema, making its libraries not global but rather
held in the PROJECT.
2014-08-13 20:28:54 +00:00
|
|
|
}
|
2014-08-18 16:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-24 13:19:50 +00:00
|
|
|
void SCH_SCREEN::SetConnectivityDirty()
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : Items() )
|
|
|
|
item->SetConnectivityDirty( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-20 18:18:54 +00:00
|
|
|
void SCH_SCREEN::Print( const RENDER_SETTINGS* aSettings )
|
2014-08-18 16:39:51 +00:00
|
|
|
{
|
2020-01-10 04:15:46 +00:00
|
|
|
// Ensure links are up to date, even if a library was reloaded for some reason:
|
2020-12-15 17:11:14 +00:00
|
|
|
std::vector<SCH_ITEM*> junctions;
|
|
|
|
std::vector<SCH_ITEM*> bitmaps;
|
|
|
|
std::vector<SCH_ITEM*> other;
|
2014-08-18 16:39:51 +00:00
|
|
|
|
2020-12-15 17:11:14 +00:00
|
|
|
for( SCH_ITEM* item : Items() )
|
2011-01-11 20:34:29 +00:00
|
|
|
{
|
2022-12-28 14:49:15 +00:00
|
|
|
if( item->IsMoving() )
|
2011-01-11 20:34:29 +00:00
|
|
|
continue;
|
|
|
|
|
2017-11-03 17:56:59 +00:00
|
|
|
if( item->Type() == SCH_JUNCTION_T )
|
|
|
|
junctions.push_back( item );
|
2020-01-10 04:15:46 +00:00
|
|
|
else if( item->Type() == SCH_BITMAP_T )
|
|
|
|
bitmaps.push_back( item );
|
2017-11-03 17:56:59 +00:00
|
|
|
else
|
2020-01-10 04:15:46 +00:00
|
|
|
other.push_back( item );
|
2011-01-11 20:34:29 +00:00
|
|
|
}
|
2017-11-03 17:56:59 +00:00
|
|
|
|
2020-01-10 04:15:46 +00:00
|
|
|
/// Sort to ensure plot-order consistency with screen drawing
|
2022-10-02 20:21:52 +00:00
|
|
|
std::stable_sort( other.begin(), other.end(),
|
2020-04-14 12:25:00 +00:00
|
|
|
[]( const SCH_ITEM* a, const SCH_ITEM* b )
|
|
|
|
{
|
|
|
|
if( a->Type() == b->Type() )
|
|
|
|
return a->GetLayer() > b->GetLayer();
|
2020-01-10 04:15:46 +00:00
|
|
|
|
2022-10-02 20:21:52 +00:00
|
|
|
return a->Type() < b->Type();
|
2020-04-14 12:25:00 +00:00
|
|
|
} );
|
2020-01-10 04:15:46 +00:00
|
|
|
|
2020-12-15 17:11:14 +00:00
|
|
|
for( SCH_ITEM* item : bitmaps )
|
2022-01-01 06:04:08 +00:00
|
|
|
item->Print( aSettings, VECTOR2I( 0, 0 ) );
|
2020-01-10 04:15:46 +00:00
|
|
|
|
2022-10-02 20:21:52 +00:00
|
|
|
for( SCH_ITEM* item : other )
|
|
|
|
item->PrintBackground( aSettings, VECTOR2I( 0, 0 ) );
|
|
|
|
|
2020-12-15 17:11:14 +00:00
|
|
|
for( SCH_ITEM* item : other )
|
2022-01-01 06:04:08 +00:00
|
|
|
item->Print( aSettings, VECTOR2I( 0, 0 ) );
|
2020-01-10 04:15:46 +00:00
|
|
|
|
2020-12-15 17:11:14 +00:00
|
|
|
for( SCH_ITEM* item : junctions )
|
2022-01-01 06:04:08 +00:00
|
|
|
item->Print( aSettings, VECTOR2I( 0, 0 ) );
|
2011-01-11 20:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-21 20:52:51 +00:00
|
|
|
void SCH_SCREEN::Plot( PLOTTER* aPlotter, const SCH_PLOT_SETTINGS& aPlotSettings ) const
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2019-06-16 20:27:11 +00:00
|
|
|
// Ensure links are up to date, even if a library was reloaded for some reason:
|
2022-07-05 23:37:36 +00:00
|
|
|
std::vector<SCH_ITEM*> junctions;
|
|
|
|
std::vector<SCH_ITEM*> bitmaps;
|
|
|
|
std::vector<SCH_SYMBOL*> symbols;
|
|
|
|
std::vector<SCH_ITEM*> other;
|
2019-06-16 20:27:11 +00:00
|
|
|
|
2021-11-23 21:18:04 +00:00
|
|
|
for( SCH_ITEM* item : Items() )
|
2019-06-16 20:27:11 +00:00
|
|
|
{
|
2022-12-28 14:49:15 +00:00
|
|
|
if( item->IsMoving() )
|
2019-06-16 20:27:11 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if( item->Type() == SCH_JUNCTION_T )
|
|
|
|
junctions.push_back( item );
|
|
|
|
else if( item->Type() == SCH_BITMAP_T )
|
|
|
|
bitmaps.push_back( item );
|
|
|
|
else
|
|
|
|
other.push_back( item );
|
2022-07-05 23:37:36 +00:00
|
|
|
|
|
|
|
// Where the symbols overlap each other, we need to plot the text items a second
|
|
|
|
// time to get them on top of the overlapping element. This collection is in addition
|
|
|
|
// to the symbols already collected in `other`
|
|
|
|
if( item->Type() == SCH_SYMBOL_T )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* sym : m_rtree.Overlapping( SCH_SYMBOL_T, item->GetBoundingBox() ) )
|
|
|
|
{
|
|
|
|
if( sym != item )
|
|
|
|
{
|
|
|
|
symbols.push_back( static_cast<SCH_SYMBOL*>( item ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-16 20:27:11 +00:00
|
|
|
}
|
|
|
|
|
2020-01-10 04:15:46 +00:00
|
|
|
/// Sort to ensure plot-order consistency with screen drawing
|
2020-12-15 17:11:14 +00:00
|
|
|
std::sort( other.begin(), other.end(),
|
|
|
|
[]( const SCH_ITEM* a, const SCH_ITEM* b )
|
|
|
|
{
|
|
|
|
if( a->Type() == b->Type() )
|
|
|
|
return a->GetLayer() > b->GetLayer();
|
2020-01-10 04:15:46 +00:00
|
|
|
|
2020-12-15 17:11:14 +00:00
|
|
|
return a->Type() > b->Type();
|
|
|
|
} );
|
2020-01-10 04:15:46 +00:00
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
int defaultPenWidth = aPlotter->RenderSettings()->GetDefaultPenWidth();
|
2022-02-10 19:49:25 +00:00
|
|
|
constexpr bool background = true;
|
2020-04-14 12:25:00 +00:00
|
|
|
|
2019-06-16 20:27:11 +00:00
|
|
|
// Bitmaps are drawn first to ensure they are in the background
|
|
|
|
// This is particularly important for the wxPostscriptDC (used in *nix printers) as
|
|
|
|
// the bitmap PS command clears the screen
|
2021-03-06 09:27:41 +00:00
|
|
|
for( const SCH_ITEM* item : bitmaps )
|
2019-06-16 20:27:11 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
aPlotter->SetCurrentLineWidth( std::max( item->GetPenWidth(), defaultPenWidth ) );
|
2023-10-21 20:52:51 +00:00
|
|
|
item->Plot( aPlotter, background, aPlotSettings );
|
2019-06-16 20:27:11 +00:00
|
|
|
}
|
|
|
|
|
2023-10-02 14:38:22 +00:00
|
|
|
// Plot the background items
|
2021-03-06 09:27:41 +00:00
|
|
|
for( const SCH_ITEM* item : other )
|
2019-06-16 20:27:11 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
aPlotter->SetCurrentLineWidth( std::max( item->GetPenWidth(), defaultPenWidth ) );
|
2023-10-21 20:52:51 +00:00
|
|
|
item->Plot( aPlotter, background, aPlotSettings );
|
2022-02-10 19:49:25 +00:00
|
|
|
}
|
|
|
|
|
2023-10-02 14:38:22 +00:00
|
|
|
// Plot the foreground items
|
2022-02-10 19:49:25 +00:00
|
|
|
for( const SCH_ITEM* item : other )
|
|
|
|
{
|
|
|
|
aPlotter->SetCurrentLineWidth( std::max( item->GetPenWidth(), defaultPenWidth ) );
|
2023-10-21 20:52:51 +00:00
|
|
|
item->Plot( aPlotter, !background, aPlotSettings );
|
2019-06-16 20:27:11 +00:00
|
|
|
}
|
|
|
|
|
2022-07-05 23:37:36 +00:00
|
|
|
// After plotting the symbols as a group above (in `other`), we need to overplot the pins
|
|
|
|
// and symbols to ensure that they are always visible
|
|
|
|
for( const SCH_SYMBOL* sym :symbols )
|
|
|
|
{
|
|
|
|
aPlotter->SetCurrentLineWidth( std::max( sym->GetPenWidth(), defaultPenWidth ) );
|
|
|
|
|
|
|
|
for( SCH_FIELD field : sym->GetFields() )
|
2023-10-02 14:38:22 +00:00
|
|
|
{
|
|
|
|
field.ClearRenderCache();
|
2023-10-21 20:52:51 +00:00
|
|
|
field.Plot( aPlotter, false, aPlotSettings );
|
2023-10-02 14:38:22 +00:00
|
|
|
}
|
2022-07-05 23:37:36 +00:00
|
|
|
|
|
|
|
sym->PlotPins( aPlotter );
|
2023-01-09 23:30:58 +00:00
|
|
|
|
|
|
|
if( sym->GetDNP() )
|
|
|
|
sym->PlotDNP( aPlotter );
|
2022-07-05 23:37:36 +00:00
|
|
|
}
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
for( const SCH_ITEM* item : junctions )
|
2011-06-17 13:24:22 +00:00
|
|
|
{
|
2020-04-14 12:25:00 +00:00
|
|
|
aPlotter->SetCurrentLineWidth( std::max( item->GetPenWidth(), defaultPenWidth ) );
|
2023-10-21 20:52:51 +00:00
|
|
|
item->Plot( aPlotter, !background, aPlotSettings );
|
2011-06-17 13:24:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
void SCH_SCREEN::ClearDrawingState()
|
|
|
|
{
|
2020-12-15 17:11:14 +00:00
|
|
|
for( SCH_ITEM* item : Items() )
|
2019-05-01 11:37:35 +00:00
|
|
|
item->ClearTempFlags();
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
LIB_PIN* SCH_SCREEN::GetPin( const VECTOR2I& aPosition, SCH_SYMBOL** aSymbol,
|
2021-03-06 09:27:41 +00:00
|
|
|
bool aEndPointOnly ) const
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
SCH_SYMBOL* candidate = nullptr;
|
|
|
|
LIB_PIN* pin = nullptr;
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
for( SCH_ITEM* item : Items().Overlapping( SCH_SYMBOL_T, aPosition ) )
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
candidate = static_cast<SCH_SYMBOL*>( item );
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2011-05-05 17:45:35 +00:00
|
|
|
if( aEndPointOnly )
|
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
pin = nullptr;
|
2011-12-07 20:19:29 +00:00
|
|
|
|
2021-06-15 12:31:28 +00:00
|
|
|
if( !candidate->GetLibSymbolRef() )
|
2011-05-05 17:45:35 +00:00
|
|
|
continue;
|
2011-12-07 20:19:29 +00:00
|
|
|
|
2023-01-20 22:12:15 +00:00
|
|
|
std::vector<LIB_PIN*> pins;
|
|
|
|
candidate->GetLibPins( pins );
|
2011-12-07 20:19:29 +00:00
|
|
|
|
2023-01-20 22:12:15 +00:00
|
|
|
for( LIB_PIN* test_pin : pins )
|
|
|
|
{
|
|
|
|
if( candidate->GetPinPhysicalPosition( test_pin ) == aPosition )
|
|
|
|
{
|
|
|
|
pin = test_pin;
|
2011-05-05 17:45:35 +00:00
|
|
|
break;
|
2023-01-20 22:12:15 +00:00
|
|
|
}
|
2011-05-05 17:45:35 +00:00
|
|
|
}
|
2020-12-15 17:11:14 +00:00
|
|
|
|
2011-05-05 17:45:35 +00:00
|
|
|
if( pin )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-15 17:03:27 +00:00
|
|
|
pin = (LIB_PIN*) candidate->GetDrawItem( aPosition, LIB_PIN_T );
|
2011-12-07 20:19:29 +00:00
|
|
|
|
2011-05-05 17:45:35 +00:00
|
|
|
if( pin )
|
|
|
|
break;
|
|
|
|
}
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
2011-01-10 20:35:24 +00:00
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
if( pin && aSymbol )
|
|
|
|
*aSymbol = candidate;
|
2010-12-13 15:59:00 +00:00
|
|
|
|
|
|
|
return pin;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
SCH_SHEET_PIN* SCH_SCREEN::GetSheetPin( const VECTOR2I& aPosition ) const
|
2011-01-11 20:34:29 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
SCH_SHEET_PIN* sheetPin = nullptr;
|
2011-01-11 20:34:29 +00:00
|
|
|
|
2021-09-24 11:36:36 +00:00
|
|
|
for( SCH_ITEM* item : Items().Overlapping( SCH_SHEET_T, aPosition ) )
|
2011-01-11 20:34:29 +00:00
|
|
|
{
|
2021-11-23 21:18:04 +00:00
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
|
2011-01-11 20:34:29 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
sheetPin = sheet->GetPin( aPosition );
|
2011-01-11 20:34:29 +00:00
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
if( sheetPin )
|
2011-01-11 20:34:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-03-30 19:26:05 +00:00
|
|
|
return sheetPin;
|
2011-01-11 20:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
size_t SCH_SCREEN::CountConnectedItems( const VECTOR2I& aPos, bool aTestJunctions ) const
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
size_t count = 0;
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2021-09-24 11:36:36 +00:00
|
|
|
for( const SCH_ITEM* item : Items().Overlapping( aPos ) )
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
if( ( item->Type() != SCH_JUNCTION_T || aTestJunctions ) && item->IsConnected( aPos ) )
|
2010-12-13 15:59:00 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-13 22:37:42 +00:00
|
|
|
void SCH_SCREEN::ClearAnnotation( SCH_SHEET_PATH* aSheetPath, bool aResetPrefix )
|
2010-12-31 19:47:39 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
for( SCH_ITEM* item : Items().OfType( SCH_SYMBOL_T ) )
|
2010-12-31 19:47:39 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2022-04-13 22:37:42 +00:00
|
|
|
symbol->ClearAnnotation( aSheetPath, aResetPrefix );
|
2010-12-31 19:47:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-03 10:11:39 +00:00
|
|
|
void SCH_SCREEN::EnsureAlternateReferencesExist()
|
|
|
|
{
|
2020-02-04 22:37:14 +00:00
|
|
|
if( GetClientSheetPaths().size() <= 1 ) // No need for alternate reference
|
2018-09-03 10:11:39 +00:00
|
|
|
return;
|
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
for( SCH_ITEM* item : Items().OfType( SCH_SYMBOL_T ) )
|
2018-09-03 10:11:39 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
2018-09-03 10:11:39 +00:00
|
|
|
|
|
|
|
// Add (when not existing) all sheet path entries
|
2020-09-06 10:26:39 +00:00
|
|
|
for( const SCH_SHEET_PATH& sheet : GetClientSheetPaths() )
|
2020-11-15 17:03:27 +00:00
|
|
|
symbol->AddSheetPathReferenceEntryIfMissing( sheet.Path() );
|
2018-09-03 10:11:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
void SCH_SCREEN::GetHierarchicalItems( std::vector<SCH_ITEM*>* aItems ) const
|
2010-12-31 19:47:39 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
for( SCH_ITEM* item : Items() )
|
2010-12-31 19:47:39 +00:00
|
|
|
{
|
2022-08-20 09:27:35 +00:00
|
|
|
if( item->IsType( { SCH_SYMBOL_T, SCH_SHEET_T, SCH_LABEL_LOCATE_ANY_T } ) )
|
2020-05-03 14:52:31 +00:00
|
|
|
aItems->push_back( item );
|
2010-12-31 19:47:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
void SCH_SCREEN::GetSheets( std::vector<SCH_ITEM*>* aItems ) const
|
2020-05-03 14:52:31 +00:00
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : Items().OfType( SCH_SHEET_T ) )
|
|
|
|
aItems->push_back( item );
|
|
|
|
|
|
|
|
std::sort( aItems->begin(), aItems->end(),
|
|
|
|
[]( EDA_ITEM* a, EDA_ITEM* b ) -> bool
|
|
|
|
{
|
2020-11-28 23:26:51 +00:00
|
|
|
if( a->GetPosition().x == b->GetPosition().x )
|
2021-08-20 15:31:01 +00:00
|
|
|
{
|
|
|
|
// Ensure deterministic sort
|
|
|
|
if( a->GetPosition().y == b->GetPosition().y )
|
|
|
|
return a->m_Uuid < b->m_Uuid;
|
|
|
|
|
2020-11-28 23:26:51 +00:00
|
|
|
return a->GetPosition().y < b->GetPosition().y;
|
2021-08-20 15:31:01 +00:00
|
|
|
}
|
2020-11-28 23:26:51 +00:00
|
|
|
else
|
2022-08-20 09:27:35 +00:00
|
|
|
{
|
2020-05-03 14:52:31 +00:00
|
|
|
return a->GetPosition().x < b->GetPosition().x;
|
2022-08-20 09:27:35 +00:00
|
|
|
}
|
2020-05-03 14:52:31 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-06 21:23:16 +00:00
|
|
|
void SCH_SCREEN::TestDanglingEnds( const SCH_SHEET_PATH* aPath,
|
2021-03-06 09:27:41 +00:00
|
|
|
std::function<void( SCH_ITEM* )>* aChangedHandler ) const
|
2011-01-21 19:30:59 +00:00
|
|
|
{
|
2023-08-30 21:21:58 +00:00
|
|
|
PROF_TIMER timer( __FUNCTION__ );
|
|
|
|
|
2024-02-12 08:01:45 +00:00
|
|
|
std::vector<DANGLING_END_ITEM> endPointsByPos;
|
|
|
|
std::vector<DANGLING_END_ITEM> endPointsByType;
|
2011-01-21 19:30:59 +00:00
|
|
|
|
2024-02-12 08:01:45 +00:00
|
|
|
auto get_ends =
|
2023-07-08 11:54:42 +00:00
|
|
|
[&]( SCH_ITEM* item )
|
|
|
|
{
|
|
|
|
if( item->IsConnectable() )
|
2024-02-12 08:01:45 +00:00
|
|
|
item->GetEndPoints( endPointsByType );
|
2023-08-30 21:21:58 +00:00
|
|
|
};
|
2024-02-12 08:01:45 +00:00
|
|
|
|
2023-08-30 21:21:58 +00:00
|
|
|
auto update_state =
|
|
|
|
[&]( SCH_ITEM* item )
|
|
|
|
{
|
2024-02-12 08:01:45 +00:00
|
|
|
if( item->UpdateDanglingState( endPointsByType, endPointsByPos, aPath ) )
|
2023-07-08 11:54:42 +00:00
|
|
|
{
|
2023-08-30 21:21:58 +00:00
|
|
|
if( aChangedHandler )
|
2024-02-12 08:01:45 +00:00
|
|
|
( *aChangedHandler )( item );
|
2023-07-08 11:54:42 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : Items() )
|
|
|
|
{
|
2024-02-12 08:01:45 +00:00
|
|
|
get_ends( item );
|
|
|
|
item->RunOnChildren( get_ends );
|
2023-08-30 21:21:58 +00:00
|
|
|
}
|
|
|
|
|
2024-02-12 08:01:45 +00:00
|
|
|
PROF_TIMER sortTimer( "SCH_SCREEN::TestDanglingEnds pre-sort" );
|
|
|
|
endPointsByPos = endPointsByType;
|
|
|
|
DANGLING_END_ITEM_HELPER::sort_dangling_end_items( endPointsByType, endPointsByPos );
|
|
|
|
sortTimer.Stop();
|
|
|
|
|
|
|
|
if( wxLog::IsAllowedTraceMask( DanglingProfileMask ) )
|
|
|
|
sortTimer.Show();
|
|
|
|
|
2023-08-30 21:21:58 +00:00
|
|
|
for( SCH_ITEM* item : Items() )
|
|
|
|
{
|
|
|
|
update_state( item );
|
|
|
|
item->RunOnChildren( update_state );
|
2011-01-21 19:30:59 +00:00
|
|
|
}
|
2024-02-12 08:01:45 +00:00
|
|
|
|
2023-08-30 21:21:58 +00:00
|
|
|
if( wxLog::IsAllowedTraceMask( DanglingProfileMask ) )
|
|
|
|
timer.Show();
|
2011-01-21 19:30:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 06:04:08 +00:00
|
|
|
SCH_LINE* SCH_SCREEN::GetLine( const VECTOR2I& aPosition, int aAccuracy, int aLayer,
|
2021-03-06 09:27:41 +00:00
|
|
|
SCH_LINE_TEST_T aSearchType ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2020-04-19 16:04:14 +00:00
|
|
|
// an accuracy of 0 had problems with rounding errors; use at least 1
|
|
|
|
aAccuracy = std::max( aAccuracy, 1 );
|
|
|
|
|
2021-09-24 11:36:36 +00:00
|
|
|
for( SCH_ITEM* item : Items().Overlapping( aPosition, aAccuracy ) )
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
|
|
|
if( item->Type() != SCH_LINE_T )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( item->GetLayer() != aLayer )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !item->HitTest( aPosition, aAccuracy ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch( aSearchType )
|
|
|
|
{
|
|
|
|
case ENTIRE_LENGTH_T:
|
|
|
|
return (SCH_LINE*) item;
|
|
|
|
|
|
|
|
case EXCLUDE_END_POINTS_T:
|
|
|
|
if( !( (SCH_LINE*) item )->IsEndPoint( aPosition ) )
|
|
|
|
return (SCH_LINE*) item;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case END_POINTS_ONLY_T:
|
|
|
|
if( ( (SCH_LINE*) item )->IsEndPoint( aPosition ) )
|
|
|
|
return (SCH_LINE*) item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
return nullptr;
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-15 19:54:29 +00:00
|
|
|
std::vector<SCH_LINE*> SCH_SCREEN::GetBusesAndWires( const VECTOR2I& aPosition,
|
|
|
|
bool aIgnoreEndpoints ) const
|
|
|
|
{
|
|
|
|
std::vector<SCH_LINE*> retVal;
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : Items().Overlapping( SCH_LINE_T, aPosition ) )
|
|
|
|
{
|
|
|
|
if( item->IsType( { SCH_ITEM_LOCATE_WIRE_T, SCH_ITEM_LOCATE_BUS_T } ) )
|
|
|
|
{
|
|
|
|
SCH_LINE* wire = static_cast<SCH_LINE*>( item );
|
|
|
|
|
|
|
|
if( aIgnoreEndpoints && wire->IsEndPoint( aPosition ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( IsPointOnSegment( wire->GetStartPoint(), wire->GetEndPoint(), aPosition ) )
|
|
|
|
retVal.push_back( wire );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-18 18:40:25 +00:00
|
|
|
std::vector<VECTOR2I> SCH_SCREEN::GetConnections() const
|
|
|
|
{
|
|
|
|
std::vector<VECTOR2I> retval;
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : Items() )
|
|
|
|
{
|
|
|
|
// Avoid items that are changing
|
|
|
|
if( !( item->GetEditFlags() & ( IS_MOVING | IS_DELETED ) ) )
|
|
|
|
{
|
|
|
|
std::vector<VECTOR2I> pts = item->GetConnectionPoints();
|
|
|
|
retval.insert( retval.end(), pts.begin(), pts.end() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We always have some overlapping connection points. Drop duplicates here
|
|
|
|
std::sort( retval.begin(), retval.end(),
|
|
|
|
[]( const VECTOR2I& a, const VECTOR2I& b ) -> bool
|
|
|
|
{
|
|
|
|
return a.x < b.x || ( a.x == b.x && a.y < b.y );
|
|
|
|
} );
|
|
|
|
retval.erase( std::unique( retval.begin(), retval.end() ), retval.end() );
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-18 19:52:31 +00:00
|
|
|
std::vector<VECTOR2I> SCH_SCREEN::GetNeededJunctions( const std::deque<EDA_ITEM*>& aItems ) const
|
|
|
|
{
|
|
|
|
std::vector<VECTOR2I> pts;
|
|
|
|
std::vector<VECTOR2I> connections = GetConnections();
|
|
|
|
|
|
|
|
for( const EDA_ITEM* edaItem : aItems )
|
|
|
|
{
|
|
|
|
const SCH_ITEM* item = dynamic_cast<const SCH_ITEM*>( edaItem );
|
|
|
|
|
|
|
|
if( !item || !item->IsConnectable() )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
std::vector<VECTOR2I> new_pts = item->GetConnectionPoints();
|
|
|
|
pts.insert( pts.end(), new_pts.begin(), new_pts.end() );
|
|
|
|
|
|
|
|
// If the item is a line, we also add any connection points from the rest of the schematic
|
|
|
|
// that terminate on the line after it is moved.
|
|
|
|
if( item->Type() == SCH_LINE_T )
|
|
|
|
{
|
|
|
|
SCH_LINE* line = (SCH_LINE*) item;
|
|
|
|
|
|
|
|
for( const VECTOR2I& pt : connections )
|
|
|
|
{
|
|
|
|
if( IsPointOnSegment( line->GetStartPoint(), line->GetEndPoint(), pt ) )
|
|
|
|
pts.push_back( pt );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We always have some overlapping connection points. Drop duplicates here
|
|
|
|
std::sort( pts.begin(), pts.end(),
|
|
|
|
[]( const VECTOR2I& a, const VECTOR2I& b ) -> bool
|
|
|
|
{
|
|
|
|
return a.x < b.x || ( a.x == b.x && a.y < b.y );
|
|
|
|
} );
|
|
|
|
|
|
|
|
pts.erase( unique( pts.begin(), pts.end() ), pts.end() );
|
|
|
|
|
|
|
|
// We only want the needed junction points, remove all the others
|
|
|
|
pts.erase( std::remove_if( pts.begin(), pts.end(),
|
|
|
|
[this]( const VECTOR2I& a ) -> bool
|
|
|
|
{
|
|
|
|
return !IsExplicitJunctionNeeded( a );
|
|
|
|
} ),
|
|
|
|
pts.end() );
|
|
|
|
|
|
|
|
return pts;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-25 22:33:37 +00:00
|
|
|
SCH_LABEL_BASE* SCH_SCREEN::GetLabel( const VECTOR2I& aPosition, int aAccuracy ) const
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
for( SCH_ITEM* item : Items().Overlapping( aPosition, aAccuracy ) )
|
2011-03-25 19:16:05 +00:00
|
|
|
{
|
|
|
|
switch( item->Type() )
|
|
|
|
{
|
|
|
|
case SCH_LABEL_T:
|
|
|
|
case SCH_GLOBAL_LABEL_T:
|
2019-04-15 23:56:41 +00:00
|
|
|
case SCH_HIER_LABEL_T:
|
2022-01-24 13:40:39 +00:00
|
|
|
case SCH_DIRECTIVE_LABEL_T:
|
2011-03-25 19:16:05 +00:00
|
|
|
if( item->HitTest( aPosition, aAccuracy ) )
|
2022-01-25 22:33:37 +00:00
|
|
|
return static_cast<SCH_LABEL_BASE*>( item );
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2020-04-24 23:44:09 +00:00
|
|
|
break;
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
return nullptr;
|
2011-03-25 19:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-06-10 18:51:46 +00:00
|
|
|
void SCH_SCREEN::AddLibSymbol( LIB_SYMBOL* aLibSymbol )
|
2020-04-16 16:43:50 +00:00
|
|
|
{
|
|
|
|
wxCHECK( aLibSymbol, /* void */ );
|
|
|
|
|
|
|
|
wxString libSymbolName = aLibSymbol->GetLibId().Format().wx_str();
|
|
|
|
|
|
|
|
auto it = m_libSymbols.find( libSymbolName );
|
|
|
|
|
|
|
|
if( it != m_libSymbols.end() )
|
|
|
|
{
|
|
|
|
delete it->second;
|
|
|
|
m_libSymbols.erase( it );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_libSymbols[libSymbolName] = aLibSymbol;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
void SCH_SCREEN::AddBusAlias( std::shared_ptr<BUS_ALIAS> aAlias )
|
|
|
|
{
|
|
|
|
m_aliases.insert( aAlias );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-17 15:31:49 +00:00
|
|
|
void SCH_SCREEN::SetLegacySymbolInstanceData()
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : Items().OfType( SCH_SYMBOL_T ) )
|
|
|
|
{
|
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
|
|
|
|
|
|
|
// Add missing value and footprint instance data for legacy schematics.
|
2023-12-28 23:25:47 +00:00
|
|
|
for( const SCH_SYMBOL_INSTANCE& instance : symbol->GetInstances() )
|
2022-08-17 15:31:49 +00:00
|
|
|
{
|
|
|
|
symbol->AddHierarchicalReference( instance.m_Path, instance.m_Reference,
|
2022-11-25 14:25:39 +00:00
|
|
|
instance.m_Unit );
|
2022-08-17 15:31:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-20 17:55:02 +00:00
|
|
|
void SCH_SCREEN::FixLegacyPowerSymbolMismatches()
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : Items().OfType( SCH_SYMBOL_T ) )
|
|
|
|
{
|
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
|
|
|
|
|
|
|
// Fix pre-8.0 legacy power symbols with invisible pins
|
|
|
|
// that have mismatched pin names and value fields
|
|
|
|
if( symbol->GetLibSymbolRef()
|
|
|
|
&& symbol->GetLibSymbolRef()->IsPower()
|
|
|
|
&& symbol->GetAllLibPins().size() > 0
|
|
|
|
&& symbol->GetAllLibPins()[0]->IsGlobalPower()
|
|
|
|
&& !symbol->GetAllLibPins()[0]->IsVisible() )
|
|
|
|
{
|
|
|
|
symbol->SetValueFieldText( symbol->GetAllLibPins()[0]->GetName() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-02 20:53:57 +00:00
|
|
|
size_t SCH_SCREEN::getLibSymbolNameMatches( const SCH_SYMBOL& aSymbol,
|
|
|
|
std::vector<wxString>& aMatches )
|
|
|
|
{
|
|
|
|
wxString searchName = aSymbol.GetLibId().GetUniStringLibId();
|
|
|
|
|
|
|
|
if( m_libSymbols.find( searchName ) != m_libSymbols.end() )
|
|
|
|
aMatches.emplace_back( searchName );
|
|
|
|
|
|
|
|
searchName = aSymbol.GetLibId().GetUniStringLibItemName() + wxS( "_" );
|
|
|
|
|
2023-02-03 07:22:34 +00:00
|
|
|
long tmp;
|
2023-02-02 20:53:57 +00:00
|
|
|
wxString suffix;
|
|
|
|
|
2023-03-15 19:09:04 +00:00
|
|
|
for( auto& pair : m_libSymbols )
|
2023-02-02 20:53:57 +00:00
|
|
|
{
|
2023-02-03 07:22:34 +00:00
|
|
|
if( pair.first.StartsWith( searchName, &suffix ) && suffix.ToLong( &tmp ) )
|
2023-02-02 20:53:57 +00:00
|
|
|
aMatches.emplace_back( pair.first );
|
|
|
|
}
|
|
|
|
|
|
|
|
return aMatches.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-01 19:18:47 +00:00
|
|
|
void SCH_SCREEN::PruneOrphanedSymbolInstances( const wxString& aProjectName,
|
|
|
|
const SCH_SHEET_LIST& aValidSheetPaths )
|
|
|
|
{
|
2023-12-03 12:47:57 +00:00
|
|
|
// The project name cannot be empty. Projects older than 7.0 did not save project names
|
|
|
|
// when saving instance data. Running this algorithm with an empty project name would
|
|
|
|
// clobber all instance data for projects other than the current one when a schematic
|
2024-01-11 20:41:58 +00:00
|
|
|
// file is shared across multiple projects. Because running the schematic editor in
|
|
|
|
// stand alone mode can result in an empty project name, do not assert here.
|
|
|
|
if( aProjectName.IsEmpty() )
|
|
|
|
return;
|
2023-12-01 19:18:47 +00:00
|
|
|
|
|
|
|
for( SCH_ITEM* item : Items().OfType( SCH_SYMBOL_T ) )
|
|
|
|
{
|
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
|
|
|
|
|
|
|
wxCHECK2( symbol, continue );
|
|
|
|
|
2023-12-03 12:47:57 +00:00
|
|
|
std::set<KIID_PATH> pathsToPrune;
|
2023-12-28 23:25:47 +00:00
|
|
|
const std::vector<SCH_SYMBOL_INSTANCE> instances = symbol->GetInstances();
|
2023-12-01 19:18:47 +00:00
|
|
|
|
|
|
|
for( const SCH_SYMBOL_INSTANCE& instance : instances )
|
|
|
|
{
|
2023-12-03 12:47:57 +00:00
|
|
|
// Ignore instance paths from other projects.
|
2023-12-01 19:18:47 +00:00
|
|
|
if( aProjectName != instance.m_ProjectName )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
std::optional<SCH_SHEET_PATH> pathFound =
|
|
|
|
aValidSheetPaths.GetSheetPathByKIIDPath( instance.m_Path );
|
|
|
|
|
2023-12-28 17:18:54 +00:00
|
|
|
// Check for paths that do not exist in the current project and paths that do
|
2023-12-03 12:47:57 +00:00
|
|
|
// not contain the current symbol.
|
2023-12-01 19:18:47 +00:00
|
|
|
if( !pathFound )
|
2023-12-03 12:47:57 +00:00
|
|
|
pathsToPrune.emplace( instance.m_Path );
|
|
|
|
else if( pathFound.value().LastScreen() != this )
|
|
|
|
pathsToPrune.emplace( pathFound.value().Path() );
|
2023-12-01 19:18:47 +00:00
|
|
|
}
|
|
|
|
|
2023-12-03 12:47:57 +00:00
|
|
|
for( const KIID_PATH& sheetPath : pathsToPrune )
|
2023-12-01 19:18:47 +00:00
|
|
|
{
|
|
|
|
wxLogTrace( traceSchSheetPaths, wxS( "Pruning project '%s' symbol instance %s." ),
|
2023-12-03 12:47:57 +00:00
|
|
|
aProjectName, sheetPath.AsString() );
|
2023-12-01 19:18:47 +00:00
|
|
|
symbol->RemoveInstance( sheetPath );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-28 17:18:54 +00:00
|
|
|
void SCH_SCREEN::PruneOrphanedSheetInstances( const wxString& aProjectName,
|
|
|
|
const SCH_SHEET_LIST& aValidSheetPaths )
|
|
|
|
{
|
|
|
|
// The project name cannot be empty. Projects older than 7.0 did not save project names
|
|
|
|
// when saving instance data. Running this algorithm with an empty project name would
|
|
|
|
// clobber all instance data for projects other than the current one when a schematic
|
2024-01-11 20:41:58 +00:00
|
|
|
// file is shared across multiple projects. Because running the schematic editor in
|
|
|
|
// stand alone mode can result in an empty project name, do not assert here.
|
|
|
|
if( aProjectName.IsEmpty() )
|
|
|
|
return;
|
2023-12-28 17:18:54 +00:00
|
|
|
|
|
|
|
for( SCH_ITEM* item : Items().OfType( SCH_SHEET_T ) )
|
|
|
|
{
|
|
|
|
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
|
|
|
|
|
|
|
|
wxCHECK2( sheet, continue );
|
|
|
|
|
|
|
|
std::set<KIID_PATH> pathsToPrune;
|
|
|
|
const std::vector<SCH_SHEET_INSTANCE> instances = sheet->GetInstances();
|
|
|
|
|
|
|
|
for( const SCH_SHEET_INSTANCE& instance : instances )
|
|
|
|
{
|
|
|
|
// Ignore instance paths from other projects.
|
|
|
|
if( aProjectName != instance.m_ProjectName )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
std::optional<SCH_SHEET_PATH> pathFound =
|
|
|
|
aValidSheetPaths.GetSheetPathByKIIDPath( instance.m_Path );
|
|
|
|
|
|
|
|
// Check for paths that do not exist in the current project and paths that do
|
|
|
|
// not contain the current symbol.
|
|
|
|
if( !pathFound )
|
|
|
|
pathsToPrune.emplace( instance.m_Path );
|
|
|
|
else if( pathFound.value().LastScreen() != this )
|
|
|
|
pathsToPrune.emplace( pathFound.value().Path() );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( const KIID_PATH& sheetPath : pathsToPrune )
|
|
|
|
{
|
|
|
|
wxLogTrace( traceSchSheetPaths, wxS( "Pruning project '%s' sheet instance %s." ),
|
|
|
|
aProjectName, sheetPath.AsString() );
|
|
|
|
sheet->RemoveInstance( sheetPath );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-17 17:00:04 +00:00
|
|
|
#if defined(DEBUG)
|
|
|
|
void SCH_SCREEN::Show( int nestLevel, std::ostream& os ) const
|
|
|
|
{
|
|
|
|
// for now, make it look like XML, expand on this later.
|
|
|
|
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << ">\n";
|
2020-03-16 11:05:01 +00:00
|
|
|
|
|
|
|
for( const SCH_ITEM* item : Items() )
|
2019-06-25 23:39:58 +00:00
|
|
|
item->Show( nestLevel + 1, os );
|
2017-11-17 17:00:04 +00:00
|
|
|
|
|
|
|
NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
SCH_SCREENS::SCH_SCREENS( SCH_SHEET* aSheet )
|
2008-04-12 18:39:20 +00:00
|
|
|
{
|
2010-10-26 20:25:48 +00:00
|
|
|
m_index = 0;
|
2020-05-13 02:00:37 +00:00
|
|
|
buildScreenList( aSheet );
|
2008-04-12 18:39:20 +00:00
|
|
|
}
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
SCH_SCREENS::~SCH_SCREENS()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_SCREEN* SCH_SCREENS::GetFirst()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-10-26 20:25:48 +00:00
|
|
|
m_index = 0;
|
|
|
|
|
|
|
|
if( m_screens.size() > 0 )
|
|
|
|
return m_screens[0];
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
return nullptr;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2008-02-26 19:19:54 +00:00
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
SCH_SCREEN* SCH_SCREENS::GetNext()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-10-26 20:25:48 +00:00
|
|
|
if( m_index < m_screens.size() )
|
|
|
|
m_index++;
|
|
|
|
|
|
|
|
return GetScreen( m_index );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2014-04-30 19:16:22 +00:00
|
|
|
SCH_SCREEN* SCH_SCREENS::GetScreen( unsigned int aIndex ) const
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-10-26 20:25:48 +00:00
|
|
|
if( aIndex < m_screens.size() )
|
|
|
|
return m_screens[ aIndex ];
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
return nullptr;
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
2008-02-26 19:19:54 +00:00
|
|
|
|
|
|
|
|
2020-04-26 20:53:29 +00:00
|
|
|
SCH_SHEET* SCH_SCREENS::GetSheet( unsigned int aIndex ) const
|
|
|
|
{
|
|
|
|
if( aIndex < m_sheets.size() )
|
|
|
|
return m_sheets[ aIndex ];
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
return nullptr;
|
2020-04-26 20:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SCREENS::addScreenToList( SCH_SCREEN* aScreen, SCH_SHEET* aSheet )
|
2008-02-12 21:12:46 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
if( aScreen == nullptr )
|
2008-02-26 19:19:54 +00:00
|
|
|
return;
|
2010-10-26 20:25:48 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( const SCH_SCREEN* screen : m_screens )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
if( screen == aScreen )
|
2008-02-26 19:19:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
m_screens.push_back( aScreen );
|
2020-04-26 20:53:29 +00:00
|
|
|
m_sheets.push_back( aSheet );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2008-02-26 19:19:54 +00:00
|
|
|
|
|
|
|
|
2017-11-17 17:00:04 +00:00
|
|
|
void SCH_SCREENS::buildScreenList( SCH_SHEET* aSheet )
|
2008-02-12 21:12:46 +00:00
|
|
|
{
|
2017-11-17 17:00:04 +00:00
|
|
|
if( aSheet && aSheet->Type() == SCH_SHEET_T )
|
2008-02-26 19:19:54 +00:00
|
|
|
{
|
2017-11-17 17:00:04 +00:00
|
|
|
SCH_SCREEN* screen = aSheet->GetScreen();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2021-09-20 16:28:33 +00:00
|
|
|
wxCHECK_RET( screen, "No screen for aSheet" );
|
|
|
|
|
2020-04-26 20:53:29 +00:00
|
|
|
addScreenToList( screen, aSheet );
|
2014-08-18 16:39:51 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( SCH_ITEM* item : screen->Items().OfType( SCH_SHEET_T ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
buildScreenList( static_cast<SCH_SHEET*>( item ) );
|
2008-02-26 19:19:54 +00:00
|
|
|
}
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
2010-12-31 19:47:39 +00:00
|
|
|
|
|
|
|
|
2018-09-03 10:11:39 +00:00
|
|
|
void SCH_SCREENS::ClearAnnotationOfNewSheetPaths( SCH_SHEET_LIST& aInitialSheetPathList )
|
|
|
|
{
|
2020-05-19 02:58:28 +00:00
|
|
|
SCH_SCREEN* first = GetFirst();
|
|
|
|
|
|
|
|
if( !first )
|
|
|
|
return;
|
|
|
|
|
|
|
|
SCHEMATIC* sch = first->Schematic();
|
2020-05-13 02:00:37 +00:00
|
|
|
|
|
|
|
wxCHECK_RET( sch, "Null schematic in SCH_SCREENS::ClearAnnotationOfNewSheetPaths" );
|
|
|
|
|
2020-11-15 17:03:27 +00:00
|
|
|
// Clear the annotation for symbols inside new sheetpaths not already in aInitialSheetList
|
2020-05-13 02:00:37 +00:00
|
|
|
SCH_SCREENS screensList( sch->Root() ); // The list of screens, shared by sheet paths
|
2018-09-03 10:11:39 +00:00
|
|
|
screensList.BuildClientSheetPathList(); // build the shared by sheet paths, by screen
|
|
|
|
|
|
|
|
// Search for new sheet paths, not existing in aInitialSheetPathList
|
|
|
|
// and existing in sheetpathList
|
2020-05-13 02:00:37 +00:00
|
|
|
for( SCH_SHEET_PATH& sheetpath : sch->GetSheets() )
|
2018-09-03 10:11:39 +00:00
|
|
|
{
|
|
|
|
bool path_exists = false;
|
|
|
|
|
|
|
|
for( const SCH_SHEET_PATH& existing_sheetpath: aInitialSheetPathList )
|
|
|
|
{
|
|
|
|
if( existing_sheetpath.Path() == sheetpath.Path() )
|
|
|
|
{
|
|
|
|
path_exists = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !path_exists )
|
|
|
|
{
|
|
|
|
// A new sheet path is found: clear the annotation corresponding to this new path:
|
|
|
|
SCH_SCREEN* curr_screen = sheetpath.LastScreen();
|
2018-09-04 16:46:03 +00:00
|
|
|
|
2018-09-03 10:11:39 +00:00
|
|
|
// Clear annotation and create the AR for this path, if not exists,
|
|
|
|
// when the screen is shared by sheet paths.
|
|
|
|
// Otherwise ClearAnnotation do nothing, because the F1 field is used as
|
|
|
|
// reference default value and takes the latest displayed value
|
|
|
|
curr_screen->EnsureAlternateReferencesExist();
|
2022-04-13 22:37:42 +00:00
|
|
|
curr_screen->ClearAnnotation( &sheetpath, false );
|
2018-09-03 10:11:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-31 19:47:39 +00:00
|
|
|
int SCH_SCREENS::ReplaceDuplicateTimeStamps()
|
|
|
|
{
|
2020-05-03 14:52:31 +00:00
|
|
|
std::vector<SCH_ITEM*> items;
|
2019-10-29 07:49:15 +00:00
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
auto timestamp_cmp = []( const EDA_ITEM* a, const EDA_ITEM* b ) -> bool
|
2020-02-20 12:11:04 +00:00
|
|
|
{
|
|
|
|
return a->m_Uuid < b->m_Uuid;
|
|
|
|
};
|
2019-10-29 07:49:15 +00:00
|
|
|
|
|
|
|
std::set<EDA_ITEM*, decltype( timestamp_cmp )> unique_stamps( timestamp_cmp );
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
for( SCH_SCREEN* screen : m_screens )
|
2020-05-03 14:52:31 +00:00
|
|
|
screen->GetHierarchicalItems( &items );
|
2010-12-31 19:47:39 +00:00
|
|
|
|
|
|
|
if( items.size() < 2 )
|
|
|
|
return 0;
|
|
|
|
|
2020-02-20 12:11:04 +00:00
|
|
|
for( EDA_ITEM* item : items )
|
2010-12-31 19:47:39 +00:00
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
if( !unique_stamps.insert( item ).second )
|
2010-12-31 19:47:39 +00:00
|
|
|
{
|
2020-02-20 12:11:04 +00:00
|
|
|
// Reset to fully random UUID. This may lose reference, but better to be
|
|
|
|
// deterministic about it rather than to have duplicate UUIDs with random
|
|
|
|
// side-effects.
|
2020-02-21 22:20:42 +00:00
|
|
|
const_cast<KIID&>( item->m_Uuid ) = KIID();
|
2020-02-20 12:11:04 +00:00
|
|
|
count++;
|
2022-10-01 12:44:21 +00:00
|
|
|
|
|
|
|
// @todo If the item is a sheet, we need to decend the heirarchy from the sheet
|
|
|
|
// and repace all instances of the changed UUID in sheet paths. Otherwise,
|
|
|
|
// all instance paths with the sheet's UUID will get clobbered.
|
2010-12-31 19:47:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-07 19:04:10 +00:00
|
|
|
void SCH_SCREENS::ClearEditFlags()
|
|
|
|
{
|
|
|
|
for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
|
|
|
|
{
|
|
|
|
for( SCH_ITEM* item : screen->Items() )
|
|
|
|
item->ClearEditFlags();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
void SCH_SCREENS::DeleteMarker( SCH_MARKER* aMarker )
|
2011-03-10 19:36:30 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
|
2011-03-10 19:36:30 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
for( SCH_ITEM* item : screen->Items().OfType( SCH_MARKER_T ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
if( item == aMarker )
|
|
|
|
{
|
|
|
|
screen->DeleteItem( item );
|
|
|
|
return;
|
|
|
|
}
|
2011-03-10 19:36:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-07 14:41:30 +00:00
|
|
|
|
|
|
|
|
2024-01-29 11:51:06 +00:00
|
|
|
void SCH_SCREENS::DeleteMarkers( enum MARKER_BASE::MARKER_T aMarkerType, int aErrorCode,
|
2020-08-02 21:45:06 +00:00
|
|
|
bool aIncludeExclusions )
|
2011-10-07 14:41:30 +00:00
|
|
|
{
|
2015-07-29 12:18:53 +00:00
|
|
|
for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
|
2011-10-07 14:41:30 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
std::vector<SCH_ITEM*> markers;
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( SCH_ITEM* item : screen->Items().OfType( SCH_MARKER_T ) )
|
|
|
|
{
|
|
|
|
SCH_MARKER* marker = static_cast<SCH_MARKER*>( item );
|
2020-08-11 13:33:16 +00:00
|
|
|
std::shared_ptr<RC_ITEM>rcItem = marker->GetRCItem();
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2020-08-02 21:45:06 +00:00
|
|
|
if( marker->GetMarkerType() == aMarkerType
|
|
|
|
&& ( aErrorCode == ERCE_UNSPECIFIED || rcItem->GetErrorCode() == aErrorCode )
|
|
|
|
&& ( !marker->IsExcluded() || aIncludeExclusions ) )
|
2020-03-16 11:05:01 +00:00
|
|
|
{
|
|
|
|
markers.push_back( item );
|
|
|
|
}
|
2011-10-07 14:41:30 +00:00
|
|
|
}
|
2020-03-16 11:05:01 +00:00
|
|
|
|
|
|
|
for( SCH_ITEM* marker : markers )
|
|
|
|
screen->DeleteItem( marker );
|
2011-10-07 14:41:30 +00:00
|
|
|
}
|
2020-03-16 11:05:01 +00:00
|
|
|
}
|
2011-10-07 14:41:30 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
|
2024-01-29 11:51:06 +00:00
|
|
|
void SCH_SCREENS::DeleteAllMarkers( enum MARKER_BASE::MARKER_T aMarkerType,
|
2020-08-02 21:45:06 +00:00
|
|
|
bool aIncludeExclusions )
|
2020-03-16 11:05:01 +00:00
|
|
|
{
|
2020-08-02 21:45:06 +00:00
|
|
|
DeleteMarkers( aMarkerType, ERCE_UNSPECIFIED, aIncludeExclusions );
|
2011-10-07 14:41:30 +00:00
|
|
|
}
|
2011-12-22 21:57:50 +00:00
|
|
|
|
2017-03-04 19:49:55 +00:00
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
void SCH_SCREENS::UpdateSymbolLinks( REPORTER* aReporter )
|
2017-03-04 19:49:55 +00:00
|
|
|
{
|
|
|
|
for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
|
2020-04-16 16:43:50 +00:00
|
|
|
screen->UpdateSymbolLinks( aReporter );
|
2019-12-11 23:53:10 +00:00
|
|
|
|
2020-05-19 02:58:28 +00:00
|
|
|
SCH_SCREEN* first = GetFirst();
|
|
|
|
|
|
|
|
if( !first )
|
|
|
|
return;
|
|
|
|
|
|
|
|
SCHEMATIC* sch = first->Schematic();
|
2020-05-13 02:00:37 +00:00
|
|
|
|
|
|
|
wxCHECK_RET( sch, "Null schematic in SCH_SCREENS::UpdateSymbolLinks" );
|
|
|
|
|
|
|
|
SCH_SHEET_LIST sheets = sch->GetSheets();
|
2019-12-11 23:53:10 +00:00
|
|
|
|
|
|
|
// All of the library symbols have been replaced with copies so the connection graph
|
2020-12-06 21:23:16 +00:00
|
|
|
// pointers are stale.
|
2020-05-13 02:00:37 +00:00
|
|
|
if( sch->ConnectionGraph() )
|
|
|
|
sch->ConnectionGraph()->Recalculate( sheets, true );
|
2017-03-04 19:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-05 22:31:31 +00:00
|
|
|
bool SCH_SCREENS::HasNoFullyDefinedLibIds()
|
|
|
|
{
|
2021-09-20 16:28:33 +00:00
|
|
|
bool has_symbols = false;
|
2017-03-05 22:31:31 +00:00
|
|
|
|
2021-09-20 16:28:33 +00:00
|
|
|
for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
|
2017-03-05 22:31:31 +00:00
|
|
|
{
|
2021-07-07 18:00:00 +00:00
|
|
|
for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
|
2017-03-05 22:31:31 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
2021-09-20 16:28:33 +00:00
|
|
|
has_symbols = true;
|
2017-03-05 22:31:31 +00:00
|
|
|
|
|
|
|
if( !symbol->GetLibId().GetLibNickname().empty() )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-20 16:28:33 +00:00
|
|
|
// return true (i.e. has no fully defined symbol) only if at least one symbol is found
|
|
|
|
return has_symbols ? true : false;
|
2017-03-05 22:31:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-17 17:00:04 +00:00
|
|
|
size_t SCH_SCREENS::GetLibNicknames( wxArrayString& aLibNicknames )
|
2011-12-22 21:57:50 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
|
2011-12-22 21:57:50 +00:00
|
|
|
{
|
2021-11-23 21:18:04 +00:00
|
|
|
for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
|
2017-11-17 17:00:04 +00:00
|
|
|
{
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
|
|
|
const UTF8& nickname = symbol->GetLibId().GetLibNickname();
|
2017-11-17 17:00:04 +00:00
|
|
|
|
|
|
|
if( !nickname.empty() && ( aLibNicknames.Index( nickname ) == wxNOT_FOUND ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
aLibNicknames.Add( nickname );
|
2017-11-17 17:00:04 +00:00
|
|
|
}
|
2011-12-22 21:57:50 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 17:00:04 +00:00
|
|
|
return aLibNicknames.GetCount();
|
2011-12-22 21:57:50 +00:00
|
|
|
}
|
2017-11-17 17:00:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
int SCH_SCREENS::ChangeSymbolLibNickname( const wxString& aFrom, const wxString& aTo )
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen;
|
|
|
|
int cnt = 0;
|
|
|
|
|
|
|
|
for( screen = GetFirst(); screen; screen = GetNext() )
|
|
|
|
{
|
2021-11-23 21:18:04 +00:00
|
|
|
for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
|
2017-11-17 17:00:04 +00:00
|
|
|
{
|
2021-11-23 21:18:04 +00:00
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
2017-11-17 17:00:04 +00:00
|
|
|
|
|
|
|
if( symbol->GetLibId().GetLibNickname() != aFrom )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
LIB_ID id = symbol->GetLibId();
|
|
|
|
id.SetLibNickname( aTo );
|
|
|
|
symbol->SetLibId( id );
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cnt;
|
|
|
|
}
|
2018-09-03 10:11:39 +00:00
|
|
|
|
|
|
|
|
2019-07-19 15:39:29 +00:00
|
|
|
bool SCH_SCREENS::HasSchematic( const wxString& aSchematicFileName )
|
|
|
|
{
|
|
|
|
for( const SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
|
|
|
|
{
|
|
|
|
if( screen->GetFileName() == aSchematicFileName )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-03 10:11:39 +00:00
|
|
|
void SCH_SCREENS::BuildClientSheetPathList()
|
|
|
|
{
|
2020-05-19 02:58:28 +00:00
|
|
|
SCH_SCREEN* first = GetFirst();
|
|
|
|
|
|
|
|
if( !first )
|
|
|
|
return;
|
|
|
|
|
|
|
|
SCHEMATIC* sch = first->Schematic();
|
2020-05-13 02:00:37 +00:00
|
|
|
|
|
|
|
wxCHECK_RET( sch, "Null schematic in SCH_SCREENS::BuildClientSheetPathList" );
|
2018-09-03 10:11:39 +00:00
|
|
|
|
|
|
|
for( SCH_SCREEN* curr_screen = GetFirst(); curr_screen; curr_screen = GetNext() )
|
2020-02-04 22:37:14 +00:00
|
|
|
curr_screen->GetClientSheetPaths().clear();
|
2018-09-03 10:11:39 +00:00
|
|
|
|
2020-05-13 02:00:37 +00:00
|
|
|
for( SCH_SHEET_PATH& sheetpath : sch->GetSheets() )
|
2018-09-03 10:11:39 +00:00
|
|
|
{
|
|
|
|
SCH_SCREEN* used_screen = sheetpath.LastScreen();
|
|
|
|
|
2022-10-04 11:45:22 +00:00
|
|
|
// Search for the used_screen in list and add this unique sheet path:
|
2018-09-03 10:11:39 +00:00
|
|
|
for( SCH_SCREEN* curr_screen = GetFirst(); curr_screen; curr_screen = GetNext() )
|
|
|
|
{
|
|
|
|
if( used_screen == curr_screen )
|
|
|
|
{
|
2020-02-04 22:37:14 +00:00
|
|
|
curr_screen->GetClientSheetPaths().push_back( sheetpath );
|
2018-09-03 10:11:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-17 15:31:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCH_SCREENS::SetLegacySymbolInstanceData()
|
|
|
|
{
|
|
|
|
for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
|
|
|
|
screen->SetLegacySymbolInstanceData();
|
|
|
|
}
|
2022-12-06 14:00:11 +00:00
|
|
|
|
|
|
|
|
2023-02-20 17:55:02 +00:00
|
|
|
void SCH_SCREENS::FixLegacyPowerSymbolMismatches()
|
|
|
|
{
|
|
|
|
for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
|
|
|
|
screen->FixLegacyPowerSymbolMismatches();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-06 14:00:11 +00:00
|
|
|
void SCH_SCREEN::MigrateSimModels()
|
|
|
|
{
|
|
|
|
LOCALE_IO toggle;
|
|
|
|
|
|
|
|
// V6 schematics may specify model names in Value fields, which we don't do in V7.
|
|
|
|
// Migrate by adding an equivalent model for these symbols.
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : Items().OfType( SCH_SYMBOL_T ) )
|
|
|
|
{
|
|
|
|
SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
|
2022-12-14 13:00:25 +00:00
|
|
|
SIM_MODEL::MigrateSimModel<SCH_SYMBOL, SCH_FIELD>( *symbol, &Schematic()->Prj() );
|
2022-12-06 14:00:11 +00:00
|
|
|
}
|
|
|
|
}
|
2023-12-01 19:18:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCH_SCREENS::PruneOrphanedSymbolInstances( const wxString& aProjectName,
|
|
|
|
const SCH_SHEET_LIST& aValidSheetPaths )
|
|
|
|
{
|
2024-01-11 20:41:58 +00:00
|
|
|
if( aProjectName.IsEmpty() )
|
|
|
|
return;
|
2023-12-01 19:18:47 +00:00
|
|
|
|
|
|
|
for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
|
|
|
|
screen->PruneOrphanedSymbolInstances( aProjectName, aValidSheetPaths );
|
|
|
|
}
|
2023-12-28 17:18:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCH_SCREENS::PruneOrphanedSheetInstances( const wxString& aProjectName,
|
|
|
|
const SCH_SHEET_LIST& aValidSheetPaths )
|
|
|
|
{
|
2024-01-11 20:41:58 +00:00
|
|
|
if( aProjectName.IsEmpty() )
|
|
|
|
return;
|
2023-12-28 17:18:54 +00:00
|
|
|
|
|
|
|
for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
|
|
|
|
screen->PruneOrphanedSheetInstances( aProjectName, aValidSheetPaths );
|
|
|
|
}
|