Skip to content

mfill_mode speedup + simplicity - return once correct mode found #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 35 additions & 66 deletions GradientInfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@
class Infill(Enum):
"""Enum for infill type."""

NOT_SUPPORTED = 0 # currently unsupported infill mode
SMALL_SEGMENTS = 1 # infill with small segments like gyroid
LINEAR = 2 # linear infill like rectilinear or triangles
LINEAR = 2 # linear infill like rectilinear or triangles

class Section(Enum):
"""Enum for section type."""
Expand Down Expand Up @@ -239,36 +240,13 @@ def mfill_mode(Mode):
Returns:
Int: the Type of infill pattern
"""
iMode=0
if Mode == 'grid':
iMode=2
if Mode == 'lines':
iMode=2
if Mode == 'triangles':
iMode=2
if Mode == 'trihexagon':
iMode=2
if Mode == 'cubic':
iMode=2
if Mode == 'cubicsubdiv':
iMode=0
if Mode == 'tetrahedral':
iMode=2
if Mode == 'quarter_cubic':
iMode=2
if Mode == 'concentric':
iMode=0
if Mode == 'zigzag':
iMode=0
if Mode == 'cross':
iMode=1
if Mode == 'cross_3d':
iMode=1
if Mode == 'gyroid':
iMode=1

return iMode

if Mode in ['grid', 'lines', 'triangles', 'trihexagon', 'cubic', 'tetrahedral', 'quarter_cubic']:
return Infill.LINEAR
if Mode in ['cross', 'cross_3d', 'gyroid']:
return Infill.SMALL_SEGMENTS
if Mode in ['cubicsubdiv', 'concentric', 'zigzag']:
return Infill.NOT_SUPPORTED

class GradientInfill(Script):
def getSettingDataString(self):
return """{
Expand Down Expand Up @@ -393,10 +371,8 @@ def execute(self, data):
min_over_speed_factor = min_over_speed_factor /100

test_outer_wall= bool(self.getSettingValueByKey("testouterwall"))





# machine_extruder_count
extruder_count=Application.getInstance().getGlobalContainerStack().getProperty("machine_extruder_count", "value")
extruder_count = extruder_count-1
Expand All @@ -406,10 +382,10 @@ def execute(self, data):
# Deprecation function
# extrud = list(Application.getInstance().getGlobalContainerStack().extruders.values())
extrud = Application.getInstance().getGlobalContainerStack().extruderList

infillpattern = extrud[extruder_id].getProperty("infill_pattern", "value")
connectinfill = extrud[extruder_id].getProperty("zig_zaggify_infill", "value")

relativeextrusion = extrud[extruder_id].getProperty("relative_extrusion", "value")
link = extrud[extruder_id].getProperty("relative_extrusion", "value")
if relativeextrusion == False:
Expand All @@ -425,14 +401,14 @@ def execute(self, data):
Logger.log('d', 'Gcode must be generate with the mode infill_before_walls to off')
Message('It is important to make sure that the Walls are printed before the Infill (Infill before Walls must be set to OFF)', title = catalog.i18nc("@info:title", "Post Processing")).show()
return None

"""Parse Gcode and modify infill portions with an extrusion width gradient."""
currentSection = Section.NOTHING
lastPosition = Point2D(-10000, -10000)
gradientDiscretizationLength = gradient_thickness / gradient_discretization

infill_type=mfill_mode(infillpattern)
if infill_type == 0:
infill_type = mfill_mode(infillpattern)
if infill_type == Infill.NOT_SUPPORTED:
#
Logger.log('d', 'Infill Pattern not supported : ' + infillpattern)
Message('Infill Pattern not supported : ' + infillpattern , title = catalog.i18nc("@info:title", "Post Processing")).show()
Expand All @@ -455,25 +431,21 @@ def execute(self, data):
new_Line=""
stringFeed = ""
line_index = lines.index(currentLine)

if is_begin_layer_line(currentLine):
perimeterSegments = []

if is_begin_inner_wall_line(currentLine):
currentSection = Section.INNER_WALL
# Logger.log('d', 'is_begin_inner_wall_line' )

if is_begin_outer_wall_line(currentLine):
elif is_begin_outer_wall_line(currentLine):
currentSection = Section.OUTER_WALL
# Logger.log('d', 'is_begin_outer_wall_line' )

if currentSection == Section.INNER_WALL and test_outer_wall == False:
if is_extrusion_line(currentLine):
perimeterSegments.append(Segment(getXY(currentLine), lastPosition))

if currentSection == Section.OUTER_WALL and test_outer_wall == True:
if is_extrusion_line(currentLine):
perimeterSegments.append(Segment(getXY(currentLine), lastPosition))
if ((currentSection == Section.INNER_WALL and not test_outer_wall) or
(currentSection == Section.OUTER_WALL and test_outer_wall)) and \
is_extrusion_line(currentLine):
perimeterSegments.append(Segment(getXY(currentLine), lastPosition))

if is_begin_infill_segment_line(currentLine):
# Log Size of perimeterSegments for debuging
Expand All @@ -485,7 +457,7 @@ def execute(self, data):
if currentSection == Section.INFILL:
if "F" in currentLine and "G1" in currentLine:
searchSpeed = re.search(r"F(\d*\.?\d*)", currentLine)

if searchSpeed:
current_feed=float(searchSpeed.group(1))
new_Line="G1 F{}\n".format(current_feed)
Expand All @@ -495,9 +467,8 @@ def execute(self, data):
if "E" in currentLine and "G1" in currentLine and "X" in currentLine and "Y" in currentLine:
currentPosition = getXY(currentLine)
splitLine = currentLine.split(" ")

# if infill_type == Infill.LINEAR:
if infill_type == 2:

if infill_type == Infill.LINEAR:
# find extrusion length
for element in splitLine:
if "E" in element:
Expand All @@ -507,7 +478,7 @@ def execute(self, data):
segmentSteps = segmentLength / gradientDiscretizationLength
extrusionLengthPerSegment = extrusionLength / segmentSteps
segmentDirection = Point2D((currentPosition.x - lastPosition.x) / segmentLength * gradientDiscretizationLength,(currentPosition.y - lastPosition.y) / segmentLength * gradientDiscretizationLength)

if segmentSteps >= 2:
# new_Line=new_Line+"; GradientInfill segmentSteps >= 2\n"
for step in range(int(segmentSteps)):
Expand All @@ -516,7 +487,7 @@ def execute(self, data):
if shortestDistance < gradient_thickness:
segmentExtrusion = extrusionLengthPerSegment * mapRange((0, gradient_thickness), (max_flow / 100, min_flow / 100), shortestDistance)
segmentFeed = current_feed / mapRange((0, gradient_thickness), (max_flow / 100, min_flow / 100), shortestDistance)

if gradual_speed:
if segmentFeed > (current_feed * max_over_speed_factor):
segmentFeed = current_feed * max_over_speed_factor
Expand All @@ -530,8 +501,7 @@ def execute(self, data):
segmentFeed = current_feed / (min_flow / 100)
else:
segmentFeed = current_feed * max_over_speed_factor



if gradual_speed:
if segmentFeed > (current_feed * max_over_speed_factor):
segmentFeed = current_feed * max_over_speed_factor
Expand All @@ -549,28 +519,27 @@ def execute(self, data):
segmentFeed = current_feed * min_over_speed_factor
if gradual_speed:
stringFeed = " F{}".format(int(segmentFeed))

new_Line=new_Line+get_extrusion_command(currentPosition.x,currentPosition.y,segmentLengthRatio * extrusionLength * max_flow / 100) + stringFeed # + " ; Last line"

lines[line_index] = new_Line

else :
outPutLine = ""
# outPutLine = "; GradientInfill segmentSteps < 2\n"

for element in splitLine:
if "E" in element:
outPutLine = outPutLine + "E" + str(round(extrusionLength * link_flow / 100, 5))
else:
outPutLine = outPutLine + element + " "
outPutLine = outPutLine # + "\n"
lines[line_index] = outPutLine

# writtenToFile = 1

# gyroid or honeycomb
# if infill_type == Infill.SMALL_SEGMENTS:
if infill_type == 1:
if infill_type == Infill.SMALL_SEGMENTS:
shortestDistance = min_distance_from_segment(Segment(lastPosition, currentPosition), perimeterSegments)

outPutLine = new_Line
Expand Down