コード例 #1
0
        /// <summary>
        /// Draw Rectangle with 2 connections points.
        /// </summary>
        public static Shape DrawRectangle(Page page, double x1, double y1, double x2, double y2)
        {
            Shape rect = page.DrawRectangle(x1, y1, x2, y2);

            // add connection point1
            short rowIndex1 = rect.AddRow(
                (short)Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionConnectionPts,
                (short)Microsoft.Office.Interop.Visio.VisRowIndices.visRowLast,
                (short)Microsoft.Office.Interop.Visio.VisRowTags.visTagCnnctPt);

            Row row1 = rect.Section[(short)Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionConnectionPts][rowIndex1];

            row1.CellU[(short)Microsoft.Office.Interop.Visio.VisCellIndices.visCnnctX].FormulaU    = "Width*0";
            row1.CellU[(short)Microsoft.Office.Interop.Visio.VisCellIndices.visCnnctY].FormulaU    = "Height*0.5";
            row1.CellU[(short)Microsoft.Office.Interop.Visio.VisCellIndices.visCnnctDirX].FormulaU = "1";
            row1.CellU[(short)Microsoft.Office.Interop.Visio.VisCellIndices.visCnnctDirY].FormulaU = "0";
            row1.CellU[(short)Microsoft.Office.Interop.Visio.VisCellIndices.visCnnctType].FormulaU =
                ((short)Microsoft.Office.Interop.Visio.tagVisCellVals.visCnnctTypeInward).ToString(CultureInfo.InvariantCulture);

            // add connection point2
            short rowIndex2 = rect.AddRow(
                (short)Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionConnectionPts,
                (short)Microsoft.Office.Interop.Visio.VisRowIndices.visRowLast,
                (short)Microsoft.Office.Interop.Visio.VisRowTags.visTagCnnctPt);

            Row row2 = rect.Section[(short)Microsoft.Office.Interop.Visio.VisSectionIndices.visSectionConnectionPts][rowIndex2];

            row2.CellU[(short)Microsoft.Office.Interop.Visio.VisCellIndices.visCnnctX].FormulaU    = "Width*1";
            row2.CellU[(short)Microsoft.Office.Interop.Visio.VisCellIndices.visCnnctY].FormulaU    = "Height*0.5";
            row2.CellU[(short)Microsoft.Office.Interop.Visio.VisCellIndices.visCnnctDirX].FormulaU = "-1";
            row2.CellU[(short)Microsoft.Office.Interop.Visio.VisCellIndices.visCnnctDirY].FormulaU = "0";
            row2.CellU[(short)Microsoft.Office.Interop.Visio.VisCellIndices.visCnnctType].FormulaU =
                ((short)Microsoft.Office.Interop.Visio.tagVisCellVals.visCnnctTypeInward).ToString(CultureInfo.InvariantCulture);

            return(rect);
        }
コード例 #2
0
        /// <summary>This method adds a right mouse action to a shape. The 
        /// right mouse action is added to the Actions section of the given
        /// shape.</summary>
        /// <param name="targetShape">Shape to add the action item to.</param>
        /// <param name="menuCaption">Caption for the newly created menu item.
        /// </param>
        /// <param name="menuAction">Action to be taken when the menu item is
        /// selected. This is a formula in universal syntax.</param>
        /// <param name="menuEnabled">Initial enabled state of the menu item.
        /// </param>
        /// <param name="menuChecked">Initial checked state of the menu item.
        /// </param>
        /// <param name="beginGroup">display a divider bar above the command 
        /// in the menu.</param>
        /// <param name="addToBottom">display the command at the bottom of the
        ///  menu.</param>
        private static void AddRightMouseAction(Shape targetShape, string menuCaption, string menuAction,
            bool menuEnabled, bool menuChecked, bool beginGroup, bool addToBottom)
        {
            const string DividerBarPrefix = "_";
            const string AddToBottomPrefix = "%";
            const string AcceleratorPrefix = "&";

            if (menuCaption == null || targetShape == null)
                return;

            short actionRow;
            short actionRows;
            string taggedMenuCaption;
            string rowCaption;
            string cleanMenuCaption;
            Cell actionCell;

            try {
                // the menuCaption string may need to be modified to include a
                // tag that indicates the menu should be at the bottom, or
                // should be preceeded by a separator line.
                taggedMenuCaption = menuCaption;
                if (taggedMenuCaption == null)
                    throw new ArgumentNullException("Menu caption is null");

                // strip modifier tokens from the caption
                cleanMenuCaption = menuCaption.Replace(AcceleratorPrefix, "");

                // Check if the right menu action item already exists.
                actionRows = targetShape.get_RowCount((short)VisSectionIndices.visSectionAction);

                bool actionExists = false;

                for (actionRow = 0; (actionExists == false) && (actionRow < actionRows); actionRow++) {
                    actionCell = targetShape.get_CellsSRC((short)VisSectionIndices.visSectionAction,
                        (short)(VisRowIndices.visRowAction + actionRow),
                        (short)VisCellIndices.visActionMenu);

                    rowCaption = Common.FormulaStringToString(actionCell.FormulaU);

                    // strip modifier tokens from the caption before compare
                    rowCaption = rowCaption.Replace(DividerBarPrefix, "");
                    rowCaption = rowCaption.Replace(AddToBottomPrefix, "");
                    rowCaption = rowCaption.Replace(AcceleratorPrefix, "");

                    if (rowCaption == cleanMenuCaption)
                        actionExists = true;
                }

                if (actionExists == false) {
                    // prefix underscore (_) to the caption to add a separator
                    // line above it.
                    if (beginGroup == true && taggedMenuCaption != null)
                        taggedMenuCaption = taggedMenuCaption.Insert(0, DividerBarPrefix);

                    // prefix percent (%) to the caption to add it to the
                    // bottom of the menu.
                    if (addToBottom == true)
                        taggedMenuCaption = taggedMenuCaption.Insert(0, AddToBottomPrefix);

                    // Add a new action row to the shape.
                    actionRow = targetShape.AddRow((short)VisSectionIndices.visSectionAction,
                        (short)VisRowIndices.visRowLast,
                        (short)VisRowIndices.visRowAction);

                    // Set the menu caption.
                    actionCell = targetShape.get_CellsSRC((short)VisSectionIndices.visSectionAction,
                        actionRow,
                        (short)VisCellIndices.visActionMenu);
                    actionCell.FormulaU = Common.StringToFormulaForString(taggedMenuCaption);

                    // Set the action for the menu item.
                    actionCell = targetShape.get_CellsSRC((short)VisSectionIndices.visSectionAction,
                        actionRow,
                        (short)VisCellIndices.visActionAction);
                    actionCell.FormulaU = menuAction;

                    // Set the menu item's enabled/disabled state.
                    actionCell = targetShape.get_CellsSRC((short)VisSectionIndices.visSectionAction,
                        actionRow,
                        (short)VisCellIndices.visActionDisabled);
                    actionCell.set_ResultFromInt(VisUnitCodes.visNumber,
                        Convert.ToInt32(!menuEnabled, System.Globalization.CultureInfo.InvariantCulture));

                    // Set the menu item's checked state.
                    actionCell = targetShape.get_CellsSRC(
                        (short)VisSectionIndices.visSectionAction,
                        actionRow,
                        (short)VisCellIndices.visActionChecked);
                    actionCell.set_ResultFromInt(VisUnitCodes.visNumber,
                        Convert.ToInt32(menuChecked, System.Globalization.CultureInfo.InvariantCulture));
                }
            }
            catch (System.Runtime.InteropServices.COMException err) {
                System.Diagnostics.Debug.WriteLine(err.Message);
            }
        }
コード例 #3
0
        private void ShowShapeSettings(Shape shape, int index)
        {
            var isShow = EditorGUILayout.Foldout(index == _selectedShapeIndex, shape.ShapeName);

            if ((index == _selectedShapeIndex) != isShow)
            {
                _selectedShapeIndex = index == _selectedShapeIndex ? -1 : index;
            }

            if (!isShow)
            {
                return;
            }

            shape.ShapeName = EditorGUILayout.TextField("Shape Name", shape.ShapeName);

            shape.ShapeColor = EditorGUILayout.ColorField("Shape Color", shape.ShapeColor);

            for (var i = 0; i < shape.Height; i++)
            {
                EditorGUILayout.BeginHorizontal();
                for (var j = 0; j < shape.Width; j++)
                {
                    var style = _uncheckShapeStyle;
                    if (shape.At(i, j))
                    {
                        style = _checkShapeStyle;
                    }

                    if (GUILayout.Button("", style))
                    {
                        shape.SetAt(i, j, !shape.At(i, j));
                    }
                }

                EditorGUILayout.EndHorizontal();
            }
            Separator();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Add Row"))
            {
                shape.AddRow();
            }
            if (GUILayout.Button("Add Colum"))
            {
                shape.AddColum();
            }
            EditorGUILayout.EndHorizontal();
            Separator();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Optimize Shape"))
            {
                shape.OptimizeShape();
            }
            if (GUILayout.Button("Delete Shape"))
            {
                _serializedObject.Shapes.RemoveAt(_selectedShapeIndex);
                _selectedShapeIndex = -1;
            }
            EditorGUILayout.EndHorizontal();

            Separator();
        }
コード例 #4
0
        /// <summary>This method adds a right mouse action to a shape. The
        /// right mouse action is added to the Actions section of the given
        /// shape.</summary>
        /// <param name="targetShape">Shape to add the action item to.</param>
        /// <param name="menuCaption">Caption for the newly created menu item.
        /// </param>
        /// <param name="menuAction">Action to be taken when the menu item is
        /// selected. This is a formula in universal syntax.</param>
        /// <param name="menuEnabled">Initial enabled state of the menu item.
        /// </param>
        /// <param name="menuChecked">Initial checked state of the menu item.
        /// </param>
        /// <param name="beginGroup">display a divider bar above the command
        /// in the menu.</param>
        /// <param name="addToBottom">display the command at the bottom of the
        ///  menu.</param>
        private static void AddRightMouseAction(Shape targetShape, string menuCaption, string menuAction,
                                                bool menuEnabled, bool menuChecked, bool beginGroup, bool addToBottom)
        {
            const string DividerBarPrefix  = "_";
            const string AddToBottomPrefix = "%";
            const string AcceleratorPrefix = "&";

            if (menuCaption == null || targetShape == null)
            {
                return;
            }

            short  actionRow;
            short  actionRows;
            string taggedMenuCaption;
            string rowCaption;
            string cleanMenuCaption;
            Cell   actionCell;

            try {
                // the menuCaption string may need to be modified to include a
                // tag that indicates the menu should be at the bottom, or
                // should be preceeded by a separator line.
                taggedMenuCaption = menuCaption;
                if (taggedMenuCaption == null)
                {
                    throw new ArgumentNullException("Menu caption is null");
                }

                // strip modifier tokens from the caption
                cleanMenuCaption = menuCaption.Replace(AcceleratorPrefix, "");

                // Check if the right menu action item already exists.
                actionRows = targetShape.get_RowCount((short)VisSectionIndices.visSectionAction);

                bool actionExists = false;

                for (actionRow = 0; (actionExists == false) && (actionRow < actionRows); actionRow++)
                {
                    actionCell = targetShape.get_CellsSRC((short)VisSectionIndices.visSectionAction,
                                                          (short)(VisRowIndices.visRowAction + actionRow),
                                                          (short)VisCellIndices.visActionMenu);

                    rowCaption = Common.FormulaStringToString(actionCell.FormulaU);

                    // strip modifier tokens from the caption before compare
                    rowCaption = rowCaption.Replace(DividerBarPrefix, "");
                    rowCaption = rowCaption.Replace(AddToBottomPrefix, "");
                    rowCaption = rowCaption.Replace(AcceleratorPrefix, "");

                    if (rowCaption == cleanMenuCaption)
                    {
                        actionExists = true;
                    }
                }

                if (actionExists == false)
                {
                    // prefix underscore (_) to the caption to add a separator
                    // line above it.
                    if (beginGroup == true && taggedMenuCaption != null)
                    {
                        taggedMenuCaption = taggedMenuCaption.Insert(0, DividerBarPrefix);
                    }

                    // prefix percent (%) to the caption to add it to the
                    // bottom of the menu.
                    if (addToBottom == true)
                    {
                        taggedMenuCaption = taggedMenuCaption.Insert(0, AddToBottomPrefix);
                    }

                    // Add a new action row to the shape.
                    actionRow = targetShape.AddRow((short)VisSectionIndices.visSectionAction,
                                                   (short)VisRowIndices.visRowLast,
                                                   (short)VisRowIndices.visRowAction);

                    // Set the menu caption.
                    actionCell = targetShape.get_CellsSRC((short)VisSectionIndices.visSectionAction,
                                                          actionRow,
                                                          (short)VisCellIndices.visActionMenu);
                    actionCell.FormulaU = Common.StringToFormulaForString(taggedMenuCaption);

                    // Set the action for the menu item.
                    actionCell = targetShape.get_CellsSRC((short)VisSectionIndices.visSectionAction,
                                                          actionRow,
                                                          (short)VisCellIndices.visActionAction);
                    actionCell.FormulaU = menuAction;

                    // Set the menu item's enabled/disabled state.
                    actionCell = targetShape.get_CellsSRC((short)VisSectionIndices.visSectionAction,
                                                          actionRow,
                                                          (short)VisCellIndices.visActionDisabled);
                    actionCell.set_ResultFromInt(VisUnitCodes.visNumber,
                                                 Convert.ToInt32(!menuEnabled, System.Globalization.CultureInfo.InvariantCulture));

                    // Set the menu item's checked state.
                    actionCell = targetShape.get_CellsSRC(
                        (short)VisSectionIndices.visSectionAction,
                        actionRow,
                        (short)VisCellIndices.visActionChecked);
                    actionCell.set_ResultFromInt(VisUnitCodes.visNumber,
                                                 Convert.ToInt32(menuChecked, System.Globalization.CultureInfo.InvariantCulture));
                }
            }
            catch (System.Runtime.InteropServices.COMException err) {
                System.Diagnostics.Debug.WriteLine(err.Message);
            }
        }