浏览代码

- replaced the testing if instance of FlatCAMObj with testing the obj.kind attribute
- removed the import of the whole FlatCAMApp file only for the usage of GracefulException
- remove the import of FlatCAMApp and used alternate ways
- optimized the imports in some files
- moved the Bookmarksmanager and ToolDB classes into their own files
- solved some bugs that were not so visible in the Editors and HPGL parser
- split the FlatCAMObj file into multiple files located in the flatcamObjects folder and renamed the contained classes with names more suggestive
- updated the Google Translation for the German language

Marius Stanciu 5 年之前
父节点
当前提交
9f13b47077
共有 50 个文件被更改,包括 9853 次插入9671 次删除
  1. 33 31
      CHANGELOG.md
  2. 93 89
      FlatCAMApp.py
  3. 0 8245
      FlatCAMObj.py
  4. 20 14
      ObjectCollection.py
  5. 1 1
      camlib.py
  6. 2 2
      flatcamEditors/FlatCAMExcEditor.py
  7. 4 4
      flatcamEditors/FlatCAMGeoEditor.py
  8. 3 3
      flatcamEditors/FlatCAMGrbEditor.py
  9. 1220 0
      flatcamObjects/FlatCAMCNCJob.py
  10. 314 0
      flatcamObjects/FlatCAMDocument.py
  11. 1622 0
      flatcamObjects/FlatCAMExcellon.py
  12. 2622 0
      flatcamObjects/FlatCAMGeometry.py
  13. 1870 0
      flatcamObjects/FlatCAMGerber.py
  14. 505 0
      flatcamObjects/FlatCAMObj.py
  15. 231 0
      flatcamObjects/FlatCAMScript.py
  16. 0 0
      flatcamObjects/__init__.py
  17. 3 3
      flatcamTools/ToolAlignObjects.py
  18. 1 1
      flatcamTools/ToolDblSided.py
  19. 4 4
      flatcamTools/ToolNCC.py
  20. 3 3
      flatcamTools/ToolPunchGerber.py
  21. 2 2
      flatcamTools/ToolSolderPaste.py
  22. 二进制
      locale/de/LC_MESSAGES/strings.mo
  23. 327 267
      locale/de/LC_MESSAGES/strings.po
  24. 二进制
      locale/en/LC_MESSAGES/strings.mo
  25. 230 233
      locale/en/LC_MESSAGES/strings.po
  26. 二进制
      locale/es/LC_MESSAGES/strings.mo
  27. 230 233
      locale/es/LC_MESSAGES/strings.po
  28. 二进制
      locale/fr/LC_MESSAGES/strings.mo
  29. 229 232
      locale/fr/LC_MESSAGES/strings.po
  30. 3 3
      locale/it/LC_MESSAGES/strings.po
  31. 7 7
      locale/pt_BR/LC_MESSAGES/strings.po
  32. 二进制
      locale/ro/LC_MESSAGES/strings.mo
  33. 229 232
      locale/ro/LC_MESSAGES/strings.po
  34. 10 10
      locale/ru/LC_MESSAGES/strings.po
  35. 3 3
      locale_template/strings.pot
  36. 1 4
      tclCommands/TclCommandAlignDrill.py
  37. 2 3
      tclCommands/TclCommandBbox.py
  38. 2 3
      tclCommands/TclCommandCncjob.py
  39. 2 3
      tclCommands/TclCommandDrillcncjob.py
  40. 2 3
      tclCommands/TclCommandFollow.py
  41. 2 3
      tclCommands/TclCommandGeoCutout.py
  42. 2 3
      tclCommands/TclCommandIsolate.py
  43. 2 2
      tclCommands/TclCommandJoinExcellon.py
  44. 2 2
      tclCommands/TclCommandJoinGeometry.py
  45. 1 2
      tclCommands/TclCommandMillDrills.py
  46. 1 2
      tclCommands/TclCommandMillSlots.py
  47. 1 4
      tclCommands/TclCommandMirror.py
  48. 3 4
      tclCommands/TclCommandNregions.py
  49. 2 3
      tclCommands/TclCommandOpenGerber.py
  50. 7 8
      tclCommands/TclCommandPanelize.py

+ 33 - 31
CHANGELOG.md

@@ -19,6 +19,8 @@ CHANGELOG for FlatCAM beta
 - optimized the imports in some files
 - moved the Bookmarksmanager and ToolDB classes into their own files
 - solved some bugs that were not so visible in the Editors and HPGL parser
+- split the FlatCAMObj file into multiple files located in the flatcamObjects folder and renamed the contained classes with names more suggestive
+- updated the Google Translation for the German language
 
 25.04.2020
 
@@ -296,7 +298,7 @@ CHANGELOG for FlatCAM beta
 
 12.02.2020
 
-- working on fixing a bug in FlatCAMGeometry.merge() - FIXED issue #380
+- working on fixing a bug in GeometryObject.merge() - FIXED issue #380
 - fixed bug: when deleting a FlatCAMCNCJob with annotations enabled, the annotations are not deleted from canvas; fixed issue #379
 - fixed bug: creating a new project while a project is open and it contain CNCJob annotations and/or Gerber mark shapes, did not delete them from canvas
 
@@ -651,7 +653,7 @@ CHANGELOG for FlatCAM beta
 - modified the Jump To method such that now allows relative jump from the current mouse location
 - fixed the Defaults upgrade overwriting the new version number with the old one
 - fixed issue with clear_polygon3() - the one who makes 'lines' and fixed the NCC Tool
-- some small changes in the FlatCAMGeometry.on_tool_add() method
+- some small changes in the GeometryObject.on_tool_add() method
 - made sure that in Geometry Editor the self.app.mouse attribute is updated with the current mouse position (x, y)
 - updated the preprocessor files
 - fixed the HPGL preprocessor
@@ -694,7 +696,7 @@ CHANGELOG for FlatCAM beta
 - changed the Scale Entry in Object UI to FCEntry() GUI element in order to allow expressions to be entered. E.g: 1/25.4
 - some small changes in the Scale button handler in FlatCAMObj() class
 - added option to save objects as PDF files in File -> Save menu
-- optimized the FlatCAMGerber.clear_plot_apertures() method
+- optimized the GerberObject.clear_plot_apertures() method
 - some changes in the ObjectUI and for the Geometry UI
 - finished a very rough and limited HPGL2 file import 
 
@@ -724,7 +726,7 @@ CHANGELOG for FlatCAM beta
 - reverted this change: "selected object in Project used to ask twice for UI build" because it will not build the UI when a tab is closed for Document object and the object is selected
 - fixed issue after Geometry object edit; the GCode made from an edited object did not reflect the changes in the object
 - in Object UI, the Scale FCDoubleSpinner will no longer work for Return key press due of issues of unwanted scaling on focusOut event
-- in FlatCAMGeometry fixed the scale and offset methods to always process the self.solid_geometry
+- in GeometryObject fixed the scale and offset methods to always process the self.solid_geometry
 - Calibration Tool - finished the calibrated object creation method
 - updated the POT file
 - fixed an error in the German PO file
@@ -815,7 +817,7 @@ CHANGELOG for FlatCAM beta
 
 28.11.2019
 
-- small fixes in NCC Tool and in the FlatCAMGeometry class
+- small fixes in NCC Tool and in the GeometryObject class
 
 27.11.2019
 
@@ -833,7 +835,7 @@ CHANGELOG for FlatCAM beta
 
 - In Gerber isolation changed the UI
 - in Gerber isolation added the option to selectively isolate only certain polygons
-- made some optimizations in FlatCAMGerber.isolate() method
+- made some optimizations in GerberObject.isolate() method
 - updated the 'single' isolation of Gerber polygons to remove the polygon if clicked on it and it is already in the list of single polygons to be isolated
 - clicking to add a polygon when doing Single type isolation will add a blue shape marking the selected polygon, second click will remove that shape
 - fixed bugs in Paint Tool when painting single polygon
@@ -844,7 +846,7 @@ CHANGELOG for FlatCAM beta
 
 - in Tool Fiducials added a new fiducial type: chess pattern
 - work in Calibrate Excellon Tool
-- fixed the line numbers in the TextPlainEdit to fit all digits of the line number; activated the line numbers for FlatCAMScript objects too
+- fixed the line numbers in the TextPlainEdit to fit all digits of the line number; activated the line numbers for ScriptObject objects too
 - line numbers in the TextPlainEdit for the selected line are bold
 - made sure that the self.defaults dictionary is deepcopy-ed in the self.options dictionary
 - made sure that the units are read from the self.defaults and not from the GUI
@@ -856,7 +858,7 @@ CHANGELOG for FlatCAM beta
 - Tool Fiducials - updated the source_file object for the modified Gerber files
 - working on adding line numbers to the TextPlainEdit
 - GCode view now has line numbers
-- solved a bug that made selection of objects on canvas impossible if there is an object of type FlatCAMScript or FlatCAMDocument opened
+- solved a bug that made selection of objects on canvas impossible if there is an object of type ScriptObject or DocumentObject opened
 
 21.11.2019
 
@@ -913,7 +915,7 @@ CHANGELOG for FlatCAM beta
 - trying to improve the performance of View CNC Code command by using QPlainTextEdit; made the mods for it
 - when using the Find function in the TextEditor and the result reach the bottom of the document, the next find will be the first in the document (before it defaulted to the beginning of the document)
 - finished improving the show of text files in FlatCAM (CNC Code, Source files)
-- fixed an issue in the FlatCAMObj.FlatCAMGerber.convert_units() which needed to be updated after changes elsewhere
+- fixed an issue in the FlatCAMObj.GerberObject.convert_units() which needed to be updated after changes elsewhere
 
 12.11.2019
 
@@ -951,7 +953,7 @@ CHANGELOG for FlatCAM beta
 
 - the "CRTL+S" key combo when the Preferences Tab is in focus will save the Preferences instead of saving the Project
 - fixed bug in the Paint Tool that did not allow choosing a Paint Method that was not Standard
-- made sure that in the FlatCAMGeometry.merge() all the source data is deepcopy-ed in the final object
+- made sure that in the GeometryObject.merge() all the source data is deepcopy-ed in the final object
 - the font color of the Preferences tab will change to red if settings are not saved and it will revert to default when saved
 - fixed issue #333. The Geometry Editor Paint tool was not working and using it resulted in an error
 
@@ -1163,7 +1165,7 @@ CHANGELOG for FlatCAM beta
 - added a dark theme to FlatCAM (only for canvas). The selection is done in Edit -> Preferences -> General -> GUI Settings
 - updated the .POT file and worked a bit in the romanian translation
 - small changes: reduced the thickness of the axis in 3D mode from 3 pixels to 1 pixel
-- made sure that is the text in the source file of a FlatCAMDocument is HTML is loaded as such
+- made sure that is the text in the source file of a DocumentObject is HTML is loaded as such
 - added inverted icons
 
 6.10.2019
@@ -1207,20 +1209,20 @@ CHANGELOG for FlatCAM beta
 
 3.10.2019
 
-- previously I've added the initial layout for the FlatCAMDocument object
-- added more editing features in the Selected Tab for the FlatCAMDocument object
+- previously I've added the initial layout for the DocumentObject object
+- added more editing features in the Selected Tab for the DocumentObject object
 
 2.10.2019
 
 - fixed bug in Geometry Editor that did not allow the copy of geometric elements
 - created a new class that holds all the Code Editor functionality and integrated as a Editor in FlatCAM, the location is in flatcamEditors folder
 - remade all the functions for view_source, scripts and view_code to use the new TextEditor class; now all the Code Editor tabs are being kept alive, before only one could be in an open state
-- changed the name of the new object FlatCAMNotes to a more general one FlatCAMDocument
-- changed the way a new FlatCAMScript object is made, the method that is processing the Tcl commands when the Run button is clicked is moved to the FlatCAMObj.FlatCAMScript() class
+- changed the name of the new object FlatCAMNotes to a more general one DocumentObject
+- changed the way a new ScriptObject object is made, the method that is processing the Tcl commands when the Run button is clicked is moved to the FlatCAMObj.ScriptObject() class
 - reused the Multiprocessing Pool declared in the App for the ToolRulesCheck() class
 - adapted the Project context menu for the new types of FLatCAM objects
 - modified the setup_recent_files to accommodate the new FlatCAM objects
-- made sure that when an FlatCAMScript object is deleted, it's associated Tab is closed
+- made sure that when an ScriptObject object is deleted, it's associated Tab is closed
 - fixed the FlatCMAScript object saving when project is saved (loading a project with this script object is not working yet)
 - fixed the FlatCMAScript object when loading it from a project
 
@@ -1234,7 +1236,7 @@ CHANGELOG for FlatCAM beta
 - added new settings for the Gerber newly introduced feature to isolate with the V-Shape tools (tip dia, tip angle, tool_type and cut Z) in Edit -> Preferences -> Gerber Advanced
 - made those settings just added for Gerber, to be updated on object creation
 - added the Geo Tolerance parameter to those that are converted from MM to INCH
-- added two new FlatCAM objects: FlatCAMScript and FlatCAMNotes
+- added two new FlatCAM objects: ScriptObject and FlatCAMNotes
 
 30.09.2019
 
@@ -1457,7 +1459,7 @@ CHANGELOG for FlatCAM beta
 
 15.09.2019
 
-- refactored FlatCAMGeometry.mtool_gen_cncjob() method
+- refactored GeometryObject.mtool_gen_cncjob() method
 - fixed the TclCommandCncjob to work for multigeometry Geometry objects; still I had to fix the list of tools parameter, right now I am setting it to an empty list
 - update the Tcl Command isolate to be able to isolate exteriors, interiors besides the full isolation, using the iso_type parameter
 - fixed issue in ToolPaint that could not allow area painting of a geometry that was a list and not a Geometric element (polygon or MultiPolygon)
@@ -1833,7 +1835,7 @@ CHANGELOG for FlatCAM beta
 - done regression to solve the bug with multiple passes cutting from the copper features (I should remember not to make mods here)
 - if 'combine' is checked in Gerber isolation but there is only one pass, the resulting geometry will still be single geo
 - the 'passes' entry was changed to a IntSpinner so it will allow passes to be entered only in range (1, 999) - it will not allow entry of 0 which may create some issues
-- improved the FlatCAMGerber.isolate() function to work for geometry in the form of list and also in case that the elements of the list are LinearRings (like when doing the Exterior Isolation)
+- improved the GerberObject.isolate() function to work for geometry in the form of list and also in case that the elements of the list are LinearRings (like when doing the Exterior Isolation)
 - in NCC Tool made sure that at each run the old objects are deleted
 - fixed bug in camlib.Gerber.parse_lines() Gerber parser where for Allegro Gerber files the Gerber units were incorrectly detected
 - improved Mark Area Tool in Gerber Editor such that at each launch the previous markings are deleted
@@ -1928,7 +1930,7 @@ CHANGELOG for FlatCAM beta
 
 19.07.2019
 
-- fixed bug in FlatCAMObj.FlatCAMGeometry.ui_disconnect(); the widgets signals were not disconnected from handlers when required therefore the signals were connected in an exponential way
+- fixed bug in FlatCAMObj.GeometryObject.ui_disconnect(); the widgets signals were not disconnected from handlers when required therefore the signals were connected in an exponential way
 - some changes in the widgets used in the Selected tab for Geometry object
 - some PEP8 cleanup in FlatCAMObj.py
 - updated languages
@@ -2059,7 +2061,7 @@ CHANGELOG for FlatCAM beta
 
 - fixed bug in ToolCutout where creating a cutout object geometry from another external isolation geometry failed
 - fixed bug in cncjob TclCommand where the gcode could not be correctly generated due of missing bounds params in obj.options dict
-- fixed a hardcoded tolerance in FlatCAMGeometry.generatecncjob() and in FlatCAMGeometry.mtool_gen_cncjob() to use the parameter from Preferences
+- fixed a hardcoded tolerance in GeometryObject.generatecncjob() and in GeometryObject.mtool_gen_cncjob() to use the parameter from Preferences
 - updated translations
 
 5.06.2019
@@ -2233,7 +2235,7 @@ CHANGELOG for FlatCAM beta
 - fixed some bugs related to moving an Gerber object with the aperture table in view
 - added a new parameter in the Edit -> Preferences -> App Preferences named Geo Tolerance. This parameter control the level of geometric detail throughout FlatCAM. It directly influence the effect of Circle Steps parameter.
 - solved a bug in Excellon Editor that caused app crash when trying to edit a tool in Tool Table due of missing a tool offset
-- updated the ToolPanelize tool so the Gerber panel of type FlatCAMGerber can be isolated like any other FlatCAMGerber object
+- updated the ToolPanelize tool so the Gerber panel of type GerberObject can be isolated like any other GerberObject object
 - updated the ToolPanelize tool so it can be edited
 - modified the default values for toolchangez and endz parameters so they are now safe in all cases
 
@@ -2717,7 +2719,7 @@ CHANGELOG for FlatCAM beta
 - added ability to mark individual apertures in Gerber file using the Gerber Aperture Table
 - more modifications for the Gerber UI layout; made 'follow' an advanced Gerber option
 - added in Preferences a new Category: Gerber Advanced Options. For now it controls the display of Gerber Aperture Table and the "follow" attribute4
-- fixed FlatCAMGerber.merge() to merge the self.apertures[ap]['solid_geometry'] too
+- fixed GerberObject.merge() to merge the self.apertures[ap]['solid_geometry'] too
 - started to work on a new feature that allow adding a ToolChange GCode macro - GUI added both in CNCJob Selected tab and in CNCJob Preferences
 - added a limited 'sort-of' Gerber Editor: it allows buffering and scaling of apertures
 
@@ -2860,7 +2862,7 @@ CHANGELOG for FlatCAM beta
 - added total travel distance for CNCJob object created from Excellon Object in the CNCJob Selected tab
 - added 'FlatCAM ' prefix to any detached tab, for easy identification
 - remade the Grids context menu (right mouse button click on canvas). Now it has values linked to the units type (inch or mm). Added ability to add or delete grid values and they are persistent.
-- updated the function for the project context menu 'Generate CNC' menu entry (Action) to use the modernized function FlatCAMObj.FlatCAMGeometry.on_generatecnc_button_click()
+- updated the function for the project context menu 'Generate CNC' menu entry (Action) to use the modernized function FlatCAMObj.GeometryObject.on_generatecnc_button_click()
 - when linked, the grid snap on Y will copy the value in grid snap on X in real time
 - in Gerber aperture table now the values are displayed in the current units set in FlatCAM
 - added shortcut key 'J' (jump to location) in Editors and added an icon to the dialog popup window
@@ -2877,7 +2879,7 @@ CHANGELOG for FlatCAM beta
 - finished Gerber aperture table display
 - made the Gerber aperture table not visible as default and added a checkbox that can toggle the visibility
 - fixed issue with plotting in CNCJob; with Plot kind set to something else than 'all' when toggling Plot, it was defaulting to kind = 'all'
-- added (and commented) an experimental FlatCAMObj.FlatCAMGerber.plot_aperture()
+- added (and commented) an experimental FlatCAMObj.GerberObject.plot_aperture()
 
 12.02.2019
 
@@ -3066,7 +3068,7 @@ CHANGELOG for FlatCAM beta
 
 28.01.2018
 
-- fixed the FlatCAMGerber.merge() function
+- fixed the GerberObject.merge() function
 - added a new menu entry for the Gerber Join function: Edit -> Conversions -> "Join Gerber(s) to Gerber" allowing joining Gerber objects into a final Gerber object
 - moved Paint Tool defaults from Geometry section to the Tools section in Edit -> Preferences
 - added key shortcuts for Open Manual = F1 and for Open Online VideoHelp = F2
@@ -3089,13 +3091,13 @@ CHANGELOG for FlatCAM beta
 - added new entries to the Canvas context menu (Copy, Delete, Edit/Save, Move, New Excellon, New Geometry, New Project)
 - fixed GRBL_laser preprocessor file
 - updated function for copy of an Excellon object for the case when the object has slots
-- updated FlatCAMExcellon.merge() function to work in case some (or all) of the merged objects have slots  
+- updated ExcellonObject.merge() function to work in case some (or all) of the merged objects have slots  
 
 25.01.2019
 
 - deleted junk folders
 - remade the Panelize Tool: now it is much faster, it is multi-threaded, it works with multitool geometries and it works with multigeo geometries too.
-- made sure to copy the options attribute to the final object in the case of: FlatCAMGeometry.merge(), FlatCAMGerber.merge() and for the Panelize Tool
+- made sure to copy the options attribute to the final object in the case of: GeometryObject.merge(), GerberObject.merge() and for the Panelize Tool
 - modified the panelize TclCommand to take advantage of the new panelize() function; added a 'threaded' parameter (default value is 1) which controls the execution of the panelize TclCommand: threaded or non-threaded
 - fixed TclCommand Cutout
 - added a new TclCommand named CutoutAny. Keyword: cutout_any
@@ -3178,7 +3180,7 @@ CHANGELOG for FlatCAM beta
 - fixed the initial text in the ToolShell
 - reactivated the version check in case the release is not BETA; FlatCAMApp.App has now a beta object that when set True the application will show in the Title and help-> About that is Beta (and it disable version checking)
 - added a new name (mine: for good and/or bad) to the contributors list
-- fixed the Join function to work on Gerber and Excellon, Gerber and Gerber, Excellon and Excelon combination of objects. The merged property is the solid_geometry and the result is a FlatCAMGeometry object.
+- fixed the Join function to work on Gerber and Excellon, Gerber and Gerber, Excellon and Excelon combination of objects. The merged property is the solid_geometry and the result is a GeometryObject object.
 
 3.01.2019
 
@@ -3260,8 +3262,8 @@ CHANGELOG for FlatCAM beta
 
 18.12.2018
 
-- small changes in FlatCAMGeometry.plot()
-- updated the FlatCAMGeometry.merge() function and the Join Geometry feature to accommodate the different types of geometries: singlegeo and multigeo type
+- small changes in GeometryObject.plot()
+- updated the GeometryObject.merge() function and the Join Geometry feature to accommodate the different types of geometries: singlegeo and multigeo type
 - added Conversion submenu in Edit where I moved the Join features and added the Convert from MultiGeo to SingleGeo type and the reverse
 - added Copy Tool (on a selection of tools) feature in Geometry Object UI 
 - fixed the bounds() method for the MultiGeo geometry object so the canvas selection is working and also the Properties Tool

+ 93 - 89
FlatCAMApp.py

@@ -14,24 +14,22 @@ import getopt
 import random
 import simplejson as json
 import lzma
-# import threading
 import shutil
 import stat
-
+from datetime import datetime
 from stat import S_IREAD, S_IRGRP, S_IROTH
 import ctypes
+import traceback
 
-# import tkinter as tk
-# from PyQt5 import QtPrintSupport
+from shapely.geometry import Point, MultiPolygon
+from io import StringIO
 
 from reportlab.graphics import renderPDF
 from reportlab.pdfgen import canvas
-# from reportlab.graphics import renderPM
 from reportlab.lib.units import inch, mm
 from reportlab.lib.pagesizes import landscape, portrait
 from svglib.svglib import svg2rlg
 
-# from contextlib import contextmanager
 import gc
 
 from xml.dom.minidom import parseString as parse_xml_string
@@ -39,9 +37,6 @@ from xml.dom.minidom import parseString as parse_xml_string
 from multiprocessing.connection import Listener, Client
 from multiprocessing import Pool
 import socket
-# from array import array
-
-# import vispy.scene as scene
 
 # #######################################
 # #      Imports part of FlatCAM       ##
@@ -51,8 +46,17 @@ from FlatCAMBookmark import BookmarkManager
 from FlatCAMDB import ToolsDB2
 
 from ObjectCollection import *
-from FlatCAMObj import *
-from camlib import to_dict, dict2obj, ET, ParseError
+from flatcamObjects.FlatCAMObj import FlatCAMObj
+from flatcamObjects.FlatCAMCNCJob import CNCJobObject
+from flatcamObjects.FlatCAMDocument import DocumentObject
+from flatcamObjects.FlatCAMExcellon import ExcellonObject
+from flatcamObjects.FlatCAMGeometry import GeometryObject
+from flatcamObjects.FlatCAMGerber import GerberObject
+from flatcamObjects.FlatCAMScript import ScriptObject
+
+from flatcamParsers.ParseExcellon import Excellon
+from flatcamParsers.ParseGerber import Gerber
+from camlib import to_dict, dict2obj, ET, ParseError, Geometry, CNCjob
 
 from flatcamGUI.PlotCanvas import *
 from flatcamGUI.PlotCanvasLegacy import *
@@ -3411,14 +3415,14 @@ class App(QtCore.QObject):
 
         edited_object = self.collection.get_active()
 
-        if isinstance(edited_object, FlatCAMGerber) or isinstance(edited_object, FlatCAMGeometry) or \
-                isinstance(edited_object, FlatCAMExcellon):
+        if isinstance(edited_object, GerberObject) or isinstance(edited_object, GeometryObject) or \
+                isinstance(edited_object, ExcellonObject):
             pass
         else:
             self.inform.emit('[WARNING_NOTCL] %s' % _("Select a Geometry, Gerber or Excellon Object to edit."))
             return
 
-        if isinstance(edited_object, FlatCAMGeometry):
+        if isinstance(edited_object, GeometryObject):
             # store the Geometry Editor Toolbar visibility before entering in the Editor
             self.geo_editor.toolbar_old_state = True if self.ui.geo_edit_toolbar.isVisible() else False
 
@@ -3451,7 +3455,7 @@ class App(QtCore.QObject):
             # set call source to the Editor we go into
             self.call_source = 'geo_editor'
 
-        elif isinstance(edited_object, FlatCAMExcellon):
+        elif isinstance(edited_object, ExcellonObject):
             # store the Excellon Editor Toolbar visibility before entering in the Editor
             self.exc_editor.toolbar_old_state = True if self.ui.exc_edit_toolbar.isVisible() else False
 
@@ -3463,7 +3467,7 @@ class App(QtCore.QObject):
             # set call source to the Editor we go into
             self.call_source = 'exc_editor'
 
-        elif isinstance(edited_object, FlatCAMGerber):
+        elif isinstance(edited_object, GerberObject):
             # store the Gerber Editor Toolbar visibility before entering in the Editor
             self.grb_editor.toolbar_old_state = True if self.ui.grb_edit_toolbar.isVisible() else False
 
@@ -3527,7 +3531,7 @@ class App(QtCore.QObject):
                     self.ui.tool_scroll_area.setWidget(QtWidgets.QWidget())
                     self.ui.notebook.setTabText(2, "Tool")
 
-                    if isinstance(edited_obj, FlatCAMGeometry):
+                    if isinstance(edited_obj, GeometryObject):
                         obj_type = "Geometry"
                         if cleanup is None:
                             self.geo_editor.update_fcgeometry(edited_obj)
@@ -3553,7 +3557,7 @@ class App(QtCore.QObject):
                         edited_obj.build_ui()
                         self.inform.emit('[success] %s' % _("Editor exited. Editor content saved."))
 
-                    elif isinstance(edited_obj, FlatCAMGerber):
+                    elif isinstance(edited_obj, GerberObject):
                         obj_type = "Gerber"
                         if cleanup is None:
                             self.grb_editor.update_fcgerber()
@@ -3578,7 +3582,7 @@ class App(QtCore.QObject):
                         # Remove anything else in the GUI
                         self.ui.selected_scroll_area.takeWidget()
 
-                    elif isinstance(edited_obj, FlatCAMExcellon):
+                    elif isinstance(edited_obj, ExcellonObject):
                         obj_type = "Excellon"
                         if cleanup is None:
                             self.exc_editor.update_fcexcellon(edited_obj)
@@ -3610,13 +3614,13 @@ class App(QtCore.QObject):
 
                     self.inform.emit('[WARNING_NOTCL] %s' % _("Editor exited. Editor content was not saved."))
 
-                    if isinstance(edited_obj, FlatCAMGeometry):
+                    if isinstance(edited_obj, GeometryObject):
                         self.geo_editor.deactivate()
                         edited_obj.build_ui()
-                    elif isinstance(edited_obj, FlatCAMGerber):
+                    elif isinstance(edited_obj, GerberObject):
                         self.grb_editor.deactivate_grb_editor()
                         edited_obj.build_ui()
-                    elif isinstance(edited_obj, FlatCAMExcellon):
+                    elif isinstance(edited_obj, ExcellonObject):
                         self.exc_editor.deactivate()
                         edited_obj.build_ui()
                     else:
@@ -3631,11 +3635,11 @@ class App(QtCore.QObject):
                 # Switch notebook to Selected page
                 self.ui.notebook.setCurrentWidget(self.ui.selected_tab)
             else:
-                if isinstance(edited_obj, FlatCAMGeometry):
+                if isinstance(edited_obj, GeometryObject):
                     self.geo_editor.deactivate()
-                elif isinstance(edited_obj, FlatCAMGerber):
+                elif isinstance(edited_obj, GerberObject):
                     self.grb_editor.deactivate_grb_editor()
-                elif isinstance(edited_obj, FlatCAMExcellon):
+                elif isinstance(edited_obj, ExcellonObject):
                     self.exc_editor.deactivate()
                 else:
                     self.inform.emit('[WARNING_NOTCL] %s' %
@@ -4227,12 +4231,12 @@ class App(QtCore.QObject):
 
         # ## Create object
         classdict = {
-            "gerber": FlatCAMGerber,
-            "excellon": FlatCAMExcellon,
-            "cncjob": FlatCAMCNCjob,
-            "geometry": FlatCAMGeometry,
-            "script": FlatCAMScript,
-            "document": FlatCAMDocument
+            "gerber": GerberObject,
+            "excellon": ExcellonObject,
+            "cncjob": CNCJobObject,
+            "geometry": GeometryObject,
+            "script": ScriptObject,
+            "document": DocumentObject
         }
 
         App.log.debug("Calling object constructor...")
@@ -4497,7 +4501,7 @@ class App(QtCore.QObject):
         # here it is done the object plotting
         def worker_task(t_obj):
             with self.proc_container.new(_("Plotting")):
-                if isinstance(t_obj, FlatCAMCNCjob):
+                if isinstance(t_obj, CNCJobObject):
                     t_obj.plot(kind=self.defaults["cncjob_plot_kind"])
                 else:
                     t_obj.plot()
@@ -5661,7 +5665,7 @@ class App(QtCore.QObject):
         # if at least one True object is in the list then due of the previous check, all list elements are True objects
         if True in geo_type_set:
             def initialize(geo_obj, app):
-                FlatCAMGeometry.merge(self, geo_list=objs, geo_final=geo_obj, multigeo=True)
+                GeometryObject.merge(self, geo_list=objs, geo_final=geo_obj, multigeo=True)
                 app.inform.emit('[success] %s.' % _("Geometry merging finished"))
 
                 # rename all the ['name] key in obj.tools[tooluid]['data'] to the obj_name_multi
@@ -5671,7 +5675,7 @@ class App(QtCore.QObject):
             self.new_object("geometry", obj_name_multi, initialize)
         else:
             def initialize(geo_obj, app):
-                FlatCAMGeometry.merge(self, geo_list=objs, geo_final=geo_obj, multigeo=False)
+                GeometryObject.merge(self, geo_list=objs, geo_final=geo_obj, multigeo=False)
                 app.inform.emit('[success] %s.' % _("Geometry merging finished"))
 
                 # rename all the ['name] key in obj.tools[tooluid]['data'] to the obj_name_multi
@@ -5694,7 +5698,7 @@ class App(QtCore.QObject):
         objs = self.collection.get_selected()
 
         for obj in objs:
-            if not isinstance(obj, FlatCAMExcellon):
+            if not isinstance(obj, ExcellonObject):
                 self.inform.emit('[ERROR_NOTCL] %s' % _("Failed. Excellon joining works only on Excellon objects."))
                 return
 
@@ -5704,7 +5708,7 @@ class App(QtCore.QObject):
             return 'fail'
 
         def initialize(exc_obj, app):
-            FlatCAMExcellon.merge(self, exc_list=objs, exc_final=exc_obj)
+            ExcellonObject.merge(self, exc_list=objs, exc_final=exc_obj)
             app.inform.emit('[success] %s.' % _("Excellon merging finished"))
 
         self.new_object("excellon", 'Combo_Excellon', initialize)
@@ -5722,7 +5726,7 @@ class App(QtCore.QObject):
         objs = self.collection.get_selected()
 
         for obj in objs:
-            if not isinstance(obj, FlatCAMGerber):
+            if not isinstance(obj, GerberObject):
                 self.inform.emit('[ERROR_NOTCL] %s' % _("Failed. Gerber joining works only on Gerber objects."))
                 return
 
@@ -5732,7 +5736,7 @@ class App(QtCore.QObject):
             return 'fail'
 
         def initialize(grb_obj, app):
-            FlatCAMGerber.merge(self, grb_list=objs, grb_final=grb_obj)
+            GerberObject.merge(self, grb_list=objs, grb_final=grb_obj)
             app.inform.emit('[success] %s.' % _("Gerber merging finished"))
 
         self.new_object("gerber", 'Combo_Gerber', initialize)
@@ -5756,8 +5760,8 @@ class App(QtCore.QObject):
             self.inform.emit('[ERROR_NOTCL] %s' % _("Failed. Select a Geometry Object and try again."))
             return
 
-        if not isinstance(obj, FlatCAMGeometry):
-            self.inform.emit('[ERROR_NOTCL] %s: %s' % (_("Expected a FlatCAMGeometry, got"), type(obj)))
+        if not isinstance(obj, GeometryObject):
+            self.inform.emit('[ERROR_NOTCL] %s: %s' % (_("Expected a GeometryObject, got"), type(obj)))
             return
 
         obj.multigeo = True
@@ -5791,9 +5795,9 @@ class App(QtCore.QObject):
                              _("Failed. Select a Geometry Object and try again."))
             return
 
-        if not isinstance(obj, FlatCAMGeometry):
+        if not isinstance(obj, GeometryObject):
             self.inform.emit('[ERROR_NOTCL] %s: %s' %
-                             (_("Expected a FlatCAMGeometry, got"), type(obj)))
+                             (_("Expected a GeometryObject, got"), type(obj)))
             return
 
         obj.multigeo = False
@@ -6078,7 +6082,7 @@ class App(QtCore.QObject):
             current = self.collection.get_active()
             if current is not None:
                 # the transfer of converted values to the UI form for Geometry is done local in the FlatCAMObj.py
-                if not isinstance(current, FlatCAMGeometry):
+                if not isinstance(current, GeometryObject):
                     current.to_form()
 
             # replot all objects
@@ -6943,7 +6947,7 @@ class App(QtCore.QObject):
 
         # work only if the notebook tab on focus is the Selected_Tab and only if the object is Geometry
         if notebook_widget_name == 'selected_tab':
-            if str(type(self.collection.get_active())) == "<class 'FlatCAMObj.FlatCAMGeometry'>":
+            if str(type(self.collection.get_active())) == "<class 'FlatCAMObj.GeometryObject'>":
                 self.collection.get_active().on_tool_delete()
 
         # work only if the notebook tab on focus is the Tools_Tab
@@ -7007,14 +7011,14 @@ class App(QtCore.QObject):
                     self.log.debug("App.on_delete()")
 
                     for obj_active in self.collection.get_selected():
-                        # if the deleted object is FlatCAMGerber then make sure to delete the possible mark shapes
-                        if isinstance(obj_active, FlatCAMGerber):
+                        # if the deleted object is GerberObject then make sure to delete the possible mark shapes
+                        if isinstance(obj_active, GerberObject):
                             for el in obj_active.mark_shapes:
                                 obj_active.mark_shapes[el].clear(update=True)
                                 obj_active.mark_shapes[el].enabled = False
                                 # obj_active.mark_shapes[el] = None
                                 del el
-                        elif isinstance(obj_active, FlatCAMCNCjob):
+                        elif isinstance(obj_active, CNCJobObject):
                             try:
                                 obj_active.text_col.enabled = False
                                 del obj_active.text_col
@@ -7556,15 +7560,15 @@ class App(QtCore.QObject):
             obj_name = obj.options["name"]
 
             try:
-                if isinstance(obj, FlatCAMExcellon):
+                if isinstance(obj, ExcellonObject):
                     self.new_object("excellon", str(obj_name) + "_copy", initialize_excellon)
-                elif isinstance(obj, FlatCAMGerber):
+                elif isinstance(obj, GerberObject):
                     self.new_object("gerber", str(obj_name) + "_copy", initialize)
-                elif isinstance(obj, FlatCAMGeometry):
+                elif isinstance(obj, GeometryObject):
                     self.new_object("geometry", str(obj_name) + "_copy", initialize)
-                elif isinstance(obj, FlatCAMScript):
+                elif isinstance(obj, ScriptObject):
                     self.new_object("script", str(obj_name) + "_copy", initialize_script)
-                elif isinstance(obj, FlatCAMDocument):
+                elif isinstance(obj, DocumentObject):
                     self.new_object("document", str(obj_name) + "_copy", initialize_document)
             except Exception as e:
                 return "Operation failed: %s" % str(e)
@@ -7608,11 +7612,11 @@ class App(QtCore.QObject):
         for obj in self.collection.get_selected():
             obj_name = obj.options["name"]
             try:
-                if isinstance(obj, FlatCAMExcellon):
+                if isinstance(obj, ExcellonObject):
                     self.new_object("excellon", str(obj_name) + custom_name, initialize_excellon)
-                elif isinstance(obj, FlatCAMGerber):
+                elif isinstance(obj, GerberObject):
                     self.new_object("gerber", str(obj_name) + custom_name, initialize_gerber)
-                elif isinstance(obj, FlatCAMGeometry):
+                elif isinstance(obj, GeometryObject):
                     self.new_object("geometry", str(obj_name) + custom_name, initialize_geometry)
             except Exception as er:
                 return "Operation failed: %s" % str(er)
@@ -7662,7 +7666,7 @@ class App(QtCore.QObject):
 
         def initialize_excellon(obj_init, app):
             # objs = self.collection.get_selected()
-            # FlatCAMGeometry.merge(objs, obj)
+            # GeometryObject.merge(objs, obj)
             solid_geo = []
             for tool in obj.tools:
                 for geo in obj.tools[tool]['solid_geometry']:
@@ -7679,7 +7683,7 @@ class App(QtCore.QObject):
             obj_name = obj.options["name"]
 
             try:
-                if isinstance(obj, FlatCAMExcellon):
+                if isinstance(obj, ExcellonObject):
                     self.new_object("geometry", str(obj_name) + "_conv", initialize_excellon)
                 else:
                     self.new_object("geometry", str(obj_name) + "_conv", initialize)
@@ -7757,9 +7761,9 @@ class App(QtCore.QObject):
             obj_name = obj.options["name"]
 
             try:
-                if isinstance(obj, FlatCAMExcellon):
+                if isinstance(obj, ExcellonObject):
                     self.new_object("gerber", str(obj_name) + "_conv", initialize_excellon)
-                elif isinstance(obj, FlatCAMGeometry):
+                elif isinstance(obj, GeometryObject):
                     self.new_object("gerber", str(obj_name) + "_conv", initialize_geometry)
                 else:
                     log.warning("App.convert_any2gerber --> This is no vaild object for conversion.")
@@ -7960,7 +7964,7 @@ class App(QtCore.QObject):
         tool_from_db = deepcopy(tool)
 
         obj = self.collection.get_active()
-        if isinstance(obj, FlatCAMGeometry):
+        if isinstance(obj, GeometryObject):
             obj.on_tool_from_db_inserted(tool=tool_from_db)
 
             # close the tab and delete it
@@ -8994,8 +8998,8 @@ class App(QtCore.QObject):
         curr_x, curr_y = self.pos
 
         for obj in self.all_objects_list:
-            # FlatCAMScript and FlatCAMDocument objects can't be selected
-            if isinstance(obj, FlatCAMScript) or isinstance(obj, FlatCAMDocument):
+            # ScriptObject and DocumentObject objects can't be selected
+            if isinstance(obj, ScriptObject) or isinstance(obj, DocumentObject):
                 continue
 
             if key == 'multisel' and obj.options['name'] in self.objects_under_the_click_list:
@@ -9336,7 +9340,7 @@ class App(QtCore.QObject):
 
         for obj in self.collection.get_list():
             # delete shapes left drawn from mark shape_collections, if any
-            if isinstance(obj, FlatCAMGerber):
+            if isinstance(obj, GerberObject):
                 try:
                     for el in obj.mark_shapes:
                         obj.mark_shapes[el].clear(update=True)
@@ -9346,7 +9350,7 @@ class App(QtCore.QObject):
                     pass
 
             # also delete annotation shapes, if any
-            elif isinstance(obj, FlatCAMCNCjob):
+            elif isinstance(obj, CNCJobObject):
                 try:
                     obj.text_col.enabled = False
                     del obj.text_col
@@ -9409,17 +9413,17 @@ class App(QtCore.QObject):
         """
 
         obj = self.collection.get_active()
-        if type(obj) == FlatCAMGeometry:
+        if type(obj) == GeometryObject:
             self.on_file_exportdxf()
-        elif type(obj) == FlatCAMExcellon:
+        elif type(obj) == ExcellonObject:
             self.on_file_saveexcellon()
-        elif type(obj) == FlatCAMCNCjob:
+        elif type(obj) == CNCJobObject:
             obj.on_exportgcode_button_click()
-        elif type(obj) == FlatCAMGerber:
+        elif type(obj) == GerberObject:
             self.on_file_savegerber()
-        elif type(obj) == FlatCAMScript:
+        elif type(obj) == ScriptObject:
             self.on_file_savescript()
-        elif type(obj) == FlatCAMDocument:
+        elif type(obj) == DocumentObject:
             self.on_file_savedocument()
 
     def obj_move(self):
@@ -9672,10 +9676,10 @@ class App(QtCore.QObject):
             return
 
         # Check for more compatible types and add as required
-        if (not isinstance(obj, FlatCAMGeometry)
-                and not isinstance(obj, FlatCAMGerber)
-                and not isinstance(obj, FlatCAMCNCjob)
-                and not isinstance(obj, FlatCAMExcellon)):
+        if (not isinstance(obj, GeometryObject)
+                and not isinstance(obj, GerberObject)
+                and not isinstance(obj, CNCJobObject)
+                and not isinstance(obj, ExcellonObject)):
             msg = '[ERROR_NOTCL] %s' % \
                   _("Only Geometry, Gerber and CNCJob objects can be used.")
             msgbox = QtWidgets.QMessageBox()
@@ -9761,7 +9765,7 @@ class App(QtCore.QObject):
             return
 
         # Check for more compatible types and add as required
-        if not isinstance(obj, FlatCAMGerber):
+        if not isinstance(obj, GerberObject):
             self.inform.emit('[ERROR_NOTCL] %s' % _("Failed. Only Gerber objects can be saved as Gerber files..."))
             return
 
@@ -9802,7 +9806,7 @@ class App(QtCore.QObject):
             return
 
         # Check for more compatible types and add as required
-        if not isinstance(obj, FlatCAMScript):
+        if not isinstance(obj, ScriptObject):
             self.inform.emit('[ERROR_NOTCL] %s' % _("Failed. Only Script objects can be saved as TCL Script files..."))
             return
 
@@ -9843,7 +9847,7 @@ class App(QtCore.QObject):
             return
 
         # Check for more compatible types and add as required
-        if not isinstance(obj, FlatCAMScript):
+        if not isinstance(obj, ScriptObject):
             self.inform.emit('[ERROR_NOTCL] %s' % _("Failed. Only Document objects can be saved as Document files..."))
             return
 
@@ -9884,7 +9888,7 @@ class App(QtCore.QObject):
             return
 
         # Check for more compatible types and add as required
-        if not isinstance(obj, FlatCAMExcellon):
+        if not isinstance(obj, ExcellonObject):
             self.inform.emit('[ERROR_NOTCL] %s' % _("Failed. Only Excellon objects can be saved as Excellon files..."))
             return
 
@@ -9925,7 +9929,7 @@ class App(QtCore.QObject):
             return
 
         # Check for more compatible types and add as required
-        if not isinstance(obj, FlatCAMExcellon):
+        if not isinstance(obj, ExcellonObject):
             self.inform.emit('[ERROR_NOTCL] %s' % _("Failed. Only Excellon objects can be saved as Excellon files..."))
             return
 
@@ -9969,7 +9973,7 @@ class App(QtCore.QObject):
             return
 
         # Check for more compatible types and add as required
-        if not isinstance(obj, FlatCAMGerber):
+        if not isinstance(obj, GerberObject):
             self.inform.emit('[ERROR_NOTCL] %s' % _("Failed. Only Gerber objects can be saved as Gerber files..."))
             return
 
@@ -10019,7 +10023,7 @@ class App(QtCore.QObject):
             return
 
         # Check for more compatible types and add as required
-        if not isinstance(obj, FlatCAMGeometry):
+        if not isinstance(obj, GeometryObject):
             msg = '[ERROR_NOTCL] %s' % _("Only Geometry objects can be used.")
             msgbox = QtWidgets.QMessageBox()
             msgbox.setInformativeText(msg)
@@ -10368,7 +10372,7 @@ class App(QtCore.QObject):
                 self.splash.showMessage('%s: %ssec\n%s' %
                                         (_("Canvas initialization started.\n"
                                            "Canvas initialization finished in"), '%.2f' % self.used_time,
-                                         _("Executing FlatCAMScript file.")
+                                         _("Executing ScriptObject file.")
                                          ),
                                         alignment=Qt.AlignBottom | Qt.AlignLeft,
                                         color=QtGui.QColor("gray"))
@@ -10847,7 +10851,7 @@ class App(QtCore.QObject):
         else:
             obj = local_use
 
-        if not isinstance(obj, FlatCAMExcellon):
+        if not isinstance(obj, ExcellonObject):
             self.inform.emit('[ERROR_NOTCL] %s' %
                              _("Failed. Only Excellon objects can be saved as Excellon files..."))
             return
@@ -11253,8 +11257,8 @@ class App(QtCore.QObject):
         # How the object should be initialized
         def obj_init(gerber_obj, app_obj):
 
-            assert isinstance(gerber_obj, FlatCAMGerber), \
-                "Expected to initialize a FlatCAMGerber but got %s" % type(gerber_obj)
+            assert isinstance(gerber_obj, GerberObject), \
+                "Expected to initialize a GerberObject but got %s" % type(gerber_obj)
 
             # Opening the file happens here
             try:
@@ -11439,8 +11443,8 @@ class App(QtCore.QObject):
         # How the object should be initialized
         def obj_init(geo_obj, app_obj):
 
-            assert isinstance(geo_obj, FlatCAMGeometry), \
-                "Expected to initialize a FlatCAMGeometry but got %s" % type(geo_obj)
+            assert isinstance(geo_obj, GeometryObject), \
+                "Expected to initialize a GeometryObject but got %s" % type(geo_obj)
 
             # Opening the file happens here
             obj = HPGL2(self)
@@ -12330,7 +12334,7 @@ class App(QtCore.QObject):
             with self.proc_container.new(_("Enabling plots ...")):
                 for plot_obj in objs:
                     # obj.options['plot'] = True
-                    if isinstance(plot_obj, FlatCAMCNCjob):
+                    if isinstance(plot_obj, CNCJobObject):
                         plot_obj.plot(visible=True, kind=self.defaults["cncjob_plot_kind"])
                     else:
                         plot_obj.plot(visible=True)
@@ -12382,7 +12386,7 @@ class App(QtCore.QObject):
             with self.proc_container.new(_("Disabling plots ...")):
                 for plot_obj in objs:
                     # obj.options['plot'] = True
-                    if isinstance(plot_obj, FlatCAMCNCjob):
+                    if isinstance(plot_obj, CNCJobObject):
                         plot_obj.plot(visible=False, kind=self.defaults["cncjob_plot_kind"])
                     else:
                         plot_obj.plot(visible=False)

+ 0 - 8245
FlatCAMObj.py

@@ -1,8245 +0,0 @@
-# ##########################################################
-# FlatCAM: 2D Post-processing for Manufacturing            #
-# http://flatcam.org                                       #
-# Author: Juan Pablo Caram (c)                             #
-# Date: 2/5/2014                                           #
-# MIT Licence                                              #
-# ##########################################################
-
-# ##########################################################
-# File modified by: Marius Stanciu                         #
-# ##########################################################
-
-
-from shapely.geometry import Point, Polygon, MultiPolygon, MultiLineString, LineString, LinearRing
-from shapely.ops import cascaded_union
-import shapely.affinity as affinity
-
-from copy import deepcopy
-# from copy import copy
-
-from io import StringIO
-import traceback
-import inspect  # TODO: For debugging only.
-from datetime import datetime
-
-from flatcamEditors.FlatCAMTextEditor import TextEditor
-from flatcamGUI.ObjectUI import *
-from flatcamGUI.GUIElements import FCFileSaveDialog
-from FlatCAMCommon import LoudDict
-from flatcamGUI.PlotCanvasLegacy import ShapeCollectionLegacy
-from flatcamParsers.ParseExcellon import Excellon
-from flatcamParsers.ParseGerber import Gerber
-from camlib import Geometry, CNCjob
-
-# from flatcamGUI.VisPyVisuals import ShapeCollection
-
-import tkinter as tk
-import os
-import sys
-import itertools
-import ezdxf
-
-import math
-import numpy as np
-
-import gettext
-import FlatCAMTranslation as fcTranslate
-import builtins
-
-fcTranslate.apply_language('strings')
-if '_' not in builtins.__dict__:
-    _ = gettext.gettext
-
-
-# Interrupts plotting process if FlatCAMObj has been deleted
-class ObjectDeleted(Exception):
-    pass
-
-
-class ValidationError(Exception):
-    def __init__(self, message, errors):
-        super().__init__(message)
-
-        self.errors = errors
-
-
-# #######################################
-# #            FlatCAMObj              ##
-# #######################################
-
-
-class FlatCAMObj(QtCore.QObject):
-    """
-    Base type of objects handled in FlatCAM. These become interactive
-    in the GUI, can be plotted, and their options can be modified
-    by the user in their respective forms.
-    """
-
-    # Instance of the application to which these are related.
-    # The app should set this value.
-    app = None
-
-    # signal to plot a single object
-    plot_single_object = QtCore.pyqtSignal()
-
-    def __init__(self, name):
-        """
-        Constructor.
-
-        :param name: Name of the object given by the user.
-        :return: FlatCAMObj
-        """
-
-        QtCore.QObject.__init__(self)
-
-        # View
-        self.ui = None
-
-        self.options = LoudDict(name=name)
-        self.options.set_change_callback(self.on_options_change)
-
-        self.form_fields = {}
-
-        # store here the default data for Geometry Data
-        self.default_data = {}
-
-        # 2D mode
-        # Axes must exist and be attached to canvas.
-        self.axes = None
-        self.kind = None  # Override with proper name
-
-        if self.app.is_legacy is False:
-            self.shapes = self.app.plotcanvas.new_shape_group()
-            # self.shapes = ShapeCollection(parent=self.app.plotcanvas.view.scene, pool=self.app.pool, layers=2)
-        else:
-            self.shapes = ShapeCollectionLegacy(obj=self, app=self.app, name=name)
-
-        self.mark_shapes = {}
-
-        self.item = None  # Link with project view item
-
-        self.muted_ui = False
-        self.deleted = False
-
-        try:
-            self._drawing_tolerance = float(self.app.defaults["global_tolerance"]) if \
-                self.app.defaults["global_tolerance"] else 0.01
-        except ValueError:
-            self._drawing_tolerance = 0.01
-
-        self.isHovering = False
-        self.notHovering = True
-
-        # Flag to show if a selection shape is drawn
-        self.selection_shape_drawn = False
-
-        # self.units = 'IN'
-        self.units = self.app.defaults['units']
-
-        self.plot_single_object.connect(self.single_object_plot)
-
-    def __del__(self):
-        pass
-
-    def __str__(self):
-        return "<FlatCAMObj({:12s}): {:20s}>".format(self.kind, self.options["name"])
-
-    def from_dict(self, d):
-        """
-        This supersedes ``from_dict`` in derived classes. Derived classes
-        must inherit from FlatCAMObj first, then from derivatives of Geometry.
-
-        ``self.options`` is only updated, not overwritten. This ensures that
-        options set by the app do not vanish when reading the objects
-        from a project file.
-
-        :param d: Dictionary with attributes to set.
-        :return: None
-        """
-
-        for attr in self.ser_attrs:
-
-            if attr == 'options':
-                self.options.update(d[attr])
-            else:
-                try:
-                    setattr(self, attr, d[attr])
-                except KeyError:
-                    log.debug("FlatCAMObj.from_dict() --> KeyError: %s. "
-                              "Means that we are loading an old project that don't"
-                              "have all attributes in the latest FlatCAM." % str(attr))
-                    pass
-
-    def on_options_change(self, key):
-        # Update form on programmatically options change
-        self.set_form_item(key)
-
-        # Set object visibility
-        if key == 'plot':
-            self.visible = self.options['plot']
-
-        self.optionChanged.emit(key)
-
-    def set_ui(self, ui):
-        self.ui = ui
-
-        self.form_fields = {"name": self.ui.name_entry}
-
-        assert isinstance(self.ui, ObjectUI)
-        self.ui.name_entry.returnPressed.connect(self.on_name_activate)
-
-        try:
-            # it will raise an exception for those FlatCAM objects that do not build UI with the common elements
-            self.ui.offset_button.clicked.connect(self.on_offset_button_click)
-        except (TypeError, AttributeError):
-            pass
-
-        try:
-            self.ui.scale_button.clicked.connect(self.on_scale_button_click)
-        except (TypeError, AttributeError):
-            pass
-
-        try:
-            self.ui.offsetvector_entry.returnPressed.connect(self.on_offset_button_click)
-        except (TypeError, AttributeError):
-            pass
-
-        # Creates problems on focusOut
-        try:
-            self.ui.scale_entry.returnPressed.connect(self.on_scale_button_click)
-        except (TypeError, AttributeError):
-            pass
-
-        # self.ui.skew_button.clicked.connect(self.on_skew_button_click)
-
-    def build_ui(self):
-        """
-        Sets up the UI/form for this object. Show the UI
-        in the App.
-
-        :return: None
-        :rtype: None
-        """
-
-        self.muted_ui = True
-        log.debug(str(inspect.stack()[1][3]) + "--> FlatCAMObj.build_ui()")
-
-        try:
-            # HACK: disconnect the scale entry signal since on focus out event will trigger an undesired scale()
-            # it seems that the takewidget() does generate a focus out event for the QDoubleSpinbox ...
-            # and reconnect after the takeWidget() is done
-            # self.ui.scale_entry.returnPressed.disconnect(self.on_scale_button_click)
-            self.app.ui.selected_scroll_area.takeWidget()
-            # self.ui.scale_entry.returnPressed.connect(self.on_scale_button_click)
-        except Exception as e:
-            self.app.log.debug("FlatCAMObj.build_ui() --> Nothing to remove: %s" % str(e))
-
-        self.app.ui.selected_scroll_area.setWidget(self.ui)
-        # self.ui.setMinimumWidth(100)
-        # self.ui.setMaximumWidth(self.app.ui.selected_tab.sizeHint().width())
-
-        self.muted_ui = False
-
-    def on_name_activate(self, silent=None):
-        old_name = copy(self.options["name"])
-        new_name = self.ui.name_entry.get_value()
-
-        if new_name != old_name:
-            # update the SHELL auto-completer model data
-            try:
-                self.app.myKeywords.remove(old_name)
-                self.app.myKeywords.append(new_name)
-                self.app.shell._edit.set_model_data(self.app.myKeywords)
-                self.app.ui.code_editor.set_model_data(self.app.myKeywords)
-            except Exception:
-                log.debug("on_name_activate() --> Could not remove the old object name from auto-completer model list")
-
-            self.options["name"] = self.ui.name_entry.get_value()
-            self.default_data["name"] = self.ui.name_entry.get_value()
-            self.app.collection.update_view()
-            if silent:
-                self.app.inform.emit('[success] %s: %s %s: %s' % (
-                    _("Name changed from"), str(old_name), _("to"), str(new_name)
-                )
-                                     )
-
-    def on_offset_button_click(self):
-        self.app.report_usage("obj_on_offset_button")
-
-        self.read_form()
-        vector_val = self.ui.offsetvector_entry.get_value()
-
-        def worker_task():
-            with self.app.proc_container.new(_("Offsetting...")):
-                self.offset(vector_val)
-            self.app.proc_container.update_view_text('')
-            with self.app.proc_container.new('%s...' % _("Plotting")):
-                self.plot()
-            self.app.object_changed.emit(self)
-
-        self.app.worker_task.emit({'fcn': worker_task, 'params': []})
-
-    def on_scale_button_click(self):
-        self.read_form()
-        try:
-            factor = float(eval(self.ui.scale_entry.get_value()))
-        except Exception as e:
-            self.app.inform.emit('[ERROR_NOTCL] %s' % _("Scaling could not be executed."))
-            log.debug("FlatCAMObj.on_scale_button_click() -- %s" % str(e))
-            return
-
-        if type(factor) != float:
-            self.app.inform.emit('[ERROR_NOTCL] %s' % _("Scaling could not be executed."))
-
-        # if factor is 1.0 do nothing, there is no point in scaling with a factor of 1.0
-        if factor == 1.0:
-            self.app.inform.emit('[success] %s' % _("Scale done."))
-            return
-
-        log.debug("FlatCAMObj.on_scale_button_click()")
-
-        def worker_task():
-            with self.app.proc_container.new(_("Scaling...")):
-                self.scale(factor)
-                self.app.inform.emit('[success] %s' % _("Scale done."))
-
-            self.app.proc_container.update_view_text('')
-            with self.app.proc_container.new('%s...' % _("Plotting")):
-                self.plot()
-            self.app.object_changed.emit(self)
-
-        self.app.worker_task.emit({'fcn': worker_task, 'params': []})
-
-    def on_skew_button_click(self):
-        self.app.report_usage("obj_on_skew_button")
-        self.read_form()
-        x_angle = self.ui.xangle_entry.get_value()
-        y_angle = self.ui.yangle_entry.get_value()
-
-        def worker_task():
-            with self.app.proc_container.new(_("Skewing...")):
-                self.skew(x_angle, y_angle)
-            self.app.proc_container.update_view_text('')
-            with self.app.proc_container.new('%s...' % _("Plotting")):
-                self.plot()
-            self.app.object_changed.emit(self)
-
-        self.app.worker_task.emit({'fcn': worker_task, 'params': []})
-
-    def to_form(self):
-        """
-        Copies options to the UI form.
-
-        :return: None
-        """
-        log.debug(str(inspect.stack()[1][3]) + " --> FlatCAMObj.to_form()")
-        for option in self.options:
-            try:
-                self.set_form_item(option)
-            except Exception:
-                self.app.log.warning("Unexpected error:", sys.exc_info())
-
-    def read_form(self):
-        """
-        Reads form into ``self.options``.
-
-        :return: None
-        :rtype: None
-        """
-        log.debug(str(inspect.stack()[1][3]) + "--> FlatCAMObj.read_form()")
-        for option in self.options:
-            try:
-                self.read_form_item(option)
-            except Exception:
-                self.app.log.warning("Unexpected error:", sys.exc_info())
-
-    def set_form_item(self, option):
-        """
-        Copies the specified option to the UI form.
-
-        :param option: Name of the option (Key in ``self.options``).
-        :type option: str
-        :return: None
-        """
-
-        try:
-            self.form_fields[option].set_value(self.options[option])
-        except KeyError:
-            # self.app.log.warn("Tried to set an option or field that does not exist: %s" % option)
-            pass
-
-    def read_form_item(self, option):
-        """
-        Reads the specified option from the UI form into ``self.options``.
-
-        :param option: Name of the option.
-        :type option: str
-        :return: None
-        """
-        try:
-            self.options[option] = self.form_fields[option].get_value()
-        except KeyError:
-            pass
-            # self.app.log.warning("Failed to read option from field: %s" % option)
-
-    def plot(self, kind=None):
-        """
-        Plot this object (Extend this method to implement the actual plotting).
-        Call this in descendants before doing the plotting.
-
-        :param kind:    Used by only some of the FlatCAM objects
-        :return:        Whether to continue plotting or not depending on the "plot" option. Boolean
-        """
-        log.debug(str(inspect.stack()[1][3]) + " --> FlatCAMObj.plot()")
-
-        if self.deleted:
-            return False
-
-        self.clear()
-        return True
-
-    def single_object_plot(self):
-        def plot_task():
-            with self.app.proc_container.new('%s...' % _("Plotting")):
-                self.plot()
-            self.app.object_changed.emit(self)
-
-        self.app.worker_task.emit({'fcn': plot_task, 'params': []})
-
-    def serialize(self):
-        """
-        Returns a representation of the object as a dictionary so
-        it can be later exported as JSON. Override this method.
-
-        :return: Dictionary representing the object
-        :rtype: dict
-        """
-        return
-
-    def deserialize(self, obj_dict):
-        """
-        Re-builds an object from its serialized version.
-
-        :param obj_dict: Dictionary representing a FlatCAMObj
-        :type obj_dict: dict
-        :return: None
-        """
-        return
-
-    def add_shape(self, **kwargs):
-        if self.deleted:
-            raise ObjectDeleted()
-        else:
-            key = self.shapes.add(tolerance=self.drawing_tolerance, **kwargs)
-        return key
-
-    def add_mark_shape(self, apid, **kwargs):
-        if self.deleted:
-            raise ObjectDeleted()
-        else:
-            key = self.mark_shapes[apid].add(tolerance=self.drawing_tolerance, layer=0, **kwargs)
-        return key
-
-    def update_filters(self, last_ext, filter_string):
-        """
-        Will modify the filter string that is used when saving a file (a list of file extensions) to have the last
-        used file extension as the first one in the special string
-
-        :param last_ext:        The file extension that was last used to save a file
-        :param filter_string:   A key in self.app.defaults that holds a string with the filter from QFileDialog
-        used when saving a file
-        :return:                None
-        """
-
-        filters = copy(self.app.defaults[filter_string])
-        filter_list = filters.split(';;')
-        filter_list_enum_1 = enumerate(filter_list)
-
-        # search for the last element in the filters which should always be "All Files (*.*)"
-        last_elem = ''
-        for elem in list(filter_list_enum_1):
-            if '(*.*)' in elem[1]:
-                last_elem = filter_list.pop(elem[0])
-
-        filter_list_enum = enumerate(filter_list)
-        for elem in list(filter_list_enum):
-            if '.' + last_ext in elem[1]:
-                used_ext = filter_list.pop(elem[0])
-
-                # sort the extensions back
-                filter_list.sort(key=lambda x: x.rpartition('.')[2])
-
-                # add as a first element the last used extension
-                filter_list.insert(0, used_ext)
-                # add back the element that should always be the last (All Files)
-                filter_list.append(last_elem)
-
-                self.app.defaults[filter_string] = ';;'.join(filter_list)
-                return
-
-    @staticmethod
-    def poly2rings(poly):
-        return [poly.exterior] + [interior for interior in poly.interiors]
-
-    @property
-    def visible(self):
-        return self.shapes.visible
-
-    @visible.setter
-    def visible(self, value, threaded=True):
-        log.debug("FlatCAMObj.visible()")
-
-        def worker_task(app_obj):
-            self.shapes.visible = value
-
-            if self.app.is_legacy is False:
-                # Not all object types has annotations
-                try:
-                    self.annotation.visible = value
-                except Exception:
-                    pass
-
-        if threaded is False:
-            worker_task(app_obj=self.app)
-        else:
-            self.app.worker_task.emit({'fcn': worker_task, 'params': [self]})
-
-    @property
-    def drawing_tolerance(self):
-        self.units = self.app.defaults['units'].upper()
-        tol = self._drawing_tolerance if self.units == 'MM' or not self.units else self._drawing_tolerance / 25.4
-        return tol
-
-    @drawing_tolerance.setter
-    def drawing_tolerance(self, value):
-        self.units = self.app.defaults['units'].upper()
-        self._drawing_tolerance = value if self.units == 'MM' or not self.units else value / 25.4
-
-    def clear(self, update=False):
-        self.shapes.clear(update)
-
-        # Not all object types has annotations
-        try:
-            self.annotation.clear(update)
-        except AttributeError:
-            pass
-
-    def delete(self):
-        # Free resources
-        del self.ui
-        del self.options
-
-        # Set flag
-        self.deleted = True
-
-
-class FlatCAMGerber(FlatCAMObj, Gerber):
-    """
-    Represents Gerber code.
-    """
-    optionChanged = QtCore.pyqtSignal(str)
-    replotApertures = QtCore.pyqtSignal()
-
-    ui_type = GerberObjectUI
-
-    def merge(self, grb_list, grb_final):
-        """
-        Merges the geometry of objects in geo_list into
-        the geometry of geo_final.
-
-        :param grb_list: List of FlatCAMGerber Objects to join.
-        :param grb_final: Destination FlatCAMGeometry object.
-        :return: None
-        """
-
-        if grb_final.solid_geometry is None:
-            grb_final.solid_geometry = []
-            grb_final.follow_geometry = []
-
-        if not grb_final.apertures:
-            grb_final.apertures = {}
-
-        if type(grb_final.solid_geometry) is not list:
-            grb_final.solid_geometry = [grb_final.solid_geometry]
-            grb_final.follow_geometry = [grb_final.follow_geometry]
-
-        for grb in grb_list:
-
-            # Expand lists
-            if type(grb) is list:
-                FlatCAMGerber.merge(grb, grb_final)
-            else:   # If not list, just append
-                for option in grb.options:
-                    if option != 'name':
-                        try:
-                            grb_final.options[option] = grb.options[option]
-                        except KeyError:
-                            log.warning("Failed to copy option.", option)
-
-                try:
-                    for geos in grb.solid_geometry:
-                        grb_final.solid_geometry.append(geos)
-                        grb_final.follow_geometry.append(geos)
-                except TypeError:
-                    grb_final.solid_geometry.append(grb.solid_geometry)
-                    grb_final.follow_geometry.append(grb.solid_geometry)
-
-                for ap in grb.apertures:
-                    if ap not in grb_final.apertures:
-                        grb_final.apertures[ap] = grb.apertures[ap]
-                    else:
-                        # create a list of integers out of the grb.apertures keys and find the max of that value
-                        # then, the aperture duplicate is assigned an id value incremented with 1,
-                        # and finally made string because the apertures dict keys are strings
-                        max_ap = str(max([int(k) for k in grb_final.apertures.keys()]) + 1)
-                        grb_final.apertures[max_ap] = {}
-                        grb_final.apertures[max_ap]['geometry'] = []
-
-                        for k, v in grb.apertures[ap].items():
-                            grb_final.apertures[max_ap][k] = deepcopy(v)
-
-        grb_final.solid_geometry = MultiPolygon(grb_final.solid_geometry)
-        grb_final.follow_geometry = MultiPolygon(grb_final.follow_geometry)
-
-    def __init__(self, name):
-        self.decimals = self.app.decimals
-
-        self.circle_steps = int(self.app.defaults["gerber_circle_steps"])
-
-        Gerber.__init__(self, steps_per_circle=self.circle_steps)
-        FlatCAMObj.__init__(self, name)
-
-        self.kind = "gerber"
-
-        # The 'name' is already in self.options from FlatCAMObj
-        # Automatically updates the UI
-        self.options.update({
-            "plot": True,
-            "multicolored": False,
-            "solid": False,
-            "tool_type": 'circular',
-            "vtipdia": 0.1,
-            "vtipangle": 30,
-            "vcutz": -0.05,
-            "isotooldia": 0.016,
-            "isopasses": 1,
-            "isooverlap": 15,
-            "milling_type": "cl",
-            "combine_passes": True,
-            "noncoppermargin": 0.0,
-            "noncopperrounded": False,
-            "bboxmargin": 0.0,
-            "bboxrounded": False,
-            "aperture_display": False,
-            "follow": False,
-            "iso_scope": 'all',
-            "iso_type": 'full'
-        })
-
-        # type of isolation: 0 = exteriors, 1 = interiors, 2 = complete isolation (both interiors and exteriors)
-        self.iso_type = 2
-
-        self.multigeo = False
-
-        self.follow = False
-
-        self.apertures_row = 0
-
-        # store the source file here
-        self.source_file = ""
-
-        # list of rows with apertures plotted
-        self.marked_rows = []
-
-        # Mouse events
-        self.mr = None
-        self.mm = None
-        self.mp = None
-
-        # dict to store the polygons selected for isolation; key is the shape added to be plotted and value is the poly
-        self.poly_dict = {}
-
-        # store the status of grid snapping
-        self.grid_status_memory = None
-
-        self.units_found = self.app.defaults['units']
-
-        self.fill_color = self.app.defaults['gerber_plot_fill']
-        self.outline_color = self.app.defaults['gerber_plot_line']
-        self.alpha_level = 'bf'
-
-        # keep track if the UI is built so we don't have to build it every time
-        self.ui_build = False
-
-        # build only once the aperture storage (takes time)
-        self.build_aperture_storage = False
-
-        # Attributes to be included in serialization
-        # Always append to it because it carries contents
-        # from predecessors.
-        self.ser_attrs += ['options', 'kind', 'fill_color', 'outline_color', 'alpha_level']
-
-    def set_ui(self, ui):
-        """
-        Maps options with GUI inputs.
-        Connects GUI events to methods.
-
-        :param ui: GUI object.
-        :type ui: GerberObjectUI
-        :return: None
-        """
-        FlatCAMObj.set_ui(self, ui)
-        log.debug("FlatCAMGerber.set_ui()")
-
-        self.units = self.app.defaults['units'].upper()
-
-        self.replotApertures.connect(self.on_mark_cb_click_table)
-
-        self.form_fields.update({
-            "plot": self.ui.plot_cb,
-            "multicolored": self.ui.multicolored_cb,
-            "solid": self.ui.solid_cb,
-            "tool_type": self.ui.tool_type_radio,
-            "vtipdia": self.ui.tipdia_spinner,
-            "vtipangle": self.ui.tipangle_spinner,
-            "vcutz": self.ui.cutz_spinner,
-            "isotooldia": self.ui.iso_tool_dia_entry,
-            "isopasses": self.ui.iso_width_entry,
-            "isooverlap": self.ui.iso_overlap_entry,
-            "milling_type": self.ui.milling_type_radio,
-            "combine_passes": self.ui.combine_passes_cb,
-            "noncoppermargin": self.ui.noncopper_margin_entry,
-            "noncopperrounded": self.ui.noncopper_rounded_cb,
-            "bboxmargin": self.ui.bbmargin_entry,
-            "bboxrounded": self.ui.bbrounded_cb,
-            "aperture_display": self.ui.aperture_table_visibility_cb,
-            "follow": self.ui.follow_cb,
-            "iso_scope": self.ui.iso_scope_radio,
-            "iso_type": self.ui.iso_type_radio
-        })
-
-        # Fill form fields only on object create
-        self.to_form()
-
-        assert isinstance(self.ui, GerberObjectUI)
-        self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
-        self.ui.solid_cb.stateChanged.connect(self.on_solid_cb_click)
-        self.ui.multicolored_cb.stateChanged.connect(self.on_multicolored_cb_click)
-        self.ui.generate_iso_button.clicked.connect(self.on_iso_button_click)
-        self.ui.generate_ncc_button.clicked.connect(self.app.ncclear_tool.run)
-        self.ui.generate_cutout_button.clicked.connect(self.app.cutout_tool.run)
-        self.ui.generate_bb_button.clicked.connect(self.on_generatebb_button_click)
-        self.ui.generate_noncopper_button.clicked.connect(self.on_generatenoncopper_button_click)
-        self.ui.aperture_table_visibility_cb.stateChanged.connect(self.on_aperture_table_visibility_change)
-        self.ui.follow_cb.stateChanged.connect(self.on_follow_cb_click)
-
-        # set the model for the Area Exception comboboxes
-        self.ui.obj_combo.setModel(self.app.collection)
-        self.ui.obj_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
-        self.ui.obj_combo.is_last = True
-        self.ui.obj_combo.obj_type = {
-            _("Gerber"): "Gerber", _("Geometry"): "Geometry"
-        }[self.ui.type_obj_combo.get_value()]
-        self.on_type_obj_index_changed()
-
-        self.ui.type_obj_combo.currentIndexChanged.connect(self.on_type_obj_index_changed)
-
-        self.ui.tool_type_radio.activated_custom.connect(self.on_tool_type_change)
-        # establish visibility for the GUI elements found in the slot function
-        self.ui.tool_type_radio.activated_custom.emit(self.options['tool_type'])
-
-        # Show/Hide Advanced Options
-        if self.app.defaults["global_app_level"] == 'b':
-            self.ui.level.setText('<span style="color:green;"><b>%s</b></span>' % _('Basic'))
-            self.options['tool_type'] = 'circular'
-
-            self.ui.tool_type_label.hide()
-            self.ui.tool_type_radio.hide()
-
-            # override the Preferences Value; in Basic mode the Tool Type is always Circular ('C1')
-            self.ui.tool_type_radio.set_value('circular')
-
-            self.ui.tipdialabel.hide()
-            self.ui.tipdia_spinner.hide()
-            self.ui.tipanglelabel.hide()
-            self.ui.tipangle_spinner.hide()
-            self.ui.cutzlabel.hide()
-            self.ui.cutz_spinner.hide()
-
-            self.ui.apertures_table_label.hide()
-            self.ui.aperture_table_visibility_cb.hide()
-            self.ui.milling_type_label.hide()
-            self.ui.milling_type_radio.hide()
-            self.ui.iso_type_label.hide()
-            self.ui.iso_type_radio.hide()
-
-            self.ui.follow_cb.hide()
-            self.ui.except_cb.setChecked(False)
-            self.ui.except_cb.hide()
-        else:
-            self.ui.level.setText('<span style="color:red;"><b>%s</b></span>' % _('Advanced'))
-            self.ui.tipdia_spinner.valueChanged.connect(self.on_calculate_tooldia)
-            self.ui.tipangle_spinner.valueChanged.connect(self.on_calculate_tooldia)
-            self.ui.cutz_spinner.valueChanged.connect(self.on_calculate_tooldia)
-
-        if self.app.defaults["gerber_buffering"] == 'no':
-            self.ui.create_buffer_button.show()
-            try:
-                self.ui.create_buffer_button.clicked.disconnect(self.on_generate_buffer)
-            except TypeError:
-                pass
-            self.ui.create_buffer_button.clicked.connect(self.on_generate_buffer)
-        else:
-            self.ui.create_buffer_button.hide()
-
-        # set initial state of the aperture table and associated widgets
-        self.on_aperture_table_visibility_change()
-
-        self.build_ui()
-        self.units_found = self.app.defaults['units']
-
-    def on_calculate_tooldia(self):
-        try:
-            tdia = float(self.ui.tipdia_spinner.get_value())
-        except Exception:
-            return
-        try:
-            dang = float(self.ui.tipangle_spinner.get_value())
-        except Exception:
-            return
-        try:
-            cutz = float(self.ui.cutz_spinner.get_value())
-        except Exception:
-            return
-
-        cutz *= -1
-        if cutz < 0:
-            cutz *= -1
-
-        half_tip_angle = dang / 2
-
-        tool_diameter = tdia + (2 * cutz * math.tan(math.radians(half_tip_angle)))
-        self.ui.iso_tool_dia_entry.set_value(tool_diameter)
-
-    def on_type_obj_index_changed(self):
-        val = self.ui.type_obj_combo.get_value()
-        obj_type = {"Gerber": 0, "Geometry": 2}[val]
-        self.ui.obj_combo.setRootModelIndex(self.app.collection.index(obj_type, 0, QtCore.QModelIndex()))
-        self.ui.obj_combo.setCurrentIndex(0)
-        self.ui.obj_combo.obj_type = {_("Gerber"): "Gerber", _("Geometry"): "Geometry"}[val]
-
-    def on_tool_type_change(self, state):
-        if state == 'circular':
-            self.ui.tipdialabel.hide()
-            self.ui.tipdia_spinner.hide()
-            self.ui.tipanglelabel.hide()
-            self.ui.tipangle_spinner.hide()
-            self.ui.cutzlabel.hide()
-            self.ui.cutz_spinner.hide()
-            self.ui.iso_tool_dia_entry.setDisabled(False)
-            # update the value in the self.iso_tool_dia_entry once this is selected
-            self.ui.iso_tool_dia_entry.set_value(self.options['isotooldia'])
-        else:
-            self.ui.tipdialabel.show()
-            self.ui.tipdia_spinner.show()
-            self.ui.tipanglelabel.show()
-            self.ui.tipangle_spinner.show()
-            self.ui.cutzlabel.show()
-            self.ui.cutz_spinner.show()
-            self.ui.iso_tool_dia_entry.setDisabled(True)
-            # update the value in the self.iso_tool_dia_entry once this is selected
-            self.on_calculate_tooldia()
-
-    def build_ui(self):
-        FlatCAMObj.build_ui(self)
-
-        if self.ui.aperture_table_visibility_cb.get_value() and self.ui_build is False:
-            self.ui_build = True
-
-            try:
-                # if connected, disconnect the signal from the slot on item_changed as it creates issues
-                self.ui.apertures_table.itemChanged.disconnect()
-            except (TypeError, AttributeError):
-                pass
-
-            self.apertures_row = 0
-            aper_no = self.apertures_row + 1
-            sort = []
-            for k, v in list(self.apertures.items()):
-                sort.append(int(k))
-            sorted_apertures = sorted(sort)
-
-            n = len(sorted_apertures)
-            self.ui.apertures_table.setRowCount(n)
-
-            for ap_code in sorted_apertures:
-                ap_code = str(ap_code)
-
-                ap_id_item = QtWidgets.QTableWidgetItem('%d' % int(self.apertures_row + 1))
-                ap_id_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
-                self.ui.apertures_table.setItem(self.apertures_row, 0, ap_id_item)  # Tool name/id
-
-                ap_code_item = QtWidgets.QTableWidgetItem(ap_code)
-                ap_code_item.setFlags(QtCore.Qt.ItemIsEnabled)
-
-                ap_type_item = QtWidgets.QTableWidgetItem(str(self.apertures[ap_code]['type']))
-                ap_type_item.setFlags(QtCore.Qt.ItemIsEnabled)
-
-                if str(self.apertures[ap_code]['type']) == 'R' or str(self.apertures[ap_code]['type']) == 'O':
-                    ap_dim_item = QtWidgets.QTableWidgetItem(
-                        '%.*f, %.*f' % (self.decimals, self.apertures[ap_code]['width'],
-                                        self.decimals, self.apertures[ap_code]['height']
-                                        )
-                    )
-                    ap_dim_item.setFlags(QtCore.Qt.ItemIsEnabled)
-                elif str(self.apertures[ap_code]['type']) == 'P':
-                    ap_dim_item = QtWidgets.QTableWidgetItem(
-                        '%.*f, %.*f' % (self.decimals, self.apertures[ap_code]['diam'],
-                                        self.decimals, self.apertures[ap_code]['nVertices'])
-                    )
-                    ap_dim_item.setFlags(QtCore.Qt.ItemIsEnabled)
-                else:
-                    ap_dim_item = QtWidgets.QTableWidgetItem('')
-                    ap_dim_item.setFlags(QtCore.Qt.ItemIsEnabled)
-
-                try:
-                    if self.apertures[ap_code]['size'] is not None:
-                        ap_size_item = QtWidgets.QTableWidgetItem(
-                            '%.*f' % (self.decimals, float(self.apertures[ap_code]['size'])))
-                    else:
-                        ap_size_item = QtWidgets.QTableWidgetItem('')
-                except KeyError:
-                    ap_size_item = QtWidgets.QTableWidgetItem('')
-                ap_size_item.setFlags(QtCore.Qt.ItemIsEnabled)
-
-                mark_item = FCCheckBox()
-                mark_item.setLayoutDirection(QtCore.Qt.RightToLeft)
-                # if self.ui.aperture_table_visibility_cb.isChecked():
-                #     mark_item.setChecked(True)
-
-                self.ui.apertures_table.setItem(self.apertures_row, 1, ap_code_item)  # Aperture Code
-                self.ui.apertures_table.setItem(self.apertures_row, 2, ap_type_item)  # Aperture Type
-                self.ui.apertures_table.setItem(self.apertures_row, 3, ap_size_item)   # Aperture Dimensions
-                self.ui.apertures_table.setItem(self.apertures_row, 4, ap_dim_item)   # Aperture Dimensions
-
-                empty_plot_item = QtWidgets.QTableWidgetItem('')
-                empty_plot_item.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
-                self.ui.apertures_table.setItem(self.apertures_row, 5, empty_plot_item)
-                self.ui.apertures_table.setCellWidget(self.apertures_row, 5, mark_item)
-
-                self.apertures_row += 1
-
-            self.ui.apertures_table.selectColumn(0)
-            self.ui.apertures_table.resizeColumnsToContents()
-            self.ui.apertures_table.resizeRowsToContents()
-
-            vertical_header = self.ui.apertures_table.verticalHeader()
-            # vertical_header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
-            vertical_header.hide()
-            self.ui.apertures_table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
-
-            horizontal_header = self.ui.apertures_table.horizontalHeader()
-            horizontal_header.setMinimumSectionSize(10)
-            horizontal_header.setDefaultSectionSize(70)
-            horizontal_header.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
-            horizontal_header.resizeSection(0, 27)
-            horizontal_header.setSectionResizeMode(1, QtWidgets.QHeaderView.ResizeToContents)
-            horizontal_header.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
-            horizontal_header.setSectionResizeMode(3, QtWidgets.QHeaderView.ResizeToContents)
-            horizontal_header.setSectionResizeMode(4,  QtWidgets.QHeaderView.Stretch)
-            horizontal_header.setSectionResizeMode(5, QtWidgets.QHeaderView.Fixed)
-            horizontal_header.resizeSection(5, 17)
-            self.ui.apertures_table.setColumnWidth(5, 17)
-
-            self.ui.apertures_table.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
-            self.ui.apertures_table.setSortingEnabled(False)
-            self.ui.apertures_table.setMinimumHeight(self.ui.apertures_table.getHeight())
-            self.ui.apertures_table.setMaximumHeight(self.ui.apertures_table.getHeight())
-
-            # update the 'mark' checkboxes state according with what is stored in the self.marked_rows list
-            if self.marked_rows:
-                for row in range(self.ui.apertures_table.rowCount()):
-                    try:
-                        self.ui.apertures_table.cellWidget(row, 5).set_value(self.marked_rows[row])
-                    except IndexError:
-                        pass
-
-            self.ui_connect()
-
-    def ui_connect(self):
-        for row in range(self.ui.apertures_table.rowCount()):
-            try:
-                self.ui.apertures_table.cellWidget(row, 5).clicked.disconnect(self.on_mark_cb_click_table)
-            except (TypeError, AttributeError):
-                pass
-            self.ui.apertures_table.cellWidget(row, 5).clicked.connect(self.on_mark_cb_click_table)
-
-        try:
-            self.ui.mark_all_cb.clicked.disconnect(self.on_mark_all_click)
-        except (TypeError, AttributeError):
-            pass
-        self.ui.mark_all_cb.clicked.connect(self.on_mark_all_click)
-
-    def ui_disconnect(self):
-        for row in range(self.ui.apertures_table.rowCount()):
-            try:
-                self.ui.apertures_table.cellWidget(row, 5).clicked.disconnect()
-            except (TypeError, AttributeError):
-                pass
-
-        try:
-            self.ui.mark_all_cb.clicked.disconnect(self.on_mark_all_click)
-        except (TypeError, AttributeError):
-            pass
-
-    def on_generate_buffer(self):
-        self.app.inform.emit('[WARNING_NOTCL] %s...' % _("Buffering solid geometry"))
-
-        def buffer_task():
-            with self.app.proc_container.new('%s...' % _("Buffering")):
-                if isinstance(self.solid_geometry, list):
-                    self.solid_geometry = MultiPolygon(self.solid_geometry)
-
-                self.solid_geometry = self.solid_geometry.buffer(0.0000001)
-                self.solid_geometry = self.solid_geometry.buffer(-0.0000001)
-                self.app.inform.emit('[success] %s.' % _("Done"))
-                self.plot_single_object.emit()
-
-        self.app.worker_task.emit({'fcn': buffer_task, 'params': []})
-
-    def on_generatenoncopper_button_click(self, *args):
-        self.app.report_usage("gerber_on_generatenoncopper_button")
-
-        self.read_form()
-        name = self.options["name"] + "_noncopper"
-
-        def geo_init(geo_obj, app_obj):
-            assert isinstance(geo_obj, FlatCAMGeometry)
-            if isinstance(self.solid_geometry, list):
-                try:
-                    self.solid_geometry = MultiPolygon(self.solid_geometry)
-                except Exception:
-                    self.solid_geometry = cascaded_union(self.solid_geometry)
-
-            bounding_box = self.solid_geometry.envelope.buffer(float(self.options["noncoppermargin"]))
-            if not self.options["noncopperrounded"]:
-                bounding_box = bounding_box.envelope
-            non_copper = bounding_box.difference(self.solid_geometry)
-
-            if non_copper is None or non_copper.is_empty:
-                self.app.inform.emit("[ERROR_NOTCL] %s" % _("Operation could not be done."))
-                return "fail"
-            geo_obj.solid_geometry = non_copper
-
-        self.app.new_object("geometry", name, geo_init)
-
-    def on_generatebb_button_click(self, *args):
-        self.app.report_usage("gerber_on_generatebb_button")
-        self.read_form()
-        name = self.options["name"] + "_bbox"
-
-        def geo_init(geo_obj, app_obj):
-            assert isinstance(geo_obj, FlatCAMGeometry)
-
-            if isinstance(self.solid_geometry, list):
-                try:
-                    self.solid_geometry = MultiPolygon(self.solid_geometry)
-                except Exception:
-                    self.solid_geometry = cascaded_union(self.solid_geometry)
-
-            # Bounding box with rounded corners
-            bounding_box = self.solid_geometry.envelope.buffer(float(self.options["bboxmargin"]))
-            if not self.options["bboxrounded"]:  # Remove rounded corners
-                bounding_box = bounding_box.envelope
-
-            if bounding_box is None or bounding_box.is_empty:
-                self.app.inform.emit("[ERROR_NOTCL] %s" % _("Operation could not be done."))
-                return "fail"
-            geo_obj.solid_geometry = bounding_box
-
-        self.app.new_object("geometry", name, geo_init)
-
-    def on_iso_button_click(self, *args):
-
-        obj = self.app.collection.get_active()
-
-        self.iso_type = 2
-        if self.ui.iso_type_radio.get_value() == 'ext':
-            self.iso_type = 0
-        if self.ui.iso_type_radio.get_value() == 'int':
-            self.iso_type = 1
-
-        def worker_task(iso_obj, app_obj):
-            with self.app.proc_container.new(_("Isolating...")):
-                if self.ui.follow_cb.get_value() is True:
-                    iso_obj.follow_geo()
-                    # in the end toggle the visibility of the origin object so we can see the generated Geometry
-                    iso_obj.ui.plot_cb.toggle()
-                else:
-                    app_obj.report_usage("gerber_on_iso_button")
-                    self.read_form()
-
-                    iso_scope = 'all' if self.ui.iso_scope_radio.get_value() == 'all' else 'single'
-                    self.isolate_handler(iso_type=self.iso_type, iso_scope=iso_scope)
-
-        self.app.worker_task.emit({'fcn': worker_task, 'params': [obj, self.app]})
-
-    def follow_geo(self, outname=None):
-        """
-        Creates a geometry object "following" the gerber paths.
-
-        :return: None
-        """
-
-        # default_name = self.options["name"] + "_follow"
-        # follow_name = outname or default_name
-
-        if outname is None:
-            follow_name = self.options["name"] + "_follow"
-        else:
-            follow_name = outname
-
-        def follow_init(follow_obj, app):
-            # Propagate options
-            follow_obj.options["cnctooldia"] = str(self.options["isotooldia"])
-            follow_obj.solid_geometry = self.follow_geometry
-
-        # TODO: Do something if this is None. Offer changing name?
-        try:
-            self.app.new_object("geometry", follow_name, follow_init)
-        except Exception as e:
-            return "Operation failed: %s" % str(e)
-
-    def isolate_handler(self, iso_type, iso_scope):
-
-        if iso_scope == 'all':
-            self.isolate(iso_type=iso_type)
-        else:
-            # disengage the grid snapping since it may be hard to click on polygons with grid snapping on
-            if self.app.ui.grid_snap_btn.isChecked():
-                self.grid_status_memory = True
-                self.app.ui.grid_snap_btn.trigger()
-            else:
-                self.grid_status_memory = False
-
-            self.mr = self.app.plotcanvas.graph_event_connect('mouse_release', self.on_mouse_click_release)
-
-            if self.app.is_legacy is False:
-                self.app.plotcanvas.graph_event_disconnect('mouse_release', self.app.on_mouse_click_release_over_plot)
-            else:
-                self.app.plotcanvas.graph_event_disconnect(self.app.mr)
-
-            self.app.inform.emit('[WARNING_NOTCL] %s' % _("Click on a polygon to isolate it."))
-
-    def on_mouse_click_release(self, event):
-        if self.app.is_legacy is False:
-            event_pos = event.pos
-            right_button = 2
-            self.app.event_is_dragging = self.app.event_is_dragging
-        else:
-            event_pos = (event.xdata, event.ydata)
-            right_button = 3
-            self.app.event_is_dragging = self.app.ui.popMenu.mouse_is_panning
-
-        try:
-            x = float(event_pos[0])
-            y = float(event_pos[1])
-        except TypeError:
-            return
-
-        event_pos = (x, y)
-        curr_pos = self.app.plotcanvas.translate_coords(event_pos)
-        if self.app.grid_status():
-            curr_pos = self.app.geo_editor.snap(curr_pos[0], curr_pos[1])
-        else:
-            curr_pos = (curr_pos[0], curr_pos[1])
-
-        if event.button == 1:
-            clicked_poly = self.find_polygon(point=(curr_pos[0], curr_pos[1]))
-
-            if self.app.selection_type is not None:
-                self.selection_area_handler(self.app.pos, curr_pos, self.app.selection_type)
-                self.app.selection_type = None
-            elif clicked_poly:
-                if clicked_poly not in self.poly_dict.values():
-                    shape_id = self.app.tool_shapes.add(tolerance=self.drawing_tolerance, layer=0, shape=clicked_poly,
-                                                        color=self.app.defaults['global_sel_draw_color'] + 'AF',
-                                                        face_color=self.app.defaults['global_sel_draw_color'] + 'AF',
-                                                        visible=True)
-                    self.poly_dict[shape_id] = clicked_poly
-                    self.app.inform.emit(
-                        '%s: %d. %s' % (_("Added polygon"), int(len(self.poly_dict)),
-                                        _("Click to add next polygon or right click to start isolation."))
-                    )
-                else:
-                    try:
-                        for k, v in list(self.poly_dict.items()):
-                            if v == clicked_poly:
-                                self.app.tool_shapes.remove(k)
-                                self.poly_dict.pop(k)
-                                break
-                    except TypeError:
-                        return
-                    self.app.inform.emit(
-                        '%s. %s' % (_("Removed polygon"),
-                                    _("Click to add/remove next polygon or right click to start isolation."))
-                    )
-
-                self.app.tool_shapes.redraw()
-            else:
-                self.app.inform.emit(_("No polygon detected under click position."))
-        elif event.button == right_button and self.app.event_is_dragging is False:
-            # restore the Grid snapping if it was active before
-            if self.grid_status_memory is True:
-                self.app.ui.grid_snap_btn.trigger()
-
-            if self.app.is_legacy is False:
-                self.app.plotcanvas.graph_event_disconnect('mouse_release', self.on_mouse_click_release)
-            else:
-                self.app.plotcanvas.graph_event_disconnect(self.mr)
-
-            self.app.mr = self.app.plotcanvas.graph_event_connect('mouse_release',
-                                                                  self.app.on_mouse_click_release_over_plot)
-
-            self.app.tool_shapes.clear(update=True)
-
-            if self.poly_dict:
-                poly_list = deepcopy(list(self.poly_dict.values()))
-                self.isolate(iso_type=self.iso_type, geometry=poly_list)
-                self.poly_dict.clear()
-            else:
-                self.app.inform.emit('[ERROR_NOTCL] %s' % _("List of single polygons is empty. Aborting."))
-
-    def selection_area_handler(self, start_pos, end_pos, sel_type):
-        """
-        :param start_pos: mouse position when the selection LMB click was done
-        :param end_pos: mouse position when the left mouse button is released
-        :param sel_type: if True it's a left to right selection (enclosure), if False it's a 'touch' selection
-        :return:
-        """
-        poly_selection = Polygon([start_pos, (end_pos[0], start_pos[1]), end_pos, (start_pos[0], end_pos[1])])
-
-        # delete previous selection shape
-        self.app.delete_selection_shape()
-
-        added_poly_count = 0
-        try:
-            for geo in self.solid_geometry:
-                if geo not in self.poly_dict.values():
-                    if sel_type is True:
-                        if geo.within(poly_selection):
-                            shape_id = self.app.tool_shapes.add(tolerance=self.drawing_tolerance, layer=0,
-                                                                shape=geo,
-                                                                color=self.app.defaults['global_sel_draw_color'] + 'AF',
-                                                                face_color=self.app.defaults[
-                                                                               'global_sel_draw_color'] + 'AF',
-                                                                visible=True)
-                            self.poly_dict[shape_id] = geo
-                            added_poly_count += 1
-                    else:
-                        if poly_selection.intersects(geo):
-                            shape_id = self.app.tool_shapes.add(tolerance=self.drawing_tolerance, layer=0,
-                                                                shape=geo,
-                                                                color=self.app.defaults['global_sel_draw_color'] + 'AF',
-                                                                face_color=self.app.defaults[
-                                                                               'global_sel_draw_color'] + 'AF',
-                                                                visible=True)
-                            self.poly_dict[shape_id] = geo
-                            added_poly_count += 1
-        except TypeError:
-            if self.solid_geometry not in self.poly_dict.values():
-                if sel_type is True:
-                    if self.solid_geometry.within(poly_selection):
-                        shape_id = self.app.tool_shapes.add(tolerance=self.drawing_tolerance, layer=0,
-                                                            shape=self.solid_geometry,
-                                                            color=self.app.defaults['global_sel_draw_color'] + 'AF',
-                                                            face_color=self.app.defaults[
-                                                                           'global_sel_draw_color'] + 'AF',
-                                                            visible=True)
-                        self.poly_dict[shape_id] = self.solid_geometry
-                        added_poly_count += 1
-                else:
-                    if poly_selection.intersects(self.solid_geometry):
-                        shape_id = self.app.tool_shapes.add(tolerance=self.drawing_tolerance, layer=0,
-                                                            shape=self.solid_geometry,
-                                                            color=self.app.defaults['global_sel_draw_color'] + 'AF',
-                                                            face_color=self.app.defaults[
-                                                                           'global_sel_draw_color'] + 'AF',
-                                                            visible=True)
-                        self.poly_dict[shape_id] = self.solid_geometry
-                        added_poly_count += 1
-
-        if added_poly_count > 0:
-            self.app.tool_shapes.redraw()
-            self.app.inform.emit(
-                '%s: %d. %s' % (_("Added polygon"),
-                                int(added_poly_count),
-                                _("Click to add next polygon or right click to start isolation."))
-            )
-        else:
-            self.app.inform.emit(_("No polygon in selection."))
-
-    def isolate(self, iso_type=None, geometry=None, dia=None, passes=None, overlap=None, outname=None, combine=None,
-                milling_type=None, follow=None, plot=True):
-        """
-        Creates an isolation routing geometry object in the project.
-
-        :param iso_type: type of isolation to be done: 0 = exteriors, 1 = interiors and 2 = both
-        :param geometry: specific geometry to isolate
-        :param dia: Tool diameter
-        :param passes: Number of tool widths to cut
-        :param overlap: Overlap between passes in fraction of tool diameter
-        :param outname: Base name of the output object
-        :param combine: Boolean: if to combine passes in one resulting object in case of multiple passes
-        :param milling_type: type of milling: conventional or climbing
-        :param follow: Boolean: if to generate a 'follow' geometry
-        :param plot: Boolean: if to plot the resulting geometry object
-        :return: None
-        """
-
-        if geometry is None:
-            work_geo = self.follow_geometry if follow is True else self.solid_geometry
-        else:
-            work_geo = geometry
-
-        if dia is None:
-            dia = float(self.options["isotooldia"])
-
-        if passes is None:
-            passes = int(self.options["isopasses"])
-
-        if overlap is None:
-            overlap = float(self.options["isooverlap"])
-
-        overlap /= 100.0
-
-        combine = self.options["combine_passes"] if combine is None else bool(combine)
-
-        if milling_type is None:
-            milling_type = self.options["milling_type"]
-
-        if iso_type is None:
-            iso_t = 2
-        else:
-            iso_t = iso_type
-
-        base_name = self.options["name"]
-
-        if combine:
-            if outname is None:
-                if self.iso_type == 0:
-                    iso_name = base_name + "_ext_iso"
-                elif self.iso_type == 1:
-                    iso_name = base_name + "_int_iso"
-                else:
-                    iso_name = base_name + "_iso"
-            else:
-                iso_name = outname
-
-            def iso_init(geo_obj, app_obj):
-                # Propagate options
-                geo_obj.options["cnctooldia"] = str(self.options["isotooldia"])
-                geo_obj.tool_type = self.ui.tool_type_radio.get_value().upper()
-
-                geo_obj.solid_geometry = []
-
-                # transfer the Cut Z and Vtip and VAngle values in case that we use the V-Shape tool in Gerber UI
-                if self.ui.tool_type_radio.get_value() == 'v':
-                    new_cutz = self.ui.cutz_spinner.get_value()
-                    new_vtipdia = self.ui.tipdia_spinner.get_value()
-                    new_vtipangle = self.ui.tipangle_spinner.get_value()
-                    tool_type = 'V'
-                else:
-                    new_cutz = self.app.defaults['geometry_cutz']
-                    new_vtipdia = self.app.defaults['geometry_vtipdia']
-                    new_vtipangle = self.app.defaults['geometry_vtipangle']
-                    tool_type = 'C1'
-
-                # store here the default data for Geometry Data
-                default_data = {}
-                default_data.update({
-                    "name": iso_name,
-                    "plot": self.app.defaults['geometry_plot'],
-                    "cutz": new_cutz,
-                    "vtipdia": new_vtipdia,
-                    "vtipangle": new_vtipangle,
-                    "travelz": self.app.defaults['geometry_travelz'],
-                    "feedrate": self.app.defaults['geometry_feedrate'],
-                    "feedrate_z": self.app.defaults['geometry_feedrate_z'],
-                    "feedrate_rapid": self.app.defaults['geometry_feedrate_rapid'],
-                    "dwell": self.app.defaults['geometry_dwell'],
-                    "dwelltime": self.app.defaults['geometry_dwelltime'],
-                    "multidepth": self.app.defaults['geometry_multidepth'],
-                    "ppname_g": self.app.defaults['geometry_ppname_g'],
-                    "depthperpass": self.app.defaults['geometry_depthperpass'],
-                    "extracut": self.app.defaults['geometry_extracut'],
-                    "extracut_length": self.app.defaults['geometry_extracut_length'],
-                    "toolchange": self.app.defaults['geometry_toolchange'],
-                    "toolchangez": self.app.defaults['geometry_toolchangez'],
-                    "endz": self.app.defaults['geometry_endz'],
-                    "spindlespeed": self.app.defaults['geometry_spindlespeed'],
-                    "toolchangexy": self.app.defaults['geometry_toolchangexy'],
-                    "startz": self.app.defaults['geometry_startz']
-                })
-
-                geo_obj.tools = {}
-                geo_obj.tools['1'] = {}
-                geo_obj.tools.update({
-                    '1': {
-                        'tooldia': float(self.options["isotooldia"]),
-                        'offset': 'Path',
-                        'offset_value': 0.0,
-                        'type': _('Rough'),
-                        'tool_type': tool_type,
-                        'data': default_data,
-                        'solid_geometry': geo_obj.solid_geometry
-                    }
-                })
-
-                for nr_pass in range(passes):
-                    iso_offset = dia * ((2 * nr_pass + 1) / 2.0) - (nr_pass * overlap * dia)
-
-                    # if milling type is climb then the move is counter-clockwise around features
-                    mill_dir = 1 if milling_type == 'cl' else 0
-                    geom = self.generate_envelope(iso_offset, mill_dir, geometry=work_geo, env_iso_type=iso_t,
-                                                  follow=follow, nr_passes=nr_pass)
-
-                    if geom == 'fail':
-                        app_obj.inform.emit('[ERROR_NOTCL] %s' % _("Isolation geometry could not be generated."))
-                        return 'fail'
-                    geo_obj.solid_geometry.append(geom)
-
-                    # update the geometry in the tools
-                    geo_obj.tools['1']['solid_geometry'] = geo_obj.solid_geometry
-
-                # detect if solid_geometry is empty and this require list flattening which is "heavy"
-                # or just looking in the lists (they are one level depth) and if any is not empty
-                # proceed with object creation, if there are empty and the number of them is the length
-                # of the list then we have an empty solid_geometry which should raise a Custom Exception
-                empty_cnt = 0
-                if not isinstance(geo_obj.solid_geometry, list) and \
-                        not isinstance(geo_obj.solid_geometry, MultiPolygon):
-                    geo_obj.solid_geometry = [geo_obj.solid_geometry]
-
-                for g in geo_obj.solid_geometry:
-                    if g:
-                        break
-                    else:
-                        empty_cnt += 1
-
-                if empty_cnt == len(geo_obj.solid_geometry):
-                    raise ValidationError("Empty Geometry", None)
-                else:
-                    app_obj.inform.emit('[success] %s" %s' % (_("Isolation geometry created"), geo_obj.options["name"]))
-
-                # even if combine is checked, one pass is still single-geo
-                geo_obj.multigeo = True if passes > 1 else False
-
-                # ############################################################
-                # ########## AREA SUBTRACTION ################################
-                # ############################################################
-                if self.ui.except_cb.get_value():
-                    self.app.proc_container.update_view_text(' %s' % _("Subtracting Geo"))
-                    geo_obj.solid_geometry = self.area_subtraction(geo_obj.solid_geometry)
-
-            # TODO: Do something if this is None. Offer changing name?
-            self.app.new_object("geometry", iso_name, iso_init, plot=plot)
-        else:
-            for i in range(passes):
-
-                offset = dia * ((2 * i + 1) / 2.0) - (i * overlap * dia)
-                if passes > 1:
-                    if outname is None:
-                        if self.iso_type == 0:
-                            iso_name = base_name + "_ext_iso" + str(i + 1)
-                        elif self.iso_type == 1:
-                            iso_name = base_name + "_int_iso" + str(i + 1)
-                        else:
-                            iso_name = base_name + "_iso" + str(i + 1)
-                    else:
-                        iso_name = outname
-                else:
-                    if outname is None:
-                        if self.iso_type == 0:
-                            iso_name = base_name + "_ext_iso"
-                        elif self.iso_type == 1:
-                            iso_name = base_name + "_int_iso"
-                        else:
-                            iso_name = base_name + "_iso"
-                    else:
-                        iso_name = outname
-
-                def iso_init(geo_obj, app_obj):
-                    # Propagate options
-                    geo_obj.options["cnctooldia"] = str(self.options["isotooldia"])
-                    if self.ui.tool_type_radio.get_value() == 'v':
-                        geo_obj.tool_type = 'V'
-                    else:
-                        geo_obj.tool_type = 'C1'
-
-                    # if milling type is climb then the move is counter-clockwise around features
-                    mill_dir = 1 if milling_type == 'cl' else 0
-                    geom = self.generate_envelope(offset, mill_dir, geometry=work_geo, env_iso_type=iso_t,
-                                                  follow=follow,
-                                                  nr_passes=i)
-
-                    if geom == 'fail':
-                        app_obj.inform.emit('[ERROR_NOTCL] %s' % _("Isolation geometry could not be generated."))
-                        return 'fail'
-
-                    geo_obj.solid_geometry = geom
-
-                    # transfer the Cut Z and Vtip and VAngle values in case that we use the V-Shape tool in Gerber UI
-                    # even if the resulting geometry is not multigeo we add the tools dict which will hold the data
-                    # required to be transfered to the Geometry object
-                    if self.ui.tool_type_radio.get_value() == 'v':
-                        new_cutz = self.ui.cutz_spinner.get_value()
-                        new_vtipdia = self.ui.tipdia_spinner.get_value()
-                        new_vtipangle = self.ui.tipangle_spinner.get_value()
-                        tool_type = 'V'
-                    else:
-                        new_cutz = self.app.defaults['geometry_cutz']
-                        new_vtipdia = self.app.defaults['geometry_vtipdia']
-                        new_vtipangle = self.app.defaults['geometry_vtipangle']
-                        tool_type = 'C1'
-
-                    # store here the default data for Geometry Data
-                    default_data = {}
-                    default_data.update({
-                        "name": iso_name,
-                        "plot": self.app.defaults['geometry_plot'],
-                        "cutz": new_cutz,
-                        "vtipdia": new_vtipdia,
-                        "vtipangle": new_vtipangle,
-                        "travelz": self.app.defaults['geometry_travelz'],
-                        "feedrate": self.app.defaults['geometry_feedrate'],
-                        "feedrate_z": self.app.defaults['geometry_feedrate_z'],
-                        "feedrate_rapid": self.app.defaults['geometry_feedrate_rapid'],
-                        "dwell": self.app.defaults['geometry_dwell'],
-                        "dwelltime": self.app.defaults['geometry_dwelltime'],
-                        "multidepth": self.app.defaults['geometry_multidepth'],
-                        "ppname_g": self.app.defaults['geometry_ppname_g'],
-                        "depthperpass": self.app.defaults['geometry_depthperpass'],
-                        "extracut": self.app.defaults['geometry_extracut'],
-                        "extracut_length": self.app.defaults['geometry_extracut_length'],
-                        "toolchange": self.app.defaults['geometry_toolchange'],
-                        "toolchangez": self.app.defaults['geometry_toolchangez'],
-                        "endz": self.app.defaults['geometry_endz'],
-                        "spindlespeed": self.app.defaults['geometry_spindlespeed'],
-                        "toolchangexy": self.app.defaults['geometry_toolchangexy'],
-                        "startz": self.app.defaults['geometry_startz']
-                    })
-
-                    geo_obj.tools = {}
-                    geo_obj.tools['1'] = {}
-                    geo_obj.tools.update({
-                        '1': {
-                            'tooldia': float(self.options["isotooldia"]),
-                            'offset': 'Path',
-                            'offset_value': 0.0,
-                            'type': _('Rough'),
-                            'tool_type': tool_type,
-                            'data': default_data,
-                            'solid_geometry': geo_obj.solid_geometry
-                        }
-                    })
-
-                    # detect if solid_geometry is empty and this require list flattening which is "heavy"
-                    # or just looking in the lists (they are one level depth) and if any is not empty
-                    # proceed with object creation, if there are empty and the number of them is the length
-                    # of the list then we have an empty solid_geometry which should raise a Custom Exception
-                    empty_cnt = 0
-                    if not isinstance(geo_obj.solid_geometry, list):
-                        geo_obj.solid_geometry = [geo_obj.solid_geometry]
-
-                    for g in geo_obj.solid_geometry:
-                        if g:
-                            break
-                        else:
-                            empty_cnt += 1
-
-                    if empty_cnt == len(geo_obj.solid_geometry):
-                        raise ValidationError("Empty Geometry", None)
-                    else:
-                        app_obj.inform.emit('[success] %s: %s' %
-                                            (_("Isolation geometry created"), geo_obj.options["name"]))
-                    geo_obj.multigeo = False
-
-                    # ############################################################
-                    # ########## AREA SUBTRACTION ################################
-                    # ############################################################
-                    if self.ui.except_cb.get_value():
-                        self.app.proc_container.update_view_text(' %s' % _("Subtracting Geo"))
-                        geo_obj.solid_geometry = self.area_subtraction(geo_obj.solid_geometry)
-
-                # TODO: Do something if this is None. Offer changing name?
-                self.app.new_object("geometry", iso_name, iso_init, plot=plot)
-
-    def generate_envelope(self, offset, invert, geometry=None, env_iso_type=2, follow=None, nr_passes=0):
-        # isolation_geometry produces an envelope that is going on the left of the geometry
-        # (the copper features). To leave the least amount of burrs on the features
-        # the tool needs to travel on the right side of the features (this is called conventional milling)
-        # the first pass is the one cutting all of the features, so it needs to be reversed
-        # the other passes overlap preceding ones and cut the left over copper. It is better for them
-        # to cut on the right side of the left over copper i.e on the left side of the features.
-
-        if follow:
-            geom = self.isolation_geometry(offset, geometry=geometry, follow=follow)
-        else:
-            try:
-                geom = self.isolation_geometry(offset, geometry=geometry, iso_type=env_iso_type, passes=nr_passes)
-            except Exception as e:
-                log.debug('FlatCAMGerber.isolate().generate_envelope() --> %s' % str(e))
-                return 'fail'
-
-        if invert:
-            try:
-                pl = []
-                for p in geom:
-                    if p is not None:
-                        if isinstance(p, Polygon):
-                            pl.append(Polygon(p.exterior.coords[::-1], p.interiors))
-                        elif isinstance(p, LinearRing):
-                            pl.append(Polygon(p.coords[::-1]))
-                geom = MultiPolygon(pl)
-            except TypeError:
-                if isinstance(geom, Polygon) and geom is not None:
-                    geom = Polygon(geom.exterior.coords[::-1], geom.interiors)
-                elif isinstance(geom, LinearRing) and geom is not None:
-                    geom = Polygon(geom.coords[::-1])
-                else:
-                    log.debug("FlatCAMGerber.isolate().generate_envelope() Error --> Unexpected Geometry %s" %
-                              type(geom))
-            except Exception as e:
-                log.debug("FlatCAMGerber.isolate().generate_envelope() Error --> %s" % str(e))
-                return 'fail'
-        return geom
-
-    def area_subtraction(self, geo, subtractor_geo=None):
-        """
-        Subtracts the subtractor_geo (if present else self.solid_geometry) from the geo
-
-        :param geo: target geometry from which to subtract
-        :param subtractor_geo: geometry that acts as subtractor
-        :return:
-        """
-        new_geometry = []
-        target_geo = geo
-
-        if subtractor_geo:
-            sub_union = cascaded_union(subtractor_geo)
-        else:
-            name = self.ui.obj_combo.currentText()
-            subtractor_obj = self.app.collection.get_by_name(name)
-            sub_union = cascaded_union(subtractor_obj.solid_geometry)
-
-        try:
-            for geo_elem in target_geo:
-                if isinstance(geo_elem, Polygon):
-                    for ring in self.poly2rings(geo_elem):
-                        new_geo = ring.difference(sub_union)
-                        if new_geo and not new_geo.is_empty:
-                            new_geometry.append(new_geo)
-                elif isinstance(geo_elem, MultiPolygon):
-                    for poly in geo_elem:
-                        for ring in self.poly2rings(poly):
-                            new_geo = ring.difference(sub_union)
-                            if new_geo and not new_geo.is_empty:
-                                new_geometry.append(new_geo)
-                elif isinstance(geo_elem, LineString):
-                    new_geo = geo_elem.difference(sub_union)
-                    if new_geo:
-                        if not new_geo.is_empty:
-                            new_geometry.append(new_geo)
-                elif isinstance(geo_elem, MultiLineString):
-                    for line_elem in geo_elem:
-                        new_geo = line_elem.difference(sub_union)
-                        if new_geo and not new_geo.is_empty:
-                            new_geometry.append(new_geo)
-        except TypeError:
-            if isinstance(target_geo, Polygon):
-                for ring in self.poly2rings(target_geo):
-                    new_geo = ring.difference(sub_union)
-                    if new_geo:
-                        if not new_geo.is_empty:
-                            new_geometry.append(new_geo)
-            elif isinstance(target_geo, LineString):
-                new_geo = target_geo.difference(sub_union)
-                if new_geo and not new_geo.is_empty:
-                    new_geometry.append(new_geo)
-            elif isinstance(target_geo, MultiLineString):
-                for line_elem in target_geo:
-                    new_geo = line_elem.difference(sub_union)
-                    if new_geo and not new_geo.is_empty:
-                        new_geometry.append(new_geo)
-        return new_geometry
-
-    def on_plot_cb_click(self, *args):
-        if self.muted_ui:
-            return
-        self.read_form_item('plot')
-        self.plot()
-
-    def on_solid_cb_click(self, *args):
-        if self.muted_ui:
-            return
-        self.read_form_item('solid')
-        self.plot()
-
-    def on_multicolored_cb_click(self, *args):
-        if self.muted_ui:
-            return
-        self.read_form_item('multicolored')
-        self.plot()
-
-    def on_follow_cb_click(self):
-        if self.muted_ui:
-            return
-        self.plot()
-
-    def on_aperture_table_visibility_change(self):
-        if self.ui.aperture_table_visibility_cb.isChecked():
-            # add the shapes storage for marking apertures
-            if self.build_aperture_storage is False:
-                self.build_aperture_storage = True
-
-                if self.app.is_legacy is False:
-                    for ap_code in self.apertures:
-                        self.mark_shapes[ap_code] = self.app.plotcanvas.new_shape_collection(layers=1)
-                else:
-                    for ap_code in self.apertures:
-                        self.mark_shapes[ap_code] = ShapeCollectionLegacy(obj=self, app=self.app,
-                                                                          name=self.options['name'] + str(ap_code))
-
-            self.ui.apertures_table.setVisible(True)
-            for ap in self.mark_shapes:
-                self.mark_shapes[ap].enabled = True
-
-            self.ui.mark_all_cb.setVisible(True)
-            self.ui.mark_all_cb.setChecked(False)
-            self.build_ui()
-        else:
-            self.ui.apertures_table.setVisible(False)
-
-            self.ui.mark_all_cb.setVisible(False)
-
-            # on hide disable all mark plots
-            try:
-                for row in range(self.ui.apertures_table.rowCount()):
-                    self.ui.apertures_table.cellWidget(row, 5).set_value(False)
-                self.clear_plot_apertures()
-
-                # for ap in list(self.mark_shapes.keys()):
-                #     # self.mark_shapes[ap].enabled = False
-                #     del self.mark_shapes[ap]
-            except Exception as e:
-                log.debug(" FlatCAMGerber.on_aperture_visibility_changed() --> %s" % str(e))
-
-    def convert_units(self, units):
-        """
-        Converts the units of the object by scaling dimensions in all geometry
-        and options.
-
-        :param units: Units to which to convert the object: "IN" or "MM".
-        :type units: str
-        :return: None
-        :rtype: None
-        """
-
-        # units conversion to get a conversion should be done only once even if we found multiple
-        # units declaration inside a Gerber file (it can happen to find also the obsolete declaration)
-        if self.conversion_done is True:
-            log.debug("Gerber units conversion cancelled. Already done.")
-            return
-
-        log.debug("FlatCAMObj.FlatCAMGerber.convert_units()")
-
-        factor = Gerber.convert_units(self, units)
-
-        # self.options['isotooldia'] = float(self.options['isotooldia']) * factor
-        # self.options['bboxmargin'] = float(self.options['bboxmargin']) * factor
-
-    def plot(self, kind=None, **kwargs):
-        """
-
-        :param kind:    Not used, for compatibility with the plot method for other objects
-        :param kwargs:  Color and face_color, visible
-        :return:
-        """
-        log.debug(str(inspect.stack()[1][3]) + " --> FlatCAMGerber.plot()")
-
-        # Does all the required setup and returns False
-        # if the 'ptint' option is set to False.
-        if not FlatCAMObj.plot(self):
-            return
-
-        if 'color' in kwargs:
-            color = kwargs['color']
-        else:
-            color = self.outline_color
-
-        if 'face_color' in kwargs:
-            face_color = kwargs['face_color']
-        else:
-            face_color = self.fill_color
-
-        if 'visible' not in kwargs:
-            visible = self.options['plot']
-        else:
-            visible = kwargs['visible']
-
-        # if the Follow Geometry checkbox is checked then plot only the follow geometry
-        if self.ui.follow_cb.get_value():
-            geometry = self.follow_geometry
-        else:
-            geometry = self.solid_geometry
-
-        # Make sure geometry is iterable.
-        try:
-            __ = iter(geometry)
-        except TypeError:
-            geometry = [geometry]
-
-        if self.app.is_legacy is False:
-            def random_color():
-                r_color = np.random.rand(4)
-                r_color[3] = 1
-                return r_color
-        else:
-            def random_color():
-                while True:
-                    r_color = np.random.rand(4)
-                    r_color[3] = 1
-
-                    new_color = '#'
-                    for idx in range(len(r_color)):
-                        new_color += '%x' % int(r_color[idx] * 255)
-                    # do it until a valid color is generated
-                    # a valid color has the # symbol, another 6 chars for the color and the last 2 chars for alpha
-                    # for a total of 9 chars
-                    if len(new_color) == 9:
-                        break
-                return new_color
-
-        try:
-            if self.options["solid"]:
-                for g in geometry:
-                    if type(g) == Polygon or type(g) == LineString:
-                        self.add_shape(shape=g, color=color,
-                                       face_color=random_color() if self.options['multicolored']
-                                       else face_color, visible=visible)
-                    elif type(g) == Point:
-                        pass
-                    else:
-                        try:
-                            for el in g:
-                                self.add_shape(shape=el, color=color,
-                                               face_color=random_color() if self.options['multicolored']
-                                               else face_color, visible=visible)
-                        except TypeError:
-                            self.add_shape(shape=g, color=color,
-                                           face_color=random_color() if self.options['multicolored']
-                                           else face_color, visible=visible)
-            else:
-                for g in geometry:
-                    if type(g) == Polygon or type(g) == LineString:
-                        self.add_shape(shape=g, color=random_color() if self.options['multicolored'] else 'black',
-                                       visible=visible)
-                    elif type(g) == Point:
-                        pass
-                    else:
-                        for el in g:
-                            self.add_shape(shape=el, color=random_color() if self.options['multicolored'] else 'black',
-                                           visible=visible)
-            self.shapes.redraw(
-                # update_colors=(self.fill_color, self.outline_color),
-                # indexes=self.app.plotcanvas.shape_collection.data.keys()
-            )
-        except (ObjectDeleted, AttributeError):
-            self.shapes.clear(update=True)
-        except Exception as e:
-            log.debug("FlatCAMGerber.plot() --> %s" % str(e))
-
-    # experimental plot() when the solid_geometry is stored in the self.apertures
-    def plot_aperture(self, run_thread=True, **kwargs):
-        """
-
-        :param run_thread: if True run the aperture plot as a thread in a worker
-        :param kwargs: color and face_color
-        :return:
-        """
-
-        log.debug(str(inspect.stack()[1][3]) + " --> FlatCAMGerber.plot_aperture()")
-
-        # Does all the required setup and returns False
-        # if the 'ptint' option is set to False.
-        # if not FlatCAMObj.plot(self):
-        #     return
-
-        # for marking apertures, line color and fill color are the same
-        if 'color' in kwargs:
-            color = kwargs['color']
-        else:
-            color = self.app.defaults['gerber_plot_fill']
-
-        if 'marked_aperture' not in kwargs:
-            return
-        else:
-            aperture_to_plot_mark = kwargs['marked_aperture']
-            if aperture_to_plot_mark is None:
-                return
-
-        if 'visible' not in kwargs:
-            visibility = True
-        else:
-            visibility = kwargs['visible']
-
-        with self.app.proc_container.new(_("Plotting Apertures")):
-
-            def job_thread(app_obj):
-                try:
-                    if aperture_to_plot_mark in self.apertures:
-                        for elem in self.apertures[aperture_to_plot_mark]['geometry']:
-                            if 'solid' in elem:
-                                geo = elem['solid']
-                                if type(geo) == Polygon or type(geo) == LineString:
-                                    self.add_mark_shape(apid=aperture_to_plot_mark, shape=geo, color=color,
-                                                        face_color=color, visible=visibility)
-                                else:
-                                    for el in geo:
-                                        self.add_mark_shape(apid=aperture_to_plot_mark, shape=el, color=color,
-                                                            face_color=color, visible=visibility)
-
-                    self.mark_shapes[aperture_to_plot_mark].redraw()
-
-                except (ObjectDeleted, AttributeError):
-                    self.clear_plot_apertures()
-                except Exception as e:
-                    log.debug("FlatCAMGerber.plot_aperture() --> %s" % str(e))
-
-            if run_thread:
-                self.app.worker_task.emit({'fcn': job_thread, 'params': [self]})
-            else:
-                job_thread(self)
-
-    def clear_plot_apertures(self, aperture='all'):
-        """
-
-        :param aperture: string; aperture for which to clear the mark shapes
-        :return:
-        """
-
-        if self.mark_shapes:
-            if aperture == 'all':
-                for apid in list(self.apertures.keys()):
-                    try:
-                        if self.app.is_legacy is True:
-                            self.mark_shapes[apid].clear(update=False)
-                        else:
-                            self.mark_shapes[apid].clear(update=True)
-                    except Exception as e:
-                        log.debug("FlatCAMGerber.clear_plot_apertures() 'all' --> %s" % str(e))
-            else:
-                try:
-                    if self.app.is_legacy is True:
-                        self.mark_shapes[aperture].clear(update=False)
-                    else:
-                        self.mark_shapes[aperture].clear(update=True)
-                except Exception as e:
-                    log.debug("FlatCAMGerber.clear_plot_apertures() 'aperture' --> %s" % str(e))
-
-    def clear_mark_all(self):
-        self.ui.mark_all_cb.set_value(False)
-        self.marked_rows[:] = []
-
-    def on_mark_cb_click_table(self):
-        """
-        Will mark aperture geometries on canvas or delete the markings depending on the checkbox state
-        :return:
-        """
-
-        self.ui_disconnect()
-        try:
-            cw = self.sender()
-            assert isinstance(cw, FCCheckBox),\
-                "Expected a cellWidget but got %s" % type(cw)
-            cw_index = self.ui.apertures_table.indexAt(cw.pos())
-            cw_row = cw_index.row()
-        except AttributeError:
-            cw_row = 0
-        except TypeError:
-            return
-
-        self.marked_rows[:] = []
-
-        try:
-            aperture = self.ui.apertures_table.item(cw_row, 1).text()
-        except AttributeError:
-            return
-
-        if self.ui.apertures_table.cellWidget(cw_row, 5).isChecked():
-            self.marked_rows.append(True)
-            # self.plot_aperture(color='#2d4606bf', marked_aperture=aperture, visible=True)
-            self.plot_aperture(color=self.app.defaults['global_sel_draw_color'] + 'AF',
-                               marked_aperture=aperture, visible=True, run_thread=True)
-            # self.mark_shapes[aperture].redraw()
-        else:
-            self.marked_rows.append(False)
-            self.clear_plot_apertures(aperture=aperture)
-
-        # make sure that the Mark All is disabled if one of the row mark's are disabled and
-        # if all the row mark's are enabled also enable the Mark All checkbox
-        cb_cnt = 0
-        total_row = self.ui.apertures_table.rowCount()
-        for row in range(total_row):
-            if self.ui.apertures_table.cellWidget(row, 5).isChecked():
-                cb_cnt += 1
-            else:
-                cb_cnt -= 1
-        if cb_cnt < total_row:
-            self.ui.mark_all_cb.setChecked(False)
-        else:
-            self.ui.mark_all_cb.setChecked(True)
-        self.ui_connect()
-
-    def on_mark_all_click(self):
-        self.ui_disconnect()
-        mark_all = self.ui.mark_all_cb.isChecked()
-        for row in range(self.ui.apertures_table.rowCount()):
-            # update the mark_rows list
-            if mark_all:
-                self.marked_rows.append(True)
-            else:
-                self.marked_rows[:] = []
-
-            mark_cb = self.ui.apertures_table.cellWidget(row, 5)
-            mark_cb.setChecked(mark_all)
-
-        if mark_all:
-            for aperture in self.apertures:
-                # self.plot_aperture(color='#2d4606bf', marked_aperture=aperture, visible=True)
-                self.plot_aperture(color=self.app.defaults['global_sel_draw_color'] + 'AF',
-                                   marked_aperture=aperture, visible=True)
-            # HACK: enable/disable the grid for a better look
-            self.app.ui.grid_snap_btn.trigger()
-            self.app.ui.grid_snap_btn.trigger()
-        else:
-            self.clear_plot_apertures()
-            self.marked_rows[:] = []
-
-        self.ui_connect()
-
-    def export_gerber(self, whole, fract, g_zeros='L', factor=1):
-        """
-        Creates a Gerber file content to be exported to a file.
-
-        :param whole: how many digits in the whole part of coordinates
-        :param fract: how many decimals in coordinates
-        :param g_zeros: type of the zero suppression used: LZ or TZ; string
-        :param factor: factor to be applied onto the Gerber coordinates
-        :return: Gerber_code
-        """
-        log.debug("FlatCAMGerber.export_gerber() --> Generating the Gerber code from the selected Gerber file")
-
-        def tz_format(x, y, fac):
-            x_c = x * fac
-            y_c = y * fac
-
-            x_form = "{:.{dec}f}".format(x_c, dec=fract)
-            y_form = "{:.{dec}f}".format(y_c, dec=fract)
-
-            # extract whole part and decimal part
-            x_form = x_form.partition('.')
-            y_form = y_form.partition('.')
-
-            # left padd the 'whole' part with zeros
-            x_whole = x_form[0].rjust(whole, '0')
-            y_whole = y_form[0].rjust(whole, '0')
-
-            # restore the coordinate padded in the left with 0 and added the decimal part
-            # without the decinal dot
-            x_form = x_whole + x_form[2]
-            y_form = y_whole + y_form[2]
-            return x_form, y_form
-
-        def lz_format(x, y, fac):
-            x_c = x * fac
-            y_c = y * fac
-
-            x_form = "{:.{dec}f}".format(x_c, dec=fract).replace('.', '')
-            y_form = "{:.{dec}f}".format(y_c, dec=fract).replace('.', '')
-
-            # pad with rear zeros
-            x_form.ljust(length, '0')
-            y_form.ljust(length, '0')
-
-            return x_form, y_form
-
-        # Gerber code is stored here
-        gerber_code = ''
-
-        # apertures processing
-        try:
-            length = whole + fract
-            if '0' in self.apertures:
-                if 'geometry' in self.apertures['0']:
-                    for geo_elem in self.apertures['0']['geometry']:
-                        if 'solid' in geo_elem:
-                            geo = geo_elem['solid']
-                            if not geo.is_empty:
-                                gerber_code += 'G36*\n'
-                                geo_coords = list(geo.exterior.coords)
-                                # first command is a move with pen-up D02 at the beginning of the geo
-                                if g_zeros == 'T':
-                                    x_formatted, y_formatted = tz_format(geo_coords[0][0], geo_coords[0][1], factor)
-                                    gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
-                                                                                   yform=y_formatted)
-                                else:
-                                    x_formatted, y_formatted = lz_format(geo_coords[0][0], geo_coords[0][1], factor)
-                                    gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
-                                                                                   yform=y_formatted)
-                                for coord in geo_coords[1:]:
-                                    if g_zeros == 'T':
-                                        x_formatted, y_formatted = tz_format(coord[0], coord[1], factor)
-                                        gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
-                                                                                       yform=y_formatted)
-                                    else:
-                                        x_formatted, y_formatted = lz_format(coord[0], coord[1], factor)
-                                        gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
-                                                                                       yform=y_formatted)
-                                gerber_code += 'D02*\n'
-                                gerber_code += 'G37*\n'
-
-                                clear_list = list(geo.interiors)
-                                if clear_list:
-                                    gerber_code += '%LPC*%\n'
-                                    for clear_geo in clear_list:
-                                        gerber_code += 'G36*\n'
-                                        geo_coords = list(clear_geo.coords)
-
-                                        # first command is a move with pen-up D02 at the beginning of the geo
-                                        if g_zeros == 'T':
-                                            x_formatted, y_formatted = tz_format(
-                                                geo_coords[0][0], geo_coords[0][1], factor)
-                                            gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
-                                                                                           yform=y_formatted)
-                                        else:
-                                            x_formatted, y_formatted = lz_format(
-                                                geo_coords[0][0], geo_coords[0][1], factor)
-                                            gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
-                                                                                           yform=y_formatted)
-
-                                        prev_coord = geo_coords[0]
-                                        for coord in geo_coords[1:]:
-                                            if coord != prev_coord:
-                                                if g_zeros == 'T':
-                                                    x_formatted, y_formatted = tz_format(coord[0], coord[1], factor)
-                                                    gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
-                                                                                                   yform=y_formatted)
-                                                else:
-                                                    x_formatted, y_formatted = lz_format(coord[0], coord[1], factor)
-                                                    gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
-                                                                                                   yform=y_formatted)
-                                            prev_coord = coord
-
-                                        gerber_code += 'D02*\n'
-                                        gerber_code += 'G37*\n'
-                                    gerber_code += '%LPD*%\n'
-                        if 'clear' in geo_elem:
-                            geo = geo_elem['clear']
-                            if not geo.is_empty:
-                                gerber_code += '%LPC*%\n'
-                                gerber_code += 'G36*\n'
-                                geo_coords = list(geo.exterior.coords)
-                                # first command is a move with pen-up D02 at the beginning of the geo
-                                if g_zeros == 'T':
-                                    x_formatted, y_formatted = tz_format(geo_coords[0][0], geo_coords[0][1], factor)
-                                    gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
-                                                                                   yform=y_formatted)
-                                else:
-                                    x_formatted, y_formatted = lz_format(geo_coords[0][0], geo_coords[0][1], factor)
-                                    gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
-                                                                                   yform=y_formatted)
-
-                                prev_coord = geo_coords[0]
-                                for coord in geo_coords[1:]:
-                                    if coord != prev_coord:
-                                        if g_zeros == 'T':
-                                            x_formatted, y_formatted = tz_format(coord[0], coord[1], factor)
-                                            gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
-                                                                                           yform=y_formatted)
-                                        else:
-                                            x_formatted, y_formatted = lz_format(coord[0], coord[1], factor)
-                                            gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
-                                                                                           yform=y_formatted)
-                                    prev_coord = coord
-
-                                gerber_code += 'D02*\n'
-                                gerber_code += 'G37*\n'
-                                gerber_code += '%LPD*%\n'
-        except Exception as e:
-            log.debug("FlatCAMObj.FlatCAMGerber.export_gerber() '0' aperture --> %s" % str(e))
-
-        for apid in self.apertures:
-            if apid == '0':
-                continue
-            else:
-                gerber_code += 'D%s*\n' % str(apid)
-                if 'geometry' in self.apertures[apid]:
-                    for geo_elem in self.apertures[apid]['geometry']:
-                        try:
-                            if 'follow' in geo_elem:
-                                geo = geo_elem['follow']
-                                if not geo.is_empty:
-                                    if isinstance(geo, Point):
-                                        if g_zeros == 'T':
-                                            x_formatted, y_formatted = tz_format(geo.x, geo.y, factor)
-                                            gerber_code += "X{xform}Y{yform}D03*\n".format(xform=x_formatted,
-                                                                                           yform=y_formatted)
-                                        else:
-                                            x_formatted, y_formatted = lz_format(geo.x, geo.y, factor)
-                                            gerber_code += "X{xform}Y{yform}D03*\n".format(xform=x_formatted,
-                                                                                           yform=y_formatted)
-                                    else:
-                                        geo_coords = list(geo.coords)
-                                        # first command is a move with pen-up D02 at the beginning of the geo
-                                        if g_zeros == 'T':
-                                            x_formatted, y_formatted = tz_format(
-                                                geo_coords[0][0], geo_coords[0][1], factor)
-                                            gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
-                                                                                           yform=y_formatted)
-                                        else:
-                                            x_formatted, y_formatted = lz_format(
-                                                geo_coords[0][0], geo_coords[0][1], factor)
-                                            gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
-                                                                                           yform=y_formatted)
-
-                                        prev_coord = geo_coords[0]
-                                        for coord in geo_coords[1:]:
-                                            if coord != prev_coord:
-                                                if g_zeros == 'T':
-                                                    x_formatted, y_formatted = tz_format(coord[0], coord[1], factor)
-                                                    gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
-                                                                                                   yform=y_formatted)
-                                                else:
-                                                    x_formatted, y_formatted = lz_format(coord[0], coord[1], factor)
-                                                    gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
-                                                                                                   yform=y_formatted)
-                                            prev_coord = coord
-
-                                        # gerber_code += "D02*\n"
-                        except Exception as e:
-                            log.debug("FlatCAMObj.FlatCAMGerber.export_gerber() 'follow' --> %s" % str(e))
-
-                        try:
-                            if 'clear' in geo_elem:
-                                gerber_code += '%LPC*%\n'
-
-                                geo = geo_elem['clear']
-                                if not geo.is_empty:
-                                    if isinstance(geo, Point):
-                                        if g_zeros == 'T':
-                                            x_formatted, y_formatted = tz_format(geo.x, geo.y, factor)
-                                            gerber_code += "X{xform}Y{yform}D03*\n".format(xform=x_formatted,
-                                                                                           yform=y_formatted)
-                                        else:
-                                            x_formatted, y_formatted = lz_format(geo.x, geo.y, factor)
-                                            gerber_code += "X{xform}Y{yform}D03*\n".format(xform=x_formatted,
-                                                                                           yform=y_formatted)
-                                    elif isinstance(geo, Polygon):
-                                        geo_coords = list(geo.exterior.coords)
-                                        # first command is a move with pen-up D02 at the beginning of the geo
-                                        if g_zeros == 'T':
-                                            x_formatted, y_formatted = tz_format(
-                                                geo_coords[0][0], geo_coords[0][1], factor)
-                                            gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
-                                                                                           yform=y_formatted)
-                                        else:
-                                            x_formatted, y_formatted = lz_format(
-                                                geo_coords[0][0], geo_coords[0][1], factor)
-                                            gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
-                                                                                           yform=y_formatted)
-
-                                        prev_coord = geo_coords[0]
-                                        for coord in geo_coords[1:]:
-                                            if coord != prev_coord:
-                                                if g_zeros == 'T':
-                                                    x_formatted, y_formatted = tz_format(coord[0], coord[1], factor)
-                                                    gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
-                                                                                                   yform=y_formatted)
-                                                else:
-                                                    x_formatted, y_formatted = lz_format(coord[0], coord[1], factor)
-                                                    gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
-                                                                                                   yform=y_formatted)
-
-                                            prev_coord = coord
-
-                                        for geo_int in geo.interiors:
-                                            geo_coords = list(geo_int.coords)
-                                            # first command is a move with pen-up D02 at the beginning of the geo
-                                            if g_zeros == 'T':
-                                                x_formatted, y_formatted = tz_format(
-                                                    geo_coords[0][0], geo_coords[0][1], factor)
-                                                gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
-                                                                                               yform=y_formatted)
-                                            else:
-                                                x_formatted, y_formatted = lz_format(
-                                                    geo_coords[0][0], geo_coords[0][1], factor)
-                                                gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
-                                                                                               yform=y_formatted)
-
-                                            prev_coord = geo_coords[0]
-                                            for coord in geo_coords[1:]:
-                                                if coord != prev_coord:
-                                                    if g_zeros == 'T':
-                                                        x_formatted, y_formatted = tz_format(coord[0], coord[1], factor)
-                                                        gerber_code += "X{xform}Y{yform}D01*\n".format(
-                                                            xform=x_formatted,
-                                                            yform=y_formatted)
-                                                    else:
-                                                        x_formatted, y_formatted = lz_format(coord[0], coord[1], factor)
-                                                        gerber_code += "X{xform}Y{yform}D01*\n".format(
-                                                            xform=x_formatted,
-                                                            yform=y_formatted)
-
-                                                prev_coord = coord
-                                    else:
-                                        geo_coords = list(geo.coords)
-                                        # first command is a move with pen-up D02 at the beginning of the geo
-                                        if g_zeros == 'T':
-                                            x_formatted, y_formatted = tz_format(
-                                                geo_coords[0][0], geo_coords[0][1], factor)
-                                            gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
-                                                                                           yform=y_formatted)
-                                        else:
-                                            x_formatted, y_formatted = lz_format(
-                                                geo_coords[0][0], geo_coords[0][1], factor)
-                                            gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
-                                                                                           yform=y_formatted)
-
-                                        prev_coord = geo_coords[0]
-                                        for coord in geo_coords[1:]:
-                                            if coord != prev_coord:
-                                                if g_zeros == 'T':
-                                                    x_formatted, y_formatted = tz_format(coord[0], coord[1], factor)
-                                                    gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
-                                                                                                   yform=y_formatted)
-                                                else:
-                                                    x_formatted, y_formatted = lz_format(coord[0], coord[1], factor)
-                                                    gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
-                                                                                                   yform=y_formatted)
-
-                                            prev_coord = coord
-                                        # gerber_code += "D02*\n"
-                                    gerber_code += '%LPD*%\n'
-                        except Exception as e:
-                            log.debug("FlatCAMObj.FlatCAMGerber.export_gerber() 'clear' --> %s" % str(e))
-
-        if not self.apertures:
-            log.debug("FlatCAMObj.FlatCAMGerber.export_gerber() --> Gerber Object is empty: no apertures.")
-            return 'fail'
-
-        return gerber_code
-
-    def mirror(self, axis, point):
-        Gerber.mirror(self, axis=axis, point=point)
-        self.replotApertures.emit()
-
-    def offset(self, vect):
-        Gerber.offset(self, vect=vect)
-        self.replotApertures.emit()
-
-    def rotate(self, angle, point):
-        Gerber.rotate(self, angle=angle, point=point)
-        self.replotApertures.emit()
-
-    def scale(self, xfactor, yfactor=None, point=None):
-        Gerber.scale(self, xfactor=xfactor, yfactor=yfactor, point=point)
-        self.replotApertures.emit()
-
-    def skew(self, angle_x, angle_y, point):
-        Gerber.skew(self, angle_x=angle_x, angle_y=angle_y, point=point)
-        self.replotApertures.emit()
-
-    def buffer(self, distance, join, factor=None):
-        Gerber.buffer(self, distance=distance, join=join, factor=factor)
-        self.replotApertures.emit()
-
-    def serialize(self):
-        return {
-            "options": self.options,
-            "kind": self.kind
-        }
-
-
-class FlatCAMExcellon(FlatCAMObj, Excellon):
-    """
-    Represents Excellon/Drill code.
-    """
-
-    ui_type = ExcellonObjectUI
-    optionChanged = QtCore.pyqtSignal(str)
-
-    def __init__(self, name):
-        self.decimals = self.app.decimals
-
-        self.circle_steps = int(self.app.defaults["geometry_circle_steps"])
-
-        Excellon.__init__(self, geo_steps_per_circle=self.circle_steps)
-        FlatCAMObj.__init__(self, name)
-
-        self.kind = "excellon"
-
-        self.options.update({
-            "plot": True,
-            "solid": False,
-
-            "operation": "drill",
-            "milling_type": "drills",
-
-            "milling_dia": 0.04,
-
-            "cutz": -0.1,
-            "multidepth": False,
-            "depthperpass": 0.7,
-            "travelz": 0.1,
-            "feedrate": self.app.defaults["geometry_feedrate"],
-            "feedrate_z": 5.0,
-            "feedrate_rapid": 5.0,
-            "tooldia": 0.1,
-            "slot_tooldia": 0.1,
-            "toolchange": False,
-            "toolchangez": 1.0,
-            "toolchangexy": "0.0, 0.0",
-            "extracut": self.app.defaults["geometry_extracut"],
-            "extracut_length": self.app.defaults["geometry_extracut_length"],
-            "endz": 2.0,
-            "endxy": '',
-
-            "startz": None,
-            "offset": 0.0,
-            "spindlespeed": 0,
-            "dwell": True,
-            "dwelltime": 1000,
-            "ppname_e": 'default',
-            "ppname_g": self.app.defaults["geometry_ppname_g"],
-            "z_pdepth": -0.02,
-            "feedrate_probe": 3.0,
-            "optimization_type": "B",
-        })
-
-        # TODO: Document this.
-        self.tool_cbs = {}
-
-        # dict that holds the object names and the option name
-        # the key is the object name (defines in ObjectUI) for each UI element that is a parameter
-        # particular for a tool and the value is the actual name of the option that the UI element is changing
-        self.name2option = {}
-
-        # default set of data to be added to each tool in self.tools as self.tools[tool]['data'] = self.default_data
-        self.default_data = {}
-
-        # fill in self.default_data values from self.options
-        for opt_key, opt_val in self.app.options.items():
-            if opt_key.find('excellon_') == 0:
-                self.default_data[opt_key] = deepcopy(opt_val)
-        for opt_key, opt_val in self.app.options.items():
-            if opt_key.find('geometry_') == 0:
-                self.default_data[opt_key] = deepcopy(opt_val)
-
-        # variable to store the total amount of drills per job
-        self.tot_drill_cnt = 0
-        self.tool_row = 0
-
-        # variable to store the total amount of slots per job
-        self.tot_slot_cnt = 0
-        self.tool_row_slots = 0
-
-        # variable to store the distance travelled
-        self.travel_distance = 0.0
-
-        # store the source file here
-        self.source_file = ""
-
-        self.multigeo = False
-        self.units_found = self.app.defaults['units']
-
-        self.fill_color = self.app.defaults['excellon_plot_fill']
-        self.outline_color = self.app.defaults['excellon_plot_line']
-        self.alpha_level = 'bf'
-
-        # Attributes to be included in serialization
-        # Always append to it because it carries contents
-        # from predecessors.
-        self.ser_attrs += ['options', 'kind']
-
-    def merge(self, exc_list, exc_final):
-        """
-        Merge Excellon objects found in exc_list parameter into exc_final object.
-        Options are always copied from source .
-
-        Tools are disregarded, what is taken in consideration is the unique drill diameters found as values in the
-        exc_list tools dict's. In the reconstruction section for each unique tool diameter it will be created a
-        tool_name to be used in the final Excellon object, exc_final.
-
-        If only one object is in exc_list parameter then this function will copy that object in the exc_final
-
-        :param exc_list: List or one object of FlatCAMExcellon Objects to join.
-        :param exc_final: Destination FlatCAMExcellon object.
-        :return: None
-        """
-
-        try:
-            decimals_exc = self.decimals
-        except AttributeError:
-            decimals_exc = 4
-
-        # flag to signal that we need to reorder the tools dictionary and drills and slots lists
-        flag_order = False
-
-        try:
-            flattened_list = list(itertools.chain(*exc_list))
-        except TypeError:
-            flattened_list = exc_list
-
-        # this dict will hold the unique tool diameters found in the exc_list objects as the dict keys and the dict
-        # values will be list of Shapely Points; for drills
-        custom_dict_drills = {}
-
-        # this dict will hold the unique tool diameters found in the exc_list objects as the dict keys and the dict
-        # values will be list of Shapely Points; for slots
-        custom_dict_slots = {}
-
-        for exc in flattened_list:
-            # copy options of the current excellon obj to the final excellon obj
-            for option in exc.options:
-                if option != 'name':
-                    try:
-                        exc_final.options[option] = exc.options[option]
-                    except Exception:
-                        exc.app.log.warning("Failed to copy option.", option)
-
-            for drill in exc.drills:
-                exc_tool_dia = float('%.*f' % (decimals_exc, exc.tools[drill['tool']]['C']))
-
-                if exc_tool_dia not in custom_dict_drills:
-                    custom_dict_drills[exc_tool_dia] = [drill['point']]
-                else:
-                    custom_dict_drills[exc_tool_dia].append(drill['point'])
-
-            for slot in exc.slots:
-                exc_tool_dia = float('%.*f' % (decimals_exc, exc.tools[slot['tool']]['C']))
-
-                if exc_tool_dia not in custom_dict_slots:
-                    custom_dict_slots[exc_tool_dia] = [[slot['start'], slot['stop']]]
-                else:
-                    custom_dict_slots[exc_tool_dia].append([slot['start'], slot['stop']])
-
-            # add the zeros and units to the exc_final object
-            exc_final.zeros = exc.zeros
-            exc_final.units = exc.units
-
-        # ##########################################
-        # Here we add data to the exc_final object #
-        # ##########################################
-
-        # variable to make tool_name for the tools
-        current_tool = 0
-        # The tools diameter are now the keys in the drill_dia dict and the values are the Shapely Points in case of
-        # drills
-        for tool_dia in custom_dict_drills:
-            # we create a tool name for each key in the drill_dia dict (the key is a unique drill diameter)
-            current_tool += 1
-
-            tool_name = str(current_tool)
-            spec = {"C": float(tool_dia)}
-            exc_final.tools[tool_name] = spec
-
-            # rebuild the drills list of dict's that belong to the exc_final object
-            for point in custom_dict_drills[tool_dia]:
-                exc_final.drills.append(
-                    {
-                        "point": point,
-                        "tool": str(current_tool)
-                    }
-                )
-
-        # The tools diameter are now the keys in the drill_dia dict and the values are a list ([start, stop])
-        # of two Shapely Points in case of slots
-        for tool_dia in custom_dict_slots:
-            # we create a tool name for each key in the slot_dia dict (the key is a unique slot diameter)
-            # but only if there are no drills
-            if not exc_final.tools:
-                current_tool += 1
-                tool_name = str(current_tool)
-                spec = {"C": float(tool_dia)}
-                exc_final.tools[tool_name] = spec
-            else:
-                dia_list = []
-                for v in exc_final.tools.values():
-                    dia_list.append(float(v["C"]))
-
-                if tool_dia not in dia_list:
-                    flag_order = True
-
-                    current_tool = len(dia_list) + 1
-                    tool_name = str(current_tool)
-                    spec = {"C": float(tool_dia)}
-                    exc_final.tools[tool_name] = spec
-
-                else:
-                    for k, v in exc_final.tools.items():
-                        if v["C"] == tool_dia:
-                            current_tool = int(k)
-                            break
-
-            # rebuild the slots list of dict's that belong to the exc_final object
-            for point in custom_dict_slots[tool_dia]:
-                exc_final.slots.append(
-                    {
-                        "start": point[0],
-                        "stop": point[1],
-                        "tool": str(current_tool)
-                    }
-                )
-
-        # flag_order == True means that there was an slot diameter not in the tools and we also have drills
-        # and the new tool was added to self.tools therefore we need to reorder the tools and drills and slots
-        current_tool = 0
-        if flag_order is True:
-            dia_list = []
-            temp_drills = []
-            temp_slots = []
-            temp_tools = {}
-            for v in exc_final.tools.values():
-                dia_list.append(float(v["C"]))
-            dia_list.sort()
-            for ordered_dia in dia_list:
-                current_tool += 1
-                tool_name_temp = str(current_tool)
-                spec_temp = {"C": float(ordered_dia)}
-                temp_tools[tool_name_temp] = spec_temp
-
-                for drill in exc_final.drills:
-                    exc_tool_dia = float('%.*f' % (decimals_exc, exc_final.tools[drill['tool']]['C']))
-                    if exc_tool_dia == ordered_dia:
-                        temp_drills.append(
-                            {
-                                "point": drill["point"],
-                                "tool": str(current_tool)
-                            }
-                        )
-
-                for slot in exc_final.slots:
-                    slot_tool_dia = float('%.*f' % (decimals_exc, exc_final.tools[slot['tool']]['C']))
-                    if slot_tool_dia == ordered_dia:
-                        temp_slots.append(
-                            {
-                                "start": slot["start"],
-                                "stop": slot["stop"],
-                                "tool": str(current_tool)
-                            }
-                        )
-
-            # delete the exc_final tools, drills and slots
-            exc_final.tools = {}
-            exc_final.drills[:] = []
-            exc_final.slots[:] = []
-
-            # update the exc_final tools, drills and slots with the ordered values
-            exc_final.tools = temp_tools
-            exc_final.drills[:] = temp_drills
-            exc_final.slots[:] = temp_slots
-
-        # create the geometry for the exc_final object
-        exc_final.create_geometry()
-
-    def build_ui(self):
-        FlatCAMObj.build_ui(self)
-
-        self.units = self.app.defaults['units'].upper()
-
-        for row in range(self.ui.tools_table.rowCount()):
-            try:
-                # if connected, disconnect the signal from the slot on item_changed as it creates issues
-                offset_spin_widget = self.ui.tools_table.cellWidget(row, 4)
-                offset_spin_widget.valueChanged.disconnect()
-            except (TypeError, AttributeError):
-                pass
-
-        n = len(self.tools)
-        # we have (n+2) rows because there are 'n' tools, each a row, plus the last 2 rows for totals.
-        self.ui.tools_table.setRowCount(n + 2)
-
-        self.tot_drill_cnt = 0
-        self.tot_slot_cnt = 0
-
-        self.tool_row = 0
-
-        sort = []
-        for k, v in list(self.tools.items()):
-            sort.append((k, v.get('C')))
-        sorted_tools = sorted(sort, key=lambda t1: t1[1])
-        tools = [i[0] for i in sorted_tools]
-
-        new_options = {}
-        for opt in self.options:
-            new_options[opt] = self.options[opt]
-
-        for tool_no in tools:
-
-            # add the data dictionary for each tool with the default values
-            self.tools[tool_no]['data'] = deepcopy(new_options)
-            # self.tools[tool_no]['data']["tooldia"] = self.tools[tool_no]["C"]
-            # self.tools[tool_no]['data']["slot_tooldia"] = self.tools[tool_no]["C"]
-
-            drill_cnt = 0  # variable to store the nr of drills per tool
-            slot_cnt = 0  # variable to store the nr of slots per tool
-
-            # Find no of drills for the current tool
-            for drill in self.drills:
-                if drill['tool'] == tool_no:
-                    drill_cnt += 1
-
-            self.tot_drill_cnt += drill_cnt
-
-            # Find no of slots for the current tool
-            for slot in self.slots:
-                if slot['tool'] == tool_no:
-                    slot_cnt += 1
-
-            self.tot_slot_cnt += slot_cnt
-
-            exc_id_item = QtWidgets.QTableWidgetItem('%d' % int(tool_no))
-            exc_id_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
-
-            dia_item = QtWidgets.QTableWidgetItem('%.*f' % (self.decimals, self.tools[tool_no]['C']))
-            dia_item.setFlags(QtCore.Qt.ItemIsEnabled)
-
-            drill_count_item = QtWidgets.QTableWidgetItem('%d' % drill_cnt)
-            drill_count_item.setFlags(QtCore.Qt.ItemIsEnabled)
-
-            # if the slot number is zero is better to not clutter the GUI with zero's so we print a space
-            slot_count_str = '%d' % slot_cnt if slot_cnt > 0 else ''
-            slot_count_item = QtWidgets.QTableWidgetItem(slot_count_str)
-            slot_count_item.setFlags(QtCore.Qt.ItemIsEnabled)
-
-            plot_item = FCCheckBox()
-            plot_item.setLayoutDirection(QtCore.Qt.RightToLeft)
-            if self.ui.plot_cb.isChecked():
-                plot_item.setChecked(True)
-
-            self.ui.tools_table.setItem(self.tool_row, 0, exc_id_item)  # Tool name/id
-            self.ui.tools_table.setItem(self.tool_row, 1, dia_item)  # Diameter
-            self.ui.tools_table.setItem(self.tool_row, 2, drill_count_item)  # Number of drills per tool
-            self.ui.tools_table.setItem(self.tool_row, 3, slot_count_item)  # Number of drills per tool
-            empty_plot_item = QtWidgets.QTableWidgetItem('')
-            empty_plot_item.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
-            self.ui.tools_table.setItem(self.tool_row, 5, empty_plot_item)
-            self.ui.tools_table.setCellWidget(self.tool_row, 5, plot_item)
-
-            self.tool_row += 1
-
-        # add a last row with the Total number of drills
-        empty_1 = QtWidgets.QTableWidgetItem('')
-        empty_1.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
-        empty_1_1 = QtWidgets.QTableWidgetItem('')
-        empty_1_1.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
-        empty_1_2 = QtWidgets.QTableWidgetItem('')
-        empty_1_2.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
-        empty_1_3 = QtWidgets.QTableWidgetItem('')
-        empty_1_3.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
-
-        label_tot_drill_count = QtWidgets.QTableWidgetItem(_('Total Drills'))
-        tot_drill_count = QtWidgets.QTableWidgetItem('%d' % self.tot_drill_cnt)
-        label_tot_drill_count.setFlags(QtCore.Qt.ItemIsEnabled)
-        tot_drill_count.setFlags(QtCore.Qt.ItemIsEnabled)
-
-        self.ui.tools_table.setItem(self.tool_row, 0, empty_1)
-        self.ui.tools_table.setItem(self.tool_row, 1, label_tot_drill_count)
-        self.ui.tools_table.setItem(self.tool_row, 2, tot_drill_count)  # Total number of drills
-        self.ui.tools_table.setItem(self.tool_row, 3, empty_1_1)
-        self.ui.tools_table.setItem(self.tool_row, 5, empty_1_3)
-
-        font = QtGui.QFont()
-        font.setBold(True)
-        font.setWeight(75)
-
-        for k in [1, 2]:
-            self.ui.tools_table.item(self.tool_row, k).setForeground(QtGui.QColor(127, 0, 255))
-            self.ui.tools_table.item(self.tool_row, k).setFont(font)
-
-        self.tool_row += 1
-
-        # add a last row with the Total number of slots
-        empty_2 = QtWidgets.QTableWidgetItem('')
-        empty_2.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
-        empty_2_1 = QtWidgets.QTableWidgetItem('')
-        empty_2_1.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
-        empty_2_2 = QtWidgets.QTableWidgetItem('')
-        empty_2_2.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
-        empty_2_3 = QtWidgets.QTableWidgetItem('')
-        empty_2_3.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
-
-        label_tot_slot_count = QtWidgets.QTableWidgetItem(_('Total Slots'))
-        tot_slot_count = QtWidgets.QTableWidgetItem('%d' % self.tot_slot_cnt)
-        label_tot_slot_count.setFlags(QtCore.Qt.ItemIsEnabled)
-        tot_slot_count.setFlags(QtCore.Qt.ItemIsEnabled)
-
-        self.ui.tools_table.setItem(self.tool_row, 0, empty_2)
-        self.ui.tools_table.setItem(self.tool_row, 1, label_tot_slot_count)
-        self.ui.tools_table.setItem(self.tool_row, 2, empty_2_1)
-        self.ui.tools_table.setItem(self.tool_row, 3, tot_slot_count)  # Total number of slots
-        self.ui.tools_table.setItem(self.tool_row, 5, empty_2_3)
-
-        for kl in [1, 2, 3]:
-            self.ui.tools_table.item(self.tool_row, kl).setFont(font)
-            self.ui.tools_table.item(self.tool_row, kl).setForeground(QtGui.QColor(0, 70, 255))
-
-        # sort the tool diameter column
-        # self.ui.tools_table.sortItems(1)
-
-        # all the tools are selected by default
-        self.ui.tools_table.selectColumn(0)
-
-        self.ui.tools_table.resizeColumnsToContents()
-        self.ui.tools_table.resizeRowsToContents()
-
-        vertical_header = self.ui.tools_table.verticalHeader()
-        # vertical_header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
-        vertical_header.hide()
-        self.ui.tools_table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
-
-        horizontal_header = self.ui.tools_table.horizontalHeader()
-        horizontal_header.setMinimumSectionSize(10)
-        horizontal_header.setDefaultSectionSize(70)
-        horizontal_header.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
-        horizontal_header.resizeSection(0, 20)
-
-        horizontal_header.setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
-
-        horizontal_header.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
-        horizontal_header.setSectionResizeMode(3, QtWidgets.QHeaderView.ResizeToContents)
-        horizontal_header.setSectionResizeMode(5, QtWidgets.QHeaderView.Fixed)
-        horizontal_header.resizeSection(5, 17)
-        self.ui.tools_table.setColumnWidth(5, 17)
-
-        # horizontal_header.setStretchLastSection(True)
-        # horizontal_header.setColumnWidth(2, QtWidgets.QHeaderView.ResizeToContents)
-
-        # horizontal_header.setStretchLastSection(True)
-        self.ui.tools_table.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
-
-        self.ui.tools_table.setSortingEnabled(False)
-
-        self.ui.tools_table.setMinimumHeight(self.ui.tools_table.getHeight())
-        self.ui.tools_table.setMaximumHeight(self.ui.tools_table.getHeight())
-
-        if not self.drills:
-            self.ui.tooldia_entry.hide()
-            self.ui.generate_milling_button.hide()
-        else:
-            self.ui.tooldia_entry.show()
-            self.ui.generate_milling_button.show()
-
-        if not self.slots:
-            self.ui.slot_tooldia_entry.hide()
-            self.ui.generate_milling_slots_button.hide()
-        else:
-            self.ui.slot_tooldia_entry.show()
-            self.ui.generate_milling_slots_button.show()
-
-        # set the text on tool_data_label after loading the object
-        sel_items = self.ui.tools_table.selectedItems()
-        sel_rows = [it.row() for it in sel_items]
-        if len(sel_rows) > 1:
-            self.ui.tool_data_label.setText(
-                "<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("Multiple Tools"))
-            )
-
-        self.ui_connect()
-
-    def set_ui(self, ui):
-        """
-        Configures the user interface for this object.
-        Connects options to form fields.
-
-        :param ui: User interface object.
-        :type ui: ExcellonObjectUI
-        :return: None
-        """
-        FlatCAMObj.set_ui(self, ui)
-
-        log.debug("FlatCAMExcellon.set_ui()")
-
-        self.units = self.app.defaults['units'].upper()
-
-        self.form_fields.update({
-            "plot": self.ui.plot_cb,
-            "solid": self.ui.solid_cb,
-
-            "operation": self.ui.operation_radio,
-            "milling_type": self.ui.milling_type_radio,
-
-            "milling_dia": self.ui.mill_dia_entry,
-            "cutz": self.ui.cutz_entry,
-            "multidepth": self.ui.mpass_cb,
-            "depthperpass": self.ui.maxdepth_entry,
-            "travelz": self.ui.travelz_entry,
-            "feedrate_z": self.ui.feedrate_z_entry,
-            "feedrate": self.ui.xyfeedrate_entry,
-            "feedrate_rapid": self.ui.feedrate_rapid_entry,
-            "tooldia": self.ui.tooldia_entry,
-            "slot_tooldia": self.ui.slot_tooldia_entry,
-            "toolchange": self.ui.toolchange_cb,
-            "toolchangez": self.ui.toolchangez_entry,
-            "extracut": self.ui.extracut_cb,
-            "extracut_length": self.ui.e_cut_entry,
-
-            "spindlespeed": self.ui.spindlespeed_entry,
-            "dwell": self.ui.dwell_cb,
-            "dwelltime": self.ui.dwelltime_entry,
-
-            "startz": self.ui.estartz_entry,
-            "endz": self.ui.endz_entry,
-            "endxy": self.ui.endxy_entry,
-
-            "offset": self.ui.offset_entry,
-
-            "ppname_e": self.ui.pp_excellon_name_cb,
-            "ppname_g": self.ui.pp_geo_name_cb,
-            "z_pdepth": self.ui.pdepth_entry,
-            "feedrate_probe": self.ui.feedrate_probe_entry,
-            # "gcode_type": self.ui.excellon_gcode_type_radio
-        })
-
-        self.name2option = {
-            "e_operation": "operation",
-            "e_milling_type": "milling_type",
-            "e_milling_dia": "milling_dia",
-            "e_cutz": "cutz",
-            "e_multidepth": "multidepth",
-            "e_depthperpass": "depthperpass",
-
-            "e_travelz": "travelz",
-            "e_feedratexy": "feedrate",
-            "e_feedratez": "feedrate_z",
-            "e_fr_rapid": "feedrate_rapid",
-            "e_extracut": "extracut",
-            "e_extracut_length": "extracut_length",
-            "e_spindlespeed": "spindlespeed",
-            "e_dwell": "dwell",
-            "e_dwelltime": "dwelltime",
-            "e_offset": "offset",
-        }
-
-        # populate Excellon preprocessor combobox list
-        for name in list(self.app.preprocessors.keys()):
-            # the HPGL preprocessor is only for Geometry not for Excellon job therefore don't add it
-            if name == 'hpgl':
-                continue
-            self.ui.pp_excellon_name_cb.addItem(name)
-
-        # populate Geometry (milling) preprocessor combobox list
-        for name in list(self.app.preprocessors.keys()):
-            self.ui.pp_geo_name_cb.addItem(name)
-
-        # Fill form fields
-        self.to_form()
-
-        # update the changes in UI depending on the selected preprocessor in Preferences
-        # after this moment all the changes in the Posprocessor combo will be handled by the activated signal of the
-        # self.ui.pp_excellon_name_cb combobox
-        self.on_pp_changed()
-
-        # Show/Hide Advanced Options
-        if self.app.defaults["global_app_level"] == 'b':
-            self.ui.level.setText('<span style="color:green;"><b>%s</b></span>' % _('Basic'))
-
-            self.ui.tools_table.setColumnHidden(4, True)
-            self.ui.tools_table.setColumnHidden(5, True)
-            self.ui.estartz_label.hide()
-            self.ui.estartz_entry.hide()
-            self.ui.feedrate_rapid_label.hide()
-            self.ui.feedrate_rapid_entry.hide()
-            self.ui.pdepth_label.hide()
-            self.ui.pdepth_entry.hide()
-            self.ui.feedrate_probe_label.hide()
-            self.ui.feedrate_probe_entry.hide()
-        else:
-            self.ui.level.setText('<span style="color:red;"><b>%s</b></span>' % _('Advanced'))
-
-        assert isinstance(self.ui, ExcellonObjectUI), \
-            "Expected a ExcellonObjectUI, got %s" % type(self.ui)
-        self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
-        self.ui.solid_cb.stateChanged.connect(self.on_solid_cb_click)
-        self.ui.generate_cnc_button.clicked.connect(self.on_create_cncjob_button_click)
-        self.ui.generate_milling_button.clicked.connect(self.on_generate_milling_button_click)
-        self.ui.generate_milling_slots_button.clicked.connect(self.on_generate_milling_slots_button_click)
-
-        self.on_operation_type(val='drill')
-        self.ui.operation_radio.activated_custom.connect(self.on_operation_type)
-
-        self.ui.pp_excellon_name_cb.activated.connect(self.on_pp_changed)
-
-        self.ui.apply_param_to_all.clicked.connect(self.on_apply_param_to_all_clicked)
-
-        self.units_found = self.app.defaults['units']
-
-        # ########################################
-        # #######3 TEMP SETTINGS #################
-        # ########################################
-        self.ui.operation_radio.set_value("drill")
-        self.ui.operation_radio.setEnabled(False)
-
-    def ui_connect(self):
-
-        # selective plotting
-        for row in range(self.ui.tools_table.rowCount() - 2):
-            self.ui.tools_table.cellWidget(row, 5).clicked.connect(self.on_plot_cb_click_table)
-        self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
-
-        # rows selected
-        self.ui.tools_table.clicked.connect(self.on_row_selection_change)
-        self.ui.tools_table.horizontalHeader().sectionClicked.connect(self.on_row_selection_change)
-
-        # value changed in the particular parameters of a tool
-        for key, option in self.name2option.items():
-            current_widget = self.form_fields[option]
-
-            if isinstance(current_widget, FCCheckBox):
-                current_widget.stateChanged.connect(self.form_to_storage)
-            if isinstance(current_widget, RadioSet):
-                current_widget.activated_custom.connect(self.form_to_storage)
-            elif isinstance(current_widget, FCDoubleSpinner) or isinstance(current_widget, FCSpinner):
-                current_widget.returnPressed.connect(self.form_to_storage)
-
-    def ui_disconnect(self):
-        # selective plotting
-        for row in range(self.ui.tools_table.rowCount()):
-            try:
-                self.ui.tools_table.cellWidget(row, 5).clicked.disconnect()
-            except (TypeError, AttributeError):
-                pass
-        try:
-            self.ui.plot_cb.stateChanged.disconnect()
-        except (TypeError, AttributeError):
-            pass
-
-        # rows selected
-        try:
-            self.ui.tools_table.clicked.disconnect()
-        except (TypeError, AttributeError):
-            pass
-        try:
-            self.ui.tools_table.horizontalHeader().sectionClicked.disconnect()
-        except (TypeError, AttributeError):
-            pass
-
-        # value changed in the particular parameters of a tool
-        for key, option in self.name2option.items():
-            current_widget = self.form_fields[option]
-
-            if isinstance(current_widget, FCCheckBox):
-                try:
-                    current_widget.stateChanged.disconnect(self.form_to_storage)
-                except (TypeError, ValueError):
-                    pass
-            if isinstance(current_widget, RadioSet):
-                try:
-                    current_widget.activated_custom.disconnect(self.form_to_storage)
-                except (TypeError, ValueError):
-                    pass
-            elif isinstance(current_widget, FCDoubleSpinner) or isinstance(current_widget, FCSpinner):
-                try:
-                    current_widget.returnPressed.disconnect(self.form_to_storage)
-                except (TypeError, ValueError):
-                    pass
-
-    def on_row_selection_change(self):
-        self.ui_disconnect()
-
-        sel_rows = []
-        sel_items = self.ui.tools_table.selectedItems()
-        for it in sel_items:
-            sel_rows.append(it.row())
-
-        if not sel_rows:
-            self.ui.tool_data_label.setText(
-                "<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("No Tool Selected"))
-            )
-            self.ui.generate_cnc_button.setDisabled(True)
-            self.ui.generate_milling_button.setDisabled(True)
-            self.ui.generate_milling_slots_button.setDisabled(True)
-            self.ui_connect()
-            return
-        else:
-            self.ui.generate_cnc_button.setDisabled(False)
-            self.ui.generate_milling_button.setDisabled(False)
-            self.ui.generate_milling_slots_button.setDisabled(False)
-
-        if len(sel_rows) == 1:
-            # update the QLabel that shows for which Tool we have the parameters in the UI form
-            tooluid = int(self.ui.tools_table.item(sel_rows[0], 0).text())
-            self.ui.tool_data_label.setText(
-                "<b>%s: <font color='#0000FF'>%s %d</font></b>" % (_('Parameters for'), _("Tool"), tooluid)
-            )
-        else:
-            self.ui.tool_data_label.setText(
-                "<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("Multiple Tools"))
-            )
-
-        for c_row in sel_rows:
-            # populate the form with the data from the tool associated with the row parameter
-            try:
-                item = self.ui.tools_table.item(c_row, 0)
-                if type(item) is not None:
-                    tooluid = item.text()
-                    self.storage_to_form(self.tools[str(tooluid)]['data'])
-                else:
-                    self.ui_connect()
-                    return
-            except Exception as e:
-                log.debug("Tool missing. Add a tool in Geo Tool Table. %s" % str(e))
-                self.ui_connect()
-                return
-
-        self.ui_connect()
-
-    def storage_to_form(self, dict_storage):
-        for form_key in self.form_fields:
-            for storage_key in dict_storage:
-                if form_key == storage_key and form_key not in \
-                        ["toolchange", "toolchangez", "startz", "endz", "ppname_e", "ppname_g"]:
-                    try:
-                        self.form_fields[form_key].set_value(dict_storage[form_key])
-                    except Exception as e:
-                        log.debug("FlatCAMExcellon.storage_to_form() --> %s" % str(e))
-                        pass
-
-    def form_to_storage(self):
-        if self.ui.tools_table.rowCount() == 0:
-            # there is no tool in tool table so we can't save the GUI elements values to storage
-            return
-
-        self.ui_disconnect()
-
-        widget_changed = self.sender()
-        wdg_objname = widget_changed.objectName()
-        option_changed = self.name2option[wdg_objname]
-
-        # row = self.ui.tools_table.currentRow()
-        rows = sorted(set(index.row() for index in self.ui.tools_table.selectedIndexes()))
-        for row in rows:
-            if row < 0:
-                row = 0
-            tooluid_item = int(self.ui.tools_table.item(row, 0).text())
-
-            for tooluid_key, tooluid_val in self.tools.items():
-                if int(tooluid_key) == tooluid_item:
-                    new_option_value = self.form_fields[option_changed].get_value()
-                    if option_changed in tooluid_val:
-                        tooluid_val[option_changed] = new_option_value
-                    if option_changed in tooluid_val['data']:
-                        tooluid_val['data'][option_changed] = new_option_value
-
-        self.ui_connect()
-
-    def on_operation_type(self, val):
-        if val == 'mill':
-            self.ui.mill_type_label.show()
-            self.ui.milling_type_radio.show()
-            self.ui.mill_dia_label.show()
-            self.ui.mill_dia_entry.show()
-            self.ui.frxylabel.show()
-            self.ui.xyfeedrate_entry.show()
-            self.ui.extracut_cb.show()
-            self.ui.e_cut_entry.show()
-
-            # if 'laser' not in self.ui.pp_excellon_name_cb.get_value().lower():
-            #     self.ui.mpass_cb.show()
-            #     self.ui.maxdepth_entry.show()
-        else:
-            self.ui.mill_type_label.hide()
-            self.ui.milling_type_radio.hide()
-            self.ui.mill_dia_label.hide()
-            self.ui.mill_dia_entry.hide()
-            # self.ui.mpass_cb.hide()
-            # self.ui.maxdepth_entry.hide()
-            self.ui.frxylabel.hide()
-            self.ui.xyfeedrate_entry.hide()
-            self.ui.extracut_cb.hide()
-            self.ui.e_cut_entry.hide()
-
-    def get_selected_tools_list(self):
-        """
-        Returns the keys to the self.tools dictionary corresponding
-        to the selections on the tool list in the GUI.
-
-        :return: List of tools.
-        :rtype: list
-        """
-
-        return [str(x.text()) for x in self.ui.tools_table.selectedItems()]
-
-    def get_selected_tools_table_items(self):
-        """
-        Returns a list of lists, each list in the list is made out of row elements
-
-        :return: List of table_tools items.
-        :rtype: list
-        """
-        table_tools_items = []
-        for x in self.ui.tools_table.selectedItems():
-            # from the columnCount we subtract a value of 1 which represent the last column (plot column)
-            # which does not have text
-            txt = ''
-            elem = []
-
-            for column in range(0, self.ui.tools_table.columnCount() - 1):
-                try:
-                    txt = self.ui.tools_table.item(x.row(), column).text()
-                except AttributeError:
-                    try:
-                        txt = self.ui.tools_table.cellWidget(x.row(), column).currentText()
-                    except AttributeError:
-                        pass
-                elem.append(txt)
-            table_tools_items.append(deepcopy(elem))
-            # table_tools_items.append([self.ui.tools_table.item(x.row(), column).text()
-            #                           for column in range(0, self.ui.tools_table.columnCount() - 1)])
-        for item in table_tools_items:
-            item[0] = str(item[0])
-        return table_tools_items
-
-    def export_excellon(self, whole, fract, e_zeros=None, form='dec', factor=1, slot_type='routing'):
-        """
-        Returns two values, first is a boolean , if 1 then the file has slots and second contain the Excellon code
-        :return: has_slots and Excellon_code
-        """
-
-        excellon_code = ''
-
-        # store here if the file has slots, return 1 if any slots, 0 if only drills
-        has_slots = 0
-
-        # drills processing
-        try:
-            if self.drills:
-                length = whole + fract
-                for tool in self.tools:
-                    excellon_code += 'T0%s\n' % str(tool) if int(tool) < 10 else 'T%s\n' % str(tool)
-
-                    for drill in self.drills:
-                        if form == 'dec' and tool == drill['tool']:
-                            drill_x = drill['point'].x * factor
-                            drill_y = drill['point'].y * factor
-                            excellon_code += "X{:.{dec}f}Y{:.{dec}f}\n".format(drill_x, drill_y, dec=fract)
-                        elif e_zeros == 'LZ' and tool == drill['tool']:
-                            drill_x = drill['point'].x * factor
-                            drill_y = drill['point'].y * factor
-
-                            exc_x_formatted = "{:.{dec}f}".format(drill_x, dec=fract)
-                            exc_y_formatted = "{:.{dec}f}".format(drill_y, dec=fract)
-
-                            # extract whole part and decimal part
-                            exc_x_formatted = exc_x_formatted.partition('.')
-                            exc_y_formatted = exc_y_formatted.partition('.')
-
-                            # left padd the 'whole' part with zeros
-                            x_whole = exc_x_formatted[0].rjust(whole, '0')
-                            y_whole = exc_y_formatted[0].rjust(whole, '0')
-
-                            # restore the coordinate padded in the left with 0 and added the decimal part
-                            # without the decinal dot
-                            exc_x_formatted = x_whole + exc_x_formatted[2]
-                            exc_y_formatted = y_whole + exc_y_formatted[2]
-
-                            excellon_code += "X{xform}Y{yform}\n".format(xform=exc_x_formatted,
-                                                                         yform=exc_y_formatted)
-                        elif tool == drill['tool']:
-                            drill_x = drill['point'].x * factor
-                            drill_y = drill['point'].y * factor
-
-                            exc_x_formatted = "{:.{dec}f}".format(drill_x, dec=fract).replace('.', '')
-                            exc_y_formatted = "{:.{dec}f}".format(drill_y, dec=fract).replace('.', '')
-
-                            # pad with rear zeros
-                            exc_x_formatted.ljust(length, '0')
-                            exc_y_formatted.ljust(length, '0')
-
-                            excellon_code += "X{xform}Y{yform}\n".format(xform=exc_x_formatted,
-                                                                         yform=exc_y_formatted)
-        except Exception as e:
-            log.debug(str(e))
-
-        # slots processing
-        try:
-            if self.slots:
-                has_slots = 1
-                for tool in self.tools:
-                    excellon_code += 'G05\n'
-
-                    if int(tool) < 10:
-                        excellon_code += 'T0' + str(tool) + '\n'
-                    else:
-                        excellon_code += 'T' + str(tool) + '\n'
-
-                    for slot in self.slots:
-                        if form == 'dec' and tool == slot['tool']:
-                            start_slot_x = slot['start'].x * factor
-                            start_slot_y = slot['start'].y * factor
-                            stop_slot_x = slot['stop'].x * factor
-                            stop_slot_y = slot['stop'].y * factor
-                            if slot_type == 'routing':
-                                excellon_code += "G00X{:.{dec}f}Y{:.{dec}f}\nM15\n".format(start_slot_x,
-                                                                                           start_slot_y,
-                                                                                           dec=fract)
-                                excellon_code += "G01X{:.{dec}f}Y{:.{dec}f}\nM16\n".format(stop_slot_x,
-                                                                                           stop_slot_y,
-                                                                                           dec=fract)
-                            elif slot_type == 'drilling':
-                                excellon_code += "X{:.{dec}f}Y{:.{dec}f}G85X{:.{dec}f}Y{:.{dec}f}\nG05\n".format(
-                                    start_slot_x, start_slot_y, stop_slot_x, stop_slot_y, dec=fract
-                                )
-
-                        elif e_zeros == 'LZ' and tool == slot['tool']:
-                            start_slot_x = slot['start'].x * factor
-                            start_slot_y = slot['start'].y * factor
-                            stop_slot_x = slot['stop'].x * factor
-                            stop_slot_y = slot['stop'].y * factor
-
-                            start_slot_x_formatted = "{:.{dec}f}".format(start_slot_x, dec=fract).replace('.', '')
-                            start_slot_y_formatted = "{:.{dec}f}".format(start_slot_y, dec=fract).replace('.', '')
-                            stop_slot_x_formatted = "{:.{dec}f}".format(stop_slot_x, dec=fract).replace('.', '')
-                            stop_slot_y_formatted = "{:.{dec}f}".format(stop_slot_y, dec=fract).replace('.', '')
-
-                            # extract whole part and decimal part
-                            start_slot_x_formatted = start_slot_x_formatted.partition('.')
-                            start_slot_y_formatted = start_slot_y_formatted.partition('.')
-                            stop_slot_x_formatted = stop_slot_x_formatted.partition('.')
-                            stop_slot_y_formatted = stop_slot_y_formatted.partition('.')
-
-                            # left padd the 'whole' part with zeros
-                            start_x_whole = start_slot_x_formatted[0].rjust(whole, '0')
-                            start_y_whole = start_slot_y_formatted[0].rjust(whole, '0')
-                            stop_x_whole = stop_slot_x_formatted[0].rjust(whole, '0')
-                            stop_y_whole = stop_slot_y_formatted[0].rjust(whole, '0')
-
-                            # restore the coordinate padded in the left with 0 and added the decimal part
-                            # without the decinal dot
-                            start_slot_x_formatted = start_x_whole + start_slot_x_formatted[2]
-                            start_slot_y_formatted = start_y_whole + start_slot_y_formatted[2]
-                            stop_slot_x_formatted = stop_x_whole + stop_slot_x_formatted[2]
-                            stop_slot_y_formatted = stop_y_whole + stop_slot_y_formatted[2]
-
-                            if slot_type == 'routing':
-                                excellon_code += "G00X{xstart}Y{ystart}\nM15\n".format(xstart=start_slot_x_formatted,
-                                                                                       ystart=start_slot_y_formatted)
-                                excellon_code += "G01X{xstop}Y{ystop}\nM16\n".format(xstop=stop_slot_x_formatted,
-                                                                                     ystop=stop_slot_y_formatted)
-                            elif slot_type == 'drilling':
-                                excellon_code += "{xstart}Y{ystart}G85X{xstop}Y{ystop}\nG05\n".format(
-                                    xstart=start_slot_x_formatted, ystart=start_slot_y_formatted,
-                                    xstop=stop_slot_x_formatted, ystop=stop_slot_y_formatted
-                                )
-                        elif tool == slot['tool']:
-                            start_slot_x = slot['start'].x * factor
-                            start_slot_y = slot['start'].y * factor
-                            stop_slot_x = slot['stop'].x * factor
-                            stop_slot_y = slot['stop'].y * factor
-                            length = whole + fract
-
-                            start_slot_x_formatted = "{:.{dec}f}".format(start_slot_x, dec=fract).replace('.', '')
-                            start_slot_y_formatted = "{:.{dec}f}".format(start_slot_y, dec=fract).replace('.', '')
-                            stop_slot_x_formatted = "{:.{dec}f}".format(stop_slot_x, dec=fract).replace('.', '')
-                            stop_slot_y_formatted = "{:.{dec}f}".format(stop_slot_y, dec=fract).replace('.', '')
-
-                            # pad with rear zeros
-                            start_slot_x_formatted.ljust(length, '0')
-                            start_slot_y_formatted.ljust(length, '0')
-                            stop_slot_x_formatted.ljust(length, '0')
-                            stop_slot_y_formatted.ljust(length, '0')
-
-                            if slot_type == 'routing':
-                                excellon_code += "G00X{xstart}Y{ystart}\nM15\n".format(xstart=start_slot_x_formatted,
-                                                                                       ystart=start_slot_y_formatted)
-                                excellon_code += "G01X{xstop}Y{ystop}\nM16\n".format(xstop=stop_slot_x_formatted,
-                                                                                     ystop=stop_slot_y_formatted)
-                            elif slot_type == 'drilling':
-                                excellon_code += "{xstart}Y{ystart}G85X{xstop}Y{ystop}\nG05\n".format(
-                                    xstart=start_slot_x_formatted, ystart=start_slot_y_formatted,
-                                    xstop=stop_slot_x_formatted, ystop=stop_slot_y_formatted
-                                )
-        except Exception as e:
-            log.debug(str(e))
-
-        if not self.drills and not self.slots:
-            log.debug("FlatCAMObj.FlatCAMExcellon.export_excellon() --> Excellon Object is empty: no drills, no slots.")
-            return 'fail'
-
-        return has_slots, excellon_code
-
-    def generate_milling_drills(self, tools=None, outname=None, tooldia=None, plot=False, use_thread=False):
-        """
-        Note: This method is a good template for generic operations as
-        it takes it's options from parameters or otherwise from the
-        object's options and returns a (success, msg) tuple as feedback
-        for shell operations.
-
-        :return: Success/failure condition tuple (bool, str).
-        :rtype: tuple
-        """
-
-        # Get the tools from the list. These are keys
-        # to self.tools
-        if tools is None:
-            tools = self.get_selected_tools_list()
-
-        if outname is None:
-            outname = self.options["name"] + "_mill"
-
-        if tooldia is None:
-            tooldia = float(self.options["tooldia"])
-
-        # Sort tools by diameter. items() -> [('name', diameter), ...]
-        # sorted_tools = sorted(list(self.tools.items()), key=lambda tl: tl[1]) # no longer works in Python3
-
-        sort = []
-        for k, v in self.tools.items():
-            sort.append((k, v.get('C')))
-        sorted_tools = sorted(sort, key=lambda t1: t1[1])
-
-        if tools == "all":
-            tools = [i[0] for i in sorted_tools]  # List if ordered tool names.
-            log.debug("Tools 'all' and sorted are: %s" % str(tools))
-
-        if len(tools) == 0:
-            self.app.inform.emit('[ERROR_NOTCL] %s' %
-                                 _("Please select one or more tools from the list and try again."))
-            return False, "Error: No tools."
-
-        for tool in tools:
-            if tooldia > self.tools[tool]["C"]:
-                self.app.inform.emit(
-                    '[ERROR_NOTCL] %s %s: %s' % (
-                        _("Milling tool for DRILLS is larger than hole size. Cancelled."),
-                        _("Tool"),
-                        str(tool)
-                    )
-                )
-                return False, "Error: Milling tool is larger than hole."
-
-        def geo_init(geo_obj, app_obj):
-            assert isinstance(geo_obj, FlatCAMGeometry), \
-                "Initializer expected a FlatCAMGeometry, got %s" % type(geo_obj)
-
-            # ## Add properties to the object
-
-            # get the tool_table items in a list of row items
-            tool_table_items = self.get_selected_tools_table_items()
-            # insert an information only element in the front
-            tool_table_items.insert(0, [_("Tool_nr"), _("Diameter"), _("Drills_Nr"), _("Slots_Nr")])
-
-            geo_obj.options['Tools_in_use'] = tool_table_items
-            geo_obj.options['type'] = 'Excellon Geometry'
-            geo_obj.options["cnctooldia"] = str(tooldia)
-
-            geo_obj.solid_geometry = []
-
-            # in case that the tool used has the same diameter with the hole, and since the maximum resolution
-            # for FlatCAM is 6 decimals,
-            # we add a tenth of the minimum value, meaning 0.0000001, which from our point of view is "almost zero"
-            for hole in self.drills:
-                if hole['tool'] in tools:
-                    buffer_value = self.tools[hole['tool']]["C"] / 2 - tooldia / 2
-                    if buffer_value == 0:
-                        geo_obj.solid_geometry.append(
-                            Point(hole['point']).buffer(0.0000001).exterior)
-                    else:
-                        geo_obj.solid_geometry.append(
-                            Point(hole['point']).buffer(buffer_value).exterior)
-        if use_thread:
-            def geo_thread(app_obj):
-                app_obj.new_object("geometry", outname, geo_init, plot=plot)
-
-            # Create a promise with the new name
-            self.app.collection.promise(outname)
-
-            # Send to worker
-            self.app.worker_task.emit({'fcn': geo_thread, 'params': [self.app]})
-        else:
-            self.app.new_object("geometry", outname, geo_init, plot=plot)
-
-        return True, ""
-
-    def generate_milling_slots(self, tools=None, outname=None, tooldia=None, plot=True, use_thread=False):
-        """
-        Note: This method is a good template for generic operations as
-        it takes it's options from parameters or otherwise from the
-        object's options and returns a (success, msg) tuple as feedback
-        for shell operations.
-
-        :return: Success/failure condition tuple (bool, str).
-        :rtype: tuple
-        """
-
-        # Get the tools from the list. These are keys
-        # to self.tools
-        if tools is None:
-            tools = self.get_selected_tools_list()
-
-        if outname is None:
-            outname = self.options["name"] + "_mill"
-
-        if tooldia is None:
-            tooldia = float(self.options["slot_tooldia"])
-
-        # Sort tools by diameter. items() -> [('name', diameter), ...]
-        # sorted_tools = sorted(list(self.tools.items()), key=lambda tl: tl[1]) # no longer works in Python3
-
-        sort = []
-        for k, v in self.tools.items():
-            sort.append((k, v.get('C')))
-        sorted_tools = sorted(sort, key=lambda t1: t1[1])
-
-        if tools == "all":
-            tools = [i[0] for i in sorted_tools]  # List if ordered tool names.
-            log.debug("Tools 'all' and sorted are: %s" % str(tools))
-
-        if len(tools) == 0:
-            self.app.inform.emit('[ERROR_NOTCL] %s' %
-                                 _("Please select one or more tools from the list and try again."))
-            return False, "Error: No tools."
-
-        for tool in tools:
-            # I add the 0.0001 value to account for the rounding error in converting from IN to MM and reverse
-            adj_toolstable_tooldia = float('%.*f' % (self.decimals, float(tooldia)))
-            adj_file_tooldia = float('%.*f' % (self.decimals, float(self.tools[tool]["C"])))
-            if adj_toolstable_tooldia > adj_file_tooldia + 0.0001:
-                self.app.inform.emit('[ERROR_NOTCL] %s' %
-                                     _("Milling tool for SLOTS is larger than hole size. Cancelled."))
-                return False, "Error: Milling tool is larger than hole."
-
-        def geo_init(geo_obj, app_obj):
-            assert isinstance(geo_obj, FlatCAMGeometry), \
-                "Initializer expected a FlatCAMGeometry, got %s" % type(geo_obj)
-
-            # ## Add properties to the object
-
-            # get the tool_table items in a list of row items
-            tool_table_items = self.get_selected_tools_table_items()
-            # insert an information only element in the front
-            tool_table_items.insert(0, [_("Tool_nr"), _("Diameter"), _("Drills_Nr"), _("Slots_Nr")])
-
-            geo_obj.options['Tools_in_use'] = tool_table_items
-            geo_obj.options['type'] = 'Excellon Geometry'
-            geo_obj.options["cnctooldia"] = str(tooldia)
-
-            geo_obj.solid_geometry = []
-
-            # in case that the tool used has the same diameter with the hole, and since the maximum resolution
-            # for FlatCAM is 6 decimals,
-            # we add a tenth of the minimum value, meaning 0.0000001, which from our point of view is "almost zero"
-            for slot in self.slots:
-                if slot['tool'] in tools:
-                    toolstable_tool = float('%.*f' % (self.decimals, float(tooldia)))
-                    file_tool = float('%.*f' % (self.decimals, float(self.tools[tool]["C"])))
-
-                    # I add the 0.0001 value to account for the rounding error in converting from IN to MM and reverse
-                    # for the file_tool (tooldia actually)
-                    buffer_value = float(file_tool / 2) - float(toolstable_tool / 2) + 0.0001
-                    if buffer_value == 0:
-                        start = slot['start']
-                        stop = slot['stop']
-
-                        lines_string = LineString([start, stop])
-                        poly = lines_string.buffer(0.0000001, int(self.geo_steps_per_circle)).exterior
-                        geo_obj.solid_geometry.append(poly)
-                    else:
-                        start = slot['start']
-                        stop = slot['stop']
-
-                        lines_string = LineString([start, stop])
-                        poly = lines_string.buffer(buffer_value, int(self.geo_steps_per_circle)).exterior
-                        geo_obj.solid_geometry.append(poly)
-
-        if use_thread:
-            def geo_thread(app_obj):
-                app_obj.new_object("geometry", outname + '_slot', geo_init, plot=plot)
-
-            # Create a promise with the new name
-            self.app.collection.promise(outname)
-
-            # Send to worker
-            self.app.worker_task.emit({'fcn': geo_thread, 'params': [self.app]})
-        else:
-            self.app.new_object("geometry", outname + '_slot', geo_init, plot=plot)
-
-        return True, ""
-
-    def on_generate_milling_button_click(self, *args):
-        self.app.report_usage("excellon_on_create_milling_drills button")
-        self.read_form()
-
-        self.generate_milling_drills(use_thread=False)
-
-    def on_generate_milling_slots_button_click(self, *args):
-        self.app.report_usage("excellon_on_create_milling_slots_button")
-        self.read_form()
-
-        self.generate_milling_slots(use_thread=False)
-
-    def on_pp_changed(self):
-        current_pp = self.ui.pp_excellon_name_cb.get_value()
-
-        if "toolchange_probe" in current_pp.lower():
-            self.ui.pdepth_entry.setVisible(True)
-            self.ui.pdepth_label.show()
-
-            self.ui.feedrate_probe_entry.setVisible(True)
-            self.ui.feedrate_probe_label.show()
-        else:
-            self.ui.pdepth_entry.setVisible(False)
-            self.ui.pdepth_label.hide()
-
-            self.ui.feedrate_probe_entry.setVisible(False)
-            self.ui.feedrate_probe_label.hide()
-
-        if 'marlin' in current_pp.lower() or 'custom' in current_pp.lower():
-            self.ui.feedrate_rapid_label.show()
-            self.ui.feedrate_rapid_entry.show()
-        else:
-            self.ui.feedrate_rapid_label.hide()
-            self.ui.feedrate_rapid_entry.hide()
-
-        if 'laser' in current_pp.lower():
-            self.ui.cutzlabel.hide()
-            self.ui.cutz_entry.hide()
-            try:
-                self.ui.mpass_cb.hide()
-                self.ui.maxdepth_entry.hide()
-            except AttributeError:
-                pass
-
-            if 'marlin' in current_pp.lower():
-                self.ui.travelzlabel.setText('%s:' % _("Focus Z"))
-                self.ui.endz_label.show()
-                self.ui.endz_entry.show()
-            else:
-                self.ui.travelzlabel.hide()
-                self.ui.travelz_entry.hide()
-
-                self.ui.endz_label.hide()
-                self.ui.endz_entry.hide()
-
-            try:
-                self.ui.frzlabel.hide()
-                self.ui.feedrate_z_entry.hide()
-            except AttributeError:
-                pass
-
-            self.ui.dwell_cb.hide()
-            self.ui.dwelltime_entry.hide()
-
-            self.ui.spindle_label.setText('%s:' % _("Laser Power"))
-
-            try:
-                self.ui.tool_offset_label.hide()
-                self.ui.offset_entry.hide()
-            except AttributeError:
-                pass
-        else:
-            self.ui.cutzlabel.show()
-            self.ui.cutz_entry.show()
-            try:
-                self.ui.mpass_cb.show()
-                self.ui.maxdepth_entry.show()
-            except AttributeError:
-                pass
-
-            self.ui.travelzlabel.setText('%s:' % _('Travel Z'))
-
-            self.ui.travelzlabel.show()
-            self.ui.travelz_entry.show()
-
-            self.ui.endz_label.show()
-            self.ui.endz_entry.show()
-
-            try:
-                self.ui.frzlabel.show()
-                self.ui.feedrate_z_entry.show()
-            except AttributeError:
-                pass
-            self.ui.dwell_cb.show()
-            self.ui.dwelltime_entry.show()
-
-            self.ui.spindle_label.setText('%s:' % _('Spindle speed'))
-
-            try:
-                self.ui.tool_offset_lbl.show()
-                self.ui.offset_entry.show()
-            except AttributeError:
-                pass
-
-    def on_create_cncjob_button_click(self, *args):
-        self.app.report_usage("excellon_on_create_cncjob_button")
-        self.read_form()
-
-        # Get the tools from the list
-        tools = self.get_selected_tools_list()
-
-        if len(tools) == 0:
-            # if there is a single tool in the table (remember that the last 2 rows are for totals and do not count in
-            # tool number) it means that there are 3 rows (1 tool and 2 totals).
-            # in this case regardless of the selection status of that tool, use it.
-            if self.ui.tools_table.rowCount() == 3:
-                tools.append(self.ui.tools_table.item(0, 0).text())
-            else:
-                self.app.inform.emit('[ERROR_NOTCL] %s' %
-                                     _("Please select one or more tools from the list and try again."))
-                return
-
-        xmin = self.options['xmin']
-        ymin = self.options['ymin']
-        xmax = self.options['xmax']
-        ymax = self.options['ymax']
-
-        job_name = self.options["name"] + "_cnc"
-        pp_excellon_name = self.options["ppname_e"]
-
-        # Object initialization function for app.new_object()
-        def job_init(job_obj, app_obj):
-            assert isinstance(job_obj, FlatCAMCNCjob), \
-                "Initializer expected a FlatCAMCNCjob, got %s" % type(job_obj)
-
-            # get the tool_table items in a list of row items
-            tool_table_items = self.get_selected_tools_table_items()
-            # insert an information only element in the front
-            tool_table_items.insert(0, [_("Tool_nr"), _("Diameter"), _("Drills_Nr"), _("Slots_Nr")])
-
-            # ## Add properties to the object
-
-            job_obj.origin_kind = 'excellon'
-
-            job_obj.options['Tools_in_use'] = tool_table_items
-            job_obj.options['type'] = 'Excellon'
-            job_obj.options['ppname_e'] = pp_excellon_name
-
-            job_obj.multidepth = self.options["multidepth"]
-            job_obj.z_depthpercut = self.options["depthperpass"]
-
-            job_obj.z_move = float(self.options["travelz"])
-            job_obj.feedrate = float(self.options["feedrate_z"])
-            job_obj.z_feedrate = float(self.options["feedrate_z"])
-            job_obj.feedrate_rapid = float(self.options["feedrate_rapid"])
-
-            job_obj.spindlespeed = float(self.options["spindlespeed"]) if self.options["spindlespeed"] != 0 else None
-            job_obj.spindledir = self.app.defaults['excellon_spindledir']
-            job_obj.dwell = self.options["dwell"]
-            job_obj.dwelltime = float(self.options["dwelltime"])
-
-            job_obj.pp_excellon_name = pp_excellon_name
-
-            job_obj.toolchange_xy_type = "excellon"
-            job_obj.coords_decimals = int(self.app.defaults["cncjob_coords_decimals"])
-            job_obj.fr_decimals = int(self.app.defaults["cncjob_fr_decimals"])
-
-            job_obj.options['xmin'] = xmin
-            job_obj.options['ymin'] = ymin
-            job_obj.options['xmax'] = xmax
-            job_obj.options['ymax'] = ymax
-
-            job_obj.z_pdepth = float(self.options["z_pdepth"])
-            job_obj.feedrate_probe = float(self.options["feedrate_probe"])
-
-            job_obj.z_cut = float(self.options['cutz'])
-            job_obj.toolchange = self.options["toolchange"]
-            job_obj.xy_toolchange = self.app.defaults["excellon_toolchangexy"]
-            job_obj.z_toolchange = float(self.options["toolchangez"])
-            job_obj.startz = float(self.options["startz"]) if self.options["startz"] else None
-            job_obj.endz = float(self.options["endz"])
-            job_obj.xy_end = self.options["endxy"]
-            job_obj.excellon_optimization_type = self.app.defaults["excellon_optimization_type"]
-
-            tools_csv = ','.join(tools)
-            ret_val = job_obj.generate_from_excellon_by_tool(self, tools_csv, use_ui=True)
-
-            if ret_val == 'fail':
-                return 'fail'
-
-            job_obj.gcode_parse()
-            job_obj.create_geometry()
-
-        # To be run in separate thread
-        def job_thread(app_obj):
-            with self.app.proc_container.new(_("Generating CNC Code")):
-                app_obj.new_object("cncjob", job_name, job_init)
-
-        # Create promise for the new name.
-        self.app.collection.promise(job_name)
-
-        # Send to worker
-        # self.app.worker.add_task(job_thread, [self.app])
-        self.app.worker_task.emit({'fcn': job_thread, 'params': [self.app]})
-
-    def convert_units(self, units):
-        log.debug("FlatCAMObj.FlatCAMExcellon.convert_units()")
-
-        Excellon.convert_units(self, units)
-
-        # factor = Excellon.convert_units(self, units)
-        # self.options['drillz'] = float(self.options['drillz']) * factor
-        # self.options['travelz'] = float(self.options['travelz']) * factor
-        # self.options['feedrate'] = float(self.options['feedrate']) * factor
-        # self.options['feedrate_rapid'] = float(self.options['feedrate_rapid']) * factor
-        # self.options['toolchangez'] = float(self.options['toolchangez']) * factor
-        #
-        # if self.app.defaults["excellon_toolchangexy"] == '':
-        #     self.options['toolchangexy'] = "0.0, 0.0"
-        # else:
-        #     coords_xy = [float(eval(coord)) for coord in self.app.defaults["excellon_toolchangexy"].split(",")]
-        #     if len(coords_xy) < 2:
-        #         self.app.inform.emit('[ERROR] %s' % _("The Toolchange X,Y field in Edit -> Preferences has to be "
-        #                                               "in the format (x, y) \n"
-        #                                               "but now there is only one value, not two. "))
-        #         return 'fail'
-        #     coords_xy[0] *= factor
-        #     coords_xy[1] *= factor
-        #     self.options['toolchangexy'] = "%f, %f" % (coords_xy[0], coords_xy[1])
-        #
-        # if self.options['startz'] is not None:
-        #     self.options['startz'] = float(self.options['startz']) * factor
-        # self.options['endz'] = float(self.options['endz']) * factor
-
-    def on_solid_cb_click(self, *args):
-        if self.muted_ui:
-            return
-        self.read_form_item('solid')
-        self.plot()
-
-    def on_plot_cb_click(self, *args):
-        if self.muted_ui:
-            return
-        self.plot()
-        self.read_form_item('plot')
-
-        self.ui_disconnect()
-        cb_flag = self.ui.plot_cb.isChecked()
-        for row in range(self.ui.tools_table.rowCount() - 2):
-            table_cb = self.ui.tools_table.cellWidget(row, 5)
-            if cb_flag:
-                table_cb.setChecked(True)
-            else:
-                table_cb.setChecked(False)
-
-        self.ui_connect()
-
-    def on_plot_cb_click_table(self):
-        # self.ui.cnc_tools_table.cellWidget(row, 2).widget().setCheckState(QtCore.Qt.Unchecked)
-        self.ui_disconnect()
-        # cw = self.sender()
-        # cw_index = self.ui.tools_table.indexAt(cw.pos())
-        # cw_row = cw_index.row()
-        check_row = 0
-
-        self.shapes.clear(update=True)
-        for tool_key in self.tools:
-            solid_geometry = self.tools[tool_key]['solid_geometry']
-
-            # find the geo_tool_table row associated with the tool_key
-            for row in range(self.ui.tools_table.rowCount()):
-                tool_item = int(self.ui.tools_table.item(row, 0).text())
-                if tool_item == int(tool_key):
-                    check_row = row
-                    break
-            if self.ui.tools_table.cellWidget(check_row, 5).isChecked():
-                self.options['plot'] = True
-                # self.plot_element(element=solid_geometry, visible=True)
-                # Plot excellon (All polygons?)
-                if self.options["solid"]:
-                    for geo in solid_geometry:
-                        self.add_shape(shape=geo, color='#750000BF', face_color='#C40000BF',
-                                       visible=self.options['plot'],
-                                       layer=2)
-                else:
-                    for geo in solid_geometry:
-                        self.add_shape(shape=geo.exterior, color='red', visible=self.options['plot'])
-                        for ints in geo.interiors:
-                            self.add_shape(shape=ints, color='green', visible=self.options['plot'])
-        self.shapes.redraw()
-
-        # make sure that the general plot is disabled if one of the row plot's are disabled and
-        # if all the row plot's are enabled also enable the general plot checkbox
-        cb_cnt = 0
-        total_row = self.ui.tools_table.rowCount()
-        for row in range(total_row - 2):
-            if self.ui.tools_table.cellWidget(row, 5).isChecked():
-                cb_cnt += 1
-            else:
-                cb_cnt -= 1
-        if cb_cnt < total_row - 2:
-            self.ui.plot_cb.setChecked(False)
-        else:
-            self.ui.plot_cb.setChecked(True)
-        self.ui_connect()
-
-    def plot(self, visible=None, kind=None):
-
-        # Does all the required setup and returns False
-        # if the 'ptint' option is set to False.
-        if not FlatCAMObj.plot(self):
-            return
-
-        # try:
-        #     # Plot Excellon (All polygons?)
-        #     if self.options["solid"]:
-        #         for tool in self.tools:
-        #             for geo in self.tools[tool]['solid_geometry']:
-        #                 self.add_shape(shape=geo, color='#750000BF', face_color='#C40000BF',
-        #                                visible=self.options['plot'],
-        #                                layer=2)
-        #     else:
-        #         for tool in self.tools:
-        #             for geo in self.tools[tool]['solid_geometry']:
-        #                 self.add_shape(shape=geo.exterior, color='red', visible=self.options['plot'])
-        #                 for ints in geo.interiors:
-        #                     self.add_shape(shape=ints, color='orange', visible=self.options['plot'])
-        #
-        #     self.shapes.redraw()
-        #     return
-        # except (ObjectDeleted, AttributeError, KeyError):
-        #     self.shapes.clear(update=True)
-
-        # this stays for compatibility reasons, in case we try to open old projects
-        try:
-            __ = iter(self.solid_geometry)
-        except TypeError:
-            self.solid_geometry = [self.solid_geometry]
-
-        visible = visible if visible else self.options['plot']
-
-        try:
-            # Plot Excellon (All polygons?)
-            if self.options["solid"]:
-                for geo in self.solid_geometry:
-                    self.add_shape(shape=geo,
-                                   color=self.outline_color,
-                                   face_color=self.fill_color,
-                                   visible=visible,
-                                   layer=2)
-            else:
-                for geo in self.solid_geometry:
-                    self.add_shape(shape=geo.exterior, color='red', visible=visible)
-                    for ints in geo.interiors:
-                        self.add_shape(shape=ints, color='orange', visible=visible)
-
-            self.shapes.redraw()
-        except (ObjectDeleted, AttributeError):
-            self.shapes.clear(update=True)
-
-    def on_apply_param_to_all_clicked(self):
-        if self.ui.tools_table.rowCount() == 0:
-            # there is no tool in tool table so we can't save the GUI elements values to storage
-            log.debug("FlatCAMExcellon.on_apply_param_to_all_clicked() --> no tool in Tools Table, aborting.")
-            return
-
-        self.ui_disconnect()
-
-        row = self.ui.tools_table.currentRow()
-        if row < 0:
-            row = 0
-
-        tooluid_item = int(self.ui.tools_table.item(row, 0).text())
-        temp_tool_data = {}
-
-        for tooluid_key, tooluid_val in self.tools.items():
-            if int(tooluid_key) == tooluid_item:
-                # this will hold the 'data' key of the self.tools[tool] dictionary that corresponds to
-                # the current row in the tool table
-                temp_tool_data = tooluid_val['data']
-                break
-
-        for tooluid_key, tooluid_val in self.tools.items():
-            tooluid_val['data'] = deepcopy(temp_tool_data)
-
-        self.app.inform.emit('[success] %s' % _("Current Tool parameters were applied to all tools."))
-
-        self.ui_connect()
-
-
-class FlatCAMGeometry(FlatCAMObj, Geometry):
-    """
-    Geometric object not associated with a specific
-    format.
-    """
-    optionChanged = QtCore.pyqtSignal(str)
-    ui_type = GeometryObjectUI
-
-    def __init__(self, name):
-        self.decimals = self.app.decimals
-
-        self.circle_steps = int(self.app.defaults["geometry_circle_steps"])
-
-        FlatCAMObj.__init__(self, name)
-        Geometry.__init__(self, geo_steps_per_circle=self.circle_steps)
-
-        self.kind = "geometry"
-
-        self.options.update({
-            "plot": True,
-            "cutz": -0.002,
-            "vtipdia": 0.1,
-            "vtipangle": 30,
-            "travelz": 0.1,
-            "feedrate": 5.0,
-            "feedrate_z": 5.0,
-            "feedrate_rapid": 5.0,
-            "spindlespeed": 0,
-            "dwell": True,
-            "dwelltime": 1000,
-            "multidepth": False,
-            "depthperpass": 0.002,
-            "extracut": False,
-            "extracut_length": 0.1,
-            "endz": 2.0,
-            "endxy": '',
-
-            "startz": None,
-            "toolchange": False,
-            "toolchangez": 1.0,
-            "toolchangexy": "0.0, 0.0",
-            "ppname_g": 'default',
-            "z_pdepth": -0.02,
-            "feedrate_probe": 3.0,
-        })
-
-        if "cnctooldia" not in self.options:
-            if type(self.app.defaults["geometry_cnctooldia"]) == float:
-                self.options["cnctooldia"] = self.app.defaults["geometry_cnctooldia"]
-            else:
-                try:
-                    tools_string = self.app.defaults["geometry_cnctooldia"].split(",")
-                    tools_diameters = [eval(a) for a in tools_string if a != '']
-                    self.options["cnctooldia"] = tools_diameters[0] if tools_diameters else 0.0
-                except Exception as e:
-                    log.debug("FlatCAMObj.FlatCAMGeometry.init() --> %s" % str(e))
-
-        self.options["startz"] = self.app.defaults["geometry_startz"]
-
-        # this will hold the tool unique ID that is useful when having multiple tools with same diameter
-        self.tooluid = 0
-
-        '''
-            self.tools = {}
-            This is a dictionary. Each dict key is associated with a tool used in geo_tools_table. The key is the 
-            tool_id of the tools and the value is another dict that will hold the data under the following form:
-                {tooluid:   {
-                            'tooldia': 1,
-                            'offset': 'Path',
-                            'offset_value': 0.0
-                            'type': 'Rough',
-                            'tool_type': 'C1',
-                            'data': self.default_tool_data
-                            'solid_geometry': []
-                            }
-                }
-        '''
-        self.tools = {}
-
-        # this dict is to store those elements (tools) of self.tools that are selected in the self.geo_tools_table
-        # those elements are the ones used for generating GCode
-        self.sel_tools = {}
-
-        self.offset_item_options = ["Path", "In", "Out", "Custom"]
-        self.type_item_options = [_("Iso"), _("Rough"), _("Finish")]
-        self.tool_type_item_options = ["C1", "C2", "C3", "C4", "B", "V"]
-
-        # flag to store if the V-Shape tool is selected in self.ui.geo_tools_table
-        self.v_tool_type = None
-
-        # flag to store if the Geometry is type 'multi-geometry' meaning that each tool has it's own geometry
-        # the default value is False
-        self.multigeo = False
-
-        # flag to store if the geometry is part of a special group of geometries that can't be processed by the default
-        # engine of FlatCAM. Most likely are generated by some of tools and are special cases of geometries.
-        self.special_group = None
-
-        self.old_pp_state = self.app.defaults["geometry_multidepth"]
-        self.old_toolchangeg_state = self.app.defaults["geometry_toolchange"]
-        self.units_found = self.app.defaults['units']
-
-        # this variable can be updated by the Object that generates the geometry
-        self.tool_type = 'C1'
-
-        # save here the old value for the Cut Z before it is changed by selecting a V-shape type tool in the tool table
-        self.old_cutz = self.app.defaults["geometry_cutz"]
-
-        self.fill_color = self.app.defaults['geometry_plot_line']
-        self.outline_color = self.app.defaults['geometry_plot_line']
-        self.alpha_level = 'FF'
-
-        self.param_fields = {}
-
-        # Attributes to be included in serialization
-        # Always append to it because it carries contents
-        # from predecessors.
-        self.ser_attrs += ['options', 'kind', 'tools', 'multigeo']
-
-    def build_ui(self):
-        self.ui_disconnect()
-        FlatCAMObj.build_ui(self)
-
-        self.units = self.app.defaults['units']
-
-        tool_idx = 0
-
-        n = len(self.tools)
-        self.ui.geo_tools_table.setRowCount(n)
-
-        for tooluid_key, tooluid_value in self.tools.items():
-            tool_idx += 1
-            row_no = tool_idx - 1
-
-            tool_id = QtWidgets.QTableWidgetItem('%d' % int(tool_idx))
-            tool_id.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
-            self.ui.geo_tools_table.setItem(row_no, 0, tool_id)  # Tool name/id
-
-            # Make sure that the tool diameter when in MM is with no more than 2 decimals.
-            # There are no tool bits in MM with more than 3 decimals diameter.
-            # For INCH the decimals should be no more than 3. There are no tools under 10mils.
-
-            dia_item = QtWidgets.QTableWidgetItem('%.*f' % (self.decimals, float(tooluid_value['tooldia'])))
-
-            dia_item.setFlags(QtCore.Qt.ItemIsEnabled)
-
-            offset_item = FCComboBox()
-            for item in self.offset_item_options:
-                offset_item.addItem(item)
-            # offset_item.setStyleSheet('background-color: rgb(255,255,255)')
-            idx = offset_item.findText(tooluid_value['offset'])
-            offset_item.setCurrentIndex(idx)
-
-            type_item = FCComboBox()
-            for item in self.type_item_options:
-                type_item.addItem(item)
-            # type_item.setStyleSheet('background-color: rgb(255,255,255)')
-            idx = type_item.findText(tooluid_value['type'])
-            type_item.setCurrentIndex(idx)
-
-            tool_type_item = FCComboBox()
-            for item in self.tool_type_item_options:
-                tool_type_item.addItem(item)
-                # tool_type_item.setStyleSheet('background-color: rgb(255,255,255)')
-            idx = tool_type_item.findText(tooluid_value['tool_type'])
-            tool_type_item.setCurrentIndex(idx)
-
-            tool_uid_item = QtWidgets.QTableWidgetItem(str(tooluid_key))
-
-            plot_item = FCCheckBox()
-            plot_item.setLayoutDirection(QtCore.Qt.RightToLeft)
-            if self.ui.plot_cb.isChecked():
-                plot_item.setChecked(True)
-
-            self.ui.geo_tools_table.setItem(row_no, 1, dia_item)  # Diameter
-            self.ui.geo_tools_table.setCellWidget(row_no, 2, offset_item)
-            self.ui.geo_tools_table.setCellWidget(row_no, 3, type_item)
-            self.ui.geo_tools_table.setCellWidget(row_no, 4, tool_type_item)
-
-            # ## REMEMBER: THIS COLUMN IS HIDDEN IN OBJECTUI.PY ###
-            self.ui.geo_tools_table.setItem(row_no, 5, tool_uid_item)  # Tool unique ID
-            self.ui.geo_tools_table.setCellWidget(row_no, 6, plot_item)
-
-            try:
-                self.ui.tool_offset_entry.set_value(tooluid_value['offset_value'])
-            except Exception as e:
-                log.debug("build_ui() --> Could not set the 'offset_value' key in self.tools. Error: %s" % str(e))
-
-        # make the diameter column editable
-        for row in range(tool_idx):
-            self.ui.geo_tools_table.item(row, 1).setFlags(QtCore.Qt.ItemIsSelectable |
-                                                          QtCore.Qt.ItemIsEditable |
-                                                          QtCore.Qt.ItemIsEnabled)
-
-        # sort the tool diameter column
-        # self.ui.geo_tools_table.sortItems(1)
-        # all the tools are selected by default
-        # self.ui.geo_tools_table.selectColumn(0)
-
-        self.ui.geo_tools_table.resizeColumnsToContents()
-        self.ui.geo_tools_table.resizeRowsToContents()
-
-        vertical_header = self.ui.geo_tools_table.verticalHeader()
-        # vertical_header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
-        vertical_header.hide()
-        self.ui.geo_tools_table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
-
-        horizontal_header = self.ui.geo_tools_table.horizontalHeader()
-        horizontal_header.setMinimumSectionSize(10)
-        horizontal_header.setDefaultSectionSize(70)
-        horizontal_header.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
-        horizontal_header.resizeSection(0, 20)
-        horizontal_header.setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
-        # horizontal_header.setColumnWidth(2, QtWidgets.QHeaderView.ResizeToContents)
-        horizontal_header.setSectionResizeMode(3, QtWidgets.QHeaderView.ResizeToContents)
-        horizontal_header.setSectionResizeMode(4, QtWidgets.QHeaderView.Fixed)
-        horizontal_header.resizeSection(4, 40)
-        horizontal_header.setSectionResizeMode(6, QtWidgets.QHeaderView.Fixed)
-        horizontal_header.resizeSection(4, 17)
-        # horizontal_header.setStretchLastSection(True)
-        self.ui.geo_tools_table.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
-
-        self.ui.geo_tools_table.setColumnWidth(0, 20)
-        self.ui.geo_tools_table.setColumnWidth(4, 40)
-        self.ui.geo_tools_table.setColumnWidth(6, 17)
-
-        # self.ui.geo_tools_table.setSortingEnabled(True)
-
-        self.ui.geo_tools_table.setMinimumHeight(self.ui.geo_tools_table.getHeight())
-        self.ui.geo_tools_table.setMaximumHeight(self.ui.geo_tools_table.getHeight())
-
-        # update UI for all rows - useful after units conversion but only if there is at least one row
-        row_cnt = self.ui.geo_tools_table.rowCount()
-        if row_cnt > 0:
-            for r in range(row_cnt):
-                self.update_ui(r)
-
-        # select only the first tool / row
-        selected_row = 0
-        try:
-            self.select_tools_table_row(selected_row, clearsel=True)
-            # update the Geometry UI
-            self.update_ui()
-        except Exception as e:
-            # when the tools table is empty there will be this error but once the table is populated it will go away
-            log.debug(str(e))
-
-        # disable the Plot column in Tool Table if the geometry is SingleGeo as it is not needed
-        # and can create some problems
-        if self.multigeo is False:
-            self.ui.geo_tools_table.setColumnHidden(6, True)
-        else:
-            self.ui.geo_tools_table.setColumnHidden(6, False)
-
-        self.set_tool_offset_visibility(selected_row)
-
-        # HACK: for whatever reasons the name in Selected tab is reverted to the original one after a successful rename
-        # done in the collection view but only for Geometry objects. Perhaps some references remains. Should be fixed.
-        self.ui.name_entry.set_value(self.options['name'])
-        self.ui_connect()
-
-        self.ui.e_cut_entry.setDisabled(False) if self.ui.extracut_cb.get_value() else \
-            self.ui.e_cut_entry.setDisabled(True)
-
-        # set the text on tool_data_label after loading the object
-        sel_rows = []
-        sel_items = self.ui.geo_tools_table.selectedItems()
-        for it in sel_items:
-            sel_rows.append(it.row())
-        if len(sel_rows) > 1:
-            self.ui.tool_data_label.setText(
-                "<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("Multiple Tools"))
-            )
-
-    def set_ui(self, ui):
-        FlatCAMObj.set_ui(self, ui)
-
-        log.debug("FlatCAMGeometry.set_ui()")
-
-        assert isinstance(self.ui, GeometryObjectUI), \
-            "Expected a GeometryObjectUI, got %s" % type(self.ui)
-
-        self.units = self.app.defaults['units'].upper()
-        self.units_found = self.app.defaults['units']
-
-        # populate preprocessor names in the combobox
-        for name in list(self.app.preprocessors.keys()):
-            self.ui.pp_geometry_name_cb.addItem(name)
-
-        self.form_fields.update({
-            "plot": self.ui.plot_cb,
-            "cutz": self.ui.cutz_entry,
-            "vtipdia": self.ui.tipdia_entry,
-            "vtipangle": self.ui.tipangle_entry,
-            "travelz": self.ui.travelz_entry,
-            "feedrate": self.ui.cncfeedrate_entry,
-            "feedrate_z": self.ui.feedrate_z_entry,
-            "feedrate_rapid": self.ui.feedrate_rapid_entry,
-            "spindlespeed": self.ui.cncspindlespeed_entry,
-            "dwell": self.ui.dwell_cb,
-            "dwelltime": self.ui.dwelltime_entry,
-            "multidepth": self.ui.mpass_cb,
-            "ppname_g": self.ui.pp_geometry_name_cb,
-            "z_pdepth": self.ui.pdepth_entry,
-            "feedrate_probe": self.ui.feedrate_probe_entry,
-            "depthperpass": self.ui.maxdepth_entry,
-            "extracut": self.ui.extracut_cb,
-            "extracut_length": self.ui.e_cut_entry,
-            "toolchange": self.ui.toolchangeg_cb,
-            "toolchangez": self.ui.toolchangez_entry,
-            "endz": self.ui.endz_entry,
-            "endxy": self.ui.endxy_entry,
-            "cnctooldia": self.ui.addtool_entry
-        })
-
-        self.param_fields.update({
-            "vtipdia": self.ui.tipdia_entry,
-            "vtipangle": self.ui.tipangle_entry,
-            "cutz": self.ui.cutz_entry,
-            "depthperpass": self.ui.maxdepth_entry,
-            "multidepth": self.ui.mpass_cb,
-            "travelz": self.ui.travelz_entry,
-            "feedrate": self.ui.cncfeedrate_entry,
-            "feedrate_z": self.ui.feedrate_z_entry,
-            "feedrate_rapid": self.ui.feedrate_rapid_entry,
-            "extracut": self.ui.extracut_cb,
-            "extracut_length": self.ui.e_cut_entry,
-            "spindlespeed": self.ui.cncspindlespeed_entry,
-            "dwelltime": self.ui.dwelltime_entry,
-            "dwell": self.ui.dwell_cb,
-            "pdepth": self.ui.pdepth_entry,
-            "pfeedrate": self.ui.feedrate_probe_entry,
-        })
-        # Fill form fields only on object create
-        self.to_form()
-
-        # update the changes in UI depending on the selected preprocessor in Preferences
-        # after this moment all the changes in the Posprocessor combo will be handled by the activated signal of the
-        # self.ui.pp_geometry_name_cb combobox
-        self.on_pp_changed()
-
-        self.ui.tipdialabel.hide()
-        self.ui.tipdia_entry.hide()
-        self.ui.tipanglelabel.hide()
-        self.ui.tipangle_entry.hide()
-        self.ui.cutz_entry.setDisabled(False)
-
-        # store here the default data for Geometry Data
-        self.default_data = {}
-        self.default_data.update({
-            "name": None,
-            "plot": None,
-            "cutz": None,
-            "vtipdia": None,
-            "vtipangle": None,
-            "travelz": None,
-            "feedrate": None,
-            "feedrate_z": None,
-            "feedrate_rapid": None,
-            "dwell": None,
-            "dwelltime": None,
-            "multidepth": None,
-            "ppname_g": None,
-            "depthperpass": None,
-            "extracut": None,
-            "extracut_length": None,
-            "toolchange": None,
-            "toolchangez": None,
-            "endz": None,
-            "endxy": '',
-            "spindlespeed": 0,
-            "toolchangexy": None,
-            "startz": None
-        })
-
-        # fill in self.default_data values from self.options
-        for def_key in self.default_data:
-            for opt_key, opt_val in self.options.items():
-                if def_key == opt_key:
-                    self.default_data[def_key] = deepcopy(opt_val)
-
-        if type(self.options["cnctooldia"]) == float:
-            tools_list = [self.options["cnctooldia"]]
-        else:
-            try:
-                temp_tools = self.options["cnctooldia"].split(",")
-                tools_list = [
-                    float(eval(dia)) for dia in temp_tools if dia != ''
-                ]
-            except Exception as e:
-                log.error("FlatCAMGeometry.set_ui() -> At least one tool diameter needed. "
-                          "Verify in Edit -> Preferences -> Geometry General -> Tool dia. %s" % str(e))
-                return
-
-        self.tooluid += 1
-
-        if not self.tools:
-            for toold in tools_list:
-                new_data = deepcopy(self.default_data)
-                self.tools.update({
-                    self.tooluid: {
-                        'tooldia': float('%.*f' % (self.decimals, float(toold))),
-                        'offset': 'Path',
-                        'offset_value': 0.0,
-                        'type': _('Rough'),
-                        'tool_type': self.tool_type,
-                        'data': new_data,
-                        'solid_geometry': self.solid_geometry
-                    }
-                })
-                self.tooluid += 1
-        else:
-            # if self.tools is not empty then it can safely be assumed that it comes from an opened project.
-            # Because of the serialization the self.tools list on project save, the dict keys (members of self.tools
-            # are each a dict) are turned into strings so we rebuild the self.tools elements so the keys are
-            # again float type; dict's don't like having keys changed when iterated through therefore the need for the
-            # following convoluted way of changing the keys from string to float type
-            temp_tools = {}
-            for tooluid_key in self.tools:
-                val = deepcopy(self.tools[tooluid_key])
-                new_key = deepcopy(int(tooluid_key))
-                temp_tools[new_key] = val
-
-            self.tools.clear()
-            self.tools = deepcopy(temp_tools)
-
-        self.ui.tool_offset_entry.hide()
-        self.ui.tool_offset_lbl.hide()
-
-        # used to store the state of the mpass_cb if the selected preprocessor for geometry is hpgl
-        self.old_pp_state = self.default_data['multidepth']
-        self.old_toolchangeg_state = self.default_data['toolchange']
-
-        if not isinstance(self.ui, GeometryObjectUI):
-            log.debug("Expected a GeometryObjectUI, got %s" % type(self.ui))
-            return
-
-        self.ui.geo_tools_table.setupContextMenu()
-        self.ui.geo_tools_table.addContextMenu(
-            _("Add from Tool DB"), self.on_tool_add_from_db_clicked,
-            icon=QtGui.QIcon(self.app.resource_location + "/plus16.png"))
-        self.ui.geo_tools_table.addContextMenu(
-            _("Copy"), self.on_tool_copy,
-            icon=QtGui.QIcon(self.app.resource_location + "/copy16.png"))
-        self.ui.geo_tools_table.addContextMenu(
-            _("Delete"), lambda: self.on_tool_delete(all_tools=None),
-            icon=QtGui.QIcon(self.app.resource_location + "/delete32.png"))
-
-        # Show/Hide Advanced Options
-        if self.app.defaults["global_app_level"] == 'b':
-            self.ui.level.setText('<span style="color:green;"><b>%s</b></span>' % _('Basic'))
-
-            self.ui.geo_tools_table.setColumnHidden(2, True)
-            self.ui.geo_tools_table.setColumnHidden(3, True)
-            # self.ui.geo_tools_table.setColumnHidden(4, True)
-            self.ui.addtool_entry_lbl.hide()
-            self.ui.addtool_entry.hide()
-            self.ui.addtool_btn.hide()
-            self.ui.copytool_btn.hide()
-            self.ui.deltool_btn.hide()
-            # self.ui.endz_label.hide()
-            # self.ui.endz_entry.hide()
-            self.ui.fr_rapidlabel.hide()
-            self.ui.feedrate_rapid_entry.hide()
-            self.ui.extracut_cb.hide()
-            self.ui.e_cut_entry.hide()
-            self.ui.pdepth_label.hide()
-            self.ui.pdepth_entry.hide()
-            self.ui.feedrate_probe_label.hide()
-            self.ui.feedrate_probe_entry.hide()
-        else:
-            self.ui.level.setText('<span style="color:red;"><b>%s</b></span>' % _('Advanced'))
-
-        self.ui.e_cut_entry.setDisabled(False) if self.app.defaults['geometry_extracut'] else \
-            self.ui.e_cut_entry.setDisabled(True)
-        self.ui.extracut_cb.toggled.connect(lambda state: self.ui.e_cut_entry.setDisabled(not state))
-
-        self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
-        self.ui.generate_cnc_button.clicked.connect(self.on_generatecnc_button_click)
-        self.ui.paint_tool_button.clicked.connect(lambda: self.app.paint_tool.run(toggle=False))
-        self.ui.generate_ncc_button.clicked.connect(lambda: self.app.ncclear_tool.run(toggle=False))
-        self.ui.pp_geometry_name_cb.activated.connect(self.on_pp_changed)
-
-        self.ui.tipdia_entry.valueChanged.connect(self.update_cutz)
-        self.ui.tipangle_entry.valueChanged.connect(self.update_cutz)
-
-        self.ui.addtool_from_db_btn.clicked.connect(self.on_tool_add_from_db_clicked)
-        self.ui.apply_param_to_all.clicked.connect(self.on_apply_param_to_all_clicked)
-        self.ui.cutz_entry.returnPressed.connect(self.on_cut_z_changed)
-
-    def on_cut_z_changed(self):
-        self.old_cutz = self.ui.cutz_entry.get_value()
-
-    def set_tool_offset_visibility(self, current_row):
-        if current_row is None:
-            return
-        try:
-            tool_offset = self.ui.geo_tools_table.cellWidget(current_row, 2)
-            if tool_offset is not None:
-                tool_offset_txt = tool_offset.currentText()
-                if tool_offset_txt == 'Custom':
-                    self.ui.tool_offset_entry.show()
-                    self.ui.tool_offset_lbl.show()
-                else:
-                    self.ui.tool_offset_entry.hide()
-                    self.ui.tool_offset_lbl.hide()
-        except Exception as e:
-            log.debug("set_tool_offset_visibility() --> " + str(e))
-            return
-
-    def on_offset_value_edited(self):
-        """
-        This will save the offset_value into self.tools storage whenever the offset value is edited
-        :return:
-        """
-
-        for current_row in self.ui.geo_tools_table.selectedItems():
-            # sometime the header get selected and it has row number -1
-            # we don't want to do anything with the header :)
-            if current_row.row() < 0:
-                continue
-            tool_uid = int(self.ui.geo_tools_table.item(current_row.row(), 5).text())
-            self.set_tool_offset_visibility(current_row.row())
-
-            for tooluid_key, tooluid_value in self.tools.items():
-                if int(tooluid_key) == tool_uid:
-                    try:
-                        tooluid_value['offset_value'] = float(self.ui.tool_offset_entry.get_value())
-                    except ValueError:
-                        # try to convert comma to decimal point. if it's still not working error message and return
-                        try:
-                            tooluid_value['offset_value'] = float(
-                                self.ui.tool_offset_entry.get_value().replace(',', '.')
-                            )
-                        except ValueError:
-                            self.app.inform.emit('[ERROR_NOTCL] %s' %
-                                                 _("Wrong value format entered, use a number."))
-                            return
-
-    def ui_connect(self):
-        # on any change to the widgets that matter it will be called self.gui_form_to_storage which will save the
-        # changes in geometry UI
-        for i in self.param_fields:
-            current_widget = self.param_fields[i]
-            if isinstance(current_widget, FCCheckBox):
-                current_widget.stateChanged.connect(self.gui_form_to_storage)
-            elif isinstance(current_widget, FCComboBox):
-                current_widget.currentIndexChanged.connect(self.gui_form_to_storage)
-            elif isinstance(current_widget, FloatEntry) or isinstance(current_widget, LengthEntry) or \
-                    isinstance(current_widget, FCEntry) or isinstance(current_widget, IntEntry):
-                current_widget.editingFinished.connect(self.gui_form_to_storage)
-            elif isinstance(current_widget, FCSpinner) or isinstance(current_widget, FCDoubleSpinner):
-                current_widget.returnPressed.connect(self.gui_form_to_storage)
-
-        for row in range(self.ui.geo_tools_table.rowCount()):
-            for col in [2, 3, 4]:
-                self.ui.geo_tools_table.cellWidget(row, col).currentIndexChanged.connect(
-                    self.on_tooltable_cellwidget_change)
-
-        # I use lambda's because the connected functions have parameters that could be used in certain scenarios
-        self.ui.addtool_btn.clicked.connect(lambda: self.on_tool_add())
-
-        self.ui.copytool_btn.clicked.connect(lambda: self.on_tool_copy())
-        self.ui.deltool_btn.clicked.connect(lambda: self.on_tool_delete())
-
-        # self.ui.geo_tools_table.currentItemChanged.connect(self.on_row_selection_change)
-        self.ui.geo_tools_table.clicked.connect(self.on_row_selection_change)
-        self.ui.geo_tools_table.horizontalHeader().sectionClicked.connect(self.on_row_selection_change)
-
-        self.ui.geo_tools_table.itemChanged.connect(self.on_tool_edit)
-        self.ui.tool_offset_entry.returnPressed.connect(self.on_offset_value_edited)
-
-        for row in range(self.ui.geo_tools_table.rowCount()):
-            self.ui.geo_tools_table.cellWidget(row, 6).clicked.connect(self.on_plot_cb_click_table)
-        self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
-
-        # common parameters update
-        self.ui.pp_geometry_name_cb.currentIndexChanged.connect(self.update_common_param_in_storage)
-
-    def ui_disconnect(self):
-
-        # on any change to the widgets that matter it will be called self.gui_form_to_storage which will save the
-        # changes in geometry UI
-        for i in self.param_fields:
-            # current_widget = self.ui.grid3.itemAt(i).widget()
-            current_widget = self.param_fields[i]
-            if isinstance(current_widget, FCCheckBox):
-                try:
-                    current_widget.stateChanged.disconnect(self.gui_form_to_storage)
-                except (TypeError, AttributeError):
-                    pass
-            elif isinstance(current_widget, FCComboBox):
-                try:
-                    current_widget.currentIndexChanged.disconnect(self.gui_form_to_storage)
-                except (TypeError, AttributeError):
-                    pass
-            elif isinstance(current_widget, LengthEntry) or isinstance(current_widget, IntEntry) or \
-                    isinstance(current_widget, FCEntry) or isinstance(current_widget, FloatEntry):
-                try:
-                    current_widget.editingFinished.disconnect(self.gui_form_to_storage)
-                except (TypeError, AttributeError):
-                    pass
-            elif isinstance(current_widget, FCSpinner) or isinstance(current_widget, FCDoubleSpinner):
-                try:
-                    current_widget.returnPressed.disconnect(self.gui_form_to_storage)
-                except TypeError:
-                    pass
-
-        for row in range(self.ui.geo_tools_table.rowCount()):
-            for col in [2, 3, 4]:
-                try:
-                    self.ui.geo_tools_table.cellWidget(row, col).currentIndexChanged.disconnect()
-                except (TypeError, AttributeError):
-                    pass
-
-        try:
-            self.ui.addtool_btn.clicked.disconnect()
-        except (TypeError, AttributeError):
-            pass
-
-        try:
-            self.ui.copytool_btn.clicked.disconnect()
-        except (TypeError, AttributeError):
-            pass
-
-        try:
-            self.ui.deltool_btn.clicked.disconnect()
-        except (TypeError, AttributeError):
-            pass
-
-        try:
-            self.ui.geo_tools_table.clicked.disconnect()
-        except (TypeError, AttributeError):
-            pass
-        try:
-            self.ui.geo_tools_table.horizontalHeader().sectionClicked.disconnect()
-        except (TypeError, AttributeError):
-            pass
-
-        try:
-            self.ui.geo_tools_table.itemChanged.disconnect()
-        except (TypeError, AttributeError):
-            pass
-
-        try:
-            self.ui.tool_offset_entry.returnPressed.disconnect()
-        except (TypeError, AttributeError):
-            pass
-
-        for row in range(self.ui.geo_tools_table.rowCount()):
-            try:
-                self.ui.geo_tools_table.cellWidget(row, 6).clicked.disconnect()
-            except (TypeError, AttributeError):
-                pass
-
-        try:
-            self.ui.plot_cb.stateChanged.disconnect()
-        except (TypeError, AttributeError):
-            pass
-
-    def on_row_selection_change(self):
-        self.update_ui()
-
-    def update_ui(self, row=None):
-        self.ui_disconnect()
-
-        if row is None:
-            sel_rows = []
-            sel_items = self.ui.geo_tools_table.selectedItems()
-            for it in sel_items:
-                sel_rows.append(it.row())
-        else:
-            sel_rows = row if type(row) == list else [row]
-
-        if not sel_rows:
-            sel_rows = [0]
-
-        for current_row in sel_rows:
-            self.set_tool_offset_visibility(current_row)
-
-            # populate the form with the data from the tool associated with the row parameter
-            try:
-                item = self.ui.geo_tools_table.item(current_row, 5)
-                if type(item) is not None:
-                    tooluid = int(item.text())
-                else:
-                    self.ui_connect()
-                    return
-            except Exception as e:
-                log.debug("Tool missing. Add a tool in Geo Tool Table. %s" % str(e))
-                self.ui_connect()
-                return
-
-            # update the QLabel that shows for which Tool we have the parameters in the UI form
-            if len(sel_rows) == 1:
-                self.ui.tool_data_label.setText(
-                    "<b>%s: <font color='#0000FF'>%s %d</font></b>" % (_('Parameters for'), _("Tool"), tooluid)
-                )
-
-                # update the form with the V-Shape fields if V-Shape selected in the geo_tool_table
-                # also modify the Cut Z form entry to reflect the calculated Cut Z from values got from V-Shape Fields
-                try:
-                    item = self.ui.geo_tools_table.cellWidget(current_row, 4)
-                    if item is not None:
-                        tool_type_txt = item.currentText()
-                        self.ui_update_v_shape(tool_type_txt=tool_type_txt)
-                    else:
-                        self.ui_connect()
-                        return
-                except Exception as e:
-                    log.debug("Tool missing in ui_update_v_shape(). Add a tool in Geo Tool Table. %s" % str(e))
-                    return
-
-                try:
-                    # set the form with data from the newly selected tool
-                    for tooluid_key, tooluid_value in list(self.tools.items()):
-                        if int(tooluid_key) == tooluid:
-                            for key, value in list(tooluid_value.items()):
-                                if key == 'data':
-                                    form_value_storage = tooluid_value['data']
-                                    self.update_form(form_value_storage)
-                                if key == 'offset_value':
-                                    # update the offset value in the entry even if the entry is hidden
-                                    self.ui.tool_offset_entry.set_value(tooluid_value['offset_value'])
-
-                                if key == 'tool_type' and value == 'V':
-                                    self.update_cutz()
-                except Exception as e:
-                    log.debug("FlatCAMGeometry.update_ui() -> %s " % str(e))
-
-            else:
-                self.ui.tool_data_label.setText(
-                    "<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("Multiple Tools"))
-                )
-
-        self.ui_connect()
-
-    def on_tool_add(self, dia=None):
-        self.ui_disconnect()
-
-        self.units = self.app.defaults['units'].upper()
-
-        if dia is not None:
-            tooldia = dia
-        else:
-            tooldia = float(self.ui.addtool_entry.get_value())
-
-        # construct a list of all 'tooluid' in the self.tools
-        # tool_uid_list = []
-        # for tooluid_key in self.tools:
-        #     tool_uid_list.append(int(tooluid_key))
-        tool_uid_list = [int(tooluid_key) for tooluid_key in self.tools]
-
-        # find maximum from the temp_uid, add 1 and this is the new 'tooluid'
-        max_uid = max(tool_uid_list) if tool_uid_list else 0
-        self.tooluid = max_uid + 1
-
-        tooldia = float('%.*f' % (self.decimals, tooldia))
-
-        # here we actually add the new tool; if there is no tool in the tool table we add a tool with default data
-        # otherwise we add a tool with data copied from last tool
-        if self.tools:
-            last_data = self.tools[max_uid]['data']
-            last_offset = self.tools[max_uid]['offset']
-            last_offset_value = self.tools[max_uid]['offset_value']
-            last_type = self.tools[max_uid]['type']
-            last_tool_type = self.tools[max_uid]['tool_type']
-            last_solid_geometry = self.tools[max_uid]['solid_geometry']
-
-            # if previous geometry was empty (it may happen for the first tool added)
-            # then copy the object.solid_geometry
-            if not last_solid_geometry:
-                last_solid_geometry = self.solid_geometry
-
-            self.tools.update({
-                self.tooluid: {
-                    'tooldia': tooldia,
-                    'offset': last_offset,
-                    'offset_value': last_offset_value,
-                    'type': last_type,
-                    'tool_type': last_tool_type,
-                    'data': deepcopy(last_data),
-                    'solid_geometry': deepcopy(last_solid_geometry)
-                }
-            })
-        else:
-            self.tools.update({
-                self.tooluid: {
-                    'tooldia': tooldia,
-                    'offset': 'Path',
-                    'offset_value': 0.0,
-                    'type': _('Rough'),
-                    'tool_type': 'C1',
-                    'data': deepcopy(self.default_data),
-                    'solid_geometry': self.solid_geometry
-                }
-            })
-
-        self.tools[self.tooluid]['data']['name'] = self.options['name']
-
-        self.ui.tool_offset_entry.hide()
-        self.ui.tool_offset_lbl.hide()
-
-        # we do this HACK to make sure the tools attribute to be serialized is updated in the self.ser_attrs list
-        try:
-            self.ser_attrs.remove('tools')
-        except TypeError:
-            pass
-        self.ser_attrs.append('tools')
-
-        self.app.inform.emit('[success] %s' % _("Tool added in Tool Table."))
-        self.ui_connect()
-        self.build_ui()
-
-        # if there is no tool left in the Tools Table, enable the parameters GUI
-        if self.ui.geo_tools_table.rowCount() != 0:
-            self.ui.geo_param_frame.setDisabled(False)
-
-    def on_tool_add_from_db_clicked(self):
-        """
-        Called when the user wants to add a new tool from Tools Database. It will create the Tools Database object
-        and display the Tools Database tab in the form needed for the Tool adding
-        :return: None
-        """
-
-        # if the Tools Database is already opened focus on it
-        for idx in range(self.app.ui.plot_tab_area.count()):
-            if self.app.ui.plot_tab_area.tabText(idx) == _("Tools Database"):
-                self.app.ui.plot_tab_area.setCurrentWidget(self.app.tools_db_tab)
-                break
-        self.app.on_tools_database()
-        self.app.tools_db_tab.ok_to_add = True
-        self.app.tools_db_tab.buttons_frame.hide()
-        self.app.tools_db_tab.add_tool_from_db.show()
-        self.app.tools_db_tab.cancel_tool_from_db.show()
-
-    def on_tool_from_db_inserted(self, tool):
-        """
-        Called from the Tools DB object through a App method when adding a tool from Tools Database
-        :param tool: a dict with the tool data
-        :return: None
-        """
-
-        self.ui_disconnect()
-        self.units = self.app.defaults['units'].upper()
-
-        tooldia = float(tool['tooldia'])
-
-        # construct a list of all 'tooluid' in the self.tools
-        tool_uid_list = []
-        for tooluid_key in self.tools:
-            tool_uid_item = int(tooluid_key)
-            tool_uid_list.append(tool_uid_item)
-
-        # find maximum from the temp_uid, add 1 and this is the new 'tooluid'
-        if not tool_uid_list:
-            max_uid = 0
-        else:
-            max_uid = max(tool_uid_list)
-        self.tooluid = max_uid + 1
-
-        tooldia = float('%.*f' % (self.decimals, tooldia))
-
-        self.tools.update({
-            self.tooluid: {
-                'tooldia': tooldia,
-                'offset': tool['offset'],
-                'offset_value': float(tool['offset_value']),
-                'type': tool['type'],
-                'tool_type': tool['tool_type'],
-                'data': deepcopy(tool['data']),
-                'solid_geometry': self.solid_geometry
-            }
-        })
-
-        self.tools[self.tooluid]['data']['name'] = self.options['name']
-
-        self.ui.tool_offset_entry.hide()
-        self.ui.tool_offset_lbl.hide()
-
-        # we do this HACK to make sure the tools attribute to be serialized is updated in the self.ser_attrs list
-        try:
-            self.ser_attrs.remove('tools')
-        except TypeError:
-            pass
-        self.ser_attrs.append('tools')
-
-        self.ui_connect()
-        self.build_ui()
-
-        # if there is no tool left in the Tools Table, enable the parameters GUI
-        if self.ui.geo_tools_table.rowCount() != 0:
-            self.ui.geo_param_frame.setDisabled(False)
-
-    def on_tool_copy(self, all_tools=None):
-        self.ui_disconnect()
-
-        # find the tool_uid maximum value in the self.tools
-        uid_list = []
-        for key in self.tools:
-            uid_list.append(int(key))
-        try:
-            max_uid = max(uid_list, key=int)
-        except ValueError:
-            max_uid = 0
-
-        if all_tools is None:
-            if self.ui.geo_tools_table.selectedItems():
-                for current_row in self.ui.geo_tools_table.selectedItems():
-                    # sometime the header get selected and it has row number -1
-                    # we don't want to do anything with the header :)
-                    if current_row.row() < 0:
-                        continue
-                    try:
-                        tooluid_copy = int(self.ui.geo_tools_table.item(current_row.row(), 5).text())
-                        self.set_tool_offset_visibility(current_row.row())
-                        max_uid += 1
-                        self.tools[int(max_uid)] = deepcopy(self.tools[tooluid_copy])
-                    except AttributeError:
-                        self.app.inform.emit('[WARNING_NOTCL] %s' % _("Failed. Select a tool to copy."))
-                        self.ui_connect()
-                        self.build_ui()
-                        return
-                    except Exception as e:
-                        log.debug("on_tool_copy() --> " + str(e))
-                # deselect the table
-                # self.ui.geo_tools_table.clearSelection()
-            else:
-                self.app.inform.emit('[WARNING_NOTCL] %s' % _("Failed. Select a tool to copy."))
-                self.ui_connect()
-                self.build_ui()
-                return
-        else:
-            # we copy all tools in geo_tools_table
-            try:
-                temp_tools = deepcopy(self.tools)
-                max_uid += 1
-                for tooluid in temp_tools:
-                    self.tools[int(max_uid)] = deepcopy(temp_tools[tooluid])
-                temp_tools.clear()
-            except Exception as e:
-                log.debug("on_tool_copy() --> " + str(e))
-
-        # if there are no more tools in geo tools table then hide the tool offset
-        if not self.tools:
-            self.ui.tool_offset_entry.hide()
-            self.ui.tool_offset_lbl.hide()
-
-        # we do this HACK to make sure the tools attribute to be serialized is updated in the self.ser_attrs list
-        try:
-            self.ser_attrs.remove('tools')
-        except ValueError:
-            pass
-        self.ser_attrs.append('tools')
-
-        self.ui_connect()
-        self.build_ui()
-        self.app.inform.emit('[success] %s' % _("Tool was copied in Tool Table."))
-
-    def on_tool_edit(self, current_item):
-        self.ui_disconnect()
-
-        current_row = current_item.row()
-        try:
-            d = float(self.ui.geo_tools_table.item(current_row, 1).text())
-        except ValueError:
-            # try to convert comma to decimal point. if it's still not working error message and return
-            try:
-                d = float(self.ui.geo_tools_table.item(current_row, 1).text().replace(',', '.'))
-            except ValueError:
-                self.app.inform.emit('[ERROR_NOTCL] %s' % _("Wrong value format entered, use a number."))
-                return
-
-        tool_dia = float('%.*f' % (self.decimals, d))
-        tooluid = int(self.ui.geo_tools_table.item(current_row, 5).text())
-
-        self.tools[tooluid]['tooldia'] = tool_dia
-
-        try:
-            self.ser_attrs.remove('tools')
-            self.ser_attrs.append('tools')
-        except (TypeError, ValueError):
-            pass
-
-        self.app.inform.emit('[success] %s' % _("Tool was edited in Tool Table."))
-        self.ui_connect()
-        self.build_ui()
-
-    def on_tool_delete(self, all_tools=None):
-        self.ui_disconnect()
-
-        if all_tools is None:
-            if self.ui.geo_tools_table.selectedItems():
-                for current_row in self.ui.geo_tools_table.selectedItems():
-                    # sometime the header get selected and it has row number -1
-                    # we don't want to do anything with the header :)
-                    if current_row.row() < 0:
-                        continue
-                    try:
-                        tooluid_del = int(self.ui.geo_tools_table.item(current_row.row(), 5).text())
-                        self.set_tool_offset_visibility(current_row.row())
-
-                        temp_tools = deepcopy(self.tools)
-                        for tooluid_key in self.tools:
-                            if int(tooluid_key) == tooluid_del:
-                                # if the self.tools has only one tool and we delete it then we move the solid_geometry
-                                # as a property of the object otherwise there will be nothing to hold it
-                                if len(self.tools) == 1:
-                                    self.solid_geometry = deepcopy(self.tools[tooluid_key]['solid_geometry'])
-                                temp_tools.pop(tooluid_del, None)
-                        self.tools = deepcopy(temp_tools)
-                        temp_tools.clear()
-                    except AttributeError:
-                        self.app.inform.emit('[WARNING_NOTCL] %s' % _("Failed. Select a tool to delete."))
-                        self.ui_connect()
-                        self.build_ui()
-                        return
-                    except Exception as e:
-                        log.debug("on_tool_delete() --> " + str(e))
-                # deselect the table
-                # self.ui.geo_tools_table.clearSelection()
-            else:
-                self.app.inform.emit('[WARNING_NOTCL] %s' % _("Failed. Select a tool to delete."))
-                self.ui_connect()
-                self.build_ui()
-                return
-        else:
-            # we delete all tools in geo_tools_table
-            self.tools.clear()
-
-        self.app.plot_all()
-
-        # if there are no more tools in geo tools table then hide the tool offset
-        if not self.tools:
-            self.ui.tool_offset_entry.hide()
-            self.ui.tool_offset_lbl.hide()
-
-        # we do this HACK to make sure the tools attribute to be serialized is updated in the self.ser_attrs list
-        try:
-            self.ser_attrs.remove('tools')
-        except TypeError:
-            pass
-        self.ser_attrs.append('tools')
-
-        self.ui_connect()
-        self.build_ui()
-        self.app.inform.emit('[success] %s' % _("Tool was deleted in Tool Table."))
-
-        obj_active = self.app.collection.get_active()
-        # if the object was MultiGeo and now it has no tool at all (therefore no geometry)
-        # we make it back SingleGeo
-        if self.ui.geo_tools_table.rowCount() <= 0:
-            obj_active.multigeo = False
-            obj_active.options['xmin'] = 0
-            obj_active.options['ymin'] = 0
-            obj_active.options['xmax'] = 0
-            obj_active.options['ymax'] = 0
-
-        if obj_active.multigeo is True:
-            try:
-                xmin, ymin, xmax, ymax = obj_active.bounds()
-                obj_active.options['xmin'] = xmin
-                obj_active.options['ymin'] = ymin
-                obj_active.options['xmax'] = xmax
-                obj_active.options['ymax'] = ymax
-            except Exception:
-                obj_active.options['xmin'] = 0
-                obj_active.options['ymin'] = 0
-                obj_active.options['xmax'] = 0
-                obj_active.options['ymax'] = 0
-
-        # if there is no tool left in the Tools Table, disable the parameters GUI
-        if self.ui.geo_tools_table.rowCount() == 0:
-            self.ui.geo_param_frame.setDisabled(True)
-
-    def ui_update_v_shape(self, tool_type_txt):
-        if tool_type_txt == 'V':
-            self.ui.tipdialabel.show()
-            self.ui.tipdia_entry.show()
-            self.ui.tipanglelabel.show()
-            self.ui.tipangle_entry.show()
-            self.ui.cutz_entry.setDisabled(True)
-
-            self.update_cutz()
-        else:
-            self.ui.tipdialabel.hide()
-            self.ui.tipdia_entry.hide()
-            self.ui.tipanglelabel.hide()
-            self.ui.tipangle_entry.hide()
-            self.ui.cutz_entry.setDisabled(False)
-
-    def update_cutz(self):
-        vdia = float(self.ui.tipdia_entry.get_value())
-        half_vangle = float(self.ui.tipangle_entry.get_value()) / 2
-
-        row = self.ui.geo_tools_table.currentRow()
-        tool_uid_item = self.ui.geo_tools_table.item(row, 5)
-        if tool_uid_item is None:
-            return
-        tool_uid = int(tool_uid_item.text())
-
-        tool_dia_item = self.ui.geo_tools_table.item(row, 1)
-        if tool_dia_item is None:
-            return
-        tooldia = float(tool_dia_item.text())
-
-        try:
-            new_cutz = (tooldia - vdia) / (2 * math.tan(math.radians(half_vangle)))
-        except ZeroDivisionError:
-            new_cutz = self.old_cutz
-
-        new_cutz = float('%.*f' % (self.decimals, new_cutz)) * -1.0   # this value has to be negative
-
-        self.ui.cutz_entry.set_value(new_cutz)
-
-        # store the new CutZ value into storage (self.tools)
-        for tooluid_key, tooluid_value in self.tools.items():
-            if int(tooluid_key) == tool_uid:
-                tooluid_value['data']['cutz'] = new_cutz
-
-    def on_tooltable_cellwidget_change(self):
-        cw = self.sender()
-        cw_index = self.ui.geo_tools_table.indexAt(cw.pos())
-        cw_row = cw_index.row()
-        cw_col = cw_index.column()
-        current_uid = int(self.ui.geo_tools_table.item(cw_row, 5).text())
-
-        # store the text of the cellWidget that changed it's index in the self.tools
-        for tooluid_key, tooluid_value in self.tools.items():
-            if int(tooluid_key) == current_uid:
-                cb_txt = cw.currentText()
-                if cw_col == 2:
-                    tooluid_value['offset'] = cb_txt
-                    if cb_txt == 'Custom':
-                        self.ui.tool_offset_entry.show()
-                        self.ui.tool_offset_lbl.show()
-                    else:
-                        self.ui.tool_offset_entry.hide()
-                        self.ui.tool_offset_lbl.hide()
-                        # reset the offset_value in storage self.tools
-                        tooluid_value['offset_value'] = 0.0
-                elif cw_col == 3:
-                    # force toolpath type as 'Iso' if the tool type is V-Shape
-                    if self.ui.geo_tools_table.cellWidget(cw_row, 4).currentText() == 'V':
-                        tooluid_value['type'] = _('Iso')
-                        idx = self.ui.geo_tools_table.cellWidget(cw_row, 3).findText(_('Iso'))
-                        self.ui.geo_tools_table.cellWidget(cw_row, 3).setCurrentIndex(idx)
-                    else:
-                        tooluid_value['type'] = cb_txt
-                elif cw_col == 4:
-                    tooluid_value['tool_type'] = cb_txt
-
-                    # if the tool_type selected is V-Shape then autoselect the toolpath type as Iso
-                    if cb_txt == 'V':
-                        idx = self.ui.geo_tools_table.cellWidget(cw_row, 3).findText(_('Iso'))
-                        self.ui.geo_tools_table.cellWidget(cw_row, 3).setCurrentIndex(idx)
-                    else:
-                        self.ui.cutz_entry.set_value(self.old_cutz)
-
-                self.ui_update_v_shape(tool_type_txt=self.ui.geo_tools_table.cellWidget(cw_row, 4).currentText())
-
-    def update_form(self, dict_storage):
-        for form_key in self.form_fields:
-            for storage_key in dict_storage:
-                if form_key == storage_key:
-                    try:
-                        self.form_fields[form_key].set_value(dict_storage[form_key])
-                    except Exception as e:
-                        log.debug(str(e))
-
-        # this is done here because those buttons control through OptionalInputSelection if some entry's are Enabled
-        # or not. But due of using the ui_disconnect() status is no longer updated and I had to do it here
-        self.ui.ois_dwell_geo.on_cb_change()
-        self.ui.ois_mpass_geo.on_cb_change()
-        self.ui.ois_tcz_geo.on_cb_change()
-
-    def on_apply_param_to_all_clicked(self):
-        if self.ui.geo_tools_table.rowCount() == 0:
-            # there is no tool in tool table so we can't save the GUI elements values to storage
-            log.debug("FlatCAMGeometry.gui_form_to_storage() --> no tool in Tools Table, aborting.")
-            return
-
-        self.ui_disconnect()
-
-        row = self.ui.geo_tools_table.currentRow()
-        if row < 0:
-            row = 0
-
-        # store all the data associated with the row parameter to the self.tools storage
-        tooldia_item = float(self.ui.geo_tools_table.item(row, 1).text())
-        offset_item = self.ui.geo_tools_table.cellWidget(row, 2).currentText()
-        type_item = self.ui.geo_tools_table.cellWidget(row, 3).currentText()
-        tool_type_item = self.ui.geo_tools_table.cellWidget(row, 4).currentText()
-
-        offset_value_item = float(self.ui.tool_offset_entry.get_value())
-
-        # this new dict will hold the actual useful data, another dict that is the value of key 'data'
-        temp_tools = {}
-        temp_dia = {}
-        temp_data = {}
-
-        for tooluid_key, tooluid_value in self.tools.items():
-            for key, value in tooluid_value.items():
-                if key == 'tooldia':
-                    temp_dia[key] = tooldia_item
-                # update the 'offset', 'type' and 'tool_type' sections
-                if key == 'offset':
-                    temp_dia[key] = offset_item
-                if key == 'type':
-                    temp_dia[key] = type_item
-                if key == 'tool_type':
-                    temp_dia[key] = tool_type_item
-                if key == 'offset_value':
-                    temp_dia[key] = offset_value_item
-
-                if key == 'data':
-                    # update the 'data' section
-                    for data_key in tooluid_value[key].keys():
-                        for form_key, form_value in self.form_fields.items():
-                            if form_key == data_key:
-                                temp_data[data_key] = form_value.get_value()
-                        # make sure we make a copy of the keys not in the form (we may use 'data' keys that are
-                        # updated from self.app.defaults
-                        if data_key not in self.form_fields:
-                            temp_data[data_key] = value[data_key]
-                    temp_dia[key] = deepcopy(temp_data)
-                    temp_data.clear()
-
-                if key == 'solid_geometry':
-                    temp_dia[key] = deepcopy(self.tools[tooluid_key]['solid_geometry'])
-
-                temp_tools[tooluid_key] = deepcopy(temp_dia)
-
-        self.tools.clear()
-        self.tools = deepcopy(temp_tools)
-        temp_tools.clear()
-
-        self.ui_connect()
-
-    def gui_form_to_storage(self):
-        if self.ui.geo_tools_table.rowCount() == 0:
-            # there is no tool in tool table so we can't save the GUI elements values to storage
-            log.debug("FlatCAMGeometry.gui_form_to_storage() --> no tool in Tools Table, aborting.")
-            return
-
-        self.ui_disconnect()
-        widget_changed = self.sender()
-        try:
-            widget_idx = self.ui.grid3.indexOf(widget_changed)
-        except Exception:
-            return
-
-        # those are the indexes for the V-Tip Dia and V-Tip Angle, if edited calculate the new Cut Z
-        if widget_idx == 1 or widget_idx == 3:
-            self.update_cutz()
-
-        # the original connect() function of the OptionalInputSelection is no longer working because of the
-        # ui_diconnect() so I use this 'hack'
-        if isinstance(widget_changed, FCCheckBox):
-            if widget_changed.text() == 'Multi-Depth:':
-                self.ui.ois_mpass_geo.on_cb_change()
-
-            if widget_changed.text() == 'Tool change':
-                self.ui.ois_tcz_geo.on_cb_change()
-
-            if widget_changed.text() == 'Dwell:':
-                self.ui.ois_dwell_geo.on_cb_change()
-
-        row = self.ui.geo_tools_table.currentRow()
-        if row < 0:
-            row = 0
-
-        # store all the data associated with the row parameter to the self.tools storage
-        tooldia_item = float(self.ui.geo_tools_table.item(row, 1).text())
-        offset_item = self.ui.geo_tools_table.cellWidget(row, 2).currentText()
-        type_item = self.ui.geo_tools_table.cellWidget(row, 3).currentText()
-        tool_type_item = self.ui.geo_tools_table.cellWidget(row, 4).currentText()
-        tooluid_item = int(self.ui.geo_tools_table.item(row, 5).text())
-
-        offset_value_item = float(self.ui.tool_offset_entry.get_value())
-
-        # this new dict will hold the actual useful data, another dict that is the value of key 'data'
-        temp_tools = {}
-        temp_dia = {}
-        temp_data = {}
-
-        for tooluid_key, tooluid_value in self.tools.items():
-            if int(tooluid_key) == tooluid_item:
-                for key, value in tooluid_value.items():
-                    if key == 'tooldia':
-                        temp_dia[key] = tooldia_item
-                    # update the 'offset', 'type' and 'tool_type' sections
-                    if key == 'offset':
-                        temp_dia[key] = offset_item
-                    if key == 'type':
-                        temp_dia[key] = type_item
-                    if key == 'tool_type':
-                        temp_dia[key] = tool_type_item
-                    if key == 'offset_value':
-                        temp_dia[key] = offset_value_item
-
-                    if key == 'data':
-                        # update the 'data' section
-                        for data_key in tooluid_value[key].keys():
-                            for form_key, form_value in self.form_fields.items():
-                                if form_key == data_key:
-                                    temp_data[data_key] = form_value.get_value()
-                            # make sure we make a copy of the keys not in the form (we may use 'data' keys that are
-                            # updated from self.app.defaults
-                            if data_key not in self.form_fields:
-                                temp_data[data_key] = value[data_key]
-                        temp_dia[key] = deepcopy(temp_data)
-                        temp_data.clear()
-
-                    if key == 'solid_geometry':
-                        temp_dia[key] = deepcopy(self.tools[tooluid_key]['solid_geometry'])
-
-                    temp_tools[tooluid_key] = deepcopy(temp_dia)
-            else:
-                temp_tools[tooluid_key] = deepcopy(tooluid_value)
-
-        self.tools.clear()
-        self.tools = deepcopy(temp_tools)
-        temp_tools.clear()
-        self.ui_connect()
-
-    def update_common_param_in_storage(self):
-        for tooluid_value in self.tools.values():
-            tooluid_value['data']['ppname_g'] = self.ui.pp_geometry_name_cb.get_value()
-
-    def select_tools_table_row(self, row, clearsel=None):
-        if clearsel:
-            self.ui.geo_tools_table.clearSelection()
-
-        if self.ui.geo_tools_table.rowCount() > 0:
-            # self.ui.geo_tools_table.item(row, 0).setSelected(True)
-            self.ui.geo_tools_table.setCurrentItem(self.ui.geo_tools_table.item(row, 0))
-
-    def export_dxf(self):
-        dwg = None
-        try:
-            dwg = ezdxf.new('R2010')
-            msp = dwg.modelspace()
-
-            def g2dxf(dxf_space, geo_obj):
-                if isinstance(geo_obj, MultiPolygon):
-                    for poly in geo_obj:
-                        ext_points = list(poly.exterior.coords)
-                        dxf_space.add_lwpolyline(ext_points)
-                        for interior in poly.interiors:
-                            dxf_space.add_lwpolyline(list(interior.coords))
-                if isinstance(geo_obj, Polygon):
-                    ext_points = list(geo_obj.exterior.coords)
-                    dxf_space.add_lwpolyline(ext_points)
-                    for interior in geo_obj.interiors:
-                        dxf_space.add_lwpolyline(list(interior.coords))
-                if isinstance(geo_obj, MultiLineString):
-                    for line in geo_obj:
-                        dxf_space.add_lwpolyline(list(line.coords))
-                if isinstance(geo_obj, LineString) or isinstance(geo_obj, LinearRing):
-                    dxf_space.add_lwpolyline(list(geo_obj.coords))
-
-            multigeo_solid_geometry = []
-            if self.multigeo:
-                for tool in self.tools:
-                    multigeo_solid_geometry += self.tools[tool]['solid_geometry']
-            else:
-                multigeo_solid_geometry = self.solid_geometry
-
-            for geo in multigeo_solid_geometry:
-                if type(geo) == list:
-                    for g in geo:
-                        g2dxf(msp, g)
-                else:
-                    g2dxf(msp, geo)
-
-                # points = FlatCAMGeometry.get_pts(geo)
-                # msp.add_lwpolyline(points)
-        except Exception as e:
-            log.debug(str(e))
-
-        return dwg
-
-    def get_selected_tools_table_items(self):
-        """
-        Returns a list of lists, each list in the list is made out of row elements
-
-        :return: List of table_tools items.
-        :rtype: list
-        """
-        table_tools_items = []
-        if self.multigeo:
-            for x in self.ui.geo_tools_table.selectedItems():
-                elem = []
-                txt = ''
-
-                for column in range(0, self.ui.geo_tools_table.columnCount()):
-                    try:
-                        txt = self.ui.geo_tools_table.item(x.row(), column).text()
-                    except AttributeError:
-                        try:
-                            txt = self.ui.geo_tools_table.cellWidget(x.row(), column).currentText()
-                        except AttributeError:
-                            pass
-                    elem.append(txt)
-                table_tools_items.append(deepcopy(elem))
-                # table_tools_items.append([self.ui.geo_tools_table.item(x.row(), column).text()
-                #                           for column in range(0, self.ui.geo_tools_table.columnCount())])
-        else:
-            for x in self.ui.geo_tools_table.selectedItems():
-                r = []
-                txt = ''
-
-                # the last 2 columns for single-geo geometry are irrelevant and create problems reading
-                # so we don't read them
-                for column in range(0, self.ui.geo_tools_table.columnCount() - 2):
-                    # the columns have items that have text but also have items that are widgets
-                    # for which the text they hold has to be read differently
-                    try:
-                        txt = self.ui.geo_tools_table.item(x.row(), column).text()
-                    except AttributeError:
-                        try:
-                            txt = self.ui.geo_tools_table.cellWidget(x.row(), column).currentText()
-                        except AttributeError:
-                            pass
-                    r.append(txt)
-                table_tools_items.append(r)
-
-        for item in table_tools_items:
-            item[0] = str(item[0])
-        return table_tools_items
-
-    def on_pp_changed(self):
-        current_pp = self.ui.pp_geometry_name_cb.get_value()
-        if current_pp == 'hpgl':
-            self.old_pp_state = self.ui.mpass_cb.get_value()
-            self.old_toolchangeg_state = self.ui.toolchangeg_cb.get_value()
-
-            self.ui.mpass_cb.set_value(False)
-            self.ui.mpass_cb.setDisabled(True)
-
-            self.ui.toolchangeg_cb.set_value(True)
-            self.ui.toolchangeg_cb.setDisabled(True)
-        else:
-            self.ui.mpass_cb.set_value(self.old_pp_state)
-            self.ui.mpass_cb.setDisabled(False)
-
-            self.ui.toolchangeg_cb.set_value(self.old_toolchangeg_state)
-            self.ui.toolchangeg_cb.setDisabled(False)
-
-        if "toolchange_probe" in current_pp.lower():
-            self.ui.pdepth_entry.setVisible(True)
-            self.ui.pdepth_label.show()
-
-            self.ui.feedrate_probe_entry.setVisible(True)
-            self.ui.feedrate_probe_label.show()
-        else:
-            self.ui.pdepth_entry.setVisible(False)
-            self.ui.pdepth_label.hide()
-
-            self.ui.feedrate_probe_entry.setVisible(False)
-            self.ui.feedrate_probe_label.hide()
-
-        if 'marlin' in current_pp.lower() or 'custom' in current_pp.lower():
-            self.ui.fr_rapidlabel.show()
-            self.ui.feedrate_rapid_entry.show()
-        else:
-            self.ui.fr_rapidlabel.hide()
-            self.ui.feedrate_rapid_entry.hide()
-
-        if 'laser' in current_pp.lower():
-            self.ui.cutzlabel.hide()
-            self.ui.cutz_entry.hide()
-            try:
-                self.ui.mpass_cb.hide()
-                self.ui.maxdepth_entry.hide()
-            except AttributeError:
-                pass
-
-            if 'marlin' in current_pp.lower():
-                self.ui.travelzlabel.setText('%s:' % _("Focus Z"))
-                self.ui.endz_label.show()
-                self.ui.endz_entry.show()
-            else:
-                self.ui.travelzlabel.hide()
-                self.ui.travelz_entry.hide()
-
-                self.ui.endz_label.hide()
-                self.ui.endz_entry.hide()
-
-            try:
-                self.ui.frzlabel.hide()
-                self.ui.feedrate_z_entry.hide()
-            except AttributeError:
-                pass
-
-            self.ui.dwell_cb.hide()
-            self.ui.dwelltime_entry.hide()
-
-            self.ui.spindle_label.setText('%s:' % _("Laser Power"))
-
-            try:
-                self.ui.tool_offset_label.hide()
-                self.ui.offset_entry.hide()
-            except AttributeError:
-                pass
-        else:
-            self.ui.cutzlabel.show()
-            self.ui.cutz_entry.show()
-            try:
-                self.ui.mpass_cb.show()
-                self.ui.maxdepth_entry.show()
-            except AttributeError:
-                pass
-
-            self.ui.travelzlabel.setText('%s:' % _('Travel Z'))
-
-            self.ui.travelzlabel.show()
-            self.ui.travelz_entry.show()
-
-            self.ui.endz_label.show()
-            self.ui.endz_entry.show()
-
-            try:
-                self.ui.frzlabel.show()
-                self.ui.feedrate_z_entry.show()
-            except AttributeError:
-                pass
-            self.ui.dwell_cb.show()
-            self.ui.dwelltime_entry.show()
-
-            self.ui.spindle_label.setText('%s:' % _('Spindle speed'))
-
-            try:
-                self.ui.tool_offset_lbl.show()
-                self.ui.offset_entry.show()
-            except AttributeError:
-                pass
-
-    def on_generatecnc_button_click(self, *args):
-        log.debug("Generating CNCJob from Geometry ...")
-        self.app.report_usage("geometry_on_generatecnc_button")
-
-        # this reads the values in the UI form to the self.options dictionary
-        self.read_form()
-
-        self.sel_tools = {}
-
-        try:
-            if self.special_group:
-                self.app.inform.emit(
-                    '[WARNING_NOTCL] %s %s %s.' %
-                    (_("This Geometry can't be processed because it is"), str(self.special_group), _("geometry"))
-                )
-                return
-        except AttributeError:
-            pass
-
-        # test to see if we have tools available in the tool table
-        if self.ui.geo_tools_table.selectedItems():
-            for x in self.ui.geo_tools_table.selectedItems():
-                # try:
-                #     tooldia = float(self.ui.geo_tools_table.item(x.row(), 1).text())
-                # except ValueError:
-                #     # try to convert comma to decimal point. if it's still not working error message and return
-                #     try:
-                #         tooldia = float(self.ui.geo_tools_table.item(x.row(), 1).text().replace(',', '.'))
-                #     except ValueError:
-                #         self.app.inform.emit('[ERROR_NOTCL] %s' %
-                #                              _("Wrong value format entered, use a number."))
-                #         return
-                tooluid = int(self.ui.geo_tools_table.item(x.row(), 5).text())
-
-                for tooluid_key, tooluid_value in self.tools.items():
-                    if int(tooluid_key) == tooluid:
-                        self.sel_tools.update({
-                            tooluid: deepcopy(tooluid_value)
-                        })
-            self.mtool_gen_cncjob()
-            self.ui.geo_tools_table.clearSelection()
-
-        elif self.ui.geo_tools_table.rowCount() == 1:
-            tooluid = int(self.ui.geo_tools_table.item(0, 5).text())
-
-            for tooluid_key, tooluid_value in self.tools.items():
-                if int(tooluid_key) == tooluid:
-                    self.sel_tools.update({
-                        tooluid: deepcopy(tooluid_value)
-                    })
-            self.mtool_gen_cncjob()
-            self.ui.geo_tools_table.clearSelection()
-
-        else:
-            self.app.inform.emit('[ERROR_NOTCL] %s' % _("Failed. No tool selected in the tool table ..."))
-
-    def mtool_gen_cncjob(self, outname=None, tools_dict=None, tools_in_use=None, segx=None, segy=None,
-                         plot=True, use_thread=True):
-        """
-        Creates a multi-tool CNCJob out of this Geometry object.
-        The actual work is done by the target FlatCAMCNCjob object's
-        `generate_from_geometry_2()` method.
-
-        :param tools_dict: a dictionary that holds the whole data needed to create the Gcode
-        (including the solid_geometry)
-
-        :param tools_in_use: the tools that are used, needed by some preprocessors
-        :type list of lists, each list in the list is made out of row elements of tools table from GUI
-
-        :param outname:
-        :param tools_dict:
-        :param tools_in_use:
-        :param segx:            number of segments on the X axis, for auto-levelling
-        :param segy:            number of segments on the Y axis, for auto-levelling
-        :param plot:            if True the generated object will be plotted; if False will not be plotted
-        :param use_thread:      if True use threading
-        :return:                None
-        """
-
-        # use the name of the first tool selected in self.geo_tools_table which has the diameter passed as tool_dia
-        outname = "%s_%s" % (self.options["name"], 'cnc') if outname is None else outname
-
-        tools_dict = self.sel_tools if tools_dict is None else tools_dict
-        tools_in_use = tools_in_use if tools_in_use is not None else self.get_selected_tools_table_items()
-        segx = segx if segx is not None else float(self.app.defaults['geometry_segx'])
-        segy = segy if segy is not None else float(self.app.defaults['geometry_segy'])
-
-        try:
-            xmin = self.options['xmin']
-            ymin = self.options['ymin']
-            xmax = self.options['xmax']
-            ymax = self.options['ymax']
-        except Exception as e:
-            log.debug("FlatCAMObj.FlatCAMGeometry.mtool_gen_cncjob() --> %s\n" % str(e))
-
-            msg = '[ERROR] %s' % _("An internal error has occurred. See shell.\n")
-            msg += '%s %s' % ('FlatCAMObj.FlatCAMGeometry.mtool_gen_cncjob() -->', str(e))
-            msg += traceback.format_exc()
-            self.app.inform.emit(msg)
-            return
-
-        # 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)
-
-            job_obj.options['xmin'] = xmin
-            job_obj.options['ymin'] = ymin
-            job_obj.options['xmax'] = xmax
-            job_obj.options['ymax'] = ymax
-
-            # count the tools
-            tool_cnt = 0
-
-            dia_cnc_dict = {}
-
-            # this turn on the FlatCAMCNCJob plot for multiple tools
-            job_obj.multitool = True
-            job_obj.multigeo = False
-            job_obj.cnc_tools.clear()
-
-            job_obj.options['Tools_in_use'] = tools_in_use
-            job_obj.segx = segx if segx else float(self.app.defaults["geometry_segx"])
-            job_obj.segy = segy if segy else float(self.app.defaults["geometry_segy"])
-
-            job_obj.z_pdepth = float(self.app.defaults["geometry_z_pdepth"])
-            job_obj.feedrate_probe = float(self.app.defaults["geometry_feedrate_probe"])
-
-            for tooluid_key in list(tools_dict.keys()):
-                tool_cnt += 1
-
-                dia_cnc_dict = deepcopy(tools_dict[tooluid_key])
-                tooldia_val = float('%.*f' % (self.decimals, float(tools_dict[tooluid_key]['tooldia'])))
-                dia_cnc_dict.update({
-                    'tooldia': tooldia_val
-                })
-
-                if dia_cnc_dict['offset'] == 'in':
-                    tool_offset = -dia_cnc_dict['tooldia'] / 2
-                elif dia_cnc_dict['offset'].lower() == 'out':
-                    tool_offset = dia_cnc_dict['tooldia'] / 2
-                elif dia_cnc_dict['offset'].lower() == 'custom':
-                    try:
-                        offset_value = float(self.ui.tool_offset_entry.get_value())
-                    except ValueError:
-                        # try to convert comma to decimal point. if it's still not working error message and return
-                        try:
-                            offset_value = float(self.ui.tool_offset_entry.get_value().replace(',', '.'))
-                        except ValueError:
-                            self.app.inform.emit('[ERROR_NOTCL] %s' % _("Wrong value format entered, use a number."))
-                            return
-                    if offset_value:
-                        tool_offset = float(offset_value)
-                    else:
-                        self.app.inform.emit(
-                            '[WARNING] %s' % _("Tool Offset is selected in Tool Table but no value is provided.\n"
-                                               "Add a Tool Offset or change the Offset Type.")
-                        )
-                        return
-                else:
-                    tool_offset = 0.0
-
-                dia_cnc_dict.update({
-                    'offset_value': tool_offset
-                })
-
-                z_cut = tools_dict[tooluid_key]['data']["cutz"]
-                z_move = tools_dict[tooluid_key]['data']["travelz"]
-                feedrate = tools_dict[tooluid_key]['data']["feedrate"]
-                feedrate_z = tools_dict[tooluid_key]['data']["feedrate_z"]
-                feedrate_rapid = tools_dict[tooluid_key]['data']["feedrate_rapid"]
-                multidepth = tools_dict[tooluid_key]['data']["multidepth"]
-                extracut = tools_dict[tooluid_key]['data']["extracut"]
-                extracut_length = tools_dict[tooluid_key]['data']["extracut_length"]
-                depthpercut = tools_dict[tooluid_key]['data']["depthperpass"]
-                toolchange = tools_dict[tooluid_key]['data']["toolchange"]
-                toolchangez = tools_dict[tooluid_key]['data']["toolchangez"]
-                toolchangexy = tools_dict[tooluid_key]['data']["toolchangexy"]
-                startz = tools_dict[tooluid_key]['data']["startz"]
-                endz = tools_dict[tooluid_key]['data']["endz"]
-                endxy = self.options["endxy"]
-                spindlespeed = tools_dict[tooluid_key]['data']["spindlespeed"]
-                dwell = tools_dict[tooluid_key]['data']["dwell"]
-                dwelltime = tools_dict[tooluid_key]['data']["dwelltime"]
-                pp_geometry_name = tools_dict[tooluid_key]['data']["ppname_g"]
-
-                spindledir = self.app.defaults['geometry_spindledir']
-                tool_solid_geometry = self.solid_geometry
-
-                job_obj.coords_decimals = self.app.defaults["cncjob_coords_decimals"]
-                job_obj.fr_decimals = self.app.defaults["cncjob_fr_decimals"]
-
-                # Propagate options
-                job_obj.options["tooldia"] = tooldia_val
-                job_obj.options['type'] = 'Geometry'
-                job_obj.options['tool_dia'] = tooldia_val
-
-                # it seems that the tolerance needs to be a lot lower value than 0.01 and it was hardcoded initially
-                # to a value of 0.0005 which is 20 times less than 0.01
-                tol = float(self.app.defaults['global_tolerance']) / 20
-                res = job_obj.generate_from_geometry_2(
-                    self, tooldia=tooldia_val, offset=tool_offset, tolerance=tol,
-                    z_cut=z_cut, z_move=z_move,
-                    feedrate=feedrate, feedrate_z=feedrate_z, feedrate_rapid=feedrate_rapid,
-                    spindlespeed=spindlespeed, spindledir=spindledir, dwell=dwell, dwelltime=dwelltime,
-                    multidepth=multidepth, depthpercut=depthpercut,
-                    extracut=extracut, extracut_length=extracut_length, startz=startz, endz=endz, endxy=endxy,
-                    toolchange=toolchange, toolchangez=toolchangez, toolchangexy=toolchangexy,
-                    pp_geometry_name=pp_geometry_name,
-                    tool_no=tool_cnt)
-
-                if res == 'fail':
-                    log.debug("FlatCAMGeometry.mtool_gen_cncjob() --> generate_from_geometry2() failed")
-                    return 'fail'
-                else:
-                    dia_cnc_dict['gcode'] = res
-
-                # tell gcode_parse from which point to start drawing the lines depending on what kind of
-                # object is the source of gcode
-                job_obj.toolchange_xy_type = "geometry"
-
-                self.app.inform.emit('[success] %s' % _("G-Code parsing in progress..."))
-                dia_cnc_dict['gcode_parsed'] = job_obj.gcode_parse()
-                self.app.inform.emit('[success] %s' % _("G-Code parsing finished..."))
-
-                # TODO this serve for bounding box creation only; should be optimized
-                # commented this; there is no need for the actual GCode geometry - the original one will serve as well
-                # for bounding box values
-                # dia_cnc_dict['solid_geometry'] = cascaded_union([geo['geom'] for geo in dia_cnc_dict['gcode_parsed']])
-                try:
-                    dia_cnc_dict['solid_geometry'] = tool_solid_geometry
-                    self.app.inform.emit('[success] %s...' % _("Finished G-Code processing"))
-                except Exception as e:
-                    self.app.inform.emit('[ERROR] %s: %s' % (_("G-Code processing failed with error"), str(e)))
-
-                job_obj.cnc_tools.update({
-                    tooluid_key: deepcopy(dia_cnc_dict)
-                })
-                dia_cnc_dict.clear()
-
-        # 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)
-
-            current_uid = int(1)
-
-            job_obj.options['xmin'] = xmin
-            job_obj.options['ymin'] = ymin
-            job_obj.options['xmax'] = xmax
-            job_obj.options['ymax'] = ymax
-
-            # count the tools
-            tool_cnt = 0
-
-            dia_cnc_dict = {}
-
-            # this turn on the FlatCAMCNCJob plot for multiple tools
-            job_obj.multitool = True
-            job_obj.multigeo = True
-            job_obj.cnc_tools.clear()
-
-            job_obj.options['Tools_in_use'] = tools_in_use
-            job_obj.segx = segx if segx else float(self.app.defaults["geometry_segx"])
-            job_obj.segy = segy if segy else float(self.app.defaults["geometry_segy"])
-
-            job_obj.z_pdepth = float(self.app.defaults["geometry_z_pdepth"])
-            job_obj.feedrate_probe = float(self.app.defaults["geometry_feedrate_probe"])
-
-            # make sure that trying to make a CNCJob from an empty file is not creating an app crash
-            if not self.solid_geometry:
-                a = 0
-                for tooluid_key in self.tools:
-                    if self.tools[tooluid_key]['solid_geometry'] is None:
-                        a += 1
-                if a == len(self.tools):
-                    self.app.inform.emit('[ERROR_NOTCL] %s...' % _('Cancelled. Empty file, it has no geometry'))
-                    return 'fail'
-
-            for tooluid_key in list(tools_dict.keys()):
-                tool_cnt += 1
-                dia_cnc_dict = deepcopy(tools_dict[tooluid_key])
-                tooldia_val = float('%.*f' % (self.decimals, float(tools_dict[tooluid_key]['tooldia'])))
-
-                dia_cnc_dict.update({
-                    'tooldia': tooldia_val
-                })
-
-                # find the tool_dia associated with the tooluid_key
-                # search in the self.tools for the sel_tool_dia and when found see what tooluid has
-                # on the found tooluid in self.tools we also have the solid_geometry that interest us
-                # for k, v in self.tools.items():
-                #     if float('%.*f' % (self.decimals, float(v['tooldia']))) == tooldia_val:
-                #         current_uid = int(k)
-                #         break
-
-                if dia_cnc_dict['offset'] == 'in':
-                    tool_offset = -tooldia_val / 2
-                elif dia_cnc_dict['offset'].lower() == 'out':
-                    tool_offset = tooldia_val / 2
-                elif dia_cnc_dict['offset'].lower() == 'custom':
-                    offset_value = float(self.ui.tool_offset_entry.get_value())
-                    if offset_value:
-                        tool_offset = float(offset_value)
-                    else:
-                        self.app.inform.emit('[WARNING] %s' %
-                                             _("Tool Offset is selected in Tool Table but "
-                                               "no value is provided.\n"
-                                               "Add a Tool Offset or change the Offset Type."))
-                        return
-                else:
-                    tool_offset = 0.0
-
-                dia_cnc_dict.update({
-                    'offset_value': tool_offset
-                })
-
-                z_cut = tools_dict[tooluid_key]['data']["cutz"]
-                z_move = tools_dict[tooluid_key]['data']["travelz"]
-                feedrate = tools_dict[tooluid_key]['data']["feedrate"]
-                feedrate_z = tools_dict[tooluid_key]['data']["feedrate_z"]
-                feedrate_rapid = tools_dict[tooluid_key]['data']["feedrate_rapid"]
-                multidepth = tools_dict[tooluid_key]['data']["multidepth"]
-                extracut = tools_dict[tooluid_key]['data']["extracut"]
-                extracut_length = tools_dict[tooluid_key]['data']["extracut_length"]
-                depthpercut = tools_dict[tooluid_key]['data']["depthperpass"]
-                toolchange = tools_dict[tooluid_key]['data']["toolchange"]
-                toolchangez = tools_dict[tooluid_key]['data']["toolchangez"]
-                toolchangexy = tools_dict[tooluid_key]['data']["toolchangexy"]
-                startz = tools_dict[tooluid_key]['data']["startz"]
-                endz = tools_dict[tooluid_key]['data']["endz"]
-                endxy = self.options["endxy"]
-                spindlespeed = tools_dict[tooluid_key]['data']["spindlespeed"]
-                dwell = tools_dict[tooluid_key]['data']["dwell"]
-                dwelltime = tools_dict[tooluid_key]['data']["dwelltime"]
-                pp_geometry_name = tools_dict[tooluid_key]['data']["ppname_g"]
-
-                spindledir = self.app.defaults['geometry_spindledir']
-                tool_solid_geometry = self.tools[tooluid_key]['solid_geometry']
-
-                job_obj.coords_decimals = self.app.defaults["cncjob_coords_decimals"]
-                job_obj.fr_decimals = self.app.defaults["cncjob_fr_decimals"]
-
-                # Propagate options
-                job_obj.options["tooldia"] = tooldia_val
-                job_obj.options['type'] = 'Geometry'
-                job_obj.options['tool_dia'] = tooldia_val
-
-                # it seems that the tolerance needs to be a lot lower value than 0.01 and it was hardcoded initially
-                # to a value of 0.0005 which is 20 times less than 0.01
-                tol = float(self.app.defaults['global_tolerance']) / 20
-                res = job_obj.generate_from_multitool_geometry(
-                    tool_solid_geometry, tooldia=tooldia_val, offset=tool_offset,
-                    tolerance=tol, z_cut=z_cut, z_move=z_move,
-                    feedrate=feedrate, feedrate_z=feedrate_z, feedrate_rapid=feedrate_rapid,
-                    spindlespeed=spindlespeed, spindledir=spindledir, dwell=dwell, dwelltime=dwelltime,
-                    multidepth=multidepth, depthpercut=depthpercut,
-                    extracut=extracut, extracut_length=extracut_length, startz=startz, endz=endz, endxy=endxy,
-                    toolchange=toolchange, toolchangez=toolchangez, toolchangexy=toolchangexy,
-                    pp_geometry_name=pp_geometry_name,
-                    tool_no=tool_cnt)
-
-                if res == 'fail':
-                    log.debug("FlatCAMGeometry.mtool_gen_cncjob() --> generate_from_geometry2() failed")
-                    return 'fail'
-                else:
-                    dia_cnc_dict['gcode'] = res
-
-                self.app.inform.emit('[success] %s' % _("G-Code parsing in progress..."))
-                dia_cnc_dict['gcode_parsed'] = job_obj.gcode_parse()
-                self.app.inform.emit('[success] %s' % _("G-Code parsing finished..."))
-
-                # TODO this serve for bounding box creation only; should be optimized
-                # commented this; there is no need for the actual GCode geometry - the original one will serve as well
-                # for bounding box values
-                # geo_for_bound_values = cascaded_union([
-                #     geo['geom'] for geo in dia_cnc_dict['gcode_parsed'] if geo['geom'].is_valid is True
-                # ])
-                try:
-                    dia_cnc_dict['solid_geometry'] = deepcopy(tool_solid_geometry)
-                    self.app.inform.emit('[success] %s' % _("Finished G-Code processing..."))
-                except Exception as ee:
-                    self.app.inform.emit('[ERROR] %s: %s' % (_("G-Code processing failed with error"), str(ee)))
-
-                # tell gcode_parse from which point to start drawing the lines depending on what kind of
-                # object is the source of gcode
-                job_obj.toolchange_xy_type = "geometry"
-
-                job_obj.cnc_tools.update({
-                    tooluid_key: deepcopy(dia_cnc_dict)
-                })
-                dia_cnc_dict.clear()
-
-        if use_thread:
-            # To be run in separate thread
-            def job_thread(app_obj):
-                if self.multigeo is False:
-                    with self.app.proc_container.new(_("Generating CNC Code")):
-                        if app_obj.new_object("cncjob", outname, job_init_single_geometry, plot=plot) != 'fail':
-                            app_obj.inform.emit('[success] %s: %s' % (_("CNCjob created"), outname))
-                else:
-                    with self.app.proc_container.new(_("Generating CNC Code")):
-                        if app_obj.new_object("cncjob", outname, job_init_multi_geometry) != 'fail':
-                            app_obj.inform.emit('[success] %s: %s' % (_("CNCjob created"), outname))
-
-            # Create a promise with the name
-            self.app.collection.promise(outname)
-            # Send to worker
-            self.app.worker_task.emit({'fcn': job_thread, 'params': [self.app]})
-        else:
-            if self.solid_geometry:
-                self.app.new_object("cncjob", outname, job_init_single_geometry, plot=plot)
-            else:
-                self.app.new_object("cncjob", outname, job_init_multi_geometry, plot=plot)
-
-    def generatecncjob(
-            self, outname=None,
-            dia=None, offset=None,
-            z_cut=None, z_move=None,
-            feedrate=None, feedrate_z=None, feedrate_rapid=None,
-            spindlespeed=None, dwell=None, dwelltime=None,
-            multidepth=None, depthperpass=None,
-            toolchange=None, toolchangez=None, toolchangexy=None,
-            extracut=None, extracut_length=None, startz=None, endz=None,
-            pp=None,
-            segx=None, segy=None,
-            use_thread=True,
-            plot=True):
-        """
-        Only used for TCL Command.
-        Creates a CNCJob out of this Geometry object. The actual
-        work is done by the target camlib.CNCjob
-        `generate_from_geometry_2()` method.
-
-        :param outname:         Name of the new object
-        :param dia:             Tool diameter
-        :param offset:
-        :param z_cut:           Cut depth (negative value)
-        :param z_move:          Height of the tool when travelling (not cutting)
-        :param feedrate:        Feed rate while cutting on X - Y plane
-        :param feedrate_z:      Feed rate while cutting on Z plane
-        :param feedrate_rapid:  Feed rate while moving with rapids
-        :param spindlespeed:    Spindle speed (RPM)
-        :param dwell:
-        :param dwelltime:
-        :param multidepth:
-        :param depthperpass:
-        :param toolchange:
-        :param toolchangez:
-        :param toolchangexy:
-        :param extracut:
-        :param extracut_length:
-        :param startz:
-        :param endz:
-        :param pp:              Name of the preprocessor
-        :param segx:
-        :param segy:
-        :param use_thread:
-        :param plot:
-        :return: None
-        """
-
-        tooldia = dia if dia else float(self.options["cnctooldia"])
-        outname = outname if outname is not None else self.options["name"]
-
-        z_cut = z_cut if z_cut is not None else float(self.options["cutz"])
-        z_move = z_move if z_move is not None else float(self.options["travelz"])
-
-        feedrate = feedrate if feedrate is not None else float(self.options["feedrate"])
-        feedrate_z = feedrate_z if feedrate_z is not None else float(self.options["feedrate_z"])
-        feedrate_rapid = feedrate_rapid if feedrate_rapid is not None else float(self.options["feedrate_rapid"])
-
-        multidepth = multidepth if multidepth is not None else self.options["multidepth"]
-        depthperpass = depthperpass if depthperpass is not None else float(self.options["depthperpass"])
-
-        segx = segx if segx is not None else float(self.app.defaults['geometry_segx'])
-        segy = segy if segy is not None else float(self.app.defaults['geometry_segy'])
-
-        extracut = extracut if extracut is not None else float(self.options["extracut"])
-        extracut_length = extracut_length if extracut_length is not None else float(self.options["extracut_length"])
-
-        startz = startz if startz is not None else self.options["startz"]
-        endz = endz if endz is not None else float(self.options["endz"])
-        endxy = self.options["endxy"]
-
-        toolchangez = toolchangez if toolchangez else float(self.options["toolchangez"])
-        toolchangexy = toolchangexy if toolchangexy else self.options["toolchangexy"]
-        toolchange = toolchange if toolchange else self.options["toolchange"]
-
-        offset = offset if offset else 0.0
-
-        # int or None.
-        spindlespeed = spindlespeed if spindlespeed else self.options['spindlespeed']
-        dwell = dwell if dwell else self.options["dwell"]
-        dwelltime = dwelltime if dwelltime else float(self.options["dwelltime"])
-
-        ppname_g = pp if pp else self.options["ppname_g"]
-
-        # Object initialization function for app.new_object()
-        # RUNNING ON SEPARATE THREAD!
-        def job_init(job_obj, app_obj):
-            assert isinstance(job_obj, FlatCAMCNCjob), "Initializer expected a FlatCAMCNCjob, got %s" % type(job_obj)
-
-            # Propagate options
-            job_obj.options["tooldia"] = tooldia
-
-            job_obj.coords_decimals = self.app.defaults["cncjob_coords_decimals"]
-            job_obj.fr_decimals = self.app.defaults["cncjob_fr_decimals"]
-
-            job_obj.options['type'] = 'Geometry'
-            job_obj.options['tool_dia'] = tooldia
-
-            job_obj.segx = segx
-            job_obj.segy = segy
-
-            job_obj.z_pdepth = float(self.options["z_pdepth"])
-            job_obj.feedrate_probe = float(self.options["feedrate_probe"])
-
-            job_obj.options['xmin'] = self.options['xmin']
-            job_obj.options['ymin'] = self.options['ymin']
-            job_obj.options['xmax'] = self.options['xmax']
-            job_obj.options['ymax'] = self.options['ymax']
-
-            # it seems that the tolerance needs to be a lot lower value than 0.01 and it was hardcoded initially
-            # to a value of 0.0005 which is 20 times less than 0.01
-            tol = float(self.app.defaults['global_tolerance']) / 20
-            job_obj.generate_from_geometry_2(
-                self, tooldia=tooldia, offset=offset, tolerance=tol,
-                z_cut=z_cut, z_move=z_move,
-                feedrate=feedrate, feedrate_z=feedrate_z, feedrate_rapid=feedrate_rapid,
-                spindlespeed=spindlespeed, dwell=dwell, dwelltime=dwelltime,
-                multidepth=multidepth, depthpercut=depthperpass,
-                toolchange=toolchange, toolchangez=toolchangez, toolchangexy=toolchangexy,
-                extracut=extracut, extracut_length=extracut_length, startz=startz, endz=endz, endxy=endxy,
-                pp_geometry_name=ppname_g
-            )
-
-            # tell gcode_parse from which point to start drawing the lines depending on what kind of object is the
-            # source of gcode
-            job_obj.toolchange_xy_type = "geometry"
-            job_obj.gcode_parse()
-            self.app.inform.emit('[success] %s' % _("Finished G-Code processing..."))
-
-        if use_thread:
-            # To be run in separate thread
-            def job_thread(app_obj):
-                with self.app.proc_container.new(_("Generating CNC Code")):
-                    app_obj.new_object("cncjob", outname, job_init, plot=plot)
-                    app_obj.inform.emit('[success] %s: %s' % (_("CNCjob created")), outname)
-
-            # Create a promise with the name
-            self.app.collection.promise(outname)
-            # Send to worker
-            self.app.worker_task.emit({'fcn': job_thread, 'params': [self.app]})
-        else:
-            self.app.new_object("cncjob", outname, job_init, plot=plot)
-
-    # def on_plot_cb_click(self, *args):
-    #     if self.muted_ui:
-    #         return
-    #     self.read_form_item('plot')
-
-    def scale(self, xfactor, yfactor=None, point=None):
-        """
-        Scales all geometry by a given factor.
-
-        :param xfactor: Factor by which to scale the object's geometry/
-        :type xfactor: float
-        :param yfactor: Factor by which to scale the object's geometry/
-        :type yfactor: float
-        :return: None
-        :rtype: None
-        """
-        log.debug("FlatCAMObj.FlatCAMGeometry.scale()")
-
-        try:
-            xfactor = float(xfactor)
-        except Exception:
-            self.app.inform.emit('[ERROR_NOTCL] %s' % _("Scale factor has to be a number: integer or float."))
-            return
-
-        if yfactor is None:
-            yfactor = xfactor
-        else:
-            try:
-                yfactor = float(yfactor)
-            except Exception:
-                self.app.inform.emit('[ERROR_NOTCL] %s' % _("Scale factor has to be a number: integer or float."))
-                return
-
-        if xfactor == 1 and yfactor == 1:
-            return
-
-        if point is None:
-            px = 0
-            py = 0
-        else:
-            px, py = point
-
-        self.geo_len = 0
-        self.old_disp_number = 0
-        self.el_count = 0
-
-        def scale_recursion(geom):
-            if type(geom) is list:
-                geoms = []
-                for local_geom in geom:
-                    geoms.append(scale_recursion(local_geom))
-                return geoms
-            else:
-                try:
-                    self.el_count += 1
-                    disp_number = int(np.interp(self.el_count, [0, self.geo_len], [0, 100]))
-                    if self.old_disp_number < disp_number <= 100:
-                        self.app.proc_container.update_view_text(' %d%%' % disp_number)
-                        self.old_disp_number = disp_number
-
-                    return affinity.scale(geom, xfactor, yfactor, origin=(px, py))
-                except AttributeError:
-                    return geom
-
-        if self.multigeo is True:
-            for tool in self.tools:
-                # variables to display the percentage of work done
-                self.geo_len = 0
-                try:
-                    self.geo_len = len(self.tools[tool]['solid_geometry'])
-                except TypeError:
-                    self.geo_len = 1
-                self.old_disp_number = 0
-                self.el_count = 0
-
-                self.tools[tool]['solid_geometry'] = scale_recursion(self.tools[tool]['solid_geometry'])
-
-        try:
-            # variables to display the percentage of work done
-            self.geo_len = 0
-            try:
-                self.geo_len = len(self.solid_geometry)
-            except TypeError:
-                self.geo_len = 1
-            self.old_disp_number = 0
-            self.el_count = 0
-
-            self.solid_geometry = scale_recursion(self.solid_geometry)
-        except AttributeError:
-            self.solid_geometry = []
-            return
-
-        self.app.proc_container.new_text = ''
-        self.app.inform.emit('[success] %s' % _("Geometry Scale done."))
-
-    def offset(self, vect):
-        """
-        Offsets all geometry by a given vector/
-
-        :param vect: (x, y) vector by which to offset the object's geometry.
-        :type vect: tuple
-        :return: None
-        :rtype: None
-        """
-        log.debug("FlatCAMObj.FlatCAMGeometry.offset()")
-
-        try:
-            dx, dy = vect
-        except TypeError:
-            self.app.inform.emit('[ERROR_NOTCL] %s' %
-                                 _("An (x,y) pair of values are needed. "
-                                   "Probable you entered only one value in the Offset field.")
-                                 )
-            return
-
-        if dx == 0 and dy == 0:
-            return
-
-        self.geo_len = 0
-        self.old_disp_number = 0
-        self.el_count = 0
-
-        def translate_recursion(geom):
-            if type(geom) is list:
-                geoms = []
-                for local_geom in geom:
-                    geoms.append(translate_recursion(local_geom))
-                return geoms
-            else:
-                try:
-                    self.el_count += 1
-                    disp_number = int(np.interp(self.el_count, [0, self.geo_len], [0, 100]))
-                    if self.old_disp_number < disp_number <= 100:
-                        self.app.proc_container.update_view_text(' %d%%' % disp_number)
-                        self.old_disp_number = disp_number
-
-                    return affinity.translate(geom, xoff=dx, yoff=dy)
-                except AttributeError:
-                    return geom
-
-        if self.multigeo is True:
-            for tool in self.tools:
-                # variables to display the percentage of work done
-                self.geo_len = 0
-                try:
-                    self.geo_len = len(self.tools[tool]['solid_geometry'])
-                except TypeError:
-                    self.geo_len = 1
-                self.old_disp_number = 0
-                self.el_count = 0
-
-                self.tools[tool]['solid_geometry'] = translate_recursion(self.tools[tool]['solid_geometry'])
-
-        # variables to display the percentage of work done
-        self.geo_len = 0
-        try:
-            self.geo_len = len(self.solid_geometry)
-        except TypeError:
-            self.geo_len = 1
-
-        self.old_disp_number = 0
-        self.el_count = 0
-
-        self.solid_geometry = translate_recursion(self.solid_geometry)
-
-        self.app.proc_container.new_text = ''
-        self.app.inform.emit('[success] %s' % _("Geometry Offset done."))
-
-    def convert_units(self, units):
-        log.debug("FlatCAMObj.FlatCAMGeometry.convert_units()")
-
-        self.ui_disconnect()
-
-        factor = Geometry.convert_units(self, units)
-
-        self.options['cutz'] = float(self.options['cutz']) * factor
-        self.options['depthperpass'] = float(self.options['depthperpass']) * factor
-        self.options['travelz'] = float(self.options['travelz']) * factor
-        self.options['feedrate'] = float(self.options['feedrate']) * factor
-        self.options['feedrate_z'] = float(self.options['feedrate_z']) * factor
-        self.options['feedrate_rapid'] = float(self.options['feedrate_rapid']) * factor
-        self.options['endz'] = float(self.options['endz']) * factor
-        # self.options['cnctooldia'] *= factor
-        # self.options['painttooldia'] *= factor
-        # self.options['paintmargin'] *= factor
-        # self.options['paintoverlap'] *= factor
-
-        self.options["toolchangez"] = float(self.options["toolchangez"]) * factor
-
-        if self.app.defaults["geometry_toolchangexy"] == '':
-            self.options['toolchangexy'] = "0.0, 0.0"
-        else:
-            coords_xy = [float(eval(coord)) for coord in self.app.defaults["geometry_toolchangexy"].split(",")]
-            if len(coords_xy) < 2:
-                self.app.inform.emit('[ERROR] %s' %
-                                     _("The Toolchange X,Y field in Edit -> Preferences "
-                                       "has to be in the format (x, y)\n"
-                                       "but now there is only one value, not two.")
-                                     )
-                return 'fail'
-            coords_xy[0] *= factor
-            coords_xy[1] *= factor
-            self.options['toolchangexy'] = "%f, %f" % (coords_xy[0], coords_xy[1])
-
-        if self.options['startz'] is not None:
-            self.options['startz'] = float(self.options['startz']) * factor
-
-        param_list = ['cutz', 'depthperpass', 'travelz', 'feedrate', 'feedrate_z', 'feedrate_rapid',
-                      'endz', 'toolchangez']
-
-        if isinstance(self, FlatCAMGeometry):
-            temp_tools_dict = {}
-            tool_dia_copy = {}
-            data_copy = {}
-            for tooluid_key, tooluid_value in self.tools.items():
-                for dia_key, dia_value in tooluid_value.items():
-                    if dia_key == 'tooldia':
-                        dia_value *= factor
-                        dia_value = float('%.*f' % (self.decimals, dia_value))
-                        tool_dia_copy[dia_key] = dia_value
-                    if dia_key == 'offset':
-                        tool_dia_copy[dia_key] = dia_value
-                    if dia_key == 'offset_value':
-                        dia_value *= factor
-                        tool_dia_copy[dia_key] = dia_value
-
-                        # convert the value in the Custom Tool Offset entry in UI
-                        custom_offset = None
-                        try:
-                            custom_offset = float(self.ui.tool_offset_entry.get_value())
-                        except ValueError:
-                            # try to convert comma to decimal point. if it's still not working error message and return
-                            try:
-                                custom_offset = float(self.ui.tool_offset_entry.get_value().replace(',', '.'))
-                            except ValueError:
-                                self.app.inform.emit('[ERROR_NOTCL] %s' %
-                                                     _("Wrong value format entered, use a number."))
-                                return
-                        except TypeError:
-                            pass
-
-                        if custom_offset:
-                            custom_offset *= factor
-                            self.ui.tool_offset_entry.set_value(custom_offset)
-
-                    if dia_key == 'type':
-                        tool_dia_copy[dia_key] = dia_value
-                    if dia_key == 'tool_type':
-                        tool_dia_copy[dia_key] = dia_value
-                    if dia_key == 'data':
-                        for data_key, data_value in dia_value.items():
-                            # convert the form fields that are convertible
-                            for param in param_list:
-                                if data_key == param and data_value is not None:
-                                    data_copy[data_key] = data_value * factor
-                            # copy the other dict entries that are not convertible
-                            if data_key not in param_list:
-                                data_copy[data_key] = data_value
-                        tool_dia_copy[dia_key] = deepcopy(data_copy)
-                        data_copy.clear()
-
-                temp_tools_dict.update({
-                    tooluid_key: deepcopy(tool_dia_copy)
-                })
-                tool_dia_copy.clear()
-
-            self.tools.clear()
-            self.tools = deepcopy(temp_tools_dict)
-
-        # if there is a value in the new tool field then convert that one too
-        try:
-            self.ui.addtool_entry.returnPressed.disconnect()
-        except TypeError:
-            pass
-        tooldia = self.ui.addtool_entry.get_value()
-        if tooldia:
-            tooldia *= factor
-            tooldia = float('%.*f' % (self.decimals, tooldia))
-
-            self.ui.addtool_entry.set_value(tooldia)
-        self.ui.addtool_entry.returnPressed.connect(self.on_tool_add)
-
-        return factor
-
-    def plot_element(self, element, color=None, visible=None):
-
-        if color is None:
-            color = '#FF0000FF'
-
-        visible = visible if visible else self.options['plot']
-        try:
-            for sub_el in element:
-                self.plot_element(sub_el, color=color)
-
-        except TypeError:  # Element is not iterable...
-            # if self.app.is_legacy is False:
-            self.add_shape(shape=element, color=color, visible=visible, layer=0)
-
-    def plot(self, visible=None, kind=None):
-        """
-        Plot the object.
-
-        :param visible: Controls if the added shape is visible of not
-        :param kind: added so there is no error when a project is loaded and it has both geometry and CNCJob, because
-        CNCJob require the 'kind' parameter. Perhaps the FlatCAMObj.plot() has to be rewrited
-        :return:
-        """
-
-        # Does all the required setup and returns False
-        # if the 'ptint' option is set to False.
-        if not FlatCAMObj.plot(self):
-            return
-
-        try:
-            # plot solid geometries found as members of self.tools attribute dict
-            # for MultiGeo
-            if self.multigeo is True:  # geo multi tool usage
-                for tooluid_key in self.tools:
-                    solid_geometry = self.tools[tooluid_key]['solid_geometry']
-                    self.plot_element(solid_geometry, visible=visible,
-                                      color=self.app.defaults["geometry_plot_line"])
-            else:
-                # plot solid geometry that may be an direct attribute of the geometry object
-                # for SingleGeo
-                if self.solid_geometry:
-                    self.plot_element(self.solid_geometry, visible=visible,
-                                      color=self.app.defaults["geometry_plot_line"])
-
-            # self.plot_element(self.solid_geometry, visible=self.options['plot'])
-
-            self.shapes.redraw()
-
-        except (ObjectDeleted, AttributeError):
-            self.shapes.clear(update=True)
-
-    def on_plot_cb_click(self, *args):
-        if self.muted_ui:
-            return
-        self.read_form_item('plot')
-        self.plot()
-
-        self.ui_disconnect()
-        cb_flag = self.ui.plot_cb.isChecked()
-        for row in range(self.ui.geo_tools_table.rowCount()):
-            table_cb = self.ui.geo_tools_table.cellWidget(row, 6)
-            if cb_flag:
-                table_cb.setChecked(True)
-            else:
-                table_cb.setChecked(False)
-        self.ui_connect()
-
-    def on_plot_cb_click_table(self):
-        # self.ui.cnc_tools_table.cellWidget(row, 2).widget().setCheckState(QtCore.Qt.Unchecked)
-        self.ui_disconnect()
-        # cw = self.sender()
-        # cw_index = self.ui.geo_tools_table.indexAt(cw.pos())
-        # cw_row = cw_index.row()
-        check_row = 0
-
-        self.shapes.clear(update=True)
-        for tooluid_key in self.tools:
-            solid_geometry = self.tools[tooluid_key]['solid_geometry']
-
-            # find the geo_tool_table row associated with the tooluid_key
-            for row in range(self.ui.geo_tools_table.rowCount()):
-                tooluid_item = int(self.ui.geo_tools_table.item(row, 5).text())
-                if tooluid_item == int(tooluid_key):
-                    check_row = row
-                    break
-            if self.ui.geo_tools_table.cellWidget(check_row, 6).isChecked():
-                self.plot_element(element=solid_geometry, visible=True)
-        self.shapes.redraw()
-
-        # make sure that the general plot is disabled if one of the row plot's are disabled and
-        # if all the row plot's are enabled also enable the general plot checkbox
-        cb_cnt = 0
-        total_row = self.ui.geo_tools_table.rowCount()
-        for row in range(total_row):
-            if self.ui.geo_tools_table.cellWidget(row, 6).isChecked():
-                cb_cnt += 1
-            else:
-                cb_cnt -= 1
-        if cb_cnt < total_row:
-            self.ui.plot_cb.setChecked(False)
-        else:
-            self.ui.plot_cb.setChecked(True)
-        self.ui_connect()
-
-    def merge(self, geo_list, geo_final, multigeo=None):
-        """
-        Merges the geometry of objects in grb_list into
-        the geometry of geo_final.
-
-        :param geo_list: List of FlatCAMGerber Objects to join.
-        :param geo_final: Destination FlatCAMGerber object.
-        :param multigeo: if the merged geometry objects are of type MultiGeo
-        :return: None
-        """
-
-        if geo_final.solid_geometry is None:
-            geo_final.solid_geometry = []
-
-        try:
-            __ = iter(geo_final.solid_geometry)
-        except TypeError:
-            geo_final.solid_geometry = [geo_final.solid_geometry]
-
-        new_solid_geometry = []
-        new_options = {}
-        new_tools = {}
-
-        for geo_obj in geo_list:
-            for option in geo_obj.options:
-                if option != 'name':
-                    try:
-                        new_options[option] = deepcopy(geo_obj.options[option])
-                    except Exception as e:
-                        log.warning("Failed to copy option %s. Error: %s" % (str(option), str(e)))
-
-            # Expand lists
-            if type(geo_obj) is list:
-                FlatCAMGeometry.merge(self, geo_list=geo_obj, geo_final=geo_final)
-            # If not list, just append
-            else:
-                if multigeo is None or multigeo is False:
-                    geo_final.multigeo = False
-                else:
-                    geo_final.multigeo = True
-
-                try:
-                    new_solid_geometry += deepcopy(geo_obj.solid_geometry)
-                except Exception as e:
-                    log.debug("FlatCAMGeometry.merge() --> %s" % str(e))
-
-                # find the tool_uid maximum value in the geo_final
-                try:
-                    max_uid = max([int(i) for i in new_tools.keys()])
-                except ValueError:
-                    max_uid = 0
-
-                # add and merge tools. If what we try to merge as Geometry is Excellon's and/or Gerber's then don't try
-                # to merge the obj.tools as it is likely there is none to merge.
-                if not isinstance(geo_obj, FlatCAMGerber) and not isinstance(geo_obj, FlatCAMExcellon):
-                    for tool_uid in geo_obj.tools:
-                        max_uid += 1
-                        new_tools[max_uid] = deepcopy(geo_obj.tools[tool_uid])
-
-        geo_final.options.update(new_options)
-        geo_final.solid_geometry = new_solid_geometry
-        geo_final.tools = new_tools
-
-    @staticmethod
-    def get_pts(o):
-        """
-        Returns a list of all points in the object, where
-        the object can be a MultiPolygon, Polygon, Not a polygon, or a list
-        of such. Search is done recursively.
-
-        :param: geometric object
-        :return: List of points
-        :rtype: list
-        """
-        pts = []
-
-        # Iterable: descend into each item.
-        try:
-            for subo in o:
-                pts += FlatCAMGeometry.get_pts(subo)
-
-        # Non-iterable
-        except TypeError:
-            if o is not None:
-                if type(o) == MultiPolygon:
-                    for poly in o:
-                        pts += FlatCAMGeometry.get_pts(poly)
-                # ## Descend into .exerior and .interiors
-                elif type(o) == Polygon:
-                    pts += FlatCAMGeometry.get_pts(o.exterior)
-                    for i in o.interiors:
-                        pts += FlatCAMGeometry.get_pts(i)
-                elif type(o) == MultiLineString:
-                    for line in o:
-                        pts += FlatCAMGeometry.get_pts(line)
-                # ## Has .coords: list them.
-                else:
-                    pts += list(o.coords)
-            else:
-                return
-        return pts
-
-
-class FlatCAMCNCjob(FlatCAMObj, CNCjob):
-    """
-    Represents G-Code.
-    """
-    optionChanged = QtCore.pyqtSignal(str)
-    ui_type = CNCObjectUI
-
-    def __init__(self, name, units="in", kind="generic", z_move=0.1,
-                 feedrate=3.0, feedrate_rapid=3.0, z_cut=-0.002, tooldia=0.0,
-                 spindlespeed=None):
-
-        log.debug("Creating CNCJob object...")
-
-        self.decimals = self.app.decimals
-
-        CNCjob.__init__(self, units=units, kind=kind, z_move=z_move,
-                        feedrate=feedrate, feedrate_rapid=feedrate_rapid, z_cut=z_cut, tooldia=tooldia,
-                        spindlespeed=spindlespeed, steps_per_circle=int(self.app.defaults["cncjob_steps_per_circle"]))
-
-        FlatCAMObj.__init__(self, name)
-
-        self.kind = "cncjob"
-
-        self.options.update({
-            "plot": True,
-            "tooldia": 0.03937,  # 0.4mm in inches
-            "append": "",
-            "prepend": "",
-            "dwell": False,
-            "dwelltime": 1,
-            "type": 'Geometry',
-            "toolchange_macro": '',
-            "toolchange_macro_enable": False
-        })
-
-        '''
-            This is a dict of dictionaries. Each dict is associated with a tool present in the file. The key is the 
-            diameter of the tools and the value is another dict that will hold the data under the following form:
-               {tooldia:   {
-                           'tooluid': 1,
-                           'offset': 'Path',
-                           'type_item': 'Rough',
-                           'tool_type': 'C1',
-                           'data': {} # a dict to hold the parameters
-                           'gcode': "" # a string with the actual GCODE
-                           'gcode_parsed': {} # dictionary holding the CNCJob geometry and type of geometry 
-                           (cut or move)
-                           'solid_geometry': []
-                           },
-                           ...
-               }
-            It is populated in the FlatCAMGeometry.mtool_gen_cncjob()
-            BEWARE: I rely on the ordered nature of the Python 3.7 dictionary. Things might change ...
-        '''
-        self.cnc_tools = {}
-
-        '''
-           This is a dict of dictionaries. Each dict is associated with a tool present in the file. The key is the 
-           diameter of the tools and the value is another dict that will hold the data under the following form:
-              {tooldia:   {
-                          'tool': int,
-                          'nr_drills': int,
-                          'nr_slots': int,
-                          'offset': float,
-                          'data': {} # a dict to hold the parameters
-                          'gcode': "" # a string with the actual GCODE
-                          'gcode_parsed': {} # dictionary holding the CNCJob geometry and type of geometry (cut or move)
-                          'solid_geometry': []
-                          },
-                          ...
-              }
-           It is populated in the FlatCAMExcellon.on_create_cncjob_click() but actually 
-           it's done in camlib.CNCJob.generate_from_excellon_by_tool()
-           BEWARE: I rely on the ordered nature of the Python 3.7 dictionary. Things might change ...
-       '''
-        self.exc_cnc_tools = {}
-
-        # flag to store if the CNCJob is part of a special group of CNCJob objects that can't be processed by the
-        # default engine of FlatCAM. They generated by some of tools and are special cases of CNCJob objects.
-        self.special_group = None
-
-        # for now it show if the plot will be done for multi-tool CNCJob (True) or for single tool
-        # (like the one in the TCL Command), False
-        self.multitool = False
-
-        # determine if the GCode was generated out of a Excellon object or a Geometry object
-        self.origin_kind = None
-
-        # used for parsing the GCode lines to adjust the GCode when the GCode is offseted or scaled
-        gcodex_re_string = r'(?=.*(X[-\+]?\d*\.\d*))'
-        self.g_x_re = re.compile(gcodex_re_string)
-        gcodey_re_string = r'(?=.*(Y[-\+]?\d*\.\d*))'
-        self.g_y_re = re.compile(gcodey_re_string)
-        gcodez_re_string = r'(?=.*(Z[-\+]?\d*\.\d*))'
-        self.g_z_re = re.compile(gcodez_re_string)
-
-        gcodef_re_string = r'(?=.*(F[-\+]?\d*\.\d*))'
-        self.g_f_re = re.compile(gcodef_re_string)
-        gcodet_re_string = r'(?=.*(\=\s*[-\+]?\d*\.\d*))'
-        self.g_t_re = re.compile(gcodet_re_string)
-
-        gcodenr_re_string = r'([+-]?\d*\.\d+)'
-        self.g_nr_re = re.compile(gcodenr_re_string)
-
-        # Attributes to be included in serialization
-        # Always append to it because it carries contents
-        # from predecessors.
-        self.ser_attrs += ['options', 'kind', 'origin_kind', 'cnc_tools', 'exc_cnc_tools', 'multitool']
-
-        if self.app.is_legacy is False:
-            self.text_col = self.app.plotcanvas.new_text_collection()
-            self.text_col.enabled = True
-            self.annotation = self.app.plotcanvas.new_text_group(collection=self.text_col)
-
-        self.gcode_editor_tab = None
-
-        self.units_found = self.app.defaults['units']
-
-    def build_ui(self):
-        self.ui_disconnect()
-
-        FlatCAMObj.build_ui(self)
-        self.units = self.app.defaults['units'].upper()
-
-        # if the FlatCAM object is Excellon don't build the CNC Tools Table but hide it
-        self.ui.cnc_tools_table.hide()
-        if self.cnc_tools:
-            self.ui.cnc_tools_table.show()
-            self.build_cnc_tools_table()
-
-        self.ui.exc_cnc_tools_table.hide()
-        if self.exc_cnc_tools:
-            self.ui.exc_cnc_tools_table.show()
-            self.build_excellon_cnc_tools()
-        #
-        self.ui_connect()
-
-    def build_cnc_tools_table(self):
-        tool_idx = 0
-
-        n = len(self.cnc_tools)
-        self.ui.cnc_tools_table.setRowCount(n)
-
-        for dia_key, dia_value in self.cnc_tools.items():
-
-            tool_idx += 1
-            row_no = tool_idx - 1
-
-            t_id = QtWidgets.QTableWidgetItem('%d' % int(tool_idx))
-            # id.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
-            self.ui.cnc_tools_table.setItem(row_no, 0, t_id)  # Tool name/id
-
-            # Make sure that the tool diameter when in MM is with no more than 2 decimals.
-            # There are no tool bits in MM with more than 2 decimals diameter.
-            # For INCH the decimals should be no more than 4. There are no tools under 10mils.
-
-            dia_item = QtWidgets.QTableWidgetItem('%.*f' % (self.decimals, float(dia_value['tooldia'])))
-
-            offset_txt = list(str(dia_value['offset']))
-            offset_txt[0] = offset_txt[0].upper()
-            offset_item = QtWidgets.QTableWidgetItem(''.join(offset_txt))
-            type_item = QtWidgets.QTableWidgetItem(str(dia_value['type']))
-            tool_type_item = QtWidgets.QTableWidgetItem(str(dia_value['tool_type']))
-
-            t_id.setFlags(QtCore.Qt.ItemIsEnabled)
-            dia_item.setFlags(QtCore.Qt.ItemIsEnabled)
-            offset_item.setFlags(QtCore.Qt.ItemIsEnabled)
-            type_item.setFlags(QtCore.Qt.ItemIsEnabled)
-            tool_type_item.setFlags(QtCore.Qt.ItemIsEnabled)
-
-            # hack so the checkbox stay centered in the table cell
-            # used this:
-            # https://stackoverflow.com/questions/32458111/pyqt-allign-checkbox-and-put-it-in-every-row
-            # plot_item = QtWidgets.QWidget()
-            # checkbox = FCCheckBox()
-            # checkbox.setCheckState(QtCore.Qt.Checked)
-            # qhboxlayout = QtWidgets.QHBoxLayout(plot_item)
-            # qhboxlayout.addWidget(checkbox)
-            # qhboxlayout.setAlignment(QtCore.Qt.AlignCenter)
-            # qhboxlayout.setContentsMargins(0, 0, 0, 0)
-            plot_item = FCCheckBox()
-            plot_item.setLayoutDirection(QtCore.Qt.RightToLeft)
-            tool_uid_item = QtWidgets.QTableWidgetItem(str(dia_key))
-            if self.ui.plot_cb.isChecked():
-                plot_item.setChecked(True)
-
-            self.ui.cnc_tools_table.setItem(row_no, 1, dia_item)  # Diameter
-            self.ui.cnc_tools_table.setItem(row_no, 2, offset_item)  # Offset
-            self.ui.cnc_tools_table.setItem(row_no, 3, type_item)  # Toolpath Type
-            self.ui.cnc_tools_table.setItem(row_no, 4, tool_type_item)  # Tool Type
-
-            # ## REMEMBER: THIS COLUMN IS HIDDEN IN OBJECTUI.PY # ##
-            self.ui.cnc_tools_table.setItem(row_no, 5, tool_uid_item)  # Tool unique ID)
-            self.ui.cnc_tools_table.setCellWidget(row_no, 6, plot_item)
-
-        # make the diameter column editable
-        # for row in range(tool_idx):
-        #     self.ui.cnc_tools_table.item(row, 1).setFlags(QtCore.Qt.ItemIsSelectable |
-        #                                                   QtCore.Qt.ItemIsEnabled)
-
-        for row in range(tool_idx):
-            self.ui.cnc_tools_table.item(row, 0).setFlags(
-                self.ui.cnc_tools_table.item(row, 0).flags() ^ QtCore.Qt.ItemIsSelectable)
-
-        self.ui.cnc_tools_table.resizeColumnsToContents()
-        self.ui.cnc_tools_table.resizeRowsToContents()
-
-        vertical_header = self.ui.cnc_tools_table.verticalHeader()
-        # vertical_header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
-        vertical_header.hide()
-        self.ui.cnc_tools_table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
-
-        horizontal_header = self.ui.cnc_tools_table.horizontalHeader()
-        horizontal_header.setMinimumSectionSize(10)
-        horizontal_header.setDefaultSectionSize(70)
-        horizontal_header.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
-        horizontal_header.resizeSection(0, 20)
-        horizontal_header.setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
-        horizontal_header.setSectionResizeMode(3, QtWidgets.QHeaderView.ResizeToContents)
-        horizontal_header.setSectionResizeMode(4, QtWidgets.QHeaderView.Fixed)
-        horizontal_header.resizeSection(4, 40)
-        horizontal_header.setSectionResizeMode(6, QtWidgets.QHeaderView.Fixed)
-        horizontal_header.resizeSection(4, 17)
-        # horizontal_header.setStretchLastSection(True)
-        self.ui.cnc_tools_table.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
-
-        self.ui.cnc_tools_table.setColumnWidth(0, 20)
-        self.ui.cnc_tools_table.setColumnWidth(4, 40)
-        self.ui.cnc_tools_table.setColumnWidth(6, 17)
-
-        # self.ui.geo_tools_table.setSortingEnabled(True)
-
-        self.ui.cnc_tools_table.setMinimumHeight(self.ui.cnc_tools_table.getHeight())
-        self.ui.cnc_tools_table.setMaximumHeight(self.ui.cnc_tools_table.getHeight())
-
-    def build_excellon_cnc_tools(self):
-        tool_idx = 0
-
-        n = len(self.exc_cnc_tools)
-        self.ui.exc_cnc_tools_table.setRowCount(n)
-
-        for tooldia_key, dia_value in self.exc_cnc_tools.items():
-
-            tool_idx += 1
-            row_no = tool_idx - 1
-
-            t_id = QtWidgets.QTableWidgetItem('%d' % int(tool_idx))
-            dia_item = QtWidgets.QTableWidgetItem('%.*f' % (self.decimals, float(tooldia_key)))
-            nr_drills_item = QtWidgets.QTableWidgetItem('%d' % int(dia_value['nr_drills']))
-            nr_slots_item = QtWidgets.QTableWidgetItem('%d' % int(dia_value['nr_slots']))
-            cutz_item = QtWidgets.QTableWidgetItem('%.*f' % (self.decimals, float(dia_value['offset_z']) + self.z_cut))
-
-            t_id.setFlags(QtCore.Qt.ItemIsEnabled)
-            dia_item.setFlags(QtCore.Qt.ItemIsEnabled)
-            nr_drills_item.setFlags(QtCore.Qt.ItemIsEnabled)
-            nr_slots_item.setFlags(QtCore.Qt.ItemIsEnabled)
-            cutz_item.setFlags(QtCore.Qt.ItemIsEnabled)
-
-            # hack so the checkbox stay centered in the table cell
-            # used this:
-            # https://stackoverflow.com/questions/32458111/pyqt-allign-checkbox-and-put-it-in-every-row
-            # plot_item = QtWidgets.QWidget()
-            # checkbox = FCCheckBox()
-            # checkbox.setCheckState(QtCore.Qt.Checked)
-            # qhboxlayout = QtWidgets.QHBoxLayout(plot_item)
-            # qhboxlayout.addWidget(checkbox)
-            # qhboxlayout.setAlignment(QtCore.Qt.AlignCenter)
-            # qhboxlayout.setContentsMargins(0, 0, 0, 0)
-
-            plot_item = FCCheckBox()
-            plot_item.setLayoutDirection(QtCore.Qt.RightToLeft)
-            tool_uid_item = QtWidgets.QTableWidgetItem(str(dia_value['tool']))
-            if self.ui.plot_cb.isChecked():
-                plot_item.setChecked(True)
-
-            # TODO until the feature of individual plot for an Excellon tool is implemented
-            plot_item.setDisabled(True)
-
-            self.ui.exc_cnc_tools_table.setItem(row_no, 0, t_id)  # Tool name/id
-            self.ui.exc_cnc_tools_table.setItem(row_no, 1, dia_item)  # Diameter
-            self.ui.exc_cnc_tools_table.setItem(row_no, 2, nr_drills_item)  # Nr of drills
-            self.ui.exc_cnc_tools_table.setItem(row_no, 3, nr_slots_item)  # Nr of slots
-
-            # ## REMEMBER: THIS COLUMN IS HIDDEN IN OBJECTUI.PY # ##
-            self.ui.exc_cnc_tools_table.setItem(row_no, 4, tool_uid_item)  # Tool unique ID)
-            self.ui.exc_cnc_tools_table.setItem(row_no, 5, cutz_item)
-            self.ui.exc_cnc_tools_table.setCellWidget(row_no, 6, plot_item)
-
-        for row in range(tool_idx):
-            self.ui.exc_cnc_tools_table.item(row, 0).setFlags(
-                self.ui.exc_cnc_tools_table.item(row, 0).flags() ^ QtCore.Qt.ItemIsSelectable)
-
-        self.ui.exc_cnc_tools_table.resizeColumnsToContents()
-        self.ui.exc_cnc_tools_table.resizeRowsToContents()
-
-        vertical_header = self.ui.exc_cnc_tools_table.verticalHeader()
-        vertical_header.hide()
-        self.ui.exc_cnc_tools_table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
-
-        horizontal_header = self.ui.exc_cnc_tools_table.horizontalHeader()
-        horizontal_header.setMinimumSectionSize(10)
-        horizontal_header.setDefaultSectionSize(70)
-        horizontal_header.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
-        horizontal_header.resizeSection(0, 20)
-        horizontal_header.setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
-        horizontal_header.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
-        horizontal_header.setSectionResizeMode(3, QtWidgets.QHeaderView.ResizeToContents)
-        horizontal_header.setSectionResizeMode(5, QtWidgets.QHeaderView.ResizeToContents)
-
-        horizontal_header.setSectionResizeMode(6, QtWidgets.QHeaderView.Fixed)
-
-        # horizontal_header.setStretchLastSection(True)
-        self.ui.exc_cnc_tools_table.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
-
-        self.ui.exc_cnc_tools_table.setColumnWidth(0, 20)
-        self.ui.exc_cnc_tools_table.setColumnWidth(6, 17)
-
-        self.ui.exc_cnc_tools_table.setMinimumHeight(self.ui.exc_cnc_tools_table.getHeight())
-        self.ui.exc_cnc_tools_table.setMaximumHeight(self.ui.exc_cnc_tools_table.getHeight())
-
-    def set_ui(self, ui):
-        FlatCAMObj.set_ui(self, ui)
-
-        log.debug("FlatCAMCNCJob.set_ui()")
-
-        assert isinstance(self.ui, CNCObjectUI), \
-            "Expected a CNCObjectUI, got %s" % type(self.ui)
-
-        self.units = self.app.defaults['units'].upper()
-        self.units_found = self.app.defaults['units']
-
-        # this signal has to be connected to it's slot before the defaults are populated
-        # the decision done in the slot has to override the default value set bellow
-        self.ui.toolchange_cb.toggled.connect(self.on_toolchange_custom_clicked)
-
-        self.form_fields.update({
-            "plot": self.ui.plot_cb,
-            "tooldia": self.ui.tooldia_entry,
-            "append": self.ui.append_text,
-            "prepend": self.ui.prepend_text,
-            "toolchange_macro": self.ui.toolchange_text,
-            "toolchange_macro_enable": self.ui.toolchange_cb
-        })
-
-        # Fill form fields only on object create
-        self.to_form()
-
-        # this means that the object that created this CNCJob was an Excellon or Geometry
-        try:
-            if self.travel_distance:
-                self.ui.t_distance_label.show()
-                self.ui.t_distance_entry.setVisible(True)
-                self.ui.t_distance_entry.setDisabled(True)
-                self.ui.t_distance_entry.set_value('%.*f' % (self.decimals, float(self.travel_distance)))
-                self.ui.units_label.setText(str(self.units).lower())
-                self.ui.units_label.setDisabled(True)
-
-                self.ui.t_time_label.show()
-                self.ui.t_time_entry.setVisible(True)
-                self.ui.t_time_entry.setDisabled(True)
-                # if time is more than 1 then we have minutes, else we have seconds
-                if self.routing_time > 1:
-                    self.ui.t_time_entry.set_value('%.*f' % (self.decimals, math.ceil(float(self.routing_time))))
-                    self.ui.units_time_label.setText('min')
-                else:
-                    time_r = self.routing_time * 60
-                    self.ui.t_time_entry.set_value('%.*f' % (self.decimals, math.ceil(float(time_r))))
-                    self.ui.units_time_label.setText('sec')
-                self.ui.units_time_label.setDisabled(True)
-        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"])
-
-        try:
-            self.ui.annotation_cb.stateChanged.disconnect(self.on_annotation_change)
-        except (TypeError, AttributeError):
-            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(_(
-                '<span style="color:green;"><b>Basic</b></span>'
-            ))
-
-            self.ui.cnc_frame.hide()
-        else:
-            self.ui.level.setText(_(
-                '<span style="color:red;"><b>Advanced</b></span>'
-            ))
-            self.ui.cnc_frame.show()
-
-        self.ui.updateplot_button.clicked.connect(self.on_updateplot_button_click)
-        self.ui.export_gcode_button.clicked.connect(self.on_exportgcode_button_click)
-        self.ui.modify_gcode_button.clicked.connect(self.on_edit_code_click)
-
-        self.ui.tc_variable_combo.currentIndexChanged[str].connect(self.on_cnc_custom_parameters)
-
-        self.ui.cncplot_method_combo.activated_custom.connect(self.on_plot_kind_change)
-
-    def on_cnc_custom_parameters(self, signal_text):
-        if signal_text == 'Parameters':
-            return
-        else:
-            self.ui.toolchange_text.insertPlainText('%%%s%%' % signal_text)
-
-    def ui_connect(self):
-        for row in range(self.ui.cnc_tools_table.rowCount()):
-            self.ui.cnc_tools_table.cellWidget(row, 6).clicked.connect(self.on_plot_cb_click_table)
-        self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
-
-    def ui_disconnect(self):
-        for row in range(self.ui.cnc_tools_table.rowCount()):
-            self.ui.cnc_tools_table.cellWidget(row, 6).clicked.disconnect(self.on_plot_cb_click_table)
-        try:
-            self.ui.plot_cb.stateChanged.disconnect(self.on_plot_cb_click)
-        except (TypeError, AttributeError):
-            pass
-
-    def on_updateplot_button_click(self, *args):
-        """
-        Callback for the "Updata Plot" button. Reads the form for updates
-        and plots the object.
-        """
-        self.read_form()
-        self.on_plot_kind_change()
-
-    def on_plot_kind_change(self):
-        kind = self.ui.cncplot_method_combo.get_value()
-
-        def worker_task():
-            with self.app.proc_container.new(_("Plotting...")):
-                self.plot(kind=kind)
-
-        self.app.worker_task.emit({'fcn': worker_task, 'params': []})
-
-    def on_exportgcode_button_click(self, *args):
-        """
-        Handler activated by a button clicked when exporting GCode.
-
-        :param args:
-        :return:
-        """
-        self.app.report_usage("cncjob_on_exportgcode_button")
-
-        self.read_form()
-        name = self.app.collection.get_active().options['name']
-        save_gcode = False
-
-        if 'Roland' in self.pp_excellon_name or 'Roland' in self.pp_geometry_name:
-            _filter_ = "RML1 Files .rol (*.rol);;All Files (*.*)"
-        elif 'hpgl' in self.pp_geometry_name:
-            _filter_ = "HPGL Files .plt (*.plt);;All Files (*.*)"
-        else:
-            save_gcode = True
-            _filter_ = self.app.defaults['cncjob_save_filters']
-
-        try:
-            dir_file_to_save = self.app.get_last_save_folder() + '/' + str(name)
-            filename, _f = FCFileSaveDialog.get_saved_filename(
-                caption=_("Export Machine Code ..."),
-                directory=dir_file_to_save,
-                filter=_filter_
-            )
-        except TypeError:
-            filename, _f = FCFileSaveDialog.get_saved_filename(caption=_("Export Machine Code ..."), filter=_filter_)
-
-        filename = str(filename)
-
-        if filename == '':
-            self.app.inform.emit('[WARNING_NOTCL] %s' % _("Export Machine Code cancelled ..."))
-            return
-        else:
-            if save_gcode is True:
-                used_extension = filename.rpartition('.')[2]
-                self.update_filters(last_ext=used_extension, filter_string='cncjob_save_filters')
-
-        new_name = os.path.split(str(filename))[1].rpartition('.')[0]
-        self.ui.name_entry.set_value(new_name)
-        self.on_name_activate(silent=True)
-
-        preamble = str(self.ui.prepend_text.get_value())
-        postamble = str(self.ui.append_text.get_value())
-
-        gc = self.export_gcode(filename, preamble=preamble, postamble=postamble)
-        if gc == 'fail':
-            return
-
-        if self.app.defaults["global_open_style"] is False:
-            self.app.file_opened.emit("gcode", filename)
-        self.app.file_saved.emit("gcode", filename)
-        self.app.inform.emit('[success] %s: %s' % (_("Machine Code file saved to"), filename))
-
-    def on_edit_code_click(self, *args):
-        """
-        Handler activated by a button clicked when editing GCode.
-
-        :param args:
-        :return:
-        """
-
-        self.app.proc_container.view.set_busy(_("Loading..."))
-
-        preamble = str(self.ui.prepend_text.get_value())
-        postamble = str(self.ui.append_text.get_value())
-
-        gco = self.export_gcode(preamble=preamble, postamble=postamble, to_file=True)
-        if gco == 'fail':
-            return
-        else:
-            self.app.gcode_edited = gco
-
-        self.gcode_editor_tab = TextEditor(app=self.app, plain_text=True)
-
-        # add the tab if it was closed
-        self.app.ui.plot_tab_area.addTab(self.gcode_editor_tab, '%s' % _("Code Editor"))
-        self.gcode_editor_tab.setObjectName('code_editor_tab')
-
-        # delete the absolute and relative position and messages in the infobar
-        self.app.ui.position_label.setText("")
-        self.app.ui.rel_position_label.setText("")
-
-        # first clear previous text in text editor (if any)
-        self.gcode_editor_tab.code_editor.clear()
-        self.gcode_editor_tab.code_editor.setReadOnly(False)
-
-        self.gcode_editor_tab.code_editor.completer_enable = False
-        self.gcode_editor_tab.buttonRun.hide()
-
-        # Switch plot_area to CNCJob tab
-        self.app.ui.plot_tab_area.setCurrentWidget(self.gcode_editor_tab)
-
-        self.gcode_editor_tab.t_frame.hide()
-        # then append the text from GCode to the text editor
-        try:
-            self.gcode_editor_tab.code_editor.setPlainText(self.app.gcode_edited.getvalue())
-            # for line in self.app.gcode_edited:
-            #     QtWidgets.QApplication.processEvents()
-            #
-            #     proc_line = str(line).strip('\n')
-            #     self.gcode_editor_tab.code_editor.append(proc_line)
-        except Exception as e:
-            log.debug('FlatCAMCNNJob.on_edit_code_click() -->%s' % str(e))
-            self.app.inform.emit('[ERROR] %s %s' % ('FlatCAMCNNJob.on_edit_code_click() -->', str(e)))
-            return
-
-        self.gcode_editor_tab.code_editor.moveCursor(QtGui.QTextCursor.Start)
-
-        self.gcode_editor_tab.handleTextChanged()
-        self.gcode_editor_tab.t_frame.show()
-        self.app.proc_container.view.set_idle()
-
-        self.app.inform.emit('[success] %s...' % _('Loaded Machine Code into Code Editor'))
-
-    def gcode_header(self, comment_start_symbol=None, comment_stop_symbol=None):
-        """
-        Will create a header to be added to all GCode files generated by FlatCAM
-
-        :param comment_start_symbol:    A symbol to be used as the first symbol in a comment
-        :param comment_stop_symbol:     A symbol to be used as the last symbol in a comment
-        :return:                        A string with a GCode header
-        """
-
-        log.debug("FlatCAMCNCJob.gcode_header()")
-        time_str = "{:%A, %d %B %Y at %H:%M}".format(datetime.now())
-        marlin = False
-        hpgl = False
-        probe_pp = False
-
-        start_comment = comment_start_symbol if comment_start_symbol is not None else '('
-        stop_comment = comment_stop_symbol if comment_stop_symbol is not None else ')'
-
-        try:
-            for key in self.cnc_tools:
-                ppg = self.cnc_tools[key]['data']['ppname_g']
-                if 'marlin' in ppg.lower() or 'repetier' in ppg.lower():
-                    marlin = True
-                    break
-                if ppg == 'hpgl':
-                    hpgl = True
-                    break
-                if "toolchange_probe" in ppg.lower():
-                    probe_pp = True
-                    break
-        except KeyError:
-            # log.debug("FlatCAMCNCJob.gcode_header() error: --> %s" % str(e))
-            pass
-
-        try:
-            if 'marlin' in self.options['ppname_e'].lower() or 'repetier' in self.options['ppname_e'].lower():
-                marlin = True
-        except KeyError:
-            # log.debug("FlatCAMCNCJob.gcode_header(): --> There is no such self.option: %s" % str(e))
-            pass
-
-        try:
-            if "toolchange_probe" in self.options['ppname_e'].lower():
-                probe_pp = True
-        except KeyError:
-            # log.debug("FlatCAMCNCJob.gcode_header(): --> There is no such self.option: %s" % str(e))
-            pass
-
-        if marlin is True:
-            gcode = ';Marlin(Repetier) G-CODE GENERATED BY FLATCAM v%s - www.flatcam.org - Version Date:    %s\n' % \
-                    (str(self.app.version), str(self.app.version_date)) + '\n'
-
-            gcode += ';Name: ' + str(self.options['name']) + '\n'
-            gcode += ';Type: ' + "G-code from " + str(self.options['type']) + '\n'
-
-            # if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
-            #     gcode += '(Tools in use: ' + str(p['options']['Tools_in_use']) + ')\n'
-
-            gcode += ';Units: ' + self.units.upper() + '\n' + "\n"
-            gcode += ';Created on ' + time_str + '\n' + '\n'
-        elif hpgl is True:
-            gcode = 'CO "HPGL CODE GENERATED BY FLATCAM v%s - www.flatcam.org - Version Date:    %s' % \
-                    (str(self.app.version), str(self.app.version_date)) + '";\n'
-
-            gcode += 'CO "Name: ' + str(self.options['name']) + '";\n'
-            gcode += 'CO "Type: ' + "HPGL code from " + str(self.options['type']) + '";\n'
-
-            # if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
-            #     gcode += '(Tools in use: ' + str(p['options']['Tools_in_use']) + ')\n'
-
-            gcode += 'CO "Units: ' + self.units.upper() + '";\n'
-            gcode += 'CO "Created on ' + time_str + '";\n'
-        elif probe_pp is True:
-            gcode = '(G-CODE GENERATED BY FLATCAM v%s - www.flatcam.org - Version Date: %s)\n' % \
-                    (str(self.app.version), str(self.app.version_date)) + '\n'
-
-            gcode += '(This GCode tool change is done by using a Probe.)\n' \
-                     '(Make sure that before you start the job you first do a rough zero for Z axis.)\n' \
-                     '(This means that you need to zero the CNC axis and then jog to the toolchange X, Y location,)\n' \
-                     '(mount the probe and adjust the Z so more or less the probe tip touch the plate. ' \
-                     'Then zero the Z axis.)\n' + '\n'
-
-            gcode += '(Name: ' + str(self.options['name']) + ')\n'
-            gcode += '(Type: ' + "G-code from " + str(self.options['type']) + ')\n'
-
-            # if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
-            #     gcode += '(Tools in use: ' + str(p['options']['Tools_in_use']) + ')\n'
-
-            gcode += '(Units: ' + self.units.upper() + ')\n' + "\n"
-            gcode += '(Created on ' + time_str + ')\n' + '\n'
-        else:
-            gcode = '%sG-CODE GENERATED BY FLATCAM v%s - www.flatcam.org - Version Date: %s%s\n' % \
-                    (start_comment, str(self.app.version), str(self.app.version_date), stop_comment) + '\n'
-
-            gcode += '%sName: ' % start_comment + str(self.options['name']) + '%s\n' % stop_comment
-            gcode += '%sType: ' % start_comment + "G-code from " + str(self.options['type']) + '%s\n' % stop_comment
-
-            # if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
-            #     gcode += '(Tools in use: ' + str(p['options']['Tools_in_use']) + ')\n'
-
-            gcode += '%sUnits: ' % start_comment + self.units.upper() + '%s\n' % stop_comment + "\n"
-            gcode += '%sCreated on ' % start_comment + time_str + '%s\n' % stop_comment + '\n'
-
-        return gcode
-
-    def gcode_footer(self, end_command=None):
-        """
-        Will add the M02 to the end of GCode, if requested.
-
-        :param end_command: 'M02' or 'M30' - String
-        :return:
-        """
-        if end_command:
-            return end_command
-        else:
-            return 'M02'
-
-    def export_gcode(self, filename=None, preamble='', postamble='', to_file=False):
-        """
-        This will save the GCode from the Gcode object to a file on the OS filesystem
-
-        :param filename:    filename for the GCode file
-        :param preamble:    a custom Gcode block to be added at the beginning of the Gcode file
-        :param postamble:   a custom Gcode block to be added at the end of the Gcode file
-        :param to_file:     if False then no actual file is saved but the app will know that a file was created
-        :return:            None
-        """
-        # gcode = ''
-        # roland = False
-        # hpgl = False
-        # isel_icp = False
-
-        include_header = True
-
-        try:
-            if self.special_group:
-                self.app.inform.emit('[WARNING_NOTCL] %s %s %s.' %
-                                     (_("This CNCJob object can't be processed because it is a"),
-                                      str(self.special_group),
-                                      _("CNCJob object")))
-                return 'fail'
-        except AttributeError:
-            pass
-
-        # if this dict is not empty then the object is a Geometry object
-        if self.cnc_tools:
-            first_key = next(iter(self.cnc_tools))
-            include_header = self.app.preprocessors[self.cnc_tools[first_key]['data']['ppname_g']].include_header
-
-        # if this dict is not empty then the object is an Excellon object
-        if self.exc_cnc_tools:
-            first_key = next(iter(self.exc_cnc_tools))
-            include_header = self.app.preprocessors[self.exc_cnc_tools[first_key]['data']['ppname_e']].include_header
-
-        # # detect if using Roland preprocessor
-        # try:
-        #     for key in self.cnc_tools:
-        #         if self.cnc_tools[key]['data']['ppname_g'] == 'Roland_MDX_20':
-        #             roland = True
-        #             break
-        # except Exception:
-        #     try:
-        #         for key in self.cnc_tools:
-        #             if self.cnc_tools[key]['data']['ppname_e'] == 'Roland_MDX_20':
-        #                 roland = True
-        #                 break
-        #     except Exception:
-        #         pass
-        #
-        # # detect if using HPGL preprocessor
-        # try:
-        #     for key in self.cnc_tools:
-        #         if self.cnc_tools[key]['data']['ppname_g'] == 'hpgl':
-        #             hpgl = True
-        #             break
-        # except Exception:
-        #     try:
-        #         for key in self.cnc_tools:
-        #             if self.cnc_tools[key]['data']['ppname_e'] == 'hpgl':
-        #                 hpgl = True
-        #                 break
-        #     except Exception:
-        #         pass
-        #
-        # # detect if using ISEL_ICP_CNC preprocessor
-        # try:
-        #     for key in self.cnc_tools:
-        #         if 'ISEL_ICP' in self.cnc_tools[key]['data']['ppname_g'].upper():
-        #             isel_icp = True
-        #             break
-        # except Exception:
-        #     try:
-        #         for key in self.cnc_tools:
-        #             if 'ISEL_ICP' in self.cnc_tools[key]['data']['ppname_e'].upper():
-        #                 isel_icp = True
-        #                 break
-        #     except Exception:
-        #         pass
-
-        # do not add gcode_header when using the Roland preprocessor, add it for every other preprocessor
-        # if roland is False and hpgl is False and isel_icp is False:
-        #     gcode = self.gcode_header()
-
-        # do not add gcode_header when using the Roland, HPGL or ISEP_ICP_CNC preprocessor (or any other preprocessor
-        # that has the include_header attribute set as False, add it for every other preprocessor
-        # if include_header:
-        #     gcode = self.gcode_header()
-        # else:
-        #     gcode = ''
-
-        # # detect if using multi-tool and make the Gcode summation correctly for each case
-        # if self.multitool is True:
-        #     for tooluid_key in self.cnc_tools:
-        #         for key, value in self.cnc_tools[tooluid_key].items():
-        #             if key == 'gcode':
-        #                 gcode += value
-        #                 break
-        # else:
-        #     gcode += self.gcode
-
-        # if roland is True:
-        #     g = preamble + gcode + postamble
-        # elif hpgl is True:
-        #     g = self.gcode_header() + preamble + gcode + postamble
-        # else:
-        #     # fix so the preamble gets inserted in between the comments header and the actual start of GCODE
-        #     g_idx = gcode.rfind('G20')
-        #
-        #     # if it did not find 'G20' then search for 'G21'
-        #     if g_idx == -1:
-        #         g_idx = gcode.rfind('G21')
-        #
-        #     # if it did not find 'G20' and it did not find 'G21' then there is an error and return
-        #     # but only when the preprocessor is not ISEL_ICP who is allowed not to have the G20/G21 command
-        #     if g_idx == -1 and isel_icp is False:
-        #         self.app.inform.emit('[ERROR_NOTCL] %s' % _("G-code does not have a units code: either G20 or G21"))
-        #         return
-        #
-        #     footer = self.app.defaults['cncjob_footer']
-        #     end_gcode = self.gcode_footer() if footer is True else ''
-        #     g = gcode[:g_idx] + preamble + '\n' + gcode[g_idx:] + postamble + end_gcode
-
-        gcode = ''
-        if include_header is False:
-            g = preamble
-            # detect if using multi-tool and make the Gcode summation correctly for each case
-            if self.multitool is True:
-                for tooluid_key in self.cnc_tools:
-                    for key, value in self.cnc_tools[tooluid_key].items():
-                        if key == 'gcode':
-                            gcode += value
-                            break
-            else:
-                gcode += self.gcode
-
-            g = g + gcode + postamble
-        else:
-            # search for the GCode beginning which is usually a G20 or G21
-            # fix so the preamble gets inserted in between the comments header and the actual start of GCODE
-            # g_idx = gcode.rfind('G20')
-            #
-            # # if it did not find 'G20' then search for 'G21'
-            # if g_idx == -1:
-            #     g_idx = gcode.rfind('G21')
-            #
-            # # if it did not find 'G20' and it did not find 'G21' then there is an error and return
-            # if g_idx == -1:
-            #     self.app.inform.emit('[ERROR_NOTCL] %s' % _("G-code does not have a units code: either G20 or G21"))
-            #     return
-
-            # detect if using multi-tool and make the Gcode summation correctly for each case
-            if self.multitool is True:
-                for tooluid_key in self.cnc_tools:
-                    for key, value in self.cnc_tools[tooluid_key].items():
-                        if key == 'gcode':
-                            gcode += value
-                            break
-            else:
-                gcode += self.gcode
-
-            end_gcode = self.gcode_footer() if self.app.defaults['cncjob_footer'] is True else ''
-
-            # detect if using a HPGL preprocessor
-            hpgl = False
-            if self.cnc_tools:
-                for key in self.cnc_tools:
-                    if 'ppname_g' in self.cnc_tools[key]['data']:
-                        if 'hpgl' in self.cnc_tools[key]['data']['ppname_g']:
-                            hpgl = True
-                            break
-            elif self.exc_cnc_tools:
-                for key in self.cnc_tools:
-                    if 'ppname_e' in self.cnc_tools[key]['data']:
-                        if 'hpgl' in self.cnc_tools[key]['data']['ppname_e']:
-                            hpgl = True
-                            break
-
-            if hpgl:
-                processed_gcode = ''
-                pa_re = re.compile(r"^PA\s*(-?\d+\.\d*),?\s*(-?\d+\.\d*)*;?$")
-                for gline in gcode.splitlines():
-                    match = pa_re.search(gline)
-                    if match:
-                        x_int = int(float(match.group(1)))
-                        y_int = int(float(match.group(2)))
-                        new_line = 'PA%d,%d;\n' % (x_int, y_int)
-                        processed_gcode += new_line
-                    else:
-                        processed_gcode += gline + '\n'
-
-                gcode = processed_gcode
-                g = self.gcode_header() + '\n' + preamble + '\n' + gcode + postamble + end_gcode
-            else:
-                try:
-                    g_idx = gcode.index('G94')
-                    g = self.gcode_header() + gcode[:g_idx + 3] + '\n\n' + preamble + '\n' + \
-                        gcode[(g_idx + 3):] + postamble + end_gcode
-                except ValueError:
-                    self.app.inform.emit('[ERROR_NOTCL] %s' %
-                                         _("G-code does not have a G94 code and we will not include the code in the "
-                                           "'Prepend to GCode' text box"))
-                    g = self.gcode_header() + '\n' + gcode + postamble + end_gcode
-
-        # if toolchange custom is used, replace M6 code with the code from the Toolchange Custom Text box
-        if self.ui.toolchange_cb.get_value() is True:
-            # match = self.re_toolchange.search(g)
-            if 'M6' in g:
-                m6_code = self.parse_custom_toolchange_code(self.ui.toolchange_text.get_value())
-                if m6_code is None or m6_code == '':
-                    self.app.inform.emit(
-                        '[ERROR_NOTCL] %s' % _("Cancelled. The Toolchange Custom code is enabled but it's empty.")
-                    )
-                    return 'fail'
-
-                g = g.replace('M6', m6_code)
-                self.app.inform.emit('[success] %s' % _("Toolchange G-code was replaced by a custom code."))
-
-        lines = StringIO(g)
-
-        # Write
-        if filename is not None:
-            try:
-                force_windows_line_endings = self.app.defaults['cncjob_line_ending']
-                if force_windows_line_endings and sys.platform != 'win32':
-                    with open(filename, 'w', newline='\r\n') as f:
-                        for line in lines:
-                            f.write(line)
-                else:
-                    with open(filename, 'w') as f:
-                        for line in lines:
-                            f.write(line)
-            except FileNotFoundError:
-                self.app.inform.emit('[WARNING_NOTCL] %s' % _("No such file or directory"))
-                return
-            except PermissionError:
-                self.app.inform.emit(
-                    '[WARNING] %s' % _("Permission denied, saving not possible.\n"
-                                       "Most likely another app is holding the file open and not accessible.")
-                )
-                return 'fail'
-        elif to_file is False:
-            # Just for adding it to the recent files list.
-            if self.app.defaults["global_open_style"] is False:
-                self.app.file_opened.emit("cncjob", filename)
-            self.app.file_saved.emit("cncjob", filename)
-
-            self.app.inform.emit('[success] %s: %s' % (_("Saved to"), filename))
-        else:
-            return lines
-
-    def on_toolchange_custom_clicked(self, signal):
-        """
-        Handler for clicking toolchange custom.
-
-        :param signal:
-        :return:
-        """
-
-        try:
-            if 'toolchange_custom' not in str(self.options['ppname_e']).lower():
-                if self.ui.toolchange_cb.get_value():
-                    self.ui.toolchange_cb.set_value(False)
-                    self.app.inform.emit('[WARNING_NOTCL] %s' %
-                                         _("The used preprocessor file has to have in it's name: 'toolchange_custom'"))
-        except KeyError:
-            try:
-                for key in self.cnc_tools:
-                    ppg = self.cnc_tools[key]['data']['ppname_g']
-                    if 'toolchange_custom' not in str(ppg).lower():
-                        print(ppg)
-                        if self.ui.toolchange_cb.get_value():
-                            self.ui.toolchange_cb.set_value(False)
-                            self.app.inform.emit('[WARNING_NOTCL] %s' %
-                                                 _("The used preprocessor file has to have in it's name: "
-                                                   "'toolchange_custom'"))
-            except KeyError:
-                self.app.inform.emit('[ERROR] %s' % _("There is no preprocessor file."))
-
-    def get_gcode(self, preamble='', postamble=''):
-        """
-        We need this to be able to get_gcode separately for shell command export_gcode
-
-        :param preamble:    Extra GCode added to the beginning of the GCode
-        :param postamble:   Extra GCode added at the end of the GCode
-        :return:            The modified GCode
-        """
-        return preamble + '\n' + self.gcode + "\n" + postamble
-
-    def get_svg(self):
-        # we need this to be able get_svg separately for shell command export_svg
-        pass
-
-    def on_plot_cb_click(self, *args):
-        """
-        Handler for clicking on the Plot checkbox.
-
-        :param args:
-        :return:
-        """
-        if self.muted_ui:
-            return
-        kind = self.ui.cncplot_method_combo.get_value()
-        self.plot(kind=kind)
-        self.read_form_item('plot')
-
-        self.ui_disconnect()
-        cb_flag = self.ui.plot_cb.isChecked()
-        for row in range(self.ui.cnc_tools_table.rowCount()):
-            table_cb = self.ui.cnc_tools_table.cellWidget(row, 6)
-            if cb_flag:
-                table_cb.setChecked(True)
-            else:
-                table_cb.setChecked(False)
-        self.ui_connect()
-
-    def on_plot_cb_click_table(self):
-        """
-        Handler for clicking the plot checkboxes added into a Table on each row. Purpose: toggle visibility for the
-        tool/aperture found on that row.
-        :return:
-        """
-
-        # self.ui.cnc_tools_table.cellWidget(row, 2).widget().setCheckState(QtCore.Qt.Unchecked)
-        self.ui_disconnect()
-        # cw = self.sender()
-        # cw_index = self.ui.cnc_tools_table.indexAt(cw.pos())
-        # cw_row = cw_index.row()
-
-        kind = self.ui.cncplot_method_combo.get_value()
-
-        self.shapes.clear(update=True)
-
-        for tooluid_key in self.cnc_tools:
-            tooldia = float('%.*f' % (self.decimals, float(self.cnc_tools[tooluid_key]['tooldia'])))
-            gcode_parsed = self.cnc_tools[tooluid_key]['gcode_parsed']
-            # tool_uid = int(self.ui.cnc_tools_table.item(cw_row, 3).text())
-
-            for r in range(self.ui.cnc_tools_table.rowCount()):
-                if int(self.ui.cnc_tools_table.item(r, 5).text()) == int(tooluid_key):
-                    if self.ui.cnc_tools_table.cellWidget(r, 6).isChecked():
-                        self.plot2(tooldia=tooldia, obj=self, visible=True, gcode_parsed=gcode_parsed, kind=kind)
-
-        self.shapes.redraw()
-
-        # make sure that the general plot is disabled if one of the row plot's are disabled and
-        # if all the row plot's are enabled also enable the general plot checkbox
-        cb_cnt = 0
-        total_row = self.ui.cnc_tools_table.rowCount()
-        for row in range(total_row):
-            if self.ui.cnc_tools_table.cellWidget(row, 6).isChecked():
-                cb_cnt += 1
-            else:
-                cb_cnt -= 1
-        if cb_cnt < total_row:
-            self.ui.plot_cb.setChecked(False)
-        else:
-            self.ui.plot_cb.setChecked(True)
-        self.ui_connect()
-
-    def plot(self, visible=None, kind='all'):
-        """
-        # Does all the required setup and returns False
-        # if the 'ptint' option is set to False.
-
-        :param visible: Boolean to decide if the object will be plotted as visible or disabled on canvas
-        :param kind:    String. Can be "all" or "travel" or "cut". For CNCJob plotting
-        :return:        None
-        """
-        if not FlatCAMObj.plot(self):
-            return
-
-        visible = visible if visible else self.options['plot']
-
-        if self.app.is_legacy is False:
-            if self.ui.annotation_cb.get_value() and self.ui.plot_cb.get_value():
-                self.text_col.enabled = True
-            else:
-                self.text_col.enabled = False
-            self.annotation.redraw()
-
-        try:
-            if self.multitool is False:  # single tool usage
-                try:
-                    dia_plot = float(self.options["tooldia"])
-                except ValueError:
-                    # we may have a tuple with only one element and a comma
-                    dia_plot = [float(el) for el in self.options["tooldia"].split(',') if el != ''][0]
-                self.plot2(dia_plot, obj=self, visible=visible, kind=kind)
-            else:
-                # multiple tools usage
-                if self.cnc_tools:
-                    for tooluid_key in self.cnc_tools:
-                        tooldia = float('%.*f' % (self.decimals, float(self.cnc_tools[tooluid_key]['tooldia'])))
-                        gcode_parsed = self.cnc_tools[tooluid_key]['gcode_parsed']
-                        self.plot2(tooldia=tooldia, obj=self, visible=visible, gcode_parsed=gcode_parsed, kind=kind)
-
-                # TODO: until the gcode parsed will be stored on each Excellon tool this will not get executed
-                if self.exc_cnc_tools:
-                    for tooldia_key in self.exc_cnc_tools:
-                        tooldia = float('%.*f' % (self.decimals, float(tooldia_key)))
-                        # gcode_parsed = self.cnc_tools[tooldia_key]['gcode_parsed']
-                        gcode_parsed = self.gcode_parsed
-                        self.plot2(tooldia=tooldia, obj=self, visible=visible, gcode_parsed=gcode_parsed, kind=kind)
-
-            self.shapes.redraw()
-        except (ObjectDeleted, AttributeError):
-            self.shapes.clear(update=True)
-            if self.app.is_legacy is False:
-                self.annotation.clear(update=True)
-
-    def on_annotation_change(self):
-        """
-        Handler for toggling the annotation display by clicking a checkbox.
-        :return:
-        """
-
-        if self.app.is_legacy is False:
-            if self.ui.annotation_cb.get_value():
-                self.text_col.enabled = True
-            else:
-                self.text_col.enabled = False
-            # kind = self.ui.cncplot_method_combo.get_value()
-            # self.plot(kind=kind)
-            self.annotation.redraw()
-        else:
-            kind = self.ui.cncplot_method_combo.get_value()
-            self.plot(kind=kind)
-
-    def convert_units(self, units):
-        """
-        Units conversion used by the CNCJob objects.
-
-        :param units:   Can be "MM" or "IN"
-        :return:
-        """
-
-        log.debug("FlatCAMObj.FlatCAMECNCjob.convert_units()")
-
-        factor = CNCjob.convert_units(self, units)
-        self.options["tooldia"] = float(self.options["tooldia"]) * factor
-
-        param_list = ['cutz', 'depthperpass', 'travelz', 'feedrate', 'feedrate_z', 'feedrate_rapid',
-                      'endz', 'toolchangez']
-
-        temp_tools_dict = {}
-        tool_dia_copy = {}
-        data_copy = {}
-
-        for tooluid_key, tooluid_value in self.cnc_tools.items():
-            for dia_key, dia_value in tooluid_value.items():
-                if dia_key == 'tooldia':
-                    dia_value *= factor
-                    dia_value = float('%.*f' % (self.decimals, dia_value))
-                    tool_dia_copy[dia_key] = dia_value
-                if dia_key == 'offset':
-                    tool_dia_copy[dia_key] = dia_value
-                if dia_key == 'offset_value':
-                    dia_value *= factor
-                    tool_dia_copy[dia_key] = dia_value
-
-                if dia_key == 'type':
-                    tool_dia_copy[dia_key] = dia_value
-                if dia_key == 'tool_type':
-                    tool_dia_copy[dia_key] = dia_value
-                if dia_key == 'data':
-                    for data_key, data_value in dia_value.items():
-                        # convert the form fields that are convertible
-                        for param in param_list:
-                            if data_key == param and data_value is not None:
-                                data_copy[data_key] = data_value * factor
-                        # copy the other dict entries that are not convertible
-                        if data_key not in param_list:
-                            data_copy[data_key] = data_value
-                    tool_dia_copy[dia_key] = deepcopy(data_copy)
-                    data_copy.clear()
-
-                if dia_key == 'gcode':
-                    tool_dia_copy[dia_key] = dia_value
-                if dia_key == 'gcode_parsed':
-                    tool_dia_copy[dia_key] = dia_value
-                if dia_key == 'solid_geometry':
-                    tool_dia_copy[dia_key] = dia_value
-
-                # if dia_key == 'solid_geometry':
-                #     tool_dia_copy[dia_key] = affinity.scale(dia_value, xfact=factor, origin=(0, 0))
-                # if dia_key == 'gcode_parsed':
-                #     for g in dia_value:
-                #         g['geom'] = affinity.scale(g['geom'], factor, factor, origin=(0, 0))
-                #
-                #     tool_dia_copy['gcode_parsed'] = deepcopy(dia_value)
-                #     tool_dia_copy['solid_geometry'] = cascaded_union([geo['geom'] for geo in dia_value])
-
-            temp_tools_dict.update({
-                tooluid_key: deepcopy(tool_dia_copy)
-            })
-            tool_dia_copy.clear()
-
-        self.cnc_tools.clear()
-        self.cnc_tools = deepcopy(temp_tools_dict)
-
-
-class FlatCAMScript(FlatCAMObj):
-    """
-    Represents a TCL script object.
-    """
-    optionChanged = QtCore.pyqtSignal(str)
-    ui_type = ScriptObjectUI
-
-    def __init__(self, name):
-        self.decimals = self.app.decimals
-
-        log.debug("Creating a FlatCAMScript object...")
-        FlatCAMObj.__init__(self, name)
-
-        self.kind = "script"
-
-        self.options.update({
-            "plot": True,
-            "type": 'Script',
-            "source_file": '',
-        })
-
-        self.units = ''
-
-        self.ser_attrs = ['options', 'kind', 'source_file']
-        self.source_file = ''
-        self.script_code = ''
-
-        self.units_found = self.app.defaults['units']
-
-        # self.script_editor_tab = TextEditor(app=self.app, plain_text=True)
-        self.script_editor_tab = TextEditor(app=self.app, plain_text=True)
-
-    def set_ui(self, ui):
-        """
-        Sets the Object UI in Selected Tab for the FlatCAM Script type of object.
-        :param ui:
-        :return:
-        """
-        FlatCAMObj.set_ui(self, ui)
-        log.debug("FlatCAMScript.set_ui()")
-
-        assert isinstance(self.ui, ScriptObjectUI), \
-            "Expected a ScriptObjectUI, got %s" % type(self.ui)
-
-        self.units = self.app.defaults['units'].upper()
-        self.units_found = self.app.defaults['units']
-
-        # Fill form fields only on object create
-        self.to_form()
-
-        # Show/Hide Advanced Options
-        if self.app.defaults["global_app_level"] == 'b':
-            self.ui.level.setText(_(
-                '<span style="color:green;"><b>Basic</b></span>'
-            ))
-        else:
-            self.ui.level.setText(_(
-                '<span style="color:red;"><b>Advanced</b></span>'
-            ))
-
-        # tab_here = False
-        # # try to not add too many times a tab that it is already installed
-        # for idx in range(self.app.ui.plot_tab_area.count()):
-        #     if self.app.ui.plot_tab_area.widget(idx).objectName() == self.options['name']:
-        #         tab_here = True
-        #         break
-        #
-        # # add the tab if it is not already added
-        # if tab_here is False:
-        #     self.app.ui.plot_tab_area.addTab(self.script_editor_tab, '%s' % _("Script Editor"))
-        #     self.script_editor_tab.setObjectName(self.options['name'])
-
-        self.app.ui.plot_tab_area.addTab(self.script_editor_tab, '%s' % _("Script Editor"))
-        self.script_editor_tab.setObjectName(self.options['name'])
-
-        # first clear previous text in text editor (if any)
-        # self.script_editor_tab.code_editor.clear()
-        # self.script_editor_tab.code_editor.setReadOnly(False)
-
-        self.ui.autocomplete_cb.set_value(self.app.defaults['script_autocompleter'])
-        self.on_autocomplete_changed(state=self.app.defaults['script_autocompleter'])
-
-        self.script_editor_tab.buttonRun.show()
-
-        # Switch plot_area to CNCJob tab
-        self.app.ui.plot_tab_area.setCurrentWidget(self.script_editor_tab)
-
-        flt = "FlatCAM Scripts (*.FlatScript);;All Files (*.*)"
-        self.script_editor_tab.buttonOpen.clicked.disconnect()
-        self.script_editor_tab.buttonOpen.clicked.connect(lambda: self.script_editor_tab.handleOpen(filt=flt))
-        self.script_editor_tab.buttonSave.clicked.disconnect()
-        self.script_editor_tab.buttonSave.clicked.connect(lambda: self.script_editor_tab.handleSaveGCode(filt=flt))
-
-        self.script_editor_tab.buttonRun.clicked.connect(self.handle_run_code)
-        self.script_editor_tab.handleTextChanged()
-
-        self.ui.autocomplete_cb.stateChanged.connect(self.on_autocomplete_changed)
-
-        self.ser_attrs = ['options', 'kind', 'source_file']
-
-        # ---------------------------------------------------- #
-        # ----------- LOAD THE TEXT SOURCE FILE -------------- #
-        # ---------------------------------------------------- #
-        self.app.proc_container.view.set_busy(_("Loading..."))
-        self.script_editor_tab.t_frame.hide()
-
-        try:
-            self.script_editor_tab.code_editor.setPlainText(self.source_file)
-            # for line in self.source_file.splitlines():
-            #     QtWidgets.QApplication.processEvents()
-            #     self.script_editor_tab.code_editor.append(line)
-        except Exception as e:
-            log.debug("FlatCAMScript.set_ui() --> %s" % str(e))
-
-        self.script_editor_tab.code_editor.moveCursor(QtGui.QTextCursor.End)
-        self.script_editor_tab.t_frame.show()
-
-        self.app.proc_container.view.set_idle()
-        self.build_ui()
-
-    def build_ui(self):
-        FlatCAMObj.build_ui(self)
-
-    def handle_run_code(self):
-        # trying to run a Tcl command without having the Shell open will create some warnings because the Tcl Shell
-        # tries to print on a hidden widget, therefore show the dock if hidden
-        if self.app.ui.shell_dock.isHidden():
-            self.app.ui.shell_dock.show()
-
-        self.script_code = deepcopy(self.script_editor_tab.code_editor.toPlainText())
-
-        old_line = ''
-        for tcl_command_line in self.script_code.splitlines():
-            # do not process lines starting with '#' = comment and empty lines
-            if not tcl_command_line.startswith('#') and tcl_command_line != '':
-                # id FlatCAM is run in Windows then replace all the slashes with
-                # the UNIX style slash that TCL understands
-                if sys.platform == 'win32':
-                    if "open" in tcl_command_line:
-                        tcl_command_line = tcl_command_line.replace('\\', '/')
-
-                if old_line != '':
-                    new_command = old_line + tcl_command_line + '\n'
-                else:
-                    new_command = tcl_command_line
-
-                # execute the actual Tcl command
-                try:
-                    self.app.shell.open_processing()  # Disables input box.
-
-                    result = self.app.tcl.eval(str(new_command))
-                    if result != 'None':
-                        self.app.shell.append_output(result + '\n')
-
-                    old_line = ''
-                except tk.TclError:
-                    old_line = old_line + tcl_command_line + '\n'
-                except Exception as e:
-                    log.debug("FlatCAMScript.handleRunCode() --> %s" % str(e))
-
-        if old_line != '':
-            # it means that the script finished with an error
-            result = self.app.tcl.eval("set errorInfo")
-            log.error("Exec command Exception: %s" % (result + '\n'))
-            self.app.shell.append_error('ERROR: ' + result + '\n')
-
-        self.app.shell.close_processing()
-
-    def on_autocomplete_changed(self, state):
-        if state:
-            self.script_editor_tab.code_editor.completer_enable = True
-        else:
-            self.script_editor_tab.code_editor.completer_enable = False
-
-    def to_dict(self):
-        """
-        Returns a representation of the object as a dictionary.
-        Attributes to include are listed in ``self.ser_attrs``.
-
-        :return: A dictionary-encoded copy of the object.
-        :rtype: dict
-        """
-        d = {}
-        for attr in self.ser_attrs:
-            d[attr] = getattr(self, attr)
-        return d
-
-    def from_dict(self, d):
-        """
-        Sets object's attributes from a dictionary.
-        Attributes to include are listed in ``self.ser_attrs``.
-        This method will look only for only and all the
-        attributes in ``self.ser_attrs``. They must all
-        be present. Use only for deserializing saved
-        objects.
-
-        :param d: Dictionary of attributes to set in the object.
-        :type d: dict
-        :return: None
-        """
-        for attr in self.ser_attrs:
-            setattr(self, attr, d[attr])
-
-
-class FlatCAMDocument(FlatCAMObj):
-    """
-    Represents a Document object.
-    """
-    optionChanged = QtCore.pyqtSignal(str)
-    ui_type = DocumentObjectUI
-
-    def __init__(self, name):
-        self.decimals = self.app.decimals
-
-        log.debug("Creating a Document object...")
-        FlatCAMObj.__init__(self, name)
-
-        self.kind = "document"
-        self.units = ''
-
-        self.ser_attrs = ['options', 'kind', 'source_file']
-        self.source_file = ''
-        self.doc_code = ''
-
-        self.font_name = None
-        self.font_italic = None
-        self.font_bold = None
-        self.font_underline = None
-
-        self.document_editor_tab = None
-
-        self._read_only = False
-        self.units_found = self.app.defaults['units']
-
-    def set_ui(self, ui):
-        FlatCAMObj.set_ui(self, ui)
-        log.debug("FlatCAMDocument.set_ui()")
-
-        assert isinstance(self.ui, DocumentObjectUI), \
-            "Expected a DocumentObjectUI, got %s" % type(self.ui)
-
-        self.units = self.app.defaults['units'].upper()
-        self.units_found = self.app.defaults['units']
-
-        # Fill form fields only on object create
-        self.to_form()
-
-        # Show/Hide Advanced Options
-        if self.app.defaults["global_app_level"] == 'b':
-            self.ui.level.setText(_(
-                '<span style="color:green;"><b>Basic</b></span>'
-            ))
-        else:
-            self.ui.level.setText(_(
-                '<span style="color:red;"><b>Advanced</b></span>'
-            ))
-
-        self.document_editor_tab = TextEditor(app=self.app)
-        stylesheet = """
-                        QTextEdit {selection-background-color:%s;
-                                   selection-color:white;
-                        }
-                     """ % self.app.defaults["document_sel_color"]
-
-        self.document_editor_tab.code_editor.setStyleSheet(stylesheet)
-
-        # first clear previous text in text editor (if any)
-        self.document_editor_tab.code_editor.clear()
-        self.document_editor_tab.code_editor.setReadOnly(self._read_only)
-
-        self.document_editor_tab.buttonRun.hide()
-
-        self.ui.autocomplete_cb.set_value(self.app.defaults['document_autocompleter'])
-        self.on_autocomplete_changed(state=self.app.defaults['document_autocompleter'])
-        self.on_tab_size_change(val=self.app.defaults['document_tab_size'])
-
-        flt = "FlatCAM Docs (*.FlatDoc);;All Files (*.*)"
-
-        # ######################################################################
-        # ######################## SIGNALS #####################################
-        # ######################################################################
-        self.document_editor_tab.buttonOpen.clicked.disconnect()
-        self.document_editor_tab.buttonOpen.clicked.connect(lambda: self.document_editor_tab.handleOpen(filt=flt))
-        self.document_editor_tab.buttonSave.clicked.disconnect()
-        self.document_editor_tab.buttonSave.clicked.connect(lambda: self.document_editor_tab.handleSaveGCode(filt=flt))
-
-        self.document_editor_tab.code_editor.textChanged.connect(self.on_text_changed)
-
-        self.ui.font_type_cb.currentFontChanged.connect(self.font_family)
-        self.ui.font_size_cb.activated.connect(self.font_size)
-        self.ui.font_bold_tb.clicked.connect(self.on_bold_button)
-        self.ui.font_italic_tb.clicked.connect(self.on_italic_button)
-        self.ui.font_under_tb.clicked.connect(self.on_underline_button)
-
-        self.ui.font_color_entry.editingFinished.connect(self.on_font_color_entry)
-        self.ui.font_color_button.clicked.connect(self.on_font_color_button)
-        self.ui.sel_color_entry.editingFinished.connect(self.on_selection_color_entry)
-        self.ui.sel_color_button.clicked.connect(self.on_selection_color_button)
-
-        self.ui.al_left_tb.clicked.connect(lambda: self.document_editor_tab.code_editor.setAlignment(Qt.AlignLeft))
-        self.ui.al_center_tb.clicked.connect(lambda: self.document_editor_tab.code_editor.setAlignment(Qt.AlignCenter))
-        self.ui.al_right_tb.clicked.connect(lambda: self.document_editor_tab.code_editor.setAlignment(Qt.AlignRight))
-        self.ui.al_justify_tb.clicked.connect(
-            lambda: self.document_editor_tab.code_editor.setAlignment(Qt.AlignJustify)
-        )
-
-        self.ui.autocomplete_cb.stateChanged.connect(self.on_autocomplete_changed)
-        self.ui.tab_size_spinner.returnPressed.connect(self.on_tab_size_change)
-        # #######################################################################
-
-        self.ui.font_color_entry.set_value(self.app.defaults['document_font_color'])
-        self.ui.font_color_button.setStyleSheet(
-            "background-color:%s" % str(self.app.defaults['document_font_color']))
-
-        self.ui.sel_color_entry.set_value(self.app.defaults['document_sel_color'])
-        self.ui.sel_color_button.setStyleSheet(
-            "background-color:%s" % self.app.defaults['document_sel_color'])
-
-        self.ui.font_size_cb.setCurrentIndex(int(self.app.defaults['document_font_size']))
-
-        self.document_editor_tab.handleTextChanged()
-        self.ser_attrs = ['options', 'kind', 'source_file']
-
-        if Qt.mightBeRichText(self.source_file):
-            self.document_editor_tab.code_editor.setHtml(self.source_file)
-        else:
-            for line in self.source_file.splitlines():
-                self.document_editor_tab.code_editor.append(line)
-
-        self.build_ui()
-
-    @property
-    def read_only(self):
-        return self._read_only
-
-    @read_only.setter
-    def read_only(self, val):
-        if val:
-            self._read_only = True
-        else:
-            self._read_only = False
-
-    def build_ui(self):
-        FlatCAMObj.build_ui(self)
-        tab_here = False
-
-        # try to not add too many times a tab that it is already installed
-        for idx in range(self.app.ui.plot_tab_area.count()):
-            if self.app.ui.plot_tab_area.widget(idx).objectName() == self.options['name']:
-                tab_here = True
-                break
-
-        # add the tab if it is not already added
-        if tab_here is False:
-            self.app.ui.plot_tab_area.addTab(self.document_editor_tab, '%s' % _("Document Editor"))
-            self.document_editor_tab.setObjectName(self.options['name'])
-
-        # Switch plot_area to CNCJob tab
-        self.app.ui.plot_tab_area.setCurrentWidget(self.document_editor_tab)
-
-    def on_autocomplete_changed(self, state):
-        if state:
-            self.document_editor_tab.code_editor.completer_enable = True
-        else:
-            self.document_editor_tab.code_editor.completer_enable = False
-
-    def on_tab_size_change(self, val=None):
-        try:
-            self.ui.tab_size_spinner.returnPressed.disconnect(self.on_tab_size_change)
-        except TypeError:
-            pass
-
-        if val:
-            self.ui.tab_size_spinner.set_value(val)
-
-        tab_balue = int(self.ui.tab_size_spinner.get_value())
-        self.document_editor_tab.code_editor.setTabStopWidth(tab_balue)
-        self.app.defaults['document_tab_size'] = tab_balue
-
-        self.ui.tab_size_spinner.returnPressed.connect(self.on_tab_size_change)
-
-    def on_text_changed(self):
-        self.source_file = self.document_editor_tab.code_editor.toHtml()
-        # print(self.source_file)
-
-    def font_family(self, font):
-        # self.document_editor_tab.code_editor.selectAll()
-        font.setPointSize(float(self.ui.font_size_cb.get_value()))
-        self.document_editor_tab.code_editor.setCurrentFont(font)
-        self.font_name = self.ui.font_type_cb.currentFont().family()
-
-    def font_size(self):
-        # self.document_editor_tab.code_editor.selectAll()
-        self.document_editor_tab.code_editor.setFontPointSize(float(self.ui.font_size_cb.get_value()))
-
-    def on_bold_button(self):
-        if self.ui.font_bold_tb.isChecked():
-            self.document_editor_tab.code_editor.setFontWeight(QtGui.QFont.Bold)
-            self.font_bold = True
-        else:
-            self.document_editor_tab.code_editor.setFontWeight(QtGui.QFont.Normal)
-            self.font_bold = False
-
-    def on_italic_button(self):
-        if self.ui.font_italic_tb.isChecked():
-            self.document_editor_tab.code_editor.setFontItalic(True)
-            self.font_italic = True
-        else:
-            self.document_editor_tab.code_editor.setFontItalic(False)
-            self.font_italic = False
-
-    def on_underline_button(self):
-        if self.ui.font_under_tb.isChecked():
-            self.document_editor_tab.code_editor.setFontUnderline(True)
-            self.font_underline = True
-        else:
-            self.document_editor_tab.code_editor.setFontUnderline(False)
-            self.font_underline = False
-
-    # Setting font colors handlers
-    def on_font_color_entry(self):
-        self.app.defaults['document_font_color'] = self.ui.font_color_entry.get_value()
-        self.ui.font_color_button.setStyleSheet("background-color:%s" % str(self.app.defaults['document_font_color']))
-
-    def on_font_color_button(self):
-        current_color = QtGui.QColor(self.app.defaults['document_font_color'])
-
-        c_dialog = QtWidgets.QColorDialog()
-        font_color = c_dialog.getColor(initial=current_color)
-
-        if font_color.isValid() is False:
-            return
-
-        self.document_editor_tab.code_editor.setTextColor(font_color)
-        self.ui.font_color_button.setStyleSheet("background-color:%s" % str(font_color.name()))
-
-        new_val = str(font_color.name())
-        self.ui.font_color_entry.set_value(new_val)
-        self.app.defaults['document_font_color'] = new_val
-
-    # Setting selection colors handlers
-    def on_selection_color_entry(self):
-        self.app.defaults['document_sel_color'] = self.ui.sel_color_entry.get_value()
-        self.ui.sel_color_button.setStyleSheet("background-color:%s" % str(self.app.defaults['document_sel_color']))
-
-    def on_selection_color_button(self):
-        current_color = QtGui.QColor(self.app.defaults['document_sel_color'])
-
-        c_dialog = QtWidgets.QColorDialog()
-        sel_color = c_dialog.getColor(initial=current_color)
-
-        if sel_color.isValid() is False:
-            return
-
-        p = QtGui.QPalette()
-        p.setColor(QtGui.QPalette.Highlight, sel_color)
-        p.setColor(QtGui.QPalette.HighlightedText, QtGui.QColor('white'))
-
-        self.document_editor_tab.code_editor.setPalette(p)
-
-        self.ui.sel_color_button.setStyleSheet("background-color:%s" % str(sel_color.name()))
-
-        new_val = str(sel_color.name())
-        self.ui.sel_color_entry.set_value(new_val)
-        self.app.defaults['document_sel_color'] = new_val
-
-    def to_dict(self):
-        """
-        Returns a representation of the object as a dictionary.
-        Attributes to include are listed in ``self.ser_attrs``.
-
-        :return: A dictionary-encoded copy of the object.
-        :rtype: dict
-        """
-        d = {}
-        for attr in self.ser_attrs:
-            d[attr] = getattr(self, attr)
-        return d
-
-    def from_dict(self, d):
-        """
-        Sets object's attributes from a dictionary.
-        Attributes to include are listed in ``self.ser_attrs``.
-        This method will look only for only and all the
-        attributes in ``self.ser_attrs``. They must all
-        be present. Use only for deserializing saved
-        objects.
-
-        :param d: Dictionary of attributes to set in the object.
-        :type d: dict
-        :return: None
-        """
-        for attr in self.ser_attrs:
-            setattr(self, attr, d[attr])
-
-# end of file

+ 20 - 14
ObjectCollection.py

@@ -16,8 +16,14 @@ from PyQt5.QtCore import Qt, QSettings
 from PyQt5.QtGui import QColor
 # from PyQt5.QtCore import QModelIndex
 
-from FlatCAMObj import FlatCAMGerber, FlatCAMGeometry, FlatCAMExcellon, FlatCAMCNCjob, FlatCAMDocument, FlatCAMScript, \
-    FlatCAMObj
+from flatcamObjects.FlatCAMObj import FlatCAMObj
+from flatcamObjects.FlatCAMCNCJob import CNCJobObject
+from flatcamObjects.FlatCAMDocument import DocumentObject
+from flatcamObjects.FlatCAMExcellon import ExcellonObject
+from flatcamObjects.FlatCAMGeometry import GeometryObject
+from flatcamObjects.FlatCAMGerber import GerberObject
+from flatcamObjects.FlatCAMScript import ScriptObject
+
 import inspect  # TODO: Remove
 
 import re
@@ -233,12 +239,12 @@ class ObjectCollection(QtCore.QAbstractItemModel):
     ]
 
     classdict = {
-        "gerber": FlatCAMGerber,
-        "excellon": FlatCAMExcellon,
-        "cncjob": FlatCAMCNCjob,
-        "geometry": FlatCAMGeometry,
-        "script": FlatCAMScript,
-        "document": FlatCAMDocument
+        "gerber": GerberObject,
+        "excellon": ExcellonObject,
+        "cncjob": CNCJobObject,
+        "geometry": GeometryObject,
+        "script": ScriptObject,
+        "document": DocumentObject
     }
 
     icon_files = {
@@ -372,17 +378,17 @@ class ObjectCollection(QtCore.QAbstractItemModel):
             self.app.ui.menuprojectcolor.setEnabled(False)
 
             for obj in self.get_selected():
-                if type(obj) == FlatCAMGerber or type(obj) == FlatCAMExcellon:
+                if type(obj) == GerberObject or type(obj) == ExcellonObject:
                     self.app.ui.menuprojectcolor.setEnabled(True)
 
-                if type(obj) != FlatCAMGeometry:
+                if type(obj) != GeometryObject:
                     self.app.ui.menuprojectgeneratecnc.setVisible(False)
-                if type(obj) != FlatCAMGeometry and type(obj) != FlatCAMExcellon and type(obj) != FlatCAMGerber:
+                if type(obj) != GeometryObject and type(obj) != ExcellonObject and type(obj) != GerberObject:
                     self.app.ui.menuprojectedit.setVisible(False)
-                if type(obj) != FlatCAMGerber and type(obj) != FlatCAMExcellon and type(obj) != FlatCAMCNCjob:
+                if type(obj) != GerberObject and type(obj) != ExcellonObject and type(obj) != CNCJobObject:
                     self.app.ui.menuprojectviewsource.setVisible(False)
-                if type(obj) != FlatCAMGerber and type(obj) != FlatCAMGeometry and type(obj) != FlatCAMExcellon and \
-                        type(obj) != FlatCAMCNCjob:
+                if type(obj) != GerberObject and type(obj) != GeometryObject and type(obj) != ExcellonObject and \
+                        type(obj) != CNCJobObject:
                     # meaning for Scripts and for Document type of FlatCAM object
                     self.app.ui.menuprojectenable.setVisible(False)
                     self.app.ui.menuprojectdisable.setVisible(False)

+ 1 - 1
camlib.py

@@ -4318,7 +4318,7 @@ class CNCjob(Geometry):
 
         log.debug("Finishing SolderPste G-Code... %s paths traced." % path_count)
         self.app.inform.emit(
-            '%s... %s %s' % (_("Finished SolderPste G-Code generation"), str(path_count), _("paths traced."))
+            '%s... %s %s' % (_("Finished SolderPaste G-Code generation"), str(path_count), _("paths traced."))
         )
 
         # Finish

+ 2 - 2
flatcamEditors/FlatCAMExcEditor.py

@@ -3039,7 +3039,7 @@ class FlatCAMExcEditor(QtCore.QObject):
         Imports the geometry from the given FlatCAM Excellon object
         into the editor.
 
-        :param exc_obj: FlatCAMExcellon object
+        :param exc_obj: ExcellonObject object
         :return: None
         """
 
@@ -3115,7 +3115,7 @@ class FlatCAMExcEditor(QtCore.QObject):
         """
         Create a new Excellon object that contain the edited content of the source Excellon object
 
-        :param exc_obj: FlatCAMExcellon
+        :param exc_obj: ExcellonObject
         :return: None
         """
 

+ 4 - 4
flatcamEditors/FlatCAMGeoEditor.py

@@ -87,8 +87,8 @@ class BufferSelectionTool(FlatCAMTool):
         self.buffer_corner_lbl.setToolTip(
             _("There are 3 types of corners:\n"
               " - 'Round': the corner is rounded for exterior buffer.\n"
-              " - 'Square:' the corner is met in a sharp angle for exterior buffer.\n"
-              " - 'Beveled:' the corner is a line that directly connects the features meeting in the corner")
+              " - 'Square': the corner is met in a sharp angle for exterior buffer.\n"
+              " - 'Beveled': the corner is a line that directly connects the features meeting in the corner")
         )
         self.buffer_corner_cb = FCComboBox()
         self.buffer_corner_cb.addItem(_("Round"))
@@ -4035,7 +4035,7 @@ class FlatCAMGeoEditor(QtCore.QObject):
         Imports the geometry from the given FlatCAM Geometry object
         into the editor.
 
-        :param fcgeometry:      FlatCAMGeometry
+        :param fcgeometry:      GeometryObject
         :param multigeo_tool:   A tool for the case of the edited geometry being of type 'multigeo'
         :return:                None
         """
@@ -4750,7 +4750,7 @@ class FlatCAMGeoEditor(QtCore.QObject):
         Transfers the geometry tool shape buffer to the selected geometry
         object. The geometry already in the object are removed.
 
-        :param fcgeometry: FlatCAMGeometry
+        :param fcgeometry: GeometryObject
         :return: None
         """
         if self.multigeo_tool:

+ 3 - 3
flatcamEditors/FlatCAMGrbEditor.py

@@ -2621,8 +2621,8 @@ class FlatCAMGrbEditor(QtCore.QObject):
         self.buffer_corner_lbl.setToolTip(
             _("There are 3 types of corners:\n"
               " - 'Round': the corner is rounded.\n"
-              " - 'Square:' the corner is met in a sharp angle.\n"
-              " - 'Beveled:' the corner is a line that directly connects the features meeting in the corner")
+              " - 'Square': the corner is met in a sharp angle.\n"
+              " - 'Beveled': the corner is a line that directly connects the features meeting in the corner")
         )
         self.buffer_corner_cb = FCComboBox()
         self.buffer_corner_cb.addItem(_("Round"))
@@ -3833,7 +3833,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
         Imports the geometry found in self.apertures from the given FlatCAM Gerber object
         into the editor.
 
-        :param orig_grb_obj: FlatCAMExcellon
+        :param orig_grb_obj: ExcellonObject
         :return: None
         """
 

+ 1220 - 0
flatcamObjects/FlatCAMCNCJob.py

@@ -0,0 +1,1220 @@
+# ##########################################################
+# FlatCAM: 2D Post-processing for Manufacturing            #
+# http://flatcam.org                                       #
+# Author: Juan Pablo Caram (c)                             #
+# Date: 2/5/2014                                           #
+# MIT Licence                                              #
+# ##########################################################
+
+# ##########################################################
+# File modified by: Marius Stanciu                         #
+# ##########################################################
+
+from copy import deepcopy
+from io import StringIO
+from datetime import datetime
+
+from flatcamEditors.FlatCAMTextEditor import TextEditor
+from flatcamObjects.FlatCAMObj import *
+
+from camlib import CNCjob
+
+import os
+import sys
+import math
+
+import gettext
+import FlatCAMTranslation as fcTranslate
+import builtins
+
+fcTranslate.apply_language('strings')
+if '_' not in builtins.__dict__:
+    _ = gettext.gettext
+
+
+class CNCJobObject(FlatCAMObj, CNCjob):
+    """
+    Represents G-Code.
+    """
+    optionChanged = QtCore.pyqtSignal(str)
+    ui_type = CNCObjectUI
+
+    def __init__(self, name, units="in", kind="generic", z_move=0.1,
+                 feedrate=3.0, feedrate_rapid=3.0, z_cut=-0.002, tooldia=0.0,
+                 spindlespeed=None):
+
+        log.debug("Creating CNCJob object...")
+
+        self.decimals = self.app.decimals
+
+        CNCjob.__init__(self, units=units, kind=kind, z_move=z_move,
+                        feedrate=feedrate, feedrate_rapid=feedrate_rapid, z_cut=z_cut, tooldia=tooldia,
+                        spindlespeed=spindlespeed, steps_per_circle=int(self.app.defaults["cncjob_steps_per_circle"]))
+
+        FlatCAMObj.__init__(self, name)
+
+        self.kind = "cncjob"
+
+        self.options.update({
+            "plot": True,
+            "tooldia": 0.03937,  # 0.4mm in inches
+            "append": "",
+            "prepend": "",
+            "dwell": False,
+            "dwelltime": 1,
+            "type": 'Geometry',
+            "toolchange_macro": '',
+            "toolchange_macro_enable": False
+        })
+
+        '''
+            This is a dict of dictionaries. Each dict is associated with a tool present in the file. The key is the 
+            diameter of the tools and the value is another dict that will hold the data under the following form:
+               {tooldia:   {
+                           'tooluid': 1,
+                           'offset': 'Path',
+                           'type_item': 'Rough',
+                           'tool_type': 'C1',
+                           'data': {} # a dict to hold the parameters
+                           'gcode': "" # a string with the actual GCODE
+                           'gcode_parsed': {} # dictionary holding the CNCJob geometry and type of geometry 
+                           (cut or move)
+                           'solid_geometry': []
+                           },
+                           ...
+               }
+            It is populated in the GeometryObject.mtool_gen_cncjob()
+            BEWARE: I rely on the ordered nature of the Python 3.7 dictionary. Things might change ...
+        '''
+        self.cnc_tools = {}
+
+        '''
+           This is a dict of dictionaries. Each dict is associated with a tool present in the file. The key is the 
+           diameter of the tools and the value is another dict that will hold the data under the following form:
+              {tooldia:   {
+                          'tool': int,
+                          'nr_drills': int,
+                          'nr_slots': int,
+                          'offset': float,
+                          'data': {} # a dict to hold the parameters
+                          'gcode': "" # a string with the actual GCODE
+                          'gcode_parsed': {} # dictionary holding the CNCJob geometry and type of geometry (cut or move)
+                          'solid_geometry': []
+                          },
+                          ...
+              }
+           It is populated in the ExcellonObject.on_create_cncjob_click() but actually 
+           it's done in camlib.CNCJob.generate_from_excellon_by_tool()
+           BEWARE: I rely on the ordered nature of the Python 3.7 dictionary. Things might change ...
+       '''
+        self.exc_cnc_tools = {}
+
+        # flag to store if the CNCJob is part of a special group of CNCJob objects that can't be processed by the
+        # default engine of FlatCAM. They generated by some of tools and are special cases of CNCJob objects.
+        self.special_group = None
+
+        # for now it show if the plot will be done for multi-tool CNCJob (True) or for single tool
+        # (like the one in the TCL Command), False
+        self.multitool = False
+
+        # determine if the GCode was generated out of a Excellon object or a Geometry object
+        self.origin_kind = None
+
+        # used for parsing the GCode lines to adjust the GCode when the GCode is offseted or scaled
+        gcodex_re_string = r'(?=.*(X[-\+]?\d*\.\d*))'
+        self.g_x_re = re.compile(gcodex_re_string)
+        gcodey_re_string = r'(?=.*(Y[-\+]?\d*\.\d*))'
+        self.g_y_re = re.compile(gcodey_re_string)
+        gcodez_re_string = r'(?=.*(Z[-\+]?\d*\.\d*))'
+        self.g_z_re = re.compile(gcodez_re_string)
+
+        gcodef_re_string = r'(?=.*(F[-\+]?\d*\.\d*))'
+        self.g_f_re = re.compile(gcodef_re_string)
+        gcodet_re_string = r'(?=.*(\=\s*[-\+]?\d*\.\d*))'
+        self.g_t_re = re.compile(gcodet_re_string)
+
+        gcodenr_re_string = r'([+-]?\d*\.\d+)'
+        self.g_nr_re = re.compile(gcodenr_re_string)
+
+        # Attributes to be included in serialization
+        # Always append to it because it carries contents
+        # from predecessors.
+        self.ser_attrs += ['options', 'kind', 'origin_kind', 'cnc_tools', 'exc_cnc_tools', 'multitool']
+
+        if self.app.is_legacy is False:
+            self.text_col = self.app.plotcanvas.new_text_collection()
+            self.text_col.enabled = True
+            self.annotation = self.app.plotcanvas.new_text_group(collection=self.text_col)
+
+        self.gcode_editor_tab = None
+
+        self.units_found = self.app.defaults['units']
+
+    def build_ui(self):
+        self.ui_disconnect()
+
+        FlatCAMObj.build_ui(self)
+        self.units = self.app.defaults['units'].upper()
+
+        # if the FlatCAM object is Excellon don't build the CNC Tools Table but hide it
+        self.ui.cnc_tools_table.hide()
+        if self.cnc_tools:
+            self.ui.cnc_tools_table.show()
+            self.build_cnc_tools_table()
+
+        self.ui.exc_cnc_tools_table.hide()
+        if self.exc_cnc_tools:
+            self.ui.exc_cnc_tools_table.show()
+            self.build_excellon_cnc_tools()
+        #
+        self.ui_connect()
+
+    def build_cnc_tools_table(self):
+        tool_idx = 0
+
+        n = len(self.cnc_tools)
+        self.ui.cnc_tools_table.setRowCount(n)
+
+        for dia_key, dia_value in self.cnc_tools.items():
+
+            tool_idx += 1
+            row_no = tool_idx - 1
+
+            t_id = QtWidgets.QTableWidgetItem('%d' % int(tool_idx))
+            # id.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
+            self.ui.cnc_tools_table.setItem(row_no, 0, t_id)  # Tool name/id
+
+            # Make sure that the tool diameter when in MM is with no more than 2 decimals.
+            # There are no tool bits in MM with more than 2 decimals diameter.
+            # For INCH the decimals should be no more than 4. There are no tools under 10mils.
+
+            dia_item = QtWidgets.QTableWidgetItem('%.*f' % (self.decimals, float(dia_value['tooldia'])))
+
+            offset_txt = list(str(dia_value['offset']))
+            offset_txt[0] = offset_txt[0].upper()
+            offset_item = QtWidgets.QTableWidgetItem(''.join(offset_txt))
+            type_item = QtWidgets.QTableWidgetItem(str(dia_value['type']))
+            tool_type_item = QtWidgets.QTableWidgetItem(str(dia_value['tool_type']))
+
+            t_id.setFlags(QtCore.Qt.ItemIsEnabled)
+            dia_item.setFlags(QtCore.Qt.ItemIsEnabled)
+            offset_item.setFlags(QtCore.Qt.ItemIsEnabled)
+            type_item.setFlags(QtCore.Qt.ItemIsEnabled)
+            tool_type_item.setFlags(QtCore.Qt.ItemIsEnabled)
+
+            # hack so the checkbox stay centered in the table cell
+            # used this:
+            # https://stackoverflow.com/questions/32458111/pyqt-allign-checkbox-and-put-it-in-every-row
+            # plot_item = QtWidgets.QWidget()
+            # checkbox = FCCheckBox()
+            # checkbox.setCheckState(QtCore.Qt.Checked)
+            # qhboxlayout = QtWidgets.QHBoxLayout(plot_item)
+            # qhboxlayout.addWidget(checkbox)
+            # qhboxlayout.setAlignment(QtCore.Qt.AlignCenter)
+            # qhboxlayout.setContentsMargins(0, 0, 0, 0)
+            plot_item = FCCheckBox()
+            plot_item.setLayoutDirection(QtCore.Qt.RightToLeft)
+            tool_uid_item = QtWidgets.QTableWidgetItem(str(dia_key))
+            if self.ui.plot_cb.isChecked():
+                plot_item.setChecked(True)
+
+            self.ui.cnc_tools_table.setItem(row_no, 1, dia_item)  # Diameter
+            self.ui.cnc_tools_table.setItem(row_no, 2, offset_item)  # Offset
+            self.ui.cnc_tools_table.setItem(row_no, 3, type_item)  # Toolpath Type
+            self.ui.cnc_tools_table.setItem(row_no, 4, tool_type_item)  # Tool Type
+
+            # ## REMEMBER: THIS COLUMN IS HIDDEN IN OBJECTUI.PY # ##
+            self.ui.cnc_tools_table.setItem(row_no, 5, tool_uid_item)  # Tool unique ID)
+            self.ui.cnc_tools_table.setCellWidget(row_no, 6, plot_item)
+
+        # make the diameter column editable
+        # for row in range(tool_idx):
+        #     self.ui.cnc_tools_table.item(row, 1).setFlags(QtCore.Qt.ItemIsSelectable |
+        #                                                   QtCore.Qt.ItemIsEnabled)
+
+        for row in range(tool_idx):
+            self.ui.cnc_tools_table.item(row, 0).setFlags(
+                self.ui.cnc_tools_table.item(row, 0).flags() ^ QtCore.Qt.ItemIsSelectable)
+
+        self.ui.cnc_tools_table.resizeColumnsToContents()
+        self.ui.cnc_tools_table.resizeRowsToContents()
+
+        vertical_header = self.ui.cnc_tools_table.verticalHeader()
+        # vertical_header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
+        vertical_header.hide()
+        self.ui.cnc_tools_table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
+
+        horizontal_header = self.ui.cnc_tools_table.horizontalHeader()
+        horizontal_header.setMinimumSectionSize(10)
+        horizontal_header.setDefaultSectionSize(70)
+        horizontal_header.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
+        horizontal_header.resizeSection(0, 20)
+        horizontal_header.setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
+        horizontal_header.setSectionResizeMode(3, QtWidgets.QHeaderView.ResizeToContents)
+        horizontal_header.setSectionResizeMode(4, QtWidgets.QHeaderView.Fixed)
+        horizontal_header.resizeSection(4, 40)
+        horizontal_header.setSectionResizeMode(6, QtWidgets.QHeaderView.Fixed)
+        horizontal_header.resizeSection(4, 17)
+        # horizontal_header.setStretchLastSection(True)
+        self.ui.cnc_tools_table.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
+
+        self.ui.cnc_tools_table.setColumnWidth(0, 20)
+        self.ui.cnc_tools_table.setColumnWidth(4, 40)
+        self.ui.cnc_tools_table.setColumnWidth(6, 17)
+
+        # self.ui.geo_tools_table.setSortingEnabled(True)
+
+        self.ui.cnc_tools_table.setMinimumHeight(self.ui.cnc_tools_table.getHeight())
+        self.ui.cnc_tools_table.setMaximumHeight(self.ui.cnc_tools_table.getHeight())
+
+    def build_excellon_cnc_tools(self):
+        tool_idx = 0
+
+        n = len(self.exc_cnc_tools)
+        self.ui.exc_cnc_tools_table.setRowCount(n)
+
+        for tooldia_key, dia_value in self.exc_cnc_tools.items():
+
+            tool_idx += 1
+            row_no = tool_idx - 1
+
+            t_id = QtWidgets.QTableWidgetItem('%d' % int(tool_idx))
+            dia_item = QtWidgets.QTableWidgetItem('%.*f' % (self.decimals, float(tooldia_key)))
+            nr_drills_item = QtWidgets.QTableWidgetItem('%d' % int(dia_value['nr_drills']))
+            nr_slots_item = QtWidgets.QTableWidgetItem('%d' % int(dia_value['nr_slots']))
+            cutz_item = QtWidgets.QTableWidgetItem('%.*f' % (self.decimals, float(dia_value['offset_z']) + self.z_cut))
+
+            t_id.setFlags(QtCore.Qt.ItemIsEnabled)
+            dia_item.setFlags(QtCore.Qt.ItemIsEnabled)
+            nr_drills_item.setFlags(QtCore.Qt.ItemIsEnabled)
+            nr_slots_item.setFlags(QtCore.Qt.ItemIsEnabled)
+            cutz_item.setFlags(QtCore.Qt.ItemIsEnabled)
+
+            # hack so the checkbox stay centered in the table cell
+            # used this:
+            # https://stackoverflow.com/questions/32458111/pyqt-allign-checkbox-and-put-it-in-every-row
+            # plot_item = QtWidgets.QWidget()
+            # checkbox = FCCheckBox()
+            # checkbox.setCheckState(QtCore.Qt.Checked)
+            # qhboxlayout = QtWidgets.QHBoxLayout(plot_item)
+            # qhboxlayout.addWidget(checkbox)
+            # qhboxlayout.setAlignment(QtCore.Qt.AlignCenter)
+            # qhboxlayout.setContentsMargins(0, 0, 0, 0)
+
+            plot_item = FCCheckBox()
+            plot_item.setLayoutDirection(QtCore.Qt.RightToLeft)
+            tool_uid_item = QtWidgets.QTableWidgetItem(str(dia_value['tool']))
+            if self.ui.plot_cb.isChecked():
+                plot_item.setChecked(True)
+
+            # TODO until the feature of individual plot for an Excellon tool is implemented
+            plot_item.setDisabled(True)
+
+            self.ui.exc_cnc_tools_table.setItem(row_no, 0, t_id)  # Tool name/id
+            self.ui.exc_cnc_tools_table.setItem(row_no, 1, dia_item)  # Diameter
+            self.ui.exc_cnc_tools_table.setItem(row_no, 2, nr_drills_item)  # Nr of drills
+            self.ui.exc_cnc_tools_table.setItem(row_no, 3, nr_slots_item)  # Nr of slots
+
+            # ## REMEMBER: THIS COLUMN IS HIDDEN IN OBJECTUI.PY # ##
+            self.ui.exc_cnc_tools_table.setItem(row_no, 4, tool_uid_item)  # Tool unique ID)
+            self.ui.exc_cnc_tools_table.setItem(row_no, 5, cutz_item)
+            self.ui.exc_cnc_tools_table.setCellWidget(row_no, 6, plot_item)
+
+        for row in range(tool_idx):
+            self.ui.exc_cnc_tools_table.item(row, 0).setFlags(
+                self.ui.exc_cnc_tools_table.item(row, 0).flags() ^ QtCore.Qt.ItemIsSelectable)
+
+        self.ui.exc_cnc_tools_table.resizeColumnsToContents()
+        self.ui.exc_cnc_tools_table.resizeRowsToContents()
+
+        vertical_header = self.ui.exc_cnc_tools_table.verticalHeader()
+        vertical_header.hide()
+        self.ui.exc_cnc_tools_table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
+
+        horizontal_header = self.ui.exc_cnc_tools_table.horizontalHeader()
+        horizontal_header.setMinimumSectionSize(10)
+        horizontal_header.setDefaultSectionSize(70)
+        horizontal_header.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
+        horizontal_header.resizeSection(0, 20)
+        horizontal_header.setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
+        horizontal_header.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
+        horizontal_header.setSectionResizeMode(3, QtWidgets.QHeaderView.ResizeToContents)
+        horizontal_header.setSectionResizeMode(5, QtWidgets.QHeaderView.ResizeToContents)
+
+        horizontal_header.setSectionResizeMode(6, QtWidgets.QHeaderView.Fixed)
+
+        # horizontal_header.setStretchLastSection(True)
+        self.ui.exc_cnc_tools_table.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
+
+        self.ui.exc_cnc_tools_table.setColumnWidth(0, 20)
+        self.ui.exc_cnc_tools_table.setColumnWidth(6, 17)
+
+        self.ui.exc_cnc_tools_table.setMinimumHeight(self.ui.exc_cnc_tools_table.getHeight())
+        self.ui.exc_cnc_tools_table.setMaximumHeight(self.ui.exc_cnc_tools_table.getHeight())
+
+    def set_ui(self, ui):
+        FlatCAMObj.set_ui(self, ui)
+
+        log.debug("FlatCAMCNCJob.set_ui()")
+
+        assert isinstance(self.ui, CNCObjectUI), \
+            "Expected a CNCObjectUI, got %s" % type(self.ui)
+
+        self.units = self.app.defaults['units'].upper()
+        self.units_found = self.app.defaults['units']
+
+        # this signal has to be connected to it's slot before the defaults are populated
+        # the decision done in the slot has to override the default value set bellow
+        self.ui.toolchange_cb.toggled.connect(self.on_toolchange_custom_clicked)
+
+        self.form_fields.update({
+            "plot": self.ui.plot_cb,
+            "tooldia": self.ui.tooldia_entry,
+            "append": self.ui.append_text,
+            "prepend": self.ui.prepend_text,
+            "toolchange_macro": self.ui.toolchange_text,
+            "toolchange_macro_enable": self.ui.toolchange_cb
+        })
+
+        # Fill form fields only on object create
+        self.to_form()
+
+        # this means that the object that created this CNCJob was an Excellon or Geometry
+        try:
+            if self.travel_distance:
+                self.ui.t_distance_label.show()
+                self.ui.t_distance_entry.setVisible(True)
+                self.ui.t_distance_entry.setDisabled(True)
+                self.ui.t_distance_entry.set_value('%.*f' % (self.decimals, float(self.travel_distance)))
+                self.ui.units_label.setText(str(self.units).lower())
+                self.ui.units_label.setDisabled(True)
+
+                self.ui.t_time_label.show()
+                self.ui.t_time_entry.setVisible(True)
+                self.ui.t_time_entry.setDisabled(True)
+                # if time is more than 1 then we have minutes, else we have seconds
+                if self.routing_time > 1:
+                    self.ui.t_time_entry.set_value('%.*f' % (self.decimals, math.ceil(float(self.routing_time))))
+                    self.ui.units_time_label.setText('min')
+                else:
+                    time_r = self.routing_time * 60
+                    self.ui.t_time_entry.set_value('%.*f' % (self.decimals, math.ceil(float(time_r))))
+                    self.ui.units_time_label.setText('sec')
+                self.ui.units_time_label.setDisabled(True)
+        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"])
+
+        try:
+            self.ui.annotation_cb.stateChanged.disconnect(self.on_annotation_change)
+        except (TypeError, AttributeError):
+            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(_(
+                '<span style="color:green;"><b>Basic</b></span>'
+            ))
+
+            self.ui.cnc_frame.hide()
+        else:
+            self.ui.level.setText(_(
+                '<span style="color:red;"><b>Advanced</b></span>'
+            ))
+            self.ui.cnc_frame.show()
+
+        self.ui.updateplot_button.clicked.connect(self.on_updateplot_button_click)
+        self.ui.export_gcode_button.clicked.connect(self.on_exportgcode_button_click)
+        self.ui.modify_gcode_button.clicked.connect(self.on_edit_code_click)
+
+        self.ui.tc_variable_combo.currentIndexChanged[str].connect(self.on_cnc_custom_parameters)
+
+        self.ui.cncplot_method_combo.activated_custom.connect(self.on_plot_kind_change)
+
+    def on_cnc_custom_parameters(self, signal_text):
+        if signal_text == 'Parameters':
+            return
+        else:
+            self.ui.toolchange_text.insertPlainText('%%%s%%' % signal_text)
+
+    def ui_connect(self):
+        for row in range(self.ui.cnc_tools_table.rowCount()):
+            self.ui.cnc_tools_table.cellWidget(row, 6).clicked.connect(self.on_plot_cb_click_table)
+        self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
+
+    def ui_disconnect(self):
+        for row in range(self.ui.cnc_tools_table.rowCount()):
+            self.ui.cnc_tools_table.cellWidget(row, 6).clicked.disconnect(self.on_plot_cb_click_table)
+        try:
+            self.ui.plot_cb.stateChanged.disconnect(self.on_plot_cb_click)
+        except (TypeError, AttributeError):
+            pass
+
+    def on_updateplot_button_click(self, *args):
+        """
+        Callback for the "Updata Plot" button. Reads the form for updates
+        and plots the object.
+        """
+        self.read_form()
+        self.on_plot_kind_change()
+
+    def on_plot_kind_change(self):
+        kind = self.ui.cncplot_method_combo.get_value()
+
+        def worker_task():
+            with self.app.proc_container.new(_("Plotting...")):
+                self.plot(kind=kind)
+
+        self.app.worker_task.emit({'fcn': worker_task, 'params': []})
+
+    def on_exportgcode_button_click(self, *args):
+        """
+        Handler activated by a button clicked when exporting GCode.
+
+        :param args:
+        :return:
+        """
+        self.app.report_usage("cncjob_on_exportgcode_button")
+
+        self.read_form()
+        name = self.app.collection.get_active().options['name']
+        save_gcode = False
+
+        if 'Roland' in self.pp_excellon_name or 'Roland' in self.pp_geometry_name:
+            _filter_ = "RML1 Files .rol (*.rol);;All Files (*.*)"
+        elif 'hpgl' in self.pp_geometry_name:
+            _filter_ = "HPGL Files .plt (*.plt);;All Files (*.*)"
+        else:
+            save_gcode = True
+            _filter_ = self.app.defaults['cncjob_save_filters']
+
+        try:
+            dir_file_to_save = self.app.get_last_save_folder() + '/' + str(name)
+            filename, _f = FCFileSaveDialog.get_saved_filename(
+                caption=_("Export Machine Code ..."),
+                directory=dir_file_to_save,
+                filter=_filter_
+            )
+        except TypeError:
+            filename, _f = FCFileSaveDialog.get_saved_filename(caption=_("Export Machine Code ..."), filter=_filter_)
+
+        filename = str(filename)
+
+        if filename == '':
+            self.app.inform.emit('[WARNING_NOTCL] %s' % _("Export Machine Code cancelled ..."))
+            return
+        else:
+            if save_gcode is True:
+                used_extension = filename.rpartition('.')[2]
+                self.update_filters(last_ext=used_extension, filter_string='cncjob_save_filters')
+
+        new_name = os.path.split(str(filename))[1].rpartition('.')[0]
+        self.ui.name_entry.set_value(new_name)
+        self.on_name_activate(silent=True)
+
+        preamble = str(self.ui.prepend_text.get_value())
+        postamble = str(self.ui.append_text.get_value())
+
+        gc = self.export_gcode(filename, preamble=preamble, postamble=postamble)
+        if gc == 'fail':
+            return
+
+        if self.app.defaults["global_open_style"] is False:
+            self.app.file_opened.emit("gcode", filename)
+        self.app.file_saved.emit("gcode", filename)
+        self.app.inform.emit('[success] %s: %s' % (_("Machine Code file saved to"), filename))
+
+    def on_edit_code_click(self, *args):
+        """
+        Handler activated by a button clicked when editing GCode.
+
+        :param args:
+        :return:
+        """
+
+        self.app.proc_container.view.set_busy(_("Loading..."))
+
+        preamble = str(self.ui.prepend_text.get_value())
+        postamble = str(self.ui.append_text.get_value())
+
+        gco = self.export_gcode(preamble=preamble, postamble=postamble, to_file=True)
+        if gco == 'fail':
+            return
+        else:
+            self.app.gcode_edited = gco
+
+        self.gcode_editor_tab = TextEditor(app=self.app, plain_text=True)
+
+        # add the tab if it was closed
+        self.app.ui.plot_tab_area.addTab(self.gcode_editor_tab, '%s' % _("Code Editor"))
+        self.gcode_editor_tab.setObjectName('code_editor_tab')
+
+        # delete the absolute and relative position and messages in the infobar
+        self.app.ui.position_label.setText("")
+        self.app.ui.rel_position_label.setText("")
+
+        # first clear previous text in text editor (if any)
+        self.gcode_editor_tab.code_editor.clear()
+        self.gcode_editor_tab.code_editor.setReadOnly(False)
+
+        self.gcode_editor_tab.code_editor.completer_enable = False
+        self.gcode_editor_tab.buttonRun.hide()
+
+        # Switch plot_area to CNCJob tab
+        self.app.ui.plot_tab_area.setCurrentWidget(self.gcode_editor_tab)
+
+        self.gcode_editor_tab.t_frame.hide()
+        # then append the text from GCode to the text editor
+        try:
+            self.gcode_editor_tab.code_editor.setPlainText(self.app.gcode_edited.getvalue())
+            # for line in self.app.gcode_edited:
+            #     QtWidgets.QApplication.processEvents()
+            #
+            #     proc_line = str(line).strip('\n')
+            #     self.gcode_editor_tab.code_editor.append(proc_line)
+        except Exception as e:
+            log.debug('FlatCAMCNNJob.on_edit_code_click() -->%s' % str(e))
+            self.app.inform.emit('[ERROR] %s %s' % ('FlatCAMCNNJob.on_edit_code_click() -->', str(e)))
+            return
+
+        self.gcode_editor_tab.code_editor.moveCursor(QtGui.QTextCursor.Start)
+
+        self.gcode_editor_tab.handleTextChanged()
+        self.gcode_editor_tab.t_frame.show()
+        self.app.proc_container.view.set_idle()
+
+        self.app.inform.emit('[success] %s...' % _('Loaded Machine Code into Code Editor'))
+
+    def gcode_header(self, comment_start_symbol=None, comment_stop_symbol=None):
+        """
+        Will create a header to be added to all GCode files generated by FlatCAM
+
+        :param comment_start_symbol:    A symbol to be used as the first symbol in a comment
+        :param comment_stop_symbol:     A symbol to be used as the last symbol in a comment
+        :return:                        A string with a GCode header
+        """
+
+        log.debug("FlatCAMCNCJob.gcode_header()")
+        time_str = "{:%A, %d %B %Y at %H:%M}".format(datetime.now())
+        marlin = False
+        hpgl = False
+        probe_pp = False
+
+        start_comment = comment_start_symbol if comment_start_symbol is not None else '('
+        stop_comment = comment_stop_symbol if comment_stop_symbol is not None else ')'
+
+        try:
+            for key in self.cnc_tools:
+                ppg = self.cnc_tools[key]['data']['ppname_g']
+                if 'marlin' in ppg.lower() or 'repetier' in ppg.lower():
+                    marlin = True
+                    break
+                if ppg == 'hpgl':
+                    hpgl = True
+                    break
+                if "toolchange_probe" in ppg.lower():
+                    probe_pp = True
+                    break
+        except KeyError:
+            # log.debug("FlatCAMCNCJob.gcode_header() error: --> %s" % str(e))
+            pass
+
+        try:
+            if 'marlin' in self.options['ppname_e'].lower() or 'repetier' in self.options['ppname_e'].lower():
+                marlin = True
+        except KeyError:
+            # log.debug("FlatCAMCNCJob.gcode_header(): --> There is no such self.option: %s" % str(e))
+            pass
+
+        try:
+            if "toolchange_probe" in self.options['ppname_e'].lower():
+                probe_pp = True
+        except KeyError:
+            # log.debug("FlatCAMCNCJob.gcode_header(): --> There is no such self.option: %s" % str(e))
+            pass
+
+        if marlin is True:
+            gcode = ';Marlin(Repetier) G-CODE GENERATED BY FLATCAM v%s - www.flatcam.org - Version Date:    %s\n' % \
+                    (str(self.app.version), str(self.app.version_date)) + '\n'
+
+            gcode += ';Name: ' + str(self.options['name']) + '\n'
+            gcode += ';Type: ' + "G-code from " + str(self.options['type']) + '\n'
+
+            # if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
+            #     gcode += '(Tools in use: ' + str(p['options']['Tools_in_use']) + ')\n'
+
+            gcode += ';Units: ' + self.units.upper() + '\n' + "\n"
+            gcode += ';Created on ' + time_str + '\n' + '\n'
+        elif hpgl is True:
+            gcode = 'CO "HPGL CODE GENERATED BY FLATCAM v%s - www.flatcam.org - Version Date:    %s' % \
+                    (str(self.app.version), str(self.app.version_date)) + '";\n'
+
+            gcode += 'CO "Name: ' + str(self.options['name']) + '";\n'
+            gcode += 'CO "Type: ' + "HPGL code from " + str(self.options['type']) + '";\n'
+
+            # if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
+            #     gcode += '(Tools in use: ' + str(p['options']['Tools_in_use']) + ')\n'
+
+            gcode += 'CO "Units: ' + self.units.upper() + '";\n'
+            gcode += 'CO "Created on ' + time_str + '";\n'
+        elif probe_pp is True:
+            gcode = '(G-CODE GENERATED BY FLATCAM v%s - www.flatcam.org - Version Date: %s)\n' % \
+                    (str(self.app.version), str(self.app.version_date)) + '\n'
+
+            gcode += '(This GCode tool change is done by using a Probe.)\n' \
+                     '(Make sure that before you start the job you first do a rough zero for Z axis.)\n' \
+                     '(This means that you need to zero the CNC axis and then jog to the toolchange X, Y location,)\n' \
+                     '(mount the probe and adjust the Z so more or less the probe tip touch the plate. ' \
+                     'Then zero the Z axis.)\n' + '\n'
+
+            gcode += '(Name: ' + str(self.options['name']) + ')\n'
+            gcode += '(Type: ' + "G-code from " + str(self.options['type']) + ')\n'
+
+            # if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
+            #     gcode += '(Tools in use: ' + str(p['options']['Tools_in_use']) + ')\n'
+
+            gcode += '(Units: ' + self.units.upper() + ')\n' + "\n"
+            gcode += '(Created on ' + time_str + ')\n' + '\n'
+        else:
+            gcode = '%sG-CODE GENERATED BY FLATCAM v%s - www.flatcam.org - Version Date: %s%s\n' % \
+                    (start_comment, str(self.app.version), str(self.app.version_date), stop_comment) + '\n'
+
+            gcode += '%sName: ' % start_comment + str(self.options['name']) + '%s\n' % stop_comment
+            gcode += '%sType: ' % start_comment + "G-code from " + str(self.options['type']) + '%s\n' % stop_comment
+
+            # if str(p['options']['type']) == 'Excellon' or str(p['options']['type']) == 'Excellon Geometry':
+            #     gcode += '(Tools in use: ' + str(p['options']['Tools_in_use']) + ')\n'
+
+            gcode += '%sUnits: ' % start_comment + self.units.upper() + '%s\n' % stop_comment + "\n"
+            gcode += '%sCreated on ' % start_comment + time_str + '%s\n' % stop_comment + '\n'
+
+        return gcode
+
+    @staticmethod
+    def gcode_footer(end_command=None):
+        """
+        Will add the M02 to the end of GCode, if requested.
+
+        :param end_command: 'M02' or 'M30' - String
+        :return:
+        """
+        if end_command:
+            return end_command
+        else:
+            return 'M02'
+
+    def export_gcode(self, filename=None, preamble='', postamble='', to_file=False):
+        """
+        This will save the GCode from the Gcode object to a file on the OS filesystem
+
+        :param filename:    filename for the GCode file
+        :param preamble:    a custom Gcode block to be added at the beginning of the Gcode file
+        :param postamble:   a custom Gcode block to be added at the end of the Gcode file
+        :param to_file:     if False then no actual file is saved but the app will know that a file was created
+        :return:            None
+        """
+        # gcode = ''
+        # roland = False
+        # hpgl = False
+        # isel_icp = False
+
+        include_header = True
+
+        try:
+            if self.special_group:
+                self.app.inform.emit('[WARNING_NOTCL] %s %s %s.' %
+                                     (_("This CNCJob object can't be processed because it is a"),
+                                      str(self.special_group),
+                                      _("CNCJob object")))
+                return 'fail'
+        except AttributeError:
+            pass
+
+        # if this dict is not empty then the object is a Geometry object
+        if self.cnc_tools:
+            first_key = next(iter(self.cnc_tools))
+            include_header = self.app.preprocessors[self.cnc_tools[first_key]['data']['ppname_g']].include_header
+
+        # if this dict is not empty then the object is an Excellon object
+        if self.exc_cnc_tools:
+            first_key = next(iter(self.exc_cnc_tools))
+            include_header = self.app.preprocessors[self.exc_cnc_tools[first_key]['data']['ppname_e']].include_header
+
+        # # detect if using Roland preprocessor
+        # try:
+        #     for key in self.cnc_tools:
+        #         if self.cnc_tools[key]['data']['ppname_g'] == 'Roland_MDX_20':
+        #             roland = True
+        #             break
+        # except Exception:
+        #     try:
+        #         for key in self.cnc_tools:
+        #             if self.cnc_tools[key]['data']['ppname_e'] == 'Roland_MDX_20':
+        #                 roland = True
+        #                 break
+        #     except Exception:
+        #         pass
+        #
+        # # detect if using HPGL preprocessor
+        # try:
+        #     for key in self.cnc_tools:
+        #         if self.cnc_tools[key]['data']['ppname_g'] == 'hpgl':
+        #             hpgl = True
+        #             break
+        # except Exception:
+        #     try:
+        #         for key in self.cnc_tools:
+        #             if self.cnc_tools[key]['data']['ppname_e'] == 'hpgl':
+        #                 hpgl = True
+        #                 break
+        #     except Exception:
+        #         pass
+        #
+        # # detect if using ISEL_ICP_CNC preprocessor
+        # try:
+        #     for key in self.cnc_tools:
+        #         if 'ISEL_ICP' in self.cnc_tools[key]['data']['ppname_g'].upper():
+        #             isel_icp = True
+        #             break
+        # except Exception:
+        #     try:
+        #         for key in self.cnc_tools:
+        #             if 'ISEL_ICP' in self.cnc_tools[key]['data']['ppname_e'].upper():
+        #                 isel_icp = True
+        #                 break
+        #     except Exception:
+        #         pass
+
+        # do not add gcode_header when using the Roland preprocessor, add it for every other preprocessor
+        # if roland is False and hpgl is False and isel_icp is False:
+        #     gcode = self.gcode_header()
+
+        # do not add gcode_header when using the Roland, HPGL or ISEP_ICP_CNC preprocessor (or any other preprocessor
+        # that has the include_header attribute set as False, add it for every other preprocessor
+        # if include_header:
+        #     gcode = self.gcode_header()
+        # else:
+        #     gcode = ''
+
+        # # detect if using multi-tool and make the Gcode summation correctly for each case
+        # if self.multitool is True:
+        #     for tooluid_key in self.cnc_tools:
+        #         for key, value in self.cnc_tools[tooluid_key].items():
+        #             if key == 'gcode':
+        #                 gcode += value
+        #                 break
+        # else:
+        #     gcode += self.gcode
+
+        # if roland is True:
+        #     g = preamble + gcode + postamble
+        # elif hpgl is True:
+        #     g = self.gcode_header() + preamble + gcode + postamble
+        # else:
+        #     # fix so the preamble gets inserted in between the comments header and the actual start of GCODE
+        #     g_idx = gcode.rfind('G20')
+        #
+        #     # if it did not find 'G20' then search for 'G21'
+        #     if g_idx == -1:
+        #         g_idx = gcode.rfind('G21')
+        #
+        #     # if it did not find 'G20' and it did not find 'G21' then there is an error and return
+        #     # but only when the preprocessor is not ISEL_ICP who is allowed not to have the G20/G21 command
+        #     if g_idx == -1 and isel_icp is False:
+        #         self.app.inform.emit('[ERROR_NOTCL] %s' % _("G-code does not have a units code: either G20 or G21"))
+        #         return
+        #
+        #     footer = self.app.defaults['cncjob_footer']
+        #     end_gcode = self.gcode_footer() if footer is True else ''
+        #     g = gcode[:g_idx] + preamble + '\n' + gcode[g_idx:] + postamble + end_gcode
+
+        gcode = ''
+        if include_header is False:
+            g = preamble
+            # detect if using multi-tool and make the Gcode summation correctly for each case
+            if self.multitool is True:
+                for tooluid_key in self.cnc_tools:
+                    for key, value in self.cnc_tools[tooluid_key].items():
+                        if key == 'gcode':
+                            gcode += value
+                            break
+            else:
+                gcode += self.gcode
+
+            g = g + gcode + postamble
+        else:
+            # search for the GCode beginning which is usually a G20 or G21
+            # fix so the preamble gets inserted in between the comments header and the actual start of GCODE
+            # g_idx = gcode.rfind('G20')
+            #
+            # # if it did not find 'G20' then search for 'G21'
+            # if g_idx == -1:
+            #     g_idx = gcode.rfind('G21')
+            #
+            # # if it did not find 'G20' and it did not find 'G21' then there is an error and return
+            # if g_idx == -1:
+            #     self.app.inform.emit('[ERROR_NOTCL] %s' % _("G-code does not have a units code: either G20 or G21"))
+            #     return
+
+            # detect if using multi-tool and make the Gcode summation correctly for each case
+            if self.multitool is True:
+                for tooluid_key in self.cnc_tools:
+                    for key, value in self.cnc_tools[tooluid_key].items():
+                        if key == 'gcode':
+                            gcode += value
+                            break
+            else:
+                gcode += self.gcode
+
+            end_gcode = self.gcode_footer() if self.app.defaults['cncjob_footer'] is True else ''
+
+            # detect if using a HPGL preprocessor
+            hpgl = False
+            if self.cnc_tools:
+                for key in self.cnc_tools:
+                    if 'ppname_g' in self.cnc_tools[key]['data']:
+                        if 'hpgl' in self.cnc_tools[key]['data']['ppname_g']:
+                            hpgl = True
+                            break
+            elif self.exc_cnc_tools:
+                for key in self.cnc_tools:
+                    if 'ppname_e' in self.cnc_tools[key]['data']:
+                        if 'hpgl' in self.cnc_tools[key]['data']['ppname_e']:
+                            hpgl = True
+                            break
+
+            if hpgl:
+                processed_gcode = ''
+                pa_re = re.compile(r"^PA\s*(-?\d+\.\d*),?\s*(-?\d+\.\d*)*;?$")
+                for gline in gcode.splitlines():
+                    match = pa_re.search(gline)
+                    if match:
+                        x_int = int(float(match.group(1)))
+                        y_int = int(float(match.group(2)))
+                        new_line = 'PA%d,%d;\n' % (x_int, y_int)
+                        processed_gcode += new_line
+                    else:
+                        processed_gcode += gline + '\n'
+
+                gcode = processed_gcode
+                g = self.gcode_header() + '\n' + preamble + '\n' + gcode + postamble + end_gcode
+            else:
+                try:
+                    g_idx = gcode.index('G94')
+                    g = self.gcode_header() + gcode[:g_idx + 3] + '\n\n' + preamble + '\n' + \
+                        gcode[(g_idx + 3):] + postamble + end_gcode
+                except ValueError:
+                    self.app.inform.emit('[ERROR_NOTCL] %s' %
+                                         _("G-code does not have a G94 code and we will not include the code in the "
+                                           "'Prepend to GCode' text box"))
+                    g = self.gcode_header() + '\n' + gcode + postamble + end_gcode
+
+        # if toolchange custom is used, replace M6 code with the code from the Toolchange Custom Text box
+        if self.ui.toolchange_cb.get_value() is True:
+            # match = self.re_toolchange.search(g)
+            if 'M6' in g:
+                m6_code = self.parse_custom_toolchange_code(self.ui.toolchange_text.get_value())
+                if m6_code is None or m6_code == '':
+                    self.app.inform.emit(
+                        '[ERROR_NOTCL] %s' % _("Cancelled. The Toolchange Custom code is enabled but it's empty.")
+                    )
+                    return 'fail'
+
+                g = g.replace('M6', m6_code)
+                self.app.inform.emit('[success] %s' % _("Toolchange G-code was replaced by a custom code."))
+
+        lines = StringIO(g)
+
+        # Write
+        if filename is not None:
+            try:
+                force_windows_line_endings = self.app.defaults['cncjob_line_ending']
+                if force_windows_line_endings and sys.platform != 'win32':
+                    with open(filename, 'w', newline='\r\n') as f:
+                        for line in lines:
+                            f.write(line)
+                else:
+                    with open(filename, 'w') as f:
+                        for line in lines:
+                            f.write(line)
+            except FileNotFoundError:
+                self.app.inform.emit('[WARNING_NOTCL] %s' % _("No such file or directory"))
+                return
+            except PermissionError:
+                self.app.inform.emit(
+                    '[WARNING] %s' % _("Permission denied, saving not possible.\n"
+                                       "Most likely another app is holding the file open and not accessible.")
+                )
+                return 'fail'
+        elif to_file is False:
+            # Just for adding it to the recent files list.
+            if self.app.defaults["global_open_style"] is False:
+                self.app.file_opened.emit("cncjob", filename)
+            self.app.file_saved.emit("cncjob", filename)
+
+            self.app.inform.emit('[success] %s: %s' % (_("Saved to"), filename))
+        else:
+            return lines
+
+    def on_toolchange_custom_clicked(self, signal):
+        """
+        Handler for clicking toolchange custom.
+
+        :param signal:
+        :return:
+        """
+
+        try:
+            if 'toolchange_custom' not in str(self.options['ppname_e']).lower():
+                if self.ui.toolchange_cb.get_value():
+                    self.ui.toolchange_cb.set_value(False)
+                    self.app.inform.emit('[WARNING_NOTCL] %s' %
+                                         _("The used preprocessor file has to have in it's name: 'toolchange_custom'"))
+        except KeyError:
+            try:
+                for key in self.cnc_tools:
+                    ppg = self.cnc_tools[key]['data']['ppname_g']
+                    if 'toolchange_custom' not in str(ppg).lower():
+                        print(ppg)
+                        if self.ui.toolchange_cb.get_value():
+                            self.ui.toolchange_cb.set_value(False)
+                            self.app.inform.emit('[WARNING_NOTCL] %s' %
+                                                 _("The used preprocessor file has to have in it's name: "
+                                                   "'toolchange_custom'"))
+            except KeyError:
+                self.app.inform.emit('[ERROR] %s' % _("There is no preprocessor file."))
+
+    def get_gcode(self, preamble='', postamble=''):
+        """
+        We need this to be able to get_gcode separately for shell command export_gcode
+
+        :param preamble:    Extra GCode added to the beginning of the GCode
+        :param postamble:   Extra GCode added at the end of the GCode
+        :return:            The modified GCode
+        """
+        return preamble + '\n' + self.gcode + "\n" + postamble
+
+    def get_svg(self):
+        # we need this to be able get_svg separately for shell command export_svg
+        pass
+
+    def on_plot_cb_click(self, *args):
+        """
+        Handler for clicking on the Plot checkbox.
+
+        :param args:
+        :return:
+        """
+        if self.muted_ui:
+            return
+        kind = self.ui.cncplot_method_combo.get_value()
+        self.plot(kind=kind)
+        self.read_form_item('plot')
+
+        self.ui_disconnect()
+        cb_flag = self.ui.plot_cb.isChecked()
+        for row in range(self.ui.cnc_tools_table.rowCount()):
+            table_cb = self.ui.cnc_tools_table.cellWidget(row, 6)
+            if cb_flag:
+                table_cb.setChecked(True)
+            else:
+                table_cb.setChecked(False)
+        self.ui_connect()
+
+    def on_plot_cb_click_table(self):
+        """
+        Handler for clicking the plot checkboxes added into a Table on each row. Purpose: toggle visibility for the
+        tool/aperture found on that row.
+        :return:
+        """
+
+        # self.ui.cnc_tools_table.cellWidget(row, 2).widget().setCheckState(QtCore.Qt.Unchecked)
+        self.ui_disconnect()
+        # cw = self.sender()
+        # cw_index = self.ui.cnc_tools_table.indexAt(cw.pos())
+        # cw_row = cw_index.row()
+
+        kind = self.ui.cncplot_method_combo.get_value()
+
+        self.shapes.clear(update=True)
+
+        for tooluid_key in self.cnc_tools:
+            tooldia = float('%.*f' % (self.decimals, float(self.cnc_tools[tooluid_key]['tooldia'])))
+            gcode_parsed = self.cnc_tools[tooluid_key]['gcode_parsed']
+            # tool_uid = int(self.ui.cnc_tools_table.item(cw_row, 3).text())
+
+            for r in range(self.ui.cnc_tools_table.rowCount()):
+                if int(self.ui.cnc_tools_table.item(r, 5).text()) == int(tooluid_key):
+                    if self.ui.cnc_tools_table.cellWidget(r, 6).isChecked():
+                        self.plot2(tooldia=tooldia, obj=self, visible=True, gcode_parsed=gcode_parsed, kind=kind)
+
+        self.shapes.redraw()
+
+        # make sure that the general plot is disabled if one of the row plot's are disabled and
+        # if all the row plot's are enabled also enable the general plot checkbox
+        cb_cnt = 0
+        total_row = self.ui.cnc_tools_table.rowCount()
+        for row in range(total_row):
+            if self.ui.cnc_tools_table.cellWidget(row, 6).isChecked():
+                cb_cnt += 1
+            else:
+                cb_cnt -= 1
+        if cb_cnt < total_row:
+            self.ui.plot_cb.setChecked(False)
+        else:
+            self.ui.plot_cb.setChecked(True)
+        self.ui_connect()
+
+    def plot(self, visible=None, kind='all'):
+        """
+        # Does all the required setup and returns False
+        # if the 'ptint' option is set to False.
+
+        :param visible: Boolean to decide if the object will be plotted as visible or disabled on canvas
+        :param kind:    String. Can be "all" or "travel" or "cut". For CNCJob plotting
+        :return:        None
+        """
+        if not FlatCAMObj.plot(self):
+            return
+
+        visible = visible if visible else self.options['plot']
+
+        if self.app.is_legacy is False:
+            if self.ui.annotation_cb.get_value() and self.ui.plot_cb.get_value():
+                self.text_col.enabled = True
+            else:
+                self.text_col.enabled = False
+            self.annotation.redraw()
+
+        try:
+            if self.multitool is False:  # single tool usage
+                try:
+                    dia_plot = float(self.options["tooldia"])
+                except ValueError:
+                    # we may have a tuple with only one element and a comma
+                    dia_plot = [float(el) for el in self.options["tooldia"].split(',') if el != ''][0]
+                self.plot2(dia_plot, obj=self, visible=visible, kind=kind)
+            else:
+                # multiple tools usage
+                if self.cnc_tools:
+                    for tooluid_key in self.cnc_tools:
+                        tooldia = float('%.*f' % (self.decimals, float(self.cnc_tools[tooluid_key]['tooldia'])))
+                        gcode_parsed = self.cnc_tools[tooluid_key]['gcode_parsed']
+                        self.plot2(tooldia=tooldia, obj=self, visible=visible, gcode_parsed=gcode_parsed, kind=kind)
+
+                # TODO: until the gcode parsed will be stored on each Excellon tool this will not get executed
+                if self.exc_cnc_tools:
+                    for tooldia_key in self.exc_cnc_tools:
+                        tooldia = float('%.*f' % (self.decimals, float(tooldia_key)))
+                        # gcode_parsed = self.cnc_tools[tooldia_key]['gcode_parsed']
+                        gcode_parsed = self.gcode_parsed
+                        self.plot2(tooldia=tooldia, obj=self, visible=visible, gcode_parsed=gcode_parsed, kind=kind)
+
+            self.shapes.redraw()
+        except (ObjectDeleted, AttributeError):
+            self.shapes.clear(update=True)
+            if self.app.is_legacy is False:
+                self.annotation.clear(update=True)
+
+    def on_annotation_change(self):
+        """
+        Handler for toggling the annotation display by clicking a checkbox.
+        :return:
+        """
+
+        if self.app.is_legacy is False:
+            if self.ui.annotation_cb.get_value():
+                self.text_col.enabled = True
+            else:
+                self.text_col.enabled = False
+            # kind = self.ui.cncplot_method_combo.get_value()
+            # self.plot(kind=kind)
+            self.annotation.redraw()
+        else:
+            kind = self.ui.cncplot_method_combo.get_value()
+            self.plot(kind=kind)
+
+    def convert_units(self, units):
+        """
+        Units conversion used by the CNCJob objects.
+
+        :param units:   Can be "MM" or "IN"
+        :return:
+        """
+
+        log.debug("FlatCAMObj.FlatCAMECNCjob.convert_units()")
+
+        factor = CNCjob.convert_units(self, units)
+        self.options["tooldia"] = float(self.options["tooldia"]) * factor
+
+        param_list = ['cutz', 'depthperpass', 'travelz', 'feedrate', 'feedrate_z', 'feedrate_rapid',
+                      'endz', 'toolchangez']
+
+        temp_tools_dict = {}
+        tool_dia_copy = {}
+        data_copy = {}
+
+        for tooluid_key, tooluid_value in self.cnc_tools.items():
+            for dia_key, dia_value in tooluid_value.items():
+                if dia_key == 'tooldia':
+                    dia_value *= factor
+                    dia_value = float('%.*f' % (self.decimals, dia_value))
+                    tool_dia_copy[dia_key] = dia_value
+                if dia_key == 'offset':
+                    tool_dia_copy[dia_key] = dia_value
+                if dia_key == 'offset_value':
+                    dia_value *= factor
+                    tool_dia_copy[dia_key] = dia_value
+
+                if dia_key == 'type':
+                    tool_dia_copy[dia_key] = dia_value
+                if dia_key == 'tool_type':
+                    tool_dia_copy[dia_key] = dia_value
+                if dia_key == 'data':
+                    for data_key, data_value in dia_value.items():
+                        # convert the form fields that are convertible
+                        for param in param_list:
+                            if data_key == param and data_value is not None:
+                                data_copy[data_key] = data_value * factor
+                        # copy the other dict entries that are not convertible
+                        if data_key not in param_list:
+                            data_copy[data_key] = data_value
+                    tool_dia_copy[dia_key] = deepcopy(data_copy)
+                    data_copy.clear()
+
+                if dia_key == 'gcode':
+                    tool_dia_copy[dia_key] = dia_value
+                if dia_key == 'gcode_parsed':
+                    tool_dia_copy[dia_key] = dia_value
+                if dia_key == 'solid_geometry':
+                    tool_dia_copy[dia_key] = dia_value
+
+                # if dia_key == 'solid_geometry':
+                #     tool_dia_copy[dia_key] = affinity.scale(dia_value, xfact=factor, origin=(0, 0))
+                # if dia_key == 'gcode_parsed':
+                #     for g in dia_value:
+                #         g['geom'] = affinity.scale(g['geom'], factor, factor, origin=(0, 0))
+                #
+                #     tool_dia_copy['gcode_parsed'] = deepcopy(dia_value)
+                #     tool_dia_copy['solid_geometry'] = cascaded_union([geo['geom'] for geo in dia_value])
+
+            temp_tools_dict.update({
+                tooluid_key: deepcopy(tool_dia_copy)
+            })
+            tool_dia_copy.clear()
+
+        self.cnc_tools.clear()
+        self.cnc_tools = deepcopy(temp_tools_dict)

+ 314 - 0
flatcamObjects/FlatCAMDocument.py

@@ -0,0 +1,314 @@
+# ##########################################################
+# FlatCAM: 2D Post-processing for Manufacturing            #
+# http://flatcam.org                                       #
+# Author: Juan Pablo Caram (c)                             #
+# Date: 2/5/2014                                           #
+# MIT Licence                                              #
+# ##########################################################
+
+# ##########################################################
+# File modified by: Marius Stanciu                         #
+# ##########################################################
+
+from flatcamEditors.FlatCAMTextEditor import TextEditor
+from flatcamObjects.FlatCAMObj import *
+
+import gettext
+import FlatCAMTranslation as fcTranslate
+import builtins
+
+fcTranslate.apply_language('strings')
+if '_' not in builtins.__dict__:
+    _ = gettext.gettext
+
+
+class DocumentObject(FlatCAMObj):
+    """
+    Represents a Document object.
+    """
+    optionChanged = QtCore.pyqtSignal(str)
+    ui_type = DocumentObjectUI
+
+    def __init__(self, name):
+        self.decimals = self.app.decimals
+
+        log.debug("Creating a Document object...")
+        FlatCAMObj.__init__(self, name)
+
+        self.kind = "document"
+        self.units = ''
+
+        self.ser_attrs = ['options', 'kind', 'source_file']
+        self.source_file = ''
+        self.doc_code = ''
+
+        self.font_name = None
+        self.font_italic = None
+        self.font_bold = None
+        self.font_underline = None
+
+        self.document_editor_tab = None
+
+        self._read_only = False
+        self.units_found = self.app.defaults['units']
+
+    def set_ui(self, ui):
+        FlatCAMObj.set_ui(self, ui)
+        log.debug("DocumentObject.set_ui()")
+
+        assert isinstance(self.ui, DocumentObjectUI), \
+            "Expected a DocumentObjectUI, got %s" % type(self.ui)
+
+        self.units = self.app.defaults['units'].upper()
+        self.units_found = self.app.defaults['units']
+
+        # Fill form fields only on object create
+        self.to_form()
+
+        # Show/Hide Advanced Options
+        if self.app.defaults["global_app_level"] == 'b':
+            self.ui.level.setText(_(
+                '<span style="color:green;"><b>Basic</b></span>'
+            ))
+        else:
+            self.ui.level.setText(_(
+                '<span style="color:red;"><b>Advanced</b></span>'
+            ))
+
+        self.document_editor_tab = TextEditor(app=self.app)
+        stylesheet = """
+                        QTextEdit {selection-background-color:%s;
+                                   selection-color:white;
+                        }
+                     """ % self.app.defaults["document_sel_color"]
+
+        self.document_editor_tab.code_editor.setStyleSheet(stylesheet)
+
+        # first clear previous text in text editor (if any)
+        self.document_editor_tab.code_editor.clear()
+        self.document_editor_tab.code_editor.setReadOnly(self._read_only)
+
+        self.document_editor_tab.buttonRun.hide()
+
+        self.ui.autocomplete_cb.set_value(self.app.defaults['document_autocompleter'])
+        self.on_autocomplete_changed(state=self.app.defaults['document_autocompleter'])
+        self.on_tab_size_change(val=self.app.defaults['document_tab_size'])
+
+        flt = "FlatCAM Docs (*.FlatDoc);;All Files (*.*)"
+
+        # ######################################################################
+        # ######################## SIGNALS #####################################
+        # ######################################################################
+        self.document_editor_tab.buttonOpen.clicked.disconnect()
+        self.document_editor_tab.buttonOpen.clicked.connect(lambda: self.document_editor_tab.handleOpen(filt=flt))
+        self.document_editor_tab.buttonSave.clicked.disconnect()
+        self.document_editor_tab.buttonSave.clicked.connect(lambda: self.document_editor_tab.handleSaveGCode(filt=flt))
+
+        self.document_editor_tab.code_editor.textChanged.connect(self.on_text_changed)
+
+        self.ui.font_type_cb.currentFontChanged.connect(self.font_family)
+        self.ui.font_size_cb.activated.connect(self.font_size)
+        self.ui.font_bold_tb.clicked.connect(self.on_bold_button)
+        self.ui.font_italic_tb.clicked.connect(self.on_italic_button)
+        self.ui.font_under_tb.clicked.connect(self.on_underline_button)
+
+        self.ui.font_color_entry.editingFinished.connect(self.on_font_color_entry)
+        self.ui.font_color_button.clicked.connect(self.on_font_color_button)
+        self.ui.sel_color_entry.editingFinished.connect(self.on_selection_color_entry)
+        self.ui.sel_color_button.clicked.connect(self.on_selection_color_button)
+
+        self.ui.al_left_tb.clicked.connect(lambda: self.document_editor_tab.code_editor.setAlignment(Qt.AlignLeft))
+        self.ui.al_center_tb.clicked.connect(lambda: self.document_editor_tab.code_editor.setAlignment(Qt.AlignCenter))
+        self.ui.al_right_tb.clicked.connect(lambda: self.document_editor_tab.code_editor.setAlignment(Qt.AlignRight))
+        self.ui.al_justify_tb.clicked.connect(
+            lambda: self.document_editor_tab.code_editor.setAlignment(Qt.AlignJustify)
+        )
+
+        self.ui.autocomplete_cb.stateChanged.connect(self.on_autocomplete_changed)
+        self.ui.tab_size_spinner.returnPressed.connect(self.on_tab_size_change)
+        # #######################################################################
+
+        self.ui.font_color_entry.set_value(self.app.defaults['document_font_color'])
+        self.ui.font_color_button.setStyleSheet(
+            "background-color:%s" % str(self.app.defaults['document_font_color']))
+
+        self.ui.sel_color_entry.set_value(self.app.defaults['document_sel_color'])
+        self.ui.sel_color_button.setStyleSheet(
+            "background-color:%s" % self.app.defaults['document_sel_color'])
+
+        self.ui.font_size_cb.setCurrentIndex(int(self.app.defaults['document_font_size']))
+
+        self.document_editor_tab.handleTextChanged()
+        self.ser_attrs = ['options', 'kind', 'source_file']
+
+        if Qt.mightBeRichText(self.source_file):
+            self.document_editor_tab.code_editor.setHtml(self.source_file)
+        else:
+            for line in self.source_file.splitlines():
+                self.document_editor_tab.code_editor.append(line)
+
+        self.build_ui()
+
+    @property
+    def read_only(self):
+        return self._read_only
+
+    @read_only.setter
+    def read_only(self, val):
+        if val:
+            self._read_only = True
+        else:
+            self._read_only = False
+
+    def build_ui(self):
+        FlatCAMObj.build_ui(self)
+        tab_here = False
+
+        # try to not add too many times a tab that it is already installed
+        for idx in range(self.app.ui.plot_tab_area.count()):
+            if self.app.ui.plot_tab_area.widget(idx).objectName() == self.options['name']:
+                tab_here = True
+                break
+
+        # add the tab if it is not already added
+        if tab_here is False:
+            self.app.ui.plot_tab_area.addTab(self.document_editor_tab, '%s' % _("Document Editor"))
+            self.document_editor_tab.setObjectName(self.options['name'])
+
+        # Switch plot_area to CNCJob tab
+        self.app.ui.plot_tab_area.setCurrentWidget(self.document_editor_tab)
+
+    def on_autocomplete_changed(self, state):
+        if state:
+            self.document_editor_tab.code_editor.completer_enable = True
+        else:
+            self.document_editor_tab.code_editor.completer_enable = False
+
+    def on_tab_size_change(self, val=None):
+        try:
+            self.ui.tab_size_spinner.returnPressed.disconnect(self.on_tab_size_change)
+        except TypeError:
+            pass
+
+        if val:
+            self.ui.tab_size_spinner.set_value(val)
+
+        tab_balue = int(self.ui.tab_size_spinner.get_value())
+        self.document_editor_tab.code_editor.setTabStopWidth(tab_balue)
+        self.app.defaults['document_tab_size'] = tab_balue
+
+        self.ui.tab_size_spinner.returnPressed.connect(self.on_tab_size_change)
+
+    def on_text_changed(self):
+        self.source_file = self.document_editor_tab.code_editor.toHtml()
+        # print(self.source_file)
+
+    def font_family(self, font):
+        # self.document_editor_tab.code_editor.selectAll()
+        font.setPointSize(float(self.ui.font_size_cb.get_value()))
+        self.document_editor_tab.code_editor.setCurrentFont(font)
+        self.font_name = self.ui.font_type_cb.currentFont().family()
+
+    def font_size(self):
+        # self.document_editor_tab.code_editor.selectAll()
+        self.document_editor_tab.code_editor.setFontPointSize(float(self.ui.font_size_cb.get_value()))
+
+    def on_bold_button(self):
+        if self.ui.font_bold_tb.isChecked():
+            self.document_editor_tab.code_editor.setFontWeight(QtGui.QFont.Bold)
+            self.font_bold = True
+        else:
+            self.document_editor_tab.code_editor.setFontWeight(QtGui.QFont.Normal)
+            self.font_bold = False
+
+    def on_italic_button(self):
+        if self.ui.font_italic_tb.isChecked():
+            self.document_editor_tab.code_editor.setFontItalic(True)
+            self.font_italic = True
+        else:
+            self.document_editor_tab.code_editor.setFontItalic(False)
+            self.font_italic = False
+
+    def on_underline_button(self):
+        if self.ui.font_under_tb.isChecked():
+            self.document_editor_tab.code_editor.setFontUnderline(True)
+            self.font_underline = True
+        else:
+            self.document_editor_tab.code_editor.setFontUnderline(False)
+            self.font_underline = False
+
+    # Setting font colors handlers
+    def on_font_color_entry(self):
+        self.app.defaults['document_font_color'] = self.ui.font_color_entry.get_value()
+        self.ui.font_color_button.setStyleSheet("background-color:%s" % str(self.app.defaults['document_font_color']))
+
+    def on_font_color_button(self):
+        current_color = QtGui.QColor(self.app.defaults['document_font_color'])
+
+        c_dialog = QtWidgets.QColorDialog()
+        font_color = c_dialog.getColor(initial=current_color)
+
+        if font_color.isValid() is False:
+            return
+
+        self.document_editor_tab.code_editor.setTextColor(font_color)
+        self.ui.font_color_button.setStyleSheet("background-color:%s" % str(font_color.name()))
+
+        new_val = str(font_color.name())
+        self.ui.font_color_entry.set_value(new_val)
+        self.app.defaults['document_font_color'] = new_val
+
+    # Setting selection colors handlers
+    def on_selection_color_entry(self):
+        self.app.defaults['document_sel_color'] = self.ui.sel_color_entry.get_value()
+        self.ui.sel_color_button.setStyleSheet("background-color:%s" % str(self.app.defaults['document_sel_color']))
+
+    def on_selection_color_button(self):
+        current_color = QtGui.QColor(self.app.defaults['document_sel_color'])
+
+        c_dialog = QtWidgets.QColorDialog()
+        sel_color = c_dialog.getColor(initial=current_color)
+
+        if sel_color.isValid() is False:
+            return
+
+        p = QtGui.QPalette()
+        p.setColor(QtGui.QPalette.Highlight, sel_color)
+        p.setColor(QtGui.QPalette.HighlightedText, QtGui.QColor('white'))
+
+        self.document_editor_tab.code_editor.setPalette(p)
+
+        self.ui.sel_color_button.setStyleSheet("background-color:%s" % str(sel_color.name()))
+
+        new_val = str(sel_color.name())
+        self.ui.sel_color_entry.set_value(new_val)
+        self.app.defaults['document_sel_color'] = new_val
+
+    def to_dict(self):
+        """
+        Returns a representation of the object as a dictionary.
+        Attributes to include are listed in ``self.ser_attrs``.
+
+        :return: A dictionary-encoded copy of the object.
+        :rtype: dict
+        """
+        d = {}
+        for attr in self.ser_attrs:
+            d[attr] = getattr(self, attr)
+        return d
+
+    def from_dict(self, d):
+        """
+        Sets object's attributes from a dictionary.
+        Attributes to include are listed in ``self.ser_attrs``.
+        This method will look only for only and all the
+        attributes in ``self.ser_attrs``. They must all
+        be present. Use only for deserializing saved
+        objects.
+
+        :param d: Dictionary of attributes to set in the object.
+        :type d: dict
+        :return: None
+        """
+        for attr in self.ser_attrs:
+            setattr(self, attr, d[attr])

+ 1622 - 0
flatcamObjects/FlatCAMExcellon.py

@@ -0,0 +1,1622 @@
+# ##########################################################
+# FlatCAM: 2D Post-processing for Manufacturing            #
+# http://flatcam.org                                       #
+# Author: Juan Pablo Caram (c)                             #
+# Date: 2/5/2014                                           #
+# MIT Licence                                              #
+# ##########################################################
+
+# ##########################################################
+# File modified by: Marius Stanciu                         #
+# ##########################################################
+
+
+from shapely.geometry import Point, LineString
+
+from copy import deepcopy
+
+from flatcamParsers.ParseExcellon import Excellon
+from flatcamObjects.FlatCAMObj import *
+
+import itertools
+
+import gettext
+import FlatCAMTranslation as fcTranslate
+import builtins
+
+fcTranslate.apply_language('strings')
+if '_' not in builtins.__dict__:
+    _ = gettext.gettext
+
+
+class ExcellonObject(FlatCAMObj, Excellon):
+    """
+    Represents Excellon/Drill code.
+    """
+
+    ui_type = ExcellonObjectUI
+    optionChanged = QtCore.pyqtSignal(str)
+
+    def __init__(self, name):
+        self.decimals = self.app.decimals
+
+        self.circle_steps = int(self.app.defaults["geometry_circle_steps"])
+
+        Excellon.__init__(self, geo_steps_per_circle=self.circle_steps)
+        FlatCAMObj.__init__(self, name)
+
+        self.kind = "excellon"
+
+        self.options.update({
+            "plot": True,
+            "solid": False,
+
+            "operation": "drill",
+            "milling_type": "drills",
+
+            "milling_dia": 0.04,
+
+            "cutz": -0.1,
+            "multidepth": False,
+            "depthperpass": 0.7,
+            "travelz": 0.1,
+            "feedrate": self.app.defaults["geometry_feedrate"],
+            "feedrate_z": 5.0,
+            "feedrate_rapid": 5.0,
+            "tooldia": 0.1,
+            "slot_tooldia": 0.1,
+            "toolchange": False,
+            "toolchangez": 1.0,
+            "toolchangexy": "0.0, 0.0",
+            "extracut": self.app.defaults["geometry_extracut"],
+            "extracut_length": self.app.defaults["geometry_extracut_length"],
+            "endz": 2.0,
+            "endxy": '',
+
+            "startz": None,
+            "offset": 0.0,
+            "spindlespeed": 0,
+            "dwell": True,
+            "dwelltime": 1000,
+            "ppname_e": 'default',
+            "ppname_g": self.app.defaults["geometry_ppname_g"],
+            "z_pdepth": -0.02,
+            "feedrate_probe": 3.0,
+            "optimization_type": "B",
+        })
+
+        # TODO: Document this.
+        self.tool_cbs = {}
+
+        # dict that holds the object names and the option name
+        # the key is the object name (defines in ObjectUI) for each UI element that is a parameter
+        # particular for a tool and the value is the actual name of the option that the UI element is changing
+        self.name2option = {}
+
+        # default set of data to be added to each tool in self.tools as self.tools[tool]['data'] = self.default_data
+        self.default_data = {}
+
+        # fill in self.default_data values from self.options
+        for opt_key, opt_val in self.app.options.items():
+            if opt_key.find('excellon_') == 0:
+                self.default_data[opt_key] = deepcopy(opt_val)
+        for opt_key, opt_val in self.app.options.items():
+            if opt_key.find('geometry_') == 0:
+                self.default_data[opt_key] = deepcopy(opt_val)
+
+        # variable to store the total amount of drills per job
+        self.tot_drill_cnt = 0
+        self.tool_row = 0
+
+        # variable to store the total amount of slots per job
+        self.tot_slot_cnt = 0
+        self.tool_row_slots = 0
+
+        # variable to store the distance travelled
+        self.travel_distance = 0.0
+
+        # store the source file here
+        self.source_file = ""
+
+        self.multigeo = False
+        self.units_found = self.app.defaults['units']
+
+        self.fill_color = self.app.defaults['excellon_plot_fill']
+        self.outline_color = self.app.defaults['excellon_plot_line']
+        self.alpha_level = 'bf'
+
+        # Attributes to be included in serialization
+        # Always append to it because it carries contents
+        # from predecessors.
+        self.ser_attrs += ['options', 'kind']
+
+    def merge(self, exc_list, exc_final):
+        """
+        Merge Excellon objects found in exc_list parameter into exc_final object.
+        Options are always copied from source .
+
+        Tools are disregarded, what is taken in consideration is the unique drill diameters found as values in the
+        exc_list tools dict's. In the reconstruction section for each unique tool diameter it will be created a
+        tool_name to be used in the final Excellon object, exc_final.
+
+        If only one object is in exc_list parameter then this function will copy that object in the exc_final
+
+        :param exc_list: List or one object of ExcellonObject Objects to join.
+        :param exc_final: Destination ExcellonObject object.
+        :return: None
+        """
+
+        try:
+            decimals_exc = self.decimals
+        except AttributeError:
+            decimals_exc = 4
+
+        # flag to signal that we need to reorder the tools dictionary and drills and slots lists
+        flag_order = False
+
+        try:
+            flattened_list = list(itertools.chain(*exc_list))
+        except TypeError:
+            flattened_list = exc_list
+
+        # this dict will hold the unique tool diameters found in the exc_list objects as the dict keys and the dict
+        # values will be list of Shapely Points; for drills
+        custom_dict_drills = {}
+
+        # this dict will hold the unique tool diameters found in the exc_list objects as the dict keys and the dict
+        # values will be list of Shapely Points; for slots
+        custom_dict_slots = {}
+
+        for exc in flattened_list:
+            # copy options of the current excellon obj to the final excellon obj
+            for option in exc.options:
+                if option != 'name':
+                    try:
+                        exc_final.options[option] = exc.options[option]
+                    except Exception:
+                        exc.app.log.warning("Failed to copy option.", option)
+
+            for drill in exc.drills:
+                exc_tool_dia = float('%.*f' % (decimals_exc, exc.tools[drill['tool']]['C']))
+
+                if exc_tool_dia not in custom_dict_drills:
+                    custom_dict_drills[exc_tool_dia] = [drill['point']]
+                else:
+                    custom_dict_drills[exc_tool_dia].append(drill['point'])
+
+            for slot in exc.slots:
+                exc_tool_dia = float('%.*f' % (decimals_exc, exc.tools[slot['tool']]['C']))
+
+                if exc_tool_dia not in custom_dict_slots:
+                    custom_dict_slots[exc_tool_dia] = [[slot['start'], slot['stop']]]
+                else:
+                    custom_dict_slots[exc_tool_dia].append([slot['start'], slot['stop']])
+
+            # add the zeros and units to the exc_final object
+            exc_final.zeros = exc.zeros
+            exc_final.units = exc.units
+
+        # ##########################################
+        # Here we add data to the exc_final object #
+        # ##########################################
+
+        # variable to make tool_name for the tools
+        current_tool = 0
+        # The tools diameter are now the keys in the drill_dia dict and the values are the Shapely Points in case of
+        # drills
+        for tool_dia in custom_dict_drills:
+            # we create a tool name for each key in the drill_dia dict (the key is a unique drill diameter)
+            current_tool += 1
+
+            tool_name = str(current_tool)
+            spec = {"C": float(tool_dia)}
+            exc_final.tools[tool_name] = spec
+
+            # rebuild the drills list of dict's that belong to the exc_final object
+            for point in custom_dict_drills[tool_dia]:
+                exc_final.drills.append(
+                    {
+                        "point": point,
+                        "tool": str(current_tool)
+                    }
+                )
+
+        # The tools diameter are now the keys in the drill_dia dict and the values are a list ([start, stop])
+        # of two Shapely Points in case of slots
+        for tool_dia in custom_dict_slots:
+            # we create a tool name for each key in the slot_dia dict (the key is a unique slot diameter)
+            # but only if there are no drills
+            if not exc_final.tools:
+                current_tool += 1
+                tool_name = str(current_tool)
+                spec = {"C": float(tool_dia)}
+                exc_final.tools[tool_name] = spec
+            else:
+                dia_list = []
+                for v in exc_final.tools.values():
+                    dia_list.append(float(v["C"]))
+
+                if tool_dia not in dia_list:
+                    flag_order = True
+
+                    current_tool = len(dia_list) + 1
+                    tool_name = str(current_tool)
+                    spec = {"C": float(tool_dia)}
+                    exc_final.tools[tool_name] = spec
+
+                else:
+                    for k, v in exc_final.tools.items():
+                        if v["C"] == tool_dia:
+                            current_tool = int(k)
+                            break
+
+            # rebuild the slots list of dict's that belong to the exc_final object
+            for point in custom_dict_slots[tool_dia]:
+                exc_final.slots.append(
+                    {
+                        "start": point[0],
+                        "stop": point[1],
+                        "tool": str(current_tool)
+                    }
+                )
+
+        # flag_order == True means that there was an slot diameter not in the tools and we also have drills
+        # and the new tool was added to self.tools therefore we need to reorder the tools and drills and slots
+        current_tool = 0
+        if flag_order is True:
+            dia_list = []
+            temp_drills = []
+            temp_slots = []
+            temp_tools = {}
+            for v in exc_final.tools.values():
+                dia_list.append(float(v["C"]))
+            dia_list.sort()
+            for ordered_dia in dia_list:
+                current_tool += 1
+                tool_name_temp = str(current_tool)
+                spec_temp = {"C": float(ordered_dia)}
+                temp_tools[tool_name_temp] = spec_temp
+
+                for drill in exc_final.drills:
+                    exc_tool_dia = float('%.*f' % (decimals_exc, exc_final.tools[drill['tool']]['C']))
+                    if exc_tool_dia == ordered_dia:
+                        temp_drills.append(
+                            {
+                                "point": drill["point"],
+                                "tool": str(current_tool)
+                            }
+                        )
+
+                for slot in exc_final.slots:
+                    slot_tool_dia = float('%.*f' % (decimals_exc, exc_final.tools[slot['tool']]['C']))
+                    if slot_tool_dia == ordered_dia:
+                        temp_slots.append(
+                            {
+                                "start": slot["start"],
+                                "stop": slot["stop"],
+                                "tool": str(current_tool)
+                            }
+                        )
+
+            # delete the exc_final tools, drills and slots
+            exc_final.tools = {}
+            exc_final.drills[:] = []
+            exc_final.slots[:] = []
+
+            # update the exc_final tools, drills and slots with the ordered values
+            exc_final.tools = temp_tools
+            exc_final.drills[:] = temp_drills
+            exc_final.slots[:] = temp_slots
+
+        # create the geometry for the exc_final object
+        exc_final.create_geometry()
+
+    def build_ui(self):
+        FlatCAMObj.build_ui(self)
+
+        self.units = self.app.defaults['units'].upper()
+
+        for row in range(self.ui.tools_table.rowCount()):
+            try:
+                # if connected, disconnect the signal from the slot on item_changed as it creates issues
+                offset_spin_widget = self.ui.tools_table.cellWidget(row, 4)
+                offset_spin_widget.valueChanged.disconnect()
+            except (TypeError, AttributeError):
+                pass
+
+        n = len(self.tools)
+        # we have (n+2) rows because there are 'n' tools, each a row, plus the last 2 rows for totals.
+        self.ui.tools_table.setRowCount(n + 2)
+
+        self.tot_drill_cnt = 0
+        self.tot_slot_cnt = 0
+
+        self.tool_row = 0
+
+        sort = []
+        for k, v in list(self.tools.items()):
+            sort.append((k, v.get('C')))
+        sorted_tools = sorted(sort, key=lambda t1: t1[1])
+        tools = [i[0] for i in sorted_tools]
+
+        new_options = {}
+        for opt in self.options:
+            new_options[opt] = self.options[opt]
+
+        for tool_no in tools:
+
+            # add the data dictionary for each tool with the default values
+            self.tools[tool_no]['data'] = deepcopy(new_options)
+            # self.tools[tool_no]['data']["tooldia"] = self.tools[tool_no]["C"]
+            # self.tools[tool_no]['data']["slot_tooldia"] = self.tools[tool_no]["C"]
+
+            drill_cnt = 0  # variable to store the nr of drills per tool
+            slot_cnt = 0  # variable to store the nr of slots per tool
+
+            # Find no of drills for the current tool
+            for drill in self.drills:
+                if drill['tool'] == tool_no:
+                    drill_cnt += 1
+
+            self.tot_drill_cnt += drill_cnt
+
+            # Find no of slots for the current tool
+            for slot in self.slots:
+                if slot['tool'] == tool_no:
+                    slot_cnt += 1
+
+            self.tot_slot_cnt += slot_cnt
+
+            exc_id_item = QtWidgets.QTableWidgetItem('%d' % int(tool_no))
+            exc_id_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
+
+            dia_item = QtWidgets.QTableWidgetItem('%.*f' % (self.decimals, self.tools[tool_no]['C']))
+            dia_item.setFlags(QtCore.Qt.ItemIsEnabled)
+
+            drill_count_item = QtWidgets.QTableWidgetItem('%d' % drill_cnt)
+            drill_count_item.setFlags(QtCore.Qt.ItemIsEnabled)
+
+            # if the slot number is zero is better to not clutter the GUI with zero's so we print a space
+            slot_count_str = '%d' % slot_cnt if slot_cnt > 0 else ''
+            slot_count_item = QtWidgets.QTableWidgetItem(slot_count_str)
+            slot_count_item.setFlags(QtCore.Qt.ItemIsEnabled)
+
+            plot_item = FCCheckBox()
+            plot_item.setLayoutDirection(QtCore.Qt.RightToLeft)
+            if self.ui.plot_cb.isChecked():
+                plot_item.setChecked(True)
+
+            self.ui.tools_table.setItem(self.tool_row, 0, exc_id_item)  # Tool name/id
+            self.ui.tools_table.setItem(self.tool_row, 1, dia_item)  # Diameter
+            self.ui.tools_table.setItem(self.tool_row, 2, drill_count_item)  # Number of drills per tool
+            self.ui.tools_table.setItem(self.tool_row, 3, slot_count_item)  # Number of drills per tool
+            empty_plot_item = QtWidgets.QTableWidgetItem('')
+            empty_plot_item.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
+            self.ui.tools_table.setItem(self.tool_row, 5, empty_plot_item)
+            self.ui.tools_table.setCellWidget(self.tool_row, 5, plot_item)
+
+            self.tool_row += 1
+
+        # add a last row with the Total number of drills
+        empty_1 = QtWidgets.QTableWidgetItem('')
+        empty_1.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
+        empty_1_1 = QtWidgets.QTableWidgetItem('')
+        empty_1_1.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
+        empty_1_2 = QtWidgets.QTableWidgetItem('')
+        empty_1_2.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
+        empty_1_3 = QtWidgets.QTableWidgetItem('')
+        empty_1_3.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
+
+        label_tot_drill_count = QtWidgets.QTableWidgetItem(_('Total Drills'))
+        tot_drill_count = QtWidgets.QTableWidgetItem('%d' % self.tot_drill_cnt)
+        label_tot_drill_count.setFlags(QtCore.Qt.ItemIsEnabled)
+        tot_drill_count.setFlags(QtCore.Qt.ItemIsEnabled)
+
+        self.ui.tools_table.setItem(self.tool_row, 0, empty_1)
+        self.ui.tools_table.setItem(self.tool_row, 1, label_tot_drill_count)
+        self.ui.tools_table.setItem(self.tool_row, 2, tot_drill_count)  # Total number of drills
+        self.ui.tools_table.setItem(self.tool_row, 3, empty_1_1)
+        self.ui.tools_table.setItem(self.tool_row, 5, empty_1_3)
+
+        font = QtGui.QFont()
+        font.setBold(True)
+        font.setWeight(75)
+
+        for k in [1, 2]:
+            self.ui.tools_table.item(self.tool_row, k).setForeground(QtGui.QColor(127, 0, 255))
+            self.ui.tools_table.item(self.tool_row, k).setFont(font)
+
+        self.tool_row += 1
+
+        # add a last row with the Total number of slots
+        empty_2 = QtWidgets.QTableWidgetItem('')
+        empty_2.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
+        empty_2_1 = QtWidgets.QTableWidgetItem('')
+        empty_2_1.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
+        empty_2_2 = QtWidgets.QTableWidgetItem('')
+        empty_2_2.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
+        empty_2_3 = QtWidgets.QTableWidgetItem('')
+        empty_2_3.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
+
+        label_tot_slot_count = QtWidgets.QTableWidgetItem(_('Total Slots'))
+        tot_slot_count = QtWidgets.QTableWidgetItem('%d' % self.tot_slot_cnt)
+        label_tot_slot_count.setFlags(QtCore.Qt.ItemIsEnabled)
+        tot_slot_count.setFlags(QtCore.Qt.ItemIsEnabled)
+
+        self.ui.tools_table.setItem(self.tool_row, 0, empty_2)
+        self.ui.tools_table.setItem(self.tool_row, 1, label_tot_slot_count)
+        self.ui.tools_table.setItem(self.tool_row, 2, empty_2_1)
+        self.ui.tools_table.setItem(self.tool_row, 3, tot_slot_count)  # Total number of slots
+        self.ui.tools_table.setItem(self.tool_row, 5, empty_2_3)
+
+        for kl in [1, 2, 3]:
+            self.ui.tools_table.item(self.tool_row, kl).setFont(font)
+            self.ui.tools_table.item(self.tool_row, kl).setForeground(QtGui.QColor(0, 70, 255))
+
+        # sort the tool diameter column
+        # self.ui.tools_table.sortItems(1)
+
+        # all the tools are selected by default
+        self.ui.tools_table.selectColumn(0)
+
+        self.ui.tools_table.resizeColumnsToContents()
+        self.ui.tools_table.resizeRowsToContents()
+
+        vertical_header = self.ui.tools_table.verticalHeader()
+        # vertical_header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
+        vertical_header.hide()
+        self.ui.tools_table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
+
+        horizontal_header = self.ui.tools_table.horizontalHeader()
+        horizontal_header.setMinimumSectionSize(10)
+        horizontal_header.setDefaultSectionSize(70)
+        horizontal_header.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
+        horizontal_header.resizeSection(0, 20)
+
+        horizontal_header.setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
+
+        horizontal_header.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
+        horizontal_header.setSectionResizeMode(3, QtWidgets.QHeaderView.ResizeToContents)
+        horizontal_header.setSectionResizeMode(5, QtWidgets.QHeaderView.Fixed)
+        horizontal_header.resizeSection(5, 17)
+        self.ui.tools_table.setColumnWidth(5, 17)
+
+        # horizontal_header.setStretchLastSection(True)
+        # horizontal_header.setColumnWidth(2, QtWidgets.QHeaderView.ResizeToContents)
+
+        # horizontal_header.setStretchLastSection(True)
+        self.ui.tools_table.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
+
+        self.ui.tools_table.setSortingEnabled(False)
+
+        self.ui.tools_table.setMinimumHeight(self.ui.tools_table.getHeight())
+        self.ui.tools_table.setMaximumHeight(self.ui.tools_table.getHeight())
+
+        if not self.drills:
+            self.ui.tooldia_entry.hide()
+            self.ui.generate_milling_button.hide()
+        else:
+            self.ui.tooldia_entry.show()
+            self.ui.generate_milling_button.show()
+
+        if not self.slots:
+            self.ui.slot_tooldia_entry.hide()
+            self.ui.generate_milling_slots_button.hide()
+        else:
+            self.ui.slot_tooldia_entry.show()
+            self.ui.generate_milling_slots_button.show()
+
+        # set the text on tool_data_label after loading the object
+        sel_items = self.ui.tools_table.selectedItems()
+        sel_rows = [it.row() for it in sel_items]
+        if len(sel_rows) > 1:
+            self.ui.tool_data_label.setText(
+                "<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("Multiple Tools"))
+            )
+
+        self.ui_connect()
+
+    def set_ui(self, ui):
+        """
+        Configures the user interface for this object.
+        Connects options to form fields.
+
+        :param ui: User interface object.
+        :type ui: ExcellonObjectUI
+        :return: None
+        """
+        FlatCAMObj.set_ui(self, ui)
+
+        log.debug("ExcellonObject.set_ui()")
+
+        self.units = self.app.defaults['units'].upper()
+
+        self.form_fields.update({
+            "plot": self.ui.plot_cb,
+            "solid": self.ui.solid_cb,
+
+            "operation": self.ui.operation_radio,
+            "milling_type": self.ui.milling_type_radio,
+
+            "milling_dia": self.ui.mill_dia_entry,
+            "cutz": self.ui.cutz_entry,
+            "multidepth": self.ui.mpass_cb,
+            "depthperpass": self.ui.maxdepth_entry,
+            "travelz": self.ui.travelz_entry,
+            "feedrate_z": self.ui.feedrate_z_entry,
+            "feedrate": self.ui.xyfeedrate_entry,
+            "feedrate_rapid": self.ui.feedrate_rapid_entry,
+            "tooldia": self.ui.tooldia_entry,
+            "slot_tooldia": self.ui.slot_tooldia_entry,
+            "toolchange": self.ui.toolchange_cb,
+            "toolchangez": self.ui.toolchangez_entry,
+            "extracut": self.ui.extracut_cb,
+            "extracut_length": self.ui.e_cut_entry,
+
+            "spindlespeed": self.ui.spindlespeed_entry,
+            "dwell": self.ui.dwell_cb,
+            "dwelltime": self.ui.dwelltime_entry,
+
+            "startz": self.ui.estartz_entry,
+            "endz": self.ui.endz_entry,
+            "endxy": self.ui.endxy_entry,
+
+            "offset": self.ui.offset_entry,
+
+            "ppname_e": self.ui.pp_excellon_name_cb,
+            "ppname_g": self.ui.pp_geo_name_cb,
+            "z_pdepth": self.ui.pdepth_entry,
+            "feedrate_probe": self.ui.feedrate_probe_entry,
+            # "gcode_type": self.ui.excellon_gcode_type_radio
+        })
+
+        self.name2option = {
+            "e_operation": "operation",
+            "e_milling_type": "milling_type",
+            "e_milling_dia": "milling_dia",
+            "e_cutz": "cutz",
+            "e_multidepth": "multidepth",
+            "e_depthperpass": "depthperpass",
+
+            "e_travelz": "travelz",
+            "e_feedratexy": "feedrate",
+            "e_feedratez": "feedrate_z",
+            "e_fr_rapid": "feedrate_rapid",
+            "e_extracut": "extracut",
+            "e_extracut_length": "extracut_length",
+            "e_spindlespeed": "spindlespeed",
+            "e_dwell": "dwell",
+            "e_dwelltime": "dwelltime",
+            "e_offset": "offset",
+        }
+
+        # populate Excellon preprocessor combobox list
+        for name in list(self.app.preprocessors.keys()):
+            # the HPGL preprocessor is only for Geometry not for Excellon job therefore don't add it
+            if name == 'hpgl':
+                continue
+            self.ui.pp_excellon_name_cb.addItem(name)
+
+        # populate Geometry (milling) preprocessor combobox list
+        for name in list(self.app.preprocessors.keys()):
+            self.ui.pp_geo_name_cb.addItem(name)
+
+        # Fill form fields
+        self.to_form()
+
+        # update the changes in UI depending on the selected preprocessor in Preferences
+        # after this moment all the changes in the Posprocessor combo will be handled by the activated signal of the
+        # self.ui.pp_excellon_name_cb combobox
+        self.on_pp_changed()
+
+        # Show/Hide Advanced Options
+        if self.app.defaults["global_app_level"] == 'b':
+            self.ui.level.setText('<span style="color:green;"><b>%s</b></span>' % _('Basic'))
+
+            self.ui.tools_table.setColumnHidden(4, True)
+            self.ui.tools_table.setColumnHidden(5, True)
+            self.ui.estartz_label.hide()
+            self.ui.estartz_entry.hide()
+            self.ui.feedrate_rapid_label.hide()
+            self.ui.feedrate_rapid_entry.hide()
+            self.ui.pdepth_label.hide()
+            self.ui.pdepth_entry.hide()
+            self.ui.feedrate_probe_label.hide()
+            self.ui.feedrate_probe_entry.hide()
+        else:
+            self.ui.level.setText('<span style="color:red;"><b>%s</b></span>' % _('Advanced'))
+
+        assert isinstance(self.ui, ExcellonObjectUI), \
+            "Expected a ExcellonObjectUI, got %s" % type(self.ui)
+        self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
+        self.ui.solid_cb.stateChanged.connect(self.on_solid_cb_click)
+        self.ui.generate_cnc_button.clicked.connect(self.on_create_cncjob_button_click)
+        self.ui.generate_milling_button.clicked.connect(self.on_generate_milling_button_click)
+        self.ui.generate_milling_slots_button.clicked.connect(self.on_generate_milling_slots_button_click)
+
+        self.on_operation_type(val='drill')
+        self.ui.operation_radio.activated_custom.connect(self.on_operation_type)
+
+        self.ui.pp_excellon_name_cb.activated.connect(self.on_pp_changed)
+
+        self.ui.apply_param_to_all.clicked.connect(self.on_apply_param_to_all_clicked)
+
+        self.units_found = self.app.defaults['units']
+
+        # ########################################
+        # #######3 TEMP SETTINGS #################
+        # ########################################
+        self.ui.operation_radio.set_value("drill")
+        self.ui.operation_radio.setEnabled(False)
+
+    def ui_connect(self):
+
+        # selective plotting
+        for row in range(self.ui.tools_table.rowCount() - 2):
+            self.ui.tools_table.cellWidget(row, 5).clicked.connect(self.on_plot_cb_click_table)
+        self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
+
+        # rows selected
+        self.ui.tools_table.clicked.connect(self.on_row_selection_change)
+        self.ui.tools_table.horizontalHeader().sectionClicked.connect(self.on_row_selection_change)
+
+        # value changed in the particular parameters of a tool
+        for key, option in self.name2option.items():
+            current_widget = self.form_fields[option]
+
+            if isinstance(current_widget, FCCheckBox):
+                current_widget.stateChanged.connect(self.form_to_storage)
+            if isinstance(current_widget, RadioSet):
+                current_widget.activated_custom.connect(self.form_to_storage)
+            elif isinstance(current_widget, FCDoubleSpinner) or isinstance(current_widget, FCSpinner):
+                current_widget.returnPressed.connect(self.form_to_storage)
+
+    def ui_disconnect(self):
+        # selective plotting
+        for row in range(self.ui.tools_table.rowCount()):
+            try:
+                self.ui.tools_table.cellWidget(row, 5).clicked.disconnect()
+            except (TypeError, AttributeError):
+                pass
+        try:
+            self.ui.plot_cb.stateChanged.disconnect()
+        except (TypeError, AttributeError):
+            pass
+
+        # rows selected
+        try:
+            self.ui.tools_table.clicked.disconnect()
+        except (TypeError, AttributeError):
+            pass
+        try:
+            self.ui.tools_table.horizontalHeader().sectionClicked.disconnect()
+        except (TypeError, AttributeError):
+            pass
+
+        # value changed in the particular parameters of a tool
+        for key, option in self.name2option.items():
+            current_widget = self.form_fields[option]
+
+            if isinstance(current_widget, FCCheckBox):
+                try:
+                    current_widget.stateChanged.disconnect(self.form_to_storage)
+                except (TypeError, ValueError):
+                    pass
+            if isinstance(current_widget, RadioSet):
+                try:
+                    current_widget.activated_custom.disconnect(self.form_to_storage)
+                except (TypeError, ValueError):
+                    pass
+            elif isinstance(current_widget, FCDoubleSpinner) or isinstance(current_widget, FCSpinner):
+                try:
+                    current_widget.returnPressed.disconnect(self.form_to_storage)
+                except (TypeError, ValueError):
+                    pass
+
+    def on_row_selection_change(self):
+        self.ui_disconnect()
+
+        sel_rows = []
+        sel_items = self.ui.tools_table.selectedItems()
+        for it in sel_items:
+            sel_rows.append(it.row())
+
+        if not sel_rows:
+            self.ui.tool_data_label.setText(
+                "<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("No Tool Selected"))
+            )
+            self.ui.generate_cnc_button.setDisabled(True)
+            self.ui.generate_milling_button.setDisabled(True)
+            self.ui.generate_milling_slots_button.setDisabled(True)
+            self.ui_connect()
+            return
+        else:
+            self.ui.generate_cnc_button.setDisabled(False)
+            self.ui.generate_milling_button.setDisabled(False)
+            self.ui.generate_milling_slots_button.setDisabled(False)
+
+        if len(sel_rows) == 1:
+            # update the QLabel that shows for which Tool we have the parameters in the UI form
+            tooluid = int(self.ui.tools_table.item(sel_rows[0], 0).text())
+            self.ui.tool_data_label.setText(
+                "<b>%s: <font color='#0000FF'>%s %d</font></b>" % (_('Parameters for'), _("Tool"), tooluid)
+            )
+        else:
+            self.ui.tool_data_label.setText(
+                "<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("Multiple Tools"))
+            )
+
+        for c_row in sel_rows:
+            # populate the form with the data from the tool associated with the row parameter
+            try:
+                item = self.ui.tools_table.item(c_row, 0)
+                if type(item) is not None:
+                    tooluid = item.text()
+                    self.storage_to_form(self.tools[str(tooluid)]['data'])
+                else:
+                    self.ui_connect()
+                    return
+            except Exception as e:
+                log.debug("Tool missing. Add a tool in Geo Tool Table. %s" % str(e))
+                self.ui_connect()
+                return
+
+        self.ui_connect()
+
+    def storage_to_form(self, dict_storage):
+        for form_key in self.form_fields:
+            for storage_key in dict_storage:
+                if form_key == storage_key and form_key not in \
+                        ["toolchange", "toolchangez", "startz", "endz", "ppname_e", "ppname_g"]:
+                    try:
+                        self.form_fields[form_key].set_value(dict_storage[form_key])
+                    except Exception as e:
+                        log.debug("ExcellonObject.storage_to_form() --> %s" % str(e))
+                        pass
+
+    def form_to_storage(self):
+        if self.ui.tools_table.rowCount() == 0:
+            # there is no tool in tool table so we can't save the GUI elements values to storage
+            return
+
+        self.ui_disconnect()
+
+        widget_changed = self.sender()
+        wdg_objname = widget_changed.objectName()
+        option_changed = self.name2option[wdg_objname]
+
+        # row = self.ui.tools_table.currentRow()
+        rows = sorted(set(index.row() for index in self.ui.tools_table.selectedIndexes()))
+        for row in rows:
+            if row < 0:
+                row = 0
+            tooluid_item = int(self.ui.tools_table.item(row, 0).text())
+
+            for tooluid_key, tooluid_val in self.tools.items():
+                if int(tooluid_key) == tooluid_item:
+                    new_option_value = self.form_fields[option_changed].get_value()
+                    if option_changed in tooluid_val:
+                        tooluid_val[option_changed] = new_option_value
+                    if option_changed in tooluid_val['data']:
+                        tooluid_val['data'][option_changed] = new_option_value
+
+        self.ui_connect()
+
+    def on_operation_type(self, val):
+        if val == 'mill':
+            self.ui.mill_type_label.show()
+            self.ui.milling_type_radio.show()
+            self.ui.mill_dia_label.show()
+            self.ui.mill_dia_entry.show()
+            self.ui.frxylabel.show()
+            self.ui.xyfeedrate_entry.show()
+            self.ui.extracut_cb.show()
+            self.ui.e_cut_entry.show()
+
+            # if 'laser' not in self.ui.pp_excellon_name_cb.get_value().lower():
+            #     self.ui.mpass_cb.show()
+            #     self.ui.maxdepth_entry.show()
+        else:
+            self.ui.mill_type_label.hide()
+            self.ui.milling_type_radio.hide()
+            self.ui.mill_dia_label.hide()
+            self.ui.mill_dia_entry.hide()
+            # self.ui.mpass_cb.hide()
+            # self.ui.maxdepth_entry.hide()
+            self.ui.frxylabel.hide()
+            self.ui.xyfeedrate_entry.hide()
+            self.ui.extracut_cb.hide()
+            self.ui.e_cut_entry.hide()
+
+    def get_selected_tools_list(self):
+        """
+        Returns the keys to the self.tools dictionary corresponding
+        to the selections on the tool list in the GUI.
+
+        :return: List of tools.
+        :rtype: list
+        """
+
+        return [str(x.text()) for x in self.ui.tools_table.selectedItems()]
+
+    def get_selected_tools_table_items(self):
+        """
+        Returns a list of lists, each list in the list is made out of row elements
+
+        :return: List of table_tools items.
+        :rtype: list
+        """
+        table_tools_items = []
+        for x in self.ui.tools_table.selectedItems():
+            # from the columnCount we subtract a value of 1 which represent the last column (plot column)
+            # which does not have text
+            txt = ''
+            elem = []
+
+            for column in range(0, self.ui.tools_table.columnCount() - 1):
+                try:
+                    txt = self.ui.tools_table.item(x.row(), column).text()
+                except AttributeError:
+                    try:
+                        txt = self.ui.tools_table.cellWidget(x.row(), column).currentText()
+                    except AttributeError:
+                        pass
+                elem.append(txt)
+            table_tools_items.append(deepcopy(elem))
+            # table_tools_items.append([self.ui.tools_table.item(x.row(), column).text()
+            #                           for column in range(0, self.ui.tools_table.columnCount() - 1)])
+        for item in table_tools_items:
+            item[0] = str(item[0])
+        return table_tools_items
+
+    def export_excellon(self, whole, fract, e_zeros=None, form='dec', factor=1, slot_type='routing'):
+        """
+        Returns two values, first is a boolean , if 1 then the file has slots and second contain the Excellon code
+        :return: has_slots and Excellon_code
+        """
+
+        excellon_code = ''
+
+        # store here if the file has slots, return 1 if any slots, 0 if only drills
+        has_slots = 0
+
+        # drills processing
+        try:
+            if self.drills:
+                length = whole + fract
+                for tool in self.tools:
+                    excellon_code += 'T0%s\n' % str(tool) if int(tool) < 10 else 'T%s\n' % str(tool)
+
+                    for drill in self.drills:
+                        if form == 'dec' and tool == drill['tool']:
+                            drill_x = drill['point'].x * factor
+                            drill_y = drill['point'].y * factor
+                            excellon_code += "X{:.{dec}f}Y{:.{dec}f}\n".format(drill_x, drill_y, dec=fract)
+                        elif e_zeros == 'LZ' and tool == drill['tool']:
+                            drill_x = drill['point'].x * factor
+                            drill_y = drill['point'].y * factor
+
+                            exc_x_formatted = "{:.{dec}f}".format(drill_x, dec=fract)
+                            exc_y_formatted = "{:.{dec}f}".format(drill_y, dec=fract)
+
+                            # extract whole part and decimal part
+                            exc_x_formatted = exc_x_formatted.partition('.')
+                            exc_y_formatted = exc_y_formatted.partition('.')
+
+                            # left padd the 'whole' part with zeros
+                            x_whole = exc_x_formatted[0].rjust(whole, '0')
+                            y_whole = exc_y_formatted[0].rjust(whole, '0')
+
+                            # restore the coordinate padded in the left with 0 and added the decimal part
+                            # without the decinal dot
+                            exc_x_formatted = x_whole + exc_x_formatted[2]
+                            exc_y_formatted = y_whole + exc_y_formatted[2]
+
+                            excellon_code += "X{xform}Y{yform}\n".format(xform=exc_x_formatted,
+                                                                         yform=exc_y_formatted)
+                        elif tool == drill['tool']:
+                            drill_x = drill['point'].x * factor
+                            drill_y = drill['point'].y * factor
+
+                            exc_x_formatted = "{:.{dec}f}".format(drill_x, dec=fract).replace('.', '')
+                            exc_y_formatted = "{:.{dec}f}".format(drill_y, dec=fract).replace('.', '')
+
+                            # pad with rear zeros
+                            exc_x_formatted.ljust(length, '0')
+                            exc_y_formatted.ljust(length, '0')
+
+                            excellon_code += "X{xform}Y{yform}\n".format(xform=exc_x_formatted,
+                                                                         yform=exc_y_formatted)
+        except Exception as e:
+            log.debug(str(e))
+
+        # slots processing
+        try:
+            if self.slots:
+                has_slots = 1
+                for tool in self.tools:
+                    excellon_code += 'G05\n'
+
+                    if int(tool) < 10:
+                        excellon_code += 'T0' + str(tool) + '\n'
+                    else:
+                        excellon_code += 'T' + str(tool) + '\n'
+
+                    for slot in self.slots:
+                        if form == 'dec' and tool == slot['tool']:
+                            start_slot_x = slot['start'].x * factor
+                            start_slot_y = slot['start'].y * factor
+                            stop_slot_x = slot['stop'].x * factor
+                            stop_slot_y = slot['stop'].y * factor
+                            if slot_type == 'routing':
+                                excellon_code += "G00X{:.{dec}f}Y{:.{dec}f}\nM15\n".format(start_slot_x,
+                                                                                           start_slot_y,
+                                                                                           dec=fract)
+                                excellon_code += "G01X{:.{dec}f}Y{:.{dec}f}\nM16\n".format(stop_slot_x,
+                                                                                           stop_slot_y,
+                                                                                           dec=fract)
+                            elif slot_type == 'drilling':
+                                excellon_code += "X{:.{dec}f}Y{:.{dec}f}G85X{:.{dec}f}Y{:.{dec}f}\nG05\n".format(
+                                    start_slot_x, start_slot_y, stop_slot_x, stop_slot_y, dec=fract
+                                )
+
+                        elif e_zeros == 'LZ' and tool == slot['tool']:
+                            start_slot_x = slot['start'].x * factor
+                            start_slot_y = slot['start'].y * factor
+                            stop_slot_x = slot['stop'].x * factor
+                            stop_slot_y = slot['stop'].y * factor
+
+                            start_slot_x_formatted = "{:.{dec}f}".format(start_slot_x, dec=fract).replace('.', '')
+                            start_slot_y_formatted = "{:.{dec}f}".format(start_slot_y, dec=fract).replace('.', '')
+                            stop_slot_x_formatted = "{:.{dec}f}".format(stop_slot_x, dec=fract).replace('.', '')
+                            stop_slot_y_formatted = "{:.{dec}f}".format(stop_slot_y, dec=fract).replace('.', '')
+
+                            # extract whole part and decimal part
+                            start_slot_x_formatted = start_slot_x_formatted.partition('.')
+                            start_slot_y_formatted = start_slot_y_formatted.partition('.')
+                            stop_slot_x_formatted = stop_slot_x_formatted.partition('.')
+                            stop_slot_y_formatted = stop_slot_y_formatted.partition('.')
+
+                            # left padd the 'whole' part with zeros
+                            start_x_whole = start_slot_x_formatted[0].rjust(whole, '0')
+                            start_y_whole = start_slot_y_formatted[0].rjust(whole, '0')
+                            stop_x_whole = stop_slot_x_formatted[0].rjust(whole, '0')
+                            stop_y_whole = stop_slot_y_formatted[0].rjust(whole, '0')
+
+                            # restore the coordinate padded in the left with 0 and added the decimal part
+                            # without the decinal dot
+                            start_slot_x_formatted = start_x_whole + start_slot_x_formatted[2]
+                            start_slot_y_formatted = start_y_whole + start_slot_y_formatted[2]
+                            stop_slot_x_formatted = stop_x_whole + stop_slot_x_formatted[2]
+                            stop_slot_y_formatted = stop_y_whole + stop_slot_y_formatted[2]
+
+                            if slot_type == 'routing':
+                                excellon_code += "G00X{xstart}Y{ystart}\nM15\n".format(xstart=start_slot_x_formatted,
+                                                                                       ystart=start_slot_y_formatted)
+                                excellon_code += "G01X{xstop}Y{ystop}\nM16\n".format(xstop=stop_slot_x_formatted,
+                                                                                     ystop=stop_slot_y_formatted)
+                            elif slot_type == 'drilling':
+                                excellon_code += "{xstart}Y{ystart}G85X{xstop}Y{ystop}\nG05\n".format(
+                                    xstart=start_slot_x_formatted, ystart=start_slot_y_formatted,
+                                    xstop=stop_slot_x_formatted, ystop=stop_slot_y_formatted
+                                )
+                        elif tool == slot['tool']:
+                            start_slot_x = slot['start'].x * factor
+                            start_slot_y = slot['start'].y * factor
+                            stop_slot_x = slot['stop'].x * factor
+                            stop_slot_y = slot['stop'].y * factor
+                            length = whole + fract
+
+                            start_slot_x_formatted = "{:.{dec}f}".format(start_slot_x, dec=fract).replace('.', '')
+                            start_slot_y_formatted = "{:.{dec}f}".format(start_slot_y, dec=fract).replace('.', '')
+                            stop_slot_x_formatted = "{:.{dec}f}".format(stop_slot_x, dec=fract).replace('.', '')
+                            stop_slot_y_formatted = "{:.{dec}f}".format(stop_slot_y, dec=fract).replace('.', '')
+
+                            # pad with rear zeros
+                            start_slot_x_formatted.ljust(length, '0')
+                            start_slot_y_formatted.ljust(length, '0')
+                            stop_slot_x_formatted.ljust(length, '0')
+                            stop_slot_y_formatted.ljust(length, '0')
+
+                            if slot_type == 'routing':
+                                excellon_code += "G00X{xstart}Y{ystart}\nM15\n".format(xstart=start_slot_x_formatted,
+                                                                                       ystart=start_slot_y_formatted)
+                                excellon_code += "G01X{xstop}Y{ystop}\nM16\n".format(xstop=stop_slot_x_formatted,
+                                                                                     ystop=stop_slot_y_formatted)
+                            elif slot_type == 'drilling':
+                                excellon_code += "{xstart}Y{ystart}G85X{xstop}Y{ystop}\nG05\n".format(
+                                    xstart=start_slot_x_formatted, ystart=start_slot_y_formatted,
+                                    xstop=stop_slot_x_formatted, ystop=stop_slot_y_formatted
+                                )
+        except Exception as e:
+            log.debug(str(e))
+
+        if not self.drills and not self.slots:
+            log.debug("FlatCAMObj.ExcellonObject.export_excellon() --> Excellon Object is empty: no drills, no slots.")
+            return 'fail'
+
+        return has_slots, excellon_code
+
+    def generate_milling_drills(self, tools=None, outname=None, tooldia=None, plot=False, use_thread=False):
+        """
+        Note: This method is a good template for generic operations as
+        it takes it's options from parameters or otherwise from the
+        object's options and returns a (success, msg) tuple as feedback
+        for shell operations.
+
+        :return: Success/failure condition tuple (bool, str).
+        :rtype: tuple
+        """
+
+        # Get the tools from the list. These are keys
+        # to self.tools
+        if tools is None:
+            tools = self.get_selected_tools_list()
+
+        if outname is None:
+            outname = self.options["name"] + "_mill"
+
+        if tooldia is None:
+            tooldia = float(self.options["tooldia"])
+
+        # Sort tools by diameter. items() -> [('name', diameter), ...]
+        # sorted_tools = sorted(list(self.tools.items()), key=lambda tl: tl[1]) # no longer works in Python3
+
+        sort = []
+        for k, v in self.tools.items():
+            sort.append((k, v.get('C')))
+        sorted_tools = sorted(sort, key=lambda t1: t1[1])
+
+        if tools == "all":
+            tools = [i[0] for i in sorted_tools]  # List if ordered tool names.
+            log.debug("Tools 'all' and sorted are: %s" % str(tools))
+
+        if len(tools) == 0:
+            self.app.inform.emit('[ERROR_NOTCL] %s' %
+                                 _("Please select one or more tools from the list and try again."))
+            return False, "Error: No tools."
+
+        for tool in tools:
+            if tooldia > self.tools[tool]["C"]:
+                self.app.inform.emit(
+                    '[ERROR_NOTCL] %s %s: %s' % (
+                        _("Milling tool for DRILLS is larger than hole size. Cancelled."),
+                        _("Tool"),
+                        str(tool)
+                    )
+                )
+                return False, "Error: Milling tool is larger than hole."
+
+        def geo_init(geo_obj, app_obj):
+            assert geo_obj.kind == 'geometry', "Initializer expected a GeometryObject, got %s" % type(geo_obj)
+
+            # ## Add properties to the object
+
+            # get the tool_table items in a list of row items
+            tool_table_items = self.get_selected_tools_table_items()
+            # insert an information only element in the front
+            tool_table_items.insert(0, [_("Tool_nr"), _("Diameter"), _("Drills_Nr"), _("Slots_Nr")])
+
+            geo_obj.options['Tools_in_use'] = tool_table_items
+            geo_obj.options['type'] = 'Excellon Geometry'
+            geo_obj.options["cnctooldia"] = str(tooldia)
+
+            geo_obj.solid_geometry = []
+
+            # in case that the tool used has the same diameter with the hole, and since the maximum resolution
+            # for FlatCAM is 6 decimals,
+            # we add a tenth of the minimum value, meaning 0.0000001, which from our point of view is "almost zero"
+            for hole in self.drills:
+                if hole['tool'] in tools:
+                    buffer_value = self.tools[hole['tool']]["C"] / 2 - tooldia / 2
+                    if buffer_value == 0:
+                        geo_obj.solid_geometry.append(
+                            Point(hole['point']).buffer(0.0000001).exterior)
+                    else:
+                        geo_obj.solid_geometry.append(
+                            Point(hole['point']).buffer(buffer_value).exterior)
+        if use_thread:
+            def geo_thread(app_obj):
+                app_obj.new_object("geometry", outname, geo_init, plot=plot)
+
+            # Create a promise with the new name
+            self.app.collection.promise(outname)
+
+            # Send to worker
+            self.app.worker_task.emit({'fcn': geo_thread, 'params': [self.app]})
+        else:
+            self.app.new_object("geometry", outname, geo_init, plot=plot)
+
+        return True, ""
+
+    def generate_milling_slots(self, tools=None, outname=None, tooldia=None, plot=True, use_thread=False):
+        """
+        Note: This method is a good template for generic operations as
+        it takes it's options from parameters or otherwise from the
+        object's options and returns a (success, msg) tuple as feedback
+        for shell operations.
+
+        :return: Success/failure condition tuple (bool, str).
+        :rtype: tuple
+        """
+
+        # Get the tools from the list. These are keys
+        # to self.tools
+        if tools is None:
+            tools = self.get_selected_tools_list()
+
+        if outname is None:
+            outname = self.options["name"] + "_mill"
+
+        if tooldia is None:
+            tooldia = float(self.options["slot_tooldia"])
+
+        # Sort tools by diameter. items() -> [('name', diameter), ...]
+        # sorted_tools = sorted(list(self.tools.items()), key=lambda tl: tl[1]) # no longer works in Python3
+
+        sort = []
+        for k, v in self.tools.items():
+            sort.append((k, v.get('C')))
+        sorted_tools = sorted(sort, key=lambda t1: t1[1])
+
+        if tools == "all":
+            tools = [i[0] for i in sorted_tools]  # List if ordered tool names.
+            log.debug("Tools 'all' and sorted are: %s" % str(tools))
+
+        if len(tools) == 0:
+            self.app.inform.emit('[ERROR_NOTCL] %s' %
+                                 _("Please select one or more tools from the list and try again."))
+            return False, "Error: No tools."
+
+        for tool in tools:
+            # I add the 0.0001 value to account for the rounding error in converting from IN to MM and reverse
+            adj_toolstable_tooldia = float('%.*f' % (self.decimals, float(tooldia)))
+            adj_file_tooldia = float('%.*f' % (self.decimals, float(self.tools[tool]["C"])))
+            if adj_toolstable_tooldia > adj_file_tooldia + 0.0001:
+                self.app.inform.emit('[ERROR_NOTCL] %s' %
+                                     _("Milling tool for SLOTS is larger than hole size. Cancelled."))
+                return False, "Error: Milling tool is larger than hole."
+
+        def geo_init(geo_obj, app_obj):
+            assert geo_obj.kind == 'geometry' "Initializer expected a GeometryObject, got %s" % type(geo_obj)
+
+            # ## Add properties to the object
+
+            # get the tool_table items in a list of row items
+            tool_table_items = self.get_selected_tools_table_items()
+            # insert an information only element in the front
+            tool_table_items.insert(0, [_("Tool_nr"), _("Diameter"), _("Drills_Nr"), _("Slots_Nr")])
+
+            geo_obj.options['Tools_in_use'] = tool_table_items
+            geo_obj.options['type'] = 'Excellon Geometry'
+            geo_obj.options["cnctooldia"] = str(tooldia)
+
+            geo_obj.solid_geometry = []
+
+            # in case that the tool used has the same diameter with the hole, and since the maximum resolution
+            # for FlatCAM is 6 decimals,
+            # we add a tenth of the minimum value, meaning 0.0000001, which from our point of view is "almost zero"
+            for slot in self.slots:
+                if slot['tool'] in tools:
+                    toolstable_tool = float('%.*f' % (self.decimals, float(tooldia)))
+                    file_tool = float('%.*f' % (self.decimals, float(self.tools[tool]["C"])))
+
+                    # I add the 0.0001 value to account for the rounding error in converting from IN to MM and reverse
+                    # for the file_tool (tooldia actually)
+                    buffer_value = float(file_tool / 2) - float(toolstable_tool / 2) + 0.0001
+                    if buffer_value == 0:
+                        start = slot['start']
+                        stop = slot['stop']
+
+                        lines_string = LineString([start, stop])
+                        poly = lines_string.buffer(0.0000001, int(self.geo_steps_per_circle)).exterior
+                        geo_obj.solid_geometry.append(poly)
+                    else:
+                        start = slot['start']
+                        stop = slot['stop']
+
+                        lines_string = LineString([start, stop])
+                        poly = lines_string.buffer(buffer_value, int(self.geo_steps_per_circle)).exterior
+                        geo_obj.solid_geometry.append(poly)
+
+        if use_thread:
+            def geo_thread(app_obj):
+                app_obj.new_object("geometry", outname + '_slot', geo_init, plot=plot)
+
+            # Create a promise with the new name
+            self.app.collection.promise(outname)
+
+            # Send to worker
+            self.app.worker_task.emit({'fcn': geo_thread, 'params': [self.app]})
+        else:
+            self.app.new_object("geometry", outname + '_slot', geo_init, plot=plot)
+
+        return True, ""
+
+    def on_generate_milling_button_click(self, *args):
+        self.app.report_usage("excellon_on_create_milling_drills button")
+        self.read_form()
+
+        self.generate_milling_drills(use_thread=False)
+
+    def on_generate_milling_slots_button_click(self, *args):
+        self.app.report_usage("excellon_on_create_milling_slots_button")
+        self.read_form()
+
+        self.generate_milling_slots(use_thread=False)
+
+    def on_pp_changed(self):
+        current_pp = self.ui.pp_excellon_name_cb.get_value()
+
+        if "toolchange_probe" in current_pp.lower():
+            self.ui.pdepth_entry.setVisible(True)
+            self.ui.pdepth_label.show()
+
+            self.ui.feedrate_probe_entry.setVisible(True)
+            self.ui.feedrate_probe_label.show()
+        else:
+            self.ui.pdepth_entry.setVisible(False)
+            self.ui.pdepth_label.hide()
+
+            self.ui.feedrate_probe_entry.setVisible(False)
+            self.ui.feedrate_probe_label.hide()
+
+        if 'marlin' in current_pp.lower() or 'custom' in current_pp.lower():
+            self.ui.feedrate_rapid_label.show()
+            self.ui.feedrate_rapid_entry.show()
+        else:
+            self.ui.feedrate_rapid_label.hide()
+            self.ui.feedrate_rapid_entry.hide()
+
+        if 'laser' in current_pp.lower():
+            self.ui.cutzlabel.hide()
+            self.ui.cutz_entry.hide()
+            try:
+                self.ui.mpass_cb.hide()
+                self.ui.maxdepth_entry.hide()
+            except AttributeError:
+                pass
+
+            if 'marlin' in current_pp.lower():
+                self.ui.travelzlabel.setText('%s:' % _("Focus Z"))
+                self.ui.endz_label.show()
+                self.ui.endz_entry.show()
+            else:
+                self.ui.travelzlabel.hide()
+                self.ui.travelz_entry.hide()
+
+                self.ui.endz_label.hide()
+                self.ui.endz_entry.hide()
+
+            try:
+                self.ui.frzlabel.hide()
+                self.ui.feedrate_z_entry.hide()
+            except AttributeError:
+                pass
+
+            self.ui.dwell_cb.hide()
+            self.ui.dwelltime_entry.hide()
+
+            self.ui.spindle_label.setText('%s:' % _("Laser Power"))
+
+            try:
+                self.ui.tool_offset_label.hide()
+                self.ui.offset_entry.hide()
+            except AttributeError:
+                pass
+        else:
+            self.ui.cutzlabel.show()
+            self.ui.cutz_entry.show()
+            try:
+                self.ui.mpass_cb.show()
+                self.ui.maxdepth_entry.show()
+            except AttributeError:
+                pass
+
+            self.ui.travelzlabel.setText('%s:' % _('Travel Z'))
+
+            self.ui.travelzlabel.show()
+            self.ui.travelz_entry.show()
+
+            self.ui.endz_label.show()
+            self.ui.endz_entry.show()
+
+            try:
+                self.ui.frzlabel.show()
+                self.ui.feedrate_z_entry.show()
+            except AttributeError:
+                pass
+            self.ui.dwell_cb.show()
+            self.ui.dwelltime_entry.show()
+
+            self.ui.spindle_label.setText('%s:' % _('Spindle speed'))
+
+            try:
+                self.ui.tool_offset_lbl.show()
+                self.ui.offset_entry.show()
+            except AttributeError:
+                pass
+
+    def on_create_cncjob_button_click(self, *args):
+        self.app.report_usage("excellon_on_create_cncjob_button")
+        self.read_form()
+
+        # Get the tools from the list
+        tools = self.get_selected_tools_list()
+
+        if len(tools) == 0:
+            # if there is a single tool in the table (remember that the last 2 rows are for totals and do not count in
+            # tool number) it means that there are 3 rows (1 tool and 2 totals).
+            # in this case regardless of the selection status of that tool, use it.
+            if self.ui.tools_table.rowCount() == 3:
+                tools.append(self.ui.tools_table.item(0, 0).text())
+            else:
+                self.app.inform.emit('[ERROR_NOTCL] %s' %
+                                     _("Please select one or more tools from the list and try again."))
+                return
+
+        xmin = self.options['xmin']
+        ymin = self.options['ymin']
+        xmax = self.options['xmax']
+        ymax = self.options['ymax']
+
+        job_name = self.options["name"] + "_cnc"
+        pp_excellon_name = self.options["ppname_e"]
+
+        # Object initialization function for app.new_object()
+        def job_init(job_obj, app_obj):
+            assert job_obj.kind == 'cncjob', "Initializer expected a CNCJobObject, got %s" % type(job_obj)
+
+            # get the tool_table items in a list of row items
+            tool_table_items = self.get_selected_tools_table_items()
+            # insert an information only element in the front
+            tool_table_items.insert(0, [_("Tool_nr"), _("Diameter"), _("Drills_Nr"), _("Slots_Nr")])
+
+            # ## Add properties to the object
+
+            job_obj.origin_kind = 'excellon'
+
+            job_obj.options['Tools_in_use'] = tool_table_items
+            job_obj.options['type'] = 'Excellon'
+            job_obj.options['ppname_e'] = pp_excellon_name
+
+            job_obj.multidepth = self.options["multidepth"]
+            job_obj.z_depthpercut = self.options["depthperpass"]
+
+            job_obj.z_move = float(self.options["travelz"])
+            job_obj.feedrate = float(self.options["feedrate_z"])
+            job_obj.z_feedrate = float(self.options["feedrate_z"])
+            job_obj.feedrate_rapid = float(self.options["feedrate_rapid"])
+
+            job_obj.spindlespeed = float(self.options["spindlespeed"]) if self.options["spindlespeed"] != 0 else None
+            job_obj.spindledir = self.app.defaults['excellon_spindledir']
+            job_obj.dwell = self.options["dwell"]
+            job_obj.dwelltime = float(self.options["dwelltime"])
+
+            job_obj.pp_excellon_name = pp_excellon_name
+
+            job_obj.toolchange_xy_type = "excellon"
+            job_obj.coords_decimals = int(self.app.defaults["cncjob_coords_decimals"])
+            job_obj.fr_decimals = int(self.app.defaults["cncjob_fr_decimals"])
+
+            job_obj.options['xmin'] = xmin
+            job_obj.options['ymin'] = ymin
+            job_obj.options['xmax'] = xmax
+            job_obj.options['ymax'] = ymax
+
+            job_obj.z_pdepth = float(self.options["z_pdepth"])
+            job_obj.feedrate_probe = float(self.options["feedrate_probe"])
+
+            job_obj.z_cut = float(self.options['cutz'])
+            job_obj.toolchange = self.options["toolchange"]
+            job_obj.xy_toolchange = self.app.defaults["excellon_toolchangexy"]
+            job_obj.z_toolchange = float(self.options["toolchangez"])
+            job_obj.startz = float(self.options["startz"]) if self.options["startz"] else None
+            job_obj.endz = float(self.options["endz"])
+            job_obj.xy_end = self.options["endxy"]
+            job_obj.excellon_optimization_type = self.app.defaults["excellon_optimization_type"]
+
+            tools_csv = ','.join(tools)
+            ret_val = job_obj.generate_from_excellon_by_tool(self, tools_csv, use_ui=True)
+
+            if ret_val == 'fail':
+                return 'fail'
+
+            job_obj.gcode_parse()
+            job_obj.create_geometry()
+
+        # To be run in separate thread
+        def job_thread(app_obj):
+            with self.app.proc_container.new(_("Generating CNC Code")):
+                app_obj.new_object("cncjob", job_name, job_init)
+
+        # Create promise for the new name.
+        self.app.collection.promise(job_name)
+
+        # Send to worker
+        # self.app.worker.add_task(job_thread, [self.app])
+        self.app.worker_task.emit({'fcn': job_thread, 'params': [self.app]})
+
+    def convert_units(self, units):
+        log.debug("FlatCAMObj.ExcellonObject.convert_units()")
+
+        Excellon.convert_units(self, units)
+
+        # factor = Excellon.convert_units(self, units)
+        # self.options['drillz'] = float(self.options['drillz']) * factor
+        # self.options['travelz'] = float(self.options['travelz']) * factor
+        # self.options['feedrate'] = float(self.options['feedrate']) * factor
+        # self.options['feedrate_rapid'] = float(self.options['feedrate_rapid']) * factor
+        # self.options['toolchangez'] = float(self.options['toolchangez']) * factor
+        #
+        # if self.app.defaults["excellon_toolchangexy"] == '':
+        #     self.options['toolchangexy'] = "0.0, 0.0"
+        # else:
+        #     coords_xy = [float(eval(coord)) for coord in self.app.defaults["excellon_toolchangexy"].split(",")]
+        #     if len(coords_xy) < 2:
+        #         self.app.inform.emit('[ERROR] %s' % _("The Toolchange X,Y field in Edit -> Preferences has to be "
+        #                                               "in the format (x, y) \n"
+        #                                               "but now there is only one value, not two. "))
+        #         return 'fail'
+        #     coords_xy[0] *= factor
+        #     coords_xy[1] *= factor
+        #     self.options['toolchangexy'] = "%f, %f" % (coords_xy[0], coords_xy[1])
+        #
+        # if self.options['startz'] is not None:
+        #     self.options['startz'] = float(self.options['startz']) * factor
+        # self.options['endz'] = float(self.options['endz']) * factor
+
+    def on_solid_cb_click(self, *args):
+        if self.muted_ui:
+            return
+        self.read_form_item('solid')
+        self.plot()
+
+    def on_plot_cb_click(self, *args):
+        if self.muted_ui:
+            return
+        self.plot()
+        self.read_form_item('plot')
+
+        self.ui_disconnect()
+        cb_flag = self.ui.plot_cb.isChecked()
+        for row in range(self.ui.tools_table.rowCount() - 2):
+            table_cb = self.ui.tools_table.cellWidget(row, 5)
+            if cb_flag:
+                table_cb.setChecked(True)
+            else:
+                table_cb.setChecked(False)
+
+        self.ui_connect()
+
+    def on_plot_cb_click_table(self):
+        # self.ui.cnc_tools_table.cellWidget(row, 2).widget().setCheckState(QtCore.Qt.Unchecked)
+        self.ui_disconnect()
+        # cw = self.sender()
+        # cw_index = self.ui.tools_table.indexAt(cw.pos())
+        # cw_row = cw_index.row()
+        check_row = 0
+
+        self.shapes.clear(update=True)
+        for tool_key in self.tools:
+            solid_geometry = self.tools[tool_key]['solid_geometry']
+
+            # find the geo_tool_table row associated with the tool_key
+            for row in range(self.ui.tools_table.rowCount()):
+                tool_item = int(self.ui.tools_table.item(row, 0).text())
+                if tool_item == int(tool_key):
+                    check_row = row
+                    break
+            if self.ui.tools_table.cellWidget(check_row, 5).isChecked():
+                self.options['plot'] = True
+                # self.plot_element(element=solid_geometry, visible=True)
+                # Plot excellon (All polygons?)
+                if self.options["solid"]:
+                    for geo in solid_geometry:
+                        self.add_shape(shape=geo, color='#750000BF', face_color='#C40000BF',
+                                       visible=self.options['plot'],
+                                       layer=2)
+                else:
+                    for geo in solid_geometry:
+                        self.add_shape(shape=geo.exterior, color='red', visible=self.options['plot'])
+                        for ints in geo.interiors:
+                            self.add_shape(shape=ints, color='green', visible=self.options['plot'])
+        self.shapes.redraw()
+
+        # make sure that the general plot is disabled if one of the row plot's are disabled and
+        # if all the row plot's are enabled also enable the general plot checkbox
+        cb_cnt = 0
+        total_row = self.ui.tools_table.rowCount()
+        for row in range(total_row - 2):
+            if self.ui.tools_table.cellWidget(row, 5).isChecked():
+                cb_cnt += 1
+            else:
+                cb_cnt -= 1
+        if cb_cnt < total_row - 2:
+            self.ui.plot_cb.setChecked(False)
+        else:
+            self.ui.plot_cb.setChecked(True)
+        self.ui_connect()
+
+    def plot(self, visible=None, kind=None):
+
+        # Does all the required setup and returns False
+        # if the 'ptint' option is set to False.
+        if not FlatCAMObj.plot(self):
+            return
+
+        # try:
+        #     # Plot Excellon (All polygons?)
+        #     if self.options["solid"]:
+        #         for tool in self.tools:
+        #             for geo in self.tools[tool]['solid_geometry']:
+        #                 self.add_shape(shape=geo, color='#750000BF', face_color='#C40000BF',
+        #                                visible=self.options['plot'],
+        #                                layer=2)
+        #     else:
+        #         for tool in self.tools:
+        #             for geo in self.tools[tool]['solid_geometry']:
+        #                 self.add_shape(shape=geo.exterior, color='red', visible=self.options['plot'])
+        #                 for ints in geo.interiors:
+        #                     self.add_shape(shape=ints, color='orange', visible=self.options['plot'])
+        #
+        #     self.shapes.redraw()
+        #     return
+        # except (ObjectDeleted, AttributeError, KeyError):
+        #     self.shapes.clear(update=True)
+
+        # this stays for compatibility reasons, in case we try to open old projects
+        try:
+            __ = iter(self.solid_geometry)
+        except TypeError:
+            self.solid_geometry = [self.solid_geometry]
+
+        visible = visible if visible else self.options['plot']
+
+        try:
+            # Plot Excellon (All polygons?)
+            if self.options["solid"]:
+                for geo in self.solid_geometry:
+                    self.add_shape(shape=geo,
+                                   color=self.outline_color,
+                                   face_color=self.fill_color,
+                                   visible=visible,
+                                   layer=2)
+            else:
+                for geo in self.solid_geometry:
+                    self.add_shape(shape=geo.exterior, color='red', visible=visible)
+                    for ints in geo.interiors:
+                        self.add_shape(shape=ints, color='orange', visible=visible)
+
+            self.shapes.redraw()
+        except (ObjectDeleted, AttributeError):
+            self.shapes.clear(update=True)
+
+    def on_apply_param_to_all_clicked(self):
+        if self.ui.tools_table.rowCount() == 0:
+            # there is no tool in tool table so we can't save the GUI elements values to storage
+            log.debug("ExcellonObject.on_apply_param_to_all_clicked() --> no tool in Tools Table, aborting.")
+            return
+
+        self.ui_disconnect()
+
+        row = self.ui.tools_table.currentRow()
+        if row < 0:
+            row = 0
+
+        tooluid_item = int(self.ui.tools_table.item(row, 0).text())
+        temp_tool_data = {}
+
+        for tooluid_key, tooluid_val in self.tools.items():
+            if int(tooluid_key) == tooluid_item:
+                # this will hold the 'data' key of the self.tools[tool] dictionary that corresponds to
+                # the current row in the tool table
+                temp_tool_data = tooluid_val['data']
+                break
+
+        for tooluid_key, tooluid_val in self.tools.items():
+            tooluid_val['data'] = deepcopy(temp_tool_data)
+
+        self.app.inform.emit('[success] %s' % _("Current Tool parameters were applied to all tools."))
+
+        self.ui_connect()

+ 2622 - 0
flatcamObjects/FlatCAMGeometry.py

@@ -0,0 +1,2622 @@
+# ##########################################################
+# FlatCAM: 2D Post-processing for Manufacturing            #
+# http://flatcam.org                                       #
+# Author: Juan Pablo Caram (c)                             #
+# Date: 2/5/2014                                           #
+# MIT Licence                                              #
+# ##########################################################
+
+# ##########################################################
+# File modified by: Marius Stanciu                         #
+# ##########################################################
+
+from shapely.geometry import Polygon, MultiPolygon, MultiLineString, LineString, LinearRing
+import shapely.affinity as affinity
+
+from camlib import Geometry
+
+from flatcamObjects.FlatCAMObj import *
+
+import ezdxf
+import math
+import numpy as np
+from copy import deepcopy
+import traceback
+
+import gettext
+import FlatCAMTranslation as fcTranslate
+import builtins
+
+fcTranslate.apply_language('strings')
+if '_' not in builtins.__dict__:
+    _ = gettext.gettext
+
+
+class GeometryObject(FlatCAMObj, Geometry):
+    """
+    Geometric object not associated with a specific
+    format.
+    """
+    optionChanged = QtCore.pyqtSignal(str)
+    ui_type = GeometryObjectUI
+
+    def __init__(self, name):
+        self.decimals = self.app.decimals
+
+        self.circle_steps = int(self.app.defaults["geometry_circle_steps"])
+
+        FlatCAMObj.__init__(self, name)
+        Geometry.__init__(self, geo_steps_per_circle=self.circle_steps)
+
+        self.kind = "geometry"
+
+        self.options.update({
+            "plot": True,
+            "cutz": -0.002,
+            "vtipdia": 0.1,
+            "vtipangle": 30,
+            "travelz": 0.1,
+            "feedrate": 5.0,
+            "feedrate_z": 5.0,
+            "feedrate_rapid": 5.0,
+            "spindlespeed": 0,
+            "dwell": True,
+            "dwelltime": 1000,
+            "multidepth": False,
+            "depthperpass": 0.002,
+            "extracut": False,
+            "extracut_length": 0.1,
+            "endz": 2.0,
+            "endxy": '',
+
+            "startz": None,
+            "toolchange": False,
+            "toolchangez": 1.0,
+            "toolchangexy": "0.0, 0.0",
+            "ppname_g": 'default',
+            "z_pdepth": -0.02,
+            "feedrate_probe": 3.0,
+        })
+
+        if "cnctooldia" not in self.options:
+            if type(self.app.defaults["geometry_cnctooldia"]) == float:
+                self.options["cnctooldia"] = self.app.defaults["geometry_cnctooldia"]
+            else:
+                try:
+                    tools_string = self.app.defaults["geometry_cnctooldia"].split(",")
+                    tools_diameters = [eval(a) for a in tools_string if a != '']
+                    self.options["cnctooldia"] = tools_diameters[0] if tools_diameters else 0.0
+                except Exception as e:
+                    log.debug("FlatCAMObj.GeometryObject.init() --> %s" % str(e))
+
+        self.options["startz"] = self.app.defaults["geometry_startz"]
+
+        # this will hold the tool unique ID that is useful when having multiple tools with same diameter
+        self.tooluid = 0
+
+        '''
+            self.tools = {}
+            This is a dictionary. Each dict key is associated with a tool used in geo_tools_table. The key is the 
+            tool_id of the tools and the value is another dict that will hold the data under the following form:
+                {tooluid:   {
+                            'tooldia': 1,
+                            'offset': 'Path',
+                            'offset_value': 0.0
+                            'type': 'Rough',
+                            'tool_type': 'C1',
+                            'data': self.default_tool_data
+                            'solid_geometry': []
+                            }
+                }
+        '''
+        self.tools = {}
+
+        # this dict is to store those elements (tools) of self.tools that are selected in the self.geo_tools_table
+        # those elements are the ones used for generating GCode
+        self.sel_tools = {}
+
+        self.offset_item_options = ["Path", "In", "Out", "Custom"]
+        self.type_item_options = [_("Iso"), _("Rough"), _("Finish")]
+        self.tool_type_item_options = ["C1", "C2", "C3", "C4", "B", "V"]
+
+        # flag to store if the V-Shape tool is selected in self.ui.geo_tools_table
+        self.v_tool_type = None
+
+        # flag to store if the Geometry is type 'multi-geometry' meaning that each tool has it's own geometry
+        # the default value is False
+        self.multigeo = False
+
+        # flag to store if the geometry is part of a special group of geometries that can't be processed by the default
+        # engine of FlatCAM. Most likely are generated by some of tools and are special cases of geometries.
+        self.special_group = None
+
+        self.old_pp_state = self.app.defaults["geometry_multidepth"]
+        self.old_toolchangeg_state = self.app.defaults["geometry_toolchange"]
+        self.units_found = self.app.defaults['units']
+
+        # this variable can be updated by the Object that generates the geometry
+        self.tool_type = 'C1'
+
+        # save here the old value for the Cut Z before it is changed by selecting a V-shape type tool in the tool table
+        self.old_cutz = self.app.defaults["geometry_cutz"]
+
+        self.fill_color = self.app.defaults['geometry_plot_line']
+        self.outline_color = self.app.defaults['geometry_plot_line']
+        self.alpha_level = 'FF'
+
+        self.param_fields = {}
+
+        # Attributes to be included in serialization
+        # Always append to it because it carries contents
+        # from predecessors.
+        self.ser_attrs += ['options', 'kind', 'tools', 'multigeo']
+
+    def build_ui(self):
+        self.ui_disconnect()
+        FlatCAMObj.build_ui(self)
+
+        self.units = self.app.defaults['units']
+
+        tool_idx = 0
+
+        n = len(self.tools)
+        self.ui.geo_tools_table.setRowCount(n)
+
+        for tooluid_key, tooluid_value in self.tools.items():
+            tool_idx += 1
+            row_no = tool_idx - 1
+
+            tool_id = QtWidgets.QTableWidgetItem('%d' % int(tool_idx))
+            tool_id.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
+            self.ui.geo_tools_table.setItem(row_no, 0, tool_id)  # Tool name/id
+
+            # Make sure that the tool diameter when in MM is with no more than 2 decimals.
+            # There are no tool bits in MM with more than 3 decimals diameter.
+            # For INCH the decimals should be no more than 3. There are no tools under 10mils.
+
+            dia_item = QtWidgets.QTableWidgetItem('%.*f' % (self.decimals, float(tooluid_value['tooldia'])))
+
+            dia_item.setFlags(QtCore.Qt.ItemIsEnabled)
+
+            offset_item = FCComboBox()
+            for item in self.offset_item_options:
+                offset_item.addItem(item)
+            # offset_item.setStyleSheet('background-color: rgb(255,255,255)')
+            idx = offset_item.findText(tooluid_value['offset'])
+            offset_item.setCurrentIndex(idx)
+
+            type_item = FCComboBox()
+            for item in self.type_item_options:
+                type_item.addItem(item)
+            # type_item.setStyleSheet('background-color: rgb(255,255,255)')
+            idx = type_item.findText(tooluid_value['type'])
+            type_item.setCurrentIndex(idx)
+
+            tool_type_item = FCComboBox()
+            for item in self.tool_type_item_options:
+                tool_type_item.addItem(item)
+                # tool_type_item.setStyleSheet('background-color: rgb(255,255,255)')
+            idx = tool_type_item.findText(tooluid_value['tool_type'])
+            tool_type_item.setCurrentIndex(idx)
+
+            tool_uid_item = QtWidgets.QTableWidgetItem(str(tooluid_key))
+
+            plot_item = FCCheckBox()
+            plot_item.setLayoutDirection(QtCore.Qt.RightToLeft)
+            if self.ui.plot_cb.isChecked():
+                plot_item.setChecked(True)
+
+            self.ui.geo_tools_table.setItem(row_no, 1, dia_item)  # Diameter
+            self.ui.geo_tools_table.setCellWidget(row_no, 2, offset_item)
+            self.ui.geo_tools_table.setCellWidget(row_no, 3, type_item)
+            self.ui.geo_tools_table.setCellWidget(row_no, 4, tool_type_item)
+
+            # ## REMEMBER: THIS COLUMN IS HIDDEN IN OBJECTUI.PY ###
+            self.ui.geo_tools_table.setItem(row_no, 5, tool_uid_item)  # Tool unique ID
+            self.ui.geo_tools_table.setCellWidget(row_no, 6, plot_item)
+
+            try:
+                self.ui.tool_offset_entry.set_value(tooluid_value['offset_value'])
+            except Exception as e:
+                log.debug("build_ui() --> Could not set the 'offset_value' key in self.tools. Error: %s" % str(e))
+
+        # make the diameter column editable
+        for row in range(tool_idx):
+            self.ui.geo_tools_table.item(row, 1).setFlags(QtCore.Qt.ItemIsSelectable |
+                                                          QtCore.Qt.ItemIsEditable |
+                                                          QtCore.Qt.ItemIsEnabled)
+
+        # sort the tool diameter column
+        # self.ui.geo_tools_table.sortItems(1)
+        # all the tools are selected by default
+        # self.ui.geo_tools_table.selectColumn(0)
+
+        self.ui.geo_tools_table.resizeColumnsToContents()
+        self.ui.geo_tools_table.resizeRowsToContents()
+
+        vertical_header = self.ui.geo_tools_table.verticalHeader()
+        # vertical_header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
+        vertical_header.hide()
+        self.ui.geo_tools_table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
+
+        horizontal_header = self.ui.geo_tools_table.horizontalHeader()
+        horizontal_header.setMinimumSectionSize(10)
+        horizontal_header.setDefaultSectionSize(70)
+        horizontal_header.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
+        horizontal_header.resizeSection(0, 20)
+        horizontal_header.setSectionResizeMode(1, QtWidgets.QHeaderView.Stretch)
+        # horizontal_header.setColumnWidth(2, QtWidgets.QHeaderView.ResizeToContents)
+        horizontal_header.setSectionResizeMode(3, QtWidgets.QHeaderView.ResizeToContents)
+        horizontal_header.setSectionResizeMode(4, QtWidgets.QHeaderView.Fixed)
+        horizontal_header.resizeSection(4, 40)
+        horizontal_header.setSectionResizeMode(6, QtWidgets.QHeaderView.Fixed)
+        horizontal_header.resizeSection(4, 17)
+        # horizontal_header.setStretchLastSection(True)
+        self.ui.geo_tools_table.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
+
+        self.ui.geo_tools_table.setColumnWidth(0, 20)
+        self.ui.geo_tools_table.setColumnWidth(4, 40)
+        self.ui.geo_tools_table.setColumnWidth(6, 17)
+
+        # self.ui.geo_tools_table.setSortingEnabled(True)
+
+        self.ui.geo_tools_table.setMinimumHeight(self.ui.geo_tools_table.getHeight())
+        self.ui.geo_tools_table.setMaximumHeight(self.ui.geo_tools_table.getHeight())
+
+        # update UI for all rows - useful after units conversion but only if there is at least one row
+        row_cnt = self.ui.geo_tools_table.rowCount()
+        if row_cnt > 0:
+            for r in range(row_cnt):
+                self.update_ui(r)
+
+        # select only the first tool / row
+        selected_row = 0
+        try:
+            self.select_tools_table_row(selected_row, clearsel=True)
+            # update the Geometry UI
+            self.update_ui()
+        except Exception as e:
+            # when the tools table is empty there will be this error but once the table is populated it will go away
+            log.debug(str(e))
+
+        # disable the Plot column in Tool Table if the geometry is SingleGeo as it is not needed
+        # and can create some problems
+        if self.multigeo is False:
+            self.ui.geo_tools_table.setColumnHidden(6, True)
+        else:
+            self.ui.geo_tools_table.setColumnHidden(6, False)
+
+        self.set_tool_offset_visibility(selected_row)
+
+        # HACK: for whatever reasons the name in Selected tab is reverted to the original one after a successful rename
+        # done in the collection view but only for Geometry objects. Perhaps some references remains. Should be fixed.
+        self.ui.name_entry.set_value(self.options['name'])
+        self.ui_connect()
+
+        self.ui.e_cut_entry.setDisabled(False) if self.ui.extracut_cb.get_value() else \
+            self.ui.e_cut_entry.setDisabled(True)
+
+        # set the text on tool_data_label after loading the object
+        sel_rows = []
+        sel_items = self.ui.geo_tools_table.selectedItems()
+        for it in sel_items:
+            sel_rows.append(it.row())
+        if len(sel_rows) > 1:
+            self.ui.tool_data_label.setText(
+                "<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("Multiple Tools"))
+            )
+
+    def set_ui(self, ui):
+        FlatCAMObj.set_ui(self, ui)
+
+        log.debug("GeometryObject.set_ui()")
+
+        assert isinstance(self.ui, GeometryObjectUI), \
+            "Expected a GeometryObjectUI, got %s" % type(self.ui)
+
+        self.units = self.app.defaults['units'].upper()
+        self.units_found = self.app.defaults['units']
+
+        # populate preprocessor names in the combobox
+        for name in list(self.app.preprocessors.keys()):
+            self.ui.pp_geometry_name_cb.addItem(name)
+
+        self.form_fields.update({
+            "plot": self.ui.plot_cb,
+            "cutz": self.ui.cutz_entry,
+            "vtipdia": self.ui.tipdia_entry,
+            "vtipangle": self.ui.tipangle_entry,
+            "travelz": self.ui.travelz_entry,
+            "feedrate": self.ui.cncfeedrate_entry,
+            "feedrate_z": self.ui.feedrate_z_entry,
+            "feedrate_rapid": self.ui.feedrate_rapid_entry,
+            "spindlespeed": self.ui.cncspindlespeed_entry,
+            "dwell": self.ui.dwell_cb,
+            "dwelltime": self.ui.dwelltime_entry,
+            "multidepth": self.ui.mpass_cb,
+            "ppname_g": self.ui.pp_geometry_name_cb,
+            "z_pdepth": self.ui.pdepth_entry,
+            "feedrate_probe": self.ui.feedrate_probe_entry,
+            "depthperpass": self.ui.maxdepth_entry,
+            "extracut": self.ui.extracut_cb,
+            "extracut_length": self.ui.e_cut_entry,
+            "toolchange": self.ui.toolchangeg_cb,
+            "toolchangez": self.ui.toolchangez_entry,
+            "endz": self.ui.endz_entry,
+            "endxy": self.ui.endxy_entry,
+            "cnctooldia": self.ui.addtool_entry
+        })
+
+        self.param_fields.update({
+            "vtipdia": self.ui.tipdia_entry,
+            "vtipangle": self.ui.tipangle_entry,
+            "cutz": self.ui.cutz_entry,
+            "depthperpass": self.ui.maxdepth_entry,
+            "multidepth": self.ui.mpass_cb,
+            "travelz": self.ui.travelz_entry,
+            "feedrate": self.ui.cncfeedrate_entry,
+            "feedrate_z": self.ui.feedrate_z_entry,
+            "feedrate_rapid": self.ui.feedrate_rapid_entry,
+            "extracut": self.ui.extracut_cb,
+            "extracut_length": self.ui.e_cut_entry,
+            "spindlespeed": self.ui.cncspindlespeed_entry,
+            "dwelltime": self.ui.dwelltime_entry,
+            "dwell": self.ui.dwell_cb,
+            "pdepth": self.ui.pdepth_entry,
+            "pfeedrate": self.ui.feedrate_probe_entry,
+        })
+        # Fill form fields only on object create
+        self.to_form()
+
+        # update the changes in UI depending on the selected preprocessor in Preferences
+        # after this moment all the changes in the Posprocessor combo will be handled by the activated signal of the
+        # self.ui.pp_geometry_name_cb combobox
+        self.on_pp_changed()
+
+        self.ui.tipdialabel.hide()
+        self.ui.tipdia_entry.hide()
+        self.ui.tipanglelabel.hide()
+        self.ui.tipangle_entry.hide()
+        self.ui.cutz_entry.setDisabled(False)
+
+        # store here the default data for Geometry Data
+        self.default_data = {}
+        self.default_data.update({
+            "name": None,
+            "plot": None,
+            "cutz": None,
+            "vtipdia": None,
+            "vtipangle": None,
+            "travelz": None,
+            "feedrate": None,
+            "feedrate_z": None,
+            "feedrate_rapid": None,
+            "dwell": None,
+            "dwelltime": None,
+            "multidepth": None,
+            "ppname_g": None,
+            "depthperpass": None,
+            "extracut": None,
+            "extracut_length": None,
+            "toolchange": None,
+            "toolchangez": None,
+            "endz": None,
+            "endxy": '',
+            "spindlespeed": 0,
+            "toolchangexy": None,
+            "startz": None
+        })
+
+        # fill in self.default_data values from self.options
+        for def_key in self.default_data:
+            for opt_key, opt_val in self.options.items():
+                if def_key == opt_key:
+                    self.default_data[def_key] = deepcopy(opt_val)
+
+        if type(self.options["cnctooldia"]) == float:
+            tools_list = [self.options["cnctooldia"]]
+        else:
+            try:
+                temp_tools = self.options["cnctooldia"].split(",")
+                tools_list = [
+                    float(eval(dia)) for dia in temp_tools if dia != ''
+                ]
+            except Exception as e:
+                log.error("GeometryObject.set_ui() -> At least one tool diameter needed. "
+                          "Verify in Edit -> Preferences -> Geometry General -> Tool dia. %s" % str(e))
+                return
+
+        self.tooluid += 1
+
+        if not self.tools:
+            for toold in tools_list:
+                new_data = deepcopy(self.default_data)
+                self.tools.update({
+                    self.tooluid: {
+                        'tooldia': float('%.*f' % (self.decimals, float(toold))),
+                        'offset': 'Path',
+                        'offset_value': 0.0,
+                        'type': _('Rough'),
+                        'tool_type': self.tool_type,
+                        'data': new_data,
+                        'solid_geometry': self.solid_geometry
+                    }
+                })
+                self.tooluid += 1
+        else:
+            # if self.tools is not empty then it can safely be assumed that it comes from an opened project.
+            # Because of the serialization the self.tools list on project save, the dict keys (members of self.tools
+            # are each a dict) are turned into strings so we rebuild the self.tools elements so the keys are
+            # again float type; dict's don't like having keys changed when iterated through therefore the need for the
+            # following convoluted way of changing the keys from string to float type
+            temp_tools = {}
+            for tooluid_key in self.tools:
+                val = deepcopy(self.tools[tooluid_key])
+                new_key = deepcopy(int(tooluid_key))
+                temp_tools[new_key] = val
+
+            self.tools.clear()
+            self.tools = deepcopy(temp_tools)
+
+        self.ui.tool_offset_entry.hide()
+        self.ui.tool_offset_lbl.hide()
+
+        # used to store the state of the mpass_cb if the selected preprocessor for geometry is hpgl
+        self.old_pp_state = self.default_data['multidepth']
+        self.old_toolchangeg_state = self.default_data['toolchange']
+
+        if not isinstance(self.ui, GeometryObjectUI):
+            log.debug("Expected a GeometryObjectUI, got %s" % type(self.ui))
+            return
+
+        self.ui.geo_tools_table.setupContextMenu()
+        self.ui.geo_tools_table.addContextMenu(
+            _("Add from Tool DB"), self.on_tool_add_from_db_clicked,
+            icon=QtGui.QIcon(self.app.resource_location + "/plus16.png"))
+        self.ui.geo_tools_table.addContextMenu(
+            _("Copy"), self.on_tool_copy,
+            icon=QtGui.QIcon(self.app.resource_location + "/copy16.png"))
+        self.ui.geo_tools_table.addContextMenu(
+            _("Delete"), lambda: self.on_tool_delete(all_tools=None),
+            icon=QtGui.QIcon(self.app.resource_location + "/delete32.png"))
+
+        # Show/Hide Advanced Options
+        if self.app.defaults["global_app_level"] == 'b':
+            self.ui.level.setText('<span style="color:green;"><b>%s</b></span>' % _('Basic'))
+
+            self.ui.geo_tools_table.setColumnHidden(2, True)
+            self.ui.geo_tools_table.setColumnHidden(3, True)
+            # self.ui.geo_tools_table.setColumnHidden(4, True)
+            self.ui.addtool_entry_lbl.hide()
+            self.ui.addtool_entry.hide()
+            self.ui.addtool_btn.hide()
+            self.ui.copytool_btn.hide()
+            self.ui.deltool_btn.hide()
+            # self.ui.endz_label.hide()
+            # self.ui.endz_entry.hide()
+            self.ui.fr_rapidlabel.hide()
+            self.ui.feedrate_rapid_entry.hide()
+            self.ui.extracut_cb.hide()
+            self.ui.e_cut_entry.hide()
+            self.ui.pdepth_label.hide()
+            self.ui.pdepth_entry.hide()
+            self.ui.feedrate_probe_label.hide()
+            self.ui.feedrate_probe_entry.hide()
+        else:
+            self.ui.level.setText('<span style="color:red;"><b>%s</b></span>' % _('Advanced'))
+
+        self.ui.e_cut_entry.setDisabled(False) if self.app.defaults['geometry_extracut'] else \
+            self.ui.e_cut_entry.setDisabled(True)
+        self.ui.extracut_cb.toggled.connect(lambda state: self.ui.e_cut_entry.setDisabled(not state))
+
+        self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
+        self.ui.generate_cnc_button.clicked.connect(self.on_generatecnc_button_click)
+        self.ui.paint_tool_button.clicked.connect(lambda: self.app.paint_tool.run(toggle=False))
+        self.ui.generate_ncc_button.clicked.connect(lambda: self.app.ncclear_tool.run(toggle=False))
+        self.ui.pp_geometry_name_cb.activated.connect(self.on_pp_changed)
+
+        self.ui.tipdia_entry.valueChanged.connect(self.update_cutz)
+        self.ui.tipangle_entry.valueChanged.connect(self.update_cutz)
+
+        self.ui.addtool_from_db_btn.clicked.connect(self.on_tool_add_from_db_clicked)
+        self.ui.apply_param_to_all.clicked.connect(self.on_apply_param_to_all_clicked)
+        self.ui.cutz_entry.returnPressed.connect(self.on_cut_z_changed)
+
+    def on_cut_z_changed(self):
+        self.old_cutz = self.ui.cutz_entry.get_value()
+
+    def set_tool_offset_visibility(self, current_row):
+        if current_row is None:
+            return
+        try:
+            tool_offset = self.ui.geo_tools_table.cellWidget(current_row, 2)
+            if tool_offset is not None:
+                tool_offset_txt = tool_offset.currentText()
+                if tool_offset_txt == 'Custom':
+                    self.ui.tool_offset_entry.show()
+                    self.ui.tool_offset_lbl.show()
+                else:
+                    self.ui.tool_offset_entry.hide()
+                    self.ui.tool_offset_lbl.hide()
+        except Exception as e:
+            log.debug("set_tool_offset_visibility() --> " + str(e))
+            return
+
+    def on_offset_value_edited(self):
+        """
+        This will save the offset_value into self.tools storage whenever the offset value is edited
+        :return:
+        """
+
+        for current_row in self.ui.geo_tools_table.selectedItems():
+            # sometime the header get selected and it has row number -1
+            # we don't want to do anything with the header :)
+            if current_row.row() < 0:
+                continue
+            tool_uid = int(self.ui.geo_tools_table.item(current_row.row(), 5).text())
+            self.set_tool_offset_visibility(current_row.row())
+
+            for tooluid_key, tooluid_value in self.tools.items():
+                if int(tooluid_key) == tool_uid:
+                    try:
+                        tooluid_value['offset_value'] = float(self.ui.tool_offset_entry.get_value())
+                    except ValueError:
+                        # try to convert comma to decimal point. if it's still not working error message and return
+                        try:
+                            tooluid_value['offset_value'] = float(
+                                self.ui.tool_offset_entry.get_value().replace(',', '.')
+                            )
+                        except ValueError:
+                            self.app.inform.emit('[ERROR_NOTCL] %s' %
+                                                 _("Wrong value format entered, use a number."))
+                            return
+
+    def ui_connect(self):
+        # on any change to the widgets that matter it will be called self.gui_form_to_storage which will save the
+        # changes in geometry UI
+        for i in self.param_fields:
+            current_widget = self.param_fields[i]
+            if isinstance(current_widget, FCCheckBox):
+                current_widget.stateChanged.connect(self.gui_form_to_storage)
+            elif isinstance(current_widget, FCComboBox):
+                current_widget.currentIndexChanged.connect(self.gui_form_to_storage)
+            elif isinstance(current_widget, FloatEntry) or isinstance(current_widget, LengthEntry) or \
+                    isinstance(current_widget, FCEntry) or isinstance(current_widget, IntEntry):
+                current_widget.editingFinished.connect(self.gui_form_to_storage)
+            elif isinstance(current_widget, FCSpinner) or isinstance(current_widget, FCDoubleSpinner):
+                current_widget.returnPressed.connect(self.gui_form_to_storage)
+
+        for row in range(self.ui.geo_tools_table.rowCount()):
+            for col in [2, 3, 4]:
+                self.ui.geo_tools_table.cellWidget(row, col).currentIndexChanged.connect(
+                    self.on_tooltable_cellwidget_change)
+
+        # I use lambda's because the connected functions have parameters that could be used in certain scenarios
+        self.ui.addtool_btn.clicked.connect(lambda: self.on_tool_add())
+
+        self.ui.copytool_btn.clicked.connect(lambda: self.on_tool_copy())
+        self.ui.deltool_btn.clicked.connect(lambda: self.on_tool_delete())
+
+        # self.ui.geo_tools_table.currentItemChanged.connect(self.on_row_selection_change)
+        self.ui.geo_tools_table.clicked.connect(self.on_row_selection_change)
+        self.ui.geo_tools_table.horizontalHeader().sectionClicked.connect(self.on_row_selection_change)
+
+        self.ui.geo_tools_table.itemChanged.connect(self.on_tool_edit)
+        self.ui.tool_offset_entry.returnPressed.connect(self.on_offset_value_edited)
+
+        for row in range(self.ui.geo_tools_table.rowCount()):
+            self.ui.geo_tools_table.cellWidget(row, 6).clicked.connect(self.on_plot_cb_click_table)
+        self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
+
+        # common parameters update
+        self.ui.pp_geometry_name_cb.currentIndexChanged.connect(self.update_common_param_in_storage)
+
+    def ui_disconnect(self):
+
+        # on any change to the widgets that matter it will be called self.gui_form_to_storage which will save the
+        # changes in geometry UI
+        for i in self.param_fields:
+            # current_widget = self.ui.grid3.itemAt(i).widget()
+            current_widget = self.param_fields[i]
+            if isinstance(current_widget, FCCheckBox):
+                try:
+                    current_widget.stateChanged.disconnect(self.gui_form_to_storage)
+                except (TypeError, AttributeError):
+                    pass
+            elif isinstance(current_widget, FCComboBox):
+                try:
+                    current_widget.currentIndexChanged.disconnect(self.gui_form_to_storage)
+                except (TypeError, AttributeError):
+                    pass
+            elif isinstance(current_widget, LengthEntry) or isinstance(current_widget, IntEntry) or \
+                    isinstance(current_widget, FCEntry) or isinstance(current_widget, FloatEntry):
+                try:
+                    current_widget.editingFinished.disconnect(self.gui_form_to_storage)
+                except (TypeError, AttributeError):
+                    pass
+            elif isinstance(current_widget, FCSpinner) or isinstance(current_widget, FCDoubleSpinner):
+                try:
+                    current_widget.returnPressed.disconnect(self.gui_form_to_storage)
+                except TypeError:
+                    pass
+
+        for row in range(self.ui.geo_tools_table.rowCount()):
+            for col in [2, 3, 4]:
+                try:
+                    self.ui.geo_tools_table.cellWidget(row, col).currentIndexChanged.disconnect()
+                except (TypeError, AttributeError):
+                    pass
+
+        try:
+            self.ui.addtool_btn.clicked.disconnect()
+        except (TypeError, AttributeError):
+            pass
+
+        try:
+            self.ui.copytool_btn.clicked.disconnect()
+        except (TypeError, AttributeError):
+            pass
+
+        try:
+            self.ui.deltool_btn.clicked.disconnect()
+        except (TypeError, AttributeError):
+            pass
+
+        try:
+            self.ui.geo_tools_table.clicked.disconnect()
+        except (TypeError, AttributeError):
+            pass
+        try:
+            self.ui.geo_tools_table.horizontalHeader().sectionClicked.disconnect()
+        except (TypeError, AttributeError):
+            pass
+
+        try:
+            self.ui.geo_tools_table.itemChanged.disconnect()
+        except (TypeError, AttributeError):
+            pass
+
+        try:
+            self.ui.tool_offset_entry.returnPressed.disconnect()
+        except (TypeError, AttributeError):
+            pass
+
+        for row in range(self.ui.geo_tools_table.rowCount()):
+            try:
+                self.ui.geo_tools_table.cellWidget(row, 6).clicked.disconnect()
+            except (TypeError, AttributeError):
+                pass
+
+        try:
+            self.ui.plot_cb.stateChanged.disconnect()
+        except (TypeError, AttributeError):
+            pass
+
+    def on_row_selection_change(self):
+        self.update_ui()
+
+    def update_ui(self, row=None):
+        self.ui_disconnect()
+
+        if row is None:
+            sel_rows = []
+            sel_items = self.ui.geo_tools_table.selectedItems()
+            for it in sel_items:
+                sel_rows.append(it.row())
+        else:
+            sel_rows = row if type(row) == list else [row]
+
+        if not sel_rows:
+            sel_rows = [0]
+
+        for current_row in sel_rows:
+            self.set_tool_offset_visibility(current_row)
+
+            # populate the form with the data from the tool associated with the row parameter
+            try:
+                item = self.ui.geo_tools_table.item(current_row, 5)
+                if type(item) is not None:
+                    tooluid = int(item.text())
+                else:
+                    self.ui_connect()
+                    return
+            except Exception as e:
+                log.debug("Tool missing. Add a tool in Geo Tool Table. %s" % str(e))
+                self.ui_connect()
+                return
+
+            # update the QLabel that shows for which Tool we have the parameters in the UI form
+            if len(sel_rows) == 1:
+                self.ui.tool_data_label.setText(
+                    "<b>%s: <font color='#0000FF'>%s %d</font></b>" % (_('Parameters for'), _("Tool"), tooluid)
+                )
+
+                # update the form with the V-Shape fields if V-Shape selected in the geo_tool_table
+                # also modify the Cut Z form entry to reflect the calculated Cut Z from values got from V-Shape Fields
+                try:
+                    item = self.ui.geo_tools_table.cellWidget(current_row, 4)
+                    if item is not None:
+                        tool_type_txt = item.currentText()
+                        self.ui_update_v_shape(tool_type_txt=tool_type_txt)
+                    else:
+                        self.ui_connect()
+                        return
+                except Exception as e:
+                    log.debug("Tool missing in ui_update_v_shape(). Add a tool in Geo Tool Table. %s" % str(e))
+                    return
+
+                try:
+                    # set the form with data from the newly selected tool
+                    for tooluid_key, tooluid_value in list(self.tools.items()):
+                        if int(tooluid_key) == tooluid:
+                            for key, value in list(tooluid_value.items()):
+                                if key == 'data':
+                                    form_value_storage = tooluid_value['data']
+                                    self.update_form(form_value_storage)
+                                if key == 'offset_value':
+                                    # update the offset value in the entry even if the entry is hidden
+                                    self.ui.tool_offset_entry.set_value(tooluid_value['offset_value'])
+
+                                if key == 'tool_type' and value == 'V':
+                                    self.update_cutz()
+                except Exception as e:
+                    log.debug("GeometryObject.update_ui() -> %s " % str(e))
+
+            else:
+                self.ui.tool_data_label.setText(
+                    "<b>%s: <font color='#0000FF'>%s</font></b>" % (_('Parameters for'), _("Multiple Tools"))
+                )
+
+        self.ui_connect()
+
+    def on_tool_add(self, dia=None):
+        self.ui_disconnect()
+
+        self.units = self.app.defaults['units'].upper()
+
+        if dia is not None:
+            tooldia = dia
+        else:
+            tooldia = float(self.ui.addtool_entry.get_value())
+
+        # construct a list of all 'tooluid' in the self.tools
+        # tool_uid_list = []
+        # for tooluid_key in self.tools:
+        #     tool_uid_list.append(int(tooluid_key))
+        tool_uid_list = [int(tooluid_key) for tooluid_key in self.tools]
+
+        # find maximum from the temp_uid, add 1 and this is the new 'tooluid'
+        max_uid = max(tool_uid_list) if tool_uid_list else 0
+        self.tooluid = max_uid + 1
+
+        tooldia = float('%.*f' % (self.decimals, tooldia))
+
+        # here we actually add the new tool; if there is no tool in the tool table we add a tool with default data
+        # otherwise we add a tool with data copied from last tool
+        if self.tools:
+            last_data = self.tools[max_uid]['data']
+            last_offset = self.tools[max_uid]['offset']
+            last_offset_value = self.tools[max_uid]['offset_value']
+            last_type = self.tools[max_uid]['type']
+            last_tool_type = self.tools[max_uid]['tool_type']
+            last_solid_geometry = self.tools[max_uid]['solid_geometry']
+
+            # if previous geometry was empty (it may happen for the first tool added)
+            # then copy the object.solid_geometry
+            if not last_solid_geometry:
+                last_solid_geometry = self.solid_geometry
+
+            self.tools.update({
+                self.tooluid: {
+                    'tooldia': tooldia,
+                    'offset': last_offset,
+                    'offset_value': last_offset_value,
+                    'type': last_type,
+                    'tool_type': last_tool_type,
+                    'data': deepcopy(last_data),
+                    'solid_geometry': deepcopy(last_solid_geometry)
+                }
+            })
+        else:
+            self.tools.update({
+                self.tooluid: {
+                    'tooldia': tooldia,
+                    'offset': 'Path',
+                    'offset_value': 0.0,
+                    'type': _('Rough'),
+                    'tool_type': 'C1',
+                    'data': deepcopy(self.default_data),
+                    'solid_geometry': self.solid_geometry
+                }
+            })
+
+        self.tools[self.tooluid]['data']['name'] = self.options['name']
+
+        self.ui.tool_offset_entry.hide()
+        self.ui.tool_offset_lbl.hide()
+
+        # we do this HACK to make sure the tools attribute to be serialized is updated in the self.ser_attrs list
+        try:
+            self.ser_attrs.remove('tools')
+        except TypeError:
+            pass
+        self.ser_attrs.append('tools')
+
+        self.app.inform.emit('[success] %s' % _("Tool added in Tool Table."))
+        self.ui_connect()
+        self.build_ui()
+
+        # if there is no tool left in the Tools Table, enable the parameters GUI
+        if self.ui.geo_tools_table.rowCount() != 0:
+            self.ui.geo_param_frame.setDisabled(False)
+
+    def on_tool_add_from_db_clicked(self):
+        """
+        Called when the user wants to add a new tool from Tools Database. It will create the Tools Database object
+        and display the Tools Database tab in the form needed for the Tool adding
+        :return: None
+        """
+
+        # if the Tools Database is already opened focus on it
+        for idx in range(self.app.ui.plot_tab_area.count()):
+            if self.app.ui.plot_tab_area.tabText(idx) == _("Tools Database"):
+                self.app.ui.plot_tab_area.setCurrentWidget(self.app.tools_db_tab)
+                break
+        self.app.on_tools_database()
+        self.app.tools_db_tab.ok_to_add = True
+        self.app.tools_db_tab.buttons_frame.hide()
+        self.app.tools_db_tab.add_tool_from_db.show()
+        self.app.tools_db_tab.cancel_tool_from_db.show()
+
+    def on_tool_from_db_inserted(self, tool):
+        """
+        Called from the Tools DB object through a App method when adding a tool from Tools Database
+        :param tool: a dict with the tool data
+        :return: None
+        """
+
+        self.ui_disconnect()
+        self.units = self.app.defaults['units'].upper()
+
+        tooldia = float(tool['tooldia'])
+
+        # construct a list of all 'tooluid' in the self.tools
+        tool_uid_list = []
+        for tooluid_key in self.tools:
+            tool_uid_item = int(tooluid_key)
+            tool_uid_list.append(tool_uid_item)
+
+        # find maximum from the temp_uid, add 1 and this is the new 'tooluid'
+        if not tool_uid_list:
+            max_uid = 0
+        else:
+            max_uid = max(tool_uid_list)
+        self.tooluid = max_uid + 1
+
+        tooldia = float('%.*f' % (self.decimals, tooldia))
+
+        self.tools.update({
+            self.tooluid: {
+                'tooldia': tooldia,
+                'offset': tool['offset'],
+                'offset_value': float(tool['offset_value']),
+                'type': tool['type'],
+                'tool_type': tool['tool_type'],
+                'data': deepcopy(tool['data']),
+                'solid_geometry': self.solid_geometry
+            }
+        })
+
+        self.tools[self.tooluid]['data']['name'] = self.options['name']
+
+        self.ui.tool_offset_entry.hide()
+        self.ui.tool_offset_lbl.hide()
+
+        # we do this HACK to make sure the tools attribute to be serialized is updated in the self.ser_attrs list
+        try:
+            self.ser_attrs.remove('tools')
+        except TypeError:
+            pass
+        self.ser_attrs.append('tools')
+
+        self.ui_connect()
+        self.build_ui()
+
+        # if there is no tool left in the Tools Table, enable the parameters GUI
+        if self.ui.geo_tools_table.rowCount() != 0:
+            self.ui.geo_param_frame.setDisabled(False)
+
+    def on_tool_copy(self, all_tools=None):
+        self.ui_disconnect()
+
+        # find the tool_uid maximum value in the self.tools
+        uid_list = []
+        for key in self.tools:
+            uid_list.append(int(key))
+        try:
+            max_uid = max(uid_list, key=int)
+        except ValueError:
+            max_uid = 0
+
+        if all_tools is None:
+            if self.ui.geo_tools_table.selectedItems():
+                for current_row in self.ui.geo_tools_table.selectedItems():
+                    # sometime the header get selected and it has row number -1
+                    # we don't want to do anything with the header :)
+                    if current_row.row() < 0:
+                        continue
+                    try:
+                        tooluid_copy = int(self.ui.geo_tools_table.item(current_row.row(), 5).text())
+                        self.set_tool_offset_visibility(current_row.row())
+                        max_uid += 1
+                        self.tools[int(max_uid)] = deepcopy(self.tools[tooluid_copy])
+                    except AttributeError:
+                        self.app.inform.emit('[WARNING_NOTCL] %s' % _("Failed. Select a tool to copy."))
+                        self.ui_connect()
+                        self.build_ui()
+                        return
+                    except Exception as e:
+                        log.debug("on_tool_copy() --> " + str(e))
+                # deselect the table
+                # self.ui.geo_tools_table.clearSelection()
+            else:
+                self.app.inform.emit('[WARNING_NOTCL] %s' % _("Failed. Select a tool to copy."))
+                self.ui_connect()
+                self.build_ui()
+                return
+        else:
+            # we copy all tools in geo_tools_table
+            try:
+                temp_tools = deepcopy(self.tools)
+                max_uid += 1
+                for tooluid in temp_tools:
+                    self.tools[int(max_uid)] = deepcopy(temp_tools[tooluid])
+                temp_tools.clear()
+            except Exception as e:
+                log.debug("on_tool_copy() --> " + str(e))
+
+        # if there are no more tools in geo tools table then hide the tool offset
+        if not self.tools:
+            self.ui.tool_offset_entry.hide()
+            self.ui.tool_offset_lbl.hide()
+
+        # we do this HACK to make sure the tools attribute to be serialized is updated in the self.ser_attrs list
+        try:
+            self.ser_attrs.remove('tools')
+        except ValueError:
+            pass
+        self.ser_attrs.append('tools')
+
+        self.ui_connect()
+        self.build_ui()
+        self.app.inform.emit('[success] %s' % _("Tool was copied in Tool Table."))
+
+    def on_tool_edit(self, current_item):
+        self.ui_disconnect()
+
+        current_row = current_item.row()
+        try:
+            d = float(self.ui.geo_tools_table.item(current_row, 1).text())
+        except ValueError:
+            # try to convert comma to decimal point. if it's still not working error message and return
+            try:
+                d = float(self.ui.geo_tools_table.item(current_row, 1).text().replace(',', '.'))
+            except ValueError:
+                self.app.inform.emit('[ERROR_NOTCL] %s' % _("Wrong value format entered, use a number."))
+                return
+
+        tool_dia = float('%.*f' % (self.decimals, d))
+        tooluid = int(self.ui.geo_tools_table.item(current_row, 5).text())
+
+        self.tools[tooluid]['tooldia'] = tool_dia
+
+        try:
+            self.ser_attrs.remove('tools')
+            self.ser_attrs.append('tools')
+        except (TypeError, ValueError):
+            pass
+
+        self.app.inform.emit('[success] %s' % _("Tool was edited in Tool Table."))
+        self.ui_connect()
+        self.build_ui()
+
+    def on_tool_delete(self, all_tools=None):
+        self.ui_disconnect()
+
+        if all_tools is None:
+            if self.ui.geo_tools_table.selectedItems():
+                for current_row in self.ui.geo_tools_table.selectedItems():
+                    # sometime the header get selected and it has row number -1
+                    # we don't want to do anything with the header :)
+                    if current_row.row() < 0:
+                        continue
+                    try:
+                        tooluid_del = int(self.ui.geo_tools_table.item(current_row.row(), 5).text())
+                        self.set_tool_offset_visibility(current_row.row())
+
+                        temp_tools = deepcopy(self.tools)
+                        for tooluid_key in self.tools:
+                            if int(tooluid_key) == tooluid_del:
+                                # if the self.tools has only one tool and we delete it then we move the solid_geometry
+                                # as a property of the object otherwise there will be nothing to hold it
+                                if len(self.tools) == 1:
+                                    self.solid_geometry = deepcopy(self.tools[tooluid_key]['solid_geometry'])
+                                temp_tools.pop(tooluid_del, None)
+                        self.tools = deepcopy(temp_tools)
+                        temp_tools.clear()
+                    except AttributeError:
+                        self.app.inform.emit('[WARNING_NOTCL] %s' % _("Failed. Select a tool to delete."))
+                        self.ui_connect()
+                        self.build_ui()
+                        return
+                    except Exception as e:
+                        log.debug("on_tool_delete() --> " + str(e))
+                # deselect the table
+                # self.ui.geo_tools_table.clearSelection()
+            else:
+                self.app.inform.emit('[WARNING_NOTCL] %s' % _("Failed. Select a tool to delete."))
+                self.ui_connect()
+                self.build_ui()
+                return
+        else:
+            # we delete all tools in geo_tools_table
+            self.tools.clear()
+
+        self.app.plot_all()
+
+        # if there are no more tools in geo tools table then hide the tool offset
+        if not self.tools:
+            self.ui.tool_offset_entry.hide()
+            self.ui.tool_offset_lbl.hide()
+
+        # we do this HACK to make sure the tools attribute to be serialized is updated in the self.ser_attrs list
+        try:
+            self.ser_attrs.remove('tools')
+        except TypeError:
+            pass
+        self.ser_attrs.append('tools')
+
+        self.ui_connect()
+        self.build_ui()
+        self.app.inform.emit('[success] %s' % _("Tool was deleted in Tool Table."))
+
+        obj_active = self.app.collection.get_active()
+        # if the object was MultiGeo and now it has no tool at all (therefore no geometry)
+        # we make it back SingleGeo
+        if self.ui.geo_tools_table.rowCount() <= 0:
+            obj_active.multigeo = False
+            obj_active.options['xmin'] = 0
+            obj_active.options['ymin'] = 0
+            obj_active.options['xmax'] = 0
+            obj_active.options['ymax'] = 0
+
+        if obj_active.multigeo is True:
+            try:
+                xmin, ymin, xmax, ymax = obj_active.bounds()
+                obj_active.options['xmin'] = xmin
+                obj_active.options['ymin'] = ymin
+                obj_active.options['xmax'] = xmax
+                obj_active.options['ymax'] = ymax
+            except Exception:
+                obj_active.options['xmin'] = 0
+                obj_active.options['ymin'] = 0
+                obj_active.options['xmax'] = 0
+                obj_active.options['ymax'] = 0
+
+        # if there is no tool left in the Tools Table, disable the parameters GUI
+        if self.ui.geo_tools_table.rowCount() == 0:
+            self.ui.geo_param_frame.setDisabled(True)
+
+    def ui_update_v_shape(self, tool_type_txt):
+        if tool_type_txt == 'V':
+            self.ui.tipdialabel.show()
+            self.ui.tipdia_entry.show()
+            self.ui.tipanglelabel.show()
+            self.ui.tipangle_entry.show()
+            self.ui.cutz_entry.setDisabled(True)
+
+            self.update_cutz()
+        else:
+            self.ui.tipdialabel.hide()
+            self.ui.tipdia_entry.hide()
+            self.ui.tipanglelabel.hide()
+            self.ui.tipangle_entry.hide()
+            self.ui.cutz_entry.setDisabled(False)
+
+    def update_cutz(self):
+        vdia = float(self.ui.tipdia_entry.get_value())
+        half_vangle = float(self.ui.tipangle_entry.get_value()) / 2
+
+        row = self.ui.geo_tools_table.currentRow()
+        tool_uid_item = self.ui.geo_tools_table.item(row, 5)
+        if tool_uid_item is None:
+            return
+        tool_uid = int(tool_uid_item.text())
+
+        tool_dia_item = self.ui.geo_tools_table.item(row, 1)
+        if tool_dia_item is None:
+            return
+        tooldia = float(tool_dia_item.text())
+
+        try:
+            new_cutz = (tooldia - vdia) / (2 * math.tan(math.radians(half_vangle)))
+        except ZeroDivisionError:
+            new_cutz = self.old_cutz
+
+        new_cutz = float('%.*f' % (self.decimals, new_cutz)) * -1.0   # this value has to be negative
+
+        self.ui.cutz_entry.set_value(new_cutz)
+
+        # store the new CutZ value into storage (self.tools)
+        for tooluid_key, tooluid_value in self.tools.items():
+            if int(tooluid_key) == tool_uid:
+                tooluid_value['data']['cutz'] = new_cutz
+
+    def on_tooltable_cellwidget_change(self):
+        cw = self.sender()
+        # assert isinstance(cw, FCComboBox) or isinstance(cw, FCCheckBox),\
+        #     "Expected a FCCombobox or a FCCheckbox got %s" % type(cw)
+        cw_index = self.ui.geo_tools_table.indexAt(cw.pos())
+        cw_row = cw_index.row()
+        cw_col = cw_index.column()
+        current_uid = int(self.ui.geo_tools_table.item(cw_row, 5).text())
+
+        # store the text of the cellWidget that changed it's index in the self.tools
+        for tooluid_key, tooluid_value in self.tools.items():
+            if int(tooluid_key) == current_uid:
+                cb_txt = cw.currentText()
+                if cw_col == 2:
+                    tooluid_value['offset'] = cb_txt
+                    if cb_txt == 'Custom':
+                        self.ui.tool_offset_entry.show()
+                        self.ui.tool_offset_lbl.show()
+                    else:
+                        self.ui.tool_offset_entry.hide()
+                        self.ui.tool_offset_lbl.hide()
+                        # reset the offset_value in storage self.tools
+                        tooluid_value['offset_value'] = 0.0
+                elif cw_col == 3:
+                    # force toolpath type as 'Iso' if the tool type is V-Shape
+                    if self.ui.geo_tools_table.cellWidget(cw_row, 4).currentText() == 'V':
+                        tooluid_value['type'] = _('Iso')
+                        idx = self.ui.geo_tools_table.cellWidget(cw_row, 3).findText(_('Iso'))
+                        self.ui.geo_tools_table.cellWidget(cw_row, 3).setCurrentIndex(idx)
+                    else:
+                        tooluid_value['type'] = cb_txt
+                elif cw_col == 4:
+                    tooluid_value['tool_type'] = cb_txt
+
+                    # if the tool_type selected is V-Shape then autoselect the toolpath type as Iso
+                    if cb_txt == 'V':
+                        idx = self.ui.geo_tools_table.cellWidget(cw_row, 3).findText(_('Iso'))
+                        self.ui.geo_tools_table.cellWidget(cw_row, 3).setCurrentIndex(idx)
+                    else:
+                        self.ui.cutz_entry.set_value(self.old_cutz)
+
+                self.ui_update_v_shape(tool_type_txt=self.ui.geo_tools_table.cellWidget(cw_row, 4).currentText())
+
+    def update_form(self, dict_storage):
+        for form_key in self.form_fields:
+            for storage_key in dict_storage:
+                if form_key == storage_key:
+                    try:
+                        self.form_fields[form_key].set_value(dict_storage[form_key])
+                    except Exception as e:
+                        log.debug(str(e))
+
+        # this is done here because those buttons control through OptionalInputSelection if some entry's are Enabled
+        # or not. But due of using the ui_disconnect() status is no longer updated and I had to do it here
+        self.ui.ois_dwell_geo.on_cb_change()
+        self.ui.ois_mpass_geo.on_cb_change()
+        self.ui.ois_tcz_geo.on_cb_change()
+
+    def on_apply_param_to_all_clicked(self):
+        if self.ui.geo_tools_table.rowCount() == 0:
+            # there is no tool in tool table so we can't save the GUI elements values to storage
+            log.debug("GeometryObject.gui_form_to_storage() --> no tool in Tools Table, aborting.")
+            return
+
+        self.ui_disconnect()
+
+        row = self.ui.geo_tools_table.currentRow()
+        if row < 0:
+            row = 0
+
+        # store all the data associated with the row parameter to the self.tools storage
+        tooldia_item = float(self.ui.geo_tools_table.item(row, 1).text())
+        offset_item = self.ui.geo_tools_table.cellWidget(row, 2).currentText()
+        type_item = self.ui.geo_tools_table.cellWidget(row, 3).currentText()
+        tool_type_item = self.ui.geo_tools_table.cellWidget(row, 4).currentText()
+
+        offset_value_item = float(self.ui.tool_offset_entry.get_value())
+
+        # this new dict will hold the actual useful data, another dict that is the value of key 'data'
+        temp_tools = {}
+        temp_dia = {}
+        temp_data = {}
+
+        for tooluid_key, tooluid_value in self.tools.items():
+            for key, value in tooluid_value.items():
+                if key == 'tooldia':
+                    temp_dia[key] = tooldia_item
+                # update the 'offset', 'type' and 'tool_type' sections
+                if key == 'offset':
+                    temp_dia[key] = offset_item
+                if key == 'type':
+                    temp_dia[key] = type_item
+                if key == 'tool_type':
+                    temp_dia[key] = tool_type_item
+                if key == 'offset_value':
+                    temp_dia[key] = offset_value_item
+
+                if key == 'data':
+                    # update the 'data' section
+                    for data_key in tooluid_value[key].keys():
+                        for form_key, form_value in self.form_fields.items():
+                            if form_key == data_key:
+                                temp_data[data_key] = form_value.get_value()
+                        # make sure we make a copy of the keys not in the form (we may use 'data' keys that are
+                        # updated from self.app.defaults
+                        if data_key not in self.form_fields:
+                            temp_data[data_key] = value[data_key]
+                    temp_dia[key] = deepcopy(temp_data)
+                    temp_data.clear()
+
+                if key == 'solid_geometry':
+                    temp_dia[key] = deepcopy(self.tools[tooluid_key]['solid_geometry'])
+
+                temp_tools[tooluid_key] = deepcopy(temp_dia)
+
+        self.tools.clear()
+        self.tools = deepcopy(temp_tools)
+        temp_tools.clear()
+
+        self.ui_connect()
+
+    def gui_form_to_storage(self):
+        if self.ui.geo_tools_table.rowCount() == 0:
+            # there is no tool in tool table so we can't save the GUI elements values to storage
+            log.debug("GeometryObject.gui_form_to_storage() --> no tool in Tools Table, aborting.")
+            return
+
+        self.ui_disconnect()
+        widget_changed = self.sender()
+        try:
+            widget_idx = self.ui.grid3.indexOf(widget_changed)
+        except Exception:
+            return
+
+        # those are the indexes for the V-Tip Dia and V-Tip Angle, if edited calculate the new Cut Z
+        if widget_idx == 1 or widget_idx == 3:
+            self.update_cutz()
+
+        # the original connect() function of the OptionalInputSelection is no longer working because of the
+        # ui_diconnect() so I use this 'hack'
+        if isinstance(widget_changed, FCCheckBox):
+            if widget_changed.text() == 'Multi-Depth:':
+                self.ui.ois_mpass_geo.on_cb_change()
+
+            if widget_changed.text() == 'Tool change':
+                self.ui.ois_tcz_geo.on_cb_change()
+
+            if widget_changed.text() == 'Dwell:':
+                self.ui.ois_dwell_geo.on_cb_change()
+
+        row = self.ui.geo_tools_table.currentRow()
+        if row < 0:
+            row = 0
+
+        # store all the data associated with the row parameter to the self.tools storage
+        tooldia_item = float(self.ui.geo_tools_table.item(row, 1).text())
+        offset_item = self.ui.geo_tools_table.cellWidget(row, 2).currentText()
+        type_item = self.ui.geo_tools_table.cellWidget(row, 3).currentText()
+        tool_type_item = self.ui.geo_tools_table.cellWidget(row, 4).currentText()
+        tooluid_item = int(self.ui.geo_tools_table.item(row, 5).text())
+
+        offset_value_item = float(self.ui.tool_offset_entry.get_value())
+
+        # this new dict will hold the actual useful data, another dict that is the value of key 'data'
+        temp_tools = {}
+        temp_dia = {}
+        temp_data = {}
+
+        for tooluid_key, tooluid_value in self.tools.items():
+            if int(tooluid_key) == tooluid_item:
+                for key, value in tooluid_value.items():
+                    if key == 'tooldia':
+                        temp_dia[key] = tooldia_item
+                    # update the 'offset', 'type' and 'tool_type' sections
+                    if key == 'offset':
+                        temp_dia[key] = offset_item
+                    if key == 'type':
+                        temp_dia[key] = type_item
+                    if key == 'tool_type':
+                        temp_dia[key] = tool_type_item
+                    if key == 'offset_value':
+                        temp_dia[key] = offset_value_item
+
+                    if key == 'data':
+                        # update the 'data' section
+                        for data_key in tooluid_value[key].keys():
+                            for form_key, form_value in self.form_fields.items():
+                                if form_key == data_key:
+                                    temp_data[data_key] = form_value.get_value()
+                            # make sure we make a copy of the keys not in the form (we may use 'data' keys that are
+                            # updated from self.app.defaults
+                            if data_key not in self.form_fields:
+                                temp_data[data_key] = value[data_key]
+                        temp_dia[key] = deepcopy(temp_data)
+                        temp_data.clear()
+
+                    if key == 'solid_geometry':
+                        temp_dia[key] = deepcopy(self.tools[tooluid_key]['solid_geometry'])
+
+                    temp_tools[tooluid_key] = deepcopy(temp_dia)
+            else:
+                temp_tools[tooluid_key] = deepcopy(tooluid_value)
+
+        self.tools.clear()
+        self.tools = deepcopy(temp_tools)
+        temp_tools.clear()
+        self.ui_connect()
+
+    def update_common_param_in_storage(self):
+        for tooluid_value in self.tools.values():
+            tooluid_value['data']['ppname_g'] = self.ui.pp_geometry_name_cb.get_value()
+
+    def select_tools_table_row(self, row, clearsel=None):
+        if clearsel:
+            self.ui.geo_tools_table.clearSelection()
+
+        if self.ui.geo_tools_table.rowCount() > 0:
+            # self.ui.geo_tools_table.item(row, 0).setSelected(True)
+            self.ui.geo_tools_table.setCurrentItem(self.ui.geo_tools_table.item(row, 0))
+
+    def export_dxf(self):
+        dwg = None
+        try:
+            dwg = ezdxf.new('R2010')
+            msp = dwg.modelspace()
+
+            def g2dxf(dxf_space, geo_obj):
+                if isinstance(geo_obj, MultiPolygon):
+                    for poly in geo_obj:
+                        ext_points = list(poly.exterior.coords)
+                        dxf_space.add_lwpolyline(ext_points)
+                        for interior in poly.interiors:
+                            dxf_space.add_lwpolyline(list(interior.coords))
+                if isinstance(geo_obj, Polygon):
+                    ext_points = list(geo_obj.exterior.coords)
+                    dxf_space.add_lwpolyline(ext_points)
+                    for interior in geo_obj.interiors:
+                        dxf_space.add_lwpolyline(list(interior.coords))
+                if isinstance(geo_obj, MultiLineString):
+                    for line in geo_obj:
+                        dxf_space.add_lwpolyline(list(line.coords))
+                if isinstance(geo_obj, LineString) or isinstance(geo_obj, LinearRing):
+                    dxf_space.add_lwpolyline(list(geo_obj.coords))
+
+            multigeo_solid_geometry = []
+            if self.multigeo:
+                for tool in self.tools:
+                    multigeo_solid_geometry += self.tools[tool]['solid_geometry']
+            else:
+                multigeo_solid_geometry = self.solid_geometry
+
+            for geo in multigeo_solid_geometry:
+                if type(geo) == list:
+                    for g in geo:
+                        g2dxf(msp, g)
+                else:
+                    g2dxf(msp, geo)
+
+                # points = GeometryObject.get_pts(geo)
+                # msp.add_lwpolyline(points)
+        except Exception as e:
+            log.debug(str(e))
+
+        return dwg
+
+    def get_selected_tools_table_items(self):
+        """
+        Returns a list of lists, each list in the list is made out of row elements
+
+        :return: List of table_tools items.
+        :rtype: list
+        """
+        table_tools_items = []
+        if self.multigeo:
+            for x in self.ui.geo_tools_table.selectedItems():
+                elem = []
+                txt = ''
+
+                for column in range(0, self.ui.geo_tools_table.columnCount()):
+                    try:
+                        txt = self.ui.geo_tools_table.item(x.row(), column).text()
+                    except AttributeError:
+                        try:
+                            txt = self.ui.geo_tools_table.cellWidget(x.row(), column).currentText()
+                        except AttributeError:
+                            pass
+                    elem.append(txt)
+                table_tools_items.append(deepcopy(elem))
+                # table_tools_items.append([self.ui.geo_tools_table.item(x.row(), column).text()
+                #                           for column in range(0, self.ui.geo_tools_table.columnCount())])
+        else:
+            for x in self.ui.geo_tools_table.selectedItems():
+                r = []
+                txt = ''
+
+                # the last 2 columns for single-geo geometry are irrelevant and create problems reading
+                # so we don't read them
+                for column in range(0, self.ui.geo_tools_table.columnCount() - 2):
+                    # the columns have items that have text but also have items that are widgets
+                    # for which the text they hold has to be read differently
+                    try:
+                        txt = self.ui.geo_tools_table.item(x.row(), column).text()
+                    except AttributeError:
+                        try:
+                            txt = self.ui.geo_tools_table.cellWidget(x.row(), column).currentText()
+                        except AttributeError:
+                            pass
+                    r.append(txt)
+                table_tools_items.append(r)
+
+        for item in table_tools_items:
+            item[0] = str(item[0])
+        return table_tools_items
+
+    def on_pp_changed(self):
+        current_pp = self.ui.pp_geometry_name_cb.get_value()
+        if current_pp == 'hpgl':
+            self.old_pp_state = self.ui.mpass_cb.get_value()
+            self.old_toolchangeg_state = self.ui.toolchangeg_cb.get_value()
+
+            self.ui.mpass_cb.set_value(False)
+            self.ui.mpass_cb.setDisabled(True)
+
+            self.ui.toolchangeg_cb.set_value(True)
+            self.ui.toolchangeg_cb.setDisabled(True)
+        else:
+            self.ui.mpass_cb.set_value(self.old_pp_state)
+            self.ui.mpass_cb.setDisabled(False)
+
+            self.ui.toolchangeg_cb.set_value(self.old_toolchangeg_state)
+            self.ui.toolchangeg_cb.setDisabled(False)
+
+        if "toolchange_probe" in current_pp.lower():
+            self.ui.pdepth_entry.setVisible(True)
+            self.ui.pdepth_label.show()
+
+            self.ui.feedrate_probe_entry.setVisible(True)
+            self.ui.feedrate_probe_label.show()
+        else:
+            self.ui.pdepth_entry.setVisible(False)
+            self.ui.pdepth_label.hide()
+
+            self.ui.feedrate_probe_entry.setVisible(False)
+            self.ui.feedrate_probe_label.hide()
+
+        if 'marlin' in current_pp.lower() or 'custom' in current_pp.lower():
+            self.ui.fr_rapidlabel.show()
+            self.ui.feedrate_rapid_entry.show()
+        else:
+            self.ui.fr_rapidlabel.hide()
+            self.ui.feedrate_rapid_entry.hide()
+
+        if 'laser' in current_pp.lower():
+            self.ui.cutzlabel.hide()
+            self.ui.cutz_entry.hide()
+            try:
+                self.ui.mpass_cb.hide()
+                self.ui.maxdepth_entry.hide()
+            except AttributeError:
+                pass
+
+            if 'marlin' in current_pp.lower():
+                self.ui.travelzlabel.setText('%s:' % _("Focus Z"))
+                self.ui.endz_label.show()
+                self.ui.endz_entry.show()
+            else:
+                self.ui.travelzlabel.hide()
+                self.ui.travelz_entry.hide()
+
+                self.ui.endz_label.hide()
+                self.ui.endz_entry.hide()
+
+            try:
+                self.ui.frzlabel.hide()
+                self.ui.feedrate_z_entry.hide()
+            except AttributeError:
+                pass
+
+            self.ui.dwell_cb.hide()
+            self.ui.dwelltime_entry.hide()
+
+            self.ui.spindle_label.setText('%s:' % _("Laser Power"))
+
+            try:
+                self.ui.tool_offset_label.hide()
+                self.ui.offset_entry.hide()
+            except AttributeError:
+                pass
+        else:
+            self.ui.cutzlabel.show()
+            self.ui.cutz_entry.show()
+            try:
+                self.ui.mpass_cb.show()
+                self.ui.maxdepth_entry.show()
+            except AttributeError:
+                pass
+
+            self.ui.travelzlabel.setText('%s:' % _('Travel Z'))
+
+            self.ui.travelzlabel.show()
+            self.ui.travelz_entry.show()
+
+            self.ui.endz_label.show()
+            self.ui.endz_entry.show()
+
+            try:
+                self.ui.frzlabel.show()
+                self.ui.feedrate_z_entry.show()
+            except AttributeError:
+                pass
+            self.ui.dwell_cb.show()
+            self.ui.dwelltime_entry.show()
+
+            self.ui.spindle_label.setText('%s:' % _('Spindle speed'))
+
+            try:
+                self.ui.tool_offset_lbl.show()
+                self.ui.offset_entry.show()
+            except AttributeError:
+                pass
+
+    def on_generatecnc_button_click(self, *args):
+        log.debug("Generating CNCJob from Geometry ...")
+        self.app.report_usage("geometry_on_generatecnc_button")
+
+        # this reads the values in the UI form to the self.options dictionary
+        self.read_form()
+
+        self.sel_tools = {}
+
+        try:
+            if self.special_group:
+                self.app.inform.emit(
+                    '[WARNING_NOTCL] %s %s %s.' %
+                    (_("This Geometry can't be processed because it is"), str(self.special_group), _("geometry"))
+                )
+                return
+        except AttributeError:
+            pass
+
+        # test to see if we have tools available in the tool table
+        if self.ui.geo_tools_table.selectedItems():
+            for x in self.ui.geo_tools_table.selectedItems():
+                # try:
+                #     tooldia = float(self.ui.geo_tools_table.item(x.row(), 1).text())
+                # except ValueError:
+                #     # try to convert comma to decimal point. if it's still not working error message and return
+                #     try:
+                #         tooldia = float(self.ui.geo_tools_table.item(x.row(), 1).text().replace(',', '.'))
+                #     except ValueError:
+                #         self.app.inform.emit('[ERROR_NOTCL] %s' %
+                #                              _("Wrong value format entered, use a number."))
+                #         return
+                tooluid = int(self.ui.geo_tools_table.item(x.row(), 5).text())
+
+                for tooluid_key, tooluid_value in self.tools.items():
+                    if int(tooluid_key) == tooluid:
+                        self.sel_tools.update({
+                            tooluid: deepcopy(tooluid_value)
+                        })
+            self.mtool_gen_cncjob()
+            self.ui.geo_tools_table.clearSelection()
+
+        elif self.ui.geo_tools_table.rowCount() == 1:
+            tooluid = int(self.ui.geo_tools_table.item(0, 5).text())
+
+            for tooluid_key, tooluid_value in self.tools.items():
+                if int(tooluid_key) == tooluid:
+                    self.sel_tools.update({
+                        tooluid: deepcopy(tooluid_value)
+                    })
+            self.mtool_gen_cncjob()
+            self.ui.geo_tools_table.clearSelection()
+
+        else:
+            self.app.inform.emit('[ERROR_NOTCL] %s' % _("Failed. No tool selected in the tool table ..."))
+
+    def mtool_gen_cncjob(self, outname=None, tools_dict=None, tools_in_use=None, segx=None, segy=None,
+                         plot=True, use_thread=True):
+        """
+        Creates a multi-tool CNCJob out of this Geometry object.
+        The actual work is done by the target CNCJobObject object's
+        `generate_from_geometry_2()` method.
+
+        :param tools_dict: a dictionary that holds the whole data needed to create the Gcode
+        (including the solid_geometry)
+
+        :param tools_in_use: the tools that are used, needed by some preprocessors
+        :type list of lists, each list in the list is made out of row elements of tools table from GUI
+
+        :param outname:
+        :param tools_dict:
+        :param tools_in_use:
+        :param segx:            number of segments on the X axis, for auto-levelling
+        :param segy:            number of segments on the Y axis, for auto-levelling
+        :param plot:            if True the generated object will be plotted; if False will not be plotted
+        :param use_thread:      if True use threading
+        :return:                None
+        """
+
+        # use the name of the first tool selected in self.geo_tools_table which has the diameter passed as tool_dia
+        outname = "%s_%s" % (self.options["name"], 'cnc') if outname is None else outname
+
+        tools_dict = self.sel_tools if tools_dict is None else tools_dict
+        tools_in_use = tools_in_use if tools_in_use is not None else self.get_selected_tools_table_items()
+        segx = segx if segx is not None else float(self.app.defaults['geometry_segx'])
+        segy = segy if segy is not None else float(self.app.defaults['geometry_segy'])
+
+        try:
+            xmin = self.options['xmin']
+            ymin = self.options['ymin']
+            xmax = self.options['xmax']
+            ymax = self.options['ymax']
+        except Exception as e:
+            log.debug("FlatCAMObj.GeometryObject.mtool_gen_cncjob() --> %s\n" % str(e))
+
+            msg = '[ERROR] %s' % _("An internal error has occurred. See shell.\n")
+            msg += '%s %s' % ('FlatCAMObj.GeometryObject.mtool_gen_cncjob() -->', str(e))
+            msg += traceback.format_exc()
+            self.app.inform.emit(msg)
+            return
+
+        # 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 job_obj.kind == 'cncjob', "Initializer expected a CNCJobObject, got %s" % type(job_obj)
+
+            job_obj.options['xmin'] = xmin
+            job_obj.options['ymin'] = ymin
+            job_obj.options['xmax'] = xmax
+            job_obj.options['ymax'] = ymax
+
+            # count the tools
+            tool_cnt = 0
+
+            dia_cnc_dict = {}
+
+            # this turn on the FlatCAMCNCJob plot for multiple tools
+            job_obj.multitool = True
+            job_obj.multigeo = False
+            job_obj.cnc_tools.clear()
+
+            job_obj.options['Tools_in_use'] = tools_in_use
+            job_obj.segx = segx if segx else float(self.app.defaults["geometry_segx"])
+            job_obj.segy = segy if segy else float(self.app.defaults["geometry_segy"])
+
+            job_obj.z_pdepth = float(self.app.defaults["geometry_z_pdepth"])
+            job_obj.feedrate_probe = float(self.app.defaults["geometry_feedrate_probe"])
+
+            for tooluid_key in list(tools_dict.keys()):
+                tool_cnt += 1
+
+                dia_cnc_dict = deepcopy(tools_dict[tooluid_key])
+                tooldia_val = float('%.*f' % (self.decimals, float(tools_dict[tooluid_key]['tooldia'])))
+                dia_cnc_dict.update({
+                    'tooldia': tooldia_val
+                })
+
+                if dia_cnc_dict['offset'] == 'in':
+                    tool_offset = -dia_cnc_dict['tooldia'] / 2
+                elif dia_cnc_dict['offset'].lower() == 'out':
+                    tool_offset = dia_cnc_dict['tooldia'] / 2
+                elif dia_cnc_dict['offset'].lower() == 'custom':
+                    try:
+                        offset_value = float(self.ui.tool_offset_entry.get_value())
+                    except ValueError:
+                        # try to convert comma to decimal point. if it's still not working error message and return
+                        try:
+                            offset_value = float(self.ui.tool_offset_entry.get_value().replace(',', '.'))
+                        except ValueError:
+                            self.app.inform.emit('[ERROR_NOTCL] %s' % _("Wrong value format entered, use a number."))
+                            return
+                    if offset_value:
+                        tool_offset = float(offset_value)
+                    else:
+                        self.app.inform.emit(
+                            '[WARNING] %s' % _("Tool Offset is selected in Tool Table but no value is provided.\n"
+                                               "Add a Tool Offset or change the Offset Type.")
+                        )
+                        return
+                else:
+                    tool_offset = 0.0
+
+                dia_cnc_dict.update({
+                    'offset_value': tool_offset
+                })
+
+                z_cut = tools_dict[tooluid_key]['data']["cutz"]
+                z_move = tools_dict[tooluid_key]['data']["travelz"]
+                feedrate = tools_dict[tooluid_key]['data']["feedrate"]
+                feedrate_z = tools_dict[tooluid_key]['data']["feedrate_z"]
+                feedrate_rapid = tools_dict[tooluid_key]['data']["feedrate_rapid"]
+                multidepth = tools_dict[tooluid_key]['data']["multidepth"]
+                extracut = tools_dict[tooluid_key]['data']["extracut"]
+                extracut_length = tools_dict[tooluid_key]['data']["extracut_length"]
+                depthpercut = tools_dict[tooluid_key]['data']["depthperpass"]
+                toolchange = tools_dict[tooluid_key]['data']["toolchange"]
+                toolchangez = tools_dict[tooluid_key]['data']["toolchangez"]
+                toolchangexy = tools_dict[tooluid_key]['data']["toolchangexy"]
+                startz = tools_dict[tooluid_key]['data']["startz"]
+                endz = tools_dict[tooluid_key]['data']["endz"]
+                endxy = self.options["endxy"]
+                spindlespeed = tools_dict[tooluid_key]['data']["spindlespeed"]
+                dwell = tools_dict[tooluid_key]['data']["dwell"]
+                dwelltime = tools_dict[tooluid_key]['data']["dwelltime"]
+                pp_geometry_name = tools_dict[tooluid_key]['data']["ppname_g"]
+
+                spindledir = self.app.defaults['geometry_spindledir']
+                tool_solid_geometry = self.solid_geometry
+
+                job_obj.coords_decimals = self.app.defaults["cncjob_coords_decimals"]
+                job_obj.fr_decimals = self.app.defaults["cncjob_fr_decimals"]
+
+                # Propagate options
+                job_obj.options["tooldia"] = tooldia_val
+                job_obj.options['type'] = 'Geometry'
+                job_obj.options['tool_dia'] = tooldia_val
+
+                # it seems that the tolerance needs to be a lot lower value than 0.01 and it was hardcoded initially
+                # to a value of 0.0005 which is 20 times less than 0.01
+                tol = float(self.app.defaults['global_tolerance']) / 20
+                res = job_obj.generate_from_geometry_2(
+                    self, tooldia=tooldia_val, offset=tool_offset, tolerance=tol,
+                    z_cut=z_cut, z_move=z_move,
+                    feedrate=feedrate, feedrate_z=feedrate_z, feedrate_rapid=feedrate_rapid,
+                    spindlespeed=spindlespeed, spindledir=spindledir, dwell=dwell, dwelltime=dwelltime,
+                    multidepth=multidepth, depthpercut=depthpercut,
+                    extracut=extracut, extracut_length=extracut_length, startz=startz, endz=endz, endxy=endxy,
+                    toolchange=toolchange, toolchangez=toolchangez, toolchangexy=toolchangexy,
+                    pp_geometry_name=pp_geometry_name,
+                    tool_no=tool_cnt)
+
+                if res == 'fail':
+                    log.debug("GeometryObject.mtool_gen_cncjob() --> generate_from_geometry2() failed")
+                    return 'fail'
+                else:
+                    dia_cnc_dict['gcode'] = res
+
+                # tell gcode_parse from which point to start drawing the lines depending on what kind of
+                # object is the source of gcode
+                job_obj.toolchange_xy_type = "geometry"
+
+                self.app.inform.emit('[success] %s' % _("G-Code parsing in progress..."))
+                dia_cnc_dict['gcode_parsed'] = job_obj.gcode_parse()
+                self.app.inform.emit('[success] %s' % _("G-Code parsing finished..."))
+
+                # TODO this serve for bounding box creation only; should be optimized
+                # commented this; there is no need for the actual GCode geometry - the original one will serve as well
+                # for bounding box values
+                # dia_cnc_dict['solid_geometry'] = cascaded_union([geo['geom'] for geo in dia_cnc_dict['gcode_parsed']])
+                try:
+                    dia_cnc_dict['solid_geometry'] = tool_solid_geometry
+                    self.app.inform.emit('[success] %s...' % _("Finished G-Code processing"))
+                except Exception as er:
+                    self.app.inform.emit('[ERROR] %s: %s' % (_("G-Code processing failed with error"), str(er)))
+
+                job_obj.cnc_tools.update({
+                    tooluid_key: deepcopy(dia_cnc_dict)
+                })
+                dia_cnc_dict.clear()
+
+        # 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 job_obj.kind == 'cncjob', "Initializer expected a CNCJobObject, got %s" % type(job_obj)
+
+            job_obj.options['xmin'] = xmin
+            job_obj.options['ymin'] = ymin
+            job_obj.options['xmax'] = xmax
+            job_obj.options['ymax'] = ymax
+
+            # count the tools
+            tool_cnt = 0
+
+            dia_cnc_dict = {}
+
+            # this turn on the FlatCAMCNCJob plot for multiple tools
+            job_obj.multitool = True
+            job_obj.multigeo = True
+            job_obj.cnc_tools.clear()
+
+            job_obj.options['Tools_in_use'] = tools_in_use
+            job_obj.segx = segx if segx else float(self.app.defaults["geometry_segx"])
+            job_obj.segy = segy if segy else float(self.app.defaults["geometry_segy"])
+
+            job_obj.z_pdepth = float(self.app.defaults["geometry_z_pdepth"])
+            job_obj.feedrate_probe = float(self.app.defaults["geometry_feedrate_probe"])
+
+            # make sure that trying to make a CNCJob from an empty file is not creating an app crash
+            if not self.solid_geometry:
+                a = 0
+                for tooluid_key in self.tools:
+                    if self.tools[tooluid_key]['solid_geometry'] is None:
+                        a += 1
+                if a == len(self.tools):
+                    self.app.inform.emit('[ERROR_NOTCL] %s...' % _('Cancelled. Empty file, it has no geometry'))
+                    return 'fail'
+
+            for tooluid_key in list(tools_dict.keys()):
+                tool_cnt += 1
+                dia_cnc_dict = deepcopy(tools_dict[tooluid_key])
+                tooldia_val = float('%.*f' % (self.decimals, float(tools_dict[tooluid_key]['tooldia'])))
+
+                dia_cnc_dict.update({
+                    'tooldia': tooldia_val
+                })
+
+                # find the tool_dia associated with the tooluid_key
+                # search in the self.tools for the sel_tool_dia and when found see what tooluid has
+                # on the found tooluid in self.tools we also have the solid_geometry that interest us
+                # for k, v in self.tools.items():
+                #     if float('%.*f' % (self.decimals, float(v['tooldia']))) == tooldia_val:
+                #         current_uid = int(k)
+                #         break
+
+                if dia_cnc_dict['offset'] == 'in':
+                    tool_offset = -tooldia_val / 2
+                elif dia_cnc_dict['offset'].lower() == 'out':
+                    tool_offset = tooldia_val / 2
+                elif dia_cnc_dict['offset'].lower() == 'custom':
+                    offset_value = float(self.ui.tool_offset_entry.get_value())
+                    if offset_value:
+                        tool_offset = float(offset_value)
+                    else:
+                        self.app.inform.emit('[WARNING] %s' %
+                                             _("Tool Offset is selected in Tool Table but "
+                                               "no value is provided.\n"
+                                               "Add a Tool Offset or change the Offset Type."))
+                        return
+                else:
+                    tool_offset = 0.0
+
+                dia_cnc_dict.update({
+                    'offset_value': tool_offset
+                })
+
+                z_cut = tools_dict[tooluid_key]['data']["cutz"]
+                z_move = tools_dict[tooluid_key]['data']["travelz"]
+                feedrate = tools_dict[tooluid_key]['data']["feedrate"]
+                feedrate_z = tools_dict[tooluid_key]['data']["feedrate_z"]
+                feedrate_rapid = tools_dict[tooluid_key]['data']["feedrate_rapid"]
+                multidepth = tools_dict[tooluid_key]['data']["multidepth"]
+                extracut = tools_dict[tooluid_key]['data']["extracut"]
+                extracut_length = tools_dict[tooluid_key]['data']["extracut_length"]
+                depthpercut = tools_dict[tooluid_key]['data']["depthperpass"]
+                toolchange = tools_dict[tooluid_key]['data']["toolchange"]
+                toolchangez = tools_dict[tooluid_key]['data']["toolchangez"]
+                toolchangexy = tools_dict[tooluid_key]['data']["toolchangexy"]
+                startz = tools_dict[tooluid_key]['data']["startz"]
+                endz = tools_dict[tooluid_key]['data']["endz"]
+                endxy = self.options["endxy"]
+                spindlespeed = tools_dict[tooluid_key]['data']["spindlespeed"]
+                dwell = tools_dict[tooluid_key]['data']["dwell"]
+                dwelltime = tools_dict[tooluid_key]['data']["dwelltime"]
+                pp_geometry_name = tools_dict[tooluid_key]['data']["ppname_g"]
+
+                spindledir = self.app.defaults['geometry_spindledir']
+                tool_solid_geometry = self.tools[tooluid_key]['solid_geometry']
+
+                job_obj.coords_decimals = self.app.defaults["cncjob_coords_decimals"]
+                job_obj.fr_decimals = self.app.defaults["cncjob_fr_decimals"]
+
+                # Propagate options
+                job_obj.options["tooldia"] = tooldia_val
+                job_obj.options['type'] = 'Geometry'
+                job_obj.options['tool_dia'] = tooldia_val
+
+                # it seems that the tolerance needs to be a lot lower value than 0.01 and it was hardcoded initially
+                # to a value of 0.0005 which is 20 times less than 0.01
+                tol = float(self.app.defaults['global_tolerance']) / 20
+                res = job_obj.generate_from_multitool_geometry(
+                    tool_solid_geometry, tooldia=tooldia_val, offset=tool_offset,
+                    tolerance=tol, z_cut=z_cut, z_move=z_move,
+                    feedrate=feedrate, feedrate_z=feedrate_z, feedrate_rapid=feedrate_rapid,
+                    spindlespeed=spindlespeed, spindledir=spindledir, dwell=dwell, dwelltime=dwelltime,
+                    multidepth=multidepth, depthpercut=depthpercut,
+                    extracut=extracut, extracut_length=extracut_length, startz=startz, endz=endz, endxy=endxy,
+                    toolchange=toolchange, toolchangez=toolchangez, toolchangexy=toolchangexy,
+                    pp_geometry_name=pp_geometry_name,
+                    tool_no=tool_cnt)
+
+                if res == 'fail':
+                    log.debug("GeometryObject.mtool_gen_cncjob() --> generate_from_geometry2() failed")
+                    return 'fail'
+                else:
+                    dia_cnc_dict['gcode'] = res
+
+                self.app.inform.emit('[success] %s' % _("G-Code parsing in progress..."))
+                dia_cnc_dict['gcode_parsed'] = job_obj.gcode_parse()
+                self.app.inform.emit('[success] %s' % _("G-Code parsing finished..."))
+
+                # TODO this serve for bounding box creation only; should be optimized
+                # commented this; there is no need for the actual GCode geometry - the original one will serve as well
+                # for bounding box values
+                # geo_for_bound_values = cascaded_union([
+                #     geo['geom'] for geo in dia_cnc_dict['gcode_parsed'] if geo['geom'].is_valid is True
+                # ])
+                try:
+                    dia_cnc_dict['solid_geometry'] = deepcopy(tool_solid_geometry)
+                    self.app.inform.emit('[success] %s' % _("Finished G-Code processing..."))
+                except Exception as ee:
+                    self.app.inform.emit('[ERROR] %s: %s' % (_("G-Code processing failed with error"), str(ee)))
+
+                # tell gcode_parse from which point to start drawing the lines depending on what kind of
+                # object is the source of gcode
+                job_obj.toolchange_xy_type = "geometry"
+
+                job_obj.cnc_tools.update({
+                    tooluid_key: deepcopy(dia_cnc_dict)
+                })
+                dia_cnc_dict.clear()
+
+        if use_thread:
+            # To be run in separate thread
+            def job_thread(app_obj):
+                if self.multigeo is False:
+                    with self.app.proc_container.new(_("Generating CNC Code")):
+                        if app_obj.new_object("cncjob", outname, job_init_single_geometry, plot=plot) != 'fail':
+                            app_obj.inform.emit('[success] %s: %s' % (_("CNCjob created"), outname))
+                else:
+                    with self.app.proc_container.new(_("Generating CNC Code")):
+                        if app_obj.new_object("cncjob", outname, job_init_multi_geometry) != 'fail':
+                            app_obj.inform.emit('[success] %s: %s' % (_("CNCjob created"), outname))
+
+            # Create a promise with the name
+            self.app.collection.promise(outname)
+            # Send to worker
+            self.app.worker_task.emit({'fcn': job_thread, 'params': [self.app]})
+        else:
+            if self.solid_geometry:
+                self.app.new_object("cncjob", outname, job_init_single_geometry, plot=plot)
+            else:
+                self.app.new_object("cncjob", outname, job_init_multi_geometry, plot=plot)
+
+    def generatecncjob(
+            self, outname=None,
+            dia=None, offset=None,
+            z_cut=None, z_move=None,
+            feedrate=None, feedrate_z=None, feedrate_rapid=None,
+            spindlespeed=None, dwell=None, dwelltime=None,
+            multidepth=None, depthperpass=None,
+            toolchange=None, toolchangez=None, toolchangexy=None,
+            extracut=None, extracut_length=None, startz=None, endz=None,
+            pp=None,
+            segx=None, segy=None,
+            use_thread=True,
+            plot=True):
+        """
+        Only used for TCL Command.
+        Creates a CNCJob out of this Geometry object. The actual
+        work is done by the target camlib.CNCjob
+        `generate_from_geometry_2()` method.
+
+        :param outname:         Name of the new object
+        :param dia:             Tool diameter
+        :param offset:
+        :param z_cut:           Cut depth (negative value)
+        :param z_move:          Height of the tool when travelling (not cutting)
+        :param feedrate:        Feed rate while cutting on X - Y plane
+        :param feedrate_z:      Feed rate while cutting on Z plane
+        :param feedrate_rapid:  Feed rate while moving with rapids
+        :param spindlespeed:    Spindle speed (RPM)
+        :param dwell:
+        :param dwelltime:
+        :param multidepth:
+        :param depthperpass:
+        :param toolchange:
+        :param toolchangez:
+        :param toolchangexy:
+        :param extracut:
+        :param extracut_length:
+        :param startz:
+        :param endz:
+        :param pp:              Name of the preprocessor
+        :param segx:
+        :param segy:
+        :param use_thread:
+        :param plot:
+        :return: None
+        """
+
+        tooldia = dia if dia else float(self.options["cnctooldia"])
+        outname = outname if outname is not None else self.options["name"]
+
+        z_cut = z_cut if z_cut is not None else float(self.options["cutz"])
+        z_move = z_move if z_move is not None else float(self.options["travelz"])
+
+        feedrate = feedrate if feedrate is not None else float(self.options["feedrate"])
+        feedrate_z = feedrate_z if feedrate_z is not None else float(self.options["feedrate_z"])
+        feedrate_rapid = feedrate_rapid if feedrate_rapid is not None else float(self.options["feedrate_rapid"])
+
+        multidepth = multidepth if multidepth is not None else self.options["multidepth"]
+        depthperpass = depthperpass if depthperpass is not None else float(self.options["depthperpass"])
+
+        segx = segx if segx is not None else float(self.app.defaults['geometry_segx'])
+        segy = segy if segy is not None else float(self.app.defaults['geometry_segy'])
+
+        extracut = extracut if extracut is not None else float(self.options["extracut"])
+        extracut_length = extracut_length if extracut_length is not None else float(self.options["extracut_length"])
+
+        startz = startz if startz is not None else self.options["startz"]
+        endz = endz if endz is not None else float(self.options["endz"])
+        endxy = self.options["endxy"]
+
+        toolchangez = toolchangez if toolchangez else float(self.options["toolchangez"])
+        toolchangexy = toolchangexy if toolchangexy else self.options["toolchangexy"]
+        toolchange = toolchange if toolchange else self.options["toolchange"]
+
+        offset = offset if offset else 0.0
+
+        # int or None.
+        spindlespeed = spindlespeed if spindlespeed else self.options['spindlespeed']
+        dwell = dwell if dwell else self.options["dwell"]
+        dwelltime = dwelltime if dwelltime else float(self.options["dwelltime"])
+
+        ppname_g = pp if pp else self.options["ppname_g"]
+
+        # Object initialization function for app.new_object()
+        # RUNNING ON SEPARATE THREAD!
+        def job_init(job_obj, app_obj):
+            assert job_obj.kind == 'cncjob', "Initializer expected a CNCJobObject, got %s" % type(job_obj)
+
+            # Propagate options
+            job_obj.options["tooldia"] = tooldia
+
+            job_obj.coords_decimals = self.app.defaults["cncjob_coords_decimals"]
+            job_obj.fr_decimals = self.app.defaults["cncjob_fr_decimals"]
+
+            job_obj.options['type'] = 'Geometry'
+            job_obj.options['tool_dia'] = tooldia
+
+            job_obj.segx = segx
+            job_obj.segy = segy
+
+            job_obj.z_pdepth = float(self.options["z_pdepth"])
+            job_obj.feedrate_probe = float(self.options["feedrate_probe"])
+
+            job_obj.options['xmin'] = self.options['xmin']
+            job_obj.options['ymin'] = self.options['ymin']
+            job_obj.options['xmax'] = self.options['xmax']
+            job_obj.options['ymax'] = self.options['ymax']
+
+            # it seems that the tolerance needs to be a lot lower value than 0.01 and it was hardcoded initially
+            # to a value of 0.0005 which is 20 times less than 0.01
+            tol = float(self.app.defaults['global_tolerance']) / 20
+            job_obj.generate_from_geometry_2(
+                self, tooldia=tooldia, offset=offset, tolerance=tol,
+                z_cut=z_cut, z_move=z_move,
+                feedrate=feedrate, feedrate_z=feedrate_z, feedrate_rapid=feedrate_rapid,
+                spindlespeed=spindlespeed, dwell=dwell, dwelltime=dwelltime,
+                multidepth=multidepth, depthpercut=depthperpass,
+                toolchange=toolchange, toolchangez=toolchangez, toolchangexy=toolchangexy,
+                extracut=extracut, extracut_length=extracut_length, startz=startz, endz=endz, endxy=endxy,
+                pp_geometry_name=ppname_g
+            )
+
+            # tell gcode_parse from which point to start drawing the lines depending on what kind of object is the
+            # source of gcode
+            job_obj.toolchange_xy_type = "geometry"
+            job_obj.gcode_parse()
+            self.app.inform.emit('[success] %s' % _("Finished G-Code processing..."))
+
+        if use_thread:
+            # To be run in separate thread
+            def job_thread(app_obj):
+                with self.app.proc_container.new(_("Generating CNC Code")):
+                    app_obj.new_object("cncjob", outname, job_init, plot=plot)
+                    app_obj.inform.emit('[success] %s: %s' % (_("CNCjob created")), outname)
+
+            # Create a promise with the name
+            self.app.collection.promise(outname)
+            # Send to worker
+            self.app.worker_task.emit({'fcn': job_thread, 'params': [self.app]})
+        else:
+            self.app.new_object("cncjob", outname, job_init, plot=plot)
+
+    # def on_plot_cb_click(self, *args):
+    #     if self.muted_ui:
+    #         return
+    #     self.read_form_item('plot')
+
+    def scale(self, xfactor, yfactor=None, point=None):
+        """
+        Scales all geometry by a given factor.
+
+        :param xfactor:     Factor by which to scale the object's geometry/
+        :type xfactor:      float
+        :param yfactor:     Factor by which to scale the object's geometry/
+        :type yfactor:      float
+        :param point:       Point around which to scale
+        :return: None
+        :rtype: None
+        """
+        log.debug("FlatCAMObj.GeometryObject.scale()")
+
+        try:
+            xfactor = float(xfactor)
+        except Exception:
+            self.app.inform.emit('[ERROR_NOTCL] %s' % _("Scale factor has to be a number: integer or float."))
+            return
+
+        if yfactor is None:
+            yfactor = xfactor
+        else:
+            try:
+                yfactor = float(yfactor)
+            except Exception:
+                self.app.inform.emit('[ERROR_NOTCL] %s' % _("Scale factor has to be a number: integer or float."))
+                return
+
+        if xfactor == 1 and yfactor == 1:
+            return
+
+        if point is None:
+            px = 0
+            py = 0
+        else:
+            px, py = point
+
+        self.geo_len = 0
+        self.old_disp_number = 0
+        self.el_count = 0
+
+        def scale_recursion(geom):
+            if type(geom) is list:
+                geoms = []
+                for local_geom in geom:
+                    geoms.append(scale_recursion(local_geom))
+                return geoms
+            else:
+                try:
+                    self.el_count += 1
+                    disp_number = int(np.interp(self.el_count, [0, self.geo_len], [0, 100]))
+                    if self.old_disp_number < disp_number <= 100:
+                        self.app.proc_container.update_view_text(' %d%%' % disp_number)
+                        self.old_disp_number = disp_number
+
+                    return affinity.scale(geom, xfactor, yfactor, origin=(px, py))
+                except AttributeError:
+                    return geom
+
+        if self.multigeo is True:
+            for tool in self.tools:
+                # variables to display the percentage of work done
+                self.geo_len = 0
+                try:
+                    self.geo_len = len(self.tools[tool]['solid_geometry'])
+                except TypeError:
+                    self.geo_len = 1
+                self.old_disp_number = 0
+                self.el_count = 0
+
+                self.tools[tool]['solid_geometry'] = scale_recursion(self.tools[tool]['solid_geometry'])
+
+        try:
+            # variables to display the percentage of work done
+            self.geo_len = 0
+            try:
+                self.geo_len = len(self.solid_geometry)
+            except TypeError:
+                self.geo_len = 1
+            self.old_disp_number = 0
+            self.el_count = 0
+
+            self.solid_geometry = scale_recursion(self.solid_geometry)
+        except AttributeError:
+            self.solid_geometry = []
+            return
+
+        self.app.proc_container.new_text = ''
+        self.app.inform.emit('[success] %s' % _("Geometry Scale done."))
+
+    def offset(self, vect):
+        """
+        Offsets all geometry by a given vector/
+
+        :param vect: (x, y) vector by which to offset the object's geometry.
+        :type vect: tuple
+        :return: None
+        :rtype: None
+        """
+        log.debug("FlatCAMObj.GeometryObject.offset()")
+
+        try:
+            dx, dy = vect
+        except TypeError:
+            self.app.inform.emit('[ERROR_NOTCL] %s' %
+                                 _("An (x,y) pair of values are needed. "
+                                   "Probable you entered only one value in the Offset field.")
+                                 )
+            return
+
+        if dx == 0 and dy == 0:
+            return
+
+        self.geo_len = 0
+        self.old_disp_number = 0
+        self.el_count = 0
+
+        def translate_recursion(geom):
+            if type(geom) is list:
+                geoms = []
+                for local_geom in geom:
+                    geoms.append(translate_recursion(local_geom))
+                return geoms
+            else:
+                try:
+                    self.el_count += 1
+                    disp_number = int(np.interp(self.el_count, [0, self.geo_len], [0, 100]))
+                    if self.old_disp_number < disp_number <= 100:
+                        self.app.proc_container.update_view_text(' %d%%' % disp_number)
+                        self.old_disp_number = disp_number
+
+                    return affinity.translate(geom, xoff=dx, yoff=dy)
+                except AttributeError:
+                    return geom
+
+        if self.multigeo is True:
+            for tool in self.tools:
+                # variables to display the percentage of work done
+                self.geo_len = 0
+                try:
+                    self.geo_len = len(self.tools[tool]['solid_geometry'])
+                except TypeError:
+                    self.geo_len = 1
+                self.old_disp_number = 0
+                self.el_count = 0
+
+                self.tools[tool]['solid_geometry'] = translate_recursion(self.tools[tool]['solid_geometry'])
+
+        # variables to display the percentage of work done
+        self.geo_len = 0
+        try:
+            self.geo_len = len(self.solid_geometry)
+        except TypeError:
+            self.geo_len = 1
+
+        self.old_disp_number = 0
+        self.el_count = 0
+
+        self.solid_geometry = translate_recursion(self.solid_geometry)
+
+        self.app.proc_container.new_text = ''
+        self.app.inform.emit('[success] %s' % _("Geometry Offset done."))
+
+    def convert_units(self, units):
+        log.debug("FlatCAMObj.GeometryObject.convert_units()")
+
+        self.ui_disconnect()
+
+        factor = Geometry.convert_units(self, units)
+
+        self.options['cutz'] = float(self.options['cutz']) * factor
+        self.options['depthperpass'] = float(self.options['depthperpass']) * factor
+        self.options['travelz'] = float(self.options['travelz']) * factor
+        self.options['feedrate'] = float(self.options['feedrate']) * factor
+        self.options['feedrate_z'] = float(self.options['feedrate_z']) * factor
+        self.options['feedrate_rapid'] = float(self.options['feedrate_rapid']) * factor
+        self.options['endz'] = float(self.options['endz']) * factor
+        # self.options['cnctooldia'] *= factor
+        # self.options['painttooldia'] *= factor
+        # self.options['paintmargin'] *= factor
+        # self.options['paintoverlap'] *= factor
+
+        self.options["toolchangez"] = float(self.options["toolchangez"]) * factor
+
+        if self.app.defaults["geometry_toolchangexy"] == '':
+            self.options['toolchangexy'] = "0.0, 0.0"
+        else:
+            coords_xy = [float(eval(coord)) for coord in self.app.defaults["geometry_toolchangexy"].split(",")]
+            if len(coords_xy) < 2:
+                self.app.inform.emit('[ERROR] %s' %
+                                     _("The Toolchange X,Y field in Edit -> Preferences "
+                                       "has to be in the format (x, y)\n"
+                                       "but now there is only one value, not two.")
+                                     )
+                return 'fail'
+            coords_xy[0] *= factor
+            coords_xy[1] *= factor
+            self.options['toolchangexy'] = "%f, %f" % (coords_xy[0], coords_xy[1])
+
+        if self.options['startz'] is not None:
+            self.options['startz'] = float(self.options['startz']) * factor
+
+        param_list = ['cutz', 'depthperpass', 'travelz', 'feedrate', 'feedrate_z', 'feedrate_rapid',
+                      'endz', 'toolchangez']
+
+        if isinstance(self, GeometryObject):
+            temp_tools_dict = {}
+            tool_dia_copy = {}
+            data_copy = {}
+            for tooluid_key, tooluid_value in self.tools.items():
+                for dia_key, dia_value in tooluid_value.items():
+                    if dia_key == 'tooldia':
+                        dia_value *= factor
+                        dia_value = float('%.*f' % (self.decimals, dia_value))
+                        tool_dia_copy[dia_key] = dia_value
+                    if dia_key == 'offset':
+                        tool_dia_copy[dia_key] = dia_value
+                    if dia_key == 'offset_value':
+                        dia_value *= factor
+                        tool_dia_copy[dia_key] = dia_value
+
+                        # convert the value in the Custom Tool Offset entry in UI
+                        custom_offset = None
+                        try:
+                            custom_offset = float(self.ui.tool_offset_entry.get_value())
+                        except ValueError:
+                            # try to convert comma to decimal point. if it's still not working error message and return
+                            try:
+                                custom_offset = float(self.ui.tool_offset_entry.get_value().replace(',', '.'))
+                            except ValueError:
+                                self.app.inform.emit('[ERROR_NOTCL] %s' %
+                                                     _("Wrong value format entered, use a number."))
+                                return
+                        except TypeError:
+                            pass
+
+                        if custom_offset:
+                            custom_offset *= factor
+                            self.ui.tool_offset_entry.set_value(custom_offset)
+
+                    if dia_key == 'type':
+                        tool_dia_copy[dia_key] = dia_value
+                    if dia_key == 'tool_type':
+                        tool_dia_copy[dia_key] = dia_value
+                    if dia_key == 'data':
+                        for data_key, data_value in dia_value.items():
+                            # convert the form fields that are convertible
+                            for param in param_list:
+                                if data_key == param and data_value is not None:
+                                    data_copy[data_key] = data_value * factor
+                            # copy the other dict entries that are not convertible
+                            if data_key not in param_list:
+                                data_copy[data_key] = data_value
+                        tool_dia_copy[dia_key] = deepcopy(data_copy)
+                        data_copy.clear()
+
+                temp_tools_dict.update({
+                    tooluid_key: deepcopy(tool_dia_copy)
+                })
+                tool_dia_copy.clear()
+
+            self.tools.clear()
+            self.tools = deepcopy(temp_tools_dict)
+
+        # if there is a value in the new tool field then convert that one too
+        try:
+            self.ui.addtool_entry.returnPressed.disconnect()
+        except TypeError:
+            pass
+        tooldia = self.ui.addtool_entry.get_value()
+        if tooldia:
+            tooldia *= factor
+            tooldia = float('%.*f' % (self.decimals, tooldia))
+
+            self.ui.addtool_entry.set_value(tooldia)
+        self.ui.addtool_entry.returnPressed.connect(self.on_tool_add)
+
+        return factor
+
+    def plot_element(self, element, color=None, visible=None):
+
+        if color is None:
+            color = '#FF0000FF'
+
+        visible = visible if visible else self.options['plot']
+        try:
+            for sub_el in element:
+                self.plot_element(sub_el, color=color)
+
+        except TypeError:  # Element is not iterable...
+            # if self.app.is_legacy is False:
+            self.add_shape(shape=element, color=color, visible=visible, layer=0)
+
+    def plot(self, visible=None, kind=None):
+        """
+        Plot the object.
+
+        :param visible: Controls if the added shape is visible of not
+        :param kind: added so there is no error when a project is loaded and it has both geometry and CNCJob, because
+        CNCJob require the 'kind' parameter. Perhaps the FlatCAMObj.plot() has to be rewrited
+        :return:
+        """
+
+        # Does all the required setup and returns False
+        # if the 'ptint' option is set to False.
+        if not FlatCAMObj.plot(self):
+            return
+
+        try:
+            # plot solid geometries found as members of self.tools attribute dict
+            # for MultiGeo
+            if self.multigeo is True:  # geo multi tool usage
+                for tooluid_key in self.tools:
+                    solid_geometry = self.tools[tooluid_key]['solid_geometry']
+                    self.plot_element(solid_geometry, visible=visible,
+                                      color=self.app.defaults["geometry_plot_line"])
+            else:
+                # plot solid geometry that may be an direct attribute of the geometry object
+                # for SingleGeo
+                if self.solid_geometry:
+                    self.plot_element(self.solid_geometry, visible=visible,
+                                      color=self.app.defaults["geometry_plot_line"])
+
+            # self.plot_element(self.solid_geometry, visible=self.options['plot'])
+
+            self.shapes.redraw()
+
+        except (ObjectDeleted, AttributeError):
+            self.shapes.clear(update=True)
+
+    def on_plot_cb_click(self, *args):
+        if self.muted_ui:
+            return
+        self.read_form_item('plot')
+        self.plot()
+
+        self.ui_disconnect()
+        cb_flag = self.ui.plot_cb.isChecked()
+        for row in range(self.ui.geo_tools_table.rowCount()):
+            table_cb = self.ui.geo_tools_table.cellWidget(row, 6)
+            if cb_flag:
+                table_cb.setChecked(True)
+            else:
+                table_cb.setChecked(False)
+        self.ui_connect()
+
+    def on_plot_cb_click_table(self):
+        # self.ui.cnc_tools_table.cellWidget(row, 2).widget().setCheckState(QtCore.Qt.Unchecked)
+        self.ui_disconnect()
+        # cw = self.sender()
+        # cw_index = self.ui.geo_tools_table.indexAt(cw.pos())
+        # cw_row = cw_index.row()
+        check_row = 0
+
+        self.shapes.clear(update=True)
+        for tooluid_key in self.tools:
+            solid_geometry = self.tools[tooluid_key]['solid_geometry']
+
+            # find the geo_tool_table row associated with the tooluid_key
+            for row in range(self.ui.geo_tools_table.rowCount()):
+                tooluid_item = int(self.ui.geo_tools_table.item(row, 5).text())
+                if tooluid_item == int(tooluid_key):
+                    check_row = row
+                    break
+            if self.ui.geo_tools_table.cellWidget(check_row, 6).isChecked():
+                self.plot_element(element=solid_geometry, visible=True)
+        self.shapes.redraw()
+
+        # make sure that the general plot is disabled if one of the row plot's are disabled and
+        # if all the row plot's are enabled also enable the general plot checkbox
+        cb_cnt = 0
+        total_row = self.ui.geo_tools_table.rowCount()
+        for row in range(total_row):
+            if self.ui.geo_tools_table.cellWidget(row, 6).isChecked():
+                cb_cnt += 1
+            else:
+                cb_cnt -= 1
+        if cb_cnt < total_row:
+            self.ui.plot_cb.setChecked(False)
+        else:
+            self.ui.plot_cb.setChecked(True)
+        self.ui_connect()
+
+    def merge(self, geo_list, geo_final, multigeo=None):
+        """
+        Merges the geometry of objects in grb_list into
+        the geometry of geo_final.
+
+        :param geo_list: List of GerberObject Objects to join.
+        :param geo_final: Destination GerberObject object.
+        :param multigeo: if the merged geometry objects are of type MultiGeo
+        :return: None
+        """
+
+        if geo_final.solid_geometry is None:
+            geo_final.solid_geometry = []
+
+        try:
+            __ = iter(geo_final.solid_geometry)
+        except TypeError:
+            geo_final.solid_geometry = [geo_final.solid_geometry]
+
+        new_solid_geometry = []
+        new_options = {}
+        new_tools = {}
+
+        for geo_obj in geo_list:
+            for option in geo_obj.options:
+                if option != 'name':
+                    try:
+                        new_options[option] = deepcopy(geo_obj.options[option])
+                    except Exception as e:
+                        log.warning("Failed to copy option %s. Error: %s" % (str(option), str(e)))
+
+            # Expand lists
+            if type(geo_obj) is list:
+                GeometryObject.merge(self, geo_list=geo_obj, geo_final=geo_final)
+            # If not list, just append
+            else:
+                if multigeo is None or multigeo is False:
+                    geo_final.multigeo = False
+                else:
+                    geo_final.multigeo = True
+
+                try:
+                    new_solid_geometry += deepcopy(geo_obj.solid_geometry)
+                except Exception as e:
+                    log.debug("GeometryObject.merge() --> %s" % str(e))
+
+                # find the tool_uid maximum value in the geo_final
+                try:
+                    max_uid = max([int(i) for i in new_tools.keys()])
+                except ValueError:
+                    max_uid = 0
+
+                # add and merge tools. If what we try to merge as Geometry is Excellon's and/or Gerber's then don't try
+                # to merge the obj.tools as it is likely there is none to merge.
+                if geo_obj.kind != 'gerber' and geo_obj.kind != 'excellon':
+                    for tool_uid in geo_obj.tools:
+                        max_uid += 1
+                        new_tools[max_uid] = deepcopy(geo_obj.tools[tool_uid])
+
+        geo_final.options.update(new_options)
+        geo_final.solid_geometry = new_solid_geometry
+        geo_final.tools = new_tools
+
+    @staticmethod
+    def get_pts(o):
+        """
+        Returns a list of all points in the object, where
+        the object can be a MultiPolygon, Polygon, Not a polygon, or a list
+        of such. Search is done recursively.
+
+        :param: geometric object
+        :return: List of points
+        :rtype: list
+        """
+        pts = []
+
+        # Iterable: descend into each item.
+        try:
+            for subo in o:
+                pts += GeometryObject.get_pts(subo)
+
+        # Non-iterable
+        except TypeError:
+            if o is not None:
+                if type(o) == MultiPolygon:
+                    for poly in o:
+                        pts += GeometryObject.get_pts(poly)
+                # ## Descend into .exerior and .interiors
+                elif type(o) == Polygon:
+                    pts += GeometryObject.get_pts(o.exterior)
+                    for i in o.interiors:
+                        pts += GeometryObject.get_pts(i)
+                elif type(o) == MultiLineString:
+                    for line in o:
+                        pts += GeometryObject.get_pts(line)
+                # ## Has .coords: list them.
+                else:
+                    pts += list(o.coords)
+            else:
+                return
+        return pts

+ 1870 - 0
flatcamObjects/FlatCAMGerber.py

@@ -0,0 +1,1870 @@
+# ##########################################################
+# FlatCAM: 2D Post-processing for Manufacturing            #
+# http://flatcam.org                                       #
+# Author: Juan Pablo Caram (c)                             #
+# Date: 2/5/2014                                           #
+# MIT Licence                                              #
+# ##########################################################
+
+# ##########################################################
+# File modified by: Marius Stanciu                         #
+# ##########################################################
+
+
+from shapely.geometry import Point, Polygon, MultiPolygon, MultiLineString, LineString, LinearRing
+from shapely.ops import cascaded_union
+
+from flatcamParsers.ParseGerber import Gerber
+from flatcamObjects.FlatCAMObj import *
+
+import math
+import numpy as np
+from copy import deepcopy
+
+import gettext
+import FlatCAMTranslation as fcTranslate
+import builtins
+
+fcTranslate.apply_language('strings')
+if '_' not in builtins.__dict__:
+    _ = gettext.gettext
+
+
+class GerberObject(FlatCAMObj, Gerber):
+    """
+    Represents Gerber code.
+    """
+    optionChanged = QtCore.pyqtSignal(str)
+    replotApertures = QtCore.pyqtSignal()
+
+    ui_type = GerberObjectUI
+
+    def merge(self, grb_list, grb_final):
+        """
+        Merges the geometry of objects in geo_list into
+        the geometry of geo_final.
+
+        :param grb_list: List of GerberObject Objects to join.
+        :param grb_final: Destination GeometryObject object.
+        :return: None
+        """
+
+        if grb_final.solid_geometry is None:
+            grb_final.solid_geometry = []
+            grb_final.follow_geometry = []
+
+        if not grb_final.apertures:
+            grb_final.apertures = {}
+
+        if type(grb_final.solid_geometry) is not list:
+            grb_final.solid_geometry = [grb_final.solid_geometry]
+            grb_final.follow_geometry = [grb_final.follow_geometry]
+
+        for grb in grb_list:
+
+            # Expand lists
+            if type(grb) is list:
+                GerberObject.merge(grb, grb_final)
+            else:   # If not list, just append
+                for option in grb.options:
+                    if option != 'name':
+                        try:
+                            grb_final.options[option] = grb.options[option]
+                        except KeyError:
+                            log.warning("Failed to copy option.", option)
+
+                try:
+                    for geos in grb.solid_geometry:
+                        grb_final.solid_geometry.append(geos)
+                        grb_final.follow_geometry.append(geos)
+                except TypeError:
+                    grb_final.solid_geometry.append(grb.solid_geometry)
+                    grb_final.follow_geometry.append(grb.solid_geometry)
+
+                for ap in grb.apertures:
+                    if ap not in grb_final.apertures:
+                        grb_final.apertures[ap] = grb.apertures[ap]
+                    else:
+                        # create a list of integers out of the grb.apertures keys and find the max of that value
+                        # then, the aperture duplicate is assigned an id value incremented with 1,
+                        # and finally made string because the apertures dict keys are strings
+                        max_ap = str(max([int(k) for k in grb_final.apertures.keys()]) + 1)
+                        grb_final.apertures[max_ap] = {}
+                        grb_final.apertures[max_ap]['geometry'] = []
+
+                        for k, v in grb.apertures[ap].items():
+                            grb_final.apertures[max_ap][k] = deepcopy(v)
+
+        grb_final.solid_geometry = MultiPolygon(grb_final.solid_geometry)
+        grb_final.follow_geometry = MultiPolygon(grb_final.follow_geometry)
+
+    def __init__(self, name):
+        self.decimals = self.app.decimals
+
+        self.circle_steps = int(self.app.defaults["gerber_circle_steps"])
+
+        Gerber.__init__(self, steps_per_circle=self.circle_steps)
+        FlatCAMObj.__init__(self, name)
+
+        self.kind = "gerber"
+
+        # The 'name' is already in self.options from FlatCAMObj
+        # Automatically updates the UI
+        self.options.update({
+            "plot": True,
+            "multicolored": False,
+            "solid": False,
+            "tool_type": 'circular',
+            "vtipdia": 0.1,
+            "vtipangle": 30,
+            "vcutz": -0.05,
+            "isotooldia": 0.016,
+            "isopasses": 1,
+            "isooverlap": 15,
+            "milling_type": "cl",
+            "combine_passes": True,
+            "noncoppermargin": 0.0,
+            "noncopperrounded": False,
+            "bboxmargin": 0.0,
+            "bboxrounded": False,
+            "aperture_display": False,
+            "follow": False,
+            "iso_scope": 'all',
+            "iso_type": 'full'
+        })
+
+        # type of isolation: 0 = exteriors, 1 = interiors, 2 = complete isolation (both interiors and exteriors)
+        self.iso_type = 2
+
+        self.multigeo = False
+
+        self.follow = False
+
+        self.apertures_row = 0
+
+        # store the source file here
+        self.source_file = ""
+
+        # list of rows with apertures plotted
+        self.marked_rows = []
+
+        # Mouse events
+        self.mr = None
+        self.mm = None
+        self.mp = None
+
+        # dict to store the polygons selected for isolation; key is the shape added to be plotted and value is the poly
+        self.poly_dict = {}
+
+        # store the status of grid snapping
+        self.grid_status_memory = None
+
+        self.units_found = self.app.defaults['units']
+
+        self.fill_color = self.app.defaults['gerber_plot_fill']
+        self.outline_color = self.app.defaults['gerber_plot_line']
+        self.alpha_level = 'bf'
+
+        # keep track if the UI is built so we don't have to build it every time
+        self.ui_build = False
+
+        # build only once the aperture storage (takes time)
+        self.build_aperture_storage = False
+
+        # Attributes to be included in serialization
+        # Always append to it because it carries contents
+        # from predecessors.
+        self.ser_attrs += ['options', 'kind', 'fill_color', 'outline_color', 'alpha_level']
+
+    def set_ui(self, ui):
+        """
+        Maps options with GUI inputs.
+        Connects GUI events to methods.
+
+        :param ui: GUI object.
+        :type ui: GerberObjectUI
+        :return: None
+        """
+        FlatCAMObj.set_ui(self, ui)
+        log.debug("GerberObject.set_ui()")
+
+        self.units = self.app.defaults['units'].upper()
+
+        self.replotApertures.connect(self.on_mark_cb_click_table)
+
+        self.form_fields.update({
+            "plot": self.ui.plot_cb,
+            "multicolored": self.ui.multicolored_cb,
+            "solid": self.ui.solid_cb,
+            "tool_type": self.ui.tool_type_radio,
+            "vtipdia": self.ui.tipdia_spinner,
+            "vtipangle": self.ui.tipangle_spinner,
+            "vcutz": self.ui.cutz_spinner,
+            "isotooldia": self.ui.iso_tool_dia_entry,
+            "isopasses": self.ui.iso_width_entry,
+            "isooverlap": self.ui.iso_overlap_entry,
+            "milling_type": self.ui.milling_type_radio,
+            "combine_passes": self.ui.combine_passes_cb,
+            "noncoppermargin": self.ui.noncopper_margin_entry,
+            "noncopperrounded": self.ui.noncopper_rounded_cb,
+            "bboxmargin": self.ui.bbmargin_entry,
+            "bboxrounded": self.ui.bbrounded_cb,
+            "aperture_display": self.ui.aperture_table_visibility_cb,
+            "follow": self.ui.follow_cb,
+            "iso_scope": self.ui.iso_scope_radio,
+            "iso_type": self.ui.iso_type_radio
+        })
+
+        # Fill form fields only on object create
+        self.to_form()
+
+        assert isinstance(self.ui, GerberObjectUI)
+        self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
+        self.ui.solid_cb.stateChanged.connect(self.on_solid_cb_click)
+        self.ui.multicolored_cb.stateChanged.connect(self.on_multicolored_cb_click)
+        self.ui.generate_iso_button.clicked.connect(self.on_iso_button_click)
+        self.ui.generate_ncc_button.clicked.connect(self.app.ncclear_tool.run)
+        self.ui.generate_cutout_button.clicked.connect(self.app.cutout_tool.run)
+        self.ui.generate_bb_button.clicked.connect(self.on_generatebb_button_click)
+        self.ui.generate_noncopper_button.clicked.connect(self.on_generatenoncopper_button_click)
+        self.ui.aperture_table_visibility_cb.stateChanged.connect(self.on_aperture_table_visibility_change)
+        self.ui.follow_cb.stateChanged.connect(self.on_follow_cb_click)
+
+        # set the model for the Area Exception comboboxes
+        self.ui.obj_combo.setModel(self.app.collection)
+        self.ui.obj_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
+        self.ui.obj_combo.is_last = True
+        self.ui.obj_combo.obj_type = {
+            _("Gerber"): "Gerber", _("Geometry"): "Geometry"
+        }[self.ui.type_obj_combo.get_value()]
+        self.on_type_obj_index_changed()
+
+        self.ui.type_obj_combo.currentIndexChanged.connect(self.on_type_obj_index_changed)
+
+        self.ui.tool_type_radio.activated_custom.connect(self.on_tool_type_change)
+        # establish visibility for the GUI elements found in the slot function
+        self.ui.tool_type_radio.activated_custom.emit(self.options['tool_type'])
+
+        # Show/Hide Advanced Options
+        if self.app.defaults["global_app_level"] == 'b':
+            self.ui.level.setText('<span style="color:green;"><b>%s</b></span>' % _('Basic'))
+            self.options['tool_type'] = 'circular'
+
+            self.ui.tool_type_label.hide()
+            self.ui.tool_type_radio.hide()
+
+            # override the Preferences Value; in Basic mode the Tool Type is always Circular ('C1')
+            self.ui.tool_type_radio.set_value('circular')
+
+            self.ui.tipdialabel.hide()
+            self.ui.tipdia_spinner.hide()
+            self.ui.tipanglelabel.hide()
+            self.ui.tipangle_spinner.hide()
+            self.ui.cutzlabel.hide()
+            self.ui.cutz_spinner.hide()
+
+            self.ui.apertures_table_label.hide()
+            self.ui.aperture_table_visibility_cb.hide()
+            self.ui.milling_type_label.hide()
+            self.ui.milling_type_radio.hide()
+            self.ui.iso_type_label.hide()
+            self.ui.iso_type_radio.hide()
+
+            self.ui.follow_cb.hide()
+            self.ui.except_cb.setChecked(False)
+            self.ui.except_cb.hide()
+        else:
+            self.ui.level.setText('<span style="color:red;"><b>%s</b></span>' % _('Advanced'))
+            self.ui.tipdia_spinner.valueChanged.connect(self.on_calculate_tooldia)
+            self.ui.tipangle_spinner.valueChanged.connect(self.on_calculate_tooldia)
+            self.ui.cutz_spinner.valueChanged.connect(self.on_calculate_tooldia)
+
+        if self.app.defaults["gerber_buffering"] == 'no':
+            self.ui.create_buffer_button.show()
+            try:
+                self.ui.create_buffer_button.clicked.disconnect(self.on_generate_buffer)
+            except TypeError:
+                pass
+            self.ui.create_buffer_button.clicked.connect(self.on_generate_buffer)
+        else:
+            self.ui.create_buffer_button.hide()
+
+        # set initial state of the aperture table and associated widgets
+        self.on_aperture_table_visibility_change()
+
+        self.build_ui()
+        self.units_found = self.app.defaults['units']
+
+    def on_calculate_tooldia(self):
+        try:
+            tdia = float(self.ui.tipdia_spinner.get_value())
+        except Exception:
+            return
+        try:
+            dang = float(self.ui.tipangle_spinner.get_value())
+        except Exception:
+            return
+        try:
+            cutz = float(self.ui.cutz_spinner.get_value())
+        except Exception:
+            return
+
+        cutz *= -1
+        if cutz < 0:
+            cutz *= -1
+
+        half_tip_angle = dang / 2
+
+        tool_diameter = tdia + (2 * cutz * math.tan(math.radians(half_tip_angle)))
+        self.ui.iso_tool_dia_entry.set_value(tool_diameter)
+
+    def on_type_obj_index_changed(self):
+        val = self.ui.type_obj_combo.get_value()
+        obj_type = {"Gerber": 0, "Geometry": 2}[val]
+        self.ui.obj_combo.setRootModelIndex(self.app.collection.index(obj_type, 0, QtCore.QModelIndex()))
+        self.ui.obj_combo.setCurrentIndex(0)
+        self.ui.obj_combo.obj_type = {_("Gerber"): "Gerber", _("Geometry"): "Geometry"}[val]
+
+    def on_tool_type_change(self, state):
+        if state == 'circular':
+            self.ui.tipdialabel.hide()
+            self.ui.tipdia_spinner.hide()
+            self.ui.tipanglelabel.hide()
+            self.ui.tipangle_spinner.hide()
+            self.ui.cutzlabel.hide()
+            self.ui.cutz_spinner.hide()
+            self.ui.iso_tool_dia_entry.setDisabled(False)
+            # update the value in the self.iso_tool_dia_entry once this is selected
+            self.ui.iso_tool_dia_entry.set_value(self.options['isotooldia'])
+        else:
+            self.ui.tipdialabel.show()
+            self.ui.tipdia_spinner.show()
+            self.ui.tipanglelabel.show()
+            self.ui.tipangle_spinner.show()
+            self.ui.cutzlabel.show()
+            self.ui.cutz_spinner.show()
+            self.ui.iso_tool_dia_entry.setDisabled(True)
+            # update the value in the self.iso_tool_dia_entry once this is selected
+            self.on_calculate_tooldia()
+
+    def build_ui(self):
+        FlatCAMObj.build_ui(self)
+
+        if self.ui.aperture_table_visibility_cb.get_value() and self.ui_build is False:
+            self.ui_build = True
+
+            try:
+                # if connected, disconnect the signal from the slot on item_changed as it creates issues
+                self.ui.apertures_table.itemChanged.disconnect()
+            except (TypeError, AttributeError):
+                pass
+
+            self.apertures_row = 0
+            aper_no = self.apertures_row + 1
+            sort = []
+            for k, v in list(self.apertures.items()):
+                sort.append(int(k))
+            sorted_apertures = sorted(sort)
+
+            n = len(sorted_apertures)
+            self.ui.apertures_table.setRowCount(n)
+
+            for ap_code in sorted_apertures:
+                ap_code = str(ap_code)
+
+                ap_id_item = QtWidgets.QTableWidgetItem('%d' % int(self.apertures_row + 1))
+                ap_id_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
+                self.ui.apertures_table.setItem(self.apertures_row, 0, ap_id_item)  # Tool name/id
+
+                ap_code_item = QtWidgets.QTableWidgetItem(ap_code)
+                ap_code_item.setFlags(QtCore.Qt.ItemIsEnabled)
+
+                ap_type_item = QtWidgets.QTableWidgetItem(str(self.apertures[ap_code]['type']))
+                ap_type_item.setFlags(QtCore.Qt.ItemIsEnabled)
+
+                if str(self.apertures[ap_code]['type']) == 'R' or str(self.apertures[ap_code]['type']) == 'O':
+                    ap_dim_item = QtWidgets.QTableWidgetItem(
+                        '%.*f, %.*f' % (self.decimals, self.apertures[ap_code]['width'],
+                                        self.decimals, self.apertures[ap_code]['height']
+                                        )
+                    )
+                    ap_dim_item.setFlags(QtCore.Qt.ItemIsEnabled)
+                elif str(self.apertures[ap_code]['type']) == 'P':
+                    ap_dim_item = QtWidgets.QTableWidgetItem(
+                        '%.*f, %.*f' % (self.decimals, self.apertures[ap_code]['diam'],
+                                        self.decimals, self.apertures[ap_code]['nVertices'])
+                    )
+                    ap_dim_item.setFlags(QtCore.Qt.ItemIsEnabled)
+                else:
+                    ap_dim_item = QtWidgets.QTableWidgetItem('')
+                    ap_dim_item.setFlags(QtCore.Qt.ItemIsEnabled)
+
+                try:
+                    if self.apertures[ap_code]['size'] is not None:
+                        ap_size_item = QtWidgets.QTableWidgetItem(
+                            '%.*f' % (self.decimals, float(self.apertures[ap_code]['size'])))
+                    else:
+                        ap_size_item = QtWidgets.QTableWidgetItem('')
+                except KeyError:
+                    ap_size_item = QtWidgets.QTableWidgetItem('')
+                ap_size_item.setFlags(QtCore.Qt.ItemIsEnabled)
+
+                mark_item = FCCheckBox()
+                mark_item.setLayoutDirection(QtCore.Qt.RightToLeft)
+                # if self.ui.aperture_table_visibility_cb.isChecked():
+                #     mark_item.setChecked(True)
+
+                self.ui.apertures_table.setItem(self.apertures_row, 1, ap_code_item)  # Aperture Code
+                self.ui.apertures_table.setItem(self.apertures_row, 2, ap_type_item)  # Aperture Type
+                self.ui.apertures_table.setItem(self.apertures_row, 3, ap_size_item)   # Aperture Dimensions
+                self.ui.apertures_table.setItem(self.apertures_row, 4, ap_dim_item)   # Aperture Dimensions
+
+                empty_plot_item = QtWidgets.QTableWidgetItem('')
+                empty_plot_item.setFlags(~QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
+                self.ui.apertures_table.setItem(self.apertures_row, 5, empty_plot_item)
+                self.ui.apertures_table.setCellWidget(self.apertures_row, 5, mark_item)
+
+                self.apertures_row += 1
+
+            self.ui.apertures_table.selectColumn(0)
+            self.ui.apertures_table.resizeColumnsToContents()
+            self.ui.apertures_table.resizeRowsToContents()
+
+            vertical_header = self.ui.apertures_table.verticalHeader()
+            # vertical_header.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
+            vertical_header.hide()
+            self.ui.apertures_table.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
+
+            horizontal_header = self.ui.apertures_table.horizontalHeader()
+            horizontal_header.setMinimumSectionSize(10)
+            horizontal_header.setDefaultSectionSize(70)
+            horizontal_header.setSectionResizeMode(0, QtWidgets.QHeaderView.Fixed)
+            horizontal_header.resizeSection(0, 27)
+            horizontal_header.setSectionResizeMode(1, QtWidgets.QHeaderView.ResizeToContents)
+            horizontal_header.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
+            horizontal_header.setSectionResizeMode(3, QtWidgets.QHeaderView.ResizeToContents)
+            horizontal_header.setSectionResizeMode(4,  QtWidgets.QHeaderView.Stretch)
+            horizontal_header.setSectionResizeMode(5, QtWidgets.QHeaderView.Fixed)
+            horizontal_header.resizeSection(5, 17)
+            self.ui.apertures_table.setColumnWidth(5, 17)
+
+            self.ui.apertures_table.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
+            self.ui.apertures_table.setSortingEnabled(False)
+            self.ui.apertures_table.setMinimumHeight(self.ui.apertures_table.getHeight())
+            self.ui.apertures_table.setMaximumHeight(self.ui.apertures_table.getHeight())
+
+            # update the 'mark' checkboxes state according with what is stored in the self.marked_rows list
+            if self.marked_rows:
+                for row in range(self.ui.apertures_table.rowCount()):
+                    try:
+                        self.ui.apertures_table.cellWidget(row, 5).set_value(self.marked_rows[row])
+                    except IndexError:
+                        pass
+
+            self.ui_connect()
+
+    def ui_connect(self):
+        for row in range(self.ui.apertures_table.rowCount()):
+            try:
+                self.ui.apertures_table.cellWidget(row, 5).clicked.disconnect(self.on_mark_cb_click_table)
+            except (TypeError, AttributeError):
+                pass
+            self.ui.apertures_table.cellWidget(row, 5).clicked.connect(self.on_mark_cb_click_table)
+
+        try:
+            self.ui.mark_all_cb.clicked.disconnect(self.on_mark_all_click)
+        except (TypeError, AttributeError):
+            pass
+        self.ui.mark_all_cb.clicked.connect(self.on_mark_all_click)
+
+    def ui_disconnect(self):
+        for row in range(self.ui.apertures_table.rowCount()):
+            try:
+                self.ui.apertures_table.cellWidget(row, 5).clicked.disconnect()
+            except (TypeError, AttributeError):
+                pass
+
+        try:
+            self.ui.mark_all_cb.clicked.disconnect(self.on_mark_all_click)
+        except (TypeError, AttributeError):
+            pass
+
+    def on_generate_buffer(self):
+        self.app.inform.emit('[WARNING_NOTCL] %s...' % _("Buffering solid geometry"))
+
+        def buffer_task():
+            with self.app.proc_container.new('%s...' % _("Buffering")):
+                if isinstance(self.solid_geometry, list):
+                    self.solid_geometry = MultiPolygon(self.solid_geometry)
+
+                self.solid_geometry = self.solid_geometry.buffer(0.0000001)
+                self.solid_geometry = self.solid_geometry.buffer(-0.0000001)
+                self.app.inform.emit('[success] %s.' % _("Done"))
+                self.plot_single_object.emit()
+
+        self.app.worker_task.emit({'fcn': buffer_task, 'params': []})
+
+    def on_generatenoncopper_button_click(self, *args):
+        self.app.report_usage("gerber_on_generatenoncopper_button")
+
+        self.read_form()
+        name = self.options["name"] + "_noncopper"
+
+        def geo_init(geo_obj, app_obj):
+            assert geo_obj.kind == 'geometry', "Expected a Geometry object got %s" % type(geo_obj)
+
+            if isinstance(self.solid_geometry, list):
+                try:
+                    self.solid_geometry = MultiPolygon(self.solid_geometry)
+                except Exception:
+                    self.solid_geometry = cascaded_union(self.solid_geometry)
+
+            bounding_box = self.solid_geometry.envelope.buffer(float(self.options["noncoppermargin"]))
+            if not self.options["noncopperrounded"]:
+                bounding_box = bounding_box.envelope
+            non_copper = bounding_box.difference(self.solid_geometry)
+
+            if non_copper is None or non_copper.is_empty:
+                self.app.inform.emit("[ERROR_NOTCL] %s" % _("Operation could not be done."))
+                return "fail"
+            geo_obj.solid_geometry = non_copper
+
+        self.app.new_object("geometry", name, geo_init)
+
+    def on_generatebb_button_click(self, *args):
+        self.app.report_usage("gerber_on_generatebb_button")
+        self.read_form()
+        name = self.options["name"] + "_bbox"
+
+        def geo_init(geo_obj, app_obj):
+            assert geo_obj.kind == 'geometry', "Expected a Geometry object got %s" % type(geo_obj)
+
+            if isinstance(self.solid_geometry, list):
+                try:
+                    self.solid_geometry = MultiPolygon(self.solid_geometry)
+                except Exception:
+                    self.solid_geometry = cascaded_union(self.solid_geometry)
+
+            # Bounding box with rounded corners
+            bounding_box = self.solid_geometry.envelope.buffer(float(self.options["bboxmargin"]))
+            if not self.options["bboxrounded"]:  # Remove rounded corners
+                bounding_box = bounding_box.envelope
+
+            if bounding_box is None or bounding_box.is_empty:
+                self.app.inform.emit("[ERROR_NOTCL] %s" % _("Operation could not be done."))
+                return "fail"
+            geo_obj.solid_geometry = bounding_box
+
+        self.app.new_object("geometry", name, geo_init)
+
+    def on_iso_button_click(self, *args):
+
+        obj = self.app.collection.get_active()
+
+        self.iso_type = 2
+        if self.ui.iso_type_radio.get_value() == 'ext':
+            self.iso_type = 0
+        if self.ui.iso_type_radio.get_value() == 'int':
+            self.iso_type = 1
+
+        def worker_task(iso_obj, app_obj):
+            with self.app.proc_container.new(_("Isolating...")):
+                if self.ui.follow_cb.get_value() is True:
+                    iso_obj.follow_geo()
+                    # in the end toggle the visibility of the origin object so we can see the generated Geometry
+                    iso_obj.ui.plot_cb.toggle()
+                else:
+                    app_obj.report_usage("gerber_on_iso_button")
+                    self.read_form()
+
+                    iso_scope = 'all' if self.ui.iso_scope_radio.get_value() == 'all' else 'single'
+                    self.isolate_handler(iso_type=self.iso_type, iso_scope=iso_scope)
+
+        self.app.worker_task.emit({'fcn': worker_task, 'params': [obj, self.app]})
+
+    def follow_geo(self, outname=None):
+        """
+        Creates a geometry object "following" the gerber paths.
+
+        :return: None
+        """
+
+        # default_name = self.options["name"] + "_follow"
+        # follow_name = outname or default_name
+
+        if outname is None:
+            follow_name = self.options["name"] + "_follow"
+        else:
+            follow_name = outname
+
+        def follow_init(follow_obj, app):
+            # Propagate options
+            follow_obj.options["cnctooldia"] = str(self.options["isotooldia"])
+            follow_obj.solid_geometry = self.follow_geometry
+
+        # TODO: Do something if this is None. Offer changing name?
+        try:
+            self.app.new_object("geometry", follow_name, follow_init)
+        except Exception as e:
+            return "Operation failed: %s" % str(e)
+
+    def isolate_handler(self, iso_type, iso_scope):
+
+        if iso_scope == 'all':
+            self.isolate(iso_type=iso_type)
+        else:
+            # disengage the grid snapping since it may be hard to click on polygons with grid snapping on
+            if self.app.ui.grid_snap_btn.isChecked():
+                self.grid_status_memory = True
+                self.app.ui.grid_snap_btn.trigger()
+            else:
+                self.grid_status_memory = False
+
+            self.mr = self.app.plotcanvas.graph_event_connect('mouse_release', self.on_mouse_click_release)
+
+            if self.app.is_legacy is False:
+                self.app.plotcanvas.graph_event_disconnect('mouse_release', self.app.on_mouse_click_release_over_plot)
+            else:
+                self.app.plotcanvas.graph_event_disconnect(self.app.mr)
+
+            self.app.inform.emit('[WARNING_NOTCL] %s' % _("Click on a polygon to isolate it."))
+
+    def on_mouse_click_release(self, event):
+        if self.app.is_legacy is False:
+            event_pos = event.pos
+            right_button = 2
+            self.app.event_is_dragging = self.app.event_is_dragging
+        else:
+            event_pos = (event.xdata, event.ydata)
+            right_button = 3
+            self.app.event_is_dragging = self.app.ui.popMenu.mouse_is_panning
+
+        try:
+            x = float(event_pos[0])
+            y = float(event_pos[1])
+        except TypeError:
+            return
+
+        event_pos = (x, y)
+        curr_pos = self.app.plotcanvas.translate_coords(event_pos)
+        if self.app.grid_status():
+            curr_pos = self.app.geo_editor.snap(curr_pos[0], curr_pos[1])
+        else:
+            curr_pos = (curr_pos[0], curr_pos[1])
+
+        if event.button == 1:
+            clicked_poly = self.find_polygon(point=(curr_pos[0], curr_pos[1]))
+
+            if self.app.selection_type is not None:
+                self.selection_area_handler(self.app.pos, curr_pos, self.app.selection_type)
+                self.app.selection_type = None
+            elif clicked_poly:
+                if clicked_poly not in self.poly_dict.values():
+                    shape_id = self.app.tool_shapes.add(tolerance=self.drawing_tolerance, layer=0, shape=clicked_poly,
+                                                        color=self.app.defaults['global_sel_draw_color'] + 'AF',
+                                                        face_color=self.app.defaults['global_sel_draw_color'] + 'AF',
+                                                        visible=True)
+                    self.poly_dict[shape_id] = clicked_poly
+                    self.app.inform.emit(
+                        '%s: %d. %s' % (_("Added polygon"), int(len(self.poly_dict)),
+                                        _("Click to add next polygon or right click to start isolation."))
+                    )
+                else:
+                    try:
+                        for k, v in list(self.poly_dict.items()):
+                            if v == clicked_poly:
+                                self.app.tool_shapes.remove(k)
+                                self.poly_dict.pop(k)
+                                break
+                    except TypeError:
+                        return
+                    self.app.inform.emit(
+                        '%s. %s' % (_("Removed polygon"),
+                                    _("Click to add/remove next polygon or right click to start isolation."))
+                    )
+
+                self.app.tool_shapes.redraw()
+            else:
+                self.app.inform.emit(_("No polygon detected under click position."))
+        elif event.button == right_button and self.app.event_is_dragging is False:
+            # restore the Grid snapping if it was active before
+            if self.grid_status_memory is True:
+                self.app.ui.grid_snap_btn.trigger()
+
+            if self.app.is_legacy is False:
+                self.app.plotcanvas.graph_event_disconnect('mouse_release', self.on_mouse_click_release)
+            else:
+                self.app.plotcanvas.graph_event_disconnect(self.mr)
+
+            self.app.mr = self.app.plotcanvas.graph_event_connect('mouse_release',
+                                                                  self.app.on_mouse_click_release_over_plot)
+
+            self.app.tool_shapes.clear(update=True)
+
+            if self.poly_dict:
+                poly_list = deepcopy(list(self.poly_dict.values()))
+                self.isolate(iso_type=self.iso_type, geometry=poly_list)
+                self.poly_dict.clear()
+            else:
+                self.app.inform.emit('[ERROR_NOTCL] %s' % _("List of single polygons is empty. Aborting."))
+
+    def selection_area_handler(self, start_pos, end_pos, sel_type):
+        """
+        :param start_pos: mouse position when the selection LMB click was done
+        :param end_pos: mouse position when the left mouse button is released
+        :param sel_type: if True it's a left to right selection (enclosure), if False it's a 'touch' selection
+        :return:
+        """
+        poly_selection = Polygon([start_pos, (end_pos[0], start_pos[1]), end_pos, (start_pos[0], end_pos[1])])
+
+        # delete previous selection shape
+        self.app.delete_selection_shape()
+
+        added_poly_count = 0
+        try:
+            for geo in self.solid_geometry:
+                if geo not in self.poly_dict.values():
+                    if sel_type is True:
+                        if geo.within(poly_selection):
+                            shape_id = self.app.tool_shapes.add(tolerance=self.drawing_tolerance, layer=0,
+                                                                shape=geo,
+                                                                color=self.app.defaults['global_sel_draw_color'] + 'AF',
+                                                                face_color=self.app.defaults[
+                                                                               'global_sel_draw_color'] + 'AF',
+                                                                visible=True)
+                            self.poly_dict[shape_id] = geo
+                            added_poly_count += 1
+                    else:
+                        if poly_selection.intersects(geo):
+                            shape_id = self.app.tool_shapes.add(tolerance=self.drawing_tolerance, layer=0,
+                                                                shape=geo,
+                                                                color=self.app.defaults['global_sel_draw_color'] + 'AF',
+                                                                face_color=self.app.defaults[
+                                                                               'global_sel_draw_color'] + 'AF',
+                                                                visible=True)
+                            self.poly_dict[shape_id] = geo
+                            added_poly_count += 1
+        except TypeError:
+            if self.solid_geometry not in self.poly_dict.values():
+                if sel_type is True:
+                    if self.solid_geometry.within(poly_selection):
+                        shape_id = self.app.tool_shapes.add(tolerance=self.drawing_tolerance, layer=0,
+                                                            shape=self.solid_geometry,
+                                                            color=self.app.defaults['global_sel_draw_color'] + 'AF',
+                                                            face_color=self.app.defaults[
+                                                                           'global_sel_draw_color'] + 'AF',
+                                                            visible=True)
+                        self.poly_dict[shape_id] = self.solid_geometry
+                        added_poly_count += 1
+                else:
+                    if poly_selection.intersects(self.solid_geometry):
+                        shape_id = self.app.tool_shapes.add(tolerance=self.drawing_tolerance, layer=0,
+                                                            shape=self.solid_geometry,
+                                                            color=self.app.defaults['global_sel_draw_color'] + 'AF',
+                                                            face_color=self.app.defaults[
+                                                                           'global_sel_draw_color'] + 'AF',
+                                                            visible=True)
+                        self.poly_dict[shape_id] = self.solid_geometry
+                        added_poly_count += 1
+
+        if added_poly_count > 0:
+            self.app.tool_shapes.redraw()
+            self.app.inform.emit(
+                '%s: %d. %s' % (_("Added polygon"),
+                                int(added_poly_count),
+                                _("Click to add next polygon or right click to start isolation."))
+            )
+        else:
+            self.app.inform.emit(_("No polygon in selection."))
+
+    def isolate(self, iso_type=None, geometry=None, dia=None, passes=None, overlap=None, outname=None, combine=None,
+                milling_type=None, follow=None, plot=True):
+        """
+        Creates an isolation routing geometry object in the project.
+
+        :param iso_type: type of isolation to be done: 0 = exteriors, 1 = interiors and 2 = both
+        :param geometry: specific geometry to isolate
+        :param dia: Tool diameter
+        :param passes: Number of tool widths to cut
+        :param overlap: Overlap between passes in fraction of tool diameter
+        :param outname: Base name of the output object
+        :param combine: Boolean: if to combine passes in one resulting object in case of multiple passes
+        :param milling_type: type of milling: conventional or climbing
+        :param follow: Boolean: if to generate a 'follow' geometry
+        :param plot: Boolean: if to plot the resulting geometry object
+        :return: None
+        """
+
+        if geometry is None:
+            work_geo = self.follow_geometry if follow is True else self.solid_geometry
+        else:
+            work_geo = geometry
+
+        if dia is None:
+            dia = float(self.options["isotooldia"])
+
+        if passes is None:
+            passes = int(self.options["isopasses"])
+
+        if overlap is None:
+            overlap = float(self.options["isooverlap"])
+
+        overlap /= 100.0
+
+        combine = self.options["combine_passes"] if combine is None else bool(combine)
+
+        if milling_type is None:
+            milling_type = self.options["milling_type"]
+
+        if iso_type is None:
+            iso_t = 2
+        else:
+            iso_t = iso_type
+
+        base_name = self.options["name"]
+
+        if combine:
+            if outname is None:
+                if self.iso_type == 0:
+                    iso_name = base_name + "_ext_iso"
+                elif self.iso_type == 1:
+                    iso_name = base_name + "_int_iso"
+                else:
+                    iso_name = base_name + "_iso"
+            else:
+                iso_name = outname
+
+            def iso_init(geo_obj, app_obj):
+                # Propagate options
+                geo_obj.options["cnctooldia"] = str(self.options["isotooldia"])
+                geo_obj.tool_type = self.ui.tool_type_radio.get_value().upper()
+
+                geo_obj.solid_geometry = []
+
+                # transfer the Cut Z and Vtip and VAngle values in case that we use the V-Shape tool in Gerber UI
+                if self.ui.tool_type_radio.get_value() == 'v':
+                    new_cutz = self.ui.cutz_spinner.get_value()
+                    new_vtipdia = self.ui.tipdia_spinner.get_value()
+                    new_vtipangle = self.ui.tipangle_spinner.get_value()
+                    tool_type = 'V'
+                else:
+                    new_cutz = self.app.defaults['geometry_cutz']
+                    new_vtipdia = self.app.defaults['geometry_vtipdia']
+                    new_vtipangle = self.app.defaults['geometry_vtipangle']
+                    tool_type = 'C1'
+
+                # store here the default data for Geometry Data
+                default_data = {}
+                default_data.update({
+                    "name": iso_name,
+                    "plot": self.app.defaults['geometry_plot'],
+                    "cutz": new_cutz,
+                    "vtipdia": new_vtipdia,
+                    "vtipangle": new_vtipangle,
+                    "travelz": self.app.defaults['geometry_travelz'],
+                    "feedrate": self.app.defaults['geometry_feedrate'],
+                    "feedrate_z": self.app.defaults['geometry_feedrate_z'],
+                    "feedrate_rapid": self.app.defaults['geometry_feedrate_rapid'],
+                    "dwell": self.app.defaults['geometry_dwell'],
+                    "dwelltime": self.app.defaults['geometry_dwelltime'],
+                    "multidepth": self.app.defaults['geometry_multidepth'],
+                    "ppname_g": self.app.defaults['geometry_ppname_g'],
+                    "depthperpass": self.app.defaults['geometry_depthperpass'],
+                    "extracut": self.app.defaults['geometry_extracut'],
+                    "extracut_length": self.app.defaults['geometry_extracut_length'],
+                    "toolchange": self.app.defaults['geometry_toolchange'],
+                    "toolchangez": self.app.defaults['geometry_toolchangez'],
+                    "endz": self.app.defaults['geometry_endz'],
+                    "spindlespeed": self.app.defaults['geometry_spindlespeed'],
+                    "toolchangexy": self.app.defaults['geometry_toolchangexy'],
+                    "startz": self.app.defaults['geometry_startz']
+                })
+
+                geo_obj.tools = {}
+                geo_obj.tools['1'] = {}
+                geo_obj.tools.update({
+                    '1': {
+                        'tooldia': float(self.options["isotooldia"]),
+                        'offset': 'Path',
+                        'offset_value': 0.0,
+                        'type': _('Rough'),
+                        'tool_type': tool_type,
+                        'data': default_data,
+                        'solid_geometry': geo_obj.solid_geometry
+                    }
+                })
+
+                for nr_pass in range(passes):
+                    iso_offset = dia * ((2 * nr_pass + 1) / 2.0) - (nr_pass * overlap * dia)
+
+                    # if milling type is climb then the move is counter-clockwise around features
+                    mill_dir = 1 if milling_type == 'cl' else 0
+                    geom = self.generate_envelope(iso_offset, mill_dir, geometry=work_geo, env_iso_type=iso_t,
+                                                  follow=follow, nr_passes=nr_pass)
+
+                    if geom == 'fail':
+                        app_obj.inform.emit('[ERROR_NOTCL] %s' % _("Isolation geometry could not be generated."))
+                        return 'fail'
+                    geo_obj.solid_geometry.append(geom)
+
+                    # update the geometry in the tools
+                    geo_obj.tools['1']['solid_geometry'] = geo_obj.solid_geometry
+
+                # detect if solid_geometry is empty and this require list flattening which is "heavy"
+                # or just looking in the lists (they are one level depth) and if any is not empty
+                # proceed with object creation, if there are empty and the number of them is the length
+                # of the list then we have an empty solid_geometry which should raise a Custom Exception
+                empty_cnt = 0
+                if not isinstance(geo_obj.solid_geometry, list) and \
+                        not isinstance(geo_obj.solid_geometry, MultiPolygon):
+                    geo_obj.solid_geometry = [geo_obj.solid_geometry]
+
+                for g in geo_obj.solid_geometry:
+                    if g:
+                        break
+                    else:
+                        empty_cnt += 1
+
+                if empty_cnt == len(geo_obj.solid_geometry):
+                    raise ValidationError("Empty Geometry", None)
+                else:
+                    app_obj.inform.emit('[success] %s" %s' % (_("Isolation geometry created"), geo_obj.options["name"]))
+
+                # even if combine is checked, one pass is still single-geo
+                geo_obj.multigeo = True if passes > 1 else False
+
+                # ############################################################
+                # ########## AREA SUBTRACTION ################################
+                # ############################################################
+                if self.ui.except_cb.get_value():
+                    self.app.proc_container.update_view_text(' %s' % _("Subtracting Geo"))
+                    geo_obj.solid_geometry = self.area_subtraction(geo_obj.solid_geometry)
+
+            # TODO: Do something if this is None. Offer changing name?
+            self.app.new_object("geometry", iso_name, iso_init, plot=plot)
+        else:
+            for i in range(passes):
+
+                offset = dia * ((2 * i + 1) / 2.0) - (i * overlap * dia)
+                if passes > 1:
+                    if outname is None:
+                        if self.iso_type == 0:
+                            iso_name = base_name + "_ext_iso" + str(i + 1)
+                        elif self.iso_type == 1:
+                            iso_name = base_name + "_int_iso" + str(i + 1)
+                        else:
+                            iso_name = base_name + "_iso" + str(i + 1)
+                    else:
+                        iso_name = outname
+                else:
+                    if outname is None:
+                        if self.iso_type == 0:
+                            iso_name = base_name + "_ext_iso"
+                        elif self.iso_type == 1:
+                            iso_name = base_name + "_int_iso"
+                        else:
+                            iso_name = base_name + "_iso"
+                    else:
+                        iso_name = outname
+
+                def iso_init(geo_obj, app_obj):
+                    # Propagate options
+                    geo_obj.options["cnctooldia"] = str(self.options["isotooldia"])
+                    if self.ui.tool_type_radio.get_value() == 'v':
+                        geo_obj.tool_type = 'V'
+                    else:
+                        geo_obj.tool_type = 'C1'
+
+                    # if milling type is climb then the move is counter-clockwise around features
+                    mill_dir = 1 if milling_type == 'cl' else 0
+                    geom = self.generate_envelope(offset, mill_dir, geometry=work_geo, env_iso_type=iso_t,
+                                                  follow=follow,
+                                                  nr_passes=i)
+
+                    if geom == 'fail':
+                        app_obj.inform.emit('[ERROR_NOTCL] %s' % _("Isolation geometry could not be generated."))
+                        return 'fail'
+
+                    geo_obj.solid_geometry = geom
+
+                    # transfer the Cut Z and Vtip and VAngle values in case that we use the V-Shape tool in Gerber UI
+                    # even if the resulting geometry is not multigeo we add the tools dict which will hold the data
+                    # required to be transfered to the Geometry object
+                    if self.ui.tool_type_radio.get_value() == 'v':
+                        new_cutz = self.ui.cutz_spinner.get_value()
+                        new_vtipdia = self.ui.tipdia_spinner.get_value()
+                        new_vtipangle = self.ui.tipangle_spinner.get_value()
+                        tool_type = 'V'
+                    else:
+                        new_cutz = self.app.defaults['geometry_cutz']
+                        new_vtipdia = self.app.defaults['geometry_vtipdia']
+                        new_vtipangle = self.app.defaults['geometry_vtipangle']
+                        tool_type = 'C1'
+
+                    # store here the default data for Geometry Data
+                    default_data = {}
+                    default_data.update({
+                        "name": iso_name,
+                        "plot": self.app.defaults['geometry_plot'],
+                        "cutz": new_cutz,
+                        "vtipdia": new_vtipdia,
+                        "vtipangle": new_vtipangle,
+                        "travelz": self.app.defaults['geometry_travelz'],
+                        "feedrate": self.app.defaults['geometry_feedrate'],
+                        "feedrate_z": self.app.defaults['geometry_feedrate_z'],
+                        "feedrate_rapid": self.app.defaults['geometry_feedrate_rapid'],
+                        "dwell": self.app.defaults['geometry_dwell'],
+                        "dwelltime": self.app.defaults['geometry_dwelltime'],
+                        "multidepth": self.app.defaults['geometry_multidepth'],
+                        "ppname_g": self.app.defaults['geometry_ppname_g'],
+                        "depthperpass": self.app.defaults['geometry_depthperpass'],
+                        "extracut": self.app.defaults['geometry_extracut'],
+                        "extracut_length": self.app.defaults['geometry_extracut_length'],
+                        "toolchange": self.app.defaults['geometry_toolchange'],
+                        "toolchangez": self.app.defaults['geometry_toolchangez'],
+                        "endz": self.app.defaults['geometry_endz'],
+                        "spindlespeed": self.app.defaults['geometry_spindlespeed'],
+                        "toolchangexy": self.app.defaults['geometry_toolchangexy'],
+                        "startz": self.app.defaults['geometry_startz']
+                    })
+
+                    geo_obj.tools = {}
+                    geo_obj.tools['1'] = {}
+                    geo_obj.tools.update({
+                        '1': {
+                            'tooldia': float(self.options["isotooldia"]),
+                            'offset': 'Path',
+                            'offset_value': 0.0,
+                            'type': _('Rough'),
+                            'tool_type': tool_type,
+                            'data': default_data,
+                            'solid_geometry': geo_obj.solid_geometry
+                        }
+                    })
+
+                    # detect if solid_geometry is empty and this require list flattening which is "heavy"
+                    # or just looking in the lists (they are one level depth) and if any is not empty
+                    # proceed with object creation, if there are empty and the number of them is the length
+                    # of the list then we have an empty solid_geometry which should raise a Custom Exception
+                    empty_cnt = 0
+                    if not isinstance(geo_obj.solid_geometry, list):
+                        geo_obj.solid_geometry = [geo_obj.solid_geometry]
+
+                    for g in geo_obj.solid_geometry:
+                        if g:
+                            break
+                        else:
+                            empty_cnt += 1
+
+                    if empty_cnt == len(geo_obj.solid_geometry):
+                        raise ValidationError("Empty Geometry", None)
+                    else:
+                        app_obj.inform.emit('[success] %s: %s' %
+                                            (_("Isolation geometry created"), geo_obj.options["name"]))
+                    geo_obj.multigeo = False
+
+                    # ############################################################
+                    # ########## AREA SUBTRACTION ################################
+                    # ############################################################
+                    if self.ui.except_cb.get_value():
+                        self.app.proc_container.update_view_text(' %s' % _("Subtracting Geo"))
+                        geo_obj.solid_geometry = self.area_subtraction(geo_obj.solid_geometry)
+
+                # TODO: Do something if this is None. Offer changing name?
+                self.app.new_object("geometry", iso_name, iso_init, plot=plot)
+
+    def generate_envelope(self, offset, invert, geometry=None, env_iso_type=2, follow=None, nr_passes=0):
+        # isolation_geometry produces an envelope that is going on the left of the geometry
+        # (the copper features). To leave the least amount of burrs on the features
+        # the tool needs to travel on the right side of the features (this is called conventional milling)
+        # the first pass is the one cutting all of the features, so it needs to be reversed
+        # the other passes overlap preceding ones and cut the left over copper. It is better for them
+        # to cut on the right side of the left over copper i.e on the left side of the features.
+
+        if follow:
+            geom = self.isolation_geometry(offset, geometry=geometry, follow=follow)
+        else:
+            try:
+                geom = self.isolation_geometry(offset, geometry=geometry, iso_type=env_iso_type, passes=nr_passes)
+            except Exception as e:
+                log.debug('GerberObject.isolate().generate_envelope() --> %s' % str(e))
+                return 'fail'
+
+        if invert:
+            try:
+                pl = []
+                for p in geom:
+                    if p is not None:
+                        if isinstance(p, Polygon):
+                            pl.append(Polygon(p.exterior.coords[::-1], p.interiors))
+                        elif isinstance(p, LinearRing):
+                            pl.append(Polygon(p.coords[::-1]))
+                geom = MultiPolygon(pl)
+            except TypeError:
+                if isinstance(geom, Polygon) and geom is not None:
+                    geom = Polygon(geom.exterior.coords[::-1], geom.interiors)
+                elif isinstance(geom, LinearRing) and geom is not None:
+                    geom = Polygon(geom.coords[::-1])
+                else:
+                    log.debug("GerberObject.isolate().generate_envelope() Error --> Unexpected Geometry %s" %
+                              type(geom))
+            except Exception as e:
+                log.debug("GerberObject.isolate().generate_envelope() Error --> %s" % str(e))
+                return 'fail'
+        return geom
+
+    def area_subtraction(self, geo, subtractor_geo=None):
+        """
+        Subtracts the subtractor_geo (if present else self.solid_geometry) from the geo
+
+        :param geo: target geometry from which to subtract
+        :param subtractor_geo: geometry that acts as subtractor
+        :return:
+        """
+        new_geometry = []
+        target_geo = geo
+
+        if subtractor_geo:
+            sub_union = cascaded_union(subtractor_geo)
+        else:
+            name = self.ui.obj_combo.currentText()
+            subtractor_obj = self.app.collection.get_by_name(name)
+            sub_union = cascaded_union(subtractor_obj.solid_geometry)
+
+        try:
+            for geo_elem in target_geo:
+                if isinstance(geo_elem, Polygon):
+                    for ring in self.poly2rings(geo_elem):
+                        new_geo = ring.difference(sub_union)
+                        if new_geo and not new_geo.is_empty:
+                            new_geometry.append(new_geo)
+                elif isinstance(geo_elem, MultiPolygon):
+                    for poly in geo_elem:
+                        for ring in self.poly2rings(poly):
+                            new_geo = ring.difference(sub_union)
+                            if new_geo and not new_geo.is_empty:
+                                new_geometry.append(new_geo)
+                elif isinstance(geo_elem, LineString):
+                    new_geo = geo_elem.difference(sub_union)
+                    if new_geo:
+                        if not new_geo.is_empty:
+                            new_geometry.append(new_geo)
+                elif isinstance(geo_elem, MultiLineString):
+                    for line_elem in geo_elem:
+                        new_geo = line_elem.difference(sub_union)
+                        if new_geo and not new_geo.is_empty:
+                            new_geometry.append(new_geo)
+        except TypeError:
+            if isinstance(target_geo, Polygon):
+                for ring in self.poly2rings(target_geo):
+                    new_geo = ring.difference(sub_union)
+                    if new_geo:
+                        if not new_geo.is_empty:
+                            new_geometry.append(new_geo)
+            elif isinstance(target_geo, LineString):
+                new_geo = target_geo.difference(sub_union)
+                if new_geo and not new_geo.is_empty:
+                    new_geometry.append(new_geo)
+            elif isinstance(target_geo, MultiLineString):
+                for line_elem in target_geo:
+                    new_geo = line_elem.difference(sub_union)
+                    if new_geo and not new_geo.is_empty:
+                        new_geometry.append(new_geo)
+        return new_geometry
+
+    def on_plot_cb_click(self, *args):
+        if self.muted_ui:
+            return
+        self.read_form_item('plot')
+        self.plot()
+
+    def on_solid_cb_click(self, *args):
+        if self.muted_ui:
+            return
+        self.read_form_item('solid')
+        self.plot()
+
+    def on_multicolored_cb_click(self, *args):
+        if self.muted_ui:
+            return
+        self.read_form_item('multicolored')
+        self.plot()
+
+    def on_follow_cb_click(self):
+        if self.muted_ui:
+            return
+        self.plot()
+
+    def on_aperture_table_visibility_change(self):
+        if self.ui.aperture_table_visibility_cb.isChecked():
+            # add the shapes storage for marking apertures
+            if self.build_aperture_storage is False:
+                self.build_aperture_storage = True
+
+                if self.app.is_legacy is False:
+                    for ap_code in self.apertures:
+                        self.mark_shapes[ap_code] = self.app.plotcanvas.new_shape_collection(layers=1)
+                else:
+                    for ap_code in self.apertures:
+                        self.mark_shapes[ap_code] = ShapeCollectionLegacy(obj=self, app=self.app,
+                                                                          name=self.options['name'] + str(ap_code))
+
+            self.ui.apertures_table.setVisible(True)
+            for ap in self.mark_shapes:
+                self.mark_shapes[ap].enabled = True
+
+            self.ui.mark_all_cb.setVisible(True)
+            self.ui.mark_all_cb.setChecked(False)
+            self.build_ui()
+        else:
+            self.ui.apertures_table.setVisible(False)
+
+            self.ui.mark_all_cb.setVisible(False)
+
+            # on hide disable all mark plots
+            try:
+                for row in range(self.ui.apertures_table.rowCount()):
+                    self.ui.apertures_table.cellWidget(row, 5).set_value(False)
+                self.clear_plot_apertures()
+
+                # for ap in list(self.mark_shapes.keys()):
+                #     # self.mark_shapes[ap].enabled = False
+                #     del self.mark_shapes[ap]
+            except Exception as e:
+                log.debug(" GerberObject.on_aperture_visibility_changed() --> %s" % str(e))
+
+    def convert_units(self, units):
+        """
+        Converts the units of the object by scaling dimensions in all geometry
+        and options.
+
+        :param units: Units to which to convert the object: "IN" or "MM".
+        :type units: str
+        :return: None
+        :rtype: None
+        """
+
+        # units conversion to get a conversion should be done only once even if we found multiple
+        # units declaration inside a Gerber file (it can happen to find also the obsolete declaration)
+        if self.conversion_done is True:
+            log.debug("Gerber units conversion cancelled. Already done.")
+            return
+
+        log.debug("FlatCAMObj.GerberObject.convert_units()")
+
+        factor = Gerber.convert_units(self, units)
+
+        # self.options['isotooldia'] = float(self.options['isotooldia']) * factor
+        # self.options['bboxmargin'] = float(self.options['bboxmargin']) * factor
+
+    def plot(self, kind=None, **kwargs):
+        """
+
+        :param kind:    Not used, for compatibility with the plot method for other objects
+        :param kwargs:  Color and face_color, visible
+        :return:
+        """
+        log.debug(str(inspect.stack()[1][3]) + " --> GerberObject.plot()")
+
+        # Does all the required setup and returns False
+        # if the 'ptint' option is set to False.
+        if not FlatCAMObj.plot(self):
+            return
+
+        if 'color' in kwargs:
+            color = kwargs['color']
+        else:
+            color = self.outline_color
+
+        if 'face_color' in kwargs:
+            face_color = kwargs['face_color']
+        else:
+            face_color = self.fill_color
+
+        if 'visible' not in kwargs:
+            visible = self.options['plot']
+        else:
+            visible = kwargs['visible']
+
+        # if the Follow Geometry checkbox is checked then plot only the follow geometry
+        if self.ui.follow_cb.get_value():
+            geometry = self.follow_geometry
+        else:
+            geometry = self.solid_geometry
+
+        # Make sure geometry is iterable.
+        try:
+            __ = iter(geometry)
+        except TypeError:
+            geometry = [geometry]
+
+        if self.app.is_legacy is False:
+            def random_color():
+                r_color = np.random.rand(4)
+                r_color[3] = 1
+                return r_color
+        else:
+            def random_color():
+                while True:
+                    r_color = np.random.rand(4)
+                    r_color[3] = 1
+
+                    new_color = '#'
+                    for idx in range(len(r_color)):
+                        new_color += '%x' % int(r_color[idx] * 255)
+                    # do it until a valid color is generated
+                    # a valid color has the # symbol, another 6 chars for the color and the last 2 chars for alpha
+                    # for a total of 9 chars
+                    if len(new_color) == 9:
+                        break
+                return new_color
+
+        try:
+            if self.options["solid"]:
+                for g in geometry:
+                    if type(g) == Polygon or type(g) == LineString:
+                        self.add_shape(shape=g, color=color,
+                                       face_color=random_color() if self.options['multicolored']
+                                       else face_color, visible=visible)
+                    elif type(g) == Point:
+                        pass
+                    else:
+                        try:
+                            for el in g:
+                                self.add_shape(shape=el, color=color,
+                                               face_color=random_color() if self.options['multicolored']
+                                               else face_color, visible=visible)
+                        except TypeError:
+                            self.add_shape(shape=g, color=color,
+                                           face_color=random_color() if self.options['multicolored']
+                                           else face_color, visible=visible)
+            else:
+                for g in geometry:
+                    if type(g) == Polygon or type(g) == LineString:
+                        self.add_shape(shape=g, color=random_color() if self.options['multicolored'] else 'black',
+                                       visible=visible)
+                    elif type(g) == Point:
+                        pass
+                    else:
+                        for el in g:
+                            self.add_shape(shape=el, color=random_color() if self.options['multicolored'] else 'black',
+                                           visible=visible)
+            self.shapes.redraw(
+                # update_colors=(self.fill_color, self.outline_color),
+                # indexes=self.app.plotcanvas.shape_collection.data.keys()
+            )
+        except (ObjectDeleted, AttributeError):
+            self.shapes.clear(update=True)
+        except Exception as e:
+            log.debug("GerberObject.plot() --> %s" % str(e))
+
+    # experimental plot() when the solid_geometry is stored in the self.apertures
+    def plot_aperture(self, run_thread=True, **kwargs):
+        """
+
+        :param run_thread: if True run the aperture plot as a thread in a worker
+        :param kwargs: color and face_color
+        :return:
+        """
+
+        log.debug(str(inspect.stack()[1][3]) + " --> GerberObject.plot_aperture()")
+
+        # Does all the required setup and returns False
+        # if the 'ptint' option is set to False.
+        # if not FlatCAMObj.plot(self):
+        #     return
+
+        # for marking apertures, line color and fill color are the same
+        if 'color' in kwargs:
+            color = kwargs['color']
+        else:
+            color = self.app.defaults['gerber_plot_fill']
+
+        if 'marked_aperture' not in kwargs:
+            return
+        else:
+            aperture_to_plot_mark = kwargs['marked_aperture']
+            if aperture_to_plot_mark is None:
+                return
+
+        if 'visible' not in kwargs:
+            visibility = True
+        else:
+            visibility = kwargs['visible']
+
+        with self.app.proc_container.new(_("Plotting Apertures")):
+
+            def job_thread(app_obj):
+                try:
+                    if aperture_to_plot_mark in self.apertures:
+                        for elem in self.apertures[aperture_to_plot_mark]['geometry']:
+                            if 'solid' in elem:
+                                geo = elem['solid']
+                                if type(geo) == Polygon or type(geo) == LineString:
+                                    self.add_mark_shape(apid=aperture_to_plot_mark, shape=geo, color=color,
+                                                        face_color=color, visible=visibility)
+                                else:
+                                    for el in geo:
+                                        self.add_mark_shape(apid=aperture_to_plot_mark, shape=el, color=color,
+                                                            face_color=color, visible=visibility)
+
+                    self.mark_shapes[aperture_to_plot_mark].redraw()
+
+                except (ObjectDeleted, AttributeError):
+                    self.clear_plot_apertures()
+                except Exception as e:
+                    log.debug("GerberObject.plot_aperture() --> %s" % str(e))
+
+            if run_thread:
+                self.app.worker_task.emit({'fcn': job_thread, 'params': [self]})
+            else:
+                job_thread(self)
+
+    def clear_plot_apertures(self, aperture='all'):
+        """
+
+        :param aperture: string; aperture for which to clear the mark shapes
+        :return:
+        """
+
+        if self.mark_shapes:
+            if aperture == 'all':
+                for apid in list(self.apertures.keys()):
+                    try:
+                        if self.app.is_legacy is True:
+                            self.mark_shapes[apid].clear(update=False)
+                        else:
+                            self.mark_shapes[apid].clear(update=True)
+                    except Exception as e:
+                        log.debug("GerberObject.clear_plot_apertures() 'all' --> %s" % str(e))
+            else:
+                try:
+                    if self.app.is_legacy is True:
+                        self.mark_shapes[aperture].clear(update=False)
+                    else:
+                        self.mark_shapes[aperture].clear(update=True)
+                except Exception as e:
+                    log.debug("GerberObject.clear_plot_apertures() 'aperture' --> %s" % str(e))
+
+    def clear_mark_all(self):
+        self.ui.mark_all_cb.set_value(False)
+        self.marked_rows[:] = []
+
+    def on_mark_cb_click_table(self):
+        """
+        Will mark aperture geometries on canvas or delete the markings depending on the checkbox state
+        :return:
+        """
+
+        self.ui_disconnect()
+        try:
+            cw = self.sender()
+            assert isinstance(cw, FCCheckBox),\
+                "Expected a cellWidget but got %s" % type(cw)
+            cw_index = self.ui.apertures_table.indexAt(cw.pos())
+            cw_row = cw_index.row()
+        except AttributeError:
+            cw_row = 0
+        except TypeError:
+            return
+
+        self.marked_rows[:] = []
+
+        try:
+            aperture = self.ui.apertures_table.item(cw_row, 1).text()
+        except AttributeError:
+            return
+
+        if self.ui.apertures_table.cellWidget(cw_row, 5).isChecked():
+            self.marked_rows.append(True)
+            # self.plot_aperture(color='#2d4606bf', marked_aperture=aperture, visible=True)
+            self.plot_aperture(color=self.app.defaults['global_sel_draw_color'] + 'AF',
+                               marked_aperture=aperture, visible=True, run_thread=True)
+            # self.mark_shapes[aperture].redraw()
+        else:
+            self.marked_rows.append(False)
+            self.clear_plot_apertures(aperture=aperture)
+
+        # make sure that the Mark All is disabled if one of the row mark's are disabled and
+        # if all the row mark's are enabled also enable the Mark All checkbox
+        cb_cnt = 0
+        total_row = self.ui.apertures_table.rowCount()
+        for row in range(total_row):
+            if self.ui.apertures_table.cellWidget(row, 5).isChecked():
+                cb_cnt += 1
+            else:
+                cb_cnt -= 1
+        if cb_cnt < total_row:
+            self.ui.mark_all_cb.setChecked(False)
+        else:
+            self.ui.mark_all_cb.setChecked(True)
+        self.ui_connect()
+
+    def on_mark_all_click(self):
+        self.ui_disconnect()
+        mark_all = self.ui.mark_all_cb.isChecked()
+        for row in range(self.ui.apertures_table.rowCount()):
+            # update the mark_rows list
+            if mark_all:
+                self.marked_rows.append(True)
+            else:
+                self.marked_rows[:] = []
+
+            mark_cb = self.ui.apertures_table.cellWidget(row, 5)
+            mark_cb.setChecked(mark_all)
+
+        if mark_all:
+            for aperture in self.apertures:
+                # self.plot_aperture(color='#2d4606bf', marked_aperture=aperture, visible=True)
+                self.plot_aperture(color=self.app.defaults['global_sel_draw_color'] + 'AF',
+                                   marked_aperture=aperture, visible=True)
+            # HACK: enable/disable the grid for a better look
+            self.app.ui.grid_snap_btn.trigger()
+            self.app.ui.grid_snap_btn.trigger()
+        else:
+            self.clear_plot_apertures()
+            self.marked_rows[:] = []
+
+        self.ui_connect()
+
+    def export_gerber(self, whole, fract, g_zeros='L', factor=1):
+        """
+        Creates a Gerber file content to be exported to a file.
+
+        :param whole: how many digits in the whole part of coordinates
+        :param fract: how many decimals in coordinates
+        :param g_zeros: type of the zero suppression used: LZ or TZ; string
+        :param factor: factor to be applied onto the Gerber coordinates
+        :return: Gerber_code
+        """
+        log.debug("GerberObject.export_gerber() --> Generating the Gerber code from the selected Gerber file")
+
+        def tz_format(x, y, fac):
+            x_c = x * fac
+            y_c = y * fac
+
+            x_form = "{:.{dec}f}".format(x_c, dec=fract)
+            y_form = "{:.{dec}f}".format(y_c, dec=fract)
+
+            # extract whole part and decimal part
+            x_form = x_form.partition('.')
+            y_form = y_form.partition('.')
+
+            # left padd the 'whole' part with zeros
+            x_whole = x_form[0].rjust(whole, '0')
+            y_whole = y_form[0].rjust(whole, '0')
+
+            # restore the coordinate padded in the left with 0 and added the decimal part
+            # without the decinal dot
+            x_form = x_whole + x_form[2]
+            y_form = y_whole + y_form[2]
+            return x_form, y_form
+
+        def lz_format(x, y, fac):
+            x_c = x * fac
+            y_c = y * fac
+
+            x_form = "{:.{dec}f}".format(x_c, dec=fract).replace('.', '')
+            y_form = "{:.{dec}f}".format(y_c, dec=fract).replace('.', '')
+
+            # pad with rear zeros
+            x_form.ljust(length, '0')
+            y_form.ljust(length, '0')
+
+            return x_form, y_form
+
+        # Gerber code is stored here
+        gerber_code = ''
+
+        # apertures processing
+        try:
+            length = whole + fract
+            if '0' in self.apertures:
+                if 'geometry' in self.apertures['0']:
+                    for geo_elem in self.apertures['0']['geometry']:
+                        if 'solid' in geo_elem:
+                            geo = geo_elem['solid']
+                            if not geo.is_empty:
+                                gerber_code += 'G36*\n'
+                                geo_coords = list(geo.exterior.coords)
+                                # first command is a move with pen-up D02 at the beginning of the geo
+                                if g_zeros == 'T':
+                                    x_formatted, y_formatted = tz_format(geo_coords[0][0], geo_coords[0][1], factor)
+                                    gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
+                                                                                   yform=y_formatted)
+                                else:
+                                    x_formatted, y_formatted = lz_format(geo_coords[0][0], geo_coords[0][1], factor)
+                                    gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
+                                                                                   yform=y_formatted)
+                                for coord in geo_coords[1:]:
+                                    if g_zeros == 'T':
+                                        x_formatted, y_formatted = tz_format(coord[0], coord[1], factor)
+                                        gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
+                                                                                       yform=y_formatted)
+                                    else:
+                                        x_formatted, y_formatted = lz_format(coord[0], coord[1], factor)
+                                        gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
+                                                                                       yform=y_formatted)
+                                gerber_code += 'D02*\n'
+                                gerber_code += 'G37*\n'
+
+                                clear_list = list(geo.interiors)
+                                if clear_list:
+                                    gerber_code += '%LPC*%\n'
+                                    for clear_geo in clear_list:
+                                        gerber_code += 'G36*\n'
+                                        geo_coords = list(clear_geo.coords)
+
+                                        # first command is a move with pen-up D02 at the beginning of the geo
+                                        if g_zeros == 'T':
+                                            x_formatted, y_formatted = tz_format(
+                                                geo_coords[0][0], geo_coords[0][1], factor)
+                                            gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
+                                                                                           yform=y_formatted)
+                                        else:
+                                            x_formatted, y_formatted = lz_format(
+                                                geo_coords[0][0], geo_coords[0][1], factor)
+                                            gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
+                                                                                           yform=y_formatted)
+
+                                        prev_coord = geo_coords[0]
+                                        for coord in geo_coords[1:]:
+                                            if coord != prev_coord:
+                                                if g_zeros == 'T':
+                                                    x_formatted, y_formatted = tz_format(coord[0], coord[1], factor)
+                                                    gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
+                                                                                                   yform=y_formatted)
+                                                else:
+                                                    x_formatted, y_formatted = lz_format(coord[0], coord[1], factor)
+                                                    gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
+                                                                                                   yform=y_formatted)
+                                            prev_coord = coord
+
+                                        gerber_code += 'D02*\n'
+                                        gerber_code += 'G37*\n'
+                                    gerber_code += '%LPD*%\n'
+                        if 'clear' in geo_elem:
+                            geo = geo_elem['clear']
+                            if not geo.is_empty:
+                                gerber_code += '%LPC*%\n'
+                                gerber_code += 'G36*\n'
+                                geo_coords = list(geo.exterior.coords)
+                                # first command is a move with pen-up D02 at the beginning of the geo
+                                if g_zeros == 'T':
+                                    x_formatted, y_formatted = tz_format(geo_coords[0][0], geo_coords[0][1], factor)
+                                    gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
+                                                                                   yform=y_formatted)
+                                else:
+                                    x_formatted, y_formatted = lz_format(geo_coords[0][0], geo_coords[0][1], factor)
+                                    gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
+                                                                                   yform=y_formatted)
+
+                                prev_coord = geo_coords[0]
+                                for coord in geo_coords[1:]:
+                                    if coord != prev_coord:
+                                        if g_zeros == 'T':
+                                            x_formatted, y_formatted = tz_format(coord[0], coord[1], factor)
+                                            gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
+                                                                                           yform=y_formatted)
+                                        else:
+                                            x_formatted, y_formatted = lz_format(coord[0], coord[1], factor)
+                                            gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
+                                                                                           yform=y_formatted)
+                                    prev_coord = coord
+
+                                gerber_code += 'D02*\n'
+                                gerber_code += 'G37*\n'
+                                gerber_code += '%LPD*%\n'
+        except Exception as e:
+            log.debug("FlatCAMObj.GerberObject.export_gerber() '0' aperture --> %s" % str(e))
+
+        for apid in self.apertures:
+            if apid == '0':
+                continue
+            else:
+                gerber_code += 'D%s*\n' % str(apid)
+                if 'geometry' in self.apertures[apid]:
+                    for geo_elem in self.apertures[apid]['geometry']:
+                        try:
+                            if 'follow' in geo_elem:
+                                geo = geo_elem['follow']
+                                if not geo.is_empty:
+                                    if isinstance(geo, Point):
+                                        if g_zeros == 'T':
+                                            x_formatted, y_formatted = tz_format(geo.x, geo.y, factor)
+                                            gerber_code += "X{xform}Y{yform}D03*\n".format(xform=x_formatted,
+                                                                                           yform=y_formatted)
+                                        else:
+                                            x_formatted, y_formatted = lz_format(geo.x, geo.y, factor)
+                                            gerber_code += "X{xform}Y{yform}D03*\n".format(xform=x_formatted,
+                                                                                           yform=y_formatted)
+                                    else:
+                                        geo_coords = list(geo.coords)
+                                        # first command is a move with pen-up D02 at the beginning of the geo
+                                        if g_zeros == 'T':
+                                            x_formatted, y_formatted = tz_format(
+                                                geo_coords[0][0], geo_coords[0][1], factor)
+                                            gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
+                                                                                           yform=y_formatted)
+                                        else:
+                                            x_formatted, y_formatted = lz_format(
+                                                geo_coords[0][0], geo_coords[0][1], factor)
+                                            gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
+                                                                                           yform=y_formatted)
+
+                                        prev_coord = geo_coords[0]
+                                        for coord in geo_coords[1:]:
+                                            if coord != prev_coord:
+                                                if g_zeros == 'T':
+                                                    x_formatted, y_formatted = tz_format(coord[0], coord[1], factor)
+                                                    gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
+                                                                                                   yform=y_formatted)
+                                                else:
+                                                    x_formatted, y_formatted = lz_format(coord[0], coord[1], factor)
+                                                    gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
+                                                                                                   yform=y_formatted)
+                                            prev_coord = coord
+
+                                        # gerber_code += "D02*\n"
+                        except Exception as e:
+                            log.debug("FlatCAMObj.GerberObject.export_gerber() 'follow' --> %s" % str(e))
+
+                        try:
+                            if 'clear' in geo_elem:
+                                gerber_code += '%LPC*%\n'
+
+                                geo = geo_elem['clear']
+                                if not geo.is_empty:
+                                    if isinstance(geo, Point):
+                                        if g_zeros == 'T':
+                                            x_formatted, y_formatted = tz_format(geo.x, geo.y, factor)
+                                            gerber_code += "X{xform}Y{yform}D03*\n".format(xform=x_formatted,
+                                                                                           yform=y_formatted)
+                                        else:
+                                            x_formatted, y_formatted = lz_format(geo.x, geo.y, factor)
+                                            gerber_code += "X{xform}Y{yform}D03*\n".format(xform=x_formatted,
+                                                                                           yform=y_formatted)
+                                    elif isinstance(geo, Polygon):
+                                        geo_coords = list(geo.exterior.coords)
+                                        # first command is a move with pen-up D02 at the beginning of the geo
+                                        if g_zeros == 'T':
+                                            x_formatted, y_formatted = tz_format(
+                                                geo_coords[0][0], geo_coords[0][1], factor)
+                                            gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
+                                                                                           yform=y_formatted)
+                                        else:
+                                            x_formatted, y_formatted = lz_format(
+                                                geo_coords[0][0], geo_coords[0][1], factor)
+                                            gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
+                                                                                           yform=y_formatted)
+
+                                        prev_coord = geo_coords[0]
+                                        for coord in geo_coords[1:]:
+                                            if coord != prev_coord:
+                                                if g_zeros == 'T':
+                                                    x_formatted, y_formatted = tz_format(coord[0], coord[1], factor)
+                                                    gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
+                                                                                                   yform=y_formatted)
+                                                else:
+                                                    x_formatted, y_formatted = lz_format(coord[0], coord[1], factor)
+                                                    gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
+                                                                                                   yform=y_formatted)
+
+                                            prev_coord = coord
+
+                                        for geo_int in geo.interiors:
+                                            geo_coords = list(geo_int.coords)
+                                            # first command is a move with pen-up D02 at the beginning of the geo
+                                            if g_zeros == 'T':
+                                                x_formatted, y_formatted = tz_format(
+                                                    geo_coords[0][0], geo_coords[0][1], factor)
+                                                gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
+                                                                                               yform=y_formatted)
+                                            else:
+                                                x_formatted, y_formatted = lz_format(
+                                                    geo_coords[0][0], geo_coords[0][1], factor)
+                                                gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
+                                                                                               yform=y_formatted)
+
+                                            prev_coord = geo_coords[0]
+                                            for coord in geo_coords[1:]:
+                                                if coord != prev_coord:
+                                                    if g_zeros == 'T':
+                                                        x_formatted, y_formatted = tz_format(coord[0], coord[1], factor)
+                                                        gerber_code += "X{xform}Y{yform}D01*\n".format(
+                                                            xform=x_formatted,
+                                                            yform=y_formatted)
+                                                    else:
+                                                        x_formatted, y_formatted = lz_format(coord[0], coord[1], factor)
+                                                        gerber_code += "X{xform}Y{yform}D01*\n".format(
+                                                            xform=x_formatted,
+                                                            yform=y_formatted)
+
+                                                prev_coord = coord
+                                    else:
+                                        geo_coords = list(geo.coords)
+                                        # first command is a move with pen-up D02 at the beginning of the geo
+                                        if g_zeros == 'T':
+                                            x_formatted, y_formatted = tz_format(
+                                                geo_coords[0][0], geo_coords[0][1], factor)
+                                            gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
+                                                                                           yform=y_formatted)
+                                        else:
+                                            x_formatted, y_formatted = lz_format(
+                                                geo_coords[0][0], geo_coords[0][1], factor)
+                                            gerber_code += "X{xform}Y{yform}D02*\n".format(xform=x_formatted,
+                                                                                           yform=y_formatted)
+
+                                        prev_coord = geo_coords[0]
+                                        for coord in geo_coords[1:]:
+                                            if coord != prev_coord:
+                                                if g_zeros == 'T':
+                                                    x_formatted, y_formatted = tz_format(coord[0], coord[1], factor)
+                                                    gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
+                                                                                                   yform=y_formatted)
+                                                else:
+                                                    x_formatted, y_formatted = lz_format(coord[0], coord[1], factor)
+                                                    gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
+                                                                                                   yform=y_formatted)
+
+                                            prev_coord = coord
+                                        # gerber_code += "D02*\n"
+                                    gerber_code += '%LPD*%\n'
+                        except Exception as e:
+                            log.debug("FlatCAMObj.GerberObject.export_gerber() 'clear' --> %s" % str(e))
+
+        if not self.apertures:
+            log.debug("FlatCAMObj.GerberObject.export_gerber() --> Gerber Object is empty: no apertures.")
+            return 'fail'
+
+        return gerber_code
+
+    def mirror(self, axis, point):
+        Gerber.mirror(self, axis=axis, point=point)
+        self.replotApertures.emit()
+
+    def offset(self, vect):
+        Gerber.offset(self, vect=vect)
+        self.replotApertures.emit()
+
+    def rotate(self, angle, point):
+        Gerber.rotate(self, angle=angle, point=point)
+        self.replotApertures.emit()
+
+    def scale(self, xfactor, yfactor=None, point=None):
+        Gerber.scale(self, xfactor=xfactor, yfactor=yfactor, point=point)
+        self.replotApertures.emit()
+
+    def skew(self, angle_x, angle_y, point):
+        Gerber.skew(self, angle_x=angle_x, angle_y=angle_y, point=point)
+        self.replotApertures.emit()
+
+    def buffer(self, distance, join, factor=None):
+        Gerber.buffer(self, distance=distance, join=join, factor=factor)
+        self.replotApertures.emit()
+
+    def serialize(self):
+        return {
+            "options": self.options,
+            "kind": self.kind
+        }

+ 505 - 0
flatcamObjects/FlatCAMObj.py

@@ -0,0 +1,505 @@
+# ##########################################################
+# FlatCAM: 2D Post-processing for Manufacturing            #
+# http://flatcam.org                                       #
+# Author: Juan Pablo Caram (c)                             #
+# Date: 2/5/2014                                           #
+# MIT Licence                                              #
+# ##########################################################
+
+# ##########################################################
+# File modified by: Marius Stanciu                         #
+# ##########################################################
+
+import inspect  # TODO: For debugging only.
+
+from flatcamGUI.ObjectUI import *
+
+from FlatCAMCommon import LoudDict
+from flatcamGUI.PlotCanvasLegacy import ShapeCollectionLegacy
+
+import sys
+
+import gettext
+import FlatCAMTranslation as fcTranslate
+import builtins
+
+fcTranslate.apply_language('strings')
+if '_' not in builtins.__dict__:
+    _ = gettext.gettext
+
+
+# Interrupts plotting process if FlatCAMObj has been deleted
+class ObjectDeleted(Exception):
+    pass
+
+
+class ValidationError(Exception):
+    def __init__(self, message, errors):
+        super().__init__(message)
+
+        self.errors = errors
+
+
+class FlatCAMObj(QtCore.QObject):
+    """
+    Base type of objects handled in FlatCAM. These become interactive
+    in the GUI, can be plotted, and their options can be modified
+    by the user in their respective forms.
+    """
+
+    # Instance of the application to which these are related.
+    # The app should set this value.
+    app = None
+
+    # signal to plot a single object
+    plot_single_object = QtCore.pyqtSignal()
+
+    def __init__(self, name):
+        """
+        Constructor.
+
+        :param name: Name of the object given by the user.
+        :return: FlatCAMObj
+        """
+
+        QtCore.QObject.__init__(self)
+
+        # View
+        self.ui = None
+
+        self.options = LoudDict(name=name)
+        self.options.set_change_callback(self.on_options_change)
+
+        self.form_fields = {}
+
+        # store here the default data for Geometry Data
+        self.default_data = {}
+
+        # 2D mode
+        # Axes must exist and be attached to canvas.
+        self.axes = None
+        self.kind = None  # Override with proper name
+
+        if self.app.is_legacy is False:
+            self.shapes = self.app.plotcanvas.new_shape_group()
+            # self.shapes = ShapeCollection(parent=self.app.plotcanvas.view.scene, pool=self.app.pool, layers=2)
+        else:
+            self.shapes = ShapeCollectionLegacy(obj=self, app=self.app, name=name)
+
+        self.mark_shapes = {}
+
+        self.item = None  # Link with project view item
+
+        self.muted_ui = False
+        self.deleted = False
+
+        try:
+            self._drawing_tolerance = float(self.app.defaults["global_tolerance"]) if \
+                self.app.defaults["global_tolerance"] else 0.01
+        except ValueError:
+            self._drawing_tolerance = 0.01
+
+        self.isHovering = False
+        self.notHovering = True
+
+        # Flag to show if a selection shape is drawn
+        self.selection_shape_drawn = False
+
+        # self.units = 'IN'
+        self.units = self.app.defaults['units']
+
+        self.plot_single_object.connect(self.single_object_plot)
+
+    def __del__(self):
+        pass
+
+    def __str__(self):
+        return "<FlatCAMObj({:12s}): {:20s}>".format(self.kind, self.options["name"])
+
+    def from_dict(self, d):
+        """
+        This supersedes ``from_dict`` in derived classes. Derived classes
+        must inherit from FlatCAMObj first, then from derivatives of Geometry.
+
+        ``self.options`` is only updated, not overwritten. This ensures that
+        options set by the app do not vanish when reading the objects
+        from a project file.
+
+        :param d: Dictionary with attributes to set.
+        :return: None
+        """
+
+        for attr in self.ser_attrs:
+
+            if attr == 'options':
+                self.options.update(d[attr])
+            else:
+                try:
+                    setattr(self, attr, d[attr])
+                except KeyError:
+                    log.debug("FlatCAMObj.from_dict() --> KeyError: %s. "
+                              "Means that we are loading an old project that don't"
+                              "have all attributes in the latest FlatCAM." % str(attr))
+                    pass
+
+    def on_options_change(self, key):
+        # Update form on programmatically options change
+        self.set_form_item(key)
+
+        # Set object visibility
+        if key == 'plot':
+            self.visible = self.options['plot']
+
+        self.optionChanged.emit(key)
+
+    def set_ui(self, ui):
+        self.ui = ui
+
+        self.form_fields = {"name": self.ui.name_entry}
+
+        assert isinstance(self.ui, ObjectUI)
+        self.ui.name_entry.returnPressed.connect(self.on_name_activate)
+
+        try:
+            # it will raise an exception for those FlatCAM objects that do not build UI with the common elements
+            self.ui.offset_button.clicked.connect(self.on_offset_button_click)
+        except (TypeError, AttributeError):
+            pass
+
+        try:
+            self.ui.scale_button.clicked.connect(self.on_scale_button_click)
+        except (TypeError, AttributeError):
+            pass
+
+        try:
+            self.ui.offsetvector_entry.returnPressed.connect(self.on_offset_button_click)
+        except (TypeError, AttributeError):
+            pass
+
+        # Creates problems on focusOut
+        try:
+            self.ui.scale_entry.returnPressed.connect(self.on_scale_button_click)
+        except (TypeError, AttributeError):
+            pass
+
+        # self.ui.skew_button.clicked.connect(self.on_skew_button_click)
+
+    def build_ui(self):
+        """
+        Sets up the UI/form for this object. Show the UI
+        in the App.
+
+        :return: None
+        :rtype: None
+        """
+
+        self.muted_ui = True
+        log.debug(str(inspect.stack()[1][3]) + "--> FlatCAMObj.build_ui()")
+
+        try:
+            # HACK: disconnect the scale entry signal since on focus out event will trigger an undesired scale()
+            # it seems that the takewidget() does generate a focus out event for the QDoubleSpinbox ...
+            # and reconnect after the takeWidget() is done
+            # self.ui.scale_entry.returnPressed.disconnect(self.on_scale_button_click)
+            self.app.ui.selected_scroll_area.takeWidget()
+            # self.ui.scale_entry.returnPressed.connect(self.on_scale_button_click)
+        except Exception as e:
+            self.app.log.debug("FlatCAMObj.build_ui() --> Nothing to remove: %s" % str(e))
+
+        self.app.ui.selected_scroll_area.setWidget(self.ui)
+        # self.ui.setMinimumWidth(100)
+        # self.ui.setMaximumWidth(self.app.ui.selected_tab.sizeHint().width())
+
+        self.muted_ui = False
+
+    def on_name_activate(self, silent=None):
+        old_name = copy(self.options["name"])
+        new_name = self.ui.name_entry.get_value()
+
+        if new_name != old_name:
+            # update the SHELL auto-completer model data
+            try:
+                self.app.myKeywords.remove(old_name)
+                self.app.myKeywords.append(new_name)
+                self.app.shell._edit.set_model_data(self.app.myKeywords)
+                self.app.ui.code_editor.set_model_data(self.app.myKeywords)
+            except Exception:
+                log.debug("on_name_activate() --> Could not remove the old object name from auto-completer model list")
+
+            self.options["name"] = self.ui.name_entry.get_value()
+            self.default_data["name"] = self.ui.name_entry.get_value()
+            self.app.collection.update_view()
+            if silent:
+                self.app.inform.emit('[success] %s: %s %s: %s' % (
+                    _("Name changed from"), str(old_name), _("to"), str(new_name)
+                )
+                                     )
+
+    def on_offset_button_click(self):
+        self.app.report_usage("obj_on_offset_button")
+
+        self.read_form()
+        vector_val = self.ui.offsetvector_entry.get_value()
+
+        def worker_task():
+            with self.app.proc_container.new(_("Offsetting...")):
+                self.offset(vector_val)
+            self.app.proc_container.update_view_text('')
+            with self.app.proc_container.new('%s...' % _("Plotting")):
+                self.plot()
+            self.app.object_changed.emit(self)
+
+        self.app.worker_task.emit({'fcn': worker_task, 'params': []})
+
+    def on_scale_button_click(self):
+        self.read_form()
+        try:
+            factor = float(eval(self.ui.scale_entry.get_value()))
+        except Exception as e:
+            self.app.inform.emit('[ERROR_NOTCL] %s' % _("Scaling could not be executed."))
+            log.debug("FlatCAMObj.on_scale_button_click() -- %s" % str(e))
+            return
+
+        if type(factor) != float:
+            self.app.inform.emit('[ERROR_NOTCL] %s' % _("Scaling could not be executed."))
+
+        # if factor is 1.0 do nothing, there is no point in scaling with a factor of 1.0
+        if factor == 1.0:
+            self.app.inform.emit('[success] %s' % _("Scale done."))
+            return
+
+        log.debug("FlatCAMObj.on_scale_button_click()")
+
+        def worker_task():
+            with self.app.proc_container.new(_("Scaling...")):
+                self.scale(factor)
+                self.app.inform.emit('[success] %s' % _("Scale done."))
+
+            self.app.proc_container.update_view_text('')
+            with self.app.proc_container.new('%s...' % _("Plotting")):
+                self.plot()
+            self.app.object_changed.emit(self)
+
+        self.app.worker_task.emit({'fcn': worker_task, 'params': []})
+
+    def on_skew_button_click(self):
+        self.app.report_usage("obj_on_skew_button")
+        self.read_form()
+        x_angle = self.ui.xangle_entry.get_value()
+        y_angle = self.ui.yangle_entry.get_value()
+
+        def worker_task():
+            with self.app.proc_container.new(_("Skewing...")):
+                self.skew(x_angle, y_angle)
+            self.app.proc_container.update_view_text('')
+            with self.app.proc_container.new('%s...' % _("Plotting")):
+                self.plot()
+            self.app.object_changed.emit(self)
+
+        self.app.worker_task.emit({'fcn': worker_task, 'params': []})
+
+    def to_form(self):
+        """
+        Copies options to the UI form.
+
+        :return: None
+        """
+        log.debug(str(inspect.stack()[1][3]) + " --> FlatCAMObj.to_form()")
+        for option in self.options:
+            try:
+                self.set_form_item(option)
+            except Exception:
+                self.app.log.warning("Unexpected error:", sys.exc_info())
+
+    def read_form(self):
+        """
+        Reads form into ``self.options``.
+
+        :return: None
+        :rtype: None
+        """
+        log.debug(str(inspect.stack()[1][3]) + "--> FlatCAMObj.read_form()")
+        for option in self.options:
+            try:
+                self.read_form_item(option)
+            except Exception:
+                self.app.log.warning("Unexpected error:", sys.exc_info())
+
+    def set_form_item(self, option):
+        """
+        Copies the specified option to the UI form.
+
+        :param option: Name of the option (Key in ``self.options``).
+        :type option: str
+        :return: None
+        """
+
+        try:
+            self.form_fields[option].set_value(self.options[option])
+        except KeyError:
+            # self.app.log.warn("Tried to set an option or field that does not exist: %s" % option)
+            pass
+
+    def read_form_item(self, option):
+        """
+        Reads the specified option from the UI form into ``self.options``.
+
+        :param option: Name of the option.
+        :type option: str
+        :return: None
+        """
+        try:
+            self.options[option] = self.form_fields[option].get_value()
+        except KeyError:
+            pass
+            # self.app.log.warning("Failed to read option from field: %s" % option)
+
+    def plot(self, kind=None):
+        """
+        Plot this object (Extend this method to implement the actual plotting).
+        Call this in descendants before doing the plotting.
+
+        :param kind:    Used by only some of the FlatCAM objects
+        :return:        Whether to continue plotting or not depending on the "plot" option. Boolean
+        """
+        log.debug(str(inspect.stack()[1][3]) + " --> FlatCAMObj.plot()")
+
+        if self.deleted:
+            return False
+
+        self.clear()
+        return True
+
+    def single_object_plot(self):
+        def plot_task():
+            with self.app.proc_container.new('%s...' % _("Plotting")):
+                self.plot()
+            self.app.object_changed.emit(self)
+
+        self.app.worker_task.emit({'fcn': plot_task, 'params': []})
+
+    def serialize(self):
+        """
+        Returns a representation of the object as a dictionary so
+        it can be later exported as JSON. Override this method.
+
+        :return: Dictionary representing the object
+        :rtype: dict
+        """
+        return
+
+    def deserialize(self, obj_dict):
+        """
+        Re-builds an object from its serialized version.
+
+        :param obj_dict: Dictionary representing a FlatCAMObj
+        :type obj_dict: dict
+        :return: None
+        """
+        return
+
+    def add_shape(self, **kwargs):
+        if self.deleted:
+            raise ObjectDeleted()
+        else:
+            key = self.shapes.add(tolerance=self.drawing_tolerance, **kwargs)
+        return key
+
+    def add_mark_shape(self, apid, **kwargs):
+        if self.deleted:
+            raise ObjectDeleted()
+        else:
+            key = self.mark_shapes[apid].add(tolerance=self.drawing_tolerance, layer=0, **kwargs)
+        return key
+
+    def update_filters(self, last_ext, filter_string):
+        """
+        Will modify the filter string that is used when saving a file (a list of file extensions) to have the last
+        used file extension as the first one in the special string
+
+        :param last_ext:        The file extension that was last used to save a file
+        :param filter_string:   A key in self.app.defaults that holds a string with the filter from QFileDialog
+        used when saving a file
+        :return:                None
+        """
+
+        filters = copy(self.app.defaults[filter_string])
+        filter_list = filters.split(';;')
+        filter_list_enum_1 = enumerate(filter_list)
+
+        # search for the last element in the filters which should always be "All Files (*.*)"
+        last_elem = ''
+        for elem in list(filter_list_enum_1):
+            if '(*.*)' in elem[1]:
+                last_elem = filter_list.pop(elem[0])
+
+        filter_list_enum = enumerate(filter_list)
+        for elem in list(filter_list_enum):
+            if '.' + last_ext in elem[1]:
+                used_ext = filter_list.pop(elem[0])
+
+                # sort the extensions back
+                filter_list.sort(key=lambda x: x.rpartition('.')[2])
+
+                # add as a first element the last used extension
+                filter_list.insert(0, used_ext)
+                # add back the element that should always be the last (All Files)
+                filter_list.append(last_elem)
+
+                self.app.defaults[filter_string] = ';;'.join(filter_list)
+                return
+
+    @staticmethod
+    def poly2rings(poly):
+        return [poly.exterior] + [interior for interior in poly.interiors]
+
+    @property
+    def visible(self):
+        return self.shapes.visible
+
+    @visible.setter
+    def visible(self, value, threaded=True):
+        log.debug("FlatCAMObj.visible()")
+
+        def worker_task(app_obj):
+            self.shapes.visible = value
+
+            if self.app.is_legacy is False:
+                # Not all object types has annotations
+                try:
+                    self.annotation.visible = value
+                except Exception:
+                    pass
+
+        if threaded is False:
+            worker_task(app_obj=self.app)
+        else:
+            self.app.worker_task.emit({'fcn': worker_task, 'params': [self]})
+
+    @property
+    def drawing_tolerance(self):
+        self.units = self.app.defaults['units'].upper()
+        tol = self._drawing_tolerance if self.units == 'MM' or not self.units else self._drawing_tolerance / 25.4
+        return tol
+
+    @drawing_tolerance.setter
+    def drawing_tolerance(self, value):
+        self.units = self.app.defaults['units'].upper()
+        self._drawing_tolerance = value if self.units == 'MM' or not self.units else value / 25.4
+
+    def clear(self, update=False):
+        self.shapes.clear(update)
+
+        # Not all object types has annotations
+        try:
+            self.annotation.clear(update)
+        except AttributeError:
+            pass
+
+    def delete(self):
+        # Free resources
+        del self.ui
+        del self.options
+
+        # Set flag
+        self.deleted = True

+ 231 - 0
flatcamObjects/FlatCAMScript.py

@@ -0,0 +1,231 @@
+# ##########################################################
+# FlatCAM: 2D Post-processing for Manufacturing            #
+# http://flatcam.org                                       #
+# Author: Juan Pablo Caram (c)                             #
+# Date: 2/5/2014                                           #
+# MIT Licence                                              #
+# ##########################################################
+
+# ##########################################################
+# File modified by: Marius Stanciu                         #
+# ##########################################################
+
+from flatcamEditors.FlatCAMTextEditor import TextEditor
+from flatcamObjects.FlatCAMObj import *
+from flatcamGUI.ObjectUI import *
+
+import tkinter as tk
+import sys
+from copy import deepcopy
+
+import gettext
+import FlatCAMTranslation as fcTranslate
+import builtins
+
+fcTranslate.apply_language('strings')
+if '_' not in builtins.__dict__:
+    _ = gettext.gettext
+
+
+class ScriptObject(FlatCAMObj):
+    """
+    Represents a TCL script object.
+    """
+    optionChanged = QtCore.pyqtSignal(str)
+    ui_type = ScriptObjectUI
+
+    def __init__(self, name):
+        self.decimals = self.app.decimals
+
+        log.debug("Creating a ScriptObject object...")
+        FlatCAMObj.__init__(self, name)
+
+        self.kind = "script"
+
+        self.options.update({
+            "plot": True,
+            "type": 'Script',
+            "source_file": '',
+        })
+
+        self.units = ''
+
+        self.ser_attrs = ['options', 'kind', 'source_file']
+        self.source_file = ''
+        self.script_code = ''
+
+        self.units_found = self.app.defaults['units']
+
+        # self.script_editor_tab = TextEditor(app=self.app, plain_text=True)
+        self.script_editor_tab = TextEditor(app=self.app, plain_text=True)
+
+    def set_ui(self, ui):
+        """
+        Sets the Object UI in Selected Tab for the FlatCAM Script type of object.
+        :param ui:
+        :return:
+        """
+        FlatCAMObj.set_ui(self, ui)
+        log.debug("ScriptObject.set_ui()")
+
+        assert isinstance(self.ui, ScriptObjectUI), \
+            "Expected a ScriptObjectUI, got %s" % type(self.ui)
+
+        self.units = self.app.defaults['units'].upper()
+        self.units_found = self.app.defaults['units']
+
+        # Fill form fields only on object create
+        self.to_form()
+
+        # Show/Hide Advanced Options
+        if self.app.defaults["global_app_level"] == 'b':
+            self.ui.level.setText(_(
+                '<span style="color:green;"><b>Basic</b></span>'
+            ))
+        else:
+            self.ui.level.setText(_(
+                '<span style="color:red;"><b>Advanced</b></span>'
+            ))
+
+        # tab_here = False
+        # # try to not add too many times a tab that it is already installed
+        # for idx in range(self.app.ui.plot_tab_area.count()):
+        #     if self.app.ui.plot_tab_area.widget(idx).objectName() == self.options['name']:
+        #         tab_here = True
+        #         break
+        #
+        # # add the tab if it is not already added
+        # if tab_here is False:
+        #     self.app.ui.plot_tab_area.addTab(self.script_editor_tab, '%s' % _("Script Editor"))
+        #     self.script_editor_tab.setObjectName(self.options['name'])
+
+        self.app.ui.plot_tab_area.addTab(self.script_editor_tab, '%s' % _("Script Editor"))
+        self.script_editor_tab.setObjectName(self.options['name'])
+
+        # first clear previous text in text editor (if any)
+        # self.script_editor_tab.code_editor.clear()
+        # self.script_editor_tab.code_editor.setReadOnly(False)
+
+        self.ui.autocomplete_cb.set_value(self.app.defaults['script_autocompleter'])
+        self.on_autocomplete_changed(state=self.app.defaults['script_autocompleter'])
+
+        self.script_editor_tab.buttonRun.show()
+
+        # Switch plot_area to CNCJob tab
+        self.app.ui.plot_tab_area.setCurrentWidget(self.script_editor_tab)
+
+        flt = "FlatCAM Scripts (*.FlatScript);;All Files (*.*)"
+        self.script_editor_tab.buttonOpen.clicked.disconnect()
+        self.script_editor_tab.buttonOpen.clicked.connect(lambda: self.script_editor_tab.handleOpen(filt=flt))
+        self.script_editor_tab.buttonSave.clicked.disconnect()
+        self.script_editor_tab.buttonSave.clicked.connect(lambda: self.script_editor_tab.handleSaveGCode(filt=flt))
+
+        self.script_editor_tab.buttonRun.clicked.connect(self.handle_run_code)
+        self.script_editor_tab.handleTextChanged()
+
+        self.ui.autocomplete_cb.stateChanged.connect(self.on_autocomplete_changed)
+
+        self.ser_attrs = ['options', 'kind', 'source_file']
+
+        # ---------------------------------------------------- #
+        # ----------- LOAD THE TEXT SOURCE FILE -------------- #
+        # ---------------------------------------------------- #
+        self.app.proc_container.view.set_busy(_("Loading..."))
+        self.script_editor_tab.t_frame.hide()
+
+        try:
+            self.script_editor_tab.code_editor.setPlainText(self.source_file)
+            # for line in self.source_file.splitlines():
+            #     QtWidgets.QApplication.processEvents()
+            #     self.script_editor_tab.code_editor.append(line)
+        except Exception as e:
+            log.debug("ScriptObject.set_ui() --> %s" % str(e))
+
+        self.script_editor_tab.code_editor.moveCursor(QtGui.QTextCursor.End)
+        self.script_editor_tab.t_frame.show()
+
+        self.app.proc_container.view.set_idle()
+        self.build_ui()
+
+    def build_ui(self):
+        FlatCAMObj.build_ui(self)
+
+    def handle_run_code(self):
+        # trying to run a Tcl command without having the Shell open will create some warnings because the Tcl Shell
+        # tries to print on a hidden widget, therefore show the dock if hidden
+        if self.app.ui.shell_dock.isHidden():
+            self.app.ui.shell_dock.show()
+
+        self.script_code = deepcopy(self.script_editor_tab.code_editor.toPlainText())
+
+        old_line = ''
+        for tcl_command_line in self.script_code.splitlines():
+            # do not process lines starting with '#' = comment and empty lines
+            if not tcl_command_line.startswith('#') and tcl_command_line != '':
+                # id FlatCAM is run in Windows then replace all the slashes with
+                # the UNIX style slash that TCL understands
+                if sys.platform == 'win32':
+                    if "open" in tcl_command_line:
+                        tcl_command_line = tcl_command_line.replace('\\', '/')
+
+                if old_line != '':
+                    new_command = old_line + tcl_command_line + '\n'
+                else:
+                    new_command = tcl_command_line
+
+                # execute the actual Tcl command
+                try:
+                    self.app.shell.open_processing()  # Disables input box.
+
+                    result = self.app.tcl.eval(str(new_command))
+                    if result != 'None':
+                        self.app.shell.append_output(result + '\n')
+
+                    old_line = ''
+                except tk.TclError:
+                    old_line = old_line + tcl_command_line + '\n'
+                except Exception as e:
+                    log.debug("ScriptObject.handleRunCode() --> %s" % str(e))
+
+        if old_line != '':
+            # it means that the script finished with an error
+            result = self.app.tcl.eval("set errorInfo")
+            log.error("Exec command Exception: %s" % (result + '\n'))
+            self.app.shell.append_error('ERROR: ' + result + '\n')
+
+        self.app.shell.close_processing()
+
+    def on_autocomplete_changed(self, state):
+        if state:
+            self.script_editor_tab.code_editor.completer_enable = True
+        else:
+            self.script_editor_tab.code_editor.completer_enable = False
+
+    def to_dict(self):
+        """
+        Returns a representation of the object as a dictionary.
+        Attributes to include are listed in ``self.ser_attrs``.
+
+        :return: A dictionary-encoded copy of the object.
+        :rtype: dict
+        """
+        d = {}
+        for attr in self.ser_attrs:
+            d[attr] = getattr(self, attr)
+        return d
+
+    def from_dict(self, d):
+        """
+        Sets object's attributes from a dictionary.
+        Attributes to include are listed in ``self.ser_attrs``.
+        This method will look only for only and all the
+        attributes in ``self.ser_attrs``. They must all
+        be present. Use only for deserializing saved
+        objects.
+
+        :param d: Dictionary of attributes to set in the object.
+        :type d: dict
+        :return: None
+        """
+        for attr in self.ser_attrs:
+            setattr(self, attr, d[attr])

+ 0 - 0
flatcamObjects/__init__.py


+ 3 - 3
flatcamTools/ToolAlignObjects.py

@@ -382,7 +382,7 @@ class AlignObjects(FlatCAMTool):
     def check_points(self):
         if len(self.clicked_points) == 1:
             self.app.inform.emit('%s: %s. %s' % (
-                _("First Point"), _("Click on the DESTINATION point."), _(" Or right click to cancel.")))
+                _("First Point"), _("Click on the DESTINATION point."), _("Or right click to cancel.")))
             self.target_obj = self.aligner_obj
             self.reset_color()
             self.set_color()
@@ -397,14 +397,14 @@ class AlignObjects(FlatCAMTool):
                 return
             else:
                 self.app.inform.emit('%s: %s. %s' % (
-                    _("Second Point"), _("Click on the START point."), _(" Or right click to cancel.")))
+                    _("Second Point"), _("Click on the START point."), _("Or right click to cancel.")))
                 self.target_obj = self.aligned_obj
                 self.reset_color()
                 self.set_color()
 
         if len(self.clicked_points) == 3:
             self.app.inform.emit('%s: %s. %s' % (
-                _("Second Point"), _("Click on the DESTINATION point."), _(" Or right click to cancel.")))
+                _("Second Point"), _("Click on the DESTINATION point."), _("Or right click to cancel.")))
             self.target_obj = self.aligner_obj
             self.reset_color()
             self.set_color()

+ 1 - 1
flatcamTools/ToolDblSided.py

@@ -191,7 +191,7 @@ class DblSidedTool(FlatCAMTool):
         # Add a reference
         self.add_point_button = QtWidgets.QPushButton(_("Add"))
         self.add_point_button.setToolTip(
-            _("Add the coordinates in format <b>(x, y)</b> through which the mirroring axis \n "
+            _("Add the coordinates in format <b>(x, y)</b> through which the mirroring axis\n "
               "selected in 'MIRROR AXIS' pass.\n"
               "The (x, y) coordinates are captured by pressing SHIFT key\n"
               "and left mouse button click on canvas or you can enter the coordinates manually.")

+ 4 - 4
flatcamTools/ToolNCC.py

@@ -2263,7 +2263,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
         # ##########################################################################################
         def gen_clear_area(geo_obj, app_obj):
             assert geo_obj.kind == 'geometry', \
-                "Initializer expected a FlatCAMGeometry, got %s" % type(geo_obj)
+                "Initializer expected a GeometryObject, got %s" % type(geo_obj)
 
             # provide the app with a way to process the GUI events when in a blocking loop
             if not run_threaded:
@@ -2551,7 +2551,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
         # ###########################################################################################
         def gen_clear_area_rest(geo_obj, app_obj):
             assert geo_obj.kind == 'geometry', \
-                "Initializer expected a FlatCAMGeometry, got %s" % type(geo_obj)
+                "Initializer expected a GeometryObject, got %s" % type(geo_obj)
 
             log.debug("NCC Tool. Rest machining copper clearing task started.")
             app_obj.inform.emit('_(NCC Tool. Rest machining copper clearing task started.')
@@ -3045,7 +3045,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
         # ##########################################################################################
         def gen_clear_area(geo_obj, app_obj):
             assert geo_obj.kind == 'geometry', \
-                "Initializer expected a FlatCAMGeometry, got %s" % type(geo_obj)
+                "Initializer expected a GeometryObject, got %s" % type(geo_obj)
 
             # provide the app with a way to process the GUI events when in a blocking loop
             if not run_threaded:
@@ -3446,7 +3446,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
         # ###########################################################################################
         def gen_clear_area_rest(geo_obj, app_obj):
             assert geo_obj.kind == 'geometry', \
-                "Initializer expected a FlatCAMGeometry, got %s" % type(geo_obj)
+                "Initializer expected a GeometryObject, got %s" % type(geo_obj)
 
             log.debug("NCC Tool. Rest machining copper clearing task started.")
             app_obj.inform.emit('_(NCC Tool. Rest machining copper clearing task started.')

+ 3 - 3
flatcamTools/ToolPunchGerber.py

@@ -604,8 +604,8 @@ class ToolPunchGerber(FlatCAMTool):
                 if grb_obj.apertures[apid]['type'] == 'C' and self.circular_cb.get_value():
                     if punch_size >= float(grb_obj.apertures[apid]['size']):
                         self.app.inform.emit('[ERROR_NOTCL] %s' %
-                                             _(" Could not generate punched hole Gerber because the punch hole size"
-                                               "is bigger than some of the apertures in the Gerber object."))
+                                             _("Could not generate punched hole Gerber because the punch hole size"
+                                               " is bigger than some of the apertures in the Gerber object."))
                         return 'fail'
                     else:
                         for elem in grb_obj.apertures[apid]['geometry']:
@@ -617,7 +617,7 @@ class ToolPunchGerber(FlatCAMTool):
                             punch_size >= float(grb_obj.apertures[apid]['height']):
                         self.app.inform.emit('[ERROR_NOTCL] %s' %
                                              _("Could not generate punched hole Gerber because the punch hole size"
-                                               "is bigger than some of the apertures in the Gerber object."))
+                                               " is bigger than some of the apertures in the Gerber object."))
                         return 'fail'
                     elif round(float(grb_obj.apertures[apid]['width']), self.decimals) == \
                             round(float(grb_obj.apertures[apid]['height']), self.decimals) and \

+ 2 - 2
flatcamTools/ToolSolderPaste.py

@@ -1335,7 +1335,7 @@ class SolderPaste(FlatCAMTool):
         # RUNNING ON SEPARATE THREAD!
         def job_init(job_obj):
             assert job_obj.kind == 'cncjob', \
-                "Initializer expected a FlatCAMCNCjob, got %s" % type(job_obj)
+                "Initializer expected a CNCJobObject, got %s" % type(job_obj)
 
             # this turn on the FlatCAMCNCJob plot for multiple tools
             job_obj.multitool = True
@@ -1365,7 +1365,7 @@ class SolderPaste(FlatCAMTool):
                 res = job_obj.generate_gcode_from_solderpaste_geo(**tooluid_value)
 
                 if res == 'fail':
-                    log.debug("FlatCAMGeometry.mtool_gen_cncjob() --> generate_from_geometry2() failed")
+                    log.debug("GeometryObject.mtool_gen_cncjob() --> generate_from_geometry2() failed")
                     return 'fail'
                 else:
                     tool_cnc_dict['gcode'] = res

二进制
locale/de/LC_MESSAGES/strings.mo


文件差异内容过多而无法显示
+ 327 - 267
locale/de/LC_MESSAGES/strings.po


二进制
locale/en/LC_MESSAGES/strings.mo


文件差异内容过多而无法显示
+ 230 - 233
locale/en/LC_MESSAGES/strings.po


二进制
locale/es/LC_MESSAGES/strings.mo


文件差异内容过多而无法显示
+ 230 - 233
locale/es/LC_MESSAGES/strings.po


二进制
locale/fr/LC_MESSAGES/strings.mo


文件差异内容过多而无法显示
+ 229 - 232
locale/fr/LC_MESSAGES/strings.po


+ 3 - 3
locale/it/LC_MESSAGES/strings.po

@@ -507,7 +507,7 @@ msgid "Failed. Select a Geometry Object and try again."
 msgstr ""
 
 #: FlatCAMApp.py:5652 FlatCAMApp.py:5688
-msgid "Expected a FlatCAMGeometry, got"
+msgid "Expected a GeometryObject, got"
 msgstr ""
 
 #: FlatCAMApp.py:5665
@@ -1125,7 +1125,7 @@ msgid "Open TCL script cancelled."
 msgstr ""
 
 #: FlatCAMApp.py:9993
-msgid "Executing FlatCAMScript file."
+msgid "Executing ScriptObject file."
 msgstr ""
 
 #: FlatCAMApp.py:10000 FlatCAMApp.py:10003
@@ -14705,7 +14705,7 @@ msgid "Buffer done"
 msgstr ""
 
 #: tclCommands/TclCommandBbox.py:74 tclCommands/TclCommandNregions.py:73
-msgid "Expected FlatCAMGerber or FlatCAMGeometry, got"
+msgid "Expected GerberObject or GeometryObject, got"
 msgstr ""
 
 #: tclCommands/TclCommandBounds.py:64 tclCommands/TclCommandBounds.py:68

+ 7 - 7
locale/pt_BR/LC_MESSAGES/strings.po

@@ -557,7 +557,7 @@ msgid "Failed. Select a Geometry Object and try again."
 msgstr "Falha. Selecione um Objeto de Geometria e tente novamente."
 
 #: FlatCAMApp.py:5652 FlatCAMApp.py:5688
-msgid "Expected a FlatCAMGeometry, got"
+msgid "Expected a GeometryObject, got"
 msgstr "Geometria FlatCAM esperada, recebido"
 
 #: FlatCAMApp.py:5665
@@ -1211,7 +1211,7 @@ msgid "Open TCL script cancelled."
 msgstr "Abrir script TCL cancelado."
 
 #: FlatCAMApp.py:9993
-msgid "Executing FlatCAMScript file."
+msgid "Executing ScriptObject file."
 msgstr "Executando arquivo de Script FlatCAM."
 
 #: FlatCAMApp.py:10000 FlatCAMApp.py:10003
@@ -16677,8 +16677,8 @@ msgid "Buffer done"
 msgstr "Buffer concluído"
 
 #: tclCommands/TclCommandBbox.py:74 tclCommands/TclCommandNregions.py:73
-msgid "Expected FlatCAMGerber or FlatCAMGeometry, got"
-msgstr "Esperando FlatCAMGerber ou FlatCAMGeometry, recebido"
+msgid "Expected GerberObject or GeometryObject, got"
+msgstr "Esperando GerberObject ou GeometryObject, recebido"
 
 #: tclCommands/TclCommandBounds.py:64 tclCommands/TclCommandBounds.py:68
 msgid "Expected a list of objects names separated by comma. Got"
@@ -17323,8 +17323,8 @@ msgstr "Nenhum nome de geometria nos argumentos. Altere e tente novamente."
 #~ msgid "<span style=\"color:red;\"><b>%s</b></span>"
 #~ msgstr "<span style=\"color:red;\"><b>%s</b></span>"
 
-#~ msgid "FlatCAMObj.FlatCAMGeometry.mtool_gen_cncjob() -->"
-#~ msgstr "FlatCAMObj.FlatCAMGeometry.mtool_gen_cncjob() -->"
+#~ msgid "FlatCAMObj.GeometryObject.mtool_gen_cncjob() -->"
+#~ msgstr "FlatCAMObj.GeometryObject.mtool_gen_cncjob() -->"
 
 #~ msgid "FlatCAMCNNJob.on_edit_code_click() -->"
 #~ msgstr "FlatCAMCNNJob.on_edit_code_click() -->"
@@ -17580,7 +17580,7 @@ msgstr "Nenhum nome de geometria nos argumentos. Altere e tente novamente."
 #~ "flatcam/src/Beta/\">aqui.</a><BR>Área de <B>DOWNLOAD</B> <a href = "
 #~ "\"https://bitbucket.org/jpcgt/flatcam/downloads/\">aqui.</a><BR>"
 
-#~ msgid "Expected a FlatCAMGeometry, got %s"
+#~ msgid "Expected a GeometryObject, got %s"
 #~ msgstr "Geometria FlatCAM esperada, recebido %s"
 
 #~ msgid "Saved to: %s"

二进制
locale/ro/LC_MESSAGES/strings.mo


文件差异内容过多而无法显示
+ 229 - 232
locale/ro/LC_MESSAGES/strings.po


+ 10 - 10
locale/ru/LC_MESSAGES/strings.po

@@ -546,8 +546,8 @@ msgid "Failed. Select a Geometry Object and try again."
 msgstr "Неудалось. Выберите объект Geometry и попробуйте снова."
 
 #: FlatCAMApp.py:5652 FlatCAMApp.py:5688
-msgid "Expected a FlatCAMGeometry, got"
-msgstr "Ожидается FlatCAMGeometry, получено"
+msgid "Expected a GeometryObject, got"
+msgstr "Ожидается GeometryObject, получено"
 
 #: FlatCAMApp.py:5665
 msgid "A Geometry object was converted to MultiGeo type."
@@ -1189,8 +1189,8 @@ msgid "Open TCL script cancelled."
 msgstr "Открытие сценария отменено."
 
 #: FlatCAMApp.py:9993
-msgid "Executing FlatCAMScript file."
-msgstr "Выполнение файла FlatCAMScript."
+msgid "Executing ScriptObject file."
+msgstr "Выполнение файла ScriptObject."
 
 #: FlatCAMApp.py:10000 FlatCAMApp.py:10003
 msgid "Run TCL script"
@@ -16746,8 +16746,8 @@ msgid "Buffer done"
 msgstr "Буфер готов"
 
 #: tclCommands/TclCommandBbox.py:74 tclCommands/TclCommandNregions.py:73
-msgid "Expected FlatCAMGerber or FlatCAMGeometry, got"
-msgstr "Ожидался FlatCAMGerber или FlatCAMGeometry, получено"
+msgid "Expected GerberObject or GeometryObject, got"
+msgstr "Ожидался GerberObject или GeometryObject, получено"
 
 #: tclCommands/TclCommandBounds.py:64 tclCommands/TclCommandBounds.py:68
 msgid "Expected a list of objects names separated by comma. Got"
@@ -17431,8 +17431,8 @@ msgstr "Нет имени геометрии в аргументах. Укажи
 #~ msgid "<span style=\"color:red;\"><b>%s</b></span>"
 #~ msgstr "<span style=\"color:red;\"><b>%s</b></span>"
 
-#~ msgid "FlatCAMObj.FlatCAMGeometry.mtool_gen_cncjob() -->"
-#~ msgstr "FlatCAMObj.FlatCAMGeometry.mtool_gen_cncjob() -->"
+#~ msgid "FlatCAMObj.GeometryObject.mtool_gen_cncjob() -->"
+#~ msgstr "FlatCAMObj.GeometryObject.mtool_gen_cncjob() -->"
 
 #~ msgid "FlatCAMCNNJob.on_edit_code_click() -->"
 #~ msgstr "FlatCAMCNNJob.on_edit_code_click() -->"
@@ -17603,8 +17603,8 @@ msgstr "Нет имени геометрии в аргументах. Укажи
 #~ "a><BR><b>ЗАГРУЗИТЬ</B> можно <a href = \"https://bitbucket.org/jpcgt/"
 #~ "flatcam/downloads/\">отсюда.</a><BR>"
 
-#~ msgid "Expected a FlatCAMGeometry, got %s"
-#~ msgstr "Ожидается FlatCAMGeometry, получено %s"
+#~ msgid "Expected a GeometryObject, got %s"
+#~ msgstr "Ожидается GeometryObject, получено %s"
 
 #~ msgid "Saved to: %s"
 #~ msgstr "Сохранёно в: %s"

+ 3 - 3
locale_template/strings.pot

@@ -498,7 +498,7 @@ msgid "Failed. Select a Geometry Object and try again."
 msgstr ""
 
 #: FlatCAMApp.py:5765 FlatCAMApp.py:5801
-msgid "Expected a FlatCAMGeometry, got"
+msgid "Expected a GeometryObject, got"
 msgstr ""
 
 #: FlatCAMApp.py:5778
@@ -1056,7 +1056,7 @@ msgid "Open TCL script"
 msgstr ""
 
 #: FlatCAMApp.py:10373
-msgid "Executing FlatCAMScript file."
+msgid "Executing ScriptObject file."
 msgstr ""
 
 #: FlatCAMApp.py:10381 FlatCAMApp.py:10384
@@ -15065,7 +15065,7 @@ msgid "Buffer done"
 msgstr ""
 
 #: tclCommands/TclCommandBbox.py:76 tclCommands/TclCommandNregions.py:75
-msgid "Expected FlatCAMGerber or FlatCAMGeometry, got"
+msgid "Expected GerberObject or GeometryObject, got"
 msgstr ""
 
 #: tclCommands/TclCommandBounds.py:67 tclCommands/TclCommandBounds.py:71

+ 1 - 4
tclCommands/TclCommandAlignDrill.py

@@ -1,6 +1,5 @@
 import collections
 from tclCommands.TclCommand import TclCommandSignaled
-from FlatCAMObj import FlatCAMGeometry, FlatCAMGerber, FlatCAMExcellon
 
 from shapely.geometry import Point
 import shapely.affinity as affinity
@@ -89,9 +88,7 @@ class TclCommandAlignDrill(TclCommandSignaled):
         if obj is None:
             return "Object not found: %s" % name
 
-        if not isinstance(obj, FlatCAMGeometry) and \
-                not isinstance(obj, FlatCAMGerber) and \
-                not isinstance(obj, FlatCAMExcellon):
+        if obj.kind != "geometry" and obj.kind != 'gerber' and obj.kind != 'excellon':
             return "ERROR: Only Gerber, Geometry and Excellon objects can be used."
 
         # Axis

+ 2 - 3
tclCommands/TclCommandBbox.py

@@ -1,6 +1,5 @@
 import collections
 from tclCommands.TclCommand import TclCommand
-from FlatCAMObj import FlatCAMGeometry, FlatCAMGerber
 
 from shapely.ops import cascaded_union
 
@@ -73,7 +72,7 @@ class TclCommandBbox(TclCommand):
 
         if not isinstance(obj, FlatCAMGerber) and not isinstance(obj, FlatCAMGeometry):
             self.raise_tcl_error('%s %s: %s.' % (
-                _("Expected FlatCAMGerber or FlatCAMGeometry, got"), name, type(obj)))
+                _("Expected GerberObject or GeometryObject, got"), name, type(obj)))
 
         if 'margin' not in args:
             args['margin'] = float(self.app.defaults["gerber_bboxmargin"])
@@ -92,7 +91,7 @@ class TclCommandBbox(TclCommand):
 
         try:
             def geo_init(geo_obj, app_obj):
-                assert isinstance(geo_obj, FlatCAMGeometry)
+                # assert geo_obj.kind == 'geometry'
 
                 # Bounding box with rounded corners
                 geo = cascaded_union(obj.solid_geometry)

+ 2 - 3
tclCommands/TclCommandCncjob.py

@@ -1,5 +1,4 @@
 from tclCommands.TclCommand import TclCommandSignaled
-from FlatCAMObj import FlatCAMGeometry
 
 import collections
 from copy import deepcopy
@@ -119,9 +118,9 @@ class TclCommandCncjob(TclCommandSignaled):
             else:
                 return "fail"
 
-        if not isinstance(obj, FlatCAMGeometry):
+        if obj.kind != 'geometry':
             if muted is False:
-                self.raise_tcl_error('Expected FlatCAMGeometry, got %s %s.' % (str(name), type(obj)))
+                self.raise_tcl_error('Expected GeometryObject, got %s %s.' % (str(name), type(obj)))
             else:
                 return
 

+ 2 - 3
tclCommands/TclCommandDrillcncjob.py

@@ -1,5 +1,4 @@
 from tclCommands.TclCommand import TclCommandSignaled
-from FlatCAMObj import FlatCAMExcellon
 
 import collections
 import math
@@ -125,9 +124,9 @@ class TclCommandDrillcncjob(TclCommandSignaled):
             else:
                 return "fail"
 
-        if not isinstance(obj, FlatCAMExcellon):
+        if obj.kind != 'excellon':
             if muted is False:
-                self.raise_tcl_error('Expected FlatCAMExcellon, got %s %s.' % (name, type(obj)))
+                self.raise_tcl_error('Expected ExcellonObject, got %s %s.' % (name, type(obj)))
             else:
                 return "fail"
 

+ 2 - 3
tclCommands/TclCommandFollow.py

@@ -1,5 +1,4 @@
 from tclCommands.TclCommand import TclCommandSignaled
-from FlatCAMObj import FlatCAMGerber
 
 import collections
 
@@ -56,8 +55,8 @@ class TclCommandFollow(TclCommandSignaled):
         if obj is None:
             self.raise_tcl_error("Object not found: %s" % name)
 
-        if not isinstance(obj, FlatCAMGerber):
-            self.raise_tcl_error('Expected FlatCAMGerber, got %s %s.' % (name, type(obj)))
+        if obj.kind != 'gerber':
+            self.raise_tcl_error('Expected GerberObject, got %s %s.' % (name, type(obj)))
 
         del args['name']
         try:

+ 2 - 3
tclCommands/TclCommandGeoCutout.py

@@ -1,5 +1,4 @@
 from tclCommands.TclCommand import TclCommandSignaled
-from FlatCAMObj import FlatCAMGerber, FlatCAMGeometry
 
 import logging
 import collections
@@ -209,7 +208,7 @@ class TclCommandGeoCutout(TclCommandSignaled):
         except ValueError:
             gaps_u = gaps
 
-        if isinstance(cutout_obj, FlatCAMGeometry):
+        if cutout_obj.kind == 'geometry':
             # rename the obj name so it can be identified as cutout
             # cutout_obj.options["name"] += "_cutout"
 
@@ -306,7 +305,7 @@ class TclCommandGeoCutout(TclCommandSignaled):
             # cutout_obj.plot()
             # self.app.inform.emit("[success] Any-form Cutout operation finished.")
             # self.app.plots_updated.emit()
-        elif isinstance(cutout_obj, FlatCAMGerber):
+        elif cutout_obj.kind == 'gerber':
 
             def geo_init(geo_obj, app_obj):
                 try:

+ 2 - 3
tclCommands/TclCommandIsolate.py

@@ -1,5 +1,4 @@
 from tclCommands.TclCommand import TclCommandSignaled
-from FlatCAMObj import FlatCAMGerber
 
 import collections
 
@@ -96,8 +95,8 @@ class TclCommandIsolate(TclCommandSignaled):
         if obj is None:
             self.raise_tcl_error("Object not found: %s" % name)
 
-        if not isinstance(obj, FlatCAMGerber):
-            self.raise_tcl_error('Expected FlatCAMGerber, got %s %s.' % (name, type(obj)))
+        if obj.kind != 'gerber':
+            self.raise_tcl_error('Expected GerberObject, got %s %s.' % (name, type(obj)))
 
         del args['name']
         obj.isolate(plot=False, **args)

+ 2 - 2
tclCommands/TclCommandJoinExcellon.py

@@ -1,5 +1,5 @@
 from tclCommands.TclCommand import TclCommand
-from FlatCAMObj import FlatCAMExcellon
+from flatcamObjects.FlatCAMExcellon import ExcellonObject
 
 import collections
 
@@ -62,7 +62,7 @@ class TclCommandJoinExcellon(TclCommand):
                 objs.append(obj)
 
         def initialize(obj_, app):
-            FlatCAMExcellon.merge(self, objs, obj_)
+            ExcellonObject.merge(self, objs, obj_)
 
         if objs and len(objs) >= 2:
             self.app.new_object("excellon", outname, initialize, plot=False)

+ 2 - 2
tclCommands/TclCommandJoinGeometry.py

@@ -1,5 +1,5 @@
 from tclCommands.TclCommand import TclCommand
-from FlatCAMObj import FlatCAMGeometry
+from flatcamObjects.FlatCAMGeometry import GeometryObject
 
 import collections
 
@@ -62,7 +62,7 @@ class TclCommandJoinGeometry(TclCommand):
                 objs.append(obj)
 
         def initialize(obj_, app):
-            FlatCAMGeometry.merge(self, objs, obj_)
+            GeometryObject.merge(self, objs, obj_)
 
         if objs and len(objs) >= 2:
             self.app.new_object("geometry", outname, initialize, plot=False)

+ 1 - 2
tclCommands/TclCommandMillDrills.py

@@ -6,7 +6,6 @@
 # ##########################################################
 
 from tclCommands.TclCommand import TclCommandSignaled
-from FlatCAMObj import FlatCAMExcellon
 
 import math
 import collections
@@ -138,7 +137,7 @@ class TclCommandMillDrills(TclCommandSignaled):
         except Exception as e:
             self.raise_tcl_error("Bad tools: %s" % str(e))
 
-        if not isinstance(obj, FlatCAMExcellon):
+        if obj.kind != 'excellon':
             self.raise_tcl_error('Only Excellon objects can be mill-drilled, got %s %s.' % (name, type(obj)))
 
         if self.app.collection.has_promises():

+ 1 - 2
tclCommands/TclCommandMillSlots.py

@@ -6,7 +6,6 @@
 # ##########################################################
 
 from tclCommands.TclCommand import TclCommandSignaled
-from FlatCAMObj import FlatCAMExcellon
 
 import collections
 import math
@@ -139,7 +138,7 @@ class TclCommandMillSlots(TclCommandSignaled):
         except Exception as e:
             self.raise_tcl_error("Bad tools: %s" % str(e))
 
-        if not isinstance(obj, FlatCAMExcellon):
+        if obj.kind != 'excellon':
             self.raise_tcl_error('Only Excellon objects can have mill-slots, got %s %s.' % (name, type(obj)))
 
         if self.app.collection.has_promises():

+ 1 - 4
tclCommands/TclCommandMirror.py

@@ -1,5 +1,4 @@
 from tclCommands.TclCommand import TclCommandSignaled
-from FlatCAMObj import FlatCAMExcellon, FlatCAMGeometry, FlatCAMGerber
 
 import collections
 
@@ -68,9 +67,7 @@ class TclCommandMirror(TclCommandSignaled):
         if obj is None:
             return "Object not found: %s" % name
 
-        if not isinstance(obj, FlatCAMGerber) and \
-                not isinstance(obj, FlatCAMExcellon) and \
-                not isinstance(obj, FlatCAMGeometry):
+        if obj.kind != 'gerber' and obj.kind != 'geometry' and obj.kind != 'excellon':
             return "ERROR: Only Gerber, Excellon and Geometry objects can be mirrored."
 
         # Axis

+ 3 - 4
tclCommands/TclCommandNregions.py

@@ -1,5 +1,4 @@
 from tclCommands.TclCommand import TclCommand
-from FlatCAMObj import FlatCAMGeometry, FlatCAMGerber
 
 from shapely.ops import cascaded_union
 
@@ -71,8 +70,8 @@ class TclCommandNregions(TclCommand):
         if obj is None:
             self.raise_tcl_error("%s: %s" % (_("Object not found"), name))
 
-        if not isinstance(obj, FlatCAMGerber) and not isinstance(obj, FlatCAMGeometry):
-            self.raise_tcl_error('%s %s: %s.' % (_("Expected FlatCAMGerber or FlatCAMGeometry, got"), name, type(obj)))
+        if obj.kind != 'gerber' and obj.kind != 'geometry':
+            self.raise_tcl_error('%s %s: %s.' % (_("Expected GerberObject or GeometryObject, got"), name, type(obj)))
 
         if 'margin' not in args:
             args['margin'] = float(self.app.defaults["gerber_noncoppermargin"])
@@ -91,7 +90,7 @@ class TclCommandNregions(TclCommand):
 
         try:
             def geo_init(geo_obj, app_obj):
-                assert isinstance(geo_obj, FlatCAMGeometry)
+                assert geo_obj.kind == 'geometry'
 
                 geo = cascaded_union(obj.solid_geometry)
                 bounding_box = geo.envelope.buffer(float(margin))

+ 2 - 3
tclCommands/TclCommandOpenGerber.py

@@ -1,6 +1,5 @@
 from tclCommands.TclCommand import TclCommandSignaled
 from camlib import ParseError
-from FlatCAMObj import FlatCAMGerber
 
 import collections
 
@@ -53,8 +52,8 @@ class TclCommandOpenGerber(TclCommandSignaled):
         # How the object should be initialized
         def obj_init(gerber_obj, app_obj):
 
-            if not isinstance(gerber_obj, FlatCAMGerber):
-                self.raise_tcl_error('Expected FlatCAMGerber, got %s %s.' % (outname, type(gerber_obj)))
+            if gerber_obj.kind != 'gerber':
+                self.raise_tcl_error('Expected GerberObject, got %s %s.' % (outname, type(gerber_obj)))
 
             # Opening the file happens here
             try:

+ 7 - 8
tclCommands/TclCommandPanelize.py

@@ -1,5 +1,4 @@
 from tclCommands.TclCommand import TclCommand
-from FlatCAMObj import FlatCAMGeometry, FlatCAMExcellon
 
 import shapely.affinity as affinity
 
@@ -153,12 +152,12 @@ class TclCommandPanelize(TclCommand):
         #         objs.append(obj_init)
         #
         #     def initialize_geometry(obj_init, app):
-        #         FlatCAMGeometry.merge(objs, obj_init)
+        #         GeometryObject.merge(objs, obj_init)
         #
         #     def initialize_excellon(obj_init, app):
         #         # merge expects tools to exist in the target object
         #         obj_init.tools = obj.tools.copy()
-        #         FlatCAMExcellon.merge(objs, obj_init)
+        #         ExcellonObject.merge(objs, obj_init)
         #
         #     objs = []
         #     if obj is not None:
@@ -167,7 +166,7 @@ class TclCommandPanelize(TclCommand):
         #             currentx = 0
         #             for col in range(columns):
         #                 local_outname = outname + ".tmp." + str(col) + "." + str(row)
-        #                 if isinstance(obj, FlatCAMExcellon):
+        #                 if isinstance(obj, ExcellonObject):
         #                     self.app.new_object("excellon", local_outname, initialize_local_excellon, plot=False,
         #                                         autoselected=False)
         #                 else:
@@ -177,7 +176,7 @@ class TclCommandPanelize(TclCommand):
         #                 currentx += lenghtx
         #             currenty += lenghty
         #
-        #         if isinstance(obj, FlatCAMExcellon):
+        #         if isinstance(obj, ExcellonObject):
         #             self.app.new_object("excellon", outname, initialize_excellon)
         #         else:
         #             self.app.new_object("geometry", outname, initialize_geometry)
@@ -258,7 +257,7 @@ class TclCommandPanelize(TclCommand):
 
                     obj_fin.solid_geometry = []
 
-                    if isinstance(obj, FlatCAMGeometry):
+                    if obj.kind == 'geometry':
                         obj_fin.multigeo = obj.multigeo
                         obj_fin.tools = deepcopy(obj.tools)
                         if obj.multigeo is True:
@@ -269,7 +268,7 @@ class TclCommandPanelize(TclCommand):
                         currentx = 0.0
 
                         for col in range(columns):
-                            if isinstance(obj, FlatCAMGeometry):
+                            if obj.kind == 'geometry':
                                 if obj.multigeo is True:
                                     for tool in obj.tools:
                                         obj_fin.tools[tool]['solid_geometry'].append(translate_recursion(
@@ -287,7 +286,7 @@ class TclCommandPanelize(TclCommand):
                             currentx += lenghtx
                         currenty += lenghty
 
-                if isinstance(obj, FlatCAMExcellon):
+                if obj.kind == 'excellon':
                     self.app.new_object("excellon", outname, job_init_excellon, plot=False, autoselected=True)
                 else:
                     self.app.new_object("geometry", outname, job_init_geometry, plot=False, autoselected=True)

部分文件因为文件数量过多而无法显示