GerberGenPrefGroupUI.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. from PyQt5 import QtCore, QtGui
  2. from flatcamGUI.preferences.OptionUI import *
  3. from flatcamGUI.preferences.OptionsGroupUI import OptionsGroupUI2
  4. import gettext
  5. import FlatCAMTranslation as fcTranslate
  6. import builtins
  7. fcTranslate.apply_language('strings')
  8. if '_' not in builtins.__dict__:
  9. _ = gettext.gettext
  10. class GerberGenPrefGroupUI(OptionsGroupUI2):
  11. def __init__(self, decimals=4, **kwargs):
  12. self.decimals = decimals
  13. super().__init__(**kwargs)
  14. self.setTitle(str(_("Gerber General")))
  15. self.plot_line_field = self.option_dict()["gerber_plot_line"].get_field()
  16. self.plot_fill_field = self.option_dict()["gerber_plot_fill"].get_field()
  17. self.plot_alpha_field = self.option_dict()["_gerber_plot_alpha"].get_field()
  18. self.plot_alpha_field.spinner.valueChanged.connect(self.on_plot_alpha_change)
  19. def build_options(self) -> [OptionUI]:
  20. return [
  21. HeadingOptionUI(label_text="Plot Options"),
  22. CheckboxOptionUI(
  23. option="gerber_solid",
  24. label_text="Solid",
  25. label_tooltip="Solid color polygons."
  26. ),
  27. CheckboxOptionUI(
  28. option="gerber_multicolored",
  29. label_text="M-Color",
  30. label_tooltip="Draw polygons in different colors."
  31. ),
  32. CheckboxOptionUI(
  33. option="gerber_plot",
  34. label_text="Plot",
  35. label_tooltip="Plot (show) this object."
  36. ),
  37. SpinnerOptionUI(
  38. option="gerber_circle_steps",
  39. label_text="Circle Steps",
  40. label_tooltip="The number of circle steps for Gerber \n"
  41. "circular aperture linear approximation.",
  42. min_value=0, max_value=9999, step=1
  43. ),
  44. SeparatorOptionUI(),
  45. HeadingOptionUI(
  46. label_text="Default Values",
  47. label_tooltip="Those values will be used as fallback values\n"
  48. "in case that they are not found in the Gerber file."
  49. ),
  50. RadioSetOptionUI(
  51. option="gerber_def_units",
  52. label_text="Units",
  53. label_tooltip="The units used in the Gerber file.",
  54. choices=[{'label': _('INCH'), 'value': 'IN'},
  55. {'label': _('MM'), 'value': 'MM'}]
  56. ),
  57. RadioSetOptionUI(
  58. option="gerber_def_zeros",
  59. label_text="Zeros",
  60. label_tooltip="This sets the type of Gerber zeros.\n"
  61. "If LZ then Leading Zeros are removed and\n"
  62. "Trailing Zeros are kept.\n"
  63. "If TZ is checked then Trailing Zeros are removed\n"
  64. "and Leading Zeros are kept.",
  65. choices=[{'label': _('LZ'), 'value': 'L'},
  66. {'label': _('TZ'), 'value': 'T'}]
  67. ),
  68. SeparatorOptionUI(),
  69. CheckboxOptionUI(
  70. option="gerber_clean_apertures",
  71. label_text="Clean Apertures",
  72. label_tooltip="Will remove apertures that do not have geometry\n"
  73. "thus lowering the number of apertures in the Gerber object."
  74. ),
  75. CheckboxOptionUI(
  76. option="gerber_extra_buffering",
  77. label_text="Polarity change buffer",
  78. label_tooltip="Will apply extra buffering for the\n"
  79. "solid geometry when we have polarity changes.\n"
  80. "May help loading Gerber files that otherwise\n"
  81. "do not load correctly."
  82. ),
  83. SeparatorOptionUI(),
  84. HeadingOptionUI(label_text="Gerber Object Color"),
  85. ColorOptionUI(
  86. option="gerber_plot_line",
  87. label_text="Outline",
  88. label_tooltip="Set the line color for plotted objects.",
  89. ),
  90. ColorOptionUI(
  91. option="gerber_plot_fill",
  92. label_text="Fill",
  93. label_tooltip="Set the fill color for plotted objects.\n"
  94. "First 6 digits are the color and the last 2\n"
  95. "digits are for alpha (transparency) level."
  96. ),
  97. SliderWithSpinnerOptionUI(
  98. option="_gerber_plot_alpha",
  99. label_text="Alpha",
  100. label_tooltip="Set the transparency for plotted objects.",
  101. min_value=0, max_value=255, step=1
  102. )
  103. ]
  104. def on_plot_alpha_change(self):
  105. alpha = self.plot_alpha_field.get_value()
  106. fill = self._modify_color_alpha(color=self.plot_fill_field.get_value(), alpha=alpha)
  107. self.plot_fill_field.set_value(fill)
  108. line = self._modify_color_alpha(color=self.plot_line_field.get_value(), alpha=alpha)
  109. self.plot_line_field.set_value(line)
  110. def _modify_color_alpha(self, color: str, alpha: int):
  111. color_without_alpha = color[:7]
  112. if alpha > 255:
  113. return color_without_alpha + "FF"
  114. elif alpha < 0:
  115. return color_without_alpha + "00"
  116. else:
  117. hexalpha = hex(alpha)[2:]
  118. if len(hexalpha) == 1:
  119. hexalpha = "0" + hexalpha
  120. return color_without_alpha + hexalpha
  121. # def on_pf_color_alpha_spinner(self):
  122. # self.pf_color_alpha_slider.setValue(spinner_value)
  123. # self.app.defaults['gerber_plot_fill'] = \
  124. # self.app.defaults['gerber_plot_fill'][:7] + \
  125. # (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')
  126. # self.app.defaults['gerber_plot_line'] = \
  127. # self.app.defaults['gerber_plot_line'][:7] + \
  128. # (hex(spinner_value)[2:] if int(hex(spinner_value)[2:], 16) > 0 else '00')