- moved all the new_object related methods in their own class AppObjects.AppObject

This commit is contained in:
Marius Stanciu
2020-05-18 17:31:02 +03:00
committed by Marius
parent 710a84b442
commit 2bcdeff7ef
55 changed files with 579 additions and 554 deletions

View File

@@ -1,6 +1,6 @@
import sys
import re
import App
import AppMain
import abc
import collections
from PyQt5 import QtCore
@@ -53,7 +53,7 @@ class TclCommand(object):
if self.app is None:
raise TypeError('Expected app to be FlatCAMApp instance.')
if not isinstance(self.app, App.App):
if not isinstance(self.app, AppMain.App):
raise TypeError('Expected FlatCAMApp, got %s.' % type(app))
self.log = self.app.log

View File

@@ -189,7 +189,7 @@ class TclCommandAlignDrill(TclCommandSignaled):
px = 0.5 * (xmin + xmax)
py = 0.5 * (ymin + ymax)
obj.app.new_object("excellon", outname, alligndrill_init_me, plot=False)
obj.app.app_obj.new_object("excellon", outname, alligndrill_init_me, plot=False)
except Exception as e:
return "Operation failed: %s" % str(e)
@@ -205,7 +205,7 @@ class TclCommandAlignDrill(TclCommandSignaled):
try:
px = dist
py = dist
obj.app.new_object("excellon", outname, alligndrill_init_me, plot=False)
obj.app.app_obj.new_object("excellon", outname, alligndrill_init_me, plot=False)
except Exception as e:
return "Operation failed: %s" % str(e)

View File

@@ -111,4 +111,4 @@ class TclCommandAlignDrillGrid(TclCommandSignaled):
init_obj.create_geometry()
# Create the new object
self.app.new_object("excellon", outname, aligndrillgrid_init_me, plot=False)
self.app.app_obj.new_object("excellon", outname, aligndrillgrid_init_me, plot=False)

View File

@@ -100,6 +100,6 @@ class TclCommandBbox(TclCommand):
bounding_box = bounding_box.envelope
geo_obj.solid_geometry = bounding_box
self.app.new_object("geometry", args['outname'], geo_init, plot=False)
self.app.app_obj.new_object("geometry", args['outname'], geo_init, plot=False)
except Exception as e:
return "Operation failed: %s" % str(e)

View File

@@ -137,7 +137,7 @@ class TclCommandCutout(TclCommand):
geo_obj.solid_geometry = cascaded_union([LineString(segment) for segment in cuts])
try:
self.app.new_object("geometry", outname, geo_init_me, plot=False)
self.app.app_obj.new_object("geometry", outname, geo_init_me, plot=False)
self.app.inform.emit("[success] Rectangular-form Cutout operation finished.")
except Exception as e:
return "Operation failed: %s" % str(e)

View File

@@ -343,4 +343,4 @@ class TclCommandDrillcncjob(TclCommandSignaled):
job_obj.gcode_parse()
job_obj.create_geometry()
self.app.new_object("cncjob", args['outname'], job_init, plot=False)
self.app.app_obj.new_object("cncjob", args['outname'], job_init, plot=False)

View File

@@ -66,4 +66,4 @@ class TclCommandExteriors(TclCommandSignaled):
geo_obj.solid_geometry = obj_exteriors
obj_exteriors = obj.get_exteriors()
self.app.new_object('geometry', outname, geo_init, plot=False)
self.app.app_obj.new_object('geometry', outname, geo_init, plot=False)

View File

@@ -300,11 +300,8 @@ class TclCommandGeoCutout(TclCommandSignaled):
app_obj.inform.emit("[success] %s" % _("Any-form Cutout operation finished."))
self.app.new_object('geometry', outname, geo_init, plot=False)
self.app.app_obj.new_object('geometry', outname, geo_init, plot=False)
# cutout_obj.plot()
# self.app.inform.emit("[success] Any-form Cutout operation finished.")
# self.app.plots_updated.emit()
elif cutout_obj.kind == 'gerber':
def geo_init(geo_obj, app_obj):
@@ -358,7 +355,7 @@ class TclCommandGeoCutout(TclCommandSignaled):
geo_obj.options['ymax'] = cutout_obj.options['ymax']
app_obj.inform.emit("[success] %s" % _("Any-form Cutout operation finished."))
self.app.new_object('geometry', outname, geo_init, plot=False)
self.app.app_obj.new_object('geometry', outname, geo_init, plot=False)
cutout_obj = self.app.collection.get_by_name(outname)
else:

View File

@@ -76,7 +76,7 @@ class TclCommandImportSvg(TclCommandSignaled):
with self.app.proc_container.new("Import SVG"):
# Object creation
self.app.new_object(obj_type, outname, obj_init, plot=False)
self.app.app_obj.new_object(obj_type, outname, obj_init, plot=False)
# Register recent file
self.app.file_opened.emit("svg", filename)

View File

@@ -67,4 +67,4 @@ class TclCommandInteriors(TclCommandSignaled):
geo_obj.solid_geometry = obj_interiors
obj_interiors = obj.get_interiors()
self.app.new_object('geometry', outname, geo_init)
self.app.app_obj.new_object('geometry', outname, geo_init)

View File

@@ -65,6 +65,6 @@ class TclCommandJoinExcellon(TclCommand):
ExcellonObject.merge(objs, obj_, decimals=self.app.decimals)
if objs and len(objs) >= 2:
self.app.new_object("excellon", outname, initialize, plot=False)
self.app.app_obj.new_object("excellon", outname, initialize, plot=False)
else:
return "No Excellon objects to be joined or less than two Excellon objects specified for merging."

View File

@@ -65,6 +65,6 @@ class TclCommandJoinGeometry(TclCommand):
GeometryObject.merge(objs, obj_)
if objs and len(objs) >= 2:
self.app.new_object("geometry", outname, initialize, plot=False)
self.app.app_obj.new_object("geometry", outname, initialize, plot=False)
else:
return "No Geometry objects to be joined or less than two Geometry objects specified for merging."

View File

@@ -58,4 +58,4 @@ class TclCommandNewExcellon(TclCommandSignaled):
name = args['name']
else:
name = 'new_exc'
self.app.new_object('excellon', name, lambda x, y: None, plot=False)
self.app.app_obj.new_object('excellon', name, lambda x, y: None, plot=False)

View File

@@ -52,4 +52,4 @@ class TclCommandNewGeometry(TclCommandSignaled):
else:
name = 'new_geo'
self.app.new_object('geometry', str(name), lambda x, y: None, plot=False)
self.app.app_obj.new_object('geometry', str(name), lambda x, y: None, plot=False)

View File

@@ -75,4 +75,4 @@ class TclCommandNewGerber(TclCommandSignaled):
except KeyError:
pass
self.app.new_object('gerber', name, initialize, plot=False)
self.app.app_obj.new_object('gerber', name, initialize, plot=False)

View File

@@ -100,7 +100,7 @@ class TclCommandNregions(TclCommand):
non_copper = bounding_box.difference(geo)
geo_obj.solid_geometry = non_copper
self.app.new_object("geometry", args['outname'], geo_init, plot=False)
self.app.app_obj.new_object("geometry", args['outname'], geo_init, plot=False)
except Exception as e:
return "Operation failed: %s" % str(e)

View File

@@ -77,10 +77,10 @@ class TclCommandOpenDXF(TclCommandSignaled):
with self.app.proc_container.new("Open DXF"):
# Object creation
ret_val = self.app.new_object(obj_type, outname, obj_init, plot=False)
ret_val = self.app.app_obj.new_object(obj_type, outname, obj_init, plot=False)
if ret_val == 'fail':
filename = self.app.defaults['global_tcl_path'] + '/' + outname
ret_val = self.app.new_object(obj_type, outname, obj_init, plot=False)
ret_val = self.app.app_obj.new_object(obj_type, outname, obj_init, plot=False)
self.app.shell.append_output(
"No path provided or path is wrong. Using the default Path... \n")

View File

@@ -77,10 +77,10 @@ class TclCommandOpenSVG(TclCommandSignaled):
with self.app.proc_container.new("Import SVG"):
# Object creation
ret_val = self.app.new_object(obj_type, outname, obj_init, plot=False)
ret_val = self.app.app_obj.new_object(obj_type, outname, obj_init, plot=False)
if ret_val == 'fail':
filename = self.app.defaults['global_tcl_path'] + '/' + outname
ret_val = self.app.new_object(obj_type, outname, obj_init, plot=False)
ret_val = self.app.app_obj.new_object(obj_type, outname, obj_init, plot=False)
self.app.shell.append_output(
"No path provided or path is wrong. Using the default Path... \n")
if ret_val == 'fail':

View File

@@ -167,19 +167,19 @@ class TclCommandPanelize(TclCommand):
# for col in range(columns):
# local_outname = outname + ".tmp." + str(col) + "." + str(row)
# if isinstance(obj, ExcellonObject):
# self.app.new_object("excellon", local_outname, initialize_local_excellon, plot=False,
# self.app.app_obj.new_object("excellon", local_outname, initialize_local_excellon, plot=False,
# autoselected=False)
# else:
# self.app.new_object("geometry", local_outname, initialize_local, plot=False,
# self.app.app_obj.new_object("geometry", local_outname, initialize_local, plot=False,
# autoselected=False)
#
# currentx += lenghtx
# currenty += lenghty
#
# if isinstance(obj, ExcellonObject):
# self.app.new_object("excellon", outname, initialize_excellon)
# self.app.app_obj.new_object("excellon", outname, initialize_excellon)
# else:
# self.app.new_object("geometry", outname, initialize_geometry)
# self.app.app_obj.new_object("geometry", outname, initialize_geometry)
#
# # deselect all to avoid delete selected object when run delete from shell
# self.app.collection.set_all_inactive()
@@ -287,9 +287,9 @@ class TclCommandPanelize(TclCommand):
currenty += lenghty
if obj.kind == 'excellon':
self.app.new_object("excellon", outname, job_init_excellon, plot=False, autoselected=True)
self.app.app_obj.new_object("excellon", outname, job_init_excellon, plot=False, autoselected=True)
else:
self.app.new_object("geometry", outname, job_init_geometry, plot=False, autoselected=True)
self.app.app_obj.new_object("geometry", outname, job_init_geometry, plot=False, autoselected=True)
if threaded is True:
proc = self.app.proc_container.new("Generating panel ... Please wait.")

View File

@@ -80,15 +80,15 @@ class TclCommandWriteGCode(TclCommandSignaled):
# This is not needed any more? All targets should be present.
# If there are promised objects, wait until all promises have been fulfilled.
# if self.collection.has_promises():
# def write_gcode_on_object(new_object):
# def write_gcode_on_object(app_obj.new_object):
# self.log.debug("write_gcode_on_object(): Disconnecting %s" % write_gcode_on_object)
# self.new_object_available.disconnect(write_gcode_on_object)
# self.app_obj.new_object_available.disconnect(write_gcode_on_object)
# write_gcode(obj_name, filename, preamble, postamble)
#
# # Try again when a new object becomes available.
# self.log.debug("write_gcode(): Collection has promises. Queued for %s." % obj_name)
# self.log.debug("write_gcode(): Queued function: %s" % write_gcode_on_object)
# self.new_object_available.connect(write_gcode_on_object)
# self.app_obj.new_object_available.connect(write_gcode_on_object)
#
# return