486 # If movement is greater than MIN_MOVE then a dragging is initiated |
486 # If movement is greater than MIN_MOVE then a dragging is initiated |
487 if not self.Dragging and (abs(movex) > MIN_MOVE or abs(movey) > MIN_MOVE): |
487 if not self.Dragging and (abs(movex) > MIN_MOVE or abs(movey) > MIN_MOVE): |
488 self.Dragging = True |
488 self.Dragging = True |
489 # If a dragging have been initiated, refreshes the element state |
489 # If a dragging have been initiated, refreshes the element state |
490 if self.Dragging: |
490 if self.Dragging: |
491 dragx, dragy = self.ProcessDragging(movex, movey, scaling) |
491 dragx, dragy = self.ProcessDragging(movex, movey, event.ShiftDown(), scaling) |
492 self.oldPos.x += dragx |
492 self.oldPos.x += dragx |
493 self.oldPos.y += dragy |
493 self.oldPos.y += dragy |
494 return dragx, dragy |
494 return dragx, dragy |
495 return movex, movey |
495 return movex, movey |
496 # If cursor just pass over the element, changes the cursor if it is on a handle |
496 # If cursor just pass over the element, changes the cursor if it is on a handle |
516 def Resize(self, x, y, width, height): |
516 def Resize(self, x, y, width, height): |
517 self.Move(x, y) |
517 self.Move(x, y) |
518 self.SetSize(width, height) |
518 self.SetSize(width, height) |
519 |
519 |
520 # Refreshes the element state according to move defined and handle selected |
520 # Refreshes the element state according to move defined and handle selected |
521 def ProcessDragging(self, movex, movey, scaling): |
521 def ProcessDragging(self, movex, movey, centered, scaling): |
522 handle_type, handle = self.Handle |
522 handle_type, handle = self.Handle |
523 # If it is a resize handle, calculate the values from resizing |
523 # If it is a resize handle, calculate the values from resizing |
524 if handle_type == HANDLE_RESIZE: |
524 if handle_type == HANDLE_RESIZE: |
525 x = y = start_x = start_y = 0 |
525 x = y = start_x = start_y = 0 |
526 width, height = start_width, start_height = self.GetSize() |
526 width, height = start_width, start_height = self.GetSize() |
527 if handle[0] == 1: |
527 if handle[0] == 1: |
528 movex = max(-self.BoundingBox.x, movex) |
528 movex = max(-self.BoundingBox.x, movex) |
529 if scaling is not None: |
529 if scaling is not None: |
530 movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x |
530 movex = round(float(self.Pos.x + movex) / float(scaling[0])) * scaling[0] - self.Pos.x |
531 x = movex |
531 x = movex |
532 width -= movex |
532 if centered: |
|
533 width -= 2 * movex |
|
534 else: |
|
535 width -= movex |
533 elif handle[0] == 3: |
536 elif handle[0] == 3: |
534 if scaling is not None: |
537 if scaling is not None: |
535 movex = round(float(self.Pos.x + width + movex) / float(scaling[0])) * scaling[0] - self.Pos.x - width |
538 movex = round(float(self.Pos.x + width + movex) / float(scaling[0])) * scaling[0] - self.Pos.x - width |
536 width += movex |
539 if centered: |
|
540 x = -movex |
|
541 width += 2 * movex |
|
542 else: |
|
543 width += movex |
537 if handle[1] == 1: |
544 if handle[1] == 1: |
538 movey = max(-self.BoundingBox.y, movey) |
545 movey = max(-self.BoundingBox.y, movey) |
539 if scaling is not None: |
546 if scaling is not None: |
540 movey = round(float(self.Pos.y + movey) / float(scaling[1])) * scaling[1] - self.Pos.y |
547 movey = round(float(self.Pos.y + movey) / float(scaling[1])) * scaling[1] - self.Pos.y |
541 y = movey |
548 y = movey |
542 height -= movey |
549 if centered: |
|
550 height -= 2 * movey |
|
551 else: |
|
552 height -= movey |
543 elif handle[1] == 3: |
553 elif handle[1] == 3: |
544 if scaling is not None: |
554 if scaling is not None: |
545 movey = round(float(self.Pos.y + height + movey) / float(scaling[1])) * scaling[1] - self.Pos.y - height |
555 movey = round(float(self.Pos.y + height + movey) / float(scaling[1])) * scaling[1] - self.Pos.y - height |
546 height += movey |
556 if centered: |
|
557 y = -movey |
|
558 height += 2 * movey |
|
559 else: |
|
560 height += movey |
547 # Verify that new size is not lesser than minimum |
561 # Verify that new size is not lesser than minimum |
548 min_width, min_height = self.GetMinSize() |
562 min_width, min_height = self.GetMinSize() |
549 if handle[0] != 2 and (width >= min_width or width > self.Size[0]): |
563 if handle[0] != 2 and (width >= min_width or width > self.Size[0]): |
550 start_x = x |
564 start_x = x |
551 start_width = width |
565 start_width = width |
1910 else: |
1924 else: |
1911 # Execute the default method for a graphic element |
1925 # Execute the default method for a graphic element |
1912 return Graphic_Element.OnMotion(self, event, dc, scaling) |
1926 return Graphic_Element.OnMotion(self, event, dc, scaling) |
1913 |
1927 |
1914 # Refreshes the wire state according to move defined and handle selected |
1928 # Refreshes the wire state according to move defined and handle selected |
1915 def ProcessDragging(self, movex, movey, scaling): |
1929 def ProcessDragging(self, movex, movey, centered, scaling): |
1916 handle_type, handle = self.Handle |
1930 handle_type, handle = self.Handle |
1917 # A point has been handled |
1931 # A point has been handled |
1918 if handle_type == HANDLE_POINT: |
1932 if handle_type == HANDLE_POINT: |
1919 movex = max(-self.Points[handle].x + POINT_RADIUS, movex) |
1933 movex = max(-self.Points[handle].x + POINT_RADIUS, movex) |
1920 movey = max(-self.Points[handle].y + POINT_RADIUS, movey) |
1934 movey = max(-self.Points[handle].y + POINT_RADIUS, movey) |
1962 # A segment has been handled, move a segment |
1976 # A segment has been handled, move a segment |
1963 elif handle_type == HANDLE_SEGMENT: |
1977 elif handle_type == HANDLE_SEGMENT: |
1964 return self.MoveSegment(handle[0], movex, movey, scaling) |
1978 return self.MoveSegment(handle[0], movex, movey, scaling) |
1965 # Execute the default method for a graphic element |
1979 # Execute the default method for a graphic element |
1966 else: |
1980 else: |
1967 return Graphic_Element.ProcessDragging(self, movex, movey, scaling) |
1981 return Graphic_Element.ProcessDragging(self, movex, movey, centered, scaling) |
1968 |
1982 |
1969 # Refreshes the wire model |
1983 # Refreshes the wire model |
1970 def RefreshModel(self, move=True): |
1984 def RefreshModel(self, move=True): |
1971 if self.StartConnected and self.StartPoint[1] in [WEST, NORTH]: |
1985 if self.StartConnected and self.StartPoint[1] in [WEST, NORTH]: |
1972 self.StartConnected.RefreshParentBlock() |
1986 self.StartConnected.RefreshParentBlock() |