From 1dc4ad1d62925778763e712767360a832c25eaf3 Mon Sep 17 00:00:00 2001 From: Cadin Batrack Date: Tue, 5 Sep 2023 17:27:02 -0700 Subject: [PATCH] =?UTF-8?q?fix=20path=20bugs;=20don=E2=80=99t=20send=20mul?= =?UTF-8?q?tiple=20`mode`=20commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AxiControl.xcodeproj/project.pbxproj | 4 ++-- AxiControl/ContentView.swift | 30 +++++++++++++++++++--------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/AxiControl.xcodeproj/project.pbxproj b/AxiControl.xcodeproj/project.pbxproj index bbef118..946af77 100644 --- a/AxiControl.xcodeproj/project.pbxproj +++ b/AxiControl.xcodeproj/project.pbxproj @@ -303,7 +303,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 1.1; + MARKETING_VERSION = 1.1.1; PRODUCT_BUNDLE_IDENTIFIER = com.cadinbatrack.AxiControl; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; @@ -332,7 +332,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 1.1; + MARKETING_VERSION = 1.1.1; PRODUCT_BUNDLE_IDENTIFIER = com.cadinbatrack.AxiControl; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; diff --git a/AxiControl/ContentView.swift b/AxiControl/ContentView.swift index cceea1c..ec3469a 100644 --- a/AxiControl/ContentView.swift +++ b/AxiControl/ContentView.swift @@ -125,22 +125,22 @@ struct ContentView: View { showError = true } - func sendAxiCommand(_ cmd: String, withFile path: String) { - let args = cmd.components(separatedBy: " ") + func getArgsForCommand(_ cmd: String) -> [String]? { + let args = cmd.count > 0 ? cmd.components(separatedBy: " ") : [] var newArgs = args + ["--model", String(modelNumber), "--reordering", String(reorderNumber), "--speed_pendown", String(Int(speed)) ] - if(plotSingleLayer){ + if(plotSingleLayer && !newArgs.contains("--mode")){ if let layerNum = Int(singleLayerNum){ if(layerNum > 0 && layerNum <= 1000){ newArgs = newArgs + ["--mode", "layers", "--layer", "\(layerNum)"] } else { showLayerError() - return + return nil } } else { showLayerError() - return + return nil } } @@ -152,7 +152,19 @@ struct ContentView: View { newArgs = newArgs + ["--hiding"] } - runAxiCLI(args: [path] + newArgs) + return newArgs + } + + func sendAxiCommand(_ cmd: String, withFile path: String, outputPath: String) { + if let args = getArgsForCommand(cmd) { + runAxiCLI(args: [path, "-o", outputPath] + args) + } + } + + func sendAxiCommand(_ cmd:String, withFile path: String) { + if let args = getArgsForCommand(cmd) { + runAxiCLI(args: [path] + args) + } } func sendAxiCommand(_ cmd: String) { @@ -215,7 +227,7 @@ struct ContentView: View { if let original = originalFileURL { let outputPath = getNewOutputPath(path: original) isPlotting = true - sendAxiCommand("-o \(outputPath)", withFile: url.path) + sendAxiCommand("", withFile: url.path, outputPath: outputPath) } } } @@ -231,7 +243,7 @@ struct ContentView: View { let outputPath = getNewOutputPath(path: original) currentFileURL = URL(string: url) isPlotting = true - runAxiCLI(args: [url, "--mode", "res_plot", "-o", outputPath]) + sendAxiCommand("--mode res_plot", withFile: url, outputPath: outputPath) } } @@ -240,7 +252,7 @@ struct ContentView: View { let url = getCurrentOutputPath(path: original) let outputPath = getNewOutputPath(path: original) currentFileURL = URL(string: url) - runAxiCLI(args: [url, "--mode", "res_home", "-o", outputPath]) + sendAxiCommand("--mode res_home", withFile: url, outputPath: outputPath) } }