示例#1
0
        private static void ConnectNodePair(IActivity fromActivity, IActivity toActivity, Visio.InvisibleApp vapp, Visio.IVDocument stencil, Library.Shapes.Connector connector)
        {
            try
            {

                if (fromActivity.Shape == null || toActivity.Shape == null)
                    return;

                Shape fromShape;
                Shape toShape;

                if (fromActivity.Shape.ContainingPage != toActivity.Shape.ContainingPage)
                {
                    fromShape = fromActivity.Parent.Shape;
                    toShape = toActivity.Parent.Shape;
                } else
                {
                    
                    fromShape = fromActivity.Shape;
                    toShape = toActivity.Shape;
                }

                if (fromShape == null || toShape == null)
                    return;

                var connectorShape = fromShape.ContainingPage.Drop(stencil.Masters[connector.TemplateShapeName], 2.50, 2.50);
                connectorShape.Text = connector.Title;

                if (connector.HasProperty(ConnectorProperties.Negative))
                {
                    connectorShape.CellsSRC[(short) Visio.VisSectionIndices.visSectionObject, (short) Visio.VisRowIndices.visRowLine, (short) Visio.VisCellIndices.visLineColor].FormulaU = "THEMEGUARD(RGB(255,0,0))";
                }
                if (connector.HasProperty(ConnectorProperties.Optimal))
                {
                    connectorShape.CellsSRC[(short) Visio.VisSectionIndices.visSectionObject, (short) Visio.VisRowIndices.visRowLine, (short) Visio.VisCellIndices.visLineColor].FormulaU = "THEMEGUARD(RGB(0,255,0))";
                }

                if (connector.HasProperty(ConnectorProperties.Trigger))
                {
                    var triggerShape = fromShape.ContainingPage.Drop(stencil.Masters["Trigger"], 0, 0);

                    var vCell1 = triggerShape.CellsSRC[7, 0, 0];
                    var vCell2 = connectorShape.CellsSRC[7, 0, 0];

                    vCell1.GlueTo(vCell2);
                }

                // get the cell from the source side of the connector
                var beginXCell = connectorShape.CellsSRC[(short) Visio.VisSectionIndices.visSectionObject, (short) Visio.VisRowIndices.visRowXForm1D, (short) Visio.VisCellIndices.vis1DBeginX];

                // glue the source side of the connector to the first shape
                beginXCell.GlueTo(fromShape.CellsSRC[(short) Visio.VisSectionIndices.visSectionObject, (short) Visio.VisRowIndices.visRowXFormOut, (short) Visio.VisCellIndices.visXFormPinX]);
                
                // get the cell from the destination side of the connector
                var endXCell = connectorShape.CellsSRC[(short) Visio.VisSectionIndices.visSectionObject, (short) Visio.VisRowIndices.visRowXForm1D, (short) Visio.VisCellIndices.vis1DEndX];

                // glue the destination side of the connector to the second shape
                endXCell.GlueTo(toShape.CellsSRC[(short) Visio.VisSectionIndices.visSectionObject, (short) Visio.VisRowIndices.visRowXFormOut, (short) Visio.VisCellIndices.visXFormPinX]);

                var arrowCell = connectorShape.CellsSRC[(short) Visio.VisSectionIndices.visSectionObject, (short) Visio.VisRowIndices.visRowLine, (short) Visio.VisCellIndices.visLineEndArrow];
                arrowCell.FormulaU = "5";
            
            } catch (Exception ex)
            {
                throw new ArgumentException("Unable to draw Connector: " + ex.Message);
            }
        }