3dPrinting :

- riorganizzazione
- correzioni nel collegamento e nel riordino dei setti.
This commit is contained in:
SaraP
2022-06-29 11:34:46 +02:00
parent b9f1922969
commit 37dd22aa3e
13 changed files with 487 additions and 399 deletions
+81 -37
View File
@@ -1,4 +1,4 @@
-- RunPartPositioning.lua by Egaltech s.r.l. 2022/05/28
-- RunPartPositioning.lua by Egaltech s.r.l. 2022/06/28
-- Gestione calcolo disposizione e lavorazioni per stampa 3d
-- 2022/03/21 Creazione file
@@ -22,20 +22,22 @@ function RunPartPositioning.Exec()
return
end
-- Recupero ultimo oggetto selezionato
local nPartId = EgtGetParent(EgtGetParent( EgtGetLastSelectedObj()))
-- verifico sia un pezzo valido
local nSolidId = EgtGetLastSelectedObj()
local nLayerId = EgtGetParent( nSolidId)
local nPartId = EgtGetParent( nLayerId)
-- Verifico sia in un pezzo valido
if nPartId then
local nParentId = EgtGetParent( nPartId)
while nParentId ~= GDB_ID.ROOT do
nPartId = nParentId
nParentId = EgtGetParent( nPartId)
end
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_WALLS 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
@@ -45,25 +47,30 @@ function RunPartPositioning.Exec()
return
end
-- gli assegno nome pezzo e layer
-- 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)
local nLayerId = EgtGetFirstInGroup( nPartId)
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( nPartId, FRAME_PART)
local nFrameId = EgtGetFirstNameInGroup( nAuxId, FRAME_PART)
if nFrameId then EgtErase( nFrameId) end
-- rimuovo eventuale start point
local nPtStartId = EgtGetFirstNameInGroup( nPartId, KEY_START_POINT)
-- 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)
@@ -74,14 +81,34 @@ function RunPartPositioning.Exec()
dTabY = b3Tab:getDimY()
EgtRemoveMachGroup( nQqqId or GDB_ID.NULL)
-- Richiedo coordinata posizionamento pezzo
local b3Part = EgtGetBBoxGlob( nPartId, GDB_BB.EXACT)
local dPosX = b3Tab:getDimX() / 2
local dPosY = b3Tab:getDimY() / 2
local Positions = EgtDialogBox( 'Part position on table:', { 'X', EgtNumToString( EgtToUiUnits(dPosX), 1)}, { 'Y', EgtNumToString( EgtToUiUnits(dPosY), 1)})
if not Positions then return end
dPosX = EgtFromUiUnits( tonumber( Positions[1])) - b3Part:getDimX() / 2
dPosY = EgtFromUiUnits( tonumber( Positions[2])) - b3Part:getDimY() / 2
-- 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)
@@ -89,6 +116,7 @@ function RunPartPositioning.Exec()
-- 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)
@@ -100,41 +128,57 @@ function RunPartPositioning.Exec()
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) - b3Part:getMin()
local vtMove = Point3d( dPosX, dPosY, 0) - b3Solid:getMin()
EgtMove( nPartId, vtMove)
b3Solid:move( vtMove)
b3Part:move( vtMove)
-- Posiziono eventuali setti
local nSettiPart = EgtGetFirstNameInGroup( GDB_ID.ROOT, SETTI_GRP)
if nSettiPart then
EgtMove( nSettiPart, 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
-- Creo il frame del pezzo
local frPart = Frame3d( b3Part:getCenter() - 0.5 * b3Part:getDimZ() * Z_AX(), Z_AX())
nFrameId = EgtFrame( nPartId, frPart, GDB_RT.GLOB)
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, GDB_ID.NULL, 0, Color3d( 128, 128, 128, 30))
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 = b3Part:getCenter() - 0.6 * b3Part:getDimY() * Y_AX() - 0.5 * b3Part:getDimZ() * Z_AX()
nPtStartId = EgtPoint( nPartId, ptStart, GDB_RT.GLOB)
-- 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, KEY_START_POINT)
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)