a8e2272a88
- aggiunta funzione per nascondere tutte le lavorazioni e usata al termine di simulazioe e generazione.
396 lines
17 KiB
VB.net
396 lines
17 KiB
VB.net
Imports EgtUILib
|
|
|
|
Public Module CamAuto
|
|
|
|
Private m_MainWindow As MainWindow = Application.Current.MainWindow
|
|
|
|
Friend Function AddMachinings(nPartId As Integer, bPreview As Boolean, bToolpath As Boolean) As Boolean
|
|
EgtLuaCreateGlobTable("CAM")
|
|
SetLuaStandardCamParams()
|
|
EgtLuaSetGlobIntVar("CAM.PARTID", nPartId)
|
|
EgtLuaSetGlobBoolVar("CAM.PREVIEW", bPreview)
|
|
EgtLuaSetGlobBoolVar("CAM.TOOLPATH", bToolpath)
|
|
Dim bOk As Boolean = EgtLuaExecFile(m_MainWindow.GetCamAutoDir() & "\CamAuto.lua")
|
|
bOk = bOk AndAlso EgtLuaCallFunction("CAM.Add")
|
|
Dim nErr As Integer = 999
|
|
EgtLuaGetGlobIntVar("CAM.ERR", nErr)
|
|
EgtLuaResetGlobVar("CAM")
|
|
If nErr <> 0 Then
|
|
bOk = False
|
|
EgtOutLog("Error in CamAuto : " & nErr.ToString())
|
|
End If
|
|
m_MainWindow.m_CurrentProjectPageUC.ResetOrderMachiningFlag()
|
|
Return bOk
|
|
End Function
|
|
|
|
Friend Function EraseMachinings(nPartId As Integer) As Boolean
|
|
EgtLuaCreateGlobTable("CAM")
|
|
EgtLuaSetGlobIntVar("CAM.PARTID", nPartId)
|
|
Dim bOk As Boolean = EgtLuaExecFile(m_MainWindow.GetCamAutoDir() & "\CamAuto.lua")
|
|
bOk = bOk AndAlso EgtLuaCallFunction("CAM.Erase")
|
|
Dim nErr As Integer = 999
|
|
EgtLuaGetGlobIntVar("CAM.ERR", nErr)
|
|
EgtLuaResetGlobVar("CAM")
|
|
If nErr <> 0 Then
|
|
bOk = False
|
|
EgtOutLog("Error in CamAuto : " & nErr.ToString())
|
|
End If
|
|
m_MainWindow.m_CurrentProjectPageUC.ResetOrderMachiningFlag()
|
|
Return bOk
|
|
End Function
|
|
|
|
Friend Function UpdateAllMachiningsToolpaths() As Boolean
|
|
EgtLuaCreateGlobTable("CAM")
|
|
SetLuaStandardCamParams()
|
|
Dim bOk As Boolean = EgtLuaExecFile(m_MainWindow.GetCamAutoDir() & "\CamAuto.lua")
|
|
bOk = bOk AndAlso EgtLuaCallFunction("CAM.UpdateAllTp")
|
|
Dim nErr As Integer = 999
|
|
EgtLuaGetGlobIntVar("CAM.ERR", nErr)
|
|
EgtLuaResetGlobVar("CAM")
|
|
If nErr <> 0 Then
|
|
bOk = False
|
|
EgtOutLog("Error in CamAuto : " & nErr.ToString())
|
|
End If
|
|
Return bOk
|
|
End Function
|
|
|
|
Friend Function SortAllMachinings() As Boolean
|
|
EgtLuaCreateGlobTable("CAM")
|
|
SetLuaStandardCamParams()
|
|
Dim bOk As Boolean = EgtLuaExecFile(m_MainWindow.GetCamAutoDir() & "\CamAuto.lua")
|
|
bOk = bOk AndAlso EgtLuaCallFunction("CAM.Sort")
|
|
Dim nErr As Integer = 999
|
|
EgtLuaGetGlobIntVar("CAM.ERR", nErr)
|
|
EgtLuaResetGlobVar("CAM")
|
|
If nErr <> 0 Then
|
|
bOk = False
|
|
EgtOutLog("Error in CamAuto : " & nErr.ToString())
|
|
End If
|
|
Return bOk
|
|
End Function
|
|
|
|
Friend Function DeactivateAllMachinings() As Boolean
|
|
Return EgtSetAllOperationsMode(False)
|
|
End Function
|
|
|
|
Friend Function ActivateAllMachinings() As Boolean
|
|
Return EgtSetAllOperationsMode(True)
|
|
End Function
|
|
|
|
Friend Function HideAllMachinings() As Boolean
|
|
Dim nId As Integer = EgtGetFirstOperation()
|
|
While nId <> GDB_ID.NULL
|
|
If EgtGetOperationType(nId) <> MCH_OY.DISP Then
|
|
EgtSetOperationStatus(nId, False)
|
|
End If
|
|
nId = EgtGetNextOperation(nId)
|
|
End While
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function TestAllMachiningsForStrict() As Boolean
|
|
Dim bModified As Boolean = False
|
|
' Affondamento ridotto
|
|
Dim dReducedDepth As Double = GetPrivateProfileDouble(S_MACH_NEST, K_MACH_REDUCEDDEPTH, 1, m_MainWindow.GetMachIniFile())
|
|
' Ciclo sulle lavorazioni
|
|
Dim nOperId As Integer = EgtGetFirstOperation()
|
|
While nOperId <> GDB_ID.NULL
|
|
' verifico sia una lavorazione valida
|
|
If IsValidMachining(nOperId) Then
|
|
' verifica interferenza
|
|
Dim nFlag As Integer = FMI_TYPE.NONE
|
|
If Not VerifyComposedMachining(nOperId, nFlag) Then
|
|
nFlag = FMI_TYPE.LI Or FMI_TYPE.RM Or FMI_TYPE.LO
|
|
End If
|
|
' sistemazione lavorazione, se necessario
|
|
If AdjustMachining(nOperId, nFlag, dReducedDepth) Then
|
|
bModified = True
|
|
End If
|
|
End If
|
|
nOperId = EgtGetNextOperation(nOperId)
|
|
End While
|
|
Return bModified
|
|
End Function
|
|
|
|
Friend Function VerifyComposedMachining(nOperId As Integer, ByRef nFlag As Integer) As Boolean
|
|
' verifico sia una lavorazione
|
|
If Not EgtSetCurrMachining(nOperId) Then Return False
|
|
' determino eventuali lavorazioni inglobate
|
|
Dim vOthId As New List(Of Integer)
|
|
Dim sInfo As String = String.Empty
|
|
If EgtGetInfo(nOperId, INFO_MCH_OTHMID, sInfo) Then
|
|
Dim sItems() As String = sInfo.Split(",".ToCharArray)
|
|
For Each sId In sItems
|
|
vOthId.Add(CInt(sId))
|
|
Next
|
|
End If
|
|
' layer di origine
|
|
Dim sLay As String = String.Empty
|
|
EgtGetInfo(nOperId, "Lay", sLay)
|
|
' verifica interferenza
|
|
nFlag = FMI_TYPE.NONE
|
|
If sLay = "OutLoop" Then
|
|
Dim nRes As Integer = FMI_TYPE.LI Or FMI_TYPE.RM Or FMI_TYPE.LO
|
|
If Not EgtVerifyMachining(nOperId, nRes) Then Return False
|
|
nFlag = nFlag Or nRes
|
|
For Each nId As Integer In vOthId
|
|
nRes = FMI_TYPE.LI Or FMI_TYPE.RM Or FMI_TYPE.LO
|
|
If Not EgtVerifyMachining(nId, nRes) Then Return False
|
|
nFlag = nFlag Or nRes
|
|
Next
|
|
End If
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function AdjustMachining(nOperId As Integer, nFlag As Integer, dReducedDepth As Double) As Boolean
|
|
Dim bModified As Boolean = False
|
|
' abilitazione
|
|
Dim bEnabled As Boolean = Not EgtExistsInfo(nOperId, INFO_MCH_USER_OFF)
|
|
' restringo lavorazione abilitata ma con interferenza
|
|
If bEnabled And nFlag <> FMI_TYPE.NONE Then
|
|
Dim bStart As Boolean = (nFlag And FMI_TYPE.LI)
|
|
Dim bEnd As Boolean = (nFlag And FMI_TYPE.LO)
|
|
SetCutStrict(nOperId, bStart, bEnd)
|
|
' se risulta lavorazione vuota, provo a diminuire l'affondamento
|
|
If EgtIsMachiningEmpty() Then
|
|
ResetCutStrict(nOperId, bStart, bEnd)
|
|
SetCutDepth(nOperId, dReducedDepth)
|
|
' ripeto verifica
|
|
nFlag = FMI_TYPE.NONE
|
|
If Not VerifyComposedMachining(nOperId, nFlag) Then
|
|
nFlag = FMI_TYPE.LI Or FMI_TYPE.RM Or FMI_TYPE.LO
|
|
End If
|
|
' se non superata la stringo
|
|
If nFlag <> FMI_TYPE.NONE Then
|
|
bStart = (nFlag And FMI_TYPE.LI)
|
|
bEnd = (nFlag And FMI_TYPE.LO)
|
|
SetCutStrict(nOperId, bStart, bEnd)
|
|
End If
|
|
End If
|
|
bModified = True
|
|
End If
|
|
Return bModified
|
|
End Function
|
|
|
|
Friend Function SetCutDepth(nMchId As Integer, dDepth As Double) As Boolean
|
|
' Imposto la lavorazione corrente
|
|
If Not EgtSetCurrMachining(nMchId) Then Return False
|
|
' Imposto l'affondamento
|
|
EgtSetMachiningParam(MCH_MP.DEPTH, dDepth)
|
|
' Ricalcolo il preview
|
|
UpdateMachiningPreview(nMchId, True)
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function SetCutStrict(nMchId As Integer, bStart As Boolean, bEnd As Boolean) As Boolean
|
|
' Recupero sicurezza su tagli
|
|
Dim dSafeLen As Double = GetPrivateProfileDouble(S_MACH_NEST, K_MACH_SAFE_LEN_CUT, 0, m_MainWindow.GetMachIniFile())
|
|
' Imposto la lavorazione corrente
|
|
If Not EgtSetCurrMachining(nMchId) Then Return False
|
|
Dim bModif As Boolean = False
|
|
' Se richiesto, restringo l'attacco
|
|
If bStart Then
|
|
' Recupero tipo attacco originale e lo salvo se non già fatto
|
|
Dim nOriLeadIn As Integer = MCH_SAW_LI.CENT
|
|
EgtGetMachiningParam(MCH_MP.LEADINTYPE, nOriLeadIn)
|
|
If Not EgtExistsInfo(nMchId, INFO_MCH_ORILEADIN) Then
|
|
EgtSetInfo(nMchId, INFO_MCH_ORILEADIN, nOriLeadIn)
|
|
End If
|
|
' Se attacco cambiato, aggiorno e accorcio della sicurezza sui tagli
|
|
If nOriLeadIn <> MCH_SAW_LI.STRICT Then
|
|
EgtSetMachiningParam(MCH_MP.LEADINTYPE, MCH_SAW_LI.STRICT)
|
|
Dim dAddLen As Double = 0
|
|
EgtGetMachiningParam(MCH_MP.STARTADDLEN, dAddLen)
|
|
EgtSetMachiningParam(MCH_MP.STARTADDLEN, dAddLen - dSafeLen)
|
|
bModif = True
|
|
End If
|
|
End If
|
|
' Se richiesto, restringo l'uscita
|
|
If bEnd Then
|
|
' Recupero tipo uscita originale e lo salvo se non già fatto
|
|
Dim nOriLeadOut As Integer = MCH_SAW_LO.CENT
|
|
EgtGetMachiningParam(MCH_MP.LEADOUTTYPE, nOriLeadOut)
|
|
If Not EgtExistsInfo(nMchId, INFO_MCH_ORILEADOUT) Then
|
|
EgtSetInfo(nMchId, INFO_MCH_ORILEADOUT, nOriLeadOut)
|
|
End If
|
|
' Se uscita cambiata, aggiorno e accorcio della sicurezza sui tagli
|
|
If nOriLeadOut <> MCH_SAW_LO.STRICT Then
|
|
EgtSetMachiningParam(MCH_MP.LEADOUTTYPE, MCH_SAW_LO.STRICT)
|
|
Dim dAddLen As Double = 0
|
|
EgtGetMachiningParam(MCH_MP.ENDADDLEN, dAddLen)
|
|
EgtSetMachiningParam(MCH_MP.ENDADDLEN, dAddLen - dSafeLen)
|
|
bModif = True
|
|
End If
|
|
End If
|
|
' Se modificato, ricalcolo il preview
|
|
If bModif Then
|
|
UpdateMachiningPreview(nMchId, True)
|
|
End If
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function ResetCutStrict(nMchId As Integer, bStart As Boolean, bEnd As Boolean) As Boolean
|
|
' Recupero sicurezza su tagli
|
|
Dim dSafeLen As Double = GetPrivateProfileDouble(S_MACH_NEST, K_MACH_SAFE_LEN_CUT, 0, m_MainWindow.GetMachIniFile())
|
|
' Imposto la lavorazione corrente
|
|
If Not EgtSetCurrMachining(nMchId) Then Return False
|
|
Dim bModif As Boolean = False
|
|
' Se richiesto, ripristino l'attacco
|
|
If bStart Then
|
|
' Recupero tipo attacco originale
|
|
Dim nOriLeadIn As Integer = MCH_SAW_LI.CENT
|
|
EgtGetInfo(nMchId, INFO_MCH_ORILEADIN, nOriLeadIn)
|
|
Dim nCurrLeadIn As Integer = MCH_SAW_LI.CENT
|
|
EgtGetMachiningParam(MCH_MP.LEADINTYPE, nCurrLeadIn)
|
|
' Se attacco cambiato, aggiorno e allungo della sicurezza sui tagli
|
|
If nOriLeadIn <> nCurrLeadIn Then
|
|
EgtSetMachiningParam(MCH_MP.LEADINTYPE, nOriLeadIn)
|
|
Dim dAddLen As Double = 0
|
|
EgtGetMachiningParam(MCH_MP.STARTADDLEN, dAddLen)
|
|
EgtSetMachiningParam(MCH_MP.STARTADDLEN, dAddLen + dSafeLen)
|
|
bModif = True
|
|
End If
|
|
End If
|
|
' Se richiesto, ripristino l'uscita
|
|
If bEnd Then
|
|
' Recupero tipo uscita originale
|
|
Dim nOriLeadOut As Integer = MCH_SAW_LO.CENT
|
|
EgtGetInfo(nMchId, INFO_MCH_ORILEADOUT, nOriLeadOut)
|
|
Dim nCurrLeadOut As Integer = MCH_SAW_LO.CENT
|
|
EgtGetMachiningParam(MCH_MP.LEADOUTTYPE, nCurrLeadOut)
|
|
' Se uscita cambiata, aggiorno
|
|
If nOriLeadOut <> nCurrLeadOut Then
|
|
EgtSetMachiningParam(MCH_MP.LEADOUTTYPE, nOriLeadOut)
|
|
Dim dAddLen As Double = 0
|
|
EgtGetMachiningParam(MCH_MP.ENDADDLEN, dAddLen)
|
|
EgtSetMachiningParam(MCH_MP.ENDADDLEN, dAddLen + dSafeLen)
|
|
bModif = True
|
|
End If
|
|
End If
|
|
' Se modificato, ricalcolo il preview
|
|
If bModif Then
|
|
UpdateMachiningPreview(nMchId, True)
|
|
End If
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function UpdateMachiningPreview(nMchId As Integer, bMoveOnPart As Boolean) As Boolean
|
|
' Imposto la lavorazione corrente
|
|
If Not EgtSetCurrMachining(nMchId) Then Return False
|
|
' Ricalcolo il preview
|
|
EgtPreviewMachining(True)
|
|
' Se non devo spostarlo nel pezzo, esco
|
|
If Not bMoveOnPart Then
|
|
Return True
|
|
End If
|
|
' Indice gruppo di preview nella lavorazione
|
|
Dim nMchPvId As Integer = EgtGetFirstNameInGroup(nMchId, NAME_PREVIEW)
|
|
' Indice gruppo di preview nel pezzo
|
|
Dim nPartPvId As Integer = GDB_ID.NULL
|
|
EgtGetInfo(nMchPvId, INFO_PV_ONPART_ID, nPartPvId)
|
|
' Svuoto il preview nel pezzo
|
|
EgtEmptyGroup(nPartPvId)
|
|
' Rimuovo anche il preview di lavorazioni inglobate
|
|
Dim sInfo As String = String.Empty
|
|
If EgtGetInfo(nMchId, INFO_MCH_OTHMID, sInfo) Then
|
|
Dim sItems() As String = sInfo.Split(",".ToCharArray)
|
|
For Each sId In sItems
|
|
' Indice gruppo di preview nella lavorazione
|
|
Dim nMchPvId2 As Integer = EgtGetFirstNameInGroup(CInt(sId), NAME_PREVIEW)
|
|
' Indice gruppo di preview nel pezzo
|
|
Dim nPartPvId2 As Integer = GDB_ID.NULL
|
|
EgtGetInfo(nMchPvId2, INFO_PV_ONPART_ID, nPartPvId2)
|
|
' Svuoto il preview nel pezzo
|
|
EgtEmptyGroup(nPartPvId2)
|
|
Next
|
|
End If
|
|
' Lo sposto dalla lavorazione al pezzo
|
|
Dim nId As Integer = EgtGetFirstInGroup(nMchPvId)
|
|
While nId <> GDB_ID.NULL
|
|
EgtRelocateGlob(nId, nPartPvId)
|
|
nId = EgtGetFirstInGroup(nMchPvId)
|
|
End While
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function IsValidMachining(nOperId As Integer) As Boolean
|
|
' Deve essere una lavorazione
|
|
If Not EgtSetCurrMachining(nOperId) Then Return False
|
|
' Deve contenere qualcosa
|
|
If EgtIsMachiningEmpty() Then Return False
|
|
' Deve essere abilitata oppure disabilitata direttamente dall'utente
|
|
If Not (EgtGetOperationMode(nOperId) Or EgtExistsInfo(nOperId, INFO_MCH_USER_OFF)) Then Return False
|
|
' E' valida
|
|
Return True
|
|
End Function
|
|
|
|
Private Function SetLuaStandardCamParams() As Boolean
|
|
Dim sSawMch As String = String.Empty
|
|
GetPrivateProfileString(S_MACH_MACH, K_CURRSAWING, "", sSawMch, m_MainWindow.GetMachIniFile())
|
|
Dim sDrillMch As String = String.Empty
|
|
GetPrivateProfileString(S_MACH_MACH, K_CURRDRILLING, "", sDrillMch, m_MainWindow.GetMachIniFile())
|
|
Dim dReducedDepth As Double = GetPrivateProfileDouble(S_MACH_NEST, K_MACH_REDUCEDDEPTH, 1, m_MainWindow.GetMachIniFile())
|
|
Dim dHolesOffset As Double = GetPrivateProfileDouble(S_MACH_NEST, K_MACH_HOLES_OFFSET, 0, m_MainWindow.GetMachIniFile())
|
|
Dim dHolesOverlap As Double = GetPrivateProfileDouble(S_MACH_NEST, K_MACH_HOLES_OVERLAP, 0, m_MainWindow.GetMachIniFile())
|
|
Dim dCornerSafety As Double = GetPrivateProfileDouble(S_MACH_NEST, K_MACH_SAFE_LEN_INTCORNER, 0, m_MainWindow.GetMachIniFile())
|
|
EgtLuaSetGlobStringVar("CAM.SAWMCH", sSawMch)
|
|
EgtLuaSetGlobStringVar("CAM.DRILLMCH", sDrillMch)
|
|
EgtLuaSetGlobNumVar("CAM.REDUCEDDEPTH", dReducedDepth)
|
|
EgtLuaSetGlobNumVar("CAM.HOLESOFFSET", dHolesOffset)
|
|
EgtLuaSetGlobNumVar("CAM.HOLESOVERLAP", dHolesOverlap)
|
|
EgtLuaSetGlobNumVar("CAM.CORNERSAFETY", dCornerSafety)
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function GetRawBox(ByRef ptRawMin As Point3d, ByRef ptRawMax As Point3d) As Boolean
|
|
Return GetRawBox(EgtGetFirstRawPart(), ptRawMin, ptRawMax)
|
|
End Function
|
|
|
|
Friend Function GetRawBox(nRawId As Integer, ByRef ptRawMin As Point3d, ByRef ptRawMax As Point3d) As Boolean
|
|
' Recupero identificativo del grezzo e del suo solido
|
|
Dim nSolidRawId As Integer = EgtGetFirstNameInGroup(nRawId, NAME_RAW_SOLID)
|
|
If nSolidRawId = GDB_ID.NULL Then
|
|
Return False
|
|
End If
|
|
' Ne recupero il box
|
|
Dim nFlag As Integer = GDB_BB.ONLY_VISIBLE + GDB_BB.IGNORE_TEXT + GDB_BB.IGNORE_DIM
|
|
EgtGetBBoxGlob(nSolidRawId, nFlag, ptRawMin, ptRawMax)
|
|
Return True
|
|
End Function
|
|
|
|
Friend Function GetRawHeight() As Double
|
|
Dim ptRawMin, ptRawMax As Point3d
|
|
If GetRawBox(ptRawMin, ptRawMax) Then
|
|
Return (ptRawMax.z - ptRawMin.z)
|
|
Else
|
|
Return 0
|
|
End If
|
|
End Function
|
|
|
|
Friend Function IsMachiningInActiveRaw(nMchId As Integer) As Boolean
|
|
EgtSetCurrMachining(nMchId)
|
|
' Recupero la prima entità geometrica della lavorazione
|
|
Dim nId, nSub As Integer
|
|
If Not EgtGetMachiningGeometry(0, nId, nSub) Then Return False
|
|
' Recupero il pezzo di appartenenza
|
|
Dim nPartId = EgtGetParent(EgtGetParent(nId))
|
|
If nPartId = GDB_ID.NULL Then Return False
|
|
' Recupero la fase di appartenenza della lavorazione
|
|
Dim nPhase As Integer = EgtGetOperationPhase(nMchId)
|
|
' Verifico se il pezzo è nei grezzi della fase indicata
|
|
Dim nRawId As Integer = EgtGetFirstRawPart()
|
|
While nRawId <> GDB_ID.NULL
|
|
If EgtVerifyRawPartPhase(nRawId, nPhase) Then
|
|
Dim nPirId As Integer = EgtGetFirstPartInRawPart(nRawId)
|
|
While nPirId <> GDB_ID.NULL
|
|
If nPartId = nPirId Then Return True
|
|
nPirId = EgtGetNextPartInRawPart(nPirId)
|
|
End While
|
|
End If
|
|
nRawId = EgtGetNextRawPart(nRawId)
|
|
End While
|
|
Return False
|
|
End Function
|
|
|
|
End Module
|