ToolsFilmPrefGroupUI.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. from PyQt5 import QtWidgets
  2. from PyQt5.QtCore import QSettings
  3. from appGUI.GUIElements import RadioSet, FCDoubleSpinner, FCCheckBox, FCComboBox, FCColorEntry, FCLabel, FCSpinner
  4. from appGUI.preferences.OptionsGroupUI import OptionsGroupUI
  5. import gettext
  6. import appTranslation as fcTranslate
  7. import builtins
  8. fcTranslate.apply_language('strings')
  9. if '_' not in builtins.__dict__:
  10. _ = gettext.gettext
  11. settings = QSettings("Open Source", "FlatCAM")
  12. if settings.contains("machinist"):
  13. machinist_setting = settings.value('machinist', type=int)
  14. else:
  15. machinist_setting = 0
  16. class ToolsFilmPrefGroupUI(OptionsGroupUI):
  17. def __init__(self, decimals=4, parent=None):
  18. # OptionsGroupUI.__init__(self, "Cutout Tool Options", parent=parent)
  19. super(ToolsFilmPrefGroupUI, self).__init__(self, parent=parent)
  20. self.setTitle(str(_("Film Tool Options")))
  21. self.decimals = decimals
  22. # ## Parameters
  23. self.film_label = FCLabel("<b>%s:</b>" % _("Parameters"))
  24. self.film_label.setToolTip(
  25. _("Create a PCB film from a Gerber or Geometry object.\n"
  26. "The file is saved in SVG format.")
  27. )
  28. self.layout.addWidget(self.film_label)
  29. grid0 = QtWidgets.QGridLayout()
  30. self.layout.addLayout(grid0)
  31. self.film_type_radio = RadioSet([{'label': 'Pos', 'value': 'pos'},
  32. {'label': 'Neg', 'value': 'neg'}])
  33. ftypelbl = FCLabel('%s:' % _('Film Type'))
  34. ftypelbl.setToolTip(
  35. _("Generate a Positive black film or a Negative film.\n"
  36. "Positive means that it will print the features\n"
  37. "with black on a white canvas.\n"
  38. "Negative means that it will print the features\n"
  39. "with white on a black canvas.\n"
  40. "The Film format is SVG.")
  41. )
  42. grid0.addWidget(ftypelbl, 0, 0)
  43. grid0.addWidget(self.film_type_radio, 0, 1)
  44. # Film Color
  45. self.film_color_label = FCLabel('%s:' % _('Film Color'))
  46. self.film_color_label.setToolTip(
  47. _("Set the film color when positive film is selected.")
  48. )
  49. self.film_color_entry = FCColorEntry()
  50. grid0.addWidget(self.film_color_label, 1, 0)
  51. grid0.addWidget(self.film_color_entry, 1, 1)
  52. # Film Border
  53. self.film_boundary_entry = FCDoubleSpinner()
  54. self.film_boundary_entry.set_precision(self.decimals)
  55. self.film_boundary_entry.set_range(0, 10000.0000)
  56. self.film_boundary_entry.setSingleStep(0.1)
  57. self.film_boundary_label = FCLabel('%s:' % _("Border"))
  58. self.film_boundary_label.setToolTip(
  59. _("Specify a border around the object.\n"
  60. "Only for negative film.\n"
  61. "It helps if we use as a Box Object the same \n"
  62. "object as in Film Object. It will create a thick\n"
  63. "black bar around the actual print allowing for a\n"
  64. "better delimitation of the outline features which are of\n"
  65. "white color like the rest and which may confound with the\n"
  66. "surroundings if not for this border.")
  67. )
  68. grid0.addWidget(self.film_boundary_label, 2, 0)
  69. grid0.addWidget(self.film_boundary_entry, 2, 1)
  70. self.film_scale_stroke_entry = FCDoubleSpinner()
  71. self.film_scale_stroke_entry.set_precision(self.decimals)
  72. self.film_scale_stroke_entry.set_range(0, 10000.0000)
  73. self.film_scale_stroke_entry.setSingleStep(0.1)
  74. self.film_scale_stroke_label = FCLabel('%s:' % _("Scale Stroke"))
  75. self.film_scale_stroke_label.setToolTip(
  76. _("Scale the line stroke thickness of each feature in the SVG file.\n"
  77. "It means that the line that envelope each SVG feature will be thicker or thinner,\n"
  78. "therefore the fine features may be more affected by this parameter.")
  79. )
  80. grid0.addWidget(self.film_scale_stroke_label, 3, 0)
  81. grid0.addWidget(self.film_scale_stroke_entry, 3, 1)
  82. self.film_adj_label = FCLabel('<b>%s</b>' % _("Film Adjustments"))
  83. self.film_adj_label.setToolTip(
  84. _("Sometime the printers will distort the print shape, especially the Laser types.\n"
  85. "This section provide the tools to compensate for the print distortions.")
  86. )
  87. grid0.addWidget(self.film_adj_label, 4, 0, 1, 2)
  88. # Scale Geometry
  89. self.film_scale_cb = FCCheckBox('%s' % _("Scale Film geometry"))
  90. self.film_scale_cb.setToolTip(
  91. _("A value greater than 1 will stretch the film\n"
  92. "while a value less than 1 will jolt it.")
  93. )
  94. self.film_scale_cb.setStyleSheet(
  95. """
  96. QCheckBox {font-weight: bold; color: black}
  97. """
  98. )
  99. grid0.addWidget(self.film_scale_cb, 5, 0, 1, 2)
  100. self.film_scalex_label = FCLabel('%s:' % _("X factor"))
  101. self.film_scalex_entry = FCDoubleSpinner()
  102. self.film_scalex_entry.set_range(-999.9999, 999.9999)
  103. self.film_scalex_entry.set_precision(self.decimals)
  104. self.film_scalex_entry.setSingleStep(0.01)
  105. grid0.addWidget(self.film_scalex_label, 6, 0)
  106. grid0.addWidget(self.film_scalex_entry, 6, 1)
  107. self.film_scaley_label = FCLabel('%s:' % _("Y factor"))
  108. self.film_scaley_entry = FCDoubleSpinner()
  109. self.film_scaley_entry.set_range(-999.9999, 999.9999)
  110. self.film_scaley_entry.set_precision(self.decimals)
  111. self.film_scaley_entry.setSingleStep(0.01)
  112. grid0.addWidget(self.film_scaley_label, 7, 0)
  113. grid0.addWidget(self.film_scaley_entry, 7, 1)
  114. # Skew Geometry
  115. self.film_skew_cb = FCCheckBox('%s' % _("Skew Film geometry"))
  116. self.film_skew_cb.setToolTip(
  117. _("Positive values will skew to the right\n"
  118. "while negative values will skew to the left.")
  119. )
  120. self.film_skew_cb.setStyleSheet(
  121. """
  122. QCheckBox {font-weight: bold; color: black}
  123. """
  124. )
  125. grid0.addWidget(self.film_skew_cb, 8, 0, 1, 2)
  126. self.film_skewx_label = FCLabel('%s:' % _("X angle"))
  127. self.film_skewx_entry = FCDoubleSpinner()
  128. self.film_skewx_entry.set_range(-999.9999, 999.9999)
  129. self.film_skewx_entry.set_precision(self.decimals)
  130. self.film_skewx_entry.setSingleStep(0.01)
  131. grid0.addWidget(self.film_skewx_label, 9, 0)
  132. grid0.addWidget(self.film_skewx_entry, 9, 1)
  133. self.film_skewy_label = FCLabel('%s:' % _("Y angle"))
  134. self.film_skewy_entry = FCDoubleSpinner()
  135. self.film_skewy_entry.set_range(-999.9999, 999.9999)
  136. self.film_skewy_entry.set_precision(self.decimals)
  137. self.film_skewy_entry.setSingleStep(0.01)
  138. grid0.addWidget(self.film_skewy_label, 10, 0)
  139. grid0.addWidget(self.film_skewy_entry, 10, 1)
  140. self.film_skew_ref_label = FCLabel('%s:' % _("Reference"))
  141. self.film_skew_ref_label.setToolTip(
  142. _("The reference point to be used as origin for the skew.\n"
  143. "It can be one of the four points of the geometry bounding box.")
  144. )
  145. self.film_skew_reference = RadioSet([{'label': _('Bottom Left'), 'value': 'bottomleft'},
  146. {'label': _('Top Left'), 'value': 'topleft'},
  147. {'label': _('Bottom Right'), 'value': 'bottomright'},
  148. {'label': _('Top right'), 'value': 'topright'}],
  149. orientation='vertical',
  150. stretch=False)
  151. grid0.addWidget(self.film_skew_ref_label, 11, 0)
  152. grid0.addWidget(self.film_skew_reference, 11, 1)
  153. # Mirror Geometry
  154. self.film_mirror_cb = FCCheckBox('%s' % _("Mirror Film geometry"))
  155. self.film_mirror_cb.setToolTip(
  156. _("Mirror the film geometry on the selected axis or on both.")
  157. )
  158. self.film_mirror_cb.setStyleSheet(
  159. """
  160. QCheckBox {font-weight: bold; color: black}
  161. """
  162. )
  163. grid0.addWidget(self.film_mirror_cb, 12, 0, 1, 2)
  164. self.film_mirror_axis = RadioSet([{'label': _('None'), 'value': 'none'},
  165. {'label': _('X'), 'value': 'x'},
  166. {'label': _('Y'), 'value': 'y'},
  167. {'label': _('Both'), 'value': 'both'}],
  168. stretch=False)
  169. self.film_mirror_axis_label = FCLabel('%s:' % _("Mirror Axis"))
  170. grid0.addWidget(self.film_mirror_axis_label, 13, 0)
  171. grid0.addWidget(self.film_mirror_axis, 13, 1)
  172. separator_line3 = QtWidgets.QFrame()
  173. separator_line3.setFrameShape(QtWidgets.QFrame.HLine)
  174. separator_line3.setFrameShadow(QtWidgets.QFrame.Sunken)
  175. grid0.addWidget(separator_line3, 14, 0, 1, 2)
  176. self.file_type_radio = RadioSet([{'label': _('SVG'), 'value': 'svg'},
  177. {'label': _('PNG'), 'value': 'png'},
  178. {'label': _('PDF'), 'value': 'pdf'}
  179. ], stretch=False)
  180. self.file_type_label = FCLabel('%s:' % _("Film Type"))
  181. self.file_type_label.setToolTip(
  182. _("The file type of the saved film. Can be:\n"
  183. "- 'SVG' -> open-source vectorial format\n"
  184. "- 'PNG' -> raster image\n"
  185. "- 'PDF' -> portable document format")
  186. )
  187. grid0.addWidget(self.file_type_label, 15, 0)
  188. grid0.addWidget(self.file_type_radio, 15, 1)
  189. # Page orientation
  190. self.orientation_label = FCLabel('%s:' % _("Page Orientation"))
  191. self.orientation_label.setToolTip(_("Can be:\n"
  192. "- Portrait\n"
  193. "- Landscape"))
  194. self.orientation_radio = RadioSet([{'label': _('Portrait'), 'value': 'p'},
  195. {'label': _('Landscape'), 'value': 'l'},
  196. ], stretch=False)
  197. grid0.addWidget(self.orientation_label, 16, 0)
  198. grid0.addWidget(self.orientation_radio, 16, 1)
  199. # Page Size
  200. self.pagesize_label = FCLabel('%s:' % _("Page Size"))
  201. self.pagesize_label.setToolTip(_("A selection of standard ISO 216 page sizes."))
  202. self.pagesize_combo = FCComboBox()
  203. self.pagesize = {}
  204. self.pagesize.update(
  205. {
  206. 'Bounds': None,
  207. 'A0': (841, 1189),
  208. 'A1': (594, 841),
  209. 'A2': (420, 594),
  210. 'A3': (297, 420),
  211. 'A4': (210, 297),
  212. 'A5': (148, 210),
  213. 'A6': (105, 148),
  214. 'A7': (74, 105),
  215. 'A8': (52, 74),
  216. 'A9': (37, 52),
  217. 'A10': (26, 37),
  218. 'B0': (1000, 1414),
  219. 'B1': (707, 1000),
  220. 'B2': (500, 707),
  221. 'B3': (353, 500),
  222. 'B4': (250, 353),
  223. 'B5': (176, 250),
  224. 'B6': (125, 176),
  225. 'B7': (88, 125),
  226. 'B8': (62, 88),
  227. 'B9': (44, 62),
  228. 'B10': (31, 44),
  229. 'C0': (917, 1297),
  230. 'C1': (648, 917),
  231. 'C2': (458, 648),
  232. 'C3': (324, 458),
  233. 'C4': (229, 324),
  234. 'C5': (162, 229),
  235. 'C6': (114, 162),
  236. 'C7': (81, 114),
  237. 'C8': (57, 81),
  238. 'C9': (40, 57),
  239. 'C10': (28, 40),
  240. # American paper sizes
  241. 'LETTER': (8.5, 11),
  242. 'LEGAL': (8.5, 14),
  243. 'ELEVENSEVENTEEN': (11, 17),
  244. # From https://en.wikipedia.org/wiki/Paper_size
  245. 'JUNIOR_LEGAL': (5, 8),
  246. 'HALF_LETTER': (5.5, 8),
  247. 'GOV_LETTER': (8, 10.5),
  248. 'GOV_LEGAL': (8.5, 13),
  249. 'LEDGER': (17, 11),
  250. }
  251. )
  252. page_size_list = list(self.pagesize.keys())
  253. self.pagesize_combo.addItems(page_size_list)
  254. grid0.addWidget(self.pagesize_label, 17, 0)
  255. grid0.addWidget(self.pagesize_combo, 17, 1)
  256. # PNG DPI
  257. self.png_dpi_label = FCLabel('%s:' % "PNG DPI")
  258. self.png_dpi_label.setToolTip(
  259. _("Default value is 96 DPI. Change this value to scale the PNG file.")
  260. )
  261. self.png_dpi_spinner = FCSpinner()
  262. self.png_dpi_spinner.set_range(0, 100000)
  263. grid0.addWidget(self.png_dpi_label, 19, 0)
  264. grid0.addWidget(self.png_dpi_spinner, 19, 1)
  265. self.layout.addStretch()
  266. # Film Tool
  267. self.film_color_entry.editingFinished.connect(self.on_film_color_entry)
  268. def on_film_color_entry(self):
  269. self.app.defaults['tools_film_color'] = self.film_color_entry.get_value()