示例#1
0
        public void BatchFixComponent(ref MGCPCB.Component _cellDoc)
        {
            List <Point> Points = new List <Point>();

            #region Point Motor Function

            //foreach ( FabricationLayerGfx gfx in _cellDoc.get_FabricationLayerGfxs(EPcbFabricationType.epcbFabSilkscreen) )
            //{
            //    if ( !gfx.Geometry.Filled )
            //    {
            //        gfx.Geometry.set_LineDisplayWidth(EPcbUnit.epcbUnitMils, SilkScreenLineWidth);
            //        gfx.Geometry.set_LineWidth(EPcbUnit.epcbUnitMils, SilkScreenLineWidth);
            //    }
            //}

            //foreach ( FabricationLayerText _txt in _cellDoc.get_FabricationLayerTexts(EPcbFabricationType.epcbFabSilkscreen) )
            //{
            //    //Console.WriteLine(_txt.TextString);
            //    if ( _txt.TextString == _cellDoc.RefDes )
            //    {
            //        //_txt.Format.set_Height(EPcbUnit.epcbUnitMils, SilkScreenRefDesHeight);
            //        //_txt.Format.set_PenWidth(EPcbUnit.epcbUnitMils, SilkScreenLineWidth);
            //        _txt.Format.Font = "VeriBest Gerber 0";
            //        _txt.Format.set_PenWidth(EPcbUnit.epcbUnitMils, SilkScreenLineWidth);
            //        _txt.Format.AspectRatio = 1;
            //    }
            //}

            double orientation = _cellDoc.get_Orientation(EPcbAngleUnit.epcbAngleUnitDegrees);
            //bool orientationChanged = false;

            _cellDoc.PlacementOutlines[1].Geometry.set_LineDisplayWidth(EPcbUnit.epcbUnitMils, 0);


            if (orientation % 90 != 0)
            {
                return;
            }

            foreach (FabricationLayerGfx gfx in _cellDoc.get_FabricationLayerGfxs(EPcbFabricationType.epcbFabAssembly))
            {
                gfx.Geometry.set_LineDisplayWidth(EPcbUnit.epcbUnitMils, AssemblyLineWidth);
                Points = ProcessGFX(gfx.Geometry, Points);
            }

            if (_cellDoc.get_FabricationLayerGfxs(EPcbFabricationType.epcbFabAssembly).Count < 1)
            {
                Points = ProcessGFX(_cellDoc.PlacementOutlines[1].Geometry, Points);
            }

            #endregion
            if (Points.Count > 1000)
            {
                Console.WriteLine("Not Processed: " + _cellDoc.Name);
                return;
            }

            #region rectangle find motor
            List <Rectangle> Rectangles = new List <Rectangle>();
            foreach (Point _point in Points)
            {
                if (_point.X != 0 || _point.Y != 0)
                {
                    foreach (Point _point2 in Points)
                    {
                        if (_point2.X != 0 && _point2.Y != 0)
                        {
                            if (_point.X != _point2.X && _point.Y != _point2.Y)
                            {
                                int minX = 0, maxX = 0;
                                int minY = 0, maxY = 0;

                                if (_point.X < _point2.X)
                                {
                                    minX = _point.X;
                                    maxX = _point2.X;
                                }
                                else
                                {
                                    minX = _point2.X;
                                    maxX = _point.X;
                                }
                                if (_point.Y < _point2.Y)
                                {
                                    minY = _point.Y;
                                    maxY = _point2.Y;
                                }
                                else
                                {
                                    minY = _point2.Y;
                                    maxY = _point.Y;
                                }

                                bool IsAcceptable = true;
                                #region Validate rectangle is free
                                foreach (Point _point3 in Points)
                                {
                                    if (minX < _point3.X && _point3.X < maxX)
                                    {
                                        if (minY < _point3.Y && _point3.Y < maxY)
                                        {
                                            IsAcceptable = false;
                                            break;
                                        }
                                    }
                                }
                                #endregion
                                if (IsAcceptable)
                                {
                                    Rectangles.Add(new Rectangle(minX, minY, maxX - minX, maxY - minY));
                                }
                            }
                        }
                    }
                }
            }

            Rectangle theBestRectangle = new Rectangle();
            foreach (Rectangle _rect in Rectangles)
            {
                int  area1       = _rect.Width * _rect.Height;
                bool greatisThis = true;
                foreach (Rectangle _rect2 in Rectangles)
                {
                    int area2 = _rect2.Width * _rect2.Height;
                    if (area2 > area1)
                    {
                        greatisThis = false;
                        break;
                    }
                }
                if (greatisThis)
                {
                    theBestRectangle = _rect;
                    break;
                }
            }
            #endregion
            #region Text Repair Engine

            double gfx_X1 = 0, gfx_X2 = 0, gfx_Y1 = 0, gfx_Y2 = 0;
            double centerpointX = 0;
            double centerpointY = 0;
            double width        = 0;
            double height       = 0;
            double text_height  = 0;

            gfx_X1 = theBestRectangle.X;
            gfx_X2 = theBestRectangle.X + theBestRectangle.Width;

            gfx_Y1 = theBestRectangle.Y;
            gfx_Y2 = theBestRectangle.Y + theBestRectangle.Height;

            width  = gfx_X2 - gfx_X1;
            height = gfx_Y2 - gfx_Y1;

            centerpointX = (gfx_X1 + gfx_X2) / 2;
            centerpointY = (gfx_Y1 + gfx_Y2) / 2;


            bool _90deg = false;
            if (height > width)
            {
                _90deg      = true;
                text_height = width - 10;
            }
            else
            {
                _90deg      = false;
                text_height = height - 10;
            }

            if (text_height > 100)
            {
                text_height = 100;
            }

            if (height > 5)
            {
                foreach (FabricationLayerText text in _cellDoc.get_FabricationLayerTexts(EPcbFabricationType.epcbFabAssembly))
                {
                    text.Format.Font = "vf_std";
                    text.Format.set_PenWidth(EPcbUnit.epcbUnitMils, TextLineWidth);
                    text.Format.AspectRatio = 1;
                    if (text.TextString == _cellDoc.RefDes)
                    {
                        text.set_PositionX(EPcbUnit.epcbUnitMils, centerpointX);
                        text.set_PositionY(EPcbUnit.epcbUnitMils, centerpointY);
                        if (_90deg)
                        {
                            text.Format.set_Orientation(EPcbAngleUnit.epcbAngleUnitDegrees, 90);
                        }
                        else
                        {
                            text.Format.set_Orientation(EPcbAngleUnit.epcbAngleUnitDegrees, 0);
                        }
                        text.Format.set_Height(EPcbUnit.epcbUnitMils, text_height);
                        text.Format.HorizontalJust = EPcbHorizontalJustification.epcbJustifyHCenter;
                        text.Format.VerticalJust   = EPcbVerticalJustification.epcbJustifyVCenter;
                        try
                        {
                            if (_90deg)
                            {
                                for ( ;;)
                                {
                                    Size s = TextRenderer.MeasureText(text.TextString, new Font("vf_std", (float)text_height));
                                    if (s.Width > height - 5 && text_height > 10)
                                    {
                                        text_height -= 5;
                                    }
                                    else
                                    {
                                        text.Format.set_Height(EPcbUnit.epcbUnitMils, text_height);
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                for ( ;;)
                                {
                                    Size s = TextRenderer.MeasureText(text.TextString, new Font("vf_std", (float)text_height));
                                    if (s.Width > width - 5 && text_height > 10)
                                    {
                                        text_height -= 5;
                                    }
                                    else
                                    {
                                        text.Format.set_Height(EPcbUnit.epcbUnitMils, text_height);
                                        break;
                                    }
                                }
                            }
                        }
                        catch (Exception m)
                        {
                            System.Windows.Forms.MessageBox.Show(m.Message);
                            throw m;
                        }
                    }
                    else
                    {
                        if (text.Format.get_Height(EPcbUnit.epcbUnitMils) > 25)
                        {
                            text.Format.set_Height(EPcbUnit.epcbUnitMils, 25);
                        }
                    }
                }
            }
            #endregion
            UserLayerTexts _texts = _cellDoc.get_UserLayerTexts(EPcbSelectionType.epcbSelectAll);
            foreach (UserLayerText _text in _texts)
            {
                _text.Format.set_PenWidth(EPcbUnit.epcbUnitMils, 2);
            }

            //if ( orientationChanged)
            //{
            //    _cellDoc.set_Orientation(EPcbAngleUnit.epcbAngleUnitDegrees, orientation);
            //}
        }
示例#2
0
文件: Form1.cs 项目: OGREAXE/XProbe
 //正向与 Mentor Expedition 交互
 //每次操作完整体数据后需要清空列表
 private void CrossProbe2xpedition(bool select)
 {
     if (crossProbeEnable == true)
     {
         //这里会反过去响应点击的事件,导致不循环
         //需要按正反向单独存放列表吗?
         for (int i = 0; i < listComps2xpedition.Count; i++)
         {
             _comp = pcbDoc.FindComponent(listComps2xpedition[i]);
             //_comp = pcbDoc.FindComponent("JA0V1");
             if (_comp != null)
             {
                 _comp.Selected    = select;
                 _comp.Highlighted = select;
             }
         }
         for (int i = 0; i < listNets2xpedition.Count; i++)
         {
             _net = pcbDoc.FindNet(listNets2xpedition[i]);
             if (_net != null)
             {
                 _net.Selected    = select;
                 _net.Highlighted = select;
             }
         }
         for (int i = 0; i < listPins2xpedition.Count; i++)
         {
             //如Pin脚为“R1-1”,则分为代表位号的“R1”和该位号的Pin脚号“1”
             string[]  _ref  = listPins2xpedition[i].Split('-');
             Component aComp = FindComponent(_ref[0]);
             if (aComp != null)
             {
                 _pin = aComp.FindPin(_ref[1]);
                 if (_pin != null)
                 {
                     _pin.Selected    = select;
                     _pin.Highlighted = select;
                 }
             }
         }
         //如果在布局模式下
         if (pcbApp.Gui.ActiveMode == EPcbMode.epcbModePlace)
         {
             //Todo Something
             if (fitSelectedEnable && select)
             {
                 pcbDoc.ActiveView.SetExtentsToSelection(true, false);
                 if (moveSelectedEnable)
                 {
                     //
                     pcbApp.Gui.ProcessCommand("Edit->Move", true);
                 }
                 else
                 {
                     //Nothing To Do ...
                 }
             }
             else
             {
                 //Nothing To Do ...
             }
         }
         else
         {
             if (fitSelectedEnable && select)
             {
                 pcbDoc.ActiveView.SetExtentsToSelection(true, false);
             }
             else
             {
                 //Nothing To Do ...
             }
         }
         //每次操作完整体数据后需要清空
         listComps2xpedition.Clear();
         listNets2xpedition.Clear();
         listPins2xpedition.Clear();
     }
     else
     {
         WriteLog(MsgSvr.Info, "正向操作交互已关闭 !");
         pcbDoc.UnSelectAll();
     }
 }