d0c9e02e13
- migliorie e correzione in movimento grezzi con ventose.
704 lines
29 KiB
VB.net
704 lines
29 KiB
VB.net
Imports EgtUILib
|
|
|
|
Public Class MoveRawPartPage
|
|
' Riferimento alla MainWindow
|
|
Private m_MainWindow As MainWindow = Application.Current.MainWindow
|
|
Private WithEvents m_CurrProjPage As CurrentProjectPageUC
|
|
' Flag di pagina attiva
|
|
Private m_bActive As Boolean = False
|
|
' Fase corrente
|
|
Private m_nCurrPhase As Integer = 0
|
|
' Dati movimento
|
|
Private m_dStep As Double = 0
|
|
' Tipo manipolatore con ventosa
|
|
Private m_nVacType As Integer = 0
|
|
' Tipo movimento dei grezzi (manuale o con testa ventosa)
|
|
Private m_bByHand As Boolean = True
|
|
' Gestione movimento manuale perpendicolare
|
|
Private m_vtDir As New Vector3d ' direzione di movimento
|
|
Private m_ptMid As New Point3d ' punto medio del taglio
|
|
Private m_dOrigDist As Double = 0 ' distanza iniziale (spessore taglio)
|
|
Private m_dCurrDist As Double = 0 ' distanza corrente
|
|
' Gestione movimento con ventose
|
|
Private m_nTempId As Integer = GDB_ID.NULL
|
|
Private m_nVacId As Integer = GDB_ID.NULL
|
|
Private m_nRefId As Integer = GDB_ID.NULL
|
|
Private m_RawPartDataList As New List(Of RawPartData)
|
|
Private m_ptTabCen As New Point3d
|
|
|
|
Private Sub MoveRawPartPage_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized
|
|
PrevBtn.IsEnabled = False
|
|
' Assegno testi
|
|
RemovePartBtn.Content = EgtMsg(MSG_MOVERAWPAGEUC + 1) 'Rimuovi
|
|
End Sub
|
|
|
|
Private Sub MoveRawPartPage_Loaded(sender As Object, e As EventArgs) Handles Me.Loaded
|
|
m_CurrProjPage = m_MainWindow.m_CurrentProjectPageUC
|
|
m_bActive = True
|
|
' Leggo tipo manipolatore con ventosa
|
|
' (0=assente, 1=dietro, 2=laterale esterno, 3= laterale interno)
|
|
m_nVacType = 0
|
|
EgtGetInfo(EgtGetHeadId(VACUUM_HEAD), "VacType", m_nVacType)
|
|
' Leggo tipo movimento grezzi
|
|
m_bByHand = (m_nVacType = 0 Or
|
|
(GetPrivateProfileInt(S_RAWMOVE, K_PERPENDICULAR, 0, m_MainWindow.GetIniFile()) <> 0))
|
|
' Deseleziono tutto
|
|
EgtDeselectAll()
|
|
' Recupero i tagli allungati prima definiti
|
|
Dim Cuts(0) As Integer
|
|
m_MainWindow.m_CadCutPageUC.m_SplitPage.GetSplitCuts(Cuts)
|
|
' Aggiorno preview di questi tagli lasciandoli nella lavorazione
|
|
For Each nCut As Integer In Cuts
|
|
UpdateMachiningPreview(nCut, False)
|
|
Next
|
|
' Fase precedente
|
|
Dim nPrevPhase As Integer = EgtGetCurrPhase()
|
|
' Creo nuova fase
|
|
m_nCurrPhase = EgtAddPhase()
|
|
' Origine della tavola
|
|
Dim ptOri As Point3d
|
|
EgtGetTableRef(1, ptOri)
|
|
Dim vtOri As New Vector3d(ptOri.x, ptOri.y, ptOri.z)
|
|
' Centro della tavola
|
|
Dim b3Tab As New BBox3d
|
|
EgtGetTableArea(1, b3Tab)
|
|
m_ptTabCen = b3Tab.Center()
|
|
' Se non ci sono tagli allungati, confermo i grezzi
|
|
If Cuts.Length() = 0 Then
|
|
' Ciclo sui grezzi
|
|
Dim nRawId As Integer = EgtGetFirstRawPart()
|
|
While nRawId <> GDB_ID.NULL
|
|
If EgtVerifyRawPartPhase(nRawId, nPrevPhase) Then
|
|
' Confermo il grezzo
|
|
EgtKeepRawPart(nRawId)
|
|
' Fisso posizione del grezzo
|
|
Dim ptMin, ptMax As Point3d
|
|
GetRawBox(nRawId, ptMin, ptMax)
|
|
EgtMoveToCornerRawPart(nRawId, ptMin - vtOri, MCH_CR.BL)
|
|
End If
|
|
nRawId = EgtGetNextRawPart(nRawId)
|
|
End While
|
|
' Altrimenti eseguo eventuali spezzature dei grezzi e vi sposto i pezzi
|
|
Else
|
|
' eseguo spezzature
|
|
Dim nRawId As Integer = EgtGetFirstRawPart()
|
|
While nRawId <> GDB_ID.NULL
|
|
' se il grezzo è presente nella fase precedente
|
|
If EgtVerifyRawPartPhase(nRawId, nPrevPhase) Then
|
|
' Calcolo nuovi grezzi
|
|
Dim nRaw1Id = EgtSplitFlatRawPartWithMachinings(nRawId, Cuts)
|
|
' Fisso posizione dei nuovi grezzi
|
|
Dim nNewRawId = nRaw1Id
|
|
While nNewRawId <> GDB_ID.NULL
|
|
Dim ptMin, ptMax As Point3d
|
|
GetRawBox(nNewRawId, ptMin, ptMax)
|
|
EgtMoveToCornerRawPart(nNewRawId, ptMin - vtOri, MCH_CR.BL)
|
|
nNewRawId = EgtGetNextRawPart(nNewRawId)
|
|
End While
|
|
' Assegno ai nuovi grezzi eventuale texture del grezzo originale
|
|
Dim nSolidId = EgtGetFirstNameInGroup(nRawId, NAME_RAW_SOLID)
|
|
Dim nameTxr As String = String.Empty
|
|
If EgtGetTextureName(nSolidId, nameTxr) Then
|
|
Dim refTxr As New Frame3d
|
|
EgtGetTextureFrame(nSolidId, GDB_ID.ROOT, refTxr)
|
|
nNewRawId = nRaw1Id
|
|
While nNewRawId <> GDB_ID.NULL
|
|
' Carico la texture sul nuovo grezzo
|
|
Dim nNewSolidId = EgtGetFirstNameInGroup(nNewRawId, NAME_RAW_SOLID)
|
|
EgtSetTextureName(nNewSolidId, nameTxr)
|
|
' Sistemo il riferimento della texture
|
|
EgtSetTextureFrame(nNewSolidId, refTxr, GDB_RT.GLOB)
|
|
' Passo al grezzo successivo
|
|
nNewRawId = EgtGetNextRawPart(nNewRawId)
|
|
End While
|
|
End If
|
|
End If
|
|
' passo al successivo grezzo
|
|
nRawId = EgtGetNextRawPart(nRawId)
|
|
End While
|
|
End If
|
|
' Cancello preview dei tagli allungati dalla lavorazione
|
|
For Each nCut As Integer In Cuts
|
|
RemoveMachiningPreview(nCut)
|
|
Next
|
|
' Sposto tutte le lavorazioni disabilitate e le eventuali inglobate nella nuova fase
|
|
Dim nId = EgtGetFirstOperation()
|
|
While nId <> GDB_ID.NULL
|
|
Dim nNextId = EgtGetNextOperation(nId)
|
|
If IsValidMachining(nId) And EgtGetOperationPhase(nId) = m_nCurrPhase - 1 And EgtExistsInfo(nId, INFO_MCH_USER_OFF) Then
|
|
' sposto la lavorazione
|
|
EgtChangeOperationPhase(nId, m_nCurrPhase)
|
|
' sposto le inglobate
|
|
Dim sInfo As String = String.Empty
|
|
If EgtGetInfo(nId, INFO_MCH_OTHMID, sInfo) Then
|
|
Dim sItems() As String = sInfo.Split(",".ToCharArray)
|
|
For Each sId In sItems
|
|
EgtChangeOperationPhase(CInt(sId), m_nCurrPhase)
|
|
Next
|
|
End If
|
|
End If
|
|
nId = nNextId
|
|
End While
|
|
' Aggiorno visualizzazione
|
|
EgtDraw()
|
|
' Carico i parametri di movimento
|
|
m_dStep = GetPrivateProfileDouble(S_RAWMOVE, K_RAWSTEP, 50, m_MainWindow.GetIniFile())
|
|
StepMoveTxBx.Text = LenToString(m_dStep, 3)
|
|
' Se movimento manuale perpendicolare
|
|
If m_bByHand Then
|
|
' Se esiste taglio passante determino direzione di movimento
|
|
If Cuts.Length() > 0 Then
|
|
' recupero taglio di separazione
|
|
Dim nCutId As Integer = Cuts(0)
|
|
' recupero linea di base del taglio
|
|
EgtSetCurrMachining(nCutId)
|
|
' Recupero la prima entità geometrica della lavorazione
|
|
Dim nEntId, nSub As Integer
|
|
If EgtGetMachiningGeometry(0, nEntId, nSub) Then
|
|
' Direzione perpendicolare al taglio
|
|
EgtStartVector(nEntId, GDB_ID.ROOT, m_vtDir)
|
|
m_vtDir.Rotate(Vector3d.Z_AX(), 90)
|
|
' Punto medio del taglio
|
|
EgtMidPoint(nEntId, GDB_ID.ROOT, m_ptMid)
|
|
' Recupero il preview della lavorazione
|
|
Dim nPvId As Integer = GDB_ID.NULL
|
|
EgtGetInfo(EgtGetFirstNameInGroup(nCutId, NAME_PREVIEW), INFO_PV_ONPART_ID, nPvId)
|
|
' Recupero la larghezza del taglio
|
|
Dim nGrpId As Integer = EgtGetFirstGroupInGroup(nPvId)
|
|
If Not EgtGetInfo(nGrpId, "WT", m_dOrigDist) Then
|
|
m_dOrigDist = 4
|
|
End If
|
|
' Distanza iniziale
|
|
m_dCurrDist = 0
|
|
End If
|
|
' Non dovrebbe mai accadere, ma inizializzo con default
|
|
Else
|
|
m_vtDir = Vector3d.Y_AX()
|
|
m_ptMid = Point3d.ORIG()
|
|
m_dOrigDist = 0
|
|
m_dCurrDist = 0
|
|
End If
|
|
' Altrimenti movimento con ventose
|
|
Else
|
|
' Pulisco lista info per grezzi
|
|
m_RawPartDataList.Clear()
|
|
m_RawPartDataList.Capacity() = 10
|
|
End If
|
|
' Aggiorno interfaccia per taglio perpendicolare
|
|
If m_bByHand Then
|
|
LeftBtn.Visibility = Windows.Visibility.Hidden
|
|
RightBtn.Visibility = Windows.Visibility.Hidden
|
|
RemovePartBtn.Visibility = Windows.Visibility.Visible
|
|
' Altrimeni per movimento con ventose
|
|
Else
|
|
LeftBtn.Visibility = Windows.Visibility.Visible
|
|
RightBtn.Visibility = Windows.Visibility.Visible
|
|
RemovePartBtn.Visibility = Windows.Visibility.Hidden
|
|
End If
|
|
|
|
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
|
|
' Gruppo dei grezzi
|
|
Dim nRawGroupId = EgtGetParent(EgtGetFirstRawPart())
|
|
' Verifico se selezionato indicativo di grezzo attivo
|
|
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
|
|
' Cerco l'identificativo del grezzo cui appartiene
|
|
Dim nParentId = EgtGetParent(nId)
|
|
While nParentId <> GDB_ID.NULL And nParentId <> nRawGroupId
|
|
nId = nParentId
|
|
nParentId = EgtGetParent(nId)
|
|
End While
|
|
' Se trovato il grezzo
|
|
If nParentId = nRawGroupId Then
|
|
Dim nStat As Integer = GDB_ST.ON_
|
|
EgtGetStatus(nId, nStat)
|
|
If nStat = GDB_ST.SEL Then
|
|
EgtSetStatus(nId, GDB_ST.ON_)
|
|
' Se con ventose, le nascondo
|
|
If Not m_bByHand Then EgtSetStatus(m_nVacId, GDB_ST.OFF)
|
|
Else
|
|
EgtDeselectAll()
|
|
EgtSetStatus(nId, GDB_ST.SEL)
|
|
' Se con ventose le posiziono sul grezzo
|
|
If Not m_bByHand Then PutVacuumCupsOnRaw(nId)
|
|
End If
|
|
EgtDraw()
|
|
Exit While
|
|
End If
|
|
nId = EgtGetNextObjInSelWin()
|
|
End While
|
|
End Sub
|
|
|
|
Private Sub UpBtn_Click(sender As Object, e As RoutedEventArgs) Handles UpBtn.Click
|
|
Dim nRawId As Integer = EgtGetFirstSelectedObj()
|
|
While nRawId <> GDB_ID.NULL
|
|
' Se movimento perpendicolare, è allontanamento
|
|
If m_bByHand Then
|
|
' Recupero il centro del grezzo
|
|
Dim ptRawCen As Point3d
|
|
GetRawCenter(nRawId, ptRawCen)
|
|
' Calcolo la distanza di movimento
|
|
Dim dMove As Double = m_dStep
|
|
If m_dCurrDist < EPS_SMALL Then
|
|
dMove -= m_dOrigDist
|
|
End If
|
|
If (m_vtDir * (ptRawCen - m_ptMid) < 0) Then dMove *= -1
|
|
' Eseguo il movimento
|
|
If EgtMoveRawPart(nRawId, dMove * m_vtDir) Then
|
|
m_dCurrDist += Math.Abs(dMove)
|
|
End If
|
|
' Altrimenti movimento Y +
|
|
Else
|
|
Dim vtMove As New Vector3d(0, m_dStep, 0)
|
|
If EgtMoveRawPart(nRawId, vtMove) Then
|
|
EgtMove(m_nVacId, vtMove, GDB_RT.GLOB)
|
|
AddRawPartData(nRawId, vtMove)
|
|
End If
|
|
End If
|
|
nRawId = EgtGetNextSelectedObj()
|
|
End While
|
|
EgtDraw()
|
|
End Sub
|
|
|
|
Private Sub DownBtn_Click(sender As Object, e As RoutedEventArgs) Handles DownBtn.Click
|
|
Dim nRawId As Integer = EgtGetFirstSelectedObj()
|
|
While nRawId <> GDB_ID.NULL
|
|
' Se movimento perpendicolare, è avvicinamento
|
|
If m_bByHand Then
|
|
' Se sono già a contatto, non devo fare alcunché
|
|
If m_dCurrDist < EPS_SMALL Then Return
|
|
' Recupero il centro del grezzo
|
|
Dim ptRawCen As Point3d
|
|
GetRawCenter(nRawId, ptRawCen)
|
|
' Calcolo la distanza di movimento
|
|
Dim dMove As Double = m_dStep
|
|
If m_dCurrDist < m_dStep Then
|
|
dMove -= m_dOrigDist
|
|
End If
|
|
If (m_vtDir * (ptRawCen - m_ptMid) > 0) Then dMove *= -1
|
|
' Eseguo il movimento
|
|
If EgtMoveRawPart(nRawId, dMove * m_vtDir) Then
|
|
m_dCurrDist -= Math.Abs(dMove)
|
|
End If
|
|
' Altrimenti movimento Y -
|
|
Else
|
|
Dim vtMove As New Vector3d(0, -m_dStep, 0)
|
|
If EgtMoveRawPart(nRawId, vtMove) Then
|
|
EgtMove(m_nVacId, vtMove, GDB_RT.GLOB)
|
|
AddRawPartData(nRawId, vtMove)
|
|
End If
|
|
End If
|
|
nRawId = EgtGetNextSelectedObj()
|
|
End While
|
|
EgtDraw()
|
|
End Sub
|
|
|
|
Private Sub RightBtn_Click(sender As Object, e As RoutedEventArgs) Handles RightBtn.Click
|
|
Dim nRawId As Integer = EgtGetFirstSelectedObj()
|
|
While nRawId <> GDB_ID.NULL
|
|
Dim vtMove As New Vector3d(m_dStep, 0, 0)
|
|
If EgtMoveRawPart(nRawId, vtMove) Then
|
|
EgtMove(m_nVacId, vtMove, GDB_RT.GLOB)
|
|
AddRawPartData(nRawId, vtMove)
|
|
End If
|
|
nRawId = EgtGetNextSelectedObj()
|
|
End While
|
|
EgtDraw()
|
|
End Sub
|
|
|
|
Private Sub LeftBtn_Click(sender As Object, e As RoutedEventArgs) Handles LeftBtn.Click
|
|
Dim nRawId As Integer = EgtGetFirstSelectedObj()
|
|
While nRawId <> GDB_ID.NULL
|
|
Dim vtMove As New Vector3d(-m_dStep, 0, 0)
|
|
If EgtMoveRawPart(nRawId, vtMove) Then
|
|
EgtMove(m_nVacId, vtMove, GDB_RT.GLOB)
|
|
AddRawPartData(nRawId, vtMove)
|
|
End If
|
|
nRawId = EgtGetNextSelectedObj()
|
|
End While
|
|
EgtDraw()
|
|
End Sub
|
|
|
|
Private Sub RemovePartBtn_Click(sender As Object, e As RoutedEventArgs) Handles RemovePartBtn.Click
|
|
Dim nRawId As Integer = EgtGetFirstSelectedObj()
|
|
While nRawId <> GDB_ID.NULL
|
|
EgtRemoveRawPartFromCurrPhase(nRawId)
|
|
nRawId = EgtGetFirstSelectedObj()
|
|
End While
|
|
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 NextBtn_Click(sender As Object, e As RoutedEventArgs) Handles NextBtn.Click
|
|
' Deseleziono tutto
|
|
EgtDeselectAll()
|
|
' Passo alla pagina delle lavorazioni
|
|
m_MainWindow.m_CadCutPageUC.CadCutPageGrid.Children.Remove(m_MainWindow.m_CadCutPageUC.m_MoveRawPartPage)
|
|
m_MainWindow.m_CadCutPageUC.CadCutPageGrid.Children.Add(m_MainWindow.m_CadCutPageUC.m_SplitPage)
|
|
m_MainWindow.m_CadCutPageUC.m_CadCutMode = CadCutPageUC.CadCutModes.Split
|
|
End Sub
|
|
|
|
Private Sub MoveRawPartPage_Unloaded(sender As Object, e As EventArgs) Handles Me.Unloaded
|
|
m_bActive = False
|
|
' Se movimento con ventose
|
|
If Not m_bByHand Then
|
|
' nascondo le ventose
|
|
EgtSetStatus(m_nVacId, GDB_ST.OFF)
|
|
' aggiungo al gruppo disposizione dei sottogruppi con i dati di movimento dei grezzi spostati
|
|
Dim nDispId As Integer = EgtGetPhaseDisposition(m_nCurrPhase)
|
|
Dim nI As Integer = 0
|
|
For Each rwData As RawPartData In m_RawPartDataList
|
|
' Se movimento significativo
|
|
If Not rwData.m_vtMove.IsSmall() Then
|
|
' Incremento contatore
|
|
nI += 1
|
|
' Creo il gruppo
|
|
Dim nRpmId As Integer = EgtCreateGroup(nDispId)
|
|
EgtSetName(nRpmId, "Rpm" & rwData.m_nId.ToString())
|
|
Dim sInfo As String = String.Empty
|
|
sInfo = rwData.m_nId.ToString()
|
|
EgtSetInfo(nRpmId, "Id", sInfo)
|
|
sInfo = DoubleToString(rwData.m_vtMove.x, 4) & "," &
|
|
DoubleToString(rwData.m_vtMove.y, 4) & "," &
|
|
DoubleToString(rwData.m_vtMove.z, 4)
|
|
EgtSetInfo(nRpmId, "Mv", sInfo)
|
|
sInfo = DoubleToString(rwData.m_vtDelta.x, 4) & "," &
|
|
DoubleToString(rwData.m_vtDelta.y, 4) & "," &
|
|
DoubleToString(rwData.m_vtDelta.z, 4)
|
|
EgtSetInfo(nRpmId, "Dt", sInfo)
|
|
sInfo = DoubleToString(rwData.m_dAngRotDeg, 4)
|
|
EgtSetInfo(nRpmId, "Ad", sInfo)
|
|
sInfo = rwData.m_sCups
|
|
EgtSetInfo(nRpmId, "Vc", sInfo)
|
|
sInfo = m_nVacType.ToString()
|
|
EgtSetInfo(nRpmId, "Vt", sInfo)
|
|
End If
|
|
Next
|
|
' Eseguo calcolo speciale dei movimenti
|
|
EgtSpecialApplyDisposition(nDispId, True)
|
|
End If
|
|
End Sub
|
|
|
|
Friend Function LoadVacuumCups() As Boolean
|
|
' Cancello eventuali vecchie ventose
|
|
RemoveVacuumCups()
|
|
' Identificativo ventose nella macchina
|
|
Dim nLayId As Integer = EgtGetFirstNameInGroup(EgtGetHeadId(VACUUM_HEAD), VACUUM_HEAD_LAYOUT)
|
|
If nLayId = GDB_ID.NULL Then Return False
|
|
' Identificativo riferimento della testa nella macchina
|
|
Dim nT1Id As Integer = EgtGetFirstNameInGroup(EgtGetHeadId(VACUUM_HEAD), HEAD_FIRST_EXIT)
|
|
If nT1Id = GDB_ID.NULL Then Return False
|
|
' Creo gruppo temporaneo in cui copiarli
|
|
m_nTempId = EgtCreateGroup(GDB_ID.ROOT)
|
|
If m_nTempId = GDB_ID.NULL Then Return False
|
|
EgtSetName(m_nTempId, "VacTmp")
|
|
EgtSetLevel(m_nTempId, GDB_LV.SYSTEM)
|
|
' Eseguo copia in globale
|
|
m_nVacId = EgtCopyGlob(nLayId, m_nTempId)
|
|
If m_nVacId = GDB_ID.NULL Then Return False
|
|
' Nascondo il gruppo ma rendo visibili le curve di contorno delle ventose
|
|
EgtSetStatus(m_nVacId, GDB_ST.OFF)
|
|
Dim nId As Integer = EgtGetFirstInGroup(m_nVacId)
|
|
While nId <> GDB_ID.NULL
|
|
Select Case EgtGetType(nId)
|
|
Case GDB_TY.CRV_LINE, GDB_TY.CRV_ARC, GDB_TY.CRV_BEZ, GDB_TY.CRV_COMPO
|
|
EgtSetStatus(nId, GDB_ST.ON_)
|
|
Case Else
|
|
EgtSetStatus(nId, GDB_ST.OFF)
|
|
End Select
|
|
nId = EgtGetNext(nId)
|
|
End While
|
|
m_nRefId = EgtCopyGlob(nT1Id, m_nVacId)
|
|
If m_nRefId = GDB_ID.NULL Then Return False
|
|
EgtSetStatus(m_nRefId, GDB_ST.ON_)
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function RemoveVacuumCups() As Boolean
|
|
' cancello eventuale gruppo per ventose
|
|
EgtErase(m_nTempId)
|
|
m_nTempId = GDB_ID.NULL
|
|
m_nVacId = GDB_ID.NULL
|
|
m_nRefId = GDB_ID.NULL
|
|
Return True
|
|
End Function
|
|
|
|
Private Function ResetVacuumCups() As Boolean
|
|
' Ripristino posizione e rotazione originali
|
|
Dim frOriRef As New Frame3d
|
|
EgtFrame(EgtGetFirstNameInGroup(EgtGetHeadId(VACUUM_HEAD), HEAD_FIRST_EXIT), GDB_ID.ROOT, frOriRef)
|
|
Dim frCurrRef As New Frame3d
|
|
EgtFrame(m_nRefId, GDB_ID.ROOT, frCurrRef)
|
|
EgtMove(m_nVacId, frOriRef.Orig() - frCurrRef.Orig(), GDB_RT.GLOB)
|
|
frCurrRef.ToLoc(frOriRef)
|
|
Dim dLen, dAngVertDeg, dAngOrizzDeg As Double
|
|
frCurrRef.VersX().ToSpherical(dLen, dAngVertDeg, dAngOrizzDeg)
|
|
EgtRotate(m_nVacId, frOriRef.Orig(), frOriRef.VersZ(), -dAngOrizzDeg, GDB_RT.GLOB)
|
|
' Ripristino visualizzazione originale
|
|
Dim nId As Integer = EgtGetFirstInGroup(m_nVacId)
|
|
While nId <> GDB_ID.NULL
|
|
Select Case EgtGetType(nId)
|
|
Case GDB_TY.CRV_LINE, GDB_TY.CRV_ARC, GDB_TY.CRV_BEZ, GDB_TY.CRV_COMPO
|
|
EgtSetStatus(nId, GDB_ST.ON_)
|
|
Case Else
|
|
EgtSetStatus(nId, GDB_ST.OFF)
|
|
End Select
|
|
nId = EgtGetNext(nId)
|
|
End While
|
|
EgtSetStatus(m_nRefId, GDB_ST.ON_)
|
|
Return True
|
|
End Function
|
|
|
|
Private Function PutVacuumCupsOnRaw(nRawId As Integer) As Boolean
|
|
If m_bByHand Then Return False
|
|
' Ripristino posizione originale ventose
|
|
ResetVacuumCups()
|
|
' Visualizzo le ventose
|
|
EgtSetStatus(m_nVacId, GDB_ST.ON_)
|
|
' Box e baricentro del grezzo (riportato sopra al grezzo)
|
|
Dim b3Raw As New BBox3d
|
|
GetRawBox(nRawId, b3Raw)
|
|
Dim ptRawCen As Point3d
|
|
GetRawCenter(nRawId, ptRawCen)
|
|
ptRawCen.z += b3Raw.DimZ() / 2
|
|
' Se non esiste, creo la regione del kerf del grezzo
|
|
Dim nRawRegId = EgtGetFirstNameInGroup(nRawId, NAME_KERF_REGION)
|
|
If nRawRegId = GDB_ID.NULL Then
|
|
Dim nOutlineId As Integer = EgtGetFirstNameInGroup(nRawId, NAME_KERF)
|
|
nRawRegId = EgtCreateSurfFlatRegion(nRawId, nOutlineId)
|
|
EgtSetName(nRawRegId, NAME_KERF_REGION)
|
|
EgtSetStatus(nRawRegId, GDB_ST.OFF)
|
|
End If
|
|
' Baricentro della regione di kerf
|
|
Dim ptKerfCen As Point3d
|
|
EgtCentroid(nRawRegId, GDB_ID.ROOT, ptKerfCen)
|
|
' Cerco migliore configurazione di ventose per prendere il grezzo
|
|
Const MAX_SEL As Integer = 20
|
|
For nI As Integer = 1 To MAX_SEL
|
|
' Recupero la configurazione di ventose nI-esima
|
|
Dim sCups() As String = Nothing
|
|
Dim sCups2() As String = Nothing
|
|
If Not GetVacuumCupSelection(nI, sCups, sCups2) Then Return False
|
|
' Determino validità soluzioni della configurazione
|
|
Dim vtMove As New Vector3d
|
|
Dim ptRotCen As New Point3d
|
|
Dim dRotAngDeg As Double = 0
|
|
Dim vtMove2 As New Vector3d
|
|
Dim ptRotCen2 As New Point3d
|
|
Dim dRotAngDeg2 As Double = 0
|
|
Dim dDist = TestVacuumCupSelection(sCups, b3Raw, ptKerfCen, nRawRegId, vtMove, ptRotCen, dRotAngDeg)
|
|
Dim dDist2 = TestVacuumCupSelection(sCups2, b3Raw, ptKerfCen, nRawRegId, vtMove2, ptRotCen2, dRotAngDeg2)
|
|
If dDist > INFINITO - 1 And dDist2 > INFINITO - 1 Then Continue For
|
|
If dDist2 < dDist Then
|
|
sCups = sCups2
|
|
vtMove = vtMove2
|
|
ptRotCen = ptRotCen2
|
|
dRotAngDeg = dRotAngDeg2
|
|
End If
|
|
' Eseguo il movimento
|
|
EgtMove(m_nVacId, vtMove, GDB_RT.GLOB)
|
|
EgtRotate(m_nVacId, ptRotCen, Vector3d.Z_AX(), dRotAngDeg, GDB_RT.GLOB)
|
|
' Visualizzo le ventose
|
|
For nJ As Integer = 0 To sCups.Length() - 1
|
|
Dim nCupId = EgtGetFirstNameInGroup(m_nVacId, sCups(nJ))
|
|
EgtSetStatus(nCupId, GDB_ST.ON_)
|
|
Next
|
|
' Aggiorno dati del grezzo
|
|
Dim frCurrRef As New Frame3d
|
|
EgtFrame(m_nRefId, GDB_ID.ROOT, frCurrRef)
|
|
Dim vtDelta As Vector3d = frCurrRef.Orig() - ptRawCen
|
|
AddRawPartData(nRawId, vtDelta, dRotAngDeg, sCups)
|
|
Return True
|
|
Next
|
|
Return False
|
|
End Function
|
|
|
|
Private Function GetVacuumCupSelection(nInd As Integer, ByRef sCups() As String, ByRef sCups2() As String) As Boolean
|
|
' Recupero elenco ventose nella soluzione
|
|
Dim sSel As String = "Sel" & nInd.ToString()
|
|
Dim sVal As String = String.Empty
|
|
If Not EgtGetInfo(m_nVacId, sSel, sVal) Then Return False
|
|
If sVal.IndexOf("/") >= 0 Then
|
|
Dim sSplit() As String = sVal.Split("/".ToCharArray)
|
|
If sSplit.Length() >= 2 Then
|
|
sCups = sSplit(0).Split(",".ToCharArray)
|
|
sCups2 = sSplit(1).Split(",".ToCharArray)
|
|
ElseIf sSplit.Length() >= 1 Then
|
|
sCups = sSplit(0).Split(",".ToCharArray)
|
|
sCups2 = Nothing
|
|
Else
|
|
sCups = Nothing
|
|
sCups2 = Nothing
|
|
End If
|
|
Else
|
|
sCups = sVal.Split(",".ToCharArray)
|
|
sCups2 = Nothing
|
|
End If
|
|
Return True
|
|
End Function
|
|
|
|
Private Function TestVacuumCupSelection(sCups() As String, b3Raw As BBox3d, ptRawCen As Point3d, nRawRegId As Integer,
|
|
ByRef vtMove As Vector3d, ByRef ptRotCen As Point3d, ByRef dRotAngDeg As Double) As Double
|
|
' Se definizione mancante, scarto soluzione
|
|
If IsNothing(sCups) Then Return INFINITO
|
|
' Ne calcolo il box
|
|
Dim b3Vac As New BBox3d
|
|
For nJ As Integer = 0 To sCups.Length() - 1
|
|
Dim nCupId = EgtGetFirstNameInGroup(m_nVacId, sCups(nJ))
|
|
Dim b3Cup As New BBox3d
|
|
If EgtGetBBoxGlob(nCupId, GDB_BB.STANDARD, b3Cup) Then b3Vac.Add(b3Cup)
|
|
Next
|
|
If b3Vac.IsEmpty() Then Return INFINITO
|
|
' Se box maggiore di quello del pezzo, scarto soluzione
|
|
If Not ((b3Vac.DimX() < b3Raw.DimX() And b3Vac.DimY() < b3Raw.DimY()) Or
|
|
(b3Vac.DimX() < b3Raw.DimY() And b3Vac.DimY() < b3Raw.DimX())) Then
|
|
Return INFINITO
|
|
End If
|
|
' Determino il movimento
|
|
vtMove = ptRawCen - b3Vac.Center()
|
|
b3Vac.Move(vtMove)
|
|
' Determino la rotazione, allineando il lato lungo delle ventose con quello del grezzo
|
|
ptRotCen = b3Vac.Center()
|
|
dRotAngDeg = 0
|
|
If (b3Vac.DimX() >= b3Vac.DimY() And b3Raw.DimX() < b3Raw.DimY()) Or
|
|
(b3Vac.DimX() < b3Vac.DimY() And b3Raw.DimX() >= b3Raw.DimY()) Then
|
|
dRotAngDeg = 90
|
|
End If
|
|
' Identificativi delle ventose
|
|
Dim nCups(sCups.Length() - 1) As Integer
|
|
For nJ As Integer = 0 To sCups.Length() - 1
|
|
nCups(nJ) = EgtGetFirstNameInGroup(m_nVacId, sCups(nJ))
|
|
Next
|
|
' Eseguo verifica delle ventose rispetto al grezzo
|
|
Dim bVacOk As Boolean = True
|
|
If Not TestVacuumCups(nCups, nRawRegId, vtMove, ptRotCen, dRotAngDeg) Then
|
|
' Provo ad aggiungere rotazione di + 45
|
|
dRotAngDeg += 45
|
|
If Not TestVacuumCups(nCups, nRawRegId, vtMove, ptRotCen, dRotAngDeg) Then
|
|
' Provo ad aggiungere rotazione di - 45
|
|
dRotAngDeg -= 90
|
|
If Not TestVacuumCups(nCups, nRawRegId, vtMove, ptRotCen, dRotAngDeg) Then
|
|
bVacOk = False
|
|
End If
|
|
End If
|
|
End If
|
|
If Not bVacOk Then Return INFINITO
|
|
' Recupero riferimento della testa ventose
|
|
Dim frCurrRef As New Frame3d
|
|
EgtFrame(m_nRefId, GDB_ID.ROOT, frCurrRef)
|
|
Dim ptRef As Point3d = frCurrRef.Orig()
|
|
' Applico movimento e rotazione al punto
|
|
ptRef.Move(vtMove)
|
|
ptRef.Rotate(ptRotCen, Vector3d.Z_AX(), dRotAngDeg)
|
|
' Ne calcolo la distanza dal centro della tavola
|
|
Dim dDist As Double = Point3d.DistXY(ptRef, m_ptTabCen)
|
|
Return dDist
|
|
End Function
|
|
|
|
Private Function TestVacuumCups(nCups() As Integer, nRawRegId As Integer,
|
|
vtMove As Vector3d, ptRotCen As Point3d, dRotAngDeg As Double) As Boolean
|
|
' Eseguo verifica delle ventose rispetto al grezzo
|
|
Dim bVacOk As Boolean = True
|
|
For nJ As Integer = 0 To nCups.Length() - 1
|
|
Dim nCupId = nCups(nJ)
|
|
' Eseguo rototraslazione delle ventose per verificare se sono contenute nel grezzo
|
|
EgtMove(nCupId, vtMove, GDB_RT.GLOB)
|
|
EgtRotate(nCupId, ptRotCen, Vector3d.Z_AX(), dRotAngDeg, GDB_RT.GLOB)
|
|
' Confronto le regioni
|
|
If EgtSurfFrChunkSimpleClassify(nRawRegId, 0, nCupId, 0) <> REGC.IN2 Then bVacOk = False
|
|
' Annullo rototraslazione
|
|
EgtRotate(nCupId, ptRotCen, Vector3d.Z_AX(), -dRotAngDeg, GDB_RT.GLOB)
|
|
EgtMove(nCupId, -vtMove, GDB_RT.GLOB)
|
|
' Se verifica fallita, esco dal ciclo
|
|
If Not bVacOk Then Exit For
|
|
Next
|
|
Return bVacOk
|
|
End Function
|
|
|
|
Private Function AddRawPartData(nRawId As Integer) As Integer
|
|
' Cerco in lista record con dati del grezzo indicato
|
|
Dim nInd As Integer = -1
|
|
For i As Integer = 0 To m_RawPartDataList.Count() - 1
|
|
If m_RawPartDataList(i).m_nId = nRawId Then
|
|
nInd = i
|
|
Exit For
|
|
End If
|
|
Next
|
|
' Se non trovato, lo accodo
|
|
If nInd = -1 Then
|
|
m_RawPartDataList.Add(New RawPartData(nRawId))
|
|
nInd = m_RawPartDataList.Count() - 1
|
|
End If
|
|
Return nInd
|
|
End Function
|
|
|
|
Private Function AddRawPartData(nRawId As Integer, vtMove As Vector3d) As Integer
|
|
' Recupero o creo record con dati del grezzo indicato
|
|
Dim nInd As Integer = AddRawPartData(nRawId)
|
|
If nInd = -1 Then Return -1
|
|
' Aggiorno i valori
|
|
m_RawPartDataList(nInd).m_vtMove += vtMove
|
|
Return nInd
|
|
End Function
|
|
|
|
Private Function AddRawPartData(nRawId As Integer, vtDelta As Vector3d, dAngRotDeg As Double, sCups() As String) As Integer
|
|
' Recupero o creo record con dati del grezzo indicato
|
|
Dim nInd As Integer = AddRawPartData(nRawId)
|
|
If nInd = -1 Then Return -1
|
|
' Aggiorno i valori
|
|
m_RawPartDataList(nInd).m_vtDelta = vtDelta
|
|
m_RawPartDataList(nInd).m_dAngRotDeg = dAngRotDeg
|
|
Dim sVal As String = String.Empty
|
|
For Each sCup As String In sCups
|
|
If String.IsNullOrEmpty(sVal) Then
|
|
sVal &= sCup
|
|
Else
|
|
sVal &= "," & sCup
|
|
End If
|
|
Next
|
|
m_RawPartDataList(nInd).m_sCups = sVal
|
|
Return nInd
|
|
End Function
|
|
|
|
'-----------------------------------------------------------------------------------------------
|
|
Private Class RawPartData
|
|
|
|
Public m_nId As Integer
|
|
Public m_vtMove As Vector3d
|
|
Public m_vtDelta As Vector3d
|
|
Public m_dAngRotDeg As Double
|
|
Public m_sCups As String
|
|
|
|
Sub New(nId As Integer)
|
|
m_nId = nId
|
|
m_vtMove = Vector3d.NULL()
|
|
m_vtDelta = Vector3d.NULL()
|
|
m_dAngRotDeg = 0
|
|
m_sCups = String.Empty
|
|
End Sub
|
|
End Class
|
|
|
|
End Class
|
|
|
|
|