From 2d65b8b49b707cbaf46368bee9e04b37bcf9b53a Mon Sep 17 00:00:00 2001 From: denneyl2711 Date: Tue, 6 Aug 2024 13:04:49 -0500 Subject: [PATCH 1/2] Stop multiple tasks from running at the same time. --- src/kintsugi3d/builder/app/Rendering.java | 5 +++ .../builder/core/DefaultProgressMonitor.java | 5 +++ .../builder/core/IBRRequestManager.java | 10 ++++-- src/kintsugi3d/builder/core/IOModel.java | 13 ++++++++ .../builder/core/ProgressMonitor.java | 7 ++++ .../general/GeneralRenderRequestUI.java | 5 +++ .../projectExporter/ExportRequestUI.java | 5 +++ .../export/resample/ResampleRequestUI.java | 5 +++ .../export/screenshot/ScreenshotUI.java | 5 +++ .../simpleanimation/SimpleAnimationUI.java | 5 +++ .../export/specular/SpecularFitRequestUI.java | 5 +++ src/kintsugi3d/builder/javafx/ProjectIO.java | 7 ++-- .../menubar/MenubarController.java | 33 +++++++++++++++++-- .../builder/rendering/IBRInstanceManager.java | 16 +++++++++ .../resources/DynamicResourceLoader.java | 4 +++ 15 files changed, 122 insertions(+), 8 deletions(-) diff --git a/src/kintsugi3d/builder/app/Rendering.java b/src/kintsugi3d/builder/app/Rendering.java index da4e496f..8108ca59 100644 --- a/src/kintsugi3d/builder/app/Rendering.java +++ b/src/kintsugi3d/builder/app/Rendering.java @@ -417,6 +417,11 @@ public void warn(Throwable e) { ioModel.getProgressMonitor().warn(e); } + + @Override + public boolean isConflictingProcess() { + return ioModel.getProgressMonitor().isConflictingProcess(); + } }); app.addRefreshable(new Refreshable() diff --git a/src/kintsugi3d/builder/core/DefaultProgressMonitor.java b/src/kintsugi3d/builder/core/DefaultProgressMonitor.java index a7faa865..f07737b6 100644 --- a/src/kintsugi3d/builder/core/DefaultProgressMonitor.java +++ b/src/kintsugi3d/builder/core/DefaultProgressMonitor.java @@ -65,4 +65,9 @@ public void complete() public void fail(Throwable e) { } + + @Override + public boolean isConflictingProcess() { + return false; + } } diff --git a/src/kintsugi3d/builder/core/IBRRequestManager.java b/src/kintsugi3d/builder/core/IBRRequestManager.java index ed66bb9c..0974d089 100644 --- a/src/kintsugi3d/builder/core/IBRRequestManager.java +++ b/src/kintsugi3d/builder/core/IBRRequestManager.java @@ -24,10 +24,7 @@ import javafx.scene.control.Alert.AlertType; import kintsugi3d.builder.rendering.IBRInstanceManager; import kintsugi3d.gl.core.Context; -import kintsugi3d.gl.interactive.GraphicsRequest; import kintsugi3d.gl.interactive.ObservableGraphicsRequest; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class IBRRequestManager> implements IBRRequestQueue { @@ -112,6 +109,10 @@ public synchronized void addBackgroundIBRRequest(IBRRequest request) @Override public synchronized void addIBRRequest(ObservableIBRRequest request) { + if(this.progressMonitor.isConflictingProcess()){ + return; + } + if (instanceManager.getLoadedInstance() == null) { // Instance is currently null, wait for a load and then call this function again (recursive-ish) @@ -209,6 +210,9 @@ public synchronized void addGraphicsRequest(ObservableGraphicsRequest request) { if (progressMonitor != null) { + if(this.progressMonitor.isConflictingProcess()){ + return; + } progressMonitor.start(); } diff --git a/src/kintsugi3d/builder/core/IOModel.java b/src/kintsugi3d/builder/core/IOModel.java index 8852c8a9..0498a20b 100644 --- a/src/kintsugi3d/builder/core/IOModel.java +++ b/src/kintsugi3d/builder/core/IOModel.java @@ -132,6 +132,19 @@ public void warn(Throwable e) monitor.warn(e); } } + + @Override + public boolean isConflictingProcess() { + boolean processing = false; + for (ProgressMonitor monitor : subMonitors) + { + if(monitor.isConflictingProcess()){ + processing = true; + } + } + + return processing; + } } private IOHandler handler; diff --git a/src/kintsugi3d/builder/core/ProgressMonitor.java b/src/kintsugi3d/builder/core/ProgressMonitor.java index fcb24263..bb8747b7 100644 --- a/src/kintsugi3d/builder/core/ProgressMonitor.java +++ b/src/kintsugi3d/builder/core/ProgressMonitor.java @@ -95,4 +95,11 @@ public interface ProgressMonitor default void warn(Throwable e) { } + + /** + * Usually a call to ProgressBarsController.getInstance().isProcessing(). + * Used to stop multiple processes from conflicting with each other. + * @return true if a process is in progress. + */ + boolean isConflictingProcess(); } diff --git a/src/kintsugi3d/builder/export/general/GeneralRenderRequestUI.java b/src/kintsugi3d/builder/export/general/GeneralRenderRequestUI.java index 6b25cc16..84eccf9d 100644 --- a/src/kintsugi3d/builder/export/general/GeneralRenderRequestUI.java +++ b/src/kintsugi3d/builder/export/general/GeneralRenderRequestUI.java @@ -30,6 +30,7 @@ import javafx.stage.FileChooser.ExtensionFilter; import javafx.stage.Stage; import javafx.stage.Window; +import kintsugi3d.builder.javafx.MultithreadModels; import kintsugi3d.util.RecentProjects; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -136,6 +137,10 @@ public > void prompt(IBRRequestQueue> void prompt(IBRRequestQueue> void prompt(IBRRequestQueue> void prompt(IBRRequestQueue> void prompt(IBRRequestQueue> void prompt(IBRRequestQueue + { + ButtonType ok = new ButtonType("OK", ButtonBar.ButtonData.OK_DONE); + //ButtonType stopProcess = new ButtonType("Start New Process", ButtonBar.ButtonData.YES); + Alert alert = new Alert(AlertType.NONE, "Cannot run multiple tasks at the same time.\n" + + "Either wait for the current task to complete or cancel it." /*+ + "Press OK to finish the current process."*/, ok/*, stopProcess*/); + alert.setHeaderText("Conflicting Tasks"); + +// //continue current process, don't start a new one +// ((Button) alert.getDialogPane().lookupButton(ok)).setOnAction(event -> { +// }); +// +// //cancel current process and start new one +// ((Button) alert.getDialogPane().lookupButton(stopProcess)).setOnAction(event -> { +// cancelRequested.set(true); +// }); + + alert.showAndWait(); + }); + + return true; + } }); boolean foundExportClass = false; diff --git a/src/kintsugi3d/builder/rendering/IBRInstanceManager.java b/src/kintsugi3d/builder/rendering/IBRInstanceManager.java index 08f4e3d8..1b830d53 100644 --- a/src/kintsugi3d/builder/rendering/IBRInstanceManager.java +++ b/src/kintsugi3d/builder/rendering/IBRInstanceManager.java @@ -311,6 +311,11 @@ public void warn(Throwable e) progressMonitor.warn(e); } } + + @Override + public boolean isConflictingProcess() { + return progressMonitor.isConflictingProcess(); + } }); newInstance = newItem; } @@ -318,6 +323,10 @@ public void warn(Throwable e) @Override public void loadFromVSETFile(String id, File vsetFile, File supportingFilesDirectory, ReadonlyLoadOptionsModel loadOptions) { + if(this.progressMonitor.isConflictingProcess()){ + return; + } + this.progressMonitor.start(); this.progressMonitor.setProcessName("Load from File"); @@ -346,6 +355,10 @@ public void loadAgisoftFromZIP(String id, MetashapeObjectChunk metashapeObjectCh // TODO There currently isn't functionality for a supportingFilesDirectory at this early in the process // Restructuring required from Tetzlaff. + if(this.progressMonitor.isConflictingProcess()){ + return; + } + this.progressMonitor.start(); this.progressMonitor.setProcessName("Load from Agisoft Project"); @@ -491,6 +504,9 @@ private void showMissingImgsAlert(MetashapeObjectChunk metashapeObjectChunk, Str public void loadFromAgisoftXMLFile(String id, File xmlFile, File meshFile, File imageDirectory, String primaryViewName, ReadonlyLoadOptionsModel loadOptions) { + if(this.progressMonitor.isConflictingProcess()){ + return; + } this.progressMonitor.start(); this.progressMonitor.setProcessName("Load from Agisoft Files"); diff --git a/src/kintsugi3d/builder/resources/DynamicResourceLoader.java b/src/kintsugi3d/builder/resources/DynamicResourceLoader.java index 486fdd11..dbe939a3 100644 --- a/src/kintsugi3d/builder/resources/DynamicResourceLoader.java +++ b/src/kintsugi3d/builder/resources/DynamicResourceLoader.java @@ -252,6 +252,10 @@ else if (environmentFile.exists()) if (Objects.equals(environmentFile, desiredEnvironmentFile) && (!Objects.equals(environmentFile, currentEnvironmentFile) || lastModified != environmentLastModified)) { + if(this.progressMonitor.isConflictingProcess()){ + return Optional.empty(); + } + this.progressMonitor.start(); this.progressMonitor.setMaxProgress(0.0); this.progressMonitor.setProcessName("Load Environment Map"); From 2cb12723c77da7695183eb75fd41df693e89fd5d Mon Sep 17 00:00:00 2001 From: denneyl2711 Date: Wed, 7 Aug 2024 12:03:32 -0500 Subject: [PATCH 2/2] Error handling message is condensed into ProjectIO, better error handling during specular fit. --- .../builder/core/IBRRequestManager.java | 31 +++++-------------- .../export/specular/SpecularFitRequest.java | 3 +- src/kintsugi3d/builder/javafx/ProjectIO.java | 5 ++- .../menubar/MenubarController.java | 19 ++---------- 4 files changed, 14 insertions(+), 44 deletions(-) diff --git a/src/kintsugi3d/builder/core/IBRRequestManager.java b/src/kintsugi3d/builder/core/IBRRequestManager.java index 0974d089..8c7fa0b6 100644 --- a/src/kintsugi3d/builder/core/IBRRequestManager.java +++ b/src/kintsugi3d/builder/core/IBRRequestManager.java @@ -11,20 +11,19 @@ package kintsugi3d.builder.core; -import java.util.LinkedList; -import java.util.Queue; - -import javafx.scene.control.*; -import kintsugi3d.builder.javafx.controllers.menubar.MenubarController; -import kintsugi3d.gl.interactive.GraphicsRequest; import javafx.application.Platform; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; +import kintsugi3d.builder.javafx.ProjectIO; import kintsugi3d.builder.rendering.IBRInstanceManager; import kintsugi3d.gl.core.Context; +import kintsugi3d.gl.interactive.GraphicsRequest; import kintsugi3d.gl.interactive.ObservableGraphicsRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.LinkedList; +import java.util.Queue; public class IBRRequestManager> implements IBRRequestQueue { @@ -149,21 +148,7 @@ public synchronized void addIBRRequest(ObservableIBRRequest request) } catch (Exception | AssertionError e) { - log.error("Error occurred while executing request:", e); - Platform.runLater(() -> - { - ButtonType ok = new ButtonType("OK", ButtonBar.ButtonData.CANCEL_CLOSE); - ButtonType showLog = new ButtonType("Show Log", ButtonBar.ButtonData.YES); - Alert alert = new Alert(Alert.AlertType.NONE, - "An error occurred processing request. Processing has stopped\nSee the log for more info.", - ok, showLog); - - ((ButtonBase) alert.getDialogPane().lookupButton(showLog)).setOnAction(event -> { - // Use the menubar's console open function to prevent 2 console windows from appearing - MenubarController.getInstance().help_console(); - }); - alert.show(); - }); + ProjectIO.handleException("Error occured while excecuting request", e); } } diff --git a/src/kintsugi3d/builder/export/specular/SpecularFitRequest.java b/src/kintsugi3d/builder/export/specular/SpecularFitRequest.java index c7eac140..b8b47e06 100644 --- a/src/kintsugi3d/builder/export/specular/SpecularFitRequest.java +++ b/src/kintsugi3d/builder/export/specular/SpecularFitRequest.java @@ -24,6 +24,7 @@ import kintsugi3d.builder.fit.SpecularFitProcess; import kintsugi3d.builder.fit.SpecularFitProgramFactory; import kintsugi3d.builder.fit.settings.SpecularFitRequestParams; +import kintsugi3d.builder.javafx.ProjectIO; import kintsugi3d.builder.javafx.controllers.menubar.MenubarController; import kintsugi3d.builder.metrics.ColorAppearanceRMSE; import kintsugi3d.builder.resources.ibr.ReadonlyIBRResources; @@ -105,7 +106,7 @@ public > void executeRequest(IBRInstanc } catch(IOException e) // thrown by createReflectanceProgram { - log.error("Error executing specular fit request:", e); + ProjectIO.handleException("Error executing specular fit request:", e); } } diff --git a/src/kintsugi3d/builder/javafx/ProjectIO.java b/src/kintsugi3d/builder/javafx/ProjectIO.java index 0ab81dda..6648707b 100644 --- a/src/kintsugi3d/builder/javafx/ProjectIO.java +++ b/src/kintsugi3d/builder/javafx/ProjectIO.java @@ -117,8 +117,7 @@ public void fail(Throwable e) projectLoaded = false; if (e instanceof MeshImportException) { - //TODO: change to (e.getMessage(), e)? - handleException("Imported object is missing texture coordinates", e); + handleException(e.getMessage(), e); } else { @@ -149,7 +148,7 @@ public boolean isProjectLoaded() return projectLoaded; } - private static void handleException(String message, Throwable e) + public static void handleException(String message, Throwable e) { log.error("{}:", message, e); Platform.runLater(() -> diff --git a/src/kintsugi3d/builder/javafx/controllers/menubar/MenubarController.java b/src/kintsugi3d/builder/javafx/controllers/menubar/MenubarController.java index ae58f3fa..3873e4ec 100644 --- a/src/kintsugi3d/builder/javafx/controllers/menubar/MenubarController.java +++ b/src/kintsugi3d/builder/javafx/controllers/menubar/MenubarController.java @@ -68,6 +68,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; +import static kintsugi3d.builder.javafx.ProjectIO.handleException; + public class MenubarController { private static final Logger log = LoggerFactory.getLogger(MenubarController.class); @@ -405,8 +407,6 @@ public void complete() { this.maximum = 0.0; ProgressBarsController.getInstance().endStopwatches(); - //TODO: desaturate progress bars instead of hiding stage -// ProgressBarsController.getInstance().hideStage(); setReadyToDismissMiniProgBar(); if(overallProgressBar.getProgress() == ProgressIndicator.INDETERMINATE_PROGRESS){ @@ -1052,21 +1052,6 @@ public void launchViewerApp() } } - private void handleException(String message, Exception e) - { - log.error("{}:", message, e); - Platform.runLater(() -> - { - ButtonType ok = new ButtonType("OK", ButtonBar.ButtonData.OK_DONE); - ButtonType showLog = new ButtonType("Show Log", ButtonBar.ButtonData.YES); - Alert alert = new Alert(AlertType.ERROR, message + "\nSee the log for more info.", ok, showLog); - ((Button) alert.getDialogPane().lookupButton(showLog)).setOnAction(event -> { - help_console(); - }); - alert.show(); - }); - } - public void file_removeInvalidReferences() { RecentProjects.removeInvalidReferences(); }