- Gerber Editor: reduced the delay to show UI when editing an empty Gerber object

- update the order of event handlers connection in Editors to first connect new handlers then disconnect old handlers. It seems that if nothing is connected some VispY functions like canvas panning no longer works if there is at least once nothing connected to the 'mouse_move' event
- Excellon Editor: update so always there is a tool selected even after the Execllon object was just edited; before it always required a click inside of the tool table, not you do it only if needed.
- fixed the menu File -> Edit -> Edit/Close Editor entry to reflect the status of the app (Editor active or not)
This commit is contained in:
Marius Stanciu 2019-04-15 16:19:30 +03:00 committed by Marius
parent 348fe4f135
commit d7cb8a5825
5 changed files with 151 additions and 90 deletions

View File

@ -2093,12 +2093,9 @@ class App(QtCore.QObject):
if isinstance(edited_object, FlatCAMGerber) or isinstance(edited_object, FlatCAMGeometry) or \ if isinstance(edited_object, FlatCAMGerber) or isinstance(edited_object, FlatCAMGeometry) or \
isinstance(edited_object, FlatCAMExcellon): isinstance(edited_object, FlatCAMExcellon):
pass
# adjust the status of the menu entries related to the editor
self.ui.menueditedit.setDisabled(True)
self.ui.menueditok.setDisabled(False)
else: else:
self.inform.emit(_("[WARNING_NOTCL] Select a Geometry or Excellon Object to edit.")) self.inform.emit(_("[WARNING_NOTCL] Select a Geometry, Gerber or Excellon Object to edit."))
return return
if isinstance(edited_object, FlatCAMGeometry): if isinstance(edited_object, FlatCAMGeometry):
@ -2109,7 +2106,8 @@ class App(QtCore.QObject):
edited_tools = [int(x.text()) for x in edited_object.ui.geo_tools_table.selectedItems()] edited_tools = [int(x.text()) for x in edited_object.ui.geo_tools_table.selectedItems()]
if len(edited_tools) > 1: if len(edited_tools) > 1:
self.inform.emit(_("[WARNING_NOTCL] Simultanoeus editing of tools geometry in a MultiGeo Geometry " self.inform.emit(_("[WARNING_NOTCL] Simultanoeus editing of tools geometry in a MultiGeo Geometry "
"is not possible.\n Edit only one geometry at a time.")) "is not possible.\n"
"Edit only one geometry at a time."))
self.geo_editor.edit_fcgeometry(edited_object, multigeo_tool=edited_tools[0]) self.geo_editor.edit_fcgeometry(edited_object, multigeo_tool=edited_tools[0])
else: else:
self.geo_editor.edit_fcgeometry(edited_object) self.geo_editor.edit_fcgeometry(edited_object)
@ -2156,16 +2154,8 @@ class App(QtCore.QObject):
""" """
self.report_usage("editor2object()") self.report_usage("editor2object()")
# adjust the status of the menu entries related to the editor
self.ui.menueditedit.setDisabled(False)
self.ui.menueditok.setDisabled(True)
# do not update a geometry or excellon object unless it comes out of an editor # do not update a geometry or excellon object unless it comes out of an editor
if self.call_source != 'app': if self.call_source != 'app':
# adjust the visibility of some of the canvas context menu
self.ui.popmenu_edit.setVisible(True)
self.ui.popmenu_save.setVisible(False)
edited_obj = self.collection.get_active() edited_obj = self.collection.get_active()
obj_type = "" obj_type = ""
@ -2244,6 +2234,8 @@ class App(QtCore.QObject):
self.grb_editor.deactivate_grb_editor() self.grb_editor.deactivate_grb_editor()
elif isinstance(edited_obj, FlatCAMExcellon): elif isinstance(edited_obj, FlatCAMExcellon):
self.exc_editor.deactivate() self.exc_editor.deactivate()
# set focus on the project tab
self.ui.notebook.setCurrentWidget(self.ui.project_tab)
else: else:
self.inform.emit(_("[WARNING_NOTCL] Select a Gerber, Geometry or Excellon Object to update.")) self.inform.emit(_("[WARNING_NOTCL] Select a Gerber, Geometry or Excellon Object to update."))
return return

View File

@ -13,6 +13,10 @@ CAD program, and create G-Code for Isolation routing.
- working on a new tool to process automatically PcbWizard Excellon files which are generated in 2 files - working on a new tool to process automatically PcbWizard Excellon files which are generated in 2 files
- finished ToolPcbWizard; it will autodetect the Excellon format, units from the INF file - finished ToolPcbWizard; it will autodetect the Excellon format, units from the INF file
- Gerber Editor: reduced the delay to show UI when editing an empty Gerber object
- update the order of event handlers connection in Editors to first connect new handlers then disconnect old handlers. It seems that if nothing is connected some VispY functions like canvas panning no longer works if there is at least once nothing connected to the 'mouse_move' event
- Excellon Editor: update so always there is a tool selected even after the Execllon object was just edited; before it always required a click inside of the tool table, not you do it only if needed.
- fixed the menu File -> Edit -> Edit/Close Editor entry to reflect the status of the app (Editor active or not)
14.04.2019 14.04.2019

View File

@ -12,6 +12,8 @@ from camlib import *
from flatcamGUI.GUIElements import FCEntry, FCComboBox, FCTable, FCDoubleSpinner, LengthEntry, RadioSet, SpinBoxDelegate from flatcamGUI.GUIElements import FCEntry, FCComboBox, FCTable, FCDoubleSpinner, LengthEntry, RadioSet, SpinBoxDelegate
from flatcamEditors.FlatCAMGeoEditor import FCShapeTool, DrawTool, DrawToolShape, DrawToolUtilityShape, FlatCAMGeoEditor from flatcamEditors.FlatCAMGeoEditor import FCShapeTool, DrawTool, DrawToolShape, DrawToolUtilityShape, FlatCAMGeoEditor
from copy import copy, deepcopy
import gettext import gettext
import FlatCAMTranslation as fcTranslate import FlatCAMTranslation as fcTranslate
@ -695,12 +697,23 @@ class FlatCAMExcEditor(QtCore.QObject):
self.units = self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().upper() self.units = self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().upper()
self.exc_edit_widget = QtWidgets.QWidget() self.exc_edit_widget = QtWidgets.QWidget()
## Box for custom widgets
# This gets populated in offspring implementations.
layout = QtWidgets.QVBoxLayout() layout = QtWidgets.QVBoxLayout()
self.exc_edit_widget.setLayout(layout) self.exc_edit_widget.setLayout(layout)
# add a frame and inside add a vertical box layout. Inside this vbox layout I add all the Drills widgets
# this way I can hide/show the frame
self.drills_frame = QtWidgets.QFrame()
self.drills_frame.setContentsMargins(0, 0, 0, 0)
layout.addWidget(self.drills_frame)
self.tools_box = QtWidgets.QVBoxLayout()
self.tools_box.setContentsMargins(0, 0, 0, 0)
self.drills_frame.setLayout(self.tools_box)
## Page Title box (spacing between children) ## Page Title box (spacing between children)
self.title_box = QtWidgets.QHBoxLayout() self.title_box = QtWidgets.QHBoxLayout()
layout.addLayout(self.title_box) self.tools_box.addLayout(self.title_box)
## Page Title icon ## Page Title icon
pixmap = QtGui.QPixmap('share/flatcam_icon32.png') pixmap = QtGui.QPixmap('share/flatcam_icon32.png')
@ -715,26 +728,12 @@ class FlatCAMExcEditor(QtCore.QObject):
## Object name ## Object name
self.name_box = QtWidgets.QHBoxLayout() self.name_box = QtWidgets.QHBoxLayout()
layout.addLayout(self.name_box) self.tools_box.addLayout(self.name_box)
name_label = QtWidgets.QLabel(_("Name:")) name_label = QtWidgets.QLabel(_("Name:"))
self.name_box.addWidget(name_label) self.name_box.addWidget(name_label)
self.name_entry = FCEntry() self.name_entry = FCEntry()
self.name_box.addWidget(self.name_entry) self.name_box.addWidget(self.name_entry)
## Box box for custom widgets
# This gets populated in offspring implementations.
self.custom_box = QtWidgets.QVBoxLayout()
layout.addLayout(self.custom_box)
# add a frame and inside add a vertical box layout. Inside this vbox layout I add all the Drills widgets
# this way I can hide/show the frame
self.drills_frame = QtWidgets.QFrame()
self.drills_frame.setContentsMargins(0, 0, 0, 0)
self.custom_box.addWidget(self.drills_frame)
self.tools_box = QtWidgets.QVBoxLayout()
self.tools_box.setContentsMargins(0, 0, 0, 0)
self.drills_frame.setLayout(self.tools_box)
#### Tools Drills #### #### Tools Drills ####
self.tools_table_label = QtWidgets.QLabel("<b>%s</b>" % _('Tools Table')) self.tools_table_label = QtWidgets.QLabel("<b>%s</b>" % _('Tools Table'))
self.tools_table_label.setToolTip( self.tools_table_label.setToolTip(
@ -1134,6 +1133,7 @@ class FlatCAMExcEditor(QtCore.QObject):
return storage return storage
def set_ui(self): def set_ui(self):
# updated units # updated units
self.units = self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().upper() self.units = self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().upper()
@ -1177,7 +1177,7 @@ class FlatCAMExcEditor(QtCore.QObject):
tool_dia = float('%.2f' % v['C']) tool_dia = float('%.2f' % v['C'])
self.tool2tooldia[int(k)] = tool_dia self.tool2tooldia[int(k)] = tool_dia
def build_ui(self): def build_ui(self, first_run=None):
try: try:
# if connected, disconnect the signal from the slot on item_changed as it creates issues # if connected, disconnect the signal from the slot on item_changed as it creates issues
@ -1271,6 +1271,11 @@ class FlatCAMExcEditor(QtCore.QObject):
self.tools_table_exc.setItem(self.tool_row, 1, dia) # Diameter self.tools_table_exc.setItem(self.tool_row, 1, dia) # Diameter
self.tools_table_exc.setItem(self.tool_row, 2, drill_count) # Number of drills per tool self.tools_table_exc.setItem(self.tool_row, 2, drill_count) # Number of drills per tool
self.tools_table_exc.setItem(self.tool_row, 3, slot_count) # Number of drills per tool self.tools_table_exc.setItem(self.tool_row, 3, slot_count) # Number of drills per tool
if first_run is True:
# set now the last tool selected
self.last_tool_selected = int(tool_id)
self.tool_row += 1 self.tool_row += 1
# make the diameter column editable # make the diameter column editable
@ -1568,6 +1573,13 @@ class FlatCAMExcEditor(QtCore.QObject):
self.edited_obj_name = self.name_entry.get_value() self.edited_obj_name = self.name_entry.get_value()
def activate(self): def activate(self):
# adjust the status of the menu entries related to the editor
self.app.ui.menueditedit.setDisabled(True)
self.app.ui.menueditok.setDisabled(False)
# adjust the visibility of some of the canvas context menu
self.app.ui.popmenu_edit.setVisible(False)
self.app.ui.popmenu_save.setVisible(True)
self.connect_canvas_event_handlers() self.connect_canvas_event_handlers()
# initialize working objects # initialize working objects
@ -1604,14 +1616,20 @@ class FlatCAMExcEditor(QtCore.QObject):
if self.app.ui.grid_snap_btn.isChecked() is False: if self.app.ui.grid_snap_btn.isChecked() is False:
self.app.ui.grid_snap_btn.trigger() self.app.ui.grid_snap_btn.trigger()
# adjust the visibility of some of the canvas context menu
self.app.ui.popmenu_edit.setVisible(False)
self.app.ui.popmenu_save.setVisible(True)
# Tell the App that the editor is active # Tell the App that the editor is active
self.editor_active = True self.editor_active = True
# show the UI
self.drills_frame.show()
def deactivate(self): def deactivate(self):
# adjust the status of the menu entries related to the editor
self.app.ui.menueditedit.setDisabled(False)
self.app.ui.menueditok.setDisabled(True)
# adjust the visibility of some of the canvas context menu
self.app.ui.popmenu_edit.setVisible(True)
self.app.ui.popmenu_save.setVisible(False)
self.disconnect_canvas_event_handlers() self.disconnect_canvas_event_handlers()
self.clear() self.clear()
self.app.ui.exc_edit_toolbar.setDisabled(True) self.app.ui.exc_edit_toolbar.setDisabled(True)
@ -1661,42 +1679,44 @@ class FlatCAMExcEditor(QtCore.QObject):
self.app.ui.g_editor_cmenu.setEnabled(False) self.app.ui.g_editor_cmenu.setEnabled(False)
self.app.ui.e_editor_cmenu.setEnabled(False) self.app.ui.e_editor_cmenu.setEnabled(False)
# adjust the visibility of some of the canvas context menu
self.app.ui.popmenu_edit.setVisible(True)
self.app.ui.popmenu_save.setVisible(False)
# Show original geometry # Show original geometry
if self.exc_obj: if self.exc_obj:
self.exc_obj.visible = True self.exc_obj.visible = True
# hide the UI
self.drills_frame.hide()
def connect_canvas_event_handlers(self): def connect_canvas_event_handlers(self):
## Canvas events ## Canvas events
# first connect to new, then disconnect the old handlers
# don't ask why but if there is nothing connected I've seen issues
self.canvas.vis_connect('mouse_press', self.on_canvas_click)
self.canvas.vis_connect('mouse_move', self.on_canvas_move)
self.canvas.vis_connect('mouse_release', self.on_exc_click_release)
# make sure that the shortcuts key and mouse events will no longer be linked to the methods from FlatCAMApp # make sure that the shortcuts key and mouse events will no longer be linked to the methods from FlatCAMApp
# but those from FlatCAMGeoEditor # but those from FlatCAMGeoEditor
self.app.plotcanvas.vis_disconnect('mouse_press', self.app.on_mouse_click_over_plot) self.app.plotcanvas.vis_disconnect('mouse_press', self.app.on_mouse_click_over_plot)
self.app.plotcanvas.vis_disconnect('mouse_move', self.app.on_mouse_move_over_plot) self.app.plotcanvas.vis_disconnect('mouse_move', self.app.on_mouse_move_over_plot)
self.app.plotcanvas.vis_disconnect('mouse_release', self.app.on_mouse_click_release_over_plot) self.app.plotcanvas.vis_disconnect('mouse_release', self.app.on_mouse_click_release_over_plot)
self.app.plotcanvas.vis_disconnect('mouse_double_click', self.app.on_double_click_over_plot) self.app.plotcanvas.vis_disconnect('mouse_double_click', self.app.on_double_click_over_plot)
self.app.collection.view.clicked.disconnect() self.app.collection.view.clicked.disconnect()
self.canvas.vis_connect('mouse_press', self.on_canvas_click)
self.canvas.vis_connect('mouse_move', self.on_canvas_move)
self.canvas.vis_connect('mouse_release', self.on_exc_click_release)
def disconnect_canvas_event_handlers(self): def disconnect_canvas_event_handlers(self):
self.canvas.vis_disconnect('mouse_press', self.on_canvas_click)
self.canvas.vis_disconnect('mouse_move', self.on_canvas_move)
self.canvas.vis_disconnect('mouse_release', self.on_exc_click_release)
# we restore the key and mouse control to FlatCAMApp method # we restore the key and mouse control to FlatCAMApp method
# first connect to new, then disconnect the old handlers
# don't ask why but if there is nothing connected I've seen issues
self.app.plotcanvas.vis_connect('mouse_press', self.app.on_mouse_click_over_plot) self.app.plotcanvas.vis_connect('mouse_press', self.app.on_mouse_click_over_plot)
self.app.plotcanvas.vis_connect('mouse_move', self.app.on_mouse_move_over_plot) self.app.plotcanvas.vis_connect('mouse_move', self.app.on_mouse_move_over_plot)
self.app.plotcanvas.vis_connect('mouse_release', self.app.on_mouse_click_release_over_plot) self.app.plotcanvas.vis_connect('mouse_release', self.app.on_mouse_click_release_over_plot)
self.app.plotcanvas.vis_connect('mouse_double_click', self.app.on_double_click_over_plot) self.app.plotcanvas.vis_connect('mouse_double_click', self.app.on_double_click_over_plot)
self.app.collection.view.clicked.connect(self.app.collection.on_mouse_down) self.app.collection.view.clicked.connect(self.app.collection.on_mouse_down)
self.canvas.vis_disconnect('mouse_press', self.on_canvas_click)
self.canvas.vis_disconnect('mouse_move', self.on_canvas_move)
self.canvas.vis_disconnect('mouse_release', self.on_exc_click_release)
def clear(self): def clear(self):
self.active_tool = None self.active_tool = None
# self.shape_buffer = [] # self.shape_buffer = []
@ -1741,7 +1761,7 @@ class FlatCAMExcEditor(QtCore.QObject):
self.set_ui() self.set_ui()
# now that we hava data, create the GUI interface and add it to the Tool Tab # now that we hava data, create the GUI interface and add it to the Tool Tab
self.build_ui() self.build_ui(first_run=True)
# we activate this after the initial build as we don't need to see the tool been populated # we activate this after the initial build as we don't need to see the tool been populated
self.tools_table_exc.itemChanged.connect(self.on_tool_edit) self.tools_table_exc.itemChanged.connect(self.on_tool_edit)
@ -1992,7 +2012,7 @@ class FlatCAMExcEditor(QtCore.QObject):
try: try:
selected_dia = self.tool2tooldia[self.tools_table_exc.currentRow() + 1] selected_dia = self.tool2tooldia[self.tools_table_exc.currentRow() + 1]
self.last_tool_selected = self.tools_table_exc.currentRow() + 1 self.last_tool_selected = copy(self.tools_table_exc.currentRow()) + 1
for obj in self.storage_dict[selected_dia].get_objects(): for obj in self.storage_dict[selected_dia].get_objects():
self.selected.append(obj) self.selected.append(obj)
except Exception as e: except Exception as e:

View File

@ -2855,6 +2855,13 @@ class FlatCAMGeoEditor(QtCore.QObject):
self.replot() self.replot()
def activate(self): def activate(self):
# adjust the status of the menu entries related to the editor
self.app.ui.menueditedit.setDisabled(True)
self.app.ui.menueditok.setDisabled(False)
# adjust the visibility of some of the canvas context menu
self.app.ui.popmenu_edit.setVisible(False)
self.app.ui.popmenu_save.setVisible(True)
self.connect_canvas_event_handlers() self.connect_canvas_event_handlers()
# initialize working objects # initialize working objects
@ -2887,14 +2894,17 @@ class FlatCAMGeoEditor(QtCore.QObject):
for w in sel_tab_widget_list: for w in sel_tab_widget_list:
w.setEnabled(False) w.setEnabled(False)
# adjust the visibility of some of the canvas context menu
self.app.ui.popmenu_edit.setVisible(False)
self.app.ui.popmenu_save.setVisible(True)
# Tell the App that the editor is active # Tell the App that the editor is active
self.editor_active = True self.editor_active = True
def deactivate(self): def deactivate(self):
# adjust the status of the menu entries related to the editor
self.app.ui.menueditedit.setDisabled(False)
self.app.ui.menueditok.setDisabled(True)
# adjust the visibility of some of the canvas context menu
self.app.ui.popmenu_edit.setVisible(True)
self.app.ui.popmenu_save.setVisible(False)
self.disconnect_canvas_event_handlers() self.disconnect_canvas_event_handlers()
self.clear() self.clear()
self.app.ui.geo_edit_toolbar.setDisabled(True) self.app.ui.geo_edit_toolbar.setDisabled(True)
@ -2942,10 +2952,6 @@ class FlatCAMGeoEditor(QtCore.QObject):
# Tell the app that the editor is no longer active # Tell the app that the editor is no longer active
self.editor_active = False self.editor_active = False
# adjust the visibility of some of the canvas context menu
self.app.ui.popmenu_edit.setVisible(True)
self.app.ui.popmenu_save.setVisible(False)
try: try:
# re-enable all the widgets in the Selected Tab that were disabled after entering in Edit Geometry Mode # re-enable all the widgets in the Selected Tab that were disabled after entering in Edit Geometry Mode
sel_tab_widget_list = self.app.ui.selected_tab.findChildren(QtWidgets.QWidget) sel_tab_widget_list = self.app.ui.selected_tab.findChildren(QtWidgets.QWidget)
@ -2961,9 +2967,14 @@ class FlatCAMGeoEditor(QtCore.QObject):
def connect_canvas_event_handlers(self): def connect_canvas_event_handlers(self):
## Canvas events ## Canvas events
# first connect to new, then disconnect the old handlers
# don't ask why but if there is nothing connected I've seen issues
self.canvas.vis_connect('mouse_press', self.on_canvas_click)
self.canvas.vis_connect('mouse_move', self.on_canvas_move)
self.canvas.vis_connect('mouse_release', self.on_geo_click_release)
# make sure that the shortcuts key and mouse events will no longer be linked to the methods from FlatCAMApp # make sure that the shortcuts key and mouse events will no longer be linked to the methods from FlatCAMApp
# but those from FlatCAMGeoEditor # but those from FlatCAMGeoEditor
self.app.plotcanvas.vis_disconnect('mouse_press', self.app.on_mouse_click_over_plot) self.app.plotcanvas.vis_disconnect('mouse_press', self.app.on_mouse_click_over_plot)
self.app.plotcanvas.vis_disconnect('mouse_move', self.app.on_mouse_move_over_plot) self.app.plotcanvas.vis_disconnect('mouse_move', self.app.on_mouse_move_over_plot)
self.app.plotcanvas.vis_disconnect('mouse_release', self.app.on_mouse_click_release_over_plot) self.app.plotcanvas.vis_disconnect('mouse_release', self.app.on_mouse_click_release_over_plot)
@ -2971,23 +2982,20 @@ class FlatCAMGeoEditor(QtCore.QObject):
self.app.collection.view.clicked.disconnect() self.app.collection.view.clicked.disconnect()
self.canvas.vis_connect('mouse_press', self.on_canvas_click)
self.canvas.vis_connect('mouse_move', self.on_canvas_move)
self.canvas.vis_connect('mouse_release', self.on_geo_click_release)
def disconnect_canvas_event_handlers(self): def disconnect_canvas_event_handlers(self):
self.canvas.vis_disconnect('mouse_press', self.on_canvas_click)
self.canvas.vis_disconnect('mouse_move', self.on_canvas_move)
self.canvas.vis_disconnect('mouse_release', self.on_geo_click_release)
# we restore the key and mouse control to FlatCAMApp method # we restore the key and mouse control to FlatCAMApp method
# first connect to new, then disconnect the old handlers
# don't ask why but if there is nothing connected I've seen issues
self.app.plotcanvas.vis_connect('mouse_press', self.app.on_mouse_click_over_plot) self.app.plotcanvas.vis_connect('mouse_press', self.app.on_mouse_click_over_plot)
self.app.plotcanvas.vis_connect('mouse_move', self.app.on_mouse_move_over_plot) self.app.plotcanvas.vis_connect('mouse_move', self.app.on_mouse_move_over_plot)
self.app.plotcanvas.vis_connect('mouse_release', self.app.on_mouse_click_release_over_plot) self.app.plotcanvas.vis_connect('mouse_release', self.app.on_mouse_click_release_over_plot)
self.app.plotcanvas.vis_connect('mouse_double_click', self.app.on_double_click_over_plot) self.app.plotcanvas.vis_connect('mouse_double_click', self.app.on_double_click_over_plot)
self.app.collection.view.clicked.connect(self.app.collection.on_mouse_down) self.app.collection.view.clicked.connect(self.app.collection.on_mouse_down)
self.canvas.vis_disconnect('mouse_press', self.on_canvas_click)
self.canvas.vis_disconnect('mouse_move', self.on_canvas_move)
self.canvas.vis_disconnect('mouse_release', self.on_geo_click_release)
def add_shape(self, shape): def add_shape(self, shape):
""" """
Adds a shape to the shape storage. Adds a shape to the shape storage.

View File

@ -8,7 +8,7 @@ import shapely.affinity as affinity
from numpy import arctan2, Inf, array, sqrt, sign, dot from numpy import arctan2, Inf, array, sqrt, sign, dot
from rtree import index as rtindex from rtree import index as rtindex
import threading, time import threading, time
import copy from copy import copy, deepcopy
from camlib import * from camlib import *
from flatcamGUI.GUIElements import FCEntry, FCComboBox, FCTable, FCDoubleSpinner, LengthEntry, RadioSet, \ from flatcamGUI.GUIElements import FCEntry, FCComboBox, FCTable, FCDoubleSpinner, LengthEntry, RadioSet, \
@ -36,8 +36,14 @@ class FCPad(FCShapeTool):
self.name = 'pad' self.name = 'pad'
self.draw_app = draw_app self.draw_app = draw_app
try:
self.radius = float(self.draw_app.storage_dict[self.draw_app.last_aperture_selected]['size']) / 2
except KeyError:
self.draw_app.app.inform.emit(_("[WARNING_NOTCL] To add a Pad, first select a tool in Tool Table"))
self.draw_app.in_action = False
self.complete = True
return
self.storage_obj = self.draw_app.storage_dict[self.draw_app.last_aperture_selected]['solid_geometry'] self.storage_obj = self.draw_app.storage_dict[self.draw_app.last_aperture_selected]['solid_geometry']
self.radius = float(self.draw_app.storage_dict[self.draw_app.last_aperture_selected]['size']) / 2
self.steps_per_circ = self.draw_app.app.defaults["geometry_circle_steps"] self.steps_per_circ = self.draw_app.app.defaults["geometry_circle_steps"]
# if those cause KeyError exception it means that the aperture type is not 'R'. Only 'R' type has those keys # if those cause KeyError exception it means that the aperture type is not 'R'. Only 'R' type has those keys
@ -51,7 +57,6 @@ class FCPad(FCShapeTool):
pass pass
geo = self.utility_geometry(data=(self.draw_app.snap_x, self.draw_app.snap_y)) geo = self.utility_geometry(data=(self.draw_app.snap_x, self.draw_app.snap_y))
if isinstance(geo, DrawToolShape) and geo.geo is not None: if isinstance(geo, DrawToolShape) and geo.geo is not None:
self.draw_app.draw_utility_geometry(geo=geo) self.draw_app.draw_utility_geometry(geo=geo)
@ -191,8 +196,15 @@ class FCPadArray(FCShapeTool):
self.name = 'array' self.name = 'array'
self.draw_app = draw_app self.draw_app = draw_app
try:
self.radius = float(self.draw_app.storage_dict[self.draw_app.last_aperture_selected]['size']) / 2
except KeyError:
self.draw_app.app.inform.emit(_("[WARNING_NOTCL] To add an Pad Array first select a tool in Tool Table"))
self.complete = True
self.draw_app.in_action = False
self.draw_app.array_frame.hide()
return
self.storage_obj = self.draw_app.storage_dict[self.draw_app.last_aperture_selected]['solid_geometry'] self.storage_obj = self.draw_app.storage_dict[self.draw_app.last_aperture_selected]['solid_geometry']
self.radius = float(self.draw_app.storage_dict[self.draw_app.last_aperture_selected]['size']) / 2
self.steps_per_circ = self.draw_app.app.defaults["geometry_circle_steps"] self.steps_per_circ = self.draw_app.app.defaults["geometry_circle_steps"]
# if those cause KeyError exception it means that the aperture type is not 'R'. Only 'R' type has those keys # if those cause KeyError exception it means that the aperture type is not 'R'. Only 'R' type has those keys
@ -229,12 +241,6 @@ class FCPadArray(FCShapeTool):
self.draw_app.app.inform.emit(self.start_msg) self.draw_app.app.inform.emit(self.start_msg)
try:
self.selected_size = self.draw_app.tool2tooldia[self.draw_app.last_aperture_selected]
except KeyError:
self.draw_app.app.inform.emit(_("[WARNING_NOTCL] To add an Pad Array first select a tool in Tool Table"))
return
geo = self.utility_geometry(data=(self.draw_app.snap_x, self.draw_app.snap_y), static=True) geo = self.utility_geometry(data=(self.draw_app.snap_x, self.draw_app.snap_y), static=True)
if isinstance(geo, DrawToolShape) and geo.geo is not None: if isinstance(geo, DrawToolShape) and geo.geo is not None:
@ -466,7 +472,7 @@ class FCPadArray(FCShapeTool):
self.geometry.append(DrawToolShape(geo)) self.geometry.append(DrawToolShape(geo))
self.complete = True self.complete = True
self.draw_app.app.inform.emit(_("[success] Done. Pad Array added.")) self.draw_app.app.inform.emit(_("[success] Done. Pad Array added."))
self.draw_app.in_action = True self.draw_app.in_action = False
self.draw_app.array_frame.hide() self.draw_app.array_frame.hide()
return return
@ -1518,7 +1524,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
self.pad_direction_radio.set_value('CW') self.pad_direction_radio.set_value('CW')
self.pad_axis_radio.set_value('X') self.pad_axis_radio.set_value('X')
def build_ui(self): def build_ui(self, first_run=None):
try: try:
# if connected, disconnect the signal from the slot on item_changed as it creates issues # if connected, disconnect the signal from the slot on item_changed as it creates issues
@ -1601,6 +1607,9 @@ class FlatCAMGrbEditor(QtCore.QObject):
self.apertures_table.setItem(self.apertures_row, 4, ap_dim_item) # Aperture Dimensions self.apertures_table.setItem(self.apertures_row, 4, ap_dim_item) # Aperture Dimensions
self.apertures_row += 1 self.apertures_row += 1
if first_run is True:
# set now the last aperture selected
self.last_aperture_selected = ap_code
for ap_code in sorted_macros: for ap_code in sorted_macros:
ap_code = str(ap_code) ap_code = str(ap_code)
@ -1618,6 +1627,9 @@ class FlatCAMGrbEditor(QtCore.QObject):
self.apertures_table.setItem(self.apertures_row, 2, ap_type_item) # Aperture Type self.apertures_table.setItem(self.apertures_row, 2, ap_type_item) # Aperture Type
self.apertures_row += 1 self.apertures_row += 1
if first_run is True:
# set now the last aperture selected
self.last_aperture_selected = ap_code
self.apertures_table.selectColumn(0) self.apertures_table.selectColumn(0)
self.apertures_table.resizeColumnsToContents() self.apertures_table.resizeColumnsToContents()
@ -1872,6 +1884,13 @@ class FlatCAMGrbEditor(QtCore.QObject):
self.apsize_entry.setReadOnly(False) self.apsize_entry.setReadOnly(False)
def activate_grb_editor(self): def activate_grb_editor(self):
# adjust the status of the menu entries related to the editor
self.app.ui.menueditedit.setDisabled(True)
self.app.ui.menueditok.setDisabled(False)
# adjust the visibility of some of the canvas context menu
self.app.ui.popmenu_edit.setVisible(False)
self.app.ui.popmenu_save.setVisible(True)
self.connect_canvas_event_handlers() self.connect_canvas_event_handlers()
# init working objects # init working objects
@ -1914,6 +1933,13 @@ class FlatCAMGrbEditor(QtCore.QObject):
self.editor_active = True self.editor_active = True
def deactivate_grb_editor(self): def deactivate_grb_editor(self):
# adjust the status of the menu entries related to the editor
self.app.ui.menueditedit.setDisabled(False)
self.app.ui.menueditok.setDisabled(True)
# adjust the visibility of some of the canvas context menu
self.app.ui.popmenu_edit.setVisible(True)
self.app.ui.popmenu_save.setVisible(False)
self.disconnect_canvas_event_handlers() self.disconnect_canvas_event_handlers()
self.clear() self.clear()
self.app.ui.grb_edit_toolbar.setDisabled(True) self.app.ui.grb_edit_toolbar.setDisabled(True)
@ -1978,28 +2004,33 @@ class FlatCAMGrbEditor(QtCore.QObject):
# make sure that the shortcuts key and mouse events will no longer be linked to the methods from FlatCAMApp # make sure that the shortcuts key and mouse events will no longer be linked to the methods from FlatCAMApp
# but those from FlatCAMGeoEditor # but those from FlatCAMGeoEditor
# first connect to new, then disconnect the old handlers
# don't ask why but if there is nothing connected I've seen issues
self.canvas.vis_connect('mouse_press', self.on_canvas_click)
self.canvas.vis_connect('mouse_move', self.on_canvas_move)
self.canvas.vis_connect('mouse_release', self.on_grb_click_release)
self.app.plotcanvas.vis_disconnect('mouse_press', self.app.on_mouse_click_over_plot) self.app.plotcanvas.vis_disconnect('mouse_press', self.app.on_mouse_click_over_plot)
self.app.plotcanvas.vis_disconnect('mouse_move', self.app.on_mouse_move_over_plot) self.app.plotcanvas.vis_disconnect('mouse_move', self.app.on_mouse_move_over_plot)
self.app.plotcanvas.vis_disconnect('mouse_release', self.app.on_mouse_click_release_over_plot) self.app.plotcanvas.vis_disconnect('mouse_release', self.app.on_mouse_click_release_over_plot)
self.app.plotcanvas.vis_disconnect('mouse_double_click', self.app.on_double_click_over_plot) self.app.plotcanvas.vis_disconnect('mouse_double_click', self.app.on_double_click_over_plot)
self.app.collection.view.clicked.disconnect() self.app.collection.view.clicked.disconnect()
self.canvas.vis_connect('mouse_press', self.on_canvas_click)
self.canvas.vis_connect('mouse_move', self.on_canvas_move)
self.canvas.vis_connect('mouse_release', self.on_grb_click_release)
def disconnect_canvas_event_handlers(self): def disconnect_canvas_event_handlers(self):
self.canvas.vis_disconnect('mouse_press', self.on_canvas_click)
self.canvas.vis_disconnect('mouse_move', self.on_canvas_move)
self.canvas.vis_disconnect('mouse_release', self.on_grb_click_release)
# we restore the key and mouse control to FlatCAMApp method # we restore the key and mouse control to FlatCAMApp method
# first connect to new, then disconnect the old handlers
# don't ask why but if there is nothing connected I've seen issues
self.app.plotcanvas.vis_connect('mouse_press', self.app.on_mouse_click_over_plot) self.app.plotcanvas.vis_connect('mouse_press', self.app.on_mouse_click_over_plot)
self.app.plotcanvas.vis_connect('mouse_move', self.app.on_mouse_move_over_plot) self.app.plotcanvas.vis_connect('mouse_move', self.app.on_mouse_move_over_plot)
self.app.plotcanvas.vis_connect('mouse_release', self.app.on_mouse_click_release_over_plot) self.app.plotcanvas.vis_connect('mouse_release', self.app.on_mouse_click_release_over_plot)
self.app.plotcanvas.vis_connect('mouse_double_click', self.app.on_double_click_over_plot) self.app.plotcanvas.vis_connect('mouse_double_click', self.app.on_double_click_over_plot)
self.app.collection.view.clicked.connect(self.app.collection.on_mouse_down) self.app.collection.view.clicked.connect(self.app.collection.on_mouse_down)
self.canvas.vis_disconnect('mouse_press', self.on_canvas_click)
self.canvas.vis_disconnect('mouse_move', self.on_canvas_move)
self.canvas.vis_disconnect('mouse_release', self.on_grb_click_release)
def clear(self): def clear(self):
self.active_tool = None self.active_tool = None
# self.shape_buffer = [] # self.shape_buffer = []
@ -2104,7 +2135,13 @@ class FlatCAMGrbEditor(QtCore.QObject):
self.grb_plot_promises.append(apid) self.grb_plot_promises.append(apid)
self.app.worker_task.emit({'fcn': job_thread, 'params': [self, apid]}) self.app.worker_task.emit({'fcn': job_thread, 'params': [self, apid]})
self.start_delayed_plot(check_period=1000) # do the delayed plot only if there is something to plot (the gerber is not empty)
if bool(self.gerber_obj.apertures):
self.start_delayed_plot(check_period=1000)
else:
self.set_ui()
# now that we have data (empty data actually), create the GUI interface and add it to the Tool Tab
self.build_ui(first_run=True)
def update_fcgerber(self, grb_obj): def update_fcgerber(self, grb_obj):
""" """
@ -2296,7 +2333,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
try: try:
# selected_apid = str(self.tool2tooldia[row + 1]) # selected_apid = str(self.tool2tooldia[row + 1])
selected_apid = self.apertures_table.item(row, 1).text() selected_apid = self.apertures_table.item(row, 1).text()
self.last_aperture_selected = selected_apid self.last_aperture_selected = copy(selected_apid)
for obj in self.storage_dict[selected_apid]['solid_geometry']: for obj in self.storage_dict[selected_apid]['solid_geometry']:
self.selected.append(obj) self.selected.append(obj)
@ -2685,7 +2722,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
self.set_ui() self.set_ui()
# now that we have data, create the GUI interface and add it to the Tool Tab # now that we have data, create the GUI interface and add it to the Tool Tab
self.build_ui() self.build_ui(first_run=True)
self.plot_all() self.plot_all()
# HACK: enabling/disabling the cursor seams to somehow update the shapes making them more 'solid' # HACK: enabling/disabling the cursor seams to somehow update the shapes making them more 'solid'