FlatCAMObj - to_form,read_form,read_form_item cleanups for better debuging and cleanup Excellon merge method
FlatCAMApp - fix accidentall delete issue, change calling to understand FlatCAMObj changes
This commit is contained in:
@@ -2774,6 +2774,8 @@ class App(QtCore.QObject):
|
||||
|
||||
def delete(obj_name):
|
||||
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.on_delete()
|
||||
except Exception, e:
|
||||
@@ -2815,7 +2817,7 @@ class App(QtCore.QObject):
|
||||
objs.append(obj)
|
||||
|
||||
def initialize(obj, app):
|
||||
FlatCAMExcellon.merge(objs, obj,True)
|
||||
FlatCAMExcellon.merge(objs, obj)
|
||||
|
||||
if objs is not None:
|
||||
self.new_object("excellon", obj_name, initialize)
|
||||
@@ -2880,14 +2882,14 @@ class App(QtCore.QObject):
|
||||
obj_init.offset([float(currentx), float(currenty)]),
|
||||
|
||||
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)]),
|
||||
|
||||
def initialize_geometry(obj_init, app):
|
||||
FlatCAMGeometry.merge(objs, obj_init)
|
||||
|
||||
def initialize_excellon(obj_init, app):
|
||||
FlatCAMExcellon.merge(objs, obj_init,True)
|
||||
FlatCAMExcellon.merge(objs, obj_init)
|
||||
|
||||
objs=[]
|
||||
if obj is not None:
|
||||
@@ -2909,7 +2911,8 @@ class App(QtCore.QObject):
|
||||
else:
|
||||
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:
|
||||
self.collection.set_active(delobj.options['name'])
|
||||
self.on_delete()
|
||||
|
||||
@@ -123,8 +123,12 @@ class FlatCAMObj(QtCore.QObject):
|
||||
|
||||
:return: None
|
||||
"""
|
||||
FlatCAMApp.App.log.debug(str(inspect.stack()[1][3]) + "--> FlatCAMObj.to_form()")
|
||||
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):
|
||||
"""
|
||||
@@ -135,7 +139,11 @@ class FlatCAMObj(QtCore.QObject):
|
||||
"""
|
||||
FlatCAMApp.App.log.debug(str(inspect.stack()[1][3]) + "--> FlatCAMObj.read_form()")
|
||||
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):
|
||||
"""
|
||||
@@ -191,11 +199,16 @@ class FlatCAMObj(QtCore.QObject):
|
||||
:type option: str
|
||||
:return: None
|
||||
"""
|
||||
|
||||
try:
|
||||
self.options[option] = self.form_fields[option].get_value()
|
||||
except KeyError:
|
||||
self.app.log.warning("Failed to read option from field: %s" % option)
|
||||
#try read field only when option have equivalent in form_fields
|
||||
if option in self.form_fields:
|
||||
option_type=type(self.options[option])
|
||||
try:
|
||||
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):
|
||||
"""
|
||||
@@ -631,13 +644,16 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
|
||||
self.ser_attrs += ['options', 'kind']
|
||||
|
||||
@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
|
||||
options have same like exc_final
|
||||
the geometry of geo_final.
|
||||
Merge excellons in exc_list into exc_final.
|
||||
Options are allways copied from source .
|
||||
|
||||
: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.
|
||||
:return: None
|
||||
"""
|
||||
@@ -648,26 +664,27 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
|
||||
else:
|
||||
exc_list_real=exc_list
|
||||
|
||||
|
||||
for exc in exc_list_real:
|
||||
# Expand lists
|
||||
if type(exc) is list:
|
||||
FlatCAMExcellon.merge(exc, exc_final, copy_options)
|
||||
|
||||
# If not list, just append
|
||||
FlatCAMExcellon.merge(exc, exc_final)
|
||||
# If not list, merge excellons
|
||||
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:
|
||||
point = Point(drill['point'].x,drill['point'].y)
|
||||
exc_final.drills.append({"point": point, "tool": drill['tool']})
|
||||
@@ -679,7 +696,7 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
|
||||
max_numeric_tool=numeric_tool
|
||||
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():
|
||||
numeric_tool=int(toolname)
|
||||
if numeric_tool>max_numeric_tool:
|
||||
@@ -692,9 +709,10 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
|
||||
exc_final.tools[str(max_numeric_tool+1)]={"C": toolvalues}
|
||||
else:
|
||||
exc_final.tools[toolsrework[toolvalues]]={"C": toolvalues}
|
||||
#this value was not co
|
||||
exc_final.zeros=exc.zeros
|
||||
exc_final.create_geometry()
|
||||
|
||||
|
||||
def build_ui(self):
|
||||
FlatCAMObj.build_ui(self)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user