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 #include <schematic.h>
35 
36 // A window name for the annotate dialog to retrieve is if not destroyed
37 #define DLG_WINDOW_NAME "DialogAnnotateWindowName"
38 
39 
44 {
45 public:
46  DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent, const wxString& message );
48 
49 private:
51  void InitValues();
52  void OnOptionChanged( wxCommandEvent& event ) override;
53  void OnClearAnnotationClick( wxCommandEvent& event ) override;
54  void OnCloseClick( wxCommandEvent& event ) override;
55  void OnClose( wxCloseEvent& event ) override;
56  void OnApplyClick( wxCommandEvent& event ) override;
57 
58  // User functions:
59  bool GetResetItems();
60 
62 
64 
66 
67  int GetStartNumber();
68 
70 };
71 
72 
73 DIALOG_ANNOTATE::DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent, const wxString& message )
74  : DIALOG_ANNOTATE_BASE( parent )
75 {
76  SetName( DLG_WINDOW_NAME );
77  m_Parent = parent;
78 
79  if( !message.IsEmpty() )
80  {
82  m_infoBar->ShowMessage( message );
83 
84  m_rbScope->Enable( false );
85  }
86 
87  m_MessageWindow->SetLabel( _( "Annotation Messages:" ) );
88  m_MessageWindow->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) );
89 
90  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
91  // that requires us to correct the button labels here.
92  m_sdbSizer1OK->SetLabel( _( "Annotate" ) );
93  m_sdbSizer1Cancel->SetLabel( _( "Close" ) );
94  m_sdbSizer1->Layout();
95 
96  m_sdbSizer1OK->SetDefault();
97 
98  InitValues();
99  Layout();
100 
101  // When all widgets have the size fixed, call FinishDialogSettings
103 }
104 
105 
107 {
108  auto cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
109 
110  cfg->m_AnnotatePanel.sort_order = GetSortOrder();
111  cfg->m_AnnotatePanel.method = GetAnnotateAlgo();
112  cfg->m_AnnotatePanel.options = m_rbOptions->GetSelection();
113  cfg->m_AnnotatePanel.scope = m_rbScope->GetSelection();
114  cfg->m_AnnotatePanel.messages_filter = m_MessageWindow->GetVisibleSeverities();
115 
116  // Get the "start annotation after" value from dialog and update project settings if changed
117  int startNum = GetStartNumber();
118  SCH_EDIT_FRAME* schFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_parentFrame );
119 
120  if( schFrame ) {
121  SCHEMATIC_SETTINGS& projSettings = schFrame->Schematic().Settings();
122 
123  // If the user has updated the start annotation number then update the project file.
124  // We manually update the project file here in case the user has changed the value
125  // and just clicked the "Close" button on the annotation dialog.
126 
127  if( projSettings.m_AnnotateStartNum != startNum )
128  {
129  projSettings.m_AnnotateStartNum = startNum;
130  schFrame->SaveProjectSettings();
131  }
132  }
133 }
134 
135 
137 {
138  EESCHEMA_SETTINGS* cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
139  int option;
140 
141  m_rbScope->SetSelection( cfg->m_AnnotatePanel.scope );
142  m_rbOptions->SetSelection( cfg->m_AnnotatePanel.options );
143 
144  option = cfg->m_AnnotatePanel.sort_order;
145 
146  switch( option )
147  {
148  default:
149  case 0: m_rbSortBy_X_Position->SetValue( true ); break;
150  case 1: m_rbSortBy_Y_Position->SetValue( true ); break;
151  }
152 
153  option = cfg->m_AnnotatePanel.method;
154 
155  switch( option )
156  {
157  default:
158  case 0: m_rbFirstFree->SetValue( true ); break;
159  case 1: m_rbSheetX100->SetValue( true ); break;
160  case 2: m_rbSheetX1000->SetValue( true ); break;
161  }
162 
163  int annotateStartNum = 0; // Default "start after" value for annotation
164 
165  // See if we can get a "start after" value from the project settings
166  SCH_EDIT_FRAME* schFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_parentFrame );
167 
168  if( schFrame )
169  {
170  SCHEMATIC_SETTINGS& projSettings = schFrame->Schematic().Settings();
171  annotateStartNum = projSettings.m_AnnotateStartNum;
172  }
173 
174  m_textNumberAfter->SetValue( wxString::Format( wxT( "%d" ), annotateStartNum ) );
175 
178 
180 
181  m_MessageWindow->MsgPanelSetMinSize( wxSize( -1, 160 ) );
182 }
183 
184 
185 // This is a modeless dialog so we have to handle these ourselves.
186 void DIALOG_ANNOTATE::OnCloseClick( wxCommandEvent& event )
187 {
188  Close();
189 }
190 
191 
192 void DIALOG_ANNOTATE::OnClose( wxCloseEvent& event )
193 {
194  Destroy();
195 }
196 
197 
198 void DIALOG_ANNOTATE::OnApplyClick( wxCommandEvent& event )
199 {
201  REPORTER& reporter = m_MessageWindow->Reporter();
202  m_MessageWindow->SetLazyUpdate( true ); // Don't update after each message
203 
205  GetStartNumber(), GetResetItems(), true, reporter );
206 
207  m_MessageWindow->Flush( true ); // Now update to show all messages
208 
209  m_Parent->GetCanvas()->Refresh();
210 
211  m_btnClear->Enable();
212  m_sdbSizer1Cancel->SetDefault();
213 
214  // Don't close dialog if there are things the user needs to address
215  if( reporter.HasMessage() )
216  return;
217 
218  if( m_infoBar->IsShown() )
219  {
220  // Close the dialog by calling the default handler for a wxID_OK event
221  event.SetId( wxID_OK );
222  event.Skip();
223  }
224 }
225 
226 
227 void DIALOG_ANNOTATE::OnClearAnnotationClick( wxCommandEvent& event )
228 {
229  bool appendUndo = false;
230 
231  m_Parent->DeleteAnnotation( GetScope(), &appendUndo );
232  m_btnClear->Enable( false );
233 }
234 
235 
236 void DIALOG_ANNOTATE::OnOptionChanged( wxCommandEvent& event )
237 {
238  m_sdbSizer1OK->Enable( true );
239  m_sdbSizer1OK->SetDefault();
240 }
241 
242 
244 {
245  return m_rbOptions->GetSelection() >= 1;
246 }
247 
248 
250 {
251  switch( m_rbScope->GetSelection() )
252  {
253  case 0: return ANNOTATE_ALL;
254  case 1: return ANNOTATE_CURRENT_SHEET;
255  case 2: return ANNOTATE_SELECTION;
256  default: return ANNOTATE_ALL;
257  }
258 }
259 
260 
262 {
263  if( m_rbSortBy_Y_Position->GetValue() )
264  return SORT_BY_Y_POSITION;
265  else
266  return SORT_BY_X_POSITION;
267 }
268 
269 
271 {
272  if( m_rbSheetX100->GetValue() )
273  return SHEET_NUMBER_X_100;
274  else if( m_rbSheetX1000->GetValue() )
275  return SHEET_NUMBER_X_1000;
276  else
277  return INCREMENTAL_BY_REF;
278 }
279 
280 
282 {
284 }
285 
286 
287 void SCH_EDIT_FRAME::OnAnnotate( wxCommandEvent& event )
288 {
289  DIALOG_ANNOTATE* dlg = static_cast<DIALOG_ANNOTATE*> ( wxWindow::FindWindowByName( DLG_WINDOW_NAME ) );
290 
291  if( !dlg )
292  {
293  dlg = new DIALOG_ANNOTATE( this, wxEmptyString );
294  dlg->Show( true );
295  }
296  else // The dialog is already opened, perhaps not visible
297  {
298  dlg->Show( true );
299  }
300 }
301 
302 
303 int SCH_EDIT_FRAME::ModalAnnotate( const wxString& aMessage )
304 {
305  DIALOG_ANNOTATE dlg( this, aMessage );
306 
307  return dlg.ShowModal();
308 }
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.
void SaveProjectSettings() override
Save changes to the project settings to the project (.pro) file.
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
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:167
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 symbol 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:416
EDA_BASE_FRAME * m_parentFrame
Definition: dialog_shim.h:216
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.
SCHEMATIC & Schematic() const
WX_HTML_REPORT_PANEL * m_MessageWindow
ANNOTATE_SCOPE_T
Schematic annotation scope options.
#define _(s)
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:105
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: infobar.cpp:287
bool Show(bool show) override
wxRadioButton * m_rbFirstFree
Annotate by Y position from top to bottom.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
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
wxStaticBitmap * annotate_down_right_bitmap
ANNOTATE_ALGO_T
Schematic annotation type options.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
Annotate by X position from left to right.
These settings were stored in SCH_BASE_FRAME previously.
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