Files
EgtDOORCreator/SceneManager/SceneManagerViewModel.vb
T
Nicola Pievani efb250b4a4 EgtDOORCreator 1.8e2 :
- aggiunto il campo "Weight" al general del door,
- aggiunta di una variabile booleana alla funzione ReadDDF nella classe Door per permettere di stampare le funzioni scritte nelle textbox, attualmente no è in uso (settata True)
2017-05-09 16:04:50 +00:00

300 lines
12 KiB
VB.net

Imports System.ComponentModel
Imports System.IO
Imports System.Windows.Forms.Integration
Imports EgtUILib
'Imports System.Text.RegularExpressions
Public Class SceneManagerViewModel
Implements INotifyPropertyChanged
' riferimento alla finestra principale
Private m_rfMainWindowViewModel As MainWindowViewModel
Friend bProtectKey As Boolean = True
Private m_ShowPanel As ShowPanelView
Public ReadOnly Property ShowPanel As ShowPanelView
Get
If IsNothing(m_ShowPanel) Then
m_ShowPanel = New ShowPanelView
m_ShowPanel.DataContext = New ShowPanelViewModel(Me)
End If
Return m_ShowPanel
End Get
End Property
Private m_ViewPanel As ViewPanelView
Public ReadOnly Property ViewPanel As ViewPanelView
Get
If IsNothing(m_ViewPanel) Then
m_ViewPanel = New ViewPanelView
m_ViewPanel.DataContext = New ViewPanelViewModel(Me)
End If
Return m_ViewPanel
End Get
End Property
Private m_PopUpViewPanel As PopUpViewPanelView
Public ReadOnly Property PopUpViewPanel As PopUpViewPanelView
Get
If IsNothing(m_PopUpViewPanel) Then
m_PopUpViewPanel = New PopUpViewPanelView
m_PopUpViewPanel.DataContext = New PopUpViewPanelViewModel(Me)
End If
Return m_PopUpViewPanel
End Get
End Property
Private m_InstrumentPanel As InstrumentPanelView
Public ReadOnly Property InstrumentPanel As InstrumentPanelView
Get
If IsNothing(m_InstrumentPanel) Then
m_InstrumentPanel = New InstrumentPanelView
m_InstrumentPanel.DataContext = New InstrumentPanelViewModel(Me)
End If
Return m_InstrumentPanel
End Get
End Property
Private m_RefreshPanel As RefreshPanelView
Public ReadOnly Property RefreshPanel As RefreshPanelView
Get
If IsNothing(m_RefreshPanel) Then
m_RefreshPanel = New RefreshPanelView
m_RefreshPanel.DataContext = New RefreshPanelViewModel(Me)
End If
Return m_RefreshPanel
End Get
End Property
Private m_StatusBar As StatusBarView
Public ReadOnly Property StatusBar As StatusBarView
Get
If IsNothing(m_StatusBar) Then
m_StatusBar = New StatusBarView
m_StatusBar.DataContext = New StatusBarViewModel(Me)
End If
Return m_StatusBar
End Get
End Property
'PROJECT PAGE'S SCENE FIELDS AND PROPERTIES
' Reference to the ProjectScene
Private WithEvents m_ProjectScene As New Scene
Public ReadOnly Property ProjectScene As Scene
Get
Return m_ProjectScene
End Get
End Property
' Property used to bind the scene to the WindowsFormsHost in XAML
Private m_ProjectSceneHost As WindowsFormsHost
Public ReadOnly Property ProjectSceneHost As WindowsFormsHost
Get
If IsNothing(m_ProjectSceneHost) Then
m_ProjectSceneHost = New WindowsFormsHost() With {.Child = m_ProjectScene}
' Creazione scena
PreInitializeScene()
If Not m_ProjectScene.Init() Then
bProtectKey = False
EgtOutLog(EgtMsg(5129))
m_ProjectSceneHost.Child = Nothing
' Box di avviso chiave mancante
MessageBox.Show(EgtMsg(MSG_MISSINGKEYWD + 2) & vbCrLf & EgtMsg(MSG_MISSINGKEYWD + 3), EgtMsg(MSG_MISSINGKEYWD + 1), MessageBoxButton.OK, MessageBoxImage.Error)
' Chiudo il programma
Application.Current.Shutdown()
' Verifico abilitazione prodotto
ElseIf (IniFile.m_nKeyOptions And KEY_OPT.DOORCREATOR) = 0 Then
MsgBox(EgtMsg(MSG_MISSINGKEYWD + 5), MsgBoxStyle.OkOnly, EgtMsg(MSG_MISSINGKEYWD + 1))
' Chiudo il programma
Application.Current.Shutdown()
' Tutto bene
Else
EgtSetCurrentContext(m_ProjectScene.GetCtx)
PostInitializeScene()
m_ProjectScene.SetStatusNull()
End If
End If
Return m_ProjectSceneHost
End Get
End Property
' ''#Region "Messages"
' '' Public ReadOnly Property RefreshMsg As String
' '' Get
' '' Return EgtMsg(50301)
' '' End Get
' '' End Property
' ''#End Region
' ''#Region "ToolTip"
' '' Public ReadOnly Property RefreschToolTip As String
' '' Get
' '' Return EgtMsg(50301)
' '' End Get
' '' End Property
' ''#End Region
' Scene controller
Private WithEvents m_Controller As New Controller
' definizione comando
Private m_CmdRefreshBtn As ICommand
Sub New(ByRef MainWindowViewModel As MainWindowViewModel)
m_rfMainWindowViewModel = MainWindowViewModel
End Sub
Private Sub PreInitializeScene()
' imposto colore di default
Dim DefColor As New Color3d(0, 0, 0)
GetPrivateProfileColor(S_GEOMDB, K_DEFAULTCOLOR, DefColor)
m_ProjectScene.SetDefaultMaterial(DefColor)
' imposto colori sfondo
Dim BackTopColor As New Color3d(192, 192, 192)
GetPrivateProfileColor(S_SCENE, K_BACKTOP, BackTopColor)
Dim BackBotColor As New Color3d(BackTopColor)
GetPrivateProfileColor(S_SCENE, K_BACKBOTTOM, BackBotColor)
m_ProjectScene.SetViewBackground(BackTopColor, BackBotColor)
' imposto colore di evidenziazione
Dim MarkColor As New Color3d(255, 255, 0)
GetPrivateProfileColor(S_SCENE, K_MARK, MarkColor)
m_ProjectScene.SetMarkMaterial(MarkColor)
' imposto colore per superfici selezionate
Dim SelSurfColor As New Color3d(255, 255, 192)
GetPrivateProfileColor(S_SCENE, K_SELSURF, SelSurfColor)
m_ProjectScene.SetSelSurfMaterial(SelSurfColor)
' imposto tipo e colore del rettangolo di zoom
Dim bOutline As Boolean = True
Dim ZwColor As New Color3d(0, 0, 0)
GetPrivateProfileZoomWin(S_SCENE, K_ZOOMWIN, bOutline, ZwColor)
m_ProjectScene.SetZoomWinAttribs(bOutline, ZwColor)
' imposto colore della linea di distanza
Dim DstLnColor As New Color3d(255, 0, 0)
GetPrivateProfileColor(S_SCENE, K_DISTLINE, DstLnColor)
m_ProjectScene.SetDistLineMaterial(DstLnColor)
' imposto parametri OpenGL
Dim nDriver As Integer = GetPrivateProfileInt(S_OPENGL, K_DRIVER, 3)
Dim b2Buff As Boolean = (GetPrivateProfileInt(S_OPENGL, K_DOUBLEBUFFER, 1) <> 0)
Dim nColorBits As Integer = GetPrivateProfileInt(S_OPENGL, K_COLORBITS, 32)
Dim nDepthBits As Integer = GetPrivateProfileInt(S_OPENGL, K_DEPTHBITS, 32)
m_ProjectScene.SetViewAttributes(nDriver, b2Buff, nColorBits, nDepthBits)
End Sub
Private Sub PostInitializeScene()
' Impostazioni Controller
m_Controller.SetScene(m_ProjectScene)
Dim bLuaReg As Boolean = (GetPrivateProfileInt(S_GENERAL, K_COMMANDLOG, 0) <> 0)
Dim nShowMode As Integer = GetPrivateProfileInt(S_SCENE, K_SHOWMODE, SM.SHADING)
Dim nShowCurveDir As Integer = GetPrivateProfileInt(S_SCENE, K_CURVEDIR, 0)
End Sub
'questo metodo restituisce l'errore letto nel file CurrDoor.txt
Friend Sub ShowGraphicError()
Dim FileContent() As String
' controllo se esite il file CurrDoor.txt
If Not File.Exists(IniFile.m_sTempDir & "\" & TEMP_FILE_TXT) Then Return
FileContent = File.ReadAllLines(IniFile.m_sTempDir & "\" & TEMP_FILE_TXT)
' se il file esiste ma è vuoto
If FileContent.Count = 0 Then
MessageBox.Show(EgtMsg(50107), EgtMsg(50101), MessageBoxButton.OK, MessageBoxImage.Error)
End If
Dim IndexLine As Integer = 0
Dim nMsgErr As Integer = 0
' leggo il valore numerico (se il valore non è numerico è passato di default il valore 0)
nMsgErr = RegexFunction.ErrDraw(FileContent(IndexLine))
' passo alla riga succesiva
IndexLine += 1
' se il valore è maggiore di zero allora è un errore
If nMsgErr > 0 Then
' salto tutte le righe vuote
While String.IsNullOrEmpty(FileContent(IndexLine)) AndAlso IndexLine < FileContent.Count
IndexLine += 1
End While
DirectCast(Me.RefreshPanel.DataContext, RefreshPanelViewModel).m_MsgGraphic = FileContent(IndexLine)
'MessageBox.Show(FileContent(IndexLine), "Error", MessageBoxButton.OK, MessageBoxImage.Error)
' se compare u errore disattivo il righello
DirectCast(Me.InstrumentPanel.DataContext, InstrumentPanelViewModel).GetDistIsChecked = False
' rendo visibile il bottone dell'errore
DirectCast(Me.RefreshPanel.DataContext, RefreshPanelViewModel).ButtonVisibility = Visibility.Visible
DirectCast(Me.RefreshPanel.DataContext, RefreshPanelViewModel).MsgError = EgtMsg(50101) & nMsgErr
' altrimenti un avvertimento
ElseIf nMsgErr < 0 Then
While String.IsNullOrEmpty(FileContent(IndexLine)) AndAlso IndexLine < FileContent.Count
IndexLine += 1
End While
DirectCast(Me.RefreshPanel.DataContext, RefreshPanelViewModel).m_MsgGraphic = FileContent(IndexLine)
'MessageBox.Show(FileContent(IndexLine), "Warning", MessageBoxButton.OK, MessageBoxImage.Warning)
DirectCast(Me.RefreshPanel.DataContext, RefreshPanelViewModel).ButtonVisibility = Visibility.Visible
DirectCast(Me.RefreshPanel.DataContext, RefreshPanelViewModel).MsgError = EgtMsg(50144) & nMsgErr
End If
If nMsgErr = 0 Then
'DirectCast(Me.StatusBar.DataContext, StatusBarViewModel).StatusOutput = String.Empty
DirectCast(Me.RefreshPanel.DataContext, RefreshPanelViewModel).ButtonVisibility = Visibility.Collapsed
End If
End Sub
#Region "COMMAND"
#Region "RefreshBtnCommand"
''' <summary>
''' Returns a command that do Exec.
''' </summary>
Public ReadOnly Property RefreshBtnCommand As ICommand
Get
If m_CmdRefreshBtn Is Nothing Then
m_CmdRefreshBtn = New Command(AddressOf RefreshBtn)
End If
Return m_CmdRefreshBtn
End Get
End Property
''' <summary>
''' Execute the Exec. This method is invoked by the ExecCommand.
''' </summary>
Public Sub RefreshBtn()
Dim rfDoorParametersViewModel As DoorParametersViewModel = DirectCast(m_rfMainWindowViewModel.DoorParameters.DataContext, DoorParametersViewModel)
Dim CurrDoorPath As String = IniFile.m_sTempDir & "\" & TEMP_FILE
If Not IsNothing(rfDoorParametersViewModel.CurrDoor) AndAlso Not String.IsNullOrWhiteSpace(DirectCast(m_rfMainWindowViewModel.DoorManager.DataContext, DoorManagerViewModel).SelectedDoor) Then
DdfFile.WriteDDF(rfDoorParametersViewModel.CurrDoor, CurrDoorPath, True)
ExecDoors(m_ProjectScene, CurrDoorPath)
End If
ShowGraphicError()
End Sub
#End Region ' RefreshBtnCommand
#End Region ' Command
#Region "EVENTS"
Sub m_ProjectScene_OnChangedSnapPointType(sender As Object, nSpType As EgtUILib.EgtInterface.SP, bForced As Boolean) Handles m_ProjectScene.OnChangedSnapPointType
Dim rfStatusBarViewModel As StatusBarViewModel = DirectCast(m_StatusBar.DataContext, StatusBarViewModel)
For SnapIndex = 0 To rfStatusBarViewModel.SnapPointTypeList.Count - 1
Dim TempSnapPoint As SPItem = rfStatusBarViewModel.SnapPointTypeList(SnapIndex)
If TempSnapPoint.SPValue = nSpType Then
rfStatusBarViewModel.SnapPointSelect = TempSnapPoint
End If
Next
End Sub
Sub m_ProjectScene_OnShowDistance(sender As Object, sDistance As String) Handles m_ProjectScene.OnShowDistance
' se deseleziono il righello
Dim rfStatusBarViewModel As StatusBarViewModel = DirectCast(m_StatusBar.DataContext, StatusBarViewModel)
Dim rfInstrumentPanel As InstrumentPanelViewModel = DirectCast(m_InstrumentPanel.DataContext, InstrumentPanelViewModel)
' restituisco una stringa vuota alla textblock che contiene la distanza
rfStatusBarViewModel.StatusOutput = sDistance
End Sub
#End Region
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Public Sub NotifyPropertyChanged(propName As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propName))
End Sub
End Class