1962 if rect.InsideXY(pt.x, pt.y): |
1962 if rect.InsideXY(pt.x, pt.y): |
1963 return i, self.Segments[i] |
1963 return i, self.Segments[i] |
1964 return None |
1964 return None |
1965 |
1965 |
1966 # Define the wire points |
1966 # Define the wire points |
1967 def SetPoints(self, points, verify=True): |
1967 def SetPoints(self, points, merge_segments=True): |
|
1968 print("SetPoints", self) |
1968 if len(points) > 1: |
1969 if len(points) > 1: |
1969 self.Points = [wx.Point(x, y) for x, y in points] |
1970 self.Points = [wx.Point(x, y) for x, y in points] |
1970 # Calculate the start and end directions |
1971 # Calculate the start and end directions |
1971 self.StartPoint = [None, vector(self.Points[0], self.Points[1])] |
1972 self.StartPoint = [None, vector(self.Points[0], self.Points[1])] |
1972 self.EndPoint = [None, vector(self.Points[-1], self.Points[-2])] |
1973 self.EndPoint = [None, vector(self.Points[-1], self.Points[-2])] |
1978 self.Points[0] = self.StartPoint[0] |
1979 self.Points[0] = self.StartPoint[0] |
1979 self.Points[-1] = self.EndPoint[0] |
1980 self.Points[-1] = self.EndPoint[0] |
1980 # Calculate the segments directions |
1981 # Calculate the segments directions |
1981 self.Segments = [] |
1982 self.Segments = [] |
1982 i = 0 |
1983 i = 0 |
1983 while i < len(self.Points) - 1: |
1984 while True: |
1984 if verify and 0 < i < len(self.Points) - 2 and \ |
1985 l = len(self.Points) |
1985 self.Points[i] == self.Points[i + 1] and \ |
1986 if i > l - 2: |
1986 self.Segments[-1] == vector(self.Points[i + 1], self.Points[i + 2]): |
1987 break |
1987 for dummy in xrange(2): |
1988 |
1988 self.Points.pop(i) |
1989 segment = vector(self.Points[i], self.Points[i + 1]) |
1989 else: |
1990 |
1990 segment = vector(self.Points[i], self.Points[i + 1]) |
1991 # delete duplicates |
1991 if is_null_vector(segment) and i > 0: |
1992 if is_null_vector(segment): |
1992 segment = (self.Segments[-1][1], self.Segments[-1][0]) |
1993 self.Points.pop(i) |
1993 if i < len(self.Points) - 2: |
1994 # next point is the same, no need to rollback |
1994 next = vector(self.Points[i + 1], self.Points[i + 2]) |
1995 continue |
1995 if next == segment or is_null_vector(add_vectors(segment, next)): |
1996 |
1996 self.Points.insert(i + 1, wx.Point(self.Points[i + 1].x, self.Points[i + 1].y)) |
1997 # merge segment if requested |
1997 self.Segments.append(segment) |
1998 if merge_segments and 0 < i and \ |
1998 i += 1 |
1999 self.Segments[-1] == segment: |
|
2000 self.Points.pop(i) |
|
2001 # Rollback |
|
2002 self.Segments.pop() |
|
2003 i -= 1 |
|
2004 continue |
|
2005 |
|
2006 # add point to make a corner in case of diagonal segment |
|
2007 if segment not in [EAST, NORTH, WEST, SOUTH]: |
|
2008 self.Points.insert(i + 1, wx.Point( |
|
2009 self.Points[i].x, self.Points[i + 1].y)) |
|
2010 continue |
|
2011 |
|
2012 # remove corner when two segments are in opposite direction |
|
2013 if i < l - 2: |
|
2014 next = vector(self.Points[i + 1], self.Points[i + 2]) |
|
2015 if is_null_vector(add_vectors(segment, next)): |
|
2016 self.Points.pop(i+1) |
|
2017 continue |
|
2018 |
|
2019 self.Segments.append(segment) |
|
2020 |
|
2021 i += 1 |
|
2022 |
|
2023 |
1999 self.RefreshBoundingBox() |
2024 self.RefreshBoundingBox() |
2000 self.RefreshRealPoints() |
2025 self.RefreshRealPoints() |
2001 |
2026 |
2002 # Returns the position of the point indicated |
2027 # Returns the position of the point indicated |
2003 def GetPoint(self, index): |
2028 def GetPoint(self, index): |