From faf41d7bcab75f47a9502721fbc9b354d6759c35 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sat, 8 Apr 2023 12:29:45 +0300 Subject: [PATCH] - major change: from now on the only dimensional units available are those from ISO METRIC system --- CHANGELOG.md | 1 + appGUI/MainGUI.py | 15 +- appGUI/preferences/PreferencesUIManager.py | 2 - .../general/GeneralAppPrefGroupUI.py | 31 +- appHandlers/AppIO.py | 2 - appMain.py | 313 +----------------- defaults.py | 1 - 7 files changed, 8 insertions(+), 357 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf4e5a01..8f715a59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ CHANGELOG for FlatCAM Evo beta - fixed some really long strings in the Geometry Editor toolbar actions - modified the paint and buffer icons - optimized the editor menu/toolbar action names +- major change: from now on the only dimensional units available are those from ISO METRIC system 22.03.2023 diff --git a/appGUI/MainGUI.py b/appGUI/MainGUI.py index 3b758200..948e1588 100644 --- a/appGUI/MainGUI.py +++ b/appGUI/MainGUI.py @@ -491,9 +491,6 @@ class MainGUI(QtWidgets.QMainWindow): # Separator self.menuedit.addSeparator() - self.menuedittoggleunits = self.menuedit.addAction( - QtGui.QIcon(self.app.resource_location + '/toggle_units16.png'), - '%s\t%s' % (_('Toggle Units'), _('Q'))) self.menueditselectall = self.menuedit.addAction( QtGui.QIcon(self.app.resource_location + '/select_all.png'), '%s\t%s' % (_('Select All'), _('Ctrl+A'))) @@ -1981,7 +1978,7 @@ class MainGUI(QtWidgets.QMainWindow): self.status_toolbar.setVisible(self.app.defaults["global_statusbar_show"]) self.units_label = FCLabel("[mm]") - self.units_label.setToolTip(_("Application units")) + self.units_label.setToolTip(_("The application dimensional units is millimeter.")) self.units_label.setMargin(2) self.infobar.addWidget(self.units_label) @@ -3372,12 +3369,7 @@ class MainGUI(QtWidgets.QMainWindow): # Change Units if key == QtCore.Qt.Key.Key_Q: - # if self.app.app_units == 'MM': - # self.app.ui.general_pref_form.general_app_group.units_radio.set_value("IN") - # else: - # self.app.ui.general_pref_form.general_app_group.units_radio.set_value("MM") - # self.app.on_toggle_units(no_pref=True) - self.app.on_toggle_units_click() + pass # Rotate Object by 90 degree CW if key == QtCore.Qt.Key.Key_R: @@ -3960,7 +3952,6 @@ class MainGUI(QtWidgets.QMainWindow): # Add Track if key == QtCore.Qt.Key.Key_T or key == 'T': self.app.grb_editor.launched_from_shortcuts = True - # ## Current application units in Upper Case self.app.grb_editor.select_tool('track') return @@ -4230,7 +4221,7 @@ class MainGUI(QtWidgets.QMainWindow): if key == QtCore.Qt.Key.Key_T or key == 'T': self.app.exc_editor.launched_from_shortcuts = True # ## Current application units in Upper Case - self.units = self.general_pref_form.general_app_group.units_radio.get_value().upper() + self.units = "MM" tool_add_popup = FCInputDoubleSpinner(title='%s ...' % _("New Tool"), text='%s:' % _('Enter a Tool Diameter'), min=0.0000, max=99.9999, decimals=self.decimals) diff --git a/appGUI/preferences/PreferencesUIManager.py b/appGUI/preferences/PreferencesUIManager.py index 9eed28de..1d69df04 100644 --- a/appGUI/preferences/PreferencesUIManager.py +++ b/appGUI/preferences/PreferencesUIManager.py @@ -55,9 +55,7 @@ class PreferencesUIManager(QtCore.QObject): # def app_obj.new_object(self, kind, name, initialize, active=True, fit=True, plot=True) self.defaults_form_fields = { # General App - "decimals_inch": self.ui.general_pref_form.general_app_group.precision_inch_entry, "decimals_metric": self.ui.general_pref_form.general_app_group.precision_metric_entry, - "units": self.ui.general_pref_form.general_app_group.units_radio, "global_graphic_engine": self.ui.general_pref_form.general_app_group.ge_radio, "global_graphic_engine_3d_no_mp": self.ui.general_pref_form.general_app_group.ge_comp_cb, "global_app_level": self.ui.general_pref_form.general_app_group.app_level_radio, diff --git a/appGUI/preferences/general/GeneralAppPrefGroupUI.py b/appGUI/preferences/general/GeneralAppPrefGroupUI.py index b76400ff..6dc5d6cd 100644 --- a/appGUI/preferences/general/GeneralAppPrefGroupUI.py +++ b/appGUI/preferences/general/GeneralAppPrefGroupUI.py @@ -30,9 +30,7 @@ class GeneralAppPrefGroupUI(OptionsGroupUI): # Grid0 Frame # ############################################################################################################# self.unitslabel = FCLabel('%s' % _("Units"), color='red', bold=True) - self.unitslabel.setToolTip(_("The default value for the application units.\n" - "Whatever is selected here is set every time\n" - "the application is started.")) + self.unitslabel.setToolTip(_("The application dimensional units is millimeter.")) self.layout.addWidget(self.unitslabel) grid0_frame = FCFrame() @@ -41,19 +39,10 @@ class GeneralAppPrefGroupUI(OptionsGroupUI): grid0 = GLay(v_spacing=5, h_spacing=3) grid0_frame.setLayout(grid0) - # Units for FlatCAM - self.units_radio = RadioSetDefaults( - choices=[{'label': _('mm'), 'value': 'MM'}, {'label': _('inch'), 'value': 'IN'}], - compact=True - ) - - grid0.addWidget(self.units_radio, 0, 0, 1, 2) - # Precision Metric - self.precision_metric_label = FCLabel('%s:' % _('Precision MM')) + self.precision_metric_label = FCLabel('%s:' % _('Dim. Precision')) self.precision_metric_label.setToolTip( - _("The number of decimals used throughout the application\n" - "when the set units are in METRIC system.\n" + _("The number of decimals used throughout the application.\n" "Any change here require an application restart.") ) self.precision_metric_entry = FCSpinner() @@ -63,20 +52,6 @@ class GeneralAppPrefGroupUI(OptionsGroupUI): grid0.addWidget(self.precision_metric_label, 2, 0) grid0.addWidget(self.precision_metric_entry, 2, 1) - # Precision Inch - self.precision_inch_label = FCLabel('%s:' % _('Precision Inch')) - self.precision_inch_label.setToolTip( - _("The number of decimals used throughout the application\n" - "when the set units are in INCH system.\n" - "Any change here require an application restart.") - ) - self.precision_inch_entry = FCSpinner() - self.precision_inch_entry.set_range(2, 16) - self.precision_inch_entry.setWrapping(True) - - grid0.addWidget(self.precision_inch_label, 4, 0) - grid0.addWidget(self.precision_inch_entry, 4, 1) - self.par_label = FCLabel('%s' % _("Parameters"), color='blue', bold=True) self.layout.addWidget(self.par_label) diff --git a/appHandlers/AppIO.py b/appHandlers/AppIO.py index e547ed3f..f871b7cc 100644 --- a/appHandlers/AppIO.py +++ b/appHandlers/AppIO.py @@ -2599,8 +2599,6 @@ class AppIO(QtCore.QObject): # for some reason, setting ui_title does not work when this method is called from Tcl Shell # it's because the TclCommand is run in another thread (it inherits TclCommandSignaled) - if cli is None: - self.app.set_screen_units(self.app.options["units"]) self.app.restore_project_objects_sig.emit(proj_dict, filename, cli, plot) diff --git a/appMain.py b/appMain.py index a3435e00..a0bd1aae 100644 --- a/appMain.py +++ b/appMain.py @@ -619,11 +619,7 @@ class App(QtCore.QObject): self.app_units = self.options["units"] self.default_units = self.defaults["units"] - - if self.app_units == 'MM': - self.decimals = int(self.options['decimals_metric']) - else: - self.decimals = int(self.options['decimals_inch']) + self.decimals = int(self.options['decimals_metric']) if self.options["global_theme"] == 'default': self.resource_location = 'assets/resources' @@ -803,8 +799,6 @@ class App(QtCore.QObject): self.ui = MainGUI(self) # ######################## - # set FlatCAM units in the Status bar - self.set_screen_units(self.app_units) # decide if to show or hide the Notebook side of the screen at startup if self.options["global_project_at_startup"] is True: @@ -1911,7 +1905,6 @@ class App(QtCore.QObject): self.ui.menueditjump.triggered.connect(self.on_jump_to) self.ui.menueditlocate.triggered.connect(lambda: self.on_locate(obj=self.collection.get_active())) - self.ui.menuedittoggleunits.triggered.connect(self.on_toggle_units_click) self.ui.menueditselectall.triggered.connect(self.on_selectall) self.ui.menueditpreferences.triggered.connect(self.on_preferences) @@ -4214,310 +4207,6 @@ class App(QtCore.QObject): """ self.preferencesUiManager.defaults_write_form_field(field=field) - if field == "units": - self.set_screen_units(self.app_units) - - def set_screen_units(self, units): - """ - Set the FlatCAM units on the status bar. - - :param units: the new measuring units to be displayed in FlatCAM's status bar. - :return: None - """ - self.ui.units_label.setText("[" + units.lower() + "]") - - def on_toggle_units_click(self): - try: - new_units, factor = self.on_toggle_units() - except TypeError: - # hen the self.on_toggle_units() return only one value (maybe None) it means something went wrong, - # it will end up in this exception, and we should return - return - - if self.ui.plot_tab_area.currentWidget().objectName() == "preferences_tab": - if factor != 1: # means we had a unit change in the rest of the app - if self.app_units != new_units: - pref_factor = 25.4 if new_units == 'MM' else 1 / 25.4 - self.scale_preferences(pref_factor, new_units) - - self.options["units"] = new_units - - # update th new units in the preferences storage - self.app_units = new_units - - def scale_preferences(self, sfactor, new_units): - self.preferencesUiManager.defaults_read_form() - - # update the defaults from form, some may assume that the conversion is enough, and it's not - self.on_defaults2options() - - # Keys in self.options for which to scale their values - dimensions = [ - # Global - 'global_gridx', 'global_gridy', 'global_snap_max', "global_tolerance", - 'global_tpdf_bmargin', 'global_tpdf_tmargin', 'global_tpdf_rmargin', 'global_tpdf_lmargin', - - # Gerber Object - 'gerber_noncoppermargin', 'gerber_bboxmargin', - - # Gerber Editor - "gerber_editor_newsize", "gerber_editor_lin_pitch", "gerber_editor_buff_f", - "gerber_editor_newdim", "gerber_editor_ma_low", "gerber_editor_ma_high", - - # Excellon Object - 'excellon_drill_tooldia', 'excellon_slot_tooldia', - - # Excellon Editor - "excellon_editor_newdia", "excellon_editor_lin_pitch", "excellon_editor_slot_lin_pitch", - "excellon_editor_slot_length", - - # Geometry Object - 'tools_mill_cutz', "tools_mill_depthperpass", 'tools_mill_travelz', 'tools_mill_feedrate', - 'tools_mill_feedrate_rapid', "tools_mill_toolchangez", "tools_mill_feedrate_z", - "tools_mill_toolchangexy", 'tools_mill_tooldia', 'tools_mill_endz', 'tools_mill_endxy', - "tools_mill_extracut_length", "tools_mill_z_pdepth", - "tools_mill_feedrate_probe", "tools_mill_startz", "geometry_segx", "geometry_segy", "tools_mill_area_overz", - - # CNCJob Object - 'cncjob_tooldia', 'cncjob_bed_max_x', 'cncjob_bed_max_y', 'cncjob_bed_offset_x', 'cncjob_bed_offset_y', - 'cncjob_bed_skew_x', 'cncjob_bed_skew_y', - - # AutoLevelling Plugin - "tools_al_travelz", "tools_al_probe_depth", "tools_al_grbl_jog_step", - "tools_al_grbl_jog_fr", "tools_al_grbl_travelz", - - # Isolation Plugin - "tools_iso_tool_cutz", - - # Drilling Plugin - 'tools_drill_cutz', 'tools_drill_depthperpass', 'tools_drill_travelz', 'tools_drill_endz', - 'tools_drill_endxy', 'tools_drill_feedrate_z', 'tools_drill_toolchangez', "tools_drill_drill_overlap", - 'tools_drill_offset', "tools_drill_toolchangexy", "tools_drill_startz", 'tools_drill_feedrate_rapid', - "tools_drill_feedrate_probe", "tools_drill_z_pdepth", "tools_drill_area_overz", - - # NCC Plugin - "tools_ncc_tools", "tools_ncc_margin", "tools_ncc_offset_value", "tools_ncc_cutz", "tools_ncc_tipdia", - "tools_ncc_newdia", - - # Cutout Plugin - "tools_cutout_tooldia", 'tools_cutout_margin', "tools_cutout_z", "tools_cutout_depthperpass", - 'tools_cutout_gapsize', 'tools_cutout_gap_depth', 'tools_cutout_mb_dia', 'tools_cutout_mb_spacing', - - # Paint Plugin - "tools_paint_tooldia", 'tools_paint_offset', "tools_paint_cutz", "tools_paint_tipdia", "tools_paint_newdia", - - # 2Sided Plugin - "tools_2sided_drilldia", - - # Film Plugin - "tools_film_boundary", "tools_film_scale_stroke", - - # Panel Plugin - "tools_panelize_spacing_columns", "tools_panelize_spacing_rows", "tools_panelize_constrainx", - "tools_panelize_constrainy", - - # Calculators Plugin - "tools_calc_vshape_tip_dia", "tools_calc_vshape_cut_z", - - # Transform Plugin - "tools_transform_ref_point", "tools_transform_offset_x", "tools_transform_offset_y", - "tools_transform_buffer_dis", - - # SolderPaste Plugin - "tools_solderpaste_tools", "tools_solderpaste_new", "tools_solderpaste_z_start", - "tools_solderpaste_z_dispense", "tools_solderpaste_z_stop", "tools_solderpaste_z_travel", - "tools_solderpaste_z_toolchange", "tools_solderpaste_xy_toolchange", "tools_solderpaste_frxy", - "tools_solderpaste_frz", "tools_solderpaste_frz_dispense", - - # Markers Plugin - "tools_markers_thickness", "tools_markers_length", "tools_markers_offset_x", "tools_markers_offset_y", - - # Check Rules Plugin - "tools_cr_trace_size_val", "tools_cr_c2c_val", "tools_cr_c2o_val", "tools_cr_s2s_val", "tools_cr_s2sm_val", - "tools_cr_s2o_val", "tools_cr_sm2sm_val", "tools_cr_ri_val", "tools_cr_h2h_val", "tools_cr_dh_val", - - # QRCode Plugin - "tools_qrcode_border_size", - - # Copper Thieving Plugin - "tools_copper_thieving_clearance", "tools_copper_thieving_margin", - "tools_copper_thieving_dots_dia", "tools_copper_thieving_dots_spacing", - "tools_copper_thieving_squares_size", "tools_copper_thieving_squares_spacing", - "tools_copper_thieving_lines_size", "tools_copper_thieving_lines_spacing", - "tools_copper_thieving_rb_margin", "tools_copper_thieving_rb_thickness", - "tools_copper_thieving_mask_clearance", - - # Fiducials Plugin - "tools_fiducials_dia", "tools_fiducials_margin", "tools_fiducials_line_thickness", - - # Drills Extraction Plugin - "tools_extract_hole_fixed_dia", "tools_extract_circular_ring", "tools_extract_oblong_ring", - "tools_extract_square_ring", "tools_extract_rectangular_ring", "tools_extract_others_ring", - - # Punch Gerber Plugin - "tools_punch_hole_fixed_dia", "tools_punch_circular_ring", "tools_punch_oblong_ring", - "tools_punch_square_ring", "tools_punch_rectangular_ring", "tools_punch_others_ring", - - # Invert Gerber Plugin - "tools_invert_margin", - - ] - for dim in dimensions: - if dim in ['tools_mill_tooldia', 'tools_ncc_tools', 'tools_solderpaste_tools', 'tools_iso_tooldia', - 'tools_paint_tooldia', 'tools_transform_ref_point', 'tools_cal_toolchange_xy', - 'gerber_editor_newdim', 'tools_drill_toolchangexy', 'tools_drill_endxy', - 'tools_mill_toolchangexy', 'tools_mill_endxy', 'tools_solderpaste_xy_toolchange']: - if not self.options[dim] or self.options[dim] == '': - continue - - if isinstance(self.options[dim], str): - try: - tools_diameters = eval(self.options[dim]) - except Exception as e: - self.log.error("App.on_toggle_units().scale_defaults() lists --> %s" % str(e)) - continue - elif isinstance(self.options[dim], (float, int)): - tools_diameters = [self.options[dim]] - else: - tools_diameters = list(self.options[dim]) - - if isinstance(tools_diameters, (tuple, list)): - pass - elif isinstance(tools_diameters, (int, float)): - tools_diameters = [self.options[dim]] - else: - continue - - td_len = len(tools_diameters) - conv_list = [] - for t in range(td_len): - conv_list.append(self.dec_format(float(tools_diameters[t]) * sfactor, self.decimals)) - - self.options[dim] = conv_list - elif dim in ['global_gridx', 'global_gridy']: - # format the number of decimals to the one specified in self.decimals - try: - val = float(self.options[dim]) * sfactor - except Exception as e: - self.log.error('App.on_toggle_units().scale_defaults() grids --> %s' % str(e)) - continue - - self.options[dim] = self.dec_format(val, self.decimals) - else: - # the number of decimals for the rest is kept unchanged - if self.options[dim]: - try: - val = float(self.options[dim]) * sfactor - except Exception as e: - self.log.error( - 'App.on_toggle_units().scale_defaults() standard --> Value: %s %s' % (str(dim), str(e)) - ) - continue - - self.options[dim] = self.dec_format(val, self.decimals) - - self.preferencesUiManager.defaults_write_form(fl_units=new_units) - - def on_toggle_units(self): - """ - Callback for the Units radio-button change in the Preferences tab. - Changes the application's default units adn for the project too. - If changing the project's units, the change propagates to all - the objects in the project. - - :return: The new application units. String: "IN" or "MM" with caps lock - """ - - if self.toggle_units_ignore: - return - - new_units = 'IN' if self.app_units.upper() == 'MM' else 'MM' - - # we can't change the units while inside the Editors - if self.call_source in ['geo_editor', 'grb_editor', 'exc_editor']: - msg = _("Units cannot be changed while the editor is active.") - self.inform.emit("[WARNING_NOTCL] %s" % msg) - return - - # ############################################################################################################## - # Changing project units. Ask the user. - # ############################################################################################################## - msgbox = FCMessageBox(parent=self.ui) - title = _("Toggle Units") - txt = _("Changing the units of the project\n" - "will scale all objects.\n\n" - "Do you want to continue?") - msgbox.setWindowTitle(title) # taskbar still shows it - msgbox.setWindowIcon(QtGui.QIcon(self.resource_location + '/app128.png')) - msgbox.setText('%s' % title) - msgbox.setInformativeText(txt) - msgbox.setIconPixmap(QtGui.QPixmap(self.resource_location + '/toggle_units32.png')) - - bt_ok = msgbox.addButton(_('Ok'), QtWidgets.QMessageBox.ButtonRole.AcceptRole) - msgbox.addButton(_('Cancel'), QtWidgets.QMessageBox.ButtonRole.RejectRole) - - msgbox.setDefaultButton(bt_ok) - msgbox.exec() - response = msgbox.clickedButton() - - if response == bt_ok: - new_units = "IN" if self.app_units.upper() == "MM" else "MM" - - # The scaling factor depending on choice of units. - factor = 25.4 if new_units == 'MM' else 1 / 25.4 - - # update the Application objects with the new units - for obj in self.collection.get_list(): - obj.convert_units(new_units) - # make that the properties stored in the object are also updated - self.app_obj.object_changed.emit(obj) - - # rebuild the object UI - obj.build_ui() - - # update workspace if active - if self.options['global_workspace'] is True: - self.plotcanvas.draw_workspace(pagesize=self.options['global_workspaceT']) - - # adjust the grid values on the main toolbar - val_x = round(float(self.options['global_gridx']) * factor, self.decimals) - val_y = val_x if self.ui.grid_gap_link_cb.isChecked() else \ - round(float(self.options['global_gridy']) * factor, self.decimals) - - # update Object UI forms - current = self.collection.get_active() - if current is not None: - # the transfer of converted values to the UI form for Geometry is done local in the AppObjectTemplate.py - if not isinstance(current, GeometryObject): - current.to_form() - - # plot again all objects - self.plot_all() - self.set_screen_units(new_units) - - # flag for the app that we changed the object properties, and it should save the project - self.should_we_save = True - - self.inform.emit('[success] %s: %s' % (_("Converted units to"), new_units)) - else: - factor = 1 - - # store the grid values, so they are not changed in the next step - val_x = float(self.options['global_gridx']) - val_y = float(self.options['global_gridy']) - - self.inform.emit('[WARNING_NOTCL] %s' % _("Cancelled.")) - - self.preferencesUiManager.defaults_read_form() - - # update the Grid snap values - self.options['global_gridx'] = val_x - self.options['global_gridy'] = val_y - self.ui.grid_gap_x_entry.set_value(val_x, decimals=self.decimals) - self.ui.grid_gap_y_entry.set_value(val_y, decimals=self.decimals) - - return new_units, factor - def on_deselect_all(self): self.collection.set_all_inactive() self.delete_selection_shape() diff --git a/defaults.py b/defaults.py index fa8a4b6d..f0779d7e 100644 --- a/defaults.py +++ b/defaults.py @@ -74,7 +74,6 @@ class AppDefaults: "global_tcl_path": '', # General APP Preferences - "decimals_inch": 4, "decimals_metric": 4, "global_graphic_engine": '3D', "global_graphic_engine_3d_no_mp": False,