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>
|
2020-01-23 14:05:12 +00:00
|
|
|
* Copyright (C) 1992-2020 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file sch_screen.cpp
|
|
|
|
* @brief Implementation of SCH_SCREEN and SCH_SCREENS classes.
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
#include <eda_rect.h>
|
2020-10-02 13:50:46 +00:00
|
|
|
//#include <gr_text.h>
|
2020-01-03 16:04:54 +00:00
|
|
|
#include <id.h>
|
2019-06-25 23:39:58 +00:00
|
|
|
#include <kicad_string.h>
|
2015-04-09 19:37:48 +00:00
|
|
|
#include <kiway.h>
|
2019-06-25 23:39:58 +00:00
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <plotter.h>
|
|
|
|
#include <project.h>
|
2020-04-16 16:43:50 +00:00
|
|
|
#include <reporter.h>
|
2018-08-03 12:18:26 +00:00
|
|
|
#include <sch_draw_panel.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
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_library.h>
|
2020-04-16 16:43:50 +00:00
|
|
|
#include <class_libentry.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>
|
|
|
|
#include <sch_component.h>
|
|
|
|
#include <sch_junction.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <sch_line.h>
|
|
|
|
#include <sch_marker.h>
|
|
|
|
#include <sch_sheet.h>
|
|
|
|
#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>
|
2010-11-10 15:30:12 +00:00
|
|
|
|
2019-04-06 01:14:15 +00:00
|
|
|
#include <thread>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <future>
|
|
|
|
|
2019-03-11 21:32:05 +00:00
|
|
|
// TODO(JE) Debugging only
|
|
|
|
#include <profile.h>
|
2020-08-10 11:40:58 +00:00
|
|
|
#include "sch_bus_entry.h"
|
2019-12-30 18:28:00 +00:00
|
|
|
|
2020-05-21 02:27:48 +00:00
|
|
|
SCH_SCREEN::SCH_SCREEN( EDA_ITEM* aParent ) :
|
|
|
|
BASE_SCREEN( aParent, SCH_SCREEN_T ),
|
2013-10-11 16:24:43 +00:00
|
|
|
m_paper( wxT( "A4" ) )
|
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;
|
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;
|
|
|
|
|
2012-01-05 08:07:11 +00:00
|
|
|
InitDataPoints( m_paper.GetSizeIU() );
|
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,
|
|
|
|
"SCH_SCREEN must have a SCHEMATIC parent!" );
|
|
|
|
|
|
|
|
return static_cast<SCHEMATIC*>( GetParent() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
void SCH_SCREEN::clearLibSymbols()
|
|
|
|
{
|
|
|
|
for( auto libSymbol : m_libSymbols )
|
|
|
|
delete libSymbol.second;
|
|
|
|
|
|
|
|
m_libSymbols.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
wxCHECK_RET( m_refCount != 0,
|
|
|
|
wxT( "Screen reference count already zero. Bad programmer!" ) );
|
|
|
|
m_refCount--;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-26 20:53:29 +00:00
|
|
|
bool SCH_SCREEN::HasItems( KICAD_T aItemType ) const
|
|
|
|
{
|
|
|
|
EE_RTREE::EE_TYPE sheets = const_cast<EE_RTREE&>( m_rtree ).OfType( aItemType );
|
|
|
|
|
|
|
|
return sheets.begin() != sheets.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
void SCH_SCREEN::Append( SCH_ITEM* aItem )
|
|
|
|
{
|
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 );
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
if( aItem->Type() == SCH_COMPONENT_T )
|
|
|
|
{
|
|
|
|
SCH_COMPONENT* symbol = static_cast<SCH_COMPONENT*>( aItem );
|
|
|
|
|
|
|
|
if( symbol->GetPartRef() )
|
|
|
|
{
|
|
|
|
auto it = m_libSymbols.find( symbol->GetSchSymbolLibraryName() );
|
|
|
|
|
|
|
|
if( it == m_libSymbols.end() )
|
|
|
|
{
|
|
|
|
m_libSymbols[symbol->GetSchSymbolLibraryName()] =
|
|
|
|
new LIB_PART( *symbol->GetPartRef() );
|
|
|
|
}
|
|
|
|
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.
|
|
|
|
LIB_PART* foundSymbol = it->second;
|
|
|
|
|
|
|
|
if( *foundSymbol != *symbol->GetPartRef() )
|
|
|
|
{
|
|
|
|
int cnt = 1;
|
|
|
|
wxString newName;
|
|
|
|
|
|
|
|
newName.Printf( "%s_%d", symbol->GetLibId().Format().wx_str(), cnt );
|
|
|
|
|
|
|
|
while( m_libSymbols.find( newName ) != m_libSymbols.end() )
|
|
|
|
{
|
|
|
|
cnt += 1;
|
|
|
|
newName.Printf( "%s_%d", symbol->GetLibId().Format().wx_str(), cnt );
|
|
|
|
}
|
|
|
|
|
|
|
|
symbol->SetSchSymbolLibraryName( newName );
|
|
|
|
m_libSymbols[newName] = new LIB_PART( *symbol->GetPartRef() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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." );
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
// No need to descend the hierarchy. Once the top level screen is copied, all of it's
|
2017-11-17 17:00:04 +00:00
|
|
|
// children are copied as well.
|
2019-06-25 23:39:58 +00:00
|
|
|
for( auto 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();
|
|
|
|
|
|
|
|
for( auto item : delete_list )
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SCREEN::Update( SCH_ITEM* aItem )
|
|
|
|
{
|
2020-01-25 17:32:05 +00:00
|
|
|
if( Remove( aItem ) )
|
|
|
|
Append( aItem );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2020-01-25 17:32:05 +00:00
|
|
|
bool SCH_SCREEN::Remove( SCH_ITEM* aItem )
|
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.
|
|
|
|
if( retv && aItem->Type() == SCH_COMPONENT_T )
|
|
|
|
{
|
|
|
|
SCH_COMPONENT* removedSymbol = static_cast<SCH_COMPONENT*>( aItem );
|
|
|
|
|
|
|
|
bool removeUnusedLibSymbol = true;
|
|
|
|
|
|
|
|
for( SCH_ITEM* item : Items().OfType( SCH_COMPONENT_T ) )
|
|
|
|
{
|
|
|
|
SCH_COMPONENT* symbol = static_cast<SCH_COMPONENT*>( item );
|
|
|
|
|
|
|
|
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 )
|
|
|
|
SetModify();
|
|
|
|
|
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();
|
2018-10-18 12:07:57 +00:00
|
|
|
wxCHECK_RET( sheet, wxT( "Sheet label 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-05 14:46:51 +00:00
|
|
|
bool SCH_SCREEN::CheckIfOnDrawList( SCH_ITEM* aItem )
|
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
|
|
|
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
SCH_ITEM* SCH_SCREEN::GetItem( const wxPoint& aPosition, int aAccuracy, KICAD_T aType )
|
2011-01-11 20:34:29 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
EDA_RECT bbox;
|
|
|
|
bbox.SetOrigin( aPosition );
|
|
|
|
bbox.Inflate( aAccuracy );
|
2019-05-06 02:32:01 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
for( auto 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
std::set<SCH_ITEM*> SCH_SCREEN::MarkConnections( SCH_LINE* aSegment )
|
2011-02-05 02:21:11 +00:00
|
|
|
{
|
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
|
|
|
{
|
2020-08-10 11:40:58 +00:00
|
|
|
SCH_LINE* test_item = to_search.top();
|
2019-06-25 23:39:58 +00:00
|
|
|
to_search.pop();
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2020-08-10 11:40:58 +00:00
|
|
|
for( SCH_ITEM* item : Items().Overlapping( SCH_JUNCTION_T, test_item->GetBoundingBox() ) )
|
2011-03-10 19:36:30 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
if( test_item->IsEndPoint( item->GetPosition() ) )
|
|
|
|
retval.insert( item );
|
2011-03-10 19:36:30 +00:00
|
|
|
}
|
|
|
|
|
2020-08-10 11:40:58 +00:00
|
|
|
for( SCH_ITEM* item : Items().Overlapping( SCH_LINE_T, test_item->GetBoundingBox() ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
2020-04-02 17:03:53 +00:00
|
|
|
// Skip connecting lines on different layers (e.g. buses)
|
2019-06-25 23:39:58 +00:00
|
|
|
if( test_item->GetLayer() != item->GetLayer() )
|
|
|
|
continue;
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2020-08-10 11:40:58 +00:00
|
|
|
SCH_LINE* line = static_cast<SCH_LINE*>( item );
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
if( ( test_item->IsEndPoint( line->GetStartPoint() )
|
|
|
|
&& !GetPin( line->GetStartPoint(), NULL, true ) )
|
2020-08-10 11:40:58 +00:00
|
|
|
|| ( test_item->IsEndPoint( line->GetEndPoint() )
|
|
|
|
&& !GetPin( line->GetEndPoint(), nullptr, true ) ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
|
|
|
auto result = retval.insert( line );
|
2011-03-10 19:36:30 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
if( result.second )
|
|
|
|
to_search.push( line );
|
|
|
|
}
|
2011-03-10 19:36:30 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
|
|
|
|
return retval;
|
2011-03-10 19:36:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-27 19:27:24 +00:00
|
|
|
bool SCH_SCREEN::IsJunctionNeeded( const wxPoint& aPosition, bool aNew )
|
2011-03-10 19:36:30 +00:00
|
|
|
{
|
2020-04-02 17:03:53 +00:00
|
|
|
enum { WIRES, BUSES } layers;
|
2019-05-17 09:29:52 +00:00
|
|
|
|
|
|
|
bool has_nonparallel[ sizeof( layers ) ] = { false };
|
|
|
|
int end_count[ sizeof( layers ) ] = { 0 };
|
2020-08-10 11:40:58 +00:00
|
|
|
int entry_count = 0;
|
2017-12-13 05:12:06 +00:00
|
|
|
int pin_count = 0;
|
|
|
|
|
2019-05-17 09:29:52 +00:00
|
|
|
std::vector<SCH_LINE*> lines[ sizeof( layers ) ];
|
2017-11-27 19:27:24 +00:00
|
|
|
|
2020-08-10 11:40:58 +00:00
|
|
|
for( 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:
|
|
|
|
if( aNew && item->HitTest( aPosition ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_LINE_T:
|
|
|
|
if( item->HitTest( aPosition, 0 ) )
|
|
|
|
{
|
|
|
|
if( item->GetLayer() == LAYER_WIRE )
|
|
|
|
lines[WIRES].push_back( (SCH_LINE*) item );
|
|
|
|
else if( item->GetLayer() == LAYER_BUS )
|
|
|
|
lines[BUSES].push_back( (SCH_LINE*) item );
|
|
|
|
}
|
|
|
|
break;
|
2017-12-07 20:19:53 +00:00
|
|
|
|
2020-08-10 11:40:58 +00:00
|
|
|
case SCH_BUS_WIRE_ENTRY_T:
|
|
|
|
case SCH_BUS_BUS_ENTRY_T:
|
|
|
|
if( item->IsConnected( aPosition ) )
|
|
|
|
entry_count++;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCH_COMPONENT_T:
|
|
|
|
case SCH_SHEET_T:
|
|
|
|
if( item->IsConnected( aPosition ) )
|
|
|
|
pin_count++;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-03-10 19:36:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-02 17:03:53 +00:00
|
|
|
for( int i : { WIRES, BUSES } )
|
2017-11-27 19:27:24 +00:00
|
|
|
{
|
2017-12-13 05:12:06 +00:00
|
|
|
bool removed_overlapping = false;
|
2020-01-03 13:38:50 +00:00
|
|
|
bool mid_point = false;
|
2017-12-13 05:12:06 +00:00
|
|
|
|
|
|
|
for( auto line = lines[i].begin(); line < lines[i].end(); line++ )
|
2017-11-27 19:27:24 +00:00
|
|
|
{
|
2017-12-13 05:12:06 +00:00
|
|
|
if( !(*line)->IsEndPoint( aPosition ) )
|
2020-01-03 13:38:50 +00:00
|
|
|
mid_point = true;
|
|
|
|
else
|
2017-12-13 05:12:06 +00:00
|
|
|
end_count[i]++;
|
|
|
|
|
|
|
|
for( auto second_line = lines[i].end() - 1; second_line > line; second_line-- )
|
|
|
|
{
|
|
|
|
if( !(*line)->IsParallel( *second_line ) )
|
|
|
|
has_nonparallel[i] = true;
|
|
|
|
else if( !removed_overlapping
|
|
|
|
&& (*line)->IsSameQuadrant( *second_line, aPosition ) )
|
|
|
|
{
|
|
|
|
removed_overlapping = true;
|
|
|
|
}
|
|
|
|
}
|
2017-11-27 19:27:24 +00:00
|
|
|
}
|
2020-01-03 13:38:50 +00:00
|
|
|
|
|
|
|
/// A line with a midpoint should be counted as two endpoints for this calculation
|
|
|
|
/// because the junction will split the line into two if there is another item
|
|
|
|
/// present at the point.
|
|
|
|
if( mid_point )
|
|
|
|
end_count[i] += 2;
|
|
|
|
|
|
|
|
///Overlapping lines that point in the same direction should not be counted
|
|
|
|
/// as extra end_points.
|
|
|
|
if( removed_overlapping )
|
|
|
|
end_count[i]--;
|
2017-11-27 19:27:24 +00:00
|
|
|
}
|
|
|
|
|
2017-12-07 20:19:53 +00:00
|
|
|
// If there are three or more endpoints
|
2019-10-19 03:15:29 +00:00
|
|
|
if( pin_count && pin_count + end_count[WIRES] > 2 )
|
2017-11-27 19:27:24 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// If there is at least one segment that ends on a non-parallel line or
|
|
|
|
// junction of two other lines
|
2019-10-19 03:15:29 +00:00
|
|
|
if( has_nonparallel[WIRES] && end_count[WIRES] > 2 )
|
2017-12-13 05:12:06 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// Check for bus - bus junction requirements
|
2020-04-02 17:03:53 +00:00
|
|
|
if( has_nonparallel[BUSES] && end_count[BUSES] > 2 )
|
2017-11-27 19:27:24 +00:00
|
|
|
return true;
|
|
|
|
|
2020-08-10 11:40:58 +00:00
|
|
|
// Check for bus - bus entry requirements
|
|
|
|
if( !aNew && entry_count && end_count[BUSES] )
|
|
|
|
return true;
|
|
|
|
|
2011-03-10 19:36:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
bool SCH_SCREEN::IsTerminalPoint( const wxPoint& aPosition, int aLayer )
|
|
|
|
{
|
|
|
|
wxCHECK_MSG( aLayer == LAYER_NOTES || aLayer == LAYER_BUS || aLayer == LAYER_WIRE, false,
|
|
|
|
wxT( "Invalid layer type passed to SCH_SCREEN::IsTerminalPoint()." ) );
|
|
|
|
|
|
|
|
SCH_SHEET_PIN* label;
|
|
|
|
SCH_TEXT* text;
|
2019-03-11 21:32:05 +00:00
|
|
|
SCH_CONNECTION conn;
|
2011-03-25 19:16:05 +00:00
|
|
|
|
|
|
|
switch( aLayer )
|
|
|
|
{
|
|
|
|
case LAYER_BUS:
|
|
|
|
|
|
|
|
if( GetBus( aPosition ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
label = GetSheetLabel( aPosition );
|
|
|
|
|
2020-05-06 22:26:56 +00:00
|
|
|
if( label && conn.MightBeBusLabel( label->GetText() ) && label->IsConnected( aPosition ) )
|
2011-03-25 19:16:05 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
text = GetLabel( aPosition );
|
|
|
|
|
2020-05-06 22:26:56 +00:00
|
|
|
if( text && conn.MightBeBusLabel( text->GetText() ) && text->IsConnected( aPosition )
|
2011-03-25 19:16:05 +00:00
|
|
|
&& (text->Type() != SCH_LABEL_T) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_NOTES:
|
|
|
|
|
|
|
|
if( GetLine( aPosition ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_WIRE:
|
2020-04-04 20:32:14 +00:00
|
|
|
if( GetItem( aPosition, Mils2iu( 6 ), SCH_BUS_WIRE_ENTRY_T) )
|
2013-04-01 10:35:20 +00:00
|
|
|
return true;
|
|
|
|
|
2020-04-04 20:32:14 +00:00
|
|
|
if( GetItem( aPosition, Mils2iu( 6 ), SCH_BUS_BUS_ENTRY_T) )
|
2011-03-25 19:16:05 +00:00
|
|
|
return true;
|
|
|
|
|
2020-05-20 03:34:55 +00:00
|
|
|
if( GetItem( aPosition, Schematic()->Settings().m_JunctionSize, SCH_JUNCTION_T ) )
|
2011-03-25 19:16:05 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if( GetPin( aPosition, NULL, true ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( GetWire( aPosition ) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
text = GetLabel( aPosition );
|
|
|
|
|
2020-05-06 22:26:56 +00:00
|
|
|
if( text && text->IsConnected( aPosition ) && !conn.MightBeBusLabel( text->GetText() ) )
|
2011-03-25 19:16:05 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
label = GetSheetLabel( aPosition );
|
|
|
|
|
2020-05-06 22:26:56 +00:00
|
|
|
if( label && label->IsConnected( aPosition ) && !conn.MightBeBusLabel( label->GetText() ) )
|
2011-03-25 19:16:05 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
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;
|
|
|
|
std::unique_ptr< LIB_PART > libSymbol;
|
|
|
|
std::vector<SCH_COMPONENT*> symbols;
|
2020-05-21 02:27:48 +00:00
|
|
|
SYMBOL_LIB_TABLE* libs = Schematic()->Prj().SchSymbolLibTable();
|
2020-04-16 16:43:50 +00:00
|
|
|
|
|
|
|
// This will be a nullptr if an s-expression schematic is loaded.
|
2020-05-21 02:27:48 +00:00
|
|
|
PART_LIBS* legacyLibs = Schematic()->Prj().SchLibs();
|
2020-04-16 16:43:50 +00:00
|
|
|
|
|
|
|
for( auto item : Items().OfType( SCH_COMPONENT_T ) )
|
|
|
|
symbols.push_back( static_cast<SCH_COMPONENT*>( item ) );
|
|
|
|
|
|
|
|
// Remove them from the R tree. There bounding box size may change.
|
|
|
|
for( auto symbol : symbols )
|
|
|
|
Remove( symbol );
|
|
|
|
|
|
|
|
// Clear all existing symbol links.
|
|
|
|
clearLibSymbols();
|
|
|
|
|
|
|
|
for( auto 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
|
|
|
{
|
2020-04-16 16:43:50 +00:00
|
|
|
LIB_PART* tmp = nullptr;
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Setting schematic symbol '%s %s' library identifier "
|
|
|
|
"to '%s'. " ),
|
|
|
|
symbol->GetField( REFERENCE )->GetText(),
|
|
|
|
symbol->GetField( VALUE )->GetText(),
|
|
|
|
symbol->GetLibId().Format().wx_str() );
|
|
|
|
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.
|
|
|
|
symbol->SetLibSymbol( new LIB_PART( *it->second ) );
|
2020-04-16 16:43:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !symbol->GetLibId().IsValid() )
|
|
|
|
{
|
|
|
|
if( aReporter )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Schematic symbol reference '%s' library identifier is not "
|
|
|
|
"valid. Unable to link library symbol." ),
|
|
|
|
symbol->GetLibId().Format().wx_str() );
|
|
|
|
aReporter->ReportTail( msg, RPT_SEVERITY_WARNING );
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// LIB_TABLE_BASE::LoadSymbol() throws an IO_ERROR if the the library nickname
|
|
|
|
// 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 )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Symbol library '%s' not found and no fallback cache "
|
2020-05-10 14:55:15 +00:00
|
|
|
"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(),
|
|
|
|
symbol->GetLibId().Format().wx_str() );
|
|
|
|
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
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
if( !tmp && legacyLibs )
|
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
|
|
|
{
|
2020-04-16 16:43:50 +00:00
|
|
|
// If here, only the cache library should be loaded if the loaded schematic
|
|
|
|
// is the legacy file format.
|
|
|
|
wxCHECK2( legacyLibs->GetLibraryCount() == 1, continue );
|
|
|
|
|
|
|
|
PART_LIB& legacyCacheLib = legacyLibs->at( 0 );
|
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
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
// ...and it better be the cache library.
|
|
|
|
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'." ),
|
|
|
|
symbol->GetField( REFERENCE )->GetText(),
|
|
|
|
symbol->GetField( VALUE )->GetText(),
|
|
|
|
id );
|
|
|
|
aReporter->ReportTail( msg, RPT_SEVERITY_WARNING );
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = legacyCacheLib.FindPart( id );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( tmp )
|
|
|
|
{
|
|
|
|
// We want a full symbol not just the top level child symbol.
|
|
|
|
libSymbol = tmp->Flatten();
|
|
|
|
libSymbol->SetParent();
|
|
|
|
|
|
|
|
m_libSymbols.insert( { symbol->GetSchSymbolLibraryName(),
|
|
|
|
new LIB_PART( *libSymbol.get() ) } );
|
|
|
|
|
|
|
|
if( aReporter )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "Setting schematic symbol '%s %s' library identifier to '%s'. " ),
|
|
|
|
symbol->GetField( REFERENCE )->GetText(),
|
|
|
|
symbol->GetField( VALUE )->GetText(),
|
|
|
|
symbol->GetLibId().Format().wx_str() );
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
msg.Printf( _( "No library symbol found for schematic symbol '%s %s'. " ),
|
|
|
|
symbol->GetField( REFERENCE )->GetText(),
|
|
|
|
symbol->GetField( VALUE )->GetText() );
|
|
|
|
aReporter->ReportTail( msg, RPT_SEVERITY_ERROR );
|
|
|
|
}
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
2020-01-23 14:05:12 +00:00
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
symbol->SetLibSymbol( libSymbol.release() );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Changing the symbol may adjust the bbox of the symbol. This re-inserts the
|
|
|
|
// item with the new bbox
|
|
|
|
for( auto symbol : symbols )
|
|
|
|
Append( symbol );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SCREEN::UpdateLocalLibSymbolLinks()
|
|
|
|
{
|
2020-05-20 22:50:09 +00:00
|
|
|
std::vector<SCH_COMPONENT*> symbols;
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
for( auto item : Items().OfType( SCH_COMPONENT_T ) )
|
2020-05-20 22:50:09 +00:00
|
|
|
symbols.push_back( static_cast<SCH_COMPONENT*>( item ) );
|
|
|
|
|
|
|
|
for( auto 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() );
|
|
|
|
|
|
|
|
LIB_PART* libSymbol = nullptr;
|
|
|
|
|
|
|
|
if( it != m_libSymbols.end() )
|
|
|
|
libSymbol = new LIB_PART( *it->second );
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
void SCH_SCREEN::Print( 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:
|
2017-11-03 17:56:59 +00:00
|
|
|
std::vector< SCH_ITEM* > junctions;
|
2020-01-10 04:15:46 +00:00
|
|
|
std::vector<SCH_ITEM*> bitmaps;
|
|
|
|
std::vector<SCH_ITEM*> other;
|
2014-08-18 16:39:51 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
for( auto item : Items() )
|
2011-01-11 20:34:29 +00:00
|
|
|
{
|
2011-07-08 19:55:41 +00:00
|
|
|
if( item->IsMoving() || item->IsResized() )
|
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
|
2020-04-14 12:25:00 +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-04-14 12:25:00 +00:00
|
|
|
return a->Type() > b->Type();
|
|
|
|
} );
|
2020-01-10 04:15:46 +00:00
|
|
|
|
|
|
|
for( auto item : bitmaps )
|
2020-04-14 12:25:00 +00:00
|
|
|
item->Print( aSettings, wxPoint( 0, 0 ) );
|
2020-01-10 04:15:46 +00:00
|
|
|
|
|
|
|
for( auto item : other )
|
2020-04-14 12:25:00 +00:00
|
|
|
item->Print( aSettings, wxPoint( 0, 0 ) );
|
2020-01-10 04:15:46 +00:00
|
|
|
|
2017-11-03 17:56:59 +00:00
|
|
|
for( auto item : junctions )
|
2020-04-14 12:25:00 +00:00
|
|
|
item->Print( aSettings, wxPoint( 0, 0 ) );
|
2011-01-11 20:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-17 13:24:22 +00:00
|
|
|
void SCH_SCREEN::Plot( PLOTTER* aPlotter )
|
|
|
|
{
|
2019-06-16 20:27:11 +00:00
|
|
|
// Ensure links are up to date, even if a library was reloaded for some reason:
|
|
|
|
std::vector< SCH_ITEM* > junctions;
|
|
|
|
std::vector< SCH_ITEM* > bitmaps;
|
|
|
|
std::vector< SCH_ITEM* > other;
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
for( auto item : Items() )
|
2019-06-16 20:27:11 +00:00
|
|
|
{
|
|
|
|
if( item->IsMoving() || item->IsResized() )
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2020-01-10 04:15:46 +00:00
|
|
|
/// Sort to ensure plot-order consistency with screen drawing
|
|
|
|
std::sort( other.begin(), other.end(), []( const SCH_ITEM* a, const SCH_ITEM* b ) {
|
|
|
|
if( a->Type() == b->Type() )
|
|
|
|
return a->GetLayer() > b->GetLayer();
|
|
|
|
|
|
|
|
return a->Type() > b->Type();
|
|
|
|
} );
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
int defaultPenWidth = aPlotter->RenderSettings()->GetDefaultPenWidth();
|
|
|
|
|
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
|
2020-05-12 14:02:24 +00:00
|
|
|
for( 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 ) );
|
2019-06-16 20:27:11 +00:00
|
|
|
item->Plot( aPlotter );
|
|
|
|
}
|
|
|
|
|
2020-05-12 14:02:24 +00:00
|
|
|
for( 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 ) );
|
2019-06-16 20:27:11 +00:00
|
|
|
item->Plot( aPlotter );
|
|
|
|
}
|
|
|
|
|
2020-05-12 14:02:24 +00:00
|
|
|
for( 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 ) );
|
2011-06-17 13:24:22 +00:00
|
|
|
item->Plot( aPlotter );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
void SCH_SCREEN::ClearDrawingState()
|
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
for( auto item : Items() )
|
2019-05-01 11:37:35 +00:00
|
|
|
item->ClearTempFlags();
|
2010-11-03 14:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
LIB_PIN* SCH_SCREEN::GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent,
|
|
|
|
bool aEndPointOnly )
|
2010-12-13 15:59:00 +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
|
|
|
SCH_COMPONENT* component = NULL;
|
|
|
|
LIB_PIN* pin = NULL;
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( SCH_ITEM* item : Items().Overlapping( SCH_COMPONENT_T, aPosition ) )
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
component = static_cast<SCH_COMPONENT*>( item );
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2011-05-05 17:45:35 +00:00
|
|
|
if( aEndPointOnly )
|
|
|
|
{
|
|
|
|
pin = NULL;
|
2011-12-07 20:19:29 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
if( !component->GetPartRef() )
|
2011-05-05 17:45:35 +00:00
|
|
|
continue;
|
2011-12-07 20:19:29 +00:00
|
|
|
|
2019-11-06 19:15:42 +00:00
|
|
|
for( pin = component->GetPartRef()->GetNextPin(); pin;
|
|
|
|
pin = component->GetPartRef()->GetNextPin( pin ) )
|
2011-05-05 17:45:35 +00:00
|
|
|
{
|
|
|
|
// Skip items not used for this part.
|
|
|
|
if( component->GetUnit() && pin->GetUnit() &&
|
|
|
|
( pin->GetUnit() != component->GetUnit() ) )
|
|
|
|
continue;
|
2011-12-07 20:19:29 +00:00
|
|
|
|
2011-05-05 17:45:35 +00:00
|
|
|
if( component->GetConvert() && pin->GetConvert() &&
|
|
|
|
( pin->GetConvert() != component->GetConvert() ) )
|
|
|
|
continue;
|
2011-12-07 20:19:29 +00:00
|
|
|
|
2011-05-05 17:45:35 +00:00
|
|
|
if(component->GetPinPhysicalPosition( pin ) == aPosition )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if( pin )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pin = (LIB_PIN*) component->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
|
|
|
|
2011-05-05 17:45:35 +00:00
|
|
|
if( pin && aComponent )
|
2010-12-13 15:59:00 +00:00
|
|
|
*aComponent = component;
|
|
|
|
|
|
|
|
return pin;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-11 20:34:29 +00:00
|
|
|
SCH_SHEET_PIN* SCH_SCREEN::GetSheetLabel( const wxPoint& aPosition )
|
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
SCH_SHEET_PIN* sheetPin = nullptr;
|
2011-01-11 20:34:29 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( SCH_ITEM* item : Items().OfType( SCH_SHEET_T ) )
|
2011-01-11 20:34:29 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
auto 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
size_t SCH_SCREEN::CountConnectedItems( const wxPoint& aPos, bool aTestJunctions )
|
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
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( SCH_ITEM* item : Items() )
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-15 20:22:45 +00:00
|
|
|
void SCH_SCREEN::ClearAnnotation( SCH_SHEET_PATH* aSheetPath )
|
2010-12-31 19:47:39 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( SCH_ITEM* item : Items().OfType( SCH_COMPONENT_T ) )
|
2010-12-31 19:47:39 +00:00
|
|
|
{
|
2020-03-16 11:05:01 +00:00
|
|
|
SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( item );
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
component->ClearAnnotation( aSheetPath );
|
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;
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( SCH_ITEM* item : Items().OfType( SCH_COMPONENT_T ) )
|
2018-09-03 10:11:39 +00:00
|
|
|
{
|
2020-09-06 10:26:39 +00:00
|
|
|
SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( 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-02-04 22:37:14 +00:00
|
|
|
component->AddSheetPathReferenceEntryIfMissing( sheet.Path() );
|
2018-09-03 10:11:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-03 14:52:31 +00:00
|
|
|
void SCH_SCREEN::GetHierarchicalItems( std::vector<SCH_ITEM*>* aItems )
|
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
|
|
|
{
|
|
|
|
if( ( item->Type() == SCH_SHEET_T ) || ( item->Type() == SCH_COMPONENT_T ) )
|
2020-05-03 14:52:31 +00:00
|
|
|
aItems->push_back( item );
|
2010-12-31 19:47:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-03 14:52:31 +00:00
|
|
|
void SCH_SCREEN::GetSheets( std::vector<SCH_ITEM*>* aItems )
|
|
|
|
{
|
|
|
|
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-05-03 22:20:31 +00:00
|
|
|
long a_order = 0;
|
|
|
|
long b_order = 0;
|
|
|
|
|
|
|
|
for( const SCH_FIELD& field : static_cast<SCH_SHEET*>( a )->GetFields() )
|
|
|
|
{
|
|
|
|
if( field.GetName().CmpNoCase( wxT( "Order" ) ) == 0 )
|
|
|
|
{
|
|
|
|
field.GetText().ToLong( &a_order );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( const SCH_FIELD& field : static_cast<SCH_SHEET*>( b )->GetFields() )
|
|
|
|
{
|
|
|
|
if( field.GetName().CmpNoCase( wxT( "Order" ) ) == 0 )
|
|
|
|
{
|
|
|
|
field.GetText().ToLong( &b_order );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( a_order == b_order )
|
|
|
|
{
|
|
|
|
if( a->GetPosition().x == b->GetPosition().x )
|
|
|
|
return a->GetPosition().y < b->GetPosition().y;
|
|
|
|
|
2020-05-03 14:52:31 +00:00
|
|
|
return a->GetPosition().x < b->GetPosition().x;
|
2020-05-03 22:20:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return a_order < b_order;
|
2020-05-03 14:52:31 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-17 02:33:16 +00:00
|
|
|
bool SCH_SCREEN::TestDanglingEnds( const SCH_SHEET_PATH* aPath )
|
2011-01-21 19:30:59 +00:00
|
|
|
{
|
|
|
|
std::vector< DANGLING_END_ITEM > endPoints;
|
2016-02-19 15:41:32 +00:00
|
|
|
bool hasStateChanged = false;
|
2011-01-21 19:30:59 +00:00
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( SCH_ITEM* item : Items() )
|
2011-01-21 19:30:59 +00:00
|
|
|
item->GetEndPoints( endPoints );
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( SCH_ITEM* item : Items() )
|
2011-01-21 19:30:59 +00:00
|
|
|
{
|
2020-01-17 02:33:16 +00:00
|
|
|
if( item->UpdateDanglingState( endPoints, aPath ) )
|
2016-02-19 15:41:32 +00:00
|
|
|
hasStateChanged = true;
|
2011-01-21 19:30:59 +00:00
|
|
|
}
|
|
|
|
|
2016-02-19 15:41:32 +00:00
|
|
|
return hasStateChanged;
|
2011-01-21 19:30:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
SCH_LINE* SCH_SCREEN::GetLine( const wxPoint& aPosition, int aAccuracy, int aLayer,
|
|
|
|
SCH_LINE_TEST_T aSearchType )
|
|
|
|
{
|
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 );
|
|
|
|
|
2020-03-16 11:05:01 +00:00
|
|
|
for( SCH_ITEM* item : Items() )
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_TEXT* SCH_SCREEN::GetLabel( const wxPoint& aPosition, int aAccuracy )
|
|
|
|
{
|
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:
|
2011-03-25 19:16:05 +00:00
|
|
|
if( item->HitTest( aPosition, aAccuracy ) )
|
|
|
|
return (SCH_TEXT*) item;
|
|
|
|
|
2020-04-24 23:44:09 +00:00
|
|
|
break;
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-16 16:43:50 +00:00
|
|
|
void SCH_SCREEN::AddLibSymbol( LIB_PART* aLibSymbol )
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
2008-02-26 19:19:54 +00:00
|
|
|
return NULL;
|
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 ];
|
|
|
|
|
2008-02-26 19:19:54 +00:00
|
|
|
return NULL;
|
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 ];
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_SCREENS::addScreenToList( SCH_SCREEN* aScreen, SCH_SHEET* aSheet )
|
2008-02-12 21:12:46 +00:00
|
|
|
{
|
2010-10-26 20:25:48 +00:00
|
|
|
if( aScreen == NULL )
|
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
|
|
|
|
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" );
|
|
|
|
|
2018-09-03 10:11:39 +00:00
|
|
|
// Clear the annotation for the components 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();
|
|
|
|
curr_screen->ClearAnnotation( &sheetpath );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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++;
|
2010-12-31 19:47:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2020-08-02 21:45:06 +00:00
|
|
|
void SCH_SCREENS::DeleteMarkers( enum MARKER_BASE::TYPEMARKER aMarkerType, int aErrorCode,
|
|
|
|
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
|
|
|
|
2020-08-02 21:45:06 +00:00
|
|
|
void SCH_SCREENS::DeleteAllMarkers( enum MARKER_BASE::TYPEMARKER aMarkerType,
|
|
|
|
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
|
|
|
|
// pointer 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-10 14:36:55 +00:00
|
|
|
void SCH_SCREENS::TestDanglingEnds()
|
|
|
|
{
|
2019-04-06 01:14:15 +00:00
|
|
|
std::vector<SCH_SCREEN*> screens;
|
2017-03-10 14:36:55 +00:00
|
|
|
for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
|
2019-04-06 01:14:15 +00:00
|
|
|
screens.push_back( screen );
|
|
|
|
|
|
|
|
size_t parallelThreadCount = std::min<size_t>( std::thread::hardware_concurrency(),
|
|
|
|
screens.size() );
|
|
|
|
|
|
|
|
std::atomic<size_t> nextScreen( 0 );
|
|
|
|
std::vector<std::future<size_t>> returns( parallelThreadCount );
|
|
|
|
|
|
|
|
auto update_lambda = [&screens, &nextScreen]() -> size_t
|
|
|
|
{
|
|
|
|
for( auto i = nextScreen++; i < screens.size(); i = nextScreen++ )
|
|
|
|
screens[i]->TestDanglingEnds();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
if( parallelThreadCount == 1 )
|
|
|
|
update_lambda();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
|
|
|
|
returns[ii] = std::async( std::launch::async, update_lambda );
|
|
|
|
|
|
|
|
// Finalize the threads
|
|
|
|
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
|
|
|
|
returns[ii].wait();
|
|
|
|
}
|
2017-03-10 14:36:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-05 22:31:31 +00:00
|
|
|
bool SCH_SCREENS::HasNoFullyDefinedLibIds()
|
|
|
|
{
|
|
|
|
SCH_SCREEN* screen;
|
2017-10-06 18:07:43 +00:00
|
|
|
unsigned cnt = 0;
|
2017-03-05 22:31:31 +00:00
|
|
|
|
|
|
|
for( screen = GetFirst(); screen; screen = GetNext() )
|
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
for( auto item : screen->Items().OfType( SCH_COMPONENT_T ) )
|
2017-03-05 22:31:31 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
cnt++;
|
|
|
|
auto symbol = static_cast<SCH_COMPONENT*>( item );
|
2017-03-05 22:31:31 +00:00
|
|
|
|
|
|
|
if( !symbol->GetLibId().GetLibNickname().empty() )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
return cnt != 0;
|
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
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
for( auto item : screen->Items().OfType( SCH_COMPONENT_T ) )
|
2017-11-17 17:00:04 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
auto symbol = static_cast<SCH_COMPONENT*>( item );
|
|
|
|
auto& 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() )
|
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
for( auto item : screen->Items().OfType( SCH_COMPONENT_T ) )
|
2017-11-17 17:00:04 +00:00
|
|
|
{
|
2019-06-25 23:39:58 +00:00
|
|
|
auto symbol = static_cast<SCH_COMPONENT*>( 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-17 16:43:05 +00:00
|
|
|
bool SCH_SCREENS::CanCauseCaseSensitivityIssue( const wxString& aSchematicFileName ) const
|
|
|
|
{
|
2019-11-19 21:06:18 +00:00
|
|
|
wxString lhsLower;
|
|
|
|
wxString rhsLower;
|
2019-11-17 16:43:05 +00:00
|
|
|
wxFileName lhs;
|
|
|
|
wxFileName rhs = aSchematicFileName;
|
|
|
|
|
|
|
|
wxCHECK( rhs.IsAbsolute(), false );
|
|
|
|
|
|
|
|
for( const SCH_SCREEN* screen : m_screens )
|
|
|
|
{
|
|
|
|
lhs = screen->GetFileName();
|
|
|
|
|
|
|
|
if( lhs.GetPath() != rhs.GetPath() )
|
|
|
|
continue;
|
|
|
|
|
2019-12-12 17:30:35 +00:00
|
|
|
lhsLower = lhs.GetFullName().Lower();
|
|
|
|
rhsLower = rhs.GetFullName().Lower();
|
2019-11-19 21:06:18 +00:00
|
|
|
|
2019-12-12 17:30:35 +00:00
|
|
|
if( lhsLower == rhsLower && lhs.GetFullName() != rhs.GetFullName() )
|
2019-11-17 16:43:05 +00:00
|
|
|
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();
|
|
|
|
|
|
|
|
// SEarch for the used_screen in list and add this unique sheet path:
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|