예제 #1
0
        static void Main(string[] args)
        {
            #region Instance Connection Code
            try
            {
                var clsid = Marshal.GetTypeFromCLSID(
                    new Guid("44983CB8-19B0-4695-937A-6FF0B74ECFC5")
                    );
                dynamic _server = Activator.CreateInstance(clsid);


                _server.SetEnvironment("");
                string VxVersion   = _server.sddVersion;
                string strSDD_HOME = _server.sddHome;
                int    length      = strSDD_HOME.IndexOf("SDD_HOME");
                strSDD_HOME = strSDD_HOME.Substring(0, length).Replace("\\", "\\\\") + "SDD_HOME";
                _server.SetEnvironment(strSDD_HOME);
                string progID = _server.ProgIDVersion;

                object[,] _releases = (object[, ])_server.GetInstalledReleases();
                dynamic pcbApp = null;

                for (int i = 1; i < _releases.Length / 4; i++)
                {
                    string _com_version = Convert.ToString(_releases[i, 0]);
                    try
                    {
                        pcbApp = Interaction.GetObject(null, "MGCPCB.Application." + _com_version);

                        pcbDoc = pcbApp.ActiveDocument;
                        dynamic licApp = Interaction.CreateObject("MGCPCBAutomationLicensing.Application." + _com_version);
                        int     _token = licApp.GetToken(pcbDoc.Validate(0));
                        pcbDoc.Validate(_token);

                        break;
                    }
                    catch (Exception m)
                    {
                    }
                }


                if (pcbApp == null)
                {
                    System.Windows.Forms.MessageBox.Show("Could not found active Xpedition or PADSPro Application");
                    System.Environment.Exit(1);
                }
            }
            catch (Exception m)
            {
                MessageBox.Show(m.Message + "\r\n" + m.Source + "\r\n" + m.StackTrace);
            }
            #endregion

            #region Work Code
            MGCSDDOUTPUTWINDOWLib.MGCSDDOutputLogControl msgWnd = null;
            MGCSDDOUTPUTWINDOWLib.HtmlCtrl _tabCtrl             = null;

            foreach (dynamic addin in (dynamic)pcbDoc.Application.Addins)
            {
                if (addin.Name == "Message Window")
                {
                    Console.WriteLine(addin.Control);
                    addin.Visible = true;
                    msgWnd        = addin.Control;
                }
            }

            if (msgWnd != null)
            {
                _tabCtrl = msgWnd.AddTab("Ref-Des Arranger");
                _tabCtrl.Clear();
                _tabCtrl.Activate();
            }

            var addText = new Action <string>(text =>
            {
                if (_tabCtrl != null)
                {
                    _tabCtrl.AppendText(text + "\r\n");
                }
            });

            var addHtml = new Action <string>(html =>
            {
                if (_tabCtrl != null)
                {
                    _tabCtrl.AppendHTML(html);
                }
            });



            addText("*THIS CODE IS A OPEN-SOURCE SOFTWARE UNDER MIT LICENSE");
            addText("*PROVIDED \"AS IS\" WITHOUT WARRANTY OF ANY KIND,");
            addText("*EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED");
            addText("*WARRANTIES OF MERCHANTABILITY AND / OR FITNESS FOR A PARTICULAR PURPOSE.");
            addText("");
            addHtml("<p style=\"{color: red; font-weight: bold;}\">Copyright 2008-2020; Milbitt Engineering. All rights reserved.<br />" +
                    "<a href=\"https://www.milbitt.com\">www.milbitt.com</a><br />" +
                    "<a href=\"mailto:[email protected]\">[email protected]</a></p>");
            // Everything is OK, then....
            System.Threading.Thread.Sleep(2000);

            MGCPCB.Components _comps = pcbDoc.get_Components(EPcbSelectionType.epcbSelectSelected);
            if (_comps.Count == 0)
            {
                pcbDoc.Application.Gui.StatusBarText("Select some components", EPcbStatusField.epcbStatusFieldError);
                addText("Error: Select some components");
                return;
            }

            pcbDoc.Application.Gui.ProgressBarInitialize(false, "", 0, 0);
            pcbDoc.Application.Gui.ProgressBarInitialize(true, "Starting Ref-Des Arranger", 100, 0);
            addText("Starting Ref-Des Arranger");

            try
            {
                pcbDoc.TransactionStart(EPcbDRCMode.epcbDRCModeNone);
                CellFixEngine _cfe = new CellFixEngine();
                Parallel.ForEach(pcbDoc.get_Components(EPcbSelectionType.epcbSelectSelected, EPcbComponentType.epcbCompAll, EPcbCelltype.epcbCelltypeAll).OfType <MGCPCB.Component>(),
                                 comp => {
                    addText(string.Format("Processing Part: {0}({1})", comp.RefDes, comp.CellName));
                    _cfe.BatchFixComponent(ref comp);
                }
                                 );
            }
            catch (Exception m)
            {
                addHtml("<p style=\"{color: red; font-weight: bold;}\">Error! " + m.Message + "<br/>" + m.Source + "<br/>" + m.StackTrace + "</p>");
            }
            finally
            {
                pcbDoc.TransactionEnd();
                pcbDoc.Application.Gui.ProgressBar(100);
                pcbDoc.Application.Gui.ProgressBarInitialize(false, "Ref-Des Arranger: Completed");
                addHtml("<p style=\"{color: #006600; font-weight: bold;}\">Operation Competed</p>");
                addText("");
                addHtml("<p style=\"{color: red; font-weight: bold;}\">Copyright 2008-2020; Milbitt Engineering. All rights reserved.<br />" +
                        "<a href=\"www.milbitt.com\">www.milbitt.com</a></p>");
                addText("");
            }
            #endregion
        }
예제 #2
0
파일: Form1.cs 프로젝트: OGREAXE/XProbe
        //反向与OrCAD交互,从 Xpedition ---> Capture
        void OnSelectionChange(EPcbOnSelectionType eType)
        {
            strComps = "";
            strNets  = "";
            strPins  = "";
            //从 OrCAD ---> Xpedition 选定交互的过程中有Slected操作
            //会同时调用该点击事件处理函数,因此必须检测是正向还是反向操作
            //在正向操作时给定值为True,处理完毕后再重新设定回默认反向操作
            if (bFromCapture2xpedition)
            {
                Console.WriteLine("点击原理图时又调用了一次该选定事件!");
                //bFromCapture2xpedition = false;
            }
            else
            {
                if (crossProbeEnable)
                {
                    //*
                    switch (pcbApp.Gui.ActiveMode)
                    {
                    case EPcbMode.epcbModeDrawing:
                        break;

                    case EPcbMode.epcbModeModeless:
                        compsCollection = pcbDoc.get_Components(EPcbSelectionType.epcbSelectSelected, EPcbComponentType.epcbCompGeneral, EPcbCelltype.epcbCelltypePackage, "");
                        netsCollection  = pcbDoc.get_Nets(EPcbSelectionType.epcbSelectSelected, true, "");
                        break;

                    case EPcbMode.epcbModePlace:
                        compsCollection = pcbDoc.get_Components(EPcbSelectionType.epcbSelectSelected, EPcbComponentType.epcbCompGeneral, EPcbCelltype.epcbCelltypePackage, "");
                        break;

                    case EPcbMode.epcbModeRF:
                        break;

                    case EPcbMode.epcbModeRoute:
                        netsCollection = pcbDoc.get_Nets(EPcbSelectionType.epcbSelectSelected, true, "");
                        pinsCollection = pcbDoc.get_Pins(EPcbSelectionType.epcbSelectSelected);
                        break;

                    default:
                        break;
                    }
                    //*/

                    if (compsCollection != null)
                    {
                        foreach (MGCPCB.Component comp in compsCollection)
                        {
                            listComps2capture.Add(comp.RefDes);
                            strComps += comp.RefDes + ",";
                        }
                    }
                    if (netsCollection != null)
                    {
                        foreach (MGCPCB.Net net in netsCollection)
                        {
                            listNets2capture.Add(net.Name);
                            strNets += net.Name + ",";
                        }
                    }
                    if (pinsCollection != null)
                    {
                        foreach (MGCPCB.Pin pin in pinsCollection)
                        {
                            listPins2capture.Add(pin.Component.RefDes + "-" + pin.Name);
                            strPins += pin.Component.RefDes + "-" + pin.Name + ",";
                        }
                    }
                    //以下代码供测试用,左侧调用后,清除集合内容(但是正向操作时选定操作会同时调用此过程?)
                    //同时检测crossProbeEnable选项是否打开,以判断是否对 CaptureCIS 原理图作操作
                    CrossProbe2capture();
                    //bFromCapture2xpedition = true;
                }
                else
                {
                    WriteLog(MsgSvr.Info, "反向操作交互已关闭 !");
                }
            }
        }