Ejemplo n.º 1
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");
    }