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_SKIP_CONFIRMATION wxT( "AnnotateSkipConfirmation" )
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_cbSkipConfirmation->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_SKIP_CONFIRMATION, &option, 0L );
183  m_cbSkipConfirmation->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  // Ask for confirmation of destructive actions unless the user asked us not to.
204  {
205  if( GetLevel() )
206  message += _( "Clear and annotate all of the symbols on the entire schematic?" );
207  else
208  message += _( "Clear and annotate all of the symbols on the current sheet?" );
209 
210  message += _( "\n\nThis operation will change the current annotation and cannot be undone." );
211 
212  response = wxMessageBox( message, wxT( "" ), wxICON_EXCLAMATION | wxOK | wxCANCEL );
213 
214  if( response == wxCANCEL )
215  return;
216  }
217 
219  REPORTER& reporter = m_MessageWindow->Reporter();
220  m_MessageWindow->SetLazyUpdate( true ); // Don't update after each message
221 
224  GetResetItems() , true, GetLockUnits(), reporter );
225 
226  m_MessageWindow->Flush( true ); // Now update to show all messages
227 
228  m_Parent->GetCanvas()->Refresh();
229 
230  m_btnClear->Enable();
231 
232  // Don't close dialog if there are things the user needs to address
233  if( reporter.HasMessage() )
234  return;
235 
236  if( m_userMessage->IsShown() || !GetAnnotateKeepOpen() )
237  {
238  // Close the dialog by calling the default handler for a wxID_OK event
239  event.SetId( wxID_OK );
240  event.Skip();
241  }
242 }
243 
244 
245 void DIALOG_ANNOTATE::OnClearAnnotationCmpClick( wxCommandEvent& event )
246 {
247  int response;
248  wxString message;
249 
251  {
252  if( GetLevel() )
253  message = _( "Clear the existing annotation for the entire schematic?" );
254  else
255  message = _( "Clear the existing annotation for the current sheet?" );
256 
257  message += _( "\n\nThis operation will clear the existing annotation and cannot be undone." );
258  response = wxMessageBox( message, wxT( "" ), wxICON_EXCLAMATION | wxOK | wxCANCEL );
259 
260  if( response == wxCANCEL )
261  return;
262  }
263 
264  m_Parent->DeleteAnnotation( GetLevel() ? false : true );
265  m_btnClear->Enable( false );
266 }
267 
268 
270 {
271  return m_rbScope->GetSelection() == 0;
272 }
273 
274 
276 {
277  return m_rbOptions->GetSelection() >= 1;
278 }
279 
280 
282 {
283  return m_rbOptions->GetSelection() == 2;
284 }
285 
286 
288 {
289  if( m_rbSortBy_Y_Position->GetValue() )
290  return 1;
291  else
292  return 0;
293 }
294 
295 
297 {
298  if( m_rbSheetX100->GetValue() )
299  return 1;
300  else if( m_rbSheetX1000->GetValue() )
301  return 2;
302  else
303  return 0;
304 }
305 
306 
308 {
310 }
311 
312 
313 void SCH_EDIT_FRAME::OnAnnotate( wxCommandEvent& event )
314 {
315  if( !m_annotateDialog )
316  {
317  m_annotateDialog = new DIALOG_ANNOTATE( this, wxEmptyString );
318  m_annotateDialog->Show( true );
319  }
320  else // The dialog is just not visible
321  {
322  m_annotateDialog->Show( true );
323  }
324 }
325 
326 
327 int SCH_EDIT_FRAME::ModalAnnotate( const wxString& aMessage )
328 {
329  DIALOG_ANNOTATE dlg( this, aMessage );
330 
331  return dlg.ShowModal();
332 }
void SetVisibleSeverities(int aSeverities)
Set the visible severity filter.
wxCheckBox * m_cbSkipConfirmation
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 by a python script (note: it is automatically called by a...
Definition: draw_panel.cpp:338
EDA_DRAW_PANEL * GetCanvas()
Definition: draw_frame.h:359
wxRadioButton * m_rbSortBy_X_Position
ANNOTATE_ORDER_T
Schematic annotation order options.
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 Flush(bool aSort=false)
Forces updating the HTML page, after the report is built in lazy mode If aSort = true, the body messages will be ordered by severity
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:370
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
wxStaticText * m_userMessage
void OnAnnotate(wxCommandEvent &event)
wxRadioButton * m_rbSheetX100
int GetAnnotateAlgo()
Function GetAnnotateAlgo.
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
#define KEY_ANNOTATE_SKIP_CONFIRMATION
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
bool GetAnnotateSkipConfirmation()
#define KEY_ANNOTATE_MESSAGES_FILTER