Kaynağa Gözat

Use calculateStateAndVisualForCurrentTimeStep and not calculateVisual when updating from async job

Henrik Kunzelmann 3 yıl önce
ebeveyn
işleme
75c30a895b

+ 22 - 8
src/holeg/HolegGateway.java

@@ -93,16 +93,30 @@ public class HolegGateway {
         }
     }
 
-    public static void solve(HolegPowerFlowContext context, MinimumNetwork minimumNetwork, int iteration, FlexManager flexManager, DecoratedNetwork network) {
+    public static synchronized void solve(HolegPowerFlowContext context, MinimumNetwork minimumNetwork, int iteration, FlexManager flexManager, DecoratedNetwork network) {
+        if (context == null)
+            throw new IllegalArgumentException("context is null");
+        if (minimumNetwork == null)
+            throw new IllegalArgumentException("minimumNetwork is null");
+        if (network == null)
+            throw new IllegalArgumentException("network is null");
+
+        // This is used when doing async updates and is the grid we should show
+        if (context.showGridForVisual != null) {
+            decorateNetwork(minimumNetwork, iteration, flexManager, network, context.showGridForVisual);
+            context.showGridForVisual = null;
+            return;
+        }
+
         boolean solve = !PowerFlowAnalysisMenu.getInstance().areUpdatesDisabled();
         Grid grid = convert(minimumNetwork, iteration, flexManager);
 
         // Create settings when null
-        if (context != null && context.settings == null)
+        if (context.settings == null)
             context.settings = PowerFlowSettings.getDefault();
 
         // Check if the grid is equal to one already solved
-        if (context != null && context.settings.onlyUpdateGridWhenChanged) {
+        if (context.settings.onlyUpdateGridWhenChanged) {
             for (Grid lastSolved : context.lastSolvedGrids) {
                 if (GridComparator.isEqual(lastSolved, grid)) {
                     decorateNetwork(minimumNetwork, iteration, flexManager, network, lastSolved);
@@ -122,7 +136,7 @@ public class HolegGateway {
         }
 
         // Stop old solver
-        if (context != null && context.solverJob != null) {
+        if (context.solverJob != null) {
             try {
                 context.solverJob.interrupt();
                 // wait till old solver job has finished or is interrupted
@@ -147,11 +161,11 @@ public class HolegGateway {
 
             // Decorate network
             decorateNetwork(minimumNetwork, iteration, flexManager, network, grid);
-            if (context != null)
-                context.solverTimeMilliseconds = (System.nanoTime() - start) / 1e6f;
+            context.solverTimeMilliseconds = (System.nanoTime() - start) / 1e6f;
 
             // Update canvas and other visuals
-            SingletonControl.getInstance().getControl().calculateVisual();
+            context.showGridForVisual = grid;
+            SingletonControl.getInstance().getControl().calculateStateAndVisualForCurrentTimeStep();
 
             // Show result message box
             if (result != null && PowerFlowAnalysisMenu.getInstance().shouldShowResult())
@@ -161,7 +175,7 @@ public class HolegGateway {
 
         // Wait or save solver job
         try {
-            if (context == null || context.settings.waitForSolverJob) {
+            if (context.settings.waitForSolverJob) {
                 // Start and wait till solver job is finished
                 solverJob.start();
                 solverJob.join();

+ 1 - 0
src/holeg/HolegPowerFlowContext.java

@@ -10,6 +10,7 @@ public class HolegPowerFlowContext {
     public List<Grid> lastSolvedGrids = new ArrayList<>();
     public Thread solverJob;
     public float solverTimeMilliseconds;
+    public Grid showGridForVisual;
 
     public void clearCache() {
         lastSolvedGrids.clear();