This commit is contained in:
Marius Stanciu
2018-05-30 17:54:34 +03:00
3 changed files with 41 additions and 15 deletions

View File

@@ -114,10 +114,10 @@ class App(QtCore.QObject):
plots_updated = QtCore.pyqtSignal()
# Emitted by new_object() and passes the new object as argument.
# on_object_created() adds the object to the collection,
# Emitted by new_object() and passes the new object as argument and a plot flag
# on_object_created() adds the object to the collection, plot the object if plot flag is True
# and emits new_object_available.
object_created = QtCore.pyqtSignal(object)
object_created = QtCore.pyqtSignal(object, bool)
# Emitted when a new object has been added to the collection
# and is ready to be used.
@@ -1023,9 +1023,12 @@ class App(QtCore.QObject):
but before it is attached to the application. The function is
called with 2 parameters: the new object and the App instance.
:type initialize: function
:param plot: Whether to plot the object or not
:type plot: Bool
:return: None
:rtype: None
"""
self.plot = plot
App.log.debug("new_object()")
@@ -1049,6 +1052,10 @@ class App(QtCore.QObject):
oname = option[len(kind) + 1:]
obj.options[oname] = self.options[option]
# make sure that the plot option of the new object is reflecting the current status and not the general option
# solve issues with the modelview currently used (checkbox on the Project Tab)
obj.options['plot'] = self.plot
# Initialize as per user request
# User must take care to implement initialize
# in a thread-safe way as is is likely that we
@@ -1071,7 +1078,7 @@ class App(QtCore.QObject):
# Move the object to the main thread and let the app know that it is available.
obj.moveToThread(QtGui.QApplication.instance().thread())
self.object_created.emit(obj)
self.object_created.emit(obj, self.plot)
return obj
@@ -1485,12 +1492,14 @@ class App(QtCore.QObject):
# Keep this for later
try:
name = self.collection.get_active().options["name"]
isPlotted = self.collection.get_active().options["plot"]
except AttributeError:
self.log.debug("Nothing selected for deletion")
return
# Remove plot
self.plotcanvas.figure.delaxes(self.collection.get_active().axes)
# Remove plot only if the object was plotted otherwise delaxes will fail
if isPlotted:
self.plotcanvas.figure.delaxes(self.collection.get_active().axes)
self.plotcanvas.auto_adjust_axes()
# Clear form
@@ -1532,11 +1541,12 @@ class App(QtCore.QObject):
def on_row_activated(self, index):
self.ui.notebook.setCurrentWidget(self.ui.selected_tab)
def on_object_created(self, obj):
def on_object_created(self, obj, plot):
"""
Event callback for object creation.
:param obj: The newly created FlatCAM object.
:param plot: If to plot the new object, bool
:return: None
"""
t0 = time.time() # DEBUG
@@ -1547,7 +1557,9 @@ class App(QtCore.QObject):
self.inform.emit("Object (%s) created: %s" % (obj.kind, obj.options['name']))
self.new_object_available.emit(obj)
obj.plot()
if plot:
obj.plot()
self.on_zoom_fit(None)
t1 = time.time() # DEBUG
self.log.debug("%f seconds adding object and plotting." % (t1 - t0))