Merged Improve_panelize_Tcl_command into master

This commit is contained in:
Marius Stanciu 2018-05-30 03:00:42 +03:00
commit 7ec6914422
3 changed files with 25 additions and 14 deletions

View File

@ -112,10 +112,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.
@ -1021,9 +1021,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()")
@ -1047,6 +1050,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
@ -1069,7 +1076,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
@ -1483,12 +1490,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
@ -1530,11 +1539,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
@ -1545,7 +1555,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))

View File

@ -289,7 +289,7 @@ class ObjectCollection():
:param name: Name of the FlatCAM Object
:return: None
"""
iobj = self.createIndex(self.get_names().index(name), 0) # Column 0
iobj = self.model.createIndex(self.get_names().index(name), 0) # Column 0
self.view.selectionModel().select(iobj, QtGui.QItemSelectionModel.Select)
def set_inactive(self, name):
@ -300,7 +300,7 @@ class ObjectCollection():
:param name: Name of the FlatCAM Object
:return: None
"""
iobj = self.createIndex(self.get_names().index(name), 0) # Column 0
iobj = self.model.createIndex(self.get_names().index(name), 0) # Column 0
self.view.selectionModel().select(iobj, QtGui.QItemSelectionModel.Deselect)
def set_all_inactive(self):

View File

@ -13,7 +13,7 @@ class TclCommandPanelize(TclCommand.TclCommand):
"""
# List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
aliases = ['panelize']
aliases = ['panelize', 'pan', 'panel']
# Dictionary of types from Tcl command, needs to be ordered
arg_names = collections.OrderedDict([
@ -130,10 +130,9 @@ class TclCommandPanelize(TclCommand.TclCommand):
for col in range(args['columns']):
local_outname = outname + ".tmp." + str(col) + "." + str(row)
if isinstance(obj, FlatCAMExcellon):
self.app.new_object("excellon", local_outname, initialize_local_excellon)
self.app.new_object("excellon", local_outname, initialize_local_excellon, plot=False)
else:
self.app.new_object("geometry", local_outname, initialize_local)
self.app.new_object("geometry", local_outname, initialize_local, plot=False)
currentx += lenghtx
currenty += lenghty