- fixed a new bug that did not allow to open the FlatCAM Preferences files by doubleclick in Windows

- added a new feature: Tools Database for Geometry objects; resolved issue #308
This commit is contained in:
Marius Stanciu 2019-11-09 18:04:49 +02:00 committed by Marius
parent c091af35b8
commit ee8719093c
7 changed files with 779 additions and 314 deletions

View File

@ -325,6 +325,16 @@ class App(QtCore.QObject):
os.makedirs(self.postprocessorpaths)
App.log.debug('Created postprocessors folder: ' + self.postprocessorpaths)
# create tools_db.FlatConfig file if there is none
try:
f = open(self.data_path + '/tools_db.FlatConfig')
f.close()
except IOError:
App.log.debug('Creating empty tool_db.FlatConfig')
f = open(self.data_path + '/tools_db.FlatConfig', 'w')
json.dump({}, f)
f.close()
# create current_defaults.FlatConfig file if there is none
try:
f = open(self.data_path + '/current_defaults.FlatConfig')
@ -2274,7 +2284,7 @@ class App(QtCore.QObject):
# ############################## Tools Database ####################################
# ##################################################################################
self.tools_db_tab = ToolsDB(app=self)
self.tools_db_tab = None
# ### System Font Parsing ###
# self.f_parse = ParseFont(self)
@ -2370,6 +2380,9 @@ class App(QtCore.QObject):
# if Preferences are changed in the Edit -> Preferences tab the value will be set to True
self.preferences_changed_flag = False
# if Tools DB are changed/edited in the Edit -> Tools Database tab the value will be set to True
self.tools_db_changed_flag = False
self.grb_list = ['art', 'bot', 'bsm', 'cmp', 'crc', 'crs', 'dim', 'g4', 'gb0', 'gb1', 'gb2', 'gb3', 'gb5',
'gb6', 'gb7', 'gb8', 'gb9', 'gbd', 'gbl', 'gbo', 'gbp', 'gbr', 'gbs', 'gdo', 'ger', 'gko',
'gml', 'gm1', 'gm2', 'gm3', 'grb', 'gtl', 'gto', 'gtp', 'gts', 'ly15', 'ly2', 'mil', 'pho',
@ -4566,28 +4579,6 @@ class App(QtCore.QObject):
msgbox.exec_()
# response = msgbox.clickedButton()
def on_tools_database(self):
"""
Adds the Tools Database in a Tab in Plot Area
:return:
"""
for idx in range(self.ui.plot_tab_area.count()):
if self.ui.plot_tab_area.tabText(idx) == _("Tools Database"):
# there can be only one instance of Tools Database at one time
return
self.tools_db_tab = ToolsDB(app=self, parent=self.ui)
# add the tab if it was closed
self.ui.plot_tab_area.addTab(self.tools_db_tab, _("Tools Database"))
# delete the absolute and relative position and messages in the infobar
self.ui.position_label.setText("")
self.ui.rel_position_label.setText("")
# Switch plot_area to preferences page
self.ui.plot_tab_area.setCurrentWidget(self.tools_db_tab)
def on_file_savedefaults(self):
"""
Callback for menu item File->Save Defaults. Saves application default options
@ -7362,6 +7353,12 @@ class App(QtCore.QObject):
self.draw_selection_shape(curr_sel_obj)
def on_preferences(self):
"""
Adds the Preferences in a Tab in Plot Area
:return:
"""
# add the tab if it was closed
self.ui.plot_tab_area.addTab(self.ui.preferences_tab, _("Preferences"))
@ -7431,6 +7428,66 @@ class App(QtCore.QObject):
self.preferences_changed_flag = True
def on_tools_database(self):
"""
Adds the Tools Database in a Tab in Plot Area
:return:
"""
for idx in range(self.ui.plot_tab_area.count()):
if self.ui.plot_tab_area.tabText(idx) == _("Tools Database"):
# there can be only one instance of Tools Database at one time
return
self.tools_db_tab = ToolsDB(
app=self,
parent=self.ui,
callback_on_edited=self.on_tools_db_edited,
callback_on_tool_request=self.on_geometry_tool_add_from_db_executed
)
# add the tab if it was closed
self.ui.plot_tab_area.addTab(self.tools_db_tab, _("Tools Database"))
self.tools_db_tab.setObjectName("database_tab")
# delete the absolute and relative position and messages in the infobar
self.ui.position_label.setText("")
self.ui.rel_position_label.setText("")
# Switch plot_area to preferences page
self.ui.plot_tab_area.setCurrentWidget(self.tools_db_tab)
# detect changes in the Tools in Tools DB, connect signals from table widget in tab
self.tools_db_tab.ui_connect()
def on_tools_db_edited(self):
self.inform.emit('[WARNING_NOTCL] %s' % _("Tools in Tools Database edited but not saved."))
for idx in range(self.ui.plot_tab_area.count()):
if self.ui.plot_tab_area.tabText(idx) == _("Tools Database"):
self.ui.plot_tab_area.tabBar.setTabTextColor(idx, QtGui.QColor('red'))
self.tools_db_changed_flag = True
def on_geometry_tool_add_from_db_executed(self, tool):
"""
Here add the tool from DB in the selected geometry object
:return:
"""
tool_from_db = deepcopy(tool)
obj = self.collection.get_active()
if isinstance(obj, FlatCAMGeometry):
obj.on_tool_from_db_inserted(tool=tool_from_db)
for idx in range(self.ui.plot_tab_area.count()):
if self.ui.plot_tab_area.tabText(idx) == _("Tools Database"):
wdg = self.ui.plot_tab_area.widget(idx)
wdg.deleteLater()
self.ui.plot_tab_area.removeTab(idx)
self.inform.emit('[success] %s' % _("Tool from DB added in Tool Table."))
else:
self.inform.emit('[ERROR_NOTCL] %s' % _("Adding tool from DB is not allowed for this object."))
def on_plot_area_tab_closed(self, title):
if title == _("Preferences"):
# disconnect
@ -7477,12 +7534,37 @@ class App(QtCore.QObject):
if response == bt_yes:
self.on_save_button()
self.inform.emit('[success] %s' %
_("Preferences saved."))
self.inform.emit('[success] %s' % _("Preferences saved."))
else:
self.preferences_changed_flag = False
return
if title == _("Tools Database"):
# disconnect the signals from the table widget in tab
self.tools_db_tab.ui_disconnect()
if self.tools_db_changed_flag is True:
msgbox = QtWidgets.QMessageBox()
msgbox.setText(_("One or more Tools are edited.\n"
"Do you want to update the Tools Database?"))
msgbox.setWindowTitle(_("Save Tools Database"))
msgbox.setWindowIcon(QtGui.QIcon('share/save_as.png'))
bt_yes = msgbox.addButton(_('Yes'), QtWidgets.QMessageBox.YesRole)
bt_no = msgbox.addButton(_('No'), QtWidgets.QMessageBox.NoRole)
msgbox.setDefaultButton(bt_yes)
msgbox.exec_()
response = msgbox.clickedButton()
if response == bt_yes:
self.tools_db_tab.on_save_tools_db()
self.inform.emit('[success] %s' % "Tools DB saved to file.")
else:
self.tools_db_changed_flag = False
return
self.tools_db_tab.deleteLater()
if title == _("Code Editor"):
self.toggle_codeeditor = False
@ -10859,21 +10941,27 @@ class App(QtCore.QObject):
_("Opening FlatCAM Config file.")),
alignment=Qt.AlignBottom | Qt.AlignLeft,
color=QtGui.QColor("gray"))
# add the tab if it was closed
self.ui.plot_tab_area.addTab(self.ui.text_editor_tab, _("Code Editor"))
# first clear previous text in text editor (if any)
self.ui.text_editor_tab.code_editor.clear()
# # add the tab if it was closed
# self.ui.plot_tab_area.addTab(self.ui.text_editor_tab, _("Code Editor"))
# # first clear previous text in text editor (if any)
# self.ui.text_editor_tab.code_editor.clear()
#
# # Switch plot_area to CNCJob tab
# self.ui.plot_tab_area.setCurrentWidget(self.ui.text_editor_tab)
# Switch plot_area to CNCJob tab
self.ui.plot_tab_area.setCurrentWidget(self.ui.text_editor_tab)
# close the Code editor if already open
if self.toggle_codeeditor:
self.on_toggle_code_editor()
self.on_toggle_code_editor()
try:
if filename:
f = QtCore.QFile(filename)
if f.open(QtCore.QIODevice.ReadOnly):
stream = QtCore.QTextStream(f)
gcode_edited = stream.readAll()
self.ui.text_editor_tab.code_editor.setPlainText(gcode_edited)
code_edited = stream.readAll()
self.text_editor_tab.code_editor.setPlainText(code_edited)
f.close()
except IOError:
App.log.error("Failed to open config file: %s" % filename)

File diff suppressed because it is too large Load Diff

View File

@ -3677,7 +3677,7 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
self.ui.geo_tools_table.setupContextMenu()
self.ui.geo_tools_table.addContextMenu(
_("Add from Tool DB"), self.on_tool_add_from_db, icon=QtGui.QIcon("share/plus16.png"))
_("Add from Tool DB"), self.on_tool_add_from_db_clicked, icon=QtGui.QIcon("share/plus16.png"))
self.ui.geo_tools_table.addContextMenu(
_("Copy"), self.on_tool_copy, icon=QtGui.QIcon("share/copy16.png"))
self.ui.geo_tools_table.addContextMenu(
@ -3716,6 +3716,8 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
self.ui.tipdia_entry.valueChanged.connect(self.update_cutz)
self.ui.tipangle_entry.valueChanged.connect(self.update_cutz)
self.ui.addtool_from_db_btn.clicked.connect(self.on_tool_add_from_db_clicked)
def set_tool_offset_visibility(self, current_row):
if current_row is None:
return
@ -3967,8 +3969,7 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
self.ser_attrs.append('tools')
if change_message is False:
self.app.inform.emit('[success] %s' %
_("Tool added in Tool Table."))
self.app.inform.emit('[success] %s' % _("Tool added in Tool Table."))
else:
change_message = False
self.app.inform.emit('[WARNING_NOTCL] %s' %
@ -3979,8 +3980,72 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
if self.ui.geo_tools_table.rowCount() != 0:
self.ui.geo_param_frame.setDisabled(False)
def on_tool_add_from_db(self):
pass
def on_tool_add_from_db_clicked(self):
"""
Called when the user wants to add a new tool from Tools Database. It will create the Tools Database object
and display the Tools Database tab in the form needed for the Tool adding
:return: None
"""
self.app.on_tools_database()
self.app.tools_db_tab.buttons_frame.hide()
self.app.tools_db_tab.add_tool_from_db.show()
def on_tool_from_db_inserted(self, tool):
"""
Called from the Tools DB object through a App method when adding a tool from Tools Database
:param tool: a dict with the tool data
:return: None
"""
self.ui_disconnect()
self.units = self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().upper()
tooldia = float(tool['tooldia'])
# construct a list of all 'tooluid' in the self.tools
tool_uid_list = []
for tooluid_key in self.tools:
tool_uid_item = int(tooluid_key)
tool_uid_list.append(tool_uid_item)
# find maximum from the temp_uid, add 1 and this is the new 'tooluid'
if not tool_uid_list:
max_uid = 0
else:
max_uid = max(tool_uid_list)
self.tooluid = max_uid + 1
tooldia = float('%.*f' % (self.decimals, tooldia))
self.tools.update({
self.tooluid: {
'tooldia': tooldia,
'offset': tool['offset'],
'offset_value': float(tool['offset_value']),
'type': tool['type'],
'tool_type': tool['tool_type'],
'data': deepcopy(tool['data']),
'solid_geometry': self.solid_geometry
}
})
self.tools[self.tooluid]['data']['name'] = self.options['name']
self.ui.tool_offset_entry.hide()
self.ui.tool_offset_lbl.hide()
# we do this HACK to make sure the tools attribute to be serialized is updated in the self.ser_attrs list
try:
self.ser_attrs.remove('tools')
except TypeError:
pass
self.ser_attrs.append('tools')
self.build_ui()
# if there is no tool left in the Tools Table, enable the parameters GUI
if self.ui.geo_tools_table.rowCount() != 0:
self.ui.geo_param_frame.setDisabled(False)
def on_tool_copy(self, all=None):
self.ui_disconnect()

View File

@ -9,6 +9,11 @@ CAD program, and create G-Code for Isolation routing.
=================================================
9.11.2019
- fixed a new bug that did not allow to open the FlatCAM Preferences files by doubleclick in Windows
- added a new feature: Tools Database for Geometry objects; resolved issue #308
8.11.2019
- updated the make file for freezed executable

View File

@ -193,12 +193,12 @@ class TextEditor(QtWidgets.QWidget):
try:
filename = str(QtWidgets.QFileDialog.getSaveFileName(
caption=_("Export G-Code ..."),
caption=_("Export Code ..."),
directory=self.app.defaults["global_last_folder"] + '/' + str(obj_name),
filter=_filter_
)[0])
except TypeError:
filename = str(QtWidgets.QFileDialog.getSaveFileName(caption=_("Export G-Code ..."), filter=_filter_)[0])
filename = str(QtWidgets.QFileDialog.getSaveFileName(caption=_("Export Code ..."), filter=_filter_)[0])
if filename == "":
self.app.inform.emit('[WARNING_NOTCL] %s' % _("Export Code cancelled."))

View File

@ -363,7 +363,8 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
self.menuoptions_view_source = self.menuoptions.addAction(QtGui.QIcon('share/source32.png'),
_("View source\tALT+S"))
self.menuoptions_tools_db = self.menuoptions.addAction(QtGui.QIcon('share/database32.png'), _("Tools DataBase"))
self.menuoptions_tools_db = self.menuoptions.addAction(QtGui.QIcon('share/database32.png'),
_("Tools DataBase\tCTRL+D"))
# Separator
self.menuoptions.addSeparator()
@ -1221,6 +1222,10 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
<td height="20"><strong>CTRL+C</strong></td>
<td>&nbsp;%s</td>
</tr>
<tr height="20">
<td height="20"><strong>CTRL+D</strong></td>
<td>&nbsp;%s</td>
</tr>
<tr height="20">
<td height="20"><strong>CTRL+E</strong></td>
<td>&nbsp;%s</td>
@ -1422,7 +1427,7 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
_("Flip on X_axis"), _("Flip on Y_axis"), _("Zoom Out"), _("Zoom In"),
# CTRL section
_("Select All"), _("Copy Obj"),
_("Select All"), _("Copy Obj"), _("Open Tools Database"),
_("Open Excellon File"), _("Open Gerber File"), _("New Project"), _("Distance Tool"),
_("Open Project"), _("PDF Import Tool"), _("Save Project As"), _("Toggle Plot Area"),
@ -2375,6 +2380,10 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
if key == QtCore.Qt.Key_C:
self.app.on_copy_object()
# Copy an FlatCAM object
if key == QtCore.Qt.Key_D:
self.app.on_tools_database()
# Open Excellon file
if key == QtCore.Qt.Key_E:
self.app.on_fileopenexcellon()
@ -2405,6 +2414,13 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
if widget_name == 'preferences_tab':
self.app.on_save_button()
return
if widget_name == 'database_tab':
# Tools DB saved, update flag
self.app.tools_db_changed_flag = False
self.app.tools_db_tab.on_save_tools_db()
return
self.app.on_file_saveproject()
# Toggle Plot Area

View File

@ -376,9 +376,9 @@ class FCEntry(QtWidgets.QLineEdit):
def get_value(self):
return str(self.text())
def set_value(self, val):
def set_value(self, val, decimals=4):
if type(val) is float:
self.setText('%.4f' % val)
self.setText('%.*f' % (decimals, val))
else:
self.setText(str(val))