-- WallExec.lua by Egaltech s.r.l. 2023/07/04 -- Libreria esecuzione lavorazioni per Pareti -- 2023/05/25 Aggiunto ordinamento in base a priorità da btl. -- 2023/06/07 Nel caso di outline con priorità aggiunta la rimozione degli sfridi nella lavorazione successiva. -- 2023/06/27 Aggiunte origini TN e BN. -- 2023/07/04 Se c'è funzione di macchina WD.GetOrigCorner si lascia scegliere posizione default a questa impostando 0 se non c'è 'REFPOS'. -- Tabella per definizione modulo local WallExec = {} -- Include require( 'EgtBase') -- Carico i dati globali e libero tutti gli altri _G.package.loaded.WallData = nil _G.package.loaded.CutData = nil _G.package.loaded.MillingData = nil _G.package.loaded.PocketingData = nil _G.package.loaded.DrillData = nil _G.package.loaded.SawingData = nil local WD = require( 'WallData') if WALL and WALL.NESTINGCORNERBL then WD.NESTING_CORNER = 'BL' end -- Carico le librerie _G.package.loaded.WMachiningLib = nil _G.package.loaded.WallLib = nil _G.package.loaded.WFeatureTopology = nil _G.package.loaded.WProcessCut = nil _G.package.loaded.WProcessDoubleCut = nil _G.package.loaded.WProcessSawCut = nil _G.package.loaded.WProcessLapJoint = nil _G.package.loaded.WProcessDrill = nil _G.package.loaded.WProcessMortise = nil _G.package.loaded.WProcessDtMortise = nil _G.package.loaded.WProcessMark = nil _G.package.loaded.WProcessText = nil _G.package.loaded.WProcessFreeContour = nil _G.package.loaded.WProcessVariant = nil local WM = require( 'WMachiningLib') local WL = require( 'WallLib') local Topology = require( 'WFeatureTopology') local Cut = require( 'WProcessCut') local DoubleCut = require( 'WProcessDoubleCut') local SawCut = require( 'WProcessSawCut') local LapJoint = require( 'WProcessLapJoint') local Drill = require( 'WProcessDrill') local Mortise = require( 'WProcessMortise') local DtMortise = require( 'WProcessDtMortise') local Mark = require( 'WProcessMark') local Text = require( 'WProcessText') local FreeContour = require( 'WProcessFreeContour') local Variant = require( 'WProcessVariant') ------------------------------------------------------------------------------------------------------------- -- *** Inserimento delle pareti nel pannello *** ------------------------------------------------------------------------------------------------------------- function WallExec.ProcessWalls( dRawL, dRawW, dRawH, vWall, bMachGroupOk, bNewProcess, nRawOutlineId) -- Creazione nuovo gruppo di lavoro if not bMachGroupOk then local sMgName = EgtGetMachGroupNewName( 'Mach') local NewMgId = EgtAddMachGroup( sMgName) if not NewMgId then local sOut = 'Errore nella creazione del gruppo di lavoro ' .. sMgName return false, sOut end end -- Impostazione della tavola EgtSetTable( 'Tab') -- Area tavola local b3Tab = EgtGetTableArea() -- Calcolo posizione estremo di riferimento della tavola rispetto a sua origine in BL local OrigOnTab local nCorner local sOrigCorner = WD.ORIG_CORNER or 'BR' if WD.GetOrigCorner then sOrigCorner = WD.GetOrigCorner( EgtGetInfo( EgtGetFirstNameInGroup( GDB_ID.ROOT, 'BtlInfo') or GDB_ID.NULL, 'REFPOS', 'i') or 0) end if sOrigCorner == 'TL' then nCorner = MCH_CR.TL OrigOnTab = Point3d( 0 + abs( WD.DELTA_X or 0), b3Tab:getDimY() - abs( WD.DELTA_Y or 0), ( WD.DELTA_Z or 0)) elseif sOrigCorner == 'BL' then nCorner = MCH_CR.BL OrigOnTab = Point3d( 0 + abs( WD.DELTA_X or 0), abs( WD.DELTA_Y or 0), ( WD.DELTA_Z or 0)) elseif sOrigCorner == 'TR' then nCorner = MCH_CR.TR OrigOnTab = Point3d( b3Tab:getDimX() - abs( WD.DELTA_X or 0), b3Tab:getDimY() - abs( WD.DELTA_Y or 0), ( WD.DELTA_Z or 0)) elseif sOrigCorner == 'BR' then nCorner = MCH_CR.BR OrigOnTab = Point3d( b3Tab:getDimX() - abs( WD.DELTA_X or 0), abs( WD.DELTA_Y or 0), ( WD.DELTA_Z or 0)) elseif sOrigCorner == 'TM' then nCorner = MCH_CR.TR OrigOnTab = Point3d( WD.MID_REF - abs( WD.DELTA_X or 0), b3Tab:getDimY() - abs( WD.DELTA_Y or 0), ( WD.DELTA_Z or 0)) elseif sOrigCorner == 'BM' then nCorner = MCH_CR.BR OrigOnTab = Point3d( WD.MID_REF - abs( WD.DELTA_X or 0), abs( WD.DELTA_Y or 0), ( WD.DELTA_Z or 0)) elseif sOrigCorner == 'TN' then nCorner = MCH_CR.TL OrigOnTab = Point3d( WD.NEW_REF + abs( WD.DELTA_X or 0), b3Tab:getDimY() - abs( WD.DELTA_Y or 0), ( WD.DELTA_Z or 0)) elseif sOrigCorner == 'BN' then nCorner = MCH_CR.BL OrigOnTab = Point3d( WD.NEW_REF + abs( WD.DELTA_X or 0), abs( WD.DELTA_Y or 0), ( WD.DELTA_Z or 0)) end -- Impostazione dell'attrezzaggio di default EgtImportSetup() -- Impostazione eventuale allargamento area disponibile per grezzo EgtSetTableAreaOffset( WD.TAB_EXTRA_XP or 0, WD.TAB_EXTRA_XM or 0, WD.TAB_EXTRA_YP or 0, WD.TAB_EXTRA_YM or 0) -- Creazione del grezzo e suo posizionamento in macchina local nRaw = GDB_ID.NULL if nRawOutlineId and nRawOutlineId ~= GDB_ID.NULL then nRaw = EgtAddRawPartWithPart( 0, nRawOutlineId, 0, WD.RAWCOL) else nRaw = EgtAddRawPart( Point3d( 0, 0, 0), dRawL, dRawW, dRawH, WD.RAWCOL) end EgtMoveToCornerRawPart( nRaw, OrigOnTab, nCorner) EgtSetInfo( nRaw, 'ORD', 1) -- Inserimento dei pezzi nel grezzo for i = 1, #vWall do -- assegno identificativo pezzo local Pz = vWall[i].Id -- dati del pezzo local b3Part = EgtGetBBoxGlob( Pz or GDB_ID.NULL, GDB_BB.EXACT) local b3Solid = vWall[i].Box if b3Part:isEmpty() or b3Solid:isEmpty() then break end local PartLen = b3Solid:getDimX() local PartWidth = b3Solid:getDimY() local PartHeight = b3Solid:getDimZ() local vtOffs = b3Part:getMin() - b3Solid:getMin() -- creo o pulisco gruppo geometrie aggiuntive if not WL.CreateOrEmptyAddGroup( Pz) then local sOut = 'Error creating Additional Group in Part ' .. tostring( Pz) return false, sOut end -- inserisco il pezzo nel grezzo EgtDeselectPartObjs( Pz) local ptPos if bNewProcess then local sNestingRef = ( WALL.NESTING_REF or WD.NESTING_CORNER) if sNestingRef == 'TL' then ptPos = Point3d( vWall[i].PosX, dRawW - PartWidth - vWall[i].PosZ, ( dRawH - PartHeight) / 2) + vtOffs elseif sNestingRef == 'TR' then ptPos = Point3d( dRawL - PartLen - vWall[i].PosX, dRawW - PartWidth - vWall[i].PosZ, ( dRawH - PartHeight) / 2) + vtOffs elseif sNestingRef == 'BR' then ptPos = Point3d( dRawL - PartLen - vWall[i].PosX, vWall[i].PosZ, ( dRawH - PartHeight) / 2) + vtOffs else -- 'BL' ptPos = Point3d( vWall[i].PosX, vWall[i].PosZ, ( dRawH - PartHeight) / 2) + vtOffs end else local dPosH = EgtIf( vWall[i].PosY < 0.1, ( dRawH - PartHeight) / 2, vWall[i].PosY) ptPos = Point3d( dRawL - vWall[i].PosX - PartLen, vWall[i].PosZ, dPosH) + vtOffs end EgtAddPartToRawPart( Pz, ptPos, nRaw) end return true end ------------------------------------------------------------------------------------------------------------- -- *** Inserimento delle lavorazioni nelle pareti *** ------------------------------------------------------------------------------------------------------------- function WallExec.CollectFeatures( PartId, b3Raw) -- recupero le feature local vProc = {} local LayerId = {} LayerId[1] = EgtGetFirstNameInGroup( PartId or GDB_ID.NULL, 'Outline') LayerId[2] = EgtGetFirstNameInGroup( PartId or GDB_ID.NULL, 'Processings') for nInd = 1, #LayerId do local ProcId = EgtGetFirstInGroup( LayerId[nInd] or GDB_ID.NULL) while ProcId do local nEntType = EgtGetType( ProcId) if nEntType == GDB_TY.SRF_MESH or nEntType == GDB_TY.EXT_TEXT or nEntType == GDB_TY.CRV_LINE or nEntType == GDB_TY.CRV_ARC or nEntType == GDB_TY.CRV_BEZ or nEntType == GDB_TY.CRV_COMPO then local nGrp = EgtGetInfo( ProcId, 'GRP', 'i') local nPrc = EgtGetInfo( ProcId, 'PRC', 'i') local nDo = EgtGetInfo( ProcId, 'DO', 'i') or 1 local nCutId = EgtGetInfo( EgtGetParent( EgtGetParent( ProcId)), 'CUTID', 'i') or 0 local nTaskId = EgtGetInfo( ProcId, 'TASKID', 'i') or 0 if nGrp and nPrc and nDo == 1 then local Proc = {} Proc.PartId = PartId Proc.Id = ProcId Proc.Grp = nGrp Proc.Prc = nPrc Proc.Flg = 1 Proc.Fct = EgtSurfTmFacetCount( ProcId) or 0 Proc.Diam = 0 Proc.Fcs = 0 Proc.Fce = 0 Proc.CutId = nCutId Proc.TaskId = nTaskId Proc.Box = EgtGetBBoxGlob( ProcId, GDB_BB.STANDARD) Proc.IsOutline = ( Proc.Prc == 251 or Proc.Prc == 252) -- recupero l'elenco delle facce della parte interessate dalla feature Proc.AffectedFaces = WL.GetProcessAffectedFaces( Proc) -- recupero informazioni sulle facce della feature Proc.Face = {} for i = 1, Proc.Fct do Proc.Face[i] = { Id = i - 1, VtN = EgtSurfTmFacetNormVersor( Proc.Id, i - 1, GDB_ID.ROOT ), Elevation = WL.GetFaceElevation( Proc.Id, i - 1, PartId)} end if Proc.Box and not Proc.Box:isEmpty() then table.insert( vProc, Proc) -- se foro if Drill.Identify( Proc) then -- assegno diametro e facce di ingresso e uscita (dati tabelle sempre per riferimento) Proc.Diam, Proc.Fcs, Proc.Fce = Drill.GetData( Proc, b3Raw) -- verifico se necessaria seconda lavorazione da parte opposta per foro più lungo della punta if Drill.Split( Proc, b3Raw) then -- aggiorno flags prima parte foro (dati tabelle sempre per riferimento) Proc.Flg = 2 -- definisco dati seconda parte local Proc2 = {} Proc2.PartId = PartId Proc2.Id = ProcId Proc2.Grp = nGrp Proc2.Prc = nPrc Proc2.Flg = -2 Proc2.Box = BBox3d( Proc.Box) Proc2.Fct = Proc.Fct Proc2.Diam = Proc.Diam Proc2.Fcs = Proc.Fce Proc2.Fce = Proc.Fcs Proc2.CutId = Proc.CutId Proc2.TaskId = Proc.TaskId table.insert( vProc, Proc2) end end else EgtOutLog( ' Feature ' .. tostring( Proc.Id) .. ' is empty (no geometry)') end end end ProcId = EgtGetNext( ProcId) end end return vProc end ------------------------------------------------------------------------------------------------------------- local function ClassifyFeatures( vProc, b3Raw) for i = 1, #vProc do local Proc = vProc[i] -- se taglio if Cut.Identify( Proc) then local bOk = Cut.Classify( Proc, b3Raw) if not bOk then Proc.Flg = 0 end -- se taglio doppio elseif DoubleCut.Identify( Proc) then local bOk = DoubleCut.Classify( Proc, b3Raw) if not bOk then Proc.Flg = 0 end -- se taglio con lama elseif SawCut.Identify( Proc) then local bOk = SawCut.Classify( Proc, b3Raw) if not bOk then Proc.Flg = 0 end -- se tasca elseif LapJoint.Identify( Proc) then local bOk = LapJoint.Classify( Proc, b3Raw) if not bOk then Proc.Flg = 0 end -- se foratura elseif Drill.Identify( Proc) then local bOk = Drill.Classify( Proc, b3Raw) if not bOk then Proc.Flg = 0 end -- se mortasatura elseif Mortise.Identify( Proc) then local bOk = Mortise.Classify( Proc, b3Raw) if not bOk then Proc.Flg = 0 end -- se mortasatura a coda di rondine elseif DtMortise.Identify( Proc) then local bOk = DtMortise.Classify( Proc, b3Raw) if not bOk then Proc.Flg = 0 end -- se marcatura elseif Mark.Identify( Proc) then local bOk = Mark.Classify( Proc, b3Raw) if not bOk then Proc.Flg = 0 end -- se testo elseif Text.Identify( Proc) then local bOk = Text.Classify( Proc, b3Raw) if not bOk then Proc.Flg = 0 end -- se contorno libero, outile o aperture elseif FreeContour.Identify( Proc) then local bOk = FreeContour.Classify( Proc, b3Raw) if not bOk then Proc.Flg = 0 end -- se feature custom (Variant) elseif Variant.Identify( Proc) then local bOk = Variant.Classify( Proc, b3Raw) if not bOk then Proc.Flg = 0 end end end end ------------------------------------------------------------------------------------------------------------- local function ClassifyTopology( vProc) local nRecognized = 0 for i = 1, #vProc do local Proc = vProc[i] if Topology.Classify( Proc) then nRecognized = nRecognized + 1 end end return nRecognized end ------------------------------------------------------------------------------------------------------------- local function PrintFeatures( vProc) EgtOutLog( ' *** Feature List ***') for i = 1, #vProc do local Proc = vProc[i] local sOut = string.format( 'Part=%3d Proc=%3d Grp=%1d Prc=%3d TC=%2d/%d Flg=%2d Fcse=%1d,%1d Diam=%.2f Fct=%2d Dbl=%2d Dlt=%.1f Box=%s TopoName=%s', Proc.PartId, Proc.Id, Proc.Grp, Proc.Prc, Proc.TaskId, Proc.CutId, Proc.Flg, Proc.Fcs, Proc.Fce, Proc.Diam, Proc.Fct, Proc.Double or 0, Proc.Delta or 0, tostring( Proc.Box), Proc.TopologyLongName or '') EgtOutLog( sOut) end end ------------------------------------------------------------------------------------------------------------- local function AddFeatureMachining( Proc, nRawId, b3Raw) local bOk = true local sErr = '' EgtOutLog( ' * Process ' .. tostring( Proc.Id) .. ' *', 1) -- se taglio (1/2-010-X) o taglio longitudinale (0/3/4-010-X) if Cut.Identify( Proc) then -- esecuzione taglio bOk, sErr = Cut.Make( Proc, nRawId, b3Raw) -- se taglio doppio (1/2-011-X) o taglio doppio longitudinale (0-012-X) elseif DoubleCut.Identify( Proc) then -- esecuzione taglio bOk, sErr = DoubleCut.Make( Proc, nRawId, b3Raw) -- se taglio con lama (0/3/4-013-X) elseif SawCut.Identify( Proc) then -- esecuzione taglio bOk, sErr = SawCut.Make( Proc, nRawId, b3Raw) -- se tasca (3/4-030-X) o similari elseif LapJoint.Identify( Proc) then -- esecuzione tasca bOk, sErr = LapJoint.Make( Proc, nRawId, b3Raw) -- se foratura ( 3/4-040-X) elseif Drill.Identify( Proc) then -- esecuzione foratura bOk, sErr = Drill.Make( Proc, nRawId, b3Raw) -- se mortasatura (3/4-050-X) o similari elseif Mortise.Identify( Proc) then -- esecuzione mortasatura bOk, sErr = Mortise.Make( Proc, nRawId, b3Raw) -- se mortasatura a coda di rondine (3/4-055-X) elseif DtMortise.Identify( Proc) then -- esecuzione mortasatura a coda di rondine bOk, sErr = DtMortise.Make( Proc, nRawId, b3Raw) -- se marcatura (3/4-060-X) elseif Mark.Identify( Proc) then -- esecuzione marcatura bOk, sErr = Mark.Make( Proc, nRawId, b3Raw) -- se testo (4-061-X) elseif Text.Identify( Proc) then -- esecuzione incisione testo bOk, sErr = Text.Make( Proc, nRawId, b3Raw) -- se contorno libero, outline o apertura ( 0/3/4-250/251/252-X) elseif FreeContour.Identify( Proc) then -- esecuzione contorno bOk, sErr = FreeContour.Make( Proc, nRawId, b3Raw) -- se feature custom (Variant) elseif Variant.Identify( Proc) then -- esecuzione bOk, sErr = Variant.Make( Proc, nRawId, b3Raw) -- altrimenti feature non riconosciuta else bOk = false sErr = 'Feature type non recognized for machining' end return bOk, sErr end ------------------------------------------------------------------------------------------------------------- local function MoveMachiningsAtEnd( nPhase, nType, sStartName, sProperty) local nOperId = EgtGetPhaseDisposition( nPhase) local nLastId = EgtGetLastOperation() local nInsertId = nLastId while nOperId do local nNextOperId = EgtGetNextOperation( nOperId) if EgtGetOperationPhase( nOperId) == nPhase and EgtGetOperationType( nOperId) == nType and ( ( EgtGetInfo( nOperId, 'MOVE_AFTER', 'i') == 1 ) or ( not sStartName or string.sub( EgtGetName( nOperId), 1, #sStartName) == sStartName)) then EgtRelocateGlob( nOperId, nInsertId, GDB_IN.AFTER) nInsertId = nOperId end if nOperId == nLastId then break end nOperId = nNextOperId end end ------ Ordinamento dei tagli, delle fresature e delle forature ------- local function SpSorting( TabCut, PrevMch, nType, bOneWay) -- ordino le lavorazioni (in gruppi di max 1000 entità se 32bit 10000 se 64bit) --EgtOutLog('Dati per ShortestPath :') local SP_MAX_ENT = EgtIf( EgtIs64bit(), 10000, 1000) local nBase = 0 while nBase < #TabCut do -- calcolo ordinamento EgtSpInit() for i = 1, min( #TabCut - nBase, SP_MAX_ENT) do local ptS = TabCut[nBase+i].Start local ptE = TabCut[nBase+i].End EgtSpAddPoint( ptS:getX(), ptS:getY(), ptS:getZ(), 0, 0, ptE:getX(), ptE:getY(), ptE:getZ(), 0, 0) end EgtSpSetAngularParams( 1000, 40, 2000, 60) EgtSpSetOpenBound( true, SHP_OB.NEAR_PNT, 50000, 0, 0, 0, 0) if WD.BEAM_MACHINE and (nType & MCH_OY.SAWING) == MCH_OY.SAWING then EgtSpSetOpenBound( false, SHP_OB.NEAR_PNT, -50000, 0, 0, 0, 0) end EgtSpSetZzOwStep( 10) local nType = EgtIf( bOneWay, SHP_TY.ONEWAY_YM, SHP_TY.OPEN) local vOrd = EgtSpCalculate( nType) EgtSpTerminate() -- applico ordinamento calcolato if vOrd then for i = 1, #vOrd do EgtRelocateGlob( TabCut[nBase+vOrd[i]].Mch, PrevMch, GDB_IN.AFTER) PrevMch = TabCut[nBase+vOrd[i]].Mch end end -- incremento la base nBase = nBase + SP_MAX_ENT end return PrevMch end local function ContainsStartName( nOperId, StartNames) local bFound = false for i = 1, #StartNames do local sStartName = StartNames[i] if string.sub( EgtGetName( nOperId), 1, #sStartName) == sStartName then bFound = true end end return bFound end ------ Ordinamento dei tagli, delle fresature e delle forature ------- local function SortMach( nPhase, PrevMch, nPartId, nType, StartNames, bExistName, sInfo, bExistInfo, bOneWay, bByTool, bByToolAngle, nPriority) -- dichiarazione tabella local TabCut = {} -- Recupero gli identificativi delle lavorazioni e annullo eventuali allungamenti e Id di altre lavorazioni rappresentate local nOperId = EgtGetNextOperation( PrevMch) while nOperId do local nOperType = EgtGetOperationType( nOperId) -- Se appartiene alla fase corrente e taglio con lama non da sopra (sempre su 1 sola entità) if EgtGetOperationPhase( nOperId) == nPhase and ( nType & nOperType) == nOperType and ( not nPartId or EgtGetInfo( nOperId, 'Part', 'i') == nPartId) and ( not nPriority or EgtGetInfo( nOperId, 'PRIORITY', 'i') == nPriority ) and ( not StartNames or ( bExistName and ContainsStartName( nOperId, StartNames)) or ( not bExistName and not ContainsStartName( nOperId, StartNames))) and ( not sInfo or ( bExistInfo and EgtGetInfo( nOperId, sInfo, 'i') == 1) or ( not bExistInfo and EgtGetInfo( nOperId, sInfo, 'i') ~= 1)) then -- non si deve cambiare lo stato di attivazione della lavorazione (se disabilitata errata) EgtSetCurrMachining( nOperId) if not EgtIsMachiningEmpty() then -- punto iniziale e finale e direzione della lavorazione local ptStart = EgtGetMachiningStartPoint() local ptEnd = EgtGetMachiningEndPoint() local sTUUID = '' local nToolType = 0 local nToolDiam = 0 local nToolDir = 0 if bByTool then sTUUID = EgtGetMachiningParam( MCH_MP.TUUID) local sToolName = EgtTdbGetToolFromUUID( sTUUID) if EgtTdbSetCurrTool( sToolName) then nToolType = EgtTdbGetCurrToolParam( MCH_TP.TYPE) nToolDiam = EgtTdbGetCurrToolParam( MCH_TP.TOTDIAM) else sTUUID = '' end end if bByToolAngle then local nClId = EgtGetFirstNameInGroup( nOperId, 'CL') local nPathId = EgtGetFirstInGroup( nClId or GDB_ID.NULL) local vtTool = EgtGetInfo( nPathId, 'EXTR', 'v') nToolDir = EgtIf( vtTool:getZ() > 0.999999, 1, 0) end table.insert( TabCut, {Mch=nOperId, Ent=nEntId, Start=ptStart, End=ptEnd, Tool=sTUUID, ToolType=nToolType, ToolDiam=nToolDiam, ToolDir=nToolDir}) end end -- Passo alla operazione successiva nOperId = EgtGetNextOperation( nOperId) end if bByTool then function ToolCompare(a,b) if a.ToolType < b.ToolType then return true elseif a.ToolType == b.ToolType then if a.ToolDiam > b.ToolDiam then return true elseif a.ToolDiam == b.ToolDiam then if a.Tool < b.Tool then return true elseif a.Tool == b.Tool then if bByToolAngle then if a.ToolDir > b.ToolDir then return true elseif a.ToolDir == b.ToolDir then return a.Mch < b.Mch end else return a.Mch < b.Mch end end end end return false end -- test della funzione di ordinamento if EgtGetDebugLevel() >= 3 then EgtOutLog( ' CompareFeatures Test ') local bCompTest = true for i = 1, #TabCut do for j = i + 1, #TabCut do local bComp1 = ToolCompare( TabCut[i], TabCut[j]) local bComp2 = ToolCompare( TabCut[j], TabCut[i]) if bComp1 == bComp2 then bCompTest = false EgtOutLog( string.format( ' ProcId : %d vs %d --> ERROR', TabCut[i].Mch, TabCut[j].Mch)) end end end if bCompTest then EgtOutLog( ' ALL OK') end end table.sort(TabCut, ToolCompare) -- table.sort(TabCut, function(a,b) return a.ToolType < b.ToolType and a.ToolDiam > b.ToolDiam and a.Tool < b.Tool end) local SupportTabCut = {} local nPrevTUUID = 0 local nPrevTDirZ = 1 for i = 1, #TabCut do -- se tuuid uguale al precedente, lo aggiungo alla lista if nPrevTUUID == TabCut[i].Tool and ( not bByToolAngle or nPrevTDirZ == TabCut[i].ToolDir) then table.insert( SupportTabCut, TabCut[i]) -- se tuuid diverso, else -- faccio calcolare la lista PrevMch = SpSorting( SupportTabCut, PrevMch, nType, bOneWay) -- cancello la lista e aggiorno tuuid corrente SupportTabCut = {} nPrevTUUID = TabCut[i].Tool if bByToolAngle then nPrevTDirZ = TabCut[i].ToolDir end table.insert( SupportTabCut, TabCut[i]) end end -- calcolo ultima lista if #SupportTabCut > 0 then PrevMch = SpSorting( SupportTabCut, PrevMch, nType, bOneWay) end else PrevMch = SpSorting( TabCut, PrevMch, nType, bOneWay) end return PrevMch end ------------------------------------------------------------------------------------------------------------- local function SortMachinings( nPhase, PrevMch, nPartId, nPriority) -- Chiodature PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MILLING, { 'Nail_'}, true, nil, nil, nil, true, nil, nPriority) -- Tagli con sega a catena che sono rifiniture di spigoli PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MORTISING, { 'Csaw_'}, false, nil, nil, nil, nil, nil, nPriority) -- Forature orizzontali con punte lunghe PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.DRILLING, { 'LhDrill_'}, true, 'MOVE_AFTER', false, true, nil, nil, nPriority) -- Preforature per fori inclinati PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.POCKETING, { 'PreDrill_'}, true, nil, nil, nil, nil, nil, nPriority) -- Forature e Svuotature PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.DRILLING + MCH_OY.POCKETING + MCH_OY.MILLING, { 'SideMill_', 'Clean_'}, false, 'MOVE_AFTER', false, false, true, nil, nPriority) -- -- Forature *** -- PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.DRILLING, nil, nil, 'MOVE_AFTER', false) -- -- Svuotature *** -- PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.POCKETING, nil, nil, 'MOVE_AFTER', false) -- -- Fresature che sono rifiniture di spigoli -- PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MILLING, { 'Clean_'}, false, 'MOVE_AFTER', false, false, true) -- Lavorazioni di superficie PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_MY.SURFFINISHING, nil, nil, 'MOVE_AFTER', false, nil, nil, nil, nPriority) -- Fresature per gole PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MILLING, { 'Gorge_'}, true, 'MOVE_AFTER', false, nil, nil, nil, nPriority) -- Fresature che sono rifiniture di spigoli PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MILLING, { 'SideMill_'}, true, 'MOVE_AFTER', false, false, true, true, nPriority) -- Fresature che sono puliture di spigoli PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MILLING, { 'Clean_'}, true, 'MOVE_AFTER', false, false, true, nil, nPriority) -- Tagli per gole PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.SAWING, { 'GorgeCut_'}, true, nil, nil, nil, nil, nil, nPriority) -- Tagli con lama PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.SAWING, nil, nil, nil, nil, nil, nil, nil, nPriority) -- Qui rimozione sfridi (se ci sono lavorazioni successive) if not nPriority then -- Fresature dei lapjoint che necessitano di gorge PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MILLING, { 'SideMill_'}, true, 'MOVE_AFTER', true, false, true, true) -- Tagli con sega a catena che vanno fatti dopo i tagli con lama PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MORTISING, { 'Csaw_'}, true) -- Fresature (puliture di spigoli) che vanno fatte dopo i tagli con lama PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.MILLING, nil, nil, 'MOVE_AFTER', true) -- Forature che vanno fatte dopo i tagli con lama PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.DRILLING, nil, nil, 'MOVE_AFTER', true) -- Svuotature che vanno fatte dopo i tagli con lama PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_OY.POCKETING, nil, nil, 'MOVE_AFTER', true) -- Lavorazioni di superficie che vanno fatte dopo i tagli con lama PrevMch = SortMach( nPhase, PrevMch, nPartId, MCH_MY.SURFFINISHING, nil, nil, 'MOVE_AFTER', true) end return PrevMch end ------------------------------------------------------------------------------------------------------------- -- setto la rimozione sfridi dopo le lavorazioni di outline function InsertScrapRemoval( nPhase) local nCurrentOperationId = EgtGetNextOperation( EgtGetPhaseDisposition( nPhase)) local nActiveMachiningId = EgtGetCurrMachining() while nCurrentOperationId do local bIsCurrentOperationOutline = ( EgtGetInfo( nCurrentOperationId or GDB_ID.NULL, 'ISOUTLINE', 'b' ) == true) local bIsCurrentOperationWithPriority = ( ( EgtGetInfo( nCurrentOperationId or GDB_ID.NULL, 'PRIORITY', 'i' ) or 0) > 0) local nNextOperationId = EgtGetNextOperation (nCurrentOperationId) local bIsNextOperationOutline = ( EgtGetInfo( nNextOperationId or GDB_ID.NULL, 'ISOUTLINE', 'b' ) == true) if bIsCurrentOperationOutline and bIsCurrentOperationWithPriority and nNextOperationId and not bIsNextOperationOutline then EgtSetCurrMachining( nNextOperationId) local sMachiningNotes = EgtGetMachiningParam( MCH_MP.USERNOTES) sMachiningNotes = sMachiningNotes .. 'ScrapRemove=1;' EgtSetMachiningParam( MCH_MP.USERNOTES, sMachiningNotes) end nCurrentOperationId = EgtGetNextOperation( nCurrentOperationId) end EgtSetCurrMachining( nActiveMachiningId or GDB_ID.NULL) end ------------------------------------------------------------------------------------------------------------- -- funzione per l'ordinamento delle features in doppio da accoppiare -- ordinate prima in base alla X e poi alla Y local function SortFeaturesForMirror( Proc1, Proc2) local TOL = EgtIf( Proc1.TopologyLongName == 'DRILLING', WD.DOUBLE_HEAD_DRILLING_TOLERANCE , WD.DOUBLE_HEAD_POCKET_TOLERANCE) local Proc1X = Proc1.Box:getCenter():getX() local Proc1Y = Proc1.Box:getCenter():getY() local Proc2X = Proc2.Box:getCenter():getX() local Proc2Y = Proc2.Box:getCenter():getY() if Proc1X < Proc2X - TOL then return true elseif abs( Proc1X - Proc2X) < TOL then if Proc1Y < Proc2Y - TOL then return true end end end ------------------------------------------------------------------------------------------------------------- -- Controlla in vProc la presenza di feature da lavorare in doppio e, se trovate, ne setta i parametri local function SetMirroredFeatures( vProc, b3Raw) local dMinimumDistanceMirroredFeatures = 780 local vGroovesThrough = {} local vDrillings = {} -- in base alla topologia cerco subito la feature mirror oppure raccolgo tutte le feature simili e le accoppio successivamente for i = 1, #vProc do local Proc = vProc[i] if Proc.Flg ~= 0 then -- tutte le rabbet, tunnel e groove sul fianco vengono confrontate con possibili feature mirror if WD.DOUBLE_HEAD_POCKET and ( ( Proc.TopologyLongName == 'Rabbet-Through-RightAngles-Parallel-2' and Proc.AffectedFaces.Front) or ( Proc.TopologyLongName == 'Groove-Blind-RightAngles-Parallel-3' and Proc.AffectedFaces.Front) or ( Proc.TopologyLongName == 'Groove-Blind-RightAngles-Parallel-4' and Proc.AffectedFaces.Front) or ( Proc.TopologyLongName == 'Tunnel-Blind-RightAngles-Parallel-5' and Proc.AffectedFaces.Front) or ( Proc.TopologyLongName == 'Groove-Through-RightAngles-Parallel-3' and Proc.AffectedFaces.Front and Proc.AffectedFaces.Left and Proc.AffectedFaces.Right) ) then -- feature vicino al bordo Y- del grezzo local bIsFeatureOnEdgeOrPocket = false local nFaceLookingFrontSide for j = 1, Proc.Fct do if AreOppositeVectorApprox( Proc.Face[j].VtN, Y_AX()) then nFaceLookingFrontSide = j - 1 end end local dMaxDist = 200 if nFaceLookingFrontSide then local ptFaceCenter = EgtSurfTmFacetCenter( Proc.Id, nFaceLookingFrontSide, GDB_ID.ROOT) local dSideDist = abs( ptFaceCenter:getY() - b3Raw:getMin():getY()) bIsFeatureOnEdgeOrPocket = dSideDist < dMaxDist end -- mirror XY sul lato opposto local nMirrorId local dYMirrorAx local dDeltaZ local bIsMirrorTowardsBottom = false -- cerco una possibile feature mirror for j = 1, #vProc do local ProcMirror = vProc[j] if ProcMirror.TopologyLongName == Proc.TopologyLongName and ProcMirror.Id ~= Proc.Id and ProcMirror.Flg ~= 0 then -- feature specchiata rivolta verso Y+ e parallela a X local bIsMirrorFeatureFacingBackSide = EgtIf( Proc.TopologyLongName == 'Groove-Through-RightAngles-Parallel-3', ProcMirror.AffectedFaces.Back and Proc.AffectedFaces.Left and Proc.AffectedFaces.Right, ProcMirror.AffectedFaces.Back) -- feature specchiata vicino al bordo Y+ del grezzo local bIsMirrorFeatureOnEdgeOrPocket = false local nMirrorFaceLookingBackSide for k = 1, ProcMirror.Fct do if AreSameVectorApprox( ProcMirror.Face[k].VtN, Y_AX()) then nMirrorFaceLookingBackSide = k - 1 end end if nMirrorFaceLookingBackSide then local ptMirrorFaceCenter = EgtSurfTmFacetCenter( ProcMirror.Id, nMirrorFaceLookingBackSide, GDB_ID.ROOT) local dMirrorSideDist = abs( ptMirrorFaceCenter:getY() - b3Raw:getMax():getY()) bIsMirrorFeatureOnEdgeOrPocket = bIsMirrorFeatureFacingBackSide and ( dMirrorSideDist < dMaxDist) end -- box delle stesse dimensioni local bIsMirrorFeatureSameDimension = false local b3Proc = EgtGetBBoxGlob( Proc.Id, GDB_BB.STANDARD) local b3ProcMirror = EgtGetBBoxGlob( ProcMirror.Id, GDB_BB.STANDARD) bIsMirrorFeatureSameDimension = abs( b3Proc:getDimX() - b3ProcMirror:getDimX()) < ( WD.DOUBLE_HEAD_POCKET_TOLERANCE or 0.5) and abs( b3Proc:getDimY() - b3ProcMirror:getDimY()) < ( WD.DOUBLE_HEAD_POCKET_TOLERANCE or 0.5) and abs( b3Proc:getDimZ() - b3ProcMirror:getDimZ()) < ( WD.DOUBLE_HEAD_POCKET_TOLERANCE or 0.5) -- box allineati in X local bIsMirrorBoxXAligned = abs( Proc.Box:getCenter():getX() - ProcMirror.Box:getCenter():getX()) < WD.DOUBLE_HEAD_POCKET_TOLERANCE or 0.5 -- box che non si intersecano local bIsNotMirrorBoxOverlapping = not OverlapsXY( b3Proc, b3ProcMirror) -- distanza minima tra le feature local dYMinDistance = max( b3Proc:getMin():getY(), b3ProcMirror:getMin():getY()) - min( b3Proc:getMax():getY(), b3ProcMirror:getMax():getY()) local bIsMirrorFeatureDistanceOk = dYMinDistance > dMinimumDistanceMirroredFeatures + 10 * GEO.EPS_SMALL -- se tutte vere le condizioni, calcolo i parametri da passare alle lavorazioni if bIsMirrorFeatureFacingBackSide and bIsMirrorFeatureOnEdgeOrPocket and bIsMirrorFeatureSameDimension and bIsMirrorBoxXAligned and bIsNotMirrorBoxOverlapping and bIsMirrorFeatureDistanceOk then nMirrorId = ProcMirror.Id local b3Tab = EgtGetTableArea() local ptOnMirrorAx = ( Proc.Box:getCenter() + ProcMirror.Box:getCenter()) / 2 dYMirrorAx = ptOnMirrorAx:getY() - b3Tab:getMin():getY() dDeltaZ = ProcMirror.Box:getMax():getZ() - Proc.Box:getMax():getZ() bIsMirrorTowardsBottom = ProcMirror.AffectedFaces.Bottom end end end -- se ho trovato una feature mirror e le condizioni precedenti sono soddisfatte, posso scrivere i parametri nella lavorazione if nMirrorId and bIsFeatureOnEdgeOrPocket then -- 2: specchiatura in Y Proc.Double = 2 Proc.MirrorId = nMirrorId -- posizione Y dell'asse di specchiatura Proc.MirrorAx = dYMirrorAx -- Offset Z tra le feature Proc.MirrorDeltaZ = dDeltaZ -- se sono groove cieche e la principale guarda su e l'altra guarda giù, la principale va trattata come sidegroove in accordo con la seconda if ( Proc.TopologyLongName == 'Groove-Blind-RightAngles-Parallel-3' or Proc.TopologyLongName == 'Groove-Blind-RightAngles-Parallel-4') and Proc.AffectedFaces.Top and bIsMirrorTowardsBottom then Proc.Stype = 2 end end -- le groove non sul fianco e rivolte verso Z+ vanno raccolte, ordinate e accoppiate a 2 a 2 per il doppio elseif WD.DOUBLE_HEAD_POCKET and ( ( Proc.TopologyLongName == 'Groove-Through-RightAngles-Parallel-3' and Proc.AffectedFaces.Top and Proc.AffectedFaces.Left and Proc.AffectedFaces.Right) or ( Proc.TopologyLongName == 'Groove-Blind-RightAngles-Parallel-4' and Proc.AffectedFaces.Top and ( Proc.AffectedFaces.Left or Proc.AffectedFaces.Right)) or ( Proc.TopologyLongName == 'Tunnel-Blind-RightAngles-Parallel-5' and Proc.AffectedFaces.Top) ) then table.insert( vGroovesThrough, Proc) -- i fori verticali e aperti verso Z+ vanno raccolti, ordinati e accoppiati a 2 a 2 per il doppio a parità di X elseif WD.DOUBLE_HEAD_DRILLING and Proc.TopologyLongName == 'DRILLING' then -- recupero e verifico la geometria del foro local AuxId = EgtGetInfo( Proc.Id, 'AUXID', 'i') or 0 if AuxId then AuxId = AuxId + Proc.Id end if not AuxId or EgtGetType( AuxId) ~= GDB_TY.CRV_ARC then return false end local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) if Proc.AffectedFaces.Top and AreSameOrOppositeVectorApprox( vtExtr, Z_AX()) then table.insert( vDrillings, Proc) end end end end -- ordinamento delle feature che vanno accoppiate -- groove verso Z+ table.sort( vGroovesThrough, SortFeaturesForMirror) -- forature verso Z+ table.sort( vDrillings, SortFeaturesForMirror) -- accoppio le groove passanti rivolte verso Z+ local nCurrentGroove = 1 while nCurrentGroove <= #vGroovesThrough do local Proc = vGroovesThrough[nCurrentGroove] if Proc.Flg ~= 0 then local b3Proc = EgtGetBBoxGlob( Proc.Id, GDB_BB.STANDARD) local nCurrentMirrorGroove = nCurrentGroove + 1 while nCurrentMirrorGroove <= #vGroovesThrough do local ProcMirror = vGroovesThrough[nCurrentMirrorGroove] local b3ProcMirror = EgtGetBBoxGlob( ProcMirror.Id, GDB_BB.STANDARD) -- feature non disattivata e diversa da nCurrentGroove local bIsMirrorIdOk = ( Proc.Id ~= ProcMirror.Id and ProcMirror.Flg ~= 0) -- box delle stesse dimensioni local bIsMirrorFeatureSameDimension = false bIsMirrorFeatureSameDimension = abs( b3Proc:getDimX() - b3ProcMirror:getDimX()) < ( WD.DOUBLE_HEAD_POCKET_TOLERANCE or 0.5) and abs( b3Proc:getDimY() - b3ProcMirror:getDimY()) < ( WD.DOUBLE_HEAD_POCKET_TOLERANCE or 0.5) and abs( b3Proc:getDimZ() - b3ProcMirror:getDimZ()) < ( WD.DOUBLE_HEAD_POCKET_TOLERANCE or 0.5) -- box allineati in X local bIsMirrorBoxXAligned = abs( Proc.Box:getCenter():getX() - ProcMirror.Box:getCenter():getX()) < ( WD.DOUBLE_HEAD_POCKET_TOLERANCE or 0.5) -- box che non si intersecano local bIsNotMirrorBoxOverlapping = not OverlapsXY( b3Proc, b3ProcMirror) -- distanza minima tra le feature local dYMinDistance = max( b3Proc:getMin():getY(), b3ProcMirror:getMin():getY()) - min( b3Proc:getMax():getY(), b3ProcMirror:getMax():getY()) local bIsMirrorFeatureDistanceOk = dYMinDistance > dMinimumDistanceMirroredFeatures + 10 * GEO.EPS_SMALL -- se tutte vere le condizioni, calcolo i parametri da passare alle lavorazioni if bIsMirrorIdOk and bIsMirrorFeatureSameDimension and bIsMirrorBoxXAligned and bIsNotMirrorBoxOverlapping and bIsMirrorFeatureDistanceOk then local dYMirrorAx local b3Tab = EgtGetTableArea() local ptOnMirrorAx = ( Proc.Box:getCenter() + ProcMirror.Box:getCenter()) / 2 dYMirrorAx = ptOnMirrorAx:getY() - b3Tab:getMin():getY() -- scrivo i parametri nella lavorazione -- 2: specchiatura in Y Proc.Double = 2 Proc.MirrorId = ProcMirror.Id -- posizione Y dell'asse di specchiatura Proc.MirrorAx = dYMirrorAx -- rimuovo dalla lista le groove già assegnate local ProcMirrorOldId = ProcMirror.Id table.remove( vGroovesThrough, nCurrentGroove) -- avendo rimosso un elemento dall'array, potrebbe essere cambiato l'elemento nCurrentMirrorGroove if nCurrentMirrorGroove > #vGroovesThrough or ( vGroovesThrough[nCurrentMirrorGroove].Id ~= ProcMirrorOldId) then nCurrentMirrorGroove = nCurrentMirrorGroove - 1 end table.remove( vGroovesThrough, nCurrentMirrorGroove) nCurrentGroove = 0 break end nCurrentMirrorGroove = nCurrentMirrorGroove + 1 end end nCurrentGroove = nCurrentGroove + 1 end -- accoppio le forature local nCurrentDrilling = 1 while nCurrentDrilling <= #vDrillings do local Proc = vDrillings[nCurrentDrilling] if Proc.Flg ~= 0 then local nCurrentMirrorDrilling = nCurrentDrilling + 1 local b3Proc = EgtGetBBoxGlob( Proc.Id, GDB_BB.STANDARD) while nCurrentMirrorDrilling <= #vDrillings do local ProcMirror = vDrillings[nCurrentMirrorDrilling] local b3ProcMirror = EgtGetBBoxGlob( ProcMirror.Id, GDB_BB.STANDARD) -- feature non disattivata e diversa da nCurrentDrilling local bIsMirrorIdOk = ( Proc.Id ~= ProcMirror.Id and ProcMirror.Flg ~= 0) -- box delle stesse dimensioni local bIsMirrorFeatureSameDimension = false bIsMirrorFeatureSameDimension = abs( b3Proc:getDimX() - b3ProcMirror:getDimX()) < ( WD.DOUBLE_HEAD_DRILLING_TOLERANCE or 0.1) and abs( b3Proc:getDimY() - b3ProcMirror:getDimY()) < ( WD.DOUBLE_HEAD_DRILLING_TOLERANCE or 0.1) and abs( b3Proc:getDimZ() - b3ProcMirror:getDimZ()) < ( WD.DOUBLE_HEAD_DRILLING_TOLERANCE or 0.1) -- box allineati in X local bIsMirrorBoxXAligned = abs( Proc.Box:getCenter():getX() - ProcMirror.Box:getCenter():getX()) < ( WD.DOUBLE_HEAD_DRILLING_TOLERANCE or 0.1) -- box che non si intersecano local bIsNotMirrorBoxOverlapping = not OverlapsXY( b3Proc, b3ProcMirror) -- distanza minima tra le feature local dYMinDistance = max( b3Proc:getMin():getY(), b3ProcMirror:getMin():getY()) - min( b3Proc:getMax():getY(), b3ProcMirror:getMax():getY()) local bIsMirrorFeatureDistanceOk = dYMinDistance > dMinimumDistanceMirroredFeatures + 10 * GEO.EPS_SMALL -- se tutte vere le condizioni, calcolo i parametri da passare alle lavorazioni if bIsMirrorIdOk and bIsMirrorFeatureSameDimension and bIsMirrorBoxXAligned and bIsNotMirrorBoxOverlapping and bIsMirrorFeatureDistanceOk then local dYMirrorAx local b3Tab = EgtGetTableArea() local ptOnMirrorAx = ( Proc.Box:getCenter() + ProcMirror.Box:getCenter()) / 2 dYMirrorAx = ptOnMirrorAx:getY() - b3Tab:getMin():getY() -- scrivo i parametri nella lavorazione -- 2: specchiatura in Y Proc.Double = 2 Proc.MirrorId = ProcMirror.Id -- posizione Y dell'asse di specchiatura Proc.MirrorAx = dYMirrorAx -- rimuovo dalla lista le groove già assegnate local ProcMirrorOldId = ProcMirror.Id table.remove( vDrillings, nCurrentDrilling) -- avendo rimosso un elemento dall'array, potrebbe essere cambiato l'elemento nCurrentMirrorDrilling if nCurrentMirrorDrilling > #vDrillings or ( vDrillings[nCurrentMirrorDrilling].Id ~= ProcMirrorOldId) then nCurrentMirrorDrilling = nCurrentMirrorDrilling - 1 end table.remove( vDrillings, nCurrentMirrorDrilling) nCurrentDrilling = 0 break end nCurrentMirrorDrilling = nCurrentMirrorDrilling + 1 end end nCurrentDrilling = nCurrentDrilling + 1 end end ------------------------------------------------------------------------------------------------------------- function WallExec.ProcessFeatures() -- errori e stato local nTotErr = 0 local Stats = {} -- recupero il grezzo e il suo box local nRawId = EgtGetFirstRawPart() local b3Raw = EgtGetRawPartBBox( nRawId) -- raccolgo l'elenco dei pezzi local vPart = {} local nPartId = EgtGetFirstPartInRawPart( nRawId) while nPartId do local Ls = EgtGetFirstNameInGroup( nPartId, 'Box') local b3Solid = EgtGetBBoxGlob( Ls or GDB_ID.NULL, GDB_BB.STANDARD) table.insert( vPart, {Id=nPartId, Box=b3Solid}) nPartId = EgtGetNextPartInRawPart( nPartId) end -- raccolgo l'elenco delle feature da lavorare, ciclando sui pezzi local vProc = {} for i = 1, #vPart do -- recupero le feature di lavorazione della parete local vPartProc = WallExec.CollectFeatures( vPart[i].Id, b3Raw) vProc = EgtJoinTables( vProc, vPartProc) end -- classifico topologicamente le feature ClassifyTopology( vProc) -- classifico le feature ClassifyFeatures( vProc, b3Raw) -- Eventuale determinazione delle feature lavorabili in parallelo (implementata nella configurazione macchina) -- si impostano i flag Double (nil/0=no, 1=su X, 2=su Y) e Delta (offset tra T14 e T12 positivo o negativo) if WD.FindFeaturesInDouble then WD.FindFeaturesInDouble( vProc, b3Raw) end SetMirroredFeatures( vProc, b3Raw) -- debug if EgtGetDebugLevel() >= 1 then PrintFeatures( vProc) end EgtOutLog( ' *** AddMachinings ***', 1) -- inserisco le lavorazioni for i = 1, #vProc do -- creo la lavorazione local Proc = vProc[i] if Proc.Flg ~= 0 then local bOk, sMsg = AddFeatureMachining( Proc, nRawId, b3Raw) if not bOk then nTotErr = nTotErr + 1 table.insert( Stats, {Err=1, Msg=sMsg, Rot=0, CutId=Proc.CutId, TaskId=Proc.TaskId}) elseif sMsg and #sMsg > 0 then table.insert( Stats, {Err=-1, Msg=sMsg, Rot=0, CutId=Proc.CutId, TaskId=Proc.TaskId}) else table.insert( Stats, {Err=0, Msg='', Rot=0, CutId=Proc.CutId, TaskId=Proc.TaskId}) end elseif not Proc.Double then local sMsg = 'Feature not machinable by orientation' table.insert( Stats, {Err=1, Msg=sMsg, Rot=0, CutId=Proc.CutId, TaskId=Proc.TaskId}) end end EgtOutLog( ' *** End AddMachinings ***', 1) ------- -- LAVORAZIONI IN DOPPIO - QUI INSERIRE: -- ELIMINAZIONE LAVORAZIONI MIRROR IN BASE A SETTAGGIO MACHININGTODELETE IN PROC -- VERIFICA E UPDATE NOTE PER LAVORAZIONI IN CUI SI CONTROLLA SE I PERCORSI SONO SPECCHIATI ------- -- setto quali sono le lavorazioni da disattivare perchè specchiate di lavorazioni in doppio local vProcToDisable = {} for i = 1, #vProc do local Proc = vProc[i] if Proc.Double and Proc.Double > 0 then for j = 1, #vProc do local ProcMirror = vProc[j] if Proc.MirrorId == ProcMirror.Id then -- per i fori l'operazione si basa sulla geometria ausiliaria if Proc.TopologyLongName == 'DRILLING' then local AuxId = EgtGetInfo( ProcMirror.Id, 'AUXID', 'i') or 0 if AuxId then AuxId = AuxId + ProcMirror.Id end table.insert( vProcToDisable, AuxId) -- per tutte le altre lavorazioni si usa la geometria della feature else table.insert( vProcToDisable, ProcMirror.Id) end end end end end -- cancello le operazioni legate a lavorazioni specchiate local nOperId = EgtGetNextOperation( EgtGetPhaseDisposition( 1)) while nOperId do EgtSetCurrMachining( nOperId) local nOperationProcIds = EgtGetMachiningGeometry() local nOperationProcId = nOperationProcIds[1][1] local nCurrentOperId = nOperId for i = 1, #vProcToDisable do local ProcId = vProcToDisable[i] if nOperationProcId == ProcId then nOperId = EgtGetNextOperation( nOperId) EgtRemoveOperation(nCurrentOperId) break end end if nCurrentOperId == nOperId then nOperId = EgtGetNextOperation( nOperId) end end -- se macchina pareti if not WD.BEAM_MACHINE then -- riordino le lavorazioni tra tutti i pezzi local nPhase = 1 local PrevMch = EgtGetPhaseDisposition( nPhase) -- abilitazione ordinamento con priorità da btl: 0 = no, 1 = ordine crescente, 2 = ordine decrescente -- le lavorazioni con priorità 0 o senza priorità saranno lasciate per ultime local nGetPriorityFromBtl = WD.BTL_PRIORITY or 0 if nGetPriorityFromBtl > 0 then local vPriority = {} local nOperId = EgtGetNextOperation( PrevMch) local nCurrentPriorityId = 1 while nOperId do local nPriority = EgtGetInfo( nOperId or GDB_ID.NULL, 'PRIORITY', 'i') if nPriority and nPriority ~= 0 then vPriority[nCurrentPriorityId] = nPriority nCurrentPriorityId = nCurrentPriorityId + 1 end nOperId = EgtGetNextOperation( nOperId) end -- sorting delle priorità -- ordine crescente if nGetPriorityFromBtl == 1 then table.sort( vPriority) -- ordine decrescente else table.sort( vPriority, function( a, b) return a > b end) end -- riordino le lavorazioni per priorità for i = 1, #vPriority do if i == 1 or ( vPriority[i] ~= vPriority[i - 1]) then PrevMch = SortMachinings( nPhase, PrevMch, nil, vPriority[i]) end end end -- ordinamento standard SortMachinings( nPhase, PrevMch) -- Aggiornamento finale di tutto if nGetPriorityFromBtl > 0 then InsertScrapRemoval( nPhase) end EgtSetCurrPhase( 1) EgtApplyAllMachinings() -- altrimenti macchina travi else -- dichiaro lavorazione pareti EgtSetInfo( EgtGetCurrMachGroup() or GDB_ID.NULL, 'Wall', '1') -- ordino i pezzi secondo le X decrescenti local function CompareParts( P1, P2) return P1.Box:getCenter():getX() > P2.Box:getCenter():getX() end table.sort( vPart, CompareParts) -- riordino le lavorazioni sui singoli pezzi local nPhase = 1 local PrevMch = EgtGetPhaseDisposition( nPhase) for i = 1, #vPart do PrevMch = SortMachinings( nPhase, PrevMch, vPart[i].Id) end -- aggiungo dati su prima disposizione local nDispId = EgtGetPhaseDisposition( 1) EgtSetInfo( nDispId, 'TYPE', 'START') EgtSetInfo( nDispId, 'ORD', 1) -- aggiungo flag su ultima lavorazione local nLastMchId = EgtGetLastActiveOperation() EgtSetCurrMachining( nLastMchId) EgtSetMachiningParam( MCH_MP.USERNOTES, 'Cut;') -- aggiungo disposizione per lo scarico EgtAddPhase() local nRawId = EgtGetFirstRawPart() EgtKeepRawPart( nRawId, 1) local nDisp2Id = EgtGetPhaseDisposition( 2) EgtSetInfo( nDisp2Id, 'TYPE', 'END') EgtSetInfo( nDisp2Id, 'ORD', 1) -- Aggiornamento finale di tutto EgtSetCurrPhase( 1) local bApplOk, sApplErrors, sApplWarns = EgtApplyAllMachinings() if not bApplOk then nTotErr = nTotErr + 1 table.insert( Stats, {Err = 1, Msg=sApplErrors, Rot=0, CutId=0, TaskId=0}) elseif sApplWarns and #sApplWarns > 0 then -- non interessano perchè riguardano lo scarico delle travi end end -- restituzione risultati return ( nTotErr == 0), Stats end ------------------------------------------------------------------------------------------------------------- return WallExec