- migliorato flusso automatismo
- aggiunta chiamata alla WinLib
This commit is contained in:
+82
-56
@@ -37,7 +37,9 @@ EgtAddToPackagePath( sMachDir .. '\\Window\\?.lua')
|
||||
EgtOutLog( '*** Window Process Start ***', 1)
|
||||
|
||||
-- Carico le librerie
|
||||
_G.package.loaded.WinData = nil
|
||||
_G.package.loaded.WinExec = nil
|
||||
_G.package.loaded.WinLib = nil
|
||||
|
||||
-- TODO controllare se c'è un modo migliore per resettare librerie delle strategie caricate precedentemente
|
||||
-- Per ottimizzare potremmo anche ciclare solo fino al numero di strategie raggiunto per il momento.
|
||||
@@ -56,6 +58,10 @@ for i = 1, 99 do
|
||||
end
|
||||
|
||||
local WinExec = require( 'WinExec')
|
||||
local WinExec = require( 'WinLib')
|
||||
|
||||
-- Carico i dati globali
|
||||
local WinData = require( 'WinData')
|
||||
|
||||
-- Variabili globali
|
||||
PARTS = {}
|
||||
@@ -63,28 +69,6 @@ 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 ***
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
@@ -111,17 +95,12 @@ 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()
|
||||
PARTS[i].b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( PARTS[i].id, 'Solid') or GDB_ID.NULL, GDB_BB.STANDARD)
|
||||
PARTS[i].b3FinishedPiece = EgtGetBBoxGlob( EgtGetFirstNameInGroup( PARTS[i].id, 'Geo') or GDB_ID.NULL, GDB_BB.STANDARD)
|
||||
PARTS[i].frame = EgtFR( EgtGetFirstNameInGroup( EgtGetFirstNameInGroup( PARTS[i].id, 'Geo'), 'Frame'))
|
||||
sOut = sOut .. PARTS[i].sName .. ', '
|
||||
end
|
||||
sOut = sOut:sub( 1, -3)
|
||||
@@ -145,19 +124,17 @@ end
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
local function GetDispOffsetFromNotes( nPieceIndex)
|
||||
local bAllOffsetsAreOk = false
|
||||
local DispOffset = {}
|
||||
DispOffset.Phase1 = {}
|
||||
DispOffset.Phase2 = {}
|
||||
|
||||
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')
|
||||
PARTS[nPieceIndex].DispOffset.Phase1.dOffsetX = 0 -- dovrà essere calcolato in base alle lavorazioni
|
||||
PARTS[nPieceIndex].DispOffset.Phase1.dOffsetY = EgtGetInfo( PARTS[nPieceIndex].id, 'OFFY_1', 'd')
|
||||
PARTS[nPieceIndex].DispOffset.Phase1.dOffsetZ = EgtGetInfo( PARTS[nPieceIndex].id, 'OFFZ_1', 'd')
|
||||
PARTS[nPieceIndex].DispOffset.Phase2.dOffsetX = 0 -- dovrà essere calcolato in base alle lavorazioni
|
||||
PARTS[nPieceIndex].DispOffset.Phase2.dOffsetY = EgtGetInfo( PARTS[nPieceIndex].id, 'OFFY_2', 'd')
|
||||
PARTS[nPieceIndex].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
|
||||
-- controllo se tutti gli offset siano settati
|
||||
if PARTS[nPieceIndex].DispOffset.Phase1.dOffsetY and PARTS[nPieceIndex].DispOffset.Phase1.dOffsetZ and
|
||||
PARTS[nPieceIndex].DispOffset.Phase2.dOffsetY and PARTS[nPieceIndex].DispOffset.Phase2.dOffsetZ then
|
||||
bAllOffsetsAreOk = true
|
||||
end
|
||||
|
||||
@@ -167,12 +144,11 @@ end
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
local function GetDispOffsetFromInput( nPieceIndex)
|
||||
-- assegno alle stringhe i valori letti, in modo che vengano proposti quelli nel dialogo
|
||||
local sOffYPh1 = EgtIf( PARTS[nPieceIndex].DispOffset.Phase1.dOffsetY, tostring( PARTS[nPieceIndex].DispOffset.Phase1.dOffsetY), tostring( PARTS[nPieceIndex].dWidth / 2))
|
||||
local sOffYPh1 = EgtIf( PARTS[nPieceIndex].DispOffset.Phase1.dOffsetY, tostring( PARTS[nPieceIndex].DispOffset.Phase1.dOffsetY), tostring( PARTS[nPieceIndex].dPartWidth / 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 sOffYPh2 = EgtIf( PARTS[nPieceIndex].DispOffset.Phase2.dOffsetY, tostring( PARTS[nPieceIndex].DispOffset.Phase2.dOffsetY), tostring( PARTS[nPieceIndex].dPartWidth / 2))
|
||||
local sOffZPh2 = EgtIf( PARTS[nPieceIndex].DispOffset.Phase2.dOffsetZ, tostring( PARTS[nPieceIndex].DispOffset.Phase2.dOffsetZ), '0')
|
||||
|
||||
|
||||
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})
|
||||
@@ -194,17 +170,41 @@ end
|
||||
---------------------------------------------------------------------
|
||||
local function AddOverMaterialToRaw( PARTS)
|
||||
for i = 1, #PARTS do
|
||||
|
||||
-- prima di aggiungere sovramateriale al grezzo, calcolo dimensioni del finito
|
||||
local b3FinishedPart = EgtGetBBoxGlob( PARTS[i].idRaw or GDB_ID.NULL, GDB_BB.STANDARD)
|
||||
PARTS[i].b3FinishedPart = b3FinishedPart
|
||||
PARTS[i].dPartLength = PARTS[i].b3FinishedPart:getDimX()
|
||||
PARTS[i].dPartWidth = PARTS[i].b3FinishedPart:getDimY()
|
||||
PARTS[i].dPartHeight = PARTS[i].b3FinishedPart:getDimZ()
|
||||
|
||||
-- recupero e aggiungo offset
|
||||
PARTS[i].RawOffset = {}
|
||||
-- recupero le info
|
||||
-- recupero info sovramateriale
|
||||
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)
|
||||
|
||||
PARTS[i].dRawLength = PARTS[i].RawOffset.dOverMatLeft + PARTS[i].dPartLength + PARTS[i].RawOffset.dOverMatRight
|
||||
PARTS[i].dRawWidth = PARTS[i].RawOffset.dOverMatOut + PARTS[i].dPartWidth + PARTS[i].RawOffset.dOverMatIn
|
||||
PARTS[i].dRawHeight = PARTS[i].dPartHeight
|
||||
|
||||
EgtDraw() --TODO rimuovere
|
||||
|
||||
EgtModifyRawPartSize( PARTS[i].idRaw, PARTS[i].dRawLength, PARTS[i].dRawWidth, PARTS[i].dRawHeight)
|
||||
EgtDraw() --TODO rimuovere
|
||||
|
||||
local vtMove = Vector3d( PARTS[i].RawOffset.dOverMatLeft, PARTS[i].RawOffset.dOverMatOut, 0)
|
||||
EgtMovePartInRawPart( PARTS[i].id, vtMove)
|
||||
|
||||
EgtDraw() --TODO rimuovere
|
||||
|
||||
-- TODO da controllare, se ruotato di 180° bisognerebbe prendere dOverMatIn. Lo stesso per la X
|
||||
PARTS[i].OffsetPartToRaw = {}
|
||||
PARTS[i].OffsetPartToRaw.X = PARTS[i].RawOffset.dOverMatLeft
|
||||
PARTS[i].OffsetPartToRaw.Y = PARTS[i].RawOffset.dOverMatOut
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -213,27 +213,53 @@ end
|
||||
---------------------------------------------------------------------
|
||||
local function CreateRaws( PARTS)
|
||||
for i = 1, #PARTS do
|
||||
PARTS[i].idRaw = EgtAddRawPartWithPart( PARTS[i].id, PARTS[i].idSolid, 0, ColA)
|
||||
-- si crea il grezzo nell'origine del pezzo
|
||||
PARTS[i].idRaw = EgtAddRawPartWithPart( PARTS[i].id, EgtGetFirstNameInGroup( PARTS[i].id, 'Geo'), 0, ColA)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
-- *** Funzione per trovare nome MachGroup ***
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
local function NewMachGroupName()
|
||||
local nMachGroupId = EgtGetFirstMachGroup()
|
||||
if not nMachGroupId then return 1 end
|
||||
local nMaxMachGroup = 0
|
||||
while nMachGroupId do
|
||||
local sMachGroupName = EgtGetMachGroupName(nMachGroupId)
|
||||
local nMachGroupName = tonumber(sMachGroupName)
|
||||
if nMachGroupName > nMaxMachGroup then
|
||||
nMaxMachGroup = nMachGroupName
|
||||
end
|
||||
nMachGroupId = EgtGetNextMachGroup(nMachGroupId)
|
||||
end
|
||||
return nMaxMachGroup + 1
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
-- *** Inserimento delle travi nel grezzo ***
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
local function MyProcessPieces()
|
||||
|
||||
-- verifico che i pezzi selezionati siano compatibili con la macchina
|
||||
WinData.VerifyPieces( PARTS)
|
||||
-- creo macchinata
|
||||
local MachGroupName = NewMachGroupName()
|
||||
local nMachGroup = EgtAddMachGroup( MachGroupName)
|
||||
|
||||
-- si crea il grezzo
|
||||
CreateRaws( PARTS)
|
||||
|
||||
-- aggiunta sovramateriale
|
||||
-- allineo i pezzi come orientamento richiesto dalla macchina
|
||||
WinData.AlignRawsToTable( PARTS)
|
||||
|
||||
-- aggiungo sovramateriale ai grezzi
|
||||
AddOverMaterialToRaw( PARTS)
|
||||
|
||||
-- recupero offset per posizionamento
|
||||
for i = 1, #PARTS do
|
||||
PARTS[i].DispOffset = {}
|
||||
PARTS[i].DispOffset.Phase1 = {}
|
||||
PARTS[i].DispOffset.Phase2 = {}
|
||||
|
||||
local bInsertedAllOffs = GetDispOffsetFromNotes( i)
|
||||
-- se non sono settati nelle note, li chiedo
|
||||
if not bInsertedAllOffs then
|
||||
@@ -246,7 +272,7 @@ local function MyProcessPieces()
|
||||
end
|
||||
|
||||
-- si dispongono i pezzi sulla tavola
|
||||
WinData.DisposePiecesOnTable( PARTS)
|
||||
WinData.Disposition( PARTS)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user