Example #1
0
    def __init__(self, parent=None):
        ObjectUI.__init__(self, title='Gerber Object', parent=parent)

        ## 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 = 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 = QtWidgets.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 = QtWidgets.QGridLayout()
        self.custom_box.addLayout(grid1)
        tdlabel = QtWidgets.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 = QtWidgets.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 = QtWidgets.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 = QtWidgets.QPushButton('Generate Geometry')
        self.generate_iso_button.setToolTip("Create the Geometry Object\n"
                                            "for isolation routing.")
        self.custom_box.addWidget(self.generate_iso_button)

        ## Board cuttout
        self.board_cutout_label = QtWidgets.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 = QtWidgets.QGridLayout()
        self.custom_box.addLayout(grid2)
        tdclabel = QtWidgets.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 = QtWidgets.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 = QtWidgets.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 = QtWidgets.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 = QtWidgets.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 = QtWidgets.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 = QtWidgets.QGridLayout()
        self.custom_box.addLayout(grid3)

        # Margin
        bmlabel = QtWidgets.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 = QtWidgets.QPushButton(
            'Generate Geometry')
        self.custom_box.addWidget(self.generate_noncopper_button)

        ## Bounding box
        self.boundingbox_label = QtWidgets.QLabel('<b>Bounding Box:</b>')
        self.custom_box.addWidget(self.boundingbox_label)

        grid4 = QtWidgets.QGridLayout()
        self.custom_box.addLayout(grid4)

        bbmargin = QtWidgets.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 = QtWidgets.QPushButton('Generate Geometry')
        self.generate_bb_button.setToolTip("Generate the Geometry object.")
        self.custom_box.addWidget(self.generate_bb_button)
Example #2
0
class ObjectUI(QtWidgets.QWidget):
    """
    Base class for the UI of FlatCAM objects. Deriving classes should
    put UI elements in ObjectUI.custom_box (QtWidgets.QLayout).
    """
    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()
Example #3
0
    def __init__(self, parent=None):
        super(GeometryObjectUI,
              self).__init__(title='Geometry Object',
                             icon_file='share/geometry32.png',
                             parent=parent)

        ## Plot options
        self.plot_options_label = QtWidgets.QLabel("<b>Plot Options:</b>")
        self.custom_box.addWidget(self.plot_options_label)

        # Plot CB
        self.plot_cb = FCCheckBox(label='Plot')
        self.plot_cb.setToolTip("Plot (show) this object.")
        self.custom_box.addWidget(self.plot_cb)

        #-----------------------------------
        # Create CNC Job
        #-----------------------------------
        self.cncjob_label = QtWidgets.QLabel('<b>Create CNC Job:</b>')
        self.cncjob_label.setToolTip("Create a CNC Job object\n"
                                     "tracing the contours of this\n"
                                     "Geometry object.")
        self.custom_box.addWidget(self.cncjob_label)

        grid1 = QtWidgets.QGridLayout()
        self.custom_box.addLayout(grid1)

        cutzlabel = QtWidgets.QLabel('Cut Z:')
        cutzlabel.setToolTip("Cutting depth (negative)\n"
                             "below the copper surface.")
        grid1.addWidget(cutzlabel, 0, 0)
        self.cutz_entry = LengthEntry()
        grid1.addWidget(self.cutz_entry, 0, 1)

        # Travel Z
        travelzlabel = QtWidgets.QLabel('Travel Z:')
        travelzlabel.setToolTip("Height of the tool when\n"
                                "moving without cutting.")
        grid1.addWidget(travelzlabel, 1, 0)
        self.travelz_entry = LengthEntry()
        grid1.addWidget(self.travelz_entry, 1, 1)

        # Feedrate
        frlabel = QtWidgets.QLabel('Feed Rate:')
        frlabel.setToolTip("Cutting speed in the XY\n"
                           "plane in units per minute")
        grid1.addWidget(frlabel, 2, 0)
        self.cncfeedrate_entry = LengthEntry()
        grid1.addWidget(self.cncfeedrate_entry, 2, 1)

        # Tooldia
        tdlabel = QtWidgets.QLabel('Tool dia:')
        tdlabel.setToolTip("The diameter of the cutting\n"
                           "tool (just for display).")
        grid1.addWidget(tdlabel, 3, 0)
        self.cnctooldia_entry = LengthEntry()
        grid1.addWidget(self.cnctooldia_entry, 3, 1)

        # Spindlespeed
        spdlabel = QtWidgets.QLabel('Spindle speed:')
        spdlabel.setToolTip("Speed of the spindle\n" "in RPM (optional)")
        grid1.addWidget(spdlabel, 4, 0)
        self.cncspindlespeed_entry = IntEntry(allow_empty=True)
        grid1.addWidget(self.cncspindlespeed_entry, 4, 1)

        # Multi-pass
        mpasslabel = QtWidgets.QLabel('Multi-Depth:')
        mpasslabel.setToolTip("Use multiple passes to limit\n"
                              "the cut depth in each pass. Will\n"
                              "cut multiple times until Cut Z is\n"
                              "reached.")
        grid1.addWidget(mpasslabel, 5, 0)
        self.mpass_cb = FCCheckBox()
        grid1.addWidget(self.mpass_cb, 5, 1)

        maxdepthlabel = QtWidgets.QLabel('Depth/pass:'******'Generate')
        self.generate_cnc_button.setToolTip("Generate the CNC Job object.")
        self.custom_box.addWidget(self.generate_cnc_button)

        #------------------------------
        # Paint area
        #------------------------------
        self.paint_label = QtWidgets.QLabel('<b>Paint Area:</b>')
        self.paint_label.setToolTip("Creates tool paths to cover the\n"
                                    "whole area of a polygon (remove\n"
                                    "all copper). You will be asked\n"
                                    "to click on the desired polygon.")
        self.custom_box.addWidget(self.paint_label)

        grid2 = QtWidgets.QGridLayout()
        self.custom_box.addLayout(grid2)

        # Tool dia
        ptdlabel = QtWidgets.QLabel('Tool dia:')
        ptdlabel.setToolTip("Diameter of the tool to\n"
                            "be used in the operation.")
        grid2.addWidget(ptdlabel, 0, 0)

        self.painttooldia_entry = LengthEntry()
        grid2.addWidget(self.painttooldia_entry, 0, 1)

        # Overlap
        ovlabel = QtWidgets.QLabel('Overlap:')
        ovlabel.setToolTip("How much (fraction) of the tool\n"
                           "width to overlap each tool pass.")
        grid2.addWidget(ovlabel, 1, 0)
        self.paintoverlap_entry = LengthEntry()
        grid2.addWidget(self.paintoverlap_entry, 1, 1)

        # Margin
        marginlabel = QtWidgets.QLabel('Margin:')
        marginlabel.setToolTip("Distance by which to avoid\n"
                               "the edges of the polygon to\n"
                               "be painted.")
        grid2.addWidget(marginlabel, 2, 0)
        self.paintmargin_entry = LengthEntry()
        grid2.addWidget(self.paintmargin_entry, 2, 1)

        # Method
        methodlabel = QtWidgets.QLabel('Method:')
        methodlabel.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
        methodlabel.setToolTip("Algorithm to paint the polygon:<BR>"
                               "<B>Standard</B>: Fixed step inwards.<BR>"
                               "<B>Seed-based</B>: Outwards from seed.")
        grid2.addWidget(methodlabel, 3, 0)
        self.paintmethod_combo = RadioSet([{
            "label": "Standard",
            "value": "standard"
        }, {
            "label": "Seed-based",
            "value": "seed"
        }, {
            "label": "Straight lines",
            "value": "lines"
        }],
                                          orientation='vertical')
        grid2.addWidget(self.paintmethod_combo, 3, 1)

        # Connect lines
        pathconnectlabel = QtWidgets.QLabel("Connect:")
        pathconnectlabel.setToolTip("Draw lines between resulting\n"
                                    "segments to minimize tool lifts.")
        grid2.addWidget(pathconnectlabel, 4, 0)
        self.pathconnect_cb = FCCheckBox()
        grid2.addWidget(self.pathconnect_cb, 4, 1)

        contourlabel = QtWidgets.QLabel("Contour:")
        contourlabel.setToolTip("Cut around the perimeter of the polygon\n"
                                "to trim rough edges.")
        grid2.addWidget(contourlabel, 5, 0)
        self.paintcontour_cb = FCCheckBox()
        grid2.addWidget(self.paintcontour_cb, 5, 1)

        # Polygon selection
        selectlabel = QtWidgets.QLabel('Selection:')
        selectlabel.setToolTip("How to select the polygons to paint.")
        grid2.addWidget(selectlabel, 6, 0)
        #grid3 = QtWidgets.QGridLayout()
        self.selectmethod_combo = RadioSet([
            {
                "label": "Single",
                "value": "single"
            },
            {
                "label": "All",
                "value": "all"
            },
            #{"label": "Rectangle", "value": "rectangle"}
        ])
        grid2.addWidget(self.selectmethod_combo, 6, 1)

        # GO Button
        self.generate_paint_button = QtWidgets.QPushButton('Generate')
        self.generate_paint_button.setToolTip(
            "After clicking here, click inside\n"
            "the polygon you wish to be painted.\n"
            "A new Geometry object with the tool\n"
            "paths will be created.")
        self.custom_box.addWidget(self.generate_paint_button)
Example #4
0
class DblSidedTool(FlatCAMTool):

    toolName = "Double-Sided PCB Tool"

    def __init__(self, app):
        FlatCAMTool.__init__(self, app)

        ## Title
        title_label = QtGui.QLabel("<font size=4><b>%s</b></font>" % self.toolName)
        self.layout.addWidget(title_label)

        ## Form Layout
        form_layout = QtGui.QFormLayout()
        self.layout.addLayout(form_layout)

        ## Layer to mirror
        self.object_combo = QtGui.QComboBox()
        self.object_combo.setModel(self.app.collection)
        self.botlay_label = QtGui.QLabel("Bottom Layer:")
        self.botlay_label.setToolTip(
            "Layer to be mirrorer."
        )
        # form_layout.addRow("Bottom Layer:", self.object_combo)
        form_layout.addRow(self.botlay_label, self.object_combo)

        ## Axis
        self.mirror_axis = RadioSet([{'label': 'X', 'value': 'X'},
                                     {'label': 'Y', 'value': 'Y'}])
        self.mirax_label = QtGui.QLabel("Mirror Axis:")
        self.mirax_label.setToolTip(
            "Mirror vertically (X) or horizontally (Y)."
        )
        # form_layout.addRow("Mirror Axis:", self.mirror_axis)
        form_layout.addRow(self.mirax_label, self.mirror_axis)

        ## Axis Location
        self.axis_location = RadioSet([{'label': 'Point', 'value': 'point'},
                                       {'label': 'Box', 'value': 'box'}])
        self.axloc_label = QtGui.QLabel("Axis Location:")
        self.axloc_label.setToolTip(
            "The axis should pass through a <b>point</b> or cut "
            "a specified <b>box</b> (in a Geometry object) in "
            "the middle."
        )
        # form_layout.addRow("Axis Location:", self.axis_location)
        form_layout.addRow(self.axloc_label, self.axis_location)

        ## Point/Box
        self.point_box_container = QtGui.QVBoxLayout()
        self.pb_label = QtGui.QLabel("Point/Box:")
        self.pb_label.setToolTip(
            "Specify the point (x, y) through which the mirror axis "
            "passes or the Geometry object containing a rectangle "
            "that the mirror axis cuts in half."
        )
        # form_layout.addRow("Point/Box:", self.point_box_container)
        form_layout.addRow(self.pb_label, self.point_box_container)

        self.point = EvalEntry()
        self.point_box_container.addWidget(self.point)
        self.box_combo = QtGui.QComboBox()
        self.box_combo.setModel(self.app.collection)
        self.point_box_container.addWidget(self.box_combo)
        self.box_combo.hide()

        ## Alignment holes
        self.alignment_holes = EvalEntry()
        self.ah_label = QtGui.QLabel("Alignment Holes:")
        self.ah_label.setToolTip(
            "Alignment holes (x1, y1), (x2, y2), ... "
            "on one side of the mirror axis."
        )
        form_layout.addRow(self.ah_label, self.alignment_holes)

        ## Drill diameter for alignment holes
        self.drill_dia = LengthEntry()
        self.dd_label = QtGui.QLabel("Drill diam.:")
        self.dd_label.setToolTip(
            "Diameter of the drill for the "
            "alignment holes."
        )
        form_layout.addRow(self.dd_label, self.drill_dia)

        ## Buttons
        hlay = QtGui.QHBoxLayout()
        self.layout.addLayout(hlay)
        hlay.addStretch()
        self.create_alignment_hole_button = QtGui.QPushButton("Create Alignment Drill")
        self.create_alignment_hole_button.setToolTip(
            "Creates an Excellon Object containing the "
            "specified alignment holes and their mirror "
            "images."
        )
        self.mirror_object_button = QtGui.QPushButton("Mirror Object")
        self.mirror_object_button.setToolTip(
            "Mirrors (flips) the specified object around "
            "the specified axis. Does not create a new "
            "object, but modifies it."
        )
        hlay.addWidget(self.create_alignment_hole_button)
        hlay.addWidget(self.mirror_object_button)

        self.layout.addStretch()

        ## Signals
        self.create_alignment_hole_button.clicked.connect(self.on_create_alignment_holes)
        self.mirror_object_button.clicked.connect(self.on_mirror)

        self.axis_location.group_toggle_fn = self.on_toggle_pointbox

        ## Initialize form
        self.mirror_axis.set_value('X')
        self.axis_location.set_value('point')

    def on_create_alignment_holes(self):
        axis = self.mirror_axis.get_value()
        mode = self.axis_location.get_value()

        if mode == "point":
            px, py = self.point.get_value()
        else:
            selection_index = self.box_combo.currentIndex()
            bb_obj = self.app.collection.object_list[selection_index]  # TODO: Direct access??
            xmin, ymin, xmax, ymax = bb_obj.bounds()
            px = 0.5 * (xmin + xmax)
            py = 0.5 * (ymin + ymax)

        xscale, yscale = {"X": (1.0, -1.0), "Y": (-1.0, 1.0)}[axis]

        dia = self.drill_dia.get_value()
        tools = {"1": {"C": dia}}

        # holes = self.alignment_holes.get_value()
        holes = eval('[{}]'.format(self.alignment_holes.text()))
        drills = []

        for hole in holes:
            point = Point(hole)
            point_mirror = affinity.scale(point, xscale, yscale, origin=(px, py))
            drills.append({"point": point, "tool": "1"})
            drills.append({"point": point_mirror, "tool": "1"})

        def obj_init(obj_inst, app_inst):
            obj_inst.tools = tools
            obj_inst.drills = drills
            obj_inst.create_geometry()

        self.app.new_object("excellon", "Alignment Drills", obj_init)

    def on_mirror(self):
        selection_index = self.object_combo.currentIndex()
        fcobj = self.app.collection.object_list[selection_index]

        # For now, lets limit to Gerbers and Excellons.
        # assert isinstance(gerb, FlatCAMGerber)
        if not isinstance(fcobj, FlatCAMGerber) and \
                not isinstance(fcobj, FlatCAMExcellon) and \
                not isinstance(fcobj, FlatCAMGeometry):
            self.info("ERROR: Only Gerber, Excellon and Geometry objects can be mirrored.")
            return

        axis = self.mirror_axis.get_value()
        mode = self.axis_location.get_value()

        if mode == "point":
            px, py = self.point.get_value()
        else:
            selection_index = self.box_combo.currentIndex()
            bb_obj = self.app.collection.object_list[selection_index]  # TODO: Direct access??
            xmin, ymin, xmax, ymax = bb_obj.bounds()
            px = 0.5 * (xmin + xmax)
            py = 0.5 * (ymin + ymax)

        fcobj.mirror(axis, [px, py])
        fcobj.plot()

    def on_toggle_pointbox(self):
        if self.axis_location.get_value() == "point":
            self.point.show()
            self.box_combo.hide()
        else:
            self.point.hide()
            self.box_combo.show()
Example #5
0
    def __init__(self, app):
        FlatCAMTool.__init__(self, app)

        ## Title
        title_label = QtGui.QLabel("<font size=4><b>%s</b></font>" % self.toolName)
        self.layout.addWidget(title_label)

        ## Form Layout
        form_layout = QtGui.QFormLayout()
        self.layout.addLayout(form_layout)

        ## Layer to mirror
        self.object_combo = QtGui.QComboBox()
        self.object_combo.setModel(self.app.collection)
        self.botlay_label = QtGui.QLabel("Bottom Layer:")
        self.botlay_label.setToolTip(
            "Layer to be mirrorer."
        )
        # form_layout.addRow("Bottom Layer:", self.object_combo)
        form_layout.addRow(self.botlay_label, self.object_combo)

        ## Axis
        self.mirror_axis = RadioSet([{'label': 'X', 'value': 'X'},
                                     {'label': 'Y', 'value': 'Y'}])
        self.mirax_label = QtGui.QLabel("Mirror Axis:")
        self.mirax_label.setToolTip(
            "Mirror vertically (X) or horizontally (Y)."
        )
        # form_layout.addRow("Mirror Axis:", self.mirror_axis)
        form_layout.addRow(self.mirax_label, self.mirror_axis)

        ## Axis Location
        self.axis_location = RadioSet([{'label': 'Point', 'value': 'point'},
                                       {'label': 'Box', 'value': 'box'}])
        self.axloc_label = QtGui.QLabel("Axis Location:")
        self.axloc_label.setToolTip(
            "The axis should pass through a <b>point</b> or cut "
            "a specified <b>box</b> (in a Geometry object) in "
            "the middle."
        )
        # form_layout.addRow("Axis Location:", self.axis_location)
        form_layout.addRow(self.axloc_label, self.axis_location)

        ## Point/Box
        self.point_box_container = QtGui.QVBoxLayout()
        self.pb_label = QtGui.QLabel("Point/Box:")
        self.pb_label.setToolTip(
            "Specify the point (x, y) through which the mirror axis "
            "passes or the Geometry object containing a rectangle "
            "that the mirror axis cuts in half."
        )
        # form_layout.addRow("Point/Box:", self.point_box_container)
        form_layout.addRow(self.pb_label, self.point_box_container)

        self.point = EvalEntry()
        self.point_box_container.addWidget(self.point)
        self.box_combo = QtGui.QComboBox()
        self.box_combo.setModel(self.app.collection)
        self.point_box_container.addWidget(self.box_combo)
        self.box_combo.hide()

        ## Alignment holes
        self.alignment_holes = EvalEntry()
        self.ah_label = QtGui.QLabel("Alignment Holes:")
        self.ah_label.setToolTip(
            "Alignment holes (x1, y1), (x2, y2), ... "
            "on one side of the mirror axis."
        )
        form_layout.addRow(self.ah_label, self.alignment_holes)

        ## Drill diameter for alignment holes
        self.drill_dia = LengthEntry()
        self.dd_label = QtGui.QLabel("Drill diam.:")
        self.dd_label.setToolTip(
            "Diameter of the drill for the "
            "alignment holes."
        )
        form_layout.addRow(self.dd_label, self.drill_dia)

        ## Buttons
        hlay = QtGui.QHBoxLayout()
        self.layout.addLayout(hlay)
        hlay.addStretch()
        self.create_alignment_hole_button = QtGui.QPushButton("Create Alignment Drill")
        self.create_alignment_hole_button.setToolTip(
            "Creates an Excellon Object containing the "
            "specified alignment holes and their mirror "
            "images."
        )
        self.mirror_object_button = QtGui.QPushButton("Mirror Object")
        self.mirror_object_button.setToolTip(
            "Mirrors (flips) the specified object around "
            "the specified axis. Does not create a new "
            "object, but modifies it."
        )
        hlay.addWidget(self.create_alignment_hole_button)
        hlay.addWidget(self.mirror_object_button)

        self.layout.addStretch()

        ## Signals
        self.create_alignment_hole_button.clicked.connect(self.on_create_alignment_holes)
        self.mirror_object_button.clicked.connect(self.on_mirror)

        self.axis_location.group_toggle_fn = self.on_toggle_pointbox

        ## Initialize form
        self.mirror_axis.set_value('X')
        self.axis_location.set_value('point')
Example #6
0
    def __init__(self, app):
        FlatCAMTool.__init__(self, app)

        ## Title
        title_label = QtGui.QLabel("<font size=4><b>%s</b></font>" % self.toolName)
        self.layout.addWidget(title_label)

        ## Form Layout
        form_layout = QtGui.QFormLayout()
        self.layout.addLayout(form_layout)

        ## Layer to mirror
        self.object_combo = QtGui.QComboBox()
        self.object_combo.setModel(self.app.collection)
        self.botlay_label = QtGui.QLabel("Bottom Layer:")
        self.botlay_label.setToolTip("Layer to be mirrorer.")
        # form_layout.addRow("Bottom Layer:", self.object_combo)
        form_layout.addRow(self.botlay_label, self.object_combo)

        ## Axis
        self.mirror_axis = RadioSet([{"label": "X", "value": "X"}, {"label": "Y", "value": "Y"}])
        self.mirax_label = QtGui.QLabel("Mirror Axis:")
        self.mirax_label.setToolTip("Mirror vertically (X) or horizontally (Y).")
        # form_layout.addRow("Mirror Axis:", self.mirror_axis)
        form_layout.addRow(self.mirax_label, self.mirror_axis)

        ## Axis Location
        self.axis_location = RadioSet([{"label": "Point", "value": "point"}, {"label": "Box", "value": "box"}])
        self.axloc_label = QtGui.QLabel("Axis Location:")
        self.axloc_label.setToolTip(
            "The axis should pass through a <b>point</b> or cut "
            "a specified <b>box</b> (in a Geometry object) in "
            "the middle."
        )
        # form_layout.addRow("Axis Location:", self.axis_location)
        form_layout.addRow(self.axloc_label, self.axis_location)

        ## Point/Box
        self.point_box_container = QtGui.QVBoxLayout()
        self.pb_label = QtGui.QLabel("Point/Box:")
        self.pb_label.setToolTip(
            "Specify the point (x, y) through which the mirror axis "
            "passes or the Geometry object containing a rectangle "
            "that the mirror axis cuts in half."
        )
        # form_layout.addRow("Point/Box:", self.point_box_container)
        form_layout.addRow(self.pb_label, self.point_box_container)

        self.point = EvalEntry()
        self.point_box_container.addWidget(self.point)
        self.box_combo = QtGui.QComboBox()
        self.box_combo.setModel(self.app.collection)
        self.point_box_container.addWidget(self.box_combo)
        self.box_combo.hide()

        ## Alignment holes
        self.alignment_holes = EvalEntry()
        self.ah_label = QtGui.QLabel("Alignment Holes:")
        self.ah_label.setToolTip("Alignment holes (x1, y1), (x2, y2), ... " "on one side of the mirror axis.")
        form_layout.addRow(self.ah_label, self.alignment_holes)

        ## Drill diameter for alignment holes
        self.drill_dia = LengthEntry()
        self.dd_label = QtGui.QLabel("Drill diam.:")
        self.dd_label.setToolTip("Diameter of the drill for the " "alignment holes.")
        form_layout.addRow(self.dd_label, self.drill_dia)

        ## Buttons
        hlay = QtGui.QHBoxLayout()
        self.layout.addLayout(hlay)
        hlay.addStretch()
        self.create_alignment_hole_button = QtGui.QPushButton("Create Alignment Drill")
        self.create_alignment_hole_button.setToolTip(
            "Creates an Excellon Object containing the " "specified alignment holes and their mirror " "images."
        )
        self.mirror_object_button = QtGui.QPushButton("Mirror Object")
        self.mirror_object_button.setToolTip(
            "Mirrors (flips) the specified object around "
            "the specified axis. Does not create a new "
            "object, but modifies it."
        )
        hlay.addWidget(self.create_alignment_hole_button)
        hlay.addWidget(self.mirror_object_button)

        self.layout.addStretch()

        ## Signals
        self.create_alignment_hole_button.clicked.connect(self.on_create_alignment_holes)
        self.mirror_object_button.clicked.connect(self.on_mirror)

        self.axis_location.group_toggle_fn = self.on_toggle_pointbox

        ## Initialize form
        self.mirror_axis.set_value("X")
        self.axis_location.set_value("point")
Example #7
0
class DblSidedTool(FlatCAMTool):

    toolName = "Double-Sided PCB Tool"

    def __init__(self, app):
        FlatCAMTool.__init__(self, app)

        ## Title
        title_label = QtGui.QLabel("<font size=4><b>%s</b></font>" % self.toolName)
        self.layout.addWidget(title_label)

        ## Form Layout
        form_layout = QtGui.QFormLayout()
        self.layout.addLayout(form_layout)

        ## Layer to mirror
        self.object_combo = QtGui.QComboBox()
        self.object_combo.setModel(self.app.collection)
        self.botlay_label = QtGui.QLabel("Bottom Layer:")
        self.botlay_label.setToolTip("Layer to be mirrorer.")
        # form_layout.addRow("Bottom Layer:", self.object_combo)
        form_layout.addRow(self.botlay_label, self.object_combo)

        ## Axis
        self.mirror_axis = RadioSet([{"label": "X", "value": "X"}, {"label": "Y", "value": "Y"}])
        self.mirax_label = QtGui.QLabel("Mirror Axis:")
        self.mirax_label.setToolTip("Mirror vertically (X) or horizontally (Y).")
        # form_layout.addRow("Mirror Axis:", self.mirror_axis)
        form_layout.addRow(self.mirax_label, self.mirror_axis)

        ## Axis Location
        self.axis_location = RadioSet([{"label": "Point", "value": "point"}, {"label": "Box", "value": "box"}])
        self.axloc_label = QtGui.QLabel("Axis Location:")
        self.axloc_label.setToolTip(
            "The axis should pass through a <b>point</b> or cut "
            "a specified <b>box</b> (in a Geometry object) in "
            "the middle."
        )
        # form_layout.addRow("Axis Location:", self.axis_location)
        form_layout.addRow(self.axloc_label, self.axis_location)

        ## Point/Box
        self.point_box_container = QtGui.QVBoxLayout()
        self.pb_label = QtGui.QLabel("Point/Box:")
        self.pb_label.setToolTip(
            "Specify the point (x, y) through which the mirror axis "
            "passes or the Geometry object containing a rectangle "
            "that the mirror axis cuts in half."
        )
        # form_layout.addRow("Point/Box:", self.point_box_container)
        form_layout.addRow(self.pb_label, self.point_box_container)

        self.point = EvalEntry()
        self.point_box_container.addWidget(self.point)
        self.box_combo = QtGui.QComboBox()
        self.box_combo.setModel(self.app.collection)
        self.point_box_container.addWidget(self.box_combo)
        self.box_combo.hide()

        ## Alignment holes
        self.alignment_holes = EvalEntry()
        self.ah_label = QtGui.QLabel("Alignment Holes:")
        self.ah_label.setToolTip("Alignment holes (x1, y1), (x2, y2), ... " "on one side of the mirror axis.")
        form_layout.addRow(self.ah_label, self.alignment_holes)

        ## Drill diameter for alignment holes
        self.drill_dia = LengthEntry()
        self.dd_label = QtGui.QLabel("Drill diam.:")
        self.dd_label.setToolTip("Diameter of the drill for the " "alignment holes.")
        form_layout.addRow(self.dd_label, self.drill_dia)

        ## Buttons
        hlay = QtGui.QHBoxLayout()
        self.layout.addLayout(hlay)
        hlay.addStretch()
        self.create_alignment_hole_button = QtGui.QPushButton("Create Alignment Drill")
        self.create_alignment_hole_button.setToolTip(
            "Creates an Excellon Object containing the " "specified alignment holes and their mirror " "images."
        )
        self.mirror_object_button = QtGui.QPushButton("Mirror Object")
        self.mirror_object_button.setToolTip(
            "Mirrors (flips) the specified object around "
            "the specified axis. Does not create a new "
            "object, but modifies it."
        )
        hlay.addWidget(self.create_alignment_hole_button)
        hlay.addWidget(self.mirror_object_button)

        self.layout.addStretch()

        ## Signals
        self.create_alignment_hole_button.clicked.connect(self.on_create_alignment_holes)
        self.mirror_object_button.clicked.connect(self.on_mirror)

        self.axis_location.group_toggle_fn = self.on_toggle_pointbox

        ## Initialize form
        self.mirror_axis.set_value("X")
        self.axis_location.set_value("point")

    def on_create_alignment_holes(self):
        axis = self.mirror_axis.get_value()
        mode = self.axis_location.get_value()

        if mode == "point":
            px, py = self.point.get_value()
        else:
            selection_index = self.box_combo.currentIndex()
            bb_obj = self.app.collection.object_list[selection_index]  # TODO: Direct access??
            xmin, ymin, xmax, ymax = bb_obj.bounds()
            px = 0.5 * (xmin + xmax)
            py = 0.5 * (ymin + ymax)

        xscale, yscale = {"X": (1.0, -1.0), "Y": (-1.0, 1.0)}[axis]

        dia = self.drill_dia.get_value()
        tools = {"1": {"C": dia}}

        # holes = self.alignment_holes.get_value()
        holes = eval("[{}]".format(self.alignment_holes.text()))
        drills = []

        for hole in holes:
            point = Point(hole)
            point_mirror = affinity.scale(point, xscale, yscale, origin=(px, py))
            drills.append({"point": point, "tool": "1"})
            drills.append({"point": point_mirror, "tool": "1"})

        def obj_init(obj_inst, app_inst):
            obj_inst.tools = tools
            obj_inst.drills = drills
            obj_inst.create_geometry()

        self.app.new_object("excellon", "Alignment Drills", obj_init)

    def on_mirror(self):
        selection_index = self.object_combo.currentIndex()
        fcobj = self.app.collection.object_list[selection_index]

        # For now, lets limit to Gerbers and Excellons.
        # assert isinstance(gerb, FlatCAMGerber)
        if not isinstance(fcobj, FlatCAMGerber) and not isinstance(fcobj, FlatCAMExcellon):
            self.info("ERROR: Only Gerber and Excellon objects can be mirrored.")
            return

        axis = self.mirror_axis.get_value()
        mode = self.axis_location.get_value()

        if mode == "point":
            px, py = self.point.get_value()
        else:
            selection_index = self.box_combo.currentIndex()
            bb_obj = self.app.collection.object_list[selection_index]  # TODO: Direct access??
            xmin, ymin, xmax, ymax = bb_obj.bounds()
            px = 0.5 * (xmin + xmax)
            py = 0.5 * (ymin + ymax)

        fcobj.mirror(axis, [px, py])
        fcobj.plot()

    def on_toggle_pointbox(self):
        if self.axis_location.get_value() == "point":
            self.point.show()
            self.box_combo.hide()
        else:
            self.point.hide()
            self.box_combo.show()