Files
3dprinting/LuaLibs/RunPartPositioning.lua
T
DarioS 56b05c0eeb 3dPrinting :
- correzioni per aggiustamento posizione solido con 45 gradi
- piccola modifica posizionamento pezzo su tavola macchina.
2022-08-29 09:35:11 +02:00

210 lines
7.4 KiB
Lua

-- RunPartPositioning.lua by Egaltech s.r.l. 2022/08/29
-- Gestione calcolo disposizione e lavorazioni per stampa 3d
-- 2022/03/21 Creazione file
-- Tabella per definizione modulo
local RunPartPositioning = {}
-- Intestazioni
require( 'EgtBase')
EgtOutLog( ' RunPartPositioning started', 1)
-- Costanti generali
local AMD = require( 'AddManData')
---------------------------------------------------------------------
function RunPartPositioning.Exec()
-- Verifico che la macchina corrente sia adatta alla stampa 3d
local sMachIni = EgtGetCurrMachineDir() .. '\\' .. EgtGetCurrMachineName() .. '.ini'
local sMachMaterial = EgtGetStringFromIni( 'General', 'Material', '', sMachIni)
if sMachMaterial ~= 'Additive' then
EgtOutBox( 'Current machine unsuitable for additive manufacturing', 'Warning', 'WARNING')
return
end
-- Recupero ultimo oggetto selezionato
local nSolidId = EgtGetLastSelectedObj()
local nLayerId = EgtGetParent( nSolidId)
local nPartId = EgtGetParent( nLayerId)
-- Verifico sia in un pezzo valido
if nPartId then
if EgtIsPart( nPartId) then
local sName = EgtGetName( nPartId)
if sName == TABLE then
EgtOutBox( 'No selected part. Please select a part before moving it on the table.', 'Warning', 'WARNING')
return
end
local sLayer = EgtGetName( nLayerId)
if sLayer == LAY_RIBS or sLayer == LAY_AUX_SOLIDS or sLayer == LAY_SHELL_NBR then
EgtOutBox( 'No selected solid. Please select a solid before moving it on the table.', 'Warning', 'WARNING')
return
end
else
EgtOutBox( 'No selected part. Please select a part before moving it on the table.', 'Warning', 'WARNING')
return
end
else
EgtOutBox( 'No selected part. Please select a part before moving it on the table.', 'Warning', 'WARNING')
return
end
-- Assegno nome pezzo e layer
if not EgtGetName( nPartId) then
local nPartIndex = 1
while EgtGetFirstNameInGroup( GDB_ID.ROOT, PART .. nPartIndex) do
nPartIndex = nPartIndex + 1
end
EgtSetName( nPartId, PART .. nPartIndex)
EgtSetName( nLayerId, PRINT_SOLID)
end
-- Recupero o creo layer ausiliario
local nAuxId = EgtGetFirstNameInGroup( nPartId, LAY_AUX)
if not nAuxId then
nAuxId = EgtGroup( nPartId)
EgtSetName( nAuxId, LAY_AUX)
else
EgtEmptyGroup( nAuxId)
end
-- Rimuovo eventuale gruppo di lavoro
local nMchGrpId = EgtGetMachGroupId( '3dPrint')
EgtRemoveMachGroup( nMchGrpId or GDB_ID.NULL)
-- Recupero dati tavola (creando gruppo di lavoro temporaneo)
local nQqqId = EgtAddMachGroup( 'qqq')
EgtSetTable( 'Tab')
local b3Tab = EgtGetTableArea()
dTabX = b3Tab:getDimX()
dTabY = b3Tab:getDimY()
EgtRemoveMachGroup( nQqqId or GDB_ID.NULL)
-- Richiedo posizione origine e offset pezzo
local b3Solid = EgtGetBBoxGlob( nSolidId, GDB_BB.EXACT)
local b3Part = EgtGetBBoxGlob( nPartId, GDB_BB.EXACT)
local nRefX = 1
local nRefY = 1
local dPosX = b3Tab:getDimX() / 2 - b3Solid:getDimX() / 2
local dPosY = b3Tab:getDimY() / 2 - b3Solid:getDimY() / 2
local Positions = EgtDialogBox( 'Part position on table:', { 'Reference', 'CB:Left,Center,Right'},
{ '', 'CB:Bottom,Middle,Top'},
{ 'X', EgtNumToString( EgtToUiUnits( dPosX), 1)},
{ 'Y', EgtNumToString( EgtToUiUnits( dPosY), 1)})
if not Positions then return end
dPosX = EgtFromUiUnits( tonumber( Positions[3]))
dPosY = EgtFromUiUnits( tonumber( Positions[4]))
if Positions[1] == 'Center' then
nRefX = 2
dPosX = dPosX - b3Solid:getDimX() / 2
elseif Positions[1] == 'Right' then
nRefX = 3
dPosX = dPosX - b3Solid:getDimX()
end
if Positions[2] == 'Middle' then
nRefY = 2
dPosY = dPosY - b3Solid:getDimY() / 2
elseif Positions[2] == 'Top' then
nRefY = 3
dPosY = dPosY - b3Solid:getDimY()
end
-- Creo disegno tavola
local nTabPart = EgtGetFirstNameInGroup( GDB_ID.ROOT, TABLE)
EgtErase( nTabPart)
-- Disegno tavola
nTabPart = EgtGroup( GDB_ID.ROOT)
EgtSetMode( nTabPart, GDB_MD.LOCKED)
EgtSetLevel( nTabPart, GDB_LV.SYSTEM)
EgtSetName( nTabPart, TABLE)
local nTabLayer = EgtGroup( nTabPart)
EgtSetName( nTabLayer, TABLE)
local nTabOutlineId = EgtRectangle2P( nTabLayer, Point3d( 0, 0, 0), Point3d( dTabX, dTabY, 0))
local nTabSurfId = EgtSurfFlatRegion( nTabLayer, nTabOutlineId)
EgtSetColor( nTabSurfId, 'GRAY')
EgtSetAlpha( nTabSurfId, 70)
-- Aggiungo il box del solido
local nBoxId = EgtSurfTmBBox( nAuxId, b3Solid, false, GDB_RT.GLOB)
-- Posiziono il pezzo e aggiorno il suo box
local vtMove = Point3d( dPosX, dPosY, 0) - b3Solid:getMin()
EgtMove( nPartId, vtMove)
b3Solid:move( vtMove)
b3Part:move( vtMove)
-- Creo il frame del pezzo
local ptOrig = b3Solid:getMin()
if nRefX == 2 then
ptOrig = ptOrig + b3Solid:getDimX() / 2 * X_AX()
elseif nRefX == 3 then
ptOrig = ptOrig + b3Solid:getDimX() * X_AX()
end
if nRefY == 2 then
ptOrig = ptOrig + b3Solid:getDimY() / 2 * Y_AX()
elseif nRefY == 3 then
ptOrig = ptOrig + b3Solid:getDimY() * Y_AX()
end
-- Svuoto o creo layer per il frame
local nFrameLay = EgtGetFirstNameInGroup( nPartId, LAY_FRAME)
if not nFrameLay then
nFrameLay = EgtGroup( nPartId)
EgtSetName( nFrameLay, LAY_FRAME)
else
EgtEmptyGroup( nFrameLay)
end
local frPart = Frame3d( ptOrig, Z_AX())
nFrameId = EgtFrame( nFrameLay, frPart, GDB_RT.GLOB)
if nFrameId then
EgtSetName( nFrameId, FRAME_PART)
EgtSetMode( nFrameId, GDB_MD.LOCKED)
end
-- Definisco e posiziono il grezzo sulla tavola
EgtAddMachGroup( '3dPrint')
EgtSetTable( 'Tab')
local nRawId = EgtAddRawPartWithPart( nPartId, nBoxId, 0, Color3d( 128, 128, 128, 30))
EgtMoveToCornerRawPart( nRawId, Point3d( dPosX, dPosY, 0), MCH_CR.BL)
EgtResetCurrMachGroup()
-- Recupero/creo gruppo per punti e curve di partenza
local nMachStartId = EgtGetFirstNameInGroup( nPartId, LAY_MACH_START)
if not nMachStartId then
nMachStartId = EgtGroup( nPartId)
EgtSetName( nMachStartId, LAY_MACH_START)
end
local vStartId = EgtGetNameInGroup( nLayerId, START_GEOM)
if vStartId then
for j = 1, #vStartId do
EgtRelocateGlob( vStartId[j], nMachStartId)
EgtSetColor( vStartId[j], EgtStdColor( "RED"))
end
else
-- se non ci sono punti/curve di inizio definiti e non ve ne sono nemmeno nel gruppo, creo un punto
local vOldStart = EgtGetNameInGroup( nMachStartId, START_GEOM)
if not vOldStart then
local ptStart = b3Solid:getCenter() - 0.6 * b3Solid:getDimY() * Y_AX() - 0.5 * b3Solid:getDimZ() * Z_AX()
nPtStartId = EgtPoint( nMachStartId, ptStart, GDB_RT.GLOB)
EgtSetName( nPtStartId, START_GEOM)
EgtSetColor( nPtStartId, EgtStdColor( "RED"))
end
end
-- Dichiaro pezzo posizionato
EgtSetInfo( nPartId, KEY_PART_ON_TABLE, 1)
-- Deseleziono tutto
EgtDeselectAll()
EgtSetView( SCE_VD.ISO_SW, false)
EgtZoom( SCE_ZM.ALL)
EgtOutLog( ' +++ RunPartPositioning completed')
end
---------------------------------------------------------------------
return RunPartPositioning