2016-09-22 14:17:51 +00:00
|
|
|
############################################################
|
|
|
|
# FlatCAM: 2D Post-processing for Manufacturing #
|
|
|
|
# http://flatcam.org #
|
|
|
|
# Author: Juan Pablo Caram (c) #
|
|
|
|
# Date: 2/5/2014 #
|
|
|
|
# MIT Licence #
|
|
|
|
############################################################
|
|
|
|
|
2016-06-04 02:19:47 +00:00
|
|
|
from cStringIO import StringIO
|
2014-06-13 19:21:11 +00:00
|
|
|
from PyQt4 import QtCore
|
2015-10-04 00:03:53 +00:00
|
|
|
from copy import copy
|
2014-06-13 19:21:11 +00:00
|
|
|
from ObjectUI import *
|
2014-05-03 02:10:04 +00:00
|
|
|
import FlatCAMApp
|
2014-06-13 19:21:11 +00:00
|
|
|
import inspect # TODO: For debugging only.
|
2014-03-28 22:14:21 +00:00
|
|
|
from camlib import *
|
2014-06-13 19:21:11 +00:00
|
|
|
from FlatCAMCommon import LoudDict
|
2014-10-28 21:39:38 +00:00
|
|
|
from FlatCAMDraw import FlatCAMDraw
|
2014-03-28 22:14:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
########################################
|
|
|
|
## FlatCAMObj ##
|
|
|
|
########################################
|
2014-06-13 19:21:11 +00:00
|
|
|
class FlatCAMObj(QtCore.QObject):
|
2014-03-28 22:14:21 +00:00
|
|
|
"""
|
|
|
|
Base type of objects handled in FlatCAM. These become interactive
|
|
|
|
in the GUI, can be plotted, and their options can be modified
|
|
|
|
by the user in their respective forms.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Instance of the application to which these are related.
|
|
|
|
# The app should set this value.
|
|
|
|
app = None
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
def __init__(self, name):
|
2014-04-25 05:24:03 +00:00
|
|
|
"""
|
2016-07-03 19:59:25 +00:00
|
|
|
Constructor.
|
2014-04-25 05:24:03 +00:00
|
|
|
|
|
|
|
:param name: Name of the object given by the user.
|
|
|
|
:return: FlatCAMObj
|
|
|
|
"""
|
2014-06-13 19:21:11 +00:00
|
|
|
QtCore.QObject.__init__(self)
|
2014-04-04 15:41:03 +00:00
|
|
|
|
2014-04-25 05:24:03 +00:00
|
|
|
# View
|
2014-06-13 19:21:11 +00:00
|
|
|
self.ui = None
|
2014-04-25 05:24:03 +00:00
|
|
|
|
|
|
|
self.options = LoudDict(name=name)
|
|
|
|
self.options.set_change_callback(self.on_options_change)
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
self.form_fields = {}
|
|
|
|
|
2014-03-28 22:14:21 +00:00
|
|
|
self.axes = None # Matplotlib axes
|
|
|
|
self.kind = None # Override with proper name
|
|
|
|
|
2014-04-25 05:24:03 +00:00
|
|
|
self.muted_ui = False
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
# assert isinstance(self.ui, ObjectUI)
|
|
|
|
# self.ui.name_entry.returnPressed.connect(self.on_name_activate)
|
|
|
|
# self.ui.offset_button.clicked.connect(self.on_offset_button_click)
|
|
|
|
# self.ui.scale_button.clicked.connect(self.on_scale_button_click)
|
|
|
|
|
2016-07-02 21:36:19 +00:00
|
|
|
def from_dict(self, d):
|
|
|
|
"""
|
|
|
|
This supersedes ``from_dict`` in derived classes. Derived classes
|
|
|
|
must inherit from FlatCAMObj first, then from derivatives of Geometry.
|
|
|
|
|
|
|
|
``self.options`` is only updated, not overwritten. This ensures that
|
|
|
|
options set by the app do not vanish when reading the objects
|
|
|
|
from a project file.
|
2016-07-03 19:59:25 +00:00
|
|
|
|
|
|
|
:param d: Dictionary with attributes to set.
|
|
|
|
:return: None
|
2016-07-02 21:36:19 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
for attr in self.ser_attrs:
|
|
|
|
|
|
|
|
if attr == 'options':
|
|
|
|
self.options.update(d[attr])
|
|
|
|
else:
|
|
|
|
setattr(self, attr, d[attr])
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
def on_options_change(self, key):
|
|
|
|
self.emit(QtCore.SIGNAL("optionChanged"), key)
|
|
|
|
|
|
|
|
def set_ui(self, ui):
|
|
|
|
self.ui = ui
|
|
|
|
|
|
|
|
self.form_fields = {"name": self.ui.name_entry}
|
|
|
|
|
|
|
|
assert isinstance(self.ui, ObjectUI)
|
|
|
|
self.ui.name_entry.returnPressed.connect(self.on_name_activate)
|
|
|
|
self.ui.offset_button.clicked.connect(self.on_offset_button_click)
|
|
|
|
self.ui.scale_button.clicked.connect(self.on_scale_button_click)
|
2014-04-25 05:24:03 +00:00
|
|
|
|
2014-04-05 04:36:23 +00:00
|
|
|
def __str__(self):
|
|
|
|
return "<FlatCAMObj({:12s}): {:20s}>".format(self.kind, self.options["name"])
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
def on_name_activate(self):
|
2014-04-25 05:24:03 +00:00
|
|
|
old_name = copy(self.options["name"])
|
2014-06-13 19:21:11 +00:00
|
|
|
new_name = self.ui.name_entry.get_value()
|
|
|
|
self.options["name"] = self.ui.name_entry.get_value()
|
2014-04-25 05:24:03 +00:00
|
|
|
self.app.info("Name changed from %s to %s" % (old_name, new_name))
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
def on_offset_button_click(self):
|
2014-10-13 22:16:43 +00:00
|
|
|
self.app.report_usage("obj_on_offset_button")
|
|
|
|
|
2014-04-25 05:24:03 +00:00
|
|
|
self.read_form()
|
|
|
|
vect = self.ui.offsetvector_entry.get_value()
|
|
|
|
self.offset(vect)
|
|
|
|
self.plot()
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
def on_scale_button_click(self):
|
2014-10-13 22:16:43 +00:00
|
|
|
self.app.report_usage("obj_on_scale_button")
|
2014-04-25 05:24:03 +00:00
|
|
|
self.read_form()
|
|
|
|
factor = self.ui.scale_entry.get_value()
|
|
|
|
self.scale(factor)
|
|
|
|
self.plot()
|
|
|
|
|
2014-03-28 22:14:21 +00:00
|
|
|
def setup_axes(self, figure):
|
|
|
|
"""
|
|
|
|
1) Creates axes if they don't exist. 2) Clears axes. 3) Attaches
|
|
|
|
them to figure if not part of the figure. 4) Sets transparent
|
|
|
|
background. 5) Sets 1:1 scale aspect ratio.
|
|
|
|
|
|
|
|
:param figure: A Matplotlib.Figure on which to add/configure axes.
|
|
|
|
:type figure: matplotlib.figure.Figure
|
|
|
|
:return: None
|
|
|
|
:rtype: None
|
|
|
|
"""
|
|
|
|
|
|
|
|
if self.axes is None:
|
2014-05-03 02:10:04 +00:00
|
|
|
FlatCAMApp.App.log.debug("setup_axes(): New axes")
|
2014-03-28 22:14:21 +00:00
|
|
|
self.axes = figure.add_axes([0.05, 0.05, 0.9, 0.9],
|
|
|
|
label=self.options["name"])
|
|
|
|
elif self.axes not in figure.axes:
|
2014-05-03 02:10:04 +00:00
|
|
|
FlatCAMApp.App.log.debug("setup_axes(): Clearing and attaching axes")
|
2014-03-28 22:14:21 +00:00
|
|
|
self.axes.cla()
|
|
|
|
figure.add_axes(self.axes)
|
|
|
|
else:
|
2014-05-03 02:10:04 +00:00
|
|
|
FlatCAMApp.App.log.debug("setup_axes(): Clearing Axes")
|
2014-03-28 22:14:21 +00:00
|
|
|
self.axes.cla()
|
|
|
|
|
|
|
|
# Remove all decoration. The app's axes will have
|
|
|
|
# the ticks and grid.
|
|
|
|
self.axes.set_frame_on(False) # No frame
|
|
|
|
self.axes.set_xticks([]) # No tick
|
|
|
|
self.axes.set_yticks([]) # No ticks
|
|
|
|
self.axes.patch.set_visible(False) # No background
|
|
|
|
self.axes.set_aspect(1)
|
|
|
|
|
|
|
|
def to_form(self):
|
|
|
|
"""
|
|
|
|
Copies options to the UI form.
|
|
|
|
|
|
|
|
:return: None
|
|
|
|
"""
|
2016-02-23 11:21:57 +00:00
|
|
|
FlatCAMApp.App.log.debug(str(inspect.stack()[1][3]) + "--> FlatCAMObj.to_form()")
|
2014-03-28 22:14:21 +00:00
|
|
|
for option in self.options:
|
2016-02-23 11:21:57 +00:00
|
|
|
try:
|
|
|
|
self.set_form_item(option)
|
|
|
|
except:
|
|
|
|
self.app.log.warning("Unexpected error:", sys.exc_info())
|
2014-03-28 22:14:21 +00:00
|
|
|
|
|
|
|
def read_form(self):
|
|
|
|
"""
|
|
|
|
Reads form into ``self.options``.
|
|
|
|
|
|
|
|
:return: None
|
|
|
|
:rtype: None
|
|
|
|
"""
|
2014-05-03 02:10:04 +00:00
|
|
|
FlatCAMApp.App.log.debug(str(inspect.stack()[1][3]) + "--> FlatCAMObj.read_form()")
|
2014-03-28 22:14:21 +00:00
|
|
|
for option in self.options:
|
2016-02-23 11:21:57 +00:00
|
|
|
try:
|
|
|
|
self.read_form_item(option)
|
|
|
|
except:
|
|
|
|
self.app.log.warning("Unexpected error:", sys.exc_info())
|
|
|
|
|
2014-03-28 22:14:21 +00:00
|
|
|
def build_ui(self):
|
|
|
|
"""
|
2015-10-31 22:58:46 +00:00
|
|
|
Sets up the UI/form for this object. Show the UI
|
|
|
|
in the App.
|
2014-03-28 22:14:21 +00:00
|
|
|
|
|
|
|
:return: None
|
|
|
|
:rtype: None
|
|
|
|
"""
|
|
|
|
|
2014-04-25 05:24:03 +00:00
|
|
|
self.muted_ui = True
|
2014-05-03 02:10:04 +00:00
|
|
|
FlatCAMApp.App.log.debug(str(inspect.stack()[1][3]) + "--> FlatCAMObj.build_ui()")
|
2014-04-25 05:24:03 +00:00
|
|
|
|
2014-03-28 22:14:21 +00:00
|
|
|
# Remove anything else in the box
|
2014-06-13 19:21:11 +00:00
|
|
|
# box_children = self.app.ui.notebook.selected_contents.get_children()
|
|
|
|
# for child in box_children:
|
|
|
|
# self.app.ui.notebook.selected_contents.remove(child)
|
|
|
|
# while self.app.ui.selected_layout.count():
|
|
|
|
# self.app.ui.selected_layout.takeAt(0)
|
2014-03-28 22:14:21 +00:00
|
|
|
|
|
|
|
# Put in the UI
|
2014-04-25 05:24:03 +00:00
|
|
|
# box_selected.pack_start(sw, True, True, 0)
|
2014-06-13 19:21:11 +00:00
|
|
|
# self.app.ui.notebook.selected_contents.add(self.ui)
|
|
|
|
# self.app.ui.selected_layout.addWidget(self.ui)
|
|
|
|
try:
|
|
|
|
self.app.ui.selected_scroll_area.takeWidget()
|
|
|
|
except:
|
|
|
|
self.app.log.debug("Nothing to remove")
|
|
|
|
self.app.ui.selected_scroll_area.setWidget(self.ui)
|
2014-03-28 22:14:21 +00:00
|
|
|
self.to_form()
|
2014-06-13 19:21:11 +00:00
|
|
|
|
2014-04-25 05:24:03 +00:00
|
|
|
self.muted_ui = False
|
2014-03-28 22:14:21 +00:00
|
|
|
|
|
|
|
def set_form_item(self, option):
|
|
|
|
"""
|
|
|
|
Copies the specified option to the UI form.
|
|
|
|
|
|
|
|
:param option: Name of the option (Key in ``self.options``).
|
|
|
|
:type option: str
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
|
2014-04-25 05:24:03 +00:00
|
|
|
try:
|
|
|
|
self.form_fields[option].set_value(self.options[option])
|
|
|
|
except KeyError:
|
2014-05-03 02:10:04 +00:00
|
|
|
self.app.log.warn("Tried to set an option or field that does not exist: %s" % option)
|
2014-03-28 22:14:21 +00:00
|
|
|
|
|
|
|
def read_form_item(self, option):
|
|
|
|
"""
|
|
|
|
Reads the specified option from the UI form into ``self.options``.
|
|
|
|
|
|
|
|
:param option: Name of the option.
|
|
|
|
:type option: str
|
|
|
|
:return: None
|
|
|
|
"""
|
2016-02-29 18:59:20 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
self.options[option] = self.form_fields[option].get_value()
|
|
|
|
except KeyError:
|
|
|
|
self.app.log.warning("Failed to read option from field: %s" % option)
|
|
|
|
|
|
|
|
# #try read field only when option have equivalent in form_fields
|
|
|
|
# if option in self.form_fields:
|
|
|
|
# option_type=type(self.options[option])
|
|
|
|
# try:
|
|
|
|
# value=self.form_fields[option].get_value()
|
|
|
|
# #catch per option as it was ignored anyway, also when syntax error (probably uninitialized field),don't read either.
|
|
|
|
# except (KeyError,SyntaxError):
|
|
|
|
# self.app.log.warning("Failed to read option from field: %s" % option)
|
|
|
|
# else:
|
|
|
|
# self.app.log.warning("Form fied does not exists: %s" % option)
|
2014-03-28 22:14:21 +00:00
|
|
|
|
|
|
|
def plot(self):
|
|
|
|
"""
|
|
|
|
Plot this object (Extend this method to implement the actual plotting).
|
|
|
|
Axes get created, appended to canvas and cleared before plotting.
|
|
|
|
Call this in descendants before doing the plotting.
|
|
|
|
|
|
|
|
:return: Whether to continue plotting or not depending on the "plot" option.
|
|
|
|
:rtype: bool
|
|
|
|
"""
|
2014-06-13 19:21:11 +00:00
|
|
|
FlatCAMApp.App.log.debug(str(inspect.stack()[1][3]) + " --> FlatCAMObj.plot()")
|
2014-03-28 22:14:21 +00:00
|
|
|
|
|
|
|
# Axes must exist and be attached to canvas.
|
|
|
|
if self.axes is None or self.axes not in self.app.plotcanvas.figure.axes:
|
|
|
|
self.axes = self.app.plotcanvas.new_axes(self.options['name'])
|
|
|
|
|
|
|
|
if not self.options["plot"]:
|
|
|
|
self.axes.cla()
|
|
|
|
self.app.plotcanvas.auto_adjust_axes()
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Clear axes or we will plot on top of them.
|
2014-06-13 19:21:11 +00:00
|
|
|
self.axes.cla() # TODO: Thread safe?
|
2014-03-28 22:14:21 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
def serialize(self):
|
|
|
|
"""
|
|
|
|
Returns a representation of the object as a dictionary so
|
|
|
|
it can be later exported as JSON. Override this method.
|
|
|
|
|
|
|
|
:return: Dictionary representing the object
|
|
|
|
:rtype: dict
|
|
|
|
"""
|
|
|
|
return
|
|
|
|
|
|
|
|
def deserialize(self, obj_dict):
|
|
|
|
"""
|
|
|
|
Re-builds an object from its serialized version.
|
|
|
|
|
|
|
|
:param obj_dict: Dictionary representing a FlatCAMObj
|
|
|
|
:type obj_dict: dict
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
class FlatCAMGerber(FlatCAMObj, Gerber):
|
|
|
|
"""
|
|
|
|
Represents Gerber code.
|
|
|
|
"""
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
ui_type = GerberObjectUI
|
|
|
|
|
2014-03-28 22:14:21 +00:00
|
|
|
def __init__(self, name):
|
|
|
|
Gerber.__init__(self)
|
2014-06-13 19:21:11 +00:00
|
|
|
FlatCAMObj.__init__(self, name)
|
2014-03-28 22:14:21 +00:00
|
|
|
|
|
|
|
self.kind = "gerber"
|
|
|
|
|
|
|
|
# The 'name' is already in self.options from FlatCAMObj
|
2014-04-25 05:24:03 +00:00
|
|
|
# Automatically updates the UI
|
2014-03-28 22:14:21 +00:00
|
|
|
self.options.update({
|
|
|
|
"plot": True,
|
|
|
|
"multicolored": False,
|
|
|
|
"solid": False,
|
|
|
|
"isotooldia": 0.016,
|
|
|
|
"isopasses": 1,
|
|
|
|
"isooverlap": 0.15,
|
2015-05-26 23:48:09 +00:00
|
|
|
"combine_passes": True,
|
2014-03-28 22:14:21 +00:00
|
|
|
"cutouttooldia": 0.07,
|
|
|
|
"cutoutmargin": 0.2,
|
|
|
|
"cutoutgapsize": 0.15,
|
|
|
|
"gaps": "tb",
|
|
|
|
"noncoppermargin": 0.0,
|
|
|
|
"noncopperrounded": False,
|
|
|
|
"bboxmargin": 0.0,
|
|
|
|
"bboxrounded": False
|
|
|
|
})
|
|
|
|
|
|
|
|
# Attributes to be included in serialization
|
|
|
|
# Always append to it because it carries contents
|
|
|
|
# from predecessors.
|
|
|
|
self.ser_attrs += ['options', 'kind']
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
# assert isinstance(self.ui, GerberObjectUI)
|
|
|
|
# self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
|
|
|
|
# self.ui.solid_cb.stateChanged.connect(self.on_solid_cb_click)
|
|
|
|
# self.ui.multicolored_cb.stateChanged.connect(self.on_multicolored_cb_click)
|
|
|
|
# self.ui.generate_iso_button.clicked.connect(self.on_iso_button_click)
|
|
|
|
# self.ui.generate_cutout_button.clicked.connect(self.on_generatecutout_button_click)
|
|
|
|
# self.ui.generate_bb_button.clicked.connect(self.on_generatebb_button_click)
|
|
|
|
# self.ui.generate_noncopper_button.clicked.connect(self.on_generatenoncopper_button_click)
|
|
|
|
|
|
|
|
def set_ui(self, ui):
|
2015-10-31 22:58:46 +00:00
|
|
|
"""
|
|
|
|
Maps options with GUI inputs.
|
|
|
|
Connects GUI events to methods.
|
|
|
|
|
|
|
|
:param ui: GUI object.
|
|
|
|
:type ui: GerberObjectUI
|
|
|
|
:return: None
|
|
|
|
"""
|
2014-06-13 19:21:11 +00:00
|
|
|
FlatCAMObj.set_ui(self, ui)
|
|
|
|
|
|
|
|
FlatCAMApp.App.log.debug("FlatCAMGerber.set_ui()")
|
|
|
|
|
|
|
|
self.form_fields.update({
|
|
|
|
"plot": self.ui.plot_cb,
|
|
|
|
"multicolored": self.ui.multicolored_cb,
|
|
|
|
"solid": self.ui.solid_cb,
|
|
|
|
"isotooldia": self.ui.iso_tool_dia_entry,
|
|
|
|
"isopasses": self.ui.iso_width_entry,
|
|
|
|
"isooverlap": self.ui.iso_overlap_entry,
|
2016-06-03 21:15:35 +00:00
|
|
|
"combine_passes": self.ui.combine_passes_cb,
|
2014-06-13 19:21:11 +00:00
|
|
|
"cutouttooldia": self.ui.cutout_tooldia_entry,
|
|
|
|
"cutoutmargin": self.ui.cutout_margin_entry,
|
|
|
|
"cutoutgapsize": self.ui.cutout_gap_entry,
|
|
|
|
"gaps": self.ui.gaps_radio,
|
|
|
|
"noncoppermargin": self.ui.noncopper_margin_entry,
|
|
|
|
"noncopperrounded": self.ui.noncopper_rounded_cb,
|
|
|
|
"bboxmargin": self.ui.bbmargin_entry,
|
|
|
|
"bboxrounded": self.ui.bbrounded_cb
|
|
|
|
})
|
|
|
|
|
2014-04-25 05:24:03 +00:00
|
|
|
assert isinstance(self.ui, GerberObjectUI)
|
2014-06-13 19:21:11 +00:00
|
|
|
self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
|
|
|
|
self.ui.solid_cb.stateChanged.connect(self.on_solid_cb_click)
|
|
|
|
self.ui.multicolored_cb.stateChanged.connect(self.on_multicolored_cb_click)
|
|
|
|
self.ui.generate_iso_button.clicked.connect(self.on_iso_button_click)
|
|
|
|
self.ui.generate_cutout_button.clicked.connect(self.on_generatecutout_button_click)
|
|
|
|
self.ui.generate_bb_button.clicked.connect(self.on_generatebb_button_click)
|
|
|
|
self.ui.generate_noncopper_button.clicked.connect(self.on_generatenoncopper_button_click)
|
2014-04-25 05:24:03 +00:00
|
|
|
|
|
|
|
def on_generatenoncopper_button_click(self, *args):
|
2014-10-13 22:16:43 +00:00
|
|
|
self.app.report_usage("gerber_on_generatenoncopper_button")
|
|
|
|
|
2014-04-25 05:24:03 +00:00
|
|
|
self.read_form()
|
|
|
|
name = self.options["name"] + "_noncopper"
|
|
|
|
|
|
|
|
def geo_init(geo_obj, app_obj):
|
|
|
|
assert isinstance(geo_obj, FlatCAMGeometry)
|
|
|
|
bounding_box = self.solid_geometry.envelope.buffer(self.options["noncoppermargin"])
|
|
|
|
if not self.options["noncopperrounded"]:
|
|
|
|
bounding_box = bounding_box.envelope
|
|
|
|
non_copper = bounding_box.difference(self.solid_geometry)
|
|
|
|
geo_obj.solid_geometry = non_copper
|
|
|
|
|
|
|
|
# TODO: Check for None
|
|
|
|
self.app.new_object("geometry", name, geo_init)
|
|
|
|
|
|
|
|
def on_generatebb_button_click(self, *args):
|
2014-10-13 22:16:43 +00:00
|
|
|
self.app.report_usage("gerber_on_generatebb_button")
|
2014-04-25 05:24:03 +00:00
|
|
|
self.read_form()
|
|
|
|
name = self.options["name"] + "_bbox"
|
|
|
|
|
|
|
|
def geo_init(geo_obj, app_obj):
|
|
|
|
assert isinstance(geo_obj, FlatCAMGeometry)
|
|
|
|
# Bounding box with rounded corners
|
|
|
|
bounding_box = self.solid_geometry.envelope.buffer(self.options["bboxmargin"])
|
|
|
|
if not self.options["bboxrounded"]: # Remove rounded corners
|
|
|
|
bounding_box = bounding_box.envelope
|
|
|
|
geo_obj.solid_geometry = bounding_box
|
|
|
|
|
|
|
|
self.app.new_object("geometry", name, geo_init)
|
|
|
|
|
|
|
|
def on_generatecutout_button_click(self, *args):
|
2014-10-13 22:16:43 +00:00
|
|
|
self.app.report_usage("gerber_on_generatecutout_button")
|
2014-04-25 05:24:03 +00:00
|
|
|
self.read_form()
|
|
|
|
name = self.options["name"] + "_cutout"
|
|
|
|
|
|
|
|
def geo_init(geo_obj, app_obj):
|
|
|
|
margin = self.options["cutoutmargin"] + self.options["cutouttooldia"]/2
|
|
|
|
gap_size = self.options["cutoutgapsize"] + self.options["cutouttooldia"]
|
|
|
|
minx, miny, maxx, maxy = self.bounds()
|
|
|
|
minx -= margin
|
|
|
|
maxx += margin
|
|
|
|
miny -= margin
|
|
|
|
maxy += margin
|
|
|
|
midx = 0.5 * (minx + maxx)
|
|
|
|
midy = 0.5 * (miny + maxy)
|
|
|
|
hgap = 0.5 * gap_size
|
|
|
|
pts = [[midx - hgap, maxy],
|
|
|
|
[minx, maxy],
|
|
|
|
[minx, midy + hgap],
|
|
|
|
[minx, midy - hgap],
|
|
|
|
[minx, miny],
|
|
|
|
[midx - hgap, miny],
|
|
|
|
[midx + hgap, miny],
|
|
|
|
[maxx, miny],
|
|
|
|
[maxx, midy - hgap],
|
|
|
|
[maxx, midy + hgap],
|
|
|
|
[maxx, maxy],
|
|
|
|
[midx + hgap, maxy]]
|
|
|
|
cases = {"tb": [[pts[0], pts[1], pts[4], pts[5]],
|
|
|
|
[pts[6], pts[7], pts[10], pts[11]]],
|
|
|
|
"lr": [[pts[9], pts[10], pts[1], pts[2]],
|
|
|
|
[pts[3], pts[4], pts[7], pts[8]]],
|
|
|
|
"4": [[pts[0], pts[1], pts[2]],
|
|
|
|
[pts[3], pts[4], pts[5]],
|
|
|
|
[pts[6], pts[7], pts[8]],
|
|
|
|
[pts[9], pts[10], pts[11]]]}
|
|
|
|
cuts = cases[self.options['gaps']]
|
|
|
|
geo_obj.solid_geometry = cascaded_union([LineString(segment) for segment in cuts])
|
|
|
|
|
|
|
|
# TODO: Check for None
|
|
|
|
self.app.new_object("geometry", name, geo_init)
|
|
|
|
|
|
|
|
def on_iso_button_click(self, *args):
|
2014-10-13 22:16:43 +00:00
|
|
|
self.app.report_usage("gerber_on_iso_button")
|
2014-04-25 05:24:03 +00:00
|
|
|
self.read_form()
|
2014-09-13 21:29:07 +00:00
|
|
|
self.isolate()
|
|
|
|
|
2014-09-22 01:51:50 +00:00
|
|
|
def follow(self, outname=None):
|
|
|
|
"""
|
|
|
|
Creates a geometry object "following" the gerber paths.
|
|
|
|
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
|
|
|
|
default_name = self.options["name"] + "_follow"
|
|
|
|
follow_name = outname or default_name
|
|
|
|
|
|
|
|
def follow_init(follow_obj, app_obj):
|
|
|
|
# Propagate options
|
|
|
|
follow_obj.options["cnctooldia"] = self.options["isotooldia"]
|
|
|
|
follow_obj.solid_geometry = self.solid_geometry
|
|
|
|
app_obj.info("Follow geometry created: %s" % follow_obj.options["name"])
|
|
|
|
|
|
|
|
# TODO: Do something if this is None. Offer changing name?
|
|
|
|
self.app.new_object("geometry", follow_name, follow_init)
|
|
|
|
|
2015-05-26 23:48:09 +00:00
|
|
|
def isolate(self, dia=None, passes=None, overlap=None, outname=None, combine=None):
|
2014-09-13 21:29:07 +00:00
|
|
|
"""
|
|
|
|
Creates an isolation routing geometry object in the project.
|
|
|
|
|
|
|
|
:param dia: Tool diameter
|
|
|
|
:param passes: Number of tool widths to cut
|
|
|
|
:param overlap: Overlap between passes in fraction of tool diameter
|
2014-09-22 01:51:50 +00:00
|
|
|
:param outname: Base name of the output object
|
2014-09-13 21:29:07 +00:00
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
if dia is None:
|
|
|
|
dia = self.options["isotooldia"]
|
|
|
|
if passes is None:
|
|
|
|
passes = int(self.options["isopasses"])
|
|
|
|
if overlap is None:
|
2015-05-26 23:48:09 +00:00
|
|
|
overlap = self.options["isooverlap"]
|
|
|
|
if combine is None:
|
|
|
|
combine = self.options["combine_passes"]
|
|
|
|
else:
|
|
|
|
combine = bool(combine)
|
2014-04-25 05:24:03 +00:00
|
|
|
|
2014-09-22 01:51:50 +00:00
|
|
|
base_name = self.options["name"] + "_iso"
|
|
|
|
base_name = outname or base_name
|
|
|
|
|
2015-08-30 22:22:54 +00:00
|
|
|
def generate_envelope(offset, invert):
|
2015-06-19 23:25:22 +00:00
|
|
|
# isolation_geometry produces an envelope that is going on the left of the geometry
|
|
|
|
# (the copper features). To leave the least amount of burrs on the features
|
|
|
|
# the tool needs to travel on the right side of the features (this is called conventional milling)
|
|
|
|
# the first pass is the one cutting all of the features, so it needs to be reversed
|
|
|
|
# the other passes overlap preceding ones and cut the left over copper. It is better for them
|
|
|
|
# to cut on the right side of the left over copper i.e on the left side of the features.
|
|
|
|
geom = self.isolation_geometry(offset)
|
|
|
|
if invert:
|
|
|
|
if type(geom) is MultiPolygon:
|
|
|
|
pl = []
|
|
|
|
for p in geom:
|
2015-08-30 22:22:54 +00:00
|
|
|
pl.append(Polygon(p.exterior.coords[::-1], p.interiors))
|
2015-06-19 23:25:22 +00:00
|
|
|
geom = MultiPolygon(pl)
|
|
|
|
elif type(geom) is Polygon:
|
2015-08-30 22:22:54 +00:00
|
|
|
geom = Polygon(geom.exterior.coords[::-1], geom.interiors)
|
2015-06-19 23:25:22 +00:00
|
|
|
else:
|
|
|
|
raise "Unexpected Geometry"
|
|
|
|
return geom
|
|
|
|
|
2015-08-30 22:22:54 +00:00
|
|
|
if combine:
|
2015-05-26 23:48:09 +00:00
|
|
|
iso_name = base_name
|
2014-04-25 05:24:03 +00:00
|
|
|
|
|
|
|
# TODO: This is ugly. Create way to pass data into init function.
|
|
|
|
def iso_init(geo_obj, app_obj):
|
|
|
|
# Propagate options
|
|
|
|
geo_obj.options["cnctooldia"] = self.options["isotooldia"]
|
2015-05-26 23:48:09 +00:00
|
|
|
geo_obj.solid_geometry = []
|
|
|
|
for i in range(passes):
|
|
|
|
offset = (2 * i + 1) / 2.0 * dia - i * overlap * dia
|
2015-06-19 23:25:22 +00:00
|
|
|
geom = generate_envelope (offset, i == 0)
|
|
|
|
geo_obj.solid_geometry.append(geom)
|
2014-04-25 05:24:03 +00:00
|
|
|
app_obj.info("Isolation geometry created: %s" % geo_obj.options["name"])
|
|
|
|
|
|
|
|
# TODO: Do something if this is None. Offer changing name?
|
|
|
|
self.app.new_object("geometry", iso_name, iso_init)
|
|
|
|
|
2015-05-26 23:48:09 +00:00
|
|
|
else:
|
|
|
|
for i in range(passes):
|
|
|
|
|
|
|
|
offset = (2 * i + 1) / 2.0 * dia - i * overlap * dia
|
|
|
|
if passes > 1:
|
|
|
|
iso_name = base_name + str(i + 1)
|
|
|
|
else:
|
|
|
|
iso_name = base_name
|
|
|
|
|
|
|
|
# TODO: This is ugly. Create way to pass data into init function.
|
|
|
|
def iso_init(geo_obj, app_obj):
|
|
|
|
# Propagate options
|
|
|
|
geo_obj.options["cnctooldia"] = self.options["isotooldia"]
|
2015-06-19 23:25:22 +00:00
|
|
|
geo_obj.solid_geometry = generate_envelope (offset, i == 0)
|
2015-05-26 23:48:09 +00:00
|
|
|
app_obj.info("Isolation geometry created: %s" % geo_obj.options["name"])
|
|
|
|
|
|
|
|
# TODO: Do something if this is None. Offer changing name?
|
|
|
|
self.app.new_object("geometry", iso_name, iso_init)
|
|
|
|
|
2014-04-25 05:24:03 +00:00
|
|
|
def on_plot_cb_click(self, *args):
|
|
|
|
if self.muted_ui:
|
|
|
|
return
|
|
|
|
self.read_form_item('plot')
|
|
|
|
self.plot()
|
|
|
|
|
|
|
|
def on_solid_cb_click(self, *args):
|
|
|
|
if self.muted_ui:
|
|
|
|
return
|
|
|
|
self.read_form_item('solid')
|
|
|
|
self.plot()
|
|
|
|
|
|
|
|
def on_multicolored_cb_click(self, *args):
|
|
|
|
if self.muted_ui:
|
|
|
|
return
|
|
|
|
self.read_form_item('multicolored')
|
|
|
|
self.plot()
|
|
|
|
|
2014-03-28 22:14:21 +00:00
|
|
|
def convert_units(self, units):
|
|
|
|
"""
|
|
|
|
Converts the units of the object by scaling dimensions in all geometry
|
|
|
|
and options.
|
|
|
|
|
|
|
|
:param units: Units to which to convert the object: "IN" or "MM".
|
|
|
|
:type units: str
|
|
|
|
:return: None
|
|
|
|
:rtype: None
|
|
|
|
"""
|
|
|
|
|
|
|
|
factor = Gerber.convert_units(self, units)
|
|
|
|
|
|
|
|
self.options['isotooldia'] *= factor
|
|
|
|
self.options['cutoutmargin'] *= factor
|
|
|
|
self.options['cutoutgapsize'] *= factor
|
|
|
|
self.options['noncoppermargin'] *= factor
|
|
|
|
self.options['bboxmargin'] *= factor
|
|
|
|
|
|
|
|
def plot(self):
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
FlatCAMApp.App.log.debug(str(inspect.stack()[1][3]) + " --> FlatCAMGerber.plot()")
|
|
|
|
|
2014-03-28 22:14:21 +00:00
|
|
|
# Does all the required setup and returns False
|
|
|
|
# if the 'ptint' option is set to False.
|
|
|
|
if not FlatCAMObj.plot(self):
|
|
|
|
return
|
|
|
|
|
2014-04-19 00:20:17 +00:00
|
|
|
geometry = self.solid_geometry
|
2014-03-28 22:14:21 +00:00
|
|
|
|
2014-04-12 06:16:39 +00:00
|
|
|
# Make sure geometry is iterable.
|
|
|
|
try:
|
|
|
|
_ = iter(geometry)
|
|
|
|
except TypeError:
|
|
|
|
geometry = [geometry]
|
|
|
|
|
2014-03-28 22:14:21 +00:00
|
|
|
if self.options["multicolored"]:
|
|
|
|
linespec = '-'
|
|
|
|
else:
|
|
|
|
linespec = 'k-'
|
|
|
|
|
|
|
|
if self.options["solid"]:
|
|
|
|
for poly in geometry:
|
|
|
|
# TODO: Too many things hardcoded.
|
2014-04-19 00:20:17 +00:00
|
|
|
try:
|
|
|
|
patch = PolygonPatch(poly,
|
|
|
|
facecolor="#BBF268",
|
|
|
|
edgecolor="#006E20",
|
|
|
|
alpha=0.75,
|
|
|
|
zorder=2)
|
|
|
|
self.axes.add_patch(patch)
|
|
|
|
except AssertionError:
|
2014-05-03 02:10:04 +00:00
|
|
|
FlatCAMApp.App.log.warning("A geometry component was not a polygon:")
|
|
|
|
FlatCAMApp.App.log.warning(str(poly))
|
2014-03-28 22:14:21 +00:00
|
|
|
else:
|
|
|
|
for poly in geometry:
|
|
|
|
x, y = poly.exterior.xy
|
|
|
|
self.axes.plot(x, y, linespec)
|
|
|
|
for ints in poly.interiors:
|
|
|
|
x, y = ints.coords.xy
|
|
|
|
self.axes.plot(x, y, linespec)
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
self.app.plotcanvas.auto_adjust_axes()
|
2014-03-28 22:14:21 +00:00
|
|
|
|
|
|
|
def serialize(self):
|
|
|
|
return {
|
|
|
|
"options": self.options,
|
|
|
|
"kind": self.kind
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class FlatCAMExcellon(FlatCAMObj, Excellon):
|
|
|
|
"""
|
|
|
|
Represents Excellon/Drill code.
|
|
|
|
"""
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
ui_type = ExcellonObjectUI
|
|
|
|
|
2014-03-28 22:14:21 +00:00
|
|
|
def __init__(self, name):
|
|
|
|
Excellon.__init__(self)
|
2014-06-13 19:21:11 +00:00
|
|
|
FlatCAMObj.__init__(self, name)
|
2014-03-28 22:14:21 +00:00
|
|
|
|
|
|
|
self.kind = "excellon"
|
|
|
|
|
|
|
|
self.options.update({
|
|
|
|
"plot": True,
|
|
|
|
"solid": False,
|
|
|
|
"drillz": -0.1,
|
|
|
|
"travelz": 0.1,
|
|
|
|
"feedrate": 5.0,
|
2014-06-13 19:21:11 +00:00
|
|
|
# "toolselection": ""
|
2015-02-07 18:32:58 +00:00
|
|
|
"tooldia": 0.1,
|
|
|
|
"toolchange": False,
|
2015-07-17 07:49:24 +00:00
|
|
|
"toolchangez": 1.0,
|
2015-09-05 21:41:00 +00:00
|
|
|
"spindlespeed": None
|
2014-03-28 22:14:21 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
# TODO: Document this.
|
|
|
|
self.tool_cbs = {}
|
|
|
|
|
|
|
|
# Attributes to be included in serialization
|
|
|
|
# Always append to it because it carries contents
|
|
|
|
# from predecessors.
|
|
|
|
self.ser_attrs += ['options', 'kind']
|
|
|
|
|
2016-02-21 16:03:59 +00:00
|
|
|
@staticmethod
|
2016-02-23 11:21:57 +00:00
|
|
|
def merge(exc_list, exc_final):
|
2016-02-21 16:03:59 +00:00
|
|
|
"""
|
2016-02-23 11:21:57 +00:00
|
|
|
Merge excellons in exc_list into exc_final.
|
|
|
|
Options are allways copied from source .
|
|
|
|
|
|
|
|
Tools are also merged, if name for tool is same and size differs, then as name is used next available number from both lists
|
2016-02-21 16:03:59 +00:00
|
|
|
|
2016-02-23 11:21:57 +00:00
|
|
|
if only one object is specified in exc_list then this acts as copy only
|
|
|
|
|
|
|
|
:param exc_list: List or one object of FlatCAMExcellon Objects to join.
|
2016-02-21 16:03:59 +00:00
|
|
|
:param exc_final: Destination FlatCAMExcellon object.
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
|
|
|
|
if type(exc_list) is not list:
|
|
|
|
exc_list_real= list()
|
|
|
|
exc_list_real.append(exc_list)
|
|
|
|
else:
|
|
|
|
exc_list_real=exc_list
|
|
|
|
|
|
|
|
for exc in exc_list_real:
|
|
|
|
# Expand lists
|
|
|
|
if type(exc) is list:
|
2016-02-23 11:21:57 +00:00
|
|
|
FlatCAMExcellon.merge(exc, exc_final)
|
|
|
|
# If not list, merge excellons
|
2016-02-21 16:03:59 +00:00
|
|
|
else:
|
|
|
|
|
2016-02-23 11:21:57 +00:00
|
|
|
# TODO: I realize forms does not save values into options , when object is deselected
|
|
|
|
# leave this here for future use
|
|
|
|
# this reinitialize options based on forms, all steps may not be necessary
|
|
|
|
# exc.app.collection.set_active(exc.options['name'])
|
|
|
|
# exc.to_form()
|
|
|
|
# exc.read_form()
|
|
|
|
for option in exc.options:
|
|
|
|
if option is not 'name':
|
|
|
|
try:
|
|
|
|
exc_final.options[option] = exc.options[option]
|
|
|
|
except:
|
|
|
|
exc.app.log.warning("Failed to copy option.",option)
|
|
|
|
|
|
|
|
#deep copy of all drills,to avoid any references
|
2016-02-21 16:03:59 +00:00
|
|
|
for drill in exc.drills:
|
|
|
|
point = Point(drill['point'].x,drill['point'].y)
|
|
|
|
exc_final.drills.append({"point": point, "tool": drill['tool']})
|
|
|
|
toolsrework=dict()
|
|
|
|
max_numeric_tool=0
|
|
|
|
for toolname in exc.tools.iterkeys():
|
|
|
|
numeric_tool=int(toolname)
|
|
|
|
if numeric_tool>max_numeric_tool:
|
|
|
|
max_numeric_tool=numeric_tool
|
|
|
|
toolsrework[exc.tools[toolname]['C']]=toolname
|
|
|
|
|
2016-02-23 11:21:57 +00:00
|
|
|
#exc_final as last because names from final tools will be used
|
2016-02-21 16:03:59 +00:00
|
|
|
for toolname in exc_final.tools.iterkeys():
|
|
|
|
numeric_tool=int(toolname)
|
|
|
|
if numeric_tool>max_numeric_tool:
|
|
|
|
max_numeric_tool=numeric_tool
|
|
|
|
toolsrework[exc_final.tools[toolname]['C']]=toolname
|
|
|
|
|
|
|
|
for toolvalues in toolsrework.iterkeys():
|
|
|
|
if toolsrework[toolvalues] in exc_final.tools:
|
|
|
|
if exc_final.tools[toolsrework[toolvalues]]!={"C": toolvalues}:
|
|
|
|
exc_final.tools[str(max_numeric_tool+1)]={"C": toolvalues}
|
|
|
|
else:
|
|
|
|
exc_final.tools[toolsrework[toolvalues]]={"C": toolvalues}
|
2016-02-23 11:21:57 +00:00
|
|
|
#this value was not co
|
|
|
|
exc_final.zeros=exc.zeros
|
2016-02-21 16:03:59 +00:00
|
|
|
exc_final.create_geometry()
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
def build_ui(self):
|
|
|
|
FlatCAMObj.build_ui(self)
|
|
|
|
|
|
|
|
# Populate tool list
|
|
|
|
n = len(self.tools)
|
|
|
|
self.ui.tools_table.setColumnCount(2)
|
|
|
|
self.ui.tools_table.setHorizontalHeaderLabels(['#', 'Diameter'])
|
|
|
|
self.ui.tools_table.setRowCount(n)
|
|
|
|
self.ui.tools_table.setSortingEnabled(False)
|
|
|
|
i = 0
|
|
|
|
for tool in self.tools:
|
|
|
|
id = QtGui.QTableWidgetItem(tool)
|
|
|
|
id.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
|
|
|
self.ui.tools_table.setItem(i, 0, id) # Tool name/id
|
|
|
|
dia = QtGui.QTableWidgetItem(str(self.tools[tool]['C']))
|
|
|
|
dia.setFlags(QtCore.Qt.ItemIsEnabled)
|
|
|
|
self.ui.tools_table.setItem(i, 1, dia) # Diameter
|
|
|
|
i += 1
|
2016-02-14 05:40:32 +00:00
|
|
|
|
|
|
|
# sort the tool diameter column
|
|
|
|
self.ui.tools_table.sortItems(1)
|
|
|
|
# all the tools are selected by default
|
|
|
|
self.ui.tools_table.selectColumn(0)
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
self.ui.tools_table.resizeColumnsToContents()
|
|
|
|
self.ui.tools_table.resizeRowsToContents()
|
|
|
|
self.ui.tools_table.horizontalHeader().setStretchLastSection(True)
|
|
|
|
self.ui.tools_table.verticalHeader().hide()
|
|
|
|
self.ui.tools_table.setSortingEnabled(True)
|
|
|
|
|
|
|
|
def set_ui(self, ui):
|
2015-02-07 23:41:29 +00:00
|
|
|
"""
|
|
|
|
Configures the user interface for this object.
|
|
|
|
Connects options to form fields.
|
|
|
|
|
|
|
|
:param ui: User interface object.
|
|
|
|
:type ui: ExcellonObjectUI
|
|
|
|
:return: None
|
|
|
|
"""
|
2014-06-13 19:21:11 +00:00
|
|
|
FlatCAMObj.set_ui(self, ui)
|
|
|
|
|
|
|
|
FlatCAMApp.App.log.debug("FlatCAMExcellon.set_ui()")
|
|
|
|
|
|
|
|
self.form_fields.update({
|
|
|
|
"plot": self.ui.plot_cb,
|
|
|
|
"solid": self.ui.solid_cb,
|
|
|
|
"drillz": self.ui.cutz_entry,
|
|
|
|
"travelz": self.ui.travelz_entry,
|
|
|
|
"feedrate": self.ui.feedrate_entry,
|
2015-02-07 18:41:56 +00:00
|
|
|
"tooldia": self.ui.tooldia_entry,
|
|
|
|
"toolchange": self.ui.toolchange_cb,
|
2015-07-17 07:49:24 +00:00
|
|
|
"toolchangez": self.ui.toolchangez_entry,
|
2015-10-04 00:03:53 +00:00
|
|
|
"spindlespeed": self.ui.spindlespeed_entry
|
2014-06-13 19:21:11 +00:00
|
|
|
})
|
|
|
|
|
2015-10-28 16:00:56 +00:00
|
|
|
assert isinstance(self.ui, ExcellonObjectUI), \
|
|
|
|
"Expected a ExcellonObjectUI, got %s" % type(self.ui)
|
2014-06-13 19:21:11 +00:00
|
|
|
self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
|
|
|
|
self.ui.solid_cb.stateChanged.connect(self.on_solid_cb_click)
|
|
|
|
self.ui.generate_cnc_button.clicked.connect(self.on_create_cncjob_button_click)
|
2014-12-07 19:53:33 +00:00
|
|
|
self.ui.generate_milling_button.clicked.connect(self.on_generate_milling_button_click)
|
|
|
|
|
|
|
|
def get_selected_tools_list(self):
|
|
|
|
"""
|
|
|
|
Returns the keys to the self.tools dictionary corresponding
|
|
|
|
to the selections on the tool list in the GUI.
|
2015-10-04 00:03:53 +00:00
|
|
|
|
|
|
|
:return: List of tools.
|
|
|
|
:rtype: list
|
2014-12-07 19:53:33 +00:00
|
|
|
"""
|
|
|
|
return [str(x.text()) for x in self.ui.tools_table.selectedItems()]
|
|
|
|
|
2015-10-04 00:03:53 +00:00
|
|
|
def generate_milling(self, tools=None, outname=None, tooldia=None):
|
|
|
|
"""
|
|
|
|
Note: This method is a good template for generic operations as
|
|
|
|
it takes it's options from parameters or otherwise from the
|
2017-05-05 20:20:14 +00:00
|
|
|
object's options and returns a (success, msg) tuple as feedback
|
2015-10-04 00:03:53 +00:00
|
|
|
for shell operations.
|
|
|
|
|
|
|
|
:return: Success/failure condition tuple (bool, str).
|
|
|
|
:rtype: tuple
|
|
|
|
"""
|
2014-12-07 19:53:33 +00:00
|
|
|
|
2014-12-10 02:30:01 +00:00
|
|
|
# Get the tools from the list. These are keys
|
|
|
|
# to self.tools
|
2015-10-04 00:03:53 +00:00
|
|
|
if tools is None:
|
|
|
|
tools = self.get_selected_tools_list()
|
|
|
|
|
|
|
|
if outname is None:
|
|
|
|
outname = self.options["name"] + "_mill"
|
|
|
|
|
|
|
|
if tooldia is None:
|
|
|
|
tooldia = self.options["tooldia"]
|
2014-12-07 19:53:33 +00:00
|
|
|
|
2017-05-05 20:20:14 +00:00
|
|
|
# Sort tools by diameter. items() -> [('name', diameter), ...]
|
|
|
|
sorted_tools = sorted(self.tools.items(), key=lambda tl: tl[1])
|
|
|
|
|
|
|
|
if tools == "all":
|
|
|
|
tools = [i[0] for i in sorted_tools] # List if ordered tool names.
|
|
|
|
log.debug("Tools 'all' and sorted are: %s" % str(tools))
|
|
|
|
|
2014-12-07 19:53:33 +00:00
|
|
|
if len(tools) == 0:
|
|
|
|
self.app.inform.emit("Please select one or more tools from the list and try again.")
|
2015-10-04 00:03:53 +00:00
|
|
|
return False, "Error: No tools."
|
2014-12-07 19:53:33 +00:00
|
|
|
|
2014-12-10 02:30:01 +00:00
|
|
|
for tool in tools:
|
2015-10-04 00:03:53 +00:00
|
|
|
if self.tools[tool]["C"] < tooldia:
|
2014-12-10 02:30:01 +00:00
|
|
|
self.app.inform.emit("[warning] Milling tool is larger than hole size. Cancelled.")
|
2015-10-04 00:03:53 +00:00
|
|
|
return False, "Error: Milling tool is larger than hole."
|
2014-12-07 19:53:33 +00:00
|
|
|
|
|
|
|
def geo_init(geo_obj, app_obj):
|
2015-10-28 16:00:56 +00:00
|
|
|
assert isinstance(geo_obj, FlatCAMGeometry), \
|
|
|
|
"Initializer expected a FlatCAMGeometry, got %s" % type(geo_obj)
|
2014-12-07 19:53:33 +00:00
|
|
|
app_obj.progress.emit(20)
|
|
|
|
|
|
|
|
geo_obj.solid_geometry = []
|
|
|
|
|
|
|
|
for hole in self.drills:
|
|
|
|
if hole['tool'] in tools:
|
|
|
|
geo_obj.solid_geometry.append(
|
2014-12-10 02:30:01 +00:00
|
|
|
Point(hole['point']).buffer(self.tools[hole['tool']]["C"] / 2 -
|
2015-10-04 00:03:53 +00:00
|
|
|
tooldia / 2).exterior
|
2014-12-07 19:53:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def geo_thread(app_obj):
|
2015-10-04 00:03:53 +00:00
|
|
|
app_obj.new_object("geometry", outname, geo_init)
|
2014-12-07 19:53:33 +00:00
|
|
|
app_obj.progress.emit(100)
|
|
|
|
|
2015-08-30 22:22:54 +00:00
|
|
|
# Create a promise with the new name
|
2015-10-04 00:03:53 +00:00
|
|
|
self.app.collection.promise(outname)
|
2015-08-30 22:22:54 +00:00
|
|
|
|
2014-12-07 19:53:33 +00:00
|
|
|
# Send to worker
|
|
|
|
self.app.worker_task.emit({'fcn': geo_thread, 'params': [self.app]})
|
2014-05-03 02:10:04 +00:00
|
|
|
|
2015-10-04 00:03:53 +00:00
|
|
|
return True, ""
|
|
|
|
|
|
|
|
def on_generate_milling_button_click(self, *args):
|
|
|
|
self.app.report_usage("excellon_on_create_milling_button")
|
|
|
|
self.read_form()
|
|
|
|
|
|
|
|
self.generate_milling()
|
|
|
|
|
2014-05-03 02:10:04 +00:00
|
|
|
def on_create_cncjob_button_click(self, *args):
|
2014-10-13 22:16:43 +00:00
|
|
|
self.app.report_usage("excellon_on_create_cncjob_button")
|
2014-05-03 02:10:04 +00:00
|
|
|
self.read_form()
|
2014-06-13 19:21:11 +00:00
|
|
|
|
|
|
|
# Get the tools from the list
|
2014-12-07 19:53:33 +00:00
|
|
|
tools = self.get_selected_tools_list()
|
2014-06-13 19:21:11 +00:00
|
|
|
|
|
|
|
if len(tools) == 0:
|
|
|
|
self.app.inform.emit("Please select one or more tools from the list and try again.")
|
|
|
|
return
|
|
|
|
|
2014-05-03 02:10:04 +00:00
|
|
|
job_name = self.options["name"] + "_cnc"
|
|
|
|
|
|
|
|
# Object initialization function for app.new_object()
|
|
|
|
def job_init(job_obj, app_obj):
|
2015-10-28 16:00:56 +00:00
|
|
|
assert isinstance(job_obj, FlatCAMCNCjob), \
|
|
|
|
"Initializer expected a FlatCAMCNCjob, got %s" % type(job_obj)
|
2014-05-03 02:10:04 +00:00
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
app_obj.progress.emit(20)
|
2014-05-03 02:10:04 +00:00
|
|
|
job_obj.z_cut = self.options["drillz"]
|
|
|
|
job_obj.z_move = self.options["travelz"]
|
|
|
|
job_obj.feedrate = self.options["feedrate"]
|
2015-07-17 07:49:24 +00:00
|
|
|
job_obj.spindlespeed = self.options["spindlespeed"]
|
2014-05-03 02:10:04 +00:00
|
|
|
# There could be more than one drill size...
|
|
|
|
# job_obj.tooldia = # TODO: duplicate variable!
|
|
|
|
# job_obj.options["tooldia"] =
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
tools_csv = ','.join(tools)
|
2015-02-07 18:32:58 +00:00
|
|
|
job_obj.generate_from_excellon_by_tool(self, tools_csv,
|
|
|
|
toolchange=self.options["toolchange"],
|
|
|
|
toolchangez=self.options["toolchangez"])
|
2014-06-13 19:21:11 +00:00
|
|
|
|
|
|
|
app_obj.progress.emit(50)
|
2014-05-03 02:10:04 +00:00
|
|
|
job_obj.gcode_parse()
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
app_obj.progress.emit(60)
|
2014-05-03 02:10:04 +00:00
|
|
|
job_obj.create_geometry()
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
app_obj.progress.emit(80)
|
2014-05-03 02:10:04 +00:00
|
|
|
|
|
|
|
# To be run in separate thread
|
|
|
|
def job_thread(app_obj):
|
|
|
|
app_obj.new_object("cncjob", job_name, job_init)
|
2014-06-13 19:21:11 +00:00
|
|
|
app_obj.progress.emit(100)
|
2014-05-03 02:10:04 +00:00
|
|
|
|
2015-08-30 22:22:54 +00:00
|
|
|
# Create promise for the new name.
|
|
|
|
self.app.collection.promise(job_name)
|
|
|
|
|
2014-05-03 02:10:04 +00:00
|
|
|
# Send to worker
|
2014-06-13 19:21:11 +00:00
|
|
|
# self.app.worker.add_task(job_thread, [self.app])
|
|
|
|
self.app.worker_task.emit({'fcn': job_thread, 'params': [self.app]})
|
2014-04-25 05:24:03 +00:00
|
|
|
|
|
|
|
def on_plot_cb_click(self, *args):
|
|
|
|
if self.muted_ui:
|
|
|
|
return
|
|
|
|
self.read_form_item('plot')
|
|
|
|
self.plot()
|
|
|
|
|
|
|
|
def on_solid_cb_click(self, *args):
|
|
|
|
if self.muted_ui:
|
|
|
|
return
|
|
|
|
self.read_form_item('solid')
|
|
|
|
self.plot()
|
|
|
|
|
2014-03-28 22:14:21 +00:00
|
|
|
def convert_units(self, units):
|
|
|
|
factor = Excellon.convert_units(self, units)
|
|
|
|
|
|
|
|
self.options['drillz'] *= factor
|
|
|
|
self.options['travelz'] *= factor
|
|
|
|
self.options['feedrate'] *= factor
|
|
|
|
|
|
|
|
def plot(self):
|
|
|
|
|
|
|
|
# Does all the required setup and returns False
|
|
|
|
# if the 'ptint' option is set to False.
|
|
|
|
if not FlatCAMObj.plot(self):
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
_ = iter(self.solid_geometry)
|
|
|
|
except TypeError:
|
|
|
|
self.solid_geometry = [self.solid_geometry]
|
|
|
|
|
|
|
|
# Plot excellon (All polygons?)
|
|
|
|
if self.options["solid"]:
|
|
|
|
for geo in self.solid_geometry:
|
|
|
|
patch = PolygonPatch(geo,
|
|
|
|
facecolor="#C40000",
|
|
|
|
edgecolor="#750000",
|
|
|
|
alpha=0.75,
|
|
|
|
zorder=3)
|
|
|
|
self.axes.add_patch(patch)
|
|
|
|
else:
|
|
|
|
for geo in self.solid_geometry:
|
|
|
|
x, y = geo.exterior.coords.xy
|
|
|
|
self.axes.plot(x, y, 'r-')
|
|
|
|
for ints in geo.interiors:
|
|
|
|
x, y = ints.coords.xy
|
|
|
|
self.axes.plot(x, y, 'g-')
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
self.app.plotcanvas.auto_adjust_axes()
|
2014-03-28 22:14:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
class FlatCAMCNCjob(FlatCAMObj, CNCjob):
|
|
|
|
"""
|
|
|
|
Represents G-Code.
|
|
|
|
"""
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
ui_type = CNCObjectUI
|
|
|
|
|
2014-03-28 22:14:21 +00:00
|
|
|
def __init__(self, name, units="in", kind="generic", z_move=0.1,
|
2015-09-05 21:41:00 +00:00
|
|
|
feedrate=3.0, z_cut=-0.002, tooldia=0.0,
|
|
|
|
spindlespeed=None):
|
2015-01-19 16:53:28 +00:00
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
FlatCAMApp.App.log.debug("Creating CNCJob object...")
|
2015-01-19 16:53:28 +00:00
|
|
|
|
2014-03-28 22:14:21 +00:00
|
|
|
CNCjob.__init__(self, units=units, kind=kind, z_move=z_move,
|
2015-09-05 21:41:00 +00:00
|
|
|
feedrate=feedrate, z_cut=z_cut, tooldia=tooldia,
|
|
|
|
spindlespeed=spindlespeed)
|
2015-01-19 16:53:28 +00:00
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
FlatCAMObj.__init__(self, name)
|
2014-03-28 22:14:21 +00:00
|
|
|
|
|
|
|
self.kind = "cncjob"
|
|
|
|
|
|
|
|
self.options.update({
|
|
|
|
"plot": True,
|
2014-06-13 19:21:11 +00:00
|
|
|
"tooldia": 0.4 / 25.4, # 0.4mm in inches
|
2015-02-13 19:47:00 +00:00
|
|
|
"append": "",
|
2016-06-04 02:19:47 +00:00
|
|
|
"prepend": "",
|
|
|
|
"dwell": False,
|
|
|
|
"dwelltime": 1
|
2014-03-28 22:14:21 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
# Attributes to be included in serialization
|
|
|
|
# Always append to it because it carries contents
|
|
|
|
# from predecessors.
|
|
|
|
self.ser_attrs += ['options', 'kind']
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
def set_ui(self, ui):
|
|
|
|
FlatCAMObj.set_ui(self, ui)
|
|
|
|
|
|
|
|
FlatCAMApp.App.log.debug("FlatCAMCNCJob.set_ui()")
|
|
|
|
|
2015-10-28 16:00:56 +00:00
|
|
|
assert isinstance(self.ui, CNCObjectUI), \
|
|
|
|
"Expected a CNCObjectUI, got %s" % type(self.ui)
|
2014-06-13 19:21:11 +00:00
|
|
|
|
|
|
|
self.form_fields.update({
|
|
|
|
"plot": self.ui.plot_cb,
|
|
|
|
"tooldia": self.ui.tooldia_entry,
|
2015-02-13 19:47:00 +00:00
|
|
|
"append": self.ui.append_text,
|
2016-06-04 02:19:47 +00:00
|
|
|
"prepend": self.ui.prepend_text,
|
|
|
|
"dwell": self.ui.dwell_cb,
|
|
|
|
"dwelltime": self.ui.dwelltime_entry
|
2014-06-13 19:21:11 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
|
|
|
|
self.ui.updateplot_button.clicked.connect(self.on_updateplot_button_click)
|
|
|
|
self.ui.export_gcode_button.clicked.connect(self.on_exportgcode_button_click)
|
2014-05-03 02:10:04 +00:00
|
|
|
|
2014-05-05 14:15:57 +00:00
|
|
|
def on_updateplot_button_click(self, *args):
|
2014-06-13 19:21:11 +00:00
|
|
|
"""
|
|
|
|
Callback for the "Updata Plot" button. Reads the form for updates
|
|
|
|
and plots the object.
|
|
|
|
"""
|
2014-05-05 14:15:57 +00:00
|
|
|
self.read_form()
|
|
|
|
self.plot()
|
|
|
|
|
2014-05-03 02:10:04 +00:00
|
|
|
def on_exportgcode_button_click(self, *args):
|
2014-10-13 22:16:43 +00:00
|
|
|
self.app.report_usage("cncjob_on_exportgcode_button")
|
2014-05-03 02:10:04 +00:00
|
|
|
|
2016-06-04 02:19:47 +00:00
|
|
|
self.read_form()
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
try:
|
2017-03-24 13:29:30 +00:00
|
|
|
filename = unicode(QtGui.QFileDialog.getSaveFileName(caption="Export G-Code ...",
|
|
|
|
directory=self.app.defaults["last_folder"]))
|
2014-06-13 19:21:11 +00:00
|
|
|
except TypeError:
|
2017-03-24 13:29:30 +00:00
|
|
|
filename = unicode(QtGui.QFileDialog.getSaveFileName(caption="Export G-Code ..."))
|
2014-06-13 19:21:11 +00:00
|
|
|
|
2015-02-13 19:47:00 +00:00
|
|
|
preamble = str(self.ui.prepend_text.get_value())
|
2014-06-13 19:21:11 +00:00
|
|
|
postamble = str(self.ui.append_text.get_value())
|
|
|
|
|
2015-02-13 19:47:00 +00:00
|
|
|
self.export_gcode(filename, preamble=preamble, postamble=postamble)
|
2014-09-22 01:51:50 +00:00
|
|
|
|
2016-06-04 02:19:47 +00:00
|
|
|
def dwell_generator(self, lines):
|
2016-06-04 20:45:52 +00:00
|
|
|
"""
|
|
|
|
Inserts "G4 P..." instructions after spindle-start
|
|
|
|
instructions (M03 or M04).
|
|
|
|
|
|
|
|
"""
|
2016-06-04 02:19:47 +00:00
|
|
|
|
|
|
|
log.debug("dwell_generator()...")
|
|
|
|
|
|
|
|
m3m4re = re.compile(r'^\s*[mM]0[34]')
|
|
|
|
g4re = re.compile(r'^\s*[gG]4\s+([\d\.\+\-e]+)')
|
|
|
|
bufline = None
|
|
|
|
|
|
|
|
for line in lines:
|
|
|
|
# If the buffer contains a G4, yield that.
|
|
|
|
# If current line is a G4, discard it.
|
|
|
|
if bufline is not None:
|
|
|
|
yield bufline
|
|
|
|
bufline = None
|
|
|
|
|
|
|
|
if not g4re.search(line):
|
|
|
|
yield line
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
# If start spindle, buffer a G4.
|
|
|
|
if m3m4re.search(line):
|
|
|
|
log.debug("Found M03/4")
|
2016-06-04 20:45:52 +00:00
|
|
|
bufline = "G4 P{}\n".format(self.options['dwelltime'])
|
2016-06-04 02:19:47 +00:00
|
|
|
|
|
|
|
yield line
|
|
|
|
|
|
|
|
raise StopIteration
|
|
|
|
|
2014-09-22 01:51:50 +00:00
|
|
|
def export_gcode(self, filename, preamble='', postamble=''):
|
2016-06-04 02:19:47 +00:00
|
|
|
|
|
|
|
lines = StringIO(self.gcode)
|
|
|
|
|
2016-06-04 20:45:52 +00:00
|
|
|
## Post processing
|
|
|
|
# Dwell?
|
2016-06-04 02:19:47 +00:00
|
|
|
if self.options['dwell']:
|
|
|
|
log.debug("Will add G04!")
|
|
|
|
lines = self.dwell_generator(lines)
|
|
|
|
|
2016-06-04 20:45:52 +00:00
|
|
|
## Write
|
2016-06-04 02:19:47 +00:00
|
|
|
with open(filename, 'w') as f:
|
|
|
|
f.write(preamble + "\n")
|
|
|
|
|
|
|
|
for line in lines:
|
|
|
|
|
|
|
|
f.write(line)
|
|
|
|
|
|
|
|
f.write(postamble)
|
2014-06-13 19:21:11 +00:00
|
|
|
|
2015-10-31 22:58:46 +00:00
|
|
|
# Just for adding it to the recent files list.
|
2014-06-13 19:21:11 +00:00
|
|
|
self.app.file_opened.emit("cncjob", filename)
|
2015-10-31 22:58:46 +00:00
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
self.app.inform.emit("Saved to: " + filename)
|
2014-05-03 02:10:04 +00:00
|
|
|
|
2016-03-19 14:13:07 +00:00
|
|
|
def get_gcode(self, preamble='', postamble=''):
|
|
|
|
#we need this to beable get_gcode separatelly for shell command export_code
|
|
|
|
return preamble + '\n' + self.gcode + "\n" + postamble
|
|
|
|
|
2014-04-25 05:24:03 +00:00
|
|
|
def on_plot_cb_click(self, *args):
|
|
|
|
if self.muted_ui:
|
|
|
|
return
|
|
|
|
self.read_form_item('plot')
|
|
|
|
self.plot()
|
|
|
|
|
2014-03-28 22:14:21 +00:00
|
|
|
def plot(self):
|
|
|
|
|
|
|
|
# Does all the required setup and returns False
|
|
|
|
# if the 'ptint' option is set to False.
|
|
|
|
if not FlatCAMObj.plot(self):
|
|
|
|
return
|
|
|
|
|
|
|
|
self.plot2(self.axes, tooldia=self.options["tooldia"])
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
self.app.plotcanvas.auto_adjust_axes()
|
2014-03-28 22:14:21 +00:00
|
|
|
|
|
|
|
def convert_units(self, units):
|
|
|
|
factor = CNCjob.convert_units(self, units)
|
2014-05-03 02:10:04 +00:00
|
|
|
FlatCAMApp.App.log.debug("FlatCAMCNCjob.convert_units()")
|
2014-03-28 22:14:21 +00:00
|
|
|
self.options["tooldia"] *= factor
|
|
|
|
|
|
|
|
|
|
|
|
class FlatCAMGeometry(FlatCAMObj, Geometry):
|
|
|
|
"""
|
|
|
|
Geometric object not associated with a specific
|
|
|
|
format.
|
|
|
|
"""
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
ui_type = GeometryObjectUI
|
|
|
|
|
2014-11-13 20:06:43 +00:00
|
|
|
@staticmethod
|
|
|
|
def merge(geo_list, geo_final):
|
|
|
|
"""
|
|
|
|
Merges the geometry of objects in geo_list into
|
|
|
|
the geometry of geo_final.
|
|
|
|
|
|
|
|
:param geo_list: List of FlatCAMGeometry Objects to join.
|
|
|
|
:param geo_final: Destination FlatCAMGeometry object.
|
|
|
|
:return: None
|
|
|
|
"""
|
2015-01-19 01:23:37 +00:00
|
|
|
|
|
|
|
if geo_final.solid_geometry is None:
|
|
|
|
geo_final.solid_geometry = []
|
|
|
|
if type(geo_final.solid_geometry) is not list:
|
|
|
|
geo_final.solid_geometry = [geo_final.solid_geometry]
|
2014-11-13 20:06:43 +00:00
|
|
|
|
|
|
|
for geo in geo_list:
|
2015-01-07 14:38:46 +00:00
|
|
|
|
2015-01-19 01:23:37 +00:00
|
|
|
# Expand lists
|
|
|
|
if type(geo) is list:
|
|
|
|
FlatCAMGeometry.merge(geo, geo_final)
|
2015-01-07 14:38:46 +00:00
|
|
|
|
2015-01-19 01:23:37 +00:00
|
|
|
# If not list, just append
|
|
|
|
else:
|
|
|
|
geo_final.solid_geometry.append(geo.solid_geometry)
|
|
|
|
|
|
|
|
# try: # Iterable
|
|
|
|
# for shape in geo.solid_geometry:
|
|
|
|
# geo_final.solid_geometry.append(shape)
|
|
|
|
#
|
|
|
|
# except TypeError: # Non-iterable
|
|
|
|
# geo_final.solid_geometry.append(geo.solid_geometry)
|
2014-11-13 20:06:43 +00:00
|
|
|
|
2014-03-28 22:14:21 +00:00
|
|
|
def __init__(self, name):
|
2014-06-13 19:21:11 +00:00
|
|
|
FlatCAMObj.__init__(self, name)
|
2014-03-28 22:14:21 +00:00
|
|
|
Geometry.__init__(self)
|
|
|
|
|
|
|
|
self.kind = "geometry"
|
|
|
|
|
|
|
|
self.options.update({
|
|
|
|
"plot": True,
|
|
|
|
"cutz": -0.002,
|
|
|
|
"travelz": 0.1,
|
|
|
|
"feedrate": 5.0,
|
2015-09-05 21:41:00 +00:00
|
|
|
"spindlespeed": None,
|
2014-03-28 22:14:21 +00:00
|
|
|
"cnctooldia": 0.4 / 25.4,
|
|
|
|
"painttooldia": 0.0625,
|
|
|
|
"paintoverlap": 0.15,
|
2014-12-07 19:53:33 +00:00
|
|
|
"paintmargin": 0.01,
|
2015-11-01 23:06:20 +00:00
|
|
|
"paintmethod": "standard",
|
2016-10-27 21:34:41 +00:00
|
|
|
"pathconnect": True,
|
2016-11-01 04:34:46 +00:00
|
|
|
"paintcontour": True,
|
2015-11-01 23:06:20 +00:00
|
|
|
"multidepth": False,
|
2016-09-19 20:44:29 +00:00
|
|
|
"depthperpass": 0.002,
|
|
|
|
"selectmethod": "single"
|
2014-03-28 22:14:21 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
# Attributes to be included in serialization
|
|
|
|
# Always append to it because it carries contents
|
|
|
|
# from predecessors.
|
|
|
|
self.ser_attrs += ['options', 'kind']
|
|
|
|
|
2014-10-28 21:39:38 +00:00
|
|
|
def build_ui(self):
|
|
|
|
FlatCAMObj.build_ui(self)
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
def set_ui(self, ui):
|
|
|
|
FlatCAMObj.set_ui(self, ui)
|
|
|
|
|
|
|
|
FlatCAMApp.App.log.debug("FlatCAMGeometry.set_ui()")
|
|
|
|
|
2015-10-28 16:00:56 +00:00
|
|
|
assert isinstance(self.ui, GeometryObjectUI), \
|
|
|
|
"Expected a GeometryObjectUI, got %s" % type(self.ui)
|
2014-06-13 19:21:11 +00:00
|
|
|
|
|
|
|
self.form_fields.update({
|
|
|
|
"plot": self.ui.plot_cb,
|
|
|
|
"cutz": self.ui.cutz_entry,
|
|
|
|
"travelz": self.ui.travelz_entry,
|
|
|
|
"feedrate": self.ui.cncfeedrate_entry,
|
2015-07-17 07:49:24 +00:00
|
|
|
"spindlespeed": self.ui.cncspindlespeed_entry,
|
2014-06-13 19:21:11 +00:00
|
|
|
"cnctooldia": self.ui.cnctooldia_entry,
|
|
|
|
"painttooldia": self.ui.painttooldia_entry,
|
|
|
|
"paintoverlap": self.ui.paintoverlap_entry,
|
2014-12-07 19:53:33 +00:00
|
|
|
"paintmargin": self.ui.paintmargin_entry,
|
2015-11-01 23:06:20 +00:00
|
|
|
"paintmethod": self.ui.paintmethod_combo,
|
2016-10-27 21:34:41 +00:00
|
|
|
"pathconnect": self.ui.pathconnect_cb,
|
2016-11-01 04:34:46 +00:00
|
|
|
"paintcontour": self.ui.paintcontour_cb,
|
2015-11-01 23:06:20 +00:00
|
|
|
"multidepth": self.ui.mpass_cb,
|
2016-09-19 20:44:29 +00:00
|
|
|
"depthperpass": self.ui.maxdepth_entry,
|
|
|
|
"selectmethod": self.ui.selectmethod_combo
|
2014-06-13 19:21:11 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
self.ui.plot_cb.stateChanged.connect(self.on_plot_cb_click)
|
|
|
|
self.ui.generate_cnc_button.clicked.connect(self.on_generatecnc_button_click)
|
|
|
|
self.ui.generate_paint_button.clicked.connect(self.on_paint_button_click)
|
2014-04-25 05:24:03 +00:00
|
|
|
|
|
|
|
def on_paint_button_click(self, *args):
|
2014-10-13 22:16:43 +00:00
|
|
|
self.app.report_usage("geometry_on_paint_button")
|
|
|
|
|
2014-04-25 05:24:03 +00:00
|
|
|
self.read_form()
|
|
|
|
tooldia = self.options["painttooldia"]
|
|
|
|
overlap = self.options["paintoverlap"]
|
|
|
|
|
2016-09-19 20:44:29 +00:00
|
|
|
if self.options["selectmethod"] == "all":
|
2016-10-27 21:34:41 +00:00
|
|
|
self.paint_poly_all(tooldia, overlap,
|
2016-11-01 04:34:46 +00:00
|
|
|
connect=self.options["pathconnect"],
|
|
|
|
contour=self.options["paintcontour"])
|
2016-09-19 20:44:29 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
if self.options["selectmethod"] == "single":
|
|
|
|
self.app.info("Click inside the desired polygon.")
|
2014-04-25 05:24:03 +00:00
|
|
|
|
2016-09-19 20:44:29 +00:00
|
|
|
# To be called after clicking on the plot.
|
|
|
|
def doit(event):
|
|
|
|
self.app.info("Painting polygon...")
|
|
|
|
self.app.plotcanvas.mpl_disconnect(subscription)
|
|
|
|
point = [event.xdata, event.ydata]
|
2016-10-27 21:34:41 +00:00
|
|
|
self.paint_poly_single_click(point, tooldia, overlap,
|
2016-11-01 04:34:46 +00:00
|
|
|
connect=self.options["pathconnect"],
|
|
|
|
contour=self.options["paintcontour"])
|
2014-04-25 05:24:03 +00:00
|
|
|
|
2016-09-19 20:44:29 +00:00
|
|
|
subscription = self.app.plotcanvas.mpl_connect('button_press_event', doit)
|
|
|
|
|
2016-10-27 21:34:41 +00:00
|
|
|
def paint_poly_single_click(self, inside_pt, tooldia, overlap,
|
2016-11-01 04:34:46 +00:00
|
|
|
outname=None, connect=True, contour=True):
|
2016-09-19 20:44:29 +00:00
|
|
|
"""
|
|
|
|
Paints a polygon selected by clicking on its interior.
|
2014-04-25 05:24:03 +00:00
|
|
|
|
2016-09-19 20:44:29 +00:00
|
|
|
Note:
|
|
|
|
* The margin is taken directly from the form.
|
|
|
|
|
|
|
|
:param inside_pt: [x, y]
|
|
|
|
:param tooldia: Diameter of the painting tool
|
|
|
|
:param overlap: Overlap of the tool between passes.
|
2016-09-21 17:01:51 +00:00
|
|
|
:param outname: Name of the resulting Geometry Object.
|
2016-11-01 04:34:46 +00:00
|
|
|
:param connect: Connect lines to avoid tool lifts.
|
|
|
|
:param contour: Paint around the edges.
|
2016-09-19 20:44:29 +00:00
|
|
|
:return: None
|
|
|
|
"""
|
2014-12-07 19:53:33 +00:00
|
|
|
|
|
|
|
# Which polygon.
|
2015-01-15 01:24:37 +00:00
|
|
|
poly = self.find_polygon(inside_pt)
|
2014-04-25 05:24:03 +00:00
|
|
|
|
2015-01-01 22:32:56 +00:00
|
|
|
# No polygon?
|
|
|
|
if poly is None:
|
|
|
|
self.app.log.warning('No polygon found.')
|
2015-01-15 01:24:37 +00:00
|
|
|
self.app.inform.emit('[warning] No polygon found.')
|
2015-01-01 22:32:56 +00:00
|
|
|
return
|
|
|
|
|
2015-02-02 01:03:03 +00:00
|
|
|
proc = self.app.proc_container.new("Painting polygon.")
|
|
|
|
|
2016-09-19 20:44:29 +00:00
|
|
|
name = outname or self.options["name"] + "_paint"
|
2015-08-30 22:22:54 +00:00
|
|
|
|
2014-09-22 01:51:50 +00:00
|
|
|
# Initializes the new geometry object
|
|
|
|
def gen_paintarea(geo_obj, app_obj):
|
2015-10-28 16:00:56 +00:00
|
|
|
assert isinstance(geo_obj, FlatCAMGeometry), \
|
|
|
|
"Initializer expected a FlatCAMGeometry, got %s" % type(geo_obj)
|
2014-09-22 01:51:50 +00:00
|
|
|
#assert isinstance(app_obj, App)
|
2015-01-01 22:32:56 +00:00
|
|
|
|
2014-12-07 19:53:33 +00:00
|
|
|
if self.options["paintmethod"] == "seed":
|
2016-09-23 18:04:31 +00:00
|
|
|
# Type(cp) == FlatCAMRTreeStorage | None
|
2015-08-30 22:22:54 +00:00
|
|
|
cp = self.clear_polygon2(poly.buffer(-self.options["paintmargin"]),
|
2016-11-01 04:34:46 +00:00
|
|
|
tooldia, overlap=overlap, connect=connect,
|
|
|
|
contour=contour)
|
2015-01-30 20:17:57 +00:00
|
|
|
|
2016-10-27 20:57:36 +00:00
|
|
|
elif self.options["paintmethod"] == "lines":
|
|
|
|
# Type(cp) == FlatCAMRTreeStorage | None
|
|
|
|
cp = self.clear_polygon3(poly.buffer(-self.options["paintmargin"]),
|
2016-11-01 04:34:46 +00:00
|
|
|
tooldia, overlap=overlap, connect=connect,
|
|
|
|
contour=contour)
|
2015-01-30 20:17:57 +00:00
|
|
|
else:
|
2016-09-23 18:04:31 +00:00
|
|
|
# Type(cp) == FlatCAMRTreeStorage | None
|
2015-08-30 22:22:54 +00:00
|
|
|
cp = self.clear_polygon(poly.buffer(-self.options["paintmargin"]),
|
2016-11-01 04:34:46 +00:00
|
|
|
tooldia, overlap=overlap, connect=connect,
|
|
|
|
contour=contour)
|
2015-01-30 20:17:57 +00:00
|
|
|
|
2016-09-23 18:04:31 +00:00
|
|
|
if cp is not None:
|
|
|
|
geo_obj.solid_geometry = list(cp.get_objects())
|
|
|
|
|
2014-09-22 01:51:50 +00:00
|
|
|
geo_obj.options["cnctooldia"] = tooldia
|
2016-09-19 20:44:29 +00:00
|
|
|
|
|
|
|
# Experimental...
|
|
|
|
print "Indexing...",
|
|
|
|
geo_obj.make_index()
|
|
|
|
print "Done"
|
|
|
|
|
|
|
|
self.app.inform.emit("Done.")
|
|
|
|
|
|
|
|
def job_thread(app_obj):
|
|
|
|
try:
|
|
|
|
app_obj.new_object("geometry", name, gen_paintarea)
|
|
|
|
except Exception as e:
|
|
|
|
proc.done()
|
|
|
|
raise e
|
|
|
|
proc.done()
|
|
|
|
|
|
|
|
self.app.inform.emit("Polygon Paint started ...")
|
|
|
|
|
|
|
|
# Promise object with the new name
|
|
|
|
self.app.collection.promise(name)
|
|
|
|
|
|
|
|
# Background
|
|
|
|
self.app.worker_task.emit({'fcn': job_thread, 'params': [self.app]})
|
|
|
|
|
2016-11-01 04:34:46 +00:00
|
|
|
def paint_poly_all(self, tooldia, overlap, outname=None,
|
|
|
|
connect=True, contour=True):
|
2016-09-25 17:11:03 +00:00
|
|
|
"""
|
|
|
|
Paints all polygons in this object.
|
|
|
|
|
|
|
|
:param tooldia:
|
|
|
|
:param overlap:
|
|
|
|
:param outname:
|
2016-11-01 04:34:46 +00:00
|
|
|
:param connect: Connect lines to avoid tool lifts.
|
|
|
|
:param contour: Paint around the edges.
|
2016-09-25 17:11:03 +00:00
|
|
|
:return:
|
|
|
|
"""
|
2016-09-19 20:44:29 +00:00
|
|
|
|
|
|
|
proc = self.app.proc_container.new("Painting polygon.")
|
|
|
|
|
|
|
|
name = outname or self.options["name"] + "_paint"
|
|
|
|
|
2016-09-23 18:04:31 +00:00
|
|
|
# This is a recursive generator of individual Polygons.
|
|
|
|
# Note: Double check correct implementation. Might exit
|
|
|
|
# early if it finds something that is not a Polygon?
|
2016-09-19 20:44:29 +00:00
|
|
|
def recurse(geo):
|
|
|
|
try:
|
|
|
|
for subg in geo:
|
|
|
|
for subsubg in recurse(subg):
|
|
|
|
yield subsubg
|
|
|
|
except TypeError:
|
|
|
|
if isinstance(geo, Polygon):
|
|
|
|
yield geo
|
|
|
|
|
|
|
|
raise StopIteration
|
|
|
|
|
|
|
|
# Initializes the new geometry object
|
|
|
|
def gen_paintarea(geo_obj, app_obj):
|
|
|
|
assert isinstance(geo_obj, FlatCAMGeometry), \
|
|
|
|
"Initializer expected a FlatCAMGeometry, got %s" % type(geo_obj)
|
|
|
|
|
|
|
|
geo_obj.solid_geometry = []
|
|
|
|
|
|
|
|
for poly in recurse(self.solid_geometry):
|
|
|
|
|
|
|
|
if self.options["paintmethod"] == "seed":
|
2016-09-23 18:04:31 +00:00
|
|
|
# Type(cp) == FlatCAMRTreeStorage | None
|
2016-09-19 20:44:29 +00:00
|
|
|
cp = self.clear_polygon2(poly.buffer(-self.options["paintmargin"]),
|
2016-11-01 04:34:46 +00:00
|
|
|
tooldia, overlap=overlap, contour=contour,
|
|
|
|
connect=connect)
|
2016-09-19 20:44:29 +00:00
|
|
|
|
2016-10-27 20:57:36 +00:00
|
|
|
elif self.options["paintmethod"] == "lines":
|
|
|
|
# Type(cp) == FlatCAMRTreeStorage | None
|
|
|
|
cp = self.clear_polygon3(poly.buffer(-self.options["paintmargin"]),
|
2016-11-01 04:34:46 +00:00
|
|
|
tooldia, overlap=overlap, contour=contour,
|
|
|
|
connect=connect)
|
2016-10-27 20:57:36 +00:00
|
|
|
|
2016-09-19 20:44:29 +00:00
|
|
|
else:
|
2016-09-23 18:04:31 +00:00
|
|
|
# Type(cp) == FlatCAMRTreeStorage | None
|
2016-09-19 20:44:29 +00:00
|
|
|
cp = self.clear_polygon(poly.buffer(-self.options["paintmargin"]),
|
2016-11-01 04:34:46 +00:00
|
|
|
tooldia, overlap=overlap, contour=contour,
|
|
|
|
connect=connect)
|
2016-09-19 20:44:29 +00:00
|
|
|
|
2016-09-23 18:04:31 +00:00
|
|
|
if cp is not None:
|
|
|
|
geo_obj.solid_geometry += list(cp.get_objects())
|
2016-09-19 20:44:29 +00:00
|
|
|
|
|
|
|
geo_obj.options["cnctooldia"] = tooldia
|
|
|
|
|
|
|
|
# Experimental...
|
|
|
|
print "Indexing...",
|
|
|
|
geo_obj.make_index()
|
|
|
|
print "Done"
|
|
|
|
|
2015-01-25 21:55:22 +00:00
|
|
|
self.app.inform.emit("Done.")
|
2014-09-22 01:51:50 +00:00
|
|
|
|
2015-01-29 22:02:06 +00:00
|
|
|
def job_thread(app_obj):
|
2015-02-13 19:37:54 +00:00
|
|
|
try:
|
|
|
|
app_obj.new_object("geometry", name, gen_paintarea)
|
|
|
|
except Exception as e:
|
|
|
|
proc.done()
|
2016-09-23 18:04:31 +00:00
|
|
|
traceback.print_stack()
|
2015-02-13 19:37:54 +00:00
|
|
|
raise e
|
2015-02-02 01:03:03 +00:00
|
|
|
proc.done()
|
2015-01-29 22:02:06 +00:00
|
|
|
|
|
|
|
self.app.inform.emit("Polygon Paint started ...")
|
2015-08-30 22:22:54 +00:00
|
|
|
|
|
|
|
# Promise object with the new name
|
|
|
|
self.app.collection.promise(name)
|
|
|
|
|
|
|
|
# Background
|
2015-01-29 22:02:06 +00:00
|
|
|
self.app.worker_task.emit({'fcn': job_thread, 'params': [self.app]})
|
2014-04-25 05:24:03 +00:00
|
|
|
|
|
|
|
def on_generatecnc_button_click(self, *args):
|
2014-10-13 22:16:43 +00:00
|
|
|
self.app.report_usage("geometry_on_generatecnc_button")
|
2014-04-25 05:24:03 +00:00
|
|
|
self.read_form()
|
2014-09-22 01:51:50 +00:00
|
|
|
self.generatecncjob()
|
|
|
|
|
2015-11-01 23:06:20 +00:00
|
|
|
def generatecncjob(self,
|
|
|
|
z_cut=None,
|
|
|
|
z_move=None,
|
|
|
|
feedrate=None,
|
|
|
|
tooldia=None,
|
|
|
|
outname=None,
|
|
|
|
spindlespeed=None,
|
|
|
|
multidepth=None,
|
2016-03-19 14:13:07 +00:00
|
|
|
depthperpass=None,
|
|
|
|
use_thread=True):
|
2015-08-30 22:22:54 +00:00
|
|
|
"""
|
2015-11-01 23:06:20 +00:00
|
|
|
Creates a CNCJob out of this Geometry object. The actual
|
|
|
|
work is done by the target FlatCAMCNCjob object's
|
|
|
|
`generate_from_geometry_2()` method.
|
2015-08-30 22:22:54 +00:00
|
|
|
|
|
|
|
:param z_cut: Cut depth (negative)
|
|
|
|
:param z_move: Hight of the tool when travelling (not cutting)
|
|
|
|
:param feedrate: Feed rate while cutting
|
|
|
|
:param tooldia: Tool diameter
|
|
|
|
:param outname: Name of the new object
|
|
|
|
:param spindlespeed: Spindle speed (RPM)
|
|
|
|
:return: None
|
|
|
|
"""
|
2014-09-22 01:51:50 +00:00
|
|
|
|
|
|
|
outname = outname if outname is not None else self.options["name"] + "_cnc"
|
|
|
|
z_cut = z_cut if z_cut is not None else self.options["cutz"]
|
|
|
|
z_move = z_move if z_move is not None else self.options["travelz"]
|
|
|
|
feedrate = feedrate if feedrate is not None else self.options["feedrate"]
|
|
|
|
tooldia = tooldia if tooldia is not None else self.options["cnctooldia"]
|
2015-11-01 23:06:20 +00:00
|
|
|
multidepth = multidepth if multidepth is not None else self.options["multidepth"]
|
|
|
|
depthperpass = depthperpass if depthperpass is not None else self.options["depthperpass"]
|
2015-07-17 07:49:24 +00:00
|
|
|
|
|
|
|
# To allow default value to be "" (optional in gui) and translate to None
|
2015-09-05 21:41:00 +00:00
|
|
|
# if not isinstance(spindlespeed, int):
|
|
|
|
# if isinstance(self.options["spindlespeed"], int) or \
|
|
|
|
# isinstance(self.options["spindlespeed"], float):
|
|
|
|
# spindlespeed = int(self.options["spindlespeed"])
|
|
|
|
# else:
|
|
|
|
# spindlespeed = None
|
|
|
|
|
|
|
|
if spindlespeed is None:
|
|
|
|
# int or None.
|
|
|
|
spindlespeed = self.options['spindlespeed']
|
2015-07-17 07:49:24 +00:00
|
|
|
|
2014-04-25 05:24:03 +00:00
|
|
|
# Object initialization function for app.new_object()
|
|
|
|
# RUNNING ON SEPARATE THREAD!
|
|
|
|
def job_init(job_obj, app_obj):
|
2015-10-28 16:00:56 +00:00
|
|
|
assert isinstance(job_obj, FlatCAMCNCjob), \
|
|
|
|
"Initializer expected a FlatCAMCNCjob, got %s" % type(job_obj)
|
|
|
|
|
2014-04-25 05:24:03 +00:00
|
|
|
# Propagate options
|
2014-09-22 01:51:50 +00:00
|
|
|
job_obj.options["tooldia"] = tooldia
|
2014-04-25 05:24:03 +00:00
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
app_obj.progress.emit(20)
|
2014-09-22 01:51:50 +00:00
|
|
|
job_obj.z_cut = z_cut
|
|
|
|
job_obj.z_move = z_move
|
|
|
|
job_obj.feedrate = feedrate
|
2015-07-17 07:49:24 +00:00
|
|
|
job_obj.spindlespeed = spindlespeed
|
2014-06-13 19:21:11 +00:00
|
|
|
app_obj.progress.emit(40)
|
2014-04-25 05:24:03 +00:00
|
|
|
# TODO: The tolerance should not be hard coded. Just for testing.
|
2015-11-01 23:06:20 +00:00
|
|
|
job_obj.generate_from_geometry_2(self,
|
|
|
|
multidepth=multidepth,
|
|
|
|
depthpercut=depthperpass,
|
|
|
|
tolerance=0.0005)
|
2014-04-25 05:24:03 +00:00
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
app_obj.progress.emit(50)
|
2014-04-25 05:24:03 +00:00
|
|
|
job_obj.gcode_parse()
|
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
app_obj.progress.emit(80)
|
2014-04-25 05:24:03 +00:00
|
|
|
|
2016-06-04 02:19:47 +00:00
|
|
|
if use_thread:
|
2016-03-19 14:13:07 +00:00
|
|
|
# To be run in separate thread
|
|
|
|
def job_thread(app_obj):
|
|
|
|
with self.app.proc_container.new("Generating CNC Job."):
|
|
|
|
app_obj.new_object("cncjob", outname, job_init)
|
|
|
|
app_obj.inform.emit("CNCjob created: %s" % outname)
|
|
|
|
app_obj.progress.emit(100)
|
2015-08-30 22:22:54 +00:00
|
|
|
|
2016-03-19 14:13:07 +00:00
|
|
|
# Create a promise with the name
|
|
|
|
self.app.collection.promise(outname)
|
|
|
|
|
|
|
|
# Send to worker
|
|
|
|
self.app.worker_task.emit({'fcn': job_thread, 'params': [self.app]})
|
|
|
|
else:
|
|
|
|
self.app.new_object("cncjob", outname, job_init)
|
2014-04-25 05:24:03 +00:00
|
|
|
|
2014-06-13 19:21:11 +00:00
|
|
|
def on_plot_cb_click(self, *args): # TODO: args not needed
|
2014-04-25 05:24:03 +00:00
|
|
|
if self.muted_ui:
|
|
|
|
return
|
|
|
|
self.read_form_item('plot')
|
|
|
|
self.plot()
|
|
|
|
|
2014-03-28 22:14:21 +00:00
|
|
|
def scale(self, factor):
|
|
|
|
"""
|
|
|
|
Scales all geometry by a given factor.
|
|
|
|
|
|
|
|
:param factor: Factor by which to scale the object's geometry/
|
|
|
|
:type factor: float
|
|
|
|
:return: None
|
|
|
|
:rtype: None
|
|
|
|
"""
|
|
|
|
|
|
|
|
if type(self.solid_geometry) == list:
|
|
|
|
self.solid_geometry = [affinity.scale(g, factor, factor, origin=(0, 0))
|
|
|
|
for g in self.solid_geometry]
|
|
|
|
else:
|
|
|
|
self.solid_geometry = affinity.scale(self.solid_geometry, factor, factor,
|
|
|
|
origin=(0, 0))
|
|
|
|
|
|
|
|
def offset(self, vect):
|
|
|
|
"""
|
|
|
|
Offsets all geometry by a given vector/
|
|
|
|
|
|
|
|
:param vect: (x, y) vector by which to offset the object's geometry.
|
|
|
|
:type vect: tuple
|
|
|
|
:return: None
|
|
|
|
:rtype: None
|
|
|
|
"""
|
|
|
|
|
|
|
|
dx, dy = vect
|
|
|
|
|
2016-02-21 16:03:59 +00:00
|
|
|
def translate_recursion(geom):
|
|
|
|
if type(geom) == list:
|
|
|
|
geoms=list()
|
|
|
|
for local_geom in geom:
|
|
|
|
geoms.append(translate_recursion(local_geom))
|
|
|
|
return geoms
|
|
|
|
else:
|
|
|
|
return affinity.translate(geom, xoff=dx, yoff=dy)
|
|
|
|
|
|
|
|
self.solid_geometry=translate_recursion(self.solid_geometry)
|
2014-03-28 22:14:21 +00:00
|
|
|
|
|
|
|
def convert_units(self, units):
|
|
|
|
factor = Geometry.convert_units(self, units)
|
|
|
|
|
|
|
|
self.options['cutz'] *= factor
|
|
|
|
self.options['travelz'] *= factor
|
|
|
|
self.options['feedrate'] *= factor
|
|
|
|
self.options['cnctooldia'] *= factor
|
|
|
|
self.options['painttooldia'] *= factor
|
|
|
|
self.options['paintmargin'] *= factor
|
|
|
|
|
|
|
|
return factor
|
|
|
|
|
2014-12-07 19:53:33 +00:00
|
|
|
def plot_element(self, element):
|
|
|
|
try:
|
|
|
|
for sub_el in element:
|
|
|
|
self.plot_element(sub_el)
|
2014-12-10 02:30:01 +00:00
|
|
|
|
|
|
|
except TypeError: # Element is not iterable...
|
|
|
|
|
2014-12-07 19:53:33 +00:00
|
|
|
if type(element) == Polygon:
|
|
|
|
x, y = element.exterior.coords.xy
|
|
|
|
self.axes.plot(x, y, 'r-')
|
|
|
|
for ints in element.interiors:
|
|
|
|
x, y = ints.coords.xy
|
|
|
|
self.axes.plot(x, y, 'r-')
|
|
|
|
return
|
|
|
|
|
|
|
|
if type(element) == LineString or type(element) == LinearRing:
|
|
|
|
x, y = element.coords.xy
|
|
|
|
self.axes.plot(x, y, 'r-')
|
|
|
|
return
|
|
|
|
|
2014-12-10 02:30:01 +00:00
|
|
|
FlatCAMApp.App.log.warning("Did not plot:" + str(type(element)))
|
2014-12-07 19:53:33 +00:00
|
|
|
|
2014-03-28 22:14:21 +00:00
|
|
|
def plot(self):
|
|
|
|
"""
|
|
|
|
Plots the object into its axes. If None, of if the axes
|
|
|
|
are not part of the app's figure, it fetches new ones.
|
|
|
|
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Does all the required setup and returns False
|
|
|
|
# if the 'ptint' option is set to False.
|
|
|
|
if not FlatCAMObj.plot(self):
|
|
|
|
return
|
|
|
|
|
|
|
|
# Make sure solid_geometry is iterable.
|
2014-09-22 01:51:50 +00:00
|
|
|
# TODO: This method should not modify the object !!!
|
2014-12-07 19:53:33 +00:00
|
|
|
# try:
|
|
|
|
# _ = iter(self.solid_geometry)
|
|
|
|
# except TypeError:
|
|
|
|
# if self.solid_geometry is None:
|
|
|
|
# self.solid_geometry = []
|
|
|
|
# else:
|
|
|
|
# self.solid_geometry = [self.solid_geometry]
|
|
|
|
#
|
|
|
|
# for geo in self.solid_geometry:
|
|
|
|
#
|
|
|
|
# if type(geo) == Polygon:
|
|
|
|
# x, y = geo.exterior.coords.xy
|
|
|
|
# self.axes.plot(x, y, 'r-')
|
|
|
|
# for ints in geo.interiors:
|
|
|
|
# x, y = ints.coords.xy
|
|
|
|
# self.axes.plot(x, y, 'r-')
|
|
|
|
# continue
|
|
|
|
#
|
|
|
|
# if type(geo) == LineString or type(geo) == LinearRing:
|
|
|
|
# x, y = geo.coords.xy
|
|
|
|
# self.axes.plot(x, y, 'r-')
|
|
|
|
# continue
|
|
|
|
#
|
|
|
|
# if type(geo) == MultiPolygon:
|
|
|
|
# for poly in geo:
|
|
|
|
# x, y = poly.exterior.coords.xy
|
|
|
|
# self.axes.plot(x, y, 'r-')
|
|
|
|
# for ints in poly.interiors:
|
|
|
|
# x, y = ints.coords.xy
|
|
|
|
# self.axes.plot(x, y, 'r-')
|
|
|
|
# continue
|
|
|
|
#
|
|
|
|
# FlatCAMApp.App.log.warning("Did not plot:", str(type(geo)))
|
2014-03-28 22:14:21 +00:00
|
|
|
|
2014-12-07 19:53:33 +00:00
|
|
|
self.plot_element(self.solid_geometry)
|
2014-03-28 22:14:21 +00:00
|
|
|
|
2015-06-19 23:25:22 +00:00
|
|
|
self.app.plotcanvas.auto_adjust_axes()
|