Files
EgtWPFLib5/ToolDbWindow/ToolDbWindowVM.vb
T
Renzo Lanza be2fa8bc2b EgtWPFLib5 2.2f5 :
- aggiunti messaggi di errore sulle Operazioni (come per Db Lav.)
- Cambio colore pulsante "Applica Lavorazioni" in caso di modifica e errore
- MessageBox che elenca errori prevista premendo "Applica Lavorazioni" con errori
- Variabile m_MatType spostata in MachiningTreeView e nuova gestione della stessa per Db Lav. e Operazioni (correzioni anche in ToolDbWindow)
- Correzione gestione Messaggi in base al Materiale della Macchina
2020-06-17 14:46:48 +00:00

892 lines
32 KiB
VB.net

Imports System.Windows.Forms.Integration
Imports System.Collections.ObjectModel
Imports System.Reflection
Imports System.IO
Imports EgtUILib
Imports EgtWPFLib5
Public Class ToolDbWindowVM
Inherits VMBase
Private Const SETUP_FILEEXTENSION As String = ".stu"
Friend Shared m_bActive As Boolean = False
Friend Shared m_ProjectSceneContext As Integer = 0
Public Shared ReadOnly Property ProjectSceneContext As Integer
Get
Return m_ProjectSceneContext
End Get
End Property
Friend Shared m_ToolDbSceneContext As Integer = 0
Friend Shared m_sToolMakersDirPath As String = String.Empty
Friend Shared m_sMachineIniPath As String = String.Empty
Friend Shared m_sScriptDirPath As String = String.Empty
Friend Shared m_sToolDirPath As String = String.Empty
Friend Shared m_MatType As MaterialType = Nothing
Public Property MatType As MaterialType
Get
Return m_MatType
End Get
Set(value As MaterialType)
m_MatType = value
End Set
End Property
Private m_Title As String
Public ReadOnly Property Title As String
Get
Return EgtMsg(MSG_MAINWINDOW + 3)
End Get
End Property
' Lista degli utensili
Private m_ToolsList As New ObservableCollection(Of FamilyToolTreeViewItem)
Public Property ToolsList As ObservableCollection(Of FamilyToolTreeViewItem)
Get
Return m_ToolsList
End Get
Set(value As ObservableCollection(Of FamilyToolTreeViewItem))
m_ToolsList = value
End Set
End Property
Private m_IsEnabledNewBtn As Boolean
Public ReadOnly Property IsEnabledNewBtn As Boolean
Get
Return m_IsEnabledNewBtn
End Get
End Property
Private m_IsEnabledSaveBtn As Boolean
Public ReadOnly Property IsEnabledSaveBtn As Boolean
Get
Return m_IsEnabledSaveBtn
End Get
End Property
Private m_IsEnabledRemoveBtn As Boolean
Public ReadOnly Property IsEnabledRemoveBtn As Boolean
Get
Return m_IsEnabledRemoveBtn
End Get
End Property
Dim StoneDrillToolParamPageV As StoneDrillParamPageV
Dim WoodDrillToolParamPageV As WoodDrillParamPageV
Dim StoneSawToolParamPageV As StoneSawParamPageV
Dim WoodSawToolParamPageV As WoodSawParamPageV
Dim StoneMillToolParamPageV As StoneMillParamPageV
Dim WoodMillToolParamPageV As WoodMillParamPageV
Dim BeamMillToolParamPageV As BeamMillParamPageV
Dim ChiselToolParamPageV As ChiselParamPageV
Dim MortiseToolParamPageV As MortiseParamPageV
Dim WaterjetToolParamPageV As WaterjetParamPageV
Public ReadOnly Property ParamPageV As ContentControl
Get
Dim selToolFamily As FamilyToolTreeViewItem = Nothing
Dim selTool As ToolTreeViewItem = Nothing
Dim selToolFamilyType As Integer = 0
For Each ToolFamily In ToolsList
For Each Tool In ToolFamily.Items
If Tool.IsSelected Then
selTool = DirectCast(Tool, ToolTreeViewItem)
Exit For
End If
Next
If Not IsNothing(selTool) Then
selToolFamilyType = ToolFamily.ToolType
Exit For
End If
Next
' disattivo disegno utensile
ToolTreeViewItem.SuspendToolDrawUpdate = True
StoneDrillToolParamPageV.DataContext = Nothing
WoodDrillToolParamPageV.DataContext = Nothing
StoneSawToolParamPageV.DataContext = Nothing
WoodSawToolParamPageV.DataContext = Nothing
StoneMillToolParamPageV.DataContext = Nothing
WoodMillToolParamPageV.DataContext = Nothing
BeamMillToolParamPageV.DataContext = Nothing
MortiseToolParamPageV.DataContext = Nothing
ChiselToolParamPageV.DataContext = Nothing
WaterjetToolParamPageV.DataContext = Nothing
Select Case selToolFamilyType
Case MCH_TF.DRILLBIT
If m_MatType = MaterialType.STONE Then
StoneDrillToolParamPageV.DataContext = selTool
Return StoneDrillToolParamPageV
ElseIf m_MatType = MaterialType.WOOD Or m_MatType = MaterialType.BEAM Then
WoodDrillToolParamPageV.DataContext = selTool
Return WoodDrillToolParamPageV
End If
Case MCH_TF.SAWBLADE
If m_MatType = MaterialType.STONE Then
StoneSawToolParamPageV.DataContext = selTool
Return StoneSawToolParamPageV
ElseIf m_MatType = MaterialType.WOOD Or m_MatType = MaterialType.BEAM Then
WoodSawToolParamPageV.DataContext = selTool
Return WoodSawToolParamPageV
End If
Case MCH_TF.MILL
If m_MatType = MaterialType.STONE Then
StoneMillToolParamPageV.DataContext = selTool
Return StoneMillToolParamPageV
ElseIf m_MatType = MaterialType.WOOD Then
WoodMillToolParamPageV.DataContext = selTool
Return WoodMillToolParamPageV
ElseIf m_MatType = MaterialType.BEAM Then
BeamMillToolParamPageV.DataContext = selTool
Return BeamMillToolParamPageV
End If
Case MCH_TF.MORTISE
MortiseToolParamPageV.DataContext = selTool
Return MortiseToolParamPageV
Case MCH_TF.CHISEL
ChiselToolParamPageV.DataContext = selTool
Return ChiselToolParamPageV
Case MCH_TF.WATERJET
WaterjetToolParamPageV.DataContext = selTool
Return WaterjetToolParamPageV
End Select
' riattivo disegno utensile
ToolTreeViewItem.SuspendToolDrawUpdate = False
Return Nothing
End Get
End Property
'PROJECT PAGE'S SCENE FIELDS AND PROPERTIES
' Reference to the ProjectScene
Private WithEvents m_ToolScene As New Scene
' Reference to the ProjectSceneHost
Private SceneHost As WindowsFormsHost
' Property used to bind the scene to the WindowsFormsHost in XAML
Private m_bfirst As Boolean = True
Public ReadOnly Property ToolSceneHost As WindowsFormsHost
Get
If m_bfirst Then
SceneHost = New WindowsFormsHost() With {.Child = m_ToolScene}
If Not m_ToolScene.Init() Then
EgtOutLog("Error in Tool scene creation")
'Application.Msn.NotifyColleagues(Application.CLOSEAPPLICATION)
End If
m_ToolDbSceneContext = m_ToolScene.GetCtx()
' inibisco selezione diretta da Scene
m_ToolScene.SetStatusNull()
'OnPropertyChanged("SelectedMachine")
m_bfirst = False
End If
Return SceneHost
End Get
End Property
' visibilità parametro Active
Private m_Active_Visibility As Boolean
Public ReadOnly Property Active_Visibility As Visibility
Get
Return If(m_Active_Visibility, Visibility.Visible, Visibility.Collapsed)
End Get
End Property
Public Overridable Sub OnCursorPos(ByVal sender As Object, ByVal sCursorPos As String) Handles m_ToolScene.OnCursorPos
LibMap.refStatusBarVM.SetCurrPos(sCursorPos)
End Sub
' Definizione comandi
Private m_cmdNew As ICommand
Private m_cmdSave As ICommand
Private m_cmdRemove As ICommand
Private m_cmdReloadTool As ICommand
Private m_cmdCloseToolsDb As ICommand
#Region "MESSAGES"
'Definizione dei messaggi della pagina
Public ReadOnly Property NewMsg As String
Get
Return EgtMsg(31701)
End Get
End Property
Public ReadOnly Property SaveMsg As String
Get
Return EgtMsg(31702)
End Get
End Property
Public ReadOnly Property RemoveMsg As String
Get
Return EgtMsg(31703)
End Get
End Property
Public ReadOnly Property CorrTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 51)
End Get
End Property
Public ReadOnly Property ExitParTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 52)
End Get
End Property
Public ReadOnly Property TypeTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 53)
End Get
End Property
Public ReadOnly Property CoolantTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 54)
End Get
End Property
Public ReadOnly Property CornRadTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 55)
End Get
End Property
Public ReadOnly Property DiamTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 56)
End Get
End Property
Public ReadOnly Property TotDiamTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 57)
End Get
End Property
Public ReadOnly Property FeedTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 58)
End Get
End Property
Public ReadOnly Property EndFeedTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 59)
End Get
End Property
Public ReadOnly Property StartFeedTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 60)
End Get
End Property
Public ReadOnly Property LenTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 62)
End Get
End Property
Public ReadOnly Property TotLenTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 63)
End Get
End Property
Public ReadOnly Property MaxMatTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 64)
End Get
End Property
Public ReadOnly Property LonOffsetTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 65)
End Get
End Property
Public ReadOnly Property RadOffsetTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 66)
End Get
End Property
Public ReadOnly Property SpeedTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 67)
End Get
End Property
Public ReadOnly Property SideAngTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 68)
End Get
End Property
Public ReadOnly Property MaxSpeedTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 69)
End Get
End Property
Public ReadOnly Property ThickTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 70)
End Get
End Property
Public ReadOnly Property MaxAbsorptionTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 71)
End Get
End Property
Public ReadOnly Property MinFeedTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 72)
End Get
End Property
Public ReadOnly Property DrawTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 73)
End Get
End Property
Public ReadOnly Property HeadTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 74)
End Get
End Property
Public ReadOnly Property NameParTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 75)
End Get
End Property
Public ReadOnly Property UserNotesTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 76)
End Get
End Property
Public ReadOnly Property TcPosTxBl As String
Get
Return EgtMsg(MSG_TOOLDB + 77)
End Get
End Property
#End Region
#Region "CONSTRUCTOR"
Sub New(sMachineDirPath As String, sMachineIniPath As String, ProjectSceneContext As Integer, Optional sMatType As String = "Wood")
m_bActive = True
m_ProjectSceneContext = ProjectSceneContext
m_sMachineIniPath = sMachineIniPath
m_sScriptDirPath = sMachineDirPath & "\Scripts"
m_sToolDirPath = sMachineDirPath & "\Tools"
' leggo direttorio toolmakers
GetMainPrivateProfileString(S_MACH, K_TOOLMAKERSDIR, "", m_sToolMakersDirPath)
EgtUILib.GetPrivateProfileString(S_GENERAL, K_MATERIAL, "Wood", sMatType, sMachineIniPath)
Select Case sMatType
Case "Stone"
m_MatType = MaterialType.STONE
Case "Wood"
m_MatType = MaterialType.WOOD
Case "Beam"
m_MatType = MaterialType.BEAM
Case Else
' Se il materiale spcificato nel file INI della macchina non corrisponde ai 2 sopracitati viene emesso un messaggio di errore
m_MatType = Nothing
MsgBox(EgtMsg(31409), MsgBoxStyle.Exclamation, EgtMsg(31551))
Exit Sub
End Select
' Passo all'item della lista il delegato alla funzione che permette di cancellare una lavorazione
ToolTreeViewItem.m_delRemoveTool = AddressOf RemoveTool
' Passo all'item della lista il delegato alla funzione che permette di disattivare la lista delle lavorazioni
ToolTreeViewItem.m_delErrorOnTool = AddressOf ErrorOnTool
FamilyToolTreeViewItem.m_delErrorOnTool = AddressOf ErrorOnTool
' Passo all'item della lista il delegato alla funzione che permette di disattivare la lista delle lavorazioni
ToolTreeViewItem.m_delIsEnabledBtns = AddressOf IsEnabledBtns
FamilyToolTreeViewItem.m_delIsEnabledBtns = AddressOf IsEnabledBtns
ToolTreeViewItem.m_delNotifyPropertyChanged = AddressOf ccc
FamilyToolTreeViewItem.m_delNotifyPropertyChanged = AddressOf ccc
' Passo all'item della lista il delegato alla funzione che restituisce l'utensile selezionato
ToolTreeViewItem.m_delGetSelectedTool = AddressOf GetSelectedTool
LoadSelectedMachineTools()
' carico Lua che contiene le funzioni di attrezzaggio
EgtSetCurrentContext( ToolDbWindowVM.m_ProjectSceneContext)
Dim bScriptFileExec As Boolean = EgtLuaExecFile( m_sScriptDirPath & "\SetUp.lua")
' carico lista teste
ToolTreeViewItem.m_HeadList.Clear()
Dim sHeads As String = String.Empty
EgtSetCurrentContext(ToolDbWindowVM.m_ProjectSceneContext)
If EgtGetAllHeadsNames(sHeads) Then
Dim sHeadList() As String = sHeads.Split(","c)
For HeadIndex = 0 To sHeadList.Count - 1
If bScriptFileExec Then
' Verifico che la testa sia valida
EgtLuaSetGlobStringVar("STU.HEAD", sHeadList(HeadIndex))
If EgtLuaCallFunction("STU.IsValidHead") Then
' Leggo variabili
Dim IsValidHead As Boolean = False
EgtLuaGetGlobBoolVar("STU.ISVALID", IsValidHead)
If Not IsValidHead Then Continue For
End If
End If
' Cerco messaggio per questa testa
Dim sHText As String = String.Empty
EgtUILib.GetPrivateProfileString(S_HEADS, sHeadList(HeadIndex), "", sHText, m_sMachineIniPath)
Dim sHTextMsg As String = String.Empty
If IsNumeric(sHText) Then
sHTextMsg = EgtMsg(CInt(sHText))
If sHTextMsg = ("Msg" & CInt(sHText)) Then
sHTextMsg = sHText
End If
Else
sHTextMsg = sHText
End If
sHTextMsg &= " (" & sHeadList(HeadIndex) & ")"
ToolTreeViewItem.m_HeadList.Add(New HeadItem(sHeadList(HeadIndex), sHTextMsg))
Next
Else
MessageBox.Show("Impossible loading Head list from machine!", "Error", MessageBoxButton.OK, MessageBoxImage.Error)
EgtOutLog("Error: Impossible loading Head list from machine!")
End If
ToolTreeViewItem.m_OrigTcPosList.Clear()
If bScriptFileExec Then
' creo lista di tutti i TcPos
Dim nPosIndex As Integer = 1
Dim sTcPos As String = String.Empty
Dim nErr As Integer = 0
While nErr = 0
EgtLuaSetGlobIntVar("STU.INDEX", nPosIndex)
If Not EgtLuaCallFunction("STU.GetTcPosFromPos") Then Exit While
' Leggo variabili
EgtLuaGetGlobStringVar("STU.TCPOS", sTcPos)
If Not EgtLuaGetGlobIntVar("STU.ERR", nErr) Then nErr = 999
If nErr = 0 Then
ToolTreeViewItem.m_OrigTcPosList.Add(sTcPos)
End If
nPosIndex += 1
End While
End If
If Not bScriptFileExec Then
MessageBox.Show(EgtMsg(MSG_TOOLDBERRORS + 25), EgtMsg(MSG_TOOLDBERRORS + 26), MessageBoxButton.OK, MessageBoxImage.Error)
EgtOutLog("Error: SetUp configuration file not found!")
End If
' leggo da ini se parametro Active è attivo
m_Active_Visibility = (EgtUILib.GetPrivateProfileInt(S_TOOLS, K_ACTIVE, 0, m_sMachineIniPath) <> 0)
StoneDrillToolParamPageV = New StoneDrillParamPageV
WoodDrillToolParamPageV = New WoodDrillParamPageV
StoneSawToolParamPageV = New StoneSawParamPageV
WoodSawToolParamPageV = New WoodSawParamPageV
StoneMillToolParamPageV = New StoneMillParamPageV
WoodMillToolParamPageV = New WoodMillParamPageV
BeamMillToolParamPageV = New BeamMillParamPageV
MortiseToolParamPageV = New MortiseParamPageV
ChiselToolParamPageV = New ChiselParamPageV
WaterjetToolParamPageV = New WaterjetParamPageV
NotifyPropertyChanged("ParamPageV")
End Sub
#End Region ' Constructor
#Region "METHODS"
Private Sub ccc()
NotifyPropertyChanged("ParamPageV")
End Sub
Private Sub IsEnabledBtns(bIsEnabledNewBtn As Boolean, bIsEnabledSaveBtn As Boolean, bIsEnabledDeleteBtn As Boolean)
m_IsEnabledNewBtn = bIsEnabledNewBtn
m_IsEnabledSaveBtn = bIsEnabledSaveBtn
m_IsEnabledRemoveBtn = bIsEnabledDeleteBtn
NotifyPropertyChanged("IsEnabledNewBtn")
NotifyPropertyChanged("IsEnabledSaveBtn")
NotifyPropertyChanged("IsEnabledRemoveBtn")
End Sub
' Quando chiamato, disattiva tutti gli item dell'albero o li riattiva a seconda che ci sia o meno un errore
Private Sub ErrorOnTool(bIsEnabled As Boolean)
For Each FamilyToolItem In ToolsList
FamilyToolItem.IsEnabled = Not bIsEnabled
Next
End Sub
''' <summary>
''' Method that search tools for the currently selected Machine and add it to the ToolsList.
''' </summary>
Private Sub LoadSelectedMachineTools()
Dim ActiveToolsFamilies() As ToolsFamily = MachineUtility.ReadToolFamilies(m_sMachineIniPath)
For Each ToolsFamily In ActiveToolsFamilies
Dim FamilyTreeView As New FamilyToolTreeViewItem(ToolsFamily.Name, ToolsFamily.Id)
ToolsList.Add(FamilyTreeView)
Dim nType As Integer = 0
Dim ToolName As String = String.Empty
EgtSetCurrentContext(ToolDbWindowVM.m_ProjectSceneContext)
If EgtTdbGetFirstTool(ToolsFamily.Id, ToolName, nType) Then
FamilyTreeView.Items.Add(New ToolTreeViewItem(ToolName))
While EgtTdbGetNextTool(ToolsFamily.Id, ToolName, nType)
FamilyTreeView.Items.Add(New ToolTreeViewItem(ToolName))
End While
End If
Next
' 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
Private Function GetSelectedTool() As ToolTreeViewItem
For Each ToolFamily In m_ToolsList
For Each Tool In ToolFamily.Items
If Tool.m_IsSelected Then
Return DirectCast(Tool, ToolTreeViewItem)
End If
Next
Next
Return Nothing
End Function
' Funzione che aggiorna setup default con tool che hanno parametro Active
' (deve essere sovrascitta se il programma prevede l'uso del parametro Active)
Public Overridable Function UpdateDefSetup() As Boolean
Return True
End Function
#End Region ' Methods
#Region "COMMANDS"
#Region "NewCommand"
''' <summary>
''' Returns a command that create a new tool.
''' </summary>
Public ReadOnly Property NewCommand As ICommand
Get
If m_cmdNew Is Nothing Then
m_cmdNew = New Command(AddressOf NewPar)
End If
Return m_cmdNew
End Get
End Property
''' <summary>
''' Creata the new tool. This method is invoked by the NewCommand.
''' </summary>
Public Overridable Sub NewPar(ByVal param As Object)
EgtSetCurrentContext(ToolDbWindowVM.m_ProjectSceneContext)
' Verifico se sia selezionata una famiglia
Dim NewToolItem As ToolTreeViewItem
If TypeOf param Is FamilyToolTreeViewItem Then
Dim ToolFamily As FamilyToolTreeViewItem = DirectCast(param, FamilyToolTreeViewItem)
Dim NewName As String = ToolFamily.Name
EgtTdbGetToolNewName(NewName)
If EgtTdbAddTool(NewName, ToolFamily.ToolType) Then
NewToolItem = New ToolTreeViewItem(NewName)
ToolFamily.Items.Add(NewToolItem)
EgtTdbSaveCurrTool()
NewToolItem.NewTool = True
' Determino il tipo di utensile
Dim nType As Integer
EgtTdbGetCurrToolParam(MCH_TP.TYPE, nType)
Dim bSaw As Boolean = ((nType And MCH_TF.SAWBLADE) <> 0)
' Imposto testa e uscita
' Sempre lame su H1.1 e altri utensili su H1.2
EgtTdbSetCurrToolParam(MCH_TP.HEAD, "H1")
EgtTdbSetCurrToolParam(MCH_TP.EXIT_, If(bSaw, 1, 2))
' Per macchine senza ToolChanger, resetto la posizione su questo
If CurrentMachine.ShowToolChanger = 0 Then
EgtTdbSetCurrToolParam(MCH_TP.TCPOS, "")
End If
' Imposto dimensioni standard
If (nType And MCH_TF.DRILLBIT) <> 0 Then
EgtTdbSetCurrToolParam(MCH_TP.LEN, 80.0)
EgtTdbSetCurrToolParam(MCH_TP.TOTLEN, 80.0)
EgtTdbSetCurrToolParam(MCH_TP.DIAM, 20.0)
EgtTdbSetCurrToolParam(MCH_TP.TOTDIAM, 20.0)
EgtTdbSetCurrToolParam(MCH_TP.MAXMAT, 40.0)
ElseIf (nType And MCH_TF.SAWBLADE) <> 0 Then
EgtTdbSetCurrToolParam(MCH_TP.LEN, 80.0)
EgtTdbSetCurrToolParam(MCH_TP.TOTLEN, 80.0)
EgtTdbSetCurrToolParam(MCH_TP.DIAM, 600.0)
EgtTdbSetCurrToolParam(MCH_TP.TOTDIAM, 600.0)
EgtTdbSetCurrToolParam(MCH_TP.THICK, 5.0)
EgtTdbSetCurrToolParam(MCH_TP.MAXMAT, 40.0)
ElseIf (nType And MCH_TF.MILL) <> 0 Then
EgtTdbSetCurrToolParam(MCH_TP.LEN, 80.0)
EgtTdbSetCurrToolParam(MCH_TP.TOTLEN, 80.0)
EgtTdbSetCurrToolParam(MCH_TP.DIAM, 20.0)
EgtTdbSetCurrToolParam(MCH_TP.TOTDIAM, 20.0)
EgtTdbSetCurrToolParam(MCH_TP.MAXMAT, 40.0)
End If
' Salvo e aggiorno interfaccia utente
EgtTdbSaveCurrTool()
' Seleziono il nuovo utensile
If Not ToolFamily.IsExpanded Then ToolFamily.IsExpanded = True
NewToolItem.IsSelected = True
NewToolItem.NotifyPropertyChanged("IsSelected")
End If
' Verifico se sia selezionato un utensile
ElseIf TypeOf param Is ToolTreeViewItem Then
Dim ToolCopied As ToolTreeViewItem = DirectCast(param, ToolTreeViewItem)
Dim NewName As String = ToolCopied.Name
EgtTdbGetToolNewName(NewName)
If EgtTdbCopyTool(ToolCopied.Name, NewName) Then
' Elimino disegno che non deve essere copiato
EgtTdbSetCurrToolParam(MCH_TP.DRAW, String.Empty)
Dim CurrType As Integer
EgtTdbGetCurrToolParam(MCH_TP.TYPE, CurrType)
For Each ToolFamily In ToolsList
If (ToolFamily.ToolType And CurrType) <> 0 Then
NewToolItem = New ToolTreeViewItem(NewName)
ToolFamily.Items.Add(NewToolItem)
EgtTdbSaveCurrTool()
NewToolItem.NewTool = True
' Reimposto l'utensile vecchio nel Db per deselezionarlo e fare le verifiche correttamente
EgtTdbSetCurrTool(ToolCopied.Name)
ToolCopied.IsSelected = False
ToolCopied.NotifyPropertyChanged("IsSelected")
NewToolItem.IsSelected = True
Exit For
End If
Next
End If
End If
End Sub
#End Region ' NewCommand
#Region "SaveCommand"
''' <summary>
''' Returns a command that save the current selected tool.
''' </summary>
Public ReadOnly Property SaveCommand() As ICommand
Get
If m_cmdSave Is Nothing Then
m_cmdSave = New Command(AddressOf Save)
End If
Return m_cmdSave
End Get
End Property
''' <summary>
''' Saves the current tool. This method is invoked by the SaveCommand.
''' </summary>
Public Sub Save(ByVal param As Object)
Dim CurrTool As ToolTreeViewItem = DirectCast(param, ToolTreeViewItem)
CurrTool.WriteToolParam()
CurrTool.m_Name = CurrTool.m_Name.Trim()
CurrTool.WriteToolName()
EgtTdbSaveCurrTool()
CurrTool.NewTool = False
CurrTool.IsModifiedReset()
IsEnabledBtns(CurrTool.IsValid And Not CurrTool.IsModified, CurrTool.IsValid, True)
End Sub
#End Region ' SaveCommand
#Region "RemoveCommand"
''' <summary>
''' Returns a command that remove the current selected tool.
''' </summary>
Public ReadOnly Property RemoveCommand() As ICommand
Get
If m_cmdRemove Is Nothing Then
m_cmdRemove = New Command(AddressOf Remove)
End If
Return m_cmdRemove
End Get
End Property
''' <summary>
''' Remove the current selected tools from Db and TreeView. This method is invoked by the RemoveCommand.
''' </summary>
Public Sub Remove(ByVal param As Object)
EgtSetCurrentContext(ToolDbWindowVM.m_ProjectSceneContext)
Dim ToolToRemove As ToolTreeViewItem = DirectCast(param, ToolTreeViewItem)
' Verifico se questo utensile viene utilizzato da qualche lavorazione
Dim UsingMachining As New List(Of String)
Dim ActiveMachiningsTypes() As MachiningsType = MachineUtility.ReadMachiningFamilies(m_sMachineIniPath)
For Each MachiningsType In ActiveMachiningsTypes
Dim MachiningName As String = String.Empty
EgtMdbGetFirstMachining(MachiningsType.Id, MachiningName)
While Not String.IsNullOrWhiteSpace(MachiningName)
' recupero tuuid
EgtMdbSetCurrMachining(MachiningName)
Dim sCurrMachTUUID As String = String.Empty
EgtMdbGetCurrMachiningParam(MCH_MP.TUUID, sCurrMachTUUID)
If sCurrMachTUUID = ToolToRemove.Uuid Then
UsingMachining.Add(MachiningName)
End If
EgtMdbGetNextMachining(MachiningsType.Id, MachiningName)
End While
Next
Dim MessageBoxText As String = EgtMsg(MSG_TOOLDBERRORS + 22) & " " & ToolToRemove.Name & EgtMsg(MSG_TOOLDBERRORS + 23)
If UsingMachining.Count > 0 Then
MessageBoxText &= "This is the list of Machining that use this tool:" & Environment.NewLine
For MachiningIndex = 0 To UsingMachining.Count - 1
MessageBoxText &= "- " & UsingMachining(MachiningIndex) & Environment.NewLine
Next
End If
' Chiedo conferma cancellazione lavorazione
If MessageBox.Show(MessageBoxText, EgtMsg(MSG_TOOLDBERRORS + 24), MessageBoxButton.YesNo, MessageBoxImage.Question) <> MessageBoxResult.Yes Then
Return
End If
RemoveTool(ToolToRemove)
End Sub
Private Sub RemoveTool(ToolToRemove As ToolTreeViewItem)
EgtSetCurrentContext(ToolDbWindowVM.m_ProjectSceneContext)
' Salvo il tipo di utensile per poterlo cancellare
Dim ToolType As Integer = ToolToRemove.Type
' Cancello l'utensile
Dim CurrToolOriginalName As String = String.Empty
EgtTdbGetToolFromUUID(ToolToRemove.Uuid, CurrToolOriginalName)
EgtTdbRemoveTool(CurrToolOriginalName)
' Rimuovo il nome dell'albero
For Each ToolFamily In ToolsList
If (ToolFamily.ToolType And ToolType) <> 0 Then
ToolFamily.Items.Remove(ToolToRemove)
End If
Next
ErrorOnTool(False)
End Sub
#End Region ' RemoveCommand
#Region "ReloadToolCommand"
''' <summary>
''' Returns a command that reload the current selected tool.
''' </summary>
Public ReadOnly Property ReloadToolCommand() As ICommand
Get
If m_cmdReloadTool Is Nothing Then
m_cmdReloadTool = New Command(AddressOf ReloadTool)
End If
Return m_cmdReloadTool
End Get
End Property
''' <summary>
''' Reload the current selected tools. This method is invoked by the RemoveCommand.
''' </summary>
Public Sub ReloadTool(ByVal param As Object)
If TypeOf param Is FamilyToolTreeViewItem Then
Return
' Verifico se sia selezionato un utensile
ElseIf TypeOf param Is ToolTreeViewItem Then
Dim ToolToReload As ToolTreeViewItem = DirectCast(param, ToolTreeViewItem)
EgtSetCurrentContext(ToolDbWindowVM.m_ProjectSceneContext)
ToolToReload.ReadToolParam()
ToolToReload.ReadToolName()
ToolToReload.IsModifiedReset()
End If
End Sub
#End Region ' ReloadToolCommand
#Region "CloseToolDbCommand"
''' <summary>
''' Returns a command that remove the current selected machining.
''' </summary>
Public ReadOnly Property CloseToolsDbCommand() As ICommand
Get
If m_cmdCloseToolsDb Is Nothing Then
m_cmdCloseToolsDb = New Command(AddressOf CloseToolsDb)
End If
Return m_cmdCloseToolsDb
End Get
End Property
''' <summary>
''' Manage the MachiningDb closing. This method is invoked by the CloseMachiningDbCommand.
''' </summary>
Public Sub CloseToolsDb(param As Object)
m_bActive = False
' Imposto contesto di progetto
EgtSetCurrentContext(ToolDbWindowVM.m_ProjectSceneContext)
' Se selezionata una lavorazione, verifico salvataggio
If TypeOf param Is ToolTreeViewItem Then
Dim CurrTool As ToolTreeViewItem = DirectCast(param, ToolTreeViewItem)
If CurrTool.IsValid Then
CurrTool.WriteToolParam()
If EgtTdbIsCurrToolModified() Or CurrTool.m_IsModifiedName Or CurrTool.NewTool Then
Select Case MsgBox(EgtMsg(MSG_TOOLDBERRORS), MsgBoxStyle.YesNo, EgtMsg(MSG_TOOLDBERRORS + 1))
Case MsgBoxResult.Yes
CurrTool.NewTool = False
CurrTool.m_Name = CurrTool.m_Name.Trim()
CurrTool.WriteToolName()
EgtTdbSaveCurrTool()
Case MsgBoxResult.No
If CurrTool.NewTool Then
RemoveTool(CurrTool)
ElseIf CurrTool.m_IsModifiedName Then
Dim DbName As String = String.Empty
EgtTdbGetCurrToolParam(MCH_TP.NAME, DbName)
CurrTool.NamePar = DbName
End If
End Select
End If
Else
'Utensile non valido, correggerlo o cancellarlo prima di uscire dal Db Utensili. - Errore
MessageBox.Show(EgtMsg( 31129), EgtMsg( 31126))
Return
End If
End If
' Salvataggio DB utensili
EgtTdbSave()
' Reset lua
EgtLuaResetGlobVar("STU")
' Se c'è il parametro Active sugli utensili
If m_Active_Visibility Then
' aggiorno setup di default
UpdateDefSetup()
End If
' Chiusura finestra
ToolTreeViewItem.m_delRemoveTool = Nothing
ToolTreeViewItem.m_delErrorOnTool = Nothing
ToolTreeViewItem.m_delIsEnabledBtns = Nothing
FamilyToolTreeViewItem.m_delIsEnabledBtns = Nothing
For Each Window In Application.Current.Windows
If TypeOf Window Is ToolDbWindowV Then
Dim ToolDbWindow As ToolDbWindowV = DirectCast(Window, ToolDbWindowV)
ToolDbWindow.DataContext = Nothing
ToolDbWindow.Close()
End If
Next
End Sub
#End Region ' CloseToolsDbCommand
#End Region ' Commands
End Class