Eyeshot 10 WinForms API Reference
WorkUnit Class
Members  Example 

WinForms Assembly > devDept.Eyeshot Namespace : WorkUnit Class

Base class for background working support. Overriding this class you can build a model or do your CPU intensive calculations on a separate thread keeping your application UI responsive.

Depending on the nature of the work you may need to override both the DoWork and WorkCompleted methods or only the DoWork one and provide a ViewportLayout.WorkCompletedEventHandler to be notified when the work has completed.

Syntax
'Declaration
 
Public Class WorkUnit 
public class WorkUnit 
Example
The following sample demonstrates the WorkUnit class usage for building a solid model.
public void Lego(Viewport viewport)
{
  
    BuildLego bl = new BuildLego();
  
    viewport.StartWork(bl);
}
            
private class BuildLego : WorkUnit
{
  
    private Solid[] model;
  
    protected override void DoWork(System.ComponentModel.BackgroundWorker worker, System.ComponentModel.DoWorkEventArgs doWorkEventArgs)
    {
        // dimensions
        double width = 95.75;
        double depth = 47.75;
        double height = 3.25;
 
        // rows ans columns number
        int nRows = 6;
        int nColumns = 12;
  
        // top cylinders size and position
        double cylRadius = 2.55;
        double distFromBorder = 1;
        double cylHeight = 1.6;
        Point2D startPos = new Point2D(3.55, 3.55);
  
        // creates the plate
        model = new Solid[]{Solid.CreateBox(width, depth, height)};
                
        // adds cylinders to the upper side
        double xOffset, yOffset;
  
        if (nColumns <= 1)
            xOffset = 0;
        else
            xOffset = (width - 2 * distFromBorder - 2 * cylRadius) / (nColumns - 1);
  
        if (nRows <= 1)
            yOffset = 0;
        else
            yOffset = (depth - 2 * distFromBorder - 2 * cylRadius) / (nRows - 1);
            
        Circle circle = new Circle(startPos.X, startPos.Y, height, cylRadius);
  
        CompositeCurve curve = new CompositeCurve(circle);
  
        int currentValue = 0;
  
        for (int i = 0; i < nRows; i++)
        {
            Solid solid = model[0];
  
            for (int j = 0; j < nColumns; j++)
            {
                model = solid.ExtrudeAdd(curve, 0.2, new Vector3D(0, 0, cylHeight), true);
  
                if (model != null)
                {
                    solid = model[0];
  
                    curve.Translate(xOffset, 0, 0);
  
                    // updates progress using build in progress bar
                    UpdateProgress(++currentValue, nRows * nColumns, "Adding top cylinders...", worker);
 
                    // checks for cancellation using built in progress bar cancel button
                    if (Canceled(worker, doWorkEventArgs))
                        return;
                }
            }
  
            curve.Translate(-nColumns * xOffset, yOffset, 0);
        }
 
    }
 
    protected override void WorkCompleted(Viewport viewport)
    {
        // adds the result to viewport entities collection
        ViewportLayout._entities.AddRange(model, 0, Color.Green);
        viewport.ZoomFit();
 
        // prints the execution time
        Console.WriteLine("Execution time: " + ExecutionTime + " ms");
    }
}
Public Sub Lego(viewport As Viewport)
              
                 Dim bl As New BuildLego()
              
                 viewport.StartWork(bl)
              
             End Sub
              
             Private Class BuildLego
                 Inherits WorkUnit
              
                 Private model As Solid()
              
                 Protected Overrides Sub DoWork(worker As System.ComponentModel.BackgroundWorker, doWorkEventArgs As System.ComponentModel.DoWorkEventArgs)
              
                     ' dimensions
                     Dim width As Double = 95.75
                     Dim depth As Double = 47.75
                     Dim height As Double = 3.25
              
                     ' rows ans columns number
                     Dim nRows As Integer = 6
                     Dim nColumns As Integer = 12
              
                     ' top cylinders size and position
                     Dim cylRadius As Double = 2.55
                     Dim distFromBorder As Double = 1
                     Dim cylHeight As Double = 1.6
                     Dim startPos As New Point2D(3.55, 3.55)
              
                     ' creates the plate
                     model = New Solid() {Solid.CreateBox(width, depth, height)}
              
                     ' adds cylinders to the upper side
                     Dim xOffset As Double, yOffset As Double
              
                     If nColumns <= 1 Then
                         xOffset = 0
                     Else
                         xOffset = (width - 2 * distFromBorder - 2 * cylRadius) / (nColumns - 1)
                     End If
              
                     If nRows <= 1 Then
                         yOffset = 0
                     Else
                         yOffset = (depth - 2 * distFromBorder - 2 * cylRadius) / (nRows - 1)
                     End If
              
                     Dim circle As New Circle(startPos.X, startPos.Y, height, cylRadius)
              
                     Dim curve As New CompositeCurve(circle)
              
                     Dim currentValue As Integer = 0
              
                     For i As Integer = 0 To nRows - 1
              
                         Dim theSolid As Solid = model(0)
              
                         For j As Integer = 0 To nColumns - 1
              
                             model = theSolid.ExtrudeAdd(curve, 0.2, New Vector3D(0, 0, cylHeight), True)
              
                             If model IsNot Nothing Then
              
                                 theSolid = model(0)
              
                                 curve.Translate(xOffset, 0, 0)
              
                                 ' updates progress using build in progress bar
                                 UpdateProgress(System.Threading.Interlocked.Increment(currentValue), nRows * nColumns, "Adding top cylinders...", worker)
              
                                 ' checks for cancellation using built in progress bar cancel button
                                 If Canceled(worker, doWorkEventArgs) Then
                                     Return
                                 End If
              
                             End If
              
                         Next
              
                         curve.Translate(-nColumns * xOffset, yOffset, 0)
                     Next
              
                 End Sub
              
                 Protected Overrides Sub WorkCompleted(viewport As Viewport)
                     ' adds the result to viewport entities collection
                     ViewportLayout._entities.AddRange(model, 0, Color.Green)
                     viewport.ZoomFit()
             
                     ' prints the execution time
                     Console.WriteLine("Execution time: " + ExecutionTime + " ms")
                 End Sub
             End Class
Inheritance Hierarchy

System.Object
   devDept.Eyeshot.WorkUnit
      devDept.Eyeshot.Fem.SolverBase
      devDept.Eyeshot.HiddenLinesView
      devDept.Eyeshot.Translators.ReadFileAsync
      devDept.Eyeshot.Translators.WriteFileAsync
      devDept.Eyeshot.Triangulation.BallPivoting
      devDept.Eyeshot.Triangulation.MarchingCubes
      devDept.Eyeshot.Triangulation.MarchingSquares

See Also

Reference

WorkUnit Members
devDept.Eyeshot Namespace
CancelWork() method.
DoWork() method.
StartWork() method.