From 261aec363d16829147da45706e33629dcebd8b06 Mon Sep 17 00:00:00 2001 From: Emmanuele Sassi Date: Wed, 13 Apr 2022 15:35:05 +0200 Subject: [PATCH] - Correzioni e migliorie su pezzo di esempio - Gestione avvio script solo quando eseguiti precedenti - Correzioni varie --- LuaLibs/AddManData.lua | 64 +++++++--- LuaLibs/CalcPaths.lua | 35 +++-- LuaLibs/CalcSlices.lua | 70 +++++++--- LuaLibs/CalcSolids.lua | 205 ++++++++++++++---------------- LuaLibs/CalcToolPath.lua | 27 ++-- LuaLibs/RunGcodeGenerate.lua | 35 ++++- LuaLibs/RunMachiningParamCalc.lua | 5 +- LuaLibs/RunShowManager.lua | 4 +- LuaLibs/RunSliceAdvancement.lua | 73 ++++++++--- LuaLibs/RunSlicePalette.lua | 10 +- LuaLibs/RunSlicing.lua | 44 +++++-- LuaLibs/RunViewManager.lua | 84 ++++++++---- 12 files changed, 417 insertions(+), 239 deletions(-) diff --git a/LuaLibs/AddManData.lua b/LuaLibs/AddManData.lua index 2ce0ac0..fc21148 100644 --- a/LuaLibs/AddManData.lua +++ b/LuaLibs/AddManData.lua @@ -1,4 +1,4 @@ --- AddManData.lua by Egaltech s.r.l. 2022/03/28 +-- AddManData.lua by Egaltech s.r.l. 2022/04/12 -- Raccolta costanti generali per Stampa 3d -- Tabella per definizione modulo @@ -34,13 +34,14 @@ KEY_SLICE_STEP = "StrandH" KEY_SHELLS_NBR = "StrandCount" KEY_STRAND = "StrandW" KEY_OFFSET_SLICE ="Offset" -KEY_START_POINT = "StartingPoint" +KEY_START_POINT = "StartPoint" KEY_PRINT_ORDER = "StrandOrder" KEY_PRINT_DIRECTION = "Direction" KEY_TYPE = "Type" KEY_LINK_TYPE = "LinkType" KEY_LINK_PARAM = "LinkParam" KEY_LINK_DIST="LinkDist" +KEY_LINK_ZUP = "LinkZup" KEY_FLOOR_NBR = "FloorCount" KEY_SPEED = "Speed" KEY_FEED = "Feed" @@ -63,32 +64,30 @@ KEY_LEAD_OUT_ORTHO_DIST= "LeadOutOrthoDist" KEY_OFFSET_LEAD_POINT = "OffsetLeadPoint" TYPE = { - OUTER_SHELL = 0, - INNER_SHELL = 1, - INFILL = 2, - LINK = 3, + OUTER_SHELL = 1, + INNER_SHELL = 2, + INFILL = 3, + LINK = 4, } PRINT_ORDER = { - INT_EXT_INF = 0, EXT_INT_INF = 1, - INF_EXT_INT = 2, - INF_INT_EXT = 3, + INF_INT_EXT = 2, } PRINT_DIRECTION = { - CCW = 0, - CW = 1, + CCW = 1, + CW = 2, } LINK_TYPE = { - LINEAR = 0, - BIARC = 1, + LINEAR = 1, + BIARC = 2, } LEAD_TYPE = { - LINEAR = 0, - ARC = 1, + LINEAR = 1, + ARC = 2, } @@ -105,16 +104,41 @@ RESULT_READ_PROG = 'ResultReadProg' KEY_RESULT = 'Result' KEY_PALETTE = 'Palette' +KEY_LAYER_VIEW = 'LayerView' +KEY_SHELL_VIEW = 'ShellView' +KEY_INNER_NUM = 'InnerNum' +KEY_SEL_LAYER = 'SelLayer' +KEY_SLICE_ADV_MODE = 'SliceAdvMode' +KEY_SLICE_ADV_PERC = 'SliceAdvPerc' RESULT = { - OK = 0, - KO_MINUS = 1, - KO_PLUS = 2, + OK = 1, + KO_MINUS = 2, + KO_PLUS = 3, } PALETTE_TYPE = { - IN_OUT = 0, - RESULTS = 1, + IN_OUT = 1, + RESULTS = 2, } + +LAYER_VIEW_TYPE = { + ALL = 1, + TILL_SEL = 2, + ONLY_SEL = 3, +} +SHELL_VIEW_TYPE = { + ALL = 1, + OUTER = 2, + INNER = 3, + INFILL = 4, +} +SLICE_ADV_TYPE = { + ALL = 1, + OUTER = 2, + INNER = 3, + INFILL = 4, +} + --------------------------------------------------------------------- return AddManData diff --git a/LuaLibs/CalcPaths.lua b/LuaLibs/CalcPaths.lua index 718d627..f582e8a 100644 --- a/LuaLibs/CalcPaths.lua +++ b/LuaLibs/CalcPaths.lua @@ -1,4 +1,4 @@ --- CalcPaths.lua by Egaltech s.r.l. 2022/03/30 +-- CalcPaths.lua by Egaltech s.r.l. 2022/04/13 -- Calcolo percorsi di lavoro per Stampa 3d -- Tabella per definizione modulo @@ -56,7 +56,7 @@ local function GetPathsFromSurf( nSrfId, sName, nType, nGrpId, nLayId, dStrand) -- scelta start point local ptStart = GetLayerStartPoint( nLayId) - EgtChangeClosedCurveStartPoint( nCrvId + nInd, ptStart) + EgtChangeClosedCurveStartPoint( nCrvId + nInd, ptStart, GDB_RT.GLOB) end end end @@ -123,19 +123,36 @@ function CalcPaths.Exec( nPartId) if nSrf then -- esterno local nSrfId = EgtCopyGlob( nSrf, nCrvGrpId) - local dOffs = 0.5 * LayerParams.dStrand - LayerParams.dOffs - EgtSurfFrOffset( nSrfId, - dOffs) - -- estraggo i contorni (pareti esterne) - GetPathsFromSurf( nSrfId, SHELL_CRV..'0', TYPE.OUTER_SHELL, nGrpId, nLayId, LayerParams.dStrand) + local dOffs = 0.5 * LayerParams.dStrand - LayerParams.dOffs + local bOk = ( EgtSurfFrOffset( nSrfId, -dOffs) and EgtSurfFrChunkCount( nSrfId) > 0) + if not bOk then + EgtErase( nSrfId) + nSrfId = EgtCopyGlob( nSrf, nCrvGrpId) + bOk = ( EgtSurfFrOffset( nSrfId, -dOffs + 0.05) and EgtSurfFrChunkCount( nSrfId) > 0) + end + -- se offset riuscito, estraggo i contorni (pareti esterne) + if bOk then + GetPathsFromSurf( nSrfId, SHELL_CRV..'0', TYPE.OUTER_SHELL, nGrpId, nLayId, LayerParams.dStrand) + else + EgtOutLog( 'Error on ExtOffset (layer '..tostring( nIdx)..') - CalcPaths') + end EgtErase( nSrfId) -- calcolo pareti interne for nInd2 = 1, LayerParams.nShellsNbr - 1 do -- offset della superficie originale local nSrfId = EgtCopy( nSrf, nGrpId) - if EgtSurfFrOffset( nSrfId, - dOffs - nInd2 * LayerParams.dStrand) then - -- estraggo i contorni ( pareti interne) - GetPathsFromSurf( nSrfId, SHELL_CRV..tostring( nInd2), TYPE.INNER_SHELL, nGrpId, nLayId, LayerParams.dStrand) + local bOk = ( EgtSurfFrOffset( nSrfId, - dOffs - nInd2 * LayerParams.dStrand) and EgtSurfFrChunkCount( nSrfId) > 0) + if not bOk then + EgtErase( nSrfId) + nSrfId = EgtCopyGlob( nSrf, nCrvGrpId) + bOk = ( EgtSurfFrOffset( nSrfId, -dOffs + 0.05 - nInd2 * LayerParams.dStrand) and EgtSurfFrChunkCount( nSrfId) > 0) + end + -- se offset riuscito, estraggo i contorni ( pareti interne) + if bOk then + GetPathsFromSurf( nSrfId, SHELL_CRV..tostring( nInd2), TYPE.INNER_SHELL, nGrpId, nLayId, LayerParams.dStrand) + else + EgtOutLog( 'Error on IntOffset (layer '..tostring( nIdx)..') - CalcPaths') end EgtErase( nSrfId) end diff --git a/LuaLibs/CalcSlices.lua b/LuaLibs/CalcSlices.lua index 6eed2e5..cc2b76a 100644 --- a/LuaLibs/CalcSlices.lua +++ b/LuaLibs/CalcSlices.lua @@ -21,8 +21,9 @@ end --------------------------------------------------------------------- function CalcSlices.Exec( nPartId, nStmId) - - local dTol = 0.05 + + local dTol = 0.1 + -- recuper il box della superficie local b3Box = EgtGetBBoxRef( nStmId, GDB_BB.STANDARD, EgtGetGridFrame()) if not b3Box or b3Box:isEmpty() then @@ -32,8 +33,10 @@ function CalcSlices.Exec( nPartId, nStmId) end -- Parametri di slicing - local dZmin = b3Box:getMin():getZ() + 0.1 --0.1 * dStep - local dZmax = b3Box:getMax():getZ() - 0.1 -- 0.1 * dStep + local dZmin = b3Box:getMin():getZ() + local dZmax = b3Box:getMax():getZ() + --dZmin = 1030 + --dZmax = 1031 -- se slicing già presente lo cancello local nOldSliceId = EgtGetFirstNameInGroup( nPartId, SLICE_LAYER .."*") or GDB_ID.NULL @@ -42,8 +45,6 @@ function CalcSlices.Exec( nPartId, nStmId) nOldSliceId = EgtGetFirstNameInGroup( nPartId, SLICE_LAYER .."*") or GDB_ID.NULL end - EgtStartCounter() - -- Eseguo slicing local dPosZ = dZmin local nLayCnt = 1 @@ -54,7 +55,9 @@ function CalcSlices.Exec( nPartId, nStmId) EgtSetInfo( nLayId, KEY_SLICE_NBR, nLayCnt) -- calcolo intersezione - nNewId, nPntCnt, nCrvCnt, nSrfCnt = EgtPlaneSurfTmInters( Point3d( 0, 0, dPosZ), Z_AX(), nStmId, nLayId, GDB_RT.GRID) + 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) -- verifico se ricalcolare con piccolo spostamento local bRecalc = not nNewId or ( nSrfCnt ~= 0) if not bRecalc then @@ -68,24 +71,51 @@ function CalcSlices.Exec( nPartId, nStmId) -- se richiesto, eseguo ricalcolo if bRecalc then local vtN = EgtSurfTmFacetNormVersor( nNewId or 0 + nPntCnt or 0 + nCrvCnt or 0, 0) - local dDeltaZ = EgtIf( vtN and vtN:getZ() < 0, 0.005, - 0.005) + 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.GRID) + nNewId, nPntCnt, nCrvCnt, nSrfCnt = EgtPlaneSurfTmInters( Point3d( 0, 0, dPosZ + dDeltaZ), Z_AX(), nStmId, nLayId, GDB_RT.GLOB) end -- salvo i risultati nel layer if nNewId then - -- verifico presenza contorni aperti - local bAllClosed = true - for Id = nNewId + nPntCnt, nNewId + nPntCnt + nCrvCnt - 1 do - if not EgtCurveIsClosed( Id) then - bAllClosed = false - break + + -- elimino eventuali punti e superfici + for i = 1, nPntCnt do + EgtErase( nNewId + i - 1) + end + nNewId = nNewId + nPntCnt + nPntCnt = 0 + for i = 1, nSrfCnt do + EgtErase( nNewId + nPntCnt + nCrvCnt + i - 1) + end + nSrfCnt = 0 + + -- correggo eventuali spostamenti in Z + if abs( dDeltaZ) > GEO.EPS_SMALL then + for nId = nNewId, nNewId + nPntCnt + nCrvCnt + nSrfCnt - 1 do + EgtMove( nId, Vector3d( 0, 0, -dDeltaZ)) end end - -- salvo - EgtSetName( nLayId, EgtIf( bAllClosed, '', '**') .. SLICE_LAYER .. EgtNumToString( nLayCnt)) + -- verifico presenza contorni aperti + local vOpenId = {} + for Id = nNewId + nPntCnt, nNewId + nPntCnt + nCrvCnt - 1 do + if not EgtCurveIsClosed( Id) then + table.insert( vOpenId, Id) + 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 = {} + end + end + + -- imposto dati ausiliari + EgtSetName( nLayId, EgtIf( #vOpenId == 0, '', '**') .. SLICE_LAYER .. EgtNumToString( nLayCnt)) EgtSetInfo( nLayId, 'PntCnt', nPntCnt) EgtSetInfo( nLayId, 'CrvCnt', nCrvCnt) EgtSetInfo( nLayId, 'SrfCnt', nSrfCnt) @@ -100,9 +130,9 @@ function CalcSlices.Exec( nPartId, nStmId) EgtApproxCurve( nNewId + nPntCnt + nInd, GDB_CA.ARCS, dTol) end local nSurfFR = EgtSurfFlatRegion( nLayId, vCrvs) - for nInd = 1, #vCrvs do - EgtErase( vCrvs[nInd]) - end + --for nInd = 1, #vCrvs do + -- EgtErase( vCrvs[nInd]) + --end if nSurfFR then -- analizzo i singoli chunks diff --git a/LuaLibs/CalcSolids.lua b/LuaLibs/CalcSolids.lua index 05847eb..49f6f75 100644 --- a/LuaLibs/CalcSolids.lua +++ b/LuaLibs/CalcSolids.lua @@ -1,4 +1,4 @@ --- CalcSolids.lua by Egaltech s.r.l. 2022/03/30 +-- CalcSolids.lua by Egaltech s.r.l. 2022/04/13 -- Calcolo percorsi di lavoro per Stampa 3d -- Tabella per definizione modulo @@ -23,18 +23,41 @@ local function GetLayerParamsForSolidCalc() return LayerParams end + +--------------------------------------------------------------------- +local function CalcSectionParams( dStrand, dH) + local dL = dStrand + local dLm = dStrand / 10 + local dHm = dH / 6 + -- recupero offset + local nParamsGrp = EgtGetFirstNameInGroup( GDB_ID.ROOT, PARAMS_GRP) + --local dOffs = EgtGetInfo( nParamsGrp, 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 + local dD4 = dH - 2 * dD3 + return dD1, dD2, dD3, dD4 +end + --------------------------------------------------------------------- local function CreateSection( ptS, vtDir, dStrand, dH, nSolidGrp) - ptS = ptS - dH * Z_AX() - local dD1 = 0.5 * dStrand - dStrand / 10 - local dD2 = 0.5 * dStrand - dD1 - local dD3 = dH / 6 - local dD4 = dH - 2 * dD3 - - vtDir:rotate( Z_AX(), 90) - - local ptA = ptS + dD1 * vtDir + local dD1, dD2, dD3, dD4 = CalcSectionParams( dStrand, dH) + local ptA = ptS - dH * Z_AX() + dD1 * vtDir local ptB = ptA + dD2 * vtDir + dD3 * Z_AX() local ptC = ptB + dD4 * Z_AX() local ptD = ptA + dH * Z_AX() @@ -48,138 +71,90 @@ local function CreateSection( ptS, vtDir, dStrand, dH, nSolidGrp) return nId end +--------------------------------------------------------------------- +local function CreateHalfSection( ptS, vtDir, dStrand, dH, nSolidGrp) + + local dD1, dD2, dD3, dD4 = CalcSectionParams( dStrand, dH) + local ptA = ptS - dH * Z_AX() + dD1 * vtDir + local ptB = ptA + dD2 * vtDir + dD3 * Z_AX() + local ptC = ptB + dD4 * Z_AX() + local ptD = ptA + dH * Z_AX() + + local nId = EgtCurveCompoFromPoints( nSolidGrp, { ptS - dH * Z_AX(), ptA, ptB, ptC, ptD, ptS}) + + return nId +end + -------------------------------------------------------------------- local function CloseSolid( nCrvId, nSrfId, nSolidGrp, LayerParams) local ptS = EgtSP( nCrvId) local vtS = EgtSV( nCrvId) - local nSectS = CreateSection( ptS, vtS, LayerParams.dStrand, LayerParams.dLayHeight, nSolidGrp) - local nSrfS = EgtSurfTmByRevolve( nSolidGrp, nSectS, ptS, Z_AX(), false, 0.1) - EgtCutSurfTmPlane( nSrfS, ptS, EgtSV( nCrvId), true) + vtS:rotate( Z_AX(), 90) + local nSectS = CreateHalfSection( ptS, vtS, LayerParams.dStrand, LayerParams.dLayHeight, nSolidGrp) + local nSrfS = EgtSurfTmByScrewing( nSolidGrp, nSectS, ptS, Z_AX(), 180, 0, false, 0.1) + EgtErase( nSectS) local ptE = EgtEP( nCrvId) local vtE = EgtEV( nCrvId) - local nSectE = CreateSection( ptE, vtE, LayerParams.dStrand, LayerParams.dLayHeight, nSolidGrp) - local nSrfE = EgtSurfTmByRevolve( nSolidGrp, nSectE, ptE, Z_AX(), false, 0.1) - EgtCutSurfTmPlane( nSrfE, ptE, - EgtEV( nCrvId), true) - - EgtErase( nSectS) + vtE:rotate( Z_AX(), -90) + local nSectE = CreateHalfSection( ptE, vtE, LayerParams.dStrand, LayerParams.dLayHeight, nSolidGrp) + local nSrfE = EgtSurfTmByScrewing( nSolidGrp, nSectE, ptE, Z_AX(), 180, 0, false, 0.1) EgtErase( nSectE) + return EgtSurfTmBySewing( nSolidGrp, { nSrfId, nSrfS, nSrfE}) end --------------------------------------------------------------------- -local function CreateSolidFromCurve( nCrvId, nSolidGrp, LayerParams, nParts) - - local nCopyId = EgtCopyGlob( nCrvId, nSolidGrp) - +local function CreateSolidFromCurve( nCrvId, nSolidGrp, LayerParams) + -- scelta del colore local nType = EgtGetInfo( nCrvId, KEY_TYPE, 'i') local Color = EgtStdColor( 'GRAY') if nType == TYPE.OUTER_SHELL then - Color = EgtStdColor( 'ORANGE') - elseif nType == TYPE.INNER_SHELL or nType == TYPE.LINK then Color = EgtStdColor( 'TEAL') + elseif nType == TYPE.INNER_SHELL then + Color = EgtStdColor( 'ORANGE') + elseif nType == TYPE.LINK then + Color = EgtStdColor( 'GRAY') elseif nType == TYPE.INFILL then Color = EgtStdColor( 'YELLOW') end - local nDefaultParts = EgtIf( nType == TYPE.LINK, 1, 10) - if not nParts then - nParts = nDefaultParts - elseif nParts == nDefaultParts then - nParts = nDefaultParts + 1 - end + local nParts = EgtIf( nType == TYPE.LINK, 1, 10) + local nCopyId = EgtCopyGlob( nCrvId, nSolidGrp) local nId = EgtSplitCurve( nCopyId, nParts) - local vIdStm = {} - + for nInd = 0, nParts - 1 do - - if nType == TYPE.INFILL and nInd == 0 then - EgtInvertCurve( nId + nInd) - end - + local ptS = EgtSP( nId + nInd) local vtS = EgtSV( nId + nInd) + vtS:rotate( Z_AX(), 90) local nSectId = CreateSection( ptS, vtS, LayerParams.dStrand, LayerParams.dLayHeight, nSolidGrp) EgtInvertCurve( nSectId) local nSrfId = EgtSurfTmSwept( nSolidGrp, nSectId, nId + nInd, false, 0.1) - + EgtErase( nSectId) if nSrfId then - table.insert( vIdStm, nSrfId) + nSrfId = CloseSolid( nId + nInd, nSrfId, nSolidGrp, LayerParams) else - if nParts < 100 then - -- cancello quando appena fatto e provo a spezzare la curva in un diverso numero di parti - 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 - local nNewParts = EgtIf( nParts == nDefaultParts, 5, nParts + 1) - CreateSolidFromCurve( nCrvId, nSolidGrp, LayerParams, nNewParts) - return - else - EgtOutBox( 'CalcSolid error', '') - 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 - return - end + 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 end - - EgtErase( nSectId) + EgtSetColor( nSrfId, Color) + EgtSetInfo( nSrfId, KEY_TYPE, nType) + EgtErase( nId + nInd) end - - -- se ho creato troppe parts unisco le superfici per ridurne il numero - local vCrvIds = {} - if nParts > nDefaultParts then - local nGroups1 = nParts % nDefaultParts - local nGroups2 = nDefaultParts - nGroups1 - local nElements1 = ceil( nParts / nDefaultParts) - local nElements2 = floor( nParts / nDefaultParts) - local nCnt = 0 - local nInd = 1 - while nInd <= #vIdStm do - local nElements = EgtIf( nCnt < nGroups1, nElements1, nElements2) - local vIds = { vIdStm[nInd]} - local nFirstId = nId + nInd - 1 - for nId2 = 1, nElements - 1 do - nInd = nInd + 1 - table.insert( vIds, vIdStm[nInd]) - EgtAddCurveCompoCurve( nFirstId, nId + nInd - 1) - end - - local nNewSrf = EgtSurfTmByTriangles( nSolidGrp, vIds) - nInd = nInd + 1 - nCnt = nCnt + 1 - - table.insert( vCrvIds, nFirstId) - vIdStm[nCnt] = nNewSrf - end - nParts = nDefaultParts - else - for nInd = 0, nParts - 1 do - table.insert( vCrvIds, nId + nInd) - end - end - - for nInd = 1, nParts do - vIdStm[nInd] = CloseSolid( vCrvIds[nInd], vIdStm[nInd], nSolidGrp, LayerParams) - EgtSetColor( vIdStm[nInd], Color) - EgtSetInfo( vIdStm[nInd], KEY_TYPE, nType) - EgtErase( vCrvIds[nInd]) - end - + end --------------------------------------------------------------------- @@ -206,7 +181,7 @@ function CalcSolids.Exec( nPartId) return end - -- recupero il gruppo dei soldi + -- recupero il gruppo dei solidi local nSolidGrpId = EgtGetFirstNameInGroup( nCrvGrpId, SOLID_GRP) or GDB_ID.NULL if nSolidGrpId == GDB_ID.NULL then nSolidGrpId = EgtGroup( nCrvGrpId) @@ -215,7 +190,7 @@ function CalcSolids.Exec( nPartId) EgtEmptyGroup( nSolidGrpId) end - -- scorro le curve + -- scorro le curve del percorso utensile local nId = EgtGetFirstInGroup( nTPathGrpId) while nId do CreateSolidFromCurve( nId, nSolidGrpId, LayerParams) @@ -227,12 +202,20 @@ function CalcSolids.Exec( nPartId) for nInd = 1, #vExtCrvs do EgtSetStatus( vExtCrvs[nInd], GDB_ST.OFF) end - + + -- processo gli eventi + if ( nIdx % 20) == 0 then + EgtDraw() + if EgtProcessEvents( nIdx / #vLayIds * 100, 0) == 1 then + return + end + end + --passo al gruppo di contorni successivo nCrvGrpId = EgtGetNextName( nCrvGrpId, CONTOUR_GRP.."*") or GDB_ID.NULL end + EgtDraw() if EgtProcessEvents( nIdx / #vLayIds * 100, 0) == 1 then - EgtDraw() return end end diff --git a/LuaLibs/CalcToolPath.lua b/LuaLibs/CalcToolPath.lua index 7722dfb..6180c9f 100644 --- a/LuaLibs/CalcToolPath.lua +++ b/LuaLibs/CalcToolPath.lua @@ -1,4 +1,4 @@ --- CalcToolPath.lua by Egaltech s.r.l. 2022/03/29 +-- CalcToolPath.lua by Egaltech s.r.l. 2022/04/13 -- Calcolo percorsi di lavoro per Stampa 3d -- Tabella per definizione modulo @@ -40,7 +40,7 @@ local function AddLeadIn( nCrvId, LayerParams, nGrpId) local vtTang = EgtSV( nCrvId) local vtOrtho = Vector3d( vtTang) local dAng = 90 - if ( LayerParams.bInvert and LayerParams.nOrder == PRINT_ORDER.INT_EXT_INF) or + if ( LayerParams.bInvert and LayerParams.nOrder == PRINT_ORDER.INF_INT_EXT) or ( not LayerParams.bInvert and LayerParams.nOrder == PRINT_ORDER.EXT_INT_INF) then dAng = - 90 end @@ -65,31 +65,30 @@ end -------------------------------------------------------------------- local function AddLeadOut( nCrvId, LayerParams, nGrpId) - + local ptS = EgtEP( nCrvId) local vtTang = EgtEV( nCrvId) local vtOrtho = Vector3d( vtTang) local dAng = - 90 - if ( LayerParams.bInvert and LayerParams.nOrder == PRINT_ORDER.INT_EXT_INF) or + if ( LayerParams.bInvert and LayerParams.nOrder == PRINT_ORDER.INF_INT_EXT) or ( not LayerParams.bInvert and LayerParams.nOrder == PRINT_ORDER.EXT_INT_INF) then dAng = 90 end - + vtOrtho:rotate( Z_AX(), dAng) local ptE = ptS + LayerParams.LeadOutTangDist * vtTang + LayerParams.LeadOutOrthoDist * vtOrtho - + local nLeadOutCrv = GDB_ID.NULL if LayerParams.LeadOutType == LEAD_TYPE.LINEAR then nLeadOutCrv = EgtLine( nGrpId, ptS, ptE) 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) EgtSetInfo( nLeadOutCrv, KEY_TYPE, TYPE.LINK) - end @@ -136,14 +135,14 @@ function CalcToolPath.Exec( nPartId) -- copio le curve, le ordino, le oriento e le muovo in Z local nEntId = EgtGetFirstInGroup( nPathGrpId) while nEntId do - local nNewEntId = EgtCopyGlob( nEntId, nTpathGrpId, EgtIf( LayerParams.nOrder == PRINT_ORDER.INT_EXT_INF, GDB_IN.FIRST_SON, GDB_IN.LAST_SON)) + local nNewEntId = EgtCopyGlob( nEntId, nTpathGrpId, EgtIf( LayerParams.nOrder == PRINT_ORDER.INF_INT_EXT, GDB_IN.FIRST_SON, GDB_IN.LAST_SON)) EgtMove( nNewEntId, Vector3d( 0, 0, LayerParams.dLayHeight), GDB_RT.GLOB) if LayerParams.bInvert then EgtInvertCurve( nNewEntId) end nEntId = EgtGetNext( nEntId) end - + -- aggiungo gli opportuni raccordi local nPrevId = EgtGetFirstInGroup( nTpathGrpId) local nCurrId = EgtGetNext( nPrevId or GDB_ID.NULL) @@ -153,10 +152,12 @@ function CalcToolPath.Exec( nPartId) EgtTrimCurveEndAtLen( nPrevId, EgtCurveLength( nPrevId) - k * LayerParams.LinkDist) k = k + 1 EgtChangeClosedCurveStartPoint( nCurrId, EgtEP( nPrevId)) - + if LayerParams.LinkType == LINK_TYPE.LINEAR then - nLinkId = EgtLine( nTpathGrpId, EgtEP( nPrevId), EgtEP( nCurrId)) - else + EgtTrimCurveEndAtLen( nPrevId, EgtCurveLength( nPrevId) - LayerParams.LinkParam / 2) + EgtTrimCurveStartAtLen( nCurrId, LayerParams.LinkParam / 2) + nLinkId = EgtLine( nTpathGrpId, EgtEP( nPrevId), EgtSP( nCurrId)) + else EgtTrimCurveEndAtLen( nPrevId, EgtCurveLength( nPrevId) - LayerParams.LinkParam / 2) EgtTrimCurveStartAtLen( nCurrId, LayerParams.LinkParam / 2) local _, _, dAngIni = SphericalFromVector( EgtEV( nPrevId)) diff --git a/LuaLibs/RunGcodeGenerate.lua b/LuaLibs/RunGcodeGenerate.lua index b37260c..e636e13 100644 --- a/LuaLibs/RunGcodeGenerate.lua +++ b/LuaLibs/RunGcodeGenerate.lua @@ -13,6 +13,15 @@ EgtOutLog( ' RunGcodeGenerate started', 1) _G.package.loaded.AddManData = nil local AMD = require( 'AddManData') +--------------------------------------------------------------------- +local function GetLayerParamsForGcodeGenerate() + local nParamsGrp = EgtGetFirstNameInGroup( GDB_ID.ROOT, PARAMS_GRP) + local LayerParams = {} + LayerParams.LinkZup = EgtGetInfo( nParamsGrp, KEY_LINK_ZUP, 'd') + return LayerParams +end + +--------------------------------------------------------------------- function RunGcodeGenerate.Exec() -- Recupero il pezzo (per ora primo e unico) local nPartIndex = 1 @@ -25,10 +34,13 @@ function RunGcodeGenerate.Exec() -- Recupero i layer da processare local vLayIds = EgtGetNameInGroup( nPartId, SLICE_LAYER.."*") if not vLayIds then - EgtOutBox( 'Error missing slices', 'ToolPathCalc') + EgtOutBox( 'Error missing slices', 'GcodeGenerate') return end + -- Recupero i parametri relativi al layer + local LayerParams = GetLayerParamsForGcodeGenerate() + -- Ciclo sui layer local vEntId = {} for nIdx = 1, #vLayIds do @@ -38,7 +50,7 @@ function RunGcodeGenerate.Exec() -- recupero il gruppo dei percorsi utensile local nTpathGrpId = EgtGetFirstNameInGroup( nCrvGrpId, TOOLPATH_GRP) if not nTpathGrpId then - EgtOutBox( 'Error missing toolpaths', 'ToolPathCalc') + EgtOutBox( 'Error missing toolpaths', 'GcodeGenerate') return end -- recupero le entità nel gruppo @@ -52,15 +64,28 @@ function RunGcodeGenerate.Exec() end end if #vEntId == 0 then - EgtOutBox( 'Error missing entities', 'ToolPathCalc') + EgtOutBox( 'Error missing entities', 'GcodeGenerate') return end -- Aggiungo la lavorazione EgtSetCurrMachGroup() - EgtAddMachining( 'Extrusion 1', 'ExtrusionA') + + local nMchId = EgtAddMachining( 'Extrusion 1', 'ExtrusionA') + if not nMchId then + EgtOutBox( 'Error adding Extrusion', 'GcodeGenerate') + return + end + EgtSetMachiningGeometry( vEntId) - EgtApplyMachining() + + local sNotes = EgtAdjustNotes( '', 'LinkZup', LayerParams.LinkZup) + EgtSetMachiningParam( MCH_MP.USERNOTES, sNotes) + + if not EgtApplyMachining() then + EgtOutBox( 'Error applying Extrusion', 'GcodeGenerate') + return + end end --------------------------------------------------------------------- diff --git a/LuaLibs/RunMachiningParamCalc.lua b/LuaLibs/RunMachiningParamCalc.lua index 3958e6e..498734f 100644 --- a/LuaLibs/RunMachiningParamCalc.lua +++ b/LuaLibs/RunMachiningParamCalc.lua @@ -1,4 +1,4 @@ --- RunMachiningParamCalc.lua by Egaltech s.r.l. 2022/04/05 +-- RunMachiningParamCalc.lua by Egaltech s.r.l. 2022/04/13 -- Gestione visualizzazione per Stampa 3d -- Tabella per definizione modulo @@ -31,8 +31,7 @@ function RunMachiningParamCalc.Exec() local dCoeffY = tonumber( EgtGetStringFromIni( DEFAULT_SECTION, KEY_COEFF_Y, 0, sMachiningPath)) local sCalcBaseDir = EgtGetStringFromIni( '3dPrinting', 'BaseDir', 'C:\\ProgramData\\Egaltech\\EgtCam5\\3dPrinting', EgtGetIniFile()) local sCurrProjectPath = EgtGetCurrFilePath() - local _, sCurrProjectName = EgtSplitPath( sCurrProjectPath) - local sResultFile = sCalcBaseDir .. '\\Results\\' .. sCurrProjectName .. '.csv' + local sResultFile = EgtChangePathExtension( sCurrProjectPath, '.csv') local bResultFile = EgtExistsFile( sResultFile) -- calcolo intervallo tempi consentito diff --git a/LuaLibs/RunShowManager.lua b/LuaLibs/RunShowManager.lua index bf9f3d1..1a99388 100644 --- a/LuaLibs/RunShowManager.lua +++ b/LuaLibs/RunShowManager.lua @@ -29,8 +29,8 @@ function RunShowManager.Exec() local bImportedSolid = false local bOuterCrv = false local bPath = false - local bSolid = true - local bToolPath = true + local bSolid = false + local bToolPath = false if not nViewId then nViewId = EgtGroup( GDB_ID.ROOT) diff --git a/LuaLibs/RunSliceAdvancement.lua b/LuaLibs/RunSliceAdvancement.lua index 6bd6b23..1970c43 100644 --- a/LuaLibs/RunSliceAdvancement.lua +++ b/LuaLibs/RunSliceAdvancement.lua @@ -24,23 +24,51 @@ local function ManageSegmentVisibility( SegmentList, nLastActiveIndex, ToHideLis end function RunSliceAdvancement.Exec() - ViewValues = EgtDialogBox( 'Slice advancement', { 'Type', 'CB:*All,Only Outer,Only Inner,Only Infill'}, - { 'Percentage (0-100)', '30'}) + -- verifico ci sia almeno uno slice + local nPartId = EgtGetFirstNameInGroup( GDB_ID.ROOT, PART .. 1) + if not nPartId then + EgtOutBox( 'No sliced part in this project!', 'Error', 'ERROR') + return + else + local nLayerId = EgtGetFirstNameInGroup( nPartId, SLICE_LAYER .. 1) + if not nLayerId then + EgtOutBox( 'No sliced part in this project!', 'Error', 'ERROR') + return + end + end + local nAdvancementType = 1 -- 1 = All, 2 = Only Outer, 3 = Only Inner, 4 = Only Infill + local nPercentage = 30 + -- leggo ultimi valori + local nViewId = EgtGetFirstNameInGroup( GDB_ID.ROOT, VIEWPARAMS) + if nViewId then + nAdvancementType = EgtGetInfo( nViewId, KEY_SLICE_ADV_MODE, 'i') or SLICE_ADV_TYPE.ALL + nPercentage = EgtGetInfo( nViewId, KEY_SLICE_ADV_PERC, 'i') or 30 + end + local sAdvTypeCombo = '' + if nAdvancementType == SLICE_ADV_TYPE.ALL then + sAdvTypeCombo = 'CB:*All,Only Outer,Only Inner,Only Infill' + elseif nAdvancementType == SLICE_ADV_TYPE.OUTER then + sAdvTypeCombo = 'CB:All,*Only Outer,Only Inner,Only Infill' + elseif nAdvancementType == SLICE_ADV_TYPE.INNER then + sAdvTypeCombo = 'CB:All,Only Outer,*Only Inner,Only Infill' + elseif nAdvancementType == SLICE_ADV_TYPE.INFILL then + sAdvTypeCombo = 'CB:All,Only Outer,Only Inner,*Only Infill' + end + ViewValues = EgtDialogBox( 'Slice advancement', { 'Type', sAdvTypeCombo}, + { 'Percentage (0-100)', tostring( nPercentage)}) if not ViewValues or #ViewValues < 1 then return end - local nAdvancementType = 1 -- 1 = All, 2 = Only Outer, 3 = Only Inner, 4 = Only Infill if ViewValues[1] == 'All' then - nAdvancementType = 1 + nAdvancementType = SLICE_ADV_TYPE.ALL elseif ViewValues[1] == 'Only Outer' then - nAdvancementType = 2 + nAdvancementType = SLICE_ADV_TYPE.OUTER elseif ViewValues[1] == 'Only Inner' then - nAdvancementType = 3 + nAdvancementType = SLICE_ADV_TYPE.INNER elseif ViewValues[1] == 'Only Infill' then - nAdvancementType = 4 + nAdvancementType = SLICE_ADV_TYPE.INFILL end - - local nPercentage = tonumber( ViewValues[2]) - + nPercentage = tonumber( ViewValues[2]) + local nParamsGrp = EgtGetFirstNameInGroup( GDB_ID.ROOT, PARAMS_GRP) or GDB_ID.NULL local nPrintOrder = EgtGetInfo( nParamsGrp, KEY_PRINT_ORDER, 'i') -- ciclo sui pezzi @@ -54,20 +82,20 @@ function RunSliceAdvancement.Exec() local nCrvId = EgtGetFirstGroupInGroup( nLayerId) while nCrvId do local nSolidId = EgtGetFirstNameInGroup( nCrvId, SOLID_GRP) - local ShellList = { {}, {}} + local ShellList = { {}, {}, {}} local nSurfId = EgtGetFirstInGroup( nSolidId) - local nOldType = 0 + local nOldType = TYPE.OUTER_SHELL while nSurfId do local nType = EgtGetInfo( nSurfId, KEY_TYPE, 'i') - if not nType or ( nType ~= 0 and nType ~= 1) then nType = nOldType end + if not nType or ( nType ~= TYPE.OUTER_SHELL and nType ~= TYPE.INNER_SHELL and nType ~= TYPE.INFILL) then nType = nOldType end nOldType = nType - table.insert( ShellList[nType + 1], nSurfId) + table.insert( ShellList[nType], nSurfId) nSurfId = EgtGetNext( nSurfId) end local nSegmentQty = 1 local SegmentList local ToHideList - if nAdvancementType == 1 then + if nAdvancementType == SLICE_ADV_TYPE.ALL then nSegmentQty = #ShellList[1] + #ShellList[2] if nPrintOrder == PRINT_ORDER.EXT_INT_INF then SegmentList = ShellList[1] @@ -80,14 +108,21 @@ function RunSliceAdvancement.Exec() SegmentList[#SegmentList + 1] = ShellList[1][i] end end - elseif nAdvancementType == 2 then + elseif nAdvancementType == SLICE_ADV_TYPE.OUTER then nSegmentQty = #ShellList[1] SegmentList = ShellList[1] ToHideList = ShellList[2] - elseif nAdvancementType == 3 then + elseif nAdvancementType == SLICE_ADV_TYPE.INNER then nSegmentQty = #ShellList[2] SegmentList = ShellList[2] ToHideList = ShellList[1] + elseif nAdvancementType == SLICE_ADV_TYPE.INFILL then + nSegmentQty = 1 + SegmentList = {} + ToHideList = ShellList[1] + for i = 1, #ShellList[2] do + ToHideList[#ToHideList + 1] = ShellList[2][i] + end end local nLastActiveIndex = ceil( nSegmentQty * nPercentage / 100) ManageSegmentVisibility( SegmentList, nLastActiveIndex, ToHideList) @@ -100,6 +135,10 @@ function RunSliceAdvancement.Exec() nPartId = EgtGetFirstNameInGroup( GDB_ID.ROOT, PART .. nPartIndex) end + -- riporto impostazioni in gruppo apposito + EgtSetInfo( nViewId, KEY_SLICE_ADV_MODE, nAdvancementType) + EgtSetInfo( nViewId, KEY_SLICE_ADV_PERC, nPercentage) + EgtDraw() end diff --git a/LuaLibs/RunSlicePalette.lua b/LuaLibs/RunSlicePalette.lua index 35fbd73..9cedc93 100644 --- a/LuaLibs/RunSlicePalette.lua +++ b/LuaLibs/RunSlicePalette.lua @@ -30,13 +30,15 @@ function RunSlicePalette.UpdateColors( nPaletteType) local Color = EgtStdColor( 'GRAY') if nPaletteType == PALETTE_TYPE.IN_OUT then local nType = EgtGetInfo( nSurfId, KEY_TYPE, 'i') - if not nType or ( nType ~= 0 and nType ~= 1) then nType = nOldType end + if not nType or ( nType ~= 1 and nType ~= 2 and nType ~= 3 and nType ~= 4) then nType = nOldType end nOldType = nType -- scelta del colore if nType == TYPE.OUTER_SHELL then - Color = EgtStdColor( 'ORANGE') - elseif nType == TYPE.INNER_SHELL or nType == TYPE.LINK then Color = EgtStdColor( 'TEAL') + elseif nType == TYPE.INNER_SHELL then + Color = EgtStdColor( 'ORANGE') + elseif nType == TYPE.LINK then + Color = EgtStdColor( 'GRAY') elseif nType == TYPE.INFILL then Color = EgtStdColor( 'YELLOW') end @@ -70,7 +72,7 @@ function RunSlicePalette.Exec() local nParamsGrp = EgtGetFirstNameInGroup( GDB_ID.ROOT, PARAMS_GRP) or GDB_ID.NULL local nOldPaletteType = EgtGetInfo( nParamsGrp, KEY_PALETTE, 'i') - local sCombo = EgtIf( not nOldPaletteType or nOldPaletteType == 0, 'CB:*In/Out,Results', 'CB:In/Out,*Results') + local sCombo = EgtIf( not nOldPaletteType or nOldPaletteType == 1, 'CB:*In/Out,Results', 'CB:In/Out,*Results') ViewValues = EgtDialogBox( 'Slice Palette', { 'Type', sCombo}) if not ViewValues or #ViewValues < 1 then return end diff --git a/LuaLibs/RunSlicing.lua b/LuaLibs/RunSlicing.lua index b3308fc..ddd3bdb 100644 --- a/LuaLibs/RunSlicing.lua +++ b/LuaLibs/RunSlicing.lua @@ -1,4 +1,4 @@ --- RunSlicing.lua by Egaltech s.r.l. 2022/03/30 +-- RunSlicing.lua by Egaltech s.r.l. 2022/04/12 -- Calcoli prima fase per Stampa 3d -- Tabella per definizione modulo @@ -51,11 +51,11 @@ local function LoadParams( sFile, nPartId) local ptStart = EgtGetVal( 'P='..sStartPoint..',0', 'P', 'p') EgtSetInfo( nParamsGrp, KEY_START_POINT, ptStart) - local sStrandOrder = EgtGetStringFromIni( DEFAULT_SECTION, KEY_PRINT_ORDER, 'in', sFile) - if sStrandOrder == 'out' then + local sStrandOrder = EgtGetStringFromIni( DEFAULT_SECTION, KEY_PRINT_ORDER, 'InToOut', sFile) + if sStrandOrder == 'OutToIn' then EgtSetInfo( nParamsGrp, KEY_PRINT_ORDER, PRINT_ORDER.EXT_INT_INF) - else -- sStrandOrder == 'in' - EgtSetInfo( nParamsGrp, KEY_PRINT_ORDER, PRINT_ORDER.INT_EXT_INF) + else -- 'InToOut' + EgtSetInfo( nParamsGrp, KEY_PRINT_ORDER, PRINT_ORDER.INF_INT_EXT) end local sStrandDirection = EgtGetStringFromIni( DEFAULT_SECTION, KEY_PRINT_DIRECTION, 'CCW', sFile) @@ -65,14 +65,15 @@ local function LoadParams( sFile, nPartId) EgtSetInfo( nParamsGrp, KEY_PRINT_DIRECTION, PRINT_DIRECTION.CCW) end - local sLinkType = EgtGetStringFromIni( DEFAULT_SECTION, KEY_LINK_TYPE, 'straight', sFile) - if sLinkType == 'sPath' then + local sLinkType = EgtGetStringFromIni( DEFAULT_SECTION, KEY_LINK_TYPE, 'BiArc', sFile) + if sLinkType == 'BiArc' then EgtSetInfo( nParamsGrp, KEY_LINK_TYPE, LINK_TYPE.BIARC) - else -- sStrandOrder == 'sPath' + else -- 'Linear' EgtSetInfo( nParamsGrp, KEY_LINK_TYPE, LINK_TYPE.LINEAR) end SetParamInfo( sFile, nParamsGrp, DEFAULT_SECTION, KEY_LINK_PARAM, '0') + SetParamInfo( sFile, nParamsGrp, DEFAULT_SECTION, KEY_LINK_ZUP, '0') SetParamInfo( sFile, nParamsGrp, DEFAULT_SECTION, KEY_LINK_DIST, '0.0') SetParamInfo( sFile, nParamsGrp, DEFAULT_SECTION, KEY_FLOOR_NBR, '0') SetParamInfo( sFile, nParamsGrp, DEFAULT_SECTION, KEY_SPEED, '0.0') @@ -107,6 +108,12 @@ end function RunSlicing.Exec() + -- Verifico che il progetto sia stato salvato + local sCurrProjectPath = EgtGetCurrFilePath() + if not sCurrProjectPath or sCurrProjectPath == '' then + EgtOutBox( 'Save project before calculating slicing!', 'Warning', 'WARNING') + return + end -- Recupero ultimo oggetto selezionato local nStmId = EgtGetLastSelectedObj() -- Verifico sia una superficie @@ -116,7 +123,13 @@ function RunSlicing.Exec() return end local nPartId = EgtGetParent( EgtGetParent( nStmId)) - + + -- Verifico che il pezzo sia stato posizionato in macchina + local sPartName = EgtGetName( nPartId) + if not sPartName or sPartName == '' or sPartName:sub( 1, 4) ~= PART then + EgtOutBox( 'Position part on the machine table before slicing it!', 'Error', 'ERROR') + return + end -- Scelta del file dei parametri local sLastParamFile = EgtGetStringFromIni( '3dPrinting', 'ParamFile', 'C:\\ProgramData\\Egaltech\\EgtCam5\\3dPrinting\\Machinings\\aaa.ini', EgtGetIniFile()) local sDir = EgtSplitPath( sLastParamFile) @@ -129,7 +142,6 @@ function RunSlicing.Exec() -- Elimino eventuale precedente file dei risultati local sCalcBaseDir = EgtGetStringFromIni( '3dPrinting', 'BaseDir', 'C:\\ProgramData\\Egaltech\\EgtCam5\\3dPrinting', EgtGetIniFile()) - local sCurrProjectPath = EgtGetCurrFilePath() local _, sCurrProjectName = EgtSplitPath( sCurrProjectPath) local sResultFile = sCalcBaseDir .. '\\Results\\' .. sCurrProjectName .. '.csv' EgtEraseFile( sResultFile) @@ -154,6 +166,18 @@ function RunSlicing.Exec() EgtSetStatus( nStmId, GDB_ST.OFF) EgtDraw() + -- Aggiorno impostazioni di visibilita' per ShowManager + local nViewId = EgtGetFirstNameInGroup( GDB_ID.ROOT, VIEWPARAMS) + if not nViewId then + nViewId = EgtGroup( GDB_ID.ROOT) + EgtSetName( nViewId, VIEWPARAMS) + end + EgtSetInfo( nViewId, IMPORTED_SOLID, false) + EgtSetInfo( nViewId, OUTER_CRV, false) + EgtSetInfo( nViewId, PATH_GRP, false) + EgtSetInfo( nViewId, SOLID_GRP, true) + EgtSetInfo( nViewId, TOOLPATH_GRP, true) + end --------------------------------------------------------------------- diff --git a/LuaLibs/RunViewManager.lua b/LuaLibs/RunViewManager.lua index 13e8ba4..cf60dff 100644 --- a/LuaLibs/RunViewManager.lua +++ b/LuaLibs/RunViewManager.lua @@ -13,31 +13,56 @@ EgtOutLog( ' RunViewManager started', 1) local AMD = require( 'AddManData') function RunViewManager.Exec() - ViewValues = EgtDialogBox( 'Slicing visibility manager', { 'Visibility Mode', 'CB:*All,Till Selected,Only Selected'}, - { 'Shell type', 'CB:*All,Outer,Inner,Infill'}, - { 'Inner Number', '1'}) + local nVisibilityMode = LAYER_VIEW_TYPE.ALL -- 1 = All, 2 = Till Selected, 3 = Only Selected + local nShellType = SHELL_VIEW_TYPE.ALL -- 1 = All, 2 = Outer, 3 = Inner, 4 = infill + local nOldSelLayerId = GDB_ID.NULL + + -- leggo ultimi valori + local nViewId = EgtGetFirstNameInGroup( GDB_ID.ROOT, VIEWPARAMS) + if nViewId then + nVisibilityMode = EgtGetInfo( nViewId, KEY_LAYER_VIEW, 'i') + nShellType = EgtGetInfo( nViewId, KEY_SHELL_VIEW, 'i') + nOldSelLayerId = EgtGetInfo( nViewId, KEY_SEL_LAYER, 'i') or GDB_ID.NULL + end + local sLayerViewCombo = '' + if nVisibilityMode == LAYER_VIEW_TYPE.TILL_SEL then + sLayerViewCombo = 'CB:All,*Till Selected,Only Selected' + elseif nVisibilityMode == LAYER_VIEW_TYPE.ONLY_SEL then + sLayerViewCombo = 'CB:All,Till Selected,*Only Selected' + else + sLayerViewCombo = 'CB:*All,Till Selected,Only Selected' + end + local sShellViewCombo = '' + if nShellType == SHELL_VIEW_TYPE.OUTER then + sShellViewCombo = 'CB:All,*Outer,Inner,Infill' + elseif nShellType == SHELL_VIEW_TYPE.INNER then + sShellViewCombo = 'CB:All,Outer,*Inner,Infill' + elseif nShellType == SHELL_VIEW_TYPE.INFILL then + sShellViewCombo = 'CB:All,Outer,Inner,*Infill' + else + sShellViewCombo = 'CB:*All,Outer,Inner,Infill' + end + + ViewValues = EgtDialogBox( 'Slicing visibility manager', { 'Visibility Mode', sLayerViewCombo}, + { 'Shell type', sShellViewCombo}) if not ViewValues or #ViewValues < 2 then return end - - local nVisibilityMode = 1 -- 1 = All, 2 = Till Selected, 3 = Only Selected if ViewValues[1] == 'All' then - nVisibilityMode = 1 + nVisibilityMode = LAYER_VIEW_TYPE.ALL elseif ViewValues[1] == 'Till Selected' then - nVisibilityMode = 2 + nVisibilityMode = LAYER_VIEW_TYPE.TILL_SEL elseif ViewValues[1] == 'Only Selected' then - nVisibilityMode = 3 + nVisibilityMode = LAYER_VIEW_TYPE.ONLY_SEL end - local nShellType = 0 -- 1 = All, 2 = Outer, 3 = Inner, 4 = infill if ViewValues[2] == 'All' then - nShellType = 1 + nShellType = SHELL_VIEW_TYPE.ALL elseif ViewValues[2] == 'Outer' then - nShellType = 2 + nShellType = SHELL_VIEW_TYPE.OUTER elseif ViewValues[2] == 'Inner' then - nShellType = 3 + nShellType = SHELL_VIEW_TYPE.INNER elseif ViewValues[2] == 'Infill' then - nShellType = 4 + nShellType = SHELL_VIEW_TYPE.INFILL end - local nInnerNumber = tonumber(ViewValues[3]) -- Recupero ultimo layer selezionato -- verifico sia un pezzo valido @@ -53,12 +78,16 @@ function RunViewManager.Exec() nSelLayerId = EgtGetParent( nSelLayerId) end if not bFound then - if nVisibilityMode ~= 1 then - EgtOutBox( 'No selected element!', 'Warning', 'WARNING') - return + if nOldSelLayerId and nOldSelLayerId ~= GDB_ID.NULL then + nSelLayerId = nOldSelLayerId else - nSelLayerId = GDB_ID.NULL - sSelLayerName = '' + if nVisibilityMode ~= LAYER_VIEW_TYPE.ALL then + EgtOutBox( 'No selected element!', 'Warning', 'WARNING') + return + else + nSelLayerId = GDB_ID.NULL + sSelLayerName = '' + end end end @@ -70,11 +99,11 @@ function RunViewManager.Exec() local nLayerIndex = 1 local nLayerId = EgtGetFirstNameInGroup( nPartId, SLICE_LAYER .. nLayerIndex) while nLayerId do - if nVisibilityMode == 1 then -- All + if nVisibilityMode == LAYER_VIEW_TYPE.ALL then EgtSetStatus( nLayerId, GDB_ST.ON) - elseif nVisibilityMode == 2 then -- Till Selected + elseif nVisibilityMode == LAYER_VIEW_TYPE.TILL_SEL then EgtSetStatus( nLayerId, EgtIf( nLayerId <= nSelLayerId, GDB_ST.ON, GDB_ST.OFF)) - elseif nVisibilityMode == 3 then -- Only Selected + elseif nVisibilityMode == LAYER_VIEW_TYPE.ONLY_SEL then EgtSetStatus( nLayerId, EgtIf( nLayerId == nSelLayerId, GDB_ST.ON, GDB_ST.OFF)) end local nCrvId = EgtGetFirstGroupInGroup( nLayerId) @@ -83,21 +112,21 @@ function RunViewManager.Exec() local nShellId = EgtGetFirstInGroup( nPathId) while nShellId do local nType = EgtGetInfo( nShellId, KEY_TYPE, 'i') - EgtSetStatus( nShellId, EgtIf( nShellType == 1 or ( nShellType == 2 and nType == 0) or (nShellType == 3 and nType == nInnerNumber), GDB_ST.ON, GDB_ST.OFF)) + EgtSetStatus( nShellId, EgtIf( nShellType == SHELL_VIEW_TYPE.ALL or ( nShellType == SHELL_VIEW_TYPE.OUTER and nType == TYPE.OUTER_SHELL) or (nShellType == SHELL_VIEW_TYPE.INNER and nType == TYPE.INNER_SHELL), GDB_ST.ON, GDB_ST.OFF)) nShellId = EgtGetNext( nShellId) end local nSolidId = EgtGetFirstNameInGroup( nCrvId, SOLID_GRP) local nSurfId = EgtGetFirstInGroup( nSolidId) while nSurfId do local nType = EgtGetInfo( nSurfId, KEY_TYPE, 'i') - EgtSetStatus( nSurfId, EgtIf( nShellType == 1 or ( nShellType == 2 and nType == 0) or (nShellType == 3 and nType == nInnerNumber), GDB_ST.ON, GDB_ST.OFF)) + EgtSetStatus( nSurfId, EgtIf( nShellType == SHELL_VIEW_TYPE.ALL or ( nShellType == SHELL_VIEW_TYPE.OUTER and nType == TYPE.OUTER_SHELL) or (nShellType == SHELL_VIEW_TYPE.INNER and nType == TYPE.INNER_SHELL), GDB_ST.ON, GDB_ST.OFF)) nSurfId = EgtGetNext( nSurfId) end local nToolPathId = EgtGetFirstNameInGroup( nCrvId, TOOLPATH_GRP) nShellId = EgtGetFirstInGroup( nToolPathId) while nShellId do local nType = EgtGetInfo( nShellId, KEY_TYPE, 'i') - EgtSetStatus( nShellId, EgtIf( nType and ( nShellType == 1 or ( nShellType == 2 and nType == 0) or (nShellType == 3 and nType == nInnerNumber)), GDB_ST.ON, GDB_ST.OFF)) + EgtSetStatus( nShellId, EgtIf( nType and ( nShellType == SHELL_VIEW_TYPE.ALL or ( nShellType == SHELL_VIEW_TYPE.OUTER and nType == TYPE.OUTER_SHELL) or (nShellType == SHELL_VIEW_TYPE.INNER and nType == TYPE.INNER_SHELL)), GDB_ST.ON, GDB_ST.OFF)) nShellId = EgtGetNext( nShellId) end nCrvId = EgtGetNext( nCrvId) @@ -109,6 +138,11 @@ function RunViewManager.Exec() nPartId = EgtGetFirstNameInGroup( GDB_ID.ROOT, PART .. nPartIndex) end + -- riporto impostazioni in gruppo apposito + EgtSetInfo( nViewId, KEY_LAYER_VIEW, nVisibilityMode) + EgtSetInfo( nViewId, KEY_SHELL_VIEW, nShellType) + EgtSetInfo( nViewId, KEY_SEL_LAYER, nSelLayerId) + EgtDraw() end