'//////////////////////////////////////////////////////////////////////////////
'//
'//  Copyright 2025 Autodesk, Inc.  All rights reserved.
'//
'//  Use of this software is subject to the terms of the Autodesk license 
'//  agreement provided at the time of installation or download, or which 
'//  otherwise accompanies this software in either electronic or hard copy form.   
'//
'//////////////////////////////////////////////////////////////////////////////
'

Imports SymBBAuto
Imports Autodesk.AutoCAD.ApplicationServices

Public Class frmSettings

    Dim taperStd As McadTaperStandard

    Private Sub frmSettings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dimType As McadTaperDimensionType
        Dim ratioFormat As McadTaperRatioFormatType
        Dim separator As String = Nothing

        'get dimension type
        taperStd.GetDimensionType(dimType, ratioFormat, separator)
        'set dialog settings
        If (dimType = McadTaperDimensionType.sbRatio) Then
            btnRatio.Checked = True
        Else
            btnPercentage.Checked = True
        End If

        If (ratioFormat = McadTaperRatioFormatType.sbFraction) Then
            cbFormat.SelectedIndex = 0
        ElseIf ratioFormat = McadTaperRatioFormatType.sbNoFraction Then
            cbFormat.SelectedIndex = 1
        Else
            cbFormat.SelectedIndex = 2
        End If

        txtSeparator.Text = separator

    End Sub

    Private Sub m_settingsOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSettingsOk.Click
        'set dimension settings according to dialog changes
        Dim separator As String = txtSeparator.Text
        Dim format As Integer = cbFormat.SelectedIndex
        If (btnRatio.Checked) Then
            taperStd.SetDimensionType(McadTaperDimensionType.sbRatio, CType(format, McadTaperRatioFormatType), separator)
        Else
            taperStd.SetDimensionType(McadTaperDimensionType.sbPercentage, CType(format, McadTaperRatioFormatType), separator)
        End If
        Me.Close()
    End Sub

    Private Sub m_settingsCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSettingsCancel.Click
        Me.Close()
    End Sub

    Public Sub initialize(ByVal std As McadTaperStandard)
        'initialize dimension type
        taperStd = std
    End Sub

    Private Sub btnRatio_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRatio.CheckedChanged
        'when Radio is checked, format combo box and separator text box will be enabled.
        If btnRatio.Checked Then
            btnPercentage.Checked = False
            cbFormat.Enabled = True
            txtSeparator.Enabled = True
        End If
    End Sub

    Private Sub btnPercentage_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPercentage.CheckedChanged
        'when Percentage is checked, format combo box and separator text box will be disabled.
        If btnPercentage.Checked Then
            btnRatio.Checked = False
            cbFormat.Enabled = False
            txtSeparator.Enabled = False
        End If
    End Sub
End Class