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_base.h>
32 #include <wx_html_report_panel.h>
33 #include <schematic.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->SetSelection( 0 );
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 
114  if( m_rbScope->IsEnabled() )
115  cfg->m_AnnotatePanel.scope = m_rbScope->GetSelection();
116 
117  cfg->m_AnnotatePanel.messages_filter = m_MessageWindow->GetVisibleSeverities();
118 
119  // Get the "start annotation after" value from dialog and update project settings if changed
120  int startNum = GetStartNumber();
121  SCH_EDIT_FRAME* schFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_parentFrame );
122 
123  if( schFrame )
124  {
125  SCHEMATIC_SETTINGS& projSettings = schFrame->Schematic().Settings();
126 
127  // If the user has updated the start annotation number then update the project file.
128  // We manually update the project file here in case the user has changed the value
129  // and just clicked the "Close" button on the annotation dialog.
130 
131  if( projSettings.m_AnnotateStartNum != startNum )
132  {
133  projSettings.m_AnnotateStartNum = startNum;
134  schFrame->SaveProjectSettings();
135  }
136  }
137 }
138 
139 
141 {
142  EESCHEMA_SETTINGS* cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
143  int option;
144 
145  if( m_rbScope->IsEnabled() )
146  m_rbScope->SetSelection( cfg->m_AnnotatePanel.scope );
147 
148  m_rbOptions->SetSelection( cfg->m_AnnotatePanel.options );
149 
150  option = cfg->m_AnnotatePanel.sort_order;
151 
152  switch( option )
153  {
154  default:
155  case 0: m_rbSortBy_X_Position->SetValue( true ); break;
156  case 1: m_rbSortBy_Y_Position->SetValue( true ); break;
157  }
158 
159  option = cfg->m_AnnotatePanel.method;
160 
161  switch( option )
162  {
163  default:
164  case 0: m_rbFirstFree->SetValue( true ); break;
165  case 1: m_rbSheetX100->SetValue( true ); break;
166  case 2: m_rbSheetX1000->SetValue( true ); break;
167  }
168 
169  int annotateStartNum = 0; // Default "start after" value for annotation
170 
171  // See if we can get a "start after" value from the project settings
172  SCH_EDIT_FRAME* schFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_parentFrame );
173 
174  if( schFrame )
175  {
176  SCHEMATIC_SETTINGS& projSettings = schFrame->Schematic().Settings();
177  annotateStartNum = projSettings.m_AnnotateStartNum;
178  }
179 
180  m_textNumberAfter->SetValue( wxString::Format( wxT( "%d" ), annotateStartNum ) );
181 
184 
186 
187  m_MessageWindow->MsgPanelSetMinSize( wxSize( -1, 160 ) );
188 }
189 
190 
191 // This is a modeless dialog so we have to handle these ourselves.
192 void DIALOG_ANNOTATE::OnCloseClick( wxCommandEvent& event )
193 {
194  Close();
195 }
196 
197 
198 void DIALOG_ANNOTATE::OnClose( wxCloseEvent& event )
199 {
200  Destroy();
201 }
202 
203 
204 void DIALOG_ANNOTATE::OnApplyClick( wxCommandEvent& event )
205 {
207  REPORTER& reporter = m_MessageWindow->Reporter();
208  m_MessageWindow->SetLazyUpdate( true ); // Don't update after each message
209 
211  GetStartNumber(), GetResetItems(), true, reporter );
212 
213  m_MessageWindow->Flush( true ); // Now update to show all messages
214 
215  m_Parent->GetCanvas()->Refresh();
216 
217  m_btnClear->Enable();
218  m_sdbSizer1Cancel->SetDefault();
219 
220  // Don't close dialog if there are things the user needs to address
221  if( reporter.HasMessage() )
222  return;
223 
224  if( m_infoBar->IsShown() )
225  {
226  // Close the dialog by calling the default handler for a wxID_OK event
227  event.SetId( wxID_OK );
228  event.Skip();
229  }
230 }
231 
232 
233 void DIALOG_ANNOTATE::OnClearAnnotationClick( wxCommandEvent& event )
234 {
235  bool appendUndo = false;
236 
237  m_Parent->DeleteAnnotation( GetScope(), &appendUndo );
238  m_btnClear->Enable( false );
239 }
240 
241 
242 void DIALOG_ANNOTATE::OnOptionChanged( wxCommandEvent& event )
243 {
244  m_sdbSizer1OK->Enable( true );
245  m_sdbSizer1OK->SetDefault();
246 }
247 
248 
250 {
251  return m_rbOptions->GetSelection() >= 1;
252 }
253 
254 
256 {
257  switch( m_rbScope->GetSelection() )
258  {
259  case 0: return ANNOTATE_ALL;
260  case 1: return ANNOTATE_CURRENT_SHEET;
261  case 2: return ANNOTATE_SELECTION;
262  default: return ANNOTATE_ALL;
263  }
264 }
265 
266 
268 {
269  if( m_rbSortBy_Y_Position->GetValue() )
270  return SORT_BY_Y_POSITION;
271  else
272  return SORT_BY_X_POSITION;
273 }
274 
275 
277 {
278  if( m_rbSheetX100->GetValue() )
279  return SHEET_NUMBER_X_100;
280  else if( m_rbSheetX1000->GetValue() )
281  return SHEET_NUMBER_X_1000;
282  else
283  return INCREMENTAL_BY_REF;
284 }
285 
286 
288 {
290 }
291 
292 
293 void SCH_EDIT_FRAME::OnAnnotate( wxCommandEvent& event )
294 {
295  DIALOG_ANNOTATE* dlg = static_cast<DIALOG_ANNOTATE*> ( wxWindow::FindWindowByName( DLG_WINDOW_NAME ) );
296 
297  if( !dlg )
298  {
299  dlg = new DIALOG_ANNOTATE( this, wxEmptyString );
300  dlg->Show( true );
301  }
302  else // The dialog is already opened, perhaps not visible
303  {
304  dlg->Show( true );
305  }
306 }
307 
308 
309 int SCH_EDIT_FRAME::ModalAnnotate( const wxString& aMessage )
310 {
311  DIALOG_ANNOTATE dlg( this, aMessage );
312 
313  return dlg.ShowModal();
314 }
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:142
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
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
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:70
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.
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:286
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