Forráskód Böngészése

PowerFlowAnalysisMenu: add solve button, add clear cache button

Henrik Kunzelmann 3 éve
szülő
commit
e2627a50ca

+ 10 - 3
src/holeg/HolegGateway.java

@@ -93,11 +93,18 @@ public class HolegGateway {
             context.lastSolvedGrids.add(grid);
         }
 
-        HolegPowerFlow powerFlow = new HolegPowerFlow();
-        GridSolverResult result = powerFlow.solve(grid, PowerFlowSettings.getDefault());
+        // Start solver
+        GridSolverResult result = null;
+        if (!PowerFlowAnalysisMenu.getInstance().areUpdatesDisabled()) {
+            HolegPowerFlow powerFlow = new HolegPowerFlow();
+            result = powerFlow.solve(grid, PowerFlowSettings.getDefault());
+        }
+
+        // Decorate network
         decorateNetwork(minimumNetwork, iteration, flexManager, network, grid);
 
-        if (PowerFlowAnalysisMenu.getInstance().shouldShowResult())
+        // Show result
+        if (result != null && PowerFlowAnalysisMenu.getInstance().shouldShowResult())
             SolveResultMessageBox.show(result);
     }
 }

+ 4 - 0
src/holeg/HolegPowerFlowContext.java

@@ -8,4 +8,8 @@ import java.util.List;
 public class HolegPowerFlowContext {
     public PowerFlowSettings settings = PowerFlowSettings.getDefault();
     public List<Grid> lastSolvedGrids = new ArrayList<>();
+
+    public void clearCache() {
+        lastSolvedGrids.clear();
+    }
 }

+ 20 - 0
src/holeg/ui/PowerFlowAnalysisMenu.java

@@ -1,12 +1,19 @@
 package holeg.ui;
 
+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;
 
 public class PowerFlowAnalysisMenu extends JMenu {
     private JMenuItem settingsMenu;
     private JMenuItem showFlow;
+    private JMenuItem clearCache;
+    private JMenuItem solve;
+    private JCheckBoxMenuItem disableUpdates;
     private JCheckBoxMenuItem showResultMessageBox;
     private JCheckBoxMenuItem showDebugMessageBox;
 
@@ -17,12 +24,25 @@ public class PowerFlowAnalysisMenu extends JMenu {
 
         settingsMenu = add(new JMenuItem("Settings"));
         showFlow = add(new JMenuItem("Show flow table"));
+        addSeparator();
+        clearCache = add(new JMenuItem("Clear cache"));
+        solve = add(new JMenuItem("Solve"));
+        addSeparator();
+        disableUpdates = (JCheckBoxMenuItem) add(new JCheckBoxMenuItem("Disable updates"));
         showResultMessageBox = (JCheckBoxMenuItem) add(new JCheckBoxMenuItem("Show result message"));
         showDebugMessageBox = (JCheckBoxMenuItem) add(new JCheckBoxMenuItem("Show debug message"));
 
+        clearCache.addActionListener((e) -> {
+            SingletonControl.getInstance().getControl().getSimManager().getHolegPowerFlowContext().clearCache();
+        });
+
         instance = this;
     }
 
+    public boolean areUpdatesDisabled() {
+        return disableUpdates.getState();
+    }
+
     public boolean shouldShowResult() {
         return showResultMessageBox.getState();
     }

+ 3 - 1
src/ui/controller/SimulationManager.java

@@ -300,5 +300,7 @@ public class SimulationManager {
 		return savesVisual.getOrDefault(timestep, null);
 	}
 
-
+	public HolegPowerFlowContext getHolegPowerFlowContext() {
+		return holegPowerFlowContext;
+	}
 }

+ 2 - 2
src/ui/view/Main.java

@@ -47,9 +47,9 @@ public class Main {
 
 	private static void loadNotLinuxLookAndFeel() {
 		try {
-		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
 		} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
-		e.printStackTrace();
+			e.printStackTrace();
 		}
 	}