- Creazione WinExec (derivazione da progetto Beam)

- Funzione allineamento pezzo
- Funzione aggiunta sovramateriale pezzo
- Altre modifiche minori
This commit is contained in:
andrea.villa
2024-06-13 12:32:23 +02:00
parent 9d493812d9
commit 7d571bff39
3 changed files with 825 additions and 21 deletions
+81 -20
View File
@@ -60,6 +60,31 @@ local WinExec = require( 'WinExec')
-- Variabili globali
PARTS = {}
-- Colore del grezzo
local ColA = Color3d( 255, 165, 0, 30)
---------------------------------------------------------------------
-- Crea il grezzo che verrà messo in macchina
---------------------------------------------------------------------
local function AlignPieces( PARTS)
for i = 1, #PARTS do
-- TODO allinea X a globale, ma bisognerebbe tenere in considerazione l'orientamento pezzi che vuole la macchina
local dRotX, dRotY, dRotZ = GetFixedAxesRotABCFromFrame( PARTS[i].idFrame)
local ptOrigFrame = getOrigin( PARTS[i].idFrame)
if dRotX ~= 0 then
EgtRotate( PARTS[i].id, ptOrigFrame, X_AX(), dRotX)
end
if dRotY ~= 0 then
EgtRotate( PARTS[i].id, ptOrigFrame, Y_AX(), dRotY)
end
if dRotZ ~= 0 then
EgtRotate( PARTS[i].id, ptOrigFrame, Z_AX(), dRotZ)
end
end
end
-------------------------------------------------------------------------------------------------------------
-- *** Recupero i pezzi da processare ***
-------------------------------------------------------------------------------------------------------------
@@ -86,8 +111,17 @@ local function MyProcessInputData()
EgtOutBox( 'Non sono state selezionati pezzi', 'Lavora Pezzi', 'ERROR')
return false
else
-- allineo i pezzi per come se li aspetta la macchina
AlignPieces()
-- recupero tutte le dimensioni necessarie
local sOut = ''
for i = 1, #PARTS do
PARTS[i].idSolid = EgtGetFirstNameInGroup( PARTS[i].id, 'Solid')
PARTS[i].idFrame = EgtGetFirstNameInGroup( EgtGetFirstNameInGroup( PARTS[i].id, 'Geo'), 'Frame')
PARTS[i].b3Solid = EgtGetBBoxGlob( PARTS[i].idSolid or GDB_ID.NULL, GDB_BB.STANDARD)
PARTS[i].dLength = PARTS[1].b3Solid:getDimX()
PARTS[i].dWidth = PARTS[1].b3Solid:getDimY()
PARTS[i].dHeight = PARTS[1].b3Solid:getDimZ()
sOut = sOut .. PARTS[i].sName .. ', '
end
sOut = sOut:sub( 1, -3)
@@ -115,10 +149,12 @@ local function GetDispOffsetFromNotes( nPieceIndex)
DispOffset.Phase1 = {}
DispOffset.Phase2 = {}
DispOffset.Phase1.dOffsetY = EgtGetInfo( PIECES[nPieceIndex].id, 'OFFY_1', 'd')
DispOffset.Phase1.dOffsetZ = EgtGetInfo( PIECES[nPieceIndex].id, 'OFFZ_1', 'd')
DispOffset.Phase2.dOffsetY = EgtGetInfo( PIECES[nPieceIndex].id, 'OFFY_2', 'd')
DispOffset.Phase2.dOffsetZ = EgtGetInfo( PIECES[nPieceIndex].id, 'OFFZ_2', 'd')
DispOffset.Phase1.dOffsetX = 0 -- dovrà essere calcolato in base alle lavorazioni
DispOffset.Phase1.dOffsetY = EgtGetInfo( PARTS[nPieceIndex].id, 'OFFY_1', 'd')
DispOffset.Phase1.dOffsetZ = EgtGetInfo( PARTS[nPieceIndex].id, 'OFFZ_1', 'd')
DispOffset.Phase2.dOffsetX = 0 -- dovrà essere calcolato in base alle lavorazioni
DispOffset.Phase2.dOffsetY = EgtGetInfo( PARTS[nPieceIndex].id, 'OFFY_2', 'd')
DispOffset.Phase2.dOffsetZ = EgtGetInfo( PARTS[nPieceIndex].id, 'OFFZ_2', 'd')
-- controllo se tutti gli offset sono settati
if DispOffset.Phase1.dOffsetY and DispOffset.Phase1.dOffsetZ and DispOffset.Phase2.dOffsetY and DispOffset.Phase2.dOffsetZ then
@@ -131,13 +167,13 @@ end
-------------------------------------------------------------------------------------------------------------
local function GetDispOffsetFromInput( nPieceIndex)
-- assegno alle stringhe i valori letti, in modo che vengano proposti quelli nel dialogo
local sOffYPh1 = EgtIf( PIECES[nPieceIndex].DispOffset.Phase1.dOffsetY, tostring( PIECES[nPieceIndex].DispOffset.Phase1.dOffsetY), tostring( PIECES[nPieceIndex].dWidth / 2))
local sOffZPh1 = EgtIf( PIECES[nPieceIndex].DispOffset.Phase1.dOffsetZ, tostring( PIECES[nPieceIndex].DispOffset.Phase1.dOffsetZ), '0')
local sOffYPh2 = EgtIf( PIECES[nPieceIndex].DispOffset.Phase2.dOffsetY, tostring( PIECES[nPieceIndex].DispOffset.Phase2.dOffsetY), tostring( PIECES[nPieceIndex].dWidth / 2))
local sOffZPh2 = EgtIf( PIECES[nPieceIndex].DispOffset.Phase2.dOffsetZ, tostring( PIECES[nPieceIndex].DispOffset.Phase2.dOffsetZ), '0')
local sOffYPh1 = EgtIf( PARTS[nPieceIndex].DispOffset.Phase1.dOffsetY, tostring( PARTS[nPieceIndex].DispOffset.Phase1.dOffsetY), tostring( PARTS[nPieceIndex].dWidth / 2))
local sOffZPh1 = EgtIf( PARTS[nPieceIndex].DispOffset.Phase1.dOffsetZ, tostring( PARTS[nPieceIndex].DispOffset.Phase1.dOffsetZ), '0')
local sOffYPh2 = EgtIf( PARTS[nPieceIndex].DispOffset.Phase2.dOffsetY, tostring( PARTS[nPieceIndex].DispOffset.Phase2.dOffsetY), tostring( PARTS[nPieceIndex].dWidth / 2))
local sOffZPh2 = EgtIf( PARTS[nPieceIndex].DispOffset.Phase2.dOffsetZ, tostring( PARTS[nPieceIndex].DispOffset.Phase2.dOffsetZ), '0')
local vInp = EgtDialogBox( 'Dati di disposizione pezzo: ' .. PIECES[nPieceIndex].sName,
local vInp = EgtDialogBox( 'Dati di disposizione pezzo: ' .. PARTS[nPieceIndex].sName,
{'Sporgenza laterale FASE1', sOffYPh1}, {'Posizione Z FASE1', sOffZPh1},
{'Sporgenza laterale FASE2', sOffYPh2}, {'Posizione Z FASE2', sOffZPh2})
if not vInp or #vInp == 0 then
@@ -145,10 +181,10 @@ local function GetDispOffsetFromInput( nPieceIndex)
end
-- salvo input nei valori che utilizzerò dopo
PIECES[nPieceIndex].DispOffset.Phase1.dOffsetY = tonumber( vInp[1])
PIECES[nPieceIndex].DispOffset.Phase1.dOffsetZ = tonumber( vInp[2])
PIECES[nPieceIndex].DispOffset.Phase2.dOffsetY = tonumber( vInp[3])
PIECES[nPieceIndex].DispOffset.Phase2.dOffsetZ = tonumber( vInp[4])
PARTS[nPieceIndex].DispOffset.Phase1.dOffsetY = tonumber( vInp[1])
PARTS[nPieceIndex].DispOffset.Phase1.dOffsetZ = tonumber( vInp[2])
PARTS[nPieceIndex].DispOffset.Phase2.dOffsetY = tonumber( vInp[3])
PARTS[nPieceIndex].DispOffset.Phase2.dOffsetZ = tonumber( vInp[4])
return true
end
@@ -156,23 +192,48 @@ end
---------------------------------------------------------------------
-- Crea il grezzo che verrà messo in macchina
---------------------------------------------------------------------
local function CreateRawPart( PIECES)
local function AddOverMaterialToRaw( PARTS)
for i = 1, #PARTS do
PARTS[i].RawOffset = {}
-- recupero le info
PARTS[i].RawOffset.dOverMatIn = EgtGetInfo( PARTS[i].id, 'OVERMAT_IN', 'd') or 5
PARTS[i].RawOffset.dOverMatOut = EgtGetInfo( PARTS[i].id, 'OVERMAT_OUT', 'd') or 5
PARTS[i].RawOffset.dOverMatLeft = EgtGetInfo( PARTS[i].id, 'OVERMAT_LEFT', 'd') or 5
PARTS[i].RawOffset.dOverMatRight = EgtGetInfo( PARTS[i].id, 'OVERMAT_RIGHT', 'd') or 5
-- aggiungo sovramateriale
local dLength = PARTS[i].dLength + PARTS[i].RawOffset.dOverMatIn + PARTS[i].RawOffset.dOverMatOut
local dWidth = PARTS[i].dWidth + PARTS[i].RawOffset.dOverMatLeft + PARTS[i].RawOffset.dOverMatRight
local dHeight = PARTS[i].dHeight -- altezza non ha sovramteriale
EgtModifyRawPartSize( PARTS[i].idRaw, dLength, dWidth, dHeight)
end
end
---------------------------------------------------------------------
-- Crea il grezzo che verrà messo in macchina
---------------------------------------------------------------------
local function CreateRaws( PARTS)
for i = 1, #PARTS do
PARTS[i].idRaw = EgtAddRawPartWithPart( PARTS[i].id, PARTS[i].idSolid, 0, ColA)
end
end
-------------------------------------------------------------------------------------------------------------
-- *** Inserimento delle travi nel grezzo ***
-------------------------------------------------------------------------------------------------------------
local function MyProcessPieces()
-- verifico che i pezzi selezionati siano compatibili con la macchina
WinData.VerifyPieces( PIECES)
WinData.VerifyPieces( PARTS)
-- si crea il grezzo
CreateRawPart( PIECES)
CreateRaws( PARTS)
-- aggiunta sovramateriale
AddOverMaterialToRaw( PARTS)
-- recupero offset per posizionamento
for i = 1, #PIECES do
for i = 1, #PARTS do
local bInsertedAllOffs = GetDispOffsetFromNotes( i)
-- se non sono settati nelle note, li chiedo
if not bInsertedAllOffs then
@@ -185,7 +246,7 @@ local function MyProcessPieces()
end
-- si dispongono i pezzi sulla tavola
WinData.DisposePiecesOnTable( PIECES)
WinData.DisposePiecesOnTable( PARTS)
return true
end
@@ -194,7 +255,7 @@ end
-- *** Inserimento delle lavorazioni ***
-------------------------------------------------------------------------------------------------------------
local function MyProcessFeatures()
local bOk, Stats = WinExec.ProcessFeatures( PARTS)
--local bOk = WinExec.ProcessFeatures( PARTS)
return true
end