-
-
Notifications
You must be signed in to change notification settings - Fork 491
/
eeschema_config.cpp
384 lines (293 loc) · 14.2 KB
/
eeschema_config.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mutex>
#include <wx/ffile.h>
#include <symbol_library.h>
#include <confirm.h>
#include <dialogs/dialog_schematic_setup.h>
#include <kiway.h>
#include <symbol_edit_frame.h>
#include <dialogs/panel_gal_display_options.h>
#include <filename_resolver.h>
#include <pgm_base.h>
#include <project/project_file.h>
#include <project/project_local_settings.h>
#include <project/net_settings.h>
#include <sch_edit_frame.h>
#include <sch_painter.h>
#include <schematic.h>
#include <widgets/design_block_pane.h>
#include <widgets/hierarchy_pane.h>
#include <widgets/sch_search_pane.h>
#include <widgets/panel_sch_selection_filter.h>
#include <widgets/properties_panel.h>
#include <settings/app_settings.h>
#include <settings/settings_manager.h>
#include <wildcards_and_files_ext.h>
#include <drawing_sheet/ds_data_model.h>
#include <zoom_defines.h>
#include <sim/spice_settings.h>
#include <tool/tool_manager.h>
#include <tools/ee_selection_tool.h>
/// Helper for all the old plotting/printing code while it still exists
COLOR4D GetLayerColor( SCH_LAYER_ID aLayer )
{
return Pgm().GetSettingsManager().GetColorSettings()->GetColor( aLayer );
}
bool SCH_EDIT_FRAME::LoadProjectSettings()
{
SCHEMATIC_SETTINGS& settings = Schematic().Settings();
settings.m_JunctionSize = GetSchematicJunctionSize();
GetRenderSettings()->SetDefaultPenWidth( settings.m_DefaultLineWidth );
GetRenderSettings()->m_LabelSizeRatio = settings.m_LabelSizeRatio;
GetRenderSettings()->m_TextOffsetRatio = settings.m_TextOffsetRatio;
GetRenderSettings()->m_PinSymbolSize = settings.m_PinSymbolSize;
GetRenderSettings()->SetDashLengthRatio( settings.m_DashedLineDashRatio );
GetRenderSettings()->SetGapLengthRatio( settings.m_DashedLineGapRatio );
BASE_SCREEN::m_DrawingSheetFileName = settings.m_SchDrawingSheetFileName;
PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
EE_SELECTION_TOOL* selTool = GetToolManager()->GetTool<EE_SELECTION_TOOL>();
selTool->GetFilter() = localSettings.m_SchSelectionFilter;
m_selectionFilterPanel->SetCheckboxesFromFilter( localSettings.m_SchSelectionFilter );
return true;
}
void SCH_EDIT_FRAME::LoadDrawingSheet()
{
// Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
// If empty, or not existing, the default drawing sheet is loaded.
SCHEMATIC_SETTINGS& settings = Schematic().Settings();
FILENAME_RESOLVER resolver;
resolver.SetProject( &Prj() );
resolver.SetProgramBase( &Pgm() );
wxString filename = resolver.ResolvePath( settings.m_SchDrawingSheetFileName,
Prj().GetProjectPath(),
Schematic().GetEmbeddedFiles() );
wxString msg;
if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename, &msg ) )
ShowInfoBarError( msg, true );
}
void SCH_EDIT_FRAME::ShowSchematicSetupDialog( const wxString& aInitialPage )
{
static std::mutex dialogMutex; // Local static mutex
std::unique_lock<std::mutex> dialogLock( dialogMutex, std::try_to_lock );
// One dialog at a time.
if( !dialogLock.owns_lock() )
{
if( m_schematicSetupDialog && m_schematicSetupDialog->IsShown() )
{
m_schematicSetupDialog->Raise(); // Brings the existing dialog to the front
}
return;
}
SCH_SCREENS screens( Schematic().Root() );
std::vector<std::shared_ptr<BUS_ALIAS>> oldAliases;
for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
{
for( const std::shared_ptr<BUS_ALIAS>& alias : screen->GetBusAliases() )
oldAliases.push_back( alias );
}
DIALOG_SCHEMATIC_SETUP dlg( this );
if( !aInitialPage.IsEmpty() )
dlg.SetInitialPage( aInitialPage, wxEmptyString );
// Assign dlg to the m_schematicSetupDialog pointer to track its status.
m_schematicSetupDialog = &dlg;
// TODO: is QuasiModal required here?
if( dlg.ShowQuasiModal() == wxID_OK )
{
// Mark document as modified so that project settings can be saved as part of doc save
OnModify();
Kiway().CommonSettingsChanged( false, true );
Prj().IncrementTextVarsTicker();
Prj().IncrementNetclassesTicker();
Pgm().GetSettingsManager().SaveProject();
GetRenderSettings()->SetDefaultPenWidth( Schematic().Settings().m_DefaultLineWidth );
GetRenderSettings()->m_LabelSizeRatio = Schematic().Settings().m_LabelSizeRatio;
GetRenderSettings()->m_TextOffsetRatio = Schematic().Settings().m_TextOffsetRatio;
GetRenderSettings()->m_PinSymbolSize = Schematic().Settings().m_PinSymbolSize;
GetRenderSettings()->SetDashLengthRatio( Schematic().Settings().m_DashedLineDashRatio );
GetRenderSettings()->SetGapLengthRatio( Schematic().Settings().m_DashedLineGapRatio );
GetCanvas()->GetView()->MarkDirty();
GetCanvas()->GetView()->UpdateAllItems( KIGFX::REPAINT );
std::vector<std::shared_ptr<BUS_ALIAS>> newAliases;
for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
{
for( const std::shared_ptr<BUS_ALIAS>& alias : screen->GetBusAliases() )
newAliases.push_back( alias );
}
if( oldAliases != newAliases )
RecalculateConnections( nullptr, GLOBAL_CLEANUP );
RefreshOperatingPointDisplay();
GetCanvas()->Refresh();
}
// Reset m_schematicSetupDialog after the dialog is closed
m_schematicSetupDialog = nullptr;
}
int SCH_EDIT_FRAME::GetSchematicJunctionSize()
{
std::vector<double>& sizeMultipliers = eeconfig()->m_Drawing.junction_size_mult_list;
const std::shared_ptr<NET_SETTINGS>& netSettings = Prj().GetProjectFile().NetSettings();
int sizeChoice = Schematic().Settings().m_JunctionSizeChoice;
int dotSize = netSettings->GetDefaultNetclass()->GetWireWidth() * sizeMultipliers[sizeChoice];
return std::max( dotSize, 1 );
}
void SCH_EDIT_FRAME::saveProjectSettings()
{
wxFileName fn = Schematic().RootScreen()->GetFileName(); //ConfigFileName
fn.SetExt( FILEEXT::ProjectFileExtension );
if( !fn.HasName() || !IsWritable( fn, false ) )
return;
Schematic().RecordERCExclusions();
if( Kiway().Player( FRAME_SIMULATOR, false ) )
Prj().GetProjectFile().m_SchematicSettings->m_NgspiceSettings->SaveToFile();
// Save the page layout file if doesn't exist yet (e.g. if we opened a non-kicad schematic)
// TODO: We need to remove dependence on BASE_SCREEN
Prj().GetProjectFile().m_SchematicSettings->m_SchDrawingSheetFileName
= BASE_SCREEN::m_DrawingSheetFileName;
if( !BASE_SCREEN::m_DrawingSheetFileName.IsEmpty() )
{
FILENAME_RESOLVER resolve;
resolve.SetProject( &Prj() );
resolve.SetProgramBase( &Pgm() );
wxFileName layoutfn( resolve.ResolvePath( BASE_SCREEN::m_DrawingSheetFileName,
Prj().GetProjectPath(),
Schematic().GetEmbeddedFiles() ) );
bool success = true;
if( !layoutfn.IsAbsolute() )
success = layoutfn.MakeAbsolute( Prj().GetProjectPath() );
if( success && layoutfn.IsOk() && !layoutfn.FileExists() && layoutfn.HasName() )
{
if( layoutfn.DirExists() && layoutfn.IsDirWritable() )
DS_DATA_MODEL::GetTheInstance().Save( layoutfn.GetFullPath() );
}
}
GetSettingsManager()->SaveProject( fn.GetFullPath() );
}
void SCH_EDIT_FRAME::SaveProjectLocalSettings()
{
if( m_schematic )
m_schematic->RecordERCExclusions();
PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
EE_SELECTION_TOOL* selTool = GetToolManager()->GetTool<EE_SELECTION_TOOL>();
localSettings.m_SchSelectionFilter = selTool->GetFilter();
}
void SCH_EDIT_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
{
// For now, axes are forced off in Eeschema even if turned on in config
EESCHEMA_SETTINGS* cfg = eeconfig();
cfg->m_Window.grid.axes_enabled = false;
SCH_BASE_FRAME::LoadSettings( cfg );
SCH_SEARCH_DATA* searchData = dynamic_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() );
if( searchData )
{
searchData->replaceReferences = cfg->m_FindReplaceExtra.replace_references;
searchData->searchAllFields = cfg->m_FindReplaceExtra.search_all_fields;
searchData->searchAllPins = cfg->m_FindReplaceExtra.search_all_pins;
searchData->searchCurrentSheetOnly = cfg->m_FindReplaceExtra.search_current_sheet_only;
searchData->searchSelectedOnly = cfg->m_FindReplaceExtra.search_selected_only;
}
m_show_search = cfg->m_AuiPanels.show_search;
GetRenderSettings()->m_ShowPinsElectricalType = false;
GetRenderSettings()->m_ShowPinNumbers = false;
GetRenderSettings()->m_ShowPinAltIcons = cfg->m_Appearance.show_pin_alt_icons;
GetRenderSettings()->SetDefaultFont( cfg->m_Appearance.default_font );
}
void SCH_EDIT_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
{
EESCHEMA_SETTINGS* cfg = eeconfig();
SCH_BASE_FRAME::SaveSettings( cfg );
wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
if( cfg )
{
cfg->m_System.units = static_cast<int>( GetUserUnits() );
cfg->m_AuiPanels.show_schematic_hierarchy = hierarchy_pane.IsShown();
cfg->m_AuiPanels.schematic_hierarchy_float = hierarchy_pane.IsFloating();
// Other parameters (hierarchy_panel_float_width, hierarchy_panel_float_height,
// and hierarchy_panel_docked_width should have been updated when resizing the
// hierarchy panel
SCH_SEARCH_DATA* searchData = dynamic_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() );
if( searchData )
{
cfg->m_FindReplaceExtra.replace_references = searchData->replaceReferences;
cfg->m_FindReplaceExtra.search_all_fields = searchData->searchAllFields;
cfg->m_FindReplaceExtra.search_all_pins = searchData->searchAllPins;
cfg->m_FindReplaceExtra.search_current_sheet_only =
searchData->searchCurrentSheetOnly;
cfg->m_FindReplaceExtra.search_selected_only = searchData->searchSelectedOnly;
}
wxAuiPaneInfo& searchPaneInfo = m_auimgr.GetPane( SearchPaneName() );
m_show_search = searchPaneInfo.IsShown();
cfg->m_AuiPanels.show_search = m_show_search;
cfg->m_AuiPanels.search_panel_height = m_searchPane->GetSize().y;
cfg->m_AuiPanels.search_panel_width = m_searchPane->GetSize().x;
cfg->m_AuiPanels.search_panel_dock_direction = searchPaneInfo.dock_direction;
wxAuiPaneInfo& propertiesPane = m_auimgr.GetPane( PropertiesPaneName() );
cfg->m_AuiPanels.show_properties = propertiesPane.IsShown();
cfg->m_AuiPanels.properties_splitter = m_propertiesPanel->SplitterProportion();
cfg->m_AuiPanels.properties_panel_width = m_propertiesPanel->GetSize().x;
wxAuiPaneInfo& netNavigatorPane = m_auimgr.GetPane( NetNavigatorPaneName() );
cfg->m_AuiPanels.show_net_nav_panel = netNavigatorPane.IsShown();
cfg->m_AuiPanels.float_net_nav_panel = netNavigatorPane.IsFloating();
if( netNavigatorPane.IsDocked() )
cfg->m_AuiPanels.net_nav_panel_docked_size = m_netNavigator->GetSize();
else
{
cfg->m_AuiPanels.net_nav_panel_float_pos = netNavigatorPane.floating_pos;
cfg->m_AuiPanels.net_nav_panel_float_size = netNavigatorPane.floating_size;
}
wxAuiPaneInfo& designBlocksPane = m_auimgr.GetPane( DesignBlocksPaneName() );
cfg->m_AuiPanels.design_blocks_show = designBlocksPane.IsShown();
if( designBlocksPane.IsDocked() )
cfg->m_AuiPanels.design_blocks_panel_docked_width = m_designBlocksPane->GetSize().x;
else
{
cfg->m_AuiPanels.design_blocks_panel_float_height = designBlocksPane.floating_size.y;
cfg->m_AuiPanels.design_blocks_panel_float_width = designBlocksPane.floating_size.x;
}
}
}
void SCH_BASE_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
{
wxCHECK_RET( aCfg, "Call to SCH_BASE_FRAME::LoadSettings with null settings" );
EDA_DRAW_FRAME::LoadSettings( aCfg );
if( aCfg->m_Window.grid.grids.empty() )
aCfg->m_Window.grid.grids = aCfg->DefaultGridSizeList();
// Move legacy user grids to grid list
if( !aCfg->m_Window.grid.user_grid_x.empty() )
{
aCfg->m_Window.grid.grids.emplace_back( GRID{ "User Grid", aCfg->m_Window.grid.user_grid_x,
aCfg->m_Window.grid.user_grid_y } );
aCfg->m_Window.grid.user_grid_x = wxEmptyString;
aCfg->m_Window.grid.user_grid_y = wxEmptyString;
}
if( aCfg->m_Window.grid.last_size_idx > (int) aCfg->m_Window.grid.grids.size() )
aCfg->m_Window.grid.last_size_idx = 1;
if( aCfg->m_Window.grid.fast_grid_1 > (int) aCfg->m_Window.grid.grids.size() )
aCfg->m_Window.grid.fast_grid_1 = 1;
if( aCfg->m_Window.grid.fast_grid_2 > (int) aCfg->m_Window.grid.grids.size() )
aCfg->m_Window.grid.fast_grid_2 = 2;
if( aCfg->m_Window.zoom_factors.empty() )
{
aCfg->m_Window.zoom_factors = { ZOOM_LIST_EESCHEMA };
}
}
void SCH_BASE_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
{
wxCHECK_RET( aCfg, wxS( "Call to SCH_BASE_FRAME::SaveSettings with null settings" ) );
EDA_DRAW_FRAME::SaveSettings( aCfg );
}