⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 draw.c

📁 CNC.rar
💻 C
📖 第 1 页 / 共 3 页
字号:
    //
    g_ulZSpeed = ulSpeed;
    g_ulZAccel = ulAccel;
}

//*****************************************************************************
//
//! Draws the text in a string on the table.
//!
//! \param lX is the X position, in steps, of the lower left hand corner of the
//! box to contain the drawn text.
//! \param lY is the Y position, in steps, of the lower left hand corner of the
//! box to contain the drawn text.
//! \param lZ is the Z position, in steps, of the tool traversal plane.
//! \param pcString is a pointer to the string to be drawn.
//! \param lHeight is the height, in steps, of the text to be drawn.  The
//! height is specified as the height of an upper case letter (i.e. lower case
//! letters with a descender will extend below the given Y coordinate).
//! \param lDepth is the depth, in steps, to which the tool is lowered in order
//! to draw.
//!
//! This function will draw the text from a string onto the work piece using a
//! Hershey Simplex Roman vector font (simplex meaning there is only one stroke
//! per line segment in each characters).  The text is drawn along the positive
//! X axis, with the top of the character being in the positive Y direction and
//! and any possible descender being in the negative Y direction.
//!
//! Traversal occurs at the the specified Z position, and drawing occurs at the
//! specified depth from Z position.  For tools such as a pen, the depth should
//! be the number of steps from the traversal plane to the work surface plane.
//! For tools such as a router, the depth should be the number of steps from
//! the traversal plane to the work surface plane plus the number of steps into
//! the work surface that the tool should descend (multiple passes can be made
//! with increasing depths to route further into the work piece than can be
//! done in a single pass).
//!
//! \return The width, in steps, of the text drawn on the table.
//
//*****************************************************************************
long
DrawString(long lX, long lY, long lZ, char *pcString, long lHeight,
           long lDepth)
{
    long lDX, lDY, lOldZ, lOldX, lNewX, lNewY;
    const signed char *pcChar;
    unsigned long ulIdx;
    tBoolean bUp;

    //
    // Get the current table position.  The Z value is the one really needed so
    // that the first jog can be done in the current Z plane and the remaining
    // jogs can be done in the traversal Z plane.
    //
    TableGetPosition(&lDX, &lDY, &lOldZ);

    //
    // The tool is in the up position.
    //
    bUp = true;

    //
    // Save the starting X position for use in determining the width of the
    // drawn string.
    //
    lOldX = lX;

    //
    // Loop over the characters in the string.
    //
    for(; *pcString; pcString++)
    {
        //
        // Get the vector data for this character.
        //
        pcChar = (signed char *)g_ppcFont[*pcString - ' '];

        //
        // The initial deltas are zero.
        //
        lDX = 0;
        lDY = 0;

        //
        // Loop over the coordinate pairs in the vector data for this
        // character.
        //
        for(ulIdx = 0; ulIdx < pcChar[0]; ulIdx++)
        {
            //
            // Get the X and Y value of the new coordinate.
            //
            lNewX = pcChar[(ulIdx * 2) + 2];
            lNewY = pcChar[(ulIdx * 2) + 3];

            //
            // See if the new coordinate pair is (-1, -1), indicating that the
            // tool should be lifted for the next movement.
            //
            if((lNewX == -1) && (lNewY == -1))
            {
                //
                // Move the tool up into the traversal plane.
                //
                TableMoveLine(lX + lDX, lY + lDY, lZ, g_ulZSpeed, g_ulZAccel);

                //
                // Indicate that the tool is up.
                //
                bUp = true;
            }
            else
            {
                //
                // Scale the X and Y coordinates to the requested size.
                //
                lDX = (lNewX * lHeight) / 21;
                lDY = (lNewY * lHeight) / 21;

                //
                // See if the tool is up.
                //
                if(bUp)
                {
                    //
                    // The tool is up, so traverse to the new position with the
                    // tool still up.
                    //
                    TableMoveLine(lX + lDX, lY + lDY, lOldZ, g_ulTraverseSpeed,
                                  g_ulTraverseAccel);

                    //
                    // Wait until the table is no longer moving.
                    //
                    while(TableIsMoving())
                    {
                    }

                    //
                    // Return if the drawing has been aborted.
                    //
                    if(!DrawIsDrawing())
                    {
                        return(lX - lOldX);
                    }

                    //
                    // Move the tool down into the drawing Z plane.
                    //
                    TableMoveLine(lX + lDX, lY + lDY, lZ + lDepth, g_ulZSpeed,
                                  g_ulZAccel);

                    //
                    // Set the old Z position to the traversal plane.  The
                    // first jog was done in the original Z plane, but all
                    // subsequent jogs are done in the traversal plane.
                    //
                    lOldZ = lZ;

                    //
                    // Indicate that the tool is down.
                    //
                    bUp = false;
                }
                else
                {
                    //
                    // The tool is down, so draw to the new position with the
                    // tool still down.
                    //
                    TableMoveLine(lX + lDX, lY + lDY, lZ + lDepth,
                                  g_ulDrawSpeed, g_ulDrawAccel);
                }
            }

            //
            // Wait until the table is no longer moving.
            //
            while(TableIsMoving())
            {
            }

            //
            // Return if the drawing has been aborted.
            //
            if(!DrawIsDrawing())
            {
                return(lX - lOldX);
            }
        }

        //
        // See if the tool is down.
        //
        if(!bUp)
        {
            //
            // The tool is down, so move it up into the traversal Z plane.
            //
            TableMoveLine(lX + lDX, lY + lDY, lZ, g_ulZSpeed, g_ulZAccel);

            //
            // Wait until the table is no longer moving.
            //
            while(TableIsMoving())
            {
            }

            //
            // Return if the drawing has been aborted.
            //
            if(!DrawIsDrawing())
            {
                return(lX - lOldX);
            }

            //
            // Indicate that the tool is up.
            //
            bUp = true;
        }

        //
        // Increment the base X coordinate by the width of this character.
        //
        lX += (pcChar[1] * lHeight) / 21;
    }

    //
    // Return the width of the entire string as drawn.
    //
    return(lX - lOldX);
}

//*****************************************************************************
//
//! Determines the extents of a string.
//!
//! \param pcString is a pointer to the string to query.
//! \param lHeight is the height, in steps, that the text would be drawn.  The
//! height is specified as the height of an upper case letter (i.e. lower case
//! letters with a descender will extend below the specified height).
//! \param plXMax is a pointer to a long that will be filled in with the width
//! of the string as drawn.
//! \param plYMin is a pointer to a long that will be filled in with the
//! minimum Y value that would be drawn, based on a Y baseline of zero.
//! \param plYMax is a pointer to a long that will be filled in with the
//! maximum Y value that would be drawn, based on a Y baseline of zero.
//!
//! This function determines the extents of a string once drawn onto the table.
//! The X and Y coordinate of the lower left corner of the string (i.e. the
//! starting point) is assumed to be (0, 0), and all other values are given
//! relative to that point.  Since the X axis will never be less than the X
//! starting point, the maximum X value is provided.  Because of descenders,
//! the minimum Y value may be less than zero; therefore both the minimum and
//! maximum Y values are provided.
//!
//! \return None.
//
//*****************************************************************************
void
DrawGetStringSize(char *pcString, long lHeight, long *plXMax, long *plYMin,
                  long *plYMax)
{
    long lXMax, lYMin, lYMax, lX, lDX, lDY;
    const signed char *pcChar;
    unsigned long ulIdx;

    //
    // Set the minimum and maximum value to zero.
    //
    lXMax = 0;
    lYMin = 0;
    lYMax = 0;

    //
    // Set the starting X coordinate to zero.
    //
    lX = 0;

    //
    // Loop over the characters in the string.
    //
    for(; *pcString; pcString++)
    {
        //
        // Get the vector data for this character.
        //
        pcChar = (signed char *)g_ppcFont[*pcString - ' '];

        //
        // Loop over the coordinate pairs in the vector data for this
        // character.
        //
        for(ulIdx = 0; ulIdx < pcChar[0]; ulIdx++)
        {
            //
            // Get the X and Y value of the new coordinate.
            //
            lDX = pcChar[(ulIdx * 2) + 2];
            lDY = pcChar[(ulIdx * 2) + 3];

            //
            // If this coordinate pair is (-1, -1), then skip to the next
            // coordinate pair.
            //
            if((lDX == -1) && (lDY == -1))
            {
                continue;
            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -