Пример #1
0
        /// <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));
        }
Пример #2
0
        private void loadCObjectName()
        {
            // Get number of rows in shape data section of object
            short numRows = ownerShape.get_RowCount(CaseTypes.SHAPE_DATA_SECTION);
            // Initialize an empty string
            string cName = "";

            // Loop created to search through each row of shape data section
            for (short r = 0; r < numRows; ++r)
            {
                // Initialize shape data cell
                Visio.Cell labelCell = ownerShape.get_CellsSRC(CaseTypes.SHAPE_DATA_SECTION,
                                                               r, CaseTypes.DS_LABEL_CELL);
                // Get string from shape data row label
                string labelCellValue = labelCell.get_ResultStr(Visio.VisUnitCodes.visUnitsString);
                // We are only interested in c object name
                if (labelCellValue.StartsWith("c_"))
                {
                    // We are only interested in the object name
                    // Get start index of c object name
                    int startIndex = labelCellValue.IndexOf('_') + 1;
                    // Get end index of c object name
                    int endIndex = labelCellValue.LastIndexOf('_');
                    // Get length of c object name
                    int cNameLen = endIndex - startIndex;
                    // Get c object name
                    cName = labelCellValue.Substring(startIndex, cNameLen);
                }
            }
            // Update c object name in c object editor
            cObjectNameText.Text = cName;
            // Update c object name
            ownerShape.Text = cName;
        }
Пример #3
0
        /// <summary>
        /// Sets the Value Cell of a Shapesheet's Data Section at the given row
        /// name to the specified value. Also sets the Label Cell to given rowName.
        /// </summary>
        /// <param name="Shape">Shape to change.</param>
        /// <param name="rowIndex">Name of row within the Data Section.</param>
        /// <param name="value">Value to change the Value Cell to.</param>
        public static void setDataSectionValueCell(Visio.Shape Shape, string rowName, string value)
        {
            // Row Names can only contain a-z, A-Z, 0-9, or _
            rowName = spaceToUnderscore(rowName);

            // Name of the Value Cell in the Shapesheet
            string cellName = "Prop." + rowName + ".Value";

            short rowIndex;
            // Return value of == 0 means cell (and thus, the row) doesn't exist.
            short cellExists = Shape.get_CellExists(cellName, 0);

            if (cellExists == 0)
            {
                rowIndex = Shape.AddNamedRow(CaseTypes.SHAPE_DATA_SECTION, rowName,
                                             (short)Visio.VisRowTags.visTagDefault);
            }
            else
            {
                rowIndex = Shape.get_CellsRowIndex(cellName);
            }

            Visio.Cell valueCell = Shape.get_CellsSRC(CaseTypes.SHAPE_DATA_SECTION,
                                                      rowIndex, CaseTypes.DS_VALUE_CELL);

            valueCell.Formula = '"' + value + '"';

            Visio.Cell labelCell = Shape.get_CellsSRC(CaseTypes.SHAPE_DATA_SECTION,
                                                      rowIndex, CaseTypes.DS_LABEL_CELL);

            labelCell.Formula = '"' + rowName + '"';
        }
Пример #4
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("Допустимо только инвертирование ребер!");
                    }
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Connects a fromShape to a toShape using a Dynamic Connector.
        /// </summary>
        /// <param name="page">Page to drop the Shapes in.</param>
        /// <param name="fromShape">The Shape to start the connection at.</param>
        /// <param name="toShape">The Shape to end the connection at.</param>
        /// <param name="fromXPercent">
        /// X coordinate (in percent of the fromShape's width) to Glue</param>
        /// <param name="fromYPercent">
        /// Y coordinate (in percent of the fromShape's height) to Glue.</param>
        /// <param name="toXPercent">
        /// X coordinate (in percent of the toShape's width) to Glue.</param>
        /// <param name="toYPercent">
        /// X coordinate (in percent of the toShape's width) to Glue.</param>
        public static void glueShapesWithDynamicConnector(Visio.Page page, Visio.Shape fromShape, Visio.Shape toShape,
                                                          double fromXPercent, double fromYPercent, double toXPercent, double toYPercent)
        {
            Visio.Documents appDocuments = page.Application.Documents;

            // We only want to get the Dynamic Connector Master from the Stencil,
            // so keep the stencil hidden since user won't need to use it.
            Visio.Document stencil = getStencil(appDocuments, CaseTypes.OOSD_GENERAL_STENCIL,
                                                Visio.VisOpenSaveArgs.visOpenHidden);

            Visio.Master connectorMaster = stencil.Masters[CaseTypes.OOSD_CONNECTOR];
            Visio.Shape  connector       = page.Drop(connectorMaster, 0, 0);

            // The Dynamic Connector has an end point and a begin point, which are
            // the glue points used to connect to shapes. These points are stored
            // in the 1-D Endpoints Shapesheet section.
            Visio.Cell beginCell = connector.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionObject,
                (short)Visio.VisRowIndices.visRowXForm1D,
                (short)Visio.VisCellIndices.vis1DBeginX);
            Visio.Cell endCell = connector.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionObject,
                (short)Visio.VisRowIndices.visRowXForm1D,
                (short)Visio.VisCellIndices.vis1DEndX);

            // Connect the connector end points to the from and to shapes
            beginCell.GlueToPos(fromShape, fromXPercent, fromYPercent);
            endCell.GlueToPos(toShape, toXPercent, toYPercent);
        }
Пример #6
0
        /// <summary>
        /// Returns a list of values in the Label Cell of the Shape Data Section
        /// for all rows with a prefix that match the rowNamePrefix. Results are
        /// stripped of the rowNamePrefix.
        /// </summary>
        /// <param name="shape"></param>
        /// <param name="rowNamePrefix"></param>
        /// <returns></returns>
        public static HashSet <string> getDSLabelCells(Visio.Shape shape, string rowNamePrefix)
        {
            HashSet <string> labelCellsList = new HashSet <string>();

            // All operation rows are stored in the form:
            // op_[operation_name]_[operation_property] in the Label Cell
            short numRows = shape.get_RowCount(CaseTypes.SHAPE_DATA_SECTION);

            for (short r = 0; r < numRows; ++r)
            {
                Visio.Cell labelCell = shape.get_CellsSRC(CaseTypes.SHAPE_DATA_SECTION,
                                                          r, CaseTypes.DS_LABEL_CELL);

                string labelCellValue = labelCell.get_ResultStr(Visio.VisUnitCodes.visUnitsString);

                // we are only interested in rows with prefix
                if (labelCellValue.StartsWith(rowNamePrefix))
                {
                    // we are only interested in the Label Cell value without
                    // prefix and any postfix
                    int    startIndex = labelCellValue.IndexOf('_') + 1;
                    int    endIndex   = labelCellValue.LastIndexOf('_');
                    int    opNameLen  = endIndex - startIndex;
                    string opName     = labelCellValue.Substring(startIndex, opNameLen);

                    labelCellsList.Add(Utilities.underscoreToSpace(opName));
                }
            }

            return(labelCellsList);
        }
Пример #7
0
 private void SetCellText(Visio.Cell cell, string text)
 {
     if (cell != null)
     {
         cell.FormulaU = text != null ? "\"" + text.Replace("\"", "\"\"") + "\"" : "No Formula";
     }
 }
Пример #8
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));
        }
Пример #9
0
        /// <summary>
        /// Retrieves the value of the Value Cell in a Shape's Data Section.
        /// </summary>
        /// <param name="Shape">Shape to get cell value for.</param>
        /// <param name="rowName">Name of the row to find the Value Cell.</param>
        /// <returns></returns>
        public static string getDataSectionValueCell(Visio.Shape Shape, string rowName)
        {
            string cellName = "Prop." + spaceToUnderscore(rowName) + ".Value";

            Visio.Cell valueCell = Shape.get_Cells(cellName);

            return(valueCell.get_ResultStr(Visio.VisUnitCodes.visUnitsString));
        }
Пример #10
0
        /// <summary>
        /// Returns the Page Width in inches.
        /// </summary>
        /// <param name="page">Page.</param>
        /// <returns>Page width in inches.</returns>
        public static double getPageWidth(Visio.Page page)
        {
            Visio.Cell cell = page.PageSheet.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionObject,
                (short)Visio.VisRowIndices.visRowPage,
                (short)Visio.VisCellIndices.visPageWidth);

            return(cell.get_Result(Visio.VisUnitCodes.visInches));
        }
Пример #11
0
        void vApp_CellChanged(Visio.Cell Cell)
        {
            if (vApp.ActivePage.Layers.Count != LAYERS_LAST_KNOWN_COUNT)
            {
//                System.Diagnostics.Debug.WriteLine("Previous {0} : Current {1}", LAYERS_LAST_KNOWN_COUNT, vApp.ActivePage.Layers.Count);
                LAYERS_LAST_KNOWN_COUNT = vApp.ActivePage.Layers.Count;
                vApp_WindowTurnedToPage(vApp.ActiveWindow);
            }
        }
Пример #12
0
 public string GetValueProperty(Visio.Shape shape, string propertyName)
 {
     Visio.Cell cell = shape.Cells[propertyName];
     try
     {
         return(cell.Formula);
     }
     catch
     {
         return(null);
     }
 }
Пример #13
0
 public Visio.Cell GetCell(Visio.Shape shape, string propertyName)
 {
     try
     {
         Visio.Cell cell = shape.Cells[propertyName];
         return(cell);
     }
     catch
     {
         return(null);
     }
 }
Пример #14
0
 public bool SetValueProperty(Visio.Shape shape, string propertyName, string propertyValue)
 {
     try
     {
         Visio.Cell cell = shape.Cells[propertyName];
         cell.Formula = propertyValue;
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Пример #15
0
 public static bool SetIntCellVal(Visio.Cell visCell, int iValue)
 {
     try
     {
         visCell.set_ResultFromIntForce((int)Visio.VisUnitCodes.visNumber, iValue);
     }
     catch (System.Exception except)
     {
         string strMessage = except.Message;
         return(false);
     }
     return(true);
 }
        private void loadObject()
        {
            HashSet <string> operationSet = new HashSet <string>();
            short            numRows      = ownerShape.get_RowCount(CaseTypes.SHAPE_DATA_SECTION);

            for (short r = 0; r < numRows; ++r)
            {
                Visio.Cell labelCell = ownerShape.get_CellsSRC(CaseTypes.SHAPE_DATA_SECTION,
                                                               r, CaseTypes.DS_LABEL_CELL);

                string labelCellValue = labelCell.get_ResultStr(Visio.VisUnitCodes.visUnitsString);

                if (labelCellValue.StartsWith("adt_"))
                {
                    int    startIndex = labelCellValue.IndexOf('_') + 1;
                    int    endIndex   = labelCellValue.LastIndexOf('_');
                    int    opNameLen  = endIndex - startIndex;
                    string adtObjName = labelCellValue.Substring(startIndex, opNameLen);
                    adtObjectNameTextBox.Text = adtObjName;
                }
                if (labelCellValue.EndsWith("name"))
                {
                    int       startIndex = labelCellValue.IndexOf('_') + 1;
                    int       endIndex   = labelCellValue.LastIndexOf('_');
                    int       opNameLen  = endIndex - startIndex;
                    string    opName     = labelCellValue.Substring(startIndex, opNameLen);
                    Operation opObj      = new Operation();
                    string    rowName    = "op_" + opName + "_";
                    opObj.name    = Utilities.getDataSectionValueCell(ownerShape, rowName + "name");
                    opObj.domain  = Utilities.getDataSectionValueCell(ownerShape, rowName + "domain");
                    opObj.range   = Utilities.getDataSectionValueCell(ownerShape, rowName + "range");
                    opObj.purpose = Utilities.getDataSectionValueCell(ownerShape, rowName + "purpose");
                    opObj.effects = Utilities.getDataSectionValueCell(ownerShape, rowName + "effects");
                    if (Utilities.getDataSectionValueCell(ownerShape, rowName + "exceptions_list").Any())
                    {
                        opObj.exceptions = Utilities.getDataSectionValueCell(ownerShape, rowName + "exceptions_list").Split(',').Select(a => a.Trim()).ToList();
                    }
                    this.operationList.Add(opObj);
                    operationListBox.Items.Add(opObj.name);
                }
                if (labelCellValue.StartsWith("axiom"))
                {
                    string rowName = "axiom_list";
                    axiomList = Utilities.getDataSectionValueCell(ownerShape, rowName).Split(',').Select(a => a.Trim()).ToList();
                    axiomListBox.DataSource = axiomList;
                }
            }
            //operationListBox.Items.AddRange(operationSet.ToArray());
        }
Пример #17
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));
            }
        }
Пример #18
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";
        }
Пример #19
0
        private static void connectionNames(Visio.Shape shape)
        {
            List <string> listOfNames = new List <string>();
            short         iRow        = (short)Visio.VisRowIndices.visRowConnectionPts;

            while (shape.get_RowExists((short)Visio.VisSectionIndices.visSectionConnectionPts, iRow, (short)0) != 0)
            {
                // Get a cell from the connection point row.
                Visio.Cell cell = shape.get_CellsSRC((short)Visio.VisSectionIndices.visSectionConnectionPts, iRow, (short)Visio.VisCellIndices.visCnnctX);

                // Ask the cell what row it is in.
                listOfNames.Add(cell.RowName);

                // Next row.
                ++iRow;
            }
            return;
        }
Пример #20
0
        public static bool GetStringCellFormula(Visio.Cell visCell, out string strChaine)
        {
            strChaine = visCell.FormulaU;
            if (strChaine != String.Empty)
            {
                int longueur;

                if ((longueur = strChaine.Length) >= 2)
                {
                    strChaine = strChaine.Substring(1, longueur - 2);
                }
                else
                {
                    strChaine = String.Empty;
                }
            }
            return(true);
        }
Пример #21
0
        /// <summary>
        /// Delete all rows in the Data Section that starts with the given row name.
        /// </summary>
        /// <param name="Shape">
        /// The Shape to delete the row(s) from.
        /// </param>
        /// <param name="rowName">The name of the row to delete.</param>
        public static void deleteDataSectionRow(Visio.Shape Shape, string rowName)
        {
            short numRows = Shape.get_RowCount(CaseTypes.SHAPE_DATA_SECTION);

            rowName = Utilities.spaceToUnderscore(rowName);

            // Iterate through the list of Data Section rows in reverse (since upon
            // deletion of a row, all row indexes after the deleted row gets shifted
            // up by 1) to safely delete any row that starts with the given rowName.
            short startIndex = --numRows;

            for (short r = startIndex; r >= 0; --r)
            {
                Visio.Cell labelCell = Shape.get_CellsSRC(CaseTypes.SHAPE_DATA_SECTION, r, CaseTypes.DS_LABEL_CELL);

                string labelValue = labelCell.get_ResultStr(Visio.VisUnitCodes.visUnitsString);
                if (labelValue.StartsWith(rowName))
                {
                    Shape.DeleteRow(CaseTypes.SHAPE_DATA_SECTION, r);
                }
            }
        }
Пример #22
0
        private void loadAttributeNameList()
        {
            // Initialize empty HashSet
            HashSet <string> attributeSet = new HashSet <string>();
            // All attribute rows are stored in the form:
            // at_[attribute_name]_[attribute_property] in the Label Cell
            // Get number of rows in c object shape data section
            short numRows = ownerShape.get_RowCount(CaseTypes.SHAPE_DATA_SECTION);

            // Loop through each row of shape data section
            for (short r = 0; r < numRows; ++r)
            {
                // Initialize shape data label cell
                Visio.Cell labelCell = ownerShape.get_CellsSRC(CaseTypes.SHAPE_DATA_SECTION,
                                                               r, CaseTypes.DS_LABEL_CELL);
                // Get shape data label cell value
                string labelCellValue = labelCell.get_ResultStr(Visio.VisUnitCodes.visUnitsString);
                // Ee are only interested in attribute-related rows
                if (labelCellValue.StartsWith("at_"))
                {
                    // We are only interested in the attribute name
                    // Get start index of attribute name
                    int startIndex = labelCellValue.IndexOf('_') + 1;
                    // Get end index of attribute name
                    int endIndex = labelCellValue.LastIndexOf('_');
                    // Get length of attribute name
                    int atNameLen = endIndex - startIndex;
                    // Get attribute name
                    string atName = labelCellValue.Substring(startIndex, atNameLen);
                    // And add it to HashSet
                    attributeSet.Add(Utilities.underscoreToSpace(atName));
                }
            }
            // Add attribute names to attribute list box of c object editor
            attributeListBox.Items.AddRange(attributeSet.ToArray());
        }
Пример #23
0
 public static bool GetIntCellVal(Visio.Cell visCell, int visUnits, out int iValue)
 {
     iValue = visCell.get_ResultInt(visUnits, 1);
     return(true);
 }
Пример #24
0
 public static bool SetStringCellVal(Visio.Cell visCell, string strChaine)
 {
     visCell.FormulaForceU = AddQuotes(StripQuotes(strChaine));
     return(true);
 }
Пример #25
0
 public static bool GetFormulaUCell(Visio.Cell visCell, out string strFormula)
 {
     strFormula = visCell.FormulaU;
     return(true);
 }
Пример #26
0
 private string GetCellText(Visio.Cell cell)
 {
     return(string.IsNullOrEmpty(cell.FormulaU)
         ? string.Empty
         : cell.ResultStrU[(short)Visio.VisUnitCodes.visUnitsString]);
 }
Пример #27
0
        public static void RenderVisioDiagram(RegEx regex)
        {
            // Start Visio
            Visio.Application app = new Visio.Application();

            // Create a new document.
            Visio.Document doc = app.Documents.Add(string.Empty);

            // The new document will have one page,
            // get the a reference to it.
            Visio.Page page1 = doc.Pages[1];

            // Name the page. This is want is shown in the page tabs.
            page1.Name = "Diagram";

            DirectedGraphLayout d = new DirectedGraphLayout();

            string basic_stencil = "basic_u.vss";

            Shape[] shapes = new Shape[regex.States.Count];

            for (int i = 0, len = regex.States.Count; i < len; i++)
            {
                string stateInfo = $"State {i}";

                if (i == regex.StartingState)
                {
                    stateInfo += Environment.NewLine + "[START]";
                }

                if (regex.States[i].Ending)
                {
                    stateInfo += Environment.NewLine + "[END]";
                }

                shapes[i] = d.AddShape(
                    $"s{i}",
                    stateInfo,
                    basic_stencil,
                    "Rectangle"
                    );
            }

            for (int i = 0, len = regex.Edges.Count; i < len; i++)
            {
                Edge edge = regex.Edges[i];

                const ConnectorType type       = ConnectorType.RightAngle;
                const int           beginArrow = 20;
                const int           endArrow   = 5;

                if (string.IsNullOrEmpty(edge.Value))
                {
                    d.AddConnection(
                        $"e{i}",
                        shapes[edge.Origin],
                        shapes[edge.Destination],
                        string.Empty,
                        type,
                        beginArrow,
                        endArrow,
                        string.Empty
                        );
                }
                else
                {
                    string edgeValue = $"\"{edge.Value}\"" + Environment.NewLine + $"[{string.Join(",", edge.CaptureGroups)}]";

                    Shape edgeShape = d.AddShape($"e{i}", edgeValue, basic_stencil, "Diamond");
                    edgeShape.Size = new Size(2.5, 1.75);

                    d.AddConnection($"e{i}_1", shapes[edge.Origin], edgeShape, string.Empty, type, beginArrow, endArrow, string.Empty);
                    d.AddConnection($"e{i}_2", edgeShape, shapes[edge.Destination], string.Empty, type, beginArrow, endArrow, string.Empty);
                }

                //d.AddConnection(
                //    $"e{i}",
                //    shapes[edge.Origin],
                //    shapes[edge.Destination],
                //    edgeValue,
                //    ConnectorType.RightAngle
                //);
            }

            MsaglLayoutOptions options = new MsaglLayoutOptions();

            d.Render(page1, options);

            foreach (Visio.Shape shape in page1.Shapes)
            {
                Visio.Cell cell = shape.CellsU["Char.Size"];
                cell.FormulaU = "20 pt";
            }
        }
Пример #28
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;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #29
0
 public static bool GetDoubleCellVal(Visio.Cell visCell, int visUnits, out double dblValue)
 {
     dblValue = visCell.get_Result(visUnits);
     return(true);
 }