Example #1
0
 def __init__(self, part_type, point=None, rect=None, tag=None, xy=None):
     SelectPart.id += 1
     self.id = SelectPart.id
     self.connecteds = []  # Start with none connected
     self.part_type = part_type
     self.highlighted = False
     self.highlight_tag = None
     self.display_tag = tag
     if point is not None:
         self.loc = SelectLoc(point=point)
     elif rect is not None:
         self.loc = SelectLoc(rect=rect)
     else:
         raise SelectError("SelectPart: neither point nor rect type")
Example #2
0
    def get_corner_rect_at_pt(cls, pt, sztype=None, enlarge=False):
        """ Get corner rectangle at given point
        """
        if sztype is None:
            sztype = cls.SZ_DISPLAY
        corner_width = cls.corner_width_display
        if sztype == SelectPart.SZ_DISPLAY:
            corner_width = cls.corner_width_display
        elif sztype == SelectPart.SZ_SELECT:
            corner_width = cls.corner_width_select
        elif sztype == SelectPart.SZ_STANDOFF:
            corner_width = cls.corner_width_standoff

        c1x = pt[0]
        if c1x >= corner_width / 2:
            c1x -= corner_width / 2
        c1y = pt[1]  # inside upper left  corner
        if c1y >= corner_width / 2:
            c1y -= corner_width / 2
        if isinstance(c1x, list):
            print("c1x is a list")
        c3 = (c1x + corner_width, c1y + corner_width)
        c3x = c3[0]
        c3y = c3[1]
        # Enlarge a bit
        if enlarge:
            el = 2  # enlarge number of pixels
            c1x -= el
            c1y -= el
            c3x += el
            c3y += el
        """ Ensure uL to left and above lR """
        return SelectLoc.order_ul_lr(c1x, c1y, c3x, c3y)
Example #3
0
 def get_region_rect(self, sz_type=None, enlarge=False):
     """ Get upper left x,y and lower right x,y region
     :handle: region's SelectPart
     Region is a set of parts, with the corners being the boundary
     """
     if sz_type is None:
         sz_type = SelectPart.SZ_DISPLAY
     corners = []
     for part in self.connecteds:
         if part.is_corner():
             corners.append(part)
     if len(corners) < 4:
         ###print("Region with %d corners %s" % (len(corners), self))
         co = self.loc.coord
         c1x = co[0][0]
         c1y = co[0][1]
         c3x = co[1][0]
         c3y = co[1][1]
     else:
         c1x = corners[0].loc.coord[0]
         c1y = corners[0].loc.coord[1]
         c3x = corners[2].loc.coord[0]
         c3y = corners[2].loc.coord[1]
     c1x, c1y, c3x, c3y = SelectLoc.order_ul_lr(c1x, c1y, c3x, c3y)
     wlen = self.get_edge_width(sz_type)
     c1x += wlen
     c1y += wlen
     c3x -= wlen
     c3y -= wlen
     if enlarge:
         c1x -= self.edge_width_enlarge
         c1y -= self.edge_width_enlarge
         c3x += self.edge_width_enlarge
         c3y += self.edge_width_enlarge
     return c1x, c1y, c3x, c3y
Example #4
0
 def __init__(self, sel_area, rect=None, draggable=True, invisible=False):
     SelectPart.__init__(self,
                         sel_area,
                         "edge",
                         rect=rect,
                         draggable=draggable,
                         invisible=invisible)
     self.loc = SelectLoc(rect=rect)
Example #5
0
    def get_rect(self, sz_type=None, enlarge=False):
        """ Get upper left x,y and lower right x,y region
        :sz_type: type of rect 
        :enlarge: true - enlarge
        """
        if sz_type is None:
            sz_type = SelectPart.SZ_DISPLAY
        if self.do_corners:
            corners = []
            for part in self.connecteds:
                if part.is_corner():
                    corners.append(part)
            if len(corners) < 4:
                SlTrace.lg("Region with %d corners %s" % (len(corners), self),
                           "region_few_corners")
                co = self.loc.coord
                c1x = co[0][0]
                c1y = co[0][1]
                c3x = co[1][0]
                c3y = co[1][1]
            else:
                c1x = corners[0].loc.coord[0]
                c1y = corners[0].loc.coord[1]
                c3x = corners[2].loc.coord[0]
                c3y = corners[2].loc.coord[1]
        else:
            co = self.loc.coord
            c1x = co[0][0]
            c1y = co[0][1]
            c3x = co[1][0]
            c3y = co[1][1]
        c1x, c1y, c3x, c3y = SelectLoc.order_ul_lr(c1x, c1y, c3x, c3y)
        wlen = self.get_edge_width(sz_type)
        c1x += wlen
        c1y += wlen
        c3x -= wlen
        c3y -= wlen
        if enlarge:
            c1x -= self.edge_width_enlarge
            c1y -= self.edge_width_enlarge
            c3x += self.edge_width_enlarge
            c3y += self.edge_width_enlarge
        if SlTrace.trace("region_rect"):
            SlTrace.lg("region.get_rect: %d c1x=%d c1y=%d c3x=%d c3y=%d" %
                       (self.partno, c1x, c1y, c3x, c3y))
            if c3y < c1y:
                SlTrace.lg("region: %d c3y(%d) < c1y(%d)" %
                           (self.partno, c3y, c1y))
                SlTrace.lg("Strange?")
                for connected in self.connecteds:
                    SlTrace.lg("%d: %s loc_key: %s" %
                               (connected.part_id, connected.part_type,
                                connected.loc_key()))

        return c1x, c1y, c3x, c3y
Example #6
0
    def get_rect(self, sz_type=None, enlarge=False):
        """ Get rectangle containing edge
        Use connected corners
        Coordinates returned are ordered ulx, uly, lrx,lry so ulx<=lrx, uly<=lry
        We leave room for the corners at each end
        :edge - selected edge
        :enlarge - True - enlarge rectangle
        """
        if sz_type is None:
            sz_type = SelectPart.SZ_DISPLAY
        c1x = self.loc.coord[0][0]
        c1y = self.loc.coord[0][1]
        c3x = self.loc.coord[1][0]
        c3y = self.loc.coord[1][1]
        c1x, c1y, c3x, c3y = SelectLoc.order_ul_lr(c1x, c1y, c3x, c3y)
        """ Leave room at each end for corner """
        corner1 = self.get_corner(c1x, c1y)
        if corner1 is not None:
            _, _, corner1_xsize, corner1_ysize = corner1.get_center_size()
            corner3 = self.get_corner(c3x, c3y)
            _, _, corner3_xsize, corner3_ysize = corner3.get_center_size()
        else:
            corner1_xsize = corner1_ysize = 0
            corner3_xsize = corner3_ysize = 0
        dir_x, dir_y = self.edge_dxy()
        wlen = self.get_edge_width(sz_type) / 2
        if dir_y != 0:  # Check if in y direction
            if c1x >= wlen:  # Yes - widen the orthogonal dimension
                c1x -= wlen
            c3x += wlen
            c1y += corner1_ysize  # Yes - shorten ends to avoid corner
            c3y -= corner3_ysize
        if dir_x != 0:  # Check if in x direction
            if c1y >= wlen:  # Yes - widen the orthogonal dimension
                c1y -= wlen
            c3y += wlen
            c1x += corner1_xsize  # Yes - shorten ends to avoid corner
            c3x -= corner3_xsize
        if enlarge:
            wenlarge = SelectPart.edge_width_enlarge
            if dir_y != 0:
                c1x -= wenlarge
                c3x += wenlarge
            if dir_x != 0:
                c1y -= wenlarge
                c3y += wenlarge

        return c1x, c1y, c3x, c3y
Example #7
0
 def __init__(self, rect=None):
     SelectPart.__init__(self, "region", rect=None)
     self.loc = SelectLoc(rect=rect)
Example #8
0
 def __init__(self, part_type, point=None):
     SelectPart.__init__(self, "corner", point=point)
     self.loc = SelectLoc(point=point)