KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <base_units.h>
28#include <bitmaps.h>
29#include <confirm.h>
31#include <eeschema_settings.h>
32#include <kiface_base.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{
45public:
46 DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent, const wxString& message );
48
49private:
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
63 bool GetRecursive();
64
66
68
69 int GetStartNumber();
70
72};
73
74
75DIALOG_ANNOTATE::DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent, const wxString& message )
76 : DIALOG_ANNOTATE_BASE( parent )
77{
78 SetName( DLG_WINDOW_NAME );
79 m_Parent = parent;
80
81 if( !message.IsEmpty() )
82 {
84 m_infoBar->ShowMessage( message );
85
86 m_rbScope_Schematic->SetValue( true );
87 m_rbScope_Schematic->Enable( false );
88 }
89
90 m_MessageWindow->SetLabel( _( "Annotation Messages:" ) );
91 m_MessageWindow->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) );
92
93 SetupStandardButtons( { { wxID_OK, _( "Annotate" ) },
94 { wxID_CANCEL, _( "Close" ) } } );
95
96 InitValues();
97 Layout();
98
99 // When all widgets have the size fixed, call FinishDialogSettings
101}
102
103
105{
106 auto cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
107
109 cfg->m_AnnotatePanel.method = GetAnnotateAlgo();
110 cfg->m_AnnotatePanel.options = m_rbOptions->GetSelection();
111
112 if( m_rbScope_Schematic->IsEnabled() )
113 {
114 cfg->m_AnnotatePanel.scope = GetScope();
115 cfg->m_AnnotatePanel.recursive = GetRecursive();
116 }
117
118 cfg->m_AnnotatePanel.messages_filter = m_MessageWindow->GetVisibleSeverities();
119
120 // Get the "start annotation after" value from dialog and update project settings if changed
121 int startNum = GetStartNumber();
122 SCH_EDIT_FRAME* schFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_parentFrame );
123
124 if( schFrame )
125 {
126 SCHEMATIC_SETTINGS& projSettings = schFrame->Schematic().Settings();
127
128 // If the user has updated the start annotation number then update the project file.
129 // We manually update the project file here in case the user has changed the value
130 // and just clicked the "Close" button on the annotation dialog.
131
132 if( projSettings.m_AnnotateStartNum != startNum )
133 {
134 projSettings.m_AnnotateStartNum = startNum;
135 schFrame->OnModify();
136 }
137 }
138}
139
140
142{
143 EESCHEMA_SETTINGS* cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
144 int option;
145
146 if( m_rbScope_Schematic->IsEnabled() )
147 {
148 switch( cfg->m_AnnotatePanel.scope )
149 {
150 default:
151 case ANNOTATE_ALL: m_rbScope_Schematic->SetValue( true ); break;
152 case ANNOTATE_CURRENT_SHEET: m_rbScope_Sheet->SetValue( true ); break;
153 case ANNOTATE_SELECTION: m_rbScope_Selection->SetValue( true ); break;
154 }
155
157 }
158
159
160 m_rbOptions->SetSelection( cfg->m_AnnotatePanel.options );
161
162 option = cfg->m_AnnotatePanel.sort_order;
163
164 switch( option )
165 {
166 default:
167 case SORT_BY_X_POSITION: m_rbSortBy_X_Position->SetValue( true ); break;
168 case SORT_BY_Y_POSITION: m_rbSortBy_Y_Position->SetValue( true ); break;
169 }
170
171 option = cfg->m_AnnotatePanel.method;
172
173 switch( option )
174 {
175 default:
176 case INCREMENTAL_BY_REF: m_rbFirstFree->SetValue( true ); break;
177 case SHEET_NUMBER_X_100: m_rbSheetX100->SetValue( true ); break;
178 case SHEET_NUMBER_X_1000: m_rbSheetX1000->SetValue( true ); break;
179 }
180
181 int annotateStartNum = 0; // Default "start after" value for annotation
182
183 // See if we can get a "start after" value from the project settings
184 SCH_EDIT_FRAME* schFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_parentFrame );
185
186 if( schFrame )
187 {
188 SCHEMATIC_SETTINGS& projSettings = schFrame->Schematic().Settings();
189 annotateStartNum = projSettings.m_AnnotateStartNum;
190 }
191
192 m_textNumberAfter->SetValue( wxString::Format( wxT( "%d" ), annotateStartNum ) );
193
194 annotate_down_right_bitmap->SetBitmap( KiBitmap( BITMAPS::annotate_down_right ) );
195 annotate_right_down_bitmap->SetBitmap( KiBitmap( BITMAPS::annotate_right_down ) );
196
198
199 m_MessageWindow->MsgPanelSetMinSize( wxSize( -1, 160 ) );
200}
201
202
203// This is a modeless dialog so we have to handle these ourselves.
204void DIALOG_ANNOTATE::OnCloseClick( wxCommandEvent& event )
205{
206 Close();
207}
208
209
210void DIALOG_ANNOTATE::OnClose( wxCloseEvent& event )
211{
212 Destroy();
213}
214
215
216void DIALOG_ANNOTATE::OnApplyClick( wxCommandEvent& event )
217{
219 REPORTER& reporter = m_MessageWindow->Reporter();
220 m_MessageWindow->SetLazyUpdate( true ); // Don't update after each message
221
223 GetStartNumber(), GetResetItems(), true, reporter );
224
225 m_MessageWindow->Flush( true ); // Now update to show all messages
226
228
229 m_btnClear->Enable();
230
231 m_sdbSizer1Cancel->SetDefault();
232
233 // Don't close dialog if there are things the user needs to address
234 if( reporter.HasMessage() )
235 return;
236
237 if( m_infoBar->IsShown() )
238 {
239 // Close the dialog by calling the default handler for a wxID_OK event
240 event.SetId( wxID_OK );
241 event.Skip();
242 }
243}
244
245
246void DIALOG_ANNOTATE::OnClearAnnotationClick( wxCommandEvent& event )
247{
249 m_btnClear->Enable( false );
250}
251
252
253void DIALOG_ANNOTATE::OnOptionChanged( wxCommandEvent& event )
254{
255 m_sdbSizer1OK->Enable( true );
256 m_sdbSizer1OK->SetDefault();
257}
258
259
261{
262 return m_rbOptions->GetSelection() >= 1;
263}
264
265
267{
268 if( m_rbScope_Schematic->GetValue() )
269 return ANNOTATE_ALL;
270 else if( m_rbScope_Sheet->GetValue() )
272 else
273 return ANNOTATE_SELECTION;
274}
275
276
278{
279 return m_checkRecursive->GetValue();
280}
281
282
284{
285 if( m_rbSortBy_Y_Position->GetValue() )
286 return SORT_BY_Y_POSITION;
287 else
288 return SORT_BY_X_POSITION;
289}
290
291
293{
294 if( m_rbSheetX100->GetValue() )
295 return SHEET_NUMBER_X_100;
296 else if( m_rbSheetX1000->GetValue() )
297 return SHEET_NUMBER_X_1000;
298 else
299 return INCREMENTAL_BY_REF;
300}
301
302
304{
306}
307
308
309void SCH_EDIT_FRAME::OnAnnotate( wxCommandEvent& event )
310{
311 DIALOG_ANNOTATE* dlg = static_cast<DIALOG_ANNOTATE*> ( wxWindow::FindWindowByName( DLG_WINDOW_NAME ) );
312
313 if( !dlg )
314 {
315 dlg = new DIALOG_ANNOTATE( this, wxEmptyString );
316 dlg->Show( true );
317 }
318 else // The dialog is already opened, perhaps not visible
319 {
320 dlg->Show( true );
321 }
322}
323
324
325int SCH_EDIT_FRAME::ModalAnnotate( const wxString& aMessage )
326{
327 DIALOG_ANNOTATE dlg( this, aMessage );
328
329 return dlg.ShowModal();
330}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
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:106
Class DIALOG_ANNOTATE_BASE.
wxStaticBitmap * annotate_down_right_bitmap
wxRadioButton * m_rbSortBy_X_Position
wxRadioButton * m_rbSheetX100
wxRadioButton * m_rbScope_Sheet
wxRadioButton * m_rbSheetX1000
wxStaticBitmap * annotate_right_down_bitmap
wxRadioButton * m_rbScope_Schematic
wxRadioButton * m_rbSortBy_Y_Position
WX_HTML_REPORT_PANEL * m_MessageWindow
wxRadioButton * m_rbScope_Selection
wxRadioButton * m_rbFirstFree
A dialog to set/clear reference designators of a schematic with different options.
void OnClose(wxCloseEvent &event) override
void OnClearAnnotationClick(wxCommandEvent &event) override
ANNOTATE_SCOPE_T GetScope()
void OnOptionChanged(wxCommandEvent &event) override
void OnCloseClick(wxCommandEvent &event) override
void OnApplyClick(wxCommandEvent &event) override
SCH_EDIT_FRAME * m_Parent
DIALOG_ANNOTATE(SCH_EDIT_FRAME *parent, const wxString &message)
ANNOTATE_ORDER_T GetSortOrder()
void InitValues()
Initialize member variables.
ANNOTATE_ALGO_T GetAnnotateAlgo()
bool Show(bool show) override
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
EDA_BASE_FRAME * m_parentFrame
Definition: dialog_shim.h:221
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
PANEL_ANNOTATE m_AnnotatePanel
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:95
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
virtual bool HasMessage() const =0
Returns true if the reporter client is non-empty.
These settings were stored in SCH_BASE_FRAME previously.
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:205
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
Schematic editor (Eeschema) main window.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag and update other data struc...
SCHEMATIC & Schematic() const
void OnAnnotate(wxCommandEvent &event)
void DeleteAnnotation(ANNOTATE_SCOPE_T aAnnotateScope, bool aRecursive)
Clear the current symbol annotation.
Definition: annotate.cpp:61
int ModalAnnotate(const wxString &aMessage)
Run a modal version of the annotate dialog for a specific purpose.
void AnnotateSymbols(ANNOTATE_SCOPE_T aAnnotateScope, ANNOTATE_ORDER_T aSortOption, ANNOTATE_ALGO_T aAlgoOption, bool aRecursive, int aStartNumber, bool aResetAnnotation, bool aRepairTimestamps, REPORTER &aReporter, bool appendUndo=false)
Annotate the symbols in the schematic that are not currently annotated.
Definition: annotate.cpp:195
void Clear()
return the number of messages matching the given severity mask.
void SetLazyUpdate(bool aLazyUpdate)
Forces updating the HTML page, after the report is built in lazy mode If aSort = true,...
void SetLabel(const wxString &aLabel) override
Sets the lazy update.
void MsgPanelSetMinSize(const wxSize &aMinSize)
returns the reporter object that reports to this panel
void SetFileName(const wxString &aReportFileName)
void SetVisibleSeverities(int aSeverities)
void Flush(bool aSort=false)
Set the visible severity filter.
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: wx_infobar.cpp:301
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: wx_infobar.cpp:154
This file is part of the common library.
#define DLG_WINDOW_NAME
#define _(s)
long long int ValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Function ValueFromString converts aTextValue in aUnits to internal units used by the application.
Definition: eda_units.cpp:525
ANNOTATE_ORDER_T
Schematic annotation order options.
@ SORT_BY_X_POSITION
Annotate by X position from left to right.
@ SORT_BY_Y_POSITION
Annotate by Y position from top to bottom.
ANNOTATE_SCOPE_T
Schematic annotation scope options.
@ ANNOTATE_SELECTION
Annotate the selection.
@ ANNOTATE_CURRENT_SHEET
Annotate the current sheet.
@ ANNOTATE_ALL
Annotate the full schematic.
ANNOTATE_ALGO_T
Schematic annotation type options.
@ SHEET_NUMBER_X_1000
Annotate using the first free reference number starting at the sheet number * 1000.
@ INCREMENTAL_BY_REF
Annotate incrementally using the first free reference number.
@ SHEET_NUMBER_X_100
Annotate using the first free reference number starting at the sheet number * 100.