Skip to content

Commit

Permalink
RC3
Browse files Browse the repository at this point in the history
- #13 more logging
- #12 always verify spool before print
- #11 show remaining filament in spool selection
- #10 display of orange
- #9 remaining filament not shown
  • Loading branch information
OllisGit committed Jul 22, 2020
1 parent 78833b9 commit 3d4cc49
Show file tree
Hide file tree
Showing 16 changed files with 238 additions and 38 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ should include the following features:

## Planning Release #2

- [ ] External Database
- [ ] Table column visibity
- [ ] Capture Spool-Image
- [ ] Scan QR/Barcodes of a spool
Expand Down
2 changes: 1 addition & 1 deletion octoprint_SpoolManager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ def _on_clientOpened(self, payload):
selectedSpoolAsDict = Transformer.transformSpoolModelToDict(selectedSpool)
else:
# spool not found
self._logger.warning("Last selected Spool from plugin-settings not found in database. Maybe deleted in the meantime.")
pass

self._sendDataToClient(dict(action="initalData",
Expand Down Expand Up @@ -367,6 +366,7 @@ def get_settings_defaults(self):

## Genral
settings[SettingsKeys.SETTINGS_KEY_SELECTED_SPOOL_DATABASE_ID] = None
settings[SettingsKeys.SETTINGS_KEY_REMINDER_SELECTING_SPOOL] = True
settings[SettingsKeys.SETTINGS_KEY_WARN_IF_SPOOL_NOT_SELECTED] = True
settings[SettingsKeys.SETTINGS_KEY_WARN_IF_FILAMENT_NOT_ENOUGH] = True
settings[SettingsKeys.SETTINGS_KEY_CURRENCY_SYMBOL] = "€"
Expand Down
56 changes: 45 additions & 11 deletions octoprint_SpoolManager/api/SpoolManagerAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,26 @@ def loadSelectedSpool(self):
databaseId = self._settings.get_int([SettingsKeys.SETTINGS_KEY_SELECTED_SPOOL_DATABASE_ID])
if (databaseId != None):
spoolModel = self._databaseManager.loadSpool(databaseId)
if (spoolModel == None):
self._logger.warning(
"Last selected Spool from plugin-settings not found in database. Maybe deleted in the meantime.")

return spoolModel


def _createSampleSpoolModel(self):
#DisplayName, Vendor, Material, Color[# code], Diameter [mm], Density [g/cm³], Temperature [°C], TotalWeight [g], UsedWeight [g], UsedLength [mm], FirstUse [dd.mm.yyyy hh:mm], LastUse [dd.mm.yyyy hh:mm], PurchasedFrom, PurchasedOn [dd.mm.yyyy hh:mm], Cost, CostUnit, Labels, NoteText

s1 = SpoolModel()
s1.displayName = "Number #1"
s1.vendor = "The Spool Company"
s1.material = "PETG"
s1.color = "#FF0000"
s1.diameter = 1.75
s1.density = 1.27
return s1


################################################### APIs

############################################################################################## ALLOWED TO PRINT
Expand All @@ -110,6 +127,7 @@ def allowed_to_print(self):

checkForSelectedSpool = self._settings.get_boolean([SettingsKeys.SETTINGS_KEY_WARN_IF_SPOOL_NOT_SELECTED])
checkForFilamentLength = self._settings.get_boolean([SettingsKeys.SETTINGS_KEY_WARN_IF_FILAMENT_NOT_ENOUGH])
reminderSelectingSpool = self._settings.get_boolean([SettingsKeys.SETTINGS_KEY_REMINDER_SELECTING_SPOOL])

if (checkForFilamentLength == False and checkForSelectedSpool == False):
return flask.jsonify({
Expand All @@ -123,18 +141,24 @@ def allowed_to_print(self):
"result": "noSpoolSelected",
})

if (checkForFilamentLength == True):
# check if loaded
if (spoolModel == None):
if (checkForFilamentLength == True and spoolModel != None):
# # check if loaded
# if (spoolModel == None):
# return flask.jsonify({
# "result": "noSpoolForUsageCheck",
# })
# else:
result = self.checkRemainingFilament();
if (result == False):
return flask.jsonify({
"result": "noSpoolForUsageCheck",
"result": "filamentNotEnough",
})
else:
result = self.checkRemainingFilament();
if (result == False):
return flask.jsonify({
"result": "filamentNotEnough",
})

if (reminderSelectingSpool == True and spoolModel != None):
return flask.jsonify({
"result": "reminderSpoolSelection",
"spoolName": spoolModel.displayName
})

return flask.jsonify({
"result": "startPrint"
Expand All @@ -143,20 +167,26 @@ def allowed_to_print(self):
##################################################################################################### SELECT SPOOL
@octoprint.plugin.BlueprintPlugin.route("/selectSpool", methods=["PUT"])
def select_spool(self):
self._logger.info("API Store selected spool")
jsonData = request.json

databaseId = self._getValueFromJSONOrNone("databaseId", jsonData)
if (databaseId != None):
spoolModel = self._databaseManager.loadSpool(databaseId)
# check if loaded
if (spoolModel != None):
self._logger.info("Store selected spool '"+spoolModel.displayName+"' in settings.")

# - store spool in Settings
self._settings.set_int([SettingsKeys.SETTINGS_KEY_SELECTED_SPOOL_DATABASE_ID], databaseId)
self._settings.save()

self.checkRemainingFilament()
else:
self._logger.warning("Selected Spool with id '"+str(databaseId)+"' not in database anymore. Maybe deleted in the meantime.")
else:
# No selection
self._logger.info("Clear stored selected spool in settings.")
self._settings.set_int([SettingsKeys.SETTINGS_KEY_SELECTED_SPOOL_DATABASE_ID], None)
self._settings.save()
pass
Expand All @@ -169,7 +199,7 @@ def select_spool(self):
################################################################################################## LOAD ALL SPOOLS
@octoprint.plugin.BlueprintPlugin.route("/loadSpoolsByQuery", methods=["GET"])
def load_allSpools(self):

self._logger.debug("API Load all spool")
# sp1 = SpoolModel()
# sp1.displayName = "Spool No.1"
# sp1.vendor = "Janbex"
Expand Down Expand Up @@ -237,13 +267,16 @@ def load_allSpools(self):
####################################################################################################### SAVE SPOOL
@octoprint.plugin.BlueprintPlugin.route("/saveSpool", methods=["PUT"])
def save_spool(self):
self._logger.info("API Save spool")
jsonData = request.json

databaseId = self._getValueFromJSONOrNone("databaseId", jsonData)
if (databaseId != None):
self._logger.info("Update spool with database id '"+str(databaseId)+"'")
spoolModel = self._databaseManager.loadSpool(databaseId)
self._updateSpoolModelFromJSONData(spoolModel, jsonData)
else:
self._logger.info("Create new spool")
spoolModel = SpoolModel()
self._updateSpoolModelFromJSONData(spoolModel, jsonData)

Expand All @@ -255,6 +288,7 @@ def save_spool(self):
##################################################################################################### DELETE SPOOL
@octoprint.plugin.BlueprintPlugin.route("/deleteSpool/<int:databaseId>", methods=["DELETE"])
def delete_printjob(self, databaseId):
self._logger.info("API Delete spool with database id '" + str(databaseId) + "'")
printJob = self._databaseManager.deleteSpool(databaseId)
# snapshotFilename = CameraManager.buildSnapshotFilename(printJob.printStartDateTime)
# self._cameraManager.deleteSnapshot(snapshotFilename)
Expand Down
39 changes: 38 additions & 1 deletion octoprint_SpoolManager/api/Transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@
from octoprint_SpoolManager.models.SpoolModel import SpoolModel
from octoprint_SpoolManager.common import StringUtils

def _calculateRemainingWeight(usedWeight, totalWeight):
if (usedWeight == None or totalWeight == None):
return None

if ( (type(usedWeight) == int or type(usedWeight) == float) and
(type(totalWeight) == int or type(totalWeight) == float) ):
result = totalWeight - usedWeight
return result

return None

def _calculateUsedPercentage(remainingWeight, totalWeight):
if (remainingWeight == None or totalWeight == None):
return None

if ( (type(remainingWeight) == int or type(remainingWeight) == float) and
(type(totalWeight) == int or type(totalWeight) == float) ):
result = remainingWeight / (totalWeight / 100.0);
return result

return None


def transformSpoolModelToDict(spoolModel):
spoolAsDict = spoolModel.__data__

Expand All @@ -14,10 +37,24 @@ def transformSpoolModelToDict(spoolModel):

spoolAsDict["created"] = StringUtils.formatDateTime(spoolModel.created)

# Decimal and date time needs to be converted

totalWeight = spoolModel.totalWeight
usedWeight = spoolModel.usedWeight
remainingWeight = _calculateRemainingWeight(usedWeight, totalWeight)
usedPercentage = _calculateUsedPercentage(remainingWeight, totalWeight)

spoolAsDict["remainingWeight"] = StringUtils.formatFloat(remainingWeight)
spoolAsDict["usedPercentage"] = StringUtils.formatFloat(usedPercentage)


# Decimal and date time needs to be converted. ATTENTION orgiginal fields will be modified
spoolAsDict["totalWeight"] = StringUtils.formatFloat(spoolModel.totalWeight)
spoolAsDict["usedWeight"] = StringUtils.formatFloat(spoolModel.usedWeight)





# spoolAsDict["temperature"] = StringUtils.formatSave("{:.02f}", spoolAsDict["temperature"], "")
# spoolAsDict["weight"] = StringUtils.formatSave("{:.02f}", spoolAsDict["weight"], "")
# spoolAsDict["remainingWeight"] = StringUtils.formatSave("{:.02f}", spoolAsDict["remainingWeight"], "")
Expand Down
1 change: 1 addition & 0 deletions octoprint_SpoolManager/common/SettingsKeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class SettingsKeys():

SETTINGS_KEY_SELECTED_SPOOL_DATABASE_ID = "selectedSpoolDatabaseId"

SETTINGS_KEY_REMINDER_SELECTING_SPOOL = "reminderSelectingSpool"
SETTINGS_KEY_WARN_IF_SPOOL_NOT_SELECTED = "warnIfSpoolNotSelected"
SETTINGS_KEY_WARN_IF_FILAMENT_NOT_ENOUGH = "warnIfFilamentNotEnough"

Expand Down
12 changes: 6 additions & 6 deletions octoprint_SpoolManager/static/css/SpoolManager.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
overflow: hidden;
text-overflow: ellipsis;
}

.dropdown-menu {
max-height: 120px;
overflow-y: auto;
overflow-x: hidden;
}
// TODO Maybe not needed any more
// .dropdown-menu {
// max-height: 120px;
// overflow-y: auto;
// overflow-x: hidden;
// }



Expand Down
12 changes: 6 additions & 6 deletions octoprint_SpoolManager/static/js/ComponentFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ function ComponentFactory(pluginId) {
showHexInput : true,
allowBlank : false,
basicColors : {
white : 'fff',
black : '000',
red : 'f00',
white : 'ffffff',
black : '000000',
red : 'ff0000',
green : '008000',
blue : '00f',
yellow : 'ff0',
orange : 'f60',
blue : '0000ff',
yellow : 'ffff00',
orange : 'ffa500',
purple : '800080',
// gray : '808080',
// darkgray : 'A9A9A9',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ function SpoolManagerEditSpoolDialog(){
this.color(updateData.color == null ? DEFAULT_COLOR : updateData.color);
this.temperature(updateData.temperature);
this.totalWeight(updateData.totalWeight);
// this.remainingWeight(updateData.remainingWeight);
this.remainingWeight(updateData.remainingWeight);
this.code(updateData.code);
// this.usedPercentage(updateData.usedPercentage); // TODO needed?
this.usedPercentage(updateData.usedPercentage);
this.usedLength(updateData.usedLength);
this.usedWeight(updateData.usedWeight);

Expand Down Expand Up @@ -349,7 +349,7 @@ function SpoolManagerEditSpoolDialog(){
self.updateUsedPercentage();
});

// update used percentage
// update RemainingWeight
self.updateRemainingWeight = function(){
var total = self.spoolItemForEditing.totalWeight();
var used = self.spoolItemForEditing.usedWeight();
Expand Down
26 changes: 21 additions & 5 deletions octoprint_SpoolManager/static/js/SpoolManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,14 @@ $(function() {
displayName = " ";
}

var label = color + " - " + material + " - " + displayName;
var remainingFilament = spoolItem.remainingWeight;
if (remainingFilament && displayName.trim().length != 0){
remainingFilament = " (" + remainingFilament + "%)" ;
} else {
remainingFilament = "";
}

var label = color + " - " + material + " - " + displayName + remainingFilament;
return label
}

Expand Down Expand Up @@ -239,15 +246,24 @@ $(function() {
}
return;
}
if ("noSpoolForUsageCheck" == result){
self.showPopUp("Error", "", "No Spool selected for usage check. Select a spool first");
return
}
// Not needed because a length check is only done, if spool was selected
// if ("noSpoolForUsageCheck" == result){
// self.showPopUp("Error", "", "No Spool selected for usage check. Select a spool first");
// return;
// }
if ("filamentNotEnough" == result){
var check = confirm('Not enough filament. Do you want to start the print anyway?');
if (check == true) {
startPrint();
}
return;
}
if ("reminderSpoolSelection" == result){
var question = "Please verify your selected Spool '"+responseData.spoolName+"'. Do you want to start the print anyway?";
var check = confirm(question);
if (check == true) {
startPrint();
}
}
}
});
Expand Down
7 changes: 7 additions & 0 deletions octoprint_SpoolManager/templates/SpoolManager_settings.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
<!-- GENERAL - TAB -->
<div class="tab-pane active" id="tab-spool-General">

<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: pluginSettings.reminderSelectingSpool" > Reminder for verifying the selected spool.
</label>
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
</div>
</div>
<div class="control-group no-bottom-gap">
<label class="control-label">Density <sup>2</sup></label>
<label class="control-label">Density <sup>2,3</sup></label>
<div class="controls">
<div class="input-append">
<input type="text" class="input-small text-right" data-bind="value: spoolDialog.spoolItemForEditing.density" />
Expand Down Expand Up @@ -238,8 +238,10 @@
-->
<div class="control-group" style="margin-bottom: -20px;">
<label class="">
<div><sup>1</sup><small>Mandatory field</small></label></div>
<div><sup>1</sup><small>Mandatory field</small></div>
<div><sup>2</sup><small>Needed for filament usage prediction</small></div>
<div><sup>3</sup><small>See <a href="https://bitfab.io/blog/3d-printing-materials-densities/" target="newTab">https://bitfab.io/blog/3d-printing-materials-densities/ (without warranty)</a></small></div>
</label>
</div>

</div>
Expand Down Expand Up @@ -278,7 +280,7 @@
<div class="input-append">
<input type="text" class="input-small text-right" data-bind="value: spoolDialog.spoolItemForEditing.cost"/>
<!-- <input type="text" class="input-mini text-right" data-bind="value: spoolDialog.spoolItemForEditing.costUnit" />-->
<span class="add-on"data-bind="text: spoolDialog.spoolItemForEditing.costUnit" >€</span>
<span class="add-on" data-bind="text: spoolDialog.spoolItemForEditing.costUnit" >€</span>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 3d4cc49

Please sign in to comment.