Imports EgtWPFLib5
Imports EgtUILib
Imports System.IO
Imports EgtBEAMWALL.Core
Public Class BTLPartManagerVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
Public ReadOnly Property ViewPage_Visibility As Visibility
Get
Return If(Map.refMainMenuVM.SelPage = Pages.VIEW OrElse Map.refMainMenuVM.SelPage = Pages.ONLYPRODPAGE, Visibility.Visible, Visibility.Collapsed)
End Get
End Property
Public ReadOnly Property MachiningPage_Visibility As Visibility
Get
Return If(Map.refMainMenuVM.SelPage = Pages.MACHINING OrElse Map.refMainMenuVM.SelPage = Pages.ONLYPRODPAGE, Visibility.Visible, Visibility.Collapsed)
End Get
End Property
Private m_BTLPartManager_IsEnabled As Boolean = True
Public ReadOnly Property BTLPartManager_IsEnabled As Boolean
Get
Return m_BTLPartManager_IsEnabled
End Get
End Property
Public ReadOnly Property CopyPart_IsEnabled As Boolean
Get
Return m_BTLPartManager_IsEnabled AndAlso Not IsNothing(Map.refShowBeamPanelVM) AndAlso Not Map.refShowBeamPanelVM.bShowAll AndAlso Not IsNothing(Map.refProjectVM.BTLStructureVM) AndAlso Not Map.refProjectVM.BTLStructureVM.SelBTLParts.Count > 1
End Get
End Property
Public ReadOnly Property RotatePart_IsEnabled As Boolean
Get
Return m_BTLPartManager_IsEnabled AndAlso Not IsNothing(Map.refProjectVM) AndAlso Not IsNothing(Map.refProjectVM.BTLStructureVM) AndAlso Map.refProjectVM.BTLStructureVM.SelBTLParts.Count > 1
End Get
End Property
Public ReadOnly Property RemovePart_IsEnabled As Boolean
Get
Return m_BTLPartManager_IsEnabled
End Get
End Property
' Definizione comandi
Private m_cmdCopyPart As ICommand
Private m_cmdRemovePart As ICommand
Private m_cmdSimulate As ICommand
Private m_cmdEdit As ICommand
Private m_cmdResetCalc As ICommand
#Region "Messages"
Public ReadOnly Property NewRawPart_ToolTip As String
Get
Return EgtMsg(61903)
End Get
End Property
Public ReadOnly Property NewRawPartLast_ToolTip As String
Get
Return EgtMsg(61977)
End Get
End Property
Public ReadOnly Property AddToRawPart_ToolTip As String
Get
Return EgtMsg(61904)
End Get
End Property
Public ReadOnly Property CopyPart_ToolTip As String
Get
Return EgtMsg(61905)
End Get
End Property
Public ReadOnly Property RemovePart_ToolTip As String
Get
Return EgtMsg(61907)
End Get
End Property
Public ReadOnly Property AddFeature_ToolTip As String
Get
Return EgtMsg(61910)
End Get
End Property
Public ReadOnly Property RemoveFeature_ToolTip As String
Get
Return EgtMsg(61911)
End Get
End Property
Public ReadOnly Property BackRotation_ToolTip As String
Get
Return EgtMsg(61996)
End Get
End Property
Public ReadOnly Property ForwardRotation_ToolTip As String
Get
Return EgtMsg(61997)
End Get
End Property
Public ReadOnly Property InvertSx_ToolTip As String
Get
Return EgtMsg(61998)
End Get
End Property
Public ReadOnly Property InvertDx_ToolTip As String
Get
Return EgtMsg(61999)
End Get
End Property
Public ReadOnly Property Simulate_ToolTip As String
Get
Return EgtMsg(61902)
End Get
End Property
Public ReadOnly Property Edit_ToolTip As String
Get
Return EgtMsg(61939)
End Get
End Property
Public ReadOnly Property ResetCalc_ToolTip As String
Get
Return EgtMsg(61940)
End Get
End Property
#End Region ' Messages
#End Region ' Fields & Properties
#Region "CONSTRUCTOR"
Sub New()
Map.SetRefBTLPartManagerVM(Me)
End Sub
#End Region ' Constructor
#Region "METHODS"
Friend Sub SetBTLPartManagerIsEnabled(bIsEnabled As Boolean)
m_BTLPartManager_IsEnabled = bIsEnabled
NotifyPropertyChanged(NameOf(BTLPartManager_IsEnabled))
NotifyPropertyChanged(NameOf(CopyPart_IsEnabled))
NotifyPropertyChanged(NameOf(RemovePart_IsEnabled))
End Sub
Friend Sub PartShowAllChanged()
NotifyPropertyChanged(NameOf(CopyPart_IsEnabled))
'NotifyPropertyChanged(NameOf(RotatePart_IsEnabled))
NotifyPropertyChanged(NameOf(RemovePart_IsEnabled))
End Sub
' funzione che gestisce risposta da thread di verifica, aggiorna progress e segnala comando di interruzione
Private Sub ManageCalc(dProgress As Double, sProgress As String, ByRef bCancel As Boolean)
If dProgress = 0 Then
Map.refMyStatusBarVM.SetLoadingProgress_Visibility(True)
Map.refMyStatusBarVM.SetStopProgress_IsActive(True)
Map.refMyStatusBarVM.SetStopProgress_IsEnabled(True)
Map.refMyStatusBarVM.SetOutputMessage(sProgress)
Map.refMyStatusBarVM.SetStopProgress_IsActive(True)
Map.refMyStatusBarVM.SetStopProgress_IsEnabled(True)
ElseIf dProgress = 1 Then
Map.refMyStatusBarVM.SetLoadingProgress_Visibility(False)
Map.refMyStatusBarVM.SetStopProgress_IsActive(False)
Map.refMyStatusBarVM.SetStopProgress_IsEnabled(False)
Map.refMyStatusBarVM.SetOutputMessage(sProgress, 3)
End If
bCancel = Map.refMyStatusBarVM.bStopProgress
Map.refMyStatusBarVM.SetLoadingProgress(dProgress * 100)
Map.refMyStatusBarVM.SetOutputMessage(sProgress)
End Sub
#End Region ' Methods
#Region "COMMANDS"
#Region "CopyPart"
'''
''' Returns a command that do Exec.
'''
Public ReadOnly Property CopyPart_Command As ICommand
Get
If m_cmdCopyPart Is Nothing Then
m_cmdCopyPart = New Command(AddressOf CopyPart)
End If
Return m_cmdCopyPart
End Get
End Property
'''
''' Execute the Exec. This method is invoked by the ExecCommand.
'''
Public Sub CopyPart()
If IsNothing(ProjectManagerVM.CurrProj) Then Return
Dim SelPart As BTLPartVM = Map.refProjectVM.BTLStructureVM.SelBTLPart
If IsNothing(SelPart) Then Return
' creo copia
Dim NewPart As BTLPartM = SelPart.Copy()
If Not IsNothing(NewPart) Then
' selezione ultimo che e' quello appena creato
Map.refProjectVM.BTLStructureVM.SetSelBTLPart(Map.refProjectVM.BTLStructureVM.BTLPartVMList(Map.refProjectVM.BTLStructureVM.BTLPartVMList.Count - 1), False, True)
End If
End Sub
#End Region ' CopyPart
#Region "RemovePart"
'''
''' Returns a command that do Exec.
'''
Public ReadOnly Property RemovePart_Command As ICommand
Get
If m_cmdRemovePart Is Nothing Then
m_cmdRemovePart = New Command(AddressOf RemovePartCmd)
End If
Return m_cmdRemovePart
End Get
End Property
'''
''' Execute the Exec. This method is invoked by the ExecCommand.
'''
Public Sub RemovePartCmd()
If IsNothing(ProjectManagerVM.CurrProj) Then Return
If Map.refProjectVM.BTLStructureVM.SelBTLParts.Count > 0 Then
Dim CurrSelBTLParts As List(Of BTLPartVM) = Map.refProjectVM.BTLStructureVM.SelBTLParts.ToList()
For RemoveIndex = CurrSelBTLParts.Count - 1 To 0 Step -1
RemovePart(CurrSelBTLParts(RemoveIndex), RemoveIndex = 0)
Next
End If
End Sub
Public Sub RemovePart(BTLPartToDelete As BTLPartVM, bSelPrevious As Boolean)
' verifico se ci sono già copie in grezzi
Dim nDuploCount As Integer = 0
If EgtDuploCount(BTLPartToDelete.nPartId, nDuploCount) AndAlso nDuploCount > 0 Then
' avviso che il pezzo non è cancellabile perchè in produzione
MessageBox.Show(String.Format(EgtMsg(61929), nDuploCount), EgtMsg(15003), MessageBoxButton.OK, MessageBoxImage.Warning)
Return
End If
' verifico se rimuovere sezione dalla lista
If Not Map.refProjectVM.BTLStructureVM.BTLPartVMList.Any(Function(x) x IsNot BTLPartToDelete AndAlso x.Section = BTLPartToDelete.Section) Then
Map.refProjectVM.BTLStructureVM.SectionList.Remove(BTLPartToDelete.Section)
Map.refProjectVM.BTLStructureVM.SelSection = SectionXMaterial.Empty
End If
' Eseguo cancellazione
EgtBeamSetPart(BTLPartToDelete.nPartId)
' seleziono elemento precedente
Dim Index As Integer = Map.refProjectVM.BTLStructureVM.BTLPartVMList.IndexOf(BTLPartToDelete)
Dim FilteredIndex As Integer = Map.refProjectVM.BTLStructureVM.BTLPartVMList_View.IndexOf(BTLPartToDelete)
Map.refProjectVM.BTLStructureVM.SelBTLParts.Remove(BTLPartToDelete)
If EgtBeamErasePart() Then
If bSelPrevious Then
If FilteredIndex = 0 Then
If Map.refProjectVM.BTLStructureVM.BTLPartVMList_View.Count > 1 Then
Map.refProjectVM.BTLStructureVM.SetSelBTLPart(Map.refProjectVM.BTLStructureVM.BTLPartVMList_View(1))
Else
Map.refProjectVM.BTLStructureVM.SetSelBTLPart(Nothing)
End If
ElseIf FilteredIndex = Map.refProjectVM.BTLStructureVM.BTLPartVMList_View.Count - 1 Then
If Map.refProjectVM.BTLStructureVM.BTLPartVMList_View.Count > 1 Then
Map.refProjectVM.BTLStructureVM.SetSelBTLPart(Map.refProjectVM.BTLStructureVM.BTLPartVMList_View(Map.refProjectVM.BTLStructureVM.BTLPartVMList_View.Count - 2))
Else
Map.refProjectVM.BTLStructureVM.SetSelBTLPart(Nothing)
End If
Else
Map.refProjectVM.BTLStructureVM.SetSelBTLPart(Map.refProjectVM.BTLStructureVM.BTLPartVMList_View(FilteredIndex - 1))
End If
End If
' rimuovo dalla lista pezzi
Map.refProjectVM.BTLStructureVM.BTLPartVMList.RemoveAt(Index)
End If
End Sub
#End Region ' RemovePart
#Region "SimulateCommand"
'''
''' Returns a command that do Open.
'''
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
'''
''' Execute the Open. This method is invoked by the OpenCommand.
'''
Friend Sub Simulate()
If ((IsNothing(ProjectManagerVM.CurrProj) OrElse IsNothing(Map.refProjectVM.BTLStructureVM)) AndAlso (IsNothing(ProjectManagerVM.CurrProd) OrElse IsNothing(Map.refProjectVM.MachGroupPanelVM))) Then Return
Dim ProjType As BWType
Dim BarList() As EgtBEAMWALL.Core.Bar = Nothing
ProjType = Map.refOnlyProdManagerVM.CurrProd.nType
If Not CreateBarToSimulate(ProjType, BarList) Then Return
' lancio simulazione
EgtBEAMWALL.Core.CalcIntegration.Run(BarList, ProjectManagerVM.CurrProj.sProjDirPath, AddressOf ManageCalc)
End Sub
Private Function CreateBarToSimulate(ProjType As BWType, ByRef BarList As Bar()) As Boolean
If Not IsNothing(Map.refProjectVM.BTLStructureVM.SelBTLPart) Then
Dim TempBarList(0) As EgtBEAMWALL.Core.Bar
Dim Bar As New EgtBEAMWALL.Core.Bar With {.nBarId = Map.refProjectVM.BTLStructureVM.SelBTLPart.nPartId,
.nProgramPage = ProjectType.PROJ,
.nProjType = ProjType,
.bBarOk = True,
.nMachineName = Map.refMachinePanelVM.SelectedMachine.Name,
.nCmdType = CalcIntegration.CmdTypes.SIMULATE,
.nGlobState = Map.refProjectVM.BTLStructureVM.SelBTLPart.nGlobalState}
If Map.refProjectVM.BTLStructureVM.SelBTLPart.nGlobalState = CalcStates.NOTCALCULATED Then
Dim sBTLPartFilePath As String = ProjectManagerVM.CurrProj.sProjDirPath & "\" & Map.refProjectVM.BTLStructureVM.SelBTLPart.nPDN.ToString() & ".ori.bwe"
If File.Exists(sBTLPartFilePath) Then File.Delete(sBTLPartFilePath)
End If
TempBarList(0) = Bar
BarList = TempBarList
Else
Return False
End If
' disabilito interfaccia
Map.refProjectVM.SetCalcRunning(True)
Return True
End Function
#End Region ' SimulateCommand
#Region "Edit"
'''
''' Returns a command that do Open.
'''
Public ReadOnly Property Edit_Command As ICommand
Get
If m_cmdEdit Is Nothing Then
m_cmdEdit = New Command(AddressOf Edit)
End If
Return m_cmdEdit
End Get
End Property
'''
''' Execute the Open. This method is invoked by the OpenCommand.
'''
Friend Sub Edit()
Map.refProjectVM.SetRawPartManagerVisibility(Visibility.Collapsed)
Map.refProjectVM.SetFeatureListVisibility(Visibility.Collapsed)
Map.refProjectVM.SetSelManagerTab(ProjectVM.StrategyManagerTab.FEATUREMANAGER)
' Disabilito LeftPanel
Map.refProjectVM.SetOnlyProdLeftPanel_IsEnabled(False)
Map.refProjectVM.SetOnlyProdLeftPanel_Opacity(0.2)
End Sub
#End Region ' Edit
#Region "ResetCalc"
'''
''' Returns a command that do Exec.
'''
Public ReadOnly Property ResetCalc_Command As ICommand
Get
If m_cmdResetCalc Is Nothing Then
m_cmdResetCalc = New Command(AddressOf ResetCalc)
End If
Return m_cmdResetCalc
End Get
End Property
'''
''' Execute the Exec. This method is invoked by the ExecCommand.
'''
Public Sub ResetCalc()
If (Map.refMainMenuVM.SelPage = Pages.ONLYPRODPAGE AndAlso (IsNothing(ProjectManagerVM.CurrProj) OrElse IsNothing(Map.refProjectVM.BTLStructureVM)) AndAlso (IsNothing(ProjectManagerVM.CurrProd) OrElse IsNothing(Map.refProjectVM.MachGroupPanelVM))) Then Return
Dim SelPart As BTLPartVM = Map.refProjectVM.BTLStructureVM.SelBTLPart
If IsNothing(SelPart) Then Return
If SelPart.nGlobalState <> CalcStates.NOTCALCULATED Then
SelPart.ResetCalcTotalPart()
End If
End Sub
#End Region ' ResetCalc
#End Region ' COMMANDS
End Class