a4b5cd4834
- Cambiati nomi classi e file.
312 lines
13 KiB
VB.net
312 lines
13 KiB
VB.net
'----------------------------------------------------------------------------
|
|
' EgalTech 2016-2016
|
|
'----------------------------------------------------------------------------
|
|
' File : GunStock.vb Data : 13.12.16 Versione : 1.6x2
|
|
' Contenuto : Classe GunStock (interfaccia per script Calci di Fucile).
|
|
'
|
|
'
|
|
'
|
|
' Modifiche : 08.10.16 DS Creazione modulo.
|
|
'
|
|
'
|
|
'----------------------------------------------------------------------------
|
|
|
|
Imports System.Collections.ObjectModel
|
|
Imports Microsoft.VisualBasic
|
|
Imports EgtUILib
|
|
|
|
Module GunStock
|
|
|
|
Private m_sModFile As String = String.Empty
|
|
Private m_sPezFile As String = String.Empty
|
|
Private m_sDescription As String = String.Empty
|
|
Structure ParamData
|
|
Dim sName As String
|
|
Dim dMin As Double
|
|
Dim dMax As Double
|
|
Dim dDef As Double
|
|
Dim dVal As Double
|
|
Dim sVar As String
|
|
End Structure
|
|
Private m_vParams() As ParamData
|
|
|
|
Function ExecGunStockMod(ByRef scene As Scene, sFilePath As String) As Boolean
|
|
' Scelta file MOD : se sFilePath non vuoto apro questo file
|
|
If Not String.IsNullOrEmpty(sFilePath) Then
|
|
m_sModFile = sFilePath
|
|
' altrimenti chiedo all'utente
|
|
Else
|
|
' Direttorio corrente per file MOD
|
|
Dim sDir As String = String.Empty
|
|
GetPrivateProfileString(S_GUNSTOCK, K_MODDIR, "", sDir)
|
|
' Apertura dialogo di scelta file MOD
|
|
Dim OpenFileDialog As New System.Windows.Forms.OpenFileDialog
|
|
OpenFileDialog.Title = "Open MOD file"
|
|
OpenFileDialog.Filter = "Model file (*.mod)|*.mod"
|
|
OpenFileDialog.FilterIndex = 1
|
|
OpenFileDialog.InitialDirectory = sDir
|
|
If OpenFileDialog.ShowDialog <> Windows.Forms.DialogResult.OK Then
|
|
Return True
|
|
End If
|
|
m_sModFile = OpenFileDialog.FileName
|
|
End If
|
|
WritePrivateProfileString(S_GUNSTOCK, K_MODDIR, System.IO.Path.GetDirectoryName(m_sModFile))
|
|
IniFile.m_MODFilePath = m_sModFile
|
|
|
|
' Carico ambiente lua per Gunstock
|
|
If Not LoadGunStock() Then
|
|
MessageBox.Show(EgtMsg(MSG_GUNSTOCKERRORS + 2), EgtMsg(MSG_GUNSTOCKERRORS + 1), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
EgtOutLog("Error in LoadGunStock")
|
|
Return False
|
|
End If
|
|
|
|
' Lettura dei parametri dal modello
|
|
m_sDescription = String.Empty
|
|
If Not ReadModParams() Then
|
|
MessageBox.Show(EgtMsg(MSG_GUNSTOCKERRORS + 3), EgtMsg(MSG_GUNSTOCKERRORS + 1), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
EgtOutLog("Error in ReadModParams")
|
|
Return False
|
|
End If
|
|
|
|
' Calcolo path per file PEZ
|
|
m_sPezFile = System.IO.Path.GetDirectoryName(System.IO.Path.GetDirectoryName(m_sModFile)) & "\PEZ\" &
|
|
System.IO.Path.GetFileNameWithoutExtension(m_sModFile) & ".pez"
|
|
If Not UpdatePezParams(True) Then
|
|
Return True
|
|
End If
|
|
WritePrivateProfileString(S_GUNSTOCK, K_PEZDIR, System.IO.Path.GetDirectoryName(m_sPezFile))
|
|
IniFile.m_PEZFilePath = m_sPezFile
|
|
|
|
' Scrivo file PEZ
|
|
If Not WritePezParams() Then
|
|
MessageBox.Show(EgtMsg(MSG_GUNSTOCKERRORS + 4), EgtMsg(MSG_GUNSTOCKERRORS + 1), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
EgtOutLog("Error in WritePezParams")
|
|
Return False
|
|
End If
|
|
|
|
' Visualizzo dimensioni grezzo
|
|
If Not ShowRawDim() Then
|
|
MessageBox.Show(EgtMsg(MSG_GUNSTOCKERRORS + 4), EgtMsg(MSG_GUNSTOCKERRORS + 1), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
EgtOutLog("Error in ShawRawDim")
|
|
Return False
|
|
End If
|
|
|
|
' Generazione calcio di fucile
|
|
scene.Cursor = System.Windows.Forms.Cursors.WaitCursor
|
|
Dim bOk As Boolean = CreateGunStock()
|
|
' Aggiorno la visualizzazione
|
|
EgtZoom(ZM.ALL)
|
|
scene.Cursor = System.Windows.Forms.Cursors.Default
|
|
|
|
Return bOk
|
|
End Function
|
|
|
|
Function ExecGunStockPez(ByRef scene As Scene, sFilePath As String) As Boolean
|
|
' Scelta file PEZ : se sFilePath non vuoto apro questo file
|
|
If Not String.IsNullOrEmpty(sFilePath) Then
|
|
m_sPezFile = sFilePath
|
|
' altrimenti chiedo all'utente
|
|
Else
|
|
' Direttorio corrente per file MOD
|
|
Dim sDir As String = String.Empty
|
|
GetPrivateProfileString(S_GUNSTOCK, K_PEZDIR, "", sDir)
|
|
' Apertura dialogo di scelta file MOD
|
|
Dim OpenFileDialog As New System.Windows.Forms.OpenFileDialog
|
|
OpenFileDialog.Title = "Open PEZ file"
|
|
OpenFileDialog.Filter = "Part file (*.pez)|*.pez"
|
|
OpenFileDialog.FilterIndex = 1
|
|
OpenFileDialog.InitialDirectory = sDir
|
|
If OpenFileDialog.ShowDialog <> Windows.Forms.DialogResult.OK Then
|
|
Return True
|
|
End If
|
|
m_sPezFile = OpenFileDialog.FileName
|
|
End If
|
|
WritePrivateProfileString(S_GUNSTOCK, K_PEZDIR, System.IO.Path.GetDirectoryName(m_sPezFile))
|
|
IniFile.m_PEZFilePath = m_sPezFile
|
|
|
|
' Carico ambiente lua per Gunstock
|
|
If Not LoadGunStock() Then
|
|
MessageBox.Show(EgtMsg(MSG_GUNSTOCKERRORS + 2), EgtMsg(MSG_GUNSTOCKERRORS + 1), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
EgtOutLog("Error in LoadGunStock")
|
|
Return False
|
|
End If
|
|
|
|
' Lettura dei parametri dal pezzo
|
|
If Not ReadPezParams() Then
|
|
MessageBox.Show(EgtMsg(MSG_GUNSTOCKERRORS + 3), EgtMsg(MSG_GUNSTOCKERRORS + 1), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
EgtOutLog("Error in ReadPezParams")
|
|
Return False
|
|
End If
|
|
|
|
' Eventuale modifica
|
|
If Not UpdatePezParams(False) Then
|
|
Return True
|
|
End If
|
|
|
|
' Scrivo file PEZ
|
|
If Not WritePezParams() Then
|
|
MessageBox.Show(EgtMsg(MSG_GUNSTOCKERRORS + 4), EgtMsg(MSG_GUNSTOCKERRORS + 1), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
EgtOutLog("Error in WritePezParams")
|
|
Return False
|
|
End If
|
|
|
|
' Visualizzo dimensioni grezzo
|
|
If Not ShowRawDim() Then
|
|
MessageBox.Show(EgtMsg(MSG_GUNSTOCKERRORS + 4), EgtMsg(MSG_GUNSTOCKERRORS + 1), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
EgtOutLog("Error in ShawRawDim")
|
|
Return False
|
|
End If
|
|
|
|
' Generazione calcio di fucile
|
|
scene.Cursor = System.Windows.Forms.Cursors.WaitCursor
|
|
Dim bOk As Boolean = CreateGunStock()
|
|
' Aggiorno la visualizzazione
|
|
EgtZoom(ZM.ALL)
|
|
scene.Cursor = System.Windows.Forms.Cursors.Default
|
|
|
|
Return bOk
|
|
End Function
|
|
|
|
Private Function LoadGunStock() As Boolean
|
|
' Cancello ambiente Gunstock globale
|
|
EgtLuaResetGlobVar("GGD")
|
|
' Carico il file
|
|
Dim sExecPath As String = String.Empty
|
|
GetPrivateProfileString(S_GUNSTOCK, K_GUNSTOCKEXEC, "", sExecPath)
|
|
Return EgtLuaExecFile(sExecPath)
|
|
End Function
|
|
|
|
Private Function ReadModParams() As Boolean
|
|
' Lancio la lettura dei parametri del modello
|
|
EgtLuaSetGlobStringVar("GGD.MODFILE", m_sModFile)
|
|
Dim sFunction As String = String.Empty
|
|
GetPrivateProfileString(S_GUNSTOCK, K_READMODFUNCTION, "", sFunction)
|
|
Dim bOk As Boolean = EgtLuaExecLine(sFunction)
|
|
Dim nErr As Integer = 999
|
|
If Not EgtLuaGetGlobIntVar("GGD.ERR", nErr) Or nErr <> 0 Then bOk = False
|
|
EgtOutLog("Gunstock Err=" & nErr.ToString())
|
|
If Not bOk Then Return False
|
|
' Acquisisco i valori letti
|
|
EgtLuaGetGlobStringVar("GGD.MODNAME", m_sDescription)
|
|
Dim nParTot As Integer = 0
|
|
EgtLuaGetGlobIntVar("GGD.PARTOT", nParTot)
|
|
Array.Resize(m_vParams, nParTot)
|
|
For i As Integer = 1 To nParTot
|
|
Dim sParNameI As String = "GGD.PARNAME" & i.ToString()
|
|
EgtLuaGetGlobStringVar(sParNameI, m_vParams(i - 1).sName)
|
|
Dim sParMinI As String = "GGD.PARMIN" & i.ToString()
|
|
EgtLuaGetGlobNumVar(sParMinI, m_vParams(i - 1).dMin)
|
|
Dim sParMaxI As String = "GGD.PARMAX" & i.ToString()
|
|
EgtLuaGetGlobNumVar(sParMaxI, m_vParams(i - 1).dMax)
|
|
Dim sParDefI As String = "GGD.PARDEF" & i.ToString()
|
|
EgtLuaGetGlobNumVar(sParDefI, m_vParams(i - 1).dDef)
|
|
m_vParams(i - 1).dVal = m_vParams(i - 1).dDef
|
|
Dim sParVarI As String = "GGD.PARVAR" & i.ToString()
|
|
EgtLuaGetGlobStringVar(sParVarI, m_vParams(i - 1).sVar)
|
|
Next
|
|
Return True
|
|
End Function
|
|
|
|
Private Function UpdatePezParams(bNewFile As Boolean) As Boolean
|
|
' Scelta parametri pezzo
|
|
Dim GunStockWnd As New GunStockWndV
|
|
Dim GunStockWndViewModel As New GunStockWndVM
|
|
GunStockWnd.DataContext = GunStockWndViewModel
|
|
GunStockWnd.Owner = Application.Current.MainWindow
|
|
' Creo lista dei valori
|
|
GunStockWndViewModel.bNewFile = bNewFile
|
|
GunStockWndViewModel.OrigFileName = m_sPezFile
|
|
GunStockWndViewModel.OrigDescription = m_sDescription
|
|
For i As Integer = 0 To m_vParams.Length() - 1
|
|
GunStockWndViewModel.AddParam(m_vParams(i).sName, m_vParams(i).dVal, m_vParams(i).dMin, m_vParams(i).dMax)
|
|
Next
|
|
If Not GunStockWnd.ShowDialog() Then
|
|
Return False
|
|
End If
|
|
' Lettura valori
|
|
m_sPezFile = GunStockWndViewModel.FileName
|
|
m_sDescription = GunStockWndViewModel.Description
|
|
For i As Integer = 0 To m_vParams.Length() - 1
|
|
StringToDouble(GunStockWndViewModel.ParamList(i).Value, m_vParams(i).dVal)
|
|
Next
|
|
Return True
|
|
End Function
|
|
|
|
Private Function ReadPezParams() As Boolean
|
|
' Lancio la lettura dei parametri del pezzo
|
|
EgtLuaSetGlobStringVar("GGD.PEZFILE", m_sPezFile)
|
|
Dim sFunction As String = String.Empty
|
|
GetPrivateProfileString(S_GUNSTOCK, K_READPEZFUNCTION, "", sFunction)
|
|
Dim bOk As Boolean = EgtLuaExecLine(sFunction)
|
|
Dim nErr As Integer = 999
|
|
If Not EgtLuaGetGlobIntVar("GGD.ERR", nErr) Or nErr <> 0 Then bOk = False
|
|
EgtOutLog("Gunstock Err=" & nErr.ToString())
|
|
If Not bOk Then Return False
|
|
' Acquisisco i valori letti
|
|
EgtLuaGetGlobStringVar("GGD.MODFILE", m_sModFile)
|
|
EgtLuaGetGlobStringVar("GGD.DESCR", m_sDescription)
|
|
Dim nParTot As Integer = 0
|
|
EgtLuaGetGlobIntVar("GGD.PARTOT", nParTot)
|
|
Array.Resize(m_vParams, nParTot)
|
|
For i As Integer = 1 To nParTot
|
|
Dim sParNameI As String = "GGD.PARNAME" & i.ToString()
|
|
EgtLuaGetGlobStringVar(sParNameI, m_vParams(i - 1).sName)
|
|
Dim sParMinI As String = "GGD.PARMIN" & i.ToString()
|
|
EgtLuaGetGlobNumVar(sParMinI, m_vParams(i - 1).dMin)
|
|
Dim sParMaxI As String = "GGD.PARMAX" & i.ToString()
|
|
EgtLuaGetGlobNumVar(sParMaxI, m_vParams(i - 1).dMax)
|
|
Dim sParDefI As String = "GGD.PARDEF" & i.ToString()
|
|
EgtLuaGetGlobNumVar(sParDefI, m_vParams(i - 1).dDef)
|
|
Dim sParValI As String = "GGD.PARVAL" & i.ToString()
|
|
EgtLuaGetGlobNumVar(sParValI, m_vParams(i - 1).dVal)
|
|
Dim sParVarI As String = "GGD.PARVAR" & i.ToString()
|
|
EgtLuaGetGlobStringVar(sParVarI, m_vParams(i - 1).sVar)
|
|
Next
|
|
Return True
|
|
End Function
|
|
|
|
Private Function WritePezParams() As Boolean
|
|
' Assegno i valori letti
|
|
For i As Integer = 1 To m_vParams.Length()
|
|
Dim sParValI As String = "GGD.PARVAL" & i.ToString()
|
|
EgtLuaSetGlobNumVar(sParValI, m_vParams(i - 1).dVal)
|
|
Next
|
|
' Lancio la scrittura dei parametri del pezzo
|
|
EgtLuaSetGlobStringVar("GGD.PEZFILE", m_sPezFile)
|
|
EgtLuaSetGlobStringVar("GGD.DESCR", m_sDescription)
|
|
Dim sFunction As String = String.Empty
|
|
GetPrivateProfileString(S_GUNSTOCK, K_WRITEPEZFUNCTION, "", sFunction)
|
|
Dim bOk As Boolean = EgtLuaExecLine(sFunction)
|
|
Dim nErr As Integer = 999
|
|
If Not EgtLuaGetGlobIntVar("GGD.ERR", nErr) Or nErr <> 0 Then bOk = False
|
|
EgtOutLog("Gunstock Err=" & nErr.ToString())
|
|
Return bOk
|
|
End Function
|
|
|
|
Private Function ShowRawDim() As Boolean
|
|
' Recupero la stringa con la dimensione del grezzo
|
|
Dim sDimGrez As String = String.Empty
|
|
If Not EgtLuaGetGlobStringVar("GGD.DIMGREZ", sDimGrez) Or
|
|
String.IsNullOrWhiteSpace(sDimGrez) Then Return False
|
|
' Visualizzo la dimensione del grezzo
|
|
MessageBox.Show(sDimGrez, EgtMsg(MSG_GUNSTOCK + 13), MessageBoxButton.OK, MessageBoxImage.Information)
|
|
Return True
|
|
End Function
|
|
|
|
Private Function CreateGunStock() As Boolean
|
|
' Lancio la creazione
|
|
EgtLuaSetGlobStringVar("GGD.PEZFILE", m_sPezFile)
|
|
EgtLuaSetGlobStringVar("GGD.MODFILE", m_sModFile)
|
|
Dim sFunction As String = String.Empty
|
|
GetPrivateProfileString(S_GUNSTOCK, K_CREATEFUNCTION, "", sFunction)
|
|
Dim bOk As Boolean = EgtLuaExecLine(sFunction)
|
|
Dim nErr As Integer = 999
|
|
If Not EgtLuaGetGlobIntVar("GGD.ERR", nErr) Or nErr <> 0 Then bOk = False
|
|
EgtOutLog("Gunstock Err=" & nErr.ToString())
|
|
' Cancello variabile globale
|
|
EgtLuaResetGlobVar("GGD")
|
|
Return bOk
|
|
End Function
|
|
|
|
End Module
|