Files
egtbeamwall/EgtBEAMWALL.ViewerOptimizer/LeftPanel/LeftPanelVM.vb
T
DarioS cbed398eae EgtBEAMWALL 2.3i1 :
- modifiche e correzioni varie.
2021-09-09 16:20:04 +02:00

813 lines
33 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtBEAMWALL.Core
Imports EgtUILib
Imports EgtWPFLib5
Public Class LeftPanelVM
Inherits VMBase
#Region "FIELDS & PROPERTIES"
Public ReadOnly Property ViewPage_Visibility As Visibility
Get
Return If(Map.refMainMenuVM.SelPage = Pages.VIEW, Visibility.Visible, Visibility.Collapsed)
End Get
End Property
Public ReadOnly Property MachiningPage_Visibility As Visibility
Get
Return If(Map.refMainMenuVM.SelPage = Pages.MACHINING, Visibility.Visible, Visibility.Collapsed)
End Get
End Property
Private m_LeftPanel_IsEnabled As Boolean = True
Public ReadOnly Property LeftPanel_IsEnabled As Boolean
Get
Return m_LeftPanel_IsEnabled
End Get
End Property
' Definizione comandi
Private m_cmdNewRawPart As ICommand
Private m_cmdAddToRawPart As ICommand
Private m_cmdCopyPart As ICommand
Private m_cmdAddPart As ICommand
Private m_cmdRemovePart As ICommand
Private m_cmdCopyFeature As ICommand
Private m_cmdMacroFeature As ICommand
Private m_cmdAddFeature As ICommand
Private m_cmdRemoveFeature As ICommand
Private m_cmdResetCalc As ICommand
#Region "Messages"
Public ReadOnly Property NewRawPart_ToopTip As String
Get
Return EgtMsg(61903)
End Get
End Property
Public ReadOnly Property AddToRawPart_ToopTip As String
Get
Return EgtMsg(61904)
End Get
End Property
Public ReadOnly Property CopyPart_ToopTip As String
Get
Return EgtMsg(61905)
End Get
End Property
Public ReadOnly Property AddPart_ToopTip As String
Get
Return EgtMsg(61906)
End Get
End Property
Public ReadOnly Property RemovePart_ToopTip As String
Get
Return EgtMsg(61907)
End Get
End Property
Public ReadOnly Property CopyFeature_ToopTip As String
Get
Return EgtMsg(61908)
End Get
End Property
Public ReadOnly Property MacroFeature_ToopTip As String
Get
Return EgtMsg(61909)
End Get
End Property
Public ReadOnly Property AddFeature_ToopTip As String
Get
Return EgtMsg(61910)
End Get
End Property
Public ReadOnly Property RemoveFeature_ToopTip As String
Get
Return EgtMsg(61911)
End Get
End Property
#End Region ' Messages
#End Region 'FIELDS & PROPERTIES
Sub New()
' imposto riferimento su mappa
Map.SetRefLeftPanelVM(Me)
End Sub
#Region "METHODS"
Friend Sub UpdateView()
NotifyPropertyChanged(NameOf(ViewPage_Visibility))
NotifyPropertyChanged(NameOf(MachiningPage_Visibility))
End Sub
Friend Sub SetLeftPanelIsEnabled(bIsEnabled As Boolean)
m_LeftPanel_IsEnabled = bIsEnabled
NotifyPropertyChanged(NameOf(LeftPanel_IsEnabled))
End Sub
#End Region ' METHODS
#Region "COMMANDS"
#Region "NewRawPart"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property NewRawPart_Command As ICommand
Get
If m_cmdNewRawPart Is Nothing Then
m_cmdNewRawPart = New Command(AddressOf NewRawPart)
End If
Return m_cmdNewRawPart
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub NewRawPart()
If IsNothing(Map.refProdManagerVM.CurrProd) Then Return
Dim SelPart As BTLPartVM = Map.refProjectVM.BTLStructureVM.SelBTLPart
If IsNothing(SelPart) Then Return
' verifico se sono gia' stati messi tutti i pezzi richiesti
If Not VerifyPartCount(SelPart) Then Return
' chiedo lunghezza grezzo
Dim dRawL As Double = SelPart.dL
Dim dRawW As Double = SelPart.dW
Dim dStartOffset As Double = 0
Dim dKerf As Double = 0
Dim sWarehouseIniPath As String = Map.refMainWindowVM.MainWindowM.sWarehouseDir & "\" & WH_BASIC_INI_FILE_NAME
If Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.BEAM Then
dStartOffset = EgtUILib.GenInterface.GetPrivateProfileDouble(WRH_BEAM, WRH_STARTOFFSET, 0, sWarehouseIniPath)
dRawL += dStartOffset
Else
dKerf = EgtUILib.GenInterface.GetPrivateProfileDouble(WRH_WALL, WRH_KERF, 0, sWarehouseIniPath)
dRawL += 2 * dKerf
dRawW += 2 * dKerf
End If
Dim AddRawPartWndVM As New AddRawPartWndVM(Map.refProjectVM.BTLStructureVM.nPROJTYPE, dRawL, dRawW, dStartOffset)
Dim AddRawPartWnd As New AddRawPartWndV(Application.Current.MainWindow, AddRawPartWndVM)
If Not AddRawPartWnd.ShowDialog() Then Return
' creo nuovo gruppo di lavorazione
Map.refMachGroupPanelVM.AddMachGroup()
Dim nCurrMachGroup As Integer = EgtGetCurrMachGroup()
Dim sCurrMachGroupName As String = ""
EgtGetMachGroupName(nCurrMachGroup, sCurrMachGroupName)
' creo copia del pezzo
Dim nPartDuploId As Integer = EgtDuploNew(SelPart.nPartId)
' elimino valori calcolo dell'originale
MyMachGroupPanelVM.DuploRemoveProjCalc(nPartDuploId)
' lo rendo std
EgtSetMode(nPartDuploId, GDB_MD.STD)
Dim sLogPath As String = Map.refMainWindowVM.MainWindowM.sTempDir & "\RawPartLog.txt"
' scrivo dati per variabili P di comunicazione con la macchina in gruppo di lavorazione
EgtSetInfo(nCurrMachGroup, MGR_RPT_PRODID, Map.refProdManagerVM.CurrProd.nProdId)
EgtSetInfo(nCurrMachGroup, MGR_RPT_PATTID, nCurrMachGroup)
If Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.BEAM Then
' scrivo dati costruzione grezzo in gruppo di lavorazione
EgtSetInfo(nCurrMachGroup, MGR_RPT_BARLEN, AddRawPartWndVM.VariableList(0).dValue)
EgtSetInfo(nCurrMachGroup, MGR_RPT_MATERIAL, SelPart.sMATERIAL)
EgtSetInfo(nCurrMachGroup, MGR_RPT_PART & 1, nPartDuploId & "," & AddRawPartWndVM.VariableList(1).dValue)
Dim BeamMachGroup As BeamMachGroupVM = Map.refMachGroupPanelVM.GetLastMachGroup()
' eseguo script creazione grezzo
If Not ExecBeam(sLogPath, Map.refMachinePanelVM.SelectedMachine.Name, CalcIntegration.CmdType.RAWPART, False) Then
BeamMachGroup.DeleteMachGroup()
Dim LogFile As String() = File.ReadAllLines(sLogPath)
If LogFile.Count >= 2 AndAlso Not IsNothing(LogFile(1)) Then
MessageBox.Show(LogFile(1), EgtMsg(30007), MessageBoxButton.OK, MessageBoxImage.Error)
End If
Return
End If
' aggiorno contatore pezzi usati in Prod
SelPart.RefreshPartInProd()
'aggiorno lista pezzi
BeamMachGroup.m_BeamMachGroupM.RefreshPartList()
BeamMachGroup.m_BeamMachGroupM.RefreshGroupData()
' aggiorno dati utilizzo barra
BeamMachGroup.UpdateUsage()
EgtSetView(VT.ISO_SW, False)
ElseIf Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.WALL Then
' scrivo dati in gruppo di lavorazione
Dim dPosX As Double = dKerf
Dim dPosY As Double = dKerf
EgtSetInfo(nCurrMachGroup, MGR_RPT_PANELLEN, AddRawPartWndVM.VariableList(0).dValue)
EgtSetInfo(nCurrMachGroup, MGR_RPT_PANELWIDTH, AddRawPartWndVM.VariableList(1).dValue)
EgtSetInfo(nCurrMachGroup, MGR_RPT_MATERIAL, SelPart.sMATERIAL)
EgtSetInfo(nCurrMachGroup, MGR_RPT_PART & 1, nPartDuploId & "," & dPosX & "," & dPosY & "," & 0 & "," & 0)
Dim WallMachGroup As WallMachGroupVM = DirectCast(Map.refMachGroupPanelVM.MachGroupVMList(Map.refMachGroupPanelVM.MachGroupVMList.Count - 1), WallMachGroupVM)
' eseguo script creazione grezzo
If Not ExecWall(sLogPath, Map.refMachinePanelVM.SelectedMachine.Name, CalcIntegration.CmdType.RAWPART, False) Then
WallMachGroup.DeleteMachGroup()
If File.Exists(sLogPath) Then
Dim LogFile As String() = File.ReadAllLines(sLogPath)
If LogFile.Count >= 2 AndAlso Not IsNothing(LogFile(1)) Then
MessageBox.Show(LogFile(1), EgtMsg(30007), MessageBoxButton.OK, MessageBoxImage.Error)
End If
Else
MessageBox.Show("Impossible creating rawpart", EgtMsg(30007), MessageBoxButton.OK, MessageBoxImage.Error)
End If
Return
End If
' scrivo dati pezzo
EgtSetInfo(nPartDuploId, MGR_PRT_POSX, dPosX)
EgtSetInfo(nPartDuploId, MGR_PRT_POSY, dPosY)
EgtSetInfo(nPartDuploId, MGR_PRT_ROT, 0)
EgtSetInfo(nPartDuploId, MGR_PRT_FLIP, False)
' aggiorno contatore pezzi usati in Prod
SelPart.RefreshPartInProd()
' aggiorno lista pezzi
WallMachGroup.m_WallMachGroupM.RefreshPartList()
WallMachGroup.m_WallMachGroupM.RefreshGroupData()
' aggiorno dati ultilizzo barra
WallMachGroup.UpdateUsage()
EgtSetView(VT.TOP, False)
End If
EgtZoom(ZM.ALL)
End Sub
Private Function VerifyPartCount(SelPart As BTLPartVM) As Boolean
' verifico se ci sono pezzi da aggiungere
If Not SelPart.CanAddPartToCount Then
' se non ci sono, chiedo se aggiungerne uno nuovo
If MessageBox.Show(EgtMsg(61863) &
SelPart.nCNT & EgtMsg(61864) & SelPart.nADDED & EgtMsg(61865), "", MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then
SelPart.AddNewPartToAdded()
Else
Return False
End If
End If
Return True
End Function
'Friend Sub IncrementPartCount(SelPart As BTLPartVM)
' ' incremento i pezzi utilizzati
' SelPart.AddPartToProd()
'End Sub
#End Region ' NewRawPart
#Region "AddToRawPart"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property AddToRawPart_Command As ICommand
Get
If m_cmdAddToRawPart Is Nothing Then
m_cmdAddToRawPart = New Command(AddressOf AddToRawPart)
End If
Return m_cmdAddToRawPart
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub AddToRawPart()
If IsNothing(Map.refProdManagerVM.CurrProd) Then Return
Dim SelPart As BTLPartVM = Map.refProjectVM.BTLStructureVM.SelBTLPart
If IsNothing(SelPart) Then Return
Dim SelMachGroup As MachGroupVM = Map.refMachGroupPanelVM.SelectedMachGroup
If IsNothing(SelMachGroup) Then Return
' verifico se sono gia' stati messi tutti i pezzi richiesti
If Not VerifyPartCount(SelPart) Then Return
' verifico se impostato gruppo di lavorazione
Dim nCurrMachgroupId As Integer = EgtGetCurrMachGroup()
' se nullo o diverso da quello selezionato in lista
If nCurrMachgroupId = GDB_ID.NULL OrElse nCurrMachgroupId <> SelMachGroup.Id Then
' lo imposto
EgtSetCurrMachGroup(SelMachGroup.Id)
End If
If Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.BEAM Then
Dim BeamMachGroup As BeamMachGroupVM = DirectCast(SelMachGroup, BeamMachGroupVM)
' verifico sezione e materiale
If SelPart.Section <> BeamMachGroup.Section Then
MessageBox.Show(EgtMsg(61866), EgtMsg(30007))
Return
End If
' verifico lunghezza totale
If Not VerifyTotLength(BeamMachGroup, SelPart) Then
MessageBox.Show(EgtMsg(61867), EgtMsg(30007))
Return
End If
If AddPartToBeam(BeamMachGroup, SelPart) Then
' aggiorno contatore pezzi usati in Prod
SelPart.RefreshPartInProd()
End If
' aggiorno dati ultilizzo barra
BeamMachGroup.UpdateUsage()
EgtSetView(VT.ISO_SW, False)
ElseIf Map.refProjectVM.BTLStructureVM.nPROJTYPE = MachineType.WALL Then
Dim WallMachGroup As WallMachGroupVM = DirectCast(SelMachGroup, WallMachGroupVM)
' verifico spessore
If SelPart.dH < WallMachGroup.dH - EPS_SMALL OrElse SelPart.dH > WallMachGroup.dH + EPS_SMALL Then
MessageBox.Show(EgtMsg(61868), EgtMsg(30007))
Return
End If
If AddPartToWall(WallMachGroup, SelPart) Then
' aggiorno contatore pezzi usati in Prod
SelPart.RefreshPartInProd()
End If
' aggiorno dati ultilizzo barra
WallMachGroup.UpdateUsage()
EgtSetView(VT.TOP, False)
End If
EgtZoom(ZM.ALL)
End Sub
Friend Function VerifyTotLength(BeamMachGroup As BeamMachGroupVM, PartToAdd As BTLPartVM) As Boolean
Dim dNewPartPos As Double = 0
If BeamMachGroup.PartVMList.Count > 0 Then
Dim LastPart As PartVM = BeamMachGroup.PartVMList(BeamMachGroup.PartVMList.Count - 1)
dNewPartPos += LastPart.dPOSX + LastPart.dL
End If
dNewPartPos += RawPartConfiguration.dBeamDist + PartToAdd.dL
Return dNewPartPos < BeamMachGroup.dL
End Function
Friend Function AddPartToBeam(BeamMachGroup As BeamMachGroupVM, PartToAdd As BTLPartVM) As Boolean
' creo copia del pezzo
Dim nPartDuploId As Integer = EgtDuploNew(PartToAdd.nPartId)
' lo rendo std
EgtSetMode(nPartDuploId, GDB_MD.STD)
' calcolo posizione nuovo pezzo per rispettare ordine lunghezze
Dim nInsertIndex As Integer
' scrivo dati di tutti i pezzi
Dim dPosX As Double = BeamMachGroup.dStartCut
Dim bPartAdded As Boolean = False
Dim nIndex As Integer
' ciclo sui pezzi
For nIndex = 0 To BeamMachGroup.PartVMList.Count - 1
' se non ancora aggiunto e lunghezza minore del pezzo corrente, lo aggiungo
If Not bPartAdded AndAlso BeamMachGroup.PartVMList(nIndex).dL > PartToAdd.dL Then
' se non è primo, aggiungo offset tra barre standard
If nIndex <> 0 Then
dPosX += RawPartConfiguration.dBeamDist
End If
EgtSetInfo(BeamMachGroup.Id, MGR_RPT_PART & nIndex + 1, nPartDuploId & "," & DoubleToString(dPosX, 3))
' incremento posizione della sua lunghezza
dPosX += PartToAdd.dL
' conservo indice d'inserimento
nInsertIndex = nIndex
bPartAdded = True
End If
' se non è primo, aggiungo offset del pezzo
If nIndex <> 0 Then
Dim Beam As BeamVM = DirectCast(BeamMachGroup.PartVMList(nIndex), BeamVM)
dPosX += Beam.dOffset
' se sono a indice primo ed è stato aggiunto pezzo nuovo
ElseIf nIndex = 0 AndAlso bPartAdded Then
' aggiungo offset tra barre standard
dPosX += RawPartConfiguration.dBeamDist
End If
EgtSetInfo(BeamMachGroup.Id, MGR_RPT_PART & nIndex + If(bPartAdded, 2, 1), BeamMachGroup.PartVMList(nIndex).nPartId & "," & DoubleToString(dPosX, 3))
' incremento posizione della sua lunghezza
dPosX += BeamMachGroup.PartVMList(nIndex).dL
Next
' se non è ancora stato aggiunto
If Not bPartAdded Then
' aggiungo offset tra barre standard
dPosX += RawPartConfiguration.dBeamDist
' lo aggiungo in fondo
EgtSetInfo(BeamMachGroup.Id, MGR_RPT_PART & nIndex + 1, nPartDuploId & "," & DoubleToString(dPosX, 3))
' conservo indice d'inserimento
nInsertIndex = nIndex
End If
' elimino vecchio grezzo ed eseguo script creazione nuovo
Dim nRawId As Integer = EgtGetFirstRawPart()
While nRawId <> GDB_ID.NULL
EgtRemoveRawPart(nRawId)
nRawId = EgtGetFirstRawPart()
End While
If Not ExecBeam(Map.refMainWindowVM.MainWindowM.sTempDir, Map.refMachinePanelVM.SelectedMachine.Name, CalcIntegration.CmdType.RAWPART, False) Then
Return False
End If
' aggiorno lista pezzi
BeamMachGroup.m_BeamMachGroupM.RefreshPartList()
' seleziono pezzo aggiunto
If BeamMachGroup.PartVMList.Count > nInsertIndex Then BeamMachGroup.SelPart = BeamMachGroup.PartVMList(nInsertIndex)
Return True
End Function
Friend Function AddPartToWall(WallMachGroup As WallMachGroupVM, PartToAdd As BTLPartVM) As Boolean
' creo copia del pezzo
Dim nPartDuploId As Integer = EgtDuploNew(PartToAdd.nPartId)
' lo rendo std
EgtSetMode(nPartDuploId, GDB_MD.STD)
' Posizione di inserimento
Dim dPosX As Double = 10
Dim dPosY As Double = 10
' Se ci sono pezzi già inseriti
If WallMachGroup.PartVMList.Count > 0 Then
Dim LastWall As WallVM = DirectCast(WallMachGroup.PartVMList(WallMachGroup.PartVMList.Count - 1), WallVM)
' verifico se posso metterlo sopra in Y
Dim NextPosY = LastWall.m_WallM.dPOSY + LastWall.dW + RawPartConfiguration.dWallDist
If WallMachGroup.dW - NextPosY > PartToAdd.dW + 10 Then
dPosX = LastWall.dPOSX
dPosY = NextPosY
Else
dPosX = 10
For i As Integer = 0 To WallMachGroup.PartVMList.Count - 1
Dim CurrWall As WallVM = DirectCast(WallMachGroup.PartVMList(i), WallVM)
Dim NextPosX = CurrWall.dPOSX + CurrWall.dL + RawPartConfiguration.dWallDist
If NextPosX > dPosX Then
dPosX = NextPosX
End If
Next
dPosY = 10
End If
End If
If EgtAddPartToRawPart(nPartDuploId, New Point3d(dPosX, dPosY, 0), WallMachGroup.m_WallMachGroupM.nRawPartId) Then
EgtSetInfo(nPartDuploId, MGR_PRT_POSX, dPosX)
EgtSetInfo(nPartDuploId, MGR_PRT_POSY, dPosY)
EgtSetInfo(nPartDuploId, MGR_PRT_ROT, 0)
EgtSetInfo(nPartDuploId, MGR_PRT_FLIP, False)
Else
Return False
End If
'' scrivo dati in gruppo di lavorazione
'EgtSetInfo(WallMachGroup.Id, MGR_RPT_PART & WallMachGroup.PartVMList.Count + 1, nPartDuploId & "," & dPosX & "," & dPosY & "," & 0 & "," & 0)
'' eseguo script creazione grezzo
'Dim nRawId As Integer = EgtGetFirstRawPart()
'While nRawId <> GDB_ID.NULL
' EgtRemoveRawPart(nRawId)
' nRawId = EgtGetFirstRawPart()
'End While
'If Not ExecWall(Map.refMainWindowVM.MainWindowM.sTempDir, Map.refMachinePanelVM.SelectedMachine.Name, CalcIntegration.CmdType.RAWPART, False) Then Return False
'aggiorno lista pezzi
WallMachGroup.m_WallMachGroupM.RefreshPartList()
' seleziono pezzo aggiunto
If WallMachGroup.PartVMList.Count > 0 Then WallMachGroup.SelPart = WallMachGroup.PartVMList.FirstOrDefault(Function(x) x.nPartId = nPartDuploId)
Return True
End Function
#End Region ' AddToRawPart
#Region "CopyPart"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
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
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub CopyPart()
If IsNothing(Map.refProjManagerVM.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 crerato
Map.refProjectVM.BTLStructureVM.SelBTLPart = Map.refProjectVM.BTLStructureVM.BTLPartVMList(Map.refProjectVM.BTLStructureVM.BTLPartVMList.Count - 1)
End If
End Sub
#End Region ' CopyPart
#Region "AddPart"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property AddPart_Command As ICommand
Get
If m_cmdAddPart Is Nothing Then
m_cmdAddPart = New Command(AddressOf AddPart)
End If
Return m_cmdAddPart
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub AddPart(ByVal param As Object)
If IsNothing(Map.refProjManagerVM.CurrProj) Then Return
' apro finestra di definizione nuovo part
Dim AddPartWndVM As New AddPartWndVM()
Dim AddPartWnd As New AddPartWndV(Application.Current.MainWindow, AddPartWndVM)
If AddPartWnd.ShowDialog() Then
' creo nuovo part
Dim nNewPartId As Integer = EgtBeamCreatePart()
' scrivo info proj
EgtSetInfo(nNewPartId, BTL_PRT_PROJ, Map.refProjManagerVM.CurrProj.nProjId)
EgtBeamSetPartProdNbr(AddPartWndVM.nPDN)
If Not IsNothing(AddPartWndVM.sNAM) Then EgtBeamSetPartName(AddPartWndVM.sNAM)
EgtBeamSetPartCount(AddPartWndVM.nCNT)
EgtBeamSetPartBox(AddPartWndVM.dL, AddPartWndVM.dH, AddPartWndVM.dW)
' aggiungo dati pezzo
Dim NewPart As BTLPartM = BTLPartM.CreateBTLPart(nNewPartId)
' aggiungo pezzo alla lista
Map.refProjectVM.BTLStructureVM.BTLStructureM.AddBTLPart(NewPart)
Map.refProjectVM.BTLStructureVM.SelBTLPart = Map.refProjectVM.BTLStructureVM.BTLPartVMList.FirstOrDefault(Function(x) x.BTLPartM Is NewPart)
' verifico se aggiungere sezione alla lista
If Not Map.refProjectVM.BTLStructureVM.SectionList.Contains(Map.refProjectVM.BTLStructureVM.SelBTLPart.Section) Then
Map.refProjectVM.BTLStructureVM.SectionList.Add(Map.refProjectVM.BTLStructureVM.SelBTLPart.Section)
End If
End If
End Sub
#End Region ' AddPart
#Region "RemovePart"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property RemovePart_Command As ICommand
Get
If m_cmdRemovePart Is Nothing Then
m_cmdRemovePart = New Command(AddressOf RemovePart)
End If
Return m_cmdRemovePart
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub RemovePart()
If IsNothing(Map.refProjManagerVM.CurrProj) Then Return
If IsNothing(Map.refProjectVM.BTLStructureVM.SelBTLPart) Then Return
' verifico se ci sono già copie in grezzi
Dim nDuploCount As Integer = 0
If EgtDuploCount(Map.refProjectVM.BTLStructureVM.SelBTLPart.nPartId, nDuploCount) AndAlso nDuploCount > 0 Then
' avviso che il pezzo non è cancellabile perchè in produzione
MessageBox.Show(String.Format(EgtMsg(61852), 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 Map.refProjectVM.BTLStructureVM.SelBTLPart AndAlso x.Section = Map.refProjectVM.BTLStructureVM.SelBTLPart.Section) Then
Map.refProjectVM.BTLStructureVM.SectionList.Remove(Map.refProjectVM.BTLStructureVM.SelBTLPart.Section)
End If
' Eseguo cancellazione
EgtBeamSetPart(Map.refProjectVM.BTLStructureVM.SelBTLPart.nPartId)
If EgtBeamErasePart() Then
' rimuovo dalla lista pezzi
Dim Index As Integer = Map.refProjectVM.BTLStructureVM.BTLPartVMList.IndexOf(Map.refProjectVM.BTLStructureVM.SelBTLPart)
If Index = 0 Then
If Map.refProjectVM.BTLStructureVM.BTLPartVMList.Count > 1 Then
Map.refProjectVM.BTLStructureVM.SelBTLPart = Map.refProjectVM.BTLStructureVM.BTLPartVMList(1)
Else
Map.refProjectVM.BTLStructureVM.SelBTLPart = Nothing
End If
ElseIf Index = Map.refProjectVM.BTLStructureVM.BTLPartVMList.Count - 1 Then
If Map.refProjectVM.BTLStructureVM.BTLPartVMList.Count > 1 Then
Map.refProjectVM.BTLStructureVM.SelBTLPart = Map.refProjectVM.BTLStructureVM.BTLPartVMList(Map.refProjectVM.BTLStructureVM.BTLPartVMList.Count - 2)
Else
Map.refProjectVM.BTLStructureVM.SelBTLPart = Nothing
End If
Else
Map.refProjectVM.BTLStructureVM.SelBTLPart = Map.refProjectVM.BTLStructureVM.BTLPartVMList(Index - 1)
End If
Map.refProjectVM.BTLStructureVM.BTLPartVMList.RemoveAt(Index)
End If
End Sub
#End Region ' RemovePart
#Region "CopyFeature"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property CopyFeature_Command As ICommand
Get
If m_cmdCopyFeature Is Nothing Then
m_cmdCopyFeature = New Command(AddressOf CopyFeature)
End If
Return m_cmdCopyFeature
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub CopyFeature()
If IsNothing(Map.refProjManagerVM.CurrProj) Then Return
Dim SelPart As BTLPartVM = Map.refProjectVM.BTLStructureVM.SelBTLPart
If IsNothing(SelPart) Then Return
Dim SelFeature As BTLFeatureVM = SelPart.SelBTLFeatureVM
If IsNothing(SelFeature) Then Return
' creo copia
Dim NewFeature = SelFeature.Copy()
If Not IsNothing(NewFeature) Then
Map.refProjectVM.BTLStructureVM.SelBTLPart.SelBTLFeatureVM = Map.refProjectVM.BTLStructureVM.SelBTLPart.BTLFeatureVMList.FirstOrDefault(Function(x) x.BTLFeatureM Is NewFeature)
End If
End Sub
#End Region ' CopyFeature
#Region "MacroFeature"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property MacroFeature_Command As ICommand
Get
If m_cmdMacroFeature Is Nothing Then
m_cmdMacroFeature = New Command(AddressOf MacroFeature)
End If
Return m_cmdMacroFeature
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub MacroFeature()
If IsNothing(Map.refProjManagerVM.CurrProj) Then Return
If IsNothing(Map.refProjectVM.BTLStructureVM.SelBTLPart) Then Return
' apro finestra di creazione macro
Dim MacroFeatureWndVM As New MacroFeatureWndVM()
Dim MacroFeatureWnd As New MacroFeatureWndV(Application.Current.MainWindow, MacroFeatureWndVM)
If MacroFeatureWnd.ShowDialog() Then
End If
End Sub
#End Region ' MacroFeature
#Region "AddFeature"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property AddFeature_Command As ICommand
Get
If m_cmdAddFeature Is Nothing Then
m_cmdAddFeature = New Command(AddressOf AddFeature)
End If
Return m_cmdAddFeature
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub AddFeature(ByVal param As Object)
If IsNothing(Map.refProjManagerVM.CurrProj) Then Return
If IsNothing(Map.refProjectVM.BTLStructureVM.SelBTLPart) Then Return
' apro finestra di definizione nuova feature
Dim AddFeatureWndVM As New AddFeatureWndVM()
Dim AddFeatureWnd As New AddFeatureWndV(Application.Current.MainWindow, AddFeatureWndVM)
If AddFeatureWnd.ShowDialog() Then
Dim NewFeat As BTLFeatureM
Dim nNewFeatureId As Integer = 0
Dim bMacroFlag As Boolean = False
' verifico se una Macro è selezionata
If AddFeatureWndVM.MacroList.Count > 0 AndAlso AddFeatureWndVM.nSelMacro >= 0 Then
' Creo nuova feature sulla base della Macro selezionata
' Creo table e setto variabili
EgtLuaCreateGlobTable("MACRO")
EgtLuaSetGlobNumVar("MACRO.L", Map.refProjectVM.BTLStructureVM.SelBTLPart.dBtlL)
EgtLuaSetGlobNumVar("MACRO.W", Map.refProjectVM.BTLStructureVM.SelBTLPart.dBtlW)
EgtLuaSetGlobNumVar("MACRO.H", Map.refProjectVM.BTLStructureVM.SelBTLPart.dBtlH)
EgtLuaSetGlobIntVar("MACRO.PROCID", Map.refProjectVM.BTLStructureVM.SelBTLPart.BTLPartM.NewProcId())
Dim bOk = EgtLuaExecFile(AddFeatureWndVM.m_MacroFilePathList(AddFeatureWndVM.nSelMacro))
' Leggo variabili
EgtLuaGetGlobIntVar("MACRO.FEATUREID", nNewFeatureId)
' Reset lua
EgtLuaResetGlobVar("MACRO")
If Not bOk Then
MessageBox.Show(EgtMsg(61869), EgtMsg(30007))
Return
End If
bMacroFlag = True
Else
' Creo nuova feature (Macro non selezionata)
NewFeat = BTLFeatureM.CreateBTLFeature(AddFeatureWndVM.nSelPRC.nPRC, AddFeatureWndVM.nSelPRC.nGRP, AddFeatureWndVM.nSelPRC.nSIDE)
NewFeat.SetDefaultValues()
Dim vPar() As Double = Nothing
Dim sPar As String = String.Empty
Dim vParQ() As String = Nothing
NewFeat.CalcParamArray(vPar, sPar, vParQ)
' aggiorno la feature con nuovo valore
EgtBeamSetPart(Map.refProjectVM.BTLStructureVM.SelBTLPart.nPartId)
nNewFeatureId = EgtBeamAddProcess(NewFeat.nSelGRP, NewFeat.nPRC, NewFeat.nSelSIDE, "",
Map.refProjectVM.BTLStructureVM.SelBTLPart.BTLPartM.NewProcId(),
New Frame3d(), vPar, sPar, vParQ)
bMacroFlag = False
End If
' se è stata creata
If nNewFeatureId <> GDB_ID.NULL Then
' la aggiungo a struttura BTL corrente
NewFeat = BTLFeatureM.CreateBTLFeature(Map.refProjectVM.BTLStructureVM.SelBTLPart.BTLPartM, nNewFeatureId)
If Not bMacroFlag Then NewFeat.SetDefaultValues()
Map.refProjectVM.BTLStructureVM.SelBTLPart.BTLPartM.AddBTLFeature(NewFeat)
Map.refProjectVM.BTLStructureVM.SelBTLPart.SelBTLFeatureVM = Map.refProjectVM.BTLStructureVM.SelBTLPart.BTLFeatureVMList.FirstOrDefault(Function(x) x.BTLFeatureM Is NewFeat)
End If
End If
End Sub
#End Region ' AddFeature
#Region "RemoveFeature"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property RemoveFeature_Command As ICommand
Get
If m_cmdRemoveFeature Is Nothing Then
m_cmdRemoveFeature = New Command(AddressOf RemoveFeature)
End If
Return m_cmdRemoveFeature
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub RemoveFeature()
If IsNothing(Map.refProjManagerVM.CurrProj) Then Return
If IsNothing(Map.refProjectVM.BTLStructureVM.SelBTLPart) Then Return
If IsNothing(Map.refProjectVM.BTLStructureVM.SelBTLPart.SelBTLFeatureVM) Then Return
If EgtBeamEraseProcess(Map.refProjectVM.BTLStructureVM.SelBTLPart.SelBTLFeatureVM.nFeatureId) Then
' rimuovo dalla lista pezzi
Dim Index As Integer = Map.refProjectVM.BTLStructureVM.SelBTLPart.BTLFeatureVMList.IndexOf(Map.refProjectVM.BTLStructureVM.SelBTLPart.SelBTLFeatureVM)
If Index = 0 Then
If Map.refProjectVM.BTLStructureVM.SelBTLPart.BTLFeatureVMList.Count > 0 Then
Map.refProjectVM.BTLStructureVM.SelBTLPart.SelBTLFeatureVM = Map.refProjectVM.BTLStructureVM.SelBTLPart.BTLFeatureVMList(0)
Else
Map.refProjectVM.BTLStructureVM.SelBTLPart.SelBTLFeatureVM = Nothing
End If
ElseIf Index = Map.refProjectVM.BTLStructureVM.SelBTLPart.BTLFeatureVMList.Count - 1 Then
If Map.refProjectVM.BTLStructureVM.SelBTLPart.BTLFeatureVMList.Count > 1 Then
Map.refProjectVM.BTLStructureVM.SelBTLPart.SelBTLFeatureVM = Map.refProjectVM.BTLStructureVM.SelBTLPart.BTLFeatureVMList(Map.refProjectVM.BTLStructureVM.SelBTLPart.BTLFeatureVMList.Count - 2)
Else
Map.refProjectVM.BTLStructureVM.SelBTLPart.SelBTLFeatureVM = Nothing
End If
Else
Map.refProjectVM.BTLStructureVM.SelBTLPart.SelBTLFeatureVM = Map.refProjectVM.BTLStructureVM.SelBTLPart.BTLFeatureVMList(Index - 1)
End If
Map.refProjectVM.BTLStructureVM.SelBTLPart.BTLFeatureVMList.RemoveAt(Index)
EgtDraw()
End If
End Sub
#End Region ' RemoveFeature
#Region "ResetCalc"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
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
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub ResetCalc()
If IsNothing(Map.refProjManagerVM.CurrProj) Then Return
If IsNothing(Map.refProjectVM.BTLStructureVM) Then Return
If (Keyboard.Modifiers And ModifierKeys.Shift) = ModifierKeys.Shift Then
For each Part In Map.refProjectVM.BTLStructureVM.BTLPartVMList
If Part.nGlobalState <> CalcStates.NOTCALCULATED Then
Part.ResetCalcPart()
End If
Next
Else
Dim SelPart As BTLPartVM = Map.refProjectVM.BTLStructureVM.SelBTLPart
If IsNothing(SelPart) Then Return
If SelPart.nGlobalState <> CalcStates.NOTCALCULATED Then
SelPart.ResetCalcPart()
End If
End If
End Sub
#End Region ' ResetCalc
#End Region ' COMMANDS
End Class