Files
Dario Sassi 9d62cf6b99 EgtCAM5 :
- miglioramenti spostamento grezzi con morse.
2024-10-31 18:34:30 +01:00

1305 lines
59 KiB
VB.net

Imports System.Windows.Forms.AxHost
Imports EgtUILib
Imports Microsoft.VisualBasic.ApplicationServices
Public NotInheritable Class DispositionUtility
Friend Const PDIST As String = "PDist"
Friend Const MDIST As String = "MDist"
Friend Const PREV As String = "Prev"
Friend Const NEXT_ As String = "Next"
Friend Const HOOK As String = "HOOK*"
Friend Const CLASS_ As String = "CLASS"
Friend Const FIXED As String = "FIXED*"
Friend Const TYPE As String = "TYPE"
Friend Const FREE As String = "FREE"
Friend Const LINE As String = "LINE"
Friend Const POINT As String = "POINT"
Friend Enum HOOKTYPE As Integer
FREE = 0
POINT = 1
LINE = 2
End Enum
Private Shared m_vtHook As Vector3d = Vector3d.NULL
Private Shared m_nUsedHookId As Integer = GDB_ID.NULL
Private Shared m_nPrevUsedHookId As Integer = GDB_ID.NULL
Private Shared m_nPrevFixtureId As Integer = GDB_ID.NULL
Friend Class HookData
Public m_sName As String
Public m_sParent As String
Public m_bParentAxis As Boolean
Public m_sGrParentAxis As String
Public m_nId As Integer
Public m_nType As HOOKTYPE
Public m_ptP1 As Point3d
Public m_ptP2 As Point3d
Public m_nClass As Integer
Public m_nHooked As Integer
Public m_sHooked As String
Sub New()
m_sName = ""
m_sParent = ""
m_bParentAxis = False
m_sGrParentAxis = ""
m_nId = GDB_ID.NULL
m_nType = HOOKTYPE.FREE
m_ptP1 = Point3d.ORIG()
m_ptP2 = Point3d.ORIG()
m_nClass = 0
m_nHooked = GDB_ID.NULL
m_sHooked = ""
End Sub
Sub New(sName As String, sParent As String, bParentAxis As Boolean, sGrParentAxis As String,
nId As Integer, ptP As Point3d, nClass As Integer)
m_sName = sName
m_sParent = sParent
m_bParentAxis = bParentAxis
m_sGrParentAxis = sGrParentAxis
m_nId = nId
m_nType = HOOKTYPE.POINT
m_ptP1 = ptP
m_ptP2 = Point3d.ORIG()
m_nClass = nClass
m_nHooked = GDB_ID.NULL
m_sHooked = ""
End Sub
Sub New(sName As String, sParent As String, bParentAxis As Boolean, sGrParentAxis As String,
nId As Integer, ptP1 As Point3d, ptP2 As Point3d, nClass As Integer)
m_sName = sName
m_sParent = sParent
m_bParentAxis = bParentAxis
m_sGrParentAxis = sGrParentAxis
m_nId = nId
m_nType = HOOKTYPE.LINE
m_ptP1 = ptP1
m_ptP2 = ptP2
m_nClass = nClass
m_nHooked = GDB_ID.NULL
m_sHooked = ""
End Sub
End Class
Friend Shared m_vHookData As New List(Of HookData)
Friend Shared Function DistPointSegment( ptP As Point3d, ptS1 As Point3d, ptS2 As Point3d) As Point3d
If AreSamePointApprox( ptS1, ptS2) Then
Return Point3d.Media( ptS1, ptS2)
End If
Dim vtDir As Vector3d = ptS2 - ptS1
vtDir.z = 0
Dim dLen As Double = vtDir.Len()
vtDir /= dLen
Dim dProSca As Double = vtDir * ( ptP - ptS1)
If dProSca < EPS_SMALL Then
Return ptS1
ElseIf dProSca > dLen - EPS_SMALL Then
Return ptS2
Else
Return ptS1 + dProSca * vtDir
End If
End Function
' Identificativi per elemento da selezionare/deselezionare
Friend Enum SelType As Integer
NULL = 0
FIXTURE = 1
RAWPART = 2
BARS = 3
PART = 4
End Enum
Friend Shared Function GetRawPartRefPoint(nRawPartId As Integer, RawRefPosition As MCH_CR) As Point3d
Dim bboxRawPart As New BBox3d
' recupero il solido del grezzo dal primo elemento selezionato
Dim nRawSolidId As Integer = EgtGetFirstNameInGroup(nRawPartId, RAWSOLID)
' ne calcolo il BBox
EgtGetBBoxGlob(nRawSolidId, GDB_BB.ONLY_VISIBLE, bboxRawPart)
' imposto il riferimento della tavola
Dim ptTableRef As Point3d
EgtGetTableRef(1, ptTableRef)
' calcolo i punti min e max del bbox riferiti alla tavola
Dim ptBBoxRawPartMin As New Point3d(bboxRawPart.Min)
Dim ptBBoxRawPartMax As New Point3d(bboxRawPart.Max)
ptBBoxRawPartMin.ToLoc(New Frame3d(ptTableRef))
ptBBoxRawPartMax.ToLoc(New Frame3d(ptTableRef))
' dal box e dal tipo di punto di riferimento selezionato ricavo le coordinate del punto di riferimento
Dim ptRawRefPoint As Point3d
Select Case RawRefPosition
Case MCH_CR.TL
ptRawRefPoint.x = ptBBoxRawPartMin.x
ptRawRefPoint.y = ptBBoxRawPartMax.y
Case MCH_CR.TR
ptRawRefPoint.x = ptBBoxRawPartMax.x
ptRawRefPoint.y = ptBBoxRawPartMax.y
Case MCH_CR.BL
ptRawRefPoint.x = ptBBoxRawPartMin.x
ptRawRefPoint.y = ptBBoxRawPartMin.y
Case MCH_CR.BR
ptRawRefPoint.x = ptBBoxRawPartMax.x
ptRawRefPoint.y = ptBBoxRawPartMin.y
End Select
ptRawRefPoint.z = ptBBoxRawPartMin.z
Return ptRawRefPoint
End Function
Public Shared Function MoveRawPartPartAndFixture(nMoveId As Integer, vtMove As Vector3d, sSelType As Integer, Optional ptCurr As Point3d = Nothing, Optional nCount As Integer = 1) As Boolean
Dim bErrorMoving As Boolean = False
' Muovo gli oggetti selezionati se consentito
If nMoveId = GDB_ID.SEL Then
Dim nSelObjId As Integer = EgtGetFirstSelectedObj()
While nSelObjId <> GDB_ID.NULL
If EgtVerifyFixture(nSelObjId) Then
If Not EgtMoveFixture(nSelObjId, vtMove) Then
bErrorMoving = True
nSelObjId = EgtGetPrevSelectedObj()
While nSelObjId <> GDB_ID.NULL
If EgtVerifyFixture(nSelObjId) Then
EgtMoveFixture(nSelObjId, -vtMove)
Else
EgtMoveRawPart(nSelObjId, -vtMove)
End If
nSelObjId = EgtGetPrevSelectedObj()
End While
Exit While
End If
nSelObjId = EgtGetNextSelectedObj()
Else
If Not EgtMoveRawPart(nSelObjId, vtMove) Then
bErrorMoving = True
nSelObjId = EgtGetPrevSelectedObj()
While nSelObjId <> GDB_ID.NULL
If EgtVerifyFixture(nSelObjId) Then
EgtMoveFixture(nSelObjId, -vtMove)
Else
EgtMoveRawPart(nSelObjId, -vtMove)
End If
nSelObjId = EgtGetPrevSelectedObj()
End While
Exit While
End If
nSelObjId = EgtGetNextSelectedObj()
End If
End While
Else
If EgtVerifyFixture(nMoveId) Then
VerifyHookFixture(nMoveId, vtMove, ptCurr, False)
If Not EgtMoveFixture(nMoveId, vtMove) Then
bErrorMoving = True
End If
ElseIf sSelType = SelType.BARS Then
VerifyBarPosition(nMoveId, vtMove)
Else
If Not EgtMoveRawPart(nMoveId, vtMove) Then
bErrorMoving = True
End If
End If
End If
' Variabile che contiene l'eventuale spostamento correttivo per interferenza con riferimenti
Dim vtRefMove As New Vector3d(Vector3d.NULL)
' Se non ci sono stati errori nel movimento
Dim bErrorVerify As Boolean = False
If Not bErrorMoving Then
' Verifico che gli spostamenti effettuati siano validi
If nMoveId = GDB_ID.SEL Then
Dim nSelObjId As Integer = EgtGetFirstSelectedObj()
While nSelObjId <> GDB_ID.NULL
If Not VerifyRawPartFixturePos(nSelObjId, vtMove, vtRefMove) Then
bErrorVerify = True
Exit While
End If
nSelObjId = EgtGetNextSelectedObj()
End While
Else
If Not VerifyRawPartFixturePos(nMoveId, vtMove, vtRefMove) Then
bErrorVerify = True
End If
'Dim sOut As String = "VerifyRaw : Count=" & nCount & " Err=" & If(bErrorVerify, "1", "0") &
' " Move=" & LenToString(vtMove.x, 3) & "," & LenToString(vtMove.y, 3) &
' " RefMove=" & LenToString(vtRefMove.x, 3) & "," & LenToString(vtRefMove.y, 3)
'EgtOutLog(sOut)
End If
End If
' Se non c'è errore ma necessaria correzione riferimento
If Not bErrorVerify AndAlso Not vtRefMove.IsSmall() Then
' provo a correggere (max 1 prova)
If nCount < 2 Then
bErrorVerify = Not MoveRawPartPartAndFixture(nMoveId, vtRefMove, DispositionUtility.SelType.NULL, Nothing, nCount + 1)
End If
End If
' Se c'è almeno uno spostamento non valido
If bErrorVerify Then
' ripristino la situazione iniziale annullando tutti i movimenti
If nMoveId = GDB_ID.SEL Then
Dim nSelObjId As Integer = EgtGetFirstSelectedObj()
While nSelObjId <> GDB_ID.NULL
If EgtVerifyFixture(nSelObjId) Then
EgtMoveFixture(nSelObjId, -vtMove)
Else
EgtMoveRawPart(nSelObjId, -vtMove)
End If
nSelObjId = EgtGetNextSelectedObj()
End While
Else
If EgtVerifyFixture(nMoveId) Then
EgtMoveFixture(nMoveId, -vtMove)
' ripristino occupazione hooks
SetHookUsed(m_nPrevUsedHookId, nMoveId, False)
SetHookUsed(m_nUsedHookId, m_nPrevFixtureId, True)
' rieseguo verifica nel punto iniziale
VerifyHookFixture(nMoveId, Vector3d.NULL(), Point3d.ORIG(), True)
Else
EgtMoveRawPart(nMoveId, -vtMove)
End If
End If
' ritorno falso
Return False
End If
Return True
End Function
Public Shared Function VerifyRawPartFixturePos(nMovedObjId As Integer, ByRef vtOrigMove As Vector3d, ByRef vtRefMove As Vector3d) As Boolean
' Verifico quale sia il tipo dell'oggetto mosso
If EgtVerifyFixture(nMovedObjId) Then
Return VerifyFixturePosition(nMovedObjId, vtRefMove)
ElseIf EgtVerifyRawPartCurrPhase(nMovedObjId) Then
Return VerifyRawPosition(nMovedObjId, vtOrigMove, vtRefMove)
Elseif VerifyTableAxis( nMovedObjId) Then
Return True
Else
Return False
End If
End Function
Friend Shared Function VerifyFixturePosition(nMovedFixtureId As Integer, ByRef vtRefMove As Vector3d) As Boolean
' Definisco il box della ventosa mossa
Dim bboxMovedFixture As New BBox3d
EgtGetBBoxGlob(nMovedFixtureId, GDB_BB.ONLY_VISIBLE, bboxMovedFixture)
Dim bboxFixture As New BBox3d
' Ciclo sui sottopezzi correnti per verificare le collisioni con il sottopezzo spostato
Dim nFixtureId As Integer = EgtGetFirstFixture()
While nFixtureId <> GDB_ID.NULL
If EgtVerifyFixture(nFixtureId) AndAlso nFixtureId <> nMovedFixtureId Then
' ne calcolo il BBox
EgtGetBBoxGlob(nFixtureId, GDB_BB.ONLY_VISIBLE, bboxFixture)
' verifico se c'è sovrapposizione
If bboxMovedFixture.OverlapsXY(bboxFixture) Then
' se c'è restituisco falso perchè i sottopezzi non si possono sovrapporre
Return False
End If
End If
nFixtureId = EgtGetNextFixture(nFixtureId)
End While
Return VerifyFixtureWithRaw(nMovedFixtureId, vtRefMove)
End Function
Private Shared Function VerifyFixtureWithRaw(nFixtureId As Integer, ByRef vtRefMove As Vector3d) As Boolean
' Tengo da parte il riferimento della tavola
Dim ptTableRef As Point3d
EgtGetTableRef(1, ptTableRef)
Dim TableFrame As New Frame3d(ptTableRef)
' Definisco il box del sottopezzo mosso
Dim bboxFixture As New BBox3d
EgtGetBBoxGlob(nFixtureId, GDB_BB.ONLY_VISIBLE, bboxFixture)
Dim bboxRawPart As New BBox3d
' Variabile che indica se il riferimento non è in battuta su nessun grezzo
Dim bRefAttachedToRaw As Boolean = False
' Ciclo sui grezzi della fase corrente per verificare le collisioni con il sottopezzo mosso
Dim nRawPartId As Integer = EgtGetFirstRawPart()
While nRawPartId <> GDB_ID.NULL
If EgtVerifyRawPartCurrPhase(nRawPartId) Then
' recupero il solido del grezzo
Dim nRawSolidId As Integer = EgtGetFirstNameInGroup(nRawPartId, RAWSOLID)
' ne calcolo il BBox
EgtGetBBoxGlob(nRawSolidId, GDB_BB.ONLY_VISIBLE, bboxRawPart)
' verifico il tipo di sottopezzo
Select Case FixtureType(nFixtureId)
' se il sottopezzo è una ventosa
Case FIX_TYPE.VACUUM
' verifico se c'è sovrapposizione
If bboxFixture.OverlapsXY(bboxRawPart) Then
' se c'è devo verificare che l'altezza del grezzo sia uguale a quella della ventosa
' recupero altezza ventosa
Dim dFixtureHeight As Double = 0
EgtGetInfo(nFixtureId, "H", dFixtureHeight)
' recupero altezza grezzo riferita alla tavola
Dim dRawPartMin As Point3d = bboxRawPart.Min
dRawPartMin.ToLoc(TableFrame)
' se l'altezza grezzo è minore di quella della ventosa, lo sposto alla stessa altezza
If dRawPartMin.z < dFixtureHeight - EPS_SMALL Then
Dim vtMove As New Vector3d(0, 0, dFixtureHeight - dRawPartMin.z)
EgtMoveRawPart(nRawPartId, vtMove)
' ricalcolo il BBox del solido del grezzo per averlo aggiornato con la nuova Z
EgtGetBBoxGlob(nRawSolidId, GDB_BB.ONLY_VISIBLE, bboxRawPart)
End If
' se non c'è sovrapposizione devo verificare il grezzo con tutti gli altri sottopezzi per sapere se ho tolto l'ultimo e quindi devo abbassarlo
Else
' variabile che contiene la massima altezza delle ventose sottostanti
Dim dMaxFixtureHeight As Double = 0
' Variabile che dice se c'è almeno una ventosa sotto il grezzo
Dim bIsFixtureUnderRawPart As Boolean = False
Dim nOtherFixtureId As Integer = EgtGetFirstFixture()
While nOtherFixtureId <> GDB_ID.NULL
' evito di rifare la verifica sul sottopezzo mosso
If nOtherFixtureId <> nFixtureId Then
' calcolo il BBox del sottopezzo
Dim bboxOtherFixture As New BBox3d
EgtGetBBoxGlob(nOtherFixtureId, GDB_BB.ONLY_VISIBLE, bboxOtherFixture)
If bboxRawPart.OverlapsXY(bboxOtherFixture) Then
bIsFixtureUnderRawPart = True
' recupero altezza ventosa
Dim dOtherFixtureHeight As Double = 0
EgtGetInfo(nFixtureId, "H", dOtherFixtureHeight)
' la confronto con quella massima
If dOtherFixtureHeight > dMaxFixtureHeight Then
dMaxFixtureHeight = dOtherFixtureHeight
End If
End If
End If
nOtherFixtureId = EgtGetNextFixture(nOtherFixtureId)
End While
' recupero altezza grezzo riferita alla tavola
Dim dRawPartMin As Point3d = bboxRawPart.Min
dRawPartMin.ToLoc(TableFrame)
' se non ci sono ventose sotto il grezzo
If Not bIsFixtureUnderRawPart Then
' verifico che il grezzo sia ad altezza tavola
If dRawPartMin.z <> 0 Then
Dim vtMove As New Vector3d(0, 0, -dRawPartMin.z)
EgtMoveRawPart(nRawPartId, vtMove)
End If
Else
' se ci sono verifico che l'altezza del grezzo sia quella della ventosa più alta
If Math.Abs(dRawPartMin.z - dMaxFixtureHeight) > EPS_SMALL Then
Dim vtMove As New Vector3d(0, 0, dMaxFixtureHeight - dRawPartMin.z)
EgtMoveRawPart(nRawPartId, vtMove)
End If
End If
End If
' se il sottopezzo è un riferimento
Case FIX_TYPE.REFERENCE
' verifico se c'è sovrapposizione
If bboxFixture.OverlapsXY(bboxRawPart) Then
' recupero arco del riferimento
Dim arcRefId As Integer = EgtGetFirstNameInGroup(EgtGetFirstNameInGroup(nFixtureId, SOLID), REF_ARC)
' calcolo bbox dell'arco di riferimento
Dim bboxArcRef As New BBox3d
EgtGetBBoxGlob(arcRefId, GDB_BB.STANDARD, bboxArcRef)
' ne faccio l'offset ??
'bboxArcRef.Expand(10)
If bboxRawPart.OverlapsXY(bboxArcRef) Then
' recupero contorno del grezzo
Dim ccompoRawPartOutlineId As Integer = EgtGetFirstNameInGroup(nRawPartId, RAWOUTLINE)
'recupero il raggio dell'arco di riferimento
Dim dArcRadius As Double
EgtArcRadius(arcRefId, dArcRadius)
' faccio copia e offset del contorno grezzo
Dim ccompoRawPartOutlineOffsetId As Integer = EgtCopyGlob(ccompoRawPartOutlineId, ccompoRawPartOutlineId, GDB_POS.AFTER)
EgtOffsetCurve(ccompoRawPartOutlineOffsetId, dArcRadius, OFF_TYPE.FILLET)
' recupero centro dell'arco di riferimento
Dim ptArcCenter As Point3d
EgtCenterPoint(arcRefId, ccompoRawPartOutlineOffsetId, ptArcCenter)
' verifico quale è il punto dell'offset vicino al centro dell'arco di riferimento
Dim dDist As Double
Dim ptMin As Point3d
Dim nSide As Integer
EgtPointCurveDistSide(ptArcCenter, ccompoRawPartOutlineOffsetId, Vector3d.Z_AX, ccompoRawPartOutlineOffsetId, dDist, ptMin, nSide)
' cancello offset
EgtErase(ccompoRawPartOutlineOffsetId)
' calcolo il vettore di spostamento necessario ad allinearli
Dim vtDelta As Vector3d = ptArcCenter - ptMin
vtDelta.z = 0
' se i punti coincidono, esco
If vtDelta.IsSmall() Then
' il grezzo è in battuta sul riferimento
Dim nContactColDisk As Integer = EgtGetFirstNameInGroup(EgtGetFirstNameInGroup(nFixtureId, SOLID), REF_DISK)
EgtSetColor(nContactColDisk, ReferenceContactColGreen)
bRefAttachedToRaw = True
Else
' altrimenti riporto il vettore di correzione
vtRefMove = -vtDelta.Glob(ccompoRawPartOutlineId)
End If
Else
' il grezzo non è in battuta sul riferimento
Dim nContactColDisk As Integer = EgtGetFirstNameInGroup(EgtGetFirstNameInGroup(nFixtureId, SOLID), REF_DISK)
EgtSetColor(nContactColDisk, ReferenceContactColRed)
End If
End If
End Select
End If
nRawPartId = EgtGetNextRawPart(nRawPartId)
End While
' se è un riferimento e non è in battuta sul nessun grezzo
If FixtureType(nFixtureId) = FIX_TYPE.REFERENCE AndAlso Not bRefAttachedToRaw Then
' lo segnalo
Dim nContactColDisk As Integer = EgtGetFirstNameInGroup(EgtGetFirstNameInGroup(nFixtureId, SOLID), REF_DISK)
EgtSetColor(nContactColDisk, ReferenceContactColRed)
End If
Return True
End Function
Friend Shared Function VerifyRawPosition(nMovedRawId As Integer, ByRef vtOrigMove As Vector3d, ByRef vtRefMove As Vector3d) As Boolean
' Recupero il solido del grezzo
Dim nMovedRawSolidId As Integer = EgtGetFirstNameInGroup(nMovedRawId, RAWSOLID)
' definisco il box del solido del grezzo
Dim bboxMovedRawPart As New BBox3d
EgtGetBBoxGlob(nMovedRawSolidId, GDB_BB.ONLY_VISIBLE, bboxMovedRawPart)
Dim bboxRawPart As New BBox3d
' Ciclo sui grezzi della fase corrente per verificare le collisioni con il grezzo spostato
Dim nRawPartId As Integer = EgtGetFirstRawPart()
While nRawPartId <> GDB_ID.NULL
If EgtVerifyRawPartCurrPhase(nRawPartId) AndAlso nRawPartId <> nMovedRawId Then
' recupero il solido del grezzo
Dim nRawSolidId As Integer = EgtGetFirstNameInGroup(nRawPartId, RAWSOLID)
' ne calcolo il BBox
EgtGetBBoxGlob(nRawSolidId, GDB_BB.ONLY_VISIBLE, bboxRawPart)
' verifico se c'è sovrapposizione
If bboxMovedRawPart.OverlapsXY(bboxRawPart) Then
' se c'è restituisco falso perchè i grezzi non si possono sovrapporre
Return False
End If
End If
nRawPartId = EgtGetNextRawPart(nRawPartId)
End While
' verifico le interferenze tra il grezzo spostato e le ventose
Return VerifyRawWithFixture(nMovedRawId, vtOrigMove, vtRefMove)
End Function
Private Shared Function VerifyRawWithFixture(nRawId As Integer, ByRef vtOrigMove As Vector3d, ByRef vtRefMove As Vector3d) As Boolean
' Tengo da parte il riferimento della tavola
Dim ptTableRef As Point3d
EgtGetTableRef(1, ptTableRef)
Dim TableFrame As New Frame3d(ptTableRef)
' Recupero il solido del grezzo
Dim nMovedRawSolidId As Integer = EgtGetFirstNameInGroup(nRawId, RAWSOLID)
' definisco il box del solido del grezzo
Dim bboxRawPartId As New BBox3d
EgtGetBBoxGlob(nMovedRawSolidId, GDB_BB.ONLY_VISIBLE, bboxRawPartId)
' Variabile che dice se c'è almeno una ventosa sotto il grezzo
Dim bIsFixtureUnderRawPart As Boolean = False
Dim bboxFixture As New BBox3d
' variabile che contiene la massima altezza delle ventose sottostanti
Dim dMaxFixtureHeight As Double = 0
' recupero altezza grezzo riferita alla tavola
Dim dRawPartMin As Point3d = bboxRawPartId.Min
dRawPartMin.ToLoc(TableFrame)
' Ciclo sui sottopezzi presenti per verificare le collisioni con il grezzo
Dim nFixtureId As Integer = EgtGetFirstFixture()
While nFixtureId <> GDB_ID.NULL
' calcolo il BBox del sottopezzo
EgtGetBBoxGlob(nFixtureId, GDB_BB.ONLY_VISIBLE, bboxFixture)
' verifico se c'è sovrapposizione
If bboxRawPartId.OverlapsXY(bboxFixture) Then
' recupero il tipo di fixture
Dim nFxtType As FIX_TYPE = FixtureType(nFixtureId)
' Se è ventosa o morsa
If nFxtType = FIX_TYPE.VACUUM Or nFxtType = FIX_TYPE.VISE Then
' recupero altezza ventosa
Dim dFixtureHeight As Double = 0
EgtGetInfo(nFixtureId, "H", dFixtureHeight)
' la confronto con quella massima
If dFixtureHeight > dMaxFixtureHeight Then
dMaxFixtureHeight = dFixtureHeight
End If
' se l'altezza grezzo è diversa da quella della ventosa, lo sposto alla stessa altezza
If dRawPartMin.z < dFixtureHeight - EPS_SMALL Then
Dim vtMove As New Vector3d(0, 0, dFixtureHeight - dRawPartMin.z)
EgtMoveRawPart(nRawId, vtMove)
' recupero il solido del grezzo
Dim nRawSolidId As Integer = EgtGetFirstNameInGroup(nRawId, RAWSOLID)
' ricalcolo il BBox del solido del grezzo per averlo aggiornato con la nuova Z
EgtGetBBoxGlob(nRawSolidId, GDB_BB.ONLY_VISIBLE, bboxRawPartId)
dRawPartMin = bboxRawPartId.Min
dRawPartMin.ToLoc(TableFrame)
End If
bIsFixtureUnderRawPart = True
End If
' Se è morsa
If nFxtType = FIX_TYPE.VISE Then
' regolo la posizione in Z della morsa
EgtSetFixtureMobile( nFixtureId, bboxRawPartId.DimZ())
End If
' Se è un riferimento o una morsa
If nFxtType = FIX_TYPE.REFERENCE Or nFxtType = FIX_TYPE.VISE Then
' recupero arco del riferimento
Dim arcRefId As Integer = EgtGetFirstNameInGroup(EgtGetFirstNameInGroup(nFixtureId, SOLID), REF_ARC)
' calcolo bbox dell'arco di riferimento
Dim bboxArcRef As New BBox3d
EgtGetBBoxGlob(arcRefId, GDB_BB.STANDARD, bboxArcRef)
If bboxRawPartId.OverlapsXY(bboxArcRef) Then
' recupero contorno del grezzo
Dim ccompoRawPartOutlineId As Integer = EgtGetFirstNameInGroup(nRawId, RAWOUTLINE)
'recupero il raggio dell'arco di riferimento
Dim dArcRadius As Double
EgtArcRadius(arcRefId, dArcRadius)
' faccio copia e offset del contorno grezzo
Dim ccompoRawPartOutlineOffsetId As Integer = EgtCopyGlob(ccompoRawPartOutlineId, ccompoRawPartOutlineId, GDB_POS.AFTER)
EgtOffsetCurve(ccompoRawPartOutlineOffsetId, dArcRadius, OFF_TYPE.FILLET)
' recupero centro dell'arco di riferimento
Dim ptArcCenter As Point3d
EgtCenterPoint(arcRefId, ccompoRawPartOutlineId, ptArcCenter)
' Creo un segmento avente origine nel centro dell'arco e direzione opposta a quella del movimento
Dim nDistLine As Integer = EgtCreateLinePVL(EgtGetParent(ccompoRawPartOutlineId), ptArcCenter, vtOrigMove.Loc(ccompoRawPartOutlineId), 10000)
' cerco punto di intersezione tra il segmento e l'offset
Dim ptDist As Point3d
If EgtIntersectionPoint(nDistLine, ccompoRawPartOutlineOffsetId, ptArcCenter, ptDist) Then
' calcolo il vettore di spostamento necessario ad allinearli
Dim vtDelta As Vector3d = -(ptDist - ptArcCenter)
vtDelta.z = 0
' se il vettore non è nullo
If vtDelta.IsSmall() Then
' il grezzo è in battuta sul riferimento
Dim nContactColDisk As Integer = EgtGetFirstNameInGroup(EgtGetFirstNameInGroup(nFixtureId, SOLID), REF_DISK)
EgtSetColor(nContactColDisk, ReferenceContactColGreen)
Else
vtDelta = vtDelta.Glob(ccompoRawPartOutlineId)
' il vettore da restituire è nullo, quindi lo inizializzo
If vtRefMove.IsSmall() Then
vtRefMove = vtDelta
' altrimenti lo confronto
Else
' per ogni coordinata devo prendere il massimo in direzione opposta allo spostamento originale
' calcolo il versore nella direzione del movimento
Dim vtMoveVers As New Vector3d(vtOrigMove)
vtMoveVers.Normalize()
If (vtDelta * vtMoveVers) < (vtRefMove * vtMoveVers) Then
vtRefMove = vtDelta
End If
End If
End If
End If
' cancello segmento e offset
EgtErase(nDistLine)
EgtErase(ccompoRawPartOutlineOffsetId)
Else
' il grezzo non è in battuta sul riferimento
Dim nContactColDisk As Integer = EgtGetFirstNameInGroup(EgtGetFirstNameInGroup(nFixtureId, SOLID), REF_DISK)
EgtSetColor(nContactColDisk, ReferenceContactColRed)
End If
End If
' se non c'è sovrapposizione
ElseIf FixtureType(nFixtureId) = FIX_TYPE.REFERENCE Then
' il grezzo non è in battuta sul riferimento
Dim nContactColDisk As Integer = EgtGetFirstNameInGroup(EgtGetFirstNameInGroup(nFixtureId, SOLID), REF_DISK)
EgtSetColor(nContactColDisk, ReferenceContactColRed)
End If
nFixtureId = EgtGetNextFixture(nFixtureId)
End While
' se non ci sono ventose sotto il grezzo
If Not bIsFixtureUnderRawPart Then
' verifico che il grezzo sia ad altezza tavola
If dRawPartMin.z <> 0 Then
Dim vtMove As New Vector3d(0, 0, -dRawPartMin.z)
EgtMoveRawPart(nRawId, vtMove)
End If
Else
' se ci sono verifico che l'altezza del grezzo sia quella della ventosa più alta
If Math.Abs(dRawPartMin.z - dMaxFixtureHeight) > EPS_SMALL Then
Dim vtMove As New Vector3d(0, 0, dMaxFixtureHeight - dRawPartMin.z)
EgtMoveRawPart(nRawId, vtMove)
End If
End If
Return True
End Function
' Funzione che verifica se asse o sottoasse di tavola (e quindi barra o carrello)
Friend Shared Function VerifyTableAxis( nObjId As Integer) As Boolean
' Verifico se asse
Dim sObjName As String = ""
If Not EgtGetName( nObjId, sObjName) OrElse EgtGetAxisId( sObjName) = GDB_ID.NULL Then Return False
' Recupero il padre
Dim nParId As Integer = EgtGetParent( nObjId)
Dim sParName As String = ""
If Not EgtGetName( nParId, sParName) Then Return False
' Verifico se tavola
If EgtGetTableId( sParName) <> GDB_ID.NULL Then Return True
' Verifico se asse di tavola
Return VerifyTableAxis( nParId)
End Function
' Funzione che verifica i movimenti della barra
Private Shared Function VerifyBarPosition(nMoveId As Integer, vtMove As Vector3d) As Boolean
' Nome dell'asse
Dim sName As String = ""
If Not EgtGetName( nMoveId, sName) Then Return False
' Recupero la direzione di spostamento
Dim vtDir As New Vector3d
If Not EgtGetAxisDir( sName, VtDir) Then Return False
' Recupero la corsa
Dim dAxMin As Double = 0
Dim dAxMax As Double = 0
If Not EgtGetAxisMin( sName, dAxMin) OrElse Not EgtGetAxisMax( sName, dAxMax) Then Return False
' Recupero dati barra corrente
Dim dCurrBarPos As Double = 0
Dim dCurrBarMEnc As Double = 0
Dim dCurrBarPEnc As Double = 0
GetBarExtreme(nMoveId, dCurrBarPos, dCurrBarMEnc, dCurrBarPEnc)
' Recupero dati eventuale barra precedente
Dim sPrevBarName As String = ""
If EgtGetInfo( nMoveId, PREV, sPrevBarName) Then
Dim nPrevBarId As Integer = EgtGetAxisId( sPrevBarName)
Dim dPrevBarPos As Double = 0
Dim dPrevBarMEnc As Double = 0
Dim dPrevBarPEnc As Double = 0
If Not GetBarExtreme(nPrevBarId, dPrevBarPos, dPrevBarMEnc, dPrevBarPEnc) Then Return False
dAxMin = Math.Max( dAxMin, dPrevBarPos + dPrevBarPEnc + dCurrBarMEnc)
End If
' Recupero dati eventuale barra successiva
Dim sNextBarName As String = ""
If EgtGetInfo( nMoveId, NEXT_, sNextBarName) Then
Dim nNextBarId As Integer = EgtGetAxisId( sNextBarName)
Dim dNextBarPos As Double = 0
Dim dNextBarMEnc As Double = 0
Dim dNextBarPEnc As Double = 0
if Not GetBarExtreme(nNextBarId, dNextBarPos, dNextBarMEnc, dNextBarPEnc) Then Return False
dAxMax = Math.Min( dAxMax, dNextBarPos - dNextBarMEnc - dCurrBarPEnc)
End If
' Limito lo spostamento alle corse ammesse
If dAxMax < dAxMin Then Return False
Dim dNewBarPos As Double = dCurrBarPos + vtMove * vtDir
dNewBarPos = Math.Min( Math.Max( dNewBarPos,dAxMin), dAxMax)
' Eseguo lo spostamento
EgtMoveDispAxis( sName, dNewBarPos)
Dim vtRealMove As Vector3d = ( dNewBarPos - dCurrBarPos) * vtDir
UpdateFixturesForDispAxisMove( sName, vtRealMove)
Return True
End Function
Private Shared Function GetBarExtreme(nMoveId As Integer, ByRef dPos As Double, ByRef dMEnc As Double, ByRef dPEnc As Double) As Boolean
' Recupero la posizione
Dim sName As String = ""
If Not EgtGetName( nMoveId, sName) OrElse Not EgtGetAxisPos( sName, dPos) Then Return False
' Recupero ingombro negativo
dMEnc = 0
EgtGetInfo(nMoveId, MDIST, dMEnc)
' recupero ingombro positivo
dPEnc = 0
EgtGetInfo(nMoveId, PDIST, dPEnc)
Return True
End Function
' Funzione che verifica l'agganciamento dei sottopezzi
Private Shared Function VerifyHookFixture(nMoveId As Integer, ByRef vtMove As Vector3d, ptCurr As Point3d, bInPlace As Boolean) As Boolean
' cerco punto hook sulla ventosa
Dim nFixtSolidId As Integer = EgtGetFirstNameInGroup(nMoveId, SOLID)
Dim nFixtHookId As Integer = EgtGetFirstNameInGroup(nFixtSolidId, HOOK)
' leggo tipo e classe
Dim nFixtHookType As HOOKTYPE = HOOKTYPE.FREE
Dim sType As String = ""
EgtGetInfo(nFixtHookId, TYPE, sType)
If sType.Equals(POINT) Then
nFixtHookType = HOOKTYPE.POINT
ElseIf sType.Equals(LINE) Then
nFixtHookType = HOOKTYPE.LINE
Else 'FREE
' esco perchè non devo cercare alcun punto
Return True
End If
Dim nFixtHookClass As Integer = 0
EgtGetInfo(nFixtHookId, CLASS_, nFixtHookClass)
' recupero punto di hook
Dim ptFixtHook As Point3d
EgtStartPoint(nFixtHookId, GDB_ID.ROOT, ptFixtHook)
' calcolo vtMove nel caso normale
If bInPlace Then
ptCurr = ptFixtHook - m_vtHook
ElseIf Not IsNothing(ptCurr) Then
vtMove = ptCurr + m_vtHook - ptFixtHook
Else
ptCurr = ptFixtHook - m_vtHook + vtMove
End If
' Variabili per tenere da parte l'entità, la distanza e il punto di hook più vicino alla ventosa
Dim nNearestHookId As Integer = GDB_ID.NULL
Dim dNearestHookDist As Double = 99999999
Dim ptNearestHook As Point3d = Nothing
' Recupero Id tavola corrente
Dim sTableName As String = ""
EgtGetTableName(sTableName)
Dim nTableId As Integer = EgtGetTableId(sTableName)
' *** Cerco hook su tavola ***
Dim nTableSolidId As Integer = EgtGetFirstNameInGroup(nTableId, SOLID)
Dim nCurrHookId As Integer = EgtGetFirstNameInGroup(nTableSolidId, HOOK)
While nCurrHookId <> GDB_ID.NULL
HookAnalyzer(nCurrHookId, nFixtHookType, nFixtHookClass, ptCurr + m_vtHook, nMoveId, nNearestHookId, dNearestHookDist, ptNearestHook)
nCurrHookId = EgtGetNextName(nCurrHookId, HOOK)
End While
' *** Cerco hook su barre fisse ***
Dim nTableFixedId As Integer = EgtGetFirstNameInGroup(nTableId, FIXED)
While nTableFixedId <> GDB_ID.NULL
nCurrHookId = EgtGetFirstNameInGroup(nTableFixedId, HOOK)
While nCurrHookId <> GDB_ID.NULL
HookAnalyzer(nCurrHookId, nFixtHookType, nFixtHookClass, ptCurr + m_vtHook, nMoveId, nNearestHookId, dNearestHookDist, ptNearestHook)
nCurrHookId = EgtGetNextName(nCurrHookId, HOOK)
End While
nTableFixedId = EgtGetNextName(nTableFixedId, FIXED)
End While
' *** Cerco hook su barre mobili ***
Dim nBarId As Integer = EgtGetFirstGroupInGroup(nTableId)
While nBarId <> GDB_ID.NULL
Dim sBarName As String = ""
If EgtGetName( nBarId, sBarName) AndAlso EgtGetAxisId( sBarName) <> GDB_ID.NULL Then
nCurrHookId = EgtGetFirstNameInGroup(nBarId, HOOK)
While nCurrHookId <> GDB_ID.NULL
HookAnalyzer(nCurrHookId, nFixtHookType, nFixtHookClass, ptCurr + m_vtHook, nMoveId, nNearestHookId, dNearestHookDist, ptNearestHook)
nCurrHookId = EgtGetNextName(nCurrHookId, HOOK)
End While
' Cerco su eventuali carrelli
Dim nCharId As Integer = EgtGetFirstGroupInGroup(nBarId)
While nCharId <> GDB_ID.NULL
Dim sCharName As String = ""
If EgtGetName( nCharId, sCharName) AndAlso EgtGetAxisId( sCharName) <> GDB_ID.NULL Then
nCurrHookId = EgtGetFirstNameInGroup(nCharId, DispositionUtility.HOOK)
While nCurrHookId <> GDB_ID.NULL
HookAnalyzer(nCurrHookId, nFixtHookType, nFixtHookClass, ptCurr + m_vtHook, nMoveId, nNearestHookId, dNearestHookDist, ptNearestHook)
nCurrHookId = EgtGetNextName(nCurrHookId, DispositionUtility.HOOK)
End While
End If
nCharId = EgtGetNextGroup(nCharId)
End While
End If
nBarId = EgtGetNextGroup(nBarId)
End While
' Se non ho trovato hook compatibili e liberi esco
If nNearestHookId = GDB_ID.NULL Then Return False
' Verifico se la distanza minima è inferiore al raggio dell'area di aggancio
Dim dHookTolerance As Double = 1
If Not bInPlace Then
dHookTolerance = EgtUILib.GetPrivateProfileDouble(S_FIXTURES, K_HOOKTOLERANCE, 50, IniFile.m_sCurrMachIniFilePath)
End If
If dNearestHookDist > dHookTolerance Then Return False
' Sostituisco spostamento mouse con spostamento ad hook
vtMove = ptNearestHook - ptFixtHook
m_nUsedHookId = nNearestHookId
' Segno hook come utilizzato
SetHookUsed(m_nUsedHookId, nMoveId, True)
Return True
End Function
' Funzioni gestione tabella degli Hook
Private Shared Function AddOneHookData( nHookId As Integer, sParent As String, bParentAxis As Boolean) As Boolean
Dim sHook As String = ""
EgtGetName( nHookId, sHook)
Dim sGrParentAxis As String = ""
If bParentAxis Then
Dim nIdGrParent As Integer = EgtGetParent( EgtGetParent( nHookId))
Dim sParentName As String = ""
If EgtGetName( nIdGrParent, sParentName) AndAlso EgtGetAxisId( sParentName) = nIdGrParent Then
sGrParentAxis = sParentName
End If
End If
Dim nClass As Integer = 0
EgtGetInfo(nHookId, CLASS_, nClass)
Dim nType As Integer = EgtGetType( nHookId)
If nType = GDB_TY.GEO_POINT Then
Dim ptP As Point3d
EgtStartPoint( nHookId, GDB_ID.ROOT, ptP)
Dim hdCurr As New HookData( sHook, sParent, bParentAxis, sGrParentAxis, nHookId, ptP, nClass)
m_vHookData.Add( hdCurr)
Return True
Else If nType = GDB_TY.CRV_LINE Then
Dim ptP1 As Point3d
EgtStartPoint( nHookId, GDB_ID.ROOT, ptP1)
Dim ptP2 As Point3d
EgtEndPoint( nHookId, GDB_ID.ROOT, ptP2)
Dim hdCurr As New HookData( sHook, sParent, bParentAxis, sGrParentAxis, nHookId, ptP1, ptP2, nClass)
m_vHookData.Add( hdCurr)
Return True
End If
Return False
End Function
Private Shared Sub PrepareHookData()
' Pulisco lista di Hook
m_vHookData.Clear()
' Recupero Id tavola corrente
Dim sTableName As String = ""
EgtGetTableName(sTableName)
Dim nTableId As Integer = EgtGetTableId(sTableName)
' *** Cerco hook su tavola ***
Dim nTableSolidId As Integer = EgtGetFirstNameInGroup(nTableId, SOLID)
Dim nCurrHookId As Integer = EgtGetFirstNameInGroup(nTableSolidId, HOOK)
While nCurrHookId <> GDB_ID.NULL
AddOneHookData( nCurrHookId, SOLID, False)
nCurrHookId = EgtGetNextName(nCurrHookId, HOOK)
End While
' *** Cerco hook su barre fisse ***
Dim nTableFixedId As Integer = EgtGetFirstNameInGroup(nTableId, FIXED)
While nTableFixedId <> GDB_ID.NULL
Dim sName As String = ""
EgtGetName( nTableFixedId, sName)
nCurrHookId = EgtGetFirstNameInGroup(nTableFixedId, HOOK)
While nCurrHookId <> GDB_ID.NULL
AddOneHookData( nCurrHookId, sName, False)
nCurrHookId = EgtGetNextName(nCurrHookId, HOOK)
End While
nTableFixedId = EgtGetNextName(nTableFixedId, FIXED)
End While
' *** Cerco hook su barre mobili ***
Dim nBarId As Integer = EgtGetFirstGroupInGroup(nTableId)
While nBarId <> GDB_ID.NULL
Dim sBarName As String = ""
If EgtGetName( nBarId, sBarName) AndAlso EgtGetAxisId( sBarName) = nBarId Then
nCurrHookId = EgtGetFirstNameInGroup(nBarId, HOOK)
While nCurrHookId <> GDB_ID.NULL
AddOneHookData( nCurrHookId, sBarName, True)
nCurrHookId = EgtGetNextName(nCurrHookId, HOOK)
End While
' Cerco su eventuali carrelli
Dim nCharId As Integer = EgtGetFirstGroupInGroup(nBarId)
While nCharId <> GDB_ID.NULL
Dim sCharName As String = ""
If EgtGetName( nCharId, sCharName) AndAlso EgtGetAxisId( sCharName) = nCharId Then
nCurrHookId = EgtGetFirstNameInGroup(nCharId, DispositionUtility.HOOK)
While nCurrHookId <> GDB_ID.NULL
AddOneHookData( nCurrHookId, sCharName, True)
nCurrHookId = EgtGetNextName(nCurrHookId, HOOK)
End While
End If
nCharId = EgtGetNextGroup(nCharId)
End While
End If
nBarId = EgtGetNextGroup(nBarId)
End While
End Sub
Private Shared Sub PrepareHookedFixtures()
' Ciclo su tutte le fixtures in tavola
Dim nFixtId As Integer = EgtGetFirstFixture()
While nFixtId <> GDB_ID.NULL
Dim nHookId As Integer = EgtGetFirstNameInGroup( EgtGetFirstNameInGroup( nFixtId, SOLID), HOOK)
Dim ptP As Point3d
If EgtStartPoint( nHookId, GDB_ID.ROOT, ptP) Then
For Each hkCurr As HookData In m_vHookData
If hkCurr.m_nType = HOOKTYPE.POINT Then
If Point3d.SqDistXY( ptP, hkCurr.m_ptP1) < 1 Then
hkCurr.m_nHooked = nFixtId
Exit For
End If
ElseIf hkCurr.m_nType = HOOKTYPE.LINE Then
Dim dSqDist As Double = Point3d.SqDistXY( ptP, DistPointSegment( ptP, hkCurr.m_ptP1, hkCurr.m_ptP2))
If dSqDist < 1 Then
AddHookUsed( hkCurr.m_nId, nFixtId)
Exit For
End If
End If
Next
End If
nFixtId = EgtGetNextFixture( nFixtId)
End While
End Sub
Friend Shared Sub InitHookData()
' Carico i dati degli agganci
PrepareHookData()
' Determino eventuali fixtures agganciate
PrepareHookedFixtures()
' Log di debug
If Map.refMainWindowVM.DebugLevel() >= 4 then
EgtOutLog( " *** HOOK DATA TABLE ***")
Dim sCurrParent As String = ""
For Each hkCurr As HookData In m_vHookData
If hkCurr.m_sParent <> sCurrParent Then
sCurrParent = hkCurr.m_sParent
If String.IsNullOrWhiteSpace( hkCurr.m_sGrParentAxis) Then
EgtOutLog( sCurrParent & If( hkCurr.m_bParentAxis, " Axis", " Fixed"))
Else
EgtOutLog( sCurrParent & " (" & hkCurr.m_sGrParentAxis & ") Axis")
End If
End If
If hkCurr.m_nType = HOOKTYPE.POINT Then
EgtOutLog( " " & hkCurr.m_sName & " (" & hkCurr.m_nId &
") Point(" & hkCurr.m_ptP1.ToString() & ") Class=" & hkCurr.m_nClass &
If( hkCurr.m_nHooked = GDB_ID.NULL, " Free", " Fixt " & hkCurr.m_nHooked))
Else If hkCurr.m_nType = HOOKTYPE.LINE Then
EgtOutLog( " " & hkCurr.m_sName & " (" & hkCurr.m_nId &
") Line(" & hkCurr.m_ptP1.ToString() & "),(" & hkCurr.m_ptP2.ToString() & ") Class=" & hkCurr.m_nClass &
If( String.IsNullOrWhiteSpace( hkCurr.m_sHooked), " Free", " Fixt " & hkCurr.m_sHooked))
End If
Next
End If
End Sub
Friend Shared Function GetHookClass( nHookId As Integer) As Integer
For Each hkCurr As HookData In m_vHookData
If hkCurr.m_nId = nHookId Then Return hkCurr.m_nClass
Next
Return -1
End Function
Friend Shared Function GetIsHookUsed( nHookId As Integer) As Boolean
For Each hkCurr As HookData In m_vHookData
If hkCurr.m_nId = nHookId Then
If hkCurr.m_nType = HOOKTYPE.POINT Then
Return ( hkCurr.m_nHooked <> GDB_ID.NULL)
Else
Return Not String.IsNullOrWhiteSpace( hkCurr.m_sHooked)
End If
End If
Next
Return True
End Function
Friend Shared Function GetHookUsed( nHookId As Integer, nFixtureId As Integer) As Integer
For Each hkCurr As HookData In m_vHookData
If hkCurr.m_nId = nHookId Then
If hkCurr.m_nType = HOOKTYPE.POINT Then
If hkCurr.m_nHooked = nFixtureId then
Return hkCurr.m_nHooked
End If
Else
Dim sFixtureId As String = nFixtureId.ToString & ";"
If hkCurr.m_sHooked.IndexOf( sFixtureId) <> -1 Then
Return nFixtureId
End If
End If
Return GDB_ID.NULL
End If
Next
Return GDB_ID.NULL
End Function
Friend Shared Function SetHookUsed( nHookId As Integer, nFixtureId As Integer) As Boolean
' Rimuovo da eventuale precedente aggancio
RemoveFixtureFromHook( nFixtureId)
' Inserisco in nuovo aggancio
For Each hkCurr As HookData In m_vHookData
If hkCurr.m_nId = nHookId Then
If hkCurr.m_nType = HOOKTYPE.POINT Then
m_nPrevFixtureId = hkCurr.m_nHooked
hkCurr.m_nHooked = nFixtureId
Return True
Else
Return False
End If
End If
Next
Return False
End Function
Friend Shared Function ResetHookUsed( nHookId As Integer) As Boolean
For Each hkCurr As HookData In m_vHookData
If hkCurr.m_nId = nHookId Then
If hkCurr.m_nType = HOOKTYPE.POINT Then
hkCurr.m_nHooked = GDB_ID.NULL
Return True
Else
Return False
End If
End If
Next
Return False
End Function
Friend Shared Function AddHookUsed( nHookId As Integer, nFixtureId As Integer) As Boolean
' Rimuovo da eventuale precedente aggancio
RemoveFixtureFromHook( nFixtureId)
' Inserisco in nuovo aggancio
For Each hkCurr As HookData In m_vHookData
If hkCurr.m_nId = nHookId Then
If hkCurr.m_nType = HOOKTYPE.POINT Then
Return False
Else
' Verifico non sia già presente
Dim SplitInfo() As String = hkCurr.m_sHooked.Split(";"c)
For Each sInfo As String In SplitInfo
Dim nInfo As Integer = GDB_ID.NULL
Integer.TryParse(sInfo, nInfo)
If nInfo = nFixtureId Then Return True
Next
' Lo aggiungo
hkCurr.m_sHooked &= nFixtureId.ToString() & ";"
Return True
End If
End If
Next
Return False
End Function
Friend Shared Function RemoveHookUsed( nHookId As Integer, nFixtureId As Integer) As Boolean
For Each hkCurr As HookData In m_vHookData
If hkCurr.m_nId = nHookId Then
If hkCurr.m_nType = HOOKTYPE.POINT Then
Return False
Else
' Se lo trovo, lo tolgo dall'elenco
Dim SplitInfo() As String = hkCurr.m_sHooked.Split(";"c)
hkCurr.m_sHooked = ""
For Each sInfo As String In SplitInfo
Dim nInfo As Integer
If Integer.TryParse(sInfo, nInfo) AndAlso nInfo <> nFixtureId Then
hkCurr.m_sHooked &= sInfo & ";"
End If
Next
Return True
End If
End If
Next
Return False
End Function
Friend Shared Function RemoveFixtureFromHook( nFixtureId As Integer) As Boolean
Dim sFixtureId As String = nFixtureId.ToString & ";"
For Each hkCurr As HookData In m_vHookData
If hkCurr.m_nType = HOOKTYPE.POINT Then
If hkCurr.m_nHooked = nFixtureId Then
hkCurr.m_nHooked = GDB_ID.NULL
Return True
End If
Else
Dim nInd As Integer = hkCurr.m_sHooked.IndexOf( sFixtureId)
If nInd <> -1 Then
hkCurr.m_sHooked = hkCurr.m_sHooked.Remove( nInd, sFixtureId.Length())
Return True
End If
End If
Next
Return False
End Function
Private Shared Function UpdateFixturesForDispAxisMove( sName As String, vtMove As Vector3d) As Boolean
For Each hkCurr As HookData In m_vHookData
If hkCurr.m_sParent = sName OrElse hkCurr.m_sGrParentAxis = sName Then
' Aggiorno posizione di aggancio
If hkCurr.m_nType = HOOKTYPE.POINT Then
hkCurr.m_ptP1 += vtMove
Else ' HOOKTYPE.LINE
hkCurr.m_ptP1 += vtMove
hkCurr.m_ptP2 += vtMove
End If
' Sposto anche eventuali ventosa/e agganciata/e
If hkCurr.m_nType = HOOKTYPE.POINT Then
If hkCurr.m_nHooked <> GDB_ID.NULL Then EgtMoveFixture( hkCurr.m_nHooked, vtMove)
Else ' HOOKTYPE.LINE
Dim SplitInfo() As String = hkCurr.m_sHooked.Split(";"c)
For Each sInfo As String In SplitInfo
Dim nInfo As Integer = GDB_ID.NULL
If Integer.TryParse(sInfo, nInfo) Then
EgtMoveFixture( nInfo, vtMove)
End If
Next
End If
End If
Next
Return True
End Function
' Funzioni che leggono e settano le ventose agganciate agli hook
Private Shared Sub SetHookUsed(nHookId As Integer, nFixtureId As Integer, bUsed As Boolean)
' cerco punto hook sulla ventosa
Dim nFixtSolidId As Integer = EgtGetFirstNameInGroup(nFixtureId, SOLID)
Dim nFixtHookId As Integer = EgtGetFirstNameInGroup(nFixtSolidId, HOOK)
' leggo tipo e classe
Dim nFixtHookType As HOOKTYPE = HOOKTYPE.FREE
Dim sType As String = ""
EgtGetInfo(nFixtHookId, TYPE, sType)
If sType.Equals(POINT) Then
nFixtHookType = HOOKTYPE.POINT
ElseIf sType.Equals(LINE) Then
nFixtHookType = HOOKTYPE.LINE
Else 'FREE
nFixtHookType = HOOKTYPE.FREE
' esco perchè non devo cercare alcun punto
Return
End If
Select Case nFixtHookType
Case HOOKTYPE.POINT
If bUsed Then
SetHookUsed(nHookId, nFixtureId)
Else
ResetHookUsed(nHookId)
End If
Case HOOKTYPE.LINE
If bUsed Then
AddHookUsed( nHookId, nFixtureId)
Else
RemoveHookUsed( nHookId, nFixtureId)
End If
End Select
End Sub
' Funzione che analizza gli hook
Private Shared Sub HookAnalyzer(nCurrHookId As Integer, nFixtHookType As Integer, nFixtHookClass As Integer,
ptFixtHook As Point3d, nMoveId As Integer,
ByRef nNearestHookId As Integer, ByRef dNearestHookDist As Double, ByRef ptNearestHook As Point3d)
' Verifico se del tipo giusto
Dim nTableHookType As GDB_TY = EgtGetType(nCurrHookId)
If Not (nTableHookType = GDB_TY.GEO_POINT And nFixtHookType = HOOKTYPE.POINT) AndAlso
Not (nTableHookType = GDB_TY.CRV_LINE And nFixtHookType = HOOKTYPE.LINE) Then
Return
End If
' Verifico se della stessa classe
Dim nTableHookClass As Integer = GetHookClass( nCurrHookId)
If nTableHookClass <> nFixtHookClass Then
Return
End If
Dim dDist As Double = 0
' punto a distanza minima sull'hook
Dim ptCurrHook As Point3d
If nTableHookType = GDB_TY.GEO_POINT Then
' verifico se utilizzato
Dim nTableHookUsed As Integer = GetHookUsed( nCurrHookId, nMoveId)
If nTableHookUsed <> GDB_ID.NULL AndAlso nTableHookUsed <> nMoveId Then
Return
End If
If nTableHookUsed = nMoveId Then
SetHookUsed(nCurrHookId, nMoveId, False)
m_nPrevUsedHookId = nCurrHookId
End If
' calcolo distanza punto hook tavola dal punto hook della ventosa
EgtStartPoint(nCurrHookId, GDB_ID.ROOT, ptCurrHook)
dDist = Point3d.DistXY(ptCurrHook, ptFixtHook)
ElseIf nTableHookType = GDB_TY.CRV_LINE Then
' verifico se utilizzato
Dim nTableHookUsed As Integer = GetHookUsed( nCurrHookId, nMoveId)
If nTableHookUsed <> GDB_ID.NULL AndAlso nTableHookUsed <> nMoveId Then
Return
End If
If nTableHookUsed = nMoveId Then
SetHookUsed(nCurrHookId, nMoveId, False)
m_nPrevUsedHookId = nCurrHookId
End If
' calcolo distanza linea hook tavola dal punto hook della ventosa
Dim ptL1 As Point3d : EgtStartPoint( nCurrHookId, GDB_ID.ROOT, ptL1)
Dim ptL2 As Point3d : EgtEndPoint( nCurrHookId, GDB_ID.ROOT, ptL2)
ptCurrHook = DistPointSegment( ptFixtHook, ptL1, ptL2)
dDist = Point3d.DistXY( ptFixtHook, ptCurrHook)
Else
Return
End If
' se minore della distanza minima, sostituisco il valore
If dDist < dNearestHookDist Then
nNearestHookId = nCurrHookId
dNearestHookDist = dDist
ptNearestHook = ptCurrHook
End If
End Sub
' Funzione che fissa il vettore di hook
Friend Shared Sub VtHookFinder(nFixtureId As Integer, ptCurr As Point3d)
' cerco punto hook sulla ventosa
Dim nFixtSolidId As Integer = EgtGetFirstNameInGroup(nFixtureId, SOLID)
Dim nFixtHookId As Integer = EgtGetFirstNameInGroup(nFixtSolidId, HOOK)
' recupero punto di hook
Dim ptFixtHook As Point3d
EgtStartPoint(nFixtHookId, GDB_ID.ROOT, ptFixtHook)
m_vtHook = ptFixtHook - ptCurr
End Sub
' Funzione che restituisce il tipo di sottopezzo passatogli
Friend Shared Function FixtureType(nFixtureId As Integer) As FIX_TYPE
Dim sFixtureType As String = String.Empty
EgtGetInfo(nFixtureId, EgtUILib.FIX_TYPE, sFixtureType)
Select Case sFixtureType
Case FIX_VAC
Return FIX_TYPE.VACUUM
Case FIX_REF
Return FIX_TYPE.REFERENCE
Case FIX_VIS
Return FIX_TYPE.VISE
End Select
Return FIX_TYPE.NULL
End Function
Public Enum FIX_TYPE As Integer
NULL = 0
VACUUM = 1
REFERENCE = 2
VISE = 3
End Enum
' Funzione che seleziona i sottopezzi del grezzo passatogli
Friend Shared Sub SelectRawPartFixture(nRawPartId As Integer)
Dim bboxRawPart As New BBox3d
Dim bboxFixture As New BBox3d
' ricavo solido del grezzo
Dim nRawPartSolid As Integer = EgtGetFirstNameInGroup(nRawPartId, RAWSOLID)
' ne ricavo il bbox
EgtGetBBoxGlob(nRawPartSolid, GDB_BB.ONLY_VISIBLE, bboxRawPart)
Dim nFixtureId As Integer = EgtGetFirstFixture()
While nFixtureId <> GDB_ID.NULL
' ricavo il bbox del sottopezzo
EgtGetBBoxGlob(nFixtureId, GDB_BB.ONLY_VISIBLE, bboxFixture)
' verifico se si sovrappongono
If bboxRawPart.OverlapsXY(bboxFixture) Then
' seleziono il sottopezzo
EgtSelectObj(nFixtureId)
End If
nFixtureId = EgtGetNextFixture(nFixtureId)
End While
End Sub
' Funzione che deseleziona i sottopezzi del grezzo passatogli
Friend Shared Sub DeselectRawPartFixture(nRawPartId As Integer)
Dim bboxRawPart As New BBox3d
Dim bboxFixture As New BBox3d
' ricavo solido del grezzo
Dim nRawPartSolid As Integer = EgtGetFirstNameInGroup(nRawPartId, RAWSOLID)
' ne ricavo il bbox
EgtGetBBoxGlob(nRawPartSolid, GDB_BB.ONLY_VISIBLE, bboxRawPart)
Dim nFixtureId As Integer = EgtGetFirstFixture()
While nFixtureId <> GDB_ID.NULL
' ricavo il bbox del sottopezzo
EgtGetBBoxGlob(nFixtureId, GDB_BB.ONLY_VISIBLE, bboxFixture)
' verifico se si sovrappongono
If bboxRawPart.OverlapsXY(bboxFixture) Then
' deseleziono il pezzo
EgtDeselectObj(nFixtureId)
End If
nFixtureId = EgtGetNextFixture(nFixtureId)
End While
End Sub
' Costante che identifica l'informazione contenente il Frame3d originale del pezzo
Private Const ORIG_FRAME As String = "ORIGFRAME"
' Funzione che visualizza i pezzi disponibili e li sposta sotto il grezzo
Friend Shared Sub ShowParts()
' prendo riferimento tavola
' ciclo sui pezzi
Dim nPartId As Integer = EgtGetFirstPart()
While nPartId <> GDB_ID.NULL
' mi faccio dare il riferimento del pezzo prima si spostarlo
Dim frOrigPart As New Frame3d
EgtGetGroupGlobFrame(nPartId, frOrigPart)
' salvo il riferimento originale
EgtSetInfo(nPartId, ORIG_FRAME, frOrigPart)
'
' Attivo la visualizzazione del pezzo mettendolo in modalità standard
EgtSetStatus(nPartId, GDB_ST.ON_)
' prendo il pezzo successivo
nPartId = EgtGetNextPart(nPartId)
End While
EgtDraw()
End Sub
' Funzione che rimette a posto i pezzi
Friend Shared Sub HideParts()
' ciclo sui pezzi
Dim nPartId As Integer = EgtGetFirstPart()
While nPartId <> GDB_ID.NULL
' recupero il riferimento originale
Dim frOrigPart As New Frame3d
EgtGetInfo(nPartId, ORIG_FRAME, frOrigPart)
' lo ripristino
EgtChangeGroupFrame(nPartId, frOrigPart)
' Attivo la visualizzazione del pezzo mettendolo in modalità standard
EgtSetStatus(nPartId, GDB_ST.OFF)
' prendo il pezzo successivo
nPartId = EgtGetNextPart(nPartId)
End While
End Sub
End Class