diff --git a/LuaLibs/BeamExec.lua b/LuaLibs/BeamExec.lua index 5a82940..c82bae9 100644 --- a/LuaLibs/BeamExec.lua +++ b/LuaLibs/BeamExec.lua @@ -982,19 +982,20 @@ local function CalculateMachinings( vProc, Part) bAreAllApplyOk, _ = StrategyScript.Make( true, Proc, Part, Proc.ChosenStrategy.Parameters) end end + return MACHININGS end ------------------------------------------------------------------------------------------------------------- -local function PrepareMachiningsForSorting( ) +local function PrepareMachiningsForSorting( Part) local nFeatureInternalIndex = 1 for i = 1, #MACHININGS do local MachiningCurrent = MACHININGS[i].Machining - local ProcIdCurrent = MACHININGS[i].Proc.id + local ProcCurrent = MACHININGS[i].Proc -- conversione campo sStage in nStage, numerico e ordinabile - if not MachiningCurrent.sStage then - MachiningCurrent.sStage = '' + if not MachiningCurrent.sStage or MachiningCurrent.sStage == '' then + MachiningCurrent.sStage = 'Middle' end if MachiningCurrent.sStage == 'Head' then MachiningCurrent.nStage = 1 @@ -1008,8 +1009,8 @@ local function PrepareMachiningsForSorting( ) if i > 1 then local MachiningPrevious = MACHININGS[i - 1].Machining - local ProcIdPrevious = MACHININGS[i - 1].Proc.id - if ProcIdCurrent == ProcIdPrevious then + local ProcPrevious = MACHININGS[i - 1].Proc + if ProcCurrent.id == ProcPrevious.id then -- nStage devono essere sempre crescenti nella stessa feature if MachiningCurrent.nStage < MachiningPrevious.nStage then MachiningCurrent.nStage = MachiningPrevious.nStage @@ -1024,16 +1025,35 @@ local function PrepareMachiningsForSorting( ) -- se fase di lavoro standard, assegnazione dello spezzone if MachiningCurrent.nStage == 2 then - + if not MachiningCurrent.ptCenter then + MachiningCurrent.ptCenter = Point3d( ProcCurrent.b3Box:getCenter():getX(), 0, 0) + end + local nParts = #Part.SplittingPoints + 1 + local dPartMinX = Part.b3Part:getMin():getX() + local dPartMaxX = Part.b3Part:getMax():getX() + for j = 1, nParts do + local dNextSplitX = dPartMinX + local dPreviousSplitX = dPartMaxX + if j ~= 1 then + dPreviousSplitX = Part.SplittingPoints[j - 1]:getX() + elseif j ~= nParts then + dNextSplitX = Part.SplittingPoints[j]:getX() + end + if MachiningCurrent.ptCenter:getX() > dNextSplitX - 10 * GEO.EPS_SMALL and MachiningCurrent.ptCenter:getX() < dPreviousSplitX + 10 * GEO.EPS_SMALL then + MachiningCurrent.nPartSegment = j + end + end end end + + return MACHININGS end ------------------------------------------------------------------------------------------------------------- local function SortMachiningsBySegment( MachiningA, MachiningB) - if MachiningA.Machining.nSegment > MachiningB.Machining.nSegment then + if MachiningA.Machining.nFeatureSegment > MachiningB.Machining.nFeatureSegment then return false - elseif MachiningB.Machining.nSegment > MachiningA.Machining.nSegment then + elseif MachiningB.Machining.nFeatureSegment > MachiningA.Machining.nFeatureSegment then return true end @@ -1402,6 +1422,7 @@ function BeamExec.ProcessMachinings( PROCESSINGS, PARTS) MACHININGS = CalculateMachinings( vProc, PARTS[nPart]) -- TODO riordinare lavorazioni ottimizzando cambio utensile/spezzone ecc..., mantenendo dipendenze definite prima + MACHININGS = PrepareMachiningsForSorting( PARTS[nPart]) --table.sort( MACHININGS, SortMachinings) -- MACHININGS = OrderMachining( MACHININGS, PARTS[nPart]) diff --git a/LuaLibs/FaceData.lua b/LuaLibs/FaceData.lua index bf5f5eb..25a5aee 100644 --- a/LuaLibs/FaceData.lua +++ b/LuaLibs/FaceData.lua @@ -265,7 +265,7 @@ local function GetBottomFaces( Proc) CurrentEdge.idAdjacentFace = BottomFaces[1].Edges[i].Adj CurrentEdge.vtToolDirection = Vector3d( BottomFaces[1].Edges[i].Norm) CurrentEdge.dLength = BottomFaces[1].Edges[i].Len - CurrentEdge.dLengthOnX = CurrentEdge.dLength * CurrentEdge.vtToolDirection:getY() + CurrentEdge.dLengthOnX = abs( CurrentEdge.dLength * CurrentEdge.vtToolDirection:getY()) CurrentEdge.dElevation = BottomFaces[1].Edges[i].Elev CurrentEdge.bIsOpen = BottomFaces[1].Edges[i].Open CurrentEdge.bIsStartOpen = BottomFaces[1].Edges[nPreviousEdgeIndex].Open @@ -351,7 +351,7 @@ local function GetLongFaces( Proc, MainFaces) CurrentEdge.idAdjacentFace = LongFaces[i].Edges[j].Adj CurrentEdge.vtToolDirection = Vector3d( LongFaces[i].Edges[j].Norm) CurrentEdge.dLength = LongFaces[i].Edges[j].Len - CurrentEdge.dLengthOnX = CurrentEdge.dLength * CurrentEdge.vtToolDirection:getY() + CurrentEdge.dLengthOnX = abs( CurrentEdge.dLength * CurrentEdge.vtToolDirection:getY()) CurrentEdge.dElevation = LongFaces[i].Edges[j].Elev CurrentEdge.bIsOpen = LongFaces[i].Edges[j].Open CurrentEdge.bIsStartOpen = LongFaces[i].Edges[nPreviousEdgeIndex].Open @@ -438,7 +438,7 @@ local function GetSideFaces( Proc, MainFaces) CurrentEdge.idAdjacentFace = SideFaces[i].Edges[j].Adj CurrentEdge.vtToolDirection = Vector3d( SideFaces[i].Edges[j].Norm) CurrentEdge.dLength = SideFaces[i].Edges[j].Len - CurrentEdge.dLengthOnX = CurrentEdge.dLength * CurrentEdge.vtToolDirection:getY() + CurrentEdge.dLengthOnX = abs( CurrentEdge.dLength * CurrentEdge.vtToolDirection:getY()) CurrentEdge.dElevation = SideFaces[i].Edges[j].Elev CurrentEdge.bIsOpen = SideFaces[i].Edges[j].Open CurrentEdge.bIsStartOpen = SideFaces[i].Edges[nPreviousEdgeIndex].Open diff --git a/LuaLibs/MachiningLib.lua b/LuaLibs/MachiningLib.lua index 2af5bfa..0cfa359 100644 --- a/LuaLibs/MachiningLib.lua +++ b/LuaLibs/MachiningLib.lua @@ -105,9 +105,9 @@ function MachiningLib.GetMachiningSteps( dMachiningDepth, dStep) end ------------------------------------------------------------------------------------------------------------- -function MachiningLib.GetSplitMachinings( Machinings, vSplittingPoints, Part ) +function MachiningLib.GetSplitMachinings( Machinings, SplittingPoints, Part ) for i = #Machinings, 1, -1 do - local nParts = #vSplittingPoints + 1 + local nParts = #SplittingPoints + 1 local dEdgeMaxX = Machinings[i].ptEdge1:getX() local dEdgeMinX = Machinings[i].ptEdge2:getX() if Machinings[i].ptEdge1:getX() < Machinings[i].ptEdge2:getX() - 10 * GEO.EPS_SMALL then @@ -122,10 +122,10 @@ function MachiningLib.GetSplitMachinings( Machinings, vSplittingPoints, Part ) for j = 1, nParts do -- check ultimo segmento della lavorazione (NON della feature) local bIsLastSegment = ( nParts == 1) - or ( ( ( j ~= 1) and vSplittingPoints[j - 1]:getX() > dEdgeMinX + 10 * GEO.EPS_SMALL) - and ( j == nParts or vSplittingPoints[j]:getX() < dEdgeMinX + 10 * GEO.EPS_SMALL)) + or ( ( ( j ~= 1) and SplittingPoints[j - 1]:getX() > dEdgeMinX + 10 * GEO.EPS_SMALL) + and ( j == nParts or SplittingPoints[j]:getX() < dEdgeMinX + 10 * GEO.EPS_SMALL)) -- se non è l'ultimo segmento della lavorazione, il punto di spezzatura deve essere all'interno del lato che si sta lavorando - if ( j ~= nParts and ( vSplittingPoints[j]:getX() > dEdgeMinX + 10 * GEO.EPS_SMALL and vSplittingPoints[j]:getX() < dEdgeMaxX - 10 * GEO.EPS_SMALL)) + if ( j ~= nParts and ( SplittingPoints[j]:getX() > dEdgeMinX + 10 * GEO.EPS_SMALL and SplittingPoints[j]:getX() < dEdgeMaxX - 10 * GEO.EPS_SMALL)) or bIsLastSegment then if j > 1 then nCurrentMachiningIndex = nCurrentMachiningIndex + 1 @@ -137,12 +137,15 @@ function MachiningLib.GetSplitMachinings( Machinings, vSplittingPoints, Part ) dStartAddLength, dEndAddLength = dEndAddLength, dStartAddLength end if j == 1 then - dEndAddLength = - ( vSplittingPoints[j]:getX() - dEdgeMinX) + BeamData.MILL_OVERLAP + dEndAddLength = - ( SplittingPoints[j]:getX() - dEdgeMinX) + BeamData.MILL_OVERLAP + Machinings[nCurrentMachiningIndex].ptCenter = Point3d( SplittingPoints[j]:getX() + ( dEdgeMaxX - SplittingPoints[j]:getX()) / 2, 0, 0) elseif j == nParts then - dStartAddLength = - ( dEdgeMaxX - vSplittingPoints[j - 1]:getX()) + BeamData.MILL_OVERLAP + dStartAddLength = - ( dEdgeMaxX - SplittingPoints[j - 1]:getX()) + BeamData.MILL_OVERLAP + Machinings[nCurrentMachiningIndex].ptCenter = Point3d( dEdgeMinX + ( SplittingPoints[j - 1]:getX() - dEdgeMinX) / 2, 0, 0) else - dStartAddLength = - ( dEdgeMaxX - vSplittingPoints[j - 1]:getX()) + BeamData.MILL_OVERLAP - dEndAddLength = - ( vSplittingPoints[j]:getX() - dEdgeMinX) + BeamData.MILL_OVERLAP + dStartAddLength = - ( dEdgeMaxX - SplittingPoints[j - 1]:getX()) + BeamData.MILL_OVERLAP + dEndAddLength = - ( SplittingPoints[j]:getX() - dEdgeMinX) + BeamData.MILL_OVERLAP + Machinings[nCurrentMachiningIndex].ptCenter = Point3d( SplittingPoints[j]:getX() + ( SplittingPoints[j - 1]:getX() - SplittingPoints[j]:getX()) / 2, 0, 0) end if MachiningLib.StartsLeftSide( Machinings[nCurrentMachiningIndex]) then dStartAddLength, dEndAddLength = dEndAddLength, dStartAddLength @@ -154,7 +157,7 @@ function MachiningLib.GetSplitMachinings( Machinings, vSplittingPoints, Part ) if not bIsLastSegment then Machinings[nCurrentMachiningIndex].sStage = '' end - Machinings[nCurrentMachiningIndex].nSegment = j + Machinings[nCurrentMachiningIndex].nFeatureSegment = j end -- anche le lavorazioni non splittate necessitano del segmento assegnato else @@ -167,12 +170,13 @@ function MachiningLib.GetSplitMachinings( Machinings, vSplittingPoints, Part ) local dNextSplitX = dEdgeMinX local dPreviousSplitX = dEdgeMaxX if j ~= 1 then - dPreviousSplitX = vSplittingPoints[j - 1]:getX() + dPreviousSplitX = SplittingPoints[j - 1]:getX() elseif j ~= nParts then - dNextSplitX = vSplittingPoints[j]:getX() + dNextSplitX = SplittingPoints[j]:getX() end if ( dEdgeMinX - dLeftAddLength) > dNextSplitX - 10 * GEO.EPS_SMALL and ( dEdgeMaxX + dRightAddLength) < dPreviousSplitX + 10 * GEO.EPS_SMALL then - Machinings[i].nSegment = j + Machinings[i].nFeatureSegment = j + Machinings[i].ptCenter = Point3d( dNextSplitX + ( dPreviousSplitX - dNextSplitX) / 2, 0, 0) end end end diff --git a/Strategies/Core/SLOTBYBLADE.lua b/Strategies/Core/SLOTBYBLADE.lua index 9808817..e0763b6 100644 --- a/Strategies/Core/SLOTBYBLADE.lua +++ b/Strategies/Core/SLOTBYBLADE.lua @@ -93,7 +93,7 @@ function SLOTBYBLADE.Make( Proc, Part, FaceToMachine, EdgeToMachine, OptionalPar Cutting.dResidualDepth = abs( EdgeToMachine.dElevation) Cutting.dBladeMarkLength = 0 Cutting.sEdgeType = EdgeToMachine.sType - Cutting. nSegment = 1 + Cutting.nFeatureSegment = 1 -- parametri opzionali if not OptionalParameters then @@ -248,7 +248,7 @@ function SLOTBYBLADE.Make( Proc, Part, FaceToMachine, EdgeToMachine, OptionalPar -- se lavorazione aperta sulla coda, eventuali aggiustamenti -- TODO valutare se fare funzione a parte - if Proc.AffectedFaces.bLeft then + if Proc.AffectedFaces.bLeft and ( EdgeToMachine.sType == 'Bottom' or ( EdgeToMachine.vtToolDirection:getX() < 10 * GEO.EPS_SMALL)) then local bStartLeft = MachiningLib.StartsLeftSide( Cutting) local dAddLengthLeftSide = Cutting.LeadOut.dEndAddLength local dAddLengthToReduce = sqrt( Cutting.dDepthToMachine * TOOLS[Cutting.nToolIndex].dDiameter - Cutting.dDepthToMachine * Cutting.dDepthToMachine) diff --git a/Strategies/Core/SLOTBYCHAINSAW.lua b/Strategies/Core/SLOTBYCHAINSAW.lua index 019a94b..692bc97 100644 --- a/Strategies/Core/SLOTBYCHAINSAW.lua +++ b/Strategies/Core/SLOTBYCHAINSAW.lua @@ -56,7 +56,7 @@ function SLOTBYCHAINSAW.Make( Proc, Part, FaceToMachine, EdgeToMachine, Optional Mortising.sMessage = '' Mortising.idProc = Proc.id Mortising.sEdgeType = EdgeToMachine.sType - Mortising.nSegment = 1 + Mortising.nFeatureSegment = 1 -- parametri opzionali if not OptionalParameters then @@ -224,7 +224,7 @@ function SLOTBYCHAINSAW.Make( Proc, Part, FaceToMachine, EdgeToMachine, Optional -- se lavorazione aperta sulla coda, eventuali aggiustamenti -- TODO valutare se fare funzione a parte - if Proc.AffectedFaces.bLeft then + if Proc.AffectedFaces.bLeft and ( EdgeToMachine.sType == 'Bottom' or ( EdgeToMachine.vtToolDirection:getX() < 10 * GEO.EPS_SMALL)) then local bStartLeft = MachiningLib.StartsLeftSide( Mortising) local dAddLengthLeftSide = Mortising.LeadOut.dEndAddLength if bStartLeft then diff --git a/Strategies/Standard/STR0003/STR0003.lua b/Strategies/Standard/STR0003/STR0003.lua index c7d453b..a2fbba9 100644 --- a/Strategies/Standard/STR0003/STR0003.lua +++ b/Strategies/Standard/STR0003/STR0003.lua @@ -62,9 +62,9 @@ end -- TODO si può unificare con eguale funzione in STR0004 local function SortMachiningsBySegment( MachiningA, MachiningB) - if MachiningA.nSegment > MachiningB.nSegment then + if MachiningA.nFeatureSegment > MachiningB.nFeatureSegment then return false - elseif MachiningB.nSegment > MachiningA.nSegment then + elseif MachiningB.nFeatureSegment > MachiningA.nFeatureSegment then return true else if TOOLS[ MachiningA.nToolIndex].sFamily == 'SAWBLADE' and TOOLS[ MachiningB.nToolIndex].sFamily == 'MORTISE' then @@ -88,9 +88,9 @@ local function SortMachiningsByTool( MachiningA, MachiningB) elseif TOOLS[ MachiningA.nToolIndex].sFamily == 'MORTISE' and TOOLS[ MachiningB.nToolIndex].sFamily == 'SAWBLADE' then return false else - if MachiningA.nSegment > MachiningB.nSegment then + if MachiningA.nFeatureSegment > MachiningB.nFeatureSegment then return false - elseif MachiningB.nSegment > MachiningA.nSegment then + elseif MachiningB.nFeatureSegment > MachiningA.nFeatureSegment then return true else if MachiningA.sEdgeType == 'Side' and MachiningB.sEdgeType ~= 'Side' then diff --git a/Strategies/Standard/STR0004/STR0004.lua b/Strategies/Standard/STR0004/STR0004.lua index e41fb5d..7ddb078 100644 --- a/Strategies/Standard/STR0004/STR0004.lua +++ b/Strategies/Standard/STR0004/STR0004.lua @@ -58,9 +58,9 @@ end local function SortMachiningsBySegment( MachiningA, MachiningB) - if MachiningA.nSegment > MachiningB.nSegment then + if MachiningA.nFeatureSegment > MachiningB.nFeatureSegment then return false - elseif MachiningB.nSegment > MachiningA.nSegment then + elseif MachiningB.nFeatureSegment > MachiningA.nFeatureSegment then return true else if MachiningA.sEdgeType == 'Side' and MachiningB.sEdgeType ~= 'Side' then