ToolFilm.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. from FlatCAMTool import FlatCAMTool
  2. from GUIElements import RadioSet, FloatEntry
  3. from PyQt5 import QtGui, QtCore, QtWidgets
  4. class Film(FlatCAMTool):
  5. toolName = "Film PCB Tool"
  6. def __init__(self, app):
  7. FlatCAMTool.__init__(self, app)
  8. # Title
  9. title_label = QtWidgets.QLabel("<font size=4><b>%s</b></font>" % self.toolName)
  10. self.layout.addWidget(title_label)
  11. # Form Layout
  12. tf_form_layout = QtWidgets.QFormLayout()
  13. self.layout.addLayout(tf_form_layout)
  14. # Type of object for which to create the film
  15. self.tf_type_obj_combo = QtWidgets.QComboBox()
  16. self.tf_type_obj_combo.addItem("Gerber")
  17. self.tf_type_obj_combo.addItem("Excellon")
  18. self.tf_type_obj_combo.addItem("Geometry")
  19. # we get rid of item1 ("Excellon") as it is not suitable for creating film
  20. self.tf_type_obj_combo.view().setRowHidden(1, True)
  21. self.tf_type_obj_combo.setItemIcon(0, QtGui.QIcon("share/flatcam_icon16.png"))
  22. self.tf_type_obj_combo.setItemIcon(2, QtGui.QIcon("share/geometry16.png"))
  23. self.tf_type_obj_combo_label = QtWidgets.QLabel("Object Type:")
  24. self.tf_type_obj_combo_label.setToolTip(
  25. "Specify the type of object for which to create the film.\n"
  26. "The object can be of type: Gerber or Geometry.\n"
  27. "The selection here decide the type of objects that will be\n"
  28. "in the Film Object combobox."
  29. )
  30. tf_form_layout.addRow(self.tf_type_obj_combo_label, self.tf_type_obj_combo)
  31. # List of objects for which we can create the film
  32. self.tf_object_combo = QtWidgets.QComboBox()
  33. self.tf_object_combo.setModel(self.app.collection)
  34. self.tf_object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  35. self.tf_object_combo.setCurrentIndex(1)
  36. self.tf_object_label = QtWidgets.QLabel("Film Object:")
  37. self.tf_object_label.setToolTip(
  38. "Object for which to create the film."
  39. )
  40. tf_form_layout.addRow(self.tf_object_label, self.tf_object_combo)
  41. # Type of Box Object to be used as an envelope for film creation
  42. # Within this we can create negative
  43. self.tf_type_box_combo = QtWidgets.QComboBox()
  44. self.tf_type_box_combo.addItem("Gerber")
  45. self.tf_type_box_combo.addItem("Excellon")
  46. self.tf_type_box_combo.addItem("Geometry")
  47. # we get rid of item1 ("Excellon") as it is not suitable for box when creating film
  48. self.tf_type_box_combo.view().setRowHidden(1, True)
  49. self.tf_type_box_combo.setItemIcon(0, QtGui.QIcon("share/flatcam_icon16.png"))
  50. self.tf_type_box_combo.setItemIcon(2, QtGui.QIcon("share/geometry16.png"))
  51. self.tf_type_box_combo_label = QtWidgets.QLabel("Box Type:")
  52. self.tf_type_box_combo_label.setToolTip(
  53. "Specify the type of object to be used as an container for\n"
  54. "film creation. It can be: Gerber or Geometry type."
  55. "The selection here decide the type of objects that will be\n"
  56. "in the Box Object combobox."
  57. )
  58. tf_form_layout.addRow(self.tf_type_box_combo_label, self.tf_type_box_combo)
  59. # Box
  60. self.tf_box_combo = QtWidgets.QComboBox()
  61. self.tf_box_combo.setModel(self.app.collection)
  62. self.tf_box_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  63. self.tf_box_combo.setCurrentIndex(1)
  64. self.tf_box_combo_label = QtWidgets.QLabel("Box Object:")
  65. self.tf_box_combo_label.setToolTip(
  66. "The actual object that is used a container for the\n "
  67. "selected object for which we create the film.\n"
  68. "Usually it is the PCB outline but it can be also the\n"
  69. "same object for which the film is created.")
  70. tf_form_layout.addRow(self.tf_box_combo_label, self.tf_box_combo)
  71. # Film Type
  72. self.film_type = RadioSet([{'label': 'Positive', 'value': 'pos'},
  73. {'label': 'Negative', 'value': 'neg'}])
  74. self.film_type_label = QtWidgets.QLabel("Film Type:")
  75. self.film_type_label.setToolTip(
  76. "Generate a Positive black film or a Negative film.\n"
  77. "Positive means that it will print the features\n"
  78. "with black on a white canvas.\n"
  79. "Negative means that it will print the features\n"
  80. "with white on a black canvas.\n"
  81. "The Film format is SVG."
  82. )
  83. tf_form_layout.addRow(self.film_type_label, self.film_type)
  84. # Boundary for negative film generation
  85. self.boundary_entry = FloatEntry()
  86. self.boundary_label = QtWidgets.QLabel("Border:")
  87. self.boundary_label.setToolTip(
  88. "Specify a border around the object.\n"
  89. "Only for negative film.\n"
  90. "It helps if we use as a Box Object the same \n"
  91. "object as in Film Object. It will create a thick\n"
  92. "black bar around the actual print allowing for a\n"
  93. "better delimitation of the outline features which are of\n"
  94. "white color like the rest and which may confound with the\n"
  95. "surroundings if not for this border."
  96. )
  97. tf_form_layout.addRow(self.boundary_label, self.boundary_entry)
  98. # Buttons
  99. hlay = QtWidgets.QHBoxLayout()
  100. self.layout.addLayout(hlay)
  101. hlay.addStretch()
  102. self.film_object_button = QtWidgets.QPushButton("Save Film")
  103. self.film_object_button.setToolTip(
  104. "Create a Film for the selected object, within\n"
  105. "the specified box. Does not create a new \n "
  106. "FlatCAM object, but directly save it in SVG format\n"
  107. "which can be opened with Inkscape."
  108. )
  109. hlay.addWidget(self.film_object_button)
  110. self.layout.addStretch()
  111. ## Signals
  112. self.film_object_button.clicked.connect(self.on_film_creation)
  113. self.tf_type_obj_combo.currentIndexChanged.connect(self.on_type_obj_index_changed)
  114. self.tf_type_box_combo.currentIndexChanged.connect(self.on_type_box_index_changed)
  115. ## Initialize form
  116. self.film_type.set_value('neg')
  117. self.boundary_entry.set_value(0.0)
  118. def on_type_obj_index_changed(self, index):
  119. obj_type = self.tf_type_obj_combo.currentIndex()
  120. self.tf_object_combo.setRootModelIndex(self.app.collection.index(obj_type, 0, QtCore.QModelIndex()))
  121. self.tf_object_combo.setCurrentIndex(0)
  122. def on_type_box_index_changed(self, index):
  123. obj_type = self.tf_type_box_combo.currentIndex()
  124. self.tf_box_combo.setRootModelIndex(self.app.collection.index(obj_type, 0, QtCore.QModelIndex()))
  125. self.tf_box_combo.setCurrentIndex(0)
  126. def run(self):
  127. FlatCAMTool.run(self)
  128. self.app.ui.notebook.setTabText(2, "Film Tool")
  129. def on_film_creation(self):
  130. try:
  131. name = self.tf_object_combo.currentText()
  132. except:
  133. self.app.inform.emit("[error_notcl] No Film object selected. Load a Film object and retry.")
  134. return
  135. try:
  136. boxname = self.tf_box_combo.currentText()
  137. except:
  138. self.app.inform.emit("[error_notcl] No Box object selected. Load a Box object and retry.")
  139. return
  140. border = float(self.boundary_entry.get_value())
  141. if border is None:
  142. border = 0
  143. self.app.inform.emit("Generating Film ...")
  144. if self.film_type.get_value() == "pos":
  145. try:
  146. filename, _ = QtWidgets.QFileDialog.getSaveFileName(caption="Export SVG positive",
  147. directory=self.app.get_last_save_folder(), filter="*.svg")
  148. except TypeError:
  149. filename, _ = QtWidgets.QFileDialog.getSaveFileName(caption="Export SVG positive")
  150. filename = str(filename)
  151. if str(filename) == "":
  152. self.app.inform.emit("Export SVG positive cancelled.")
  153. return
  154. else:
  155. self.app.export_svg_black(name, boxname, filename)
  156. else:
  157. try:
  158. filename, _ = QtWidgets.QFileDialog.getSaveFileName(caption="Export SVG negative",
  159. directory=self.app.get_last_save_folder(), filter="*.svg")
  160. except TypeError:
  161. filename, _ = QtWidgets.QFileDialog.getSaveFileName(caption="Export SVG negative")
  162. filename = str(filename)
  163. if str(filename) == "":
  164. self.app.inform.emit("Export SVG negative cancelled.")
  165. return
  166. else:
  167. self.app.export_svg_negative(name, boxname, filename, border)
  168. def reset_fields(self):
  169. self.tf_object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
  170. self.tf_box_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))