2191f0fb8c
- correzioni per preview tagli con inizio ine messi a strict.
300 lines
13 KiB
VB.net
300 lines
13 KiB
VB.net
Imports EgtUILib
|
|
|
|
Public Module CamAuto
|
|
|
|
Private m_MainWindow As MainWindow = Application.Current.MainWindow
|
|
|
|
Public 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
|
|
|
|
Public 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
|
|
|
|
Public 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
|
|
|
|
Public 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
|
|
|
|
Public Function DeactivateAllMachinings() As Boolean
|
|
Return EgtSetAllOperationsMode(False)
|
|
End Function
|
|
|
|
Public Function ActivateAllMachinings() As Boolean
|
|
Return EgtSetAllOperationsMode(True)
|
|
End Function
|
|
|
|
Public Function TestAllMachiningsForStrict() As Boolean
|
|
Dim bModified As Boolean = False
|
|
' Identificativo grezzo corrente
|
|
Dim nRawId As Integer = EgtGetFirstRawPart()
|
|
' 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
|
|
' 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
|
|
Dim bFree As Boolean = True
|
|
If sLay = "OutLoop" Then
|
|
bFree = EgtVerifyMachining(nOperId, False, nRawId)
|
|
For Each nId As Integer In vOthId
|
|
If Not EgtVerifyMachining(nId, False, nRawId) Then
|
|
bFree = False
|
|
End If
|
|
Next
|
|
Else
|
|
bFree = True
|
|
End If
|
|
' abilitazione
|
|
Dim bEnabled As Boolean = Not EgtExistsInfo(nOperId, INFO_MCH_USER_OFF)
|
|
' Restringo lavorazione abilitata ma con interferenza
|
|
If bEnabled And Not bFree Then
|
|
SetCutStrict(nOperId, True, True)
|
|
If Not EgtIsMachiningNotEmpty() Then
|
|
ResetCutStrict(nOperId, True, True)
|
|
SetCutDepth(nOperId, dReducedDepth)
|
|
If Not EgtVerifyMachining(nOperId, False, nRawId) Then
|
|
SetCutStrict(nOperId, True, True)
|
|
End If
|
|
End If
|
|
bModified = True
|
|
End If
|
|
End If
|
|
nOperId = EgtGetNextOperation(nOperId)
|
|
End While
|
|
Return bModified
|
|
End Function
|
|
|
|
Public 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)
|
|
Return True
|
|
End Function
|
|
|
|
Public 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)
|
|
End If
|
|
Return True
|
|
End Function
|
|
|
|
Public 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)
|
|
End If
|
|
Return True
|
|
End Function
|
|
|
|
Public Function UpdateMachiningPreview(nMchId As Integer) As Boolean
|
|
' Imposto la lavorazione corrente
|
|
If Not EgtSetCurrMachining(nMchId) Then Return False
|
|
' 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
|
|
' Ricalcolo il preview
|
|
EgtPreviewMachining(True)
|
|
' 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
|
|
|
|
Public Function IsValidMachining(nOperId As Integer) As Boolean
|
|
' Deve essere una lavorazione
|
|
If Not EgtSetCurrMachining(nOperId) Then Return False
|
|
' Deve contenere qualcosa
|
|
If Not EgtIsMachiningNotEmpty() Then Return False
|
|
' Deve essere abilitata oppure disabilitata direttamente dall'utente
|
|
If Not EgtGetOperationMode(nOperId) And Not 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, K_CURRSAWING, "", sSawMch, m_MainWindow.GetIniFile())
|
|
Dim sDrillMch As String = String.Empty
|
|
GetPrivateProfileString(S_MACH, K_CURRDRILLING, "", sDrillMch, m_MainWindow.GetIniFile())
|
|
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.HOLESOFFSET", dHolesOffset)
|
|
EgtLuaSetGlobNumVar("CAM.HOLESOVERLAP", dHolesOverlap)
|
|
EgtLuaSetGlobNumVar("CAM.CORNERSAFETY", dCornerSafety)
|
|
Return True
|
|
End Function
|
|
|
|
End Module
|