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 End Set 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 DdfFile.WriteDDFPart(NewAssName.SelAssembly.GetArrayPartDoor(0).Door, sTempFile, False, False) ExecDoors(Map.refSceneManagerVM.ProjectScene, sTempFile) Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nDDFPage Else DdfFile.WriteDDFAssembly(NewAssName.SelAssembly, sTempFile, False) ExecDoors(Map.refSceneManagerVM.ProjectScene, sTempFile) Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nAssemblyPage End If Return End Sub Public Function Save(SavedAssName As AssemblyName) As Boolean If IsNothing(SavedAssName) Then Return False ' Salvo If OptionModule.m_ConfigurationSoftware = ConfigType.Door Then DdfFile.WriteDDFPart(SavedAssName.SelAssembly.GetArrayPartDoor(0).Door, SavedAssName.Name, True, False) Else DdfFile.WriteDDFAssembly(SavedAssName.SelAssembly, SavedAssName.Name, True) End If SavedAssName.IsModified = False SavedAssName.NotifyPropertyChanged("IsModify") 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 ' Seleziono questo AssemblyName CurrProject.SelAssemblyName = OpenedAssName ' resetto errori sui bevel edge Part.FirstReadingEdge = False ' leggo il ddf e creo relativo assemblato OpenedAssName.SelAssembly = CreateNewAssembly(OpenedAssName.Name) 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 Return False OpenedAssName.IsModified = Part.FirstReadingEdge If OptionModule.m_ConfigurationSoftware = ConfigType.Door Then DdfFile.WriteDDFPart(OpenedAssName.SelAssembly.GetArrayPartDoor(0).Door, sTempFile, True, False) ExecDoors(Map.refSceneManagerVM.ProjectScene, sTempFile) Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nDDFPage Else DdfFile.WriteDDFAssembly(OpenedAssName.SelAssembly, sTempFile, True) ExecDoors(Map.refSceneManagerVM.ProjectScene, sTempFile) Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nAssemblyPage End If Return True End Function Public Sub Delete(DeleteAssName As AssemblyName) ' Se il file esiste eliminalo 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 ' 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) Else m_CurrProject.SelAssemblyName = m_CurrProject.AssemblyList(SelIndex) Open(m_CurrProject.SelAssemblyName) End If ' se non ci sono altre porte nella lista allora Else ' elimino qualsiasi resto di porta m_CurrProject.SelAssemblyName = Nothing ' pulisco entry page Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nNothingSelected ' 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.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 Save(m_CurrProject.SelAssemblyName) m_CurrProject.SelAssemblyName.IsModified = False Case MessageBoxResult.No If Not File.Exists(m_CurrProject.SelAssemblyName.Name) Then m_CurrProject.AssemblyList.Remove(m_CurrProject.SelAssemblyName) 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" ' Caricamento dei dati della pagina generale degli assemblati Friend Function CreateNewAssembly(value As String) As Assembly '' se non esisteva nessuna porta allora posso procedere 'CurrProject.SelAssemblyName.Name = value 'NotifyPropertyChanged("SelectedAssembly") ' costruisco un nuvo assemblato e lo carico con i valori Dim Local_SelAssembly As New Assembly Local_SelAssembly.SetExterior(OptionModule.m_Exterior) Local_SelAssembly.DoorListNumber = OptionModule.m_DoorsListNumber ' Carico tutti i vettori in sola lettura (i metodi set non contengono nessuna operazione) Local_SelAssembly.SetThickness(OptionModule.m_ThicknessJamb) Local_SelAssembly.SetWidth(OptionModule.m_WidthJamb) Local_SelAssembly.SetLightUp(OptionModule.m_LightUp) Local_SelAssembly.SetLightLock(OptionModule.m_LightLock) Local_SelAssembly.SetLightBottom(OptionModule.m_LightBottom) Local_SelAssembly.SetLightHinge(OptionModule.m_LightHinge) Local_SelAssembly.SetThicknessHead(OptionModule.m_ThicknessHead) Local_SelAssembly.SetOverlapHinge(OptionModule.m_OverlapHinge) Local_SelAssembly.SetOverlapLock(OptionModule.m_OverlapLock) Local_SelAssembly.SetOverlapTop(OptionModule.m_OverlapTop) Local_SelAssembly.SetDeltaThickness(OptionModule.m_DeltaThickness) Local_SelAssembly.SetLockEdgeType(OptionModule.m_LockEdgeTypeAssembly) Local_SelAssembly.SetHingeEdgeType(OptionModule.m_HingeEdgeTypeAssembly) Local_SelAssembly.SetTopType(OptionModule.m_TopTypeAssembly) Local_SelAssembly.SetBottomType(OptionModule.m_BottomTypeAssembly) Local_SelAssembly.SetLockEdgeMachining(OptionModule.m_LockEdgeMachiningAssembly) Local_SelAssembly.SetHingeEdgeMachining(OptionModule.m_HingeEdgeMachiningAssembly) Local_SelAssembly.SetTopMachining(OptionModule.m_TopMachiningAssembly) Local_SelAssembly.SetBottomMachining(OptionModule.m_BottomMachiningAssembly) Local_SelAssembly.SetLockEdgeOverMaterial(OptionModule.m_LockEdgeOverMaterialAssembly) Local_SelAssembly.SetHingeEdgeOverMaterial(OptionModule.m_HingeEdgeOverMaterialAssembly) Local_SelAssembly.SetTopOverMaterial(OptionModule.m_TopOverMaterialAssembly) Local_SelAssembly.SetBottomOverMaterial(OptionModule.m_BottomOverMaterialAssembly) Local_SelAssembly.SetDoorNumber(OptionModule.m_DoorsNumber) ' costruisco e carico le parti CreatePart(Local_SelAssembly) ' carico l'assemblato che sto creando in locale (così da poter gestire i Jamb) m_CurrProject.SelAssemblyName.SelAssembly = Local_SelAssembly CreateDoor(Local_SelAssembly) ' calcolo la dimensione dei Jambs in funzione del numero di porte visibili Local_SelAssembly.DoorVisibilityNew() Local_SelAssembly.TopRabbetJamb() 'Local_SelAssembly.HingeRabbetJamb() Return Local_SelAssembly End Function ' creazione dei jamb Private Sub CreatePart(ByRef CurrAssembly As Assembly) CurrAssembly.LeftJamb = New Part CurrAssembly.LeftJamb.TypePart = "FL_" CurrAssembly.LeftJamb.SetThickness(CurrAssembly.Thickness) CurrAssembly.LeftJamb.SetWidth(CurrAssembly.Width) CurrAssembly.LeftJamb.SwingTypeList = OptionModule.m_SwingTypeList CurrAssembly.LeftJamb.IsActive = OptionModule.m_LeftJambChk CurrAssembly.RightJamb = New Part CurrAssembly.RightJamb.TypePart = "FR_" CurrAssembly.RightJamb.SetThickness(CurrAssembly.Thickness) CurrAssembly.RightJamb.SetWidth(CurrAssembly.Width) CurrAssembly.RightJamb.SwingTypeList = OptionModule.m_SwingTypeList CurrAssembly.RightJamb.IsActive = OptionModule.m_RightJambChk CurrAssembly.TopJamb = New Part CurrAssembly.TopJamb.TypePart = "FT_" CurrAssembly.TopJamb.SetThickness(CurrAssembly.Thickness) CurrAssembly.TopJamb.SetHeight(CurrAssembly.ThicknessHead) CurrAssembly.TopJamb.SwingTypeList = OptionModule.m_SwingTypeList CurrAssembly.TopJamb.IsActive = OptionModule.m_TopJambChk CurrAssembly.BottomJamb = New Part CurrAssembly.BottomJamb.TypePart = "FB_" CurrAssembly.BottomJamb.SetThickness(CurrAssembly.Thickness) CurrAssembly.BottomJamb.SetHeight(CurrAssembly.Width) CurrAssembly.BottomJamb.SwingTypeList = OptionModule.m_SwingTypeList CurrAssembly.BottomJamb.IsActive = OptionModule.m_BottomJambChk End Sub ' Caricamento del vettore delle porte, se già ne esiste uno esso viene sovrascritto con nuovi oggetti Private Sub CreateDoor(ByRef CurrAssembly As Assembly) CurrAssembly.LockEdgeType = CurrAssembly.LockEdgeType CurrAssembly.HingeEdgeType = CurrAssembly.HingeEdgeType CurrAssembly.TopType = CurrAssembly.TopType CurrAssembly.BottomType = CurrAssembly.BottomType CurrAssembly.LockEdgeMachining = CurrAssembly.LockEdgeMachining CurrAssembly.HingeEdgeMachining = CurrAssembly.HingeEdgeMachining CurrAssembly.TopMachining = CurrAssembly.TopMachining CurrAssembly.BottomMachining = CurrAssembly.BottomMachining CurrAssembly.LockEdgeOverMaterial = CurrAssembly.LockEdgeOverMaterial CurrAssembly.HingeEdgeOverMaterial = CurrAssembly.HingeEdgeOverMaterial CurrAssembly.TopOverMaterial = CurrAssembly.TopOverMaterial CurrAssembly.BottomOverMaterial = CurrAssembly.BottomOverMaterial ' qui carico il vettore delle porte (se il vettore è vuoto) Dim ref_PartDoor As PartDoor Dim ref_Door As Part For IndexDoor As Integer = 0 To K_DOORNUMBER ref_PartDoor = New PartDoor ref_Door = New Part ref_Door.TypePart = "DO_" & IndexDoor + 1 LoadDefaultPartOne(ref_Door) ref_PartDoor.Door = ref_Door ref_PartDoor.IsChecked = True CurrAssembly.ArrayPartDoor.Add(ref_PartDoor) Next End Sub ' carica i valori di default negli oggetti appena creati Public Sub LoadDefaultPartOne(ByRef ref_Part As Part) 'OptionModule.GeneralDoor.CompoList.Clear() '--------------------------------------------------------------------------------------------------------------- ' Date le dimensioni della porta calcoliamo la dimensione dei Jamb ref_Part.Width = OptionModule.m_Width ref_Part.Height = OptionModule.m_Height ref_Part.Thickness = OptionModule.m_Thickness '--------------------------------------------------------------------------------------------------------------- ' i parametri che seguono non influenzano in alcun modo i jamb ref_Part.SetSwing(OptionModule.m_Swing) ref_Part.IsActive = False ref_Part.Measure = OptionModule.m_SelectedMeasureUnit ref_Part.Weight = OptionModule.m_Weight ref_Part.LockEdgeType = OptionModule.m_LockEdgeType ref_Part.HingeEdgeType = OptionModule.m_HingeEdgeType ref_Part.TopType = OptionModule.m_TopType ref_Part.BottomType = 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 End Sub #End Region ' Creazione e caricamento degli oggetti dell'assemblato #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 ImportTemplate As String = 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 ' End If ' ' carico l'indirizzo del template che voglio aprire ' ImportTemplate = OpenFileDialog.FileName 'End If '---------------------------------------------------------------------------------------------------------------------------------------------------- ' Creo nuovo assembly ' Lancio la finestra per chiedere il nome dell'assemblato Dim SaveFileDialog As New EgtWPFLib5.EgtSaveFileDialog SaveFileDialog.Title = K_NEWDOOR SaveFileDialog.Directory = m_CurrProject.Name SaveFileDialog.Extension = K_DDFEXTENSION ' Se annullo esco If Not SaveFileDialog.EgtShowDialog Then Return ' Controllo se il nome della porta ha estensione 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 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 = SaveFileDialog.FileName 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) ' ''CurrProject.NotifyPropertyChanged("AssemblyList") End If ' aggiungo il nome del file alla lista degli assemblati Dim Local_AssemblyName As New AssemblyName Local_AssemblyName.Name = SaveFileDialog.FileName m_CurrProject.AssemblyList.Add(Local_AssemblyName) ' Seleziono AssembyName creato m_CurrProject.SelAssemblyName = Local_AssemblyName ' aggiorno la lista ''CurrProject.NotifyPropertyChanged("AssemblyList") '------------------------------------------------------------------------------------------------------------------------------------------------ ' LETTURA DI UN FILE DI TIPO TEMPLATE 'If String.IsNullOrEmpty(ImportTemplate) Then ' NewAssembly = True 'Else ' ' !!!!se sto aprendo un template significa che devo leggere un file già esistente!!!! ' NewAssembly = False ' ' creo il file ddf associato al template ' Map.refAssemblyPageVM.CurrAssembly = CreateNewAssembly(ImportTemplate) ' Assembly.ReadDDFAssembly(ImportTemplate, Map.refAssemblyPageVM.CurrAssembly) ' DdfFile.WriteDDFPart(Map.refAssemblyPageVM.CurrAssembly.GetArrayPartDoor(0).Door, Local_AssemblyName.Name, True, False) 'End If '------------------------------------------------------------------------------------------------------------------------------------------------ ' Creo nuovo assembly NewCmd(Local_AssemblyName) ' carico il nome come Assemblato selezionato Dim OrderWindow As New OrderV(Application.Current.MainWindow, New OrderVM()) OrderWindow.ShowDialog() End Sub #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