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 <sch_draw_panel.h>
34 #include <bitmaps.h>
35 #include <confirm.h>
36 
37 #include <invoke_sch_dialog.h>
38 #include <dialog_annotate_base.h>
39 #include <kiface_i.h>
40 #include <wx_html_report_panel.h>
41 
42 #define KEY_ANNOTATE_SORT_OPTION wxT( "AnnotateSortOption" )
43 #define KEY_ANNOTATE_ALGO_OPTION wxT( "AnnotateAlgoOption" )
44 #define KEY_ANNOTATE_MESSAGES_FILTER wxT( "AnnotateFilterMsg" )
45 
46 // A window name for the annotate dialog to retrieve is if not destroyed
47 #define DLG_WINDOW_NAME "DialogAnnotateWindowName"
48 
49 
50 class wxConfigBase;
51 
57 {
58 public:
59  DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent, const wxString& message );
61 
62 private:
64  wxConfigBase* m_Config;
65 
67  void InitValues();
68  void OnClearAnnotationCmpClick( wxCommandEvent& event ) override;
69  void OnCloseClick( wxCommandEvent& event ) override;
70  void OnClose( wxCloseEvent& event ) override;
71  void OnApplyClick( wxCommandEvent& event ) override;
72 
73  // User functions:
74  bool GetLevel();
75  bool GetResetItems();
76  bool GetLockUnits();
77 
83  int GetSortOrder();
84 
91  int GetAnnotateAlgo();
92 
93  int GetStartNumber();
94 };
95 
96 
97 DIALOG_ANNOTATE::DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent, const wxString& message )
98  : DIALOG_ANNOTATE_BASE( parent )
99 {
100  SetName( DLG_WINDOW_NAME );
101  m_Parent = parent;
102 
103  if( !message.IsEmpty() )
104  {
105  m_userMessage->SetLabelText( message );
106  m_userMessage->Show( true );
107 
108  m_rbScope->Enable( false );
109  }
110 
111  m_MessageWindow->SetLabel( _( "Annotation Messages:" ) );
112 
113  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
114  // that requires us to correct the button labels here.
115  m_sdbSizer1OK->SetLabel( _( "Annotate" ) );
116  m_sdbSizer1Cancel->SetLabel( _( "Close" ) );
117  m_sdbSizer1->Layout();
118 
119  m_sdbSizer1OK->SetDefault();
120 
121  InitValues();
122  Layout();
123 
124  // When all widgets have the size fixed, call FinishDialogSettings
126 }
127 
128 
130 {
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  annotate_down_right_bitmap->SetBitmap( KiBitmap( annotate_down_right_xpm ) );
180  annotate_right_down_bitmap->SetBitmap( KiBitmap( annotate_right_down_xpm ) );
181 
182  int severities = m_Config->Read( KEY_ANNOTATE_MESSAGES_FILTER, -1l );
183  m_MessageWindow->SetVisibleSeverities( severities );
184 
185  m_MessageWindow->MsgPanelSetMinSize( wxSize( -1, 160 ) );
186 }
187 
188 
189 // This is a modeless dialog so we have to handle these ourselves.
190 void DIALOG_ANNOTATE::OnCloseClick( wxCommandEvent& event )
191 {
192  Close();
193 }
194 
195 
196 void DIALOG_ANNOTATE::OnClose( wxCloseEvent& event )
197 {
198  Destroy();
199 }
200 
201 
202 void DIALOG_ANNOTATE::OnApplyClick( wxCommandEvent& event )
203 {
204  wxString message;
205 
206  // Ask for confirmation of destructive actions.
207  if( GetResetItems() )
208  {
209  if( GetLevel() )
210  message += _( "Clear and annotate all of the symbols on the entire schematic?" );
211  else
212  message += _( "Clear and annotate all of the symbols on the current sheet?" );
213 
214  message += _( "\n\nThis operation will change the current annotation and cannot be undone." );
215 
216  KIDIALOG dlg( this, message, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
217  dlg.SetOKLabel( _( "Clear and Annotate" ) );
218  dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
219 
220  if( dlg.ShowModal() == wxCANCEL )
221  return;
222  }
223 
225  REPORTER& reporter = m_MessageWindow->Reporter();
226  m_MessageWindow->SetLazyUpdate( true ); // Don't update after each message
227 
230  GetResetItems() , true, GetLockUnits(), reporter );
231 
232  m_MessageWindow->Flush( true ); // Now update to show all messages
233 
234  m_Parent->GetCanvas()->Refresh();
235 
236  m_btnClear->Enable();
237 
238  // Don't close dialog if there are things the user needs to address
239  if( reporter.HasMessage() )
240  return;
241 
242  if( m_userMessage->IsShown() )
243  {
244  // Close the dialog by calling the default handler for a wxID_OK event
245  event.SetId( wxID_OK );
246  event.Skip();
247  }
248 }
249 
250 
251 void DIALOG_ANNOTATE::OnClearAnnotationCmpClick( wxCommandEvent& event )
252 {
253  wxString message;
254 
255  if( GetLevel() )
256  message = _( "Clear the existing annotation for the entire schematic?" );
257  else
258  message = _( "Clear the existing annotation for the current sheet?" );
259 
260  message += _( "\n\nThis operation will clear the existing annotation and cannot be undone." );
261 
262  KIDIALOG dlg( this, message, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
263  dlg.SetOKLabel( _( "Clear Annotation" ) );
264  dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
265 
266  if( dlg.ShowModal() == wxID_CANCEL )
267  return;
268 
270  m_btnClear->Enable( false );
271 }
272 
273 
275 {
276  return m_rbScope->GetSelection() == 0;
277 }
278 
279 
281 {
282  return m_rbOptions->GetSelection() >= 1;
283 }
284 
285 
287 {
288  return m_rbOptions->GetSelection() == 2;
289 }
290 
291 
293 {
294  if( m_rbSortBy_Y_Position->GetValue() )
295  return 1;
296  else
297  return 0;
298 }
299 
300 
302 {
303  if( m_rbSheetX100->GetValue() )
304  return 1;
305  else if( m_rbSheetX1000->GetValue() )
306  return 2;
307  else
308  return 0;
309 }
310 
311 
313 {
315 }
316 
317 
318 void SCH_EDIT_FRAME::OnAnnotate( wxCommandEvent& event )
319 {
320  DIALOG_ANNOTATE* dlg = static_cast<DIALOG_ANNOTATE*> ( wxWindow::FindWindowByName( DLG_WINDOW_NAME ) );
321 
322  if( !dlg )
323  {
324  dlg = new DIALOG_ANNOTATE( this, wxEmptyString );
325  dlg->Show( true );
326  }
327  else // The dialog is already opened, perhaps not visible
328  {
329  dlg->Show( true );
330  }
331 }
332 
333 
334 int SCH_EDIT_FRAME::ModalAnnotate( const wxString& aMessage )
335 {
336  DIALOG_ANNOTATE dlg( this, aMessage );
337 
338  return dlg.ShowModal();
339 }
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.
void DoNotShowCheckbox(wxString file, int line)
Shows the &#39;do not show again&#39; checkbox
Definition: confirm.cpp:60
Helper class to create more flexible dialogs, including &#39;do not show again&#39; checkbox handling...
Definition: confirm.h:44
This file is part of the common library.
wxRadioButton * m_rbSortBy_X_Position
ANNOTATE_ORDER_T
Schematic annotation order options.
void OnCloseClick(wxCommandEvent &event) override
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:82
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
wxRadioButton * m_rbSheetX1000
wxConfigBase * m_Config
Schematic editor (Eeschema) main window.
void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
void InitValues()
Initialises member variables.
SCH_EDIT_FRAME * m_Parent
int ValueFromString(EDA_UNITS_T aUnits, const wxString &aTextValue, bool aUseMils)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application...
Definition: base_units.cpp:409
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)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:79
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
SCH_DRAW_PANEL * GetCanvas() const override
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
bool Show(bool show) 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
void OnClose(wxCloseEvent &event) override
wxStaticBitmap * annotate_down_right_bitmap
#define KEY_ANNOTATE_ALGO_OPTION
int ShowModal() override
Definition: confirm.cpp:102
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.
wxStdDialogButtonSizer * m_sdbSizer1
void SetLabel(const wxString &aLabel) override
sets the frame label
#define DLG_WINDOW_NAME
#define KEY_ANNOTATE_MESSAGES_FILTER