diff --git a/CamAuto.lua b/CamAuto.lua index 12cf844..4fe234a 100644 --- a/CamAuto.lua +++ b/CamAuto.lua @@ -1,4 +1,4 @@ --- 2026/03/14 18:00:00 +-- 2026/03/16 12:30:00 -- Programma per Cam automatico in OmagCut -- Legenda codici errore (CAM.ERR) : -- 0 = tutto bene @@ -188,8 +188,6 @@ local function SquaringWJ( MyTabRtf, TabOutCrv, TabInCrv) dOrigSideAng<0: SideAng1=a, Offset1=H*tan(a) | SideAng2=0, Offset2=0, Depth=H ]]-- - EgtOutLog( 'Nuova gestione rettifica talloni con WJ') - local TabTrimCrvs = {} for i = 1, #MyTabRtf do @@ -1298,12 +1296,8 @@ function CAM.ApplyWaterJettings( TabEnt, TabPartMch, sLay) local nIntAngLoType = MCH_WJET_LO.LINEAR local dIntAngLoTang = 0 local dIntAngLoPerp = 2 - -- preparo tabella con info circonferenze preforo - local TabEntPreDrill = {} - + local TabMPartC = {} - -- questa tabella contiene l'indice della tabella sopra che devono esseere ricopiate - local TabMNewPartC = {} -- Preparo tabella info tagli completi: **TabMPartC** partendo dall'identificativo dell'entità for i = 1, #TabEnt do local nEntId = TabEnt[i] @@ -1423,6 +1417,32 @@ function CAM.ApplyWaterJettings( TabEnt, TabPartMch, sLay) end -- FINE: Preparo tabella info tagli parziali, solo se tipo operazione **MCH_OY.SAWING** + -- Se richiesta ottimizzazione, escludo i tagli verticali sovrapposti + if bWaterJetOptimize then + local dMaxDist = 1.4 + for i = 1, #TabMPartC do + local CurrMPC = TabMPartC[i] + local ptStart = EgtSP( CurrMPC.EntId, GDB_ID.ROOT) + local ptEnd = EgtEP( CurrMPC.EntId, GDB_ID.ROOT) + local ptMid = EgtMP( CurrMPC.EntId, GDB_ID.ROOT) + if abs( CurrMPC.SideAng) < GEO.EPS_ANG_SMALL then + for j = 1, #TabMPartC do + if j ~= i then + local OtherMPC = TabMPartC[j] + if not OtherMPC.Skip and abs( OtherMPC.SideAng) < GEO.EPS_ANG_SMALL and + EgtPointCurveDist( ptStart, OtherMPC.EntId, GDB_RT.GLOB) < dMaxDist and + EgtPointCurveDist( ptEnd, OtherMPC.EntId, GDB_RT.GLOB) < dMaxDist and + EgtPointCurveDist( ptMid, OtherMPC.EntId, GDB_RT.GLOB) < dMaxDist then + CurrMPC.Skip = true + CurrMPC.Join = false + break + end + end + end + end + end + end + -- |CONGIUNZIONI TAGLI| -- Cerco le congiunzioni -> aggiorno i campi della tabella **RecMPartC.PrevInd** e **RecMPartC2.NextInd** !ATTENZIONE! sono gli indici della tabella (NON dell'entità) for i = 1, #TabMPartC do @@ -1437,10 +1457,8 @@ function CAM.ApplyWaterJettings( TabEnt, TabPartMch, sLay) if ( RecMPartC2.OperId == 0 or RecMPartC2.EndStrict) and ( RecMPartC2.Join or #TabEnt == 0) then local ptEnd = EgtEP( RecMPartC2.EntId, GDB_ID.ROOT) -- se estremi e angoli coincidono - -- (tolti i positivi il 2021/03/24 per fare rettangoli con lati indipendenti anche con misure sul top, poi reintrodotti) if AreSamePointEpsilon( ptStart, ptEnd, 10 * GEO.EPS_SMALL) and abs( RecMPartC.SideAng - RecMPartC2.SideAng) < 10 * GEO.EPS_ANG_SMALL then - --and ( not bSizeAlwaysOnTop or RecMPartC.SideAng <= 10 * GEO.EPS_ANG_SMALL) then RecMPartC.PrevInd = j RecMPartC2.NextInd = i break @@ -1488,21 +1506,20 @@ function CAM.ApplyWaterJettings( TabEnt, TabPartMch, sLay) end -- FINE: Cerco le congiunzioni - --[[Stampe di debug - for i = 1, #TabMPartC do - local RecMPartC = TabMPartC[i] - EgtOutLog( 'OperId='..tostring( RecMPartC.OperId).. - ', StartStrict='..tostring(RecMPartC.StartStrict)..', EndStrict='..tostring(RecMPartC.EndStrict).. - ', Sal='..EgtNumToString(RecMPartC.Sal,2)..', Eal='..EgtNumToString(RecMPartC.Eal,2).. - ', DeltaT='..EgtNumToString(RecMPartC.DeltaT,2)..', DeltaTI='..EgtNumToString(RecMPartC.DeltaTI,2).. - ', EntId='..tostring(RecMPartC.EntId)..', EntLen='..EgtNumToString(RecMPartC.EntLen,2).. - ', PrevAng='..EgtNumToString(RecMPartC.PrevAng,2)..', NextAng='..EgtNumToString(RecMPartC.NextAng,2).. - ', SideAng='..EgtNumToString(RecMPartC.SideAng,2).. - ', PrevInd='..tostring(RecMPartC.PrevInd)..', NextInd='..tostring(RecMPartC.NextInd).. - ', StartDone='..tostring(RecMPartC.StartDone)..', EndDone='..tostring(RecMPartC.EndDone).. - ', Double='..tostring(RecMPartC.Double)..', Width='..EgtNumToString(RecMPartC.Width,2)) - end]] - -- + --Stampe di debug + --for i = 1, #TabMPartC do + -- local RecMPartC = TabMPartC[i] + -- EgtOutLog( 'OperId='..tostring( RecMPartC.OperId).. + -- ', Sstc='..tostring( RecMPartC.StartStrict)..', Estc='..tostring( RecMPartC.EndStrict).. + -- ', Sal='..EgtNumToString( RecMPartC.Sal, 2)..', Eal='..EgtNumToString( RecMPartC.Eal, 2).. + -- ', DeltaT='..EgtNumToString( RecMPartC.DeltaT, 2)..', DeltaTI='..EgtNumToString( RecMPartC.DeltaTI, 2).. + -- ', EntId='..tostring( RecMPartC.EntId)..', EntLen='..EgtNumToString( RecMPartC.EntLen, 2).. + -- ', PrevAng='..EgtNumToString( RecMPartC.PrevAng, 2)..', NextAng='..EgtNumToString( RecMPartC.NextAng, 2).. + -- ', SideAng='..EgtNumToString( RecMPartC.SideAng, 2)..', Join='..tostring( RecMPartC.Join)..', Skip='..tostring( RecMPartC.Skip or false).. + -- ', PrevInd='..tostring( RecMPartC.PrevInd)..', NextInd='..tostring( RecMPartC.NextInd).. + -- ', Sdone='..tostring( RecMPartC.StartDone)..', Edone='..tostring( RecMPartC.EndDone).. + -- ', Double='..tostring( RecMPartC.Double or false)..', Width='..EgtNumToString( RecMPartC.Width or 0, 2)) + --end -- Ciclo sui tratti concatenabili for i = 1, #TabMPartC do @@ -1560,7 +1577,13 @@ function CAM.ApplyWaterJettings( TabEnt, TabPartMch, sLay) -- aggiusto inizio local dStartAddLen = 0 if RecMPartCs.OperId == 0 then - if RecMPartCs.PrevAng > - 175 and RecMPartCs.PrevAng < - 5 then + if bWaterJetOptimize and abs( RecMPartCs.SideAng) < GEO.EPS_ANG_SMALL then + dStartAddLen = 0 + EgtSetMachiningParam( MCH_MP.LIHOLE, false) + EgtSetMachiningParam( MCH_MP.LEADINTYPE, nIntAngLiType) + EgtSetMachiningParam( MCH_MP.LITANG, dRad) + EgtSetMachiningParam( MCH_MP.LIPERP, 0) + elseif RecMPartCs.PrevAng > - 175 and RecMPartCs.PrevAng < - 5 then dStartAddLen = dRad * ( cos( 180 + RecMPartCs.PrevAng) + 1) / sin( 180 + RecMPartCs.PrevAng) EgtSetMachiningParam( MCH_MP.LEADINTYPE, nIntAngLiType) EgtSetMachiningParam( MCH_MP.LITANG, dIntAngLiTang) @@ -1581,7 +1604,12 @@ function CAM.ApplyWaterJettings( TabEnt, TabPartMch, sLay) -- aggiusto fine local dEndAddLen = 0 if RecMPartCe.OperId == 0 then - if RecMPartCe.NextAng > - 175 and RecMPartCe.NextAng < - 5 then + if bWaterJetOptimize and abs( RecMPartCs.SideAng) < GEO.EPS_ANG_SMALL then + dEndAddLen = 0 + EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, nIntAngLoType) + EgtSetMachiningParam( MCH_MP.LOTANG, dRad) + EgtSetMachiningParam( MCH_MP.LOPERP, 0) + elseif RecMPartCe.NextAng > - 175 and RecMPartCe.NextAng < - 5 then dEndAddLen = dRad * ( cos( 180 + RecMPartCe.NextAng) + 1) / sin( 180 + RecMPartCe.NextAng) EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, nIntAngLoType) EgtSetMachiningParam( MCH_MP.LOTANG, dIntAngLoTang) @@ -1734,7 +1762,13 @@ function CAM.ApplyWaterJettings( TabEnt, TabPartMch, sLay) if bInvert then dStWhiExt, dEdWhiExt = dEdWhiExt, dStWhiExt end -- aggiusto inizio local dStartAddLen = 0 - if dPrevAng < - 5 and dPrevAng > - 175 then + if bWaterJetOptimize and abs( RecMPartC.SideAng) < GEO.EPS_ANG_SMALL then + dStartAddLen = 0 + EgtSetMachiningParam( MCH_MP.LIHOLE, false) + EgtSetMachiningParam( MCH_MP.LEADINTYPE, nIntAngLiType) + EgtSetMachiningParam( MCH_MP.LITANG, dRad) + EgtSetMachiningParam( MCH_MP.LIPERP, 0) + elseif dPrevAng < - 5 and dPrevAng > - 175 then dStartAddLen = dRad * ( cos( 180 + dPrevAng) + 1) / sin( 180 + dPrevAng) EgtSetMachiningParam( MCH_MP.LEADINTYPE, nIntAngLiType) EgtSetMachiningParam( MCH_MP.LITANG, dIntAngLiTang) @@ -1744,7 +1778,12 @@ function CAM.ApplyWaterJettings( TabEnt, TabPartMch, sLay) EgtSetMachiningParam( MCH_MP.STARTADDLEN, - dStartAddLen) -- aggiusto fine local dEndAddLen = 0 - if dNextAng < - 5 and dNextAng > - 175 then + if bWaterJetOptimize and abs( RecMPartC.SideAng) < GEO.EPS_ANG_SMALL then + dEndAddLen = 0 + EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, nIntAngLoType) + EgtSetMachiningParam( MCH_MP.LOTANG, dRad) + EgtSetMachiningParam( MCH_MP.LOPERP, 0) + elseif dNextAng < - 5 and dNextAng > - 175 then dEndAddLen = dRad * ( cos( 180 + dNextAng) + 1) / sin( 180 + dNextAng) EgtSetMachiningParam( MCH_MP.LEADOUTTYPE, nIntAngLoType) EgtSetMachiningParam( MCH_MP.LOTANG, dIntAngLoTang) @@ -1819,6 +1858,11 @@ function CAM.ApplyWaterJettings( TabEnt, TabPartMch, sLay) end EgtSetOperationStatus( nMill, false) EgtSetInfo( nMill, 'Lay', sLay) + if RecMPartC.Skip then + local nPartId = EgtGetParent(EgtGetParent( RecMPartC.EntId)) + CAM.ErasePreviewInPiece( nMill, nPartId) + EgtRemoveOperation( nMill) + end else EgtRemoveOperation( nMill) end @@ -4856,16 +4900,6 @@ function CAM.UpdateAllTp() end ------ Cancellazione delle lavorazioni --------------------- -local function EraseWjDrill( TabPart) - if #TabPart < 1 then - return - end - for i = 1, #TabPart do - EgtErase( EgtGetNameInGroup( TabPart[i].Part, "WjDrill")) - EgtErase( EgtGetNameInGroup( TabPart[i].Part, "RegionWjDrill")) - end -end - local function EraseWjRectification( TabPart) if #TabPart < 1 then return @@ -4889,8 +4923,6 @@ function CAM.Erase() -- Passo al grezzo successivo nPartId = EgtGetNextPartInRawPart( nPartId) end - -- cancello WjDrill - EraseWjDrill( TabErase) -- cancello wjRectification EraseWjRectification( TabErase) -- Cancello le lavorazioni @@ -4903,8 +4935,6 @@ function CAM.Erase() local TabErase = {} -- Recupero gli identificativi TabErase = CAM.FindPartMachinings( CAM.PARTID, TabErase) - -- cancello WjDrill - EraseWjDrill( TabErase) -- cancello wjRectification EraseWjRectification( TabErase) -- Cancello le lavorazioni @@ -5448,71 +5478,63 @@ end ------------------------------------------------------------------------------- local function SortWaterJets( nPhase, LastMch, sLay) -- dichiarazione tabella - local TabMill = {} - local TabDrill = {} + local TabWj = {} -- recupero i tagli ad acqua e i loro centri - local nMillId = EgtGetPhaseDisposition( nPhase) - while nMillId do + local nWjId = EgtGetPhaseDisposition( nPhase) + while nWjId do -- Se appartiene alla fase corrente e taglio ad acqua non vuoto del layer voluto - if EgtGetOperationPhase( nMillId) == nPhase and EgtGetOperationType( nMillId) == MCH_OY.WATERJETTING and - ( not sLay or EgtGetInfo( nMillId, 'Lay') == sLay) then + if EgtGetOperationPhase( nWjId) == nPhase and EgtGetOperationType( nWjId) == MCH_OY.WATERJETTING and + ( not sLay or EgtGetInfo( nWjId, 'Lay') == sLay) then -- imposto come lavorazione corrente - EgtSetCurrMachining( nMillId) - local nStartId, nEndId = CAM.GetEntIdFromCurrMachining() - if nStartId ~= GDB_ID.NULL and EgtExistsObj( nStartId) and nEndId ~= GDB_ID.NULL and EgtExistsObj( nEndId) then - local ptStart = EgtSP( nStartId, GDB_ID.ROOT) - local ptEnd = EgtEP( nEndId, GDB_ID.ROOT) - local bInvert = EgtGetMachiningParam( MCH_MP.INVERT) + EgtSetCurrMachining( nWjId) + -- cerco il gruppo di preview + local nMchPvId = EgtGetFirstNameInGroup( nWjId, 'PV') + local nGeoPvId = EgtGetInfo( nMchPvId or GDB_ID.NULL, 'PvId', 'i') + local nP1PvId = EgtGetFirstNameInGroup( nGeoPvId or GDB_ID.NULL, 'P1') + if nP1PvId then + local ptStart = EgtGetInfo( nP1PvId, 'START', 'p') + local ptEnd = EgtGetInfo( nP1PvId, 'END', 'p') local dAng = EgtGetMachiningParam( MCH_MP.SIDEANGLE) - if bInvert then - ptStart, ptEnd = ptEnd, ptStart - end - local ParentId = EgtGetParent( nStartId) - local sName = EgtGetName( ParentId) - if sName == "WjDrill" then - table.insert( TabDrill, {Id=nMillId, Start= ptStart, End = ptEnd, Ang=abs( dAng)}) - else - table.insert( TabMill, {Id=nMillId, Start= ptStart, End = ptEnd, Ang=abs( dAng)}) - end + table.insert( TabWj, {Id=nWjId, Start=ptStart, End=ptEnd, Ang=abs( dAng)}) end end - nMillId = EgtGetNextOperation( nMillId) + nWjId = EgtGetNextOperation( nWjId) end - -- calcolo ordinamento - EgtSpInit() - for i = 1, #TabDrill do - EgtSpAddPoint( TabDrill[i].Start:getX(), TabDrill[i].Start:getY(), 0, 0, TabDrill[i].Ang, - TabDrill[i].End:getX(), TabDrill[i].End:getY(), 0, 0, TabDrill[i].Ang) + -- log dei dati lavorazioni per debug + EgtOutLog( 'Dati lavorazioni :') + for i = 1, #TabWj do + EgtOutLog( 'WjId='..tostring( TabWj[i].Id).. + ' Start='..tostring( TabWj[i].Start)..' End='..tostring( TabWj[i].End)..' Ang='..EgtNumToString( TabWj[i].Ang, 3)) end - EgtSpSetAngularParams( 1000, 40, 2000, 60) - EgtSpSetOpenBound( true, SHP_OB.NEAR_PNT, 0, -4000, 0, 0, 90) - local vMillOrd = EgtSpCalculate( SHP_TY.OPEN) - EgtSpTerminate() - -- applico ordinamento calcolato - -- parto da LastMch precedente - if vMillOrd then - for i = 1, #vMillOrd do - EgtRelocateGlob( TabDrill[vMillOrd[i]].Id, LastMch, GDB_IN.AFTER) - LastMch = TabDrill[vMillOrd[i]].Id - end - end - -- calcolo ordinamento EgtSpInit() - for i = 1, #TabMill do - EgtSpAddPoint( TabMill[i].Start:getX(), TabMill[i].Start:getY(), 0, 0, TabMill[i].Ang, - TabMill[i].End:getX(), TabMill[i].End:getY(), 0, 0, TabMill[i].Ang) + for i = 1, #TabWj do + EgtSpAddPoint( TabWj[i].Start:getX(), TabWj[i].Start:getY(), 0, 0, TabWj[i].Ang, + TabWj[i].End:getX(), TabWj[i].End:getY(), 0, 0, TabWj[i].Ang) end EgtSpSetAngularParams( 1000, 40, 2000, 60) - EgtSpSetOpenBound( true, SHP_OB.NEAR_PNT, 0, -4000, 0, 0, 90) - vMillOrd = EgtSpCalculate( SHP_TY.OPEN) + local dSpStartX = 0 + local dSpStartY = -4000 + if bWaterJetOptimize then + for i = 1, #TabWj do + if ( AreSamePointEpsilon( TabWj[i].Start, TabWj[i].End, 1)) then + dSpStartX = TabWj[i].Start:getX() + dSpStartY = TabWj[i].Start:getY() + break + end + end + end + EgtSpSetOpenBound( true, SHP_OB.NEAR_PNT, dSpStartX, dSpStartY, 0, 0, 90) + vWjOrd = EgtSpCalculate( SHP_TY.OPEN) EgtSpTerminate() + -- log dell'ordinamento per debug + EgtOutLog( 'Ordinamento :'..table.concat( vWjOrd, ',')) -- applico ordinamento calcolato -- parto da LastMch precedente - if vMillOrd then - for i = 1, #vMillOrd do - EgtRelocateGlob( TabMill[vMillOrd[i]].Id, LastMch, GDB_IN.AFTER) - LastMch = TabMill[vMillOrd[i]].Id + if vWjOrd then + for i = 1, #vWjOrd do + EgtRelocateGlob( TabWj[vWjOrd[i]].Id, LastMch, GDB_IN.AFTER) + LastMch = TabWj[vWjOrd[i]].Id end end return LastMch