Exemplo n.º 1
0
        /// <summary>
        /// Creates a connector between the ports of the specified shapes
        /// </summary>
        /// <param name="fromShape"></param>
        /// <param name="fromPortName"></param>
        /// <param name="toShape"></param>
        /// <param name="toPortName"></param>
        /// <param name="connectorType"></param>
        /// <param name="text"></param>
        /// <returns></returns>
        public NShape CreateConnector(NShape fromShape, string fromPortName, NShape toShape, string toPortName, ConnectorType connectorType, string text)
        {
            // check input
            if (fromShape == null)
            {
                throw new ArgumentNullException("fromShape");
            }

            if (toShape == null)
            {
                throw new ArgumentNullException("toShape");
            }

            NPort fromPort = (fromShape.Ports.GetChildByName(fromPortName, 0) as NPort);

            if (fromPort == null)
            {
                throw new ArgumentException("Was not able to find fromPortName in the ports collection of the fromShape", "fromPortName");
            }

            NPort toPort = (toShape.Ports.GetChildByName(toPortName, 0) as NPort);

            if (toPort == null)
            {
                throw new ArgumentException("Was not able to find toPortName in the ports collection of the toShape", "toPortName");
            }

            // create the connector
            NShape connector = null;

            switch (connectorType)
            {
            case ConnectorType.Line:
                connector = new NLineShape();
                break;

            case ConnectorType.Bezier:
                connector = new NBezierCurveShape();
                break;

            case ConnectorType.SingleArrow:
                connector = new NArrowShape(ArrowType.SingleArrow);
                break;

            case ConnectorType.DoubleArrow:
                connector = new NArrowShape(ArrowType.DoubleArrow);
                break;

            case ConnectorType.SideToTopBottom:
                connector = new NStep2Connector(false);
                break;

            case ConnectorType.TopBottomToSide:
                connector = new NStep2Connector(true);
                break;

            case ConnectorType.SideToSide:
                connector = new NStep3Connector(false, 50, 0, true);
                break;

            case ConnectorType.TopToBottom:
                connector = new NStep3Connector(true, 50, 0, true);
                break;

            case ConnectorType.DynamicHV:
                connector = new NRoutableConnector(RoutableConnectorType.DynamicHV);
                break;

            case ConnectorType.DynamicPolyline:
                connector = new NRoutableConnector(RoutableConnectorType.DynamicPolyline);
                break;

            case ConnectorType.DynamicCurve:
                connector = new NRoutableConnector(RoutableConnectorType.DynamicCurve);
                break;

            default:
                Debug.Assert(false, "New graph connector type?");
                break;
            }

            // the connector must be added to the document prior to connecting it
            document.ActiveLayer.AddChild(connector);

            connector.StartPlug.Connect(fromPort);
            connector.EndPlug.Connect(toPort);

            connector.Style.TextStyle        = (connector.ComposeTextStyle().Clone() as NTextStyle);
            connector.Style.TextStyle.Offset = new Nevron.GraphicsCore.NPointL(0, -7);

            connector.Text = text;
            return(connector);
        }
        /// <summary>
        /// Creates a new connector, which connects the specified shapes
        /// </summary>
        /// <param name="fromShape"></param>
        /// <param name="fromPortName"></param>
        /// <param name="toShape"></param>
        /// <param name="toPortName"></param>
        /// <param name="connectorType"></param>
        /// <param name="text"></param>
        /// <returns>new 1D shapes</returns>
        protected NShape CreateConnector(NShape fromShape, string fromPortName, NShape toShape, string toPortName, ConnectorType connectorType, string text)
        {
            // check arguments
            if (fromShape == null)
            {
                throw new ArgumentNullException("fromShape");
            }

            if (toShape == null)
            {
                throw new ArgumentNullException("toShape");
            }

            NPort fromPort = (fromShape.Ports.GetChildByName(fromPortName, 0) as NPort);

            if (fromPort == null)
            {
                throw new ArgumentException("Was not able to find fromPortName in the ports collection of the fromShape", "fromPortName");
            }

            NPort toPort = (toShape.Ports.GetChildByName(toPortName, 0) as NPort);

            if (toPort == null)
            {
                throw new ArgumentException("Was not able to find toPortName in the ports collection of the toShape", "toPortName");
            }

            // create the connector
            NShape connector = null;

            switch (connectorType)
            {
            case ConnectorType.Line:
                connector = new NLineShape();
                break;

            case ConnectorType.Bezier:
                connector = new NBezierCurveShape();
                break;

            case ConnectorType.SingleArrow:
                connector = new NArrowShape(ArrowType.SingleArrow);
                break;

            case ConnectorType.DoubleArrow:
                connector = new NArrowShape(ArrowType.DoubleArrow);
                break;

            case ConnectorType.SideToTopBottom:
                connector = new NStep2Connector(false);
                break;

            case ConnectorType.TopBottomToSide:
                connector = new NStep2Connector(true);
                break;

            case ConnectorType.SideToSide:
                connector = new NStep3Connector(false, 50, 0, true);
                break;

            case ConnectorType.TopToBottom:
                connector = new NStep3Connector(true, 50, 0, true);
                break;

            case ConnectorType.DynamicHV:
                connector = new NRoutableConnector(RoutableConnectorType.DynamicHV);
                break;

            case ConnectorType.DynamicPolyline:
                connector = new NRoutableConnector(RoutableConnectorType.DynamicPolyline);
                break;

            case ConnectorType.DynamicCurve:
                connector = new NRoutableConnector(RoutableConnectorType.DynamicCurve);
                break;

            default:
                Debug.Assert(false, "New graph connector type?");
                break;
            }

            // the connector must be added to the document prior to connecting it
            DrawingView.Document.ActiveLayer.AddChild(connector);

            // change the default label text
            connector.Text = text;

            // connectors by default inherit styles from the connectors stylesheet
            connector.StyleSheetName = NDR.NameConnectorsStyleSheet;

            // connect the connector to the specified ports
            connector.StartPlug.Connect(fromPort);
            connector.EndPlug.Connect(toPort);

            // modify the connector text style
            connector.Style.TextStyle        = (connector.ComposeTextStyle().Clone() as NTextStyle);
            connector.Style.TextStyle.Offset = new NPointL(0, -7);

            return(connector);
        }