1965 |
1965 |
1966 # Define the wire points |
1966 # Define the wire points |
1967 def SetPoints(self, points, merge_segments=True): |
1967 def SetPoints(self, points, merge_segments=True): |
1968 print("SetPoints", self) |
1968 print("SetPoints", self) |
1969 if len(points) > 1: |
1969 if len(points) > 1: |
1970 self.Points = [wx.Point(x, y) for x, y in points] |
1970 |
|
1971 # filter duplicates, add corner to diagonals |
|
1972 self.Points = [] |
|
1973 lx,ly = None,None |
|
1974 for x, y in points: |
|
1975 ex, ey = lx == x, ly == y |
|
1976 if ex and ey: |
|
1977 # duplicate |
|
1978 continue |
|
1979 if (lx,ly) != (None,None) and not ex and not ey: |
|
1980 # diagonal |
|
1981 self.Points.append(wx.Point(lx, y)) |
|
1982 self.Points.append(wx.Point(x, y)) |
|
1983 lx,ly = x,y |
|
1984 |
1971 # Calculate the start and end directions |
1985 # Calculate the start and end directions |
1972 self.StartPoint = [None, vector(self.Points[0], self.Points[1])] |
1986 self.StartPoint = [None, vector(self.Points[0], self.Points[1])] |
1973 self.EndPoint = [None, vector(self.Points[-1], self.Points[-2])] |
1987 self.EndPoint = [None, vector(self.Points[-1], self.Points[-2])] |
1974 # Calculate the start and end points |
1988 # Calculate the start and end points |
1975 self.StartPoint[0] = wx.Point(self.Points[0].x + CONNECTOR_SIZE * self.StartPoint[1][0], |
1989 self.StartPoint[0] = wx.Point(self.Points[0].x + CONNECTOR_SIZE * self.StartPoint[1][0], |
1986 if i > l - 2: |
2000 if i > l - 2: |
1987 break |
2001 break |
1988 |
2002 |
1989 segment = vector(self.Points[i], self.Points[i + 1]) |
2003 segment = vector(self.Points[i], self.Points[i + 1]) |
1990 |
2004 |
1991 # delete duplicates |
|
1992 if is_null_vector(segment): |
|
1993 self.Points.pop(i) |
|
1994 # next point is the same, no need to rollback |
|
1995 continue |
|
1996 |
|
1997 # merge segment if requested |
2005 # merge segment if requested |
1998 if merge_segments and 0 < i and \ |
2006 if merge_segments and 0 < i and \ |
1999 self.Segments[-1] == segment: |
2007 self.Segments[-1] == segment: |
2000 self.Points.pop(i) |
2008 self.Points.pop(i) |
2001 # Rollback |
2009 # Rollback |
2002 self.Segments.pop() |
2010 self.Segments.pop() |
2003 i -= 1 |
2011 i -= 1 |
2004 continue |
2012 continue |
2005 |
2013 |
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 |
2014 # remove corner when two segments are in opposite direction |
2013 if i < l - 2: |
2015 if i < l - 2: |
2014 next = vector(self.Points[i + 1], self.Points[i + 2]) |
2016 next = vector(self.Points[i + 1], self.Points[i + 2]) |
2015 if is_null_vector(add_vectors(segment, next)): |
2017 if is_null_vector(add_vectors(segment, next)): |
2016 self.Points.pop(i+1) |
2018 self.Points.pop(i+1) |
2017 continue |
2019 continue |
2018 |
2020 |
2019 self.Segments.append(segment) |
2021 self.Segments.append(segment) |
2020 |
2022 |
2021 i += 1 |
2023 i += 1 |
2022 |
|
2023 |
2024 |
2024 self.RefreshBoundingBox() |
2025 self.RefreshBoundingBox() |
2025 self.RefreshRealPoints() |
2026 self.RefreshRealPoints() |
2026 |
2027 |
2027 # Returns the position of the point indicated |
2028 # Returns the position of the point indicated |