adding GUI interface for mirror and auto offset functions

This commit is contained in:
Idechix 2018-05-19 12:21:27 +02:00
parent bb3b07455c
commit 2a2d8d75cc
2 changed files with 76 additions and 1 deletions

View File

@ -92,7 +92,9 @@ class FlatCAMObj(QtCore.QObject):
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.auto_offset_button.clicked.connect(self.on_auto_offset_button_click)
self.ui.scale_button.clicked.connect(self.on_scale_button_click)
self.ui.mirror_button.clicked.connect(self.on_mirror_button_click)
def __str__(self):
return "<FlatCAMObj({:12s}): {:20s}>".format(self.kind, self.options["name"])
@ -110,6 +112,15 @@ class FlatCAMObj(QtCore.QObject):
vect = self.ui.offsetvector_entry.get_value()
self.offset(vect)
self.plot()
def on_auto_offset_button_click(self):
self.app.report_usage("obj_on_auto_offset_button")
self.read_form()
minx, miny, maxx, maxy = self.bounds()
vect = (-minx, -miny)
self.ui.offsetvector_entry.set_value(vect)
self.offset(vect)
self.plot()
def on_scale_button_click(self):
self.app.report_usage("obj_on_scale_button")
@ -118,6 +129,23 @@ class FlatCAMObj(QtCore.QObject):
self.scale(factor)
self.plot()
def on_mirror_button_click(self):
self.app.report_usage("obj_on_mirror_button")
self.read_form()
minx, miny, maxx, maxy = self.bounds()
axis = self.ui.mirror_axis_radio.get_value()
if not self.ui.mirror_auto_center_cb.get_value():
vect = (0, 0)
elif axis == 'X':
vect = (0, (maxy + miny)/2)
else:
vect = ((maxx + minx)/2, 0)
self.mirror(axis, vect)
self.plot()
def setup_axes(self, figure):
"""
1) Creates axes if they don't exist. 2) Clears axes. 3) Attaches

View File

@ -103,6 +103,46 @@ class ObjectUI(QtGui.QWidget):
)
layout.addWidget(self.offset_button)
self.auto_offset_button = QtGui.QPushButton('Offset auto')
self.auto_offset_button.setToolTip(
"Align the object with the x and y axes."
)
layout.addWidget(self.auto_offset_button)
#### Mirror ####
self.mirror_label = QtGui.QLabel('<b>Mirror:</b>')
self.mirror_label.setToolTip(
"Flip the object along an axis."
)
layout.addWidget(self.mirror_label)
self.mirror_axis_grid = QtGui.QGridLayout()
layout.addLayout(self.mirror_axis_grid)
axislabel = QtGui.QLabel('Axis:')
axislabel.setToolTip(
"Mirror axis parallel to the x or y axis."
)
self.mirror_axis_grid.addWidget(axislabel, 0, 0)
self.mirror_axis_radio = RadioSet([{'label': 'X', 'value': 'X'},
{'label': 'Y', 'value': 'Y'}])
self.mirror_axis_radio.set_value('Y')
self.mirror_axis_grid.addWidget(self.mirror_axis_radio, 0, 1)
self.mirror_auto_center_cb = FCCheckBox(label='Center axis automatically')
self.mirror_auto_center_cb.setToolTip(
"Place the mirror axis on the middle of the object."
)
self.mirror_auto_center_cb.set_value(True)
layout.addWidget(self.mirror_auto_center_cb)
self.mirror_button = QtGui.QPushButton('Mirror')
self.mirror_button.setToolTip(
"Perform the mirror operation."
)
layout.addWidget(self.mirror_button)
layout.addStretch()
@ -130,6 +170,13 @@ class CNCObjectUI(ObjectUI):
self.offset_grid.itemAt(i).widget().hide()
self.offset_label.hide()
self.offset_button.hide()
self.auto_offset_button.hide()
self.mirror_label.hide()
for i in range(0, self.mirror_axis_grid.count()):
self.mirror_axis_grid.itemAt(i).widget().hide()
self.mirror_auto_center_cb.hide()
self.mirror_button.hide()
## Plot options
self.plot_options_label = QtGui.QLabel("<b>Plot Options:</b>")
@ -801,7 +848,7 @@ class GerberObjectUI(ObjectUI):
self.generate_bb_button = QtGui.QPushButton('Generate Geometry')
self.generate_bb_button.setToolTip(
"Genrate the Geometry object."
"Generate the Geometry object."
)
self.custom_box.addWidget(self.generate_bb_button)