- 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:
@@ -7,7 +7,6 @@
|
||||
# ########################################################## ##
|
||||
|
||||
from camlib import Geometry
|
||||
import FlatCAMApp
|
||||
|
||||
import shapely.affinity as affinity
|
||||
from shapely.geometry import Point, LineString
|
||||
@@ -19,6 +18,7 @@ import traceback
|
||||
from copy import deepcopy
|
||||
|
||||
import FlatCAMTranslation as fcTranslate
|
||||
from FlatCAMCommon import GracefulException as grace
|
||||
|
||||
import gettext
|
||||
import builtins
|
||||
@@ -86,6 +86,7 @@ class Excellon(Geometry):
|
||||
:return: Excellon object.
|
||||
:rtype: Excellon
|
||||
"""
|
||||
|
||||
self.decimals = self.app.decimals
|
||||
|
||||
if geo_steps_per_circle is None:
|
||||
@@ -241,12 +242,12 @@ class Excellon(Geometry):
|
||||
|
||||
def parse_file(self, filename=None, file_obj=None):
|
||||
"""
|
||||
Reads the specified file as array of lines as
|
||||
passes it to ``parse_lines()``.
|
||||
Reads the specified file as array of lines as passes it to ``parse_lines()``.
|
||||
|
||||
:param filename: The file to be read and parsed.
|
||||
:type filename: str
|
||||
:return: None
|
||||
:param filename: The file to be read and parsed.
|
||||
:param file_obj:
|
||||
:type filename: str
|
||||
:return: None
|
||||
"""
|
||||
if file_obj:
|
||||
estr = file_obj
|
||||
@@ -298,7 +299,7 @@ class Excellon(Geometry):
|
||||
for eline in elines:
|
||||
if self.app.abort_flag:
|
||||
# graceful abort requested by the user
|
||||
raise FlatCAMApp.GracefulException
|
||||
raise grace
|
||||
|
||||
line_num += 1
|
||||
# log.debug("%3d %s" % (line_num, str(eline)))
|
||||
@@ -526,7 +527,7 @@ class Excellon(Geometry):
|
||||
slot_dia = 0.05
|
||||
try:
|
||||
slot_dia = float(self.tools[current_tool]['C'])
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
pass
|
||||
log.debug(
|
||||
'Milling/Drilling slot with tool %s, diam=%f' % (
|
||||
@@ -596,7 +597,7 @@ class Excellon(Geometry):
|
||||
slot_dia = 0.05
|
||||
try:
|
||||
slot_dia = float(self.tools[current_tool]['C'])
|
||||
except Exception as e:
|
||||
except Exception:
|
||||
pass
|
||||
log.debug(
|
||||
'Milling/Drilling slot with tool %s, diam=%f' % (
|
||||
@@ -893,9 +894,8 @@ class Excellon(Geometry):
|
||||
log.info("Zeros: %s, Units %s." % (self.zeros, self.units))
|
||||
except Exception:
|
||||
log.error("Excellon PARSING FAILED. Line %d: %s" % (line_num, eline))
|
||||
msg = '[ERROR_NOTCL] %s' % \
|
||||
_("An internal error has ocurred. See shell.\n")
|
||||
msg += ('{e_code} {tx} {l_nr}: {line}\n').format(
|
||||
msg = '[ERROR_NOTCL] %s' % _("An internal error has occurred. See shell.\n")
|
||||
msg += '{e_code} {tx} {l_nr}: {line}\n'.format(
|
||||
e_code='[ERROR]',
|
||||
tx=_("Excellon Parser error.\nParsing Failed. Line"),
|
||||
l_nr=line_num,
|
||||
@@ -1010,13 +1010,13 @@ class Excellon(Geometry):
|
||||
"Excellon geometry creation failed due of ERROR: %s" % str(e))
|
||||
return "fail"
|
||||
|
||||
def bounds(self):
|
||||
def bounds(self, flatten=None):
|
||||
"""
|
||||
Returns coordinates of rectangular bounds
|
||||
of Excellon geometry: (xmin, ymin, xmax, ymax).
|
||||
|
||||
:param flatten: No used
|
||||
"""
|
||||
# fixed issue of getting bounds only for one level lists of objects
|
||||
# now it can get bounds for nested lists of objects
|
||||
|
||||
log.debug("flatcamParsers.ParseExcellon.Excellon.bounds()")
|
||||
|
||||
@@ -1056,11 +1056,11 @@ class Excellon(Geometry):
|
||||
maxy_list = []
|
||||
|
||||
for tool in self.tools:
|
||||
minx, miny, maxx, maxy = bounds_rec(self.tools[tool]['solid_geometry'])
|
||||
minx_list.append(minx)
|
||||
miny_list.append(miny)
|
||||
maxx_list.append(maxx)
|
||||
maxy_list.append(maxy)
|
||||
eminx, eminy, emaxx, emaxy = bounds_rec(self.tools[tool]['solid_geometry'])
|
||||
minx_list.append(eminx)
|
||||
miny_list.append(eminy)
|
||||
maxx_list.append(emaxx)
|
||||
maxy_list.append(emaxy)
|
||||
|
||||
return min(minx_list), min(miny_list), max(maxx_list), max(maxy_list)
|
||||
|
||||
@@ -1075,8 +1075,9 @@ class Excellon(Geometry):
|
||||
|
||||
Kind of convolute way to make the conversion and it is based on the assumption that the Excellon file
|
||||
will have detected the units before the tools are parsed and stored in self.tools
|
||||
:param units:
|
||||
:type str: IN or MM
|
||||
|
||||
:param units: 'IN' or 'MM'. String
|
||||
|
||||
:return:
|
||||
"""
|
||||
|
||||
@@ -1109,12 +1110,13 @@ class Excellon(Geometry):
|
||||
Scales geometry on the XY plane in the object by a given factor.
|
||||
Tool sizes, feedrates an Z-plane dimensions are untouched.
|
||||
|
||||
:param xfactor: Number by which to scale the object.
|
||||
:type xfactor: float
|
||||
:param yfactor: Number by which to scale the object.
|
||||
:type yfactor: float
|
||||
:return: None
|
||||
:rtype: NOne
|
||||
:param xfactor: Number by which to scale the object.
|
||||
:type xfactor: float
|
||||
:param yfactor: Number by which to scale the object.
|
||||
:type yfactor: float
|
||||
:param point: Origin point for scale
|
||||
:return: None
|
||||
:rtype: None
|
||||
"""
|
||||
log.debug("flatcamParsers.ParseExcellon.Excellon.scale()")
|
||||
|
||||
@@ -1145,8 +1147,7 @@ class Excellon(Geometry):
|
||||
# variables to display the percentage of work done
|
||||
self.geo_len = 0
|
||||
try:
|
||||
for g in self.drills:
|
||||
self.geo_len += 1
|
||||
self.geo_len = len(self.drills)
|
||||
except TypeError:
|
||||
self.geo_len = 1
|
||||
self.old_disp_number = 0
|
||||
@@ -1190,12 +1191,12 @@ class Excellon(Geometry):
|
||||
return
|
||||
|
||||
def offset_geom(obj):
|
||||
if type(obj) is list:
|
||||
try:
|
||||
new_obj = []
|
||||
for g in obj:
|
||||
new_obj.append(offset_geom(g))
|
||||
for geo in obj:
|
||||
new_obj.append(offset_geom(geo))
|
||||
return new_obj
|
||||
else:
|
||||
except TypeError:
|
||||
try:
|
||||
return affinity.translate(obj, xoff=dx, yoff=dy)
|
||||
except AttributeError:
|
||||
@@ -1204,8 +1205,7 @@ class Excellon(Geometry):
|
||||
# variables to display the percentage of work done
|
||||
self.geo_len = 0
|
||||
try:
|
||||
for g in self.drills:
|
||||
self.geo_len += 1
|
||||
self.geo_len = len(self.drills)
|
||||
except TypeError:
|
||||
self.geo_len = 1
|
||||
self.old_disp_number = 0
|
||||
@@ -1237,11 +1237,11 @@ class Excellon(Geometry):
|
||||
def mirror(self, axis, point):
|
||||
"""
|
||||
|
||||
:param axis: "X" or "Y" indicates around which axis to mirror.
|
||||
:type axis: str
|
||||
:param point: [x, y] point belonging to the mirror axis.
|
||||
:type point: list
|
||||
:return: None
|
||||
:param axis: "X" or "Y" indicates around which axis to mirror.
|
||||
:type axis: str
|
||||
:param point: [x, y] point belonging to the mirror axis.
|
||||
:type point: list
|
||||
:return: None
|
||||
"""
|
||||
log.debug("flatcamParsers.ParseExcellon.Excellon.mirror()")
|
||||
|
||||
@@ -1249,12 +1249,12 @@ class Excellon(Geometry):
|
||||
xscale, yscale = {"X": (1.0, -1.0), "Y": (-1.0, 1.0)}[axis]
|
||||
|
||||
def mirror_geom(obj):
|
||||
if type(obj) is list:
|
||||
try:
|
||||
new_obj = []
|
||||
for g in obj:
|
||||
new_obj.append(mirror_geom(g))
|
||||
for geo in obj:
|
||||
new_obj.append(mirror_geom(geo))
|
||||
return new_obj
|
||||
else:
|
||||
except TypeError:
|
||||
try:
|
||||
return affinity.scale(obj, xscale, yscale, origin=(px, py))
|
||||
except AttributeError:
|
||||
@@ -1265,8 +1265,7 @@ class Excellon(Geometry):
|
||||
# variables to display the percentage of work done
|
||||
self.geo_len = 0
|
||||
try:
|
||||
for g in self.drills:
|
||||
self.geo_len += 1
|
||||
self.geo_len = len(self.drills)
|
||||
except TypeError:
|
||||
self.geo_len = 1
|
||||
self.old_disp_number = 0
|
||||
@@ -1300,12 +1299,12 @@ class Excellon(Geometry):
|
||||
Shear/Skew the geometries of an object by angles along x and y dimensions.
|
||||
Tool sizes, feedrates an Z-plane dimensions are untouched.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
xs, ys : float, float
|
||||
:param angle_x:
|
||||
:param angle_y:
|
||||
The shear angle(s) for the x and y axes respectively. These can be
|
||||
specified in either degrees (default) or radians by setting
|
||||
use_radians=True.
|
||||
:param point: Origin point for Skew
|
||||
|
||||
See shapely manual for more information:
|
||||
http://toblerity.org/shapely/manual.html#affine-transformations
|
||||
@@ -1322,12 +1321,12 @@ class Excellon(Geometry):
|
||||
return
|
||||
|
||||
def skew_geom(obj):
|
||||
if type(obj) is list:
|
||||
try:
|
||||
new_obj = []
|
||||
for g in obj:
|
||||
new_obj.append(skew_geom(g))
|
||||
return new_obj
|
||||
else:
|
||||
except TypeError:
|
||||
try:
|
||||
return affinity.skew(obj, angle_x, angle_y, origin=(px, py))
|
||||
except AttributeError:
|
||||
@@ -1336,8 +1335,7 @@ class Excellon(Geometry):
|
||||
# variables to display the percentage of work done
|
||||
self.geo_len = 0
|
||||
try:
|
||||
for g in self.drills:
|
||||
self.geo_len += 1
|
||||
self.geo_len = len(self.drills)
|
||||
except TypeError:
|
||||
self.geo_len = 1
|
||||
self.old_disp_number = 0
|
||||
@@ -1393,9 +1391,10 @@ class Excellon(Geometry):
|
||||
def rotate(self, angle, point=None):
|
||||
"""
|
||||
Rotate the geometry of an object by an angle around the 'point' coordinates
|
||||
|
||||
:param angle:
|
||||
:param point: tuple of coordinates (x, y)
|
||||
:return:
|
||||
:param point: tuple of coordinates (x, y)
|
||||
:return: None
|
||||
"""
|
||||
log.debug("flatcamParsers.ParseExcellon.Excellon.rotate()")
|
||||
|
||||
@@ -1423,8 +1422,7 @@ class Excellon(Geometry):
|
||||
# variables to display the percentage of work done
|
||||
self.geo_len = 0
|
||||
try:
|
||||
for g in self.drills:
|
||||
self.geo_len += 1
|
||||
self.geo_len = len(self.drills)
|
||||
except TypeError:
|
||||
self.geo_len = 1
|
||||
self.old_disp_number = 0
|
||||
@@ -1476,9 +1474,10 @@ class Excellon(Geometry):
|
||||
def buffer(self, distance, join, factor):
|
||||
"""
|
||||
|
||||
:param distance: if 'factor' is True then distance is the factor
|
||||
:param factor: True or False (None)
|
||||
:return:
|
||||
:param distance: if 'factor' is True then distance is the factor
|
||||
:param factor: True or False (None)
|
||||
:param join: The type of line joint used by the shapely buffer method: round, square, bevel
|
||||
:return: None
|
||||
"""
|
||||
log.debug("flatcamParsers.ParseExcellon.Excellon.buffer()")
|
||||
|
||||
@@ -1486,12 +1485,12 @@ class Excellon(Geometry):
|
||||
return
|
||||
|
||||
def buffer_geom(obj):
|
||||
if type(obj) is list:
|
||||
try:
|
||||
new_obj = []
|
||||
for g in obj:
|
||||
new_obj.append(buffer_geom(g))
|
||||
return new_obj
|
||||
else:
|
||||
except TypeError:
|
||||
try:
|
||||
if factor is None:
|
||||
return obj.buffer(distance, resolution=self.geo_steps_per_circle)
|
||||
|
||||
Reference in New Issue
Block a user