"""BlenderCAM 'ui.py' © 2012 Vilem Novak
Panels displayed in the 3D Viewport - Curve Tools, Creators and Import G-code
"""
from bpy_extras.io_utils import ImportHelper
from bpy.props import (
BoolProperty,
EnumProperty,
FloatProperty,
StringProperty,
)
from bpy.types import (
Panel,
Operator,
UIList,
PropertyGroup,
)
from .gcodeimportparser import import_gcode
[docs]
class CAM_UL_orientations(UIList):
[docs]
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
if self.layout_type in {'DEFAULT', 'COMPACT'}:
layout.label(text=item.name, translate=False, icon_value=icon)
elif self.layout_type in {'GRID'}:
layout.alignment = 'CENTER'
layout.label(text="", icon_value=icon)
# panel containing all tools
# Gcode import panel---------------------------------------------------------------
# ------------------------------------------------------------------------
# Panel in Object Mode
# ------------------------------------------------------------------------
[docs]
class CustomPanel(Panel):
[docs]
bl_space_type = 'VIEW_3D'
[docs]
bl_region_type = 'TOOLS'
[docs]
bl_context = "objectmode"
[docs]
bl_label = "Import G-code"
[docs]
bl_idname = "OBJECT_PT_importgcode"
[docs]
bl_options = {'DEFAULT_CLOSED'}
@classmethod
[docs]
def poll(cls, context):
return context.mode in {'OBJECT',
'EDIT_MESH'} # with this poll addon is visibly even when no object is selected
[docs]
def draw(self, context):
layout = self.layout
scene = context.scene
isettings = scene.cam_import_gcode
layout.prop(isettings, 'output')
layout.prop(isettings, "split_layers")
layout.prop(isettings, "subdivide")
col = layout.column(align=True)
col = col.row(align=True)
col.split()
col.label(text="Segment Length")
col.prop(isettings, "max_segment_size")
col.enabled = isettings.subdivide
col.separator()
col = layout.column()
col.scale_y = 2.0
col.operator("wm.gcode_import")
[docs]
class WM_OT_gcode_import(Operator, ImportHelper):
"""Import G-code, Travel Lines Don't Get Drawn"""
[docs]
bl_idname = "wm.gcode_import" # important since its how bpy.ops.import_test.some_data is constructed
[docs]
bl_label = "Import G-code"
# ImportHelper mixin class uses this
[docs]
filter_glob: StringProperty(
default="*.*",
options={'HIDDEN'},
maxlen=255, # Max internal buffer length, longer would be clamped.
)
[docs]
def execute(self, context):
print(self.filepath)
return import_gcode(context, self.filepath)
[docs]
class import_settings(PropertyGroup):
[docs]
split_layers: BoolProperty(
name="Split Layers",
description="Save every layer as single Objects in Collection",
default=False,
)
[docs]
subdivide: BoolProperty(
name="Subdivide",
description="Only Subdivide gcode segments that are "
"bigger than 'Segment length' ",
default=False,
)
[docs]
output: EnumProperty(
name="Output Type",
items=(
("mesh", "Mesh", "Make a mesh output"),
("curve", "Curve", "Make curve output"),
),
default="curve",
)
[docs]
max_segment_size: FloatProperty(
name="",
description="Only Segments bigger than this value get subdivided",
default=0.001,
min=0.0001,
max=1.0,
unit="LENGTH",
)