private void GenAllPathPosition(System.Collections.IEnumerable enumerable) { System.Collections.IEnumerator e = enumerable.GetEnumerator(); while (e.MoveNext()) { if (e.Current is PathPointNode) { PathPointNode node = e.Current as PathPointNode; if (node.MyPath != null) { Point relativeLocation = node.TranslatePoint(new Point(5, 5), LayoutRoot); PathReDrawing(relativeLocation, node.MyPath.EndPathPosition, node.MyPath); node.MyPath.StartPosition = relativeLocation; } if (node.ComePath != null) { Point relativeLocation = node.TranslatePoint(new Point(5, 5), LayoutRoot); PathReDrawing(node.ComePath.StartPosition, relativeLocation, node.ComePath); node.ComePath.EndPathPosition = relativeLocation; } } } }
private void ObjectMouseMove(object sender, MouseEventArgs e) { /* * In this event, at first we check the mouse left button state. If it is pressed and * event sender object is similar with our moving object, we can move our control with * some effects. */ if (e.LeftButton == MouseButtonState.Pressed) { if (MovingObject == null) { if (MovingPath != null) { Point NowActualPostion = e.GetPosition((MovingPath.MyPath.Path as FrameworkElement).Parent as FrameworkElement); if (isConnected) { if (DestinationPoint != null) { Point relativeLocation = DestinationPoint.TranslatePoint(new Point(5, 5), LayoutRoot); if (relativeLocation.X < NowActualPostion.X + 15 && relativeLocation.X > NowActualPostion.X - 15 && relativeLocation.Y < NowActualPostion.Y + 15 && relativeLocation.Y > NowActualPostion.Y - 15) { //MyPathStartPosition PathReDrawing(MovingPath.MyPath.StartPosition, relativeLocation, MovingPath.MyPath); MovingPath.MyPath.EndPathPosition = relativeLocation; return; } } isConnected = false; DestinationPoint = null; } PathReDrawing(MovingPath.MyPath.StartPosition, NowActualPostion, MovingPath.MyPath); MovingPath.MyPath.EndPathPosition = NowActualPostion; } return; } // We start to moving objects with setting the lines positions. Path1.X1 = FirstArrowXPos; Path1.Y1 = FirstArrowYPos; Path1.X2 = e.GetPosition((MovingObject as FrameworkElement).Parent as FrameworkElement).X - FirstXPos; Path1.Y2 = e.GetPosition((MovingObject as FrameworkElement).Parent as FrameworkElement).Y - FirstYPos; Path2.X1 = Path1.X1 + (MovingObject as FrameworkElement).ActualWidth; Path2.Y1 = Path1.Y1; Path2.X2 = Path1.X2 + (MovingObject as FrameworkElement).ActualWidth; Path2.Y2 = Path1.Y2; Path3.X1 = Path1.X1; Path3.Y1 = Path1.Y1 + (MovingObject as FrameworkElement).ActualHeight; Path3.X2 = Path1.X2; Path3.Y2 = Path1.Y2 + (MovingObject as FrameworkElement).ActualHeight; Path4.X1 = Path1.X1 + (MovingObject as FrameworkElement).ActualWidth; Path4.Y1 = Path1.Y1 + (MovingObject as FrameworkElement).ActualHeight; Path4.X2 = Path1.X2 + (MovingObject as FrameworkElement).ActualWidth; Path4.Y2 = Path1.Y2 + (MovingObject as FrameworkElement).ActualHeight; FirstPosition.Width = (MovingObject as FrameworkElement).ActualWidth; FirstPosition.Height = (MovingObject as FrameworkElement).ActualHeight; FirstPosition.SetValue(Canvas.LeftProperty, FirstArrowXPos); FirstPosition.SetValue(Canvas.TopProperty, FirstArrowYPos); CurrentPosition.Width = (MovingObject as FrameworkElement).ActualWidth; CurrentPosition.Height = (MovingObject as FrameworkElement).ActualHeight; CurrentPosition.SetValue(Canvas.LeftProperty, Path1.X2); CurrentPosition.SetValue(Canvas.TopProperty, Path1.Y2); Path1.Visibility = System.Windows.Visibility.Visible; Path2.Visibility = System.Windows.Visibility.Visible; Path3.Visibility = System.Windows.Visibility.Visible; Path4.Visibility = System.Windows.Visibility.Visible; FirstPosition.Visibility = System.Windows.Visibility.Visible; CurrentPosition.Visibility = System.Windows.Visibility.Visible; /* * For changing the position of a control, we should use the SetValue method to setting * the Canvas.LeftProperty and Canvas.TopProperty dependencies. * * For calculating the currect position of the control, we should do : * Current position of the mouse cursor on the object parent - * Mouse position on the control at the start of moving - * position of the control's parent. */ (MovingObject as FrameworkElement).SetValue(Canvas.LeftProperty, e.GetPosition((MovingObject as FrameworkElement).Parent as FrameworkElement).X - FirstXPos); (MovingObject as FrameworkElement).SetValue(Canvas.TopProperty, e.GetPosition((MovingObject as FrameworkElement).Parent as FrameworkElement).Y - FirstYPos); if (MovingObject is ModuleView) { GenAllPathPosition((MovingObject as ModuleView).LayoutRoot.Children); } } }
void ObjectPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (MovingObject is ModuleView && MovingObject != null) { CurrentSelectPosition.Visibility = System.Windows.Visibility.Visible; CurrentSelectPosition.Width = (CurrentSelect as FrameworkElement).ActualWidth + 10; CurrentSelectPosition.Height = (CurrentSelect as FrameworkElement).ActualHeight + 10; Point po1 = new Point(); po1.X = e.GetPosition((MovingObject as FrameworkElement).Parent as FrameworkElement).X - FirstXPos - 5; po1.Y = e.GetPosition((MovingObject as FrameworkElement).Parent as FrameworkElement).Y - FirstYPos - 5; CurrentSelectPosition.SetValue(Canvas.LeftProperty, po1.X); CurrentSelectPosition.SetValue(Canvas.TopProperty, po1.Y); } else { //CurrentSelect = null; //CurrentSelectPosition.Visibility = System.Windows.Visibility.Hidden; } if (isConnected == false) { if (MovingPath != null) { //선은 있는데 연결이 끊긴경우 MovingPath.MyPath.Visibility = System.Windows.Visibility.Collapsed; //MovingPath.Disconnect(); if (MovingPath.NextPoint != null) { if (MovingPath.NextPoint.BeforePoint != null) { MovingPath.NextPoint.BeforePoint.Disconnect(); MovingPath.NextPoint.BeforePoint = null; } MovingPath.NextPoint.Disconnect(); MovingPath.NextPoint = null; } } } else if (DestinationPoint != null) { if (BeginnerPoint.Next != null) { BeginnerPoint.Next.Before = null; } if (MovingPath.NextPoint != null) { MovingPath.NextPoint.BeforePoint = null; } //앞뒤로 연결하기 MovingPath.NextPoint = DestinationPoint; DestinationPoint.BeforePoint = MovingPath; DestinationPoint.ComePath = MovingPath.MyPath; //IF문의 경우 True에 if (MovingPath.MySequence == PathPointNode.PathIFDirection.TrueSequence) { BeginnerPoint.TrueNode = FinisherPoint; } else if (MovingPath.MySequence == PathPointNode.PathIFDirection.FalseSequence) {//false에 값을 넣는다. BeginnerPoint.FalseNode = FinisherPoint; } else { BeginnerPoint.Next = FinisherPoint; } FinisherPoint.Before = BeginnerPoint; MovingPath.OnConnect(); MovingPath.NextPoint.OnConnect(); } DestinationPoint = null; MovingPath = null; BeginnerPoint = null; FinisherPoint = null; // In this event, we should set the lines visibility to Hidden MovingObject = null; Path1.Visibility = System.Windows.Visibility.Hidden; Path2.Visibility = System.Windows.Visibility.Hidden; Path3.Visibility = System.Windows.Visibility.Hidden; Path4.Visibility = System.Windows.Visibility.Hidden; FirstPosition.Visibility = System.Windows.Visibility.Hidden; CurrentPosition.Visibility = System.Windows.Visibility.Hidden; }