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.

246 lines
7.2 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 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
9 years ago
9 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_H
  28. #define SIMULATOR_FRAME_H
  29. #include <sim/simulator_frame_ui_base.h>
  30. #include <sim/sim_types.h>
  31. #include <kiway_player.h>
  32. #include <dialogs/dialog_sim_command.h>
  33. #include <wx/event.h>
  34. #include <list>
  35. #include <memory>
  36. #include <map>
  37. class SCH_EDIT_FRAME;
  38. class SCH_SYMBOL;
  39. class SIMULATOR_FRAME_UI;
  40. class SIM_THREAD_REPORTER;
  41. class ACTION_TOOLBAR;
  42. class SPICE_SIMULATOR;
  43. /**
  44. * Simple error container for failure to init the simulation engine
  45. * and ultimately abort the frame construction
  46. */
  47. class SIMULATOR_INIT_ERR : public std::runtime_error
  48. {
  49. public:
  50. explicit SIMULATOR_INIT_ERR(const std::string& what_arg)
  51. : std::runtime_error(what_arg) {}
  52. };
  53. /**
  54. *
  55. * The SIMULATOR_FRAME holds the main user-interface for running simulations.
  56. *
  57. * It contains a workbook with multiple tabs, each tab holding a SIM_PLOT_TAB, a specific
  58. * simulation command (.TRAN, .AC, etc.), and simulation settings (save all currents, etc.).
  59. *
  60. * Each plot can have multiple TRACEs. While internally each TRACE can have multiple cursors,
  61. * the GUI supports only two cursors (and a differential cursor) for each plot.
  62. *
  63. * TRACEs are identified by a signal (V(OUT), I(R2), etc.) and a type (SPT_VOLTAGE, SPT_AC_PHASE,
  64. * etc.).
  65. *
  66. * The simulator outputs simple signals in a vector of the same name. Complex signals (such as
  67. * V(OUT) / V(IN)) are stored in vectors of the format "user%d".
  68. *
  69. */
  70. class SIMULATOR_FRAME : public KIWAY_PLAYER
  71. {
  72. public:
  73. SIMULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent );
  74. ~SIMULATOR_FRAME();
  75. /**
  76. * Check and load the current netlist into the simulator.
  77. * @return true if document is fully annotated and netlist was loaded successfully.
  78. */
  79. bool LoadSimulator( const wxString& aSimCommand, unsigned aSimOptions );
  80. /**
  81. * Re-send the current command and settings to the simulator. Use the existing netlist.
  82. */
  83. void ReloadSimulator( const wxString& aSimCommand, unsigned aSimOptions );
  84. void StartSimulation();
  85. /**
  86. * Create a new plot tab for a given simulation type.
  87. *
  88. * @param aSimCommand is requested simulation command.
  89. */
  90. SIM_TAB* NewSimTab( const wxString& aSimCommand );
  91. /**
  92. * Shows a dialog for editing the current tab's simulation command, or creating a new tab
  93. * with a different simulation command type.
  94. */
  95. bool EditAnalysis();
  96. /**
  97. * @return the list of vectors (signals) in the current simulation results.
  98. */
  99. const std::vector<wxString> SimPlotVectors();
  100. /**
  101. * @return the list of schematic signals + any user defined signals.
  102. */
  103. const std::vector<wxString> Signals();
  104. const std::map<int, wxString>& UserDefinedSignals();
  105. void SetUserDefinedSignals( const std::map<int, wxString>& aSignals );
  106. /**
  107. * Add a voltage trace for a given net to the current plot.
  108. *
  109. * @param aNetName is the net name for which a voltage plot should be created.
  110. */
  111. void AddVoltageTrace( const wxString& aNetName );
  112. /**
  113. * Add a current trace for a given device to the current plot.
  114. *
  115. * @param aDeviceName is the device name (e.g. R1, C1).
  116. * @param aParam is the current type (e.g. I, Ic, Id).
  117. */
  118. void AddCurrentTrace( const wxString& aDeviceName );
  119. /**
  120. * Add a tuner for a symbol.
  121. */
  122. void AddTuner( const SCH_SHEET_PATH& aSheetPath, SCH_SYMBOL* aSymbol );
  123. /**
  124. * Return the current tab (or NULL if there is none).
  125. */
  126. SIM_TAB* GetCurrentSimTab() const;
  127. void ToggleSimConsole();
  128. void ToggleSimSidePanel();
  129. /**
  130. * Toggle dark-mode of the plot tabs.
  131. */
  132. void ToggleDarkModePlots();
  133. void ShowChangedLanguage() override;
  134. /**
  135. * Load plot, signal, cursor, measurement, etc. settings from a file.
  136. */
  137. bool LoadWorkbook( const wxString& aPath );
  138. /**
  139. * Save plot, signal, cursor, measurement, etc. settings to a file.
  140. */
  141. bool SaveWorkbook( const wxString& aPath );
  142. void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
  143. void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
  144. void CommonSettingsChanged( int aFlags ) override;
  145. WINDOW_SETTINGS* GetWindowSettings( APP_SETTINGS_BASE* aCfg ) override;
  146. SCH_EDIT_FRAME* GetSchematicFrame() const { return m_schematicFrame; }
  147. std::shared_ptr<SPICE_CIRCUIT_MODEL> GetCircuitModel() const { return m_circuitModel; }
  148. std::shared_ptr<SPICE_SIMULATOR> GetSimulator() const { return m_simulator; }
  149. wxString GetCurrentSimCommand() const;
  150. SIM_TYPE GetCurrentSimType() const;
  151. int GetCurrentOptions() const;
  152. bool SimFinished() const { return m_simFinished; }
  153. // Simulator doesn't host a canvas
  154. wxWindow* GetToolCanvas() const override { return nullptr; }
  155. /**
  156. * Set the main window title bar text.
  157. */
  158. void UpdateTitle();
  159. void OnModify() override;
  160. DECLARE_EVENT_TABLE()
  161. private:
  162. void setupTools();
  163. void doReCreateMenuBar() override;
  164. void setupUIConditions() override;
  165. void showNetlistErrors( const WX_STRING_REPORTER& aReporter );
  166. bool canCloseWindow( wxCloseEvent& aEvent ) override;
  167. void doCloseWindow() override;
  168. void onUpdateSim( wxCommandEvent& aEvent );
  169. void onSimReport( wxCommandEvent& aEvent );
  170. void onSimStarted( wxCommandEvent& aEvent );
  171. void onSimFinished( wxCommandEvent& aEvent );
  172. void onExit( wxCommandEvent& event );
  173. private:
  174. SCH_EDIT_FRAME* m_schematicFrame;
  175. ACTION_TOOLBAR* m_toolBar;
  176. SIMULATOR_FRAME_UI* m_ui;
  177. std::shared_ptr<SPICE_SIMULATOR> m_simulator;
  178. SIM_THREAD_REPORTER* m_reporter;
  179. std::shared_ptr<SPICE_CIRCUIT_MODEL> m_circuitModel;
  180. bool m_simFinished;
  181. bool m_workbookModified;
  182. };
  183. // Commands
  184. wxDECLARE_EVENT( EVT_SIM_UPDATE, wxCommandEvent );
  185. wxDECLARE_EVENT( EVT_SIM_REPORT, wxCommandEvent );
  186. // Notifications
  187. wxDECLARE_EVENT( EVT_SIM_STARTED, wxCommandEvent );
  188. wxDECLARE_EVENT( EVT_SIM_FINISHED, wxCommandEvent );
  189. #endif // SIMULATOR_FRAME_H