Files
egtstone3d/CompoLib/ParametricCompoVM.vb
T
2025-02-05 17:32:10 +01:00

131 lines
4.7 KiB
VB.net

Imports System.IO
Imports System.Windows.Forms.AxHost
Imports EgtUILib.EgtInterface
Imports EgtWPFLib5
Public Class ParametricCompoVM
Inherits SceneUserControlVM
Public Enum ParamType As Integer
BOOL = 1
INT = 2
LEN = 3
DOUB = 4
STR = 5
End Enum
Private Const LUA_CMP_VARS As String = "CMP"
Friend Const LUA_VALUE As String = LUA_CMP_VARS & ".V"
Const LUA_NAME As String = LUA_CMP_VARS & ".N"
Const LUA_TYPE As String = LUA_CMP_VARS & ".T"
Private sLuaPath As String = String.Empty
Sub New(sFile As String)
' Recupero path cartella che contiene i componenti
GetMainPrivateProfileString(K_COMPO, COMPO_DIR, "", sLuaPath)
sLuaPath &= sFile
LoadParamList()
' aggiorno visualizzazione
EgtSetView(VT.TOP, False)
EgtZoom(ZM.ALL)
End Sub
Public Overrides Sub LoadParamList()
ParamList.Clear()
EgtLuaExecFile(sLuaPath)
Dim sPar As String = "0"
EgtLuaGetGlobStringVar("CMP.Npar", sPar)
Dim nPar As Integer = CInt(sPar)
ParamList.Add(New _TextBlockParam("Messaggio", "RETTANGOLO", Visibility.Visible))
'ParamList.Add(New _TextBoxParam("L", "300", Visibility.Visible))
'ParamList.Add(New _TextBoxParam("H", "200", Visibility.Visible))
' Pulisco lista variabili
' Recupero nome, tipo e valore delle variabili globali
For i As Integer = 1 To nPar
Dim NewCompo As GenericParam = Nothing
If NameTypeValueFromLua(i, NewCompo) Then
ParamList.Add(NewCompo)
End If
Next
End Sub
Private Sub ExecLua()
'' recupero i valori nelle box
'Dim l_TextBox As _TextBoxParam = DirectCast(ParamList(1), _TextBoxParam)
'Dim h_TextBox As _TextBoxParam = DirectCast(ParamList(2), _TextBoxParam)
'' verifico che siano validi
'If String.IsNullOrEmpty(l_TextBox.sValue) Then l_TextBox.sValue = "0"
'If String.IsNullOrEmpty(h_TextBox.sValue) Then h_TextBox.sValue = "0"
Dim nVeinCtx As Integer = Map.refSceneHostVM.MainScene.GetCtx()
If Not File.Exists(sLuaPath) Then
EgtOutLog("Matching error: missing file (" & sLuaPath & ")")
Return
End If
' Parsing
EgtLuaExecFile(sLuaPath)
EgtSetCurrentContext(nVeinCtx)
For Index As Integer = 0 To ParamList.Count - 1
If TypeOf ParamList(Index) Is _TextBoxParam Then
Dim _TextBox As _TextBoxParam = DirectCast(ParamList(Index), _TextBoxParam)
EgtLuaSetGlobNumVar("CMP.V" & Index, CDbl(_TextBox.sValue))
ElseIf TypeOf ParamList(Index) Is _CheckBoxParam Then
Dim _CheckBox As _CheckBoxParam = DirectCast(ParamList(Index), _CheckBoxParam)
EgtLuaSetGlobBoolVar("CMP.V" & Index, _CheckBox.IsChecked)
End If
Next
EgtLuaExecLine("CMP_Draw" & "(true)")
EgtLuaResetGlobVar("CMP")
End Sub
Public Overrides Sub Conferma()
End Sub
Public Overrides Sub Annulla()
End Sub
Public Overrides Sub ShowPreview()
ExecLua()
EgtDraw()
End Sub
Private Sub Close()
End Sub
Private Function NameTypeValueFromLua(nInd As Integer, ByRef Param As GenericParam) As Boolean
Dim bOk As Boolean = True
Dim sName As String = String.Empty
Dim nType As Integer = 0
bOk = bOk AndAlso EgtLuaGetGlobStringVar(LUA_NAME & nInd.ToString(), sName)
bOk = bOk AndAlso EgtLuaGetGlobIntVar(LUA_TYPE & nInd.ToString(), nType)
Return bOk AndAlso FromLua(nInd, sName, nType, Param)
End Function
Private Function FromLua(nInd As Integer, sName As String, nType As Integer, ByRef Param As GenericParam) As Boolean
Select Case nType
Case ParamType.BOOL
Dim Compo As New _CheckBoxParam(sName, ParamType.BOOL)
Param = Compo
Return EgtLuaGetGlobBoolVar(LUA_VALUE & nInd.ToString(), Compo.IsChecked)
Case ParamType.INT
Dim Compo As New _TextBoxParam(sName, ParamType.INT)
Param = Compo
Return EgtLuaGetGlobIntVar(LUA_VALUE & nInd.ToString(), Compo.sValue)
Case ParamType.LEN
Dim Compo As New _TextBoxParam(sName, ParamType.LEN)
Param = Compo
Return EgtLuaGetGlobNumVar(LUA_VALUE & nInd.ToString(), Compo.sValue)
Case ParamType.DOUB
Dim Compo As New _TextBoxParam(sName, ParamType.DOUB)
Param = Compo
Return EgtLuaGetGlobNumVar(LUA_VALUE & nInd.ToString(), Compo.sValue)
Case ParamType.STR
Dim Compo As New _TextBoxParam(sName, ParamType.STR)
Param = Compo
Return EgtLuaGetGlobStringVar(LUA_VALUE & nInd.ToString(), Compo.sValue)
End Select
Return False
End Function
End Class