390 lines
15 KiB
VB.net
390 lines
15 KiB
VB.net
Imports System.IO
|
|
Imports EgtUILib
|
|
Imports EgtWPFLib5
|
|
|
|
Public Class SceneHostVM
|
|
Inherits VMBase
|
|
|
|
#Region "FIELDS & PROPERTIES"
|
|
|
|
Private m_MainScene As Scene
|
|
Public ReadOnly Property MainScene As Scene
|
|
Get
|
|
Return m_MainScene
|
|
End Get
|
|
End Property
|
|
|
|
' Scene controller
|
|
Private WithEvents m_MainController As New Controller
|
|
Public ReadOnly Property MainController As Controller
|
|
Get
|
|
Return m_MainController
|
|
End Get
|
|
End Property
|
|
|
|
#End Region ' FIELDS & PROPERTIES
|
|
|
|
#Region "CONSTRUCTOR"
|
|
|
|
Sub New()
|
|
' Creo riferimento a questa classe in LibMap
|
|
LibMap.SetRefSceneHostVM(Me)
|
|
End Sub
|
|
|
|
#End Region ' CONSTRUCTOR
|
|
|
|
#Region "METHODS"
|
|
|
|
Public Sub SetMainScene(ViewMainScene As Scene)
|
|
m_MainScene = ViewMainScene
|
|
InitScene()
|
|
End Sub
|
|
|
|
Public Overridable Sub InitScene()
|
|
End Sub
|
|
|
|
Public Overridable Sub InitSceneEvents()
|
|
End Sub
|
|
|
|
#End Region ' METHODS
|
|
|
|
#Region "ProjectManager"
|
|
|
|
Public Overridable Function NewProject() As Boolean
|
|
EgtSetCurrentContext(MainScene.GetCtx())
|
|
Return m_MainController.NewProject()
|
|
End Function
|
|
|
|
Public Overridable Function OpenProject(sFilePath As String) As Boolean
|
|
EgtSetCurrentContext(MainScene.GetCtx())
|
|
If String.IsNullOrEmpty(sFilePath) Then
|
|
' Recupero cartella dell'ultimo progetto aperto
|
|
Dim sDir As String = m_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
|
|
Return m_MainController.OpenProject(sDir)
|
|
Else
|
|
Return m_MainController.OpenProject(sFilePath, False)
|
|
End If
|
|
End Function
|
|
|
|
Public Overridable Function SaveProject() As Boolean
|
|
EgtSetCurrentContext(MainScene.GetCtx())
|
|
Dim nType As NGE = DirectCast(GetMainPrivateProfileInt(S_GEOMDB, K_SAVETYPE, NGE.CMPTEXT), NGE)
|
|
Dim sFile As String = m_MainController.GetCurrFile()
|
|
If Not String.IsNullOrWhiteSpace(sFile) Then
|
|
Return m_MainController.SaveProject(nType)
|
|
Else
|
|
Return SaveAsProject()
|
|
End If
|
|
End Function
|
|
|
|
Public Overridable Function SaveAsProject() As Boolean
|
|
EgtSetCurrentContext(MainScene.GetCtx())
|
|
Dim nType As NGE = DirectCast(GetMainPrivateProfileInt(S_GEOMDB, K_SAVETYPE, NGE.CMPTEXT), NGE)
|
|
Dim sFile As String = m_MainController.GetCurrFile()
|
|
If String.IsNullOrWhiteSpace(sFile) Then
|
|
GetMainPrivateProfileString(S_MRUFILES, K_FILE & "1", "", sFile)
|
|
If Not String.IsNullOrWhiteSpace(sFile) Then
|
|
sFile = Path.GetDirectoryName(sFile) & "\"
|
|
End If
|
|
'sFile.TrimEnd("\"c)
|
|
'sFile += "\New" & m_nInstance.ToString() & ".nge" 'KK?
|
|
End If
|
|
|
|
Return m_MainController.SaveAsProject(sFile, nType)
|
|
End Function
|
|
|
|
Public Overridable Function InsertProject() As Boolean
|
|
Dim sDir As String = String.Empty
|
|
GetMainPrivateProfileString(S_MRUFILES, K_FILE & "1", "", sDir)
|
|
If Not String.IsNullOrWhiteSpace(sDir) Then
|
|
sDir = Path.GetDirectoryName(sDir)
|
|
End If
|
|
sDir.TrimEnd("\"c)
|
|
Return m_MainController.InsertProject(sDir)
|
|
End Function
|
|
|
|
Public Overridable Function ImportProject() As Boolean
|
|
Dim sDir As String = String.Empty
|
|
GetMainPrivateProfileString(S_MRUIMPORT, K_FILE & "1", "", sDir)
|
|
If Not String.IsNullOrWhiteSpace(sDir) Then
|
|
sDir = Path.GetDirectoryName(sDir)
|
|
End If
|
|
sDir.TrimEnd("\"c)
|
|
Return m_MainController.ImportProject(sDir)
|
|
End Function
|
|
|
|
Public Overridable Function ExportProject() As Boolean
|
|
EgtSetCurrentContext(MainScene.GetCtx())
|
|
Return m_MainController.ExportProject(Path.ChangeExtension(m_MainController.GetCurrFile(), "dxf"))
|
|
End Function
|
|
|
|
Public Overridable Function ExecScript(sFilePath As String) As Boolean
|
|
If String.IsNullOrEmpty(sFilePath) Then
|
|
Dim sDir As String = String.Empty
|
|
GetMainPrivateProfileString(S_MRUSCRIPTS, K_FILE & "1", "", sDir)
|
|
If Not String.IsNullOrWhiteSpace(sDir) Then
|
|
sDir = Path.GetDirectoryName(sDir)
|
|
End If
|
|
sDir.TrimEnd("\"c)
|
|
Return m_MainController.Exec(sDir)
|
|
Else
|
|
Return m_MainController.Exec(sFilePath, False)
|
|
End If
|
|
End Function
|
|
|
|
#End Region ' ProjectManager
|
|
|
|
#Region "ShowMode"
|
|
|
|
Public Sub ShowMode(nType As SM)
|
|
Select Case nType
|
|
Case SM.WIREFRAME
|
|
MainScene.WireFrame()
|
|
Case SM.HIDDENLINE
|
|
MainScene.HiddenLine()
|
|
Case SM.SHADING
|
|
MainScene.Shading()
|
|
End Select
|
|
End Sub
|
|
|
|
#End Region ' ShowMode
|
|
|
|
#Region "Zoom"
|
|
|
|
Public Sub ZoomMode(nType As ZM)
|
|
Select Case nType
|
|
Case ZM.ALL
|
|
MainScene.ZoomAll()
|
|
Case ZM.IN_
|
|
MainScene.ZoomIn()
|
|
Case ZM.OUT
|
|
MainScene.ZoomOut()
|
|
End Select
|
|
End Sub
|
|
|
|
#End Region ' Zoom
|
|
|
|
#Region "ViewMode"
|
|
|
|
Public Sub ViewMode(nType As VT)
|
|
Select Case nType
|
|
Case VT.TOP
|
|
MainScene.TopView()
|
|
Case VT.FRONT
|
|
MainScene.FrontView()
|
|
Case VT.RIGHT
|
|
MainScene.RightView()
|
|
Case VT.BACK
|
|
MainScene.BackView()
|
|
Case VT.LEFT
|
|
MainScene.LeftView()
|
|
Case VT.BOTTOM
|
|
MainScene.BottomView()
|
|
Case VT.ISO_SW
|
|
MainScene.IsoViewSW()
|
|
Case VT.ISO_SE
|
|
MainScene.IsoViewSE()
|
|
Case VT.ISO_NE
|
|
MainScene.IsoViewNE()
|
|
Case VT.ISO_NW
|
|
MainScene.IsoViewNW()
|
|
End Select
|
|
End Sub
|
|
|
|
#End Region ' ViewMode
|
|
|
|
#Region "GetDistance"
|
|
|
|
Public Sub GetDistanceON()
|
|
MainScene.SetStatusGetDistance()
|
|
End Sub
|
|
|
|
Public Sub GetDistanceOFF()
|
|
MainScene.ResetStatusGetDistance()
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
'#Region "EVENTS"
|
|
|
|
' Private Sub OnNewProject(sender As Object, bOk As Boolean) Handles m_Controller.OnNewProject
|
|
' OmagOFFICEMap.refMainWindowVM.Title = " New - OmagOFFICE"
|
|
' End Sub
|
|
|
|
' Private Sub OnOpenProject(sender As Object, sFile As String, bOk As Boolean) Handles m_Controller.OnOpenProject
|
|
' OmagOFFICEMap.refMainWindowVM.Title = sFile & " - OmagOFFICE"
|
|
' WriteMainPrivateProfileString(S_GENERAL, K_LASTPROJ, sFile)
|
|
' If bOk Then
|
|
' OmagOFFICEMap.refTopCommandBarVM.m_MruFiles.Add(sFile)
|
|
' Else
|
|
' OmagOFFICEMap.refTopCommandBarVM.m_MruFiles.Remove(sFile)
|
|
' Dim sMsg As String = EgtMsg(10003) & " '" & sFile & "'" 'Error opening file
|
|
' MessageBox.Show(sMsg, EgtMsg(10001), MessageBoxButton.OK, MessageBoxImage.Error) 'Error
|
|
' End If
|
|
' End Sub
|
|
|
|
' Private Sub OnSavingProject(ByVal sender As Object, sFile As String) Handles m_Controller.OnSavingProject
|
|
' ' Recupero tutti i file di texture associabili ai gruppi di lavoro del progetto
|
|
' Dim sDirToSearch As String = Path.GetDirectoryName(sFile)
|
|
' Dim sFileToSearch As String = Path.GetFileNameWithoutExtension(sFile) & "." & PHOTO_NAME & "*"
|
|
' Dim vsTxrFile As New List(Of String)
|
|
' For Each sTxrFile In My.Computer.FileSystem.GetFiles(sDirToSearch, FileIO.SearchOption.SearchTopLevelOnly, sFileToSearch)
|
|
' vsTxrFile.Add(sTxrFile)
|
|
' Next
|
|
' ' Rinomino path di eventuali fotografie
|
|
' Dim nPhotoId As Integer = EgtGetFirstInGroup(EgtGetFirstNameInGroup(GDB_ID.ROOT, PHOTO_GRP))
|
|
' While nPhotoId <> GDB_ID.NULL
|
|
' ' Path originale
|
|
' Dim sPhoto As String = String.Empty
|
|
' If EgtGetPhotoPath(nPhotoId, sPhoto) Then
|
|
' ' Nome della foto
|
|
' Dim sName As String = String.Empty
|
|
' EgtGetName(nPhotoId, sName)
|
|
' ' Nuova path
|
|
' Dim sNewPhoto As String = Path.GetDirectoryName(sFile) & "\" &
|
|
' Path.GetFileNameWithoutExtension(sFile) & "." & sName &
|
|
' Path.GetExtension(sPhoto)
|
|
' ' Se diverse, eseguo copia
|
|
' If String.Compare(sPhoto, sNewPhoto, True) <> 0 Then
|
|
' Try
|
|
' ' Eseguo copia
|
|
' File.Copy(sPhoto, sNewPhoto, True)
|
|
' ' Notifico a foto il cambio di path
|
|
' EgtChangePhotoPath(nPhotoId, sNewPhoto)
|
|
' ' Eventuale notifica a VeinMatching del cambio di path
|
|
' VeinMatching.ChangePhotoPath(sPhoto, sNewPhoto)
|
|
' Catch ex As Exception
|
|
' End Try
|
|
' End If
|
|
' ' Tolgo da lista file texture associabili, se presente
|
|
' vsTxrFile.Remove(sNewPhoto)
|
|
' End If
|
|
' ' passo alla successiva
|
|
' nPhotoId = EgtGetNext(nPhotoId)
|
|
' End While
|
|
' ' Se rimasti file associabili, li cancello
|
|
' For Each sTxrFile In vsTxrFile
|
|
' Try
|
|
' My.Computer.FileSystem.DeleteFile(sTxrFile)
|
|
' Catch
|
|
' End Try
|
|
' Next
|
|
' End Sub
|
|
|
|
' Private Sub OnSavedProject(ByVal sender As Object, ByVal sFile As String, ByVal bOk As Boolean) Handles m_Controller.OnSavedProject
|
|
' ' Se salvataggio non riuscito, esco subito
|
|
' If Not bOk Then
|
|
' OmagOFFICEMap.refTopCommandBarVM.m_MruFiles.Remove(sFile)
|
|
' Dim sMsg As String = EgtMsg(10004) & " '" & sFile & "'" 'Error saving file
|
|
' MessageBox.Show(sMsg, EgtMsg(10001), MessageBoxButton.OK, MessageBoxImage.Error) ' Error
|
|
' Return
|
|
' End If
|
|
' ' Eventuale salvataggio VM
|
|
' Dim sVmFile As String = Path.ChangeExtension(sFile, ".vme")
|
|
' VeinMatching.Save(sVmFile)
|
|
' ' Eventuale salvataggio CSV
|
|
' CsvM.SaveCsvPartList()
|
|
' ' Aggiornamento titolo
|
|
' OmagOFFICEMap.refMainWindowVM.Title = sFile & " - OmagOFFICE"
|
|
' ' Riabilito visualizzazione pezzi in parcheggio
|
|
' EstCalc.ShowParkedParts()
|
|
' ' Inserisco nome in MRU
|
|
' OmagOFFICEMap.refTopCommandBarVM.m_MruFiles.Add(sFile)
|
|
' ' Salvo nome ultimo file
|
|
' WriteMainPrivateProfileString(S_GENERAL, K_LASTPROJ, sFile)
|
|
' 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
|
|
|
|
' Private Sub OnChangedSnapPointType(ByVal sender As Object, ByVal nSpType As SP, ByVal bUser As Boolean) Handles OmagOFFICEScene.OnChangedSnapPointType
|
|
' Dim BtnColor As Brush
|
|
' If bUser Then
|
|
' BtnColor = New SolidColorBrush(SystemColors.ControlColor)
|
|
' Else
|
|
' BtnColor = Brushes.Bisque
|
|
' End If
|
|
' Select Case nSpType
|
|
' Case SP.PT_SKETCH
|
|
' OmagOFFICEMap.refStatusBarVM.SetSnapPointType(EgtMsg(1102), BtnColor) 'Sketch Point
|
|
' Case SP.PT_GRID
|
|
' OmagOFFICEMap.refStatusBarVM.SetSnapPointType(EgtMsg(1104), BtnColor) 'Grid Point
|
|
' Case SP.PT_END
|
|
' OmagOFFICEMap.refStatusBarVM.SetSnapPointType(EgtMsg(1106), BtnColor) 'End Point
|
|
' Case SP.PT_MID
|
|
' OmagOFFICEMap.refStatusBarVM.SetSnapPointType(EgtMsg(1108), BtnColor) 'Mid Point
|
|
' Case SP.CENTER
|
|
' OmagOFFICEMap.refStatusBarVM.SetSnapPointType(EgtMsg(1110), BtnColor) 'Center
|
|
' Case SP.CENTROID
|
|
' OmagOFFICEMap.refStatusBarVM.SetSnapPointType(EgtMsg(1112), BtnColor) 'Centroid
|
|
' Case SP.PT_NEAR
|
|
' OmagOFFICEMap.refStatusBarVM.SetSnapPointType(EgtMsg(1114), BtnColor) 'Near Point
|
|
' Case SP.PT_INTERS
|
|
' OmagOFFICEMap.refStatusBarVM.SetSnapPointType(EgtMsg(1116), BtnColor) 'Inters Point
|
|
' Case SP.PT_TANGENT
|
|
' OmagOFFICEMap.refStatusBarVM.SetSnapPointType(EgtMsg(1118), BtnColor) 'Tang Point
|
|
' Case SP.PT_PERPENDICULAR
|
|
' OmagOFFICEMap.refStatusBarVM.SetSnapPointType(EgtMsg(1120), BtnColor) 'Perp Point
|
|
' Case SP.PT_MINDIST
|
|
' OmagOFFICEMap.refStatusBarVM.SetSnapPointType(EgtMsg(1122), BtnColor) 'MinDist Point
|
|
' Case Else
|
|
' OmagOFFICEMap.refStatusBarVM.SetSnapPointType("---", BtnColor)
|
|
' End Select
|
|
' End Sub
|
|
|
|
'#End Region ' EVENTS
|
|
|
|
End Class
|