Merged in merge-excellons (pull request #3)

Merge excellons
This commit is contained in:
Kamil Sopko
2016-02-24 22:46:00 +01:00
3 changed files with 74 additions and 32 deletions

View File

@@ -2774,6 +2774,8 @@ class App(QtCore.QObject):
def delete(obj_name): def delete(obj_name):
try: try:
#deselect all to avoid delete selected object when run delete from shell
self.collection.set_all_inactive()
self.collection.set_active(str(obj_name)) self.collection.set_active(str(obj_name))
self.on_delete() self.on_delete()
except Exception, e: except Exception, e:
@@ -2815,7 +2817,7 @@ class App(QtCore.QObject):
objs.append(obj) objs.append(obj)
def initialize(obj, app): def initialize(obj, app):
FlatCAMExcellon.merge(objs, obj,True) FlatCAMExcellon.merge(objs, obj)
if objs is not None: if objs is not None:
self.new_object("excellon", obj_name, initialize) self.new_object("excellon", obj_name, initialize)
@@ -2880,14 +2882,14 @@ class App(QtCore.QObject):
obj_init.offset([float(currentx), float(currenty)]), obj_init.offset([float(currentx), float(currenty)]),
def initialize_local_excellon(obj_init, app): def initialize_local_excellon(obj_init, app):
FlatCAMExcellon.merge(obj, obj_init,True) FlatCAMExcellon.merge(obj, obj_init)
obj_init.offset([float(currentx), float(currenty)]), obj_init.offset([float(currentx), float(currenty)]),
def initialize_geometry(obj_init, app): def initialize_geometry(obj_init, app):
FlatCAMGeometry.merge(objs, obj_init) FlatCAMGeometry.merge(objs, obj_init)
def initialize_excellon(obj_init, app): def initialize_excellon(obj_init, app):
FlatCAMExcellon.merge(objs, obj_init,True) FlatCAMExcellon.merge(objs, obj_init)
objs=[] objs=[]
if obj is not None: if obj is not None:
@@ -2909,7 +2911,8 @@ class App(QtCore.QObject):
else: else:
self.new_object("geometry", outname, initialize_geometry) self.new_object("geometry", outname, initialize_geometry)
#deselect all to avoid delete selected object when run delete from shell
self.collection.set_all_inactive()
for delobj in objs: for delobj in objs:
self.collection.set_active(delobj.options['name']) self.collection.set_active(delobj.options['name'])
self.on_delete() self.on_delete()

View File

@@ -123,8 +123,12 @@ class FlatCAMObj(QtCore.QObject):
:return: None :return: None
""" """
FlatCAMApp.App.log.debug(str(inspect.stack()[1][3]) + "--> FlatCAMObj.to_form()")
for option in self.options: for option in self.options:
self.set_form_item(option) try:
self.set_form_item(option)
except:
self.app.log.warning("Unexpected error:", sys.exc_info())
def read_form(self): def read_form(self):
""" """
@@ -135,7 +139,11 @@ class FlatCAMObj(QtCore.QObject):
""" """
FlatCAMApp.App.log.debug(str(inspect.stack()[1][3]) + "--> FlatCAMObj.read_form()") FlatCAMApp.App.log.debug(str(inspect.stack()[1][3]) + "--> FlatCAMObj.read_form()")
for option in self.options: for option in self.options:
self.read_form_item(option) try:
self.read_form_item(option)
except:
self.app.log.warning("Unexpected error:", sys.exc_info())
def build_ui(self): def build_ui(self):
""" """
@@ -191,11 +199,16 @@ class FlatCAMObj(QtCore.QObject):
:type option: str :type option: str
:return: None :return: None
""" """
#try read field only when option have equivalent in form_fields
try: if option in self.form_fields:
self.options[option] = self.form_fields[option].get_value() option_type=type(self.options[option])
except KeyError: try:
self.app.log.warning("Failed to read option from field: %s" % option) value=self.form_fields[option].get_value()
#catch per option as it was ignored anyway, also when syntax error (probably uninitialized field),don't read either.
except (KeyError,SyntaxError):
self.app.log.warning("Failed to read option from field: %s" % option)
else:
self.app.log.warning("Form fied does not exists: %s" % option)
def plot(self): def plot(self):
""" """
@@ -631,13 +644,16 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
self.ser_attrs += ['options', 'kind'] self.ser_attrs += ['options', 'kind']
@staticmethod @staticmethod
def merge(exc_list, exc_final, copy_options): def merge(exc_list, exc_final):
""" """
Merges(copy if used on one) the excellon of objects in exc_list into Merge excellons in exc_list into exc_final.
options have same like exc_final Options are allways copied from source .
the geometry of geo_final.
:param exc_list: List of FlatCAMExcellon Objects to join. Tools are also merged, if name for tool is same and size differs, then as name is used next available number from both lists
if only one object is specified in exc_list then this acts as copy only
:param exc_list: List or one object of FlatCAMExcellon Objects to join.
:param exc_final: Destination FlatCAMExcellon object. :param exc_final: Destination FlatCAMExcellon object.
:return: None :return: None
""" """
@@ -648,26 +664,27 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
else: else:
exc_list_real=exc_list exc_list_real=exc_list
for exc in exc_list_real: for exc in exc_list_real:
# Expand lists # Expand lists
if type(exc) is list: if type(exc) is list:
FlatCAMExcellon.merge(exc, exc_final, copy_options) FlatCAMExcellon.merge(exc, exc_final)
# If not list, merge excellons
# If not list, just append
else: else:
if copy_options is True:
exc_final.options["plot"]=exc.options["plot"]
exc_final.options["solid"]=exc.options["solid"]
exc_final.options["drillz"]=exc.options["drillz"]
exc_final.options["travelz"]=exc.options["travelz"]
exc_final.options["feedrate"]=exc.options["feedrate"]
exc_final.options["tooldia"]=exc.options["tooldia"]
exc_final.options["toolchange"]=exc.options["toolchange"]
exc_final.options["toolchangez"]=exc.options["toolchangez"]
exc_final.options["spindlespeed"]=exc.options["spindlespeed"]
# TODO: I realize forms does not save values into options , when object is deselected
# leave this here for future use
# this reinitialize options based on forms, all steps may not be necessary
# exc.app.collection.set_active(exc.options['name'])
# exc.to_form()
# exc.read_form()
for option in exc.options:
if option is not 'name':
try:
exc_final.options[option] = exc.options[option]
except:
exc.app.log.warning("Failed to copy option.",option)
#deep copy of all drills,to avoid any references
for drill in exc.drills: for drill in exc.drills:
point = Point(drill['point'].x,drill['point'].y) point = Point(drill['point'].x,drill['point'].y)
exc_final.drills.append({"point": point, "tool": drill['tool']}) exc_final.drills.append({"point": point, "tool": drill['tool']})
@@ -679,7 +696,7 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
max_numeric_tool=numeric_tool max_numeric_tool=numeric_tool
toolsrework[exc.tools[toolname]['C']]=toolname toolsrework[exc.tools[toolname]['C']]=toolname
#final as last becouse names from final tools will be used #exc_final as last because names from final tools will be used
for toolname in exc_final.tools.iterkeys(): for toolname in exc_final.tools.iterkeys():
numeric_tool=int(toolname) numeric_tool=int(toolname)
if numeric_tool>max_numeric_tool: if numeric_tool>max_numeric_tool:
@@ -692,9 +709,10 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
exc_final.tools[str(max_numeric_tool+1)]={"C": toolvalues} exc_final.tools[str(max_numeric_tool+1)]={"C": toolvalues}
else: else:
exc_final.tools[toolsrework[toolvalues]]={"C": toolvalues} exc_final.tools[toolsrework[toolvalues]]={"C": toolvalues}
#this value was not co
exc_final.zeros=exc.zeros
exc_final.create_geometry() exc_final.create_geometry()
def build_ui(self): def build_ui(self):
FlatCAMObj.build_ui(self) FlatCAMObj.build_ui(self)

View File

@@ -244,6 +244,27 @@ class ObjectCollection(QtCore.QAbstractListModel):
iobj = self.createIndex(self.get_names().index(name), 0) # Column 0 iobj = self.createIndex(self.get_names().index(name), 0) # Column 0
self.view.selectionModel().select(iobj, QtGui.QItemSelectionModel.Select) self.view.selectionModel().select(iobj, QtGui.QItemSelectionModel.Select)
def set_inactive(self, name):
"""
Unselect object by name from the project list. This triggers the
list_selection_changed event and call on_list_selection_changed.
:param name: Name of the FlatCAM Object
:return: None
"""
iobj = self.createIndex(self.get_names().index(name), 0) # Column 0
self.view.selectionModel().select(iobj, QtGui.QItemSelectionModel.Deselect)
def set_all_inactive(self):
"""
Unselect all objects from the project list. This triggers the
list_selection_changed event and call on_list_selection_changed.
:return: None
"""
for name in self.get_names():
self.set_inactive(name)
def on_list_selection_change(self, current, previous): def on_list_selection_change(self, current, previous):
FlatCAMApp.App.log.debug("on_list_selection_change()") FlatCAMApp.App.log.debug("on_list_selection_change()")
FlatCAMApp.App.log.debug("Current: %s, Previous %s" % (str(current), str(previous))) FlatCAMApp.App.log.debug("Current: %s, Previous %s" % (str(current), str(previous)))