VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "clsTCEventHandler"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
'******************************************************************'
'*                                                                *'
'*                      TurboCAD for Windows                      *'
'*                   Copyright (c) 1993 - 2001                    *'
'*             International Microcomputer Software, Inc.         *'
'*                            (IMSI)                              *'
'*                      All rights reserved.                      *'
'*                                                                *'
'******************************************************************'

Public Enum stateEnum
     enStart = 0
     enSelFirst = 1
     enSelSecond = 2
     enFinish = 3
End Enum

Public state As stateEnum

Private xdbToolEvents As IToolEvents
Private gxGrSbj As Graphic
Private gxGrSbd As Graphic

Public Function MouseDown(WhichDrawing As Object, WhichView As Object, WhichWindow As Object, Button As ImsiMouseButton, Shift As Long, X As Long, Y As Long, Cancel As IMSI_BOOL)
    
    Dim gxView As View
    Dim xView As Double
    Dim yView As Double
    Dim XScr As Double
    Dim YScr As Double
    Dim gxPResult As PickResult
    
    Dim gxGr As Graphic
    Dim gxVrt As Vertex
    
    Set gxView = WhichView
    If (Button = imsiLeftButton) Then
        XScr = X
        YScr = Y
        WhichView.ScreenToView XScr, YScr, xView, yView
        Set gxPResult = WhichView.PickPoint(xView, yView, , , False, False, True, False, False)
        If (gxPResult.Count > 0) Then
            Set gxGr = gxPResult(0).Graphic
            ProcesNextPoint WhichDrawing, WhichView, gxGr
        Else
            Beep
        End If
        
        Cancel = True
    Else
        Cancel = False
    End If

End Function

Public Function RunTool(WhichTool As Tool)
    DoLMCommand 0
End Function

Public Function DrawingDeactivate(WhichDrawing As IDrawing)
    DoLMCommand 0
End Function

Public Function ProcesNextPoint(Optional gxDwg As IDrawing, Optional gxView As View, Optional gxGr As Graphic)
    Dim gxTSets As TieSets
    
    Select Case state
    Case enBegin
        xdbToolEvents.ToolChangePrompt Me, "Select subject graphic for Vertex Tie", False
        xdbToolEvents.ToolChangeCommands Me, 1, "Finish", "Finish AddVertexTie macro", True, False, True
        state = enSelFirst
    Case enSelFirst
        xdbToolEvents.ToolChangePrompt Me, "Select subordinate graphic for Vertex Tie", False
        Set gxGrSbj = gxGr
        state = enSelSecond
    Case enSelSecond
        xdbToolEvents.ToolChangePrompt Me, "Select subject graphic for Vertex Tie", False
        Set gxGrSbd = gxGr
        Set gxTSets = gxDwg.TieSets
        gxTSets.Add "VertexTie.clsVertexTie", gxGrSbj, gxGrSbd, 0, 0
        gxTSets.Add "VertexTie.clsVertexTie", gxGrSbj, gxGrSbd, 1, 0
        
        state = enSelFirst
        Set gxGrSbj = Nothing
        Set gxGrSbd = Nothing
        gxView.Refresh
    End Select

End Function

Public Function DoLMCommand(idLMCmd As Long)
    xdbToolEvents.ToolChangePrompt Me, "", True
    xdbToolEvents.ToolChangeCommands Me, 0, , , , , False
    Application.DisconnectEvents idConnection
    state = enFinish
    Set gxGrSbj = Nothing
    Set gxGrSbd = Nothing
    tcEventsHandler = Nothing
End Function

Private Sub Class_Initialize()
    Set xdbToolEvents = Application
    state = enStart
End Sub
