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.

406 lines
13 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. * Creates a column at the end of m_signalsGrid named "Cursor n" ( n = m_customCursorsCnt ),
  76. * increases m_customCursorsCnt,
  77. * emplaces a vector to m_cursorFormatsDyn,
  78. * and update widgets
  79. */
  80. void CreateNewCursor();
  81. /**
  82. * Deletes last m_signalsGrid "Cursor n" column,
  83. * removes vector's m_cursorFormatsDyn last entry,
  84. * reduces m_customCursorsCnt by one, and update widgets
  85. */
  86. void DeleteCursor();
  87. /**
  88. * Add a new trace to the current plot.
  89. *
  90. * @param aName is the device/net name.
  91. * @param aType describes the type of trace.
  92. */
  93. void AddTrace( const wxString& aName, SIM_TRACE_TYPE aType );
  94. /**
  95. * Get/Set the number of significant digits and the range for formatting a cursor value.
  96. * @param aValueCol 0 indicates the X value column; 1 the Y value.
  97. */
  98. SPICE_VALUE_FORMAT GetCursorFormat( int aCursorId, int aValueCol ) const
  99. {
  100. return m_cursorFormatsDyn[aCursorId][aValueCol];
  101. }
  102. void SetCursorFormat( int aCursorId, int aValueCol, const SPICE_VALUE_FORMAT& aFormat )
  103. {
  104. m_cursorFormatsDyn[ aCursorId ][ aValueCol ] = aFormat;
  105. wxCommandEvent dummy;
  106. onPlotCursorUpdate( dummy );
  107. }
  108. /**
  109. * Add a tuner for a symbol.
  110. */
  111. void AddTuner( const SCH_SHEET_PATH& aSheetPath, SCH_SYMBOL* aSymbol );
  112. /**
  113. * Remove an existing tuner.
  114. */
  115. void RemoveTuner( TUNER_SLIDER* aTuner );
  116. /**
  117. * Safely update a field of the associated symbol without dereferencing
  118. * the symbol.
  119. *
  120. * @param aSymbol id of the symbol needing updating
  121. * @param aId id of the symbol field
  122. * @param aValue new value of the symbol field
  123. */
  124. void UpdateTunerValue( const SCH_SHEET_PATH& aSheetPath, const KIID& aSymbol,
  125. const wxString& aRef, const wxString& aValue );
  126. /**
  127. * Add a measurement to the measurements grid.
  128. */
  129. void AddMeasurement( const wxString& aCmd );
  130. /**
  131. * Delete a row from the measurements grid.
  132. */
  133. void DeleteMeasurement( int aRow );
  134. /**
  135. * Get/Set the format of a value in the measurements grid.
  136. */
  137. SPICE_VALUE_FORMAT GetMeasureFormat( int aRow ) const;
  138. void SetMeasureFormat( int aRow, const SPICE_VALUE_FORMAT& aFormat );
  139. /**
  140. * Update a measurement in the measurements grid.
  141. */
  142. void UpdateMeasurement( int aRow );
  143. void DoFourier( const wxString& aSignal, const wxString& aFundamental );
  144. /**
  145. * Return the netlist exporter object used for simulations.
  146. */
  147. const SPICE_CIRCUIT_MODEL* GetExporter() const;
  148. bool IsSimConsoleShown();
  149. void ToggleSimConsole();
  150. bool IsSimSidePanelShown();
  151. void ToggleSimSidePanel();
  152. bool DarkModePlots() const { return m_darkMode; }
  153. void ToggleDarkModePlots();
  154. void ShowChangedLanguage();
  155. /**
  156. * Load the currently active workbook stored in the project settings. If there is none,
  157. * generate a filename for the currently active workbook and store it in the project settings.
  158. */
  159. void InitWorkbook();
  160. /**
  161. * Load plot, signal, cursor, measurement, etc. settings from a file.
  162. */
  163. bool LoadWorkbook( const wxString& aPath );
  164. /**
  165. * Save plot, signal, cursor, measurement, etc. settings to a file.
  166. */
  167. bool SaveWorkbook( const wxString& aPath );
  168. void LoadSettings( EESCHEMA_SETTINGS* aCfg );
  169. void SaveSettings( EESCHEMA_SETTINGS* aCfg );
  170. /**
  171. * Called when settings are changed via the common Preferences dialog.
  172. */
  173. void ApplyPreferences( const SIM_PREFERENCES& aPrefs );
  174. /**
  175. * Adjust the sash dimension of splitter windows after reading
  176. * the config settings
  177. * must be called after the config settings are read, and once the
  178. * frame is initialized (end of the Ctor)
  179. */
  180. void SetSubWindowsSashSize();
  181. /**
  182. * Return the currently opened plot panel (or NULL if there is none).
  183. */
  184. SIM_TAB* GetCurrentSimTab() const
  185. {
  186. return dynamic_cast<SIM_TAB*>( m_plotNotebook->GetCurrentPage() );
  187. }
  188. SIM_TAB* GetSimTab( SIM_TYPE aType ) const
  189. {
  190. for( int ii = 0; ii < (int) m_plotNotebook->GetPageCount(); ++ii )
  191. {
  192. SIM_TAB* candidate = dynamic_cast<SIM_TAB*>( m_plotNotebook->GetPage( ii ) );
  193. if( candidate && candidate->GetSimType() == aType )
  194. return candidate;
  195. }
  196. return nullptr;
  197. }
  198. int GetSimTabIndex( SIM_TAB* aPlot ) const
  199. {
  200. return m_plotNotebook->GetPageIndex( aPlot );
  201. }
  202. void OnPlotSettingsChanged();
  203. void OnSimUpdate();
  204. void OnSimReport( const wxString& aMsg );
  205. void OnSimRefresh( bool aFinal );
  206. void OnModify();
  207. private:
  208. /**
  209. * Get the simulator output vector name for a given signal name and type.
  210. */
  211. wxString vectorNameFromSignalName( SIM_PLOT_TAB* aPlotTab, const wxString& aSignalName,
  212. int* aTraceType );
  213. /**
  214. * Update a trace in a particular SIM_PLOT_TAB. If the panel does not contain the given
  215. * trace, then add it.
  216. *
  217. * @param aVectorName is the SPICE vector name, such as "I(Net-C1-Pad1)".
  218. * @param aTraceType describes the type of plot.
  219. * @param aPlotTab is the tab that should receive the update.
  220. */
  221. void updateTrace( const wxString& aVectorName, int aTraceType, SIM_PLOT_TAB* aPlotTab,
  222. std::vector<double>* aDataX = nullptr, bool aClearData = false );
  223. /**
  224. * A common toggler for the two main wxSplitterWindow s
  225. */
  226. void TogglePanel( wxPanel* aPanel, wxSplitterWindow* aSplitterWindow, int& aSashPosition );
  227. /**
  228. * Init handler for custom cursors
  229. *
  230. * Called once in class's body
  231. */
  232. void CustomCursorsInit();
  233. /**
  234. * Rebuild the list of signals available from the netlist.
  235. *
  236. * Note: this is not the filtered list. See rebuildSignalsGrid() for that.
  237. */
  238. void rebuildSignalsList();
  239. /**
  240. * Rebuild the filtered list of signals in the signals grid.
  241. */
  242. void rebuildSignalsGrid( wxString aFilter );
  243. /**
  244. * Update the values in the signals grid.
  245. */
  246. void updateSignalsGrid();
  247. /**
  248. * Update the cursor values (in the grid) and graphics (in the plot window).
  249. */
  250. void updatePlotCursors();
  251. /**
  252. * Updates m_signalsGrid cursor widget, column rendering and attributes
  253. *
  254. * @param t is the type of the enum that holds m_signalsGrid column indexing
  255. * @param u a cursor "ID". Applies a 2 integer offset against the enum indexing
  256. * @param r is a wxGrid widget's row
  257. */
  258. template <typename T, typename U, typename R>
  259. void signalsGridCursorUpdate( T t, U u, R r );
  260. /**
  261. * Apply user-defined signals to the SPICE session.
  262. */
  263. void applyUserDefinedSignals();
  264. /**
  265. * Rebuild the measurements grid for the current plot.
  266. */
  267. void rebuildMeasurementsGrid();
  268. void updateMeasurementsFromGrid();
  269. /**
  270. * Apply component values specified using tuner sliders to the current netlist.
  271. */
  272. void applyTuners();
  273. /**
  274. * Return X axis for a given simulation type.
  275. */
  276. SIM_TRACE_TYPE getXAxisType( SIM_TYPE aType ) const;
  277. wxString getNoiseSource() const;
  278. void parseTraceParams( SIM_PLOT_TAB* aPlotTab, TRACE* aTrace, const wxString& aSignalName,
  279. const wxString& aParams );
  280. std::shared_ptr<SPICE_SIMULATOR> simulator() const;
  281. std::shared_ptr<SPICE_CIRCUIT_MODEL> circuitModel() const;
  282. // Event handlers
  283. void onPlotClose( wxAuiNotebookEvent& event ) override;
  284. void onPlotClosed( wxAuiNotebookEvent& event ) override;
  285. void onPlotChanging( wxAuiNotebookEvent& event ) override;
  286. void onPlotChanged( wxAuiNotebookEvent& event ) override;
  287. void onPlotDragged( wxAuiNotebookEvent& event ) override;
  288. void OnFilterText( wxCommandEvent& aEvent ) override;
  289. void OnFilterMouseMoved( wxMouseEvent& aEvent ) override;
  290. void onSignalsGridCellChanged( wxGridEvent& aEvent ) override;
  291. void onCursorsGridCellChanged( wxGridEvent& aEvent ) override;
  292. void onMeasurementsGridCellChanged( wxGridEvent& aEvent ) override;
  293. void OnUpdateUI( wxUpdateUIEvent& event ) override;
  294. bool loadLegacyWorkbook( const wxString & aPath );
  295. bool loadJsonWorkbook( const wxString & aPath );
  296. void SaveCursorToWorkbook( nlohmann::json& aTraceJs, TRACE* aTrace, int aCursorId );
  297. void onPlotCursorUpdate( wxCommandEvent& aEvent );
  298. public:
  299. int m_SuppressGridEvents;
  300. private:
  301. SIMULATOR_FRAME* m_simulatorFrame;
  302. SCH_EDIT_FRAME* m_schematicFrame;
  303. std::vector<wxString> m_signals;
  304. std::map<int, wxString> m_userDefinedSignals;
  305. std::list<TUNER_SLIDER*> m_tuners;
  306. ///< SPICE expressions need quoted versions of the netnames since KiCad allows '-' and '/'
  307. ///< in netnames.
  308. std::vector<wxString> m_netnames;
  309. SPICE_VALUE_FORMAT m_cursorFormats[3][2];
  310. // Holds cursor formating for m_cursorsGrid, includes m_cursorFormats[3][2], TODO: merge.
  311. std::vector<std::vector<SPICE_VALUE_FORMAT>> m_cursorFormatsDyn;
  312. // Variables for temporary storage:
  313. int m_splitterLeftRightSashPosition;
  314. int m_splitterPlotAndConsoleSashPosition;
  315. int m_splitterSignalsSashPosition;
  316. int m_splitterCursorsSashPosition;
  317. int m_splitterTuneValuesSashPosition;
  318. bool m_darkMode;
  319. unsigned int m_plotNumber;
  320. wxTimer m_refreshTimer;
  321. SIM_PREFERENCES m_preferences;
  322. // Count all available cursors in m_signalsGrid
  323. int m_customCursorsCnt; // Defaults to 2 + 1
  324. };
  325. #endif // SIMULATOR_FRAME_UI_H