Display a ruler in FJ screen

Overview

Display a ruler to in FJ screen arbitrarily.

Specification of this example


Behavior
Input the position of a ruler to a control on the PanDA form, and display it in FJ screen.

Screenshot


How to try this example
1.Click the link below, then the folder containing zip file automatically opens.
refFile

2.Right-click and hold on the zip file, and drop it on working window of FJ system, then the demo-tool automatically starts.

3.Click "Start PanDA Form" button in the program, then the PanDA form will start.

4.Input the position of a ruler to a control on the PanDA form.

5.Click "Re-Measure" button, then system remeasures sample image files and display the ruler.

How to implement

Scene data
Unit No.
Processing Item
0.
Camera Image Input
1.
Search
2.
Macro

Set the macro program below to "2.Macro".
Macro Program
*MCRINIT
    LEN& = 5
Return

*MEASUREPROC
Return

*MEASUREDISPG
    GetImageSize UnitNo, 0, IMAGEX&, IMAGEY&         '(1)

    DrawLine X&&, 0, X&&, IMAGEY&, 0         '(2)
    DrawLine 0, Y&&, IMAGEX&, Y&&, 0

    If PITCH&& <> 0 Then
    If Y&& - LEN& < 0 Then
        MINY& = 0
    Else
        MINY& = Y&& - LEN&
    EndIf

    If Y&& - LEN& > IMAGEY& Then
        MAXY& = IMAGEY&
    Else
        MAXY& = Y&& + LEN&
    EndIf

    If X&& - LEN& < 0 Then
        MINX& = 0
    Else
        MINX& = X&& - LEN&
    EndIf

    If X&& - LEN& > IMAGEX& Then
        MAXX& = IMAGEX&
    Else
        MAXX& = X&& + LEN&
    EndIf

    COUNT& = 0
    Do
        DrawLine PITCH&& * COUNT&, MINY&, PITCH&& * COUNT&, MAXY&, 0
        COUNT& =COUNT& + 1
    Loop While PITCH&& * COUNT& < IMAGEX&

    COUNT& = 0
    Do
        DrawLine MINX&, PITCH&& * COUNT&, MAXX&, PITCH&& * COUNT&, 0
        COUNT& =COUNT& + 1
    Loop While PITCH&& * COUNT& < IMAGEY&

    EndIf
Return

The macro program is in refthis link.
Explanation
(1)Get the image size.
(2)Draw horizontal line and vertical line which cross the desinated position.
Process of UI unit
Public Class Macro_VB_DrawRuler
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load                              '(1)
        Dim imagex, imagey As Integer
        FZ_FormBase.FZ_FormBase.GetImageSize(2, 0, imagex, imagey)
        Me.SliderSet_X.MaxValue = imagex
        Me.SliderSet_Y.MaxValue = imagey

        Dim X, Y As Double
        FZ_PanDAForm.FZ_PanDAForm.GetUnitData(2, "X&&", X)
        FZ_PanDAForm.FZ_PanDAForm.GetUnitData(2, "Y&&", Y)
        Me.SliderSet_X.Measurement = X
        Me.SliderSet_Y.Measurement = Y
    End Sub

    Private Sub SliderSet_X_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SliderSet_X.ValueChanged   '(2)
        FZ_PanDAForm.FZ_PanDAForm.SetUnitData(2, "X&&", Me.SliderSet_X.Measurement)
    End Sub

    Private Sub SliderSet_Y_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SliderSet_Y.ValueChanged   '(2)
        FZ_PanDAForm.FZ_PanDAForm.SetUnitData(2, "Y&&", Me.SliderSet_Y.Measurement)
    End Sub

    Private Sub ImageButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImageButton1.Click
        Me.Close()
    End Sub
End Class

Explanation
(1)When form load, get the image size and the position of the ruler.
(2)When change the slider control on the PanDA form, set the position to the variables of Macro Unit.

Source codes

Total source codes can be get from refhere.