mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 10:13:19 +02:00
Simplify some of the library editing code. There have been a few minor changes in the behavior of the editor. If the current symbol is deleted from the library, the next symbol in the library is not loaded. The deleted symbol is cleared and the current symbol is empty. Change component to symbol to align with the preferred terminology discussed on the developer's mailing list. Add separate update UI event for save library as to enable the menu entry whenever a library is selected. Change the select symbol list dialog to a single column using the LIB_ID format LIB_NICKNAME:LIB_ITEM_NAME so that the selection can be parsed by LIB_ID. Add method to expand URI to LIB_TABLE_BASE. Override wxApp::OnExceptionInMainLoop() in debug builds to make debugging easier when an unhandled exception occurs in a wxUpdateUIEvent handler. Change SCH_SCREENS::HasNoFullyDefinedLibIds() to return false when the schematic has no symbols to prevent the remapping dialog from being run. Use SCH_COMPONENT part reference when creating netlist rather than looking up the library symbol.
201 lines
5.7 KiB
C++
201 lines
5.7 KiB
C++
/**
|
|
* @file annotate.cpp
|
|
* @brief Component annotation.
|
|
*/
|
|
|
|
/*
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
*
|
|
* Copyright (C) 2004-2017 KiCad Developers, see change_log.txt for contributors.
|
|
*
|
|
* 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
|
|
*/
|
|
|
|
#include <algorithm>
|
|
|
|
#include <fctsys.h>
|
|
#include <class_drawpanel.h>
|
|
#include <confirm.h>
|
|
#include <schframe.h>
|
|
|
|
#include <sch_reference_list.h>
|
|
#include <class_library.h>
|
|
|
|
void SCH_EDIT_FRAME::DeleteAnnotation( bool aCurrentSheetOnly )
|
|
{
|
|
if( aCurrentSheetOnly )
|
|
{
|
|
SCH_SCREEN* screen = GetScreen();
|
|
wxCHECK_RET( screen != NULL, wxT( "Attempt to clear annotation of a NULL screen." ) );
|
|
screen->ClearAnnotation( m_CurrentSheet );
|
|
}
|
|
else
|
|
{
|
|
SCH_SCREENS ScreenList;
|
|
ScreenList.ClearAnnotation();
|
|
}
|
|
|
|
// Update the references for the sheet that is currently being displayed.
|
|
m_CurrentSheet->UpdateAllScreenReferences();
|
|
GetCanvas()->Refresh();
|
|
OnModify();
|
|
}
|
|
|
|
|
|
void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic,
|
|
ANNOTATE_ORDER_T aSortOption,
|
|
ANNOTATE_OPTION_T aAlgoOption,
|
|
bool aResetAnnotation,
|
|
bool aRepairTimestamps,
|
|
bool aLockUnits )
|
|
{
|
|
SCH_REFERENCE_LIST references;
|
|
|
|
SCH_SCREENS screens;
|
|
|
|
// Build the sheet list.
|
|
SCH_SHEET_LIST sheets( g_RootSheet );
|
|
|
|
// Map of locked components
|
|
SCH_MULTI_UNIT_REFERENCE_MAP lockedComponents;
|
|
|
|
// Test for and replace duplicate time stamps in components and sheets. Duplicate
|
|
// time stamps can happen with old schematics, schematic conversions, or manual
|
|
// editing of files.
|
|
if( aRepairTimestamps )
|
|
{
|
|
int count = screens.ReplaceDuplicateTimeStamps();
|
|
|
|
if( count )
|
|
{
|
|
wxString msg;
|
|
msg.Printf( _( "%d duplicate time stamps were found and replaced." ), count );
|
|
DisplayInfoMessage( NULL, msg );
|
|
}
|
|
}
|
|
|
|
// If units must be locked, collect all the sets that must be annotated together.
|
|
if( aLockUnits )
|
|
{
|
|
if( aAnnotateSchematic )
|
|
{
|
|
sheets.GetMultiUnitComponents( lockedComponents );
|
|
}
|
|
else
|
|
{
|
|
m_CurrentSheet->GetMultiUnitComponents( lockedComponents );
|
|
}
|
|
}
|
|
|
|
// If it is an annotation for all the components, reset previous annotation.
|
|
if( aResetAnnotation )
|
|
DeleteAnnotation( !aAnnotateSchematic );
|
|
|
|
// Set sheet number and number of sheets.
|
|
SetSheetNumberAndCount();
|
|
|
|
// Build component list
|
|
if( aAnnotateSchematic )
|
|
{
|
|
sheets.GetComponents( references );
|
|
}
|
|
else
|
|
{
|
|
m_CurrentSheet->GetComponents( references );
|
|
}
|
|
|
|
// Break full components reference in name (prefix) and number:
|
|
// example: IC1 become IC, and 1
|
|
references.SplitReferences();
|
|
|
|
switch( aSortOption )
|
|
{
|
|
default:
|
|
case SORT_BY_X_POSITION:
|
|
references.SortByXCoordinate();
|
|
break;
|
|
|
|
case SORT_BY_Y_POSITION:
|
|
references.SortByYCoordinate();
|
|
break;
|
|
}
|
|
|
|
bool useSheetNum = false;
|
|
int idStep = 100;
|
|
|
|
switch( aAlgoOption )
|
|
{
|
|
default:
|
|
case INCREMENTAL_BY_REF:
|
|
break;
|
|
|
|
case SHEET_NUMBER_X_100:
|
|
useSheetNum = true;
|
|
break;
|
|
|
|
case SHEET_NUMBER_X_1000:
|
|
useSheetNum = true;
|
|
idStep = 1000;
|
|
break;
|
|
}
|
|
|
|
// Recalculate and update reference numbers in schematic
|
|
references.Annotate( useSheetNum, idStep, lockedComponents );
|
|
references.UpdateAnnotation();
|
|
|
|
wxArrayString errors;
|
|
|
|
// Final control (just in case ... ).
|
|
if( CheckAnnotate( &errors, !aAnnotateSchematic ) )
|
|
{
|
|
wxString msg;
|
|
|
|
for( size_t i = 0; i < errors.GetCount(); i++ )
|
|
msg += errors[i];
|
|
|
|
// wxLogWarning is a cheap and dirty way to dump a potentially long list of
|
|
// strings to a dialog that can be saved to a file. This should be replaced
|
|
// by a more elegant solution.
|
|
wxLogWarning( msg );
|
|
}
|
|
|
|
OnModify();
|
|
|
|
// Update on screen references, that can be modified by previous calculations:
|
|
m_CurrentSheet->UpdateAllScreenReferences();
|
|
SetSheetNumberAndCount();
|
|
|
|
m_canvas->Refresh( true );
|
|
}
|
|
|
|
|
|
int SCH_EDIT_FRAME::CheckAnnotate( wxArrayString* aMessageList, bool aOneSheetOnly )
|
|
{
|
|
// build the screen list
|
|
SCH_SHEET_LIST sheetList( g_RootSheet );
|
|
SCH_REFERENCE_LIST componentsList;
|
|
|
|
// Build the list of components
|
|
if( !aOneSheetOnly )
|
|
sheetList.GetComponents( componentsList );
|
|
else
|
|
m_CurrentSheet->GetComponents( componentsList );
|
|
|
|
return componentsList.CheckAnnotation( aMessageList );
|
|
}
|