3dabab5b72
- eliminati file inutili - prime modifiche per gestione necessità ricalcolo slices.
383 lines
13 KiB
VB.net
383 lines
13 KiB
VB.net
Imports EgtWPFLib5
|
|
Imports EgtUILib
|
|
|
|
Public Class SliceManagerVM
|
|
Inherits VMBase
|
|
|
|
' Funzioni di callback per output in interfaccia da LUA
|
|
Private m_ProcEventsCallback As New ProcessEventsCallback(AddressOf ProcessEvents)
|
|
|
|
Private m_SliceManagerState As CalcStates
|
|
|
|
Private m_dMass As Double = 0
|
|
Public ReadOnly Property ghMass As String
|
|
Get
|
|
Return DoubleToString(m_dMass, 1) & " kg"
|
|
End Get
|
|
End Property
|
|
|
|
Private m_dTime As Double = 0
|
|
Public ReadOnly Property ghTime As String
|
|
Get
|
|
Dim dtTime As TimeSpan = TimeSpan.FromSeconds(m_dTime)
|
|
Return Math.Floor(dtTime.TotalHours) & "hours " & Math.Floor(dtTime.Minutes) & "min " & Math.Ceiling(dtTime.Seconds) & "sec"
|
|
End Get
|
|
End Property
|
|
|
|
Private m_Loading_Value As Integer = 0
|
|
Public Property Loading_Value As Integer
|
|
Get
|
|
Return m_Loading_Value
|
|
End Get
|
|
Set(value As Integer)
|
|
m_Loading_Value = value
|
|
End Set
|
|
End Property
|
|
Private Sub SetLoadingValue(value As Integer)
|
|
m_Loading_Value = value
|
|
NotifyPropertyChanged(NameOf(Loading_Value))
|
|
End Sub
|
|
|
|
Private m_Loading_Visibility As Visibility = Visibility.Collapsed
|
|
Public Property Loading_Visibility As Visibility
|
|
Get
|
|
Return m_Loading_Visibility
|
|
End Get
|
|
Set(value As Visibility)
|
|
m_Loading_Visibility = value
|
|
End Set
|
|
End Property
|
|
Private Sub SetLoadingVisibility(bIsVisible As Boolean)
|
|
m_Loading_Visibility = If(bIsVisible, Visibility.Visible, Visibility.Collapsed)
|
|
NotifyPropertyChanged(NameOf(Loading_Visibility))
|
|
End Sub
|
|
|
|
Private m_ModifyMode_Visibility As Visibility = Visibility.Collapsed
|
|
Public ReadOnly Property ModifyMode_Visibility As Visibility
|
|
Get
|
|
Return m_ModifyMode_Visibility
|
|
End Get
|
|
End Property
|
|
|
|
Private m_SliceMode_Visibility As Visibility = Visibility.Collapsed
|
|
Public ReadOnly Property SliceMode_Visibility As Visibility
|
|
Get
|
|
Return m_SliceMode_Visibility
|
|
End Get
|
|
End Property
|
|
|
|
' Definizione comandi
|
|
Private m_cmdSlice As ICommand
|
|
Private m_cmdSimulate As ICommand
|
|
Private m_cmdGenerate As ICommand
|
|
Private m_cmdExit As ICommand
|
|
|
|
#Region "CONSTRUCTORS"
|
|
|
|
Sub New()
|
|
' Creo riferimento a questa classe in EgtCAM5Map
|
|
Map.SetRefSliceManagerVM(Me)
|
|
' Installo funzione gestione eventi per lua
|
|
EgtSetProcessEvents(m_ProcEventsCallback)
|
|
UpdateState(False)
|
|
End Sub
|
|
|
|
#End Region ' CONSTRUCTORS
|
|
|
|
#Region "METHODS"
|
|
|
|
Friend Sub UpdateState(bState As Boolean)
|
|
If bState Then
|
|
m_ModifyMode_Visibility = Visibility.Collapsed
|
|
m_SliceMode_Visibility = Visibility.Visible
|
|
Else
|
|
m_ModifyMode_Visibility = Visibility.Visible
|
|
m_SliceMode_Visibility = Visibility.Collapsed
|
|
End If
|
|
NotifyPropertyChanged(NameOf(ModifyMode_Visibility))
|
|
NotifyPropertyChanged(NameOf(SliceMode_Visibility))
|
|
End Sub
|
|
|
|
Private Function ProcessEvents(ByVal nProg As Integer, ByVal nPause As Integer) As Integer
|
|
' Se previsto, imposto progress
|
|
If nProg > 0 Then SetLoadingValue(Math.Min(nProg, 100))
|
|
'' Notifico a simulazione aggiornamento dati
|
|
'If Not IsNothing(Map.refSimulationExpanderVM) Then
|
|
' ' Uso i valori negativi del primo parametro come flag per la Simulazione
|
|
' Dim nFlag As Integer = If(nProg < 0, -nProg, 0)
|
|
' Map.refSimulationExpanderVM.SimulationExpander_Update_CncData(nFlag)
|
|
'End If
|
|
' Costringo ad aggiornare
|
|
UpdateUI()
|
|
' Eventuale attesa
|
|
Threading.Thread.Sleep(nPause)
|
|
'' Ritorno eventuale stop
|
|
'If m_bStopScript Then
|
|
' m_bStopScript = False
|
|
' Return 1
|
|
'Else
|
|
' Return 0
|
|
'End If
|
|
Return 0
|
|
End Function
|
|
|
|
Friend Function CalcSlice(bSlice As Boolean, bCalcTFS As Boolean, bGenerate As Boolean) As Boolean
|
|
Dim bOk As Boolean = True
|
|
' verifico se eseguire slice
|
|
Dim bToRecalc As Boolean = False
|
|
If bSlice Then
|
|
Dim nPartId As Integer = EgtGetFirstPart()
|
|
While nPartId <> GDB_ID.NULL
|
|
Dim bTemp As Boolean = False
|
|
If EgtGetInfo(nPartId, MAC_TO_RECALC, bTemp) AndAlso bTemp Then
|
|
bToRecalc = True
|
|
Exit While
|
|
End If
|
|
nPartId = EgtGetNextPart(nPartId)
|
|
End While
|
|
End If
|
|
If Not bToRecalc Then bSlice = False
|
|
' aggiorno dati macchina
|
|
If bCalcTFS Then Map.refTFSEditorVM.UpdateSpeedMinMax()
|
|
' eseguo calcolo slicing, toolpath e solidi
|
|
SetLoadingVisibility(True)
|
|
bOk = ExecSlice(bSlice, bCalcTFS)
|
|
SetLoadingVisibility(False)
|
|
' se calcolo andato a buon fine, sistemo visualizzazione e rimuovo flag richiesta ricalcolo
|
|
If bOk Then
|
|
Dim nPartId As Integer = EgtGetFirstPart()
|
|
While nPartId <> GDB_ID.NULL
|
|
' aggiorno stato visualizzazione
|
|
Dim nSolidLayId As Integer = EgtGetFirstNameInGroup( nPartId, PRINT_SOLID)
|
|
EgtSetStatus( nSolidLayId, GDB_ST.OFF)
|
|
Dim nMachStartLayId As Integer = EgtGetFirstNameInGroup( nPartId, LAY_MACH_START)
|
|
EgtSetStatus( nMachStartLayId, GDB_ST.OFF)
|
|
Dim nRibsLayId As Integer = EgtGetFirstNameInGroup( nPartId, LAY_RIBS)
|
|
EgtSetStatus( nRibsLayId, GDB_ST.OFF)
|
|
Dim nShellNbrLay As Integer = EgtGetFirstNameInGroup( nPartId, LAY_SHELL_NBR)
|
|
EgtSetStatus( nShellNbrLay, GDB_ST.OFF)
|
|
Dim nAuxSolidsLay As Integer = EgtGetFirstNameInGroup( nPartId, LAY_AUX_SOLIDS)
|
|
EgtSetStatus( nAuxSolidsLay, GDB_ST.OFF)
|
|
' eseguo rimozione flag
|
|
EgtRemoveInfo( nPartId, MAC_TO_RECALC)
|
|
nPartId = EgtGetNextPart(nPartId)
|
|
End While
|
|
End If
|
|
' aggiorno massa
|
|
If bOk Then
|
|
Dim nLayTFSCalcId As Integer = EgtGetFirstNameInGroup(GDB_ID.ROOT, LAY_TFSCALC)
|
|
EgtGetInfo(nLayTFSCalcId, KEY_MASS, m_dMass)
|
|
NotifyPropertyChanged(NameOf(ghMass))
|
|
End If
|
|
Map.refTFSEditorVM.Refresh()
|
|
Map.refTopPanelVM.SelPart.RefreshPrintLayers()
|
|
' in caso di errore, segnalazione
|
|
If Not bOk Then
|
|
MessageBox.Show("Error in slicing! See log file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error)
|
|
End If
|
|
If bOk And bGenerate Then
|
|
' verifico esistenza e correttezza machgroup
|
|
InitMachGroup(True)
|
|
' eseguo generazione CN
|
|
bOk = ExecGenerate()
|
|
EgtGetInfo(EgtGetFirstMachGroup(), "Ttot", m_dTime)
|
|
NotifyPropertyChanged(NameOf(ghTime))
|
|
' eseguo script di uscita da machgroup corrente
|
|
ExecExitMachScript()
|
|
If Not bOk Then
|
|
MessageBox.Show("Error in NC code generation! See log file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error)
|
|
End If
|
|
End If
|
|
' Aggiorno intestazione programma
|
|
Map.refSceneHostVM.EmitTitle()
|
|
Return bOk
|
|
End Function
|
|
|
|
Friend Sub InitMachGroup(bGenerate As Boolean)
|
|
' esecuzione script prima di inizio Mach
|
|
ExecInitMachScript()
|
|
If bGenerate Then
|
|
Dim nMachGroupId As Integer = EgtGetFirstMachGroup()
|
|
While nMachGroupId <> GDB_ID.NULL
|
|
EgtRemoveMachGroup(nMachGroupId)
|
|
nMachGroupId = EgtGetFirstMachGroup()
|
|
End While
|
|
' Definisco e posiziono il grezzo sulla tavola
|
|
EgtAddMachGroup("3dPrint")
|
|
EgtSetTable("Tab")
|
|
For Each CurrPart In Map.refTopPanelVM.PartList
|
|
Dim b3Part As New BBox3d
|
|
Dim b3PrintSolid As New BBox3d
|
|
EgtGetBBoxGlob(CurrPart.nPartId, GDB_BB.STANDARD, b3Part)
|
|
EgtGetBBoxGlob(CurrPart.nPrintSolidId, GDB_BB.STANDARD, b3PrintSolid)
|
|
Dim nRawId As Integer = EgtAddRawPart(b3PrintSolid.Min, b3PrintSolid.DimX, b3PrintSolid.DimY, b3PrintSolid.DimZ, New Color3d(128, 128, 128, 30))
|
|
EgtAddPartToRawPart(CurrPart.nPartId, Point3d.ORIG() + (b3Part.Min - b3PrintSolid.Min), nRawId)
|
|
EgtMoveToCornerRawPart(nRawId, b3PrintSolid.Min, MCH_CR.BL)
|
|
Next
|
|
EgtResetCurrMachGroup()
|
|
Else
|
|
EgtSetCurrMachGroup(EgtGetFirstMachGroup())
|
|
End If
|
|
End Sub
|
|
|
|
Private Function ExecInitMachScript() As Boolean
|
|
' Recupero il nome dello script e verifico esista
|
|
Dim sInitMachScriptPath As String = ""
|
|
If EgtUILib.GetPrivateProfileString(S_MACHINING, K_MACH_INITSCRIPT, "", sInitMachScriptPath, CurrentMachine.sMachIniFile) = 0 Then Return True
|
|
sInitMachScriptPath = (CurrentMachine.sMachScriptDir & "\" & sInitMachScriptPath).TrimEnd({"\"c})
|
|
If Not My.Computer.FileSystem.FileExists(sInitMachScriptPath) Then Return True
|
|
' Eseguo lo script
|
|
EgtLuaCreateGlobTable("MACH")
|
|
If Not EgtLuaExecFile(sInitMachScriptPath) Then
|
|
EgtOutLog("Error executing Machining init script " & sInitMachScriptPath)
|
|
MessageBox.Show(EgtMsg(5463) & " " & sInitMachScriptPath, EgtMsg(5461), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
Return False
|
|
End If
|
|
Dim nErr As Integer = 999
|
|
EgtLuaGetGlobIntVar("MACH.ERR", nErr)
|
|
EgtLuaResetGlobVar("MACH")
|
|
Return nErr = 0
|
|
End Function
|
|
|
|
Friend Function ExecExitMachScript() As Boolean
|
|
' Recupero il nome dello script e verifico esista
|
|
Dim sExitMachScriptPath As String = ""
|
|
If EgtUILib.GetPrivateProfileString(S_MACHINING, K_MACH_EXITSCRIPT, "", sExitMachScriptPath, CurrentMachine.sMachIniFile) = 0 Then Return True
|
|
sExitMachScriptPath = CurrentMachine.sMachScriptDir & "\" & sExitMachScriptPath
|
|
If Not My.Computer.FileSystem.FileExists(sExitMachScriptPath) Then Return True
|
|
' Eseguo lo script
|
|
EgtLuaCreateGlobTable("MACH")
|
|
If Not EgtLuaExecFile(sExitMachScriptPath) Then
|
|
EgtOutLog("Error executing Machining exit script " & sExitMachScriptPath)
|
|
MessageBox.Show(EgtMsg(5464) & " " & sExitMachScriptPath, EgtMsg(5461), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
Return False
|
|
End If
|
|
Dim nErr As Integer = 999
|
|
EgtLuaGetGlobIntVar("MACH.ERR", nErr)
|
|
EgtLuaResetGlobVar("MACH")
|
|
Return nErr = 0
|
|
End Function
|
|
|
|
#End Region ' METHODS
|
|
|
|
#Region "COMMANDS"
|
|
|
|
#Region "Slice"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do CPlaneTop.
|
|
''' </summary>
|
|
Public ReadOnly Property Slice_Command As ICommand
|
|
Get
|
|
If m_cmdSlice Is Nothing Then
|
|
m_cmdSlice = New Command(AddressOf Slice)
|
|
End If
|
|
Return m_cmdSlice
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Execute the CPlaneTop. This method is invoked by the CPlaneTopCommand.
|
|
''' </summary>
|
|
Public Sub Slice()
|
|
If IsNothing(Map.refTopPanelVM.SelPart) Then
|
|
MessageBox.Show("No parts to slice!", "Error", MessageBoxButton.OK, MessageBoxImage.Error)
|
|
Return
|
|
End If
|
|
If IsNothing(Map.refTopPanelVM.SelMachining) Then
|
|
MessageBox.Show("No print parameters set!", "Error", MessageBoxButton.OK, MessageBoxImage.Error)
|
|
Return
|
|
End If
|
|
If Map.refTopPanelVM.SelPage <> Pages.SLICE Then
|
|
|
|
End If
|
|
' eseguo calcoli
|
|
CalcSlice(True, True, True)
|
|
Map.refTopPanelVM.SelPage = Pages.SLICE
|
|
Map.refSliderManagerVM.SetLayerIndexToMax()
|
|
End Sub
|
|
|
|
#End Region ' Slice
|
|
|
|
#Region "Generate"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do CPlaneTop.
|
|
''' </summary>
|
|
Public ReadOnly Property Generate_Command As ICommand
|
|
Get
|
|
If m_cmdGenerate Is Nothing Then
|
|
m_cmdGenerate = New Command(AddressOf Generate)
|
|
End If
|
|
Return m_cmdGenerate
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Execute the CPlaneTop. This method is invoked by the CPlaneTopCommand.
|
|
''' </summary>
|
|
Public Sub Generate()
|
|
' eseguo calcoli
|
|
CalcSlice(False, True, True)
|
|
End Sub
|
|
|
|
#End Region ' Generate
|
|
|
|
#Region "Simulate"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do CPlaneTop.
|
|
''' </summary>
|
|
Public ReadOnly Property Simulate_Command As ICommand
|
|
Get
|
|
If m_cmdSimulate Is Nothing Then
|
|
m_cmdSimulate = New Command(AddressOf Simulate)
|
|
End If
|
|
Return m_cmdSimulate
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Execute the CPlaneTop. This method is invoked by the CPlaneTopCommand.
|
|
''' </summary>
|
|
Public Sub Simulate()
|
|
' verifico esistenza e correttezza machgroup
|
|
InitMachGroup(False)
|
|
' apro simulazione
|
|
Map.refRightPanelVM.SetSelPanel(RightPanelVM.Panels.SIMULATION)
|
|
End Sub
|
|
|
|
#End Region ' Simulate
|
|
|
|
#Region "Exit"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do CPlaneTop.
|
|
''' </summary>
|
|
Public ReadOnly Property Exit_Command As ICommand
|
|
Get
|
|
If m_cmdExit Is Nothing Then
|
|
m_cmdExit = New Command(AddressOf ExitCmd)
|
|
End If
|
|
Return m_cmdExit
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Execute the CPlaneTop. This method is invoked by the CPlaneTopCommand.
|
|
''' </summary>
|
|
Public Sub ExitCmd()
|
|
' se in simulazione
|
|
If Map.refRightPanelVM.SelPanel = RightPanelVM.Panels.SIMULATION Then
|
|
' la chiudo
|
|
Map.refSimulationPanelVM.Ok()
|
|
End If
|
|
Map.refTopPanelVM.SelPage = Pages.MODIFY
|
|
End Sub
|
|
|
|
#End Region ' Exit
|
|
|
|
#End Region ' COMMANDS
|
|
|
|
End Class
|