Browse Source

- added the possibility to display text annotation for the CNC travel lines. The setting is both in Preferences and in the CNC object properties

Marius Stanciu 6 years ago
parent
commit
9abb9c5df2
7 changed files with 76 additions and 14 deletions
  1. 2 0
      FlatCAMApp.py
  2. 23 0
      FlatCAMObj.py
  3. 4 0
      README.md
  4. 7 2
      camlib.py
  5. 23 8
      flatcamGUI/FlatCAMGUI.py
  6. 16 3
      flatcamGUI/ObjectUI.py
  7. 1 1
      flatcamGUI/PlotCanvas.py

+ 2 - 0
FlatCAMApp.py

@@ -466,6 +466,7 @@ class App(QtCore.QObject):
             # CNCJob General
             "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_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,
@@ -790,6 +791,7 @@ class App(QtCore.QObject):
             # CNC Job General
             "cncjob_plot": True,
             "cncjob_plot_kind": 'all',
+            "cncjob_annotation": True,
             "cncjob_tooldia": 0.0393701,
             "cncjob_coords_decimals": 4,
             "cncjob_fr_decimals": 2,

+ 23 - 0
FlatCAMObj.py

@@ -90,6 +90,8 @@ class FlatCAMObj(QtCore.QObject):
         self.isHovering = False
         self.notHovering = True
 
+        self.units = 'IN'
+
         # assert isinstance(self.ui, ObjectUI)
         # self.ui.name_entry.returnPressed.connect(self.on_name_activate)
         # self.ui.offset_button.clicked.connect(self.on_offset_button_click)
@@ -4274,6 +4276,8 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
         # Object initialization function for app.new_object()
         # RUNNING ON SEPARATE THREAD!
         def job_init_single_geometry(job_obj, app_obj):
+            log.debug("Creating a CNCJob out of a single-geometry")
+
             assert isinstance(job_obj, FlatCAMCNCjob), \
                 "Initializer expected a FlatCAMCNCjob, got %s" % type(job_obj)
 
@@ -4485,6 +4489,8 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
         # Object initialization function for app.new_object()
         # RUNNING ON SEPARATE THREAD!
         def job_init_multi_geometry(job_obj, app_obj):
+            log.debug("Creating a CNCJob out of a multi-geometry")
+
             assert isinstance(job_obj, FlatCAMCNCjob), \
                 "Initializer expected a FlatCAMCNCjob, got %s" % type(job_obj)
 
@@ -5461,6 +5467,15 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
         # set the kind of geometries are plotted by default with plot2() from camlib.CNCJob
         self.ui.cncplot_method_combo.set_value(self.app.defaults["cncjob_plot_kind"])
 
+        try:
+            self.ui.annotation_cb.stateChanged.disconnect(self.on_annotation_change)
+        except:
+            pass
+        self.ui.annotation_cb.stateChanged.connect(self.on_annotation_change)
+
+        # set if to display text annotations
+        self.ui.annotation_cb.set_value(self.app.defaults["cncjob_annotation"])
+
         # Show/Hide Advanced Options
         if self.app.defaults["global_app_level"] == 'b':
             self.ui.level.setText(_(
@@ -5910,6 +5925,14 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
             self.shapes.clear(update=True)
             self.annotation.clear(update=True)
 
+    def on_annotation_change(self):
+        if self.ui.annotation_cb.get_value():
+            self.app.plotcanvas.text_collection.enabled = True
+        else:
+            self.app.plotcanvas.text_collection.enabled = False
+        kind = self.ui.cncplot_method_combo.get_value()
+        self.plot(kind=kind)
+
     def convert_units(self, units):
         factor = CNCjob.convert_units(self, units)
         FlatCAMApp.App.log.debug("FlatCAMCNCjob.convert_units()")

+ 4 - 0
README.md

@@ -9,6 +9,10 @@ CAD program, and create G-Code for Isolation routing.
 
 =================================================
 
+31.05.2019
+
+- added the possibility to display text annotation for the CNC travel lines. The setting is both in Preferences and in the CNC object properties
+
 30.05.2019
 
 - editing a multi geometry will no longer pop-up a Tcl window

+ 7 - 2
camlib.py

@@ -6487,6 +6487,7 @@ class CNCjob(Geometry):
         :param tool_tolerance: Tolerance when drawing the toolshape.
         :return: None
         """
+        # units = self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().upper()
 
         gcode_parsed = gcode_parsed if gcode_parsed else self.gcode_parsed
         path_num = 0
@@ -6504,7 +6505,6 @@ class CNCjob(Geometry):
                 elif kind == 'cut':
                     if geo['kind'][0] == 'C':
                         obj.add_shape(shape=geo['geom'], color=color['C'][1], visible=visible)
-
         else:
             text = []
             pos = []
@@ -6512,7 +6512,12 @@ class CNCjob(Geometry):
                 path_num += 1
 
                 text.append(str(path_num))
-                pos.append(geo['geom'].coords[0])
+                current_position = geo['geom'].coords[0]
+                if current_position in pos:
+                    corrected_position = (current_position[0], current_position[1] + tooldia)
+                    pos.append(corrected_position)
+                else:
+                    pos.append(current_position)
 
                 # plot the geometry of Excellon objects
                 if self.origin_kind == 'excellon':

+ 23 - 8
flatcamGUI/FlatCAMGUI.py

@@ -5443,15 +5443,30 @@ class CNCJobGenPrefGroupUI(OptionsGroupUI):
         grid0.addWidget(self.cncplot_method_radio, 1, 1)
         grid0.addWidget(QtWidgets.QLabel(''), 1, 2)
 
+        # Display Annotation
+        self.annotation_label = QtWidgets.QLabel(_("Display Annotation:"))
+        self.annotation_label.setToolTip(
+            _(
+                "This selects if to display text annotation on the plot.\n"
+                "When checked it will display numbers in order for each end\n"
+                "of a travel line."
+            )
+        )
+        self.annotation_cb = FCCheckBox()
+
+        grid0.addWidget(self.annotation_label, 2, 0)
+        grid0.addWidget(self.annotation_cb, 2, 1)
+        grid0.addWidget(QtWidgets.QLabel(''), 2, 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 <b>GCode</b> \n"
             "circle and arc shapes linear approximation.")
         )
-        grid0.addWidget(self.steps_per_circle_label, 2, 0)
+        grid0.addWidget(self.steps_per_circle_label, 3, 0)
         self.steps_per_circle_entry = IntEntry()
-        grid0.addWidget(self.steps_per_circle_entry, 2, 1)
+        grid0.addWidget(self.steps_per_circle_entry, 3, 1)
 
         # Tool dia for plot
         tdlabel = QtWidgets.QLabel(_('Tool dia:'))
@@ -5459,9 +5474,9 @@ class CNCJobGenPrefGroupUI(OptionsGroupUI):
             _("Diameter of the tool to be\n"
             "rendered in the plot.")
         )
-        grid0.addWidget(tdlabel, 3, 0)
+        grid0.addWidget(tdlabel, 4, 0)
         self.tooldia_entry = LengthEntry()
-        grid0.addWidget(self.tooldia_entry, 3, 1)
+        grid0.addWidget(self.tooldia_entry,4, 1)
 
         # Number of decimals to use in GCODE coordinates
         cdeclabel = QtWidgets.QLabel(_('Coords dec.:'))
@@ -5469,9 +5484,9 @@ class CNCJobGenPrefGroupUI(OptionsGroupUI):
             _("The number of decimals to be used for \n"
             "the X, Y, Z coordinates in CNC code (GCODE, etc.)")
         )
-        grid0.addWidget(cdeclabel, 4, 0)
+        grid0.addWidget(cdeclabel, 5, 0)
         self.coords_dec_entry = IntEntry()
-        grid0.addWidget(self.coords_dec_entry, 4, 1)
+        grid0.addWidget(self.coords_dec_entry, 5, 1)
 
         # Number of decimals to use in GCODE feedrate
         frdeclabel = QtWidgets.QLabel(_('Feedrate dec.:'))
@@ -5479,9 +5494,9 @@ class CNCJobGenPrefGroupUI(OptionsGroupUI):
             _("The number of decimals to be used for \n"
             "the Feedrate parameter in CNC code (GCODE, etc.)")
         )
-        grid0.addWidget(frdeclabel, 5, 0)
+        grid0.addWidget(frdeclabel, 6, 0)
         self.fr_dec_entry = IntEntry()
-        grid0.addWidget(self.fr_dec_entry, 5, 1)
+        grid0.addWidget(self.fr_dec_entry, 6, 1)
 
         self.layout.addStretch()
 

+ 16 - 3
flatcamGUI/ObjectUI.py

@@ -1366,6 +1366,16 @@ class CNCObjectUI(ObjectUI):
             {"label": "Cut", "value": "cut"}
         ], stretch=False)
 
+        self.annotation_label = QtWidgets.QLabel(_("<b>Display Annotation:</b>"))
+        self.annotation_label.setToolTip(
+            _(
+                "This selects if to display text annotation on the plot.\n"
+                "When checked it will display numbers in order for each end\n"
+                "of a travel line."
+            )
+        )
+        self.annotation_cb = FCCheckBox()
+
         # ## Object name
         self.name_hlay = QtWidgets.QHBoxLayout()
         self.custom_box.addLayout(self.name_hlay)
@@ -1399,9 +1409,12 @@ class CNCObjectUI(ObjectUI):
         f_lay.addWidget(self.cncplot_method_label, 0, 0)
         f_lay.addWidget(self.cncplot_method_combo, 0, 1)
         f_lay.addWidget(QtWidgets.QLabel(''), 0, 2)
-        f_lay.addWidget(self.t_distance_label, 1, 0)
-        f_lay.addWidget(self.t_distance_entry, 1, 1)
-        f_lay.addWidget(self.units_label, 1, 2)
+        f_lay.addWidget(self.annotation_label, 1, 0)
+        f_lay.addWidget(self.annotation_cb, 1, 1)
+        f_lay.addWidget(QtWidgets.QLabel(''), 1, 2)
+        f_lay.addWidget(self.t_distance_label, 2, 0)
+        f_lay.addWidget(self.t_distance_entry, 2, 1)
+        f_lay.addWidget(self.units_label, 2, 2)
 
         self.t_distance_label.hide()
         self.t_distance_entry.setVisible(False)

+ 1 - 1
flatcamGUI/PlotCanvas.py

@@ -74,7 +74,7 @@ class PlotCanvas(QtCore.QObject):
         self.text_collection = self.new_text_collection()
 
         # TODO: Should be setting to show/hide CNC job annotations (global or per object)
-        self.text_collection.enabled = False
+        self.text_collection.enabled = True
 
     # draw a rectangle made out of 4 lines on the canvas to serve as a hint for the work area
     # all CNC have a limited workspace