/// <summary>
        /// Draw a directional, dynamic connector between two entities, representing an entity relationship.
        /// </summary>
        /// <param name="shapeFrom">Shape initiating the relationship</param>
        /// <param name="shapeTo">Shape referenced by the relationship</param>
        /// <param name="isManyToMany">Whether or not it is a many-to-many entity relationship</param>
        /// <param name="SchemaName">The relationship Shcema Name</param>
        private void DrawDirectionalDynamicConnector(VisioApi.Shape shapeFrom, VisioApi.Shape shapeTo, bool isManyToMany, string SchemaName)
        {
            // Add a dynamic connector to the page.
            VisioApi.Shape connectorShape = shapeFrom.ContainingPage.Drop(_application.ConnectorToolDataObject, 0.0, 0.0);

            if (dbp.showRelationshipsNames)
            {
                connectorShape.Text = SchemaName;
            }

            // Set the connector properties, using different arrows, colors, and patterns for many-to-many relationships.
            connectorShape.get_CellsSRC(VISIO_SECTION_OJBECT_INDEX, (short)VisioApi.VisRowIndices.visRowFill, (short)VisioApi.VisCellIndices.visFillShdwPattern).ResultIU = SHDW_PATTERN;
            connectorShape.get_CellsSRC(VISIO_SECTION_OJBECT_INDEX, (short)VisioApi.VisRowIndices.visRowLine, (short)VisioApi.VisCellIndices.visLineBeginArrow).ResultIU  = isManyToMany ? BEGIN_ARROW_MANY : BEGIN_ARROW;
            connectorShape.get_CellsSRC(VISIO_SECTION_OJBECT_INDEX, (short)VisioApi.VisRowIndices.visRowLine, (short)VisioApi.VisCellIndices.visLineEndArrow).ResultIU    = END_ARROW;
            connectorShape.get_CellsSRC(VISIO_SECTION_OJBECT_INDEX, (short)VisioApi.VisRowIndices.visRowLine, (short)VisioApi.VisCellIndices.visLineColor).ResultIU       = isManyToMany ? LINE_COLOR_MANY : LINE_COLOR;
            connectorShape.get_CellsSRC(VISIO_SECTION_OJBECT_INDEX, (short)VisioApi.VisRowIndices.visRowLine, (short)VisioApi.VisCellIndices.visLinePattern).ResultIU     = isManyToMany ? LINE_PATTERN : LINE_PATTERN;
            connectorShape.get_CellsSRC(VISIO_SECTION_OJBECT_INDEX, (short)VisioApi.VisRowIndices.visRowFill, (short)VisioApi.VisCellIndices.visLineRounding).ResultIU    = ROUNDING;

            // Connect the starting point.
            VisioApi.Cell cellBeginX = connectorShape.get_CellsSRC(VISIO_SECTION_OJBECT_INDEX, (short)VisioApi.VisRowIndices.visRowXForm1D, (short)VisioApi.VisCellIndices.vis1DBeginX);
            cellBeginX.GlueTo(shapeFrom.get_CellsSRC(VISIO_SECTION_OJBECT_INDEX, (short)VisioApi.VisRowIndices.visRowXFormOut, (short)VisioApi.VisCellIndices.visXFormPinX));

            // Connect the ending point.
            VisioApi.Cell cellEndX = connectorShape.get_CellsSRC(VISIO_SECTION_OJBECT_INDEX, (short)VisioApi.VisRowIndices.visRowXForm1D, (short)VisioApi.VisCellIndices.vis1DEndX);
            cellEndX.GlueTo(shapeTo.get_CellsSRC(VISIO_SECTION_OJBECT_INDEX, (short)VisioApi.VisRowIndices.visRowXFormOut, (short)VisioApi.VisCellIndices.visXFormPinX));
        }
Esempio n. 2
0
        /// <summary>
        /// Метод инвертирования ребра
        /// </summary>
        /// <param name="window"></param>
        public void Invert(Visio.Window window)
        {
            if (window != null)
            {
                // Для всех выделенных фигур
                foreach (Visio.Shape shape in window.Selection)
                {
                    // Проверяем, что это ребро
                    if (edges.ContainsValue(shape))
                    {
                        foreach (var edge in edges)
                        {
                            if (edge.Value == shape)
                            {
                                // Инвертируем ребро
                                Visio.Cell beginXCell = shape.get_CellsSRC((short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXForm1D, (short)Visio.VisCellIndices.vis1DBeginX);
                                beginXCell.GlueTo(vertices[edge.Key.Destination].get_CellsSRC((short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXFormOut, (short)Visio.VisCellIndices.visXFormPinX));
                                Visio.Cell endXCell = shape.get_CellsSRC((short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXForm1D, (short)Visio.VisCellIndices.vis1DEndX);
                                endXCell.GlueTo(vertices[edge.Key.Source].get_CellsSRC((short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXFormOut, (short)Visio.VisCellIndices.visXFormPinX));

                                // Заменяем старое ребро новым инвертированным
                                DotEdge <string> invertedEdge = new DotEdge <string>(edge.Key.Destination, edge.Key.Source, edge.Key.Attributes);
                                break;
                            }
                        }
                    }
                    else
                    {
                        throw new ArgumentException("Допустимо только инвертирование ребер!");
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// This function connects two shapes using the provided connector.
        /// </summary>
        /// <param name="shape1">This is the "Parent" shape.</param>
        /// <param name="shape2">This is the "Child" shape.</param>
        /// <param name="connector">This is the connector shape.</param>
        private static void ConnectShapes(Visio.Shape shape1, Visio.Shape shape2, Visio.Shape connector)
        {
            // get the cell from the source side of the connector
            Visio.Cell beginXCell = connector.get_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(shape1.get_CellsSRC(
                                  (short)Visio.VisSectionIndices.visSectionObject,
                                  (short)Visio.VisRowIndices.visRowXFormOut,
                                  (short)Visio.VisCellIndices.visXFormPinX));

            // get the cell from the destination side of the connector
            Visio.Cell endXCell = connector.get_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(shape2.get_CellsSRC(
                                (short)Visio.VisSectionIndices.visSectionObject,
                                (short)Visio.VisRowIndices.visRowXFormOut,
                                (short)Visio.VisCellIndices.visXFormPinX));
        }
Esempio n. 4
0
        //Старая версия
        //public void ConnectShapes(object shape1, object shape2, Visio.Shape connector)
        //{
        //    if (shape1 == null)
        //    {
        //        return;
        //    }
        //    Visio.Cell beginXCell = connector.get_CellsSRC((short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXForm1D, (short)Visio.VisCellIndices.vis1DBeginX);
        //    beginXCell.GlueTo(((Visio.Shape)shape1).get_CellsSRC((short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXFormOut, (short)Visio.VisCellIndices.visXFormPinX));
        //    if (shape2 != null)
        //    {
        //        Visio.Cell endXCell = connector.get_CellsSRC((short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXForm1D, (short)Visio.VisCellIndices.vis1DEndX);
        //        endXCell.GlueTo(((Visio.Shape)shape2).get_CellsSRC((short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXFormOut, (short)Visio.VisCellIndices.visXFormPinX));
        //    }
        //}
        public void ConnectShapes(object shape1, object shape2, Visio.Shape connector)
        {
            if (shape1 == null)
            {
                return;
            }

            Visio.Cell beginXCell = connector.get_CellsSRC(1, 4, 0);
            beginXCell.GlueTo(((Visio.Shape)shape1).get_CellsSRC(1, 1, 0));

            if (shape2 != null)
            {
                Visio.Cell endXCell = connector.get_CellsSRC(1, 4, 2);
                endXCell.GlueTo(((Visio.Shape)shape2).get_CellsSRC(1, 1, 0));
            }
        }
Esempio n. 5
0
        private void ConnectShapes(Visio.Shape shape, int connectPoint, Visio.Shape connector, int direction)
        {
            // get the cell from the source side of the connector
            Visio.Cell beginXCell = connector.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionObject,
                (short)Visio.VisRowIndices.visRowXForm1D,
                (short)Visio.VisCellIndices.vis1DBeginX);
            // glue the source side of the connector to the first shape

            //shape1.AutoConnect(shape2, Visio.VisAutoConnectDir.visAutoConnectDirRight,connector);

            Visio.Cell fromCell = shape.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionConnectionPts,
                (short)connectPoint, 0);

            //beginXCell.GlueTo(fromCell);
            //shape1.get_Cells("FillForegnd").Formula = "3";


            //get the cell from the destination side of the connector
            Visio.Cell endXCell = connector.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionObject,
                (short)Visio.VisRowIndices.visRowXForm1D,
                (short)Visio.VisCellIndices.vis1DEndX);

            //// glue the destination side of the connector to the second shape

            //Visio.Cell toXCell = shape2.get_CellsSRC(
            //(short)Visio.VisSectionIndices.visSectionObject,
            //(short)Visio.VisRowIndices.visRowXFormOut,
            //(short)Visio.VisCellIndices.visXFormPinX);
            //endXCell.GlueTo(toXCell);

            //Visio.Cell arrowCell = connector.get_CellsSRC((short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowLine, (short)Visio.VisCellIndices.visLineEndArrow);
            if (direction == 0)
            {
                //connector.get_Cells("BeginArrow").Formula = "=5";
                connector.get_Cells("EndArrow").Formula = "=5";
                endXCell.GlueTo(fromCell);
            }
            else
            {
                connector.get_Cells("EndArrow").Formula = "=5";
                beginXCell.GlueTo(fromCell);
            }
            //connector.get_Cells("LineColor").Formula = "3";
        }
Esempio n. 6
0
        private void DrawDependencies(Visio.Shape shape)
        {
            string shapeText = shape.Text;
            string shapeName = shape.Master.Name;
            int    start = this.contentDSC.IndexOf(shapeName + " " + shapeText), startBracket = -1;
            int    end = -1, endBracket = -1;
            string shapeProps = "";

            string[] propLines;
            short    customProps = (short)Visio.VisSectionIndices.visSectionProp;

            synchronizationContext.Post(new SendOrPostCallback(o =>
            {
                lblStatus.Text  = "Linking shapes... ";
                lblDetails.Text = shapeText;
            }), null);

            /*while (start >= 0)
             * {*/
            start = start + shapeText.Length;
            end   = contentDSC.IndexOf("\r\n", start);

            /* Get all properties for the shape */
            if (end >= 0)
            {
                startBracket = contentDSC.IndexOf("{", end + 2) + 1;
                endBracket   = contentDSC.IndexOf("}", end + 2);
                shapeProps   = contentDSC.Substring(startBracket, endBracket - startBracket);

                propLines = shapeProps.Split('\n');

                foreach (string prop in propLines)
                {
                    // Nik20161101 - This shape depends on another. Add a dynamic connector and link the two together;
                    if (prop.Split('=')[0].Trim().ToLower() == "dependson")
                    {
                        string[] dependsOn = prop.Split('=')[1].Trim().Replace("\"", "").Split(';');
                        if (dependsOn.Length == 1 && dependsOn[0].Contains(","))
                        {
                            dependsOn = dependsOn[0].Split(',');
                            for (int i = 0; i < dependsOn.Length; i++)
                            {
                                dependsOn[i] = dependsOn[i].Replace("@(", "").Replace("'", "").Replace(")", "");
                            }
                        }
                        Visio.Document basicStencil = _addin.Application.Documents.OpenEx("Basic Flowchart Shapes (US units).vss", (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDocked);
                        Visio.Master   connector    = basicStencil.Masters.get_ItemU("Dynamic Connector");
                        foreach (string dependency in dependsOn)
                        {
                            if (!string.IsNullOrEmpty(dependency))
                            {
                                Visio.Shape connectorShape = _addin.Application.ActivePage.Drop(connector, 0.0, 0.0);

                                // Connect the begin point. 
                                Visio.Cell endXCell = connectorShape.get_CellsSRC((short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXForm1D, (short)Visio.VisCellIndices.vis1DEndX);
                                endXCell.GlueTo(shape.get_CellsSRC((short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXFormOut, (short)Visio.VisCellIndices.visXFormPinX));

                                Visio.Cell beginXCell = connectorShape.get_CellsSRC((short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXForm1D, (short)Visio.VisCellIndices.vis1DBeginX);

                                // Nik20161101 - Get the type of resource the shape depends on.
                                string dependsOnResourceType = "";
                                int    startType             = dependency.IndexOf('[') + 1;
                                int    endType = -1;
                                if (startType >= 1)
                                {
                                    endType = dependency.IndexOf("]");
                                    if (endType > startType)
                                    {
                                        dependsOnResourceType = dependency.Substring(startType, endType - startType);
                                    }
                                }

                                Visio.Document doc = _window.Document;
                                string         masterShapeName = "", curPropName = "", curPropValue = "", curShapeText = "";
                                foreach (Visio.Page page in doc.Pages)
                                {
                                    foreach (Visio.Shape curShape in page.Shapes)
                                    {
                                        curShapeText = curShape.Text.Trim();
                                        for (short i = 0; i < curShape.RowCount[customProps]; i++)
                                        {
                                            masterShapeName = curShape.Master.Name;
                                            curPropName     = curShape.CellsSRC[customProps, i, (short)Visio.VisCellIndices.visCustPropsLabel].Formula.Replace("\"", "").ToLower();
                                            curPropValue    = curShape.CellsSRC[customProps, i, (short)Visio.VisCellIndices.visCustPropsValue].FormulaU.Replace(" ", ""); //TODO - Replace the space trimming logic by something more robust

                                            if (curShape != shape && masterShapeName == dependsOnResourceType &&
                                                ((curPropName == "name" && curPropValue == "\"" + dependency.Split(']')[1] + "\"") ||
                                                 curShapeText == dependency.Split(']')[1].Split(',')[0].Replace("'", "")))
                                            {
                                                beginXCell.GlueTo(curShape.get_CellsSRC((short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXFormOut, (short)Visio.VisCellIndices.visXFormPinX));
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }