Ejemplo n.º 1
0
    private void CountPrimitivesOfFootprint()
    {
        OpenFileDialog openDialog = InitFileOpenDialog("PCBLIB");

        if (openDialog == null)
        {
            return;
        }

        string[] FootprintFiles = openDialog.FileNames;
        foreach (string FootprintFile in FootprintFiles)
        {
            System.Threading.Thread.Sleep(5000);

            IServerDocument PcbDocuemnt = OpenDocuemnt(FootprintFile, "PCBLIB");
            if (PcbDocuemnt == null)
            {
                DXP.Utils.ShowMessage("Failed to open " + FootprintFile);
                return;
            }

            IPCB_ServerInterface PcbServer = PCB.GlobalVars.PCBServer;
            IPCB_Library         PcbLib    = PcbServer.GetCurrentPCBLibrary();

            IPCB_Board currentBoard = PcbServer.GetCurrentPCBBoard();
            currentBoard.GraphicalView_ZoomRedraw();

            IPCB_LibraryIterator LibIteartor = PcbLib.LibraryIterator_Create();
            LibIteartor.AddFilter_ObjectSet(new PCB.TObjectSet(PCB.TObjectId.eComponentObject));
            IPCB_LibComponent PcbCmp = LibIteartor.FirstPCBObject() as IPCB_LibComponent;

            while (PcbCmp != null)
            {
                string FootprintDescription = PcbCmp.GetState_Description();
                string FootprintName        = PcbCmp.GetState_Pattern();

                IPCB_GroupIterator PcbObjItera = PcbCmp.GroupIterator_Create();
                int            count           = 0;
                IPCB_Primitive PcbObj          = PcbObjItera.FirstPCBObject();

                while (PcbObj != null)
                {
                    count++;
                    PcbObj = PcbObjItera.NextPCBObject();
                }

                PcbCmp.GroupIterator_Destroy(ref PcbObjItera);

                System.IO.File.AppendAllText(@"G:\report.txt", FootprintName + "|" + FootprintDescription + "|" + count.ToString() + "\r\n");

                PcbCmp = LibIteartor.NextPCBObject() as IPCB_LibComponent;
            }

            PcbLib.LibraryIterator_Destroy(ref LibIteartor);

            CloseDocument(PcbDocuemnt);
        }
    }
Ejemplo n.º 2
0
    IPCB_Primitive CreateTrack(double x1, double y1, double x2, double y2, TV6_Layer Layer)
    {
        IPCB_Primitive tmpPrim = PCBServer.PCBObjectFactory(TObjectId.eTrackObject, TDimensionKind.eNoDimension, TObjectCreationMode.eCreate_Default);
        IPCB_Track     track   = tmpPrim as IPCB_Track;

        track.SetState_X1(OffsetX + EDP.Utils.MilsToCoord(x1 - 4285));
        track.SetState_Y1(OffsetY + EDP.Utils.MilsToCoord(y1));
        track.SetState_X2(OffsetX + EDP.Utils.MilsToCoord(x2 - 4285));
        track.SetState_Y2(OffsetY + EDP.Utils.MilsToCoord(y2));

        track.SetState_Layer(Layer);
        track.SetState_Width(EDP.Utils.MilsToCoord(20));

        return(tmpPrim);
    }
Ejemplo n.º 3
0
    //Autogenerated code. End of implementation [GetState_Viagrid]

    //Autogenerated code. Begin of implementation [Command_Viagrid]
    public void Command_Viagrid(IServerDocumentView view, ref string parameters)
    {
        IPCB_ServerInterface pcbServer = PCB.GlobalVars.PCBServer;

        if (pcbServer == null)
        {
            return;
        }

        IPCB_Board pcbBoard = pcbServer.GetCurrentPCBBoard();

        if (pcbBoard == null)
        {
            return;
        }

        DXP.Utils.RunCommand("PCB:DeSelect", "Scope=All");

        var boundingRect = pcbBoard.GetState_BoardOutline().BoundingRectangle();
        var gridSize     = (int)pcbBoard.GetState_ComponentGridSize();
        var delta        = EDP.Utils.MMsToCoord(0.001);

        IPCB_BoardIterator iterator = pcbBoard.BoardIterator_Create();

        iterator.AddFilter_ObjectSet(new PCB.TObjectSet(PCB.TObjectId.eViaObject));
        iterator.AddFilter_LayerSet(PCBConstant.V6AllLayersSet);
        iterator.AddFilter_Area(boundingRect.Left, boundingRect.Bottom, boundingRect.Right, boundingRect.Top);

        IPCB_Primitive pcbObject = iterator.FirstPCBObject();

        while (pcbObject != null)
        {
            if (pcbObject is IPCB_Via via &&
                (via.GetState_XLocation() % gridSize > delta ||
                 via.GetState_XLocation() % gridSize > delta))
            {
                via.SetState_Selected(true);
            }
            pcbObject = iterator.NextPCBObject();
        }

        pcbBoard.BoardIterator_Destroy(ref iterator);

        DXP.Utils.RunCommand("PCB:RunQuery", "Apply=True|Expr=IsSelected|Mask=True|Select=True");
    }
Ejemplo n.º 4
0
    IPCB_Primitive CreateString(double x1, double y1, string Text, TV6_Layer Layer)
    {
        if (Text == null)
        {
            return(null);
        }
        IPCB_Primitive tmpPrim = PCBServer.PCBObjectFactory(TObjectId.eTextObject, TDimensionKind.eNoDimension, TObjectCreationMode.eCreate_Default);
        IPCB_Text      text    = tmpPrim as IPCB_Text;

        text.SetState_XLocation(OffsetX + EDP.Utils.MilsToCoord(x1 - 4285));
        text.SetState_YLocation(OffsetY + EDP.Utils.MilsToCoord(y1));
        text.SetState_Text(Text);
        text.SetState_FontID(2);
        text.SetState_Width(100000);
        text.SetState_Size(950000);

        text.SetState_Layer(Layer);

        return(tmpPrim);
    }
Ejemplo n.º 5
0
    //Autogenerated code. End of implementation [GetState_SetActiveLayer]

    //Autogenerated code. Begin of implementation [Command_SetActiveLayer]
    public void Command_SetActiveLayer(IServerDocumentView view, ref string parameters)
    {
        IPCB_Primitive obj   = null;
        IPCB_Board     board = Util.GetCurrentPCB();

        try
        {
            //If a object is already selected, Use it. If not, then get the object under the cursor.
            if (board.GetState_SelectecObjectCount() != 1)
            {
                obj = (IPCB_Primitive)board.GetObjectAtXYAskUserIfAmbiguous(board.GetState_XCursor(), board.GetState_YCursor(), Util.PCBAllObject, PCBConstant.V6AllLayersSet, TEditingAction.eEditAction_Focus);
            }
            if (obj == null)
            {
                obj = (IPCB_Primitive)board.GetLastClickedObject(Util.PCBAllObject, TEditingAction.eEditAction_Select);
            }
            else
            {
                obj = (IPCB_Primitive)board.GetState_SelectecObject(0);
            }

            if (obj == null)
            {
                return;
            }
            //Set the active layer to that of the selected object layer. Doesnt update the selected layer tab.
            board.SetState_CurrentLayerV7(obj.GetState_V7Layer());

            //Switch to the next layer and back so that the propper layer tab is selected.
            DXP.Utils.RunCommand("PCB:SetCurrentLayer", "LayerName = Next");
            DXP.Utils.RunCommand("PCB:SetCurrentLayer", "LayerName = Previous");

            //Switch to single layer mode.
            //DXP.Utils.RunCommand("PCB:SetupPreferences", "SingleLayerMode=ON");
        }
        catch (Exception ex)
        {
            ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex);
        }
    }
Ejemplo n.º 6
0
    /// <summary>
    /// Adds a new track to the PCB
    /// </summary>
    /// <param name="Offset"></param>
    /// <param name="argWidth"></param>
    private void AddTrack(structPos Offset, int argWidth)//, V7_Layer argLayer)
    {
        PCBServer = PCB.GlobalVars.PCBServer;
        if (Offset.x == null)
        {
            Offset.x = 0;
        }
        if (Offset.y == null)
        {
            Offset.y = 0;
        }

        int        xL, yL, xO, yO;
        IPCB_Board pcbBoard = Util.GetCurrentPCB();

        if (pcbBoard == null)
        {
            return;
        }

        System.Diagnostics.Debug.WriteLine(pcbBoard.GetState_DisplayUnit().ToString());



        TV6_Layer ActiveLayer = pcbBoard.GetState_CurrentLayer();

        int OriginX = pcbBoard.GetState_XOrigin();
        int OriginY = pcbBoard.GetState_YOrigin();

        PCBServer.PreProcess();

        // Set the value of J to point to the "next" vertex; this is normally
        // I + 1, but needs to be set to 0 instead for the very last vertex
        // that is processed by this loop.
        IPCB_Primitive primitive = PCBServer.PCBObjectFactory(TObjectId.eTrackObject, TDimensionKind.eNoDimension, TObjectCreationMode.eCreate_Default);

        if (primitive == null)
        {
            return;
        }
        IPCB_Track track = primitive as IPCB_Track;

        if (pcbBoard.GetState_DisplayUnit() == TUnit.eImperial)
        {
            xL       = EDP.Utils.MilsToCoord((double)LastPos.x);
            yL       = EDP.Utils.MilsToCoord((double)LastPos.y);
            xO       = EDP.Utils.MilsToCoord((double)Offset.x);
            yO       = EDP.Utils.MilsToCoord((double)Offset.y);
            argWidth = EDP.Utils.MilsToCoord((double)argWidth);
        }
        else
        {
            xL       = EDP.Utils.MMsToCoord((double)LastPos.x);
            yL       = EDP.Utils.MMsToCoord((double)LastPos.y);
            xO       = EDP.Utils.MMsToCoord((double)Offset.x);
            yO       = EDP.Utils.MMsToCoord((double)Offset.y);
            argWidth = EDP.Utils.MMsToCoord((double)argWidth);
        }

        if (Offset.absolute)
        {
            track.SetState_X1(OriginX + xL);
            track.SetState_Y1(OriginY + yL);
            track.SetState_X2(OriginX + xO);
            track.SetState_Y2(OriginY + yO);

            LastPos = Offset;
        }
        else
        {
            track.SetState_X1(OriginX + xL);
            track.SetState_Y1(OriginY + yL);
            track.SetState_X2(OriginX + (xL + xO));
            track.SetState_Y2(OriginY + (yL + yO));

            LastPos.x = LastPos.x + Offset.x;
            LastPos.y = LastPos.y + Offset.y;
        }

        track.SetState_Layer(ActiveLayer);
        track.SetState_Width(argWidth);
        pcbBoard.AddPCBObject(primitive);

        PCBServer.PostProcess();


        // Refresh PCB workspace.
        //DXP.Utils.RunCommand("PCB:Zoom", "Action=Redraw");
    }
Ejemplo n.º 7
0
    public void AssignNet()
    {
        IClient        tmpClient = DXP.GlobalVars.Client;
        IPCB_Primitive FirstObj = null;
        IPCB_Primitive SecondObj = null;
        IPCB_Board     board = Util.GetCurrentPCB();
        int            NewX = 0, NewY = 0;

        try
        {
            //If a object is already selected, Use it. If not, then get the object under the cursor.
            if (board.GetState_SelectecObjectCount() != 1)
            {
                FirstObj = (IPCB_Primitive)board.GetObjectAtXYAskUserIfAmbiguous(board.GetState_XCursor(), board.GetState_YCursor(), Util.PCBAllObject, PCBConstant.V6AllLayersSet, TEditingAction.eEditAction_Focus);
            }
            if (FirstObj == null)
            {
                FirstObj = (IPCB_Primitive)board.GetLastClickedObject(Util.PCBAllObject, TEditingAction.eEditAction_Select);
            }
            else
            {
                FirstObj = (IPCB_Primitive)board.GetState_SelectecObject(0);
            }

            if (FirstObj == null)
            {
                return;
            }

            board.ChooseLocation(ref NewX, ref NewY, "Select desired net.");
            if (NewX > 0 & NewY > 0)
            {
                SecondObj = (IPCB_Primitive)board.GetObjectAtXYAskUserIfAmbiguous(NewX, NewY, Util.PCBAllObject, PCBConstant.V6AllLayersSet, TEditingAction.eEditAction_Select);
            }

            if (SecondObj == null)
            {
                return;
            }

            if (SecondObj.GetState_Net() != null)
            {
#if DEBUG
                MessageBox.Show(SecondObj.GetState_Net().GetState_Name());
#endif
                FirstObj.BeginModify();
                FirstObj.SetState_Net(SecondObj.GetState_Net());
                FirstObj.EndModify();
            }

            if (FirstObj.GetState_ObjectID() == TObjectId.eSplitPlaneObject)
            {
                DXP.Utils.RunCommand("PCB:EditInternalPlanes", "RebuildPlane=All");
            }
            //PCB:EditInternalPlanes
            //RebuildPlane=All
        }
        catch (Exception ex)
        {
            ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex);
        }
    }
Ejemplo n.º 8
0
    private void CleanUpSamtecFootprints()
    {
        IPCB_ServerInterface PcbServer = PCB.GlobalVars.PCBServer;

        if (PcbServer == null)
        {
            return;
        }

        IPCB_Library PcbLib = PcbServer.GetCurrentPCBLibrary();

        if (PcbLib == null)
        {
            return;
        }

        IPCB_LibraryIterator LibIteartor = PcbLib.LibraryIterator_Create();

        LibIteartor.AddFilter_ObjectSet(new PCB.TObjectSet(PCB.TObjectId.eComponentObject));
        IPCB_LibComponent PcbCmp = LibIteartor.FirstPCBObject() as IPCB_LibComponent;

        PcbServer.PreProcess();

        while (PcbCmp != null)
        {
            IPCB_Board currentBoard = PcbServer.GetCurrentPCBBoard();      // heads up, PCB Ojbect can be added only by IPCB_Board, not IPCB_Component

            IPCB_GroupIterator PcbObjItera = PcbCmp.GroupIterator_Create();
            IPCB_Primitive     PcbObj      = PcbObjItera.FirstPCBObject();

            while (PcbObj != null)
            {
                switch (PcbObj.GetState_ObjectID())
                {
                case PCB.TObjectId.eTrackObject:
                    if ((int)PcbObj.GetState_V7Layer().ID != (int)new V7_Layer().Mechanical1().ID)
                    {
                        PcbObj = PcbObjItera.NextPCBObject();
                        continue;
                    }

                    IPCB_Track TrackObj = PcbObj as IPCB_Track;
                    TrackObj.SetState_Width(EDP.Utils.MMsToCoord((double)0.1));
                    TrackObj.SetState_Layer((int)new V7_Layer().Mechanical13().ID);
                    break;

                case PCB.TObjectId.eArcObject:
                    if ((int)PcbObj.GetState_V7Layer().ID != (int)new V7_Layer().Mechanical1().ID)
                    {
                        PcbObj = PcbObjItera.NextPCBObject();
                        continue;
                    }

                    IPCB_Arc ArcObj = PcbObj as IPCB_Arc;
                    ArcObj.SetState_LineWidth(EDP.Utils.MMsToCoord((double)0.1));
                    ArcObj.SetState_Layer((int)new V7_Layer().Mechanical13().ID);
                    break;

                case PCB.TObjectId.eComponentBodyObject:
                    IPCB_ComponentBody BodyObj = PcbObj as IPCB_ComponentBody;
                    BodyObj.SetState_Layer((int)new V7_Layer().Mechanical13().ID);
                    break;

                case PCB.TObjectId.eTextObject:
                    PcbCmp.RemovePCBObject(PcbObj);
                    break;
                }

                PcbObj = PcbObjItera.NextPCBObject();
            }

            PcbServer.PostProcess();
            DXP.Utils.RunCommand("PCB:Zoom", "Action=Redraw");

            PcbCmp.GroupIterator_Destroy(ref PcbObjItera);

            PcbCmp = LibIteartor.NextPCBObject() as IPCB_LibComponent;
        }

        PcbLib.LibraryIterator_Destroy(ref LibIteartor);
    }
Ejemplo n.º 9
0
    private void AddCourtyard()
    {
        IPCB_ServerInterface PcbServer = PCB.GlobalVars.PCBServer;

        if (PcbServer == null)
        {
            return;
        }

        IPCB_Library PcbLib = PcbServer.GetCurrentPCBLibrary();

        if (PcbLib == null)
        {
            return;
        }

        IPCB_LibraryIterator LibIteartor = PcbLib.LibraryIterator_Create();

        LibIteartor.AddFilter_ObjectSet(new PCB.TObjectSet(PCB.TObjectId.eComponentObject));
        IPCB_Component PcbCmp = LibIteartor.FirstPCBObject() as IPCB_Component;

        while (PcbCmp != null)
        {
            IPCB_Board currentBoard = PcbServer.GetCurrentPCBBoard();

            IPCB_GroupIterator PcbObjItera = PcbCmp.GroupIterator_Create();
            TV6_LayerSet       layers      = new TV6_LayerSet(TV6_Layer.eV6_BottomLayer, TV6_Layer.eV6_BottomOverlay, TV6_Layer.eV6_Mechanical13,
                                                              TV6_Layer.eV6_TopLayer, TV6_Layer.eV6_TopOverlay);
            PcbObjItera.AddFilter_LayerSet(layers);

            IPCB_Primitive PcbObj = PcbObjItera.FirstPCBObject();

            List <PrimitiveArea> Areas = new List <PrimitiveArea>();
            while (PcbObj != null)
            {
                PrimitiveArea ObjArea = new PrimitiveArea();

                switch (PcbObj.GetState_ObjectID())
                {
                case PCB.TObjectId.ePadObject:
                    ObjArea = CalPadArea(PcbObj as IPCB_Pad);
                    Areas.Add(ObjArea);
                    break;

                case PCB.TObjectId.eTrackObject:
                    ObjArea = CalTrackArea(PcbObj as IPCB_Track);
                    Areas.Add(ObjArea);
                    break;

                case PCB.TObjectId.eArcObject:
                    break;
                }

                PcbObj = PcbObjItera.NextPCBObject();
            }

            PrimitiveArea ComponentArea = CalComponentArea(Areas);
            DrawAreaAsCourtyard(ComponentArea, PcbServer, currentBoard);

            PcbCmp.GroupIterator_Destroy(ref PcbObjItera);

            PcbCmp = LibIteartor.NextPCBObject() as IPCB_Component;
        }

        PcbLib.LibraryIterator_Destroy(ref LibIteartor);
    }