- upgraded the UI of Region sub-tool in the Gerber Editor
This commit is contained in:
@@ -19,6 +19,7 @@ from appEditors.grb_plugins.GrbPadArrayPlugin import GrbPadArrayEditorTool
|
||||
from appEditors.grb_plugins.GrbTrackPlugin import GrbTrackEditorTool
|
||||
from appEditors.grb_plugins.GrbSimplificationPlugin import SimplificationTool
|
||||
from appEditors.grb_plugins.GrbCopyPlugin import CopyEditorTool
|
||||
from appEditors.grb_plugins.GrberRegionPlugin import GrbRegionEditorTool
|
||||
|
||||
# import inspect
|
||||
|
||||
@@ -1110,25 +1111,11 @@ class RegionEditorGrb(ShapeToolEditorGrb):
|
||||
DrawTool.__init__(self, draw_app)
|
||||
self.name = 'region'
|
||||
self.draw_app = draw_app
|
||||
self.app = self.draw_app.app
|
||||
self.dont_execute = False
|
||||
|
||||
self.steps_per_circle = self.draw_app.app.options["gerber_circle_steps"]
|
||||
|
||||
# try:
|
||||
# size_ap = float(self.draw_app.storage_dict[self.draw_app.last_aperture_selected]['size'])
|
||||
# except KeyError:
|
||||
# msg = '[ERROR_NOTCL] %s' % _("You need to preselect a aperture in the Aperture Table that has a size.")
|
||||
# self.draw_app.app.inform.emit(msg)
|
||||
# try:
|
||||
# QtGui.QGuiApplication.restoreOverrideCursor()
|
||||
# except Exception:
|
||||
# pass
|
||||
# self.dont_execute = True
|
||||
# self.draw_app.in_action = False
|
||||
# self.complete = True
|
||||
# self.draw_app.select_tool('select')
|
||||
# return
|
||||
|
||||
# regions are added always in the 0 aperture
|
||||
if 0 not in self.draw_app.storage_dict:
|
||||
self.draw_app.on_aperture_add(apcode=0)
|
||||
@@ -1152,18 +1139,37 @@ class RegionEditorGrb(ShapeToolEditorGrb):
|
||||
self.cursor = QtGui.QCursor(QtGui.QPixmap(self.draw_app.app.resource_location + '/aero.png'))
|
||||
QtGui.QGuiApplication.setOverrideCursor(self.cursor)
|
||||
|
||||
if self.app.use_3d_engine:
|
||||
self.draw_app.app.plotcanvas.view.camera.zoom_callback = self.draw_cursor_data
|
||||
self.draw_app.app.jump_signal.connect(lambda x: self.draw_app.update_utility_geometry(data=x))
|
||||
|
||||
self.reg_tool = GrbRegionEditorTool(self.app, self.draw_app, plugin_name=_("Region"))
|
||||
self.reg_tool.run()
|
||||
self.reg_tool.length = self.draw_app.last_length
|
||||
self.ui = self.reg_tool.ui
|
||||
|
||||
self.set_plugin_ui()
|
||||
|
||||
self.draw_app.app.jump_signal.connect(lambda x: self.draw_app.update_utility_geometry(data=x))
|
||||
|
||||
self.draw_app.app.inform.emit(_('Corner Mode 1: 45 degrees ...'))
|
||||
|
||||
self.start_msg = _("Click on 1st point ...")
|
||||
|
||||
def set_plugin_ui(self):
|
||||
dia = float(self.draw_app.storage_dict[self.draw_app.last_aperture_selected]['size'])
|
||||
self.ui.dia_entry.set_value(dia)
|
||||
self.ui.x_entry.set_value(float(self.draw_app.snap_x))
|
||||
self.ui.y_entry.set_value(float(self.draw_app.snap_y))
|
||||
|
||||
def click(self, point):
|
||||
self.draw_app.in_action = True
|
||||
|
||||
if self.inter_point is not None:
|
||||
self.points.append(self.inter_point)
|
||||
self.points.append(point)
|
||||
self.draw_app.last_length = self.reg_tool.length
|
||||
self.ui.x_entry.set_value(float(self.draw_app.snap_x))
|
||||
self.ui.y_entry.set_value(float(self.draw_app.snap_y))
|
||||
|
||||
if len(self.points) > 0:
|
||||
self.draw_app.app.inform.emit(_("Click on next Point or click right mouse button to complete ..."))
|
||||
@@ -1392,6 +1398,56 @@ class RegionEditorGrb(ShapeToolEditorGrb):
|
||||
|
||||
self.draw_app.app.inform.emit('[success] %s' % _("Done."))
|
||||
|
||||
def draw_cursor_data(self, pos=None, delete=False):
|
||||
if pos is None:
|
||||
pos = self.draw_app.snap_x, self.draw_app.snap_y
|
||||
|
||||
if delete:
|
||||
if self.draw_app.app.use_3d_engine:
|
||||
self.draw_app.app.plotcanvas.text_cursor.parent = None
|
||||
self.draw_app.app.plotcanvas.view.camera.zoom_callback = lambda *args: None
|
||||
return
|
||||
|
||||
# font size
|
||||
qsettings = QtCore.QSettings("Open Source", "FlatCAM")
|
||||
if qsettings.contains("hud_font_size"):
|
||||
fsize = qsettings.value('hud_font_size', type=int)
|
||||
else:
|
||||
fsize = 8
|
||||
|
||||
old_x = self.ui.x_entry.get_value()
|
||||
old_y = self.ui.y_entry.get_value()
|
||||
|
||||
x = pos[0]
|
||||
y = pos[1]
|
||||
try:
|
||||
length = abs(np.sqrt((x - old_x) ** 2 + (y - old_y) ** 2))
|
||||
except IndexError:
|
||||
length = self.draw_app.app.dec_format(0.0, self.draw_app.app.decimals)
|
||||
units = self.draw_app.app.app_units.lower()
|
||||
|
||||
x_dec = str(self.draw_app.app.dec_format(x, self.draw_app.app.decimals)) if x else '0.0'
|
||||
y_dec = str(self.draw_app.app.dec_format(y, self.draw_app.app.decimals)) if y else '0.0'
|
||||
length_dec = str(self.draw_app.app.dec_format(length, self.draw_app.app.decimals)) if length else '0.0'
|
||||
|
||||
l1_txt = 'X: %s [%s]' % (x_dec, units)
|
||||
l2_txt = 'Y: %s [%s]' % (y_dec, units)
|
||||
l3_txt = 'L: %s [%s]' % (length_dec, units)
|
||||
cursor_text = '%s\n%s\n\n%s' % (l1_txt, l2_txt, l3_txt)
|
||||
|
||||
if self.draw_app.app.use_3d_engine:
|
||||
new_pos = self.draw_app.app.plotcanvas.translate_coords_2((x, y))
|
||||
x, y, __, ___ = self.draw_app.app.plotcanvas.translate_coords((new_pos[0]+30, new_pos[1]))
|
||||
|
||||
# text
|
||||
self.draw_app.app.plotcanvas.text_cursor.font_size = fsize
|
||||
self.draw_app.app.plotcanvas.text_cursor.text = cursor_text
|
||||
self.draw_app.app.plotcanvas.text_cursor.pos = x, y
|
||||
self.draw_app.app.plotcanvas.text_cursor.anchors = 'left', 'top'
|
||||
|
||||
if self.draw_app.app.plotcanvas.text_cursor.parent is None:
|
||||
self.draw_app.app.plotcanvas.text_cursor.parent = self.draw_app.app.plotcanvas.view.scene
|
||||
|
||||
def on_key(self, key):
|
||||
# Jump to coords
|
||||
if key == QtCore.Qt.Key.Key_J or key == 'J':
|
||||
@@ -1457,6 +1513,56 @@ class RegionEditorGrb(ShapeToolEditorGrb):
|
||||
|
||||
return msg
|
||||
|
||||
if key in [str(i) for i in range(10)] + ['.', ',', '+', '-', '/', '*'] or \
|
||||
key in [QtCore.Qt.Key.Key_0, QtCore.Qt.Key.Key_0, QtCore.Qt.Key.Key_1, QtCore.Qt.Key.Key_2,
|
||||
QtCore.Qt.Key.Key_3, QtCore.Qt.Key.Key_4, QtCore.Qt.Key.Key_5, QtCore.Qt.Key.Key_6,
|
||||
QtCore.Qt.Key.Key_7, QtCore.Qt.Key.Key_8, QtCore.Qt.Key.Key_9, QtCore.Qt.Key.Key_Minus,
|
||||
QtCore.Qt.Key.Key_Plus, QtCore.Qt.Key.Key_Comma, QtCore.Qt.Key.Key_Period,
|
||||
QtCore.Qt.Key.Key_Slash, QtCore.Qt.Key.Key_Asterisk]:
|
||||
try:
|
||||
# VisPy keys
|
||||
if self.reg_tool.length == self.draw_app.last_length:
|
||||
self.reg_tool.length = str(key.name)
|
||||
else:
|
||||
self.reg_tool.length = str(self.reg_tool.length) + str(key.name)
|
||||
except AttributeError:
|
||||
# Qt keys
|
||||
if self.reg_tool.length == self.draw_app.last_length:
|
||||
self.reg_tool.length = chr(key)
|
||||
else:
|
||||
self.reg_tool.length = str(self.reg_tool.length) + chr(key)
|
||||
|
||||
if key == 'Enter' or key == QtCore.Qt.Key.Key_Return or key == QtCore.Qt.Key.Key_Enter:
|
||||
if self.reg_tool.length != 0:
|
||||
target_length = self.reg_tool.length
|
||||
if target_length is None:
|
||||
self.reg_tool.length = 0.0
|
||||
return _("Failed.")
|
||||
|
||||
first_pt = self.ui.x_entry.get_value(), self.ui.y_entry.get_value()
|
||||
last_pt = self.draw_app.app.mouse_pos
|
||||
|
||||
seg_length = math.sqrt((last_pt[0] - first_pt[0])**2 + (last_pt[1] - first_pt[1])**2)
|
||||
if seg_length == 0.0:
|
||||
self.draw_app.app.log.debug("GrbRegionEditorGrb.on_key() --> 'ENTER'. Segment is zero.")
|
||||
return
|
||||
try:
|
||||
new_x = first_pt[0] + (last_pt[0] - first_pt[0]) / seg_length * target_length
|
||||
new_y = first_pt[1] + (last_pt[1] - first_pt[1]) / seg_length * target_length
|
||||
except ZeroDivisionError as err:
|
||||
self.clean_up()
|
||||
return '[ERROR_NOTCL] %s %s' % (_("Failed."), str(err).capitalize())
|
||||
|
||||
if first_pt != (new_x, new_y):
|
||||
self.draw_app.app.on_jump_to(custom_location=(new_x, new_y), fit_center=False)
|
||||
if len(self.points) > 0:
|
||||
msg = '%s: %s. %s' % (
|
||||
_("Projected"), str(self.reg_tool.length),
|
||||
_("Click on next Point or click right mouse button to complete ..."))
|
||||
self.draw_app.app.inform.emit(msg)
|
||||
# self.interpolate_length = ''
|
||||
# return "Click on next point or hit ENTER to complete ..."
|
||||
|
||||
def clean_up(self):
|
||||
self.draw_app.selected = []
|
||||
self.draw_app.ui.apertures_table.clearSelection()
|
||||
@@ -5914,7 +6020,7 @@ class AppGerberEditor(QtCore.QObject):
|
||||
|
||||
self.update_utility_geometry(data=(x, y))
|
||||
if self.active_tool.name in [
|
||||
'pad', 'array', 'track'
|
||||
'pad', 'array', 'track', 'region'
|
||||
]:
|
||||
try:
|
||||
self.active_tool.draw_cursor_data(pos=self.app.mouse_pos)
|
||||
|
||||
Reference in New Issue
Block a user