Creazione dei comandi per importare ed esportare gli utensili

This commit is contained in:
NicolaP
2021-09-16 14:36:11 +02:00
parent 6a894e9d33
commit ed19ade967
5 changed files with 261 additions and 27 deletions
+67
View File
@@ -0,0 +1,67 @@
<Window x:Class="ImportExportToolWD"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:EgtWPFLib="clr-namespace:EgtWPFLib;assembly=EgtWPFLib"
xmlns:EgtWPFLib5="clr-namespace:EgtWPFLib5;assembly=EgtWPFLib5"
FontFamily="{DynamicResource OmagCut_Font}"
ResizeMode="NoResize" WindowStyle="None" AllowsTransparency="True" Background="Transparent"
Title="SaveNameWD" Height="350" Width="426.5" ShowInTaskbar="False">
<!--Definizione della pagina di scelta del nome con cui salvare il progetto-->
<Border Style="{DynamicResource OmagCut_Border}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="7*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<ScrollViewer Grid.Row="0">
<TreeView ItemsSource="{Binding FamilyList}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type EgtWPFLib5:ImpExpFamily}" ItemsSource="{Binding ToolList}">
<Grid Height="20">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="{Binding PictureString}" Height="20" Width="20" Margin="0,0,5,0" />
<TextBlock Grid.Column="1" Text="{Binding Name}" FontSize="15" Margin="0,-2,5,0" VerticalAlignment="Center" />
</Grid>
</HierarchicalDataTemplate>
<DataTemplate DataType="{x:Type EgtWPFLib5:ImpExpItem}">
<Grid Height="20">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<!--<Image Grid.Column="0" Source="{Binding PictureString}" Height="32" Margin="0,8,6,4" />-->
<CheckBox Name="ActiveTxBx" Grid.Column="0" Height="15" Width="15" Margin="-15,0,5,0" VerticalContentAlignment="Center"
IsChecked="{Binding Active}"
Visibility="{Binding Path=DataContext.Active_Visibility,
RelativeSource={RelativeSource AncestorType={x:Type EgtWPFLib5:EgtCustomWindow}}}"/>
<TextBlock Grid.Column="1" Text="{Binding Name}" FontSize="15" Margin="0,-2,5,0" VerticalAlignment="Center" />
</Grid>
</DataTemplate>
</TreeView.Resources>
</TreeView>
</ScrollViewer>
<Button Command="{Binding OkCommand}"
Content="{Binding OkMsg}"
Grid.Row="1"
Height="30" Width="100"
Margin="10" />
</Grid>
</Border>
</Window>
+3
View File
@@ -0,0 +1,3 @@
Public Class ImportExportToolWD
End Class
+5 -1
View File
@@ -434,13 +434,17 @@
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="11*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="9*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Button Name="NewBtn" Grid.Column="0" Style="{DynamicResource OmagCut_YellowGradientYellowTextButton}"/>
<Button Name="SaveBtn" Grid.Column="1" Style="{DynamicResource OmagCut_YellowGradientYellowTextButton}"/>
<Button Name="RemoveBtn" Grid.Column="2" Style="{DynamicResource OmagCut_YellowGradientYellowTextButton}" Padding="0"/>
<Button Name="ExportBtn" Grid.Column="3" Style="{DynamicResource OmagCut_YellowGradientYellowTextButton}" Padding="0"/>
<Button Name="ImportBtn" Grid.Column="4" Style="{DynamicResource OmagCut_YellowGradientYellowTextButton}" Padding="0"/>
</Grid>
+180 -26
View File
@@ -3,6 +3,7 @@ Imports OmagCUT.TreeViewItem
Imports System.ComponentModel
Imports EgtUILib
Imports EgtWPFLib
Imports EgtWPFLib5
Public Class ToolsDbPageUC
@@ -53,6 +54,8 @@ Public Class ToolsDbPageUC
NewBtn.Content = EgtMsg(MSG_MACHINEPAGEUC + 15)
SaveBtn.Content = EgtMsg(MSG_MACHINEPAGEUC + 17)
RemoveBtn.Content = EgtMsg(MSG_MACHINEPAGEUC + 18)
ExportBtn.Content = "Export"
ImportBtn.Content = "Import"
NameTxBl.Text = EgtMsg(MSG_TOOLSDBPAGEUC + 1)
TCPosTxBl.Text = EgtMsg(MSG_TOOLSDBPAGEUC + 2)
@@ -239,17 +242,17 @@ Public Class ToolsDbPageUC
Next
' Determino il tipo di utensile
Dim nType As Integer
EgtTdbGetCurrToolParam( MCH_TP.TYPE, nType)
EgtTdbGetCurrToolParam(MCH_TP.TYPE, nType)
' Imposto testa e uscita
' Sempre lame su H1.1 e utensili foretto, fresa e mola da scasso su H1.2
If ( nType And MCH_TF.WATERJET) = 0 then
If (nType And MCH_TF.WATERJET) = 0 Then
Dim bSaw As Boolean = ((nType And MCH_TF.SAWBLADE) <> 0)
EgtTdbSetCurrToolParam( MCH_TP.HEAD, "H1")
EgtTdbSetCurrToolParam( MCH_TP.EXIT_, If(bSaw, 1, 2))
' Waterjet sempre su H2.1
EgtTdbSetCurrToolParam(MCH_TP.HEAD, "H1")
EgtTdbSetCurrToolParam(MCH_TP.EXIT_, If(bSaw, 1, 2))
' Waterjet sempre su H2.1
Else
EgtTdbSetCurrToolParam( MCH_TP.HEAD, "H2")
EgtTdbSetCurrToolParam( MCH_TP.EXIT_, 1)
EgtTdbSetCurrToolParam(MCH_TP.HEAD, "H2")
EgtTdbSetCurrToolParam(MCH_TP.EXIT_, 1)
End If
' Per macchine senza ToolChanger, resetto la posizione su questo
If m_CurrMachine.ShowToolChanger = 0 Then
@@ -317,8 +320,8 @@ Public Class ToolsDbPageUC
EgtTdbGetCurrToolParam(MCH_TP.TYPE, CurrType)
For Each ToolFamily As CathegoryItem In ToolsList
If ToolFamily.nTType = CurrType Then
Dim NewToolItem As New CustomItem( NewName, CurrType)
ToolFamily.Items.Add( NewToolItem)
Dim NewToolItem As New CustomItem(NewName, CurrType)
ToolFamily.Items.Add(NewToolItem)
NewToolItem.IsSelected = True
GetToolParams()
m_OldItem = ToolTreeView.SelectedItem
@@ -354,15 +357,15 @@ Public Class ToolsDbPageUC
Dim sItems() As String = sUserNotes.Split(";".ToCharArray)
For i As Integer = 0 To sItems.Count() - 1
If sItems(i).Contains("CODE=") Then
CodeTxBx.Text = sItems(i).Substring( 5)
CodeTxBx.Text = sItems(i).Substring(5)
ElseIf sItems(i).Contains("SUPPL=") Then
SupplierTxBx.Text = sItems(i).Substring( 6)
SupplierTxBx.Text = sItems(i).Substring(6)
ElseIf sItems(i).Contains("S/N=") Then
SerNbrTxBx.Text = sItems(i).Substring( 4)
SerNbrTxBx.Text = sItems(i).Substring(4)
ElseIf sItems(i).Contains("END=") Then
EndLifeChBx.IsChecked = True
m_sEndLife = sItems(i).Substring( 4)
ElseIf Not String.IsNullOrWhiteSpace(sItems(i))
m_sEndLife = sItems(i).Substring(4)
ElseIf Not String.IsNullOrWhiteSpace(sItems(i)) Then
sToShow &= sItems(i) & ";"
End If
Next
@@ -383,7 +386,7 @@ Public Class ToolsDbPageUC
sUserNotes &= "SUPPL=" & SupplierTxBx.Text & ";"
sUserNotes &= "S/N=" & SerNbrTxBx.Text & ";"
If EndLifeChBx.IsChecked Then
If String.IsNullOrWhiteSpace( m_sEndLife) Then
If String.IsNullOrWhiteSpace(m_sEndLife) Then
m_sEndLife = My.Computer.Clock.LocalTime.ToString("dd.MM.yyyy HH:mm:ss")
End If
sUserNotes &= "END=" & m_sEndLife & ";"
@@ -479,18 +482,169 @@ Public Class ToolsDbPageUC
End If
End Sub
Private Sub ExportBtn_Click(Sender As Object, e As RoutedEventArgs) Handles ExportBtn.Click
' contesto corrente
EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
' creo lista utensili per esportazione
Dim ToolToExportList = New ObservableCollection(Of ImpExpFamily)
Dim Family As CathegoryItem
Dim Tool As CustomItem
For Each Family In ToolsList
Dim ImpExpFamily As New ImpExpFamily(Family.Name, Family.nTType)
ImpExpFamily.PictureString = "/Resources/ToolsTreeviewImages/Folder.png"
For Each Tool In Family.Items
Dim CurrTool = New ImpExpItem(Tool.Name, False)
ImpExpFamily.ToolList.Add(CurrTool)
Next
ToolToExportList.Add(ImpExpFamily)
Next
Dim ExportWndVM As New ImportExportToolWindowVM(ToolToExportList)
Dim ExportWnd As New ImportExportToolWindowV(Application.Current.MainWindow, ExportWndVM)
ExportWnd.ShowDialog()
End Sub
Private Sub ImportBtn_Click(Sender As Object, e As RoutedEventArgs) Handles ImportBtn.Click
' contesto corrente
EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx())
' apro dialogo di scelta file
Dim ImportFileDlg As New Microsoft.Win32.OpenFileDialog() With {
.Title = EgtMsg(31161) & " " & EgtMsg(31163),
.DefaultExt = ".data",
.Filter = "Tools (.data)|*.data",
.CheckFileExists = True,
.ValidateNames = True
}
If ImportFileDlg.ShowDialog() <> True Then Return
Dim ImportFilePath As String = ImportFileDlg.FileName
' recupero liste utensili da importare
Dim ImportFileToolNameList As String() = Nothing
Dim ImportFileToolFamilyList As Integer() = Nothing
EgtTdbToBeImported(ImportFilePath, ImportFileToolNameList, ImportFileToolFamilyList)
' li inserisco in lista per finestra di scelta
Dim ToolToImportList As New ObservableCollection(Of ImpExpFamily)
' creo famiglie di utensili in base a quelle trovate in lista importata
For ToolIndex As Integer = 0 To ImportFileToolNameList.Count - 1
Dim ToolName As String = ImportFileToolNameList(ToolIndex)
Dim ToolFamily As Integer = ImportFileToolFamilyList(ToolIndex)
ToolFamily = ToolFamily And
(MCH_TF.DRILLBIT Or
MCH_TF.SAWBLADE Or
MCH_TF.MILL Or
MCH_TF.MORTISE Or
MCH_TF.CHISEL Or
MCH_TF.WATERJET Or
MCH_TF.COMPO)
Dim bFounded As Boolean = False
Dim ToolToImportFamily As ImpExpFamily
For Each ToolToImportFamily In ToolToImportList
If (ToolFamily = ToolToImportFamily.FamilyType) Then
ToolToImportFamily.ToolList.Add(New ImpExpItem(ToolName, AlreadyExist(ToolName)))
bFounded = True
Exit For
End If
Next
If Not bFounded Then
Dim NewFamily As New ImpExpFamily(GetToolFamilyName(ToolFamily), ToolFamily)
NewFamily.ToolList.Add(New ImpExpItem(ToolName, AlreadyExist(ToolName)))
ToolToImportList.Add(NewFamily)
End If
Next
Dim ImportWndVM As New ImportExportToolWindowVM(ToolToImportList, ImportFilePath, ImportFileToolNameList)
Dim ImportWnd As New ImportExportToolWindowV(Application.Current.MainWindow, ImportWndVM)
If ImportWnd.ShowDialog() Then
' Aggiungo all'albero visualizzato gli utensili appena importati
LoadImportedMachineTools(ImportWndVM.vsImported)
End If
End Sub
Private Function AlreadyExist(ToolName As String) As Boolean
Dim ToolFamily As CathegoryItem
For Each ToolFamily In ToolsList
Dim ToolItem As CustomItem
For Each ToolItem In ToolFamily.Items
If ToolName = ToolItem.Name Then
Return True
End If
Next
Next
Return False
End Function
Private Function GetToolFamilyName(NewToolFamily As Integer) As String
Dim ToolFamily As CathegoryItem
For Each ToolFamily In ToolsList
If NewToolFamily = ToolFamily.nTType Then
Return ToolFamily.Name
End If
Next
Return ""
End Function
Private Sub LoadImportedMachineTools(vsImportedTools As String())
' Leggo tutti gli utensili presenti nella Macchina (quindi anche quelli appena importati).
Dim ActiveToolsFamilies() As ToolsFamily = MachineUtility.ReadToolFamilies(m_CurrMachine.sMachIniFile)
Dim ToolsFamilyIndex As Integer = 0
Dim ToolsFamilyItem As ToolsFamily
For Each ToolsFamilyItem In ActiveToolsFamilies
Dim FamilyTreeView As New CathegoryItem(ToolsFamilyItem.Name, ToolsFamilyItem.Id)
Dim ToolFamilyItem = ToolsList.FirstOrDefault(Function(ToolFamily) ToolsFamilyItem.Id = FamilyTreeView.nTType)
If IsNothing(ToolFamilyItem) Then
ToolsList.Insert(ToolsFamilyIndex, FamilyTreeView)
End If
Dim nType As Integer = 0
Dim ToolName As String = String.Empty
Dim ToolIndex As Integer = 0
EgtSetCurrentContext(ToolScene.GetCtx())
If EgtTdbGetFirstTool(ToolsFamilyItem.Id, ToolName, nType) Then
Dim ToolItem = ToolsList(ToolsFamilyIndex).Items.FirstOrDefault(Function(Tool) Tool.Name = ToolName)
If IsNothing(ToolItem) Then
' Se leggo un utensile non presente nella ToolsList visualizzata lo aggiungo ad essa.
Dim NewToolName As New CustomItem(ToolName, nType)
ToolsList(ToolsFamilyIndex).Items.Insert(ToolIndex, NewToolName)
ElseIf vsImportedTools.Contains(ToolName) Then
' Se un utensile è presente nella ToolsList visualizzata ma nel contempo è nell'array vsImported
' vuol dire che è stato sovrascritto perciò lo rimuovo e lo riaggiungo alla ToolsList.
ToolsList(ToolsFamilyIndex).Items.Remove(ToolsList(ToolsFamilyIndex).Items.FirstOrDefault(Function(Tool) Tool.Name = ToolName))
Dim NewToolName As New CustomItem(ToolName, nType)
ToolsList(ToolsFamilyIndex).Items.Insert(ToolIndex, NewToolName)
End If
ToolIndex += 1
While EgtTdbGetNextTool(ToolsFamilyItem.Id, ToolName, nType)
ToolItem = ToolsList(ToolsFamilyIndex).Items.FirstOrDefault(Function(Tool) Tool.Name = ToolName)
If IsNothing(ToolItem) Then
' Se leggo un utensile non presente nella ToolsList visualizzata lo aggiungo ad essa.
Dim NewToolName As New CustomItem(ToolName, nType)
ToolsList(ToolsFamilyIndex).Items.Insert(ToolIndex, NewToolName)
ElseIf vsImportedTools.Contains(ToolName) Then
' Se un utensile è presente nella ToolsList visualizzata ma nel contempo è nell'array vsImported
' vuol dire che è stato sovrascritto perciò lo rimuovo e lo riaggiungo alla ToolsList.
ToolsList(ToolsFamilyIndex).Items.Remove(ToolsList(ToolsFamilyIndex).Items.FirstOrDefault(Function(Tool) Tool.Name = ToolName))
Dim NewToolName As New CustomItem(ToolName, nType)
ToolsList(ToolsFamilyIndex).Items.Insert(ToolIndex, NewToolName)
End If
ToolIndex += 1
End While
End If
ToolsFamilyIndex += 1
Next
End Sub
Friend Sub InitializeToolGroup(bEnabled As Boolean, nTType As Integer, sFName As String)
If Not bEnabled Then Return
' Inserisco categoria ed eventuali elementi
Dim ToolCathegory As New CathegoryItem( sFName, nTType)
Dim ToolCathegory As New CathegoryItem(sFName, nTType)
Dim nType As Integer = 0
Dim ToolName As String = String.Empty
Dim bFound As Boolean = EgtTdbGetFirstTool( nTType, ToolName, nType)
Dim bFound As Boolean = EgtTdbGetFirstTool(nTType, ToolName, nType)
While bFound
If nType = nTType Then ToolCathegory.Items.Add( New CustomItem( ToolName, nType))
bFound = EgtTdbGetNextTool( nTType, ToolName, nType)
If nType = nTType Then ToolCathegory.Items.Add(New CustomItem(ToolName, nType))
bFound = EgtTdbGetNextTool(nTType, ToolName, nType)
End While
ToolsList.Add( ToolCathegory)
ToolsList.Add(ToolCathegory)
End Sub
Private Sub GetToolParams()
@@ -545,7 +699,7 @@ Public Class ToolsDbPageUC
HeadTxBx.Text = ToolString
EgtTdbGetCurrToolParam(MCH_TP.EXIT_, ToolInt)
ExitTxBx.Text = ToolInt.ToString()
if Not GetSpecials() Then
If Not GetSpecials() Then
EgtTdbGetCurrToolParam(MCH_TP.USERNOTES, ToolString)
UserNotesTxBx.Text = ToolString
End If
@@ -601,7 +755,7 @@ Public Class ToolsDbPageUC
EgtTdbSetCurrToolParam(MCH_TP.HEAD, HeadTxBx.Text)
Int32.TryParse(ExitTxBx.Text, nTemp)
EgtTdbSetCurrToolParam(MCH_TP.EXIT_, nTemp)
if Not SetSpecials() Then
If Not SetSpecials() Then
EgtTdbSetCurrToolParam(MCH_TP.USERNOTES, UserNotesTxBx.Text)
End If
End Sub
@@ -637,7 +791,7 @@ Public Class ToolsDbPageUC
Dim bShowUserNotes As Boolean = ((m_nToolType = MCH_TY.SAW_STD And m_CurrMachine.ShowUserNotes <> 0) Or m_CurrMachine.ShowUserNotes = 1)
UserNotesTxBl.Visibility = If(bShowUserNotes, Windows.Visibility.Visible, Windows.Visibility.Hidden)
UserNotesTxBx.Visibility = If(bShowUserNotes, Windows.Visibility.Visible, Windows.Visibility.Hidden)
Dim bShowSpecials As Boolean = ((m_nToolType = MCH_TY.SAW_STD And m_CurrMachine.ShowSpecials <> 0) Or m_CurrMachine.ShowSpecials = 1)
Dim bShowSpecials As Boolean = ((m_nToolType = MCH_TY.SAW_STD And m_CurrMachine.ShowSpecials <> 0) Or m_CurrMachine.ShowSpecials = 1)
SerNbrTxBl.Visibility = If(bShowSpecials, Windows.Visibility.Visible, Windows.Visibility.Hidden)
SerNbrTxBx.Visibility = If(bShowSpecials, Windows.Visibility.Visible, Windows.Visibility.Hidden)
CodeTxBl.Visibility = If(bShowSpecials, Windows.Visibility.Visible, Windows.Visibility.Hidden)
@@ -776,7 +930,7 @@ Public Class ToolsDbPageUC
Private Sub RecreateToolDraw(ByVal dVal As Double)
' Salvo il vecchio valore
Dim dOldVal As Double
GetVariableValue( dOldVal)
GetVariableValue(dOldVal)
' Aggiorno dati utensile
SetVariableValue(dVal)
' Creo utensile
@@ -1004,7 +1158,7 @@ Public Class ToolsDbPageUC
End Function
Private Function CreateToolDraw() As Boolean
Dim nErr As Integer = EgtTdbCurrToolDraw( m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx(), ToolScene.GetCtx())
Dim nErr As Integer = EgtTdbCurrToolDraw(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx(), ToolScene.GetCtx())
EgtSetCurrentContext(ToolScene.GetCtx())
Return (nErr = 0)
End Function
@@ -1057,4 +1211,4 @@ Public Class ToolsDbPageUC
End If
End Sub
End Class
End Class