Esempio n. 1
0
    /// <summary>
    /// Used to decode the text command provided by user.
    /// </summary>
    /// <param name="Cmd">Text command</param>
    /// <returns>Returns coord of command</returns>
    structPos DecodeCommand(string Cmd)
    {
        structPos Output = new structPos()
        {
            x = null, y = null, absolute = true
        };

        try
        {
            string[] CmdInfo = Cmd.Split(' ');
            if (CmdInfo.Length < 2)
            {
                return(new structPos()
                {
                    x = null, y = null
                });
            }

            if (CmdInfo[0].ToLower() == "iy" || CmdInfo[0].ToLower() == "y")
            {
                Output.y = Int32.Parse(CmdInfo[1]);
                if (CmdInfo.Length > 2)
                {
                    Output.x = Int32.Parse(CmdInfo[2]);
                }
            }
            else if (CmdInfo[0].ToLower() == "ix" || CmdInfo[0].ToLower() == "x")
            {
                Output.x = Int32.Parse(CmdInfo[1]);
                if (CmdInfo.Length > 2)
                {
                    Output.y = Int32.Parse(CmdInfo[2]);
                }
            }
            if (CmdInfo[0].ToLower() == "iy" || CmdInfo[0].ToLower() == "ix")
            {
                Output.absolute = false;
            }
            return(Output);
        }
        catch// (Exception e)
        {
            Output.x = null;
            Output.y = null;
            return(Output);
        }
    }
Esempio n. 2
0
    private void txtCmd_KeyPress(object sender, KeyPressEventArgs e)
    {
        structPos NewPos = new structPos()
        {
            x = null, y = null, absolute = true
        };

        if (e.KeyChar == (char)Keys.Enter)
        {
            if (txtCmd.Text.StartsWith("iy", StringComparison.CurrentCultureIgnoreCase) || txtCmd.Text.StartsWith("ix", StringComparison.CurrentCultureIgnoreCase) || txtCmd.Text.StartsWith("x", StringComparison.CurrentCultureIgnoreCase) || txtCmd.Text.StartsWith("y", StringComparison.CurrentCultureIgnoreCase))
            {
                if (LastPos.x == null && LastPos.y == null)
                {
                    LastPos = DecodeCommand(txtCmd.Text);
                    txtLog.AppendText("\n" + txtCmd.Text);
                    if (LastPos.x == null || LastPos.y == null)
                    {
                        txtLog.AppendText("\nIncorrect command format. (i.e. x 123 123)");
                        LastPos = new structPos()
                        {
                            x = null, y = null, absolute = true
                        };
                        return;
                    }
                    txtCmd.Text = "";
                }
                else
                {
                    NewPos = DecodeCommand(txtCmd.Text);
                    if (NewPos.x == null && NewPos.y == null)
                    {
                        txtLog.AppendText("\nIncorrect command format. (i.e. ix 123 123)");
                        return;
                    }
                    if ((NewPos.x == null || NewPos.y == null) && NewPos.absolute == true)
                    {
                        txtLog.AppendText("\nIncorrect command format. (i.e. x 123 123)");
                        NewPos = new structPos()
                        {
                            x = null, y = null, absolute = true
                        };
                        return;
                    }
                    if (NewPos.x == null)
                    {
                        NewPos.x = 0;
                    }
                    if (NewPos.y == null)
                    {
                        NewPos.y = 0;
                    }

                    txtLog.AppendText("\n" + txtCmd.Text);
                    txtCmd.Text = "";
                    AddTrack(NewPos, trackWidth);
                }
            }
            else if (txtCmd.Text.ToLower() == "new")
            {
                LastPos = new structPos()
                {
                    x = null, y = null, absolute = true
                };
                txtLog.AppendText("\nProvide first coord.");
                txtCmd.Text = "";
                return;
            }
            else if (txtCmd.Text.ToLower() == "help")
            {
                //txtLog.AppendText("\n");
                txtLog.AppendText(@"
Command options: 
Offset from last position
ix [x value] [y value] (Second value is optional.)
iy [y value] [x value] (Second value is optional.)
                                        
Absolute position:
x [x value] [y value]
y [y value] [x value]

Track width:
w [value]
                                        
Start a new line:
new
                                        
Help menu:
help");
                txtCmd.Text = "";
            }
            else if (txtCmd.Text.StartsWith("w", StringComparison.CurrentCultureIgnoreCase))
            {
                string[] CmdInfo = txtCmd.Text.Split(' ');
                if (CmdInfo.Length == 2)
                {
                    if (!Int32.TryParse(CmdInfo[1].ToLower(), out trackWidth))
                    {
                        txtLog.AppendText("\nUnable to determine value. Please try again. (i.e. w 10)");
                    }
                    txtLog.AppendText("\n" + txtCmd.Text);
                    txtCmd.Text = "";
                }
                else
                {
                    txtLog.AppendText("\nIncorrect command format. (i.e. w 10)");
                    txtCmd.Text = "";
                }
            }
            else
            {
                txtLog.AppendText("\nIncorrect command format. (i.e. ix 123 123)");
                return;
            }
        }
    }
Esempio n. 3
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");
    }