Files
DataWall/LuaLibs/Squaring.lua
T

196 lines
8.3 KiB
Lua

-- 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