ToolPanelize.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. from FlatCAMTool import FlatCAMTool
  2. from copy import copy, deepcopy
  3. from ObjectCollection import *
  4. import time
  5. import gettext
  6. import FlatCAMTranslation as fcTranslate
  7. fcTranslate.apply_language('ToolPanelize')
  8. def _tr(text):
  9. try:
  10. return _(text)
  11. except:
  12. return text
  13. class Panelize(FlatCAMTool):
  14. toolName = _tr("Panelize PCB")
  15. def __init__(self, app):
  16. super(Panelize, self).__init__(self)
  17. self.app = app
  18. ## Title
  19. title_label = QtWidgets.QLabel("%s" % self.toolName)
  20. title_label.setStyleSheet("""
  21. QLabel
  22. {
  23. font-size: 16px;
  24. font-weight: bold;
  25. }
  26. """)
  27. self.layout.addWidget(title_label)
  28. ## Form Layout
  29. form_layout = QtWidgets.QFormLayout()
  30. self.layout.addLayout(form_layout)
  31. ## Type of object to be panelized
  32. self.type_obj_combo = QtWidgets.QComboBox()
  33. self.type_obj_combo.addItem("Gerber")
  34. self.type_obj_combo.addItem("Excellon")
  35. self.type_obj_combo.addItem("Geometry")
  36. self.type_obj_combo.setItemIcon(0, QtGui.QIcon("share/flatcam_icon16.png"))
  37. self.type_obj_combo.setItemIcon(1, QtGui.QIcon("share/drill16.png"))
  38. self.type_obj_combo.setItemIcon(2, QtGui.QIcon("share/geometry16.png"))
  39. self.type_obj_combo_label = QtWidgets.QLabel(_tr("Object Type:"))
  40. self.type_obj_combo_label.setToolTip(
  41. _tr("Specify the type of object to be panelized\n"
  42. "It can be of type: Gerber, Excellon or Geometry.\n"
  43. "The selection here decide the type of objects that will be\n"
  44. "in the Object combobox.")
  45. )
  46. form_layout.addRow(self.type_obj_combo_label, self.type_obj_combo)
  47. ## Object to be panelized
  48. self.object_combo = QtWidgets.QComboBox()
  49. self.object_combo.setModel(self.app.collection)
  50. self.object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  51. self.object_combo.setCurrentIndex(1)
  52. self.object_label = QtWidgets.QLabel(_tr("Object:"))
  53. self.object_label.setToolTip(
  54. _tr("Object to be panelized. This means that it will\n"
  55. "be duplicated in an array of rows and columns.")
  56. )
  57. form_layout.addRow(self.object_label, self.object_combo)
  58. ## Type of Box Object to be used as an envelope for panelization
  59. self.type_box_combo = QtWidgets.QComboBox()
  60. self.type_box_combo.addItem("Gerber")
  61. self.type_box_combo.addItem("Excellon")
  62. self.type_box_combo.addItem("Geometry")
  63. # we get rid of item1 ("Excellon") as it is not suitable for use as a "box" for panelizing
  64. self.type_box_combo.view().setRowHidden(1, True)
  65. self.type_box_combo.setItemIcon(0, QtGui.QIcon("share/flatcam_icon16.png"))
  66. self.type_box_combo.setItemIcon(2, QtGui.QIcon("share/geometry16.png"))
  67. self.type_box_combo_label = QtWidgets.QLabel(_tr("Box Type:"))
  68. self.type_box_combo_label.setToolTip(
  69. _tr("Specify the type of object to be used as an container for\n"
  70. "panelization. It can be: Gerber or Geometry type.\n"
  71. "The selection here decide the type of objects that will be\n"
  72. "in the Box Object combobox.")
  73. )
  74. form_layout.addRow(self.type_box_combo_label, self.type_box_combo)
  75. ## Box
  76. self.box_combo = QtWidgets.QComboBox()
  77. self.box_combo.setModel(self.app.collection)
  78. self.box_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  79. self.box_combo.setCurrentIndex(1)
  80. self.box_combo_label = QtWidgets.QLabel(_tr("Box Object:"))
  81. self.box_combo_label.setToolTip(
  82. _tr("The actual object that is used a container for the\n "
  83. "selected object that is to be panelized.")
  84. )
  85. form_layout.addRow(self.box_combo_label, self.box_combo)
  86. ## Spacing Columns
  87. self.spacing_columns = FCEntry()
  88. self.spacing_columns_label = QtWidgets.QLabel(_tr("Spacing cols:"))
  89. self.spacing_columns_label.setToolTip(
  90. _tr("Spacing between columns of the desired panel.\n"
  91. "In current units.")
  92. )
  93. form_layout.addRow(self.spacing_columns_label, self.spacing_columns)
  94. ## Spacing Rows
  95. self.spacing_rows = FCEntry()
  96. self.spacing_rows_label = QtWidgets.QLabel(_tr("Spacing rows:"))
  97. self.spacing_rows_label.setToolTip(
  98. _tr("Spacing between rows of the desired panel.\n"
  99. "In current units.")
  100. )
  101. form_layout.addRow(self.spacing_rows_label, self.spacing_rows)
  102. ## Columns
  103. self.columns = FCEntry()
  104. self.columns_label = QtWidgets.QLabel(_tr("Columns:"))
  105. self.columns_label.setToolTip(
  106. _tr("Number of columns of the desired panel")
  107. )
  108. form_layout.addRow(self.columns_label, self.columns)
  109. ## Rows
  110. self.rows = FCEntry()
  111. self.rows_label = QtWidgets.QLabel(_tr("Rows:"))
  112. self.rows_label.setToolTip(
  113. _tr("Number of rows of the desired panel")
  114. )
  115. form_layout.addRow(self.rows_label, self.rows)
  116. ## Type of resulting Panel object
  117. self.panel_type_radio = RadioSet([{'label': 'Gerber', 'value': 'gerber'},
  118. {'label': 'Geometry', 'value': 'geometry'}])
  119. self.panel_type_label = QtWidgets.QLabel(_tr("Panel Type:"))
  120. self.panel_type_label.setToolTip(
  121. _tr("Choose the type of object for the panel object:\n"
  122. "- Geometry\n"
  123. "- Gerber")
  124. )
  125. form_layout.addRow(self.panel_type_label)
  126. form_layout.addRow(self.panel_type_radio)
  127. ## Constrains
  128. self.constrain_cb = FCCheckBox(_tr("Constrain panel within:"))
  129. self.constrain_cb.setToolTip(
  130. _tr("Area define by DX and DY within to constrain the panel.\n"
  131. "DX and DY values are in current units.\n"
  132. "Regardless of how many columns and rows are desired,\n"
  133. "the final panel will have as many columns and rows as\n"
  134. "they fit completely within selected area.")
  135. )
  136. form_layout.addRow(self.constrain_cb)
  137. self.x_width_entry = FCEntry()
  138. self.x_width_lbl = QtWidgets.QLabel(_tr("Width (DX):"))
  139. self.x_width_lbl.setToolTip(
  140. _tr("The width (DX) within which the panel must fit.\n"
  141. "In current units.")
  142. )
  143. form_layout.addRow(self.x_width_lbl, self.x_width_entry)
  144. self.y_height_entry = FCEntry()
  145. self.y_height_lbl = QtWidgets.QLabel(_tr("Height (DY):"))
  146. self.y_height_lbl.setToolTip(
  147. _tr("The height (DY)within which the panel must fit.\n"
  148. "In current units.")
  149. )
  150. form_layout.addRow(self.y_height_lbl, self.y_height_entry)
  151. self.constrain_sel = OptionalInputSection(
  152. self.constrain_cb, [self.x_width_lbl, self.x_width_entry, self.y_height_lbl, self.y_height_entry])
  153. ## Buttons
  154. hlay_2 = QtWidgets.QHBoxLayout()
  155. self.layout.addLayout(hlay_2)
  156. hlay_2.addStretch()
  157. self.panelize_object_button = QtWidgets.QPushButton(_tr("Panelize Object"))
  158. self.panelize_object_button.setToolTip(
  159. _tr("Panelize the specified object around the specified box.\n"
  160. "In other words it creates multiple copies of the source object,\n"
  161. "arranged in a 2D array of rows and columns.")
  162. )
  163. hlay_2.addWidget(self.panelize_object_button)
  164. self.layout.addStretch()
  165. ## Signals
  166. self.panelize_object_button.clicked.connect(self.on_panelize)
  167. self.type_obj_combo.currentIndexChanged.connect(self.on_type_obj_index_changed)
  168. self.type_box_combo.currentIndexChanged.connect(self.on_type_box_index_changed)
  169. # list to hold the temporary objects
  170. self.objs = []
  171. # final name for the panel object
  172. self.outname = ""
  173. # flag to signal the constrain was activated
  174. self.constrain_flag = False
  175. def run(self, toggle=False):
  176. self.app.report_usage("ToolPanelize()")
  177. if toggle:
  178. # if the splitter is hidden, display it, else hide it but only if the current widget is the same
  179. if self.app.ui.splitter.sizes()[0] == 0:
  180. self.app.ui.splitter.setSizes([1, 1])
  181. else:
  182. try:
  183. if self.app.ui.tool_scroll_area.widget().objectName() == self.toolName:
  184. self.app.ui.splitter.setSizes([0, 1])
  185. except AttributeError:
  186. pass
  187. FlatCAMTool.run(self)
  188. self.set_tool_ui()
  189. self.app.ui.notebook.setTabText(2, "Panel. Tool")
  190. def install(self, icon=None, separator=None, **kwargs):
  191. FlatCAMTool.install(self, icon, separator, shortcut='ALT+Z', **kwargs)
  192. def set_tool_ui(self):
  193. self.reset_fields()
  194. sp_c = self.app.defaults["tools_panelize_spacing_columns"] if \
  195. self.app.defaults["tools_panelize_spacing_columns"] else 0.0
  196. self.spacing_columns.set_value(float(sp_c))
  197. sp_r = self.app.defaults["tools_panelize_spacing_rows"] if \
  198. self.app.defaults["tools_panelize_spacing_rows"] else 0.0
  199. self.spacing_rows.set_value(float(sp_r))
  200. rr = self.app.defaults["tools_panelize_rows"] if \
  201. self.app.defaults["tools_panelize_rows"] else 0.0
  202. self.rows.set_value(int(rr))
  203. cc = self.app.defaults["tools_panelize_columns"] if \
  204. self.app.defaults["tools_panelize_columns"] else 0.0
  205. self.columns.set_value(int(cc))
  206. c_cb = self.app.defaults["tools_panelize_constrain"] if \
  207. self.app.defaults["tools_panelize_constrain"] else False
  208. self.constrain_cb.set_value(c_cb)
  209. x_w = self.app.defaults["tools_panelize_constrainx"] if \
  210. self.app.defaults["tools_panelize_constrainx"] else 0.0
  211. self.x_width_entry.set_value(float(x_w))
  212. y_w = self.app.defaults["tools_panelize_constrainy"] if \
  213. self.app.defaults["tools_panelize_constrainy"] else 0.0
  214. self.y_height_entry.set_value(float(y_w))
  215. panel_type = self.app.defaults["tools_panelize_panel_type"] if \
  216. self.app.defaults["tools_panelize_panel_type"] else 'gerber'
  217. self.panel_type_radio.set_value(panel_type)
  218. def on_type_obj_index_changed(self):
  219. obj_type = self.type_obj_combo.currentIndex()
  220. self.object_combo.setRootModelIndex(self.app.collection.index(obj_type, 0, QtCore.QModelIndex()))
  221. self.object_combo.setCurrentIndex(0)
  222. def on_type_box_index_changed(self):
  223. obj_type = self.type_box_combo.currentIndex()
  224. self.box_combo.setRootModelIndex(self.app.collection.index(obj_type, 0, QtCore.QModelIndex()))
  225. self.box_combo.setCurrentIndex(0)
  226. def on_panelize(self):
  227. name = self.object_combo.currentText()
  228. # Get source object.
  229. try:
  230. obj = self.app.collection.get_by_name(str(name))
  231. except:
  232. self.app.inform.emit(_tr("[ERROR_NOTCL]Could not retrieve object: %s") % name)
  233. return "Could not retrieve object: %s" % name
  234. panel_obj = obj
  235. if panel_obj is None:
  236. self.app.inform.emit(_tr("[ERROR_NOTCL]Object not found: %s") % panel_obj)
  237. return "Object not found: %s" % panel_obj
  238. boxname = self.box_combo.currentText()
  239. try:
  240. box = self.app.collection.get_by_name(boxname)
  241. except:
  242. self.app.inform.emit(_tr("[ERROR_NOTCL]Could not retrieve object: %s") % boxname)
  243. return "Could not retrieve object: %s" % boxname
  244. if box is None:
  245. self.app.inform.emit(_tr("[WARNING]No object Box. Using instead %s") % panel_obj)
  246. box = panel_obj
  247. self.outname = name + '_panelized'
  248. try:
  249. spacing_columns = float(self.spacing_columns.get_value())
  250. except ValueError:
  251. # try to convert comma to decimal point. if it's still not working error message and return
  252. try:
  253. spacing_columns = float(self.spacing_columns.get_value().replace(',', '.'))
  254. except ValueError:
  255. self.app.inform.emit(_tr("[ERROR_NOTCL]Wrong value format entered, "
  256. "use a number."))
  257. return
  258. spacing_columns = spacing_columns if spacing_columns is not None else 0
  259. try:
  260. spacing_rows = float(self.spacing_rows.get_value())
  261. except ValueError:
  262. # try to convert comma to decimal point. if it's still not working error message and return
  263. try:
  264. spacing_rows = float(self.spacing_rows.get_value().replace(',', '.'))
  265. except ValueError:
  266. self.app.inform.emit(_tr("[ERROR_NOTCL]Wrong value format entered, "
  267. "use a number."))
  268. return
  269. spacing_rows = spacing_rows if spacing_rows is not None else 0
  270. try:
  271. rows = int(self.rows.get_value())
  272. except ValueError:
  273. # try to convert comma to decimal point. if it's still not working error message and return
  274. try:
  275. rows = float(self.rows.get_value().replace(',', '.'))
  276. rows = int(rows)
  277. except ValueError:
  278. self.app.inform.emit(_tr("[ERROR_NOTCL]Wrong value format entered, "
  279. "use a number."))
  280. return
  281. rows = rows if rows is not None else 1
  282. try:
  283. columns = int(self.columns.get_value())
  284. except ValueError:
  285. # try to convert comma to decimal point. if it's still not working error message and return
  286. try:
  287. columns = float(self.columns.get_value().replace(',', '.'))
  288. columns = int(columns)
  289. except ValueError:
  290. self.app.inform.emit(_tr("[ERROR_NOTCL]Wrong value format entered, "
  291. "use a number."))
  292. return
  293. columns = columns if columns is not None else 1
  294. try:
  295. constrain_dx = float(self.x_width_entry.get_value())
  296. except ValueError:
  297. # try to convert comma to decimal point. if it's still not working error message and return
  298. try:
  299. constrain_dx = float(self.x_width_entry.get_value().replace(',', '.'))
  300. except ValueError:
  301. self.app.inform.emit(_tr("[ERROR_NOTCL]Wrong value format entered, "
  302. "use a number."))
  303. return
  304. try:
  305. constrain_dy = float(self.y_height_entry.get_value())
  306. except ValueError:
  307. # try to convert comma to decimal point. if it's still not working error message and return
  308. try:
  309. constrain_dy = float(self.y_height_entry.get_value().replace(',', '.'))
  310. except ValueError:
  311. self.app.inform.emit(_tr("[ERROR_NOTCL]Wrong value format entered, "
  312. "use a number."))
  313. return
  314. panel_type = str(self.panel_type_radio.get_value())
  315. if 0 in {columns, rows}:
  316. self.app.inform.emit(_tr("[ERROR_NOTCL]Columns or Rows are zero value. Change them to a positive integer."))
  317. return "Columns or Rows are zero value. Change them to a positive integer."
  318. xmin, ymin, xmax, ymax = box.bounds()
  319. lenghtx = xmax - xmin + spacing_columns
  320. lenghty = ymax - ymin + spacing_rows
  321. # check if constrain within an area is desired
  322. if self.constrain_cb.isChecked():
  323. panel_lengthx = ((xmax - xmin) * columns) + (spacing_columns * (columns - 1))
  324. panel_lengthy = ((ymax - ymin) * rows) + (spacing_rows * (rows - 1))
  325. # adjust the number of columns and/or rows so the panel will fit within the panel constraint area
  326. if (panel_lengthx > constrain_dx) or (panel_lengthy > constrain_dy):
  327. self.constrain_flag = True
  328. while panel_lengthx > constrain_dx:
  329. columns -= 1
  330. panel_lengthx = ((xmax - xmin) * columns) + (spacing_columns * (columns - 1))
  331. while panel_lengthy > constrain_dy:
  332. rows -= 1
  333. panel_lengthy = ((ymax - ymin) * rows) + (spacing_rows * (rows - 1))
  334. # def clean_temp():
  335. # # deselect all to avoid delete selected object when run delete from shell
  336. # self.app.collection.set_all_inactive()
  337. #
  338. # for del_obj in self.objs:
  339. # self.app.collection.set_active(del_obj.options['name'])
  340. # self.app.on_delete()
  341. #
  342. # self.objs[:] = []
  343. # def panelize():
  344. # if panel_obj is not None:
  345. # self.app.inform.emit("Generating panel ... Please wait.")
  346. #
  347. # self.app.progress.emit(10)
  348. #
  349. # if isinstance(panel_obj, FlatCAMExcellon):
  350. # currenty = 0.0
  351. # self.app.progress.emit(0)
  352. #
  353. # def initialize_local_excellon(obj_init, app):
  354. # obj_init.tools = panel_obj.tools
  355. # # drills are offset, so they need to be deep copied
  356. # obj_init.drills = deepcopy(panel_obj.drills)
  357. # obj_init.offset([float(currentx), float(currenty)])
  358. # obj_init.create_geometry()
  359. # self.objs.append(obj_init)
  360. #
  361. # self.app.progress.emit(0)
  362. # for row in range(rows):
  363. # currentx = 0.0
  364. # for col in range(columns):
  365. # local_outname = self.outname + ".tmp." + str(col) + "." + str(row)
  366. # self.app.new_object("excellon", local_outname, initialize_local_excellon, plot=False,
  367. # autoselected=False)
  368. # currentx += lenghtx
  369. # currenty += lenghty
  370. # else:
  371. # currenty = 0
  372. # self.app.progress.emit(0)
  373. #
  374. # def initialize_local_geometry(obj_init, app):
  375. # obj_init.solid_geometry = panel_obj.solid_geometry
  376. # obj_init.offset([float(currentx), float(currenty)])
  377. # self.objs.append(obj_init)
  378. #
  379. # self.app.progress.emit(0)
  380. # for row in range(rows):
  381. # currentx = 0
  382. #
  383. # for col in range(columns):
  384. # local_outname = self.outname + ".tmp." + str(col) + "." + str(row)
  385. # self.app.new_object("geometry", local_outname, initialize_local_geometry, plot=False,
  386. # autoselected=False)
  387. # currentx += lenghtx
  388. # currenty += lenghty
  389. #
  390. # def job_init_geometry(obj_fin, app_obj):
  391. # FlatCAMGeometry.merge(self.objs, obj_fin)
  392. #
  393. # def job_init_excellon(obj_fin, app_obj):
  394. # # merge expects tools to exist in the target object
  395. # obj_fin.tools = panel_obj.tools.copy()
  396. # FlatCAMExcellon.merge(self.objs, obj_fin)
  397. #
  398. # if isinstance(panel_obj, FlatCAMExcellon):
  399. # self.app.progress.emit(50)
  400. # self.app.new_object("excellon", self.outname, job_init_excellon, plot=True, autoselected=True)
  401. # else:
  402. # self.app.progress.emit(50)
  403. # self.app.new_object("geometry", self.outname, job_init_geometry, plot=True, autoselected=True)
  404. #
  405. # else:
  406. # self.app.inform.emit("[ERROR_NOTCL] Obj is None")
  407. # return "ERROR: Obj is None"
  408. # panelize()
  409. # clean_temp()
  410. def panelize_2():
  411. if panel_obj is not None:
  412. self.app.inform.emit(_tr("Generating panel ... Please wait."))
  413. self.app.progress.emit(0)
  414. def job_init_excellon(obj_fin, app_obj):
  415. currenty = 0.0
  416. self.app.progress.emit(10)
  417. obj_fin.tools = panel_obj.tools.copy()
  418. obj_fin.drills = []
  419. obj_fin.slots = []
  420. obj_fin.solid_geometry = []
  421. for option in panel_obj.options:
  422. if option is not 'name':
  423. try:
  424. obj_fin.options[option] = panel_obj.options[option]
  425. except:
  426. log.warning("Failed to copy option.", option)
  427. for row in range(rows):
  428. currentx = 0.0
  429. for col in range(columns):
  430. if panel_obj.drills:
  431. for tool_dict in panel_obj.drills:
  432. point_offseted = affinity.translate(tool_dict['point'], currentx, currenty)
  433. obj_fin.drills.append(
  434. {
  435. "point": point_offseted,
  436. "tool": tool_dict['tool']
  437. }
  438. )
  439. if panel_obj.slots:
  440. for tool_dict in panel_obj.slots:
  441. start_offseted = affinity.translate(tool_dict['start'], currentx, currenty)
  442. stop_offseted = affinity.translate(tool_dict['stop'], currentx, currenty)
  443. obj_fin.slots.append(
  444. {
  445. "start": start_offseted,
  446. "stop": stop_offseted,
  447. "tool": tool_dict['tool']
  448. }
  449. )
  450. currentx += lenghtx
  451. currenty += lenghty
  452. obj_fin.create_geometry()
  453. obj_fin.zeros = panel_obj.zeros
  454. obj_fin.units = panel_obj.units
  455. def job_init_geometry(obj_fin, app_obj):
  456. currentx = 0.0
  457. currenty = 0.0
  458. def translate_recursion(geom):
  459. if type(geom) == list:
  460. geoms = list()
  461. for local_geom in geom:
  462. geoms.append(translate_recursion(local_geom))
  463. return geoms
  464. else:
  465. return affinity.translate(geom, xoff=currentx, yoff=currenty)
  466. obj_fin.solid_geometry = []
  467. if isinstance(panel_obj, FlatCAMGeometry):
  468. obj_fin.multigeo = panel_obj.multigeo
  469. obj_fin.tools = deepcopy(panel_obj.tools)
  470. if panel_obj.multigeo is True:
  471. for tool in panel_obj.tools:
  472. obj_fin.tools[tool]['solid_geometry'][:] = []
  473. self.app.progress.emit(0)
  474. for row in range(rows):
  475. currentx = 0.0
  476. for col in range(columns):
  477. if isinstance(panel_obj, FlatCAMGeometry):
  478. if panel_obj.multigeo is True:
  479. for tool in panel_obj.tools:
  480. obj_fin.tools[tool]['solid_geometry'].append(translate_recursion(
  481. panel_obj.tools[tool]['solid_geometry'])
  482. )
  483. else:
  484. obj_fin.solid_geometry.append(
  485. translate_recursion(panel_obj.solid_geometry)
  486. )
  487. else:
  488. obj_fin.solid_geometry.append(
  489. translate_recursion(panel_obj.solid_geometry)
  490. )
  491. currentx += lenghtx
  492. currenty += lenghty
  493. if isinstance(panel_obj, FlatCAMExcellon):
  494. self.app.progress.emit(50)
  495. self.app.new_object("excellon", self.outname, job_init_excellon, plot=True, autoselected=True)
  496. else:
  497. self.app.progress.emit(50)
  498. self.app.new_object(panel_type, self.outname, job_init_geometry,
  499. plot=True, autoselected=True)
  500. if self.constrain_flag is False:
  501. self.app.inform.emit(_tr("[success]Panel done..."))
  502. else:
  503. self.constrain_flag = False
  504. self.app.inform.emit(_tr("[WARNING] Too big for the constrain area. Final panel has %s columns and %s rows") %
  505. (columns, rows))
  506. proc = self.app.proc_container.new(_tr("Generating panel ... Please wait."))
  507. def job_thread(app_obj):
  508. try:
  509. panelize_2()
  510. self.app.inform.emit(_tr("[success]Panel created successfully."))
  511. except Exception as e:
  512. proc.done()
  513. log.debug(str(e))
  514. return
  515. proc.done()
  516. self.app.collection.promise(self.outname)
  517. self.app.worker_task.emit({'fcn': job_thread, 'params': [self.app]})
  518. def reset_fields(self):
  519. self.object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  520. self.box_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))