Skip to content

Commit

Permalink
Stop multiple tasks from running at the same time.
Browse files Browse the repository at this point in the history
  • Loading branch information
denneyl2711 committed Aug 6, 2024
1 parent 19f3e46 commit 2d65b8b
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/kintsugi3d/builder/app/Rendering.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions src/kintsugi3d/builder/core/DefaultProgressMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ public void complete()
public void fail(Throwable e)
{
}

@Override
public boolean isConflictingProcess() {
return false;
}
}
10 changes: 7 additions & 3 deletions src/kintsugi3d/builder/core/IBRRequestManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContextType extends Context<ContextType>> implements IBRRequestQueue<ContextType>
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -209,6 +210,9 @@ public synchronized void addGraphicsRequest(ObservableGraphicsRequest request)
{
if (progressMonitor != null)
{
if(this.progressMonitor.isConflictingProcess()){
return;
}
progressMonitor.start();
}

Expand Down
13 changes: 13 additions & 0 deletions src/kintsugi3d/builder/core/IOModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/kintsugi3d/builder/core/ProgressMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -136,6 +137,10 @@ public <ContextType extends Context<ContextType>> void prompt(IBRRequestQueue<Co
{
// stage.close();

if(MultithreadModels.getInstance().getIOModel().getProgressMonitor().isConflictingProcess()){
return;
}

File fragmentShader = new File(fragmentShaderField.getText());
File outputDirectory = new File(exportDirectoryField.getText());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import kintsugi3d.builder.core.*;
import kintsugi3d.builder.fit.settings.ExportSettings;

import kintsugi3d.builder.javafx.MultithreadModels;
import kintsugi3d.builder.util.Kintsugi3DViewerLauncher;
import kintsugi3d.gl.core.Context;
import org.slf4j.Logger;
Expand Down Expand Up @@ -103,6 +104,10 @@ public <ContextType extends Context<ContextType>> void prompt(IBRRequestQueue<Co
//Updates settings to equal what widget is displaying
saveAllVariables(settings);

if(MultithreadModels.getInstance().getIOModel().getProgressMonitor().isConflictingProcess()){
return;
}

try
{
exportLocationFile = objFileChooser.showSaveDialog(stage);
Expand Down
5 changes: 5 additions & 0 deletions src/kintsugi3d/builder/export/resample/ResampleRequestUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Stage;
import javafx.stage.Window;
import kintsugi3d.builder.javafx.MultithreadModels;
import kintsugi3d.gl.core.Context;
import kintsugi3d.builder.core.IBRRequestQueue;
import kintsugi3d.builder.core.IBRRequestUI;
Expand Down Expand Up @@ -126,6 +127,10 @@ public <ContextType extends Context<ContextType>> void prompt(IBRRequestQueue<Co
{
//stage.close();

if(MultithreadModels.getInstance().getIOModel().getProgressMonitor().isConflictingProcess()){
return;
}

requestQueue.addIBRRequest(
new ResampleRequest(
Integer.parseInt(widthTextField.getText()),
Expand Down
5 changes: 5 additions & 0 deletions src/kintsugi3d/builder/export/screenshot/ScreenshotUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Stage;
import javafx.stage.Window;
import kintsugi3d.builder.javafx.MultithreadModels;
import kintsugi3d.gl.core.Context;
import kintsugi3d.builder.core.IBRRequestQueue;
import kintsugi3d.builder.core.IBRRequestUI;
Expand Down Expand Up @@ -115,6 +116,10 @@ public <ContextType extends Context<ContextType>> void prompt(IBRRequestQueue<Co
//stage.close();
if (builderSupplier != null)
{
if(MultithreadModels.getInstance().getIOModel().getProgressMonitor().isConflictingProcess()){
return;
}

requestQueue.addIBRRequest(
builderSupplier.get()
.setWidth(Integer.parseInt(widthTextField.getText()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;
import javafx.stage.Window;
import kintsugi3d.builder.javafx.MultithreadModels;
import kintsugi3d.gl.core.Context;
import kintsugi3d.builder.core.IBRRequestQueue;
import kintsugi3d.builder.core.IBRRequestUI;
Expand Down Expand Up @@ -109,6 +110,10 @@ public <ContextType extends Context<ContextType>> void prompt(IBRRequestQueue<Co
//stage.close();
if (builderSupplier != null)
{
if(MultithreadModels.getInstance().getIOModel().getProgressMonitor().isConflictingProcess()){
return;
}

requestQueue.addIBRRequest(
builderSupplier.get()
.setWidth(Integer.parseInt(widthTextField.getText()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import kintsugi3d.builder.core.Kintsugi3DBuilderState;
import kintsugi3d.builder.core.TextureResolution;
import kintsugi3d.builder.fit.settings.SpecularFitRequestParams;
import kintsugi3d.builder.javafx.MultithreadModels;
import kintsugi3d.gl.core.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -111,6 +112,10 @@ public <ContextType extends Context<ContextType>> void prompt(IBRRequestQueue<Co
{
//stage.close();

if(MultithreadModels.getInstance().getIOModel().getProgressMonitor().isConflictingProcess()){
return;
}

SpecularFitRequestParams settings = new SpecularFitRequestParams(new TextureResolution(
Integer.parseInt(widthTextField.getText()),
Integer.parseInt(heightTextField.getText())),
Expand Down
7 changes: 5 additions & 2 deletions src/kintsugi3d/builder/javafx/ProjectIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
import kintsugi3d.builder.javafx.controllers.scene.ProgressBarsController;
import kintsugi3d.builder.javafx.controllers.scene.WelcomeWindowController;
import kintsugi3d.builder.resources.ibr.MeshImportException;
import kintsugi3d.gl.interactive.InteractiveRenderable;
import kintsugi3d.gl.interactive.InteractiveRenderableList;
import kintsugi3d.util.Flag;
import kintsugi3d.util.RecentProjects;
import org.slf4j.Logger;
Expand Down Expand Up @@ -375,6 +373,11 @@ private static void startLoad(File projectFile, File vsetFile)

public void openProjectFromFile(File selectedFile)
{
//need to check for conflicting process early so crucial info isn't unloaded
if(MultithreadModels.getInstance().getIOModel().getProgressMonitor().isConflictingProcess()){
return;
}

//open the project, update the recent files list & recentDirectory, disable shaders which aren't useful until processing textures
this.projectFile = selectedFile;
RecentProjects.setMostRecentDirectory(this.projectFile.getParentFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,6 @@ public void cancelComplete(UserCancellationException e)
@Override
public void start()
{
//TODO: deal with conflicting processes here
//if process is already happening, cancel it and continue with the new one?

cancelRequested.set(false);

stageCountProperty.setValue(0);
Expand Down Expand Up @@ -433,6 +430,36 @@ public void fail(Throwable e)
{
complete();
}

@Override
public boolean isConflictingProcess(){
if (!ProgressBarsController.getInstance().isProcessing()){
return false;
}

Platform.runLater(() ->
{
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;
Expand Down
16 changes: 16 additions & 0 deletions src/kintsugi3d/builder/rendering/IBRInstanceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,22 @@ public void warn(Throwable e)
progressMonitor.warn(e);
}
}

@Override
public boolean isConflictingProcess() {
return progressMonitor.isConflictingProcess();
}
});
newInstance = newItem;
}

@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");

Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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");

Expand Down
4 changes: 4 additions & 0 deletions src/kintsugi3d/builder/resources/DynamicResourceLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 2d65b8b

Please sign in to comment.