Files
EgtDOORCreator/AssemblyManager/AssemblyManagerVM.vb
T
2025-04-07 15:58:14 +02:00

1827 lines
94 KiB
VB.net

Imports System.Collections.ObjectModel
Imports System.IO
Imports EgtUILib
Imports EgtWPFLib5
Public Class AssemblyManagerVM
Inherits VMBase
' 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
NotifyPropertyChanged("CurrProject")
End Set
End Property
Private m_VisibilityDoorList As Visibility = Visibility.Collapsed
Public Property VisibilityDoorList As Visibility
Get
Return m_VisibilityDoorList
End Get
Set(value As Visibility)
m_VisibilityDoorList = value
NotifyPropertyChanged("VisibilityDoorList")
End Set
End Property
Public ReadOnly Property EnableAssebmlyManager As Boolean
Get
If Not IsNothing(Map.refInstrumentPanelVM) Then
Return Map.refInstrumentPanelVM.EnablePage
Else
Return True
End If
End Get
End Property
#Region "MESSAGES"
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
#End Region 'MESSAGES
' Definizione comandi
Private m_cmdAddAssembly As ICommand
Private m_cmdRemoveAssembly As ICommand
Sub New()
Map.SetRefDoorManagerVM(Me)
End Sub
#Region "METHODS"
#Region "Apertura e salvataggio"
Public Sub NewCmd(NewAssName As AssemblyName)
' segno come modificato il nome dell'assemblato
CurrProject.SelAssemblyName.IsModified = True
' definisco e rimuovo file temporaneo di assemblato
Dim sTempFile As String = IniFile.m_sTempDir & "\" & TEMP_FILE
Try
File.Delete(sTempFile)
Catch ex As Exception
End Try
' creo nuovo assemblato
m_CurrProject.SelAssemblyName.SelAssembly = CreateNewAssembly(CurrProject.SelAssemblyName.Name)
If OptionModule.m_ConfigurationSoftware = ConfigType.Door Then
' ricarico la lista completa degli swing
NewAssName.SelAssembly.ListPartDoor(0).Door.SwingTypeList = OptionModule.m_SwingTypeList
If String.IsNullOrEmpty(NewAssName.SelAssembly.ListPartDoor(0).Door.Swing) Then
NewAssName.SelAssembly.ListPartDoor(0).Door.SetSwing(OptionModule.m_Swing)
End If
DdfFile.WriteDDFPart(NewAssName.SelAssembly.ListPartDoor(0).Door, sTempFile, False, False)
' assegno la porte salvata nel CurrPart.ddf come porta corrente del progetto
Map.refPartPageVM.CurrPart = NewAssName.SelAssembly.ListPartDoor(0).Door
' aggiorno elenco quotature
Map.refDimensioningPanelVM.LoadHardwareDimList()
ExecDoors(Map.refSceneManagerVM.ProjectScene, sTempFile, False)
' rendo visibili quotature
For Each HardwareDimension In Map.refDimensioningPanelVM.HardwareDimensionList
PrintWndVM.TurnDimensioningLayer(HardwareDimension.NameLayer, HardwareDimension.SelectedLayer)
Next
EgtZoom(ZM.ALL)
Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nDDFPage
Else
DdfFile.WriteDDFAssembly(NewAssName.SelAssembly, sTempFile, False)
' aggiorno elenco quotature
Map.refDimensioningPanelVM.LoadHardwareDimList()
ExecDoors(Map.refSceneManagerVM.ProjectScene, sTempFile, False)
' rendo visibili quotature
For Each HardwareDimension In Map.refDimensioningPanelVM.HardwareDimensionList
PrintWndVM.TurnDimensioningLayer(HardwareDimension.NameLayer, HardwareDimension.SelectedLayer)
Next
EgtZoom(ZM.ALL)
Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nAssemblyPage
End If
Return
End Sub
Public Function Save(SavedAssName As AssemblyName) As Boolean
If IsNothing(SavedAssName) OrElse IsNothing(SavedAssName.SelAssembly) Then Return False
Dim ErrorMessages As String = String.Empty
Dim sTempFile As String = IniFile.m_sTempDir & "\" & TEMP_FILE
DdfFile.SaveErrorCompo = True
Map.refSceneManagerVM.RefreshBtn()
DdfFile.SaveErrorCompo = False
Dim bConfirmSavin As Boolean = False
' verifico se il ddf presenta degli errori, se ignoro gli errori salvo
bConfirmSavin = ConfirmSaving(DdfFile.ErrorInWriting)
If Not bConfirmSavin Then Return False
'Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.IsModified = False
TrimFileName(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.Name)
' Salvo
If OptionModule.m_ConfigurationSoftware = ConfigType.Door Then
' questa condizione non DOVREBBE mai accadere, perchè viene interrotto prima il caricamento
If SavedAssName.SelAssembly.ListPartDoorOfDoor.Count < 1 Then
' 50540 = The current ddf is a part of a frame, do you want to save?
If MessageBox.Show(EgtMsg(50540), EgtMsg(50144), MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No) = MessageBoxResult.Yes Then
DdfFile.SaveErrorCompo = True
Dim _IsDDF As Boolean = IsCurrentFileDDF(SavedAssName.Name)
DdfFile.WriteDDFPart(SavedAssName.SelAssembly.ListPartDoor(0).Door, SavedAssName.Name, _IsDDF, False)
DdfFile.SaveErrorCompo = False
Else
Return False
End If
Else
DdfFile.SaveErrorCompo = True
Dim _IsDDF As Boolean = IsCurrentFileDDF(SavedAssName.Name)
DdfFile.WriteDDFPart(SavedAssName.SelAssembly.ListPartDoor(0).Door, SavedAssName.Name, _IsDDF, False)
DdfFile.SaveErrorCompo = False
End If
Else
' Se il ddf che sto leggendo è composto dal al massimo due parti significa che c'è un errore
If SavedAssName.SelAssembly.bOk = Assembly.ResultReadingAssembInfo.CorrectAssembInfo AndAlso
SavedAssName.SelAssembly.ListPartDoor.Count < 3 Then
' Se sto salvando meno di tre componenti significa che mancano qualche pezzo per essere un assemblato
SavedAssName.SelAssembly.bOk = Assembly.ResultReadingAssembInfo.MissingAssembInfo
End If
Dim ErrorMessage As String = SavedAssName.SelAssembly.ControlAssembly(True)
Dim m_MessageBoxResult As MessageBoxResult = MessageBoxResult.Cancel
If Not String.IsNullOrEmpty(ErrorMessage) Then
' Richiedo di scegliere se salvare come porta singola oppure come assemblato (altrimenti annullo il salvataggio)
If GetMainPrivateProfileInt(S_GENERAL, K_SAVEASSINGLEDOOR, 0) <> 0 Then
' 50732=Save as Assembly (YES), Single door (NO).
m_MessageBoxResult = MessageBox.Show(EgtMsg(50732), EgtMsg(50144), MessageBoxButton.YesNoCancel, MessageBoxImage.Warning, MessageBoxResult.No)
If m_MessageBoxResult = MessageBoxResult.Cancel Then
' interrompo il salvataggio
Return False
End If
If m_MessageBoxResult = MessageBoxResult.Yes Then
' Procedo a sovrascrivere il file come ASSEMBALTO
DdfFile.SaveErrorCompo = True
DdfFile.WriteDDFAssembly(SavedAssName.SelAssembly, SavedAssName.Name, True)
DdfFile.SaveErrorCompo = False
ElseIf m_MessageBoxResult = MessageBoxResult.No Then
' Procedo a sovrascrivere il file come SINGLE DOOR
DdfFile.SaveErrorCompo = True
Dim _IsDDF As Boolean = IsCurrentFileDDF(SavedAssName.Name)
DdfFile.WriteDDFPart(SavedAssName.SelAssembly.ListPartDoor(0).Door, SavedAssName.Name, _IsDDF, False)
DdfFile.SaveErrorCompo = False
End If
Else
' Avviso che sto per salvare una porta singola come assemblato (altrimenti annullo il salvataggio)
If Not MessageBox.Show(ErrorMessage, EgtMsg(50144), MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No) = MessageBoxResult.Yes Then
Return False
End If
' Procedo a sovrascrivere il file
DdfFile.SaveErrorCompo = True
DdfFile.WriteDDFAssembly(SavedAssName.SelAssembly, SavedAssName.Name, True)
DdfFile.SaveErrorCompo = False
End If
Else
' Non ci sono errori: procedo a sovrascrivere il file
DdfFile.SaveErrorCompo = True
DdfFile.WriteDDFAssembly(SavedAssName.SelAssembly, SavedAssName.Name, True)
DdfFile.SaveErrorCompo = False
End If
End If
' controllo che il salvataggio sia andato a buon fine
If bConfirmSavin Then
SavedAssName.IsModified = False
' ogni progetto salvato è l'ultimo da aprire, anche se il programma è chiuso dall'HardwareManager
WriteMainPrivateProfileString(S_LAUNCHERWINDOW, K_LASTPROJECT, Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.Name)
SavedAssName.NotifyPropertyChanged("IsModify")
Else
Return False
End If
Return True
End Function
' in fase di scrittura del file dei messaggi leggo gli errori che sono stati comunicati
Private Function ConfirmSaving(sMessages As String) As Boolean
If Not String.IsNullOrEmpty(sMessages) Then
' 50503=Do you want to save?
DdfFile.ErrorInWriting &= vbCrLf & EgtMsg(50503)
If MessageBox.Show(DdfFile.ErrorInWriting, EgtMsg(50101), MessageBoxButton.YesNo, MessageBoxImage.Error) = MessageBoxResult.Yes Then
DdfFile.DDFIsCorrect = True
Else
DdfFile.DDFIsCorrect = False
End If
End If
Return DdfFile.DDFIsCorrect
End Function
Private Sub TrimFileName(ByRef sFileName As String)
If String.IsNullOrEmpty(sFileName) Then Return
If Trim(Path.GetFileNameWithoutExtension(sFileName)) <> Path.GetFileNameWithoutExtension(sFileName) Then
' 50115=Caution
' 50504=File name contains empty spaces, do you want to rename file deleting empty spaces?
If MessageBox.Show(EgtMsg(50504), EgtMsg(50115), MessageBoxButton.YesNo, MessageBoxImage.Warning) = MessageBoxResult.Yes Then
Dim FilePath = Path.GetFileNameWithoutExtension(sFileName)
Dim RenamePath = sFileName.Replace(FilePath, Trim(FilePath))
Try
FileSystem.Rename(sFileName, RenamePath)
sFileName = RenamePath
Catch ex As Exception
End Try
Else
Return
End If
End If
End Sub
' rileggo le componenti caricate di default e se possibile le correggo
Public Function RefreshAssembly(Optional ErCompo As Compo = Nothing) As Boolean
' se ricevo una componente specifica non controllo solo qella
If IsNothing(Map.refAssemblyManagerVM) OrElse
IsNothing(Map.refAssemblyManagerVM.CurrProject) OrElse
IsNothing(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName) OrElse
IsNothing(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.SelAssembly) OrElse
Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.SelAssembly.ListPartDoor.Count < 1 Then
Return False
End If
' creo una copia dell'assemblato
Dim CurrAssembly As Assembly = Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.SelAssembly
' se sono in modalità porta (e non assemblato)
If OptionModule.m_ConfigurationSoftware = ConfigType.Door Then
Dim CurrPart As Part = CurrAssembly.ListPartDoor(0).Door
Select Case Map.refMainWindowVM.selectedWatcher
' creazione di un file
Case MainWindowVM.WatcherCalling.OnCreated
' in fase di creazione devo scorrere tutte le componenti che sono CompoDDFName e che hanno il LoadDefault = True
If IsNothing(ErCompo) Then
Dim IndexCompo As Integer = 0
For IndexCompo = 0 To CurrAssembly.ListPartDoor(0).Door.m_CompoList.Count - 1
' se non ricevo il nome del direttorio allora scorro su tutte le componeti
If Not String.IsNullOrEmpty(Map.refMainWindowVM.CompoDDFName) Then
If Map.refMainWindowVM.CompoDDFName = CurrAssembly.ListPartDoor(0).Door.m_CompoList(IndexCompo).CompoType.DDFName Then
'CurrAssembly.ListPartDoor(0).Door.m_CompoList(IndexCompo).LoadByDefault Then
Dim ErrCompo As Compo = CurrAssembly.ListPartDoor(0).Door.m_CompoList(IndexCompo)
ReCreateCompo(ErrCompo, CurrPart, IndexCompo)
'RecreateCompoParm(ErrCompo, CurrPart)
End If
Else
'If CurrAssembly.ListPartDoor(0).Door.m_CompoList(IndexCompo).LoadByDefault Then
Dim ErrCompo As Compo = CurrAssembly.ListPartDoor(0).Door.m_CompoList(IndexCompo)
ReCreateCompo(ErrCompo, CurrPart, IndexCompo)
'RecreateCompoParm(ErrCompo, CurrPart)
'End If
End If
Next
Else
' se ricevo una componente specifica
If ErCompo.LoadByDefault Then ReCreateCompo(ErCompo, CurrPart)
'RecreateCompoParm(ErCompo, CurrPart)
End If
' eliminazione di un file
Case MainWindowVM.WatcherCalling.OnDeleted
' in fase di eliminazione devo scorrere tutte le componenti che sono CompoDDFName e che hanno il LoadDefault = false
If IsNothing(ErCompo) Then
Dim IndexCompo As Integer = 0
For IndexCompo = 0 To CurrAssembly.ListPartDoor(0).Door.m_CompoList.Count - 1
' se non ricevo il nome del direttorio allora scorro su tutte le componeti che hanno il LoadDefault = False
If Not String.IsNullOrEmpty(Map.refMainWindowVM.CompoDDFName) Then
If Map.refMainWindowVM.CompoDDFName = CurrAssembly.ListPartDoor(0).Door.m_CompoList(IndexCompo).CompoType.DDFName AndAlso
Not CurrAssembly.ListPartDoor(0).Door.m_CompoList(IndexCompo).LoadByDefault Then
Dim ErrCompo As Compo = CurrAssembly.ListPartDoor(0).Door.m_CompoList(IndexCompo)
ReCreateCompo(ErrCompo, CurrPart, IndexCompo)
'RecreateCompoParm(ErrCompo, CurrPart)
End If
Else
If Not CurrAssembly.ListPartDoor(0).Door.m_CompoList(IndexCompo).LoadByDefault Then
Dim ErrCompo As Compo = CurrAssembly.ListPartDoor(0).Door.m_CompoList(IndexCompo)
ReCreateCompo(ErrCompo, CurrPart, IndexCompo)
'RecreateCompoParm(ErrCompo, CurrPart)
End If
End If
Next
Else
' se ricevo una componente specifica
If Not ErCompo.LoadByDefault Then ReCreateCompo(ErCompo, CurrPart)
'RecreateCompoParm(ErCompo, CurrPart)
End If
' rinomina di un file
Case MainWindowVM.WatcherCalling.OnRenamed
' in fase di eliminazione devo scorrere tutte le componenti che sono CompoDDFName
If IsNothing(ErCompo) Then
Dim IndexCompo As Integer = 0
For IndexCompo = 0 To CurrAssembly.ListPartDoor(0).Door.m_CompoList.Count - 1
' se non ricevo il nome del direttorio allora scorro su tutte le componeti che hanno il LoadDefault = False
If Not String.IsNullOrEmpty(Map.refMainWindowVM.CompoDDFName) Then
If Map.refMainWindowVM.CompoDDFName = CurrAssembly.ListPartDoor(0).Door.m_CompoList(IndexCompo).CompoType.DDFName Then
Dim ErrCompo As Compo = CurrAssembly.ListPartDoor(0).Door.m_CompoList(IndexCompo)
ReCreateCompo(ErrCompo, CurrPart, IndexCompo)
'RecreateCompoParm(ErrCompo, CurrPart)
End If
Else
Dim ErrCompo As Compo = CurrAssembly.ListPartDoor(0).Door.m_CompoList(IndexCompo)
ReCreateCompo(ErrCompo, CurrPart, IndexCompo)
'RecreateCompoParm(ErrCompo, CurrPart)
End If
Next
Else
' se ricevo una componente specifica
ReCreateCompo(ErCompo, CurrPart)
'RecreateCompoParm(ErCompo, CurrPart)
End If
' cambiamento: questo metdod non è utlizzato
Case MainWindowVM.WatcherCalling.OnChanged
' permette di rileggere il file temporaneo
Case MainWindowVM.WatcherCalling.OnLoadTempFile
LoadTempFile()
Case Else
If Not IsNothing(ErCompo) Then
' ReCreateCompo(ErCompo, CurrPart)
RecreateCompoParm(ErCompo, CurrPart)
Else
Dim IndexDoor As Integer = 0
For IndexDoor = 0 To CurrAssembly.ListPartDoorOfDoor.Count - 1
Dim IndexCompo As Integer = 0
For IndexCompo = 0 To CurrAssembly.ListPartDoorOfDoor(IndexDoor).Door.m_CompoList.Count - 1
Dim ErrCompo As Compo = CurrAssembly.ListPartDoorOfDoor(IndexDoor).Door.m_CompoList(IndexCompo)
' ricevo l'inidice della componente per mantenere l'ordine
ReCreateCompo(ErrCompo, CurrPart, IndexCompo)
Next
Next
End If
' se sto forzando un ricalcolo completo di tutto faccio passare tutte le componenti senza pietà?
End Select
Map.refMainWindowVM.selectedWatcher = MainWindowVM.WatcherCalling.NoEvents
' se sono in modalità hardware allora esco senza caricare l'elenco delle porte
If Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nHardwarePage Then Return True
'-------------------------------------------------------------------------------------------------------------------------------------------------
' devo ricalcolare l'elenco delle porte nel progetto corrente:
If OptionModule.m_SingleDoor Then Return True
' calcolo l'elenco delle porte solo dopo il salvataggio della porta corrente
If Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.IsModified Then Return True
If Not IsNothing(Map.refAssemblyManagerVM.CurrProject) AndAlso Not String.IsNullOrEmpty(Map.refAssemblyManagerVM.CurrProject.Name) Then
Dim CurrAssemblyName As String = Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.Name
Map.refAssemblyManagerVM.CurrProject.AssemblyList = New ObservableCollection(Of AssemblyName)
Dim DDFArray() As String = Directory.GetFiles(Map.refAssemblyManagerVM.CurrProject.Name)
For IndexFile As Integer = 0 To DDFArray.Count - 1
If Path.GetExtension(DDFArray(IndexFile)).ToLower = DDF_EXTENSION Then
Dim NewAssembly As New AssemblyName
NewAssembly.Name = DDFArray(IndexFile)
NewAssembly.IsModified = False
Map.refAssemblyManagerVM.CurrProject.AssemblyList.Add(NewAssembly)
End If
Next
If Not IsNothing(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName) Then
Try
'Map.refAssemblyManagerVM.CurrProject = LocalCurrProject
'LocalCurrProject.SelAssemblyName = LocalCurrProject.AssemblyList.First(Function(x) x.Name = Local_AssemblyName.Name)
Map.refAssemblyManagerVM.CurrProject = Map.refAssemblyManagerVM.CurrProject
Map.refAssemblyManagerVM.CurrProject.SelAssemblyName = Map.refAssemblyManagerVM.CurrProject.AssemblyList.First(Function(x) x.Name = CurrAssemblyName)
Catch ex As Exception
EgtOutLog("Aggiornamento Progetto Corrente: impossibile caricare ultima porta")
End Try
End If
End If
'-------------------------------------------------------------------------------------------------------------------------------------------------
Else
If Not IsNothing(ErCompo) Then
' ReCreateCompo(ErCompo, CurrPart)
If Not IsNothing(Map.refPartPageVM) AndAlso Not IsNothing(Map.refPartPageVM.CurrPart) Then
RecreateCompoParm(ErCompo, Map.refPartPageVM.CurrPart)
End If
Else
Dim IndexPart As Integer = 0
For IndexPart = 0 To CurrAssembly.ListPartDoor.Count - 1
Dim IndexCompo As Integer = 0
For IndexCompo = 0 To CurrAssembly.ListPartDoor(IndexPart).Door.m_CompoList.Count - 1
If CurrAssembly.ListPartDoor(IndexPart).Door.m_CompoList(IndexCompo).LoadByDefault Then
CurrAssembly.ListPartDoor(IndexPart).Door.m_CompoList(IndexCompo).CompoType.LoadListTemplate()
Dim ErrCompo As Compo = CurrAssembly.ListPartDoor(IndexPart).Door.m_CompoList(IndexCompo)
Dim CurrPart As Part = CurrAssembly.ListPartDoor(IndexPart).Door
ReCreateCompo(ErrCompo, CurrPart)
End If
Next
Next
End If
End If
Return True
End Function
' ricerca il tipo di compoente chiamato
Private Function SearchCompotypeIndex(sDDFName As String) As Integer
Dim CompoListIndex As Integer = -1
For CmpInd = 0 To Map.refCompoPanelVM.CompoTypeList.Count() - 1
' eseguo il confronto con il nome dei componenti che è stato caricato dal file Default.ini
If Map.refCompoPanelVM.CompoTypeList(CmpInd).DDFName = sDDFName Then
CompoListIndex = CmpInd
Exit For
End If
Next
Return CompoListIndex
End Function
' ricarica l'elenco dei file per la componnete selezionata
Private Function ReCreateCompo(ByRef ErrCompo As Compo, CurrPart As Part, Optional ByVal IndexCompo As Integer = -1) As Boolean
Dim DDFIsModified As Boolean = Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.IsModified
' Controllo esistenza del componente
Dim CompoListIndex As Integer = -1
CompoListIndex = SearchCompotypeIndex(ErrCompo.CompoType.DDFName)
' verifico che la componente non esiste
If CompoListIndex = -1 Then Return False
Dim m_CurrCompo = New Compo(Map.refCompoPanelVM.CompoTypeList(CompoListIndex))
' Se previsto template o shape da configurazione
Dim CurrCompoTypePath As String = Map.refCompoPanelVM.CompoTypeList(CompoListIndex).Path
Dim nIsActive As Integer = EgtUILib.GetPrivateProfileInt(S_TEMPLATE, K_ISACTIVE, 1, CurrCompoTypePath & "\" & CONFIGINI_FILE_NAME)
' leggo se template o shape
Dim Name As String = String.Empty
Dim DDFName As String = String.Empty
IniFile.GetPrivateProfileCompoName(S_TEMPLATE, K_NAME, DDFName, Name, CurrCompoTypePath & "\" & CONFIGINI_FILE_NAME)
' inizializzazione della componente
m_CurrCompo.TemplateDDFName = DDFName
m_CurrCompo.TemplateName = Name
If ErrCompo.SelBrandPart.Contains(FRAME_FOLDER) Then
CurrPart.LoadBrandFileList(m_CurrCompo, True)
Else
CurrPart.LoadBrandFileList(m_CurrCompo)
End If
If IsNothing(m_CurrCompo) Then Return False
' verifico che i nomi che sono caricati esistano
Dim bBrandExists As Boolean = False
Dim bFileExists As Boolean = False
Dim sBrand As String = ErrCompo.SelBrandPart
For IndexBrand As Integer = 0 To m_CurrCompo.BrandListPart.Count - 1
If sBrand.ToLower = m_CurrCompo.BrandListPart(IndexBrand).ToLower Then
m_CurrCompo.SelBrandPart = m_CurrCompo.BrandListPart(IndexBrand)
m_CurrCompo.MissingDirectory = False
bBrandExists = True
Exit For
End If
Next
If bBrandExists Then
For IndexFile As Integer = 0 To m_CurrCompo.FileList.Count - 1
If ErrCompo.SelFile.ToLower = m_CurrCompo.FileList(IndexFile).ToLower Then
m_CurrCompo.SelFile = m_CurrCompo.FileList(IndexFile)
m_CurrCompo.MissingFile = False
bFileExists = True
Exit For
End If
Next
End If
' in caso sia fallita la ricera dei direttori o dei file
If Not bBrandExists OrElse Not bFileExists Then
'' se la compoenente che sto caricando era corretta
'ErrCompo.LoadByDefault = True
' se il brand non esiste, ma è selezionato
If Not bBrandExists Then
ErrCompo.MissingDirectory = True
ErrCompo.MissingFile = True
' aggiungo alla lista dei brand che esistono quelli sbagliati, ed elimino quelli che non sono in quel momento selezioanti
RefreshListFile(m_CurrCompo.BrandListPart, ErrCompo.BrandListPart)
If Not ErrCompo.LoadByDefault Then
For Each BrandItem In ErrCompo.BrandListPart
' ricerco l'elemento selezionato
If BrandItem = ErrCompo.SelBrandPart Then
' se il direttorio non esiste ne viene creato uno fasullo, o recupera i file che appartngono al direttorio fasullo
ErrCompo.SelBrandPart = BrandItem
If ErrCompo.FileList.Count < 1 Then
ErrCompo.FileList.Add(ErrCompo.SelFile)
End If
ErrCompo.SelFile = ErrCompo.FileList(ErrCompo.FileList.Count - 1)
End If
Next
End If
Else
ErrCompo.MissingDirectory = False
End If
If Not bFileExists AndAlso bBrandExists Then
ErrCompo.MissingFile = True
'If Map.refMainWindowVM.selectedWatcher = MainWindowVM.WatcherCalling.OnRenamed Then
RefreshListFile(m_CurrCompo.FileList, ErrCompo.FileList)
'End If
End If
' se la compoenente che sto caricando era corretta
ErrCompo.LoadByDefault = True
If Not DDFIsModified Then
Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.IsModified = False
End If
Return False
End If
Dim sErrorInfo As String = String.Empty
CopyCompoParamList(m_CurrCompo.CompoParamList, ErrCompo.CompoParamList)
m_CurrCompo.m_ParameterDDfList = ErrCompo.m_ParameterDDfList
If Not ReadParams(m_CurrCompo, sErrorInfo) Then
m_CurrCompo.MissingParameter = ErrCompo.MissingParameter
m_CurrCompo.ErrorValue = ErrCompo.ErrorValue
End If
m_CurrCompo.LoadByDefault = False
'm_CurrCompo.ErrorColor = ErrCompo.ErrorColor
ErrCompo.Delete(False)
If IndexCompo > -1 Then
CurrPart.CompoList.Insert(IndexCompo, m_CurrCompo)
Else
CurrPart.CompoList.Add(m_CurrCompo)
End If
If Not DDFIsModified Then
Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.IsModified = False
End If
Return True
End Function
' Leggo i parametri del componente
Public Function ReadParams(ByRef CompoTemplateItem As Compo, ByRef sErrorInfo As String) As Boolean
Dim IndexLine As Integer = 0
If CompoTemplateItem.m_ParameterDDfList.Count < 1 Then Return False
Dim FileContent As List(Of String) = CompoTemplateItem.m_ParameterDDfList
' questo è l'indice dei parametri del componente
Dim IndexParam As Integer = 0
Dim ErrParamList As New List(Of String)
While IndexParam < CompoTemplateItem.CompoParamList.Count
' carico la lista dei parametri della componente parametro per parametro
Dim CurrCompoParam As CompoParam = CompoTemplateItem.CompoParamList(IndexParam)
' Controllo che il file non sia terminato
If IndexLine < FileContent.Count Then
Dim sLine As String = RemoveComment(FileContent(IndexLine))
' se stringa vuota o tutto commento, vado oltre
If String.IsNullOrWhiteSpace(sLine) Then
IndexLine += 1
Continue While
End If
' se fine pezzo o fine file o nome o metacomando, esco dal ciclo
If Search3Hyphens(sLine) OrElse Search3Dots(sLine) OrElse
Not String.IsNullOrWhiteSpace(GetName(sLine)) OrElse
sLine.Trim().StartsWith(DDF_METADATA) Then
If Not TypeOf CurrCompoParam Is TextBoxOnOffParam AndAlso Not TypeOf CurrCompoParam Is ComboBoxOnOffParam Then
' restituisco il messaggio che manca un parametro
' Error in reading: line {0}. Expected {1}.
sErrorInfo &= String.Format(EgtMsg(50139), IndexLine + 1, Trim(CompoTemplateItem.CompoParamList(IndexParam).DDFName))
' All missing params will be initialized by default.
sErrorInfo &= String.Format(Environment.NewLine & EgtMsg(50140)) & vbCrLf
Part.FirstReadingEdge = True
CompoTemplateItem.MissingParameter = True
CurrCompoParam.MissingParameterInReading = True
Else
' significa che la TextBoxOnOff è stata disattivata
If TypeOf CurrCompoParam Is TextBoxOnOffParam Then DirectCast(CurrCompoParam, TextBoxOnOffParam).SetIsActive(False)
If TypeOf CurrCompoParam Is ComboBoxOnOffParam Then DirectCast(CurrCompoParam, ComboBoxOnOffParam).SetIsActive(False)
End If
Exit While
End If
' Se è di tipo obbligatorio (non è OnOff)
If Not (TypeOf CurrCompoParam Is TextBoxOnOffParam OrElse TypeOf CurrCompoParam Is ComboBoxOnOffParam) Then
Dim sKey As String = GetKey(sLine)
' se il nome del parametro è lo stesso di quello presente nel componente
If String.Equals(Trim(CurrCompoParam.DDFName), sKey) Then
If TypeOf CurrCompoParam Is ComboBoxParam Then
' leggo il valore DDF dal file
Dim sVal As String = GetValueWithoutKey(sLine)
' carico la lista dei valori (messaggi)
Dim List As ObservableCollection(Of String) = DirectCast(CurrCompoParam, ComboBoxParam).ItemList
' carico la lista dei valori DDF
Dim ListDDF As ObservableCollection(Of String) = DirectCast(CurrCompoParam, ComboBoxParam).ItemListDDF
' riscrivo i valori della lista DDF senza spazi all'inizio e alla fine e in minuscolo
For IndexListDDF As Integer = 0 To ListDDF.Count - 1
ListDDF(IndexListDDF) = Trim(ListDDF(IndexListDDF)).ToLower()
Next
' carico il valore IndexName come indice del valore selezionato dalla lista DDF
Dim IndexName As Integer = ListDDF.IndexOf(sVal.ToLower())
Dim SelItem As String = String.Empty
' se è stata trovata una corrispondenza tra il valore letto dal file e il valore presente nella lista DDF
If IndexName >= 0 Then
' restituisco il valore DDF della lista associato all'indice passato
SelItem = List(IndexName)
Else
' il nome DDF non è corretto
' Error in reading {0}: line {1}. It is not a member of the list.
sErrorInfo &= String.Format(EgtMsg(50137), sVal, IndexLine)
' This param will be initialized by default.
sErrorInfo &= String.Format(Environment.NewLine & EgtMsg(50138)) & vbCrLf
' aggiungo un nuovo elemento solo nella lista da mostrare a video, quella dei ddf non deve essere toccata
List.Add(sVal)
SelItem = List(List.Count - 1)
CompoTemplateItem.ErrorValue = True
CurrCompoParam.ErrorInReading = True
' SelItem = List(0)
End If
' assegno al parametro del componente il valore "filtrato"
DirectCast(CurrCompoParam, ComboBoxParam).SetSelItem(SelItem)
' assegno il valore letto alla textbox
ElseIf TypeOf CurrCompoParam Is TextBoxParam Then
Dim sVal As String = GetValueWithoutKey(sLine)
' per ora non esegue nessun tipo di controllo sui valori letti dal file DDF
DirectCast(CurrCompoParam, TextBoxParam).SetValue(sVal)
' avviso che il file è modificato (in caso di chiusura del programma obbligo a passare dal salvataggio)
Dim dVal As Double
If String.IsNullOrEmpty(sVal) OrElse Not StringToDouble(sVal, dVal) Then
' Part.FirstReadingEdge = True
CompoTemplateItem.ErrorValue = True
CurrCompoParam.ErrorInReading = True
End If
End If
' se il nome esiste ma è sbagliato
ElseIf Not String.IsNullOrWhiteSpace(sKey) Then
' se il nome non è preceduto dal trattino
If Not sKey.StartsWith("- ") Then
' il nome DDF non è corretto
' Error in reading: line {0}. Expected {1}.
sErrorInfo &= String.Format(EgtMsg(50139), IndexLine + 1, Trim(CompoTemplateItem.CompoParamList(IndexParam).DDFName))
' This param will be initialized by default.
sErrorInfo &= String.Format(Environment.NewLine & EgtMsg(50138)) & vbCrLf
Part.FirstReadingEdge = True
CompoTemplateItem.MissingParameter = True
CurrCompoParam.MissingParameterInReading = True
' passo al parametro successivo senza cambiare linea del file DDF
IndexParam += 1
Continue While
Else
' istanzio tutti i valori che mancano al compo corrente di default
' Error in reading: line {0}. Expected {1}.
sErrorInfo &= String.Format(EgtMsg(50139), IndexLine + 1, Trim(CompoTemplateItem.CompoParamList(IndexParam).DDFName))
' This param will be initialized by default.
sErrorInfo &= String.Format(Environment.NewLine & EgtMsg(50138)) & vbCrLf
' avviso che il file in scrittura è differente da quello in lettura
Part.FirstReadingEdge = True
CompoTemplateItem.MissingParameter = True
CurrCompoParam.MissingParameterInReading = True
' esco dal ciclo
Exit While
End If
End If
' Se altrimenti è una TextBoxOnOff
ElseIf TypeOf CurrCompoParam Is TextBoxOnOffParam Then
' se il nome del parametro è lo stesso di quello presente nel componente
If String.Equals(Trim(CompoTemplateItem.CompoParamList(IndexParam).DDFName), GetKey(sLine)) Then
' se la stringa c'è nel DDF vuol dire che è stata selezionata
Dim sVal As String = GetValueWithKey(sLine, Trim(CurrCompoParam.DDFName))
DirectCast(CurrCompoParam, TextBoxOnOffParam).SetValue(sVal)
Dim dVal As Double
If String.IsNullOrEmpty(sVal) OrElse Not StringToDouble(sVal, dVal) Then
CompoTemplateItem.ErrorValue = True
CurrCompoParam.ErrorInReading = True
End If
DirectCast(CurrCompoParam, TextBoxOnOffParam).SetIsActive(True)
' se il nome esiste ma è sbagliato
ElseIf Not String.IsNullOrWhiteSpace(GetKey(sLine)) Then
' significa che la TextBoxOnOff è stata disattivata
DirectCast(CurrCompoParam, TextBoxOnOffParam).SetIsActive(False)
' passo al parametro successivo senza cambiare linea del file DDF
IndexParam += 1
Continue While
End If
' Altrimenti è una ComboBoxOnOffParam
Else
' se il nome del parametro è lo stesso di quello presente nel componente
If String.Equals(Trim(CompoTemplateItem.CompoParamList(IndexParam).DDFName), Trim(GetKey(sLine))) Then
' leggo il valore DDF dal file
Dim sVal As String = GetValueWithKey(sLine, Trim(CurrCompoParam.DDFName))
Dim IndexName As Integer = 0
' carico la lista dei valori (messaggi)
Dim List As ObservableCollection(Of String) = DirectCast(CurrCompoParam, ComboBoxOnOffParam).ItemList
Dim IndexListDDF As Integer = 0
' carico la lista dei valori DDF
Dim ListDDF As ObservableCollection(Of String) = DirectCast(CurrCompoParam, ComboBoxOnOffParam).ItemListDDF
' riscrivo i valori della lista DDF senza spaziatura
For IndexListDDF = 0 To ListDDF.Count - 1
ListDDF(IndexListDDF) = Trim(ListDDF(IndexListDDF))
Next
' carico il valore IndexName come indice del valore selezionato dalla lista DDF
IndexName = ListDDF.IndexOf(sVal)
Dim SelItem As String = String.Empty
' se è stata trovata una corrispondenza tra il valore letto dal file e il valore presente nella lista DDF
If IndexName >= 0 Then
' restituisco il valore DDF della lista associato all'indice passato
SelItem = Trim(List(IndexName))
Else
' il nome DDF non è corretto
' Error in reading {0}: line {1}. It is not a member of the list.
sErrorInfo &= String.Format(EgtMsg(50137), sVal, IndexLine)
' This param will be initialized by default.
sErrorInfo &= String.Format(Environment.NewLine & EgtMsg(50138)) & vbCrLf
' aggiungo un nuovo elemento solo nella lista da mostrare a video, quella dei ddf non deve essere toccata
List.Add(sVal)
SelItem = List(List.Count - 1)
CompoTemplateItem.ErrorValue = True
CurrCompoParam.ErrorInReading = True
'SelItem = List(0)
End If
' assegno al parametro della compnente il valore "filtrato"
DirectCast(CurrCompoParam, ComboBoxOnOffParam).SetSelItem(SelItem)
' se il nome esiste ma è sbagliato
ElseIf Not String.IsNullOrWhiteSpace(GetKey(sLine)) Then
' significa che la TextBoxOnOff è stata disattivata
DirectCast(CurrCompoParam, ComboBoxOnOffParam).SetIsActive(False)
' passo al parametro successivo senza cambiare linea del file DDF
IndexParam += 1
Continue While
End If
End If
Else
If TypeOf DirectCast(CompoTemplateItem.CompoParamList(IndexParam), CompoParam) Is TextBoxOnOffParam Then
DirectCast(CurrCompoParam, TextBoxOnOffParam).SetIsActive(False)
ElseIf TypeOf DirectCast(CompoTemplateItem.CompoParamList(IndexParam), CompoParam) Is ComboBoxOnOffParam Then
DirectCast(CurrCompoParam, ComboBoxOnOffParam).SetIsActive(False)
Else
' Error in reading: line {0}. Expected {1}.
sErrorInfo &= String.Format(EgtMsg(50139), IndexLine + 1, Trim(CompoTemplateItem.CompoParamList(IndexParam).DDFName))
' All missing params will be initialized by default.
sErrorInfo &= String.Format(Environment.NewLine & EgtMsg(50140)) & vbCrLf
Part.FirstReadingEdge = True
CompoTemplateItem.MissingParameter = True
CurrCompoParam.MissingParameterInReading = True
For Index As Integer = IndexParam To CompoTemplateItem.CompoParamList.Count - 1
'If TypeOf DirectCast(CompoTemplateItem.CompoParamList(Index), CompoParam) Is TextBoxOnOffParam Then
' DirectCast(CurrCompoParam, TextBoxOnOffParam).SetIsActive(False)
'ElseIf TypeOf DirectCast(CompoTemplateItem.CompoParamList(Index), CompoParam) Is ComboBoxOnOffParam Then
' DirectCast(CurrCompoParam, ComboBoxOnOffParam).SetIsActive(False)
'Else
CompoTemplateItem.CompoParamList(Index).MissingParameterInReading = True
'End If
Next
End If
End If
' Avanzo nell'elenco dei parametri e nel file DDF
IndexParam += 1
IndexLine = SkipWhiteSpaceList(FileContent, IndexLine + 1)
End While
CompoTemplateItem.m_ParameterDDfList.Clear()
Return True
End Function
' copia i valori delle textbox e delle combobox
Private Function CopyCompoParamList(NewList As ObservableCollection(Of CompoParam), OldList As ObservableCollection(Of CompoParam)) As Boolean
Dim IndexParam As Integer = 0
For IndexParam = 0 To OldList.Count - 1
If TypeOf OldList(IndexParam) Is TextBoxOnOffParam Then
Dim OldParam As TextBoxOnOffParam = DirectCast(OldList(IndexParam), TextBoxOnOffParam)
Dim NewParam As TextBoxOnOffParam = DirectCast(NewList(IndexParam), TextBoxOnOffParam)
NewParam.m_Value = OldParam.m_Value
NewParam.SetIsActive(OldParam.IsActive)
Dim dVal As Double
If StringToDouble(OldParam.Value, dVal) Then
NewList(IndexParam).ErrorInReading = False
Else
NewList(IndexParam).ErrorInReading = True
End If
ElseIf TypeOf OldList(IndexParam) Is TextBoxParam Then
Dim OldParam As TextBoxParam = DirectCast(OldList(IndexParam), TextBoxParam)
Dim NewParam As TextBoxParam = DirectCast(NewList(IndexParam), TextBoxParam)
NewParam.m_Value = OldParam.m_Value
NewParam.MissingParameterInReading = OldParam.MissingParameterInReading
Dim dVal As Double
If StringToDouble(OldParam.Value, dVal) Then
NewList(IndexParam).ErrorInReading = False
Else
NewList(IndexParam).ErrorInReading = True
End If
ElseIf TypeOf OldList(IndexParam) Is ComboBoxOnOffParam Then
Dim OldParam As ComboBoxOnOffParam = DirectCast(OldList(IndexParam), ComboBoxOnOffParam)
Dim NewParam As ComboBoxOnOffParam = DirectCast(NewList(IndexParam), ComboBoxOnOffParam)
If OldParam.ItemList.Count > OldParam.ItemListDDF.Count Then
NewParam.ItemList.Add(OldParam.ItemList.Last)
NewParam.SetSelItem(NewParam.ItemList.Last)
NewList(IndexParam).ErrorInReading = True
End If
Dim IndexItem As Integer = -1
For IndexItem = 0 To OldParam.ItemListDDF.Count - 1
If OldParam.SelItem = OldParam.ItemList(IndexItem) Then
NewList(IndexParam).ErrorInReading = False
NewParam.MissingParameterInReading = OldParam.MissingParameterInReading
NewParam.SetSelItem(NewParam.ItemList(IndexItem))
If OldParam.ItemList.Count > OldParam.ItemListDDF.Count Then
OldParam.ItemList.RemoveAt(OldParam.ItemList.Count - 1)
NewParam.ItemList.RemoveAt(NewParam.ItemList.Count - 1)
End If
Exit For
End If
Next
NewParam.SetIsActive(OldParam.IsActive)
ElseIf TypeOf OldList(IndexParam) Is ComboBoxParam Then
Dim OldParam As ComboBoxParam = DirectCast(OldList(IndexParam), ComboBoxParam)
Dim NewParam As ComboBoxParam = DirectCast(NewList(IndexParam), ComboBoxParam)
If OldParam.ItemList.Count > OldParam.ItemListDDF.Count Then
NewParam.ItemList.Add(OldParam.ItemList.Last)
NewParam.SetSelItem(NewParam.ItemList.Last)
NewList(IndexParam).ErrorInReading = True
End If
Dim IndexItem As Integer = -1
For IndexItem = 0 To OldParam.ItemListDDF.Count - 1
If OldParam.SelItem = OldParam.ItemList(IndexItem) Then
NewList(IndexParam).ErrorInReading = False
NewParam.MissingParameterInReading = OldParam.MissingParameterInReading
NewParam.SetSelItem(NewParam.ItemList(IndexItem))
If OldParam.ItemList.Count > OldParam.ItemListDDF.Count Then
OldParam.ItemList.RemoveAt(OldParam.ItemList.Count - 1)
NewParam.ItemList.RemoveAt(NewParam.ItemList.Count - 1)
End If
Exit For
End If
Next
End If
Next
Return True
End Function
' aggiunge alla lista dei file esistenti quelli che non esistono più
Private Function RefreshListFile(CorrectList As ObservableCollection(Of String), ErrList As ObservableCollection(Of String)) As Boolean
Dim IndexC As Integer = 0
Dim IndexErr As Integer = 0
Dim bCommunFile As Boolean = False
Dim NewFileList As New ObservableCollection(Of String)
For IndexC = 0 To CorrectList.Count - 1
bCommunFile = False
For IndexErr = 0 To ErrList.Count - 1
If CorrectList(IndexC) = ErrList(IndexErr) Then
bCommunFile = True
Exit For
End If
Next
If Not bCommunFile Then
NewFileList.Add(CorrectList(IndexC))
End If
Next
For Each Item In NewFileList
ErrList.Add(Item)
Next
Return True
End Function
Private Function DeleteFileInList(SelFile As String, ByRef ErrFileList As ObservableCollection(Of String)) As Boolean
Dim IndexList As Integer = ErrFileList.Count - 1
For Index As Integer = IndexList To 0 Step -1
If SelFile.ToLower <> ErrFileList(Index).ToLower Then
ErrFileList.RemoveAt(Index)
End If
Next
Return True
End Function
' verifica che la componente non riceva un errore in fase di inserimento di un parametro
Public Function RecreateCompoParm(ByRef ErrCompo As Compo, CurrPart As Part) As Boolean
Dim CompoListIndex As Integer = SearchCompotypeIndex(ErrCompo.CompoType.DDFName)
If CompoListIndex = -1 Then Return False
Dim IndexParam As Integer = 0
For IndexParam = 0 To ErrCompo.CompoParamList.Count - 1
If ErrCompo.CompoParamList(IndexParam).ErrorInReading Then
If TypeOf ErrCompo.CompoParamList(IndexParam) Is TextBoxParam Then
Dim Param As TextBoxParam = DirectCast(ErrCompo.CompoParamList(IndexParam), TextBoxParam)
Dim dVal As Double
If StringToDouble(Param.Value, dVal) Then
ErrCompo.CompoParamList(IndexParam).ErrorInReading = False
End If
ElseIf TypeOf ErrCompo.CompoParamList(IndexParam) Is ComboBoxParam Then
Dim Param As ComboBoxParam = DirectCast(ErrCompo.CompoParamList(IndexParam), ComboBoxParam)
Dim IndexItem As Integer = -1
For IndexItem = 0 To Param.ItemListDDF.Count - 1
If Param.SelItem = Param.ItemList(IndexItem) Then
If Param.ItemList.Count > Param.ItemListDDF.Count Then
ErrCompo.CompoParamList(IndexParam).ErrorInReading = False
Param.ItemList.RemoveAt(Param.ItemList.Count - 1)
ElseIf Param.ItemList.Count = Param.ItemListDDF.Count Then
ErrCompo.CompoParamList(IndexParam).ErrorInReading = False
End If
Exit For
End If
Next
ElseIf TypeOf ErrCompo.CompoParamList(IndexParam) Is TextBoxOnOffParam Then
Dim Param As TextBoxOnOffParam = DirectCast(ErrCompo.CompoParamList(IndexParam), TextBoxOnOffParam)
Dim dVal As Double
If StringToDouble(Param.Value, dVal) Then
ErrCompo.CompoParamList(IndexParam).ErrorInReading = False
End If
ElseIf TypeOf ErrCompo.CompoParamList(IndexParam) Is ComboBoxOnOffParam Then
Dim Param As ComboBoxOnOffParam = DirectCast(ErrCompo.CompoParamList(IndexParam), ComboBoxOnOffParam)
For Each Item In Param.ItemListDDF
If Param.SelItem = Item Then
If Param.ItemList.Count > Param.ItemListDDF.Count Then
Param.ItemList.RemoveAt(Param.ItemList.Count - 1)
ElseIf Param.ItemList.Count = Param.ItemListDDF.Count Then
ErrCompo.CompoParamList(IndexParam).ErrorInReading = False
End If
Param.ErrorInReading = False
Exit For
End If
Next
End If
End If
Next
ErrCompo.ErrorValue = False
ErrCompo.MissingParameter = False
For Each Param In ErrCompo.CompoParamList
If Param.ErrorInReading Then
ErrCompo.ErrorValue = True
Exit For
End If
Next
For Each Param In ErrCompo.CompoParamList
If Param.MissingParameterInReading Then
ErrCompo.MissingParameter = True
Exit For
End If
Next
Return True
End Function
' rielegge il file temporaneo e qundi permette di stampare gli errori attuali
Public Function LoadTempFile() As Boolean
Dim sTempFile As String = IniFile.m_sTempDir & "\" & TEMP_FILE
If Not File.Exists(sTempFile) Then Return False
' verifico che un progetto esiste
If IsNothing(Map.refAssemblyManagerVM) OrElse
IsNothing(Map.refAssemblyManagerVM.CurrProject) OrElse
IsNothing(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName) OrElse
IsNothing(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.SelAssembly) Then
Return False
End If
Dim TempAssembly As New Assembly
Assembly.ReadDDFAssembly(sTempFile, TempAssembly)
Try
File.Delete(sTempFile)
Catch
End Try
' If IsNothing(TempAssembly) Then Return False
Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.SelAssembly = TempAssembly
If OptionModule.m_ConfigurationSoftware = ConfigType.Door Then
DdfFile.WriteDDFPart(TempAssembly.ListPartDoor(0).Door, sTempFile, False, False)
' aggiorno elenco quotature
Map.refDimensioningPanelVM.LoadHardwareDimList()
ExecDoors(Map.refSceneManagerVM.ProjectScene, sTempFile, False)
Map.refSceneManagerVM.ShowGraphicError()
Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nDDFPage
' rendo visibili quotature
For Each HardwareDimension In Map.refDimensioningPanelVM.HardwareDimensionList
PrintWndVM.TurnDimensioningLayer(HardwareDimension.NameLayer, HardwareDimension.SelectedLayer)
Next
EgtZoom(ZM.ALL)
Else
' ! questa parte non funziona !
Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nAssemblyPage
DdfFile.WriteDDFAssembly(TempAssembly, sTempFile, False)
' aggiorno elenco quotature
Map.refDimensioningPanelVM.LoadHardwareDimList()
ExecDoors(Map.refSceneManagerVM.ProjectScene, sTempFile, False)
Map.refSceneManagerVM.ShowGraphicError()
Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nAssemblyPage
' rendo visibili quotature
For Each HardwareDimension In Map.refDimensioningPanelVM.HardwareDimensionList
PrintWndVM.TurnDimensioningLayer(HardwareDimension.NameLayer, HardwareDimension.SelectedLayer)
Next
EgtZoom(ZM.ALL)
End If
Return True
End Function
Public Function Open(OpenedAssName As AssemblyName) As Boolean
If IsNothing(OpenedAssName) Then Return False
If Not File.Exists(OpenedAssName.Name) Then Return False
' resetto errori sui bevel edge
Part.FirstReadingEdge = False
' leggo il ddf e creo relativo assemblato
OpenedAssName.SelAssembly = New Assembly
Assembly.ReadDDFAssembly(OpenedAssName.Name, OpenedAssName.SelAssembly)
' definisco e rimuovo file temporaneo di assemblato
Dim sTempFile As String = IniFile.m_sTempDir & "\" & TEMP_FILE
Try
File.Delete(sTempFile)
Catch ex As Exception
End Try
' se l'apertura di un assemblato genera un errore esco
If IsNothing(OpenedAssName.SelAssembly) Then
' aggiorno la grafica per eliminare la precedente porta visualizzata
Map.refSceneManagerVM.RefreshBtn()
Return False
End If
OpenedAssName.IsModified = Part.FirstReadingEdge
If OptionModule.m_ConfigurationSoftware = ConfigType.Door Then
DdfFile.WriteDDFPart(OpenedAssName.SelAssembly.ListPartDoor(0).Door, sTempFile, True, False)
If OptionModule.AdjustDDT Then
DdfFile.WriteDDFPart(OpenedAssName.SelAssembly.ListPartDoor(0).Door, OptionModule.SaveFileNameFromArgs, True, False)
' TERMINO TUTTO SUBITO
EgtOutLog("Scrittura file '.ddf' terminata")
EgtExit()
Application.Current.Shutdown(0)
Return True
End If
' aggiorno elenco quotature
Map.refDimensioningPanelVM.LoadHardwareDimList()
ExecDoors(Map.refSceneManagerVM.ProjectScene, sTempFile, False)
Map.refSceneManagerVM.ShowGraphicError()
Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nDDFPage
' rendo visibili quotature
For Each HardwareDimension In Map.refDimensioningPanelVM.HardwareDimensionList
PrintWndVM.TurnDimensioningLayer(HardwareDimension.NameLayer, HardwareDimension.SelectedLayer)
Next
EgtZoom(ZM.ALL)
Else
If Not DdfFile.WriteDDFAssembly(OpenedAssName.SelAssembly, sTempFile, True) Then
Return False
End If
' aggiorno elenco quotature
Map.refDimensioningPanelVM.LoadHardwareDimList()
ExecDoors(Map.refSceneManagerVM.ProjectScene, sTempFile, False)
Map.refSceneManagerVM.ShowGraphicError()
For Each HardwareDimension In Map.refDimensioningPanelVM.HardwareDimensionList
PrintWndVM.TurnDimensioningLayer(HardwareDimension.NameLayer, HardwareDimension.SelectedLayer)
Next
'ExecDoors(Map.refSceneManagerVM.ProjectScene, sTempFile, False)
If Assembly.Refreshing Then EgtZoom(ZM.ALL)
m_CurrProject.SelAssemblyName.SelAssembly.MatchCompo()
m_CurrProject.SelAssemblyName.SelAssembly.UpDateAllOrigValue()
' Se mancano le info per generare l'assemblato accedo direttamente alla prima porta
If m_CurrProject.SelAssemblyName.SelAssembly.bOk = Assembly.ResultReadingAssembInfo.MissingAssembInfo Then
If m_CurrProject.SelAssemblyName.SelAssembly.ListPartDoorOfDoor.Count > 0 Then
Map.refAssemblyPageVM.JambBtn(m_CurrProject.SelAssemblyName.SelAssembly.ListPartDoorOfDoor(0).Type)
Else
Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nAssemblyPage
End If
Else
Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nAssemblyPage
End If
End If
' ogni progetto salvato è l'ultimo da aprire, anche se il programma è chiuso dall'HardwareManager
' controllo che esiste almeno un file aperto
If Not IsNothing(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName) AndAlso
Not IsNothing(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.Name) Then
WriteMainPrivateProfileString(S_LAUNCHERWINDOW, K_LASTPROJECT, Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.Name)
Else
WriteMainPrivateProfileString(S_LAUNCHERWINDOW, K_LASTPROJECT, Map.refAssemblyManagerVM.CurrProject.Name)
End If
Return True
End Function
Public Sub Delete(DeleteAssName As AssemblyName)
' Se il file esiste eliminalo
Utility.OutLog("Chiudo progetto")
Utility.UnLockDir()
If File.Exists(DeleteAssName.Name) Then
Try
File.Delete(DeleteAssName.Name)
Catch ex As Exception
' non è un problema
End Try
End If
' Elimino anche il temporaneo
Dim sTempFile As String = IniFile.m_sTempDir & "\" & TEMP_FILE
Try
File.Delete(sTempFile)
Catch ex As Exception
End Try
' elimino dall'elenco dei file MruFiles
Map.refProjectManagerVM.m_MruFiles.Remove(DeleteAssName.Name)
' Salvo indice posizione elemento da eliminare
Dim SelIndex As Integer = m_CurrProject.AssemblyList.IndexOf(DeleteAssName)
m_CurrProject.AssemblyList.Remove(DeleteAssName)
If m_CurrProject.AssemblyList.Count > 0 Then
' aggiorno la porta da visualizzare
If SelIndex > m_CurrProject.AssemblyList.Count - 1 Then
m_CurrProject.SelAssemblyName = m_CurrProject.AssemblyList(m_CurrProject.AssemblyList.Count - 1)
'Open(m_CurrProject.SelAssemblyName)
Utility.OutLog("Apro Progetto: " & m_CurrProject.SelAssemblyName.Name)
Utility.LockDir(m_CurrProject.Name, m_CurrProject.SelAssemblyName.GraphicName)
Else
m_CurrProject.SelAssemblyName = m_CurrProject.AssemblyList(SelIndex)
'Open(m_CurrProject.SelAssemblyName)
Utility.OutLog("Apro Progetto: " & m_CurrProject.SelAssemblyName.Name)
Utility.LockDir(m_CurrProject.Name, m_CurrProject.SelAssemblyName.GraphicName)
End If
' se non ci sono altre porte nella lista allora
Else
Dim LastProject As String = m_CurrProject.Name
' pulisco entry page
Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nNothingSelected
' aggiorno il titolo della pagina
If OptionModule.m_SingleDoor Then
' elimino i nomi scritti nell'interstazione della pagina
Map.refMainWindowVM.ProjectNameMsg = ""
Else
Map.refMainWindowVM.ProjectNameMsg = LastProject
End If
' aggiorno l'immagine a nulla
EgtNewFile()
EgtZoom(ZM.ALL)
End If
End Sub
Public Function ManageModified() As Boolean
' verifico se selezionato esiste e modificato
If Not IsNothing(m_CurrProject) AndAlso Not IsNothing(m_CurrProject.SelAssemblyName) AndAlso m_CurrProject.SelAssemblyName.IsModified Then
Dim sText As String = String.Format(EgtMsg(50109), Path.GetFileNameWithoutExtension(m_CurrProject.SelAssemblyName.Name))
Select Case MessageBox.Show(sText, "", MessageBoxButton.YesNoCancel, MessageBoxImage.Question)
Case MessageBoxResult.Yes
If Save(m_CurrProject.SelAssemblyName) Then
m_CurrProject.SelAssemblyName.IsModified = False
Else
Return False
End If
Case MessageBoxResult.No
If Not File.Exists(m_CurrProject.SelAssemblyName.Name) Then
Delete(m_CurrProject.SelAssemblyName)
Return False
Else
m_CurrProject.SelAssemblyName.IsModified = False
End If
Case MessageBoxResult.Cancel
Return False
End Select
End If
Return True
End Function
#End Region ' Apertura e salvataggio
#Region "Creazione e caricamento degli oggetti dell'assemblato"
' creazione e di un nuovo assemblato
Friend Function CreateNewAssembly(value As String) As Assembly
Dim bIsNewAssembly As Boolean = True
' costruisco un nuvo assemblato e lo carico con i valori
Dim Local_SelAssembly As New Assembly
' carico i valori di default dell'assemblato
LoadAssemblyInformation(Local_SelAssembly)
' costruisco e carico le parti (Jamb)
CreateJamb(Local_SelAssembly)
' carico le info comuni a tutti i jamb
LoadOM_M_ET(Local_SelAssembly)
' carico il numero massimo di porte ammesse (e intanto dimesiono i jamb)
CreateDoor(Local_SelAssembly)
' carico come progetto corrente l'assemblato che sto creando in locale (così da poter gestire i Jamb), l'array delle porte è ancora vuoto!
m_CurrProject.SelAssemblyName.SelAssembly = Local_SelAssembly
' costruisco le associazioni tra i pezzi
CreateAssociation(Local_SelAssembly)
' carico le dimensioni dell'assemblato
Local_SelAssembly.SetNewDimensionAssembly(bIsNewAssembly)
Return Local_SelAssembly
End Function
' Caricamento dei dati della pagina generale degli assemblati
Public Sub LoadAssemblyInformation(CurrAssembly As Assembly)
' carico tutti le proprietà della classe Assembly
CurrAssembly.SetExterior(OptionModule.m_Exterior)
CurrAssembly.DoorListNumber = OptionModule.m_DoorsListNumber
CurrAssembly.SetThickness(OptionModule.m_ThicknessJamb)
CurrAssembly.SetWidth(OptionModule.m_WidthJamb)
CurrAssembly.SetLightUp(OptionModule.m_LightUp)
CurrAssembly.SetLightLock(OptionModule.m_LightLock)
CurrAssembly.SetLightBottom(OptionModule.m_LightBottom)
CurrAssembly.SetLightHinge(OptionModule.m_LightHinge)
CurrAssembly.SetThicknessHead(OptionModule.m_ThicknessHead)
CurrAssembly.SetOverlapHinge(OptionModule.m_OverlapHinge)
CurrAssembly.SetOverlapLock(OptionModule.m_OverlapLock)
CurrAssembly.SetOverlapTop(OptionModule.m_OverlapTop)
CurrAssembly.SetDeltaThickness(OptionModule.m_DeltaThickness)
CurrAssembly.SetLockEdgeType(OptionModule.m_LockEdgeTypeAssembly)
CurrAssembly.SetHingeEdgeType(OptionModule.m_HingeEdgeTypeAssembly)
CurrAssembly.SetTopType(OptionModule.m_TopTypeAssembly)
CurrAssembly.SetBottomType(OptionModule.m_BottomTypeAssembly)
CurrAssembly.SetLockEdgeMachining(OptionModule.m_LockEdgeMachiningAssembly)
CurrAssembly.SetHingeEdgeMachining(OptionModule.m_HingeEdgeMachiningAssembly)
CurrAssembly.SetTopMachining(OptionModule.m_TopMachiningAssembly)
CurrAssembly.SetBottomMachining(OptionModule.m_BottomMachiningAssembly)
CurrAssembly.SetLockEdgeOverMaterial(OptionModule.m_LockEdgeOverMaterialAssembly)
CurrAssembly.SetHingeEdgeOverMaterial(OptionModule.m_HingeEdgeOverMaterialAssembly)
CurrAssembly.SetTopOverMaterial(OptionModule.m_TopOverMaterialAssembly)
CurrAssembly.SetBottomOverMaterial(OptionModule.m_BottomOverMaterialAssembly)
CurrAssembly.SetDoorNumber(OptionModule.m_DoorsNumber)
CurrAssembly.SetDispositionItem(OptionModule.m_Disposition)
CurrAssembly.SetDimension(OptionModule.m_TotalDimension)
CurrAssembly.SetAssemblyHeight(OptionModule.m_TotalHeight)
CurrAssembly.SetAssemblyWidth(OptionModule.m_TotalWidth)
CurrAssembly.SetThicknessBottom(OptionModule.m_ThicknessBottom)
CurrAssembly.SetOverlapBottom(OptionModule.m_OverlapBottom)
CurrAssembly.SetDepthBottom(OptionModule.m_ThicknessJamb)
CurrAssembly.SetDeltaBottom(OptionModule.m_DeltaBottom)
End Sub
' creazione dei jamb
Public Sub CreateJamb(ByRef CurrAssembly As Assembly, Optional bNewAssembly As Boolean = True)
If OptionModule.m_ConfigurationSoftware = ConfigType.Door Then Return
' in questa fase carico separatamete i valori di ogni jamb
' in particolare le differenze tra i jamb sono -> Type, -> le dimensioni (ThicknessHead = Door.Height)
' carico i valori del JambLeft ( solo se è selezionato nella pagina delle impostazioni)
If IsNothing(ReserchPartDoor("FL_")) Then
Dim LeftJamb As New PartDoor
LeftJamb.Door = New Part(LeftJamb)
LeftJamb.Door.TypePart = ConstGen.PART_FRAME_LEFT
LeftJamb.Door.SetThickness(CurrAssembly.Thickness)
LeftJamb.Door.SetWidth(CurrAssembly.Width)
' assegno la lista completa degli swing perchè la selezione dello swing corretto avviene nel programma
LeftJamb.Door.SwingTypeList = OptionModule.m_SwingTypeList
' definisce la disposizione (da selezionare in una sola anta)
LeftJamb.Door.SetDispositionItem(OptionModule.m_Disposition)
If bNewAssembly Then
LeftJamb.IsChecked = OptionModule.m_LeftJambChk
LeftJamb.Door.IsActive = OptionModule.m_LeftJambChk
Else
LeftJamb.IsChecked = False
LeftJamb.Door.IsActive = False
End If
' aggiungo alla lista dei PartDoor
CurrAssembly.ListPartDoor.Add(LeftJamb)
End If
If IsNothing(ReserchPartDoor("FR_")) Then
' carico i valori del JambRight
Dim RightJamb As New PartDoor
RightJamb.Door = New Part(RightJamb)
RightJamb.Door.TypePart = ConstGen.PART_FRAME_RIGHT
RightJamb.Door.SetThickness(CurrAssembly.Thickness)
RightJamb.Door.SetWidth(CurrAssembly.Width)
' assegno la lista completa degli swing perchè la selezione dello swing corretto avviene nel programma
RightJamb.Door.SwingTypeList = OptionModule.m_SwingTypeList
' definisce la disposizione (da selezionare in una sola anta)
RightJamb.Door.SetDispositionItem(OptionModule.m_Disposition)
If bNewAssembly Then
RightJamb.IsChecked = OptionModule.m_RightJambChk
RightJamb.Door.IsActive = OptionModule.m_RightJambChk
Else
RightJamb.IsChecked = False
RightJamb.Door.IsActive = False
End If
' aggiungo alla lista dei PartDoor
CurrAssembly.ListPartDoor.Add(RightJamb)
End If
If IsNothing(ReserchPartDoor("FT_")) Then
' carico i valori del JambTop
Dim TopJamb As New PartDoor
TopJamb.Door = New Part(TopJamb)
TopJamb.Door.TypePart = ConstGen.PART_FRAME_TOP
TopJamb.Door.SetThickness(CurrAssembly.Thickness)
TopJamb.Door.SetHeight(CurrAssembly.ThicknessHead)
' assegno la lista completa degli swing perchè la selezione dello swing corretto avviene nel programma
TopJamb.Door.SwingTypeList = OptionModule.m_SwingTypeList
' definisce la disposizione (da selezionare in una sola anta)
TopJamb.Door.SetDispositionItem(OptionModule.m_Disposition)
If bNewAssembly Then
TopJamb.IsChecked = OptionModule.m_TopJambChk
TopJamb.Door.IsActive = OptionModule.m_TopJambChk
Else
TopJamb.IsChecked = False
TopJamb.Door.IsActive = False
End If
CurrAssembly.ListPartDoor.Add(TopJamb)
End If
If IsNothing(ReserchPartDoor("FB_")) AndAlso CurrAssembly.Exterior Then
Dim BottomJamb As New PartDoor
BottomJamb.Door = New Part(BottomJamb)
' carico i valori del JambBottom
BottomJamb.Door.TypePart = ConstGen.PART_FRAME_BOTTOM
BottomJamb.Door.SetThickness(CurrAssembly.DepthBottom)
BottomJamb.Door.SetHeight(CurrAssembly.ThicknessBottom)
' assegno la lista completa degli swing perchè la selezione dello swing corretto avviene nel programma
BottomJamb.Door.SwingTypeList = OptionModule.m_SwingTypeList
' definisce la disposizione (da selezionare in una sola anta)
BottomJamb.Door.SetDispositionItem(OptionModule.m_Disposition)
If bNewAssembly Then
BottomJamb.IsChecked = OptionModule.m_BottomJambChk
BottomJamb.Door.IsActive = OptionModule.m_BottomJambChk
Else
BottomJamb.IsChecked = False
BottomJamb.Door.IsActive = False
End If
' aggiungo alla lista dei PartDoor
CurrAssembly.ListPartDoor.Add(BottomJamb)
ElseIf Not IsNothing(ReserchPartDoor("FB_")) AndAlso Not CurrAssembly.Exterior Then
Dim LocalJamb As PartDoor = ReserchPartDoor("FB_")
CurrAssembly.ListPartDoor.RemoveAt(CurrAssembly.ListPartDoor.IndexOf(ReserchPartDoor("FB_")))
LocalJamb = Nothing
End If
' i parametri che non sono ancora stati caricati sono:
' Swing -> dalla porta
' Size -> dalla porta
' OverMaterial -> LoadOM_M_ET
' Machining -> LoadOM_M_ET
' EdgeType -> LoadOM_M_ET
' Material -> dalla porta
' Properties -> dalla porta
End Sub
' carica i valori di Overmaterial, Machining e EdgeType settati di Default
Public Sub LoadOM_M_ET(CurrAssembly As Assembly)
For IndexPartDoor As Integer = 0 To CurrAssembly.ListPartDoor.Count - 1
Dim Local_Part As Part = CurrAssembly.ListPartDoor(IndexPartDoor).Door
' se gli oggetti esistono gia vengono sempicemente ricaricati
If Local_Part.TypePart.Contains("F") Then
' OverMaterial
Local_Part.TopOverMaterial = CurrAssembly.TopOverMaterial
Local_Part.BottomOverMaterial = CurrAssembly.BottomOverMaterial
Local_Part.HingeEdgeOverMaterial = CurrAssembly.HingeEdgeOverMaterial
Local_Part.LockEdgeOverMaterial = CurrAssembly.LockEdgeOverMaterial
' Machining
Local_Part.TopMachining = CurrAssembly.TopMachining
Local_Part.BottomMachining = CurrAssembly.BottomMachining
Local_Part.HingeEdgeMachining = CurrAssembly.HingeEdgeMachining
Local_Part.LockEdgeMachining = CurrAssembly.LockEdgeMachining
' EdgeType
Local_Part.SetTopType(CurrAssembly.TopType)
Local_Part.SetBottomType(CurrAssembly.BottomType)
Local_Part.SetHingeEdgeType(CurrAssembly.HingeEdgeType)
Local_Part.SetLockEdgeType(CurrAssembly.LockEdgeType)
End If
Next
End Sub
' creazione ante/eliminazione ante
Public Sub CreateDoor(ByRef CurrAssembly As Assembly)
Dim nDoorNumber As Integer
Dim sDN As String = "0"
Int32.TryParse(CurrAssembly.DoorNumber, nDoorNumber)
If nDoorNumber < 1 OrElse nDoorNumber > MAX_DOORNUMBER Then
nDoorNumber = 1
End If
If nDoorNumber > 0 Then sDN = "1"
' creo le Ante
For IndexDoor As Integer = 0 To nDoorNumber - 1
Dim Type As String = ConstGen.PART_DO_ & IndexDoor + 1
Dim _PartDoor As PartDoor = ReserchPartDoor(Type)
If IsNothing(_PartDoor) Then
Dim Local_PartDoor As New PartDoor
Local_PartDoor.Door = New Part(Local_PartDoor)
Local_PartDoor.Door.TypePart = Type
' non viene caricato lo swing, che è carciato al termine del ciclo for
LoadDefaultSingleDoor(Local_PartDoor.Door, CStr(nDoorNumber))
Local_PartDoor.SetIsChecked(True)
'CreateNewPropertiesList(Local_PartDoor.Door.PropertiesList, Local_PartDoor.Door.SelectedMaterial)
CurrAssembly.ListPartDoor.Add(Local_PartDoor)
Else
CurrAssembly.ListPartDoor.Add(_PartDoor)
End If
Next
' eliminazione porta
If nDoorNumber < CurrAssembly.ListPartDoorOfDoor.Count Then
If Not IsNothing(ReserchPartDoor("DO_2")) Then
Dim LocalPartDoor2 As PartDoor = ReserchPartDoor("DO_2")
Dim Type As String = "DO_2"
For IndexPartDoor As Integer = 0 To CurrAssembly.ListPartDoor.Count - 1
If CurrAssembly.ListPartDoor(IndexPartDoor).Type = Type Then
CurrAssembly.ListPartDoor.RemoveAt(IndexPartDoor)
Exit For
End If
Next
LocalPartDoor2.Door = Nothing
LocalPartDoor2 = Nothing
' aggiorno la lista delle ante
CurrAssembly.NotifyPropertyChanged("ListPartDoorOfDoor")
' devo eliminare tutti riferiemnti che possono esistere
CreateAssociation(CurrAssembly)
End If
End If
' prima di cambiare lo swing
Dim IndexSwing As Integer = 0
If Not IsNothing(ReserchPartDoor("DO_1")) Then
Dim LocalPartDorr As PartDoor = ReserchPartDoor("DO_1")
If LocalPartDorr.Door.TypePart.Contains("DO_1") Then
For Each Item In LocalPartDorr.Door.SwingTypeList
If Item = LocalPartDorr.Door.SwingAlias.AliasName Then
Exit For
End If
IndexSwing += 1
Next
End If
End If
' carica la lista degli swing
For Each ItemPartDoor In CurrAssembly.ListPartDoorOfDoor
SetSwingOnDoor(CurrAssembly.DoorNumber, ItemPartDoor.Door, IndexSwing)
Next
CurrAssembly.NotifyPropertyChanged("ListPartDoorOfDoor")
End Sub
' carica i valori di default (dell'option page) nella prima porta
Public Sub LoadDefaultSingleDoor(ByRef ref_Part As Part, Optional ByVal sDN As String = "0")
ref_Part.SetWidth(OptionModule.m_Width)
ref_Part.SetHeight(OptionModule.m_Height)
ref_Part.SetThickness(OptionModule.m_Thickness)
ref_Part.IsActive = False
ref_Part.Measure = ConvertMmUnitsToString(OptionModule.m_bIsMmUnit)
ref_Part.Weight = OptionModule.m_Weight
ref_Part.SetLockEdgeType(OptionModule.m_LockEdgeType)
ref_Part.SetHingeEdgeType(OptionModule.m_HingeEdgeType)
ref_Part.SetTopType(OptionModule.m_TopType)
ref_Part.SetBottomType(OptionModule.m_BottomType)
ref_Part.LockEdgeMachining = OptionModule.m_LockEdgeMachining
ref_Part.HingeEdgeMachining = OptionModule.m_HingeEdgeMachining
ref_Part.TopMachining = OptionModule.m_TopMachining
ref_Part.BottomMachining = OptionModule.m_BottomMachining
ref_Part.LockEdgeOverMaterial = OptionModule.m_LockEdgeOverMaterial
ref_Part.HingeEdgeOverMaterial = OptionModule.m_HingeEdgeOverMaterial
ref_Part.TopOverMaterial = OptionModule.m_TopOverMaterial
ref_Part.BottomOverMaterial = OptionModule.m_BottomOverMaterial
ref_Part.SetDispositionItem(OptionModule.m_Disposition)
ref_Part.SetMaterial(OptionModule.m_CurrMaterial)
End Sub
' carica la lista degli swing a seconda del numero di porte selezionato
Public Sub SetSwingOnDoor(sDN As String, ByRef CurrPart As Part, nIndexSwing As Integer)
Select Case sDN
Case "1"
CurrPart.SwingTypeList = OptionModule.m_SwingTypeListSinlgeDoor
CurrPart.SetSwing(CurrPart.SwingTypeList(nIndexSwing))
Case "2"
If CurrPart.TypePart.Contains("DO_1") Then
CurrPart.SwingTypeList = OptionModule.m_SwingTypeListLeftDoor
CurrPart.SetSwing(CurrPart.SwingTypeList(nIndexSwing))
End If
If CurrPart.TypePart.Contains("DO_2") Then
CurrPart.SwingTypeList = OptionModule.m_SwingTypeListRightDoor
CurrPart.SetSwing(CurrPart.SwingTypeList(nIndexSwing))
End If
Case Else
CurrPart.SwingTypeList = OptionModule.m_SwingTypeList
CurrPart.SetSwing(OptionModule.m_Swing)
End Select
End Sub
#End Region ' Creazione e caricamento degli oggetti dell'assemblato
#Region "Association"
' questa è la funzione principale che esegue l'aggiunta/aggiornamento dei riferimenti
' per tutti gli oggetti presenti nell'assemblato viene costruito il riferimento
Public Function CreateAssociation(ByRef CurrAssembly As Assembly) As Boolean
Dim TypePart As String = String.Empty
Dim LocalPd As PartDoor = Nothing
Dim nDN As Integer
Int32.TryParse(CurrAssembly.DoorNumber, nDN)
' ripulisco elimino le assiciazioni che non esisto più ( se elimino un'anta ricostruisco le giuste associazioni)
CleanAssociation()
For Each ItemPartDoor In CurrAssembly.ListPartDoor
' se l'oggetto che ricevo è di tipo Frame ripulisco il nome del tipo per ottenre le forma "FL", "FR", "FB", FT
If ItemPartDoor.Type.Contains("F") Then
TypePart = ItemPartDoor.Type.Remove(ItemPartDoor.Type.LastIndexOf("_"c))
Else
TypePart = ItemPartDoor.Type
End If
Select Case TypePart
Case "FL"
LocalPd = ReserchPartDoor("DO_1")
BuildAssociation(ItemPartDoor, LocalPd, 100)
LocalPd = ReserchPartDoor("FT_")
BuildAssociation(ItemPartDoor, LocalPd, 200)
LocalPd = ReserchPartDoor("FB_")
BuildAssociation(ItemPartDoor, LocalPd, 400)
Case "FR"
If nDN = 1 Then
LocalPd = ReserchPartDoor("DO_1")
BuildAssociation(ItemPartDoor, LocalPd, 300)
Else
' se esiste elimino la precedente associazione
DeleteAssociation(ReserchPartDoor("DO_1"), ItemPartDoor)
LocalPd = ReserchPartDoor("DO_2")
BuildAssociation(ItemPartDoor, LocalPd, 300)
End If
LocalPd = ReserchPartDoor("FT_")
BuildAssociation(ItemPartDoor, LocalPd, 200)
LocalPd = ReserchPartDoor("FB_")
BuildAssociation(ItemPartDoor, LocalPd, 400)
Case "FT"
LocalPd = ReserchPartDoor("DO_1")
BuildAssociation(ItemPartDoor, LocalPd, 400)
LocalPd = ReserchPartDoor("DO_2")
BuildAssociation(ItemPartDoor, LocalPd, 400)
LocalPd = ReserchPartDoor("FL_")
BuildAssociation(ItemPartDoor, LocalPd, 400)
LocalPd = ReserchPartDoor("FR_")
BuildAssociation(ItemPartDoor, LocalPd, 400)
Case "FB"
LocalPd = ReserchPartDoor("DO_1")
BuildAssociation(ItemPartDoor, LocalPd, 200)
LocalPd = ReserchPartDoor("DO_2")
BuildAssociation(ItemPartDoor, LocalPd, 200)
LocalPd = ReserchPartDoor("FL_")
BuildAssociation(ItemPartDoor, LocalPd, 200)
LocalPd = ReserchPartDoor("FR_")
BuildAssociation(ItemPartDoor, LocalPd, 200)
Case "DO_1"
If nDN = 1 Then
LocalPd = ReserchPartDoor("FR_")
BuildAssociation(ItemPartDoor, LocalPd, 100)
Else
' se esiste elimino la precedente associazione
DeleteAssociation(ReserchPartDoor("FR_"), ItemPartDoor)
LocalPd = ReserchPartDoor("DO_2")
BuildAssociation(ItemPartDoor, LocalPd, 100)
End If
LocalPd = ReserchPartDoor("FL_")
BuildAssociation(ItemPartDoor, LocalPd, 300)
LocalPd = ReserchPartDoor("FT_")
BuildAssociation(ItemPartDoor, LocalPd, 200)
LocalPd = ReserchPartDoor("FB_")
BuildAssociation(ItemPartDoor, LocalPd, 400)
Case "DO_2"
LocalPd = ReserchPartDoor("DO_1")
BuildAssociation(ItemPartDoor, LocalPd, 300)
LocalPd = ReserchPartDoor("FL_")
BuildAssociation(ItemPartDoor, LocalPd, 300)
LocalPd = ReserchPartDoor("FR_")
BuildAssociation(ItemPartDoor, LocalPd, 100)
LocalPd = ReserchPartDoor("FT_")
BuildAssociation(ItemPartDoor, LocalPd, 200)
LocalPd = ReserchPartDoor("FB_")
BuildAssociation(ItemPartDoor, LocalPd, 400)
End Select
Next
Return True
End Function
' in base al tipo (Type) di Part restistuisce il PartDoor associato
Public Function ReserchPartDoor(TypePart As String) As PartDoor
Dim PD As PartDoor = Nothing
If Not IsNothing(Map.refAssemblyPageVM.CurrAssembly) Then
For Each ItemPartDoor In Map.refAssemblyPageVM.CurrAssembly.ListPartDoor
If ItemPartDoor.Type.Contains(TypePart) Then
PD = ItemPartDoor
Exit For
End If
Next
End If
Return PD
End Function
' costruisce (sull'oeggto ItemPD) il riferimento all'ogetto passato (ReserchPD)
Public Function BuildAssociation(ByRef ItemPD As PartDoor, ByRef ReserchPd As PartDoor, nSide As Integer) As Boolean
If IsNothing(ReserchPd) Then Return False
' conto il numero di associazioni presenti sullo stesso lato
Dim CountAssociation As Integer = 0
For Each ItemAssociation In ItemPD.ListAssociation
If ItemAssociation.Side > nSide AndAlso ItemAssociation.Side < nSide + 100 Then
' se l'associazione esiste già allora esco
If ItemAssociation.refPartDoor.Type = ReserchPd.Type Then Return True
CountAssociation = 1 + CountAssociation
End If
Next
' quindi sommo uno (perchè è la nuova associazione)
CountAssociation = 1 + CountAssociation
Dim NewAssociation1 As New Association(ReserchPd, nSide + CountAssociation)
ItemPD.ListAssociation.Add(NewAssociation1)
Return True
End Function
' elimina le associazioni che hanno riferimenti nulli
Public Sub CleanAssociation()
If IsNothing(Map.refAssemblyPageVM) AndAlso IsNothing(Map.refAssemblyPageVM.CurrAssembly) Then Return
For Each ItemPartDoor In Map.refAssemblyPageVM.CurrAssembly.ListPartDoor
Dim ListIndexToRemove As New List(Of Integer)
' raccolgo l'elenco degli indici da eliminare
For IndexAssociation As Integer = 0 To ItemPartDoor.ListAssociation.Count - 1
If IsNothing(ItemPartDoor.ListAssociation(IndexAssociation).refPartDoor.Door) Then
ListIndexToRemove.Add(IndexAssociation)
End If
Next
' rimuovo dalla lista precedentemente analizzata
For Each ItemIndex In ListIndexToRemove
ItemPartDoor.ListAssociation.RemoveAt(ItemIndex)
Next
Next
End Sub
' elimina il PartDoor (DeletingAssication) dalla lista delle associazioni di un altro PartDoor (CurrPartDoor)
Public Sub DeleteAssociation(DeletingAssication As PartDoor, CurrPartDoor As PartDoor)
If Not IsNothing(DeletingAssication) Then
For Each ItemAssociated In CurrPartDoor.ListAssociation
If DeletingAssication.Type = ItemAssociated.refPartDoor.Type Then
CurrPartDoor.ListAssociation.RemoveAt(CurrPartDoor.ListAssociation.IndexOf(ItemAssociated))
Return
End If
Next
End If
End Sub
#End Region ' Association
#End Region ' METHODS
#Region "COMMANDS"
#Region "AddDoor"
Public ReadOnly Property AddAssembly_Command As ICommand
Get
If m_cmdAddAssembly Is Nothing Then
m_cmdAddAssembly = New Command(AddressOf AddAssembly)
End If
Return m_cmdAddAssembly
End Get
End Property
Public Sub AddAssembly()
' Gestisco porta corrente modificata
If Not ManageModified() Then Return
'---------------------------------------------------------------------------------------------------------------------------------------------------
' CHIEDO SE SI VUOLE IMPORTARE UN TEMPLATE
'Prima di tutto chiedo se vuole aprire un template
Dim sImportTemplate As String = ShowDialogImportTemplate()
'----------------------------------------------------------------------------------------------------------------------------------------------------
' Creo nuovo assembly
' Lancio la finestra per chiedere il nome dell'assemblato
Dim SaveFileDialog As New MySaveFileDialogVM
Dim SaveFileDialogWnd As New EgtWPFLib5.SaveFileDialogV(Application.Current.MainWindow, SaveFileDialog)
' New Door
SaveFileDialog.Title = EgtMsg(50113)
SaveFileDialog.Directory = m_CurrProject.Name
SaveFileDialog.Extension = DDF_EXTENSION
' Se annullo esco
If Not SaveFileDialogWnd.ShowDialog Then
'm_CurrProject.SelAssemblyName = Nothing
Return
End If
Dim FilePath As String = Path.GetFileNameWithoutExtension(SaveFileDialog.FileName)
SaveFileDialog.FileName = SaveFileDialog.FileName.Replace(FilePath, Trim(FilePath))
' Controllo se il nome della porta ha estensione
If Path.HasExtension(SaveFileDialog.FileName) Then
Dim sExtension As String = Path.GetExtension(SaveFileDialog.FileName).ToLower
If Not sExtension = DDF_EXTENSION Then
SaveFileDialog.FileName = SaveFileDialog.FileName.Replace(sExtension, DDF_EXTENSION)
End If
Else
SaveFileDialog.FileName &= DDF_EXTENSION
End If
' verifico che non sia bloccato (in fase di creazione di una nuova porta posso avere il file .lck senza il ddf)
If Utility.IsFileLocked(Path.GetDirectoryName(SaveFileDialog.FileName), Path.GetFileNameWithoutExtension(SaveFileDialog.FileName)) Then
If Not IsNothing(Map.refAssemblyManagerVM.CurrProject.SelAssemblyName) Then
Utility.OutLog("Apertura progetto : " & Map.refAssemblyManagerVM.CurrProject.Name)
Utility.LockDir(Map.refAssemblyManagerVM.CurrProject.Name, Map.refAssemblyManagerVM.CurrProject.SelAssemblyName.GraphicName)
End If
Return
End If
' controllo che il nome non sia presente nella lista degli assemblati
Dim bNameExist As Boolean = False
Dim IndexDoorList As Integer
For IndexDoorList = 0 To m_CurrProject.AssemblyList.Count - 1
If m_CurrProject.AssemblyList(IndexDoorList).Name.ToLower = SaveFileDialog.FileName.ToLower Then
' se il nome è nella lista allora esco dal ciclo e rendo falsa la variabile bNameExist
bNameExist = True
Exit For
End If
bNameExist = False
Next
' se il nome è nella lista allora sovrascrivo la porta esistente
If bNameExist Then
' elimino la porta esistente
If File.Exists(SaveFileDialog.FileName) Then
Try
File.Delete(SaveFileDialog.FileName)
Catch ex As FileNotFoundException
' non è un problema
Catch ex As Exception
' non è un problema
End Try
End If
' elimino dalla lista
m_CurrProject.AssemblyList.RemoveAt(IndexDoorList)
End If
' aggiungo il nome del file alla lista degli assemblati
Dim Local_AssemblyName As New AssemblyName
Local_AssemblyName.Name = SaveFileDialog.FileName
Local_AssemblyName.GraphicName = Path.GetFileNameWithoutExtension(Local_AssemblyName.Name)
m_CurrProject.AssemblyList.Add(Local_AssemblyName)
' Seleziono AssembyName creato
m_CurrProject.SelAssemblyName = Local_AssemblyName
' aggiorno la lista
'------------------------------------------------------------------------------------------------------------------------------------------------
' LETTURA DI UN FILE DI TIPO TEMPLATE
If ImportTemplate(sImportTemplate) Then
Utility.OutLog("Apertura progetto : " & Local_AssemblyName.Name)
Utility.LockDir(Path.GetDirectoryName(Local_AssemblyName.Name), Path.GetFileNameWithoutExtension(Local_AssemblyName.Name))
' carico il nome come Assemblato selezionato
If Not OptionModule.m_DisableWindowOrder Then
Dim OrderWindow As New OrderV(Application.Current.MainWindow, New OrderVM())
OrderWindow.ShowDialog()
End If
Return
End If
'------------------------------------------------------------------------------------------------------------------------------------------------
' Creo nuovo assembly (Solo se non ho importato un template!)
NewCmd(Local_AssemblyName)
Utility.OutLog("Apertura progetto : " & Local_AssemblyName.Name)
Utility.LockDir(Path.GetDirectoryName(Local_AssemblyName.Name), Path.GetFileNameWithoutExtension(Local_AssemblyName.Name))
' carico il nome come Assemblato selezionato
If Not OptionModule.m_DisableWindowOrder Then
Dim OrderWindow As New OrderV(Application.Current.MainWindow, New OrderVM())
OrderWindow.ShowDialog()
End If
End Sub
' carico il template nel ddf corrente
Public Function ImportTemplate(sTemplateFile As String) As Boolean
If Not String.IsNullOrEmpty(sTemplateFile) Then
' creo il file ddf associato al template
'm_CurrProject.SelAssemblyName.SelAssembly = CreateNewAssembly(ImportTemplate)
m_CurrProject.SelAssemblyName.SelAssembly = New Assembly
Assembly.ReadDDFAssembly(sTemplateFile, m_CurrProject.SelAssemblyName.SelAssembly)
Dim sTempFile As String = IniFile.m_sTempDir & "\" & TEMP_FILE
Try
File.Delete(sTempFile)
Catch ex As Exception
End Try
If OptionModule.m_ConfigurationSoftware = ConfigType.Door Then
DdfFile.WriteDDFPart(m_CurrProject.SelAssemblyName.SelAssembly.ListPartDoorOfDoor(0).Door, m_CurrProject.SelAssemblyName.Name, False, False)
DdfFile.WriteDDFPart(m_CurrProject.SelAssemblyName.SelAssembly.ListPartDoorOfDoor(0).Door, m_CurrProject.SelAssemblyName.Name, True, False)
' Va salvato ancora con i parametri perchè sotto viene riletto e ci devono ancora essere i parametri
DdfFile.WriteDDFPart(m_CurrProject.SelAssemblyName.SelAssembly.ListPartDoorOfDoor(0).Door, m_CurrProject.SelAssemblyName.Name, False, False)
' aggiorno elenco quotature
Map.refDimensioningPanelVM.LoadHardwareDimList()
ExecDoors(Map.refSceneManagerVM.ProjectScene, m_CurrProject.SelAssemblyName.Name, False)
Map.refSceneManagerVM.ShowGraphicError()
Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nDDFPage
' rendo visibili quotature
For Each HardwareDimension In Map.refDimensioningPanelVM.HardwareDimensionList
PrintWndVM.TurnDimensioningLayer(HardwareDimension.NameLayer, HardwareDimension.SelectedLayer)
Next
EgtZoom(ZM.ALL)
Else
DdfFile.WriteDDFAssembly(m_CurrProject.SelAssemblyName.SelAssembly, m_CurrProject.SelAssemblyName.Name, False)
ExecDoors(Map.refSceneManagerVM.ProjectScene, sTempFile, False)
Map.refSceneManagerVM.ShowGraphicError()
EgtZoom(ZM.ALL)
Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nAssemblyPage
End If
If Open(m_CurrProject.SelAssemblyName) Then
m_CurrProject.SelAssemblyName.IsModified = True
' Cancello il file ancora con i parametri
File.Delete(m_CurrProject.SelAssemblyName.Name)
End If
Return True
End If
Return False
End Function
' mostro chiedo di caricare un template e mostro a video browse per la ricerca dei file .ddt
Public Function ShowDialogImportTemplate() As String
If Not OptionModule.m_DisableTemplate Then
If Directory.GetFiles(IniFile.m_TemplateDir).Count < 1 Then Return String.Empty
If MessageBox.Show(EgtMsg(50146), EgtMsg(50110), MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) = MessageBoxResult.Yes Then
' Apro la finestra di dialogo aperta direttamente sulla cartella cercata
Dim OpenFileDialog As New Microsoft.Win32.OpenFileDialog() With {
.InitialDirectory = IniFile.m_TemplateDir
}
If OpenFileDialog.ShowDialog() <> True Then
' se la risposta è diversa da OK esce
Return String.Empty
End If
' carico l'indirizzo del template che voglio aprire
Return OpenFileDialog.FileName
End If
End If
Return String.Empty
End Function
#End Region ' AddDoor
#Region "RemoveAssembly"
Public ReadOnly Property RemoveAssembly_Command As ICommand
Get
If m_cmdRemoveAssembly Is Nothing Then
m_cmdRemoveAssembly = New Command(AddressOf RemoveAssembly)
End If
Return m_cmdRemoveAssembly
End Get
End Property
Public Sub RemoveAssembly()
If IsNothing(CurrProject.SelAssemblyName) Then Return
Select Case MessageBox.Show(String.Format(EgtMsg(50116), Path.GetFileNameWithoutExtension(CurrProject.SelAssemblyName.Name)),
EgtMsg(50110), MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No)
Case MessageBoxResult.Yes
Delete(CurrProject.SelAssemblyName)
Case MessageBoxResult.No
' non faccio alcunchè
End Select
End Sub
#End Region ' RemoveAssembly
#End Region ' COMMANDS
End Class