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 <widgets/wx_infobar.h>
28#include <bitmaps.h>
30#include <eeschema_settings.h>
31#include <kiface_base.h>
33#include <schematic.h>
34#include <sch_commit.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
49 bool TransferDataToWindow() override;
50
51private:
53 void OnOptionChanged( wxCommandEvent& event ) override;
54 void OnClearAnnotationClick( wxCommandEvent& event ) override;
55 void OnCloseClick( wxCommandEvent& event ) override;
56 void OnClose( wxCloseEvent& event ) override;
57 void OnAnnotateClick( wxCommandEvent& event ) override;
58
60 {
61 if( m_rbScope_Schematic->GetValue() )
62 return ANNOTATE_ALL;
63 else if( m_rbScope_Sheet->GetValue() )
65 else
66 return ANNOTATE_SELECTION;
67 }
68
70 {
71 if( m_rbSortBy_Y_Position->GetValue() )
72 return SORT_BY_Y_POSITION;
73 else
74 return SORT_BY_X_POSITION;
75 }
76
78 {
79 if( m_rbSheetX100->GetValue() )
80 return SHEET_NUMBER_X_100;
81 else if( m_rbSheetX1000->GetValue() )
83 else
84 return INCREMENTAL_BY_REF;
85 }
86
88 {
90 }
91
92private:
94};
95
96
97DIALOG_ANNOTATE::DIALOG_ANNOTATE( SCH_EDIT_FRAME* parent, const wxString& message ) :
98 DIALOG_ANNOTATE_BASE( parent )
99{
100 SetName( DLG_WINDOW_NAME );
101 m_Parent = parent;
102
103 if( !message.IsEmpty() )
104 {
105 m_infoBar->RemoveAllButtons();
106 m_infoBar->ShowMessage( message );
107
108 m_rbScope_Schematic->SetValue( true );
109 m_rbScope_Schematic->Enable( false );
110 }
111
112 m_MessageWindow->SetLabel( _( "Annotation Messages:" ) );
113 m_MessageWindow->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) );
114
115 SetupStandardButtons( { { wxID_OK, _( "Annotate" ) },
116 { wxID_CANCEL, _( "Close" ) } } );
117
120
121 m_MessageWindow->MsgPanelSetMinSize( wxSize( -1, 160 ) );
122
123 Layout();
124
125 // When all widgets have the size fixed, call FinishDialogSettings
127}
128
129
131{
132 // We still save/restore to config (instead of letting DIALOG_SHIM do it) because we also
133 // allow editing of these settings in preferences.
134
135 EESCHEMA_SETTINGS* cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
136
137 cfg->m_AnnotatePanel.options = m_rbReset_Annotations->GetValue() ? 1 : 0;
138
139 if( m_rbScope_Schematic->IsEnabled() )
140 {
142 cfg->m_AnnotatePanel.recursive = m_checkRecursive->GetValue();
143 }
144
146
147 int sort = GetSortOrder();
148 int method = GetAnnotateAlgo();
149 int startNum = GetStartNumber();
150
151 if( SCH_EDIT_FRAME* schFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_parentFrame ) )
152 {
153 SCHEMATIC_SETTINGS& projSettings = schFrame->Schematic().Settings();
154 bool modified = false;
155
156 if( projSettings.m_AnnotateSortOrder != sort )
157 {
158 projSettings.m_AnnotateSortOrder = sort;
159 modified = true;
160 }
161
162 if( projSettings.m_AnnotateMethod != method )
163 {
164 projSettings.m_AnnotateMethod = method;
165 modified = true;
166 }
167
168 if( projSettings.m_AnnotateStartNum != startNum )
169 {
170 projSettings.m_AnnotateStartNum = startNum;
171 modified = true;
172 }
173
174 if( modified )
175 schFrame->OnModify();
176 }
177}
178
179
181{
182 // We still save/restore to config (instead of letting DIALOG_SHIM do it) because we also
183 // allow editing of these settings in preferences.
184 EESCHEMA_SETTINGS* cfg = static_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() );
185
186 if( m_rbScope_Schematic->IsEnabled() )
187 {
188 switch( cfg->m_AnnotatePanel.scope )
189 {
190 default:
191 case ANNOTATE_ALL: m_rbScope_Schematic->SetValue( true ); break;
192 case ANNOTATE_CURRENT_SHEET: m_rbScope_Sheet->SetValue( true ); break;
193 case ANNOTATE_SELECTION: m_rbScope_Selection->SetValue( true ); break;
194 }
195
197 }
198
199 bool resetAnnotation = cfg->m_AnnotatePanel.options >= 1;
200 m_rbReset_Annotations->SetValue( resetAnnotation );
201 m_rbKeep_Annotations->SetValue( !resetAnnotation );
202
204 m_checkRegroupUnits->Enable( cfg->m_AnnotatePanel.options >= 1 );
205
206 if( SCH_EDIT_FRAME* schFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_parentFrame ) )
207 {
208 SCHEMATIC_SETTINGS& projSettings = schFrame->Schematic().Settings();
209
210 switch( projSettings.m_AnnotateSortOrder )
211 {
212 default:
213 case SORT_BY_X_POSITION: m_rbSortBy_X_Position->SetValue( true ); break;
214 case SORT_BY_Y_POSITION: m_rbSortBy_Y_Position->SetValue( true ); break;
215 }
216
217 switch( projSettings.m_AnnotateMethod )
218 {
219 default:
220 case INCREMENTAL_BY_REF: m_rbFirstFree->SetValue( true ); break;
221 case SHEET_NUMBER_X_100: m_rbSheetX100->SetValue( true ); break;
222 case SHEET_NUMBER_X_1000: m_rbSheetX1000->SetValue( true ); break;
223 }
224
225 m_textNumberAfter->SetValue( wxString::Format( wxT( "%d" ), projSettings.m_AnnotateStartNum ) );
226 }
227
228 return true;
229}
230
231
232// This is a modeless dialog so we have to handle these ourselves.
233void DIALOG_ANNOTATE::OnCloseClick( wxCommandEvent& event )
234{
235 Close();
236}
237
238
239void DIALOG_ANNOTATE::OnClose( wxCloseEvent& event )
240{
241 Destroy();
242}
243
244
245void DIALOG_ANNOTATE::OnAnnotateClick( wxCommandEvent& event )
246{
247 SCH_COMMIT commit( m_Parent );
248
249 m_MessageWindow->Clear();
250 REPORTER& reporter = m_MessageWindow->Reporter();
251 m_MessageWindow->SetLazyUpdate( true ); // Don't update after each message
252
253 bool resetAnnotation = m_rbReset_Annotations->GetValue();
254 bool regroupUnits = resetAnnotation && m_checkRegroupUnits->GetValue();
255
256 m_Parent->AnnotateSymbols( &commit, GetScope(), GetSortOrder(), GetAnnotateAlgo(),
257 m_checkRecursive->GetValue(), GetStartNumber(), resetAnnotation,
258 regroupUnits, true, reporter );
259
260 commit.Push( _( "Annotate" ) );
261
262 m_MessageWindow->Flush( true ); // Now update to show all messages
263}
264
265
266void DIALOG_ANNOTATE::OnClearAnnotationClick( wxCommandEvent& event )
267{
268 m_MessageWindow->Clear();
269 m_Parent->DeleteAnnotation( GetScope(), m_checkRecursive->GetValue(), m_MessageWindow->Reporter() );
270
271 m_MessageWindow->Flush( true ); // Now update to show all messages
272}
273
274
275void DIALOG_ANNOTATE::OnOptionChanged( wxCommandEvent& event )
276{
277 m_checkRegroupUnits->Enable( m_rbReset_Annotations->GetValue() );
278
279 m_sdbSizer1OK->Enable( true );
280 m_sdbSizer1OK->SetDefault();
281}
282
283
285{
286 DIALOG_ANNOTATE* dlg = static_cast<DIALOG_ANNOTATE*>( wxWindow::FindWindowByName( DLG_WINDOW_NAME ) );
287
288 if( !dlg )
289 {
290 dlg = new DIALOG_ANNOTATE( this, wxEmptyString );
291 dlg->Show( true );
292 }
293 else // The dialog is already opened, perhaps not visible
294 {
295 dlg->Show( true );
296 }
297}
298
299
300int SCH_EDIT_FRAME::ModalAnnotate( const wxString& aMessage )
301{
302 DIALOG_ANNOTATE dlg( this, aMessage );
303
304 return dlg.ShowModal();
305}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:110
@ annotate_down_right
@ annotate_right_down
wxStaticBitmap * annotate_down_right_bitmap
wxRadioButton * m_rbSortBy_X_Position
wxRadioButton * m_rbSheetX100
DIALOG_ANNOTATE_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Annotate Schematic"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxRadioButton * m_rbScope_Sheet
wxRadioButton * m_rbSheetX1000
wxStaticBitmap * annotate_right_down_bitmap
wxRadioButton * m_rbKeep_Annotations
wxRadioButton * m_rbReset_Annotations
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()
bool TransferDataToWindow() override
void OnOptionChanged(wxCommandEvent &event) override
Initialize member variables.
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()
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
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:73
These are loaded from Eeschema settings but then overwritten by the project settings.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
Schematic editor (Eeschema) main window.
int ModalAnnotate(const wxString &aMessage)
Run a modal version of the annotate dialog for a specific purpose.
#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.
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.