Beispiel #1
0
        void OnMouseLeftButtonDown(object sender, System.Windows.Input.MouseEventArgs e)
        {
            //Keyboard.Focus(this);

            hitResultsList.Clear();
            TestClick(e.GetPosition(workBench));

            #region test for a port
            dynPort p = null;
            if (hitResultsList.Count > 0)
            {
                foreach (DependencyObject depObj in hitResultsList)
                {
                    //traverse the tree through all the
                    //hit elements to see if you get a port
                    p = ElementClicked(depObj, typeof(dynPort)) as dynPort;
                    if (p != null)
                    {
                        break;
                    }
                }
            }


            if (p != null)
            {
                if (!isConnecting)
                {
                    //test if port already has a connection if so grab it
                    //and begin connecting to somewhere else
                    //don't allow the grabbing of the start connector
                    if (p.Connectors.Count > 0 && p.Connectors[0].Start != p)
                    {
                        activeConnector = p.Connectors[0];
                        activeConnector.Disconnect(p);
                        isConnecting           = true;
                        workBench.isConnecting = true;
                    }
                    else
                    {
                        try
                        {
                            //you've begun creating a connector
                            dynConnector c = new dynConnector(p, workBench, e.GetPosition(workBench));
                            activeConnector        = c;
                            isConnecting           = true;
                            workBench.isConnecting = true;
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                        }
                    }
                }
                else
                {
                    //attempt a connection between the port
                    //and the connector
                    if (!activeConnector.Connect(p))
                    {
                        activeConnector.Kill();
                        isConnecting           = false;
                        workBench.isConnecting = false;
                        activeConnector        = null;
                    }
                    else
                    {
                        //you've already started connecting
                        //now you're going to stop
                        isConnecting           = false;
                        workBench.isConnecting = false;
                        activeConnector        = null;
                    }
                }

                //set the handled flag so that the element doesn't get dragged
                e.Handled = true;
            }
            else
            {
                //if you click on the canvas and you're connecting
                //then drop the connector, otherwise do nothing
                if (activeConnector != null)
                {
                    activeConnector.Kill();
                    isConnecting           = false;
                    workBench.isConnecting = false;
                    activeConnector        = null;
                }
            }
            #endregion

            #region test for canvas
            hitResultsList.Clear();
            TestClick(e.GetPosition(workBench));

            DragCanvas dc = null;
            if (hitResultsList.Count > 0)
            {
                foreach (DependencyObject depObj in hitResultsList)
                {
                    //traverse the tree through all the
                    //hit elements to see if you get a port
                    dc = ElementClicked(depObj, typeof(DragCanvas)) as DragCanvas;
                    if (dc != null)
                    {
                        Debug.WriteLine("Canvas clicked");
                        ClearSelection();
                        break;
                    }
                }
            }
            #endregion

            #region test for dyn element
            hitResultsList.Clear();
            TestClick(e.GetPosition(workBench));

            dynElement element = null;
            if (hitResultsList.Count > 0)
            {
                foreach (DependencyObject depObj in hitResultsList)
                {
                    //traverse the tree through all the
                    //hit elements to see if you get an element
                    element = ElementClicked(depObj, typeof(dynElement)) as dynElement;
                    if (element != null)
                    {
                        SelectElement(element);
                        break;
                    }
                }
            }
            #endregion
        }
 private void workBench_OnLoaded(object sender, RoutedEventArgs e)
 {
     workBench = sender as DragCanvas;
     workBench.owningWorkspace = this;
 }
Beispiel #3
0
 private void WorkBench_OnLoaded(object sender, RoutedEventArgs e)
 {
     WorkBench = sender as Dynamo.Controls.DragCanvas;
     WorkBench.owningWorkspace = this;
 }
 private void WorkBench_OnLoaded(object sender, RoutedEventArgs e)
 {
     WorkBench = sender as Dynamo.Controls.DragCanvas;
     WorkBench.owningWorkspace = this;
 }
 private void WorkBench_OnLoaded(object sender, RoutedEventArgs e)
 {
     WorkBench = sender as Dynamo.Controls.DragCanvas;
     //DrawGrid();
 }