Source code for cam.ui

"""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
[docs] class VIEW3D_PT_tools_curvetools(Panel):
[docs] bl_space_type = 'VIEW_3D'
[docs] bl_region_type = 'TOOLS'
[docs] bl_context = "objectmode"
[docs] bl_label = "Curve CAM Tools"
[docs] def draw(self, context): layout = self.layout layout.operator("object.curve_boolean") layout.operator("object.convex_hull") layout.operator("object.curve_intarsion") layout.operator("object.curve_overcuts") layout.operator("object.curve_overcuts_b") layout.operator("object.silhouete") layout.operator("object.silhouete_offset") layout.operator("object.curve_remove_doubles") layout.operator("object.mesh_get_pockets")
[docs] class VIEW3D_PT_tools_create(Panel):
[docs] bl_space_type = 'VIEW_3D'
[docs] bl_region_type = 'TOOLS'
[docs] bl_context = "objectmode"
[docs] bl_label = "Curve CAM Creators"
[docs] bl_option = 'DEFAULT_CLOSED'
[docs] def draw(self, context): layout = self.layout layout.operator("object.curve_plate") layout.operator("object.curve_drawer") layout.operator("object.curve_mortise") layout.operator("object.curve_interlock") layout.operator("object.curve_puzzle") layout.operator("object.sine") layout.operator("object.lissajous") layout.operator("object.hypotrochoid") layout.operator("object.customcurve") layout.operator("object.curve_hatch") layout.operator("object.curve_gear") layout.operator("object.curve_flat_cone")
# 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] filename_ext = ".txt"
[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", )