Преглед изворни кода

- fixed an issue that caused the impossibility to load a GCode file that contained the % symbol even when was loaded in a regular way from the File menu
- re-added the CNC tool diameter entry for the CNCjob object in Selected tab.FCSpinner
- since the CNCjob geometry creation is only useful for graphical purposes and have no impact on the GCode creation I have removed the cascaded union on the GCode geometry therefore speeding up the Gcode display by many factors (perhaps hundreds of times faster)

Marius Stanciu пре 6 година
родитељ
комит
d43ec01cdd
5 измењених фајлова са 51 додато и 36 уклоњено
  1. 6 4
      FlatCAMApp.py
  2. 9 2
      FlatCAMObj.py
  3. 3 0
      README.md
  4. 13 4
      camlib.py
  5. 20 26
      flatcamGUI/ObjectUI.py

+ 6 - 4
FlatCAMApp.py

@@ -8909,7 +8909,7 @@ class App(QtCore.QObject):
         else:
             for filename in filenames:
                 if filename != '':
-                    self.worker_task.emit({'fcn': self.open_gcode, 'params': [filename]})
+                    self.worker_task.emit({'fcn': self.open_gcode, 'params': [filename, None, True]})
 
     def on_file_openproject(self, checked=None):
         """
@@ -10803,7 +10803,7 @@ class App(QtCore.QObject):
             self.inform.emit('[success] %s: %s' %
                              (_("Opened"), filename))
 
-    def open_gcode(self, filename, outname=None, plot=True):
+    def open_gcode(self, filename, outname=None, force_parsing=None, plot=True):
         """
         Opens a G-gcode file, parses it and creates a new object for
         it in the program. Thread-safe.
@@ -10824,6 +10824,7 @@ class App(QtCore.QObject):
             assert isinstance(app_obj_, App), \
                 "Initializer expected App, got %s" % type(app_obj_)
 
+            app_obj_.inform.emit('%s...' % _("Reading GCode file"))
             try:
                 f = open(filename)
                 gcode = f.read()
@@ -10835,7 +10836,7 @@ class App(QtCore.QObject):
 
             job_obj.gcode = gcode
 
-            ret = job_obj.gcode_parse()
+            ret = job_obj.gcode_parse(force_parsing=force_parsing)
             if ret == "fail":
                 self.inform.emit('[ERROR_NOTCL] %s' %
                                  _("This is not GCODE"))
@@ -10852,7 +10853,8 @@ class App(QtCore.QObject):
             ret = self.new_object("cncjob", name, obj_init, autoselected=False, plot=plot)
             if ret == 'fail':
                 self.inform.emit('[ERROR_NOTCL] %s' %
-                                 _("Failed to create CNCJob Object. Probable not a GCode file.\n "
+                                 _("Failed to create CNCJob Object. Probable not a GCode file. "
+                                   "Try to load it from File menu.\n "
                                    "Attempting to create a FlatCAM CNCJob Object from "
                                    "G-Code file failed during processing"))
                 return "fail"

+ 9 - 2
FlatCAMObj.py

@@ -5872,7 +5872,7 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
 
         self.form_fields.update({
             "plot": self.ui.plot_cb,
-            # "tooldia": self.ui.tooldia_entry,
+            "tooldia": self.ui.tooldia_entry,
             "append": self.ui.append_text,
             "prepend": self.ui.prepend_text,
             "toolchange_macro": self.ui.toolchange_text,
@@ -5907,6 +5907,13 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
         except AttributeError:
             pass
 
+        if self.multitool is False:
+            self.ui.tooldia_entry.show()
+            self.ui.updateplot_button.show()
+        else:
+            self.ui.tooldia_entry.hide()
+            self.ui.updateplot_button.hide()
+
         # 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"])
 
@@ -5965,7 +5972,7 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
         and plots the object.
         """
         self.read_form()
-        self.plot()
+        self.on_plot_kind_change()
 
     def on_plot_kind_change(self):
         kind = self.ui.cncplot_method_combo.get_value()

+ 3 - 0
README.md

@@ -18,6 +18,9 @@ CAD program, and create G-Code for Isolation routing.
 - updated the translation files (~ 89% translation level)
 - changed the splash screen as it seems that FlatCAM beta will never be more than beta
 - changed some of the signals from returnPressed to editingFinished due of now using the SpinBoxes
+- fixed an issue that caused the impossibility to load a GCode file that contained the % symbol even when was loaded in a regular way from the File menu
+- re-added the CNC tool diameter entry for the CNCjob object in Selected tab.FCSpinner
+- since the CNCjob geometry creation is only useful for graphical purposes and have no impact on the GCode creation I have removed the cascaded union on the GCode geometry therefore speeding up the Gcode display by many factors (perhaps hundreds of times faster)
 
 13.10.2019
 

+ 13 - 4
camlib.py

@@ -3937,7 +3937,7 @@ class CNCjob(Geometry):
                 match = re.search(r'^\s*([A-Z])\s*([\+\-\.\d\s]+)', gline)
         return command
 
-    def gcode_parse(self):
+    def gcode_parse(self, force_parsing=None):
         """
         G-Code parser (from self.gcode). Generates dictionary with
         single-segment LineString's and "kind" indicating cut or travel,
@@ -3968,10 +3968,12 @@ class CNCjob(Geometry):
         path = [pos_xy]
         # path = [(0, 0)]
 
+        self.app.inform.emit('%s: %d' % (_("Parsing GCode file. Number of lines"), len(self.gcode.splitlines())))
         # Process every instruction
         for line in StringIO(self.gcode):
-            if '%MO' in line or '%' in line or 'MOIN' in line or 'MOMM' in line:
-                return "fail"
+            if force_parsing is False or force_parsing is None:
+                if '%MO' in line or '%' in line or 'MOIN' in line or 'MOMM' in line:
+                    return "fail"
 
             gobj = self.codes_split(line)
 
@@ -4056,6 +4058,7 @@ class CNCjob(Geometry):
             for code in gobj:
                 current[code] = gobj[code]
 
+        self.app.inform.emit('%s...' % _("Creating Geometry from the parsed GCode file. "))
         # There might not be a change in height at the
         # end, therefore, see here too if there is
         # a final path.
@@ -4318,8 +4321,14 @@ class CNCjob(Geometry):
                 pass
 
     def create_geometry(self):
+        self.app.inform.emit('%s: %s' % (_("Unifying Geometry from parsed Geometry segments"),
+                                         str(len(self.gcode_parsed))))
         # TODO: This takes forever. Too much data?
-        self.solid_geometry = cascaded_union([geo['geom'] for geo in self.gcode_parsed])
+        # self.solid_geometry = cascaded_union([geo['geom'] for geo in self.gcode_parsed])
+
+        # This is much faster but not so nice to look at as you can see different segments of the geometry
+        self.solid_geometry = [geo['geom'] for geo in self.gcode_parsed]
+
         return self.solid_geometry
 
     # code snippet added by Lei Zheng in a rejected pull request on FlatCAM https://bitbucket.org/realthunder/

+ 20 - 26
flatcamGUI/ObjectUI.py

@@ -78,10 +78,10 @@ class ObjectUI(QtWidgets.QWidget):
         # ## Common to all objects ##
         # ###########################
         if common is True:
-            grid0 = QtWidgets.QGridLayout()
-            layout.addLayout(grid0)
-            grid0.setColumnStretch(0, 0)
-            grid0.setColumnStretch(1, 1)
+            self.common_grid = QtWidgets.QGridLayout()
+            layout.addLayout(self.common_grid)
+            self.common_grid.setColumnStretch(0, 0)
+            self.common_grid.setColumnStretch(1, 1)
 
             # ### Scale ####
             self.scale_label = QtWidgets.QLabel('<b>%s</b>' % _('Scale'))
@@ -89,7 +89,7 @@ class ObjectUI(QtWidgets.QWidget):
                 _("Change the size of the object.")
             )
 
-            grid0.addWidget(self.scale_label, 0, 0, 1, 3)
+            self.common_grid.addWidget(self.scale_label, 0, 0, 1, 3)
 
             # Factor
             faclabel = QtWidgets.QLabel('%s:' % _('Factor'))
@@ -111,9 +111,9 @@ class ObjectUI(QtWidgets.QWidget):
             )
             self.scale_button.setMinimumWidth(70)
 
-            grid0.addWidget(faclabel, 1, 0)
-            grid0.addWidget(self.scale_entry, 1, 1)
-            grid0.addWidget(self.scale_button, 1, 2)
+            self.common_grid.addWidget(faclabel, 1, 0)
+            self.common_grid.addWidget(self.scale_entry, 1, 1)
+            self.common_grid.addWidget(self.scale_button, 1, 2)
 
             # ### Offset ####
             self.offset_label = QtWidgets.QLabel('<b>%s</b>' % _('Offset'))
@@ -121,7 +121,7 @@ class ObjectUI(QtWidgets.QWidget):
                 _("Change the position of this object.")
             )
 
-            grid0.addWidget(self.offset_label, 2, 0, 1, 3)
+            self.common_grid.addWidget(self.offset_label, 2, 0, 1, 3)
 
             self.offset_vectorlabel = QtWidgets.QLabel('%s:' % _('Vector'))
             self.offset_vectorlabel.setToolTip(
@@ -137,9 +137,9 @@ class ObjectUI(QtWidgets.QWidget):
             )
             self.offset_button.setMinimumWidth(70)
 
-            grid0.addWidget(self.offset_vectorlabel, 3, 0)
-            grid0.addWidget(self.offsetvector_entry, 3, 1)
-            grid0.addWidget(self.offset_button, 3, 2)
+            self.common_grid.addWidget(self.offset_vectorlabel, 3, 0)
+            self.common_grid.addWidget(self.offsetvector_entry, 3, 1)
+            self.common_grid.addWidget(self.offset_button, 3, 2)
 
         layout.addStretch()
 
@@ -1583,17 +1583,8 @@ class CNCObjectUI(ObjectUI):
         ObjectUI.__init__(self, title=_('CNC Job Object'), icon_file='share/cnc32.png', parent=parent)
         self.decimals = 4
 
-        # Scale and offset ans skew are not available for CNCJob objects.
-        # Hiding from the GUI.
-        for i in range(0, self.scale_grid.count()):
-            self.scale_grid.itemAt(i).widget().hide()
-        self.scale_label.hide()
-        self.scale_button.hide()
-
-        for i in range(0, self.offset_grid.count()):
-            self.offset_grid.itemAt(i).widget().hide()
-        self.offset_label.hide()
-        self.offset_button.hide()
+        for i in range(0, self.common_grid.count()):
+            self.common_grid.itemAt(i).widget().hide()
 
         # ## Plot options
         self.plot_options_label = QtWidgets.QLabel("<b>%s:</b>" % _("Plot Options"))
@@ -1715,9 +1706,6 @@ class CNCObjectUI(ObjectUI):
         self.cnc_tools_table = FCTable()
         self.custom_box.addWidget(self.cnc_tools_table)
 
-        # self.cnc_tools_table.setColumnCount(4)
-        # self.cnc_tools_table.setHorizontalHeaderLabels(['#', 'Dia', 'Plot', ''])
-        # self.cnc_tools_table.setColumnHidden(3, True)
         self.cnc_tools_table.setColumnCount(7)
         self.cnc_tools_table.setColumnWidth(0, 20)
         self.cnc_tools_table.setHorizontalHeaderLabels(['#', _('Dia'), _('Offset'), _('Type'), _('TT'), '',
@@ -1726,6 +1714,12 @@ class CNCObjectUI(ObjectUI):
         # stylesheet = "::section{Background-color:rgb(239,239,245)}"
         # self.cnc_tools_table.horizontalHeader().setStyleSheet(stylesheet)
 
+        self.tooldia_entry = FCDoubleSpinner()
+        self.tooldia_entry.set_range(0, 9999.9999)
+        self.tooldia_entry.set_precision(self.decimals)
+        self.tooldia_entry.setSingleStep(0.1)
+        self.custom_box.addWidget(self.tooldia_entry)
+
         # Update plot button
         self.updateplot_button = QtWidgets.QPushButton(_('Update Plot'))
         self.updateplot_button.setToolTip(