DXF - Add some color

This commit is contained in:
David Varley
2020-09-22 19:41:47 +10:00
parent bcc5846662
commit 2d6bef71ae
3 changed files with 30 additions and 24 deletions

View File

@@ -437,9 +437,11 @@ int Createdxf::getcolorCode (const long red, const long green, const long blue)
} }
return minndx; return minndx;
} }
int Createdxf::dxfColor(QColor color) { int Createdxf::dxfColor(QColor color) {
return Createdxf::getcolorCode(color.red(), color.green(), color.blue()); return Createdxf::getcolorCode(color.red(), color.green(), color.blue());
} }
int Createdxf::dxfColor(QPen pen) { int Createdxf::dxfColor(QPen pen) {
return Createdxf::dxfColor(pen.color()); return Createdxf::dxfColor(pen.color());
} }
@@ -984,7 +986,13 @@ void Createdxf::drawPolygon(
const QPolygonF &poly, const QPolygonF &poly,
const int &colorcode) const int &colorcode)
{ {
drawPolyline(filepath,poly,colorcode); qDebug() << "PolygonIsClosed: " << poly.isClosed();
QPolygonF pg = poly;
if(!poly.isClosed()) {
pg << poly.at(0);
}
qDebug() << "PolygonIsClosed: " << poly.isClosed();
drawPolyline(filepath,pg,colorcode);
} }
/** /**

View File

@@ -660,7 +660,7 @@ void ExportDialog::generateDxf(
qreal offset = fontSize * 1.6; qreal offset = fontSize * 1.6;
foreach (QString line, lines) { foreach (QString line, lines) {
if (line.size() > 0 && line != "_" ) if (line.size() > 0 && line != "_" )
Createdxf::drawText(file_path, line, QPointF(x, y), fontSize, 360-angle, 0, 0.72 ); Createdxf::drawText(file_path, line, QPointF(x, y), fontSize, 360-angle, Createdxf::dxfColor(dti->color()), 0.72 );
x += offset * xdir; x += offset * xdir;
y -= offset * ydir; y -= offset * ydir;
} }

View File

@@ -965,30 +965,28 @@ bool QetShapeItem::toDXF(const QString &filepath,const QPen &pen)
switch (m_shapeType) switch (m_shapeType)
{ {
case Line: case Line:
Createdxf::drawLine(filepath, Createdxf::drawLine(filepath,
QLineF(mapToScene(m_P1), QLineF( mapToScene(m_P1),
mapToScene(m_P2)), mapToScene(m_P2)),
Createdxf::getcolorCode(pen.color().red(), Createdxf::dxfColor(pen));
pen.color().green(), return true;
pen.color().blue()));
return true;
case Rectangle: case Rectangle:
Createdxf::drawRectangle(filepath, Createdxf::drawRectangle(filepath,
QRectF(mapToScene(m_P1), QRectF(mapToScene(m_P1),
mapToScene(m_P2)).normalized(), mapToScene(m_P2)).normalized(),
Createdxf::getcolorCode(pen.color().red(), Createdxf::dxfColor(pen));
pen.color().green(), return true;
pen.color().blue()));
return true;
case Ellipse: case Ellipse:
Createdxf::drawEllipse (filepath, Createdxf::drawEllipse(filepath,
QRectF(mapToScene(m_P1), QRectF(mapToScene(m_P1),
mapToScene(m_P2)).normalized(), mapToScene(m_P2)).normalized(),
Createdxf::getcolorCode(pen.color().red(), Createdxf::dxfColor(pen));
pen.color().green(), return true;
pen.color().blue())); case Polygon:
return true; Createdxf::drawPolygon(filepath,m_polygon,Createdxf::dxfColor(pen));
default: return false; return true;
default:
return false;
} }
} }