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 <sch_edit_frame.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 #include <wx_html_report_panel.h>
40 
41 #define KEY_ANNOTATE_SORT_OPTION wxT( "AnnotateSortOption" )
42 #define KEY_ANNOTATE_ALGO_OPTION wxT( "AnnotateAlgoOption" )
43 #define KEY_ANNOTATE_KEEP_OPEN_OPTION wxT( "AnnotateKeepOpenOption" )
44 #define KEY_ANNOTATE_ASK_FOR_CONFIRMATION wxT( "AnnotateRequestConfirmation" )
45 #define KEY_ANNOTATE_MESSAGES_FILTER wxT( "AnnotateFilterMsg" )
46 
47 
48 class wxConfigBase;
49 
55 {
56 public:
57  DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent, const wxString& message );
59 
60 private:
62  wxConfigBase* m_Config;
63 
65  void InitValues();
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 
79  int GetSortOrder();
80 
87  int GetAnnotateAlgo();
88 
89  int GetStartNumber();
90 
92  {
93  return m_cbKeepDlgOpen->GetValue();
94  }
95 
97  {
98  return m_cbAskForConfirmation->GetValue();
99  }
100 };
101 
102 
103 DIALOG_ANNOTATE::DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent, const wxString& message )
104  : DIALOG_ANNOTATE_BASE( parent )
105 {
106  m_Parent = parent;
107 
108  if( !message.IsEmpty() )
109  {
110  m_userMessage->SetLabelText( message );
111  m_userMessage->Show( true );
112 
113  m_rbScope->Enable( false );
114  m_cbKeepDlgOpen->Show( false );
115  }
116 
117  m_MessageWindow->SetLabel( _( "Annotation Messages:" ) );
118 
119  InitValues();
120  Layout();
121 
122  // When all widgets have the size fixed, call FinishDialogSettings
124 }
125 
126 
128 {
133 
136 }
137 
138 
140 {
142  long option;
143 
144  // These are always reset to attempt to keep the user out of trouble...
145  m_rbScope->SetSelection( 0 );
146  m_rbOptions->SetSelection( 0 );
147 
148  m_Config->Read( KEY_ANNOTATE_SORT_OPTION, &option, 0L );
149  switch( option )
150  {
151  default:
152  case 0:
153  m_rbSortBy_X_Position->SetValue( 1 );
154  break;
155 
156  case 1:
157  m_rbSortBy_Y_Position->SetValue( 1 );
158  break;
159  }
160 
161  m_Config->Read( KEY_ANNOTATE_ALGO_OPTION, &option, 0L );
162  switch( option )
163  {
164  default:
165  case 0:
166  m_rbFirstFree->SetValue( 1 );
167  break;
168 
169  case 1:
170  m_rbSheetX100->SetValue( 100 );
171  break;
172 
173  case 2:
174  m_rbSheetX1000->SetValue( 1000 );
175  break;
176  }
177  m_textNumberAfter->SetValue( wxT( "0" ) );
178 
179  m_Config->Read( KEY_ANNOTATE_KEEP_OPEN_OPTION, &option, 0L );
180  m_cbKeepDlgOpen->SetValue( option );
181 
182  m_Config->Read( KEY_ANNOTATE_ASK_FOR_CONFIRMATION, &option, 1L );
183  m_cbAskForConfirmation->SetValue( option );
184 
185  annotate_down_right_bitmap->SetBitmap( KiBitmap( annotate_down_right_xpm ) );
186  annotate_right_down_bitmap->SetBitmap( KiBitmap( annotate_right_down_xpm ) );
187 
188  int severities = m_Config->Read( KEY_ANNOTATE_MESSAGES_FILTER, -1l );
189  m_MessageWindow->SetVisibleSeverities( severities );
190 
191  m_MessageWindow->MsgPanelSetMinSize( wxSize( -1, 160 ) );
192 
193  m_btnApply->SetDefault();
194 }
195 
196 
197 void DIALOG_ANNOTATE::OnApplyClick( wxCommandEvent& event )
198 {
199  int response;
200  wxString message;
201 
202  // Display a message info if we always ask for confirmation
203  // or if a reset of the previous annotation is asked.
204  bool promptUser = GetAnnotateAskForConfirmation();
205 
206  if( GetResetItems() )
207  {
208  if( GetLevel() )
209  message += _( "Clear and annotate all of the symbols on the entire schematic?" );
210  else
211  message += _( "Clear and annotate all of the symbols on the current sheet?" );
212  promptUser = true;
213  }
214  else
215  {
216  if( GetLevel() )
217  message += _( "Annotate only the unannotated symbols on the entire schematic?" );
218  else
219  message += _( "Annotate only the unannotated symbols on the current sheet?" );
220  }
221 
222  message += _( "\n\nThis operation will change the current annotation and cannot be undone." );
223 
224  if( promptUser )
225  {
226  // TODO(hzeller): ideally, this would be a wxMessageDialog that contains
227  // a checkbox asking the 'ask for confirmation' flag for better
228  // discoverability (and it should only show in the 'benign' case, so if
229  // !GetResetItems())
230  response = wxMessageBox( message, wxT( "" ), wxICON_EXCLAMATION | wxOK | wxCANCEL );
231 
232  if( response == wxCANCEL )
233  return;
234  }
235 
237  REPORTER& reporter = m_MessageWindow->Reporter();
238  m_MessageWindow->SetLazyUpdate( true ); // Don't update after each message
239 
242  GetResetItems() , true, GetLockUnits(), reporter );
243 
244  m_MessageWindow->Flush(); // Now update to show all messages
245 
246  m_Parent->GetCanvas()->Refresh();
247 
248  m_btnClear->Enable();
249 
250  // Don't close dialog if there are things the user needs to address
251  if( reporter.HasMessage() )
252  return;
253 
254  if( m_userMessage->IsShown() || !GetAnnotateKeepOpen() )
255  {
256  // Close the dialog by calling the default handler for a wxID_OK event
257  event.SetId( wxID_OK );
258  event.Skip();
259  }
260 }
261 
262 
263 void DIALOG_ANNOTATE::OnClearAnnotationCmpClick( wxCommandEvent& event )
264 {
265  int response;
266  wxString message;
267 
268  if( GetLevel() )
269  message = _( "Clear the existing annotation for the entire schematic?" );
270  else
271  message = _( "Clear the existing annotation for the current sheet?" );
272 
273  message += _( "\n\nThis operation will clear the existing annotation and cannot be undone." );
274  response = wxMessageBox( message, wxT( "" ), wxICON_EXCLAMATION | wxOK | wxCANCEL );
275 
276  if( response == wxCANCEL )
277  return;
278 
279  m_Parent->DeleteAnnotation( GetLevel() ? false : true );
280  m_btnClear->Enable( false );
281 }
282 
283 
285 {
286  return m_rbScope->GetSelection() == 0;
287 }
288 
289 
291 {
292  return m_rbOptions->GetSelection() >= 1;
293 }
294 
295 
297 {
298  return m_rbOptions->GetSelection() == 2;
299 }
300 
301 
303 {
304  if( m_rbSortBy_Y_Position->GetValue() )
305  return 1;
306  else
307  return 0;
308 }
309 
310 
312 {
313  if( m_rbSheetX100->GetValue() )
314  return 1;
315  else if( m_rbSheetX1000->GetValue() )
316  return 2;
317  else
318  return 0;
319 }
320 
321 
323 {
325 }
326 
327 
328 void SCH_EDIT_FRAME::OnAnnotate( wxCommandEvent& event )
329 {
330  if( !m_annotateDialog )
331  {
332  m_annotateDialog = new DIALOG_ANNOTATE( this, wxEmptyString );
333  m_annotateDialog->Show( true );
334  }
335  else // The dialog is just not visible
336  {
337  m_annotateDialog->Show( true );
338  }
339 }
340 
341 
342 int SCH_EDIT_FRAME::ModalAnnotate( const wxString& aMessage )
343 {
344  DIALOG_ANNOTATE dlg( this, aMessage );
345 
346  return dlg.ShowModal();
347 }
void SetVisibleSeverities(int aSeverities)
Set the visible severity filter.
void SetLazyUpdate(bool aLazyUpdate)
Sets the lasy update.
virtual bool HasMessage() const =0
Function HasMessage Returns true if the reporter client is non-empty.
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:339
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:342
wxRadioButton * m_rbSortBy_X_Position
ANNOTATE_ORDER_T
Schematic annotation order options.
#define KEY_ANNOTATE_ASK_FOR_CONFIRMATION
Class DIALOG_ANNOTATE_BASE.
void OnApplyClick(wxCommandEvent &event) override
void AnnotateComponents(bool aAnnotateSchematic, ANNOTATE_ORDER_T aSortOption, ANNOTATE_OPTION_T aAlgoOption, int aStartNumber, bool aResetAnnotation, bool aRepairTimestamps, bool aLockUnits, REPORTER &aReporter)
Annotate the components in the schematic that are not currently annotated.
Definition: annotate.cpp:80
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
#define KEY_ANNOTATE_SORT_OPTION
#define KEY_ANNOTATE_KEEP_OPEN_OPTION
wxRadioButton * m_rbSheetX1000
wxConfigBase * m_Config
Schematic editor (Eeschema) main window.
void InitValues()
Initialises member variables.
SCH_EDIT_FRAME * m_Parent
Class REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:61
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:78
wxStaticBitmap * annotate_right_down_bitmap
DIALOG_ANNOTATE(SCH_EDIT_FRAME *parent, const wxString &message)
void DeleteAnnotation(bool aCurrentSheetOnly)
Clear the current component annotation.
Definition: annotate.cpp:59
wxRadioButton * m_rbSortBy_Y_Position
REPORTER & Reporter()
returns the reporter object that reports to this panel
int ValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application...
Definition: base_units.cpp:369
WX_HTML_REPORT_PANEL * m_MessageWindow
ANNOTATE_OPTION_T
Schematic annotation type options.
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
void OnClearAnnotationCmpClick(wxCommandEvent &event) override
wxRadioButton * m_rbFirstFree
wxCheckBox * m_cbAskForConfirmation
wxStaticText * m_userMessage
void OnAnnotate(wxCommandEvent &event)
wxRadioButton * m_rbSheetX100
int GetAnnotateAlgo()
Function GetAnnotateAlgo.
void Flush()
Forces updating the HTML page, after the report is built in lazy mode
int ModalAnnotate(const wxString &aMessage)
Run a modal version of the Annotate dialog for a specific purpose.
void Clear()
clears the report panel
wxStaticBitmap * annotate_down_right_bitmap
#define KEY_ANNOTATE_ALGO_OPTION
bool GetAnnotateAskForConfirmation()
Class DIALOG_ANNOTATE: a dialog to set/clear reference designators, of a schematic hierarchy...
void MsgPanelSetMinSize(const wxSize &aMinSize)
Set the min size of the area which displays html messages:
int GetSortOrder()
Function GetSortOrder.
void SetLabel(const wxString &aLabel) override
sets the frame label
#define KEY_ANNOTATE_MESSAGES_FILTER