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 The 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>
29#include <eeschema_settings.h>
30#include <kiface_base.h>
32#include <schematic.h>
33#include <sch_commit.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{
44public:
45 DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent, const wxString& message );
47
48private:
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 OnAnnotateClick( wxCommandEvent& event ) override;
56
57 // User functions:
58 bool GetResetItems();
59
61
62 bool GetRecursive();
63
65
67
68 int GetStartNumber();
69
71};
72
73
74DIALOG_ANNOTATE::DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent, const wxString& message )
75 : DIALOG_ANNOTATE_BASE( parent )
76{
77 SetName( DLG_WINDOW_NAME );
78 m_Parent = parent;
79
80 if( !message.IsEmpty() )
81 {
83 m_infoBar->ShowMessage( message );
84
85 m_rbScope_Schematic->SetValue( true );
86 m_rbScope_Schematic->Enable( false );
87 }
88
89 m_MessageWindow->SetLabel( _( "Annotation Messages:" ) );
90 m_MessageWindow->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) );
91
92 SetupStandardButtons( { { wxID_OK, _( "Annotate" ) },
93 { wxID_CANCEL, _( "Close" ) } } );
94
95 InitValues();
96 Layout();
97
98 // When all widgets have the size fixed, call FinishDialogSettings
100}
101
102
104{
105 auto cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
106
108 cfg->m_AnnotatePanel.method = GetAnnotateAlgo();
109 cfg->m_AnnotatePanel.options = m_rbOptions->GetSelection();
110
111 if( m_rbScope_Schematic->IsEnabled() )
112 {
113 cfg->m_AnnotatePanel.scope = GetScope();
114 cfg->m_AnnotatePanel.recursive = GetRecursive();
115 }
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->OnModify();
135 }
136 }
137}
138
139
141{
142 EESCHEMA_SETTINGS* cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
143 int option;
144
145 if( m_rbScope_Schematic->IsEnabled() )
146 {
147 switch( cfg->m_AnnotatePanel.scope )
148 {
149 default:
150 case ANNOTATE_ALL: m_rbScope_Schematic->SetValue( true ); break;
151 case ANNOTATE_CURRENT_SHEET: m_rbScope_Sheet->SetValue( true ); break;
152 case ANNOTATE_SELECTION: m_rbScope_Selection->SetValue( true ); break;
153 }
154
156 }
157
158
159 m_rbOptions->SetSelection( cfg->m_AnnotatePanel.options );
160
161 option = cfg->m_AnnotatePanel.sort_order;
162
163 switch( option )
164 {
165 default:
166 case SORT_BY_X_POSITION: m_rbSortBy_X_Position->SetValue( true ); break;
167 case SORT_BY_Y_POSITION: m_rbSortBy_Y_Position->SetValue( true ); break;
168 }
169
170 option = cfg->m_AnnotatePanel.method;
171
172 switch( option )
173 {
174 default:
175 case INCREMENTAL_BY_REF: m_rbFirstFree->SetValue( true ); break;
176 case SHEET_NUMBER_X_100: m_rbSheetX100->SetValue( true ); break;
177 case SHEET_NUMBER_X_1000: m_rbSheetX1000->SetValue( true ); break;
178 }
179
180 int annotateStartNum = 0; // Default "start after" value for annotation
181
182 // See if we can get a "start after" value from the project settings
183 SCH_EDIT_FRAME* schFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_parentFrame );
184
185 if( schFrame )
186 {
187 SCHEMATIC_SETTINGS& projSettings = schFrame->Schematic().Settings();
188 annotateStartNum = projSettings.m_AnnotateStartNum;
189 }
190
191 m_textNumberAfter->SetValue( wxString::Format( wxT( "%d" ), annotateStartNum ) );
192
193 annotate_down_right_bitmap->SetBitmap( KiBitmapBundle( BITMAPS::annotate_down_right ) );
194 annotate_right_down_bitmap->SetBitmap( KiBitmapBundle( BITMAPS::annotate_right_down ) );
195
197
198 m_MessageWindow->MsgPanelSetMinSize( wxSize( -1, 160 ) );
199}
200
201
202// This is a modeless dialog so we have to handle these ourselves.
203void DIALOG_ANNOTATE::OnCloseClick( wxCommandEvent& event )
204{
205 Close();
206}
207
208
209void DIALOG_ANNOTATE::OnClose( wxCloseEvent& event )
210{
211 Destroy();
212}
213
214
215void DIALOG_ANNOTATE::OnAnnotateClick( wxCommandEvent& event )
216{
217 SCH_COMMIT commit( m_Parent );
218
220 REPORTER& reporter = m_MessageWindow->Reporter();
221 m_MessageWindow->SetLazyUpdate( true ); // Don't update after each message
222
224 GetRecursive(), GetStartNumber(), GetResetItems(), true, reporter );
225
226 commit.Push( _( "Annotate" ) );
227
228 m_MessageWindow->Flush( true ); // Now update to show all messages
229}
230
231
232void DIALOG_ANNOTATE::OnClearAnnotationClick( wxCommandEvent& event )
233{
236
237 m_MessageWindow->Flush( true ); // Now update to show all messages
238}
239
240
241void DIALOG_ANNOTATE::OnOptionChanged( wxCommandEvent& event )
242{
243 m_sdbSizer1OK->Enable( true );
244 m_sdbSizer1OK->SetDefault();
245}
246
247
249{
250 return m_rbOptions->GetSelection() >= 1;
251}
252
253
255{
256 if( m_rbScope_Schematic->GetValue() )
257 return ANNOTATE_ALL;
258 else if( m_rbScope_Sheet->GetValue() )
260 else
261 return ANNOTATE_SELECTION;
262}
263
264
266{
267 return m_checkRecursive->GetValue();
268}
269
270
272{
273 if( m_rbSortBy_Y_Position->GetValue() )
274 return SORT_BY_Y_POSITION;
275 else
276 return SORT_BY_X_POSITION;
277}
278
279
281{
282 if( m_rbSheetX100->GetValue() )
283 return SHEET_NUMBER_X_100;
284 else if( m_rbSheetX1000->GetValue() )
285 return SHEET_NUMBER_X_1000;
286 else
287 return INCREMENTAL_BY_REF;
288}
289
290
292{
294}
295
296
298{
299 DIALOG_ANNOTATE* dlg =
300 static_cast<DIALOG_ANNOTATE*>( wxWindow::FindWindowByName( DLG_WINDOW_NAME ) );
301
302 if( !dlg )
303 {
304 dlg = new DIALOG_ANNOTATE( this, wxEmptyString );
305 dlg->Show( true );
306 }
307 else // The dialog is already opened, perhaps not visible
308 {
309 dlg->Show( true );
310 }
311}
312
313
314int SCH_EDIT_FRAME::ModalAnnotate( const wxString& aMessage )
315{
316 DIALOG_ANNOTATE dlg( this, aMessage );
317
318 return dlg.ShowModal();
319}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
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 OnAnnotateClick(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:248
int ShowModal() 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:72
These are loaded from Eeschema settings but then overwritten by the project settings.
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:312
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
Definition: sch_commit.cpp:432
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...
void DeleteAnnotation(ANNOTATE_SCOPE_T aAnnotateScope, bool aRecursive, REPORTER &aReporter)
Clear the current symbol annotation.
Definition: annotate.cpp:60
void AnnotateSymbols(SCH_COMMIT *aCommit, ANNOTATE_SCOPE_T aAnnotateScope, ANNOTATE_ORDER_T aSortOption, ANNOTATE_ALGO_T aAlgoOption, bool aRecursive, int aStartNumber, bool aResetAnnotation, bool aRepairTimestamps, REPORTER &aReporter)
Annotate the symbols in the schematic that are not currently annotated.
Definition: annotate.cpp:212
SCHEMATIC & Schematic() const
int ModalAnnotate(const wxString &aMessage)
Run a modal version of the annotate dialog for a specific purpose.
void Clear()
Clears the report panel.
void SetLazyUpdate(bool aLazyUpdate)
Set the lazy update.
void SetLabel(const wxString &aLabel) override
Set the frame label.
void MsgPanelSetMinSize(const wxSize &aMinSize)
Set the min size of the area which displays html messages.
void SetFileName(const wxString &aReportFileName)
Set the report full file name to the string.
void SetVisibleSeverities(int aSeverities)
Set the visible severity filter.
void Flush(bool aSort=false)
Force updating the HTML page, after the report is built in lazy mode If aSort = true,...
REPORTER & Reporter()
Return the reporter object that reports to this panel.
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: wx_infobar.cpp:320
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: wx_infobar.cpp:153
#define DLG_WINDOW_NAME
#define _(s)
KICOMMON_API long long int ValueFromString(const EDA_IU_SCALE &aIuScale, EDA_UNITS aUnits, const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Convert aTextValue in aUnits to internal units used by the application.
Definition: eda_units.cpp:648
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.