234 lines
8.5 KiB
VB.net
234 lines
8.5 KiB
VB.net
Imports EgtBEAMWALL.Core.ConstBeam
|
|
Imports EgtUILib
|
|
Imports EgtWPFLib5
|
|
Imports System.IO
|
|
|
|
Public Class MainWindowVM
|
|
Inherits VMBase
|
|
|
|
' Riferimento al Model della MainWindow
|
|
Private m_MainWindowM As MainWindowM
|
|
Friend ReadOnly Property MainWindowM As MainWindowM
|
|
Get
|
|
Return m_MainWindowM
|
|
End Get
|
|
End Property
|
|
|
|
' Variabile che indica che il programma è stato avviato correttamente (sia la mappa che l'ambiente Egt)
|
|
Private m_bInitStatus As Boolean
|
|
Friend ReadOnly Property bInitStatus As Boolean
|
|
Get
|
|
Return m_bInitStatus
|
|
End Get
|
|
End Property
|
|
|
|
' Titolo
|
|
Private m_Title As String = ""
|
|
Public ReadOnly Property Title As String
|
|
Get
|
|
Return m_Title
|
|
End Get
|
|
End Property
|
|
|
|
' proprietà che seleziona la giusta pagina del TabControl
|
|
Public Property nSelTabPage As Integer
|
|
Get
|
|
Return If(IsNothing(Map.refMainMenuVM.SelPage) OrElse Map.refMainMenuVM.SelPage = -1 OrElse Map.refMainMenuVM.SelPage = Pages.VIEW OrElse Map.refMainMenuVM.SelPage = Pages.MACHINING, 0, 1)
|
|
End Get
|
|
Set(value As Integer)
|
|
End Set
|
|
End Property
|
|
|
|
Private m_MachinePanelVM As MachinePanelVM
|
|
Public ReadOnly Property MachinePanelVM As MachinePanelVM
|
|
Get
|
|
Return m_MachinePanelVM
|
|
End Get
|
|
End Property
|
|
|
|
' definizione comandi
|
|
Private m_cmdAboutBox As ICommand
|
|
Private m_cmdCloseApplication As ICommand
|
|
|
|
#Region "CONSTRUCTOR"
|
|
|
|
Sub New()
|
|
' Avvio l'inizializzazione della mappa passandogli il riferimento al MainWindowVM
|
|
Map.BeginInit(Me)
|
|
' Creo Model della MainWindow
|
|
m_MainWindowM = New MainWindowM
|
|
' inizializzo machine panel
|
|
m_MachinePanelVM = New MachinePanelVM
|
|
End Sub
|
|
|
|
#End Region ' CONSTRUCTOR
|
|
|
|
#Region "METHODS"
|
|
|
|
Friend Sub SetTitle(sTitle As String)
|
|
m_Title = sTitle
|
|
NotifyPropertyChanged(NameOf(Title))
|
|
End Sub
|
|
Public Sub UpdateTitle()
|
|
m_Title = ""
|
|
Select Case Map.refMainMenuVM.SelPage
|
|
Case Pages.VIEW
|
|
If Not IsNothing(Map.refProjManagerVM.CurrProj) Then
|
|
If Map.refProjManagerVM.CurrProj.bIsNew Then m_Title = "New - "
|
|
m_Title &= Map.refProjManagerVM.CurrProj.nProjId.ToString("0000") & " - " & Map.refProjManagerVM.CurrProj.sBTLFileName
|
|
End If
|
|
Case Pages.MACHINING
|
|
If Not IsNothing(Map.refProdManagerVM.CurrProd) Then
|
|
If Map.refProdManagerVM.CurrProd.bIsNew Then m_Title = "New - "
|
|
m_Title &= Map.refProdManagerVM.CurrProd.nProdId.ToString("0000") & " - " & Map.refProdManagerVM.CurrProd.sBTLFileName
|
|
End If
|
|
Case Pages.CONFIG
|
|
m_Title = "Configuration Page"
|
|
End Select
|
|
m_Title &= " - EgtBEAMWALL"
|
|
NotifyPropertyChanged(NameOf(Title))
|
|
End Sub
|
|
|
|
Friend Sub ContentRendered()
|
|
'' chiamata a caso su Db per inizializzarlo
|
|
DbControllers.m_ProjController.FindByProjDbId(0)
|
|
' Verifico che l'inizializzazione di tutte le parti del programma sia andata a buon fine
|
|
If Map.EndInit() Then
|
|
m_bInitStatus = True
|
|
' altrimenti chiudo il programma
|
|
Else
|
|
m_bInitStatus = False
|
|
End If
|
|
' Aggiorno visualizzazione unità di misura
|
|
'Map.refStatusBarVM.SetMeasureUnit(If(EgtUiUnitsAreMM(), MeasureUnitOpt.MM, MeasureUnitOpt.INCH))
|
|
' Se istanza oltre la prima, chiedo cosa aprire
|
|
If Not m_MainWindowM.bFirstInstance Then
|
|
' Map.refProjectManagerVM.Open()
|
|
' ' altrimenti verifico se richiesto ultimo progetto
|
|
'ElseIf GetMainPrivateProfileInt(S_GENERAL, K_AUTOLOADLASTPROJ, 0) = 1 Then
|
|
' Dim sLastProjectPath As String = String.Empty
|
|
' GetMainPrivateProfileString(S_GENERAL, K_LASTPROJ, String.Empty, sLastProjectPath)
|
|
' If Not String.IsNullOrWhiteSpace(sLastProjectPath) AndAlso File.Exists(sLastProjectPath) Then
|
|
' Map.refProjectManagerVM.OpenProject(sLastProjectPath)
|
|
' Else
|
|
' Map.refProjectManagerVM.NewCmd()
|
|
' End If
|
|
' ' altrimenti nuovo progetto
|
|
'Else
|
|
' Map.refProjectManagerVM.NewCmd()
|
|
End If
|
|
' apro in modalita' VIEW
|
|
Map.refMainMenuVM.SelPage = Pages.VIEW
|
|
|
|
End Sub
|
|
|
|
Friend Sub KeyDown(PressedKey As Key)
|
|
' Con ESC esco dall'azione corrente
|
|
If PressedKey = Key.Escape Then
|
|
' se in modifica L250
|
|
If Map.refFreeContourManagerVM.bIsActive Then
|
|
' se in modifica testo angolo di inclinazione
|
|
If Map.refFreeContourManagerVM.bIsModifyingTextAngle Then
|
|
Map.refFreeContourManagerVM.CloseIsModifyingTextAngle(False)
|
|
End If
|
|
' reset Azione corrente
|
|
Map.refSceneHostVM.MainController.ResetStatus()
|
|
Map.refFreeContourInputVM.ResetInputBox()
|
|
End If
|
|
' se misura attiva, la disattivo
|
|
If Map.refInstrumentPanelVM.GetDistIsChecked Then
|
|
Map.refInstrumentPanelVM.SetGetDistance_IsChecked(False)
|
|
End If
|
|
' pulisco output
|
|
Map.refMyStatusBarVM.ClearOutputMessage()
|
|
End If
|
|
End Sub
|
|
|
|
|
|
#End Region ' METHODS
|
|
|
|
#Region "COMMANDS"
|
|
|
|
#Region "AboutBoxCommand"
|
|
|
|
' Returns a command that manage the MainWindow_Unloaded command
|
|
Public ReadOnly Property AboutBoxCommand() As ICommand
|
|
Get
|
|
If m_cmdAboutBox Is Nothing Then
|
|
m_cmdAboutBox = New Command(AddressOf AboutBox)
|
|
End If
|
|
Return m_cmdAboutBox
|
|
End Get
|
|
End Property
|
|
|
|
' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded.
|
|
Public Sub AboutBox(ByVal param As Object)
|
|
Dim AboutBoxWindow As New AboutBoxV
|
|
AboutBoxWindow.Owner = Application.Current.MainWindow
|
|
AboutBoxWindow.ShowDialog()
|
|
End Sub
|
|
|
|
#End Region ' AboutBoxCommand
|
|
|
|
#Region "CloseApplicationCommand"
|
|
|
|
' Returns a command that manage the MainWindow_Unloaded command
|
|
Public ReadOnly Property CloseApplicationCommand() As ICommand
|
|
Get
|
|
If m_cmdCloseApplication Is Nothing Then
|
|
m_cmdCloseApplication = New Command(AddressOf CloseApplication)
|
|
End If
|
|
Return m_cmdCloseApplication
|
|
End Get
|
|
End Property
|
|
|
|
' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded.
|
|
Public Sub CloseApplication(ByVal param As Object)
|
|
'If Map.refOptionPanelVM.SelItem = OptionPanelVM.Tabs.SIMUL Then
|
|
' Map.refSimulTabVM.ResetSimulation()
|
|
'End If
|
|
' Imposto contesto principale
|
|
'EgtSetCurrentContext(Map.refSceneHostVM.MainScene.GetCtx())
|
|
' Gestisco eventuale file corrente modificato
|
|
Dim bOk As Boolean = True
|
|
Select Case Map.refMainMenuVM.SelPage
|
|
Case Pages.VIEW
|
|
bOk = ProjFileVM.VerifyProjectModification(Map.refProjManagerVM.CurrProj, ProjectType.PROJ)
|
|
Case Pages.MACHINING
|
|
bOk = ProdFileVM.VerifyProjectModification(Map.refProdManagerVM.CurrProd)
|
|
Case Pages.CONFIG
|
|
' Verifica modifica parametri Macchina e chiedo il salvataggio
|
|
Map.refConfigurationPageVM.VerifyConfigPageModification()
|
|
End Select
|
|
' se salvataggio annullato, rimango
|
|
If Not bOk Then Return
|
|
Dim bAllowClose As Boolean = Map.refSceneHostVM.MainController.ManageModified()
|
|
' Salvo impostazione macchina corrente
|
|
Map.refMachinePanelVM.SaveCurrentMachine()
|
|
' Se non confermata chiusura, esco
|
|
If Not bAllowClose Then Return
|
|
' salvo modo di visualizzazione
|
|
WriteMainPrivateProfileString(S_SCENE, K_SHOWMODE, EgtGetShowMode().ToString)
|
|
' salvo visualizzazione assemblato
|
|
WriteMainPrivateProfileString(S_SCENE, K_SHOWBUILDING, If(Map.refShowBeamPanelVM.ShowBuilding_IsChecked, 1, 0))
|
|
' Salvo nome ultimo file (per gestire bene multi istanza)
|
|
Dim sFilePath As String = String.Empty
|
|
If EgtGetCurrFilePath(sFilePath) Then WriteMainPrivateProfileString(S_GENERAL, K_LASTPROJ, sFilePath)
|
|
' tolgo lock da file aperto
|
|
If Map.refMainMenuVM.SelPage = Pages.VIEW And Not IsNothing(Map.refProjManagerVM.CurrProj) Then
|
|
DbControllers.m_ProjController.LockByProjId(Map.refProjManagerVM.CurrProj.nProjId, False)
|
|
ElseIf Map.refMainMenuVM.SelPage = Pages.MACHINING And Not IsNothing(Map.refProdManagerVM.CurrProd) Then
|
|
DbControllers.m_ProdController.LockByProdId(Map.refProdManagerVM.CurrProd.nProdId, False)
|
|
End If
|
|
' Termino il Model
|
|
m_MainWindowM.Close()
|
|
' Termino il programma
|
|
Application.Current.Shutdown()
|
|
End Sub
|
|
|
|
#End Region ' CloseApplicationCommand
|
|
|
|
#End Region ' COMMANDS
|
|
|
|
End Class
|