forked from 5axes/Calibration-Shapes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalibrationShapesReborn.py
534 lines (429 loc) · 27.8 KB
/
CalibrationShapesReborn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
# Part of initial code by fieldOfView 2018
# Based on Calibration Shapes by 5@xes 2020-2022
# Reborn edition by Slashee the Cow 2025-
# Version history (Reborn)
# 1.0.0: Initial release.
# - Rebranded.
# - Removed towers and tests that require use of post-processing scripts
# AutoTowers Generator does them so much better and asking the user to add a script is a pain.
# - Removed support for Cura versions below 5.0 to get rid of legacy code.
# 1.0.1:
# - Replaced "default size" settings box with something you wouldn't be afraid to take how to meet your parents for the first time.
# - This will have definitely broken the existing translations so they have been removed. If you're happy to help translate this, I'm happier to have you help!
# - Removed some more old, dead code.
# - Fixed a couple of typos in code that didn't affect functionality but bugged me.
# - Fixed a couple of typos in original code that would affect functionality.
# Imports from the python standard library to build the plugin functionality
import os
import sys
import math
import numpy
import trimesh
from typing import Optional, List
from UM.Extension import Extension
from UM.Application import Application
from cura.CuraApplication import CuraApplication
from UM.Mesh.MeshData import MeshData, calculateNormalsFromIndexedVertices
from UM.Resources import Resources
from UM.Settings.SettingInstance import SettingInstance
from cura.Scene.CuraSceneNode import CuraSceneNode
from UM.Scene.SceneNode import SceneNode
from UM.Scene.Selection import Selection
from UM.Scene.SceneNodeSettings import SceneNodeSettings
from cura.Scene.SliceableObjectDecorator import SliceableObjectDecorator
from cura.Scene.BuildPlateDecorator import BuildPlateDecorator
from UM.Operations.AddSceneNodeOperation import AddSceneNodeOperation
from UM.Operations.RemoveSceneNodeOperation import RemoveSceneNodeOperation
from UM.Operations.SetTransformOperation import SetTransformOperation
from UM.Logger import Logger
from UM.Message import Message
from UM.i18n import i18nCatalog
from PyQt6.QtCore import QObject, pyqtSlot, pyqtSignal, pyqtProperty
i18n_cura_catalog = i18nCatalog("cura")
i18n_catalog = i18nCatalog("fdmprinter.def.json")
i18n_extrud_catalog = i18nCatalog("fdmextruder.def.json")
# Suggested solution from fieldOfView . in this discussion solved in Cura 4.9
# https://github.com/5axes/Calibration-Shapes/issues/1
# Cura are able to find the scripts from inside the plugin folder if the scripts are into a folder named resources
Resources.addSearchPath(
os.path.join(os.path.abspath(os.path.dirname(__file__)),'resources')
) # Plugin translation file import
catalog = i18nCatalog("calibrationshapesreborn")
if catalog.hasTranslationLoaded():
Logger.log("i", "Calibration Shapes Reborn Plugin translation loaded!")
#This class is the extension and doubles as QObject to manage the qml
class CalibrationShapesReborn(QObject, Extension):
def __init__(self, parent = None) -> None:
super().__init__()
# set the preferences to store the default value
self._preferences = CuraApplication.getInstance().getPreferences()
self._preferences.addPreference("calibrationshapesreborn/shapesize", 20)
self._shape_size = float(self._preferences.getValue("calibrationshapesreborn/shapesize"))
self._settings_popup = None
# self._settings_qml = os.path.join(os.path.dirname(os.path.abspath(__file__)), "qml", "settings.qml")
self._settings_qml = os.path.abspath(os.path.join(os.path.dirname(__file__), "qml", "settings.qml"))
self._controller = CuraApplication.getInstance().getController()
self.setMenuName(catalog.i18nc("@item:inmenu", "Calibration Shapes"))
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a cube"), self.addCube)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a cylinder"), self.addCylinder)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a sphere"), self.addSphere)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a tube"), self.addTube)
self.addMenuItem("", lambda: None)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a Calibration Cube"), self.addCalibrationCube)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a Layer Adhesion Test"), self.addLayerAdhesion)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a Retract Test"), self.addRetractTest)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a XY Calibration Test"), self.addXYCalibration)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a Dimensional Accuracy Test"), self.addDimensionalTest)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a Tolerance Test"), self.addTolerance)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a Hole Test"), self.addHoleTest)
# self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a Junction Deviation Tower"), self.addJunctionDeviationTower)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a Bridge Test"), self.addBridgeTest)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a Thin Wall Test"), self.addThinWall)
# self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a Thin Wall Test Cura 5.0"), self.addThinWall2)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add an Overhang Test"), self.addOverhangTest)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a Flow Test"), self.addFlowTest)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a Support Test"), self.addSupportTest)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a Lithophane Test"), self.addLithophaneTest)
# self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a MultiCube Calibration"), self.addMultiCube)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a Bed Level Calibration"), self.addBedLevelCalibration)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a Backlash Test"), self.addBacklashTest)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a Linear/Pressure Adv Tower"), self.addPressureAdvTower)
self.addMenuItem(" ", lambda: None)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a Cube bi-color"), self.addCubeBiColor)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add a Bi-Color Calibration Cube"), self.addHollowCalibrationCube)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Add an Extruder Offset Calibration Part"), self.addExtruderOffsetCalibration)
self.addMenuItem(" ", lambda: None)
self.addMenuItem(catalog.i18nc("@item:inmenu", "Set default size"), self.showSettingsPopup)
# Define the default value for the standard element
def showSettingsPopup(self):
if self._settings_popup is None:
self._createSettingsPopup()
self._settings_popup.show()
def _createSettingsPopup(self):
#qml_file_path = os.path.join(os.path.dirname(__file__), "qml", "settings.qml")
self._settings_popup = CuraApplication.getInstance().createQmlComponent(self._settings_qml, {"manager": self})
_shape_size_changed = pyqtSignal()
@pyqtSlot(int)
def SetShapeSize(self, value: int) -> None:
#Logger.log("d", f"Attempting to set ShapeSize from pyqtProperty: {value}")
self._preferences.setValue("calibrationshapesreborn/shapesize", value)
self._shape_size = value
self._shape_size_changed.emit()
@pyqtProperty(int, notify = _shape_size_changed)
def ShapeSize(self) -> int:
#Logger.log("d", f"ShapeSize pyqtProperty accessed: {self._shape_size}, cast to {int(self._shape_size)}")
return int(self._shape_size)
def addBedLevelCalibration(self) -> None:
# Get the build plate Size
machine_manager = CuraApplication.getInstance().getMachineManager()
stack = CuraApplication.getInstance().getGlobalContainerStack()
global_stack = machine_manager.activeMachine
m_w=global_stack.getProperty("machine_width", "value")
m_d=global_stack.getProperty("machine_depth", "value")
if (m_w/m_d)>1.15 or (m_d/m_w)>1.15:
factor_w=round((m_w/100), 1)
factor_d=round((m_d/100), 1)
else:
factor_w=int(m_w/100)
factor_d=int(m_d/100)
# Logger.log("d", "factor_w= %.1f", factor_w)
# Logger.log("d", "factor_d= %.1f", factor_d)
model_definition_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "models", "ParametricBedLevel.stl")
mesh = trimesh.load(model_definition_path)
origin = [0, 0, 0]
DirX = [1, 0, 0]
DirY = [0, 1, 0]
# DirZ = [0, 0, 1]
mesh.apply_transform(trimesh.transformations.scale_matrix(factor_w, origin, DirX))
mesh.apply_transform(trimesh.transformations.scale_matrix(factor_d, origin, DirY))
# addShape
self._addShape("BedLevelCalibration",self._toMeshData(mesh))
def _registerShapeStl(self, mesh_name, mesh_filename=None, **kwargs) -> None:
if mesh_filename is None:
mesh_filename = mesh_name + ".stl"
model_definition_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "models", mesh_filename)
mesh = trimesh.load(model_definition_path)
# addShape
self._addShape(mesh_name,self._toMeshData(mesh), **kwargs)
# Source code from MeshTools Plugin
# Copyright (c) 2020 Aldo Hoeben / fieldOfView
def _getAllSelectedNodes(self) -> List[SceneNode]:
selection = Selection.getAllSelectedObjects()[:]
if selection:
deep_selection = [] # type: List[SceneNode]
for selected_node in selection:
if selected_node.hasChildren():
deep_selection = deep_selection + selected_node.getAllChildren()
if selected_node.getMeshData() != None:
deep_selection.append(selected_node)
if deep_selection:
return deep_selection
Message(catalog.i18nc("@info:status", "Please select one or more models first"))
return []
def addCalibrationCube(self) -> None:
self._registerShapeStl("CalibrationCube")
def addMultiCube(self) -> None:
self._registerShapeStl("MultiCube")
def addJunctionDeviationTower(self) -> None:
self._registerShapeStl("JunctionDeviationTower")
def addRetractTest(self) -> None:
self._registerShapeStl("RetractTest")
def addLayerAdhesion(self) -> None:
self._registerShapeStl("LayerAdhesion")
def addXYCalibration(self) -> None:
self._registerShapeStl("xy_calibration")
def addBridgeTest(self) -> None:
self._registerShapeStl("BridgeTest")
def addThinWall(self) -> None:
self._registerShapeStl("ThinWall")
def addThinWall2(self) -> None:
self._registerShapeStl("ThinWallRought")
def addBacklashTest(self) -> None:
self._registerShapeStl("Backlash")
def addOverhangTest(self) -> None:
self._registerShapeStl("OverhangTest", "Overhang.stl")
def addFlowTest(self) -> None:
self._registerShapeStl("FlowTest", "FlowTest.stl")
def addHoleTest(self) -> None:
self._registerShapeStl("FlowTest", "HoleTest.stl")
def addTolerance(self) -> None:
self._registerShapeStl("Tolerance")
def addLithophaneTest(self) -> None:
self._registerShapeStl("Lithophane")
# Dotdash addition 2 - Support test
def addSupportTest(self) -> None:
self._registerShapeStl("SupportTest")
# Dimensional Accuracy Test
def addDimensionalTest(self) -> None:
self._registerShapeStl("DimensionalAccuracyTest")
# Dotdash addition - for Linear/Pressure advance
def addPressureAdvTower(self) -> None:
self._registerShapeStl("PressureAdv", "PressureAdvTower.stl")
#-----------------------------
# Dual Extruder
#-----------------------------
def addCubeBiColor(self) -> None:
self._registerShapeStl("CubeBiColorExt1", "CubeBiColorWhite.stl", ext_pos=1)
self._registerShapeStl("CubeBiColorExt2", "CubeBiColorRed.stl", ext_pos=2)
def addHollowCalibrationCube(self) -> None:
self._registerShapeStl("CubeBiColorExt", "HollowCalibrationCube.stl", ext_pos=1)
self._registerShapeStl("CubeBiColorInt", "HollowCenterCube.stl", ext_pos=2)
def addExtruderOffsetCalibration(self) -> None:
self._registerShapeStl("CalibrationMultiExtruder1", "nozzle-to-nozzle-xy-offset-calibration-pattern-a.stl", ext_pos=1)
self._registerShapeStl("CalibrationMultiExtruder1", "nozzle-to-nozzle-xy-offset-calibration-pattern-b.stl", ext_pos=2)
#-----------------------------
# Standard Geometry
#-----------------------------
# Origin, xaxis, yaxis, zaxis = [0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]
# S = trimesh.transformations.scale_matrix(20, origin)
# xaxis = [1, 0, 0]
# Rx = trimesh.transformations.rotation_matrix(math.radians(90), xaxis)
def addCube(self) -> None:
Tz = trimesh.transformations.translation_matrix([0, 0, self._shape_size*0.5])
self._addShape("Cube",self._toMeshData(trimesh.creation.box(extents = [self._shape_size, self._shape_size, self._shape_size], transform = Tz )))
def addCylinder(self) -> None:
mesh = trimesh.creation.cylinder(radius = self._shape_size / 2, height = self._shape_size, sections=90)
mesh.apply_transform(trimesh.transformations.translation_matrix([0, 0, self._shape_size*0.5]))
self._addShape("Cylinder",self._toMeshData(mesh))
def addTube(self) -> None:
mesh = trimesh.creation.annulus(r_min = self._shape_size / 4, r_max = self._shape_size / 2, height = self._shape_size, sections = 90)
mesh.apply_transform(trimesh.transformations.translation_matrix([0, 0, self._shape_size*0.5]))
self._addShape("Tube",self._toMeshData(mesh))
# Sphere are not very usefull but I leave it for the moment
def addSphere(self) -> None:
# subdivisions (int) – How many times to subdivide the mesh. Note that the number of faces will grow as function of 4 ** subdivisions, so you probably want to keep this under ~5
mesh = trimesh.creation.icosphere(subdivisions=4,radius = self._shape_size / 2,)
mesh.apply_transform(trimesh.transformations.translation_matrix([0, 0, self._shape_size*0.5]))
self._addShape("Sphere",self._toMeshData(mesh))
#----------------------------------------------------------
# Check retraction_enable must be True
#----------------------------------------------------------
def _checkRetract(self, val):
# Logger.log("d", "In checkRetract = %s", str(val))
global_container_stack = CuraApplication.getInstance().getGlobalContainerStack()
extruder = global_container_stack.extruderList[0]
extruder_stack = CuraApplication.getInstance().getExtruderManager().getActiveExtruderStacks()[0]
retraction_e = float(extruder.getProperty("retraction_enable", "value"))
if retraction_e != val :
key="retraction_enable"
definition_key=key + " label"
untranslated_label=extruder_stack.getProperty(key,"label")
translated_label=i18n_catalog.i18nc(definition_key, untranslated_label)
Message(text = catalog.i18nc("@info:label","! Modification ! in the current profile of : ") + translated_label + catalog.i18nc("@info:label","\nNew value :") + " %s" % (str(val)), title = catalog.i18nc("@info:title", "Warning ! Calibration Shapes"), message_type = Message.MessageType.WARNING).show()
# Define retraction_enable
extruder.setProperty("retraction_enable", "value", True)
retraction_amount = extruder.getProperty("retraction_amount", "value")
Logger.log("d", "In checkRetract retraction_amount = %s", str(retraction_amount))
if (retraction_amount == 0) :
key="retraction_amount"
definition_key=key + " label"
untranslated_label=extruder_stack.getProperty(key,"label")
translated_label=i18n_catalog.i18nc(definition_key, untranslated_label)
Message(text = catalog.i18nc("@info:label", "! Modification ! in the current profile of : ") + translated_label + catalog.i18nc("@info:label","\nNew value :") + " %s" % (str(1.0)), title = catalog.i18nc("@info:title", "Warning ! Calibration Shapes"), message_type = Message.MessageType.WARNING).show()
# Define retraction_amount
extruder.setProperty("retraction_amount", "value", 1.0)
#----------------------------------------------------------
# Check adaptive_layer_height_enabled must be False
#----------------------------------------------------------
def _checkAdaptativ(self, val):
# Logger.log("d", "In checkAdaptativ = %s", str(val))
# Fix some settings in Cura to get a better result
global_container_stack = CuraApplication.getInstance().getGlobalContainerStack()
extruder_stack = CuraApplication.getInstance().getExtruderManager().getActiveExtruderStacks()[0]
adaptive_layer = global_container_stack.getProperty("adaptive_layer_height_enabled", "value")
extruder = global_container_stack.extruderList[0]
if adaptive_layer != val :
key="adaptive_layer_height_enabled"
definition_key=key + " label"
untranslated_label=extruder_stack.getProperty(key,"label")
translated_label=i18n_catalog.i18nc(definition_key, untranslated_label)
Message(text = catalog.i18nc("@info:label", "! Modification ! in the current profile of : ") + translated_label + catalog.i18nc("@info:label","\nNew value :") + " %s" % (str(val)), title = catalog.i18nc("@info:title", "Warning ! Calibration Shapes"), message_type = Message.MessageType.WARNING).show()
# Define adaptive_layer
global_container_stack.setProperty("adaptive_layer_height_enabled", "value", False)
#--------------------------------------------------------------------------
# Check meshfix_union_all_remove_holes Set to true if nozzle_size > 0.4
#--------------------------------------------------------------------------
def _checkAllRemoveHoles(self, val)-> bool:
global_container_stack = CuraApplication.getInstance().getGlobalContainerStack()
extruder_stack = CuraApplication.getInstance().getExtruderManager().getActiveExtruderStacks()[0]
extruder = global_container_stack.extruderList[0]
_Remove = False
nozzle_size = float(extruder.getProperty("machine_nozzle_size", "value"))
remove_holes = extruder.getProperty("meshfix_union_all_remove_holes", "value")
# Logger.log("d", "In checkAdaptativ nozzle_size = %s", str(nozzle_size))
# Logger.log("d", "In checkAdaptativ remove_holes = %s", str(remove_holes))
if (nozzle_size > 0.4) and (remove_holes == False) :
_Remove = True
key="meshfix_union_all_remove_holes"
definition_key=key + " label"
untranslated_label=extruder_stack.getProperty(key,"label")
translated_label=i18n_catalog.i18nc(definition_key, untranslated_label)
Message(text = catalog.i18nc("@info:label","Individual definition for the calibration part of : ") + translated_label + catalog.i18nc("@info:label","\n(machine_nozzle_size>0.4)\nSet value :") + " %s" % (str(True)), title = catalog.i18nc("@info:title", "Information ! Calibration Shapes"), message_type = Message.MessageType.POSITIVE).show()
# Define adaptive_layer
# extruder.setProperty("meshfix_union_all_remove_holes", "value", True)
return _Remove
#--------------------------------------------------------------
# Check fill_outline_gaps (Print Thin Walls V5.0) must be True
#--------------------------------------------------------------
def _checkThinWalls(self, val)-> bool:
# Logger.log("d", "In checkThinWalls = %s", str(val))
# Fix some settings in Cura to get a better result
global_container_stack = CuraApplication.getInstance().getGlobalContainerStack()
extruder_stack = CuraApplication.getInstance().getExtruderManager().getActiveExtruderStacks()[0]
thin_wall = global_container_stack.getProperty("fill_outline_gaps", "value")
if thin_wall != val :
key="fill_outline_gaps"
definition_key=key + " label"
untranslated_label=extruder_stack.getProperty(key,"label")
translated_label=i18n_catalog.i18nc(definition_key, untranslated_label)
Message(text = catalog.i18nc("@info:label","Individual definition for the calibration part of : ") + translated_label + catalog.i18nc("@info:label","\nSet value :") + " %s" % (str(val)), title = catalog.i18nc("@info:title", "Information ! Calibration Shapes"), message_type = Message.MessageType.POSITIVE).show()
thin_wall = val
# global_container_stack.setProperty("fill_outline_gaps", "value", val)
return thin_wall
#----------------------------------------------------------
# Check fill_perimeter_gaps (Fill Gaps Between Walls) must be "nowhere"
#----------------------------------------------------------
def _checkFill_Perimeter_Gaps(self, val):
# Logger.log("d", "In checkAdaptativ = %s", str(val))
# Fix some settings in Cura to get a better result
global_container_stack = CuraApplication.getInstance().getGlobalContainerStack()
extruder_stack = CuraApplication.getInstance().getExtruderManager().getActiveExtruderStacks()[0]
fill_perimeter_gaps = global_container_stack.getProperty("fill_perimeter_gaps", "value")
if fill_perimeter_gaps != val :
key="fill_perimeter_gaps"
definition_key=key + " label"
untranslated_label=extruder_stack.getProperty(key,"label")
translated_label=i18n_catalog.i18nc(definition_key, untranslated_label)
Message(text = catalog.i18nc("@info:label","! Modification ! in the current profile of : ") + translated_label + catalog.i18nc("@info:label","\nNew value :") + " %s" % (str(val)), title = catalog.i18nc("@info:title", "Warning ! Calibration Shapes"), message_type = Message.MessageType.WARNING).show()
# Define adaptive_layer
global_container_stack.setProperty("fill_perimeter_gaps", "value", val)
extruder = global_container_stack.extruderList[0]
fill_perimeter_gaps = extruder.getProperty("fill_perimeter_gaps", "value")
if fill_perimeter_gaps != val :
Message(text = catalog.i18nc("@info:label","! Modification ! for the extruder definition of : ") + translated_label + catalog.i18nc("@info:label","\nNew value :") + " %s" % (str(val)), title = catalog.i18nc("@info:title", "Warning ! Calibration Shapes"), message_type = Message.MessageType.WARNING).show()
# Define adaptive_layer
extruder.setProperty("fill_perimeter_gaps", "value", val)
#----------------------------------------
# Initial Source code from fieldOfView
#----------------------------------------
def _toMeshData(self, tri_node: trimesh.base.Trimesh) -> MeshData:
# Rotate the part to laydown on the build plate
# Modification from 5@xes
tri_node.apply_transform(trimesh.transformations.rotation_matrix(math.radians(90), [-1, 0, 0]))
tri_faces = tri_node.faces
tri_vertices = tri_node.vertices
# Following Source code from fieldOfView
# https://github.com/fieldOfView/Cura-SimpleShapes/blob/bac9133a2ddfbf1ca6a3c27aca1cfdd26e847221/SimpleShapes.py#L45
indices = []
vertices = []
index_count = 0
face_count = 0
for tri_face in tri_faces:
face = []
for tri_index in tri_face:
vertices.append(tri_vertices[tri_index])
face.append(index_count)
index_count += 1
indices.append(face)
face_count += 1
vertices = numpy.asarray(vertices, dtype=numpy.float32)
indices = numpy.asarray(indices, dtype=numpy.int32)
normals = calculateNormalsFromIndexedVertices(vertices, indices, face_count)
mesh_data = MeshData(vertices=vertices, indices=indices, normals=normals)
return mesh_data
# Initial Source code from fieldOfView
# https://github.com/fieldOfView/Cura-SimpleShapes/blob/bac9133a2ddfbf1ca6a3c27aca1cfdd26e847221/SimpleShapes.py#L70
def _addShape(self, mesh_name, mesh_data: MeshData, ext_pos = 0 , hole = False , thin = False , mode = "" ) -> None:
application = CuraApplication.getInstance()
global_stack = application.getGlobalContainerStack()
if not global_stack:
return
node = CuraSceneNode()
node.setMeshData(mesh_data)
node.setSelectable(True)
if len(mesh_name)==0:
node.setName("TestPart" + str(id(mesh_data)))
else:
node.setName(str(mesh_name))
scene = self._controller.getScene()
op = AddSceneNodeOperation(node, scene.getRoot())
op.push()
extruder_stack = application.getExtruderManager().getActiveExtruderStacks()
extruder_nr=len(extruder_stack)
# Logger.log("d", "extruder_nr= %d", extruder_nr)
# default_extruder_position : <class 'str'>
if ext_pos>0 and ext_pos<=extruder_nr :
default_extruder_position = int(ext_pos-1)
else :
default_extruder_position = int(application.getMachineManager().defaultExtruderPosition)
# Logger.log("d", "default_extruder_position= %s", type(default_extruder_position))
default_extruder_id = extruder_stack[default_extruder_position].getId()
# Logger.log("d", "default_extruder_id= %s", default_extruder_id)
node.callDecoration("setActiveExtruder", default_extruder_id)
stack = node.callDecoration("getStack") # created by SettingOverrideDecorator that is automatically added to CuraSceneNode
settings = stack.getTop()
# Remove All Holes
if hole :
definition = stack.getSettingDefinition("meshfix_union_all_remove_holes")
new_instance = SettingInstance(definition, settings)
new_instance.setProperty("value", True)
new_instance.resetState() # Ensure that the state is not seen as a user state.
settings.addInstance(new_instance)
# Print Thin Walls
if thin :
definition = stack.getSettingDefinition("fill_outline_gaps")
new_instance = SettingInstance(definition, settings)
new_instance.setProperty("value", True)
new_instance.resetState() # Ensure that the state is not seen as a user state.
settings.addInstance(new_instance)
if len(mode) :
definition = stack.getSettingDefinition("magic_mesh_surface_mode")
new_instance = SettingInstance(definition, settings)
new_instance.setProperty("value", mode)
new_instance.resetState() # Ensure that the state is not seen as a user state.
settings.addInstance(new_instance)
node.setSetting(SceneNodeSettings.AutoDropDown, True)
active_build_plate = application.getMultiBuildPlateModel().activeBuildPlate
node.addDecorator(BuildPlateDecorator(active_build_plate))
node.addDecorator(SliceableObjectDecorator())
application.getController().getScene().sceneChanged.emit(node)