diff --git a/.vscode/settings.json b/.vscode/settings.json index 975b78b..40b196b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -150,6 +150,10 @@ "EgtExplodeCurveCompo", "EgtCurveCompo", "EgtAddCurveCompoCurve", - "AreSameColor" + "AreSameColor", + "EgtPointCurveDistSide", + "X_AX", + "max", + "EgtSurfFrRectangle" ] } \ No newline at end of file diff --git a/Config.lua b/Config.lua index d045c89..e858e64 100644 --- a/Config.lua +++ b/Config.lua @@ -151,7 +151,7 @@ Config.TabParams = {{MatId = 1, MatExtCode = 6120, Length = 10.0, Height = Config.Kerf = {{MatId = 1, MatExtCode = 6120, Kerf = 8}, {MatId = 2, MatExtCode = 6110, Kerf = 20}, {MatId = 3, MatExtCode = 6049, Kerf = 20}, - {MatId = 4, MatExtCode = 6118, Kerf = 20}, + {MatId = 4, MatExtCode = 6118, Kerf = 10}, {MatId = 5, MatExtCode = 6479, Kerf = 20}, {MatId = 6, MatExtCode = 6408, Kerf = 20}, {MatId = 7, MatExtCode = 6406, Kerf = 20}, diff --git a/Main.lua b/Main.lua index bcd2e96..a85f761 100644 --- a/Main.lua +++ b/Main.lua @@ -400,7 +400,9 @@ function Nesting(readBatch) EgtOutText("End sheets nest") -- se debug - if DebugCode then + --if DebugCode then + -- verifico se ci sono tutti i pezzi dopo il nesting perche' i pezzi grandi quasi come il foglio potrebbero non essere nestati + if Config.bDoubleMach then -- verifico di aver messo tutti i part su un grezzo local PartList = {} -- raccolgo tutti i part dai materiali in una lista @@ -948,8 +950,48 @@ function Estimate(readBatch) end end - EgtOutText("End sheets estimate") + -- verifico se ci sono tutti i pezzi dopo il nesting perche' i pezzi grandi quasi come il foglio potrebbero non essere nestati + if Config.bDoubleMach then + -- verifico di aver messo tutti i part su un grezzo + local PartList = {} + -- raccolgo tutti i part dai materiali in una lista + for MaterialIndex = 1, #materials do + if materials[MaterialIndex].SheetList then + for SheetIndex = 1, #materials[MaterialIndex].SheetList do + for PartIndex = 1, #materials[MaterialIndex].SheetList[SheetIndex].PartList do + table.insert(PartList, tonumber(materials[MaterialIndex].SheetList[SheetIndex].PartList[PartIndex].PartId)) + end + end + end + end + -- passo i part del readbatch + for OrderIndex = CurrOrderIndex, CurrOrderCount do + for KitIndex = 1, #readBatch.OrderList[OrderIndex].KitList do + for BPartIndex = 1, #readBatch.OrderList[OrderIndex].KitList[KitIndex].PartList do + local bFound = false + for VPartIndex = #PartList, 1, -1 do + if readBatch.OrderList[OrderIndex].KitList[KitIndex].PartList[BPartIndex].PartId == PartList[VPartIndex] then + if not bFound then + bFound = true + table.remove(PartList, VPartIndex) + else + table.insert(ErrorList, {ErrType = "E.12", Uid = "PartId = " .. readBatch.OrderList[OrderIndex].KitList[KitIndex].PartList[BPartIndex].PartId, Description = "Part duplicated after nesting!"}) + end + end + end + if not bFound then + table.insert(ErrorList, {ErrType = "E.12", Uid = "PartId = " .. readBatch.OrderList[OrderIndex].KitList[KitIndex].PartList[BPartIndex].PartId, Description = "Part lost after nesting!"}) + end + end + end + end + -- verifico se sono rimasti elementi nella tabella kit + if #PartList > 0 then + table.insert(ErrorList, {ErrType = "E.12", Uid = "PartId = " .. PartList[1], Description = #PartList .. " part more than in batch request after nesting!"}) + end + end + EgtOutText("End sheets estimate") -- creo batch di risposta local answ = {} @@ -1069,6 +1111,47 @@ function ExtendedEstimate(readBatch) table.insert(answ.EstOrderList, readBatch.OrderList[Order]) end +-- -- verifico se ci sono tutti i pezzi dopo il nesting perche' i pezzi grandi quasi come il foglio potrebbero non essere nestati +-- if true then +-- -- verifico di aver messo tutti i part su un grezzo +-- local PartList = {} +-- -- raccolgo tutti i part dai materiali in una lista +-- for MaterialIndex = 1, #materials do +-- if materials[MaterialIndex].SheetList then +-- for SheetIndex = 1, #materials[MaterialIndex].SheetList do +-- for PartIndex = 1, #materials[MaterialIndex].SheetList[SheetIndex].PartList do +-- table.insert(PartList, tonumber(materials[MaterialIndex].SheetList[SheetIndex].PartList[PartIndex].PartId)) +-- end +-- end +-- end +-- end +-- -- passo i part del readbatch +-- for OrderIndex = 1, #readBatch.OrderList do +-- for KitIndex = 1, #readBatch.OrderList[OrderIndex].KitList do +-- for BPartIndex = 1, #readBatch.OrderList[OrderIndex].KitList[KitIndex].PartList do +-- local bFound = false +-- for VPartIndex = #PartList, 1, -1 do +-- if readBatch.OrderList[OrderIndex].KitList[KitIndex].PartList[BPartIndex].PartId == PartList[VPartIndex] then +-- if not bFound then +-- bFound = true +-- table.remove(PartList, VPartIndex) +-- else +-- table.insert(ErrorList, {ErrType = "E.12", Uid = "PartId = " .. readBatch.OrderList[OrderIndex].KitList[KitIndex].PartList[BPartIndex].PartId, Description = "Part duplicated after nesting!"}) +-- end +-- end +-- end +-- if not bFound then +-- table.insert(ErrorList, {ErrType = "E.12", Uid = "PartId = " .. readBatch.OrderList[OrderIndex].KitList[KitIndex].PartList[BPartIndex].PartId, Description = "Part lost after nesting!"}) +-- end +-- end +-- end +-- end +-- -- verifico se sono rimasti elementi nella tabella kit +-- if #PartList > 0 then +-- table.insert(ErrorList, {ErrType = "E.12", Uid = "PartId = " .. PartList[1], Description = #PartList .. " part more than in batch request after nesting!"}) +-- end +-- end + -- correggo e riporto tempo totale di lavorazione answ.EstimatedWorktime = TotTime diff --git a/NestingLib.lua b/NestingLib.lua index 520b716..46951d1 100644 --- a/NestingLib.lua +++ b/NestingLib.lua @@ -536,13 +536,13 @@ local SKELETONTRACK = "SKELETONTRACK" local SKELETONPART = "SKELETON" local CUTOPT = "CUTOPT" -- funzione legge il dxf ed aggiunge il pezzo al nesting -local function AddPartListToNesting(PartList, ErrorList, Material) +local function AddPartListToNesting(PartList, ErrorList, Material, IsEstimate) local BigPartsQty = 0 local LastId = GDB_ID.ROOT for Part = 1, #PartList do - if PartList[Part].PartExtCode == '128057' then - local f = 3 - end + --if PartList[Part].PartExtCode == '14162182' or PartList[Part].PartExtCode == '14162184' then + -- x = 5 + --end -- tipo di rotazione del pezzo consentita : 0 -> rotazione libera, 1 -> rotazione solo di 180°, 2 -> nessuna rotazione local RotationType = 0 -- verifico se gia' presente per importazione precedente @@ -581,6 +581,7 @@ local function AddPartListToNesting(PartList, ErrorList, Material) local LayerId = EgtGetFirstLayer(PartId1) local nMaxId = GDB_ID.NULL local bFound = false + local bBigPart = false while LayerId do local layerName = EgtGetName(LayerId) local bOutline = false @@ -715,8 +716,48 @@ local function AddPartListToNesting(PartList, ErrorList, Material) end EgtSetName(nMaxId, OUTLINE) -- verifico se e' grande quasi come il foglio - if OutlineBox:getDimX() > Material.L_mm - 51 or OutlineBox:getDimY() > Material.W_mm - 26 then - BigPartsQty = BigPartsQty + 1 + local dTempX = OutlineBox:getDimX() + local dTempY = OutlineBox:getDimY() + local bRotated = false + if dTempY > dTempX then + bRotated = true + dTempX = OutlineBox:getDimY() + dTempY = OutlineBox:getDimX() + end + -- ricavo Kerf del materiale + local dKerf = 9 + for Index = 1, #Config.Kerf do + if Config.Kerf[Index].MatId == Material.MatId then + dKerf = Config.Kerf[Index].Kerf + end + end + if dTempX > Material.L_mm - max( 51, dKerf) - dKerf and dTempY > Material.W_mm - max( 26, dKerf) - dKerf then + -- verifico se occupa l'angolo + local nInside1 = 0 + local nInside2 = 0 + if not bRotated then + local LabelRegId = EgtSurfFrRectangle( EgtGetParent( nMaxId), OutlineBox:getMin() + ( OutlineBox:getDimY() - 26) * Y_AX() - 10 * X_AX(), OutlineBox:getMin() + ( OutlineBox:getDimY() + 10) * Y_AX() + 51 * X_AX(), GDB_RT.GLOB) + nInside1 = EgtCurveWithRegionClassify( nMaxId, LabelRegId) + EgtErase( LabelRegId) + LabelRegId = EgtSurfFrRectangle( EgtGetParent( nMaxId), OutlineBox:getMax() - ( OutlineBox:getDimY() - 10) * Y_AX() - 51 * X_AX(), OutlineBox:getMax() + 10 * X_AX() - ( OutlineBox:getDimY() - 26) * Y_AX(), GDB_RT.GLOB) + nInside2 = EgtCurveWithRegionClassify( nMaxId, LabelRegId) + EgtErase( LabelRegId) + --_, _, nInside1 = EgtPointCurveDistSide( OutlineBox:getMin() + ( OutlineBox:getDimY() - 26) * Y_AX() + 51 * X_AX(), nMaxId, Z_AX()) + --_, _, nInside2 = EgtPointCurveDistSide( OutlineBox:getMax() - ( OutlineBox:getDimY() - 26) * Y_AX() - 51 * X_AX(), nMaxId, Z_AX()) + else + local LabelRegId = EgtSurfFrRectangle( EgtGetParent( nMaxId), OutlineBox:getMin() - 10 * X_AX() - 10 * Y_AX(), OutlineBox:getMin() + 51 * Y_AX() + 26 * X_AX(), GDB_RT.GLOB) + nInside1 = EgtCurveWithRegionClassify( nMaxId, LabelRegId) + EgtErase( LabelRegId) + LabelRegId = EgtSurfFrRectangle( EgtGetParent( nMaxId), OutlineBox:getMax() - 51 * Y_AX() - 26 * X_AX(), OutlineBox:getMax() + 10 * X_AX() + 10 * Y_AX(), GDB_RT.GLOB) + nInside2 = EgtCurveWithRegionClassify( nMaxId, LabelRegId) + EgtErase( LabelRegId) + --_, _, nInside1 = EgtPointCurveDistSide( OutlineBox:getMin() + 51 * Y_AX() + 26 * X_AX(), nMaxId, Z_AX()) + --_, _, nInside2 = EgtPointCurveDistSide( OutlineBox:getMax() - 51 * Y_AX() - 26 * X_AX(), nMaxId, Z_AX()) + end + if nInside1 ~= GDB_CRC.OUT and nInside2 ~= GDB_CRC.OUT then + bBigPart = true + BigPartsQty = BigPartsQty + 1 + end end -- copio outline in un layer dedicato local OutlineLayer = EgtGroup(PartId1) @@ -870,7 +911,9 @@ local function AddPartListToNesting(PartList, ErrorList, Material) end -- preparo pezzo per il nesting local Priority = 0 - if PartList[Part].Priority then + if bBigPart and not IsEstimate then + Priority = 1 + elseif PartList[Part].Priority then Priority = PartList[Part].Priority end local bCanRotate, dRotStep = true, 0 @@ -1061,7 +1104,7 @@ function NestingLib.NestPartInRawPart(LastRaw, PartList, Material, ErrorList, Is -- aggiungo tutti i pezzi al nesting local BigPartsQty = 0 - BigPartsQty = AddPartListToNesting(PartList, ErrorList, Material) or 0 + BigPartsQty = AddPartListToNesting(PartList, ErrorList, Material, IsEstimate) or 0 -- ripristino MachGroup EgtSetCurrMachGroup(nOldMachGroup) @@ -1082,20 +1125,7 @@ function NestingLib.NestPartInRawPart(LastRaw, PartList, Material, ErrorList, Is dKerf = Config.Kerf[Index].Kerf end end - - -- se ci sono pezzi grandi --- if BigPartsQty > 0 then --- -- creo un ugual numero di fogli senza etichetta --- local BigSheetPartId = EgtGroup(GDB_ID.ROOT) --- EgtSetName(BigSheetPartId, "Sheet") --- local BigSheetLayerId = EgtGroup(BigSheetPartId) --- EgtSetName(BigSheetLayerId, OUTLINE) --- local BigSheetOutlineId = EgtRectangle2P(BigSheetLayerId, Point3d(0,0,0), Point3d(Material.L_mm, Material.W_mm, 0), GDB_RT.GLOB) --- EgtModifyCurveThickness(BigSheetOutlineId, -Material.T_mm) --- EgtSetName(BigSheetOutlineId, OUTLINE) --- EgtAutoNestAddSheet( BigSheetPartId, BigSheetOutlineId, dKerf, 0, BigPartsQty) -- EgtAutoNestAddSheet( SheetId, OutlineId, dKerf, nPriority, nCount) --- end - + -- verifico se ultimo grezzo non nullo local LastMachGroupId = nil if LastRaw and LastRaw ~= GDB_ID.NULL then @@ -1127,6 +1157,18 @@ function NestingLib.NestPartInRawPart(LastRaw, PartList, Material, ErrorList, Is else -- se ci sono pezzi grandi if BigPartsQty > 0 then + -- creo un ugual numero di fogli senza etichetta + local BigSheetPartId = EgtGroup(GDB_ID.ROOT) + EgtSetName(BigSheetPartId, "Sheet") + local BigSheetLayerId = EgtGroup(BigSheetPartId) + EgtSetName(BigSheetLayerId, OUTLINE) + local BigSheetOutlineId = EgtRectangle2P(BigSheetLayerId, Point3d(0,0,0), Point3d(Material.L_mm, Material.W_mm, 0), GDB_RT.GLOB) + EgtModifyCurveThickness(BigSheetOutlineId, -Material.T_mm) + EgtSetName(BigSheetOutlineId, OUTLINE) + EgtAutoNestAddSheet( BigSheetPartId, BigSheetOutlineId, dKerf, 0, BigPartsQty) -- EgtAutoNestAddSheet( SheetId, OutlineId, dKerf, nPriority, nCount) + end + -- se ci sono pezzi grandi + -- if BigPartsQty > 0 then -- -- creo un ugual numero di fogli senza etichetta -- local BigSheetPartId = EgtGroup(GDB_ID.ROOT) -- EgtSetName(BigSheetPartId, "Sheet") @@ -1135,8 +1177,8 @@ function NestingLib.NestPartInRawPart(LastRaw, PartList, Material, ErrorList, Is -- local BigSheetOutlineId = EgtRectangle2P(BigSheetLayerId, Point3d(0,0,0), Point3d(Material.L_mm, Material.W_mm, 0), GDB_RT.GLOB) -- EgtModifyCurveThickness(BigSheetOutlineId, -Material.T_mm) -- EgtSetName(BigSheetOutlineId, OUTLINE) - EgtAutoNestAddSheet( SheetPartId, SheetOutlineId, dKerf, 0, BigPartsQty) -- EgtAutoNestAddSheet( SheetId, OutlineId, dKerf, nPriority, nCount) - end + -- EgtAutoNestAddSheet( SheetPartId, SheetOutlineId, dKerf, 0, BigPartsQty) -- EgtAutoNestAddSheet( SheetId, OutlineId, dKerf, nPriority, nCount) + -- end -- creo etichetta dello sheet local dLabelW = 50 local dLabelH = 25 @@ -1147,7 +1189,7 @@ function NestingLib.NestPartInRawPart(LastRaw, PartList, Material, ErrorList, Is local nSheetLabel = EgtRectangle2P(SheetLayerId, Point3d(0, dYPos - dLabelH,0), Point3d(dLabelW, dYPos, 0), GDB_RT.GLOB) EgtSetName(nSheetLabel, SHEETLABEL) -- creo foglio per nesting - EgtAutoNestAddSheet( SheetPartId, SheetOutlineId, dKerf, 0, 50) -- EgtAutoNestAddSheet( SheetId, OutlineId, dKerf, nPriority, nCount) + EgtAutoNestAddSheet( SheetPartId, SheetOutlineId, dKerf, 0, 1000) -- EgtAutoNestAddSheet( SheetId, OutlineId, dKerf, nPriority, nCount) -- aggiungo etichetta come difetto EgtAutoNestAddDefectToSheet(SheetPartId, nSheetLabel) -- EgtAutoNestAddDefectToSheet( SheetId, DefectId) end