Imports System.Collections.ObjectModel Imports System.ComponentModel Imports System.IO Imports EgtUILib Namespace EgtCAM5 Public Class SetUpViewModel Implements INotifyPropertyChanged Private Const INVALIDPOS As String = "" Private m_Title As String Public ReadOnly Property Title As String Get Return EgtMsg(MSG_SETUP + 1) End Get End Property ' Lista degli utensili Private m_ToolsList As New ObservableCollection(Of FamilyToolItem) Public Property ToolsList As ObservableCollection(Of FamilyToolItem) Get Return m_ToolsList End Get Set(value As ObservableCollection(Of FamilyToolItem)) m_ToolsList = value End Set End Property ' Lista dei gruppi di posizioni Private m_PositionGroupList As New ObservableCollection(Of PositionGroup) Public Property PositionGroupList As ObservableCollection(Of PositionGroup) Get Return m_PositionGroupList End Get Set(value As ObservableCollection(Of PositionGroup)) m_PositionGroupList = value End Set End Property Private m_IsEnabledApplyBtn As Boolean Public ReadOnly Property IsEnabledApplyBtn As Boolean Get Return m_IsEnabledApplyBtn End Get End Property ' Immagine del porta utensili Public ReadOnly Property SetUpImage As String Get ' Cerco png Dim sImagePath As String = IniFile.m_sCurrMachSetUpDirPath & "\SetupImage.png" If File.Exists(sImagePath) Then Return sImagePath ' Cerco jpeg sImagePath = IniFile.m_sCurrMachSetUpDirPath & "\SetupImage.jpg" If File.Exists(sImagePath) Then Return sImagePath ' Cerco bmp sImagePath = IniFile.m_sCurrMachSetUpDirPath & "\SetupImage.bmp" If File.Exists(sImagePath) Then Return sImagePath ' Non trovato alcunché Return String.Empty End Get End Property #Region "Messages" Public ReadOnly Property TitleMsg As String Get Return EgtMsg(MSG_SETUP + 1) End Get End Property Public ReadOnly Property ApplyMsg As String Get Return EgtMsg(MSG_SETUP + 2) End Get End Property Public ReadOnly Property ArchiveMsg As String Get Return EgtMsg(MSG_SETUP + 3) End Get End Property Public ReadOnly Property RetrievesMsg As String Get Return EgtMsg(MSG_SETUP + 4) End Get End Property Public ReadOnly Property AutomaticMsg As String Get Return EgtMsg(MSG_SETUP + 5) End Get End Property #End Region ' Definizione comandi Private m_cmdApply As ICommand Private m_cmdArchive As ICommand Private m_cmdRetrieves As ICommand Private m_cmdAutomatic As ICommand Private m_cmdCloseSetUp As ICommand Private m_cmdToolDoubleClick As ICommand Sub New() ' rendo accessibile la lista posizioni a famiglie ed utensili per poterle attivare e disattivare ' (probabilmente da cambiare passandogli il riferimento alla creazione dell'utensile per non avere parametro shared) FamilyToolItem.m_PositionGroupList = m_PositionGroupList ToolItem.m_PositionGroupList = m_PositionGroupList ' rendo accessibile le liste utensili e posizioni alle uscite ExitToolAssociation.sh_ToolsList = m_ToolsList ExitToolAssociation.sh_PositionGroupList = m_PositionGroupList ' imposto il delegate che attiva e disattiva il bottone applica dall'uscita ExitToolAssociation.m_delIsEnabledBtns = AddressOf IsEnabledBtns ' carico lista utensili LoadMachineTools() ' carico lista posizioni LoadMachinePositions() ' Se esiste almeno una famiglia di utensili, la seleziono If ToolsList.Count > 0 Then ToolsList(0).IsSelected = True ToolsList(0).NotifyPropertyChanged("IsSelected") End If End Sub ''' ''' Method that search tools for the currently selected Machine and add it to the ToolsList. ''' Private Sub LoadMachineTools() ' Creo lista utensili utilizzati dal gruppo di lavorazione corrente Dim UsedToolList As New List(Of String) Dim Machining As Integer = EgtGetFirstOperation() While Machining <> GDB_ID.NULL If EgtGetOperationType(Machining) <> MCH_OY.DISP Then EgtSetCurrMachining(Machining) Dim Tuuid As String = String.Empty EgtGetMachiningParam(MCH_MP.TUUID, Tuuid) UsedToolList.Add(Tuuid) End If Machining = EgtGetNextOperation(Machining) End While ' Creo lista utensili per grafica Dim ActiveToolsFamilies() As ToolsFamily = MachineModel.ReadActiveToolsFamilies() For Index = 0 To ActiveToolsFamilies.Count - 1 Dim FamilyToolItem As New FamilyToolItem(ActiveToolsFamilies(Index).FamilyName, ActiveToolsFamilies(Index).FamilyId) m_ToolsList.Add(FamilyToolItem) Dim nType As Integer = 0 Dim ToolName As String = String.Empty Dim bFound As Boolean = EgtTdbGetFirstTool(ActiveToolsFamilies(Index).FamilyId, ToolName, nType) While bFound EgtTdbSetCurrTool(ToolName) Dim nValue As Integer = 0 Dim sValue As String = String.Empty EgtTdbGetCurrToolParam(MCH_TP.EXIT_, nValue) Dim ExitPar As String = nValue.ToString() EgtTdbGetCurrToolParam(MCH_TP.HEAD, sValue) Dim Head As String = sValue EgtTdbGetCurrToolParam(MCH_TP.TCPOS, sValue) Dim TcPos As String = sValue EgtTdbGetCurrToolParam(MCH_TP.UUID, sValue) Dim Uuid As String = sValue Dim IsInCurrMachGroup As Boolean = If(UsedToolList.Contains(Uuid), True, False) FamilyToolItem.Items.Add(New ToolItem(ToolName, ExitPar, nType, Head, TcPos, Uuid, IsInCurrMachGroup)) bFound = EgtTdbGetNextTool(ActiveToolsFamilies(Index).FamilyId, ToolName, nType) End While Next End Sub Private Sub LoadMachinePositions() ' recupero il gruppo del setup Dim nSetUpGroup As Integer = EgtGetCurrSetup() ' genero l'attrezzaggio dalla configurazione Lua Dim Index As Integer = 1 While CreateStdPosFromPosIndex(Index) Index += 1 End While Index -= 1 ' leggo l'attrezzaggio del progetto Dim sPosition As String = String.Empty Dim IniIndex As Integer = 1 ' recupero stringa di ogni posizione While EgtGetInfo(nSetUpGroup, K_POS & IniIndex, sPosition) If IniIndex <= Index Then ReadPositionString(IniIndex, sPosition, True) Else EgtRemoveInfo(nSetUpGroup, K_POS & IniIndex) End If IniIndex += 1 End While End Sub ' Funzione che dato l'indice di una posizione, la crea secondo il modello standard presente nello script Lua Private Function CreateStdPosFromPosIndex(Index As Integer) As Boolean Dim sTcPos As String = String.Empty Dim sHead As String = String.Empty Dim sGroup As String = String.Empty Dim nErr As Integer = 999 EgtLuaSetGlobIntVar("STU.INDEX", Index) EgtLuaCallFunction("STU.GetTcPosHeadGroupFromPos") ' Leggo variabili EgtLuaGetGlobStringVar("STU.TCPOS", sTcPos) EgtLuaGetGlobStringVar("STU.HEAD", sHead) EgtLuaGetGlobStringVar("STU.GROUP", sGroup) EgtLuaGetGlobIntVar("STU.ERR", nErr) ' se l'indice del gruppo è valido Dim nGroup As Integer = If(Integer.TryParse(sGroup.Trim("G"c), nGroup), nGroup, 0) If VerifyIndexValidity(nGroup) Then m_PositionGroupList(nGroup - 1).PositionList.Add(New Position(sTcPos, sHead, EgtGetHeadExitCount(sHead))) End If Return (nErr = 0) End Function ' funzione che mantiene le posizioni ma elimina tutti gli utensili attrezzati Private Sub ClearAllPos() For GroupIndex = 0 To m_PositionGroupList.Count - 1 For PositionIndex = 0 To m_PositionGroupList(GroupIndex).PositionList.Count - 1 For ExitIndex = 0 To m_PositionGroupList(GroupIndex).PositionList(PositionIndex).ExitToolAssociationList.Count - 1 Dim TempExit As ExitToolAssociation = m_PositionGroupList(GroupIndex).PositionList(PositionIndex).ExitToolAssociationList(ExitIndex) ' e lo tolgo dalla posizione di attrezzaggio TempExit.Tool = Nothing TempExit.IsOccupied = False Next Next Next End Sub ' Funzione che verifica che l'indice del gruppo sia valido, esista, e nel caso non esistesse aggiunge i gruppi necessari Private Function VerifyIndexValidity(nGroupIndex As Integer) As Boolean ' verifico che l'indice del gruppo sia valido If nGroupIndex >= 1 Then ' verifico che l'indice del gruppo sia compreso nel range di quelli esistenti If nGroupIndex <= m_PositionGroupList.Count Then Return True ' se l'indice è maggiore di quelli presenti nella lista dei gruppi Else ' aggiungo i gruppi che mancano fino all'indice del mio For GroupIndex = m_PositionGroupList.Count To nGroupIndex - 1 m_PositionGroupList.Add(New PositionGroup) Next Return True End If ' altrimenti Else ' mi assicuro che esista il primo gruppo VerifyIndexValidity(1) Return False End If End Function ' Funzione che dati l'indice della posizione e la sua stringa di attrezzaggio, carica l'attrezzaggio descritto Private Sub ReadPositionString(nIndex As Integer, sPosition As String, bOriginal As Boolean) Dim sTcPos As String = String.Empty Dim sHead As String = String.Empty Dim sExitList As New List(Of String) Dim sToolList As New List(Of String) ' la spezzo sui ; Dim sItems() As String = sPosition.Split(";".ToCharArray) ' se c'è almeno un elemento sono sicuro che ci sia la T If sItems.Count() >= 1 Then Dim nGroup As Integer = 0 sTcPos = sItems(0) ' recupero il suo gruppo If Not GetGroupFromTcPos(sTcPos, nGroup) Then ' se non lo trovo lo metto nel primo nGroup = 1 End If If Not VerifyIndexValidity(nGroup) Then ' se mi viene passato un indice non valido, lo metto nel primo nGroup = 1 End If ' se ci sono almeno due elementi sono sicuro che ci sia la H If sItems.Count >= 2 Then sHead = sItems(1) ' se ci sono almeno tre elementi sono sicuro che ci sia almeno un'uscita attrezzata If sItems.Count >= 3 Then ' separo le uscite divise dalla , Dim sExitToolAssList() As String = sItems(2).Split(",".ToCharArray) sExitList.Clear() sToolList.Clear() ' creo le liste di uscite e utensili attrezzati ricavati For AssIndex = 0 To sExitToolAssList.Count() - 1 Dim sExitToolAssItem() As String = sExitToolAssList(AssIndex).Split("/".ToCharArray) If sExitToolAssItem.Count > 1 Then sExitList.Add(sExitToolAssItem(0)) sToolList.Add(sExitToolAssItem(1)) End If Next ' analizzo la lista di utensili attrezzati For ToolIndex = 0 To sToolList.Count - 1 If Not String.IsNullOrEmpty(sToolList(ToolIndex)) Then Dim TempTool As ToolItem = Nothing Dim TempFamilyIndex As Integer = -1 Dim TempToolIndex As Integer = -1 Dim bToolFound As Boolean = False ' cerco l'utensile attrezzato nella lista utensili For FamilyListIndex = 0 To m_ToolsList.Count - 1 For ToolListIndex = 0 To m_ToolsList(FamilyListIndex).Items.Count - 1 TempTool = DirectCast(m_ToolsList(FamilyListIndex).Items(ToolListIndex), ToolItem) If TempTool.Uuid = sToolList(ToolIndex) Then TempFamilyIndex = FamilyListIndex TempToolIndex = ToolListIndex bToolFound = True Exit For End If Next If bToolFound Then Exit For Next ' se lo trovo If bToolFound Then ' cerco la relativa uscita Dim bFoundPos As Boolean = False For PositionIndex = 0 To m_PositionGroupList(nGroup - 1).PositionList.Count - 1 Dim TempPosition As Position = m_PositionGroupList(nGroup - 1).PositionList(PositionIndex) If TempPosition.TcPos = sTcPos Then bFoundPos = True ' verifico se la testa è diversa If TempPosition.Head <> sHead Then ' altrimenti la sovrascrivo TempPosition.Head = sHead ' e verifico il numero di uscite For ExitIndex = TempPosition.ExitToolAssociationList.Count + 1 To EgtGetHeadExitCount(sHead) TempPosition.ExitToolAssociationList.Add(New ExitToolAssociation(ExitIndex.ToString, TempPosition)) Next For ExitIndex = TempPosition.ExitToolAssociationList.Count - 1 To EgtGetHeadExitCount(sHead) Step -1 TempPosition.ExitToolAssociationList.RemoveAt(ExitIndex) Next End If For ExitIndex = 0 To TempPosition.ExitToolAssociationList.Count - 1 Dim CurrExitToolAss As ExitToolAssociation = TempPosition.ExitToolAssociationList(ExitIndex) If CurrExitToolAss.ExitPar = sExitList(ToolIndex) Then ' vi metto l'utensile e segno l'uscita come occupata CurrExitToolAss.Tool = TempTool CurrExitToolAss.IsOccupied = True CurrExitToolAss.NotifyPropertyChanged("ToolTipMsg") ' lo metto anche come utensile originale If bOriginal Then CurrExitToolAss.OrigTool = TempTool Exit For End If Next Exit For End If Next ' se posizione trovata, devo togliere l'utensile dalla lista utensili If bFoundPos Then m_ToolsList(TempFamilyIndex).Items.Remove(m_ToolsList(TempFamilyIndex).Items(TempToolIndex)) End If ' altrimenti, se non l'ho trovato Else Dim sSearchedTool As String = String.Empty EgtTdbGetToolFromUUID(sToolList(ToolIndex), sSearchedTool) If Not String.IsNullOrWhiteSpace(sSearchedTool) Then ' Impossibile trovare l'utensile xxx nel DB utensili MessageBox.Show(EgtMsg(MSG_SETUPERRORS + 3) & " " & sSearchedTool & " " & EgtMsg(MSG_SETUPERRORS + 4), EgtMsg(MSG_SETUPERRORS + 2), MessageBoxButton.OK, MessageBoxImage.Error) Else ' Impossibile trovare l'utensile nel DB utensili MessageBox.Show(EgtMsg(MSG_SETUPERRORS + 3) & " " & EgtMsg(MSG_SETUPERRORS + 4), EgtMsg(MSG_SETUPERRORS + 2), MessageBoxButton.OK, MessageBoxImage.Error) End If End If End If Next End If End If End If End Sub '' Funzione che dati l'indice della posizione e la sua stringa di attrezzaggio, carica l'attrezzaggio descritto 'Private Sub ReadPositionString(nIndex As Integer, sPosition As String) ' Dim sTcPos As String = String.Empty ' Dim sHead As String = String.Empty ' Dim sExitList As New List(Of String) ' Dim sToolList As New List(Of String) ' ' la spezzo sui ; ' Dim sItems() As String = sPosition.Split(";".ToCharArray) ' ' se c'è almeno un elemento sono sicuro che ci sia la T ' If sItems.Count() >= 1 Then ' Dim nGroup As Integer = 0 ' sTcPos = sItems(0) ' ' recupero il suo gruppo ' If Not GetGroupFromTcPos(sTcPos, nGroup) Then ' ' se non lo trovo lo metto nel primo ' nGroup = 1 ' End If ' If Not VerifyIndexValidity(nGroup) Then ' ' se mi viene passato un indice non valido, lo metto nel primo ' nGroup = 1 ' End If ' ' se ci sono almeno due elementi sono sicuro che ci sia la H ' If sItems.Count >= 2 Then ' sHead = sItems(1) ' m_PositionGroupList(nGroup - 1).PositionList.Add(New Position(sTcPos, sHead, EgtGetHeadExitCount(sHead))) ' ' se ci sono almeno tre elementi sono sicuro che ci sia almeno un'uscita attrezzata ' If sItems.Count >= 3 Then ' ' separo le uscite divise dalla , ' Dim sExitToolAssList() As String = sItems(2).Split(",".ToCharArray) ' sExitList.Clear() ' sToolList.Clear() ' ' creo le liste di uscite e utensili attrezzati ricavati ' For AssIndex = 0 To sExitToolAssList.Count() - 1 ' Dim sExitToolAssItem() As String = sExitToolAssList(AssIndex).Split("/".ToCharArray) ' If sExitToolAssItem.Count > 1 Then ' sExitList.Add(sExitToolAssItem(0)) ' sToolList.Add(sExitToolAssItem(1)) ' End If ' Next ' ' analizzo la lista di utensili attrezzati ' For ToolIndex = 0 To sToolList.Count - 1 ' If Not String.IsNullOrEmpty(sToolList(ToolIndex)) Then ' Dim TempTool As ToolItem = Nothing ' Dim bFound As Boolean = False ' ' cerco l'utensile attrezzato nella lista utensili ' For FamilyListIndex = 0 To m_ToolsList.Count - 1 ' For ToolListIndex = 0 To m_ToolsList(FamilyListIndex).Items.Count - 1 ' TempTool = DirectCast(m_ToolsList(FamilyListIndex).Items(ToolListIndex), ToolItem) ' If TempTool.Uuid = sToolList(ToolIndex) Then ' ' lo salvo in una variabile temporanea e lo tolgo dalla lista ' m_ToolsList(FamilyListIndex).Items.Remove(m_ToolsList(FamilyListIndex).Items(ToolListIndex)) ' bFound = True ' Exit For ' End If ' Next ' If bFound Then Exit For ' Next ' ' se lo trovo ' If bFound Then ' ' cerco la relativa uscita ' For ExitIndex = 0 To m_PositionGroupList(nGroup - 1).PositionList(m_PositionGroupList(nGroup - 1).PositionList.Count - 1).ExitToolAssociationList.Count - 1 ' Dim CurrExitToolAss As ExitToolAssociation = m_PositionGroupList(nGroup - 1).PositionList(m_PositionGroupList(nGroup - 1).PositionList.Count - 1).ExitToolAssociationList(ExitIndex) ' If CurrExitToolAss.ExitPar = sExitList(ToolIndex) Then ' ' vi metto l'utensile e segno l'uscita come occupata ' CurrExitToolAss.Tool = TempTool ' CurrExitToolAss.IsOccupied = True ' ' lo metto anche come utensile originale ' CurrExitToolAss.OrigTool = TempTool ' Exit For ' End If ' Next ' ' altrimenti, se non l'ho trovato ' Else ' Dim sSearchedTool As String = String.Empty ' EgtTdbGetToolFromUUID(sToolList(ToolIndex), sSearchedTool) ' MessageBox.Show(EgtMsg(MSG_SETUPERRORS + 3) & " " & sSearchedTool & " " & EgtMsg(MSG_SETUPERRORS + 4), EgtMsg(MSG_SETUPERRORS + 2), MessageBoxButton.OK, MessageBoxImage.Error) ' End If ' End If ' Next ' End If ' ' non è presente la H, quindi la recupero dal modello delle posizioni nel file MachIni ' Else ' CreateStdPosFromPosIndex(nIndex) ' End If ' End If 'End Sub ' Funzione che data una T restituisce il gruppo a cui appartiene Private Function GetGroupFromTcPos(sTcPos As String, ByRef nGroup As Integer) As Boolean Dim sGroup As String = String.Empty Dim nErr As Integer = 999 EgtLuaSetGlobStringVar("STU.TCPOS", sTcPos) EgtLuaCallFunction("STU.GetGroupFromTcPos") ' Leggo variabili EgtLuaGetGlobStringVar("STU.GROUP", sGroup) EgtLuaGetGlobIntVar("STU.ERR", nErr) If nErr = 0 Then nGroup = If(Integer.TryParse(sGroup.Trim("G"c), nGroup), nGroup, 0) Return True End If nGroup = 0 Return False End Function Private Function GetPositionFromTcPos(sTcPos As String, ByRef nPosIndex As Integer) As Boolean Dim sPosition As String = String.Empty Dim nErr As Integer = 999 EgtLuaSetGlobStringVar("STU.TCPOS", sTcPos) EgtLuaCallFunction("STU.GetPosFromTcPos") ' Leggo variabili EgtLuaGetGlobStringVar("STU.POS", sPosition) EgtLuaGetGlobIntVar("STU.ERR", nErr) If nErr = 0 Then nPosIndex = If(Integer.TryParse(sPosition.Replace("Pos", ""), nPosIndex), nPosIndex, -1) Return (nPosIndex >= 0) End If nPosIndex = -1 Return False End Function ' Funzione che verifica se ci sono state modifiche all'attrezzaggio corrente Private Function IsModifiedSetUp() As Boolean For GroupIndex = 0 To PositionGroupList.Count - 1 For PositionIndex = 0 To PositionGroupList(GroupIndex).PositionList.Count - 1 For ExitIndex = 0 To PositionGroupList(GroupIndex).PositionList(PositionIndex).ExitToolAssociationList.Count - 1 Dim CurrExitToolAss As ExitToolAssociation = PositionGroupList(GroupIndex).PositionList(PositionIndex).ExitToolAssociationList(ExitIndex) If CurrExitToolAss.m_IsModifiedTool Then Return True End If Next Next Next Return False End Function ' Funzione che verifica se ci sono state modifiche all'attrezzaggio corrente e permette di attivare e disattivare il bottone applica Private Sub IsEnabledBtns() m_IsEnabledApplyBtn = IsModifiedSetUp() NotifyPropertyChanged("IsEnabledApplyBtn") End Sub #Region "COMMANDS" #Region "ApplyCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property ApplyCommand As ICommand Get If m_cmdApply Is Nothing Then m_cmdApply = New Command(AddressOf Apply) End If Return m_cmdApply End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub Apply() ' ricavo il gruppo in cui mettere l'attrezzaggio Dim nSetUpGroup As Integer = EgtGetCurrSetup() For GroupIndex = 0 To m_PositionGroupList.Count - 1 For PositionIndex = 0 To m_PositionGroupList(GroupIndex).PositionList.Count - 1 Dim CurrPosition As Position = m_PositionGroupList(GroupIndex).PositionList(PositionIndex) Dim sPosition As String = String.Empty sPosition = CurrPosition.TcPos Dim sExitToolAssociation As String = String.Empty For ExitIndex = 0 To CurrPosition.ExitToolAssociationList.Count - 1 Dim CurrExitToolAss As ExitToolAssociation = CurrPosition.ExitToolAssociationList(ExitIndex) sExitToolAssociation &= If(CurrExitToolAss.IsOccupied, CurrExitToolAss.ExitPar & "/" & CurrExitToolAss.Tool.Uuid & "/" & CurrExitToolAss.Tool.Name & ",", String.Empty) CurrExitToolAss.OrigTool = CurrExitToolAss.Tool Next sExitToolAssociation = sExitToolAssociation.Trim(","c) If Not String.IsNullOrEmpty(sExitToolAssociation) Then sPosition &= ";" & CurrPosition.Head & ";" & sExitToolAssociation End If Dim nPosition As Integer If GetPositionFromTcPos(CurrPosition.TcPos, nPosition) Then EgtSetInfo(nSetUpGroup, K_POS & nPosition, sPosition) End If Next Next m_IsEnabledApplyBtn = False NotifyPropertyChanged("IsEnabledApplyBtn") ' aggiorno le librerie sottostanti EgtUpdateSetup() End Sub #End Region ' ApplyCommand #Region "ArchiveCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property ArchiveCommand As ICommand Get If m_cmdArchive Is Nothing Then m_cmdArchive = New Command(AddressOf Archive) End If Return m_cmdArchive End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub Archive(param As Object) ' Direttorio per attrezzaggi Dim sDir As String = IniFile.m_sMachinesRoot & "\" & IniFile.m_sMachineName & "\SetUp" Dim sPath As String = String.Empty If Not Directory.Exists(sDir) Then Try Directory.CreateDirectory(sDir) Catch ex As Exception EgtOutLog("Error in SetupDir creation " & ex.ToString()) Return End Try End If ' Apertura dialogo di salvataggio Dim SaveFileDialogView As New EgtWPFLib5.EgtSaveFileDialog SaveFileDialogView.Title = EgtMsg(MSG_SETUP + 3) & " " & EgtMsg(MSG_SETUP + 1) SaveFileDialogView.Extension = ".stu" SaveFileDialogView.Directory = sDir SaveFileDialogView.FileName = String.Empty If Not SaveFileDialogView.EgtShowDialog Then Return End If sPath = SaveFileDialogView.FileName ' creo il file con il solo commento come prima linea File.WriteAllLines(sPath, {"; Commento per evitare BOM con UTF-8"}, Text.Encoding.UTF8) For GroupIndex = 0 To m_PositionGroupList.Count - 1 For PositionIndex = 0 To m_PositionGroupList(GroupIndex).PositionList.Count - 1 Dim CurrPosition As Position = m_PositionGroupList(GroupIndex).PositionList(PositionIndex) Dim sPosition As String = String.Empty sPosition = CurrPosition.TcPos Dim sExitToolAssociation As String = String.Empty For AssIndex = 0 To CurrPosition.ExitToolAssociationList.Count - 1 sExitToolAssociation &= If(CurrPosition.ExitToolAssociationList(AssIndex).IsOccupied, CurrPosition.ExitToolAssociationList(AssIndex).ExitPar & "/" & CurrPosition.ExitToolAssociationList(AssIndex).Tool.Uuid & "/" & CurrPosition.ExitToolAssociationList(AssIndex).Tool.Name & ",", String.Empty) Next sExitToolAssociation = sExitToolAssociation.Trim(","c) If Not String.IsNullOrEmpty(sExitToolAssociation) Then sPosition &= ";" & CurrPosition.Head & ";" & sExitToolAssociation End If Dim nPosition As Integer If GetPositionFromTcPos(m_PositionGroupList(GroupIndex).PositionList(PositionIndex).TcPos, nPosition) Then EgtUILib.WritePrivateProfileString(S_GENERAL, K_POS & nPosition, sPosition, sPath) End If Next Next End Sub #End Region ' ArchiveCommand #Region "RetrievesCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property RetrievesCommand As ICommand Get If m_cmdRetrieves Is Nothing Then m_cmdRetrieves = New Command(AddressOf Retrieves) End If Return m_cmdRetrieves End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub Retrieves(param As Object) ' Direttorio per attrezzaggi Dim sDir As String = IniFile.m_sMachinesRoot & "\" & IniFile.m_sMachineName & "\SetUp" Dim sPath As String = String.Empty If Not Directory.Exists(sDir) Then EgtOutLog("Error in SetupDir retrieve : directory not found") Return End If ' Apertura dialogo di salvataggio Dim OpenFileDialogView As New EgtWPFLib5.EgtOpenFileDialog OpenFileDialogView.Title = EgtMsg(MSG_SETUP + 4) & " " & EgtMsg(MSG_SETUP + 1) OpenFileDialogView.Filter = "*.stu" OpenFileDialogView.Directory = sDir OpenFileDialogView.FileName = String.Empty If Not OpenFileDialogView.EgtShowDialog Then Return End If sPath = OpenFileDialogView.FileName ' resetto lista utensili e posizioni m_ToolsList.Clear() ClearAllPos() 'ricarico lista utensili LoadMachineTools() ' leggo l'attrezzaggio dal file scelto Dim sPosition As String = String.Empty Dim IniIndex As Integer = 1 ' recupero stringa di ogni posizione While EgtUILib.GetPrivateProfileString(S_GENERAL, K_POS & IniIndex, String.Empty, sPosition, sPath) > 0 ReadPositionString(IniIndex, sPosition, False) IniIndex += 1 End While ' verifico se disabilitare questa posizione in base all'utensile correntemente selezionato If Not TypeOf param Is ToolItem 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 Else Dim SelTool As ToolItem = DirectCast(param, ToolItem) ' 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(SelTool.Uuid) Next Next End If IsEnabledBtns() End Sub #End Region ' RetrievesCommand #Region "AutomaticCommand" ''' ''' Returns a command that do Exec. ''' Public ReadOnly Property AutomaticCommand As ICommand Get If m_cmdAutomatic Is Nothing Then m_cmdAutomatic = New Command(AddressOf Automatic) End If Return m_cmdAutomatic End Get End Property ''' ''' Execute the Exec. This method is invoked by the ExecCommand. ''' Public Sub Automatic(param As Object) ' verifico il tipo di elemento selezionato Dim bIsToolItem As Boolean = False Dim SelTool As ToolItem = Nothing If TypeOf param Is ToolItem Then SelTool = DirectCast(param, ToolItem) bIsToolItem = Not SelTool.IsInCurrMachGroup End If Dim ErrorList As New List(Of String) ' analizzo la lista degli utensili alla ricerca di quelli usati nel progetto corrente For FamilyIndex = 0 To m_ToolsList.Count - 1 ' verifico se nella famiglia c'è almeno un utensile usato nel progetto If m_ToolsList(FamilyIndex).HaveToolsInCurrMachGroup Then ' analizzo gli utensili all'interno della famiglia For ToolIndex = m_ToolsList(FamilyIndex).Items.Count - 1 To 0 Step -1 Dim CurrTool As ToolItem = DirectCast(m_ToolsList(FamilyIndex).Items(ToolIndex), ToolItem) ' se l'utensile è utilizzato If CurrTool.IsInCurrMachGroup Then ' lo attrezzo al suo posto predefinito AutoSetUpTool(CurrTool, ErrorList) End If Next End If Next ' verifico se ci sono errori If ErrorList.Count > 0 Then ' li raccolgo tutti nello stesso messaggio Dim sError As String = EgtMsg(MSG_SETUPERRORS + 6) & Environment.NewLine For ErrorIndex = 0 To ErrorList.Count - 1 sError &= "- " & ErrorList(ErrorIndex) & Environment.NewLine Next MessageBox.Show(sError, EgtMsg(MSG_SETUPERRORS + 2), MessageBoxButton.OK, MessageBoxImage.Exclamation) End If ' 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 If bIsToolItem Then m_PositionGroupList(GroupIndex).PositionList(PosIndex).SetIsValidPosFromTool(SelTool.uuid) Else m_PositionGroupList(GroupIndex).PositionList(PosIndex).SetNotValidPos() End If Next Next ' aggiorno lo stato del bottone applica IsEnabledBtns() End Sub #End Region ' AutomaticCommand #Region "CloseSetUpCommand" ''' ''' Returns a command that remove the current selected machining. ''' Public ReadOnly Property CloseSetUpCommand() As ICommand Get If m_cmdCloseSetUp Is Nothing Then m_cmdCloseSetUp = New RelayCommand(AddressOf CloseSetUp) End If Return m_cmdCloseSetUp End Get End Property ''' ''' Manage the MachiningDb closing. This method is invoked by the CloseMachiningDbCommand. ''' Public Sub CloseSetUp() ' Verifico se l'attrezzaggio è stato modificato If IsModifiedSetUp() Then ' se modificato chiedo se salvarlo prima di uscire If MessageBox.Show(EgtMsg(MSG_SETUP + 6), EgtMsg(MSG_SETUP + 2), MessageBoxButton.YesNo, MessageBoxImage.Question) = MessageBoxResult.Yes Then ' lo salvo Apply() End If End If ' Resetto tutti i delegate usati ExitToolAssociation.m_delIsEnabledBtns = Nothing ' Reset lua EgtLuaResetGlobVar("STU") ' Chiusura finestra For Each Window In Application.Current.Windows If TypeOf Window Is SetUpView Then Dim SetUpWindow As SetUpView = DirectCast(Window, SetUpView) SetUpWindow.Close() End If Next End Sub #End Region ' CloseSetUpCommand #Region "ToolDoubleClickCommand" ''' ''' Returns a command that do TreeViewDoubleClick. ''' Public ReadOnly Property ToolDoubleClickCommand As ICommand Get If m_cmdToolDoubleClick Is Nothing Then m_cmdToolDoubleClick = New RelayCommand(AddressOf ToolDoubleClick) End If Return m_cmdToolDoubleClick End Get End Property ''' ''' Execute the TreeViewDoubleClick. This method is invoked by the TreeViewDoubleClickCommand. ''' Public Sub ToolDoubleClick(ByVal param As Object) If TypeOf param Is ToolItem Then Dim SelTool As ToolItem = DirectCast(param, ToolItem) Dim ErrorList As New List(Of String) AutoSetUpTool(SelTool, ErrorList) ' verifico se ci sono errori If ErrorList.Count > 0 Then ' li raccolgo tutti nello stesso messaggio Dim sError As String = EgtMsg(MSG_SETUPERRORS + 6) & Environment.NewLine For ErrorIndex = 0 To ErrorList.Count - 1 sError &= "- " & ErrorList(ErrorIndex) & Environment.NewLine Next MessageBox.Show(sError, EgtMsg(MSG_SETUPERRORS + 2), MessageBoxButton.OK, MessageBoxImage.Exclamation) End If IsEnabledBtns() End If End Sub Private Function AutoSetUpTool(SelTool As ToolItem, ByRef ErrorList As List(Of String)) As Boolean ' cerco il TcPos dell'utensile selezionato nella lista di posizioni For GroupIndex = 0 To m_PositionGroupList.Count - 1 For PositionIndex = 0 To m_PositionGroupList(GroupIndex).PositionList.Count - 1 Dim CurrPosition As Position = m_PositionGroupList(GroupIndex).PositionList(PositionIndex) If CurrPosition.TcPos = SelTool.TcPos Then AutoSetUpToolFromPos(SelTool, CurrPosition, ErrorList) End If Next Next Return False End Function Private Function AutoSetUpToolFromPos(SelTool As ToolItem, Position As Position, ByRef ErrorList As List(Of String)) As Boolean Dim ExitToolAssociationList As ObservableCollection(Of ExitToolAssociation) = Position.ExitToolAssociationList EgtLuaSetGlobStringVar("STU.TUUID", SelTool.Uuid) EgtLuaSetGlobStringVar("STU.TCPOS", Position.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: " & Position.TcPos) Return False 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, restituisco errore If sHead = INVALIDPOS Then EgtOutLog("SetUp warning: try to set " & SelTool.Name & " on " & Position.TcPos) MessageBox.Show(EgtMsg(MSG_SETUPERRORS + 5), EgtMsg(MSG_SETUPERRORS + 1), MessageBoxButton.OK, MessageBoxImage.Error) Return False ' altrimenti, se la posizione nell'attrezzaggio è vuota ElseIf Not PosIsOccupied Then ' verifico se la testa è la stessa If Not Position.Head = sHead Then ' altrimenti la sovrascrivo Position.Head = sHead ' e verifico il numero di uscite For ExitIndex = Position.ExitToolAssociationList.Count + 1 To EgtGetHeadExitCount(sHead) Position.ExitToolAssociationList.Add(New ExitToolAssociation(ExitIndex.ToString, Position)) Next For ExitIndex = Position.ExitToolAssociationList.Count - 1 To EgtGetHeadExitCount(sHead) Step -1 Position.ExitToolAssociationList.RemoveAt(ExitIndex) Next End If ' lo aggiungo alla posizione di attrezzaggio e lo tolgo dalla lista utensili SetToolInPos(SelTool, Position, nExit) ' altrimenti, se le teste coincidono ElseIf sHead = Position.Head Then ' se l'uscita restituita è libera If Not ExitToolAssociationList(nExit - 1).IsOccupied Then ' lo aggiungo alla posizione di attrezzaggio e lo tolgo dalla lista utensili SetToolInPos(SelTool, Position, nExit) ' altrimenti restituisco falso Else ErrorList.Add(SelTool.Name) 'MessageBox.Show(EgtMsg(MSG_SETUPERRORS + 9) & " " & SelTool.Name & " " & EgtMsg(MSG_SETUPERRORS + 6), EgtMsg(MSG_SETUPERRORS + 2), MessageBoxButton.OK, MessageBoxImage.Exclamation) Return False End If ' altrimenti restituisco falso Else ErrorList.Add(SelTool.Name) 'MessageBox.Show(EgtMsg(MSG_SETUPERRORS + 9) & " " & SelTool.Name & " " & EgtMsg(MSG_SETUPERRORS + 6), EgtMsg(MSG_SETUPERRORS + 2), MessageBoxButton.OK, MessageBoxImage.Exclamation) Return False End If Return True End Function Private Function SetToolInPos(SelTool As ToolItem, Position As Position, nExit As Integer) As Boolean Dim bOk As Boolean = False ' lo aggiungo alla posizione di attrezzaggio For ExitIndex = 0 To Position.ExitToolAssociationList.Count - 1 If ExitIndex = nExit - 1 Then Position.ExitToolAssociationList(ExitIndex).Tool = SelTool Position.ExitToolAssociationList(ExitIndex).IsOccupied = True Position.ExitToolAssociationList(ExitIndex).NotifyPropertyChanged("ToolTipMsg") bOk = True Exit For End If Next If Not bOk Then Return False bOk = False ' e lo tolgo dalla lista utensili For Index = 0 To m_ToolsList.Count - 1 If (SelTool.Type And m_ToolsList(Index).Type) > 0 Then m_ToolsList(Index).Items.Remove(SelTool) bOk = True Exit For End If Next Return bOk End Function #End Region ' ToolDoubleClickCommand #End Region ' Commands Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged Public Sub NotifyPropertyChanged(propName As String) RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propName)) End Sub End Class End Namespace 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 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 ' 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 ' altrimenti le disattivo tutte 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 If bIsValid 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 Else 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.Head = Head For ExitIndex = 1 To ExitNum ExitToolAssociationList.Add(New ExitToolAssociation(ExitIndex.ToString, Me)) Next End Sub End Class Public Class ExitToolAssociation Implements INotifyPropertyChanged ' 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_delIsEnabledBtns 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 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_IsModifiedTool = False 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 m_IsModifiedTool = m_Tool IsNot m_OrigTool NotifyPropertyChanged("Tool") End Set End Property #Region "Messages" Public ReadOnly Property ToolTipMsg As String Get 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 m_delIsEnabledBtns() End Sub #End Region ' SetUpToolCommand #End Region ' Commands Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged Public Sub NotifyPropertyChanged(propName As String) RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propName)) End Sub 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