📄 draw.c
字号:
//
// Scale the X and Y coordinates to the requested size.
//
lDX = (lDX * lHeight) / 21;
lDY = (lDY * lHeight) / 21;
//
// If the X coordinate is greater than the current X maximum, then
// save it as the new X maximum.
//
if((lX + lDX) > lXMax)
{
lXMax = lX + lDX;
}
//
// If the Y coordinate is greater than the current Y maximum, then
// save it as the new Y maximum.
//
if(lDY > lYMax)
{
lYMax = lDY;
}
//
// If the Y coordinate is less than the current Y minumum, then
// save it as the new Y minimum.
//
if(lDY < lYMin)
{
lYMin = lDY;
}
}
//
// Increment X by the width of this character.
//
lX += (pcChar[1] * lHeight) / 21;
}
//
// Return the computed minimum and maximum values.
//
*plXMax = lXMax;
*plYMin = lYMin;
*plYMax = lYMax;
}
//*****************************************************************************
//
//! Draws a vector image on the table.
//!
//! \param lX is the X position, in steps, of the lower left hand corner of the
//! box to contain the vector image.
//! \param lY is the Y position, in steps, of the lower left hand corner of the
//! box to contain the vector image.
//! \param lZ is the Z position, in steps, of the tool traversal plane.
//! \param pusImage is a pointer to the vector image data.
//! \param lHeight is the height, in steps, of the vector image to be drawn.
//! \param lDepth is the depth, in steps, to which the tool is lowered in order
//! to draw.
//!
//! This function will draw a set of arbitrary vectors onto the table, which
//! typically combine to form a complete image (such as a logo). The base of
//! the image is drawn along the positive X axis, with the image extending in
//! the positive Y direction.
//!
//! The image data is organized as an array of unsigned 16-bit values. The
//! first entry in the array is the number of coordinate pairs in the image.
//! The second and third entries are the width and height, respectively, of the
//! image in whatever unit is appropriate to the creation of the image. The
//! remaining entries are X and Y coordinate pairs for the line segments that
//! make up the image; a value of (65535, 65535) indicates that the tool should
//! be raised before moving to the next coordinate pair.
//!
//! The points in the image data are specified in arbitrary coordinate units;
//! they are scaled to the desired size before being applied to the table. If,
//! for example, two images existed with one being 500 x 500 units, and the
//! other being 1000 x 1000 units, and both are drawn with the same \b lHeight
//! value, then both will be the same size when drawn despite the difference in
//! stored unit values.
//!
//! 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 image drawn on the table.
//
//*****************************************************************************
long
DrawImage(long lX, long lY, long lZ, const unsigned short *pusImage,
long lHeight, long lDepth)
{
long lDX, lDY, lOldZ;
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;
//
// The initial deltas are zero.
//
lDX = 0;
lDY = 0;
//
// Loop over the coordinate pairs in the vector data for this image.
//
for(ulIdx = 3; ulIdx < ((pusImage[0] * 2) + 3); ulIdx += 2)
{
//
// See if the new coordinate pair is (65535, 65535), indicating that
// the tool should be lifted for the next movement.
//
if((pusImage[ulIdx] == 0xffff) && (pusImage[ulIdx + 1] == 0xffff))
{
//
// 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 = (pusImage[ulIdx] * lHeight) / pusImage[2];
lDY = (pusImage[ulIdx + 1] * lHeight) / pusImage[2];
//
// 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((pusImage[1] * lHeight) / pusImage[2]);
}
//
// 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((pusImage[1] * lHeight) / pusImage[2]);
}
}
//
// 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 the width of the image as drawn.
//
return((pusImage[1] * lHeight) / pusImage[2]);
}
//*****************************************************************************
//
//! Determines the width of an image.
//!
//! \param pusImage is a pointer to the vector image data.
//! \param lHeight is the height, in steps, of the vector image as it would be
//! drawn.
//!
//! This function determines the width of an image if drawn at a particular
//! height. Since it is not possible to have negative coordinates in the image
//! data, the width is the only value that is unknown given a height.
//!
//! \return The width, in steps, of the image as it would be drawn on the
//! table.
//
//*****************************************************************************
long
DrawGetImageWidth(const unsigned short *pusImage, long lHeight)
{
//
// Return the width of the image.
//
return((pusImage[1] * lHeight) / pusImage[2]);
}
//*****************************************************************************
//
//! Initializes the drawing shape drawing routines.
//!
//! This function prepares the shape drawing routines for use. Default values
//! for the drawing, travere, and Z speed are selected; use DrawSetDrawSpeed(),
//! DrawSetTraverseSpeed(), and/or DrawSetZSpeed() to adjust the speeds as
//! required.
//!
//! \return None.
//
//*****************************************************************************
void
DrawInit(void)
{
//
// Clear the drawing flags.
//
g_ulDrawFlags = 0;
//
// Set default values for the drawing, traveral, and Z speeds.
//
g_ulDrawSpeed = 1200;
g_ulDrawAccel = 30000;
g_ulTraverseSpeed = 1200;
g_ulTraverseAccel = 30000;
g_ulZSpeed = 1200;
g_ulZAccel = 30000;
}
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -