Esempio n. 1
0
/*! Writes the data from \a pattern to a file with the given \a fileName.
 *  Returns \c true if successful, otherwise returns \c false. */
int writeExp(EmbPattern* pattern, const char* fileName)
{
#ifdef ARDUINO /* ARDUINO TODO: This is temporary. Remove when complete. */
return 0; /* ARDUINO TODO: This is temporary. Remove when complete. */
#else /* ARDUINO TODO: This is temporary. Remove when complete. */

    EmbFile* file = 0;
    EmbStitchList* stitches = 0;
    double dx = 0.0, dy = 0.0;
    double xx = 0.0, yy = 0.0;
    int flags = 0;
    unsigned char b[4];

    if(!pattern) { embLog_error("format-exp.c writeExp(), pattern argument is null\n"); return 0; }
    if(!fileName) { embLog_error("format-exp.c writeExp(), fileName argument is null\n"); return 0; }

    if(!embStitchList_count(pattern->stitchList))
    {
        embLog_error("format-exp.c writeExp(), pattern contains no stitches\n");
        return 0;
    }

    /* Check for an END stitch and add one if it is not present */
    if(pattern->lastStitch->stitch.flags != END)
        embPattern_addStitchRel(pattern, 0, 0, END, 1);

    file = embFile_open(fileName, "wb");
    if(!file)
    {
        embLog_error("format-exp.c writeExp(), cannot open %s for writing\n", fileName);
        return 0;
    }

    /* write stitches */
    stitches = pattern->stitchList;
    while(stitches)
    {
        dx = stitches->stitch.xx * 10.0 - xx;
        dy = stitches->stitch.yy * 10.0 - yy;
        xx = stitches->stitch.xx * 10.0;
        yy = stitches->stitch.yy * 10.0;
        flags = stitches->stitch.flags;
        expEncode(b, (char)roundDouble(dx), (char)roundDouble(dy), flags);
        if((b[0] == 128) && ((b[1] == 1) || (b[1] == 2) || (b[1] == 4)))
        {
            embFile_printf(file, "%c%c%c%c", b[0], b[1], b[2], b[3]);
        }
        else
        {
            embFile_printf(file, "%c%c", b[0], b[1]);
        }
        stitches = stitches->next;
    }
    embFile_printf(file, "\x1a");
    embFile_close(file);
    return 1;
#endif /* ARDUINO TODO: This is temporary. Remove when complete. */
}
Esempio n. 2
0
/*! Writes the data from \a pattern to a file with the given \a fileName.
 *  Returns \c true if successful, otherwise returns \c false. */
int writeKsm(EmbPattern* pattern, const char* fileName)
{
    EmbFile* file = 0; /* TODO: change writeKsm() to use EmbFile */
    EmbStitchList* pointer = 0;
    double xx = 0, yy = 0, dx = 0, dy = 0;
    int flags = 0;
    int i = 0;
    unsigned char b[4];

    if(!pattern) { embLog_error("format-ksm.c writeKsm(), pattern argument is null\n"); return 0; }
    if(!fileName) { embLog_error("format-ksm.c writeKsm(), fileName argument is null\n"); return 0; }

    if(!embStitchList_count(pattern->stitchList))
    {
        embLog_error("format-ksm.c writeKsm(), pattern contains no stitches\n");
        return 0;
    }

    /* Check for an END stitch and add one if it is not present */
    if(pattern->lastStitch->stitch.flags != END)
        embPattern_addStitchRel(pattern, 0, 0, END, 1);

    file = embFile_open(fileName, "wb");
    if(!file)
    {
        embLog_error("format-ksm.c writeKsm(), cannot open %s for writing\n", fileName);
        return 0;
    }
    for(i = 0; i < 0x80; i++)
    {
        binaryWriteInt(file, 0);
    }
    /* write stitches */
    xx = yy = 0;
    pointer = pattern->stitchList;
    while(pointer)
    {
        dx = pointer->stitch.xx - xx;
        dy = pointer->stitch.yy - yy;
        xx = pointer->stitch.xx;
        yy = pointer->stitch.yy;
        flags = pointer->stitch.flags;
        ksmEncode(b, (char)(dx * 10.0), (char)(dy * 10.0), flags);
        embFile_printf(file, "%c%c", b[0], b[1]);
        pointer = pointer->next;
    }
    embFile_printf(file, "\x1a");
    embFile_close(file);
    return 1;
}
Esempio n. 3
0
/*! Writes the data from \a pattern to a file with the given \a fileName.
 *  Returns \c true if successful, otherwise returns \c false. */
int writeCsv(EmbPattern* pattern, const char* fileName)
{
    EmbFile* file = 0;
    EmbStitchList* sList = 0;
    EmbThreadList* tList = 0;
    EmbRect boundingRect;
    int i = 0;
    int stitchCount = 0;
    int threadCount = 0;

    if(!pattern) { embLog_error("format-csv.c writeCsv(), pattern argument is null\n"); return 0; }
    if(!fileName) { embLog_error("format-csv.c writeCsv(), fileName argument is null\n"); return 0; }

    sList = pattern->stitchList;
    stitchCount = embStitchList_count(sList);

    tList = pattern->threadList;
    threadCount = embThreadList_count(tList);

    boundingRect = embPattern_calcBoundingBox(pattern);

    if(!stitchCount)
    {
        embLog_error("format-csv.c writeCsv(), pattern contains no stitches\n");
        return 0;
    }

    /* Check for an END stitch and add one if it is not present */
    if(pattern->lastStitch->stitch.flags != END)
    {
        embPattern_addStitchRel(pattern, 0, 0, END, 1);
        stitchCount++;
    }

    file = embFile_open(fileName, "w");
    if(!file)
    {
        embLog_error("format-csv.c writeCsv(), cannot open %s for writing\n", fileName);
        return 0;
    }

    /* write header */
    embFile_printf(file, "\"#\",\"Embroidermodder 2 CSV Embroidery File\"\n");
    embFile_printf(file, "\"#\",\"http://embroidermodder.github.io\"\n");
    embFile_printf(file, "\n");
    embFile_printf(file, "\"#\",\"General Notes:\"\n");
    embFile_printf(file, "\"#\",\"This file can be read by Excel or LibreOffice as CSV (Comma Separated Value) or with a text editor.\"\n");
    embFile_printf(file, "\"#\",\"Lines beginning with # are comments.\"\n");
    embFile_printf(file, "\"#\",\"Lines beginning with > are variables: [VAR_NAME], [VAR_VALUE]\"\n");
    embFile_printf(file, "\"#\",\"Lines beginning with $ are threads: [THREAD_NUMBER], [RED], [GREEN], [BLUE], [DESCRIPTION], [CATALOG_NUMBER]\"\n");
    embFile_printf(file, "\"#\",\"Lines beginning with * are stitch entries: [STITCH_TYPE], [X], [Y]\"\n");
    embFile_printf(file, "\n");
    embFile_printf(file, "\"#\",\"Stitch Entry Notes:\"\n");
    embFile_printf(file, "\"#\",\"STITCH instructs the machine to move to the position [X][Y] and then make a stitch.\"\n");
    embFile_printf(file, "\"#\",\"JUMP instructs the machine to move to the position [X][Y] without making a stitch.\"\n");
    embFile_printf(file, "\"#\",\"TRIM instructs the machine to cut the thread before moving to the position [X][Y] without making a stitch.\"\n");
    embFile_printf(file, "\"#\",\"COLOR instructs the machine to stop temporarily so that the user can change to a different color thread before resuming.\"\n");
    embFile_printf(file, "\"#\",\"END instructs the machine that the design is completed and there are no further instructions.\"\n");
    embFile_printf(file, "\"#\",\"UNKNOWN encompasses instructions that may not be supported currently.\"\n");
    embFile_printf(file, "\"#\",\"[X] and [Y] are absolute coordinates in millimeters (mm).\"\n");
    embFile_printf(file, "\n");

    /* write variables */
    embFile_printf(file,"\"#\",\"[VAR_NAME]\",\"[VAR_VALUE]\"\n");
    embFile_printf(file, "\">\",\"STITCH_COUNT:\",\"%u\"\n",   (unsigned int)stitchCount);
    embFile_printf(file, "\">\",\"THREAD_COUNT:\",\"%u\"\n",   (unsigned int)threadCount);
    embFile_printf(file, "\">\",\"EXTENTS_LEFT:\",\"%f\"\n",   boundingRect.left);
    embFile_printf(file, "\">\",\"EXTENTS_TOP:\",\"%f\"\n",    boundingRect.top);
    embFile_printf(file, "\">\",\"EXTENTS_RIGHT:\",\"%f\"\n",  boundingRect.right);
    embFile_printf(file, "\">\",\"EXTENTS_BOTTOM:\",\"%f\"\n", boundingRect.bottom);
    embFile_printf(file, "\">\",\"EXTENTS_WIDTH:\",\"%f\"\n",  embRect_width(boundingRect));
    embFile_printf(file, "\">\",\"EXTENTS_HEIGHT:\",\"%f\"\n", embRect_height(boundingRect));
    embFile_printf(file,"\n");

    /* write colors */
    embFile_printf(file, "\"#\",\"[THREAD_NUMBER]\",\"[RED]\",\"[GREEN]\",\"[BLUE]\",\"[DESCRIPTION]\",\"[CATALOG_NUMBER]\"\n");
    i = 1;
    while(tList)
    {
        embFile_printf(file, "\"$\",\"%d\",\"%d\",\"%d\",\"%d\",\"%s\",\"%s\"\n", i, /* TODO: fix segfault that backtraces here when libembroidery-convert from dst to csv. */
                (int)tList->thread.color.r,
                (int)tList->thread.color.g,
                (int)tList->thread.color.b,
                tList->thread.description,
                tList->thread.catalogNumber);
        i++;
        tList = tList->next;
    }
    embFile_printf(file, "\n");

    /* write stitches */
    embFile_printf(file, "\"#\",\"[STITCH_TYPE]\",\"[X]\",\"[Y]\"\n");
    while(sList)
    {
        EmbStitch s = sList->stitch;
        embFile_printf(file, "\"*\",\"%s\",\"%f\",\"%f\"\n", csvStitchFlagToStr(s.flags), s.xx, s.yy);
        sList = sList->next;
    }

    embFile_close(file);
    return 1;
}