ToolSolderPaste.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. from FlatCAMTool import FlatCAMTool
  2. from copy import copy,deepcopy
  3. from ObjectCollection import *
  4. from FlatCAMApp import *
  5. from PyQt5 import QtGui, QtCore, QtWidgets
  6. from GUIElements import IntEntry, RadioSet, LengthEntry
  7. from FlatCAMObj import FlatCAMGeometry, FlatCAMExcellon, FlatCAMGerber
  8. class ToolSolderPaste(FlatCAMTool):
  9. toolName = "Solder Paste Tool"
  10. def __init__(self, app):
  11. FlatCAMTool.__init__(self, app)
  12. ## Title
  13. title_label = QtWidgets.QLabel("%s" % self.toolName)
  14. title_label.setStyleSheet("""
  15. QLabel
  16. {
  17. font-size: 16px;
  18. font-weight: bold;
  19. }
  20. """)
  21. self.layout.addWidget(title_label)
  22. ## Form Layout
  23. form_layout = QtWidgets.QFormLayout()
  24. self.layout.addLayout(form_layout)
  25. ## Type of object to be cutout
  26. self.type_obj_combo = QtWidgets.QComboBox()
  27. self.type_obj_combo.addItem("Gerber")
  28. self.type_obj_combo.addItem("Excellon")
  29. self.type_obj_combo.addItem("Geometry")
  30. # we get rid of item1 ("Excellon") as it is not suitable for creating solderpaste
  31. self.type_obj_combo.view().setRowHidden(1, True)
  32. self.type_obj_combo.setItemIcon(0, QtGui.QIcon("share/flatcam_icon16.png"))
  33. self.type_obj_combo.setItemIcon(2, QtGui.QIcon("share/geometry16.png"))
  34. self.type_obj_combo_label = QtWidgets.QLabel("Object Type:")
  35. self.type_obj_combo_label.setToolTip(
  36. "Specify the type of object to be used for solder paste dispense.\n"
  37. "It can be of type: Gerber or Geometry.\n"
  38. "What is selected here will dictate the kind\n"
  39. "of objects that will populate the 'Object' combobox."
  40. )
  41. form_layout.addRow(self.type_obj_combo_label, self.type_obj_combo)
  42. ## Object to be used for solderpaste dispensing
  43. self.obj_combo = QtWidgets.QComboBox()
  44. self.obj_combo.setModel(self.app.collection)
  45. self.obj_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  46. self.obj_combo.setCurrentIndex(1)
  47. self.object_label = QtWidgets.QLabel("Object:")
  48. self.object_label.setToolTip(
  49. "Solder paste object. "
  50. )
  51. form_layout.addRow(self.object_label, self.obj_combo)
  52. # Offset distance
  53. self.offset_entry = FloatEntry()
  54. self.offset_entry.setValidator(QtGui.QDoubleValidator(-99.9999, 0.0000, 4))
  55. self.offset_label = QtWidgets.QLabel(" Solder Offset:")
  56. self.offset_label.setToolTip(
  57. "The offset for the solder paste.\n"
  58. "Due of the diameter of the solder paste dispenser\n"
  59. "we need to adjust the quantity of solder paste\n"
  60. "so it will not overflow over the pad."
  61. )
  62. form_layout.addRow(self.offset_label, self.offset_entry)
  63. # Z dispense start
  64. self.z_start_entry = FCEntry()
  65. self.z_start_label = QtWidgets.QLabel("Z Dispense Start:")
  66. self.z_start_label.setToolTip(
  67. "The size of the gaps in the cutout\n"
  68. "used to keep the board connected to\n"
  69. "the surrounding material (the one \n"
  70. "from which the PCB is cutout)."
  71. )
  72. form_layout.addRow(self.z_start_label, self.z_start_entry)
  73. # Z dispense
  74. self.z_dispense_entry = FCEntry()
  75. self.z_dispense_label = QtWidgets.QLabel("Z Dispense:")
  76. self.z_dispense_label.setToolTip(
  77. "Margin over bounds. A positive value here\n"
  78. "will make the cutout of the PCB further from\n"
  79. "the actual PCB border"
  80. )
  81. form_layout.addRow(self.z_dispense_label, self.z_dispense_entry)
  82. # Z dispense stop
  83. self.z_stop_entry = FCEntry()
  84. self.z_stop_label = QtWidgets.QLabel("Z Dispense Stop:")
  85. self.z_stop_label.setToolTip(
  86. "The size of the gaps in the cutout\n"
  87. "used to keep the board connected to\n"
  88. "the surrounding material (the one \n"
  89. "from which the PCB is cutout)."
  90. )
  91. form_layout.addRow(self.z_stop_label, self.z_stop_entry)
  92. # Z travel
  93. self.z_travel_entry = FCEntry()
  94. self.z_travel_label = QtWidgets.QLabel("Z Travel:")
  95. self.z_travel_label.setToolTip(
  96. "The size of the gaps in the cutout\n"
  97. "used to keep the board connected to\n"
  98. "the surrounding material (the one \n"
  99. "from which the PCB is cutout)."
  100. )
  101. form_layout.addRow(self.z_travel_label, self.z_travel_entry)
  102. # Feedrate X-Y
  103. self.frxy_entry = FCEntry()
  104. self.frxy_label = QtWidgets.QLabel("Feedrate X-Y:")
  105. self.frxy_label.setToolTip(
  106. "The size of the gaps in the cutout\n"
  107. "used to keep the board connected to\n"
  108. "the surrounding material (the one \n"
  109. "from which the PCB is cutout)."
  110. )
  111. form_layout.addRow(self.frxy_label, self.frxy_entry)
  112. # Feedrate Z
  113. self.frz_entry = FCEntry()
  114. self.frz_label = QtWidgets.QLabel("Feedrate Z:")
  115. self.frz_label.setToolTip(
  116. "The size of the gaps in the cutout\n"
  117. "used to keep the board connected to\n"
  118. "the surrounding material (the one \n"
  119. "from which the PCB is cutout)."
  120. )
  121. form_layout.addRow(self.frz_label, self.frz_entry)
  122. # Spindle Speed Forward
  123. self.speedfwd_entry = FCEntry()
  124. self.speedfwd_label = QtWidgets.QLabel("Spindle Speed FWD:")
  125. self.speedfwd_label.setToolTip(
  126. "The size of the gaps in the cutout\n"
  127. "used to keep the board connected to\n"
  128. "the surrounding material (the one \n"
  129. "from which the PCB is cutout)."
  130. )
  131. form_layout.addRow(self.speedfwd_label, self.speedfwd_entry)
  132. # Dwell Forward
  133. self.dwellfwd_entry = FCEntry()
  134. self.dwellfwd_label = QtWidgets.QLabel("Dwell FWD:")
  135. self.dwellfwd_label.setToolTip(
  136. "The size of the gaps in the cutout\n"
  137. "used to keep the board connected to\n"
  138. "the surrounding material (the one \n"
  139. "from which the PCB is cutout)."
  140. )
  141. form_layout.addRow(self.dwellfwd_label, self.dwellfwd_entry)
  142. # Spindle Speed Reverse
  143. self.speedrev_entry = FCEntry()
  144. self.speedrev_label = QtWidgets.QLabel("Spindle Speed REV:")
  145. self.speedrev_label.setToolTip(
  146. "The size of the gaps in the cutout\n"
  147. "used to keep the board connected to\n"
  148. "the surrounding material (the one \n"
  149. "from which the PCB is cutout)."
  150. )
  151. form_layout.addRow(self.speedrev_label, self.speedrev_entry)
  152. # Dwell Reverse
  153. self.dwellrev_entry = FCEntry()
  154. self.dwellrev_label = QtWidgets.QLabel("Dwell REV:")
  155. self.dwellrev_label.setToolTip(
  156. "The size of the gaps in the cutout\n"
  157. "used to keep the board connected to\n"
  158. "the surrounding material (the one \n"
  159. "from which the PCB is cutout)."
  160. )
  161. form_layout.addRow(self.dwellrev_label, self.dwellrev_entry)
  162. # Postprocessors
  163. pp_label = QtWidgets.QLabel('PostProcessors:')
  164. pp_label.setToolTip(
  165. "Files that control the GCoe generation."
  166. )
  167. self.pp_combo = FCComboBox()
  168. pp_items = [1, 2, 3, 4, 5]
  169. for it in pp_items:
  170. self.pp_combo.addItem(str(it))
  171. self.pp_combo.setStyleSheet('background-color: rgb(255,255,255)')
  172. form_layout.addRow(pp_label, self.pp_combo)
  173. ## Buttons
  174. hlay = QtWidgets.QHBoxLayout()
  175. self.layout.addLayout(hlay)
  176. hlay.addStretch()
  177. self.soldergeo_btn = QtWidgets.QPushButton("Generate Geo")
  178. self.soldergeo_btn.setToolTip(
  179. "Generate solder paste dispensing geometry."
  180. )
  181. hlay.addWidget(self.soldergeo_btn)
  182. self.solder_gcode = QtWidgets.QPushButton("Generate GCode")
  183. self.solder_gcode.setToolTip(
  184. "Generate GCode to dispense Solder Paste\n"
  185. "on PCB pads."
  186. )
  187. hlay.addWidget(self.solder_gcode)
  188. self.layout.addStretch()
  189. ## Signals
  190. self.soldergeo_btn.clicked.connect(self.on_create_geo)
  191. self.solder_gcode.clicked.connect(self.on_create_gcode)
  192. self.type_obj_combo.currentIndexChanged.connect(self.on_type_obj_index_changed)
  193. def on_type_obj_index_changed(self, index):
  194. obj_type = self.type_obj_combo.currentIndex()
  195. self.obj_combo.setRootModelIndex(self.app.collection.index(obj_type, 0, QtCore.QModelIndex()))
  196. self.obj_combo.setCurrentIndex(0)
  197. def run(self):
  198. self.app.report_usage("ToolSolderPaste()")
  199. FlatCAMTool.run(self)
  200. self.set_tool_ui()
  201. # if the splitter us hidden, display it
  202. if self.app.ui.splitter.sizes()[0] == 0:
  203. self.app.ui.splitter.setSizes([1, 1])
  204. self.app.ui.notebook.setTabText(2, "SolderPaste Tool")
  205. def install(self, icon=None, separator=None, **kwargs):
  206. FlatCAMTool.install(self, icon, separator, shortcut='ALT+K', **kwargs)
  207. def set_tool_ui(self):
  208. self.reset_fields()
  209. pass
  210. def on_create_geo(self):
  211. name = self.obj_combo.currentText()
  212. def geo_init(geo_obj, app_obj):
  213. pass
  214. # self.app.new_object("geometry", name + "_cutout", geo_init)
  215. # self.app.inform.emit("[success] Rectangular CutOut operation finished.")
  216. # self.app.ui.notebook.setCurrentWidget(self.app.ui.project_tab)
  217. def on_create_gcode(self):
  218. name = self.obj_combo.currentText()
  219. def geo_init(geo_obj, app_obj):
  220. pass
  221. # self.app.new_object("geometry", name + "_cutout", geo_init)
  222. # self.app.inform.emit("[success] Rectangular CutOut operation finished.")
  223. # self.app.ui.notebook.setCurrentWidget(self.app.ui.project_tab)
  224. def reset_fields(self):
  225. self.obj_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))