ExcellonGenPrefGroupUI.py 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import platform
  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 ExcellonGenPrefGroupUI(OptionsGroupUI2):
  11. def __init__(self, decimals=4, **kwargs):
  12. self.decimals = decimals
  13. super().__init__(**kwargs)
  14. self.setTitle(str(_("Excellon General")))
  15. # disable the Excellon path optimizations made with Google OR-Tools if the app is run on a 32bit platform
  16. if platform.architecture()[0] != '64bit':
  17. self.option_dict()["excellon_optimization_type"].get_field().set_value('T')
  18. self.option_dict()["excellon_optimization_type"].get_field().setDisabled(True)
  19. self.option_dict()["excellon_optimization_type"].label_widget.setDisabled(True)
  20. # Enable/disable the duration box according to type selected
  21. self.option_dict()["excellon_optimization_type"].get_field().activated_custom.connect(self.optimization_selection)
  22. self.optimization_selection()
  23. # Load the defaults values into the Excellon Format and Excellon Zeros fields
  24. self.option_dict()["__excellon_restore_defaults"].get_field().clicked.connect(self.on_defaults_button)
  25. def build_options(self) -> [OptionUI]:
  26. return [
  27. HeadingOptionUI(label_text="Plot Options"),
  28. CheckboxOptionUI(
  29. option="excellon_plot",
  30. label_text="Plot",
  31. label_tooltip="Plot (show) this object."
  32. ),
  33. CheckboxOptionUI(
  34. option="excellon_solid",
  35. label_text="Solid",
  36. label_tooltip="Plot as solid circles."
  37. ),
  38. SeparatorOptionUI(),
  39. HeadingOptionUI(
  40. label_text="Excellon Format",
  41. label_tooltip="The NC drill files, usually named Excellon files\n"
  42. "are files that can be found in different formats.\n"
  43. "Here we set the format used when the provided\n"
  44. "coordinates are not using period.\n"
  45. "\n"
  46. "Possible presets:\n"
  47. "\n"
  48. "PROTEUS 3:3 MM LZ\n"
  49. "DipTrace 5:2 MM TZ\n"
  50. "DipTrace 4:3 MM LZ\n"
  51. "\n"
  52. "EAGLE 3:3 MM TZ\n"
  53. "EAGLE 4:3 MM TZ\n"
  54. "EAGLE 2:5 INCH TZ\n"
  55. "EAGLE 3:5 INCH TZ\n"
  56. "\n"
  57. "ALTIUM 2:4 INCH LZ\n"
  58. "Sprint Layout 2:4 INCH LZ"
  59. "\n"
  60. "KiCAD 3:5 INCH TZ"
  61. ),
  62. SpinnerOptionUI(
  63. option="excellon_format_upper_in",
  64. label_text="INCH int",
  65. label_tooltip="This number signifies the number of digits in\nthe whole part of Excellon coordinates.",
  66. min_value=0, max_value=9, step=1
  67. ),
  68. SpinnerOptionUI(
  69. option="excellon_format_lower_in",
  70. label_text="INCH decimals",
  71. label_tooltip="This number signifies the number of digits in\nthe decimal part of Excellon coordinates.",
  72. min_value=0, max_value=9, step=1
  73. ),
  74. SpinnerOptionUI(
  75. option="excellon_format_upper_mm",
  76. label_text="METRIC int",
  77. label_tooltip="This number signifies the number of digits in\nthe whole part of Excellon coordinates.",
  78. min_value=0, max_value=9, step=1
  79. ),
  80. SpinnerOptionUI(
  81. option="excellon_format_lower_mm",
  82. label_text="METRIC decimals",
  83. label_tooltip="This number signifies the number of digits in\nthe decimal part of Excellon coordinates.",
  84. min_value=0, max_value=9, step=1
  85. ),
  86. RadioSetOptionUI(
  87. option="excellon_zeros",
  88. label_text="Zeros",
  89. label_tooltip="This sets the type of Excellon zeros.\n"
  90. "If LZ then Leading Zeros are kept and\n"
  91. "Trailing Zeros are removed.\n"
  92. "If TZ is checked then Trailing Zeros are kept\n"
  93. "and Leading Zeros are removed.\n\n"
  94. "This is used when there is no information\n"
  95. "stored in the Excellon file.",
  96. choices=[
  97. {'label': _('LZ'), 'value': 'L'},
  98. {'label': _('TZ'), 'value': 'T'}
  99. ]
  100. ),
  101. RadioSetOptionUI(
  102. option="excellon_units",
  103. label_text="Units",
  104. label_tooltip="This sets the default units of Excellon files.\n"
  105. "If it is not detected in the parsed file the value here\n"
  106. "will be used."
  107. "Some Excellon files don't have an header\n"
  108. "therefore this parameter will be used.",
  109. choices=[
  110. {'label': _('INCH'), 'value': 'INCH'},
  111. {'label': _('MM'), 'value': 'METRIC'}
  112. ]
  113. ),
  114. CheckboxOptionUI(
  115. option="excellon_update",
  116. label_text="Update Export settings",
  117. label_tooltip="If checked, the Excellon Export settings will be updated with the ones above."
  118. ),
  119. FullWidthButtonOptionUI(
  120. option="__excellon_restore_defaults",
  121. label_text="Restore Defaults",
  122. label_tooltip=None
  123. ),
  124. SeparatorOptionUI(),
  125. HeadingOptionUI(label_text="Excellon Optimization"),
  126. RadioSetOptionUI(
  127. option="excellon_optimization_type",
  128. label_text="Algorithm",
  129. label_tooltip="This sets the optimization type for the Excellon drill path.\n"
  130. "If <<MetaHeuristic>> is checked then Google OR-Tools algorithm with\n"
  131. "MetaHeuristic Guided Local Path is used. Default search time is 3sec.\n"
  132. "If <<Basic>> is checked then Google OR-Tools Basic algorithm is used.\n"
  133. "If <<TSA>> is checked then Travelling Salesman algorithm is used for\n"
  134. "drill path optimization.\n"
  135. "\n"
  136. "If this control is disabled, then FlatCAM works in 32bit mode and it uses\n"
  137. "Travelling Salesman algorithm for path optimization.",
  138. choices=[
  139. {'label': _('MetaHeuristic'), 'value': 'M'},
  140. {'label': _('Basic'), 'value': 'B'},
  141. {'label': _('TSA'), 'value': 'T'}
  142. ],
  143. orientation="vertical"
  144. ),
  145. SpinnerOptionUI(
  146. option="excellon_search_time",
  147. label_text="Duration",
  148. label_tooltip="When OR-Tools Metaheuristic (MH) is enabled there is a\n"
  149. "maximum threshold for how much time is spent doing the\n"
  150. "path optimization. This max duration is set here.\n"
  151. "In seconds.",
  152. min_value=1, max_value=999, step=1
  153. ),
  154. SeparatorOptionUI(),
  155. HeadingOptionUI(label_text="Excellon Object Color"),
  156. ColorOptionUI(
  157. option="excellon_plot_line",
  158. label_text="Outline",
  159. label_tooltip="Set the line color for plotted objects.",
  160. ),
  161. ColorOptionUI(
  162. option="excellon_plot_fill",
  163. label_text="Fill",
  164. label_tooltip="Set the fill color for plotted objects.\n"
  165. "First 6 digits are the color and the last 2\n"
  166. "digits are for alpha (transparency) level."
  167. ),
  168. ColorAlphaSliderOptionUI(
  169. applies_to=["excellon_plot_line", "excellon_plot_fill"],
  170. group=self,
  171. label_text="Alpha",
  172. label_tooltip="Set the transparency for plotted objects."
  173. )
  174. ]
  175. def optimization_selection(self):
  176. disable_time = (self.option_dict()["excellon_optimization_type"].get_field().get_value() != 'M')
  177. self.option_dict()["excellon_search_time"].label_widget.setDisabled(disable_time)
  178. self.option_dict()["excellon_search_time"].get_field().setDisabled(disable_time)
  179. def on_defaults_button(self):
  180. self.option_dict()["excellon_format_lower_in"].get_field().set_value('4')
  181. self.option_dict()["excellon_format_upper_in"].get_field().set_value('2')
  182. self.option_dict()["excellon_format_lower_mm"].get_field().set_value('3')
  183. self.option_dict()["excellon_format_upper_mm"].get_field().set_value('3')
  184. self.option_dict()["excellon_zeros"].get_field().set_value('L')
  185. self.option_dict()["excellon_units"].get_field().set_value('INCH')