ToolOptimal.py 24 KB

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