1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
/**
* @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 <reporter.h>
#include <sch_edit_frame.h>
#include <sch_reference_list.h>
#include <class_library.h>
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;
}
}
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,
int aStartNumber,
bool aResetAnnotation,
bool aRepairTimestamps,
bool aLockUnits,
REPORTER& aReporter )
{
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;
// Map of previous annotation for building info messages
std::map<timestamp_t, wxString> previousAnnotation;
// 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 );
aReporter.ReportTail( msg, REPORTER::RPT_WARNING );
}
}
// 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 );
}
}
// Store previous annotations for building info messages
mapExistingAnnotation( previousAnnotation );
// 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, aStartNumber, lockedComponents );
references.UpdateAnnotation();
for( size_t i = 0; i < references.GetCount(); i++ )
{
SCH_COMPONENT* comp = references[ i ].GetComp();
wxString prevRef = previousAnnotation[ comp->GetTimeStamp() ];
wxString newRef = comp->GetField( REFERENCE )->GetFullyQualifiedText();
wxString msg;
if( prevRef.Length() )
{
if( newRef == prevRef )
continue;
if( comp->GetUnitCount() > 1 )
msg.Printf( _( "Updated %s (unit %s) from %s to %s" ),
GetChars( comp->GetField( VALUE )->GetShownText() ),
LIB_PART::SubReference( comp->GetUnit(), false ),
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 )
msg.Printf( _( "Annotated %s (unit %s) as %s" ),
GetChars( comp->GetField( VALUE )->GetShownText() ),
LIB_PART::SubReference( comp->GetUnit(), false ),
GetChars( newRef ) );
else
msg.Printf( _( "Annotated %s as %s" ),
GetChars( comp->GetField( VALUE )->GetShownText() ),
GetChars( newRef ) );
}
aReporter.Report( msg, REPORTER::RPT_ACTION );
}
// Final control (just in case ... ).
if( !CheckAnnotate( aReporter, !aAnnotateSchematic ) )
aReporter.ReportTail( _( "Annotation complete." ), REPORTER::RPT_ACTION );
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( REPORTER& aReporter, 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( aReporter );
}
|