diff --git a/LuaLibs/BasicCustomerStrategies.lua b/LuaLibs/BasicCustomerStrategies.lua index 3434010..9183b88 100644 --- a/LuaLibs/BasicCustomerStrategies.lua +++ b/LuaLibs/BasicCustomerStrategies.lua @@ -52,7 +52,7 @@ local function GetStrategies_Egalware( Proc) elseif Proc.Topology.sName == 'Groove-3-Through' then Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Tunnel-4-Through' then - Strategies = { { sStrategyId = 'STR0003'}} + Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Groove-3-Blind' then Strategies = { { sStrategyId = 'STR0002'}} elseif Proc.Topology.sName == 'Rabbet-2-Through' then @@ -68,7 +68,7 @@ local function GetStrategies_Egalware( Proc) elseif Proc.Topology.sName == 'Groove-3-Through' then Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Tunnel-4-Through' then - Strategies = { { sStrategyId = 'STR0003'}} + Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Groove-3-Blind' then Strategies = { { sStrategyId = 'STR0002'}} elseif Proc.Topology.sName == 'Rabbet-2-Through' then @@ -90,7 +90,7 @@ local function GetStrategies_Egalware( Proc) elseif Proc.Topology.sName == 'Groove-3-Through' then Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Tunnel-4-Through' then - Strategies = { { sStrategyId = 'STR0003'}} + Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Groove-3-Blind' then Strategies = { { sStrategyId = 'STR0002'}} elseif Proc.Topology.sName == 'Rabbet-2-Through' then @@ -106,7 +106,7 @@ local function GetStrategies_Egalware( Proc) elseif Proc.Topology.sName == 'Groove-3-Through' then Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Tunnel-4-Through' then - Strategies = { { sStrategyId = 'STR0003'}} + Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Groove-3-Blind' then Strategies = { { sStrategyId = 'STR0002'}} elseif Proc.Topology.sName == 'Rabbet-2-Through' then @@ -122,7 +122,7 @@ local function GetStrategies_Egalware( Proc) elseif Proc.Topology.sName == 'Groove-3-Through' then Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Tunnel-4-Through' then - Strategies = { { sStrategyId = 'STR0003'}} + Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Groove-3-Blind' then Strategies = { { sStrategyId = 'STR0002'}} elseif Proc.Topology.sName == 'Rabbet-2-Through' then @@ -141,7 +141,7 @@ local function GetStrategies_Egalware( Proc) elseif Proc.Topology.sName == 'Groove-3-Through' then Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Tunnel-4-Through' then - Strategies = { { sStrategyId = 'STR0003'}} + Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Groove-3-Blind' then Strategies = { { sStrategyId = 'STR0002'}} elseif Proc.Topology.sName == 'Rabbet-2-Through' then @@ -169,7 +169,7 @@ local function GetStrategies_Egalware( Proc) elseif Proc.Topology.sName == 'Groove-3-Through' then Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Tunnel-4-Through' then - Strategies = { { sStrategyId = 'STR0003'}} + Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Groove-3-Blind' then Strategies = { { sStrategyId = 'STR0002'}} elseif Proc.Topology.sName == 'Rabbet-2-Through' then @@ -320,7 +320,7 @@ local function GetStrategies_Essetre( Proc) elseif Proc.Topology.sName == 'Groove-3-Through' then Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Tunnel-4-Through' then - Strategies = { { sStrategyId = 'STR0003'}} + Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Groove-3-Blind' then Strategies = { { sStrategyId = 'STR0002'}} elseif Proc.Topology.sName == 'Rabbet-2-Through' then @@ -336,7 +336,7 @@ local function GetStrategies_Essetre( Proc) elseif Proc.Topology.sName == 'Groove-3-Through' then Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Tunnel-4-Through' then - Strategies = { { sStrategyId = 'STR0003'}} + Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Groove-3-Blind' then Strategies = { { sStrategyId = 'STR0002'}} elseif Proc.Topology.sName == 'Rabbet-2-Through' then @@ -358,7 +358,7 @@ local function GetStrategies_Essetre( Proc) elseif Proc.Topology.sName == 'Groove-3-Through' then Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Tunnel-4-Through' then - Strategies = { { sStrategyId = 'STR0003'}} + Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Groove-3-Blind' then Strategies = { { sStrategyId = 'STR0002'}} elseif Proc.Topology.sName == 'Rabbet-2-Through' then @@ -374,7 +374,7 @@ local function GetStrategies_Essetre( Proc) elseif Proc.Topology.sName == 'Groove-3-Through' then Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Tunnel-4-Through' then - Strategies = { { sStrategyId = 'STR0003'}} + Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Groove-3-Blind' then Strategies = { { sStrategyId = 'STR0002'}} elseif Proc.Topology.sName == 'Rabbet-2-Through' then @@ -390,7 +390,7 @@ local function GetStrategies_Essetre( Proc) elseif Proc.Topology.sName == 'Groove-3-Through' then Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Tunnel-4-Through' then - Strategies = { { sStrategyId = 'STR0003'}} + Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Groove-3-Blind' then Strategies = { { sStrategyId = 'STR0002'}} elseif Proc.Topology.sName == 'Rabbet-2-Through' then @@ -409,7 +409,7 @@ local function GetStrategies_Essetre( Proc) elseif Proc.Topology.sName == 'Groove-3-Through' then Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Tunnel-4-Through' then - Strategies = { { sStrategyId = 'STR0003'}} + Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Groove-3-Blind' then Strategies = { { sStrategyId = 'STR0002'}} elseif Proc.Topology.sName == 'Rabbet-2-Through' then @@ -437,7 +437,7 @@ local function GetStrategies_Essetre( Proc) elseif Proc.Topology.sName == 'Groove-3-Through' then Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Tunnel-4-Through' then - Strategies = { { sStrategyId = 'STR0003'}} + Strategies = { { sStrategyId = 'STR0002'}, { sStrategyId = 'STR0003'}} elseif Proc.Topology.sName == 'Groove-3-Blind' then Strategies = { { sStrategyId = 'STR0002'}} elseif Proc.Topology.sName == 'Rabbet-2-Through' then diff --git a/LuaLibs/BeamExec.lua b/LuaLibs/BeamExec.lua index 8ae0b48..ee3e28e 100644 --- a/LuaLibs/BeamExec.lua +++ b/LuaLibs/BeamExec.lua @@ -223,7 +223,7 @@ end ------------------------------------------------------------------------------------------------------------- -- *** funzioni posizionamento pezzi all'interno della barra *** ------------------------------------------------------------------------------------------------------------- -function BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, vBeam, bMachGroupOk) +function BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, PARTS) -- default per nuove costanti qualora non definite BeamData.OVM_BLADE_HBEAM = ( BeamData.OVM_BLADE_HBEAM or 11) @@ -236,13 +236,11 @@ function BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, vBeam, b BeamExec.CalcMinUnloadableRaw( dRawW, dRawH) -- Creazione nuovo gruppo di lavoro - if not bMachGroupOk then - local sMgName = EgtGetMachGroupNewName( 'Mach_1') - local idNewMg = EgtAddMachGroup( sMgName) - if not idNewMg then - local sOut = 'Errore nella creazione del gruppo di lavoro ' .. sMgName - return false, sOut - end + local sMgName = EgtGetMachGroupNewName( 'Mach_1') + local idNewMg = EgtAddMachGroup( sMgName) + if not idNewMg then + local sOut = 'Errore nella creazione del gruppo di lavoro ' .. sMgName + return false, sOut end -- Impostazione della tavola @@ -274,26 +272,23 @@ function BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, vBeam, b local dDeltaS = dOvmHead local dDeltaSMin = 0 local dDeltaE = BeamData.OVM_MID - for i = 1, #vBeam do - -- assegno identificativo pezzo - local idPz = vBeam[i].id + for i = 1, #PARTS do -- dati del pezzo - local b3Part = EgtGetBBoxGlob( idPz or GDB_ID.NULL, GDB_BB.EXACT) - local b3Solid = vBeam[i].b3Box - if b3Part:isEmpty() or b3Solid:isEmpty() then break end + local b3Part = EgtGetBBoxGlob( PARTS[i].id or GDB_ID.NULL, GDB_BB.EXACT) + if b3Part:isEmpty() or PARTS[i].b3Box:isEmpty() then break end EgtOutLog( 'PartSez=' .. EgtNumToString( b3Part:getDimY(), 1) .. 'x' .. EgtNumToString( b3Part:getDimZ(), 1), 3) -- se sezione compatibile e lunghezza disponibile sufficiente - local dPartLen = b3Solid:getDimX() - local dPartWidth = b3Solid:getDimY() - local dPartHeight = b3Solid:getDimZ() + local dPartLen = PARTS[i].b3Box:getDimX() + local dPartWidth = PARTS[i].b3Box:getDimY() + local dPartHeight = PARTS[i].b3Box:getDimZ() local dNextLen = dLen - dDeltaS - dPartLen - dDeltaE if (( abs( dPartWidth - dRawW) < 100 * GEO.EPS_SMALL and abs( dPartHeight - dRawH) < 100 * GEO.EPS_SMALL) or ( abs( dPartHeight - dRawW) < 100 * GEO.EPS_SMALL and abs( dPartWidth - dRawH) < 100 * GEO.EPS_SMALL)) and dNextLen + dDeltaE >= 0 then -- eventuale sovramateriale di testa if i > 1 then - if vBeam[i].dPosX then - dDeltaS = max( vBeam[i].dPosX - ( dRawL - dLen), dDeltaSMin) + if PARTS[i].dPosX then + dDeltaS = max( PARTS[i].dPosX - ( dRawL - dLen), dDeltaSMin) else dDeltaS = max( dOvmMid - dDeltaE, 0) end @@ -302,49 +297,54 @@ function BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, vBeam, b local dCrawLen = min( dPartLen + dDeltaS + dDeltaE, dLen) local dDelta = dCrawLen - dPartLen - dDeltaS -- creo e posiziono il grezzo - local idRaw = EgtAddRawPart( Point3d(0,0,0), dCrawLen, dRawW, dRawH, BeamData.RAWCOL) - EgtMoveToCornerRawPart( idRaw, BeamData.ptOriXR, BeamData.dPosXR) - EgtMoveRawPart( idRaw, Vector3d( dLen - dRawL, 0, 0)) + PARTS[i].idRaw = EgtAddRawPart( Point3d(0,0,0), dCrawLen, dRawW, dRawH, BeamData.RAWCOL) + + EgtMoveToCornerRawPart( PARTS[i].idRaw, BeamData.ptOriXR, BeamData.dPosXR) + EgtMoveRawPart( PARTS[i].idRaw, Vector3d( dLen - dRawL, 0, 0)) -- assegno ordine in lavorazione nCnt = nCnt + 1 - EgtSetInfo( idRaw, 'ORD', nCnt) + EgtSetInfo( PARTS[i].idRaw, 'ORD', nCnt) -- creo o pulisco gruppo geometrie aggiuntive - if not BeamLib.CreateOrEmptyAddGroup( idPz) then - local sOut = 'Error creating Additional Group in Part ' .. tostring( idPz) + if not BeamLib.CreateOrEmptyAddGroup( PARTS[i].id) then + local sOut = 'Error creating Additional Group in Part ' .. tostring( PARTS[i].id) return false, sOut end -- aggiungo faccia per taglio iniziale al pezzo - BeamLib.AddPartStartFace( idPz, b3Solid) + BeamLib.AddPartStartFace( PARTS[i].id, PARTS[i].b3Box) -- se sovramateriale di testa, lo notifico if dDeltaS > 0.09 then - EgtSetInfo( idRaw, 'HOVM', dDeltaS) + EgtSetInfo( PARTS[i].idRaw, 'HOVM', dDeltaS) if idPrevRaw then EgtSetInfo( idPrevRaw, 'BDST', dDeltaS + dPrevDelta) end end if dDeltaE > 0.09 then - EgtSetInfo( idRaw, 'TOVM', dDeltaE) + EgtSetInfo( PARTS[i].idRaw, 'TOVM', dDeltaE) end -- aggiungo faccia per taglio finale al pezzo - BeamLib.AddPartEndFace( idPz, b3Solid) + BeamLib.AddPartEndFace( PARTS[i].id, PARTS[i].b3Box) -- inserisco il pezzo nel grezzo - EgtDeselectPartObjs( idPz) - local ptPos = b3Part:getMin() - b3Solid:getMin() + Vector3d( dDelta, ( dRawW - dPartWidth) / 2, ( dRawH - dPartHeight) / 2) - EgtAddPartToRawPart( idPz, ptPos, idRaw) + EgtDeselectPartObjs( PARTS[i].id) + local ptPos = b3Part:getMin() - PARTS[i].b3Box:getMin() + Vector3d( dDelta, ( dRawW - dPartWidth) / 2, ( dRawH - dPartHeight) / 2) + EgtAddPartToRawPart( PARTS[i].id, ptPos, PARTS[i].idRaw) if abs( dPartWidth - dRawW) > 100 * GEO.EPS_SMALL then -- rotazione attorno a centro geometria complessiva del pezzo - EgtRotatePartInRawPart( idPz, X_AX(), 90) + EgtRotatePartInRawPart( PARTS[i].id, X_AX(), 90) -- correggo per eccentricità solido rispetto a geometria complessiva del pezzo - local vtEccOri = b3Solid:getCenter() - b3Part:getCenter() + local vtEccOri = PARTS[i].b3Box:getCenter() - b3Part:getCenter() local vtEccRot = Vector3d( vtEccOri) vtEccRot:rotate( X_AX(), 90) - EgtMovePartInRawPart( idPz, ( vtEccOri - vtEccRot)) + EgtMovePartInRawPart( PARTS[i].id, ( vtEccOri - vtEccRot)) end -- aggiorno la lunghezza residua della barra dLen = dLen - dCrawLen -- aggiorno grezzo precedente - idPrevRaw = idRaw + idPrevRaw = PARTS[i].idRaw dPrevDelta = dDelta + PARTS[i].dDistanceToNextPiece = dDelta + PARTS[i].dRestLength = dLen + PARTS[i].b3Raw = EgtGetRawPartBBox( PARTS[i].idRaw) + PARTS[i].b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( PARTS[i].id, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD) else local sOut = 'Error: part L(' .. EgtNumToString( dPartLen, 1) .. ') too big for raw part L(' .. EgtNumToString( dLen - 0.1, 1) .. ')' return false, sOut @@ -359,6 +359,7 @@ function BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, vBeam, b -- Se rimasto materiale aggiungo grezzo dell'avanzo if dLen > 10 then + PARTS[#PARTS].bNextIsRaw = true local idRaw = EgtAddRawPart( Point3d(0,0,0), dLen, dRawW, dRawH, BeamData.RAWCOL) EgtMoveToCornerRawPart( idRaw, BeamData.ptOriXR, BeamData.dPosXR) EgtMoveRawPart( idRaw, Vector3d( dLen - dRawL, 0, 0)) @@ -467,8 +468,8 @@ local function CollectFeatures( Part) -- recupero le feature local vProc = {} local LayerId = {} - LayerId[1] = BeamLib.GetAddGroup( Part.idPart) - LayerId[2] = EgtGetFirstNameInGroup( Part.idPart or GDB_ID.NULL, 'Processings') + LayerId[1] = BeamLib.GetAddGroup( Part.id) + LayerId[2] = EgtGetFirstNameInGroup( Part.id or GDB_ID.NULL, 'Processings') for nInd = 1, 2 do local ProcId = EgtGetFirstInGroup( LayerId[nInd] or GDB_ID.NULL) while ProcId do @@ -480,7 +481,7 @@ local function CollectFeatures( Part) local nDo = EgtGetInfo( ProcId, 'DO', 'i') or 1 if nGrp and nPrc and nDo == 1 then local Proc = {} - Proc.idPart = Part.idPart + Proc.idPart = Part.id Proc.id = ProcId -- id della feature btl ( se non presente info, si prende id dell'entità geometrica) Proc.idFeature = EgtGetInfo( Proc.id, 'PRID', 's') or Proc.id @@ -757,7 +758,7 @@ end -- 2) Standard : ( lavorazioni standard che non impattano sulal coda) -- 3) AdvanceTail : ( lavorazioni che richiedono taglio di separazione, ma che devono essere fatte prima perchè il taglio di separazione farebbe cadere il pezzo) -- 4) Split : ( taglio di separazione) --- 5) Tail : ( lavorazionio di coda, fatte dopo il taglio di separazione) +-- 5) Tail : ( lavorazioni di coda, fatte dopo il taglio di separazione) local function OrderFeatures( vProc) local vProcToSort = vProc -- funzione di confronto. TRUE = B1 prima di B2. FALSE = B2 prima di B1 @@ -864,21 +865,15 @@ local function PrintFeatures( vProc, Part) end ------------------------------------------------------------------------------------------------------------- -function BeamExec.ProcessFeatures() +function BeamExec.ProcessFeatures( PARTS) -- ciclo sui pezzi local nTotErr = 0 local Stats = {} local nOrd = 1 local Part = {} - - Part.idRaw = EgtGetFirstRawPart() - while Part.idRaw do - -- verifico che il grezzo contenga pezzi oppure sia abbastanza lungo da essere scaricato coi carrelli - Part.idPart = EgtGetFirstPartInRawPart( Part.idRaw) - Part.b3Raw = EgtGetRawPartBBox( Part.idRaw) - Part.b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( Part.idPart, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD) - if not Part.idPart and Part.b3Raw:getDimX() < BeamData.dMinRaw then break end + for nPart = 1, #PARTS do + if not PARTS[nPart].id and PARTS[nPart].b3Raw:getDimX() < BeamData.dMinRaw then break end -- per ogni rotazione, calcolo come lavorare le feature per decidere posizionamento iniziale e in che rotazione verranno lavorate le singole feature local vProcRot = {} @@ -896,31 +891,31 @@ end for dRotIndex = 1, 4 do -- recupero le feature di lavorazione della trave - table.insert( vProcRot, CollectFeatures( Part)) + table.insert( vProcRot, CollectFeatures( PARTS[nPart])) -- recupero informazioni ausiliarie feature e dipendenze tra feature stesse -- TODO le dipendenze cambiano in base alla rotazione del pezzo? probabilmente no - vProcRot[dRotIndex] = GetFeatureInfoAndDependency( vProcRot[dRotIndex], Part) + vProcRot[dRotIndex] = GetFeatureInfoAndDependency( vProcRot[dRotIndex], PARTS[nPart]) -- sceglie la strategia migliore tra quelle disponibili ( presenti nella tabella vProcRot[dRotIndex].AvailableStrategies) - vProcRot[dRotIndex] = GetBestStrategy( vProcRot[dRotIndex], Part) + vProcRot[dRotIndex] = GetBestStrategy( vProcRot[dRotIndex], PARTS[nPart]) -- ruoto il grezzo per calcolare la fattibilità delle lavorazioni nella prossima rotazione -- vettore movimento grezzi per rotazione di 90deg ogni step - local dDeltaYZ = Part.b3Raw:getDimY() - Part.b3Raw:getDimZ() + local dDeltaYZ = PARTS[nPart].b3Raw:getDimY() - PARTS[nPart].b3Raw:getDimZ() local vtMove = Vector3d( 0, dDeltaYZ / 2 * EgtIf( BeamData.RIGHT_LOAD, -1, 1), dDeltaYZ / 2) local bPreMove = ( dDeltaYZ < 0) -- ruoto le travi della fase corrente if bPreMove then - EgtMoveRawPart( Part.idRaw, vtMove) + EgtMoveRawPart( PARTS[nPart].idRaw, vtMove) end - EgtRotateRawPart( Part.idRaw, X_AX(), EgtIf( BeamData.RIGHT_LOAD, -90, 90)) + EgtRotateRawPart( PARTS[nPart].idRaw, X_AX(), EgtIf( BeamData.RIGHT_LOAD, -90, 90)) if not bPreMove then - EgtMoveRawPart( Part.idRaw, vtMove) + EgtMoveRawPart( PARTS[nPart].idRaw, vtMove) end -- aggiorno info pezzo - Part.b3Raw = EgtGetRawPartBBox( Part.idRaw) - Part.b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( Part.idPart, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD) + PARTS[nPart].b3Raw = EgtGetRawPartBBox( PARTS[nPart].idRaw) + PARTS[nPart].b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( PARTS[nPart].id, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD) end @@ -941,17 +936,17 @@ end if nOrd == 1 then EgtSetCurrPhase( 1) else - BeamLib.AddPhaseWithRawParts( Part, BeamData.ptOriXR, BeamData.dPosXR, 0) + BeamLib.AddPhaseWithRawParts( PARTS[nPart], BeamData.ptOriXR, BeamData.dPosXR, 0) end local nPhase = EgtGetCurrPhase() local nDispId = EgtGetPhaseDisposition( nPhase) - EgtSetInfo( nDispId, 'TYPE', EgtIf( Part.idPart, 'START', 'REST')) + EgtSetInfo( nDispId, 'TYPE', EgtIf( PARTS[nPart].id, 'START', 'REST')) EgtSetInfo( nDispId, 'ORD', nOrd) - EgtOutLog( ' *** Phase=' .. tostring( nPhase) .. ' Raw=' .. tostring( Part.idRaw) .. ' Part=' .. tostring( Part.idPart) .. ' ***', 1) + EgtOutLog( ' *** Phase=' .. tostring( nPhase) .. ' Raw=' .. tostring( PARTS[nPart].idRaw) .. ' Part=' .. tostring( PARTS[nPart].id) .. ' ***', 1) -- debug if EgtGetDebugLevel() >= 1 then - PrintFeatures( vProc, Part) + PrintFeatures( vProc, PARTS[nPart]) end EgtOutLog( ' *** AddMachinings ***', 1) @@ -964,14 +959,14 @@ end -- TODO da fare MACHININGS = {} -- esegue le strategie migliori che ha precedentemente scelto e salva le lavorazioni nella lista globale - CalculateMachinings( vProc, Part) + CalculateMachinings( vProc, PARTS[nPart]) -- TODO riordinare lavorazioni ottimizzando cambio utensile/spezzone ecc..., mantenendo dipendenze definite prima -- ordino le lavorazioni - -- OrderMachining( vProc, Part) + -- OrderMachining( vProc, PARTS[nPart]) -- aggiunge effettivamente le lavorazioni - MachiningLib.AddOperations( vProc, Part) + MachiningLib.AddOperations( vProc, PARTS[nPart]) -- TODO da rimuovere o lasciare solo per debug @@ -985,7 +980,6 @@ end EgtOutLog( ' *** End AddMachinings ***', 1) -- passo al grezzo successivo nOrd = nOrd + 1 - Part.idRaw = EgtGetNextRawPart( Part.idRaw) end -- Aggiornamento finale di tutto diff --git a/LuaLibs/MachiningLib.lua b/LuaLibs/MachiningLib.lua index eb20abd..1c79fb4 100644 --- a/LuaLibs/MachiningLib.lua +++ b/LuaLibs/MachiningLib.lua @@ -147,7 +147,7 @@ function MachiningLib.FindMill( Proc, ToolSearchParameters) -- se entrambi incompleti elseif dBestToolResidualDepth > 0 and dCurrentResidualDepth > 0 then --scelgo quello che lavora di più - if dCurrentResidualDepth > dBestToolResidualDepth then + if dCurrentResidualDepth < dBestToolResidualDepth then nBestToolIndex = i dBestToolResidualDepth = dCurrentResidualDepth end @@ -318,17 +318,15 @@ function MachiningLib.AddNewMachining( ProcToAdd, MachiningToAdd) end -- se nome non definito, assegno alla lavorazioen un nome standard if not MachiningToAdd.sOperationName then - MachiningToAdd.sOperationName = MachiningToAdd.sTypeName .. ( EgtGetName( ProcToAdd.id) or tostring( ProcToAdd.id)) .. '_' .. tostring( MachiningToAdd.idFaceToMachine) + MachiningToAdd.sOperationName = MachiningToAdd.sTypeName .. ( EgtGetName( ProcToAdd.id) or tostring( ProcToAdd.id)) .. '_' .. tostring( MachiningToAdd.Geometry[1][2]) end if not MachiningToAdd.sToolName then MachiningToAdd.sToolName = TOOLS[MachiningToAdd.nToolIndex].sName end - local Machining = {} Machining.Proc = ProcToAdd Machining.Machining = MachiningToAdd table.insert( MACHININGS, Machining) - return true end diff --git a/Process.lua b/Process.lua index dc373cf..52591b0 100644 --- a/Process.lua +++ b/Process.lua @@ -67,11 +67,13 @@ end local BeamExec = require( 'BeamExec') +-- Variabili globali +PARTS = {} + -- Carico i dati globali local BeamData = require( 'BeamData') -- Variabili di modulo -local vBeam = {} local dRawW local dRawH @@ -86,47 +88,47 @@ local function MyProcessInputData() local nPartId = EgtGetParent( EgtGetParent( nId or GDB_ID.NULL) or GDB_ID.NULL) if nPartId then local bFound = false - for i = 1, #vBeam do - if vBeam[i].id == nPartId then + for i = 1, #PARTS do + if PARTS[i].id == nPartId then bFound = true break end end if not bFound then - table.insert( vBeam, { nInd = #vBeam + 1, id = nPartId, sName = ( EgtGetName( nPartId) or ( 'Id=' .. tonumber( nPartId)))}) + table.insert( PARTS, { nInd = #PARTS + 1, id = nPartId, sName = ( EgtGetName( nPartId) or ( 'Id=' .. tonumber( nPartId)))}) end end nId = EgtGetNextSelectedObj() end - if #vBeam == 0 then + if #PARTS == 0 then EgtOutBox( 'Non sono state selezionate travi', 'Lavora Travi', 'ERROR') return false else local sOut = '' - for i = 1, #vBeam do - sOut = sOut .. vBeam[i].sName .. ', ' + for i = 1, #PARTS do + sOut = sOut .. PARTS[i].sName .. ', ' end sOut = sOut:sub( 1, -3) EgtOutLog( 'Travi selezionate : ' .. sOut, 1) end -- Ne recupero e verifico le dimensioni - for i = 1, #vBeam do - local Ls = EgtGetFirstNameInGroup( vBeam[i].id, 'Box') + for i = 1, #PARTS do + local Ls = EgtGetFirstNameInGroup( PARTS[i].id, 'Box') local b3Solid = EgtGetBBoxGlob( Ls or GDB_ID.NULL, GDB_BB.STANDARD) if not b3Solid then - EgtOutBox( 'Box non definito per la trave ' .. vBeam[i].sName, 'Lavora Travi', 'ERROR') + EgtOutBox( 'Box non definito per la trave ' .. PARTS[i].sName, 'Lavora Travi', 'ERROR') return false else - vBeam[i].b3Box = b3Solid + PARTS[i].b3Box = b3Solid end end - dRawW = vBeam[1].b3Box:getDimY() - dRawH = vBeam[1].b3Box:getDimZ() + dRawW = PARTS[1].b3Box:getDimY() + dRawH = PARTS[1].b3Box:getDimZ() local vBeamErr = {} - for i = 2, #vBeam do - local dDimW = vBeam[i].b3Box:getDimY() - local dDimH = vBeam[i].b3Box:getDimZ() + for i = 2, #PARTS do + local dDimW = PARTS[i].b3Box:getDimY() + local dDimH = PARTS[i].b3Box:getDimZ() if ( abs( dDimW - dRawW) > 10 * GEO.EPS_SMALL or abs( dDimH - dRawH) > 10 * GEO.EPS_SMALL) and ( abs( dDimH - dRawW) > 10 * GEO.EPS_SMALL or abs( dDimW - dRawH) > 10 * GEO.EPS_SMALL) then table.insert( vBeamErr, i) @@ -135,9 +137,9 @@ local function MyProcessInputData() if #vBeamErr > 0 then local sOut = 'Rimosse travi con sezioni diverse dalla prima :\n' for i = #vBeamErr, 1, -1 do - sOut = sOut .. vBeam[vBeamErr[i]].sName .. '\n' - EgtDeselectPartObjs( vBeam[vBeamErr[i]].id) - table.remove( vBeam, vBeamErr[i]) + sOut = sOut .. PARTS[vBeamErr[i]].sName .. '\n' + EgtDeselectPartObjs( PARTS[vBeamErr[i]].id) + table.remove( PARTS, vBeamErr[i]) end EgtOutLog( sOut, 1) EgtOutBox( sOut, 'Lavora Travi', 'INFO') @@ -172,17 +174,18 @@ local function MyProcessBeams() -- Lunghezza totale delle travi local dTotLen = 0 - for i = 1, #vBeam - 1 do - dTotLen = dTotLen + vBeam[i].b3Box:getDimX() + for i = 1, #PARTS - 1 do + dTotLen = dTotLen + PARTS[i].b3Box:getDimX() end - dTotLen = dTotLen + max( vBeam[#vBeam].b3Box:getDimX(), BeamData.dMinRaw) - local dAddLen = BeamData.OVM_HEAD + ( #vBeam - 1) * BeamData.OVM_MID + dTotLen = dTotLen + max( PARTS[#PARTS].b3Box:getDimX(), BeamData.dMinRaw) + local dAddLen = BeamData.OVM_HEAD + ( #PARTS - 1) * BeamData.OVM_MID EgtOutLog( 'Ltot : '..EgtNumToString( dTotLen, 1) .. ' Lagg : '..EgtNumToString( dAddLen, 1)..' MinUnloadRaw : '.. EgtNumToString( BeamData.dMinRaw + BeamData.OVM_MID, 1), 1) -- Richiedo lunghezza del grezzo, sovramateriale di testa, forzatura verticale e ordinamento automatico secondo la lunghezza local vsVal = EgtDialogBox( 'Lavora Travi' .. ' (Ltot='..EgtNumToString( dTotLen + dAddLen + 0.5, 0).. ', Lmax='..EgtNumToString( BeamData.MAX_RAW, 0)..',MinUlr='..EgtNumToString( BeamData.dMinRaw + BeamData.OVM_MID, 0)..')', - {'Lunghezza grezzo', EgtNumToString( BeamData.STD_RAW, 0)}, + --{'Lunghezza grezzo', EgtNumToString( BeamData.STD_RAW, 0)}, -- TODO RIPRISTINARE + {'Lunghezza grezzo', EgtNumToString( 0)}, {'Sovramateriale di testa', EgtNumToString( BeamData.OVM_HEAD, 0)}, {'Offset intermedio', EgtNumToString( BeamData.OVM_MID, 0)}, {'Forza sezione verticale', ' CB:true,*false'}, @@ -262,7 +265,7 @@ local function MyProcessBeams() -- Se richiesto, ordino le travi in senso di lunghezza crescente local bOrd = ( vsVal[5] == 'true') if bOrd then - table.sort( vBeam, function( B1, B2) + table.sort( PARTS, function( B1, B2) if abs( B1.b3Box:getDimX() - B2.b3Box:getDimX()) < 1 then return B1.nInd < B2.nInd else @@ -272,15 +275,15 @@ local function MyProcessBeams() end do local sOut = '' - for i = 1, #vBeam do - sOut = sOut .. vBeam[i].sName .. ', ' + for i = 1, #PARTS do + sOut = sOut .. PARTS[i].sName .. ', ' end sOut = sOut:sub( 1, -3) EgtOutLog( 'Travi ordinate : ' .. sOut, 1) end -- Sistemo le travi nel grezzo - local bOk, sErr = BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, vBeam) + local bOk, sErr = BeamExec.ProcessBeams( dRawW, dRawH, dRawL, dOvmHead, dOvmMid, PARTS) if not bOk then EgtOutLog( sErr) EgtOutBox( sErr, 'Lavora Travi', 'ERROR') @@ -294,7 +297,7 @@ end -- *** Inserimento delle lavorazioni nelle travi *** ------------------------------------------------------------------------------------------------------------- local function MyProcessFeatures() - local bOk, Stats = BeamExec.ProcessFeatures() + local bOk, Stats = BeamExec.ProcessFeatures( PARTS) local nErrCnt = 0 local nWarnCnt = 0 local sOutput = '' diff --git a/Strategies/STR0002/STR0002.lua b/Strategies/STR0002/STR0002.lua index a7a0f05..4182971 100644 --- a/Strategies/STR0002/STR0002.lua +++ b/Strategies/STR0002/STR0002.lua @@ -28,6 +28,7 @@ local Strategy = {} ------------------------------------------------------------------------------------------------------------- local function IsTopologyOk( Proc) if Proc.Topology.sName == 'Pocket-5-Blind' or + Proc.Topology.sName == 'Tunnel-4-Through' or Proc.Topology.sName == 'Groove-4-Blind' or Proc.Topology.sName == 'Groove-3-Through' or Proc.Topology.sName == 'Groove-3-Blind' or @@ -46,25 +47,37 @@ local function CalcMachinedPercentage( Proc, Machining) return 0 end - local dPercentage = 0 + local dTotalPercentage = 0 + local dPercentageBottom = 0 if Machining[1].bIsApplicable then - dPercentage = ( Machining[1].dElevation - Machining[1].ToolInfo.dResidualDepth) / Machining[1].dElevation + dTotalPercentage = ( Machining[1].dElevation - Machining[1].ToolInfo.dResidualDepth) / Machining[1].dElevation + dPercentageBottom = dTotalPercentage end if Machining[2].bIsApplicable then local dAbsPercentage = ( Machining[2].dElevation - Machining[2].ToolInfo.dResidualDepth) / Machining[2].dElevation - dPercentage = dPercentage + ( 1 - dPercentage) * dAbsPercentage + dTotalPercentage = dTotalPercentage + ( 1 - dTotalPercentage) * dAbsPercentage end if Machining[3].bIsApplicable then - local dAbsPercentage = ( Machining[3].dElevation - Machining[3].ToolInfo.dResidualDepth) / Machining[3].dElevation - dPercentage = dPercentage + ( 1 - dPercentage) * dAbsPercentage + local dAbsPercentage + if Machining[3].bMachAppliedToTunnelFace then + dAbsPercentage = ( Machining[3].dElevation - Machining[3].ToolInfo.dResidualDepth - Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].dElevation) / Machining[3].dElevation + else + dAbsPercentage = ( Machining[3].dElevation - Machining[3].ToolInfo.dResidualDepth) / Machining[3].dElevation + end + dTotalPercentage = dTotalPercentage + ( 1 - dPercentageBottom) * dAbsPercentage end if Machining[4].bIsApplicable then - local dAbsPercentage = ( Machining[4].dElevation - Machining[4].ToolInfo.dResidualDepth) / Machining[4].dElevation - dPercentage = dPercentage + ( 1 - dPercentage) * dAbsPercentage + local dAbsPercentage + if Machining[3].bMachAppliedToTunnelFace then + dAbsPercentage = ( Machining[4].dElevation - Machining[4].ToolInfo.dResidualDepth - Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].dElevation) / Machining[4].dElevation + else + dAbsPercentage = ( Machining[4].dElevation - Machining[4].ToolInfo.dResidualDepth) / Machining[4].dElevation + end + dTotalPercentage = dTotalPercentage + ( 1 - dPercentageBottom) * dAbsPercentage end - return dPercentage * 100 + return dTotalPercentage * 100 end ------------------------------------------------------------------------------------------------------------- @@ -169,12 +182,15 @@ local function GetBestPocketingStrategy( Proc) Milling.idProc = Proc.id Milling.dElevation = Proc.MainFaces.LongFaces[1].dElevation else -- 'Tunnel-4-Through', 'Groove-3-Through', 'Rabbet-2-Through' + -- se lavoro di fianco, devo comunque rispettare il raggio massimo + ToolSearchParameters.dMaxToolDiameter = min( ToolSearchParameters.dMaxToolDiameter, Strategy.Parameters.dMaxCornerRadius * 2) ToolSearchParameters.dElevation = ( Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].dElevation * 2) + BeamData.MILL_OVERLAP ToolSearchParameters.vtToolDirection = Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].vtN Milling.vtFaceNormal = Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].vtN Milling.idFaceToMachine = Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].id Milling.idProc = Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.id Milling.dElevation = ( Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].dElevation * 2) + BeamData.MILL_OVERLAP + Milling.bMachAppliedToTunnelFace = true end Milling.ToolInfo = {} Milling.ToolInfo = MachiningLib.FindMill( Proc, ToolSearchParameters) @@ -191,14 +207,17 @@ local function GetBestPocketingStrategy( Proc) Milling = {} Milling.bIsApplicable = false if Proc.Topology.sName ~= 'Pocket-5-Blind' and Proc.Topology.sName ~= 'Groove-4-Blind' then - if Proc.Topology.sName == 'Tunnel-4-Through' or Proc.Topology.sName == 'Groove-3-Through' or Proc.Topology.sName == 'Rabbet-2-Through' then + if Proc.MainFaces.TunnelAddedFaces then -- Tunnel-4-Through, Groove-3-Through, Rabbet-2-Through + -- se lavoro di fianco, devo comunque rispettare il raggio massimo + ToolSearchParameters.dMaxToolDiameter = min( ToolSearchParameters.dMaxToolDiameter, Strategy.Parameters.dMaxCornerRadius * 2) ToolSearchParameters.dElevation = ( Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].dElevation * 2) + BeamData.MILL_OVERLAP ToolSearchParameters.vtToolDirection = -Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].vtN Milling.vtFaceNormal = -Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].vtN Milling.idFaceToMachine = Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].id Milling.idProc = Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.id Milling.dElevation = ( Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].dElevation * 2) + BeamData.MILL_OVERLAP - Milling.bInvertTool = true + Milling.bToolInvert = true + Milling.bMachAppliedToTunnelFace = true else -- 'Groove-3-Blind' ToolSearchParameters.dElevation = Proc.MainFaces.SideFaces[1].dElevation ToolSearchParameters.vtToolDirection = Proc.MainFaces.SideFaces[1].vtN @@ -272,12 +291,12 @@ local function GetBestPocketingStrategy( Proc) Machining[3].bIsApplicable = false return Machining -- se tunnel 2+3 completa tutto - elseif Proc.MainFaces.TunnelAddedFaces and Machining[2].bIsApplicable and Machining[3].bIsApplicable and + elseif Proc.MainFaces.TunnelAddedFaces and Machining[3].bIsApplicable and Machining[4].bIsApplicable and Machining[3].ToolInfo.dResidualDepth + Machining[4].ToolInfo.dResidualDepth < (Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].dElevation * 2) + BeamData.MILL_OVERLAP then Machining.sTypeMachining = 'Side1-Side2' Strategy.Result.sStatus = 'Completed' Machining[3].ToolInfo.dResidualDepth = Machining[3].ToolInfo.dResidualDepth - Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].dElevation - Machining[4].ToolInfo.dResidualDepth = -Machining[3].ToolInfo.dResidualDepth + BeamData.MILL_OVERLAP + Machining[4].ToolInfo.dResidualDepth = -Machining[3].ToolInfo.dResidualDepth - BeamData.MILL_OVERLAP Strategy.Result.nCompletionIndex = FeatureData.GetFeatureCompletionIndex( 100) Strategy.Result.dMRR = ( Machining[3].dMRR + Machining[4].dMRR) / 2 Machining[1].bIsApplicable = false @@ -286,32 +305,33 @@ local function GetBestPocketingStrategy( Proc) end Strategy.Result.sStatus = 'Not-Completed' + Strategy.Result.dMRR = 0 if Machining[1].bIsApplicable then Machining.sTypeMachining = 'Bottom' Strategy.Result.dMRR = Machining[1].dMRR end if Machining[2].bIsApplicable then Machining.sTypeMachining = EgtIf( Machining.sTypeMachining == 'None', 'Bottom2', Machining.sTypeMachining .. '-Bottom2') - Strategy.Result.dMRR = Machining[1].dMRR + Strategy.Result.dMRR = ( Strategy.Result.dMRR + Machining[2].dMRR) / EgtIf( Strategy.Result.dMRR == 0, 1, 2) end if Machining[3].bIsApplicable then if Proc.MainFaces.TunnelAddedFaces then - Machining[3].ToolInfo.dResidualDepth = Machining[3].ToolInfo.dResidualDepth - Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].dElevation + Machining[3].ToolInfo.dResidualDepth = Machining[3].ToolInfo.dResidualDepth - Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].dElevation + BeamData.MILL_OVERLAP end Machining.sTypeMachining = EgtIf( Machining.sTypeMachining == 'None', 'Side1', Machining.sTypeMachining .. '-Side1') - Strategy.Result.dMRR = Machining[1].dMRR + Strategy.Result.dMRR = ( Strategy.Result.dMRR + Machining[3].dMRR) / EgtIf( Strategy.Result.dMRR == 0, 1, 2) end if Machining[4].bIsApplicable then if Proc.MainFaces.TunnelAddedFaces then - Machining[4].ToolInfo.dResidualDepth = Machining[4].ToolInfo.dResidualDepth - Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].dElevation + Machining[4].ToolInfo.dResidualDepth = Machining[4].ToolInfo.dResidualDepth - Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.Faces[1].dElevation + BeamData.MILL_OVERLAP end Machining.sTypeMachining = EgtIf( Machining.sTypeMachining == 'None', 'Side2', Machining.sTypeMachining .. '-Side2') - Strategy.Result.dMRR = Machining[1].dMRR + Strategy.Result.dMRR = ( Strategy.Result.dMRR + Machining[4].dMRR) / EgtIf( Strategy.Result.dMRR == 0, 1, 2) end local dMachinedPrercentage = CalcMachinedPercentage( Proc, Machining) Strategy.Result.nCompletionIndex = FeatureData.GetFeatureCompletionIndex( dMachinedPrercentage) - Strategy.Result.sInfo = 'Machining not complete, left ' .. tostring( 100 - dMachinedPrercentage) .. '%' + Strategy.Result.sInfo = 'Machining not complete, left ' .. tostring( 100 - ceil( dMachinedPrercentage)) .. '%' -- se non ho trovato neanche una lavorazione if Machining.sTypeMachining == 'None' then @@ -325,6 +345,148 @@ local function GetBestPocketingStrategy( Proc) return Machining end +------------------------------------------------------------------------------------------------------------- +local function VerifySplitMachiningNeeded( Proc, Part) + local vAddId = {} + local vAddIdTunnel = {} + local bSplit + + -- la lunghezza richiede spezzatura + if Proc.b3Box:getDimX() > BeamData.LONGCUT_MAXLEN or Proc.b3Box:getDimX() > 0.7 * Part.b3Solid:getDimX() then + bSplit = true + else + bSplit = false + end + + -- la lunghezza richiede spezzatura + if ( bSplit) then + -- recupero gruppo per geometria aggiuntiva + local nAddGrpId = BeamLib.GetAddGroup( Part.id) + local bStartLeft, bStartRight + local nIdTunnel = nil + if Proc.MainFaces.TunnelAddedFaces then + nIdTunnel = Proc.MainFaces.TunnelAddedFaces.MiddleFaceTm.id + end + + -- se feature inizia al di sotto del limite sinistro (coda) + if Proc.b3Box:getMin():getX() < Part.b3Solid:getMin():getX() + BeamData.LONGCUT_ENDLEN then + bStartLeft = true + end + -- se feature inizia al di sotto del limite destro (testa) + if Proc.b3Box:getMax():getX() > Part.b3Solid:getMax():getX() - BeamData.LONGCUT_ENDLEN then + bStartRight = true + end + + -- recupero utensile con massimo diametro + local dMaxDiam = 30 + for t = 1, #Strategy.Machining do + if Strategy.Machining[t].bIsApplicable then + dMaxDiam = min( dMaxDiam, TOOLS[Strategy.Machining[t].ToolInfo.nToolIndex].dDiameter) + end + end + -- salvo valori + local dNewMinX = Proc.b3Box:getMin():getX() + local dNewMaxX = Proc.b3Box:getMax():getX() + local dNewRest = Proc.b3Box:getDimX() + + -- creo primo spezzone sulla sinistra + if bStartLeft then + local AddId = EgtCopyGlob( Proc.id, nAddGrpId) or GDB_ID.NULL + -- copio faccia tunnel + local AddIdTunnel = EgtCopyGlob( nIdTunnel, nAddGrpId) or GDB_ID.NULL + + -- decido punto spezzatura verso la coda + if Proc.b3Box:getDimX() > BeamData.LONGCUT_ENDLEN * 2 then + dNewMinX = max( Part.b3Solid:getMin():getX() + BeamData.LONGCUT_ENDLEN, Proc.b3Box:getMin():getX() + dMaxDiam * 3) + else + -- se pezzo abbastanza piccolo, spezzo in mezzo al 'pezzo + grezzo restante' + if Part.dRestLength + Part.b3Solid:getDimX() < BeamData.dMinRaw * 1.5 then + dNewMinX = Part.b3Solid:getMax():getX() - ( ( Part.dRestLength + Part.b3Solid:getDimX()) / 2) + else + dNewMinX = max( Proc.b3Box:getMin():getX() + ( BeamData.dMinRaw)/2 + 150, Part.b3Solid:getMax():getX() - BeamData.LONGCUT_ENDLEN) + end + end + + local ptOn = Point3d( dNewMinX, 0, 0) + dNewRest = abs( dNewMaxX - dNewMinX) + -- taglio della superficie lato sinistro + EgtCutSurfTmPlane( AddId, ptOn, X_AX(), true, GDB_RT.GLOB) + EgtCutSurfTmPlane( AddIdTunnel, ptOn, X_AX(), true, GDB_RT.GLOB) + -- eseguo inserimento + table.insert( vAddId, AddId) + table.insert( vAddIdTunnel, AddIdTunnel) + end + -- creo spezzone sulla destra + if bStartRight then + local AddId = EgtCopyGlob( Proc.id, nAddGrpId) or GDB_ID.NULL + -- copio faccia tunnel + local AddIdTunnel = EgtCopyGlob( nIdTunnel, nAddGrpId) or GDB_ID.NULL + dNewMaxX = min( ( Proc.b3Box:getMax():getX() - dMaxDiam * 3), Part.b3Solid:getMax():getX() - BeamData.LONGCUT_ENDLEN) + if dNewMaxX - dNewMinX < 500 * GEO.EPS_SMALL then + dNewMaxX = dNewMinX - BeamData.MILL_OVERLAP + dNewRest = 0 + else + dNewRest = dNewMaxX - dNewMinX + end + local ptOn = Point3d( dNewMaxX, 0, 0) + -- taglio della superficie lato destro + EgtCutSurfTmPlane( AddId, ptOn, -X_AX(), true, GDB_RT.GLOB) + EgtCutSurfTmPlane( AddIdTunnel, ptOn, -X_AX(), true, GDB_RT.GLOB) + -- eseguo inserimento + table.insert( vAddId, 1, AddId) + table.insert( vAddIdTunnel, AddIdTunnel) + end + -- lavoro il restante + if dNewRest > 0 then + local nSplitParts = max( ceil( dNewRest / BeamData.LONGCUT_MAXLEN + 10 * GEO.EPS_SMALL), 1) + local dSplitPartsLen = dNewRest / nSplitParts + for i = 1, nSplitParts do + local AddId = EgtCopyGlob( Proc.id, nAddGrpId) or GDB_ID.NULL + -- copio faccia tunnel + local AddIdTunnel = EgtCopyGlob( nIdTunnel, nAddGrpId) or GDB_ID.NULL + local ptOn + -- se un solo spezzone, prendo punto massimo e minimo + if nSplitParts == 1 then + ptOn = Point3d( dNewMinX, 0, 0) + -- taglio della superficie lato sinistro + EgtCutSurfTmPlane( AddId, ptOn, -X_AX(), true, GDB_RT.GLOB) + EgtCutSurfTmPlane( AddIdTunnel, ptOn, -X_AX(), true, GDB_RT.GLOB) + ptOn = Point3d( dNewMaxX, 0, 0) + -- taglio della superficie lato destro + EgtCutSurfTmPlane( AddId, ptOn, X_AX(), true, GDB_RT.GLOB) + EgtCutSurfTmPlane( AddIdTunnel, ptOn, X_AX(), true, GDB_RT.GLOB) + else + -- eseguo trim sinistro + if i ~= 1 or bStartLeft then + ptOn = Point3d( dNewMinX, 0, 0) + -- taglio della superficie lato sinistro + EgtCutSurfTmPlane( AddId, ptOn, -X_AX(), true, GDB_RT.GLOB) + EgtCutSurfTmPlane( AddIdTunnel, ptOn, -X_AX(), true, GDB_RT.GLOB) + end + -- eseguo trim destro + dNewMaxX = dNewMinX + dSplitPartsLen + if i ~= nSplitParts or bStartRight then + ptOn = Point3d( dNewMaxX, 0, 0) + -- taglio della superficie lato destro + EgtCutSurfTmPlane( AddId, ptOn, X_AX(), true, GDB_RT.GLOB) + EgtCutSurfTmPlane( AddIdTunnel, ptOn, X_AX(), true, GDB_RT.GLOB) + end + -- il nuovo minimo è il punto massimo del precedente + dNewMinX = dNewMaxX + end + -- eseguo inserimento in modo da ordinare da X- a X+ + table.insert( vAddId, EgtIf( #vAddId == 0 or not bStartRight, 1, 2), AddId) + table.insert( vAddIdTunnel, EgtIf( #vAddIdTunnel == 0 or not bStartRight, 1, 2), AddIdTunnel) + end + end + else + -- TODO se è sulla coda, messaggio che posso rovinare + table.insert( vAddId, Proc.id) + end + + return vAddId, vAddIdTunnel +end + ------------------------------------------------------------------------------------------------------------- function STR0002.Make( bAddMachining, Proc, Part, CustomParameters) -- carico parametri de default e li aggiorno con quelli passati dal chiamante (potrebbero non essere congruenti) @@ -337,7 +499,7 @@ function STR0002.Make( bAddMachining, Proc, Part, CustomParameters) Strategy.Result = {} if not IsTopologyOk( Proc) then - local sErr = 'Feature '.. Proc.idFeature .. ' : strategy ' .. Strategy.Config.sStrategyId .. ' not implemented' + local sErr = 'Feature '.. Proc.idFeature .. ' : strategy ' .. StrategyLib.Config.sStrategyId .. ' not implemented' EgtOutLog( sErr) Strategy.Result.sStatus = 'Not-Applicable' Strategy.Result.nCompletionIndex = 0 @@ -350,128 +512,51 @@ function STR0002.Make( bAddMachining, Proc, Part, CustomParameters) local bAreAllApplyOk = true local ToolInfo = {} local Pocketing = {} - Pocketing.Steps = {} - Pocketing.LeadIn = {} Strategy.Machining = GetBestPocketingStrategy( Proc) if bAddMachining and Strategy.Result.sStatus ~= 'Not-Applicable' then - -- le lunghezza richiede spezzatura - if ( Proc.b3Box:getDimX() > BeamData.LONGCUT_MAXLEN) or ( Proc.b3Box:getDimX() > 0.7 * Part.b3Solid:getDimX() and Proc.b3Box:getDimX() > BeamData.LONGCUT_ENDLEN) then - -- recupero gruppo per geometria aggiuntiva - local nAddGrpId = BeamLib.GetAddGroup( Part.idPart) - local vAddId = {} - local bStartLeft, bStartRight + local vAddId, vAddIdTunnel = VerifySplitMachiningNeeded( Proc, Part) - -- se feature inizia al di sotto del limite sinistro - if Proc.b3Box:getMin():getX() < Part.b3Solid:getMin():getX() + BeamData.LONGCUT_ENDLEN then - bStartLeft = true - end - -- se feature inizia al di sotto del limite destro - if Proc.b3Box:getMax():getX() > Part.b3Solid:getMax():getX() - BeamData.LONGCUT_ENDLEN then - bStartRight = true - end - - -- salvo valori - local dNewMinX = Proc.b3Box:getMin():getX() - local dNewMaxX = Proc.b3Box:getMax():getX() - local dNewRest = Proc.b3Box:getDimX() - -- creo primo spezzone sulla sinistra - if bStartLeft then - local AddId = EgtCopyGlob( Proc.id, nAddGrpId) or GDB_ID.NULL - dNewMinX = max( ( Proc.b3Box:getMin():getX() + TOOLS[ToolInfo.nToolIndex].dDiameter * 2), Part.b3Solid:getMin():getX() + BeamData.LONGCUT_ENDLEN) - local ptOn = Point3d( dNewMinX, 0, 0) - dNewRest = abs( dNewMaxX - dNewMinX) - -- taglio della superficie lato sinistro - EgtCutSurfTmPlane( AddId, ptOn, X_AX(), true, GDB_RT.GLOB) - -- eseguo inserimento - table.insert( vAddId, AddId) - end - -- creo spezzone sulla destra - if bStartRight then - local AddId = EgtCopyGlob( Proc.id, nAddGrpId) or GDB_ID.NULL - dNewMaxX = min( ( Proc.b3Box:getMax():getX() - TOOLS[ToolInfo.nToolIndex].dDiameter * 2), Part.b3Solid:getMax():getX() - BeamData.LONGCUT_ENDLEN) - local ptOn = Point3d( dNewMaxX, 0, 0) - dNewRest = abs( dNewMaxX - dNewMinX) - -- taglio della superficie lato destro - EgtCutSurfTmPlane( AddId, ptOn, -X_AX(), true, GDB_RT.GLOB) - -- eseguo inserimento - table.insert( vAddId, EgtIf( BeamData.RIGHT_LOAD, 2, 1),AddId) - end - -- lavoro il restante - local nSplitParts = max( ceil( dNewRest / BeamData.LONGCUT_MAXLEN + 10 * GEO.EPS_SMALL), 2) - local dSplitPartsLen = dNewRest / nSplitParts - for i = 1, nSplitParts do - local AddId = EgtCopyGlob( Proc.id, nAddGrpId) or GDB_ID.NULL - local ptOn - -- eseguo trim sinistro - if i ~= 1 or bStartLeft then - ptOn = Point3d( dNewMinX, 0, 0) - -- taglio della superficie lato sinistro - EgtCutSurfTmPlane( AddId, ptOn, -X_AX(), true, GDB_RT.GLOB) - end - -- eseguo trim destro - dNewMaxX = dNewMinX + dSplitPartsLen - if i ~= nSplitParts or bStartRight then - ptOn = Point3d( dNewMaxX, 0, 0) - -- taglio della superficie lato destro - EgtCutSurfTmPlane( AddId, ptOn, X_AX(), true, GDB_RT.GLOB) - end - -- il nuovo minimo è il punto massimo del precedente - dNewMinX = dNewMaxX - -- eseguo inserimento in modo da ordinare da X- a X+ - table.insert( vAddId, EgtIf( BeamData.RIGHT_LOAD, 1+i, EgtIf( bStartLeft, 1, 2)), AddId) - end - -- setto i parametri di base comuni - Pocketing.nType = MCH_OY.POCKETING - Pocketing.nSubType = EgtIf( Proc.Topology.sName == 'Pocket-5-Blind', MCH_POCK_SUB.SPIRALOUT, MCH_POCK_SUB.SPIRALIN) - Pocketing.LeadIn.nType = MCH_POCK_LI.ZIGZAG - Pocketing.idProc = Proc.id - -- si applicano le lavorazioni - for i = 1, #vAddId do - for j = 1, #Strategy.Machining do - if Strategy.Machining[i].bIsApplicable then - Pocketing.Steps.dStep = TOOLS[Strategy.Machining[j].ToolInfo.nToolIndex].dStep - Pocketing.Steps.dSideStep = TOOLS[Strategy.Machining[j].ToolInfo.nToolIndex].dSideStep - Pocketing.nToolIndex = Strategy.Machining[j].ToolInfo.nToolIndex - Pocketing.LeadIn.dTangentDistance = TOOLS[Strategy.Machining[j].ToolInfo.nToolIndex].dDiameter/2 - Pocketing.LeadIn.dElevation = TOOLS[Strategy.Machining[j].ToolInfo.nToolIndex].dDiameter/2 - Pocketing.sDepth = -Strategy.Machining[j].ToolInfo.dResidualDepth - if j == 4 then - Pocketing.bToolInvert = true - end + -- si applicano le lavorazioni + for i = 1, #vAddId do + for j = 1, #Strategy.Machining do + if Strategy.Machining[j].bIsApplicable then + Pocketing = {} + Pocketing.Steps = {} + Pocketing.LeadIn = {} + Pocketing.nType = MCH_OY.POCKETING + Pocketing.nSubType = EgtIf( Proc.Topology.sName == 'Pocket-5-Blind', MCH_POCK_SUB.SPIRALOUT, MCH_POCK_SUB.SPIRALIN) + Pocketing.LeadIn.nType = MCH_POCK_LI.ZIGZAG + Pocketing.Steps.dStep = TOOLS[Strategy.Machining[j].ToolInfo.nToolIndex].dStep + Pocketing.Steps.dSideStep = TOOLS[Strategy.Machining[j].ToolInfo.nToolIndex].dSideStep + Pocketing.nToolIndex = Strategy.Machining[j].ToolInfo.nToolIndex + Pocketing.LeadIn.dTangentDistance = TOOLS[Strategy.Machining[j].ToolInfo.nToolIndex].dDiameter/2 + Pocketing.LeadIn.dElevation = TOOLS[Strategy.Machining[j].ToolInfo.nToolIndex].dDiameter/2 + Pocketing.sDepth = -Strategy.Machining[j].ToolInfo.dResidualDepth + -- il quarto ciclo è la lavorazione opposta sulla faccia Tunnel + if Strategy.Machining[j].bToolInvert then + Pocketing.bToolInvert = true + end + -- se ho una sola trimesh, sto lavorando la Proc direttamente e non ho spezzato. Applico direttamente alla geometria calcolata prima + if #vAddId == 1 then + Pocketing.Geometry = {{ Strategy.Machining[j].idProc, Strategy.Machining[j].idFaceToMachine}} + bAreAllApplyOk = MachiningLib.AddNewMachining( Proc, Pocketing) + else -- TODO settare parametro per indicare qual è lo spezzone che deve essere fatto dopo il taglio di separazione - for k=1, Proc.nFct do + for k = 1, Proc.nFct do local vtNSplitFace - _, vtNSplitFace = EgtSurfTmFacetCenter( vAddId[i], k - 1, GDB_ID.ROOT) - if vtNSplitFace and AreSameVectorApprox( vtNSplitFace, Strategy.Machining[j].vtFaceNormal) then - Pocketing.Geometry = {{ vAddId[i], k - 1}} - bAreAllApplyOk = MachiningLib.AddNewMachining( Proc, Pocketing) + local dIdTm = EgtIf( Strategy.Machining[j].bMachAppliedToTunnelFace, vAddIdTunnel[i], vAddId[i]) + _, vtNSplitFace = EgtSurfTmFacetCenter( dIdTm, k - 1, GDB_ID.ROOT) + if vtNSplitFace and AreSameVectorApprox( vtNSplitFace * EgtIf( Pocketing.bToolInvert, -1, 1), Strategy.Machining[j].vtFaceNormal) then + Pocketing.Geometry = {{ dIdTm, k - 1}} + bAreAllApplyOk = bAreAllApplyOk and MachiningLib.AddNewMachining( Proc, Pocketing) break end end end end end - else - Pocketing.nType = MCH_OY.POCKETING - Pocketing.nSubType = EgtIf( Proc.Topology.sName == 'Pocket-5-Blind', MCH_POCK_SUB.SPIRALOUT, MCH_POCK_SUB.SPIRALIN) - Pocketing.LeadIn.nType = MCH_POCK_LI.ZIGZAG - for i = 1, #Strategy.Machining do - if Strategy.Machining[i].bIsApplicable then - Pocketing.Steps.dStep = TOOLS[Strategy.Machining[i].ToolInfo.nToolIndex].dStep - Pocketing.Steps.dSideStep = TOOLS[Strategy.Machining[i].ToolInfo.nToolIndex].dSideStep - Pocketing.nToolIndex = Strategy.Machining[i].ToolInfo.nToolIndex - Pocketing.LeadIn.dTangentDistance = TOOLS[Strategy.Machining[i].ToolInfo.nToolIndex].dDiameter/2 - Pocketing.LeadIn.dElevation = TOOLS[Strategy.Machining[i].ToolInfo.nToolIndex].dDiameter/2 - Pocketing.sDepth = -Strategy.Machining[i].ToolInfo.dResidualDepth - if i == 4 and Strategy.Machining[i].bInvertTool then - Pocketing.bToolInvert = true - end - Pocketing.Geometry = {{ Strategy.Machining[i].idProc, Strategy.Machining[i].idFaceToMachine}} - bAreAllApplyOk = MachiningLib.AddNewMachining( Proc, Pocketing) - end - end end else bAreAllApplyOk = false