- added ability to regenerate objects (it's actually deletion followed by recreation)

This commit is contained in:
Marius Stanciu
2019-02-22 03:28:04 +02:00
committed by Marius S
parent 45b5cba68a
commit 18f38999c4
4 changed files with 26 additions and 17 deletions

View File

@@ -149,7 +149,7 @@ class App(QtCore.QObject):
# Emitted by new_object() and passes the new object as argument, plot flag. # Emitted by new_object() and passes the new object as argument, plot flag.
# on_object_created() adds the object to the collection, plots on appropriate flag # on_object_created() adds the object to the collection, plots on appropriate flag
# and emits new_object_available. # and emits new_object_available.
object_created = QtCore.pyqtSignal(object, bool, bool) object_created = QtCore.pyqtSignal(object, bool, bool, bool)
# Emitted when a object has been changed (like scaled, mirrored) # Emitted when a object has been changed (like scaled, mirrored)
object_changed = QtCore.pyqtSignal(object) object_changed = QtCore.pyqtSignal(object)
@@ -2298,7 +2298,7 @@ class App(QtCore.QObject):
# Re-buid the recent items menu # Re-buid the recent items menu
self.setup_recent_items() self.setup_recent_items()
def new_object(self, kind, name, initialize, active=True, fit=True, plot=True, autoselected=True): def new_object(self, kind, name, initialize, active=True, fit=True, plot=True, autoselected=True, overwrite=False):
""" """
Creates a new specalized FlatCAMObj and attaches it to the application, Creates a new specalized FlatCAMObj and attaches it to the application,
this is, updates the GUI accordingly, any other records and plots it. this is, updates the GUI accordingly, any other records and plots it.
@@ -2323,8 +2323,10 @@ class App(QtCore.QObject):
""" """
App.log.debug("new_object()") App.log.debug("new_object()")
self.plot = plot obj_plot = plot
self.autoselected = autoselected obj_autoselected = autoselected
obj_overwrite = overwrite
t0 = time.time() # Debug t0 = time.time() # Debug
## Create object ## Create object
@@ -2412,7 +2414,7 @@ class App(QtCore.QObject):
# Move the object to the main thread and let the app know that it is available. # Move the object to the main thread and let the app know that it is available.
obj.moveToThread(QtWidgets.QApplication.instance().thread()) obj.moveToThread(QtWidgets.QApplication.instance().thread())
self.object_created.emit(obj, self.plot, self.autoselected) self.object_created.emit(obj, obj_plot, obj_autoselected, obj_overwrite)
return obj return obj
@@ -2429,7 +2431,7 @@ class App(QtCore.QObject):
self.new_object('geometry', 'new_g', initialize, plot=False) self.new_object('geometry', 'new_g', initialize, plot=False)
def on_object_created(self, obj, plot, autoselect): def on_object_created(self, obj, plot, autoselect, overwrite):
""" """
Event callback for object creation. Event callback for object creation.
@@ -2440,7 +2442,7 @@ class App(QtCore.QObject):
self.log.debug("on_object_created()") self.log.debug("on_object_created()")
# The Collection might change the name if there is a collision # The Collection might change the name if there is a collision
self.collection.append(obj) self.collection.append(obj, overwrite=overwrite)
# after adding the object to the collection always update the list of objects that are in the collection # after adding the object to the collection always update the list of objects that are in the collection
self.all_objects_list = self.collection.get_list() self.all_objects_list = self.collection.get_list()

View File

@@ -642,7 +642,7 @@ class ObjectCollection(QtCore.QAbstractItemModel):
# return QtWidgets.QAbstractItemModel.flags(self, index) # return QtWidgets.QAbstractItemModel.flags(self, index)
def append(self, obj, active=False): def append(self, obj, active=False, overwrite=False):
FlatCAMApp.App.log.debug(str(inspect.stack()[1][3]) + " --> OC.append()") FlatCAMApp.App.log.debug(str(inspect.stack()[1][3]) + " --> OC.append()")
name = obj.options["name"] name = obj.options["name"]
@@ -652,6 +652,13 @@ class ObjectCollection(QtCore.QAbstractItemModel):
self.promises.remove(name) self.promises.remove(name)
# FlatCAMApp.App.log.debug("Promised object %s became available." % name) # FlatCAMApp.App.log.debug("Promised object %s became available." % name)
# FlatCAMApp.App.log.debug("%d promised objects remaining." % len(self.promises)) # FlatCAMApp.App.log.debug("%d promised objects remaining." % len(self.promises))
# first delete the old object
if overwrite:
if name in self.get_names():
self.set_active(name)
self.delete_active(select_project=False)
# Prevent same name # Prevent same name
while name in self.get_names(): while name in self.get_names():
## Create a new name ## Create a new name
@@ -752,7 +759,7 @@ class ObjectCollection(QtCore.QAbstractItemModel):
return obj return obj
return None return None
def delete_active(self): def delete_active(self, select_project=True):
selections = self.view.selectedIndexes() selections = self.view.selectedIndexes()
if len(selections) == 0: if len(selections) == 0:
return return
@@ -779,8 +786,9 @@ class ObjectCollection(QtCore.QAbstractItemModel):
self.endRemoveRows() self.endRemoveRows()
# always go to the Project Tab after object deletion as it may be done with a shortcut key if select_project:
self.app.ui.notebook.setCurrentWidget(self.app.ui.project_tab) # always go to the Project Tab after object deletion as it may be done with a shortcut key
self.app.ui.notebook.setCurrentWidget(self.app.ui.project_tab)
self.app.should_we_save = True self.app.should_we_save = True

View File

@@ -23,6 +23,7 @@ CAD program, and create G-Code for Isolation routing.
- fixed issue with not updating correctly the plot kind (all, cut, travel) when clicking in the CNC Tools Table plot buttons - fixed issue with not updating correctly the plot kind (all, cut, travel) when clicking in the CNC Tools Table plot buttons
- made the GCode Editor for ToolSolderPaste clear the text before updating the Code Editor tab - made the GCode Editor for ToolSolderPaste clear the text before updating the Code Editor tab
- all the Tabs in Plot Area are closed (except Plot Area itself) on New Project creation - all the Tabs in Plot Area are closed (except Plot Area itself) on New Project creation
- added ability to regenerate objects (it's actually deletion followed by recreation)
20.02.2019 20.02.2019

View File

@@ -933,7 +933,7 @@ class SolderPaste(FlatCAMTool):
def job_thread(app_obj): def job_thread(app_obj):
try: try:
app_obj.new_object("geometry", name + "_solderpaste", geo_init) app_obj.new_object("geometry", name + "_solderpaste", geo_init, overwrite=True)
except Exception as e: except Exception as e:
proc.done() proc.done()
traceback.print_stack() traceback.print_stack()
@@ -1065,7 +1065,7 @@ class SolderPaste(FlatCAMTool):
self.app.file_saved.emit("gcode", filename) self.app.file_saved.emit("gcode", filename)
self.app.inform.emit("[success] Solder paste dispenser GCode file saved to: %s" % filename) self.app.inform.emit("[success] Solder paste dispenser GCode file saved to: %s" % filename)
def on_create_gcode(self, use_thread=True): def on_create_gcode(self, signal, use_thread=True):
""" """
Creates a multi-tool CNCJob out of this Geometry object. Creates a multi-tool CNCJob out of this Geometry object.
:return: None :return: None
@@ -1168,11 +1168,9 @@ class SolderPaste(FlatCAMTool):
if use_thread: if use_thread:
# To be run in separate thread # To be run in separate thread
# The idea is that if there is a solid_geometry in the file "root" then most likely thare are no
# separate solid_geometry in the self.tools dictionary
def job_thread(app_obj): def job_thread(app_obj):
with self.app.proc_container.new("Generating CNC Code"): with self.app.proc_container.new("Generating CNC Code"):
if app_obj.new_object("cncjob", outname, job_init) != 'fail': if app_obj.new_object("cncjob", outname, job_init, overwrite=True) != 'fail':
app_obj.inform.emit("[success]ToolSolderPaste CNCjob created: %s" % outname) app_obj.inform.emit("[success]ToolSolderPaste CNCjob created: %s" % outname)
app_obj.progress.emit(100) app_obj.progress.emit(100)
@@ -1181,7 +1179,7 @@ class SolderPaste(FlatCAMTool):
# Send to worker # Send to worker
self.app.worker_task.emit({'fcn': job_thread, 'params': [self.app]}) self.app.worker_task.emit({'fcn': job_thread, 'params': [self.app]})
else: else:
self.app.new_object("cncjob", outname, job_init) self.app.new_object("cncjob", outname, job_init, overwrite=True)
def reset_fields(self): def reset_fields(self):
self.obj_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex())) self.obj_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))