Files
OmagCUT/NestPageUC.xaml.vb
T
Dario Sassi 62aaa2601a OmagCUT 1.6v4 :
- aggiunta gestione utensili con attrezzaggio manuale e automatico da toolchanger
- corretta gestione interni di componenti
- migliorata gestione grezzo principale sempre di fase 1.
2016-10-24 08:34:50 +00:00

740 lines
30 KiB
VB.net

Imports EgtUILib
Imports EgtWPFLib
Public Class NestPageUC
' Riferimento alla MainWindow
Private m_MainWindow As MainWindow = DirectCast(Application.Current.MainWindow, MainWindow)
Private WithEvents m_CurrProjPage As CurrentProjectPageUC
' Flag di pagina attiva
Private m_bActive As Boolean = False
' Flag per pezzi selezionati in tavola o fuori
Private m_nPartPos As Integer = PART_POS.NONE_TABLE
Enum PART_POS As Integer
IN_TABLE = -1
NONE_TABLE = 0
OUT_TABLE = 1
End Enum
' Identificativi per pezzo da selezionare/deselezionare
Private m_nIdToSel As Integer = GDB_ID.NULL
Private m_nIdToDesel As Integer = GDB_ID.NULL
' Dati del grezzo
Private m_nRawId As Integer = GDB_ID.NULL
Private m_ptRawMin As Point3d
Private m_ptRawMax As Point3d
Private m_dKerf As Double
Private m_dMinDist As Double = 0
' Dati movimento
Private m_dStep As Double = 0
Private m_dMaxStep As Double = 0
Private m_bMaximizeMove As Boolean = False
Private m_dAngStep As Double = 0
Private m_bReducedCut As Boolean = False
' Dati per Drag
Private m_nRestRadius As Integer = 3
Private m_bDrag As Boolean = False
Private m_bDragToStart As Boolean = False
Private m_bDragging As Boolean = False
Private m_locPrev As System.Drawing.Point
Private m_ptPrev As Point3d
Private m_bMagnetic As Boolean = False
Private m_dSnapDist As Double = 0
Private Sub NestPage_Initialized(sender As Object, e As EventArgs)
' Imposto i messaggi letti dal file dei messaggi
InsertPartBtn.Content = EgtMsg(MSG_NESTPAGEUC + 1) 'Insert part - Inserisci pezzo
StorePartBtn.Content = EgtMsg(MSG_NESTPAGEUC + 2) 'Store part - Parcheggia pezzo
RemovePartBtn.Content = EgtMsg(MSG_NESTPAGEUC + 3) 'Remove part - Elimina pezzo
SelectAllBtn.Content = EgtMsg(MSG_NESTPAGEUC + 4) 'Select All - Seleziona Tutto
DeselectAllBtn.Content = EgtMsg(MSG_NESTPAGEUC + 5) 'Deselect All - Deseleziona Tutto
End Sub
Private Sub NestPage_Loaded(sender As Object, e As RoutedEventArgs)
m_CurrProjPage = m_MainWindow.m_CurrentProjectPageUC
m_bActive = True
' recupero dimensioni del grezzo e kerf
CalcRawPart()
' calcolo valore di minima distanza (da spessore lama corrente)
Dim dSawThick As Double = 0
If EgtTdbSetCurrTool(m_MainWindow.m_CurrentMachine.sCurrSaw) AndAlso
EgtTdbGetCurrToolParam(MCH_TP.THICK, dSawThick) Then
m_dMinDist = dSawThick
Else
EgtOutLog("Not found current saw for nesting mindist")
m_dMinDist = 0
End If
' carico e calcolo i parametri di movimento e drag
m_dStep = GetPrivateProfileDouble(S_NEST, K_STEP, 10, m_MainWindow.GetIniFile())
StepMoveTxBx.Text = LenToString(m_dStep, 3)
m_dMaxStep = Math.Max(m_ptRawMax.x - m_ptRawMin.x, m_ptRawMax.y - m_ptRawMin.y)
m_dAngStep = GetPrivateProfileDouble(S_NEST, K_ANGSTEP, 15, m_MainWindow.GetIniFile())
RotationAngleTxBx.Text = DoubleToString(m_dAngStep, 2)
m_nRestRadius = GetPrivateProfileInt(S_NEST, K_RESTRADIUS, 3, m_MainWindow.GetIniFile())
m_dSnapDist = GetPrivateProfileDouble(S_NEST, K_SNAPDIST, 50, m_MainWindow.GetIniFile())
m_bReducedCut = (GetPrivateProfileInt(S_MACH_NEST, K_MACH_REDUCEDCUT, 0, m_MainWindow.GetMachIniFile()) <> 0)
' Garantisco visibilità pezzi parcheggiati
ShowParkedParts()
EgtZoom(ZM.ALL)
End Sub
Public Sub CalcRawPart()
' determino il grezzo (è il primo con fase 1)
m_nRawId = EgtGetFirstRawPart()
While m_nRawId <> GDB_ID.NULL And Not EgtVerifyRawPartPhase(m_nRawId, 1)
m_nRawId = EgtGetNextRawPart(m_nRawId)
End While
' recupero dimensioni del grezzo e kerf
GetRawBox(m_ptRawMin, m_ptRawMax)
EgtGetInfo(m_nRawId, KEY_KERF, m_dKerf)
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
' Per default no drag
m_bDrag = False
' Verifico se selezionato indicativo di pezzo
EgtSetObjFilterForSelWin(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 EgtIsPart(nPartId) Or bPartInTable 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
' Drag possibile
m_bDrag = True
Exit While
End If
nId = EgtGetNextObjInSelWin()
End While
' Dati per drag
m_locPrev = e.Location
m_bDrag = m_bDrag AndAlso EgtUnProjectPoint(e.Location, m_ptPrev)
m_bDragToStart = m_bDrag
End Sub
Private Sub OnMyMouseMoveScene(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles m_CurrProjPage.OnMouseMoveScene
' Verifico di essere il gestore attivo
If Not m_bActive Then Return
' Se drag non abilitato o già in esecuzione, esco
If Not m_bDrag Or m_bDragging Then Return
' Se primo movimento di drag, verifico di aver superato la soglia di movimento in pixel
If m_bDragToStart Then
If Math.Abs(e.Location.X - m_locPrev.X) < m_nRestRadius And
Math.Abs(e.Location.Y - m_locPrev.Y) < m_nRestRadius Then
Return
End If
m_bDragToStart = False
End If
' Determino cosa muovere
Dim nMoveId = If(m_nIdToSel <> GDB_ID.NULL, m_nIdToSel, GDB_ID.SEL)
' Verifico se in tavola
Dim nTestId = If(nMoveId <> GDB_ID.SEL, nMoveId, EgtGetFirstSelectedObj())
If (EgtGetParent(nTestId) <> m_nRawId) Then Return
' Inizio esecuzione di drag
m_bDragging = True
' Ricavo il punto corrente in coordinate mondo
Dim ptCurr As Point3d
EgtUnProjectPoint(e.Location, ptCurr)
' Ricavo il vettore di movimento
Dim vtMove As Vector3d = ptCurr - m_ptPrev
' Muovo i pezzi selezionati di quanto possibile
If vtMove.SqLen() > EPS_SMALL * EPS_SMALL Then
' Aggiorno regioni per nesting
UpdateNestRegions()
EnableReferenceRegion(False)
' muovo il pezzo
EgtMovePart(nMoveId, m_bReducedCut, vtMove)
EgtSaveCollInfo()
' se movimento risultante nullo, provo con movimento tangente
Dim bTgMoved As Boolean = False
If vtMove.IsSmall() Then
' riprovo con movimento tangente
Dim vtTgMove As Vector3d = ptCurr - m_ptPrev
EgtTgMovePartOnCollision(nMoveId, m_bReducedCut, vtTgMove)
bTgMoved = (Not vtTgMove.IsSmall())
End If
' se abilitato magnetico (allineamento + snap), lo provo
Dim bAlignMoved As Boolean = False
Dim bSnapMoved As Boolean = False
If m_bMagnetic Then
EgtAlignPartOnCollision(nMoveId, m_bReducedCut, bAlignMoved)
If m_dSnapDist > EPS_SMALL Then
EgtRestoreCollInfo()
EgtMovePartToSnapPointOnCollision(nMoveId, m_bReducedCut, m_dSnapDist, bSnapMoved)
End If
End If
EgtDraw()
m_CurrProjPage.ResetOrderMachiningFlag()
' Eventuale notifica al VeinMatching
If nMoveId = GDB_ID.SEL Then
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
VeinMatching.OnMovePartInRaw(nId)
nId = EgtGetNextSelectedObj()
End While
Else
VeinMatching.OnMovePartInRaw(nMoveId)
End If
End If
' Aggiorno il punto precedente
'm_ptPrev += vtMove
m_ptPrev = ptCurr
' Terminata esecuzione di drag
m_bDragging = False
End Sub
Private Sub OnMyMouseUpScene(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles m_CurrProjPage.OnMouseUpScene
' Verifico di essere il gestore attivo
If Not m_bActive Then
Return
End If
' Se eseguito drag
If Not m_bDragToStart Then
' Basta reset alla fine
' Se selezione da eseguire
ElseIf m_nIdToSel <> GDB_ID.NULL Then
' Determino se pezzo in tavola o in parcheggio
Dim bPartInTable As Boolean = (EgtGetParent(m_nIdToSel) = m_nRawId)
' Se ci sono pezzi già selezionati nella posizione opposta, li deseleziono
If (bPartInTable And m_nPartPos = PART_POS.OUT_TABLE) Or
(Not bPartInTable And m_nPartPos = PART_POS.IN_TABLE) Then
EgtDeselectAll()
End If
' Eseguo la selezione
EgtSelectObj(m_nIdToSel)
' Set flag posizione selezionati
m_nPartPos = If(bPartInTable, PART_POS.IN_TABLE, PART_POS.OUT_TABLE)
' Se deselezione da eseguire
ElseIf m_nIdToDesel <> GDB_ID.NULL Then
EgtDeselectObj(m_nIdToDesel)
End If
' Reset
m_bDrag = False
m_nIdToSel = GDB_ID.NULL
m_nIdToDesel = GDB_ID.NULL
' Se nessun pezzo selezionato, reset flag posizione selezionati
If EgtGetSelectedObjCount() = 0 Then
m_nPartPos = PART_POS.NONE_TABLE
End If
EgtDraw()
End Sub
Private Sub MaximizeMoveBtn_Click(sender As Object, e As RoutedEventArgs) Handles MaximizeMoveBtn.Click
If MaximizeMoveBtn.IsChecked() Then
m_bMaximizeMove = True
Else
m_bMaximizeMove = False
End If
End Sub
Private Sub UpBtn_Click(sender As Object, e As RoutedEventArgs) Handles UpBtn.Click
EgtSetCurrentContext(m_CurrProjPage.CurrentProjectScene.GetCtx())
' Aggiorno regioni per nesting
UpdateNestRegions()
EnableReferenceRegion(False)
' eseguo movimento
Dim dStep As Double = If(m_bMaximizeMove, m_dMaxStep, m_dStep)
EgtMovePart(GDB_ID.SEL, m_bReducedCut, New Vector3d(0, dStep, 0))
EgtSaveCollInfo()
' se abilitato magnetico (allineamento + snap), lo provo
Dim bAlignMoved As Boolean = False
Dim bSnapMoved As Boolean = False
If m_bMagnetic Then
EgtAlignPartOnCollision(GDB_ID.SEL, m_bReducedCut, bAlignMoved)
If m_dSnapDist > EPS_SMALL Then
EgtRestoreCollInfo()
EgtMovePartToSnapPointOnCollision(GDB_ID.SEL, m_bReducedCut, m_dSnapDist, bSnapMoved)
End If
End If
m_CurrProjPage.ResetOrderMachiningFlag()
EgtDraw()
' Eventuale notifica al VeinMatching
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
VeinMatching.OnMovePartInRaw(nId)
nId = EgtGetNextSelectedObj()
End While
End Sub
Private Sub DownBtn_Click(sender As Object, e As RoutedEventArgs) Handles DownBtn.Click
EgtSetCurrentContext(m_CurrProjPage.CurrentProjectScene.GetCtx())
' Aggiorno regioni per nesting
UpdateNestRegions()
EnableReferenceRegion(False)
' eseguo movimento
Dim dStep As Double = If(m_bMaximizeMove, m_dMaxStep, m_dStep)
EgtMovePart(GDB_ID.SEL, m_bReducedCut, New Vector3d(0, -dStep, 0))
EgtSaveCollInfo()
' se abilitato magnetico (allineamento + snap), lo provo
Dim bAlignMoved As Boolean = False
Dim bSnapMoved As Boolean = False
If m_bMagnetic Then
EgtAlignPartOnCollision(GDB_ID.SEL, m_bReducedCut, bAlignMoved)
If m_dSnapDist > EPS_SMALL Then
EgtRestoreCollInfo()
EgtMovePartToSnapPointOnCollision(GDB_ID.SEL, m_bReducedCut, m_dSnapDist, bSnapMoved)
End If
End If
m_CurrProjPage.ResetOrderMachiningFlag()
EgtDraw()
' Eventuale notifica al VeinMatching
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
VeinMatching.OnMovePartInRaw(nId)
nId = EgtGetNextSelectedObj()
End While
End Sub
Private Sub RightBtn_Click(sender As Object, e As RoutedEventArgs) Handles RightBtn.Click
EgtSetCurrentContext(m_CurrProjPage.CurrentProjectScene.GetCtx())
' Aggiorno regioni per nesting
UpdateNestRegions()
EnableReferenceRegion(False)
' eseguo movimento
Dim dStep As Double = If(m_bMaximizeMove, m_dMaxStep, m_dStep)
EgtMovePart(GDB_ID.SEL, m_bReducedCut, New Vector3d(dStep, 0, 0))
EgtSaveCollInfo()
' se abilitato magnetico (allineamento + snap), lo provo
Dim bAlignMoved As Boolean = False
Dim bSnapMoved As Boolean = False
If m_bMagnetic Then
EgtAlignPartOnCollision(GDB_ID.SEL, m_bReducedCut, bAlignMoved)
If m_dSnapDist > EPS_SMALL Then
EgtRestoreCollInfo()
EgtMovePartToSnapPointOnCollision(GDB_ID.SEL, m_bReducedCut, m_dSnapDist, bSnapMoved)
End If
End If
m_CurrProjPage.ResetOrderMachiningFlag()
EgtDraw()
' Eventuale notifica al VeinMatching
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
VeinMatching.OnMovePartInRaw(nId)
nId = EgtGetNextSelectedObj()
End While
End Sub
Private Sub LeftBtn_Click(sender As Object, e As RoutedEventArgs) Handles LeftBtn.Click
EgtSetCurrentContext(m_CurrProjPage.CurrentProjectScene.GetCtx())
' Aggiorno regioni per nesting
UpdateNestRegions()
EnableReferenceRegion(False)
' eseguo movimento
Dim dStep As Double = If(m_bMaximizeMove, m_dMaxStep, m_dStep)
EgtMovePart(GDB_ID.SEL, m_bReducedCut, New Vector3d(-dStep, 0, 0))
EgtSaveCollInfo()
' se abilitato magnetico (allineamento + snap), lo provo
Dim bAlignMoved As Boolean = False
Dim bSnapMoved As Boolean = False
If m_bMagnetic Then
EgtAlignPartOnCollision(GDB_ID.SEL, m_bReducedCut, bAlignMoved)
If m_dSnapDist > EPS_SMALL Then
EgtRestoreCollInfo()
EgtMovePartToSnapPointOnCollision(GDB_ID.SEL, m_bReducedCut, m_dSnapDist, bSnapMoved)
End If
End If
m_CurrProjPage.ResetOrderMachiningFlag()
EgtDraw()
' Eventuale notifica al VeinMatching
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
VeinMatching.OnMovePartInRaw(nId)
nId = EgtGetNextSelectedObj()
End While
End Sub
Private Sub RotateCounterClockwiseBtn_Click(sender As Object, e As RoutedEventArgs) Handles RotateCounterClockwiseBtn.Click
EgtSetCurrentContext(m_CurrProjPage.CurrentProjectScene.GetCtx())
RotateCluster(m_dAngStep)
m_CurrProjPage.ResetOrderMachiningFlag()
EgtDraw()
' Eventuale notifica al VeinMatching
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
VeinMatching.OnMovePartInRaw(nId)
nId = EgtGetNextSelectedObj()
End While
End Sub
Private Sub RotateClockwiseBtn_Click(sender As Object, e As RoutedEventArgs) Handles RotateClockwiseBtn.Click
EgtSetCurrentContext(m_CurrProjPage.CurrentProjectScene.GetCtx())
RotateCluster(-m_dAngStep)
m_CurrProjPage.ResetOrderMachiningFlag()
EgtDraw()
' Eventuale notifica al VeinMatching
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
VeinMatching.OnMovePartInRaw(nId)
nId = EgtGetNextSelectedObj()
End While
End Sub
Private Function RotateCluster(ByVal dAngRotDeg As Double) As Boolean
' Se non ci sono pezzi selezionati, esco
If EgtGetSelectedObjCount() = 0 Then
Return True
End If
' Calcolo il centro di rotazione come centro del cluster
Dim ptCen As Point3d
If Not EgtGetPartPartClusterCenterGlob(GDB_ID.SEL, ptCen) Then
Return False
End If
' Se pezzi in parcheggio, li ruoto liberamente e li risistemo (sempre possibile)
If m_nPartPos <> PART_POS.IN_TABLE Then
' Rotazione dei pezzi attorno al loro centro
EgtRotate(GDB_ID.SEL, ptCen, Vector3d.Z_AX(), dAngRotDeg, GDB_RT.GLOB)
' Sistemazione nel parcheggio
PackPartInStore(GDB_ID.SEL)
Return True
' Altrimenti li ruoto tenendo conto delle collisioni
Else
' Aggiorno regioni per nesting
UpdateNestRegions()
EnableReferenceRegion(False)
Return EgtRotatePart(GDB_ID.SEL, m_bReducedCut, ptCen, dAngRotDeg)
End If
End Function
Private Sub InsertPartBtn_Click(sender As Object, e As RoutedEventArgs) Handles InsertPartBtn.Click
EgtSetCurrentContext(m_CurrProjPage.CurrentProjectScene.GetCtx())
' Ciclo di inserimento in tavola dei pezzi selezionati
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
' Recupero successivo selezionato
Dim nNextId = EgtGetNextSelectedObj()
' Lo metto in tavola, se possibile
InsertOnePart(nId)
' Costringo ad aggiornare UI
UpdateUI()
' Passo al successivo selezionato
nId = nNextId
End While
' Aggiorno flag selezionati
m_nPartPos = If(EgtGetSelectedObjCount() > 0, PART_POS.IN_TABLE, PART_POS.NONE_TABLE)
' Aggiorno vista
EgtZoom(ZM.ALL)
End Sub
Public Function InsertOnePart(ByVal nId As Integer) As Boolean
' Se esiste grezzo e pezzo in parcheggio, lo metto nella tavola
If m_nRawId <> GDB_ID.NULL AndAlso EgtIsPart(nId) Then
' Sistemazioni per eventuali lati esterni inclinati
EgtCalcFlatPartDownRegion(nId, m_ptRawMax.z - m_ptRawMin.z)
' Dimensioni del pezzo
Dim ptPartMin, ptPartMax As Point3d
If Not EgtGetBBox(nId, GDB_BB.IGNORE_DIM + GDB_BB.IGNORE_TEXT, ptPartMin, ptPartMax) Then Return False
Dim dPartLen As Double = ptPartMax.x - ptPartMin.x
Dim dPartHeight As Double = ptPartMax.y - ptPartMin.y
' Centro del grezzo
Dim nRawCenId = EgtGetFirstNameInGroup(m_nRawId, "RawCenter")
Dim ptRawCenter As Point3d
EgtStartPoint(nRawCenId, GDB_ID.ROOT, ptRawCenter)
Dim dRawCenX = ptRawCenter.x - m_ptRawMin.x
Dim dRawCenY = ptRawCenter.y - m_ptRawMin.y
' Inserisco il pezzo nel grezzo, in centro in XY e in alto in Z
Dim ptP As New Point3d(dRawCenX - 0.5 * dPartLen, dRawCenY - 0.5 * dPartHeight, m_ptRawMax.z - m_ptRawMin.z)
If EgtAddPartToRawPart(nId, ptP, m_nRawId) Then
' Aggiungo le lavorazioni standard
AddMachinings(nId, True, False)
' Eseguo nesting
Dim bFit As Boolean = False
If UpdateNestRegions() Then
Dim bAligned As Boolean = (GetPrivateProfileInt(S_MACH_NEST, K_MACH_NEST_ALIGNED, 0, m_MainWindow.GetMachIniFile()) <> 0)
EnableReferenceRegion(bAligned)
If Not EgtExistsInfo(m_nRawId, KEY_RAWBYPOINTS) Then
bFit = EgtPackPartInRectangle(nId, m_bReducedCut, True)
End If
If Not bFit Then
bFit = EgtPackPart(nId, m_bReducedCut, True)
End If
End If
' Gestione risultato nesting
If bFit Then
' Eventuale notifica al VeinMatching
VeinMatching.OnInsertPartInRaw(nId)
Return True
Else
EraseMachinings(nId)
EgtRemovePartFromRawPart(nId)
EgtSetStatus(nId, GDB_ST.ON_)
End If
End If
End If
Return False
End Function
Private Sub SetAllPreviewsStatus(bShow As Boolean)
Dim nPartId = EgtGetFirstPartInRawPart(m_nRawId)
While nPartId <> GDB_ID.NULL
' Recupero il layer preview del pezzo e ne imposto lo stato di visualizzazione
Dim nPvId As Integer = EgtGetFirstNameInGroup(nPartId, NAME_PREVIEW)
EgtSetStatus(nPvId, If(bShow, GDB_ST.ON_, GDB_ST.OFF))
' Passo al pezzo successivo
nPartId = EgtGetNextPartInRawPart(nPartId)
End While
End Sub
Private Sub StorePartBtn_Click(sender As Object, e As RoutedEventArgs) Handles StorePartBtn.Click
EgtSetCurrentContext(m_CurrProjPage.CurrentProjectScene.GetCtx())
' Ciclo di parcheggio dei pezzi selezionati
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
' Recupero indice del successivo
Dim nNextId = EgtGetNextSelectedObj()
' Metto in parcheggio, se in grezzo
StoreOnePart(nId)
' Eventuale notifica al VeinMatching
VeinMatching.OnRemovePartFromRaw(nId)
' Passo al successivo selezionato
nId = nNextId
End While
' Imposto flag posizione pezzi su parcheggio
m_nPartPos = PART_POS.OUT_TABLE
' Aggiorno vista
EgtZoom(ZM.ALL)
End Sub
Public Function StoreOnePart(ByVal nId As Integer, Optional ByVal bForced As Boolean = False) As Boolean
' Se pezzo in grezzo, metto in parcheggio (sempre possibile)
If bForced OrElse
(m_nRawId <> GDB_ID.NULL AndAlso EgtGetParent(nId) = m_nRawId) Then
' Rimuovo le lavorazioni
EraseMachinings(nId)
' Elimino eventuali modifiche per lati esterni inclinati
EgtCalcFlatPartDownRegion(nId, 0)
' Parcheggio
EgtRemovePartFromRawPart(nId)
EgtSetStatus(nId, GDB_ST.ON_)
PackPartInStore(nId)
' Aggiusto la posizione in Z
Dim ptPartMin, ptPartMax As Point3d
If EgtGetBBoxGlob(nId, GDB_BB.IGNORE_DIM + GDB_BB.IGNORE_TEXT, ptPartMin, ptPartMax) Then
EgtMove(nId, New Vector3d(0, 0, m_ptRawMax.z - ptPartMax.z), GDB_RT.GLOB)
End If
Return True
End If
Return False
End Function
Private Function PackPartInStore(nId As Integer) As Boolean
' Recupero box tavola
Dim b3Tab As New BBox3d
If Not EgtGetTableArea(1, b3Tab) Then
b3Tab.Add(New Point3d(0, 0, 0))
b3Tab.Add(New Point3d(-3600, -2600, 0))
End If
' Parcheggio
Const STORE_LARGH As Double = 6000
Const STORE_DIST As Double = 200
Const STORE_OFFS As Double = 20
Dim dStXmin As Double = b3Tab.Min().x - 0.5 * (STORE_LARGH - b3Tab.DimX())
Return EgtPackBox(nId, dStXmin, -INFINITO, dStXmin + STORE_LARGH, b3Tab.Min().y - STORE_DIST, STORE_OFFS, False)
End Function
Private Sub RemovePartBtn_Click(sender As Object, e As RoutedEventArgs) Handles RemovePartBtn.Click
EgtSetCurrentContext(m_CurrProjPage.CurrentProjectScene.GetCtx())
' Verifico se ci sono pezzi provenienti da liste Csv
Dim bCsvParts As Boolean = False
Dim nId As Integer = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
If EgtExistsInfo(nId, INFO_CSV_PATH) Then
bCsvParts = True
Exit While
End If
nId = EgtGetNextSelectedObj()
End While
' Chiedo se si vogliono cancellare anche questi pezzi
Dim bEraseCsvParts As Boolean = False
If bCsvParts Then
' Vuoi cancellare anche i pezzi da lista Csv ?
Dim EraseCsvParts As New EgtMsgBox(m_MainWindow, "", EgtMsg(MSG_EGTMSGBOX + 12),
EgtMsgBox.Buttons.YES_NO_CANCEL, EgtMsgBox.Icons.NULL)
Select Case EraseCsvParts.DialogResult
Case 0 ' Annulla
Return
Case 1 ' Si
bEraseCsvParts = True
Case 2 ' No
bEraseCsvParts = False
End Select
End If
' Ciclo di cancellazione dei pezzi selezionati
nId = EgtGetFirstSelectedObj()
While nId <> GDB_ID.NULL
' Recupero indice del successivo
Dim nNextId = EgtGetNextSelectedObj()
' Se abilitata cancellazione in ogni caso o pezzo non da Csv
If bEraseCsvParts OrElse Not EgtExistsInfo(nId, INFO_CSV_PATH) Then
' Se pezzo in parcheggio cancello direttamente
If EgtIsPart(nId) Then
' Rimuovo le lavorazioni
EraseMachinings(nId)
' Cancello
EgtErase(nId)
' Altrimenti pezzo nel grezzo
ElseIf EgtGetParent(nId) = m_nRawId Then
If EgtRemovePartFromRawPart(nId) Then
' Eventuale notifica al VeinMatching
VeinMatching.OnRemovePartFromRaw(nId)
' Rimuovo le lavorazioni
EraseMachinings(nId)
'Cancello
EgtErase(nId)
End If
End If
End If
' Passo al successivo selezionato
nId = nNextId
End While
' Imposto flag posizione pezzi
m_nPartPos = PART_POS.NONE_TABLE
' Aggiorno vista
EgtZoom(ZM.ALL)
End Sub
Private Sub SelectAllBtn_Click(sender As Object, e As RoutedEventArgs) Handles SelectAllBtn.Click
EgtSetCurrentContext(m_CurrProjPage.CurrentProjectScene.GetCtx())
' Se già selezionati in tavola o non ci sono selezionati
If m_nPartPos = PART_POS.IN_TABLE Or m_nPartPos = PART_POS.NONE_TABLE Then
' Seleziono tutti i pezzi in tavola
Dim nPartId As Integer = EgtGetFirstGroupInGroup(m_nRawId)
While nPartId <> GDB_ID.NULL
EgtSetStatus(nPartId, GDB_ST.SEL)
nPartId = EgtGetNextGroup(nPartId)
End While
' Aggiorno flag
m_nPartPos = If(EgtGetSelectedObjCount() > 0, PART_POS.IN_TABLE, PART_POS.NONE_TABLE)
' Se già selezionati in parcheggio
ElseIf m_nPartPos = PART_POS.OUT_TABLE Then
' Seleziono tutti i pezzi in parcheggio
Dim nPartId As Integer = EgtGetFirstPart()
While nPartId <> GDB_ID.NULL
EgtSetStatus(nPartId, GDB_ST.SEL)
nPartId = EgtGetNextPart(nPartId)
End While
End If
' Aggiorno vista
EgtDraw()
End Sub
Private Sub DeselectAllBtn_Click(sender As Object, e As RoutedEventArgs) Handles DeselectAllBtn.Click
EgtSetCurrentContext(m_CurrProjPage.CurrentProjectScene.GetCtx())
' Eseguo
EgtDeselectAll()
' Imposto flag posizione pezzi
m_nPartPos = PART_POS.NONE_TABLE
' Aggiorno vista
EgtDraw()
End Sub
Private Sub StepMoveTxBx_EgtClosed(sender As Object, e As EventArgs) Handles StepMoveTxBx.EgtClosed
Dim dStep As Double
If StringToLen(StepMoveTxBx.Text, dStep) Then
m_dStep = Math.Max(dStep, 2 * EPS_SMALL)
End If
End Sub
Private Sub RotationAngleTxBx_EgtClosed(sender As Object, e As EventArgs) Handles RotationAngleTxBx.EgtClosed
Dim dAngStep As Double
If StringToDouble(RotationAngleTxBx.Text, dAngStep) Then
m_dAngStep = Math.Max(dAngStep, 50 * EPS_ANG_SMALL)
End If
End Sub
Private Sub NestPage_Unloaded(sender As Object, e As RoutedEventArgs)
m_bActive = False
m_MainWindow.m_CadCutPageUC.m_ProjectMgr.VeinMatchingHide()
End Sub
Private Sub MagneticPiecesBtn_Click(sender As Object, e As RoutedEventArgs) Handles MagneticPiecesBtn.Click
If MagneticPiecesBtn.IsChecked() Then
m_bMagnetic = True
Else
m_bMagnetic = False
End If
End Sub
Friend Function VerifyPartsNesting(bReducedCut As Boolean) As Boolean
' Aggiorno regioni per nesting
UpdateNestRegions()
EnableReferenceRegion(False)
' Ciclo su tutti i pezzi in tavola
Dim nPartId As Integer = EgtGetFirstGroupInGroup(m_nRawId)
While nPartId <> GDB_ID.NULL
If Not EgtVerifyPart(nPartId, bReducedCut) Then
Return False
End If
nPartId = EgtGetNextGroup(nPartId)
End While
Return True
End Function
Friend Function StoreCollisionParts(bReducedCut As Boolean) As Boolean
' Aggiorno regioni per nesting
UpdateNestRegions()
EnableReferenceRegion(False)
' Ciclo su tutti i pezzi in tavola (dall'ultimo)
Dim nPartId As Integer = EgtGetLastGroupInGroup(m_nRawId)
While nPartId <> GDB_ID.NULL
Dim nPrevPartId As Integer = EgtGetPrevGroup(nPartId)
If Not EgtVerifyPart(nPartId, bReducedCut) Then
StoreOnePart(nPartId, True)
End If
nPartId = nPrevPartId
End While
Return True
End Function
Friend Function UpdateNestRegions() As Boolean
' Se necessario, creo la regione fuori kerf
Dim nKerfId As Integer = EgtGetFirstNameInGroup(m_CurrProjPage.m_nRawId, NAME_KERF)
EgtCreateOutRegion(m_CurrProjPage.m_nRawId, nKerfId)
' Se necessario, creo la regione di riferimento
EgtCreateReferenceRegion(m_CurrProjPage.m_nRawId, nKerfId, True)
' Se necessario, creo le regioni per le aree danneggiate
Dim nId As Integer = EgtGetFirstNameInGroup(m_CurrProjPage.m_nRawId, NAME_DAMAGED)
While nId <> GDB_ID.NULL
EgtCreateDamagedRegion(m_CurrProjPage.m_nRawId, nId)
nId = EgtGetNextName(nId, NAME_DAMAGED)
End While
Return True
End Function
Friend Function EnableReferenceRegion(bEnable As Boolean) As Boolean
' Recupero identificativo della regione di riferimento
Dim nRegId As Integer = EgtGetFirstNameInGroup(m_CurrProjPage.m_nRawId, NAME_REF_REG)
If nRegId = GDB_ID.NULL Then Return False
' Imposto l'abilitazione voluta
If bEnable Then
EgtRemoveInfo(nRegId, KEY_REF_REG_OFF)
Else
EgtSetInfo(nRegId, KEY_REF_REG_OFF, 1)
End If
Return True
End Function
End Class