584717d3b1
- aggiornamento.
392 lines
16 KiB
VB.net
392 lines
16 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports System.IO
|
|
Imports EgtUILib
|
|
Imports System.Runtime.InteropServices
|
|
|
|
Public Class ImportPageUC
|
|
|
|
'Riferimento alla MainWindow
|
|
Private m_MainWindow As MainWindow = Application.Current.MainWindow
|
|
|
|
'Dichiarazione del UserControl SceneButtons
|
|
Friend m_SceneButtons As SceneButtonsUC
|
|
|
|
' Properties
|
|
Private m_sCurrDir As String = String.Empty
|
|
Private m_sCurrFile As String = String.Empty
|
|
Private m_nFileType As Integer = FT.NULL
|
|
Private m_bFirst As Boolean = True
|
|
|
|
'Dichiarazione Scene
|
|
Friend WithEvents ImportScene As New Scene
|
|
Dim ImportSceneHost As New System.Windows.Forms.Integration.WindowsFormsHost
|
|
|
|
Private Sub ImportPage_Initialized(sender As Object, e As EventArgs)
|
|
|
|
'Creazione del UserCOntrol SceneButtons
|
|
m_SceneButtons = New SceneButtonsUC
|
|
|
|
'Posizionemento nella griglia del UserControl SceneButtons
|
|
m_SceneButtons.SetValue(Grid.ColumnProperty, 0)
|
|
BottomButtonsGrid.Children.Add(m_SceneButtons)
|
|
|
|
'Assegnazione scena all'host e posizionamento nella ImportPageGrid
|
|
ImportSceneHost.Child = ImportScene
|
|
ImportSceneHost.SetValue(Grid.ColumnProperty, 1)
|
|
ImportSceneHost.SetValue(Grid.RowProperty, 0)
|
|
ImportSceneHost.SetValue(Grid.RowSpanProperty, 2)
|
|
Me.ImportPageGrid.Children.Add(ImportSceneHost)
|
|
|
|
'Definizione del collegamento tra ItemList e ListBox1
|
|
FileListBox.ItemsSource = m_MainWindow.ImportItemList
|
|
|
|
End Sub
|
|
|
|
Private Sub ImportPage_Loaded(sender As Object, e As RoutedEventArgs)
|
|
|
|
If m_bFirst Then
|
|
' imposto colore di default
|
|
Dim DefColor As New Color3d(0, 0, 0)
|
|
GetPrivateProfileColor(S_GEOMDB, K_DEFAULTCOLOR, DefColor, m_MainWindow.GetIniFile())
|
|
ImportScene.SetDefaultMaterial(DefColor)
|
|
' imposto colori sfondo
|
|
Dim BackTopColor As New Color3d(192, 192, 192)
|
|
GetPrivateProfileColor(S_SCENE, K_BACKTOP, BackTopColor, m_MainWindow.GetIniFile())
|
|
Dim BackBotColor As New Color3d(BackTopColor)
|
|
GetPrivateProfileColor(S_SCENE, K_BACKBOTTOM, BackBotColor, m_MainWindow.GetIniFile())
|
|
ImportScene.SetViewBackground(BackTopColor, BackBotColor)
|
|
' imposto colore di evidenziazione
|
|
Dim MarkColor As New Color3d(255, 255, 0)
|
|
GetPrivateProfileColor(S_SCENE, K_MARK, MarkColor, m_MainWindow.GetIniFile())
|
|
ImportScene.SetMarkMaterial(MarkColor)
|
|
' imposto colore per superfici selezionate
|
|
Dim SelSurfColor As New Color3d(255, 255, 192)
|
|
GetPrivateProfileColor(S_SCENE, K_SELSURF, SelSurfColor, m_MainWindow.GetIniFile())
|
|
ImportScene.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_MainWindow.GetIniFile())
|
|
ImportScene.SetZoomWinAttribs(bOutline, ZwColor)
|
|
' imposto colore della linea di distanza
|
|
Dim DstLnColor As New Color3d(255, 0, 0)
|
|
GetPrivateProfileColor(S_SCENE, K_DISTLINE, DstLnColor, m_MainWindow.GetIniFile())
|
|
ImportScene.SetDistLineMaterial(DstLnColor)
|
|
' imposto parametri OpenGL
|
|
Dim nDriver As Integer = GetPrivateProfileInt(S_OPENGL, K_DRIVER, 3, m_MainWindow.GetIniFile())
|
|
Dim b2Buff As Boolean = (GetPrivateProfileInt(S_OPENGL, K_DOUBLEBUFFER, 1, m_MainWindow.GetIniFile()) <> 0)
|
|
Dim nColorBits As Integer = GetPrivateProfileInt(S_OPENGL, K_COLORBITS, 32, m_MainWindow.GetIniFile())
|
|
Dim nDepthBits As Integer = GetPrivateProfileInt(S_OPENGL, K_DEPTHBITS, 32, m_MainWindow.GetIniFile())
|
|
ImportScene.SetViewAttributes(nDriver, b2Buff, nColorBits, nDepthBits)
|
|
' Inizializzazione delle viste
|
|
ImportScene.Init()
|
|
' Imposto griglia
|
|
LoadGridData()
|
|
' leggo direttorio corrente
|
|
GetPrivateProfileString(S_FLATPARTS, K_FLPCURRDIR, "", m_sCurrDir, m_MainWindow.GetIniFile())
|
|
' lo carico
|
|
LoadCurrDir()
|
|
m_bFirst = False
|
|
Else
|
|
EgtSetCurrentContext(ImportScene.GetCtx())
|
|
End If
|
|
|
|
' Pulisco tutto
|
|
ClearView()
|
|
' inibisco selezione diretta da Scene
|
|
ImportScene.SetStatusNull()
|
|
|
|
End Sub
|
|
|
|
Private Sub LoadGridData()
|
|
Dim dSnapStep As Double = GetPrivateProfileDouble(S_GRID, K_SNAPSTEP, 10, m_MainWindow.GetIniFile())
|
|
Dim nMinLineSStep As Integer = GetPrivateProfileInt(S_GRID, K_MINLINESSTEP, 1, m_MainWindow.GetIniFile())
|
|
Dim nMajLineSStep As Integer = GetPrivateProfileInt(S_GRID, K_MAJLINESSTEP, 10, m_MainWindow.GetIniFile())
|
|
Dim nExtSStep As Integer = GetPrivateProfileInt(S_GRID, K_EXTSSTEP, 50, m_MainWindow.GetIniFile())
|
|
Dim MinLnColor As New Color3d(160, 160, 160)
|
|
GetPrivateProfileColor(S_GRID, K_MINLNCOLOR, MinLnColor, m_MainWindow.GetIniFile())
|
|
Dim MajLnColor As New Color3d(160, 160, 160)
|
|
GetPrivateProfileColor(S_GRID, K_MAJLNCOLOR, MajLnColor, m_MainWindow.GetIniFile())
|
|
EgtSetGridFrame(Frame3d.GLOB)
|
|
EgtSetGridGeo(dSnapStep, nMinLineSStep, nMajLineSStep, nExtSStep)
|
|
EgtSetGridColor(MinLnColor, MajLnColor)
|
|
Dim bShowGrid As Boolean = (GetPrivateProfileInt(S_GRID, K_SHOWGRID, 1, m_MainWindow.GetIniFile()) <> 0)
|
|
EgtSetGridShow(bShowGrid, False)
|
|
End Sub
|
|
|
|
Private Function LoadCurrDir() As Boolean
|
|
' se direttorio corrente non valido, carico l'elenco dei dischi
|
|
If String.IsNullOrWhiteSpace(m_sCurrDir) OrElse Not IO.Directory.Exists(m_sCurrDir) Then
|
|
Return LoadDisks()
|
|
End If
|
|
Dim TempPath As New Text.StringBuilder(260)
|
|
PathCompactPathEx(TempPath, m_sCurrDir, 28, 0)
|
|
' lo visualizzo
|
|
FilePathTxBl.Content = TempPath.ToString
|
|
' pulisco la lista
|
|
m_MainWindow.ImportItemList.Clear()
|
|
' per risalire al direttorio padre
|
|
m_MainWindow.ImportItemList.Add(New IconListBoxItem("..", 0))
|
|
' elenco dei sottodirettori
|
|
Dim DirInfo As New DirectoryInfo(m_sCurrDir)
|
|
Dim vDirI As DirectoryInfo() = DirInfo.GetDirectories("*")
|
|
Dim DirI As DirectoryInfo
|
|
For Each DirI In vDirI
|
|
If (DirI.Attributes And FileAttributes.Hidden) <> FileAttributes.Hidden Then
|
|
m_MainWindow.ImportItemList.Add(New IconListBoxItem(DirI.Name, 2))
|
|
End If
|
|
Next
|
|
' elenco dei file
|
|
Dim vFileI As FileInfo() = DirInfo.GetFiles()
|
|
Dim FileI As FileInfo
|
|
For Each FileI In vFileI
|
|
Dim sExt As String = Path.GetExtension(FileI.Name).ToUpper()
|
|
If sExt = ".BTL" Then
|
|
m_MainWindow.ImportItemList.Add(New IconListBoxItem(FileI.Name, 3))
|
|
End If
|
|
Next
|
|
' pulisco la vista
|
|
ClearView()
|
|
Return True
|
|
End Function
|
|
|
|
Private Function LoadDisks() As Boolean
|
|
' dir corrente vuoto
|
|
m_sCurrDir = ""
|
|
' lo visualizzo
|
|
FilePathTxBl.Content = m_sCurrDir
|
|
' pulisco la lista
|
|
m_MainWindow.ImportItemList.Clear()
|
|
' elenco dei dischi
|
|
Dim vDriI As DriveInfo() = DriveInfo.GetDrives()
|
|
Dim DriI As DriveInfo
|
|
For Each DriI In vDriI
|
|
m_MainWindow.ImportItemList.Add(New IconListBoxItem(DriI.Name, 1))
|
|
Next
|
|
' pulisco la vista
|
|
ClearView()
|
|
Return True
|
|
End Function
|
|
|
|
Private Sub FileListBox_PreviewMouseUp(sender As Object, e As MouseButtonEventArgs) Handles FileListBox.PreviewMouseUp
|
|
' Recupero item selezionato
|
|
If FileListBox.SelectedItems.Count() = 0 Then
|
|
Return
|
|
End If
|
|
Dim vItems As IconListBoxItem = FileListBox.SelectedItems(0)
|
|
|
|
' A seconda del tipo
|
|
Select Case vItems.PictureID
|
|
Case 0 ' Vai nel direttorio padre
|
|
m_sCurrDir = IO.Path.GetDirectoryName(m_sCurrDir)
|
|
m_sCurrFile = ""
|
|
LoadCurrDir()
|
|
Case 1 ' Vai nella radice del disco
|
|
m_sCurrDir = vItems.Name
|
|
m_sCurrFile = ""
|
|
LoadCurrDir()
|
|
Case 2 ' Vai nel sottodirettorio
|
|
m_sCurrDir = IO.Path.Combine(m_sCurrDir, vItems.Name)
|
|
m_sCurrFile = ""
|
|
LoadCurrDir()
|
|
Case 3 ' File
|
|
m_sCurrFile = vItems.Name
|
|
LoadCurrFile()
|
|
End Select
|
|
|
|
End Sub
|
|
|
|
Private Sub FileListBox_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles FileListBox.SelectionChanged
|
|
' Recupero item selezionato
|
|
If FileListBox.SelectedItems.Count() = 0 Then
|
|
Return
|
|
End If
|
|
Dim vItems As IconListBoxItem = FileListBox.SelectedItems(0)
|
|
|
|
' Gestisco solo aggiornamento visualizzazione file
|
|
If vItems.PictureID = 3 Then
|
|
m_sCurrFile = vItems.Name
|
|
LoadCurrFile()
|
|
End If
|
|
End Sub
|
|
|
|
Private Function ClearView() As Boolean
|
|
' Pulisco il DB geometrico locale
|
|
EgtNewFile()
|
|
' Eseguo zoom
|
|
ImportScene.ZoomAll()
|
|
Return True
|
|
End Function
|
|
|
|
Private Function LoadCurrFile() As Boolean
|
|
' Pulisco il DB geometrico locale
|
|
Dim bOk As Boolean = EgtNewFile()
|
|
' Costruisco path completa del componente
|
|
Dim sPath = IO.Path.Combine(m_sCurrDir, m_sCurrFile)
|
|
' Riconoscimento tipo
|
|
m_nFileType = EgtGetFileType(sPath)
|
|
If m_nFileType = FT.BTL Then
|
|
' Carico Btl
|
|
bOk = bOk AndAlso EgtImportBtl(sPath, EIB_FL.FLAT_POS + EIB_FL.SPECIAL_TRIM)
|
|
Else
|
|
' Formato sconosciuto
|
|
EgtNewFile()
|
|
bOk = False
|
|
End If
|
|
' Eseguo zoom
|
|
ImportScene.ZoomAll()
|
|
Return bOk
|
|
End Function
|
|
|
|
Private Sub OnMouseDownScene(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles ImportScene.OnMouseDownScene
|
|
' Si può selezionare solo con il tasto sinistro e se stato NULL
|
|
If e.Button <> Windows.Forms.MouseButtons.Left Or Not ImportScene.IsStatusNull() Then
|
|
Return
|
|
End If
|
|
' Verifico se selezionato indicativo di pezzo
|
|
EgtSetObjFilterForSelect(True, True, True, True, True)
|
|
Dim nSel As Integer
|
|
EgtSelect(e.Location, Scene.DIM_SEL, Scene.DIM_SEL, nSel)
|
|
Dim nId As Integer = EgtGetFirstObjInSelWin()
|
|
While nId <> GDB_ID.NULL
|
|
' Recupero l'identificativo del pezzo cui appartiene
|
|
Dim nPartId As Integer = EgtGetParent(EgtGetParent(nId))
|
|
If EgtIsPart(nPartId) Then
|
|
Dim nStat As Integer = GDB_ST.ON_
|
|
EgtGetStatus(nPartId, nStat)
|
|
If nStat = GDB_ST.SEL Then
|
|
EgtDeselectObj(nPartId)
|
|
Else
|
|
EgtSelectObj(nPartId)
|
|
End If
|
|
EgtDraw()
|
|
Exit While
|
|
End If
|
|
nId = EgtGetNextObjInSelWin()
|
|
End While
|
|
End Sub
|
|
|
|
Private Sub ConfirmBtn_Click(sender As Object, e As RoutedEventArgs) Handles OkBtn.Click
|
|
' Vettore nomi file temporanei
|
|
Dim sTmpFiles As New ArrayList()
|
|
' Ciclo di salvataggio dei pezzi selezionati
|
|
Dim nId As Integer = EgtGetFirstSelectedObj()
|
|
While nId <> GDB_ID.NULL
|
|
' Esporto il pezzo in un file temporaneo
|
|
Dim sTmpFile As String = m_MainWindow.GetTempDir() & "\Wall" & nId & ".Nge"
|
|
sTmpFiles.Add(sTmpFile)
|
|
If Not EgtSaveObjToFile(nId, sTmpFile, NGE.BIN) Then
|
|
Return
|
|
End If
|
|
' Passo al pezzo successivo
|
|
nId = EgtGetNextSelectedObj()
|
|
End While
|
|
' Passo al contesto principale
|
|
EgtSetCurrentContext(m_MainWindow.m_PlacePageUC.PlaceScene.GetCtx())
|
|
' Parametri di caricamento
|
|
Dim dMinX As Double = 0
|
|
Dim dMinY As Double = -m_MainWindow.m_PlacePageUC.m_dWidth
|
|
Dim dMaxX As Double = m_MainWindow.m_PlacePageUC.m_dLength
|
|
Dim dMaxY As Double = 0
|
|
Dim dOffset As Double = m_MainWindow.m_PlacePageUC.m_dMinDist
|
|
Dim dParkMaxY As Double = m_MainWindow.m_PlacePageUC.m_dParkMaxY
|
|
Dim dOffsetX As Double = m_MainWindow.m_PlacePageUC.m_dOffsetX
|
|
Dim dOffsetY As Double = m_MainWindow.m_PlacePageUC.m_dOffsetY
|
|
Dim dPlankX As Double = m_MainWindow.m_PlacePageUC.m_dPlankX
|
|
' Ciclo di caricamento dei pezzi
|
|
For Each sTmpfile As String In sTmpFiles
|
|
If My.Computer.FileSystem.FileExists(sTmpfile) Then
|
|
' Inserisco il pezzo
|
|
EgtInsertFile(sTmpfile)
|
|
' Ne recupero l'Id
|
|
Dim nId2 As Integer = EgtGetLastPart()
|
|
' Aggiungo il grezzo
|
|
Dim nIdRaw As Integer = EgtCreateGroup(nId2, New Frame3d())
|
|
EgtSetName(nIdRaw, "Raw")
|
|
EgtSetAlpha(nIdRaw, 40)
|
|
Dim ptMin, ptMax As Point3d
|
|
EgtGetBBoxGlob(nId2, GDB_BB.ONLY_VISIBLE + GDB_BB.IGNORE_TEXT + GDB_BB.IGNORE_DIM, ptMin, ptMax)
|
|
ptMin.x -= dOffsetX
|
|
ptMin.y -= dOffsetY
|
|
' Per avere un numero intero di assi in X
|
|
Dim dLen As Double = ptMax.x + dOffsetX - ptMin.x
|
|
Dim nPlank As Integer = Math.Ceiling(dLen / dPlankX)
|
|
ptMax.x = ptMin.x + nPlank * dPlankX
|
|
ptMax.y += dOffsetY
|
|
EgtCreateSurfTmBBox(nIdRaw, ptMin, ptMax, GDB_RT.GLOB)
|
|
' Lo posiziono nel parcheggio
|
|
EgtPackBox(nId2, dMinX, -INFINITO, dMaxX, dParkMaxY, dOffset, False)
|
|
' Cerco di spostarlo nella tavola
|
|
EgtPackBox(nId2, dMinX, dMinY, dMaxX, dMaxY, dOffset, False)
|
|
' Cancello il file
|
|
My.Computer.FileSystem.DeleteFile(sTmpfile)
|
|
End If
|
|
Next
|
|
' Aggiorno ambiente principale
|
|
EgtZoom(ZM.ALL, False)
|
|
m_MainWindow.m_PlacePageUC.MyDraw()
|
|
'Istruzioni per chiudere ImportPageUC e aprire PlacePage UC
|
|
m_MainWindow.MainWindowGrid.Children.Remove(m_MainWindow.m_ImportPageUC)
|
|
m_MainWindow.MainWindowGrid.Children.Add(m_MainWindow.m_PlacePageUC)
|
|
m_MainWindow.m_ActivePage = MainWindow.Pages.Place
|
|
m_MainWindow.ImportBtn.IsChecked = False
|
|
m_MainWindow.PlaceBtn.IsChecked = True
|
|
End Sub
|
|
|
|
Private Sub ExitBtn_Click(sender As Object, e As RoutedEventArgs) Handles ExitBtn.Click
|
|
'Istruzioni per chiudere ImportPageUC e aprire PlacePage UC
|
|
m_MainWindow.MainWindowGrid.Children.Remove(m_MainWindow.m_ImportPageUC)
|
|
m_MainWindow.MainWindowGrid.Children.Add(m_MainWindow.m_PlacePageUC)
|
|
m_MainWindow.m_ActivePage = MainWindow.Pages.Place
|
|
m_MainWindow.ImportBtn.IsChecked = False
|
|
m_MainWindow.PlaceBtn.IsChecked = True
|
|
End Sub
|
|
|
|
Private Sub ImportPage_Unloaded(sender As Object, e As RoutedEventArgs)
|
|
' Salvo direttorio corrente
|
|
WritePrivateProfileString(S_FLATPARTS, K_FLPCURRDIR, m_sCurrDir, m_MainWindow.GetIniFile())
|
|
End Sub
|
|
|
|
End Class
|
|
|
|
Public Class IconListBoxItem
|
|
|
|
Private m_iPictureID As Integer
|
|
Private m_sName As String
|
|
|
|
Public Property PictureID() As Integer
|
|
Get
|
|
Return m_iPictureID
|
|
End Get
|
|
Set(value As Integer)
|
|
m_iPictureID = value
|
|
End Set
|
|
End Property
|
|
|
|
Public Property Name() As String
|
|
Get
|
|
Return m_sName
|
|
End Get
|
|
Set(value As String)
|
|
m_sName = value
|
|
End Set
|
|
End Property
|
|
|
|
Public ReadOnly Property PictureString() As String
|
|
Get
|
|
Return "/Resources/ImportPageListBoxImages/" + PictureID.ToString() + ".png"
|
|
End Get
|
|
End Property
|
|
|
|
Sub New()
|
|
Me.Name = String.Empty
|
|
Me.PictureID = 0
|
|
End Sub
|
|
|
|
Sub New(Name As String, PictureID As Integer)
|
|
Me.Name = Name
|
|
Me.PictureID = PictureID
|
|
End Sub
|
|
|
|
|
|
End Class |