From bc4411d56609ac544e967495083404ecec13a67f Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sun, 27 May 2018 12:07:57 +0300 Subject: [PATCH 1/2] - added a new column in the TableTool where I show the number of drill holes for each tool. --- FlatCAMObj.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/FlatCAMObj.py b/FlatCAMObj.py index f37ff471..12038e1b 100644 --- a/FlatCAMObj.py +++ b/FlatCAMObj.py @@ -756,18 +756,29 @@ class FlatCAMExcellon(FlatCAMObj, Excellon): # Populate tool list n = len(self.tools) - self.ui.tools_table.setColumnCount(2) - self.ui.tools_table.setHorizontalHeaderLabels(['#', 'Diameter']) + self.ui.tools_table.setColumnCount(3) + self.ui.tools_table.setHorizontalHeaderLabels(['#', 'Diameter', 'Count']) self.ui.tools_table.setRowCount(n) self.ui.tools_table.setSortingEnabled(False) + i = 0 for tool in self.tools: + + drill_cnt = 0 # variable to store the nr of drills per tool + # Find no of drills for the current tool + for drill in self.drills: + if drill.get('tool') == tool: + drill_cnt += 1 + id = QtGui.QTableWidgetItem(tool) id.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.ui.tools_table.setItem(i, 0, id) # Tool name/id dia = QtGui.QTableWidgetItem(str(self.tools[tool]['C'])) dia.setFlags(QtCore.Qt.ItemIsEnabled) + drill_count = QtGui.QTableWidgetItem('%d' % drill_cnt) + drill_count.setFlags(QtCore.Qt.ItemIsEnabled) self.ui.tools_table.setItem(i, 1, dia) # Diameter + self.ui.tools_table.setItem(i, 2, drill_count) # Number of drills per tool i += 1 # sort the tool diameter column @@ -777,7 +788,11 @@ class FlatCAMExcellon(FlatCAMObj, Excellon): self.ui.tools_table.resizeColumnsToContents() self.ui.tools_table.resizeRowsToContents() - self.ui.tools_table.horizontalHeader().setStretchLastSection(True) + horizontal_header = self.ui.tools_table.horizontalHeader() + horizontal_header.setResizeMode(0, QtGui.QHeaderView.ResizeToContents) + horizontal_header.setResizeMode(1, QtGui.QHeaderView.Stretch) + horizontal_header.setResizeMode(2, QtGui.QHeaderView.ResizeToContents) + # horizontal_header.setStretchLastSection(True) self.ui.tools_table.verticalHeader().hide() self.ui.tools_table.setSortingEnabled(True) From ef611753a653df6e570b643832c6021307f5e4c2 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 28 May 2018 15:46:42 +0300 Subject: [PATCH 2/2] - added the posibility to create an object without plotting it. Also if the project is created with plot=False then it will not be checked in Project tab - improved the panelize command by toggling OFF the plot for the temporary objects. There is no need to plot the temporary objects, only the panel is of interest - add a few aliases for the Panelize command ('pan' and 'panel') --- FlatCAMApp.py | 28 ++++++++++++++++++++-------- ObjectCollection.py | 4 ++-- tclCommands/TclCommandPanelize.py | 7 +++---- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 04048a5b..ea230c41 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -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)) diff --git a/ObjectCollection.py b/ObjectCollection.py index 82ccef5b..a28e7afc 100644 --- a/ObjectCollection.py +++ b/ObjectCollection.py @@ -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): diff --git a/tclCommands/TclCommandPanelize.py b/tclCommands/TclCommandPanelize.py index f04d7819..e1e01a91 100644 --- a/tclCommands/TclCommandPanelize.py +++ b/tclCommands/TclCommandPanelize.py @@ -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