예제 #1
0
 private void DrawPin(Scene scene, Graphics g, SceneObjects.Pin p)
 {
     if (p.Side == scene.Side)
     {
         p.Draw(this, g);
     }
     else if (p.Inverse != null && p.Inverse.Side == scene.Side)
     {
         p.Inverse.Draw(this, g);
     }
 }
예제 #2
0
        private bool LoadBoardView(string fileName, IBoardViewFile bdv)
        {
            if (!bdv.Load(fileName))
            {
                GC.Collect();
                GC.WaitForFullGCComplete();
                return(false);
            }
            SetCurrentFilename(Path.GetFileName(fileName));
            Root.Scene.Reset();
            GC.Collect();
            GC.WaitForFullGCComplete();
            if (bdv.InchUnits) // convert to mils
            {
                for (int i = 0; i < bdv.TopContour.Count; i++)
                {
                    bdv.TopContour[i] *= 1000;
                }
                for (int i = 0; i < bdv.BottomContour.Count; i++)
                {
                    bdv.BottomContour[i] *= 1000;
                }
                for (int i = 0; i < bdv.Nails.Count; i++)
                {
                    bdv.Nails[i].Location *= 1000;
                }
                for (int i = 0; i < bdv.Pins.Count; i++)
                {
                    bdv.Pins[i].Location *= 1000;
                }
                // ?
                //bdv.InchUnits = false;
            }
            Root.Scene.TopContour    = new SceneObjects.Contour(bdv.TopContour);
            Root.Scene.BottomContour = new SceneObjects.Contour(bdv.BottomContour);
            for (int i = 0; i < bdv.Parts.Count; i++)
            {
                var src = bdv.Parts[i];
                // process part pins and update bbox
                int flipScale = src.Side == BoardSide.Top || !bdv.FlipBottomY ? +1 : -1;
                var p         = new SceneObjects.Part();
                p.Side     = src.Side;
                p.FirstPin = src.FirstPin;
                p.PinCount = src.PinCount;
                p.Name     = src.Name;
                var pinSides = p.Side;
                for (int j = src.FirstPin; j < src.FirstPin + src.PinCount; j++)
                {
                    var loc = bdv.Pins[j].Location;
                    loc.Y *= flipScale;
                    bdv.Pins[j].Location = loc;
                    var pin = new SceneObjects.Pin(p);
                    pin.SelfIndex = j;
                    pin.Net       = bdv.Pins[j].Net;
                    pin.Name      = bdv.Pins[j].Name;
                    pin.Location  = bdv.Pins[j].Location;
                    pin.Side      = bdv.Pins[j].Side;
                    if (bdv.Pins[j].Inverse != null)
                    {
                        var invSrc = bdv.Pins[j].Inverse;
                        var ipin   = new SceneObjects.Pin(p);
                        ipin.SelfIndex = j;
                        ipin.Net       = invSrc.Net;
                        ipin.Name      = invSrc.Name;
                        ipin.Location  = invSrc.Location;
                        ipin.Side      = invSrc.Side;
                        ipin.Inverse   = pin;
                        pin.Inverse    = ipin;
                        pinSides      |= ipin.Side;
                        if (ipin.Side == BoardSide.Top)
                        {
                            Root.Scene.TopObjectSpace.Insert(ipin);
                        }
                        if (ipin.Side == BoardSide.Bottom)
                        {
                            Root.Scene.BottomObjectSpace.Insert(ipin);
                        }
                    }
                    pinSides |= pin.Side;
                    Root.Scene.Pins.Add(pin);
                    if (pin.Side == BoardSide.Top)
                    {
                        Root.Scene.TopObjectSpace.Insert(pin);
                    }
                    if (pin.Side == BoardSide.Bottom)
                    {
                        Root.Scene.BottomObjectSpace.Insert(pin);
                    }
                }
                p.HasThroughHolePins = pinSides != p.Side;
                p.Update(CalculatePartBBox(p), CalculatePartOBB(p));
                Root.Scene.Parts.Add(p);
            }
            // process through-hole pins
            int pinCount = Root.Scene.Pins.Count;

            for (int i = 0; i < pinCount; i++)
            {
                if (Root.Scene.Pins[i].Inverse != null)
                {
                    Root.Scene.Pins.Add(Root.Scene.Pins[i].Inverse);
                }
            }
            for (int i = 0; i < bdv.Nails.Count; i++)
            {
                var src  = bdv.Nails[i];
                var nail = new SceneObjects.Nail();
                nail.Side = src.Side;
                nail.Net  = src.Net;
                nail.Name = src.Name;
                int flipScale = src.Side == BoardSide.Top || !bdv.FlipBottomY ? +1 : -1;
                var loc       = src.Location;
                loc.Y        *= flipScale;
                src.Location  = loc;
                nail.Location = loc;
                Root.Scene.Nails.Add(nail);
                if (src.Side == BoardSide.Top)
                {
                    Root.Scene.TopObjectSpace.Insert(nail);
                }
                if (src.Side == BoardSide.Bottom)
                {
                    Root.Scene.BottomObjectSpace.Insert(nail);
                }
            }
            // ?
            //Root.Scene.Options.FlipBottomY = bdv.FlipBottomY;
            return(true);
        }