Files
flatcam-wsl/flatcam.py
Marius Stanciu cb7e69ee89 Squashed commit of the following:
commit 7fda555fc0
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Wed May 24 17:46:25 2023 +0300

    - for all Editors now there is a shortcut key (key "C") that will toggle the cursor data in case the cursor data is in the way
    - Geometry Editor: the Path tool now has a new behavior: when key modifier SHIFT is pressed and the Grid is OFF, when the line is drawn and it is near the 0, 45 and 90 degrees, in each quadrant, then the drawn line will follow the nearest target angle (0 or 45 or 90 degrees) allowing the drawing of straight lines.

commit e5dd294576
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Fri May 19 18:18:38 2023 +0300

    - Film Tool: fixed the export to PNG to be done at correct DPI

commit a49f54d63f
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Fri May 19 13:09:08 2023 +0300

    - the selection shapes are now moved from Move Plugin to AppMain
    - Fiducials Plugin: fixed errors due of changes in the Shapely module
    - Fiducials Plugin: fixed an error where in Basic mode the soldermask opening is added incorrectly

commit ba3152e5f9
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Fri May 19 02:23:40 2023 +0300

    - CutOut Plugin - fixed the manual adding of gaps

commit 761b61668a
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Wed May 17 22:48:39 2023 +0300

    - Thieving Plugin: fixed errors due of changes in the Shapely module

commit dea367b185
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Tue May 16 04:34:32 2023 +0300

    - NCC Plugin: fixed the Standard method of copper clearing (both normal and with Rest machining)

commit 6719e2ef8e
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sun May 14 22:14:43 2023 +0300

    - NCC Plugin - minor code refactoring

commit 5d274dd522
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sun May 14 21:48:14 2023 +0300

    - Isolation Plugin, NCC Plugin and Find Optimal Plugin: fixed not finding the optimal tool diameter (the one that will isolate completely a Gerber object)

commit 1d68dea61c
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Fri May 5 22:31:18 2023 +0300

    - replaced some type hints with using the Union

commit 412872bc09
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Fri May 5 02:40:41 2023 +0300

    - fixed an erroneous opening for a Gerber file generated by KiCAD 6.0.11, due of a rectangular flash being eliminated by the global unary_union operation

commit 765d7cc05b
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sat Apr 15 22:15:33 2023 +0300

    - when parsing a new Gerber object, I am "preparing" each geometry added therefore making the Gerber object geometry possible faster to process

commit 6a29bcbe7c
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sat Apr 15 21:29:32 2023 +0300

    - some code leftovers are commented

commit b557df8fdc
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sat Apr 15 21:08:48 2023 +0300

    - minor fixes

commit ccc71eabc2
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sat Apr 15 21:03:30 2023 +0300

    - changed the shapely imports a bit according to the specifications of Shapely 2.0
    - changed the requirements.txt file to reflect the need for at least Shapely in version 2.0

commit 6f93734d3f
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sat Apr 8 12:43:34 2023 +0300

    - minor name changes

commit faf41d7bca
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sat Apr 8 12:29:45 2023 +0300

    - major change: from now on the only dimensional units available are those from ISO METRIC system

commit b446ded9ab
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sat Apr 8 12:10:02 2023 +0300

    - fixed some really long strings in the Geometry Editor toolbar actions
    - modified the paint and buffer icons
    - optimized the editor menu/toolbar action names

commit 72dd81848f
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Wed Mar 22 16:43:27 2023 +0200

    - in the toolbars now there is text under the icons (which can be turned off from the toolbar context menu)
    - the GUI state is now saved and restored through QSettings

commit 1dff9cc566
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Mon Mar 13 23:08:57 2023 +0200

    - in Tcl Commands: export_dxf and export_gerber, fixed a mistake in declaring a wrong name of a required option
    - in Tcl Command set_path added an optional parameter which allows to create a directory where path is to be set, if the directory does not exist

commit 3b3c87e953
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Mon Mar 6 16:40:49 2023 +0200

    - fixed some possible issues due of changes in version 2.0 of Shapely
    - removed the import * statement from most of the app

commit 33de5314b1
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Wed Mar 1 18:15:10 2023 +0200

    - in Tool Milling made sure that deleting the only tool will not crash the application
    - added a new parameter in Preferences to control the number of processes created by the Pool() - more processes better performance but also a lot of memory consumed
    - made sure that the display of messages in the Status Bar is done asap

commit 9d8852e611
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Fri Jan 20 19:23:34 2023 +0200

    - added a new method for bilinear interpolation

commit 9ce9c3cb54
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Wed Jan 18 18:22:33 2023 +0200

    - in Autolevelling Plugin, preventing the add of a probe point on Excellon hole checkbox is not disabled except for the Manual mode
    - in Autolevelling Plugin, the status of soem checkoxes (avoid Excellon holes and plot points) is stored between app restarts
    - in Isolation Plugin, added an convenience shortcut button to launch the Milling Plugin.

commit c85d04bc0a
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Wed Jan 18 01:32:28 2023 +0200

    - in Autolevelling Tool, when adding manual probe points, added an option that prevent adding a probe point within a drill hole of an Excellon object that is plotted on canvas

commit f42f05d93e
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Wed Jan 18 01:07:31 2023 +0200

    - in Autolevelling Tool made sure that when adding manual probe points mouse dragging with the right button is not counted as end of adding operation

commit 220157641d
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Tue Jan 17 01:02:52 2023 +0200

    - fixed the Voronoi generation in the Autolevelling Tool (removed the Foronoi package due of issues and now using the embedded functionality from Shapely)
    - fixed the enable of Levelling Tool only for CNCJob objects that were made from geometries that were segmented

commit 853b273e79
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Mon Jan 16 23:52:30 2023 +0200

    - fixed the Voronoi generation in the Autolevelling Tool (removed the Foronoi package due of issues and now using the embedded functionality from Shapely)

commit a1b6f78d78
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Mon Jan 16 13:28:50 2023 +0200

    - some PEP8 fixes

commit 6c5a468418
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Mon Jan 16 13:02:47 2023 +0200

    - fixed a decoding error in the Excellon parser

commit d6ebcef38d
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sun Jan 15 22:31:11 2023 +0200

    - PEP8 changes

commit 2d0ea65f1b
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sun Jan 15 15:25:20 2023 +0200

    - minor change

commit c1377d5090
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sat Nov 19 02:29:40 2022 +0200

    - added a 'return' button when a fatal error is encountered allowing the user to continue the work
    - fixed a crash in Milling Plugin when trying to mill slots that do not have drills in the same file

commit 22f4d92be7
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Wed Nov 9 20:56:39 2022 +0200

    - minor change in the requirements.txt file

commit 8b4423dc0f
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Wed Nov 9 19:55:59 2022 +0200

    - when changing the style for the decorations from Preferences, now change is applied immediately

commit 9ec2ee2920
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Tue Nov 8 15:59:59 2022 +0200

    - in Drilling Plugin fixed a situation when having tools with the same diameter will get them multiplied by the number of those tools

commit d1a4de676e
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sun Nov 6 00:43:34 2022 +0200

    - if PikePDF module is not available then show an error but run the app (currently, for Python 3.11 is the only module not available)

commit 6509089dc4
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Wed Oct 19 16:59:05 2022 +0300

    - fixed an issue when exporting huge SVG files from the Film Tool by adding a fallback and using a custom XML parser with the 'huge_tree' option set

commit 2c229d8677
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Wed Oct 19 02:35:19 2022 +0300

    - added a hack so the Gerber files from Allegro 17.2 (which do not follow the Gerber specifications) can be loaded

commit 94901686b5
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sun Oct 2 06:56:13 2022 +0300

    - really small UI change in 2-Sided Plugin

commit 56033b8bc4
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Tue Sep 27 16:45:32 2022 +0300

    - in Milling Plugin, for Excellon target, re-enabled the control over the Feedrate X-Y parameter

commit 8f774df30b
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sun Sep 25 05:57:35 2022 +0300

    - small fix in ToolCutout Plugin when trying to set a checkbox state with a float value which still works in Windows but creates issues in other OS's

commit 9b08191660
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sun Sep 25 05:44:43 2022 +0300

    - added a new setting in Preferences ("3D compatibility") controlled by a checkbox. If the checkbox is checked then multithreading is disabled for the 3D mode (lower performance but perhaps more compatibility, especially for Linux) - this was done from the research done by Matti Eiden on bitbucket

commit 565c839460
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sat Sep 10 01:50:13 2022 +0300

    - added insurance that the QThread where the ArgThread class is running, really receive the interruption request and it is finished

commit 71a3963c96
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sat Sep 10 01:06:13 2022 +0300

    - hided the main UI on application quit to create a user experience of a shutdown without lag
    - added a way to terminate QThreads safely by waiting; should be much safer
    - made sure that the ArgsThread class receive the signal to stop
    - made sure that on application shutdown, all workers will quit before the actual exit

commit 3c1349a6c4
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Thu Sep 1 13:08:06 2022 +0300

    - added a new feature for Geometry export-as-SVG, the ability to export only the paths (outlines); the new feature is controlled from a new parameter in Preferences -> Geometry -> Export

commit 6eeac5312e
Merge: 419330ee 2901afd9
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Mon Aug 1 09:29:44 2022 +0000

    Merged Beta_8.995 into gerber_editor_upgrade

commit 419330ee93
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Mon Aug 1 12:27:14 2022 +0300

    - fixed some bugs in Geometry Editor in regards of Buffer Tool
    - fixed some issues in the Cutout Plugin by adding more checks
    - fixed issues when loading files by dragging in the UI (caused by recent code refactoring)

commit 4c22e52b08
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Thu May 26 00:20:43 2022 +0300

    - upgraded the UI of Region sub-tool in the Gerber Editor

commit 95066e352b
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sun May 22 14:01:21 2022 +0300

    - in Gerber Editor upgraded the Simplification sub-tool GUI

commit 5298a59372
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sun May 22 04:37:16 2022 +0300

    - in Gerber Editor upgraded the Track sub-tool GUI

commit 830d500d04
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sun May 22 03:18:51 2022 +0300

    - in Gerber Editor upgraded the PadArray GUI

commit 9055cc1230
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sun May 22 01:40:55 2022 +0300

    - in Gerber Editor upgraded the PadAdd GUI

commit bfb3aa4118
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sat May 21 02:13:47 2022 +0300

    - added properties for the mouse position and mouse clicked position (and setters) and cleaned up the code regarding this data

commit 61325b7b5f
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Sat May 21 01:25:14 2022 +0300

    - more code refactored in the appMain.py

commit 77c752701f
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Fri May 20 21:19:52 2022 +0300

    - refactored the code for the file registration and for the keywords update into its own class to make the main class smaller
    - when creating new files the file names are added to the beginning of the keywords list for the usage of Qt auto-completer

commit 5125f475eb
Merge: c3ab0b28 037a72a5
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Fri May 20 01:51:59 2022 +0000

    Merged Beta_8.995 into gerber_editor_upgrade

commit c3ab0b28b3
Merge: 93c2ab43 c0ff26db
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Thu May 19 13:25:47 2022 +0000

    Merged Beta_8.995 into gerber_editor_upgrade

commit 93c2ab43f4
Merge: 8bdaaa50 f82d4a4b
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Wed May 18 21:00:48 2022 +0000

    Merged Beta_8.995 into gerber_editor_upgrade

commit 8bdaaa5021
Merge: 1a0dfe61 04bb0857
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Tue May 17 19:55:12 2022 +0000

    Merged Beta_8.995 into gerber_editor_upgrade

commit 1a0dfe6143
Merge: 9a057a40 b09c55da
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Tue May 17 11:39:28 2022 +0000

    Merged Beta_8.995 into gerber_editor_upgrade

commit 9a057a40c5
Merge: c1a53203 3a0247e7
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Tue May 17 09:54:28 2022 +0000

    Merged Beta_8.995 into gerber_editor_upgrade

commit c1a5320315
Author: Marius Stanciu <marius.adrian@gmail.com>
Date:   Mon May 16 18:13:12 2022 +0300

    - started to lay ground for upgrading the UI in the Gerber Editor
    - fixed and upgraded the Buffer sub-tool in the Gerber Editor
    - fixed adding same aperture multiple times
2023-05-24 18:20:51 +03:00

182 lines
6.0 KiB
Python

import sys
import os
import traceback
from datetime import datetime
from PyQt6 import QtWidgets, QtGui
from PyQt6.QtCore import QSettings, QTimer
from appMain import App
from appGUI import VisPyPatches
from appGUI.GUIElements import FCMessageBox
from multiprocessing import freeze_support
# import copyreg
# import types
MIN_VERSION_MAJOR = 3
MIN_VERSION_MINOR = 6
def debug_trace():
"""
Set a tracepoint in the Python debugger that works with Qt
:return: None
"""
from PyQt6.QtCore import pyqtRemoveInputHook
# from pdb import set_trace
pyqtRemoveInputHook()
# set_trace()
if __name__ == '__main__':
# All X11 calling should be thread safe otherwise we have strange issues
# QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_X11InitThreads)
# NOTE: Never talk to the GUI from threads! This is why I commented the above.
freeze_support()
portable = False
# Folder for user settings.
if sys.platform == 'win32':
# #######################################################################################################
# ####### CONFIG FILE WITH PARAMETERS REGARDING PORTABILITY #############################################
# #######################################################################################################
config_file = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + '\\config\\configuration.txt'
try:
with open(config_file, 'r'):
pass
except FileNotFoundError:
config_file = os.path.dirname(os.path.realpath(__file__)) + '\\config\\configuration.txt'
with open(config_file, 'r') as f:
for line in f:
param = str(line).replace('\n', '').rpartition('=')
if param[0] == 'portable':
try:
portable = eval(param[2])
except NameError:
portable = False
if portable is False:
# data_path = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, None, 0) + '\\FlatCAM'
data_path = os.path.join(os.getenv('appdata'), 'FlatCAM')
else:
data_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + '\\config'
else:
data_path = os.path.expanduser('~') + '/.FlatCAM'
if not os.path.exists(data_path):
os.makedirs(data_path)
log_file_path = os.path.join(data_path, "log.txt")
major_v = sys.version_info.major
minor_v = sys.version_info.minor
v_msg = "FlatCAM Evo uses PYTHON 3 or later. The version minimum is %s.%s\n"\
"Your Python version is: %s.%s" % (MIN_VERSION_MAJOR, MIN_VERSION_MINOR, str(major_v), str(minor_v))
# Supported Python version is >= 3.6
if major_v < MIN_VERSION_MAJOR or (major_v >= MIN_VERSION_MAJOR and minor_v < MIN_VERSION_MINOR):
print(v_msg)
msg = '%s\n' % str(datetime.today())
msg += v_msg
try:
with open(log_file_path) as f:
log_file = f.read()
log_file += '\n' + msg
with open(log_file_path, 'w') as f:
f.write(log_file)
except IOError:
with open(log_file_path, 'w') as f:
f.write(msg)
# if minor_v >= 8:
# os._exit(0)
# else:
# sys.exit(0)
sys.exit(0)
debug_trace()
VisPyPatches.apply_patches()
def excepthook(exc_type, exc_value, exc_tb):
msg = '%s\n' % str(datetime.today())
if exc_type != KeyboardInterrupt:
msg += "".join(traceback.format_exception(exc_type, exc_value, exc_tb))
try:
with open(log_file_path) as f:
log_file = f.read()
log_file += '\n' + msg
with open(log_file_path, 'w') as f:
f.write(log_file)
except IOError:
with open(log_file_path, 'w') as f:
f.write(msg)
# show the message
try:
msgbox = FCMessageBox()
displayed_msg = "The application encountered a critical error and it will close.\n"\
"Please report this error to the developers."
title = "Critical Error"
msgbox.setWindowTitle(title) # taskbar still shows it
ic = QtGui.QIcon()
ic.addPixmap(QtGui.QPixmap("assets/resources/warning.png"), QtGui.QIcon.Mode.Normal)
msgbox.setWindowIcon(ic)
msgbox.setText('<b>%s</b>' % displayed_msg)
msgbox.setDetailedText(msg)
msgbox.setIcon(QtWidgets.QMessageBox.Icon.Critical)
bt_yes = msgbox.addButton("Quit", QtWidgets.QMessageBox.ButtonRole.YesRole)
bt_ret = msgbox.addButton("Return", QtWidgets.QMessageBox.ButtonRole.NoRole)
msgbox.setDefaultButton(bt_yes)
# msgbox.setTextFormat(Qt.TextFormat.RichText)
msgbox.exec()
response = msgbox.clickedButton()
if response == bt_ret:
pass
except Exception:
QtWidgets.QApplication.quit()
else:
QtWidgets.QApplication.quit()
# or QtWidgets.QApplication.exit(0)
sys.excepthook = excepthook
app = QtWidgets.QApplication(sys.argv)
# apply style
settings = QSettings("Open Source", "FlatCAM_EVO")
if settings.contains("style"):
style_index = settings.value('style', type=str)
try:
idx = int(style_index)
except Exception:
idx = 0
style = QtWidgets.QStyleFactory.keys()[idx]
app.setStyle(style)
else:
app.setStyle('windowsvista')
fc = App(qapp=app)
# interrupt the Qt loop such that Python events have a chance to be responsive
timer = QTimer()
timer.timeout.connect(lambda: None)
timer.start(100)
try:
sys.exit(app.exec())
except SystemError:
pass
# app.exec()