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 
44 {
45 public:
46  DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent, const wxString& message );
48 
49 private:
51 
53  void InitValues();
54  void OnOptionChanged( wxCommandEvent& event ) override;
55  void OnClearAnnotationClick( wxCommandEvent& event ) override;
56  void OnCloseClick( wxCommandEvent& event ) override;
57  void OnClose( wxCloseEvent& event ) override;
58  void OnApplyClick( wxCommandEvent& event ) override;
59 
60  // User functions:
61  bool GetLevel();
62  bool GetResetItems();
63  bool GetLockUnits();
64 
70  int GetSortOrder();
71 
78  int GetAnnotateAlgo();
79 
80  int GetStartNumber();
81 };
82 
83 
84 DIALOG_ANNOTATE::DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent, const wxString& message )
85  : DIALOG_ANNOTATE_BASE( parent )
86 {
87  SetName( DLG_WINDOW_NAME );
88  m_Parent = parent;
89 
90  if( !message.IsEmpty() )
91  {
93  m_infoBar->ShowMessage( message );
94 
95  m_rbScope->Enable( false );
96  }
97 
98  m_MessageWindow->SetLabel( _( "Annotation Messages:" ) );
99  m_MessageWindow->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) );
100 
101  // We use a sdbSizer to get platform-dependent ordering of the action buttons, but
102  // that requires us to correct the button labels here.
103  m_sdbSizer1OK->SetLabel( _( "Annotate" ) );
104  m_sdbSizer1Cancel->SetLabel( _( "Close" ) );
105  m_sdbSizer1->Layout();
106 
107  m_sdbSizer1OK->SetDefault();
108 
109  InitValues();
110  Layout();
111 
112  // When all widgets have the size fixed, call FinishDialogSettings
114 }
115 
116 
118 {
119  auto cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
120 
121  cfg->m_AnnotatePanel.sort_order = GetSortOrder();
122  cfg->m_AnnotatePanel.method = GetAnnotateAlgo();
123  cfg->m_AnnotatePanel.messages_filter = m_MessageWindow->GetVisibleSeverities();
124 }
125 
126 
128 {
129  EESCHEMA_SETTINGS* cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
130  int option;
131 
132  // These are always reset to attempt to keep the user out of trouble...
133  m_rbScope->SetSelection( 0 );
134  m_rbOptions->SetSelection( 0 );
135 
136  option = cfg->m_AnnotatePanel.sort_order;
137 
138  switch( option )
139  {
140  default:
141  case 0: m_rbSortBy_X_Position->SetValue( true ); break;
142  case 1: m_rbSortBy_Y_Position->SetValue( true ); break;
143  }
144 
145  option = cfg->m_AnnotatePanel.method;
146 
147  switch( option )
148  {
149  default:
150  case 0: m_rbFirstFree->SetValue( true ); break;
151  case 1: m_rbSheetX100->SetValue( true ); break;
152  case 2: m_rbSheetX1000->SetValue( true ); break;
153  }
154 
155  m_textNumberAfter->SetValue( wxT( "0" ) );
156 
159 
161 
162  m_MessageWindow->MsgPanelSetMinSize( wxSize( -1, 160 ) );
163 }
164 
165 
166 // This is a modeless dialog so we have to handle these ourselves.
167 void DIALOG_ANNOTATE::OnCloseClick( wxCommandEvent& event )
168 {
169  Close();
170 }
171 
172 
173 void DIALOG_ANNOTATE::OnClose( wxCloseEvent& event )
174 {
175  Destroy();
176 }
177 
178 
179 void DIALOG_ANNOTATE::OnApplyClick( wxCommandEvent& event )
180 {
182  REPORTER& reporter = m_MessageWindow->Reporter();
183  m_MessageWindow->SetLazyUpdate( true ); // Don't update after each message
184 
187  GetResetItems() , true, GetLockUnits(), reporter );
188 
189  m_MessageWindow->Flush( true ); // Now update to show all messages
190 
191  m_Parent->GetCanvas()->Refresh();
192 
193  m_btnClear->Enable();
194  m_sdbSizer1Cancel->SetDefault();
195 
196  // Don't close dialog if there are things the user needs to address
197  if( reporter.HasMessage() )
198  return;
199 
200  if( m_infoBar->IsShown() )
201  {
202  // Close the dialog by calling the default handler for a wxID_OK event
203  event.SetId( wxID_OK );
204  event.Skip();
205  }
206 }
207 
208 
209 void DIALOG_ANNOTATE::OnClearAnnotationClick( wxCommandEvent& event )
210 {
211  bool appendUndo = false;
212 
213  m_Parent->DeleteAnnotation( !GetLevel(), &appendUndo );
214  m_btnClear->Enable( false );
215 }
216 
217 
218 void DIALOG_ANNOTATE::OnOptionChanged( wxCommandEvent& event )
219 {
220  m_sdbSizer1OK->Enable( true );
221  m_sdbSizer1OK->SetDefault();
222 }
223 
224 
226 {
227  return m_rbScope->GetSelection() == 0;
228 }
229 
230 
232 {
233  return m_rbOptions->GetSelection() >= 1;
234 }
235 
236 
238 {
239  return m_rbOptions->GetSelection() == 2;
240 }
241 
242 
244 {
245  if( m_rbSortBy_Y_Position->GetValue() )
246  return 1;
247  else
248  return 0;
249 }
250 
251 
253 {
254  if( m_rbSheetX100->GetValue() )
255  return 1;
256  else if( m_rbSheetX1000->GetValue() )
257  return 2;
258  else
259  return 0;
260 }
261 
262 
264 {
266 }
267 
268 
269 void SCH_EDIT_FRAME::OnAnnotate( wxCommandEvent& event )
270 {
271  DIALOG_ANNOTATE* dlg = static_cast<DIALOG_ANNOTATE*> ( wxWindow::FindWindowByName( DLG_WINDOW_NAME ) );
272 
273  if( !dlg )
274  {
275  dlg = new DIALOG_ANNOTATE( this, wxEmptyString );
276  dlg->Show( true );
277  }
278  else // The dialog is already opened, perhaps not visible
279  {
280  dlg->Show( true );
281  }
282 }
283 
284 
285 int SCH_EDIT_FRAME::ModalAnnotate( const wxString& aMessage )
286 {
287  DIALOG_ANNOTATE dlg( this, aMessage );
288 
289  return dlg.ShowModal();
290 }
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:124
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.
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
const BITMAP_OPAQUE annotate_right_down_xpm[1]
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.
void Flush(bool aSort=false)
Set the visible severity filter.
PANEL_ANNOTATE m_AnnotatePanel
wxRadioButton * m_rbSheetX1000
Schematic editor (Eeschema) main window.
void InitValues()
Initialises member variables.
SCH_EDIT_FRAME * m_Parent
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:64
void DeleteAnnotation(bool aCurrentSheetOnly, bool *appendUndo)
Clear the current component annotation.
const BITMAP_OPAQUE annotate_down_right_xpm[1]
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:82
wxStaticBitmap * annotate_right_down_bitmap
DIALOG_ANNOTATE(SCH_EDIT_FRAME *parent, const wxString &message)
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:451
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.
WX_HTML_REPORT_PANEL * m_MessageWindow
ANNOTATE_OPTION_T
Schematic annotation type options.
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: infobar.cpp:277
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
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...
int GetAnnotateAlgo()
Function GetAnnotateAlgo.
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
void OnClearAnnotationClick(wxCommandEvent &event) override
DIALOG_ANNOTATE: a dialog to set/clear reference designators, of a schematic hierarchy,...
void MsgPanelSetMinSize(const wxSize &aMinSize)
returns the reporter object that reports to this panel
void SetFileName(const wxString &aReportFileName)
int GetSortOrder()
Function GetSortOrder.
wxStdDialogButtonSizer * m_sdbSizer1
void SetLabel(const wxString &aLabel) override
Sets the lasy update.
#define DLG_WINDOW_NAME