Esempio n. 1
0
        public void Disconnect(dynPort p)
        {
            if (p.Equals(pStart))
            {
                //pStart.Owner.Outputs[pStart.Index] = null;
                pStart = null;
            }

            if (p.Equals(pEnd))
            {
                if (pEnd.PortType == PortType.INPUT)
                {
                    pEnd.Owner.InPortData[pEnd.Index].Object = null;
                }
                else if (pEnd.PortType == PortType.STATE)
                {
                    pEnd.Owner.StatePortData[pEnd.Index].Object = null;
                }
                pEnd = null;
            }

            p.Disconnect(this);

            //turn the connector back to dashed
            connector.StrokeDashArray.Add(5);
            connector.StrokeDashArray.Add(2);
        }
Esempio n. 2
0
        public bool Connect(dynPort p)
        {
            //test if the port that you are connecting too is not the start port or the end port
            //of the current connector
            if (p.Equals(pStart) || p.Equals(pEnd))
            {
                return(false);
            }

            //if the selected connector is also an output connector, return false
            //output ports can't be connected to eachother
            if (p.PortType == PortType.OUTPUT)
            {
                return(false);
            }

            //test if the port that you are connecting to is an input and
            //already has other connectors
            if (p.PortType == PortType.INPUT && p.Connectors.Count > 0)
            {
                return(false);
            }

            //test if the port element at B can connect to the port at A
            //test if you can convert the element at A to the element at b
            if (p.PortType == PortType.INPUT)
            {
                if (!p.Owner.InPortData[p.Index].PortType.IsAssignableFrom(pStart.Owner.OutPortData[pStart.Index].PortType))
                {
                    return(false);
                }
            }
            else if (p.PortType == PortType.STATE)
            {
                if (!p.Owner.StatePortData[p.Index].PortType.IsAssignableFrom(pStart.Owner.OutPortData[pStart.Index].PortType))
                {
                    return(false);
                }
            }

            //turn the line solid
            connector.StrokeDashArray.Clear();

            pEnd = p;

            if (pEnd != null)
            {
                //set the start and end values to equal so this
                //starts evaulating immediately
                pEnd.Owner.InPortData[p.Index].Object = pStart.Owner.OutPortData[pStart.Index].Object;
                p.Connect(this);
                pEnd.Update();
                pEnd.Owner.Update();
            }

            return(true);
        }
Esempio n. 3
0
        public dynConnector(dynPort port, Canvas workBench, Point mousePt)
        {
            //don't allow connections to start at an input port
            if (port.PortType != PortType.INPUT)
            {
                //get start point
                //this.workBench = workBench;
                pStart = port;

                pStart.Connect(this);

                //Create a Bezier;
                connector = new Path();
                connector.Stroke = Brushes.Black;
                connector.StrokeThickness = STROKE_THICKNESS;
                connector.Opacity = .8;

                DoubleCollection dashArray = new DoubleCollection();
                dashArray.Add(5); dashArray.Add(2);
                connector.StrokeDashArray = dashArray;

                PathGeometry connectorGeometry = new PathGeometry();
                connectorPoints = new PathFigure();
                connectorCurve = new BezierSegment();

                connectorPoints.StartPoint = new Point(pStart.Center.X, pStart.Center.Y);
                connectorCurve.Point1 = connectorPoints.StartPoint;
                connectorCurve.Point2 = connectorPoints.StartPoint;
                connectorCurve.Point3 = connectorPoints.StartPoint;

                connectorPoints.Segments.Add(connectorCurve);
                connectorGeometry.Figures.Add(connectorPoints);
                connector.Data = connectorGeometry;
                workBench.Children.Add(connector);

                isDrawing = true;

                //set this to not draggable
                Dynamo.Controls.DragCanvas.SetCanBeDragged(this, false);
                Dynamo.Controls.DragCanvas.SetCanBeDragged(connector, false);

                //set the z order to the front
                Canvas.SetZIndex(this, 300);

                //register an event listener for the start port update
                //this will tell the connector to set the elements at either
                //end to be equal if pStart and pEnd are not null
                //pStart.Owner.Outputs[pStart.Index].dynElementUpdated += new Dynamo.Elements.dynElementUpdatedHandler(StartPortUpdated);
            }
            else
            {
                throw new InvalidPortException();
            }
        }
Esempio n. 4
0
        public dynConnector(dynPort port, Canvas workBench, Point mousePt)
        {
            //don't allow connections to start at an input port
            if (port.PortType != PortType.INPUT)
            {
                //get start point
                //this.workBench = workBench;
                pStart = port;

                pStart.Connect(this);

                //Create a Bezier;
                connector                 = new Path();
                connector.Stroke          = Brushes.Black;
                connector.StrokeThickness = STROKE_THICKNESS;
                connector.Opacity         = .8;

                DoubleCollection dashArray = new DoubleCollection();
                dashArray.Add(5); dashArray.Add(2);
                connector.StrokeDashArray = dashArray;

                PathGeometry connectorGeometry = new PathGeometry();
                connectorPoints = new PathFigure();
                connectorCurve  = new BezierSegment();

                connectorPoints.StartPoint = new Point(pStart.Center.X, pStart.Center.Y);
                connectorCurve.Point1      = connectorPoints.StartPoint;
                connectorCurve.Point2      = connectorPoints.StartPoint;
                connectorCurve.Point3      = connectorPoints.StartPoint;

                connectorPoints.Segments.Add(connectorCurve);
                connectorGeometry.Figures.Add(connectorPoints);
                connector.Data = connectorGeometry;
                workBench.Children.Add(connector);

                isDrawing = true;

                //set this to not draggable
                Dynamo.Controls.DragCanvas.SetCanBeDragged(this, false);
                Dynamo.Controls.DragCanvas.SetCanBeDragged(connector, false);

                //set the z order to the front
                Canvas.SetZIndex(this, 300);

                //register an event listener for the start port update
                //this will tell the connector to set the elements at either
                //end to be equal if pStart and pEnd are not null
                //pStart.Owner.Outputs[pStart.Index].dynElementUpdated += new Dynamo.Elements.dynElementUpdatedHandler(StartPortUpdated);
            }
            else
            {
                throw new InvalidPortException();
            }
        }
Esempio n. 5
0
        public void Kill()
        {
            if (pStart != null && pStart.Connectors.Contains(this))
            {
                pStart.Disconnect(this);
                //pStart.Connectors.Remove(this);
                //do not remove the owner's output element
            }
            if (pEnd != null && pEnd.Connectors.Contains(this))
            {
                pEnd.Disconnect(this);
                //remove the reference to the
                //dynElement attached to port A
                pEnd.Owner.InPortData[pEnd.Index].Object = null;
            }

            pStart = null;
            pEnd   = null;

            dynElementSettings.SharedInstance.Workbench.Children.Remove(connector);

            isDrawing = false;
        }
Esempio n. 6
0
        public dynConnector(dynNodeUI start, dynNodeUI end, int startIndex, int endIndex, int portType, bool visible)
        {
            //don't try to create a connector with a bad start,
            //end, or if we're trying to connector the same
            //port to itself.
            if (start == null || end == null || start == end)
            {
                throw new Exception("Attempting to create connector with invalid start or end nodes.");
            }

            pStart = start.OutPorts[startIndex];

            dynPort endPort = null;

            if (portType == 0)
                endPort = end.InPorts[endIndex];

            //connect the two ports
            //get start point

            pStart.Connect(this);

            BrushConverter bc = new BrushConverter();
            strokeBrush = (Brush)bc.ConvertFrom("#313131");

            #region bezier creation
            connector = new Path();
            connector.Stroke = strokeBrush;
            connector.StrokeThickness = STROKE_THICKNESS;
            connector.Opacity = STROKE_OPACITY;

            connector.DataContext = this;
            Binding strokeBinding = new Binding("StrokeBrush");
            connector.SetBinding(Path.StrokeProperty, strokeBinding);

            DoubleCollection dashArray = new DoubleCollection();
            dashArray.Add(5); dashArray.Add(2);
            connector.StrokeDashArray = dashArray;

            PathGeometry connectorGeometry = new PathGeometry();
            connectorPoints = new PathFigure();
            connectorCurve = new BezierSegment();

            connectorPoints.StartPoint = new Point(pStart.Center.X, pStart.Center.Y);
            connectorCurve.Point1 = connectorPoints.StartPoint;
            connectorCurve.Point2 = connectorPoints.StartPoint;
            connectorCurve.Point3 = connectorPoints.StartPoint;

            connectorPoints.Segments.Add(connectorCurve);
            connectorGeometry.Figures.Add(connectorPoints);
            connector.Data = connectorGeometry;
            dynSettings.Workbench.Children.Add(connector);
            #endregion

            #region polyline creation
            plineConnector = new Path();
            plineConnector.Stroke = strokeBrush;
            plineConnector.StrokeThickness = STROKE_THICKNESS;
            plineConnector.Opacity = STROKE_OPACITY;
            plineConnector.StrokeDashArray = dashArray;

            PathGeometry plineGeometry = new PathGeometry();
            //http://msdn.microsoft.com/en-us/library/system.windows.media.polylinesegment(v=vs.85).aspx
            plineFigure = new PathFigure();
            plineFigure.StartPoint = new Point(pStart.Center.X, pStart.Center.Y);
            Point[] polyLinePointArray = new Point[] { connectorPoints.StartPoint,
                connectorPoints.StartPoint,
                connectorPoints.StartPoint};
            pline = new PolyLineSegment(polyLinePointArray, true);
            pline.Points = new PointCollection(polyLinePointArray);
            plineFigure.Segments.Add(pline);
            plineGeometry.Figures.Add(plineFigure);
            plineConnector.Data = plineGeometry;
            dynSettings.Workbench.Children.Add(plineConnector);
            #endregion

            endDot = new Ellipse();
            endDot.Height = 6;
            endDot.Width = 6;
            endDot.Fill = Brushes.Black;
            endDot.StrokeThickness = 2;
            endDot.Stroke = Brushes.Black;
            endDot.IsHitTestVisible = false;
            endDot.MouseDown +=new System.Windows.Input.MouseButtonEventHandler(endDot_MouseDown);
            Canvas.SetTop(endDot, connectorCurve.Point3.Y - END_DOT_SIZE / 2);
            Canvas.SetLeft(endDot, connectorCurve.Point3.X - END_DOT_SIZE / 2);
            dynSettings.Workbench.Children.Add(endDot);
            endDot.Opacity = STROKE_OPACITY;
            endDot.IsHitTestVisible = false;
            endDot.MouseDown += new System.Windows.Input.MouseButtonEventHandler(endDot_MouseDown);

            this.Visible = visible;

            connector.MouseEnter += delegate { if (pEnd != null) Highlight(); };
            connector.MouseLeave += delegate { Unhighlight(); };
            plineConnector.MouseEnter += delegate { if (pEnd != null) Highlight(); };
            plineConnector.MouseLeave += delegate { Unhighlight(); };

            isDrawing = true;

            //set this to not draggable
            Dynamo.Controls.DragCanvas.SetCanBeDragged(this, false);
            Dynamo.Controls.DragCanvas.SetCanBeDragged(connector, false);

            //set the z order to the front
            //Canvas.SetZIndex(this, 300);
            Canvas.SetZIndex(this, 1);

            this.Connect(endPort);

            ConnectorType = dynSettings.Bench.ConnectorType;
        }
Esempio n. 7
0
        /// <summary>
        /// Add a dynPort element to this control.
        /// </summary>
        /// <param name="isInput">Is the port an input?</param>
        /// <param name="index">The index of the port in the port list.</param>
        public dynPort AddPort(PortType portType, string name, int index)
        {
            if (portType == PortType.INPUT)
            {
                if (inPorts.Count > index)
                {
                    portTextBlocks[inPorts[index]].Text = name;
                    return inPorts[index];
                }
                else
                {
                    dynPort p = new dynPort(index);

                    //create a text block for the name of the port
                    TextBlock tb = new TextBlock();

                    tb.VerticalAlignment = VerticalAlignment.Center;
                    tb.FontSize = 12;
                    tb.FontWeight = FontWeights.Normal;
                    tb.Foreground = new SolidColorBrush(Colors.Black);
                    tb.Text = name;

                    tb.HorizontalAlignment = HorizontalAlignment.Left;

                    Canvas.SetZIndex(tb, 200);

                    p.PortType = PortType.INPUT;
                    InPorts.Add(p);
                    portTextBlocks[p] = tb;
                    gridLeft.Children.Add(p);
                    Grid.SetColumn(p, 0);
                    Grid.SetRow(p, index);

                    //portNamesLeft.Children.Add(tb);
                    gridLeft.Children.Add(tb);
                    Grid.SetColumn(tb, 1);
                    Grid.SetRow(tb, index);

                    p.Owner = this;

                    //register listeners on the port
                    p.PortConnected += new PortConnectedHandler(p_PortConnected);
                    p.PortDisconnected += new PortConnectedHandler(p_PortDisconnected);

                    return p;
                }
            }
            else if (portType == PortType.OUTPUT)
            {
                if (outPorts.Count > index)
                {
                    portTextBlocks[outPorts[index]].Text = name;
                    return outPorts[index];
                }
                else
                {
                    dynPort p = new dynPort(index);

                    //create a text block for the name of the port
                    TextBlock tb = new TextBlock();

                    tb.VerticalAlignment = VerticalAlignment.Center;
                    tb.FontSize = 12;
                    tb.FontWeight = FontWeights.Normal;
                    tb.Foreground = new SolidColorBrush(Colors.Black);
                    tb.Text = name;

                    tb.HorizontalAlignment = HorizontalAlignment.Right;

                    p.PortType = PortType.OUTPUT;
                    OutPorts.Add(p);
                    portTextBlocks[p] = tb;
                    gridRight.Children.Add(p);
                    Grid.SetColumn(p, 1);
                    Grid.SetRow(p, index);

                    //portNamesLeft.Children.Add(tb);
                    gridRight.Children.Add(tb);
                    Grid.SetColumn(tb, 0);
                    Grid.SetRow(tb, index);

                    p.Owner = this;

                    //register listeners on the port
                    p.PortConnected += new PortConnectedHandler(p_PortConnected);
                    p.PortDisconnected += new PortConnectedHandler(p_PortDisconnected);

                    ScaleTransform trans = new ScaleTransform(-1, 1, p.Width / 2, p.Height / 2);
                    p.RenderTransform = trans;

                    return p;
                }
            }
            return null;
        }
Esempio n. 8
0
        public dynConnector(dynElement start, dynElement end, int startIndex, int endIndex, int portType)
        {
            //this.workBench = settings.WorkBench;

            //if (start != null && end != null && start != end)
            //{
            //in the start element, find the out port at the startIndex
            pStart = start.OutPorts[startIndex];

            dynPort endPort = null;

            if (portType == 0)
            {
                endPort = end.InPorts[endIndex];
            }
            else if (portType == 1)
            {
                endPort = end.StatePorts[endIndex];
            }

            //connect the two ports
            //get start point

            pStart.Connect(this);

            #region bezier creation
            connector                 = new Path();
            connector.Stroke          = Brushes.Black;
            connector.StrokeThickness = STROKE_THICKNESS;
            connector.Opacity         = .8;

            DoubleCollection dashArray = new DoubleCollection();
            dashArray.Add(5); dashArray.Add(2);
            connector.StrokeDashArray = dashArray;

            PathGeometry connectorGeometry = new PathGeometry();
            connectorPoints = new PathFigure();
            connectorCurve  = new BezierSegment();

            connectorPoints.StartPoint = new Point(pStart.Center.X, pStart.Center.Y);
            connectorCurve.Point1      = connectorPoints.StartPoint;
            connectorCurve.Point2      = connectorPoints.StartPoint;
            connectorCurve.Point3      = connectorPoints.StartPoint;

            connectorPoints.Segments.Add(connectorCurve);
            connectorGeometry.Figures.Add(connectorPoints);
            connector.Data = connectorGeometry;
            dynElementSettings.SharedInstance.Workbench.Children.Add(connector);

            #endregion

            isDrawing = true;

            //set this to not draggable
            Dynamo.Controls.DragCanvas.SetCanBeDragged(this, false);
            Dynamo.Controls.DragCanvas.SetCanBeDragged(connector, false);

            //set the z order to the front
            Canvas.SetZIndex(this, 300);

            this.Connect(endPort);

            //}
        }
Esempio n. 9
0
        public void ClearOutputs()
        {
            foreach (dynConnector c in outPort.Connectors)
            {
                c.Kill();
            }

            outPort = null;
            outPortData = null;
        }
Esempio n. 10
0
        private void RemovePort(dynPort inport)
        {
            if (inport.PortType == PortType.INPUT)
            {
                int index = inPorts.FindIndex(x => x == inport);

                gridLeft.Children.Remove(inport);
                gridLeft.Children.Remove(inPortTextBlocks[inport]);

                while (inport.Connectors.Any())
                {
                    inport.Connectors[0].Kill();
                }
            }
        }
Esempio n. 11
0
        public void Kill()
        {
            if (pStart != null && pStart.Connectors.Contains(this))
            {
                pStart.Disconnect(this);
                //pStart.Connectors.Remove(this);
                //do not remove the owner's output element
            }
            if (pEnd != null && pEnd.Connectors.Contains(this))
            {
                pEnd.Disconnect(this);
                //remove the reference to the
                //dynElement attached to port A

                //if (pEnd.Index < pEnd.Owner.InPortData.Count)
                //{
                //   pEnd.Owner.InPortData[pEnd.Index].Object = null;
                //}
            }

            pStart = null;
            pEnd = null;

            dynSettings.Workbench.Children.Remove(connector);
            dynSettings.Workbench.Children.Remove(plineConnector);
            dynSettings.Workbench.Children.Remove(endDot);

            isDrawing = false;

            dynSettings.Bench.RemoveConnector(this);
        }
Esempio n. 12
0
        public dynConnector(dynPort port, Canvas workBench, Point mousePt)
        {
            //don't allow connections to start at an input port
             if (port.PortType != PortType.INPUT)
             {
            //get start point
            //this.workBench = workBench;
            pStart = port;

            pStart.Connect(this);

            BrushConverter bc = new BrushConverter();
            Brush strokeBrush = (Brush)bc.ConvertFrom("#313131");

            #region bezier creation
            connector = new Path();

            connector.Stroke = strokeBrush;
            connector.StrokeThickness = STROKE_THICKNESS;
            connector.Opacity = STROKE_OPACITY;

            DoubleCollection dashArray = new DoubleCollection();
            dashArray.Add(5); dashArray.Add(2);
            connector.StrokeDashArray = dashArray;

            PathGeometry connectorGeometry = new PathGeometry();
            connectorPoints = new PathFigure();
            connectorCurve = new BezierSegment();

            connectorPoints.StartPoint = new Point(pStart.Center.X, pStart.Center.Y);
            connectorCurve.Point1 = connectorPoints.StartPoint;
            connectorCurve.Point2 = connectorPoints.StartPoint;
            connectorCurve.Point3 = connectorPoints.StartPoint;

            connectorPoints.Segments.Add(connectorCurve);
            connectorGeometry.Figures.Add(connectorPoints);
            connector.Data = connectorGeometry;
            workBench.Children.Add(connector);
            #endregion

            #region polyline creation
            plineConnector = new Path();
            plineConnector.Stroke = strokeBrush;
            plineConnector.StrokeThickness = STROKE_THICKNESS;
            plineConnector.Opacity = STROKE_OPACITY;
            plineConnector.StrokeDashArray = dashArray;

            PathGeometry plineGeometry = new PathGeometry();
            //http://msdn.microsoft.com/en-us/library/system.windows.media.polylinesegment(v=vs.85).aspx
            plineFigure = new PathFigure();
            plineFigure.StartPoint = connectorPoints.StartPoint;
            Point[] polyLinePointArray = new Point[] { connectorPoints.StartPoint,
                connectorPoints.StartPoint,
                connectorPoints.StartPoint};
            pline = new PolyLineSegment(polyLinePointArray, true);
            pline.Points = new PointCollection(polyLinePointArray);
            plineFigure.Segments.Add(pline);
            plineGeometry.Figures.Add(plineFigure);
            plineConnector.Data = plineGeometry;
            dynElementSettings.SharedInstance.Workbench.Children.Add(plineConnector);
            #endregion

            endDot = new Ellipse();
            endDot.Height = 6;
            endDot.Width = 6;
            endDot.Fill = Brushes.Black;
            endDot.StrokeThickness = 2;
            endDot.Stroke = Brushes.Black;
            Canvas.SetTop(endDot, connectorCurve.Point3.Y - END_DOT_SIZE/2);
            Canvas.SetLeft(endDot, connectorCurve.Point3.X - END_DOT_SIZE/2);
            dynElementSettings.SharedInstance.Workbench.Children.Add(endDot);
            endDot.Opacity = STROKE_OPACITY;

            connector.MouseEnter += delegate { if (pEnd != null) Highlight(); };
            connector.MouseLeave += delegate { Unhighlight(); };
            plineConnector.MouseEnter += delegate { if (pEnd != null) Highlight(); };
            plineConnector.MouseLeave += delegate { Unhighlight(); };

            isDrawing = true;

            //set this to not draggable
            Dynamo.Controls.DragCanvas.SetCanBeDragged(this, false);
            Dynamo.Controls.DragCanvas.SetCanBeDragged(connector, false);

            //set the z order to the front
            Canvas.SetZIndex(connector, 0);
            Canvas.SetZIndex(endDot, 1);

            //register an event listener for the start port update
            //this will tell the connector to set the elements at either
            //end to be equal if pStart and pEnd are not null
            //pStart.Owner.Outputs[pStart.Index].dynElementUpdated += new Dynamo.Elements.dynElementUpdatedHandler(StartPortUpdated);
            this.ConnectorType = dynElementSettings.SharedInstance.Bench.ConnectorType;
            dynElementSettings.SharedInstance.Bench.settings_curves.Checked += new RoutedEventHandler(settings_curves_Checked);
            dynElementSettings.SharedInstance.Bench.settings_plines.Checked += new RoutedEventHandler(settings_plines_Checked);
             }
             else
             {
            throw new InvalidPortException();
             }
        }
Esempio n. 13
0
        public dynConnector(dynNode start, dynNode end, int startIndex, int endIndex, int portType, bool visible)
        {
            //this.workBench = settings.WorkBench;

             //if (start != null && end != null && start != end)
             //{
             //in the start element, find the out port at the startIndex
             pStart = start.OutPort;

             dynPort endPort = null;

             if (portType == 0)
            endPort = end.InPorts[endIndex];
             else if (portType == 1)
            endPort = end.StatePorts[endIndex];

             //connect the two ports
             //get start point

             pStart.Connect(this);

             BrushConverter bc = new BrushConverter();
             Brush strokeBrush = (Brush)bc.ConvertFrom("#313131");

             #region bezier creation
             connector = new Path();
             connector.Stroke = strokeBrush;
             connector.StrokeThickness = STROKE_THICKNESS;
             connector.Opacity = STROKE_OPACITY;

             DoubleCollection dashArray = new DoubleCollection();
             dashArray.Add(5); dashArray.Add(2);
             connector.StrokeDashArray = dashArray;

             PathGeometry connectorGeometry = new PathGeometry();
             connectorPoints = new PathFigure();
             connectorCurve = new BezierSegment();

             connectorPoints.StartPoint = new Point(pStart.Center.X, pStart.Center.Y);
             connectorCurve.Point1 = connectorPoints.StartPoint;
             connectorCurve.Point2 = connectorPoints.StartPoint;
             connectorCurve.Point3 = connectorPoints.StartPoint;

             connectorPoints.Segments.Add(connectorCurve);
             connectorGeometry.Figures.Add(connectorPoints);
             connector.Data = connectorGeometry;
             dynElementSettings.SharedInstance.Workbench.Children.Add(connector);
             #endregion

             #region polyline creation
             plineConnector = new Path();
             plineConnector.Stroke = strokeBrush;
             plineConnector.StrokeThickness = STROKE_THICKNESS;
             plineConnector.Opacity = STROKE_OPACITY;
             plineConnector.StrokeDashArray = dashArray;

             PathGeometry plineGeometry = new PathGeometry();
             //http://msdn.microsoft.com/en-us/library/system.windows.media.polylinesegment(v=vs.85).aspx
             plineFigure = new PathFigure();
             plineFigure.StartPoint = new Point(pStart.Center.X, pStart.Center.Y);
             Point[] polyLinePointArray = new Point[] { connectorPoints.StartPoint,
                connectorPoints.StartPoint,
                connectorPoints.StartPoint};
             pline = new PolyLineSegment(polyLinePointArray, true);
             pline.Points = new PointCollection(polyLinePointArray);
             plineFigure.Segments.Add(pline);
             plineGeometry.Figures.Add(plineFigure);
             plineConnector.Data = plineGeometry;
             dynElementSettings.SharedInstance.Workbench.Children.Add(plineConnector);
             #endregion

             endDot = new Ellipse();
             endDot.Height = 6;
             endDot.Width = 6;
             endDot.Fill = Brushes.Black;
             endDot.StrokeThickness = 2;
             endDot.Stroke = Brushes.Black;
             Canvas.SetTop(endDot, connectorCurve.Point3.Y - END_DOT_SIZE/2);
             Canvas.SetLeft(endDot, connectorCurve.Point3.X - END_DOT_SIZE/2);
             dynElementSettings.SharedInstance.Workbench.Children.Add(endDot);
             endDot.Opacity = STROKE_OPACITY;

             this.Visible = visible;

             connector.MouseEnter += delegate { if (pEnd != null) Highlight(); };
             connector.MouseLeave += delegate { Unhighlight(); };
             plineConnector.MouseEnter += delegate { if (pEnd != null) Highlight(); };
             plineConnector.MouseLeave += delegate { Unhighlight(); };

             isDrawing = true;

             //set this to not draggable
             Dynamo.Controls.DragCanvas.SetCanBeDragged(this, false);
             Dynamo.Controls.DragCanvas.SetCanBeDragged(connector, false);

             //set the z order to the front
             Canvas.SetZIndex(this, 300);

             this.Connect(endPort);

             this.ConnectorType = dynElementSettings.SharedInstance.Bench.ConnectorType;
             dynElementSettings.SharedInstance.Bench.settings_curves.Checked += new RoutedEventHandler(settings_curves_Checked);
             dynElementSettings.SharedInstance.Bench.settings_plines.Checked += new RoutedEventHandler(settings_plines_Checked);
        }
Esempio n. 14
0
        public bool Connect(dynPort p)
        {
            //test if the port that you are connecting too is not the start port or the end port
            //of the current connector
            if (p.Equals(pStart) || p.Equals(pEnd))
            {
                return false;
            }

            //if the selected connector is also an output connector, return false
            //output ports can't be connected to eachother
            if (p.PortType == PortType.OUTPUT)
            {
                return false;
            }

            //test if the port that you are connecting to is an input and
            //already has other connectors
            if (p.PortType == PortType.INPUT && p.Connectors.Count > 0)
            {
                return false;
            }

            //turn the line solid
            connector.StrokeDashArray.Clear();
            plineConnector.StrokeDashArray.Clear();
            pEnd = p;

            if (pEnd != null)
            {
                //set the start and end values to equal so this
                //starts evaulating immediately
                //pEnd.Owner.InPortData[p.Index].Object = pStart.Owner.OutPortData.Object;
                p.Connect(this);
                pEnd.Update();
            }

            return true;
        }
Esempio n. 15
0
        /// <summary>
        /// Add a dynPort element to this control.
        /// </summary>
        /// <param name="isInput">Is the port an input?</param>
        /// <param name="index">The index of the port in the port list.</param>
        public void AddPort(object el, PortType portType, string name, int index)
        {
            dynPort p = new dynPort(index);

            //create a text block for the name of the port
            TextBlock tb = new TextBlock();

            tb.VerticalAlignment = VerticalAlignment.Center;
            tb.FontSize = 12;
            tb.FontWeight = FontWeights.Normal;
            tb.Foreground = new SolidColorBrush(Colors.Black);
            tb.Text = name;

            //set the z order to the back
            //Canvas.SetZIndex(p, 1);

            if (portType == PortType.INPUT)
            {
                tb.HorizontalAlignment = HorizontalAlignment.Left;

                p.PortType = PortType.INPUT;
                inPorts.Add(p);
                gridLeft.Children.Add(p);
                Grid.SetColumn(p, 0);
                Grid.SetRow(p, index);

                //portNamesLeft.Children.Add(tb);
                gridLeft.Children.Add(tb);
                Grid.SetColumn(tb, 1);
                Grid.SetRow(tb, index);

            }
            else if(portType == PortType.OUTPUT)
            {

                tb.HorizontalAlignment = HorizontalAlignment.Right;

                p.PortType = PortType.OUTPUT;
                outPorts.Add(p);
                gridRight.Children.Add(p);
                Grid.SetColumn(p, 1);
                Grid.SetRow(p, index);

                //portNamesRight.Children.Add(tb);
                gridRight.Children.Add(tb);
                Grid.SetColumn(tb, 0);
                Grid.SetRow(tb, index);

            }
            //else if (portType == PortType.STATE)
            //{
            //    tb.HorizontalAlignment = HorizontalAlignment.Center;

            //    p.PortType = PortType.STATE;
            //    statePorts.Add(p);
            //    gridBottom.Children.Add(p);
            //    Grid.SetColumn(p, index);
            //    Grid.SetRow(p, 0);

            //    portNamesBottom.Children.Add(tb);
            //    Grid.SetColumn(tb, index);
            //    Grid.SetRow(tb, 0);
            //}

            p.Owner = this;

            //register listeners on the port
            p.PortConnected += new PortConnectedHandler(p_PortConnected);
            p.PortDisconnected += new PortConnectedHandler(p_PortDisconnected);
        }
Esempio n. 16
0
        public void Disconnect(dynPort p)
        {
            if (p.Equals(pStart))
            {
                pStart = null;
            }

            if (p.Equals(pEnd))
            {
                pEnd = null;
            }

            p.Disconnect(this);

            //turn the connector back to dashed
            connector.StrokeDashArray.Add(5);
            connector.StrokeDashArray.Add(2);

            plineConnector.StrokeDashArray.Add(5);
            plineConnector.StrokeDashArray.Add(2);
        }
Esempio n. 17
0
        public dynConnector(dynElement start, dynElement end, int startIndex, int endIndex, int portType)
        {
            //this.workBench = settings.WorkBench;

            //if (start != null && end != null && start != end)
            //{
                //in the start element, find the out port at the startIndex
                pStart = start.OutPorts[startIndex];

                dynPort endPort = null;

                if (portType == 0)
                    endPort = end.InPorts[endIndex];
                else if (portType == 1)
                    endPort = end.StatePorts[endIndex];

                //connect the two ports
                //get start point

                pStart.Connect(this);

                #region bezier creation
                connector = new Path();
                connector.Stroke = Brushes.Black;
                connector.StrokeThickness = STROKE_THICKNESS;
                connector.Opacity = .8;

                DoubleCollection dashArray = new DoubleCollection();
                dashArray.Add(5); dashArray.Add(2);
                connector.StrokeDashArray = dashArray;

                PathGeometry connectorGeometry = new PathGeometry();
                connectorPoints = new PathFigure();
                connectorCurve = new BezierSegment();

                connectorPoints.StartPoint = new Point(pStart.Center.X, pStart.Center.Y);
                connectorCurve.Point1 = connectorPoints.StartPoint;
                connectorCurve.Point2 = connectorPoints.StartPoint;
                connectorCurve.Point3 = connectorPoints.StartPoint;

                connectorPoints.Segments.Add(connectorCurve);
                connectorGeometry.Figures.Add(connectorPoints);
                connector.Data = connectorGeometry;
                dynElementSettings.SharedInstance.Workbench.Children.Add(connector);

                #endregion

                isDrawing = true;

                //set this to not draggable
                Dynamo.Controls.DragCanvas.SetCanBeDragged(this, false);
                Dynamo.Controls.DragCanvas.SetCanBeDragged(connector, false);

                //set the z order to the front
                Canvas.SetZIndex(this, 300);

                this.Connect(endPort);

            //}
        }
Esempio n. 18
0
        public dynConnector(dynPort port, Canvas workBench, Point mousePt)
        {
            //don't allow connections to start at an input port
            if (port.PortType != PortType.INPUT)
            {
                //get start point
                //this.workBench = workBench;
                pStart = port;

                pStart.Connect(this);

                BrushConverter bc = new BrushConverter();
                strokeBrush = (Brush)bc.ConvertFrom("#313131");

                #region bezier creation
                connector = new Path();
                connector.Stroke = strokeBrush;
                connector.StrokeThickness = STROKE_THICKNESS;
                connector.Opacity = STROKE_OPACITY;

                connector.DataContext = this;
                Binding strokeBinding = new Binding("StrokeBrush");
                connector.SetBinding(Path.StrokeProperty, strokeBinding);

                DoubleCollection dashArray = new DoubleCollection();
                dashArray.Add(5); dashArray.Add(2);
                connector.StrokeDashArray = dashArray;

                PathGeometry connectorGeometry = new PathGeometry();
                connectorPoints = new PathFigure();
                connectorCurve = new BezierSegment();

                connectorPoints.StartPoint = new Point(pStart.Center.X, pStart.Center.Y);
                connectorCurve.Point1 = connectorPoints.StartPoint;
                connectorCurve.Point2 = connectorPoints.StartPoint;
                connectorCurve.Point3 = connectorPoints.StartPoint;

                connectorPoints.Segments.Add(connectorCurve);
                connectorGeometry.Figures.Add(connectorPoints);
                connector.Data = connectorGeometry;
                workBench.Children.Add(connector);
                #endregion

                #region polyline creation
                plineConnector = new Path();
                plineConnector.Stroke = strokeBrush;
                plineConnector.StrokeThickness = STROKE_THICKNESS;
                plineConnector.Opacity = STROKE_OPACITY;
                plineConnector.StrokeDashArray = dashArray;

                PathGeometry plineGeometry = new PathGeometry();
                //http://msdn.microsoft.com/en-us/library/system.windows.media.polylinesegment(v=vs.85).aspx
                plineFigure = new PathFigure();
                plineFigure.StartPoint = connectorPoints.StartPoint;
                Point[] polyLinePointArray = new Point[] { connectorPoints.StartPoint,
                connectorPoints.StartPoint,
                connectorPoints.StartPoint};
                pline = new PolyLineSegment(polyLinePointArray, true);
                pline.Points = new PointCollection(polyLinePointArray);
                plineFigure.Segments.Add(pline);
                plineGeometry.Figures.Add(plineFigure);
                plineConnector.Data = plineGeometry;
                dynSettings.Workbench.Children.Add(plineConnector);
                #endregion

                endDot = new Ellipse();
                endDot.Height = 6;
                endDot.Width = 6;
                endDot.Fill = Brushes.Black;
                endDot.StrokeThickness = 2;
                endDot.Stroke = Brushes.Black;
                endDot.IsHitTestVisible = false;
                endDot.MouseDown += new System.Windows.Input.MouseButtonEventHandler(endDot_MouseDown);
                Canvas.SetTop(endDot, connectorCurve.Point3.Y - END_DOT_SIZE / 2);
                Canvas.SetLeft(endDot, connectorCurve.Point3.X - END_DOT_SIZE / 2);
                dynSettings.Workbench.Children.Add(endDot);
                endDot.Opacity = STROKE_OPACITY;

                connector.MouseEnter += delegate { if (pEnd != null) Highlight(); };
                connector.MouseLeave += delegate { Unhighlight(); };
                plineConnector.MouseEnter += delegate { if (pEnd != null) Highlight(); };
                plineConnector.MouseLeave += delegate { Unhighlight(); };

                isDrawing = true;

                //set this to not draggable
                Dynamo.Controls.DragCanvas.SetCanBeDragged(this, false);
                Dynamo.Controls.DragCanvas.SetCanBeDragged(connector, false);

                //set the z order to the front
                Canvas.SetZIndex(connector, 0);
                Canvas.SetZIndex(endDot, 1);

                ConnectorType = dynSettings.Bench.ConnectorType;

            }
            else
            {
                throw new InvalidPortException();
            }
        }
Esempio n. 19
0
        public void Disconnect(dynPort p)
        {
            if (p.Equals(pStart))
            {
                //pStart.Owner.Outputs[pStart.Index] = null;
                pStart = null;
            }

            if (p.Equals(pEnd))
            {
                if(pEnd.PortType == PortType.INPUT)
                    pEnd.Owner.InPortData[pEnd.Index].Object = null;
                else if(pEnd.PortType == PortType.STATE)
                    pEnd.Owner.StatePortData[pEnd.Index].Object = null;
                pEnd = null;
            }

            p.Disconnect(this);

            //turn the connector back to dashed
            connector.StrokeDashArray.Add(5);
            connector.StrokeDashArray.Add(2);
        }
Esempio n. 20
0
        /// <summary>
        /// Add a dynPort element to this control.
        /// </summary>
        /// <param name="isInput">Is the port an input?</param>
        /// <param name="index">The index of the port in the port list.</param>
        public void AddPort(PortType portType, string name, int index)
        {
            if (portType == PortType.INPUT)
            {
                if (inPorts.Count > index)
                {
                    inPortTextBlocks[inPorts[index]].Text = name;
                }
                else
                {
                    dynPort p = new dynPort(index);

                    //create a text block for the name of the port
                    TextBlock tb = new TextBlock();

                    tb.VerticalAlignment = VerticalAlignment.Center;
                    tb.FontSize = 12;
                    tb.FontWeight = FontWeights.Normal;
                    tb.Foreground = new SolidColorBrush(Colors.Black);
                    tb.Text = name;

                    tb.HorizontalAlignment = HorizontalAlignment.Left;

                    Canvas.SetZIndex(tb, 200);

                    p.PortType = PortType.INPUT;
                    inPorts.Add(p);
                    inPortTextBlocks[p] = tb;
                    gridLeft.Children.Add(p);
                    Grid.SetColumn(p, 0);
                    Grid.SetRow(p, index);

                    //portNamesLeft.Children.Add(tb);
                    gridLeft.Children.Add(tb);
                    Grid.SetColumn(tb, 1);
                    Grid.SetRow(tb, index);

                    p.Owner = this;

                    //register listeners on the port
                    p.PortConnected += new PortConnectedHandler(p_PortConnected);
                    p.PortDisconnected += new PortConnectedHandler(p_PortDisconnected);
                }
            }
        }
Esempio n. 21
0
        public void Kill()
        {
            if (pStart != null && pStart.Connectors.Contains(this))
            {
                pStart.Disconnect(this);
                //pStart.Connectors.Remove(this);
                //do not remove the owner's output element
            }
            if (pEnd!= null && pEnd.Connectors.Contains(this))
            {
                pEnd.Disconnect(this);
                //remove the reference to the
                //dynElement attached to port A
                pEnd.Owner.InPortData[pEnd.Index].Object = null;

            }

            pStart = null;
            pEnd = null;

            dynElementSettings.SharedInstance.Workbench.Children.Remove(connector);

            isDrawing = false;
        }
Esempio n. 22
0
        /// <summary>
        /// Reads outputs list and adds ports for each output
        /// </summary>
        public void RegisterOutputs()
        {
            //outPorts.Clear();

            //read the outputs list and create a number of
            //output ports
            //int count = 0;
            //foreach (PortData pd in OutPortData)
            //{
            //   //add a port for each output
            //   //pass in the y center of the port
            //   AddPort(pd.Object, PortType.OUTPUT, outPortData[count].NickName, count);
            //   count++;
            //}

            //AddPort(OutPortData.Object, PortType.OUTPUT, OutPortData.NickName, 0);

            dynPort p = new dynPort(0);

            //create a text block for the name of the port
            TextBlock tb = new TextBlock();

            tb.VerticalAlignment = VerticalAlignment.Center;
            tb.FontSize = 12;
            tb.FontWeight = FontWeights.Normal;
            tb.Foreground = new SolidColorBrush(Colors.Black);
            tb.Text = OutPortData.NickName;

            tb.HorizontalAlignment = HorizontalAlignment.Right;

            ScaleTransform trans = new ScaleTransform(-1, 1, p.Width/2, p.Height/2);
            p.RenderTransform = trans;

            p.PortType = PortType.OUTPUT;
            outPort = p;
            gridRight.Children.Add(p);
            Grid.SetColumn(p, 1);
            Grid.SetRow(p, 0);

            //portNamesRight.Children.Add(tb);
            gridRight.Children.Add(tb);
            Grid.SetColumn(tb, 0);
            Grid.SetRow(tb, 0);

            p.Owner = this;

            //register listeners on the port
            p.PortConnected += new PortConnectedHandler(p_PortConnected);
            p.PortDisconnected += new PortConnectedHandler(p_PortDisconnected);
        }
Esempio n. 23
0
        /// <summary>
        /// Add a dynPort element to this control.
        /// </summary>
        /// <param name="isInput">Is the port an input?</param>
        /// <param name="index">The index of the port in the port list.</param>
        public dynPort AddPort(PortType portType, string name, int index)
        {
            if (portType == PortType.INPUT)
            {
                if (inPorts.Count > index)
                {
                    return inPorts[index];
                }
                else
                {
                    dynPort p = new dynPort(index, portType, this, name);

                    InPorts.Add(p);

                    //register listeners on the port
                    p.PortConnected += new PortConnectedHandler(p_PortConnected);
                    p.PortDisconnected += new PortConnectedHandler(p_PortDisconnected);

                    return p;
                }
            }
            else if (portType == PortType.OUTPUT)
            {
                if (outPorts.Count > index)
                {
                    return outPorts[index];
                }
                else
                {
                    dynPort p = new dynPort(index, portType, this, name);

                    OutPorts.Add(p);

                    //register listeners on the port
                    p.PortConnected += new PortConnectedHandler(p_PortConnected);
                    p.PortDisconnected += new PortConnectedHandler(p_PortDisconnected);

                    return p;
                }
            }
            return null;
        }