Files
EgtCAM5/Special-Doors/Doors.vb
T
DarioS 3ed56120e2 EgtCAM5 2.4k2 :
- per la chiamata a DMACH si imposta DGD.BASEDIR.
2022-11-07 19:01:16 +01:00

130 lines
5.5 KiB
VB.net

'----------------------------------------------------------------------------
' EgalTech 2016-2016
'----------------------------------------------------------------------------
' File : Doors.vb Data : 22.06.16 Versione : 1.6r10
' Contenuto : Classe Doors (interfaccia per script Porte).
'
'
'
' Modifiche : 22.06.16 DS Creazione modulo.
'
'
'----------------------------------------------------------------------------
Imports Microsoft.VisualBasic
Imports System.IO
Imports EgtUILib
Public Module Doors
Function ExecDoors(ByRef scene As Scene, sFilePath As String, Optional bNcGen As Boolean = False, Optional bBatch As Boolean = False, Optional nProbing As Integer = 0) As Integer
' Scelta file DDF
Dim sFile As String
' Se sFilePath non vuoto apro questo file
If Not String.IsNullOrEmpty(sFilePath) Then
sFile = sFilePath
Else
' Direttorio corrente per file DDF
Dim sDir As String = String.Empty
GetPrivateProfileString(S_DOORS, K_DDFDIR, "", sDir)
' Apertura dialogo di scelta file DDF
Dim OpenFileDialog As New System.Windows.Forms.OpenFileDialog
OpenFileDialog.Title = "Open DDF file"
OpenFileDialog.Filter = "Door Description Format (*.ddf)|*.ddf"
OpenFileDialog.FilterIndex = 1
OpenFileDialog.InitialDirectory = sDir
If OpenFileDialog.ShowDialog <> Windows.Forms.DialogResult.OK Then
Return 0
End If
sFile = OpenFileDialog.FileName
End If
WritePrivateProfileString(S_DOORS, K_DDFDIR, System.IO.Path.GetDirectoryName(sFile))
' Generazione porta
' Cursore attesa
scene.Cursor = System.Windows.Forms.Cursors.WaitCursor
' Creazione porta
Dim nErr As Integer = CreateDoors(sFile, bNcGen, bBatch, nProbing)
' Scrivo il nome del file aperto in una variabile globale per averlo in caso di errore
IniFile.m_DDFFilePath = sFile
EgtResetCurrPartLayer()
Map.refProjectVM.UpdateProjectUI(True)
Map.refManageLayerExpanderVM.SelectIdInObjTreeNoMark(EgtGetCurrLayer())
' Cursore standard
scene.Cursor = System.Windows.Forms.Cursors.Default
Return nErr
End Function
Function CreateDoors(sDdfFile As String, bNcGen As Boolean, bBatch As Boolean, nProbing As Integer) As Integer
' Carico il file
Dim sExecPath As String = String.Empty
Dim sExecName As String = String.Empty
GetPrivateProfileString(S_DOORS, K_DDFEXEC, "", sExecName)
sExecPath = IniFile.m_sDoorsDirPath & "\" & sExecName
Dim nErr As Integer = 999
EgtLuaCreateGlobTable("DGD")
EgtLuaSetGlobStringVar("DGD.BASEDIR", IniFile.m_sDoorsDirPath & "\")
If Not EgtLuaExecFile(sExecPath) Then Return nErr
' Lancio la creazione
EgtLuaSetGlobStringVar("DGD.FILE", sDdfFile)
EgtLuaSetGlobBoolVar("DGD.NCGEN", bNcGen)
EgtLuaSetGlobBoolVar("DGD.BATCH", bBatch)
If nProbing > 0 Then EgtLuaSetGlobIntVar("DGD.PROBE", nProbing)
Dim sFunction As String = String.Empty
GetPrivateProfileString(S_DOORS, K_DDFFUNCTION, "", sFunction)
Dim bOk As Boolean = EgtLuaExecLine(sFunction)
If bOk Then EgtLuaGetGlobIntVar("DGD.ERR", nErr)
EgtOutLog("Doors Err=" & nErr.ToString())
' Cancello variabile globale
EgtLuaResetGlobVar("DGD")
' aggiorno vista
EgtZoom(ZM.ALL)
If Not bNcGen And Not bBatch And nProbing = 0 Then
' Segnalazione eventuali Warnings/Errors
If nErr = 999 Then
MessageBox.Show(EgtMsg(MSG_DOORSERRORS + 17), EgtMsg(MSG_DOORSERRORS + 1).ToUpper)
ElseIf nErr <> 0 Then
Try
Dim sErrFilePath As String = Path.ChangeExtension(sDdfFile, ".txt")
Dim Lines() As String = File.ReadAllLines(sErrFilePath)
Dim sErrMsg As String = String.Empty
For Index = 1 To Lines.Count - 1
If Not String.IsNullOrWhiteSpace(Lines(Index)) Then sErrMsg &= Lines(Index) & vbCrLf
Next
If nErr > 0 Then
MessageBox.Show(sErrMsg, EgtMsg(MSG_DOORSERRORS + 1).ToUpper, MessageBoxButton.OK, MessageBoxImage.Error)
Else
MessageBox.Show(sErrMsg, EgtMsg(MSG_DOORSERRORS + 3).ToUpper, MessageBoxButton.OK, MessageBoxImage.Warning)
End If
Catch ex As Exception
MessageBox.Show(EgtMsg(MSG_DOORSERRORS + 7), EgtMsg(MSG_DOORSERRORS + 1).ToUpper)
End Try
End If
End If
Return nErr
End Function
Function ExecDoorsMachining(ByRef scene As Scene) As Boolean
' Cursore attesa
scene.Cursor = System.Windows.Forms.Cursors.WaitCursor
' Carico ed eseguo il file
Dim sExecPath As String = String.Empty
Dim sExecName As String = String.Empty
GetPrivateProfileString(S_DOORS, K_DDFMACHEXEC, "", sExecName)
sExecPath = IniFile.m_sDoorsDirPath & "\" & sExecName
Dim nErr As Integer = 999
EgtLuaCreateGlobTable("DGD")
EgtLuaSetGlobStringVar("DGD.BASEDIR", IniFile.m_sDoorsDirPath & "\")
Dim bOk As Boolean = EgtLuaExecFile(sExecPath)
If bOk Then EgtLuaGetGlobIntVar("DGD.ERR", nErr)
EgtOutLog("Doors Err=" & nErr.ToString())
' Cancello variabile globale
EgtLuaResetGlobVar("DGD")
' Cursore standard
scene.Cursor = System.Windows.Forms.Cursors.Default
Return bOk
End Function
End Module