Exemplo n.º 1
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)
Exemplo n.º 2
0
 def get_parts_at(self, x, y, sz_type=SelectPart.SZ_SELECT):
     """ Check if any part is at canvas location provided
     If found list of parts
     :Returns: SelectPart[]
     """
     parts = []
     for part in self.parts:
         if not isinstance(part, SelectPart):
             SlTrace.lg("part(%s) is not SelectPart" % part)
         if part.is_over(x, y, sz_type=sz_type):
             parts.append(part)
     if len(parts) > 1:
         SlTrace.lg("get_parts at (%d, %d) sz_type=%d" % (x, y, sz_type),
                    "get_parts")
         for part in parts:
             c1x, c1y, c3x, c3y = part.get_rect(sz_type=sz_type)
             SlTrace.lg(
                 "    %s : c1x:%d, c1y:%d, c3x:%d, c3y:%d" %
                 (part, c1x, c1y, c3x, c3y), "get_parts")
         SlTrace.lg("", "get_parts")
         olap_rect = SelectPart.get_olaps(parts,
                                          sz_type=SelectPart.SZ_SELECT)
         if olap_rect is not None:
             if SlTrace.trace("overlapping"):
                 SlTrace.lg(
                     "Overlapping %d,%d, %d,%d" %
                     (olap_rect[0][0], olap_rect[0][1], olap_rect[1][0],
                      olap_rect[1][1]), "overlapping")
                 SlTrace.lg("")
     return parts
Exemplo n.º 3
0
    def current_part(self, part_type, pt1, pt2=None):
        """ Return part with this type, location, None if none found
        """
        loc_key = SelectPart.part_loc_key(part_type, pt1, pt2=None)
        if loc_key in self.parts_by_loc:
            return self.parts_by_loc[loc_key]  # current entry

        return None  # No entry at this location
Exemplo n.º 4
0
    def get_edge_with(self, pt1, pt2):
        """ Get edge part with corners at pt1, pt2, if one
            :pt1:  end point uL or lR
            :pt2:  end point
            :Returns: edge or None
        """
        for part in self.parts:
            if not part.is_edge():
                continue
            points = part.get_points()
            if (SelectPart.is_point_equal(points[0], pt1)
                    and SelectPart.is_point_equal(points[1], pt2)):
                return part
            if (SelectPart.is_point_equal(points[1], pt1)
                    and SelectPart.is_point_equal(points[0], pt2)):
                return part

        return None
Exemplo n.º 5
0
 def add_edge(self, region, pt1, pt2):
     """ Add edge handles to region
     Also adds corner handles
     """
     edge = self.get_edge_with(pt1, pt2)
     if edge is None:
         edge = SelectPart("edge", rect=[pt1,pt2])
         self.add_part(edge)
     self.add_corners(region, [pt1, pt2], edge=edge)     # So we get corners
     region.add_connected(edge)
Exemplo n.º 6
0
 def add_corners(self, region, points, edge=None):
     """ Add corners to region
     :region: region to which to add corners
     :points: one or more corner locations
     If corner == first corner, set region enclosed
     but DON't add corner
     """
     if not isinstance(points, list):
         points = [points]     # Treat as an array of one
     for point in points:
         if self.is_first_corner(point):
             self.is_enclosed = True
         if self.has_corner(point):
             corner = self.get_corner_part(point[0], point[1])
         else:
             corner = SelectPart("corner", point=point)
         self.add_part(corner)       # Add new corners
             
         region.add_connected(corner)
         if edge is not None:
             corner.add_connected(edge)      # Connect edge to corner
             edge.add_connected(corner)      # Connect corner to edge
Exemplo n.º 7
0
 def add_rect(self, rect):
     """ Add rectangle to object as another region
     """                
     rec_ps = [None] * 4
     ulX, ulY = rect[0][0], rect[0][1]
     lrX, lrY = rect[1][0], rect[1][1]
     sr = SelectPart("region", rect=[(ulX,ulY),(lrX,lrY)])   # Just one region now
     self.regions.append(sr)         # Add region
     self.add_part(sr)       
     rec_ps[0] = (ulX, ulY)
     rec_ps[1] = (lrX, ulY) 
     rec_ps[2] = (lrX, lrY)
     rec_ps[3] = (ulX, lrY)
     for pi1 in range(0, 3+1):
         pi2 = pi1 + 1
         if pi2 >= len(rec_ps):
             pi2 = 0          # Ends at first
         pt1 = rec_ps[pi1]
         pt2 = rec_ps[pi2]
         self.add_edge(sr, pt1, pt2)
Exemplo n.º 8
0
 def get_parts_at(self, x, y, sz_type=SelectPart.SZ_SELECT):
     """ Check if any part is at canvas location provided
     If found list of parts
     :Returns: SelectPart[]
     """
     parts = []
     for part in self.parts:
         if part.is_over(x, y, sz_type=sz_type):
             parts.append(part)
     if len(parts) > 1:
         print("get_parts at (%d, %d) sz_type=%d" % (x, y, sz_type))
         for part in parts:
             c1x, c1y, c3x, c3y = part.get_rect(sz_type=sz_type)
             print("    %s : c1x:%d, c1y:%d, c3x:%d, c3y:%d" %
                   (part, c1x, c1y, c3x, c3y))
         print()
         olap_rect = SelectPart.get_olaps(parts,
                                          sz_type=SelectPart.SZ_SELECT)
         if olap_rect is not None:
             print("Overlapping %d,%d, %d,%d" %
                   (olap_rect[0][0], olap_rect[0][1], olap_rect[1][0],
                    olap_rect[1][1]))
             print()
     return parts
Exemplo n.º 9
0
color_drop_red = args.color_drop_red
color_drop_green = args.color_drop_green
color_drop_blue = args.color_drop_blue
nx = args.nx
ny = args.ny
nsq = nx * ny
show_id = args.show_id
show_moved = args.show_moved
width = args.width
height = args.height
ew_display= args.ew_display
ew_select = args.ew_select
ew_standoff = args.ew_standoff

SelectPart.set_edge_width_cls(ew_display,
                          ew_select,
                          ew_standoff)

run_running = False
figure_new = True           # True - time to setup new figure
                            # for possible arrangement
n_arrange = 1               #number of major cycle for rearrange

def one_run():
    """ One run loop with a call back
    """
    if ActiveCheck.not_active():
        return  # We're at the end
        
    global n_arrange
    if run_running:
Exemplo n.º 10
0
 def __init__(self, rect=None):
     SelectPart.__init__(self, "region", rect=None)
     self.loc = SelectLoc(rect=rect)
Exemplo n.º 11
0
 def __init__(self, part_type, point=None):
     SelectPart.__init__(self, "corner", point=point)
     self.loc = SelectLoc(point=point)