- Geometry Editor: made the tool to be able to continuously move until the tool is exited either by ESC key or by right mouse button click

- Geometry Editor Move Tool: if no shape is selected when triggering this tool, now it is possible to make the selection inside the tool
- Gerber editor Move Tool: fixed a bug that repeated the plotting function unnecessarily
- Gerber editor Move Tool: if no shape is selected the tool will exit
This commit is contained in:
Marius Stanciu
2019-05-08 20:01:06 +03:00
parent 0a150fba79
commit 28fce82432
4 changed files with 163 additions and 46 deletions

View File

@@ -2,6 +2,7 @@ from PyQt5 import QtGui, QtCore, QtWidgets
from PyQt5.QtCore import Qt, QSettings
from shapely.geometry import LineString, LinearRing, MultiLineString
# from shapely.geometry import mapping
from shapely.ops import cascaded_union, unary_union
import shapely.affinity as affinity
@@ -19,6 +20,9 @@ from FlatCAMTool import FlatCAMTool
from numpy.linalg import norm as numpy_norm
# from vispy.io import read_png
# import pngcanvas
import gettext
import FlatCAMTranslation as fcTranslate
@@ -1449,11 +1453,18 @@ class FCApertureMove(FCShapeTool):
self.destination = None
self.selected_apertures = []
if len(self.draw_app.get_selected()) == 0:
self.draw_app.app.inform.emit(_("[WARNING_NOTCL] Nothing selected to move ..."))
self.complete = True
self.draw_app.select_tool("select")
return
if self.draw_app.launched_from_shortcuts is True:
self.draw_app.launched_from_shortcuts = False
self.draw_app.app.inform.emit(_("Click on target location ..."))
else:
self.draw_app.app.inform.emit(_("Click on reference location ..."))
self.current_storage = None
self.geometry = []
@@ -1485,6 +1496,37 @@ class FCApertureMove(FCShapeTool):
self.draw_app.select_tool("select")
return
# def create_png(self):
# """
# Create a PNG file out of a list of Shapely polygons
# :return:
# """
# if len(self.draw_app.get_selected()) == 0:
# return None
#
# geo_list = [geoms.geo for geoms in self.draw_app.get_selected()]
# xmin, ymin, xmax, ymax = get_shapely_list_bounds(geo_list)
#
# iwidth = (xmax - xmin)
# iwidth = int(round(iwidth))
# iheight = (ymax - ymin)
# iheight = int(round(iheight))
# c = pngcanvas.PNGCanvas(iwidth, iheight)
#
# pixels = []
# for geom in self.draw_app.get_selected():
# m = mapping(geom.geo.exterior)
# pixels += [[coord[0], coord[1]] for coord in m['coordinates']]
# for g in geom.geo.interiors:
# m = mapping(g)
# pixels += [[coord[0], coord[1]] for coord in m['coordinates']]
# c.polyline(pixels)
# pixels = []
#
# f = open("%s.png" % 'D:\\shapely_image', "wb")
# f.write(c.dump())
# f.close()
def make(self):
# Create new geometry
dx = self.destination[0] - self.origin[0]
@@ -1499,13 +1541,14 @@ class FCApertureMove(FCShapeTool):
self.geometry.append(DrawToolShape(affinity.translate(select_shape.geo, xoff=dx, yoff=dy)))
self.current_storage.remove(select_shape)
sel_shapes_to_be_deleted.append(select_shape)
self.draw_app.on_grb_shape_complete(self.current_storage)
self.draw_app.on_grb_shape_complete(self.current_storage, noplot=True)
self.geometry = []
for shp in sel_shapes_to_be_deleted:
self.draw_app.selected.remove(shp)
sel_shapes_to_be_deleted = []
self.draw_app.plot_all()
self.draw_app.build_ui()
self.draw_app.app.inform.emit(_("[success] Done. Apertures Move completed."))
@@ -1531,8 +1574,9 @@ class FCApertureMove(FCShapeTool):
dx = data[0] - self.origin[0]
dy = data[1] - self.origin[1]
for geom in self.draw_app.get_selected():
geo_list.append(affinity.translate(geom.geo, xoff=dx, yoff=dy))
# for geom in self.draw_app.get_selected():
# geo_list.append(affinity.translate(geom.geo, xoff=dx, yoff=dy))
geo_list = [affinity.translate(geom.geo, xoff=dx, yoff=dy) for geom in self.draw_app.get_selected()]
return DrawToolUtilityShape(geo_list)
@@ -3188,7 +3232,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
self.options[key] = self.sender().isChecked()
return self.options[key]
def on_grb_shape_complete(self, storage=None, specific_shape=None):
def on_grb_shape_complete(self, storage=None, specific_shape=None, noplot=False):
self.app.log.debug("on_shape_complete()")
if specific_shape:
@@ -3209,8 +3253,9 @@ class FlatCAMGrbEditor(QtCore.QObject):
self.delete_utility_geometry()
self.tool_shape.clear(update=True)
# Replot and reset tool.
self.plot_all()
if noplot is False:
# Replot and reset tool.
self.plot_all()
def add_gerber_shape(self, shape, storage):
"""
@@ -4860,3 +4905,22 @@ class TransformEditorTool(FlatCAMTool):
else:
self.app.inform.emit(
_("[WARNING_NOTCL] Geometry shape skew Y cancelled..."))
def get_shapely_list_bounds(geometry_list):
xmin = Inf
ymin = Inf
xmax = -Inf
ymax = -Inf
for gs in geometry_list:
try:
gxmin, gymin, gxmax, gymax = gs.bounds
xmin = min([xmin, gxmin])
ymin = min([ymin, gymin])
xmax = max([xmax, gxmax])
ymax = max([ymax, gymax])
except:
log.warning("DEVELOPMENT: Tried to get bounds of empty geometry.")
return [xmin, ymin, xmax, ymax]