From 6e7c4ffda182c0083a9a2d1030bb3a14531fd004 Mon Sep 17 00:00:00 2001 From: "luca.mazzoleni" Date: Wed, 16 Oct 2024 16:59:17 +0200 Subject: [PATCH] - modifiche parziali a squadratura per contemplare casi in doppio --- LuaLibs/Squaring.lua | 196 ++++++++++++++++++++++++++++++++++++++ LuaLibs/WallExec.lua | 218 +++++++++---------------------------------- 2 files changed, 238 insertions(+), 176 deletions(-) create mode 100644 LuaLibs/Squaring.lua diff --git a/LuaLibs/Squaring.lua b/LuaLibs/Squaring.lua new file mode 100644 index 0000000..c31063d --- /dev/null +++ b/LuaLibs/Squaring.lua @@ -0,0 +1,196 @@ +-- Squaring.lua by Egaltech s.r.l. 2024/10/15 +-- Libreria squadratura pareti + +-- Tabella per definizione modulo +local Squaring = {} + +-- Include +require( 'EgtBase') + +EgtOutLog( ' Squaring started', 1) + +-- Dati +local WD = require( 'WallData') + +------------------------------------------------------------------------------------------------------------- +function Squaring.GetMachining( dDepth) + local Machining = {} + local nSquaringToolType = 0 + if WD.SQUARING_EXTEND_Z and type( WD.SQUARING_EXTEND_Z) == "number" then + dDepth = dDepth + WD.SQUARING_EXTEND_Z + end + + -- ricerca lavorazione di squadratura in base alle preferenze utente + if WD.SQUARING_TOOL and type( WD.SQUARING_TOOL) == "number" then + nSquaringToolType = WD.SQUARING_TOOL + end + -- lama + if nSquaringToolType == 0 or nSquaringToolType == 1 then + Machining.sSquaring = WM.FindCutting( 'Squaring', dDepth) + if Machining.sSquaring then + Machining.sType = 'Sawing' + end + end + -- fresa + if not Machining.sSquaring and ( nSquaringToolType == 0 or nSquaringToolType == 2) then + Machining.sSquaring = WM.FindMilling( 'Squaring', dDepth, nil, nil, nil, nil, true) + if Machining.sSquaring then + Machining.sType = 'Milling' + end + end + -- truciolatore + if not Machining.sSquaring and ( nSquaringToolType == 0 or nSquaringToolType == 3) then + Machining.sSquaring = WM.FindMilling( 'Squaring', nil, nil, nil, nil, nil, nil, dDepth) + if Machining.sSquaring then + Machining.sType = 'DiskMilling' + end + end + + -- recupero informazioni utensile + local bIsToolCCW + if Machining.sSquaring and EgtMdbSetCurrMachining( Machining.sSquaring) then + local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) + if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then + local dSpeed = ( EgtTdbGetCurrToolParam( MCH_TP.SPEED)) + bIsToolCCW = dSpeed < 0 + end + end + Machining.bIsPathCW = ( not( bIsToolCCW) and Machining.sType == 'Milling') or ( bIsToolCCW and Machining.sType ~= 'Milling') + + return Machining +end + +------------------------------------------------------------------------------------------------------------- +function Squaring.CreateGeometry( RawPart, Machining) + -- TODO gestire squadratura sulle dimensioni massime dei pezzi (shrinktoparts) invece che sul master panel + local SquaringGeometries = {} + local dDimX = RawPart.b3:getDimX() + local dDimY = RawPart.b3:getDimY() + local sOrigCorner = EgtGetInfo( RawPart.nId, 'ORIGCORNER') + local bShrinkToParts = ( WD.SQUARING_TYPE == 2) + local bSquaringStartsOnReference = type( WD.SQUARING_STARTS_ON_REFERENCE) == "boolean" and ( WD.SQUARING_STARTS_ON_REFERENCE == true) + local dOffsetXY = 0 + local dExtendZ = 0 + if type( WD.SQUARING_OFFSET_XY) == "number" then + dOffsetXY = WD.SQUARING_OFFSET_XY + end + if type( WD.SQUARING_EXTEND_Z) == "number" then + dExtendZ = WD.SQUARING_EXTEND_Z + end + + local pt1 = RawPart.b3:getMin() + Point3d( -dOffsetXY, -dOffsetXY, -dExtendZ) + local pt2 = pt1 + Point3d( dDimX + 2 * dOffsetXY, 0, 0) + local pt3 = pt2 + Point3d( 0, dDimY + 2 * dOffsetXY,0 ) + local pt4 = pt3 + Point3d( -dDimX - 2 * dOffsetXY, 0, 0) + local nFrontLineId = EgtLine( RawPart.nId, pt1, pt2, GDB_RT.GLOB) + local nRightLineId = EgtLine( RawPart.nId, pt2, pt3, GDB_RT.GLOB) + local nBackLinedId = EgtLine( RawPart.nId, pt3, pt4, GDB_RT.GLOB) + local nLeftLineId = EgtLine( RawPart.nId, pt4, pt1, GDB_RT.GLOB) + if Machining.sType == 'DiskMilling' or Machining.sType == 'Milling' then + EgtModifyCurveExtrusion( nFrontLineId, -Y_AX(), GDB_RT.GLOB) + EgtModifyCurveExtrusion( nRightLineId, X_AX(), GDB_RT.GLOB) + EgtModifyCurveExtrusion( nBackLinedId, Y_AX(), GDB_RT.GLOB) + EgtModifyCurveExtrusion( nLeftLineId, -X_AX(), GDB_RT.GLOB) + end + EgtSetName( nFrontLineId, 'SquaringGeometry' ) + EgtSetName( nRightLineId, 'SquaringGeometry' ) + EgtSetName( nBackLinedId, 'SquaringGeometry' ) + EgtSetName( nLeftLineId, 'SquaringGeometry' ) + + for i = 1, 4 do + SquaringGeometries[i] = {} + end + -- l'ordine di percorrenza delle linee dipende dal verso di percorrenza e, se attivato, dal riferimento utilizzato + if Machining.bIsPathCW then + if bSquaringStartsOnReference and ( sOrigCorner == 'BL' or sOrigCorner == 'BM') then + SquaringGeometries[1].nId = nFrontLineId + SquaringGeometries[2].nId = nLeftLineId + SquaringGeometries[3].nId = nBackLinedId + SquaringGeometries[4].nId = nRightLineId + elseif bSquaringStartsOnReference and ( sOrigCorner == 'TR' or sOrigCorner == 'TN') then + SquaringGeometries[1].nId = nBackLinedId + SquaringGeometries[2].nId = nRightLineId + SquaringGeometries[3].nId = nFrontLineId + SquaringGeometries[4].nId = nLeftLineId + elseif bSquaringStartsOnReference and ( sOrigCorner == 'BR' or sOrigCorner == 'BN') then + SquaringGeometries[1].nId = nRightLineId + SquaringGeometries[2].nId = nFrontLineId + SquaringGeometries[3].nId = nLeftLineId + SquaringGeometries[4].nId = nBackLinedId + else + SquaringGeometries[1].nId = nLeftLineId + SquaringGeometries[2].nId = nBackLinedId + SquaringGeometries[3].nId = nRightLineId + SquaringGeometries[4].nId = nFrontLineId + end + else + if bSquaringStartsOnReference and ( sOrigCorner == 'TL' or sOrigCorner == 'TM') then + SquaringGeometries[1].nId = nBackLinedId + SquaringGeometries[2].nId = nLeftLineId + SquaringGeometries[3].nId = nFrontLineId + SquaringGeometries[4].nId = nRightLineId + elseif bSquaringStartsOnReference and ( sOrigCorner == 'TR' or sOrigCorner == 'TN') then + SquaringGeometries[1].nId = nRightLineId + SquaringGeometries[2].nId = nBackLinedId + SquaringGeometries[3].nId = nLeftLineId + SquaringGeometries[4].nId = nFrontLineId + elseif bSquaringStartsOnReference and ( sOrigCorner == 'BR' or sOrigCorner == 'BN') then + SquaringGeometries[1].nId = nFrontLineId + SquaringGeometries[2].nId = nRightLineId + SquaringGeometries[3].nId = nBackLinedId + SquaringGeometries[4].nId = nLeftLineId + else + SquaringGeometries[1].nId = nLeftLineId + SquaringGeometries[2].nId = nFrontLineId + SquaringGeometries[3].nId = nRightLineId + SquaringGeometries[4].nId = nBackLinedId + end + end + + return SquaringGeometries +end + +------------------------------------------------------------------------------------------------------------- +function Squaring.AddMachinings( Machining, SquaringGeometries, nFirstOperationId) + local nNotOkCount = 0 + local sMsgTotal = '' + + for i = 1, #SquaringGeometries do + local nSquaringOperationId = EgtAddMachining('SQUARING', Machining.sSquaring) + EgtSetMachiningGeometry( SquaringGeometries[i].nId) + -- in base al verso di percorrenza modifico i parametri significativi di lavorazione + if Machining.bIsPathCW then + if Machining.sType == 'Sawing'then + EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_SAW_WS.LEFT) + EgtSetMachiningParam( MCH_MP.HEADSIDE, MCH_SAW_HS.LEFT) + elseif Machining.sType == 'Milling' then + EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) + elseif Machining.sType == 'DiskMilling' then + EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.RIGHT) + end + EgtSetMachiningParam( MCH_MP.INVERT, true) + else + if Machining.sType == 'Sawing' then + EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_SAW_WS.RIGHT) + EgtSetMachiningParam( MCH_MP.HEADSIDE, MCH_SAW_HS.RIGHT) + elseif Machining.sType == 'Milling' then + EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.RIGHT) + elseif Machining.sType == 'DiskMilling' then + EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) + end + EgtSetMachiningParam( MCH_MP.INVERT, false) + end + local bOk = EgtApplyMachining( true, false) + EgtRelocateGlob( nSquaringOperationId, nFirstOperationId, GDB_IN.BEFORE) + if not bOk then + local _, sMsg = EgtGetLastMachMgrError() + nNotOkCount = nNotOkCount + 1 + sMsgTotal = sMsgTotal ..'\n' .. ( sMsg or '') + end + end + + return ( nNotOkCount < 1), sMsgTotal +end + +------------------------------------------------------------------------------------------------------------- +return Squaring \ No newline at end of file diff --git a/LuaLibs/WallExec.lua b/LuaLibs/WallExec.lua index d1976e4..0352166 100644 --- a/LuaLibs/WallExec.lua +++ b/LuaLibs/WallExec.lua @@ -45,6 +45,7 @@ _G.package.loaded.WProcessVariant = nil local WM = require( 'WMachiningLib') local WL = require( 'WallLib') local Topology = require( 'WFeatureTopology') +local Squaring = require( 'Squaring') local Cut = require( 'WProcessCut') local DoubleCut = require( 'WProcessDoubleCut') local SawCut = require( 'WProcessSawCut') @@ -57,8 +58,6 @@ local Text = require( 'WProcessText') local FreeContour = require( 'WProcessFreeContour') local Variant = require( 'WProcessVariant') -local Squaring = {} - ------------------------------------------------------------------------------------------------------------- -- *** Inserimento delle pareti nel pannello *** ------------------------------------------------------------------------------------------------------------- @@ -1080,183 +1079,10 @@ local function SetMirroredOperations() end ------------------------------------------------------------------------------------------------------------- -function Squaring.GetMachining( dDepth) - local Machining = {} - local nSquaringToolType = 0 - if WD.SQUARING_EXTEND_Z and type( WD.SQUARING_EXTEND_Z) == "number" then - dDepth = dDepth + WD.SQUARING_EXTEND_Z - end +local function AddSquaring( sSquaringTool, RawPart, nFirstOperationId) - -- ricerca lavorazione di squadratura in base alle preferenze utente - if WD.SQUARING_TOOL and type( WD.SQUARING_TOOL) == "number" then - nSquaringToolType = WD.SQUARING_TOOL - end - -- lama - if nSquaringToolType == 0 or nSquaringToolType == 1 then - Machining.sSquaring = WM.FindCutting( 'Squaring', dDepth) - if Machining.sSquaring then - Machining.sType = 'Sawing' - end - end - -- fresa - if not Machining.sSquaring and ( nSquaringToolType == 0 or nSquaringToolType == 2) then - Machining.sSquaring = WM.FindMilling( 'Squaring', dDepth, nil, nil, nil, nil, true) - if Machining.sSquaring then - Machining.sType = 'Milling' - end - end - -- truciolatore - if not Machining.sSquaring and ( nSquaringToolType == 0 or nSquaringToolType == 3) then - Machining.sSquaring = WM.FindMilling( 'Squaring', nil, nil, nil, nil, nil, nil, dDepth) - if Machining.sSquaring then - Machining.sType = 'DiskMilling' - end - end - -- recupero informazioni utensile - local bIsToolCCW - if Machining.sSquaring and EgtMdbSetCurrMachining( Machining.sSquaring) then - local sTuuid = EgtMdbGetCurrMachiningParam( MCH_MP.TUUID) - if EgtTdbSetCurrTool( EgtTdbGetToolFromUUID( sTuuid) or '') then - local dSpeed = ( EgtTdbGetCurrToolParam( MCH_TP.SPEED)) - bIsToolCCW = dSpeed < 0 - end - end - Machining.bIsPathCW = ( not( bIsToolCCW) and Machining.sType == 'Milling') or ( bIsToolCCW and Machining.sType ~= 'Milling') - return Machining -end - -------------------------------------------------------------------------------------------------------------- -function Squaring.CreateGeometry( RawPart, Machining) - -- TODO gestire squadratura sulle dimensioni massime dei pezzi (shrinktoparts) invece che sul master panel - local SquaringGeometries = {} - local dDimX = RawPart.b3:getDimX() - local dDimY = RawPart.b3:getDimY() - local sOrigCorner = EgtGetInfo( RawPart.nId, 'ORIGCORNER') - local bShrinkToParts = ( WD.SQUARING_TYPE == 2) - local bSquaringStartsOnReference = type( WD.SQUARING_STARTS_ON_REFERENCE) == "boolean" and ( WD.SQUARING_STARTS_ON_REFERENCE == true) - local dOffsetXY = 0 - local dExtendZ = 0 - if type( WD.SQUARING_OFFSET_XY) == "number" then - dOffsetXY = WD.SQUARING_OFFSET_XY - end - if type( WD.SQUARING_EXTEND_Z) == "number" then - dExtendZ = WD.SQUARING_EXTEND_Z - end - - local pt1 = RawPart.b3:getMin() + Point3d( -dOffsetXY, -dOffsetXY, -dExtendZ) - local pt2 = pt1 + Point3d( dDimX + 2 * dOffsetXY, 0, 0) - local pt3 = pt2 + Point3d( 0, dDimY + 2 * dOffsetXY,0 ) - local pt4 = pt3 + Point3d( -dDimX - 2 * dOffsetXY, 0, 0) - local nFrontLineId = EgtLine( RawPart.nId, pt1, pt2, GDB_RT.GLOB) - local nRightLineId = EgtLine( RawPart.nId, pt2, pt3, GDB_RT.GLOB) - local nBackLinedId = EgtLine( RawPart.nId, pt3, pt4, GDB_RT.GLOB) - local nLeftLineId = EgtLine( RawPart.nId, pt4, pt1, GDB_RT.GLOB) - if Machining.sType == 'DiskMilling' then - EgtModifyCurveExtrusion( nFrontLineId, -Y_AX(), GDB_RT.GLOB) - EgtModifyCurveExtrusion( nRightLineId, X_AX(), GDB_RT.GLOB) - EgtModifyCurveExtrusion( nBackLinedId, Y_AX(), GDB_RT.GLOB) - EgtModifyCurveExtrusion( nLeftLineId, -X_AX(), GDB_RT.GLOB) - end - EgtSetName( nFrontLineId, 'SquaringGeometry' ) - EgtSetName( nRightLineId, 'SquaringGeometry' ) - EgtSetName( nBackLinedId, 'SquaringGeometry' ) - EgtSetName( nLeftLineId, 'SquaringGeometry' ) - - for i = 1, 4 do - SquaringGeometries[i] = {} - end - -- l'ordine di percorrenza delle linee dipende dal verso di percorrenza e, se attivato, dal riferimento utilizzato - if Machining.bIsPathCW then - if bSquaringStartsOnReference and ( sOrigCorner == 'BL' or sOrigCorner == 'BM') then - SquaringGeometries[1].nId = nFrontLineId - SquaringGeometries[2].nId = nLeftLineId - SquaringGeometries[3].nId = nBackLinedId - SquaringGeometries[4].nId = nRightLineId - elseif bSquaringStartsOnReference and ( sOrigCorner == 'TR' or sOrigCorner == 'TN') then - SquaringGeometries[1].nId = nBackLinedId - SquaringGeometries[2].nId = nRightLineId - SquaringGeometries[3].nId = nFrontLineId - SquaringGeometries[4].nId = nLeftLineId - elseif bSquaringStartsOnReference and ( sOrigCorner == 'BR' or sOrigCorner == 'BN') then - SquaringGeometries[1].nId = nRightLineId - SquaringGeometries[2].nId = nFrontLineId - SquaringGeometries[3].nId = nLeftLineId - SquaringGeometries[4].nId = nBackLinedId - else - SquaringGeometries[1].nId = nLeftLineId - SquaringGeometries[2].nId = nBackLinedId - SquaringGeometries[3].nId = nRightLineId - SquaringGeometries[4].nId = nFrontLineId - end - else - if bSquaringStartsOnReference and ( sOrigCorner == 'TL' or sOrigCorner == 'TM') then - SquaringGeometries[1].nId = nBackLinedId - SquaringGeometries[2].nId = nLeftLineId - SquaringGeometries[3].nId = nFrontLineId - SquaringGeometries[4].nId = nRightLineId - elseif bSquaringStartsOnReference and ( sOrigCorner == 'TR' or sOrigCorner == 'TN') then - SquaringGeometries[1].nId = nRightLineId - SquaringGeometries[2].nId = nBackLinedId - SquaringGeometries[3].nId = nLeftLineId - SquaringGeometries[4].nId = nFrontLineId - elseif bSquaringStartsOnReference and ( sOrigCorner == 'BR' or sOrigCorner == 'BN') then - SquaringGeometries[1].nId = nFrontLineId - SquaringGeometries[2].nId = nRightLineId - SquaringGeometries[3].nId = nBackLinedId - SquaringGeometries[4].nId = nLeftLineId - else - SquaringGeometries[1].nId = nLeftLineId - SquaringGeometries[2].nId = nFrontLineId - SquaringGeometries[3].nId = nRightLineId - SquaringGeometries[4].nId = nBackLinedId - end - end - - return SquaringGeometries -end - -------------------------------------------------------------------------------------------------------------- -function Squaring.AddMachinings( Machining, SquaringGeometries, nFirstOperationId) - local nNotOkCount = 0 - local sMsgTotal = '' - - for i = 1, #SquaringGeometries do - local nSquaringOperationId = EgtAddMachining('SQUARING', Machining.sSquaring) - EgtSetMachiningGeometry( SquaringGeometries[i].nId) - -- in base al verso di percorrenza modifico i parametri significativi di lavorazione - if Machining.bIsPathCW then - if Machining.sType == 'Sawing'then - EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_SAW_WS.LEFT) - EgtSetMachiningParam( MCH_MP.HEADSIDE, MCH_SAW_HS.LEFT) - elseif Machining.sType == 'Milling' then - EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) - elseif Machining.sType == 'DiskMilling' then - EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.RIGHT) - end - EgtSetMachiningParam( MCH_MP.INVERT, true) - else - if Machining.sType == 'Sawing' then - EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_SAW_WS.RIGHT) - EgtSetMachiningParam( MCH_MP.HEADSIDE, MCH_SAW_HS.RIGHT) - elseif Machining.sType == 'Milling' then - EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.RIGHT) - elseif Machining.sType == 'DiskMilling' then - EgtSetMachiningParam( MCH_MP.WORKSIDE, MCH_MILL_WS.LEFT) - end - EgtSetMachiningParam( MCH_MP.INVERT, false) - end - local bOk = EgtApplyMachining( true, false) - EgtRelocateGlob( nSquaringOperationId, nFirstOperationId, GDB_IN.BEFORE) - if not bOk then - local _, sMsg = EgtGetLastMachMgrError() - nNotOkCount = nNotOkCount + 1 - sMsgTotal = sMsgTotal ..'\n' .. ( sMsg or '') - end - end - - return ( nNotOkCount < 1), sMsgTotal end ------------------------------------------------------------------------------------------------------------- @@ -1410,6 +1236,46 @@ function WallExec.ProcessFeatures() -- squadratura, se richiesta if WD.SQUARING_TYPE and WD.SQUARING_TYPE > 0 then + local RawPart = { nId = nRawId, b3 = b3Raw} + local nFirstOperationId = EgtGetNextOperation( EgtGetPhaseDisposition( nPhase)) + local bOk, sMsg + + if WD.SQUARING_TOOL == 0 or WD.SQUARING_TOOL == 1 then + bOk, sMsg = AddSquaring( 'DoubleDiskmill', RawPart, nFirstOperationId) + end + if not bOk and ( WD.SQUARING_TOOL == 0 or WD.SQUARING_TOOL == 2) then + bOk, sMsg = AddSquaring( 'DoubleDiskmillAndBlade', RawPart, nFirstOperationId) + end + if not bOk and ( WD.SQUARING_TOOL == 0 or WD.SQUARING_TOOL == 3) then + bOk, sMsg = AddSquaring( 'DoubleBlade', RawPart, nFirstOperationId) + end + if not bOk and ( WD.SQUARING_TOOL == 0 or WD.SQUARING_TOOL == 4) then + bOk, sMsg = AddSquaring( 'Diskmill', RawPart, nFirstOperationId) + end + if not bOk and ( WD.SQUARING_TOOL == 0 or WD.SQUARING_TOOL == 5) then + bOk, sMsg = AddSquaring( 'Blade', RawPart, nFirstOperationId) + end + if not bOk and ( WD.SQUARING_TOOL == 0 or WD.SQUARING_TOOL == 6) then + bOk, sMsg = AddSquaring( 'DoubleMill', RawPart, nFirstOperationId) + end + if not bOk and ( WD.SQUARING_TOOL == 0 or WD.SQUARING_TOOL == 7) then + bOk, sMsg = AddSquaring( 'Mill', RawPart, nFirstOperationId) + end + + if not bOk then + nTotErr = nTotErr + 1 + table.insert( Stats, {Err=1, Msg=sMsg, Rot=0, CutId=0, TaskId=0}) + elseif sMsg and #sMsg > 0 then + table.insert( Stats, {Err=-1, Msg=sMsg, Rot=0, CutId=0, TaskId=0}) + else + table.insert( Stats, {Err=0, Msg='', Rot=0, CutId=0, TaskId=0}) + end + + + + + + local nFirstOperationId = EgtGetNextOperation( EgtGetPhaseDisposition( nPhase)) local dDepth = b3Raw:getDimZ()