Skip to content

Commit

Permalink
Added Slicer Thumbnails support j7126#287
Browse files Browse the repository at this point in the history
  • Loading branch information
Willmac16 committed Jul 26, 2021
1 parent b1388a1 commit be29a3b
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 30 deletions.
36 changes: 20 additions & 16 deletions octoprint_dashboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def __init__(self, fileBufferedReader, layer_indicator_patterns, layer_move_patt
self.layer_move_array = []
self.filament_change_array = []
self._logger = logger
self.meta_ed = False

def process_line(self, origLine):
if not len(origLine):
Expand Down Expand Up @@ -85,9 +84,9 @@ class DashboardPlugin(octoprint.plugin.SettingsPlugin,
layer_labels = []
cmd_commands= []
cmd_timers = []
gcode_preprocessors = {}
python_version = 0
is_preprocessed = False
gcode_preprocessor = None
layer_indicator_config = []
layer_indicator_patterns = []
layer_start_time = None
Expand Down Expand Up @@ -171,7 +170,7 @@ def psUtilGetStats(self):
cpuTemp=str(self.cpu_temp),
cpuFreq=str(self.cpu_freq)
)
self._plugin_manager.send_plugin_message(self._identifier, psutilmSg)
self._plugin_manager.send_plugin_message(self._identifier, psutilMsg)

def runCmd(self, cmdIndex):
cmd = self.cmd_commands[cmdIndex].get("command")
Expand Down Expand Up @@ -330,19 +329,18 @@ def connect_notification(self):
)
self._plugin_manager.send_plugin_message(self._identifier, msg)

def unload_preprocesser(self, payload):
self.gcode_preprocessor.layer_move_array.append(self.gcode_preprocessor.layer_moves)
self.gcode_preprocessor.layer_count += 1
def unload_preprocesser(self, processor, payload):
# Stick the final layer into the array (the one the print ends on)
processor.layer_move_array.append(processor.layer_moves)
processor.layer_count += 1

#Store the total_layer_count and layer_move_array in the file metadata once all analysis is finished
self._logger.info("GcodePreProcessor found layers: " + str(self.gcode_preprocessor.layer_count))
self._logger.info("GcodePreProcessor found filament changes: " + str(len(self.gcode_preprocessor.filament_change_array)))
self._logger.info("GcodePreProcessor found layers: " + str(processor.layer_count))
self._logger.info("GcodePreProcessor found filament changes: " + str(len(processor.filament_change_array)))
self._logger.info("GcodePreProcessor saving layer count in file metadata")
additionalMetaData = {"layer_move_array": json.dumps(self.gcode_preprocessor.layer_move_array), "filament_change_array": json.dumps(self.gcode_preprocessor.filament_change_array)}
additionalMetaData = {"layer_move_array": json.dumps(processor.layer_move_array), "filament_change_array": json.dumps(processor.filament_change_array)}
self._file_manager.set_additional_metadata(payload.get("origin"), payload.get("name"), self._plugin_info.key, additionalMetaData, overwrite=True)

self.gcode_preprocessor.meta_ed = True

def load_from_meta(self, payload):
#Reset vars
self.layer_start_time = None
Expand Down Expand Up @@ -412,7 +410,7 @@ def load_from_meta(self, payload):
stream = self.createFilePreProcessor(path, file_object)
stream.save(path)
self._logger.info("Gcode pre-processing done.")
self.unload_preprocesser(payload)
self.unload_preprocesser(self.gcode_preprocessors[path], payload)
self.load_from_meta(payload)
return
else:
Expand Down Expand Up @@ -459,8 +457,10 @@ def print_ended(self):
self._plugin_manager.send_plugin_message(self._identifier, endMsg)

def on_event(self, event, payload):
if event == Events.METADATA_ANALYSIS_FINISHED and self.gcode_preprocessor and not self.gcode_preprocessor.meta_ed:
self.unload_preprocesser(payload)
if event == Events.METADATA_ANALYSIS_FINISHED:
if payload['path'] in self.gcode_preprocessors:
gcpp = self.gcode_preprocessors.pop(payload.path)
self.unload_preprocesser(gcpp, payload)
elif event == Events.PRINT_STARTED:
self.load_from_meta(payload)
elif event == Events.PRINT_DONE or event == Events.PRINT_FAILED or event == Events.PRINT_CANCELLED:
Expand Down Expand Up @@ -555,6 +555,7 @@ def get_settings_defaults(self):
showFeedrate=False,
showCommandWidgets=False,
enableTempGauges=True,
showPrintThumbnail=True,
# show the widgets in full screen
fsSystemInfo=True,
fsJobControlButtons=False,
Expand All @@ -568,6 +569,7 @@ def get_settings_defaults(self):
fsFilament=True,
fsFeedrate=True,
fsWebCam=True,
fsPrintThumbnail=True,
# printingOnly: False = shown when printing or not printing, True = shown only when printing
printingOnly_SystemInfo=False,
printingOnly_JobControlButtons=False,
Expand All @@ -587,6 +589,7 @@ def get_settings_defaults(self):
clearOn_LayerGraph=2,
clearOn_Filament=2,
clearOn_Feedrate=2,
clearOn_PrintThumbnail=2,
# max value of feedrate gauge
feedrateMax=400,
# time format for eta
Expand Down Expand Up @@ -765,6 +768,7 @@ def process_gcode(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwa
self.current_move += 1
self.layer_moves += 1
if self.current_layer >= 0 and self.total_layers > 0 and len(self.layer_move_array) > 0 : # Avoid moves prior to the first layer and un-preprocessed gcode files.
# self._logger.debug("Current Layer {} total layers {}".format(self.current_layer, len(self.layer_move_array)))
current_layer_progress = int((self.layer_moves / self.layer_move_array[self.current_layer]) * 100)
if self.layer_moves % self.moves_to_update_progress == 0: # Update the in, layer progress a reasonable amount
self.layer_progress = current_layer_progress
Expand Down Expand Up @@ -836,8 +840,8 @@ def createFilePreProcessor(self, path, file_object, blinks=None, printer_profile
return file_object
fileStream = file_object.stream()
self._logger.info("GcodePreProcessor started processing.")
self.gcode_preprocessor = GcodePreProcessor(fileStream, self.layer_indicator_patterns, self.layer_move_pattern, self.filament_change_pattern, self.python_version, self._logger)
return octoprint.filemanager.util.StreamWrapper(fileName, self.gcode_preprocessor)
self.gcode_preprocessors[path] = GcodePreProcessor(fileStream, self.layer_indicator_patterns, self.layer_move_pattern, self.filament_change_pattern, self.python_version, self._logger)
return octoprint.filemanager.util.StreamWrapper(fileName, self.gcode_preprocessors[path])


__plugin_name__ = "Dashboard"
Expand Down
10 changes: 10 additions & 0 deletions octoprint_dashboard/static/css/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
left: 100%;
}

.dashboardGridItem.thumbnailContainer {
display: grid;
}

#dashboard_print_thumbnail {
margin: auto;
float: unset;
width: 50%;
}

.progressContainer div {
margin: 0 auto;
width: 100%;
Expand Down
47 changes: 35 additions & 12 deletions octoprint_dashboard/static/js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,20 @@ $(function () {
self.admin = ko.observableArray(false);
self.webcam_perm = ko.observable(false);

self.fsSystemInfo = ko.computed(() => this.isFull() && this.settingsViewModel.settings.plugins.dashboard.fsSystemInfo() || !this.isFull(), this);
self.fsTempGauges = ko.computed(() => this.isFull() && this.settingsViewModel.settings.plugins.dashboard.fsTempGauges() || !this.isFull(), this);
self.fsFan = ko.computed(() => this.isFull() && this.settingsViewModel.settings.plugins.dashboard.fsFan() || !this.isFull(), this);
self.fsCommandWidgets = ko.computed(() => this.isFull() && this.settingsViewModel.settings.plugins.dashboard.fsCommandWidgets() || !this.isFull(), this);
self.fsJobControlButtons = ko.computed(() => this.isFull() && this.settingsViewModel.settings.plugins.dashboard.fsJobControlButtons() || !this.isFull(), this);
self.fsSensorInfo = ko.computed(() => this.isFull() && this.settingsViewModel.settings.plugins.dashboard.fsSensorInfo() || !this.isFull(), this);
self.fsPrinterMessage = ko.computed(() => this.isFull() && this.settingsViewModel.settings.plugins.dashboard.fsPrinterMessage() || !this.isFull(), this);
self.fsProgressGauges = ko.computed(() => this.isFull() && this.settingsViewModel.settings.plugins.dashboard.fsProgressGauges() || !this.isFull(), this);
self.fsLayerGraph = ko.computed(() => this.isFull() && this.settingsViewModel.settings.plugins.dashboard.fsLayerGraph() || !this.isFull(), this);
self.fsFilament = ko.computed(() => this.isFull() && this.settingsViewModel.settings.plugins.dashboard.fsFilament() || !this.isFull(), this);
self.fsFeedrate = ko.computed(() => this.isFull() && this.settingsViewModel.settings.plugins.dashboard.fsFeedrate() || !this.isFull(), this);
self.fsWebCam = ko.computed(() => this.isFull() && this.settingsViewModel.settings.plugins.dashboard.fsWebCam() || !this.isFull(), this);
self.fsSystemInfo = ko.computed(() => !this.isFull() || this.settingsViewModel.settings.plugins.dashboard.fsSystemInfo(), this);
self.fsTempGauges = ko.computed(() => !this.isFull() || this.settingsViewModel.settings.plugins.dashboard.fsTempGauges(), this);
self.fsFan = ko.computed(() => !this.isFull() || this.settingsViewModel.settings.plugins.dashboard.fsFan(), this);
self.fsCommandWidgets = ko.computed(() => !this.isFull() || this.settingsViewModel.settings.plugins.dashboard.fsCommandWidgets(), this);
self.fsJobControlButtons = ko.computed(() => !this.isFull() || this.settingsViewModel.settings.plugins.dashboard.fsJobControlButtons(), this);
self.fsSensorInfo = ko.computed(() => !this.isFull() || this.settingsViewModel.settings.plugins.dashboard.fsSensorInfo(), this);
self.fsPrinterMessage = ko.computed(() => !this.isFull() || this.settingsViewModel.settings.plugins.dashboard.fsPrinterMessage(), this);
self.fsProgressGauges = ko.computed(() => !this.isFull() || this.settingsViewModel.settings.plugins.dashboard.fsProgressGauges(), this);
self.fsLayerGraph = ko.computed(() => !this.isFull() || this.settingsViewModel.settings.plugins.dashboard.fsLayerGraph(), this);
self.fsFilament = ko.computed(() => !this.isFull() || this.settingsViewModel.settings.plugins.dashboard.fsFilament(), this);
self.fsFeedrate = ko.computed(() => !this.isFull() || this.settingsViewModel.settings.plugins.dashboard.fsFeedrate(), this);
self.fsWebCam = ko.computed(() => !this.isFull() || this.settingsViewModel.settings.plugins.dashboard.fsWebCam(), this);
self.fsPrintThumbnail = ko.computed(() => !this.isFull() || this.settingsViewModel.settings.plugins.dashboard.fsPrintThumbnail(), this);


self.hls;

Expand Down Expand Up @@ -365,6 +367,10 @@ $(function () {
self.feedrateAvLastFiveSeconds(0);
self.feedrateAvNoLastFiveSeconds(0);
}

if (self.dashboardSettings.showPrintThumbnail()) {
self.updatePrintThumbnail();
}
return;
};

Expand All @@ -382,6 +388,8 @@ $(function () {
self.feedrateAvLastFiveSeconds(0);
self.feedrateAvNoLastFiveSeconds(0);
}
if (self.dashboardSettings.clearOn_PrintThumbnail() == 2)
$("#dashboard_print_thumbnail").remove()
return;
};

Expand Down Expand Up @@ -473,6 +481,7 @@ $(function () {
printingOnly: dashboardSettings.printingOnly_SensorInfo },
{ title: "Command Widgets", enabled: dashboardSettings.showCommandWidgets, settingsId: "#dashboardCommandSettingsModal", enableInFull: dashboardSettings.fsCommandWidgets, printingOnly: dashboardSettings.printingOnly_CommandWidgets },
{ title: "Printer Message (M117)", enabled: dashboardSettings.showPrinterMessage, enableInFull: dashboardSettings.fsPrinterMessage, printingOnly: dashboardSettings.printingOnly_PrinterMessage, clearOn: dashboardSettings.clearOn_PrinterMessage },
{ title: "Print Thumbnail (Slicer Thumbnails)", enabled: dashboardSettings.showPrintThumbnail, enableInFull: dashboardSettings.fsPrintThumbnail, clearOn: dashboardSettings.clearOn_PrintThumbnail },
{
title: "Progress Gauges",
enabled: function () {
Expand Down Expand Up @@ -537,6 +546,16 @@ $(function () {
self.bindingDone = true;
};

self.updatePrintThumbnail = function () {
$('#dashboard_print_thumbnail').remove();
thumbnail = $('#prusaslicer_state_thumbnail');
if (thumbnail) {
clone = thumbnail.clone();
clone.attr("id", "dashboard_print_thumbnail");
clone.appendTo( $('.dashboardGridItem.thumbnailContainer') );
}
}

self.doTempGaugeTicks = function () {
var tempTicks = [];
var temperatureTicks = self.dashboardSettings.temperatureTicks();
Expand Down Expand Up @@ -1097,6 +1116,10 @@ $(function () {
self._disableWebcam();
}
});

if (self.dashboardSettings.showPrintThumbnail()) {
setTimeout(self.updatePrintThumbnail, 2500);
}
}

self.onServerDisconnect = function () {
Expand Down
13 changes: 11 additions & 2 deletions octoprint_dashboard/templates/dashboard_tab.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,12 @@
<!-- /ko -->

<!-- Cmd Widgets as 3/4 -->

<!-- ko if: dashboardSettings.showCommandWidgets() -->
<!-- ko foreach: commandWidgetArray -->
<!-- ko if: enabled && $parent.castToWidgetTypes(type()) === $parent.widgetTypes.THREE_QUARTER -->
<div class="dashboardGridItem dashboard_threeQuarterGauge"
data-bind="css: $parent.gaugesCentreInGrid('cmd', $index()), visible: (!$parent.dashboardSettings.printingOnly_TempGauges() || $parent.printerStateModel.isPrinting())">
data-bind="css: $parent.gaugesCentreInGrid('cmd', $index()), visible: $parent.fsCommandWidgets() && (!$parent.dashboardSettings.printingOnly_TempGauges() || $parent.printerStateModel.isPrinting())">
<img class="dashboardIcon" data-bind="attr: {'src': 'plugin/dashboard/static/img/' + icon(), 'title': name}" />
<svg xmlns="http://www.w3.org/2000/svg" height="140" width="140"
data-bind="attr: {'viewBox': $parent.tempGaugeViewBox()}">
Expand All @@ -273,6 +275,7 @@
</div>
<!-- /ko -->
<!-- /ko -->
<!-- /ko -->

</div>

Expand All @@ -299,10 +302,11 @@
<!-- /ko -->

<!-- Text Command Widgets -->
<!-- ko if: dashboardSettings.showCommandWidgets() -->
<!-- ko foreach: commandWidgetArray -->
<!-- ko if: enabled && $parent.castToWidgetTypes(type()) === $parent.widgetTypes.TEXT -->
<div class="dashboardGridItem command"
data-bind="visible: (!$parent.dashboardSettings.printingOnly_CommandWidgets() || $parent.printerStateModel.isPrinting()) && enabled() && ($parent.dashboardSettings.showCommandWidgets() && $parent.fsCommandWidgets())">
data-bind="visible: (!$parent.dashboardSettings.printingOnly_CommandWidgets() || $parent.printerStateModel.isPrinting()) && $parent.fsCommandWidgets()">
<img class="dashboardIcon" data-bind="attr: {src: 'plugin/dashboard/static/img/' + icon(), title: name()}" />
<div class="inline">
<span data-bind="text: name(), attr: {title: name()}"></span>
Expand All @@ -313,6 +317,7 @@
</div>
<!-- /ko -->
<!-- /ko -->
<!-- /ko -->

</div>

Expand Down Expand Up @@ -474,6 +479,10 @@
<span id="fileInfo" data-bind="attr: { title: 'File' }, html: printerStateModel.filedisplay()"></span>
</div>

<div class="dashboardGridItem thumbnailContainer" data-bind="visible: dashboardSettings.showPrintThumbnail() && fsPrintThumbnail()">

</div>

<div class="dashboardGridContainer">

<!-- GCode -->
Expand Down

0 comments on commit be29a3b

Please sign in to comment.