In Eyeshot 9 ProgressBar can be used only in asynchronous WorkUnits (the ones ran with viewportLayout.StartWork()).
In case you would like to use ProgressBar in a synchronous way, independently from WorkUnits, updating its value when needed and then calling Invalidate(), you can use this trick:
Derive ProgressBar class and expose its Draw method:
public class MyProgressBar : devDept.Eyeshot.ProgressBar
{
public MyProgressBar()
{
Visible = false;
}
public void Draw(ViewportLayout.DrawSceneParams myParams)
{
base.Draw(myParams);
}
}
Derive the ViewportLayout and draw the custom progress bar in DrawOverlay method:
internal class MyViewportLayout : devDept.Eyeshot.ViewportLayout
{
public MyProgressBar myProgr = new MyProgressBar();
protected override void DrawOverlay(DrawSceneParams data)
{
base.DrawOverlay(data);
if (myProgr.Visible)
{
data.Viewport = Viewports[ActiveViewport];
myProgr.Draw(data);
}
}
}
Create the viewportLayout1 control as an instance of the MyViewportLayout class:
this.viewportLayout1 = new MyViewportLayout();
Somewhere in your code enable/disable the custom ProgressBar and update its value:
var myProgr = ((MyViewportLayout) viewportLayout1).myProgr;
if (!myProgr.Visible)
{
myProgr.Text = "Processing...";
myProgr.Visible = true;
myProgr.Value = 0;
}
else if (myProgr.Value == 100)
{
myProgr.Value = 0;
myProgr.Visible = false;
}
if (myProgr.Visible)
myProgr.Value += 10;
viewportLayout1.Invalidate();
Comments
How do you set the max value of the progress bar calculate the increment value?
Realised that you can calculate the value as a percentage.
private int Progress(int count, int value, int total)
{
return (int)((double)count / total * 100);
}
Is there some way to display multiple progress bars for display progress of simulations calculations in different threads and/or different WorkUnits?
Thanks, Jas
I have use this method in a project with Platform target "AnyCPU", this works perfectly.
But I cannot get it to work on a project with Platform target "x64".
I have created the internal class MyViewportLayout as described above. It shows up in the Toolbox but when I try to drag it onto my form I get the message "Failed to load toolbox item "MyViewportLayout". It will be removed from your toolbox.
Here is the code of MyViewportLayout:
internal class MyViewportLayout : devDept.Eyeshot.ViewportLayout
{
internal MyProgressBar myProgressBar = new MyProgressBar();
protected override void DrawOverlay(DrawSceneParams data)
{
base.DrawOverlay(data);
if (myProgressBar.Visible)
{
data.Viewport = Viewports[ActiveViewport];
myProgressBar.DrawProgressBar(data);
}
}
}
internal class MyProgressBar : devDept.Eyeshot.ProgressBar
{
internal MyProgressBar()
{
Visible = false;
}
internal void DrawProgressBar(devDept.Eyeshot.ViewportLayout.DrawSceneParams myParams)
{
base.Draw(myParams);
}
}
Can you tell me why it fails ?
Please sign in to leave a comment.