def __init__(self, parent=None): """ Creates the user interface for CNCJob objects. GUI elements should be placed in ``self.custom_box`` to preserve the layout. """ ObjectUI.__init__(self, title='CNC Job Object', icon_file='share/cnc32.png', parent=parent) # Scale and offset are not available for CNCJob objects. # Hiding from the GUI. for i in range(0, self.scale_grid.count()): self.scale_grid.itemAt(i).widget().hide() self.scale_label.hide() self.scale_button.hide() for i in range(0, self.offset_grid.count()): 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 = QtWidgets.QLabel("<b>Plot Options:</b>") self.custom_box.addWidget(self.plot_options_label) grid0 = QtWidgets.QGridLayout() self.custom_box.addLayout(grid0) # Plot CB # self.plot_cb = QtWidgets.QCheckBox('Plot') self.plot_cb = FCCheckBox('Plot') self.plot_cb.setToolTip("Plot (show) this object.") grid0.addWidget(self.plot_cb, 0, 0) # Tool dia for plot tdlabel = QtWidgets.QLabel('Tool dia:') tdlabel.setToolTip("Diameter of the tool to be\n" "rendered in the plot.") grid0.addWidget(tdlabel, 1, 0) self.tooldia_entry = LengthEntry() grid0.addWidget(self.tooldia_entry, 1, 1) # Update plot button self.updateplot_button = QtWidgets.QPushButton('Update Plot') self.updateplot_button.setToolTip("Update the plot.") self.custom_box.addWidget(self.updateplot_button) ################## ## Export G-Code ################## self.export_gcode_label = QtWidgets.QLabel("<b>Export G-Code:</b>") self.export_gcode_label.setToolTip("Export and save G-Code to\n" "make this object to a file.") self.custom_box.addWidget(self.export_gcode_label) # Prepend text to Gerber prependlabel = QtWidgets.QLabel('Prepend to G-Code:') prependlabel.setToolTip( "Type here any G-Code commands you would\n" "like to add to the beginning of the generated file.") self.custom_box.addWidget(prependlabel) self.prepend_text = FCTextArea() self.custom_box.addWidget(self.prepend_text) # Append text to Gerber appendlabel = QtWidgets.QLabel('Append to G-Code:') appendlabel.setToolTip("Type here any G-Code commands you would\n" "like to append to the generated file.\n" "I.e.: M2 (End of program)") self.custom_box.addWidget(appendlabel) self.append_text = FCTextArea() self.custom_box.addWidget(self.append_text) processorlabel = QtWidgets.QLabel('Postprocessing-Script:') processorlabel.setToolTip("Enter a Postprocessing Script here.\n" "It gets applied to the G-Code after it\n" "is generated.") self.custom_box.addWidget(processorlabel) self.process_script = FCTextArea() self.custom_box.addWidget(self.process_script) # Dwell grid1 = QtWidgets.QGridLayout() self.custom_box.addLayout(grid1) dwelllabel = QtWidgets.QLabel('Dwell:') dwelllabel.setToolTip("Pause to allow the spindle to reach its\n" "speed before cutting.") dwelltime = QtWidgets.QLabel('Duration [sec.]:') dwelltime.setToolTip("Number of second to dwell.") self.dwell_cb = FCCheckBox() self.dwelltime_entry = FCEntry() grid1.addWidget(dwelllabel, 0, 0) grid1.addWidget(self.dwell_cb, 0, 1) grid1.addWidget(dwelltime, 1, 0) grid1.addWidget(self.dwelltime_entry, 1, 1) # GO Button self.export_gcode_button = QtWidgets.QPushButton('Export G-Code') self.export_gcode_button.setToolTip("Opens dialog to save G-Code\n" "file.") self.custom_box.addWidget(self.export_gcode_button)
def __init__(self, icon_file='share/flatcam_icon32.png', title='FlatCAM Object', parent=None): QtWidgets.QWidget.__init__(self, parent=parent) layout = QtWidgets.QVBoxLayout() self.setLayout(layout) ## Page Title box (spacing between children) self.title_box = QtWidgets.QHBoxLayout() layout.addLayout(self.title_box) ## Page Title icon pixmap = QtWidgets.QPixmap(icon_file) self.icon = QtWidgets.QLabel() self.icon.setPixmap(pixmap) self.title_box.addWidget(self.icon, stretch=0) ## Title label self.title_label = QtWidgets.QLabel("<font size=5><b>" + title + "</b></font>") self.title_label.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) self.title_box.addWidget(self.title_label, stretch=1) ## Object name self.name_box = QtWidgets.QHBoxLayout() layout.addLayout(self.name_box) name_label = QtWidgets.QLabel("Name:") self.name_box.addWidget(name_label) self.name_entry = FCEntry() self.name_box.addWidget(self.name_entry) ## Box box for custom widgets # This gets populated in offspring implementations. self.custom_box = QtWidgets.QVBoxLayout() layout.addLayout(self.custom_box) ########################### ## Common to all objects ## ########################### #### Scale #### self.scale_label = QtWidgets.QLabel('<b>Scale:</b>') self.scale_label.setToolTip("Change the size of the object.") layout.addWidget(self.scale_label) self.scale_grid = QtWidgets.QGridLayout() layout.addLayout(self.scale_grid) # Factor faclabel = QtWidgets.QLabel('Factor:') faclabel.setToolTip("Factor by which to multiply\n" "geometric features of this object.") self.scale_grid.addWidget(faclabel, 0, 0) self.scale_entry = FloatEntry() self.scale_entry.set_value(1.0) self.scale_grid.addWidget(self.scale_entry, 0, 1) # GO Button self.scale_button = QtWidgets.QPushButton('Scale') self.scale_button.setToolTip("Perform scaling operation.") layout.addWidget(self.scale_button) #### Offset #### self.offset_label = QtWidgets.QLabel('<b>Offset:</b>') self.offset_label.setToolTip("Change the position of this object.") layout.addWidget(self.offset_label) self.offset_grid = QtWidgets.QGridLayout() layout.addLayout(self.offset_grid) self.offset_vectorlabel = QtWidgets.QLabel('Vector:') self.offset_vectorlabel.setToolTip( "Amount by which to move the object\n" "in the x and y axes in (x, y) format.") self.offset_grid.addWidget(self.offset_vectorlabel, 0, 0) self.offsetvector_entry = EvalEntry() self.offsetvector_entry.setText("(0.0, 0.0)") self.offset_grid.addWidget(self.offsetvector_entry, 0, 1) self.offset_button = QtWidgets.QPushButton('Offset') self.offset_button.setToolTip("Perform the offset operation.") layout.addWidget(self.offset_button) self.auto_offset_button = QtWidgets.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 = QtWidgets.QLabel('<b>Mirror:</b>') self.mirror_label.setToolTip("Flip the object along an axis.") layout.addWidget(self.mirror_label) self.mirror_axis_grid = QtWidgets.QGridLayout() layout.addLayout(self.mirror_axis_grid) axislabel = QtWidgets.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 = QtWidgets.QPushButton('Mirror') self.mirror_button.setToolTip("Perform the mirror operation.") layout.addWidget(self.mirror_button) layout.addStretch()
def __init__(self, parent=None): ObjectUI.__init__(self, title='Gerber Object', parent=parent) ## Plot options self.plot_options_label = QtGui.QLabel("<b>Plot Options:</b>") self.custom_box.addWidget(self.plot_options_label) grid0 = QtGui.QGridLayout() self.custom_box.addLayout(grid0) # Plot CB self.plot_cb = FCCheckBox(label='Plot') self.plot_options_label.setToolTip("Plot (show) this object.") grid0.addWidget(self.plot_cb, 0, 0) # Solid CB self.solid_cb = FCCheckBox(label='Solid') self.solid_cb.setToolTip("Solid color polygons.") grid0.addWidget(self.solid_cb, 0, 1) # Multicolored CB self.multicolored_cb = FCCheckBox(label='Multicolored') self.multicolored_cb.setToolTip("Draw polygons in different colors.") grid0.addWidget(self.multicolored_cb, 0, 2) ## Isolation Routing self.isolation_routing_label = QtGui.QLabel( "<b>Isolation Routing:</b>") self.isolation_routing_label.setToolTip( "Create a Geometry object with\n" "toolpaths to cut outside polygons.") self.custom_box.addWidget(self.isolation_routing_label) grid1 = QtGui.QGridLayout() self.custom_box.addLayout(grid1) tdlabel = QtGui.QLabel('Tool dia:') tdlabel.setToolTip("Diameter of the cutting tool.") grid1.addWidget(tdlabel, 0, 0) self.iso_tool_dia_entry = LengthEntry() grid1.addWidget(self.iso_tool_dia_entry, 0, 1) passlabel = QtGui.QLabel('Width (# passes):') passlabel.setToolTip("Width of the isolation gap in\n" "number (integer) of tool widths.") grid1.addWidget(passlabel, 1, 0) self.iso_width_entry = IntEntry() grid1.addWidget(self.iso_width_entry, 1, 1) overlabel = QtGui.QLabel('Pass overlap:') overlabel.setToolTip("How much (fraction of tool width)\n" "to overlap each pass.") grid1.addWidget(overlabel, 2, 0) self.iso_overlap_entry = FloatEntry() grid1.addWidget(self.iso_overlap_entry, 2, 1) # combine all passes CB self.combine_passes_cb = FCCheckBox(label='Combine Passes') self.combine_passes_cb.setToolTip("Combine all passes into one object") grid1.addWidget(self.combine_passes_cb, 3, 0) self.generate_iso_button = QtGui.QPushButton('Generate Geometry') self.generate_iso_button.setToolTip("Create the Geometry Object\n" "for isolation routing.") self.custom_box.addWidget(self.generate_iso_button) ## Clear non-copper regions self.clearcopper_label = QtGui.QLabel("<b>Clear non-copper:</b>") self.clearcopper_label.setToolTip( "Create a Geometry object with\n" "toolpaths to cut all non-copper regions.") self.custom_box.addWidget(self.clearcopper_label) grid5 = QtGui.QGridLayout() self.custom_box.addLayout(grid5) ncctdlabel = QtGui.QLabel('Tools dia:') ncctdlabel.setToolTip( "Diameters of the cutting tools, separated by ','") grid5.addWidget(ncctdlabel, 0, 0) self.ncc_tool_dia_entry = FCEntry() grid5.addWidget(self.ncc_tool_dia_entry, 0, 1) nccoverlabel = QtGui.QLabel('Overlap:') nccoverlabel.setToolTip("How much (fraction of tool width)\n" "to overlap each pass.") grid5.addWidget(nccoverlabel, 1, 0) self.ncc_overlap_entry = FloatEntry() grid5.addWidget(self.ncc_overlap_entry, 1, 1) nccmarginlabel = QtGui.QLabel('Margin:') nccmarginlabel.setToolTip("Bounding box margin.") grid5.addWidget(nccmarginlabel, 2, 0) self.ncc_margin_entry = FloatEntry() grid5.addWidget(self.ncc_margin_entry, 2, 1) self.generate_ncc_button = QtGui.QPushButton('Generate Geometry') self.generate_ncc_button.setToolTip("Create the Geometry Object\n" "for non-copper routing.") self.custom_box.addWidget(self.generate_ncc_button) ## Board cutout self.board_cutout_label = QtGui.QLabel("<b>Board cutout:</b>") self.board_cutout_label.setToolTip("Create toolpaths to cut around\n" "the PCB and separate it from\n" "the original board.") self.custom_box.addWidget(self.board_cutout_label) grid2 = QtGui.QGridLayout() self.custom_box.addLayout(grid2) tdclabel = QtGui.QLabel('Tool dia:') tdclabel.setToolTip("Diameter of the cutting tool.") grid2.addWidget(tdclabel, 0, 0) self.cutout_tooldia_entry = LengthEntry() grid2.addWidget(self.cutout_tooldia_entry, 0, 1) marginlabel = QtGui.QLabel('Margin:') marginlabel.setToolTip("Distance from objects at which\n" "to draw the cutout.") grid2.addWidget(marginlabel, 1, 0) self.cutout_margin_entry = LengthEntry() grid2.addWidget(self.cutout_margin_entry, 1, 1) gaplabel = QtGui.QLabel('Gap size:') gaplabel.setToolTip("Size of the gaps in the toolpath\n" "that will remain to hold the\n" "board in place.") grid2.addWidget(gaplabel, 2, 0) self.cutout_gap_entry = LengthEntry() grid2.addWidget(self.cutout_gap_entry, 2, 1) gapslabel = QtGui.QLabel('Gaps:') gapslabel.setToolTip("Where to place the gaps, Top/Bottom\n" "Left/Rigt, or on all 4 sides.") grid2.addWidget(gapslabel, 3, 0) self.gaps_radio = RadioSet([{ 'label': '2 (T/B)', 'value': 'tb' }, { 'label': '2 (L/R)', 'value': 'lr' }, { 'label': '4', 'value': '4' }]) grid2.addWidget(self.gaps_radio, 3, 1) self.generate_cutout_button = QtGui.QPushButton('Generate Geometry') self.generate_cutout_button.setToolTip("Generate the geometry for\n" "the board cutout.") self.custom_box.addWidget(self.generate_cutout_button) ## Non-copper regions self.noncopper_label = QtGui.QLabel("<b>Non-copper regions:</b>") self.noncopper_label.setToolTip("Create polygons covering the\n" "areas without copper on the PCB.\n" "Equivalent to the inverse of this\n" "object. Can be used to remove all\n" "copper from a specified region.") self.custom_box.addWidget(self.noncopper_label) grid3 = QtGui.QGridLayout() self.custom_box.addLayout(grid3) # Margin bmlabel = QtGui.QLabel('Boundary Margin:') bmlabel.setToolTip("Specify the edge of the PCB\n" "by drawing a box around all\n" "objects with this minimum\n" "distance.") grid3.addWidget(bmlabel, 0, 0) self.noncopper_margin_entry = LengthEntry() grid3.addWidget(self.noncopper_margin_entry, 0, 1) # Rounded corners self.noncopper_rounded_cb = FCCheckBox(label="Rounded corners") self.noncopper_rounded_cb.setToolTip( "Creates a Geometry objects with polygons\n" "covering the copper-free areas of the PCB.") grid3.addWidget(self.noncopper_rounded_cb, 1, 0, 1, 2) self.generate_noncopper_button = QtGui.QPushButton('Generate Geometry') self.custom_box.addWidget(self.generate_noncopper_button) ## Bounding box self.boundingbox_label = QtGui.QLabel('<b>Bounding Box:</b>') self.custom_box.addWidget(self.boundingbox_label) grid4 = QtGui.QGridLayout() self.custom_box.addLayout(grid4) bbmargin = QtGui.QLabel('Boundary Margin:') bbmargin.setToolTip("Distance of the edges of the box\n" "to the nearest polygon.") grid4.addWidget(bbmargin, 0, 0) self.bbmargin_entry = LengthEntry() grid4.addWidget(self.bbmargin_entry, 0, 1) self.bbrounded_cb = FCCheckBox(label="Rounded corners") self.bbrounded_cb.setToolTip("If the bounding box is \n" "to have rounded corners\n" "their radius is equal to\n" "the margin.") grid4.addWidget(self.bbrounded_cb, 1, 0, 1, 2) self.generate_bb_button = QtGui.QPushButton('Generate Geometry') self.generate_bb_button.setToolTip("Genrate the Geometry object.") self.custom_box.addWidget(self.generate_bb_button) # def main(): # # app = QtGui.QApplication(sys.argv) # fc = GerberObjectUI() # sys.exit(app.exec_()) # # # if __name__ == '__main__': # main()
def __init__(self, icon_file='share/flatcam_icon32.png', title='FlatCAM Object', parent=None): QtGui.QWidget.__init__(self, parent=parent) layout = QtGui.QVBoxLayout() self.setLayout(layout) ## Page Title box (spacing between children) self.title_box = QtGui.QHBoxLayout() layout.addLayout(self.title_box) ## Page Title icon pixmap = QtGui.QPixmap(icon_file) self.icon = QtGui.QLabel() self.icon.setPixmap(pixmap) self.title_box.addWidget(self.icon, stretch=0) ## Title label self.title_label = QtGui.QLabel("<font size=5><b>" + title + "</b></font>") self.title_label.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) self.title_box.addWidget(self.title_label, stretch=1) ## Object name self.name_box = QtGui.QHBoxLayout() layout.addLayout(self.name_box) name_label = QtGui.QLabel("Name:") self.name_box.addWidget(name_label) self.name_entry = FCEntry() self.name_box.addWidget(self.name_entry) ## Box box for custom widgets # This gets populated in offspring implementations. self.custom_box = QtGui.QVBoxLayout() layout.addLayout(self.custom_box) ########################### ## Common to all objects ## ########################### #### Scale #### self.scale_label = QtGui.QLabel('<b>Scale:</b>') self.scale_label.setToolTip("Change the size of the object.") layout.addWidget(self.scale_label) self.scale_grid = QtGui.QGridLayout() layout.addLayout(self.scale_grid) # Factor faclabel = QtGui.QLabel('Factor:') faclabel.setToolTip("Factor by which to multiply\n" "geometric features of this object.") self.scale_grid.addWidget(faclabel, 0, 0) self.scale_entry = FloatEntry() self.scale_entry.set_value(1.0) self.scale_grid.addWidget(self.scale_entry, 0, 1) # GO Button self.scale_button = QtGui.QPushButton('Scale') self.scale_button.setToolTip("Perform scaling operation.") layout.addWidget(self.scale_button) #### Offset #### self.offset_label = QtGui.QLabel('<b>Offset:</b>') self.offset_label.setToolTip("Change the position of this object.") layout.addWidget(self.offset_label) self.offset_grid = QtGui.QGridLayout() layout.addLayout(self.offset_grid) self.offset_vectorlabel = QtGui.QLabel('Vector:') self.offset_vectorlabel.setToolTip( "Amount by which to move the object\n" "in the x and y axes in (x, y) format.") self.offset_grid.addWidget(self.offset_vectorlabel, 0, 0) self.offsetvector_entry = EvalEntry() self.offsetvector_entry.setText("(0.0, 0.0)") self.offset_grid.addWidget(self.offsetvector_entry, 0, 1) self.offset_button = QtGui.QPushButton('Offset') self.offset_button.setToolTip("Perform the offset operation.") layout.addWidget(self.offset_button) layout.addStretch()
class ToolTransform(FlatCAMTool): toolName = "Object Transformation" rotateName = "Rotate Transformation" skewName = "Skew/Shear Transformation" flipName = "Flip Transformation" def __init__(self, app): FlatCAMTool.__init__(self, app) self.transform_lay = QVBoxLayout() self.layout.addLayout(self.transform_lay) ## Title title_label = QLabel("<font size=4><b>%s</b></font><br>" % self.toolName) self.transform_lay.addWidget(title_label) self.empty_label = QLabel("") self.empty_label.setFixedWidth(80) self.empty_label1 = QLabel("") self.empty_label1.setFixedWidth(80) self.empty_label2 = QLabel("") self.empty_label2.setFixedWidth(80) self.transform_lay.addWidget(self.empty_label) ## Rotate Title rotate_title_label = QLabel("<font size=3><b>%s</b></font>" % self.rotateName) self.transform_lay.addWidget(rotate_title_label) ## Form Layout form_layout = QFormLayout() self.transform_lay.addLayout(form_layout) self.rotate_entry = FCEntry() self.rotate_entry.setFixedWidth(70) self.rotate_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.rotate_label = QLabel("Angle Rotation:") self.rotate_label.setToolTip("Angle for Rotation action, in degrees.\n" "Float number between -360 and 359.\n" "Positive numbers for CW motion.\n" "Negative numbers for CCW motion.") self.rotate_label.setFixedWidth(80) self.rotate_button = FCButton() self.rotate_button.set_value("Rotate") self.rotate_button.setToolTip( "Rotate the selected object(s).\n" "The point of reference is the middle of\n" "the bounding box for all selected objects.\n") self.rotate_button.setFixedWidth(70) form_layout.addRow(self.rotate_label, self.rotate_entry) form_layout.addRow(self.empty_label, self.rotate_button) self.transform_lay.addWidget(self.empty_label1) ## Skew Title skew_title_label = QLabel("<font size=3><b>%s</b></font>" % self.skewName) self.transform_lay.addWidget(skew_title_label) ## Form Layout form1_layout = QFormLayout() self.transform_lay.addLayout(form1_layout) self.skewx_entry = FCEntry() self.skewx_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.skewx_entry.setFixedWidth(70) self.skewx_label = QLabel("Angle SkewX:") self.skewx_label.setToolTip("Angle for Skew action, in degrees.\n" "Float number between -360 and 359.") self.skewx_label.setFixedWidth(80) self.skewx_button = FCButton() self.skewx_button.set_value("Skew_X") self.skewx_button.setToolTip( "Skew/shear the selected object(s).\n" "The point of reference is the middle of\n" "the bounding box for all selected objects.\n") self.skewx_button.setFixedWidth(70) self.skewy_entry = FCEntry() self.skewy_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.skewy_entry.setFixedWidth(70) self.skewy_label = QLabel("Angle SkewY:") self.skewy_label.setToolTip("Angle for Skew action, in degrees.\n" "Float number between -360 and 359.") self.skewy_label.setFixedWidth(80) self.skewy_button = FCButton() self.skewy_button.set_value("Skew_Y") self.skewy_button.setToolTip( "Skew/shear the selected object(s).\n" "The point of reference is the middle of\n" "the bounding box for all selected objects.\n") self.skewy_button.setFixedWidth(70) form1_layout.addRow(self.skewx_label, self.skewx_entry) form1_layout.addRow(self.empty_label, self.skewx_button) form1_layout.addRow(self.skewy_label, self.skewy_entry) form1_layout.addRow(self.empty_label, self.skewy_button) self.transform_lay.addWidget(self.empty_label2) ## Flip Title flip_title_label = QLabel("<font size=3><b>%s</b></font>" % self.flipName) self.transform_lay.addWidget(flip_title_label) ## Form Layout form2_layout = QFormLayout() self.transform_lay.addLayout(form2_layout) self.flipx_button = FCButton() self.flipx_button.set_value("Flip_X") self.flipx_button.setToolTip( "Flip the selected object(s) over the X axis.\n" "Does not create a new object.\n ") self.flipx_button.setFixedWidth(70) self.flipy_button = FCButton() self.flipy_button.set_value("Flip_Y") self.flipy_button.setToolTip( "Flip the selected object(s) over the X axis.\n" "Does not create a new object.\n ") self.flipy_button.setFixedWidth(70) form2_layout.setSpacing(16) form2_layout.addRow(self.flipx_button, self.flipy_button) self.transform_lay.addStretch() ## Signals self.rotate_button.clicked.connect(self.on_rotate) self.skewx_button.clicked.connect(self.on_skewx) self.skewy_button.clicked.connect(self.on_skewy) self.flipx_button.clicked.connect(self.on_flipx) self.flipy_button.clicked.connect(self.on_flipy) self.rotate_entry.returnPressed.connect(self.on_rotate) self.skewx_entry.returnPressed.connect(self.on_skewx) self.skewy_entry.returnPressed.connect(self.on_skewy) ## Initialize form self.rotate_entry.set_value('0') self.skewx_entry.set_value('0') self.skewy_entry.set_value('0') def on_rotate(self): value = float(self.rotate_entry.get_value()) self.on_rotate_action(value) return def on_flipx(self): self.on_flip("Y") return def on_flipy(self): self.on_flip("X") return def on_skewx(self): value = float(self.skewx_entry.get_value()) self.on_skew("X", value) return def on_skewy(self): value = float(self.skewy_entry.get_value()) self.on_skew("Y", value) return def on_rotate_action(self, num): obj_list = self.app.collection.get_selected() xminlist = [] yminlist = [] xmaxlist = [] ymaxlist = [] if not obj_list: self.app.inform.emit("WARNING: No object selected.") msg = "Please Select an object to rotate!" warningbox = QtGui.QMessageBox() warningbox.setText(msg) warningbox.setWindowTitle("Warning ...") warningbox.setWindowIcon(QtGui.QIcon('share/warning.png')) warningbox.setStandardButtons(QtGui.QMessageBox.Ok) warningbox.setDefaultButton(QtGui.QMessageBox.Ok) warningbox.exec_() else: try: # first get a bounding box to fit all for obj in obj_list: xmin, ymin, xmax, ymax = obj.bounds() xminlist.append(xmin) yminlist.append(ymin) xmaxlist.append(xmax) ymaxlist.append(ymax) # get the minimum x,y and maximum x,y for all objects selected xminimal = min(xminlist) yminimal = min(yminlist) xmaximal = max(xmaxlist) ymaximal = max(ymaxlist) for sel_obj in obj_list: px = 0.5 * (xminimal + xmaximal) py = 0.5 * (yminimal + ymaximal) sel_obj.rotate(-num, point=(px, py)) sel_obj.plot() self.app.inform.emit('Object was rotated ...') except Exception as e: self.app.inform.emit( "[ERROR] Due of %s, rotation movement was not executed." % str(e)) raise def on_flip(self, axis): obj_list = self.app.collection.get_selected() xminlist = [] yminlist = [] xmaxlist = [] ymaxlist = [] if not obj_list: self.app.inform.emit("WARNING: No object selected.") msg = "Please Select an object to flip!" warningbox = QtGui.QMessageBox() warningbox.setText(msg) warningbox.setWindowTitle("Warning ...") warningbox.setWindowIcon(QtGui.QIcon('share/warning.png')) warningbox.setStandardButtons(QtGui.QMessageBox.Ok) warningbox.setDefaultButton(QtGui.QMessageBox.Ok) warningbox.exec_() return else: try: # first get a bounding box to fit all for obj in obj_list: xmin, ymin, xmax, ymax = obj.bounds() xminlist.append(xmin) yminlist.append(ymin) xmaxlist.append(xmax) ymaxlist.append(ymax) # get the minimum x,y and maximum x,y for all objects selected xminimal = min(xminlist) yminimal = min(yminlist) xmaximal = max(xmaxlist) ymaximal = max(ymaxlist) px = 0.5 * (xminimal + xmaximal) py = 0.5 * (yminimal + ymaximal) # execute mirroring for obj in obj_list: if axis is 'X': obj.mirror('X', [px, py]) obj.plot() self.app.inform.emit('Flipped on the Y axis ...') elif axis is 'Y': obj.mirror('Y', [px, py]) obj.plot() self.app.inform.emit('Flipped on the X axis ...') except Exception as e: self.app.inform.emit( "[ERROR] Due of %s, Flip action was not executed.") raise def on_skew(self, axis, num): obj_list = self.app.collection.get_selected() xminlist = [] yminlist = [] if not obj_list: self.app.inform.emit("WARNING: No object selected.") msg = "Please Select an object to skew/shear!" warningbox = QtGui.QMessageBox() warningbox.setText(msg) warningbox.setWindowTitle("Warning ...") warningbox.setWindowIcon(QtGui.QIcon('share/warning.png')) warningbox.setStandardButtons(QtGui.QMessageBox.Ok) warningbox.setDefaultButton(QtGui.QMessageBox.Ok) warningbox.exec_() else: try: # first get a bounding box to fit all for obj in obj_list: xmin, ymin, xmax, ymax = obj.bounds() xminlist.append(xmin) yminlist.append(ymin) # get the minimum x,y and maximum x,y for all objects selected xminimal = min(xminlist) yminimal = min(yminlist) for obj in obj_list: if axis is 'X': obj.skew(num, 0, point=(xminimal, yminimal)) elif axis is 'Y': obj.skew(0, num, point=(xminimal, yminimal)) obj.plot() self.app.inform.emit('Object was skewed on %s axis ...' % str(axis)) except Exception as e: self.app.inform.emit( "[ERROR] Due of %s, Skew action was not executed." % str(e)) raise # end of file
def __init__(self, app): FlatCAMTool.__init__(self, app) self.transform_lay = QVBoxLayout() self.layout.addLayout(self.transform_lay) ## Title title_label = QLabel("<font size=4><b>%s</b></font><br>" % self.toolName) self.transform_lay.addWidget(title_label) self.empty_label = QLabel("") self.empty_label.setFixedWidth(80) self.empty_label1 = QLabel("") self.empty_label1.setFixedWidth(80) self.empty_label2 = QLabel("") self.empty_label2.setFixedWidth(80) self.transform_lay.addWidget(self.empty_label) ## Rotate Title rotate_title_label = QLabel("<font size=3><b>%s</b></font>" % self.rotateName) self.transform_lay.addWidget(rotate_title_label) ## Form Layout form_layout = QFormLayout() self.transform_lay.addLayout(form_layout) self.rotate_entry = FCEntry() self.rotate_entry.setFixedWidth(70) self.rotate_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.rotate_label = QLabel("Angle Rotation:") self.rotate_label.setToolTip("Angle for Rotation action, in degrees.\n" "Float number between -360 and 359.\n" "Positive numbers for CW motion.\n" "Negative numbers for CCW motion.") self.rotate_label.setFixedWidth(80) self.rotate_button = FCButton() self.rotate_button.set_value("Rotate") self.rotate_button.setToolTip( "Rotate the selected object(s).\n" "The point of reference is the middle of\n" "the bounding box for all selected objects.\n") self.rotate_button.setFixedWidth(70) form_layout.addRow(self.rotate_label, self.rotate_entry) form_layout.addRow(self.empty_label, self.rotate_button) self.transform_lay.addWidget(self.empty_label1) ## Skew Title skew_title_label = QLabel("<font size=3><b>%s</b></font>" % self.skewName) self.transform_lay.addWidget(skew_title_label) ## Form Layout form1_layout = QFormLayout() self.transform_lay.addLayout(form1_layout) self.skewx_entry = FCEntry() self.skewx_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.skewx_entry.setFixedWidth(70) self.skewx_label = QLabel("Angle SkewX:") self.skewx_label.setToolTip("Angle for Skew action, in degrees.\n" "Float number between -360 and 359.") self.skewx_label.setFixedWidth(80) self.skewx_button = FCButton() self.skewx_button.set_value("Skew_X") self.skewx_button.setToolTip( "Skew/shear the selected object(s).\n" "The point of reference is the middle of\n" "the bounding box for all selected objects.\n") self.skewx_button.setFixedWidth(70) self.skewy_entry = FCEntry() self.skewy_entry.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.skewy_entry.setFixedWidth(70) self.skewy_label = QLabel("Angle SkewY:") self.skewy_label.setToolTip("Angle for Skew action, in degrees.\n" "Float number between -360 and 359.") self.skewy_label.setFixedWidth(80) self.skewy_button = FCButton() self.skewy_button.set_value("Skew_Y") self.skewy_button.setToolTip( "Skew/shear the selected object(s).\n" "The point of reference is the middle of\n" "the bounding box for all selected objects.\n") self.skewy_button.setFixedWidth(70) form1_layout.addRow(self.skewx_label, self.skewx_entry) form1_layout.addRow(self.empty_label, self.skewx_button) form1_layout.addRow(self.skewy_label, self.skewy_entry) form1_layout.addRow(self.empty_label, self.skewy_button) self.transform_lay.addWidget(self.empty_label2) ## Flip Title flip_title_label = QLabel("<font size=3><b>%s</b></font>" % self.flipName) self.transform_lay.addWidget(flip_title_label) ## Form Layout form2_layout = QFormLayout() self.transform_lay.addLayout(form2_layout) self.flipx_button = FCButton() self.flipx_button.set_value("Flip_X") self.flipx_button.setToolTip( "Flip the selected object(s) over the X axis.\n" "Does not create a new object.\n ") self.flipx_button.setFixedWidth(70) self.flipy_button = FCButton() self.flipy_button.set_value("Flip_Y") self.flipy_button.setToolTip( "Flip the selected object(s) over the X axis.\n" "Does not create a new object.\n ") self.flipy_button.setFixedWidth(70) form2_layout.setSpacing(16) form2_layout.addRow(self.flipx_button, self.flipy_button) self.transform_lay.addStretch() ## Signals self.rotate_button.clicked.connect(self.on_rotate) self.skewx_button.clicked.connect(self.on_skewx) self.skewy_button.clicked.connect(self.on_skewy) self.flipx_button.clicked.connect(self.on_flipx) self.flipy_button.clicked.connect(self.on_flipy) self.rotate_entry.returnPressed.connect(self.on_rotate) self.skewx_entry.returnPressed.connect(self.on_skewx) self.skewy_entry.returnPressed.connect(self.on_skewy) ## Initialize form self.rotate_entry.set_value('0') self.skewx_entry.set_value('0') self.skewy_entry.set_value('0')