d42d6a23a1
- tolto rallentamento in import con molti pezzi - tolto rallentamento in seleziona tutto di nesting a causa di VM.
730 lines
31 KiB
VB.net
730 lines
31 KiB
VB.net
Imports System.IO
|
|
Imports System.Windows.Interop
|
|
Imports System.Runtime.InteropServices
|
|
Imports EgtUILib
|
|
Imports EgtWPFLib
|
|
|
|
Public Class VeinMatchingWindow
|
|
|
|
' Riferimento alla MainWindow
|
|
Private m_MainWindow As MainWindow = DirectCast(Application.Current.MainWindow, MainWindow)
|
|
' Dichiarazione Scene
|
|
Friend WithEvents VeinMatchingScene As New Scene
|
|
Private VeinMatchingSceneHost As New System.Windows.Forms.Integration.WindowsFormsHost
|
|
' Gestione finestra
|
|
Private m_bFirst As Boolean = True
|
|
Private m_bPositioned As Boolean = False
|
|
' Selezione e modifica
|
|
Private m_nIdToSel As Integer = GDB_ID.NULL
|
|
Private m_nIdToDesel As Integer = GDB_ID.NULL
|
|
|
|
Private Sub Window_Initialized(sender As Object, e As EventArgs)
|
|
' Assegnazione scena all'host e posizionamento nella PlacePageGrid
|
|
VeinMatchingSceneHost.Child = VeinMatchingScene
|
|
VeinMatchingSceneHost.SetValue(Grid.ColumnProperty, 1)
|
|
Me.VeinMatchingGrid.Children.Add(VeinMatchingSceneHost)
|
|
' Per non farla visualizzare alla creazione
|
|
Me.Left = 32000
|
|
' Assegno messaggi
|
|
NewBtn.Content = EgtMsg(MSG_CADCUTPAGEUC + 3)
|
|
ExportBtn.Content = EgtMsg(MSG_CADCUTPAGEUC + 10)
|
|
End Sub
|
|
|
|
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
|
|
If m_bFirst Then
|
|
' Imposto finestra senza SystemMenu
|
|
Dim hwnd As IntPtr = New WindowInteropHelper(Me).Handle
|
|
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) And Not WS_SYSMENU)
|
|
' imposto colore di default
|
|
Dim DefColor As New Color3d(0, 0, 0)
|
|
GetPrivateProfileColor(S_GEOMDB, K_DEFAULTCOLOR, DefColor, m_MainWindow.GetIniFile())
|
|
VeinMatchingScene.SetDefaultMaterial(DefColor)
|
|
' imposto colori sfondo
|
|
Dim BackTopColor As New Color3d(211, 211, 211)
|
|
GetPrivateProfileColor(S_SCENE, K_BACKTOP, BackTopColor, m_MainWindow.GetIniFile())
|
|
Dim BackBotColor As New Color3d(211, 211, 211)
|
|
GetPrivateProfileColor(S_SCENE, K_BACKBOTTOM, BackBotColor, m_MainWindow.GetIniFile())
|
|
VeinMatchingScene.SetViewBackground(BackTopColor, BackBotColor)
|
|
' imposto colore di evidenziazione
|
|
Dim MarkColor As New Color3d(255, 255, 0)
|
|
GetPrivateProfileColor(S_SCENE, K_MARK, MarkColor, m_MainWindow.GetIniFile())
|
|
VeinMatchingScene.SetMarkMaterial(MarkColor)
|
|
' imposto colore per superfici selezionate
|
|
Dim SelSurfColor As New Color3d(255, 255, 192)
|
|
GetPrivateProfileColor(S_SCENE, K_SELSURF, SelSurfColor, m_MainWindow.GetIniFile())
|
|
VeinMatchingScene.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())
|
|
VeinMatchingScene.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())
|
|
VeinMatchingScene.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())
|
|
VeinMatchingScene.SetViewAttributes(nDriver, b2Buff, nColorBits, nDepthBits)
|
|
' inizializzo la scena (DB geometrico + visualizzazione) e verifico presenza chiave
|
|
If Not VeinMatchingScene.Init() Then
|
|
m_MainWindow.m_CadCutPageUC.m_ProjectMgr.VeinMatchingBtn.IsChecked = False
|
|
Me.Close()
|
|
End If
|
|
' dimensione lineare max in pixel delle textures
|
|
Dim nTxrMaxLinPix As Integer = GetPrivateProfileInt(S_SCENE, K_TEXMAXLINPIX, 4096, m_MainWindow.GetIniFile())
|
|
EgtSetTextureMaxLinPixels(nTxrMaxLinPix)
|
|
m_bFirst = False
|
|
End If
|
|
' inibisco selezione diretta da Scene
|
|
VeinMatchingScene.SetStatusNull()
|
|
End Sub
|
|
|
|
Private Sub Window_Closed(sender As Object, e As EventArgs) Handles Me.Closed
|
|
' Salvo posizione Window (se posizionata e non minimizzata)
|
|
If m_bPositioned And Me.WindowState <> WindowState.Minimized Then
|
|
Dim nFlag As Integer = If(Me.WindowState = WindowState.Maximized, 1, 0)
|
|
WritePrivateProfileWinPos(S_VEINMATCHING, K_VEINMA_PLACE, nFlag, CInt(Me.Left), CInt(Me.Top), CInt(Me.Width), CInt(Me.Height), m_MainWindow.GetIniFile())
|
|
End If
|
|
End Sub
|
|
|
|
Friend Sub AdjustPosition()
|
|
' Se già pozizionata, esco subito
|
|
If m_bPositioned Then Return
|
|
' Imposto posizione e dimensioni della MainWindow da INI
|
|
Dim nFlag, nLeft, nTop, nWidth, nHeight As Integer
|
|
If GetPrivateProfileWinPos(S_VEINMATCHING, K_VEINMA_PLACE, nFlag, nLeft, nTop, nWidth, nHeight, m_MainWindow.GetIniFile()) Then
|
|
Dim PtTL = New System.Drawing.Point(nLeft, nTop)
|
|
Dim s As System.Windows.Forms.Screen = System.Windows.Forms.Screen.FromPoint(PtTL)
|
|
If s.Bounds.Contains(PtTL) Then
|
|
Me.WindowStartupLocation = Windows.WindowStartupLocation.Manual
|
|
Me.Top = nTop
|
|
Me.Left = nLeft
|
|
Me.Height = nHeight
|
|
Me.Width = nWidth
|
|
Me.WindowState = If(nFlag = 1, WindowState.Maximized, WindowState.Normal)
|
|
m_bPositioned = True
|
|
Return
|
|
End If
|
|
End If
|
|
' Imposto in posizione standard
|
|
Me.WindowStartupLocation = Windows.WindowStartupLocation.Manual
|
|
Me.Top = m_MainWindow.Top
|
|
Me.Left = m_MainWindow.Left
|
|
Me.Height = nHeight
|
|
Me.Width = nWidth
|
|
Me.WindowState = If(nFlag = 1, WindowState.Maximized, WindowState.Normal)
|
|
m_bPositioned = True
|
|
End Sub
|
|
|
|
Private Sub OnMouseDownScene(sender As Object, e As Windows.Forms.MouseEventArgs) Handles VeinMatchingScene.OnMouseDownScene
|
|
' Si può selezionare solo con il tasto sinistro e se stato NULL
|
|
If e.Button <> Windows.Forms.MouseButtons.Left Or Not VeinMatchingScene.IsStatusNull() Then Return
|
|
' Eseguo selezione
|
|
EgtSetObjFilterForSelWin(True, True, True, True, True)
|
|
Dim nSel As Integer
|
|
EgtSelect(e.Location, Scene.DIM_SEL, Scene.DIM_SEL, nSel)
|
|
' Ricavo nome dell'entità selezionata e identificativo
|
|
Dim nId As Integer = EgtGetFirstObjInSelWin()
|
|
While nId <> GDB_ID.NULL
|
|
' Cerco 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)
|
|
' Se già selezionato o posizione oggetto incompatibile con flag posizione selezionati
|
|
If nStat = GDB_ST.SEL Then
|
|
' Memorizzo Id da deselezionare
|
|
m_nIdToDesel = nPartId
|
|
Else
|
|
' Memorizzo Id da selezionare
|
|
m_nIdToSel = nPartId
|
|
End If
|
|
EgtDraw()
|
|
Exit While
|
|
End If
|
|
' Passo al successivo
|
|
nId = EgtGetNextObjInSelWin()
|
|
End While
|
|
End Sub
|
|
|
|
Private Sub OnMouseUpScene(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles VeinMatchingScene.OnMouseUpScene
|
|
' Se selezione da eseguire
|
|
If m_nIdToSel <> GDB_ID.NULL Then
|
|
' Eseguo la selezione in Nesting
|
|
Dim bSelected As Boolean = False
|
|
Dim nOriId As Integer = GDB_ID.NULL
|
|
EgtGetInfo(m_nIdToSel, KEY_ORI_ID, nOriId)
|
|
If EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx()) AndAlso EgtExistsObj(nOriId) Then
|
|
If (m_MainWindow.m_CadCutPageUC.m_NestPage.SelectPart(nOriId, False)) Then
|
|
bSelected = True
|
|
Else
|
|
' "Attenzione" "Pezzo non selezionabile in questa condizione"
|
|
Dim Mbox As New EgtMsgBox(Me, 350, EgtMsgBox.WidthType.PIXEL, EgtMsg(91122), EgtMsg(91606), EgtMsgBox.Buttons.OK, EgtMsgBox.Icons.ESCLAMATION, 2)
|
|
End If
|
|
End If
|
|
EgtSetCurrentContext(VeinMatchingScene.GetCtx())
|
|
' Se selezione riuscita, la eseguo anche in VME
|
|
If bSelected Then EgtSelectObj(m_nIdToSel)
|
|
' Se deselezione da eseguire
|
|
ElseIf m_nIdToDesel <> GDB_ID.NULL Then
|
|
' Eseguo la deselezione in Nesting
|
|
Dim bDeselected As Boolean = False
|
|
Dim nOriId As Integer = GDB_ID.NULL
|
|
EgtGetInfo(m_nIdToDesel, KEY_ORI_ID, nOriId)
|
|
If EgtSetCurrentContext(m_MainWindow.m_CurrentProjectPageUC.CurrentProjectScene.GetCtx()) AndAlso EgtExistsObj(nOriId) Then
|
|
If (m_MainWindow.m_CadCutPageUC.m_NestPage.DeselectPart(nOriId, False)) Then
|
|
bDeselected = True
|
|
End If
|
|
End If
|
|
EgtSetCurrentContext(VeinMatchingScene.GetCtx())
|
|
' Se deselezione riuscita, la eseguo anche in VME
|
|
If bDeselected Then EgtDeselectObj(m_nIdToDesel)
|
|
End If
|
|
' Reset
|
|
m_nIdToSel = GDB_ID.NULL
|
|
m_nIdToDesel = GDB_ID.NULL
|
|
EgtDraw()
|
|
End Sub
|
|
|
|
Private Sub NewBtn_Click(sender As Object, e As RoutedEventArgs) Handles NewBtn.Click
|
|
VeinMatching.Clear()
|
|
End Sub
|
|
|
|
Private Sub ExportBtn_Click(sender As Object, e As RoutedEventArgs) Handles ExportBtn.Click
|
|
VeinMatching.Export(m_MainWindow.GetVeinMatchingDir() & "\Image.jpg")
|
|
End Sub
|
|
|
|
End Class
|
|
|
|
Friend Module VeinMatching
|
|
|
|
' Riferimento alla MainWindow
|
|
Private m_MainWindow As MainWindow = DirectCast(Application.Current.MainWindow, MainWindow)
|
|
' Contesto del VeinMatching
|
|
Friend m_nVeinCtx As Integer = 0
|
|
' Nome fotografia
|
|
Private m_nPhoto As Integer = 0
|
|
' Dimensioni immagine da esportare
|
|
Private m_nImgWidth As Integer = 1600
|
|
Private m_nImgHeight As Integer = 1200
|
|
|
|
' Costanti
|
|
Const REF_NAME As String = "Ref"
|
|
Const KEY_ORI_REF As String = "OriRef"
|
|
|
|
Friend Function SetRefOnAllParts(nCtx As Integer) As Boolean
|
|
' Si opera nel contesto indicato
|
|
EgtSetCurrentContext(nCtx)
|
|
Dim nId As Integer = EgtGetFirstPart()
|
|
While nId <> GDB_ID.NULL
|
|
' Gruppo regione
|
|
Dim nRegLayId As Integer = EgtGetFirstNameInGroup(nId, NAME_REGION)
|
|
' Entità superficie regione piatta
|
|
Dim nRegId As Integer = EgtGetFirstInGroup(nRegLayId)
|
|
While nRegId <> GDB_ID.NULL
|
|
If EgtGetType(nRegId) = GDB_TY.SRF_FRGN Then
|
|
Exit While
|
|
End If
|
|
nRegId = EgtGetNext(nRegId)
|
|
End While
|
|
' Ne recupero il centroide
|
|
Dim ptCen As Point3d
|
|
EgtCentroid(nRegId, GDB_ID.ROOT, ptCen)
|
|
' Inserisco il riferimento
|
|
Dim frRef As New Frame3d(ptCen)
|
|
Dim nRefId As Integer = EgtCreateGeoFrame(nRegLayId, frRef, GDB_RT.GLOB)
|
|
EgtSetName(nRefId, REF_NAME)
|
|
' salvo nelle info il riferimento originale
|
|
EgtSetInfo(nRefId, KEY_ORI_REF, frRef)
|
|
' nascondo l'oggetto appena inserito
|
|
EgtSetMode(nRefId, GDB_MD.HIDDEN)
|
|
' Passo al pezzo successivo
|
|
nId = EgtGetNextPart(nId)
|
|
End While
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function Clear() As Boolean
|
|
' Verifico esista il contesto del VeinMatching
|
|
If m_nVeinCtx = 0 Then Return True
|
|
' Imposto VeinMatching context
|
|
Dim nCurrCtx = SetVeinContext()
|
|
If nCurrCtx = 0 Then Return False
|
|
' Pulisco il DB
|
|
EgtNewFile()
|
|
EgtDraw()
|
|
' Reset contatore foto
|
|
m_nPhoto = 0
|
|
' Se necessario, ripristino il contesto originale
|
|
If nCurrCtx > 0 Then EgtSetCurrentContext(nCurrCtx)
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function AddPart(sPartFile As String, nPartId As Integer) As Boolean
|
|
' Verifico esista il contesto del VeinMatching
|
|
If m_nVeinCtx = 0 Then Return True
|
|
' Imposto VeinMatching context
|
|
Dim nMainCtx = SetVeinContext()
|
|
If nMainCtx = 0 Then Return False
|
|
' Inserisco il pezzo
|
|
EgtInsertFile(sPartFile)
|
|
' Ne recupero l'Id
|
|
Dim nVeinId2 As Integer = EgtGetLastPart()
|
|
' Assegno Id originale
|
|
EgtSetInfo(nVeinId2, KEY_ORI_ID, nPartId)
|
|
' Nascondo scritte, sono nel layer "Region"
|
|
Dim nVeinRegId As Integer = EgtGetFirstNameInGroup(nVeinId2, NAME_REGION)
|
|
Dim nCurrId As Integer = EgtGetFirstInGroup(nVeinRegId)
|
|
While nCurrId <> GDB_ID.NULL
|
|
If EgtGetType(nCurrId) = GDB_TY.EXT_TEXT Then EgtSetStatus(nCurrId, GDB_ST.OFF)
|
|
nCurrId = EgtGetNext(nCurrId)
|
|
End While
|
|
' Nascondo layer con valori angoli dei lati
|
|
nCurrId = EgtGetFirstNameInGroup(nVeinId2, SIDE_ANGLE_LAYER)
|
|
EgtSetStatus(nCurrId, GDB_ST.OFF)
|
|
' Se necessario, ripristino il contesto originale
|
|
If nMainCtx > 0 Then EgtSetCurrentContext(nMainCtx)
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function AddParts(sPartFile As String, nFirstPartId As Integer) As Boolean
|
|
' Verifico esista il contesto del VeinMatching
|
|
If m_nVeinCtx = 0 Then Return True
|
|
' Imposto VeinMatching context
|
|
Dim nMainCtx = SetVeinContext()
|
|
If nMainCtx = 0 Then Return False
|
|
' Inserisco i pezzi e recupero Id primo pezzo inserito
|
|
Dim nFirstVeinId As Integer = EgtGetLastPart()
|
|
EgtInsertFile(sPartFile)
|
|
nFirstVeinId = If(nFirstVeinId <> GDB_ID.NULL, EgtGetNextPart(nFirstVeinId), EgtGetFirstPart())
|
|
' Ciclo sui pezzi inseriti
|
|
Dim nVeinId As Integer = nFirstVeinId
|
|
While nVeinId <> GDB_ID.NULL
|
|
' Assegno Id originale
|
|
EgtSetInfo(nVeinId, KEY_ORI_ID, nFirstPartId + nVeinId - nFirstVeinId)
|
|
' Nascondo scritte, sono nel layer "Region"
|
|
Dim nVeinRegId As Integer = EgtGetFirstNameInGroup(nVeinId, NAME_REGION)
|
|
Dim nCurrId As Integer = EgtGetFirstInGroup(nVeinRegId)
|
|
While nCurrId <> GDB_ID.NULL
|
|
If EgtGetType(nCurrId) = GDB_TY.EXT_TEXT Then EgtSetStatus(nCurrId, GDB_ST.OFF)
|
|
nCurrId = EgtGetNext(nCurrId)
|
|
End While
|
|
' Nascondo layer con valori angoli dei lati
|
|
nCurrId = EgtGetFirstNameInGroup(nVeinId, SIDE_ANGLE_LAYER)
|
|
EgtSetStatus(nCurrId, GDB_ST.OFF)
|
|
' Passo al pezzo successivo
|
|
nVeinId = EgtGetNextPart(nVeinId)
|
|
End While
|
|
' Se necessario, ripristino il contesto originale
|
|
If nMainCtx > 0 Then EgtSetCurrentContext(nMainCtx)
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function UpdatePart(nPartId As Integer) As Boolean
|
|
' Verifico esista il contesto del VeinMatching
|
|
If m_nVeinCtx = 0 Then Return True
|
|
' Recupero il contesto corrente (principale)
|
|
Dim nMainCtx = EgtGetCurrentContext()
|
|
' Recupero il nome originale del pezzo
|
|
Dim nOriId As Integer = nPartId
|
|
EgtGetInfo(nPartId, KEY_ORI_ID, nOriId)
|
|
EgtSetInfo(nPartId, KEY_ORI_ID, nPartId)
|
|
' Recupero il pezzo nel VeinMatching
|
|
EgtSetCurrentContext(m_nVeinCtx)
|
|
Dim nId = GetVeinPartId(nOriId)
|
|
If nId <> GDB_ID.NULL Then EgtSetInfo(nId, KEY_ORI_ID, nPartId)
|
|
EgtSetCurrentContext(nMainCtx)
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function OnInsertPartInRaw(nPartId As Integer, Optional bDeselect As Boolean = True) As Boolean
|
|
' Verifico esista il contesto del VeinMatching
|
|
If m_nVeinCtx = 0 Then Return True
|
|
' Recupero il contesto corrente (principale)
|
|
Dim nMainCtx = EgtGetCurrentContext()
|
|
' Se non c'è la fotografia, esco
|
|
Dim nPhotoId As Integer = m_MainWindow.m_CurrentProjectPageUC.GetPhoto()
|
|
If nPhotoId = GDB_ID.NULL Then Return If(bDeselect, OnDeselectPart(nPartId), True)
|
|
' Recupero il nome originale del pezzo
|
|
Dim nOriId As Integer = nPartId
|
|
EgtGetInfo(nPartId, KEY_ORI_ID, nOriId)
|
|
' Verifico se esiste già la foto del progetto corrente nel VeinMatching
|
|
Dim sPhoto As String = String.Empty
|
|
EgtGetPhotoPath(nPhotoId, sPhoto)
|
|
Dim sVeinPhoto As String = String.Empty
|
|
GetVeinPhotoPath(sVeinPhoto)
|
|
' Se necessario, copio la foto
|
|
If String.Compare(sPhoto, sVeinPhoto, True) <> 0 Then
|
|
If Not CopyPhoto(nPhotoId) Then Return False
|
|
End If
|
|
' Recupero il pezzo nel VeinMatching
|
|
EgtSetCurrentContext(m_nVeinCtx)
|
|
Dim nId = GetVeinPartId(nOriId)
|
|
If nId <> GDB_ID.NULL Then
|
|
' Recupero la regione del pezzo
|
|
Dim nRegId As Integer = GetVeinPartRegionId(nId)
|
|
' Gli assegno la texture della foto
|
|
EgtSetTextureName(nRegId, GetPhotoName())
|
|
' Sistemo il riferimento della texture
|
|
Dim refTxr As New Frame3d
|
|
GetVeinRefPhoto(nMainCtx, nPartId, nId, refTxr)
|
|
EgtSetTextureFrame(nRegId, refTxr, GDB_RT.GLOB)
|
|
' Sistemo il colore
|
|
Dim colWhite As New Color3d(255, 255, 255, 100)
|
|
EgtSetColor(nRegId, colWhite)
|
|
' Se richiesto, eseguo deselezione
|
|
If bDeselect Then EgtDeselectObj(nId)
|
|
End If
|
|
EgtDraw()
|
|
EgtSetCurrentContext(nMainCtx)
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function OnMovePartInRaw(nPartId As Integer) As Boolean
|
|
' Verifico esista il contesto del VeinMatching
|
|
If m_nVeinCtx = 0 Then Return True
|
|
' Recupero il contesto corrente (principale)
|
|
Dim nMainCtx = EgtGetCurrentContext()
|
|
' Se non c'è la fotografia, esco
|
|
Dim nPhotoId As Integer = m_MainWindow.m_CurrentProjectPageUC.GetPhoto()
|
|
If nPhotoId = GDB_ID.NULL Then Return True
|
|
' Recupero il nome originale del pezzo
|
|
Dim nOriId As Integer = nPartId
|
|
EgtGetInfo(nPartId, KEY_ORI_ID, nOriId)
|
|
' Recupero il pezzo nel VeinMatching
|
|
EgtSetCurrentContext(m_nVeinCtx)
|
|
Dim nId = GetVeinPartId(nOriId)
|
|
If nId <> GDB_ID.NULL Then
|
|
' Recupero la regione del pezzo
|
|
Dim nRegId As Integer = GetVeinPartRegionId(nId)
|
|
' Sistemo il riferimento della texture
|
|
Dim refTxr As New Frame3d
|
|
GetVeinRefPhoto(nMainCtx, nPartId, nId, refTxr)
|
|
EgtSetTextureFrame(nRegId, refTxr, GDB_RT.GLOB)
|
|
End If
|
|
EgtDraw()
|
|
EgtSetCurrentContext(nMainCtx)
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function OnRemovePartFromRaw(nPartId As Integer, Optional bDeselect As Boolean = True) As Boolean
|
|
' Verifico esista il contesto del VeinMatching
|
|
If m_nVeinCtx = 0 Then Return True
|
|
' Recupero il contesto corrente (principale)
|
|
Dim nMainCtx = EgtGetCurrentContext()
|
|
' Se non c'è la fotografia, esco
|
|
Dim nPhotoId As Integer = m_MainWindow.m_CurrentProjectPageUC.GetPhoto()
|
|
If nPhotoId = GDB_ID.NULL Then Return If(bDeselect, OnDeselectPart(nPartId), True)
|
|
' Recupero il nome originale del pezzo
|
|
Dim nOriId As Integer = nPartId
|
|
EgtGetInfo(nPartId, KEY_ORI_ID, nOriId)
|
|
' Tolgo la texture dal pezzo
|
|
EgtSetCurrentContext(m_nVeinCtx)
|
|
Dim nId As Integer = GetVeinPartId(nOriId)
|
|
If nId <> GDB_ID.NULL Then
|
|
' Recupero la regione del pezzo
|
|
Dim nRegId As Integer = GetVeinPartRegionId(nId)
|
|
' Gli tolgo la texture
|
|
EgtRemoveTextureData(nRegId)
|
|
' Sistemo il colore
|
|
Dim colAqua As New Color3d(0, 255, 255, 25)
|
|
EgtSetColor(nRegId, colAqua)
|
|
' Se richiesto, eseguo deselezione
|
|
If bDeselect Then EgtDeselectObj(nId)
|
|
End If
|
|
EgtDraw()
|
|
EgtSetCurrentContext(nMainCtx)
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function OnSelectPart(nPartId As Integer, Optional bDraw As Boolean = True) As Boolean
|
|
' Verifico esista il contesto del VeinMatching
|
|
If m_nVeinCtx = 0 Then Return True
|
|
' Recupero il contesto corrente (principale)
|
|
Dim nMainCtx = EgtGetCurrentContext()
|
|
' Recupero il nome originale del pezzo
|
|
Dim nOriId As Integer = nPartId
|
|
EgtGetInfo(nPartId, KEY_ORI_ID, nOriId)
|
|
' Recupero il pezzo nel VeinMatching
|
|
EgtSetCurrentContext(m_nVeinCtx)
|
|
Dim nId = GetVeinPartId(nOriId)
|
|
Dim bFound As Boolean = nId <> GDB_ID.NULL
|
|
' Lo seleziono e aggiorno visualizzazione
|
|
If bFound Then
|
|
EgtSelectObj(nId)
|
|
If bDraw Then EgtDraw()
|
|
End If
|
|
' Ritorno al contesto originale
|
|
EgtSetCurrentContext(nMainCtx)
|
|
Return bFound
|
|
End Function
|
|
|
|
Friend Function OnDeselectPart(nPartId As Integer) As Boolean
|
|
' Verifico esista il contesto del VeinMatching
|
|
If m_nVeinCtx = 0 Then Return True
|
|
' Recupero il contesto corrente (principale)
|
|
Dim nMainCtx = EgtGetCurrentContext()
|
|
' Recupero il nome originale del pezzo
|
|
Dim nOriId As Integer = nPartId
|
|
EgtGetInfo(nPartId, KEY_ORI_ID, nOriId)
|
|
' Recupero il pezzo nel VeinMatching
|
|
EgtSetCurrentContext(m_nVeinCtx)
|
|
Dim nId = GetVeinPartId(nOriId)
|
|
Dim bFound As Boolean = nId <> GDB_ID.NULL
|
|
' Lo seleziono
|
|
If bFound Then EgtDeselectObj(nId)
|
|
' Aggiorno visualizzazione e ritorno al contesto originale
|
|
EgtDraw()
|
|
EgtSetCurrentContext(nMainCtx)
|
|
Return bFound
|
|
End Function
|
|
|
|
Friend Function OnSelectAll() As Boolean
|
|
' Verifico esista il contesto del VeinMatching
|
|
If m_nVeinCtx = 0 Then Return True
|
|
' Imposto VeinMatching context
|
|
Dim nCurrCtx = SetVeinContext()
|
|
If nCurrCtx = 0 Then Return False
|
|
' Eseguo selezione di tutti i pezzi
|
|
EgtSelectAll()
|
|
EgtDraw()
|
|
' Se necessario, ripristino il contesto originale
|
|
If nCurrCtx > 0 Then EgtSetCurrentContext(nCurrCtx)
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function OnDeselectAll() As Boolean
|
|
' Verifico esista il contesto del VeinMatching
|
|
If m_nVeinCtx = 0 Then Return True
|
|
' Imposto VeinMatching context
|
|
Dim nCurrCtx = SetVeinContext()
|
|
If nCurrCtx = 0 Then Return False
|
|
' Eseguo deselezione di tutti i pezzi
|
|
EgtDeselectAll()
|
|
EgtDraw()
|
|
' Se necessario, ripristino il contesto originale
|
|
If nCurrCtx > 0 Then EgtSetCurrentContext(nCurrCtx)
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function Draw() As Boolean
|
|
' Verifico esista il contesto del VeinMatching
|
|
If m_nVeinCtx = 0 Then Return True
|
|
' Imposto VeinMatching context
|
|
Dim nCurrCtx = SetVeinContext()
|
|
If nCurrCtx = 0 Then Return False
|
|
' Eseguo Zoom
|
|
EgtDraw()
|
|
' Se necessario, ripristino il contesto originale
|
|
If nCurrCtx > 0 Then EgtSetCurrentContext(nCurrCtx)
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function ZoomAll() As Boolean
|
|
' Verifico esista il contesto del VeinMatching
|
|
If m_nVeinCtx = 0 Then Return True
|
|
' Imposto VeinMatching context
|
|
Dim nCurrCtx = SetVeinContext()
|
|
If nCurrCtx = 0 Then Return False
|
|
' Eseguo Zoom
|
|
EgtZoom(ZM.ALL)
|
|
' Se necessario, ripristino il contesto originale
|
|
If nCurrCtx > 0 Then EgtSetCurrentContext(nCurrCtx)
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function Open(sFilePath As String) As Boolean
|
|
' Verifico esista il contesto del VeinMatching
|
|
If m_nVeinCtx = 0 Then Return True
|
|
' Recupero il contesto corrente (principale)
|
|
Dim nMainCtx = EgtGetCurrentContext()
|
|
' Apro il file
|
|
EgtSetCurrentContext(m_nVeinCtx)
|
|
Dim bOk As Boolean = EgtOpenFile(sFilePath)
|
|
' Aggiorno contatore foto
|
|
Dim nPhId As Integer = EgtGetFirstInGroup(EgtGetFirstNameInGroup(GDB_ID.ROOT, PHOTO_GRP))
|
|
While nPhId <> GDB_ID.NULL
|
|
Dim sName As String = String.Empty
|
|
EgtGetName(nPhId, sName)
|
|
Dim nVal As Integer = 0
|
|
If StringToInt(sName.Replace(PHOTO_NAME, ""), nVal) Then m_nPhoto = Math.Max(m_nPhoto, nVal)
|
|
nPhId = EgtGetNext(nPhId)
|
|
End While
|
|
' Eseguo zoom all
|
|
EgtZoom(ZM.ALL)
|
|
' Ripristino il contesto originale
|
|
EgtSetCurrentContext(nMainCtx)
|
|
Return bOk
|
|
End Function
|
|
|
|
Friend Function Save(sFilePath As String) As Boolean
|
|
' Verifico esista il contesto del VeinMatching
|
|
If m_nVeinCtx = 0 Then Return True
|
|
' Recupero il contesto corrente (principale)
|
|
Dim nMainCtx As Integer = EgtGetCurrentContext()
|
|
' Salvo il file
|
|
EgtSetCurrentContext(m_nVeinCtx)
|
|
Dim bOk As Boolean = EgtSaveFile(sFilePath, NGE.CMPTEXT)
|
|
' Ripristino il contesto originale
|
|
EgtSetCurrentContext(nMainCtx)
|
|
Return bOk
|
|
End Function
|
|
|
|
Friend Function Export(sFilePath As String) As Boolean
|
|
' Verifico esista il contesto del VeinMatching
|
|
If m_nVeinCtx = 0 Then Return True
|
|
' Recupero il contesto corrente (principale)
|
|
Dim nMainCtx = EgtGetCurrentContext()
|
|
' Esporto il file come immagine
|
|
EgtSetCurrentContext(m_nVeinCtx)
|
|
Dim bOk As Boolean = (EgtGetFileType(sFilePath) = FT.IMG)
|
|
bOk = bOk AndAlso EgtGetImage(EgtGetShowMode(), New Color3d(255, 255, 255), New Color3d(255, 255, 255),
|
|
m_nImgWidth, m_nImgHeight, sFilePath)
|
|
' Ripristino il contesto originale
|
|
EgtSetCurrentContext(nMainCtx)
|
|
Return bOk
|
|
End Function
|
|
|
|
Private Function GetPhotoName() As String
|
|
Return PHOTO_NAME & m_nPhoto.ToString()
|
|
End Function
|
|
|
|
Private Function CopyPhoto(nPhotoId As Integer) As Boolean
|
|
' Recupero il contesto corrente
|
|
Dim nCurrCtx = EgtGetCurrentContext()
|
|
' Recupero i dati della fotografia
|
|
Dim sPath As String = String.Empty
|
|
If Not EgtGetPhotoPath(nPhotoId, sPath) OrElse Not File.Exists(sPath) Then Return False
|
|
Dim ptOri As Point3d
|
|
If Not EgtGetPhotoOrigin(nPhotoId, ptOri) Then Return False
|
|
Dim ptCen As Point3d
|
|
If Not EgtGetPhotoCenter(nPhotoId, ptCen) Then Return False
|
|
Dim dDimX, dDimY As Double
|
|
If Not EgtGetPhotoDimensions(nPhotoId, dDimX, dDimY) Then Return False
|
|
Dim ptMin, ptMax As Point3d
|
|
If Not EgtGetBBoxGlob(nPhotoId, GDB_BB.STANDARD, ptMin, ptMax) Then Return False
|
|
' Passo al contesto del VeinMatching
|
|
EgtSetCurrentContext(m_nVeinCtx)
|
|
' Se non esiste il gruppo per le foto, lo creo
|
|
Dim nPhGrpId As Integer = EgtGetFirstNameInGroup(GDB_ID.ROOT, PHOTO_GRP)
|
|
If nPhGrpId = GDB_ID.NULL Then
|
|
nPhGrpId = EgtCreateGroup(GDB_ID.ROOT)
|
|
If nPhGrpId = GDB_ID.NULL Then
|
|
EgtSetCurrentContext(nCurrCtx)
|
|
Return False
|
|
End If
|
|
EgtSetName(nPhGrpId, PHOTO_GRP)
|
|
End If
|
|
EgtSetLevel(nPhGrpId, GDB_LV.SYSTEM)
|
|
EgtSetStatus(nPhGrpId, GDB_ST.OFF)
|
|
' Carico la fotografia
|
|
m_nPhoto += 1
|
|
Dim nNewId As Integer = EgtAddPhoto2(GetPhotoName(), sPath, ptOri, ptCen, dDimX, dDimY, nPhGrpId, ptMin, ptMax)
|
|
' Ritorno al contesto corrente
|
|
EgtSetCurrentContext(nCurrCtx)
|
|
Return nNewId <> GDB_ID.NULL
|
|
End Function
|
|
|
|
Private Function SetVeinContext() As Integer
|
|
' Verifico esista il contesto del VeinMatching
|
|
If m_nVeinCtx = 0 Then Return 0
|
|
' Recupero il contesto corrente
|
|
Dim nCurrCtx = EgtGetCurrentContext()
|
|
' Se necessario, cambio contesto
|
|
If m_nVeinCtx <> nCurrCtx Then
|
|
If EgtSetCurrentContext(m_nVeinCtx) Then
|
|
Return nCurrCtx
|
|
Else
|
|
Return 0
|
|
End If
|
|
Else
|
|
Return -1
|
|
End If
|
|
End Function
|
|
|
|
Private Function GetVeinPhoto() As Integer
|
|
' Imposto VeinMatching context
|
|
Dim nCurrCtx = SetVeinContext()
|
|
If nCurrCtx = 0 Then Return GDB_ID.NULL
|
|
' Recupero Id foto
|
|
Dim nId As Integer = EgtGetFirstNameInGroup(EgtGetFirstNameInGroup(GDB_ID.ROOT, PHOTO_GRP), GetPhotoName())
|
|
' Se necessario, ripristino il contesto originale
|
|
If nCurrCtx > 0 Then EgtSetCurrentContext(nCurrCtx)
|
|
Return nId
|
|
End Function
|
|
|
|
Private Function GetVeinPhotoPath(ByRef sPath As String) As Boolean
|
|
' Imposto VeinMatching context
|
|
Dim nCurrCtx = SetVeinContext()
|
|
If nCurrCtx = 0 Then Return False
|
|
' Recupero path dell'immagine della foto
|
|
Dim nId As Integer = EgtGetFirstNameInGroup(EgtGetFirstNameInGroup(GDB_ID.ROOT, PHOTO_GRP), GetPhotoName())
|
|
Dim bOk As Boolean = EgtGetPhotoPath(nId, sPath)
|
|
' Se necessario, ripristino il contesto originale
|
|
If nCurrCtx > 0 Then EgtSetCurrentContext(nCurrCtx)
|
|
Return bOk
|
|
End Function
|
|
|
|
Private Function GetVeinRefPhoto(nMainCtx As Integer, nPartId As Integer, nVePartId As Integer, ByRef refPhoto As Frame3d) As Boolean
|
|
' Riferimento della foto rispetto al riferimento del pezzo nel contesto principale
|
|
If Not EgtSetCurrentContext(nMainCtx) Then Return False
|
|
' riferimento della foto in globale
|
|
If Not m_MainWindow.m_CurrentProjectPageUC.GetPhotoTextureRef(refPhoto) Then Return False
|
|
' riferimento del pezzo in globale
|
|
Dim nRefId As Integer = EgtGetFirstNameInGroup(EgtGetFirstNameInGroup(nPartId, NAME_REGION), REF_NAME)
|
|
Dim refPart As New Frame3d
|
|
If Not EgtFrame(nRefId, GDB_ID.ROOT, refPart) Then Return False
|
|
' porto il riferimento della foto in quello del pezzo
|
|
refPhoto.ToLoc(refPart)
|
|
' Riferimento della foto rispetto al riferimento del pezzo in VeinMatching
|
|
If Not EgtSetCurrentContext(m_nVeinCtx) Then Return False
|
|
' riferimento del pezzo in globale
|
|
Dim nVeRefId As Integer = EgtGetFirstNameInGroup(EgtGetFirstNameInGroup(nVePartId, NAME_REGION), REF_NAME)
|
|
Dim refVePart As New Frame3d
|
|
If Not EgtFrame(nVeRefId, GDB_ID.ROOT, refVePart) Then Return False
|
|
refPhoto.ToGlob(refVePart)
|
|
Return True
|
|
End Function
|
|
|
|
Private Function GetVeinPartId(nPartId As Integer) As Integer
|
|
' Imposto VeinMatching context
|
|
Dim nCurrCtx = SetVeinContext()
|
|
If nCurrCtx = 0 Then Return GDB_ID.NULL
|
|
' Cerco il pezzo in Vein che corrisponde al pezzo desiderato
|
|
Dim nId As Integer = EgtGetFirstPart()
|
|
While nId <> GDB_ID.NULL
|
|
Dim nOriId As Integer
|
|
If EgtGetInfo(nId, KEY_ORI_ID, nOriId) AndAlso nOriId = nPartId Then
|
|
Exit While
|
|
End If
|
|
nId = EgtGetNextPart(nId)
|
|
End While
|
|
' Se necessario, ripristino il contesto originale
|
|
If nCurrCtx > 0 Then EgtSetCurrentContext(nCurrCtx)
|
|
Return nId
|
|
End Function
|
|
|
|
Private Function GetVeinPartRegionId(nVeinPartId As Integer) As Integer
|
|
' Imposto VeinMatching context
|
|
Dim nCurrCtx = SetVeinContext()
|
|
If nCurrCtx = 0 Then Return GDB_ID.NULL
|
|
' Gruppo regione
|
|
Dim nRegLayId As Integer = EgtGetFirstNameInGroup(nVeinPartId, NAME_REGION)
|
|
' Entità superficie regione piatta
|
|
Dim nRegId As Integer = EgtGetFirstInGroup(nRegLayId)
|
|
While nRegId <> GDB_ID.NULL
|
|
If EgtGetType(nRegId) = GDB_TY.SRF_FRGN Then
|
|
Exit While
|
|
End If
|
|
nRegId = EgtGetNext(nRegId)
|
|
End While
|
|
' Se necessario, ripristino il contesto originale
|
|
If nCurrCtx > 0 Then EgtSetCurrentContext(nCurrCtx)
|
|
Return nRegId
|
|
End Function
|
|
|
|
End Module
|