KiCad PCB EDA Suite
dialog_annotate.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 1992-2017 jean-pierre Charras jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 
26 #include <sch_edit_frame.h>
27 #include <bitmaps.h>
28 #include <confirm.h>
29 #include <dialog_annotate_base.h>
30 #include <eeschema_settings.h>
31 #include <kiface_i.h>
32 #include <widgets/infobar.h>
33 #include <wx_html_report_panel.h>
34 
35 // A window name for the annotate dialog to retrieve is if not destroyed
36 #define DLG_WINDOW_NAME "DialogAnnotateWindowName"
37 
38 
43 {
44 public:
45  DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent, const wxString& message );
47 
48 private:
50  void InitValues();
51  void OnOptionChanged( wxCommandEvent& event ) override;
52  void OnClearAnnotationClick( wxCommandEvent& event ) override;
53  void OnCloseClick( wxCommandEvent& event ) override;
54  void OnClose( wxCloseEvent& event ) override;
55  void OnApplyClick( wxCommandEvent& event ) override;
56 
57  // User functions:
58  bool GetResetItems();
59 
61 
63 
65 
66  int GetStartNumber();
67 
69 };
70 
71 
72 DIALOG_ANNOTATE::DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent, const wxString& message )
73  : DIALOG_ANNOTATE_BASE( parent )
74 {
75  SetName( DLG_WINDOW_NAME );
76  m_Parent = parent;
77 
78  if( !message.IsEmpty() )
79  {
81  m_infoBar->ShowMessage( message );
82 
83  m_rbScope->Enable( false );
84  }
85 
86  m_MessageWindow->SetLabel( _( "Annotation Messages:" ) );
87  m_MessageWindow->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) );
88 
89  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
90  // that requires us to correct the button labels here.
91  m_sdbSizer1OK->SetLabel( _( "Annotate" ) );
92  m_sdbSizer1Cancel->SetLabel( _( "Close" ) );
93  m_sdbSizer1->Layout();
94 
95  m_sdbSizer1OK->SetDefault();
96 
97  InitValues();
98  Layout();
99 
100  // When all widgets have the size fixed, call FinishDialogSettings
102 }
103 
104 
106 {
107  auto cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
108 
109  cfg->m_AnnotatePanel.sort_order = GetSortOrder();
110  cfg->m_AnnotatePanel.method = GetAnnotateAlgo();
111  cfg->m_AnnotatePanel.options = m_rbOptions->GetSelection();
112  cfg->m_AnnotatePanel.scope = m_rbScope->GetSelection();
113  cfg->m_AnnotatePanel.messages_filter = m_MessageWindow->GetVisibleSeverities();
114 }
115 
116 
118 {
119  EESCHEMA_SETTINGS* cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
120  int option;
121 
122  m_rbScope->SetSelection( cfg->m_AnnotatePanel.scope );
123  m_rbOptions->SetSelection( cfg->m_AnnotatePanel.options );
124 
125  option = cfg->m_AnnotatePanel.sort_order;
126 
127  switch( option )
128  {
129  default:
130  case 0: m_rbSortBy_X_Position->SetValue( true ); break;
131  case 1: m_rbSortBy_Y_Position->SetValue( true ); break;
132  }
133 
134  option = cfg->m_AnnotatePanel.method;
135 
136  switch( option )
137  {
138  default:
139  case 0: m_rbFirstFree->SetValue( true ); break;
140  case 1: m_rbSheetX100->SetValue( true ); break;
141  case 2: m_rbSheetX1000->SetValue( true ); break;
142  }
143 
144  m_textNumberAfter->SetValue( wxT( "0" ) );
145 
148 
150 
151  m_MessageWindow->MsgPanelSetMinSize( wxSize( -1, 160 ) );
152 }
153 
154 
155 // This is a modeless dialog so we have to handle these ourselves.
156 void DIALOG_ANNOTATE::OnCloseClick( wxCommandEvent& event )
157 {
158  Close();
159 }
160 
161 
162 void DIALOG_ANNOTATE::OnClose( wxCloseEvent& event )
163 {
164  Destroy();
165 }
166 
167 
168 void DIALOG_ANNOTATE::OnApplyClick( wxCommandEvent& event )
169 {
171  REPORTER& reporter = m_MessageWindow->Reporter();
172  m_MessageWindow->SetLazyUpdate( true ); // Don't update after each message
173 
175  GetStartNumber(), GetResetItems(), true, reporter );
176 
177  m_MessageWindow->Flush( true ); // Now update to show all messages
178 
179  m_Parent->GetCanvas()->Refresh();
180 
181  m_btnClear->Enable();
182  m_sdbSizer1Cancel->SetDefault();
183 
184  // Don't close dialog if there are things the user needs to address
185  if( reporter.HasMessage() )
186  return;
187 
188  if( m_infoBar->IsShown() )
189  {
190  // Close the dialog by calling the default handler for a wxID_OK event
191  event.SetId( wxID_OK );
192  event.Skip();
193  }
194 }
195 
196 
197 void DIALOG_ANNOTATE::OnClearAnnotationClick( wxCommandEvent& event )
198 {
199  bool appendUndo = false;
200 
201  m_Parent->DeleteAnnotation( GetScope(), &appendUndo );
202  m_btnClear->Enable( false );
203 }
204 
205 
206 void DIALOG_ANNOTATE::OnOptionChanged( wxCommandEvent& event )
207 {
208  m_sdbSizer1OK->Enable( true );
209  m_sdbSizer1OK->SetDefault();
210 }
211 
212 
214 {
215  return m_rbOptions->GetSelection() >= 1;
216 }
217 
218 
220 {
221  switch( m_rbScope->GetSelection() )
222  {
223  case 0: return ANNOTATE_ALL;
224  case 1: return ANNOTATE_CURRENT_SHEET;
225  case 2: return ANNOTATE_SELECTION;
226  default: return ANNOTATE_ALL;
227  }
228 }
229 
230 
232 {
233  if( m_rbSortBy_Y_Position->GetValue() )
234  return SORT_BY_Y_POSITION;
235  else
236  return SORT_BY_X_POSITION;
237 }
238 
239 
241 {
242  if( m_rbSheetX100->GetValue() )
243  return SHEET_NUMBER_X_100;
244  else if( m_rbSheetX1000->GetValue() )
245  return SHEET_NUMBER_X_1000;
246  else
247  return INCREMENTAL_BY_REF;
248 }
249 
250 
252 {
254 }
255 
256 
257 void SCH_EDIT_FRAME::OnAnnotate( wxCommandEvent& event )
258 {
259  DIALOG_ANNOTATE* dlg = static_cast<DIALOG_ANNOTATE*> ( wxWindow::FindWindowByName( DLG_WINDOW_NAME ) );
260 
261  if( !dlg )
262  {
263  dlg = new DIALOG_ANNOTATE( this, wxEmptyString );
264  dlg->Show( true );
265  }
266  else // The dialog is already opened, perhaps not visible
267  {
268  dlg->Show( true );
269  }
270 }
271 
272 
273 int SCH_EDIT_FRAME::ModalAnnotate( const wxString& aMessage )
274 {
275  DIALOG_ANNOTATE dlg( this, aMessage );
276 
277  return dlg.ShowModal();
278 }
void SetVisibleSeverities(int aSeverities)
void OnOptionChanged(wxCommandEvent &event) override
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: infobar.cpp:134
void SetLazyUpdate(bool aLazyUpdate)
Forces updating the HTML page, after the report is built in lazy mode If aSort = true,...
virtual bool HasMessage() const =0
Returns true if the reporter client is non-empty.
Annotate the selection.
Annotate the full schematic.
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 Flush(bool aSort=false)
Set the visible severity filter.
PANEL_ANNOTATE m_AnnotatePanel
void DeleteAnnotation(ANNOTATE_SCOPE_T aAnnotateScope, bool *appendUndo)
Clear the current component annotation.
Definition: annotate.cpp:63
wxRadioButton * m_rbSheetX1000
Schematic editor (Eeschema) main window.
void AnnotateSymbols(ANNOTATE_SCOPE_T aAnnotateScope, ANNOTATE_ORDER_T aSortOption, ANNOTATE_ALGO_T aAlgoOption, int aStartNumber, bool aResetAnnotation, bool aRepairTimestamps, REPORTER &aReporter)
Annotate the symbols in the schematic that are not currently annotated.
Definition: annotate.cpp:126
void InitValues()
Initialize member variables.
SCH_EDIT_FRAME * m_Parent
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:64
wxStaticBitmap * annotate_right_down_bitmap
DIALOG_ANNOTATE(SCH_EDIT_FRAME *parent, const wxString &message)
ANNOTATE_ALGO_T GetAnnotateAlgo()
long long int ValueFromString(EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: base_units.cpp:402
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
wxRadioButton * m_rbSortBy_Y_Position
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
Annotate using the first free reference number starting at the sheet number * 100.
WX_HTML_REPORT_PANEL * m_MessageWindow
ANNOTATE_SCOPE_T
Schematic annotation scope options.
ANNOTATE_SCOPE_T GetScope()
ANNOTATE_ORDER_T GetSortOrder()
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:104
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: infobar.cpp:287
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
Annotate by Y position from top to bottom.
void OnAnnotate(wxCommandEvent &event)
wxRadioButton * m_rbSheetX100
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Annotate incrementally using the first free reference number.
int ModalAnnotate(const wxString &aMessage)
Run a modal version of the annotate dialog for a specific purpose.
void Clear()
return the number of messages matching the given severity mask.
void OnClose(wxCloseEvent &event) override
#define _(s)
Definition: 3d_actions.cpp:33
wxStaticBitmap * annotate_down_right_bitmap
ANNOTATE_ALGO_T
Schematic annotation type options.
Annotate by X position from left to right.
void OnClearAnnotationClick(wxCommandEvent &event) override
Annotate using the first free reference number starting at the sheet number * 1000.
A dialog to set/clear reference designators of a schematic with different options.
void MsgPanelSetMinSize(const wxSize &aMinSize)
returns the reporter object that reports to this panel
Annotate the current sheet.
void SetFileName(const wxString &aReportFileName)
wxStdDialogButtonSizer * m_sdbSizer1
void SetLabel(const wxString &aLabel) override
Sets the lazy update.
#define DLG_WINDOW_NAME