2007-09-20 21:06:49 +00:00
|
|
|
/**************************************/
|
|
|
|
/* annotate.cpp: component annotation */
|
|
|
|
/**************************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-12-10 16:49:53 +00:00
|
|
|
#include <algorithm> // to use sort vector
|
|
|
|
#include <vector>
|
|
|
|
|
2008-02-26 01:07:38 +00:00
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
|
|
|
#include "wxstruct.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#include "class_sch_screen.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "wxEeschemaStruct.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2010-12-31 19:47:39 +00:00
|
|
|
#include "netlist.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "class_library.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "protos.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#include "sch_component.h"
|
2010-10-22 12:11:52 +00:00
|
|
|
#include "lib_pin.h"
|
2008-12-10 16:49:53 +00:00
|
|
|
|
2011-01-04 20:27:52 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function DeleteAnnotation
|
2008-04-21 06:34:56 +00:00
|
|
|
* Remove current component annotations
|
2009-12-02 21:44:03 +00:00
|
|
|
* @param aCurrentSheetOnly : if false: remove all annotations, else remove
|
|
|
|
* annotation relative to the current sheet only
|
2008-04-21 06:34:56 +00:00
|
|
|
*/
|
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 )
|
|
|
|
{
|
2010-12-31 19:47:39 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-12-31 19:47:39 +00:00
|
|
|
// Update the references for the sheet that is currently being displayed.
|
2008-04-21 06:34:56 +00:00
|
|
|
m_CurrentSheet->UpdateAllScreenReferences();
|
2008-02-26 01:07:38 +00:00
|
|
|
}
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
/**
|
2011-01-04 20:27:52 +00:00
|
|
|
* Function AnnotateComponents:
|
2009-12-02 21:44:03 +00:00
|
|
|
*
|
|
|
|
* Compute the annotation of the components for the whole project, or the
|
|
|
|
* current sheet only. All the components or the new ones only will be
|
|
|
|
* annotated.
|
2011-01-04 20:27:52 +00:00
|
|
|
* @param aAnnotateSchematic : true = entire schematic annotation,
|
2009-12-02 21:44:03 +00:00
|
|
|
* false = current sheet only
|
2011-01-04 20:27:52 +00:00
|
|
|
* @param aSortOption : 0 = annotate by sorting X position,
|
|
|
|
* 1 = annotate by sorting Y position,
|
|
|
|
* 2 = annotate by sorting value
|
|
|
|
* @param aAlgoOption : 0 = annotate schematic using first free Id number
|
|
|
|
* 1 = annotate using first free Id number, starting to sheet number * 100
|
|
|
|
* 2 = annotate using first free Id number, starting to sheet number * 1000
|
|
|
|
* @param aResetAnnotation : true = remove previous annotation
|
2009-12-02 21:44:03 +00:00
|
|
|
* false = annotate new components only
|
2011-01-04 20:27:52 +00:00
|
|
|
* @param aRepairsTimestamps : true = test for duplicate times stamps and
|
2009-12-02 21:44:03 +00:00
|
|
|
* replace duplicated
|
|
|
|
* Note: this option could change previous annotation, because time
|
|
|
|
* stamps are used to handle annotation mainly in complex
|
|
|
|
* hierarchies.
|
2011-01-04 20:27:52 +00:00
|
|
|
* When the sheet number is used in annotation,
|
|
|
|
* for each sheet annotation starts from sheet number * 100
|
|
|
|
* ( the first sheet uses 100 to 199, the second 200 to 299 ... )
|
2009-12-02 21:44:03 +00:00
|
|
|
*/
|
2011-01-05 19:16:55 +00:00
|
|
|
void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic,
|
|
|
|
int aSortOption,
|
|
|
|
int aAlgoOption,
|
|
|
|
bool aResetAnnotation,
|
|
|
|
bool aRepairsTimestamps )
|
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
|
|
|
|
2008-12-10 16:49:53 +00:00
|
|
|
wxBusyCursor dummy;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2010-12-31 19:47:39 +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.
|
2011-01-04 20:27:52 +00:00
|
|
|
if( aRepairsTimestamps )
|
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 );
|
2009-07-05 12:09:41 +00:00
|
|
|
DisplayInfoMessage( NULL, msg, 2 );
|
2009-04-25 10:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2010-12-31 19:47:39 +00:00
|
|
|
// Update the screen date.
|
|
|
|
screens.SetDate( GenDate() );
|
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
|
|
|
|
2008-12-10 16:49:53 +00:00
|
|
|
/* Build component list */
|
2011-01-04 20:27:52 +00:00
|
|
|
if( aAnnotateSchematic )
|
2008-02-26 01:07:38 +00:00
|
|
|
{
|
2010-12-31 19:47:39 +00:00
|
|
|
sheets.GetComponents( references );
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
else
|
2010-12-31 19:47:39 +00:00
|
|
|
{
|
2011-01-01 17:28:21 +00:00
|
|
|
GetSheet()->GetComponents( references );
|
2010-12-31 19:47:39 +00:00
|
|
|
}
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2008-02-26 01:07:38 +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 */
|
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:
|
2008-04-21 14:03:20 +00:00
|
|
|
case 0:
|
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
|
|
|
|
2008-04-21 14:03:20 +00:00
|
|
|
case 1:
|
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:
|
|
|
|
case 0:
|
2011-01-01 17:28:21 +00:00
|
|
|
break;
|
|
|
|
|
2011-01-04 20:27:52 +00:00
|
|
|
case 1:
|
2011-01-01 17:28:21 +00:00
|
|
|
useSheetNum = true;
|
|
|
|
break;
|
|
|
|
|
2011-01-04 20:27:52 +00:00
|
|
|
case 2:
|
|
|
|
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
|
2011-01-06 16:55:18 +00:00
|
|
|
references.Annotate( useSheetNum, idStep );
|
2011-01-02 18:56:44 +00:00
|
|
|
references.UpdateAnnotation();
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2011-01-06 16:55:18 +00:00
|
|
|
wxArrayString errors;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-01-06 16:55:18 +00:00
|
|
|
/* Final control (just in case ... )*/
|
|
|
|
if( CheckAnnotate( &errors, !aAnnotateSchematic ) )
|
2011-01-02 18:56:44 +00:00
|
|
|
{
|
2011-01-06 16:55:18 +00:00
|
|
|
wxString msg;
|
2011-01-02 18:56:44 +00:00
|
|
|
|
2011-01-06 16:55:18 +00:00
|
|
|
for( size_t i = 0; i < errors.GetCount(); i++ )
|
|
|
|
msg += errors[i];
|
2011-01-05 19:16:55 +00:00
|
|
|
|
2011-01-06 16:55:18 +00:00
|
|
|
// 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 );
|
2011-01-02 18:56:44 +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:
|
|
|
|
m_CurrentSheet->UpdateAllScreenReferences();
|
|
|
|
SetSheetNumberAndCount();
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2011-01-06 16:55:18 +00:00
|
|
|
DrawPanel->Refresh( true );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-10 16:49:53 +00:00
|
|
|
/**
|
|
|
|
* Function CheckAnnotate
|
2008-12-12 21:30:07 +00:00
|
|
|
* Check errors relatives to annotation:
|
|
|
|
* components not annotated
|
|
|
|
* components having the same reference (duplicates)
|
|
|
|
* for multiple parts per package components :
|
|
|
|
* part number > number of parts
|
|
|
|
* different values between parts
|
2011-01-06 16:55:18 +00:00
|
|
|
* @param aMessageList = a wxArrayString to store messages.
|
2009-07-05 12:09:41 +00:00
|
|
|
* @param aOneSheetOnly : true = search is made only in the current sheet
|
2009-12-02 21:44:03 +00:00
|
|
|
* false = search in whole hierarchy (usual search).
|
|
|
|
* @return errors count
|
2008-12-10 16:49:53 +00:00
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
int SCH_EDIT_FRAME::CheckAnnotate( wxArrayString* aMessageList, bool aOneSheetOnly )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-12-03 06:54:19 +00:00
|
|
|
/* build the screen list */
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_SHEET_LIST SheetList;
|
2011-01-01 17:28:21 +00:00
|
|
|
SCH_REFERENCE_LIST ComponentsList;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2008-12-10 16:49:53 +00:00
|
|
|
/* Build the list of components */
|
2009-07-05 12:09:41 +00:00
|
|
|
if( !aOneSheetOnly )
|
2010-12-31 19:47:39 +00:00
|
|
|
SheetList.GetComponents( ComponentsList );
|
2007-09-20 21:06:49 +00:00
|
|
|
else
|
2010-12-31 19:47:39 +00:00
|
|
|
GetSheet()->GetComponents( ComponentsList );
|
2008-02-26 01:07:38 +00:00
|
|
|
|
2011-01-06 16:55:18 +00:00
|
|
|
return ComponentsList.CheckAnnotation( aMessageList );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|