Files
EgtCAM5/Utility/IniFile.vb
T
Dario Sassi 7a25e8d634 EgtCAM5 3.1a2 :
- aggiunta toolbar per ReversePost
- gestione protezione da licenza di Trimming e ReversePost
- aggiunte info su Window, Trimming e ReversePost in AboutBox.
2026-01-14 11:38:24 +01:00

398 lines
17 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Public Module IniFile
Friend EgaltechBlue1 As New SolidColorBrush(Color.FromArgb(255, 77, 132, 196))
Friend EgaltechGreen As New SolidColorBrush(Color.FromArgb(255, 0, 255, 0))
Friend EgaltechRed As New SolidColorBrush(Color.FromArgb(255, 255, 0, 0))
Friend EgaltechYellow As New SolidColorBrush(Color.FromArgb(255, 255, 255, 0))
Friend ReferenceContactColRed As New Color3d(255, 0, 0)
Friend ReferenceContactColGreen As New Color3d(0, 255, 0)
Friend Enum ProjectModeOpt As Integer
DRAW = 1
MACHINING = 2
ONLYDRAW = 3
End Enum
Public Enum SceneSurfQualityOpt As Integer
LOWER = -2
LOW = -1
STANDARD = 0
HIGH = 1
HIGHER = 2
End Enum
Public Enum SceneSelModeOpt As Integer
NULL = 0
PARTCURVES = 1
PARTSURFACES = 2
PARTCURVESANDSURFACES = 3
ALL = 99
End Enum
Friend Enum SceneSelTypeOpt As Integer
NULL = 0
MACHINING = 1
FIXTURE = 2
RAWPART = 3
RAWPARTWITHFIXTURE = 4
MACHPATH = 5
End Enum
Public Enum VMillSelTypeOpt As Integer
LOWER = -2
LOW = -1
STANDARD = 0
HIGH = 1
HIGHER = 2
End Enum
' MainWindow Page
Friend m_nInstance As Integer = 0
Friend m_nUserLevel As Integer = 1
Friend m_nKeyLevel As Integer = 0
Friend m_nKeyOptions As UInteger = 0
Friend Enum KEY_OPT As UInteger
BASE = 1 ' Prodotto EgtCAM5
DOORS = 2
GUNSTOCK = 4
DOORCREATOR = 8 ' Prodotto DOORCreator
VIRTUALMILLING = 16
JAMBS = 32
BEAM = 64
CAD2D = 128
STEELDORS = 256
WALL = 512
PLUGIN = 1024
ADVMACHINING = 2048
WINDOW = 4096
TRIMMING = 8192
REVERSEPOST = 16384
End Enum
Friend m_sDataRoot As String
Friend m_sConfigDir As String
Friend m_sIniFile As String
Friend m_sTempDir As String
Friend m_sMachinesRoot As String
Friend m_sResourcesRoot As String
Friend m_sTablesRoot As String
Friend m_sLogFile As String
' path della cartella BEAM
Friend m_sBeamDirPath As String
' path della cartella WALL
Friend m_sWallDirPath As String
' path della cartella BEAMWALL
Friend m_sBeamWallDirPath As String
' path della cartella DOORS
Friend m_sDoorsDirPath As String
' path della cartella WINDOW
Friend m_sWindowDirPath As String
' path della cartella TRIMMING
Friend m_sTrimmingDirPath As String
' path della cartella REVERSEPOST
Friend m_sReversePostDirPath As String
' path della cartella GUNSTOCK
Friend m_sGunstockDirPath As String
' path della cartella Printing3d
Friend m_sPrinting3dDirPath As String
Friend m_ProjectMode As ProjectModeOpt
Friend m_bMmUnits As Boolean
Friend m_bDrawShowGrid As Boolean
Friend m_bMachiningShowGrid As Boolean = False
Friend m_bShowGridFrame As Boolean
' Project Page
Friend m_ProjectSceneContext As Integer = 0
Friend m_bScriptRunning As Boolean = False
Friend m_bStopScript As Boolean = False
Friend m_DDFFilePath As String = String.Empty
Friend m_MODFilePath As String = String.Empty
Friend m_PEZFilePath As String = String.Empty
' Grid data
Friend dSnapStepMm As Double
Friend dSnapStepInch As Double
Friend nMinLineSStep As Integer
Friend nMajLineSStep As Integer
Friend nExtSStep As Integer
Friend MinLnColor As Color3d
Friend MajLnColor As Color3d
' TopCommandBar
Friend m_MruFiles As New MruList
Friend m_MruScripts As New MruList
Friend m_MruDoors As New MruList
Friend m_MruNewGunStock As New MruList
Friend m_MruModifyGunStock As New MruList
' Current Machine
Friend m_sMachineName As String
Friend m_sCurrMachIniFilePath As String
Friend m_sCurrMachToolsDirPath As String
Friend m_sCurrMachSetUpDirPath As String
Friend m_sCurrMachScriptsDirPath As String
' Variabile che contiene la path della cartella che contiene i ToolMaker
Friend m_sToolMakersDir As String = String.Empty
' Variabile che contiene il contesto della scena presente nel database utensili
Friend m_ToolsDbSceneContext As Integer = 0
' Variabile che dice se sono abilitati i gruppi di lavorazione
Friend m_bMachiningGroup As Boolean = False
' Variabile che indica se il programma e' riuscito ad avviarsi
Friend m_bFailedRun As Boolean = False
' Flag visualizzazione solo tavola in definizione lavorazioni
Friend m_bShowOnlyTable As Boolean = False
' Variabile che contiene il vettore di traslazione dei pezzi nel passaggio da modalità disegna a lavora
Friend m_vtMachPartsPos As New Vector3d(Vector3d.NULL)
' Variabile che contiene stato simulazione per chiusura programma
Friend m_bSimulExecuting As Boolean = False
' Variabile che fa chiudere il programma al termine della simulazione
Friend m_bSimulEndExitApp As Boolean = False
Public Function GetPrivateProfileInt(IpAppName As String, IpKeyName As String, nDefault As Integer) As Integer
Return EgtUILib.GetPrivateProfileInt(IpAppName, IpKeyName, nDefault, m_sIniFile)
End Function
Public Function GetPrivateProfileDouble(IpAppName As String, IpKeyName As String, dDefault As Double) As Double
Return EgtUILib.GetPrivateProfileDouble(IpAppName, IpKeyName, dDefault, m_sIniFile)
End Function
Public Function GetPrivateProfileString(IpAppName As String, IpKeyName As String, IpDefault As String, ByRef IpString As String) As Integer
Return EgtUILib.GetPrivateProfileString(IpAppName, IpKeyName, IpDefault, IpString, m_sIniFile)
End Function
Public Function GetPrivateProfileStringUtf8(IpAppName As String, IpKeyName As String, IpDefault As String, ByRef IpString As String) As Boolean
Return EgtGetStringUtf8FromIni(IpAppName, IpKeyName, IpDefault, IpString, m_sIniFile)
End Function
Public Function GetPrivateProfileColor(IpAppName As String, IpKeyName As String, ByRef Col As EgtUILib.EgtInterface.Color3d) As Boolean
Return EgtUILib.GetPrivateProfileColor(IpAppName, IpKeyName, Col, m_sIniFile)
End Function
Public Function GetPrivateProfileWinPos(IpAppName As String, IpKeyName As String, ByRef nFlag As Integer, ByRef nLeft As Integer, ByRef nTop As Integer, ByRef nWidth As Integer, ByRef nHeight As Integer) As Boolean
Return EgtUILib.GetPrivateProfileWinPos(IpAppName, IpKeyName, nFlag, nLeft, nTop, nWidth, nHeight, m_sIniFile)
End Function
Public Function GetPrivateProfileZoomWin(IpAppName As String, IpKeyName As String, ByRef bOutline As Boolean, ByRef Col As EgtUILib.EgtInterface.Color3d) As Boolean
Return EgtUILib.GetPrivateProfileZoomWin(IpAppName, IpKeyName, bOutline, Col, m_sIniFile)
End Function
Public Function GetPrivateProfileFloatingWinPos(lpAppName As String, lpKeyName As String, ByRef nState As String, ByRef nIndex As Integer, ByRef nLeft As Integer, ByRef nTop As Integer) As Boolean
Dim sVal As String = String.Empty
GetPrivateProfileString(lpAppName, lpKeyName, "", sVal)
Dim sItems() As String = sVal.Split(","c)
If sItems.Count() >= 4 Then
nState = sItems(0)
nIndex = CInt(sItems(1))
nLeft = CInt(sItems(2))
nTop = CInt(sItems(3))
Return True
End If
Return False
End Function
Public Function GetPrivateProfileLanguage(
ByVal lpAppName As String,
ByVal lpKeyName As String) As Language
Dim sVal As String = String.Empty
GetPrivateProfileString(lpAppName, lpKeyName, "", sVal)
Dim sItems() As String = sVal.Split(","c)
If sItems.Count() = 2 Then
Return New Language(sItems(0), sItems(1))
End If
Return Nothing
End Function
Public Function GetPrivateProfileFixture(
ByVal lpAppName As String,
ByVal lpKeyName As String, ByRef sName As String, ByRef nTot As Integer) As Boolean
Dim sVal As String = String.Empty
EgtUILib.GetPrivateProfileString(lpAppName, lpKeyName, "", sVal, m_sCurrMachIniFilePath)
Dim sItems() As String = sVal.Split(","c)
If sItems.Count() = 2 Then
sName = sItems(0)
nTot = CInt(sItems(1))
Return True
End If
Return False
End Function
Public Function GetPrivateProfileSetUpPosition(
ByVal lpAppName As String,
ByVal lpKeyName As String, ByRef sTcPos As String, ByRef sHead As String, ByRef nGroup As Integer) As Boolean
Dim sVal As String = String.Empty
EgtUILib.GetPrivateProfileString(lpAppName, lpKeyName, "", sVal, m_sCurrMachIniFilePath)
Dim sItems() As String = sVal.Split(";"c)
If sItems.Count() >= 2 Then
sTcPos = sItems(0)
sHead = sItems(1)
If sItems.Count() >= 3 Then
nGroup = If(Integer.TryParse(sItems(2).Trim("G"c), nGroup), nGroup, 0)
Else
nGroup = 1
End If
Return True
End If
Return False
End Function
Public Function GetPrivateProfileButton(sSection As String, sKey As String, sBaseDir As String, ByRef ReadButtonItem As ButtonItem) As Boolean
ReadButtonItem = Nothing
Dim sVal As String = String.Empty
GetPrivateProfileString(sSection, sKey, "", sVal)
If String.IsNullOrWhiteSpace(sVal) Then Return False
Dim sItems() As String = sVal.Split(","c)
If sItems.Count() >= 1 Then
Dim sLuaPath As String = sItems(0)
Dim sImagePath As String = If(sItems.Count() >= 2, sItems(1), "")
Dim sToolTip As String = If(sItems.Count() >= 3, sItems(2), "")
Dim sDrawMachOrBoth As String = If(sItems.Count() >= 4 AndAlso Not String.IsNullOrWhiteSpace(sItems(3)), sItems(3), "1")
If Not String.IsNullOrWhiteSpace(sBaseDir) And Not String.IsNullOrWhiteSpace(sLuaPath) Then
If sLuaPath.Contains(".lua") Then sLuaPath = sBaseDir & "\" & sLuaPath
If Not String.IsNullOrWhiteSpace(sImagePath) Then sImagePath = sBaseDir & "\" & sImagePath
End If
ReadButtonItem = New ButtonItem(sSection, sLuaPath, sImagePath, sToolTip, sDrawMachOrBoth)
Return True
End If
Return False
End Function
Public Function WritePrivateProfileString(IpAppName As String, IpKeyName As String, ByRef IpString As String) As Boolean
Return EgtUILib.WritePrivateProfileString(IpAppName, IpKeyName, IpString, m_sIniFile)
End Function
Public Function WritePrivateProfileStringUtf8(IpAppName As String, IpKeyName As String, ByRef IpString As String) As Boolean
Return EgtWriteStringUtf8toIni(IpAppName, IpKeyName, IpString, m_sIniFile)
End Function
Public Function WritePrivateProfileWinPos(IpAppName As String, IpKeyName As String, ByRef nFlag As Integer, ByRef nLeft As Integer, ByRef nTop As Integer, ByRef nWidth As Integer, ByRef nHeight As Integer) As Boolean
Return EgtUILib.WritePrivateProfileWinPos(IpAppName, IpKeyName, nFlag, nLeft, nTop, nWidth, nHeight, m_sIniFile)
End Function
Public Function WritePrivateProfileColor(IpAppName As String, IpKeyName As String, ByRef Color As Color3d) As Boolean
Dim sColor As String = Color.R & "," & Color.G & "," & Color.B
Return EgtUILib.WritePrivateProfileString(IpAppName, IpKeyName, sColor, m_sIniFile)
End Function
Friend Function GetProgramVersion() As String
Return My.Application.Info.Version.Major.ToString() &
"." & My.Application.Info.Version.Minor.ToString() &
(ChrW(97 - 1 + My.Application.Info.Version.Build)).ToString() &
My.Application.Info.Version.Revision.ToString()
End Function
Friend Function IsActiveBeam() As Boolean
Dim bIsActive As Boolean = (IniFile.m_nKeyOptions And KEY_OPT.BEAM) <> 0 And (GetPrivateProfileInt(S_BEAM, K_BEAMENABLE, 0) <> 0)
If bIsActive Then
Dim sTemp As String = ""
GetPrivateProfileString(S_BEAM, K_BEAMBASEDIR, "", sTemp)
m_sBeamDirPath = sTemp.TrimEnd( "\"c)
End If
Return bIsActive
End Function
Friend Function IsActiveWall() As Boolean
Dim bIsActive As Boolean = (IniFile.m_nKeyOptions And KEY_OPT.WALL) <> 0 And (GetPrivateProfileInt(S_WALL, K_WALLENABLE, 0) <> 0)
If bIsActive Then
Dim sTemp As String = ""
GetPrivateProfileString(S_WALL, K_WALLBASEDIR, "", sTemp)
m_sWallDirPath = sTemp.TrimEnd( "\"c)
End If
Return bIsActive
End Function
Friend Function IsActiveDoors() As Boolean
Dim bIsActive As Boolean = (IniFile.m_nKeyOptions And KEY_OPT.DOORS) <> 0 And (GetPrivateProfileInt(S_DOORS, K_DDFENABLE, 0) <> 0)
If bIsActive Then
Dim sTemp As String = ""
GetPrivateProfileString(S_DOORS, K_BASEDIR, "", sTemp)
m_sDoorsDirPath = sTemp.TrimEnd( "\"c)
End If
Return bIsActive
End Function
Friend Function IsActiveWindow() As Boolean
Dim bIsActive As Boolean = (IniFile.m_nKeyOptions And KEY_OPT.WINDOW) <> 0 And (GetPrivateProfileInt(S_WINDOW, K_WINDOWENABLE, 0) <> 0)
If bIsActive Then
Dim sTemp As String = ""
GetPrivateProfileString(S_WINDOW, K_WINDOWBASEDIR, "", sTemp)
m_sWindowDirPath = sTemp.TrimEnd( "\"c)
End If
Return bIsActive
End Function
Friend Function IsActiveTrimming() As Boolean
Dim bIsActive As Boolean = (IniFile.m_nKeyOptions And KEY_OPT.TRIMMING) <> 0 And (GetPrivateProfileInt(S_TRIMMING, K_TRIMMINGENABLE, 0) <> 0)
If bIsActive Then
Dim sTemp As String = ""
GetPrivateProfileString(S_TRIMMING, K_TRIMMINGBASEDIR, "", sTemp)
m_sTrimmingDirPath = sTemp.TrimEnd( "\"c)
End If
Return bIsActive
End Function
Friend Function IsActiveReversePost() As Boolean
Dim bIsActive As Boolean = (IniFile.m_nKeyOptions And KEY_OPT.REVERSEPOST) <> 0 And (GetPrivateProfileInt(S_REVERSEPOST, K_REVERSEPOSTENABLE, 0) <> 0)
If bIsActive Then
Dim sTemp As String = ""
GetPrivateProfileString(S_REVERSEPOST, K_REVERSEPOSTBASEDIR, "", sTemp)
m_sReversePostDirPath = sTemp.TrimEnd( "\"c)
End If
Return bIsActive
End Function
Friend Function IsActiveGunStock() As Boolean
Dim bIsActive As Boolean = (IniFile.m_nKeyOptions And KEY_OPT.GUNSTOCK) <> 0 And (GetPrivateProfileInt(S_GUNSTOCK, K_GUNSTOCKENABLE, 0) <> 0)
If bIsActive Then
Dim sTemp As String = ""
GetPrivateProfileString(S_GUNSTOCK, K_GUNSTOCKEXEC, "", sTemp)
m_sGunstockDirPath = Path.GetDirectoryName( sTemp)
End If
Return bIsActive
End Function
Friend Function IsActivePlugin() As Boolean
Dim bIsActive As Boolean = (IniFile.m_nKeyOptions And KEY_OPT.PLUGIN) <> 0
Dim nTemp As Integer = GetPrivateProfileInt(S_GENERAL, K_PLUGIN, 0)
Return bIsActive And nTemp = 1
End Function
Friend Function IsKeyEnabledVirtualMilling() As Boolean
Return (IniFile.m_nKeyOptions And KEY_OPT.VIRTUALMILLING) <> 0
End Function
Friend Function IsKeyEnabledAdvancedMachining() As Boolean
Return (IniFile.m_nKeyOptions And KEY_OPT.ADVMACHINING) <> 0
End Function
Friend Function IsActiveSpecialPanel( Optional bTestButton As Boolean = true) As Boolean
If GetPrivateProfileInt(S_SPECIAL, K_SPECIALENABLE, 0) = 0 Then Return False
If Not bTestButton Then Return True
Return (Not IsNothing(Map.refSpecialPanelVM) AndAlso Map.refSpecialPanelVM.ButtonCount > 0)
End Function
Friend Function GetSpecialLuaVersion( sSpecialLuaDir As String, ByRef sVersion As String) As Boolean
Dim sExecPath As String = (sSpecialLuaDir & "\Version.lua")
If Not EgtLuaExecFile(sExecPath, False) Then Return False
If Not EgtLuaGetGlobStringVar("VERSION", sVersion) Then Return False
EgtLuaResetGlobVar("VERSION")
Return True
End Function
Friend Function GetSpecialLuaData( sSpecialLuaDir As String,
ByRef sName As String, ByRef sVersion As String, ByRef sMinExe As String) As Boolean
Dim sExecPath As String = (sSpecialLuaDir & "\Version.lua")
If Not EgtLuaExecFile(sExecPath, False) Then Return False
If Not EgtLuaGetGlobStringVar("NAME", sName) Then Return False
If Not EgtLuaGetGlobStringVar("VERSION", sVersion) Then Return False
If Not EgtLuaGetGlobStringVar("MIN_EXE", sMinExe) Then Return False
EgtLuaResetGlobVar("NAME")
EgtLuaResetGlobVar("VERSION")
EgtLuaResetGlobVar("MIN_EXE")
Return True
End Function
End Module