Skip to content

Commit

Permalink
#36 z-movement in comment lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Olli committed May 4, 2018
1 parent 9b21cb0 commit c945fca
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
46 changes: 29 additions & 17 deletions octoprint_DisplayLayerProgress/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
LAYER_EXPRESSION_CURA = ";LAYER:([0-9]+).*"
LAYER_EXPRESSION_S3D = "; layer ([0-9]+),.*"
LAYER_COUNT_EXPRESSION = LAYER_MESSAGE_PREFIX + "([0-9]*)"
# Match G1 Z149.370 F1000 or G0 F9000 X161.554 Y118.520 Z14.950
Z_HEIGHT_EXPRESSION = "(.*)( Z)([+]*[0-9]+.[0-9]*)(.*)"
# Match G1 Z149.370 F1000 or G0 F9000 X161.554 Y118.520 Z14.950 ##no comments
Z_HEIGHT_EXPRESSION = "^[^;](.*)( Z)([+]*[0-9]+[.]*[0-9]*)(.*)"
zHeightPattern = re.compile(Z_HEIGHT_EXPRESSION)
# Match G0 or G1 positive extrusion e.g. G1 X58.030 Y72.281 E0.1839 F2250
EXTRUSION_EXPRESSION = "G[0|1] .*E[+]*([0-9]+[.]*[0-9]*).*"
Expand Down Expand Up @@ -155,23 +155,31 @@ def on_event(self, event, payload):
totalHeight = 0.0
currentHeight = 0.0
lineNumber = 0
self._activateBusyIndicator()
with open(selectedFile, "r") as f:
for line in f:
lineNumber += 1
matched = pattern.match(line)
if matched:
layerOffset = self._settings.get_int([SETTINGS_KEY_LAYER_OFFSET])
self._layerTotalCount = str(int(matched.group(1)) + layerOffset)

matched = zHeightPattern.match(line)
if matched:
currentHeight = float(matched.group(3))
if currentHeight > totalHeight:
totalHeight = currentHeight

matched = extrusionPattern.match(line)
if matched:
self._totalHeightWithExtrusion = currentHeight
try:
lineNumber += 1
matched = pattern.match(line)
if matched:
layerOffset = self._settings.get_int([SETTINGS_KEY_LAYER_OFFSET])
self._layerTotalCount = str(int(matched.group(1)) + layerOffset)

matched = zHeightPattern.match(line)
if matched:
currentHeight = float(matched.group(3))
if currentHeight > totalHeight:
totalHeight = currentHeight

matched = extrusionPattern.match(line)
if matched:
self._totalHeightWithExtrusion = currentHeight
except (ValueError, RuntimeError):
print("BOOOOOOMMMM")
print("#"+lineNumber + " "+line)



if self._settings.get([SETTINGS_KEY_TOTAL_HEIGHT_METHODE]) == HEIGHT_METHODE_Z_MAX:
self._totalHeight = "%.2f" % totalHeight
else:
Expand Down Expand Up @@ -209,6 +217,10 @@ def _resetProgressValues(self):
self._totalHeight = 0.0
self._totalHeightWithExtrusion = 0.0

def _activateBusyIndicator(self):
self._plugin_manager.send_plugin_message(self._identifier, dict(busy=True))


def _updateDisplay(self, updateReason):
currentValueDict = {
PROGRESS_KEYWORD_EXPRESSION: self._progress,
Expand Down
13 changes: 11 additions & 2 deletions octoprint_DisplayLayerProgress/static/js/DisplayLayerProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ $(function () {
var element = $("#state").find(".accordion-inner .progress");
if (element.length) {


var busyIndicator = "<i class='fa fa-spinner fa-spin busyIndicator' style='display:none'></i>";

var label = gettext("Current Height");
var tooltip = gettext("Might be inaccurate!");
element.before("<span title='" + tooltip + "'>" + label + "</span>" + ": "
+ "<strong id='state_height_message'>- / -</strong><br>");
+ "<strong id='state_height_message'>- / -</strong>"+busyIndicator+" <br>");

label = gettext("Layer");
tooltip = gettext("Shows the layer information");
element.before("<span title='" + tooltip + "'>" + label + "</span>" + ": "
+ "<strong id='state_layer_message'>- / -</strong><br>");
+ "<strong id='state_layer_message'>- / -</strong>"+busyIndicator+"<br>");

// call backend for update navbar and printer-display
OctoPrint.get("api/plugin/"+PLUGIN_ID);
Expand All @@ -56,6 +59,12 @@ $(function () {
return;
}

if (data.busy){
$(".busyIndicator").show();
} else {
$(".busyIndicator").hide();
}

// NavBar
if (data.navBarMessage){
self.navBarMessage(data.navBarMessage);
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "DisplayLayerProgress"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "1.5.0"
plugin_version = "1.5.1"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit c945fca

Please sign in to comment.