فهرست منبع

- in CNCJob UI worked on the UI for the Autolevelling
- in CNCJob UI finished working on adding test points in Grid mode

Marius Stanciu 5 سال پیش
والد
کامیت
5af8918441
3فایلهای تغییر یافته به همراه117 افزوده شده و 44 حذف شده
  1. 5 0
      CHANGELOG.md
  2. 35 34
      appGUI/ObjectUI.py
  3. 77 10
      appObjects/FlatCAMCNCJob.py

+ 5 - 0
CHANGELOG.md

@@ -7,6 +7,11 @@ CHANGELOG for FlatCAM beta
 
 =================================================
 
+14.08.2020
+
+- in CNCJob UI worked on the UI for the Autolevelling
+- in CNCJob UI finished working on adding test points in Grid mode
+
 13.08.2020
 
 - in CNCJob UI added GUI for an eventual Autolevelling feature 

+ 35 - 34
appGUI/ObjectUI.py

@@ -1919,7 +1919,17 @@ class CNCObjectUI(ObjectUI):
 
         al_title = FCLabel('<b>%s</b>' % _("Test Points Table"))
         al_title.setToolTip(_("Generate GCode that will obtain the height map"))
-        grid0.addWidget(al_title, 0, 0, 1, 2)
+
+        self.show_al_table = FCCheckBox(_("Show"))
+        self.show_al_table.setToolTip(_("Toggle the display of the Test Points table."))
+        self.show_al_table.setChecked(True)
+
+        hor_lay = QtWidgets.QHBoxLayout()
+        hor_lay.addWidget(al_title)
+        hor_lay.addStretch()
+        hor_lay.addWidget(self.show_al_table, alignment=QtCore.Qt.AlignRight)
+
+        grid0.addLayout(hor_lay, 0, 0, 1, 2)
 
         self.al_testpoints_table = FCTable()
         self.al_testpoints_table.setColumnCount(3)
@@ -1928,10 +1938,16 @@ class CNCObjectUI(ObjectUI):
 
         grid0.addWidget(self.al_testpoints_table, 1, 0, 1, 2)
 
+        self.voronoi_cb = FCCheckBox(_("Show Voronoi diagram"))
+        self.voronoi_cb.setToolTip(
+            _("Display Voronoi diagram if there are test points in the table.")
+        )
+        grid0.addWidget(self.voronoi_cb, 3, 0, 1, 2)
+
         separator_line = QtWidgets.QFrame()
         separator_line.setFrameShape(QtWidgets.QFrame.HLine)
         separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
-        grid0.addWidget(separator_line, 2, 0, 1, 2)
+        grid0.addWidget(separator_line, 5, 0, 1, 2)
 
         al_mode_lbl = FCLabel('<b>%s</b>:' % _("Mode"))
         al_mode_lbl.setToolTip(_("Choose a mode for height map generation.\n"
@@ -1943,8 +1959,8 @@ class CNCObjectUI(ObjectUI):
                 {'label': _('Manual'), 'value': 'manual'},
                 {'label': _('Grid'), 'value': 'grid'}
             ])
-        grid0.addWidget(al_mode_lbl, 3, 0)
-        grid0.addWidget(self.al_mode_radio, 3, 1)
+        grid0.addWidget(al_mode_lbl, 7, 0)
+        grid0.addWidget(self.al_mode_radio, 7, 1)
 
         # ## Columns
         self.al_columns_entry = FCSpinner()
@@ -1953,8 +1969,8 @@ class CNCObjectUI(ObjectUI):
         self.al_columns_label.setToolTip(
             _("The number of grid columns.")
         )
-        grid0.addWidget(self.al_columns_label, 5, 0)
-        grid0.addWidget(self.al_columns_entry, 5, 1)
+        grid0.addWidget(self.al_columns_label, 9, 0)
+        grid0.addWidget(self.al_columns_entry, 9, 1)
 
         # ## Rows
         self.al_rows_entry = FCSpinner()
@@ -1963,11 +1979,16 @@ class CNCObjectUI(ObjectUI):
         self.al_rows_label.setToolTip(
             _("The number of gird rows.")
         )
-        grid0.addWidget(self.al_rows_label, 6, 0)
-        grid0.addWidget(self.al_rows_entry, 6, 1)
+        grid0.addWidget(self.al_rows_label, 11, 0)
+        grid0.addWidget(self.al_rows_entry, 11, 1)
 
         self.al_add_button = FCButton(_("Add test points"))
-        grid0.addWidget(self.al_add_button, 8, 0, 1, 2)
+        grid0.addWidget(self.al_add_button, 13, 0, 1, 2)
+
+        separator_line = QtWidgets.QFrame()
+        separator_line.setFrameShape(QtWidgets.QFrame.HLine)
+        separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
+        grid0.addWidget(separator_line, 14, 0, 1, 2)
 
         self.al_controller_label = FCLabel('%s:' % _("Controller"))
         self.al_rows_label.setToolTip(
@@ -1977,25 +1998,19 @@ class CNCObjectUI(ObjectUI):
 
         self.al_controller_combo = FCComboBox()
         self.al_controller_combo.addItems(["MACH", "LinuxCNC"])
-        grid0.addWidget(self.al_controller_label, 9, 0)
-        grid0.addWidget(self.al_controller_combo, 9, 1)
+        grid0.addWidget(self.al_controller_label, 15, 0)
+        grid0.addWidget(self.al_controller_combo, 15, 1)
 
         self.h_gcode_button = FCButton(_("Generate Height Map GCode"))
-        grid0.addWidget(self.h_gcode_button, 10, 0, 1, 2)
-
-        self.voronoi_cb = FCCheckBox(_("Show Voronoi diagram"))
-        self.voronoi_cb.setToolTip(
-            _("Display Voronoi diagram.")
-        )
-        grid0.addWidget(self.voronoi_cb, 12, 0, 1, 2)
+        grid0.addWidget(self.h_gcode_button, 17, 0, 1, 2)
 
         self.import_heights_button = FCButton(_("Import Height Map"))
-        grid0.addWidget(self.import_heights_button, 14, 0, 1, 2)
+        grid0.addWidget(self.import_heights_button, 19, 0, 1, 2)
 
         separator_line = QtWidgets.QFrame()
         separator_line.setFrameShape(QtWidgets.QFrame.HLine)
         separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
-        grid0.addWidget(separator_line, 16, 0, 1, 2)
+        grid0.addWidget(separator_line, 21, 0, 1, 2)
 
         # ####################
         # ## Export G-Code ##
@@ -2167,25 +2182,11 @@ class CNCObjectUI(ObjectUI):
 
         # Signals
         self.sal_cb.stateChanged.connect(lambda state: self.al_frame.show() if state else self.al_frame.hide())
-        self.al_mode_radio.activated_custom.connect(self.on_mode_radio)
 
         # Set initial UI
         self.al_frame.hide()
-        self.al_mode_radio.set_value('grid')
         # self.on_mode_radio(val='grid')
 
-    def on_mode_radio(self, val):
-        if val == "manual":
-            self.al_rows_entry.setDisabled(True)
-            self.al_rows_label.setDisabled(True)
-            self.al_columns_entry.setDisabled(True)
-            self.al_columns_label.setDisabled(True)
-        else:
-            self.al_rows_entry.setDisabled(False)
-            self.al_rows_label.setDisabled(False)
-            self.al_columns_entry.setDisabled(False)
-            self.al_columns_label.setDisabled(False)
-
 
 class ScriptObjectUI(ObjectUI):
     """

+ 77 - 10
appObjects/FlatCAMCNCJob.py

@@ -20,6 +20,7 @@ from appObjects.FlatCAMObj import *
 from camlib import CNCjob
 
 from shapely.ops import unary_union
+from shapely.geometry import Point
 try:
     from shapely.ops import voronoi_diagram
 except Exception:
@@ -404,12 +405,29 @@ class CNCJobObject(FlatCAMObj, CNCjob):
             coords_item.setFlags(QtCore.Qt.ItemIsEnabled)
             height_item.setFlags(QtCore.Qt.ItemIsEnabled)
 
+            self.ui.al_testpoints_table.setItem(row_no, 0, t_id)  # Tool name/id
+            self.ui.al_testpoints_table.setItem(row_no, 1, coords_item)  # X-Y coords
+            self.ui.al_testpoints_table.setItem(row_no, 2, height_item)  # Determined Height
+
         self.ui.al_testpoints_table.resizeColumnsToContents()
         self.ui.al_testpoints_table.resizeRowsToContents()
 
+        h_header = self.ui.al_testpoints_table.horizontalHeader()
+        h_header.setMinimumSectionSize(10)
+        h_header.setDefaultSectionSize(70)
+        h_header.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
+        h_header.resizeSection(0, 20)
+        h_header.setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
+        h_header.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
+
         self.ui.al_testpoints_table.setMinimumHeight(self.ui.al_testpoints_table.getHeight())
         self.ui.al_testpoints_table.setMaximumHeight(self.ui.al_testpoints_table.getHeight())
 
+        if self.ui.al_testpoints_table.model().rowCount():
+            self.ui.voronoi_cb.setDisabled(False)
+        else:
+            self.ui.voronoi_cb.setDisabled(True)
+
     def set_ui(self, ui):
         FlatCAMObj.set_ui(self, ui)
 
@@ -504,6 +522,7 @@ class CNCJobObject(FlatCAMObj, CNCjob):
         self.ui.export_gcode_button.clicked.connect(self.on_exportgcode_button_click)
         self.ui.review_gcode_button.clicked.connect(self.on_edit_code_click)
         self.ui.editor_button.clicked.connect(lambda: self.app.object2editor())
+        self.ui.al_mode_radio.activated_custom.connect(self.on_mode_radio)
 
         # self.ui.tc_variable_combo.currentIndexChanged[str].connect(self.on_cnc_custom_parameters)
 
@@ -514,6 +533,8 @@ class CNCJobObject(FlatCAMObj, CNCjob):
         gc = self.export_gcode(preamble=preamble, postamble=postamble, to_file=True)
         self.source_file = gc.getvalue()
 
+        self.ui.al_mode_radio.set_value('grid')
+
     # def on_cnc_custom_parameters(self, signal_text):
     #     if signal_text == 'Parameters':
     #         return
@@ -528,6 +549,7 @@ class CNCJobObject(FlatCAMObj, CNCjob):
         self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
 
         self.ui.al_add_button.clicked.connect(self.on_add_al_testpoints)
+        self.ui.show_al_table.stateChanged.connect(self.on_show_al_table)
 
     def ui_disconnect(self):
         for row in range(self.ui.cnc_tools_table.rowCount()):
@@ -552,13 +574,24 @@ class CNCJobObject(FlatCAMObj, CNCjob):
         except (TypeError, AttributeError):
             pass
 
+        try:
+            self.ui.show_al_table.stateChanged.disconnect()
+        except (TypeError, AttributeError):
+            pass
+
     def on_add_al_testpoints(self):
         # create the solid_geo
-        solid_geo = [geo['geom'] for geo in self.gcode_parsed]
+
+        solid_geo = [geo['geom'] for geo in self.gcode_parsed if geo['kind'][0] == 'C']
         solid_geo = unary_union(solid_geo)
 
+        # reset al table
+        self.ui.al_testpoints_table.setRowCount(0)
+
+        # reset the al dict
+        self.al_geometry_dict.clear()
+
         xmin, ymin, xmax, ymax = solid_geo.bounds
-        print(solid_geo.bounds)
 
         if self.ui.al_mode_radio.get_value() == 'grid':
             width = abs(xmax - xmin)
@@ -568,23 +601,57 @@ class CNCJobObject(FlatCAMObj, CNCjob):
 
             dx = width / (cols + 1)
             dy = height / (rows + 1)
-            print(width, height, cols, rows, dx, dy)
+
             points = []
-            new_x = xmin
-            for x in range(cols):
-                new_x += dx
-                new_y = ymin
-                for x in range(rows):
-                    new_y += dy
+            new_y = ymin
+            for x in range(rows):
+                new_y += dy
+                new_x = xmin
+                for x in range(cols):
+                    new_x += dx
                     points.append((new_x, new_y))
 
-            print(points)
+            pt_id = 0
+            for point in points:
+                pt_id += 1
+                new_dict = {
+                    'point': Point(point),
+                    'geo': None,
+                    'height': 0.0
+                }
+                self.al_geometry_dict[pt_id] = deepcopy(new_dict)
+
         # self.calculate_voronoi_diagram()
+
         self.build_al_table()
 
     # def calculate_voronoi_diagram(self):
     #     return voronoi_diagram()
 
+    def on_show_al_table(self, state):
+        self.ui.al_testpoints_table.show() if state else self.ui.al_testpoints_table.hide()
+
+    def on_mode_radio(self, val):
+        # reset al table
+        self.ui.al_testpoints_table.setRowCount(0)
+
+        # reset the al dict
+        self.al_geometry_dict.clear()
+
+        # build AL table
+        self.build_al_table()
+
+        if val == "manual":
+            self.ui.al_rows_entry.setDisabled(True)
+            self.ui.al_rows_label.setDisabled(True)
+            self.ui.al_columns_entry.setDisabled(True)
+            self.ui.al_columns_label.setDisabled(True)
+        else:
+            self.ui.al_rows_entry.setDisabled(False)
+            self.ui.al_rows_label.setDisabled(False)
+            self.ui.al_columns_entry.setDisabled(False)
+            self.ui.al_columns_label.setDisabled(False)
+
     def on_updateplot_button_click(self, *args):
         """
         Callback for the "Updata Plot" button. Reads the form for updates