diff --git a/LuaLibs/CalcSlices.lua b/LuaLibs/CalcSlices.lua index 1ef79d2..1a6fa66 100644 --- a/LuaLibs/CalcSlices.lua +++ b/LuaLibs/CalcSlices.lua @@ -22,9 +22,12 @@ end --------------------------------------------------------------------- function CalcSlices.Exec( nPartId, nStmId, HMax) - local dTol = 0.1 + -- costanti + local dToler = 1.0 + local dMinLen = 5.0 + local dMinArea = 100.0 - -- recuper il box della superficie + -- recupero il box della superficie local b3Box = EgtGetBBoxRef( nStmId, GDB_BB.STANDARD, EgtGetGridFrame()) if not b3Box or b3Box:isEmpty() then EgtOutText( 'La superficie selezionata è vuota') @@ -36,14 +39,17 @@ function CalcSlices.Exec( nPartId, nStmId, HMax) local dZmin = b3Box:getMin():getZ() local dZmax = b3Box:getMax():getZ() dZmax = min( dZmax, dZmin + HMax) - --dZmin = 1030 - --dZmax = 1031 + --dZmin = 460 + --dZmax = 465 -- se slicing già presente lo cancello - local nOldSliceId = EgtGetFirstNameInGroup( nPartId, SLICE_LAYER .."*") or GDB_ID.NULL - while nOldSliceId ~= GDB_ID.NULL do - EgtErase( nOldSliceId) - nOldSliceId = EgtGetFirstNameInGroup( nPartId, SLICE_LAYER .."*") or GDB_ID.NULL + for i = 1, 2 do + local sFind = EgtIf( i == 1, '', '__') .. SLICE_LAYER .. "*" + local nOldSliceId = EgtGetFirstNameInGroup( nPartId, sFind) + while nOldSliceId do + EgtErase( nOldSliceId) + nOldSliceId = EgtGetFirstNameInGroup( nPartId, sFind) + end end -- Eseguo slicing @@ -58,9 +64,9 @@ function CalcSlices.Exec( nPartId, nStmId, HMax) -- calcolo intersezione local dDeltaZ = EgtIf( nLayCnt == 1, 0.2, 0) --dDeltaZ = 0 - nNewId, nPntCnt, nCrvCnt, nSrfCnt = EgtPlaneSurfTmInters( Point3d( 0, 0, dPosZ + dDeltaZ), Z_AX(), nStmId, nLayId, GDB_RT.GLOB) + local nNewId, nPntCnt, nCrvCnt, nStmCnt = EgtPlaneSurfTmInters( Point3d( 0, 0, dPosZ + dDeltaZ), Z_AX(), nStmId, nLayId, GDB_RT.GLOB, dToler) -- verifico se ricalcolare con piccolo spostamento - local bRecalc = not nNewId or ( nSrfCnt ~= 0) + local bRecalc = ( not nNewId or nStmCnt ~= 0) if not bRecalc then for Id = nNewId + nPntCnt, nNewId + nPntCnt + nCrvCnt - 1 do if not EgtCurveIsClosed( Id) then @@ -74,92 +80,100 @@ function CalcSlices.Exec( nPartId, nStmId, HMax) local vtN = EgtSurfTmFacetNormVersor( nNewId or 0 + nPntCnt or 0 + nCrvCnt or 0, 0) dDeltaZ = dDeltaZ + EgtIf( vtN and vtN:getZ() < 0, 0.01, - 0.01) EgtEmptyGroup( nLayId) - nNewId, nPntCnt, nCrvCnt, nSrfCnt = EgtPlaneSurfTmInters( Point3d( 0, 0, dPosZ + dDeltaZ), Z_AX(), nStmId, nLayId, GDB_RT.GLOB) + nNewId, nPntCnt, nCrvCnt, nStmCnt = EgtPlaneSurfTmInters( Point3d( 0, 0, dPosZ + dDeltaZ), Z_AX(), nStmId, nLayId, GDB_RT.GLOB, dToler) end -- salvo i risultati nel layer if nNewId then -- elimino eventuali punti e superfici - for i = 1, nPntCnt do - EgtErase( nNewId + i - 1) + for nId = nNewId, nNewId + nPntCnt - 1 do + EgtErase( nId) end nNewId = nNewId + nPntCnt - nPntCnt = 0 - for i = 1, nSrfCnt do - EgtErase( nNewId + nPntCnt + nCrvCnt + i - 1) + nPntCnt = nil + for nId = nNewId + nCrvCnt, nNewId + nCrvCnt + nStmCnt - 1 do + EgtErase( nId) end - nSrfCnt = 0 + nStmCnt = nil -- correggo eventuali spostamenti in Z if abs( dDeltaZ) > GEO.EPS_SMALL then - for nId = nNewId, nNewId + nPntCnt + nCrvCnt + nSrfCnt - 1 do + for nId = nNewId, nNewId + nCrvCnt - 1 do EgtMove( nId, Vector3d( 0, 0, -dDeltaZ)) end end -- verifico presenza contorni aperti local vOpenId = {} - for Id = nNewId + nPntCnt, nNewId + nPntCnt + nCrvCnt - 1 do - if not EgtCurveIsClosed( Id) then - table.insert( vOpenId, Id) + for nId = nNewId, nNewId + nCrvCnt - 1 do + if not EgtCurveIsClosed( nId) then + table.insert( vOpenId, nId) end end - -- provo a concatenare i contorni aperti - if #vOpenId > 1 then - local nFirstId, nCnt = EgtCurveCompoByReorder( nLayId, vOpenId, Point3d(0,0,0), true, GDB_RT.LOC, dTol) - if nFirstId and nCnt == 1 then - nCrvCnt = nCrvCnt - #vOpenId + 1 - vOpenId = {} + -- chiudo percorsi aperti praticamente chiusi + for i = #vOpenId, 1, -1 do + local ptStart = EgtSP( vOpenId[i]) + local ptEnd = EgtEP( vOpenId[i]) + if AreSamePointEpsilon( ptStart, ptEnd, dToler) and EgtCurveLength( vOpenId[i]) > dMinLen then + local ptMid = ( ptStart + ptEnd) / 2 + EgtModifyCurveStartPoint( vOpenId[i], ptMid) + EgtModifyCurveEndPoint( vOpenId[i], ptMid) + table.remove( vOpenId, i) + end + end + local bAllClosed = ( #vOpenId == 0) + + -- elimino percorsi chiusi di area troppo piccola + for nId = nNewId, nNewId + nCrvCnt - 1 do + local _, _, dArea = EgtCurveArea( nId) + if dArea and dArea < dMinArea then + EgtErase( nId) end end -- imposto dati ausiliari - EgtSetName( nLayId, EgtIf( #vOpenId == 0, '', '**') .. SLICE_LAYER .. EgtNumToString( nLayCnt)) - EgtSetInfo( nLayId, 'PntCnt', nPntCnt) + EgtSetName( nLayId, EgtIf( bAllClosed, '', '__') .. SLICE_LAYER .. EgtNumToString( nLayCnt)) EgtSetInfo( nLayId, 'CrvCnt', nCrvCnt) - EgtSetInfo( nLayId, 'SrfCnt', nSrfCnt) - EgtSetColor( EgtTableFill( nNewId, nPntCnt) or {}, 'BLUE') - EgtSetColor( EgtTableFill( nNewId + nPntCnt, nCrvCnt) or {}, 'BLACK') - EgtSetColor( EgtTableFill( nNewId + nPntCnt + nCrvCnt, nSrfCnt) or {}, 'AQUA') + EgtSetColor( EgtTableFill( nNewId, nCrvCnt) or {}, 'BLACK') -- creo flat region a partire dalle curve ottenute con lo slicing local vCrvs = {} - for nInd = 0, nCrvCnt - 1 do - table.insert( vCrvs, nNewId + nPntCnt + nInd) - EgtApproxCurve( nNewId + nPntCnt + nInd, GDB_CA.ARCS, dTol) + for nId = nNewId, nNewId + nCrvCnt - 1 do + table.insert( vCrvs, nId) + EgtApproxCurve( nId, GDB_CA.ARCS, dToler / 10) end local nSurfFR = EgtSurfFlatRegion( nLayId, vCrvs) - for nInd = 1, #vCrvs do - EgtErase( vCrvs[nInd]) + for i = 1, #vCrvs do + EgtErase( vCrvs[i]) end if nSurfFR then -- analizzo i singoli chunks - local nSfrId, nSrfCnt = EgtExplodeSurf( nSurfFR) - for nInd = 0, nSrfCnt - 1 do + local nSfrId, nSfrCnt = EgtExplodeSurf( nSurfFR) + for nId = nSfrId, nSfrId + nSfrCnt - 1 do -- per ogni chunk creo un gruppo di percorsi local nGrpCrv = EgtGroup( nLayId) - EgtSetName( nGrpCrv, CONTOUR_GRP .. EgtNumToString( nInd + 1, 1)) - EgtRelocateGlob( nSfrId + nInd, nGrpCrv) - EgtSetName( nSfrId + nInd, LAYER_SRF) - EgtSetStatus( nSfrId + nInd, GDB_ST.OFF) + EgtSetName( nGrpCrv, CONTOUR_GRP .. EgtNumToString( nId, 1)) + EgtRelocateGlob( nId, nGrpCrv) + EgtSetName( nId, LAYER_SRF) + EgtSetStatus( nId, GDB_ST.OFF) -- estraggo i contorni della superficie - local nCrvId, nCrvCnt = EgtExtractSurfFrChunkLoops( nSfrId + nInd, 0, nGrpCrv) - for nInd2 = 0, nCrvCnt - 1 do - EgtSetName( nCrvId + nInd2, OUTER_CRV) - EgtSetColor( nCrvId + nInd2, 'BLACK') + local nCsId, nCsCnt = EgtExtractSurfFrChunkLoops( nId, 0, nGrpCrv) + for nId2 = nCsId, nCsId + nCsCnt - 1 do + EgtSetName( nId2, OUTER_CRV) + EgtSetColor( nId2, 'BLACK') end end else -- errore - EgtSetName( nLayId, EgtIf( bAllClosed, '', '**') .. SLICE_LAYER .. EgtNumToString( nLayCnt)) + EgtSetName( nLayId, EgtIf( bAllClosed, '', '__') .. SLICE_LAYER .. EgtNumToString( nLayCnt)) end -- errore else - EgtSetName( nLayId, EgtIf( bAllClosed, '', '**') .. SLICE_LAYER .. EgtNumToString( nLayCnt)) + EgtSetName( nLayId, EgtIf( bAllClosed, '', '__') .. SLICE_LAYER .. EgtNumToString( nLayCnt)) end local dStep = GetSliceStep( dPosZ, dStep) diff --git a/LuaLibs/CalcSolids.lua b/LuaLibs/CalcSolids.lua index 49f6f75..c389c82 100644 --- a/LuaLibs/CalcSolids.lua +++ b/LuaLibs/CalcSolids.lua @@ -1,4 +1,4 @@ --- CalcSolids.lua by Egaltech s.r.l. 2022/04/13 +-- CalcSolids.lua by Egaltech s.r.l. 2022/04/19 -- Calcolo percorsi di lavoro per Stampa 3d -- Tabella per definizione modulo @@ -127,6 +127,7 @@ local function CreateSolidFromCurve( nCrvId, nSolidGrp, LayerParams) local nCopyId = EgtCopyGlob( nCrvId, nSolidGrp) local nId = EgtSplitCurve( nCopyId, nParts) + local bOk = true for nInd = 0, nParts - 1 do local ptS = EgtSP( nId + nInd) @@ -138,23 +139,16 @@ local function CreateSolidFromCurve( nCrvId, nSolidGrp, LayerParams) EgtErase( nSectId) if nSrfId then nSrfId = CloseSolid( nId + nInd, nSrfId, nSolidGrp, LayerParams) + EgtSetColor( nSrfId or GDB_ID.NULL, Color) + EgtSetInfo( nSrfId or GDB_ID.NULL, KEY_TYPE, nType) else EgtErase( nSectId) - for nInd3 = 0, nParts - 1 do - EgtErase( nId + nInd3) - end - for nInd3 = 0, nInd - 1 do - local nId2 = EgtGetLastInGroup( nSolidGrp) - EgtErase( nId2) - end - EgtOutBox( 'CalcSolid error', '') - return + bOk = false end - EgtSetColor( nSrfId, Color) - EgtSetInfo( nSrfId, KEY_TYPE, nType) EgtErase( nId + nInd) end + return bOk end --------------------------------------------------------------------- @@ -166,6 +160,7 @@ function CalcSolids.Exec( nPartId) return end + local vErr = {} for nIdx = 1, #vLayIds do -- recupero i parametri relativi al layer local LayerParams = GetLayerParamsForSolidCalc() @@ -193,7 +188,10 @@ function CalcSolids.Exec( nPartId) -- scorro le curve del percorso utensile local nId = EgtGetFirstInGroup( nTPathGrpId) while nId do - CreateSolidFromCurve( nId, nSolidGrpId, LayerParams) + local bOk = CreateSolidFromCurve( nId, nSolidGrpId, LayerParams) + if not bOk then + table.insert( vErr, nIdx) + end nId = EgtGetNext( nId) end @@ -219,6 +217,11 @@ function CalcSolids.Exec( nPartId) return end end + + -- eventuale segnalazione errori + if #vErr > 0 then + EgtOutBox( 'Error on layers :\n' .. table.concat( vErr, ','), 'SolidCalc') + end end --------------------------------------------------------------------- diff --git a/LuaLibs/CalcToolPath.lua b/LuaLibs/CalcToolPath.lua index 6180c9f..d46eb9b 100644 --- a/LuaLibs/CalcToolPath.lua +++ b/LuaLibs/CalcToolPath.lua @@ -1,4 +1,4 @@ --- CalcToolPath.lua by Egaltech s.r.l. 2022/04/13 +-- CalcToolPath.lua by Egaltech s.r.l. 2022/04/19 -- Calcolo percorsi di lavoro per Stampa 3d -- Tabella per definizione modulo @@ -55,12 +55,11 @@ local function AddLeadIn( nCrvId, LayerParams, nGrpId) local _, _, dAngIni = SphericalFromVector( vtTang) nLeadInCrv = EgtArc2PD( nGrpId, ptE, ptS, 180 + dAngIni) EgtInvertCurve( nLeadInCrv) - end EgtRelocate( nLeadInCrv, nGrpId, GDB_IN.FIRST_SON) + EgtModifyCurveExtrusion( nLeadInCrv, Z_AX(), GDB_RT.GLOB) EgtSetInfo( nLeadInCrv, KEY_TYPE, TYPE.LINK) - end -------------------------------------------------------------------- @@ -84,9 +83,9 @@ local function AddLeadOut( nCrvId, LayerParams, nGrpId) elseif LayerParams.LeadOutType == LEAD_TYPE.ARC then local _, _, dAngIni = SphericalFromVector( vtTang) nLeadOutCrv = EgtArc2PD( nGrpId, ptS, ptE, dAngIni) - end EgtRelocate( nLeadOutCrv, nGrpId, GDB_IN.LAST_SON) + EgtModifyCurveExtrusion( nLeadOutCrv, Z_AX(), GDB_RT.GLOB) EgtSetInfo( nLeadOutCrv, KEY_TYPE, TYPE.LINK) end @@ -139,7 +138,8 @@ function CalcToolPath.Exec( nPartId) EgtMove( nNewEntId, Vector3d( 0, 0, LayerParams.dLayHeight), GDB_RT.GLOB) if LayerParams.bInvert then EgtInvertCurve( nNewEntId) - end + end + EgtModifyCurveExtrusion( nNewEntId, Z_AX(), GDB_RT.GLOB) nEntId = EgtGetNext( nEntId) end @@ -165,6 +165,7 @@ function CalcToolPath.Exec( nPartId) nLinkId = EgtBiArc( nTpathGrpId, EgtEP( nPrevId), EgtSP( nCurrId), dAngIni, dAngFin, 0.5) end EgtRelocate( nLinkId, nCurrId, GDB_IN.BEFORE) + EgtModifyCurveExtrusion( nLinkId, Z_AX(), GDB_RT.GLOB) local nType = EgtGetInfo( nCurrId, KEY_TYPE, 'i') EgtSetInfo( nLinkId, KEY_TYPE, TYPE.LINK) nPrevId = nCurrId @@ -173,11 +174,15 @@ function CalcToolPath.Exec( nPartId) -- aggiungo leadin/leadout local nFirstCurve = EgtGetFirstInGroup( nTpathGrpId) - EgtTrimCurveStartAtLen( nFirstCurve, LayerParams.dOffsetLP) - AddLeadIn( nFirstCurve, LayerParams, nTpathGrpId) + if nFirstCurve then + EgtTrimCurveStartAtLen( nFirstCurve, LayerParams.dOffsetLP) + AddLeadIn( nFirstCurve, LayerParams, nTpathGrpId) + end local nLastCurve = EgtGetLastInGroup( nTpathGrpId) - EgtTrimCurveEndAtLen( nLastCurve, EgtCurveLength( nLastCurve) - LayerParams.dOffsetLP) - AddLeadOut( nLastCurve, LayerParams, nTpathGrpId) + if nLastCurve then + EgtTrimCurveEndAtLen( nLastCurve, EgtCurveLength( nLastCurve) - LayerParams.dOffsetLP) + AddLeadOut( nLastCurve, LayerParams, nTpathGrpId) + end --passo al gruppo di contorni successivo nCrvGrpId = EgtGetNextName( nCrvGrpId, CONTOUR_GRP.."*") end diff --git a/LuaLibs/RunShowManager.lua b/LuaLibs/RunShowManager.lua index 1a99388..e8cf80d 100644 --- a/LuaLibs/RunShowManager.lua +++ b/LuaLibs/RunShowManager.lua @@ -1,4 +1,4 @@ --- RunShowManager.lua by Egaltech s.r.l. 2022/04/05 +-- RunShowManager.lua by Egaltech s.r.l. 2022/04/19 -- Gestione visualizzazione per Stampa 3d -- Tabella per definizione modulo @@ -72,19 +72,19 @@ function RunShowManager.Exec() while nCrvId do if bOuterCrv ~= bCurrOuterCrv then local nOuterCrvId = EgtGetFirstNameInGroup( nCrvId, OUTER_CRV) - EgtSetStatus( nOuterCrvId, EgtIf( bCurrOuterCrv, GDB_ST.ON, GDB_ST.OFF)) + EgtSetStatus( nOuterCrvId or GDB_ID.NULL, EgtIf( bCurrOuterCrv, GDB_ST.ON, GDB_ST.OFF)) end if bPath ~= bCurrPath then local nPathId = EgtGetFirstNameInGroup( nCrvId, PATH_GRP) - EgtSetStatus( nPathId, EgtIf( bCurrPath, GDB_ST.ON, GDB_ST.OFF)) + EgtSetStatus( nPathId or GDB_ID.NULL, EgtIf( bCurrPath, GDB_ST.ON, GDB_ST.OFF)) end if bSolid ~= bCurrSolid then local nSolidId = EgtGetFirstNameInGroup( nCrvId, SOLID_GRP) - EgtSetStatus( nSolidId, EgtIf( bCurrSolid, GDB_ST.ON, GDB_ST.OFF)) + EgtSetStatus( nSolidId or GDB_ID.NULL, EgtIf( bCurrSolid, GDB_ST.ON, GDB_ST.OFF)) end if bToolPath ~= bCurrToolPath then local nToolPathId = EgtGetFirstNameInGroup( nCrvId, TOOLPATH_GRP) - EgtSetStatus( nToolPathId, EgtIf( bCurrToolPath, GDB_ST.ON, GDB_ST.OFF)) + EgtSetStatus( nToolPathId or GDB_ID.NULL, EgtIf( bCurrToolPath, GDB_ST.ON, GDB_ST.OFF)) end nCrvId = EgtGetNext( nCrvId) end diff --git a/Machinings/Strand18x5.ini b/Machinings/Strand18x5.ini new file mode 100644 index 0000000..2f16dfb --- /dev/null +++ b/Machinings/Strand18x5.ini @@ -0,0 +1,25 @@ +[Default] +StrandH=5.0 +StrandW=18.0 +StrandCount=2 +Offset=2.0 +StartPoint=1800,1400 +StrandOrder=OutToIn +Direction=CCW +LinkType=Linear +LinkParam=36.0 +LinkDist=0 +LinkZup=10.0 +OffsetLeadPoint=22 +LeadIn=Linear +LeadInTangDist=30 +LeadInOrthoDist=15 +LeadOut=Linear +LeadOutTangDist=30 +LeadOutOrthoDist=15 +FloorCount=2 +Speed= +Feed=2000 +G0Feed=10000 +Material=B461 + diff --git a/Machinings/Strand9x2.ini b/Machinings/Strand9x2.ini new file mode 100644 index 0000000..e3285a3 --- /dev/null +++ b/Machinings/Strand9x2.ini @@ -0,0 +1,25 @@ +[Default] +StrandH=2.0 +StrandW=9.0 +StrandCount=2 +Offset=2.0 +StartPoint=1800,1400 +StrandOrder=OutToIn +Direction=CCW +LinkType=Linear +LinkParam=18.0 +LinkDist=0 +LinkZup=10.0 +OffsetLeadPoint=11 +LeadIn=Linear +LeadInTangDist=15 +LeadInOrthoDist=7 +LeadOut=Linear +LeadOutTangDist=15 +LeadOutOrthoDist=7 +FloorCount=2 +Speed= +Feed=2000 +G0Feed=10000 +Material=B461 +