KiCad PCB EDA Suite
annotate.cpp
Go to the documentation of this file.
1 
6 /*
7  * This program source code file is part of KiCad, a free EDA CAD application.
8  *
9  * Copyright (C) 2004-2017 KiCad Developers, see change_log.txt for contributors.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, you may find one here:
23  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
24  * or you may search the http://www.gnu.org website for the version 2 license,
25  * or you may write to the Free Software Foundation, Inc.,
26  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27  */
28 
29 #include <algorithm>
30 
31 #include <fctsys.h>
32 #include <class_drawpanel.h>
33 #include <confirm.h>
34 #include <schframe.h>
35 
36 #include <sch_reference_list.h>
37 #include <class_library.h>
38 
39 void SCH_EDIT_FRAME::DeleteAnnotation( bool aCurrentSheetOnly )
40 {
41  if( aCurrentSheetOnly )
42  {
43  SCH_SCREEN* screen = GetScreen();
44  wxCHECK_RET( screen != NULL, wxT( "Attempt to clear annotation of a NULL screen." ) );
46  }
47  else
48  {
49  SCH_SCREENS ScreenList;
50  ScreenList.ClearAnnotation();
51  }
52 
53  // Update the references for the sheet that is currently being displayed.
55  GetCanvas()->Refresh();
56  OnModify();
57 }
58 
59 
60 void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic,
61  ANNOTATE_ORDER_T aSortOption,
62  ANNOTATE_OPTION_T aAlgoOption,
63  bool aResetAnnotation,
64  bool aRepairTimestamps,
65  bool aLockUnits )
66 {
67  SCH_REFERENCE_LIST references;
68 
69  SCH_SCREENS screens;
70 
71  // Build the sheet list.
72  SCH_SHEET_LIST sheets( g_RootSheet );
73 
74  // Map of locked components
75  SCH_MULTI_UNIT_REFERENCE_MAP lockedComponents;
76 
77  // Test for and replace duplicate time stamps in components and sheets. Duplicate
78  // time stamps can happen with old schematics, schematic conversions, or manual
79  // editing of files.
80  if( aRepairTimestamps )
81  {
82  int count = screens.ReplaceDuplicateTimeStamps();
83 
84  if( count )
85  {
86  wxString msg;
87  msg.Printf( _( "%d duplicate time stamps were found and replaced." ), count );
88  DisplayInfoMessage( NULL, msg );
89  }
90  }
91 
92  // If units must be locked, collect all the sets that must be annotated together.
93  if( aLockUnits )
94  {
95  if( aAnnotateSchematic )
96  {
97  sheets.GetMultiUnitComponents( lockedComponents );
98  }
99  else
100  {
101  m_CurrentSheet->GetMultiUnitComponents( lockedComponents );
102  }
103  }
104 
105  // If it is an annotation for all the components, reset previous annotation.
106  if( aResetAnnotation )
107  DeleteAnnotation( !aAnnotateSchematic );
108 
109  // Set sheet number and number of sheets.
111 
112  // Build component list
113  if( aAnnotateSchematic )
114  {
115  sheets.GetComponents( references );
116  }
117  else
118  {
119  m_CurrentSheet->GetComponents( references );
120  }
121 
122  // Break full components reference in name (prefix) and number:
123  // example: IC1 become IC, and 1
124  references.SplitReferences();
125 
126  switch( aSortOption )
127  {
128  default:
129  case SORT_BY_X_POSITION:
130  references.SortByXCoordinate();
131  break;
132 
133  case SORT_BY_Y_POSITION:
134  references.SortByYCoordinate();
135  break;
136  }
137 
138  bool useSheetNum = false;
139  int idStep = 100;
140 
141  switch( aAlgoOption )
142  {
143  default:
144  case INCREMENTAL_BY_REF:
145  break;
146 
147  case SHEET_NUMBER_X_100:
148  useSheetNum = true;
149  break;
150 
151  case SHEET_NUMBER_X_1000:
152  useSheetNum = true;
153  idStep = 1000;
154  break;
155  }
156 
157  // Recalculate and update reference numbers in schematic
158  references.Annotate( useSheetNum, idStep, lockedComponents );
159  references.UpdateAnnotation();
160 
161  wxArrayString errors;
162 
163  // Final control (just in case ... ).
164  if( CheckAnnotate( &errors, !aAnnotateSchematic ) )
165  {
166  wxString msg;
167 
168  for( size_t i = 0; i < errors.GetCount(); i++ )
169  msg += errors[i];
170 
171  // wxLogWarning is a cheap and dirty way to dump a potentially long list of
172  // strings to a dialog that can be saved to a file. This should be replaced
173  // by a more elegant solution.
174  wxLogWarning( msg );
175  }
176 
177  OnModify();
178 
179  // Update on screen references, that can be modified by previous calculations:
182 
183  m_canvas->Refresh( true );
184 }
185 
186 
187 int SCH_EDIT_FRAME::CheckAnnotate( wxArrayString* aMessageList, bool aOneSheetOnly )
188 {
189  // build the screen list
190  SCH_SHEET_LIST sheetList( g_RootSheet );
191  SCH_REFERENCE_LIST componentsList;
192 
193  // Build the list of components
194  if( !aOneSheetOnly )
195  sheetList.GetComponents( componentsList );
196  else
197  m_CurrentSheet->GetComponents( componentsList );
198 
199  return componentsList.CheckAnnotation( aMessageList );
200 }
void GetComponents(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanComponents=false)
Function GetComponents adds a SCH_REFERENCE() object to aReferences for each component in the sheet...
ANNOTATE_ORDER_T
Schematic annotation order options.
Definition: schframe.h:85
Class SCH_SHEET_LIST.
Annotate using the first free reference number starting at the sheet number * 100.
Definition: schframe.h:96
void SortByYCoordinate()
Function sortByYCoordinate sorts the list of references by Y position.
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Update the board display after modifying it bu a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:325
This file is part of the common library.
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:337
void OnModify()
Must be called after a schematic change in order to set the "modify" flag of the current screen* and ...
Definition: schframe.cpp:773
int CheckAnnotate(wxArrayString *aMessageList, bool aOneSheetOnly)
Check for annotation errors.
Definition: annotate.cpp:187
ANNOTATE_OPTION_T
Schematic annotation type options.
Definition: schframe.h:94
int CheckAnnotation(wxArrayString *aMessageList)
Function CheckAnnotation check for annotations errors.
void UpdateAllScreenReferences()
Function UpdateAllScreenReferences updates the reference and the m_Multi parameter (part selection) f...
Class SCH_REFERENCE_LIST is used to create a flattened list of components because in a complex hierar...
SCH_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Definition: schframe.cpp:532
SCH_SHEET_PATH * m_CurrentSheet
which sheet we are presently working on.
Definition: schframe.h:121
void UpdateAnnotation()
function UpdateAnnotation Updates the reference components for the schematic project (or the current ...
Annotate by X position from left to right.
Definition: schframe.h:86
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
void SortByXCoordinate()
Function sortByXCoordinate sorts the list of references by X position.
void DeleteAnnotation(bool aCurrentSheetOnly)
Clear the current component annotation.
Definition: annotate.cpp:39
void Annotate(bool aUseSheetNum, int aSheetIntervalId, SCH_MULTI_UNIT_REFERENCE_MAP aLockedUnitMap)
Function Annotate set the reference designators in the list that have not been annotated.
Annotate by Y position from top to bottom.
Definition: schframe.h:87
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString aExtraInfo)
Function DisplayInfoMessage displays an informational message box with aMessage.
Definition: confirm.cpp:104
Annotate incrementally using the first free reference number.
Definition: schframe.h:95
std::map< wxString, SCH_REFERENCE_LIST > SCH_MULTI_UNIT_REFERENCE_MAP
Type SCH_MULTI_UNIT_REFERENCE_MAP is used to create a map of reference designators for multi-unit par...
void GetMultiUnitComponents(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, bool aIncludePowerSymbols=true)
Function GetMultiUnitComponents adds a SCH_REFERENCE_LIST object to aRefList for each same-reference ...
Annotate using the first free reference number starting at the sheet number * 1000.
Definition: schframe.h:98
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:93
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
Definition: schframe.cpp:497
void ClearAnnotation()
Clear the annotation for all components in the hierarchy.
void SplitReferences()
Function SplitReferences attempts to split all reference designators into a name (U) and number (1)...
void ClearAnnotation(SCH_SHEET_PATH *aSheetPath)
Clear the annotation for the components in aSheetPath on the screen.
Definition: sch_screen.cpp:688
int ReplaceDuplicateTimeStamps()
Test all sheet and component objects in the schematic for duplicate time stamps and replaces them as ...
void GetMultiUnitComponents(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, bool aIncludePowerSymbols=true)
Function GetMultiUnitComponents adds a SCH_REFERENCE_LIST object to aRefList for each same-reference ...
Definition for part library class.
void GetComponents(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanComponents=false)
Function GetComponents adds a SCH_REFERENCE() object to aReferences for each component in the list of...
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
void AnnotateComponents(bool aAnnotateSchematic, ANNOTATE_ORDER_T aSortOption, ANNOTATE_OPTION_T aAlgoOption, bool aResetAnnotation, bool aRepairTimestamps, bool aLockUnits)
Annotate the components in the schematic that are not currently annotated.
Definition: annotate.cpp:60