efb250b4a4
- aggiunto il campo "Weight" al general del door, - aggiunta di una variabile booleana alla funzione ReadDDF nella classe Door per permettere di stampare le funzioni scritte nelle textbox, attualmente no è in uso (settata True)
352 lines
16 KiB
VB.net
352 lines
16 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports System.ComponentModel
|
|
Imports System.IO
|
|
Imports EgtUILib
|
|
|
|
Public Class DoorManagerViewModel
|
|
Implements INotifyPropertyChanged
|
|
Private m_rfMainWindowViewModel As MainWindowViewModel
|
|
' percorso della porta corrente (creata o già esistente nella cartella)
|
|
Private m_SelectedDoor As String
|
|
Private NewDoor As Boolean = False
|
|
Friend DeleteNewDoor As Integer = 1
|
|
Private SelDoor As New Door
|
|
|
|
|
|
' creiamo un nuovo progetto: un nome e una lista di porte
|
|
Private m_CurrProject As New Project
|
|
Public Property CurrProject As Project
|
|
Get
|
|
Return m_CurrProject
|
|
End Get
|
|
Set(value As Project)
|
|
m_CurrProject = value
|
|
End Set
|
|
End Property
|
|
|
|
' percorso della porta in lettura (o creazione)
|
|
Public Property SelectedDoor As String
|
|
Get
|
|
Return m_SelectedDoor
|
|
End Get
|
|
Set(value As String)
|
|
If IsNothing(value) Then Return
|
|
' riferimento alla porta (per stampare il DDF)
|
|
Dim DoorParametersViewModel As DoorParametersViewModel = DirectCast(m_rfMainWindowViewModel.DoorParameters.DataContext, DoorParametersViewModel)
|
|
' se eiste il file selezionato
|
|
If File.Exists(m_SelectedDoor) Then
|
|
' prima di cambiare porta selezionata chiedo il salvataggio il quella precedente
|
|
' se esiste una porta corrente associata al nome allora scrivo il file ddf per il disegno
|
|
If Not IsNothing(DoorParametersViewModel.CurrDoor) Then
|
|
' è necessario che il file passato alla grafica non presenti espressioni numeriche
|
|
DdfFile.WriteDDF(DoorParametersViewModel.CurrDoor, IniFile.m_sTempDir & "\CurrDoor.ddf", True)
|
|
|
|
Select Case DeleteNewDoor
|
|
' se è una porta appena creata
|
|
Case 0
|
|
' chiedo se deve essere eliminata la porta che era stata creata
|
|
RemoveDoor()
|
|
DeleteNewDoor = 1
|
|
' se è una porta "vecchia"
|
|
Case 1
|
|
' confronto il file della porta originale e quello aggiornato: se i due file sono uguali eccetto la data
|
|
' non faccio nulla
|
|
If DdfFile.SetModify(m_rfMainWindowViewModel) Then
|
|
|
|
Else
|
|
' altrimenti chiedo di salvare il file di disegno
|
|
If MessageBox.Show(String.Format(EgtMsg(50109), Path.GetFileNameWithoutExtension(m_SelectedDoor)), EgtMsg(50110), MessageBoxButton.YesNo, MessageBoxImage.Warning) = MessageBoxResult.Yes Then
|
|
DdfFile.WriteDDF(DoorParametersViewModel.CurrDoor, m_SelectedDoor, True)
|
|
DirectCast(m_rfMainWindowViewModel.DoorParameters.DataContext, DoorParametersViewModel).bSetChange = False
|
|
End If
|
|
End If
|
|
End Select
|
|
End If
|
|
End If
|
|
' tolgo l'* dal titolo a prescindere che il file sia stato o no salvato
|
|
Dim SetTitle = DirectCast(m_rfMainWindowViewModel.DoorParameters.DataContext, DoorParametersViewModel).CurrProject.Name
|
|
m_rfMainWindowViewModel.ProjectNameMsg = SetTitle
|
|
' se non esisteva nessuna porta allora posso procedere
|
|
m_SelectedDoor = value
|
|
NotifyPropertyChanged("SelectedDoor")
|
|
SelDoor = Nothing
|
|
SelDoor = New Door
|
|
SelDoor.NewDoor = NewDoor
|
|
If SelDoor.NewDoor Then
|
|
'OptionModule.GeneralDoor.CompoList.Clear()
|
|
SelDoor.Width = OptionModule.m_Width
|
|
SelDoor.Height = OptionModule.m_Height
|
|
SelDoor.Thickness = OptionModule.m_Thickness
|
|
SelDoor.Weight = OptionModule.m_Weight
|
|
SelDoor.Swing = OptionModule.m_Swing
|
|
|
|
SelDoor.LockEdgeType = OptionModule.m_LockEdgeType
|
|
SelDoor.HingeEdgeType = OptionModule.m_HingeEdgeType
|
|
SelDoor.TopType = OptionModule.m_TopType
|
|
SelDoor.BottomType = OptionModule.m_BottomType
|
|
|
|
SelDoor.LockEdgeMachining = OptionModule.m_LockEdgeMachining
|
|
SelDoor.HingeEdgeMachining = OptionModule.m_HingeEdgeMachining
|
|
SelDoor.TopMachining = OptionModule.m_TopMachining
|
|
SelDoor.BottomMachining = OptionModule.m_BottomMachining
|
|
SelDoor.LockEdgeOverMaterial = OptionModule.m_LockEdgeOverMaterial
|
|
SelDoor.HingeEdgeOverMaterial = OptionModule.m_HingeEdgeOverMaterial
|
|
SelDoor.TopOverMaterial = OptionModule.m_TopOverMaterial
|
|
SelDoor.BottomOverMaterial = OptionModule.m_BottomOverMaterial
|
|
' assegno la porta creata alla Programma come porta corrente
|
|
DoorParametersViewModel.CurrDoor = SelDoor
|
|
' scrivo il ddf della nuova porta come file temp
|
|
If Not IsNothing(DoorParametersViewModel.CurrDoor) Then DdfFile.WriteDDF(DoorParametersViewModel.CurrDoor, IniFile.m_sTempDir & "\CurrDoor.ddf", True)
|
|
' e stampo il nuovo ddf
|
|
DdfFile.WriteDDF(DoorParametersViewModel.CurrDoor, m_SelectedDoor, True)
|
|
' quindi da ora la nuova porta ha un suo DDF che possiamo trattare come tutti gli altri
|
|
' assegno il valore falso cosi da non ripetere questa operazione nel caso in cui si arrivi dalla funzione AddDoor
|
|
SelDoor.NewDoor = False
|
|
NewDoor = False
|
|
End If
|
|
' per aggiornare la parte grafica
|
|
' se il nome della porta è uno spazio vuoto allora non genero la porta ( per esempio sto aprendo una cartella vuota)
|
|
If Not String.IsNullOrWhiteSpace(m_SelectedDoor) Then
|
|
' leggo il file ddf
|
|
Door.ReadDDF(m_SelectedDoor, SelDoor)
|
|
' assegno come porta del programma quella aperta
|
|
DoorParametersViewModel.CurrDoor = SelDoor
|
|
' copio il file DDF come file DDF temporaneo
|
|
If Not IsNothing(DoorParametersViewModel.CurrDoor) Then
|
|
DdfFile.WriteDDF(SelDoor, IniFile.m_sTempDir & "\CurrDoor.ddf", True)
|
|
ExecDoors(DirectCast(m_rfMainWindowViewModel.SceneManager.DataContext, SceneManagerViewModel).ProjectScene, IniFile.m_sTempDir & "\CurrDoor.ddf")
|
|
' dal MainWindowViewModel accediamo alla ScenaManagerViewModel (primo DirectCast)
|
|
' dalla StatusBar accediamo alla proprietà pubblica UnitMeasure
|
|
DirectCast(DirectCast(m_rfMainWindowViewModel.SceneManager.DataContext, SceneManagerViewModel).StatusBar.DataContext, StatusBarViewModel).UnitMeasure = SelDoor.Measure
|
|
End If
|
|
End If
|
|
If IsNothing(SelDoor) Then
|
|
MessageBox.Show("Impossible to create the current door.", "Information", MessageBoxButton.OK, MessageBoxImage.Exclamation)
|
|
DoorParametersViewModel.CurrDoor = Nothing
|
|
DeleteDoorFromList()
|
|
End If
|
|
|
|
End Set
|
|
End Property
|
|
|
|
Private Sub DeleteDoorFromList()
|
|
Dim SelIndex As Integer = m_CurrProject.DoorList.IndexOf(m_SelectedDoor)
|
|
Dim ExtensionFile As String = Path.GetExtension(m_SelectedDoor)
|
|
Dim FileName As String = Path.GetFileName(m_SelectedDoor)
|
|
' modifico l'estensione del file
|
|
FileName = FileName.Replace(ExtensionFile, ".err")
|
|
' qui modifico il nome del file, ma ancora non è sostituito nel sistema
|
|
m_SelectedDoor = m_SelectedDoor.Replace(Path.GetFileName(m_SelectedDoor), FileName)
|
|
m_CurrProject.DoorList.RemoveAt(SelIndex)
|
|
CurrProject.NotifyPropertyChanged("DoorList")
|
|
' se la lista non è rimasta vuota
|
|
If m_CurrProject.DoorList.Count > 0 Then
|
|
' aggiorno la porta da visualizzare
|
|
If SelIndex > m_CurrProject.DoorList.Count - 1 Then
|
|
SelectedDoor = m_CurrProject.DoorList(SelIndex - 1)
|
|
Else
|
|
SelectedDoor = m_CurrProject.DoorList(SelIndex)
|
|
End If
|
|
' se non ci sono altre porte nella lista allora
|
|
Else
|
|
' elimino qualsiasi resto di porta
|
|
DirectCast(m_rfMainWindowViewModel.DoorParameters.DataContext, DoorParametersViewModel).CurrDoor = Nothing
|
|
' aggiorni l'immagine a nulla
|
|
EgtNewFile()
|
|
EgtZoom(ZM.ALL)
|
|
End If
|
|
End Sub
|
|
|
|
Public ReadOnly Property AddNewDoorToolTip As String
|
|
Get
|
|
Return EgtMsg(50302)
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property RemoveDoorToolTip As String
|
|
Get
|
|
Return EgtMsg(50303)
|
|
End Get
|
|
End Property
|
|
|
|
' Definizione comandi
|
|
Private m_cmdAddDoor As ICommand
|
|
Private m_cmdRemoveDoor As ICommand
|
|
|
|
Sub New(ByRef MainWindowViewModel As MainWindowViewModel)
|
|
m_rfMainWindowViewModel = MainWindowViewModel
|
|
End Sub
|
|
|
|
#Region "COMMANDS"
|
|
|
|
#Region "AddDoorCommand"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do New.
|
|
''' </summary>
|
|
Public ReadOnly Property AddDoorCommand As ICommand
|
|
Get
|
|
If m_cmdAddDoor Is Nothing Then
|
|
m_cmdAddDoor = New Command(AddressOf AddDoor)
|
|
End If
|
|
Return m_cmdAddDoor
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Execute the New. This method is invoked by the NewCommand.
|
|
''' </summary>
|
|
Public Sub AddDoor()
|
|
Dim NameExist As Boolean = True
|
|
' lancio la finestra per la creazione di una nuova porta
|
|
Dim SaveFileDialog As New EgtWPFLib5.EgtSaveFileDialog
|
|
SaveFileDialog.Title = K_NEWDOOR
|
|
SaveFileDialog.Directory = m_CurrProject.Name
|
|
SaveFileDialog.Extension = K_DDFEXTENSION
|
|
'SaveFileDialog.FileName = m_CurrProject.Name & "\"
|
|
' se decido di chiuedere la finestra
|
|
If Not SaveFileDialog.EgtShowDialog Then
|
|
Return
|
|
End If
|
|
' Controllo se ha estensione il nome della porta
|
|
If Path.HasExtension(SaveFileDialog.FileName) Then
|
|
Dim sExtension As String = Path.GetExtension(SaveFileDialog.FileName)
|
|
If Not sExtension.ToLower = K_DDFEXTENSION Then
|
|
SaveFileDialog.FileName = SaveFileDialog.FileName.Replace(sExtension, K_DDFEXTENSION)
|
|
End If
|
|
Else
|
|
SaveFileDialog.FileName &= K_DDFEXTENSION
|
|
End If
|
|
|
|
'' '' controllo che il nome del file già non esiste nella lista!
|
|
' ''If CurrProject.DoorList.Count > 0 Then
|
|
' '' For IndexDoorList = 0 To CurrProject.DoorList.Count - 1
|
|
' '' ' se il nome esiste già nella lista
|
|
' '' If CurrProject.DoorList(IndexDoorList) = SaveFileDialog.FileName Then
|
|
' '' MessageBox.Show(String.Format(EgtMsg(50114), CurrProject.Name), EgtMsg(50115), MessageBoxButton.OK, MessageBoxImage.Exclamation)
|
|
' '' 'esco dalla lista e chiedo nuovamente il nome da inserire
|
|
' '' NameExist = True
|
|
' '' Exit For
|
|
' '' Else
|
|
' '' NameExist = False
|
|
' '' End If
|
|
' '' Next
|
|
' ''Else
|
|
' '' ' sicuramente non esiste alcuna porta
|
|
' '' NameExist = False
|
|
' ''End If
|
|
'' '' se il nome esiste allora esco dalla sub
|
|
' ''If NameExist Then Exit Sub
|
|
' altrimenti se non esco
|
|
|
|
' aggiungo il nome del file alla lista delle porte
|
|
CurrProject.DoorList.Add(SaveFileDialog.FileName)
|
|
' aggiorno la lista
|
|
CurrProject.NotifyPropertyChanged("DoorList")
|
|
NewDoor = True
|
|
SelectedDoor = SaveFileDialog.FileName
|
|
DeleteNewDoor = 0
|
|
'm_rfMainWindowViewModel.ProjectNameMsg = "*"
|
|
End Sub
|
|
|
|
#End Region ' AddDoorCommand
|
|
|
|
#Region "RemoveDoorCommand"
|
|
|
|
''' <summary>
|
|
''' Returns a command that do New.
|
|
''' </summary>
|
|
Public ReadOnly Property RemoveDoorCommand As ICommand
|
|
Get
|
|
If m_cmdRemoveDoor Is Nothing Then
|
|
m_cmdRemoveDoor = New Command(AddressOf RemoveDoor)
|
|
End If
|
|
Return m_cmdRemoveDoor
|
|
End Get
|
|
End Property
|
|
|
|
''' <summary>
|
|
''' Execute the New. This method is invoked by the NewCommand.
|
|
''' </summary>
|
|
Public Sub RemoveDoor()
|
|
|
|
If Not IsNothing(m_SelectedDoor) Then
|
|
DeleteNewDoor = -1
|
|
' salvo il nome del file che sta per essere eliminato
|
|
Dim RemoveDoorName As String = Path.GetFileNameWithoutExtension(m_SelectedDoor)
|
|
' chiedo se devo eliminere il file: se si
|
|
If MessageBox.Show(String.Format(EgtMsg(50116), Path.GetFileNameWithoutExtension(m_SelectedDoor)), EgtMsg(50110), MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No) = MessageBoxResult.Yes Then
|
|
' ricerco l'indice del file all'interno della lista delle porte
|
|
Dim SelIndex As Integer = m_CurrProject.DoorList.IndexOf(m_SelectedDoor)
|
|
' elimino dall'elenco dei file
|
|
File.Delete(m_SelectedDoor)
|
|
' elimino dalla lista
|
|
m_CurrProject.DoorList.Remove(m_SelectedDoor)
|
|
CurrProject.NotifyPropertyChanged("DoorList")
|
|
' per quando torno nel m_SelectedDoor...per non chiedere di salvare o eliminare
|
|
DeleteNewDoor = -1
|
|
' se la lista non è rimasta vuota
|
|
If m_CurrProject.DoorList.Count > 0 Then
|
|
' aggiorno la porta da visualizzare
|
|
If SelIndex > m_CurrProject.DoorList.Count - 1 Then
|
|
SelectedDoor = m_CurrProject.DoorList(SelIndex - 1)
|
|
Else
|
|
SelectedDoor = m_CurrProject.DoorList(SelIndex)
|
|
End If
|
|
' se non ci sono altre porte nella lista allora
|
|
Else
|
|
' elimino qualsiasi resto di porta
|
|
DirectCast(m_rfMainWindowViewModel.DoorParameters.DataContext, DoorParametersViewModel).CurrDoor = Nothing
|
|
' aggiorni l'immagine a nulla
|
|
EgtNewFile()
|
|
EgtZoom(ZM.ALL)
|
|
End If
|
|
MessageBox.Show(String.Format(EgtMsg(50117), RemoveDoorName), EgtMsg(50118), MessageBoxButton.OK, MessageBoxImage.Information)
|
|
Else
|
|
' altrimenti salvo il file
|
|
DdfFile.WriteDDF(DirectCast(m_rfMainWindowViewModel.DoorParameters.DataContext, DoorParametersViewModel).CurrDoor, m_SelectedDoor, True)
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
#End Region ' RemoveDoorCommand
|
|
|
|
#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
|
|
|
|
' Restituisce solo il nome del file del progetto aperto
|
|
Public Class PathConverter
|
|
Implements IValueConverter
|
|
|
|
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
|
|
Dim sPath As String = CStr(value)
|
|
Return Path.GetFileNameWithoutExtension(sPath)
|
|
End Function
|
|
|
|
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
|
|
Throw New NotImplementedException
|
|
End Function
|
|
|
|
End Class
|
|
|
|
' Nasconde i pulsanti +/- se la lista di porte non contiene nulla
|
|
Public Class ProjectVisibilityConverter
|
|
Implements IValueConverter
|
|
|
|
Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert
|
|
Dim sProjectName As String = CStr(value)
|
|
Return If(Directory.Exists(sProjectName), Visibility.Visible, Visibility.Collapsed)
|
|
End Function
|
|
|
|
Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
|
|
Throw New NotImplementedException
|
|
End Function
|
|
|
|
End Class |