diff --git a/LuaLibs/RunCalcSolids.lua b/LuaLibs/RunCalcSolids.lua index d38c36b..f6f1b2c 100644 --- a/LuaLibs/RunCalcSolids.lua +++ b/LuaLibs/RunCalcSolids.lua @@ -1,4 +1,4 @@ --- RunCalcSolids.lua by Egaltech s.r.l. 2022/10/10 +-- RunCalcSolids.lua by Egaltech s.r.l. 2022/11/02 -- Calcolo percorsi di lavoro per Stampa 3d -- Tabella per definizione modulo @@ -13,7 +13,7 @@ EgtOutLog( ' RunCalcSolids started', 1) local AMD = require( 'AddManData') -------------------------------------------------------------------- -s_dTol = 0.1 +local s_dTol = 0.1 --------------------------------------------------------------------- local function GetLayerParamsForSolidCalc( nPartId) @@ -30,22 +30,6 @@ local function CalcSectionParams( dStrand, dH) local dL = dStrand local dLm = dStrand / 10 local dHm = dH / 6 - -- recupero offset - --local dOffs = EgtGetInfo( s_nPartId, KEY_OFFSET_SLICE, 'd') - dOffs = 0 - if dOffs and dOffs > 0 then - -- calcolo area originale - local dArea = ( dL * dH) - ( dLm * dHm) - local dLM = ( dArea / dH) - ( dLm / 6) - if dOffs / 2 <= ( dL - dLM) then - dL = dL - dOffs / 2 - dLm = dL / 10 - dHm = (( dL * dH) - dArea) / dLm - else - EgtOutLog( 'Strand section not calculated on area. Too much overlap?') - end - end - local dD1 = 0.5 * dL - dLm local dD2 = 0.5 * dL - dD1 local dD3 = dHm @@ -180,30 +164,10 @@ end ---------------------------------------------------------------------- local function CreateStandardSolid( nCrvId, nSolidGrp, LayerParams, dStrand) - - local ptS = EgtSP( nCrvId, GDB_ID.ROOT) - local vtS = EgtSV( nCrvId, GDB_ID.ROOT) - vtS:rotate( LayerParams.vtSlicing, 90) - local ptE = EgtEP( nCrvId, GDB_ID.ROOT) - local vtE = EgtEV( nCrvId, GDB_ID.ROOT) - vtE:rotate( LayerParams.vtSlicing, -90) - -- creazione del solido aperto (tubo) - local nSectId = CreateSection( ptS, vtS, dStrand, LayerParams.dLayHeight, LayerParams.vtSlicing, nSolidGrp) - local nSrfId = EgtSurfTmSwept( nSolidGrp, nSectId, nCrvId, false, s_dTol) - EgtErase( nSectId) - if not nSrfId then return nil end - -- creazione del mezzo disco iniziale - local nSectS = CreateHalfSection( ptS, vtS, dStrand, LayerParams.dLayHeight, LayerParams.vtSlicing, nSolidGrp) - local nSrfS = EgtSurfTmByScrewing( nSolidGrp, nSectS, ptS, LayerParams.vtSlicing, 180, 0, false, s_dTol, GDB_RT.GLOB) - EgtErase( nSectS) - if not nSrfS then return nil end - -- creazione del mezzo disco finale - local nSectE = CreateHalfSection( ptE, vtE, dStrand, LayerParams.dLayHeight, LayerParams.vtSlicing, nSolidGrp) - local nSrfE = EgtSurfTmByScrewing( nSolidGrp, nSectE, ptE, LayerParams.vtSlicing, 180, 0, false, s_dTol, GDB_RT.GLOB) - EgtErase( nSectE) - if not nSrfE then return nil end - -- unione delle tre superfici - return EgtSurfTmBySewing( nSolidGrp, { nSrfId, nSrfS, nSrfE}) + + local dD1, dD2, dD3, dD4 = CalcSectionParams( dStrand, LayerParams.dLayHeight) + local nSrfId = EgtSurfTmRectSwept( nSolidGrp, dStrand, LayerParams.dLayHeight, dD2, dD3, nCrvId, GDB_RSCT.BEVEL, s_dTol) + return nSrfId end -------------------------------------------------------------------------------------- @@ -216,7 +180,7 @@ local function CreateSolid( nCrvId, nSolidGrp, LayerParams, dStrand) end --------------------------------------------------------------------- -local function CreateSolidFromCurve( nCrvId, nSolidGrp, LayerParams) +local function CreateSolidFromCurve( nCrvId, nSolidGrp, LayerParams, nLayer) local nType = EgtGetInfo( nCrvId, KEY_TYPE, 'i') if nType == TYPE.WIPE then return true end @@ -260,44 +224,57 @@ local function CreateSolidFromCurve( nCrvId, nSolidGrp, LayerParams) for nInd = 0, nParts - 1 do local nGuideId = nId + nInd local nSrfId = CreateSolid( nGuideId, nSolidGrp, LayerParams, LayerParams.dStrand - 5 * GEO.EPS_SMALL) - - if not nSrfId then - -- ritento con sezione leggermente modificata - nSrfId = CreateSolid( nGuideId, nSolidGrp, LayerParams, LayerParams.dStrand - 100 * GEO.EPS_SMALL) - if not nSrfId then - nSrfId = CreateSolid( nGuideId, nSolidGrp, LayerParams, LayerParams.dStrand + 100 * GEO.EPS_SMALL) - if not nSrfId then - -- ritento spezzando la curva - local nGrp = EgtGroup( nSolidGrp, Frame3d( ORIG(), LayerParams.vtSlicing), GDB_RT.GLOB) - EgtRelocateGlob( nGuideId, nGrp) - EgtApproxCurve( nGuideId, GDB_CA.LINES, 100 * GEO.EPS_SMALL) - EgtRelocateGlob( nGuideId, nSolidGrp) - local nFirstCrv, nCrvNbr = EgtSplitCurveAtCorners( nGuideId, 30) - if nFirstCrv and nCrvNbr > 1 then - local nSrfIds = {} - for nInd2 = 0, nCrvNbr-1 do - local nSrfId2 = CreateSolid( nFirstCrv + nInd2, nSolidGrp, LayerParams, LayerParams.dStrand - 100 * GEO.EPS_SMALL) - EgtErase( nFirstCrv + nInd2) - if nSrfId2 then - table.insert( nSrfIds, nSrfId2) - end - end - if #nSrfIds == nCrvNbr then - nSrfId = EgtSurfTmBySewing( nSolidGrp, nSrfIds) - end - else - EgtErase( nFirstCrv) + if not nSrfId then + EgtOutLog( 'Warning : CreateSolid failed '.. '(layer '..tostring( nLayer)..', curve '..tostring( nCrvId)..')') + -- se non ultima, provo a spostare l'estremità finale + if nInd < nParts - 1 then + local nCopyId = EgtCopy( nGuideId + 1, nGuideId, GDB_IN.AFTER) + if nCopyId then + local LEN_TRIM = 10 + local bOk1 = EgtTrimCurveEndAtLen( nCopyId, LEN_TRIM) + local bOk2 = EgtAddCurveCompoCurve( nGuideId, nCopyId) + local bOk3 = EgtTrimCurveStartAtLen( nGuideId + 1, LEN_TRIM) + nSrfId = CreateSolid( nGuideId, nSolidGrp, LayerParams, LayerParams.dStrand - 5 * GEO.EPS_SMALL) + if not nSrfId then + nSrfId = CreateSolid( nGuideId, nSolidGrp, LayerParams, LayerParams.dStrand - 50 * GEO.EPS_SMALL) end - EgtErase( nGrp) end end + -- ritento spezzando la curva + if not nSrfId then + EgtOutLog( 'Warning : CreateSolid_2 failed') + local nGrp = EgtGroup( nSolidGrp, Frame3d( ORIG(), LayerParams.vtSlicing), GDB_RT.GLOB) + EgtRelocateGlob( nGuideId, nGrp) + EgtApproxCurve( nGuideId, GDB_CA.LINES, 100 * GEO.EPS_SMALL) + EgtRelocateGlob( nGuideId, nSolidGrp) + local nFirstCrv, nCrvNbr = EgtSplitCurveAtCorners( nGuideId, 30) + if nFirstCrv and nCrvNbr > 1 then + local nSrfIds = {} + for nInd2 = 0, nCrvNbr-1 do + local nSrfId2 = CreateSolid( nFirstCrv + nInd2, nSolidGrp, LayerParams, LayerParams.dStrand - 50 * GEO.EPS_SMALL) + EgtErase( nFirstCrv + nInd2) + if nSrfId2 then + table.insert( nSrfIds, nSrfId2) + end + end + if #nSrfIds == nCrvNbr then + nSrfId = EgtSurfTmBySewing( nSolidGrp, nSrfIds) + else + EgtOutLog( 'Warning : CreateSolid_3 failed') + end + else + EgtErase( nFirstCrv) + end + EgtErase( nGrp) + end end - + if nSrfId then EgtSetColor( nSrfId, Color) EgtSetInfo( nSrfId, KEY_TYPE, nType) else - bOk = false + bOk = false + EgtOutLog( 'Warning : CreateSolid_Sewing failed') end EgtErase( nGuideId) end @@ -307,37 +284,41 @@ end --------------------------------------------------------------------- function RunCalcSolids.Exec() - + + -- per determinare il tempo di calcolo + EgtStartCounter() + local nPartIndex = 1 local nPartId = EgtGetFirstNameInGroup( GDB_ID.ROOT, PART .. nPartIndex) or EgtGetFirstNameInGroup( GDB_ID.ROOT, PART) while nPartId do - + if EgtGetInfo( nPartId, KEY_PART_ON_TABLE, 'b') then -- verifico se necessario calcolare il solido local bCalcSolid = EgtGetInfo( nPartId, KEY_CALC_SOLIDS, 'b') or false - + if bCalcSolid then - + -- recupero i suoi slice local vLayIds = EgtGetNameInGroup( nPartId, SLICE_LAYER .. '*') if not vLayIds then EgtOutBox( 'No sliced part in this project!', 'Error', 'ERROR') return end - + EgtSetInfo( nPartId, KEY_HAS_SOLIDS, 1) - - local vErr = {} + -- recupero i parametri necessari al calcolo dei solidi local LayerParams = GetLayerParamsForSolidCalc( nPartId) - + for nIdx = 1, #vLayIds do -- flag di interruzione perchè trovati solidi già ok local bSolidsOk = false + -- indice layer (per log) + local nLayer = EgtGetInfo( vLayIds[ nIdx], KEY_SLICE_NBR, 'i') -- scorro tutti i gruppi di contorni local nCrvGrpId = EgtGetFirstNameInGroup( vLayIds[ nIdx], CONTOUR_GRP.."*") or GDB_ID.NULL while nCrvGrpId ~= GDB_ID.NULL do - + -- recupero il gruppo dei percorsi utensile local nTPathGrpId = EgtGetFirstNameInGroup( nCrvGrpId, TOOLPATH_GRP) or GDB_ID.NULL if nTPathGrpId == GDB_ID.NULL then @@ -351,43 +332,39 @@ function RunCalcSolids.Exec() nSolidGrpId = EgtGroup( nCrvGrpId) EgtSetName( nSolidGrpId, SOLID_GRP) EgtSetLevel( nSolidGrpId, GDB_LV.TEMP) - -- scorro le curve del percorso utensile local nId = EgtGetFirstInGroup( nTPathGrpId) while nId do - local bOk = CreateSolidFromCurve( nId, nSolidGrpId, LayerParams) - if not bOk then - table.insert( vErr, nIdx) - end + local bOk = CreateSolidFromCurve( nId, nSolidGrpId, LayerParams, nLayer) nId = EgtGetNext( nId) end - - -- processo gli eventi - if ( nIdx % 20) == 0 then - EgtDraw() - end else bSolidsOk = true break end - + --passo al gruppo di contorni successivo nCrvGrpId = EgtGetNextName( nCrvGrpId, CONTOUR_GRP.."*") or GDB_ID.NULL end if bSolidsOk then break end - EgtDraw() + local nStep = 10 + if nIdx > 400 then + nStep = 80 + elseif nIdx > 200 then + nStep = 40 + elseif nIdx > 100 then + nStep = 20 + end + if ( nIdx % nStep) == 0 then + EgtDraw() + end if EgtProcessEvents( EgtIf( PRINT, 400, 0) + nIdx / #vLayIds * 100, 0) == 1 then return end end - - -- eventuale segnalazione errori - for i = 1, #vErr do - EgtOutLog( 'Error on solid creation (layer ' .. vErr[i] .. ') - SolidCalc') - end - + -- eventuale aggiornamento delle ViewInfo local nViewId = EgtGetFirstNameInGroup( GDB_ID.ROOT, VIEWPARAMS) if nViewId then @@ -396,11 +373,16 @@ function RunCalcSolids.Exec() end end - + nPartIndex = nPartIndex + 1 nPartId = EgtGetFirstNameInGroup( GDB_ID.ROOT, PART .. nPartIndex) or EgtGetNextName( nPartId, PART) end - + + EgtDraw() + + -- report tempo di calcolo in log + EgtOutLog( string.format( ' CalcSolidsTime = %.2f ms', EgtStopCounter())) + end ---------------------------------------------------------------------