Ejemplo n.º 1
0
        private void MainCanvas_Drop(object sender, DragEventArgs e)
        {
            FrameworkElement elem = sender as FrameworkElement;

            if (elem == null)
            {
                return;
            }
            IDataObject data = e.Data;

            if (!data.GetDataPresent(typeof(FlowElement)))
            {
                return;
            }
            FlowElement source = data.GetData(typeof(FlowElement)) as FlowElement;

            if (source == null)
            {
                return;
            }

            if (e.Source is FlowElement)
            {
                FlowLink FL = new FlowLink(source, (FlowElement)e.Source);

                FL.LinkStyle = FlowLink.eLinkStyle.Arrow;
                GEList.Add(FL);
                SetFlowLinkConnectorsLocations(FL, e);
                FL.Draw();

                MainCanvas.Children.Add(FL);
            }
        }
Ejemplo n.º 2
0
        private void SetFlowLinkConnectorsLocations(FlowLink FL, DragEventArgs e)
        {
            // We know the source connector the user clicked on
            switch (mCurrnetFlowElemControl)
            {
            case "LeftConnector":
                FL.SourcePosition = FlowLink.eFlowElementPosition.Left;
                break;

            case "RightConnector":
                FL.SourcePosition = FlowLink.eFlowElementPosition.Right;
                break;

            case "TopConnector":
                FL.SourcePosition = FlowLink.eFlowElementPosition.Top;
                break;

            case "BottomConnector":
                FL.SourcePosition = FlowLink.eFlowElementPosition.bottom;
                break;
            }

            // TODO: if we plan to enable more than the 4 basic connectors then make a list of connectors

            //Destination - find closest connector to Mouse pos on the dest FlowElem
            // We use the event args to get posiition since it is not reliable to use Mouse.GetPosition during drag operation
            Point  mp1 = e.GetPosition(FL.Destination.TopConnector);
            double d1  = Point.Subtract(mp1, new Point(0, 0)).Length;

            Point  mp2 = e.GetPosition(FL.Destination.BottomConnector);
            double d2  = Point.Subtract(mp2, new Point(0, 0)).Length;

            Point  mp3 = e.GetPosition(FL.Destination.LeftConnector);
            double d3  = Point.Subtract(mp3, new Point(0, 0)).Length;

            Point  mp4 = e.GetPosition(FL.Destination.RightConnector);
            double d4  = Point.Subtract(mp4, new Point(0, 0)).Length;

            double min = d1;

            FL.DestinationPosition = FlowLink.eFlowElementPosition.Top;

            if (d2 < min)
            {
                min = d2;
                FL.DestinationPosition = FlowLink.eFlowElementPosition.bottom;
            }

            if (d3 < min)
            {
                min = d3;
                FL.DestinationPosition = FlowLink.eFlowElementPosition.Left;
            }

            if (d4 < min)
            {
                min = d4;
                FL.DestinationPosition = FlowLink.eFlowElementPosition.Right;
            }
        }
Ejemplo n.º 3
0
 public void AddConnector(FlowLink FL)
 {
     GEList.Add(FL);
     FL.Draw();
     MainCanvas.Children.Add(FL);
 }