blendercam/scripts/addons/fabex/ui/panels/info_panel.py

144 wiersze
5.2 KiB
Python

2024-10-25 02:47:11 +00:00
"""Fabex 'info.py'
2024-10-22 20:19:27 +00:00
'CAM Info & Warnings' properties and panel in Properties > Render
"""
2024-10-29 20:58:51 +00:00
from datetime import timedelta
2024-10-22 20:19:27 +00:00
import bpy
from bpy.types import Panel
from .parent_panel import CAMParentPanel
2024-12-19 19:10:10 +00:00
2024-10-22 20:19:27 +00:00
# Info panel
# This panel gives general information about the current operation
class CAM_INFO_Panel(CAMParentPanel, Panel):
2024-10-29 20:58:51 +00:00
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
bl_options = {"HIDE_HEADER"}
bl_label = "Info & Warnings"
2024-12-18 20:37:25 +00:00
bl_idname = "FABEX_PT_CAM_INFO"
2024-10-29 20:58:51 +00:00
panel_interface_level = 0
always_show_panel = True
def __init__(self, *args, **kwargs):
Panel.__init__(self, *args, **kwargs)
CAMParentPanel.__init__(self, *args, **kwargs)
super().__init__(*args, **kwargs)
2024-10-29 20:58:51 +00:00
# Display the Info Panel
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
main = layout.box()
2025-02-12 17:45:06 +00:00
main.label(text=f"[ Info ]", icon="INFO")
2024-10-29 20:58:51 +00:00
if context.window_manager.progress > 0:
col = main.column(align=True)
col.scale_y = 2
percent = int(context.window_manager.progress * 100)
col.progress(
factor=context.window_manager.progress,
2024-11-01 19:57:09 +00:00
text=f"Processing...{percent}%",
2024-10-29 20:58:51 +00:00
)
if self.op is None:
return
else:
if not self.op.info.warnings == "":
# Operation Warnings
box = main.box()
col = box.column(align=True)
col.alert = True
col.label(text="!!! WARNING !!!", icon="ERROR")
2024-10-29 20:58:51 +00:00
for line in self.op.info.warnings.rstrip("\n").split("\n"):
if len(line) > 0:
icon = "BLANK1"
if line.startswith(("Path", "Operation", "X", "Y", "Z")):
icon = "MOD_WIREFRAME"
if line.startswith(("Memory", "Detail")):
icon = "MEMORY"
if line.startswith(("!!!")):
icon = "ERROR"
col.label(text=line, icon=icon)
2024-10-29 20:58:51 +00:00
2024-11-05 16:14:13 +00:00
# Cutter Engagement
if not self.op.strategy == "CUTOUT" and not self.op.cutter_type in ["LASER", "PLASMA"]:
box = main.box()
col = box.column(align=True)
# Warns if cutter engagement is greater than 50%
if self.op.cutter_type in ["BALLCONE"]:
engagement = round(
100 * self.op.distance_between_paths / self.op.ball_radius, 1
)
2024-11-05 16:14:13 +00:00
else:
engagement = round(
100 * self.op.distance_between_paths / self.op.cutter_diameter, 1
2024-11-05 16:14:13 +00:00
)
if engagement > 50:
col.alert = True
col.label(text="Warning: High Cutter Engagement", icon="ERROR")
2025-02-12 17:45:06 +00:00
col.label(text="Cutter Engagement")
row = col.split(factor=0.32)
col_1 = row.column(align=True)
col_1.alignment = "RIGHT"
col_1.label(text="CWE:")
col_2 = row.column(align=True)
col_2.alignment = "LEFT"
col_2.label(text=f"{engagement}%", icon="STYLUS_PRESSURE")
2024-11-05 16:14:13 +00:00
2024-10-29 20:58:51 +00:00
# Operation Time Estimate
duration = self.op.info.duration
seconds = int(duration * 60)
if not seconds > 0:
return
time_estimate = str(timedelta(seconds=seconds))
split = time_estimate.split(":")
split[0] += "h "
split[1] += "m "
split[2] += "s"
time_estimate = split[0] + split[1] + split[2]
box = main.box()
col = box.column(align=True)
2024-11-01 19:57:09 +00:00
col.label(text="Estimates")
2025-01-24 17:07:06 +00:00
row = col.split(factor=0.32)
title_col = row.column(align=True)
2025-02-12 17:45:06 +00:00
title_col.alignment = "RIGHT"
2025-01-24 17:07:06 +00:00
value_col = row.column(align=True)
2025-02-12 17:45:06 +00:00
value_col.alignment = "LEFT"
2025-01-24 17:07:06 +00:00
2025-02-12 17:45:06 +00:00
title_col.label(text="Time:")
value_col.label(text=time_estimate, icon="TIME")
2024-10-29 20:58:51 +00:00
# Operation Chipload
2024-12-21 19:04:32 +00:00
if self.op.info.chipload > 0:
2025-01-24 17:07:06 +00:00
chipload = self.op.feedrate / (self.op.spindle_rpm * self.op.cutter_flutes)
chipload = f"{chipload:.5f}"
2025-02-12 17:45:06 +00:00
title_col.label(text=f"Chipload:")
value_col.label(
text=chipload,
2025-01-24 17:07:06 +00:00
icon="DRIVER_ROTATIONAL_DIFFERENCE",
)
else:
2024-12-21 19:04:32 +00:00
pass
2024-10-29 20:58:51 +00:00
# Operation Money Cost
if self.level >= 1:
if not int(self.op.info.duration * 60) > 0:
return
if float(bpy.context.scene.cam_machine.hourly_rate) < 0.01:
return
cost_per_second = bpy.context.scene.cam_machine.hourly_rate / 3600
total_cost = self.op.info.duration * 6000 * cost_per_second
op_cost = f"${total_cost:.2f}" # (${cost_per_second:.2f}/s)"
2025-02-12 17:45:06 +00:00
title_col.label(text="Cost:")
value_col.label(text=op_cost, icon="TAG")