Sub Class_Globals
Private Viewer2D As GCodeViewer2D
Private Viewer3D As GCodeViewer3D
Private mUse3D As Boolean
End Sub
'Inizializes the gcode viewer object to the given Pane with a selected Zoom factor for grid.
'Zoom factor 1.0 is a non scaled grid.
Public Sub Initialize (Use3D As Boolean, Pnl As Panel, Zoom As Float, Antialiasing As Boolean)
mUse3D = Use3D
If mUse3D Then
Viewer3D.Initialize(Pnl, Zoom, Antialiasing)
Else
Viewer2D.Initialize(Pnl, Zoom, Antialiasing)
End If
End Sub
'Show the gcode viewer.
Public Sub Show(X As Int, Y As Int, Width As Int, Height As Int, InnerPaneWidth As Int, InnerPaneHeight As Int)
If mUse3D Then
Viewer3D.Show(X, Y, Width, Height, InnerPaneWidth, InnerPaneHeight)
Else
Viewer2D.Show(X, Y, Width, Height, InnerPaneWidth, InnerPaneHeight)
End If
End Sub
'Resize the gcode viewer panel.
Public Sub Resize (X As Float, Y As Float, Width As Float, Height As Float)
If mUse3D Then
Viewer3D.Resize(X, Y, Width, Height)
Else
Viewer2D.Resize(X, Y, Width, Height)
End If
End Sub
'Clear the viewer with specified color.
Public Sub Clear (Color As Int)
If mUse3D Then
Viewer3D.Clear(Color)
Else
Viewer2D.Clear(Color)
End If
End Sub
'Fill the working plane with a specified color.
Public Sub FillPlane(Color As Long)
If mUse3D Then
Viewer3D.FillPlane(Color)
Else
Viewer2D.FillPlane(Color)
End If
End Sub
'Sets the current drawing plane size of CNC machine expressed in Units (Millimeters or Inches).
'
'Example:
'<code>
'Dim Viewer As GCodeViewer3D
'Viewer.SetDrawingPlaneSize(200,200) 'Setup drawings for a machine that has plane 200x200 millimeters. </code>
Public Sub SetDrawingPlaneSize(PlaneWidth As Float, PlaneHeight As Float)
If mUse3D Then
Viewer3D.SetDrawingPlaneSize(PlaneWidth, PlaneHeight)
Else
Viewer2D.SetDrawingPlaneSize(PlaneWidth, PlaneHeight)
End If
End Sub
'Draw a grid based on CNC working plane dimensions (Units) you previousely setup with SetDrawingPlaneSize method.
'You can set Canvas background color, grid color and line width.
'
'The grid has separate settings for MinorTicks (millimeters), MediumTicks (centimeters) and MajorTicks (every 5 centimeters)
'
'Example:
'<code>Viewer.DrawGrid(Colors.Black, Colors.ARGB(100,255,255,255), Colors.ARGB(100,255,255,255), Colors.ARGB(100,255,255,255), .2, .4, .8)</code>
'
'Parameters:
'BackColor: the viewer background color (NOTE: this is not a grid background only but full viewer background)
'MinorTicksColor: the color of MinorTicks lines
'MediumTicksColor: the color of MediumTicks lines
'MajorTicksColor: the color of MajorTicks lines
'MinorTicksLineWidth: the width of MinorTicks lines
'MediumTicksLineWidth: the width of MediumTicks lines
'MajorTicksLineWidth: the width of MajorTicks lines
Public Sub DrawPlaneGrid (BackColor As Int, MinorTicksColor As Int, MediumTicksColor As Int, MajorTicksColor As Int, MinorTicksLineWidth As Float, MediumTicksLineWidth As Float, MajorTicksLineWidth As Float)
If mUse3D Then
Viewer3D.DrawPlaneGrid(BackColor, MinorTicksColor, MediumTicksColor, MajorTicksColor, MinorTicksLineWidth, MediumTicksLineWidth, MajorTicksLineWidth)
Else
Viewer2D.DrawPlaneGrid(BackColor, MinorTicksColor, MediumTicksColor, MajorTicksColor, MinorTicksLineWidth, MediumTicksLineWidth, MajorTicksLineWidth)
End If
End Sub
'Draw a plane border (squared or rounded) with the specified color and line width.
'Use SetStartPoint method to set a start position that by default is X = 0 , Y = 0, Z = 0.
Public Sub DrawPlaneBorders(RoundPlane As Boolean, Color As Int, LineWidth As Float)
If mUse3D Then
Viewer3D.DrawPlaneBorders(RoundPlane, Color, LineWidth)
Else
Viewer2D.DrawPlaneBorders(RoundPlane, Color, LineWidth)
End If
End Sub
'Sets first drawing start point position from origin.
'By default X = 0, Y = 0, Z = 0 and assumed as CNC Home position.
'
'Z not used on 2D class (see 3D class), you can pass any numeric value like 0, the library just ignore it.
Public Sub SetStartPoint(X As Float, Y As Float, Z As Float)
If mUse3D Then
Viewer3D.SetStartPoint(X, Y, Z)
Else
Viewer2D.SetStartPoint(X, Y, Z)
End If
End Sub
'Force the viewer redraw a full view.
Public Sub Redraw
If mUse3D Then Viewer3D.Redraw Else Viewer2D.Redraw
End Sub
Public Sub ResetRedrawingArea
If mUse3D Then
Viewer3D.ResetRedrawingArea
Else
Viewer2D.ResetRedrawingArea
End If
End Sub
'Force the viewer redraw the working area rectangle.
Public Sub RedrawWorkingArea
If mUse3D Then
Viewer3D.RedrawWorkingArea
Else
Viewer2D.RedrawWorkingArea
End If
End Sub
' PROPERTIES
'Gets current X Axis position.
Public Sub CurrentX As Float
If mUse3D Then
Return Viewer3D.CurrentX
Else
Return Viewer2D.CurrentX
End If
End Sub
'Gets current Y Axis position.
Public Sub CurrentY As Float
If mUse3D Then
Return Viewer3D.CurrentY
Else
Return Viewer2D.CurrentY
End If
End Sub
'Gets current Z Axis position.
Public Sub CurrentZ As Float
If mUse3D Then
Return Viewer3D.CurrentZ
Else
Return Viewer2D.CurrentZ
End If
End Sub
'Gets or sets the current viewer zoom factor.
Public Sub setZoom(Zoom As Float)
If mUse3D Then Viewer3D.Zoom = Zoom Else Viewer2D.Zoom = Zoom
End Sub
Public Sub getZoom As Float
If mUse3D Then
Return Viewer3D.Zoom
Else
Return Viewer2D.Zoom
End If
End Sub
'Get round plane property.
'You can set it with DrawPlaneBorders method
Public Sub getRoundPlane As Boolean
If mUse3D Then
Return Viewer3D.RoundPlane
Else
Return Viewer2D.RoundPlane
End If
End Sub
' VIEWS
'Returns a reference of viewer canvas object.
'You can use this to change any properties you like, add a style etc...
Public Sub getCanvas As Canvas
If mUse3D Then
Return Viewer3D.Canvas
Else
Return Viewer2D.Canvas
End If
End Sub
'Returns a reference of viewer panel object.
'You can use this to change any properties you like, add a style etc...
Public Sub getPanel As Panel
If mUse3D Then
Return Viewer3D.Panel
Else
Return Viewer2D.Panel
End If
End Sub
'Returns a reference of viewer ScrollPane object.
'You can use this to get InnerNode instance or change any properties you like, add a style etc...
Public Sub getScrollPane As ScrollView2D
If mUse3D Then
Return Viewer3D.ScrollPane
Else
Return Viewer2D.ScrollPane
End If
End Sub
' //////////// DRAWING FUNCTIONS ////////////
'Draw a point in the specified position, color and line with.
'
'Z not used on 2D class (see 3D class), you can pass any numeric value like 0, the library just ignore it.
Public Sub DrawPoint(X As Float, Y As Float, Z As Float, Color As Int, PointWidth As Float)
If mUse3D Then
Viewer3D.DrawPoint(X, Y, Z, Color, PointWidth)
Else
Viewer2D.DrawPoint(X, Y, Z, Color, PointWidth)
End If
End Sub
'Draw a line from X1,Y1 to X2,Y2 position with the specified color and width.
'
'Z1 and Z2 not used on 2D class (see 3D class), you can pass any numeric value like 0, the library just ignore it.
Public Sub DrawLine(X1 As Float, Y1 As Float, Z1 As Float, X2 As Float, Y2 As Float, Z2 As Float, Color As Int, LineWidth As Float, StartCup As Boolean, EndCup As Boolean)
If mUse3D Then
Viewer3D.DrawLine(X1, Y1, Z1, X2, Y2, Z2, Color, LineWidth, StartCup, EndCup)
Else
Viewer2D.DrawLine(X1, Y1, Z1, X2, Y2, Z2, Color, LineWidth, StartCup, EndCup)
End If
End Sub
'Draw a line from last X,Y,Z position to the new X,Y,Z position with the specified color and width.
'Use SetStartPoint method to set a first start position that by default is X=0 Y=0 Z=0 (Home).
'
'Z not used on 2D class (see 3D class), you can pass any numeric value like 0, the library just ignore it.
Public Sub DrawLineTo(X As Float, Y As Float, Z As Float, Color As Int, LineWidth As Float, StartCup As Boolean, EndCup As Boolean)
If mUse3D Then
Viewer3D.DrawLineTo(X, Y, Z, Color, LineWidth, StartCup, EndCup)
Else
Viewer2D.DrawLineTo(X, Y, Z, Color, LineWidth, StartCup, EndCup)
End If
End Sub
'Draw a circle in the specified position, radius, color, fill and stroke width.
'
'Z not used on 2D class (see 3D class), you can pass any numeric value like 0, the library just ignore it.
Public Sub DrawCircle(X As Float, Y As Float, Z As Float, Radius As Float, Color As Int, Filled As Boolean, StrokeWidth As Float)
If mUse3D Then
Viewer3D.DrawCircle(X, Y, Z, Radius, Color, Filled, StrokeWidth)
Else
Viewer2D.DrawCircle(X, Y, Z, Radius, Color, Filled, StrokeWidth)
End If
End Sub
'Draw a text (2D) with the specified properties.
Public Sub DrawText(Text As String, X As Float, Y As Float, Typ As Typeface, Size As Float, Color As Int, Alignment As String)
If mUse3D Then
Viewer3D.DrawText(Text, X, Y, Typ, Size, Color, Alignment)
Else
Viewer2D.DrawText(Text, X, Y, Typ, Size, Color, Alignment)
End If
End Sub
Public Sub TakeSnapshot
If mUse3D Then Viewer3D.TakeSnapshot Else Viewer2D.TakeSnapshot
End Sub