diff --git a/LuaLibs/WProcessDrill.lua b/LuaLibs/WProcessDrill.lua index 3e45f7a..bd01bb7 100644 --- a/LuaLibs/WProcessDrill.lua +++ b/LuaLibs/WProcessDrill.lua @@ -137,7 +137,7 @@ function WPD.RotateClassify( Proc) local vtExtr = EgtCurveExtrusion( AuxId, GDB_RT.GLOB) local ptCen = EgtCP( AuxId, GDB_RT.GLOB) -- se foro orizzontale con punta lunga - if dDiam <= WD.HOR_DRILL_DIAM + WD.DRILL_TOL and dDiam >= WD.HOR_DRILL_DIAM - WD.DRILL_TOL and vtExtr:getZ() > -0.1 and vtExtr:getZ() < 0.1 then + if dDiam <= ( WD.HOR_DRILL_DIAM or 35) + WD.DRILL_TOL and dDiam >= ( WD.HOR_DRILL_DIAM or 35) - WD.DRILL_TOL and vtExtr:getZ() > -0.1 and vtExtr:getZ() < 0.1 then -- se orientato perpendicolare ad X if AreSameOrOppositeVectorApprox( vtExtr, X_AX()) then nRot0 = 0 diff --git a/NestFlipAndRotate.lua b/NestFlipAndRotate.lua index a19c747..45be4a1 100644 --- a/NestFlipAndRotate.lua +++ b/NestFlipAndRotate.lua @@ -56,21 +56,22 @@ local Text = require( 'WProcessText') -- Carico i dati globali local WD = require( 'WallData') +------------------------------------------------------------------- local function ClassifyFlip( vPartProc, b3Part) local FlipFeatureStates = {} local bLapJoints = false for nInd = 1, #vPartProc do - if LapJoint.Identify( vPartProc[nInd]) then + if LapJoint.Identify( vPartProc[nInd]) then -- setto parametro Q if vPartProc[nInd].Prc == 30 then EgtSetInfo( vPartProc[nInd].Id, "Q08", 1) - EgtSetInfo( vPartProc[nInd].Id, "Q08A", 1) + EgtSetInfo( vPartProc[nInd].Id, "Q08A", 1) else EgtSetInfo( vPartProc[nInd].Id, "Q03", 1) - EgtSetInfo( vPartProc[nInd].Id, "Q03A", 1) - end + EgtSetInfo( vPartProc[nInd].Id, "Q03A", 1) + end bLapJoints = true local nFlip0, nFlip1 = LapJoint.FlipClassify(vPartProc[nInd]) if nFlip0 and nFlip1 and nFlip0 ~= nFlip1 then @@ -80,7 +81,7 @@ local function ClassifyFlip( vPartProc, b3Part) local nFlip0, nFlip1 = Drill.FlipClassify(vPartProc[nInd], b3Part) if nFlip0 and nFlip1 and nFlip0 ~= nFlip1 then table.insert( FlipFeatureStates, { Flip0 = nFlip0, Flip1 = nFlip1}) - end + end elseif Cut.Identify( vPartProc[nInd]) then local nFlip0, nFlip1 = Cut.FlipClassify(vPartProc[nInd], b3Part) if nFlip0 and nFlip1 and nFlip0 ~= nFlip1 then @@ -90,7 +91,7 @@ local function ClassifyFlip( vPartProc, b3Part) -- setto parametro Q if vPartProc[nInd].Prc == 12 then EgtSetInfo( vPartProc[nInd].Id, "Q02", 1) - EgtSetInfo( vPartProc[nInd].Id, "Q02A", 1) + EgtSetInfo( vPartProc[nInd].Id, "Q02A", 1) end local nFlip0, nFlip1 = DoubleCut.FlipClassify(vPartProc[nInd], b3Part) if nFlip0 and nFlip1 and nFlip0 ~= nFlip1 then @@ -100,7 +101,7 @@ local function ClassifyFlip( vPartProc, b3Part) local nFlip0, nFlip1 = SawCut.FlipClassify(vPartProc[nInd], b3Part) if nFlip0 and nFlip1 and nFlip0 ~= nFlip1 then table.insert( FlipFeatureStates, { Flip0 = nFlip0, Flip1 = nFlip1}) - end + end elseif FreeContour.Identify( vPartProc[nInd]) then local nFlip0, nFlip1 = FreeContour.FlipClassify(vPartProc[nInd], b3Part) if nFlip0 and nFlip1 and nFlip0 ~= nFlip1 then @@ -120,19 +121,19 @@ local function ClassifyFlip( vPartProc, b3Part) local nFlip0, nFlip1 = Mark.FlipClassify(vPartProc[nInd], b3Part) if nFlip0 and nFlip1 and nFlip0 ~= nFlip1 then table.insert( FlipFeatureStates, { Flip0 = nFlip0, Flip1 = nFlip1}) - end + end elseif Text.Identify( vPartProc[nInd]) then local nFlip0, nFlip1 = Text.FlipClassify(vPartProc[nInd], b3Part) if nFlip0 and nFlip1 and nFlip0 ~= nFlip1 then table.insert( FlipFeatureStates, { Flip0 = nFlip0, Flip1 = nFlip1}) - end + end end end - - return FlipFeatureStates, bLapJoints + + return FlipFeatureStates, bLapJoints end - +------------------------------------------------------------------- local function ClassifyRotation( vPartProc) local RotateFeatureStates = {} @@ -144,22 +145,21 @@ local function ClassifyRotation( vPartProc) end end end - - return RotateFeatureStates + return RotateFeatureStates end ---- - +------------------------------------------------------------------- +------------------------------------------------------------------- local vPartProc = WE.CollectFeatures( NFAR.PARTID) local b3Part = EgtGetBBoxGlob( NFAR.PARTID, GDB_BB.STANDARD) local bManualFlip = EgtGetInfo( NFAR.PARTID, "MANUALFLIP", 'b') local bManualRot = EgtGetInfo( NFAR.PARTID, "MANUALROT", 'b') - --- FLIP + +-- FLIP local FlipFeatureStates, bLapJoints = ClassifyFlip( vPartProc, b3Part) -if not bManualFlip then - local bFlip +if not bManualFlip then + local bFlip -- analizzo stati flip delle feature local nFlip0Min = 100 local nFlip0Cnt = 0 @@ -187,16 +187,16 @@ if not bManualFlip then elseif nFlip0Cnt < nFlip1Cnt then bFlip = false elseif bLapJoints then - -- se equivalenti ma ci sono lap joints, fisso il flip per non avere problemi con le aree di lavorazione nel nesting - bFlip = false + -- se equivalenti ma ci sono lap joints, fisso il flip per non avere problemi con le aree di lavorazione nel nesting + bFlip = false end elseif nFlip0Min < nFlip1Min then bFlip = true else - bFlip = false + bFlip = false end - if bFlip ~= nil then + if bFlip ~= nil then -- se una posizione è più conveniente dell'altra setto info nel pezzo EgtSetInfo( NFAR.PARTID, "NestAllowFlip", false) EgtSetInfo( NFAR.PARTID, "NestFlip", bFlip) @@ -206,10 +206,10 @@ if not bManualFlip then if bFlip then -- flip pezzo - EgtRotate( NFAR.PARTID, b3Part:getCenter(), X_AX(), 180, GDB_RT.GLOB) + EgtRotate( NFAR.PARTID, b3Part:getCenter(), X_AX(), 180, GDB_RT.GLOB) -- modifico le info del pezzo local nPartFlip = EgtGetInfo( NFAR.PARTID, "INVERTED", 'i') or 0 - local nTotFlip = EgtIf( nPartFlip == 180, 0, 180) + local nTotFlip = EgtIf( nPartFlip == 180, 0, 180) EgtSetInfo( NFAR.PARTID, "INVERTED", nTotFlip) EgtSetInfo( NFAR.PARTID, "FLIPROTMODIFIED", 1) end @@ -217,12 +217,12 @@ end -- rimuovo parametri Q local b3PartInside = BBox3d( b3Part) -b3PartInside:expand( - WD.INSIDE_RAW_TOL) -for nInd = 1, #vPartProc do +b3PartInside:expand( - ( WD.INSIDE_RAW_TOL or 30)) +for nInd = 1, #vPartProc do local Proc = vPartProc[nInd] - if LapJoint.Identify( Proc) then - -- cerco la faccia rivolta verso l'alto e la faccia rivolta verso il basso + if LapJoint.Identify( Proc) then + -- cerco la faccia rivolta verso l'alto e la faccia rivolta verso il basso local nFaceInd = -1 local nFaceDownInd = -1 for nIdx = 0, Proc.Fct - 1 do @@ -231,8 +231,8 @@ for nInd = 1, #vPartProc do nFaceInd = nIdx elseif vtN:getZ() < - 0.95 then nFaceDownInd = nIdx - end - end + end + end -- se è lap joint dall'alto if nFaceInd ~= -1 and nFaceDownInd == -1 then local ptCen = EgtSurfTmFacetCenter( Proc.Id, nFaceInd, GDB_ID.ROOT) @@ -241,11 +241,11 @@ for nInd = 1, #vPartProc do -- resetto parametro Q if Proc.Prc == 30 then EgtRemoveInfo( Proc.Id, "Q08") - EgtRemoveInfo( Proc.Id, "Q08A") + EgtRemoveInfo( Proc.Id, "Q08A") else EgtRemoveInfo( Proc.Id, "Q03") - EgtRemoveInfo( Proc.Id, "Q03A") - end + EgtRemoveInfo( Proc.Id, "Q03A") + end end end @@ -264,21 +264,22 @@ for nInd = 1, #vPartProc do -- resetto parametro Q if Proc.Prc == 12 then EgtRemoveInfo( Proc.Id, "Q02") - EgtRemoveInfo( Proc.Id, "Q02A") + EgtRemoveInfo( Proc.Id, "Q02A") end end end - end - end -end - - + end + end +end + + -- ROTATION -nRotate = 0 +nRotate = 0 + -- venatura EgtRemoveInfo( NFAR.PARTID, "HasGrainDirection") local bGrain = false -local sGrainInfo = EgtGetInfo( NFAR.PARTID, "GRAINDIRECTION", 's') +local sGrainInfo = EgtGetInfo( NFAR.PARTID, "GRAINDIRECTION", 's') if sGrainInfo then local sGrainAlign = string.sub( sGrainInfo, 7) local sGrainDir = string.sub( sGrainInfo, 1, 5) @@ -286,21 +287,21 @@ if sGrainInfo then EgtSetInfo( NFAR.PARTID, "HasGrainDirection", 1) bGrain = true -- trovo la rotazione ( a meno di 180°) che deve avere il pezzo per essere allineato con la venatura del grezzo - local nGrainRot = 0 + local nGrainRot = 0 if ( sGrainDir == "1,0,0" and not NFAR.RAW_GRAIN_DIR_X) or ( sGrainDir == "0,1,0" and NFAR.RAW_GRAIN_DIR_X) then - nGrainRot = 90 + nGrainRot = 90 end local nPartRot = EgtGetInfo( NFAR.PARTID, "ROTATED", 'i') or 0 if ( nGrainRot == 0 and ( nPartRot == 90 or nPartRot == 270)) or ( nGrainRot == 90 and ( nPartRot == 0 or nPartRot == 180)) then - local b3Part = EgtGetBBoxGlob( NFAR.PARTID, GDB_BB.STANDARD) + local b3Part = EgtGetBBoxGlob( NFAR.PARTID, GDB_BB.STANDARD) EgtRotate( NFAR.PARTID, b3Part:getCenter(), Z_AX(), 90, GDB_RT.GLOB) nRotate = 90 - end + end end -end +end -if not bManualRot then +if not bManualRot then local RotateFeatureStates = ClassifyRotation( vPartProc) @@ -346,7 +347,7 @@ if not bManualRot then { Rot = 90, Score = nRot90Min, ScoreCnt = nRot90Cnt}, { Rot = 180, Score = nRot180Min, ScoreCnt = nRot180Cnt}, { Rot = 270, Score = nRot270Min, ScoreCnt = nRot270Cnt}} - local nRotateOpt = 0 + local nRotateOpt = 0 if #RotateFeatureStates > 0 then -- calcolo lato con punteggio minore o molteplicita' piu' alta local nRotMax = MinList[1].Rot @@ -359,7 +360,7 @@ if not bManualRot then nScoreCnt = MinList[nInd].ScoreCnt elseif MinList[nInd].Score == nScoreMax then -- se punteggio > 0 conservo quello con molteplicità più alta, se punteggio = 0 conservo quello con molteplicità più bassa - if ( nScoreMax ~= 0 and MinList[nInd].ScoreCnt > nScoreCnt) or ( nScoreMax == 0 and MinList[nInd].ScoreCnt < nScoreCnt) then + if ( nScoreMax ~= 0 and MinList[nInd].ScoreCnt > nScoreCnt) or ( nScoreMax == 0 and MinList[nInd].ScoreCnt < nScoreCnt) then nRotMax = MinList[nInd].Rot nScoreMax = MinList[nInd].Score nScoreCnt = MinList[nInd].ScoreCnt @@ -369,7 +370,7 @@ if not bManualRot then nRotateOpt = nRotMax else nRotateOpt = 0 - end + end local bRotNest = false local nStepRotNest = 0 @@ -387,40 +388,40 @@ if not bManualRot then -- altrimenti permetto tutto bRotNest = true nStepRotNest = 90 - end + end -- verifico se ci sono fori lungo Y che bloccano la rotazione - local bDrillOnY = ( nStepRotNest == 180) + local bDrillOnY = ( nStepRotNest == 180) - local b3Part = EgtGetBBoxGlob( NFAR.PARTID, GDB_BB.STANDARD) + local b3Part = EgtGetBBoxGlob( NFAR.PARTID, GDB_BB.STANDARD) - if bGrain then - -- se venatura eseguo rotazione solo se è di 180° - if nRotateOpt == 180 then - EgtRotate( NFAR.PARTID, b3Part:getCenter(), Z_AX(), nRotateOpt, GDB_RT.GLOB) + if bGrain then + -- se venatura eseguo rotazione solo se è di 180° + if nRotateOpt == 180 then + EgtRotate( NFAR.PARTID, b3Part:getCenter(), Z_AX(), nRotateOpt, GDB_RT.GLOB) nRotate = nRotate + nRotateOpt - end - nStepRotNest = 180 + end + nStepRotNest = 180 else -- eseguo rotazione EgtRotate( NFAR.PARTID, b3Part:getCenter(), Z_AX(), nRotateOpt, GDB_RT.GLOB) nRotate = nRotate + nRotateOpt end - -- verifico se rotazione è valida ( pezzo contenuto nel grezzo) solo se no venatura - if not bGrain then - b3Part = EgtGetBBoxGlob( NFAR.PARTID, GDB_BB.STANDARD) + -- verifico se rotazione è valida ( pezzo contenuto nel grezzo) solo se no venatura + if not bGrain then + b3Part = EgtGetBBoxGlob( NFAR.PARTID, GDB_BB.STANDARD) local bValidRotationForRaw = b3Part:getDimX() < WD.MAX_LENGTH and b3Part:getDimY() < WD.MAX_WIDTH local bRotatedIsValid = b3Part:getDimY() < WD.MAX_LENGTH and b3Part:getDimX() < WD.MAX_WIDTH if not bValidRotationForRaw and bRotatedIsValid then EgtRotate( NFAR.PARTID, b3Part:getCenter(), Z_AX(), 90, GDB_RT.GLOB) - nRotate = nRotate + 90 - nStepRotNest = 180 + nRotate = nRotate + 90 + nStepRotNest = 180 end end -- se no venatura e non ci sono fori verifico se il pezzo cade - if not bGrain and not bDrillOnY then + if not bGrain and not bDrillOnY then b3Part = EgtGetBBoxGlob( NFAR.PARTID, GDB_BB.STANDARD) local bValidRotation = b3Part:getDimX() > ( WD.INTRULLI or 1200) -- verifico se ruotata resta valida @@ -428,22 +429,22 @@ if not bManualRot then -- se non è valida ma ruotato lo sarebbe, ruoto if not bValidRotation and bRotatedIsValid and nStepRotNest ~= 180 then EgtRotate( NFAR.PARTID, b3Part:getCenter(), Z_AX(), 90, GDB_RT.GLOB) - nRotate = nRotate + 90 - nStepRotNest = 180 + nRotate = nRotate + 90 + nStepRotNest = 180 elseif bValidRotation and not bRotatedIsValid then -- se fosse valida ma la sua ruotata no, allora blocco lo step nella rotazione del nesting - nStepRotNest = 180 - end + nStepRotNest = 180 + end end - -- setto info nel pezzo + -- setto info nel pezzo if nRotate > 0 then local nPartRot = EgtGetInfo( NFAR.PARTID, "ROTATED", 'i') or 0 local nTotRot = nPartRot - nRotate nTotRot = EgtIf( nTotRot < 0, nTotRot + 360, nTotRot) - EgtSetInfo( NFAR.PARTID, "ROTATED", nTotRot) + EgtSetInfo( NFAR.PARTID, "ROTATED", nTotRot) EgtSetInfo( NFAR.PARTID, "FLIPROTMODIFIED", 1) - end + end EgtSetInfo( NFAR.PARTID, "NestStepRot", nStepRotNest) EgtSetInfo( NFAR.PARTID, "NestRot", nRotate) @@ -451,4 +452,4 @@ if not bManualRot then end -NFAR.ERR = 0 \ No newline at end of file +NFAR.ERR = 0 \ No newline at end of file diff --git a/NestProcess.lua b/NestProcess.lua index 02c904b..d26cead 100644 --- a/NestProcess.lua +++ b/NestProcess.lua @@ -60,9 +60,21 @@ local FreeContour = require( 'WProcessFreeContour') -- Carico i dati globali local WD = require( 'WallData') +-- Recupero alcuni dati dal WallData o li setto a valori di default +local s_dSideMillDiamDown = WD.SIDEMILL_DIAM_DOWN or 350 +local s_dSideMillDiamUp = WD.SIDEMILL_DIAM_UP or 65 +local s_dHorDrillLen = WD.HOR_DRILL_LEN or 1780 +local s_dHorDrillDiam = WD.HOR_DRILL_DIAM or 35 +local s_sOrigCorner = WD.ORIG_CORNER or 'TL' +local s_dIntRulli = WD.INTRULLI or 1200 +local s_dMinRawYHorDrill = WD.MINRAWY_HOR_DRILL or 2800 +local s_dNestHoleMinArea = WD.NEST_HOLE_MIN_AREA or 200000 +local s_dInsideRawTol = WD.INSIDE_RAW_TOL or 30 + -- lista dei pezzi con flip o rotazione local PartStates = {} +------------------------------------------------------------------ -- Funzioni per scrittura su file di log specifico local function WriteErrToLogFile( nErr, sMsg, nRot, nCutId, nTaskId) local hFile = io.open( sLogFile, 'a') @@ -74,12 +86,14 @@ local function WriteErrToLogFile( nErr, sMsg, nRot, nCutId, nTaskId) hFile:close() end +------------------------------------------------------------------ local function WriteTimeToLogFile( dTime) local hFile = io.open( sLogFile, 'a') hFile:write( 'TIME=' .. EgtNumToString( dTime) .. '\n') hFile:close() end +------------------------------------------------------------------ -- Funzione per gestire visualizzazione dopo errore local function PostErrView( nErr, sMsg) if nErr ~= 0 and ( NEST.FLAG == 1 or NEST.FLAG == 2 or NEST.FLAG == 5) then @@ -89,6 +103,7 @@ local function PostErrView( nErr, sMsg) end end +------------------------------------------------------------------ -- Funzione per gestire visualizzazione dopo warning local function PostWarnView( nWarn, sMsg) if nWarn ~= 0 and ( NEST.FLAG == 1 or NEST.FLAG == 2 or NEST.FLAG == 5) then @@ -98,6 +113,7 @@ local function PostWarnView( nWarn, sMsg) end end +------------------------------------------------------------------ -- Funzione per aggiornare dati ausiliari local function UpdateAuxData( sAuxFile) local bModif = false @@ -111,6 +127,7 @@ local function UpdateAuxData( sAuxFile) return bModif end +------------------------------------------------------------------ -- Funzione per trovare nome MachGroup local function NewMachGroupName() local nMachGroupId = EgtGetFirstMachGroup() @@ -127,6 +144,7 @@ local function NewMachGroupName() return nMaxMachGroup + 1 end +------------------------------------------------------------------ -- Funzione che crea il rettangolo della lavorazione local function CreateToolRectangle( ptP1, dValP1, ptP2, dValP2, vtFace, dValFace, nOutlineGrp) local dExtra = 5 @@ -141,8 +159,9 @@ local function CreateToolRectangle( ptP1, dValP1, ptP2, dValP2, vtFace, dValFace return nId end +------------------------------------------------------------------ -- Funzione che verifica se la lavorazione è lap joint dal basso ed eventualmente ne calcola l'area di lavorazione -local function IdentifyLJFromBottom( Proc, bCompute, nOutlineGrp) +local function IdentifyLJFromBottom( Proc, bCompute, nOutlineGrp) local bLJFromBottom = false local nRectId @@ -155,20 +174,19 @@ local function IdentifyLJFromBottom( Proc, bCompute, nOutlineGrp) vtN[2] = EgtSurfTmFacetNormVersor( Proc.Id, 1, GDB_ID.ROOT) -- se rivolto verso il basso - if ( vtN[1]:getZ() < - dMinCompZ or vtN[2]:getZ() < - dMinCompZ) then - vtFace = EgtIf( vtN[1]:getZ() < - dMinCompZ, vtN[2], vtN[1]) + if ( vtN[1]:getZ() < - dMinCompZ or vtN[2]:getZ() < - dMinCompZ) then + vtFace = EgtIf( vtN[1]:getZ() < - dMinCompZ, vtN[2], vtN[1]) if not ( vtFace:getZ() > dMinCompZ or vtFace:getZ() < - dMinCompZ) then bLJFromBottom = true if bCompute then local bAdj, ptP1, ptP2, dAng = EgtSurfTmFacetsContact( Proc.Id, 0, 1, GDB_ID.ROOT) -- creo il rettangolo della lavorazione - nRectId = CreateToolRectangle( ptP1, WD.SIDEMILL_DIAM_DOWN / 2, ptP2, WD.SIDEMILL_DIAM_DOWN / 2, vtFace, WD.SIDEMILL_DIAM_DOWN, nOutlineGrp) + nRectId = CreateToolRectangle( ptP1, s_dSideMillDiamDown / 2, ptP2, s_dSideMillDiamDown / 2, vtFace, s_dSideMillDiamDown, nOutlineGrp) end end end - - - elseif Proc.Fct == 3 then + + elseif Proc.Fct == 3 then local nFacInd, dElev, nFacInd2 = WL.GetFaceWithMostAdj( Proc.Id, Proc.PartId) -- se nel mezzo di una faccia @@ -181,63 +199,63 @@ local function IdentifyLJFromBottom( Proc, bCompute, nOutlineGrp) if abs( ptP1:getZ() - ptP2:getZ()) < GEO.EPS_SMALL then bLJFromBottom = true if bCompute then - nRectId = CreateToolRectangle( ptP1, WD.SIDEMILL_DIAM_DOWN / 2, ptP2, WD.SIDEMILL_DIAM_DOWN / 2, vtFace, WD.SIDEMILL_DIAM_DOWN, nOutlineGrp) + nRectId = CreateToolRectangle( ptP1, s_dSideMillDiamDown / 2, ptP2, s_dSideMillDiamDown / 2, vtFace, s_dSideMillDiamDown, nOutlineGrp) end end end end - -- se dal basso + -- se dal basso else local nFaceZ = -1 for nIdx = 0, 2 do local vtN2 = EgtSurfTmFacetNormVersor( Proc.Id, nIdx, GDB_ID.ROOT) - if vtN2:getZ() < - dMinCompZ then + if vtN2:getZ() < - dMinCompZ then nFaceZ = nIdx - break - end + break + end end if nFaceZ ~= -1 then local nFace = EgtIf( nFaceZ == nFacInd, nFacInd2, nFacInd) - local nOtherFace = EgtIf( nFaceZ + nFace == 3, 0, EgtIf( nFaceZ + nFace == 2, 1, 2)) + local nOtherFace = EgtIf( nFaceZ + nFace == 3, 0, EgtIf( nFaceZ + nFace == 2, 1, 2)) vtFace = EgtSurfTmFacetNormVersor( Proc.Id, nFace, GDB_ID.ROOT) --vtFace[2] = EgtSurfTmFacetNormVersor( Proc.Id, nOtherFace, GDB_ID.ROOT) bLJFromBottom = true - if bCompute then + if bCompute then local bAdj, ptP1, ptP2 = EgtSurfTmFacetsContact( Proc.Id, nFace, nFaceZ, GDB_ID.ROOT) local bAdj2, ptP3, ptP4 = EgtSurfTmFacetsContact( Proc.Id, nFace, nOtherFace, GDB_ID.ROOT) if AreSamePointApprox( ptP2, ptP3) or AreSamePointApprox( ptP2, ptP4) then ptP1, ptP2 = ptP2, ptP1 end - local dVal = EgtIf( NEST.MACH_AREA_IGNORE_3rdFACE == 1, WD.SIDEMILL_DIAM_DOWN / 2, 0) - nRectId = CreateToolRectangle( ptP1, dVal, ptP2, WD.SIDEMILL_DIAM_DOWN / 2, vtFace, WD.SIDEMILL_DIAM_DOWN, nOutlineGrp) - end - end - end + local dVal = EgtIf( NEST.MACH_AREA_IGNORE_3rdFACE == 1, s_dSideMillDiamDown / 2, 0) + nRectId = CreateToolRectangle( ptP1, dVal, ptP2, s_dSideMillDiamDown / 2, vtFace, s_dSideMillDiamDown, nOutlineGrp) + end + end + end - elseif Proc.Fct == 4 then + elseif Proc.Fct == 4 then local nFacInd, dElev, nFacInd2, dElev2 = WL.GetFaceWithMostAdj( Proc.Id, Proc.PartId) - if nFacInd ~= -2 and nFacInd ~= GDB_ID.NULL then + if nFacInd ~= -2 and nFacInd ~= GDB_ID.NULL then vtFace = EgtSurfTmFacetNormVersor( Proc.Id, nFacInd, GDB_ID.ROOT) if not ( vtFace:getZ() > dMinCompZ or vtFace:getZ() < - dMinCompZ) then local nOtherFace = -1 for nIdx = 0, 3 do local vtN2 = EgtSurfTmFacetNormVersor( Proc.Id, nIdx, GDB_ID.ROOT) - if vtN2:getZ() > dMinCompZ or vtN2:getZ() < - dMinCompZ then + if vtN2:getZ() > dMinCompZ or vtN2:getZ() < - dMinCompZ then nOtherFace = nIdx break - end + end end - if nOtherFace ~= -1 and nOtherFace ~= nFacInd and nOtherFace ~= nFacInd2 then + if nOtherFace ~= -1 and nOtherFace ~= nFacInd and nOtherFace ~= nFacInd2 then bLJFromBottom = true - if bCompute then + if bCompute then local bAdj, ptP1, ptP2 = EgtSurfTmFacetsContact( Proc.Id, nFacInd, nOtherFace, GDB_ID.ROOT) local bAdj2, ptP3, ptP4 = EgtSurfTmFacetsContact( Proc.Id, nFacInd, nFacInd2, GDB_ID.ROOT) if AreSamePointApprox( ptP2, ptP3) or AreSamePointApprox( ptP2, ptP4) then - ptP1, ptP2 = ptP2, ptP1 - end - nRectId = CreateToolRectangle( ptP1, 0, ptP2, WD.SIDEMILL_DIAM_DOWN / 2, vtFace, WD.SIDEMILL_DIAM_DOWN, nOutlineGrp) + ptP1, ptP2 = ptP2, ptP1 + end + nRectId = CreateToolRectangle( ptP1, 0, ptP2, s_dSideMillDiamDown / 2, vtFace, s_dSideMillDiamDown, nOutlineGrp) end end end @@ -249,36 +267,36 @@ local function IdentifyLJFromBottom( Proc, bCompute, nOutlineGrp) if vtFace:getZ() < -dMinCompZ then vtFace = vtFace2 end if bCompute then local bAdj, ptP1, ptP2 = EgtSurfTmFacetsContact( Proc.Id, nFacInd, nFacInd2, GDB_ID.ROOT) - nRectId = CreateToolRectangle( ptP1, 0, ptP2, 0, vtFace, WD.SIDEMILL_DIAM_DOWN, nOutlineGrp) - end + nRectId = CreateToolRectangle( ptP1, 0, ptP2, 0, vtFace, s_dSideMillDiamDown, nOutlineGrp) + end end - end - + end end end - + if bLJFromBottom then return vtFace, nRectId - else - return - end + else + return + end end +------------------------------------------------------------------ -- Funzione che verifica se la lavorazione è lap joint da sopra ed eventualmente ne calcola l'area di lavorazione local function IdentifyLJFromTop( Proc, bCompute, nOutlineGrp) - local bLJFromTop = false + local bLJFromTop = false local vtFace, nRectId - if not WD.SIDEMILL_DIAM_UP or WD.SIDEMILL_DIAM_UP < GEO.EPS_SMALL then return end + if s_dSideMillDiamUp < GEO.EPS_SMALL then return end local dMinComp = 0.95 - if Proc.Fct == 2 then + if Proc.Fct == 2 then local vtN = {} vtN[1] = EgtSurfTmFacetNormVersor( Proc.Id, 0, GDB_ID.ROOT) vtN[2] = EgtSurfTmFacetNormVersor( Proc.Id, 1, GDB_ID.ROOT) - -- se rivolto verso l'alto + -- se rivolto verso l'alto if (vtN[1]:getZ() > dMinComp or vtN[2]:getZ() > dMinComp) then bLJFromTop = true vtFace = EgtIf( vtN[1]:getZ() > dMinComp, vtN[2], vtN[1]) @@ -291,20 +309,20 @@ local function IdentifyLJFromTop( Proc, bCompute, nOutlineGrp) elseif vtFace:getY() > dMinComp or vtFace:getY() < - dMinComp then dDim = b3Face:getDimY() end - local dValFace = max( dDim + WD.SIDEMILL_DIAM_UP / 2, WD.SIDEMILL_DIAM_UP) - local dVal = WD.SIDEMILL_DIAM_UP / 2 + local dValFace = max( dDim + s_dSideMillDiamUp / 2, s_dSideMillDiamUp) + local dVal = s_dSideMillDiamUp / 2 if NEST.MACH_AREA_USE_OTHER_DIAM == 1 then dVal = NEST.MACH_AREA_OTHER_DIAM / 2 - end + end nRectId = CreateToolRectangle( ptP1, dVal, ptP2, dVal, vtFace, dValFace, nOutlineGrp) end end - -- caso 3 facce + -- caso 3 facce elseif Proc.Fct == 3 then local nFacInd, dElev, nFacInd2 = WL.GetFaceWithMostAdj( Proc.Id, Proc.PartId) - -- forma ad U + -- forma ad U if not nFacInd2 and nFacInd ~= GDB_ID.NULL and NEST.LAP_JOINT_U_MACH_AREA == 1 then local vtFace = EgtSurfTmFacetNormVersor( Proc.Id, nFacInd, GDB_ID.ROOT) if vtFace:getZ() > dMinComp then @@ -314,12 +332,12 @@ local function IdentifyLJFromTop( Proc, bCompute, nOutlineGrp) local nOtherFace = EgtIf( nFacInd == 0, 1, 0) local vtNOther = EgtSurfTmFacetNormVersor( Proc.Id, nOtherFace, GDB_ID.ROOT) local vtDir = EgtIf( AreSameOrOppositeVectorApprox( vtNOther, X_AX()), Y_AX(), X_AX()) - local dVal = WD.SIDEMILL_DIAM_UP / 2 + 5 + local dVal = s_dSideMillDiamUp / 2 + 5 local ptMin = b3Face:getMin() - dVal * vtDir - local ptMax = b3Face:getMax() + dVal * vtDir - -- nRectId = EgtRectangle2P( nOutlineGrp, Point3d(ptMax:getX(), ptMax:getY(), 0), Point3d( ptMin:getX(), ptMin:getY(), 0)) - nRectId = EgtRectangle2P( nOutlineGrp, ptMax, ptMin) - end + local ptMax = b3Face:getMax() + dVal * vtDir + -- nRectId = EgtRectangle2P( nOutlineGrp, Point3d(ptMax:getX(), ptMax:getY(), 0), Point3d( ptMin:getX(), ptMin:getY(), 0)) + nRectId = EgtRectangle2P( nOutlineGrp, ptMax, ptMin) + end end elseif nFacInd2 then @@ -329,20 +347,20 @@ local function IdentifyLJFromTop( Proc, bCompute, nOutlineGrp) if vtN2:getZ() > dMinComp then nFaceZ = nIdx break - end + end end if nFaceZ ~= -1 then local nFace = EgtIf( nFaceZ == nFacInd, nFacInd2, nFacInd) - local nOtherFace = EgtIf( nFaceZ + nFace == 3, 0, EgtIf( nFaceZ + nFace == 2, 1, 2)) + local nOtherFace = EgtIf( nFaceZ + nFace == 3, 0, EgtIf( nFaceZ + nFace == 2, 1, 2)) local vtFace = {} vtFace = EgtSurfTmFacetNormVersor( Proc.Id, nFace, GDB_ID.ROOT) --vtFace = EgtSurfTmFacetNormVersor( Proc.Id, nOtherFace, GDB_ID.ROOT) bLJFromTop = true - if bCompute then + if bCompute then local bAdj, ptP1, ptP2 = EgtSurfTmFacetsContact( Proc.Id, nFace, nFaceZ, GDB_ID.ROOT) local bAdj2, ptP3, ptP4 = EgtSurfTmFacetsContact( Proc.Id, nFace, nOtherFace, GDB_ID.ROOT) if AreSamePointApprox( ptP2, ptP3) or AreSamePointApprox( ptP2, ptP4) then - ptP1, ptP2 = ptP2, ptP1 + ptP1, ptP2 = ptP2, ptP1 end local b3Face = EgtSurfTmGetFacetBBoxGlob( Proc.Id, nFaceZ, GDB_BB.STANDARD) @@ -352,24 +370,25 @@ local function IdentifyLJFromTop( Proc, bCompute, nOutlineGrp) elseif vtFace:getY() > dMinComp or vtFace:getY() < - dMinComp then dDim = b3Face:getDimY() end - local dValFace = max( dDim + WD.SIDEMILL_DIAM_UP / 2, WD.SIDEMILL_DIAM_UP) - local dVal = WD.SIDEMILL_DIAM_UP / 2 + local dValFace = max( dDim + s_dSideMillDiamUp / 2, s_dSideMillDiamUp) + local dVal = s_dSideMillDiamUp / 2 if NEST.MACH_AREA_USE_OTHER_DIAM == 1 then dVal = NEST.MACH_AREA_OTHER_DIAM / 2 end nRectId = CreateToolRectangle( ptP1, 0, ptP2, dVal, vtFace, dValFace, nOutlineGrp) - end - end + end + end end - end + end if bLJFromTop then return vtFace, nRectId else - return + return end end +------------------------------------------------------------------ -- Funzione che crea le regioni occupate dalle lavorazioni local function ComputeToolOutlines( nPartId) @@ -404,8 +423,8 @@ local function ComputeToolOutlines( nPartId) local nPrId = EgtGetInfo( Proc.Id, "PRID", 'i') EgtSetInfo( nRectId, "PRID", nPrId) table.insert( ToolOutlineId, nRectId) - end - end + end + end end -- fori @@ -419,7 +438,7 @@ local function ComputeToolOutlines( nPartId) local dDiam = 2 * EgtArcRadius( AuxId) -- verifico se la lunghezza del foro è maggiore della lunghezza della punta - if bOpen and AreSameOrOppositeVectorApprox( vtExtr, Y_AX()) and dLen > WD.HOR_DRILL_LEN - 1 then + if bOpen and AreSameOrOppositeVectorApprox( vtExtr, Y_AX()) and dLen > s_dHorDrillLen - 1 then local ptP1 = Proc.Box:getMin() local ptP2 = Proc.Box:getMax() local dExtra = 10 @@ -451,49 +470,47 @@ local function ComputeToolOutlines( nPartId) dVal = ( NEST.OFFSET + 0.1) * dCosAlpha end - local frLoc, dDimX, dDimY = EgtSurfTmFacetMinAreaRectangle( Proc.Id, nInd, GDB_ID.ROOT) - local b3Face = EgtSurfTmGetFacetBBoxRef( Proc.Id, nInd, GDB_BB.STANDARD, frLoc) - local ptA = b3Face:getMin() - local ptC = b3Face:getMax() - local ptB = ptA + dDimY * Y_AX() - local ptD = ptA + dDimX * X_AX() - ptA:toGlob( frLoc) - ptB:toGlob( frLoc) - ptC:toGlob( frLoc) - ptD:toGlob( frLoc) + local frLoc, dDimX, dDimY = EgtSurfTmFacetMinAreaRectangle( Proc.Id, nInd, GDB_ID.ROOT) + local b3Face = EgtSurfTmGetFacetBBoxRef( Proc.Id, nInd, GDB_BB.STANDARD, frLoc) + local ptA = b3Face:getMin() + local ptC = b3Face:getMax() + local ptB = ptA + dDimY * Y_AX() + local ptD = ptA + dDimX * X_AX() + ptA:toGlob( frLoc) + ptB:toGlob( frLoc) + ptC:toGlob( frLoc) + ptD:toGlob( frLoc) + + local ptP1, ptP2 + if bUnderCut then + ptP1 = EgtIf( ptA:getZ() > ptC:getZ(), ptA, ptC) + ptP2 = EgtIf( ptB:getZ() > ptD:getZ(), ptB, ptD) + else + ptP1 = EgtIf( ptA:getZ() < ptC:getZ(), ptA, ptC) + ptP2 = EgtIf( ptB:getZ() < ptD:getZ(), ptB, ptD) + end - local ptP1, ptP2 - if bUnderCut then - ptP1 = EgtIf( ptA:getZ() > ptC:getZ(), ptA, ptC) - ptP2 = EgtIf( ptB:getZ() > ptD:getZ(), ptB, ptD) - else - ptP1 = EgtIf( ptA:getZ() < ptC:getZ(), ptA, ptC) - ptP2 = EgtIf( ptB:getZ() < ptD:getZ(), ptB, ptD) - end - - local vtDir = ptP2 - ptP1 - vtDir:normalize() - ptP1 = ptP1 - vtDir * 0.5 * NEST.OFFSET - ptP2 = ptP2 + vtDir * 0.5 * NEST.OFFSET - local vtNxy = Vector3d( vtN:getX(), vtN:getY(), 0) - vtNxy:normalize() - local ptP4 = ptP2 + dVal * vtNxy - - local nRectId = EgtRectangle3P( nOutlineGrp, ptP1, ptP4, ptP2) - EgtSetColor( nRectId, EgtStdColor("AQUA")) - if nRectId ~= GDB_ID.NULL then table.insert( ToolOutlineId, nRectId) end - - end - end + local vtDir = ptP2 - ptP1 + vtDir:normalize() + ptP1 = ptP1 - vtDir * 0.5 * NEST.OFFSET + ptP2 = ptP2 + vtDir * 0.5 * NEST.OFFSET + local vtNxy = Vector3d( vtN:getX(), vtN:getY(), 0) + vtNxy:normalize() + local ptP4 = ptP2 + dVal * vtNxy + + local nRectId = EgtRectangle3P( nOutlineGrp, ptP1, ptP4, ptP2) + EgtSetColor( nRectId, EgtStdColor("AQUA")) + if nRectId ~= GDB_ID.NULL then table.insert( ToolOutlineId, nRectId) end + end + end end - end - + end end return ToolOutlineId end - +------------------------------------------------------------------ local function ClassifyDrillsOnLateralFaces( nPartId, dMinSheetWidth) local dDeltaRaw = WD.MAX_WIDTH - dMinSheetWidth + NEST.KERF @@ -502,12 +519,12 @@ local function ClassifyDrillsOnLateralFaces( nPartId, dMinSheetWidth) L = {nbr = 0, closed = false, long = false, OnlyOnRef = false}, R = {nbr = 0, closed = false, long = false, OnlyOnRef = false}} local nBoxLayerId = EgtGetFirstNameInGroup( nPartId, "Box") local nBoxId = EgtGetFirstNameInGroup( nBoxLayerId, "Box") - local b3Part = EgtGetBBoxGlob(nBoxId, GDB_BB.STANDARD) + local b3Part = EgtGetBBoxGlob(nBoxId, GDB_BB.STANDARD) local ptPartMin = b3Part:getMin() local ptPartMax = b3Part:getMax() local vPartProc = WE.CollectFeatures( nPartId) - for nInd = 1, #vPartProc do repeat + for nInd = 1, #vPartProc do repeat if Drill.Identify( vPartProc[nInd]) then @@ -518,11 +535,11 @@ local function ClassifyDrillsOnLateralFaces( nPartId, dMinSheetWidth) if not AuxId or EgtGetType( AuxId) ~= GDB_TY.CRV_ARC then break end -- verifico se diametro compatibile con la punta local dDiam = 2 * EgtArcRadius( AuxId) - if abs( dDiam - WD.HOR_DRILL_DIAM) < WD.DRILL_TOL + GEO.EPS_SMALL then + if abs( dDiam - s_dHorDrillDiam) < WD.DRILL_TOL + GEO.EPS_SMALL then local ptDrill = EgtCP( AuxId, GDB_RT.GLOB) local dLen = abs( EgtCurveThickness( AuxId)) - local bLong = dLen > WD.HOR_DRILL_LEN - 1 - local bOnlyOnRef = dLen + dDeltaRaw > WD.HOR_DRILL_LEN - GEO.EPS_SMALL and not bLong + local bLong = dLen > s_dHorDrillLen - 1 + local bOnlyOnRef = dLen + dDeltaRaw > s_dHorDrillLen - GEO.EPS_SMALL and not bLong -- faccia Front local dTol = GEO.EPS_SMALL @@ -531,14 +548,14 @@ local function ClassifyDrillsOnLateralFaces( nPartId, dMinSheetWidth) if bOnlyOnRef then DrillOnFaces.F.OnlyOnRef = true end if bOpen then DrillOnFaces.B.nbr = DrillOnFaces.B.nbr + 1 - if bOnlyOnRef then DrillOnFaces.B.OnlyOnRef = true end + if bOnlyOnRef then DrillOnFaces.B.OnlyOnRef = true end else DrillOnFaces.F.closed = true end if bLong then DrillOnFaces.F.long = true - if bOpen then DrillOnFaces.B.long = true end + if bOpen then DrillOnFaces.B.long = true end end -- faccia Back @@ -553,11 +570,11 @@ local function ClassifyDrillsOnLateralFaces( nPartId, dMinSheetWidth) end if bLong then DrillOnFaces.B.long = true - if bOpen then DrillOnFaces.F.long = true end + if bOpen then DrillOnFaces.F.long = true end end -- faccia Left - elseif ( abs( ptDrill:getX() - ptPartMin:getX()) < dTol) then + elseif ( abs( ptDrill:getX() - ptPartMin:getX()) < dTol) then DrillOnFaces.L.nbr = DrillOnFaces.L.nbr + 1 if bOnlyOnRef then DrillOnFaces.L.OnlyOnRef = true end if bOpen then @@ -568,11 +585,11 @@ local function ClassifyDrillsOnLateralFaces( nPartId, dMinSheetWidth) end if bLong then DrillOnFaces.L.long = true - if bOpen then DrillOnFaces.R.long = true end + if bOpen then DrillOnFaces.R.long = true end end -- faccia Right - elseif ( abs( ptDrill:getX() - ptPartMax:getX()) < dTol) then + elseif ( abs( ptDrill:getX() - ptPartMax:getX()) < dTol) then DrillOnFaces.R.nbr = DrillOnFaces.R.nbr + 1 if bOnlyOnRef then DrillOnFaces.R.OnlyOnRef = true end if bOpen then @@ -587,7 +604,7 @@ local function ClassifyDrillsOnLateralFaces( nPartId, dMinSheetWidth) end end end - end + end until true end @@ -596,11 +613,11 @@ local function ClassifyDrillsOnLateralFaces( nPartId, dMinSheetWidth) local sDrillFace, nMax = '', -100 for k, v in pairs( DrillOnFaces) do if v.nbr > nMax or ( v.nbr == nMax and not DrillOnFaces[sDrillFace].OnlyOnRef and v.OnlyOnRef) then - sDrillFace, nMax = k, v.nbr + sDrillFace, nMax = k, v.nbr end end - local sDrillFace2 + local sDrillFace2 if nMax > 0 then if sDrillFace == 'F' or sDrillFace == 'B' then -- cerco chi vince tra faccia left e right @@ -613,7 +630,7 @@ local function ClassifyDrillsOnLateralFaces( nPartId, dMinSheetWidth) sDrillFace2 = 'L' else sDrillFace2 = 'R' - end + end end else @@ -627,18 +644,17 @@ local function ClassifyDrillsOnLateralFaces( nPartId, dMinSheetWidth) sDrillFace2 = 'F' else sDrillFace2 = 'B' - end - end - end + end + end + end end - if NEST.DRILL_MACH_AREA == 0 then DrillOnFaces[sDrillFace].long = false end if nMax > 0 then - DrillClassif = { sCase = sDrillFace, bClosed = DrillOnFaces[sDrillFace].closed, bLong = DrillOnFaces[sDrillFace].long, bOnlyOnRef = DrillOnFaces[sDrillFace].OnlyOnRef } + DrillClassif = { sCase = sDrillFace, bClosed = DrillOnFaces[sDrillFace].closed, bLong = DrillOnFaces[sDrillFace].long, bOnlyOnRef = DrillOnFaces[sDrillFace].OnlyOnRef} end local DrillClassif2 @@ -646,13 +662,14 @@ local function ClassifyDrillsOnLateralFaces( nPartId, dMinSheetWidth) if NEST.DRILL_MACH_AREA == 0 then DrillOnFaces[sDrillFace2].long = false end - DrillClassif2 = { sCase = sDrillFace2, bClosed = DrillOnFaces[sDrillFace2].closed, bLong = DrillOnFaces[sDrillFace2].long, bOnlyOnRef = DrillOnFaces[sDrillFace2].OnlyOnRef } - end + DrillClassif2 = { sCase = sDrillFace2, bClosed = DrillOnFaces[sDrillFace2].closed, bLong = DrillOnFaces[sDrillFace2].long, bOnlyOnRef = DrillOnFaces[sDrillFace2].OnlyOnRef} + end - - return DrillClassif, DrillClassif2 + + return DrillClassif, DrillClassif2 end +------------------------------------------------------------------ local function ClassifyLapJointsFromBottom( nPartId) local res = { Nbr = 0, sCase = '', bParall = false} @@ -664,13 +681,13 @@ local function ClassifyLapJointsFromBottom( nPartId) local vtLapJoints = {} local dMinComponentVal = 0.95 local vPartProc = WE.CollectFeatures( nPartId) - for nInd = 1, #vPartProc do + for nInd = 1, #vPartProc do if LapJoint.Identify( vPartProc[nInd]) then -- verifico se LJ da sotto local vtFace = IdentifyLJFromBottom( vPartProc[nInd], false) if vtFace then - if vtFace:getX() > dMinComponentVal then + if vtFace:getX() > dMinComponentVal then vtLapJoints["R"] = 1 elseif vtFace:getX() < - dMinComponentVal then vtLapJoints["L"] = 1 @@ -678,8 +695,8 @@ local function ClassifyLapJointsFromBottom( nPartId) vtLapJoints["B"] = 1 elseif vtFace:getY() < - dMinComponentVal then vtLapJoints["F"] = 1 - end - end + end + end end end @@ -710,11 +727,11 @@ local function ClassifyLapJointsFromBottom( nPartId) res.sCase = 'FR' elseif vtLapJoints["F"] and vtLapJoints["L"] then res.sCase = 'FL' - end + end end elseif nCnt == 3 then - res.Nbr = 3 + res.Nbr = 3 if not vtLapJoints["F"] then res.sCase = "F" elseif not vtLapJoints["B"] then @@ -723,7 +740,7 @@ local function ClassifyLapJointsFromBottom( nPartId) res.sCase = "R" elseif not vtLapJoints["L"] then res.sCase = "L" - end + end elseif nCnt == 4 then res.Nbr = 4 @@ -731,11 +748,11 @@ local function ClassifyLapJointsFromBottom( nPartId) return end - return res + return res end - +------------------------------------------------------------------ local function CreateDefectOnAngle( nPartId, RawPart, bDrillLong, bOnOppositeAng) local PartTab = {} @@ -747,7 +764,7 @@ local function CreateDefectOnAngle( nPartId, RawPart, bDrillLong, bOnOppositeAng EgtSetStatus( nOutlineGrp, GDB_ST.OFF) end - local dExtraMachArea = WD.SIDEMILL_DIAM_DOWN -- per tenere conto dell'area di lavorazione + local dExtraMachArea = s_dSideMillDiamDown -- per tenere conto dell'area di lavorazione local dExtra = NEST.KERF -- local b3Part = EgtGetBBoxGlob( nPartId, GDB_BB.STANDARD) @@ -756,51 +773,50 @@ local function CreateDefectOnAngle( nPartId, RawPart, bDrillLong, bOnOppositeAng local b3Part = EgtGetBBoxGlob(nBoxId, GDB_BB.STANDARD) local b3PartX = b3Part:getDimX() local b3PartY = b3Part:getDimY() - -- se ho fori lunghi devo riservare tutto lo spazio + -- se ho fori lunghi devo riservare tutto lo spazio if bDrillLong then b3PartY = RawPart.Width end -- calcolo i punti che definiscono il rettangolo local ptP1, ptP2 - if ( WD.ORIG_CORNER == 'TL' and not bOnOppositeAng) or ( WD.ORIG_CORNER == 'BL' and bOnOppositeAng) then + if ( s_sOrigCorner == 'TL' and not bOnOppositeAng) or ( s_sOrigCorner == 'BL' and bOnOppositeAng) then -- angolo TL ptP1 = Point3d( 0, RawPart.Width - b3PartY - dExtra, 0) ptP2 = Point3d( b3PartX + dExtra, RawPart.Width, 0) PartTab.posX = NEST.KERF PartTab.posY = RawPart.Width - b3Part:getDimY() - NEST.KERF - elseif ( WD.ORIG_CORNER == 'BL' and not bOnOppositeAng) or ( WD.ORIG_CORNER == 'TL' and bOnOppositeAng) then + elseif ( s_sOrigCorner == 'BL' and not bOnOppositeAng) or ( s_sOrigCorner == 'TL' and bOnOppositeAng) then -- angolo BL ptP1 = Point3d( 0, 0, 0) ptP2 = Point3d( b3PartX + dExtra, b3PartY + dExtra, 0) PartTab.posX = NEST.KERF PartTab.posY = NEST.KERF - elseif ( WD.ORIG_CORNER == 'TR' and not bOnOppositeAng) or ( WD.ORIG_CORNER == 'BR' and bOnOppositeAng) then + elseif ( s_sOrigCorner == 'TR' and not bOnOppositeAng) or ( s_sOrigCorner == 'BR' and bOnOppositeAng) then -- angolo TR ptP1 = Point3d( RawPart.Len - b3PartX - dExtra, RawPart.Width - b3PartY - dExtra, 0) ptP2 = Point3d( RawPart.Len, RawPart.Width, 0) PartTab.posX = RawPart.Len - b3Part:getDimX() - NEST.KERF PartTab.posY = RawPart.Width - b3Part:getDimY() - NEST.KERF - elseif ( WD.ORIG_CORNER == 'BR' and not bOnOppositeAng) or ( WD.ORIG_CORNER == 'TR' and bOnOppositeAng) then + elseif ( s_sOrigCorner == 'BR' and not bOnOppositeAng) or ( s_sOrigCorner == 'TR' and bOnOppositeAng) then -- angolo BR ptP1 = Point3d( RawPart.Len - b3PartX - dExtra, 0, 0) ptP2 = Point3d( RawPart.Len, b3PartY + dExtra, 0) PartTab.posX = RawPart.Len - b3Part:getDimX() - NEST.KERF - PartTab.posY = NEST.KERF + PartTab.posY = NEST.KERF end PartTab.Id = tonumber(nPartId) PartTab.DefectId = EgtRectangle2P( nOutlineGrp, Point3d(ptP2:getX() + dExtraMachArea, ptP2:getY() + dExtraMachArea , 0), Point3d( ptP1:getX() - dExtraMachArea , ptP1:getY() - dExtraMachArea, 0)) - EgtSetName( PartTab.DefectId, "Defect") + EgtSetName( PartTab.DefectId, "Defect") return PartTab - end - +------------------------------------------------------------------ local function RotateOptimalCase( nPartId, nAngle, nAngleValidRot, RawPart, nPnt1, nPnt2) - local bOptimal = false + local bOptimal = false local b3Part = EgtGetBBoxGlob( nPartId, GDB_BB.STANDARD) EgtRotate( nPartId, b3Part:getCenter(), Z_AX(), nAngle, GDB_RT.GLOB) local nRotate = nAngle @@ -817,22 +833,22 @@ local function RotateOptimalCase( nPartId, nAngle, nAngleValidRot, RawPart, nPnt bOptimal = false -- ruoto nella migliore posizione ammissibile EgtRotate( nPartId, b3Part:getCenter(), Z_AX(), nAngleValidRot, GDB_RT.GLOB) - nRotate = nRotate + nAngleValidRot - nAnglePnt = nPnt2 + nRotate = nRotate + nAngleValidRot + nAnglePnt = nPnt2 end if nRotate >= 360 then nRotate = nRotate - 360 end - return nAnglePnt, nRotate, bOptimal - + return nAnglePnt, nRotate, bOptimal end +------------------------------------------------------------------ local function RotateOptimalCaseDrill( nPartId, bCanRotate, nPnt1, nPnt2) - local nRotate = 0 - local nAnglePnt + local nRotate = 0 + local nAnglePnt if bCanRotate then local b3Part = EgtGetBBoxGlob( nPartId, GDB_BB.STANDARD) @@ -843,10 +859,10 @@ local function RotateOptimalCaseDrill( nPartId, bCanRotate, nPnt1, nPnt2) nAnglePnt = nPnt2 end - return nAnglePnt, nRotate + return nAnglePnt, nRotate end - +------------------------------------------------------------------ -- Funzione che classifica i pezzi in base alla loro necessità di stare negli angoli local function ClassifyAngles( nPartId, RawPart, sRefOrig, bLockedRot, dMinSheetWidth) @@ -859,26 +875,26 @@ local function ClassifyAngles( nPartId, RawPart, sRefOrig, bLockedRot, dMinSheet local nRotate = 0 local bOptimal local bManual = false - local bOnly180Rot = EgtGetInfo( nPartId, "HasGrainDirection", 'b') or false + local bOnly180Rot = EgtGetInfo( nPartId, "HasGrainDirection", 'b') or false local b3Part = EgtGetBBoxGlob( nPartId, GDB_BB.STANDARD) -- fori local DrillClassif, DrillClassif2 = ClassifyDrillsOnLateralFaces( nPartId, dMinSheetWidth) - local bDrill = false + local bDrill = false local bDrillOpen = false local bLongDrill = false - if DrillClassif then - bDrill = true - bDrillOpen = not DrillClassif.bClosed - bLongDrill = DrillClassif.bLong + if DrillClassif then + bDrill = true + bDrillOpen = not DrillClassif.bClosed + bLongDrill = DrillClassif.bLong if DrillClassif.bOnlyOnRef then EgtSetInfo( nPartId, "OnlyOnRefSide", 1) - end + end end -- oriento il pezzo in base al foro - if bDrill and not bLockedRot then + if bDrill and not bLockedRot then local RotationAngles if sRefOrig == 'TL' or sRefOrig == 'TR' then RotationAngles = { F = 180, B = 0, L = 270, R = 90} @@ -894,7 +910,7 @@ local function ClassifyAngles( nPartId, RawPart, sRefOrig, bLockedRot, dMinSheet -- verifico se la rotazione è valida local nBoxLayerId = EgtGetFirstNameInGroup( nPartId, "Box") local nBoxId = EgtGetFirstNameInGroup( nBoxLayerId, "Box") - local b3Part = EgtGetBBoxGlob(nBoxId, GDB_BB.STANDARD) + local b3Part = EgtGetBBoxGlob(nBoxId, GDB_BB.STANDARD) -- b3Part = EgtGetBBoxGlob( nPartId, GDB_BB.STANDARD) local bIsValidRotation = b3Part:getDimX() < RawPart.Len - 2 * NEST.KERF + GEO.EPS_SMALL and b3Part:getDimY() < RawPart.Width - 2 * NEST.KERF + GEO.EPS_SMALL if not bIsValidRotation then @@ -904,47 +920,47 @@ local function ClassifyAngles( nPartId, RawPart, sRefOrig, bLockedRot, dMinSheet -- se ho un'altra posizione possibile ruoto in quella if DrillClassif2 then EgtRotate( nPartId, b3Part:getCenter(), Z_AX(), RotationAngles[DrillClassif2.sCase], GDB_RT.GLOB) - nRotate = nRotate + RotationAngles[DrillClassif2.sCase] - bDrillOpen = not DrillClassif2.bClosed - bLongDrill = DrillClassif2.bLong + nRotate = nRotate + RotationAngles[DrillClassif2.sCase] + bDrillOpen = not DrillClassif2.bClosed + bLongDrill = DrillClassif2.bLong if DrillClassif2.bOnlyOnRef then EgtSetInfo( nPartId, "OnlyOnRefSide", 1) - end - else + end + else -- dimentico di avere il foro bDrill = false - end + end end - -- se posso ruotare solo di 180° per venatura + -- se posso ruotare solo di 180° per venatura else if RotationAngles[DrillClassif.sCase] == 0 or RotationAngles[DrillClassif.sCase] == 180 then EgtRotate( nPartId, b3Part:getCenter(), Z_AX(), RotationAngles[DrillClassif.sCase], GDB_RT.GLOB) nRotate = nRotate + RotationAngles[DrillClassif.sCase] else - -- vedo se ho un'altra posizione possibile + -- vedo se ho un'altra posizione possibile if DrillClassif2 and ( RotationAngles[DrillClassif2.sCase] == 0 or RotationAngles[DrillClassif2.sCase] == 180) then EgtRotate( nPartId, b3Part:getCenter(), Z_AX(), RotationAngles[DrillClassif2.sCase], GDB_RT.GLOB) nRotate = nRotate + RotationAngles[DrillClassif2.sCase] - bDrillOpen = not DrillClassif2.bClosed - bLongDrill = DrillClassif2.bLong + bDrillOpen = not DrillClassif2.bClosed + bLongDrill = DrillClassif2.bLong if DrillClassif2.bOnlyOnRef then EgtSetInfo( nPartId, "OnlyOnRefSide", 1) - end - else + end + else -- dimentico di avere il foro bDrill = false end - end - end - end + end + end + end -- se non ho venature e fori scelgo una posizione che non faccia cadere il pezzo if not bDrill and not bOnly180Rot and not bLockedRot then b3Part = EgtGetBBoxGlob( nPartId, GDB_BB.STANDARD) - local bIsValid = b3Part:getDimX() > ( WD.INTRULLI or 1200) - local bRotatedIsValid = b3Part:getDimY() > ( WD.INTRULLI or 1200) - if not bIsValid and not bRotatedIsValid then + local bIsValid = b3Part:getDimX() > s_dIntRulli + local bRotatedIsValid = b3Part:getDimY() > s_dIntRulli + if not bIsValid and not bRotatedIsValid then EgtSetInfo( nPartId, "REDUCECUT", 1) elseif not bIsValid or not bRotatedIsValid then bOnly180Rot = true @@ -953,76 +969,75 @@ local function ClassifyAngles( nPartId, RawPart, sRefOrig, bLockedRot, dMinSheet if not bIsValid and bRotatedIsValid then EgtRotate( nPartId, b3Part:getCenter(), Z_AX(), 90, GDB_RT.GLOB) nRotate = nRotate + 90 - end + end end - -- lap joints local ResLapJoints = ClassifyLapJointsFromBottom( nPartId) b3Part = EgtGetBBoxGlob( nPartId, GDB_BB.STANDARD) - local bAdd = true + local bAdd = true if ResLapJoints.Nbr > 0 and bLockedRot then b3Part = EgtGetBBoxGlob( nPartId, GDB_BB.STANDARD) - if b3Part:getDimX() > ( WD.INTRULLI or 1200) then + if b3Part:getDimX() > s_dIntRulli then EgtSetInfo( nPartId, "REDUCECUT", 1) end local PartAngleClassification = { PartId = tostring( nPartId), Angle = 100, nRotate = 0, bDrill = true, bLongDrill = true} return PartAngleClassification end - -- se anche fori oppure possibile solo rotazione di 180° per non far cadere il pezzo - if bDrill or bOnly180Rot then - local bCanRotate = not bDrill or ( bDrill and bDrillOpen) + -- se anche fori oppure possibile solo rotazione di 180° per non far cadere il pezzo + if bDrill or bOnly180Rot then + local bCanRotate = not bDrill or ( bDrill and bDrillOpen) if ResLapJoints.Nbr == 0 then nAngle = 0 if not bDrill then bAdd = false end - elseif ResLapJoints.Nbr == 1 then + elseif ResLapJoints.Nbr == 1 then if (( sRefOrig == 'TL' or sRefOrig == 'TR') and ResLapJoints.sCase == 'B' ) or (( sRefOrig == 'BL' or sRefOrig == 'BR') and ResLapJoints.sCase == 'F' ) then nAngle = 20 elseif (( sRefOrig == 'TL' or sRefOrig == 'TR') and ResLapJoints.sCase == 'F' ) or - (( sRefOrig == 'BL' or sRefOrig == 'BR') and ResLapJoints.sCase == 'B' ) then + (( sRefOrig == 'BL' or sRefOrig == 'BR') and ResLapJoints.sCase == 'B' ) then nAngle, nRotate2 = RotateOptimalCaseDrill( nPartId, bCanRotate, 20, 100) nRotate = nRotate + nRotate2 - elseif ResLapJoints.sCase == 'R' then + elseif ResLapJoints.sCase == 'R' then if bCanRotate then bManual = true end if sRefOrig == 'TL' or sRefOrig == 'BL'then nAngle, nRotate2 = RotateOptimalCaseDrill( nPartId, bCanRotate, 40, 0) - nRotate = nRotate + nRotate2 + nRotate = nRotate + nRotate2 else nAngle = 40 - end + end elseif ResLapJoints.sCase == 'L' then if bCanRotate then bManual = true end if sRefOrig == 'TR' or sRefOrig == 'BR' then nAngle, nRotate2 = RotateOptimalCaseDrill( nPartId, bCanRotate, 40, 0) - nRotate = nRotate + nRotate2 + nRotate = nRotate + nRotate2 else nAngle = 40 - end + end end - elseif ResLapJoints.Nbr == 2 then + elseif ResLapJoints.Nbr == 2 then if ResLapJoints.bParall then if ResLapJoints.sCase == 'F' then nAngle = 100 else nAngle = 80 - end + end else if (( sRefOrig == 'TL' or sRefOrig == 'TR') and (ResLapJoints.sCase == 'BL' or ResLapJoints.sCase == 'BR')) or (( sRefOrig == 'BL' or sRefOrig == 'BR') and (ResLapJoints.sCase == 'FL' or ResLapJoints.sCase == 'FR')) then nAngle = 40 else nAngle, nRotate2 = RotateOptimalCaseDrill( nPartId, bCanRotate, 40, 100) - nRotate = nRotate + nRotate2 + nRotate = nRotate + nRotate2 end end - elseif ResLapJoints.Nbr == 3 then + elseif ResLapJoints.Nbr == 3 then if (( sRefOrig == 'TL' or sRefOrig == 'TR') and ResLapJoints.sCase == 'F' ) or (( sRefOrig == 'BL' or sRefOrig == 'BR') and ResLapJoints.sCase == 'B' ) then nAngle = 80 @@ -1048,8 +1063,7 @@ local function ClassifyAngles( nPartId, RawPart, sRefOrig, bLockedRot, dMinSheet elseif ResLapJoints.Nbr == 4 then nAngle = 100 - end - + end -- no fori else @@ -1064,17 +1078,17 @@ local function ClassifyAngles( nPartId, RawPart, sRefOrig, bLockedRot, dMinSheet end local nAngleValidRot = EgtIf( sRefOrig == 'TL' or sRefOrig == 'BR', 90, 270) nAngle, nRotate2, bOptimal = RotateOptimalCase( nPartId, RotationAngles[ResLapJoints.sCase], nAngleValidRot, RawPart, 20, 40) - nRotate = nRotate + nRotate2 - if not bOptimal then bManual = true end + nRotate = nRotate + nRotate2 + if not bOptimal then bManual = true end elseif ResLapJoints.Nbr == 2 then if ResLapJoints.bParall then -- se lap joints su lati paralleli RotationAngles = { F = 90, R = 0} nAngle, nRotate2 = RotateOptimalCase( nPartId, RotationAngles[ResLapJoints.sCase], 90, RawPart, 80, 100) - nRotate = nRotate + nRotate2 + nRotate = nRotate + nRotate2 else - -- se lap joints su lati adiacenti + -- se lap joints su lati adiacenti if sRefOrig == 'TR' then RotationAngles = { FR = 90, BR = 0, BL = 270, FL = 180} elseif sRefOrig == 'TL' then @@ -1089,8 +1103,8 @@ local function ClassifyAngles( nPartId, RawPart, sRefOrig, bLockedRot, dMinSheet nRotate = nRotate + nRotate2 local b3Part = EgtGetBBoxGlob( nPartId, GDB_BB.STANDARD) - local bCanRotate = b3Part:getDimX() < RawPart.Width - if bOptimal and bCanRotate then bManual = true end + local bCanRotate = b3Part:getDimX() < RawPart.Width + if bOptimal and bCanRotate then bManual = true end end elseif ResLapJoints.Nbr == 3 then @@ -1102,15 +1116,13 @@ local function ClassifyAngles( nPartId, RawPart, sRefOrig, bLockedRot, dMinSheet local nAngleValidRot = EgtIf( sRefOrig == 'TL' or sRefOrig == 'BR', 90, 270) nAngle, nRotate2, bOptimal = RotateOptimalCase( nPartId, RotationAngles[ResLapJoints.sCase], nAngleValidRot, RawPart, 80, 100) nRotate = nRotate + nRotate2 - if not bOptimal then bManual = true end + if not bOptimal then bManual = true end elseif ResLapJoints.Nbr == 4 then nAngle, nRotate2 = RotateOptimalCase( nPartId, 0, 90, RawPart, 100, 100) nRotate = nRotate + nRotate2 end - - end - + end -- aggiorno le info di rotazione del pezzo if nRotate >= 360 then @@ -1130,7 +1142,7 @@ local function ClassifyAngles( nPartId, RawPart, sRefOrig, bLockedRot, dMinSheet local PartAngleClassification = { PartId = tostring( nPartId), Angle = nAngle, nRotate = nRotate, bDrill = bDrill, bLongDrill = bLongDrill, bManual = bManual} - local bCanBeOnOtherEdge = not bDrill or ( bDrill and RawPart.Width >= WD.MINRAWY_HOR_DRILL) + local bCanBeOnOtherEdge = not bDrill or ( bDrill and RawPart.Width > s_dMinRawYHorDrill - GEO.EPS_SMALL) if bOnly180Rot then if bCanBeOnOtherEdge then EgtSetInfo( nPartId, "NestAllowRot", 1) @@ -1139,37 +1151,37 @@ local function ClassifyAngles( nPartId, RawPart, sRefOrig, bLockedRot, dMinSheet EgtSetInfo( nPartId, "NestAllowRot", 0) EgtSetInfo( nPartId, "NestStepRot", 0) end - end + end -- verifico se il pezzo cade (caso di foro) b3Part = EgtGetBBoxGlob( nPartId, GDB_BB.STANDARD) - if b3Part:getDimX() > ( WD.INTRULLI or 1200) then + if b3Part:getDimX() > s_dIntRulli then EgtSetInfo( nPartId, "REDUCECUT", 1) - end + end - return PartAngleClassification + return PartAngleClassification end - +------------------------------------------------------------------ local function ComputeRestrictedZones( RawParts) local dTotArea = 0 -- area totale dei pezzi - for nPartId, nCount in pairs( PART) do + for nPartId, nCount in pairs( PART) do local b3Part = EgtGetBBoxGlob( nPartId, GDB_BB.STANDARD) - local dPartArea = b3Part:getDimX() * b3Part:getDimY() + local dPartArea = b3Part:getDimX() * b3Part:getDimY() dTotArea = dTotArea + dPartArea * nCount end - -- stimo il numero di angoli disponibili + -- stimo il numero di angoli disponibili local vSheetNbrEstimate = {} local nSheetNbrEstimate = 0 - local nSheetNbrCorrection = - 2 - local nAnglesNbrEstimate = 0 - local nAngelsNbrCorrection = 0 + local nSheetNbrCorrection = - 2 + local nAnglesNbrEstimate = 0 + local nAngelsNbrCorrection = 0 local vRawDistrib = {} - if #RawParts == 1 then + if #RawParts == 1 then vRawDistrib = {1} elseif #RawParts == 2 then vRawDistrib = {0.7, 0.3} @@ -1181,7 +1193,7 @@ local function ComputeRestrictedZones( RawParts) local dMaxSheetWidth = -100 local nMaxSheet = 1 - local dMinSheetWidth = WD.MAX_WIDTH + local dMinSheetWidth = WD.MAX_WIDTH for nInd = 1, #RawParts do local dSheetArea = RawParts[nInd].Len * RawParts[nInd].Width if RawParts[nInd].Width > dMaxSheetWidth + GEO.EPS_SMALL then @@ -1189,47 +1201,45 @@ local function ComputeRestrictedZones( RawParts) nMaxSheet = nInd elseif abs( RawParts[nInd].Width - dMaxSheetWidth) < GEO.EPS_SMALL then if RawParts[nInd].Len > RawParts[nMaxSheet].Len then - nMaxSheet = nInd - end + nMaxSheet = nInd + end end if RawParts[nInd].Width < dMinSheetWidth then dMinSheetWidth = RawParts[nInd].Width end vSheetNbrEstimate[nInd] = min( ceil( dTotArea * vRawDistrib[nInd] / dSheetArea) + nSheetNbrCorrection, RawParts[nInd].Qty) - if vSheetNbrEstimate[nInd] <= 0 then - vSheetNbrEstimate[nInd] = min( RawParts[nInd].Qty, 1) + if vSheetNbrEstimate[nInd] <= 0 then + vSheetNbrEstimate[nInd] = min( RawParts[nInd].Qty, 1) end nSheetNbrEstimate = nSheetNbrEstimate + vSheetNbrEstimate[nInd] - nAnglesNbrEstimate = nAnglesNbrEstimate + vSheetNbrEstimate[nInd] * 2 + nAnglesNbrEstimate = nAnglesNbrEstimate + vSheetNbrEstimate[nInd] * 2 end nAnglesNbrEstimate = nAnglesNbrEstimate + nAngelsNbrCorrection - -- classificazione dei pezzi in base alla loro necessità di stare negli angoli local nTotParts = 0 for _ in pairs( PART) do nTotParts = nTotParts + 1 end local nPartIndex = 0 local AngleClassification = {} for nPartId, nCount in pairs( PART) do - nPartIndex = nPartIndex + 1 + nPartIndex = nPartIndex + 1 local bManualRot = EgtGetInfo( nPartId, "MANUALROT", 'b') - local PartClassif = ClassifyAngles(tonumber(nPartId), RawParts[nMaxSheet], WD.ORIG_CORNER, bManualRot, dMinSheetWidth) + local PartClassif = ClassifyAngles(tonumber(nPartId), RawParts[nMaxSheet], s_sOrigCorner, bManualRot, dMinSheetWidth) if PartClassif then - for nI = 1, nCount do + for nI = 1, nCount do local newTab = {PartId = PartClassif.PartId, Angle = PartClassif.Angle, nRotate = PartClassif.nRotate, bDrill = PartClassif.bDrill, bLongDrill = PartClassif.bLongDrill, bManual = PartClassif.bManual} table.insert( AngleClassification, newTab) - end - end + end + end if EgtProcessEvents( nPartIndex / nTotParts * 100, 0) == 1 then return false - end + end end table.sort( AngleClassification, function(a, b) return a.Angle > b.Angle end) - local vManuallyDone = {} local vPartsManuallyDone = {} @@ -1238,102 +1248,103 @@ local function ComputeRestrictedZones( RawParts) table.insert( vManuallyDone, { RawPartId = nInd, Done = 0, Parts = {}}) end end - local nSheetNbr = #vManuallyDone - local vFilledSheets = {} + local nSheetNbr = #vManuallyDone + local vFilledSheets = {} for nInd = 1, #vSheetNbrEstimate do for nInd2 = 1, vSheetNbrEstimate[nInd] do - table.insert( vFilledSheets, { Width = RawParts[nInd].Width, OrigWidth = RawParts[nInd].Width}) - end + table.insert( vFilledSheets, { Width = RawParts[nInd].Width, OrigWidth = RawParts[nInd].Width}) + end end for nInd = 1, #AngleClassification do if AngleClassification[nInd].Angle >= NEST.MIN_ANGLE_PNT and AngleClassification[nInd].Angle > 0 then - -- verifico di avere ancora angoli a disposizione secondo la stima dei grezzi + -- verifico di avere ancora angoli a disposizione secondo la stima dei grezzi local bFound = false local nBoxLayerId = EgtGetFirstNameInGroup( AngleClassification[nInd].PartId, "Box") local nBoxId = EgtGetFirstNameInGroup( nBoxLayerId, "Box") local b3Part = EgtGetBBoxGlob(nBoxId, GDB_BB.STANDARD) - local dPartWidth = b3Part:getDimY() + NEST.KERF - for nInd2 = 1, #vFilledSheets do + local dPartWidth = b3Part:getDimY() + NEST.KERF + for nInd2 = 1, #vFilledSheets do if dPartWidth < vFilledSheets[nInd2].Width then -- verifico se il grezzo aveva già un pezzo in un angolo if abs( vFilledSheets[nInd2].Width - vFilledSheets[nInd2].OrigWidth) < GEO.EPS_SMALL then - vFilledSheets[nInd2].Width = vFilledSheets[nInd2].Width - dPartWidth - WD.SIDEMILL_DIAM_DOWN + vFilledSheets[nInd2].Width = vFilledSheets[nInd2].Width - dPartWidth - s_dSideMillDiamDown else - -- se il grezzo aveva già un pezzo nell'angolo, dopo il pezzo corrente non ne posso mettere altri - vFilledSheets[nInd2].Width = 0 - end - bFound = true - break + -- se il grezzo aveva già un pezzo nell'angolo, dopo il pezzo corrente non ne posso mettere altri + vFilledSheets[nInd2].Width = 0 + end + bFound = true + break end - end + end -- se ho ancora angoli a disposizione oppure il pezzo deve stare necessariamente sull'angolo per essere lavorato - if bFound or AngleClassification[nInd].Angle == 100 then - -- verifico se va nestato manualmente + if bFound or AngleClassification[nInd].Angle == 100 then + -- verifico se va nestato manualmente if AngleClassification[nInd].bManual then -- trovo il punto della lista dove inserirlo local nIdx = -1 - local bOnOppositeSide = false - for nInd2 = 1, #vManuallyDone do + local bOnOppositeSide = false + for nInd2 = 1, #vManuallyDone do -- verifico se il pezzo può stare sull'altro angolo local bOnlyOnRef = EgtGetInfo( AngleClassification[nInd].PartId, "OnlyOnRefSide", 'b') local bCanBeOnOtherAngle = not bOnlyOnRef and ( not AngleClassification[nInd].bDrill or - ( AngleClassification[nInd].bDrill and not AngleClassification[nInd].bLongDrill and RawParts[vManuallyDone[nInd2].RawPartId].Width >= WD.MINRAWY_HOR_DRILL)) + ( AngleClassification[nInd].bDrill and not AngleClassification[nInd].bLongDrill and + RawParts[vManuallyDone[nInd2].RawPartId].Width > s_dMinRawYHorDrill - GEO.EPS_SMALL)) if #(vManuallyDone[nInd2].Parts) == 0 then - -- verifico che il pezzo stia in questo grezzo + -- verifico che il pezzo stia in questo grezzo local b3Part = EgtGetBBoxGlob( AngleClassification[nInd].PartId, GDB_BB.STANDARD) if b3Part:getDimX() < RawParts[vManuallyDone[nInd2].RawPartId].Len and b3Part:getDimY() < RawParts[vManuallyDone[nInd2].RawPartId].Width then nIdx = nInd2 - break + break end elseif #(vManuallyDone[nInd2].Parts) == 1 and bCanBeOnOtherAngle then - -- verifico se il pezzo già posizionato nell'angolo non ha fori lunghi - if not vManuallyDone[nInd2].Parts[1].bLongDrill then + -- verifico se il pezzo già posizionato nell'angolo non ha fori lunghi + if not vManuallyDone[nInd2].Parts[1].bLongDrill then -- oriento il pezzo in modo ottimale per andare su quell'angolo - local sRefOrig - if WD.ORIG_CORNER == 'TL' then sRefOrig = 'BL' end - if WD.ORIG_CORNER == 'BL' then sRefOrig = 'TL' end - if WD.ORIG_CORNER == 'TR' then sRefOrig = 'BR' end - if WD.ORIG_CORNER == 'BR' then sRefOrig = 'TR' end + local sRefOrig + if s_sOrigCorner == 'TL' then sRefOrig = 'BL' end + if s_sOrigCorner == 'BL' then sRefOrig = 'TL' end + if s_sOrigCorner == 'TR' then sRefOrig = 'BR' end + if s_sOrigCorner == 'BR' then sRefOrig = 'TR' end local bManTmp local res = ClassifyAngles( AngleClassification[nInd].PartId, RawParts[vManuallyDone[nInd2].RawPartId], sRefOrig, bManTmp, dMinSheetWidth) - -- verifico sia compatibile con pezzo già inserito + -- verifico sia compatibile con pezzo già inserito local b3OtherPart = EgtGetBBoxGlob( vManuallyDone[nInd2].Parts[1].Id, GDB_BB.STANDARD) local b3Part = EgtGetBBoxGlob( AngleClassification[nInd].PartId, GDB_BB.STANDARD) - local dExtra = 2 * NEST.KERF + WD.SIDEMILL_DIAM_DOWN + 1 + local dExtra = 2 * NEST.KERF + s_dSideMillDiamDown + 1 -- se è compatibile assegno questa rotazione al pezzo if b3Part:getDimY() + b3OtherPart:getDimY() + dExtra < RawParts[vManuallyDone[nInd2].RawPartId].Width then nIdx = nInd2 bOnOppositeSide = true -- aggiorno le info di rotazione - if res.nRotate > 0 then + if res.nRotate > 0 then local nPartRot = EgtGetInfo( AngleClassification[nInd].PartId, "ROTATED", 'i') or 0 local nTotRot = nPartRot - res.nRotate nTotRot = EgtIf( nTotRot < 0, nTotRot + 360, nTotRot) EgtSetInfo( AngleClassification[nInd].PartId, "ROTATED", nTotRot) EgtSetInfo( AngleClassification[nInd].PartId, "MODIFIEDFORNEST", 1) - end - break + end + break end -- altrimenti lo riporto nella sua posizione originaria EgtRotate( AngleClassification[nInd].PartId, b3Part:getCenter(), Z_AX(), - res.nRotate, GDB_RT.GLOB) - end + end end end -- nesto il pezzo a mano - if nIdx ~= -1 then - -- aree di lavorazione + if nIdx ~= -1 then + -- aree di lavorazione local nToolOutlineIds = ComputeToolOutlines( AngleClassification[nInd].PartId) local sInfo = "" - for nInd = 1, #nToolOutlineIds do + for nInd = 1, #nToolOutlineIds do sInfo = sInfo .. tostring(nToolOutlineIds[nInd]) .. "," end -- salvo tra le info del pezzo gli id delle sue aree di lavorazione @@ -1341,15 +1352,15 @@ local function ComputeRestrictedZones( RawParts) EgtSetInfo( AngleClassification[nInd].PartId, "ToolOutlines", sInfo) end - -- calcolo defect corrispondente al pezzo + -- calcolo defect corrispondente al pezzo local PartTab = CreateDefectOnAngle( AngleClassification[nInd].PartId, RawParts[vManuallyDone[nIdx].RawPartId], AngleClassification[nInd].bLongDrill, bOnOppositeSide) PartTab.bLongDrill = AngleClassification[nInd].bLongDrill table.insert( vManuallyDone[nIdx].Parts, PartTab) table.insert( vPartsManuallyDone, tonumber( AngleClassification[nInd].PartId)) else - -- aggiungo info per il nesting per ricordare che andrà su angolo - EgtSetInfo( AngleClassification[nInd].PartId, "NestOnAngle", 1) + -- aggiungo info per il nesting per ricordare che andrà su angolo + EgtSetInfo( AngleClassification[nInd].PartId, "NestOnAngle", 1) end else -- se non va nestato manualmente segno info per nesting @@ -1357,14 +1368,14 @@ local function ComputeRestrictedZones( RawParts) end else - -- se non ho più angoli a disposizione lo metto sul lato + -- se non ho più angoli a disposizione lo metto sul lato EgtSetInfo(AngleClassification[nInd].PartId, "NestOnEdge", 1) end else EgtSetInfo(AngleClassification[nInd].PartId, "NestOnEdge", 1) - end - + end + end local nInd = 1 @@ -1373,14 +1384,13 @@ local function ComputeRestrictedZones( RawParts) table.remove( vManuallyDone, nInd) else nInd = nInd + 1 - end + end end - return vManuallyDone, vPartsManuallyDone + return vManuallyDone, vPartsManuallyDone end - - +------------------------------------------------------------------ -- Funzione che sposta e aggiunge pezzi per nesting local function AddRawParts(RawParts, vDoneManually) @@ -1405,13 +1415,13 @@ local function AddRawParts(RawParts, vDoneManually) -- aggiungo defects for nInd2 = 1, #(vDoneManually[nInd].Parts) do EgtAutoNestAddDefectToSheet( SheetPartId, vDoneManually[nInd].Parts[nInd2].DefectId) - end + end vDoneManually[nInd].SheetId = SheetPartId nTotSheetWithDefects = nTotSheetWithDefects + 1 - end - end + end + end - -- pannelli senza pezzi inseriti manualmente + -- pannelli senza pezzi inseriti manualmente local SheetPartId = EgtGroup(GDB_ID.ROOT) table.insert( RawParts[nIndex].PartId, SheetPartId) EgtSetName(SheetPartId, "Sheet") @@ -1422,12 +1432,12 @@ local function AddRawParts(RawParts, vDoneManually) EgtSetName(SheetOutlineId, OUTLINE) -- creo foglio per nesting - EgtAutoNestAddSheet( SheetPartId, SheetOutlineId, NEST.KERF, 1, RawParts[nIndex].Qty - nTotSheetWithDefects) -- EgtAutoNestAddSheet( SheetId, OutlineId, dKerf, nPriority, nCount) + EgtAutoNestAddSheet( SheetPartId, SheetOutlineId, NEST.KERF, 1, RawParts[nIndex].Qty - nTotSheetWithDefects) + -- EgtAutoNestAddSheet( SheetId, OutlineId, dKerf, nPriority, nCount) end end - - +------------------------------------------------------------------ local function AddParts(RawParts, vPartsDoneManually) -- cerco la width massima dei grezzi @@ -1435,24 +1445,24 @@ local function AddParts(RawParts, vPartsDoneManually) for nIndex = 1, #RawParts do if RawParts[nIndex].Width > dRawMaxWidth then dRawMaxWidth = RawParts[nIndex].Width - end - end + end + end - -- valori correttivi per vincoli StripX e StripY + -- valori correttivi per vincoli StripX e StripY local dStripYCorr = GEO.EPS_SMALL local dStripXCorr = GEO.EPS_SMALL - if NEST.CORNER == NST_CORNER.TL or NEST.CORNER == NST_CORNER.TR then + if NEST.CORNER == NST_CORNER.TL or NEST.CORNER == NST_CORNER.TR then dStripYCorr = 0.1 - GEO.EPS_SMALL - end - if NEST.CORNER == NST_CORNER.BR or NEST.CORNER == NST_CORNER.TR then + end + if NEST.CORNER == NST_CORNER.BR or NEST.CORNER == NST_CORNER.TR then dStripXCorr = 0.1 - GEO.EPS_SMALL - end + end local nTotParts = 0 for _ in pairs( PART) do nTotParts = nTotParts + 1 end local nPartIndex = 0 -- ciclo su pezzi per aggiungerli al nesting - for nPartId, nCount in pairs( PART) do repeat + for nPartId, nCount in pairs( PART) do repeat -- conto quanti pezzi di questo tipo sono già stati posizionati a mano nManuallyDone = 0 @@ -1464,18 +1474,18 @@ local function AddParts(RawParts, vPartsDoneManually) if nManuallyDone == nCount then -- se tutti posizionati passo al pezzo successivo - break + break else -- posiziono con il nesting solo quelli mancanti nCount = nCount - nManuallyDone - end + end nPartIndex = nPartIndex + 1 -- calcolo bbox pezzo per rotazioni - local b3Part = EgtGetBBoxGlob( nPartId, GDB_BB.STANDARD) + local b3Part = EgtGetBBoxGlob( nPartId, GDB_BB.STANDARD) - -- recupero eventuali stati di flip e rotazione dalle info del pezzo + -- recupero eventuali stati di flip e rotazione dalle info del pezzo local bFlipNest = true local bFlip = false local bRotNest = true @@ -1484,14 +1494,14 @@ local function AddParts(RawParts, vPartsDoneManually) -- flip local bManualFlip = EgtGetInfo( nPartId, "MANUALFLIP", 'b') - if bManualFlip then + if bManualFlip then bFlipNest = false elseif EgtExistsInfo( nPartId, "NestFlip") then bFlipNest = EgtGetInfo( nPartId, "NestAllowFlip", 'b') bFlip = EgtGetInfo( nPartId, "NestFlip", 'b') end - -- rotation + -- rotation local bManualRot = EgtGetInfo( nPartId, "MANUALROT", 'b') if bManualRot then bRotNest = false @@ -1502,67 +1512,19 @@ local function AddParts(RawParts, vPartsDoneManually) -- verifico se rotazione è valida (pezzo è contenuto nel grezzo) local bValidRotationInRaw = b3Part:getDimX() < RawParts[1].Len - 2 * NEST.KERF + GEO.EPS_SMALL and b3Part:getDimY() < dRawMaxWidth - 2 * NEST.KERF + GEO.EPS_SMALL if not bValidRotationInRaw then - bRotNest = true - nStepRotNest = 90 - end + bRotNest = true + nStepRotNest = 90 + end end - -- aggiungo stato a lista stati del pezzo - -- table.insert( PartStates, { PartId = tonumber(nPartId), Flip = bFlip, Rotate = nRotate}) - - --- local bFtDown = false --- local vPartProc = WE.CollectFeatures( nPartId, b3Raw) --- for nInd = 1, #vPartProc do --- if LapJoint.Identify( vPartProc[nInd]) then --- local nFacOpt, dMinElev, nFacOpt2, dMinElev2 = WL.GetFaceWithMostAdj( vPartProc[nInd].Id, vPartProc[nInd].PartId) --- if nFacOpt >= 0 then --- local vtN = EgtSurfTmFacetNormVersor( vPartProc[nInd].Id, nFacOpt, GDB_ID.ROOT) --- if vtN:getZ() < -0.09 then --- bFtDown = true --- break --- end --- end --- end --- LapJoint.FlipClassify(vPartProc[nInd]) --- end --- -- ruoto se necessario --- if bFtDown then --- local b3Solid = EgtGetBBoxGlob(nPartId, GDB_BB.IGNORE_TEXT) --- local ptRotCen = b3Solid:getCenter() --- EgtRotate( nPartId, ptRotCen, X_AX(), 180, GDB_RT.GLOB) --- end - --- -- recupero le feature di lavorazione della parete --- local bFtDown = false --- local vPartProc = WE.CollectFeatures( nPartId, b3Raw) --- for nInd = 1, #vPartProc do --- if LapJoint.Identify( vPartProc[nInd]) then --- local nFacOpt, dMinElev, nFacOpt2, dMinElev2 = WL.GetFaceWithMostAdj( vPartProc[nInd].Id, vPartProc[nInd].PartId) --- if nFacOpt >= 0 then --- local vtN = EgtSurfTmFacetNormVersor( vPartProc[nInd].Id, nFacOpt, GDB_ID.ROOT) --- if vtN:getZ() < -0.09 then --- bFtDown = true --- break --- end --- end --- end --- end --- -- ruoto se necessario --- if bFtDown then --- local b3Solid = EgtGetBBoxGlob(nPartId, GDB_BB.IGNORE_TEXT) --- local ptRotCen = b3Solid:getCenter() --- EgtRotate( nPartId, ptRotCen, X_AX(), 180, GDB_RT.GLOB) --- end - -- recupero vecchio contorno se già presente local nOutlineLayer = EgtGetFirstNameInGroup(nPartId, "Outline") local nOldOutline = EgtGetFirstNameInGroup(nOutlineLayer, 'ON_TMP') - local nOutline, nCnt + local nOutline, nCnt -- se l'outline non è stato calcolato oppure il pezzo è stato modificato, lo ricalcolo local bPartIsModified = EgtGetInfo( nPartId, "MODIFIEDFORNEST", 'b') - if not nOldOutline or bPartIsModified then + if not nOldOutline or bPartIsModified then -- elimino il vecchio contorno se pesente while ( nOldOutline) do @@ -1604,31 +1566,6 @@ local function AddParts(RawParts, vPartsDoneManually) break end end - - --local frSum = EgtSurfFlatRegion(nOutlineLayer, nOutline) - --EgtSaveFile("c:\\Temp\\ProvaNesting.nge") - -- -- per ogni contorno creo flat region e le sommo - -- for nIndex = 0, nCnt - 1 do - -- EgtScale( nOutline + nIndex, GLOB_FRM(), 1, 1, 0, GDB_RT.GLOB) - -- EgtModifyCurveExtrusion( nOutline + nIndex, Z_AX(), GDB_RT.GLOB) - -- local frCurr = EgtSurfFlatRegion(nOutlineLayer, nOutline + nIndex) - -- if frCurr then - -- if frSum then - -- EgtSurfFrAdd(frSum, frCurr) - -- else - -- frSum = frCurr - -- end - -- end - -- EgtErase(frCurr) - -- end - -- --EgtSaveFile("c:/Temp/ProvaNesting.nge") - -- -- calcolo contorno della flat region somma - -- nCurrOutline = EgtExtractSurfFrChunkLoops(frSum, 0, nOutlineLayer) - -- EgtErase(frSum) - -- -- cancello contorni - -- for nIndex = 0, nCnt do - -- EgtErase(nOutline + nIndex) - -- end end if nCurrOutline and nCurrOutline ~= GDB_ID.NULL then @@ -1640,39 +1577,8 @@ local function AddParts(RawParts, vPartsDoneManually) local BBox = EgtGetBBoxGlob(nBox, GDB_BB.STANDARD) nOutline = EgtRectangle2P(nOutlineLayer, Point3d( BBox:getMin():getX(), BBox:getMin():getY(), 0), Point3d( BBox:getMax():getX(), BBox:getMax():getY(), 0), GDB_RT.GLOB) EgtOutLog("Impossible creating silhouette for part " .. tostring(nPartId)) - nCnt = 1 + nCnt = 1 end - --if nCnt == 0 then - -- -- se non ho trovato contorno, lo recupero dal Box - -- local nBoxLayer = EgtGetFirstNameInGroup(nPartId, "Box") - -- local nBox = EgtGetFirstNameInGroup(nBoxLayer, "Box") - -- local BBox = EgtGetBBoxGlob(nBox, GDB_BB.STANDARD) - -- nOutline = EgtRectangle2P(nOutlineLayer, Point3d( BBox:getMin():getX(), BBox:getMin():getY(), 0), Point3d( BBox:getMax():getX(), BBox:getMax():getY(), 0), GDB_RT.GLOB) - -- EgtOutLog("Impossible creating silhouette for part " .. tostring(nPartId)) - --else - -- --EgtScale( nOutline, GLOB_FRM(), 1, 1, 0, GDB_RT.GLOB) - -- --EgtModifyCurveExtrusion( nOutline, Z_AX(), GDB_RT.GLOB) - -- --EgtSaveFile("c:/Temp/ProvaNesting.nge") - -- EgtScale( nOutline, GLOB_FRM(), 1, 1, 0, GDB_RT.GLOB) - -- EgtModifyCurveExtrusion( nOutline, Z_AX(), GDB_RT.GLOB) - -- local frSum = EgtSurfFlatRegion(nOutlineLayer, nOutline) - -- EgtSaveFile("c:\\Temp\\ProvaNesting.nge") - -- -- per ogni contorno creo flat region e le sommo - -- for nIndex = 1, nCnt - 1 do - -- EgtScale( nOutline + nIndex, GLOB_FRM(), 1, 1, 0, GDB_RT.GLOB) - -- EgtModifyCurveExtrusion( nOutline + nIndex, Z_AX(), GDB_RT.GLOB) - -- local frCurr = EgtSurfFlatRegion(nOutlineLayer, nOutline + nIndex) - -- if frCurr then - -- EgtSurfFrAdd(frSum, frCurr) - -- end - -- end - -- -- calcolo contorno della flat region somma - -- nOutline = EgtExtractSurfFrChunkLoops(frSum, 0, nOutlineLayer) - -- -- cancello contorni successivi - -- for nIndex = 1, nCnt do - -- EgtErase(nOutline + nIndex) - -- end - --end EgtSetName( nOutline, 'ON_TMP') EgtSetStatus( nOutline, 0) @@ -1684,81 +1590,6 @@ local function AddParts(RawParts, vPartsDoneManually) local vOutlinesIds = EgtGetNameInGroup( nOutlineLayer, 'ON_TMP') nCnt = #vOutlinesIds end - - - --[[ local nOutline - local nTrimesh - local bFirst = true - local bSecond = false - local bUseBox = false - nTrimesh = EgtGetFirstNameInGroup( nOutlineLayer, "1-Out") - if not nTrimesh then - nTrimesh = EgtGetFirstNameInGroup( nOutlineLayer, "2-Out") - end - if not nTrimesh then - nTrimesh = EgtGetFirstNameInGroup( nOutlineLayer, "3-Out") - end - if not nTrimesh then - nTrimesh = EgtGetFirstNameInGroup( nOutlineLayer, "4-Out") - end - -- se trovato contorno - if nTrimesh then - -- recupero la curva associata - local nAuxId = EgtGetInfo(nTrimesh, "AUXID", 'i') - nOutline = nTrimesh + nAuxId - -- verifico che il contorno sia verticale - local nFacetCount = EgtSurfTmFacetCount(nTrimesh) - for nIndex = 0, nFacetCount - 1 do - local vtNorm = EgtSurfTmFacetNormVersor(nTrimesh, nIndex, GDB_ID.ROOT) - if abs( vtNorm:getZ()) > 10 * GEO.EPS_SMALL then - bUseBox = true - break - end - end - -- se due compo o una e lati inclinati - if bUseBox then - -- calcolo box della trimesh - local b3Outline = EgtGetBBoxGlob(nTrimesh, GDB_BB.IGNORE_TEXT) - local ptP1 = Point3d( b3Outline:getMin():getX(), b3Outline:getMin():getY(), 0) - local ptP2 = Point3d( b3Outline:getMax():getX(), b3Outline:getMax():getY(), 0) - -- creo outline del box - nOutline = EgtRectangle2P(nOutlineLayer, ptP1, ptP2, GDB_RT.GLOB) - EgtSetStatus(nOutline, GDB_ST.OFF) - end - -- altrimenti cerco la regione sopra - else - -- cancello precedenti contorni calcolati - local nOldONId = EgtGetFirstNameInGroup( nOutlineLayer, 'ON_TMP') - if nOldONId then - EgtErase( nOldONId) - end - -- cerco la regione sopra - local nReg - for i = 1, 4 do - local sRegName = string.format( '%d-Top', i) - nReg = EgtGetFirstNameInGroup( nOutlineLayer, sRegName) - if nReg then - local vtNorm = EgtSurfFrNormVersor( nReg, GDB_ID.ROOT) - if vtNorm:getZ() > 0.99 then break end - end - end - if not nReg then - EgtOutLog("Errore: regione superiore non trovata") - end - -- recupero contorno della regione - local OutId, nCnt = EgtExtractSurfFrChunkLoops( nReg, 0, nOutlineLayer) - if OutId and nCnt > 1 then - for i = 2, nCnt do - EgtErase( OutId + i - 1) - end - end - if OutId then - EgtSetName( OutId, 'ON_TMP') - nOutline = OutId - end - end - ]]-- - -- calcolo aree lavorazione local nToolOutlineIds = ComputeToolOutlines( nPartId) @@ -1772,9 +1603,9 @@ local function AddParts(RawParts, vPartsDoneManually) -- EgtAutoNestAddPart( PartId, OutlineId, bCanFlip, bCanRotate, dRotStep, nPriority, nCount) end -- aggiungo finestre - for nInd = 1, nCnt - 1 do + for nInd = 1, nCnt - 1 do local _, _, dArea = EgtCurveArea( nOutline + nInd) - if dArea and dArea > WD.NEST_HOLE_MIN_AREA then + if dArea and dArea > s_dNestHoleMinArea then EgtModifyCurveExtrusion( nOutline + nInd, Z_AX(), GDB_RT.GLOB) EgtAutoNestAddHoleToPart( nPartId, nOutline + nInd) end @@ -1782,7 +1613,7 @@ local function AddParts(RawParts, vPartsDoneManually) -- aggiungo aree di lavorazione del pezzo local sInfo = "" - for nInd = 1, #nToolOutlineIds do + for nInd = 1, #nToolOutlineIds do EgtAutoNestAddToolOutlineToPart( nPartId, nToolOutlineIds[nInd]) sInfo = sInfo .. tostring(nToolOutlineIds[nInd]) .. "," end @@ -1791,7 +1622,7 @@ local function AddParts(RawParts, vPartsDoneManually) EgtSetInfo( nPartId, "ToolOutlines", sInfo) end - -- Eventuali vincoli StripX e StripY + -- Eventuali vincoli StripX e StripY local bOnEdge = EgtGetInfo(nPartId, "NestOnEdge", 'b') local bOnAngle = EgtGetInfo(nPartId, "NestOnAngle", 'b') if bOnEdge or bOnAngle then @@ -1801,9 +1632,9 @@ local function AddParts(RawParts, vPartsDoneManually) -- punto di riferimento sul pezzo local ptRef - local dval = 10 - if ( WD.ORIG_CORNER == 'TL' or WD.ORIG_CORNER == 'TR') then - ptRef = Point3d( b3Part:getMax():getX() - b3Part:getDimX() / 2, b3Part:getMax():getY() - dval, 0) + local dval = 10 + if ( s_sOrigCorner == 'TL' or s_sOrigCorner == 'TR') then + ptRef = Point3d( b3Part:getMax():getX() - b3Part:getDimX() / 2, b3Part:getMax():getY() - dval, 0) else ptRef = Point3d( b3Part:getMin():getX() + b3Part:getDimX() / 2, b3Part:getMin():getY() + dval, 0) end @@ -1811,35 +1642,37 @@ local function AddParts(RawParts, vPartsDoneManually) -- vincolo StripY local bOnlyOnRefSide = EgtGetInfo( nPartId, "OnlyOnRefSide", 'b') if bOnlyOnRefSide then - if WD.ORIG_CORNER == 'BL' or WD.ORIG_CORNER == 'BR' then + if s_sOrigCorner == 'BL' or s_sOrigCorner == 'BR' then EgtAutoNestSetStripYconstraintToPart( nPartId, ptRef, NEST.KERF + dval + dStripYCorr, 100000) else EgtAutoNestSetStripYconstraintToPart( nPartId, ptRef, - 1000, dRawMaxWidth + 1000 - ( NEST.KERF + dval - dStripYCorr)) - end + end else EgtAutoNestSetStripYconstraintToPart( nPartId, ptRef, NEST.KERF + dval + dStripYCorr, dRawMaxWidth - 2 * ( NEST.KERF + dval)) end -- se sull'angolo aggiungo anche vincolo StripX if bOnAngle then - if WD.ORIG_CORNER == 'TL' or WD.ORIG_CORNER == 'BL' then + if s_sOrigCorner == 'TL' or s_sOrigCorner == 'BL' then EgtAutoNestSetStripXconstraintToPart( nPartId, ptRef, NEST.KERF + b3Part:getDimX() / 2 + dStripXCorr, 100000) else - EgtAutoNestSetStripXconstraintToPart( nPartId, ptRef, -100, RawParts[1].Len + 100 - NEST.KERF - b3Part:getDimX() / 2 + dStripXCorr) + EgtAutoNestSetStripXconstraintToPart( nPartId, ptRef, -100, RawParts[1].Len + 100 - NEST.KERF - b3Part:getDimX() / 2 + dStripXCorr) end - end + end end -- verifico se anullato nesting if EgtProcessEvents( 100 + ( nPartIndex / nTotParts * 100), 0) == 1 then return false end - until true + until true end return true end +------------------------------------------------------------------ +------------------------------------------------------------------ -- Inizializzo contatori errori e avvisi local nErrCnt = 0 local nWarnCnt = 0 @@ -1973,7 +1806,7 @@ if bNestingOk then end end - -- aggiungo pezzi nestati a mano + -- aggiungo pezzi nestati a mano nPartCount = 0 for nInd = 1, #vDoneManually do if vDoneManually[nInd].SheetId == nId then @@ -1995,18 +1828,17 @@ if bNestingOk then for str in string.gmatch(sToolOutlines, "([^"..",".."]+)") do EgtCopyGlob( tonumber(str), nToolOutlinesGrp) - end - end + end + end -- applico flip, rotazione e traslazione pezzo e box da nesting EgtSetInfo( nMachGroup, "PART" .. nPartCount, nPartDuploId .. "," .. EgtNumToString( vDoneManually[nInd].Parts[nInd2].posX, 3) .. "," .. EgtNumToString( vDoneManually[nInd].Parts[nInd2].posY, 3) .. "," .. 0 .."," .. 0) EgtSetInfo( nPartDuploId, "POSX", vDoneManually[nInd].Parts[nInd2].posX) - EgtSetInfo( nPartDuploId, "POSY", vDoneManually[nInd].Parts[nInd2].posY) - end - end + EgtSetInfo( nPartDuploId, "POSY", vDoneManually[nInd].Parts[nInd2].posY) + end + end end - end -- altrimenti pezzo @@ -2019,22 +1851,7 @@ if bNestingOk then if nMachGroup and nMachGroup ~= GDB_ID.NULL then -- creo pezzo copia local nPartDuploId = EgtDuploNew( nId) - -- applico flip e rotazioni fatte durante verifica posizionamento pezzo - -- local b3Part = EgtGetBBoxGlob( nPartDuploId, GDB_BB.STANDARD) - local nPartInd - -- for nInd = 1, #PartStates do - -- if PartStates[nInd].PartId == nId then - -- -- if PartStates[nInd].Flip then - -- -- EgtRotate( nPartDuploId, b3Part:getCenter(), X_AX(), 180, GDB_RT.GLOB) - -- -- end - -- -- if PartStates[nInd].Rotate and PartStates[nInd].Rotate > 0 then - -- -- EgtRotate( nPartDuploId, b3Part:getCenter(), Z_AX(), PartStates[nInd].Rotate, GDB_RT.GLOB) - -- -- end - -- nPartInd = nInd - -- end - -- end - - + local nPartInd -- aggiungo le curve corrispondenti alle aree di lavorazione del pezzo local sToolOutlines = EgtGetInfo( nId, "ToolOutlines", 's') @@ -2049,8 +1866,8 @@ if bNestingOk then for str in string.gmatch(sToolOutlines, "([^"..",".."]+)") do EgtCopyGlob( tonumber(str), nToolOutlinesGrp) - end - end + end + end -- applico flip, rotazione e traslazione pezzo e box da nesting if nFlag == 1 then @@ -2061,13 +1878,13 @@ if bNestingOk then local nBoxLayerId = EgtGetFirstNameInGroup( nPartDuploId, "Box") local nBoxId = EgtGetFirstNameInGroup( nBoxLayerId, "Box") - local PartBBox = EgtGetBBoxGlob(nBoxId, GDB_BB.STANDARD) + local PartBBox = EgtGetBBoxGlob(nBoxId, GDB_BB.STANDARD) local ptPos = Point3d( PartBBox:getMin():getX(), PartBBox:getMin():getY(), 0) EgtSetInfo( nMachGroup, "PART" .. nPartCount, nPartDuploId .. "," .. EgtNumToString( ptPos:getX() + dXCorr, 3) .. "," .. EgtNumToString( ptPos:getY() + dYCorr, 3) .. "," .. 0 .."," .. 0) EgtSetInfo( nPartDuploId, "POSX", ptPos:getX() + dXCorr) EgtSetInfo( nPartDuploId, "POSY", ptPos:getY() + dYCorr) - local nPartRot = EgtGetInfo( nId, "ROTATED", 'i') or 0 + local nPartRot = EgtGetInfo( nId, "ROTATED", 'i') or 0 local nTotRot = dAngRot - nPartRot nTotRot = EgtIf( nTotRot < 0, nTotRot + 360, nTotRot) EgtSetInfo( nPartDuploId, "ROT", nTotRot) @@ -2076,7 +1893,6 @@ if bNestingOk then nPartFlip = EgtIf( nPartFlip == 180, 1, 0) local nTotFlip = EgtIf( nPartFlip ~= nFlag, 180, 0) EgtSetInfo( nPartDuploId, "FLIP", nTotFlip) - end end end @@ -2104,10 +1920,10 @@ if bNestingOk then end -- aggiungo pezzi nestati a mano - nPartCount = 0 + nPartCount = 0 for nInd2 = 1, #(vDoneManually[nInd].Parts) do nPartCount = nPartCount + 1 - local nPartDuploId = EgtDuploNew( vDoneManually[nInd].Parts[nInd2].Id) + local nPartDuploId = EgtDuploNew( vDoneManually[nInd].Parts[nInd2].Id) -- aggiungo le curve corrispondenti alle aree di lavorazione del pezzo local sToolOutlines = EgtGetInfo( vDoneManually[nInd].Parts[nInd2].Id, "ToolOutlines", 's') @@ -2122,18 +1938,17 @@ if bNestingOk then for str in string.gmatch(sToolOutlines, "([^"..",".."]+)") do EgtCopyGlob( tonumber(str), nToolOutlinesGrp) - end - end + end + end -- applico flip, rotazione e traslazione pezzo e box da nesting EgtSetInfo( nMachGroup, "PART" .. nPartCount, nPartDuploId .. "," .. EgtNumToString( vDoneManually[nInd].Parts[nInd2].posX, 3) .. "," .. EgtNumToString( vDoneManually[nInd].Parts[nInd2].posY, 3) .. "," .. 0 .."," .. 0) EgtSetInfo( nPartDuploId, "POSX", vDoneManually[nInd].Parts[nInd2].posX) EgtSetInfo( nPartDuploId, "POSY", vDoneManually[nInd].Parts[nInd2].posY) - end - end + end + end end - -- creo grezzi per ogni gruppo di lavorazione local MachGroupToTCnt = EgtGetMachGroupCount() local MachGroupIndex = 0 @@ -2159,27 +1974,27 @@ if bNestingOk then local nRawPartId = EgtGetFirstRawPart() -- recupero box grezzo ridotto della tolleranza local b3Raw = EgtGetRawPartBBox( nRawPartId) - b3Raw:expand( - WD.INSIDE_RAW_TOL) + b3Raw:expand( - s_dInsideRawTol) EgtOutLog( 'RawBox='..tostring( b3Raw)) local nPartDuploId = EgtGetFirstPartInRawPart( nRawPartId) while nPartDuploId do local vPartProc = WE.CollectFeatures( nPartDuploId) - for ProcIndex = 1, #vPartProc do + for ProcIndex = 1, #vPartProc do local Proc = vPartProc[ProcIndex] if LapJoint.Identify( Proc) then -- cerco la faccia rivolta verso l'alto e la faccia rivolta verso il basso local nFaceInd = -1 - local nFaceDownInd = -1 + local nFaceDownInd = -1 for nIdx = 0, Proc.Fct - 1 do local vtN = EgtSurfTmFacetNormVersor( Proc.Id, nIdx, GDB_ID.ROOT) if vtN:getZ() > 0.95 then nFaceInd = nIdx elseif vtN:getZ() < - 0.95 then nFaceDownInd = nIdx - end - end + end + end -- se è lap joint dall'alto if nFaceInd ~= -1 and nFaceDownInd == -1 then local bResetQ = false @@ -2207,7 +2022,7 @@ if bNestingOk then end end end - + elseif DoubleCut.Identify( Proc) then -- verifico se due facce e rivolto verso l'alto if Proc.Fct == 2 then @@ -2215,8 +2030,8 @@ if bNestingOk then vtN[1] = EgtSurfTmFacetNormVersor( Proc.Id, 0, GDB_ID.ROOT) vtN[2] = EgtSurfTmFacetNormVersor( Proc.Id, 1, GDB_ID.ROOT) - if ( vtN[1]:getZ() >= 0.95 or vtN[2]:getZ() >= 0.95) then - local nFaceInd = EgtIf( vtN[1]:getZ() >= 0.95, 0, 1) + if ( vtN[1]:getZ() >= 0.95 or vtN[2]:getZ() >= 0.95) then + local nFaceInd = EgtIf( vtN[1]:getZ() >= 0.95, 0, 1) local ptCen = EgtSurfTmFacetCenter( Proc.Id, nFaceInd, GDB_ID.ROOT) -- se all'interno rimuovo info Q if EnclosesPointXY( b3Raw, ptCen) then @@ -2254,4 +2069,4 @@ if nSheetDefectsGrp and nSheetDefectsGrp ~= GDB_ID.NULL then EgtErase( nSheetDef -- EgtSaveFile( "C:\\EgtData\\EgtBEAMWALL\\Temp\\file.nge") -EgtOutLog( ' +++ NestProcess completed') +EgtOutLog( ' +++ NestProcess completed') \ No newline at end of file