diff --git a/BatchProcess.lua b/BatchProcess.lua index 1a69edf..5054cf9 100644 --- a/BatchProcess.lua +++ b/BatchProcess.lua @@ -1,4 +1,4 @@ --- BatchProcess.lua by Egaltech s.r.l. 2020/06/12 +-- BatchProcess.lua by Egaltech s.r.l. 2020/06/29 -- Gestione calcolo batch disposizione e lavorazioni per Pareti @@ -247,16 +247,24 @@ if bToProcess then local b3Solid = vWall[i].Box -- rotazione local dRotAng = EgtGetInfo( vWall[i].Id, 'ROTATED', 'd') - if dRotAng and abs( dRotAng) > GEO.EPS_ANG_SMALL then - local ptRotCen = b3Solid:getCenter() - EgtRotate( vWall[i].Id, ptRotCen, X_AX(), dRotAng, GDB_RT.GLOB) - b3Solid:rotate( ptRotCen, X_AX(), dRotAng) + if dRotAng then + if abs( dRotAng) > GEO.EPS_ANG_SMALL then + local ptRotCen = b3Solid:getCenter() + EgtRotate( vWall[i].Id, ptRotCen, X_AX(), dRotAng, GDB_RT.GLOB) + b3Solid:rotate( ptRotCen, X_AX(), dRotAng) + end + EgtSetInfo( vWall[i].Id, 'ROTATED_DONE', dRotAng) + EgtRemoveInfo( vWall[i].Id, 'ROTATED') end -- inversione - local dInvAng = 180 - ( EgtGetInfo( vWall[i].Id, 'INVERTED', 'd') or 0) - if abs( dInvAng) > GEO.EPS_ANG_SMALL then - local ptInvCen = b3Solid:getCenter() - EgtRotate( vWall[i].Id, ptInvCen, Z_AX(), dInvAng, GDB_RT.GLOB) + local dInvAng = EgtGetInfo( vWall[i].Id, 'INVERTED', 'd') + if dInvAng then + if abs( 180 - dInvAng) > GEO.EPS_ANG_SMALL then + local ptInvCen = b3Solid:getCenter() + EgtRotate( vWall[i].Id, ptInvCen, Z_AX(), 180 - dInvAng, GDB_RT.GLOB) + end + EgtSetInfo( vWall[i].Id, 'INVERTED_DONE', dInvAng) + EgtRemoveInfo( vWall[i].Id, 'INVERTED') end end diff --git a/LuaLibs/MachiningLib.lua b/LuaLibs/WMachiningLib.lua similarity index 89% rename from LuaLibs/MachiningLib.lua rename to LuaLibs/WMachiningLib.lua index da62d7c..4f4ca85 100644 --- a/LuaLibs/MachiningLib.lua +++ b/LuaLibs/WMachiningLib.lua @@ -2,12 +2,12 @@ -- Libreria ricerca lavorazioni per Pareti -- Tabella per definizione modulo -local MachiningLib = {} +local WMachiningLib = {} -- Include require( 'EgtBase') -EgtOutLog( ' MachiningLib started', 1) +EgtOutLog( ' WMachiningLib started', 1) -- Dati local WD = require( 'WallData') @@ -28,7 +28,7 @@ local function SetCurrMachiningAndTool( sMachName) end --------------------------------------------------------------------- -function MachiningLib.FindCutting( sType) +function WMachiningLib.FindCutting( sType) for i = 1, #Cuttings do local Cutting = Cuttings[i] if Cutting.On and Cutting.Type == sType and SetCurrMachiningAndTool( Cutting.Name) then @@ -38,7 +38,7 @@ function MachiningLib.FindCutting( sType) end --------------------------------------------------------------------- -function MachiningLib.FindMilling( sType, dDepth, sTuuidMstr) +function WMachiningLib.FindMilling( sType, dDepth, sTuuidMstr) for i = 1, #Millings do local Milling = Millings[i] if Milling.On and Milling.Type == sType and SetCurrMachiningAndTool( Milling.Name) then @@ -53,7 +53,7 @@ function MachiningLib.FindMilling( sType, dDepth, sTuuidMstr) end --------------------------------------------------------------------- -function MachiningLib.FindPocketing( sType, dMaxDiam, dDepth) +function WMachiningLib.FindPocketing( sType, dMaxDiam, dDepth) for i = 1, #Pocketings do local Pocketing = Pocketings[i] if Pocketing.On and Pocketing.Type == sType and SetCurrMachiningAndTool( Pocketing.Name) then @@ -68,7 +68,7 @@ function MachiningLib.FindPocketing( sType, dMaxDiam, dDepth) end --------------------------------------------------------------------- -function MachiningLib.FindSawing( sType) +function WMachiningLib.FindSawing( sType) for i = 1, #Sawings do local Sawing = Sawings[i] if Sawing.On and Sawing.Type == sType and SetCurrMachiningAndTool( Sawing.Name) then @@ -79,7 +79,7 @@ function MachiningLib.FindSawing( sType) end --------------------------------------------------------------------- -function MachiningLib.FindDrilling( dDiam) +function WMachiningLib.FindDrilling( dDiam) -- ricerca sulle forature, dal diametro maggiore al minore for i = #Drillings, 1, -1 do local Drilling = Drillings[i] @@ -105,4 +105,4 @@ function MachiningLib.FindDrilling( dDiam) end ------------------------------------------------------------------------------------------------------------- -return MachiningLib +return WMachiningLib diff --git a/LuaLibs/ProcessDrill.lua b/LuaLibs/WProcessDrill.lua similarity index 96% rename from LuaLibs/ProcessDrill.lua rename to LuaLibs/WProcessDrill.lua index 45682bd..bbe2f4f 100644 --- a/LuaLibs/ProcessDrill.lua +++ b/LuaLibs/WProcessDrill.lua @@ -11,7 +11,7 @@ EgtOutLog( ' ProcessDrill started', 1) -- Dati local WD = require( 'WallData') -local ML = require( 'MachiningLib') +local WM = require( 'WMachiningLib') --------------------------------------------------------------------- -- Riconoscimento della feature @@ -93,7 +93,7 @@ function ProcessDrill.Make( Proc, nRawId, b3Raw) if Proc.Fcs == 0 then bToInvert = true end if bToInvert then vtExtr = - vtExtr end -- recupero la lavorazione - local sDrilling, nType = ML.FindDrilling( dDiam) + local sDrilling, nType = WM.FindDrilling( dDiam) if not sDrilling then local sErr = 'Error on process ' .. tostring( Proc.Id) .. ' drilling not found in library' EgtOutLog( sErr) diff --git a/LuaLibs/ProcessFreeContour.lua b/LuaLibs/WProcessFreeContour.lua similarity index 78% rename from LuaLibs/ProcessFreeContour.lua rename to LuaLibs/WProcessFreeContour.lua index 1dedcfe..3eab0d1 100644 --- a/LuaLibs/ProcessFreeContour.lua +++ b/LuaLibs/WProcessFreeContour.lua @@ -12,7 +12,7 @@ EgtOutLog( ' ProcessFreeContour started', 1) -- Dati local WD = require( 'WallData') -local ML = require( 'MachiningLib') +local WM = require( 'WMachiningLib') --------------------------------------------------------------------- -- Riconoscimento della feature @@ -47,6 +47,27 @@ function ProcessFreeContour.Classify( Proc, b3Raw) end end +--------------------------------------------------------------------- +local function GetOtherRegions( nPartId) + local vOthers = {} + local nOtherId = EgtGetFirstPartInRawPart( EgtGetFirstRawPart() or GDB_ID.NULL) + while nOtherId do + local nRegId = EgtGetFirstInGroup( EgtGetFirstNameInGroup( nOtherId, 'Outline') or GDB_ID.NULL) + while nRegId do + local vtN = EgtSurfFrNormVersor( nRegId, GDB_ID.ROOT) + if vtN and AreSameVectorApprox( vtN, Z_AX()) then + local b3Reg = EgtGetBBoxGlob( nRegId, GDB_BB.STANDARD) + if b3Reg then + table.insert( vOthers, { PartId = nOtherId, RegId = nRegId, Box = b3Reg}) + end + end + nRegId = EgtGetNext( nRegId) + end + nOtherId = EgtGetNextPartInRawPart( nOtherId) + end + return vOthers +end + --------------------------------------------------------------------- local function AddMillings( sMilling, vFace, Proc, nRawId, b3Raw) -- recupero i dati dell'utensile @@ -168,27 +189,29 @@ local function MakeByCut( Proc, nRawId, b3Raw) return false, sErr end -- recupero la lavorazione di fresatura - local sMilling = ML.FindMilling( 'FreeContour') + local sMilling = WM.FindMilling( 'FreeContour') if not sMilling then local sErr = 'Error : milling not found in library' EgtOutLog( sErr) return false, sErr end -- recupero la lavorazione di taglio con lama - local sCutting = ML.FindCutting( 'Standard') + local sCutting = WM.FindCutting( 'Standard') if not sCutting then local sErr = 'Error : cutting not found in library' EgtOutLog( sErr) return false, sErr end - -- recupero i dati dell'utensile + -- recupero i dati della lama local dSawDiam = 400 - local dMaxDepth = 0 + local dSawThick = 10 + local dSawMaxDepth = 0 if EgtMdbSetCurrMachining( sCutting) then local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then dSawDiam = EgtTdbGetCurrToolParam( MCH_TP.DIAM) or dSawDiam - dMaxDepth = EgtTdbGetCurrToolMaxDepth() or dMaxDepth + dSawThick = EgtTdbGetCurrToolParam( MCH_TP.THICK) or dSawThick + dSawMaxDepth = EgtTdbGetCurrToolMaxDepth() or dSawMaxDepth end end -- recupero i dati di tutte le facce @@ -207,8 +230,8 @@ local function MakeByCut( Proc, nRawId, b3Raw) for i = 1, #vFace do -- verifico l'affondamento local dDepth = WD.CUT_EXTRA - if vFace[i].Width + WD.CUT_EXTRA > dMaxDepth then - dDepth = dMaxDepth - vFace[i].Width + if vFace[i].Width + WD.CUT_EXTRA > dSawMaxDepth then + dDepth = dSawMaxDepth - vFace[i].Width end -- lunghezza baffo local dElev = vFace[i].Width + dDepth @@ -232,6 +255,52 @@ local function MakeByCut( Proc, nRawId, b3Raw) vFace[i].Whisk = dWhisk vFace[i].Type = nType end + -- recupero le regioni degli altri pezzi + local vOthers = GetOtherRegions( Proc.PartId) + -- verifico i baffi sporgenti dei tagli rispetto alle altre regioni + local nAddGrpId = WL.GetAddGroup( Proc.PartId) + for i = 1, #vFace do + -- verifico il baffo iniziale + if vFace[i].Type ~= 4 and ( vFace[i].Type & 1) == 0 then + -- creo il rettangolo del baffo + local vtDir = Vector3d( vFace[i].Norm) ; vtDir:rotate( Z_AX(), -90) + local ptIni = vFace[i].Cen + vFace[i].Len / 2 * vtDir + local ptDir = ptIni + vFace[i].Whisk * vtDir + local ptCross = ptDir + dSawThick * vFace[i].Norm + local WhId = EgtSurfFrRectangle3P( nAddGrpId, ptIni, ptCross, ptDir, GDB_RT.GLOB) + local b3Wh = EgtGetBBoxGlob( WhId or GDB_ID.NULL, GDB_BB.STANDARD) + -- verifico se interferisce con gli altri pezzi + for j = 1, #vOthers do + if OverlapsXY( b3Wh, vOthers[j].Box) then + local nClass = EgtSurfFrChunkSimpleClassify( WhId, 0, vOthers[j].RegId, 0) + if nClass ~= GDB_RC.OUT then + vFace[i].Type = vFace[i].Type + 1 + break + end + end + end + end + -- verifico il baffo finale + if vFace[i].Type ~= 4 and ( vFace[i].Type & 2) == 0 then + -- creo il rettangolo del baffo + local vtDir = Vector3d( vFace[i].Norm) ; vtDir:rotate( Z_AX(), 90) + local ptIni = vFace[i].Cen + vFace[i].Len / 2 * vtDir + local ptDir = ptIni + vFace[i].Whisk * vtDir + local ptCross = ptDir + dSawThick * vFace[i].Norm + local WhId = EgtSurfFrRectangle3P( nAddGrpId, ptIni, ptCross, ptDir, GDB_RT.GLOB) + local b3Wh = EgtGetBBoxGlob( WhId or GDB_ID.NULL, GDB_BB.STANDARD) + -- verifico se interferisce con gli altri pezzi + for j = 1, #vOthers do + if OverlapsXY( b3Wh, vOthers[j].Box) then + local nClass = EgtSurfFrChunkSimpleClassify( WhId, 0, vOthers[j].RegId, 0) + if nClass ~= GDB_RC.OUT then + vFace[i].Type = vFace[i].Type + 2 + break + end + end + end + end + end -- inserimento dei tagli di lama local bCtOk, sCtErr = AddCuts( sCutting, vFace, Proc, nRawId, b3Raw) if not bCtOk then return bCtOk, sCtErr end @@ -265,7 +334,7 @@ local function MakeByMill( Proc, nRawId, b3Raw) local b3Aux = EgtGetBBoxGlob( AuxId, GDB_BB.STANDARD) local bToolInv = ( vtExtr:getZ() < -0.1) -- recupero la lavorazione - local sMilling = ML.FindMilling( 'FreeContour') + local sMilling = WM.FindMilling( 'FreeContour') if not sMilling then local sErr = 'Error : milling not found in library' EgtOutLog( sErr) @@ -340,7 +409,7 @@ local function MakeByPocket( Proc, nRawId, b3Raw) local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) --local bToolInv = ( vtExtr:getZ() < -0.1) -- recupero la lavorazione - local sPocketing = ML.FindPocketing( 'Pocket', nil, dDepth) + local sPocketing = WM.FindPocketing( 'Pocket', nil, dDepth) if not sPocketing then local sErr = 'Error : pocketing not found in library' EgtOutLog( sErr) diff --git a/LuaLibs/WallExec.lua b/LuaLibs/WallExec.lua index 8c72d03..9151b4d 100644 --- a/LuaLibs/WallExec.lua +++ b/LuaLibs/WallExec.lua @@ -12,12 +12,14 @@ _G.package.loaded.WallData = nil local WD = require( 'WallData') -- Carico le librerie -_G.package.loaded.MachiningLib = nil -local BM = require( 'MachiningLib') -_G.package.loaded.ProcessDrill = nil -local Drill = require( 'ProcessDrill') -_G.package.loaded.ProcessFreeContour = nil -local FreeContour = require( 'ProcessFreeContour') +_G.package.loaded.WMachiningLib = nil +local WM = require( 'WMachiningLib') +_G.package.loaded.WallLib = nil +local WL = require( 'WallLib') +_G.package.loaded.WProcessDrill = nil +local Drill = require( 'WProcessDrill') +_G.package.loaded.WProcessFreeContour = nil +local FreeContour = require( 'WProcessFreeContour') ------------------------------------------------------------------------------------------------------------- -- *** Inserimento delle pareti nel pannello *** @@ -53,6 +55,11 @@ function WallExec.ProcessWalls( dRawL, dRawW, dRawH, vWall) local PartLen = b3Solid:getDimX() local PartWidth = b3Solid:getDimY() local PartHeight = b3Solid:getDimZ() + -- creo o pulisco gruppo geometrie aggiuntive + if not WL.CreateOrEmptyAddGroup( Pz) then + local sOut = 'Error creating Additional Group in Part ' .. tostring( Pz) + return false, sOut + end -- inserisco il pezzo nel grezzo EgtDeselectPartObjs( Pz) local ptPos = Point3d( dRawL - vWall[i].PosX - PartLen, vWall[i].PosZ, ( dRawH - PartHeight) / 2) diff --git a/LuaLibs/WallLib.lua b/LuaLibs/WallLib.lua index 6b6e49e..7d8cc35 100644 --- a/LuaLibs/WallLib.lua +++ b/LuaLibs/WallLib.lua @@ -9,6 +9,36 @@ require( 'EgtBase') EgtOutLog( ' WallLib started', 1) +------------------------------------------------------------------------------------------------------------- +function WallLib.GetAddGroup( PartId) + -- recupero il nome del gruppo di lavoro corrente + local sMchGrp = EgtGetMachGroupName( EgtGetCurrMachGroup() or GDB_ID.NULL) + if not sMchGrp then return nil, nil end + -- cerco il gruppo aggiuntivo omonimo nel pezzo e se esiste lo restituisco + local AddGrpId = EgtGetFirstNameInGroup( PartId or GDB_ID.NULL, sMchGrp) + -- restituisco Id e Nome + return AddGrpId, sMchGrp +end + +------------------------------------------------------------------------------------------------------------- +function WallLib.CreateOrEmptyAddGroup( PartId) + -- recupero i dati del gruppo aggiuntivo + local AddGrpId, sMchGrp = WallLib.GetAddGroup( PartId) + if not sMchGrp then return false end + -- se esiste lo svuoto + if AddGrpId then + return EgtEmptyGroup( AddGrpId) + end + -- altrimenti lo creo + AddGrpId = EgtGroup( PartId or GDB_ID.NULL) + if not AddGrpId then return false end + -- assegno nome, flag di layer per gruppo di lavoro e colore + EgtSetName( AddGrpId, sMchGrp) + EgtSetInfo( AddGrpId, GDB_SI.MGRPONLY, EgtGetCurrMachGroup()) + EgtSetColor( AddGrpId, Color3d( 80, 160, 160, 50)) + return true +end + --------------------------------------------------------------------- function WallLib.GetFaceHvRefDim( nSurfId, nFacet) -- recupero centro e normale della faccia diff --git a/Process.lua b/Process.lua index bb7432c..13d3d30 100644 --- a/Process.lua +++ b/Process.lua @@ -1,4 +1,4 @@ --- Process.lua by Egaltech s.r.l. 2020/04/25 +-- Process.lua by Egaltech s.r.l. 2020/04/29 -- Gestione calcolo disposizione e lavorazioni per Pareti -- Si opera sulla macchina corrente @@ -32,7 +32,7 @@ EgtOutLog( '*** Wall Process Start ***', 1) -- Carico le librerie _G.package.loaded.WallExec = nil local WE = require( 'WallExec') ---local BL = require( 'BeamLib') +local WL = require( 'WallLib') -- Carico i dati globali local WD = require( 'WallData') @@ -103,17 +103,25 @@ local function MyProcessInputData() for i = 1, #vWall do local b3Solid = vWall[i].Box -- rotazione - local dRotAng = EgtGetInfo( vWall[i].Id, 'ROTATED', 'd') or 0 - if dRotAng and abs( dRotAng) > GEO.EPS_ANG_SMALL then - local ptRotCen = b3Solid:getCenter() - EgtRotate( vWall[i].Id, ptRotCen, X_AX(), dRotAng, GDB_RT.GLOB) - b3Solid:rotate( ptRotCen, X_AX(), dRotAng) + local dRotAng = EgtGetInfo( vWall[i].Id, 'ROTATED', 'd') + if dRotAng then + if abs( dRotAng) > GEO.EPS_ANG_SMALL then + local ptRotCen = b3Solid:getCenter() + EgtRotate( vWall[i].Id, ptRotCen, X_AX(), dRotAng, GDB_RT.GLOB) + b3Solid:rotate( ptRotCen, X_AX(), dRotAng) + end + EgtSetInfo( vWall[i].Id, 'ROTATED_DONE', dRotAng) + EgtRemoveInfo( vWall[i].Id, 'ROTATED') end -- inversione - local dInvAng = 180 - ( EgtGetInfo( vWall[i].Id, 'INVERTED', 'd') or 180) - if abs( dInvAng) > GEO.EPS_ANG_SMALL then - local ptInvCen = b3Solid:getCenter() - EgtRotate( vWall[i].Id, ptInvCen, Z_AX(), dInvAng, GDB_RT.GLOB) + local dInvAng = EgtGetInfo( vWall[i].Id, 'INVERTED', 'd') + if dInvAng then + if abs( 180 - dInvAng) > GEO.EPS_ANG_SMALL then + local ptInvCen = b3Solid:getCenter() + EgtRotate( vWall[i].Id, ptInvCen, Z_AX(), 180 - dInvAng, GDB_RT.GLOB) + end + EgtSetInfo( vWall[i].Id, 'INVERTED_DONE', dInvAng) + EgtRemoveInfo( vWall[i].Id, 'INVERTED') end end