Files
EgtDOORCreator/SceneManager/SceneManagerVM.vb
T
Nicola Pievani 0bc8e470b9 EgtDOORCreator 1.8j1 :
- creazione di assemblati
2017-11-21 16:07:47 +00:00

326 lines
13 KiB
VB.net

Imports System.ComponentModel
Imports System.IO
Imports System.Windows.Forms.Integration
Imports EgtUILib
'Imports System.Text.RegularExpressions
Public Class SceneManagerVM
Implements INotifyPropertyChanged
Friend bProtectKey As Boolean = True
Private m_ShowPanel As ShowPanelV
Public ReadOnly Property ShowPanel As ShowPanelV
Get
If IsNothing(m_ShowPanel) Then
m_ShowPanel = New ShowPanelV
m_ShowPanel.DataContext = New ShowPanelVM()
End If
Return m_ShowPanel
End Get
End Property
Private m_ViewPanel As ViewPanelV
Public ReadOnly Property ViewPanel As ViewPanelV
Get
If IsNothing(m_ViewPanel) Then
m_ViewPanel = New ViewPanelV
m_ViewPanel.DataContext = New ViewPanelVM(Me)
End If
Return m_ViewPanel
End Get
End Property
Private m_PopUpViewPanel As PopUpViewPanelV
Public ReadOnly Property PopUpViewPanel As PopUpViewPanelV
Get
If IsNothing(m_PopUpViewPanel) Then
m_PopUpViewPanel = New PopUpViewPanelV
m_PopUpViewPanel.DataContext = New PopUpViewPanelVM()
End If
Return m_PopUpViewPanel
End Get
End Property
Private m_InstrumentPanel As InstrumentPanelV
Public ReadOnly Property InstrumentPanel As InstrumentPanelV
Get
If IsNothing(m_InstrumentPanel) Then
m_InstrumentPanel = New InstrumentPanelV
m_InstrumentPanel.DataContext = New InstrumentPanelVM()
End If
Return m_InstrumentPanel
End Get
End Property
Private m_RefreshPanel As RefreshPanelV
Public ReadOnly Property RefreshPanel As RefreshPanelV
Get
If IsNothing(m_RefreshPanel) Then
m_RefreshPanel = New RefreshPanelV
m_RefreshPanel.DataContext = New RefreshPanelVM()
End If
Return m_RefreshPanel
End Get
End Property
Private m_StatusBar As StatusBarV
Public ReadOnly Property StatusBar As StatusBarV
Get
If IsNothing(m_StatusBar) Then
m_StatusBar = New StatusBarV
m_StatusBar.DataContext = New StatusBarVM()
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
' Scene controller
Private WithEvents m_Controller As New Controller
' definizione comando
Private m_CmdRefreshBtn As ICommand
'Private m_CmdAssemblyBtn As ICommand
Sub New()
Map.SetRefSceneManagerVM(Me)
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 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, RefreshPanelVM).m_MsgGraphic = FileContent(IndexLine)
'MessageBox.Show(FileContent(IndexLine), "Error", MessageBoxButton.OK, MessageBoxImage.Error)
' se compare u errore disattivo il righello
DirectCast(Me.InstrumentPanel.DataContext, InstrumentPanelVM).GetDistIsChecked = False
' rendo visibile il bottone dell'errore
DirectCast(Me.RefreshPanel.DataContext, RefreshPanelVM).ButtonVisibility = Visibility.Visible
DirectCast(Me.RefreshPanel.DataContext, RefreshPanelVM).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, RefreshPanelVM).m_MsgGraphic = FileContent(IndexLine)
'MessageBox.Show(FileContent(IndexLine), "Warning", MessageBoxButton.OK, MessageBoxImage.Warning)
DirectCast(Me.RefreshPanel.DataContext, RefreshPanelVM).ButtonVisibility = Visibility.Visible
DirectCast(Me.RefreshPanel.DataContext, RefreshPanelVM).MsgError = EgtMsg(50144) & nMsgErr
End If
If nMsgErr = 0 Then
'DirectCast(Me.StatusBar.DataContext, StatusBarVM).StatusOutput = String.Empty
DirectCast(Me.RefreshPanel.DataContext, RefreshPanelVM).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>
'''
Friend Shared nComposeAssembly As Integer
Public Sub RefreshBtn()
Dim rfDoorParametersVM As PartPageVM = Map.refPartPageVM
Dim CurrDoorPath As String = IniFile.m_sTempDir & "\" & TEMP_FILE
If Map.refMainWindowVM.SelectedPage = MainWindowVM.ListPageEnum.nDDFPage Then
DdfFile.WriteDDFPart(Map.refPartPageVM.CurrPart, CurrDoorPath, True, False)
DdfFile.WriteDDFAssembly(Map.refAssemblyPageVM.CurrAssembly, IniFile.m_sTempDir & "\" & TEMP_ASSEMBLY, True)
ExecDoors(m_ProjectScene, CurrDoorPath)
ComposeAssembly(nComposeAssembly)
Else
DdfFile.WriteDDFAssembly(Map.refAssemblyPageVM.CurrAssembly, IniFile.m_sTempDir & "\" & TEMP_ASSEMBLY, True)
ExecDoors(m_ProjectScene, IniFile.m_sTempDir & "\" & TEMP_ASSEMBLY)
ComposeAssembly(nComposeAssembly)
End If
ShowGraphicError()
End Sub
#End Region ' RefreshBtnCommand
#Region "AssemblyBtnCommand"
Public Sub AssemblyBtn()
If nComposeAssembly = 1 Then
NotAssemblyBtn()
Else
nComposeAssembly = 1
End If
RefreshBtn()
End Sub
Public Sub AssemblyExlposeBtn()
If nComposeAssembly = 2 Then
NotAssemblyBtn()
Else
nComposeAssembly = 2
End If
RefreshBtn()
End Sub
Public Sub NotAssemblyBtn()
nComposeAssembly = 0
End Sub
#End Region ' AssemblyBtn
#End Region ' Command
Public Sub ComposeAssembly(nAssembl As Integer)
If Not File.Exists(IniFile.m_sDoorsDirPath & "\" & "Main_Assemb.lua") Then
EgtOutLog("SetUp error: SetUp configuration file (" & IniFile.m_sDoorsDirPath & "\" & "Main_Assemb.lua)" & " doesn't exist ")
MessageBox.Show("File (" & IniFile.m_sDoorsDirPath & "\" & "Main_Assemb.lua)" & " doesn't exist ", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning)
'Return False
Else
EgtLuaExecFile(IniFile.m_sDoorsDirPath & "\" & "Main_Assemb.lua")
EgtLuaSetGlobIntVar("STU.Assembl", nAssembl)
Dim x = EgtLuaCallFunction("STU.Assembled")
EgtLuaResetGlobVar("STU")
End If
End Sub
#Region "EVENTS"
Sub m_ProjectScene_OnChangedSnapPointType(sender As Object, nSpType As EgtUILib.EgtInterface.SP, bForced As Boolean) Handles m_ProjectScene.OnChangedSnapPointType
Dim rfStatusBarVM As StatusBarVM = DirectCast(m_StatusBar.DataContext, StatusBarVM)
For SnapIndex = 0 To rfStatusBarVM.SnapPointTypeList.Count - 1
Dim TempSnapPoint As SPItem = rfStatusBarVM.SnapPointTypeList(SnapIndex)
If TempSnapPoint.SPValue = nSpType Then
rfStatusBarVM.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 rfStatusBarVM As StatusBarVM = DirectCast(m_StatusBar.DataContext, StatusBarVM)
Dim rfInstrumentPanel As InstrumentPanelVM = DirectCast(m_InstrumentPanel.DataContext, InstrumentPanelVM)
' restituisco una stringa vuota alla textblock che contiene la distanza
rfStatusBarVM.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