Seamly2D
Code documentation
vdxfpaintdevice.cpp
Go to the documentation of this file.
1 /************************************************************************
2  **
3  ** @file vdxfpaintdevice.cpp
4  ** @author Valentina Zhuravska <zhuravska19(at)gmail.com>
5  ** @date 12 812, 2015
6  **
7  ** @brief
8  ** @copyright
9  ** This source code is part of the Valentine project, a pattern making
10  ** program, whose allow create and modeling patterns of clothing.
11  ** Copyright (C) 2013-2015 Seamly2D project
12  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
13  **
14  ** Seamly2D is free software: you can redistribute it and/or modify
15  ** it under the terms of the GNU General Public License as published by
16  ** the Free Software Foundation, either version 3 of the License, or
17  ** (at your option) any later version.
18  **
19  ** Seamly2D is distributed in the hope that it will be useful,
20  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  ** GNU General Public License for more details.
23  **
24  ** You should have received a copy of the GNU General Public License
25  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
26  **
27  *************************************************************************/
28 
29 #include "vdxfpaintdevice.h"
30 
31 #include <QMessageLogger>
32 #include <QtDebug>
33 
34 #include "vdxfengine.h"
35 
36  //---------------------------------------------------------------------------------------------------------------------
38  :QPaintDevice(), engine(new VDxfEngine()), fileName()
39 {
40 }
41 
42  //---------------------------------------------------------------------------------------------------------------------
44 {
45  delete engine;
46 }
47 
48  //---------------------------------------------------------------------------------------------------------------------
49  // cppcheck-suppress unusedFunction
50 QPaintEngine *VDxfPaintDevice::paintEngine() const
51 {
52  return engine;
53 }
54 
55  //---------------------------------------------------------------------------------------------------------------------
56  // cppcheck-suppress unusedFunction
58 {
59  return fileName;
60 }
61 
62  //---------------------------------------------------------------------------------------------------------------------
63 void VDxfPaintDevice::setFileName(const QString &value)
64 {
65  if (engine->isActive())
66  {
67  qWarning("VDxfPaintDevice::setFileName(), cannot set file name while Dxf is being generated");
68  return;
69  }
70 
71  fileName = value;
73 }
74 
75  //---------------------------------------------------------------------------------------------------------------------
77 {
78  return engine->getSize();
79 }
80 
81  //---------------------------------------------------------------------------------------------------------------------
82 void VDxfPaintDevice::setSize(const QSize &size)
83 {
84  if (engine->isActive())
85  {
86  qWarning("VDxfPaintDevice::setSize(), cannot set size while Dxf is being generated");
87  return;
88  }
89  engine->setSize(size);
90 }
91 
92  //---------------------------------------------------------------------------------------------------------------------
94 {
95  return engine->getResolution();
96 }
97 
98  //---------------------------------------------------------------------------------------------------------------------
100 {
101  if (engine->isActive())
102  {
103  qWarning("VDxfPaintDevice::setResolution(), cannot set dpi while Dxf is being generated");
104  return;
105  }
106  engine->setResolution(dpi);
107 }
108 
109 //---------------------------------------------------------------------------------------------------------------------
110 DRW::Version VDxfPaintDevice::GetVersion() const
111 {
112  return engine->GetVersion();
113 }
114 
115 //---------------------------------------------------------------------------------------------------------------------
116 void VDxfPaintDevice::SetVersion(DRW::Version version)
117 {
118  if (engine->isActive())
119  {
120  qWarning("VDxfPaintDevice::SetVersion(), cannot set version while Dxf is being generated");
121  return;
122  }
123  engine->SetVersion(version);
124 }
125 
126 //---------------------------------------------------------------------------------------------------------------------
128 {
129  if (engine->isActive())
130  {
131  qWarning("VDxfPaintDevice::SetBinaryFormat(), cannot set binary format while Dxf is being generated");
132  return;
133  }
134  engine->SetBinaryFormat(binary);
135 }
136 
137 //---------------------------------------------------------------------------------------------------------------------
139 {
140  return engine->IsBinaryFormat();
141 }
142 
143 //---------------------------------------------------------------------------------------------------------------------
145 {
146  if (engine->isActive())
147  {
148  qWarning("VDxfPaintDevice::setMeasurement(), cannot set measurements while Dxf is being generated");
149  return;
150  }
151  engine->setMeasurement(var);
152 }
153 
154 //---------------------------------------------------------------------------------------------------------------------
156 {
157  if (engine->isActive())
158  {
159  qWarning("VDxfPaintDevice::setInsunits(), cannot set units while Dxf is being generated");
160  return;
161  }
162  engine->setInsunits(var);
163 }
164 
165 //---------------------------------------------------------------------------------------------------------------------
167 {
168  engine->setActive(true);
169  const bool res = engine->ExportToAAMA(details);
170  engine->setActive(false);
171  return res;
172 }
173 
174  //---------------------------------------------------------------------------------------------------------------------
175 int VDxfPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const
176 {
177  switch (metric)
178  {
179  case QPaintDevice::PdmDepth:
180  return 32;
181  case QPaintDevice::PdmWidth:
182  return engine->getSize().width();
183  case QPaintDevice::PdmHeight:
184  return engine->getSize().height();
185  case QPaintDevice::PdmHeightMM:
186  return qRound(engine->getSize().height() * 25.4 / engine->getResolution());
187  case QPaintDevice::PdmWidthMM:
188  return qRound(engine->getSize().width() * 25.4 / engine->getResolution());
189  case QPaintDevice::PdmNumColors:
190  return static_cast<int>(0xffffffff);
191  case QPaintDevice::PdmPhysicalDpiX:
192  case QPaintDevice::PdmPhysicalDpiY:
193  case QPaintDevice::PdmDpiX:
194  case QPaintDevice::PdmDpiY:
195  return static_cast<int>(engine->getResolution());
196  case QPaintDevice::PdmDevicePixelRatio:
197  case QPaintDevice::PdmDevicePixelRatioScaled:
198  return 1;
199  default:
200  qWarning("VDxfPaintDevice::metric(), unhandled metric %d\n", metric);
201  break;
202  }
203  return 0;
204 }
void setMeasurement(const VarMeasurement &var)
Definition: vdxfengine.cpp:558
double getResolution() const
Definition: vdxfengine.cpp:417
bool ExportToAAMA(const QVector< VLayoutPiece > &details)
Definition: vdxfengine.cpp:607
bool IsBinaryFormat() const
Definition: vdxfengine.cpp:462
void SetBinaryFormat(bool binary)
Definition: vdxfengine.cpp:456
void setSize(const QSize &value)
Definition: vdxfengine.cpp:410
QSize getSize() const
Definition: vdxfengine.cpp:404
DRW::Version GetVersion() const
Definition: vdxfengine.cpp:443
void setResolution(double value)
Definition: vdxfengine.cpp:423
void setInsunits(const VarInsunits &var)
Definition: vdxfengine.cpp:565
void SetVersion(DRW::Version version)
Definition: vdxfengine.cpp:449
void setFileName(const QString &value)
Definition: vdxfengine.cpp:436
void setInsunits(const VarInsunits &var)
virtual ~VDxfPaintDevice() Q_DECL_OVERRIDE
virtual QPaintEngine * paintEngine() const Q_DECL_OVERRIDE
bool ExportToAAMA(const QVector< VLayoutPiece > &details) const
VDxfEngine * engine
void setFileName(const QString &value)
virtual int metric(PaintDeviceMetric metric) const Q_DECL_OVERRIDE
void SetBinaryFormat(bool binary)
QString getFileName() const
void setResolution(double dpi)
DRW::Version GetVersion() const
bool IsBinaryFormat() const
void SetVersion(DRW::Version version)
void setMeasurement(const VarMeasurement &var)
void setSize(const QSize &size)
double getResolution() const
VarMeasurement
Definition: dxfdef.h:61
VarInsunits
Definition: dxfdef.h:64