KiCad PCB EDA Suite
dialog_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) 1992-2017 jean-pierre Charras jp.charras at wanadoo.fr
10  * Copyright (C) 1992-2017 Kicad Developers, see AUTHORS.txt for contributors.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, you may find one here:
24  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
25  * or you may search the http://www.gnu.org website for the version 2 license,
26  * or you may write to the Free Software Foundation, Inc.,
27  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
28  */
29 
30 
31 #include <fctsys.h>
32 #include <schframe.h>
33 #include <class_drawpanel.h>
34 #include <bitmaps.h>
35 
36 #include <invoke_sch_dialog.h>
37 #include <dialog_annotate_base.h>
38 #include <kiface_i.h>
39 
40 #define KEY_ANNOTATE_SORT_OPTION wxT( "AnnotateSortOption" )
41 #define KEY_ANNOTATE_ALGO_OPTION wxT( "AnnotateAlgoOption" )
42 #define KEY_ANNOTATE_KEEP_OPEN_OPTION wxT( "AnnotateKeepOpenOption" )
43 #define KEY_ANNOTATE_ASK_FOR_CONFIRMATION wxT( "AnnotateRequestConfirmation" )
44 
45 
46 class wxConfigBase;
47 
53 {
54 public:
55  DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent, wxString message );
56 
57 
58 private:
60  wxConfigBase* m_Config;
61 
63  void InitValues();
64  void OnCancelClick( wxCommandEvent& event ) override;
65  void OnClearAnnotationCmpClick( wxCommandEvent& event ) override;
66  void OnApplyClick( wxCommandEvent& event ) override;
67 
68  // User functions:
69  bool GetLevel();
70  bool GetResetItems();
71  bool GetLockUnits();
72 
79  int GetSortOrder();
80 
87  int GetAnnotateAlgo();
88 
90  {
91  return m_cbKeepDlgOpen->GetValue();
92  }
93 
95  {
96  return m_cbAskForConfirmation->GetValue();
97  }
98 };
99 
100 
102  : DIALOG_ANNOTATE_BASE( parent )
103 {
104  m_Parent = parent;
105  m_userMessage->SetLabelText( message );
106  m_userMessage->Show( !message.empty() );
107 
108  InitValues();
109  Layout();
110  GetSizer()->SetSizeHints( this );
111  Centre();
112 }
113 
114 
116 {
118 
119  if( m_Config )
120  {
121  long option;
122 
123  m_Config->Read( KEY_ANNOTATE_SORT_OPTION, &option, 0L );
124  switch( option )
125  {
126  default:
127  case 0:
128  m_rbSortBy_X_Position->SetValue( 1 );
129  break;
130 
131  case 1:
132  m_rbSortBy_Y_Position->SetValue( 1 );
133  break;
134 
135  case 2:
136  m_rbUseIncremental->SetValue( 1 );
137  break;
138  }
139 
140  m_Config->Read( KEY_ANNOTATE_ALGO_OPTION, &option, 0L );
141  switch( option )
142  {
143  default:
144  case 0:
145  m_rbUseIncremental->SetValue( 1 );
146  break;
147 
148  case 1:
149  m_rbUseSheetNum->SetValue( 1 );
150  break;
151 
152  case 2:
153  m_rbStartSheetNumLarge->SetValue( 1 );
154  break;
155  }
156 
157 
158  m_Config->Read( KEY_ANNOTATE_KEEP_OPEN_OPTION, &option, 0L );
159  m_cbKeepDlgOpen->SetValue( option );
160 
161 
162  m_Config->Read( KEY_ANNOTATE_ASK_FOR_CONFIRMATION, &option, 1L );
163  m_cbAskForConfirmation->SetValue( option );
164  }
165 
166  annotate_down_right_bitmap->SetBitmap( KiBitmap( annotate_down_right_xpm ) );
167  annotate_right_down_bitmap->SetBitmap( KiBitmap( annotate_right_down_xpm ) );
168 
169  m_btnApply->SetDefault();
170 }
171 
172 
173 void DIALOG_ANNOTATE::OnApplyClick( wxCommandEvent& event )
174 {
175  int response;
176  wxString message;
177 
178  if( m_Config )
179  {
184  }
185 
186  // Display a message info if we always ask for confirmation
187  // or if a reset of the previous annotation is asked.
188  bool promptUser = GetAnnotateAskForConfirmation();
189 
190  if( GetResetItems() )
191  {
192  if( GetLevel() )
193  message += _( "Clear and annotate all of the components on the entire schematic?" );
194  else
195  message += _( "Clear and annotate all of the components on the current sheet?" );
196  promptUser = true;
197  }
198  else
199  {
200  if( GetLevel() )
201  message += _( "Annotate only the unannotated components on the entire schematic?" );
202  else
203  message += _( "Annotate only the unannotated components on the current sheet?" );
204  }
205 
206  message += _( "\n\nThis operation will change the current annotation and cannot be undone." );
207 
208  if( promptUser )
209  {
210  // TODO(hzeller): ideally, this would be a wxMessageDialog that contains
211  // a checkbox asking the 'ask for confirmation' flag for better
212  // discoverability (and it should only show in the 'benign' case, so if
213  // !GetResetItems())
214  response = wxMessageBox( message, wxT( "" ), wxICON_EXCLAMATION | wxOK | wxCANCEL );
215 
216  if( response == wxCANCEL )
217  return;
218  }
219 
222  GetResetItems() , true, GetLockUnits() );
223  m_Parent->GetCanvas()->Refresh();
224 
225  m_btnClear->Enable();
226 
227  if( !GetAnnotateKeepOpen() )
228  {
229  if( IsModal() )
230  EndModal( wxID_OK );
231  else
232  {
233  SetReturnCode( wxID_OK );
234  this->Show( false );
235  }
236  }
237 }
238 
239 
240 void DIALOG_ANNOTATE::OnClearAnnotationCmpClick( wxCommandEvent& event )
241 {
242  int response;
243  wxString message;
244 
245  if( GetLevel() )
246  message = _( "Clear the existing annotation for the entire schematic?" );
247  else
248  message = _( "Clear the existing annotation for the current sheet?" );
249 
250  message += _( "\n\nThis operation will clear the existing annotation and cannot be undone." );
251  response = wxMessageBox( message, wxT( "" ), wxICON_EXCLAMATION | wxOK | wxCANCEL );
252 
253  if( response == wxCANCEL )
254  return;
255 
256  m_Parent->DeleteAnnotation( GetLevel() ? false : true );
257  m_btnClear->Enable( false );
258 }
259 
260 
261 void DIALOG_ANNOTATE::OnCancelClick( wxCommandEvent& event )
262 {
263  if( IsModal() )
264  EndModal( wxID_CANCEL );
265  else
266  {
267  SetReturnCode( wxID_CANCEL );
268  this->Show( false );
269  }
270 }
271 
272 
274 {
275  return m_rbEntireSchematic->GetValue();
276 }
277 
278 
280 {
281  return m_rbResetAnnotation->GetValue() || m_rbResetButLock->GetValue();
282 }
283 
285 {
286  return m_rbResetButLock->GetValue();
287 }
288 
290 {
291  if( m_rbSortBy_X_Position->GetValue() )
292  return 0;
293 
294  if( m_rbSortBy_Y_Position->GetValue() )
295  return 1;
296 
297  return 2;
298 }
299 
300 
302 {
303  if( m_rbUseIncremental->GetValue() )
304  return 0;
305 
306  if( m_rbUseSheetNum->GetValue() )
307  return 1;
308 
309  return 2;
310 }
311 
312 
313 int InvokeDialogAnnotate( SCH_EDIT_FRAME* aCaller, wxString message )
314 {
315  DIALOG_ANNOTATE dlg( aCaller, message );
316 
317  return dlg.ShowModal();
318 }
ANNOTATE_ORDER_T
Schematic annotation order options.
Definition: schframe.h:84
wxRadioButton * m_rbUseIncremental
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
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:304
wxRadioButton * m_rbSortBy_X_Position
#define KEY_ANNOTATE_ASK_FOR_CONFIRMATION
Class DIALOG_ANNOTATE_BASE.
void OnApplyClick(wxCommandEvent &event) override
wxRadioButton * m_rbUseSheetNum
#define KEY_ANNOTATE_SORT_OPTION
#define KEY_ANNOTATE_KEEP_OPEN_OPTION
ANNOTATE_OPTION_T
Schematic annotation type options.
Definition: schframe.h:93
wxConfigBase * m_Config
Schematic editor (Eeschema) main window.
Definition: schframe.h:117
void InitValues()
Initialises member variables.
SCH_EDIT_FRAME * m_Parent
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Definition: kicad.cpp:52
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Function KiBitmap constructs a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:36
wxStaticBitmap * annotate_right_down_bitmap
void DeleteAnnotation(bool aCurrentSheetOnly)
Function DeleteAnnotation clears the current component annotation.
Definition: annotate.cpp:39
wxRadioButton * m_rbSortBy_Y_Position
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
int InvokeDialogAnnotate(SCH_EDIT_FRAME *aCaller, wxString message)
Create and show DIALOG_ANNOTATE and return whatever DIALOG_ANNOTATE::ShowModal() returns.
wxRadioButton * m_rbResetAnnotation
void OnCancelClick(wxCommandEvent &event) override
void OnClearAnnotationCmpClick(wxCommandEvent &event) override
bool Show(bool show) override
wxRadioButton * m_rbEntireSchematic
wxCheckBox * m_cbAskForConfirmation
DIALOG_ANNOTATE(SCH_EDIT_FRAME *parent, wxString message)
wxStaticText * m_userMessage
int GetAnnotateAlgo()
Function GetAnnotateAlgo.
wxStaticBitmap * annotate_down_right_bitmap
#define KEY_ANNOTATE_ALGO_OPTION
bool GetAnnotateAskForConfirmation()
wxRadioButton * m_rbStartSheetNumLarge
Class DIALOG_ANNOTATE: a dialog to set/clear reference designators, of a schematic hierarchy...
int GetSortOrder()
Function GetSortOrder.
wxRadioButton * m_rbResetButLock
void AnnotateComponents(bool aAnnotateSchematic, ANNOTATE_ORDER_T aSortOption, ANNOTATE_OPTION_T aAlgoOption, bool aResetAnnotation, bool aRepairTimestamps, bool aLockUnits)
Function AnnotateComponents.
Definition: annotate.cpp:60