Ver código fonte

- now, Excellon and Gerber edited objects will have the source_code updated and ready to be saved
- the edited Gerber (or Excellon) object now is kept in the app after editing and the edited object is a new object
- added a message to the splash screen

Marius Stanciu 6 anos atrás
pai
commit
1a8784f5ab
5 arquivos alterados com 93 adições e 59 exclusões
  1. 9 10
      FlatCAM.py
  2. 28 20
      FlatCAMApp.py
  3. 3 0
      README.md
  4. 4 3
      flatcamEditors/FlatCAMExcEditor.py
  5. 49 26
      flatcamEditors/FlatCAMGrbEditor.py

+ 9 - 10
FlatCAM.py

@@ -1,7 +1,7 @@
 import sys
 import sys
 import os
 import os
 
 
-from PyQt5 import QtWidgets
+from PyQt5 import QtWidgets, QtGui
 from PyQt5.QtCore import QSettings, Qt
 from PyQt5.QtCore import QSettings, Qt
 from FlatCAMApp import App
 from FlatCAMApp import App
 from flatcamGUI import VisPyPatches
 from flatcamGUI import VisPyPatches
@@ -60,18 +60,17 @@ if __name__ == '__main__':
 
 
     # Create and display the splash screen
     # Create and display the splash screen
     # from here: https://eli.thegreenplace.net/2009/05/09/creating-splash-screens-in-pyqt
     # from here: https://eli.thegreenplace.net/2009/05/09/creating-splash-screens-in-pyqt
-    # splash_pix = QtWidgets.QPixmap('splash_loading.png')
-    # splash = QtWidgets.QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint)
+    splash_pix = QtGui.QPixmap('share/flatcam_icon256.png')
+    splash = QtWidgets.QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint)
     # splash.setMask(splash_pix.mask())
     # splash.setMask(splash_pix.mask())
-    # splash.show()
-    # app.processEvents()
-    #
-    # # Simulate something that takes time
-    # while True:
-    #     pass
+    splash.show()
+    app.processEvents()
+    splash.showMessage("FlatCAM is initializing ...",
+                       alignment=Qt.AlignBottom | Qt.AlignLeft,
+                       color=QtGui.QColor("gray"))
 
 
     fc = App()
     fc = App()
+    splash.finish(fc.ui)
     fc.ui.show()
     fc.ui.show()
-    # splash.finish(fc)
 
 
     sys.exit(app.exec_())
     sys.exit(app.exec_())

+ 28 - 20
FlatCAMApp.py

@@ -8530,7 +8530,7 @@ class App(QtCore.QObject):
                                "Most likely another app is holding the file open and not accessible."))
                                "Most likely another app is holding the file open and not accessible."))
             return 'fail'
             return 'fail'
 
 
-    def export_excellon(self, obj_name, filename, use_thread=True):
+    def export_excellon(self, obj_name, filename, local_use=None, use_thread=True):
         """
         """
         Exports a Excellon Object to an Excellon file.
         Exports a Excellon Object to an Excellon file.
 
 
@@ -8551,11 +8551,14 @@ class App(QtCore.QObject):
                                                )
                                                )
         units = ''
         units = ''
 
 
-        try:
-            obj = self.collection.get_by_name(str(obj_name))
-        except:
-            # TODO: The return behavior has not been established... should raise exception?
-            return "Could not retrieve object: %s" % obj_name
+        if local_use is None:
+            try:
+                obj = self.collection.get_by_name(str(obj_name))
+            except:
+                # TODO: The return behavior has not been established... should raise exception?
+                return "Could not retrieve object: %s" % obj_name
+        else:
+            obj = local_use
 
 
         # updated units
         # updated units
         eunits = self.defaults["excellon_exp_units"]
         eunits = self.defaults["excellon_exp_units"]
@@ -8635,20 +8638,23 @@ class App(QtCore.QObject):
                 exported_excellon += excellon_code
                 exported_excellon += excellon_code
                 exported_excellon += footer
                 exported_excellon += footer
 
 
-                try:
-                    with open(filename, 'w') as fp:
-                        fp.write(exported_excellon)
-                except PermissionError:
-                    self.inform.emit('[WARNING] %s' %
-                                     _("Permission denied, saving not possible.\n"
-                                       "Most likely another app is holding the file open and not accessible."))
-                    return 'fail'
+                if local_use is None:
+                    try:
+                        with open(filename, 'w') as fp:
+                            fp.write(exported_excellon)
+                    except PermissionError:
+                        self.inform.emit('[WARNING] %s' %
+                                         _("Permission denied, saving not possible.\n"
+                                           "Most likely another app is holding the file open and not accessible."))
+                        return 'fail'
 
 
-                if self.defaults["global_open_style"] is False:
-                    self.file_opened.emit("Excellon", filename)
-                self.file_saved.emit("Excellon", filename)
-                self.inform.emit('[success] %s: %s' %
-                                 (_("Excellon file exported to"), filename))
+                    if self.defaults["global_open_style"] is False:
+                        self.file_opened.emit("Excellon", filename)
+                    self.file_saved.emit("Excellon", filename)
+                    self.inform.emit('[success] %s: %s' %
+                                     (_("Excellon file exported to"), filename))
+                else:
+                    return exported_excellon
             except Exception as e:
             except Exception as e:
                 log.debug("App.export_excellon.make_excellon() --> %s" % str(e))
                 log.debug("App.export_excellon.make_excellon() --> %s" % str(e))
                 return 'fail'
                 return 'fail'
@@ -8670,7 +8676,9 @@ class App(QtCore.QObject):
             if ret == 'fail':
             if ret == 'fail':
                 self.inform.emit('[ERROR_NOTCL] %s' %
                 self.inform.emit('[ERROR_NOTCL] %s' %
                                  _('Could not export Excellon file.'))
                                  _('Could not export Excellon file.'))
-                return
+                return 'fail'
+            if local_use is not None:
+                return ret
 
 
     def export_gerber(self, obj_name, filename, local_use=None, use_thread=True):
     def export_gerber(self, obj_name, filename, local_use=None, use_thread=True):
         """
         """

+ 3 - 0
README.md

@@ -14,6 +14,9 @@ CAD program, and create G-Code for Isolation routing.
 - small changes in the TclCommands: MillDrills, MillSlots, DrillCNCJob: the new parameter for tolerance is now named: tooldia
 - small changes in the TclCommands: MillDrills, MillSlots, DrillCNCJob: the new parameter for tolerance is now named: tooldia
 - cleaned up the 'About FlatCAM' window, started to give credits for the translation team
 - cleaned up the 'About FlatCAM' window, started to give credits for the translation team
 - started to add an application splash screen
 - started to add an application splash screen
+- now, Excellon and Gerber edited objects will have the source_code updated and ready to be saved
+- the edited Gerber (or Excellon) object now is kept in the app after editing and the edited object is a new object
+- added a message to the splash screen
 
 
 11.09.2019
 11.09.2019
 
 

+ 4 - 3
flatcamEditors/FlatCAMExcEditor.py

@@ -3125,7 +3125,6 @@ class FlatCAMExcEditor(QtCore.QObject):
         self.app.worker_task.emit({'fcn': self.new_edited_excellon,
         self.app.worker_task.emit({'fcn': self.new_edited_excellon,
                                    'params': [self.edited_obj_name]})
                                    'params': [self.edited_obj_name]})
 
 
-
         self.new_tool_offset = self.exc_obj.tool_offset
         self.new_tool_offset = self.exc_obj.tool_offset
 
 
         # reset the tool table
         # reset the tool table
@@ -3134,8 +3133,8 @@ class FlatCAMExcEditor(QtCore.QObject):
         self.last_tool_selected = None
         self.last_tool_selected = None
 
 
         # delete the edited Excellon object which will be replaced by a new one having the edited content of the first
         # delete the edited Excellon object which will be replaced by a new one having the edited content of the first
-        self.app.collection.set_active(self.exc_obj.options['name'])
-        self.app.collection.delete_active()
+        # self.app.collection.set_active(self.exc_obj.options['name'])
+        # self.app.collection.delete_active()
 
 
         # restore GUI to the Selected TAB
         # restore GUI to the Selected TAB
         # Remove anything else in the GUI
         # Remove anything else in the GUI
@@ -3193,6 +3192,8 @@ class FlatCAMExcEditor(QtCore.QObject):
                 app_obj.inform.emit(msg)
                 app_obj.inform.emit(msg)
                 raise
                 raise
                 # raise
                 # raise
+            excellon_obj.source_file = self.app.export_excellon(obj_name=outname, filename=None,
+                                                                local_use=excellon_obj, use_thread=False)
 
 
         with self.app.proc_container.new(_("Creating Excellon.")):
         with self.app.proc_container.new(_("Creating Excellon.")):
 
 

+ 49 - 26
flatcamEditors/FlatCAMGrbEditor.py

@@ -3713,7 +3713,36 @@ class FlatCAMGrbEditor(QtCore.QObject):
         for apid in self.gerber_obj.apertures:
         for apid in self.gerber_obj.apertures:
             temp_elem = []
             temp_elem = []
             if 'geometry' in self.gerber_obj.apertures[apid]:
             if 'geometry' in self.gerber_obj.apertures[apid]:
+                # for elem in self.gerber_obj.apertures[apid]['geometry']:
+                #     if 'solid' in elem:
+                #         solid_geo = elem['solid']
+                #         for clear_geo in global_clear_geo:
+                #             # Make sure that the clear_geo is within the solid_geo otherwise we loose
+                #             # the solid_geometry. We want for clear_geometry just to cut into solid_geometry not to
+                #             # delete it
+                #             if clear_geo.within(solid_geo):
+                #                 solid_geo = solid_geo.difference(clear_geo)
+                #         try:
+                #             for poly in solid_geo:
+                #                 new_elem = dict()
+                #
+                #                 new_elem['solid'] = poly
+                #                 if 'clear' in elem:
+                #                     new_elem['clear'] = poly
+                #                 if 'follow' in elem:
+                #                     new_elem['follow'] = poly
+                #                 temp_elem.append(deepcopy(new_elem))
+                #         except TypeError:
+                #             new_elem = dict()
+                #             new_elem['solid'] = solid_geo
+                #             if 'clear' in elem:
+                #                 new_elem['clear'] = solid_geo
+                #             if 'follow' in elem:
+                #                 new_elem['follow'] = solid_geo
+                #             temp_elem.append(deepcopy(new_elem))
                 for elem in self.gerber_obj.apertures[apid]['geometry']:
                 for elem in self.gerber_obj.apertures[apid]['geometry']:
+                    new_elem = dict()
+
                     if 'solid' in elem:
                     if 'solid' in elem:
                         solid_geo = elem['solid']
                         solid_geo = elem['solid']
                         for clear_geo in global_clear_geo:
                         for clear_geo in global_clear_geo:
@@ -3722,24 +3751,14 @@ class FlatCAMGrbEditor(QtCore.QObject):
                             # delete it
                             # delete it
                             if clear_geo.within(solid_geo):
                             if clear_geo.within(solid_geo):
                                 solid_geo = solid_geo.difference(clear_geo)
                                 solid_geo = solid_geo.difference(clear_geo)
-                        try:
-                            for poly in solid_geo:
-                                new_elem = dict()
-
-                                new_elem['solid'] = poly
-                                if 'clear' in elem:
-                                    new_elem['clear'] = poly
-                                if 'follow' in elem:
-                                    new_elem['follow'] = poly
-                                temp_elem.append(deepcopy(new_elem))
-                        except TypeError:
-                            new_elem = dict()
-                            new_elem['solid'] = solid_geo
-                            if 'clear' in elem:
-                                new_elem['clear'] = solid_geo
-                            if 'follow' in elem:
-                                new_elem['follow'] = solid_geo
-                            temp_elem.append(deepcopy(new_elem))
+
+                        new_elem['solid'] = solid_geo
+                    if 'clear' in elem:
+                        new_elem['clear'] = elem['clear']
+                    if 'follow' in elem:
+                        new_elem['follow'] = elem['follow']
+                    temp_elem.append(deepcopy(new_elem))
+
             self.gerber_obj.apertures[apid]['geometry'] = deepcopy(temp_elem)
             self.gerber_obj.apertures[apid]['geometry'] = deepcopy(temp_elem)
         log.warning("Polygon difference done for %d apertures." % len(self.gerber_obj.apertures))
         log.warning("Polygon difference done for %d apertures." % len(self.gerber_obj.apertures))
 
 
@@ -3876,19 +3895,19 @@ class FlatCAMGrbEditor(QtCore.QObject):
                         grb_obj.apertures[storage_apid][k] = []
                         grb_obj.apertures[storage_apid][k] = []
                         for geo_el in val:
                         for geo_el in val:
                             geometric_data = geo_el.geo
                             geometric_data = geo_el.geo
-
                             new_geo_el = dict()
                             new_geo_el = dict()
                             if 'solid' in geometric_data:
                             if 'solid' in geometric_data:
                                 new_geo_el['solid'] = geometric_data['solid']
                                 new_geo_el['solid'] = geometric_data['solid']
                                 poly_buffer.append(deepcopy(new_geo_el['solid']))
                                 poly_buffer.append(deepcopy(new_geo_el['solid']))
 
 
                             if 'follow' in geometric_data:
                             if 'follow' in geometric_data:
-                                if isinstance(geometric_data['follow'], Polygon):
-                                    buff_val = -(int(storage_apid) / 2)
-                                    geo_f = (geometric_data['follow'].buffer(buff_val)).exterior
-                                    new_geo_el['follow'] = geo_f
-                                else:
-                                    new_geo_el['follow'] = geometric_data['follow']
+                                # if isinstance(geometric_data['follow'], Polygon):
+                                #     buff_val = -(int(storage_val['size']) / 2)
+                                #     geo_f = (geometric_data['follow'].buffer(buff_val)).exterior
+                                #     new_geo_el['follow'] = geo_f
+                                # else:
+                                #     new_geo_el['follow'] = geometric_data['follow']
+                                new_geo_el['follow'] = geometric_data['follow']
                                 follow_buffer.append(deepcopy(new_geo_el['follow']))
                                 follow_buffer.append(deepcopy(new_geo_el['follow']))
                             else:
                             else:
                                 if 'solid' in geometric_data:
                                 if 'solid' in geometric_data:
@@ -3910,6 +3929,9 @@ class FlatCAMGrbEditor(QtCore.QObject):
             new_poly = new_poly.buffer(0.00000001)
             new_poly = new_poly.buffer(0.00000001)
             new_poly = new_poly.buffer(-0.00000001)
             new_poly = new_poly.buffer(-0.00000001)
 
 
+            # for ad in grb_obj.apertures:
+            #     print(ad, grb_obj.apertures[ad])
+
             try:
             try:
                 __ = iter(new_poly)
                 __ = iter(new_poly)
             except TypeError:
             except TypeError:
@@ -3924,7 +3946,6 @@ class FlatCAMGrbEditor(QtCore.QObject):
                 else:
                 else:
                     grb_obj.options[k] = deepcopy(v)
                     grb_obj.options[k] = deepcopy(v)
 
 
-            grb_obj.source_file = []
             grb_obj.multigeo = False
             grb_obj.multigeo = False
             grb_obj.follow = False
             grb_obj.follow = False
             grb_obj.gerber_units = app_obj.defaults['units']
             grb_obj.gerber_units = app_obj.defaults['units']
@@ -3940,6 +3961,8 @@ class FlatCAMGrbEditor(QtCore.QObject):
                 msg += traceback.format_exc()
                 msg += traceback.format_exc()
                 app_obj.inform.emit(msg)
                 app_obj.inform.emit(msg)
                 raise
                 raise
+            grb_obj.source_file = self.app.export_gerber(obj_name=out_name, filename=None,
+                                                         local_use=grb_obj, use_thread=False)
 
 
         with self.app.proc_container.new(_("Creating Gerber.")):
         with self.app.proc_container.new(_("Creating Gerber.")):
             try:
             try: