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.

306 lines
10 KiB

3 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
3 years ago
3 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) 1992-2015 jean-pierre.charras
  5. * Copyright (C) 1992-2023 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 3
  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 along
  18. * with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <wx/msgdlg.h>
  21. #include <wx/treebook.h>
  22. #include <wx/sizer.h>
  23. #include <typeinfo>
  24. #include <bitmaps.h>
  25. #include <bitmap_store.h>
  26. #include <geometry/shape_poly_set.h>
  27. #include <kiface_base.h>
  28. #include <attenuators/attenuator_classes.h>
  29. #include <pcb_calculator_frame.h>
  30. #include <pcb_calculator_settings.h>
  31. #include <calculator_panels/panel_rf_attenuators.h>
  32. #include <calculator_panels/panel_board_class.h>
  33. #include <calculator_panels/panel_cable_size.h>
  34. #include <calculator_panels/panel_galvanic_corrosion.h>
  35. #include <calculator_panels/panel_color_code.h>
  36. #include <calculator_panels/panel_electrical_spacing.h>
  37. #include <calculator_panels/panel_eseries.h>
  38. #include <calculator_panels/panel_fusing_current.h>
  39. #include <calculator_panels/panel_regulator.h>
  40. #include <calculator_panels/panel_track_width.h>
  41. #include <calculator_panels/panel_transline.h>
  42. #include <calculator_panels/panel_via_size.h>
  43. #include <calculator_panels/panel_wavelength.h>
  44. PCB_CALCULATOR_FRAME::PCB_CALCULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
  45. KIWAY_PLAYER( aParent, wxID_ANY, _( "Calculator Tools" ), wxDefaultPosition, wxSize( 646, 361 ),
  46. wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER|wxFULL_REPAINT_ON_RESIZE|wxTAB_TRAVERSAL,
  47. wxT( "calculator_tools" ) ),
  48. m_lastNotebookPage( -1 )
  49. {
  50. SHAPE_POLY_SET dummy; // A ugly trick to force the linker to include
  51. // some methods in code and avoid link errors
  52. SetKiway( this, aKiway );
  53. SetSizeHints( wxDefaultSize, wxDefaultSize );
  54. m_mainSizer = new wxBoxSizer( wxVERTICAL );
  55. m_treebook = new wxTreebook( this, wxID_ANY );
  56. m_treebook->SetFont( KIUI::GetControlFont( this ) );
  57. m_mainSizer->Add( m_treebook, 1, wxEXPAND | wxLEFT | wxTOP, 0 );
  58. SetSizer( m_mainSizer );
  59. Layout();
  60. Centre( wxBOTH );
  61. m_treebook->AddPage( nullptr, _( "General system design" ) );
  62. AddCalculator( new PANEL_REGULATOR( m_treebook ), _( "Regulators" ) );
  63. m_treebook->AddPage( nullptr, _( "Power, current and isolation" ) );
  64. AddCalculator( new PANEL_ELECTRICAL_SPACING( m_treebook ), _( "Electrical Spacing" ) );
  65. AddCalculator( new PANEL_VIA_SIZE( m_treebook ), _( "Via Size" ) );
  66. AddCalculator( new PANEL_TRACK_WIDTH( m_treebook ), _( "Track Width" ) );
  67. AddCalculator( new PANEL_FUSING_CURRENT( m_treebook ), _( "Fusing Current" ) );
  68. AddCalculator( new PANEL_CABLE_SIZE( m_treebook ), _( "Cable Size" ) );
  69. m_treebook->AddPage( nullptr, _( "High speed" ) );
  70. AddCalculator( new PANEL_WAVELENGTH( m_treebook ), _( "Wavelength" ) );
  71. AddCalculator( new PANEL_RF_ATTENUATORS( m_treebook ), _( "RF Attenuators" ) );
  72. AddCalculator( new PANEL_TRANSLINE( m_treebook ), _( "Transmission Lines") );
  73. m_treebook->AddPage( nullptr, _( "Memo" ) );
  74. AddCalculator( new PANEL_E_SERIES( m_treebook ), _( "E-Series" ) );
  75. AddCalculator( new PANEL_COLOR_CODE( m_treebook ), _( "Color Code" ) );
  76. AddCalculator( new PANEL_BOARD_CLASS( m_treebook ), _("Board Classes") );
  77. AddCalculator( new PANEL_GALVANIC_CORROSION( m_treebook ), _( "Galvanic Corrosion" ) );
  78. LoadSettings( config() );
  79. if( PANEL_REGULATOR* regPanel = GetCalculator<PANEL_REGULATOR>() )
  80. regPanel->ReadDataFile();
  81. // Give an icon
  82. wxIcon icon;
  83. wxIconBundle icon_bundle;
  84. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pcbcalculator ) );
  85. icon_bundle.AddIcon( icon );
  86. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pcbcalculator_32 ) );
  87. icon_bundle.AddIcon( icon );
  88. icon.CopyFromBitmap( KiBitmap( BITMAPS::icon_pcbcalculator_16 ) );
  89. icon_bundle.AddIcon( icon );
  90. SetIcons( icon_bundle );
  91. GetSizer()->SetSizeHints( this );
  92. // Set previous size and position
  93. SetSize( m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
  94. if( m_framePos == wxDefaultPosition )
  95. Centre();
  96. // Expand treebook to show all options:
  97. for( size_t pageId = 0; pageId < m_treebook->GetPageCount(); pageId++ )
  98. m_treebook->ExpandNode( pageId );
  99. // Connect Events
  100. Bind( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( PCB_CALCULATOR_FRAME::OnClosePcbCalc ), this );
  101. Bind( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( PCB_CALCULATOR_FRAME::OnUpdateUI ), this );
  102. Bind( wxEVT_SYS_COLOUR_CHANGED,
  103. wxSysColourChangedEventHandler( PCB_CALCULATOR_FRAME::onThemeChanged ), this );
  104. m_treebook->Connect( wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED, wxTreebookEventHandler(
  105. PCB_CALCULATOR_FRAME::OnPageChanged ), nullptr, this );
  106. }
  107. PCB_CALCULATOR_FRAME::~PCB_CALCULATOR_FRAME()
  108. {
  109. m_treebook->Disconnect( wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED, wxTreebookEventHandler(
  110. PCB_CALCULATOR_FRAME::OnPageChanged ), nullptr, this );
  111. // This needed for OSX: avoids further OnDraw processing after this destructor and before
  112. // the native window is destroyed
  113. this->Freeze();
  114. }
  115. void PCB_CALCULATOR_FRAME::OnPageChanged ( wxTreebookEvent& aEvent )
  116. {
  117. int page = aEvent.GetSelection();
  118. // If the selected page is a top level page
  119. if ( m_treebook->GetPageParent( page ) == wxNOT_FOUND )
  120. {
  121. m_treebook->ExpandNode( page );
  122. // Select the first child
  123. m_treebook->ChangeSelection( page + 1 );
  124. }
  125. }
  126. void PCB_CALCULATOR_FRAME::AddCalculator( CALCULATOR_PANEL *aPanel, const wxString& panelUIName )
  127. {
  128. // Update internal structures
  129. m_panels.push_back( aPanel );
  130. m_panelTypes[ typeid( *aPanel ).hash_code() ] = aPanel;
  131. m_treebook->AddSubPage( aPanel, panelUIName );
  132. }
  133. void PCB_CALCULATOR_FRAME::onThemeChanged( wxSysColourChangedEvent& aEvent )
  134. {
  135. // Force the bitmaps to refresh
  136. GetBitmapStore()->ThemeChanged();
  137. // Update the panels
  138. for( auto& panel : m_panels )
  139. panel->ThemeChanged();
  140. aEvent.Skip();
  141. }
  142. void PCB_CALCULATOR_FRAME::OnUpdateUI( wxUpdateUIEvent& event )
  143. {
  144. if( m_treebook->GetSelection() != m_lastNotebookPage )
  145. {
  146. // Kick all the things that wxWidgets can't seem to redraw on its own.
  147. // This is getting seriously ridiculous....
  148. PANEL_TRANSLINE* translinePanel = GetCalculator<PANEL_TRANSLINE>();
  149. PANEL_RF_ATTENUATORS* attenPanel = GetCalculator<PANEL_RF_ATTENUATORS>();
  150. PANEL_VIA_SIZE* viaSizePanel = GetCalculator<PANEL_VIA_SIZE>();
  151. PANEL_REGULATOR* regulPanel = GetCalculator<PANEL_REGULATOR>();
  152. PANEL_ELECTRICAL_SPACING* elecSpacingPanel = GetCalculator<PANEL_ELECTRICAL_SPACING>();
  153. wxASSERT( translinePanel );
  154. wxASSERT( attenPanel );
  155. wxASSERT( viaSizePanel );
  156. wxASSERT( regulPanel );
  157. wxASSERT( elecSpacingPanel );
  158. {
  159. wxCommandEvent event2( wxEVT_RADIOBUTTON );
  160. event2.SetEventObject( translinePanel->GetTranslineSelector() );
  161. event2.SetInt( translinePanel->GetCurrTransLineType() );
  162. translinePanel->GetTranslineSelector()->Command( event2 );
  163. }
  164. for( int i = 0; i < attenPanel->m_AttenuatorList.size(); ++i )
  165. {
  166. if( attenPanel->m_AttenuatorList[i] == attenPanel->m_CurrAttenuator )
  167. {
  168. wxCommandEvent event2( wxEVT_RADIOBUTTON );
  169. event2.SetEventObject( attenPanel->GetAttenuatorsSelector() );
  170. event2.SetInt( i );
  171. attenPanel->GetAttenuatorsSelector()->Command( event2 );
  172. break;
  173. }
  174. }
  175. attenPanel->UpdateUI();
  176. viaSizePanel->Layout();
  177. regulPanel->Layout();
  178. // Until it's shown on screen the above won't work; but doing it anyway at least keeps
  179. // putting new OnUpdateUI events into the queue until it *is* shown on screen.
  180. if( m_treebook->IsShownOnScreen() )
  181. m_lastNotebookPage = m_treebook->GetSelection();
  182. }
  183. }
  184. void PCB_CALCULATOR_FRAME::OnClosePcbCalc( wxCloseEvent& event )
  185. {
  186. PANEL_REGULATOR* regPanel = GetCalculator<PANEL_REGULATOR>();
  187. wxASSERT( regPanel );
  188. if( regPanel->m_RegulatorListChanged )
  189. {
  190. wxString msg;
  191. wxString title = _( "Write Data Failed" );
  192. if( regPanel->GetDataFilename().IsEmpty() )
  193. {
  194. msg = _( "No data filename to save modifications.\n"
  195. "Do you want to exit and abandon your changes?" );
  196. if( wxMessageBox( msg, title, wxYES_NO | wxICON_QUESTION ) == wxNO )
  197. return;
  198. }
  199. else
  200. {
  201. if( !regPanel->WriteDataFile() )
  202. {
  203. msg.Printf( _( "Unable to write file '%s'\n"
  204. "Do you want to exit and abandon your changes?"),
  205. regPanel->GetDataFilename() );
  206. if( wxMessageBox( msg, title, wxYES_NO | wxICON_ERROR ) == wxNO )
  207. return;
  208. }
  209. }
  210. }
  211. event.Skip();
  212. }
  213. void PCB_CALCULATOR_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
  214. {
  215. if( aCfg == nullptr )
  216. return;
  217. EDA_BASE_FRAME::LoadSettings( aCfg );
  218. PCB_CALCULATOR_SETTINGS* cfg = static_cast<PCB_CALCULATOR_SETTINGS*>( aCfg );
  219. m_treebook->ChangeSelection( cfg->m_LastPage );
  220. for( CALCULATOR_PANEL* panel : m_panels )
  221. panel->LoadSettings( cfg );
  222. }
  223. void PCB_CALCULATOR_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
  224. {
  225. if( aCfg == nullptr )
  226. return;
  227. EDA_BASE_FRAME::SaveSettings( aCfg );
  228. // Save current parameters values in config.
  229. auto cfg = dynamic_cast<PCB_CALCULATOR_SETTINGS*>( Kiface().KifaceSettings() );
  230. if( cfg )
  231. {
  232. cfg->m_LastPage = m_treebook->GetSelection();
  233. for( CALCULATOR_PANEL* panel : m_panels )
  234. panel->SaveSettings( cfg );
  235. }
  236. }