Exemplo n.º 1
0
void embPattern_copyStitchListToPolylines(EmbPattern* p)
{
    EmbStitchList* stitches = 0;
    EmbPolylineObjectList* currentList = 0;

    if(!p) { embLog_error("emb-pattern.c embPattern_copyStitchListToPolylines(), p argument is null\n"); return; }
    stitches = p->stitchList;
    while(stitches)
    {
        EmbPointList* currentPointList = 0;
        EmbPolylineObject* currentPolyline = (EmbPolylineObject*)malloc(sizeof(EmbPolylineObject));
        if(!currentPolyline) { embLog_error("emb-pattern.c embPattern_copyStitchListToPolylines(), cannot allocate memory for currentPolyline\n"); return; }
        currentPolyline->pointList = 0;
        currentPolyline->lineType = 1; /* TODO: Determine what the correct value should be */
        currentPolyline->color = embThreadList_getAt(p->threadList, stitches->stitch.color).color;

        while(stitches)
        {
            if(stitches->stitch.flags & (STOP | TRIM))
            {
                break;
            }
            if(!(stitches->stitch.flags & JUMP))
            {
                if(!currentPointList)
                {
                    currentPointList = embPointList_create(stitches->stitch.xx, stitches->stitch.yy);
                    currentPolyline->pointList = currentPointList;
                }
                else
                {
                    currentPointList = embPointList_add(currentPointList, embPoint_make(stitches->stitch.xx, stitches->stitch.yy));
                }
            }
            stitches = stitches->next;
        }
        currentPointList = 0;
        if(!currentList)
        {
            currentList = embPolylineObjectList_create(currentPolyline);
            p->polylineObjList = currentList;
        }
        else
        {
            currentList = embPolylineObjectList_add(currentList, currentPolyline);
        }
        if(stitches && stitches->next)
        {
            stitches = stitches->next;
        }
    }
}
Exemplo n.º 2
0
/* TODO: It doesn't appear that this function actually clears the stitchList so it is more of a copy than a move. */
void moveStitchListToPolyline(EmbPattern* p)
{
    /* TODO: pointer safety */
    EmbStitchList* stitches = p->stitchList;
    EmbPolylineObjectList* currentList = 0;
    while(stitches)
    {
        EmbPointList* currentPointList = 0;
        EmbPolylineObject* currentPolyline = (EmbPolylineObject*)malloc(sizeof(EmbPolylineObject));
        /* TODO: malloc fail error */
        currentPolyline->pointList = 0;
        currentPolyline->lineType = 1; /* TODO: Determine what the correct value should be */
        currentPolyline->color = embThreadList_getAt(p->threadList, stitches->stitch.color).color;

        while(stitches)
        {
            if(stitches->stitch.flags & (STOP | TRIM))
            {
                break;
            }
            if(!(stitches->stitch.flags & JUMP))
            {
                if(!currentPointList)
                {
                    currentPointList = embPointList_create(stitches->stitch.xx, stitches->stitch.yy);
                    currentPolyline->pointList = currentPointList;
                }
                else
                {
                    currentPointList = embPointList_add(currentPointList, embPoint_make(stitches->stitch.xx, stitches->stitch.yy));
                }
            }
            stitches = stitches->next;
        }
        currentPointList = 0;
        if(!currentList)
        {
            currentList = embPolylineObjectList_create(currentPolyline);
            p->polylineObjList = currentList;
        }
        else
        {
            currentList = embPolylineObjectList_add(currentList, currentPolyline);
        }
        if(stitches && stitches->next)
        {
            stitches = stitches->next;
        }
    }
}
Exemplo n.º 3
0
/*! Copies all of the EmbStitchList data to EmbPolylineObjectList data for pattern (\a p). */
void embPattern_copyStitchListToPolylines(EmbPattern* p)
{
    EmbStitchList* stList = 0;
    int breakAtFlags;

    if(!p) { embLog_error("emb-pattern.c embPattern_copyStitchListToPolylines(), p argument is null\n"); return; }

#ifdef EMB_DEBUG_JUMP
    breakAtFlags = (STOP | TRIM);
#else /* EMB_DEBUG_JUMP */
    breakAtFlags = (STOP | JUMP | TRIM);
#endif /* EMB_DEBUG_JUMP */

    stList = p->stitchList;
    while(stList)
    {
        EmbPointList* pointList = 0;
        EmbPointList* lastPoint = 0;
        EmbColor color;
        while(stList)
        {
            if(stList->stitch.flags & breakAtFlags)
            {
                break;
            }
            if(!(stList->stitch.flags & JUMP))
            {
                if(!pointList)
                {
                    pointList = lastPoint = embPointList_create(stList->stitch.xx, stList->stitch.yy);
                    color = embThreadList_getAt(p->threadList, stList->stitch.color).color;
                }
                else
                {
                    lastPoint = embPointList_add(lastPoint, embPoint_make(stList->stitch.xx, stList->stitch.yy));
                }
            }
            stList = stList->next;
        }

        /* NOTE: Ensure empty polylines are not created. This is critical. */
        if(pointList)
        {
            EmbPolylineObject* currentPolyline = (EmbPolylineObject*)malloc(sizeof(EmbPolylineObject));
            if(!currentPolyline) { embLog_error("emb-pattern.c embPattern_copyStitchListToPolylines(), cannot allocate memory for currentPolyline\n"); return; }
            currentPolyline->pointList = pointList;
            currentPolyline->color = color;
            currentPolyline->lineType = 1; /* TODO: Determine what the correct value should be */

            if(embPolylineObjectList_empty(p->polylineObjList))
            {
                p->polylineObjList = p->lastPolylineObj = embPolylineObjectList_create(currentPolyline);
            }
            else
            {
                p->lastPolylineObj = embPolylineObjectList_add(p->lastPolylineObj, currentPolyline);
            }
        }
        if(stList)
        {
            stList = stList->next;
        }
    }
}