a8cd99ebb4
- aggiunta gestione cornici (per ora solo disegno) - migliorie varie.
349 lines
14 KiB
VB.net
349 lines
14 KiB
VB.net
Imports EgtUILib
|
|
|
|
Public Class FrameCutPageUC
|
|
|
|
' Riferimenti a pagine
|
|
Private m_MainWindow As MainWindow = Application.Current.MainWindow
|
|
Private WithEvents m_CurrProjPage As CurrentProjectPageUC
|
|
Friend m_ProjectMgr As ProjectMgrUC
|
|
|
|
' Flag di pagina attiva
|
|
Private m_bActive As Boolean = False
|
|
' Dati del grezzo
|
|
Private m_nRawId As Integer = GDB_ID.NULL
|
|
Private m_RawBox As New BBox3d
|
|
' Array per combo direzioni
|
|
Private m_AlongAx(1) As String
|
|
' Direzione corrente
|
|
Private m_CurrAx As Integer = 0
|
|
' Oggetto di gestione della macchina fotografica
|
|
Friend m_Camera As New Camera
|
|
|
|
Private Sub FrameCutPage_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized
|
|
' Creazione delle Page UserControl
|
|
m_ProjectMgr = New ProjectMgrUC
|
|
|
|
' Posizionamento nella griglia delle Page UserControl
|
|
m_ProjectMgr.SetValue(Grid.RowProperty, 2)
|
|
m_ProjectMgr.SetValue(Grid.ColumnProperty, 1)
|
|
|
|
' Assegno UC a questa pagina
|
|
FrameCutPageGrid.Children.Add(m_ProjectMgr)
|
|
|
|
' Imposto i messaggi letti dal file dei messaggi
|
|
m_AlongAx(0) = "Lungo X"
|
|
m_AlongAx(1) = "Lungo Y"
|
|
AlongAxCmBx.ItemsSource = m_AlongAx
|
|
RemovePartBtn.Content = "Rimuovi cornice"
|
|
End Sub
|
|
|
|
Private Sub FrameCutPage_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
|
|
m_CurrProjPage = m_MainWindow.m_CurrentProjectPageUC
|
|
m_bActive = True
|
|
' recupero dimensioni del grezzo
|
|
m_nRawId = EgtGetFirstRawPart()
|
|
GetRawBox(m_RawBox)
|
|
' Imposto direzione cornici
|
|
UpdateAlongAxCmbBx()
|
|
' Se macchina fotografica abilitata
|
|
If m_MainWindow.GetKeyOption(MainWindow.KEY_OPT.MAN_PHOTO) Then
|
|
PhotoBtn.IsEnabled = True
|
|
' Inizializzo gestore macchina fotografica
|
|
m_Camera.Init()
|
|
Else
|
|
PhotoBtn.IsEnabled = False
|
|
End If
|
|
' Se provengo da grezzo, sistemo eventuali cornici
|
|
If m_MainWindow.m_PrevActivePage = MainWindow.Pages.RawPart Then
|
|
Dim nId As Integer = EgtGetFirstPart()
|
|
While nId <> GDB_ID.NULL
|
|
If Not UpdateFrame(nId) Then
|
|
EgtErase(nId)
|
|
End If
|
|
nId = EgtGetFirstPart()
|
|
End While
|
|
End If
|
|
EgtZoom(ZM.ALL)
|
|
End Sub
|
|
|
|
Private Sub UpdateAlongAxCmbBx()
|
|
' Se già presenti cornici, visualizzo direzione senza poterla modificare
|
|
Dim nPartId As Integer = EgtGetFirstPartInRawPart(m_nRawId)
|
|
If nPartId <> GDB_ID.NULL Then
|
|
Dim nDir As Integer
|
|
If EgtGetInfo(nPartId, INFO_FRAME_DIR, nDir) Then m_CurrAx = nDir
|
|
AlongAxCmBx.SelectedIndex = m_CurrAx
|
|
AlongAxCmBx.IsEnabled = False
|
|
' Altrimenti, abilito cambio direzione
|
|
Else
|
|
AlongAxCmBx.SelectedIndex = m_CurrAx
|
|
AlongAxCmBx.IsEnabled = True
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub FrameCutPage_Unloaded(sender As Object, e As RoutedEventArgs) Handles Me.Unloaded
|
|
m_bActive = False
|
|
End Sub
|
|
|
|
Private Sub OnMyMouseDownScene(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles m_CurrProjPage.OnMouseDownScene
|
|
' Verifico di essere il gestore attivo
|
|
If Not m_bActive Then
|
|
Return
|
|
End If
|
|
' Si può selezionare solo con il tasto sinistro e se stato NULL
|
|
If e.Button <> Windows.Forms.MouseButtons.Left Or
|
|
Not m_CurrProjPage.CurrentProjectScene.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))
|
|
Dim bPartInTable As Boolean = (EgtGetParent(nPartId) = m_nRawId)
|
|
If bPartInTable Then
|
|
Dim nStat As Integer = GDB_ST.ON_
|
|
EgtGetStatus(nPartId, nStat)
|
|
EgtSetStatus(nPartId, If(nStat = GDB_ST.SEL, GDB_ST.ON_, GDB_ST.SEL))
|
|
EgtDraw()
|
|
Exit While
|
|
End If
|
|
nId = EgtGetNextObjInSelWin()
|
|
End While
|
|
End Sub
|
|
|
|
Private Sub RemovePartBtn_Click(sender As Object, e As RoutedEventArgs) Handles RemovePartBtn.Click
|
|
' Ciclo di cancellazione dei pezzi selezionati
|
|
Dim nId As Integer = EgtGetFirstSelectedObj()
|
|
While nId <> GDB_ID.NULL
|
|
' Recupero indice del successivo
|
|
Dim nNextId = EgtGetNextSelectedObj()
|
|
' Cancello il pezzo
|
|
If EgtRemovePartFromRawPart(nId) Then
|
|
' Rimuovo le lavorazioni
|
|
EraseMachinings(nId)
|
|
' Cancello
|
|
EgtErase(nId)
|
|
End If
|
|
' Passo al successivo selezionato
|
|
nId = nNextId
|
|
End While
|
|
' Aggiusto posizione dei rimanenti pezzi nel grezzo
|
|
nId = EgtGetFirstPartInRawPart(m_nRawId)
|
|
While nId <> GDB_ID.NULL
|
|
EgtRemovePartFromRawPart(nId)
|
|
nId = EgtGetFirstPartInRawPart(m_nRawId)
|
|
End While
|
|
nId = EgtGetFirstPart()
|
|
While nId <> GDB_ID.NULL
|
|
InsertPartInRawPart(nId)
|
|
nId = EgtGetFirstPart()
|
|
End While
|
|
' Aggiorno vista
|
|
EgtDraw()
|
|
' Aggiorno combo per direzioni
|
|
UpdateAlongAxCmbBx()
|
|
End Sub
|
|
|
|
Private Sub PhotoBtn_Click(sender As Object, e As RoutedEventArgs) Handles PhotoBtn.Click
|
|
' Se macchina fotografica abilitata, faccio una foto
|
|
If m_Camera.GetCameraLink() Then
|
|
If Not m_Camera.CameraClick() Then
|
|
m_CurrProjPage.SetErrorMessage(EgtMsg(90313)) 'Fotografia non riuscita
|
|
End If
|
|
' Altrimenti lancio browser di immagini
|
|
Else
|
|
m_MainWindow.MainWindowGrid.Children.Remove(m_MainWindow.m_CurrentProjectPageUC)
|
|
m_MainWindow.MainWindowGrid.Children.Add(m_MainWindow.m_PhotoPage)
|
|
m_MainWindow.m_ActivePage = MainWindow.Pages.Photo
|
|
m_MainWindow.m_PrevActivePage = MainWindow.Pages.FrameCut
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub RawPartBtn_Click(sender As Object, e As RoutedEventArgs) Handles RawPartBtn.Click
|
|
m_MainWindow.m_CurrentProjectPageUC.CurrProjGrid.Visibility = Windows.Visibility.Hidden
|
|
m_MainWindow.m_CurrentProjectPageUC.CurrentProjectPageGrid.Children.Remove(Me)
|
|
m_MainWindow.m_CurrentProjectPageUC.CurrentProjectPageGrid.Children.Add(m_MainWindow.m_RawPartPage)
|
|
m_MainWindow.m_ActivePage = MainWindow.Pages.RawPart
|
|
m_MainWindow.m_PrevActivePage = MainWindow.Pages.FrameCut
|
|
End Sub
|
|
|
|
Private Sub ImportBtn_Click(sender As Object, e As RoutedEventArgs) Handles ImportBtn.Click
|
|
m_MainWindow.MainWindowGrid.Children.Remove(m_MainWindow.m_CurrentProjectPageUC)
|
|
m_MainWindow.MainWindowGrid.Children.Add(m_MainWindow.m_ImportPageUC)
|
|
m_MainWindow.m_ActivePage = MainWindow.Pages.Import
|
|
m_MainWindow.m_PrevActivePage = MainWindow.Pages.FrameCut
|
|
End Sub
|
|
|
|
Friend Function CreateFrame(nPartId As Integer) As Boolean
|
|
' Aggiorno direzione corrente
|
|
m_CurrAx = AlongAxCmBx.SelectedIndex
|
|
' Sistemo la sezione della cornice
|
|
If Not AdjustSection(nPartId) Then Return False
|
|
' Recupero layer e curva della sezione
|
|
Dim nSectLayId As Integer = EgtGetFirstNameInGroup(nPartId, NAME_SECT)
|
|
Dim nCrvId As Integer = EgtGetFirstInGroup(nSectLayId)
|
|
If nCrvId = GDB_ID.NULL Then Return False
|
|
' Porto la sezione nel piano opportuno e calcolo il vettore di estrusione
|
|
Dim vtExtr As Vector3d
|
|
If m_CurrAx = 0 Then
|
|
' Se lungo X nel piano YZ
|
|
EgtChangeGroupFrame(nSectLayId, New Frame3d(Point3d.ORIG, Frame3d.TYPE.LEFT))
|
|
vtExtr = New Vector3d(m_RawBox.DimX(), 0, 0)
|
|
Else
|
|
' Se lungo Y nel piano XZ
|
|
EgtChangeGroupFrame(nSectLayId, New Frame3d(Point3d.ORIG, Frame3d.TYPE.FRONT))
|
|
vtExtr = New Vector3d(0, m_RawBox.DimY(), 0)
|
|
End If
|
|
' Creo layer per la superficie
|
|
Dim nSurfLayId As Integer = EgtCreateGroup(nPartId, New Frame3d())
|
|
EgtSetName(nSurfLayId, NAME_SURF)
|
|
' Creo la superficie di estrusione
|
|
Dim nSectIds(0) As Integer
|
|
nSectIds(0) = nCrvId
|
|
Dim nSurfId As Integer = EgtCreateSurfTmByRegionExtrusion(nSurfLayId, 1, nSectIds, vtExtr, GDB_RT.GLOB)
|
|
EgtSetColor(nSurfId, COL_FRAME())
|
|
' Assegno nome e direzione a pezzo
|
|
EgtSetName(nPartId, NAME_FRAME)
|
|
EgtSetInfo(nPartId, INFO_FRAME_DIR, m_CurrAx)
|
|
' Inserisco il pezzo nel grezzo
|
|
Return InsertPartInRawPart(nPartId)
|
|
End Function
|
|
|
|
Friend Function UpdateFrame(nPartId As Integer) As Boolean
|
|
' Aggiorno direzione corrente
|
|
m_CurrAx = AlongAxCmBx.SelectedIndex
|
|
' Recupero layer e curva della sezione
|
|
Dim nSectLayId As Integer = EgtGetFirstNameInGroup(nPartId, NAME_SECT)
|
|
Dim nCrvId As Integer = EgtGetFirstInGroup(nSectLayId)
|
|
If nCrvId = GDB_ID.NULL Then Return False
|
|
' Porto la sezione nel piano opportuno e calcolo il vettore di estrusione
|
|
Dim vtExtr As Vector3d
|
|
If m_CurrAx = 0 Then
|
|
' Se lungo X nel piano YZ
|
|
EgtChangeGroupFrame(nSectLayId, New Frame3d(Point3d.ORIG, Frame3d.TYPE.LEFT))
|
|
vtExtr = New Vector3d(m_RawBox.DimX(), 0, 0)
|
|
Else
|
|
' Se lungo Y nel piano XZ
|
|
EgtChangeGroupFrame(nSectLayId, New Frame3d(Point3d.ORIG, Frame3d.TYPE.FRONT))
|
|
vtExtr = New Vector3d(0, m_RawBox.DimY(), 0)
|
|
End If
|
|
' Recupero layer per la superficie
|
|
Dim nSurfLayId As Integer = EgtGetFirstNameInGroup(nPartId, NAME_SURF)
|
|
If nSurfLayId = GDB_ID.NULL Then Return False
|
|
EgtEmptyGroup(nSurfLayId)
|
|
' Creo la superficie di estrusione
|
|
Dim nSectIds(0) As Integer
|
|
nSectIds(0) = nCrvId
|
|
Dim nSurfId As Integer = EgtCreateSurfTmByRegionExtrusion(nSurfLayId, 1, nSectIds, vtExtr, GDB_RT.GLOB)
|
|
EgtSetColor(nSurfId, COL_FRAME())
|
|
' Assegno nome e direzione a pezzo
|
|
EgtSetName(nPartId, NAME_FRAME)
|
|
EgtSetInfo(nPartId, INFO_FRAME_DIR, m_CurrAx)
|
|
' Inserisco il pezzo nel grezzo
|
|
Return InsertPartInRawPart(nPartId)
|
|
End Function
|
|
|
|
Private Function AdjustSection(nPartId As Integer) As Boolean
|
|
' Recupero identificativo del primo layer
|
|
Dim nLayerId As Integer = EgtGetFirstLayer(nPartId)
|
|
' Concateno le curve del primo layer
|
|
EgtSelectLayerObjs(nLayerId)
|
|
Dim nCrvIds(0) As Integer
|
|
nCrvIds(0) = GDB_ID.SEL
|
|
Dim nCrvId As Integer = EgtCreateCurveCompoByChain(nLayerId, 1, nCrvIds, New Point3d(), True)
|
|
If nCrvId = GDB_ID.NULL Then Return False
|
|
' Elimino eventuali curve oltre la prima
|
|
Dim nId As Integer = EgtGetNext(nCrvId)
|
|
While nId <> GDB_ID.NULL
|
|
Dim nNextId = EgtGetNext(nId)
|
|
EgtErase(nId)
|
|
nId = nNextId
|
|
End While
|
|
' Verifico se curva piana e ne recupero il piano medio
|
|
Dim vtN As Vector3d
|
|
Dim dDist As Double
|
|
If Not EgtCurveIsFlat(nCrvId, vtN, dDist) Then
|
|
EgtProjectCurveOnPlane(nCrvId, Point3d.ORIG + dDist * vtN, vtN)
|
|
End If
|
|
' Creo layer sezione con riferimento OCS del piano
|
|
Dim frPlane As New Frame3d
|
|
frPlane.Setup(Point3d.ORIG, vtN.Glob(nLayerId))
|
|
Dim nSectLayId As Integer = EgtCreateGroup(nPartId, frPlane, GDB_RT.GLOB)
|
|
EgtSetName(nSectLayId, NAME_SECT)
|
|
EgtRelocateGlob(nCrvId, nSectLayId)
|
|
' Elimino vecchio layer
|
|
EgtErase(nLayerId)
|
|
' Verifico chiusura sezione
|
|
If Not EgtCurveIsClosed(nCrvId) Then
|
|
' Recupero ingombro locale
|
|
Dim b3Box As New BBox3d
|
|
EgtGetBBox(nCrvId, GDB_BB.STANDARD, b3Box)
|
|
' Recupero estremi
|
|
Dim ptStart, ptEnd As Point3d
|
|
EgtStartPoint(nCrvId, ptStart)
|
|
EgtEndPoint(nCrvId, ptEnd)
|
|
' Deve andare da dx a sn
|
|
If ptStart.x < ptEnd.x Then
|
|
EgtInvertCurve(nCrvId)
|
|
Dim ptTmp As Point3d = New Point3d(ptEnd)
|
|
ptEnd = ptStart
|
|
ptStart = ptTmp
|
|
End If
|
|
' Eseguo chiusura
|
|
If ptEnd.y > b3Box.Min().y Then
|
|
EgtAddCurveCompoLine(nCrvId, b3Box.Min())
|
|
End If
|
|
EgtAddCurveCompoLine(nCrvId, New Point3d(b3Box.Max().x, b3Box.Min().y, b3Box.Min().z))
|
|
EgtCloseCurveCompo(nCrvId)
|
|
End If
|
|
Return True
|
|
End Function
|
|
|
|
Private Function InsertPartInRawPart(nPartId As Integer) As Boolean
|
|
' Determino ingombro di eventuali pezzi già presenti
|
|
Dim OtherBox As New BBox3d
|
|
Dim nId2 As Integer = EgtGetFirstPartInRawPart(m_nRawId)
|
|
While nId2 <> GDB_ID.NULL
|
|
Dim TmpBox As New BBox3d
|
|
If EgtGetBBoxGlob(nId2, GDB_BB.IGNORE_TEXT + GDB_BB.IGNORE_DIM, TmpBox) Then
|
|
OtherBox.Add(TmpBox)
|
|
End If
|
|
nId2 = EgtGetNextPartInRawPart(nId2)
|
|
End While
|
|
' Determino distanza da spessore lama
|
|
Dim dMinDist As Double = 0
|
|
Dim dSawThick As Double = 0
|
|
If EgtTdbSetCurrTool(m_MainWindow.m_CurrentMachine.sCurrSaw) AndAlso
|
|
EgtTdbGetCurrToolParam(MCH_TP.THICK, dSawThick) Then
|
|
dMinDist = dSawThick + 10 * EPS_SMALL
|
|
Else
|
|
EgtOutLog("Not found current saw for frames mindist")
|
|
dMinDist = 0
|
|
End If
|
|
' Determino kerf
|
|
Dim dKerf As Double = 0
|
|
EgtGetInfo(m_nRawId, KEY_KERF, dKerf)
|
|
' Inserisco il pezzo nel grezzo
|
|
Dim ptIns As Point3d
|
|
If OtherBox.IsEmpty() Then
|
|
If m_CurrAx = 0 Then
|
|
ptIns.y = dKerf
|
|
Else
|
|
ptIns.x = dKerf
|
|
End If
|
|
Else
|
|
If m_CurrAx = 0 Then
|
|
ptIns.y = OtherBox.Max().y - m_RawBox.Min().y + dMinDist
|
|
Else
|
|
ptIns.x = OtherBox.Max().x - m_RawBox.Min().x + dMinDist
|
|
End If
|
|
End If
|
|
Return EgtAddPartToRawPart(nPartId, ptIns, EgtGetFirstRawPart())
|
|
End Function
|
|
|
|
End Class
|