123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- package holeg.ui;
- import holeg.HolegGateway;
- import holeg.HolegPowerFlow;
- import holeg.HolegPowerFlowContext;
- import holeg.PowerFlowSettings;
- import holeg.test_sensitivity.TestSensitivityProgram;
- import ui.controller.SimulationManager;
- import ui.controller.SingletonControl;
- import ui.model.Model;
- import javax.swing.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.Set;
- public class PowerFlowAnalysisMenu extends JMenu {
- private JMenuItem settingsMenu;
- private JMenuItem showFlow;
- private JMenuItem clearCache;
- private JMenuItem solve;
- private JMenuItem clearCacheAndSolve;
- private JCheckBoxMenuItem disableUpdates;
- private JCheckBoxMenuItem showResultMessageBox;
- private JCheckBoxMenuItem showDebugMessageBox;
- private JCheckBoxMenuItem showVoltages;
- private static PowerFlowAnalysisMenu instance;
- private SettingsWindow settingsWindow;
- private FlowTableWindow flowTableWindow;
- private boolean overwriteDisableUpdatesToForceUpdates = false;
- public PowerFlowAnalysisMenu(JFrame owner, Model model) {
- super("Power flow");
- settingsMenu = add(new JMenuItem("Settings"));
- showFlow = add(new JMenuItem("Show flow table"));
- addSeparator();
- clearCache = add(new JMenuItem("Clear cache"));
- solve = add(new JMenuItem("Solve"));
- clearCacheAndSolve = add(new JMenuItem("Clear cache and solve"));
- addSeparator();
- disableUpdates = (JCheckBoxMenuItem) add(new JCheckBoxMenuItem("Disable automatic updates"));
- showResultMessageBox = (JCheckBoxMenuItem) add(new JCheckBoxMenuItem("Show result message"));
- showDebugMessageBox = (JCheckBoxMenuItem) add(new JCheckBoxMenuItem("Show debug message"));
- showVoltages = (JCheckBoxMenuItem) add(new JCheckBoxMenuItem("Show voltagess"));
- showVoltages.setState(true);
- settingsWindow = new SettingsWindow(owner, getPowerFlowSettings());
- flowTableWindow = new FlowTableWindow(owner);
- settingsMenu.addActionListener((e) -> {
- settingsWindow.setVisible(true);
- });
- showFlow.addActionListener((e) -> {
- flowTableWindow.setVisible(true);
- flowTableWindow.update();
- });
- clearCache.addActionListener((e) -> {
- clearCache();
- });
- solve.addActionListener((e) -> {
- solve(false);
- });
- clearCacheAndSolve.addActionListener((e) -> {
- solve(true);
- });
- instance = this;
- //TestSensitivityProgram.test();
- }
- private void clearCache() {
- for (HolegPowerFlowContext context : HolegGateway.getALlContext())
- context.clearCache();
- }
- private void solve(boolean clearCache) {
- // This is needed otherwise the calculateStateAndVisualForCurrentTimeStep() function would not do anything
- // when updates are disabled (same execution path)
- overwriteDisableUpdatesToForceUpdates = true;
- if (clearCache)
- clearCache();
- SingletonControl.getInstance().getControl().calculateStateAndVisualForCurrentTimeStep();
- overwriteDisableUpdatesToForceUpdates = false;
- }
- public PowerFlowSettings getPowerFlowSettings() {
- return SingletonControl.getInstance().getControl().getSimManager().getHolegPowerFlowSettings();
- }
- public boolean areUpdatesDisabled() {
- return !overwriteDisableUpdatesToForceUpdates && disableUpdates.getState();
- }
- public boolean shouldShowResult() {
- return showResultMessageBox.getState();
- }
- public boolean shouldShowDebug() {
- return showDebugMessageBox.getState();
- }
- public boolean shouldShowVoltages() { return showVoltages.getState(); }
- public static PowerFlowAnalysisMenu getInstance() {
- return instance;
- }
- }
|