39 #include <QMessageLogger>
40 #include <QPaintEngineState>
41 #include <QPainterPath>
48 #include "../vmisc/def.h"
49 #include "../vmisc/diagnostic.h"
50 #include "../vmisc/vmath.h"
52 #include "../vlayout/vlayoutpiece.h"
60 QT_WARNING_DISABLE_CLANG(
"-Wsign-conversion")
61 QT_WARNING_DISABLE_INTEL(68)
63 return QPaintEngine::PaintEngineFeatures(
64 QPaintEngine::AllFeatures
65 & ~QPaintEngine::PatternBrush
66 & ~QPaintEngine::PerspectiveTransform
67 & ~QPaintEngine::ConicalGradientFill
68 & ~QPaintEngine::PorterDuff);
77 , resolution(static_cast<int>(
PrintDPI))
79 , m_version(DRW::AC1014)
85 , textBuffer(new DRW_Text())
102 qWarning(
"VDxfEngine::begin(), the engine was alredy activated");
106 if (
size.isValid() ==
false)
108 qWarning()<<
"VDxfEngine::begin(), size is not valid";
113 input->AddQtLTypes();
114 input->AddDefLayers();
129 QPaintEngine::DirtyFlags flags = state.state();
132 flags |= QPaintEngine::AllDirty;
135 if (flags & QPaintEngine::DirtyTransform)
146 for (
int j=0; j < subpaths.size(); ++j)
148 const QPolygonF polygon = subpaths.at(j);
149 if (polygon.isEmpty())
156 DRW_LWPolyline *poly =
new DRW_LWPolyline();
159 poly->lWeight = DRW_LW_Conv::widthByLayer;
162 if (polygon.size() > 1 && polygon.first() == polygon.last())
169 for (
int i=0; i < polygon.count(); ++i)
175 input->AddEntity(poly);
179 DRW_Polyline *poly =
new DRW_Polyline();
182 poly->lWeight = DRW_LW_Conv::widthByLayer;
184 if (polygon.size() > 1 && polygon.first() == polygon.last())
191 for (
int i=0; i < polygon.count(); ++i)
197 input->AddEntity(poly);
205 for (
int i = 0; i < lineCount; ++i)
207 const QPointF p1 =
transform.map(lines[i].p1());
208 const QPointF p2 =
transform.map(lines[i].p2());
210 DRW_Line *line =
new DRW_Line();
217 line->lWeight = DRW_LW_Conv::widthByLayer;
220 input->AddEntity(line);
227 QPaintEngine::drawLines(lines, lineCount);
242 DRW_LWPolyline *poly =
new DRW_LWPolyline();
245 poly->lWeight = DRW_LW_Conv::widthByLayer;
248 if (pointCount > 1 && points[0] == points[pointCount])
255 for (
int i = 0; i < pointCount; ++i)
257 const QPointF p =
transform.map(points[i]);
262 input->AddEntity(poly);
266 DRW_Polyline *poly =
new DRW_Polyline();
269 poly->lWeight = DRW_LW_Conv::widthByLayer;
272 if (pointCount > 1 && points[0] == points[pointCount])
279 for (
int i = 0; i < pointCount; ++i)
281 const QPointF p =
transform.map(points[i]);
286 input->AddEntity(poly);
293 QPaintEngine::drawPolygon(points, pointCount, mode);
299 const QRectF newRect =
transform.mapRect(rect);
302 double majorX, majorY;
304 if(rect.width()<= rect.height())
306 majorX = (rect.top() - rect.center().y())*sin(rotationAngle)*
transform.m11()/cos(rotationAngle);
308 majorY = (rect.top() - rect.center().y())*
transform.m22();
310 ratio = rect.width()/rect.height();
314 majorX = (rect.right() - rect.center().x())*
transform.m11();
316 majorY = (rect.right() - rect.center().x())*sin(rotationAngle)*
transform.m22()/cos(rotationAngle);
318 ratio = rect.height()/rect.width();
321 DRW_Ellipse *ellipse =
new DRW_Ellipse();
325 ellipse->ratio = ratio;
326 ellipse->staparam = 0;
327 ellipse->endparam = 2*M_PI;
329 ellipse->layer =
"0";
331 ellipse->lWeight = DRW_LW_Conv::widthByLayer;
334 input->AddEntity(ellipse);
340 QPaintEngine::drawEllipse(rect);
348 const QPointF startPoint =
transform.map(p);
349 const double rotationAngle = qRadiansToDegrees(qAtan2(
transform.m12(),
transform.m11()));
351 const QFont f = textItem.font();
352 const UTF8STRING fontStyle =
input->AddFont(f);
365 textBuffer->lWeight = DRW_LW_Conv::widthByLayer;
371 QString t = textItem.text();
374 if (foundEndOfString)
381 if (foundEndOfString)
391 return QPaintEngine::User;
412 Q_ASSERT(not isActive());
425 Q_ASSERT(not isActive());
438 Q_ASSERT(not isActive());
451 Q_ASSERT(not isActive());
470 switch (state->pen().style())
476 case Qt::DashDotLine:
478 case Qt::DashDotDotLine:
489 QColor color = state->pen().color();
491 if(color == Qt::black)
495 else if(color == Qt::white)
499 else if(color == Qt::darkGray)
503 else if(color == Qt::gray)
507 else if(color == Qt::darkMagenta)
511 else if(color == Qt::magenta)
513 return DRW::l_magenta;
515 else if(color == Qt::cyan)
519 else if(color == Qt::darkCyan)
523 else if(color == Qt::blue)
527 else if(color == Qt::darkBlue)
531 else if(color == Qt::darkGreen)
535 else if(color == Qt::green)
539 else if(color == Qt::darkRed)
543 else if(color == Qt::red)
547 else if(color == Qt::yellow)
553 return DRW::ColorByLayer;
560 Q_ASSERT(not isActive());
567 Q_ASSERT(not isActive());
573 QT_WARNING_DISABLE_GCC(
"-Wswitch-default")
580 return pix / resolution * 25.4;
582 return pix / resolution * 25.4 / 10.0;
584 return pix / resolution;
609 if (
size.isValid() ==
false)
611 qWarning()<<
"VDxfEngine::begin(), size is not valid";
616 input->AddAAMAHeaderData();
619 input->AddDefLayers();
621 input->AddAAMALayers();
625 for(
int i = 0; i < details.size(); ++i)
631 QString blockName = detail.
GetName();
634 blockName.replace(
' ',
'_');
637 detailBlock->name = blockName.toStdString();
638 detailBlock->layer =
"1";
647 input->AddBlock(detailBlock);
649 DRW_Insert *insert =
new DRW_Insert();
650 insert->name = blockName.toStdString();
653 input->AddEntity(insert);
675 detailBlock->
ent.push_back(e);
688 detailBlock->
ent.push_back(e);
697 for(
int j = 0; j < drawIntCut.size(); ++j)
699 DRW_Entity *e =
AAMAPolygon(drawIntCut.at(j),
"8",
false);
702 detailBlock->
ent.push_back(e);
707 for(
int j = 0; j < drawIntCut.size(); ++j)
709 DRW_Entity *e =
AAMAPolygon(drawIntCut.at(j),
"11",
false);
712 detailBlock->
ent.push_back(e);
723 for(
int i = 0; i < notches.size(); ++i)
725 DRW_Entity *e =
AAMALine(notches.at(i),
"4");
728 detailBlock->
ent.push_back(e);
738 if (grainline.count() > 1)
740 DRW_Entity *e =
AAMALine(QLineF(grainline.first(), grainline.last()),
"7");
743 detailBlock->
ent.push_back(e);
754 for (
int i = 0; i < list.size(); ++i)
757 detailBlock->
ent.push_back(
AAMAText(pos, list.at(i),
"1"));
764 for(
int i = 0; i < details.size(); ++i)
766 const QStringList strings = details.at(i).GetPatternText();
767 if (not strings.isEmpty())
769 for (
int j = 0; j < strings.size(); ++j)
782 if (polygon.isEmpty())
789 return CreateAAMAPolygon<DRW_LWPolyline, DRW_Vertex2D>(polygon, layer, forceClosed);
793 return CreateAAMAPolygon<DRW_Polyline, DRW_Vertex>(polygon, layer, forceClosed);
800 DRW_Line *lineEnt =
new DRW_Line();
805 lineEnt->layer = layer.toStdString();
813 DRW_Text *textLine =
new DRW_Text();
820 textLine->layer = layer.toStdString();
821 textLine->text = text.toStdString();
827 template<
class P,
class V>
831 poly->layer = layer.toStdString();
839 if (polygon.size() > 1 && polygon.first() == polygon.last())
845 for (
int i=0; i < polygon.count(); ++i)
bool IsSeamAllowanceBuiltIn() const
bool IsSeamAllowance() const
bool isHideSeamLine() const
void setMeasurement(const VarMeasurement &var)
virtual bool begin(QPaintDevice *pdev) Q_DECL_OVERRIDE
QSharedPointer< dx_iface > input
virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) Q_DECL_OVERRIDE
virtual void drawLines(const QLineF *lines, int lineCount) Q_DECL_OVERRIDE
double getResolution() const
std::string getPenStyle()
QString getFileName() const
void ExportAAMAOutline(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail)
virtual void drawTextItem(const QPointF &p, const QTextItem &textItem) Q_DECL_OVERRIDE
Q_REQUIRED_RESULT DRW_Entity * AAMAText(const QPointF &pos, const QString &text, const QString &layer)
virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) Q_DECL_OVERRIDE
void ExportAAMAIntcut(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail)
virtual void drawEllipse(const QRectF &rect) Q_DECL_OVERRIDE
void ExportAAMAGlobalText(const QSharedPointer< dx_iface > &input, const QVector< VLayoutPiece > &details)
Q_REQUIRED_RESULT double FromPixel(double pix, const VarInsunits &unit) const
bool ExportToAAMA(const QVector< VLayoutPiece > &details)
bool IsBinaryFormat() const
void SetBinaryFormat(bool binary)
VarMeasurement varMeasurement
void setSize(const QSize &value)
virtual bool end() Q_DECL_OVERRIDE
void ExportAAMAGrainline(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail)
void ExportAAMANotch(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail)
Q_REQUIRED_RESULT DRW_Entity * AAMAPolygon(const QVector< QPointF > &polygon, const QString &layer, bool forceClosed)
DRW::Version GetVersion() const
void setResolution(double value)
void ExportAAMADraw(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail)
virtual void drawPath(const QPainterPath &path) Q_DECL_OVERRIDE
Q_REQUIRED_RESULT double ToPixel(double val, const VarInsunits &unit) const
Q_REQUIRED_RESULT P * CreateAAMAPolygon(const QVector< QPointF > &polygon, const QString &layer, bool forceClosed)
virtual void updateState(const QPaintEngineState &state) Q_DECL_OVERRIDE
void ExportAAMAText(dx_ifaceBlock *detailBlock, const VLayoutPiece &detail)
void setInsunits(const VarInsunits &var)
void SetVersion(DRW::Version version)
void setFileName(const QString &value)
virtual Type type() const Q_DECL_OVERRIDE
Q_REQUIRED_RESULT DRW_Entity * AAMALine(const QLineF &line, const QString &layer)
QStringList GetPieceText() const
QVector< QPointF > getContourPoints() const
QVector< QLineF > getNotches() const
QVector< QVector< QPointF > > InternalPathsForCut(bool cut) const
QVector< QPointF > GetSeamAllowancePoints() const
QPointF GetPieceTextPosition() const
QVector< QPointF > getGrainline() const
std::list< DRW_Entity * > ent
double FromPixel(double pix, const Unit &unit)
const QString endStringPlaceholder
static const qreal AAMATextHeight
static QPaintEngine::PaintEngineFeatures svgEngineFeatures()