2011-10-07 14:41:30 +00:00
|
|
|
/**
|
|
|
|
* @file annotate.cpp
|
|
|
|
* @brief Component annotation.
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2013-07-03 07:27:52 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-10-06 18:07:43 +00:00
|
|
|
* Copyright (C) 2004-2017 KiCad Developers, see change_log.txt for contributors.
|
2013-07-03 07:27:52 +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
|
|
|
|
*/
|
|
|
|
|
2013-12-13 16:27:30 +00:00
|
|
|
#include <algorithm>
|
2008-12-10 16:49:53 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
2018-02-17 11:43:56 +00:00
|
|
|
#include <reporter.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
|
2016-02-15 20:16:54 +00:00
|
|
|
#include <sch_reference_list.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_library.h>
|
2011-01-04 20:27:52 +00:00
|
|
|
|
2018-02-17 11:43:56 +00:00
|
|
|
|
|
|
|
void mapExistingAnnotation( std::map<timestamp_t, wxString>& aMap )
|
|
|
|
{
|
|
|
|
SCH_SHEET_LIST sheets( g_RootSheet );
|
|
|
|
SCH_REFERENCE_LIST references;
|
|
|
|
|
|
|
|
sheets.GetComponents( references );
|
|
|
|
|
|
|
|
for( size_t i = 0; i < references.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
SCH_COMPONENT* comp = references[ i ].GetComp();
|
|
|
|
wxString ref = comp->GetField( REFERENCE )->GetFullyQualifiedText();
|
|
|
|
|
|
|
|
if( !ref.Contains( wxT( "?" ) ) )
|
|
|
|
aMap[ comp->GetTimeStamp() ] = ref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-01 17:28:21 +00:00
|
|
|
void SCH_EDIT_FRAME::DeleteAnnotation( bool aCurrentSheetOnly )
|
2008-02-26 01:07:38 +00:00
|
|
|
{
|
2008-04-21 06:34:56 +00:00
|
|
|
if( aCurrentSheetOnly )
|
|
|
|
{
|
2016-02-15 20:22:45 +00:00
|
|
|
SCH_SCREEN* screen = GetScreen();
|
|
|
|
wxCHECK_RET( screen != NULL, wxT( "Attempt to clear annotation of a NULL screen." ) );
|
|
|
|
screen->ClearAnnotation( m_CurrentSheet );
|
2010-12-31 19:47:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-15 20:22:45 +00:00
|
|
|
SCH_SCREENS ScreenList;
|
|
|
|
ScreenList.ClearAnnotation();
|
2008-04-21 06:34:56 +00:00
|
|
|
}
|
|
|
|
|
2010-12-31 19:47:39 +00:00
|
|
|
// Update the references for the sheet that is currently being displayed.
|
2016-02-15 20:17:51 +00:00
|
|
|
m_CurrentSheet->UpdateAllScreenReferences();
|
2015-10-31 16:25:52 +00:00
|
|
|
GetCanvas()->Refresh();
|
|
|
|
OnModify();
|
2008-02-26 01:07:38 +00:00
|
|
|
}
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2011-05-20 19:21:09 +00:00
|
|
|
void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic,
|
|
|
|
ANNOTATE_ORDER_T aSortOption,
|
|
|
|
ANNOTATE_OPTION_T aAlgoOption,
|
2018-02-18 20:44:33 +00:00
|
|
|
int aStartNumber,
|
2011-05-20 19:21:09 +00:00
|
|
|
bool aResetAnnotation,
|
2015-03-23 11:45:31 +00:00
|
|
|
bool aRepairTimestamps,
|
2018-02-17 11:43:56 +00:00
|
|
|
bool aLockUnits,
|
|
|
|
REPORTER& aReporter )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-01-01 17:28:21 +00:00
|
|
|
SCH_REFERENCE_LIST references;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2010-12-31 19:47:39 +00:00
|
|
|
SCH_SCREENS screens;
|
|
|
|
|
2011-05-20 19:21:09 +00:00
|
|
|
// Build the sheet list.
|
2016-03-06 21:22:01 +00:00
|
|
|
SCH_SHEET_LIST sheets( g_RootSheet );
|
2010-12-31 19:47:39 +00:00
|
|
|
|
2015-03-23 11:45:31 +00:00
|
|
|
// Map of locked components
|
|
|
|
SCH_MULTI_UNIT_REFERENCE_MAP lockedComponents;
|
|
|
|
|
2018-02-17 11:43:56 +00:00
|
|
|
// Map of previous annotation for building info messages
|
|
|
|
std::map<timestamp_t, wxString> previousAnnotation;
|
|
|
|
|
2010-12-31 19:47:39 +00:00
|
|
|
// 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.
|
2011-05-20 19:21:09 +00:00
|
|
|
if( aRepairTimestamps )
|
2009-04-25 10:12:30 +00:00
|
|
|
{
|
2010-12-31 19:47:39 +00:00
|
|
|
int count = screens.ReplaceDuplicateTimeStamps();
|
|
|
|
|
|
|
|
if( count )
|
2009-04-25 10:12:30 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2010-12-31 19:47:39 +00:00
|
|
|
msg.Printf( _( "%d duplicate time stamps were found and replaced." ), count );
|
2018-05-21 22:28:26 +00:00
|
|
|
aReporter.ReportTail( msg, REPORTER::RPT_WARNING );
|
2009-04-25 10:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-23 11:45:31 +00:00
|
|
|
// If units must be locked, collect all the sets that must be annotated together.
|
|
|
|
if( aLockUnits )
|
|
|
|
{
|
|
|
|
if( aAnnotateSchematic )
|
|
|
|
{
|
2017-10-06 18:07:43 +00:00
|
|
|
sheets.GetMultiUnitComponents( lockedComponents );
|
2015-03-23 11:45:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-06 18:07:43 +00:00
|
|
|
m_CurrentSheet->GetMultiUnitComponents( lockedComponents );
|
2015-03-23 11:45:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-17 11:43:56 +00:00
|
|
|
// Store previous annotations for building info messages
|
|
|
|
mapExistingAnnotation( previousAnnotation );
|
|
|
|
|
2010-12-31 19:47:39 +00:00
|
|
|
// If it is an annotation for all the components, reset previous annotation.
|
2011-01-04 20:27:52 +00:00
|
|
|
if( aResetAnnotation )
|
|
|
|
DeleteAnnotation( !aAnnotateSchematic );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2011-01-02 18:56:44 +00:00
|
|
|
// Set sheet number and number of sheets.
|
2011-01-01 17:28:21 +00:00
|
|
|
SetSheetNumberAndCount();
|
2007-09-20 21:06:49 +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
|
|
|
// Build component list
|
2011-01-04 20:27:52 +00:00
|
|
|
if( aAnnotateSchematic )
|
2008-02-26 01:07:38 +00:00
|
|
|
{
|
2017-10-06 18:07:43 +00:00
|
|
|
sheets.GetComponents( references );
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
else
|
2010-12-31 19:47:39 +00:00
|
|
|
{
|
2017-10-06 18:07:43 +00:00
|
|
|
m_CurrentSheet->GetComponents( references );
|
2010-12-31 19:47:39 +00:00
|
|
|
}
|
2007-09-20 21:06:49 +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
|
|
|
// Break full components reference in name (prefix) and number:
|
|
|
|
// example: IC1 become IC, and 1
|
2011-01-05 19:16:55 +00:00
|
|
|
references.SplitReferences();
|
2008-04-25 10:32:16 +00:00
|
|
|
|
2011-01-04 20:27:52 +00:00
|
|
|
switch( aSortOption )
|
2008-04-21 14:03:20 +00:00
|
|
|
{
|
2011-01-04 20:27:52 +00:00
|
|
|
default:
|
2011-05-20 19:21:09 +00:00
|
|
|
case SORT_BY_X_POSITION:
|
2011-01-05 19:16:55 +00:00
|
|
|
references.SortByXCoordinate();
|
2008-04-21 14:03:20 +00:00
|
|
|
break;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2011-05-20 19:21:09 +00:00
|
|
|
case SORT_BY_Y_POSITION:
|
2011-01-05 19:16:55 +00:00
|
|
|
references.SortByYCoordinate();
|
2008-04-21 14:03:20 +00:00
|
|
|
break;
|
2011-01-04 20:27:52 +00:00
|
|
|
}
|
2008-04-21 14:03:20 +00:00
|
|
|
|
2011-01-04 20:27:52 +00:00
|
|
|
bool useSheetNum = false;
|
|
|
|
int idStep = 100;
|
2011-01-05 19:16:55 +00:00
|
|
|
|
2011-01-04 20:27:52 +00:00
|
|
|
switch( aAlgoOption )
|
|
|
|
{
|
|
|
|
default:
|
2011-05-20 19:21:09 +00:00
|
|
|
case INCREMENTAL_BY_REF:
|
2011-01-01 17:28:21 +00:00
|
|
|
break;
|
|
|
|
|
2011-05-20 19:21:09 +00:00
|
|
|
case SHEET_NUMBER_X_100:
|
2011-01-01 17:28:21 +00:00
|
|
|
useSheetNum = true;
|
|
|
|
break;
|
|
|
|
|
2011-05-20 19:21:09 +00:00
|
|
|
case SHEET_NUMBER_X_1000:
|
2011-01-04 20:27:52 +00:00
|
|
|
useSheetNum = true;
|
|
|
|
idStep = 1000;
|
2008-04-21 14:03:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2011-01-02 18:56:44 +00:00
|
|
|
// Recalculate and update reference numbers in schematic
|
2018-02-18 20:44:33 +00:00
|
|
|
references.Annotate( useSheetNum, idStep, aStartNumber, lockedComponents );
|
2011-01-02 18:56:44 +00:00
|
|
|
references.UpdateAnnotation();
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2018-02-17 11:43:56 +00:00
|
|
|
for( size_t i = 0; i < references.GetCount(); i++ )
|
2011-01-02 18:56:44 +00:00
|
|
|
{
|
2018-02-17 11:43:56 +00:00
|
|
|
SCH_COMPONENT* comp = references[ i ].GetComp();
|
|
|
|
wxString prevRef = previousAnnotation[ comp->GetTimeStamp() ];
|
|
|
|
wxString newRef = comp->GetField( REFERENCE )->GetFullyQualifiedText();
|
|
|
|
wxString msg;
|
2011-01-02 18:56:44 +00:00
|
|
|
|
2018-02-17 11:43:56 +00:00
|
|
|
if( prevRef.Length() )
|
|
|
|
{
|
|
|
|
if( newRef == prevRef )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( comp->GetUnitCount() > 1 )
|
2018-05-05 23:21:54 +00:00
|
|
|
msg.Printf( _( "Updated %s (unit %s) from %s to %s" ),
|
2018-02-17 11:43:56 +00:00
|
|
|
GetChars( comp->GetField( VALUE )->GetShownText() ),
|
2018-05-05 23:21:54 +00:00
|
|
|
LIB_PART::SubReference( comp->GetUnit(), false ),
|
2018-02-17 11:43:56 +00:00
|
|
|
GetChars( prevRef ),
|
|
|
|
GetChars( newRef ) );
|
|
|
|
else
|
|
|
|
msg.Printf( _( "Updated %s from %s to %s" ),
|
|
|
|
GetChars( comp->GetField( VALUE )->GetShownText() ),
|
|
|
|
GetChars( prevRef ),
|
|
|
|
GetChars( newRef ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( comp->GetUnitCount() > 1 )
|
2018-05-05 23:21:54 +00:00
|
|
|
msg.Printf( _( "Annotated %s (unit %s) as %s" ),
|
2018-02-17 11:43:56 +00:00
|
|
|
GetChars( comp->GetField( VALUE )->GetShownText() ),
|
2018-05-05 23:21:54 +00:00
|
|
|
LIB_PART::SubReference( comp->GetUnit(), false ),
|
2018-02-17 11:43:56 +00:00
|
|
|
GetChars( newRef ) );
|
|
|
|
else
|
|
|
|
msg.Printf( _( "Annotated %s as %s" ),
|
|
|
|
GetChars( comp->GetField( VALUE )->GetShownText() ),
|
|
|
|
GetChars( newRef ) );
|
|
|
|
}
|
2011-01-05 19:16:55 +00:00
|
|
|
|
2018-02-18 20:44:33 +00:00
|
|
|
aReporter.Report( msg, REPORTER::RPT_ACTION );
|
2011-01-02 18:56:44 +00:00
|
|
|
}
|
|
|
|
|
2018-02-17 11:43:56 +00:00
|
|
|
// Final control (just in case ... ).
|
|
|
|
if( !CheckAnnotate( aReporter, !aAnnotateSchematic ) )
|
2018-05-21 22:28:26 +00:00
|
|
|
aReporter.ReportTail( _( "Annotation complete." ), REPORTER::RPT_ACTION );
|
2018-02-17 11:43:56 +00:00
|
|
|
|
2011-01-06 16:55:18 +00:00
|
|
|
OnModify();
|
2011-01-05 19:16:55 +00:00
|
|
|
|
2011-01-06 16:55:18 +00:00
|
|
|
// Update on screen references, that can be modified by previous calculations:
|
2016-02-15 20:17:51 +00:00
|
|
|
m_CurrentSheet->UpdateAllScreenReferences();
|
2011-01-06 16:55:18 +00:00
|
|
|
SetSheetNumberAndCount();
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh( true );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-17 11:43:56 +00:00
|
|
|
int SCH_EDIT_FRAME::CheckAnnotate( REPORTER& aReporter, bool aOneSheetOnly )
|
2007-05-06 16:03:28 +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
|
|
|
// build the screen list
|
2016-06-24 10:55:54 +00:00
|
|
|
SCH_SHEET_LIST sheetList( g_RootSheet );
|
|
|
|
SCH_REFERENCE_LIST componentsList;
|
2007-09-20 21:06:49 +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
|
|
|
// Build the list of components
|
2009-07-05 12:09:41 +00:00
|
|
|
if( !aOneSheetOnly )
|
2017-10-06 18:07:43 +00:00
|
|
|
sheetList.GetComponents( componentsList );
|
2007-09-20 21:06:49 +00:00
|
|
|
else
|
2017-10-06 18:07:43 +00:00
|
|
|
m_CurrentSheet->GetComponents( componentsList );
|
2008-02-26 01:07:38 +00:00
|
|
|
|
2018-02-17 11:43:56 +00:00
|
|
|
return componentsList.CheckAnnotation( aReporter );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|