Imports System.IO Imports EgtBEAMWALL.Core Imports EgtUILib Imports EgtWPFLib5 Public Class BTLPartManagerVM Inherits VMBase #Region "FIELDS & PROPERTIES" 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(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" 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 Public Sub CopyPart() If IsNothing(ProjectManagerVM.CurrProd) 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 If Map.refProdManagerVM.ListProjAsseBase.Count > 0 Then Map.refProjectVM.UpdatePart(NewPart.nPartId) ' 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" 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 Public Sub RemovePartCmd() If IsNothing(ProjectManagerVM.CurrProd) Then Return If EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(62573), EgtMsg(30009), MessageBoxButton.OKCancel, MessageBoxImage.Exclamation) = MessageBoxResult.OK Then 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 Else Return 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 EgtBEAMWALL.Core.EgtMessageBoxV.Show(Application.Current.MainWindow, 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) If Map.refProdManagerVM.ListProjAsseBase.Count > 0 Then RemoveScenePart(BTLPartToDelete) ' 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 Private Sub RemoveScenePart(BTLPartToDelete As BTLPartVM) ' Rimuovo pezzo dalla scena Dim IdAsseBase As Integer = 0 Dim DeletePartId As Integer = 0 If Not Map.refProdManagerVM.ListProjAsseBase.TryGetValue(BTLPartToDelete.nPROJ, IdAsseBase) Then Return End If ' Setto il nuovo contesto EgtSetCurrentContext(Map.refSceneShowBuldingVM.SceneShowBulding.GetCtx()) If EgtBeamGetBuildingIsOn(IdAsseBase) Then EgtBeamShowBuilding(IdAsseBase, False) If Map.refSceneShowBuldingVM.MapInfo.TryGetValue(BTLPartToDelete.nPartId, DeletePartId) Then EgtErase(DeletePartId) Map.refSceneShowBuldingVM.MapInfo.Remove(BTLPartToDelete.nPartId) End If EgtBeamShowBuilding(IdAsseBase, True) EgtZoom(ZM.ALL) ' Ritorno al contesto corrente EgtSetCurrentContext(Map.refSceneHostVM.MainScene.GetCtx()) End Sub #End Region ' RemovePart #Region "SimulateCommand" 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 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.refProdManagerVM.CurrProd.nType If Not CreateBarToSimulate(ProjType, BarList) Then Return ' lancio simulazione EgtBEAMWALL.Core.CalcIntegration.Run(BarList, ProjectManagerVM.CurrProd.sProdDirPath & "\Projs\" & Map.refProjectVM.BTLStructureVM.SelBTLPart.nPROJ.ToString("0000"), 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 = ProjectManagerVM.CurrProd.sMachine, .nCmdType = CalcIntegration.CmdTypes.SIMULATE, .nGlobState = Map.refProjectVM.BTLStructureVM.SelBTLPart.nGlobalState} If Map.refProjectVM.BTLStructureVM.SelBTLPart.nGlobalState = CalcStates.NOTCALCULATED Then Dim sBTLPartFilePath As String = ProjectManagerVM.CurrProd.sProdDirPath & "\Projs\" & Map.refProjectVM.BTLStructureVM.SelBTLPart.nPROJ.ToString("0000") & "\" & 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" 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 Friend Sub Edit() Map.refBTLDataWndVM.SetIsBTLDataWnd(False) Dim bValuePart As Boolean = False For Each GeneralParam As ProjectParameters In Map.refProjectVM.GeneralParametersList bValuePart = False EgtGetInfo(Map.refProjectVM.BTLStructureVM.SelBTLPart.BTLPartM.nPartId, GeneralParam.sNameNge & "_FORCED", bValuePart) If bValuePart Then Exit For Next If bValuePart Then Map.refProjectVM.GetGeneralParameters(bValuePart) Else Map.refProjectVM.Read(ProjectManagerVM.CurrProd.nType) End If Map.refProjectVM.SetRawPartManagerVisibility(False) Map.refProjectVM.SetFeatureListVisibility(False) Map.refProjectVM.SetSelManagerTab(ProjectVM.StrategyManagerTab.FEATUREMANAGER) ' Disabilito LeftPanel Map.refProjectVM.SetLeftPanel_IsEnabled(False) Map.refProjectVM.SetLeftPanel_Opacity(0.2) End Sub #End Region ' Edit #Region "ResetCalc" 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 Public Sub ResetCalc() If IsNothing(ProjectManagerVM.CurrProd) OrElse IsNothing(Map.refProjectVM.BTLStructureVM) OrElse IsNothing(Map.refProjectVM.MachGroupPanelVM) Then Return Map.refShowBeamPanelVM.ShowBuilding_IsEnabled = True Map.refCALCPanelVM.SetCalculating(False) Dim SelPart As BTLPartVM = Map.refProjectVM.BTLStructureVM.SelBTLPart If IsNothing(SelPart) Then Return If SelPart.nGlobalState <> CalcStates.NOTCALCULATED Then ' Resetto info If MyExecProcessManager.sInfoNgePartList.Count > 0 Then For Each InfoNgePart As String In MyExecProcessManager.sInfoNgePartList Dim sInfoNgePart As String() = InfoNgePart.Split("="c) EgtRemoveInfo(SelPart.nPartId, sInfoNgePart(0)) Next End If SelPart.ResetCalcTotalPart() End If End Sub #End Region ' ResetCalc #End Region ' COMMANDS End Class