Skip to content

Commit

Permalink
stitchOnly format saving improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
redteam316 committed Feb 28, 2014
1 parent 096dc48 commit 01055eb
Show file tree
Hide file tree
Showing 19 changed files with 177 additions and 28 deletions.
14 changes: 14 additions & 0 deletions embroidermodder2/object-circle.cpp
Expand Up @@ -250,4 +250,18 @@ void CircleObject::gripEdit(const QPointF& before, const QPointF& after)
else { setObjectRadius(QLineF(objectCenter(), after).length()); }
}

QPainterPath CircleObject::objectSavePath() const
{
QPainterPath path;
QRectF r = rect();
path.arcMoveTo(r, 0);
path.arcTo(r, 0, 360);

qreal s = scale();
QTransform trans;
trans.rotate(rotation());
trans.scale(s,s);
return trans.map(path);
}

/* kate: bom off; indent-mode cstyle; indent-width 4; replace-trailing-space-save on; */
2 changes: 2 additions & 0 deletions embroidermodder2/object-circle.h
Expand Up @@ -13,6 +13,8 @@ class CircleObject : public BaseObject
enum { Type = OBJ_TYPE_CIRCLE };
virtual int type() const { return Type; }

QPainterPath objectSavePath() const;

QPointF objectCenter() const { return scenePos(); }
qreal objectCenterX() const { return scenePos().x(); }
qreal objectCenterY() const { return scenePos().y(); }
Expand Down
14 changes: 14 additions & 0 deletions embroidermodder2/object-ellipse.cpp
Expand Up @@ -298,4 +298,18 @@ void EllipseObject::gripEdit(const QPointF& before, const QPointF& after)
//TODO: gripEdit() for EllipseObject
}

QPainterPath EllipseObject::objectSavePath() const
{
QPainterPath path;
QRectF r = rect();
path.arcMoveTo(r, 0);
path.arcTo(r, 0, 360);

qreal s = scale();
QTransform trans;
trans.rotate(rotation());
trans.scale(s,s);
return trans.map(path);
}

/* kate: bom off; indent-mode cstyle; indent-width 4; replace-trailing-space-save on; */
2 changes: 2 additions & 0 deletions embroidermodder2/object-ellipse.h
Expand Up @@ -13,6 +13,8 @@ class EllipseObject : public BaseObject
enum { Type = OBJ_TYPE_ELLIPSE };
virtual int type() const { return Type; }

QPainterPath objectSavePath() const;

QPointF objectCenter() const { return scenePos(); }
qreal objectCenterX() const { return scenePos().x(); }
qreal objectCenterY() const { return scenePos().y(); }
Expand Down
7 changes: 7 additions & 0 deletions embroidermodder2/object-line.cpp
Expand Up @@ -222,4 +222,11 @@ void LineObject::gripEdit(const QPointF& before, const QPointF& after)
else if(before == objectMidPoint()) { QPointF delta = after-before; moveBy(delta.x(), delta.y()); }
}

QPainterPath LineObject::objectSavePath() const
{
QPainterPath path;
path.lineTo(objectDeltaX(), objectDeltaY());
return path;
}

/* kate: bom off; indent-mode cstyle; indent-width 4; replace-trailing-space-save on; */
2 changes: 2 additions & 0 deletions embroidermodder2/object-line.h
Expand Up @@ -13,6 +13,8 @@ class LineObject : public BaseObject
enum { Type = OBJ_TYPE_LINE };
virtual int type() const { return Type; }

QPainterPath objectSavePath() const;

QPointF objectEndPoint1() const { return scenePos(); }
QPointF objectEndPoint2() const;
QPointF objectMidPoint() const;
Expand Down
9 changes: 9 additions & 0 deletions embroidermodder2/object-path.cpp
Expand Up @@ -102,4 +102,13 @@ void PathObject::gripEdit(const QPointF& before, const QPointF& after)
//TODO: gripEdit() for PathObject
}

QPainterPath PathObject::objectSavePath() const
{
qreal s = scale();
QTransform trans;
trans.rotate(rotation());
trans.scale(s,s);
return trans.map(normalPath);
}

/* kate: bom off; indent-mode cstyle; indent-width 4; replace-trailing-space-save on; */
2 changes: 1 addition & 1 deletion embroidermodder2/object-path.h
Expand Up @@ -13,7 +13,7 @@ class PathObject : public BaseObject
enum { Type = OBJ_TYPE_PATH };
virtual int type() const { return Type; }

QPainterPath objectSavePath() const { return normalPath; }
QPainterPath objectSavePath() const;

QPointF objectPos() const { return scenePos(); }
qreal objectX() const { return scenePos().x(); }
Expand Down
7 changes: 7 additions & 0 deletions embroidermodder2/object-point.cpp
Expand Up @@ -102,4 +102,11 @@ void PointObject::gripEdit(const QPointF& before, const QPointF& after)
if(before == scenePos()) { QPointF delta = after-before; moveBy(delta.x(), delta.y()); }
}

QPainterPath PointObject::objectSavePath() const
{
QPainterPath path;
path.addRect(-0.00000001, -0.00000001, 0.00000002, 0.00000002);
return path;
}

/* kate: bom off; indent-mode cstyle; indent-width 4; replace-trailing-space-save on; */
2 changes: 2 additions & 0 deletions embroidermodder2/object-point.h
Expand Up @@ -13,6 +13,8 @@ class PointObject : public BaseObject
enum { Type = OBJ_TYPE_POINT };
virtual int type() const { return Type; }

QPainterPath objectSavePath() const;

QPointF objectPos() const { return scenePos(); }
qreal objectX() const { return scenePos().x(); }
qreal objectY() const { return scenePos().y(); }
Expand Down
11 changes: 11 additions & 0 deletions embroidermodder2/object-polygon.cpp
Expand Up @@ -255,4 +255,15 @@ void PolygonObject::gripEdit(const QPointF& before, const QPointF& after)
gripIndex = -1;
}

QPainterPath PolygonObject::objectSavePath() const
{
QPainterPath closedPath = normalPath;
closedPath.closeSubpath();
qreal s = scale();
QTransform trans;
trans.rotate(rotation());
trans.scale(s,s);
return trans.map(closedPath);
}

/* kate: bom off; indent-mode cstyle; indent-width 4; replace-trailing-space-save on; */
2 changes: 1 addition & 1 deletion embroidermodder2/object-polygon.h
Expand Up @@ -13,7 +13,7 @@ class PolygonObject : public BaseObject
enum { Type = OBJ_TYPE_POLYGON };
virtual int type() const { return Type; }

QPainterPath objectSavePath() const { return normalPath; }
QPainterPath objectSavePath() const;

QPointF objectPos() const { return scenePos(); }
qreal objectX() const { return scenePos().x(); }
Expand Down
9 changes: 9 additions & 0 deletions embroidermodder2/object-polyline.cpp
Expand Up @@ -234,4 +234,13 @@ void PolylineObject::gripEdit(const QPointF& before, const QPointF& after)
gripIndex = -1;
}

QPainterPath PolylineObject::objectSavePath() const
{
qreal s = scale();
QTransform trans;
trans.rotate(rotation());
trans.scale(s,s);
return trans.map(normalPath);
}

/* kate: bom off; indent-mode cstyle; indent-width 4; replace-trailing-space-save on; */
2 changes: 1 addition & 1 deletion embroidermodder2/object-polyline.h
Expand Up @@ -13,7 +13,7 @@ class PolylineObject : public BaseObject
enum { Type = OBJ_TYPE_POLYLINE };
virtual int type() const { return Type; }

QPainterPath objectSavePath() const { return normalPath; }
QPainterPath objectSavePath() const;

QPointF objectPos() const { return scenePos(); }
qreal objectX() const { return scenePos().x(); }
Expand Down
17 changes: 17 additions & 0 deletions embroidermodder2/object-rect.cpp
Expand Up @@ -232,4 +232,21 @@ void RectObject::gripEdit(const QPointF& before, const QPointF& after)
else if(before == objectBottomRight()) { setObjectRect(objectTopLeft().x(), objectTopLeft().y(), objectWidth()+delta.x(), objectHeight()+delta.y()); }
}

QPainterPath RectObject::objectSavePath() const
{
QPainterPath path;
QRectF r = rect();
path.moveTo(r.bottomLeft());
path.lineTo(r.bottomRight());
path.lineTo(r.topRight());
path.lineTo(r.topLeft());
path.lineTo(r.bottomLeft());

qreal s = scale();
QTransform trans;
trans.rotate(rotation());
trans.scale(s,s);
return trans.map(path);
}

/* kate: bom off; indent-mode cstyle; indent-width 4; replace-trailing-space-save on; */
2 changes: 2 additions & 0 deletions embroidermodder2/object-rect.h
Expand Up @@ -13,6 +13,8 @@ class RectObject : public BaseObject
enum { Type = OBJ_TYPE_RECTANGLE };
virtual int type() const { return Type; }

QPainterPath objectSavePath() const;

QPointF objectTopLeft() const;
QPointF objectTopRight() const;
QPointF objectBottomLeft() const;
Expand Down
44 changes: 20 additions & 24 deletions embroidermodder2/object-save.cpp
Expand Up @@ -7,6 +7,7 @@
#include "object-ellipse.h"
#include "object-line.h"
#include "object-point.h"
#include "object-polygon.h"
#include "object-polyline.h"
#include "object-rect.h"
#include "object-textsingle.h"
Expand Down Expand Up @@ -125,10 +126,8 @@ void SaveObject::addCircle(EmbPattern* pattern, QGraphicsItem* item)
{
if(formatType == EMBFORMAT_STITCHONLY)
{
QPainterPath path;
path.addEllipse(QPointF(0,0), obj->objectRadius(), obj->objectRadius());
path = path.simplified();
toPolyline(pattern, obj->objectCenter(), path, "0", obj->objectColor(), "CONTINUOUS", "BYLAYER"); //TODO: proper layer/lineType/lineWeight
QPainterPath path = obj->objectSavePath();
toPolyline(pattern, obj->objectCenter(), path.simplified(), "0", obj->objectColor(), "CONTINUOUS", "BYLAYER"); //TODO: proper layer/lineType/lineWeight //TODO: Improve precision, replace simplified
}
else
{
Expand Down Expand Up @@ -176,10 +175,8 @@ void SaveObject::addEllipse(EmbPattern* pattern, QGraphicsItem* item)
{
if(formatType == EMBFORMAT_STITCHONLY)
{
QPainterPath path;
path.addEllipse(QPointF(0,0), obj->objectWidth()/2.0, obj->objectHeight()/2.0);
path = path.simplified();
toPolyline(pattern, obj->objectCenter(), path, "0", obj->objectColor(), "CONTINUOUS", "BYLAYER"); //TODO: proper layer/lineType/lineWeight
QPainterPath path = obj->objectSavePath();
toPolyline(pattern, obj->objectCenter(), path.simplified(), "0", obj->objectColor(), "CONTINUOUS", "BYLAYER"); //TODO: proper layer/lineType/lineWeight //TODO: Improve precision, replace simplified
}
else
{
Expand Down Expand Up @@ -216,9 +213,7 @@ void SaveObject::addLine(EmbPattern* pattern, QGraphicsItem* item)
{
if(formatType == EMBFORMAT_STITCHONLY)
{
QPainterPath path;
path.lineTo(obj->objectDeltaX(), obj->objectDeltaY());
toPolyline(pattern, obj->objectEndPoint1(), path, "0", obj->objectColor(), "CONTINUOUS", "BYLAYER"); //TODO: proper layer/lineType/lineWeight
toPolyline(pattern, obj->objectEndPoint1(), obj->objectSavePath(), "0", obj->objectColor(), "CONTINUOUS", "BYLAYER"); //TODO: proper layer/lineType/lineWeight
}
else
{
Expand Down Expand Up @@ -282,9 +277,7 @@ void SaveObject::addPoint(EmbPattern* pattern, QGraphicsItem* item)
{
if(formatType == EMBFORMAT_STITCHONLY)
{
QPainterPath path;
path.addRect(-0.00000001, -0.00000001, 0.00000002, 0.00000002);
toPolyline(pattern, obj->objectPos(), path, "0", obj->objectColor(), "CONTINUOUS", "BYLAYER"); //TODO: proper layer/lineType/lineWeight
toPolyline(pattern, obj->objectPos(), obj->objectSavePath(), "0", obj->objectColor(), "CONTINUOUS", "BYLAYER"); //TODO: proper layer/lineType/lineWeight
}
else
{
Expand All @@ -295,14 +288,19 @@ void SaveObject::addPoint(EmbPattern* pattern, QGraphicsItem* item)

void SaveObject::addPolygon(EmbPattern* pattern, QGraphicsItem* item)
{
PolygonObject* obj = static_cast<PolygonObject*>(item);
if(obj)
{
toPolyline(pattern, obj->objectPos(), obj->objectSavePath(), "0", obj->objectColor(), "CONTINUOUS", "BYLAYER"); //TODO: proper layer/lineType/lineWeight
}
}

void SaveObject::addPolyline(EmbPattern* pattern, QGraphicsItem* item)
{
PolylineObject* obj = static_cast<PolylineObject*>(item);
if(obj)
{
toPolyline(pattern, obj->pos(), obj->objectSavePath(), "0", obj->objectColor(), "CONTINUOUS", "BYLAYER"); //TODO: proper layer/lineType/lineWeight
toPolyline(pattern, obj->objectPos(), obj->objectSavePath(), "0", obj->objectColor(), "CONTINUOUS", "BYLAYER"); //TODO: proper layer/lineType/lineWeight
}
}

Expand All @@ -317,10 +315,7 @@ void SaveObject::addRectangle(EmbPattern* pattern, QGraphicsItem* item)
{
if(formatType == EMBFORMAT_STITCHONLY)
{
//TODO: This needs work
QPainterPath path;
path.addRect(obj->objectTopLeft().x(), obj->objectTopLeft().y(), obj->objectWidth(), obj->objectHeight());
toPolyline(pattern, obj->objectTopLeft(), path, "0", obj->objectColor(), "CONTINUOUS", "BYLAYER"); //TODO: proper layer/lineType/lineWeight
toPolyline(pattern, obj->objectBottomLeft(), obj->objectSavePath(), "0", obj->objectColor(), "CONTINUOUS", "BYLAYER"); //TODO: proper layer/lineType/lineWeight
}
else
{
Expand Down Expand Up @@ -355,10 +350,11 @@ void SaveObject::addTextSingle(EmbPattern* pattern, QGraphicsItem* item)
{
if(formatType == EMBFORMAT_STITCHONLY)
{
QTransform transform;
transform.rotate(obj->rotation());
QPainterPath path = transform.map(obj->objectSavePath().simplified());
toPolyline(pattern, obj->objectPos(), path, "0", obj->objectColor(), "CONTINUOUS", "BYLAYER"); //TODO: proper layer/lineType/lineWeight
QList<QPainterPath> pathList = obj->objectSavePathList();
foreach(QPainterPath path, pathList)
{
toPolyline(pattern, obj->objectPos(), path.simplified(), "0", obj->objectColor(), "CONTINUOUS", "BYLAYER"); //TODO: proper layer/lineType/lineWeight //TODO: Improve precision, replace simplified
}
}
else
{
Expand All @@ -370,7 +366,7 @@ void SaveObject::addTextSingle(EmbPattern* pattern, QGraphicsItem* item)
//NOTE: This function should be used to interpret various object types and save them as polylines for stitchOnly formats.
void SaveObject::toPolyline(EmbPattern* pattern, const QPointF& objPos, const QPainterPath& objPath, const QString& layer, const QColor& color, const QString& lineType, const QString& lineWeight)
{
EmbPolylineObject* polyObject = (EmbPolylineObject*) malloc(sizeof(EmbPolylineObject));
EmbPolylineObject* polyObject = (EmbPolylineObject*)malloc(sizeof(EmbPolylineObject));
if(!polyObject) { } //TODO: error
polyObject->color = embColor_make(color.red(), color.green(), color.blue());
//polyObject->lineType = obj->type(); //TODO: This is wrong! type() is not lineType!
Expand Down
54 changes: 54 additions & 0 deletions embroidermodder2/object-textsingle.cpp
Expand Up @@ -299,4 +299,58 @@ void TextSingleObject::gripEdit(const QPointF& before, const QPointF& after)
if(before == scenePos()) { QPointF delta = after-before; moveBy(delta.x(), delta.y()); }
}

QList<QPainterPath> TextSingleObject::subPathList() const
{
qreal s = scale();
QTransform trans;
trans.rotate(rotation());
trans.scale(s,s);

QList<QPainterPath> pathList;

QPainterPath path = objTextPath;

QPainterPath::Element element;
QList<int> pathMoves;
int numMoves = 0;

for(int i = 0; i < path.elementCount(); i++)
{
element = path.elementAt(i);
if(element.isMoveTo())
{
pathMoves << i;
numMoves++;
}
}

pathMoves << path.elementCount();

for(int p = 0; p < pathMoves.size()-1 && p < numMoves; p++)
{
QPainterPath subPath;
for(int i = pathMoves.value(p); i < pathMoves.value(p+1); i++)
{
element = path.elementAt(i);
if(element.isMoveTo())
{
subPath.moveTo(element.x, element.y);
}
else if(element.isLineTo())
{
subPath.lineTo(element.x, element.y);
}
else if(element.isCurveTo())
{
subPath.cubicTo(path.elementAt(i ).x, path.elementAt(i ).y, //control point 1
path.elementAt(i+1).x, path.elementAt(i+1).y, //control point 2
path.elementAt(i+2).x, path.elementAt(i+2).y); //end point
}
}
pathList.append(trans.map(subPath));
}

return pathList;
}

/* kate: bom off; indent-mode cstyle; indent-width 4; replace-trailing-space-save on; */
3 changes: 2 additions & 1 deletion embroidermodder2/object-textsingle.h
Expand Up @@ -13,7 +13,8 @@ class TextSingleObject : public BaseObject
enum { Type = OBJ_TYPE_TEXTSINGLE };
virtual int type() const { return Type; }

QPainterPath objectSavePath() const { return objTextPath; }
QList<QPainterPath> objectSavePathList() const { return subPathList(); }
QList<QPainterPath> subPathList() const;

QString objectText() const { return objText; }
QString objectTextFont() const { return objTextFont; }
Expand Down

0 comments on commit 01055eb

Please sign in to comment.