Ejemplo n.º 1
0
        public static void Close(IVisio.Document doc, bool force_close)
        {
            if (force_close)
            {
                var new_alert_response = Application.AlertResponseCode.No;
                var app = doc.Application;

                using (var alertresponse = new Application.AlertResponseScope(app, new_alert_response))
                {
                    doc.Close();
                }
            }
            else
            {
                doc.Close();
            }
        }
Ejemplo n.º 2
0
        private static void AutomateVisioImpl()
        {
            try
            {
                // Create an instance of Microsoft Visio and make it invisible.

                Visio.Application oVisio = new Visio.Application();
                oVisio.Visible = false;
                Console.WriteLine("Visio.Application is started");

                // Create a new Document based on no template.

                Visio.Document oDoc = oVisio.Documents.Add("");
                Console.WriteLine("A new document is created");

                // Draw a rectangle and a oval on the first page.

                Console.WriteLine("Draw a rectangle and a oval");
                oDoc.Pages[1].DrawRectangle(0.5, 10.25, 6.25, 7.375);
                oDoc.Pages[1].DrawOval(1.125, 6, 6.875, 2.125);

                // Save the document as a vsd file and close it.

                Console.WriteLine("Save and close the document");
                string fileName = Path.GetDirectoryName(
                    Assembly.GetExecutingAssembly().Location) + "\\Sample2.vsd";
                oDoc.SaveAs(fileName);
                oDoc.Close();

                // Quit the Visio application.

                Console.WriteLine("Quit the Visio application");
                oVisio.Quit();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Solution2.AutomateVisio throws the error: {0}",
                                  ex.Message);
            }
        }
Ejemplo n.º 3
0
        private void lvGeneral_MouseMove(object sender, MouseEventArgs e)
        {
            Image lvi = (Image)sender;

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                Visio.Page currentPage = visioControl.Document.Pages[1];
                if (lvi.Source.ToString().Contains("Stream"))
                {
                    Visio.Document  currentStencil  = visioControl.Document.Application.Documents.OpenEx("CONNEC_M.vss", (short)Visio.VisOpenSaveArgs.visAddHidden);
                    Visio.Master    visioRectMaster = currentStencil.Masters.get_ItemU(@"Dynamic connector");
                    DragDropEffects dde1            = DragDrop.DoDragDrop(lvi, visioRectMaster, DragDropEffects.All);
                    currentStencil.Close();
                    openProperty();
                }
                else if (lvi.Source.ToString().Contains("Steam"))
                {
                    Visio.Document  currentStencil  = visioControl.Document.Application.Documents.OpenEx("CONNEC_M.vss", (short)Visio.VisOpenSaveArgs.visAddHidden);
                    Visio.Master    visioRectMaster = currentStencil.Masters.get_ItemU(@"Dynamic connector");
                    DragDropEffects dde1            = DragDrop.DoDragDrop(lvi, visioRectMaster, DragDropEffects.All);
                    foreach (Visio.Shape shape in visioControl.Window.Selection)
                    {
                        shape.get_Cells("LineColor").Formula = "=THEMEGUARD(RGB(255,0,0))";
                    }
                    currentStencil.Close();
                    openProperty();
                }
                else if (lvi.Source.ToString().Contains("Valve"))
                {
                    Visio.Document  currentStencil  = visioControl.Document.Application.Documents.OpenEx("PEVALV_M.vss", (short)Visio.VisOpenSaveArgs.visAddHidden);
                    Visio.Master    visioRectMaster = currentStencil.Masters.get_ItemU(@"Gate valve");
                    DragDropEffects dde1            = DragDrop.DoDragDrop(lvi, visioRectMaster, DragDropEffects.All);
                    currentStencil.Close();
                    openProperty();
                }
                else if (lvi.Source.ToString().Contains("Mixer"))
                {
                    Visio.Document  currentStencil  = visioControl.Document.Application.Documents.OpenEx("PEVESS_M.vss", (short)Visio.VisOpenSaveArgs.visAddHidden);
                    Visio.Master    visioRectMaster = currentStencil.Masters.get_ItemU(@"Access point");
                    DragDropEffects dde1            = DragDrop.DoDragDrop(lvi, visioRectMaster, DragDropEffects.All);
                    currentStencil.Close();
                    openProperty();
                }

                else if (lvi.Source.ToString().Contains("Splitter"))
                {
                    Visio.Document  currentStencil  = visioControl.Document.Application.Documents.OpenEx("PEVESS_M.vss", (short)Visio.VisOpenSaveArgs.visAddHidden);
                    Visio.Master    visioRectMaster = currentStencil.Masters.get_ItemU(@"Branch fitting");
                    DragDropEffects dde1            = DragDrop.DoDragDrop(lvi, visioRectMaster, DragDropEffects.All);
                    currentStencil.Close();
                    openProperty();
                }
                else if (lvi.Source.ToString().Contains("Flash"))
                {
                    Visio.Document  currentStencil  = visioControl.Document.Application.Documents.OpenEx("PEVESS_M.vss", (short)Visio.VisOpenSaveArgs.visAddHidden);
                    Visio.Master    visioRectMaster = currentStencil.Masters.get_ItemU(@"Vessel");
                    DragDropEffects dde1            = DragDrop.DoDragDrop(lvi, visioRectMaster, DragDropEffects.All);
                    foreach (Visio.Shape shape in visioControl.Window.Selection)
                    {
                        //short count = shape.get_RowCount((short)Visio.VisSectionIndices.visSectionConnectionPts);
                        deleteConnector(shape, 0, 1);
                        deleteConnector(shape, 4, 4);
                    }
                    currentStencil.Close();
                    openProperty();
                }
                else if (lvi.Source.ToString().Contains("Pump"))
                {
                    Visio.Document  currentStencil  = visioControl.Document.Application.Documents.OpenEx("PEPUMP_M.vss", (short)Visio.VisOpenSaveArgs.visAddHidden);
                    Visio.Master    visioRectMaster = currentStencil.Masters.get_ItemU(@"Centrifugal pump");
                    DragDropEffects dde1            = DragDrop.DoDragDrop(lvi, visioRectMaster, DragDropEffects.All);
                    foreach (Visio.Shape shape in visioControl.Window.Selection)
                    {
                        shape.Text = shape.Name;
                        deleteConnector(shape, 0, 1);
                        deleteConnector(shape, 2, 2);
                    }
                    currentStencil.Close();
                    openProperty();
                }
                else if (lvi.Source.ToString().Contains("Source"))
                {
                    Visio.Document  currentStencil  = visioControl.Document.Application.Documents.OpenEx("PEVESS_M.vss", (short)Visio.VisOpenSaveArgs.visAddHidden);
                    Visio.Master    visioRectMaster = currentStencil.Masters.get_ItemU(@"Carring vessel");
                    DragDropEffects dde1            = DragDrop.DoDragDrop(lvi, visioRectMaster, DragDropEffects.All);

                    currentStencil.Close();
                    openProperty();
                }
                else if (lvi.Source.ToString().Contains("Sink"))
                {
                    Visio.Document  currentStencil  = visioControl.Document.Application.Documents.OpenEx("PEVESS_M.vss", (short)Visio.VisOpenSaveArgs.visAddHidden);
                    Visio.Master    visioRectMaster = currentStencil.Masters.get_ItemU(@"Open tank");
                    DragDropEffects dde1            = DragDrop.DoDragDrop(lvi, visioRectMaster, DragDropEffects.All);

                    currentStencil.Close();
                    openProperty();
                }


                else if (lvi.Source.ToString().Contains("Reboiler"))
                {
                    Visio.Document  currentStencil  = visioControl.Document.Application.Documents.OpenEx("PEHEAT_M.vss", (short)Visio.VisOpenSaveArgs.visAddHidden);
                    Visio.Master    visioRectMaster = currentStencil.Masters.get_ItemU(@"Kettle reboiler");
                    DragDropEffects dde1            = DragDrop.DoDragDrop(lvi, visioRectMaster, DragDropEffects.All);
                    foreach (Visio.Shape shape in visioControl.Window.Selection)
                    {
                        shape.get_Cells("LineColor").Formula = "=THEMEGUARD(RGB(255,0,0))";
                        deleteConnector(shape, 0, 1);
                        deleteConnector(shape, 2, 2);
                    }
                    currentStencil.Close();
                    openProperty();
                }
                else if (lvi.Source.ToString().Contains("Condenser"))
                {
                    Visio.Document  currentStencil  = visioControl.Document.Application.Documents.OpenEx("PEHEAT_M.vss", (short)Visio.VisOpenSaveArgs.visAddHidden);
                    Visio.Master    visioRectMaster = currentStencil.Masters.get_ItemU(@"Heat exchanger1");
                    DragDropEffects dde1            = DragDrop.DoDragDrop(lvi, visioRectMaster, DragDropEffects.All);
                    foreach (Visio.Shape shape in visioControl.Window.Selection)
                    {
                        deleteConnector(shape, 0, 1);
                        deleteConnector(shape, 2, 2);
                    }
                    currentStencil.Close();
                    openProperty();
                }
                else if (lvi.Source.ToString().Contains("ProcessHX"))
                {
                    Visio.Document  currentStencil  = visioControl.Document.Application.Documents.OpenEx("PEHEAT_M.vss", (short)Visio.VisOpenSaveArgs.visAddHidden);
                    Visio.Master    visioRectMaster = currentStencil.Masters.get_ItemU(@"Heat exchanger1");
                    DragDropEffects dde1            = DragDrop.DoDragDrop(lvi, visioRectMaster, DragDropEffects.All);
                    foreach (Visio.Shape shape in visioControl.Window.Selection)
                    {
                        deleteConnector(shape, 0, 1);
                    }
                    currentStencil.Close();
                    openProperty();
                }
                else if (lvi.Source.ToString().Contains("Furnace"))
                {
                    Visio.Document  currentStencil  = visioControl.Document.Application.Documents.OpenEx("PEHEAT_M.vss", (short)Visio.VisOpenSaveArgs.visAddHidden);
                    Visio.Master    visioRectMaster = currentStencil.Masters.get_ItemU(@"Fired heater");
                    DragDropEffects dde1            = DragDrop.DoDragDrop(lvi, visioRectMaster, DragDropEffects.All);
                    currentStencil.Close();
                    openProperty();
                }


                else if (lvi.Source.ToString().Contains("Distillation"))
                {
                    Visio.Document  myCurrentStencil = visioControl.Document.Application.Documents.OpenEx(System.Environment.CurrentDirectory + @"/Tower.vss", (short)Visio.VisOpenSaveArgs.visAddHidden);
                    Visio.Master    visioRectMaster  = myCurrentStencil.Masters.get_ItemU(@"Dis");
                    DragDropEffects dde1             = DragDrop.DoDragDrop(lvi, visioRectMaster, DragDropEffects.All);
                    myCurrentStencil.Close();
                    openProperty();
                }


                else if (lvi.Source.ToString().Contains("CentrifugalCompressor"))
                {
                    Visio.Document  currentStencil  = visioControl.Document.Application.Documents.OpenEx("PEPUMP_M.vss", (short)Visio.VisOpenSaveArgs.visAddHidden);
                    Visio.Master    visioRectMaster = currentStencil.Masters.get_ItemU(@"Compressor / turbine");
                    DragDropEffects dde1            = DragDrop.DoDragDrop(lvi, visioRectMaster, DragDropEffects.All);
                    currentStencil.Close();
                    openProperty();
                }
                else if (lvi.Source.ToString().Contains("RecipeCompressor"))
                {
                    Visio.Document  currentStencil  = visioControl.Document.Application.Documents.OpenEx("PEPUMP_M.vss", (short)Visio.VisOpenSaveArgs.visAddHidden);
                    Visio.Master    visioRectMaster = currentStencil.Masters.get_ItemU(@"Reciprocating pump/compr.");
                    DragDropEffects dde1            = DragDrop.DoDragDrop(lvi, visioRectMaster, DragDropEffects.All);
                    currentStencil.Close();
                    openProperty();
                }
            }
        }
Ejemplo n.º 4
0
        private void DrawDistillation(Visio.Shape shape)
        {
            Tower frm = new Tower();

            frm.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            Window parentWindow = Window.GetWindow(this);

            frm.Owner  = parentWindow;
            frm.dbFile = dbFile;
            //frm.txtName.Text = shape.Text;
            frm.eqType  = "Column";
            frm.vsdFile = System.IO.Path.GetFileName(visioControl.Src);
            shape.get_Cells("Height").ResultIU = 2;

            double width  = shape.get_Cells("Width").ResultIU;
            double height = shape.get_Cells("Height").ResultIU;
            double pinX   = shape.get_Cells("PinX").ResultIU;
            double pinY   = shape.get_Cells("PinY").ResultIU;

            if (frm.ShowDialog() == true)
            {
                if (frm.op == 1)
                {
                    shape.Text = frm.txtName.Text;
                    return;
                }
                deleteShapesExcept(shape);
                przFile = frm.przFile;
                Visio.Document currentStencil_1      = visioControl.Document.Application.Documents.OpenEx("PEHEAT_M.vss", (short)Visio.VisOpenSaveArgs.visAddHidden);
                Visio.Document currentStencil_2      = visioControl.Document.Application.Documents.OpenEx("CONNEC_M.vss", (short)Visio.VisOpenSaveArgs.visAddHidden);
                Visio.Document currentStencil_3      = visioControl.Document.Application.Documents.OpenEx("PEVESS_M.vss", (short)Visio.VisOpenSaveArgs.visAddHidden);
                Visio.Master   condenserMaster       = currentStencil_1.Masters.get_ItemU(@"Heat exchanger1");
                Visio.Master   reboilerMaster        = currentStencil_1.Masters.get_ItemU(@"Kettle reboiler");
                Visio.Master   streamMaster          = currentStencil_2.Masters.get_ItemU(@"Dynamic connector");
                Visio.Master   condenserVesselMaster = currentStencil_3.Masters.get_ItemU(@"Vessel");

                Visio.Document startStencil = visioControl.Document.Application.Documents.OpenEx("PEVESS_M.vss", (short)Visio.VisOpenSaveArgs.visAddHidden);
                Visio.Master   startMaster  = startStencil.Masters.get_ItemU(@"Carrying vessel");
                Visio.Master   endMaster    = startStencil.Masters.get_ItemU(@"Clarifier");


                int       stagenumber = int.Parse(frm.txtStageNumber.Text);
                DataTable dtFeed      = (DataTable)Application.Current.Properties["FeedData"];
                int       start       = 16;
                double    multiple    = 0.125;
                //double leftmultiple = 1.5;
                int center = 13;
                foreach (DataRow dr in dtFeed.Rows)
                {
                    Visio.Shape connector = visioControl.Window.Application.ActivePage.Drop(streamMaster, 5, 5);
                    ConnectShapes(shape, start, connector, 0);
                    connector.Text = dr["streamname"].ToString();

                    Visio.Shape startShp = visioControl.Window.Application.ActivePage.Drop(startMaster, pinX - 2, pinY + (start - center) * multiple * height);
                    startShp.get_Cells("Height").ResultIU = 0.1;
                    startShp.get_Cells("Width").ResultIU  = 0.2;
                    startShp.Text = connector.Text + "_Source";
                    ConnectShapes(startShp, 2, connector, 1);
                    start--;
                    if (start < 11)
                    {
                        start = 16;
                    }
                }

                DataTable dtProd        = (DataTable)Application.Current.Properties["ProdData"];
                DataTable dtReboiler    = (DataTable)Application.Current.Properties["Reboiler"];
                DataTable dtCondenser   = (DataTable)Application.Current.Properties["Condenser"];
                DataTable dtHxCondenser = (DataTable)Application.Current.Properties["HxCondenser"];

                Visio.Shape condenser;
                Visio.Shape condenserVessel = null;
                double      twidth          = 0;
                double      theight         = 0;
                double      tpinX           = 0;
                double      tpinY           = 0;
                if (dtCondenser.Rows.Count > 0)
                {
                    condenser       = visioControl.Window.Application.ActivePage.Drop(condenserMaster, pinX + 1, pinY + height / 2 + 0.2);
                    condenserVessel = visioControl.Window.Application.ActivePage.Drop(condenserVesselMaster, pinX + 1.5, pinY + height / 2 + 0.1);
                    condenserVessel.get_Cells("Height").ResultIU = 0.2;
                    condenser.get_Cells("Height").ResultIU       = 0.2;
                    condenser.get_Cells("Width").ResultIU        = 0.2;
                    Visio.Shape connector1 = visioControl.Window.Application.ActivePage.Drop(streamMaster, 5, 5);
                    Visio.Shape connector2 = visioControl.Window.Application.ActivePage.Drop(streamMaster, 5, 5);
                    Visio.Shape connector3 = visioControl.Window.Application.ActivePage.Drop(streamMaster, 5, 5);
                    ConnectShapes(shape, 1, connector1, 1);//从塔到冷凝器
                    ConnectShapes(condenser, 2, connector1, 0);

                    ConnectShapes(condenser, 1, connector2, 1);
                    ConnectShapes(condenserVessel, 1, connector2, 0);

                    ConnectShapes(condenserVessel, 8, connector3, 1);
                    ConnectShapes(shape, 2, connector3, 0);
                    twidth  = condenserVessel.get_Cells("Width").ResultIU;
                    theight = condenserVessel.get_Cells("Height").ResultIU;
                    tpinX   = condenserVessel.get_Cells("PinX").ResultIU;
                    tpinY   = condenserVessel.get_Cells("PinY").ResultIU;

                    condenser.Text = dtCondenser.Rows[0]["heatername"].ToString();
                }

                for (int i = 1; i <= dtHxCondenser.Rows.Count; i++)
                {
                    DataRow dr = dtHxCondenser.Rows[i - 1];
                    condenser       = visioControl.Window.Application.ActivePage.Drop(condenserMaster, pinX, pinY + height / 2 - i * 0.4);
                    condenserVessel = visioControl.Window.Application.ActivePage.Drop(condenserVesselMaster, pinX + 1.5, pinY + height / 2 + 0.1);
                    condenserVessel.get_Cells("Height").ResultIU = 0.2;
                    condenser.get_Cells("Height").ResultIU       = 0.2;
                    condenser.get_Cells("Width").ResultIU        = 0.2;
                    condenser.Text = dr["heatername"].ToString();
                }



                Visio.Shape reboiler = null;
                double      bwidth   = 0;
                double      bheight  = 0;
                double      bpinX    = 0;
                double      bpinY    = 0;
                if (dtReboiler.Rows.Count > 0)
                {
                    reboiler = visioControl.Window.Application.ActivePage.Drop(reboilerMaster, pinX + 1, pinY - height / 2 - 0.2);
                    Visio.Shape connector1 = visioControl.Window.Application.ActivePage.Drop(streamMaster, 5, 5);
                    Visio.Shape connector2 = visioControl.Window.Application.ActivePage.Drop(streamMaster, 5, 5);
                    ConnectShapes(shape, 9, connector1, 1);//从塔到加热器
                    ConnectShapes(reboiler, 4, connector1, 0);

                    ConnectShapes(shape, 8, connector2, 0);//从加热器到塔
                    ConnectShapes(reboiler, 3, connector2, 1);
                    reboiler.Text = dtReboiler.Rows[0]["heatername"].ToString();
                }


                start  = 3;
                center = 5;
                int topcount    = 1;
                int bottomcount = 1;
                foreach (DataRow dr in dtProd.Rows)
                {
                    int tray = -1;
                    if (dr["tray"].ToString() != string.Empty)
                    {
                        tray = int.Parse(dr["tray"].ToString());
                    }
                    if (tray == 1)
                    {
                        if (dtCondenser.Rows.Count == 0)
                        {
                            Visio.Shape connector = visioControl.Window.Application.ActivePage.Drop(streamMaster, 5, 5);
                            ConnectShapes(shape, 1, connector, 1);
                            connector.Text = dr["streamname"].ToString();
                            Visio.Shape endShp = visioControl.Window.Application.ActivePage.Drop(endMaster, pinX + 2, pinY - 2 - height / 2);
                            endShp.get_Cells("Height").ResultIU = 0.1;
                            endShp.get_Cells("Width").ResultIU  = 0.2;
                            endShp.Text = connector.Text + "_Sink";
                            ConnectShapes(endShp, 7, connector, 0);
                        }
                        else
                        {
                            if (topcount == 1) //开放3,6,7
                            {
                                Visio.Shape connector = visioControl.Window.Application.ActivePage.Drop(streamMaster, 5, 5);
                                ConnectShapes(condenserVessel, 3, connector, 1);
                                connector.Text = dr["streamname"].ToString();

                                Visio.Shape endShp = visioControl.Window.Application.ActivePage.Drop(endMaster, tpinX + 2, tpinY - 0.2);
                                endShp.get_Cells("Height").ResultIU = 0.1;
                                endShp.get_Cells("Width").ResultIU  = 0.2;
                                endShp.Text = connector.Text + "_Sink";
                                ConnectShapes(endShp, 7, connector, 0);
                                topcount++;
                            }
                            else if (topcount == 2)
                            {
                                Visio.Shape connector = visioControl.Window.Application.ActivePage.Drop(streamMaster, 5, 5);
                                ConnectShapes(condenserVessel, 6, connector, 1);
                                connector.Text = dr["streamname"].ToString();

                                Visio.Shape endShp = visioControl.Window.Application.ActivePage.Drop(endMaster, tpinX + 2, tpinY + 0.4);
                                endShp.get_Cells("Height").ResultIU = 0.1;
                                endShp.get_Cells("Width").ResultIU  = 0.2;
                                endShp.Text = connector.Text + "_Sink";
                                ConnectShapes(endShp, 7, connector, 0);
                                topcount++;
                            }
                            else
                            {
                                Visio.Shape connector = visioControl.Window.Application.ActivePage.Drop(streamMaster, 5, 5);
                                ConnectShapes(condenserVessel, 7, connector, 1);
                                connector.Text = dr["streamname"].ToString();


                                Visio.Shape endShp = visioControl.Window.Application.ActivePage.Drop(endMaster, tpinX + 2, tpinY - 0.1);
                                endShp.get_Cells("Height").ResultIU = 0.1;
                                endShp.get_Cells("Width").ResultIU  = 0.2;
                                endShp.Text = connector.Text + "_Sink";
                                ConnectShapes(endShp, 7, connector, 0);
                                topcount++;
                            }
                        }
                    }
                    else if (tray == stagenumber)
                    {
                        if (dtReboiler.Rows.Count == 0)
                        {
                            Visio.Shape connector = visioControl.Window.Application.ActivePage.Drop(streamMaster, 5, 5);
                            ConnectShapes(shape, 9, connector, 1);
                            connector.Text = dr["streamname"].ToString();
                            Visio.Shape endShp = visioControl.Window.Application.ActivePage.Drop(endMaster, pinX + 2, pinY + 0.5 - height / 2);
                            endShp.get_Cells("Height").ResultIU = 0.1;
                            endShp.get_Cells("Width").ResultIU  = 0.2;
                            endShp.Text = connector.Text + "_Sink";
                            ConnectShapes(endShp, 7, connector, 0);
                        }
                        else
                        {
                            Visio.Shape connector = visioControl.Window.Application.ActivePage.Drop(streamMaster, 5, 5);
                            ConnectShapes(reboiler, 1, connector, 1);
                            connector.Text = dr["streamname"].ToString();
                            Visio.Shape endShp = visioControl.Window.Application.ActivePage.Drop(endMaster, pinX + 2, pinY - 0.5 - height / 2);
                            endShp.get_Cells("Height").ResultIU = 0.1;
                            endShp.get_Cells("Width").ResultIU  = 0.2;
                            endShp.Text = connector.Text + "_Sink";
                            ConnectShapes(endShp, 7, connector, 0);
                        }
                    }
                    else
                    {
                        Visio.Shape connector = visioControl.Window.Application.ActivePage.Drop(streamMaster, 5, 5);
                        ConnectShapes(shape, start, connector, 1);
                        connector.Text = dr["streamname"].ToString();

                        Visio.Shape endShp = visioControl.Window.Application.ActivePage.Drop(endMaster, pinX + 2, pinY + (center - start) * multiple * height);
                        endShp.get_Cells("Height").ResultIU = 0.1;
                        endShp.get_Cells("Width").ResultIU  = 0.2;
                        endShp.Text = connector.Text + "_Sink";
                        ConnectShapes(endShp, 7, connector, 0);
                        start++;
                        if (start > 8)
                        {
                            start = 3;
                        }
                    }
                }



                currentStencil_1.Close();
                currentStencil_2.Close();
                currentStencil_3.Close();

                shape.Text = frm.txtName.Text;
                Application.Current.Properties.Remove("Condenser");
                Application.Current.Properties.Remove("HxCondenser");
                Application.Current.Properties.Remove("Reboiler");
                Application.Current.Properties.Remove("HxReboiler");
                Application.Current.Properties.Remove("FeedData");
                Application.Current.Properties.Remove("ProdData");
                visioControl.Document.SaveAs(visioControl.Src);
            }
        }
Ejemplo n.º 5
0
        public static void AutomateVisio()
        {
            Visio.Application oVisio     = null;
            Visio.Documents   oDocs      = null;
            Visio.Document    oDoc       = null;
            Visio.Pages       oPages     = null;
            Visio.Page        oPage      = null;
            Visio.Shape       oRectShape = null;
            Visio.Shape       oOvalShape = null;

            try
            {
                // Create an instance of Microsoft Visio and make it invisible.

                oVisio         = new Visio.Application();
                oVisio.Visible = false;
                Console.WriteLine("Visio.Application is started");

                // Create a new Document based on no template.

                oDocs = oVisio.Documents;
                oDoc  = oDocs.Add("");
                Console.WriteLine("A new document is created");

                // Draw a rectangle and a oval on the first page.

                Console.WriteLine("Draw a rectangle and a oval");

                oPages     = oDoc.Pages;
                oPage      = oPages[1];
                oRectShape = oPage.DrawRectangle(0.5, 10.25, 6.25, 7.375);
                oOvalShape = oPage.DrawOval(1.125, 6, 6.875, 2.125);

                // Save the document as a vsd file and close it.

                Console.WriteLine("Save and close the document");
                string fileName = Path.GetDirectoryName(
                    Assembly.GetExecutingAssembly().Location) + "\\Sample1.vsd";
                oDoc.SaveAs(fileName);
                oDoc.Close();

                // Quit the Visio application.

                Console.WriteLine("Quit the Visio application");
                oVisio.Quit();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Solution1.AutomateVisio throws the error: {0}",
                                  ex.Message);
            }
            finally
            {
                // Clean up the unmanaged Visio COM resources by explicitly
                // calling Marshal.FinalReleaseComObject on all accessor objects.
                // See http://support.microsoft.com/kb/317109.

                if (oOvalShape != null)
                {
                    Marshal.FinalReleaseComObject(oOvalShape);
                    oOvalShape = null;
                }
                if (oRectShape != null)
                {
                    Marshal.FinalReleaseComObject(oRectShape);
                    oRectShape = null;
                }
                if (oPage != null)
                {
                    Marshal.FinalReleaseComObject(oPage);
                    oPage = null;
                }
                if (oPages != null)
                {
                    Marshal.FinalReleaseComObject(oPages);
                    oPages = null;
                }
                if (oDoc != null)
                {
                    Marshal.FinalReleaseComObject(oDoc);
                    oDoc = null;
                }
                if (oDocs != null)
                {
                    Marshal.FinalReleaseComObject(oDocs);
                    oDocs = null;
                }
                if (oVisio != null)
                {
                    Marshal.FinalReleaseComObject(oVisio);
                    oVisio = null;
                }
            }
        }
        public static void Main(string[] args)
        {
            Console.WriteLine("Process models mining started...");

            string[] models = Directory.GetFiles(MODELS_PATH, "*.vsd", SearchOption.AllDirectories);

            foreach (string model in models)
            {
                Console.WriteLine(model);

                Visio.Application visioApp = new Visio.Application();
                Visio.Document    document = visioApp.Documents.Open(model);

                visioApp.Visible = true;

                VBA.VBComponent codeModule = document.VBProject.VBComponents.Add(VBA.vbext_ComponentType.vbext_ct_StdModule);

                string vbaCode = @"
                Sub ExtractProcessModel()
                    Set file = CreateObject(""Scripting.FileSystemObject"").CreateTextFile(""${models_path}"" & ActiveDocument.Name & "".java"", True, True)
    
                    file.Write (""/* "" & ActiveDocument.Name & "" */ {"" & vbNewLine)
                    file.Write (""Process process = repository.createProcess("""""" & ActiveDocument.Name & """""");"" & vbNewLine)
    
                    For i = 1 To ActivePage.Shapes.Count
                        'For native Visio-based EPC diagrams
                        If InStr(ActivePage.Shapes(i).NameU, ""Dynamic connector"") <> 0 Then
                            FromShape = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(1).ToSheet.Text
                            ToShape = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(2).ToSheet.Text
            
                            FromShapeID = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(1).ToSheet.ID
                            ToShapeID = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(2).ToSheet.ID
            
                            FromShapeName = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(1).ToSheet.NameU
                            ToShapeName = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(2).ToSheet.NameU
            
                            If InStr(FromShapeName, ""Organizational unit"") <> 0 Then
                                file.Write (""repository.createResourceFlow("")
                            ElseIf InStr(FromShapeName, ""Information/ Material"") <> 0 Then
                                file.Write (""repository.createInputFlow("")
                            ElseIf InStr(ToShapeName, ""Information/ Material"") <> 0 Then
                                file.Write (""repository.createOutputFlow("")
                            Else
                                file.Write (""repository.createControlFlow("")
                            End If
            
                            For j = 1 To ActivePage.Shapes(i).FromConnects.ToSheet.Connects.Count
                                CurrentShapeName = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.NameU
            
                                ResText = Null
                                ResID = Null
                
                                If j = 1 Then
                                    ResText = FromShape
                                    ResID = FromShapeID
                                Else
                                    ResText = ToShape
                                    ResID = ToShapeID
                                End If
            
                                If InStr(CurrentShapeName, ""Event"") <> 0 Then
                                    file.Write (""repository.createEvent("""""" & ResText & """""", process)"")
                                End If
                
                                If InStr(CurrentShapeName, ""Function"") <> 0 Then
                                    file.Write (""repository.createFunction("""""" & ResText & """""", process)"")
                                End If
                
                                If InStr(CurrentShapeName, ""XOR"") <> 0 Then
                                    file.Write (""repository.createXOrGateway("""""" & ResID & """""", process)"")
                                ElseIf InStr(CurrentShapeName, ""OR"") <> 0 Then
                                    file.Write (""repository.createOrGateway("""""" & ResID & """""", process)"")
                                End If
                
                                If InStr(CurrentShapeName, ""AND"") <> 0 Then
                                    file.Write (""repository.createAndGateway("""""" & ResID & """""", process)"")
                                End If
                
                                If InStr(CurrentShapeName, ""Process path"") <> 0 Then
                                    file.Write (""repository.createProcessInterface("""""" & ResText & """""", process)"")
                                End If
                
                                If InStr(CurrentShapeName, ""Organizational unit"") <> 0 Then
                                    file.Write (""repository.createOrganizationalUnit("""""" & ResText & """""")"")
                                End If
                
                                If InStr(CurrentShapeName, ""Information/ Material"") <> 0 Then
                                    file.Write (""repository.createBusinessObject("""""" & ResText & """""")"")
                                End If
                
                                If j = 1 Then
                                    file.Write ("", "")
                                Else
                                    file.Write ("");"" & vbNewLine)
                                End If
                            Next
                        End If

                        'For custom ARIS stencil-based diagrams
                        If InStr(ActivePage.Shapes(i).Name, ""IsPredecessorOfARIS"") <> 0 Then
                            Subj = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(1).ToSheet.Text
                            Obj = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(2).ToSheet.Text
            
                            file.Write (""repository.createControlFlow("")
            
                            For j = 1 To ActivePage.Shapes(i).FromConnects.ToSheet.Connects.Count
                                ResName = Null
                
                                If j = 1 Then
                                    ResName = Subj
                                Else
                                    ResName = Obj
                                End If
                
                                ValID = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.ID
                
                                If InStr(ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Name, ""EventARIS"") <> 0 Then
                                    file.Write (""repository.createEvent("""""" & ResName & """""", process)"")
                                End If
                
                                If InStr(ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Name, ""FunctionARIS"") <> 0 Then
                                    file.Write (""repository.createFunction("""""" & ResName & """""", process)"")
                                End If
                
                                If InStr(ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Name, ""ProcessInterfaceARIS"") <> 0 Then
                                    file.Write (""repository.createProcessInterface("""""" & ResName & """""", process)"")
                                End If
                
                                If InStr(ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Name, ""ANDruleARIS"") <> 0 Then
                                    file.Write (""repository.createAndGateway("""""" & ValID & """""", process)"")
                                End If
                
                                If InStr(ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Name, ""XORruleARIS"") <> 0 Then
                                    file.Write (""repository.createXOrGateway("""""" & ValID & """""", process)"")
                                ElseIf InStr(ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Name, ""ORruleARIS"") <> 0 Then
                                    file.Write (""repository.createOrGateway("""""" & ValID & """""", process)"")
                                End If
                
                                If j = 1 Then
                                    file.Write ("", "")
                                Else
                                    file.Write ("");"" & vbNewLine)
                                End If
                            Next
                        End If
    
                        If InStr(ActivePage.Shapes(i).Name, ""RoleInProcessARIS"") <> 0 Then
                            Subj = Null
                            Obj = Null
            
                            For j = 1 To ActivePage.Shapes(i).FromConnects.ToSheet.Connects.Count
                                If InStr(ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Name, ""FunctionARIS"") <> 0 Then
                                    Subj = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Text
                                Else
                                    Obj = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Text
                                End If
                            Next
            
                            file.Write (""repository.assignOrganizationalUnits(repository.createFunction("""""" & Subj & """""", process), repository.createOrganizationalUnit("""""" & Obj & """"""));"" & vbNewLine)
                        End If
        
                        If InStr(ActivePage.Shapes(i).Name, ""SoftwareRoleARIS"") <> 0 Then
                            Subj = Null
                            Obj = Null
            
                            For j = 1 To ActivePage.Shapes(i).FromConnects.ToSheet.Connects.Count
                                If InStr(ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Name, ""FunctionARIS"") <> 0 Then
                                    Subj = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Text
                                Else
                                    Obj = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Text
                                End If
                            Next
            
                            file.Write (""repository.assignApplicationSystems(repository.createFunction("""""" & Subj & """""", process), repository.createApplicationSystem("""""" & Obj & """"""));"" & vbNewLine)
                        End If
        
                        If InStr(ActivePage.Shapes(i).Name, ""InputObjectARIS"") <> 0 Then
                            Subj = Null
                            Obj = Null
            
                            For j = 1 To ActivePage.Shapes(i).FromConnects.ToSheet.Connects.Count
                                If InStr(ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Name, ""FunctionARIS"") <> 0 Then
                                    Subj = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Text
                                Else
                                    Obj = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Text
                                End If
                            Next
            
                            file.Write (""repository.assignInputs(repository.createFunction("""""" & Subj & """""", process), repository.createBusinessObject("""""" & Obj & """"""));"" & vbNewLine)
                        End If
        
                        If InStr(ActivePage.Shapes(i).Name, ""OutputObjectARIS"") <> 0 Then
                            Subj = Null
                            Obj = Null
            
                            For j = 1 To ActivePage.Shapes(i).FromConnects.ToSheet.Connects.Count
                                If InStr(ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Name, ""FunctionARIS"") <> 0 Then
                                    Subj = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Text
                                Else
                                    Obj = ActivePage.Shapes(i).FromConnects.ToSheet.Connects(j).ToSheet.Text
                                End If
                            Next
            
                            file.Write (""repository.assignOutputs(repository.createFunction("""""" & Subj & """""", process), repository.createBusinessObject("""""" & Obj & """"""));"" & vbNewLine)
                        End If
                    Next
    
                    file.Write (""repository.store();"" & vbNewLine)
                    file.Write (""}"")
    
                    file.Close
                End Sub";

                vbaCode = vbaCode.Replace("${models_path}", MODELS_PATH);

                codeModule.CodeModule.AddFromString(vbaCode);

                document.ExecuteLine("ExtractProcessModel");

                document.VBProject.VBComponents.Remove(codeModule);

                document.Save();
                document.Close();

                visioApp.Quit();
            }

            string[] files = Directory.GetFiles(MODELS_PATH, "*.java", SearchOption.AllDirectories);

            string modelsCollection = @"
            package main.resources.repository;

            import edu.kopp.phd.ProcessModelRepositoryApplication;
            import edu.kopp.phd.model.flow.Process;
            import edu.kopp.phd.repository.RDFRepository;

            import org.junit.Test;

            public class PortalProcessModelsCollection {
            public RDFRepository repository = RDFRepository.getInstance();
            ";

            foreach (string file in files)
            {
                modelsCollection += File.ReadAllText(file) + "\n";

                File.Delete(file);
            }

            modelsCollection += @"
                @Test
                public void deploy() {
                    ProcessModelRepositoryApplication.run();
                }
            }";

            File.WriteAllText(PORTAL_COLLECTION_PATH, modelsCollection);

            string[] pages = Directory.GetFiles(PAGES_PATH, "*.html", SearchOption.AllDirectories);

            foreach (string page in pages)
            {
                File.Delete(page);
            }

            Console.WriteLine("Done!");
        }
Ejemplo n.º 7
0
        public void GenerateVSS()
        {
            visapp         = new IVisio.InvisibleApp();
            visapp.Visible = false;
            foreach (fileListElement fileEl in fileList)
            {
                try
                {
                    string templateFileName = Directory.GetCurrentDirectory() + "\\template.vss";
                    string newFullfileName  = fileEl.filePath + "\\result\\" + fileEl.fileName.Replace(".kml", ".vsd");

                    if (!File.Exists(templateFileName))
                    {
                        throw new Exception("Не найден шаблон выходного файла: " + templateFileName);
                    }

                    Directory.CreateDirectory(fileEl.filePath + "\\result\\");

                    string fileName = fileEl.fileName;
                    string caption  = "Поопорная схема ВЛ 0,4 кВ от ";
                    string firstTmp = "";
                    int    tpPos    = fileName.IndexOf("ТП");
                    if (tpPos >= 0)
                    {
                        firstTmp = fileName.Substring(tpPos, fileName.Length - tpPos).Replace('_', '/').Replace(".kml", "");
                        string secondTmp = fileName.Substring(0, tpPos - 1);
                        fileName = firstTmp + " кВА " + secondTmp;
                    }
                    else
                    {
                        throw new Exception("Не корректное название файла: " + fileName);
                    }
                    caption = caption + fileName + " " + fileEl.city;

                    IVisio.Document doc  = visapp.Documents.Open(templateFileName);// (short)IVisio.VisOpenSaveArgs.visAddHidden + (short)IVisio.VisOpenSaveArgs.visOpenNoWorkspace);
                    IVisio.Page     page = doc.Pages[1];

                    IVisio.Shape visioRectMaster = page.Shapes.get_ItemU("Sheet.1");
                    visioRectMaster.Text = caption;

                    visioRectMaster      = page.Shapes.get_ItemU("Sheet.509");
                    visioRectMaster.Text = caption;

                    visioRectMaster      = page.Shapes.get_ItemU("Sheet.496");
                    visioRectMaster.Text = fileEl.make;

                    visioRectMaster      = page.Shapes.get_ItemU("Sheet.508");
                    visioRectMaster.Text = fileEl.makeDate;

                    visioRectMaster      = page.Shapes.get_ItemU("Sheet.495");
                    visioRectMaster.Text = fileEl.check;

                    visioRectMaster      = page.Shapes.get_ItemU("Sheet.507");
                    visioRectMaster.Text = fileEl.checkDate;

                    int    pos2 = firstTmp.LastIndexOf('-');
                    int    pos3 = firstTmp.LastIndexOf('/');
                    string tmp2 = "?";
                    if (pos2 != -1 & pos3 != -1 & pos3 > pos2)
                    {
                        tmp2 = firstTmp.Substring(pos2 + 1, pos3 - pos2 - 1);
                    }

                    visioRectMaster      = page.Shapes.get_ItemU("Sheet.314");
                    visioRectMaster.Text = "РЛНД - " + tmp2;

                    IVisio.Master aMaster;
                    switch (fileEl.tpType)
                    {
                    case "Столбовая":
                        aMaster         = doc.Masters.get_ItemU(@"СТП");
                        visioRectMaster = page.Drop(aMaster, 6.3400314961, 5.4108622047);
                        //visioRectMaster.tra
                        visioRectMaster.Shapes[2].Text = "С" + firstTmp;
                        break;

                    case "Мачтовая":
                        aMaster         = doc.Masters.get_ItemU(@"МТП");
                        visioRectMaster = page.Drop(aMaster, 6.3976378, 5.4108622047);
                        visioRectMaster.Shapes[2].Text = "М" + firstTmp;
                        break;

                    case "Закрытая":
                        aMaster         = doc.Masters.get_ItemU(@"ЗТП");
                        visioRectMaster = page.Drop(aMaster, 6.313976378, 5.23622);
                        visioRectMaster.Shapes[2].Text = "З" + firstTmp;
                        break;

                    case "Комплектная":
                        aMaster         = doc.Masters.get_ItemU(@"КТП");
                        visioRectMaster = page.Drop(aMaster, 6.4422795276, 5.4108622047);
                        visioRectMaster.Shapes[2].Text = "К" + firstTmp;
                        break;
                    }

                    doc.SaveAs(newFullfileName);
                    doc.Close();
                    //visapp.Quit();
                }
                catch (Exception ex)
                {
                    LogTextEvent(Color.Red, ex.Message);
                }
            }
            foreach (IVisio.Document aDoc in visapp.Documents)
            {
                aDoc.Close();
            }
            visapp.Quit();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// This is the root of the recursive descent to display the tree on the Visio doc.
        /// The function uses PlaceOneShape() to start the recursive display.
        /// </summary>
        /// <param name="colorMap">Color map to use to render.</param>
        /// <param name="root">Root node to render.</param>
        private static void BuildAndDisplayWithVisio(
            Dictionary <string, string> colorMap,
            TypeTreeNode root)
        {
            Visio.Application app             = null;
            Visio.Document    contentDocument = null;

            try
            {
                app = new Visio.Application();
                app.Settings.EnableAutoConnect = false;
                ////app.Window.WindowState = (int)Visio.VisWindowStates.visWSRestored;
                app.Window.WindowState = (int)Visio.VisWindowStates.visWSMinimized;

                contentDocument = app.Documents.AddEx(
                    string.Empty,
                    Visio.VisMeasurementSystem.visMSUS,
                    (int)Visio.VisOpenSaveArgs.visAddDocked,
                    (int)0);

                contentDocument.PaperSize      = Visio.VisPaperSizes.visPaperSizeE;
                contentDocument.PrintLandscape = true;

                /*
                 * Visio.Document stencilDocument = contentDocument.Application.Documents.OpenEx(
                 *  "Basic_U.vss",
                 *  (short)Visio.VisOpenSaveArgs.visOpenDocked);
                 * Visio.Master shape = stencilDocument.Masters["Rectangle"];
                 */

                Visio.Master shape = contentDocument.Application.Documents.OpenEx(
                    "Basic_U.vss",
                    (short)Visio.VisOpenSaveArgs.visOpenDocked).Masters["Rectangle"];

                Visio.Page targetPage = contentDocument.Pages[1];
                targetPage.Name = "MFx Class Hirearchy";

                BuildHeadersAndFooters(colorMap, contentDocument);

                /*
                 * Program.selectionTree = app.ActiveWindow.Selection;
                 * Program.selectionTree.DeselectAll();
                 */

                double movingYBase = 4.0;
                foreach (TypeTreeNode t in
                         root.Children.Values.OrderBy(t => t.RawType.Namespace).ThenBy(t => t.RawType.Name))
                {
                    movingYBase = PlaceOneShape(
                        colorMap,
                        targetPage,
                        t,
                        shape,
                        null,
                        2.0,
                        movingYBase);
                }

                // now turn the selection into a group, and run the layout code
                // to make the tree look "right"
                ////Program.selectionTree.Group();

                // resize, set the placement, and connector routing styles
                Visio.Cell layoutCell;

                layoutCell = targetPage.PageSheet.get_CellsSRC(
                    (short)Visio.VisSectionIndices.visSectionObject,
                    (short)Visio.VisRowIndices.visRowPageLayout,
                    (short)Visio.VisCellIndices.visPLOResizePage);

                layoutCell.FormulaU = "FALSE";  // don't add more pages to contain the tree, let the user edit

                layoutCell = targetPage.PageSheet.get_CellsSRC(
                    (short)Visio.VisSectionIndices.visSectionObject,
                    (short)Visio.VisRowIndices.visRowPageLayout,
                    (short)Visio.VisCellIndices.visPLOPlaceStyle);

                layoutCell.set_Result(
                    Visio.VisUnitCodes.visPageUnits,
                    (double)Visio.VisCellVals.visPLOPlaceCompactDownRight);

                layoutCell = targetPage.PageSheet.get_CellsSRC(
                    (short)Visio.VisSectionIndices.visSectionObject,
                    (short)Visio.VisRowIndices.visRowPageLayout,
                    (short)Visio.VisCellIndices.visPLORouteStyle);

                layoutCell.set_Result(
                    Visio.VisUnitCodes.visPageUnits,
                    (double)Visio.VisCellVals.visLORouteOrgChartNS);

                targetPage.Layout();
                ////Program.selectionTree.Layout();

                Program.selectionTree.Group();

                Console.WriteLine("Print and save Visio doc if you want, then enter to quit (Visio will close).");
                Console.ReadLine();
            }
            finally
            {
                if (contentDocument != null)
                {
                    contentDocument.Saved = true;   // not really, but we can lie so the close/quit works.
                    contentDocument.Close();
                }

                if (app != null)
                {
                    app.Quit();
                }
            }
        }
Ejemplo n.º 9
0
        private void LoadVisioFile()
        {
            var filepath = m_visioFileTextBox.Text;

            Microsoft.Office.Interop.Visio.Application visio = null;
            Microsoft.Office.Interop.Visio.Document    doc   = null;
            try
            {
                if (!filepath.EndsWith(".vsd") || !System.IO.File.Exists(filepath))
                {
                    return;
                }

                m_lcStates = new List <string>();
                m_lcTrans  = new List <Pair>();

                visio = new Microsoft.Office.Interop.Visio.Application();
                doc   = visio.Documents.Open(filepath);
                var page = doc.Pages[1];

                var connectorMap = new Dictionary <string, ConnectorInfo>();

                foreach (Microsoft.Office.Interop.Visio.Shape shape in page.Shapes)
                {
                    if (shape.Name.StartsWith("Process"))
                    {
                        if (m_lcStates.Contains(shape.Text))
                        {
                            throw new Exception("Each state name must be unique.  " +
                                                "State " + shape.Text + " shows up multiple times.");
                        }

                        m_lcStates.Add(shape.Text);
                    }
                    else if (shape.Name.StartsWith("Dynamic connector"))
                    {
                        foreach (Connect connect in shape.Connects)
                        {
                            string fromName = connect.FromCell.Shape.Name;
                            string toText   = connect.ToCell.Shape.Text;

                            Cell endArrow   = connect.FromSheet.get_Cells("EndArrow");
                            Cell beginArrow = connect.FromSheet.get_Cells("BeginArrow");

                            ConnectorInfo info = null;
                            if (connectorMap.ContainsKey(fromName))
                            {
                                info = connectorMap[fromName];
                            }
                            else
                            {
                                info = new ConnectorInfo(fromName);
                                connectorMap.Add(fromName, info);
                            }
                            bool hasArrow = !beginArrow.Formula.StartsWith("THEME");
                            info.AddConnection(toText, hasArrow);
                        }
                    }
                }

                Dictionary <string, ConnectorInfo> .Enumerator enumerator = connectorMap.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    ConnectorInfo info = enumerator.Current.Value;

                    if (info.ShapeNames.Count != 2)
                    {
                        continue;
                    }

                    // the default connector
                    if (!info.HasArrows[0] && !info.HasArrows[1])
                    {
                        AddPair(new Pair(info.ShapeNames[0], info.ShapeNames[1]));
                    }

                    if (info.HasArrows[0])
                    {
                        AddPair(new Pair(info.ShapeNames[0], info.ShapeNames[1]));
                    }

                    // the arrow goes the other way too
                    if (info.HasArrows[1])
                    {
                        AddPair(new Pair(info.ShapeNames[1], info.ShapeNames[0]));
                    }
                }
            }
            catch (Exception e)
            {
                m_lcStates = null;
                m_lcTrans  = null;
                MessageBox.Show("Exception thrown: " + e.Message);
            }
            finally
            {
                if (doc != null)
                {
                    doc.Close();
                }

                if (visio != null)
                {
                    visio.Quit();
                }
            }
        }
Ejemplo n.º 10
0
        static int Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.Error.WriteLine("Invalid number of arguments.");
                Usage();
                return(3);
            }

            FileInfo sourceFileInfo = new FileInfo(args[0]);

            if (!sourceFileInfo.Exists)
            {
                Console.Error.WriteLine("Source file \"{0}\"doesn't exist.", sourceFileInfo.FullName);
                Usage();
                return(3);
            }

            string[] validExtensions = new string[] { ".vst", ".vsd" };
            if (!validExtensions.Contains(sourceFileInfo.Extension, StringComparer.InvariantCultureIgnoreCase))
            {
                Console.Error.WriteLine(String.Format("Source file extension must be one of: {0}", String.Join(", ", validExtensions)));
                Usage();
                return(3);
            }

            string referencePageNames = args[1];

            FileInfo targetFileInfo = new FileInfo(args[2]);

            if (targetFileInfo.Exists && targetFileInfo.IsReadOnly)
            {
                Console.Error.WriteLine("Target file exists and is readonly.");
                Usage();
                return(3);
            }
            if (!targetFileInfo.Directory.Exists)
            {
                Console.Error.WriteLine("Target file directory doesn't exist.");
                Usage();
                return(3);
            }
            if (!validExtensions.Contains(targetFileInfo.Extension, StringComparer.InvariantCultureIgnoreCase))
            {
                Console.Error.WriteLine(String.Format("Target file extension must be one of: {0}", String.Join(", ", validExtensions)));
                Usage();
                return(3);
            }
            if (String.Compare(sourceFileInfo.FullName, targetFileInfo.FullName, StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                Console.Error.WriteLine("Source and targer file are identical.");
                Usage();
                return(3);
            }

            string targetFile = targetFileInfo.FullName;

            File.Copy(sourceFileInfo.FullName, targetFile, true);
            File.SetAttributes(targetFile, FileAttributes.Normal);
            //Visio.Application visioApp = new Visio.Application(); // Visible Application
            Visio.InvisibleApp visioApp            = new Visio.InvisibleApp();
            Visio.Document     visioTargetDocument = visioApp.Documents.OpenEx(targetFile, (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visAddMacrosDisabled);

            Array pageNameArray;

            visioTargetDocument.Pages.GetNames(out pageNameArray);
            IList <string> pageNames = pageNameArray.Cast <string>().ToList();

            foreach (string referencePageName in referencePageNames.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                bool referencePageContained = pageNames.Remove(referencePageName);
                if (!referencePageContained)
                {
                    visioApp.Quit();
                    File.Delete(targetFile);
                    Console.Error.WriteLine(String.Format("ReferencePageName \"{0}\" not found in \"{1}\".", referencePageName, sourceFileInfo.FullName));
                    Usage();
                    return(3);
                }
            }

            foreach (string pageName in pageNames)
            {
                Visio.Page page = visioTargetDocument.Pages[pageName];
                page.Delete(1);
            }

            visioTargetDocument.Save();

            if (referencePageNames != "Template")
            {
                foreach (Visio.Page page in visioTargetDocument.Pages)
                {
                    foreach (Visio.Shape shape in page.Shapes)
                    {
                        if (shape.get_CellExists("User.StateChartType", (short)0) != 0)
                        {
                            string stateChartType = shape.Cells["User.StateChartType"].FormulaU;
                            if (stateChartType == "GUARD(0)")
                            {
                                Console.WriteLine("Name={0} NameID={1} NameU={2}", shape.Name, shape.NameID, shape.NameU);

                                shape.get_Cells("Prop.TargetFile").FormulaU = "";

                                Console.WriteLine("Prop.TargetFile Formula={0} Value={1}", shape.get_Cells("Prop.TargetFile").FormulaU, shape.get_Cells("Prop.TargetFile").get_ResultStrU((short)Visio.VisToParts.visNone));
                            }
                        }
                    }
                }
            }

            visioTargetDocument.Save();

            visioTargetDocument.Close();

            visioApp.Quit();

            Console.WriteLine(String.Format("File written to \"{0}\"", targetFileInfo.FullName));

            return(0);
        }
Ejemplo n.º 11
0
        private void generateVisio(Connection treeNode)
        {
            visapp = new IVisio.InvisibleApp();
            visapp.AlertResponse = 7; //autoAnswer NO on any alert
            visapp.Visible       = false;
            bool errorCatch = false;

            try
            {
                string _fileName = fileName.Text.Split('\\').Last();
                string _filePath = fileName.Text.Replace(_fileName, "");

                string templateFileName = Directory.GetCurrentDirectory() + "\\template.vss";
                string shapesFileName   = Directory.GetCurrentDirectory() + "\\shapes.vss";
                string newFullfileName  = _filePath + "\\result\\" + _fileName.Replace(".kml", ".vsd");

                if (!File.Exists(templateFileName))
                {
                    throw new Exception("Не найден шаблон выходного файла: " + templateFileName);
                }

                Directory.CreateDirectory(_filePath + "\\result\\");

                string caption  = "Поопорная схема ВЛ 0,4 кВ от ";
                string firstTmp = "";
                int    tpPos    = _fileName.IndexOf("ТП");
                if (tpPos >= 0)
                {
                    firstTmp = _fileName.Substring(tpPos, _fileName.Length - tpPos).Replace('_', '/').Replace(".kml", "");
                    string secondTmp = _fileName.Substring(0, tpPos - 1);
                    _fileName = firstTmp + " кВА " + secondTmp;
                }
                else
                {
                    throw new Exception("Не корректное название файла: " + fileName);
                }
                caption = caption + _fileName + " " + city.Text;

                IVisio.Document doc       = visapp.Documents.Open(templateFileName); // (short)IVisio.VisOpenSaveArgs.visAddHidden + (short)IVisio.VisOpenSaveArgs.visOpenNoWorkspace);
                IVisio.Document shapesDoc = visapp.Documents.Open(shapesFileName);   // (short)IVisio.VisOpenSaveArgs.visAddHidden + (short)IVisio.VisOpenSaveArgs.visOpenNoWorkspace);
                IVisio.Page     page      = doc.Pages[1];

                IVisio.Shape visioRectMaster = page.Shapes.get_ItemU("Sheet.1");
                visioRectMaster.Text = caption;

                visioRectMaster      = page.Shapes.get_ItemU("Sheet.509");
                visioRectMaster.Text = caption;

                visioRectMaster      = page.Shapes.get_ItemU("Sheet.496");
                visioRectMaster.Text = make.Text;

                visioRectMaster      = page.Shapes.get_ItemU("Sheet.508");
                visioRectMaster.Text = makeDate.Text;

                visioRectMaster      = page.Shapes.get_ItemU("Sheet.495");
                visioRectMaster.Text = chekedM.Text;

                visioRectMaster      = page.Shapes.get_ItemU("Sheet.507");
                visioRectMaster.Text = chekedDate.Text;

                int    pos2 = firstTmp.LastIndexOf('-');
                int    pos3 = firstTmp.LastIndexOf('/');
                string tmp2 = "?";
                if (pos2 != -1 & pos3 != -1 & pos3 > pos2)
                {
                    tmp2 = firstTmp.Substring(pos2 + 1, pos3 - pos2 - 1);
                }

                //visioRectMaster = page.Shapes.get_ItemU("Sheet.314");
                //visioRectMaster.Text = "РЛНД - " + tmp2;

                double newX = 5.9;
                double newY = 6.85;

                GenerateShapes(shapesDoc.Masters, ref page, mainNode, 0, newX, newY, firstTmp);

                doc.SaveAs(newFullfileName);
                doc.Close();
            }
            catch (Exception ex)
            {
                LogTextEvent(System.Drawing.Color.Red, ex.Message);
                errorCatch = true;
            }

            foreach (IVisio.Document aDoc in visapp.Documents)
            {
                aDoc.Close();
            }
            visapp.Quit();
            if (errorCatch)
            {
                throw new Exception("Ошибка формирвания выходного файла");
            }
        }