bool process_completed_compute() { if (active_compute != null) { if (active_compute.Finished) { lock (active_compute_lock) { lock (data_lock) { SlicerMeshes = active_compute.assembly; SliceStackValid = true; SliceSet = active_compute.result; } // this recomputes slice polylines, but it could be better... if (ShowSlicePolylines) { discard_slice_polylines(); compute_slice_polylines(); } active_compute = null; active_compute_thread = null; return(true); } } } return(false); }
void synchronize_meshes(BackgroundThreadData d) { // filter out any ignored/invalid meshes List <PrintMeshSO> printMeshes = CC.Objects.PrintMeshes; List <PrintMeshSO> useMeshes = new List <PrintMeshSO>(); foreach (PrintMeshSO printMesh in printMeshes) { if (printMesh.Settings.ObjectType != PrintMeshSettings.ObjectTypes.Ignored) { useMeshes.Add(printMesh); } } // this has to run in main thread int N = useMeshes.Count; d.meshToScene = new Frame3f[N]; d.localScale = new Vector3f[N]; d.meshCopies = new DMesh3[N]; d.meshSettings = new PrintMeshSettings[N]; for (int k = 0; k < N; ++k) { PrintMeshSO so = useMeshes[k]; d.meshCopies[k] = new DMesh3(so.Mesh); d.meshToScene[k] = SceneTransforms.ObjectToScene(so, Frame3f.Identity); d.localScale[k] = so.GetLocalScale(); d.meshSettings[k] = so.Settings.Clone(); } }
void update_toolpaths(bool immediate = false) { if (immediate == false && time_to_start_new_compute() == false) { return; } // have to wait for valid slice stack PrintMeshAssembly meshes; PlanarSliceStack slices; bool valid = CC.Slicer.ExtractResultsIfValid(out meshes, out slices); if (valid == false) { return; } if (slices == null) { ToolpathsProgressEvent?.Invoke(ToolpathProgressStatus.Failed); return; } BackgroundThreadData d = new BackgroundThreadData(); d.PrintSettings = CC.Settings.CloneCurrentSettings(); d.Meshes = meshes; d.SliceSet = slices; d.InterpretGCodePaths = ShowActualGCodePaths; mark_spawn_time(); spawn_new_compute(d); }
void spawn_new_compute(BackgroundThreadData d) { cancel_active_compute(); lock (active_compute_lock) { DebugUtil.Log("[GeometrySlicer] Spawning Compute!!"); active_compute = d; active_compute_thread = new Thread(d.Compute); active_compute_thread.Start(); } }
void cancel_active_compute() { lock (active_compute_lock) { if (active_compute != null) { DebugUtil.Log("[GeometrySlicer] Cancelling!!"); active_compute_thread.Abort(); active_compute = null; active_compute_thread = null; } } mark_spawn_time(); // otherwise we will start at regular intervals }
void cancel_active_compute() { lock (active_compute_lock) { if (active_compute != null) { DebugUtil.Log("[ToolpathGenerator] Cancelling!!"); active_compute.RequestCancel = true; active_compute_thread.Abort(); // [TODO] ideally thread would cancel itself, instead of aborting... active_compute = null; active_compute_thread = null; } } mark_spawn_time(); // otherwise we will start at regular intervals }
void update_slicing(bool immediate = false) { if (immediate == false && time_to_start_new_compute() == false) { return; } // ui thing CotangentUI.HideSliceLabel(); BackgroundThreadData d = new BackgroundThreadData(); synchronize_meshes(d); mark_spawn_time(); spawn_new_compute(d); }
bool process_completed_compute() { if (active_compute != null) { if (active_compute.Finished) { lock (active_compute_lock) { if (active_compute.Success) { CurrentGCode = active_compute.gcode; Toolpaths = active_compute.paths; LayerInfo = active_compute.layerInfo; Settings = active_compute.PrintSettings; Slices = active_compute.SliceSet; ToolpathsValid = true; ToolpathsFailed = false; ToolpathsProgressEvent?.Invoke(new ToolpathProgressStatus(1, 1)); CC.Objects.SetToolpaths(this); } else { CurrentGCode = null; Toolpaths = null; LayerInfo = null; Settings = null; Slices = null; ToolpathsValid = false; ToolpathsFailed = true; // notify of failure here? ToolpathsProgressEvent?.Invoke(ToolpathProgressStatus.Failed); } active_compute = null; active_compute_thread = null; return(true); } } } return(false); }