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-2012 jean-pierre Charras <jean-pierre.charras@ujf-grenoble.fr>
10  * Copyright (C) 1992-2012 Kicad Developers, see change_log.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 
48 namespace {
49 
53 class DIALOG_ANNOTATE: public DIALOG_ANNOTATE_BASE
54 {
55 public:
56  DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent, wxString message );
57 
58 
59 private:
60  SCH_EDIT_FRAME* m_Parent;
61  wxConfigBase* m_Config;
62 
64  void InitValues();
65  void OnCancelClick( wxCommandEvent& event ) override;
66  void OnClearAnnotationCmpClick( wxCommandEvent& event ) override;
67  void OnApplyClick( wxCommandEvent& event ) override;
68 
69  // User functions:
70  bool GetLevel();
71  bool GetResetItems();
72  bool GetLockUnits();
73 
80  int GetSortOrder();
81 
88  int GetAnnotateAlgo();
89 
90  bool GetAnnotateKeepOpen()
91  {
92  return m_cbKeepDlgOpen->GetValue();
93  }
94 
95  bool GetAnnotateAskForConfirmation()
96  {
97  return m_cbAskForConfirmation->GetValue();
98  }
99 };
100 
101 } // anonymous namespace
102 
103 
104 DIALOG_ANNOTATE::DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent, wxString message )
105  : DIALOG_ANNOTATE_BASE( parent )
106 {
107  m_Parent = parent;
108  m_userMessage->SetLabelText( message );
109  m_userMessage->Show( !message.empty() );
110 
111  InitValues();
112  Layout();
113  GetSizer()->SetSizeHints( this );
114  Centre();
115 }
116 
117 
118 void DIALOG_ANNOTATE::InitValues()
119 {
120  m_Config = Kiface().KifaceSettings();
121 
122  if( m_Config )
123  {
124  long option;
125 
126  m_Config->Read( KEY_ANNOTATE_SORT_OPTION, &option, 0L );
127  switch( option )
128  {
129  default:
130  case 0:
131  m_rbSortBy_X_Position->SetValue( 1 );
132  break;
133 
134  case 1:
135  m_rbSortBy_Y_Position->SetValue( 1 );
136  break;
137 
138  case 2:
139  m_rbUseIncremental->SetValue( 1 );
140  break;
141  }
142 
143  m_Config->Read( KEY_ANNOTATE_ALGO_OPTION, &option, 0L );
144  switch( option )
145  {
146  default:
147  case 0:
148  m_rbUseIncremental->SetValue( 1 );
149  break;
150 
151  case 1:
152  m_rbUseSheetNum->SetValue( 1 );
153  break;
154 
155  case 2:
156  m_rbStartSheetNumLarge->SetValue( 1 );
157  break;
158  }
159 
160 
161  m_Config->Read( KEY_ANNOTATE_KEEP_OPEN_OPTION, &option, 0L );
162  m_cbKeepDlgOpen->SetValue( option );
163 
164 
165  m_Config->Read( KEY_ANNOTATE_ASK_FOR_CONFIRMATION, &option, 1L );
166  m_cbAskForConfirmation->SetValue( option );
167  }
168 
169  annotate_down_right_bitmap->SetBitmap( KiBitmap( annotate_down_right_xpm ) );
170  annotate_right_down_bitmap->SetBitmap( KiBitmap( annotate_right_down_xpm ) );
171 
172  m_btnApply->SetDefault();
173 }
174 
175 
176 void DIALOG_ANNOTATE::OnApplyClick( wxCommandEvent& event )
177 {
178  int response;
179  wxString message;
180 
181  if( m_Config )
182  {
183  m_Config->Write( KEY_ANNOTATE_SORT_OPTION, GetSortOrder() );
184  m_Config->Write( KEY_ANNOTATE_ALGO_OPTION, GetAnnotateAlgo() );
185  m_Config->Write( KEY_ANNOTATE_KEEP_OPEN_OPTION, GetAnnotateKeepOpen() );
186  m_Config->Write( KEY_ANNOTATE_ASK_FOR_CONFIRMATION, GetAnnotateAskForConfirmation() );
187  }
188 
189  // Display a message info if we always ask for confirmation
190  // or if a reset of the previous annotation is asked.
191  bool promptUser = GetAnnotateAskForConfirmation();
192 
193  if( GetResetItems() )
194  {
195  if( GetLevel() )
196  message += _( "Clear and annotate all of the components on the entire schematic?" );
197  else
198  message += _( "Clear and annotate all of the components on the current sheet?" );
199  promptUser = true;
200  }
201  else
202  {
203  if( GetLevel() )
204  message += _( "Annotate only the unannotated components on the entire schematic?" );
205  else
206  message += _( "Annotate only the unannotated components on the current sheet?" );
207  }
208 
209  message += _( "\n\nThis operation will change the current annotation and cannot be undone." );
210 
211  if( promptUser )
212  {
213  // TODO(hzeller): ideally, this would be a wxMessageDialog that contains
214  // a checkbox asking the 'ask for confirmation' flag for better
215  // discoverability (and it should only show in the 'benign' case, so if
216  // !GetResetItems())
217  response = wxMessageBox( message, wxT( "" ), wxICON_EXCLAMATION | wxOK | wxCANCEL );
218 
219  if( response == wxCANCEL )
220  return;
221  }
222 
223  m_Parent->AnnotateComponents( GetLevel(), (ANNOTATE_ORDER_T) GetSortOrder(),
224  (ANNOTATE_OPTION_T) GetAnnotateAlgo(),
225  GetResetItems() , true, GetLockUnits() );
226  m_Parent->GetCanvas()->Refresh();
227 
228  m_btnClear->Enable();
229 
230  if( !GetAnnotateKeepOpen() )
231  {
232  if( IsModal() )
233  EndModal( wxID_OK );
234  else
235  {
236  SetReturnCode( wxID_OK );
237  this->Show( false );
238  }
239  }
240 }
241 
242 
243 void DIALOG_ANNOTATE::OnClearAnnotationCmpClick( wxCommandEvent& event )
244 {
245  int response;
246  wxString message;
247 
248  if( GetLevel() )
249  message = _( "Clear the existing annotation for the entire schematic?" );
250  else
251  message = _( "Clear the existing annotation for the current sheet?" );
252 
253  message += _( "\n\nThis operation will clear the existing annotation and cannot be undone." );
254  response = wxMessageBox( message, wxT( "" ), wxICON_EXCLAMATION | wxOK | wxCANCEL );
255 
256  if( response == wxCANCEL )
257  return;
258 
259  m_Parent->DeleteAnnotation( GetLevel() ? false : true );
260  m_btnClear->Enable( false );
261 }
262 
263 
264 void DIALOG_ANNOTATE::OnCancelClick( wxCommandEvent& event )
265 {
266  if( IsModal() )
267  EndModal( wxID_CANCEL );
268  else
269  {
270  SetReturnCode( wxID_CANCEL );
271  this->Show( false );
272  }
273 }
274 
275 
276 bool DIALOG_ANNOTATE::GetLevel()
277 {
278  return m_rbEntireSchematic->GetValue();
279 }
280 
281 
282 bool DIALOG_ANNOTATE::GetResetItems()
283 {
284  return m_rbResetAnnotation->GetValue() || m_rbResetButLock->GetValue();
285 }
286 
287 bool DIALOG_ANNOTATE::GetLockUnits()
288 {
289  return m_rbResetButLock->GetValue();
290 }
291 
292 int DIALOG_ANNOTATE::GetSortOrder()
293 {
294  if( m_rbSortBy_X_Position->GetValue() )
295  return 0;
296 
297  if( m_rbSortBy_Y_Position->GetValue() )
298  return 1;
299 
300  return 2;
301 }
302 
303 
304 int DIALOG_ANNOTATE::GetAnnotateAlgo()
305 {
306  if( m_rbUseIncremental->GetValue() )
307  return 0;
308 
309  if( m_rbUseSheetNum->GetValue() )
310  return 1;
311 
312  return 2;
313 }
314 
315 
316 int InvokeDialogAnnotate( SCH_EDIT_FRAME* aCaller, wxString message )
317 {
318  DIALOG_ANNOTATE dlg( aCaller, message );
319 
320  return dlg.ShowModal();
321 }
ANNOTATE_ORDER_T
Schematic annotation order options.
Definition: schframe.h:84
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Definition: draw_panel.cpp:326
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:299
#define KEY_ANNOTATE_ASK_FOR_CONFIRMATION
Class DIALOG_ANNOTATE_BASE.
#define KEY_ANNOTATE_SORT_OPTION
#define KEY_ANNOTATE_KEEP_OPEN_OPTION
ANNOTATE_OPTION_T
Schematic annotation type options.
Definition: schframe.h:93
Schematic editor (Eeschema) main window.
Definition: schframe.h:117
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
void DeleteAnnotation(bool aCurrentSheetOnly)
Function DeleteAnnotation clears the current component annotation.
Definition: annotate.cpp:39
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:101
int InvokeDialogAnnotate(SCH_EDIT_FRAME *aCaller, wxString message)
Create and show DIALOG_ANNOTATE and return whatever DIALOG_ANNOTATE::ShowModal() returns.
#define KEY_ANNOTATE_ALGO_OPTION
void AnnotateComponents(bool aAnnotateSchematic, ANNOTATE_ORDER_T aSortOption, ANNOTATE_OPTION_T aAlgoOption, bool aResetAnnotation, bool aRepairTimestamps, bool aLockUnits)
Function AnnotateComponents.
Definition: annotate.cpp:60