ToolOptimal.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. # ##########################################################
  2. # FlatCAM: 2D Post-processing for Manufacturing #
  3. # File Author: Marius Adrian Stanciu (c) #
  4. # Date: 09/27/2019 #
  5. # MIT Licence #
  6. # ##########################################################
  7. from PyQt5 import QtWidgets, QtCore, QtGui
  8. from AppTools.AppTool import AppTool
  9. from AppGUI.GUIElements import OptionalHideInputSection, FCTextArea, FCEntry, FCSpinner, FCCheckBox, FCComboBox
  10. from Common import GracefulException as grace
  11. from shapely.geometry import MultiPolygon
  12. from shapely.ops import nearest_points
  13. import numpy as np
  14. import logging
  15. import gettext
  16. import AppTranslation as fcTranslate
  17. import builtins
  18. fcTranslate.apply_language('strings')
  19. if '_' not in builtins.__dict__:
  20. _ = gettext.gettext
  21. log = logging.getLogger('base')
  22. class ToolOptimal(AppTool):
  23. toolName = _("Optimal Tool")
  24. update_text = QtCore.pyqtSignal(list)
  25. update_sec_distances = QtCore.pyqtSignal(dict)
  26. def __init__(self, app):
  27. AppTool.__init__(self, app)
  28. self.units = self.app.defaults['units'].upper()
  29. self.decimals = self.app.decimals
  30. # ############################################################################
  31. # ############################ GUI creation ##################################
  32. # ## Title
  33. title_label = QtWidgets.QLabel("%s" % self.toolName)
  34. title_label.setStyleSheet(
  35. """
  36. QLabel
  37. {
  38. font-size: 16px;
  39. font-weight: bold;
  40. }
  41. """)
  42. self.layout.addWidget(title_label)
  43. # ## Form Layout
  44. form_lay = QtWidgets.QFormLayout()
  45. self.layout.addLayout(form_lay)
  46. form_lay.addRow(QtWidgets.QLabel(""))
  47. # ## Gerber Object to mirror
  48. self.gerber_object_combo = FCComboBox()
  49. self.gerber_object_combo.setModel(self.app.collection)
  50. self.gerber_object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  51. self.gerber_object_combo.is_last = True
  52. self.gerber_object_combo.obj_type = "Gerber"
  53. self.gerber_object_label = QtWidgets.QLabel("<b>%s:</b>" % _("GERBER"))
  54. self.gerber_object_label.setToolTip(
  55. "Gerber object for which to find the minimum distance between copper features."
  56. )
  57. form_lay.addRow(self.gerber_object_label, self.gerber_object_combo)
  58. # Precision = nr of decimals
  59. self.precision_label = QtWidgets.QLabel('%s:' % _("Precision"))
  60. self.precision_label.setToolTip(_("Number of decimals kept for found distances."))
  61. self.precision_spinner = FCSpinner(callback=self.confirmation_message_int)
  62. self.precision_spinner.set_range(2, 10)
  63. self.precision_spinner.setWrapping(True)
  64. form_lay.addRow(self.precision_label, self.precision_spinner)
  65. # Results Title
  66. self.title_res_label = QtWidgets.QLabel('<b>%s:</b>' % _("Minimum distance"))
  67. self.title_res_label.setToolTip(_("Display minimum distance between copper features."))
  68. form_lay.addRow(self.title_res_label)
  69. # Result value
  70. self.result_label = QtWidgets.QLabel('%s:' % _("Determined"))
  71. self.result_entry = FCEntry()
  72. self.result_entry.setReadOnly(True)
  73. self.units_lbl = QtWidgets.QLabel(self.units.lower())
  74. self.units_lbl.setDisabled(True)
  75. hlay = QtWidgets.QHBoxLayout()
  76. hlay.addWidget(self.result_entry)
  77. hlay.addWidget(self.units_lbl)
  78. form_lay.addRow(self.result_label, hlay)
  79. # Frequency of minimum encounter
  80. self.freq_label = QtWidgets.QLabel('%s:' % _("Occurring"))
  81. self.freq_label.setToolTip(_("How many times this minimum is found."))
  82. self.freq_entry = FCEntry()
  83. self.freq_entry.setReadOnly(True)
  84. form_lay.addRow(self.freq_label, self.freq_entry)
  85. # Control if to display the locations of where the minimum was found
  86. self.locations_cb = FCCheckBox(_("Minimum points coordinates"))
  87. self.locations_cb.setToolTip(_("Coordinates for points where minimum distance was found."))
  88. form_lay.addRow(self.locations_cb)
  89. # Locations where minimum was found
  90. self.locations_textb = FCTextArea(parent=self)
  91. self.locations_textb.setPlaceholderText(
  92. _("Coordinates for points where minimum distance was found.")
  93. )
  94. self.locations_textb.setReadOnly(True)
  95. stylesheet = """
  96. QTextEdit { selection-background-color:blue;
  97. selection-color:white;
  98. }
  99. """
  100. self.locations_textb.setStyleSheet(stylesheet)
  101. form_lay.addRow(self.locations_textb)
  102. # Jump button
  103. self.locate_button = QtWidgets.QPushButton(_("Jump to selected position"))
  104. self.locate_button.setToolTip(
  105. _("Select a position in the Locations text box and then\n"
  106. "click this button.")
  107. )
  108. self.locate_button.setMinimumWidth(60)
  109. self.locate_button.setDisabled(True)
  110. form_lay.addRow(self.locate_button)
  111. # Other distances in Gerber
  112. self.title_second_res_label = QtWidgets.QLabel('<b>%s:</b>' % _("Other distances"))
  113. self.title_second_res_label.setToolTip(_("Will display other distances in the Gerber file ordered from\n"
  114. "the minimum to the maximum, not including the absolute minimum."))
  115. form_lay.addRow(self.title_second_res_label)
  116. # Control if to display the locations of where the minimum was found
  117. self.sec_locations_cb = FCCheckBox(_("Other distances points coordinates"))
  118. self.sec_locations_cb.setToolTip(_("Other distances and the coordinates for points\n"
  119. "where the distance was found."))
  120. form_lay.addRow(self.sec_locations_cb)
  121. # this way I can hide/show the frame
  122. self.sec_locations_frame = QtWidgets.QFrame()
  123. self.sec_locations_frame.setContentsMargins(0, 0, 0, 0)
  124. self.layout.addWidget(self.sec_locations_frame)
  125. self.distances_box = QtWidgets.QVBoxLayout()
  126. self.distances_box.setContentsMargins(0, 0, 0, 0)
  127. self.sec_locations_frame.setLayout(self.distances_box)
  128. # Other Distances label
  129. self.distances_label = QtWidgets.QLabel('%s' % _("Gerber distances"))
  130. self.distances_label.setToolTip(_("Other distances and the coordinates for points\n"
  131. "where the distance was found."))
  132. self.distances_box.addWidget(self.distances_label)
  133. # Other distances
  134. self.distances_textb = FCTextArea(parent=self)
  135. self.distances_textb.setPlaceholderText(
  136. _("Other distances and the coordinates for points\n"
  137. "where the distance was found.")
  138. )
  139. self.distances_textb.setReadOnly(True)
  140. stylesheet = """
  141. QTextEdit { selection-background-color:blue;
  142. selection-color:white;
  143. }
  144. """
  145. self.distances_textb.setStyleSheet(stylesheet)
  146. self.distances_box.addWidget(self.distances_textb)
  147. self.distances_box.addWidget(QtWidgets.QLabel(''))
  148. # Other Locations label
  149. self.locations_label = QtWidgets.QLabel('%s' % _("Points coordinates"))
  150. self.locations_label.setToolTip(_("Other distances and the coordinates for points\n"
  151. "where the distance was found."))
  152. self.distances_box.addWidget(self.locations_label)
  153. # Locations where minimum was found
  154. self.locations_sec_textb = FCTextArea(parent=self)
  155. self.locations_sec_textb.setPlaceholderText(
  156. _("Other distances and the coordinates for points\n"
  157. "where the distance was found.")
  158. )
  159. self.locations_sec_textb.setReadOnly(True)
  160. stylesheet = """
  161. QTextEdit { selection-background-color:blue;
  162. selection-color:white;
  163. }
  164. """
  165. self.locations_sec_textb.setStyleSheet(stylesheet)
  166. self.distances_box.addWidget(self.locations_sec_textb)
  167. # Jump button
  168. self.locate_sec_button = QtWidgets.QPushButton(_("Jump to selected position"))
  169. self.locate_sec_button.setToolTip(
  170. _("Select a position in the Locations text box and then\n"
  171. "click this button.")
  172. )
  173. self.locate_sec_button.setMinimumWidth(60)
  174. self.locate_sec_button.setDisabled(True)
  175. self.distances_box.addWidget(self.locate_sec_button)
  176. # GO button
  177. self.calculate_button = QtWidgets.QPushButton(_("Find Minimum"))
  178. self.calculate_button.setToolTip(
  179. _("Calculate the minimum distance between copper features,\n"
  180. "this will allow the determination of the right tool to\n"
  181. "use for isolation or copper clearing.")
  182. )
  183. self.calculate_button.setStyleSheet("""
  184. QPushButton
  185. {
  186. font-weight: bold;
  187. }
  188. """)
  189. self.calculate_button.setMinimumWidth(60)
  190. self.layout.addWidget(self.calculate_button)
  191. self.layout.addStretch()
  192. # ## Reset Tool
  193. self.reset_button = QtWidgets.QPushButton(_("Reset Tool"))
  194. self.reset_button.setToolTip(
  195. _("Will reset the tool parameters.")
  196. )
  197. self.reset_button.setStyleSheet("""
  198. QPushButton
  199. {
  200. font-weight: bold;
  201. }
  202. """)
  203. self.layout.addWidget(self.reset_button)
  204. self.loc_ois = OptionalHideInputSection(self.locations_cb, [self.locations_textb, self.locate_button])
  205. self.sec_loc_ois = OptionalHideInputSection(self.sec_locations_cb, [self.sec_locations_frame])
  206. # ################## Finished GUI creation ###################################
  207. # ############################################################################
  208. # this is the line selected in the textbox with the locations of the minimum
  209. self.selected_text = ''
  210. # this is the line selected in the textbox with the locations of the other distances found in the Gerber object
  211. self.selected_locations_text = ''
  212. # dict to hold the distances between every two elements in Gerber as keys and the actual locations where that
  213. # distances happen as values
  214. self.min_dict = {}
  215. # ############################################################################
  216. # ############################ Signals #######################################
  217. # ############################################################################
  218. self.calculate_button.clicked.connect(self.find_minimum_distance)
  219. self.locate_button.clicked.connect(self.on_locate_position)
  220. self.update_text.connect(self.on_update_text)
  221. self.locations_textb.cursorPositionChanged.connect(self.on_textbox_clicked)
  222. self.locate_sec_button.clicked.connect(self.on_locate_sec_position)
  223. self.update_sec_distances.connect(self.on_update_sec_distances_txt)
  224. self.distances_textb.cursorPositionChanged.connect(self.on_distances_textb_clicked)
  225. self.locations_sec_textb.cursorPositionChanged.connect(self.on_locations_sec_clicked)
  226. self.reset_button.clicked.connect(self.set_tool_ui)
  227. def install(self, icon=None, separator=None, **kwargs):
  228. AppTool.install(self, icon, separator, shortcut='Alt+O', **kwargs)
  229. def run(self, toggle=True):
  230. self.app.defaults.report_usage("ToolOptimal()")
  231. if toggle:
  232. # if the splitter is hidden, display it, else hide it but only if the current widget is the same
  233. if self.app.ui.splitter.sizes()[0] == 0:
  234. self.app.ui.splitter.setSizes([1, 1])
  235. else:
  236. try:
  237. if self.app.ui.tool_scroll_area.widget().objectName() == self.toolName:
  238. # if tab is populated with the tool but it does not have the focus, focus on it
  239. if not self.app.ui.notebook.currentWidget() is self.app.ui.tool_tab:
  240. # focus on Tool Tab
  241. self.app.ui.notebook.setCurrentWidget(self.app.ui.tool_tab)
  242. else:
  243. self.app.ui.splitter.setSizes([0, 1])
  244. except AttributeError:
  245. pass
  246. else:
  247. if self.app.ui.splitter.sizes()[0] == 0:
  248. self.app.ui.splitter.setSizes([1, 1])
  249. AppTool.run(self)
  250. self.set_tool_ui()
  251. self.app.ui.notebook.setTabText(2, _("Optimal Tool"))
  252. def set_tool_ui(self):
  253. self.result_entry.set_value(0.0)
  254. self.freq_entry.set_value('0')
  255. self.precision_spinner.set_value(int(self.app.defaults["tools_opt_precision"]))
  256. self.locations_textb.clear()
  257. # new cursor - select all document
  258. cursor = self.locations_textb.textCursor()
  259. cursor.select(QtGui.QTextCursor.Document)
  260. # clear previous selection highlight
  261. tmp = cursor.blockFormat()
  262. tmp.clearBackground()
  263. cursor.setBlockFormat(tmp)
  264. self.locations_textb.setVisible(False)
  265. self.locate_button.setVisible(False)
  266. self.result_entry.set_value(0.0)
  267. self.freq_entry.set_value('0')
  268. self.reset_fields()
  269. def find_minimum_distance(self):
  270. self.units = self.app.defaults['units'].upper()
  271. self.decimals = int(self.precision_spinner.get_value())
  272. selection_index = self.gerber_object_combo.currentIndex()
  273. model_index = self.app.collection.index(selection_index, 0, self.gerber_object_combo.rootModelIndex())
  274. try:
  275. fcobj = model_index.internalPointer().obj
  276. except Exception as e:
  277. log.debug("ToolOptimal.find_minimum_distance() --> %s" % str(e))
  278. self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Gerber object loaded ..."))
  279. return
  280. if fcobj.kind != 'gerber':
  281. self.app.inform.emit('[ERROR_NOTCL] %s' % _("Only Gerber objects can be evaluated."))
  282. return
  283. proc = self.app.proc_container.new(_("Working..."))
  284. def job_thread(app_obj):
  285. app_obj.inform.emit(_("Optimal Tool. Started to search for the minimum distance between copper features."))
  286. try:
  287. old_disp_number = 0
  288. pol_nr = 0
  289. app_obj.proc_container.update_view_text(' %d%%' % 0)
  290. total_geo = []
  291. for ap in list(fcobj.apertures.keys()):
  292. if 'geometry' in fcobj.apertures[ap]:
  293. app_obj.inform.emit(
  294. '%s: %s' % (_("Optimal Tool. Parsing geometry for aperture"), str(ap)))
  295. for geo_el in fcobj.apertures[ap]['geometry']:
  296. if self.app.abort_flag:
  297. # graceful abort requested by the user
  298. raise grace
  299. if 'solid' in geo_el and geo_el['solid'] is not None and geo_el['solid'].is_valid:
  300. total_geo.append(geo_el['solid'])
  301. app_obj.inform.emit(
  302. _("Optimal Tool. Creating a buffer for the object geometry."))
  303. total_geo = MultiPolygon(total_geo)
  304. total_geo = total_geo.buffer(0)
  305. try:
  306. __ = iter(total_geo)
  307. geo_len = len(total_geo)
  308. geo_len = (geo_len * (geo_len - 1)) / 2
  309. except TypeError:
  310. app_obj.inform.emit('[ERROR_NOTCL] %s' %
  311. _("The Gerber object has one Polygon as geometry.\n"
  312. "There are no distances between geometry elements to be found."))
  313. return 'fail'
  314. app_obj.inform.emit(
  315. '%s: %s' % (_("Optimal Tool. Finding the distances between each two elements. Iterations"),
  316. str(geo_len)))
  317. self.min_dict = {}
  318. idx = 1
  319. for geo in total_geo:
  320. for s_geo in total_geo[idx:]:
  321. if self.app.abort_flag:
  322. # graceful abort requested by the user
  323. raise grace
  324. # minimize the number of distances by not taking into considerations those that are too small
  325. dist = geo.distance(s_geo)
  326. dist = float('%.*f' % (self.decimals, dist))
  327. loc_1, loc_2 = nearest_points(geo, s_geo)
  328. proc_loc = (
  329. (float('%.*f' % (self.decimals, loc_1.x)), float('%.*f' % (self.decimals, loc_1.y))),
  330. (float('%.*f' % (self.decimals, loc_2.x)), float('%.*f' % (self.decimals, loc_2.y)))
  331. )
  332. if dist in self.min_dict:
  333. self.min_dict[dist].append(proc_loc)
  334. else:
  335. self.min_dict[dist] = [proc_loc]
  336. pol_nr += 1
  337. disp_number = int(np.interp(pol_nr, [0, geo_len], [0, 100]))
  338. if old_disp_number < disp_number <= 100:
  339. app_obj.proc_container.update_view_text(' %d%%' % disp_number)
  340. old_disp_number = disp_number
  341. idx += 1
  342. app_obj.inform.emit(
  343. _("Optimal Tool. Finding the minimum distance."))
  344. min_list = list(self.min_dict.keys())
  345. min_dist = min(min_list)
  346. min_dist_string = '%.*f' % (self.decimals, float(min_dist))
  347. self.result_entry.set_value(min_dist_string)
  348. freq = len(self.min_dict[min_dist])
  349. freq = '%d' % int(freq)
  350. self.freq_entry.set_value(freq)
  351. min_locations = self.min_dict.pop(min_dist)
  352. self.update_text.emit(min_locations)
  353. self.update_sec_distances.emit(self.min_dict)
  354. app_obj.inform.emit('[success] %s' % _("Optimal Tool. Finished successfully."))
  355. except Exception as ee:
  356. proc.done()
  357. log.debug(str(ee))
  358. return
  359. proc.done()
  360. self.app.worker_task.emit({'fcn': job_thread, 'params': [self.app]})
  361. def on_locate_position(self):
  362. # cursor = self.locations_textb.textCursor()
  363. # self.selected_text = cursor.selectedText()
  364. try:
  365. if self.selected_text != '':
  366. loc = eval(self.selected_text)
  367. else:
  368. return 'fail'
  369. except Exception as e:
  370. log.debug("ToolOptimal.on_locate_position() --> first try %s" % str(e))
  371. self.app.inform.emit("[ERROR_NOTCL] The selected text is no valid location in the format "
  372. "((x0, y0), (x1, y1)).")
  373. return
  374. try:
  375. loc_1 = loc[0]
  376. loc_2 = loc[1]
  377. dx = loc_1[0] - loc_2[0]
  378. dy = loc_1[1] - loc_2[1]
  379. loc = (float('%.*f' % (self.decimals, (min(loc_1[0], loc_2[0]) + (abs(dx) / 2)))),
  380. float('%.*f' % (self.decimals, (min(loc_1[1], loc_2[1]) + (abs(dy) / 2)))))
  381. self.app.on_jump_to(custom_location=loc)
  382. except Exception as e:
  383. log.debug("ToolOptimal.on_locate_position() --> sec try %s" % str(e))
  384. return
  385. def on_update_text(self, data):
  386. txt = ''
  387. for loc in data:
  388. if loc:
  389. txt += '%s, %s\n' % (str(loc[0]), str(loc[1]))
  390. self.locations_textb.setPlainText(txt)
  391. self.locate_button.setDisabled(False)
  392. def on_textbox_clicked(self):
  393. # new cursor - select all document
  394. cursor = self.locations_textb.textCursor()
  395. cursor.select(QtGui.QTextCursor.Document)
  396. # clear previous selection highlight
  397. tmp = cursor.blockFormat()
  398. tmp.clearBackground()
  399. cursor.setBlockFormat(tmp)
  400. # new cursor - select the current line
  401. cursor = self.locations_textb.textCursor()
  402. cursor.select(QtGui.QTextCursor.LineUnderCursor)
  403. # highlight the current selected line
  404. tmp = cursor.blockFormat()
  405. tmp.setBackground(QtGui.QBrush(QtCore.Qt.yellow))
  406. cursor.setBlockFormat(tmp)
  407. self.selected_text = cursor.selectedText()
  408. def on_update_sec_distances_txt(self, data):
  409. distance_list = sorted(list(data.keys()))
  410. txt = ''
  411. for loc in distance_list:
  412. txt += '%s\n' % str(loc)
  413. self.distances_textb.setPlainText(txt)
  414. self.locate_sec_button.setDisabled(False)
  415. def on_distances_textb_clicked(self):
  416. # new cursor - select all document
  417. cursor = self.distances_textb.textCursor()
  418. cursor.select(QtGui.QTextCursor.Document)
  419. # clear previous selection highlight
  420. tmp = cursor.blockFormat()
  421. tmp.clearBackground()
  422. cursor.setBlockFormat(tmp)
  423. # new cursor - select the current line
  424. cursor = self.distances_textb.textCursor()
  425. cursor.select(QtGui.QTextCursor.LineUnderCursor)
  426. # highlight the current selected line
  427. tmp = cursor.blockFormat()
  428. tmp.setBackground(QtGui.QBrush(QtCore.Qt.yellow))
  429. cursor.setBlockFormat(tmp)
  430. distance_text = cursor.selectedText()
  431. key_in_min_dict = eval(distance_text)
  432. self.on_update_locations_text(dist=key_in_min_dict)
  433. def on_update_locations_text(self, dist):
  434. distance_list = self.min_dict[dist]
  435. txt = ''
  436. for loc in distance_list:
  437. if loc:
  438. txt += '%s, %s\n' % (str(loc[0]), str(loc[1]))
  439. self.locations_sec_textb.setPlainText(txt)
  440. def on_locations_sec_clicked(self):
  441. # new cursor - select all document
  442. cursor = self.locations_sec_textb.textCursor()
  443. cursor.select(QtGui.QTextCursor.Document)
  444. # clear previous selection highlight
  445. tmp = cursor.blockFormat()
  446. tmp.clearBackground()
  447. cursor.setBlockFormat(tmp)
  448. # new cursor - select the current line
  449. cursor = self.locations_sec_textb.textCursor()
  450. cursor.select(QtGui.QTextCursor.LineUnderCursor)
  451. # highlight the current selected line
  452. tmp = cursor.blockFormat()
  453. tmp.setBackground(QtGui.QBrush(QtCore.Qt.yellow))
  454. cursor.setBlockFormat(tmp)
  455. self.selected_locations_text = cursor.selectedText()
  456. def on_locate_sec_position(self):
  457. try:
  458. if self.selected_locations_text != '':
  459. loc = eval(self.selected_locations_text)
  460. else:
  461. return
  462. except Exception as e:
  463. log.debug("ToolOptimal.on_locate_sec_position() --> first try %s" % str(e))
  464. self.app.inform.emit("[ERROR_NOTCL] The selected text is no valid location in the format "
  465. "((x0, y0), (x1, y1)).")
  466. return
  467. try:
  468. loc_1 = loc[0]
  469. loc_2 = loc[1]
  470. dx = loc_1[0] - loc_2[0]
  471. dy = loc_1[1] - loc_2[1]
  472. loc = (float('%.*f' % (self.decimals, (min(loc_1[0], loc_2[0]) + (abs(dx) / 2)))),
  473. float('%.*f' % (self.decimals, (min(loc_1[1], loc_2[1]) + (abs(dy) / 2)))))
  474. self.app.on_jump_to(custom_location=loc)
  475. except Exception as e:
  476. log.debug("ToolOptimal.on_locate_sec_position() --> sec try %s" % str(e))
  477. return
  478. def reset_fields(self):
  479. self.gerber_object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  480. self.gerber_object_combo.setCurrentIndex(0)