- refactored the is_legacy object to use_3d_engine

- made sure that there is no longer a double action when toggling the object visibility ('plot' attribute)
This commit is contained in:
Marius Stanciu
2021-10-31 14:05:00 +02:00
committed by Marius
parent 25bca44996
commit bb089eb657
34 changed files with 321 additions and 366 deletions

View File

@@ -154,7 +154,7 @@ class CNCJobObject(FlatCAMObj, CNCjob):
gcodenr_re_string = r'([+-]?\d*\.\d+)'
self.g_nr_re = re.compile(gcodenr_re_string)
if self.app.is_legacy is False:
if self.app.use_3d_engine:
self.text_col = self.app.plotcanvas.new_text_collection()
self.text_col.enabled = True
self.annotation = self.app.plotcanvas.new_text_group(collection=self.text_col)
@@ -1348,19 +1348,19 @@ class CNCJobObject(FlatCAMObj, CNCjob):
self.shapes.redraw()
except (ObjectDeleted, AttributeError):
self.shapes.clear(update=True)
if self.app.is_legacy is False:
if self.app.use_3d_engine:
self.annotation.clear(update=True)
# Annotations shapes plotting
try:
if self.app.is_legacy is False:
if self.app.use_3d_engine:
if self.ui.annotation_cb.get_value() and visible:
self.plot_annotations(obj=self, visible=True)
else:
self.plot_annotations(obj=self, visible=False)
except (ObjectDeleted, AttributeError):
if self.app.is_legacy is False:
if self.app.use_3d_engine:
self.annotation.clear(update=True)
def on_annotation_change(self, val):
@@ -1369,19 +1369,17 @@ class CNCJobObject(FlatCAMObj, CNCjob):
:return:
"""
if self.app.is_legacy is False:
# self.text_col.visible = True if val == 2 else False
# self.plot(kind=self.ui.cncplot_method_combo.get_value())
if self.app.use_3d_engine:
# Annotations shapes plotting
try:
if self.app.is_legacy is False:
if self.app.use_3d_engine:
if val and self.ui.plot_cb.get_value():
self.plot_annotations(obj=self, visible=True)
else:
self.plot_annotations(obj=self, visible=False)
except (ObjectDeleted, AttributeError):
if self.app.is_legacy is False:
if self.app.use_3d_engine:
self.annotation.clear(update=True)
# self.annotation.redraw()

View File

@@ -1197,7 +1197,7 @@ class ExcellonObject(FlatCAMObj, Excellon):
if not FlatCAMObj.plot(self):
return
if self.app.is_legacy is False:
if self.app.use_3d_engine:
def random_color():
r_color = np.random.rand(4)
r_color[3] = 1

View File

@@ -1369,7 +1369,7 @@ class GeometryObject(FlatCAMObj, Geometry):
for sub_el in element:
self.plot_element(sub_el, color=color)
except TypeError: # Element is not iterable...
# if self.app.is_legacy is False:
# if self.app.use_3d_engine:
self.add_shape(shape=element, color=color, visible=visible, layer=0)
def plot(self, visible=None, kind=None, plot_tool=None):
@@ -1389,7 +1389,7 @@ class GeometryObject(FlatCAMObj, Geometry):
if not FlatCAMObj.plot(self):
return
if self.app.is_legacy is False:
if self.app.use_3d_engine:
def random_color():
r_color = np.random.rand(4)
r_color[3] = 1
@@ -1452,6 +1452,7 @@ class GeometryObject(FlatCAMObj, Geometry):
def on_plot_cb_click(self):
if self.muted_ui:
return
self.read_form_item('plot')
self.plot()

View File

@@ -915,7 +915,7 @@ class GerberObject(FlatCAMObj, Gerber):
else:
geometry = self.solid_geometry
if self.app.is_legacy is False:
if self.app.use_3d_engine:
def random_color():
r_color = np.random.rand(4)
r_color[3] = 1
@@ -976,7 +976,7 @@ class GerberObject(FlatCAMObj, Gerber):
:return:
"""
log.debug(str(inspect.stack()[1][3]) + " --> GerberObject.plot_aperture()")
# log.debug(str(inspect.stack()[1][3]) + " --> GerberObject.plot_aperture()")
# Does all the required setup and returns False
# if the 'ptint' option is set to False.
@@ -1042,7 +1042,7 @@ class GerberObject(FlatCAMObj, Gerber):
if self.mark_shapes_storage:
if aperture == 'all':
val = False if self.app.is_legacy is True else True
val = True if self.app.use_3d_engine else False
self.mark_shapes.clear(update=val)
else:
for shape_key in self.mark_shapes_storage[aperture]:

View File

@@ -92,10 +92,9 @@ class FlatCAMObj(QtCore.QObject):
self.axes = None
self.kind = None # Override with proper name
if self.app.is_legacy is False:
if self.app.use_3d_engine:
self.shapes = self.app.plotcanvas.new_shape_group()
self.mark_shapes = ShapeCollection(parent=self.app.plotcanvas.view.scene, layers=1)
# self.shapes = ShapeCollection(parent=self.app.plotcanvas.view.scene, pool=self.app.pool, layers=2)
else:
self.shapes = ShapeCollectionLegacy(obj=self, app=self.app, name=name)
self.mark_shapes = ShapeCollectionLegacy(obj=self, app=self.app, name=name + "_mark_shapes")
@@ -161,12 +160,101 @@ class FlatCAMObj(QtCore.QObject):
# Update form on programmatically options change
self.set_form_item(key)
# Set object visibility
if key == 'plot':
# Set object visibility for objects that are edited
if key == 'plot' and self.app.call_source != 'app':
self.visible = self.options['plot']
self.optionChanged.emit(key)
def plot(self, kind=None):
"""
Plot this object (Extend this method to implement the actual plotting).
Call this in descendants before doing the plotting.
:param kind: Used by only some of the FlatCAM objects
:return: Whether to continue plotting or not depending on the "plot" option. Boolean
"""
# log.debug(str(inspect.stack()[1][3]) + " --> FlatCAMObj.plot()")
if self.deleted:
return False
self.clear()
return True
def single_object_plot(self):
def plot_task():
with self.app.proc_container.new('%s ...' % _("Plotting")):
self.plot()
self.app.app_obj.object_changed.emit(self)
self.app.worker_task.emit({'fcn': plot_task, 'params': []})
def add_shape(self, **kwargs):
tol = kwargs['tolerance'] if 'tolerance' in kwargs else self.drawing_tolerance
if self.deleted:
raise ObjectDeleted()
else:
key = self.shapes.add(tolerance=tol, **kwargs)
return key
def add_mark_shape(self, **kwargs):
tol = kwargs['tolerance'] if 'tolerance' in kwargs else self.drawing_tolerance
if self.deleted:
raise ObjectDeleted()
else:
key = self.mark_shapes.add(tolerance=tol, layer=0, **kwargs)
return key
@property
def visible(self):
'''
This property is used by Editors to turn off plotting for the original object that is edited,
such that when deleting certain elements there is no background plot in place to confuse things.
:return:
:rtype:
'''
return self.shapes.visible
@visible.setter
def visible(self, value, threaded=True):
log.debug("FlatCAMObj.visible()")
# self.shapes.enabled = not self.shapes.enabled
current_visibility = self.shapes.visible
self.shapes.visible = current_visibility # maybe this is slower in VisPy? use enabled property?
def task(visibility):
if visibility is True:
if value is False:
self.shapes.visible = False
else:
if value is True:
self.shapes.visible = True
if self.app.use_3d_engine:
# Not all object types has annotations
try:
self.annotation.visible = value
except Exception:
pass
if threaded:
self.app.worker_task.emit({'fcn': task, 'params': [current_visibility]})
else:
task(current_visibility)
def clear(self, update=False):
self.shapes.clear(update)
# Not all object types has annotations
try:
self.annotation.clear(update)
except Exception:
pass
def set_ui(self, ui):
self.ui = ui
@@ -372,30 +460,6 @@ class FlatCAMObj(QtCore.QObject):
pass
# self.app.log.warning("Failed to read option from field: %s" % option)
def plot(self, kind=None):
"""
Plot this object (Extend this method to implement the actual plotting).
Call this in descendants before doing the plotting.
:param kind: Used by only some of the FlatCAM objects
:return: Whether to continue plotting or not depending on the "plot" option. Boolean
"""
log.debug(str(inspect.stack()[1][3]) + " --> FlatCAMObj.plot()")
if self.deleted:
return False
self.clear()
return True
def single_object_plot(self):
def plot_task():
with self.app.proc_container.new('%s ...' % _("Plotting")):
self.plot()
self.app.app_obj.object_changed.emit(self)
self.app.worker_task.emit({'fcn': plot_task, 'params': []})
def serialize(self):
"""
Returns a representation of the object as a dictionary so
@@ -416,24 +480,6 @@ class FlatCAMObj(QtCore.QObject):
"""
return
def add_shape(self, **kwargs):
tol = kwargs['tolerance'] if 'tolerance' in kwargs else self.drawing_tolerance
if self.deleted:
raise ObjectDeleted()
else:
key = self.shapes.add(tolerance=tol, **kwargs)
return key
def add_mark_shape(self, **kwargs):
tol = kwargs['tolerance'] if 'tolerance' in kwargs else self.drawing_tolerance
if self.deleted:
raise ObjectDeleted()
else:
key = self.mark_shapes.add(tolerance=tol, layer=0, **kwargs)
return key
def update_filters(self, last_ext, filter_string):
"""
Will modify the filter string that is used when saving a file (a list of file extensions) to have the last
@@ -927,37 +973,6 @@ class FlatCAMObj(QtCore.QObject):
def poly2rings(poly):
return [poly.exterior] + [interior for interior in poly.interiors]
@property
def visible(self):
return self.shapes.visible
@visible.setter
def visible(self, value, threaded=True):
log.debug("FlatCAMObj.visible()")
current_visibility = self.shapes.visible
# self.shapes.visible = value # maybe this is slower in VisPy? use enabled property?
def task(visibility):
if visibility is True:
if value is False:
self.shapes.visible = False
else:
if value is True:
self.shapes.visible = True
if self.app.is_legacy is False:
# Not all object types has annotations
try:
self.annotation.visible = value
except Exception:
pass
if threaded:
self.app.worker_task.emit({'fcn': task, 'params': [current_visibility]})
else:
task(current_visibility)
@property
def drawing_tolerance(self):
self.units = self.app.app_units.upper()
@@ -969,15 +984,6 @@ class FlatCAMObj(QtCore.QObject):
self.units = self.app.app_units.upper()
self._drawing_tolerance = value if self.units == 'MM' or not self.units else value / 25.4
def clear(self, update=False):
self.shapes.clear(update)
# Not all object types has annotations
try:
self.annotation.clear(update)
except Exception:
pass
def delete(self):
# Free resources
del self.ui

View File

@@ -725,7 +725,7 @@ class ObjectCollection(QtCore.QAbstractItemModel):
self.endRemoveRows()
# ############ OBJECT DELETION FROM MODEL STOPS HERE ####################
if self.app.is_legacy is False:
if self.app.use_3d_engine:
self.app.plotcanvas.redraw()
if select_project:
@@ -778,7 +778,7 @@ class ObjectCollection(QtCore.QAbstractItemModel):
self.endRemoveRows()
# ############ OBJECT DELETION FROM MODEL STOPS HERE ####################
if self.app.is_legacy is False:
if self.app.use_3d_engine:
self.app.plotcanvas.redraw()
if select_project: