GeometryGenPrefGroupUI.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. from PyQt5 import QtWidgets
  2. from PyQt5.QtCore import QSettings
  3. from appGUI.GUIElements import FCCheckBox, FCSpinner, FCEntry, FCColorEntry, RadioSet
  4. from appGUI.preferences.OptionsGroupUI import OptionsGroupUI
  5. import platform
  6. import gettext
  7. import appTranslation as fcTranslate
  8. import builtins
  9. fcTranslate.apply_language('strings')
  10. if '_' not in builtins.__dict__:
  11. _ = gettext.gettext
  12. settings = QSettings("Open Source", "FlatCAM")
  13. if settings.contains("machinist"):
  14. machinist_setting = settings.value('machinist', type=int)
  15. else:
  16. machinist_setting = 0
  17. class GeometryGenPrefGroupUI(OptionsGroupUI):
  18. def __init__(self, decimals=4, parent=None):
  19. # OptionsGroupUI.__init__(self, "Geometry General Preferences", parent=parent)
  20. super(GeometryGenPrefGroupUI, self).__init__(self, parent=parent)
  21. self.setTitle(str(_("Geometry General")))
  22. self.decimals = decimals
  23. # ## Plot options
  24. self.plot_options_label = QtWidgets.QLabel("<b>%s:</b>" % _("Plot Options"))
  25. self.layout.addWidget(self.plot_options_label)
  26. plot_hlay = QtWidgets.QHBoxLayout()
  27. self.layout.addLayout(plot_hlay)
  28. # Plot CB
  29. self.plot_cb = FCCheckBox(label=_('Plot'))
  30. self.plot_cb.setToolTip(
  31. _("Plot (show) this object.")
  32. )
  33. plot_hlay.addWidget(self.plot_cb)
  34. # Multicolored CB
  35. self.multicolored_cb = FCCheckBox(label=_('M-Color'))
  36. self.multicolored_cb.setToolTip(
  37. _("Draw polygons in different colors.")
  38. )
  39. plot_hlay.addWidget(self.multicolored_cb)
  40. grid0 = QtWidgets.QGridLayout()
  41. self.layout.addLayout(grid0)
  42. grid0.setColumnStretch(0, 0)
  43. grid0.setColumnStretch(1, 1)
  44. # Number of circle steps for circular aperture linear approximation
  45. self.circle_steps_label = QtWidgets.QLabel('%s:' % _("Circle Steps"))
  46. self.circle_steps_label.setToolTip(
  47. _("The number of circle steps for <b>Geometry</b> \n"
  48. "circle and arc shapes linear approximation.")
  49. )
  50. self.circle_steps_entry = FCSpinner()
  51. self.circle_steps_entry.set_range(0, 999)
  52. grid0.addWidget(self.circle_steps_label, 1, 0)
  53. grid0.addWidget(self.circle_steps_entry, 1, 1)
  54. # Tools
  55. self.tools_label = QtWidgets.QLabel("<b>%s:</b>" % _("Tools"))
  56. grid0.addWidget(self.tools_label, 2, 0, 1, 2)
  57. # Tooldia
  58. tdlabel = QtWidgets.QLabel('<b><font color="green">%s:</font></b>' % _('Tools Dia'))
  59. tdlabel.setToolTip(
  60. _("Diameters of the tools, separated by comma.\n"
  61. "The value of the diameter has to use the dot decimals separator.\n"
  62. "Valid values: 0.3, 1.0")
  63. )
  64. self.cnctooldia_entry = FCEntry()
  65. grid0.addWidget(tdlabel, 3, 0)
  66. grid0.addWidget(self.cnctooldia_entry, 3, 1)
  67. separator_line = QtWidgets.QFrame()
  68. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  69. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  70. grid0.addWidget(separator_line, 9, 0, 1, 2)
  71. self.opt_label = QtWidgets.QLabel("<b>%s:</b>" % _("Path Optimization"))
  72. grid0.addWidget(self.opt_label, 10, 0, 1, 2)
  73. self.opt_algorithm_label = QtWidgets.QLabel(_('Algorithm:'))
  74. self.opt_algorithm_label.setToolTip(
  75. _("This sets the path optimization algorithm.\n"
  76. "- Rtre -> Rtree algorithm\n"
  77. "- MetaHeuristic -> Google OR-Tools algorithm with\n"
  78. "MetaHeuristic Guided Local Path is used. Default search time is 3sec.\n"
  79. "- Basic -> Using Google OR-Tools Basic algorithm\n"
  80. "- TSA -> Using Travelling Salesman algorithm\n"
  81. "\n"
  82. "Some options are disabled when the application works in 32bit mode.")
  83. )
  84. self.opt_algorithm_radio = RadioSet(
  85. [
  86. {'label': _('Rtree'), 'value': 'R'},
  87. {'label': _('MetaHeuristic'), 'value': 'M'},
  88. {'label': _('Basic'), 'value': 'B'},
  89. {'label': _('TSA'), 'value': 'T'}
  90. ], orientation='vertical', stretch=False)
  91. grid0.addWidget(self.opt_algorithm_label, 12, 0)
  92. grid0.addWidget(self.opt_algorithm_radio, 12, 1)
  93. self.optimization_time_label = QtWidgets.QLabel('%s:' % _('Duration'))
  94. self.optimization_time_label.setToolTip(
  95. _("When OR-Tools Metaheuristic (MH) is enabled there is a\n"
  96. "maximum threshold for how much time is spent doing the\n"
  97. "path optimization. This max duration is set here.\n"
  98. "In seconds.")
  99. )
  100. self.optimization_time_entry = FCSpinner()
  101. self.optimization_time_entry.set_range(0, 999)
  102. grid0.addWidget(self.optimization_time_label, 14, 0)
  103. grid0.addWidget(self.optimization_time_entry, 14, 1)
  104. separator_line = QtWidgets.QFrame()
  105. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  106. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  107. grid0.addWidget(separator_line, 16, 0, 1, 2)
  108. # Fuse Tools
  109. self.join_geo_label = QtWidgets.QLabel('<b>%s</b>:' % _('Join Option'))
  110. grid0.addWidget(self.join_geo_label, 18, 0, 1, 2)
  111. self.fuse_tools_cb = FCCheckBox(_("Fuse Tools"))
  112. self.fuse_tools_cb.setToolTip(
  113. _("When checked, the tools will be merged\n"
  114. "but only if they share some of their attributes.")
  115. )
  116. grid0.addWidget(self.fuse_tools_cb, 20, 0, 1, 2)
  117. separator_line = QtWidgets.QFrame()
  118. separator_line.setFrameShape(QtWidgets.QFrame.HLine)
  119. separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
  120. grid0.addWidget(separator_line, 22, 0, 1, 2)
  121. # Geometry Object Color
  122. self.gerber_color_label = QtWidgets.QLabel('<b>%s</b>:' % _('Object Color'))
  123. grid0.addWidget(self.gerber_color_label, 24, 0, 1, 2)
  124. # Plot Line Color
  125. self.line_color_label = QtWidgets.QLabel('%s:' % _('Outline'))
  126. self.line_color_label.setToolTip(
  127. _("Set the line color for plotted objects.")
  128. )
  129. self.line_color_entry = FCColorEntry()
  130. grid0.addWidget(self.line_color_label, 26, 0)
  131. grid0.addWidget(self.line_color_entry, 26, 1)
  132. self.layout.addStretch()
  133. current_platform = platform.architecture()[0]
  134. if current_platform == '64bit':
  135. self.opt_algorithm_radio.setOptionsDisabled([_('MetaHeuristic'), _('Basic')], False)
  136. self.optimization_time_label.setDisabled(False)
  137. self.optimization_time_entry.setDisabled(False)
  138. else:
  139. self.opt_algorithm_radio.setOptionsDisabled([_('MetaHeuristic'), _('Basic')], True)
  140. self.optimization_time_label.setDisabled(True)
  141. self.optimization_time_entry.setDisabled(True)
  142. self.opt_algorithm_radio.activated_custom.connect(self.optimization_selection)
  143. # Setting plot colors signals
  144. self.line_color_entry.editingFinished.connect(self.on_line_color_entry)
  145. def on_line_color_entry(self):
  146. self.app.defaults['geometry_plot_line'] = self.line_color_entry.get_value()[:7] + 'FF'
  147. def optimization_selection(self, val):
  148. if val == 'M':
  149. self.optimization_time_label.setDisabled(False)
  150. self.optimization_time_entry.setDisabled(False)
  151. else:
  152. self.optimization_time_label.setDisabled(True)
  153. self.optimization_time_entry.setDisabled(True)