88ff42a8c6
- aggiunta gestione lavorazione di taglio anche con lama manuale (ovviamente non si cambia lama).
372 lines
14 KiB
VB.net
372 lines
14 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports EgtUILib
|
|
|
|
Public Class ChangeToolWD
|
|
Private m_MainWindow As MainWindow = DirectCast(Application.Current.MainWindow, MainWindow)
|
|
|
|
Private m_MachiningList As New ObservableCollection(Of ItemMachining)
|
|
|
|
Sub New(Owner As Window)
|
|
Me.Owner = Owner
|
|
InitializeComponent()
|
|
End Sub
|
|
|
|
' Parametri della lama impostata correntemente in macchina
|
|
Private m_DefaultSaw_Name As String = String.Empty
|
|
Private m_DefaultSaw_Diam As Double = 0
|
|
Private m_DefaultSaw_Thick As Double = 0
|
|
Private m_DefaultSaw_Exists As Boolean = False
|
|
|
|
' Il nome della lavorazione restituito dalla selezione
|
|
Private m_NewSawing As String = String.Empty
|
|
Public ReadOnly Property NewSawing As String
|
|
Get
|
|
Return m_NewSawing
|
|
End Get
|
|
End Property
|
|
|
|
' Il colore della lavorazione
|
|
Private m_EgtColor As New Color3d
|
|
Public ReadOnly Property EgtColor As Color3d
|
|
Get
|
|
Return m_EgtColor
|
|
End Get
|
|
End Property
|
|
|
|
' Il nome della posizione sulla rulliera
|
|
Private m_TCPos As String = String.Empty
|
|
Public ReadOnly Property TCPos As String
|
|
Get
|
|
Return m_TCPos
|
|
End Get
|
|
End Property
|
|
|
|
' Nome della lavorazione corrente
|
|
Private m_CurrSawing As String = String.Empty
|
|
Public Property CurrSawing As String
|
|
Get
|
|
Return m_CurrSawing
|
|
End Get
|
|
Set(value As String)
|
|
m_CurrSawing = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Sub GetDiamAndThickDefaultSaw()
|
|
m_DefaultSaw_Name = m_MainWindow.m_CurrentMachine.sCurrSaw
|
|
' Dalla lavorazione corrente recupero il nome della lama
|
|
If EgtMdbSetCurrMachining(m_CurrSawing) Then
|
|
Dim sNameTool As String = String.Empty
|
|
If EgtMdbGetCurrMachiningParam(MCH_MP.TOOL, sNameTool) Then m_DefaultSaw_Name = sNameTool
|
|
End If
|
|
If EgtTdbSetCurrTool(m_DefaultSaw_Name) Then
|
|
' Diametro lama lavorazione
|
|
EgtTdbGetCurrToolParam(MCH_TP.DIAM, m_DefaultSaw_Diam)
|
|
' Spessore lama corrente
|
|
EgtTdbGetCurrToolParam(MCH_TP.THICK, m_DefaultSaw_Thick)
|
|
m_DefaultSaw_Exists = True
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub ChangeToolWD_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized
|
|
' Posizione finestra
|
|
Me.Top = Owner.Top + Owner.Height / 2 - Me.Height / 2
|
|
Me.Left = Owner.Left + Owner.Width / 2 - Me.Width / 2
|
|
' Definizione del collegamento tra ItemList e ListBox1
|
|
SetUpToolListBox.ItemsSource = m_MachiningList
|
|
' Seleziona lavorazione
|
|
FilePathTxBl.Text = EgtMsg(90378)
|
|
End Sub
|
|
|
|
Private Sub ChangeToolWD_Loaded(sender As Object, e As EventArgs) Handles Me.Loaded
|
|
If String.IsNullOrEmpty(m_CurrSawing) Then
|
|
m_CurrSawing = m_MainWindow.m_CurrentMachine.sCurrSawing
|
|
End If
|
|
' carico elenco degli utensili impostati attualmente in macchina (anche il laser!)
|
|
LoadSetUpMachining()
|
|
' ricerco la lavorazione corrente
|
|
Dim Item As ItemMachining = m_MachiningList.FirstOrDefault(Function(x) x.Machining = m_CurrSawing)
|
|
Dim Index As Integer = m_MachiningList.IndexOf(Item)
|
|
If Index < 0 Then
|
|
' Imposto lavorazione di default
|
|
EgtMdbSetCurrMachining(m_CurrSawing)
|
|
Dim sTool As String = String.Empty
|
|
EgtMdbGetCurrMachiningParam(MCH_MP.TOOL, sTool)
|
|
' ⚠️ Utensile {0} non attrezzato
|
|
ErrorTxBl.Text = String.Format(EgtMsg(90377), sTool)
|
|
Index = 0
|
|
End If
|
|
' se presente seleziono il primo elemento
|
|
If m_MachiningList.Count > 0 Then
|
|
SetUpToolListBox.SelectedItem = m_MachiningList(Index)
|
|
OkBtn.IsEnabled = True
|
|
Else
|
|
OkBtn.IsEnabled = False
|
|
End If
|
|
End Sub
|
|
|
|
#Region "SET UP MACHINING"
|
|
|
|
' Creo le liste da mostrare nella lista
|
|
Private Function LoadSetUpMachining() As Boolean
|
|
' Pulisco la lista delle lavorazioni di lama
|
|
m_MachiningList.Clear()
|
|
' Imposto il contesto corrente
|
|
EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
|
|
' Recupero la lista di tutte le lavorazioni di lama
|
|
Dim SawingList As List(Of String) = GetAllSawing()
|
|
' Se non ci sono lavorazioni di lama allora esco
|
|
If SawingList.Count() = 0 Then Return False
|
|
' Carico le lavorazioni di lama compatibili
|
|
CreateSawingList(SawingList)
|
|
Return True
|
|
End Function
|
|
|
|
' Creo la lista delle delle lavorazioni di lama da proporre
|
|
Private Sub CreateSawingList(SawingList As List(Of String))
|
|
' Recupero le info della lama montata di default
|
|
GetDiamAndThickDefaultSaw()
|
|
' Verifico se lama fissa
|
|
Dim bFixedSaw As Boolean = Not CamAuto.CanChangeSaw()
|
|
' recupero la prima lavorazione
|
|
For Each sSawingName As String In SawingList
|
|
Dim sToolName As String = ""
|
|
' Imposto la lavorazione corrente
|
|
EgtMdbSetCurrMachining(sSawingName)
|
|
' Recupero il nome dell'utensile della lavorazione
|
|
EgtMdbGetCurrMachiningParam(MCH_MP.TOOL, sToolName)
|
|
If String.IsNullOrWhiteSpace( sToolName) Then Continue For
|
|
' Se lama fissa
|
|
If bFixedSaw Then
|
|
' Sono ammesse solo altre lavorazioni con la stessa lama
|
|
If sToolName = m_DefaultSaw_Name AndAlso VerifyCurrMachiningMaterial() Then
|
|
' recupero eventuale posizione
|
|
EgtTdbSetCurrTool(sToolName)
|
|
Dim sTCPos As String = ""
|
|
EgtTdbGetCurrToolParam(MCH_TP.TCPOS, sTCPos)
|
|
' inserisco in lista
|
|
m_MachiningList.Add(New ItemMachining(sSawingName, sToolName, sTCPos, New Color3d(0, 0, 0, 100)))
|
|
End If
|
|
' altrimenti (ammessa solo se da TC)
|
|
Else
|
|
' Verifico compatibilità nelle dimensioni lama e nei materiali ammessi dalla lavorazione
|
|
If Not( VerifyCurrSawTolerance(sToolName) AndAlso VerifyCurrMachiningMaterial()) Then Continue For
|
|
' Cerco la lama nel TC
|
|
For Each ToolPosition As ToolChangerPos In m_MainWindow.m_CurrentMachine.ToolChanger
|
|
If sToolName = ToolPosition.sTool Then
|
|
m_MachiningList.Add(New ItemMachining(sSawingName, sToolName, ToolPosition.sName, Utility.GetColorPV()))
|
|
Exit For
|
|
End If
|
|
Next
|
|
End If
|
|
Next
|
|
' reimposto la lavorazione di lama e la lama impostate in macchina
|
|
EgtTdbSetCurrTool(m_MainWindow.m_CurrentMachine.sCurrSaw)
|
|
EgtMdbSetCurrMachining(m_MainWindow.m_CurrentMachine.sCurrSawing)
|
|
End Sub
|
|
|
|
' Verifico se la lavorazione impostata nella chiamante e quindi corrente può lavorare il grezzo corrente
|
|
Private Function VerifyCurrMachiningMaterial() As Boolean
|
|
' Stringa identificativa del materiale corrente
|
|
Dim sCurrMatId As String = m_MainWindow.m_CurrentMachine.CurrMat.nId.ToString()
|
|
If m_MainWindow.m_CurrentMachine.bWaterJet And m_MainWindow.m_CurrentMachine.bFromDBWaterJet Then
|
|
sCurrMatId &= "." & m_MainWindow.m_CurrentMachine.CurrMat.SubId.ToString()
|
|
End If
|
|
' Recupero elenco materiali della lavorazione
|
|
Dim sSysNotes As String = ""
|
|
EgtMdbGetCurrMachiningParam(MCH_MP.SYSNOTES, sSysNotes)
|
|
If String.IsNullOrWhiteSpace( sSysNotes) Then Return False
|
|
' Cerco un materiale compatibile con il corrente
|
|
Dim sItems() As String = sSysNotes.Split(";".ToCharArray)
|
|
For Ind As Integer = 0 To sItems.Count() - 1
|
|
' Divido il materiale nei suoi parametri
|
|
Dim sParams() = sItems(Ind).Split(",".ToCharArray)
|
|
' Se è il materiale del grezzo corrente
|
|
If sParams.Count() >= 3 AndAlso Trim(sParams(0)) = sCurrMatId Then
|
|
' Verifico rientri nello spessore ammesso
|
|
Dim dMinTh As Double = 0
|
|
Dim dMaxTh As Double = 0
|
|
StringToDouble(sParams(1), dMinTh)
|
|
StringToDouble(sParams(2), dMaxTh)
|
|
If dMinTh < dMaxTh - 10 * EPS_SMALL And
|
|
m_MainWindow.m_CurrentProjectPageUC.m_dRawHeight >= dMinTh And
|
|
m_MainWindow.m_CurrentProjectPageUC.m_dRawHeight <= dMaxTh Then
|
|
Return True
|
|
Else
|
|
Return False
|
|
End If
|
|
End If
|
|
Next
|
|
' Non ho trovato niente
|
|
Return False
|
|
End Function
|
|
|
|
' verifico l'utensile corrente (impostato nella funzione chiamante) se ha le stesse dimensioni della lama di default
|
|
Private Function VerifyCurrSawTolerance(sNameTool As String) As Boolean
|
|
If m_DefaultSaw_Exists Then
|
|
If EgtTdbSetCurrTool(sNameTool) Then
|
|
' Diametro nuova lama
|
|
Dim NewDiam As Double = 0
|
|
EgtTdbGetCurrToolParam(MCH_TP.DIAM, NewDiam)
|
|
' Spessore lama
|
|
Dim NewThick As Double = 0
|
|
EgtTdbGetCurrToolParam(MCH_TP.THICK, NewThick)
|
|
' Verifico che la nuova lama possa essere applicata: diametro max 1.25*prec, uguale spessore
|
|
Dim Delta_Diam As Double = NewDiam - m_DefaultSaw_Diam
|
|
Dim Delta_Thick As Double = Math.Abs(NewThick - m_DefaultSaw_Thick)
|
|
If Delta_Diam < 0.25 * m_DefaultSaw_Diam And Delta_Thick < EPS_SMALL Then
|
|
Return True
|
|
Else
|
|
EgtOutLog(String.Format("New saw {0} can not replace the current {1}; Delta_Diam={2}, |Delta_Thick|={3} ", sNameTool, m_DefaultSaw_Name, Delta_Diam, Delta_Thick))
|
|
End If
|
|
Else
|
|
EgtOutLog("Impossible to find in toolDB saw: " & sNameTool)
|
|
End If
|
|
Else
|
|
If String.IsNullOrEmpty(m_DefaultSaw_Name) Then
|
|
EgtOutLog("There is no machine CurrSaw!")
|
|
Else
|
|
EgtOutLog("Impossible to find in toolDB machine CurrSaw: " & m_DefaultSaw_Name)
|
|
End If
|
|
End If
|
|
Return False
|
|
End Function
|
|
|
|
' Restituisce tutto l'elenco delle lavorazioni di taglio di lama disponibili in macchina
|
|
Private Function GetAllSawing() As List(Of String)
|
|
Dim sFName As String = EgtMsg(90771) ' Uscita
|
|
If Not m_MainWindow.m_CurrentMachine.bSawing Then Return Nothing
|
|
' Inserisco categoria ed eventuali elementi
|
|
Dim SawingList As New List(Of String)
|
|
Dim nFType As Integer = MCH_MY.SAWING
|
|
Dim MachiningName As String = String.Empty
|
|
Dim bFound As Boolean = EgtMdbGetFirstMachining(nFType, MachiningName)
|
|
While bFound
|
|
SawingList.Add( MachiningName)
|
|
bFound = EgtMdbGetNextMachining(nFType, MachiningName)
|
|
End While
|
|
Return SawingList
|
|
End Function
|
|
|
|
#End Region ' Set up machinining
|
|
|
|
Private Sub SetUpToolListBox_PreviewMouseUp(sender As Object, e As MouseButtonEventArgs) Handles SetUpToolListBox.PreviewMouseUp
|
|
' Disabilito Ok
|
|
OkBtn.IsEnabled = False
|
|
' Recupero item selezionato
|
|
If SetUpToolListBox.SelectedItems.Count() = 0 Then
|
|
Return
|
|
Else
|
|
m_NewSawing = m_MachiningList(SetUpToolListBox.SelectedIndex).Machining
|
|
m_EgtColor = m_MachiningList(SetUpToolListBox.SelectedIndex).FootprintToolColor
|
|
m_TCPos = m_MachiningList(SetUpToolListBox.SelectedIndex).ToolPos
|
|
OkBtn.IsEnabled = True
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub SetUpToolListBox_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles SetUpToolListBox.SelectionChanged
|
|
' Disabilito Ok
|
|
OkBtn.IsEnabled = False
|
|
' Recupero item selezionato
|
|
If SetUpToolListBox.SelectedItems.Count() = 0 Then
|
|
Return
|
|
Else
|
|
m_NewSawing = m_MachiningList(SetUpToolListBox.SelectedIndex).Machining
|
|
m_EgtColor = m_MachiningList(SetUpToolListBox.SelectedIndex).FootprintToolColor
|
|
m_TCPos = m_MachiningList(SetUpToolListBox.SelectedIndex).ToolPos
|
|
OkBtn.IsEnabled = True
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub OkBtn_Click(sender As Object, e As RoutedEventArgs) Handles OkBtn.Click
|
|
DialogResult = True
|
|
End Sub
|
|
|
|
End Class
|
|
|
|
Public Class ItemMachining
|
|
|
|
Private m_ToolPos As String = String.Empty
|
|
Private m_ToolName As String = String.Empty
|
|
Private m_Machining As String = String.Empty
|
|
Private m_ToolExit As Integer = 1
|
|
Private m_ToolType As Integer = -1
|
|
Private m_FootprintToolColor As New Color3d(0, 255, 0, 100)
|
|
Private m_cSawColor As SolidColorBrush
|
|
|
|
' Posizione porta utensile
|
|
Public Property ToolPos As String
|
|
Get
|
|
Return m_ToolPos
|
|
End Get
|
|
Set(value As String)
|
|
m_ToolPos = value
|
|
End Set
|
|
End Property
|
|
|
|
' Nome utensile
|
|
Public Property ToolName As String
|
|
Get
|
|
Return m_ToolName
|
|
End Get
|
|
Set(value As String)
|
|
m_ToolName = value
|
|
End Set
|
|
End Property
|
|
|
|
' Nome della lavorazione
|
|
Public Property Machining As String
|
|
Get
|
|
Return m_Machining
|
|
End Get
|
|
Set(value As String)
|
|
m_Machining = value
|
|
End Set
|
|
End Property
|
|
|
|
Public Property ToolExit As Integer
|
|
Get
|
|
Return m_ToolExit
|
|
End Get
|
|
Set(value As Integer)
|
|
m_ToolExit = value
|
|
End Set
|
|
End Property
|
|
|
|
Public Property ToolType As Integer
|
|
Get
|
|
Return m_ToolType
|
|
End Get
|
|
Set(value As Integer)
|
|
m_ToolType = value
|
|
End Set
|
|
End Property
|
|
|
|
Public Property FootprintToolColor As Color3d
|
|
Get
|
|
Return m_FootprintToolColor
|
|
End Get
|
|
Set(value As Color3d)
|
|
m_FootprintToolColor = value
|
|
End Set
|
|
End Property
|
|
|
|
Public Property SawColor As SolidColorBrush
|
|
Get
|
|
Return m_cSawColor
|
|
End Get
|
|
Set(value As SolidColorBrush)
|
|
m_cSawColor = value
|
|
End Set
|
|
End Property
|
|
|
|
Sub New(sMachining As String, sToolName As String, sToolPos As String, cColor As Color3d)
|
|
m_Machining = sMachining
|
|
m_ToolPos = sToolPos
|
|
m_ToolName = sToolName
|
|
m_FootprintToolColor = cColor
|
|
m_cSawColor = New SolidColorBrush(Color.FromRgb(m_FootprintToolColor.R, m_FootprintToolColor.G, m_FootprintToolColor.B))
|
|
End Sub
|
|
|
|
End Class
|