ToolPanelize.py 29 KB

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