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.

229 lines
8.7 KiB

18 years ago
14 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 2012 Wayne Stambaugh <stambaughw@gmail.com>
  7. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. #include <fctsys.h>
  27. #include <pcb_edit_frame.h>
  28. #include <panel_hotkeys_editor.h>
  29. #include <panel_edit_options.h>
  30. #include <panel_pcbnew_color_settings.h>
  31. #include <panel_display_options.h>
  32. #include <panel_pcbnew_action_plugins.h>
  33. #include <panel_pcbnew_display_origin.h>
  34. #include <tool/tool_manager.h>
  35. #include <tools/selection_tool.h>
  36. #include <ws_data_model.h>
  37. #include <pcbplot.h>
  38. #include <pcb_painter.h>
  39. #include <invoke_pcb_dialog.h>
  40. #include <widgets/appearance_controls.h>
  41. #include <widgets/paged_dialog.h>
  42. #include <widgets/panel_selection_filter.h>
  43. #include <project/net_settings.h>
  44. #include <project/project_file.h>
  45. #include <project/project_local_settings.h>
  46. void PCB_EDIT_FRAME::On3DShapeLibWizard( wxCommandEvent& event )
  47. {
  48. #ifdef BUILD_GITHUB_PLUGIN
  49. Invoke3DShapeLibsDownloaderWizard( this );
  50. #endif
  51. }
  52. void PCB_EDIT_FRAME::InstallPreferences( PAGED_DIALOG* aParent,
  53. PANEL_HOTKEYS_EDITOR* aHotkeysPanel )
  54. {
  55. wxTreebook* book = aParent->GetTreebook();
  56. book->AddPage( new wxPanel( book ), _( "Pcbnew" ) );
  57. book->AddSubPage( new PANEL_DISPLAY_OPTIONS( this, aParent ), _( "Display Options" ) );
  58. book->AddSubPage( new PANEL_EDIT_OPTIONS( this, aParent ), _( "Editing Options" ) );
  59. book->AddSubPage( new PANEL_PCBNEW_COLOR_SETTINGS( this, book ), _( "Colors" ) );
  60. #if defined(KICAD_SCRIPTING) && defined(KICAD_SCRIPTING_ACTION_MENU)
  61. book->AddSubPage( new PANEL_PCBNEW_ACTION_PLUGINS( this, aParent ), _( "Action Plugins" ) );
  62. #endif
  63. book->AddSubPage( new PANEL_PCBNEW_DISPLAY_ORIGIN( this, aParent ), _( "Origins & Axes" ) );
  64. aHotkeysPanel->AddHotKeys( GetToolManager() );
  65. }
  66. bool PCB_EDIT_FRAME::LoadProjectSettings()
  67. {
  68. PROJECT_FILE& project = Prj().GetProjectFile();
  69. PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
  70. BASE_SCREEN::m_PageLayoutDescrFileName = project.m_BoardPageLayoutDescrFile;
  71. // Load the page layout decr file, from the filename stored in
  72. // BASE_SCREEN::m_PageLayoutDescrFileName, read in config project file
  73. // If empty, or not existing, the default descr is loaded
  74. WS_DATA_MODEL& pglayout = WS_DATA_MODEL::GetTheInstance();
  75. wxString filename = WS_DATA_MODEL::MakeFullFileName( BASE_SCREEN::m_PageLayoutDescrFileName,
  76. Prj().GetProjectPath() );
  77. pglayout.SetPageLayout( filename );
  78. // Load render settings that aren't stored in PCB_DISPLAY_OPTIONS
  79. NET_SETTINGS& netSettings = project.NetSettings();
  80. NETINFO_LIST& nets = GetBoard()->GetNetInfo();
  81. KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
  82. GetCanvas()->GetView()->GetPainter()->GetSettings() );
  83. std::set<int>& hiddenNets = rs->GetHiddenNets();
  84. hiddenNets.clear();
  85. for( const wxString& hidden : localSettings.m_HiddenNets )
  86. {
  87. if( NETINFO_ITEM* net = nets.GetNetItem( hidden ) )
  88. hiddenNets.insert( net->GetNet() );
  89. }
  90. std::map<int, KIGFX::COLOR4D>& netColors = rs->GetNetColorMap();
  91. netColors.clear();
  92. for( const auto& pair : netSettings.m_PcbNetColors )
  93. {
  94. if( pair.second == COLOR4D::UNSPECIFIED )
  95. continue;
  96. if( NETINFO_ITEM* net = nets.GetNetItem( pair.first ) )
  97. netColors[net->GetNet()] = pair.second;
  98. }
  99. std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
  100. netclassColors.clear();
  101. for( const auto& pair : netSettings.m_NetClasses )
  102. netclassColors[pair.first] = pair.second->GetPcbColor();
  103. m_appearancePanel->SetUserLayerPresets( project.m_LayerPresets );
  104. SELECTION_FILTER_OPTIONS& filterOpts = GetToolManager()->GetTool<SELECTION_TOOL>()->GetFilter();
  105. filterOpts = localSettings.m_SelectionFilter;
  106. m_selectionFilterPanel->SetCheckboxesFromFilter( filterOpts );
  107. PCB_DISPLAY_OPTIONS opts = GetDisplayOptions();
  108. opts.m_ContrastModeDisplay = localSettings.m_ContrastModeDisplay;
  109. opts.m_NetColorMode = localSettings.m_NetColorMode;
  110. opts.m_RatsnestMode = localSettings.m_RatsnestMode;
  111. opts.m_TrackOpacity = localSettings.m_TrackOpacity;
  112. opts.m_ViaOpacity = localSettings.m_ViaOpacity;
  113. opts.m_PadOpacity = localSettings.m_PadOpacity;
  114. opts.m_ZoneOpacity = localSettings.m_ZoneOpacity;
  115. SetDisplayOptions( opts );
  116. wxFileName fn( GetCurrentFileName() );
  117. fn.MakeRelativeTo( Prj().GetProjectPath() );
  118. LoadWindowState( fn.GetFullPath() );
  119. return true;
  120. }
  121. void PCB_EDIT_FRAME::SaveProjectSettings()
  122. {
  123. wxFileName fn = Prj().GetProjectFullName();
  124. // Check for the filename before checking IsWritable as this
  125. // will throw errors on bad names. Here, we just want to not
  126. // save the Settings if we don't have a name
  127. if( !fn.IsOk() )
  128. return;
  129. if( !fn.IsDirWritable() )
  130. return;
  131. PROJECT_FILE& project = Prj().GetProjectFile();
  132. PROJECT_LOCAL_SETTINGS& localSettings = Prj().GetLocalSettings();
  133. // TODO: Can this be pulled out of BASE_SCREEN?
  134. project.m_BoardPageLayoutDescrFile = BASE_SCREEN::m_PageLayoutDescrFileName;
  135. project.m_LayerPresets = m_appearancePanel->GetUserLayerPresets();
  136. RecordDRCExclusions();
  137. // Save appearance control settings
  138. localSettings.m_ActiveLayer = GetActiveLayer();
  139. localSettings.m_ActiveLayerPreset = m_appearancePanel->GetActiveLayerPreset();
  140. const PCB_DISPLAY_OPTIONS& displayOpts = GetDisplayOptions();
  141. localSettings.m_ContrastModeDisplay = displayOpts.m_ContrastModeDisplay;
  142. localSettings.m_NetColorMode = displayOpts.m_NetColorMode;
  143. localSettings.m_RatsnestMode = displayOpts.m_RatsnestMode;
  144. localSettings.m_TrackOpacity = displayOpts.m_TrackOpacity;
  145. localSettings.m_ViaOpacity = displayOpts.m_ViaOpacity;
  146. localSettings.m_PadOpacity = displayOpts.m_PadOpacity;
  147. localSettings.m_ZoneOpacity = displayOpts.m_ZoneOpacity;
  148. localSettings.m_ZoneDisplayMode = displayOpts.m_ZoneDisplayMode;
  149. // Save render settings that aren't stored in PCB_DISPLAY_OPTIONS
  150. KIGFX::PCB_RENDER_SETTINGS* rs = static_cast<KIGFX::PCB_RENDER_SETTINGS*>(
  151. GetCanvas()->GetView()->GetPainter()->GetSettings() );
  152. NETINFO_LIST& nets = GetBoard()->GetNetInfo();
  153. localSettings.m_HiddenNets.clear();
  154. for( int netcode : rs->GetHiddenNets() )
  155. {
  156. if( NETINFO_ITEM* net = nets.GetNetItem( netcode ) )
  157. localSettings.m_HiddenNets.emplace_back( net->GetNetname() );
  158. }
  159. NET_SETTINGS& netSettings = project.NetSettings();
  160. netSettings.m_PcbNetColors.clear();
  161. for( const std::pair<const int, KIGFX::COLOR4D>& pair : rs->GetNetColorMap() )
  162. {
  163. if( NETINFO_ITEM* net = nets.GetNetItem( pair.first ) )
  164. netSettings.m_PcbNetColors[net->GetNetname()] = pair.second;
  165. }
  166. std::map<wxString, KIGFX::COLOR4D>& netclassColors = rs->GetNetclassColorMap();
  167. // NOTE: this assumes netclasses will have already been updated, which I think is the case
  168. for( const std::pair<const wxString, NETCLASSPTR>& pair : netSettings.m_NetClasses )
  169. {
  170. if( netclassColors.count( pair.first ) )
  171. pair.second->SetPcbColor( netclassColors.at( pair.first ) );
  172. }
  173. SELECTION_FILTER_OPTIONS& filterOpts = GetToolManager()->GetTool<SELECTION_TOOL>()->GetFilter();
  174. localSettings.m_SelectionFilter = filterOpts;
  175. if( !Prj().IsNullProject() )
  176. GetSettingsManager()->SaveProject();
  177. }