1974 self.Points.append(wx.Point(lx, y)) |
1978 self.Points.append(wx.Point(lx, y)) |
1975 self.Points.append(wx.Point(x, y)) |
1979 self.Points.append(wx.Point(x, y)) |
1976 lx, ly = x, y |
1980 lx, ly = x, y |
1977 |
1981 |
1978 # Calculate the start and end directions |
1982 # Calculate the start and end directions |
1979 self.StartPoint = [None, vector(self.Points[0], self.Points[1])] |
1983 self.StartPoint = [None, ivector(self.Points[0], self.Points[1])] |
1980 self.EndPoint = [None, vector(self.Points[-1], self.Points[-2])] |
1984 self.EndPoint = [None, ivector(self.Points[-1], self.Points[-2])] |
1981 # Calculate the start and end points |
1985 # Calculate the start and end points |
1982 self.StartPoint[0] = wx.Point(self.Points[0].x + round(CONNECTOR_SIZE * self.StartPoint[1][0]), |
1986 self.StartPoint[0] = wx.Point(self.Points[0].x + round(CONNECTOR_SIZE * self.StartPoint[1][0]), |
1983 self.Points[0].y + round(CONNECTOR_SIZE * self.StartPoint[1][1])) |
1987 self.Points[0].y + round(CONNECTOR_SIZE * self.StartPoint[1][1])) |
1984 self.EndPoint[0] = wx.Point(self.Points[-1].x + round(CONNECTOR_SIZE * self.EndPoint[1][0]), |
1988 self.EndPoint[0] = wx.Point(self.Points[-1].x + round(CONNECTOR_SIZE * self.EndPoint[1][0]), |
1985 self.Points[-1].y + round(CONNECTOR_SIZE * self.EndPoint[1][1])) |
1989 self.Points[-1].y + round(CONNECTOR_SIZE * self.EndPoint[1][1])) |
1991 while True: |
1995 while True: |
1992 lp = len(self.Points) |
1996 lp = len(self.Points) |
1993 if i > lp - 2: |
1997 if i > lp - 2: |
1994 break |
1998 break |
1995 |
1999 |
1996 segment = tuple(map(round,vector(self.Points[i], self.Points[i + 1]))) |
2000 segment = ivector(self.Points[i], self.Points[i + 1]) |
1997 |
2001 |
1998 # merge segment if requested |
2002 # merge segment if requested |
1999 if merge_segments and 0 < i and \ |
2003 if merge_segments and 0 < i and \ |
2000 self.Segments[-1] == segment: |
2004 self.Segments[-1] == segment: |
2001 self.Points.pop(i) |
2005 self.Points.pop(i) |
2004 i -= 1 |
2008 i -= 1 |
2005 continue |
2009 continue |
2006 |
2010 |
2007 # remove corner when two segments are in opposite direction |
2011 # remove corner when two segments are in opposite direction |
2008 if i < lp - 2: |
2012 if i < lp - 2: |
2009 next = vector(self.Points[i + 1], self.Points[i + 2]) |
2013 next = ivector(self.Points[i + 1], self.Points[i + 2]) |
2010 if is_null_vector(add_vectors(segment, next)): |
2014 if is_null_vector(add_vectors(segment, next)): |
2011 self.Points.pop(i+1) |
2015 self.Points.pop(i+1) |
2012 continue |
2016 continue |
2013 |
2017 |
2014 self.Segments.append(segment) |
2018 self.Segments.append(segment) |
2076 # Evaluate the point till it's the last |
2080 # Evaluate the point till it's the last |
2077 while i < len(self.Points) - 1: |
2081 while i < len(self.Points) - 1: |
2078 # The next point is the last |
2082 # The next point is the last |
2079 if i + 1 == len(self.Points) - 1: |
2083 if i + 1 == len(self.Points) - 1: |
2080 # Calculate the direction from current point to end point |
2084 # Calculate the direction from current point to end point |
2081 v_end = tuple(map(round,vector(self.Points[i], end))) |
2085 v_end = vector(self.Points[i], end) |
2082 # The current point is the first |
2086 # The current point is the first |
2083 if i == 0: |
2087 if i == 0: |
2084 # If the end point is not in the start direction, a point is added |
2088 # If the end point is not in the start direction, a point is added |
2085 if v_end != self.Segments[0] or v_end == self.EndPoint[1]: |
2089 if v_end != self.Segments[0] or v_end == self.EndPoint[1]: |
2086 self.Points.insert(1, wx.Point(start.x, start.y)) |
2090 self.Points.insert(1, wx.Point(start.x, start.y)) |
2198 self.Points.insert(1, wx.Point(start.x, start.y)) |
2202 self.Points.insert(1, wx.Point(start.x, start.y)) |
2199 self.Segments.insert( |
2203 self.Segments.insert( |
2200 1, |
2204 1, |
2201 DirectionChoice((self.Segments[0][1], |
2205 DirectionChoice((self.Segments[0][1], |
2202 self.Segments[0][0]), |
2206 self.Segments[0][0]), |
2203 tuple(map(round,vector(start, self.Points[1]))), |
2207 vector(start, self.Points[1]), |
2204 self.Segments[1])) |
2208 self.Segments[1])) |
2205 else: |
2209 else: |
2206 self.Points[1].x, self.Points[1].y = start.x, start.y |
2210 self.Points[1].x, self.Points[1].y = start.x, start.y |
2207 else: |
2211 else: |
2208 # Next point is aligned with current point |
2212 # Next point is aligned with current point |