- replaced the testing if instance of FlatCAMObj with testing the obj.kind attribute

- removed the import of the whole FlatCAMApp file only for the usage of GracefulException
- remove the import of FlatCAMApp and used alternate ways
- optimized the imports in some files
- moved the Bookmarksmanager and ToolDB classes into their own files
- solved some bugs that were not so visible in the Editors and HPGL parser
This commit is contained in:
Marius Stanciu
2020-04-27 10:03:22 +03:00
committed by Marius
parent 61020e3624
commit 3ec666edbb
28 changed files with 3452 additions and 3389 deletions

View File

@@ -12,7 +12,6 @@ from camlib import distance, arc, FlatCAMRTreeStorage
from flatcamGUI.GUIElements import FCEntry, FCComboBox, FCTable, FCDoubleSpinner, RadioSet, FCSpinner
from flatcamEditors.FlatCAMGeoEditor import FCShapeTool, DrawTool, DrawToolShape, DrawToolUtilityShape, FlatCAMGeoEditor
from flatcamParsers.ParseExcellon import Excellon
import FlatCAMApp
from shapely.geometry import LineString, LinearRing, MultiLineString, Polygon, MultiPolygon, Point
import shapely.affinity as affinity
@@ -179,7 +178,7 @@ class FCDrillArray(FCShapeTool):
try:
QtGui.QGuiApplication.restoreOverrideCursor()
except Exception as e:
except Exception:
pass
self.cursor = QtGui.QCursor(QtGui.QPixmap(self.draw_app.app.resource_location + '/aero_drill_array.png'))
@@ -1516,7 +1515,7 @@ class FlatCAMExcEditor(QtCore.QObject):
draw_shape_idx = -1
def __init__(self, app):
assert isinstance(app, FlatCAMApp.App), "Expected the app to be a FlatCAMApp.App, got %s" % type(app)
# assert isinstance(app, FlatCAMApp.App), "Expected the app to be a FlatCAMApp.App, got %s" % type(app)
super(FlatCAMExcEditor, self).__init__()
@@ -2230,8 +2229,8 @@ class FlatCAMExcEditor(QtCore.QObject):
# store the status of the editor so the Delete at object level will not work until the edit is finished
self.editor_active = False
def entry2option(option, entry):
self.options[option] = float(entry.text())
# def entry2option(option, entry):
# self.options[option] = float(entry.text())
# Event signals disconnect id holders
self.mp = None
@@ -2388,7 +2387,7 @@ class FlatCAMExcEditor(QtCore.QObject):
try:
# Find no of slots for the current tool
for slot in self.slots:
for slot in self.slot_points_edit:
if slot['tool'] == tool_no:
slot_cnt += 1
@@ -2661,15 +2660,13 @@ class FlatCAMExcEditor(QtCore.QObject):
# self.tools_table_exc.selectionModel().currentChanged.disconnect()
self.is_modified = True
new_dia = None
# new_dia = None
if self.tools_table_exc.currentItem() is not None:
try:
new_dia = float(self.tools_table_exc.currentItem().text())
except ValueError as e:
log.debug("FlatCAMExcEditor.on_tool_edit() --> %s" % str(e))
self.tools_table_exc.setCurrentItem(None)
return
try:
new_dia = float(self.tools_table_exc.currentItem().text())
except ValueError as e:
log.debug("FlatCAMExcEditor.on_tool_edit() --> %s" % str(e))
return
row_of_item_changed = self.tools_table_exc.currentRow()
# rows start with 0, tools start with 1 so we adjust the value by 1
@@ -3297,7 +3294,8 @@ class FlatCAMExcEditor(QtCore.QObject):
return self.edited_obj_name
def update_options(self, obj):
@staticmethod
def update_options(obj):
try:
if not obj.options:
obj.options = {}
@@ -3316,10 +3314,14 @@ class FlatCAMExcEditor(QtCore.QObject):
"""
Creates a new Excellon object for the edited Excellon. Thread-safe.
:param outname: Name of the resulting object. None causes the
name to be that of the file.
:type outname: str
:return: None
:param outname: Name of the resulting object. None causes the
name to be that of the file.
:type outname: str
:param n_drills: The new Drills storage
:param n_slots: The new Slots storage
:param n_tools: The new Tools storage
:return: None
"""
self.app.log.debug("Update the Excellon object with edited content. Source is %s" %
@@ -3429,12 +3431,12 @@ class FlatCAMExcEditor(QtCore.QObject):
self.replot()
def toolbar_tool_toggle(self, key):
self.options[key] = self.sender().isChecked()
if self.options[key] is True:
return 1
else:
return 0
# def toolbar_tool_toggle(self, key):
# self.options[key] = self.sender().isChecked()
# if self.options[key] is True:
# return 1
# else:
# return 0
def on_canvas_click(self, event):
"""
@@ -3446,12 +3448,12 @@ class FlatCAMExcEditor(QtCore.QObject):
"""
if self.app.is_legacy is False:
event_pos = event.pos
event_is_dragging = event.is_dragging
right_button = 2
# event_is_dragging = event.is_dragging
# right_button = 2
else:
event_pos = (event.xdata, event.ydata)
event_is_dragging = self.app.plotcanvas.is_dragging
right_button = 3
# event_is_dragging = self.app.plotcanvas.is_dragging
# right_button = 3
self.pos = self.canvas.translate_coords(event_pos)
@@ -3575,8 +3577,8 @@ class FlatCAMExcEditor(QtCore.QObject):
if isinstance(shape, DrawToolUtilityShape):
self.utility.append(shape)
else:
self.storage.insert(shape) # TODO: Check performance
# else:
# self.storage.insert(shape)
def on_exc_click_release(self, event):
"""
@@ -3591,11 +3593,11 @@ class FlatCAMExcEditor(QtCore.QObject):
if self.app.is_legacy is False:
event_pos = event.pos
event_is_dragging = event.is_dragging
# event_is_dragging = event.is_dragging
right_button = 2
else:
event_pos = (event.xdata, event.ydata)
event_is_dragging = self.app.plotcanvas.is_dragging
# event_is_dragging = self.app.plotcanvas.is_dragging
right_button = 3
pos_canvas = self.canvas.translate_coords(event_pos)
@@ -4027,7 +4029,7 @@ class FlatCAMExcEditor(QtCore.QObject):
del self.slot_points_edit[storage][0]
if del_shape in self.selected:
self.selected.remove(del_shape) # TODO: Check performance
self.selected.remove(del_shape)
def delete_utility_geometry(self):
for_deletion = [util_shape for util_shape in self.utility]

View File

@@ -20,7 +20,6 @@ from flatcamGUI.ObjectUI import RadioSet
from flatcamGUI.GUIElements import OptionalInputSection, FCCheckBox, FCEntry, FCComboBox, FCTextAreaRich, \
FCTable, FCDoubleSpinner, FCButton, EvalEntry2, FCInputDialog, FCTree
from flatcamParsers.ParseFont import *
import FlatCAMApp
from shapely.geometry import LineString, LinearRing, MultiLineString, Polygon, MultiPolygon
from shapely.ops import cascaded_union, unary_union, linemerge
@@ -3299,8 +3298,8 @@ class FlatCAMGeoEditor(QtCore.QObject):
draw_shape_idx = -1
def __init__(self, app, disabled=False):
assert isinstance(app, FlatCAMApp.App), \
"Expected the app to be a FlatCAMApp.App, got %s" % type(app)
# assert isinstance(app, FlatCAMApp.App), \
# "Expected the app to be a FlatCAMApp.App, got %s" % type(app)
super(FlatCAMGeoEditor, self).__init__()
@@ -4011,6 +4010,7 @@ class FlatCAMGeoEditor(QtCore.QObject):
:return: Boolean. Status of the checkbox that toggled the Editor Tool
"""
cb_widget = self.sender()
assert isinstance(cb_widget, QtWidgets.QAction), "Expected a QAction got %s" % type(cb_widget)
self.options[key] = cb_widget.isChecked()
return 1 if self.options[key] is True else 0

View File

@@ -21,7 +21,6 @@ from camlib import distance, arc, three_point_circle
from flatcamGUI.GUIElements import FCEntry, FCComboBox, FCTable, FCDoubleSpinner, FCSpinner, RadioSet, \
EvalEntry2, FCInputDialog, FCButton, OptionalInputSection, FCCheckBox
from FlatCAMTool import FlatCAMTool
import FlatCAMApp
import numpy as np
from numpy.linalg import norm as numpy_norm
@@ -182,6 +181,7 @@ class FCShapeTool(DrawTool):
def __init__(self, draw_app):
DrawTool.__init__(self, draw_app)
self.name = None
def make(self):
pass
@@ -199,7 +199,7 @@ class FCPad(FCShapeTool):
try:
QtGui.QGuiApplication.restoreOverrideCursor()
except Exception as e:
except Exception:
pass
self.cursor = QtGui.QCursor(QtGui.QPixmap(self.draw_app.app.resource_location + '/aero_circle.png'))
QtGui.QGuiApplication.setOverrideCursor(self.cursor)
@@ -1415,7 +1415,7 @@ class FCDisc(FCShapeTool):
try:
QtGui.QGuiApplication.restoreOverrideCursor()
except Exception as e:
except Exception:
pass
self.cursor = QtGui.QCursor(QtGui.QPixmap(self.draw_app.app.resource_location + '/aero_disc.png'))
QtGui.QGuiApplication.setOverrideCursor(self.cursor)
@@ -2422,8 +2422,8 @@ class FlatCAMGrbEditor(QtCore.QObject):
mp_finished = QtCore.pyqtSignal(list)
def __init__(self, app):
assert isinstance(app, FlatCAMApp.App), \
"Expected the app to be a FlatCAMApp.App, got %s" % type(app)
# assert isinstance(app, FlatCAMApp.App), \
# "Expected the app to be a FlatCAMApp.App, got %s" % type(app)
super(FlatCAMGrbEditor, self).__init__()
@@ -3479,7 +3479,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
current_table_dia_edited = float(self.apertures_table.currentItem().text())
except ValueError as e:
log.debug("FlatCAMExcEditor.on_tool_edit() --> %s" % str(e))
self.apertures_table.setCurrentItem(None)
# self.apertures_table.setCurrentItem(None)
return
row_of_item_changed = self.apertures_table.currentRow()
@@ -3956,10 +3956,10 @@ class FlatCAMGrbEditor(QtCore.QObject):
global_clear_geo = []
# create one big geometry made out of all 'negative' (clear) polygons
for apid in app_obj.gerber_obj.apertures:
for aper_id in app_obj.gerber_obj.apertures:
# first check if we have any clear_geometry (LPC) and if yes added it to the global_clear_geo
if 'geometry' in app_obj.gerber_obj.apertures[apid]:
for elem in app_obj.gerber_obj.apertures[apid]['geometry']:
if 'geometry' in app_obj.gerber_obj.apertures[aper_id]:
for elem in app_obj.gerber_obj.apertures[aper_id]['geometry']:
if 'clear' in elem:
global_clear_geo.append(elem['clear'])
log.warning("Found %d clear polygons." % len(global_clear_geo))
@@ -3967,7 +3967,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
if global_clear_geo:
global_clear_geo = MultiPolygon(global_clear_geo)
if isinstance(global_clear_geo, Polygon):
global_clear_geo = list(global_clear_geo)
global_clear_geo = [global_clear_geo]
# we subtract the big "negative" (clear) geometry from each solid polygon but only the part of
# clear geometry that fits inside the solid. otherwise we may loose the solid
@@ -3979,8 +3979,8 @@ class FlatCAMGrbEditor(QtCore.QObject):
# solid_geo = elem['solid']
# for clear_geo in global_clear_geo:
# # Make sure that the clear_geo is within the solid_geo otherwise we loose
# # the solid_geometry. We want for clear_geometry just to cut into solid_geometry not to
# # delete it
# # the solid_geometry. We want for clear_geometry just to cut
# # into solid_geometry not to delete it
# if clear_geo.within(solid_geo):
# solid_geo = solid_geo.difference(clear_geo)
# try:
@@ -4307,14 +4307,14 @@ class FlatCAMGrbEditor(QtCore.QObject):
self.plot_all()
def toolbar_tool_toggle(self, key):
"""
:param key: key to update in self.options dictionary
:return:
"""
self.options[key] = self.sender().isChecked()
return self.options[key]
# def toolbar_tool_toggle(self, key):
# """
#
# :param key: key to update in self.options dictionary
# :return:
# """
# self.options[key] = self.sender().isChecked()
# return self.options[key]
def on_grb_shape_complete(self, storage=None, specific_shape=None, no_plot=False):
"""
@@ -4389,12 +4389,12 @@ class FlatCAMGrbEditor(QtCore.QObject):
"""
if self.app.is_legacy is False:
event_pos = event.pos
event_is_dragging = event.is_dragging
right_button = 2
# event_is_dragging = event.is_dragging
# right_button = 2
else:
event_pos = (event.xdata, event.ydata)
event_is_dragging = self.app.plotcanvas.is_dragging
right_button = 3
# event_is_dragging = self.app.plotcanvas.is_dragging
# right_button = 3
self.pos = self.canvas.translate_coords(event_pos)
@@ -4457,11 +4457,11 @@ class FlatCAMGrbEditor(QtCore.QObject):
self.modifiers = QtWidgets.QApplication.keyboardModifiers()
if self.app.is_legacy is False:
event_pos = event.pos
event_is_dragging = event.is_dragging
# event_is_dragging = event.is_dragging
right_button = 2
else:
event_pos = (event.xdata, event.ydata)
event_is_dragging = self.app.plotcanvas.is_dragging
# event_is_dragging = self.app.plotcanvas.is_dragging
right_button = 3
pos_canvas = self.canvas.translate_coords(event_pos)
@@ -4747,10 +4747,10 @@ class FlatCAMGrbEditor(QtCore.QObject):
Plots a geometric object or list of objects without rendering. Plotted objects
are returned as a list. This allows for efficient/animated rendering.
:param geometry: Geometry to be plotted (Any Shapely.geom kind or list of such)
:param color: Shape color
:param linewidth: Width of lines in # of pixels.
:return: List of plotted elements.
:param geometry: Geometry to be plotted (Any Shapely.geom kind or list of such)
:param color: Shape color
:param linewidth: Width of lines in # of pixels.
:return: List of plotted elements.
"""
if geometry is None:
@@ -5597,7 +5597,7 @@ class TransformEditorTool(FlatCAMTool):
self.flip_ref_entry.set_value((0, 0))
def template(self):
if not self.fcdraw.selected:
if not self.draw_app.selected:
self.app.inform.emit('[WARNING_NOTCL] %s' % _("Cancelled. No shape selected."))
return