Esempio n. 1
0
        /// <summary>
        /// Converts a State Transition Diagram to a State Transition Table.
        /// </summary>
        /// <param name="selection">Selection of Shape(s) which contains Diagram to convert.</param>
        /// <param name="outputPage">Page to output the Chart.</param>
        public void stateDiagramToTable(Visio.Selection selection, Visio.Page outputPage)
        {
            // Start at any node (that is a State) of the selected shapes to build a State Machine
            // Note: currently can't build a SM starting at the End State node.
            Visio.Shape node = null;
            foreach (Visio.Shape s in selection)
            {
                string masterName = s.Master.Name;
                if (masterName == CaseTypes.STATE_START_MASTER ||
                    masterName == CaseTypes.STATE_MASTER)
                {
                    node = s;
                    break;
                }
            }

            // Builds the State Machine, which lists all the States (& their Transitions)
            List <State> stateMachine = buildStateMachine(node);

            // Creates and output the State Transition Table
            outputStateTransitionTable(stateMachine, outputPage);

            // Switches focus to resulting output
            app.ActiveWindow.Page = outputPage;
        }
Esempio n. 2
0
 public static int[] GetIDs(this IVisio.Selection selection)
 {
     System.Array ids_sa;
     selection.GetIDs(out ids_sa);
     int[] ids = (int[])ids_sa;
     return(ids);
 }
Esempio n. 3
0
        public void ArrangeGraph(Visio.Selection selection)
        {
            //Sets various organisation elements)
            // set 'PlaceStyle'

            /*Visio Layout Code
             * 1. Flowchart = 1
             * 2. Hierarchy = 17
             * 3. CompactTree = 7
             * 4. Circular = 6
             * 5. Radial = 3
             * */


            var placeStyleCell = VisApp.ActivePage.PageSheet.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionObject,
                (short)Visio.VisRowIndices.visRowPageLayout,
                (short)Visio.VisCellIndices.visPLOPlaceStyle).ResultIU = flowCode; //Flow layout code goes here

            // set 'RouteStyle'
            var routeStyleCell = VisApp.ActivePage.PageSheet.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionObject,
                (short)Visio.VisRowIndices.visRowPageLayout,
                (short)Visio.VisCellIndices.visPLORouteStyle).ResultIU = 5;
            // set 'PageShapeSplit'
            var pageShapeSplitCell = VisApp.ActivePage.PageSheet.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionObject,
                (short)Visio.VisRowIndices.visRowPageLayout,
                (short)Visio.VisCellIndices.visPLOSplit).ResultIU = 1;

            if (selection.Count != 0)
            {
                selection.Layout();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// For each Shape in Selection, apply Commands
        /// </summary>
        /// <param name="shapesElement"></param>
        private void ProcessCommand_Shapes(IEnumerable <XElement> shapesElement)
        {
            VisioHlp.DisplayInWatchWindow(string.Format("{0}()",
                                                        System.Reflection.MethodInfo.GetCurrentMethod().Name));

            Visio.Application app = Globals.ThisAddIn.Application;

            Visio.Selection selection = app.ActiveWindow.Selection;

            foreach (XElement element in shapesElement)
            {
                VisioHlp.DisplayInWatchWindow(element.ToString());
                VisioHlp.DisplayInWatchWindow(element.Name.LocalName);

                switch (element.Name.LocalName)
                {
                case "Shape":
                    foreach (Visio.Shape shape in selection)
                    {
                        ProcessCommand_Shape(shape, element);
                    }

                    break;

                default:
                    VisioHlp.DisplayInWatchWindow(string.Format("Element >{0}< not supported", element.Name.LocalName));
                    break;
                }
            }
        }
Esempio n. 5
0
        public override void OnLoadCurrentSettingsExecute()
        {
            Log.EVENT_HANDLER("Enter", Common.LOG_CATEGORY);

            Visio.Application app = Globals.ThisAddIn.Application;

            switch (_shapeType)
            {
            case ShapeType.Document:
                GetInfoFromShape(((Visio.Document)app.ActiveDocument).DocumentSheet);
                break;

            case ShapeType.Page:
                GetInfoFromShape(((Visio.Page)app.ActivePage).PageSheet);
                break;

            case ShapeType.Shape:
                Visio.Selection selection = app.ActiveWindow.Selection;

                foreach (Visio.Shape shape in selection)
                {
                    GetInfoFromShape(shape);
                }
                break;

            default:
                MessageBox.Show($"Unexpected _shapeType({_shapeType.GetType()}");
                break;
            }

            Log.EVENT_HANDLER("Exit", Common.LOG_CATEGORY);
        }
Esempio n. 6
0
        public static Geometry.Rectangle GetBoundingBox(this IVisio.Selection selection, IVisio.VisBoundingBoxArgs args)
        {
            double bbx0, bby0, bbx1, bby1;

            selection.BoundingBox((short)args, out bbx0, out bby0, out bbx1, out bby1);
            var r = new Geometry.Rectangle(bbx0, bby0, bbx1, bby1);

            return(r);
        }
Esempio n. 7
0
        public static IEnumerable <IVisio.Shape> ToEnumerable(this IVisio.Selection selection)
        {
            short count16 = selection.Count16;

            for (short i = 0; i < count16; i++)
            {
                yield return(selection[i + 1]);
            }
        }
Esempio n. 8
0
        public static void ExportSelectionToXAML(IVisio.Selection sel, string filename, System.Action <string> verboselog)
        {
            // Save temp SVG
            string svg_filename = System.IO.Path.GetTempFileName() + "_temp.svg";

            sel.Export(svg_filename);

            // Load temp SVG
            var    load_svg_timer    = new System.Diagnostics.Stopwatch();
            string input_svg_content = System.IO.File.ReadAllText(svg_filename);

            load_svg_timer.Stop();
            verboselog(string.Format("Finished SVG Loading ({0} seconds)", load_svg_timer.Elapsed.TotalSeconds));

            // Delete temp SVG
            if (System.IO.File.Exists(svg_filename))
            {
                System.IO.File.Delete(svg_filename);
            }
            else
            {
                string msg = string.Format("Temporary SVG file could not be found: \"{0}\"", svg_filename);
                throw new VisioAutomation.Scripting.VisioOperationException(msg);
            }

            verboselog("Creating XHTML with embedded SVG");

            if (System.IO.File.Exists(filename))
            {
                verboselog(string.Format("Deleting \"{0}\"", filename));
                System.IO.File.Delete(filename);
            }

            verboselog("Converting to XAML ...");
            var convert_timer = new System.Diagnostics.Stopwatch();

            string xaml;

            try
            {
                xaml = XamlTuneConverter.Svg2Xaml.ConvertFromSVG(input_svg_content);
            }
            catch (System.Exception e)
            {
                string msg = string.Format("Failed to convert to XAML \"{0}\"", e.Message + e.StackTrace);
                verboselog(msg);
                return;
            }
            convert_timer.Stop();

            verboselog("Writing XAML File");
            System.IO.File.WriteAllText(filename, xaml);
            verboselog("Finished writing XAML File");

            verboselog(string.Format("Finished XAML export ({0} seconds)", convert_timer.Elapsed.TotalSeconds));
        }
Esempio n. 9
0
        public virtual Boolean OnLoadCurrentSettingsCanExecute()
        {
            Visio.Application app = Globals.ThisAddIn.Application;

            Visio.Selection selection = app.ActiveWindow.Selection;

            //var containingMaster = selection.ContainingMaster;
            //var containingMasterID = selection.ContainingMasterID;
            //var containingPage = selection.ContainingPage;
            //var containingPageID = selection.ContainingPageID;
            //var containingShape = selection.ContainingShape;
            //var primaryItem = selection.PrimaryItem;

            //var itemStatus = selection.ItemStatus[0];

            var count = selection.Count;

            SelectedShapeCount = count;

            //var whatAreYou = selection[0];

            //if (Visio_Shape.HasTextTransformSection(shape))
            //{
            //    return true;
            //}
            //else
            //{
            //    return false;
            //}
            //// TODO(crhodes)
            //// Check if shape selected


            if (count > 0)
            {
                if (count != 1)
                {
                    LoadButtonContent = "Must select single shape to load settings";

                    return(false);
                }

                LoadButtonContent = "Load from Current Shape";

                return(true);
            }
            else
            {
                LoadButtonContent = "No shape selected";

                return(false);
            }
        }
Esempio n. 10
0
        public static List <IVisio.Shape> GetSelectedShapes(IVisio.Selection selection)
        {
            if (selection.Count < 1)
            {
                return(new List <IVisio.Shape>(0));
            }

            var sel_shapes = selection.ToEnumerable();
            var shapes     = sel_shapes.ToList();

            return(shapes);
        }
Esempio n. 11
0
        private void SelectionToSVGXHTML(IVisio.Selection selection, string filename, System.Action <string> verboselog)
        {
            this.AssertApplicationAvailable();
            this.AssertDocumentAvailable();

            // Save temp SVG
            string svg_filename = System.IO.Path.GetTempFileName() + "_temp.svg";

            selection.Export(svg_filename);

            // Load temp SVG
            var load_svg_timer = new System.Diagnostics.Stopwatch();
            var svg_doc        = SXL.XDocument.Load(svg_filename);

            load_svg_timer.Stop();
            verboselog(string.Format("Finished SVG Loading ({0} seconds)", load_svg_timer.Elapsed.TotalSeconds));

            // Delete temp SVG
            if (System.IO.File.Exists(svg_filename))
            {
                System.IO.File.Delete(svg_filename);
            }
            else
            {
                // TODO: throw an exception
            }

            verboselog(string.Format("Creating XHTML with embedded SVG"));
            var s = svg_filename;

            if (System.IO.File.Exists(filename))
            {
                verboselog(string.Format("Deleting \"{0}\"", filename));
                System.IO.File.Delete(filename);
            }

            var xhtml_doc  = new SXL.XDocument();
            var xhtml_root = new SXL.XElement("{http://www.w3.org/1999/xhtml}html");

            xhtml_doc.Add(xhtml_root);
            var svg_node = svg_doc.Root;

            svg_node.Remove();

            var body = new SXL.XElement("{http://www.w3.org/1999/xhtml}body");

            xhtml_root.Add(body);
            body.Add(svg_node);

            xhtml_doc.Save(filename);
            verboselog(string.Format("Done writing XHTML file \"{0}\"", filename));
        }
Esempio n. 12
0
        public void PrintDocument()
        {
            Visio.Document  doc    = axDrawingControl1.Document;
            Visio.Selection select = doc.Application.ActiveWindow.Selection;

            System.Windows.Forms.PrintDialog printDialog = new System.Windows.Forms.PrintDialog();
            if (printDialog.ShowDialog() == DialogResult.OK)
            {
                var PrinterName = printDialog.PrinterSettings.PrinterName;

                doc.PrintOut(Visio.VisPrintOutRange.visPrintCurrentView, 1, -1, true, PrinterName);
            }
        }
Esempio n. 13
0
        void OnLoadCurrentSettingsExecute()
        {
            Visio.Application app = Globals.ThisAddIn.Application;

            Visio.Selection selection = app.ActiveWindow.Selection;

            // Verify only one shape, for now just grab first.

            foreach (Visio.Shape shape in selection)
            {
                ControlRow = new ControlsRowWrapper(Visio_Shape.Get_ControlsRow(shape));
                OnPropertyChanged("ControlRow");
            }
        }
Esempio n. 14
0
        void OnLoadCurrentSettingsExecute()
        {
            Visio.Application app = Globals.ThisAddIn.Application;

            Visio.Selection selection = app.ActiveWindow.Selection;

            // Verify only one shape, for now just grab first.

            foreach (Visio.Shape shape in selection)
            {
                Paragraph = new ParagraphWrapper(Visio_Shape.Get_ParagraphSection(shape));
                OnPropertyChanged("Paragraph");
            }
        }
Esempio n. 15
0
        public override void OnLoadCurrentSettingsExecute()
        {
            Log.EVENT_HANDLER("Enter", Common.LOG_CATEGORY);
            Visio.Application app = Globals.ThisAddIn.Application;

            Visio.Selection selection = app.ActiveWindow.Selection;

            foreach (Visio.Shape shape in selection)
            {
                FillFormat = new FillFormatWrapper(Visio_Shape.Get_FillFormat(shape));
                OnPropertyChanged("FillFormat");
            }

            Log.EVENT_HANDLER("Exit", Common.LOG_CATEGORY);
        }
Esempio n. 16
0
    public void selectShpLayer(string layerName)
    {
        int i = 0;

        int[] lngRowIDs;
        Array lngRowIDArray;

        //this selects the shapes of the selected layer
        LayerSelection = acPage.CreateSelection(Microsoft.Office.Interop.Visio.VisSelectionTypes.visSelTypeByLayer, Microsoft.Office.Interop.Visio.VisSelectMode.visSelModeSkipSuper, layerName);
        LayerSelection.GetIDs(out lngRowIDArray);
        lngRowIDs = (int[])lngRowIDArray;
        for (i = 0; i < lngRowIDs.Length; i++)
        {
            Debug.Write("Object ID: " + lngRowIDs[i].ToString() + "\n");
        }
    }
        private void _export_selection_to_html(IVisio.Selection selection, string filename, System.Action <string> export_log)
        {
            var cmdtarget = this._client.GetCommandTargetPage();

            // Save temp SVG
            string svg_filename = System.IO.Path.GetTempFileName() + "_temp.svg";

            selection.Export(svg_filename);

            // Load temp SVG
            var load_svg_timer = new System.Diagnostics.Stopwatch();
            var svg_doc        = SXL.XDocument.Load(svg_filename);

            load_svg_timer.Stop();
            export_log(string.Format("Finished SVG Loading ({0} seconds)", load_svg_timer.Elapsed.TotalSeconds));

            // Delete temp SVG
            if (System.IO.File.Exists(svg_filename))
            {
                System.IO.File.Delete(svg_filename);
            }

            export_log("Creating XHTML with embedded SVG");

            if (System.IO.File.Exists(filename))
            {
                export_log(string.Format("Deleting \"{0}\"", filename));
                System.IO.File.Delete(filename);
            }

            var xhtml_doc  = new SXL.XDocument();
            var xhtml_root = new SXL.XElement("{http://www.w3.org/1999/xhtml}html");

            xhtml_doc.Add(xhtml_root);
            var svg_node = svg_doc.Root;

            svg_node.Remove();

            var body = new SXL.XElement("{http://www.w3.org/1999/xhtml}body");

            xhtml_root.Add(body);
            body.Add(svg_node);

            xhtml_doc.Save(filename);
            export_log(string.Format("Done writing XHTML file \"{0}\"", filename));
        }
Esempio n. 18
0
 private void Application_SelectionChanged(Visio.Window Window)
 {
     if (!_isAddingAShape)
     {
         ActionsRibbon   rib       = Globals.Ribbons.ActionsRibbon;
         Visio.Selection selection = Window.Selection;
         foreach (dynamic item in selection)
         {
             Visio.Shape shp = item as Visio.Shape;
             if (shp != null)
             {
                 shp.Characters.Text = "selected";
                 shp.CellsSRC[(short)Visio.VisSectionIndices.visSectionObject, 3, 0].FormulaU = $"THEMEGUARD(RGB({rib.Red}, {rib.Green}, {rib.Blue}))";
             }
         }
     }
     _isAddingAShape = false;
 }
Esempio n. 19
0
        private void stateDiagramToTable_Click(object sender, RibbonControlEventArgs e)
        {
            // The user needs to select one or more State Transiton Diagram Node
            // to start the conversion.
            Visio.Selection selection = app.ActiveWindow.Selection;

            if (selection.Count == 0)
            {
                MessageBox.Show("Select a State Transition Diagram to Convert.");
            }
            else
            {
                // Outputs the resulting State transition table to the State Transition Page
                Visio.Page outputPage = Utilities.getDrawingPage(app, CaseTypes.STATE_TABLE_PAGE);
                FlowSystem flowEditor = new FlowSystem();
                flowEditor.stateDiagramToTable(selection, outputPage);
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Converts the selected Flow Diagram to an Architecture Chart.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void convertToArchChartBtn_Click(object sender, RibbonControlEventArgs e)
        {
            // The user needs to select one or more Transform Center node of a Transform
            // Center Diagram to start the conversion.
            Visio.Selection selection = app.ActiveWindow.Selection;

            if (selection.Count == 0)
            {
                MessageBox.Show("Select a Data Flow Diagram to Convert.");
            }
            else
            {
                // Outputs the resulting Chart on the Architecture Chart Page.
                Visio.Page outputPage = Utilities.getDrawingPage(app, CaseTypes.ARCHITECTURE_PAGE);
                FlowSystem flowEditor = new FlowSystem();
                flowEditor.convertToArchitectureChart(selection, outputPage);
            }
        }
Esempio n. 21
0
        void OnLoadCurrentSettingsExecute()
        {
            Log.EVENT_HANDLER("Enter", Common.LOG_CATEGORY);

            Visio.Application app = Globals.ThisAddIn.Application;

            Visio.Selection selection = app.ActiveWindow.Selection;

            // Verify only one shape, for now just grab first.

            foreach (Visio.Shape shape in selection)
            {
                GeometryRow = new GeometryRowWrapper(Visio_Shape.Get_GeometryRow(shape));
                OnPropertyChanged("GeometryRow");
            }

            Log.EVENT_HANDLER("Exit", Common.LOG_CATEGORY);
        }
Esempio n. 22
0
        public void addSequanceDiagram(ref Word.Document doc)
        {
            try
            {
                Visio.Document sequenceVisio;
                string         sequenceDiagramPath = Directory.GetCurrentDirectory() + "\\Templates\\" + Constants.ServiceFlow + "\\ServiceSequanceDiagram.vsdx";
                sequenceVisio = visioApp.Documents.Open(sequenceDiagramPath);
                Visio.Page sequencePage = sequenceVisio.Pages[1];
                foreach (Visio.Shape shp in sequencePage.Shapes)
                {
                    if (shp.Name != "Watermark Title" && shp.Text != "")
                    {
                        shp.Text = shp.Text.Replace("ServiceCanonicalName", Constants.ServiceCanonicalName);
                        shp.Text = shp.Text.Replace("Subject", Constants.Subject);
                        shp.Text = shp.Text.Replace("Backend", Constants.BackendName);
                    }
                }

                Visio.Selection sequenceDiagram = sequencePage.CreateSelection(Visio.VisSelectionTypes.visSelTypeAll);

                sequenceDiagram.Copy();
                //rollback
                foreach (Visio.Shape shp in sequencePage.Shapes)
                {
                    if (shp.Name != "Watermark Title" && shp.Text != "")
                    {
                        shp.Text = shp.Text.Replace(Constants.ServiceCanonicalName, "ServiceCanonicalName");
                        shp.Text = shp.Text.Replace(Constants.Subject, "Subject");
                        shp.Text = shp.Text.Replace(Constants.BackendName, "Backend");
                    }
                }
                sequenceVisio.Saved = true;


                Word.Bookmark sequenceDiagBM  = doc.Bookmarks["SequenceDiagram"];
                Word.Range    sequenceDiagRng = sequenceDiagBM.Range;
                sequenceDiagRng.PasteAndFormat(Word.WdRecoveryType.wdFormatOriginalFormatting);
                Console.WriteLine("Sequance Diagram Added");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 23
0
 private static void SendShapes(IVisio.Selection selection, VisioAutomation.Scripting.Layout.ShapeSendDirection dir)
 {
     if (dir == VisioAutomation.Scripting.Layout.ShapeSendDirection.ToBack)
     {
         selection.SendToBack();
     }
     else if (dir == VisioAutomation.Scripting.Layout.ShapeSendDirection.Backward)
     {
         selection.SendBackward();
     }
     else if (dir == VisioAutomation.Scripting.Layout.ShapeSendDirection.Forward)
     {
         selection.BringForward();
     }
     else if (dir == VisioAutomation.Scripting.Layout.ShapeSendDirection.ToFront)
     {
         selection.BringToFront();
     }
 }
Esempio n. 24
0
 private static void _send_selection(IVisio.Selection selection, Models.ShapeSendDirection dir)
 {
     if (dir == Models.ShapeSendDirection.ToBack)
     {
         selection.SendToBack();
     }
     else if (dir == Models.ShapeSendDirection.Backward)
     {
         selection.SendBackward();
     }
     else if (dir == Models.ShapeSendDirection.Forward)
     {
         selection.BringForward();
     }
     else if (dir == Models.ShapeSendDirection.ToFront)
     {
         selection.BringToFront();
     }
 }
Esempio n. 25
0
        public static List <IVisio.Shape> GetSelectedShapesRecursive(IVisio.Selection selection)
        {
            if (selection.Count < 1)
            {
                return(new List <IVisio.Shape>(0));
            }

            var shapes     = new List <IVisio.Shape>();
            var sel_shapes = selection.ToEnumerable();

            foreach (var shape in Shapes.ShapeHelper.GetNestedShapes(sel_shapes))
            {
                if (shape.Type != (short)IVisio.VisShapeTypes.visTypeGroup)
                {
                    shapes.Add(shape);
                }
            }
            return(shapes);
        }
Esempio n. 26
0
 private static void SendShapes(Microsoft.Office.Interop.Visio.Selection selection, ShapeSendDirection dir)
 {
     if (dir == ShapeSendDirection.ToBack)
     {
         selection.SendToBack();
     }
     else if (dir == ShapeSendDirection.Backward)
     {
         selection.SendBackward();
     }
     else if (dir == ShapeSendDirection.Forward)
     {
         selection.BringForward();
     }
     else if (dir == ShapeSendDirection.ToFront)
     {
         selection.BringToFront();
     }
 }
Esempio n. 27
0
 public static void SendShapes(IVisio.Selection selection, ShapeSendDirection dir)
 {
     if (dir == ShapeSendDirection.ToBack)
     {
         selection.SendToBack();
     }
     else if (dir == ShapeSendDirection.Backward)
     {
         selection.SendBackward();
     }
     else if (dir == ShapeSendDirection.Forward)
     {
         selection.BringForward();
     }
     else if (dir == ShapeSendDirection.ToFront)
     {
         selection.BringToFront();
     }
 }
Esempio n. 28
0
        public static bool GetActiveSelection(Visio.Application visApp, out Visio.Selection visSelection)
        {
            Visio.Window visWindowDoc = null;

            visSelection = null;
            try
            {
                //Récupère la fenêtre courante
                if (GetVisActiveWindow(visApp, ref visWindowDoc))
                {
                    //Récupère la sélection courante
                    visSelection = visWindowDoc.Selection;
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Esempio n. 29
0
        //Replace Shape
        public void OnButton2Clicked()
        {
            Visio.Document doc = Application.ActiveDocument;
            Visio.Selection selection = Application.ActiveWindow.Selection;
            foreach(Visio.Shape select in selection)
            {
                if(select.Master == null) { continue;}
                if(select.Master.NameU == "Sequence Flow")
                {
                    select.ReplaceShape(doc.Masters.get_ItemU("DangerFlow"), 0);
                    continue;
                }
                if (select.Master.NameU == "DangerFlow")
                {
                    select.ReplaceShape(doc.Masters.get_ItemU("Sequence Flow"), 0);
                    continue;
                }

            }
        }
Esempio n. 30
0
        public override void OnUpdateSettingsExecute()
        {
            Log.EVENT_HANDLER("Enter", Common.LOG_CATEGORY);

            // Wrap a big, OMG, what have I done ???, undo around the whole thing !!!
            int undoScope = Globals.ThisAddIn.Application.BeginUndoScope("UpdateStyleProperties");

            Visio.Application app = Globals.ThisAddIn.Application;

            Visio.Selection selection = app.ActiveWindow.Selection;

            foreach (Visio.Shape shape in selection)
            {
                //Visio_Shape.Set_StylePropertiesViewModel_Section(shape, StylePropertiesViewModel.Model);
            }

            Globals.ThisAddIn.Application.EndUndoScope(undoScope, true);

            Log.EVENT_HANDLER("Exit", Common.LOG_CATEGORY);
        }