Imports System.Collections.ObjectModel Imports EgtUILib Public Class PositionGroup ' Lista delle posizioni Private m_PositionList As New ObservableCollection(Of Position) Public Property PositionList As ObservableCollection(Of Position) Get Return m_PositionList End Get Set(value As ObservableCollection(Of Position)) m_PositionList = value End Set End Property Sub New() End Sub Sub New(PositionList As ObservableCollection(Of Position)) m_PositionList = PositionList End Sub End Class Public Class Position Private Const INVALIDPOS As String = "" Private m_TcPos As String Public Property TcPos As String Get Return m_TcPos End Get Set(value As String) m_TcPos = value End Set End Property Friend m_IsModifiedHead As Boolean = False Friend m_IsAppliedHead As Boolean = True Private m_OrigHead As String = Nothing Friend Property OrigHead As String Get Return m_OrigHead End Get Set(value As String) m_OrigHead = value m_IsAppliedHead = True End Set End Property Private m_Head As String ''' ''' Property that read and write to the tool's database the Head ''' Friend Property Head As String Get Return m_Head End Get Set(value As String) If value = String.Empty Or value <> m_Head Then m_Head = value If Not IsNothing(m_Head) And Not IsNothing(m_OrigHead) Then m_IsAppliedHead = (m_Head = m_OrigHead) Else m_IsAppliedHead = IsNothing(m_Head) And IsNothing(m_OrigHead) End If m_IsModifiedHead = True End If End Set End Property Friend Sub SetHead(value As String) If value = String.Empty Or value <> m_Head Then m_Head = value m_IsModifiedHead = False End If End Sub ' Lista delle uscite con relativi utensili associati Private m_ExitToolAssociationList As New ObservableCollection(Of ExitToolAssociation) Public Property ExitToolAssociationList As ObservableCollection(Of ExitToolAssociation) Get Return m_ExitToolAssociationList End Get Set(value As ObservableCollection(Of ExitToolAssociation)) m_ExitToolAssociationList = value End Set End Property #Region "METHODS" Friend Sub SetIsValidPosFromTool(TUuid As String) EgtLuaSetGlobStringVar("STU.TUUID", TUuid) EgtLuaSetGlobStringVar("STU.TCPOS", m_TcPos) EgtLuaCallFunction("STU.GetValidHeadExitForPos") ' Leggo variabili Dim sHead As String = String.Empty EgtLuaGetGlobStringVar("STU.HEAD", sHead) Dim nExit As Integer = 0 EgtLuaGetGlobIntVar("STU.EXIT", nExit) Dim nErr As Integer = 999 EgtLuaGetGlobIntVar("STU.ERR", nErr) If nErr <> 0 Then ' disattivo tutte le uscite tranne quelle attrezzate For ExitIndex = 0 To ExitToolAssociationList.Count - 1 If ExitToolAssociationList(ExitIndex).IsOccupied Then ExitToolAssociationList(ExitIndex).IsEnabledPos = True ExitToolAssociationList(ExitIndex).IsValidPos = False Else ExitToolAssociationList(ExitIndex).IsEnabledPos = False End If Next Dim sToolName As String = String.Empty EgtTdbGetToolFromUUID(TUuid, sToolName) EgtOutLog("Error in setup! Tool:" & sToolName & " TcPos: " & m_TcPos) Return End If ' verifico se la posizione è libera o c'è un utensile attrezzato Dim PosIsOccupied As Boolean = False For ExitIndex = 0 To ExitToolAssociationList.Count - 1 If ExitToolAssociationList(ExitIndex).IsOccupied Then PosIsOccupied = True Exit For End If Next ' se la posizione non è valida, disattivo tutte le uscite tranne quelle attrezzate If sHead = INVALIDPOS Then For ExitIndex = 0 To ExitToolAssociationList.Count - 1 If ExitToolAssociationList(ExitIndex).IsOccupied Then ExitToolAssociationList(ExitIndex).IsEnabledPos = True ExitToolAssociationList(ExitIndex).IsValidPos = False Else ExitToolAssociationList(ExitIndex).IsEnabledPos = False End If Next ' altrimenti, se la posizione nell'attrezzaggio è vuota ElseIf Not PosIsOccupied Then ' se l'uscita restituita esiste If ExitToolAssociationList.Count >= nExit Then ' disattivo tutte le uscite tranne quella restituita For ExitIndex = 0 To ExitToolAssociationList.Count - 1 If ExitIndex + 1 = nExit Then ExitToolAssociationList(ExitIndex).IsEnabledPos = True ExitToolAssociationList(ExitIndex).IsValidPos = True Else ExitToolAssociationList(ExitIndex).IsEnabledPos = False End If Next ' altrimenti lascio attiva solo la prima uscita Else ExitToolAssociationList(0).IsEnabledPos = True For ExitIndex = 1 To ExitToolAssociationList.Count - 1 ExitToolAssociationList(ExitIndex).IsEnabledPos = False Next End If ' altrimenti, se le teste coincidono ElseIf sHead = Head Then ' se l'uscita restituita è libera la attivo e disattivo tutte le altre non occupate If Not ExitToolAssociationList(nExit - 1).IsOccupied Then For ExitIndex = 0 To ExitToolAssociationList.Count - 1 If ExitIndex = nExit - 1 Then ExitToolAssociationList(ExitIndex).IsEnabledPos = True ExitToolAssociationList(ExitIndex).IsValidPos = True ElseIf ExitToolAssociationList(ExitIndex).IsOccupied Then ExitToolAssociationList(ExitIndex).IsValidPos = False Else ExitToolAssociationList(ExitIndex).IsEnabledPos = False End If Next ' altrimenti le disattivo tutte tranne quelle occupate Else For ExitIndex = 0 To ExitToolAssociationList.Count - 1 If ExitToolAssociationList(ExitIndex).IsOccupied Then ExitToolAssociationList(ExitIndex).IsEnabledPos = True If ExitIndex = nExit - 1 Then ExitToolAssociationList(ExitIndex).IsValidPos = True Else ExitToolAssociationList(ExitIndex).IsValidPos = False End If Else ExitToolAssociationList(ExitIndex).IsEnabledPos = False End If Next End If ' se le teste non coincidono Else EgtLuaSetGlobStringVar("STU.HEAD1", sHead) EgtLuaSetGlobStringVar("STU.HEAD2", Head) EgtLuaCallFunction("STU.IsCompatibleHeads") ' Leggo variabili Dim bIsValid As Boolean = False EgtLuaGetGlobBoolVar("STU.ISVALID", bIsValid) nErr = 999 EgtLuaGetGlobIntVar("STU.ERR", nErr) If nErr <> 0 Then ' disattivo tutte le uscite tranne quelle attrezzate For ExitIndex = 0 To ExitToolAssociationList.Count - 1 If ExitToolAssociationList(ExitIndex).IsOccupied Then ExitToolAssociationList(ExitIndex).IsEnabledPos = True ExitToolAssociationList(ExitIndex).IsValidPos = False Else ExitToolAssociationList(ExitIndex).IsEnabledPos = False End If Next Dim sToolName As String = String.Empty EgtTdbGetToolFromUUID(TUuid, sToolName) EgtOutLog("Error in setup! Tool:" & sToolName & " TcPos: " & m_TcPos) Return End If ' se le teste sono compatibili If bIsValid Then ' se l'uscita restituita è libera la attivo e disattivo tutte le altre non occupate If nExit < ExitToolAssociationList.Count - 1 AndAlso Not ExitToolAssociationList(nExit - 1).IsOccupied Then For ExitIndex = 0 To ExitToolAssociationList.Count - 1 If ExitIndex = nExit - 1 Then ExitToolAssociationList(ExitIndex).IsEnabledPos = True ExitToolAssociationList(ExitIndex).IsValidPos = True ElseIf ExitToolAssociationList(ExitIndex).IsOccupied Then ExitToolAssociationList(ExitIndex).IsValidPos = False Else ExitToolAssociationList(ExitIndex).IsEnabledPos = False End If Next ' altrimenti le disattivo tutte tranne quelle occupate Else For ExitIndex = 0 To ExitToolAssociationList.Count - 1 If ExitToolAssociationList(ExitIndex).IsOccupied Then ExitToolAssociationList(ExitIndex).IsEnabledPos = True If ExitIndex = nExit - 1 Then ExitToolAssociationList(ExitIndex).IsValidPos = True Else ExitToolAssociationList(ExitIndex).IsValidPos = False End If Else ExitToolAssociationList(ExitIndex).IsEnabledPos = False End If Next End If ' se le teste non sono compatibili Else ' disabilito tutte le uscite For ExitIndex = 0 To ExitToolAssociationList.Count - 1 ExitToolAssociationList(ExitIndex).IsEnabledPos = False Next End If End If End Sub Friend Sub SetNotValidPos() ' le disattivo tutte tranne quelle occupate For ExitIndex = 0 To ExitToolAssociationList.Count - 1 If ExitToolAssociationList(ExitIndex).IsOccupied Then ExitToolAssociationList(ExitIndex).IsEnabledPos = True ExitToolAssociationList(ExitIndex).IsValidPos = Nothing Else ExitToolAssociationList(ExitIndex).IsEnabledPos = False End If Next End Sub #End Region ' Methods Sub New(TcPos As String, Head As String, ExitNum As Integer) Me.TcPos = TcPos Me.SetHead(Head) For ExitIndex = 1 To ExitNum ExitToolAssociationList.Add(New ExitToolAssociation(ExitIndex.ToString, Me)) Next End Sub End Class Public Class ExitToolAssociation Inherits VMBase ' Riferimento alla lista utensili Friend Shared sh_ToolsList As ObservableCollection(Of FamilyToolItem) ' riferimento alla lista posizioni Friend Shared sh_PositionGroupList As ObservableCollection(Of PositionGroup) ' Actions Friend Shared m_delIsModifiedSetUp As Action ' Riferimento alla posizione di questa uscita Private m_MyPos As Position Private m_IsOccupied As Boolean ''' ''' Property that read and write to the tool's database the Exit ''' Public Property IsOccupied As Boolean Get Return m_IsOccupied End Get Set(value As Boolean) If value <> m_IsOccupied Then m_IsOccupied = value NotifyPropertyChanged("IsOccupied") End If End Set End Property Private m_IsEnabledPos As Boolean ''' ''' Property that read and write to the tool's database the Exit ''' Public Property IsEnabledPos As Boolean Get Return m_IsEnabledPos End Get Set(value As Boolean) If value <> m_IsEnabledPos Then m_IsEnabledPos = value NotifyPropertyChanged("IsEnabledPos") End If End Set End Property Private m_IsValidPos As Boolean? ''' ''' Property that read and write to the tool's database the Exit ''' Public Property IsValidPos As Boolean? Get Return m_IsValidPos End Get Set(value As Boolean?) m_IsValidPos = value NotifyPropertyChanged("ExitBtnBackgroundCol") End Set End Property Public ReadOnly Property ExitBtnBackgroundCol As SolidColorBrush Get If IsNothing(m_IsValidPos) Then Return New SolidColorBrush(Color.FromArgb(255, 221, 221, 221)) ElseIf m_IsValidPos Then If m_IsOccupied Then Return EgaltechYellow Else Return EgaltechGreen End If Else Return New SolidColorBrush(Color.FromArgb(255, 221, 221, 221)) End If End Get End Property Private m_Exit As String ''' ''' Property that read and write to the tool's database the Exit ''' Public Property ExitPar As String Get Return m_Exit End Get Set(value As String) If value <> m_Exit Then m_Exit = value End If End Set End Property Friend m_IsModifiedTool As Boolean = False Friend m_IsAppliedTool As Boolean = True Private m_OrigTool As ToolItem = Nothing Friend Property OrigTool As ToolItem Get Return m_OrigTool End Get Set(value As ToolItem) m_OrigTool = value m_IsAppliedTool = True End Set End Property Private m_Tool As ToolItem ''' ''' Property that read and write to the tool's database the Uuid ''' Public Property Tool As ToolItem Get Return m_Tool End Get Set(value As ToolItem) m_Tool = value If Not IsNothing(m_Tool) And Not IsNothing(m_OrigTool) Then m_IsAppliedTool = (m_Tool.Uuid = m_OrigTool.Uuid) Else m_IsAppliedTool = IsNothing(m_Tool) And IsNothing(m_OrigTool) End If m_IsModifiedTool = True NotifyPropertyChanged("Tool") m_delIsModifiedSetUp() End Set End Property Friend Sub SetTool(ToolItem As ToolItem) m_Tool = ToolItem If Not IsNothing(m_Tool) And Not IsNothing(m_OrigTool) Then m_IsAppliedTool = (m_Tool.Uuid = m_OrigTool.Uuid) Else m_IsAppliedTool = IsNothing(m_Tool) And IsNothing(m_OrigTool) End If m_IsModifiedTool = False NotifyPropertyChanged("Tool") End Sub #Region "Messages" Public ReadOnly Property ToolTipMsg As String Get If IsNothing(m_Tool) Then Return "" EgtTdbSetCurrTool(m_Tool.Name) Dim dValue As Double = 0 Dim nType As Integer EgtTdbGetCurrToolParam(MCH_TP.TYPE, nType) EgtTdbGetCurrToolParam(MCH_TP.DIAM, dValue) Dim sDiam As String = LenToString(dValue, 4) EgtTdbGetCurrToolParam(MCH_TP.LEN, dValue) Dim sLen As String = LenToString(dValue, 4) EgtTdbGetCurrToolParam(MCH_TP.MAXMAT, dValue) Dim MaxMat As String = LenToString(dValue, 4) Return (EgtMsg(MSG_TOOLSDBPAGE + 53) & ": " & ConvertToolTypeToString(nType) & Environment.NewLine & EgtMsg(MSG_TOOLSDBPAGE + 56) & ": " & sDiam & Environment.NewLine & EgtMsg(MSG_TOOLSDBPAGE + 62) & ": " & sLen & Environment.NewLine & EgtMsg(MSG_TOOLSDBPAGE + 64) & ": " & MaxMat) End Get End Property Private Function ConvertToolTypeToString(ToolType As Integer) As String Select Case ToolType Case MCH_TY.DRILL_STD Return EgtMsg(MSG_TOOLSDBPAGE + 1) Case MCH_TY.DRILL_LONG Return EgtMsg(MSG_TOOLSDBPAGE + 6) Case MCH_TY.SAW_STD Return EgtMsg(MSG_TOOLSDBPAGE + 2) Case MCH_TY.SAW_FLAT Return EgtMsg(MSG_TOOLSDBPAGE + 7) Case MCH_TY.MILL_STD Return EgtMsg(MSG_TOOLSDBPAGE + 3) Case MCH_TY.MILL_NOTIP Return EgtMsg(MSG_TOOLSDBPAGE + 8) Case MCH_TY.MORTISE_STD Return EgtMsg(MSG_TOOLSDBPAGE + 4) Case MCH_TY.COMPO Return EgtMsg(MSG_TOOLSDBPAGE + 5) Case Else Return String.Empty End Select End Function #End Region ' Messages ' Definizione comandi Private m_cmdSetUpTool As ICommand #Region "CONSTRUCTORS" Sub New(ExitPar As String, MyPos As Position) Me.ExitPar = ExitPar m_MyPos = MyPos End Sub #End Region ' Constructors #Region "COMMANDS" #Region "SetUpToolCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property SetUpToolCommand As ICommand Get If m_cmdSetUpTool Is Nothing Then m_cmdSetUpTool = New Command(AddressOf SetUpTool) End If Return m_cmdSetUpTool End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub SetUpTool(param As Object) If m_IsOccupied Then ' se quello selezionato nella lista non è un utensile esco If Not TypeOf param Is ToolItem Then m_IsOccupied = False NotifyPropertyChanged("IsOccupied") Return End If Dim SelTool As ToolItem = DirectCast(param, ToolItem) ' verifico se devo cambiare la testa EgtLuaSetGlobStringVar("STU.TUUID", SelTool.Uuid) EgtLuaSetGlobStringVar("STU.TCPOS", m_MyPos.TcPos) EgtLuaCallFunction("STU.GetValidHeadExitForPos") ' Leggo variabili Dim sHead As String = String.Empty EgtLuaGetGlobStringVar("STU.HEAD", sHead) Dim nExit As Integer = 0 EgtLuaGetGlobIntVar("STU.EXIT", nExit) Dim nErr As Integer = 999 EgtLuaGetGlobIntVar("STU.ERR", nErr) If nErr <> 0 Then Dim sToolName As String = String.Empty EgtTdbGetToolFromUUID(SelTool.Uuid, sToolName) EgtOutLog("Error in setup! Tool:" & sToolName & " TcPos: " & m_MyPos.TcPos) m_IsOccupied = False NotifyPropertyChanged("IsOccupied") Return End If ' se la testa restituita non coincide con quella della posizione If m_MyPos.Head <> sHead Then ' aggiorno testa ed uscite m_MyPos.Head = sHead For ExitIndex = m_MyPos.ExitToolAssociationList.Count + 1 To EgtGetHeadExitCount(sHead) m_MyPos.ExitToolAssociationList.Add(New ExitToolAssociation(ExitIndex.ToString, m_MyPos)) Next For ExitIndex = m_MyPos.ExitToolAssociationList.Count - 1 To EgtGetHeadExitCount(sHead) Step -1 m_MyPos.ExitToolAssociationList.RemoveAt(ExitIndex) Next End If ' lo aggiungo alla posizione di attrezzaggio Tool = SelTool IsOccupied = True ' e lo tolgo dalla lista For Index = 0 To sh_ToolsList.Count - 1 If (SelTool.Type And sh_ToolsList(Index).Type) > 0 Then sh_ToolsList(Index).Items.Remove(SelTool) Exit For End If Next NotifyPropertyChanged("ToolTipMsg") Else ' lo rimetto nella lista utensili For Index = 0 To sh_ToolsList.Count - 1 If (Tool.Type And sh_ToolsList(Index).Type) > 0 Then ' creo una copia della lista di utensili della famiglia Dim TempList As New List(Of String) Dim ToolIndex As Integer For ToolIndex = 0 To sh_ToolsList(Index).Items.Count - 1 TempList.Add(sh_ToolsList(Index).Items(ToolIndex).Name) Next ' aggiungo l'utensile da inserire TempList.Add(Tool.Name) ' riordino la lista TempList.Sort() ' ricavo l'indice dell'utensile inserito ToolIndex = TempList.IndexOf(Tool.Name) ' lo inserisco nel posto giusto sh_ToolsList(Index).Items.Insert(ToolIndex, Tool) ' espando la famiglia in cui l'ho messo sh_ToolsList(Index).IsExpanded = True Exit For End If Next ' abilito e disabilito tutte le uscite in base all'utensile selezionato For GroupIndex = 0 To sh_PositionGroupList.Count - 1 For PosIndex = 0 To sh_PositionGroupList(GroupIndex).PositionList.Count - 1 sh_PositionGroupList(GroupIndex).PositionList(PosIndex).SetIsValidPosFromTool(Tool.Uuid) Next Next ' seleziono utensile rimesso in lista m_Tool.IsSelected = True Tool.NotifyPropertyChanged("IsSelected") ' e lo tolgo dalla posizione di attrezzaggio Tool = Nothing IsOccupied = False End If End Sub #End Region ' SetUpToolCommand #End Region ' Commands End Class Public Class FamilyToolItem Inherits InheritableTreeViewItem ' riferimento alla lista posizioni Friend Shared m_PositionGroupList As ObservableCollection(Of PositionGroup) Public Overrides Property IsSelected As Boolean Get Return m_IsSelected End Get Set(value As Boolean) If (value <> m_IsSelected) Then m_IsSelected = value If value Then ' disabilito tutte le uscite tranne quelle occupate For GroupIndex = 0 To m_PositionGroupList.Count - 1 For PosIndex = 0 To m_PositionGroupList(GroupIndex).PositionList.Count - 1 m_PositionGroupList(GroupIndex).PositionList(PosIndex).SetNotValidPos() Next Next End If End If End Set End Property Public ReadOnly Property FamilyColor As SolidColorBrush Get If m_HaveToolsInCurrMachGroup Then Return Brushes.Red Else Return Brushes.Transparent End If End Get End Property Private m_HaveToolsInCurrMachGroup As Boolean Friend ReadOnly Property HaveToolsInCurrMachGroup As Boolean Get Return m_HaveToolsInCurrMachGroup End Get End Property Private m_Type As MCH_TF ''' ''' Property that determines the tool type of the family ''' Public ReadOnly Property Type As MCH_TF Get Return m_Type End Get End Property Sub New(Name As String, Type As MCH_TF) MyBase.New(Name) Me.PictureString = "/Resources/TreeView/Folder.png" m_Type = Type ' Aggiungo il gestore d'evento di modifica lista degli item per poter mettere e togliere il pallino che indica se ci sono utensili da attrezzare AddHandler Items.CollectionChanged, AddressOf ManageObservableCollection End Sub Private Sub ManageObservableCollection(sender As Object, e As System.Collections.Specialized.NotifyCollectionChangedEventArgs) m_HaveToolsInCurrMachGroup = False For Index = 0 To Items.Count - 1 Dim ToolItem As ToolItem = DirectCast(Items(Index), ToolItem) If ToolItem.m_IsInCurrMachGroup Then m_HaveToolsInCurrMachGroup = True End If Next NotifyPropertyChanged("FamilyColor") End Sub End Class Public Class ToolItem Inherits InheritableTreeViewItem ' riferimento alla lista posizioni Friend Shared m_PositionGroupList As ObservableCollection(Of PositionGroup) Public Overrides Property IsSelected As Boolean Get Return m_IsSelected End Get Set(value As Boolean) If (value <> m_IsSelected) Then m_IsSelected = value If value Then ' abilito e disabilito tutte le uscite in base all'utensile selezionato For GroupIndex = 0 To m_PositionGroupList.Count - 1 For PosIndex = 0 To m_PositionGroupList(GroupIndex).PositionList.Count - 1 m_PositionGroupList(GroupIndex).PositionList(PosIndex).SetIsValidPosFromTool(Uuid) Next Next End If End If End Set End Property Public ReadOnly Property ToolColor As SolidColorBrush Get If m_IsInCurrMachGroup Then Return Brushes.Red Else Return Brushes.Transparent End If End Get End Property Friend m_IsInCurrMachGroup As Boolean ''' ''' Property that read and write to the tool's database the Exit ''' Public Property IsInCurrMachGroup As Boolean Get Return m_IsInCurrMachGroup End Get Set(value As Boolean) If value <> m_IsInCurrMachGroup Then m_IsInCurrMachGroup = value 'NotifyPropertyChanged("IsInCurrMachGroup") End If End Set End Property Private m_Exit As String ''' ''' Property that read and write to the tool's database the Exit ''' Friend Property ExitPar As String Get Return m_Exit End Get Set(value As String) If value <> m_Exit Then m_Exit = value End If End Set End Property Private m_Type As MCH_TY ''' ''' Property that determines the tool type of the family ''' Public ReadOnly Property Type As MCH_TY Get Return m_Type End Get End Property Private m_Head As String ''' ''' Property that read and write to the tool's database the Head ''' Friend Property Head As String Get Return m_Head End Get Set(value As String) If value = String.Empty Or value <> m_Head Then m_Head = value End If End Set End Property Private m_TcPos As String ''' ''' Property that read and write to the tool's database the Tc Pos ''' Friend Property TcPos As String Get Return m_TcPos End Get Set(value As String) If value = String.Empty Or value <> m_TcPos Then m_TcPos = value End If End Set End Property Private m_Uuid As String ''' ''' Property that read and write to the tool's database the Uuid ''' Friend ReadOnly Property Uuid As String Get Return m_Uuid End Get End Property #Region "Messages" Public ReadOnly Property ToolTipMsg As String Get Return (EgtMsg(MSG_TOOLSDBPAGE + 75) & ": " & m_Name & Environment.NewLine & EgtMsg(MSG_TOOLSDBPAGE + 78) & ": " & m_TcPos & Environment.NewLine & EgtMsg(MSG_TOOLSDBPAGE + 74) & ": " & m_Head & "." & m_Exit) End Get End Property #End Region ' Messages Sub New(Name As String, ExitPar As String, Type As Integer, Head As String, TcPos As String, Uuid As String, IsInCurrMachGroup As Boolean) MyBase.New(Name) m_Exit = ExitPar m_Type = DirectCast(Type, MCH_TY) m_Head = Head m_TcPos = TcPos m_Uuid = Uuid m_IsInCurrMachGroup = IsInCurrMachGroup End Sub End Class