- moved the initialization of the FlatCAM editors after a read of the default values. If I don't do this then only at the first start of the application the Editors are not functional as the Editor objects are most likely destroyed

- fixed bug in FlatCAM editors that caused the shapes to be drawn without resolution when the app units where INCH
- modified the transformation functions in all classes in camlib.py and FlatCAMObj.py to work with empty geometries
This commit is contained in:
Marius Stanciu
2019-08-17 18:47:41 +03:00
parent d8937b82fc
commit b20203eace
8 changed files with 184 additions and 64 deletions

View File

@@ -1,3 +1,11 @@
# ##########################################################
# FlatCAM: 2D Post-processing for Manufacturing #
# http://flatcam.org #
# File Author: Marius Adrian Stanciu (c) #
# Date: 8/17/2019 #
# MIT Licence #
# ##########################################################
from PyQt5 import QtGui, QtCore, QtWidgets
from PyQt5.QtCore import Qt, QSettings
@@ -1945,6 +1953,11 @@ class FlatCAMExcEditor(QtCore.QObject):
# this var will store the state of the toolbar before starting the editor
self.toolbar_old_state = False
if self.units == 'MM':
self.tolerance = float(self.app.defaults["global_tolerance"])
else:
self.tolerance = float(self.app.defaults["global_tolerance"]) / 20
self.app.ui.delete_drill_btn.triggered.connect(self.on_delete_btn)
self.name_entry.returnPressed.connect(self.on_name_activate)
self.addtool_btn.clicked.connect(self.on_tool_add)
@@ -2048,6 +2061,7 @@ 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
log.debug("Initialization of the FlatCAM Excellon Editor is finished ...")
def pool_recreated(self, pool):
self.shapes.pool = pool
@@ -3727,7 +3741,7 @@ class FlatCAMExcEditor(QtCore.QObject):
plot_elements += self.plot_shape(geometry=geometry.interiors, color=color, linewidth=linewidth)
if type(geometry) == LineString or type(geometry) == LinearRing:
plot_elements.append(self.shapes.add(shape=geometry, color=color, layer=0))
plot_elements.append(self.shapes.add(shape=geometry, color=color, layer=0, tolerance=self.tolerance))
if type(geometry) == Point:
pass

View File

@@ -3118,6 +3118,7 @@ class FlatCAMGeoEditor(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
log.debug("Initialization of the FlatCAM Geometry Editor is finished ...")
def pool_recreated(self, pool):
self.shapes.pool = pool
@@ -3174,6 +3175,7 @@ class FlatCAMGeoEditor(QtCore.QObject):
# Tell the App that the editor is active
self.editor_active = True
log.debug("Finished activating the Geometry Editor...")
def deactivate(self):
try:
@@ -3253,6 +3255,7 @@ class FlatCAMGeoEditor(QtCore.QObject):
# Show original geometry
if self.fcgeometry:
self.fcgeometry.visible = True
log.debug("Finished deactivating the Geometry Editor...")
def connect_canvas_event_handlers(self):
# Canvas events

View File

@@ -1,3 +1,11 @@
# ##########################################################
# FlatCAM: 2D Post-processing for Manufacturing #
# http://flatcam.org #
# File Author: Marius Adrian Stanciu (c) #
# Date: 8/17/2019 #
# MIT Licence #
# ##########################################################
from PyQt5 import QtGui, QtCore, QtWidgets
from PyQt5.QtCore import Qt, QSettings
@@ -839,6 +847,8 @@ class FCRegion(FCShapeTool):
self.name = 'region'
self.draw_app = draw_app
self.steps_per_circle = self.draw_app.app.defaults["gerber_circle_steps"]
size_ap = float(self.draw_app.storage_dict[self.draw_app.last_aperture_selected]['size'])
self.buf_val = (size_ap / 2) if size_ap > 0 else 0.0000001
@@ -885,7 +895,7 @@ class FCRegion(FCShapeTool):
y = data[1]
if len(self.points) == 0:
new_geo_el['solid'] = Point(data).buffer(self.buf_val)
new_geo_el['solid'] = Point(data).buffer(self.buf_val, resolution=int(self.steps_per_circle / 4))
return DrawToolUtilityShape(new_geo_el)
if len(self.points) == 1:
@@ -951,12 +961,15 @@ class FCRegion(FCShapeTool):
if len(self.temp_points) > 1:
try:
new_geo_el['solid'] = LineString(self.temp_points).buffer(self.buf_val, join_style=1)
new_geo_el['solid'] = LineString(self.temp_points).buffer(self.buf_val,
resolution=int(self.steps_per_circle / 4),
join_style=1)
return DrawToolUtilityShape(new_geo_el)
except Exception as e:
log.debug("FlatCAMGrbEditor.FCRegion.utility_geometry() --> %s" % str(e))
else:
new_geo_el['solid'] = Point(self.temp_points).buffer(self.buf_val)
new_geo_el['solid'] = Point(self.temp_points).buffer(self.buf_val,
resolution=int(self.steps_per_circle / 4))
return DrawToolUtilityShape(new_geo_el)
if len(self.points) > 2:
@@ -1012,7 +1025,9 @@ class FCRegion(FCShapeTool):
self.temp_points.append(data)
new_geo_el = dict()
new_geo_el['solid'] = LinearRing(self.temp_points).buffer(self.buf_val, join_style=1)
new_geo_el['solid'] = LinearRing(self.temp_points).buffer(self.buf_val,
resolution=int(self.steps_per_circle / 4),
join_style=1)
new_geo_el['follow'] = LinearRing(self.temp_points)
return DrawToolUtilityShape(new_geo_el)
@@ -1031,7 +1046,9 @@ class FCRegion(FCShapeTool):
new_geo_el = dict()
new_geo_el['solid'] = Polygon(self.points).buffer(self.buf_val, join_style=2)
new_geo_el['solid'] = Polygon(self.points).buffer(self.buf_val,
resolution=int(self.steps_per_circle / 4),
join_style=2)
new_geo_el['follow'] = Polygon(self.points).exterior
self.geometry = DrawToolShape(new_geo_el)
@@ -1128,10 +1145,12 @@ class FCTrack(FCRegion):
def make(self):
new_geo_el = dict()
if len(self.temp_points) == 1:
new_geo_el['solid'] = Point(self.temp_points).buffer(self.buf_val)
new_geo_el['solid'] = Point(self.temp_points).buffer(self.buf_val,
resolution=int(self.steps_per_circle / 4))
new_geo_el['follow'] = Point(self.temp_points)
else:
new_geo_el['solid'] = (LineString(self.temp_points).buffer(self.buf_val)).buffer(0)
new_geo_el['solid'] = (LineString(self.temp_points).buffer(
self.buf_val, resolution=int(self.steps_per_circle / 4))).buffer(0)
new_geo_el['follow'] = LineString(self.temp_points)
self.geometry = DrawToolShape(new_geo_el)
@@ -1156,10 +1175,12 @@ class FCTrack(FCRegion):
new_geo_el = dict()
if len(self.temp_points) == 1:
new_geo_el['solid'] = Point(self.temp_points).buffer(self.buf_val)
new_geo_el['solid'] = Point(self.temp_points).buffer(self.buf_val,
resolution=int(self.steps_per_circle / 4))
new_geo_el['follow'] = Point(self.temp_points)
else:
new_geo_el['solid'] = LineString(self.temp_points).buffer(self.buf_val)
new_geo_el['solid'] = LineString(self.temp_points).buffer(self.buf_val,
resolution=int(self.steps_per_circle / 4))
new_geo_el['follow'] = LineString(self.temp_points)
self.draw_app.add_gerber_shape(DrawToolShape(new_geo_el),
@@ -1177,7 +1198,8 @@ class FCTrack(FCRegion):
new_geo_el = dict()
if len(self.points) == 0:
new_geo_el['solid'] = Point(data).buffer(self.buf_val)
new_geo_el['solid'] = Point(data).buffer(self.buf_val,
resolution=int(self.steps_per_circle / 4))
return DrawToolUtilityShape(new_geo_el)
elif len(self.points) > 0:
@@ -1235,10 +1257,12 @@ class FCTrack(FCRegion):
self.temp_points.append(data)
if len(self.temp_points) == 1:
new_geo_el['solid'] = Point(self.temp_points).buffer(self.buf_val)
new_geo_el['solid'] = Point(self.temp_points).buffer(self.buf_val,
resolution=int(self.steps_per_circle / 4))
return DrawToolUtilityShape(new_geo_el)
new_geo_el['solid'] = LineString(self.temp_points).buffer(self.buf_val)
new_geo_el['solid'] = LineString(self.temp_points).buffer(self.buf_val,
resolution=int(self.steps_per_circle / 4))
return DrawToolUtilityShape(new_geo_el)
def on_key(self, key):
@@ -2802,6 +2826,11 @@ class FlatCAMGrbEditor(QtCore.QObject):
# this will flag if the Editor "tools" are launched from key shortcuts (True) or from menu toolbar (False)
self.launched_from_shortcuts = False
if self.units == 'MM':
self.tolerance = float(self.app.defaults["global_tolerance"])
else:
self.tolerance = float(self.app.defaults["global_tolerance"]) / 20
def make_callback(the_tool):
def f():
self.on_tool_select(the_tool)
@@ -2887,6 +2916,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
self.conversion_factor = 1
self.set_ui()
log.debug("Initialization of the FlatCAM Gerber Editor is finished ...")
def pool_recreated(self, pool):
self.shapes.pool = pool
@@ -4372,11 +4402,11 @@ class FlatCAMGrbEditor(QtCore.QObject):
geometry = self.active_tool.geometry
try:
self.shapes.add(shape=geometry.geo, color=color, face_color=color, layer=0)
self.shapes.add(shape=geometry.geo, color=color, face_color=color, layer=0, tolerance=self.tolerance)
except AttributeError:
if type(geometry) == Point:
return
self.shapes.add(shape=geometry, color=color, face_color=color+'AF', layer=0)
self.shapes.add(shape=geometry, color=color, face_color=color+'AF', layer=0, tolerance=self.tolerance)
def start_delayed_plot(self, check_period):
"""