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.

354 lines
11 KiB

Horizontal/vertical zoom for Simulator plots ADDED: Horizontal/vertical zoom for simulator plots, via mouse wheel, toolbar buttons, menu commands, and hotkeys. ADDED: Simulator preferences panel, populated with mouse wheel and trackpad settings that control pan and zoom of simulator plots. ADDED: Zoom In/Out Horizontally/Vertically commands that can be bound to hotkeys. CHANGED: Simulator plot scroll wheel gestures are no longer hard-coded and can now be configured via the new Simulator preferences panel. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16597 Other unreported bugs that were fixed: - Fixed wierd, jumpy simulator plot view limiting behavior. - Fixed Zoom In Center and Zoom Out Center commands not preserving the simulator plot center point. - Fixed simulator plot nudging when exported as PNGs. - Fixed rectangular selection zoom being able to exceed simulator plot view limits. Notes: - Provided new SIM_PREFERENCES struct to be used for future simulator preferences set via the simulator preferences dialog. - Bundled pre-existing EESCHEMA_SETTINGS::SIMULATOR settings into EESCHEMA_SETTINGS::SIMULATOR::VIEW. - Replaced mpWindow::EnableMouseWheelPan with more general SetMouseWheelActions. - Refactored and tidied up wxMathPlot's mpWindow code involved with fitting, zooming, and panning. - Consolidated long lists of duplicated member variable initializers to a new mpWindow private delegated constructor. - Provided provisional Zoom In/Out Horizontally/Vertically toolbar icons that need improvement by a graphics designer. - Provided gitignore entries for the Qt Creator IDE
2 years ago
Horizontal/vertical zoom for Simulator plots ADDED: Horizontal/vertical zoom for simulator plots, via mouse wheel, toolbar buttons, menu commands, and hotkeys. ADDED: Simulator preferences panel, populated with mouse wheel and trackpad settings that control pan and zoom of simulator plots. ADDED: Zoom In/Out Horizontally/Vertically commands that can be bound to hotkeys. CHANGED: Simulator plot scroll wheel gestures are no longer hard-coded and can now be configured via the new Simulator preferences panel. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16597 Other unreported bugs that were fixed: - Fixed wierd, jumpy simulator plot view limiting behavior. - Fixed Zoom In Center and Zoom Out Center commands not preserving the simulator plot center point. - Fixed simulator plot nudging when exported as PNGs. - Fixed rectangular selection zoom being able to exceed simulator plot view limits. Notes: - Provided new SIM_PREFERENCES struct to be used for future simulator preferences set via the simulator preferences dialog. - Bundled pre-existing EESCHEMA_SETTINGS::SIMULATOR settings into EESCHEMA_SETTINGS::SIMULATOR::VIEW. - Replaced mpWindow::EnableMouseWheelPan with more general SetMouseWheelActions. - Refactored and tidied up wxMathPlot's mpWindow code involved with fitting, zooming, and panning. - Consolidated long lists of duplicated member variable initializers to a new mpWindow private delegated constructor. - Provided provisional Zoom In/Out Horizontally/Vertically toolbar icons that need improvement by a graphics designer. - Provided gitignore entries for the Qt Creator IDE
2 years ago
Horizontal/vertical zoom for Simulator plots ADDED: Horizontal/vertical zoom for simulator plots, via mouse wheel, toolbar buttons, menu commands, and hotkeys. ADDED: Simulator preferences panel, populated with mouse wheel and trackpad settings that control pan and zoom of simulator plots. ADDED: Zoom In/Out Horizontally/Vertically commands that can be bound to hotkeys. CHANGED: Simulator plot scroll wheel gestures are no longer hard-coded and can now be configured via the new Simulator preferences panel. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16597 Other unreported bugs that were fixed: - Fixed wierd, jumpy simulator plot view limiting behavior. - Fixed Zoom In Center and Zoom Out Center commands not preserving the simulator plot center point. - Fixed simulator plot nudging when exported as PNGs. - Fixed rectangular selection zoom being able to exceed simulator plot view limits. Notes: - Provided new SIM_PREFERENCES struct to be used for future simulator preferences set via the simulator preferences dialog. - Bundled pre-existing EESCHEMA_SETTINGS::SIMULATOR settings into EESCHEMA_SETTINGS::SIMULATOR::VIEW. - Replaced mpWindow::EnableMouseWheelPan with more general SetMouseWheelActions. - Refactored and tidied up wxMathPlot's mpWindow code involved with fitting, zooming, and panning. - Consolidated long lists of duplicated member variable initializers to a new mpWindow private delegated constructor. - Provided provisional Zoom In/Out Horizontally/Vertically toolbar icons that need improvement by a graphics designer. - Provided gitignore entries for the Qt Creator IDE
2 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016-2023 CERN
  5. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  8. * @author Maciej Suminski <maciej.suminski@cern.ch>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 3
  13. * of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, you may find one here:
  22. * https://www.gnu.org/licenses/gpl-3.0.html
  23. * or you may search the http://www.gnu.org website for the version 3 license,
  24. * or you may write to the Free Software Foundation, Inc.,
  25. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  26. */
  27. #ifndef SIMULATOR_FRAME_UI_H
  28. #define SIMULATOR_FRAME_UI_H
  29. #include <sim/simulator_frame_ui_base.h>
  30. #include <sim/sim_types.h>
  31. #include <sim/sim_plot_tab.h>
  32. #include <sim/sim_preferences.h>
  33. #include <wx/event.h>
  34. class SCH_EDIT_FRAME;
  35. class SCH_SYMBOL;
  36. class SPICE_SIMULATOR;
  37. class SPICE_SETTINGS;
  38. class EESCHEMA_SETTINGS;
  39. class SPICE_CIRCUIT_MODEL;
  40. class SIM_THREAD_REPORTER;
  41. class TUNER_SLIDER;
  42. /**
  43. *
  44. * The SIMULATOR_FRAME_UI holds the main user-interface for running simulations.
  45. *
  46. * It contains a workbook with multiple tabs, each tab holding a SIM_PLOT_TAB, a specific
  47. * simulation command (.TRAN, .AC, etc.), and simulation settings (save all currents, etc.).
  48. *
  49. * Each plot can have multiple TRACEs. While internally each TRACE can have multiple cursors,
  50. * the GUI supports only two cursors (and a differential cursor) for each plot.
  51. *
  52. * TRACEs are identified by a signal (V(OUT), I(R2), etc.) and a type (SPT_VOLTAGE, SPT_AC_PHASE,
  53. * etc.).
  54. *
  55. * The simulator outputs simple signals in a vector of the same name. Complex signals (such as
  56. * V(OUT) / V(IN)) are stored in vectors of the format "user%d".
  57. *
  58. */
  59. class SIMULATOR_FRAME_UI : public SIMULATOR_FRAME_UI_BASE
  60. {
  61. public:
  62. SIMULATOR_FRAME_UI( SIMULATOR_FRAME* aSimulatorFrame, SCH_EDIT_FRAME* aSchematicFrame );
  63. ~SIMULATOR_FRAME_UI();
  64. /**
  65. * Create a new simulation tab for a given simulation type.
  66. *
  67. * @param aSimCommand is requested simulation command.
  68. */
  69. SIM_TAB* NewSimTab( const wxString& aSimCommand );
  70. std::vector<wxString> SimPlotVectors() const;
  71. std::vector<wxString> Signals() const;
  72. const std::map<int, wxString>& UserDefinedSignals() { return m_userDefinedSignals; }
  73. void SetUserDefinedSignals( const std::map<int, wxString>& aSignals );
  74. /**
  75. * Add a new trace to the current plot.
  76. *
  77. * @param aName is the device/net name.
  78. * @param aType describes the type of trace.
  79. */
  80. void AddTrace( const wxString& aName, SIM_TRACE_TYPE aType );
  81. /**
  82. * Get/Set the number of significant digits and the range for formatting a cursor value.
  83. * @param aValueCol 0 indicates the X value column; 1 the Y value.
  84. */
  85. SPICE_VALUE_FORMAT GetCursorFormat( int aCursorId, int aValueCol ) const
  86. {
  87. return m_cursorFormats[ aCursorId ][ aValueCol ];
  88. }
  89. void SetCursorFormat( int aCursorId, int aValueCol, const SPICE_VALUE_FORMAT& aFormat )
  90. {
  91. m_cursorFormats[ aCursorId ][ aValueCol ] = aFormat;
  92. wxCommandEvent dummy;
  93. onPlotCursorUpdate( dummy );
  94. }
  95. /**
  96. * Add a tuner for a symbol.
  97. */
  98. void AddTuner( const SCH_SHEET_PATH& aSheetPath, SCH_SYMBOL* aSymbol );
  99. /**
  100. * Remove an existing tuner.
  101. */
  102. void RemoveTuner( TUNER_SLIDER* aTuner );
  103. /**
  104. * Safely update a field of the associated symbol without dereferencing
  105. * the symbol.
  106. *
  107. * @param aSymbol id of the symbol needing updating
  108. * @param aId id of the symbol field
  109. * @param aValue new value of the symbol field
  110. */
  111. void UpdateTunerValue( const SCH_SHEET_PATH& aSheetPath, const KIID& aSymbol,
  112. const wxString& aRef, const wxString& aValue );
  113. /**
  114. * Add a measurement to the measurements grid.
  115. */
  116. void AddMeasurement( const wxString& aCmd );
  117. /**
  118. * Delete a row from the measurements grid.
  119. */
  120. void DeleteMeasurement( int aRow );
  121. /**
  122. * Get/Set the format of a value in the measurements grid.
  123. */
  124. SPICE_VALUE_FORMAT GetMeasureFormat( int aRow ) const;
  125. void SetMeasureFormat( int aRow, const SPICE_VALUE_FORMAT& aFormat );
  126. /**
  127. * Update a measurement in the measurements grid.
  128. */
  129. void UpdateMeasurement( int aRow );
  130. void DoFourier( const wxString& aSignal, const wxString& aFundamental );
  131. /**
  132. * Return the netlist exporter object used for simulations.
  133. */
  134. const SPICE_CIRCUIT_MODEL* GetExporter() const;
  135. bool DarkModePlots() const { return m_darkMode; }
  136. void ToggleDarkModePlots();
  137. void ShowChangedLanguage();
  138. /**
  139. * Load the currently active workbook stored in the project settings. If there is none,
  140. * generate a filename for the currently active workbook and store it in the project settings.
  141. */
  142. void InitWorkbook();
  143. /**
  144. * Load plot, signal, cursor, measurement, etc. settings from a file.
  145. */
  146. bool LoadWorkbook( const wxString& aPath );
  147. /**
  148. * Save plot, signal, cursor, measurement, etc. settings to a file.
  149. */
  150. bool SaveWorkbook( const wxString& aPath );
  151. void LoadSettings( EESCHEMA_SETTINGS* aCfg );
  152. void SaveSettings( EESCHEMA_SETTINGS* aCfg );
  153. /**
  154. * Called when settings are changed via the common Preferences dialog.
  155. */
  156. void ApplyPreferences( const SIM_PREFERENCES& aPrefs );
  157. // adjust the sash dimension of splitter windows after reading
  158. // the config settings
  159. // must be called after the config settings are read, and once the
  160. // frame is initialized (end of the Ctor)
  161. void SetSubWindowsSashSize();
  162. /**
  163. * Return the currently opened plot panel (or NULL if there is none).
  164. */
  165. SIM_TAB* GetCurrentSimTab() const
  166. {
  167. return dynamic_cast<SIM_TAB*>( m_plotNotebook->GetCurrentPage() );
  168. }
  169. SIM_TAB* GetSimTab( SIM_TYPE aType ) const
  170. {
  171. for( int ii = 0; ii < (int) m_plotNotebook->GetPageCount(); ++ii )
  172. {
  173. SIM_TAB* candidate = dynamic_cast<SIM_TAB*>( m_plotNotebook->GetPage( ii ) );
  174. if( candidate && candidate->GetSimType() == aType )
  175. return candidate;
  176. }
  177. return nullptr;
  178. }
  179. int GetSimTabIndex( SIM_TAB* aPlot ) const
  180. {
  181. return m_plotNotebook->GetPageIndex( aPlot );
  182. }
  183. void OnPlotSettingsChanged();
  184. void OnSimUpdate();
  185. void OnSimReport( const wxString& aMsg );
  186. void OnSimRefresh( bool aFinal );
  187. void OnModify();
  188. private:
  189. /**
  190. * Get the simulator output vector name for a given signal name and type.
  191. */
  192. wxString vectorNameFromSignalName( SIM_PLOT_TAB* aPlotTab, const wxString& aSignalName,
  193. int* aTraceType );
  194. /**
  195. * Update a trace in a particular SIM_PLOT_TAB. If the panel does not contain the given
  196. * trace, then add it.
  197. *
  198. * @param aVectorName is the SPICE vector name, such as "I(Net-C1-Pad1)".
  199. * @param aTraceType describes the type of plot.
  200. * @param aPlotTab is the tab that should receive the update.
  201. */
  202. void updateTrace( const wxString& aVectorName, int aTraceType, SIM_PLOT_TAB* aPlotTab,
  203. std::vector<double>* aDataX = nullptr, bool aClearData = false );
  204. /**
  205. * Rebuild the list of signals available from the netlist.
  206. *
  207. * Note: this is not the filtered list. See rebuildSignalsGrid() for that.
  208. */
  209. void rebuildSignalsList();
  210. /**
  211. * Rebuild the filtered list of signals in the signals grid.
  212. */
  213. void rebuildSignalsGrid( wxString aFilter );
  214. /**
  215. * Update the values in the signals grid.
  216. */
  217. void updateSignalsGrid();
  218. /**
  219. * Update the cursor values (in the grid) and graphics (in the plot window).
  220. */
  221. void updatePlotCursors();
  222. /**
  223. * Apply user-defined signals to the SPICE session.
  224. */
  225. void applyUserDefinedSignals();
  226. /**
  227. * Rebuild the measurements grid for the current plot.
  228. */
  229. void rebuildMeasurementsGrid();
  230. void updateMeasurementsFromGrid();
  231. /**
  232. * Apply component values specified using tuner sliders to the current netlist.
  233. */
  234. void applyTuners();
  235. /**
  236. * Return X axis for a given simulation type.
  237. */
  238. SIM_TRACE_TYPE getXAxisType( SIM_TYPE aType ) const;
  239. wxString getNoiseSource() const;
  240. void parseTraceParams( SIM_PLOT_TAB* aPlotTab, TRACE* aTrace, const wxString& aSignalName,
  241. const wxString& aParams );
  242. std::shared_ptr<SPICE_SIMULATOR> simulator() const;
  243. std::shared_ptr<SPICE_CIRCUIT_MODEL> circuitModel() const;
  244. // Event handlers
  245. void onPlotClose( wxAuiNotebookEvent& event ) override;
  246. void onPlotClosed( wxAuiNotebookEvent& event ) override;
  247. void onPlotChanging( wxAuiNotebookEvent& event ) override;
  248. void onPlotChanged( wxAuiNotebookEvent& event ) override;
  249. void onPlotDragged( wxAuiNotebookEvent& event ) override;
  250. void OnFilterText( wxCommandEvent& aEvent ) override;
  251. void OnFilterMouseMoved( wxMouseEvent& aEvent ) override;
  252. void onSignalsGridCellChanged( wxGridEvent& aEvent ) override;
  253. void onCursorsGridCellChanged( wxGridEvent& aEvent ) override;
  254. void onMeasurementsGridCellChanged( wxGridEvent& aEvent ) override;
  255. void OnUpdateUI( wxUpdateUIEvent& event ) override;
  256. bool loadLegacyWorkbook( const wxString & aPath );
  257. bool loadJsonWorkbook( const wxString & aPath );
  258. void onPlotCursorUpdate( wxCommandEvent& aEvent );
  259. public:
  260. int m_SuppressGridEvents;
  261. private:
  262. SIMULATOR_FRAME* m_simulatorFrame;
  263. SCH_EDIT_FRAME* m_schematicFrame;
  264. std::vector<wxString> m_signals;
  265. std::map<int, wxString> m_userDefinedSignals;
  266. std::list<TUNER_SLIDER*> m_tuners;
  267. ///< SPICE expressions need quoted versions of the netnames since KiCad allows '-' and '/'
  268. ///< in netnames.
  269. std::map<wxString, wxString> m_quotedNetnames;
  270. SPICE_VALUE_FORMAT m_cursorFormats[3][2];
  271. // Variables for temporary storage:
  272. int m_splitterLeftRightSashPosition;
  273. int m_splitterPlotAndConsoleSashPosition;
  274. int m_splitterSignalsSashPosition;
  275. int m_splitterCursorsSashPosition;
  276. int m_splitterTuneValuesSashPosition;
  277. bool m_darkMode;
  278. unsigned int m_plotNumber;
  279. wxTimer m_refreshTimer;
  280. SIM_PREFERENCES m_preferences;
  281. };
  282. #endif // SIMULATOR_FRAME_UI_H