Made the progress info in View3D go through our code rather than bacground task.

This commit is contained in:
larsbrubaker 2014-11-04 10:27:59 -08:00
parent e7ae9358e1
commit 2ce24de08c
8 changed files with 57 additions and 58 deletions

View file

@ -48,18 +48,16 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
// set the progress lable text
processingProgressControl.PercentComplete = 0;
processingProgressControl.Visible = true;
string makingCopyLabel = LocalizedString.Get("Finding Meshes");
string makingCopyLabel = LocalizedString.Get("Aligning");
string makingCopyLabelFull = string.Format("{0}:", makingCopyLabel);
processingProgressControl.textWidget.Text = makingCopyLabelFull;
processingProgressControl.ProcessType = makingCopyLabelFull;
LockEditControls();
viewIsInEditModePreLock = true;
BackgroundWorker createDiscreteMeshesBackgroundWorker = null;
createDiscreteMeshesBackgroundWorker = new BackgroundWorker();
createDiscreteMeshesBackgroundWorker.WorkerReportsProgress = true;
createDiscreteMeshesBackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(BackgroundWorker_ProgressChanged);
createDiscreteMeshesBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(alignSelectedBackgroundWorker_RunWorkerCompleted);
createDiscreteMeshesBackgroundWorker.DoWork += new DoWorkEventHandler(alignSelectedBackgroundWorker_DoWork);
@ -138,9 +136,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
// create the selection info
PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, i, (double progress0To1, string processingState, out bool continueProcessing) =>
{
continueProcessing = true;
int nextPercent = (int)((currentRatioDone + ratioPerMeshGroup * progress0To1) * 100);
backgroundWorker.ReportProgress(nextPercent);
BackgroundWorker_ProgressChanged(progress0To1, processingState, out continueProcessing);
});
currentRatioDone += ratioPerMeshGroup;

View file

@ -46,16 +46,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
string progressArrangeParts = LocalizedString.Get("Arranging Parts");
string progressArrangePartsFull = string.Format("{0}:", progressArrangeParts);
processingProgressControl.textWidget.Text = progressArrangePartsFull;
processingProgressControl.ProcessType = progressArrangePartsFull;
processingProgressControl.Visible = true;
processingProgressControl.PercentComplete = 0;
LockEditControls();
BackgroundWorker arrangeMeshGroupsBackgroundWorker = new BackgroundWorker();
arrangeMeshGroupsBackgroundWorker.WorkerReportsProgress = true;
arrangeMeshGroupsBackgroundWorker.DoWork += new DoWorkEventHandler(arrangeMeshGroupsBackgroundWorker_DoWork);
arrangeMeshGroupsBackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(BackgroundWorker_ProgressChanged);
arrangeMeshGroupsBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(arrangeMeshGroupsBackgroundWorker_RunWorkerCompleted);
arrangeMeshGroupsBackgroundWorker.RunWorkerAsync();
@ -123,9 +121,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
// and create the trace info so we can select it
PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, meshGroupIndex, (double progress0To1, string processingState, out bool continueProcessing) =>
{
continueProcessing = true;
int nextPercent = (int)((currentRatioDone + ratioPerMeshGroup * progress0To1) * 100);
backgroundWorker.ReportProgress(nextPercent);
BackgroundWorker_ProgressChanged(progress0To1, processingState, out continueProcessing);
});
currentRatioDone += ratioPerMeshGroup;

View file

@ -43,17 +43,15 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
string makingCopyLabel = LocalizedString.Get("Making Copy");
string makingCopyLabelFull = string.Format("{0}:", makingCopyLabel);
processingProgressControl.textWidget.Text = makingCopyLabelFull;
processingProgressControl.ProcessType = makingCopyLabelFull;
processingProgressControl.Visible = true;
processingProgressControl.PercentComplete = 0;
LockEditControls();
BackgroundWorker copyGroupBackgroundWorker = null;
copyGroupBackgroundWorker = new BackgroundWorker();
copyGroupBackgroundWorker.WorkerReportsProgress = true;
copyGroupBackgroundWorker.DoWork += new DoWorkEventHandler(copyGroupBackgroundWorker_DoWork);
copyGroupBackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(BackgroundWorker_ProgressChanged);
copyGroupBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(copyGroupBackgroundWorker_RunWorkerCompleted);
copyGroupBackgroundWorker.RunWorkerAsync();
@ -75,16 +73,15 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
Mesh mesh = asynchMeshGroups[SelectedMeshGroupIndex].Meshes[i];
copyMeshGroup.Meshes.Add(Mesh.Copy(mesh, (double progress0To1, string processingState, out bool continueProcessing) =>
{
continueProcessing = true;
int nextPercent = (int)(100 * (progress0To1 * .8 * i / meshCount));
backgroundWorker.ReportProgress(nextPercent);
BackgroundWorker_ProgressChanged(progress0To1, processingState, out continueProcessing);
}));
}
PlatingHelper.FindPositionForGroupAndAddToPlate(copyMeshGroup, SelectedMeshGroupTransform, asynchPlatingDatas, asynchMeshGroups, asynchMeshGroupTransforms);
PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, asynchMeshGroups.Count - 1, null);
backgroundWorker.ReportProgress(95);
bool continueProcessing2;
BackgroundWorker_ProgressChanged(.95, "", out continueProcessing2);
}
void copyGroupBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)

View file

@ -58,9 +58,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
BackgroundWorker createSelectionDataBackgroundWorker = null;
createSelectionDataBackgroundWorker = new BackgroundWorker();
createSelectionDataBackgroundWorker.WorkerReportsProgress = true;
createSelectionDataBackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(BackgroundWorker_ProgressChanged);
createSelectionDataBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(createSelectionDataBackgroundWorker_RunWorkerCompleted);
createSelectionDataBackgroundWorker.DoWork += new DoWorkEventHandler(createSelectionDataBackgroundWorker_DoWork);
@ -72,7 +70,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
string makingCopyLabel = LocalizedString.Get("Preparing Meshes");
string makingCopyLabelFull = string.Format("{0}:", makingCopyLabel);
processingProgressControl.textWidget.Text = makingCopyLabelFull;
processingProgressControl.ProcessType = makingCopyLabelFull;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
BackgroundWorker backgroundWorker = (BackgroundWorker)sender;
@ -92,13 +90,15 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
// create the selection info
PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, i, (double progress0To1, string processingState, out bool continueProcessing) =>
{
continueProcessing = true;
int nextPercent = (int)((currentRatioDone + ratioPerMeshGroup * progress0To1) * 100);
backgroundWorker.ReportProgress(nextPercent);
BackgroundWorker_ProgressChanged(progress0To1, processingState, out continueProcessing);
});
currentRatioDone += ratioPerMeshGroup;
}
bool continueProcessing2;
BackgroundWorker_ProgressChanged(1, "Creating GL Data", out continueProcessing2);
meshViewerWidget.CreateGlDataForMeshes(asynchMeshGroups);
}
void createSelectionDataBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)

View file

@ -50,9 +50,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
BackgroundWorker createDiscreteMeshesBackgroundWorker = null;
createDiscreteMeshesBackgroundWorker = new BackgroundWorker();
createDiscreteMeshesBackgroundWorker.WorkerReportsProgress = true;
createDiscreteMeshesBackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(BackgroundWorker_ProgressChanged);
createDiscreteMeshesBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(groupSelectedBackgroundWorker_RunWorkerCompleted);
createDiscreteMeshesBackgroundWorker.DoWork += new DoWorkEventHandler(groupSelectedBackgroundWorker_DoWork);
@ -62,9 +60,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
void groupSelectedBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
string makingCopyLabel = LocalizedString.Get("Grouping Meshes");
string makingCopyLabel = LocalizedString.Get("Grouping");
string makingCopyLabelFull = string.Format("{0}:", makingCopyLabel);
processingProgressControl.textWidget.Text = makingCopyLabelFull;
processingProgressControl.ProcessType = makingCopyLabelFull;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
BackgroundWorker backgroundWorker = (BackgroundWorker)sender;
@ -75,8 +73,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
asynchMeshGroups[i].Transform(asynchMeshGroupTransforms[i].TotalTransform);
int nextPercent = (i + 1) * 40 / asynchMeshGroups.Count;
backgroundWorker.ReportProgress(nextPercent);
bool continueProcessing;
BackgroundWorker_ProgressChanged((i+1) * .4 / asynchMeshGroups.Count, "", out continueProcessing);
}
DoGroup(backgroundWorker);
@ -119,9 +117,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
// create the selection info
PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, i, (double progress0To1, string processingState, out bool continueProcessing) =>
{
continueProcessing = true;
int nextPercent = (int)((currentRatioDone + ratioPerMeshGroup * progress0To1) * 100);
backgroundWorker.ReportProgress(nextPercent);
BackgroundWorker_ProgressChanged(progress0To1, processingState, out continueProcessing);
});
currentRatioDone += ratioPerMeshGroup;

View file

@ -50,9 +50,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
BackgroundWorker createDiscreteMeshesBackgroundWorker = null;
createDiscreteMeshesBackgroundWorker = new BackgroundWorker();
createDiscreteMeshesBackgroundWorker.WorkerReportsProgress = true;
createDiscreteMeshesBackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(BackgroundWorker_ProgressChanged);
createDiscreteMeshesBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(ungroupSelectedBackgroundWorker_RunWorkerCompleted);
createDiscreteMeshesBackgroundWorker.DoWork += new DoWorkEventHandler(ungroupSelectedBackgroundWorker_DoWork);
@ -62,9 +60,9 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
void ungroupSelectedBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
string makingCopyLabel = LocalizedString.Get("Finding Meshes");
string makingCopyLabel = LocalizedString.Get("Ungrouping");
string makingCopyLabelFull = string.Format("{0}:", makingCopyLabel);
processingProgressControl.textWidget.Text = makingCopyLabelFull;
processingProgressControl.ProcessType = makingCopyLabelFull;
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
BackgroundWorker backgroundWorker = (BackgroundWorker)sender;
@ -75,9 +73,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
asynchMeshGroups[indexBeingReplaced].Transform(asynchMeshGroupTransforms[indexBeingReplaced].TotalTransform);
List<Mesh> discreetMeshes = CreateDiscreteMeshes.SplitConnectedIntoMeshes(asynchMeshGroups[indexBeingReplaced], (double progress0To1, string processingState, out bool continueProcessing) =>
{
continueProcessing = true;
int nextPercent = (int)(progress0To1 * 50);
backgroundWorker.ReportProgress(nextPercent);
BackgroundWorker_ProgressChanged(progress0To1 * .5, processingState, out continueProcessing);
});
asynchMeshGroups.RemoveAt(indexBeingReplaced);
@ -102,9 +98,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
// and create selection info
PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, addedMeshIndex, (double progress0To1, string processingState, out bool continueProcessing) =>
{
continueProcessing = true;
int nextPercent = (int)((currentRatioDone + ratioPerDiscreetMesh * progress0To1) * 50) + 50;
backgroundWorker.ReportProgress(nextPercent);
BackgroundWorker_ProgressChanged(progress0To1 * .5 + .5, processingState, out continueProcessing);
});
currentRatioDone += ratioPerDiscreetMesh;
}

View file

@ -629,7 +629,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
string loadingPartLabel = LocalizedString.Get("Loading Parts");
string loadingPartLabelFull = "{0}:".FormatWith(loadingPartLabel);
processingProgressControl.textWidget.Text = loadingPartLabelFull;
processingProgressControl.ProcessType = loadingPartLabelFull;
processingProgressControl.Visible = true;
processingProgressControl.PercentComplete = 0;
LockEditControls();
@ -638,10 +638,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
BackgroundWorker loadAndAddPartsToPlateBackgroundWorker = null;
loadAndAddPartsToPlateBackgroundWorker = new BackgroundWorker();
loadAndAddPartsToPlateBackgroundWorker.WorkerReportsProgress = true;
loadAndAddPartsToPlateBackgroundWorker.DoWork += new DoWorkEventHandler(loadAndAddPartsToPlateBackgroundWorker_DoWork);
loadAndAddPartsToPlateBackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(BackgroundWorker_ProgressChanged);
loadAndAddPartsToPlateBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(loadAndAddPartsToPlateBackgroundWorker_RunWorkerCompleted);
loadAndAddPartsToPlateBackgroundWorker.RunWorkerAsync(filesToLoad);
@ -649,8 +647,12 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
enum TraceInfoOpperation { DONT_COPY, DO_COPY };
private void PushMeshGroupDataToAsynchLists(TraceInfoOpperation traceInfoOpperation)
private void PushMeshGroupDataToAsynchLists(TraceInfoOpperation traceInfoOpperation, ReportProgressRatio reportProgress = null)
{
UiThread.RunOnIdle((state) =>
{
processingProgressControl.ProgressMessage = "Async Copy";
});
asynchMeshGroups.Clear();
asynchMeshGroupTransforms.Clear();
for (int meshGroupIndex = 0; meshGroupIndex < MeshGroups.Count; meshGroupIndex++)
@ -681,6 +683,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
asynchPlatingDatas.Add(meshData);
}
UiThread.RunOnIdle((state) =>
{
processingProgressControl.ProgressMessage = "";
});
}
private void PullMeshGroupDataFromAsynchLists()
@ -732,7 +738,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
continueProcessing = !this.WidgetHasBeenClosed;
double ratioAvailable = (ratioPerFile * .5);
double currentRatio = currentRatioDone + progress0To1 * ratioAvailable;
backgroundWorker.ReportProgress((int)(currentRatio * 100));
BackgroundWorker_ProgressChanged(currentRatio, processingState, out continueProcessing);
});
if (WidgetHasBeenClosed)
@ -758,7 +764,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
continueProcessing = !this.WidgetHasBeenClosed;
double ratioAvailable = (ratioPerFile * .5);
double currentRatio = currentRatioDone + currentPlatingRatioDone + ratioAvailable + progress0To1 * ratioAvailable;
backgroundWorker.ReportProgress((int)(currentRatio * 100));
BackgroundWorker_ProgressChanged(currentRatio, processingState, out continueProcessing);
});
currentPlatingRatioDone += ratioPerSubMesh;
@ -886,9 +892,19 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
}
}
void BackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
Stopwatch timeSinceReported = new Stopwatch();
void BackgroundWorker_ProgressChanged(double progress0To1, string processingState, out bool continueProcessing)
{
processingProgressControl.PercentComplete = e.ProgressPercentage;
if (!timeSinceReported.IsRunning || timeSinceReported.ElapsedMilliseconds > 100)
{
UiThread.RunOnIdle((state) =>
{
processingProgressControl.PercentComplete = (int)(progress0To1 * 100 + .5);
processingProgressControl.ProgressMessage = processingState;
});
timeSinceReported.Restart();
}
continueProcessing = true;
}
private void CreateOptionsContent()
@ -1690,16 +1706,14 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
string progressSavingPartsLabel = LocalizedString.Get("Saving");
string progressSavingPartsLabelFull = "{0}:".FormatWith(progressSavingPartsLabel);
processingProgressControl.textWidget.Text = progressSavingPartsLabelFull;
processingProgressControl.ProcessType = progressSavingPartsLabelFull;
processingProgressControl.Visible = true;
processingProgressControl.PercentComplete = 0;
LockEditControls();
BackgroundWorker mergeAndSavePartsBackgroundWorker = new BackgroundWorker();
mergeAndSavePartsBackgroundWorker.WorkerReportsProgress = true;
mergeAndSavePartsBackgroundWorker.DoWork += new DoWorkEventHandler(mergeAndSavePartsBackgroundWorker_DoWork);
mergeAndSavePartsBackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(BackgroundWorker_ProgressChanged);
mergeAndSavePartsBackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(mergeAndSavePartsBackgroundWorker_RunWorkerCompleted);
mergeAndSavePartsBackgroundWorker.RunWorkerAsync();
@ -1720,8 +1734,8 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
asynchMeshGroups[i].Transform(asynchMeshGroupTransforms[i].TotalTransform);
int nextPercent = (i + 1) * 40 / asynchMeshGroups.Count;
backgroundWorker.ReportProgress(nextPercent);
bool continueProcessing;
BackgroundWorker_ProgressChanged((i + 1) * .4 / asynchMeshGroups.Count, "", out continueProcessing);
}
LibraryData.SaveToLibraryFolder(printItemWrapper, asynchMeshGroups);

View file

@ -2807,3 +2807,9 @@ Translated:Beta
English:Alpha
Translated:Alpha
English:Ungrouping
Translated:Ungrouping
English:Grouping
Translated:Grouping