-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SW-3809 - Backend- Select materials csv based on laser cutter mode (#…
…1815) * Select materials csv based on laser cutter mode * Rework custom materials logic * Add unit tests * Pass laser cutter mode to materials * Update octoprint_mrbeam/util/material_csv_parser.py Co-authored-by: khaledsherkawi <[email protected]> * Update octoprint_mrbeam/util/material_csv_parser.py Co-authored-by: khaledsherkawi <[email protected]> * Update octoprint_mrbeam/materials.py Co-authored-by: khaledsherkawi <[email protected]> * Improve method name * Add test for empty custom materials --------- Co-authored-by: khaledsherkawi <[email protected]>
- Loading branch information
1 parent
0d88f51
commit db245dc
Showing
9 changed files
with
375 additions
and
240 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
octoprint_mrbeam/files/material_settings/materials_rotary.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Laserhead,Material,Color,Thickness,Intensity,Speed,Passes,Compressor,Piercing time,Dithering,Comments | ||
You can drag the cell to fill a range with the same name,Color codes take a long time to update -->,"Use ""fill color"" tool",Engrave or (mm),light-dark (%),light-dark 0 to 1500,,level 0 to 3,(ms),yes/no,"interpolated value or #madewithmrbeam? Let us know what makes you tick | ||
" | ||
Mr Beam II,Bamboo,#e7c982,Engrave,0-100,1500-450,1,0,0,no,values from default material settings | ||
Mr Beam II,Cork,#c19c73,Engrave,0-30,1500-1400,1,0,0,no,values from default material settings | ||
,,,,,,,,,, | ||
,DREAMCUT,,,,,,,,, | ||
MrB II Dreamcut,Bamboo,#e7c982,Engrave,0-50,1500-1500,1,3,0,no,values from default material settings | ||
MrB II Dreamcut,Cork,#c19c73,Engrave,0-30,1500-1500,1,3,0,no,values from default material settings | ||
,,,,,,,,,, | ||
,DREAMCUT S,,,,,,,,, | ||
MrB II Dreamcut S,Bamboo,#e7c982,Engrave,0-50,2000-2000,1,3,0,no,values from default material settings | ||
MrB II Dreamcut S,Cork,#c19c73,Engrave,0-15,1500-1500,1,3,0,no,values from default material settings | ||
,,,,,,,,,, | ||
,DREAMCUT X,,,,,,,,, | ||
MrB II Dreamcut x,Bamboo,#e7c982,Engrave,0-30,2000-2000,1,3,0,no,values from default material settings | ||
MrB II Dreamcut x,Cork,#c19c73,Engrave,0-14,2000-2000,1,3,0,no,values from default material settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
class CustomMaterialModel: | ||
def __init__(self, material_key, material, laser_cutter_mode, laser_model, plugin_v, device_model): | ||
self.colors = material.get("colors", []) | ||
self.custom = True | ||
self.description = material.get("description", "") | ||
self.device_model = device_model | ||
self.hints = material.get("hints", "") | ||
self.img = material.get("img", "null") | ||
self.laser_cutter_mode = laser_cutter_mode | ||
self.laser_model = laser_model | ||
self.name = material.get("name") | ||
self.safety_notes = material.get("safety_notes", "") | ||
self.v = plugin_v | ||
|
||
self.material_key = self.generate_material_key(material_key) | ||
|
||
def __str__(self): | ||
return "CustomMaterialModel(name='{0}', description='{1}')".format(self.name, self.description) | ||
|
||
def __repr__(self): | ||
return ( | ||
"CustomMaterialModel(" | ||
"key='{0}', " | ||
"colors={1}, " | ||
"custom={2}, " | ||
"description='{3}', " | ||
"device_model='{4}', " | ||
"hints='{5}', " | ||
"img='{6}', " | ||
"laser_cutter_mode='{7}', " | ||
"laser_model='{8}', " | ||
"name='{9}', " | ||
"safety_notes='{10}', " | ||
"v={11})" | ||
.format( | ||
self.material_key, | ||
self.colors, | ||
self.custom, | ||
self.description, | ||
self.device_model, | ||
self.hints, | ||
self.img, | ||
self.laser_cutter_mode, | ||
self.laser_model, | ||
self.name, | ||
self.safety_notes, | ||
self.v | ||
) | ||
) | ||
|
||
def to_dict(self): | ||
material = vars(self) | ||
return material | ||
|
||
def generate_material_key(self, material_key): | ||
return "{} - {}".format(material_key, self.laser_cutter_mode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import pytest | ||
|
||
from octoprint_mrbeam.model.custom_material_model import CustomMaterialModel | ||
|
||
|
||
@pytest.fixture | ||
def sample_custom_material(): | ||
sample_material_data = { | ||
"name": "Sample Material", | ||
"description": "This is a test material", | ||
"colors": ["red", "green", "blue"], | ||
"hints": "Some hints", | ||
"img": "sample.jpg", | ||
"laser_cutter_mode": "default", | ||
"laser_model": "sample_model", | ||
"safety_notes": "Safety notes for testing", | ||
"plugin_v": "1.0", | ||
"device_model": "Device123", | ||
} | ||
|
||
custom_material = CustomMaterialModel("sample_key", sample_material_data, "default", "X", "1.0", "dreamcut") | ||
|
||
yield custom_material | ||
|
||
|
||
def test_material_key_generation(sample_custom_material): | ||
assert sample_custom_material.material_key == "sample_key - default" | ||
|
||
|
||
def test_to_dict(sample_custom_material): | ||
material_dict = sample_custom_material.to_dict() | ||
expected_dict = {'laser_cutter_mode': 'default', 'safety_notes': 'Safety notes for testing', 'description': 'This is a test material', 'img': 'sample.jpg', 'device_model': 'dreamcut', 'name': 'Sample Material', 'custom': True, 'laser_model': 'X', 'colors': ['red', 'green', 'blue'], 'v': '1.0', 'material_key': 'sample_key - default', 'hints': 'Some hints'} | ||
|
||
assert material_dict == expected_dict |
Oops, something went wrong.