5edb9884c9
- aggiunta gestione spezzatura e movimento lastre.
234 lines
9.9 KiB
VB.net
234 lines
9.9 KiB
VB.net
'----------------------------------------------------------------------------
|
|
' EgalTech 2015-2017
|
|
'----------------------------------------------------------------------------
|
|
' File : GenPhoto.vb Data : 12.04.17 Versione : 1.8d1
|
|
' Contenuto : Modulo gestione fotografie.
|
|
' Ogni gruppo di lavoro può avere una sua foto della lastra.
|
|
'
|
|
'
|
|
' Modifiche : 12.04.17 DS Creazione modulo.
|
|
'
|
|
'
|
|
'----------------------------------------------------------------------------
|
|
|
|
Imports System.IO
|
|
Imports EgtUILib
|
|
|
|
Module EstPhoto
|
|
|
|
Friend Function LoadPhoto(sPath As String) As Boolean
|
|
' Verifico esistenza file immagine
|
|
If Not File.Exists(sPath) Then Return False
|
|
' Leggo eventuale file dati aggiuntivi
|
|
Dim ptOri As New Point3d(0, 0, 0)
|
|
Dim ptCen As New Point3d(0, 0, INFINITO)
|
|
Dim dMMxPixel As Double = 1
|
|
ReadAuxData(sPath, ptOri, ptCen, dMMxPixel)
|
|
' Altezza eventuale tavola aggiuntiva
|
|
Dim dAddTable As Double = CurrentMachine.dAdditionalTable
|
|
' Aggiusto dati per spessore grezzo
|
|
If Math.Abs(EstCalc.GetRawHeight() + dAddTable) > EPS_SMALL Then
|
|
' Coefficiente di scalatura
|
|
Dim dFsca As Double = (ptCen.z - EstCalc.GetRawHeight() - dAddTable) / (ptCen.z - ptOri.z)
|
|
dMMxPixel *= dFsca
|
|
ptOri.x = ptCen.x + (ptOri.x - ptCen.x) * dFsca
|
|
ptOri.y = ptCen.y + (ptOri.y - ptCen.y) * dFsca
|
|
ptOri.z = EstCalc.GetRawHeight() + dAddTable
|
|
End If
|
|
' Recupero origine della tavola e porto i punti in globale
|
|
Dim ptTab As Point3d
|
|
If Not EgtGetTableRef(1, ptTab) Then Return False
|
|
ptOri.ToGlob(New Frame3d(ptTab))
|
|
ptCen.ToGlob(New Frame3d(ptTab))
|
|
' Recupero le dimensioni della tavola
|
|
Dim ptMin, ptMax As Point3d
|
|
If Not EgtGetTableArea(1, ptMin, ptMax) Then Return False
|
|
' Elimino eventuale precedente foto
|
|
Dim nOldPhotoId = GetPhoto()
|
|
If nOldPhotoId <> GDB_ID.NULL Then EgtErase(nOldPhotoId)
|
|
' 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 Return False
|
|
EgtSetName(nPhGrpId, PHOTO_GRP)
|
|
End If
|
|
EgtSetLevel(nPhGrpId, GDB_LV.SYSTEM)
|
|
' Carico la fotografia
|
|
Return EgtAddPhoto(GetPhotoName(), sPath, ptOri, ptCen, dMMxPixel, nPhGrpId, ptMin, ptMax) <> GDB_ID.NULL
|
|
End Function
|
|
|
|
Private Function ReadAuxData(sPath As String,
|
|
ByRef ptOri As Point3d, ByRef ptCen As Point3d, ByRef dMMxPixel As Double) As Boolean
|
|
Dim sAuxPath As String = Path.ChangeExtension(sPath, ".txt")
|
|
Try
|
|
Dim sLine As String = String.Empty
|
|
Dim sr As StreamReader = New StreamReader(sAuxPath)
|
|
Do While sr.Peek() > -1
|
|
sLine = sr.ReadLine()
|
|
sLine = sLine.Replace(" ", "")
|
|
If sLine.StartsWith("X=") Then
|
|
StringToDouble(sLine.Substring(2), ptOri.x)
|
|
ElseIf sLine.StartsWith("Y=") Then
|
|
StringToDouble(sLine.Substring(2), ptOri.y)
|
|
ElseIf sLine.StartsWith("Z_Lastra=") Then
|
|
StringToDouble(sLine.Substring(9), ptOri.z)
|
|
ElseIf sLine.StartsWith("X_ScaleCenter=") Then
|
|
StringToDouble(sLine.Substring(14), ptCen.x)
|
|
ElseIf sLine.StartsWith("Y_ScaleCenter=") Then
|
|
StringToDouble(sLine.Substring(14), ptCen.y)
|
|
ElseIf sLine.StartsWith("Z_ScaleCenter=") Then
|
|
StringToDouble(sLine.Substring(14), ptCen.z)
|
|
ElseIf sLine.StartsWith("Pixelxmm=") Then
|
|
Dim dTmp As Double
|
|
StringToDouble(sLine.Substring(9), dTmp)
|
|
If dTmp > EPS_SMALL Then
|
|
dMMxPixel = 1 / dTmp
|
|
End If
|
|
End If
|
|
Loop
|
|
sr.Close()
|
|
Return True
|
|
Catch ex As Exception
|
|
EgtOutLog("LoadPhoto Error on auxfile : " & sAuxPath)
|
|
Return False
|
|
End Try
|
|
End Function
|
|
|
|
Public Function GetPhotoName() As String
|
|
' Recupero il nome del gruppo di lavoro corrente
|
|
Dim sMGrp As String = String.Empty
|
|
If Not EgtGetMachGroupName(EgtGetCurrMachGroup(), sMGrp) Then Return ""
|
|
' Creo il nome della foto
|
|
Return PHOTO_NAME & sMGrp
|
|
End Function
|
|
|
|
Public Function GetPhoto() As Integer
|
|
' Recupero Id del gruppo delle foto
|
|
Dim nPhGrpId As Integer = EgtGetFirstNameInGroup(GDB_ID.ROOT, PHOTO_GRP)
|
|
' Recupero Id della foto
|
|
Return EgtGetFirstNameInGroup(nPhGrpId, GetPhotoName())
|
|
End Function
|
|
|
|
Public Function GetPhotoTextureRef(ByRef refTxr As Frame3d) As Boolean
|
|
' Recupero la foto
|
|
Dim nId As Integer = GetPhoto()
|
|
If nId = GDB_ID.NULL Then Return False
|
|
' Recupero il riferimento in globale
|
|
Return EgtGetTextureFrame(nId, GDB_ID.ROOT, refTxr)
|
|
End Function
|
|
|
|
Public Function ShowPhoto(ByVal bShow As Boolean, Optional bDisableModified As Boolean = True) As Boolean
|
|
' Recupero la foto
|
|
Dim nId As Integer = GetPhoto()
|
|
If nId = GDB_ID.NULL Then Return False
|
|
' Se richiesto, disabilito impostazione modificato
|
|
Dim bOldEnMod As Boolean = False
|
|
If bDisableModified Then
|
|
bOldEnMod = EgtGetEnableModified()
|
|
If bOldEnMod Then EgtDisableModified()
|
|
End If
|
|
' Ne cambio lo stato
|
|
Dim bOk As Boolean = EgtSetStatus(nId, If(bShow, GDB_ST.ON_, GDB_ST.OFF))
|
|
' Se necessario, ripristino precedente impostazione modificato
|
|
If bOldEnMod Then EgtEnableModified()
|
|
Return bOk
|
|
End Function
|
|
|
|
Public Function UpdatePhoto() As Boolean
|
|
' Verifico esistenza oggetto foto
|
|
Dim nPhotoId As Integer = GetPhoto()
|
|
If nPhotoId = GDB_ID.NULL Then Return False
|
|
' Verifico esistenza texture della foto
|
|
Dim sPath As String = String.Empty
|
|
EgtGetPhotoPath(nPhotoId, sPath)
|
|
If Not File.Exists(sPath) Then Return False
|
|
' Recupero i dati aggiuntivi della foto
|
|
Dim ptOri As New Point3d(0, 0, 0)
|
|
EgtGetPhotoOrigin(nPhotoId, ptOri)
|
|
Dim ptCen As New Point3d(0, 0, 1)
|
|
EgtGetPhotoCenter(nPhotoId, ptCen)
|
|
Dim dMMxPixel As Double = 1
|
|
EgtGetPhotoMMxPixel(nPhotoId, dMMxPixel)
|
|
' Recupero origine della tavola
|
|
Dim ptTab As Point3d
|
|
If Not EgtGetTableRef(1, ptTab) Then Return False
|
|
' Porto i punti in locale
|
|
ptOri.ToLoc(New Frame3d(ptTab))
|
|
ptCen.ToLoc(New Frame3d(ptTab))
|
|
' Altezza eventuale tavola aggiuntiva
|
|
Dim dAddTable As Double = CurrentMachine.dAdditionalTable
|
|
' Aggiusto dati per spessore grezzo (Coefficiente di scalatura)
|
|
Dim dFsca As Double = (ptCen.z - EstCalc.GetRawHeight() - dAddTable) / (ptCen.z - ptOri.z)
|
|
dMMxPixel *= dFsca
|
|
ptOri.x = ptCen.x + (ptOri.x - ptCen.x) * dFsca
|
|
ptOri.y = ptCen.y + (ptOri.y - ptCen.y) * dFsca
|
|
ptOri.z = EstCalc.GetRawHeight() + dAddTable
|
|
' Porto i punti in globale
|
|
ptOri.ToGlob(New Frame3d(ptTab))
|
|
ptCen.ToGlob(New Frame3d(ptTab))
|
|
' Recupero le dimensioni della tavola
|
|
Dim ptMin, ptMax As Point3d
|
|
If Not EgtGetTableArea(1, ptMin, ptMax) Then Return False
|
|
' Elimino eventuale precedente foto
|
|
Dim nOldPhotoId = GetPhoto()
|
|
If nOldPhotoId <> GDB_ID.NULL Then EgtErase(nOldPhotoId)
|
|
' 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 Return False
|
|
EgtSetName(nPhGrpId, PHOTO_GRP)
|
|
End If
|
|
EgtSetLevel(nPhGrpId, GDB_LV.SYSTEM)
|
|
' Carico la fotografia
|
|
Return EgtAddPhoto(GetPhotoName(), sPath, ptOri, ptCen, dMMxPixel, nPhGrpId, ptMin, ptMax) <> GDB_ID.NULL
|
|
End Function
|
|
|
|
Public Function UpdateContour() As Boolean
|
|
' Verifico esistenza oggetto contorno
|
|
Dim nCrvId As Integer = GetContour()
|
|
If nCrvId = GDB_ID.NULL Then Return False
|
|
' Verifico esistenza oggetto foto
|
|
Dim nPhotoId As Integer = GetPhoto()
|
|
If nPhotoId = GDB_ID.NULL Then Return False
|
|
' Recupero centro della foto
|
|
Dim ptCen As New Point3d(0, 0, 1)
|
|
EgtGetPhotoCenter(nPhotoId, ptCen)
|
|
' Recupero origine della tavola
|
|
Dim ptTab As Point3d
|
|
If Not EgtGetTableRef(1, ptTab) Then Return False
|
|
' Altezza eventuale tavola aggiuntiva
|
|
Dim dAddTable As Double = CurrentMachine.dAdditionalTable
|
|
' Recupero inizio contorno
|
|
Dim ptStart As Point3d
|
|
EgtStartPoint(nCrvId, GDB_ID.ROOT, ptStart)
|
|
' Calcolo coefficiente di scalatura
|
|
Dim dFsca As Double = (ptCen.z - ptTab.z - EstCalc.GetRawHeight() - dAddTable) / (ptCen.z - ptStart.z)
|
|
' Scalo opportunamente
|
|
EgtScale(nCrvId, New Frame3d(ptCen), dFsca, dFsca, 1, GDB_RT.GLOB)
|
|
' Sposto in Z
|
|
Dim vtMove As New Vector3d(0, 0, ptTab.z + EstCalc.GetRawHeight() + dAddTable - ptStart.z)
|
|
EgtMove(nCrvId, vtMove, GDB_RT.GLOB)
|
|
Return True
|
|
End Function
|
|
|
|
Public Function GetContour() As Integer
|
|
Dim nPartId As Integer = EgtGetFirstNameInGroup(GDB_ID.ROOT, NAME_RAW_PHOTO_OUTLINE)
|
|
Dim nLayerId As Integer = EgtGetFirstGroupInGroup(nPartId)
|
|
Dim nCrvId As Integer = EgtGetFirstInGroup(nLayerId)
|
|
Return nCrvId
|
|
End Function
|
|
|
|
Public Sub ShowContour(bShow As Boolean)
|
|
' Disabilito impostazione modificato
|
|
Dim bOldEnMod As Boolean = EgtGetEnableModified()
|
|
If bOldEnMod Then EgtDisableModified()
|
|
' Cambio stato di visualizzazione
|
|
EgtSetStatus(EgtGetFirstNameInGroup(GDB_ID.ROOT, NAME_RAW_PHOTO_OUTLINE), If(bShow, GDB_ST.ON_, GDB_ST.OFF))
|
|
' Se necessario, ripristino precedente impostazione modificato
|
|
If bOldEnMod Then EgtEnableModified()
|
|
End Sub
|
|
|
|
End Module
|