385 lines
17 KiB
VB.net
385 lines
17 KiB
VB.net
Imports EgtUILib
|
|
Imports EgtWPFLib5
|
|
Imports System.IO
|
|
|
|
Public Class MySceneHostVM
|
|
Inherits SceneHostVM
|
|
|
|
#Region "FIELDS & PROPERTIES"
|
|
|
|
' Flag per distinguere tra Save a SaveAs
|
|
Private m_bIsSaveAs As Boolean = False
|
|
|
|
#End Region ' Fields & Properties
|
|
|
|
#Region "CONSTRUCTOR"
|
|
|
|
Sub New()
|
|
MyBase.New()
|
|
AddHandler MainController.OnNewProject, AddressOf OnNewProject
|
|
AddHandler MainController.OnOpenProject, AddressOf OnOpenProject
|
|
AddHandler MainController.OnSavingProject, AddressOf OnSavingProject
|
|
AddHandler MainController.OnSavedProject, AddressOf OnSavedProject
|
|
AddHandler MainController.OnInsertedProject, AddressOf OnInsertedProject
|
|
AddHandler MainController.OnImportingProject, AddressOf OnImportingProject
|
|
AddHandler MainController.OnImportedProject, AddressOf OnImportedProject
|
|
|
|
AssLogM.InitAssLog()
|
|
|
|
Map.SetRefSceneHostVM(Me)
|
|
End Sub
|
|
|
|
#End Region ' Constructor
|
|
|
|
#Region "METHODS"
|
|
|
|
Overrides Sub InitScene()
|
|
' Inizializzazione Scena
|
|
PreInitializeScene()
|
|
' Se tutto bene
|
|
'If MainScene.Init() And Map.refMainWindowVM.MainWindowM.GetKeyOption(KEY_OPT.BASE) Then
|
|
If MainScene.Init() Then
|
|
PostInitializeScene()
|
|
' modo di visualizzazione
|
|
EgtSetView(VT.ISO_SE)
|
|
' Imposto stato gestione mouse diretto della scena a nessuno
|
|
MainScene.SetStatusNull()
|
|
'MainScene.SetStatusAnalyze() ' debug
|
|
EgtSetCurrentContext(MainScene.GetCtx())
|
|
Return
|
|
End If
|
|
' Problemi
|
|
' Se manca la chiave
|
|
If Map.refMainWindowVM.MainWindowM.nKeyLevel = -1 Or Map.refMainWindowVM.MainWindowM.nKeyLevel = -2 Then
|
|
EgtOutLog("Missing Dongle")
|
|
' Box di avviso chiave mancante : "Chiave non presente. \n Inserirla e riavviare il programma." "Errore"
|
|
Dim sText As String = EgtMsg(10102) & vbCrLf & EgtMsg(10103)
|
|
Dim sTitle As String = EgtMsg(10101)
|
|
MessageBox.Show(sText, sTitle, MessageBoxButton.OK, MessageBoxImage.Error)
|
|
' Altrimenti manca la licenza
|
|
Else
|
|
EgtOutLog("Problems with Licence")
|
|
' Box di avviso licenza con problemi : "Programma senza licenza. \n Caricala e riavvia il programma." "Errore"
|
|
Dim sText As String = EgtMsg(10105) & vbCrLf & EgtMsg(10106)
|
|
Dim sTitle As String = EgtMsg(10101)
|
|
If MessageBox.Show(sText, sTitle, MessageBoxButton.OKCancel, MessageBoxImage.Error) = MessageBoxResult.OK Then
|
|
' Apro dialogo per richiesta file licenza
|
|
Dim LicDlg As New EgtManageFileDialogV(Application.Current.MainWindow, New EgtManageFileDialogVM()) With {
|
|
.Title = EgtMsg(110026),
|
|
.Filter = "Licences (.lic)|*.lic",
|
|
.CheckFileExists = True,
|
|
.ValidateNames = True
|
|
}
|
|
If LicDlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
|
|
' Recupero il direttorio del file
|
|
'Dim sDir As String = Path.GetDirectoryName(LicDlg.FileName)
|
|
Dim sDir As String = LicDlg.FileName
|
|
' Se il file non è già nel direttorio di configurazione lo copio
|
|
If Not String.Equals(Path.GetFullPath(sDir), Path.GetFullPath(Map.refMainWindowVM.MainWindowM.sConfigDir), StringComparison.OrdinalIgnoreCase) Then
|
|
Try
|
|
File.Copy(LicDlg.FileName, Path.Combine(Map.refMainWindowVM.MainWindowM.sConfigDir, LicDlg.SafeFileName), True)
|
|
Catch ex As Exception
|
|
End Try
|
|
End If
|
|
' Imposto il nuovo file di licenza nell'Ini
|
|
WriteMainPrivateProfileString(S_GENERAL, K_LICENCE, LicDlg.SafeFileName)
|
|
End If
|
|
End If
|
|
End If
|
|
' Chiudo il programma
|
|
End
|
|
End Sub
|
|
|
|
Private Sub PreInitializeScene()
|
|
' imposto colore di default
|
|
Dim DefColor As New Color3d(0, 0, 0)
|
|
GetMainPrivateProfileColor(S_GEOMDB, K_DEFAULTCOLOR, DefColor)
|
|
MainScene.SetDefaultMaterial(DefColor)
|
|
' imposto colori sfondo
|
|
Dim BackTopColor As New Color3d(0, 123, 167)
|
|
GetMainPrivateProfileColor(S_SCENE, K_BACKTOP, BackTopColor)
|
|
Dim BackBotColor As New Color3d(BackTopColor)
|
|
GetMainPrivateProfileColor(S_SCENE, K_BACKBOTTOM, BackBotColor)
|
|
MainScene.SetViewBackground(BackTopColor, BackBotColor)
|
|
' imposto spessore linee
|
|
Dim nLineWidth As Integer = 1
|
|
nLineWidth = GetMainPrivateProfileInt(S_SCENE, K_LINEWIDTH, nLineWidth)
|
|
MainScene.SetLineWidth(nLineWidth)
|
|
' imposto colore di evidenziazione
|
|
Dim MarkColor As New Color3d(255, 255, 0)
|
|
GetMainPrivateProfileColor(S_SCENE, K_MARK, MarkColor)
|
|
MainScene.SetMarkMaterial(MarkColor)
|
|
' imposto colore per superfici selezionate
|
|
Dim SelSurfColor As New Color3d(255, 255, 192)
|
|
GetMainPrivateProfileColor(S_SCENE, K_SELSURF, SelSurfColor)
|
|
MainScene.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)
|
|
MainScene.SetZoomWinAttribs(bOutline, ZwColor)
|
|
' imposto colore della linea di distanza
|
|
Dim DstLnColor As New Color3d(255, 0, 0)
|
|
GetMainPrivateProfileColor(S_SCENE, K_DISTLINE, DstLnColor)
|
|
MainScene.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)
|
|
MainScene.SetViewAttributes(nDriver, b2Buff, nColorBits, nDepthBits)
|
|
End Sub
|
|
|
|
Private Sub PostInitializeScene()
|
|
' Impostazioni Controller
|
|
MainController.SetScene(MainScene)
|
|
MainController.SetSurfTmTolerance(0.05)
|
|
MainController.SetUseCustomColors(True, S_SCENE, K_CUSTOMCOLORS)
|
|
' imposto unità di misura per interfaccia utente
|
|
Dim bMmUnits As Boolean = GetMainPrivateProfileInt(S_SCENE, K_MMUNITS, 1) <> 0
|
|
EgtSetUiUnits(bMmUnits)
|
|
'Map.refMyStatusBarVM.SetMeasureUnit(nMeasureUnit <> 0)
|
|
' imposto visualizzazione riferimento globale
|
|
EgtSetGlobFrameShow(True)
|
|
' imposto i dati della griglia
|
|
Dim bGridVisibility As Boolean = (GetMainPrivateProfileInt(S_GRID, K_SHOWGRID, 1) <> 0)
|
|
Dim dSnapStepMm As Double = GetMainPrivateProfileDouble(S_GRID, K_SNAPSTEP, 10)
|
|
Dim dSnapStepInch As Double = GetMainPrivateProfileDouble(S_GRID, K_SNAPSTEPINCH, 10)
|
|
Dim nMinLineSStep As Integer = GetMainPrivateProfileInt(S_GRID, K_MINLINESSTEP, 1)
|
|
Dim nMajLineSStep As Integer = GetMainPrivateProfileInt(S_GRID, K_MAJLINESSTEP, 10)
|
|
Dim nExtSStep As Integer = GetMainPrivateProfileInt(S_GRID, K_EXTSSTEP, 50)
|
|
Dim MinLnColor As Color3d = New Color3d(160, 160, 160)
|
|
GetMainPrivateProfileColor(S_GRID, K_MINLNCOLOR, MinLnColor)
|
|
Dim MajLnColor As Color3d = New Color3d(160, 160, 160)
|
|
GetMainPrivateProfileColor(S_GRID, K_MAJLNCOLOR, MajLnColor)
|
|
EgtSetGridFrame(Frame3d.GLOB)
|
|
If bMmUnits Then
|
|
EgtSetGridGeo(dSnapStepMm, nMinLineSStep, nMajLineSStep, nExtSStep)
|
|
Else
|
|
EgtSetGridGeo(dSnapStepInch, nMinLineSStep, nMajLineSStep, nExtSStep)
|
|
End If
|
|
EgtSetGridColor(MinLnColor, MajLnColor)
|
|
EgtSetGridShow(bGridVisibility, bGridVisibility)
|
|
' imposto tipo coordinate
|
|
MainScene.SetGridCursorPos(True)
|
|
' visualizzazione avanzata dei triangoli costituenti le superfici
|
|
Dim bShowTriaAdv As Boolean = (GetMainPrivateProfileInt(S_SCENE, K_SHOWTRIAADV, 1) <> 0)
|
|
EgtSetShowTriaAdv(bShowTriaAdv)
|
|
' visualizzazione direzione curve
|
|
Dim bShowCurveDirection As Boolean = (GetMainPrivateProfileInt(S_SCENE, K_CURVEDIR, 0) <> 0)
|
|
EgtSetShowCurveDirection(bShowCurveDirection)
|
|
' tipo visualizzazione per Zmap
|
|
Dim nShowZmap As Integer = GetMainPrivateProfileInt(S_SCENE, K_SHOWZMAP, 1)
|
|
EgtSetShowZmap(DirectCast(nShowZmap, ZSM), False)
|
|
' dimensione lineare max in pixel delle textures
|
|
Dim nTxrMaxLinPix As Integer = GetMainPrivateProfileInt(S_SCENE, K_TEXMAXLINPIX, 4096)
|
|
EgtSetTextureMaxLinPixels(nTxrMaxLinPix)
|
|
' tipo snap point
|
|
MainScene.SetSnapPointType(SP.PT_GRID)
|
|
' nascondo input box
|
|
'Map.refFreeContourInputVM.ResetInputBox()
|
|
End Sub
|
|
|
|
Public Overrides Function OpenProject(sFilePath As String) As Boolean
|
|
EgtSetCurrentContext(MainScene.GetCtx())
|
|
Dim bOk As Boolean = False
|
|
If String.IsNullOrEmpty(sFilePath) Then
|
|
' Recupero cartella dell'ultimo progetto aperto
|
|
Dim sDir As String = MainController.GetCurrFile()
|
|
If String.IsNullOrWhiteSpace(sDir) Then
|
|
GetMainPrivateProfileString(S_MRUFILES, K_FILE & 1, "", sDir)
|
|
End If
|
|
If Not String.IsNullOrWhiteSpace(sDir) Then
|
|
sDir = Path.GetDirectoryName(sDir)
|
|
End If
|
|
Dim OpenFileDialog As New EgtManageFileDialogV(Application.Current.MainWindow, New EgtManageFileDialogVM()) With {
|
|
.Title = EgtMsg(110015),
|
|
.Filter = "Icarus project(*.icrs)|*.icrs" &
|
|
"|New geometry EgalTech(*.nge)|*.nge",
|
|
.FilterIndex = 1,
|
|
.InitialDirectory = sDir
|
|
}
|
|
If Not OpenFileDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then Return False
|
|
sFilePath = OpenFileDialog.FileName
|
|
End If
|
|
bOk = MainController.OpenProject(sFilePath, False)
|
|
' Imposto stato gestione mouse diretto della scena a nessuno
|
|
MainScene.SetStatusNull()
|
|
Return bOk
|
|
End Function
|
|
|
|
Public Overrides Function SaveProject() As Boolean
|
|
' Se nome progetto non definito o con estensione non valida lo chiedo
|
|
Dim sCurrFile As String = ""
|
|
EgtGetCurrFilePath(sCurrFile)
|
|
Dim bOk As Boolean = False
|
|
If String.IsNullOrWhiteSpace(sCurrFile) Or EgtGetFileType(sCurrFile) <> FT.NGE Then
|
|
bOk = SaveAsProject()
|
|
Else
|
|
If Path.GetExtension(sCurrFile) = ".nge" Then
|
|
EgtSetCurrFilePath(sCurrFile)
|
|
Else
|
|
EgtSetCurrFilePath(sCurrFile)
|
|
End If
|
|
' Salvataggio standard
|
|
bOk = MainController.SaveProject()
|
|
End If
|
|
' Imposto stato gestione mouse diretto della scena a nessuno
|
|
MainScene.SetStatusNull()
|
|
Return bOk
|
|
End Function
|
|
|
|
Public Overrides Function SaveAsProject() As Boolean
|
|
m_bIsSaveAs = True
|
|
Dim sFile As String = ""
|
|
Dim sFileName As String = ""
|
|
Dim sFilter As String() = Nothing
|
|
EgtGetCurrFilePath(sFile)
|
|
Dim bOk As Boolean = False
|
|
' Se nome vuoto, assegno "New"
|
|
If String.IsNullOrWhiteSpace(sFile) Then sFile = "New.vme"
|
|
' Eventuale sistemazione estensione
|
|
sFile = IO.Path.ChangeExtension(sFile, "vme")
|
|
Dim sDir As String = MainController.GetCurrFile()
|
|
If String.IsNullOrWhiteSpace(sDir) Then
|
|
GetMainPrivateProfileString(S_MRUFILES, K_FILE & 1, "", sDir)
|
|
End If
|
|
If Not String.IsNullOrWhiteSpace(sDir) Then
|
|
sDir = Path.GetDirectoryName(sDir)
|
|
End If
|
|
Dim sFilterIndex As String = String.Empty
|
|
If String.IsNullOrWhiteSpace(sFilterIndex) Then
|
|
GetMainPrivateProfileString(S_GENERAL, "LastExstensionSave", "1", sFilterIndex)
|
|
End If
|
|
Dim nFilterIndex As Integer = 1
|
|
If IsNumeric(sFilterIndex) Then
|
|
nFilterIndex = CInt(sFilterIndex)
|
|
End If
|
|
' Assegnazione nome file con dialogo
|
|
Dim SaveFileDialog As New EgtManageFileDialogV(Application.Current.MainWindow, New EgtManageFileDialogVM()) With {
|
|
.Title = EgtMsg(110013),
|
|
.Filter = "New geometry EgalTech(*.nge)|*.nge" &
|
|
"|vme files (*.vme)|*.vme",
|
|
.FilterIndex = nFilterIndex,
|
|
.FileName = sFile,
|
|
.InitialDirectory = "C:\EgtData\EgtStone3D\Temp",
|
|
.ValidateNames = False,
|
|
.OverwritePrompt = True,
|
|
.Mode = 1
|
|
}
|
|
If SaveFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
|
|
sFilter = SaveFileDialog.Filter.Split("|"c)
|
|
If Path.GetExtension(SaveFileDialog.SafeFileName).Equals(String.Empty) Then
|
|
sFileName = SaveFileDialog.InitialDirectory & "\" & SaveFileDialog.SafeFileName & sFilter(nFilterIndex + 1).Trim("*"c)
|
|
Else
|
|
sFileName = SaveFileDialog.InitialDirectory & "\" & SaveFileDialog.SafeFileName
|
|
End If
|
|
EgtSetCurrFilePath(sFileName)
|
|
' Salvataggio standard
|
|
bOk = MainController.SaveProject()
|
|
End If
|
|
WriteMainPrivateProfileString(S_GENERAL, "LastExstensionSave", SaveFileDialog.FilterIndex.ToString())
|
|
m_bIsSaveAs = False
|
|
' Imposto stato gestione mouse diretto della scena a nessuno
|
|
MainScene.SetStatusNull()
|
|
Return bOk
|
|
End Function
|
|
|
|
#End Region ' Methods
|
|
|
|
#Region "EVENTS"
|
|
|
|
Private Sub OnNewProject(sender As Object, bOk As Boolean)
|
|
EgtErase(EgtGetFirstPart())
|
|
If Not bOk Then
|
|
EgtStone3D.EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(10002), EgtMsg(10001), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
End If
|
|
EgtZoom(ZM.ALL)
|
|
MainScene.SetStatusNull()
|
|
End Sub
|
|
|
|
Private Sub OnOpenProject(sender As Object, sFile As String, bOk As Boolean)
|
|
EgtZoom(ZM.ALL)
|
|
WriteMainPrivateProfileString(S_GENERAL, K_LASTNGEDIR, Path.GetDirectoryName(sFile))
|
|
If bOk Then
|
|
Map.refTopPanelVM.MruFiles.Add(sFile)
|
|
Else
|
|
Map.refTopPanelVM.MruFiles.Remove(sFile)
|
|
Dim sMsg As String
|
|
If My.Computer.FileSystem.FileExists(sFile) Then
|
|
sMsg = EgtMsg(10003) & " '" & sFile & "'" 'Error opening file
|
|
Else
|
|
sMsg = EgtMsg(10009) & " '" & sFile & "'" 'Missing file
|
|
End If
|
|
EgtStone3D.EgtMessageBoxV.Show(Application.Current.MainWindow, sMsg, EgtMsg(10001), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub OnSavingProject(ByVal sender As Object, sFile As String)
|
|
' Se in SaveAs, aggiorno nome CN da generare
|
|
If m_bIsSaveAs Then
|
|
Dim nTabPartId As Integer = EgtGetFirstNameInGroup(GDB_ID.ROOT, TABLE)
|
|
If nTabPartId <> GDB_ID.NULL Then
|
|
EgtRemoveInfo(nTabPartId, KEY_ISOFILE_PATH)
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub OnSavedProject(ByVal sender As Object, ByVal sFile As String, ByVal bOk As Boolean)
|
|
WriteMainPrivateProfileString(S_GENERAL, K_LASTNGEDIR, Path.GetDirectoryName(sFile))
|
|
If bOk Then
|
|
Map.refTopPanelVM.MruFiles.Add(sFile)
|
|
Else
|
|
Map.refTopPanelVM.MruFiles.Remove(sFile)
|
|
Dim sMsg As String = EgtMsg(10004) & " '" & sFile & "'" 'Error saving file
|
|
EgtStone3D.EgtMessageBoxV.Show(Application.Current.MainWindow, sMsg, EgtMsg(10001), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub OnInsertedProject(ByVal sender As Object, ByVal sFile As String, ByVal bOk As Boolean)
|
|
' Segnalo eventuale errore
|
|
If Not bOk Then
|
|
Dim sMsg As String = EgtMsg(10006) & " '" & sFile & "'" 'Error importing file
|
|
EgtStone3D.EgtMessageBoxV.Show(Application.Current.MainWindow, sMsg, EgtMsg(10001), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
End If
|
|
Map.refTopPanelVM.MruImportFiles.Add(sFile)
|
|
EgtSetInfo(EgtGetLastPart(), FILE_PATH, sFile)
|
|
EgtDraw()
|
|
MainScene.SetStatusNull()
|
|
End Sub
|
|
|
|
Private Sub OnImportingProject(sender As Object, nType As Integer, ByRef nFlag As Integer)
|
|
If nType <> FT.NULL Then
|
|
If nType = FT.CNC Then
|
|
nFlag = GetMainPrivateProfileInt(S_IMPORT, K_CNCFLAG, EIC_FL.NONE)
|
|
Else
|
|
nFlag = 0
|
|
End If
|
|
' Abilito progress e bottone stop
|
|
'Map.refMyStatusBarVM.StartLoading("", True)
|
|
Else
|
|
EgtStone3D.EgtMessageBoxV.Show(Application.Current.MainWindow, EgtMsg(10005), EgtMsg(10001), MessageBoxButton.OK, MessageBoxImage.Error) ' File type unknown - Error
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub OnImportedProject(ByVal sender As Object, ByVal sFile As String, ByVal bOk As Boolean)
|
|
EgtZoom(ZM.ALL)
|
|
' Disabilito progress e bottone stop
|
|
'Map.refMyStatusBarVM.EndLoading("")
|
|
' Salvo path
|
|
WriteMainPrivateProfileString(S_GENERAL, K_LASTIMPDIR, Path.GetDirectoryName(sFile))
|
|
' Segnalo eventuale errore
|
|
If Not bOk Then
|
|
Dim sMsg As String = EgtMsg(10006) & " '" & sFile & "'" 'Error importing file
|
|
EgtStone3D.EgtMessageBoxV.Show(Application.Current.MainWindow, sMsg, EgtMsg(10001), MessageBoxButton.OK, MessageBoxImage.Error) ' Error
|
|
ElseIf Path.GetExtension(sFile) <> ".cnc" Then
|
|
' creo oggetto pezzo in lista
|
|
'Map.refProjectVM.
|
|
End If
|
|
MainScene.SetStatusNull()
|
|
End Sub
|
|
|
|
#End Region ' Events
|
|
|
|
End Class
|