Files
2025-03-03 12:39:45 +01:00

320 lines
13 KiB
VB.net

Imports System.ComponentModel
Imports System.Collections.ObjectModel
Imports EgtUILib
Imports System.IO
Public Class CompoPanelVM
Implements INotifyPropertyChanged
Private m_ErroLoadCompo As String = String.Empty
Public ReadOnly Property ErrorLoadCompo As String
Get
Return m_ErroLoadCompo
End Get
End Property
Private m_PageName As String = String.Empty
Public ReadOnly Property GoToAssembly As String
Get
' 50720=GoToAssembly
Return EgtMsg(50720)
End Get
End Property
Private m_CompoTypeList As New ObservableCollection(Of CompoType)
Public ReadOnly Property CompoTypeList As ObservableCollection(Of CompoType)
Get
Return m_CompoTypeList
End Get
End Property
Private m_IsVisible As Visibility
Public Property IsVisible As Visibility
Get
Return m_IsVisible
End Get
Set(value As Visibility)
m_IsVisible = value
NotifyPropertyChanged("IsVisible")
End Set
End Property
Private m_GoBackVisibility As Visibility = Visibility.Visible
Public Property GoBackVisibility As Visibility
Get
Return m_GoBackVisibility
End Get
Set(value As Visibility)
m_GoBackVisibility = value
NotifyPropertyChanged("GoBackVisibility")
End Set
End Property
Public ReadOnly Property EnableModify As Boolean
Get
Return Not OptionModule.ReadOnlyDDF
End Get
End Property
' Definizione comando
Private m_CmdCompoBtn As ICommand
Private m_CmdGoToAssemblyBtn As ICommand
' definizione comando
Private m_EnterRefreshCmd As ICommand
Sub New(Page As String)
m_PageName = Page
'Map.SetRefCompoPanelVM(Me)
'Map.SetRefCompoPaneHardwarelVM(Me)
If m_CompoTypeList.Count > 0 Then Return ' se la lista è già caricata esco (Lista di tipo shared)
Dim IndexCompoOrder = 0
' Lettura file ini per generare bottoni
Dim Index As Integer = 1
Dim CompoName As String = String.Empty
Dim CompoNameDDF As String = String.Empty
Dim Image As String = String.Empty
Dim Side As String = String.Empty
Dim FolderName As String = String.Empty
' Carico un vettore con il nome delle Path delle componenti
If Not Directory.Exists(IniFile.m_CompoDir) Then
' CompoDir not found :
EgtOutLog(EgtMsg(50165) & IniFile.m_CompoDir)
Return
End If
Dim CompoArray() As String = Directory.GetDirectories(IniFile.m_CompoDir)
Dim ListCompoToInsert As New List(Of VerifyCompo)
For Ind As Integer = 0 To DdfFile.CompoListOrder.Count - 1
ListCompoToInsert.Add(New VerifyCompo(DdfFile.CompoListOrder(Ind), False))
Next
' Verifico che la lista Panel abbia un numero di elementi uguale o minore di quella DDF
If OptionModule.m_CompoPaneOrder.Count > DdfFile.CompoListOrder.Count Then
Dim ListCompoToShow As New List(Of VerifyCompo)
For Ind As Integer = 0 To OptionModule.m_CompoPaneOrder.Count - 1
ListCompoToShow.Add(New VerifyCompo(OptionModule.m_CompoPaneOrder(Ind), False))
Next
' cerco quali sono le componenti in esubero nella lista CompoPane
For Each ItemCompoPane As String In DdfFile.CompoListOrder
ListCompoToShow.Find(Function(x) x.sName = ItemCompoPane).SetExists(True)
Next
' recupero i nomi delle componenti non presenti nell'elenco DDF
Dim sMissingCompoInDDFList As String = String.Empty
For Each Item As VerifyCompo In ListCompoToShow
If Not Item.bExists Then
If String.IsNullOrEmpty(sMissingCompoInDDFList) Then
sMissingCompoInDDFList = Item.sName
Else
sMissingCompoInDDFList &= ", " & Item.sName
End If
End If
Next
m_ErroLoadCompo = "Verify component in CompoPanelOrder: " & sMissingCompoInDDFList
Return
End If
' carico i valori dei bottoni con un preciso ordine
Dim CompoPanelList As List(Of String) = OptionModule.m_CompoPaneOrder
For IndexCompoOrder = 0 To CompoPanelList.Count() - 1 ' DdfFile.CompoListOrder.Count - 1
For Index = 0 To CompoArray.Count - 1
' apro ogni directory e cerco un file di testo di nome Config.ini
Dim CurrCompoPath As String = CompoArray(Index) & "\" & ConstCompo.CONFIGINI_FILE_NAME
If File.Exists(CurrCompoPath) Then
Image = String.Empty
GetPrivateProfileCompoName(ConstCompo.S_COMPO, ConstCompo.K_NAME, CompoNameDDF, CompoName, CurrCompoPath)
GetPrivateProfileCompoImage(ConstCompo.S_COMPO, ConstCompo.K_IMAGE, Image, CurrCompoPath)
GetPrivateProfileJambSide(S_POSITIONSIDE, K_SIDE, Side, CurrCompoPath)
GetPrivateProfileFolderName(S_TEMPLATE, K_FOLDER_NAME, FolderName, CurrCompoPath)
If CompoPanelList(IndexCompoOrder) = CompoNameDDF Then
Dim Local_NewCompoType As CompoType
If Not String.IsNullOrEmpty(Image) Then
Local_NewCompoType = New CompoType(CompoName, CompoNameDDF, CompoArray(Index), Image, Side, FolderName, "wood")
Else
Local_NewCompoType = New CompoType(CompoName, CompoNameDDF, CompoArray(Index), Side, FolderName)
End If
m_CompoTypeList.Add(Local_NewCompoType)
ListCompoToInsert.Find(Function(x) x.sName = CompoNameDDF).SetExists(True)
' aggiungere il caricamento delle liste
Exit For
End If
End If
Next
Next
' verifica nella lista di partenza quali sono i componenti che non sono stati caricati
m_ErroLoadCompo = String.Empty
' cerco eventuali discrepanze tra la lista DDF e la lista Panel
Dim sMissingCompoInPanel As String = String.Empty
For nInd As Integer = 0 To ListCompoToInsert.Count - 1
Dim DDFCompoName As String = ListCompoToInsert(nInd).sName
If IsNothing(CompoPanelList.Find(Function(x) x = DDFCompoName)) Then
If String.IsNullOrEmpty(sMissingCompoInPanel) Then
sMissingCompoInPanel = "Missing component Panel button: " & vbCrLf & " - " & DDFCompoName
Else
sMissingCompoInPanel &= vbCrLf & " - " & DDFCompoName
End If
ListCompoToInsert(nInd).SetExists(True)
End If
Next
' cerco discrepanze tra la lista dei bottoni e direttori
For Each Item As VerifyCompo In ListCompoToInsert
If Not Item.bExists Then
If String.IsNullOrEmpty(m_ErroLoadCompo) Then
m_ErroLoadCompo = "Missing component Directory: " & vbCrLf & " - " & Item.sName
Else
m_ErroLoadCompo &= vbCrLf & " - " & Item.sName
End If
End If
Next
If Not String.IsNullOrEmpty(sMissingCompoInPanel) Then
m_ErroLoadCompo &= vbCrLf & sMissingCompoInPanel
End If
End Sub
#Region "COMMANDS"
#Region "CompoBtnCommand"
Public ReadOnly Property CompoBtnCommand As ICommand
Get
If m_CmdCompoBtn Is Nothing Then
m_CmdCompoBtn = New Command(AddressOf CompoBtn)
End If
Return m_CmdCompoBtn
End Get
End Property
Public Sub CompoBtn(param As Object)
' distinguo il modo di caricare i valori a secondo della pagina aperta
If Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nHardwarePage Then
' devo controllare se devo salvare le modifiche fatte
If Not IsNothing(Map.refHardwarePageVM) Then ' se la pagina è aperta
If Not IsNothing(Map.refHardwarePageVM.CurrHardware) Then ' se un hardware esiste
If Map.refHardwarePageVM.CurrHardware.SaveControl() = Hardware.SaveResult.nCancel Then Return ' controllo se devo salvare le modifiche
' elimino CurrHardware
Map.refHardwarePageVM.CurrHardware.DeleteTempFile()
End If
' seleziono il nuovo Hardware
Dim m_CurrCompoType As CompoType = DirectCast(param, CompoType)
For IndexCompoType As Integer = 0 To Map.refCompoPanelHardwareVM.CompoTypeList.Count - 1
If m_CurrCompoType.Name <> Map.refCompoPanelHardwareVM.CompoTypeList(IndexCompoType).Name Then
Map.refCompoPanelHardwareVM.CompoTypeList(IndexCompoType).IsSelectedBtn = False
Else
Map.refCompoPanelHardwareVM.CompoTypeList(IndexCompoType).IsSelectedBtn = True
End If
Next
' ogni volta che clicco il bottone definisco un nuovo Hardware
Map.refHardwarePageVM.CurrHardware = New Hardware
Map.refHardwarePageVM.VisibilityGeneral = Visibility.Visible
Map.refHardwarePageVM.CurrHardware.LoadTemplate(m_CurrCompoType)
' Apro il progetto di esempio del tipo del bottone selezionato
Map.refHardwareHelpSceneHostV.LoadHelpProject()
End If
'------------------------------------------------------------------------------------------------------------------------------
Else ' se non sono nella configurazione Hardware
Dim m_CurrCompoType As CompoType = DirectCast(param, CompoType)
m_CurrCompoType.LoadListTemplate()
If Not IsNothing(Map.refPartPageVM.CurrPart) Then
Dim IsFrame As Boolean = False
If Map.refPartPageVM.CurrPart.TypePart.Contains("F") Then IsFrame = True
Dim NewCompo As Compo = Map.refPartPageVM.CurrPart.AddNewCompo(m_CurrCompoType, IsFrame)
If IsNothing(NewCompo) Then Return
' aggiorno lista hardware di quotatura
Map.refDimensioningPanelVM.LoadHardwareDimList()
' aggiungo le componenti sui Jamb
If IsNothing(Map.refAssemblyPageVM.CurrAssembly) Then
Map.refAssemblyPageVM.CurrAssembly.CreateCompoOnJamb(NewCompo, "")
End If
Map.refSceneManagerVM.RefreshBtn()
' evidenzio componente
Map.refPartPageVM.CurrPart.MarkCompoInScena()
Else
MessageBox.Show(EgtMsg(50108), EgtMsg(50101), MessageBoxButton.OK, MessageBoxImage.Exclamation)
End If
End If
End Sub
#End Region ' CompoBtnCommand
#Region "GoToAssemblyBtnCommand"
Public ReadOnly Property GoToAssemblyBtnCommand As ICommand
Get
If m_CmdGoToAssemblyBtn Is Nothing Then
m_CmdGoToAssemblyBtn = New Command(AddressOf GoToAssemblyBtn)
End If
Return m_CmdGoToAssemblyBtn
End Get
End Property
Public Sub GoToAssemblyBtn(param As Object)
If OptionModule.m_ConfigurationSoftware = ConfigType.Assembly Then
Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nAssemblyPage
' aggiorno lista hardware di quotatura
Map.refDimensioningPanelVM.LoadHardwareDimList()
Map.refSceneManagerVM.RefreshBtn()
Map.refAssemblyPageVM.SlectedPart = "AssemblyPage"
Else
Map.refCompoPanelVM.GoBackVisibility = Visibility.Collapsed
Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nDDFPage
Map.refSceneManagerVM.RefreshBtn()
End If
Map.refProjectManagerVM.NotifyPropertyChanged("VisibilityCreateAssembly")
End Sub
#End Region ' GoToAssemblyBtnCommand
#Region "ENTERREFRESH"
Public ReadOnly Property RefreshCmd As ICommand
Get
If m_EnterRefreshCmd Is Nothing Then
m_EnterRefreshCmd = New Command(AddressOf EnterRefresh)
End If
Return m_EnterRefreshCmd
End Get
End Property
Public Sub EnterRefresh()
Map.refSceneManagerVM.RefreshBtn()
End Sub
#End Region ' EnterRefresh
#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 VerifyCompo
Private m_sName As String
Public ReadOnly Property sName As String
Get
Return m_sName
End Get
End Property
Private m_bExists As Boolean = False
Public ReadOnly Property bExists As Boolean
Get
Return m_bExists
End Get
End Property
Public Sub SetExists(Exists As Boolean)
m_bExists = Exists
End Sub
Sub New(Name As String, Exists As Boolean)
m_sName = Name
m_bExists = Exists
End Sub
End Class