kicad/eeschema/annotate.cpp

166 lines
4.2 KiB
C++
Raw Normal View History

/**
* @file annotate.cpp
* @brief Component annotation.
*/
2007-05-06 16:03:28 +00:00
#include <algorithm> // to use sort vector
#include <vector>
#include <fctsys.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <wxEeschemaStruct.h>
#include <netlist.h>
#include <class_library.h>
#include <protos.h>
#include <sch_component.h>
#include <lib_pin.h>
void SCH_EDIT_FRAME::DeleteAnnotation( bool aCurrentSheetOnly )
{
2008-04-21 06:34:56 +00:00
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();
2008-04-21 06:34:56 +00:00
}
// Update the references for the sheet that is currently being displayed.
2008-04-21 06:34:56 +00:00
m_CurrentSheet->UpdateAllScreenReferences();
}
2007-09-20 21:06:49 +00:00
void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic,
ANNOTATE_ORDER_T aSortOption,
ANNOTATE_OPTION_T aAlgoOption,
bool aResetAnnotation,
bool aRepairTimestamps )
2007-05-06 16:03:28 +00:00
{
SCH_REFERENCE_LIST references;
2007-09-20 21:06:49 +00:00
wxBusyCursor dummy;
2007-09-20 21:06:49 +00:00
SCH_SCREENS screens;
// Build the sheet list.
SCH_SHEET_LIST sheets;
// 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, 2 );
}
}
// If it is an annotation for all the components, reset previous annotation.
if( aResetAnnotation )
DeleteAnnotation( !aAnnotateSchematic );
2007-09-20 21:06:49 +00:00
// Set sheet number and number of sheets.
SetSheetNumberAndCount();
2007-09-20 21:06:49 +00:00
/* Build component list */
if( aAnnotateSchematic )
{
sheets.GetComponents( references );
2007-09-20 21:06:49 +00:00
}
else
{
m_CurrentSheet->GetComponents( references );
}
2007-09-20 21:06:49 +00:00
/* Break full components reference in name (prefix) and number:
2008-04-21 06:34:56 +00:00
* example: IC1 become IC, and 1 */
references.SplitReferences();
switch( aSortOption )
2008-04-21 14:03:20 +00:00
{
default:
case SORT_BY_X_POSITION:
references.SortByXCoordinate();
2008-04-21 14:03:20 +00:00
break;
2007-09-20 21:06:49 +00:00
case SORT_BY_Y_POSITION:
references.SortByYCoordinate();
2008-04-21 14:03:20 +00:00
break;
}
2008-04-21 14:03:20 +00:00
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;
2008-04-21 14:03:20 +00:00
break;
}
2007-09-20 21:06:49 +00:00
// Recalculate and update reference numbers in schematic
references.Annotate( useSheetNum, idStep );
references.UpdateAnnotation();
2007-09-20 21:06:49 +00:00
wxArrayString errors;
2007-05-06 16:03:28 +00:00
// 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();
2007-09-20 21:06:49 +00:00
m_canvas->Refresh( true );
2007-05-06 16:03:28 +00:00
}
int SCH_EDIT_FRAME::CheckAnnotate( wxArrayString* aMessageList, bool aOneSheetOnly )
2007-05-06 16:03:28 +00:00
{
/* build the screen list */
SCH_SHEET_LIST SheetList;
SCH_REFERENCE_LIST ComponentsList;
2007-09-20 21:06:49 +00:00
/* Build the list of components */
if( !aOneSheetOnly )
SheetList.GetComponents( ComponentsList );
2007-09-20 21:06:49 +00:00
else
m_CurrentSheet->GetComponents( ComponentsList );
return ComponentsList.CheckAnnotation( aMessageList );
2007-05-06 16:03:28 +00:00
}