1459253e57
- modifiche e correzioni per Costolature (Setti -> Ribs).
189 lines
6.7 KiB
Lua
189 lines
6.7 KiB
Lua
-- RunPartPositioning.lua by Egaltech s.r.l. 2022/06/28
|
|
-- 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 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, ORIGINAL_SOLID)
|
|
end
|
|
-- Recupero o creo layer ausiliario
|
|
local nAuxId = EgtGetFirstNameInGroup( nPartId, LAY_AUX)
|
|
if not nAuxId then
|
|
nAuxId = EgtGroup( nPartId)
|
|
EgtSetName( nAuxId, LAY_AUX)
|
|
end
|
|
|
|
-- Rimuovo eventuale gruppo di lavoro
|
|
local nMchGrpId = EgtGetMachGroupId( '3dPrint')
|
|
EgtRemoveMachGroup( nMchGrpId or GDB_ID.NULL)
|
|
-- Rimuovo eventuale frame
|
|
local nFrameId = EgtGetFirstNameInGroup( nAuxId, FRAME_PART)
|
|
if nFrameId then EgtErase( nFrameId) end
|
|
-- Rimuovo eventuale start point
|
|
local nPtStartId = EgtGetFirstNameInGroup( nAuxId, KEY_START_POINT)
|
|
if nPtStartId then EgtErase( nPtStartId) end
|
|
|
|
-- 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)
|
|
if not nTabPart then
|
|
-- 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)
|
|
end
|
|
|
|
-- 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
|
|
local frPart = Frame3d( ptOrig, Z_AX())
|
|
nFrameId = EgtFrame( nAuxId, 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()
|
|
|
|
-- Creo lo start point
|
|
local ptStart = b3Solid:getCenter() - 0.6 * b3Solid:getDimY() * Y_AX() - 0.5 * b3Solid:getDimZ() * Z_AX()
|
|
nPtStartId = EgtPoint( nAuxId, ptStart, GDB_RT.GLOB)
|
|
if nPtStartId then
|
|
EgtSetName( nPtStartId, START_POINT)
|
|
EgtSetColor( nPtStartId, EgtStdColor( "RED"))
|
|
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
|