diff --git a/LuaLibs/CalcToolPath.lua b/LuaLibs/CalcToolPath.lua index 881c8c5..a761c42 100644 --- a/LuaLibs/CalcToolPath.lua +++ b/LuaLibs/CalcToolPath.lua @@ -1540,9 +1540,10 @@ local function VerifyRibsLead( nId, nRibId, bInVsOut, nGrpTmp) local dOverlap = max( dShellOverlap, dStrandOverlap) local nOrigRib = EgtGetInfo( nRibId, KEY_ORIGINAL_RIB, 'i') local dLen = EgtCurveLength( nId) + local nParentId = EgtGetParent( nId) -- porto il lead nel gruppo locale - local nLeadLoc = EgtCopyGlob( nId, nGrpTmp) + EgtRelocateGlob( nId, nGrpTmp) -- 1) verifico se interseca altri setti, lead in, lead out o collegamenti -- recupero gli id degli elementi da controllare @@ -1568,9 +1569,12 @@ local function VerifyRibsLead( nId, nRibId, bInVsOut, nGrpTmp) table.insert( vCheckIds, nCurrId) end else - local nCurrOrigRib = EgtGetInfo( nCurrId, KEY_ORIGINAL_RIB, 'i') - if nOrigRib ~= nCurrOrigRib then - table.insert( vCheckIds, nCurrId) + local nRibType = EgtGetInfo( nCurrId, KEY_RIBS_TYPE, 'i') + if nRibType ~= RIB_TYPE.UNBOUNDED then + local nCurrOrigRib = EgtGetInfo( nCurrId, KEY_ORIGINAL_RIB, 'i') + if nOrigRib ~= nCurrOrigRib then + table.insert( vCheckIds, nCurrId) + end end end end @@ -1588,44 +1592,80 @@ local function VerifyRibsLead( nId, nRibId, bInVsOut, nGrpTmp) table.insert( vCheckIds, vRibsPaths[i]) end end - -- controllo se intersezione + + -- creo la superficie occupata dagli id da controllare + local nSrf for i = 1, #vCheckIds do local dCurrStrand = EgtGetInfo( vCheckIds[i], KEY_CRV_STRAND, 'd') or EgtGetInfo( vCheckIds[i], KEY_RIBS_STRAND, 'd') local dCurrOffs = dCurrStrand * 0.5 + ( 0.5 - dOverlap / 100) * dStrand - 50 * GEO.EPS_SMALL if dCurrOffs > GEO.EPS_SMALL then local nSrfCurr = EgtSurfFrFatCurve( nGrpTmp, vCheckIds[i], dCurrOffs, false) - if nSrfCurr then - -- EgtSetStatus( nSrfCurr, GDB_ST.OFF) - local nRes = EgtCurveWithRegionClassify( nLeadLoc, nSrfCurr) - if nRes ~= GDB_CRC.OUT then - return false + if not nSrf then + nSrf = nSrfCurr + else + EgtSurfFrAdd( nSrf, nSrfCurr) + end + end + end + + -- verifico di avere un tratto esterno consecutivo al setto + if nSrf then + local nOrigLead = EgtCopyGlob( nId, nGrpTmp) + local nRes, nCnt = EgtTrimCurveWithRegion( nId, nSrf, false, false) + if not nRes or nCnt == 0 then + return false + end + -- la curva di interesse รจ la prima se lead out o l'ultima se lead in + local nNewCrv = EgtIf( bInVsOut, nRes + nCnt - 1, nRes) + local ptRes = EgtIf( bInVsOut, EgtEP( nNewCrv, GDB_ID.ROOT), EgtSP( nNewCrv, GDB_ID.ROOT)) + local ptRib = EgtIf( bInVsOut, EgtSP( nRibId, GDB_ID.ROOT), EgtEP( nRibId, GDB_ID.ROOT)) + if not AreSamePointApprox( ptRes, ptRib) then + return false + end + EgtChangeId( nNewCrv, nId) + end + + -- 2) verifiche con il setto corrente + -- verifico non passi da altro estremo + local dParTest = EgtCurveParamAtPoint( nId, EgtIf( bInVsOut, EgtEP( nRibId, GDB_ID.ROOT), EgtSP( nRibId, GDB_ID.ROOT)), 100 * GEO.EPS_SMALL, GDB_RT.GLOB) + if dParTest then + return false + end + -- verifico se interrompere in corrispondenza di tratti lineari paralleli al setto che non sono sufficientemente lontani + local _, dParE = EgtCurveDomain( nId) + local nRibLoc = EgtCopyGlob( nRibId, nGrpTmp) + local vtDir = EgtMV( nRibLoc) + local dParRef = -1 + local dParCrv = 1 + for dParCrv = 0, dParE - 1 do + local vtS = EgtUV( nId, dParCrv, 1) + local vtE = EgtUV( nId, dParCrv + 1, -1) + local dLenCrv = EgtCurveCompoLength( nId, dParCrv) + if AreSameVectorApprox( vtS, vtE) and vtS * vtDir < - 1 + GEO.EPS_SMALL and dLenCrv > dStrand + GEO.EPS_SMALL then + local vtDist = EgtUP( nId, dParCrv + 0.5) - EgtMP( nRibLoc) + local vtOrthoDist = vtDist - ( vtDist * vtDir) * vtDir + local dDist = vtOrthoDist:len() + if dDist < dStrand + GEO.EPS_SMALL then + dParRef = dParCrv + if not bInVsOut then + break end end end end - - -- 2) verifiche con il setto corrente - -- verifico non passi da altro estremo - local dParTest = EgtCurveParamAtPoint( nLeadLoc, EgtIf( bInVsOut, EgtEP( nRibId, GDB_ID.ROOT), EgtSP( nRibId, GDB_ID.ROOT)), 100 * GEO.EPS_SMALL, GDB_RT.GLOB) - if dParTest then - return false - end - -- verifico se tratti lineari paralleli al setto sono sufficientemente lontani - local _, dParE = EgtCurveDomain( nLeadLoc) - local nRibLoc = EgtCopyGlob( nRibId, nGrpTmp) - local vtDir = EgtMV( nRibLoc) - local dParCrv = 1 - for dParCrv = 1, dParE do - local vtS = EgtUV( nLeadLoc, dParCrv - 1, 1) - local vtE = EgtUV( nLeadLoc, dParCrv, -1) - local dLenCrv = EgtCurveCompoLength( nLeadLoc, dParCrv - 1) - if AreSameVectorApprox( vtS, vtE) and vtS * vtDir < - 1 + GEO.EPS_SMALL and dLenCrv > dStrand + GEO.EPS_SMALL then - local vtDist = EgtUP( nLeadLoc, dParCrv - 0.5) - EgtMP( nRibLoc) - local vtOrthoDist = vtDist - ( vtDist * vtDir) * vtDir - local dDist = vtOrthoDist:len() - if dDist < dStrand + GEO.EPS_SMALL then + + if dParRef > - GEO.EPS_SMALL then + if bInVsOut then + local _, dE = EgtCurveDomain( nId) + if abs( dParRef + 1 - dE) < GEO.EPS_SMALL then -- la curva si cancella completamente return false end + EgtTrimCurveStartAtParam( nId, dParRef + 1) + else + if dParRef < GEO.EPS_SMALL then -- la curva si cancella completamente + return false + end + EgtTrimCurveEndAtParam( nId, dParRef) end end @@ -1635,7 +1675,7 @@ local function VerifyRibsLead( nId, nRibId, bInVsOut, nGrpTmp) if nCurrLI and EgtGetName( nCurrLI) == LEAD_IN_CRV then local nLeadInLoc = EgtCopyGlob( nCurrLI, nGrpTmp) -- verifico se intersezione fra curve - local _, nPnt, nCrv = EgtCurveCurveInters( nLeadLoc, nLeadInLoc, nGrpTmp) + local _, nPnt, nCrv = EgtCurveCurveInters( nId, nLeadInLoc, nGrpTmp) if nPnt ~= 0 or nCrv ~= 0 then return false end @@ -1658,14 +1698,24 @@ local function VerifyRibsLead( nId, nRibId, bInVsOut, nGrpTmp) end end end - + + local dNewLen = EgtCurveLength( nId) + if dNewLen < 100 * GEO.EPS_SMALL then + return false + end + if abs( dLen - dNewLen) > GEO.EPS_SMALL then + EgtOutLog( 'Warning : ' .. EgtGetName( nRibId) .. ' Lead' .. EgtIf( bInVsOut, 'In', 'Out') .. ' is shortened. Len = ' .. EgtNumToString( dNewLen) .. + ', SetLen = ' .. EgtNumToString( dLen) .. ' ( layer '.. tostring( s_nCurrIdx)..') - CalcToolPath' ) + end + + EgtRelocateGlob( nId, nParentId) return true end --------------------------------------------------------------------------------- local function PrepareRibLead( nCrvOffs, nRib, bInvert, bInVsOut, dPar, dLeadLen) - local nLeadId = EgtCopyGlob( nCrvOffs, nRib, EgtIf( bInVsOut, GDB_IN.BEFORE, GDB_IN.AFTER)) + local nLeadId = EgtCopyGlob( nCrvOffs, nRib, GDB_IN.AFTER) EgtChangeClosedCurveStart( nLeadId, dPar) -- oriento in modo che la curva parta da nRib if bInvert then @@ -1759,6 +1809,7 @@ local function FindCorrectRibLead( dPar, nRib, nCrvOffs, bLeadInvert, dLeadLen, end end + EgtRelocateGlob( nLeadId, nRib, EgtIf( bInVsOut, GDB_IN.BEFORE, GDB_IN.AFTER)) return nLeadId, bInvert end