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 
150  switch( option )
151  {
152  default:
153  case 0: m_rbSortBy_X_Position->SetValue( 1 ); break;
154  case 1: m_rbSortBy_Y_Position->SetValue( 1 ); break;
155  }
156 
157  m_Config->Read( KEY_ANNOTATE_ALGO_OPTION, &option, 0L );
158 
159  switch( option )
160  {
161  default:
162  case 0: m_rbFirstFree->SetValue( 1 ); break;
163  case 1: m_rbSheetX100->SetValue( 100 ); break;
164  case 2: m_rbSheetX1000->SetValue( 1000 ); break;
165  }
166 
167  m_textNumberAfter->SetValue( wxT( "0" ) );
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  int severities = m_Config->Read( KEY_ANNOTATE_MESSAGES_FILTER, -1l );
173  m_MessageWindow->SetVisibleSeverities( severities );
174 
175  m_MessageWindow->MsgPanelSetMinSize( wxSize( -1, 160 ) );
176 }
177 
178 
179 // This is a modeless dialog so we have to handle these ourselves.
180 void DIALOG_ANNOTATE::OnCloseClick( wxCommandEvent& event )
181 {
182  Close();
183 }
184 
185 
186 void DIALOG_ANNOTATE::OnClose( wxCloseEvent& event )
187 {
188  Destroy();
189 }
190 
191 
192 void DIALOG_ANNOTATE::OnApplyClick( wxCommandEvent& event )
193 {
194  wxString message;
195 
196  // Ask for confirmation of destructive actions.
197  if( GetResetItems() )
198  {
199  if( GetLevel() )
200  message += _( "Clear and annotate all of the symbols on the entire schematic?" );
201  else
202  message += _( "Clear and annotate all of the symbols on the current sheet?" );
203 
204  message += _( "\n\nThis operation will change the current annotation and cannot be undone." );
205 
206  KIDIALOG dlg( this, message, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
207  dlg.SetOKLabel( _( "Clear and Annotate" ) );
208  dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
209 
210  if( dlg.ShowModal() == wxCANCEL )
211  return;
212  }
213 
215  REPORTER& reporter = m_MessageWindow->Reporter();
216  m_MessageWindow->SetLazyUpdate( true ); // Don't update after each message
217 
220  GetResetItems() , true, GetLockUnits(), reporter );
221 
222  m_MessageWindow->Flush( true ); // Now update to show all messages
223 
224  m_Parent->GetCanvas()->Refresh();
225 
226  m_btnClear->Enable();
227 
228  // Don't close dialog if there are things the user needs to address
229  if( reporter.HasMessage() )
230  return;
231 
232  if( m_userMessage->IsShown() )
233  {
234  // Close the dialog by calling the default handler for a wxID_OK event
235  event.SetId( wxID_OK );
236  event.Skip();
237  }
238 }
239 
240 
241 void DIALOG_ANNOTATE::OnClearAnnotationCmpClick( wxCommandEvent& event )
242 {
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 
252  KIDIALOG dlg( this, message, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
253  dlg.SetOKLabel( _( "Clear Annotation" ) );
254  dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
255 
256  if( dlg.ShowModal() == wxID_CANCEL )
257  return;
258 
260  m_btnClear->Enable( false );
261 }
262 
263 
265 {
266  return m_rbScope->GetSelection() == 0;
267 }
268 
269 
271 {
272  return m_rbOptions->GetSelection() >= 1;
273 }
274 
275 
277 {
278  return m_rbOptions->GetSelection() == 2;
279 }
280 
281 
283 {
284  if( m_rbSortBy_Y_Position->GetValue() )
285  return 1;
286  else
287  return 0;
288 }
289 
290 
292 {
293  if( m_rbSheetX100->GetValue() )
294  return 1;
295  else if( m_rbSheetX1000->GetValue() )
296  return 2;
297  else
298  return 0;
299 }
300 
301 
303 {
305 }
306 
307 
308 void SCH_EDIT_FRAME::OnAnnotate( wxCommandEvent& event )
309 {
310  DIALOG_ANNOTATE* dlg = static_cast<DIALOG_ANNOTATE*> ( wxWindow::FindWindowByName( DLG_WINDOW_NAME ) );
311 
312  if( !dlg )
313  {
314  dlg = new DIALOG_ANNOTATE( this, wxEmptyString );
315  dlg->Show( true );
316  }
317  else // The dialog is already opened, perhaps not visible
318  {
319  dlg->Show( true );
320  }
321 }
322 
323 
324 int SCH_EDIT_FRAME::ModalAnnotate( const wxString& aMessage )
325 {
326  DIALOG_ANNOTATE dlg( this, aMessage );
327 
328  return dlg.ShowModal();
329 }
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 'do not show again' checkbox
Definition: confirm.cpp:53
Helper class to create more flexible dialogs, including 'do not show again' 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,...
wxConfigBase * KifaceSettings() const
Definition: kiface_i.h:103
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 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:51
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
Return a pointer to GAL-based canvas of given EDA draw frame.
WX_HTML_REPORT_PANEL * m_MessageWindow
ANNOTATE_OPTION_T
Schematic annotation type options.
void OnClearAnnotationCmpClick(wxCommandEvent &event) override
#define _(s)
bool Show(bool show) override
virtual 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...
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:95
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
long long 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:427