Files
omagoffice/SceneHost/SceneHostV.xaml.vb
T
Emmanuele Sassi 1f569d97ba OmagOFFICE :
- Migliorata gestione scelta lavorazioni.
- Aggiunto MessageBox per uscita senza chiave.
2017-05-09 15:06:07 +00:00

313 lines
12 KiB
VB.net

Imports System.Windows.Interop
Imports System.IO
Imports EgtUILib
Imports EgtWPFLib5
Public Class SceneHostV
' Scene controller
Private WithEvents m_Controller As New Controller
Friend ReadOnly Property Controller As Controller
Get
Return m_Controller
End Get
End Property
Sub New()
' This call is required by the designer.
InitializeComponent()
' Creo riferimento a questa classe in OmagOFFICEMap
OmagOFFICEMap.SetRefSceneHostV(Me)
' Inizializzazione Scena
PreInitializeScene()
If Not OmagOFFICEScene.Init() Then
EgtOutLog("Error in Project scene creation")
'SceneHost.Child = Nothing
' Box di avviso chiave mancante
MessageBox.Show(EgtMsg(MSG_MISSINGKEYWD + 2) & Environment.NewLine & EgtMsg(MSG_MISSINGKEYWD + 3), EgtMsg(MSG_MISSINGKEYWD + 1), MessageBoxButton.OK, MessageBoxImage.Error)
' Chiudo il programma
OmagOFFICEMap.refMainWindowVM.MainWindowM.Close()
Application.Current.Shutdown()
' Verifico abilitazione prodotto
ElseIf Not OmagOFFICEMap.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.OFFICE_BASE) Then
MessageBox.Show(EgtMsg(MSG_MISSINGKEYWD + 5), EgtMsg(MSG_MISSINGKEYWD + 1), MessageBoxButton.OK, MessageBoxImage.Error)
' Chiudo il programma
OmagOFFICEMap.refMainWindowVM.MainWindowM.Close()
Application.Current.Shutdown()
Else
PostInitializeScene()
' Imposto stato gestione mouse diretto della scena a nessuno
OmagOFFICEScene.SetStatusNull()
' Recupero e imposto handle finestra principale
Dim hMainWnd As IntPtr = New WindowInteropHelper(Application.Current.MainWindow).Handle
EgtSetMainWindowHandle(hMainWnd)
' inizializzo gestore lavorazioni
EgtInitMachMgr(OmagOFFICEMap.refMachinePanelVM.sMachinesRoot)
End If
End Sub
Private Sub PreInitializeScene()
' imposto colore di default
Dim DefColor As New Color3d(0, 0, 0)
GetMainPrivateProfileColor(S_GEOMDB, K_DEFAULTCOLOR, DefColor)
OmagOFFICEScene.SetDefaultMaterial(DefColor)
' imposto colori sfondo
Dim BackTopColor As New Color3d(192, 192, 192)
GetMainPrivateProfileColor(S_SCENE, K_BACKTOP, BackTopColor)
Dim BackBotColor As New Color3d(BackTopColor)
GetMainPrivateProfileColor(S_SCENE, K_BACKBOTTOM, BackBotColor)
OmagOFFICEScene.SetViewBackground(BackTopColor, BackBotColor)
' imposto colore di evidenziazione
Dim MarkColor As New Color3d(255, 255, 0)
GetMainPrivateProfileColor(S_SCENE, K_MARK, MarkColor)
OmagOFFICEScene.SetMarkMaterial(MarkColor)
' imposto colore per superfici selezionate
Dim SelSurfColor As New Color3d(255, 255, 192)
GetMainPrivateProfileColor(S_SCENE, K_SELSURF, SelSurfColor)
OmagOFFICEScene.SetSelSurfMaterial(SelSurfColor)
' imposto tipo e colore del rettangolo di zoom
Dim bOutline As Boolean = True
Dim ZwColor As New Color3d(0, 0, 0)
GetMainPrivateProfileZoomWin(S_SCENE, K_ZOOMWIN, bOutline, ZwColor)
OmagOFFICEScene.SetZoomWinAttribs(bOutline, ZwColor)
' imposto colore della linea di distanza
Dim DstLnColor As New Color3d(255, 0, 0)
GetMainPrivateProfileColor(S_SCENE, K_DISTLINE, DstLnColor)
OmagOFFICEScene.SetDistLineMaterial(DstLnColor)
' imposto parametri OpenGL
Dim nDriver As Integer = GetMainPrivateProfileInt(S_OPENGL, K_DRIVER, 3)
Dim b2Buff As Boolean = (GetMainPrivateProfileInt(S_OPENGL, K_DOUBLEBUFFER, 1) <> 0)
Dim nColorBits As Integer = GetMainPrivateProfileInt(S_OPENGL, K_COLORBITS, 32)
Dim nDepthBits As Integer = GetMainPrivateProfileInt(S_OPENGL, K_DEPTHBITS, 32)
OmagOFFICEScene.SetViewAttributes(nDriver, b2Buff, nColorBits, nDepthBits)
End Sub
Private Sub PostInitializeScene()
' Impostazioni Controller
m_Controller.SetScene(OmagOFFICEScene)
' imposto tipo coordinate
OmagOFFICEScene.SetGridCursorPos(True)
' modo di visualizzazione
Dim nShowMode As Integer = GetMainPrivateProfileInt(S_SCENE, K_SHOWMODE, SM.SHADING)
OmagOFFICEMap.refShowPanelVM.SetShowMode(DirectCast(nShowMode, SM))
' visualizzazione avanzata dei triangoli costituenti le superfici
Dim bShowTriaAdv As Boolean = (GetMainPrivateProfileInt(S_SCENE, K_SHOWTRIAADV, 1) <> 0)
EgtSetShowTriaAdv(bShowTriaAdv)
' tipo visualizzazione per Zmap
Dim nShowZmap As Integer = GetMainPrivateProfileInt(S_SCENE, K_SHOWZMAP, 1)
EgtSetShowZmap(DirectCast(nShowZmap, ZSM), False)
End Sub
#Region "ProjectManager"
Friend Sub NewProject()
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostV.OmagOFFICEScene.GetCtx())
Dim bOk As Boolean = m_Controller.NewProject()
' Eventuale reset VM
If bOk Then
VeinMatching.Clear()
End If
OmagOFFICEScene.SetStatusNull()
End Sub
Friend Sub OpenProject(sFilePath As String)
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostV.OmagOFFICEScene.GetCtx())
Dim bOk As Boolean = False
If String.IsNullOrEmpty(sFilePath) Then
' Recupero cartella dell'ultimo progetto aperto
Dim sDir As String = m_Controller.GetCurrFile()
If String.IsNullOrWhiteSpace(sDir) Then
GetMainPrivateProfileString(S_GENERAL, K_LASTPROJ, "", sDir)
End If
If Not String.IsNullOrWhiteSpace(sDir) Then
sDir = Path.GetDirectoryName(sDir)
End If
bOk = m_Controller.OpenProject(sDir)
Else
bOk = m_Controller.OpenProject(sFilePath, False)
End If
OmagOFFICEScene.SetStatusNull()
' Eventuale apertura file VM
Dim sFile As String = String.Empty
If bOk AndAlso EgtGetCurrFilePath(sFile) Then
Dim sVmFile As String = Path.ChangeExtension(sFile, ".VM.nge")
VeinMatching.Open(sVmFile)
End If
End Sub
Friend Sub SaveProject()
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostV.OmagOFFICEScene.GetCtx())
Dim nType As NGE = DirectCast(GetMainPrivateProfileInt(S_GEOMDB, K_SAVETYPE, NGE.CMPTEXT), NGE)
Dim sFile As String = m_Controller.GetCurrFile()
If Not String.IsNullOrWhiteSpace(sFile) Then
m_Controller.SaveProject(nType)
' Eventuale salvataggio VM
Dim sVmFile As String = Path.ChangeExtension(sFile, ".VM.nge")
VeinMatching.Save(sVmFile)
Else
GetMainPrivateProfileString(S_GENERAL, K_LASTPROJ, "", sFile)
If Not String.IsNullOrWhiteSpace(sFile) Then
sFile = Path.GetDirectoryName(sFile)
End If
sFile.TrimEnd("\"c)
sFile += "\New.nge"
m_Controller.SaveAsProject(sFile, nType)
End If
OmagOFFICEScene.SetStatusNull()
End Sub
Friend Sub SaveAsProject()
EgtSetCurrentContext(OmagOFFICEMap.refSceneHostV.OmagOFFICEScene.GetCtx())
Dim nType As NGE = DirectCast(GetMainPrivateProfileInt(S_GEOMDB, K_SAVETYPE, NGE.CMPTEXT), NGE)
Dim sFile As String = m_Controller.GetCurrFile()
If String.IsNullOrWhiteSpace(sFile) Then
GetMainPrivateProfileString(S_GENERAL, K_LASTPROJ, "", sFile)
If Not String.IsNullOrWhiteSpace(sFile) Then
sFile = Path.GetDirectoryName(sFile)
End If
sFile.TrimEnd("\"c)
sFile += "\New.nge"
End If
m_Controller.SaveAsProject(sFile, nType)
' Eventuale salvataggio VM
Dim sVmFile As String = Path.ChangeExtension(sFile, ".VM.nge")
VeinMatching.Save(sVmFile)
OmagOFFICEScene.SetStatusNull()
End Sub
#End Region ' ProjectManager
#Region "ShowMode"
Friend Sub ShowMode(nType As SM)
Select Case nType
Case SM.WIREFRAME
OmagOFFICEScene.WireFrame()
Case SM.HIDDENLINE
OmagOFFICEScene.HiddenLine()
Case SM.SHADING
OmagOFFICEScene.Shading()
End Select
End Sub
#End Region ' ShowMode
#Region "Zoom"
Friend Sub ZoomMode(nType As ZM)
Select Case nType
Case ZM.ALL
OmagOFFICEScene.ZoomAll()
Case ZM.IN_
OmagOFFICEScene.ZoomIn()
Case ZM.OUT
OmagOFFICEScene.ZoomOut()
End Select
End Sub
#End Region ' Zoom
#Region "ViewMode"
Friend Sub ViewMode(nType As VT)
Select Case nType
Case VT.TOP
OmagOFFICEScene.TopView()
Case VT.FRONT
OmagOFFICEScene.FrontView()
Case VT.RIGHT
OmagOFFICEScene.RightView()
Case VT.BACK
OmagOFFICEScene.BackView()
Case VT.LEFT
OmagOFFICEScene.LeftView()
Case VT.BOTTOM
OmagOFFICEScene.BottomView()
Case VT.ISO_SW
OmagOFFICEScene.IsoViewSW()
Case VT.ISO_SE
OmagOFFICEScene.IsoViewSE()
Case VT.ISO_NE
OmagOFFICEScene.IsoViewNE()
Case VT.ISO_NW
OmagOFFICEScene.IsoViewNW()
End Select
End Sub
#End Region ' ViewMode
#Region "GetDistance"
Friend Sub GetDistanceON()
OmagOFFICEScene.SetStatusGetDistance()
End Sub
Friend Sub GetDistanceOFF()
OmagOFFICEScene.ResetStatusGetDistance()
End Sub
#End Region
#Region "EVENTS"
Private Sub OnOpenProject(sender As Object, sFile As String, bOk As Boolean) Handles m_Controller.OnOpenProject
WriteMainPrivateProfileString(S_GENERAL, K_LASTPROJ, sFile)
End Sub
Private Sub OnSavedProject(ByVal sender As Object, ByVal sFile As String, ByVal bOk As Boolean) Handles m_Controller.OnSavedProject
WriteMainPrivateProfileString(S_GENERAL, K_LASTPROJ, sFile)
CsvM.SaveCsvPartList()
End Sub
Private Sub OnMouseDownScene(sender As Object, e As Windows.Forms.MouseEventArgs) Handles OmagOFFICEScene.OnMouseDownScene
' Si può selezionare solo con il tasto sinistro e se stato NULL
If e.Button <> Windows.Forms.MouseButtons.Left Or Not OmagOFFICEScene.IsStatusNull() Then
Return
End If
' Chiamo l'opportuno gestore
Select Case OmagOFFICEMap.refOptionPanelVM.SelItem
Case OptionPanelVM.Tabs.RAWPART
OmagOFFICEMap.refRawPartTabVM.OnMouseDownScene(sender, e)
Case OptionPanelVM.Tabs.NESTING
OmagOFFICEMap.refNestingTabVM.OnMouseDownScene(sender, e)
Case OptionPanelVM.Tabs.MACHINING
OmagOFFICEMap.refMachiningTabVM.OnMouseDownScene(sender, e)
Case OptionPanelVM.Tabs.SIMUL
End Select
End Sub
Private Sub OnMouseMoveScene(sender As Object, e As Windows.Forms.MouseEventArgs) Handles OmagOFFICEScene.OnMouseMoveScene
' Chiamo l'opportuno gestore
Select Case OmagOFFICEMap.refOptionPanelVM.SelItem
Case OptionPanelVM.Tabs.RAWPART
OmagOFFICEMap.refRawPartTabVM.OnMouseMoveScene(sender, e)
Case OptionPanelVM.Tabs.NESTING
OmagOFFICEMap.refNestingTabVM.OnMouseMoveScene(sender, e)
Case OptionPanelVM.Tabs.MACHINING
Case OptionPanelVM.Tabs.SIMUL
End Select
End Sub
Private Sub OnMouseUpScene(sender As Object, e As Windows.Forms.MouseEventArgs) Handles OmagOFFICEScene.OnMouseUpScene
' Chiamo l'opportuno gestore
Select Case OmagOFFICEMap.refOptionPanelVM.SelItem
Case OptionPanelVM.Tabs.RAWPART
OmagOFFICEMap.refRawPartTabVM.OnMouseUpScene(sender, e)
Case OptionPanelVM.Tabs.NESTING
OmagOFFICEMap.refNestingTabVM.OnMouseUpScene(sender, e)
Case OptionPanelVM.Tabs.MACHINING
Case OptionPanelVM.Tabs.SIMUL
End Select
End Sub
Private Sub OnCursorPos(ByVal sender As Object, ByVal sCursorPos As String) Handles OmagOFFICEScene.OnCursorPos
OmagOFFICEMap.refStatusBarVM.SetCurrPos(sCursorPos)
End Sub
Private Sub OnShowDistance(ByVal sender As Object, ByVal sDistance As String) Handles OmagOFFICEScene.OnShowDistance
OmagOFFICEMap.refStatusBarVM.SetOutputMessage(sDistance)
End Sub
#End Region ' EVENTS
End Class