You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

315 lines
12 KiB

18 years ago
18 years ago
3 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2014-2023 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software: you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation, either version 3 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <mutex>
  20. #include <wx/ffile.h>
  21. #include <symbol_library.h>
  22. #include <confirm.h>
  23. #include <dialogs/dialog_schematic_setup.h>
  24. #include <kiway.h>
  25. #include <symbol_edit_frame.h>
  26. #include <dialogs/panel_gal_display_options.h>
  27. #include <pgm_base.h>
  28. #include <project/project_file.h>
  29. #include <project/net_settings.h>
  30. #include <sch_edit_frame.h>
  31. #include <sch_painter.h>
  32. #include <schematic.h>
  33. #include <widgets/hierarchy_pane.h>
  34. #include <widgets/sch_search_pane.h>
  35. #include <widgets/properties_panel.h>
  36. #include <settings/app_settings.h>
  37. #include <settings/settings_manager.h>
  38. #include <wildcards_and_files_ext.h>
  39. #include <drawing_sheet/ds_data_model.h>
  40. #include <zoom_defines.h>
  41. #include <sim/spice_settings.h>
  42. /// Helper for all the old plotting/printing code while it still exists
  43. COLOR4D GetLayerColor( SCH_LAYER_ID aLayer )
  44. {
  45. return Pgm().GetSettingsManager().GetColorSettings()->GetColor( aLayer );
  46. }
  47. bool SCH_EDIT_FRAME::LoadProjectSettings()
  48. {
  49. SCHEMATIC_SETTINGS& settings = Schematic().Settings();
  50. settings.m_JunctionSize = GetSchematicJunctionSize();
  51. GetRenderSettings()->SetDefaultPenWidth( settings.m_DefaultLineWidth );
  52. GetRenderSettings()->m_LabelSizeRatio = settings.m_LabelSizeRatio;
  53. GetRenderSettings()->m_TextOffsetRatio = settings.m_TextOffsetRatio;
  54. GetRenderSettings()->m_PinSymbolSize = settings.m_PinSymbolSize;
  55. GetRenderSettings()->SetDashLengthRatio( settings.m_DashedLineDashRatio );
  56. GetRenderSettings()->SetGapLengthRatio( settings.m_DashedLineGapRatio );
  57. BASE_SCREEN::m_DrawingSheetFileName = settings.m_SchDrawingSheetFileName;
  58. // Load the drawing sheet from the filename stored in BASE_SCREEN::m_DrawingSheetFileName.
  59. // If empty, or not existing, the default drawing sheet is loaded.
  60. wxString filename = DS_DATA_MODEL::ResolvePath( BASE_SCREEN::m_DrawingSheetFileName,
  61. Prj().GetProjectPath() );
  62. if( !DS_DATA_MODEL::GetTheInstance().LoadDrawingSheet( filename ) )
  63. ShowInfoBarError( _( "Error loading drawing sheet." ), true );
  64. return true;
  65. }
  66. void SCH_EDIT_FRAME::ShowSchematicSetupDialog( const wxString& aInitialPage )
  67. {
  68. SCH_SCREENS screens( Schematic().Root() );
  69. std::vector<std::shared_ptr<BUS_ALIAS>> oldAliases;
  70. for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
  71. {
  72. for( const std::shared_ptr<BUS_ALIAS>& alias : screen->GetBusAliases() )
  73. oldAliases.push_back( alias );
  74. }
  75. DIALOG_SCHEMATIC_SETUP dlg( this );
  76. if( !aInitialPage.IsEmpty() )
  77. dlg.SetInitialPage( aInitialPage, wxEmptyString );
  78. if( dlg.ShowQuasiModal() == wxID_OK )
  79. {
  80. // Mark document as modified so that project settings can be saved as part of doc save
  81. OnModify();
  82. Kiway().CommonSettingsChanged( false, true );
  83. Prj().IncrementTextVarsTicker();
  84. Prj().IncrementNetclassesTicker();
  85. GetRenderSettings()->SetDefaultPenWidth( Schematic().Settings().m_DefaultLineWidth );
  86. GetRenderSettings()->m_LabelSizeRatio = Schematic().Settings().m_LabelSizeRatio;
  87. GetRenderSettings()->m_TextOffsetRatio = Schematic().Settings().m_TextOffsetRatio;
  88. GetRenderSettings()->m_PinSymbolSize = Schematic().Settings().m_PinSymbolSize;
  89. GetRenderSettings()->SetDashLengthRatio( Schematic().Settings().m_DashedLineDashRatio );
  90. GetRenderSettings()->SetGapLengthRatio( Schematic().Settings().m_DashedLineGapRatio );
  91. GetCanvas()->GetView()->MarkDirty();
  92. GetCanvas()->GetView()->UpdateAllItems( KIGFX::REPAINT );
  93. std::vector<std::shared_ptr<BUS_ALIAS>> newAliases;
  94. for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
  95. {
  96. for( const std::shared_ptr<BUS_ALIAS>& alias : screen->GetBusAliases() )
  97. newAliases.push_back( alias );
  98. }
  99. if( oldAliases != newAliases )
  100. RecalculateConnections( nullptr, GLOBAL_CLEANUP );
  101. RefreshOperatingPointDisplay();
  102. GetCanvas()->Refresh();
  103. }
  104. }
  105. int SCH_EDIT_FRAME::GetSchematicJunctionSize()
  106. {
  107. std::vector<double>& sizeMultipliers = eeconfig()->m_Drawing.junction_size_mult_list;
  108. const std::shared_ptr<NET_SETTINGS>& netSettings = Prj().GetProjectFile().NetSettings();
  109. int sizeChoice = Schematic().Settings().m_JunctionSizeChoice;
  110. int dotSize = netSettings->m_DefaultNetClass->GetWireWidth() * sizeMultipliers[ sizeChoice ];
  111. return std::max( dotSize, 1 );
  112. }
  113. void SCH_EDIT_FRAME::saveProjectSettings()
  114. {
  115. wxFileName fn = Schematic().RootScreen()->GetFileName(); //ConfigFileName
  116. fn.SetExt( FILEEXT::ProjectFileExtension );
  117. if( !fn.HasName() || !IsWritable( fn, false ) )
  118. return;
  119. Schematic().RecordERCExclusions();
  120. if( Kiway().Player( FRAME_SIMULATOR, false ) )
  121. Prj().GetProjectFile().m_SchematicSettings->m_NgspiceSettings->SaveToFile();
  122. // Save the page layout file if doesn't exist yet (e.g. if we opened a non-kicad schematic)
  123. // TODO: We need to remove dependence on BASE_SCREEN
  124. Prj().GetProjectFile().m_SchematicSettings->m_SchDrawingSheetFileName
  125. = BASE_SCREEN::m_DrawingSheetFileName;
  126. if( !BASE_SCREEN::m_DrawingSheetFileName.IsEmpty() )
  127. {
  128. wxFileName layoutfn( DS_DATA_MODEL::ResolvePath( BASE_SCREEN::m_DrawingSheetFileName,
  129. Prj().GetProjectPath() ) );
  130. bool success = true;
  131. if( !layoutfn.IsAbsolute() )
  132. success = layoutfn.MakeAbsolute( Prj().GetProjectPath() );
  133. if( success && layoutfn.IsOk() && !layoutfn.FileExists() )
  134. {
  135. if( layoutfn.DirExists() && layoutfn.IsDirWritable() )
  136. DS_DATA_MODEL::GetTheInstance().Save( layoutfn.GetFullPath() );
  137. }
  138. }
  139. GetSettingsManager()->SaveProject( fn.GetFullPath() );
  140. }
  141. void SCH_EDIT_FRAME::SaveProjectLocalSettings()
  142. {
  143. if( m_schematic )
  144. m_schematic->RecordERCExclusions();
  145. }
  146. void SCH_EDIT_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
  147. {
  148. // For now, axes are forced off in Eeschema even if turned on in config
  149. EESCHEMA_SETTINGS* cfg = eeconfig();
  150. cfg->m_Window.grid.axes_enabled = false;
  151. SCH_BASE_FRAME::LoadSettings( cfg );
  152. SCH_SEARCH_DATA* searchData = dynamic_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() );
  153. if( searchData )
  154. {
  155. searchData->replaceReferences = cfg->m_FindReplaceExtra.replace_references;
  156. searchData->searchAllFields = cfg->m_FindReplaceExtra.search_all_fields;
  157. searchData->searchAllPins = cfg->m_FindReplaceExtra.search_all_pins;
  158. searchData->searchCurrentSheetOnly = cfg->m_FindReplaceExtra.search_current_sheet_only;
  159. searchData->searchSelectedOnly = cfg->m_FindReplaceExtra.search_selected_only;
  160. }
  161. m_show_search = cfg->m_AuiPanels.show_search;
  162. GetRenderSettings()->m_ShowPinsElectricalType = false;
  163. GetRenderSettings()->m_ShowPinNumbers = false;
  164. GetRenderSettings()->SetDefaultFont( cfg->m_Appearance.default_font );
  165. }
  166. void SCH_EDIT_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
  167. {
  168. EESCHEMA_SETTINGS* cfg = eeconfig();
  169. SCH_BASE_FRAME::SaveSettings( cfg );
  170. wxAuiPaneInfo& hierarchy_pane = m_auimgr.GetPane( SchematicHierarchyPaneName() );
  171. if( cfg )
  172. {
  173. cfg->m_System.units = static_cast<int>( GetUserUnits() );
  174. cfg->m_AuiPanels.show_schematic_hierarchy = hierarchy_pane.IsShown();
  175. cfg->m_AuiPanels.schematic_hierarchy_float = hierarchy_pane.IsFloating();
  176. // Other parameters (hierarchy_panel_float_width, hierarchy_panel_float_height,
  177. // and hierarchy_panel_docked_width should have been updated when resizing the
  178. // hierarchy panel
  179. SCH_SEARCH_DATA* searchData = dynamic_cast<SCH_SEARCH_DATA*>( m_findReplaceData.get() );
  180. if( searchData )
  181. {
  182. cfg->m_FindReplaceExtra.replace_references = searchData->replaceReferences;
  183. cfg->m_FindReplaceExtra.search_all_fields = searchData->searchAllFields;
  184. cfg->m_FindReplaceExtra.search_all_pins = searchData->searchAllPins;
  185. cfg->m_FindReplaceExtra.search_current_sheet_only =
  186. searchData->searchCurrentSheetOnly;
  187. cfg->m_FindReplaceExtra.search_selected_only = searchData->searchSelectedOnly;
  188. }
  189. wxAuiPaneInfo& searchPaneInfo = m_auimgr.GetPane( SearchPaneName() );
  190. m_show_search = searchPaneInfo.IsShown();
  191. cfg->m_AuiPanels.show_search = m_show_search;
  192. cfg->m_AuiPanels.search_panel_height = m_searchPane->GetSize().y;
  193. cfg->m_AuiPanels.search_panel_width = m_searchPane->GetSize().x;
  194. cfg->m_AuiPanels.search_panel_dock_direction = searchPaneInfo.dock_direction;
  195. wxAuiPaneInfo& propertiesPane = m_auimgr.GetPane( PropertiesPaneName() );
  196. cfg->m_AuiPanels.show_properties = propertiesPane.IsShown();
  197. cfg->m_AuiPanels.properties_splitter = m_propertiesPanel->SplitterProportion();
  198. cfg->m_AuiPanels.properties_panel_width = m_propertiesPanel->GetSize().x;
  199. wxAuiPaneInfo& netNavigatorPane = m_auimgr.GetPane( NetNavigatorPaneName() );
  200. cfg->m_AuiPanels.show_net_nav_panel = netNavigatorPane.IsShown();
  201. cfg->m_AuiPanels.float_net_nav_panel = netNavigatorPane.IsFloating();
  202. if( netNavigatorPane.IsDocked() )
  203. cfg->m_AuiPanels.net_nav_panel_docked_size = m_netNavigator->GetSize();
  204. else
  205. {
  206. cfg->m_AuiPanels.net_nav_panel_float_pos = netNavigatorPane.floating_pos;
  207. cfg->m_AuiPanels.net_nav_panel_float_size = netNavigatorPane.floating_size;
  208. }
  209. }
  210. }
  211. void SCH_BASE_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
  212. {
  213. wxCHECK_RET( aCfg, "Call to SCH_BASE_FRAME::LoadSettings with null settings" );
  214. EDA_DRAW_FRAME::LoadSettings( aCfg );
  215. if( aCfg->m_Window.grid.grids.empty() )
  216. aCfg->m_Window.grid.grids = aCfg->DefaultGridSizeList();
  217. // Move legacy user grids to grid list
  218. if( !aCfg->m_Window.grid.user_grid_x.empty() )
  219. {
  220. aCfg->m_Window.grid.grids.emplace_back( GRID{ "User Grid", aCfg->m_Window.grid.user_grid_x,
  221. aCfg->m_Window.grid.user_grid_y } );
  222. aCfg->m_Window.grid.user_grid_x = wxEmptyString;
  223. aCfg->m_Window.grid.user_grid_y = wxEmptyString;
  224. }
  225. if( aCfg->m_Window.grid.last_size_idx > (int) aCfg->m_Window.grid.grids.size() )
  226. aCfg->m_Window.grid.last_size_idx = 1;
  227. if( aCfg->m_Window.grid.fast_grid_1 > (int) aCfg->m_Window.grid.grids.size() )
  228. aCfg->m_Window.grid.fast_grid_1 = 1;
  229. if( aCfg->m_Window.grid.fast_grid_2 > (int) aCfg->m_Window.grid.grids.size() )
  230. aCfg->m_Window.grid.fast_grid_2 = 2;
  231. if( aCfg->m_Window.zoom_factors.empty() )
  232. {
  233. aCfg->m_Window.zoom_factors = { ZOOM_LIST_EESCHEMA };
  234. }
  235. }
  236. void SCH_BASE_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
  237. {
  238. wxCHECK_RET( aCfg, wxS( "Call to SCH_BASE_FRAME::SaveSettings with null settings" ) );
  239. EDA_DRAW_FRAME::SaveSettings( aCfg );
  240. }