Files
EgtDOORCreator/AssemblyManager/AssemblyManagerVM.vb
T
Nicola Pievani 0887fdf3fa EgtDOORCreator 1.9j3 :
- gestione creazione/apertura singola porta.
2018-10-20 10:59:06 +00:00

862 lines
40 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
End Set
End Property
Private m_VisibilityDoorList As Visibility = Visibility.Visible
Public Property VisibilityDoorList As Visibility
Get
Return m_VisibilityDoorList
End Get
Set(value As Visibility)
m_VisibilityDoorList = 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
' ricarico la lista completa degli swing
NewAssName.SelAssembly.ListPartDoor(0).Door.SwingTypeList = OptionModule.m_SwingTypeList
NewAssName.SelAssembly.ListPartDoor(0).Door.SetSwing(OptionModule.m_Swing)
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)
EgtZoom(ZM.ALL)
Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nDDFPage
Else
DdfFile.WriteDDFAssembly(NewAssName.SelAssembly, sTempFile, False)
ExecDoors(Map.refSceneManagerVM.ProjectScene, sTempFile, False)
' aggiorno elenco quotature
Map.refDimensioningPanelVM.LoadHardwareDimList()
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
' 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
If MessageBox.Show("The current ddf is a part of a frame, do you want to save?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No) = MessageBoxResult.Yes Then
DdfFile.WriteDDFPart(SavedAssName.SelAssembly.ListPartDoor(0).Door, SavedAssName.Name, True, False)
Else
Return False
End If
Else
DdfFile.WriteDDFPart(SavedAssName.SelAssembly.ListPartDoorOfDoor(0).Door, SavedAssName.Name, True, False)
End If
Else
DdfFile.WriteDDFAssembly(SavedAssName.SelAssembly, SavedAssName.Name, True)
End If
If DdfFile.DDFIsCorrect 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")
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 Return False
OpenedAssName.IsModified = Part.FirstReadingEdge
If OptionModule.m_ConfigurationSoftware = ConfigType.Door Then
DdfFile.WriteDDFPart(OpenedAssName.SelAssembly.ListPartDoor(0).Door, sTempFile, True, 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
DdfFile.WriteDDFAssembly(OpenedAssName.SelAssembly, sTempFile, True)
' aggiorno elenco quotature
Map.refDimensioningPanelVM.LoadHardwareDimList()
ExecDoors(Map.refSceneManagerVM.ProjectScene, sTempFile, False)
Map.refSceneManagerVM.ShowGraphicError()
EgtZoom(ZM.ALL)
Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nAssemblyPage
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
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
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
' 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()
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)
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
CreateNewPropertiesListJamb(LeftJamb.Door.PropertiesList)
' 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
CreateNewPropertiesListJamb(RightJamb.Door.PropertiesList)
' 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
CreateNewPropertiesListJamb(TopJamb.Door.PropertiesList)
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.Thickness)
BottomJamb.Door.SetHeight(CurrAssembly.Width)
' assegno la lista completa degli swing perchè la selezione dello swing corretto avviene nel programma
BottomJamb.Door.SwingTypeList = OptionModule.m_SwingTypeList
BottomJamb.Door.IsActive = OptionModule.m_BottomJambChk
' definisce la disposizione (da selezionare in una sola anta)
BottomJamb.Door.SetDispositionItem(OptionModule.m_Disposition)
CreateNewPropertiesListJamb(BottomJamb.Door.PropertiesList)
If bNewAssembly Then
BottomJamb.IsChecked = True
BottomJamb.IsChecked = OptionModule.m_TopJambChk
Else
BottomJamb.IsChecked = False
BottomJamb.IsChecked = 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
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
If IsNothing(ReserchPartDoor(Type)) 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.IsChecked = True
CreateNewPropertiesList(Local_PartDoor.Door.PropertiesList)
CurrAssembly.ListPartDoor.Add(Local_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)
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 ImportTemplate As String = String.Empty
If Not OptionModule.m_DisableTemplate Then
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
End If
'----------------------------------------------------------------------------------------------------------------------------------------------------
' 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 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 = DDF_EXTENSION Then
SaveFileDialog.FileName = SaveFileDialog.FileName.Replace(sExtension, DDF_EXTENSION)
End If
Else
SaveFileDialog.FileName &= DDF_EXTENSION
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)
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
'------------------------------------------------------------------------------------------------------------------------------------------------
' LETTURA DI UN FILE DI TIPO TEMPLATE
If Not String.IsNullOrEmpty(ImportTemplate) Then
' creo il file ddf associato al template
'm_CurrProject.SelAssemblyName.SelAssembly = CreateNewAssembly(ImportTemplate)
m_CurrProject.SelAssemblyName.SelAssembly = New Assembly
Assembly.ReadDDFAssembly(ImportTemplate, 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)
Return
End If
End If
'------------------------------------------------------------------------------------------------------------------------------------------------
' Creo nuovo assembly
NewCmd(Local_AssemblyName)
' 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
#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