diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 819a6faa..3dfd5a30 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -467,6 +467,9 @@ class App(QtCore.QObject): "cncjob_plot": self.ui.cncjob_defaults_form.cncjob_gen_group.plot_cb, "cncjob_plot_kind": self.ui.cncjob_defaults_form.cncjob_gen_group.cncplot_method_radio, "cncjob_annotation": self.ui.cncjob_defaults_form.cncjob_gen_group.annotation_cb, + "cncjob_annotation_fontsize": self.ui.cncjob_defaults_form.cncjob_gen_group.annotation_fontsize_sp, + "cncjob_annotation_fontcolor": self.ui.cncjob_defaults_form.cncjob_gen_group.annotation_fontcolor_entry, + "cncjob_tooldia": self.ui.cncjob_defaults_form.cncjob_gen_group.tooldia_entry, "cncjob_coords_decimals": self.ui.cncjob_defaults_form.cncjob_gen_group.coords_dec_entry, "cncjob_fr_decimals": self.ui.cncjob_defaults_form.cncjob_gen_group.fr_dec_entry, @@ -792,6 +795,8 @@ class App(QtCore.QObject): "cncjob_plot": True, "cncjob_plot_kind": 'all', "cncjob_annotation": True, + "cncjob_annotation_fontsize": 9, + "cncjob_annotation_fontcolor": '#990000', "cncjob_tooldia": 0.0393701, "cncjob_coords_decimals": 4, "cncjob_fr_decimals": 2, @@ -1176,11 +1181,11 @@ class App(QtCore.QObject): # # ## Define OBJECT COLLECTION # ## self.collection = ObjectCollection(self) self.ui.project_tab_layout.addWidget(self.collection.view) - # # ## + # ### self.log.debug("Finished creating Object Collection.") - # # ## Initialize the color box's color in Preferences -> Global -> Color + # ### Initialize the color box's color in Preferences -> Global -> Color # Init Plot Colors self.ui.general_defaults_form.general_gui_group.pf_color_entry.set_value(self.defaults['global_plot_fill']) self.ui.general_defaults_form.general_gui_group.pf_color_button.setStyleSheet( @@ -1243,9 +1248,15 @@ class App(QtCore.QObject): self.defaults['global_proj_item_dis_color']) self.ui.general_defaults_form.general_gui_group.proj_color_dis_button.setStyleSheet( "background-color:%s" % str(self.defaults['global_proj_item_dis_color'])[:7]) - # # ## End of Data ## ## - # # ## Plot Area ## ## + # Init the Annotation CNC Job color + self.ui.cncjob_defaults_form.cncjob_gen_group.annotation_fontcolor_entry.set_value( + self.defaults['cncjob_annotation_fontcolor']) + self.ui.cncjob_defaults_form.cncjob_gen_group.annotation_fontcolor_button.setStyleSheet( + "background-color:%s" % str(self.defaults['cncjob_annotation_fontcolor'])[:7]) + # ### End of Data ## ## + + # ### Plot Area ## ## start_plot_time = time.time() # debug self.plotcanvas = PlotCanvas(self.ui.right_layout, self) @@ -1528,6 +1539,10 @@ class App(QtCore.QObject): self.ui.cncjob_defaults_form.cncjob_adv_opt_group.tc_variable_combo.currentIndexChanged[str].connect( self.on_cnc_custom_parameters) + self.ui.cncjob_defaults_form.cncjob_gen_group.annotation_fontcolor_entry.editingFinished.connect( + self.on_annotation_fontcolor_entry) + self.ui.cncjob_defaults_form.cncjob_gen_group.annotation_fontcolor_button.clicked.connect( + self.on_annotation_fontcolor_button) # Modify G-CODE Plot Area TAB self.ui.code_editor.textChanged.connect(self.handleTextChanged) @@ -4181,6 +4196,28 @@ class App(QtCore.QObject): self.ui.general_defaults_form.general_gui_group.proj_color_dis_entry.set_value(new_val_sel) self.defaults['global_proj_item_dis_color'] = new_val_sel + def on_annotation_fontcolor_entry(self): + self.defaults['cncjob_annotation_fontcolor'] = \ + self.ui.cncjob_defaults_form.cncjob_gen_group.annotation_fontcolor_entry.get_value() + self.ui.cncjob_defaults_form.cncjob_gen_group.annotation_fontcolor_button.setStyleSheet( + "background-color:%s" % str(self.defaults['cncjob_annotation_fontcolor'])) + + def on_annotation_fontcolor_button(self): + current_color = QtGui.QColor(self.defaults['cncjob_annotation_fontcolor']) + + c_dialog = QtWidgets.QColorDialog() + annotation_color = c_dialog.getColor(initial=current_color) + + if annotation_color.isValid() is False: + return + + self.ui.cncjob_defaults_form.cncjob_gen_group.annotation_fontcolor_button.setStyleSheet( + "background-color:%s" % str(annotation_color.name())) + + new_val_sel = str(annotation_color.name()) + self.ui.cncjob_defaults_form.cncjob_gen_group.annotation_fontcolor_entry.set_value(new_val_sel) + self.defaults['global_proj_item_dis_color'] = new_val_sel + def on_deselect_all(self): self.collection.set_all_inactive() self.delete_selection_shape() @@ -8299,7 +8336,7 @@ The normal flow when working in FlatCAM is the following:

""" log.debug("Enabling plots ...") - + self.inform.emit(_("Working ...")) for obj in objects: obj.options['plot'] = True self.plots_updated.emit() @@ -8312,7 +8349,7 @@ The normal flow when working in FlatCAM is the following:

""" log.debug("Disabling plots ...") - + self.inform.emit(_("Working ...")) for obj in objects: obj.options['plot'] = False self.plots_updated.emit() diff --git a/FlatCAMObj.py b/FlatCAMObj.py index a2cb16f9..0c4e0815 100644 --- a/FlatCAMObj.py +++ b/FlatCAMObj.py @@ -339,13 +339,18 @@ class FlatCAMObj(QtCore.QObject): @visible.setter def visible(self, value): - self.shapes.visible = value + log.debug("FlatCAMObj.visible()") - # Not all object types has annotations - try: - self.annotation.visible = value - except Exception as e: - pass + def worker_task(app_obj): + app_obj.shapes.visible = value + + # Not all object types has annotations + try: + app_obj.annotation.visible = value + except Exception as e: + pass + + self.app.worker_task.emit({'fcn': worker_task, 'params': [self]}) @property def drawing_tolerance(self): diff --git a/README.md b/README.md index d17b2cc9..d34d2608 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,9 @@ CAD program, and create G-Code for Isolation routing. 3.06.2019 - TclCommand Geocutout is now creating a new geometry object when working on a geometry, preserving also the origin object +- added a new parameter in Edit -> Preferences -> CNCJob named Annotation Color; it controls the color of the font used for annotations +- added a new parameter in Edit -> Preferences -> CNCJob named Annotation Size; it controls the size of the font used for annotations +- made visibility change threaded in FlatCAMObj() 2.06.2019 diff --git a/camlib.py b/camlib.py index 62a65b79..47c3cb17 100644 --- a/camlib.py +++ b/camlib.py @@ -6541,7 +6541,9 @@ class CNCjob(Geometry): obj.add_shape(shape=poly, color=color['C'][1], face_color=color['C'][0], visible=visible, layer=1) - obj.annotation.set(text=text, pos=pos, visible=obj.options['plot']) + obj.annotation.set(text=text, pos=pos, visible=obj.options['plot'], + font_size=self.app.defaults["cncjob_annotation_fontsize"], + color=self.app.defaults["cncjob_annotation_fontcolor"]) def create_geometry(self): # TODO: This takes forever. Too much data? diff --git a/flatcamGUI/FlatCAMGUI.py b/flatcamGUI/FlatCAMGUI.py index 52029cae..34e6d8af 100644 --- a/flatcamGUI/FlatCAMGUI.py +++ b/flatcamGUI/FlatCAMGUI.py @@ -5458,45 +5458,77 @@ class CNCJobGenPrefGroupUI(OptionsGroupUI): grid0.addWidget(self.annotation_cb, 2, 1) grid0.addWidget(QtWidgets.QLabel(''), 2, 2) - # Number of circle steps for circular aperture linear approximation + # Annotation Font Size + self.annotation_fontsize_label = QtWidgets.QLabel(_("Annotation Size:")) + self.annotation_fontsize_label.setToolTip( + _("The font size of the annotation text. In pixels.") + ) + grid0.addWidget(self.annotation_fontsize_label, 3, 0) + self.annotation_fontsize_sp = FCSpinner() + grid0.addWidget(self.annotation_fontsize_sp, 3, 1) + grid0.addWidget(QtWidgets.QLabel(''), 3, 2) + + # Annotation Font Color + self.annotation_color_label = QtWidgets.QLabel(_('Annotation Color:')) + self.annotation_color_label.setToolTip( + _("Set the font color for the annotation texts.\n") + ) + self.annotation_fontcolor_entry = FCEntry() + self.annotation_fontcolor_button = QtWidgets.QPushButton() + self.annotation_fontcolor_button.setFixedSize(15, 15) + + self.form_box_child = QtWidgets.QHBoxLayout() + self.form_box_child.addWidget(self.annotation_fontcolor_entry) + self.form_box_child.addWidget(self.annotation_fontcolor_button) + self.form_box_child.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) + + color_widget = QtWidgets.QWidget() + color_widget.setLayout(self.form_box_child) + grid0.addWidget(self.annotation_color_label, 4, 0) + grid0.addWidget(color_widget, 4, 1) + grid0.addWidget(QtWidgets.QLabel(''), 4, 2) + + # ################################################################### + # Number of circle steps for circular aperture linear approximation # + # ################################################################### self.steps_per_circle_label = QtWidgets.QLabel(_("Circle Steps:")) self.steps_per_circle_label.setToolTip( _("The number of circle steps for GCode \n" - "circle and arc shapes linear approximation.") + "circle and arc shapes linear approximation.") ) - grid0.addWidget(self.steps_per_circle_label, 3, 0) + grid0.addWidget(self.steps_per_circle_label, 5, 0) self.steps_per_circle_entry = IntEntry() - grid0.addWidget(self.steps_per_circle_entry, 3, 1) + grid0.addWidget(self.steps_per_circle_entry, 5, 1) # Tool dia for plot tdlabel = QtWidgets.QLabel(_('Tool dia:')) tdlabel.setToolTip( _("Diameter of the tool to be\n" - "rendered in the plot.") + "rendered in the plot.") ) - grid0.addWidget(tdlabel, 4, 0) + grid0.addWidget(tdlabel, 6, 0) self.tooldia_entry = LengthEntry() - grid0.addWidget(self.tooldia_entry,4, 1) + grid0.addWidget(self.tooldia_entry,6, 1) # Number of decimals to use in GCODE coordinates cdeclabel = QtWidgets.QLabel(_('Coords dec.:')) cdeclabel.setToolTip( _("The number of decimals to be used for \n" - "the X, Y, Z coordinates in CNC code (GCODE, etc.)") + "the X, Y, Z coordinates in CNC code (GCODE, etc.)") ) - grid0.addWidget(cdeclabel, 5, 0) + grid0.addWidget(cdeclabel, 7, 0) self.coords_dec_entry = IntEntry() - grid0.addWidget(self.coords_dec_entry, 5, 1) + grid0.addWidget(self.coords_dec_entry, 7, 1) # Number of decimals to use in GCODE feedrate frdeclabel = QtWidgets.QLabel(_('Feedrate dec.:')) frdeclabel.setToolTip( _("The number of decimals to be used for \n" - "the Feedrate parameter in CNC code (GCODE, etc.)") + "the Feedrate parameter in CNC code (GCODE, etc.)") ) - grid0.addWidget(frdeclabel, 6, 0) + grid0.addWidget(frdeclabel, 8, 0) self.fr_dec_entry = IntEntry() - grid0.addWidget(self.fr_dec_entry, 6, 1) + grid0.addWidget(self.fr_dec_entry, 8, 1) self.layout.addStretch() diff --git a/flatcamGUI/VisPyVisuals.py b/flatcamGUI/VisPyVisuals.py index c6016233..254698fd 100644 --- a/flatcamGUI/VisPyVisuals.py +++ b/flatcamGUI/VisPyVisuals.py @@ -456,20 +456,26 @@ class TextCollectionVisual(TextVisual): self.data = {} self.last_key = -1 self.lock = threading.Lock() - + self.method = 'gpu' super(TextCollectionVisual, self).__init__(**kwargs) self.freeze() - def add(self, text, pos, visible=True, update=True): + def add(self, text, pos, visible=True, update=True, font_size=9, color='black'): """ Adds array of text to collection :param text: list Array of strings ['str1', 'str2', ... ] :param pos: list Array of string positions [(0, 0), (10, 10), ... ] + :param visible: bool + | Set True to make it visible :param update: bool Set True to redraw collection + :param font_size: int + Set font size to redraw collection + :param color: string + Set font color to redraw collection :return: int Index of array """ @@ -480,7 +486,7 @@ class TextCollectionVisual(TextVisual): self.lock.release() # Prepare data for translation - self.data[key] = {'text': text, 'pos': pos, 'visible': visible} + self.data[key] = {'text': text, 'pos': pos, 'visible': visible,'font_size': font_size, 'color': color} if update: self.redraw() @@ -516,6 +522,8 @@ class TextCollectionVisual(TextVisual): """ labels = [] pos = [] + font_s = 9 + color = 'black' # Merge buffers for data in list(self.data.values()): @@ -523,6 +531,8 @@ class TextCollectionVisual(TextVisual): try: labels += data['text'] pos += data['pos'] + font_s = data['font_size'] + color = data['color'] except Exception as e: print("Data error", e) @@ -530,6 +540,8 @@ class TextCollectionVisual(TextVisual): if len(labels) > 0: self.text = labels self.pos = pos + self.font_size = font_s + self.color = color else: self.text = None self.pos = (0, 0)