diff --git a/ChangeLog.txt b/ChangeLog.txt index 3c840dcfe..bc9ab1410 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -7,6 +7,8 @@ - New feature Zoom Fit Best Current pattern piece. - [#693] New feature: Sort workpiece "Groups" by name. - [#712] Default seam allowance setting. +- [#630] Improve export: upgrade to DXF r14 format. +- [#669] Improve export: export labels as text in DXF. # Version 0.5.1 - [#683] Tool Seam allowance's dialog is off screen on small resolutions. diff --git a/common.pri b/common.pri index 9f87d0f62..15710da56 100644 --- a/common.pri +++ b/common.pri @@ -278,7 +278,7 @@ GCC_DEBUG_CXXFLAGS += \ # -Winline \ -Winvalid-pch \ # -Wunsafe-loop-optimizations \ - -Wlong-long \ +# -Wlong-long \ We have been using C++11 -Wmissing-format-attribute \ -Wswitch-default \ -Wuninitialized \ @@ -517,7 +517,7 @@ CLANG_DEBUG_CXXFLAGS += \ -Wno-c++98-compat-local-type-template-args \ -Wlogical-not-parentheses \ -Wlogical-op-parentheses \ - -Wlong-long \ +# -Wlong-long \ We have been using C++11 -Wloop-analysis \ -Wmain \ -Wmain-return-type \ diff --git a/dist/OBS_debian/debian.valentina.1 b/dist/OBS_debian/debian.valentina.1 index 2af6450c7..0e480b1f5 100644 --- a/dist/OBS_debian/debian.valentina.1 +++ b/dist/OBS_debian/debian.valentina.1 @@ -32,7 +32,7 @@ The path to output destination folder. By default the directory at which the app .BR "*" " PDF files (*.pdf) = 1," .RE .RS -.BR "*" " Images (*.png) = 2," +.BR "*" " Image files (*.png) = 2," .RE .RS .BR "*" " Wavefront OBJ (*.obj) = 3," @@ -44,8 +44,36 @@ The path to output destination folder. By default the directory at which the app .BR "*" " EPS files (*.eps) = 5," .RE .RS -.BR "*" " DXF files (*.dxf) = 6." +.BR "*" " AutoCAD DXF R10 (flat) files (*.dxf) = 6," .RE +.RS +.BR "*" " AutoCAD DXF R11/12 (flat) files (*.dxf) = 7," +.RE +.RS +.BR "*" " AutoCAD DXF R13 (flat) files (*.dxf) = 8," +.RE +.RS +.BR "*" " AutoCAD DXF R14 (flat) files (*.dxf) = 9," +.RE +.RS +.BR "*" " AutoCAD DXF 2000 (flat) files (*.dxf) = 10," +.RE +.RS +.BR "*" " AutoCAD DXF 2004 (flat) files (*.dxf) = 11," +.RE +.RS +.BR "*" " AutoCAD DXF 2007 (flat) files (*.dxf) = 12," +.RE +.RS +.BR "*" " AutoCAD DXF 2010 (flat) files (*.dxf) = 13," +.RE +.RS +.BR "*" " AutoCAD DXF 2013 (flat) files (*.dxf) = 14." +.RE +.IP "--bdxf" +.RB "Export dxf in binary form." +.IP "--text2paths" +.RB "Export text as paths." .IP "-x, --gsize " .RB "Set size value a pattern file, that was opened with standard measurements " "(export mode)" ". Valid values: 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56cm." .IP "-e, --gheight " diff --git a/dist/debian/valentina.1 b/dist/debian/valentina.1 index 2af6450c7..0e480b1f5 100644 --- a/dist/debian/valentina.1 +++ b/dist/debian/valentina.1 @@ -32,7 +32,7 @@ The path to output destination folder. By default the directory at which the app .BR "*" " PDF files (*.pdf) = 1," .RE .RS -.BR "*" " Images (*.png) = 2," +.BR "*" " Image files (*.png) = 2," .RE .RS .BR "*" " Wavefront OBJ (*.obj) = 3," @@ -44,8 +44,36 @@ The path to output destination folder. By default the directory at which the app .BR "*" " EPS files (*.eps) = 5," .RE .RS -.BR "*" " DXF files (*.dxf) = 6." +.BR "*" " AutoCAD DXF R10 (flat) files (*.dxf) = 6," .RE +.RS +.BR "*" " AutoCAD DXF R11/12 (flat) files (*.dxf) = 7," +.RE +.RS +.BR "*" " AutoCAD DXF R13 (flat) files (*.dxf) = 8," +.RE +.RS +.BR "*" " AutoCAD DXF R14 (flat) files (*.dxf) = 9," +.RE +.RS +.BR "*" " AutoCAD DXF 2000 (flat) files (*.dxf) = 10," +.RE +.RS +.BR "*" " AutoCAD DXF 2004 (flat) files (*.dxf) = 11," +.RE +.RS +.BR "*" " AutoCAD DXF 2007 (flat) files (*.dxf) = 12," +.RE +.RS +.BR "*" " AutoCAD DXF 2010 (flat) files (*.dxf) = 13," +.RE +.RS +.BR "*" " AutoCAD DXF 2013 (flat) files (*.dxf) = 14." +.RE +.IP "--bdxf" +.RB "Export dxf in binary form." +.IP "--text2paths" +.RB "Export text as paths." .IP "-x, --gsize " .RB "Set size value a pattern file, that was opened with standard measurements " "(export mode)" ". Valid values: 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56cm." .IP "-e, --gheight " diff --git a/src/app/valentina/core/vcmdexport.cpp b/src/app/valentina/core/vcmdexport.cpp index 18337cdcd..73ab2f0fb 100644 --- a/src/app/valentina/core/vcmdexport.cpp +++ b/src/app/valentina/core/vcmdexport.cpp @@ -100,6 +100,14 @@ void VCommandLine::InitOptions(VCommandLineOptions &options, QMap DialogSaveLayout::MakeHelpFormatList(), translate("VCommandLine", "Format number"), "0")); + optionsIndex.insert(LONG_OPTION_BINARYDXF, index++); + options.append(new QCommandLineOption(QStringList() << LONG_OPTION_BINARYDXF, + translate("VCommandLine", "Export dxf in binary form."))); + + optionsIndex.insert(LONG_OPTION_TEXT2PATHS, index++); + options.append(new QCommandLineOption(QStringList() << LONG_OPTION_TEXT2PATHS, + translate("VCommandLine", "Export text as paths."))); + optionsIndex.insert(LONG_OPTION_GRADATIONSIZE, index++); options.append(new QCommandLineOption(QStringList() << SINGLE_OPTION_GRADATIONSIZE << LONG_OPTION_GRADATIONSIZE, translate("VCommandLine", "Set size value a pattern file, that was opened " @@ -617,6 +625,18 @@ int VCommandLine::OptExportType() const return r; } +//--------------------------------------------------------------------------------------------------------------------- +int VCommandLine::IsBinaryDXF() const +{ + return parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_BINARYDXF))); +} + +//--------------------------------------------------------------------------------------------------------------------- +int VCommandLine::IsTextAsPaths() const +{ + return parser.isSet(*optionsUsed.value(optionsIndex.value(LONG_OPTION_TEXT2PATHS))); +} + //--------------------------------------------------------------------------------------------------------------------- QStringList VCommandLine::OptInputFileNames() const { diff --git a/src/app/valentina/core/vcmdexport.h b/src/app/valentina/core/vcmdexport.h index 001933d29..a27e60333 100644 --- a/src/app/valentina/core/vcmdexport.h +++ b/src/app/valentina/core/vcmdexport.h @@ -75,6 +75,9 @@ public: //@brief returns export type set, defaults 0 - svg int OptExportType() const; + int IsBinaryDXF() const; + int IsTextAsPaths() const; + //generator creation is moved here ... because most options are for it only, so no need to create extra getters... //@brief creates VLayoutGenerator VLayoutGeneratorPtr DefaultGenerator() const; diff --git a/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp b/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp index 9a3449653..2b3f5e632 100644 --- a/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp +++ b/src/app/valentina/dialogs/configpages/preferencespatternpage.cpp @@ -57,6 +57,7 @@ PreferencesPatternPage::PreferencesPatternPage(QWidget *parent) ui->forbidFlippingCheck->setChecked(qApp->ValentinaSettings()->GetForbidWorkpieceFlipping()); ui->doublePassmarkCheck->setChecked(qApp->ValentinaSettings()->IsDoublePassmark()); ui->checkBoxHideMainPath->setChecked(qApp->ValentinaSettings()->IsHideMainPath()); + ui->fontComboBoxLabelFont->setCurrentFont(qApp->ValentinaSettings()->GetLabelFont()); } //--------------------------------------------------------------------------------------------------------------------- @@ -85,6 +86,7 @@ void PreferencesPatternPage::Apply() settings->SetForbidWorkpieceFlipping(ui->forbidFlippingCheck->isChecked()); settings->SetHideMainPath(ui->checkBoxHideMainPath->isChecked()); + qApp->ValentinaSettings()->SetLabelFont(ui->fontComboBoxLabelFont->currentFont()); if (settings->IsDoublePassmark() != ui->doublePassmarkCheck->isChecked()) { diff --git a/src/app/valentina/dialogs/configpages/preferencespatternpage.ui b/src/app/valentina/dialogs/configpages/preferencespatternpage.ui index 085dc4f3d..461ef356a 100644 --- a/src/app/valentina/dialogs/configpages/preferencespatternpage.ui +++ b/src/app/valentina/dialogs/configpages/preferencespatternpage.ui @@ -6,8 +6,8 @@ 0 0 - 327 - 482 + 381 + 444 @@ -133,6 +133,20 @@ + + + + + + Label font: + + + + + + + + diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.cpp b/src/app/valentina/dialogs/dialoglayoutsettings.cpp index 663d014c7..faa123c7a 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.cpp +++ b/src/app/valentina/dialogs/dialoglayoutsettings.cpp @@ -337,6 +337,18 @@ void DialogLayoutSettings::SetIgnoreAllFields(bool value) ui->checkBoxIgnoreFileds->setChecked(value); } +//--------------------------------------------------------------------------------------------------------------------- +bool DialogLayoutSettings::IsTextAsPaths() const +{ + return ui->checkBoxTextAsPaths->isChecked(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogLayoutSettings::SetTextAsPaths(bool value) +{ + ui->checkBoxTextAsPaths->setChecked(value); +} + //--------------------------------------------------------------------------------------------------------------------- QString DialogLayoutSettings::SelectedPrinter() const { @@ -568,6 +580,7 @@ void DialogLayoutSettings::DialogAccepted() generator->SetUnitePages(IsUnitePages()); generator->SetStripOptimization(IsStripOptimization()); generator->SetMultiplier(GetMultiplier()); + generator->SetTestAsPaths(IsTextAsPaths()); if (IsIgnoreAllFields()) { @@ -659,6 +672,8 @@ void DialogLayoutSettings::RestoreDefaults() CorrectMaxFileds(); IgnoreAllFields(ui->checkBoxIgnoreFileds->isChecked()); + + ui->checkBoxTextAsPaths->setChecked(false); } //--------------------------------------------------------------------------------------------------------------------- @@ -1070,6 +1085,7 @@ void DialogLayoutSettings::ReadSettings() SetIgnoreAllFields(settings->GetIgnoreAllFields()); SetStripOptimization(settings->GetStripOptimization()); SetMultiplier(settings->GetMultiplier()); + SetTextAsPaths(settings->GetTextAsPaths()); FindTemplate(); @@ -1095,6 +1111,7 @@ void DialogLayoutSettings::WriteSettings() const settings->SetIgnoreAllFields(IsIgnoreAllFields()); settings->SetStripOptimization(IsStripOptimization()); settings->SetMultiplier(GetMultiplier()); + settings->SetTextAsPaths(IsTextAsPaths()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.h b/src/app/valentina/dialogs/dialoglayoutsettings.h index 39f46b950..ffecc2385 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.h +++ b/src/app/valentina/dialogs/dialoglayoutsettings.h @@ -110,6 +110,9 @@ public: bool IsIgnoreAllFields() const; void SetIgnoreAllFields(bool value); + bool IsTextAsPaths() const; + void SetTextAsPaths(bool value); + QString SelectedPrinter() const; //support functions for the command line parser which uses invisible dialog to properly build layout generator diff --git a/src/app/valentina/dialogs/dialoglayoutsettings.ui b/src/app/valentina/dialogs/dialoglayoutsettings.ui index 83e9efd8b..2dccdf585 100644 --- a/src/app/valentina/dialogs/dialoglayoutsettings.ui +++ b/src/app/valentina/dialogs/dialoglayoutsettings.ui @@ -7,7 +7,7 @@ 0 0 600 - 531 + 533 @@ -17,7 +17,7 @@ :/icon/64x64/icon64x64.png:/icon/64x64/icon64x64.png - + @@ -308,6 +308,29 @@ + + + + + + Text + + + + + + Text will be converted to paths + + + Export text as paths + + + + + + + + @@ -732,7 +755,7 @@ - + diff --git a/src/app/valentina/dialogs/dialogpreferences.h b/src/app/valentina/dialogs/dialogpreferences.h index 099fde45f..754324f72 100644 --- a/src/app/valentina/dialogs/dialogpreferences.h +++ b/src/app/valentina/dialogs/dialogpreferences.h @@ -40,6 +40,7 @@ class PreferencesConfigurationPage; class PreferencesPatternPage; class PreferencesPathPage; class QListWidgetItem; +class VPattern; class DialogPreferences : public QDialog { diff --git a/src/app/valentina/dialogs/dialogsavelayout.cpp b/src/app/valentina/dialogs/dialogsavelayout.cpp index d19e4b16d..6f280c01e 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.cpp +++ b/src/app/valentina/dialogs/dialogsavelayout.cpp @@ -47,7 +47,10 @@ bool DialogSaveLayout::tested = false; //--------------------------------------------------------------------------------------------------------------------- DialogSaveLayout::DialogSaveLayout(int count, const QString &fileName, QWidget *parent) - :QDialog(parent), ui(new Ui::DialogSaveLAyout), count(count), isInitialized(false), availFormats(InitAvailFormats()) + : QDialog(parent), + ui(new Ui::DialogSaveLAyout), + count(count), + isInitialized(false) { ui->setupUi(this); @@ -80,20 +83,14 @@ DialogSaveLayout::DialogSaveLayout(int count, const QString &fileName, QWidget * } } - foreach (auto& v , availFormats) + foreach (auto& v, InitFormats()) { - ui->comboBoxFormat->addItem(v.first, QVariant(v.second)); + ui->comboBoxFormat->addItem(v.first, QVariant(static_cast(v.second))); } connect(bOk, &QPushButton::clicked, this, &DialogSaveLayout::Save); - - auto ShowExample = [this]() - { - ui->labelExample->setText(tr("Example:") + FileName() + QLatin1String("1") + Format()); - }; - - connect(ui->lineEditFileName, &QLineEdit::textChanged, this, ShowExample); + connect(ui->lineEditFileName, &QLineEdit::textChanged, this, &DialogSaveLayout::ShowExample); connect(ui->comboBoxFormat, static_cast(&QComboBox::currentIndexChanged), - this, ShowExample); + this, &DialogSaveLayout::ShowExample); connect(ui->pushButtonBrowse, &QPushButton::clicked, this, [this]() { const QString dirPath = qApp->ValentinaSettings()->GetPathLayout(); @@ -126,15 +123,15 @@ DialogSaveLayout::DialogSaveLayout(int count, const QString &fileName, QWidget * } //--------------------------------------------------------------------------------------------------------------------- -void DialogSaveLayout::SelectFormate(const int formate) +void DialogSaveLayout::SelectFormat(LayoutExportFormats format) { - if (formate >= availFormats.size()) + if (static_cast(format) < 0 || format >= LayoutExportFormats::COUNT) { VException e(tr("Tried to use out of range format number.")); throw e; } - const int i = ui->comboBoxFormat->findData(availFormats.at(formate).second); + const int i = ui->comboBoxFormat->findData(static_cast(format)); if (i < 0) { VException e(tr("Selected not present format.")); @@ -143,15 +140,104 @@ void DialogSaveLayout::SelectFormate(const int formate) ui->comboBoxFormat->setCurrentIndex(i); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSaveLayout::SetBinaryDXFFormat(bool binary) +{ + switch(Format()) + { + case LayoutExportFormats::DXF_AC1006_Flat: + case LayoutExportFormats::DXF_AC1009_Flat: + case LayoutExportFormats::DXF_AC1012_Flat: + case LayoutExportFormats::DXF_AC1014_Flat: + case LayoutExportFormats::DXF_AC1015_Flat: + case LayoutExportFormats::DXF_AC1018_Flat: + case LayoutExportFormats::DXF_AC1021_Flat: + case LayoutExportFormats::DXF_AC1024_Flat: + case LayoutExportFormats::DXF_AC1027_Flat: + case LayoutExportFormats::DXF_AC1006_AAMA: + case LayoutExportFormats::DXF_AC1009_AAMA: + case LayoutExportFormats::DXF_AC1012_AAMA: + case LayoutExportFormats::DXF_AC1014_AAMA: + case LayoutExportFormats::DXF_AC1015_AAMA: + case LayoutExportFormats::DXF_AC1018_AAMA: + case LayoutExportFormats::DXF_AC1021_AAMA: + case LayoutExportFormats::DXF_AC1024_AAMA: + case LayoutExportFormats::DXF_AC1027_AAMA: + case LayoutExportFormats::DXF_AC1006_ASTM: + case LayoutExportFormats::DXF_AC1009_ASTM: + case LayoutExportFormats::DXF_AC1012_ASTM: + case LayoutExportFormats::DXF_AC1014_ASTM: + case LayoutExportFormats::DXF_AC1015_ASTM: + case LayoutExportFormats::DXF_AC1018_ASTM: + case LayoutExportFormats::DXF_AC1021_ASTM: + case LayoutExportFormats::DXF_AC1024_ASTM: + case LayoutExportFormats::DXF_AC1027_ASTM: + ui->checkBoxBinaryDXF->setChecked(binary); + break; + case LayoutExportFormats::SVG: + case LayoutExportFormats::PDF: + case LayoutExportFormats::PNG: + case LayoutExportFormats::OBJ: + case LayoutExportFormats::PS: + case LayoutExportFormats::EPS: + default: + ui->checkBoxBinaryDXF->setChecked(false); + break; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +bool DialogSaveLayout::IsBinaryDXFFormat() const +{ + switch(Format()) + { + case LayoutExportFormats::DXF_AC1006_Flat: + case LayoutExportFormats::DXF_AC1009_Flat: + case LayoutExportFormats::DXF_AC1012_Flat: + case LayoutExportFormats::DXF_AC1014_Flat: + case LayoutExportFormats::DXF_AC1015_Flat: + case LayoutExportFormats::DXF_AC1018_Flat: + case LayoutExportFormats::DXF_AC1021_Flat: + case LayoutExportFormats::DXF_AC1024_Flat: + case LayoutExportFormats::DXF_AC1027_Flat: + case LayoutExportFormats::DXF_AC1006_AAMA: + case LayoutExportFormats::DXF_AC1009_AAMA: + case LayoutExportFormats::DXF_AC1012_AAMA: + case LayoutExportFormats::DXF_AC1014_AAMA: + case LayoutExportFormats::DXF_AC1015_AAMA: + case LayoutExportFormats::DXF_AC1018_AAMA: + case LayoutExportFormats::DXF_AC1021_AAMA: + case LayoutExportFormats::DXF_AC1024_AAMA: + case LayoutExportFormats::DXF_AC1027_AAMA: + case LayoutExportFormats::DXF_AC1006_ASTM: + case LayoutExportFormats::DXF_AC1009_ASTM: + case LayoutExportFormats::DXF_AC1012_ASTM: + case LayoutExportFormats::DXF_AC1014_ASTM: + case LayoutExportFormats::DXF_AC1015_ASTM: + case LayoutExportFormats::DXF_AC1018_ASTM: + case LayoutExportFormats::DXF_AC1021_ASTM: + case LayoutExportFormats::DXF_AC1024_ASTM: + case LayoutExportFormats::DXF_AC1027_ASTM: + return ui->checkBoxBinaryDXF->isChecked(); + case LayoutExportFormats::SVG: + case LayoutExportFormats::PDF: + case LayoutExportFormats::PNG: + case LayoutExportFormats::OBJ: + case LayoutExportFormats::PS: + case LayoutExportFormats::EPS: + default: + return false; + } +} + //--------------------------------------------------------------------------------------------------------------------- QString DialogSaveLayout::MakeHelpFormatList() { QString out("\n"); - int cntr = 0; - const QVector> availFormats = InitAvailFormats(); - foreach(auto& v, availFormats) + foreach(auto& v, InitFormats()) { - out += QLatin1String("\t") + v.first+QLatin1String(" = ") + QString::number(cntr++) + QLatin1String("\n"); + out += QLatin1String("\t") + v.first + QLatin1String(" = ") + QString::number(static_cast(v.second)) + + QLatin1String("\n"); } return out; } @@ -183,6 +269,136 @@ void DialogSaveLayout::SetDestinationPath(const QString &cmdDestinationPath) ui->lineEditPath->setText(path); } +//--------------------------------------------------------------------------------------------------------------------- +QString DialogSaveLayout::ExportFormatDescription(LayoutExportFormats format) +{ + const QString dxfSuffix = QStringLiteral("(*.dxf)"); + const QString dxfFlatFilesStr = tr("(flat) files"); + const QString filesStr = tr("files"); + + switch(format) + { + case LayoutExportFormats::SVG: + return QString("Svg %1 (*.svg)").arg(filesStr); + case LayoutExportFormats::PDF: + return QString("PDF %1 (*.pdf)").arg(filesStr); + case LayoutExportFormats::PNG: + return tr("Image files") + QLatin1String(" (*.png)"); + case LayoutExportFormats::OBJ: + return "Wavefront OBJ (*.obj)"; + case LayoutExportFormats::PS: + return QString("PS %1 (*.ps)").arg(filesStr); + case LayoutExportFormats::EPS: + return QString("EPS %1 (*.eps)").arg(filesStr); + case LayoutExportFormats::DXF_AC1006_Flat: + return QString("AutoCAD DXF R10 %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1009_Flat: + return QString("AutoCAD DXF R11/12 %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1012_Flat: + return QString("AutoCAD DXF R13 %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1014_Flat: + return QString("AutoCAD DXF R14 %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1015_Flat: + return QString("AutoCAD DXF 2000 %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1018_Flat: + return QString("AutoCAD DXF 2004 %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1021_Flat: + return QString("AutoCAD DXF 2007 %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1024_Flat: + return QString("AutoCAD DXF 2010 %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1027_Flat: + return QString("AutoCAD DXF 2013 %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1006_AAMA: + return QString("AutoCAD DXF R10 AAMA %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1009_AAMA: + return QString("AutoCAD DXF R11/12 AAMA %1 %2").arg(dxfFlatFilesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1012_AAMA: + return QString("AutoCAD DXF R13 AAMA %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1014_AAMA: + return QString("AutoCAD DXF R14 AAMA %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1015_AAMA: + return QString("AutoCAD DXF 2000 AAMA %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1018_AAMA: + return QString("AutoCAD DXF 2004 AAMA %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1021_AAMA: + return QString("AutoCAD DXF 2007 AAMA %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1024_AAMA: + return QString("AutoCAD DXF 2010 AAMA %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1027_AAMA: + return QString("AutoCAD DXF 2013 AAMA %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1006_ASTM: + return QString("AutoCAD DXF R10 ASTM %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1009_ASTM: + return QString("AutoCAD DXF R11/12 ASTM %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1012_ASTM: + return QString("AutoCAD DXF R13 ASTM %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1014_ASTM: + return QString("AutoCAD DXF R14 ASTM %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1015_ASTM: + return QString("AutoCAD DXF 2000 ASTM %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1018_ASTM: + return QString("AutoCAD DXF 2004 ASTM %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1021_ASTM: + return QString("AutoCAD DXF 2007 ASTM %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1024_ASTM: + return QString("AutoCAD DXF 2010 ASTM %1 %2").arg(filesStr, dxfSuffix); + case LayoutExportFormats::DXF_AC1027_ASTM: + return QString("AutoCAD DXF 2013 ASTM %1 %2").arg(filesStr, dxfSuffix); + default: + return QString(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QString DialogSaveLayout::ExportFromatSuffix(LayoutExportFormats format) +{ + switch(format) + { + case LayoutExportFormats::SVG: + return ".svg"; + case LayoutExportFormats::PDF: + return ".pdf"; + case LayoutExportFormats::PNG: + return ".png"; + case LayoutExportFormats::OBJ: + return ".obj"; + case LayoutExportFormats::PS: + return ".ps"; + case LayoutExportFormats::EPS: + return ".eps"; + case LayoutExportFormats::DXF_AC1006_Flat: + case LayoutExportFormats::DXF_AC1009_Flat: + case LayoutExportFormats::DXF_AC1012_Flat: + case LayoutExportFormats::DXF_AC1014_Flat: + case LayoutExportFormats::DXF_AC1015_Flat: + case LayoutExportFormats::DXF_AC1018_Flat: + case LayoutExportFormats::DXF_AC1021_Flat: + case LayoutExportFormats::DXF_AC1024_Flat: + case LayoutExportFormats::DXF_AC1027_Flat: + case LayoutExportFormats::DXF_AC1006_AAMA: + case LayoutExportFormats::DXF_AC1009_AAMA: + case LayoutExportFormats::DXF_AC1012_AAMA: + case LayoutExportFormats::DXF_AC1014_AAMA: + case LayoutExportFormats::DXF_AC1015_AAMA: + case LayoutExportFormats::DXF_AC1018_AAMA: + case LayoutExportFormats::DXF_AC1021_AAMA: + case LayoutExportFormats::DXF_AC1024_AAMA: + case LayoutExportFormats::DXF_AC1027_AAMA: + case LayoutExportFormats::DXF_AC1006_ASTM: + case LayoutExportFormats::DXF_AC1009_ASTM: + case LayoutExportFormats::DXF_AC1012_ASTM: + case LayoutExportFormats::DXF_AC1014_ASTM: + case LayoutExportFormats::DXF_AC1015_ASTM: + case LayoutExportFormats::DXF_AC1018_ASTM: + case LayoutExportFormats::DXF_AC1021_ASTM: + case LayoutExportFormats::DXF_AC1024_ASTM: + case LayoutExportFormats::DXF_AC1027_ASTM: + return ".dxf"; + default: + return QString(); + } +} + //--------------------------------------------------------------------------------------------------------------------- DialogSaveLayout::~DialogSaveLayout() { @@ -202,9 +418,9 @@ QString DialogSaveLayout::FileName() const } //--------------------------------------------------------------------------------------------------------------------- -QString DialogSaveLayout::Format() const +LayoutExportFormats DialogSaveLayout::Format() const { - return ui->comboBoxFormat->currentData().toString(); + return static_cast(ui->comboBoxFormat->currentData().toInt()); } //--------------------------------------------------------------------------------------------------------------------- @@ -212,7 +428,7 @@ void DialogSaveLayout::Save() { for (int i=0; i < count; ++i) { - const QString name = Path()+QLatin1Literal("/")+FileName()+QString::number(i+1)+Format(); + const QString name = Path()+QLatin1Literal("/")+FileName()+QString::number(i+1)+ExportFromatSuffix(Format()); if (QFile::exists(name)) { QMessageBox::StandardButton res = QMessageBox::question(this, tr("Name conflict"), @@ -256,6 +472,55 @@ void DialogSaveLayout::PathChanged(const QString &text) ui->lineEditPath->setPalette(palette); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSaveLayout::ShowExample() +{ + const LayoutExportFormats currentFormat = Format(); + ui->labelExample->setText(tr("Example:") + FileName() + QLatin1String("1") + ExportFromatSuffix(currentFormat)); + + switch(currentFormat) + { + case LayoutExportFormats::DXF_AC1006_Flat: + case LayoutExportFormats::DXF_AC1009_Flat: + case LayoutExportFormats::DXF_AC1012_Flat: + case LayoutExportFormats::DXF_AC1014_Flat: + case LayoutExportFormats::DXF_AC1015_Flat: + case LayoutExportFormats::DXF_AC1018_Flat: + case LayoutExportFormats::DXF_AC1021_Flat: + case LayoutExportFormats::DXF_AC1024_Flat: + case LayoutExportFormats::DXF_AC1027_Flat: + case LayoutExportFormats::DXF_AC1006_AAMA: + case LayoutExportFormats::DXF_AC1009_AAMA: + case LayoutExportFormats::DXF_AC1012_AAMA: + case LayoutExportFormats::DXF_AC1014_AAMA: + case LayoutExportFormats::DXF_AC1015_AAMA: + case LayoutExportFormats::DXF_AC1018_AAMA: + case LayoutExportFormats::DXF_AC1021_AAMA: + case LayoutExportFormats::DXF_AC1024_AAMA: + case LayoutExportFormats::DXF_AC1027_AAMA: + case LayoutExportFormats::DXF_AC1006_ASTM: + case LayoutExportFormats::DXF_AC1009_ASTM: + case LayoutExportFormats::DXF_AC1012_ASTM: + case LayoutExportFormats::DXF_AC1014_ASTM: + case LayoutExportFormats::DXF_AC1015_ASTM: + case LayoutExportFormats::DXF_AC1018_ASTM: + case LayoutExportFormats::DXF_AC1021_ASTM: + case LayoutExportFormats::DXF_AC1024_ASTM: + case LayoutExportFormats::DXF_AC1027_ASTM: + ui->checkBoxBinaryDXF->setEnabled(true); + break; + case LayoutExportFormats::SVG: + case LayoutExportFormats::PDF: + case LayoutExportFormats::PNG: + case LayoutExportFormats::OBJ: + case LayoutExportFormats::PS: + case LayoutExportFormats::EPS: + default: + ui->checkBoxBinaryDXF->setEnabled(false); + break; + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogSaveLayout::showEvent(QShowEvent *event) { @@ -311,22 +576,55 @@ bool DialogSaveLayout::TestPdf() } //--------------------------------------------------------------------------------------------------------------------- -QVector> DialogSaveLayout::InitAvailFormats() +QVector > DialogSaveLayout::InitFormats() { - QVector> list; - list.append(std::make_pair(QLatin1String("Svg ") + tr("files") + QLatin1String(" (*.svg)"), QLatin1String(".svg"))); - list.append(std::make_pair(QLatin1String("PDF ") + tr("files") + QLatin1String(" (*.pdf)"), QLatin1String(".pdf"))); - list.append(std::make_pair(QLatin1String("Images") + QLatin1String(" (*.png)"), QLatin1String(".png"))); + QVector> list; + + auto InitFormat = [&list](LayoutExportFormats format) + { + list.append(std::make_pair(ExportFormatDescription(format), format)); + }; + + InitFormat(LayoutExportFormats::SVG); + InitFormat(LayoutExportFormats::PDF); + InitFormat(LayoutExportFormats::PNG); #ifndef V_NO_ASSERT // Temporarily unavailable - list.append(std::make_pair(QLatin1String("Wavefront OBJ (*.obj)"), QLatin1String(".obj"))); + InitFormat(LayoutExportFormats::OBJ); #endif if (SupportPSTest()) { - list.append(std::make_pair(QLatin1String("PS ") + tr("files") + QLatin1String(" (*.ps)"), - QLatin1String(".ps"))); - list.append(std::make_pair(QLatin1String("EPS ") + tr("files") + QLatin1String(" (*.eps)"), - QLatin1String(".eps"))); + InitFormat(LayoutExportFormats::PS); + InitFormat(LayoutExportFormats::EPS); } - list.append(std::make_pair(QLatin1String("DXF ") + tr("files") + QLatin1String(" (*.dxf)"), QLatin1String(".dxf"))); + InitFormat(LayoutExportFormats::DXF_AC1006_Flat); + InitFormat(LayoutExportFormats::DXF_AC1009_Flat); + InitFormat(LayoutExportFormats::DXF_AC1012_Flat); + InitFormat(LayoutExportFormats::DXF_AC1014_Flat); + InitFormat(LayoutExportFormats::DXF_AC1015_Flat); + InitFormat(LayoutExportFormats::DXF_AC1018_Flat); + InitFormat(LayoutExportFormats::DXF_AC1021_Flat); + InitFormat(LayoutExportFormats::DXF_AC1024_Flat); + InitFormat(LayoutExportFormats::DXF_AC1027_Flat); + + // We will support them anyway +// InitFormat(LayoutExportFormats::DXF_AC1006_AAMA); +// InitFormat(LayoutExportFormats::DXF_AC1009_AAMA); +// InitFormat(LayoutExportFormats::DXF_AC1012_AAMA); +// InitFormat(LayoutExportFormats::DXF_AC1014_AAMA); +// InitFormat(LayoutExportFormats::DXF_AC1015_AAMA); +// InitFormat(LayoutExportFormats::DXF_AC1018_AAMA); +// InitFormat(LayoutExportFormats::DXF_AC1021_AAMA); +// InitFormat(LayoutExportFormats::DXF_AC1024_AAMA); +// InitFormat(LayoutExportFormats::DXF_AC1027_AAMA); +// InitFormat(LayoutExportFormats::DXF_AC1006_ASTM); +// InitFormat(LayoutExportFormats::DXF_AC1009_ASTM); +// InitFormat(LayoutExportFormats::DXF_AC1012_ASTM); +// InitFormat(LayoutExportFormats::DXF_AC1014_ASTM); +// InitFormat(LayoutExportFormats::DXF_AC1015_ASTM); +// InitFormat(LayoutExportFormats::DXF_AC1018_ASTM); +// InitFormat(LayoutExportFormats::DXF_AC1021_ASTM); +// InitFormat(LayoutExportFormats::DXF_AC1024_ASTM); +// InitFormat(LayoutExportFormats::DXF_AC1027_ASTM); + return list; } diff --git a/src/app/valentina/dialogs/dialogsavelayout.h b/src/app/valentina/dialogs/dialogsavelayout.h index af1990831..047244292 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.h +++ b/src/app/valentina/dialogs/dialogsavelayout.h @@ -42,38 +42,82 @@ namespace Ui class DialogSaveLAyout; } +enum class LayoutExportFormats : char +{ + SVG = 0, + PDF = 1, + PNG = 2, + OBJ = 3, /* Wavefront OBJ*/ + PS = 4, + EPS = 5, + DXF_AC1006_Flat = 6, /*< R10. */ + DXF_AC1009_Flat = 7, /*< R11 & R12. */ + DXF_AC1012_Flat = 8, /*< R13. */ + DXF_AC1014_Flat = 9, /*< R14. */ + DXF_AC1015_Flat = 10, /*< ACAD 2000. */ + DXF_AC1018_Flat = 11, /*< ACAD 2004. */ + DXF_AC1021_Flat = 12, /*< ACAD 2007. */ + DXF_AC1024_Flat = 13, /*< ACAD 2010. */ + DXF_AC1027_Flat = 14, /*< ACAD 2013. */ + DXF_AC1006_AAMA = 15, /*< R10. */ + DXF_AC1009_AAMA = 16, /*< R11 & R12. */ + DXF_AC1012_AAMA = 17, /*< R13. */ + DXF_AC1014_AAMA = 18, /*< R14. */ + DXF_AC1015_AAMA = 19, /*< ACAD 2000. */ + DXF_AC1018_AAMA = 20, /*< ACAD 2004. */ + DXF_AC1021_AAMA = 21, /*< ACAD 2007. */ + DXF_AC1024_AAMA = 22, /*< ACAD 2010. */ + DXF_AC1027_AAMA = 23, /*< ACAD 2013. */ + DXF_AC1006_ASTM = 24, /*< R10. */ + DXF_AC1009_ASTM = 25, /*< R11 & R12. */ + DXF_AC1012_ASTM = 26, /*< R13. */ + DXF_AC1014_ASTM = 27, /*< R14. */ + DXF_AC1015_ASTM = 28, /*< ACAD 2000. */ + DXF_AC1018_ASTM = 29, /*< ACAD 2004. */ + DXF_AC1021_ASTM = 30, /*< ACAD 2007. */ + DXF_AC1024_ASTM = 31, /*< ACAD 2010. */ + DXF_AC1027_ASTM = 32, /*< ACAD 2013. */ + COUNT /*Use only for validation*/ +}; + class DialogSaveLayout : public QDialog { Q_OBJECT public: - explicit DialogSaveLayout(int count, const QString &fileName = QString(), - QWidget *parent = 0); - ~DialogSaveLayout(); + explicit DialogSaveLayout(int count, const QString &fileName = QString(), QWidget *parent = nullptr); + virtual ~DialogSaveLayout(); QString Path() const; QString FileName() const; - QString Format() const; - void SelectFormate(const int formate); + + LayoutExportFormats Format() const; + void SelectFormat(LayoutExportFormats format); + + void SetBinaryDXFFormat(bool binary); + bool IsBinaryDXFFormat() const; + static QString MakeHelpFormatList(); void SetDestinationPath(const QString& cmdDestinationPath); + + static QString ExportFormatDescription(LayoutExportFormats format); + static QString ExportFromatSuffix(LayoutExportFormats format); protected: virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; private slots: void Save(); void PathChanged(const QString &text); + void ShowExample(); private: Q_DISABLE_COPY(DialogSaveLayout) Ui::DialogSaveLAyout *ui; int count; bool isInitialized; - // Note. We can't make availFormats static because MSVC doesn't support C++11 list initialization - QVector> availFormats; static bool havePdf; static bool tested; static bool SupportPSTest(); static bool TestPdf(); - static QVector > InitAvailFormats(); + static QVector > InitFormats(); }; #endif // DIALOGSAVELAYOUT_H diff --git a/src/app/valentina/dialogs/dialogsavelayout.ui b/src/app/valentina/dialogs/dialogsavelayout.ui index 87c190ff1..e98cf5706 100644 --- a/src/app/valentina/dialogs/dialogsavelayout.ui +++ b/src/app/valentina/dialogs/dialogsavelayout.ui @@ -7,7 +7,7 @@ 0 0 748 - 150 + 178 @@ -92,14 +92,14 @@ - + File name: - + @@ -135,6 +135,23 @@ + + + + + + + + + + + false + + + Binary form + + + diff --git a/src/app/valentina/dialogs/vwidgetgroups.cpp b/src/app/valentina/dialogs/vwidgetgroups.cpp index c6c39332a..14d1971ea 100644 --- a/src/app/valentina/dialogs/vwidgetgroups.cpp +++ b/src/app/valentina/dialogs/vwidgetgroups.cpp @@ -30,6 +30,7 @@ #include "ui_vwidgetgroups.h" #include "../vtools/dialogs/tools/dialoggroup.h" #include "../vtools/undocommands/delgroup.h" +#include "../vpatterndb/vcontainer.h" #include diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index aca45571f..2cb82d20c 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -4350,6 +4350,7 @@ void MainWindow::Preferences() connect(dlg.data(), &DialogPreferences::UpdateProperties, toolOptions, &VToolOptionsPropertyBrowser::RefreshOptions); connect(dlg.data(), &DialogPreferences::UpdateProperties, this, &MainWindow::ToolBarStyles); + connect(dlg.data(), &DialogPreferences::UpdateProperties, this, &MainWindow::RefreshDetailsLabel); QGuiApplication::restoreOverrideCursor(); if (guard->exec() == QDialog::Accepted) @@ -4677,8 +4678,6 @@ void MainWindow::ZoomFirstShow() //--------------------------------------------------------------------------------------------------------------------- void MainWindow::DoExport(const VCommandLinePtr &expParams) { - auto settings = expParams->DefaultGenerator(); - const QHash *details = pattern->DataPieces(); if(not qApp->getOpeningPattern()) { @@ -4690,13 +4689,18 @@ void MainWindow::DoExport(const VCommandLinePtr &expParams) } } PrepareDetailsForLayout(details); + + auto settings = expParams->DefaultGenerator(); + settings->SetTestAsPaths(expParams->IsTextAsPaths()); + if (LayoutSettings(*settings.get())) { try { DialogSaveLayout dialog(scenes.size(), expParams->OptBaseName(), this); dialog.SetDestinationPath(expParams->OptDestinationPath()); - dialog.SelectFormate(expParams->OptExportType()); + dialog.SelectFormat(static_cast(expParams->OptExportType())); + dialog.SetBinaryDXFFormat(expParams->IsBinaryDXF()); ExportLayout(dialog); } catch (const VException &e) diff --git a/src/app/valentina/mainwindowsnogui.cpp b/src/app/valentina/mainwindowsnogui.cpp index 9674b9c56..70d38a921 100644 --- a/src/app/valentina/mainwindowsnogui.cpp +++ b/src/app/valentina/mainwindowsnogui.cpp @@ -41,6 +41,7 @@ #include "../vpatterndb/floatItemData/vpatternlabeldata.h" #include "../vpatterndb/floatItemData/vgrainlinedata.h" #include "../vtools/tools/vabstracttool.h" +#include "../vtools/tools/vtoolseamallowance.h" #include #include @@ -200,8 +201,6 @@ void MainWindowsNoGUI::ErrorConsoleMode(const LayoutErrors &state) //--------------------------------------------------------------------------------------------------------------------- void MainWindowsNoGUI::ExportLayout(const DialogSaveLayout &dialog) { - - const QString suf = dialog.Format().replace(".", ""); const QString path = dialog.Path(); QDir dir(path); dir.setPath(path); @@ -215,51 +214,108 @@ void MainWindowsNoGUI::ExportLayout(const DialogSaveLayout &dialog) } qApp->ValentinaSettings()->SetPathLayout(path); const QString mask = dialog.FileName(); + const LayoutExportFormats format = dialog.Format(); for (int i=0; i < scenes.size(); ++i) { QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); if (paper) { - const QString name = path + QLatin1String("/") + mask+QString::number(i+1) + dialog.Format(); + const QString name = path + QLatin1String("/") + mask+QString::number(i+1) + + DialogSaveLayout::ExportFromatSuffix(format); QBrush *brush = new QBrush(); brush->setColor( QColor( Qt::white ) ); scenes[i]->setBackgroundBrush( *brush ); shadows[i]->setVisible(false); paper->setPen(QPen(QBrush(Qt::white, Qt::NoBrush), 0.1, Qt::NoPen)); - const QStringList suffix = QStringList() << QLatin1String("svg") - << QLatin1String("png") - << QLatin1String("pdf") - << QLatin1String("eps") - << QLatin1String("ps") - << QLatin1String("obj") - << QLatin1String("dxf"); - switch (suffix.indexOf(suf)) + + switch (format) { - case 0: //svg + case LayoutExportFormats::DXF_AC1006_AAMA: + case LayoutExportFormats::DXF_AC1009_AAMA: + case LayoutExportFormats::DXF_AC1012_AAMA: + case LayoutExportFormats::DXF_AC1014_AAMA: + case LayoutExportFormats::DXF_AC1015_AAMA: + case LayoutExportFormats::DXF_AC1018_AAMA: + case LayoutExportFormats::DXF_AC1021_AAMA: + case LayoutExportFormats::DXF_AC1024_AAMA: + case LayoutExportFormats::DXF_AC1027_AAMA: + case LayoutExportFormats::DXF_AC1006_ASTM: + case LayoutExportFormats::DXF_AC1009_ASTM: + case LayoutExportFormats::DXF_AC1012_ASTM: + case LayoutExportFormats::DXF_AC1014_ASTM: + case LayoutExportFormats::DXF_AC1015_ASTM: + case LayoutExportFormats::DXF_AC1018_ASTM: + case LayoutExportFormats::DXF_AC1021_ASTM: + case LayoutExportFormats::DXF_AC1024_ASTM: + case LayoutExportFormats::DXF_AC1027_ASTM: + Q_UNREACHABLE(); // For now not supported + case LayoutExportFormats::SVG: paper->setVisible(false); SvgFile(name, i); paper->setVisible(true); break; - case 1: //png - PngFile(name, i); - break; - case 2: //pdf + case LayoutExportFormats::PDF: PdfFile(name, i); break; - case 3: //eps - EpsFile(name, i); + case LayoutExportFormats::PNG: + PngFile(name, i); break; - case 4: //ps - PsFile(name, i); - break; - case 5: //obj + case LayoutExportFormats::OBJ: paper->setVisible(false); ObjFile(name, i); paper->setVisible(true); break; - case 6: //dxf - DxfFile(name, i); + case LayoutExportFormats::PS: + PsFile(name, i); + break; + case LayoutExportFormats::EPS: + EpsFile(name, i); + break; + case LayoutExportFormats::DXF_AC1006_Flat: + paper->setVisible(false); + DxfFile(name, DRW::AC1006, dialog.IsBinaryDXFFormat(), i); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1009_Flat: + paper->setVisible(false); + DxfFile(name, DRW::AC1009, dialog.IsBinaryDXFFormat(), i); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1012_Flat: + paper->setVisible(false); + DxfFile(name, DRW::AC1012, dialog.IsBinaryDXFFormat(), i); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1014_Flat: + paper->setVisible(false); + DxfFile(name, DRW::AC1014, dialog.IsBinaryDXFFormat(), i); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1015_Flat: + paper->setVisible(false); + DxfFile(name, DRW::AC1015, dialog.IsBinaryDXFFormat(), i); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1018_Flat: + paper->setVisible(false); + DxfFile(name, DRW::AC1018, dialog.IsBinaryDXFFormat(), i); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1021_Flat: + paper->setVisible(false); + DxfFile(name, DRW::AC1021, dialog.IsBinaryDXFFormat(), i); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1024_Flat: + paper->setVisible(false); + DxfFile(name, DRW::AC1024, dialog.IsBinaryDXFFormat(), i); + paper->setVisible(true); + break; + case LayoutExportFormats::DXF_AC1027_Flat: + paper->setVisible(false); + DxfFile(name, DRW::AC1027, dialog.IsBinaryDXFFormat(), i); + paper->setVisible(true); break; default: qDebug() << "Can't recognize file suffix." << Q_FUNC_INFO; @@ -473,6 +529,25 @@ void MainWindowsNoGUI::PrintTiled() LayoutPrint(); } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief RefreshDetailsLabel call to ecalculate piece labels. For example after changing a font. + */ +void MainWindowsNoGUI::RefreshDetailsLabel() +{ + const QHash *list = pattern->DataPieces(); + QHash::const_iterator i = list->constBegin(); + while (i != list->constEnd()) + { + if (VToolSeamAllowance *tool = qobject_cast(VAbstractPattern::getTool(i.key()))) + { + tool->UpdatePatternInfo(); + tool->UpdateDetailLabel(); + } + ++i; + } +} + //--------------------------------------------------------------------------------------------------------------------- void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash *details) { @@ -763,15 +838,18 @@ void MainWindowsNoGUI::ObjFile(const QString &name, int i) const QT_WARNING_PUSH QT_WARNING_DISABLE_GCC("-Wswitch-default") -void MainWindowsNoGUI::DxfFile(const QString &name, int i) const +void MainWindowsNoGUI::DxfFile(const QString &name, int version, bool binary, int i) const { QGraphicsRectItem *paper = qgraphicsitem_cast(papers.at(i)); if (paper) { + PrepareTextForDXF(endStringPlaceholder); VDxfPaintDevice generator; generator.setFileName(name); generator.setSize(paper->rect().size().toSize()); generator.setResolution(PrintDPI); + generator.SetVersion(static_cast(version)); + generator.SetBinaryFormat(binary); switch (*pattern->GetPatternUnit()) { @@ -796,6 +874,7 @@ void MainWindowsNoGUI::DxfFile(const QString &name, int i) const scenes.at(i)->render(&painter, paper->rect(), paper->rect(), Qt::IgnoreAspectRatio); painter.end(); } + RestoreTextAfterDXF(endStringPlaceholder); } } @@ -829,6 +908,72 @@ void MainWindowsNoGUI::RestorePaper(int index) const } } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief PrepareTextForDXF prepare QGraphicsSimpleTextItem items for export to flat dxf. + * + * Because QPaintEngine::drawTextItem doesn't pass whole string per time we mark end of each string by adding special + * placholder. This method append it. + * + * @param placeholder placeholder that will be appended to each QGraphicsSimpleTextItem item's text string. + */ +void MainWindowsNoGUI::PrepareTextForDXF(const QString &placeholder) const +{ + for (int i = 0; i < details.size(); ++i) + { + const QList &paperItems = details.at(i); + for (int j = 0; j < paperItems.size(); ++j) + { + QList pieceChildren = paperItems.at(i)->childItems(); + for (int k = 0; k < pieceChildren.size(); ++k) + { + QGraphicsItem *item = pieceChildren.at(k); + if (item->type() == QGraphicsSimpleTextItem::Type) + { + if(QGraphicsSimpleTextItem *textItem = qgraphicsitem_cast(item)) + { + textItem->setText(textItem->text() + placeholder); + } + } + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief MainWindowsNoGUI::RestoreTextAfterDXF restore QGraphicsSimpleTextItem items after export to flat dxf. + * + * Because QPaintEngine::drawTextItem doesn't pass whole string per time we mark end of each string by adding special + * placholder. This method remove it. + * + * @param placeholder placeholder that will be removed from each QGraphicsSimpleTextItem item's text string. + */ +void MainWindowsNoGUI::RestoreTextAfterDXF(const QString &placeholder) const +{ + for (int i = 0; i < details.size(); ++i) + { + const QList &paperItems = details.at(i); + for (int j = 0; j < paperItems.size(); ++j) + { + QList pieceChildren = paperItems.at(i)->childItems(); + for (int k = 0; k < pieceChildren.size(); ++k) + { + QGraphicsItem *item = pieceChildren.at(k); + if (item->type() == QGraphicsSimpleTextItem::Type) + { + if(QGraphicsSimpleTextItem *textItem = qgraphicsitem_cast(item)) + { + QString text = textItem->text(); + text.replace(placeholder, ""); + textItem->setText(text); + } + } + } + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void MainWindowsNoGUI::SaveLayoutAs() { diff --git a/src/app/valentina/mainwindowsnogui.h b/src/app/valentina/mainwindowsnogui.h index 0f8ffcb07..0bfba5c03 100644 --- a/src/app/valentina/mainwindowsnogui.h +++ b/src/app/valentina/mainwindowsnogui.h @@ -55,6 +55,7 @@ public slots: void PrintPreviewTiled(); void PrintOrigin(); void PrintTiled(); + void RefreshDetailsLabel(); protected: QVector listDetails; @@ -120,11 +121,14 @@ private: void PsFile(const QString &name, int i)const; void PdfToPs(const QStringList ¶ms)const; void ObjFile(const QString &name, int i)const; - void DxfFile(const QString &name, int i)const; + void DxfFile(const QString &name, int version, bool binary, int i)const; void PreparePaper(int index) const; void RestorePaper(int index) const; + void PrepareTextForDXF(const QString &placeholder) const; + void RestoreTextAfterDXF(const QString &placeholder) const; + void SaveLayoutAs(); void PrintPreview(); void LayoutPrint(); diff --git a/src/libs/vdxf/dxfdef.cpp b/src/libs/vdxf/dxfdef.cpp new file mode 100644 index 000000000..b2379ebcf --- /dev/null +++ b/src/libs/vdxf/dxfdef.cpp @@ -0,0 +1,33 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 29 6, 2017 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2017 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "dxfdef.h" + +#include + +const QString endStringPlaceholder = QStringLiteral("%&?_?&%"); diff --git a/src/libs/vdxf/dxfdef.h b/src/libs/vdxf/dxfdef.h index 3c5139b82..0265b1b0f 100644 --- a/src/libs/vdxf/dxfdef.h +++ b/src/libs/vdxf/dxfdef.h @@ -1,6 +1,6 @@ /************************************************************************ ** - ** @file def.h + ** @file dxfdef.h ** @author Roman Telezhynskyi ** @date 31 8, 2015 ** @@ -40,6 +40,9 @@ enum class VarMeasurement : unsigned char { English=0, Metric=1 }; //Default drawing units for AutoCAD DesignCenter blocks: enum class VarInsunits : unsigned char { Inches=1, Millimeters=4, Centimeters=5 }; +// Helps mark end of string. See VDxfEngine::drawTextItem for more details +extern const QString endStringPlaceholder; + Q_REQUIRED_RESULT static inline bool DL_FuzzyComparePossibleNulls(double p1, double p2); static inline bool DL_FuzzyComparePossibleNulls(double p1, double p2) { diff --git a/src/libs/vdxf/dxflib/dl_attributes.h b/src/libs/vdxf/dxflib/dl_attributes.h deleted file mode 100644 index 1fc93a863..000000000 --- a/src/libs/vdxf/dxflib/dl_attributes.h +++ /dev/null @@ -1,260 +0,0 @@ -/**************************************************************************** -** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved. -** -** This file is part of the dxflib project. -** -** This file is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** Licensees holding valid dxflib Professional Edition licenses may use -** this file in accordance with the dxflib Commercial License -** Agreement provided with the Software. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.ribbonsoft.com for further details. -** -** Contact info@ribbonsoft.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -#ifndef DL_ATTRIBUTES_H -#define DL_ATTRIBUTES_H - -#include "dl_global.h" - -#include -#include - -#include "dl_codes.h" - -/** - * Storing and passing around attributes. Attributes - * are the layer name, color, width and line type. - * - * @author Andrew Mustun - */ -class DXFLIB_EXPORT DL_Attributes -{ - -public: - - /** - * Default constructor. - */ - DL_Attributes() : - layer(""), - color(0), - color24(-1), - width(0), - linetype("BYLAYER"), - linetypeScale(1.0), - handle(-1), - inPaperSpace(false) - { - } - - /** - * Constructor for DXF attributes. - * - * @param layer Layer name for this entity or NULL for no layer - * (every entity should be on a named layer!). - * @param color Color number (0..256). 0 = BYBLOCK, 256 = BYLAYER. - * @param width Line thickness. Defaults to zero. -1 = BYLAYER, - * -2 = BYBLOCK, -3 = default width - * @param linetype Line type name or "BYLAYER" or "BYBLOCK". Defaults - * to "BYLAYER" - */ - DL_Attributes(const std::string& layer, - int color, int width, - const std::string& linetype, - double linetypeScale) : - layer(layer), - color(color), - color24(-1), - width(width), - linetype(linetype), - linetypeScale(linetypeScale), - handle(-1), - inPaperSpace(false) - { - - } - - /** - * Constructor for DXF attributes. - * - * @param layer Layer name for this entity or NULL for no layer - * (every entity should be on a named layer!). - * @param color Color number (0..256). 0 = BYBLOCK, 256 = BYLAYER. - * @param color24 24 bit color (0x00RRGGBB, see DXF reference). - * @param width Line thickness. Defaults to zero. -1 = BYLAYER, - * -2 = BYBLOCK, -3 = default width - * @param linetype Line type name or "BYLAYER" or "BYBLOCK". Defaults - * to "BYLAYER" - */ - DL_Attributes(const std::string& layer, - int color, int color24, int width, - const std::string& linetype, - int handle=-1) : - layer(layer), - color(color), - color24(color24), - width(width), - linetype(linetype), - linetypeScale(1.0), - handle(handle), - inPaperSpace(false) - { - } - - /** - * Sets the layer. If the given pointer points to NULL, the - * new layer name will be an empty but valid string. - */ - void setLayer(const std::string& layer) - { - this->layer = layer; - } - - /** - * @return Layer name. - */ - std::string getLayer() const - { - return layer; - } - - /** - * Sets the color. - * - * @see DL_Codes, dxfColors - */ - void setColor(int color) - { - this->color = color; - } - - /** - * Sets the 24bit color. - * - * @see DL_Codes, dxfColors - */ - void setColor24(int color) - { - this->color24 = color; - } - - /** - * @return Color. - * - * @see DL_Codes, dxfColors - */ - int getColor() const - { - return color; - } - - /** - * @return 24 bit color or -1 if no 24bit color is defined. - * - * @see DL_Codes, dxfColors - */ - int getColor24() const - { - return color24; - } - - /** - * Sets the width. - */ - void setWidth(int width) - { - this->width = width; - } - - /** - * @return Width. - */ - int getWidth() const - { - return width; - } - - /** - * Sets the line type. This can be any string and is not - * checked to be a valid line type. - */ - void setLinetype(const std::string& linetype) - { - this->linetype = linetype; - } - - /** - * Sets the entity specific line type scale. - */ - void setLinetypeScale(double linetypeScale) - { - this->linetypeScale = linetypeScale; - } - - double getLinetypeScale() const - { - return linetypeScale; - } - - /** - * @return Line type. - */ - std::string getLinetype() const - { - if (linetype.length()==0) - { - return "BYLAYER"; - } - else - { - return linetype; - } - } - - void setHandle(int h) - { - handle = h; - } - - int getHandle() const - { - return handle; - } - - void setInPaperSpace(bool on) - { - inPaperSpace = on; - } - - bool isInPaperSpace() const - { - return inPaperSpace; - } - -private: - std::string layer; - int color; - int color24; - int width; - std::string linetype; - double linetypeScale; - int handle; - - // DXF code 67 (true: entity in paper space, false: entity in model space (default): - bool inPaperSpace; -}; - -#endif - -// EOF diff --git a/src/libs/vdxf/dxflib/dl_codes.h b/src/libs/vdxf/dxflib/dl_codes.h deleted file mode 100644 index cf7ad34d8..000000000 --- a/src/libs/vdxf/dxflib/dl_codes.h +++ /dev/null @@ -1,556 +0,0 @@ -/**************************************************************************** -** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved. -** Copyright (C) 2001 Robert J. Campbell Jr. -** -** This file is part of the dxflib project. -** -** This file is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** Licensees holding valid dxflib Professional Edition licenses may use -** this file in accordance with the dxflib Commercial License -** Agreement provided with the Software. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.ribbonsoft.com for further details. -** -** Contact info@ribbonsoft.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -/** - * Defines common DXF codes and constants. - */ - -#ifndef DXF_CODES_H -#define DXF_CODES_H - -#include "dl_global.h" -#include "../vmisc/diagnostic.h" - -#if defined(Q_CC_MSVC) - #if (_MSC_VER > 1000) - #pragma once - #endif // _MSC_VER > 1000 -#endif // Q_CC_MSVC - -#define DL_DXF_MAXLINE 1024 -#define DL_DXF_MAXGROUPCODE 1100 - -// used to mark invalid vectors: -//#define DL_DXF_MAXDOUBLE 1.0E+10 - -/** - * Codes for colors and DXF versions. - */ -class DXFLIB_EXPORT DL_Codes -{ -public: - /** - * Standard DXF colors. - */ - enum color - { - black = 250, - green = 3, - red = 1, - brown = 15, - yellow = 2, - cyan = 4, - magenta = 6, - gray = 8, - blue = 5, - l_blue = 163, - l_green = 121, - l_cyan = 131, - l_red = 23, - l_magenta = 221, - l_gray = 252, - white = 7, - bylayer = 256, - byblock = 0 - }; - - /** - * Version numbers for the DXF Format. - */ - enum version - { - AC1009_MIN, // R12, minimalistic - AC1009, // R12 - AC1012, - AC1014, - AC1015 // R2000 - }; -}; - - -// Extended color palette: -// The first entry is only for direct indexing starting with [1] -// Color 1 is red (1,0,0) -const double dxfColors[][3] = -{ - {0,0,0}, // unused - {1,0,0}, // 1 - {1,1,0}, - {0,1,0}, - {0,1,1}, - {0,0,1}, - {1,0,1}, - {1,1,1}, // black or white - {0.5,0.5,0.5}, - {0.75,0.75,0.75}, - {1,0,0}, // 10 - {1,0.5,0.5}, - {0.65,0,0}, - {0.65,0.325,0.325}, - {0.5,0,0}, - {0.5,0.25,0.25}, - {0.3,0,0}, - {0.3,0.15,0.15}, - {0.15,0,0}, - {0.15,0.075,0.075}, - {1,0.25,0}, // 20 - {1,0.625,0.5}, - {0.65,0.1625,0}, - {0.65,0.4063,0.325}, - {0.5,0.125,0}, - {0.5,0.3125,0.25}, - {0.3,0.075,0}, - {0.3,0.1875,0.15}, - {0.15,0.0375,0}, - {0.15,0.0938,0.075}, - {1,0.5,0}, // 30 - {1,0.75,0.5}, - {0.65,0.325,0}, - {0.65,0.4875,0.325}, - {0.5,0.25,0}, - {0.5,0.375,0.25}, - {0.3,0.15,0}, - {0.3,0.225,0.15}, - {0.15,0.075,0}, - {0.15,0.1125,0.075}, - {1,0.75,0}, // 40 - {1,0.875,0.5}, - {0.65,0.4875,0}, - {0.65,0.5688,0.325}, - {0.5,0.375,0}, - {0.5,0.4375,0.25}, - {0.3,0.225,0}, - {0.3,0.2625,0.15}, - {0.15,0.1125,0}, - {0.15,0.1313,0.075}, - {1,1,0}, // 50 - {1,1,0.5}, - {0.65,0.65,0}, - {0.65,0.65,0.325}, - {0.5,0.5,0}, - {0.5,0.5,0.25}, - {0.3,0.3,0}, - {0.3,0.3,0.15}, - {0.15,0.15,0}, - {0.15,0.15,0.075}, - {0.75,1,0}, // 60 - {0.875,1,0.5}, - {0.4875,0.65,0}, - {0.5688,0.65,0.325}, - {0.375,0.5,0}, - {0.4375,0.5,0.25}, - {0.225,0.3,0}, - {0.2625,0.3,0.15}, - {0.1125,0.15,0}, - {0.1313,0.15,0.075}, - {0.5,1,0}, // 70 - {0.75,1,0.5}, - {0.325,0.65,0}, - {0.4875,0.65,0.325}, - {0.25,0.5,0}, - {0.375,0.5,0.25}, - {0.15,0.3,0}, - {0.225,0.3,0.15}, - {0.075,0.15,0}, - {0.1125,0.15,0.075}, - {0.25,1,0}, // 80 - {0.625,1,0.5}, - {0.1625,0.65,0}, - {0.4063,0.65,0.325}, - {0.125,0.5,0}, - {0.3125,0.5,0.25}, - {0.075,0.3,0}, - {0.1875,0.3,0.15}, - {0.0375,0.15,0}, - {0.0938,0.15,0.075}, - {0,1,0}, // 90 - {0.5,1,0.5}, - {0,0.65,0}, - {0.325,0.65,0.325}, - {0,0.5,0}, - {0.25,0.5,0.25}, - {0,0.3,0}, - {0.15,0.3,0.15}, - {0,0.15,0}, - {0.075,0.15,0.075}, - {0,1,0.25}, // 100 - {0.5,1,0.625}, - {0,0.65,0.1625}, - {0.325,0.65,0.4063}, - {0,0.5,0.125}, - {0.25,0.5,0.3125}, - {0,0.3,0.075}, - {0.15,0.3,0.1875}, - {0,0.15,0.0375}, - {0.075,0.15,0.0938}, - {0,1,0.5}, // 110 - {0.5,1,0.75}, - {0,0.65,0.325}, - {0.325,0.65,0.4875}, - {0,0.5,0.25}, - {0.25,0.5,0.375}, - {0,0.3,0.15}, - {0.15,0.3,0.225}, - {0,0.15,0.075}, - {0.075,0.15,0.1125}, - {0,1,0.75}, // 120 - {0.5,1,0.875}, - {0,0.65,0.4875}, - {0.325,0.65,0.5688}, - {0,0.5,0.375}, - {0.25,0.5,0.4375}, - {0,0.3,0.225}, - {0.15,0.3,0.2625}, - {0,0.15,0.1125}, - {0.075,0.15,0.1313}, - {0,1,1}, // 130 - {0.5,1,1}, - {0,0.65,0.65}, - {0.325,0.65,0.65}, - {0,0.5,0.5}, - {0.25,0.5,0.5}, - {0,0.3,0.3}, - {0.15,0.3,0.3}, - {0,0.15,0.15}, - {0.075,0.15,0.15}, - {0,0.75,1}, // 140 - {0.5,0.875,1}, - {0,0.4875,0.65}, - {0.325,0.5688,0.65}, - {0,0.375,0.5}, - {0.25,0.4375,0.5}, - {0,0.225,0.3}, - {0.15,0.2625,0.3}, - {0,0.1125,0.15}, - {0.075,0.1313,0.15}, - {0,0.5,1}, // 150 - {0.5,0.75,1}, - {0,0.325,0.65}, - {0.325,0.4875,0.65}, - {0,0.25,0.5}, - {0.25,0.375,0.5}, - {0,0.15,0.3}, - {0.15,0.225,0.3}, - {0,0.075,0.15}, - {0.075,0.1125,0.15}, - {0,0.25,1}, // 160 - {0.5,0.625,1}, - {0,0.1625,0.65}, - {0.325,0.4063,0.65}, - {0,0.125,0.5}, - {0.25,0.3125,0.5}, - {0,0.075,0.3}, - {0.15,0.1875,0.3}, - {0,0.0375,0.15}, - {0.075,0.0938,0.15}, - {0,0,1}, // 170 - {0.5,0.5,1}, - {0,0,0.65}, - {0.325,0.325,0.65}, - {0,0,0.5}, - {0.25,0.25,0.5}, - {0,0,0.3}, - {0.15,0.15,0.3}, - {0,0,0.15}, - {0.075,0.075,0.15}, - {0.25,0,1}, // 180 - {0.625,0.5,1}, - {0.1625,0,0.65}, - {0.4063,0.325,0.65}, - {0.125,0,0.5}, - {0.3125,0.25,0.5}, - {0.075,0,0.3}, - {0.1875,0.15,0.3}, - {0.0375,0,0.15}, - {0.0938,0.075,0.15}, - {0.5,0,1}, // 190 - {0.75,0.5,1}, - {0.325,0,0.65}, - {0.4875,0.325,0.65}, - {0.25,0,0.5}, - {0.375,0.25,0.5}, - {0.15,0,0.3}, - {0.225,0.15,0.3}, - {0.075,0,0.15}, - {0.1125,0.075,0.15}, - {0.75,0,1}, // 200 - {0.875,0.5,1}, - {0.4875,0,0.65}, - {0.5688,0.325,0.65}, - {0.375,0,0.5}, - {0.4375,0.25,0.5}, - {0.225,0,0.3}, - {0.2625,0.15,0.3}, - {0.1125,0,0.15}, - {0.1313,0.075,0.15}, - {1,0,1}, // 210 - {1,0.5,1}, - {0.65,0,0.65}, - {0.65,0.325,0.65}, - {0.5,0,0.5}, - {0.5,0.25,0.5}, - {0.3,0,0.3}, - {0.3,0.15,0.3}, - {0.15,0,0.15}, - {0.15,0.075,0.15}, - {1,0,0.75}, // 220 - {1,0.5,0.875}, - {0.65,0,0.4875}, - {0.65,0.325,0.5688}, - {0.5,0,0.375}, - {0.5,0.25,0.4375}, - {0.3,0,0.225}, - {0.3,0.15,0.2625}, - {0.15,0,0.1125}, - {0.15,0.075,0.1313}, - {1,0,0.5}, // 230 - {1,0.5,0.75}, - {0.65,0,0.325}, - {0.65,0.325,0.4875}, - {0.5,0,0.25}, - {0.5,0.25,0.375}, - {0.3,0,0.15}, - {0.3,0.15,0.225}, - {0.15,0,0.075}, - {0.15,0.075,0.1125}, - {1,0,0.25}, // 240 - {1,0.5,0.625}, - {0.65,0,0.1625}, - {0.65,0.325,0.4063}, - {0.5,0,0.125}, - {0.5,0.25,0.3125}, - {0.3,0,0.075}, - {0.3,0.15,0.1875}, - {0.15,0,0.0375}, - {0.15,0.075,0.0938}, - {0.33,0.33,0.33}, // 250 - {0.464,0.464,0.464}, - {0.598,0.598,0.598}, - {0.732,0.732,0.732}, - {0.866,0.866,0.866}, - {1,1,1} // 255 -} -; - - -// AutoCAD VERSION aliases -#define DL_VERSION_R12 DL_Codes::AC1009 -#define DL_VERSION_LT2 DL_Codes::AC1009 -#define DL_VERSION_R13 DL_Codes::AC1012 // not supported yet -#define DL_VERSION_LT95 DL_Codes::AC1012 // not supported yet -#define DL_VERSION_R14 DL_Codes::AC1014 // not supported yet -#define DL_VERSION_LT97 DL_Codes::AC1014 // not supported yet -#define DL_VERSION_LT98 DL_Codes::AC1014 // not supported yet -#define DL_VERSION_2000 DL_Codes::AC1015 -#define DL_VERSION_2002 DL_Codes::AC1015 - - -// DXF Group Codes: - -// Strings -#define DL_STRGRP_START 0 -#define DL_STRGRP_END 9 - -// Coordinates -#define DL_CRDGRP_START 10 -#define DL_CRDGRP_END 19 - -// Real values -#define DL_RLGRP_START 38 -#define DL_RLGRP_END 59 - -// Short integer values -#define DL_SHOGRP_START 60 -#define DL_SHOGRP_END 79 - -// New in Release 13, -#define DL_SUBCLASS 100 - -// More coordinates -#define DL_CRD2GRP_START 210 -#define DL_CRD2GRP_END 239 - -// Extended data strings -#define DL_ESTRGRP_START 1000 -#define DL_ESTRGRP_END 1009 - -// Extended data reals -#define DL_ERLGRP_START 1010 -#define DL_ERLGRP_END 1059 - - -#define DL_Y8_COORD_CODE 28 -#define DL_Z0_COORD_CODE 30 -#define DL_Z8_COORD_CODE 38 - -#define DL_POINT_COORD_CODE 10 -#define DL_INSERT_COORD_CODE 10 - -#define DL_CRD2GRP_START 210 -#define DL_CRD2GRP_END 239 - -#define DL_THICKNESS 39 -#define DL_FIRST_REAL_CODE THICKNESS -#define DL_LAST_REAL_CODE 59 -#define DL_FIRST_INT_CODE 60 -#define DL_ATTFLAGS_CODE 70 -#define DL_PLINE_FLAGS_CODE 70 -#define DL_LAYER_FLAGS_CODE 70 -#define DL_FLD_LEN_CODE 73 // Inside ATTRIB resbuf -#define DL_LAST_INT_CODE 79 -#define DL_X_EXTRU_CODE 210 -#define DL_Y_EXTRU_CODE 220 -#define DL_Z_EXTRU_CODE 230 -#define DL_COMMENT_CODE 999 - -// Start and endpoints of a line -#define DL_LINE_START_CODE 10 // Followed by x coord -#define DL_LINE_END_CODE 11 // Followed by x coord - -// Some codes used by blocks -#define DL_BLOCK_FLAGS_CODE 70 // An int containing flags -#define DL_BLOCK_BASE_CODE 10 // Origin of block definition -#define DL_XREF_DEPENDENT 16 // If a block contains an XREF -#define DL_XREF_RESOLVED 32 // If a XREF resolved ok -#define DL_REFERENCED 64 // If a block is ref'd in DWG - -#define DL_XSCALE_CODE 41 -#define DL_YSCALE_CODE 42 -#define DL_ANGLE_CODE 50 -#define DL_INS_POINT_CODE 10 // Followed by x of ins pnt -#define DL_NAME2_CODE 3 // Second appearance of name - -// Some codes used by circle entities -#define DL_CENTER_CODE 10 // Followed by x of center -#define DL_RADIUS_CODE 40 // Followd by radius of circle - -#define DL_COND_OP_CODE -4 // Conditional op,ads_ssget - -// When using ads_buildlist you MUST use RTDXF0 instead of these -#define DL_ENTITY_TYPE_CODE 0 // Then there is LINE, 3DFACE.. -#define DL_SES_CODE 0 // Start End String Code -#define DL_FILE_SEP_CODE 0 // File separator -#define DL_SOT_CODE 0 // Start Of Table -#define DL_TEXTVAL_CODE 1 -#define DL_NAME_CODE 2 -#define DL_BLOCK_NAME_CODE 2 -#define DL_SECTION_NAME_CODE 2 -#define DL_ENT_HAND_CODE 5 // What follows is hexa string -#define DL_TXT_STYLE_CODE 7 // Inside attributes -#define DL_LAYER_NAME_CODE 8 // What follows is layer name -#define DL_FIRST_XCOORD_CODE 10 // Group code x of 1st coord -#define DL_FIRST_YCOORD_CODE 20 // Group code y of 1st coord -#define DL_FIRST_ZCOORD_CODE 30 // Group code z of 1st coord -#define DL_L_START_CODE 10 -#define DL_L_END_CODE 11 -#define DL_TXTHI_CODE 40 -#define DL_SCALE_X_CODE 41 -#define DL_SCALE_Y_CODE 42 -#define DL_SCALE_Z_CODE 43 -#define DL_BULGE_CODE 42 // Used in PLINE verts for arcs -#define DL_ROTATION_CODE 50 -#define DL_COLOUR_CODE 62 // What follows is a color int -#define DL_LTYPE_CODE 6 // What follows is a linetype - - -// Attribute flags -#define DL_ATTS_FOLLOW_CODE 66 -#define DL_ATT_TAG_CODE 2 -#define DL_ATT_VAL_CODE 1 -#define DL_ATT_FLAGS_CODE 70 // 4 1 bit flags as follows... -#define DL_ATT_INVIS_FLAG 1 -#define DL_ATT_CONST_FLAG 2 -#define DL_ATT_VERIFY_FLAG 4 // Prompt and verify -#define DL_ATT_PRESET_FLAG 8 // No prompt and no verify - -// PLINE defines -// Flags -#define DL_OPEN_PLINE 0x00 -#define DL_CLOSED_PLINE 0x01 -#define DL_POLYLINE3D 0x80 -#define DL_PFACE_MESH 0x40 -#define DL_PGON_MESH 0x10 -// Vertices follow entity, required in POLYLINES -#define DL_VERTS_FOLLOW_CODE 66 // Value should always be 1 -#define DL_VERTEX_COORD_CODE 10 - - -// LAYER flags -#define DL_FROZEN 1 -#define DL_FROZEN_BY_DEF 2 -#define DL_LOCKED 4 -#define DL_OBJECT_USED 64 // Object is ref'd in the dwg - -#define DL_BLOCK_EN_CODE -2 // Block entity definition -#define DL_E_NAME -1 // Entity name - -// Extended data codes -#define DL_EXTD_SENTINEL (-3) -#define DL_EXTD_STR 1000 -#define DL_EXTD_APP_NAME 1001 -#define DL_EXTD_CTL_STR 1002 -#define DL_EXTD_LYR_STR 1003 -#define DL_EXTD_CHUNK 1004 -#define DL_EXTD_HANDLE 1005 -#define DL_EXTD_POINT 1010 -#define DL_EXTD_POS 1011 -#define DL_EXTD_DISP 1012 -#define DL_EXTD_DIR 1013 -#define DL_EXTD_FLOAT 1040 -#define DL_EXTD_DIST 1041 -#define DL_EXTD_SCALE 1042 -#define DL_EXTD_INT16 1070 -#define DL_EXTD_INT32 1071 - -// UCS codes for use in ads_trans -#define DL_WCS_TRANS_CODE 0 -#define DL_UCS_TRANS_CODE 1 -#define DL_DCS_TRANS_CODE 2 -#define DL_PCS_TRANS_CODE 3 - -#ifndef __has_cpp_attribute -# define __has_cpp_attribute(x) 0 -#endif - -#if __cplusplus > 201402L && __has_cpp_attribute(fallthrough) -# define DL_FALLTHROUGH [[fallthrough]]; -#elif defined(Q_CC_CLANG) && __cplusplus >= 201103L - /* clang's fallthrough annotations are only available starting in C++11. */ -# define DL_FALLTHROUGH [[clang::fallthrough]]; -#elif defined(Q_CC_MSVC) - /* - * MSVC's __fallthrough annotations are checked by /analyze (Code Analysis): - * https://msdn.microsoft.com/en-us/library/ms235402%28VS.80%29.aspx - */ -# include -# define DL_FALLTHROUGH __fallthrough; -#elif defined(Q_CC_GNU) && (__GNUC__ >= 7) -# define DL_FALLTHROUGH [[gnu::fallthrough]]; -#else -# define DL_FALLTHROUGH -#endif - -#endif - diff --git a/src/libs/vdxf/dxflib/dl_creationadapter.h b/src/libs/vdxf/dxflib/dl_creationadapter.h deleted file mode 100644 index f3d892a0e..000000000 --- a/src/libs/vdxf/dxflib/dl_creationadapter.h +++ /dev/null @@ -1,141 +0,0 @@ -/**************************************************************************** -** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved. -** -** This file is part of the dxflib project. -** -** This file is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** Licensees holding valid dxflib Professional Edition licenses may use -** this file in accordance with the dxflib Commercial License -** Agreement provided with the Software. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.ribbonsoft.com for further details. -** -** Contact info@ribbonsoft.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -#ifndef DL_CREATIONADAPTER_H -#define DL_CREATIONADAPTER_H - -#include "dl_global.h" - -#include "dl_creationinterface.h" - -/** - * An abstract adapter class for receiving DXF events when a DXF file is being read. - * The methods in this class are empty. This class exists as convenience for creating - * listener objects. - * - * @author Andrew Mustun - */ -class DXFLIB_EXPORT DL_CreationAdapter : public DL_CreationInterface -{ -public: - DL_CreationAdapter() {} - virtual ~DL_CreationAdapter(); - virtual void processCodeValuePair(quint32, const std::string&) {} - virtual void endSection() {} - virtual void addLayer(const DL_LayerData&) {} - virtual void addLinetype(const DL_LinetypeData&) {} - virtual void addLinetypeDash(double) {} - virtual void addBlock(const DL_BlockData&) {} - virtual void endBlock() {} - virtual void addTextStyle(const DL_StyleData&) {} - virtual void addPoint(const DL_PointData&) {} - virtual void addLine(const DL_LineData&) {} - virtual void addXLine(const DL_XLineData&) {} - virtual void addRay(const DL_RayData&) {} - - virtual void addArc(const DL_ArcData&) {} - virtual void addCircle(const DL_CircleData&) {} - virtual void addEllipse(const DL_EllipseData&) {} - - virtual void addPolyline(const DL_PolylineData&) {} - virtual void addVertex(const DL_VertexData&) {} - - virtual void addSpline(const DL_SplineData&) {} - virtual void addControlPoint(const DL_ControlPointData&) {} - virtual void addFitPoint(const DL_FitPointData&) {} - virtual void addKnot(const DL_KnotData&) {} - - virtual void addInsert(const DL_InsertData&) {} - - virtual void addMText(const DL_MTextData&) {} - virtual void addMTextChunk(const std::string&) {} - virtual void addText(const DL_TextData&) {} - virtual void addAttribute(const DL_AttributeData&) {} - - virtual void addDimAlign(const DL_DimensionData&, - const DL_DimAlignedData&) {} - virtual void addDimLinear(const DL_DimensionData&, - const DL_DimLinearData&) {} - virtual void addDimRadial(const DL_DimensionData&, - const DL_DimRadialData&) {} - virtual void addDimDiametric(const DL_DimensionData&, - const DL_DimDiametricData&) {} - virtual void addDimAngular(const DL_DimensionData&, - const DL_DimAngularData&) {} - virtual void addDimAngular3P(const DL_DimensionData&, - const DL_DimAngular3PData&) {} - virtual void addDimOrdinate(const DL_DimensionData&, - const DL_DimOrdinateData&) {} - virtual void addLeader(const DL_LeaderData&) {} - virtual void addLeaderVertex(const DL_LeaderVertexData&) {} - - virtual void addHatch(const DL_HatchData&) {} - - virtual void addTrace(const DL_TraceData&) {} - virtual void add3dFace(const DL_3dFaceData&) {} - virtual void addSolid(const DL_SolidData&) {} - - virtual void addImage(const DL_ImageData&) {} - virtual void linkImage(const DL_ImageDefData&) {} - virtual void addHatchLoop(const DL_HatchLoopData&) {} - virtual void addHatchEdge(const DL_HatchEdgeData&) {} - - virtual void addXRecord(const std::string&) {} - virtual void addXRecordString(int, const std::string&) {} - virtual void addXRecordReal(int, double) {} - virtual void addXRecordInt(int, int) {} - virtual void addXRecordBool(int, bool) {} - - virtual void addXDataApp(const std::string&) {} - virtual void addXDataString(int, const std::string&) {} - virtual void addXDataReal(int, double) {} - virtual void addXDataInt(int, int) {} - - virtual void addDictionary(const DL_DictionaryData&) {} - virtual void addDictionaryEntry(const DL_DictionaryEntryData&) {} - - virtual void endEntity() {} - - virtual void addComment(const std::string&) {} - - virtual void setVariableVector(const std::string&, double, double, double, int) {} - virtual void setVariableString(const std::string&, const std::string&, int) {} - virtual void setVariableInt(const std::string&, int, int) {} - virtual void setVariableDouble(const std::string&, double, int) {} -#ifdef DL_COMPAT - virtual void setVariableVector(const char*, double, double, double, int) {} - virtual void setVariableString(const char*, const char*, int) {} - virtual void setVariableInt(const char*, int, int) {} - virtual void setVariableDouble(const char*, double, int) {} - virtual void processCodeValuePair(quint32, char*) {} - virtual void addComment(const char*) {} - virtual void addMTextChunk(const char*) {} -#endif - virtual void endSequence() {} -}; - -DL_CreationAdapter::~DL_CreationAdapter() -{} - -#endif diff --git a/src/libs/vdxf/dxflib/dl_creationinterface.h b/src/libs/vdxf/dxflib/dl_creationinterface.h deleted file mode 100644 index f60548995..000000000 --- a/src/libs/vdxf/dxflib/dl_creationinterface.h +++ /dev/null @@ -1,378 +0,0 @@ -/**************************************************************************** -** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved. -** -** This file is part of the dxflib project. -** -** This file is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** Licensees holding valid dxflib Professional Edition licenses may use -** this file in accordance with the dxflib Commercial License -** Agreement provided with the Software. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.ribbonsoft.com for further details. -** -** Contact info@ribbonsoft.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -#ifndef DL_CREATIONINTERFACE_H -#define DL_CREATIONINTERFACE_H - -#include "dl_global.h" - -#include - -#include "dl_attributes.h" -#include "dl_codes.h" -#include "dl_entities.h" -#include "dl_extrusion.h" - -/** - * Abstract class (interface) for the creation of new entities. - * Inherit your class which takes care of the entities in the - * processed DXF file from this interface. - * - * Double arrays passed to your implementation contain 3 double - * values for x, y, z coordinates unless stated differently. - * - * @author Andrew Mustun - */ -class DXFLIB_EXPORT DL_CreationInterface -{ -public: - DL_CreationInterface() : extrusion(new DL_Extrusion), attributes() - { - } - - virtual ~DL_CreationInterface(); - - /** - * Called for every code / value tuple of the DXF file. The complete DXF file - * contents can be handled by the implemetation of this function. - */ - virtual void processCodeValuePair(quint32 groupCode, const std::string& groupValue) = 0; - - /** - * Called when a section (entity, table entry, etc.) is finished. - */ - virtual void endSection() = 0; - - /** - * Called for every layer. - */ - virtual void addLayer(const DL_LayerData& data) = 0; - - /** - * Called for every linetype. - */ - virtual void addLinetype(const DL_LinetypeData& data) = 0; - - /** - * Called for every dash in linetype pattern - */ - virtual void addLinetypeDash(double length) = 0; - - /** - * Called for every block. Note: all entities added after this - * command go into this block until endBlock() is called. - * - * @see endBlock() - */ - virtual void addBlock(const DL_BlockData& data) = 0; - - /** Called to end the current block */ - virtual void endBlock() = 0; - - /** Called for every text style */ - virtual void addTextStyle(const DL_StyleData& data) = 0; - - /** Called for every point */ - virtual void addPoint(const DL_PointData& data) = 0; - - /** Called for every line */ - virtual void addLine(const DL_LineData& data) = 0; - - /** Called for every xline */ - virtual void addXLine(const DL_XLineData& data) = 0; - - /** Called for every ray */ - virtual void addRay(const DL_RayData& data) = 0; - - /** Called for every arc */ - virtual void addArc(const DL_ArcData& data) = 0; - - /** Called for every circle */ - virtual void addCircle(const DL_CircleData& data) = 0; - - /** Called for every ellipse */ - virtual void addEllipse(const DL_EllipseData& data) = 0; - - /** Called for every polyline start */ - virtual void addPolyline(const DL_PolylineData& data) = 0; - - /** Called for every polyline vertex */ - virtual void addVertex(const DL_VertexData& data) = 0; - - /** Called for every spline */ - virtual void addSpline(const DL_SplineData& data) = 0; - - /** Called for every spline control point */ - virtual void addControlPoint(const DL_ControlPointData& data) = 0; - - /** Called for every spline fit point */ - virtual void addFitPoint(const DL_FitPointData& data) = 0; - - /** Called for every spline knot value */ - virtual void addKnot(const DL_KnotData& data) = 0; - - /** Called for every insert. */ - virtual void addInsert(const DL_InsertData& data) = 0; - - /** Called for every trace start */ - virtual void addTrace(const DL_TraceData& data) = 0; - - /** Called for every 3dface start */ - virtual void add3dFace(const DL_3dFaceData& data) = 0; - - /** Called for every solid start */ - virtual void addSolid(const DL_SolidData& data) = 0; - - - /** Called for every Multi Text entity. */ - virtual void addMText(const DL_MTextData& data) = 0; - - /** - * Called for additional text chunks for MTEXT entities. - * The chunks come at 250 character in size each. Note that - * those chunks come before the actual MTEXT entity. - */ - virtual void addMTextChunk(const std::string& text) = 0; - - /** Called for every Text entity. */ - virtual void addText(const DL_TextData& data) = 0; - - /** Called for every Block Attribute entity. */ - virtual void addAttribute(const DL_AttributeData& data) = 0; - - /** - * Called for every aligned dimension entity. - */ - virtual void addDimAlign(const DL_DimensionData& data, - const DL_DimAlignedData& edata) = 0; - /** - * Called for every linear or rotated dimension entity. - */ - virtual void addDimLinear(const DL_DimensionData& data, - const DL_DimLinearData& edata) = 0; - - /** - * Called for every radial dimension entity. - */ - virtual void addDimRadial(const DL_DimensionData& data, - const DL_DimRadialData& edata) = 0; - - /** - * Called for every diametric dimension entity. - */ - virtual void addDimDiametric(const DL_DimensionData& data, - const DL_DimDiametricData& edata) = 0; - - /** - * Called for every angular dimension (2 lines version) entity. - */ - virtual void addDimAngular(const DL_DimensionData& data, - const DL_DimAngularData& edata) = 0; - - /** - * Called for every angular dimension (3 points version) entity. - */ - virtual void addDimAngular3P(const DL_DimensionData& data, - const DL_DimAngular3PData& edata) = 0; - - /** - * Called for every ordinate dimension entity. - */ - virtual void addDimOrdinate(const DL_DimensionData& data, - const DL_DimOrdinateData& edata) = 0; - - /** - * Called for every leader start. - */ - virtual void addLeader(const DL_LeaderData& data) = 0; - - /** - * Called for every leader vertex - */ - virtual void addLeaderVertex(const DL_LeaderVertexData& data) = 0; - - /** - * Called for every hatch entity. - */ - virtual void addHatch(const DL_HatchData& data) = 0; - - /** - * Called for every image entity. - */ - virtual void addImage(const DL_ImageData& data) = 0; - - /** - * Called for every image definition. - */ - virtual void linkImage(const DL_ImageDefData& data) = 0; - - /** - * Called for every hatch loop. - */ - virtual void addHatchLoop(const DL_HatchLoopData& data) = 0; - - /** - * Called for every hatch edge entity. - */ - virtual void addHatchEdge(const DL_HatchEdgeData& data) = 0; - - /** - * Called for every XRecord with the given handle. - */ - virtual void addXRecord(const std::string& handle) = 0; - - /** - * Called for XRecords of type string. - */ - virtual void addXRecordString(int code, const std::string& value) = 0; - - /** - * Called for XRecords of type double. - */ - virtual void addXRecordReal(int code, double value) = 0; - - /** - * Called for XRecords of type int. - */ - virtual void addXRecordInt(int code, int value) = 0; - - /** - * Called for XRecords of type bool. - */ - virtual void addXRecordBool(int code, bool value) = 0; - - /** - * Called for every beginning of an XData section of the given application. - */ - virtual void addXDataApp(const std::string& appId) = 0; - - /** - * Called for XData tuples. - */ - virtual void addXDataString(int code, const std::string& value) = 0; - - /** - * Called for XData tuples. - */ - virtual void addXDataReal(int code, double value) = 0; - - /** - * Called for XData tuples. - */ - virtual void addXDataInt(int code, int value) = 0; - - /** - * Called for dictionary objects. - */ - virtual void addDictionary(const DL_DictionaryData& data) = 0; - - /** - * Called for dictionary entries. - */ - virtual void addDictionaryEntry(const DL_DictionaryEntryData& data) = 0; - - /** - * Called after an entity has been completed. - */ - virtual void endEntity() = 0; - - /** - * Called for every comment in the DXF file (code 999). - */ - virtual void addComment(const std::string& comment) = 0; - - /** - * Called for every vector variable in the DXF file (e.g. "$EXTMIN"). - */ - virtual void setVariableVector(const std::string& key, double v1, double v2, double v3, int code) = 0; - - /** - * Called for every string variable in the DXF file (e.g. "$ACADVER"). - */ - virtual void setVariableString(const std::string& key, const std::string& value, int code) = 0; - - /** - * Called for every int variable in the DXF file (e.g. "$ACADMAINTVER"). - */ - virtual void setVariableInt(const std::string& key, int value, int code) = 0; - - /** - * Called for every double variable in the DXF file (e.g. "$DIMEXO"). - */ - virtual void setVariableDouble(const std::string& key, double value, int code) = 0; - -#ifdef DL_COMPAT - virtual void setVariableVector(const char* key, double v1, double v2, double v3, int code) = 0; - virtual void setVariableString(const char* key, const char* value, int code) = 0; - virtual void setVariableInt(const char* key, int value, int code) = 0; - virtual void setVariableDouble(const char* key, double value, int code) = 0; - virtual void processCodeValuePair(quint32 groupCode, char* groupValue) = 0; - virtual void addComment(const char* comment) = 0; - virtual void addMTextChunk(const char* text) = 0; -#endif - - /** - * Called when a SEQEND occurs (when a POLYLINE or ATTRIB is done) - */ - virtual void endSequence() = 0; - - /** Sets the current attributes for entities. */ - void setAttributes(const DL_Attributes& attrib) - { - attributes = attrib; - } - - /** @return the current attributes used for new entities. */ - DL_Attributes getAttributes() const - { - return attributes; - } - - /** Sets the current attributes for entities. */ - void setExtrusion(double dx, double dy, double dz, double elevation) - { - extrusion->setDirection(dx, dy, dz); - extrusion->setElevation(elevation); - } - - /** @return the current attributes used for new entities. */ - DL_Extrusion* getExtrusion() - { - return extrusion; - } - -private: - Q_DISABLE_COPY(DL_CreationInterface) - -protected: - DL_Extrusion *extrusion; - DL_Attributes attributes; -}; - -DL_CreationInterface::~DL_CreationInterface() -{ - delete extrusion; -} - -#endif diff --git a/src/libs/vdxf/dxflib/dl_dxf.cpp b/src/libs/vdxf/dxflib/dl_dxf.cpp deleted file mode 100644 index de4e88a02..000000000 --- a/src/libs/vdxf/dxflib/dl_dxf.cpp +++ /dev/null @@ -1,5981 +0,0 @@ -/**************************************************************************** -** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved. -** -** This file is part of the dxflib project. -** -** This file is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** Licensees holding valid dxflib Professional Edition licenses may use -** this file in accordance with the dxflib Commercial License -** Agreement provided with the Software. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.ribbonsoft.com for further details. -** -** Contact info@ribbonsoft.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -#include "dl_dxf.h" - -#include -#if defined(__GNUC__) && !defined(__APPLE__) -#if (__GNUC__ * 100 + __GNUC_MINOR__) > 406 -#include -#endif -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../vmisc/diagnostic.h" -#include "dl_attributes.h" -#include "dl_codes.h" -#include "dl_writer_ascii.h" -#include "../dxfdef.h" -#include "dl_creationinterface.h" -#include "dl_entities.h" -#include "iostream" -#include "strlcpy.h" - -/** - * Default constructor. - */ -DL_Dxf::DL_Dxf() - : version(DL_VERSION_2000), - polylineLayer(), - vertices(nullptr), - maxVertices(0), - vertexIndex(0), - - knots(nullptr), - maxKnots(0), - knotIndex(0), - - weights(nullptr), - weightIndex(0), - - controlPoints(nullptr), - maxControlPoints(0), - controlPointIndex(0), - - fitPoints(nullptr), - maxFitPoints(0), - fitPointIndex(0), - - leaderVertices(nullptr), - maxLeaderVertices(0), - leaderVertexIndex(0), - - firstHatchLoop(), hatchEdge(), hatchEdges(), - xRecordHandle(), xRecordValues(), groupCodeTmp(), groupCode(), groupValue(), - currentObjectType(), settingValue(), settingKey(), values(), firstCall(), attrib(), - libVersion(), appDictionaryHandle(), styleHandleStd() -{ -} - - - -/** - * Destructor. - */ -DL_Dxf::~DL_Dxf() -{ - delete[] vertices; - delete[] knots; - delete[] controlPoints; - delete[] fitPoints; - delete[] weights; - delete[] leaderVertices; -} - - - -/** - * @brief Reads the given file and calls the appropriate functions in - * the given creation interface for every entity found in the file. - * - * @param file Input - * Path and name of file to read - * @param creationInterface - * Pointer to the class which takes care of the entities in the file. - * - * @retval true If \p file could be opened. - * @retval false If \p file could not be opened. - */ -bool DL_Dxf::in(const std::string& file, DL_CreationInterface* creationInterface) -{ - FILE *fp; - firstCall = true; - currentObjectType = DL_UNKNOWN; - -QT_WARNING_PUSH -QT_WARNING_DISABLE_MSVC(4996) - fp = fopen(file.c_str(), "rt"); -QT_WARNING_POP - - if (fp) - { - while (readDxfGroups(fp, creationInterface)) {} - fclose(fp); - return true; - } - - return false; -} - - - -/** - * Reads a DXF file from an existing stream. - * - * @param stream The string stream. - * @param creationInterface - * Pointer to the class which takes care of the entities in the file. - * - * @retval true If \p file could be opened. - * @retval false If \p file could not be opened. - */ -bool DL_Dxf::in(std::stringstream& stream, - DL_CreationInterface* creationInterface) -{ - - if (stream.good()) - { - firstCall=true; - currentObjectType = DL_UNKNOWN; - while (readDxfGroups(stream, creationInterface)) {} - return true; - } - return false; -} - - - -/** - * @brief Reads a group couplet from a DXF file. Calls another function - * to process it. - * - * A group couplet consists of two lines that represent a single - * piece of data. An integer constant on the first line indicates - * the type of data. The value is on the next line.\n - * - * This function reads a couplet, determines the type of data, and - * passes the value to the the appropriate handler function of - * \p creationInterface.\n - * - * \p fp is advanced so that the next call to \p readDXFGroups() reads - * the next couplet in the file. - * - * @param fp Handle of input file - * @param creationInterface Handle of class which processes entities - * in the file - * - * @retval true If EOF not reached. - * @retval false If EOF reached. - */ -bool DL_Dxf::readDxfGroups(FILE *fp, DL_CreationInterface* creationInterface) -{ - // Read one group of the DXF file and strip the lines: - if (DL_Dxf::getStrippedLine(groupCodeTmp, DL_DXF_MAXLINE, fp) && - DL_Dxf::getStrippedLine(groupValue, DL_DXF_MAXLINE, fp, false) ) - { - static int line = 1; - - groupCode = static_cast(toInt(groupCodeTmp)); - - creationInterface->processCodeValuePair(groupCode, groupValue); - line+=2; - processDXFGroup(creationInterface, static_cast(groupCode), groupValue); - } - - return !feof(fp); -} - - - -/** - * Same as above but for stringstreams. - */ -bool DL_Dxf::readDxfGroups(std::stringstream& stream, - DL_CreationInterface* creationInterface) -{ - // Read one group of the DXF file and chop the lines: - if (DL_Dxf::getStrippedLine(groupCodeTmp, DL_DXF_MAXLINE, stream) && - DL_Dxf::getStrippedLine(groupValue, DL_DXF_MAXLINE, stream, false) ) - { - static int line = 1; - - groupCode = static_cast(toInt(groupCodeTmp)); - - line+=2; - processDXFGroup(creationInterface, static_cast(groupCode), groupValue); - } - return !stream.eof(); -} - - - -/** - * @brief Reads line from file & strips whitespace at start and newline - * at end. - * - * @param s Output\n - * Pointer to character array that chopped line will be returned in. - * @param size Size of \p s. (Including space for NULL.) - * @param stream Input\n - * Handle of input file. - * - * @retval true if line could be read - * @retval false if \p fp is already at end of file - * - * @todo Change function to use safer FreeBSD strl* functions - * @todo Is it a problem if line is blank (i.e., newline only)? - * Then, when function returns, (s==NULL). - */ -bool DL_Dxf::getStrippedLine(std::string& s, quint32 size, FILE *stream, bool stripSpace) -{ - if (!feof(stream)) - { - // The whole line in the file. Includes space for NULL. - char* wholeLine = new char[size]; - // Only the useful part of the line - char* line; - - line = fgets(wholeLine, static_cast(size), stream); - - if (line!=NULL && line[0] != '\0') // Evaluates to fgets() retval - { - // line == wholeLine at this point. - // Both guaranteed to be NULL terminated. - - // Strip leading whitespace and trailing CR/LF. - stripWhiteSpace(&line, stripSpace); - - s = line; - assert(size > s.length()); - } - - delete[] wholeLine; // Done with wholeLine - - return true; - } - else - { - s.clear(); - return false; - } -} - - - -/** - * Same as above but for stringstreams. - */ -bool DL_Dxf::getStrippedLine(std::string &s, quint32 size, - std::stringstream& stream, bool stripSpace) -{ - - if (!stream.eof()) - { - // Only the useful part of the line - char* line = new char[size+1]; - char* oriLine = line; - stream.getline(line, static_cast(size)); - stripWhiteSpace(&line, stripSpace); - s = line; - assert(size > s.length()); - delete[] oriLine; - return true; - } - else - { - s[0] = '\0'; - return false; - } -} - - - -/** - * @brief Strips leading whitespace and trailing Carriage Return (CR) - * and Line Feed (LF) from NULL terminated string. - * - * @param s Input and output. - * NULL terminates string. - * - * @retval true if \p s is non-NULL - * @retval false if \p s is NULL - */ -bool DL_Dxf::stripWhiteSpace(char** s, bool stripSpace) -{ - // last non-NULL char: - int lastChar = static_cast(strlen(*s) - 1); - - // Is last character CR or LF? - while ( (lastChar >= 0) && - (((*s)[lastChar] == 10) || ((*s)[lastChar] == 13) || - (stripSpace && ((*s)[lastChar] == ' ' || ((*s)[lastChar] == '\t')))) ) - { - (*s)[lastChar] = '\0'; - lastChar--; - } - - // Skip whitespace, excluding \n, at beginning of line - if (stripSpace) - { - while ((*s)[0]==' ' || (*s)[0]=='\t') - { - ++(*s); - } - } - - return ((*s) ? true : false); -} - - - -/** - * Processes a group (pair of group code and value). - * - * @param creationInterface Handle to class that creates entities and - * other CAD data from DXF group codes - * - * @param groupCode Constant indicating the data type of the group. - * @param groupValue The data value. - * - * @retval true if done processing current entity and new entity begun - * @retval false if not done processing current entity -*/ -bool DL_Dxf::processDXFGroup(DL_CreationInterface* creationInterface, - int groupCode, const std::string& groupValue) -{ - - //printf("%d\n", groupCode); - //printf("%s\n", groupValue.c_str()); - - // Init values on first call - if (firstCall) - { - settingValue[0] = '\0'; - firstCall=false; - } - - // Indicates comment or dxflib version: - if (groupCode==999) - { - if (!groupValue.empty()) - { - if (groupValue.substr(0, 6)=="dxflib") - { - libVersion = getLibVersion(groupValue.substr(7)); - } - - addComment(creationInterface, groupValue); - } - } - - // Indicates start of new entity or variable: - else if (groupCode==0 || groupCode==9) - { - // If new entity is encountered, the last one is complete. - // Prepare default attributes for next entity: - std::string layer = getStringValue(8, "0"); - - int width; - // Compatibility with qcad1: - if (hasValue(39) && !hasValue(370)) - { - width = getIntValue(39, -1); - } - // since autocad 2002: - else if (hasValue(370)) - { - width = getIntValue(370, -1); - } - // default to BYLAYER: - else - { - width = -1; - } - - int color; - color = getIntValue(62, 256); - int color24; - color24 = getIntValue(420, -1); - int handle; - handle = getInt16Value(5, -1); - - std::string linetype = getStringValue(6, "BYLAYER"); - - attrib = DL_Attributes(layer, // layer - color, // color - color24, // 24 bit color - width, // width - linetype, // linetype - handle); // handle - attrib.setInPaperSpace(static_cast(getIntValue(67, 0))); - attrib.setLinetypeScale(getRealValue(48, 1.0)); - creationInterface->setAttributes(attrib); - - int elevationGroupCode=30; - if (currentObjectType==DL_ENTITY_LWPOLYLINE ) - { - // see lwpolyline group codes reference - elevationGroupCode=38; - } - else - { - // see polyline group codes reference - elevationGroupCode=30; - } - - creationInterface->setExtrusion(getRealValue(210, 0.0), - getRealValue(220, 0.0), - getRealValue(230, 1.0), - getRealValue(elevationGroupCode, 0.0)); - - // Add the previously parsed entity via creationInterface - switch (currentObjectType) - { - case DL_SETTING: - addSetting(creationInterface); - break; - - case DL_LAYER: - addLayer(creationInterface); - break; - - case DL_LINETYPE: - addLinetype(creationInterface); - break; - - case DL_BLOCK: - addBlock(creationInterface); - break; - - case DL_ENDBLK: - endBlock(creationInterface); - break; - - case DL_STYLE: - addTextStyle(creationInterface); - break; - - case DL_ENTITY_POINT: - addPoint(creationInterface); - break; - - case DL_ENTITY_LINE: - addLine(creationInterface); - break; - - case DL_ENTITY_XLINE: - addXLine(creationInterface); - break; - - case DL_ENTITY_RAY: - addRay(creationInterface); - break; - - case DL_ENTITY_POLYLINE: - case DL_ENTITY_LWPOLYLINE: - addPolyline(creationInterface); - break; - - case DL_ENTITY_VERTEX: - addVertex(creationInterface); - break; - - case DL_ENTITY_SPLINE: - addSpline(creationInterface); - break; - - case DL_ENTITY_ARC: - addArc(creationInterface); - break; - - case DL_ENTITY_CIRCLE: - addCircle(creationInterface); - break; - - case DL_ENTITY_ELLIPSE: - addEllipse(creationInterface); - break; - - case DL_ENTITY_INSERT: - addInsert(creationInterface); - break; - - case DL_ENTITY_MTEXT: - addMText(creationInterface); - break; - - case DL_ENTITY_TEXT: - addText(creationInterface); - break; - - case DL_ENTITY_ATTRIB: - addAttribute(creationInterface); - break; - - case DL_ENTITY_DIMENSION: - { - int type = (getIntValue(70, 0)&0x07); - - switch (type) - { - case 0: - addDimLinear(creationInterface); - break; - - case 1: - addDimAligned(creationInterface); - break; - - case 2: - addDimAngular(creationInterface); - break; - - case 3: - addDimDiametric(creationInterface); - break; - - case 4: - addDimRadial(creationInterface); - break; - - case 5: - addDimAngular3P(creationInterface); - break; - - case 6: - addDimOrdinate(creationInterface); - break; - - default: - break; - } - } - break; - - case DL_ENTITY_LEADER: - addLeader(creationInterface); - break; - - case DL_ENTITY_HATCH: - //addHatch(creationInterface); - handleHatchData(creationInterface); - break; - - case DL_ENTITY_IMAGE: - addImage(creationInterface); - break; - - case DL_ENTITY_IMAGEDEF: - addImageDef(creationInterface); - break; - - case DL_ENTITY_TRACE: - addTrace(creationInterface); - break; - - case DL_ENTITY_3DFACE: - add3dFace(creationInterface); - break; - - case DL_ENTITY_SOLID: - addSolid(creationInterface); - break; - - case DL_ENTITY_SEQEND: - endSequence(creationInterface); - break; - - default: - break; - } - - creationInterface->endSection(); - - // reset all values (they are not persistent and only this - // way we can set defaults for omitted values) -// for (int i=0; iaddComment(comment); -} - -void DL_Dxf::addDictionary(DL_CreationInterface* creationInterface) -{ - creationInterface->addDictionary(DL_DictionaryData(getStringValue(5, ""))); -} - -void DL_Dxf::addDictionaryEntry(DL_CreationInterface* creationInterface) -{ - creationInterface->addDictionaryEntry(DL_DictionaryEntryData(getStringValue(3, ""), getStringValue(350, ""))); -} - - - -/** - * Adds a variable from the DXF file. - */ -void DL_Dxf::addSetting(DL_CreationInterface* creationInterface) -{ - int c = -1; - std::map::iterator it = values.begin(); - if (it!=values.end()) - { - c = it->first; - } -// for (int i=0; i<=380; ++i) { -// if (values[i][0]!='\0') { -// c = i; -// break; -// } -// } - - // string - if (c>=0 && c<=9) - { - creationInterface->setVariableString(settingKey, values[c], c); -#ifdef DL_COMPAT - // backwards compatibility: - creationInterface->setVariableString(settingKey.c_str(), values[c].c_str(), c); -#endif - } - // vector - else if (c>=10 && c<=39) - { - if (c==10) - { - creationInterface->setVariableVector( - settingKey, - getRealValue(c, 0.0), - getRealValue(c+10, 0.0), - getRealValue(c+20, 0.0), - c); - } - } - // double - else if (c>=40 && c<=59) - { - creationInterface->setVariableDouble(settingKey, getRealValue(c, 0.0), c); - } - // int - else if (c>=60 && c<=99) - { - creationInterface->setVariableInt(settingKey, getIntValue(c, 0), c); - } - // misc - else if (c>=0) - { - creationInterface->setVariableString(settingKey, getStringValue(c, ""), c); - } -} - - - -/** - * Adds a layer that was read from the file via the creation interface. - */ -void DL_Dxf::addLayer(DL_CreationInterface* creationInterface) -{ - // correct some invalid attributes for layers: - attrib = creationInterface->getAttributes(); - if (attrib.getColor()==256 || attrib.getColor()==0) - { - attrib.setColor(7); - } - if (attrib.getWidth()<0) - { - attrib.setWidth(1); - } - - std::string linetype = attrib.getLinetype(); - std::transform(linetype.begin(), linetype.end(), linetype.begin(), ::toupper); - if (linetype=="BYLAYER" || linetype=="BYBLOCK") - { - attrib.setLinetype("CONTINUOUS"); - } - - // add layer - std::string name = getStringValue(2, ""); - if (name.length()==0) - { - return; - } - - creationInterface->addLayer(DL_LayerData(name, getIntValue(70, 0))); -} - -/** - * Adds a linetype that was read from the file via the creation interface. - */ -void DL_Dxf::addLinetype(DL_CreationInterface* creationInterface) -{ - std::string name = getStringValue(2, ""); - if (name.length()==0) - { - return; - } - int numDashes = getIntValue(73, 0); - //double dashes[numDashes]; - - DL_LinetypeData d( - // name: - name, - // description: - getStringValue(3, ""), - // flags - getIntValue(70, 0), - // number of dashes: - numDashes, - // pattern length: - getRealValue(40, 0.0) - // pattern: - //dashes - ); - - if (name != "By Layer" && name != "By Block" && name != "BYLAYER" && name != "BYBLOCK") - { - creationInterface->addLinetype(d); - } -} - -/** - * Handles all dashes in linetype pattern. - */ -bool DL_Dxf::handleLinetypeData(DL_CreationInterface* creationInterface) -{ - if (groupCode == 49) - { - creationInterface->addLinetypeDash(toReal(groupValue)); - return true; - } - - return false; -} - - -/** - * Adds a block that was read from the file via the creation interface. - */ -void DL_Dxf::addBlock(DL_CreationInterface* creationInterface) -{ - std::string name = getStringValue(2, ""); - if (name.length()==0) - { - return; - } - - DL_BlockData d( - // Name: - name, - // flags: - getIntValue(70, 0), - // base point: - getRealValue(10, 0.0), - getRealValue(20, 0.0), - getRealValue(30, 0.0)); - - creationInterface->addBlock(d); -} - - - -/** - * Ends a block that was read from the file via the creation interface. - */ -void DL_Dxf::endBlock(DL_CreationInterface* creationInterface) -{ - creationInterface->endBlock(); -} - - - -void DL_Dxf::addTextStyle(DL_CreationInterface* creationInterface) -{ - std::string name = getStringValue(2, ""); - if (name.length()==0) - { - return; - } - - DL_StyleData d( - // name: - name, - // flags - getIntValue(70, 0), - // fixed text heigth: - getRealValue(40, 0.0), - // width factor: - getRealValue(41, 0.0), - // oblique angle: - getRealValue(50, 0.0), - // text generation flags: - getIntValue(71, 0), - // last height used: - getRealValue(42, 0.0), - // primart font file: - getStringValue(3, ""), - // big font file: - getStringValue(4, "") - ); - creationInterface->addTextStyle(d); -} - - -/** - * Adds a point entity that was read from the file via the creation interface. - */ -void DL_Dxf::addPoint(DL_CreationInterface* creationInterface) -{ - DL_PointData d(getRealValue(10, 0.0), - getRealValue(20, 0.0), - getRealValue(30, 0.0)); - creationInterface->addPoint(d); -} - - - -/** - * Adds a line entity that was read from the file via the creation interface. - */ -void DL_Dxf::addLine(DL_CreationInterface* creationInterface) -{ - DL_LineData d(getRealValue(10, 0.0), - getRealValue(20, 0.0), - getRealValue(30, 0.0), - getRealValue(11, 0.0), - getRealValue(21, 0.0), - getRealValue(31, 0.0)); - - creationInterface->addLine(d); -} - -/** - * Adds an xline entity that was read from the file via the creation interface. - */ -void DL_Dxf::addXLine(DL_CreationInterface* creationInterface) -{ - DL_XLineData d(getRealValue(10, 0.0), - getRealValue(20, 0.0), - getRealValue(30, 0.0), - getRealValue(11, 0.0), - getRealValue(21, 0.0), - getRealValue(31, 0.0)); - - creationInterface->addXLine(d); -} - -/** - * Adds a ray entity that was read from the file via the creation interface. - */ -void DL_Dxf::addRay(DL_CreationInterface* creationInterface) -{ - DL_RayData d(getRealValue(10, 0.0), - getRealValue(20, 0.0), - getRealValue(30, 0.0), - getRealValue(11, 0.0), - getRealValue(21, 0.0), - getRealValue(31, 0.0)); - - creationInterface->addRay(d); -} - - - -/** - * Adds a polyline entity that was read from the file via the creation interface. - */ -void DL_Dxf::addPolyline(DL_CreationInterface* creationInterface) -{ - DL_PolylineData pd(maxVertices, getIntValue(71, 0), getIntValue(72, 0), getIntValue(70, 0), getRealValue(38, 0)); - creationInterface->addPolyline(pd); - - maxVertices = std::min(maxVertices, vertexIndex+1); - - if (currentObjectType==DL_ENTITY_LWPOLYLINE) - { - for (int i=0; iaddVertex(d); - } - creationInterface->endEntity(); - } -} - - - -/** - * Adds a polyline vertex entity that was read from the file - * via the creation interface. - */ -void DL_Dxf::addVertex(DL_CreationInterface* creationInterface) -{ - - // vertex defines a face of the mesh if its vertex flags group has the - // 128 bit set but not the 64 bit. 10, 20, 30 are irrelevant and set to - // 0 in this case - if ((getIntValue(70, 0)&128) && !(getIntValue(70, 0)&64)) - { - return; - } - - DL_VertexData d(getRealValue(10, 0.0), - getRealValue(20, 0.0), - getRealValue(30, 0.0), - getRealValue(42, 0.0)); - - creationInterface->addVertex(d); -} - - -/** - * Adds a spline entity that was read from the file via the creation interface. - */ -void DL_Dxf::addSpline(DL_CreationInterface* creationInterface) -{ - DL_SplineData sd(getIntValue(71, 3), - maxKnots, - maxControlPoints, - maxFitPoints, - getIntValue(70, 4)); - - sd.tangentStartX = getRealValue(12, 0.0); - sd.tangentStartY = getRealValue(22, 0.0); - sd.tangentStartZ = getRealValue(32, 0.0); - sd.tangentEndX = getRealValue(13, 0.0); - sd.tangentEndY = getRealValue(23, 0.0); - sd.tangentEndZ = getRealValue(33, 0.0); - - creationInterface->addSpline(sd); - - int i; - for (i=0; iaddControlPoint(d); - } - for (i=0; iaddFitPoint(d); - } - for (i=0; iaddKnot(k); - } - creationInterface->endEntity(); -} - - - -/** - * Adds an arc entity that was read from the file via the creation interface. - */ -void DL_Dxf::addArc(DL_CreationInterface* creationInterface) -{ - DL_ArcData d(getRealValue(10, 0.0), - getRealValue(20, 0.0), - getRealValue(30, 0.0), - getRealValue(40, 0.0), - getRealValue(50, 0.0), - getRealValue(51, 0.0)); - - creationInterface->addArc(d); -} - - - -/** - * Adds a circle entity that was read from the file via the creation interface. - */ -void DL_Dxf::addCircle(DL_CreationInterface* creationInterface) -{ - DL_CircleData d(getRealValue(10, 0.0), - getRealValue(20, 0.0), - getRealValue(30, 0.0), - getRealValue(40, 0.0)); - - creationInterface->addCircle(d); -} - - - -/** - * Adds an ellipse entity that was read from the file via the creation interface. - */ -void DL_Dxf::addEllipse(DL_CreationInterface* creationInterface) -{ - DL_EllipseData d(getRealValue(10, 0.0), - getRealValue(20, 0.0), - getRealValue(30, 0.0), - getRealValue(11, 0.0), - getRealValue(21, 0.0), - getRealValue(31, 0.0), - getRealValue(40, 1.0), - getRealValue(41, 0.0), - getRealValue(42, M_2PI)); - - creationInterface->addEllipse(d); -} - - - -/** - * Adds an insert entity that was read from the file via the creation interface. - */ -void DL_Dxf::addInsert(DL_CreationInterface* creationInterface) -{ - //printf("addInsert\n"); - //printf("code 50: %s\n", values[50]); - //printf("code 50 length: %d\n", strlen(values[50])); - //printf("code 50:\n"); - //getRealValue(50, 0.0); - - std::string name = getStringValue(2, ""); - if (name.length()==0) - { - return; - } - - DL_InsertData d(name, - // insertion point - getRealValue(10, 0.0), - getRealValue(20, 0.0), - getRealValue(30, 0.0), - // scale: - getRealValue(41, 1.0), - getRealValue(42, 1.0), - getRealValue(43, 1.0), - // angle (deg): - getRealValue(50, 0.0), - // cols / rows: - getIntValue(70, 1), - getIntValue(71, 1), - // spacing: - getRealValue(44, 0.0), - getRealValue(45, 0.0)); - - creationInterface->addInsert(d); -} - - - -/** - * Adds a trace entity (4 edge closed polyline) that was read from the file via the creation interface. - * - * @author AHM - */ -void DL_Dxf::addTrace(DL_CreationInterface* creationInterface) -{ - DL_TraceData td; - - for (int k = 0; k < 4; k++) - { - td.x[k] = getRealValue(10 + k, 0.0); - td.y[k] = getRealValue(20 + k, 0.0); - td.z[k] = getRealValue(30 + k, 0.0); - } - creationInterface->addTrace(td); -} - - - -/** - * Adds a 3dface entity that was read from the file via the creation interface. - */ -void DL_Dxf::add3dFace(DL_CreationInterface* creationInterface) -{ - DL_3dFaceData td; - - for (int k = 0; k < 4; k++) - { - td.x[k] = getRealValue(10 + k, 0.0); - td.y[k] = getRealValue(20 + k, 0.0); - td.z[k] = getRealValue(30 + k, 0.0); - } - creationInterface->add3dFace(td); -} - - - -/** - * Adds a solid entity (filled trace) that was read from the file via the creation interface. - * - * @author AHM - */ -void DL_Dxf::addSolid(DL_CreationInterface* creationInterface) -{ - DL_SolidData sd; - - for (int k = 0; k < 4; k++) - { - sd.x[k] = getRealValue(10 + k, 0.0); - sd.y[k] = getRealValue(20 + k, 0.0); - sd.z[k] = getRealValue(30 + k, 0.0); - } - creationInterface->addSolid(sd); -} - - -/** - * Adds an MText entity that was read from the file via the creation interface. - */ -void DL_Dxf::addMText(DL_CreationInterface* creationInterface) -{ - double angle = 0.0; - - if (hasValue(50)) - { - if (libVersion<=0x02000200) - { - // wrong but compatible with dxflib <=2.0.2.0 (angle stored in rad): - angle = getRealValue(50, 0.0); - } - else - { - angle = (getRealValue(50, 0.0)*M_2PI)/360.0; - } - } - else if (hasValue(11) && hasValue(21)) - { - double x = getRealValue(11, 0.0); - double y = getRealValue(21, 0.0); - - if (fabs(x)<1.0e-6) - { - if (y>0.0) - { - angle = M_PI_2; - } - else - { - angle = M_PI_2*3.0; - } - } - else - { - angle = atan(y/x); - } - } - - DL_MTextData d( - // insertion point - getRealValue(10, 0.0), - getRealValue(20, 0.0), - getRealValue(30, 0.0), - // X direction vector - getRealValue(11, 0.0), - getRealValue(21, 0.0), - getRealValue(31, 0.0), - // height - getRealValue(40, 2.5), - // width - getRealValue(41, 0.0), - // attachment point - getIntValue(71, 1), - // drawing direction - getIntValue(72, 1), - // line spacing style - getIntValue(73, 1), - // line spacing factor - getRealValue(44, 1.0), - // text - getStringValue(1, ""), - // style - getStringValue(7, ""), - // angle - angle); - creationInterface->addMText(d); -} - -/** - * Handles all XRecord data. - */ -bool DL_Dxf::handleXRecordData(DL_CreationInterface* creationInterface) -{ - if (groupCode==105) - { - return false; - } - - if (groupCode==5) - { - creationInterface->addXRecord(groupValue); - return true; - } - - if (groupCode==280) - { - xRecordValues = true; - return true; - } - - if (!xRecordValues) - { - return false; - } - - // string: - if (groupCode<=9 || - groupCode==100 || groupCode==102 || groupCode==105 || - (groupCode>=300 && groupCode<=369) || - (groupCode>=1000 && groupCode<=1009)) - { - - creationInterface->addXRecordString(static_cast(groupCode), groupValue); - return true; - } - - // int: - else if ((groupCode>=60 && groupCode<=99) || - (groupCode>=160 && groupCode<=179) || - (groupCode>=270 && groupCode<=289)) - { - creationInterface->addXRecordInt(static_cast(groupCode), toInt(groupValue)); - return true; - } - - // bool: - else if (groupCode>=290 && groupCode<=299) - { - creationInterface->addXRecordBool(static_cast(groupCode), toBool(groupValue)); - return true; - } - - // double: - else if ((groupCode>=10 && groupCode<=59) || - (groupCode>=110 && groupCode<=149) || - (groupCode>=210 && groupCode<=239)) - { - creationInterface->addXRecordReal(static_cast(groupCode), toReal(groupValue)); - return true; - } - - return false; -} - -/** - * Handles all dictionary data. - */ -bool DL_Dxf::handleDictionaryData(DL_CreationInterface* creationInterface) -{ - if (groupCode==3) - { - return true; - } - - if (groupCode==5) - { - creationInterface->addDictionary(DL_DictionaryData(groupValue)); - return true; - } - - if (groupCode==350) - { - creationInterface->addDictionaryEntry(DL_DictionaryEntryData(getStringValue(3, ""), groupValue)); - return true; - } - return false; -} - - - -/** - * Handles XData for all object types. - */ -bool DL_Dxf::handleXData(DL_CreationInterface* creationInterface) -{ - if (groupCode==1001) - { - creationInterface->addXDataApp(groupValue); - return true; - } - else if (groupCode>=1000 && groupCode<=1009) - { - creationInterface->addXDataString(static_cast(groupCode), groupValue); - return true; - } - else if (groupCode>=1010 && groupCode<=1059) - { - creationInterface->addXDataReal(static_cast(groupCode), toReal(groupValue)); - return true; - } - else if (groupCode>=1060 && groupCode<=1070) - { - creationInterface->addXDataInt(static_cast(groupCode), toInt(groupValue)); - return true; - } - else if (groupCode==1071) - { - creationInterface->addXDataInt(static_cast(groupCode), toInt(groupValue)); - return true; - } - - return false; -} - -/** - * Handles additional MText data. - */ -bool DL_Dxf::handleMTextData(DL_CreationInterface* creationInterface) -{ - // Special handling of text chunks for MTEXT entities: - if (groupCode==3) - { - creationInterface->addMTextChunk(groupValue); - return true; - } - - return false; -} - - - -/** - * Handles additional polyline data. - */ -bool DL_Dxf::handleLWPolylineData(DL_CreationInterface* /*creationInterface*/) -{ - // Allocate LWPolyline vertices (group code 90): - if (groupCode==90) - { - maxVertices = toInt(groupValue); - if (maxVertices>0) - { - delete[] vertices; - vertices = new double[4*maxVertices]; - for (int i=0; i=0 && vertexIndex(vertexIndex) + (groupCode/10-1)] = toReal(groupValue); - } - } - else if (groupCode==42 && vertexIndex0) - { - delete[] knots; - knots = new double[maxKnots]; - for (int i=0; i0) - { - delete[] controlPoints; - delete[] weights; - controlPoints = new double[3*maxControlPoints]; - weights = new double[maxControlPoints]; - for (int i=0; i0) - { - delete[] fitPoints; - fitPoints = new double[3*maxFitPoints]; - for (int i=0; i=0 && controlPointIndex(controlPointIndex) + (groupCode/10-1)] = toReal(groupValue); - } - return true; - } - - // Process spline fit points (group codes 11/21/31): - else if (groupCode==11 || groupCode==21 || groupCode==31) - { - if (fitPointIndex=0 && fitPointIndex(fitPointIndex) + ((groupCode-1)/10-1)] = toReal(groupValue); - } - return true; - } - - // Process spline weights (group code 41) - else if (groupCode==41) - { - - if (weightIndex=0 && weightIndex0) - { - delete[] leaderVertices; - leaderVertices = new double[3*maxLeaderVertices]; - for (int i=0; i=0 && - leaderVertexIndex(leaderVertexIndex) + (groupCode/10-1)] - = toReal(groupValue); - } - } - return true; - } - - return false; -} - - - - -/** - * Adds an text entity that was read from the file via the creation interface. - */ -void DL_Dxf::addText(DL_CreationInterface* creationInterface) -{ - DL_TextData d( - // insertion point - getRealValue(10, 0.0), - getRealValue(20, 0.0), - getRealValue(30, 0.0), - // alignment point - getRealValue(11, DL_NANDOUBLE), - getRealValue(21, DL_NANDOUBLE), - getRealValue(31, DL_NANDOUBLE), - // height - getRealValue(40, 2.5), - // x scale - getRealValue(41, 1.0), - // generation flags - getIntValue(71, 0), - // h just - getIntValue(72, 0), - // v just - getIntValue(73, 0), - // text - getStringValue(1, ""), - // style - getStringValue(7, ""), - // angle - (getRealValue(50, 0.0)*M_2PI)/360.0); - - creationInterface->addText(d); -} - - - -/** - * Adds an attrib entity that was read from the file via the creation interface. - * @todo add attrib instead of normal text - */ -void DL_Dxf::addAttribute(DL_CreationInterface* creationInterface) -{ - DL_AttributeData d( - // insertion point - getRealValue(10, 0.0), - getRealValue(20, 0.0), - getRealValue(30, 0.0), - // alignment point - getRealValue(11, 0.0), - getRealValue(21, 0.0), - getRealValue(31, 0.0), - // height - getRealValue(40, 2.5), - // x scale - getRealValue(41, 1.0), - // generation flags - getIntValue(71, 0), - // h just - getIntValue(72, 0), - // v just - getIntValue(74, 0), - // tag - getStringValue(2, ""), - // text - getStringValue(1, ""), - // style - getStringValue(7, ""), - // angle - (getRealValue(50, 0.0)*M_2PI)/360.0); - - creationInterface->addAttribute(d); -} - - - -/** - * @return dimension data from current values. - */ -DL_DimensionData DL_Dxf::getDimData() -{ - // generic dimension data: - return DL_DimensionData( - // def point - getRealValue(10, 0.0), - getRealValue(20, 0.0), - getRealValue(30, 0.0), - // text middle point - getRealValue(11, 0.0), - getRealValue(21, 0.0), - getRealValue(31, 0.0), - // type - getIntValue(70, 0), - // attachment point - getIntValue(71, 5), - // line sp. style - getIntValue(72, 1), - // line sp. factor - getRealValue(41, 1.0), - // text - getStringValue(1, ""), - // style - getStringValue(3, ""), - // angle - getRealValue(53, 0.0)); -} - - - -/** - * Adds a linear dimension entity that was read from the file via the creation interface. - */ -void DL_Dxf::addDimLinear(DL_CreationInterface* creationInterface) -{ - DL_DimensionData d = getDimData(); - - // horizontal / vertical / rotated dimension: - DL_DimLinearData dl( - // definition point 1 - getRealValue(13, 0.0), - getRealValue(23, 0.0), - getRealValue(33, 0.0), - // definition point 2 - getRealValue(14, 0.0), - getRealValue(24, 0.0), - getRealValue(34, 0.0), - // angle - getRealValue(50, 0.0), - // oblique - getRealValue(52, 0.0)); - creationInterface->addDimLinear(d, dl); -} - - - -/** - * Adds an aligned dimension entity that was read from the file via the creation interface. - */ -void DL_Dxf::addDimAligned(DL_CreationInterface* creationInterface) -{ - DL_DimensionData d = getDimData(); - - // aligned dimension: - DL_DimAlignedData da( - // extension point 1 - getRealValue(13, 0.0), - getRealValue(23, 0.0), - getRealValue(33, 0.0), - // extension point 2 - getRealValue(14, 0.0), - getRealValue(24, 0.0), - getRealValue(34, 0.0)); - creationInterface->addDimAlign(d, da); -} - - - -/** - * Adds a radial dimension entity that was read from the file via the creation interface. - */ -void DL_Dxf::addDimRadial(DL_CreationInterface* creationInterface) -{ - DL_DimensionData d = getDimData(); - - DL_DimRadialData dr( - // definition point - getRealValue(15, 0.0), - getRealValue(25, 0.0), - getRealValue(35, 0.0), - // leader length: - getRealValue(40, 0.0)); - creationInterface->addDimRadial(d, dr); -} - - - -/** - * Adds a diametric dimension entity that was read from the file via the creation interface. - */ -void DL_Dxf::addDimDiametric(DL_CreationInterface* creationInterface) -{ - DL_DimensionData d = getDimData(); - - // diametric dimension: - DL_DimDiametricData dr( - // definition point - getRealValue(15, 0.0), - getRealValue(25, 0.0), - getRealValue(35, 0.0), - // leader length: - getRealValue(40, 0.0)); - creationInterface->addDimDiametric(d, dr); -} - - - -/** - * Adds an angular dimension entity that was read from the file via the creation interface. - */ -void DL_Dxf::addDimAngular(DL_CreationInterface* creationInterface) -{ - DL_DimensionData d = getDimData(); - - // angular dimension: - DL_DimAngularData da( - // definition point 1 - getRealValue(13, 0.0), - getRealValue(23, 0.0), - getRealValue(33, 0.0), - // definition point 2 - getRealValue(14, 0.0), - getRealValue(24, 0.0), - getRealValue(34, 0.0), - // definition point 3 - getRealValue(15, 0.0), - getRealValue(25, 0.0), - getRealValue(35, 0.0), - // definition point 4 - getRealValue(16, 0.0), - getRealValue(26, 0.0), - getRealValue(36, 0.0)); - creationInterface->addDimAngular(d, da); -} - - -/** - * Adds an angular dimension entity that was read from the file via the creation interface. - */ -void DL_Dxf::addDimAngular3P(DL_CreationInterface* creationInterface) -{ - DL_DimensionData d = getDimData(); - - // angular dimension (3P): - DL_DimAngular3PData da( - // definition point 1 - getRealValue(13, 0.0), - getRealValue(23, 0.0), - getRealValue(33, 0.0), - // definition point 2 - getRealValue(14, 0.0), - getRealValue(24, 0.0), - getRealValue(34, 0.0), - // definition point 3 - getRealValue(15, 0.0), - getRealValue(25, 0.0), - getRealValue(35, 0.0)); - creationInterface->addDimAngular3P(d, da); -} - - - -/** - * Adds an ordinate dimension entity that was read from the file via the creation interface. - */ -void DL_Dxf::addDimOrdinate(DL_CreationInterface* creationInterface) -{ - DL_DimensionData d = getDimData(); - - // ordinate dimension: - DL_DimOrdinateData dl( - // definition point 1 - getRealValue(13, 0.0), - getRealValue(23, 0.0), - getRealValue(33, 0.0), - // definition point 2 - getRealValue(14, 0.0), - getRealValue(24, 0.0), - getRealValue(34, 0.0), - (getIntValue(70, 0)&64)==64 // true: X-type, false: Y-type - ); - creationInterface->addDimOrdinate(d, dl); -} - - - -/** - * Adds a leader entity that was read from the file via the creation interface. - */ -void DL_Dxf::addLeader(DL_CreationInterface* creationInterface) -{ - // leader (arrow) - DL_LeaderData le( - // arrow head flag - getIntValue(71, 1), - // leader path type - getIntValue(72, 0), - // Leader creation flag - getIntValue(73, 3), - // Hookline direction flag - getIntValue(74, 1), - // Hookline flag - getIntValue(75, 0), - // Text annotation height - getRealValue(40, 1.0), - // Text annotation width - getRealValue(41, 1.0), - // Number of vertices in leader - getIntValue(76, 0) - ); - creationInterface->addLeader(le); - - for (int i=0; iaddLeaderVertex(d); - } - creationInterface->endEntity(); -} - -/** - * Adds a hatch entity that was read from the file via the creation interface. - */ -void DL_Dxf::addHatch(DL_CreationInterface* creationInterface) -{ - DL_HatchData hd(getIntValue(91, 1), - getIntValue(70, 0), - getRealValue(41, 1.0), - getRealValue(52, 0.0), - getStringValue(2, "")); - - creationInterface->addHatch(hd); - - for (quint32 i=0; iaddHatchLoop(DL_HatchLoopData(static_cast(hatchEdges[i].size()))); - for (quint32 k=0; kaddHatchEdge(DL_HatchEdgeData(hatchEdges[i][k])); - } - } - - creationInterface->endEntity(); -} - -void DL_Dxf::addHatchLoop() -{ - addHatchEdge(); - hatchEdges.push_back(std::vector()); -} - -void DL_Dxf::addHatchEdge() -{ - if (hatchEdge.defined) - { - if (hatchEdges.size()>0) - { - hatchEdges.back().push_back(hatchEdge); - } - hatchEdge = DL_HatchEdgeData(); - } -} - -/** - * Handles all hatch data. - */ -bool DL_Dxf::handleHatchData(DL_CreationInterface* creationInterface) -{ - // New polyline loop, group code 92 - // or new loop with individual edges, group code 93 - if (groupCode==92 || groupCode==93) - { - if (firstHatchLoop) - { - hatchEdges.clear(); - firstHatchLoop = false; - } - if (groupCode==92 && (toInt(groupValue)&2)==2) - { - addHatchLoop(); - } - if (groupCode==93) - { - addHatchLoop(); - } - return true; - } - - // New hatch edge or new section / entity: add last hatch edge: - if (groupCode==72 || groupCode==0 || groupCode==78 || groupCode==98) - { - // polyline boundaries use code 72 for bulge flag: - if (groupCode!=72 || (getIntValue(92, 0)&2)==0) - { - addHatchEdge(); - } - - if (groupCode==0 /*|| groupCode==78*/) - { - addHatch(creationInterface); - } - else - { - hatchEdge.type = toInt(groupValue); - } - return true; - } - - // polyline boundary: - if ((getIntValue(92, 0)&2)==2) - { - switch (groupCode) - { - case 10: - hatchEdge.type = 0; - hatchEdge.vertices.push_back(std::vector()); - hatchEdge.vertices.back().push_back(toReal(groupValue)); - return true; - case 20: - if (!hatchEdge.vertices.empty()) - { - hatchEdge.vertices.back().push_back(toReal(groupValue)); - hatchEdge.defined = true; - } - return true; - case 42: - if (!hatchEdge.vertices.empty()) - { - hatchEdge.vertices.back().push_back(toReal(groupValue)); - hatchEdge.defined = true; - } - return true; - default: - break; - } - } - else - { - // Line edge: - if (hatchEdge.type==1) - { - switch (groupCode) - { - case 10: - hatchEdge.x1 = toReal(groupValue); - return true; - case 20: - hatchEdge.y1 = toReal(groupValue); - return true; - case 11: - hatchEdge.x2 = toReal(groupValue); - return true; - case 21: - hatchEdge.y2 = toReal(groupValue); - hatchEdge.defined = true; - return true; - default: - break; - } - } - - // Arc edge: - if (hatchEdge.type==2) - { - switch(groupCode) - { - case 10: - hatchEdge.cx = toReal(groupValue); - return true; - case 20: - hatchEdge.cy = toReal(groupValue); - return true; - case 40: - hatchEdge.radius = toReal(groupValue); - return true; - case 50: - hatchEdge.angle1 = toReal(groupValue)/360.0*M_2PI; - return true; - case 51: - hatchEdge.angle2 = toReal(groupValue)/360.0*M_2PI; - return true; - case 73: - hatchEdge.ccw = static_cast(toInt(groupValue)); - hatchEdge.defined = true; - return true; - default: - break; - } - } - - // Ellipse arc edge: - if (hatchEdge.type==3) - { - switch (groupCode) - { - case 10: - hatchEdge.cx = toReal(groupValue); - return true; - case 20: - hatchEdge.cy = toReal(groupValue); - return true; - case 11: - hatchEdge.mx = toReal(groupValue); - return true; - case 21: - hatchEdge.my = toReal(groupValue); - return true; - case 40: - hatchEdge.ratio = toReal(groupValue); - return true; - case 50: - hatchEdge.angle1 = toReal(groupValue)/360.0*M_2PI; - return true; - case 51: - hatchEdge.angle2 = toReal(groupValue)/360.0*M_2PI; - return true; - case 73: - hatchEdge.ccw = static_cast(toInt(groupValue)); - hatchEdge.defined = true; - return true; - default: - break; - } - } - - // Spline edge: - if (hatchEdge.type==4) - { - switch (groupCode) - { - case 94: - hatchEdge.degree = static_cast(toInt(groupValue)); - return true; - case 73: - hatchEdge.rational = toBool(groupValue); - return true; - case 74: - hatchEdge.periodic = toBool(groupValue); - return true; - case 95: - hatchEdge.nKnots = static_cast(toInt(groupValue)); - return true; - case 96: - hatchEdge.nControl = static_cast(toInt(groupValue)); - return true; - case 97: - hatchEdge.nFit = static_cast(toInt(groupValue)); - return true; - case 40: - if (hatchEdge.knots.size() < hatchEdge.nKnots) - { - hatchEdge.knots.push_back(toReal(groupValue)); - } - return true; - case 10: - if (hatchEdge.controlPoints.size() < hatchEdge.nControl) - { - std::vector v; - v.push_back(toReal(groupValue)); - hatchEdge.controlPoints.push_back(v); - } - return true; - case 20: - if (!hatchEdge.controlPoints.empty() && hatchEdge.controlPoints.back().size()==1) - { - hatchEdge.controlPoints.back().push_back(toReal(groupValue)); - } - hatchEdge.defined = true; - return true; - case 42: - if (hatchEdge.weights.size() < hatchEdge.nControl) - { - hatchEdge.weights.push_back(toReal(groupValue)); - } - return true; - case 11: - if (hatchEdge.fitPoints.size() < hatchEdge.nFit) - { - std::vector v; - v.push_back(toReal(groupValue)); - hatchEdge.fitPoints.push_back(v); - } - return true; - case 21: - if (!hatchEdge.fitPoints.empty() && hatchEdge.fitPoints.back().size()==1) - { - hatchEdge.fitPoints.back().push_back(toReal(groupValue)); - } - hatchEdge.defined = true; - return true; - case 12: - hatchEdge.startTangentX = toReal(groupValue); - return true; - case 22: - hatchEdge.startTangentY = toReal(groupValue); - return true; - case 13: - hatchEdge.endTangentX = toReal(groupValue); - return true; - case 23: - hatchEdge.endTangentY = toReal(groupValue); - return true; - default: - break; - } - } - } - - return false; -} - - -/** - * Adds an image entity that was read from the file via the creation interface. - */ -void DL_Dxf::addImage(DL_CreationInterface* creationInterface) -{ - DL_ImageData id(// pass ref insead of name we don't have yet - getStringValue(340, ""), - // ins point: - getRealValue(10, 0.0), - getRealValue(20, 0.0), - getRealValue(30, 0.0), - // u vector: - getRealValue(11, 1.0), - getRealValue(21, 0.0), - getRealValue(31, 0.0), - // v vector: - getRealValue(12, 0.0), - getRealValue(22, 1.0), - getRealValue(32, 0.0), - // image size (pixel): - getIntValue(13, 1), - getIntValue(23, 1), - // brightness, contrast, fade - getIntValue(281, 50), - getIntValue(282, 50), - getIntValue(283, 0)); - - creationInterface->addImage(id); - creationInterface->endEntity(); - currentObjectType = DL_UNKNOWN; -} - - - -/** - * Adds an image definition that was read from the file via the creation interface. - */ -void DL_Dxf::addImageDef(DL_CreationInterface* creationInterface) -{ - DL_ImageDefData id(// handle - getStringValue(5, ""), - getStringValue(1, "")); - - creationInterface->linkImage(id); - creationInterface->endEntity(); - currentObjectType = DL_UNKNOWN; -} - - - -/** - * Ends some special entities like hatches or old style polylines. - */ -void DL_Dxf::endEntity(DL_CreationInterface* creationInterface) -{ - creationInterface->endEntity(); -} - - -/** - * Ends a sequence and notifies the creation interface. - */ -void DL_Dxf::endSequence(DL_CreationInterface* creationInterface) -{ - creationInterface->endSequence(); -} - - -/** - * Converts the given string into an int. - * ok is set to false if there was an error. - */ -//int DL_Dxf::stringToInt(const char* s, bool* ok) { -// if (ok!=NULL) { -// // check string: -// *ok = true; -// int i=0; -// bool dot = false; -// do { -// if (s[i]=='\0') { -// break; -// } else if (s[i]=='.') { -// if (dot==true) { -// //std::cerr << "two dots\n"; -// *ok = false; -// } else { -// dot = true; -// } -// } else if (s[i]<'0' || s[i]>'9') { -// //std::cerr << "NaN: '" << s[i] << "'\n"; -// *ok = false; -// } -// i++; -// } while(s[i]!='\0' && *ok==true); -// } - -// return atoi(s); -//} - - -/** - * @brief Opens the given file for writing and returns a pointer - * to the dxf writer. This pointer needs to be passed on to other - * writing functions. - * - * @param file Full path of the file to open. - * - * @return Pointer to an ascii dxf writer object. - */ -DL_WriterA* DL_Dxf::out(const char* file, DL_Codes::version version) -{ - const size_t size = strlen(file)+1; - char* f = new char[size]; - strlcpy(f, file, size); - this->version = version; - - DL_WriterA* dw = new DL_WriterA(f, version); - if (dw->openFailed()) - { - delete dw; - delete[] f; - return NULL; - } - else - { - delete[] f; - return dw; - } -} - - - -/** - * @brief Writes a DXF header to the file currently opened - * by the given DXF writer object. - */ -void DL_Dxf::writeHeader(DL_WriterA& dw) const -{ - dw.comment("dxflib " DL_VERSION); - dw.sectionHeader(); - - dw.dxfString(9, "$ACADVER"); - switch (version) - { - case DL_Codes::AC1009: - dw.dxfString(1, "AC1009"); - break; - case DL_Codes::AC1012: - dw.dxfString(1, "AC1012"); - break; - case DL_Codes::AC1014: - dw.dxfString(1, "AC1014"); - break; - case DL_Codes::AC1015: - dw.dxfString(1, "AC1015"); - break; - case DL_Codes::AC1009_MIN: - // minimalistic DXF version is unidentified in file: - default: - break; - } - - // Newer version require that (otherwise a*cad crashes..) - if (version==DL_VERSION_2000) - { - dw.dxfString(9, "$HANDSEED"); - dw.dxfHex(5, 0xFFFF); - } - - // commented out: more variables can be added after that by caller: - //dw.sectionEnd(); -} - - - - -/** - * Writes a point entity to the file. - * - * @param dw DXF writer - * @param data Entity data from the file - * @param attrib Attributes - */ -void DL_Dxf::writePoint(DL_WriterA& dw, - const DL_PointData& data, - const DL_Attributes& attrib) -{ - dw.entity("POINT"); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbPoint"); - } - dw.coord(DL_POINT_COORD_CODE, data.x, data.y, data.z); -} - - - -/** - * Writes a line entity to the file. - * - * @param dw DXF writer - * @param data Entity data from the file - * @param attrib Attributes - */ -void DL_Dxf::writeLine(DL_WriterA& dw, - const DL_LineData& data, - const DL_Attributes& attrib) -{ - dw.entity("LINE"); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbLine"); - } - dw.coord(DL_LINE_START_CODE, data.x1, data.y1, data.z1); - dw.coord(DL_LINE_END_CODE, data.x2, data.y2, data.z2); -} - - - -/** - * Writes an x line entity to the file. - * - * @param dw DXF writer - * @param data Entity data from the file - * @param attrib Attributes - */ -void DL_Dxf::writeXLine(DL_WriterA& dw, - const DL_XLineData& data, - const DL_Attributes& attrib) -{ - dw.entity("XLINE"); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbLine"); - } - dw.coord(DL_LINE_START_CODE, data.bx, data.by, data.bz); - dw.coord(DL_LINE_END_CODE, data.dx, data.dy, data.dz); -} - - - -/** - * Writes a ray entity to the file. - * - * @param dw DXF writer - * @param data Entity data from the file - * @param attrib Attributes - */ -void DL_Dxf::writeRay(DL_WriterA& dw, - const DL_RayData& data, - const DL_Attributes& attrib) -{ - dw.entity("RAY"); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbLine"); - } - dw.coord(DL_LINE_START_CODE, data.bx, data.by, data.bz); - dw.coord(DL_LINE_END_CODE, data.dx, data.dy, data.dz); -} - - - -/** - * Writes a polyline entity to the file. - * - * @param dw DXF writer - * @param data Entity data from the file - * @param attrib Attributes - * @see writeVertex - */ -void DL_Dxf::writePolyline(DL_WriterA& dw, - const DL_PolylineData& data, - const DL_Attributes& attrib) -{ - if (version==DL_VERSION_2000) - { - dw.entity("LWPOLYLINE"); - dw.dxfString(100, "AcDbEntity"); - dw.entityAttributes(attrib); - dw.dxfString(100, "AcDbPolyline"); - dw.dxfInt(90, static_cast(data.number)); - dw.dxfInt(70, data.flags); - } - else - { - dw.entity("POLYLINE"); - dw.entityAttributes(attrib); - polylineLayer = attrib.getLayer(); - dw.dxfInt(66, 1); - dw.dxfInt(70, data.flags); - dw.coord(DL_VERTEX_COORD_CODE, 0.0, 0.0, 0.0); - } -} - - - -/** - * Writes a single vertex of a polyline to the file. - * - * @param dw DXF writer - * @param data Entity data from the file - */ -void DL_Dxf::writeVertex(DL_WriterA& dw, - const DL_VertexData& data) -{ - - - if (version==DL_VERSION_2000) - { - dw.dxfReal(10, data.x); - dw.dxfReal(20, data.y); - dw.dxfReal(30, data.z); - if (fabs(data.bulge)>1.0e-10) - { - dw.dxfReal(42, data.bulge); - } - } - else - { - dw.entity("VERTEX"); - //dw.entityAttributes(attrib); - dw.dxfString(8, polylineLayer); - dw.coord(DL_VERTEX_COORD_CODE, data.x, data.y, data.z); - if (fabs(data.bulge)>1.0e-10) - { - dw.dxfReal(42, data.bulge); - } - } -} - - - -/** - * Writes the polyline end. Only needed for DXF R12. - */ -void DL_Dxf::writePolylineEnd(DL_WriterA& dw) const -{ - if (version==DL_VERSION_2000) - { - } - else - { - dw.entity("SEQEND"); - } -} - - -/** - * Writes a spline entity to the file. - * - * @param dw DXF writer - * @param data Entity data from the file - * @param attrib Attributes - * @see writeControlPoint - */ -void DL_Dxf::writeSpline(DL_WriterA& dw, - const DL_SplineData& data, - const DL_Attributes& attrib) -{ - - dw.entity("SPLINE"); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbSpline"); - } - dw.dxfInt(70, data.flags); - dw.dxfInt(71, static_cast(data.degree)); - dw.dxfInt(72, static_cast(data.nKnots)); // number of knots - dw.dxfInt(73, static_cast(data.nControl)); // number of control points - dw.dxfInt(74, static_cast(data.nFit)); // number of fit points -} - - - -/** - * Writes a single control point of a spline to the file. - * - * @param dw DXF writer - * @param data Entity data from the file - */ -void DL_Dxf::writeControlPoint(DL_WriterA& dw, - const DL_ControlPointData& data) -{ - - dw.dxfReal(10, data.x); - dw.dxfReal(20, data.y); - dw.dxfReal(30, data.z); -} - - - -/** - * Writes a single fit point of a spline to the file. - * - * @param dw DXF writer - * @param data Entity data from the file - */ -void DL_Dxf::writeFitPoint(DL_WriterA& dw, - const DL_FitPointData& data) -{ - - dw.dxfReal(11, data.x); - dw.dxfReal(21, data.y); - dw.dxfReal(31, data.z); -} - - - -/** - * Writes a single knot of a spline to the file. - * - * @param dw DXF writer - * @param data Entity data from the file - */ -void DL_Dxf::writeKnot(DL_WriterA& dw, - const DL_KnotData& data) -{ - - dw.dxfReal(40, data.k); -} - - - -/** - * Writes a circle entity to the file. - * - * @param dw DXF writer - * @param data Entity data from the file - * @param attrib Attributes - */ -void DL_Dxf::writeCircle(DL_WriterA& dw, - const DL_CircleData& data, - const DL_Attributes& attrib) -{ - dw.entity("CIRCLE"); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbCircle"); - } - dw.coord(10, data.cx, data.cy, data.cz); - dw.dxfReal(40, data.radius); -} - - - -/** - * Writes an arc entity to the file. - * - * @param dw DXF writer - * @param data Entity data from the file - * @param attrib Attributes - */ -void DL_Dxf::writeArc(DL_WriterA& dw, - const DL_ArcData& data, - const DL_Attributes& attrib) -{ - dw.entity("ARC"); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbCircle"); - } - dw.coord(10, data.cx, data.cy, data.cz); - dw.dxfReal(40, data.radius); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbArc"); - } - dw.dxfReal(50, data.angle1); - dw.dxfReal(51, data.angle2); -} - - - -/** - * Writes an ellipse entity to the file. - * - * @param dw DXF writer - * @param data Entity data from the file - * @param attrib Attributes - */ -void DL_Dxf::writeEllipse(DL_WriterA& dw, - const DL_EllipseData& data, - const DL_Attributes& attrib) -{ - - if (version>DL_VERSION_R12) - { - dw.entity("ELLIPSE"); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEllipse"); - } - dw.coord(10, data.cx, data.cy, data.cz); - dw.coord(11, data.mx, data.my, data.mz); - dw.dxfReal(40, data.ratio); - dw.dxfReal(41, data.angle1); - dw.dxfReal(42, data.angle2); - } -} - - - -/** - * Writes a solid entity to the file. - * - * @param dw DXF writer - * @param data Entity data from the file - * @param attrib Attributes - */ -void DL_Dxf::writeSolid(DL_WriterA& dw, - const DL_SolidData& data, - const DL_Attributes& attrib) -{ - dw.entity("SOLID"); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbTrace"); - } - dw.coord(10, data.x[0], data.y[0], data.z[0]); - dw.coord(11, data.x[1], data.y[1], data.z[1]); - dw.coord(12, data.x[2], data.y[2], data.z[2]); - dw.coord(13, data.x[3], data.y[3], data.z[3]); - dw.dxfReal(39, data.thickness); -} - -/** - * Writes a trace entity to the file. - * - * @param dw DXF writer - * @param data Entity data from the file - * @param attrib Attributes - */ -void DL_Dxf::writeTrace(DL_WriterA& dw, - const DL_TraceData& data, - const DL_Attributes& attrib) -{ - dw.entity("TRACE"); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbTrace"); - } - dw.coord(10, data.x[0], data.y[0], data.z[0]); - dw.coord(11, data.x[1], data.y[1], data.z[1]); - dw.coord(12, data.x[2], data.y[2], data.z[2]); - dw.coord(13, data.x[3], data.y[3], data.z[3]); - dw.dxfReal(39, data.thickness); -} - - - -/** - * Writes a 3d face entity to the file. - * - * @param dw DXF writer - * @param data Entity data from the file - * @param attrib Attributes - */ -void DL_Dxf::write3dFace(DL_WriterA& dw, - const DL_3dFaceData& data, - const DL_Attributes& attrib) -{ - dw.entity("3DFACE"); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbFace"); - } - dw.coord(10, data.x[0], data.y[0], data.z[0]); - dw.coord(11, data.x[1], data.y[1], data.z[1]); - dw.coord(12, data.x[2], data.y[2], data.z[2]); - dw.coord(13, data.x[3], data.y[3], data.z[3]); -} - - - -/** - * Writes an insert to the file. - * - * @param dw DXF writer - * @param data Entity data from the file - * @param attrib Attributes - */ -void DL_Dxf::writeInsert(DL_WriterA& dw, - const DL_InsertData& data, - const DL_Attributes& attrib) -{ - - if (data.name.empty()) - { - std::cerr << "DL_Dxf::writeInsert: " - << "Block name must not be empty\n"; - return; - } - - dw.entity("INSERT"); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - if (data.cols!=1 || data.rows!=1) - { - dw.dxfString(100, "AcDbMInsertBlock"); - } - else - { - dw.dxfString(100, "AcDbBlockReference"); - } - } - dw.dxfString(2, data.name); - dw.dxfReal(10, data.ipx); - dw.dxfReal(20, data.ipy); - dw.dxfReal(30, data.ipz); - if (!DL_FuzzyComparePossibleNulls(data.sx, 1.0) || !DL_FuzzyComparePossibleNulls(data.sy, 1.0)) - { - dw.dxfReal(41, data.sx); - dw.dxfReal(42, data.sy); - dw.dxfReal(43, 1.0); - } - if (!DL_FuzzyComparePossibleNulls(data.angle, 0.0)) - { - dw.dxfReal(50, data.angle); - } - if (data.cols!=1 || data.rows!=1) - { - dw.dxfInt(70, data.cols); - dw.dxfInt(71, data.rows); - } - if (!DL_FuzzyComparePossibleNulls(data.colSp, 0.0) || !DL_FuzzyComparePossibleNulls(data.rowSp, 0.0)) - { - dw.dxfReal(44, data.colSp); - dw.dxfReal(45, data.rowSp); - } -} - - - -/** - * Writes a multi text entity to the file. - * - * @param dw DXF writer - * @param data Entity data from the file - * @param attrib Attributes - */ -void DL_Dxf::writeMText(DL_WriterA& dw, - const DL_MTextData& data, - const DL_Attributes& attrib) -{ - - dw.entity("MTEXT"); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbMText"); - } - dw.dxfReal(10, data.ipx); - dw.dxfReal(20, data.ipy); - dw.dxfReal(30, data.ipz); - dw.dxfReal(40, data.height); - dw.dxfReal(41, data.width); - - dw.dxfInt(71, data.attachmentPoint); - dw.dxfInt(72, data.drawingDirection); - - // Creare text chunks of 250 characters each: - int length = static_cast(data.text.length()); - char chunk[251]; - int i; - for (i=250; iDL_VERSION_R12) - { - dw.dxfInt(71, data.attachmentPoint); - dw.dxfInt(72, data.lineSpacingStyle); // opt - dw.dxfReal(41, data.lineSpacingFactor); // opt - } - - dw.dxfReal(42, data.angle); - - dw.dxfString(1, data.text); // opt - //dw.dxfString(3, data.style); - dw.dxfString(3, "Standard"); - - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbAlignedDimension"); - } - - dw.dxfReal(13, edata.epx1); - dw.dxfReal(23, edata.epy1); - dw.dxfReal(33, 0.0); - - dw.dxfReal(14, edata.epx2); - dw.dxfReal(24, edata.epy2); - dw.dxfReal(34, 0.0); - - writeDimStyleOverrides(dw, data); -} - - - -/** - * Writes a linear dimension entity to the file. - * - * @param dw DXF writer - * @param data Generic dimension data for from the file - * @param edata Specific linear dimension data from the file - * @param attrib Attributes - */ -void DL_Dxf::writeDimLinear(DL_WriterA& dw, - const DL_DimensionData& data, - const DL_DimLinearData& edata, - const DL_Attributes& attrib) -{ - - dw.entity("DIMENSION"); - - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbDimension"); - } - - dw.dxfReal(10, data.dpx); - dw.dxfReal(20, data.dpy); - dw.dxfReal(30, data.dpz); - - dw.dxfReal(11, data.mpx); - dw.dxfReal(21, data.mpy); - dw.dxfReal(31, 0.0); - - dw.dxfInt(70, data.type); - if (version>DL_VERSION_R12) - { - dw.dxfInt(71, data.attachmentPoint); - dw.dxfInt(72, data.lineSpacingStyle); // opt - dw.dxfReal(41, data.lineSpacingFactor); // opt - } - - dw.dxfReal(42, data.angle); - - dw.dxfString(1, data.text); // opt - //dw.dxfString(3, data.style); - dw.dxfString(3, "Standard"); - - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbAlignedDimension"); - } - - dw.dxfReal(13, edata.dpx1); - dw.dxfReal(23, edata.dpy1); - dw.dxfReal(33, 0.0); - - dw.dxfReal(14, edata.dpx2); - dw.dxfReal(24, edata.dpy2); - dw.dxfReal(34, 0.0); - - dw.dxfReal(50, edata.angle/(M_2PI)*360.0); - - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbRotatedDimension"); - } - - writeDimStyleOverrides(dw, data); -} - - - -/** - * Writes a radial dimension entity to the file. - * - * @param dw DXF writer - * @param data Generic dimension data for from the file - * @param edata Specific radial dimension data from the file - * @param attrib Attributes - */ -void DL_Dxf::writeDimRadial(DL_WriterA& dw, - const DL_DimensionData& data, - const DL_DimRadialData& edata, - const DL_Attributes& attrib) -{ - - dw.entity("DIMENSION"); - - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbDimension"); - } - - dw.dxfReal(10, data.dpx); - dw.dxfReal(20, data.dpy); - dw.dxfReal(30, data.dpz); - - dw.dxfReal(11, data.mpx); - dw.dxfReal(21, data.mpy); - dw.dxfReal(31, 0.0); - - dw.dxfInt(70, data.type); - if (version>DL_VERSION_R12) - { - dw.dxfInt(71, data.attachmentPoint); - dw.dxfInt(72, data.lineSpacingStyle); // opt - dw.dxfReal(41, data.lineSpacingFactor); // opt - } - - dw.dxfReal(42, data.angle); - - dw.dxfString(1, data.text); // opt - //dw.dxfString(3, data.style); - dw.dxfString(3, "Standard"); - - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbRadialDimension"); - } - - dw.dxfReal(15, edata.dpx); - dw.dxfReal(25, edata.dpy); - dw.dxfReal(35, 0.0); - - dw.dxfReal(40, edata.leader); - - writeDimStyleOverrides(dw, data); -} - - - -/** - * Writes a diametric dimension entity to the file. - * - * @param dw DXF writer - * @param data Generic dimension data for from the file - * @param edata Specific diametric dimension data from the file - * @param attrib Attributes - */ -void DL_Dxf::writeDimDiametric(DL_WriterA& dw, - const DL_DimensionData& data, - const DL_DimDiametricData& edata, - const DL_Attributes& attrib) -{ - - dw.entity("DIMENSION"); - - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbDimension"); - } - - dw.dxfReal(10, data.dpx); - dw.dxfReal(20, data.dpy); - dw.dxfReal(30, data.dpz); - - dw.dxfReal(11, data.mpx); - dw.dxfReal(21, data.mpy); - dw.dxfReal(31, 0.0); - - dw.dxfInt(70, data.type); - if (version>DL_VERSION_R12) - { - dw.dxfInt(71, data.attachmentPoint); - dw.dxfInt(72, data.lineSpacingStyle); // opt - dw.dxfReal(41, data.lineSpacingFactor); // opt - } - - dw.dxfReal(42, data.angle); - - dw.dxfString(1, data.text); // opt - //dw.dxfString(3, data.style); - dw.dxfString(3, "Standard"); - - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbDiametricDimension"); - } - - dw.dxfReal(15, edata.dpx); - dw.dxfReal(25, edata.dpy); - dw.dxfReal(35, 0.0); - - dw.dxfReal(40, edata.leader); - - writeDimStyleOverrides(dw, data); -} - - - -/** - * Writes an angular dimension entity to the file. - * - * @param dw DXF writer - * @param data Generic dimension data for from the file - * @param edata Specific angular dimension data from the file - * @param attrib Attributes - */ -void DL_Dxf::writeDimAngular(DL_WriterA& dw, - const DL_DimensionData& data, - const DL_DimAngularData& edata, - const DL_Attributes& attrib) -{ - - dw.entity("DIMENSION"); - - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbDimension"); - } - - dw.dxfReal(10, data.dpx); - dw.dxfReal(20, data.dpy); - dw.dxfReal(30, data.dpz); - - dw.dxfReal(11, data.mpx); - dw.dxfReal(21, data.mpy); - dw.dxfReal(31, 0.0); - - dw.dxfInt(70, data.type); - if (version>DL_VERSION_R12) - { - dw.dxfInt(71, data.attachmentPoint); - dw.dxfInt(72, data.lineSpacingStyle); // opt - dw.dxfReal(41, data.lineSpacingFactor); // opt - } - - dw.dxfReal(42, data.angle); - - dw.dxfString(1, data.text); // opt - //dw.dxfString(3, data.style); - dw.dxfString(3, "Standard"); - - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDb2LineAngularDimension"); - } - - dw.dxfReal(13, edata.dpx1); - dw.dxfReal(23, edata.dpy1); - dw.dxfReal(33, 0.0); - - dw.dxfReal(14, edata.dpx2); - dw.dxfReal(24, edata.dpy2); - dw.dxfReal(34, 0.0); - - dw.dxfReal(15, edata.dpx3); - dw.dxfReal(25, edata.dpy3); - dw.dxfReal(35, 0.0); - - dw.dxfReal(16, edata.dpx4); - dw.dxfReal(26, edata.dpy4); - dw.dxfReal(36, 0.0); -} - - - -/** - * Writes an angular dimension entity (3 points version) to the file. - * - * @param dw DXF writer - * @param data Generic dimension data for from the file - * @param edata Specific angular dimension data from the file - * @param attrib Attributes - */ -void DL_Dxf::writeDimAngular3P(DL_WriterA& dw, - const DL_DimensionData& data, - const DL_DimAngular3PData& edata, - const DL_Attributes& attrib) -{ - - dw.entity("DIMENSION"); - - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbDimension"); - } - - dw.dxfReal(10, data.dpx); - dw.dxfReal(20, data.dpy); - dw.dxfReal(30, data.dpz); - - dw.dxfReal(11, data.mpx); - dw.dxfReal(21, data.mpy); - dw.dxfReal(31, 0.0); - - dw.dxfInt(70, data.type); - if (version>DL_VERSION_R12) - { - dw.dxfInt(71, data.attachmentPoint); - dw.dxfInt(72, data.lineSpacingStyle); // opt - dw.dxfReal(41, data.lineSpacingFactor); // opt - } - - dw.dxfReal(42, data.angle); - - dw.dxfString(1, data.text); // opt - //dw.dxfString(3, data.style); - dw.dxfString(3, "Standard"); - - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDb3PointAngularDimension"); - } - - dw.dxfReal(13, edata.dpx1); - dw.dxfReal(23, edata.dpy1); - dw.dxfReal(33, 0.0); - - dw.dxfReal(14, edata.dpx2); - dw.dxfReal(24, edata.dpy2); - dw.dxfReal(34, 0.0); - - dw.dxfReal(15, edata.dpx3); - dw.dxfReal(25, edata.dpy3); - dw.dxfReal(35, 0.0); -} - - - - -/** - * Writes an ordinate dimension entity to the file. - * - * @param dw DXF writer - * @param data Generic dimension data for from the file - * @param edata Specific ordinate dimension data from the file - * @param attrib Attributes - */ -void DL_Dxf::writeDimOrdinate(DL_WriterA& dw, - const DL_DimensionData& data, - const DL_DimOrdinateData& edata, - const DL_Attributes& attrib) -{ - - dw.entity("DIMENSION"); - - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbDimension"); - } - - dw.dxfReal(10, data.dpx); - dw.dxfReal(20, data.dpy); - dw.dxfReal(30, data.dpz); - - dw.dxfReal(11, data.mpx); - dw.dxfReal(21, data.mpy); - dw.dxfReal(31, 0.0); - - int type = data.type; - if (edata.xtype) - { - type|=0x40; - } - - dw.dxfInt(70, type); - if (version>DL_VERSION_R12) - { - dw.dxfInt(71, data.attachmentPoint); - dw.dxfInt(72, data.lineSpacingStyle); // opt - dw.dxfReal(41, data.lineSpacingFactor); // opt - } - - dw.dxfString(1, data.text); // opt - //dw.dxfString(3, data.style); - dw.dxfString(3, "Standard"); - - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbOrdinateDimension"); - } - - dw.dxfReal(13, edata.dpx1); - dw.dxfReal(23, edata.dpy1); - dw.dxfReal(33, 0.0); - - dw.dxfReal(14, edata.dpx2); - dw.dxfReal(24, edata.dpy2); - dw.dxfReal(34, 0.0); -} - - - -/** - * Writes a leader entity to the file. - * - * @param dw DXF writer - * @param data Entity data from the file - * @param attrib Attributes - * @see writeVertex - */ -void DL_Dxf::writeLeader(DL_WriterA& dw, - const DL_LeaderData& data, - const DL_Attributes& attrib) -{ - if (version>DL_VERSION_R12) - { - dw.entity("LEADER"); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbLeader"); - } - dw.dxfString(3, "Standard"); - dw.dxfInt(71, data.arrowHeadFlag); - dw.dxfInt(72, data.leaderPathType); - dw.dxfInt(73, data.leaderCreationFlag); - dw.dxfInt(74, data.hooklineDirectionFlag); - dw.dxfInt(75, data.hooklineFlag); - dw.dxfReal(40, data.textAnnotationHeight); - dw.dxfReal(41, data.textAnnotationWidth); - dw.dxfInt(76, data.number); - } -} - - - -/** - * Writes a single vertex of a leader to the file. - * - * @param dw DXF writer - * @param data Entity data - */ -void DL_Dxf::writeLeaderVertex(DL_WriterA& dw, - const DL_LeaderVertexData& data) const -{ - if (version>DL_VERSION_R12) - { - dw.dxfReal(10, data.x); - dw.dxfReal(20, data.y); - } -} - - - -/** - * Writes the beginning of a hatch entity to the file. - * This must be followed by one or more writeHatchLoop() - * calls and a writeHatch2() call. - * - * @param dw DXF writer - * @param data Entity data. - * @param attrib Attributes - */ -void DL_Dxf::writeHatch1(DL_WriterA& dw, - const DL_HatchData& data, - const DL_Attributes& attrib) -{ - - dw.entity("HATCH"); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbHatch"); - } - dw.dxfReal(10, 0.0); // elevation - dw.dxfReal(20, 0.0); - dw.dxfReal(30, 0.0); - dw.dxfReal(210, 0.0); // extrusion dir. - dw.dxfReal(220, 0.0); - dw.dxfReal(230, 1.0); - if (data.solid==false) - { - dw.dxfString(2, data.pattern); - } - else - { - dw.dxfString(2, "SOLID"); - } - dw.dxfInt(70, static_cast(data.solid)); - dw.dxfInt(71, 0); // non-associative - dw.dxfInt(91, data.numLoops); -} - - - -/** - * Writes the end of a hatch entity to the file. - * - * @param dw DXF writer - * @param data Entity data. - * @param attrib Attributes - */ -void DL_Dxf::writeHatch2(DL_WriterA& dw, - const DL_HatchData& data, - const DL_Attributes& attrib) const -{ - - Q_UNUSED(attrib) - - dw.dxfInt(75, 0); // odd parity - dw.dxfInt(76, 1); // pattern type - if (data.solid==false) - { - dw.dxfReal(52, data.angle); - dw.dxfReal(41, data.scale); - dw.dxfInt(77, 0); // not double - //dw.dxfInt(78, 0); - dw.dxfInt(78, 1); - dw.dxfReal(53, 45.0); - dw.dxfReal(43, 0.0); - dw.dxfReal(44, 0.0); - dw.dxfReal(45, -0.0883883476483184); - dw.dxfReal(46, 0.0883883476483185); - dw.dxfInt(79, 0); - } - dw.dxfInt(98, 0); - - if (version==DL_VERSION_2000) - { - dw.dxfString(1001, "ACAD"); - dw.dxfReal(1010, data.originX); - dw.dxfReal(1020, data.originY); - dw.dxfInt(1030, 0.0); - } -} - - - -/** - * Writes the beginning of a hatch loop to the file. This - * must happen after writing the beginning of a hatch entity. - * - * @param dw DXF writer - * @param data Entity data. - */ -void DL_Dxf::writeHatchLoop1(DL_WriterA& dw, - const DL_HatchLoopData& data) -{ - - dw.dxfInt(92, 1); - dw.dxfInt(93, data.numEdges); - //dw.dxfInt(97, 0); -} - - - -/** - * Writes the end of a hatch loop to the file. - * - * @param dw DXF writer - * @param data Entity data. - */ -void DL_Dxf::writeHatchLoop2(DL_WriterA& dw, - const DL_HatchLoopData& data) -{ - Q_UNUSED(data) - dw.dxfInt(97, 0); -} - - -/** - * Writes the beginning of a hatch entity to the file. - * - * @param dw DXF writer - * @param data Entity data. - */ -void DL_Dxf::writeHatchEdge(DL_WriterA& dw, - const DL_HatchEdgeData& data) -{ - - if (data.type<1 || data.type>4) - { - printf("WARNING: unsupported hatch edge type: %d", data.type); - } - - dw.dxfInt(72, data.type); - - switch (data.type) - { - // line: - case 1: - dw.dxfReal(10, data.x1); - dw.dxfReal(20, data.y1); - dw.dxfReal(11, data.x2); - dw.dxfReal(21, data.y2); - break; - - // arc: - case 2: - dw.dxfReal(10, data.cx); - dw.dxfReal(20, data.cy); - dw.dxfReal(40, data.radius); - dw.dxfReal(50, data.angle1/(M_2PI)*360.0); - dw.dxfReal(51, data.angle2/(M_2PI)*360.0); - dw.dxfInt(73, static_cast((data.ccw))); - break; - - // ellipse arc: - case 3: - dw.dxfReal(10, data.cx); - dw.dxfReal(20, data.cy); - dw.dxfReal(11, data.mx); - dw.dxfReal(21, data.my); - dw.dxfReal(40, data.ratio); - dw.dxfReal(50, data.angle1/(M_2PI)*360.0); - dw.dxfReal(51, data.angle2/(M_2PI)*360.0); - dw.dxfInt(73, static_cast((data.ccw))); - break; - - // spline: - case 4: - dw.dxfInt(94, static_cast(data.degree)); - dw.dxfBool(73, data.rational); - dw.dxfBool(74, data.periodic); - dw.dxfInt(95, static_cast(data.nKnots)); - dw.dxfInt(96, static_cast(data.nControl)); - for (quint32 i=0; i0) - { - dw.dxfInt(97, static_cast(data.nFit)); - for (quint32 i=0; i1.0e-4 || fabs(data.startTangentY)>1.0e-4) - { - dw.dxfReal(12, data.startTangentX); - dw.dxfReal(22, data.startTangentY); - } - if (fabs(data.endTangentX)>1.0e-4 || fabs(data.endTangentY)>1.0e-4) - { - dw.dxfReal(13, data.endTangentX); - dw.dxfReal(23, data.endTangentY); - } - break; - - default: - break; - } -} - - - -/** - * Writes an image entity. - * - * @return IMAGEDEF handle. Needed for the IMAGEDEF counterpart. - */ -int DL_Dxf::writeImage(DL_WriterA& dw, - const DL_ImageData& data, - const DL_Attributes& attrib) -{ - - /*if (data.file.empty()) - { - std::cerr << "DL_Dxf::writeImage: " - << "Image file must not be empty\n"; - return; - }*/ - - dw.entity("IMAGE"); - - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbEntity"); - } - dw.entityAttributes(attrib); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbRasterImage"); - dw.dxfInt(90, 0); - } - // insertion point - dw.dxfReal(10, data.ipx); - dw.dxfReal(20, data.ipy); - dw.dxfReal(30, data.ipz); - - // vector along bottom side (1 pixel long) - dw.dxfReal(11, data.ux); - dw.dxfReal(21, data.uy); - dw.dxfReal(31, data.uz); - - // vector along left side (1 pixel long) - dw.dxfReal(12, data.vx); - dw.dxfReal(22, data.vy); - dw.dxfReal(32, data.vz); - - // image size in pixel - dw.dxfReal(13, data.width); - dw.dxfReal(23, data.height); - - // handle of IMAGEDEF object - int handle = static_cast(dw.incHandle()); - dw.dxfHex(340, handle); //-V525 - - // flags - dw.dxfInt(70, 15); - - // clipping: - dw.dxfInt(280, 0); - - // brightness, contrast, fade - dw.dxfInt(281, data.brightness); - dw.dxfInt(282, data.contrast); - dw.dxfInt(283, data.fade); - - return handle; -} - - - -/** - * Writes an image definiition entity. - */ -void DL_Dxf::writeImageDef(DL_WriterA& dw, - int handle, - const DL_ImageData& data) const -{ - - /*if (data.file.empty()) - { - std::cerr << "DL_Dxf::writeImage: " - << "Image file must not be empty\n"; - return; - }*/ - - dw.dxfString(0, "IMAGEDEF"); - if (version==DL_VERSION_2000) - { - dw.dxfHex(5, handle); - } - - if (version==DL_VERSION_2000) //-V581 - { - dw.dxfString(100, "AcDbRasterImageDef"); - dw.dxfInt(90, 0); - } - // file name: - dw.dxfString(1, data.ref); - - // image size in pixel - dw.dxfReal(10, data.width); - dw.dxfReal(20, data.height); - - dw.dxfReal(11, 1.0); - dw.dxfReal(21, 1.0); - - // loaded: - dw.dxfInt(280, 1); - // units: - dw.dxfInt(281, 0); -} - - -/** - * Writes a layer to the file. Layers are stored in the - * tables section of a DXF file. - * - * @param dw DXF writer - * @param data Entity data from the file - * @param attrib Attributes - */ -void DL_Dxf::writeLayer(DL_WriterA& dw, - const DL_LayerData& data, - const DL_Attributes& attrib) -{ - - if (data.name.empty()) - { - std::cerr << "DL_Dxf::writeLayer: " - << "Layer name must not be empty\n"; - return; - } - - int color = attrib.getColor(); - if (color>=256) - { - std::cerr << "Layer color cannot be " << color << ". Changed to 7.\n"; - color = 7; - } - - if (data.name == "0") - { - dw.tableLayerEntry(0x10); - } - else - { - dw.tableLayerEntry(); - } - - dw.dxfString(2, data.name); - dw.dxfInt(70, data.flags); - dw.dxfInt(62, color); - if (version>=DL_VERSION_2000 && attrib.getColor24()!=-1) - { - dw.dxfInt(420, attrib.getColor24()); - } - - dw.dxfString(6, (attrib.getLinetype().length()==0 ? - std::string("CONTINUOUS") : attrib.getLinetype())); - - if (version>=DL_VERSION_2000) - { - // layer defpoints cannot be plotted - std::string lstr = data.name; - std::transform(lstr.begin(), lstr.end(), lstr.begin(), tolower); - if (lstr=="defpoints") - { - dw.dxfInt(290, 0); - } - } - if (version>=DL_VERSION_2000 && attrib.getWidth()!=-1) - { - dw.dxfInt(370, attrib.getWidth()); - } - if (version>=DL_VERSION_2000) - { - dw.dxfHex(390, 0xF); - } -} - - - -/** - * Writes a line type to the file. Line types are stored in the - * tables section of a DXF file. - */ -void DL_Dxf::writeLinetype(DL_WriterA& dw, - const DL_LinetypeData& data) const -{ - - std::string nameUpper = data.name; - std::transform(nameUpper.begin(), nameUpper.end(), nameUpper.begin(), ::toupper); - - if (data.name.empty()) - { - std::cerr << "DL_Dxf::writeLinetype: " - << "Line type name must not be empty\n"; - return; - } - - // ignore BYLAYER, BYBLOCK for R12 - if (version=DL_VERSION_R13) - { - dw.dxfInt(74, 0); - } - } - } -} - - - -/** - * Writes the APPID section to the DXF file. - * - * @param name Application name - */ -void DL_Dxf::writeAppid(DL_WriterA& dw, const std::string& name) -{ - if (name.empty()) - { - std::cerr << "DL_Dxf::writeAppid: " - << "Application name must not be empty\n"; - return; - } - - std::string n = name; - std::transform(n.begin(), n.end(), n.begin(), ::toupper); - - if (n=="ACAD") - { - dw.tableAppidEntry(0x12); - } - else - { - dw.tableAppidEntry(); - } - dw.dxfString(2, name); - dw.dxfInt(70, 0); -} - - - -/** - * Writes a block's definition (no entities) to the DXF file. - */ -void DL_Dxf::writeBlock(DL_WriterA& dw, const DL_BlockData& data) -{ - if (data.name.empty()) - { - std::cerr << "DL_Dxf::writeBlock: " - << "Block name must not be empty\n"; - return; - } - - std::string n = data.name; - std::transform(n.begin(), n.end(), n.begin(), ::toupper); - - if (n=="*PAPER_SPACE") - { - dw.sectionBlockEntry(0x1C); - } - else if (n=="*MODEL_SPACE") - { - dw.sectionBlockEntry(0x20); - } - else if (n=="*PAPER_SPACE0") - { - dw.sectionBlockEntry(0x24); - } - else - { - dw.sectionBlockEntry(); - } - dw.dxfString(2, data.name); - dw.dxfInt(70, 0); - dw.coord(10, data.bpx, data.bpy, data.bpz); - dw.dxfString(3, data.name); - dw.dxfString(1, ""); -} - - - -/** - * Writes a block end. - * - * @param name Block name - */ -void DL_Dxf::writeEndBlock(DL_WriterA& dw, const std::string& name) -{ - std::string n = name; - std::transform(n.begin(), n.end(), n.begin(), ::toupper); - - if (n=="*PAPER_SPACE") - { - dw.sectionBlockEntryEnd(0x1D); - } - else if (n=="*MODEL_SPACE") - { - dw.sectionBlockEntryEnd(0x21); - } - else if (n=="*PAPER_SPACE0") - { - dw.sectionBlockEntryEnd(0x25); - } - else - { - dw.sectionBlockEntryEnd(); - } -} - - - -/** - * Writes a viewport section. This section is needed in DL_VERSION_R13. - * Note that this method currently only writes a faked VPORT section - * to make the file readable by Aut*cad. - */ -void DL_Dxf::writeVPort(DL_WriterA& dw) const -{ - dw.dxfString(0, "TABLE"); - dw.dxfString(2, "VPORT"); - if (version==DL_VERSION_2000) - { - dw.dxfHex(5, 0x8); - } - //dw.dxfHex(330, 0); - if (version==DL_VERSION_2000) //-V581 - { - dw.dxfString(100, "AcDbSymbolTable"); - } - dw.dxfInt(70, 1); - dw.dxfString(0, "VPORT"); - //dw.dxfHex(5, 0x2F); - if (version==DL_VERSION_2000) - { - dw.handle(); - } - //dw.dxfHex(330, 8); - if (version==DL_VERSION_2000) //-V581 - { - dw.dxfString(100, "AcDbSymbolTableRecord"); - dw.dxfString(100, "AcDbViewportTableRecord"); - } - dw.dxfString( 2, "*Active"); - dw.dxfInt( 70, 0); - dw.dxfReal( 10, 0.0); - dw.dxfReal( 20, 0.0); - dw.dxfReal( 11, 1.0); - dw.dxfReal( 21, 1.0); - dw.dxfReal( 12, 286.3055555555555); - dw.dxfReal( 22, 148.5); - dw.dxfReal( 13, 0.0); - dw.dxfReal( 23, 0.0); - dw.dxfReal( 14, 10.0); - dw.dxfReal( 24, 10.0); - dw.dxfReal( 15, 10.0); - dw.dxfReal( 25, 10.0); - dw.dxfReal( 16, 0.0); - dw.dxfReal( 26, 0.0); - dw.dxfReal( 36, 1.0); - dw.dxfReal( 17, 0.0); - dw.dxfReal( 27, 0.0); - dw.dxfReal( 37, 0.0); - dw.dxfReal( 40, 297.0); - dw.dxfReal( 41, 1.92798353909465); - dw.dxfReal( 42, 50.0); - dw.dxfReal( 43, 0.0); - dw.dxfReal( 44, 0.0); - dw.dxfReal( 50, 0.0); - dw.dxfReal( 51, 0.0); - dw.dxfInt( 71, 0); - dw.dxfInt( 72, 100); - dw.dxfInt( 73, 1); - dw.dxfInt( 74, 3); - dw.dxfInt( 75, 1); - dw.dxfInt( 76, 1); - dw.dxfInt( 77, 0); - dw.dxfInt( 78, 0); - - if (version==DL_VERSION_2000) - { - dw.dxfInt(281, 0); - dw.dxfInt( 65, 1); - dw.dxfReal(110, 0.0); - dw.dxfReal(120, 0.0); - dw.dxfReal(130, 0.0); - dw.dxfReal(111, 1.0); - dw.dxfReal(121, 0.0); - dw.dxfReal(131, 0.0); - dw.dxfReal(112, 0.0); - dw.dxfReal(122, 1.0); - dw.dxfReal(132, 0.0); - dw.dxfInt( 79, 0); - dw.dxfReal(146, 0.0); - } - dw.dxfString( 0, "ENDTAB"); -} - - - -/** - * Writes a style section. This section is needed in DL_VERSION_R13. - */ -void DL_Dxf::writeStyle(DL_WriterA& dw, const DL_StyleData& style) -{ -// dw.dxfString( 0, "TABLE"); -// dw.dxfString( 2, "STYLE"); -// if (version==DL_VERSION_2000) { -// dw.dxfHex(5, 3); -// } - //dw.dxfHex(330, 0); -// if (version==DL_VERSION_2000) { -// dw.dxfString(100, "AcDbSymbolTable"); -// } -// dw.dxfInt( 70, 1); - dw.dxfString( 0, "STYLE"); - if (version==DL_VERSION_2000) - { - if (style.name=="Standard") - { - //dw.dxfHex(5, 0x11); - styleHandleStd = dw.handle(); - } - else - { - dw.handle(); - } - } - //dw.dxfHex(330, 3); - if (version==DL_VERSION_2000) //-V581 - { - dw.dxfString(100, "AcDbSymbolTableRecord"); - dw.dxfString(100, "AcDbTextStyleTableRecord"); - } - dw.dxfString( 2, style.name); - dw.dxfInt( 70, style.flags); - dw.dxfReal( 40, style.fixedTextHeight); - dw.dxfReal( 41, style.widthFactor); - dw.dxfReal( 50, style.obliqueAngle); - dw.dxfInt( 71, style.textGenerationFlags); - dw.dxfReal( 42, style.lastHeightUsed); - if (version==DL_VERSION_2000) - { - dw.dxfString( 3, ""); - dw.dxfString( 4, ""); - dw.dxfString(1001, "ACAD"); - //dw.dxfString(1000, style.name); - dw.dxfString(1000, style.primaryFontFile); - int xFlags = 0; - if (style.bold) - { - xFlags = xFlags|0x2000000; - } - if (style.italic) - { - xFlags = xFlags|0x1000000; - } - dw.dxfInt(1071, xFlags); - } - else - { - dw.dxfString( 3, style.primaryFontFile); - dw.dxfString( 4, style.bigFontFile); - } - //dw.dxfString( 0, "ENDTAB"); -} - - - -/** - * Writes a view section. This section is needed in DL_VERSION_R13. - * Note that this method currently only writes a faked VIEW section - * to make the file readable by Aut*cad. - */ -void DL_Dxf::writeView(DL_WriterA& dw) const -{ - dw.dxfString( 0, "TABLE"); - dw.dxfString( 2, "VIEW"); - if (version==DL_VERSION_2000) - { - dw.dxfHex(5, 6); - } - //dw.dxfHex(330, 0); - if (version==DL_VERSION_2000) //-V581 - { - dw.dxfString(100, "AcDbSymbolTable"); - } - dw.dxfInt( 70, 0); - dw.dxfString( 0, "ENDTAB"); -} - - - -/** - * Writes a ucs section. This section is needed in DL_VERSION_R13. - * Note that this method currently only writes a faked UCS section - * to make the file readable by Aut*cad. - */ -void DL_Dxf::writeUcs(DL_WriterA& dw) const -{ - dw.dxfString( 0, "TABLE"); - dw.dxfString( 2, "UCS"); - if (version==DL_VERSION_2000) - { - dw.dxfHex(5, 7); - } - //dw.dxfHex(330, 0); - if (version==DL_VERSION_2000) //-V581 - { - dw.dxfString(100, "AcDbSymbolTable"); - } - dw.dxfInt( 70, 0); - dw.dxfString( 0, "ENDTAB"); -} - - - -/** - * Writes a dimstyle section. This section is needed in DL_VERSION_R13. - * Note that this method currently only writes a faked DIMSTYLE section - * to make the file readable by Aut*cad. - */ -void DL_Dxf::writeDimStyle(DL_WriterA& dw, - double dimasz, double dimexe, double dimexo, - double dimgap, double dimtxt) -{ - - dw.dxfString( 0, "TABLE"); - dw.dxfString( 2, "DIMSTYLE"); - if (version==DL_VERSION_2000) - { - dw.dxfHex(5, 0xA); - dw.dxfString(100, "AcDbSymbolTable"); - } - dw.dxfInt( 70, 1); - if (version==DL_VERSION_2000) - { - dw.dxfString(100, "AcDbDimStyleTable"); - dw.dxfInt( 71, 0); - } - - - dw.dxfString( 0, "DIMSTYLE"); - if (version==DL_VERSION_2000) - { - dw.dxfHex(105, 0x27); - } - //dw.handle(105); - //dw.dxfHex(330, 0xA); - if (version==DL_VERSION_2000) //-V581 - { - dw.dxfString(100, "AcDbSymbolTableRecord"); - dw.dxfString(100, "AcDbDimStyleTableRecord"); - } - dw.dxfString( 2, "Standard"); - if (version==DL_VERSION_R12) - { - dw.dxfString( 3, ""); - dw.dxfString( 4, ""); - dw.dxfString( 5, ""); - dw.dxfString( 6, ""); - dw.dxfString( 7, ""); - dw.dxfReal( 40, 1.0); - } - - dw.dxfReal( 41, dimasz); - dw.dxfReal( 42, dimexo); - dw.dxfReal( 43, 3.75); - dw.dxfReal( 44, dimexe); - if (version==DL_VERSION_R12) - { - dw.dxfReal( 45, 0.0); - dw.dxfReal( 46, 0.0); - dw.dxfReal( 47, 0.0); - dw.dxfReal( 48, 0.0); - } - dw.dxfInt( 70, 0); - if (version==DL_VERSION_R12) - { - dw.dxfInt( 71, 0); - dw.dxfInt( 72, 0); - } - dw.dxfInt( 73, 0); - dw.dxfInt( 74, 0); - if (version==DL_VERSION_R12) - { - dw.dxfInt( 75, 0); - dw.dxfInt( 76, 0); - } - dw.dxfInt( 77, 1); - dw.dxfInt( 78, 8); - dw.dxfReal(140, dimtxt); - dw.dxfReal(141, 2.5); - if (version==DL_VERSION_R12) - { - dw.dxfReal(142, 0.0); - } - dw.dxfReal(143, 0.03937007874016); - if (version==DL_VERSION_R12) - { - dw.dxfReal(144, 1.0); - dw.dxfReal(145, 0.0); - dw.dxfReal(146, 1.0); - } - dw.dxfReal(147, dimgap); - if (version==DL_VERSION_R12) - { - dw.dxfInt(170, 0); - } - dw.dxfInt(171, 3); - dw.dxfInt(172, 1); - if (version==DL_VERSION_R12) - { - dw.dxfInt(173, 0); - dw.dxfInt(174, 0); - dw.dxfInt(175, 0); - dw.dxfInt(176, 0); - dw.dxfInt(177, 0); - dw.dxfInt(178, 0); - } - if (version==DL_VERSION_2000) - { - dw.dxfInt(271, 2); - dw.dxfInt(272, 2); - dw.dxfInt(274, 3); - dw.dxfInt(278, 44); - dw.dxfInt(283, 0); - dw.dxfInt(284, 8); - dw.dxfHex(340, static_cast(styleHandleStd)); - //dw.dxfHex(340, 0x11); - } - // * / - dw.dxfString( 0, "ENDTAB"); -} - - - -/** - * Writes a blockrecord section. This section is needed in DL_VERSION_R13. - * Note that this method currently only writes a faked BLOCKRECORD section - * to make the file readable by Aut*cad. - */ -void DL_Dxf::writeBlockRecord(DL_WriterA& dw) const -{ - dw.dxfString( 0, "TABLE"); - dw.dxfString( 2, "BLOCK_RECORD"); - if (version==DL_VERSION_2000) - { - dw.dxfHex(5, 1); - } - //dw.dxfHex(330, 0); - if (version==DL_VERSION_2000) //-V581 - { - dw.dxfString(100, "AcDbSymbolTable"); - } - dw.dxfInt( 70, 1); - - dw.dxfString( 0, "BLOCK_RECORD"); - if (version==DL_VERSION_2000) - { - dw.dxfHex(5, 0x1F); - } - //int msh = dw.handle(); - //dw.setModelSpaceHandle(msh); - //dw.dxfHex(330, 1); - if (version==DL_VERSION_2000) //-V581 - { - dw.dxfString(100, "AcDbSymbolTableRecord"); - dw.dxfString(100, "AcDbBlockTableRecord"); - } - dw.dxfString( 2, "*Model_Space"); - dw.dxfHex(340, 0x22); - - dw.dxfString( 0, "BLOCK_RECORD"); - if (version==DL_VERSION_2000) - { - dw.dxfHex(5, 0x1B); - } - //int psh = dw.handle(); - //dw.setPaperSpaceHandle(psh); - //dw.dxfHex(330, 1); - if (version==DL_VERSION_2000) //-V581 - { - dw.dxfString(100, "AcDbSymbolTableRecord"); - dw.dxfString(100, "AcDbBlockTableRecord"); - } - dw.dxfString( 2, "*Paper_Space"); - dw.dxfHex(340, 0x1E); - - dw.dxfString( 0, "BLOCK_RECORD"); - if (version==DL_VERSION_2000) - { - dw.dxfHex(5, 0x23); - } - //int ps0h = dw.handle(); - //dw.setPaperSpace0Handle(ps0h); - //dw.dxfHex(330, 1); - if (version==DL_VERSION_2000) //-V581 - { - dw.dxfString(100, "AcDbSymbolTableRecord"); - dw.dxfString(100, "AcDbBlockTableRecord"); - } - dw.dxfString( 2, "*Paper_Space0"); - dw.dxfHex(340, 0x26); - - //dw.dxfString( 0, "ENDTAB"); -} - - - -/** - * Writes a single block record with the given name. - */ -void DL_Dxf::writeBlockRecord(DL_WriterA& dw, const std::string& name) const -{ - dw.dxfString( 0, "BLOCK_RECORD"); - if (version==DL_VERSION_2000) - { - dw.handle(); - } - //dw->dxfHex(330, 1); - if (version==DL_VERSION_2000) //-V581 - { - dw.dxfString(100, "AcDbSymbolTableRecord"); - dw.dxfString(100, "AcDbBlockTableRecord"); - } - dw.dxfString( 2, name); - dw.dxfHex(340, 0); -} - - - -/** - * Writes a objects section. This section is needed in DL_VERSION_R13. - * Note that this method currently only writes a faked OBJECTS section - * to make the file readable by Aut*cad. - */ -void DL_Dxf::writeObjects(DL_WriterA& dw, const std::string& appDictionaryName) -{ - dw.dxfString( 0, "SECTION"); - dw.dxfString( 2, "OBJECTS"); - - - dw.dxfString( 0, "DICTIONARY"); - dw.dxfHex(5, 0xC); - dw.dxfString(100, "AcDbDictionary"); - dw.dxfInt(280, 0); - dw.dxfInt(281, 1); - dw.dxfString( 3, "ACAD_GROUP"); - dw.dxfHex(350, 0xD); - dw.dxfString( 3, "ACAD_LAYOUT"); - dw.dxfHex(350, 0x1A); - dw.dxfString( 3, "ACAD_MLINESTYLE"); - dw.dxfHex(350, 0x17); - dw.dxfString( 3, "ACAD_PLOTSETTINGS"); - dw.dxfHex(350, 0x19); - dw.dxfString( 3, "ACAD_PLOTSTYLENAME"); - dw.dxfHex(350, 0xE); - dw.dxfString( 3, "AcDbVariableDictionary"); - int acDbVariableDictionaryHandle = static_cast(dw.handle(350)); - //int acDbVariableDictionaryHandle = dw.getNextHandle(); - //dw.dxfHex(350, acDbVariableDictionaryHandle); - //dw.incHandle(); - - if (appDictionaryName.length()!=0) - { - dw.dxfString( 3, appDictionaryName); - appDictionaryHandle = dw.handle(350); - //appDictionaryHandle = dw.getNextHandle(); - //dw.dxfHex(350, appDictionaryHandle); - //dw.incHandle(); - } - - dw.dxfString( 0, "DICTIONARY"); - dw.dxfHex(5, 0xD); - //dw.handle(); // D - //dw.dxfHex(330, 0xC); - dw.dxfString(100, "AcDbDictionary"); - dw.dxfInt(280, 0); - dw.dxfInt(281, 1); - - - dw.dxfString( 0, "ACDBDICTIONARYWDFLT"); - dw.dxfHex(5, 0xE); - //dicId4 = dw.handle(); // E - //dw.dxfHex(330, 0xC); // C - dw.dxfString(100, "AcDbDictionary"); - dw.dxfInt(281, 1); - dw.dxfString( 3, "Normal"); - dw.dxfHex(350, 0xF); - //dw.dxfHex(350, dw.getNextHandle()+5); // F - dw.dxfString(100, "AcDbDictionaryWithDefault"); - dw.dxfHex(340, 0xF); - //dw.dxfHex(340, dw.getNextHandle()+5); // F - - - dw.dxfString( 0, "ACDBPLACEHOLDER"); - dw.dxfHex(5, 0xF); - //dw.handle(); // F - //dw.dxfHex(330, dicId4); // E - - - dw.dxfString( 0, "DICTIONARY"); - //dicId3 = dw.handle(); // 17 - dw.dxfHex(5, 0x17); - //dw.dxfHex(330, 0xC); // C - dw.dxfString(100, "AcDbDictionary"); - dw.dxfInt(280, 0); - dw.dxfInt(281, 1); - dw.dxfString( 3, "Standard"); - dw.dxfHex(350, 0x18); - //dw.dxfHex(350, dw.getNextHandle()+5); // 18 - - - dw.dxfString( 0, "MLINESTYLE"); - dw.dxfHex(5, 0x18); - //dw.handle(); // 18 - //dw.dxfHex(330, dicId3); // 17 - dw.dxfString(100, "AcDbMlineStyle"); - dw.dxfString( 2, "STANDARD"); - dw.dxfInt( 70, 0); - dw.dxfString( 3, ""); - dw.dxfInt( 62, 256); - dw.dxfReal( 51, 90.0); - dw.dxfReal( 52, 90.0); - dw.dxfInt( 71, 2); - dw.dxfReal( 49, 0.5); - dw.dxfInt( 62, 256); - dw.dxfString( 6, "BYLAYER"); - dw.dxfReal( 49, -0.5); - dw.dxfInt( 62, 256); - dw.dxfString( 6, "BYLAYER"); - - - dw.dxfString( 0, "DICTIONARY"); - dw.dxfHex(5, 0x19); - //dw.handle(); // 17 - //dw.dxfHex(330, 0xC); // C - dw.dxfString(100, "AcDbDictionary"); - dw.dxfInt(280, 0); - dw.dxfInt(281, 1); - - - dw.dxfString( 0, "DICTIONARY"); - //dicId2 = dw.handle(); // 1A - dw.dxfHex(5, 0x1A); - //dw.dxfHex(330, 0xC); - dw.dxfString(100, "AcDbDictionary"); - dw.dxfInt(281, 1); - dw.dxfString( 3, "Layout1"); - dw.dxfHex(350, 0x1E); - //dw.dxfHex(350, dw.getNextHandle()+2); // 1E - dw.dxfString( 3, "Layout2"); - dw.dxfHex(350, 0x26); - //dw.dxfHex(350, dw.getNextHandle()+4); // 26 - dw.dxfString( 3, "Model"); - dw.dxfHex(350, 0x22); - //dw.dxfHex(350, dw.getNextHandle()+5); // 22 - - - dw.dxfString( 0, "LAYOUT"); - dw.dxfHex(5, 0x1E); - //dw.handle(); // 1E - //dw.dxfHex(330, dicId2); // 1A - dw.dxfString(100, "AcDbPlotSettings"); - dw.dxfString( 1, ""); - dw.dxfString( 2, "none_device"); - dw.dxfString( 4, ""); - dw.dxfString( 6, ""); - dw.dxfReal( 40, 0.0); - dw.dxfReal( 41, 0.0); - dw.dxfReal( 42, 0.0); - dw.dxfReal( 43, 0.0); - dw.dxfReal( 44, 0.0); - dw.dxfReal( 45, 0.0); - dw.dxfReal( 46, 0.0); - dw.dxfReal( 47, 0.0); - dw.dxfReal( 48, 0.0); - dw.dxfReal( 49, 0.0); - dw.dxfReal(140, 0.0); - dw.dxfReal(141, 0.0); - dw.dxfReal(142, 1.0); - dw.dxfReal(143, 1.0); - dw.dxfInt( 70, 688); - dw.dxfInt( 72, 0); - dw.dxfInt( 73, 0); - dw.dxfInt( 74, 5); - dw.dxfString( 7, ""); - dw.dxfInt( 75, 16); - dw.dxfReal(147, 1.0); - dw.dxfReal(148, 0.0); - dw.dxfReal(149, 0.0); - dw.dxfString(100, "AcDbLayout"); - dw.dxfString( 1, "Layout1"); - dw.dxfInt( 70, 1); - dw.dxfInt( 71, 1); - dw.dxfReal( 10, 0.0); - dw.dxfReal( 20, 0.0); - dw.dxfReal( 11, 420.0); - dw.dxfReal( 21, 297.0); - dw.dxfReal( 12, 0.0); - dw.dxfReal( 22, 0.0); - dw.dxfReal( 32, 0.0); - dw.dxfReal( 14, 1.000000000000000E+20); - dw.dxfReal( 24, 1.000000000000000E+20); - dw.dxfReal( 34, 1.000000000000000E+20); - dw.dxfReal( 15, -1.000000000000000E+20); - dw.dxfReal( 25, -1.000000000000000E+20); - dw.dxfReal( 35, -1.000000000000000E+20); - dw.dxfReal(146, 0.0); - dw.dxfReal( 13, 0.0); - dw.dxfReal( 23, 0.0); - dw.dxfReal( 33, 0.0); - dw.dxfReal( 16, 1.0); - dw.dxfReal( 26, 0.0); - dw.dxfReal( 36, 0.0); - dw.dxfReal( 17, 0.0); - dw.dxfReal( 27, 1.0); - dw.dxfReal( 37, 0.0); - dw.dxfInt( 76, 0); - //dw.dxfHex(330, dw.getPaperSpaceHandle()); // 1B - dw.dxfHex(330, 0x1B); - - - dw.dxfString( 0, "LAYOUT"); - dw.dxfHex(5, 0x22); - //dw.handle(); // 22 - //dw.dxfHex(330, dicId2); // 1A - dw.dxfString(100, "AcDbPlotSettings"); - dw.dxfString( 1, ""); - dw.dxfString( 2, "none_device"); - dw.dxfString( 4, ""); - dw.dxfString( 6, ""); - dw.dxfReal( 40, 0.0); - dw.dxfReal( 41, 0.0); - dw.dxfReal( 42, 0.0); - dw.dxfReal( 43, 0.0); - dw.dxfReal( 44, 0.0); - dw.dxfReal( 45, 0.0); - dw.dxfReal( 46, 0.0); - dw.dxfReal( 47, 0.0); - dw.dxfReal( 48, 0.0); - dw.dxfReal( 49, 0.0); - dw.dxfReal(140, 0.0); - dw.dxfReal(141, 0.0); - dw.dxfReal(142, 1.0); - dw.dxfReal(143, 1.0); - dw.dxfInt( 70, 1712); - dw.dxfInt( 72, 0); - dw.dxfInt( 73, 0); - dw.dxfInt( 74, 0); - dw.dxfString( 7, ""); - dw.dxfInt( 75, 0); - dw.dxfReal(147, 1.0); - dw.dxfReal(148, 0.0); - dw.dxfReal(149, 0.0); - dw.dxfString(100, "AcDbLayout"); - dw.dxfString( 1, "Model"); - dw.dxfInt( 70, 1); - dw.dxfInt( 71, 0); - dw.dxfReal( 10, 0.0); - dw.dxfReal( 20, 0.0); - dw.dxfReal( 11, 12.0); - dw.dxfReal( 21, 9.0); - dw.dxfReal( 12, 0.0); - dw.dxfReal( 22, 0.0); - dw.dxfReal( 32, 0.0); - dw.dxfReal( 14, 0.0); - dw.dxfReal( 24, 0.0); - dw.dxfReal( 34, 0.0); - dw.dxfReal( 15, 0.0); - dw.dxfReal( 25, 0.0); - dw.dxfReal( 35, 0.0); - dw.dxfReal(146, 0.0); - dw.dxfReal( 13, 0.0); - dw.dxfReal( 23, 0.0); - dw.dxfReal( 33, 0.0); - dw.dxfReal( 16, 1.0); - dw.dxfReal( 26, 0.0); - dw.dxfReal( 36, 0.0); - dw.dxfReal( 17, 0.0); - dw.dxfReal( 27, 1.0); - dw.dxfReal( 37, 0.0); - dw.dxfInt( 76, 0); - //dw.dxfHex(330, dw.getModelSpaceHandle()); // 1F - dw.dxfHex(330, 0x1F); - - - dw.dxfString( 0, "LAYOUT"); - //dw.handle(); // 26 - dw.dxfHex(5, 0x26); - //dw.dxfHex(330, dicId2); // 1A - dw.dxfString(100, "AcDbPlotSettings"); - dw.dxfString( 1, ""); - dw.dxfString( 2, "none_device"); - dw.dxfString( 4, ""); - dw.dxfString( 6, ""); - dw.dxfReal( 40, 0.0); - dw.dxfReal( 41, 0.0); - dw.dxfReal( 42, 0.0); - dw.dxfReal( 43, 0.0); - dw.dxfReal( 44, 0.0); - dw.dxfReal( 45, 0.0); - dw.dxfReal( 46, 0.0); - dw.dxfReal( 47, 0.0); - dw.dxfReal( 48, 0.0); - dw.dxfReal( 49, 0.0); - dw.dxfReal(140, 0.0); - dw.dxfReal(141, 0.0); - dw.dxfReal(142, 1.0); - dw.dxfReal(143, 1.0); - dw.dxfInt( 70, 688); - dw.dxfInt( 72, 0); - dw.dxfInt( 73, 0); - dw.dxfInt( 74, 5); - dw.dxfString( 7, ""); - dw.dxfInt( 75, 16); - dw.dxfReal(147, 1.0); - dw.dxfReal(148, 0.0); - dw.dxfReal(149, 0.0); - dw.dxfString(100, "AcDbLayout"); - dw.dxfString( 1, "Layout2"); - dw.dxfInt( 70, 1); - dw.dxfInt( 71, 2); - dw.dxfReal( 10, 0.0); - dw.dxfReal( 20, 0.0); - dw.dxfReal( 11, 12.0); - dw.dxfReal( 21, 9.0); - dw.dxfReal( 12, 0.0); - dw.dxfReal( 22, 0.0); - dw.dxfReal( 32, 0.0); - dw.dxfReal( 14, 0.0); - dw.dxfReal( 24, 0.0); - dw.dxfReal( 34, 0.0); - dw.dxfReal( 15, 0.0); - dw.dxfReal( 25, 0.0); - dw.dxfReal( 35, 0.0); - dw.dxfReal(146, 0.0); - dw.dxfReal( 13, 0.0); - dw.dxfReal( 23, 0.0); - dw.dxfReal( 33, 0.0); - dw.dxfReal( 16, 1.0); - dw.dxfReal( 26, 0.0); - dw.dxfReal( 36, 0.0); - dw.dxfReal( 17, 0.0); - dw.dxfReal( 27, 1.0); - dw.dxfReal( 37, 0.0); - dw.dxfInt( 76, 0); - //dw.dxfHex(330, dw.getPaperSpace0Handle()); // 23 - dw.dxfHex(330, 0x23); - - dw.dxfString( 0, "DICTIONARY"); - //dw.dxfHex(5, 0x2C); - //dicId5 = - dw.dxfHex(5, acDbVariableDictionaryHandle); - //dw.handle(); // 2C - //dw.dxfHex(330, 0xC); // C - dw.dxfString(100, "AcDbDictionary"); - dw.dxfInt(281, 1); - dw.dxfString( 3, "DIMASSOC"); - //dw.dxfHex(350, 0x2F); - dw.dxfHex(350, static_cast(dw.getNextHandle()+1)); // 2E - dw.dxfString( 3, "HIDETEXT"); - //dw.dxfHex(350, 0x2E); - dw.dxfHex(350, static_cast(dw.getNextHandle())); // 2D - - - dw.dxfString( 0, "DICTIONARYVAR"); - //dw.dxfHex(5, 0x2E); - dw.handle(); // 2E - //dw.dxfHex(330, dicId5); // 2C - dw.dxfString(100, "DictionaryVariables"); - dw.dxfInt(280, 0); - dw.dxfInt( 1, 2); - - - dw.dxfString( 0, "DICTIONARYVAR"); - //dw.dxfHex(5, 0x2D); - dw.handle(); // 2D - //dw.dxfHex(330, dicId5); // 2C - dw.dxfString(100, "DictionaryVariables"); - dw.dxfInt(280, 0); - dw.dxfInt( 1, 1); -} - -void DL_Dxf::writeAppDictionary(DL_WriterA& dw) -{ - dw.dxfString( 0, "DICTIONARY"); - //dw.handle(); - dw.dxfHex(5, static_cast(appDictionaryHandle)); - dw.dxfString(100, "AcDbDictionary"); - dw.dxfInt(281, 1); -} - -int DL_Dxf::writeDictionaryEntry(DL_WriterA& dw, const std::string& name) -{ - dw.dxfString( 3, name); - int handle = static_cast(dw.getNextHandle()); - dw.dxfHex(350, handle); - dw.incHandle(); - return handle; -} - -void DL_Dxf::writeXRecord(DL_WriterA& dw, int handle, int value) -{ - dw.dxfString( 0, "XRECORD"); - dw.dxfHex(5, handle); - dw.dxfHex(330, static_cast(appDictionaryHandle)); - dw.dxfString(100, "AcDbXrecord"); - dw.dxfInt(280, 1); - dw.dxfInt(90, value); -} - -void DL_Dxf::writeXRecord(DL_WriterA& dw, int handle, double value) -{ - dw.dxfString( 0, "XRECORD"); - dw.dxfHex(5, handle); - dw.dxfHex(330, static_cast(appDictionaryHandle)); - dw.dxfString(100, "AcDbXrecord"); - dw.dxfInt(280, 1); - dw.dxfReal(40, value); -} - -void DL_Dxf::writeXRecord(DL_WriterA& dw, int handle, bool value) -{ - dw.dxfString( 0, "XRECORD"); - dw.dxfHex(5, handle); - dw.dxfHex(330, static_cast(appDictionaryHandle)); - dw.dxfString(100, "AcDbXrecord"); - dw.dxfInt(280, 1); - dw.dxfBool(290, value); -} - -void DL_Dxf::writeXRecord(DL_WriterA& dw, int handle, const std::string& value) -{ - dw.dxfString( 0, "XRECORD"); - dw.dxfHex(5, handle); - dw.dxfHex(330, static_cast(appDictionaryHandle)); - dw.dxfString(100, "AcDbXrecord"); - dw.dxfInt(280, 1); - dw.dxfString(1000, value); -} - -/** - * Writes the end of the objects section. This section is needed in DL_VERSION_R13. - * Note that this method currently only writes a faked OBJECTS section - * to make the file readable by Aut*cad. - */ -void DL_Dxf::writeObjectsEnd(DL_WriterA& dw) -{ - dw.dxfString( 0, "ENDSEC"); -} - - - -/** - * Writes a comment to the DXF file. - */ -void DL_Dxf::writeComment(DL_WriterA& dw, const std::string& comment) -{ - dw.dxfString(999, comment); -} - - -/** - * Checks if the given variable is known by the given DXF version. - */ -bool DL_Dxf::checkVariable(const char* var, DL_Codes::version version) -{ - if (version>=DL_VERSION_2000) - { - return true; - } - else if (version==DL_VERSION_R12) - { - // these are all the variables recognized by dxf r12: - if (!strcmp(var, "$ACADVER")) - { - return true; - } - if (!strcmp(var, "$ANGBASE")) - { - return true; - } - if (!strcmp(var, "$ANGDIR")) - { - return true; - } - if (!strcmp(var, "$ATTDIA")) - { - return true; - } - if (!strcmp(var, "$ATTMODE")) - { - return true; - } - if (!strcmp(var, "$ATTREQ")) - { - return true; - } - if (!strcmp(var, "$AUNITS")) - { - return true; - } - if (!strcmp(var, "$AUPREC")) - { - return true; - } - if (!strcmp(var, "$AXISMODE")) - { - return true; - } - if (!strcmp(var, "$AXISUNIT")) - { - return true; - } - if (!strcmp(var, "$BLIPMODE")) - { - return true; - } - if (!strcmp(var, "$CECOLOR")) - { - return true; - } - if (!strcmp(var, "$CELTYPE")) - { - return true; - } - if (!strcmp(var, "$CHAMFERA")) - { - return true; - } - if (!strcmp(var, "$CHAMFERB")) - { - return true; - } - if (!strcmp(var, "$CLAYER")) - { - return true; - } - if (!strcmp(var, "$COORDS")) - { - return true; - } - if (!strcmp(var, "$DIMALT")) - { - return true; - } - if (!strcmp(var, "$DIMALTD")) - { - return true; - } - if (!strcmp(var, "$DIMALTF")) - { - return true; - } - if (!strcmp(var, "$DIMAPOST")) - { - return true; - } - if (!strcmp(var, "$DIMASO")) - { - return true; - } - if (!strcmp(var, "$DIMASZ")) - { - return true; - } - if (!strcmp(var, "$DIMBLK")) - { - return true; - } - if (!strcmp(var, "$DIMBLK1")) - { - return true; - } - if (!strcmp(var, "$DIMBLK2")) - { - return true; - } - if (!strcmp(var, "$DIMCEN")) - { - return true; - } - if (!strcmp(var, "$DIMCLRD")) - { - return true; - } - if (!strcmp(var, "$DIMCLRE")) - { - return true; - } - if (!strcmp(var, "$DIMCLRT")) - { - return true; - } - if (!strcmp(var, "$DIMDLE")) - { - return true; - } - if (!strcmp(var, "$DIMDLI")) - { - return true; - } - if (!strcmp(var, "$DIMEXE")) - { - return true; - } - if (!strcmp(var, "$DIMEXO")) - { - return true; - } - if (!strcmp(var, "$DIMGAP")) - { - return true; - } - if (!strcmp(var, "$DIMLFAC")) - { - return true; - } - if (!strcmp(var, "$DIMLIM")) - { - return true; - } - if (!strcmp(var, "$DIMPOST")) - { - return true; - } - if (!strcmp(var, "$DIMRND")) - { - return true; - } - if (!strcmp(var, "$DIMSAH")) - { - return true; - } - if (!strcmp(var, "$DIMSCALE")) - { - return true; - } - if (!strcmp(var, "$DIMSE1")) - { - return true; - } - if (!strcmp(var, "$DIMSE2")) - { - return true; - } - if (!strcmp(var, "$DIMSHO")) - { - return true; - } - if (!strcmp(var, "$DIMSOXD")) - { - return true; - } - if (!strcmp(var, "$DIMSTYLE")) - { - return true; - } - if (!strcmp(var, "$DIMTAD")) - { - return true; - } - if (!strcmp(var, "$DIMTFAC")) - { - return true; - } - if (!strcmp(var, "$DIMTIH")) - { - return true; - } - if (!strcmp(var, "$DIMTIX")) - { - return true; - } - if (!strcmp(var, "$DIMTM")) - { - return true; - } - if (!strcmp(var, "$DIMTOFL")) - { - return true; - } - if (!strcmp(var, "$DIMTOH")) - { - return true; - } - if (!strcmp(var, "$DIMTOL")) - { - return true; - } - if (!strcmp(var, "$DIMTP")) - { - return true; - } - if (!strcmp(var, "$DIMTSZ")) - { - return true; - } - if (!strcmp(var, "$DIMTVP")) - { - return true; - } - if (!strcmp(var, "$DIMTXT")) - { - return true; - } - if (!strcmp(var, "$DIMZIN")) - { - return true; - } - if (!strcmp(var, "$DWGCODEPAGE")) - { - return true; - } - if (!strcmp(var, "$DRAGMODE")) - { - return true; - } - if (!strcmp(var, "$ELEVATION")) - { - return true; - } - if (!strcmp(var, "$EXTMAX")) - { - return true; - } - if (!strcmp(var, "$EXTMIN")) - { - return true; - } - if (!strcmp(var, "$FILLETRAD")) - { - return true; - } - if (!strcmp(var, "$FILLMODE")) - { - return true; - } - if (!strcmp(var, "$HANDLING")) - { - return true; - } - if (!strcmp(var, "$HANDSEED")) - { - return true; - } - if (!strcmp(var, "$INSBASE")) - { - return true; - } - if (!strcmp(var, "$LIMCHECK")) - { - return true; - } - if (!strcmp(var, "$LIMMAX")) - { - return true; - } - if (!strcmp(var, "$LIMMIN")) - { - return true; - } - if (!strcmp(var, "$LTSCALE")) - { - return true; - } - if (!strcmp(var, "$LUNITS")) - { - return true; - } - if (!strcmp(var, "$LUPREC")) - { - return true; - } - if (!strcmp(var, "$MAXACTVP")) - { - return true; - } - if (!strcmp(var, "$MENU")) - { - return true; - } - if (!strcmp(var, "$MIRRTEXT")) - { - return true; - } - if (!strcmp(var, "$ORTHOMODE")) - { - return true; - } - if (!strcmp(var, "$OSMODE")) - { - return true; - } - if (!strcmp(var, "$PDMODE")) - { - return true; - } - if (!strcmp(var, "$PDSIZE")) - { - return true; - } - if (!strcmp(var, "$PELEVATION")) - { - return true; - } - if (!strcmp(var, "$PEXTMAX")) - { - return true; - } - if (!strcmp(var, "$PEXTMIN")) - { - return true; - } - if (!strcmp(var, "$PLIMCHECK")) - { - return true; - } - if (!strcmp(var, "$PLIMMAX")) - { - return true; - } - if (!strcmp(var, "$PLIMMIN")) - { - return true; - } - if (!strcmp(var, "$PLINEGEN")) - { - return true; - } - if (!strcmp(var, "$PLINEWID")) - { - return true; - } - if (!strcmp(var, "$PSLTSCALE")) - { - return true; - } - if (!strcmp(var, "$PUCSNAME")) - { - return true; - } - if (!strcmp(var, "$PUCSORG")) - { - return true; - } - if (!strcmp(var, "$PUCSXDIR")) - { - return true; - } - if (!strcmp(var, "$PUCSYDIR")) - { - return true; - } - if (!strcmp(var, "$QTEXTMODE")) - { - return true; - } - if (!strcmp(var, "$REGENMODE")) - { - return true; - } - if (!strcmp(var, "$SHADEDGE")) - { - return true; - } - if (!strcmp(var, "$SHADEDIF")) - { - return true; - } - if (!strcmp(var, "$SKETCHINC")) - { - return true; - } - if (!strcmp(var, "$SKPOLY")) - { - return true; - } - if (!strcmp(var, "$SPLFRAME")) - { - return true; - } - if (!strcmp(var, "$SPLINESEGS")) - { - return true; - } - if (!strcmp(var, "$SPLINETYPE")) - { - return true; - } - if (!strcmp(var, "$SURFTAB1")) - { - return true; - } - if (!strcmp(var, "$SURFTAB2")) - { - return true; - } - if (!strcmp(var, "$SURFTYPE")) - { - return true; - } - if (!strcmp(var, "$SURFU")) - { - return true; - } - if (!strcmp(var, "$SURFV")) - { - return true; - } - if (!strcmp(var, "$TDCREATE")) - { - return true; - } - if (!strcmp(var, "$TDINDWG")) - { - return true; - } - if (!strcmp(var, "$TDUPDATE")) - { - return true; - } - if (!strcmp(var, "$TDUSRTIMER")) - { - return true; - } - if (!strcmp(var, "$TEXTSIZE")) - { - return true; - } - if (!strcmp(var, "$TEXTSTYLE")) - { - return true; - } - if (!strcmp(var, "$THICKNESS")) - { - return true; - } - if (!strcmp(var, "$TILEMODE")) - { - return true; - } - if (!strcmp(var, "$TRACEWID")) - { - return true; - } - if (!strcmp(var, "$UCSNAME")) - { - return true; - } - if (!strcmp(var, "$UCSORG")) - { - return true; - } - if (!strcmp(var, "$UCSXDIR")) - { - return true; - } - if (!strcmp(var, "$UCSYDIR")) - { - return true; - } - if (!strcmp(var, "$UNITMODE")) - { - return true; - } - if (!strcmp(var, "$USERI1")) - { - return true; - } - if (!strcmp(var, "$USERR1")) - { - return true; - } - if (!strcmp(var, "$USRTIMER")) - { - return true; - } - if (!strcmp(var, "$VISRETAIN")) - { - return true; - } - if (!strcmp(var, "$WORLDVIEW")) - { - return true; - } - if (!strcmp(var, "$FASTZOOM")) - { - return true; - } - if (!strcmp(var, "$GRIDMODE")) - { - return true; - } - if (!strcmp(var, "$GRIDUNIT")) - { - return true; - } - if (!strcmp(var, "$SNAPANG")) - { - return true; - } - if (!strcmp(var, "$SNAPBASE")) - { - return true; - } - if (!strcmp(var, "$SNAPISOPAIR")) - { - return true; - } - if (!strcmp(var, "$SNAPMODE")) - { - return true; - } - if (!strcmp(var, "$SNAPSTYLE")) - { - return true; - } - if (!strcmp(var, "$SNAPUNIT")) - { - return true; - } - if (!strcmp(var, "$VIEWCTR")) - { - return true; - } - if (!strcmp(var, "$VIEWDIR")) - { - return true; - } - if (!strcmp(var, "$VIEWSIZE")) - { - return true; - } - return false; - } - - return false; -} - - - -/** - * @returns the library version as int (4 bytes, each byte one version number). - * e.g. if str = "2.0.2.0" getLibVersion returns 0x02000200 - */ -int DL_Dxf::getLibVersion(const std::string& str) -{ - const QStringList ver = QString::fromStdString(str).split('.'); - - int v0 = 0; - int v1 = 0; - int v2 = 0; - int v3 = 0; - - if (ver.size() >= 2 && ver.size() <= 4) - { - switch (ver.size()) - { - case 4: - v3 = ver.at(3).toInt(); - DL_FALLTHROUGH - case 3: - v2 = ver.at(2).toInt(); - DL_FALLTHROUGH - case 2: - v0 = ver.at(0).toInt(); - v1 = ver.at(1).toInt(); - break; - default: - break; - } - } - else - { - std::cerr << "DL_Dxf::getLibVersion: invalid version number: " << str << "\n"; - return 0; - } - - return (v0<<(3*8)) + (v1<<(2*8)) + (v2<<(1*8)) + (v3<<(0*8)); -} - -/** - * Converts the given string into a double or returns the given - * default valud (def) if value is NULL or empty. - */ -//double DL_Dxf::toReal(const char* value, double def) { -// if (value!=NULL && value[0] != '\0') { -// printf("toReal: not empty: %s\n", value); -// printf("toReal: val: %f\n", atof(value)); -// printf("toReal: 0: %d\n", value[0]); -// printf("toReal: 1: %d\n", value[1]); -// printf("toReal: 2: %d\n", value[2]); -// double ret; -// if (strchr(value, ',') != NULL) { -// char* tmp = new char[strlen(value)+1]; -// strlcpy(tmp, value, sizeof(tmp)); -// DL_WriterA::strReplace(tmp, ',', '.'); -// ret = atof(tmp); -// delete[] tmp; -// } -// else { -// ret = atof(value); -// } -// return ret; -// } else { -// return def; -// } -//} - - -/** - * Some test routines. - */ -void DL_Dxf::test() -{ - const size_t bufSize = 10; - - char* buf1 = new char[bufSize]; - char* buf2 = new char[bufSize]; - char* buf3 = new char[bufSize]; - char* buf4 = new char[bufSize]; - char* buf5 = new char[bufSize]; - char* buf6 = new char[bufSize]; - - strlcpy(buf1, " 10\n", bufSize); - strlcpy(buf2, "10", bufSize); - strlcpy(buf3, "10\n", bufSize); - strlcpy(buf4, " 10 \n", bufSize); - strlcpy(buf5, " 10 \r", bufSize); - strlcpy(buf6, "\t10 \n", bufSize); - - // Try to avoid deleting array from an offset - char* buf1Copy = buf1; - char* buf2Copy = buf2; - char* buf3Copy = buf3; - char* buf4Copy = buf4; - char* buf5Copy = buf5; - char* buf6Copy = buf6; - - std::cout << "1 buf1: '" << buf1 << "'\n"; - stripWhiteSpace(&buf1); - std::cout << "2 buf1: '" << buf1 << "'\n"; - //assert(!strcmp(buf1, "10")); - - std::cout << "1 buf2: '" << buf2 << "'\n"; - stripWhiteSpace(&buf2); - std::cout << "2 buf2: '" << buf2 << "'\n"; - - std::cout << "1 buf3: '" << buf3 << "'\n"; - stripWhiteSpace(&buf3); - std::cout << "2 buf3: '" << buf3 << "'\n"; - - std::cout << "1 buf4: '" << buf4 << "'\n"; - stripWhiteSpace(&buf4); - std::cout << "2 buf4: '" << buf4 << "'\n"; - - std::cout << "1 buf5: '" << buf5 << "'\n"; - stripWhiteSpace(&buf5); - std::cout << "2 buf5: '" << buf5 << "'\n"; - - std::cout << "1 buf6: '" << buf6 << "'\n"; - stripWhiteSpace(&buf6); - std::cout << "2 buf6: '" << buf6 << "'\n"; - - delete[] buf1Copy; - delete[] buf2Copy; - delete[] buf3Copy; - delete[] buf4Copy; - delete[] buf5Copy; - delete[] buf6Copy; -} - - diff --git a/src/libs/vdxf/dxflib/dl_dxf.h b/src/libs/vdxf/dxflib/dl_dxf.h deleted file mode 100644 index 4661bdc88..000000000 --- a/src/libs/vdxf/dxflib/dl_dxf.h +++ /dev/null @@ -1,525 +0,0 @@ -/**************************************************************************** -** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved. -** -** This file is part of the dxflib project. -** -** This file is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** Licensees holding valid dxflib Professional Edition licenses may use -** this file in accordance with the dxflib Commercial License -** Agreement provided with the Software. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.ribbonsoft.com for further details. -** -** Contact info@ribbonsoft.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -#ifndef DL_DXF_H -#define DL_DXF_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "dl_attributes.h" -#include "dl_codes.h" -#include "dl_entities.h" -#include "dl_global.h" -#include "dl_writer_ascii.h" - -#ifndef DL_NANDOUBLE -#define DL_NANDOUBLE std::numeric_limits::quiet_NaN() -#endif - -class DL_CreationInterface; - -#define DL_VERSION "3.12.2.0" - -#define DL_VERSION_MAJOR 3 -#define DL_VERSION_MINOR 12 -#define DL_VERSION_REV 2 -#define DL_VERSION_BUILD 0 - -#define DL_UNKNOWN 0 -#define DL_LAYER 10 -#define DL_BLOCK 11 -#define DL_ENDBLK 12 -#define DL_LINETYPE 13 -#define DL_STYLE 20 -#define DL_SETTING 50 -#define DL_ENTITY_POINT 100 -#define DL_ENTITY_LINE 101 -#define DL_ENTITY_POLYLINE 102 -#define DL_ENTITY_LWPOLYLINE 103 -#define DL_ENTITY_VERTEX 104 -#define DL_ENTITY_SPLINE 105 -#define DL_ENTITY_KNOT 106 -#define DL_ENTITY_CONTROLPOINT 107 -#define DL_ENTITY_ARC 108 -#define DL_ENTITY_CIRCLE 109 -#define DL_ENTITY_ELLIPSE 110 -#define DL_ENTITY_INSERT 111 -#define DL_ENTITY_TEXT 112 -#define DL_ENTITY_MTEXT 113 -#define DL_ENTITY_DIMENSION 114 -#define DL_ENTITY_LEADER 115 -#define DL_ENTITY_HATCH 116 -#define DL_ENTITY_ATTRIB 117 -#define DL_ENTITY_IMAGE 118 -#define DL_ENTITY_IMAGEDEF 119 -#define DL_ENTITY_TRACE 120 -#define DL_ENTITY_SOLID 121 -#define DL_ENTITY_3DFACE 122 -#define DL_ENTITY_XLINE 123 -#define DL_ENTITY_RAY 124 -#define DL_ENTITY_SEQEND 125 -#define DL_XRECORD 200 -#define DL_DICTIONARY 210 - - -/** - * Reading and writing of DXF files. - * - * This class can read in a DXF file and calls methods from the - * interface DL_EntityContainer to add the entities to the - * contianer provided by the user of the library. - * - * It can also be used to write DXF files to a certain extent. - * - * When saving entities, special values for colors and linetypes - * can be used: - * - * Special colors are 0 (=BYBLOCK) and 256 (=BYLAYER). - * Special linetypes are "BYLAYER" and "BYBLOCK". - * - * @author Andrew Mustun - */ -class DXFLIB_EXPORT DL_Dxf -{ -public: - DL_Dxf(); - ~DL_Dxf(); - - bool in(const std::string& file, DL_CreationInterface* creationInterface); - bool readDxfGroups(FILE* fp, DL_CreationInterface* creationInterface); - static bool getStrippedLine(std::string& s, quint32 size, FILE* stream, bool stripSpace = true); - - bool readDxfGroups(std::stringstream& stream, DL_CreationInterface* creationInterface); - bool in(std::stringstream &stream, DL_CreationInterface* creationInterface); - static bool getStrippedLine(std::string& s, quint32 size, std::stringstream& stream, bool stripSpace = true); - - static bool stripWhiteSpace(char** s, bool stripSpace = true); - - bool processDXFGroup(DL_CreationInterface* creationInterface, int groupCode, const std::string& groupValue); - void addSetting(DL_CreationInterface* creationInterface); - void addLayer(DL_CreationInterface* creationInterface); - void addLinetype(DL_CreationInterface *creationInterface); - void addBlock(DL_CreationInterface* creationInterface); - static void endBlock(DL_CreationInterface* creationInterface); - void addTextStyle(DL_CreationInterface* creationInterface); - - void addPoint(DL_CreationInterface* creationInterface); - void addLine(DL_CreationInterface* creationInterface); - void addXLine(DL_CreationInterface* creationInterface); - void addRay(DL_CreationInterface* creationInterface); - - void addPolyline(DL_CreationInterface* creationInterface); - void addVertex(DL_CreationInterface* creationInterface); - - void addSpline(DL_CreationInterface* creationInterface); - - void addArc(DL_CreationInterface* creationInterface); - void addCircle(DL_CreationInterface* creationInterface); - void addEllipse(DL_CreationInterface* creationInterface); - void addInsert(DL_CreationInterface* creationInterface); - - void addTrace(DL_CreationInterface* creationInterface); - void add3dFace(DL_CreationInterface* creationInterface); - void addSolid(DL_CreationInterface* creationInterface); - - void addMText(DL_CreationInterface* creationInterface); - void addText(DL_CreationInterface* creationInterface); - - void addAttribute(DL_CreationInterface* creationInterface); - - DL_DimensionData getDimData(); - void addDimLinear(DL_CreationInterface* creationInterface); - void addDimAligned(DL_CreationInterface* creationInterface); - void addDimRadial(DL_CreationInterface* creationInterface); - void addDimDiametric(DL_CreationInterface* creationInterface); - void addDimAngular(DL_CreationInterface* creationInterface); - void addDimAngular3P(DL_CreationInterface* creationInterface); - void addDimOrdinate(DL_CreationInterface* creationInterface); - - void addLeader(DL_CreationInterface* creationInterface); - - void addHatch(DL_CreationInterface* creationInterface); - void addHatchLoop(); - void addHatchEdge(); - bool handleHatchData(DL_CreationInterface* creationInterface); - - void addImage(DL_CreationInterface* creationInterface); - void addImageDef(DL_CreationInterface* creationInterface); - - static void addComment(DL_CreationInterface* creationInterface, const std::string& comment); - - void addDictionary(DL_CreationInterface* creationInterface); - void addDictionaryEntry(DL_CreationInterface* creationInterface); - - bool handleXRecordData(DL_CreationInterface* creationInterface); - bool handleDictionaryData(DL_CreationInterface* creationInterface); - - bool handleXData(DL_CreationInterface *creationInterface); - bool handleMTextData(DL_CreationInterface* creationInterface); - bool handleLWPolylineData(DL_CreationInterface* creationInterface); - bool handleSplineData(DL_CreationInterface* creationInterface); - bool handleLeaderData(DL_CreationInterface* creationInterface); - bool handleLinetypeData(DL_CreationInterface* creationInterface); - - static void endEntity(DL_CreationInterface* creationInterface); - - static void endSequence(DL_CreationInterface* creationInterface); - - //int stringToInt(const char* s, bool* ok=NULL); - - DL_WriterA* out(const char* file, DL_Codes::version version=DL_VERSION_2000); - - void writeHeader(DL_WriterA& dw) const; - - void writePoint(DL_WriterA& dw, - const DL_PointData& data, - const DL_Attributes& attrib); - void writeLine(DL_WriterA& dw, - const DL_LineData& data, - const DL_Attributes& attrib); - void writeXLine(DL_WriterA& dw, - const DL_XLineData& data, - const DL_Attributes& attrib); - void writeRay(DL_WriterA& dw, - const DL_RayData& data, - const DL_Attributes& attrib); - void writePolyline(DL_WriterA& dw, - const DL_PolylineData& data, - const DL_Attributes& attrib); - void writeVertex(DL_WriterA& dw, - const DL_VertexData& data); - void writePolylineEnd(DL_WriterA& dw) const; - void writeSpline(DL_WriterA& dw, - const DL_SplineData& data, - const DL_Attributes& attrib); - static void writeControlPoint(DL_WriterA& dw, - const DL_ControlPointData& data); - static void writeFitPoint(DL_WriterA& dw, - const DL_FitPointData& data); - static void writeKnot(DL_WriterA& dw, - const DL_KnotData& data); - void writeCircle(DL_WriterA& dw, - const DL_CircleData& data, - const DL_Attributes& attrib); - void writeArc(DL_WriterA& dw, - const DL_ArcData& data, - const DL_Attributes& attrib); - void writeEllipse(DL_WriterA& dw, - const DL_EllipseData& data, - const DL_Attributes& attrib); - void writeSolid(DL_WriterA& dw, - const DL_SolidData& data, - const DL_Attributes& attrib); - void writeTrace(DL_WriterA& dw, - const DL_TraceData& data, - const DL_Attributes& attrib); - void write3dFace(DL_WriterA& dw, - const DL_3dFaceData& data, - const DL_Attributes& attrib); - void writeInsert(DL_WriterA& dw, - const DL_InsertData& data, - const DL_Attributes& attrib); - void writeMText(DL_WriterA& dw, - const DL_MTextData& data, - const DL_Attributes& attrib); - void writeText(DL_WriterA& dw, - const DL_TextData& data, - const DL_Attributes& attrib); - void writeAttribute(DL_WriterA& dw, - const DL_AttributeData& data, - const DL_Attributes& attrib); - void writeDimStyleOverrides(DL_WriterA& dw, - const DL_DimensionData& data) const; - void writeDimAligned(DL_WriterA& dw, - const DL_DimensionData& data, - const DL_DimAlignedData& edata, - const DL_Attributes& attrib); - void writeDimLinear(DL_WriterA& dw, - const DL_DimensionData& data, - const DL_DimLinearData& edata, - const DL_Attributes& attrib); - void writeDimRadial(DL_WriterA& dw, - const DL_DimensionData& data, - const DL_DimRadialData& edata, - const DL_Attributes& attrib); - void writeDimDiametric(DL_WriterA& dw, - const DL_DimensionData& data, - const DL_DimDiametricData& edata, - const DL_Attributes& attrib); - void writeDimAngular(DL_WriterA& dw, - const DL_DimensionData& data, - const DL_DimAngularData& edata, - const DL_Attributes& attrib); - void writeDimAngular3P(DL_WriterA& dw, - const DL_DimensionData& data, - const DL_DimAngular3PData& edata, - const DL_Attributes& attrib); - void writeDimOrdinate(DL_WriterA& dw, - const DL_DimensionData& data, - const DL_DimOrdinateData& edata, - const DL_Attributes& attrib); - void writeLeader(DL_WriterA& dw, - const DL_LeaderData& data, - const DL_Attributes& attrib); - void writeLeaderVertex(DL_WriterA& dw, - const DL_LeaderVertexData& data) const; - void writeHatch1(DL_WriterA& dw, - const DL_HatchData& data, - const DL_Attributes& attrib); - void writeHatch2(DL_WriterA& dw, - const DL_HatchData& data, - const DL_Attributes& attrib) const; - static void writeHatchLoop1(DL_WriterA& dw, - const DL_HatchLoopData& data); - static void writeHatchLoop2(DL_WriterA& dw, - const DL_HatchLoopData& data); - static void writeHatchEdge(DL_WriterA& dw, - const DL_HatchEdgeData& data); - - int writeImage(DL_WriterA& dw, - const DL_ImageData& data, - const DL_Attributes& attrib); - - void writeImageDef(DL_WriterA& dw, int handle, - const DL_ImageData& data) const; - - void writeLayer(DL_WriterA& dw, - const DL_LayerData& data, - const DL_Attributes& attrib); - - void writeLinetype(DL_WriterA& dw, - const DL_LinetypeData& data) const; - - static void writeAppid(DL_WriterA& dw, const std::string& name); - - static void writeBlock(DL_WriterA& dw, - const DL_BlockData& data); - static void writeEndBlock(DL_WriterA& dw, const std::string& name); - - void writeVPort(DL_WriterA& dw) const; - void writeStyle(DL_WriterA& dw, const DL_StyleData& style); - void writeView(DL_WriterA& dw) const; - void writeUcs(DL_WriterA& dw) const; - void writeDimStyle(DL_WriterA& dw, - double dimasz, double dimexe, double dimexo, - double dimgap, double dimtxt); - void writeBlockRecord(DL_WriterA& dw) const; - void writeBlockRecord(DL_WriterA& dw, const std::string& name) const; - void writeObjects(DL_WriterA& dw, const std::string& appDictionaryName = ""); - void writeAppDictionary(DL_WriterA& dw); - static int writeDictionaryEntry(DL_WriterA& dw, const std::string& name); - void writeXRecord(DL_WriterA& dw, int handle, int value); - void writeXRecord(DL_WriterA& dw, int handle, double value); - void writeXRecord(DL_WriterA& dw, int handle, bool value); - void writeXRecord(DL_WriterA& dw, int handle, const std::string& value); - static void writeObjectsEnd(DL_WriterA& dw); - - static void writeComment(DL_WriterA& dw, const std::string& comment); - - /** - * Converts the given string into a double or returns the given - * default valud (def) if value is NULL or empty. - */ - //static double toReal(const char* value, double def=0.0); - - /** - * Converts the given string into an int or returns the given - * default valud (def) if value is NULL or empty. - */ -// static int toInt(const char* value, int def=0) { -// if (value!=NULL && value[0] != '\0') { -// return atoi(value); -// } - -// return def; -// } - - /** - * Converts the given string into a string or returns the given - * default valud (def) if value is NULL or empty. - */ -// static const char* toString(const char* value, const char* def="") { -// if (value!=NULL && value[0] != '\0') { -// return value; -// } else { -// return def; -// } -// } - - static bool checkVariable(const char* var, DL_Codes::version version); - - DL_Codes::version getVersion() const - { - return version; - } - - static int getLibVersion(const std::string &str); - - static void test(); - - bool hasValue(int code) - { - return values.count(code)==1; - } - - int getIntValue(int code, int def) - { - if (!hasValue(code)) - { - return def; - } - return toInt(values[code]); - } - - static int toInt(const std::string& str) - { - char* p; - return static_cast(strtol(str.c_str(), &p, 10)); - } - - int getInt16Value(int code, int def) - { - if (!hasValue(code)) - { - return def; - } - return toInt16(values[code]); - } - - static int toInt16(const std::string& str) - { - char* p; - return static_cast(strtol(str.c_str(), &p, 16)); - } - - static bool toBool(const std::string& str) - { - char* p; - return static_cast(strtol(str.c_str(), &p, 10)); - } - - std::string getStringValue(int code, const std::string& def) - { - if (!hasValue(code)) - { - return def; - } - return values[code]; - } - - double getRealValue(int code, double def) - { - if (!hasValue(code)) - { - return def; - } - return toReal(values[code]); - } - - static double toReal(const std::string& str) - { - double ret; - // make sure the real value uses '.' not ',': - std::string str2 = str; - std::replace(str2.begin(), str2.end(), ',', '.'); - // make sure c++ expects '.' not ',': - std::istringstream istr(str2); - istr.imbue(std::locale("C")); - istr >> ret; - return ret; - } - -private: - Q_DISABLE_COPY(DL_Dxf) - DL_Codes::version version; - - std::string polylineLayer; - double* vertices; - int maxVertices; - int vertexIndex; - - double* knots; - int maxKnots; - int knotIndex; - - double* weights; - int weightIndex; - - double* controlPoints; - int maxControlPoints; - int controlPointIndex; - - double* fitPoints; - int maxFitPoints; - int fitPointIndex; - - double* leaderVertices; - int maxLeaderVertices; - int leaderVertexIndex; - - bool firstHatchLoop; - DL_HatchEdgeData hatchEdge; - std::vector > hatchEdges; - - std::string xRecordHandle; - bool xRecordValues; - - // Only the useful part of the group code - std::string groupCodeTmp; - // ...same as integer - quint32 groupCode; - // Only the useful part of the group value - std::string groupValue; - // Current entity type - int currentObjectType; - // Value of the current setting - char settingValue[DL_DXF_MAXLINE+1]; - // Key of the current setting (e.g. "$ACADVER") - std::string settingKey; - // Stores the group codes - std::map values; - // First call of this method. We initialize all group values in - // the first call. - bool firstCall; - // Attributes of the current entity (layer, color, width, line type) - DL_Attributes attrib; - // library version. hex: 0x20003001 = 2.0.3.1 - int libVersion; - // app specific dictionary handle: - unsigned long appDictionaryHandle; - // handle of standard text style, referenced by dimstyle: - unsigned long styleHandleStd; -}; - -#endif - -// EOF diff --git a/src/libs/vdxf/dxflib/dl_entities.h b/src/libs/vdxf/dxflib/dl_entities.h deleted file mode 100644 index 7d2e65aa6..000000000 --- a/src/libs/vdxf/dxflib/dl_entities.h +++ /dev/null @@ -1,1800 +0,0 @@ -/**************************************************************************** -** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved. -** -** This file is part of the dxflib project. -** -** This file is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** Licensees holding valid dxflib Professional Edition licenses may use -** this file in accordance with the dxflib Commercial License -** Agreement provided with the Software. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.ribbonsoft.com for further details. -** -** Contact info@ribbonsoft.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -#ifndef DL_ENTITIES_H -#define DL_ENTITIES_H - -#include "dl_global.h" -#include "../dxfdef.h" -#include "../vmisc/diagnostic.h" - -#include -#include -#include - -/** - * Layer Data. - */ -struct DXFLIB_EXPORT DL_LayerData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_LayerData(const std::string& lName, int lFlags) - : name(lName), flags(lFlags) - { - } - - /** Layer name. */ - std::string name; - /** Layer flags. (1 = frozen, 2 = frozen by default, 4 = locked) */ - int flags; -}; - - - -/** - * Block Data. - */ -struct DXFLIB_EXPORT DL_BlockData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_BlockData(const std::string& bName, int bFlags, - double bbpx, double bbpy, double bbpz) - : name(bName), flags(bFlags), bpx(bbpx), bpy(bbpy), bpz(bbpz) - { - } - - /** Block name. */ - std::string name; - /** Block flags. (not used currently) */ - int flags; - /** X Coordinate of base point. */ - double bpx; - /** Y Coordinate of base point. */ - double bpy; - /** Z Coordinate of base point. */ - double bpz; -}; - - -/** - * Line Type Data. - */ -struct DXFLIB_EXPORT DL_LinetypeData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_LinetypeData( - const std::string& name, - const std::string& description, - int flags, - int numberOfDashes, - double patternLength, - double* pattern = nullptr - ) - : name(name), - description(description), - flags(flags), - numberOfDashes(numberOfDashes), - patternLength(patternLength), - pattern(pattern) - { - } - - ~DL_LinetypeData() - { - } - - /** Linetype name */ - std::string name; - /** Linetype description */ - std::string description; - /** Linetype flags */ - int flags; - /** Number of dashes */ - int numberOfDashes; - /** Pattern length */ - double patternLength; - /** Pattern */ - double* pattern; - -private: - Q_DISABLE_COPY(DL_LinetypeData) -}; - - - -/** - * Text style data. - */ -struct DXFLIB_EXPORT DL_StyleData -{ - /** - * Constructor - * Parameters: see member variables. - */ - DL_StyleData( - const std::string& name, - int flags, - double fixedTextHeight, - double widthFactor, - double obliqueAngle, - int textGenerationFlags, - double lastHeightUsed, - const std::string& primaryFontFile, - const std::string& bigFontFile - ) - : name(name), - flags(flags), - fixedTextHeight(fixedTextHeight), - widthFactor(widthFactor), - obliqueAngle(obliqueAngle), - textGenerationFlags(textGenerationFlags), - lastHeightUsed(lastHeightUsed), - primaryFontFile(primaryFontFile), - bigFontFile(bigFontFile), - bold(false), - italic(false) - { - } - - bool operator==(const DL_StyleData& other) - { - // ignore lastHeightUsed: - return (name==other.name && - flags==other.flags && - DL_FuzzyComparePossibleNulls(fixedTextHeight, other.fixedTextHeight) && - DL_FuzzyComparePossibleNulls(widthFactor, other.widthFactor) && - DL_FuzzyComparePossibleNulls(obliqueAngle, other.obliqueAngle) && - textGenerationFlags==other.textGenerationFlags && - primaryFontFile==other.primaryFontFile && - bigFontFile==other.bigFontFile); - } - - /** Style name */ - std::string name; - /** Style flags */ - int flags; - /** Fixed text height or 0 for not fixed. */ - double fixedTextHeight; - /** Width factor */ - double widthFactor; - /** Oblique angle */ - double obliqueAngle; - /** Text generation flags */ - int textGenerationFlags; - /** Last height used */ - double lastHeightUsed; - /** Primary font file name */ - std::string primaryFontFile; - /** Big font file name */ - std::string bigFontFile; - - bool bold; - bool italic; -}; - -/** - * Point Data. - */ -struct DXFLIB_EXPORT DL_PointData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - explicit DL_PointData(double px=0.0, double py=0.0, double pz=0.0) - : x(px), y(py), z(pz) - { - } - - /*! X Coordinate of the point. */ - double x; - /*! Y Coordinate of the point. */ - double y; - /*! Z Coordinate of the point. */ - double z; -}; - - - -/** - * Line Data. - */ -struct DXFLIB_EXPORT DL_LineData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_LineData(double lx1, double ly1, double lz1, - double lx2, double ly2, double lz2) - : x1(lx1), y1(ly1), z1(lz1), x2(lx2), y2(ly2), z2(lz2) - { - } - - /*! X Start coordinate of the point. */ - double x1; - /*! Y Start coordinate of the point. */ - double y1; - /*! Z Start coordinate of the point. */ - double z1; - - /*! X End coordinate of the point. */ - double x2; - /*! Y End coordinate of the point. */ - double y2; - /*! Z End coordinate of the point. */ - double z2; -}; - -/** - * XLine Data. - */ -struct DXFLIB_EXPORT DL_XLineData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_XLineData(double bx, double by, double bz, - double dx, double dy, double dz) : - bx(bx), by(by), bz(bz), - dx(dx), dy(dy), dz(dz) - { - } - - /*! X base point. */ - double bx; - /*! Y base point. */ - double by; - /*! Z base point. */ - double bz; - - /*! X direction vector. */ - double dx; - /*! Y direction vector. */ - double dy; - /*! Z direction vector. */ - double dz; -}; - -/** - * Ray Data. - */ -struct DXFLIB_EXPORT DL_RayData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_RayData(double bx, double by, double bz, - double dx, double dy, double dz) : - bx(bx), by(by), bz(bz), - dx(dx), dy(dy), dz(dz) - { - } - - /*! X base point. */ - double bx; - /*! Y base point. */ - double by; - /*! Z base point. */ - double bz; - - /*! X direction vector. */ - double dx; - /*! Y direction vector. */ - double dy; - /*! Z direction vector. */ - double dz; -}; - - - -/** - * Arc Data. - */ -struct DXFLIB_EXPORT DL_ArcData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_ArcData(double acx, double acy, double acz, - double aRadius, - double aAngle1, double aAngle2) - : cx(acx), cy(acy), cz(acz), radius(aRadius), angle1(aAngle1), angle2(aAngle2) - { - } - - /*! X Coordinate of center point. */ - double cx; - /*! Y Coordinate of center point. */ - double cy; - /*! Z Coordinate of center point. */ - double cz; - - /*! Radius of arc. */ - double radius; - /*! Startangle of arc in degrees. */ - double angle1; - /*! Endangle of arc in degrees. */ - double angle2; -}; - - - -/** - * Circle Data. - */ -struct DXFLIB_EXPORT DL_CircleData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_CircleData(double acx, double acy, double acz, - double aRadius) - : cx(acx), cy(acy), cz(acz), radius(aRadius) - { - } - - /*! X Coordinate of center point. */ - double cx; - /*! Y Coordinate of center point. */ - double cy; - /*! Z Coordinate of center point. */ - double cz; - - /*! Radius of arc. */ - double radius; -}; - - - -/** - * Polyline Data. - */ -struct DXFLIB_EXPORT DL_PolylineData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_PolylineData(int pNumber, int pMVerteces, int pNVerteces, int pFlags, double pElevation = 0.0) - : number(static_cast(pNumber)), - m(static_cast(pMVerteces)), - n(static_cast(pNVerteces)), - elevation(pElevation), - flags(pFlags) - { - } - - /*! Number of vertices in this polyline. */ - quint32 number; - - /*! Number of vertices in m direction if polyline is a polygon mesh. */ - quint32 m; - - /*! Number of vertices in n direction if polyline is a polygon mesh. */ - quint32 n; - - /*! elevation of the polyline. */ - double elevation; - - /*! Flags */ - int flags; -}; - - - -/** - * Vertex Data. - */ -struct DXFLIB_EXPORT DL_VertexData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - explicit DL_VertexData(double px=0.0, double py=0.0, double pz=0.0, double pBulge=0.0) - : x(px), y(py), z(pz), bulge(pBulge) - { - } - - /*! X Coordinate of the vertex. */ - double x; - /*! Y Coordinate of the vertex. */ - double y; - /*! Z Coordinate of the vertex. */ - double z; - /*! Bulge of vertex. - * (The tangent of 1/4 of the arc angle or 0 for lines) */ - double bulge; -}; - - -/** - * Trace Data / solid data / 3d face data. - */ -struct DXFLIB_EXPORT DL_TraceData -{ - DL_TraceData() - : thickness(0.0) - { - for (int i=0; i<4; i++) - { - x[i] = 0.0; - y[i] = 0.0; - z[i] = 0.0; - } - } - - /** - * Constructor. - * Parameters: see member variables. - */ - DL_TraceData(double sx1, double sy1, double sz1, - double sx2, double sy2, double sz2, - double sx3, double sy3, double sz3, - double sx4, double sy4, double sz4, - double sthickness=0.0) - : thickness(sthickness) - { - x[0] = sx1; - y[0] = sy1; - z[0] = sz1; - - x[1] = sx2; - y[1] = sy2; - z[1] = sz2; - - x[2] = sx3; - y[2] = sy3; - z[2] = sz3; - - x[3] = sx4; - y[3] = sy4; - z[3] = sz4; - } - - /*! Thickness */ - double thickness; - - /*! Points */ - double x[4]; - double y[4]; - double z[4]; -}; - - - - - -/** - * Solid Data. - */ -typedef DL_TraceData DL_SolidData; - - -/** - * 3dface Data. - */ -typedef DL_TraceData DL_3dFaceData; - - -/** - * Spline Data. - */ -struct DXFLIB_EXPORT DL_SplineData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_SplineData(int degree, - int nKnots, - int nControl, - int nFit, - int flags) : - degree(static_cast(degree)), - nKnots(static_cast(nKnots)), - nControl(static_cast(nControl)), - nFit(static_cast(nFit)), - flags(flags), - tangentStartX(0.0), - tangentStartY(0.0), - tangentStartZ(0.0), - tangentEndX(0.0), - tangentEndY(0.0), - tangentEndZ(0.0) - { - } - - /*! Degree of the spline curve. */ - quint32 degree; - - /*! Number of knots. */ - quint32 nKnots; - - /*! Number of control points. */ - quint32 nControl; - - /*! Number of fit points. */ - quint32 nFit; - - /*! Flags */ - int flags; - - double tangentStartX; - double tangentStartY; - double tangentStartZ; - double tangentEndX; - double tangentEndY; - double tangentEndZ; -}; - - - -/** - * Spline knot data. - */ -struct DXFLIB_EXPORT DL_KnotData -{ - DL_KnotData() : k(0.0) {} - /** - * Constructor. - * Parameters: see member variables. - */ - explicit DL_KnotData(double pk) - : k(pk) - { - } - - /*! Knot value. */ - double k; -}; - - - -/** - * Spline control point data. - */ -struct DXFLIB_EXPORT DL_ControlPointData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_ControlPointData(double px, double py, double pz, double weight) - : x(px), y(py), z(pz), w(weight) - { - } - - /*! X coordinate of the control point. */ - double x; - /*! Y coordinate of the control point. */ - double y; - /*! Z coordinate of the control point. */ - double z; - /*! Weight of control point. */ - double w; -}; - - - -/** - * Spline fit point data. - */ -struct DXFLIB_EXPORT DL_FitPointData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_FitPointData(double x, double y, double z) : x(x), y(y), z(z) {} - - /*! X coordinate of the fit point. */ - double x; - /*! Y coordinate of the fit point. */ - double y; - /*! Z coordinate of the fit point. */ - double z; -}; - - - -/** - * Ellipse Data. - */ -struct DXFLIB_EXPORT DL_EllipseData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_EllipseData(double cx, double cy, double cz, - double mx, double my, double mz, - double ratio, - double angle1, double angle2) - : cx(cx), - cy(cy), - cz(cz), - mx(mx), - my(my), - mz(mz), - ratio(ratio), - angle1(angle1), - angle2(angle2) - { - } - - /*! X Coordinate of center point. */ - double cx; - /*! Y Coordinate of center point. */ - double cy; - /*! Z Coordinate of center point. */ - double cz; - - /*! X coordinate of the endpoint of the major axis. */ - double mx; - /*! Y coordinate of the endpoint of the major axis. */ - double my; - /*! Z coordinate of the endpoint of the major axis. */ - double mz; - - /*! Ratio of minor axis to major axis.. */ - double ratio; - /*! Startangle of ellipse in rad. */ - double angle1; - /*! Endangle of ellipse in rad. */ - double angle2; -}; - - - -/** - * Insert Data. - */ -struct DXFLIB_EXPORT DL_InsertData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_InsertData(const std::string& name, - double ipx, double ipy, double ipz, - double sx, double sy, double sz, - double angle, - int cols, int rows, - double colSp, double rowSp) : - name(name), - ipx(ipx), ipy(ipy), ipz(ipz), - sx(sx), sy(sy), sz(sz), - angle(angle), - cols(cols), rows(rows), - colSp(colSp), rowSp(rowSp) - { - } - - /*! Name of the referred block. */ - std::string name; - /*! X Coordinate of insertion point. */ - double ipx; - /*! Y Coordinate of insertion point. */ - double ipy; - /*! Z Coordinate of insertion point. */ - double ipz; - /*! X Scale factor. */ - double sx; - /*! Y Scale factor. */ - double sy; - /*! Z Scale factor. */ - double sz; - /*! Rotation angle in degrees. */ - double angle; - /*! Number of colums if we insert an array of the block or 1. */ - int cols; - /*! Number of rows if we insert an array of the block or 1. */ - int rows; - /*! Values for the spacing between cols. */ - double colSp; - /*! Values for the spacing between rows. */ - double rowSp; -}; - - - -/** - * MText Data. - */ -struct DXFLIB_EXPORT DL_MTextData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_MTextData(double ipx, double ipy, double ipz, - double dirx, double diry, double dirz, - double height, double width, - int attachmentPoint, - int drawingDirection, - int lineSpacingStyle, - double lineSpacingFactor, - const std::string& text, - const std::string& style, - double angle) : - ipx(ipx), ipy(ipy), ipz(ipz), - dirx(dirx), diry(diry), dirz(dirz), - height(height), width(width), - attachmentPoint(attachmentPoint), - drawingDirection(drawingDirection), - lineSpacingStyle(lineSpacingStyle), - lineSpacingFactor(lineSpacingFactor), - text(text), - style(style), - angle(angle) - { - - } - - /*! X Coordinate of insertion point. */ - double ipx; - /*! Y Coordinate of insertion point. */ - double ipy; - /*! Z Coordinate of insertion point. */ - double ipz; - /*! X Coordinate of X direction vector. */ - double dirx; - /*! Y Coordinate of X direction vector. */ - double diry; - /*! Z Coordinate of X direction vector. */ - double dirz; - /*! Text height */ - double height; - /*! Width of the text box. */ - double width; - /** - * Attachment point. - * - * 1 = Top left, 2 = Top center, 3 = Top right, - * 4 = Middle left, 5 = Middle center, 6 = Middle right, - * 7 = Bottom left, 8 = Bottom center, 9 = Bottom right - */ - int attachmentPoint; - /** - * Drawing direction. - * - * 1 = left to right, 3 = top to bottom, 5 = by style - */ - int drawingDirection; - /** - * Line spacing style. - * - * 1 = at least, 2 = exact - */ - int lineSpacingStyle; - /** - * Line spacing factor. 0.25 .. 4.0 - */ - double lineSpacingFactor; - /*! Text string. */ - std::string text; - /*! Style string. */ - std::string style; - /*! Rotation angle. */ - double angle; -}; - -QT_WARNING_PUSH -QT_WARNING_DISABLE_CLANG("-Wweak-vtables") - -/** - * Text Data. - */ -struct DXFLIB_EXPORT DL_TextData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_TextData(double ipx, double ipy, double ipz, - double apx, double apy, double apz, - double height, double xScaleFactor, - int textGenerationFlags, - int hJustification, - int vJustification, - const std::string& text, - const std::string& style, - double angle) - : ipx(ipx), ipy(ipy), ipz(ipz), - apx(apx), apy(apy), apz(apz), - height(height), xScaleFactor(xScaleFactor), - textGenerationFlags(textGenerationFlags), - hJustification(hJustification), - vJustification(vJustification), - text(text), - style(style), - angle(angle) - {} - - DL_TextData(const DL_TextData &d) - : ipx(d.ipx), ipy(d.ipy), ipz(d.ipz), - apx(d.apx), apy(d.apy), apz(d.apz), - height(d.height), xScaleFactor(d.xScaleFactor), - textGenerationFlags(d.textGenerationFlags), - hJustification(d.hJustification), - vJustification(d.vJustification), - text(d.text), - style(d.style), - angle(d.angle) - { - } - - DL_TextData &operator=(const DL_TextData &d) - { - if ( &d == this ) - { - return *this; - } - ipx = d.ipx; - ipy = d.ipy; - ipz = d.ipz; - apx = d.apx; - apy = d.apy; - apz = d.apz; - height = d.height; - xScaleFactor = d.xScaleFactor; - textGenerationFlags = d.textGenerationFlags; - hJustification = d.hJustification; - vJustification = d.vJustification; - text = d.text; - style = d.style; - angle = d.angle; - return *this; - } - - virtual ~DL_TextData() - {} - - /*! X Coordinate of insertion point. */ - double ipx; - /*! Y Coordinate of insertion point. */ - double ipy; - /*! Z Coordinate of insertion point. */ - double ipz; - - /*! X Coordinate of alignment point. */ - double apx; - /*! Y Coordinate of alignment point. */ - double apy; - /*! Z Coordinate of alignment point. */ - double apz; - - /*! Text height */ - double height; - /*! Relative X scale factor. */ - double xScaleFactor; - /*! 0 = default, 2 = Backwards, 4 = Upside down */ - int textGenerationFlags; - /** - * Horizontal justification. - * - * 0 = Left (default), 1 = Center, 2 = Right, - * 3 = Aligned, 4 = Middle, 5 = Fit - * For 3, 4, 5 the vertical alignment has to be 0. - */ - int hJustification; - /** - * Vertical justification. - * - * 0 = Baseline (default), 1 = Bottom, 2 = Middle, 3= Top - */ - int vJustification; - /*! Text string. */ - std::string text; - /*! Style (font). */ - std::string style; - /*! Rotation angle of dimension text away from default orientation. */ - double angle; -}; - - -/** - * Block attribute data. - */ -struct DXFLIB_EXPORT DL_AttributeData : public DL_TextData -{ - DL_AttributeData(const DL_TextData& tData, const std::string& tag) - : DL_TextData(tData), tag(tag) - {} - - /** - * Constructor. - * Parameters: see member variables. - */ - DL_AttributeData(double ipx, double ipy, double ipz, - double apx, double apy, double apz, - double height, double xScaleFactor, - int textGenerationFlags, - int hJustification, - int vJustification, - const std::string& tag, - const std::string& text, - const std::string& style, - double angle) - : DL_TextData(ipx, ipy, ipz, - apx, apy, apz, - height, xScaleFactor, - textGenerationFlags, - hJustification, - vJustification, - text, - style, - angle), - tag(tag) - {} - - virtual ~DL_AttributeData() - {} - - /*! Tag. */ - std::string tag; -}; - -QT_WARNING_POP - -/** - * Generic Dimension Data. - */ -struct DXFLIB_EXPORT DL_DimensionData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_DimensionData(double dpx, double dpy, double dpz, - double mpx, double mpy, double mpz, - int type, - int attachmentPoint, - int lineSpacingStyle, - double lineSpacingFactor, - const std::string& text, - const std::string& style, - double angle, - double linearFactor = 1.0, - double dimScale = 1.0) : - dpx(dpx), dpy(dpy), dpz(dpz), - mpx(mpx), mpy(mpy), mpz(mpz), - type(type), - attachmentPoint(attachmentPoint), - lineSpacingStyle(lineSpacingStyle), - lineSpacingFactor(lineSpacingFactor), - text(text), - style(style), - angle(angle), - linearFactor(linearFactor), - dimScale(dimScale) - { - - } - - /*! X Coordinate of definition point. */ - double dpx; - /*! Y Coordinate of definition point. */ - double dpy; - /*! Z Coordinate of definition point. */ - double dpz; - /*! X Coordinate of middle point of the text. */ - double mpx; - /*! Y Coordinate of middle point of the text. */ - double mpy; - /*! Z Coordinate of middle point of the text. */ - double mpz; - /** - * Dimension type. - * - * 0 Rotated, horizontal, or vertical - * 1 Aligned - * 2 Angular - * 3 Diametric - * 4 Radius - * 5 Angular 3-point - * 6 Ordinate - * 64 Ordinate type. This is a bit value (bit 7) - * used only with integer value 6. If set, - * ordinate is X-type; if not set, ordinate is - * Y-type - * 128 This is a bit value (bit 8) added to the - * other group 70 values if the dimension text - * has been positioned at a user-defined - * location rather than at the default location - */ - int type; - /** - * Attachment point. - * - * 1 = Top left, 2 = Top center, 3 = Top right, - * 4 = Middle left, 5 = Middle center, 6 = Middle right, - * 7 = Bottom left, 8 = Bottom center, 9 = Bottom right, - */ - int attachmentPoint; - /** - * Line spacing style. - * - * 1 = at least, 2 = exact - */ - int lineSpacingStyle; - /** - * Line spacing factor. 0.25 .. 4.0 - */ - double lineSpacingFactor; - /** - * Text string. - * - * Text string entered explicitly by user or null - * or "<>" for the actual measurement or " " (one blank space). - * for supressing the text. - */ - std::string text; - /*! Dimension style (font name). */ - std::string style; - /** - * Rotation angle of dimension text away from - * default orientation. - */ - double angle; - /** - * Linear factor style override. - */ - double linearFactor; - /** - * Dimension scale (dimscale) style override. - */ - double dimScale; -}; - - - -/** - * Aligned Dimension Data. - */ -struct DXFLIB_EXPORT DL_DimAlignedData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_DimAlignedData(double depx1, double depy1, double depz1, - double depx2, double depy2, double depz2) - : epx1(depx1), epy1(depy1), epz1(depz1), - epx2(depx2), epy2(depy2), epz2(depz2) - { - } - - /*! X Coordinate of Extension point 1. */ - double epx1; - /*! Y Coordinate of Extension point 1. */ - double epy1; - /*! Z Coordinate of Extension point 1. */ - double epz1; - - /*! X Coordinate of Extension point 2. */ - double epx2; - /*! Y Coordinate of Extension point 2. */ - double epy2; - /*! Z Coordinate of Extension point 2. */ - double epz2; -}; - - - -/** - * Linear (rotated) Dimension Data. - */ -struct DXFLIB_EXPORT DL_DimLinearData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_DimLinearData(double ddpx1, double ddpy1, double ddpz1, - double ddpx2, double ddpy2, double ddpz2, - double dAngle, double dOblique) - : dpx1(ddpx1), dpy1(ddpy1), dpz1(ddpz1), - dpx2(ddpx2), dpy2(ddpy2), dpz2(ddpz2), - angle(dAngle), oblique(dOblique) - { - } - - /*! X Coordinate of Extension point 1. */ - double dpx1; - /*! Y Coordinate of Extension point 1. */ - double dpy1; - /*! Z Coordinate of Extension point 1. */ - double dpz1; - - /*! X Coordinate of Extension point 2. */ - double dpx2; - /*! Y Coordinate of Extension point 2. */ - double dpy2; - /*! Z Coordinate of Extension point 2. */ - double dpz2; - - /*! Rotation angle (angle of dimension line) in degrees. */ - double angle; - /*! Oblique angle in degrees. */ - double oblique; -}; - - - -/** - * Radial Dimension Data. - */ -struct DXFLIB_EXPORT DL_DimRadialData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_DimRadialData(double ddpx, double ddpy, double ddpz, double dleader) - : dpx(ddpx), dpy(ddpy), dpz(ddpz), leader(dleader) - { - } - - /*! X Coordinate of definition point. */ - double dpx; - /*! Y Coordinate of definition point. */ - double dpy; - /*! Z Coordinate of definition point. */ - double dpz; - - /*! Leader length */ - double leader; -}; - - - -/** - * Diametric Dimension Data. - */ -struct DXFLIB_EXPORT DL_DimDiametricData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_DimDiametricData(double ddpx, double ddpy, double ddpz, double dleader) - : dpx(ddpx), dpy(ddpy), dpz(ddpz), leader(dleader) - { - } - - /*! X Coordinate of definition point (DXF 15). */ - double dpx; - /*! Y Coordinate of definition point (DXF 25). */ - double dpy; - /*! Z Coordinate of definition point (DXF 35). */ - double dpz; - - /*! Leader length */ - double leader; -}; - - - -/** - * Angular Dimension Data. - */ -struct DXFLIB_EXPORT DL_DimAngularData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_DimAngularData(double ddpx1, double ddpy1, double ddpz1, - double ddpx2, double ddpy2, double ddpz2, - double ddpx3, double ddpy3, double ddpz3, - double ddpx4, double ddpy4, double ddpz4) - : dpx1(ddpx1), dpy1(ddpy1), dpz1(ddpz1), - dpx2(ddpx2), dpy2(ddpy2), dpz2(ddpz2), - dpx3(ddpx3), dpy3(ddpy3), dpz3(ddpz3), - dpx4(ddpx4), dpy4(ddpy4), dpz4(ddpz4) - { - } - - /*! X Coordinate of definition point 1. */ - double dpx1; - /*! Y Coordinate of definition point 1. */ - double dpy1; - /*! Z Coordinate of definition point 1. */ - double dpz1; - - /*! X Coordinate of definition point 2. */ - double dpx2; - /*! Y Coordinate of definition point 2. */ - double dpy2; - /*! Z Coordinate of definition point 2. */ - double dpz2; - - /*! X Coordinate of definition point 3. */ - double dpx3; - /*! Y Coordinate of definition point 3. */ - double dpy3; - /*! Z Coordinate of definition point 3. */ - double dpz3; - - /*! X Coordinate of definition point 4. */ - double dpx4; - /*! Y Coordinate of definition point 4. */ - double dpy4; - /*! Z Coordinate of definition point 4. */ - double dpz4; -}; - - -/** - * Angular Dimension Data (3 points version). - */ -struct DXFLIB_EXPORT DL_DimAngular3PData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_DimAngular3PData(double ddpx1, double ddpy1, double ddpz1, - double ddpx2, double ddpy2, double ddpz2, - double ddpx3, double ddpy3, double ddpz3) - : dpx1(ddpx1), dpy1(ddpy1), dpz1(ddpz1), - dpx2(ddpx2), dpy2(ddpy2), dpz2(ddpz2), - dpx3(ddpx3), dpy3(ddpy3), dpz3(ddpz3) - { - } - - /*! X Coordinate of definition point 1. */ - double dpx1; - /*! Y Coordinate of definition point 1. */ - double dpy1; - /*! Z Coordinate of definition point 1. */ - double dpz1; - - /*! X Coordinate of definition point 2. */ - double dpx2; - /*! Y Coordinate of definition point 2. */ - double dpy2; - /*! Z Coordinate of definition point 2. */ - double dpz2; - - /*! X Coordinate of definition point 3. */ - double dpx3; - /*! Y Coordinate of definition point 3. */ - double dpy3; - /*! Z Coordinate of definition point 3. */ - double dpz3; -}; - - - -/** - * Ordinate Dimension Data. - */ -struct DXFLIB_EXPORT DL_DimOrdinateData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_DimOrdinateData(double ddpx1, double ddpy1, double ddpz1, - double ddpx2, double ddpy2, double ddpz2, - bool dxtype) - : dpx1(ddpx1), dpy1(ddpy1), dpz1(ddpz1), - dpx2(ddpx2), dpy2(ddpy2), dpz2(ddpz2), - xtype(dxtype) - { - } - - /*! X Coordinate of definition point 1. */ - double dpx1; - /*! Y Coordinate of definition point 1. */ - double dpy1; - /*! Z Coordinate of definition point 1. */ - double dpz1; - - /*! X Coordinate of definition point 2. */ - double dpx2; - /*! Y Coordinate of definition point 2. */ - double dpy2; - /*! Z Coordinate of definition point 2. */ - double dpz2; - - /*! True if the dimension indicates the X-value, false for Y-value */ - bool xtype; -}; - - - -/** - * Leader (arrow). - */ -struct DXFLIB_EXPORT DL_LeaderData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_LeaderData(int lArrowHeadFlag, - int lLeaderPathType, - int lLeaderCreationFlag, - int lHooklineDirectionFlag, - int lHooklineFlag, - double lTextAnnotationHeight, - double lTextAnnotationWidth, - int lNumber) - : arrowHeadFlag(lArrowHeadFlag), - leaderPathType(lLeaderPathType), - leaderCreationFlag(lLeaderCreationFlag), - hooklineDirectionFlag(lHooklineDirectionFlag), - hooklineFlag(lHooklineFlag), - textAnnotationHeight(lTextAnnotationHeight), - textAnnotationWidth(lTextAnnotationWidth), - number(lNumber) - { - } - - /*! Arrow head flag (71). */ - int arrowHeadFlag; - /*! Leader path type (72). */ - int leaderPathType; - /*! Leader creation flag (73). */ - int leaderCreationFlag; - /*! Hookline direction flag (74). */ - int hooklineDirectionFlag; - /*! Hookline flag (75) */ - int hooklineFlag; - /*! Text annotation height (40). */ - double textAnnotationHeight; - /*! Text annotation width (41) */ - double textAnnotationWidth; - /*! Number of vertices in leader (76). */ - int number; -}; - - - -/** - * Leader Vertex Data. - */ -struct DXFLIB_EXPORT DL_LeaderVertexData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - explicit DL_LeaderVertexData(double px=0.0, double py=0.0, double pz=0.0) - : x(px), y(py), z(pz) - { - } - - /*! X Coordinate of the vertex. */ - double x; - /*! Y Coordinate of the vertex. */ - double y; - /*! Z Coordinate of the vertex. */ - double z; -}; - - - -/** - * Hatch data. - */ -struct DXFLIB_EXPORT DL_HatchData -{ - /** - * Default constructor. - */ - DL_HatchData() : numLoops(0), solid(), scale(0.0), angle(0.0), pattern(), originX(0.0), originY(0.0) - {} - - /** - * Constructor. - * Parameters: see member variables. - */ - DL_HatchData(int numLoops, - bool solid, - double scale, - double angle, - const std::string& pattern, - double originX = 0.0, - double originY = 0.0) : - numLoops(numLoops), - solid(solid), - scale(scale), - angle(angle), - pattern(pattern), - originX(originX), - originY(originY) - { - } - - /*! Number of boundary paths (loops). */ - int numLoops; - /*! Solid fill flag (true=solid, false=pattern). */ - bool solid; - /*! Pattern scale or spacing */ - double scale; - /*! Pattern angle in degrees */ - double angle; - /*! Pattern name. */ - std::string pattern; - /*! Pattern origin */ - double originX; - double originY; -}; - - - -/** - * Hatch boundary path (loop) data. - */ -struct DXFLIB_EXPORT DL_HatchLoopData -{ - /** - * Default constructor. - */ - DL_HatchLoopData() : numEdges(0) - {} - /** - * Constructor. - * Parameters: see member variables. - */ - explicit DL_HatchLoopData(int hNumEdges) - : numEdges(hNumEdges) - { - } - - /*! Number of edges in this loop. */ - int numEdges; -}; - - - -/** - * Hatch edge data. - */ -struct DXFLIB_EXPORT DL_HatchEdgeData -{ - /** - * Default constructor. - */ - DL_HatchEdgeData() : defined(false), x1(0.0), y1(0.0), x2(0.0), y2(0.0), - type(0), cx(0.0), cy(0.0), radius(0.0), angle1(0.0), angle2(0.0), ccw(), - mx(0.0), my(0.0), ratio(0.0), degree(0), rational(), periodic(), - nKnots(0), nControl(0), nFit(0), controlPoints(), knots(), - weights(), fitPoints(), startTangentX(0.0), startTangentY(0.0), - endTangentX(0.0), endTangentY(0.0), vertices() - { - } - - /** - * Constructor for a line edge. - * Parameters: see member variables. - */ - DL_HatchEdgeData(double x1, double y1, - double x2, double y2) : - defined(true), - x1(x1), - y1(y1), - x2(x2), - y2(y2), - type(1), - cx(0.0), cy(0.0), radius(0.0), angle1(0.0), angle2(0.0), ccw(), - mx(0.0), my(0.0), ratio(0.0), degree(0), rational(), periodic(), - nKnots(0), nControl(0), nFit(0), controlPoints(), knots(), - weights(), fitPoints(), startTangentX(0.0), startTangentY(0.0), - endTangentX(0.0), endTangentY(0.0), vertices() - { - } - - /** - * Constructor for an arc edge. - * Parameters: see member variables. - */ - DL_HatchEdgeData(double cx, double cy, - double radius, - double angle1, double angle2, - bool ccw) : - defined(true), - x1(), y1(), x2(), y2(), - type(2), - cx(cx), - cy(cy), - radius(radius), - angle1(angle1), - angle2(angle2), - ccw(ccw), - mx(0.0), my(0.0), ratio(0.0), degree(0), rational(), periodic(), - nKnots(0), nControl(0), nFit(0), controlPoints(), knots(), - weights(), fitPoints(), startTangentX(0.0), startTangentY(0.0), - endTangentX(0.0), endTangentY(0.0), vertices() - { - } - - /** - * Constructor for an ellipse arc edge. - * Parameters: see member variables. - */ - DL_HatchEdgeData(double cx, double cy, - double mx, double my, - double ratio, - double angle1, double angle2, - bool ccw) : - defined(true), - x1(), y1(), x2(), y2(), - type(3), - cx(cx), - cy(cy), - radius(), - angle1(angle1), - angle2(angle2), - ccw(ccw), - mx(mx), - my(my), - ratio(ratio), - degree(0), rational(), periodic(), - nKnots(0), nControl(0), nFit(0), controlPoints(), knots(), - weights(), fitPoints(), startTangentX(0.0), startTangentY(0.0), - endTangentX(0.0), endTangentY(0.0), vertices() - { - } - - /** - * Constructor for a spline edge. - * Parameters: see member variables. - */ - DL_HatchEdgeData(quint32 degree, - bool rational, - bool periodic, - quint32 nKnots, - quint32 nControl, - quint32 nFit, - const std::vector& knots, - const std::vector >& controlPoints, - const std::vector >& fitPoints, - const std::vector& weights, - double startTangentX, - double startTangentY, - double endTangentX, - double endTangentY) : - defined(true), - x1(), y1(), x2(), y2(), - type(4), cx(), cy(), radius(), - angle1(), angle2(), ccw(), - mx(), my(), ratio(), degree(degree), - rational(rational), - periodic(periodic), - nKnots(nKnots), - nControl(nControl), - nFit(nFit), - controlPoints(controlPoints), - knots(knots), - weights(weights), - fitPoints(fitPoints), - startTangentX(startTangentX), - startTangentY(startTangentY), - endTangentX(endTangentX), - endTangentY(endTangentY), - vertices() - { - } - - /** - * Set to true if this edge is fully defined. - */ - bool defined; - - // line edges: - - /*! Start point (X). */ - double x1; - /*! Start point (Y). */ - double y1; - /*! End point (X). */ - double x2; - /*! End point (Y). */ - double y2; - - /** - * Edge type. 1=line, 2=arc, 3=elliptic arc, 4=spline. - */ - int type; - - /*! Center point of arc or ellipse arc (X). */ - double cx; - /*! Center point of arc or ellipse arc (Y). */ - double cy; - /*! Arc radius. */ - double radius; - /*! Start angle of arc or ellipse arc. */ - double angle1; - /*! End angle of arc or ellipse arc. */ - double angle2; - /*! Counterclockwise flag for arc or ellipse arc. */ - bool ccw; - - /*! Major axis end point (X). */ - double mx; - /*! Major axis end point (Y). */ - double my; - /*! Axis ratio */ - double ratio; - - - /*! Spline degree */ - quint32 degree; - bool rational; - bool periodic; - /*! Number of knots. */ - quint32 nKnots; - /*! Number of control points. */ - quint32 nControl; - /*! Number of fit points. */ - quint32 nFit; - - std::vector > controlPoints; - std::vector knots; - std::vector weights; - std::vector > fitPoints; - - double startTangentX; - double startTangentY; - - double endTangentX; - double endTangentY; - - /** Polyline boundary vertices (x y [bulge])*/ - std::vector > vertices; - //bool closed; -}; - - - -/** - * Image Data. - */ -struct DXFLIB_EXPORT DL_ImageData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_ImageData(const std::string& iref, - double iipx, double iipy, double iipz, - double iux, double iuy, double iuz, - double ivx, double ivy, double ivz, - int iwidth, int iheight, - int ibrightness, int icontrast, int ifade) - : ref(iref), - ipx(iipx), ipy(iipy), ipz(iipz), - ux(iux), uy(iuy), uz(iuz), - vx(ivx), vy(ivy), vz(ivz), - width(iwidth), height(iheight), - brightness(ibrightness), contrast(icontrast), fade(ifade) - { - } - - /*! Reference to the image file - (unique, used to refer to the image def object). */ - std::string ref; - /*! X Coordinate of insertion point. */ - double ipx; - /*! Y Coordinate of insertion point. */ - double ipy; - /*! Z Coordinate of insertion point. */ - double ipz; - /*! X Coordinate of u vector along bottom of image. */ - double ux; - /*! Y Coordinate of u vector along bottom of image. */ - double uy; - /*! Z Coordinate of u vector along bottom of image. */ - double uz; - /*! X Coordinate of v vector along left side of image. */ - double vx; - /*! Y Coordinate of v vector along left side of image. */ - double vy; - /*! Z Coordinate of v vector along left side of image. */ - double vz; - /*! Width of image in pixel. */ - int width; - /*! Height of image in pixel. */ - int height; - /*! Brightness (0..100, default = 50). */ - int brightness; - /*! Contrast (0..100, default = 50). */ - int contrast; - /*! Fade (0..100, default = 0). */ - int fade; -}; - - - -/** - * Image Definition Data. - */ -struct DXFLIB_EXPORT DL_ImageDefData -{ - /** - * Constructor. - * Parameters: see member variables. - */ - DL_ImageDefData(const std::string& iref, - const std::string& ifile) - : ref(iref), file(ifile) - { - } - - /*! Reference to the image file - (unique, used to refer to the image def object). */ - std::string ref; - - /*! Image file */ - std::string file; -}; - - - -/** - * Dictionary data. - */ -struct DXFLIB_EXPORT DL_DictionaryData -{ - explicit DL_DictionaryData(const std::string& handle) : handle(handle) {} - std::string handle; -}; - - - -/** - * Dictionary entry data. - */ -struct DXFLIB_EXPORT DL_DictionaryEntryData -{ - DL_DictionaryEntryData(const std::string& name, const std::string& handle) : - name(name), handle(handle) {} - - std::string name; - std::string handle; -}; - -#endif - -// EOF diff --git a/src/libs/vdxf/dxflib/dl_extrusion.h b/src/libs/vdxf/dxflib/dl_extrusion.h deleted file mode 100644 index dcde7bcdd..000000000 --- a/src/libs/vdxf/dxflib/dl_extrusion.h +++ /dev/null @@ -1,164 +0,0 @@ -/**************************************************************************** -** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved. -** -** This file is part of the dxflib project. -** -** This file is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** Licensees holding valid dxflib Professional Edition licenses may use -** this file in accordance with the dxflib Commercial License -** Agreement provided with the Software. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.ribbonsoft.com for further details. -** -** Contact info@ribbonsoft.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -#ifndef DL_EXTRUSION_H -#define DL_EXTRUSION_H - -#include "dl_global.h" - -#include "../vmisc/vmath.h" - -/** - * Storing and passing around attributes. Attributes - * are the layer name, color, width and line type. - * - * @author Andrew Mustun - */ -class DXFLIB_EXPORT DL_Extrusion -{ - -public: - - /** - * Default constructor. - */ - DL_Extrusion() : direction(new double[3]), elevation(0.0) - { - setDirection(0.0, 0.0, 1.0); - } - - - /** - * Destructor. - */ - ~DL_Extrusion() - { - delete[] direction ; - } - - DL_Extrusion(const DL_Extrusion &L) - : direction(new double[3]), elevation(L.elevation) - { - setDirection(L.direction[0], L.direction[1], L.direction[0]); - } - - /** - * Constructor for DXF extrusion. - * - * @param elevation Distance of the entities XY plane from the origin of the - * world coordinate system - */ - DL_Extrusion(double dx, double dy, double dz, double elevation) - : direction(new double[3]), elevation(elevation) - { - setDirection(dx, dy, dz); - } - - - - /** - * Sets the direction vector. - */ - void setDirection(double dx, double dy, double dz) - { - direction[0]=dx; - direction[1]=dy; - direction[2]=dz; - } - - - - /** - * @return direction vector. - */ - double* getDirection() const - { - return direction; - } - - - - /** - * @param dir vector. - */ - void getDirection(double dir[]) const - { - dir[0]=direction[0]; - dir[1]=direction[1]; - dir[2]=direction[2]; - } - - - - /** - * Sets the elevation. - */ - void setElevation(double elevation) - { - this->elevation = elevation; - } - - - - /** - * @return Elevation. - */ - double getElevation() const - { - return elevation; - } - - - - /** - * Copies extrusion (deep copies) from another extrusion object. - */ - DL_Extrusion & operator = (const DL_Extrusion& extru) - { - if ( &extru == this ) - { - return *this; - } - setDirection(extru.direction[0], extru.direction[1], extru.direction[2]); - setElevation(extru.elevation); - - return *this; - } - - - -private: - /** - * @brief direction Vector of axis along which the entity shall be extruded this is also the Z axis of the Entity - * coordinate system - */ - double *direction; - /** - * @brief elevation Distance of the entities XY plane from the origin of the world coordinate system - */ - double elevation; -}; - -#endif - diff --git a/src/libs/vdxf/dxflib/dl_global.h b/src/libs/vdxf/dxflib/dl_global.h deleted file mode 100644 index 0d52bea7e..000000000 --- a/src/libs/vdxf/dxflib/dl_global.h +++ /dev/null @@ -1,13 +0,0 @@ -#if defined(DXFLIB_DLL) -# ifdef _WIN32 -# if defined(DXFLIB_LIBRARY) -# define DXFLIB_EXPORT __declspec(dllexport) -# else -# define DXFLIB_EXPORT __declspec(dllimport) -# endif -# else -# define DXFLIB_EXPORT -# endif -#else -# define DXFLIB_EXPORT -#endif diff --git a/src/libs/vdxf/dxflib/dl_writer.cpp b/src/libs/vdxf/dxflib/dl_writer.cpp deleted file mode 100644 index b1cb6aa7b..000000000 --- a/src/libs/vdxf/dxflib/dl_writer.cpp +++ /dev/null @@ -1,644 +0,0 @@ -/**************************************************************************** - ** Copyright (C) 2015 Roman Telezhynskyi - ** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved. - ** Copyright (C) 2001 Robert J. Campbell Jr. - ** - ** This file is part of the dxflib project. - ** - ** This file is free software; you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation; either version 2 of the License, or - ** (at your option) any later version. - ** - ** Licensees holding valid dxflib Professional Edition licenses may use - ** this file in accordance with the dxflib Commercial License - ** Agreement provided with the Software. - ** - ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE - ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** -**********************************************************************/ - -#include "dl_writer.h" - -#include -#include - -#include "dl_attributes.h" -#include "dl_codes.h" - -/** - * @param version DXF version. Defaults to DL_VERSION_2002. - */ -DL_Writer::DL_Writer(DL_Codes::version version) - : m_handle(0x30), modelSpaceHandle(0), paperSpaceHandle(0), paperSpace0Handle(0), version(version) -{} - -DL_Writer::~DL_Writer() -{} - -/** Generic section for section 'name'. - * - *
- *   0
- *  SECTION
- *   2
- *  name
- * 
- */ -void DL_Writer::section(const char *name) const -{ - dxfString(0, "SECTION"); - dxfString(2, name); -} - -/** - * Section HEADER - * - *
- *   0
- *  SECTION
- *   2
- *  HEADER
- * 
- */ -void DL_Writer::sectionHeader() const -{ - section("HEADER"); -} - -/** - * Section TABLES - * - *
- *   0
- *  SECTION
- *   2
- *  TABLES
- * 
- */ -void DL_Writer::sectionTables() const -{ - section("TABLES"); -} - -/** - * Section BLOCKS - * - *
- *   0
- *  SECTION
- *   2
- *  BLOCKS
- * 
- */ -void DL_Writer::sectionBlocks() const -{ - section("BLOCKS"); -} - -/** - * Section ENTITIES - * - *
- *   0
- *  SECTION
- *   2
- *  ENTITIES
- * 
- */ -void DL_Writer::sectionEntities() const -{ - section("ENTITIES"); -} - -/** - * Section CLASSES - * - *
- *   0
- *  SECTION
- *   2
- *  CLASSES
- * 
- */ -void DL_Writer::sectionClasses() const -{ - section("CLASSES"); -} - -/** - * Section OBJECTS - * - *
- *   0
- *  SECTION
- *   2
- *  OBJECTS
- * 
- */ -void DL_Writer::sectionObjects() const -{ - section("OBJECTS"); -} - -/** - * End of a section. - * - *
- *   0
- *  ENDSEC
- * 
- */ -void DL_Writer::sectionEnd() const -{ - dxfString(0, "ENDSEC"); -} - -/** - * Generic table for table 'name' with 'num' entries: - * - *
- *   0
- *  TABLE
- *   2
- *  name
- *  70
- *   num
- * 
- */ -void DL_Writer::table(const char *name, int num, int h) const -{ - dxfString(0, "TABLE"); - dxfString(2, name); - if (version>=DL_VERSION_2000) - { - if (h==0) - { - handle(); - } - else - { - dxfHex(5, h); - } - dxfString(100, "AcDbSymbolTable"); - } - dxfInt(70, num); -} - -/** Table for layers. - * - * @param num Number of layers in total. - * - *
- *   0
- *  TABLE
- *   2
- *  LAYER
- *   70
- *      num
- * 
- */ -void DL_Writer::tableLayers(int num) const -{ - table("LAYER", num, 2); -} - -/** Table for line types. - * - * @param num Number of line types in total. - * - *
- *   0
- *  TABLE
- *   2
- *  LTYPE
- *   70
- *      num
- * 
- */ -void DL_Writer::tableLinetypes(int num) const -{ - //linetypeHandle = 5; - table("LTYPE", num, 5); -} - -/** Table for application id. - * - * @param num Number of registered applications in total. - * - *
- *   0
- *  TABLE
- *   2
- *  APPID
- *   70
- *      num
- * 
- */ -void DL_Writer::tableAppid(int num) const -{ - table("APPID", num, 9); -} - -/** Table for text style. - * - * @param num Number of text styles. - * - *
- *   0
- *  TABLE
- *   2
- *  STYLE
- *   70
- *      num
- * 
- */ -void DL_Writer::tableStyle(int num) const -{ - table("STYLE", num, 3); -} - -/** - * End of a table. - * - *
- *   0
- *  ENDTAB
- * 
- */ -void DL_Writer::tableEnd() const -{ - dxfString(0, "ENDTAB"); -} - -/** - * End of the DXF file. - * - *
- *   0
- *  EOF
- * 
- */ -void DL_Writer::dxfEOF() const -{ - dxfString(0, "EOF"); -} - -/** - * Comment. - * - *
- *  999
- *  text
- * 
- */ -void DL_Writer::comment(const char *text) const -{ - dxfString(999, text); -} - -/** - * Entity. - * - *
- *   0
- *  entTypeName
- * 
- * - */ -void DL_Writer::entity(const char *entTypeName) const -{ - dxfString(0, entTypeName); - if (version>=DL_VERSION_2000) - { - handle(); - } -} - -/** - * Attributes of an entity. - * - *
- *   8
- *  layer
- *  62
- *  color
- *  39
- *  width
- *   6
- *  linetype
- * 
- */ -void DL_Writer::entityAttributes(const DL_Attributes &attrib) const -{ - - // layer name: - dxfString(8, attrib.getLayer()); - - // R12 doesn't accept BYLAYER values. The value has to be missing - // in that case. - if (version>=DL_VERSION_2000 || attrib.getColor()!=256) - { - dxfInt(62, attrib.getColor()); - } - if (version>=DL_VERSION_2000 && attrib.getColor24()!=-1) - { - dxfInt(420, attrib.getColor24()); - } - if (version>=DL_VERSION_2000) - { - dxfInt(370, attrib.getWidth()); - } - if (version>=DL_VERSION_2000) //-V581 - { - dxfReal(48, attrib.getLinetypeScale()); - } - std::string linetype = attrib.getLinetype(); - std::transform(linetype.begin(), linetype.end(), linetype.begin(), ::toupper); - if (version>=DL_VERSION_2000 || linetype=="BYLAYER") - { - dxfString(6, attrib.getLinetype()); - } -} - -/** - * Subclass. - */ -void DL_Writer::subClass(const char *sub) const -{ - dxfString(100, sub); -} - -/** - * Layer (must be in the TABLES section LAYER). - * - *
- *   0
- *  LAYER
- * 
- */ -void DL_Writer::tableLayerEntry(unsigned long h) const -{ - dxfString(0, "LAYER"); - if (version>=DL_VERSION_2000) - { - if (h==0) - { - handle(); - } - else - { - dxfHex(5, static_cast(h)); - } - dxfString(100, "AcDbSymbolTableRecord"); - dxfString(100, "AcDbLayerTableRecord"); - } -} - -/** - * Line type (must be in the TABLES section LTYPE). - * - *
- *   0
- *  LTYPE
- * 
- */ -void DL_Writer::tableLinetypeEntry(unsigned long h) const -{ - dxfString(0, "LTYPE"); - if (version>=DL_VERSION_2000) - { - if (h==0) - { - handle(); - } - else - { - dxfHex(5, static_cast(h)); - } - //dxfHex(330, 0x5); - dxfString(100, "AcDbSymbolTableRecord"); - dxfString(100, "AcDbLinetypeTableRecord"); - } -} - -/** - * Appid (must be in the TABLES section APPID). - * - *
- *   0
- *  APPID
- * 
- */ -void DL_Writer::tableAppidEntry(unsigned long h) const -{ - dxfString(0, "APPID"); - if (version>=DL_VERSION_2000) - { - if (h==0) - { - handle(); - } - else - { - dxfHex(5, static_cast(h)); - } - //dxfHex(330, 0x9); - dxfString(100, "AcDbSymbolTableRecord"); - dxfString(100, "AcDbRegAppTableRecord"); - } -} - -/** - * Block (must be in the section BLOCKS). - * - *
- *   0
- *  BLOCK
- * 
- */ -void DL_Writer::sectionBlockEntry(unsigned long h) const -{ - dxfString(0, "BLOCK"); - if (version>=DL_VERSION_2000) - { - if (h==0) - { - handle(); - } - else - { - dxfHex(5, static_cast(h)); - } - //dxfHex(330, blockHandle); - dxfString(100, "AcDbEntity"); - if (h==0x1C) - { - dxfInt(67, 1); - } - dxfString(8, "0"); // TODO: Layer for block - dxfString(100, "AcDbBlockBegin"); - } -} - -/** - * End of Block (must be in the section BLOCKS). - * - *
- *   0
- *  ENDBLK
- * 
- */ -void DL_Writer::sectionBlockEntryEnd(unsigned long h) const -{ - dxfString(0, "ENDBLK"); - if (version>=DL_VERSION_2000) - { - if (h==0) - { - handle(); - } - else - { - dxfHex(5, static_cast(h)); - } - //dxfHex(330, blockHandle); - dxfString(100, "AcDbEntity"); - if (h==0x1D) - { - dxfInt(67, 1); - } - dxfString(8, "0"); // TODO: Layer for block - dxfString(100, "AcDbBlockEnd"); - } -} - -void DL_Writer::color(int col) const -{ - dxfInt(62, col); -} - -void DL_Writer::linetype(const char *lt) const -{ - dxfString(6, lt); -} - -void DL_Writer::linetypeScale(double scale) const -{ - dxfReal(48, scale); -} - -void DL_Writer::lineWeight(int lw) const -{ - dxfInt(370, lw); -} - -void DL_Writer::coord(int gc, double x, double y, double z) const -{ - dxfReal(gc, x); - dxfReal(gc+10, y); - dxfReal(gc+20, z); -} - -void DL_Writer::coordTriplet(int gc, const double *value) const -{ - if (value) - { - dxfReal(gc, *value++); - dxfReal(gc+10, *value++); - dxfReal(gc+20, *value++); - } -} - -void DL_Writer::resetHandle() const -{ - m_handle = 1; -} - -/** - * Writes a unique handle and returns it. - */ -unsigned long DL_Writer::handle(int gc) const -{ - // handle has to be hex - dxfHex(gc, static_cast(m_handle)); - return m_handle++; -} - -/** - * @return Next handle that will be written. - */ -unsigned long DL_Writer::getNextHandle() const -{ - return m_handle; -} - -/** - * Increases handle, so that the handle returned remains available. - */ -unsigned long DL_Writer::incHandle() const -{ - return m_handle++; -} - -/** - * Sets the handle of the model space. Entities refer to - * this handle. - */ -void DL_Writer::setModelSpaceHandle(unsigned long h) const -{ - modelSpaceHandle = h; -} - -unsigned long DL_Writer::getModelSpaceHandle() const -{ - return modelSpaceHandle; -} - -/** - * Sets the handle of the paper space. Some special blocks refer to - * this handle. - */ -void DL_Writer::setPaperSpaceHandle(unsigned long h) const -{ - paperSpaceHandle = h; -} - -unsigned long DL_Writer::getPaperSpaceHandle() const -{ - return paperSpaceHandle; -} - -/** - * Sets the handle of the paper space 0. Some special blocks refer to - * this handle. - */ -void DL_Writer::setPaperSpace0Handle(unsigned long h) const -{ - paperSpace0Handle = h; -} - -/** - * Sets the handle of the paper space 0. Some special blocks refer to - * this handle. - */ -unsigned long DL_Writer::getPaperSpace0Handle() const -{ - return paperSpace0Handle; -} - -/** - * Can be overwritten by the implementing class to write a - * bool value to the file. - * - * @param gc Group code. - * @param value The bool value. - */ -void DL_Writer::dxfBool(int gc, bool value) const -{ - dxfInt(gc, static_cast(value)); -} diff --git a/src/libs/vdxf/dxflib/dl_writer.h b/src/libs/vdxf/dxflib/dl_writer.h deleted file mode 100644 index 82316c3cf..000000000 --- a/src/libs/vdxf/dxflib/dl_writer.h +++ /dev/null @@ -1,170 +0,0 @@ -/**************************************************************************** -** Copyright (C) 2015 Roman Telezhynskyi -** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved. -** Copyright (C) 2001 Robert J. Campbell Jr. -** -** This file is part of the dxflib project. -** -** This file is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** Licensees holding valid dxflib Professional Edition licenses may use -** this file in accordance with the dxflib Commercial License -** Agreement provided with the Software. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.ribbonsoft.com for further details. -** -** Contact info@ribbonsoft.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -#ifndef DL_WRITER_H -#define DL_WRITER_H - -#include "dl_global.h" - -#ifndef _WIN32 -#include -#endif - -#if defined(Q_CC_MSVC) - #if (_MSC_VER > 1000) - #pragma once - #endif // _MSC_VER > 1000 -#endif // Q_CC_MSVC - -#include -#include -#include - -#include "dl_attributes.h" -#include "dl_codes.h" - -/** - * Defines interface for writing low level DXF constructs to - * a file. Implementation is defined in derived classes that write - * to binary or ASCII files. - * - * Implements functions that write higher level constructs in terms of - * the low level ones. - * - * @todo Add error checking for string/entry length. - */ -class DXFLIB_EXPORT DL_Writer -{ -public: - explicit DL_Writer(DL_Codes::version version); - virtual ~DL_Writer(); - - void section(const char* name) const; - void sectionHeader() const; - void sectionTables() const; - void sectionBlocks() const; - void sectionEntities() const; - void sectionClasses() const; - void sectionObjects() const; - void sectionEnd() const; - void table(const char* name, int num, int h=0) const; - void tableLayers(int num) const; - void tableLinetypes(int num) const; - void tableAppid(int num) const; - void tableStyle(int num) const; - void tableEnd() const; - void dxfEOF() const; - void comment(const char* text) const; - void entity(const char* entTypeName) const; - void entityAttributes(const DL_Attributes& attrib) const; - void subClass(const char* sub) const; - void tableLayerEntry(unsigned long int h=0) const; - void tableLinetypeEntry(unsigned long int h=0) const; - void tableAppidEntry(unsigned long int h=0) const; - void sectionBlockEntry(unsigned long int h=0) const; - void sectionBlockEntryEnd(unsigned long int h=0) const; - void color(int col=256) const; - void linetype(const char *lt) const; - void linetypeScale(double scale) const; - void lineWeight(int lw) const; - void coord(int gc, double x, double y, double z=0) const; - void coordTriplet(int gc, const double* value) const; - void resetHandle() const; - - unsigned long handle(int gc=5) const; - unsigned long getNextHandle() const; - unsigned long incHandle() const; - - void setModelSpaceHandle(unsigned long h) const; - unsigned long getModelSpaceHandle() const; - - void setPaperSpaceHandle(unsigned long h) const; - unsigned long getPaperSpaceHandle() const; - - void setPaperSpace0Handle(unsigned long h) const; - unsigned long getPaperSpace0Handle() const; - - /** - * Must be overwritten by the implementing class to write a - * real value to the file. - * - * @param gc Group code. - * @param value The real value. - */ - virtual void dxfReal(int gc, double value) const = 0; - - /** - * Must be overwritten by the implementing class to write an - * int value to the file. - * - * @param gc Group code. - * @param value The int value. - */ - virtual void dxfInt(int gc, int value) const = 0; - - - virtual void dxfBool(int gc, bool value) const; - - /** - * Must be overwritten by the implementing class to write an - * int value (hex) to the file. - * - * @param gc Group code. - * @param value The int value. - */ - virtual void dxfHex(int gc, int value) const = 0; - - /** - * Must be overwritten by the implementing class to write a - * string to the file. - * - * @param gc Group code. - * @param value The string. - */ - virtual void dxfString(int gc, const char* value) const = 0; - - /** - * Must be overwritten by the implementing class to write a - * string to the file. - * - * @param gc Group code. - * @param value The string. - */ - virtual void dxfString(int gc, const std::string& value) const = 0; - -protected: - mutable unsigned long m_handle; - mutable unsigned long modelSpaceHandle; - mutable unsigned long paperSpaceHandle; - mutable unsigned long paperSpace0Handle; - - /** - * DXF version to be created. - */ - DL_Codes::version version; -}; - -#endif diff --git a/src/libs/vdxf/dxflib/dl_writer_ascii.cpp b/src/libs/vdxf/dxflib/dl_writer_ascii.cpp deleted file mode 100644 index bc5555f6e..000000000 --- a/src/libs/vdxf/dxflib/dl_writer_ascii.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/**************************************************************************** -** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved. -** Copyright (C) 2001 Robert J. Campbell Jr. -** -** This file is part of the dxflib project. -** -** This file is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 2 of the License, or -** (at your option) any later version. -** -** Licensees holding valid dxflib Professional Edition licenses may use -** this file in accordance with the dxflib Commercial License -** Agreement provided with the Software. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.ribbonsoft.com for further details. -** -** Contact info@ribbonsoft.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -#if defined(Q_CC_MSVC) - #if (_MSC_VER > 1000) - #pragma once - #endif // _MSC_VER > 1000 -#endif // Q_CC_MSVC - -#include -#include -#include - -#include "../vmisc/diagnostic.h" -#include "dl_writer_ascii.h" - -/** - * Closes the output file. - */ -void DL_WriterA::close() const -{ - m_ofile.close(); -} - - -/** - * @retval true Opening file has failed. - * @retval false Otherwise. - */ -bool DL_WriterA::openFailed() const -{ - return m_ofile.fail(); -} - - - -/** - * Writes a real (double) variable to the DXF file. - * - * @param gc Group code. - * @param value Double value - */ -void DL_WriterA::dxfReal(int gc, double value) const -{ - char str[256]; -QT_WARNING_PUSH -#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) < 408 -QT_WARNING_DISABLE_GCC("-Wformat") -#endif - if (version==DL_Codes::AC1009_MIN) - { - snprintf(str, sizeof(str), "%.6lf", value); - } - else - { - snprintf(str, sizeof(str), "%.16lf", value); - } -QT_WARNING_POP - - // fix for german locale: - strReplace(str, ',', '.'); - - // Cut away those zeros at the end: - bool dot = false; - int end = -1; - for (quint32 i=0, sz = static_cast(strlen(str)); i(i)+2; - continue; - } - else if (dot && str[i]!='0') - { - end = static_cast(i)+1; - } - } - if (end>0 && end(strlen(str))) - { - str[end] = '\0'; - } - - dxfString(gc, str); - m_ofile.flush(); -} - - - -/** - * Writes an int variable to the DXF file. - * - * @param gc Group code. - * @param value Int value - */ -void DL_WriterA::dxfInt(int gc, int value) const -{ - m_ofile << (gc<10 ? " " : (gc<100 ? " " : "")) << gc << "\n" << value << "\n"; -} - - - -/** - * Writes a hex int variable to the DXF file. - * - * @param gc Group code. - * @param value Int value - */ -void DL_WriterA::dxfHex(int gc, int value) const -{ - char str[12]; - snprintf(str, sizeof(str), "%0X", value); - dxfString(gc, str); -} - - - -/** - * Writes a string variable to the DXF file. - * - * @param gc Group code. - * @param value String - */ -void DL_WriterA::dxfString(int gc, const char* value) const -{ - m_ofile << (gc<10 ? " " : (gc<100 ? " " : "")) << gc << "\n" - << value << "\n"; -} - - - -void DL_WriterA::dxfString(int gc, const std::string& value) const -{ - m_ofile << (gc<10 ? " " : (gc<100 ? " " : "")) << gc << "\n" - << value << "\n"; -} - - -/** - * Replaces every occurence of src with dest in the null terminated str. - */ -void DL_WriterA::strReplace(char* str, char src, char dest) -{ - size_t i; - for (i=0; i 1000) - #pragma once - #endif // _MSC_VER > 1000 - - #if _MSC_VER < 1900 - #define snprintf _snprintf - #endif -#endif // Q_CC_MSVC - -#include -#include - -#include "dl_writer.h" - -/** - * Implements functions defined in DL_Writer for writing low - * level DXF constructs to an ASCII format DXF file. - * - * @todo What if \c fname is NULL? Or \c fname can't be opened for - * another reason? - */ -class DXFLIB_EXPORT DL_WriterA : public DL_Writer -{ -public: - /** - * @brief DL_WriterA contructor - * @param fname File name of the file to be created. - * @param version DXF version. Defaults to DL_VERSION_2002. - */ - explicit DL_WriterA(const char* fname, DL_Codes::version version=DL_VERSION_2000) - : DL_Writer(version), m_ofile(fname) {} - virtual ~DL_WriterA() {} - - bool openFailed() const; - void close() const; - void dxfReal(int gc, double value) const; - void dxfInt(int gc, int value) const; - void dxfHex(int gc, int value) const; - void dxfString(int gc, const char* value) const; - void dxfString(int gc, const std::string& value) const; - - static void strReplace(char* str, char src, char dest); - -private: - /** - * DXF file to be created. - */ - mutable std::ofstream m_ofile; - -}; - -#endif - diff --git a/src/libs/vdxf/dxflib/strlcpy.h b/src/libs/vdxf/dxflib/strlcpy.h deleted file mode 100644 index 95bf9e9d1..000000000 --- a/src/libs/vdxf/dxflib/strlcpy.h +++ /dev/null @@ -1,150 +0,0 @@ -/************************************************************************ - ** - ** @file strlcpy.h - ** @author Roman Telezhynskyi - ** @date December 20, 2016 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentine project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013-2016 Valentina project - ** All Rights Reserved. - ** - ** Valentina is free software: you can redistribute it and/or modify - ** it under the terms of the GNU General Public License as published by - ** the Free Software Foundation, either version 3 of the License, or - ** (at your option) any later version. - ** - ** Valentina is distributed in the hope that it will be useful, - ** but WITHOUT ANY WARRANTY; without even the implied warranty of - ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - ** GNU General Public License for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** - *************************************************************************/ - -/* - * Copyright (c) 1998 Todd C. Miller - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef VALENTINA_STRLCPY_H -#define VALENTINA_STRLCPY_H - -/* This function comes from BSD */ -#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && \ - !defined(__bsdi__) && !defined(__APPLE__) -#include -#include - -#include "../vmisc/diagnostic.h" - -QT_WARNING_PUSH -QT_WARNING_DISABLE_CLANG("-Wsign-conversion") - -/* - * Copy src to string dst of size siz. At most siz-1 characters - * will be copied. Always NUL terminates (unless siz == 0). - * Returns strlen(src); if retval >= siz, truncation occurred. - */ -inline size_t strlcpy(char *dst, const char *src, size_t siz) -{ - char *d = dst; - const char *s = src; - size_t n = siz; - - /* Copy as many bytes as will fit */ - if (n != 0) - { - while (--n != 0) - { - if ((*d++ = *s++) == '\0') - { - break; - } - } - } - - /* Not enough room in dst, add NUL and traverse rest of src */ - if (n == 0) - { - if (siz != 0) - { - *d = '\0'; /* NUL-terminate dst */ - } - while (*s++) - ; - } - - return(s - src - 1); /* count does not include NUL */ -} - -/* - * Appends src to string dst of size siz (unlike strncat, siz is the - * full size of dst, not space left). At most siz-1 characters - * will be copied. Always NUL terminates (unless siz <= strlen(dst)). - * Returns strlen(src) + MIN(siz, strlen(initial dst)). - * If retval >= siz, truncation occurred. - */ -inline size_t strlcat(char *dst, const char *src, size_t siz) -{ - char *d = dst; - const char *s = src; - size_t n = siz; - size_t dlen; - - /* Find the end of dst and adjust bytes left but don't go past end */ - while (n-- != 0 && *d != '\0') - { - d++; - } - dlen = d - dst; - n = siz - dlen; - - if (n == 0) - { - return(dlen + strlen(s)); - } - while (*s != '\0') - { - if (n != 1) - { - *d++ = *s; - n--; - } - s++; - } - *d = '\0'; - - return(dlen + (s - src)); /* count does not include NUL */ -} - -QT_WARNING_POP - -#endif /* ! __*BSD__ */ -#endif // VALENTINA_STRLCPY_H diff --git a/src/libs/vdxf/dxiface.cpp b/src/libs/vdxf/dxiface.cpp new file mode 100644 index 000000000..a8ad79ff5 --- /dev/null +++ b/src/libs/vdxf/dxiface.cpp @@ -0,0 +1,434 @@ +/****************************************************************************** +** dwg2dxf - Program to convert dwg/dxf to dxf(ascii & binary) ** +** ** +** Copyright (C) 2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#include "dxiface.h" +#include "libdxfrw/libdwgr.h" +#include "libdxfrw/libdxfrw.h" +#include "../vmisc/vabstractapplication.h" + +#include +#include +#include +#include +#include + +dx_iface::dx_iface(const std::string &file, DRW::Version v, VarMeasurement varMeasurement, VarInsunits varInsunits) + : dxfW(new dxfRW(file.c_str())), + cData(), + version(v) +{ + InitHeader(varMeasurement, varInsunits); + InitLTypes(); + InitLayers(); + InitTextstyles(); + InitAppId(); +} + +dx_iface::~dx_iface() +{ + delete dxfW; +} + +bool dx_iface::fileExport(bool binary) +{ + bool success = dxfW->write(this, version, binary); + return success; +} + +void dx_iface::writeEntity(DRW_Entity* e){ + switch (e->eType) { + case DRW::POINT: + dxfW->writePoint(static_cast(e)); + break; + case DRW::LINE: + dxfW->writeLine(static_cast(e)); + break; + case DRW::CIRCLE: + dxfW->writeCircle(static_cast(e)); + break; + case DRW::ARC: + dxfW->writeArc(static_cast(e)); + break; + case DRW::SOLID: + dxfW->writeSolid(static_cast(e)); + break; + case DRW::ELLIPSE: + dxfW->writeEllipse(static_cast(e)); + break; + case DRW::LWPOLYLINE: + dxfW->writeLWPolyline(static_cast(e)); + break; + case DRW::POLYLINE: + dxfW->writePolyline(static_cast(e)); + break; + case DRW::SPLINE: + dxfW->writeSpline(static_cast(e)); + break; +// case RS2::EntitySplinePoints: +// writeSplinePoints(static_cast(e)); +// break; +// case RS2::EntityVertex: +// break; + case DRW::INSERT: + dxfW->writeInsert(static_cast(e)); + break; + case DRW::MTEXT: + dxfW->writeMText(static_cast(e)); + break; + case DRW::TEXT: + dxfW->writeText(static_cast(e)); + break; + case DRW::DIMLINEAR: + case DRW::DIMALIGNED: + case DRW::DIMANGULAR: + case DRW::DIMANGULAR3P: + case DRW::DIMRADIAL: + case DRW::DIMDIAMETRIC: + case DRW::DIMORDINATE: + dxfW->writeDimension(static_cast(e)); + break; + case DRW::LEADER: + dxfW->writeLeader(static_cast(e)); + break; + case DRW::HATCH: + dxfW->writeHatch(static_cast(e)); + break; + case DRW::IMAGE: + dxfW->writeImage(static_cast(e), static_cast(e)->path); + break; + default: + break; + } +} + +void dx_iface::writeHeader(DRW_Header &data){ + //complete copy of header vars: + data = cData.headerC; + //or copy one by one: + // for (std::map::iterator it=cData->headerC.vars.begin(); it != cData->headerC.vars.end(); ++it) + // data.vars[it->first] = new DRW_Variant( *(it->second) ); +} + +void dx_iface::writeBlocks(){ + //write each block + for (std::list::iterator it=cData.blocks.begin(); it != cData.blocks.end(); ++it){ + dx_ifaceBlock* bk = *it; + dxfW->writeBlock(bk); + //and write each entity in block + for (std::list::const_iterator it=bk->ent.begin(); it!=bk->ent.end(); ++it) + writeEntity(*it); + } +} + +void dx_iface::writeBlockRecords(){ + for (std::list::iterator it=cData.blocks.begin(); it != cData.blocks.end(); ++it) + dxfW->writeBlockRecord((*it)->name); +} + +void dx_iface::writeEntities(){ + for (std::list::const_iterator it=cData.mBlock->ent.begin(); it!=cData.mBlock->ent.end(); ++it) + writeEntity(*it); +} + +void dx_iface::writeLTypes(){ + for (std::list::iterator it=cData.lineTypes.begin(); it != cData.lineTypes.end(); ++it) + dxfW->writeLineType(&(*it)); +} + +void dx_iface::writeLayers(){ + for (std::list::iterator it=cData.layers.begin(); it != cData.layers.end(); ++it) + dxfW->writeLayer(&(*it)); +} + +void dx_iface::writeTextstyles(){ + for (std::list::iterator it=cData.textStyles.begin(); it != cData.textStyles.end(); ++it) + dxfW->writeTextstyle(&(*it)); +} + +void dx_iface::writeVports(){ + for (std::list::iterator it=cData.VPorts.begin(); it != cData.VPorts.end(); ++it) + dxfW->writeVport(&(*it)); +} + +void dx_iface::writeDimstyles(){ + for (std::list::iterator it=cData.dimStyles.begin(); it != cData.dimStyles.end(); ++it) + dxfW->writeDimstyle(&(*it)); +} + +void dx_iface::writeAppId(){ + for (std::list::iterator it=cData.appIds.begin(); it != cData.appIds.end(); ++it) + dxfW->writeAppId(&(*it)); +} + +void dx_iface::InitHeader(VarMeasurement varMeasurement, VarInsunits varInsunits) +{ + cData.headerC.addComment("Valentina DXF File"); + + // 1 = Clockwise angles, 0 = Counterclockwise + cData.headerC.addInt("$ANGDIR", 0, 70);// Qt use counterclockwise + + // Sets drawing units: 0 = English; 1 = Metric + cData.headerC.addInt("$MEASUREMENT", static_cast(varMeasurement), 70); + cData.headerC.addInt("$INSUNITS", static_cast(varInsunits), 70); + + QString dateTime = QDateTime::currentDateTime().toString("yyyyMMdd.HHmmsszzz"); + dateTime.chop(1);// we need hundredths of a second + cData.headerC.addStr("$TDCREATE", dateTime.toStdString(), 40); + + if (version >= DRW::AC1021) + { // Full support Unicode + cData.headerC.addStr("$DWGCODEPAGE", "UTF-8", 3); + } + else + { + cData.headerC.addStr("$DWGCODEPAGE", LocaleToISO(), 3); + } +} + +void dx_iface::InitLTypes() +{ + DRW_LType ltype; + ltype.name = "DOT"; + ltype.desc = "Dot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ."; + ltype.size = 2; + ltype.length = 0.125; + ltype.path.push_back(0.0); + ltype.path.push_back(-0.125); + cData.lineTypes.push_back(ltype); + + ltype.path.clear(); + ltype.name = "DASHED"; + ltype.desc = "Dashed _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _"; + ltype.size = 2; + ltype.length = 0.375; + ltype.path.push_back(0.25); + ltype.path.push_back(-0.125); + cData.lineTypes.push_back(ltype); + + ltype.path.clear(); + ltype.name = "DASHDOT2"; + ltype.desc = "Dash dot2 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._."; + ltype.size = 4; + ltype.length = 0.5; + ltype.path.push_back(0.25); + ltype.path.push_back(-0.125); + ltype.path.push_back(0.0); + ltype.path.push_back(-0.125); + cData.lineTypes.push_back(ltype); + + ltype.path.clear(); + ltype.name = "DIVIDE2"; + ltype.desc = "Divide2 __..__..__..__..__..__..__..__..__..__..__..__..__..__..__..__.."; + ltype.size = 6; + ltype.length = 0.625; + ltype.path.push_back(0.25); + ltype.path.push_back(-0.125); + ltype.path.push_back(0.0); + ltype.path.push_back(-0.125); + ltype.path.push_back(0.0); + ltype.path.push_back(-0.125); + cData.lineTypes.push_back(ltype); +} + +void dx_iface::InitLayers() +{ + DRW_Layer defLayer; + defLayer.name = "0"; + defLayer.color = DRW::black; // default color + defLayer.lWeight = DRW_LW_Conv::width17; // default width + defLayer.lineType = "CONTINUOUS"; // default line style + cData.layers.push_back(defLayer); + +// DRW_Layer mLayer; +// mLayer.name = "mainlayer"; +// mLayer.color = DRW::black; // default color +// mLayer.lWeight = 100; // default width +// mLayer.lineType = "CONTINUOUS"; // default line style +// cData.lineTypes.push_back(mLayer); +} + +void dx_iface::InitTextstyles() +{ + DRW_Textstyle style; + style.name = "Standard"; + style.lastHeight = 2.5; + style.font = "txt"; + + cData.textStyles.push_back(style); +} + +void dx_iface::InitAppId() +{ + DRW_AppId ai; + ai.name ="Valentina"; + cData.appIds.push_back(ai); +} + +void dx_iface::AddEntity(DRW_Entity *e) +{ + cData.mBlock->ent.push_back(e); +} + +UTF8STRING dx_iface::AddFont(const QFont &f) +{ + DRW_Textstyle ts; + ts.name = f.family().toUpper().toStdString(); + + // Idea source https://stackoverflow.com/questions/20111522/writing-text-styles-into-dxf-from-a-delphi-application + if (f.bold()) + { + ts.name += "_BOLD"; + ts.fontFamily += 0x2000000; + } + + if (f.italic()) + { + ts.name += "_ITALIC"; + ts.fontFamily += 0x1000000; + } + + for (auto it = cData.textStyles.begin() ; it !=cData.textStyles.end() ; ++it) + { + if ((*it).name == ts.name) + { + return ts.name; + } + } + + ts.font = f.family().toStdString(); + + cData.textStyles.push_back(ts); + + return ts.name; +} + +std::string dx_iface::LocaleToISO() const +{ + QMap locMap; + locMap["croatian"] = "ISO8859-2"; + locMap["cs"] = "ISO8859-2"; + locMap["cs_CS"] = "ISO8859-2"; + locMap["cs_CZ"] = "ISO8859-2"; + locMap["cz"] = "ISO8859-2"; + locMap["cz_CZ"] = "ISO8859-2"; + locMap["czech"] = "ISO8859-2"; + locMap["hr"] = "ISO8859-2"; + locMap["hr_HR"] = "ISO8859-2"; + locMap["hu"] = "ISO8859-2"; + locMap["hu_HU"] = "ISO8859-2"; + locMap["hungarian"] = "ISO8859-2"; + locMap["pl"] = "ISO8859-2"; + locMap["pl_PL"] = "ISO8859-2"; + locMap["polish"] = "ISO8859-2"; + locMap["ro"] = "ISO8859-2"; + locMap["ro_RO"] = "ISO8859-2"; + locMap["rumanian"] = "ISO8859-2"; + locMap["serbocroatian"] = "ISO8859-2"; + locMap["sh"] = "ISO8859-2"; + locMap["sh_SP"] = "ISO8859-2"; + locMap["sh_YU"] = "ISO8859-2"; + locMap["sk"] = "ISO8859-2"; + locMap["sk_SK"] = "ISO8859-2"; + locMap["sl"] = "ISO8859-2"; + locMap["sl_CS"] = "ISO8859-2"; + locMap["sl_SI"] = "ISO8859-2"; + locMap["slovak"] = "ISO8859-2"; + locMap["slovene"] = "ISO8859-2"; + locMap["sr_SP"] = "ISO8859-2"; + + locMap["eo"] = "ISO8859-3"; + + locMap["ee"] = "ISO8859-4"; + locMap["ee_EE"] = "ISO8859-4"; + + locMap["mk"] = "ISO8859-5"; + locMap["mk_MK"] = "ISO8859-5"; + locMap["sp"] = "ISO8859-5"; + locMap["sp_YU"] = "ISO8859-5"; + + locMap["ar_AA"] = "ISO8859-6"; + locMap["ar_SA"] = "ISO8859-6"; + locMap["arabic"] = "ISO8859-6"; + + locMap["el"] = "ISO8859-7"; + locMap["el_GR"] = "ISO8859-7"; + locMap["greek"] = "ISO8859-7"; + + locMap["hebrew"] = "ISO8859-8"; + locMap["he"] = "ISO8859-8"; + locMap["he_IL"] = "ISO8859-8"; + locMap["iw"] = "ISO8859-8"; + locMap["iw_IL"] = "ISO8859-8"; + + locMap["tr"] = "ISO8859-9"; + locMap["tr_TR"] = "ISO8859-9"; + locMap["turkish"] = "ISO8859-9"; + + locMap["lt"] = "ISO8859-13"; + locMap["lt_LT"] = "ISO8859-13"; + locMap["lv"] = "ISO8859-13"; + locMap["lv_LV"] = "ISO8859-13"; + + locMap["et"] = "ISO8859-15"; + locMap["et_EE"] = "ISO8859-15"; + locMap["br_FR"] = "ISO8859-15"; + locMap["ca_ES"] = "ISO8859-15"; + locMap["de"] = "ISO8859-15"; + locMap["de_AT"] = "ISO8859-15"; + locMap["de_BE"] = "ISO8859-15"; + locMap["de_DE"] = "ISO8859-15"; + locMap["de_LU"] = "ISO8859-15"; + locMap["en_IE"] = "ISO8859-15"; + locMap["es"] = "ISO8859-15"; + locMap["es_ES"] = "ISO8859-15"; + locMap["eu_ES"] = "ISO8859-15"; + locMap["fi"] = "ISO8859-15"; + locMap["fi_FI"] = "ISO8859-15"; + locMap["finnish"] = "ISO8859-15"; + locMap["fr"] = "ISO8859-15"; + locMap["fr_FR"] = "ISO8859-15"; + locMap["fr_BE"] = "ISO8859-15"; + locMap["fr_LU"] = "ISO8859-15"; + locMap["french"] = "ISO8859-15"; + locMap["ga_IE"] = "ISO8859-15"; + locMap["gl_ES"] = "ISO8859-15"; + locMap["it"] = "ISO8859-15"; + locMap["it_IT"] = "ISO8859-15"; + locMap["oc_FR"] = "ISO8859-15"; + locMap["nl"] = "ISO8859-15"; + locMap["nl_BE"] = "ISO8859-15"; + locMap["nl_NL"] = "ISO8859-15"; + locMap["pt"] = "ISO8859-15"; + locMap["pt_PT"] = "ISO8859-15"; + locMap["sv_FI"] = "ISO8859-15"; + locMap["wa_BE"] = "ISO8859-15"; + + locMap["uk"] = "KOI8-U"; + locMap["uk_UA"] = "KOI8-U"; + locMap["ru_YA"] = "KOI8-U"; + locMap["ukrainian"] = "KOI8-U"; + locMap["ru_RU"] = "KOI8-U"; + + locMap["be"] = "KOI8-R"; + locMap["be_BY"] = "KOI8-R"; + locMap["bg"] = "KOI8-R"; + locMap["bg_BG"] = "KOI8-R"; + locMap["bulgarian"] = "KOI8-R"; + locMap["ba_RU"] = "KOI8-R"; + locMap["ky"] = "KOI8-R"; + locMap["ky_KG"] = "KOI8-R"; + locMap["kk"] = "KOI8-R"; + locMap["kk_KZ"] = "KOI8-R"; + + QLocale locale(qApp->Settings()->GetLocale()); + return locMap.value(locale.name().toStdString(), "ISO8859-1"); +} diff --git a/src/libs/vdxf/dxiface.h b/src/libs/vdxf/dxiface.h new file mode 100644 index 000000000..2d835e40a --- /dev/null +++ b/src/libs/vdxf/dxiface.h @@ -0,0 +1,112 @@ +/****************************************************************************** +** dwg2dxf - Program to convert dwg/dxf to dxf(ascii & binary) ** +** ** +** Copyright (C) 2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#ifndef DX_IFACE_H +#define DX_IFACE_H + +#include "libdxfrw/drw_interface.h" +#include "libdxfrw/libdxfrw.h" +#include "dxfdef.h" + +class QFont; + +//class to store image data and path from DRW_ImageDef +class dx_ifaceImg : public DRW_Image { +public: + dx_ifaceImg(){} + dx_ifaceImg(const DRW_Image& p):DRW_Image(p){} + ~dx_ifaceImg(){} + std::string path; //stores the image path +}; + +//container class to store entites. +class dx_ifaceBlock : public DRW_Block { +public: + dx_ifaceBlock(){} + dx_ifaceBlock(const DRW_Block& p):DRW_Block(p){} + ~dx_ifaceBlock(){ + for (std::list::const_iterator it=ent.begin(); it!=ent.end(); ++it) + delete *it; + } + std::listent; //stores the entities list +}; + + +//container class to store full dwg/dxf data. +class dx_data { +public: + dx_data(){ + mBlock = new dx_ifaceBlock(); + } + ~dx_data(){ + //cleanup, + for (std::list::const_iterator it=blocks.begin(); it!=blocks.end(); ++it) + delete *it; + delete mBlock; + } + + DRW_Header headerC; //stores a copy of the header vars + std::listlineTypes; //stores a copy of all line types + std::listlayers; //stores a copy of all layers + std::listdimStyles; //stores a copy of all dimension styles + std::listVPorts; //stores a copy of all vports + std::listtextStyles; //stores a copy of all text styles + std::listappIds; //stores a copy of all line types + std::listblocks; //stores a copy of all blocks and the entities in it + std::listimages; //temporary list to find images for link with DRW_ImageDef. Do not delete it!! + + dx_ifaceBlock* mBlock; //container to store model entities + + +}; + +class dx_iface : public DRW_Interface +{ +public: + dx_iface(const std::string& file, DRW::Version v, VarMeasurement varMeasurement, VarInsunits varInsunits); + virtual ~dx_iface(); + bool fileExport(bool binary); + void writeEntity(DRW_Entity* e); + +//reimplement virtual DRW_Interface functions +//writer part, send all in class dx_data to writer + virtual void writeHeader(DRW_Header& data); + virtual void writeBlocks(); + //only send the name, needed by the reader to prepare handles of blocks & blockRecords + virtual void writeBlockRecords(); + //write entities of model space and first paper_space + virtual void writeEntities(); + virtual void writeLTypes(); + virtual void writeLayers(); + virtual void writeTextstyles(); + virtual void writeVports(); + virtual void writeDimstyles(); + virtual void writeAppId(); + + void AddEntity(DRW_Entity* e); + UTF8STRING AddFont(const QFont &f); + +private: + dxfRW* dxfW; //pointer to writer, needed to send data + dx_data cData; // class to store or read data + DRW::Version version; + + void InitHeader(VarMeasurement varMeasurement, VarInsunits varInsunits); + void InitLTypes(); + void InitLayers(); + void InitTextstyles(); + void InitAppId(); + + std::string LocaleToISO() const; +}; + +#endif // DX_IFACE_H diff --git a/src/libs/vdxf/libdxfrw/AUTHORS b/src/libs/vdxf/libdxfrw/AUTHORS new file mode 100644 index 000000000..fe5391f55 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/AUTHORS @@ -0,0 +1,7 @@ + +Rallaz + Original author. +Nicu Tofan + contributor. +Miguel E. Hernández Cuervo + contributor. \ No newline at end of file diff --git a/src/libs/vdxf/libdxfrw/COPYING b/src/libs/vdxf/libdxfrw/COPYING new file mode 100644 index 000000000..d159169d1 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/COPYING @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/src/libs/vdxf/libdxfrw/README b/src/libs/vdxf/libdxfrw/README new file mode 100644 index 000000000..38ce780be --- /dev/null +++ b/src/libs/vdxf/libdxfrw/README @@ -0,0 +1,29 @@ +libdxfrw + +libdxfrw is a free C++ library to read and write DXF files in both formats, ascii and binary form. +Also can read DWG files from R14 to the last V2015. + It is licensed under the terms of the GNU General Public License version 2 (or at you option +any later version). + + +If you are looking for general information about the project, check our website: +http://sourceforge.net/projects/libdxfrw + +== Building and installing the library == + +Use the tipical +./configure +make +make install (as root) + +[VC++] +- Open vs2013\libdxfrw.sln with VS2013 +- Build Solution +There is also a dwg to dxf converter that depends on libdxfrw that can be built the same way. +- Open dwg2dxf\vs2013\dwg2dxf.sln with VS2013 +- Build Solution + +== Example usage of the library == + +The dwg to dxf converter (dwg2dxf) included in this package can be used as reference. + diff --git a/src/libs/vdxf/libdxfrw/drw_base.h b/src/libs/vdxf/libdxfrw/drw_base.h new file mode 100644 index 000000000..23378663c --- /dev/null +++ b/src/libs/vdxf/libdxfrw/drw_base.h @@ -0,0 +1,496 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#ifndef DRW_BASE_H +#define DRW_BASE_H + +#define DRW_VERSION "0.6.3" + +#include +#include +#include + +#ifdef DRW_ASSERTS +# define drw_assert(a) assert(a) +#else +# define drw_assert(a) +#endif + +#define UTF8STRING std::string +#define DRW_UNUSED(x) (void)x + +#if defined(WIN64) || defined(_WIN64) || defined(__WIN64__) +# define DRW_WIN +#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) +# define DRW_WIN +#elif defined(__MWERKS__) && defined(__INTEL__) +# define DRW_WIN +#else +# define DRW_POSIX +#endif + +#ifndef M_PI + #define M_PI 3.141592653589793238462643 +#endif +#ifndef M_PI_2 + #define M_PI_2 1.57079632679489661923 +#endif +#define M_PIx2 6.283185307179586 // 2*PI +#define ARAD 57.29577951308232 + +typedef signed char dint8; /* 8 bit signed */ +typedef signed short dint16; /* 16 bit signed */ +typedef signed int dint32; /* 32 bit signed */ +typedef long long int dint64; /* 64 bit signed */ + +typedef unsigned char duint8; /* 8 bit unsigned */ +typedef unsigned short duint16; /* 16 bit unsigned */ +typedef unsigned int duint32; /* 32 bit unsigned */ +typedef unsigned long long int duint64; /* 64 bit unsigned */ + +typedef float dfloat32; /* 32 bit floating point */ +typedef double ddouble64; /* 64 bit floating point */ +typedef long double ddouble80; /* 80 bit floating point */ + + +namespace DRW { + +//! Version numbers for the DXF Format. +enum Version { + UNKNOWNV, /*!< UNKNOWN VERSION. */ + AC1006, /*!< R10. */ + AC1009, /*!< R11 & R12. */ + AC1012, /*!< R13. */ + AC1014, /*!< R14. */ + AC1015, /*!< ACAD 2000. */ + AC1018, /*!< ACAD 2004. */ + AC1021, /*!< ACAD 2007. */ + AC1024, /*!< ACAD 2010. */ + AC1027 /*!< ACAD 2013. */ +}; + +enum error { +BAD_NONE, /*!< No error. */ +BAD_UNKNOWN, /*!< UNKNOWN. */ +BAD_OPEN, /*!< error opening file. */ +BAD_VERSION, /*!< unsupported version. */ +BAD_READ_METADATA, /*!< error reading matadata. */ +BAD_READ_FILE_HEADER, /*!< error in file header read process. */ +BAD_READ_HEADER, /*!< error in header vars read process. */ +BAD_READ_HANDLES, /*!< error in object map read process. */ +BAD_READ_CLASSES, /*!< error in classes read process. */ +BAD_READ_TABLES, /*!< error in tables read process. */ +BAD_READ_BLOCKS, /*!< error in block read process. */ +BAD_READ_ENTITIES, /*!< error in entities read process. */ +BAD_READ_OBJECTS /*!< error in objects read process. */ +}; + +enum DBG_LEVEL { + NONE, + DEBUG +}; + +//! Special codes for colors +enum ColorCodes { + black = 250, + green = 3, + red = 1, + brown = 15, + yellow = 2, + cyan = 4, + magenta = 6, + gray = 8, + blue = 5, + l_blue = 163, + l_green = 121, + l_cyan = 131, + l_red = 23, + l_magenta = 221, + l_gray = 252, + white = 7, + ColorByLayer = 256, + ColorByBlock = 0 +}; + +//! Spaces +enum Space { + ModelSpace = 0, + PaperSpace = 1 +}; + +//! Special kinds of handles +enum HandleCodes { + NoHandle = 0 +}; + +//! Shadow mode +enum ShadowMode { + CastAndReceieveShadows = 0, + CastShadows = 1, + ReceiveShadows = 2, + IgnoreShadows = 3 +}; + +//! Special kinds of materials +enum MaterialCodes { + MaterialByLayer = 0 +}; + +//! Special kinds of plot styles +enum PlotStyleCodes { + DefaultPlotStyle = 0 +}; + +//! Special kinds of transparencies +enum TransparencyCodes { + Opaque = 0, + Transparent = -1 +}; + +} // namespace DRW + +//! Class to handle 3D coordinate point +/*! +* Class to handle 3D coordinate point +* @author Rallaz +*/ +class DRW_Coord { +public: + DRW_Coord() { x = 0; y = 0; z = 0; } + DRW_Coord(double ix, double iy, double iz) { + x = ix; y = iy; z = iz; + } + + DRW_Coord operator = (const DRW_Coord& data) { + x = data.x; y = data.y; z = data.z; + return *this; + } +/*!< convert to unitary vector */ + void unitize(){ + double dist; + dist = sqrt(x*x + y*y + z*z); + if (dist > 0.0) { + x= x/dist; + y= y/dist; + z= z/dist; + } + } + +public: + double x; + double y; + double z; +}; + + +//! Class to handle vertex +/*! +* Class to handle vertex for lwpolyline entity +* @author Rallaz +*/ +class DRW_Vertex2D { +public: + DRW_Vertex2D() { +// eType = DRW::LWPOLYLINE; + stawidth = endwidth = bulge = 0; + } + DRW_Vertex2D(double sx, double sy, double b) { + stawidth = endwidth = 0; + x = sx; + y =sy; + bulge = b; + } + +public: + double x; /*!< x coordinate, code 10 */ + double y; /*!< y coordinate, code 20 */ + double stawidth; /*!< Start width, code 40 */ + double endwidth; /*!< End width, code 41 */ + double bulge; /*!< bulge, code 42 */ +}; + + +//! Class to handle header vars +/*! +* Class to handle header vars +* @author Rallaz +*/ +class DRW_Variant { +public: + enum TYPE { + STRING, + INTEGER, + DOUBLE, + COORD, + INVALID + }; +//TODO: add INT64 support + DRW_Variant() { + type = INVALID; + } + + DRW_Variant(int c, dint32 i) { + code = c; addInt(i); + } + DRW_Variant(int c, duint32 i) { + code = c; addInt(static_cast(i));//RLZ: verify if worrk with big numbers + } + DRW_Variant(int c, double d) { + code = c; addDouble(d); + } + DRW_Variant(int c, UTF8STRING s) { + code = c; addString(s); + } + DRW_Variant(int c, DRW_Coord crd) { + code = c; addCoord(crd); + } + DRW_Variant(const DRW_Variant& d) { + code = d.code; + type = d.type; + content = d.content; + if (d.type == COORD) { + vdata = d.vdata; + content.v = &vdata; + } + if (d.type == STRING) { + sdata = d.sdata; + content.s = &sdata; + } + } + + ~DRW_Variant() { + } + + void addString(UTF8STRING s) {setType(STRING); sdata = s; content.s = &sdata;} + void addInt(int i) {setType(INTEGER); content.i = i;} + void addDouble(double d) {setType(DOUBLE); content.d = d;} + void addCoord() {setType(COORD); vdata.x=0.0; vdata.y=0.0; vdata.z=0.0; content.v = &vdata;} + void addCoord(DRW_Coord v) {setType(COORD); vdata = v; content.v = &vdata;} + void setType(enum TYPE t) { type = t;} + void setCoordX(double d) { if (type == COORD) vdata.x = d;} + void setCoordY(double d) { if (type == COORD) vdata.y = d;} + void setCoordZ(double d) { if (type == COORD) vdata.z = d;} + +private: + typedef union { + UTF8STRING *s; + dint32 i; + double d; + DRW_Coord *v; + } DRW_VarContent; + +public: + DRW_VarContent content; + enum TYPE type; + int code; /*!< dxf code of this value*/ + +private: + std::string sdata; + DRW_Coord vdata; +}; + +//! Class to handle dwg handles +/*! +* Class to handle dwg handles +* @author Rallaz +*/ +class dwgHandle{ +public: + dwgHandle(){ + code=0; + size=0; + ref=0; + } + ~dwgHandle(){} + duint8 code; + duint8 size; + duint32 ref; +}; + +//! Class to convert between line width and integer +/*! +* Class to convert between line width and integer +* verifing valid values, if value is not valid +* returns widthDefault. +* @author Rallaz +*/ +class DRW_LW_Conv{ +public: + enum lineWidth { + width00 = 0, /*!< 0.00mm (dxf 0)*/ + width01 = 1, /*!< 0.05mm (dxf 5)*/ + width02 = 2, /*!< 0.09mm (dxf 9)*/ + width03 = 3, /*!< 0.13mm (dxf 13)*/ + width04 = 4, /*!< 0.15mm (dxf 15)*/ + width05 = 5, /*!< 0.18mm (dxf 18)*/ + width06 = 6, /*!< 0.20mm (dxf 20)*/ + width07 = 7, /*!< 0.25mm (dxf 25)*/ + width08 = 8, /*!< 0.30mm (dxf 30)*/ + width09 = 9, /*!< 0.35mm (dxf 35)*/ + width10 = 10, /*!< 0.40mm (dxf 40)*/ + width11 = 11, /*!< 0.50mm (dxf 50)*/ + width12 = 12, /*!< 0.53mm (dxf 53)*/ + width13 = 13, /*!< 0.60mm (dxf 60)*/ + width14 = 14, /*!< 0.70mm (dxf 70)*/ + width15 = 15, /*!< 0.80mm (dxf 80)*/ + width16 = 16, /*!< 0.90mm (dxf 90)*/ + width17 = 17, /*!< 1.00mm (dxf 100)*/ + width18 = 18, /*!< 1.06mm (dxf 106)*/ + width19 = 19, /*!< 1.20mm (dxf 120)*/ + width20 = 20, /*!< 1.40mm (dxf 140)*/ + width21 = 21, /*!< 1.58mm (dxf 158)*/ + width22 = 22, /*!< 2.00mm (dxf 200)*/ + width23 = 23, /*!< 2.11mm (dxf 211)*/ + widthByLayer = 29, /*!< by layer (dxf -1) */ + widthByBlock = 30, /*!< by block (dxf -2) */ + widthDefault = 31 /*!< by default (dxf -3) */ + }; + + static int lineWidth2dxfInt(enum lineWidth lw){ + switch (lw){ + case widthByLayer: + return -1; + case widthByBlock: + return -2; + case widthDefault: + return -3; + case width00: + return 0; + case width01: + return 5; + case width02: + return 9; + case width03: + return 13; + case width04: + return 15; + case width05: + return 18; + case width06: + return 20; + case width07: + return 25; + case width08: + return 30; + case width09: + return 35; + case width10: + return 40; + case width11: + return 50; + case width12: + return 53; + case width13: + return 60; + case width14: + return 70; + case width15: + return 80; + case width16: + return 90; + case width17: + return 100; + case width18: + return 106; + case width19: + return 120; + case width20: + return 140; + case width21: + return 158; + case width22: + return 200; + case width23: + return 211; + default: + break; + } + return -3; + } + + static int lineWidth2dwgInt(enum lineWidth lw){ + return static_cast (lw); + } + + static enum lineWidth dxfInt2lineWidth(int i){ + if (i<0) { + if (i==-1) + return widthByLayer; + else if (i==-2) + return widthByBlock; + else if (i==-3) + return widthDefault; + } else if (i<3) { + return width00; + } else if (i<7) { + return width01; + } else if (i<11) { + return width02; + } else if (i<14) { + return width03; + } else if (i<16) { + return width04; + } else if (i<19) { + return width05; + } else if (i<22) { + return width06; + } else if (i<27) { + return width07; + } else if (i<32) { + return width08; + } else if (i<37) { + return width09; + } else if (i<45) { + return width10; + } else if (i<52) { + return width11; + } else if (i<57) { + return width12; + } else if (i<65) { + return width13; + } else if (i<75) { + return width14; + } else if (i<85) { + return width15; + } else if (i<95) { + return width16; + } else if (i<103) { + return width17; + } else if (i<112) { + return width18; + } else if (i<130) { + return width19; + } else if (i<149) { + return width20; + } else if (i<180) { + return width21; + } else if (i<205) { + return width22; + } else { + return width23; + } + //default by default + return widthDefault; + } + + static enum lineWidth dwgInt2lineWidth(int i){ + if ( (i>-1 && i<24) || (i>28 && i<32) ) { + return static_cast (i); + } + //default by default + return widthDefault; + } +}; + +#endif + +// EOF diff --git a/src/libs/vdxf/libdxfrw/drw_classes.cpp b/src/libs/vdxf/libdxfrw/drw_classes.cpp new file mode 100644 index 000000000..02eb01dc7 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/drw_classes.cpp @@ -0,0 +1,115 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#include "drw_classes.h" +#include "intern/dxfreader.h" +#include "intern/dxfwriter.h" +#include "intern/dwgbuffer.h" +#include "intern/drw_dbg.h" + +void DRW_Class::parseCode(int code, dxfReader *reader){ + switch (code) { + case 1: + recName = reader->getUtf8String(); + break; + case 2: + className = reader->getUtf8String(); + break; + case 3: + appName = reader->getUtf8String(); + break; + case 90: + proxyFlag = reader->getInt32(); + break; + case 91: + instanceCount = reader->getInt32(); + break; + case 280: + wasaProxyFlag = reader->getInt32(); + break; + case 281: + entityFlag = reader->getInt32(); + break; + default: + break; + } +} + +bool DRW_Class::parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer *strBuf){ + DRW_DBG("\n***************************** parsing Class *********************************************\n"); + + classNum = buf->getBitShort(); + DRW_DBG("Class number: "); DRW_DBG(classNum); + proxyFlag = buf->getBitShort(); //in dwg specs says "version" + + appName = strBuf->getVariableText(version, false); + className = strBuf->getVariableText(version, false); + recName = strBuf->getVariableText(version, false); + + DRW_DBG("\napp name: "); DRW_DBG(appName.c_str()); + DRW_DBG("\nclass name: "); DRW_DBG(className.c_str()); + DRW_DBG("\ndxf rec name: "); DRW_DBG(recName.c_str()); + wasaProxyFlag = buf->getBit(); //in dwg says wasazombie + entityFlag = buf->getBitShort(); + entityFlag = entityFlag == 0x1F2 ? 1: 0; + + DRW_DBG("\nProxy capabilities flag: "); DRW_DBG(proxyFlag); + DRW_DBG(", proxy flag (280): "); DRW_DBG(wasaProxyFlag); + DRW_DBG(", entity flag: "); DRW_DBGH(entityFlag); + + if (version > DRW::AC1015) {//2004+ + instanceCount = buf->getBitLong(); + DRW_DBG("\nInstance Count: "); DRW_DBG(instanceCount); + duint32 dwgVersion = buf->getBitLong(); + DRW_DBG("\nDWG version: "); DRW_DBG(dwgVersion); + DRW_DBG("\nmaintenance version: "); DRW_DBG(buf->getBitLong()); + DRW_DBG("\nunknown 1: "); DRW_DBG(buf->getBitLong()); + DRW_DBG("\nunknown 2: "); DRW_DBG(buf->getBitLong()); + } + DRW_DBG("\n"); + toDwgType(); + return buf->isGood(); +} + +void DRW_Class::write(dxfWriter *writer, DRW::Version ver){ + if (ver > DRW::AC1009) { + writer->writeString(0, "CLASS"); + writer->writeString(1, recName); + writer->writeString(2, className); + writer->writeString(3, appName); + writer->writeInt32(90, proxyFlag); + if (ver > DRW::AC1015) { //2004+ + writer->writeInt32(91, instanceCount); + } + writer->writeInt16(280, wasaProxyFlag); + writer->writeInt16(281, entityFlag); + } +} + +void DRW_Class::toDwgType(){ + if (recName == "LWPOLYLINE") + dwgType = 77; + else if (recName == "HATCH") + dwgType = 78; + else if (recName == "GROUP") + dwgType = 72; +/* else if (recName == "GROUP") + dwgType = 72;*/ + else if (recName == "LAYOUT") + dwgType = 82; + else if (recName == "IMAGE") + dwgType = 101; + else if (recName == "IMAGEDEF") + dwgType = 102; + else + dwgType =0; +} diff --git a/src/libs/vdxf/libdxfrw/drw_classes.h b/src/libs/vdxf/libdxfrw/drw_classes.h new file mode 100644 index 000000000..84ea32de0 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/drw_classes.h @@ -0,0 +1,58 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#ifndef DRW_CLASSES_H +#define DRW_CLASSES_H + + +#include "drw_base.h" +//#include "libdwgr.h" + +class dxfReader; +class dxfWriter; +class dwgBuffer; + +//! Class to handle classes entries +/*! +* Class to handle classes table entries +* TODO: verify the dxf read/write part +* @author Rallaz +*/ +class DRW_Class { +public: + DRW_Class() { + } + ~DRW_Class() { + } + + void parseCode(int code, dxfReader *reader); + void write(dxfWriter *writer, DRW::Version ver); + bool parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer *strBuf); + +private: + void toDwgType(); +public: + UTF8STRING recName; /*!< record name, code 1 */ + UTF8STRING className; /*!< C++ class name, code 2 */ + UTF8STRING appName; /*!< app name, code 3 */ + int proxyFlag; /*!< Proxy capabilities flag, code 90 */ + int instanceCount; /*!< number of instances for a custom class, code 91*/ + int wasaProxyFlag; /*!< proxy flag (app loaded on save), code 280 */ + int entityFlag; /*!< entity flag, code 281 (0 object, 1 entity)*/ +public: //only for read dwg + duint16 classNum; + int dwgType; +}; + +#endif + +// EOF diff --git a/src/libs/vdxf/libdxfrw/drw_entities.cpp b/src/libs/vdxf/libdxfrw/drw_entities.cpp new file mode 100644 index 000000000..0265f56c2 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/drw_entities.cpp @@ -0,0 +1,3064 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#include +#include "drw_entities.h" +#include "intern/dxfreader.h" +#include "intern/dwgbuffer.h" +#include "intern/drw_dbg.h" + + +//! Calculate arbitary axis +/*! +* Calculate arbitary axis for apply extrusions +* @author Rallaz +*/ +void DRW_Entity::calculateAxis(DRW_Coord extPoint){ + //Follow the arbitrary DXF definitions for extrusion axes. + if (fabs(extPoint.x) < 0.015625 && fabs(extPoint.y) < 0.015625) { + //If we get here, implement Ax = Wy x N where Wy is [0,1,0] per the DXF spec. + //The cross product works out to Wy.y*N.z-Wy.z*N.y, Wy.z*N.x-Wy.x*N.z, Wy.x*N.y-Wy.y*N.x + //Factoring in the fixed values for Wy gives N.z,0,-N.x + extAxisX.x = extPoint.z; + extAxisX.y = 0; + extAxisX.z = -extPoint.x; + } else { + //Otherwise, implement Ax = Wz x N where Wz is [0,0,1] per the DXF spec. + //The cross product works out to Wz.y*N.z-Wz.z*N.y, Wz.z*N.x-Wz.x*N.z, Wz.x*N.y-Wz.y*N.x + //Factoring in the fixed values for Wz gives -N.y,N.x,0. + extAxisX.x = -extPoint.y; + extAxisX.y = extPoint.x; + extAxisX.z = 0; + } + + extAxisX.unitize(); + + //Ay = N x Ax + extAxisY.x = (extPoint.y * extAxisX.z) - (extAxisX.y * extPoint.z); + extAxisY.y = (extPoint.z * extAxisX.x) - (extAxisX.z * extPoint.x); + extAxisY.z = (extPoint.x * extAxisX.y) - (extAxisX.x * extPoint.y); + + extAxisY.unitize(); +} + +//! Extrude a point using arbitary axis +/*! +* apply extrusion in a point using arbitary axis (previous calculated) +* @author Rallaz +*/ +void DRW_Entity::extrudePoint(DRW_Coord extPoint, DRW_Coord *point){ + double px, py, pz; + px = (extAxisX.x*point->x)+(extAxisY.x*point->y)+(extPoint.x*point->z); + py = (extAxisX.y*point->x)+(extAxisY.y*point->y)+(extPoint.y*point->z); + pz = (extAxisX.z*point->x)+(extAxisY.z*point->y)+(extPoint.z*point->z); + + point->x = px; + point->y = py; + point->z = pz; +} + +bool DRW_Entity::parseCode(int code, dxfReader *reader){ + switch (code) { + case 5: + handle = reader->getHandleString(); + break; + case 330: + parentHandle = reader->getHandleString(); + break; + case 8: + layer = reader->getUtf8String(); + break; + case 6: + lineType = reader->getUtf8String(); + break; + case 62: + color = reader->getInt32(); + break; + case 370: + lWeight = DRW_LW_Conv::dxfInt2lineWidth(reader->getInt32()); + break; + case 48: + ltypeScale = reader->getDouble(); + break; + case 60: + visible = reader->getBool(); + break; + case 420: + color24 = reader->getInt32(); + break; + case 430: + colorName = reader->getString(); + break; + case 67: + space = static_cast(reader->getInt32()); + break; + case 102: + parseDxfGroups(code, reader); + break; + case 1000: + case 1001: + case 1002: + case 1003: + case 1004: + case 1005: + extData.push_back(new DRW_Variant(code, reader->getString())); + break; + case 1010: + case 1011: + case 1012: + case 1013: + curr = new DRW_Variant(); + curr->addCoord(); + curr->setCoordX(reader->getDouble()); + curr->code = code; + extData.push_back(curr); + break; + case 1020: + case 1021: + case 1022: + case 1023: + if (curr) + curr->setCoordY(reader->getDouble()); + break; + case 1030: + case 1031: + case 1032: + case 1033: + if (curr) + curr->setCoordZ(reader->getDouble()); + curr=NULL; + break; + case 1040: + case 1041: + case 1042: + extData.push_back(new DRW_Variant(code, reader->getDouble() )); + break; + case 1070: + case 1071: + extData.push_back(new DRW_Variant(code, reader->getInt32() )); + break; + default: + break; + } + return true; +} + +//parses dxf 102 groups to read entity +bool DRW_Entity::parseDxfGroups(int code, dxfReader *reader){ + std::list ls; + DRW_Variant curr; + int nc; + std::string appName= reader->getString(); + if (!appName.empty() && appName.at(0)== '{'){ + curr.addString(appName.substr(1, (int) appName.size()-1)); + curr.code = code; + ls.push_back(curr); + while (code !=102 && appName.at(0)== '}'){ + reader->readRec(&nc); + curr.code = code; + if (code == 330 || code == 360) + curr.addInt(reader->getHandleString()); + else { + switch (reader->type) { + case dxfReader::STRING: + curr.addString(reader->getString()); + break; + case dxfReader::INT32: + case dxfReader::INT64: + curr.addInt(reader->getInt32()); + break; + case dxfReader::DOUBLE: + curr.addDouble(reader->getDouble()); + break; + case dxfReader::BOOL: + curr.addInt(reader->getInt32()); + break; + default: + break; + } + } + ls.push_back(curr); + } + } + + appData.push_back(ls); + return true; +} + +bool DRW_Entity::parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer* strBuf, duint32 bs){ + objSize=0; + DRW_DBG("\n***************************** parsing entity *********************************************\n"); + oType = buf->getObjType(version); + DRW_DBG("Object type: "); DRW_DBG(oType); DRW_DBG(", "); DRW_DBGH(oType); + + if (version > DRW::AC1014 && version < DRW::AC1024) {//2000 & 2004 + objSize = buf->getRawLong32(); //RL 32bits object size in bits + DRW_DBG(" Object size: "); DRW_DBG(objSize); DRW_DBG("\n"); + } + if (version > DRW::AC1021) {//2010+ + duint32 ms = buf->size(); + objSize = ms*8 - bs; + DRW_DBG(" Object size: "); DRW_DBG(objSize); DRW_DBG("\n"); + } + + if (strBuf != NULL && version > DRW::AC1018) {//2007+ + strBuf->moveBitPos(objSize-1); + DRW_DBG(" strBuf strbit pos 2007: "); DRW_DBG(strBuf->getPosition()); DRW_DBG(" strBuf bpos 2007: "); DRW_DBG(strBuf->getBitPos()); DRW_DBG("\n"); + if (strBuf->getBit() == 1){ + DRW_DBG("DRW_TableEntry::parseDwg string bit is 1\n"); + strBuf->moveBitPos(-17); + duint16 strDataSize = strBuf->getRawShort16(); + DRW_DBG("\nDRW_TableEntry::parseDwg string strDataSize: "); DRW_DBGH(strDataSize); DRW_DBG("\n"); + if ( (strDataSize& 0x8000) == 0x8000){ + DRW_DBG("\nDRW_TableEntry::parseDwg string 0x8000 bit is set"); + strBuf->moveBitPos(-33);//RLZ pending to verify + duint16 hiSize = strBuf->getRawShort16(); + strDataSize = ((strDataSize&0x7fff) | (hiSize<<15)); + } + strBuf->moveBitPos( -strDataSize -16); //-14 + DRW_DBG("strBuf start strDataSize pos 2007: "); DRW_DBG(strBuf->getPosition()); DRW_DBG(" strBuf bpos 2007: "); DRW_DBG(strBuf->getBitPos()); DRW_DBG("\n"); + } else + DRW_DBG("\nDRW_TableEntry::parseDwg string bit is 0"); + DRW_DBG("strBuf start pos 2007: "); DRW_DBG(strBuf->getPosition()); DRW_DBG(" strBuf bpos 2007: "); DRW_DBG(strBuf->getBitPos()); DRW_DBG("\n"); + } + + dwgHandle ho = buf->getHandle(); + handle = ho.ref; + DRW_DBG("Entity Handle: "); DRW_DBGHL(ho.code, ho.size, ho.ref); + dint16 extDataSize = buf->getBitShort(); //BS + DRW_DBG(" ext data size: "); DRW_DBG(extDataSize); + while (extDataSize>0 && buf->isGood()) { + /* RLZ: TODO */ + dwgHandle ah = buf->getHandle(); + DRW_DBG("App Handle: "); DRW_DBGHL(ah.code, ah.size, ah.ref); + duint8 *tmpExtData = new duint8[extDataSize]; + buf->getBytes(tmpExtData, extDataSize); + dwgBuffer tmpExtDataBuf(tmpExtData, extDataSize, buf->decoder); + + duint8 dxfCode = tmpExtDataBuf.getRawChar8(); + DRW_DBG(" dxfCode: "); DRW_DBG(dxfCode); + switch (dxfCode){ + case 0:{ + duint8 strLength = tmpExtDataBuf.getRawChar8(); + DRW_DBG(" strLength: "); DRW_DBG(strLength); + duint16 cp = tmpExtDataBuf.getBERawShort16(); + DRW_DBG(" str codepage: "); DRW_DBG(cp); + for (int i=0;i< strLength+1;i++) {//string length + null terminating char + duint8 dxfChar = tmpExtDataBuf.getRawChar8(); + DRW_DBG(" dxfChar: "); DRW_DBG(dxfChar); + } + break; + } + default: + /* RLZ: TODO */ + break; + } + delete[]tmpExtData; + extDataSize = buf->getBitShort(); //BS + DRW_DBG(" ext data size: "); DRW_DBG(extDataSize); + } //end parsing extData (EED) + duint8 graphFlag = buf->getBit(); //B + DRW_DBG(" graphFlag: "); DRW_DBG(graphFlag); DRW_DBG("\n"); + if (graphFlag) { + duint32 graphDataSize = buf->getRawLong32(); //RL 32bits + DRW_DBG("graphData in bytes: "); DRW_DBG(graphDataSize); DRW_DBG("\n"); +// RLZ: TODO + //skip graphData bytes + duint8 *tmpGraphData = new duint8[graphDataSize]; + buf->getBytes(tmpGraphData, graphDataSize); + dwgBuffer tmpGraphDataBuf(tmpGraphData, graphDataSize, buf->decoder); + DRW_DBG("graph data remaining bytes: "); DRW_DBG(tmpGraphDataBuf.numRemainingBytes()); DRW_DBG("\n"); + delete[]tmpGraphData; + } + if (version < DRW::AC1015) {//14- + objSize = buf->getRawLong32(); //RL 32bits object size in bits + DRW_DBG(" Object size in bits: "); DRW_DBG(objSize); DRW_DBG("\n"); + } + + duint8 entmode = buf->get2Bits(); //BB + if (entmode == 0) + ownerHandle= true; +// entmode = 2; + else if(entmode ==2) + entmode = 0; + space = (DRW::Space)entmode; //RLZ verify cast values + DRW_DBG("entmode: "); DRW_DBG(entmode); + numReactors = buf->getBitShort(); //BS + DRW_DBG(", numReactors: "); DRW_DBG(numReactors); + + if (version < DRW::AC1015) {//14- + if(buf->getBit()) {//is bylayer line type + lineType = "BYLAYER"; + ltFlags = 0; + } else { + lineType = ""; + ltFlags = 3; + } + DRW_DBG(" lineType: "); DRW_DBG(lineType.c_str()); + DRW_DBG(" ltFlags: "); DRW_DBG(ltFlags); + } + if (version > DRW::AC1015) {//2004+ + xDictFlag = buf->getBit(); + DRW_DBG(" xDictFlag: "); DRW_DBG(xDictFlag); DRW_DBG("\n"); + } + + if (version > DRW::AC1024 || version < DRW::AC1018) { + haveNextLinks = buf->getBit(); //aka nolinks //B + DRW_DBG(", haveNextLinks (0 yes, 1 prev next): "); DRW_DBG(haveNextLinks); DRW_DBG("\n"); + } else { + haveNextLinks = 1; //aka nolinks //B + DRW_DBG(", haveNextLinks (forced): "); DRW_DBG(haveNextLinks); DRW_DBG("\n"); + } +//ENC color + color = buf->getEnColor(version); //BS or CMC //ok for R14 or negate + ltypeScale = buf->getBitDouble(); //BD + DRW_DBG(" entity color: "); DRW_DBG(color); + DRW_DBG(" ltScale: "); DRW_DBG(ltypeScale); DRW_DBG("\n"); + if (version > DRW::AC1014) {//2000+ + UTF8STRING plotStyleName; + for (duint8 i = 0; i<2;++i) { //two flags in one + plotFlags = buf->get2Bits(); //BB + if (plotFlags == 1) + plotStyleName = "byblock"; + else if (plotFlags == 2) + plotStyleName = "continuous"; + else if (plotFlags == 0) + plotStyleName = "bylayer"; + else //handle at end + plotStyleName = ""; + if (i == 0) { + ltFlags = plotFlags; + lineType = plotStyleName; //RLZ: howto solve? if needed plotStyleName; + DRW_DBG("ltFlags: "); DRW_DBG(ltFlags); + DRW_DBG(" lineType: "); DRW_DBG(lineType.c_str()); + } else { + DRW_DBG(", plotFlags: "); DRW_DBG(plotFlags); + } + } + } + if (version > DRW::AC1018) {//2007+ + materialFlag = buf->get2Bits(); //BB + DRW_DBG("materialFlag: "); DRW_DBG(materialFlag); + shadowFlag = buf->getRawChar8(); //RC + DRW_DBG("shadowFlag: "); DRW_DBG(shadowFlag); DRW_DBG("\n"); + } + if (version > DRW::AC1021) {//2010+ + duint8 visualFlags = buf->get2Bits(); //full & face visual style + DRW_DBG("shadowFlag 2: "); DRW_DBG(visualFlags); DRW_DBG("\n"); + duint8 unk = buf->getBit(); //edge visual style + DRW_DBG("unknown bit: "); DRW_DBG(unk); DRW_DBG("\n"); + } + dint16 invisibleFlag = buf->getBitShort(); //BS + DRW_DBG(" invisibleFlag: "); DRW_DBG(invisibleFlag); + if (version > DRW::AC1014) {//2000+ + lWeight = DRW_LW_Conv::dwgInt2lineWidth( buf->getRawChar8() ); //RC + DRW_DBG(" lwFlag (lWeight): "); DRW_DBG(lWeight); DRW_DBG("\n"); + } + //Only in blocks ???????? +// if (version > DRW::AC1018) {//2007+ +// duint8 unk = buf->getBit(); +// DRW_DBG("unknown bit: "); DRW_DBG(unk); DRW_DBG("\n"); +// } + return buf->isGood(); +} + +bool DRW_Entity::parseDwgEntHandle(DRW::Version version, dwgBuffer *buf){ + if (version > DRW::AC1018) {//2007+ skip string area + buf->setPosition(objSize >> 3); + buf->setBitPos(objSize & 7); + } + + if(ownerHandle){//entity are in block or in a polyline + dwgHandle ownerH = buf->getOffsetHandle(handle); + DRW_DBG("owner (parent) Handle: "); DRW_DBGHL(ownerH.code, ownerH.size, ownerH.ref); DRW_DBG("\n"); + DRW_DBG(" Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + parentHandle = ownerH.ref; + DRW_DBG("Block (parent) Handle: "); DRW_DBGHL(ownerH.code, ownerH.size, parentHandle); DRW_DBG("\n"); + } else + DRW_DBG("NO Block (parent) Handle\n"); + + DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + for (int i=0; i< numReactors;++i) { + dwgHandle reactorsH = buf->getHandle(); + DRW_DBG(" reactorsH control Handle: "); DRW_DBGHL(reactorsH.code, reactorsH.size, reactorsH.ref); DRW_DBG("\n"); + } + if (xDictFlag !=1){//linetype in 2004 seems not have XDicObjH or NULL handle + dwgHandle XDicObjH = buf->getHandle(); + DRW_DBG(" XDicObj control Handle: "); DRW_DBGHL(XDicObjH.code, XDicObjH.size, XDicObjH.ref); DRW_DBG("\n"); + } + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + + if (version < DRW::AC1015) {//R14- + //layer handle + layerH = buf->getOffsetHandle(handle); + DRW_DBG(" layer Handle: "); DRW_DBGHL(layerH.code, layerH.size, layerH.ref); DRW_DBG("\n"); + DRW_DBG(" Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + //lineType handle + if(ltFlags == 3){ + lTypeH = buf->getOffsetHandle(handle); + DRW_DBG("linetype Handle: "); DRW_DBGHL(lTypeH.code, lTypeH.size, lTypeH.ref); DRW_DBG("\n"); + DRW_DBG(" Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + } + } + if (version < DRW::AC1018) {//2000+ + if (haveNextLinks == 0) { + dwgHandle nextLinkH = buf->getOffsetHandle(handle); + DRW_DBG(" prev nextLinkers Handle: "); DRW_DBGHL(nextLinkH.code, nextLinkH.size, nextLinkH.ref); DRW_DBG("\n"); + DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + prevEntLink = nextLinkH.ref; + nextLinkH = buf->getOffsetHandle(handle); + DRW_DBG(" next nextLinkers Handle: "); DRW_DBGHL(nextLinkH.code, nextLinkH.size, nextLinkH.ref); DRW_DBG("\n"); + DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + nextEntLink = nextLinkH.ref; + } else { + nextEntLink = handle+1; + prevEntLink = handle-1; + } + } + if (version > DRW::AC1015) {//2004+ + //Parses Bookcolor handle + } + if (version > DRW::AC1014) {//2000+ + //layer handle + layerH = buf->getOffsetHandle(handle); + DRW_DBG(" layer Handle: "); DRW_DBGHL(layerH.code, layerH.size, layerH.ref); DRW_DBG("\n"); + DRW_DBG(" Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + //lineType handle + if(ltFlags == 3){ + lTypeH = buf->getOffsetHandle(handle); + DRW_DBG("linetype Handle: "); DRW_DBGHL(lTypeH.code, lTypeH.size, lTypeH.ref); DRW_DBG("\n"); + DRW_DBG(" Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + } + } + if (version > DRW::AC1014) {//2000+ + if (version > DRW::AC1018) {//2007+ + if (materialFlag == 3) { + dwgHandle materialH = buf->getOffsetHandle(handle); + DRW_DBG(" material Handle: "); DRW_DBGHL(materialH.code, materialH.size, materialH.ref); DRW_DBG("\n"); + DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + } + if (shadowFlag == 3) { + dwgHandle shadowH = buf->getOffsetHandle(handle); + DRW_DBG(" shadow Handle: "); DRW_DBGHL(shadowH.code, shadowH.size, shadowH.ref); DRW_DBG("\n"); + DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + } + } + if (plotFlags == 3) { + dwgHandle plotStyleH = buf->getOffsetHandle(handle); + DRW_DBG(" plot style Handle: "); DRW_DBGHL(plotStyleH.code, plotStyleH.size, plotStyleH.ref); DRW_DBG("\n"); + DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + } + } + DRW_DBG("\n DRW_Entity::parseDwgEntHandle Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + return buf->isGood(); +} + +void DRW_Point::parseCode(int code, dxfReader *reader){ + switch (code) { + case 10: + basePoint.x = reader->getDouble(); + break; + case 20: + basePoint.y = reader->getDouble(); + break; + case 30: + basePoint.z = reader->getDouble(); + break; + case 39: + thickness = reader->getDouble(); + break; + case 210: + haveExtrusion = true; + extPoint.x = reader->getDouble(); + break; + case 220: + extPoint.y = reader->getDouble(); + break; + case 230: + extPoint.z = reader->getDouble(); + break; + default: + DRW_Entity::parseCode(code, reader); + break; + } +} + +bool DRW_Point::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + bool ret = DRW_Entity::parseDwg(version, buf, NULL, bs); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing point *********************************************\n"); + + basePoint.x = buf->getBitDouble(); + basePoint.y = buf->getBitDouble(); + basePoint.z = buf->getBitDouble(); + DRW_DBG("point: "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z); + thickness = buf->getThickness(version > DRW::AC1014);//BD + DRW_DBG("\nthickness: "); DRW_DBG(thickness); + extPoint = buf->getExtrusion(version > DRW::AC1014); + DRW_DBG(", Extrusion: "); DRW_DBGPT(extPoint.x, extPoint.y, extPoint.z); + + double x_axis = buf->getBitDouble();//BD + DRW_DBG("\n x_axis: ");DRW_DBG(x_axis);DRW_DBG("\n"); + ret = DRW_Entity::parseDwgEntHandle(version, buf); + if (!ret) + return ret; + // RS crc; //RS */ + + return buf->isGood(); +} + +void DRW_Line::parseCode(int code, dxfReader *reader){ + switch (code) { + case 11: + secPoint.x = reader->getDouble(); + break; + case 21: + secPoint.y = reader->getDouble(); + break; + case 31: + secPoint.z = reader->getDouble(); + break; + default: + DRW_Point::parseCode(code, reader); + break; + } +} + +bool DRW_Line::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + bool ret = DRW_Entity::parseDwg(version, buf, NULL, bs); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing line *********************************************\n"); + + if (version < DRW::AC1015) {//14- + basePoint.x = buf->getBitDouble(); + basePoint.y = buf->getBitDouble(); + basePoint.z = buf->getBitDouble(); + secPoint.x = buf->getBitDouble(); + secPoint.y = buf->getBitDouble(); + secPoint.z = buf->getBitDouble(); + } + if (version > DRW::AC1014) {//2000+ + bool zIsZero = buf->getBit(); //B + basePoint.x = buf->getRawDouble();//RD + secPoint.x = buf->getDefaultDouble(basePoint.x);//DD + basePoint.y = buf->getRawDouble();//RD + secPoint.y = buf->getDefaultDouble(basePoint.y);//DD + if (!zIsZero) { + basePoint.z = buf->getRawDouble();//RD + secPoint.z = buf->getDefaultDouble(basePoint.z);//DD + } + } + DRW_DBG("start point: "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z); + DRW_DBG("\nend point: "); DRW_DBGPT(secPoint.x, secPoint.y, secPoint.z); + thickness = buf->getThickness(version > DRW::AC1014);//BD + DRW_DBG("\nthickness: "); DRW_DBG(thickness); + extPoint = buf->getExtrusion(version > DRW::AC1014); + DRW_DBG(", Extrusion: "); DRW_DBGPT(extPoint.x, extPoint.y, extPoint.z);DRW_DBG("\n"); + ret = DRW_Entity::parseDwgEntHandle(version, buf); + if (!ret) + return ret; +// RS crc; //RS */ + return buf->isGood(); +} + +bool DRW_Ray::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + bool ret = DRW_Entity::parseDwg(version, buf, NULL, bs); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing ray/xline *********************************************\n"); + basePoint.x = buf->getBitDouble(); + basePoint.y = buf->getBitDouble(); + basePoint.z = buf->getBitDouble(); + secPoint.x = buf->getBitDouble(); + secPoint.y = buf->getBitDouble(); + secPoint.z = buf->getBitDouble(); + DRW_DBG("start point: "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z); + DRW_DBG("\nvector: "); DRW_DBGPT(secPoint.x, secPoint.y, secPoint.z); + ret = DRW_Entity::parseDwgEntHandle(version, buf); + if (!ret) + return ret; +// RS crc; //RS */ + return buf->isGood(); +} + +void DRW_Circle::applyExtrusion(){ + if (haveExtrusion) { + //NOTE: Commenting these out causes the the arcs being tested to be located + //on the other side of the y axis (all x dimensions are negated). + calculateAxis(extPoint); + extrudePoint(extPoint, &basePoint); + } +} + +void DRW_Circle::parseCode(int code, dxfReader *reader){ + switch (code) { + case 40: + radious = reader->getDouble(); + break; + default: + DRW_Point::parseCode(code, reader); + break; + } +} + +bool DRW_Circle::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + bool ret = DRW_Entity::parseDwg(version, buf, NULL, bs); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing circle *********************************************\n"); + + basePoint.x = buf->getBitDouble(); + basePoint.y = buf->getBitDouble(); + basePoint.z = buf->getBitDouble(); + DRW_DBG("center: "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z); + radious = buf->getBitDouble(); + DRW_DBG("\nradius: "); DRW_DBG(radious); + + thickness = buf->getThickness(version > DRW::AC1014); + DRW_DBG(" thickness: "); DRW_DBG(thickness); + extPoint = buf->getExtrusion(version > DRW::AC1014); + DRW_DBG("\nextrusion: "); DRW_DBGPT(extPoint.x, extPoint.y, extPoint.z); DRW_DBG("\n"); + + ret = DRW_Entity::parseDwgEntHandle(version, buf); + if (!ret) + return ret; +// RS crc; //RS */ + return buf->isGood(); +} + +void DRW_Arc::applyExtrusion(){ + DRW_Circle::applyExtrusion(); + + if(haveExtrusion){ + // If the extrusion vector has a z value less than 0, the angles for the arc + // have to be mirrored since DXF files use the right hand rule. + // Note that the following code only handles the special case where there is a 2D + // drawing with the z axis heading into the paper (or rather screen). An arbitrary + // extrusion axis (with x and y values greater than 1/64) may still have issues. + if (fabs(extPoint.x) < 0.015625 && fabs(extPoint.y) < 0.015625 && extPoint.z < 0.0) { + staangle=M_PI-staangle; + endangle=M_PI-endangle; + + double temp = staangle; + staangle=endangle; + endangle=temp; + } + } +} + +void DRW_Arc::parseCode(int code, dxfReader *reader){ + switch (code) { + case 50: + staangle = reader->getDouble()/ ARAD; + break; + case 51: + endangle = reader->getDouble()/ ARAD; + break; + default: + DRW_Circle::parseCode(code, reader); + break; + } +} + +bool DRW_Arc::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + bool ret = DRW_Entity::parseDwg(version, buf, NULL, bs); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing circle arc *********************************************\n"); + + basePoint.x = buf->getBitDouble(); + basePoint.y = buf->getBitDouble(); + basePoint.z = buf->getBitDouble(); + DRW_DBG("center point: "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z); + + radious = buf->getBitDouble(); + DRW_DBG("\nradius: "); DRW_DBG(radious); + thickness = buf->getThickness(version > DRW::AC1014); + DRW_DBG(" thickness: "); DRW_DBG(thickness); + extPoint = buf->getExtrusion(version > DRW::AC1014); + DRW_DBG("\nextrusion: "); DRW_DBGPT(extPoint.x, extPoint.y, extPoint.z); + staangle = buf->getBitDouble(); + DRW_DBG("\nstart angle: "); DRW_DBG(staangle); + endangle = buf->getBitDouble(); + DRW_DBG(" end angle: "); DRW_DBG(endangle); DRW_DBG("\n"); + ret = DRW_Entity::parseDwgEntHandle(version, buf); + if (!ret) + return ret; + return buf->isGood(); +} + +void DRW_Ellipse::parseCode(int code, dxfReader *reader){ + switch (code) { + case 40: + ratio = reader->getDouble(); + break; + case 41: + staparam = reader->getDouble(); + break; + case 42: + endparam = reader->getDouble(); + break; + default: + DRW_Line::parseCode(code, reader); + break; + } +} + +void DRW_Ellipse::applyExtrusion(){ + if (haveExtrusion) { + calculateAxis(extPoint); + extrudePoint(extPoint, &secPoint); + double intialparam = staparam; + if (extPoint.z < 0.){ + staparam = M_PIx2 - endparam; + endparam = M_PIx2 - intialparam; + } + } +} + +//if ratio > 1 minor axis are greather than major axis, correct it +void DRW_Ellipse::correctAxis(){ + bool complete = false; + if (staparam == endparam) { + staparam = 0.0; + endparam = M_PIx2; //2*M_PI; + complete = true; + } + if (ratio > 1){ + if ( fabs(endparam - staparam - M_PIx2) < 1.0e-10) + complete = true; + double incX = secPoint.x; + secPoint.x = -(secPoint.y * ratio); + secPoint.y = incX*ratio; + ratio = 1/ratio; + if (!complete){ + if (staparam < M_PI_2) + staparam += M_PI *2; + if (endparam < M_PI_2) + endparam += M_PI *2; + endparam -= M_PI_2; + staparam -= M_PI_2; + } + } +} + +bool DRW_Ellipse::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + bool ret = DRW_Entity::parseDwg(version, buf, NULL, bs); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing ellipse *********************************************\n"); + + basePoint =buf->get3BitDouble(); + DRW_DBG("center: "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z); + secPoint =buf->get3BitDouble(); + DRW_DBG(", axis: "); DRW_DBGPT(secPoint.x, secPoint.y, secPoint.z); DRW_DBG("\n"); + extPoint =buf->get3BitDouble(); + DRW_DBG("Extrusion: "); DRW_DBGPT(extPoint.x, extPoint.y, extPoint.z); + ratio = buf->getBitDouble();//BD + DRW_DBG("\nratio: "); DRW_DBG(ratio); + staparam = buf->getBitDouble();//BD + DRW_DBG(" start param: "); DRW_DBG(staparam); + endparam = buf->getBitDouble();//BD + DRW_DBG(" end param: "); DRW_DBG(endparam); DRW_DBG("\n"); + + ret = DRW_Entity::parseDwgEntHandle(version, buf); + if (!ret) + return ret; +// RS crc; //RS */ + return buf->isGood(); +} + +//parts are the number of vertex to split polyline, default 128 +void DRW_Ellipse::toPolyline(DRW_Polyline *pol, int parts){ + double radMajor, radMinor, cosRot, sinRot, incAngle, curAngle; + double cosCurr, sinCurr; + radMajor = sqrt(secPoint.x*secPoint.x + secPoint.y*secPoint.y); + radMinor = radMajor*ratio; + //calculate sin & cos of included angle + incAngle = atan2(secPoint.y, secPoint.x); + cosRot = cos(incAngle); + sinRot = sin(incAngle); + incAngle = M_PIx2 / parts; + curAngle = staparam; + int i = static_cast(curAngle / incAngle); + do { + if (curAngle > endparam) { + curAngle = endparam; + i = parts+2; + } + cosCurr = cos(curAngle); + sinCurr = sin(curAngle); + double x = basePoint.x + (cosCurr*cosRot*radMajor) - (sinCurr*sinRot*radMinor); + double y = basePoint.y + (cosCurr*sinRot*radMajor) + (sinCurr*cosRot*radMinor); + pol->addVertex( DRW_Vertex(x, y, 0.0, 0.0)); + curAngle = (++i)*incAngle; + } while (iflags = 1; + } + pol->layer = this->layer; + pol->lineType = this->lineType; + pol->color = this->color; + pol->lWeight = this->lWeight; + pol->extPoint = this->extPoint; +} + +void DRW_Trace::applyExtrusion(){ + if (haveExtrusion) { + calculateAxis(extPoint); + extrudePoint(extPoint, &basePoint); + extrudePoint(extPoint, &secPoint); + extrudePoint(extPoint, &thirdPoint); + extrudePoint(extPoint, &fourPoint); + } +} + +void DRW_Trace::parseCode(int code, dxfReader *reader){ + switch (code) { + case 12: + thirdPoint.x = reader->getDouble(); + break; + case 22: + thirdPoint.y = reader->getDouble(); + break; + case 32: + thirdPoint.z = reader->getDouble(); + break; + case 13: + fourPoint.x = reader->getDouble(); + break; + case 23: + fourPoint.y = reader->getDouble(); + break; + case 33: + fourPoint.z = reader->getDouble(); + break; + default: + DRW_Line::parseCode(code, reader); + break; + } +} + +bool DRW_Trace::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + bool ret = DRW_Entity::parseDwg(version, buf, NULL, bs); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing Trace *********************************************\n"); + + thickness = buf->getThickness(version>DRW::AC1014); + basePoint.z = buf->getBitDouble(); + basePoint.x = buf->getRawDouble(); + basePoint.y = buf->getRawDouble(); + secPoint.x = buf->getRawDouble(); + secPoint.y = buf->getRawDouble(); + secPoint.z = basePoint.z; + thirdPoint.x = buf->getRawDouble(); + thirdPoint.y = buf->getRawDouble(); + thirdPoint.z = basePoint.z; + fourPoint.x = buf->getRawDouble(); + fourPoint.y = buf->getRawDouble(); + fourPoint.z = basePoint.z; + extPoint = buf->getExtrusion(version>DRW::AC1014); + + DRW_DBG(" - base "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z); + DRW_DBG("\n - sec "); DRW_DBGPT(secPoint.x, secPoint.y, secPoint.z); + DRW_DBG("\n - third "); DRW_DBGPT(thirdPoint.x, thirdPoint.y, thirdPoint.z); + DRW_DBG("\n - fourth "); DRW_DBGPT(fourPoint.x, fourPoint.y, fourPoint.z); + DRW_DBG("\n - extrusion: "); DRW_DBGPT(extPoint.x, extPoint.y, extPoint.z); + DRW_DBG("\n - thickness: "); DRW_DBG(thickness); DRW_DBG("\n"); + + /* Common Entity Handle Data */ + ret = DRW_Entity::parseDwgEntHandle(version, buf); + if (!ret) + return ret; + + /* CRC X --- */ + return buf->isGood(); +} + + +void DRW_Solid::parseCode(int code, dxfReader *reader){ + DRW_Trace::parseCode(code, reader); +} + +bool DRW_Solid::parseDwg(DRW::Version v, dwgBuffer *buf, duint32 bs){ + DRW_DBG("\n***************************** parsing Solid *********************************************\n"); + return DRW_Trace::parseDwg(v, buf, bs); +} + +void DRW_3Dface::parseCode(int code, dxfReader *reader){ + switch (code) { + case 70: + invisibleflag = reader->getInt32(); + break; + default: + DRW_Trace::parseCode(code, reader); + break; + } +} + +bool DRW_3Dface::parseDwg(DRW::Version v, dwgBuffer *buf, duint32 bs){ + bool ret = DRW_Entity::parseDwg(v, buf, NULL, bs); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing 3Dface *********************************************\n"); + + if ( v < DRW::AC1015 ) {// R13 & R14 + basePoint.x = buf->getBitDouble(); + basePoint.y = buf->getBitDouble(); + basePoint.z = buf->getBitDouble(); + secPoint.x = buf->getBitDouble(); + secPoint.y = buf->getBitDouble(); + secPoint.z = buf->getBitDouble(); + thirdPoint.x = buf->getBitDouble(); + thirdPoint.y = buf->getBitDouble(); + thirdPoint.z = buf->getBitDouble(); + fourPoint.x = buf->getBitDouble(); + fourPoint.y = buf->getBitDouble(); + fourPoint.z = buf->getBitDouble(); + invisibleflag = buf->getBitShort(); + } else { // 2000+ + bool has_no_flag = buf->getBit(); + bool z_is_zero = buf->getBit(); + basePoint.x = buf->getRawDouble(); + basePoint.y = buf->getRawDouble(); + basePoint.z = z_is_zero ? 0.0 : buf->getRawDouble(); + secPoint.x = buf->getDefaultDouble(basePoint.x); + secPoint.y = buf->getDefaultDouble(basePoint.y); + secPoint.z = buf->getDefaultDouble(basePoint.z); + thirdPoint.x = buf->getDefaultDouble(secPoint.x); + thirdPoint.y = buf->getDefaultDouble(secPoint.y); + thirdPoint.z = buf->getDefaultDouble(secPoint.z); + fourPoint.x = buf->getDefaultDouble(thirdPoint.x); + fourPoint.y = buf->getDefaultDouble(thirdPoint.y); + fourPoint.z = buf->getDefaultDouble(thirdPoint.z); + invisibleflag = has_no_flag ? (int)NoEdge : buf->getBitShort(); + } + drw_assert(invisibleflag>=NoEdge); + drw_assert(invisibleflag<=AllEdges); + + DRW_DBG(" - base "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z); DRW_DBG("\n"); + DRW_DBG(" - sec "); DRW_DBGPT(secPoint.x, secPoint.y, secPoint.z); DRW_DBG("\n"); + DRW_DBG(" - third "); DRW_DBGPT(thirdPoint.x, thirdPoint.y, thirdPoint.z); DRW_DBG("\n"); + DRW_DBG(" - fourth "); DRW_DBGPT(fourPoint.x, fourPoint.y, fourPoint.z); DRW_DBG("\n"); + DRW_DBG(" - Invisibility mask: "); DRW_DBG(invisibleflag); DRW_DBG("\n"); + + /* Common Entity Handle Data */ + ret = DRW_Entity::parseDwgEntHandle(v, buf); + if (!ret) + return ret; + return buf->isGood(); +} + +void DRW_Block::parseCode(int code, dxfReader *reader){ + switch (code) { + case 2: + name = reader->getUtf8String(); + break; + case 70: + flags = reader->getInt32(); + break; + default: + DRW_Point::parseCode(code, reader); + break; + } +} + +bool DRW_Block::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dwgBuffer sBuff = *buf; + dwgBuffer *sBuf = buf; + if (version > DRW::AC1018) {//2007+ + sBuf = &sBuff; //separate buffer for strings + } + bool ret = DRW_Entity::parseDwg(version, buf, sBuf, bs); + if (!ret) + return ret; + if (!isEnd){ + DRW_DBG("\n***************************** parsing block *********************************************\n"); + name = sBuf->getVariableText(version, false); + DRW_DBG("Block name: "); DRW_DBG(name.c_str()); DRW_DBG("\n"); + } else { + DRW_DBG("\n***************************** parsing end block *********************************************\n"); + } + if (version > DRW::AC1018) {//2007+ + duint8 unk = buf->getBit(); + DRW_DBG("unknown bit: "); DRW_DBG(unk); DRW_DBG("\n"); + } +// X handleAssoc; //X + ret = DRW_Entity::parseDwgEntHandle(version, buf); + if (!ret) + return ret; +// RS crc; //RS */ + return buf->isGood(); +} + +void DRW_Insert::parseCode(int code, dxfReader *reader){ + switch (code) { + case 2: + name = reader->getUtf8String(); + break; + case 41: + xscale = reader->getDouble(); + break; + case 42: + yscale = reader->getDouble(); + break; + case 43: + zscale = reader->getDouble(); + break; + case 50: + angle = reader->getDouble(); + angle = angle/ARAD; //convert to radian + break; + case 70: + colcount = reader->getInt32(); + break; + case 71: + rowcount = reader->getInt32(); + break; + case 44: + colspace = reader->getDouble(); + break; + case 45: + rowspace = reader->getDouble(); + break; + default: + DRW_Point::parseCode(code, reader); + break; + } +} + +bool DRW_Insert::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dint32 objCount = 0; + bool ret = DRW_Entity::parseDwg(version, buf, NULL, bs); + if (!ret) + return ret; + DRW_DBG("\n************************** parsing insert/minsert *****************************************\n"); + basePoint.x = buf->getBitDouble(); + basePoint.y = buf->getBitDouble(); + basePoint.z = buf->getBitDouble(); + DRW_DBG("insertion point: "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z); DRW_DBG("\n"); + if (version < DRW::AC1015) {//14- + xscale = buf->getBitDouble(); + yscale = buf->getBitDouble(); + zscale = buf->getBitDouble(); + } else { + duint8 dataFlags = buf->get2Bits(); + if (dataFlags == 3){ + //none default value 1,1,1 + } else if (dataFlags == 1){ //x default value 1, y & z can be x value + yscale = buf->getDefaultDouble(xscale); + zscale = buf->getDefaultDouble(xscale); + } else if (dataFlags == 2){ + xscale = buf->getRawDouble(); + yscale = zscale = xscale; + } else { //dataFlags == 0 + xscale = buf->getRawDouble(); + yscale = buf->getDefaultDouble(xscale); + zscale = buf->getDefaultDouble(xscale); + } + } + angle = buf->getBitDouble(); + DRW_DBG("scale : "); DRW_DBGPT(xscale, yscale, zscale); DRW_DBG(", angle: "); DRW_DBG(angle); + extPoint = buf->getExtrusion(false); //3BD R14 style + DRW_DBG("\nextrusion: "); DRW_DBGPT(extPoint.x, extPoint.y, extPoint.z); + + bool hasAttrib = buf->getBit(); + DRW_DBG(" has Attrib: "); DRW_DBG(hasAttrib); + + if (hasAttrib && version > DRW::AC1015) {//2004+ + objCount = buf->getBitLong(); + DRW_UNUSED(objCount); + DRW_DBG(" objCount: "); DRW_DBG(objCount); DRW_DBG("\n"); + } + if (oType == 8) {//entity are minsert + colcount = buf->getBitShort(); + rowcount = buf->getBitShort(); + colspace = buf->getBitDouble(); + rowspace = buf->getBitDouble(); + } + DRW_DBG(" Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + ret = DRW_Entity::parseDwgEntHandle(version, buf); + blockRecH = buf->getHandle(); /* H 2 BLOCK HEADER (hard pointer) */ + DRW_DBG("BLOCK HEADER Handle: "); DRW_DBGHL(blockRecH.code, blockRecH.size, blockRecH.ref); DRW_DBG("\n"); + DRW_DBG(" Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + + /*attribs follows*/ + if (hasAttrib) { + if (version < DRW::AC1018) {//2000- + dwgHandle attH = buf->getHandle(); /* H 2 BLOCK HEADER (hard pointer) */ + DRW_DBG("first attrib Handle: "); DRW_DBGHL(attH.code, attH.size, attH.ref); DRW_DBG("\n"); + attH = buf->getHandle(); /* H 2 BLOCK HEADER (hard pointer) */ + DRW_DBG("second attrib Handle: "); DRW_DBGHL(attH.code, attH.size, attH.ref); DRW_DBG("\n"); + } else { + for (duint8 i=0; i< objCount; ++i){ + dwgHandle attH = buf->getHandle(); /* H 2 BLOCK HEADER (hard pointer) */ + DRW_DBG("attrib Handle #"); DRW_DBG(i); DRW_DBG(": "); DRW_DBGHL(attH.code, attH.size, attH.ref); DRW_DBG("\n"); + } + } + seqendH = buf->getHandle(); /* H 2 BLOCK HEADER (hard pointer) */ + DRW_DBG("seqendH Handle: "); DRW_DBGHL(seqendH.code, seqendH.size, seqendH.ref); DRW_DBG("\n"); + } + DRW_DBG(" Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + + if (!ret) + return ret; +// RS crc; //RS */ + return buf->isGood(); +} + +void DRW_LWPolyline::applyExtrusion(){ + if (haveExtrusion) { + calculateAxis(extPoint); + for (unsigned int i=0; ix, vert->y, elevation); + extrudePoint(extPoint, &v); + vert->x = v.x; + vert->y = v.y; + } + } +} + +void DRW_LWPolyline::parseCode(int code, dxfReader *reader){ + switch (code) { + case 10: { + vertex = new DRW_Vertex2D(); + vertlist.push_back(vertex); + vertex->x = reader->getDouble(); + break; } + case 20: + if(vertex != NULL) + vertex->y = reader->getDouble(); + break; + case 40: + if(vertex != NULL) + vertex->stawidth = reader->getDouble(); + break; + case 41: + if(vertex != NULL) + vertex->endwidth = reader->getDouble(); + break; + case 42: + if(vertex != NULL) + vertex->bulge = reader->getDouble(); + break; + case 38: + elevation = reader->getDouble(); + break; + case 39: + thickness = reader->getDouble(); + break; + case 43: + width = reader->getDouble(); + break; + case 70: + flags = reader->getInt32(); + break; + case 90: + vertexnum = reader->getInt32(); + vertlist.reserve(vertexnum); + break; + case 210: + haveExtrusion = true; + extPoint.x = reader->getDouble(); + break; + case 220: + extPoint.y = reader->getDouble(); + break; + case 230: + extPoint.z = reader->getDouble(); + break; + default: + DRW_Entity::parseCode(code, reader); + break; + } +} + +bool DRW_LWPolyline::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + bool ret = DRW_Entity::parseDwg(version, buf, NULL, bs); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing LWPolyline *******************************************\n"); + + flags = buf->getBitShort(); + DRW_DBG("flags value: "); DRW_DBG(flags); + if (flags & 4) + width = buf->getBitDouble(); + if (flags & 8) + elevation = buf->getBitDouble(); + if (flags & 2) + thickness = buf->getBitDouble(); + if (flags & 1) + extPoint = buf->getExtrusion(false); + vertexnum = buf->getBitLong(); + vertlist.reserve(vertexnum); + unsigned int bulgesnum = 0; + if (flags & 16) + bulgesnum = buf->getBitLong(); + int vertexIdCount = 0; + if (version > DRW::AC1021) {//2010+ + if (flags & 1024) + vertexIdCount = buf->getBitLong(); + } + + unsigned int widthsnum = 0; + if (flags & 32) + widthsnum = buf->getBitLong(); + DRW_DBG("\nvertex num: "); DRW_DBG(vertexnum); DRW_DBG(" bulges num: "); DRW_DBG(bulgesnum); + DRW_DBG(" vertexIdCount: "); DRW_DBG(vertexIdCount); DRW_DBG(" widths num: "); DRW_DBG(widthsnum); + //clear all bit except 128 = plinegen and set 1 to open/close //RLZ:verify plinegen & open + //dxf: plinegen 128 & open 1 + flags = (flags & 512)? (flags | 1):(flags | 0); + flags &= 129; + DRW_DBG("end flags value: "); DRW_DBG(flags); + + if (vertexnum > 0) { //verify if is lwpol without vertex (empty) + // add vertexs + vertex = new DRW_Vertex2D(); + vertex->x = buf->getRawDouble(); + vertex->y = buf->getRawDouble(); + vertlist.push_back(vertex); + DRW_Vertex2D* pv = vertex; + for (int i = 1; i< vertexnum; i++){ + vertex = new DRW_Vertex2D(); + if (version < DRW::AC1015) {//14- + vertex->x = buf->getRawDouble(); + vertex->y = buf->getRawDouble(); + } else { +// DRW_Vertex2D *pv = vertlist.back(); + vertex->x = buf->getDefaultDouble(pv->x); + vertex->y = buf->getDefaultDouble(pv->y); + } + pv = vertex; + vertlist.push_back(vertex); + } + //add bulges + for (unsigned int i = 0; i < bulgesnum; i++){ + double bulge = buf->getBitDouble(); + if (vertlist.size()> i) + vertlist.at(i)->bulge = bulge; + } + //add vertexId + if (version > DRW::AC1021) {//2010+ + for (int i = 0; i < vertexIdCount; i++){ + dint32 vertexId = buf->getBitLong(); + //TODO implement vertexId, do not exist in dxf + DRW_UNUSED(vertexId); +// if (vertlist.size()< i) +// vertlist.at(i)->vertexId = vertexId; + } + } + //add widths + for (unsigned int i = 0; i < widthsnum; i++){ + double staW = buf->getBitDouble(); + double endW = buf->getBitDouble(); + if (vertlist.size()< i) { + vertlist.at(i)->stawidth = staW; + vertlist.at(i)->endwidth = endW; + } + } + } + if (DRW_DBGGL == DRW_dbg::DEBUG){ + DRW_DBG("\nVertex list: "); + for (std::vector::iterator it = vertlist.begin() ; it != vertlist.end(); ++it){ + DRW_Vertex2D* pv = *it; + DRW_DBG("\n x: "); DRW_DBG(pv->x); DRW_DBG(" y: "); DRW_DBG(pv->y); DRW_DBG(" bulge: "); DRW_DBG(pv->bulge); + DRW_DBG(" stawidth: "); DRW_DBG(pv->stawidth); DRW_DBG(" endwidth: "); DRW_DBG(pv->endwidth); + } + } + + DRW_DBG("\n"); + /* Common Entity Handle Data */ + ret = DRW_Entity::parseDwgEntHandle(version, buf); + if (!ret) + return ret; + /* CRC X --- */ + return buf->isGood(); +} + + +void DRW_Text::parseCode(int code, dxfReader *reader){ + switch (code) { + case 40: + height = reader->getDouble(); + break; + case 41: + widthscale = reader->getDouble(); + break; + case 50: + angle = reader->getDouble(); + break; + case 51: + oblique = reader->getDouble(); + break; + case 71: + textgen = reader->getInt32(); + break; + case 72: + alignH = (HAlign)reader->getInt32(); + break; + case 73: + alignV = (VAlign)reader->getInt32(); + break; + case 1: + text = reader->getUtf8String(); + break; + case 7: + style = reader->getUtf8String(); + break; + default: + DRW_Line::parseCode(code, reader); + break; + } +} + +bool DRW_Text::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dwgBuffer sBuff = *buf; + dwgBuffer *sBuf = buf; + if (version > DRW::AC1018) {//2007+ + sBuf = &sBuff; //separate buffer for strings + } + bool ret = DRW_Entity::parseDwg(version, buf, sBuf, bs); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing text *********************************************\n"); + + // DataFlags RC Used to determine presence of subsquent data, set to 0xFF for R14- + duint8 data_flags = 0x00; + if (version > DRW::AC1014) {//2000+ + data_flags = buf->getRawChar8(); /* DataFlags RC Used to determine presence of subsquent data */ + DRW_DBG("data_flags: "); DRW_DBG(data_flags); DRW_DBG("\n"); + if ( !(data_flags & 0x01) ) { /* Elevation RD --- present if !(DataFlags & 0x01) */ + basePoint.z = buf->getRawDouble(); + } + } else {//14- + basePoint.z = buf->getBitDouble(); /* Elevation BD --- */ + } + basePoint.x = buf->getRawDouble(); /* Insertion pt 2RD 10 */ + basePoint.y = buf->getRawDouble(); + DRW_DBG("Insert point: "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z); DRW_DBG("\n"); + if (version > DRW::AC1014) {//2000+ + if ( !(data_flags & 0x02) ) { /* Alignment pt 2DD 11 present if !(DataFlags & 0x02), use 10 & 20 values for 2 default values.*/ + secPoint.x = buf->getDefaultDouble(basePoint.x); + secPoint.y = buf->getDefaultDouble(basePoint.y); + } else { + secPoint = basePoint; + } + } else {//14- + secPoint.x = buf->getRawDouble(); /* Alignment pt 2RD 11 */ + secPoint.y = buf->getRawDouble(); + } + secPoint.z = basePoint.z; + DRW_DBG("Alignment: "); DRW_DBGPT(secPoint.x, secPoint.y, basePoint.z); DRW_DBG("\n"); + extPoint = buf->getExtrusion(version > DRW::AC1014); + DRW_DBG("Extrusion: "); DRW_DBGPT(extPoint.x, extPoint.y, extPoint.z); DRW_DBG("\n"); + thickness = buf->getThickness(version > DRW::AC1014); /* Thickness BD 39 */ + + if (version > DRW::AC1014) {//2000+ + if ( !(data_flags & 0x04) ) { /* Oblique ang RD 51 present if !(DataFlags & 0x04) */ + oblique = buf->getRawDouble(); + } + if ( !(data_flags & 0x08) ) { /* Rotation ang RD 50 present if !(DataFlags & 0x08) */ + angle = buf->getRawDouble(); + } + height = buf->getRawDouble(); /* Height RD 40 */ + if ( !(data_flags & 0x10) ) { /* Width factor RD 41 present if !(DataFlags & 0x10) */ + widthscale = buf->getRawDouble(); + } + } else {//14- + oblique = buf->getBitDouble(); /* Oblique ang BD 51 */ + angle = buf->getBitDouble(); /* Rotation ang BD 50 */ + height = buf->getBitDouble(); /* Height BD 40 */ + widthscale = buf->getBitDouble(); /* Width factor BD 41 */ + } + DRW_DBG("thickness: "); DRW_DBG(thickness); DRW_DBG(", Oblique ang: "); DRW_DBG(oblique); DRW_DBG(", Width: "); + DRW_DBG(widthscale); DRW_DBG(", Rotation: "); DRW_DBG(angle); DRW_DBG(", height: "); DRW_DBG(height); DRW_DBG("\n"); + text = sBuf->getVariableText(version, false); /* Text value TV 1 */ + DRW_DBG("text string: "); DRW_DBG(text.c_str());DRW_DBG("\n"); + //textgen, alignH, alignV always present in R14-, data_flags set in initialisation + if ( !(data_flags & 0x20) ) { /* Generation BS 71 present if !(DataFlags & 0x20) */ + textgen = buf->getBitShort(); + DRW_DBG("textgen: "); DRW_DBG(textgen); + } + if ( !(data_flags & 0x40) ) { /* Horiz align. BS 72 present if !(DataFlags & 0x40) */ + alignH = (HAlign)buf->getBitShort(); + DRW_DBG(", alignH: "); DRW_DBG(alignH); + } + if ( !(data_flags & 0x80) ) { /* Vert align. BS 73 present if !(DataFlags & 0x80) */ + alignV = (VAlign)buf->getBitShort(); + DRW_DBG(", alignV: "); DRW_DBG(alignV); + } + DRW_DBG("\n"); + + /* Common Entity Handle Data */ + ret = DRW_Entity::parseDwgEntHandle(version, buf); + if (!ret) + return ret; + + styleH = buf->getHandle(); /* H 7 STYLE (hard pointer) */ + DRW_DBG("text style Handle: "); DRW_DBGHL(styleH.code, styleH.size, styleH.ref); DRW_DBG("\n"); + + /* CRC X --- */ + return buf->isGood(); +} + +void DRW_MText::parseCode(int code, dxfReader *reader){ + switch (code) { + case 1: + text += reader->getString(); + text = reader->toUtf8String(text); + break; + case 11: + haveXAxis = true; + DRW_Text::parseCode(code, reader); + break; + case 3: + text += reader->getString(); + break; + case 44: + interlin = reader->getDouble(); + break; + case 71: { + // Attachment point + Attach a = (Attach)reader->getInt32(); + + switch(a) { + case TopLeft: + alignV = VTop; + alignH = HLeft; + break; + case TopCenter: + alignV = VTop; + alignH = HCenter; + break; + case TopRight: + alignV = VTop; + alignH = HRight; + break; + case MiddleLeft: + alignV = VMiddle; + alignH = HLeft; + break; + case MiddleCenter: + alignV = VMiddle; + alignH = HCenter; + break; + case MiddleRight: + alignV = VMiddle; + alignH = HRight; + break; + case BottomLeft: + alignV = VBottom; + alignH = HLeft; + break; + case BottomCenter: + alignV = VBottom; + alignH = HCenter; + break; + case BottomRight: + alignV = VBottom; + alignH = HRight; + break; + } + } break; + case 72: + // To prevent redirection to DRW_Text::parseCode. + // This code meaning is different for MTEXT. + // Actually: Drawing direction + break; + case 73: + // To prevent redirection to DRW_Text::parseCode. + // This code meaning is different for MTEXT. + // Actually: Mtext line spacing style + break; + default: + DRW_Text::parseCode(code, reader); + break; + } +} + +bool DRW_MText::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dwgBuffer sBuff = *buf; + dwgBuffer *sBuf = buf; + if (version > DRW::AC1018) {//2007+ + sBuf = &sBuff; //separate buffer for strings + } + bool ret = DRW_Entity::parseDwg(version, buf, sBuf, bs); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing mtext *********************************************\n"); + + basePoint = buf->get3BitDouble(); /* Insertion pt 3BD 10 - First picked point. */ + DRW_DBG("Insertion: "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z); DRW_DBG("\n"); + extPoint = buf->get3BitDouble(); /* Extrusion 3BD 210 Undocumented; */ + secPoint = buf->get3BitDouble(); /* X-axis dir 3BD 11 */ + updateAngle(); + widthscale = buf->getBitDouble(); /* Rect width BD 41 */ + if (version > DRW::AC1018) {//2007+ + /* Rect height BD 46 Reference rectangle height. */ + /** @todo */buf->getBitDouble(); + } + height = buf->getBitDouble();/* Text height BD 40 Undocumented */ + textgen = buf->getBitShort(); /* Attachment BS 71 Similar to justification; */ + /* Drawing dir BS 72 Left to right, etc.; see DXF doc */ + dint16 draw_dir = buf->getBitShort(); + DRW_UNUSED(draw_dir); + /* Extents ht BD Undocumented and not present in DXF or entget */ + double ext_ht = buf->getBitDouble(); + DRW_UNUSED(ext_ht); + /* Extents wid BD Undocumented and not present in DXF or entget The extents + rectangle, when rotated the same as the text, fits the actual text image on + the screen (altough we've seen it include an extra row of text in height). */ + double ext_wid = buf->getBitDouble(); + DRW_UNUSED(ext_wid); + /* Text TV 1 All text in one long string (without '\n's 3 for line wrapping). + ACAD seems to add braces ({ }) and backslash-P's to indicate paragraphs + based on the "\r\n"'s found in the imported file. But, all the text is in + this one long string -- not broken into 1- and 3-groups as in DXF and + entget. ACAD's entget breaks this string into 250-char pieces (not 255 as + doc'd) – even if it's mid-word. The 1-group always gets the tag end; + therefore, the 3's are always 250 chars long. */ + text = sBuf->getVariableText(version, false); /* Text value TV 1 */ + if (version > DRW::AC1014) {//2000+ + buf->getBitShort();/* Linespacing Style BS 73 */ + buf->getBitDouble();/* Linespacing Factor BD 44 */ + buf->getBit();/* Unknown bit B */ + } + if (version > DRW::AC1015) {//2004+ + /* Background flags BL 0 = no background, 1 = background fill, 2 =background + fill with drawing fill color. */ + dint32 bk_flags = buf->getBitLong(); /** @todo add to DRW_MText */ + if ( bk_flags == 1 ) { + /* Background scale factor BL Present if background flags = 1, default = 1.5*/ + buf->getBitLong(); + /* Background color CMC Present if background flags = 1 */ + buf->getCmColor(version); //RLZ: warning CMC or ENC + /** @todo buf->getCMC */ + /* Background transparency BL Present if background flags = 1 */ + buf->getBitLong(); + } + } + + /* Common Entity Handle Data */ + ret = DRW_Entity::parseDwgEntHandle(version, buf); + if (!ret) + return ret; + + styleH = buf->getHandle(); /* H 7 STYLE (hard pointer) */ + DRW_DBG("text style Handle: "); DRW_DBG(styleH.code); DRW_DBG("."); + DRW_DBG(styleH.size); DRW_DBG("."); DRW_DBG(styleH.ref); DRW_DBG("\n"); + + /* CRC X --- */ + return buf->isGood(); +} + +void DRW_MText::updateAngle(){ + if (haveXAxis) { + angle = atan2(secPoint.y, secPoint.x)*180/M_PI; + } +} + +void DRW_Polyline::parseCode(int code, dxfReader *reader){ + switch (code) { + case 70: + flags = reader->getInt32(); + break; + case 40: + defstawidth = reader->getDouble(); + break; + case 41: + defendwidth = reader->getDouble(); + break; + case 71: + vertexcount = reader->getInt32(); + break; + case 72: + facecount = reader->getInt32(); + break; + case 73: + smoothM = reader->getInt32(); + break; + case 74: + smoothN = reader->getInt32(); + break; + case 75: + curvetype = reader->getInt32(); + break; + default: + DRW_Point::parseCode(code, reader); + break; + } +} + +//0x0F polyline 2D bit 4(8) & 5(16) NOT set +//0x10 polyline 3D bit 4(8) set +//0x1D PFACE bit 5(16) set +bool DRW_Polyline::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + bool ret = DRW_Entity::parseDwg(version, buf, NULL, bs); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing polyline *********************************************\n"); + + dint32 ooCount = 0; + if (oType == 0x0F) { //pline 2D + flags = buf->getBitShort(); + DRW_DBG("flags value: "); DRW_DBG(flags); + curvetype = buf->getBitShort(); + defstawidth = buf->getBitDouble(); + defendwidth = buf->getBitDouble(); + thickness = buf->getThickness(version > DRW::AC1014); + basePoint = DRW_Coord(0,0,buf->getBitDouble()); + extPoint = buf->getExtrusion(version > DRW::AC1014); + } else if (oType == 0x10) { //pline 3D + duint8 tmpFlag = buf->getRawChar8(); + DRW_DBG("flags 1 value: "); DRW_DBG(tmpFlag); + if (tmpFlag & 1) + curvetype = 5; + else if (tmpFlag & 2) + curvetype = 6; + if (tmpFlag & 3) { + curvetype = 8; + flags |= 4; + } + tmpFlag = buf->getRawChar8(); + if (tmpFlag & 1) + flags |= 1; + flags |= 8; //indicate 3DPOL + DRW_DBG("flags 2 value: "); DRW_DBG(tmpFlag); + } else if (oType == 0x1D) { //PFACE + flags = 64; + vertexcount = buf->getBitShort(); + DRW_DBG("vertex count: "); DRW_DBG(vertexcount); + facecount = buf->getBitShort(); + DRW_DBG("face count: "); DRW_DBG(facecount); + DRW_DBG("flags value: "); DRW_DBG(flags); + } + if (version > DRW::AC1015){ //2004+ + ooCount = buf->getBitLong(); + } + + ret = DRW_Entity::parseDwgEntHandle(version, buf); + if (!ret) + return ret; + + if (version < DRW::AC1018){ //2000- + dwgHandle objectH = buf->getOffsetHandle(handle); + firstEH = objectH.ref; + DRW_DBG(" first Vertex Handle: "); DRW_DBGHL(objectH.code, objectH.size, objectH.ref); DRW_DBG("\n"); + objectH = buf->getOffsetHandle(handle); + lastEH = objectH.ref; + DRW_DBG(" last Vertex Handle: "); DRW_DBGHL(objectH.code, objectH.size, objectH.ref); DRW_DBG("\n"); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + } else { + for (dint32 i = 0; i < ooCount; ++i){ + dwgHandle objectH = buf->getOffsetHandle(handle); + hadlesList.push_back (objectH.ref); + DRW_DBG(" Vertex Handle: "); DRW_DBGHL(objectH.code, objectH.size, objectH.ref); DRW_DBG("\n"); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + } + } + seqEndH = buf->getOffsetHandle(handle); + DRW_DBG(" SEQEND Handle: "); DRW_DBGHL(seqEndH.code, seqEndH.size, seqEndH.ref); DRW_DBG("\n"); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + +// RS crc; //RS */ + return buf->isGood(); +} + +void DRW_Vertex::parseCode(int code, dxfReader *reader){ + switch (code) { + case 70: + flags = reader->getInt32(); + break; + case 40: + stawidth = reader->getDouble(); + break; + case 41: + endwidth = reader->getDouble(); + break; + case 42: + bulge = reader->getDouble(); + break; + case 50: + tgdir = reader->getDouble(); + break; + case 71: + vindex1 = reader->getInt32(); + break; + case 72: + vindex2 = reader->getInt32(); + break; + case 73: + vindex3 = reader->getInt32(); + break; + case 74: + vindex4 = reader->getInt32(); + break; + case 91: + identifier = reader->getInt32(); + break; + default: + DRW_Point::parseCode(code, reader); + break; + } +} + +//0x0A vertex 2D +//0x0B vertex 3D +//0x0C MESH +//0x0D PFACE +//0x0E PFACE FACE +bool DRW_Vertex::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs, double el){ + bool ret = DRW_Entity::parseDwg(version, buf, NULL, bs); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing pline Vertex *********************************************\n"); + + if (oType == 0x0A) { //pline 2D, needed example + flags = buf->getRawChar8(); //RLZ: EC unknown type + DRW_DBG("flags value: "); DRW_DBG(flags); + basePoint = buf->get3BitDouble(); + basePoint.z = el; + DRW_DBG("basePoint: "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z); + stawidth = buf->getBitDouble(); + if (stawidth < 0) + endwidth = stawidth = fabs(stawidth); + else + endwidth = buf->getBitDouble(); + bulge = buf->getBitDouble(); + if (version > DRW::AC1021) //2010+ + DRW_DBG("Vertex ID: "); DRW_DBG(buf->getBitLong()); + tgdir = buf->getBitDouble(); + } else if (oType == 0x0B || oType == 0x0C || oType == 0x0D) { //PFACE + flags = buf->getRawChar8(); //RLZ: EC unknown type + DRW_DBG("flags value: "); DRW_DBG(flags); + basePoint = buf->get3BitDouble(); + DRW_DBG("basePoint: "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z); + } else if (oType == 0x0E) { //PFACE FACE + vindex1 = buf->getBitShort(); + vindex2 = buf->getBitShort(); + vindex3 = buf->getBitShort(); + vindex4 = buf->getBitShort(); + } + + ret = DRW_Entity::parseDwgEntHandle(version, buf); + if (!ret) + return ret; +// RS crc; //RS */ + return buf->isGood(); +} + +void DRW_Hatch::parseCode(int code, dxfReader *reader){ + switch (code) { + case 2: + name = reader->getUtf8String(); + break; + case 70: + solid = reader->getInt32(); + break; + case 71: + associative = reader->getInt32(); + break; + case 72: /*edge type*/ + if (ispol){ //if is polyline is a as_bulge flag + break; + } else if (reader->getInt32() == 1){ //line + addLine(); + } else if (reader->getInt32() == 2){ //arc + addArc(); + } else if (reader->getInt32() == 3){ //elliptic arc + addEllipse(); + } else if (reader->getInt32() == 4){ //spline + addSpline(); + } + break; + case 10: + if (pt) pt->basePoint.x = reader->getDouble(); + else if (pline) { + plvert = pline->addVertex(); + plvert->x = reader->getDouble(); + } + break; + case 20: + if (pt) pt->basePoint.y = reader->getDouble(); + else if (plvert) plvert ->y = reader->getDouble(); + break; + case 11: + if (line) line->secPoint.x = reader->getDouble(); + else if (ellipse) ellipse->secPoint.x = reader->getDouble(); + break; + case 21: + if (line) line->secPoint.y = reader->getDouble(); + else if (ellipse) ellipse->secPoint.y = reader->getDouble(); + break; + case 40: + if (arc) arc->radious = reader->getDouble(); + else if (ellipse) ellipse->ratio = reader->getDouble(); + break; + case 41: + scale = reader->getDouble(); + break; + case 42: + if (plvert) plvert ->bulge = reader->getDouble(); + break; + case 50: + if (arc) arc->staangle = reader->getDouble()/ARAD; + else if (ellipse) ellipse->staparam = reader->getDouble()/ARAD; + break; + case 51: + if (arc) arc->endangle = reader->getDouble()/ARAD; + else if (ellipse) ellipse->endparam = reader->getDouble()/ARAD; + break; + case 52: + angle = reader->getDouble(); + break; + case 73: + if (arc) arc->isccw = reader->getInt32(); + else if (pline) pline->flags = reader->getInt32(); + break; + case 75: + hstyle = reader->getInt32(); + break; + case 76: + hpattern = reader->getInt32(); + break; + case 77: + doubleflag = reader->getInt32(); + break; + case 78: + deflines = reader->getInt32(); + break; + case 91: + loopsnum = reader->getInt32(); + looplist.reserve(loopsnum); + break; + case 92: + loop = new DRW_HatchLoop(reader->getInt32()); + looplist.push_back(loop); + if (reader->getInt32() & 2) { + ispol = true; + clearEntities(); + pline = new DRW_LWPolyline; + loop->objlist.push_back(pline); + } else ispol = false; + break; + case 93: + if (pline) pline->vertexnum = reader->getInt32(); + else loop->numedges = reader->getInt32();//aqui reserve + break; + case 98: //seed points ?? + clearEntities(); + break; + default: + DRW_Point::parseCode(code, reader); + break; + } +} + +bool DRW_Hatch::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dwgBuffer sBuff = *buf; + dwgBuffer *sBuf = buf; + duint32 totalBoundItems = 0; + bool havePixelSize = false; + + if (version > DRW::AC1018) {//2007+ + sBuf = &sBuff; //separate buffer for strings + } + bool ret = DRW_Entity::parseDwg(version, buf, sBuf, bs); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing hatch *********************************************\n"); + + //Gradient data, RLZ: is ok or if grad > 0 continue read ? + if (version > DRW::AC1015) { //2004+ + dint32 isGradient = buf->getBitLong(); + DRW_DBG("is Gradient: "); DRW_DBG(isGradient); + dint32 res = buf->getBitLong(); + DRW_DBG(" reserved: "); DRW_DBG(res); + double gradAngle = buf->getBitDouble(); + DRW_DBG(" Gradient angle: "); DRW_DBG(gradAngle); + double gradShift = buf->getBitDouble(); + DRW_DBG(" Gradient shift: "); DRW_DBG(gradShift); + dint32 singleCol = buf->getBitLong(); + DRW_DBG("\nsingle color Grad: "); DRW_DBG(singleCol); + double gradTint = buf->getBitDouble(); + DRW_DBG(" Gradient tint: "); DRW_DBG(gradTint); + dint32 numCol = buf->getBitLong(); + DRW_DBG(" num colors: "); DRW_DBG(numCol); + for (dint32 i = 0 ; i < numCol; ++i){ + double unkDouble = buf->getBitDouble(); + DRW_DBG("\nunkDouble: "); DRW_DBG(unkDouble); + duint16 unkShort = buf->getBitShort(); + DRW_DBG(" unkShort: "); DRW_DBG(unkShort); + dint32 rgbCol = buf->getBitLong(); + DRW_DBG(" rgb color: "); DRW_DBG(rgbCol); + duint8 ignCol = buf->getRawChar8(); + DRW_DBG(" ignored color: "); DRW_DBG(ignCol); + } + UTF8STRING gradName = sBuf->getVariableText(version, false); + DRW_DBG("\ngradient name: "); DRW_DBG(gradName.c_str()); DRW_DBG("\n"); + } + basePoint.z = buf->getBitDouble(); + extPoint = buf->get3BitDouble(); + DRW_DBG("base point: "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z); + DRW_DBG("\nextrusion: "); DRW_DBGPT(extPoint.x, extPoint.y, extPoint.z); + name = sBuf->getVariableText(version, false); + DRW_DBG("\nhatch pattern name: "); DRW_DBG(name.c_str()); DRW_DBG("\n"); + solid = buf->getBit(); + associative = buf->getBit(); + loopsnum = buf->getBitLong(); + + //read loops + for (dint32 i = 0 ; i < loopsnum; ++i){ + loop = new DRW_HatchLoop(buf->getBitLong()); + havePixelSize |= loop->type & 4; + if (!(loop->type & 2)){ //Not polyline + dint32 numPathSeg = buf->getBitLong(); + for (dint32 j = 0; jgetRawChar8(); + if (typePath == 1){ //line + addLine(); + line->basePoint = buf->get2RawDouble(); + line->secPoint = buf->get2RawDouble(); + } else if (typePath == 2){ //circle arc + addArc(); + arc->basePoint = buf->get2RawDouble(); + arc->radious = buf->getBitDouble(); + arc->staangle = buf->getBitDouble(); + arc->endangle = buf->getBitDouble(); + arc->isccw = buf->getBit(); + } else if (typePath == 3){ //ellipse arc + addEllipse(); + ellipse->basePoint = buf->get2RawDouble(); + ellipse->secPoint = buf->get2RawDouble(); + ellipse->ratio = buf->getBitDouble(); + ellipse->staparam = buf->getBitDouble(); + ellipse->endparam = buf->getBitDouble(); + ellipse->isccw = buf->getBit(); + } else if (typePath == 4){ //spline + addSpline(); + spline->degree = buf->getBitLong(); + bool isRational = buf->getBit(); + spline->flags |= (isRational << 2); //rational + spline->flags |= (buf->getBit() << 1); //periodic + spline->nknots = buf->getBitLong(); + spline->knotslist.reserve(spline->nknots); + for (dint32 j = 0; j < spline->nknots;++j){ + spline->knotslist.push_back (buf->getBitDouble()); + } + spline->ncontrol = buf->getBitLong(); + spline->controllist.reserve(spline->ncontrol); + for (dint32 j = 0; j < spline->ncontrol;++j){ + DRW_Coord* crd = new DRW_Coord(buf->get3BitDouble()); + if(isRational) + crd->z = buf->getBitDouble(); //RLZ: investigate how store weight + spline->controllist.push_back(crd); + } + if (version > DRW::AC1021) { //2010+ + spline->nfit = buf->getBitLong(); + spline->fitlist.reserve(spline->nfit); + for (dint32 j = 0; j < spline->nfit;++j){ + DRW_Coord* crd = new DRW_Coord(buf->get3BitDouble()); + spline->fitlist.push_back (crd); + } + spline->tgStart = buf->get2RawDouble(); + spline->tgEnd = buf->get2RawDouble(); + } + } + } + } else { //end not pline, start polyline + pline = new DRW_LWPolyline; + bool asBulge = buf->getBit(); + pline->flags = buf->getBit();//closed bit + dint32 numVert = buf->getBitLong(); + for (dint32 j = 0; jgetRawDouble(); + v.y = buf->getRawDouble(); + if (asBulge) + v.bulge = buf->getBitDouble(); + pline->addVertex(v); + } + loop->objlist.push_back(pline); + }//end polyline + loop->update(); + looplist.push_back(loop); + totalBoundItems += buf->getBitLong(); + DRW_DBG(" totalBoundItems: "); DRW_DBG(totalBoundItems); + } //end read loops + + hstyle = buf->getBitShort(); + hpattern = buf->getBitShort(); + DRW_DBG("\nhatch style: "); DRW_DBG(hstyle); DRW_DBG(" pattern type"); DRW_DBG(hpattern); + if (!solid){ + angle = buf->getBitDouble(); + scale = buf->getBitDouble(); + doubleflag = buf->getBit(); + deflines = buf->getBitShort(); + for (dint32 i = 0 ; i < deflines; ++i){ + DRW_Coord ptL, offL; + double angleL = buf->getBitDouble(); + ptL.x = buf->getBitDouble(); + ptL.y = buf->getBitDouble(); + offL.x = buf->getBitDouble(); + offL.y = buf->getBitDouble(); + duint16 numDashL = buf->getBitShort(); + DRW_DBG("\ndef line: "); DRW_DBG(angleL); DRW_DBG(","); DRW_DBG(ptL.x); DRW_DBG(","); DRW_DBG(ptL.y); + DRW_DBG(","); DRW_DBG(offL.x); DRW_DBG(","); DRW_DBG(offL.y); DRW_DBG(","); DRW_DBG(angleL); + for (duint16 i = 0 ; i < numDashL; ++i){ + double lenghtL = buf->getBitDouble(); + DRW_DBG(","); DRW_DBG(lenghtL); + } + }//end deflines + } //end not solid + + if (havePixelSize){ + ddouble64 pixsize = buf->getBitDouble(); + DRW_DBG("\npixel size: "); DRW_DBG(pixsize); + } + dint32 numSeedPoints = buf->getBitLong(); + DRW_DBG("\nnum Seed Points "); DRW_DBG(numSeedPoints); + //read Seed Points + DRW_Coord seedPt; + for (dint32 i = 0 ; i < numSeedPoints; ++i){ + seedPt.x = buf->getRawDouble(); + seedPt.y = buf->getRawDouble(); + DRW_DBG("\n "); DRW_DBG(seedPt.x); DRW_DBG(","); DRW_DBG(seedPt.y); + } + + DRW_DBG("\n"); + ret = DRW_Entity::parseDwgEntHandle(version, buf); + if (!ret) + return ret; + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + + for (duint32 i = 0 ; i < totalBoundItems; ++i){ + dwgHandle biH = buf->getHandle(); + DRW_DBG("Boundary Items Handle: "); DRW_DBGHL(biH.code, biH.size, biH.ref); + } + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); +// RS crc; //RS */ + return buf->isGood(); +} + +void DRW_Spline::parseCode(int code, dxfReader *reader){ + switch (code) { + case 210: + normalVec.x = reader->getDouble(); + break; + case 220: + normalVec.y = reader->getDouble(); + break; + case 230: + normalVec.z = reader->getDouble(); + break; + case 12: + tgStart.x = reader->getDouble(); + break; + case 22: + tgStart.y = reader->getDouble(); + break; + case 32: + tgStart.z = reader->getDouble(); + break; + case 13: + tgEnd.x = reader->getDouble(); + break; + case 23: + tgEnd.y = reader->getDouble(); + break; + case 33: + tgEnd.z = reader->getDouble(); + break; + case 70: + flags = reader->getInt32(); + break; + case 71: + degree = reader->getInt32(); + break; + case 72: + nknots = reader->getInt32(); + break; + case 73: + ncontrol = reader->getInt32(); + break; + case 74: + nfit = reader->getInt32(); + break; + case 42: + tolknot = reader->getDouble(); + break; + case 43: + tolcontrol = reader->getDouble(); + break; + case 44: + tolfit = reader->getDouble(); + break; + case 10: { + controlpoint = new DRW_Coord(); + controllist.push_back(controlpoint); + controlpoint->x = reader->getDouble(); + break; } + case 20: + if(controlpoint != NULL) + controlpoint->y = reader->getDouble(); + break; + case 30: + if(controlpoint != NULL) + controlpoint->z = reader->getDouble(); + break; + case 11: { + fitpoint = new DRW_Coord(); + fitlist.push_back(fitpoint); + fitpoint->x = reader->getDouble(); + break; } + case 21: + if(fitpoint != NULL) + fitpoint->y = reader->getDouble(); + break; + case 31: + if(fitpoint != NULL) + fitpoint->z = reader->getDouble(); + break; + case 40: + knotslist.push_back(reader->getDouble()); + break; + case 41: + weightlist.push_back(reader->getDouble()); + break; + default: + DRW_Entity::parseCode(code, reader); + break; + } +} + +bool DRW_Spline::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + bool ret = DRW_Entity::parseDwg(version, buf, NULL, bs); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing spline *********************************************\n"); + duint8 weight = 0; // RLZ ??? flags, weight, code 70, bit 4 (16) + + dint32 scenario = buf->getBitLong(); + DRW_DBG("scenario: "); DRW_DBG(scenario); + if (version > DRW::AC1024) { + dint32 splFlag1 = buf->getBitLong(); + if (splFlag1 & 1) + scenario = 2; + dint32 knotParam = buf->getBitLong(); + DRW_DBG("2013 splFlag1: "); DRW_DBG(splFlag1); DRW_DBG(" 2013 knotParam: "); + DRW_DBG(knotParam); +// DRW_DBG("unk bit: "); DRW_DBG(buf->getBit()); + } + degree = buf->getBitLong(); //RLZ: code 71, verify with dxf + DRW_DBG(" degree: "); DRW_DBG(degree); DRW_DBG("\n"); + if (scenario == 2) { + flags = 8;//scenario 2 = not rational & planar + tolfit = buf->getBitDouble();//BD + DRW_DBG("flags: "); DRW_DBG(flags); DRW_DBG(" tolfit: "); DRW_DBG(tolfit); + tgStart =buf->get3BitDouble(); + DRW_DBG(" Start Tangent: "); DRW_DBGPT(tgStart.x, tgStart.y, tgStart.z); + tgEnd =buf->get3BitDouble(); + DRW_DBG("\nEnd Tangent: "); DRW_DBGPT(tgEnd.x, tgEnd.y, tgEnd.z); + nfit = buf->getBitLong(); + DRW_DBG("\nnumber of fit points: "); DRW_DBG(nfit); + } else if (scenario == 1) { + flags = 8;//scenario 1 = rational & planar + flags |= buf->getBit() << 2; //flags, rational, code 70, bit 2 (4) + flags |= buf->getBit(); //flags, closed, code 70, bit 0 (1) + flags |= buf->getBit() << 1; //flags, periodic, code 70, bit 1 (2) + tolknot = buf->getBitDouble(); + tolcontrol = buf->getBitDouble(); + DRW_DBG("flags: "); DRW_DBG(flags); DRW_DBG(" knot tolerance: "); DRW_DBG(tolknot); + DRW_DBG(" control point tolerance: "); DRW_DBG(tolcontrol); + nknots = buf->getBitLong(); + ncontrol = buf->getBitLong(); + weight = buf->getBit(); // RLZ ??? flags, weight, code 70, bit 4 (16) + DRW_DBG("\nnum of knots: "); DRW_DBG(nknots); DRW_DBG(" num of control pt: "); + DRW_DBG(ncontrol); DRW_DBG(" weight bit: "); DRW_DBG(weight); + } else { + DRW_DBG("\ndwg Ellipse, unknouwn scenario\n"); + return false; //RLZ: from doc only 1 or 2 are ok ? + } + + knotslist.reserve(nknots); + for (dint32 i= 0; igetBitDouble()); + } + controllist.reserve(ncontrol); + for (dint32 i= 0; iget3BitDouble()); + controllist.push_back(crd); + if (weight){ + DRW_DBG("\n w: "); DRW_DBG(buf->getBitDouble()); //RLZ Warning: D (BD or RD) + } + } + fitlist.reserve(nfit); + for (dint32 i= 0; iget3BitDouble()); + fitlist.push_back (crd); + } + if (DRW_DBGGL == DRW_dbg::DEBUG){ + DRW_DBG("\nknots list: "); + for (std::vector::iterator it = knotslist.begin() ; it != knotslist.end(); ++it){ + DRW_DBG("\n"); DRW_DBG(*it); + } + DRW_DBG("\ncontrol point list: "); + for (std::vector::iterator it = controllist.begin() ; it != controllist.end(); ++it){ + DRW_DBG("\n"); DRW_DBGPT((*it)->x,(*it)->y,(*it)->z); + } + DRW_DBG("\nfit point list: "); + for (std::vector::iterator it = fitlist.begin() ; it != fitlist.end(); ++it){ + DRW_DBG("\n"); DRW_DBGPT((*it)->x,(*it)->y,(*it)->z); + } + } + + /* Common Entity Handle Data */ + ret = DRW_Entity::parseDwgEntHandle(version, buf); + if (!ret) + return ret; +// RS crc; //RS */ + return buf->isGood(); +} + +void DRW_Image::parseCode(int code, dxfReader *reader){ + switch (code) { + case 12: + vVector.x = reader->getDouble(); + break; + case 22: + vVector.y = reader->getDouble(); + break; + case 32: + vVector.z = reader->getDouble(); + break; + case 13: + sizeu = reader->getDouble(); + break; + case 23: + sizev = reader->getDouble(); + break; + case 340: + ref = reader->getHandleString(); + break; + case 280: + clip = reader->getInt32(); + break; + case 281: + brightness = reader->getInt32(); + break; + case 282: + contrast = reader->getInt32(); + break; + case 283: + fade = reader->getInt32(); + break; + default: + DRW_Line::parseCode(code, reader); + break; + } +} + +bool DRW_Image::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dwgBuffer sBuff = *buf; + dwgBuffer *sBuf = buf; + if (version > DRW::AC1018) {//2007+ + sBuf = &sBuff; //separate buffer for strings + } + bool ret = DRW_Entity::parseDwg(version, buf, sBuf, bs); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing image *********************************************\n"); + + dint32 classVersion = buf->getBitLong(); + DRW_DBG("class Version: "); DRW_DBG(classVersion); + basePoint = buf->get3BitDouble(); + DRW_DBG("\nbase point: "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z); + secPoint = buf->get3BitDouble(); + DRW_DBG("\nU vector: "); DRW_DBGPT(secPoint.x, secPoint.y, secPoint.z); + vVector = buf->get3BitDouble(); + DRW_DBG("\nV vector: "); DRW_DBGPT(vVector.x, vVector.y, vVector.z); + sizeu = buf->getRawDouble(); + sizev = buf->getRawDouble(); + DRW_DBG("\nsize U: "); DRW_DBG(sizeu); DRW_DBG("\nsize V: "); DRW_DBG(sizev); + duint16 displayProps = buf->getBitShort(); + (void)displayProps; + clip = buf->getBit(); + brightness = buf->getRawChar8(); + contrast = buf->getRawChar8(); + fade = buf->getRawChar8(); + if (version > DRW::AC1021){ //2010+ + bool clipMode = buf->getBit(); + (void)clipMode; + } + duint16 clipType = buf->getBitShort(); + if (clipType == 1){ + buf->get2RawDouble(); + buf->get2RawDouble(); + } else { //clipType == 2 + dint32 numVerts = buf->getBitLong(); + for (int i= 0; i< numVerts;++i) + buf->get2RawDouble(); + } + + ret = DRW_Entity::parseDwgEntHandle(version, buf); + if (!ret) + return ret; + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + + dwgHandle biH = buf->getHandle(); + DRW_DBG("ImageDef Handle: "); DRW_DBGHL(biH.code, biH.size, biH.ref); + ref = biH.ref; + biH = buf->getHandle(); + DRW_DBG("ImageDefReactor Handle: "); DRW_DBGHL(biH.code, biH.size, biH.ref); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); +// RS crc; //RS */ + return buf->isGood(); +} + +void DRW_Dimension::parseCode(int code, dxfReader *reader){ + switch (code) { + case 1: + text = reader->getUtf8String(); + break; + case 2: + name = reader->getString(); + break; + case 3: + style = reader->getUtf8String(); + break; + case 70: + type = reader->getInt32(); + break; + case 71: + align = reader->getInt32(); + break; + case 72: + linesty = reader->getInt32(); + break; + case 10: + defPoint.x = reader->getDouble(); + break; + case 20: + defPoint.y = reader->getDouble(); + break; + case 30: + defPoint.z = reader->getDouble(); + break; + case 11: + textPoint.x = reader->getDouble(); + break; + case 21: + textPoint.y = reader->getDouble(); + break; + case 31: + textPoint.z = reader->getDouble(); + break; + case 12: + clonePoint.x = reader->getDouble(); + break; + case 22: + clonePoint.y = reader->getDouble(); + break; + case 32: + clonePoint.z = reader->getDouble(); + break; + case 13: + def1.x = reader->getDouble(); + break; + case 23: + def1.y = reader->getDouble(); + break; + case 33: + def1.z = reader->getDouble(); + break; + case 14: + def2.x = reader->getDouble(); + break; + case 24: + def2.y = reader->getDouble(); + break; + case 34: + def2.z = reader->getDouble(); + break; + case 15: + circlePoint.x = reader->getDouble(); + break; + case 25: + circlePoint.y = reader->getDouble(); + break; + case 35: + circlePoint.z = reader->getDouble(); + break; + case 16: + arcPoint.x = reader->getDouble(); + break; + case 26: + arcPoint.y = reader->getDouble(); + break; + case 36: + arcPoint.z = reader->getDouble(); + break; + case 41: + linefactor = reader->getDouble(); + break; + case 42: + actual = reader->getDouble(); + hasActual = (actual != 0.0); + break; + case 53: + rot = reader->getDouble(); + break; + case 50: + angle = reader->getDouble(); + break; + case 52: + oblique = reader->getDouble(); + break; + case 40: + length = reader->getDouble(); + break; + case 51: + hdir = reader->getDouble(); + break; + default: + DRW_Entity::parseCode(code, reader); + break; + } +} + +bool DRW_Dimension::parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer *sBuf){ + DRW_DBG("\n***************************** parsing dimension *********************************************"); + if (version > DRW::AC1021) { //2010+ + duint8 dimVersion = buf->getRawChar8(); + DRW_DBG("\ndimVersion: "); DRW_DBG(dimVersion); + } + extPoint = buf->getExtrusion(version > DRW::AC1014); + DRW_DBG("\nextPoint: "); DRW_DBGPT(extPoint.x, extPoint.y, extPoint.z); + if (version > DRW::AC1014) { //2000+ + DRW_DBG("\nFive unknown bits: "); DRW_DBG(buf->getBit()); DRW_DBG(buf->getBit()); + DRW_DBG(buf->getBit()); DRW_DBG(buf->getBit()); DRW_DBG(buf->getBit()); + } + textPoint.x = buf->getRawDouble(); + textPoint.y = buf->getRawDouble(); + textPoint.z = buf->getBitDouble(); + DRW_DBG("\ntextPoint: "); DRW_DBGPT(textPoint.x, textPoint.y, textPoint.z); + type = buf->getRawChar8(); + DRW_DBG("\ntype (70) read: "); DRW_DBG(type); + type = (type & 1) ? type & 0x7F : type | 0x80; //set bit 7 + type = (type & 2) ? type | 0x20 : type & 0xDF; //set bit 5 + DRW_DBG(" type (70) set: "); DRW_DBG(type); + //clear last 3 bits to set integer dim type + type &= 0xF8; + text = sBuf->getVariableText(version, false); + DRW_DBG("\nforced dim text: "); DRW_DBG(text.c_str()); + rot = buf->getBitDouble(); + hdir = buf->getBitDouble(); + DRW_Coord inspoint = buf->get3BitDouble(); + DRW_DBG("\ninspoint: "); DRW_DBGPT(inspoint.x, inspoint.y, inspoint.z); + double insRot_code54 = buf->getBitDouble(); //RLZ: unknown, investigate + DRW_DBG(" insRot_code54: "); DRW_DBG(insRot_code54); + if (version > DRW::AC1014) { //2000+ + align = buf->getBitShort(); + linesty = buf->getBitShort(); + linefactor = buf->getBitDouble(); + double actMeas = buf->getBitDouble(); + DRW_DBG("\n actMeas_code42: "); DRW_DBG(actMeas); + if (version > DRW::AC1018) { //2007+ + bool unk = buf->getBit(); + bool flip1 = buf->getBit(); + bool flip2 = buf->getBit(); + DRW_DBG("\n2007, unk, flip1, flip2: "); DRW_DBG(unk); DRW_DBG(flip1); DRW_DBG(flip2); + } + } + clonePoint.x = buf->getRawDouble(); + clonePoint.y = buf->getRawDouble(); + DRW_DBG("\nclonePoint: "); DRW_DBGPT(clonePoint.x, clonePoint.y, clonePoint.z); + + return buf->isGood(); +} + +bool DRW_DimAligned::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dwgBuffer sBuff = *buf; + dwgBuffer *sBuf = buf; + if (version > DRW::AC1018) {//2007+ + sBuf = &sBuff; //separate buffer for strings + } + bool ret = DRW_Entity::parseDwg(version, buf, sBuf, bs); + if (!ret) + return ret; + ret = DRW_Dimension::parseDwg(version, buf, sBuf); + if (!ret) + return ret; + if (oType == 0x15) + DRW_DBG("\n***************************** parsing dim linear *********************************************\n"); + else + DRW_DBG("\n***************************** parsing dim aligned *********************************************\n"); + DRW_Coord pt = buf->get3BitDouble(); + setPt3(pt); //def1 + DRW_DBG("def1: "); DRW_DBGPT(pt.x, pt.y, pt.z); + pt = buf->get3BitDouble(); + setPt4(pt); + DRW_DBG("\ndef2: "); DRW_DBGPT(pt.x, pt.y, pt.z); + pt = buf->get3BitDouble(); + setDefPoint(pt); + DRW_DBG("\ndefPoint: "); DRW_DBGPT(pt.x, pt.y, pt.z); + setOb52(buf->getBitDouble()); + if (oType == 0x15) + setAn50(buf->getBitDouble() * ARAD); + else + type |= 1; + DRW_DBG("\n type (70) final: "); DRW_DBG(type); DRW_DBG("\n"); + + ret = DRW_Entity::parseDwgEntHandle(version, buf); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + if (!ret) + return ret; + dimStyleH = buf->getHandle(); + DRW_DBG("dim style Handle: "); DRW_DBGHL(dimStyleH.code, dimStyleH.size, dimStyleH.ref); DRW_DBG("\n"); + blockH = buf->getHandle(); /* H 7 STYLE (hard pointer) */ + DRW_DBG("anon block Handle: "); DRW_DBGHL(blockH.code, blockH.size, blockH.ref); DRW_DBG("\n"); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + + // RS crc; //RS */ + return buf->isGood(); + } + + bool DRW_DimRadial::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dwgBuffer sBuff = *buf; + dwgBuffer *sBuf = buf; + if (version > DRW::AC1018) {//2007+ + sBuf = &sBuff; //separate buffer for strings + } + bool ret = DRW_Entity::parseDwg(version, buf, sBuf, bs); + if (!ret) + return ret; + ret = DRW_Dimension::parseDwg(version, buf, sBuf); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing dim radial *********************************************\n"); + DRW_Coord pt = buf->get3BitDouble(); + setDefPoint(pt); //code 10 + DRW_DBG("defPoint: "); DRW_DBGPT(pt.x, pt.y, pt.z); + pt = buf->get3BitDouble(); + setPt5(pt); //center pt code 15 + DRW_DBG("\ncenter point: "); DRW_DBGPT(pt.x, pt.y, pt.z); + setRa40(buf->getBitDouble()); //leader length code 40 + DRW_DBG("\nleader length: "); DRW_DBG(getRa40()); + type |= 4; + DRW_DBG("\n type (70) final: "); DRW_DBG(type); DRW_DBG("\n"); + + ret = DRW_Entity::parseDwgEntHandle(version, buf); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + if (!ret) + return ret; + dimStyleH = buf->getHandle(); + DRW_DBG("dim style Handle: "); DRW_DBGHL(dimStyleH.code, dimStyleH.size, dimStyleH.ref); DRW_DBG("\n"); + blockH = buf->getHandle(); /* H 7 STYLE (hard pointer) */ + DRW_DBG("anon block Handle: "); DRW_DBGHL(blockH.code, blockH.size, blockH.ref); DRW_DBG("\n"); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + + // RS crc; //RS */ + return buf->isGood(); + } + + bool DRW_DimDiametric::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dwgBuffer sBuff = *buf; + dwgBuffer *sBuf = buf; + if (version > DRW::AC1018) {//2007+ + sBuf = &sBuff; //separate buffer for strings + } + bool ret = DRW_Entity::parseDwg(version, buf, sBuf, bs); + if (!ret) + return ret; + ret = DRW_Dimension::parseDwg(version, buf, sBuf); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing dim diametric *********************************************\n"); + DRW_Coord pt = buf->get3BitDouble(); + setPt5(pt); //center pt code 15 + DRW_DBG("center point: "); DRW_DBGPT(pt.x, pt.y, pt.z); + pt = buf->get3BitDouble(); + setDefPoint(pt); //code 10 + DRW_DBG("\ndefPoint: "); DRW_DBGPT(pt.x, pt.y, pt.z); + setRa40(buf->getBitDouble()); //leader length code 40 + DRW_DBG("\nleader length: "); DRW_DBG(getRa40()); + type |= 3; + DRW_DBG("\n type (70) final: "); DRW_DBG(type); DRW_DBG("\n"); + + ret = DRW_Entity::parseDwgEntHandle(version, buf); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + if (!ret) + return ret; + dimStyleH = buf->getHandle(); + DRW_DBG("dim style Handle: "); DRW_DBGHL(dimStyleH.code, dimStyleH.size, dimStyleH.ref); DRW_DBG("\n"); + blockH = buf->getHandle(); /* H 7 STYLE (hard pointer) */ + DRW_DBG("anon block Handle: "); DRW_DBGHL(blockH.code, blockH.size, blockH.ref); DRW_DBG("\n"); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + + // RS crc; //RS */ + return buf->isGood(); + } + +bool DRW_DimAngular::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dwgBuffer sBuff = *buf; + dwgBuffer *sBuf = buf; + if (version > DRW::AC1018) {//2007+ + sBuf = &sBuff; //separate buffer for strings + } + bool ret = DRW_Entity::parseDwg(version, buf, sBuf, bs); + if (!ret) + return ret; + ret = DRW_Dimension::parseDwg(version, buf, sBuf); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing dim angular *********************************************\n"); + DRW_Coord pt; + pt.x = buf->getRawDouble(); + pt.y = buf->getRawDouble(); + setPt6(pt); //code 16 + DRW_DBG("arc Point: "); DRW_DBGPT(pt.x, pt.y, pt.z); + pt = buf->get3BitDouble(); + setPt3(pt); //def1 code 13 + DRW_DBG("\ndef1: "); DRW_DBGPT(pt.x, pt.y, pt.z); + pt = buf->get3BitDouble(); + setPt4(pt); //def2 code 14 + DRW_DBG("\ndef2: "); DRW_DBGPT(pt.x, pt.y, pt.z); + pt = buf->get3BitDouble(); + setPt5(pt); //center pt code 15 + DRW_DBG("\ncenter point: "); DRW_DBGPT(pt.x, pt.y, pt.z); + pt = buf->get3BitDouble(); + setDefPoint(pt); //code 10 + DRW_DBG("\ndefPoint: "); DRW_DBGPT(pt.x, pt.y, pt.z); + type |= 0x02; + DRW_DBG("\n type (70) final: "); DRW_DBG(type); DRW_DBG("\n"); + + ret = DRW_Entity::parseDwgEntHandle(version, buf); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + if (!ret) + return ret; + dimStyleH = buf->getHandle(); + DRW_DBG("dim style Handle: "); DRW_DBGHL(dimStyleH.code, dimStyleH.size, dimStyleH.ref); DRW_DBG("\n"); + blockH = buf->getHandle(); /* H 7 STYLE (hard pointer) */ + DRW_DBG("anon block Handle: "); DRW_DBGHL(blockH.code, blockH.size, blockH.ref); DRW_DBG("\n"); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + + // RS crc; //RS */ + return buf->isGood(); +} + +bool DRW_DimAngular3p::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dwgBuffer sBuff = *buf; + dwgBuffer *sBuf = buf; + if (version > DRW::AC1018) {//2007+ + sBuf = &sBuff; //separate buffer for strings + } + bool ret = DRW_Entity::parseDwg(version, buf, sBuf, bs); + if (!ret) + return ret; + ret = DRW_Dimension::parseDwg(version, buf, sBuf); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing dim angular3p *********************************************\n"); + DRW_Coord pt = buf->get3BitDouble(); + setDefPoint(pt); //code 10 + DRW_DBG("defPoint: "); DRW_DBGPT(pt.x, pt.y, pt.z); + pt = buf->get3BitDouble(); + setPt3(pt); //def1 code 13 + DRW_DBG("\ndef1: "); DRW_DBGPT(pt.x, pt.y, pt.z); + pt = buf->get3BitDouble(); + setPt4(pt); //def2 code 14 + DRW_DBG("\ndef2: "); DRW_DBGPT(pt.x, pt.y, pt.z); + pt = buf->get3BitDouble(); + setPt5(pt); //center pt code 15 + DRW_DBG("\ncenter point: "); DRW_DBGPT(pt.x, pt.y, pt.z); + type |= 0x05; + DRW_DBG("\n type (70) final: "); DRW_DBG(type); DRW_DBG("\n"); + + ret = DRW_Entity::parseDwgEntHandle(version, buf); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + if (!ret) + return ret; + dimStyleH = buf->getHandle(); + DRW_DBG("dim style Handle: "); DRW_DBGHL(dimStyleH.code, dimStyleH.size, dimStyleH.ref); DRW_DBG("\n"); + blockH = buf->getHandle(); /* H 7 STYLE (hard pointer) */ + DRW_DBG("anon block Handle: "); DRW_DBGHL(blockH.code, blockH.size, blockH.ref); DRW_DBG("\n"); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + + // RS crc; //RS */ + return buf->isGood(); +} + +bool DRW_DimOrdinate::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dwgBuffer sBuff = *buf; + dwgBuffer *sBuf = buf; + if (version > DRW::AC1018) {//2007+ + sBuf = &sBuff; //separate buffer for strings + } + bool ret = DRW_Entity::parseDwg(version, buf, sBuf, bs); + if (!ret) + return ret; + ret = DRW_Dimension::parseDwg(version, buf, sBuf); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing dim ordinate *********************************************\n"); + DRW_Coord pt = buf->get3BitDouble(); + setDefPoint(pt); + DRW_DBG("defPoint: "); DRW_DBGPT(pt.x, pt.y, pt.z); + pt = buf->get3BitDouble(); + setPt3(pt); //def1 + DRW_DBG("\ndef1: "); DRW_DBGPT(pt.x, pt.y, pt.z); + pt = buf->get3BitDouble(); + setPt4(pt); + DRW_DBG("\ndef2: "); DRW_DBGPT(pt.x, pt.y, pt.z); + duint8 type2 = buf->getRawChar8();//RLZ: correct this + DRW_DBG("type2 (70) read: "); DRW_DBG(type2); + type = (type2 & 1) ? type | 0x80 : type & 0xBF; //set bit 6 + DRW_DBG(" type (70) set: "); DRW_DBG(type); + type |= 6; + DRW_DBG("\n type (70) final: "); DRW_DBG(type); + + ret = DRW_Entity::parseDwgEntHandle(version, buf); DRW_DBG("\n"); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + if (!ret) + return ret; + dimStyleH = buf->getHandle(); + DRW_DBG("dim style Handle: "); DRW_DBGHL(dimStyleH.code, dimStyleH.size, dimStyleH.ref); DRW_DBG("\n"); + blockH = buf->getHandle(); /* H 7 STYLE (hard pointer) */ + DRW_DBG("anon block Handle: "); DRW_DBGHL(blockH.code, blockH.size, blockH.ref); DRW_DBG("\n"); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + + // RS crc; //RS */ + return buf->isGood(); +} + +void DRW_Leader::parseCode(int code, dxfReader *reader){ + switch (code) { + case 3: + style = reader->getUtf8String(); + break; + case 71: + arrow = reader->getInt32(); + break; + case 72: + leadertype = reader->getInt32(); + break; + case 73: + flag = reader->getInt32(); + break; + case 74: + hookline = reader->getInt32(); + break; + case 75: + hookflag = reader->getInt32(); + break; + case 76: + vertnum = reader->getInt32(); + break; + case 77: + coloruse = reader->getInt32(); + break; + case 40: + textheight = reader->getDouble(); + break; + case 41: + textwidth = reader->getDouble(); + break; + case 10: { + vertexpoint = new DRW_Coord(); + vertexlist.push_back(vertexpoint); + vertexpoint->x = reader->getDouble(); + break; } + case 20: + if(vertexpoint != NULL) + vertexpoint->y = reader->getDouble(); + break; + case 30: + if(vertexpoint != NULL) + vertexpoint->z = reader->getDouble(); + break; + case 340: + annotHandle = reader->getHandleString(); + break; + case 210: + extrusionPoint.x = reader->getDouble(); + break; + case 220: + extrusionPoint.y = reader->getDouble(); + break; + case 230: + extrusionPoint.z = reader->getDouble(); + break; + case 211: + horizdir.x = reader->getDouble(); + break; + case 221: + horizdir.y = reader->getDouble(); + break; + case 231: + horizdir.z = reader->getDouble(); + break; + case 212: + offsetblock.x = reader->getDouble(); + break; + case 222: + offsetblock.y = reader->getDouble(); + break; + case 232: + offsetblock.z = reader->getDouble(); + break; + case 213: + offsettext.x = reader->getDouble(); + break; + case 223: + offsettext.y = reader->getDouble(); + break; + case 233: + offsettext.z = reader->getDouble(); + break; + default: + DRW_Entity::parseCode(code, reader); + break; + } +} + +bool DRW_Leader::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dwgBuffer sBuff = *buf; + dwgBuffer *sBuf = buf; + if (version > DRW::AC1018) {//2007+ + sBuf = &sBuff; //separate buffer for strings + } + bool ret = DRW_Entity::parseDwg(version, buf, sBuf, bs); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing leader *********************************************\n"); + DRW_DBG("unknown bit "); DRW_DBG(buf->getBit()); + DRW_DBG(" annot type "); DRW_DBG(buf->getBitShort()); + DRW_DBG(" Path type "); DRW_DBG(buf->getBitShort()); + dint32 nPt = buf->getBitLong(); + DRW_DBG(" Num pts "); DRW_DBG(nPt); + + // add vertexs + for (int i = 0; i< nPt; i++){ + DRW_Coord* vertex = new DRW_Coord(buf->get3BitDouble()); + vertexlist.push_back(vertex); + DRW_DBG("\nvertex "); DRW_DBGPT(vertex->x, vertex->y, vertex->z); + } + DRW_Coord Endptproj = buf->get3BitDouble(); + DRW_DBG("\nEndptproj "); DRW_DBGPT(Endptproj.x, Endptproj.y, Endptproj.z); + extrusionPoint = buf->getExtrusion(version > DRW::AC1014); + DRW_DBG("\nextrusionPoint "); DRW_DBGPT(extrusionPoint.x, extrusionPoint.y, extrusionPoint.z); + if (version > DRW::AC1014) { //2000+ + DRW_DBG("\nFive unknown bits: "); DRW_DBG(buf->getBit()); DRW_DBG(buf->getBit()); + DRW_DBG(buf->getBit()); DRW_DBG(buf->getBit()); DRW_DBG(buf->getBit()); + } + horizdir = buf->get3BitDouble(); + DRW_DBG("\nhorizdir "); DRW_DBGPT(horizdir.x, horizdir.y, horizdir.z); + offsetblock = buf->get3BitDouble(); + DRW_DBG("\noffsetblock "); DRW_DBGPT(offsetblock.x, offsetblock.y, offsetblock.z); + if (version > DRW::AC1012) { //R14+ + DRW_Coord unk = buf->get3BitDouble(); + DRW_DBG("\nunknown "); DRW_DBGPT(unk.x, unk.y, unk.z); + } + if (version < DRW::AC1015) { //R14 - + DRW_DBG("\ndimgap "); DRW_DBG(buf->getBitDouble()); + } + if (version < DRW::AC1024) { //2010- + textheight = buf->getBitDouble(); + textwidth = buf->getBitDouble(); + DRW_DBG("\ntextheight "); DRW_DBG(textheight); DRW_DBG(" textwidth "); DRW_DBG(textwidth); + } + hookline = buf->getBit(); + arrow = buf->getBit(); + DRW_DBG(" hookline "); DRW_DBG(hookline); DRW_DBG(" arrow flag "); DRW_DBG(arrow); + + if (version < DRW::AC1015) { //R14 - + DRW_DBG("\nArrow head type "); DRW_DBG(buf->getBitShort()); + DRW_DBG("dimasz "); DRW_DBG(buf->getBitDouble()); + DRW_DBG("\nunk bit "); DRW_DBG(buf->getBit()); + DRW_DBG(" unk bit "); DRW_DBG(buf->getBit()); + DRW_DBG(" unk short "); DRW_DBG(buf->getBitShort()); + DRW_DBG(" byBlock color "); DRW_DBG(buf->getBitShort()); + DRW_DBG(" unk bit "); DRW_DBG(buf->getBit()); + DRW_DBG(" unk bit "); DRW_DBG(buf->getBit()); + } else { //R2000+ + DRW_DBG("\nunk short "); DRW_DBG(buf->getBitShort()); + DRW_DBG(" unk bit "); DRW_DBG(buf->getBit()); + DRW_DBG(" unk bit "); DRW_DBG(buf->getBit()); + } + DRW_DBG("\n"); + ret = DRW_Entity::parseDwgEntHandle(version, buf); + if (!ret) + return ret; + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + AnnotH = buf->getHandle(); + annotHandle = AnnotH.ref; + DRW_DBG("annot block Handle: "); DRW_DBGHL(AnnotH.code, AnnotH.size, dimStyleH.ref); DRW_DBG("\n"); + dimStyleH = buf->getHandle(); /* H 7 STYLE (hard pointer) */ + DRW_DBG("dim style Handle: "); DRW_DBGHL(dimStyleH.code, dimStyleH.size, dimStyleH.ref); DRW_DBG("\n"); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); +// RS crc; //RS */ + return buf->isGood(); +} + +void DRW_Viewport::parseCode(int code, dxfReader *reader){ + switch (code) { + case 40: + pswidth = reader->getDouble(); + break; + case 41: + psheight = reader->getDouble(); + break; + case 68: + vpstatus = reader->getInt32(); + break; + case 69: + vpID = reader->getInt32(); + break; + case 12: { + centerPX = reader->getDouble(); + break; } + case 22: + centerPY = reader->getDouble(); + break; + default: + DRW_Point::parseCode(code, reader); + break; + } +} +//ex 22 dec 34 +bool DRW_Viewport::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dwgBuffer sBuff = *buf; + dwgBuffer *sBuf = buf; + if (version > DRW::AC1018) {//2007+ + sBuf = &sBuff; //separate buffer for strings + } + bool ret = DRW_Entity::parseDwg(version, buf, sBuf, bs); + if (!ret) + return ret; + DRW_DBG("\n***************************** parsing viewport *****************************************\n"); + basePoint.x = buf->getBitDouble(); + basePoint.y = buf->getBitDouble(); + basePoint.z = buf->getBitDouble(); + DRW_DBG("center "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z); + pswidth = buf->getBitDouble(); + psheight = buf->getBitDouble(); + DRW_DBG("\nWidth: "); DRW_DBG(pswidth); DRW_DBG(", Height: "); DRW_DBG(psheight); DRW_DBG("\n"); + //RLZ TODO: complete in dxf + if (version > DRW::AC1014) {//2000+ + viewTarget.x = buf->getBitDouble(); + viewTarget.y = buf->getBitDouble(); + viewTarget.z = buf->getBitDouble(); + DRW_DBG("view Target "); DRW_DBGPT(viewTarget.x, viewTarget.y, viewTarget.z); + viewDir.x = buf->getBitDouble(); + viewDir.y = buf->getBitDouble(); + viewDir.z = buf->getBitDouble(); + DRW_DBG("\nview direction "); DRW_DBGPT(viewDir.x, viewDir.y, viewDir.z); + twistAngle = buf->getBitDouble(); + DRW_DBG("\nView twist Angle: "); DRW_DBG(twistAngle); + viewHeight = buf->getBitDouble(); + DRW_DBG("\nview Height: "); DRW_DBG(viewHeight); + viewLength = buf->getBitDouble(); + DRW_DBG(" Lens Length: "); DRW_DBG(viewLength); + frontClip = buf->getBitDouble(); + DRW_DBG("\nfront Clip Z: "); DRW_DBG(frontClip); + backClip = buf->getBitDouble(); + DRW_DBG(" back Clip Z: "); DRW_DBG(backClip); + snapAngle = buf->getBitDouble(); + DRW_DBG("\n snap Angle: "); DRW_DBG(snapAngle); + centerPX = buf->getRawDouble(); + centerPY = buf->getRawDouble(); + DRW_DBG("\nview center X: "); DRW_DBG(centerPX); DRW_DBG(", Y: "); DRW_DBG(centerPX); + snapPX = buf->getRawDouble(); + snapPY = buf->getRawDouble(); + DRW_DBG("\nSnap base point X: "); DRW_DBG(snapPX); DRW_DBG(", Y: "); DRW_DBG(snapPY); + snapSpPX = buf->getRawDouble(); + snapSpPY = buf->getRawDouble(); + DRW_DBG("\nSnap spacing X: "); DRW_DBG(snapSpPX); DRW_DBG(", Y: "); DRW_DBG(snapSpPY); + //RLZ: need to complete + DRW_DBG("\nGrid spacing X: "); DRW_DBG(buf->getRawDouble()); DRW_DBG(", Y: "); DRW_DBG(buf->getRawDouble());DRW_DBG("\n"); + DRW_DBG("Circle zoom?: "); DRW_DBG(buf->getBitShort()); DRW_DBG("\n"); + } + if (version > DRW::AC1018) {//2007+ + DRW_DBG("Grid major?: "); DRW_DBG(buf->getBitShort()); DRW_DBG("\n"); + } + if (version > DRW::AC1014) {//2000+ + frozenLyCount = buf->getBitLong(); + DRW_DBG("Frozen Layer count?: "); DRW_DBG(frozenLyCount); DRW_DBG("\n"); + DRW_DBG("Status Flags?: "); DRW_DBG(buf->getBitLong()); DRW_DBG("\n"); + //RLZ: Warning needed separate string bufer + DRW_DBG("Style sheet?: "); DRW_DBG(sBuf->getVariableText(version, false)); DRW_DBG("\n"); + DRW_DBG("Render mode?: "); DRW_DBG(buf->getRawChar8()); DRW_DBG("\n"); + DRW_DBG("UCS OMore...: "); DRW_DBG(buf->getBit()); DRW_DBG("\n"); + DRW_DBG("UCS VMore...: "); DRW_DBG(buf->getBit()); DRW_DBG("\n"); + DRW_DBG("UCS OMore...: "); DRW_DBGPT(buf->getBitDouble(), buf->getBitDouble(), buf->getBitDouble()); DRW_DBG("\n"); + DRW_DBG("ucs XAMore...: "); DRW_DBGPT(buf->getBitDouble(), buf->getBitDouble(), buf->getBitDouble()); DRW_DBG("\n"); + DRW_DBG("UCS YMore....: "); DRW_DBGPT(buf->getBitDouble(), buf->getBitDouble(), buf->getBitDouble()); DRW_DBG("\n"); + DRW_DBG("UCS EMore...: "); DRW_DBG(buf->getBitDouble()); DRW_DBG("\n"); + DRW_DBG("UCS OVMore...: "); DRW_DBG(buf->getBitShort()); DRW_DBG("\n"); + } + if (version > DRW::AC1015) {//2004+ + DRW_DBG("ShadePlot Mode...: "); DRW_DBG(buf->getBitShort()); DRW_DBG("\n"); + } + if (version > DRW::AC1018) {//2007+ + DRW_DBG("Use def Ligth...: "); DRW_DBG(buf->getBit()); DRW_DBG("\n"); + DRW_DBG("Def ligth tipe?: "); DRW_DBG(buf->getRawChar8()); DRW_DBG("\n"); + DRW_DBG("Brightness: "); DRW_DBG(buf->getBitDouble()); DRW_DBG("\n"); + DRW_DBG("Contrast: "); DRW_DBG(buf->getBitDouble()); DRW_DBG("\n"); +// DRW_DBG("Ambient Cmc or Enc: "); DRW_DBG(buf->getCmColor(version)); DRW_DBG("\n"); + DRW_DBG("Ambient (Cmc or Enc?), Enc: "); DRW_DBG(buf->getEnColor(version)); DRW_DBG("\n"); + } + ret = DRW_Entity::parseDwgEntHandle(version, buf); + + dwgHandle someHdl; + if (version < DRW::AC1015) {//R13 & R14 only + DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + someHdl = buf->getHandle(); + DRW_DBG("ViewPort ent header: "); DRW_DBGHL(someHdl.code, someHdl.size, someHdl.ref); DRW_DBG("\n"); + } + if (version > DRW::AC1014) {//2000+ + for (duint8 i=0; i < frozenLyCount; ++i){ + someHdl = buf->getHandle(); + DRW_DBG("Frozen layer handle "); DRW_DBG(i); DRW_DBG(": "); DRW_DBGHL(someHdl.code, someHdl.size, someHdl.ref); DRW_DBG("\n"); + } + someHdl = buf->getHandle(); + DRW_DBG("Clip bpundary handle: "); DRW_DBGHL(someHdl.code, someHdl.size, someHdl.ref); DRW_DBG("\n"); + if (version == DRW::AC1015) {//2000 only + someHdl = buf->getHandle(); + DRW_DBG("ViewPort ent header: "); DRW_DBGHL(someHdl.code, someHdl.size, someHdl.ref); DRW_DBG("\n"); + } + someHdl = buf->getHandle(); + DRW_DBG("Named ucs handle: "); DRW_DBGHL(someHdl.code, someHdl.size, someHdl.ref); DRW_DBG("\n"); + DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + someHdl = buf->getHandle(); + DRW_DBG("base ucs handle: "); DRW_DBGHL(someHdl.code, someHdl.size, someHdl.ref); DRW_DBG("\n"); + } + if (version > DRW::AC1018) {//2007+ + someHdl = buf->getHandle(); + DRW_DBG("background handle: "); DRW_DBGHL(someHdl.code, someHdl.size, someHdl.ref); DRW_DBG("\n"); + someHdl = buf->getHandle(); + DRW_DBG("visual style handle: "); DRW_DBGHL(someHdl.code, someHdl.size, someHdl.ref); DRW_DBG("\n"); + someHdl = buf->getHandle(); + DRW_DBG("shadeplot ID handle: "); DRW_DBGHL(someHdl.code, someHdl.size, someHdl.ref); DRW_DBG("\n"); + DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + someHdl = buf->getHandle(); + DRW_DBG("SUN handle: "); DRW_DBGHL(someHdl.code, someHdl.size, someHdl.ref); DRW_DBG("\n"); + } + DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + + if (!ret) + return ret; + return buf->isGood(); +} diff --git a/src/libs/vdxf/libdxfrw/drw_entities.h b/src/libs/vdxf/libdxfrw/drw_entities.h new file mode 100644 index 000000000..912967e5b --- /dev/null +++ b/src/libs/vdxf/libdxfrw/drw_entities.h @@ -0,0 +1,1572 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#ifndef DRW_ENTITIES_H +#define DRW_ENTITIES_H + + +#include +#include +#include +#include "drw_base.h" + +class dxfReader; +class dwgBuffer; +class DRW_Polyline; + +namespace DRW { + + //! Entity's type. + enum ETYPE { + E3DFACE, +// E3DSOLID, //encripted propietry data +// ACAD_PROXY_ENTITY, + ARC, +// ATTDEF, +// ATTRIB, + BLOCK,// and ENDBLK +// BODY, //encripted propietry data + CIRCLE, + DIMENSION, + DIMALIGNED, + DIMLINEAR, + DIMRADIAL, + DIMDIAMETRIC, + DIMANGULAR, + DIMANGULAR3P, + DIMORDINATE, + ELLIPSE, + HATCH, +// HELIX, + IMAGE, + INSERT, + LEADER, +// LIGHT, + LINE, + LWPOLYLINE, +// MESH, +// MLINE, +// MLEADERSTYLE, +// MLEADER, + MTEXT, +// OLEFRAME, +// OLE2FRAME, + POINT, + POLYLINE, + RAY, +// REGION, //encripted propietry data +// SECTION, +// SEQEND,//not needed?? used in polyline and insert/attrib and dwg +// SHAPE, + SOLID, + SPLINE, +// SUN, +// SURFACE, //encripted propietry data can be four types +// TABLE, + TEXT, +// TOLERANCE, + TRACE, + UNDERLAY, + VERTEX, + VIEWPORT, +// WIPEOUT, //WIPEOUTVARIABLE + XLINE, + UNKNOWN + }; + +} +//only in DWG: MINSERT, 5 types of vertex, 4 types of polylines: 2d, 3d, pface & mesh +//shape, dictionary, MLEADER, MLEADERSTYLE + +#define SETENTFRIENDS friend class dxfRW; \ + friend class dwgReader; + +//! Base class for entities +/*! +* Base class for entities +* @author Rallaz +*/ +class DRW_Entity { + SETENTFRIENDS +public: + //initializes default values + DRW_Entity() { + eType = DRW::UNKNOWN; + handle = parentHandle = DRW::NoHandle; //no handle (0) + lineType = "BYLAYER"; + color = DRW::ColorByLayer; // default BYLAYER (256) + ltypeScale = 1.0; + visible = true; + layer = "0"; + lWeight = DRW_LW_Conv::widthByLayer; // default BYLAYER (dxf -1, dwg 29) + space = DRW::ModelSpace; // default ModelSpace (0) + haveExtrusion = false; + color24 = -1; //default -1 not set + numProxyGraph = 0; + shadow = DRW::CastAndReceieveShadows; + material = DRW::MaterialByLayer; + plotStyle = DRW::DefaultPlotStyle; + transparency = DRW::Opaque; + nextEntLink = prevEntLink = 0; + numReactors = xDictFlag = 0; + curr = NULL; + ownerHandle= false; + } + + DRW_Entity(const DRW_Entity& e) { + eType = e.eType; + handle = e.handle; + parentHandle = e.parentHandle; //no handle (0) + lineType = e.lineType; + color = e.color; // default BYLAYER (256) + ltypeScale = e.ltypeScale; + visible = e.visible; + layer = e.layer; + lWeight = e.lWeight; + space = e.space; + haveExtrusion = e.haveExtrusion; + color24 = e.color24; //default -1 not set + numProxyGraph = e.numProxyGraph; + shadow = e.shadow; + material = e.material; + plotStyle = e.plotStyle; + transparency = e.transparency; + nextEntLink = e.nextEntLink; + prevEntLink = e.prevEntLink; + numReactors = e.numReactors; + xDictFlag = e.xDictFlag; + curr = NULL; + ownerHandle= false; +// curr = e.curr; + for (std::vector::const_iterator it=e.extData.begin(); it!=e.extData.end(); ++it){ + extData.push_back(new DRW_Variant(*(*it))); + } + } + + virtual ~DRW_Entity() { + for (std::vector::iterator it=extData.begin(); it!=extData.end(); ++it) + delete *it; + + extData.clear(); + } + + void reset(){ + for (std::vector::iterator it=extData.begin(); it!=extData.end(); ++it) + delete *it; + extData.clear(); + } + + virtual void applyExtrusion() = 0; + + void setWidthMm(double millimeters) { + if(millimeters < 0.0) { + lWeight = DRW_LW_Conv::widthByLayer; + return; + } + if(millimeters > 2.11) millimeters = 2.11; + lWeight = DRW_LW_Conv::dxfInt2lineWidth(int(floor(millimeters * 100.0))); + } + +protected: + //parses dxf pair to read entity + bool parseCode(int code, dxfReader *reader); + //calculates extrusion axis (normal vector) + void calculateAxis(DRW_Coord extPoint); + //apply extrusion to @extPoint and return data in @point + void extrudePoint(DRW_Coord extPoint, DRW_Coord *point); + virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0)=0; + //parses dwg common start part to read entity + bool parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer* strBuf, duint32 bs=0); + //parses dwg common handles part to read entity + bool parseDwgEntHandle(DRW::Version version, dwgBuffer *buf); + + //parses dxf 102 groups to read entity + bool parseDxfGroups(int code, dxfReader *reader); + +public: + enum DRW::ETYPE eType; /*!< enum: entity type, code 0 */ + duint32 handle; /*!< entity identifier, code 5 */ + std::list > appData; /*!< list of application data, code 102 */ + duint32 parentHandle; /*!< Soft-pointer ID/handle to owner BLOCK_RECORD object, code 330 */ + DRW::Space space; /*!< space indicator, code 67*/ + UTF8STRING layer; /*!< layer name, code 8 */ + UTF8STRING lineType; /*!< line type, code 6 */ + duint32 material; /*!< hard pointer id to material object, code 347 */ + int color; /*!< entity color, code 62 */ + enum DRW_LW_Conv::lineWidth lWeight; /*!< entity lineweight, code 370 */ + double ltypeScale; /*!< linetype scale, code 48 */ + bool visible; /*!< entity visibility, code 60 */ + int numProxyGraph; /*!< Number of bytes in proxy graphics, code 92 */ + std::string proxyGraphics; /*!< proxy graphics bytes, code 310 */ + int color24; /*!< 24-bit color, code 420 */ + std::string colorName; /*!< color name, code 430 */ + int transparency; /*!< transparency, code 440 */ + int plotStyle; /*!< hard pointer id to plot style object, code 390 */ + DRW::ShadowMode shadow; /*!< shadow mode, code 284 */ + bool haveExtrusion; /*!< set to true if the entity have extrusion*/ + std::vector extData; /*!< FIFO list of extended data, codes 1000 to 1071*/ + +protected: //only for read dwg + duint8 haveNextLinks; //aka nolinks //B + duint8 plotFlags; //presence of plot style //BB + duint8 ltFlags; //presence of linetype handle //BB + duint8 materialFlag; //presence of material handle //BB + duint8 shadowFlag; //presence of shadow handle ?? (in dwg may be plotflag)//RC + dwgHandle lTypeH; + dwgHandle layerH; + duint32 nextEntLink; + duint32 prevEntLink; + bool ownerHandle; + + duint8 xDictFlag; + dint32 numReactors; // + duint32 objSize; //RL 32bits object data size in bits + dint16 oType; + +private: + DRW_Coord extAxisX; + DRW_Coord extAxisY; + DRW_Variant* curr; +}; + + +//! Class to handle point entity +/*! +* Class to handle point entity +* @author Rallaz +*/ +class DRW_Point : public DRW_Entity { + SETENTFRIENDS +public: + DRW_Point() { + eType = DRW::POINT; + basePoint.z = extPoint.x = extPoint.y = 0; + extPoint.z = 1; + thickness = 0; + } + + virtual void applyExtrusion(){} + +protected: + void parseCode(int code, dxfReader *reader); + virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); + +public: + DRW_Coord basePoint; /*!< base point, code 10, 20 & 30 */ + double thickness; /*!< thickness, code 39 */ + DRW_Coord extPoint; /*!< Dir extrusion normal vector, code 210, 220 & 230 */ + // TNick: we're not handling code 50 - Angle of the X axis for + // the UCS in effect when the point was drawn +}; + +//! Class to handle line entity +/*! +* Class to handle line entity +* @author Rallaz +*/ +class DRW_Line : public DRW_Point { + SETENTFRIENDS +public: + DRW_Line() { + eType = DRW::LINE; + secPoint.z = 0; + } + + virtual void applyExtrusion(){} + +protected: + void parseCode(int code, dxfReader *reader); + virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); + +public: + DRW_Coord secPoint; /*!< second point, code 11, 21 & 31 */ +}; + +//! Class to handle ray entity +/*! +* Class to handle ray entity +* @author Rallaz +*/ +class DRW_Ray : public DRW_Line { + SETENTFRIENDS +public: + DRW_Ray() { + eType = DRW::RAY; + } +protected: + virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); +}; + +//! Class to handle xline entity +/*! +* Class to handle xline entity +* @author Rallaz +*/ +class DRW_Xline : public DRW_Ray { +public: + DRW_Xline() { + eType = DRW::XLINE; + } +}; + +//! Class to handle circle entity +/*! +* Class to handle circle entity +* @author Rallaz +*/ +class DRW_Circle : public DRW_Point { + SETENTFRIENDS +public: + DRW_Circle() { + eType = DRW::CIRCLE; + } + + virtual void applyExtrusion(); + +protected: + void parseCode(int code, dxfReader *reader); + virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); + +public: + double radious; /*!< radius, code 40 */ +}; + +//! Class to handle arc entity +/*! +* Class to handle arc entity +* @author Rallaz +*/ +class DRW_Arc : public DRW_Circle { + SETENTFRIENDS +public: + DRW_Arc() { + eType = DRW::ARC; + isccw = 1; + } + + virtual void applyExtrusion(); + + //! center point in OCS + const DRW_Coord & center() { return basePoint; } + //! the radius of the circle + double radius() { return radious; } + //! start angle in radians + double startAngle() { return staangle; } + //! end angle in radians + double endAngle() { return endangle; } + //! thickness + double thick() { return thickness; } + //! extrusion + const DRW_Coord & extrusion() { return extPoint; } + +protected: + //! interpret code in dxf reading process or dispatch to inherited class + void parseCode(int code, dxfReader *reader); + //! interpret dwg data (was already determined to be part of this object) + virtual bool parseDwg(DRW::Version v, dwgBuffer *buf, duint32 bs=0); + +public: + double staangle; /*!< start angle, code 50 in radians*/ + double endangle; /*!< end angle, code 51 in radians */ + int isccw; /*!< is counter clockwise arc?, only used in hatch, code 73 */ +}; + +//! Class to handle ellipse entity +/*! +* Class to handle ellipse and elliptic arc entity +* Note: start/end parameter are in radians for ellipse entity but +* for hatch boundary are in degrees +* @author Rallaz +*/ +class DRW_Ellipse : public DRW_Line { + SETENTFRIENDS +public: + DRW_Ellipse() { + eType = DRW::ELLIPSE; + isccw = 1; + } + + void toPolyline(DRW_Polyline *pol, int parts = 128); + virtual void applyExtrusion(); + +protected: + //! interpret code in dxf reading process or dispatch to inherited class + void parseCode(int code, dxfReader *reader); + //! interpret dwg data (was already determined to be part of this object) + virtual bool parseDwg(DRW::Version v, dwgBuffer *buf, duint32 bs=0); + +private: + void correctAxis(); + +public: + double ratio; /*!< ratio, code 40 */ + double staparam; /*!< start parameter, code 41, 0.0 for full ellipse*/ + double endparam; /*!< end parameter, code 42, 2*PI for full ellipse */ + int isccw; /*!< is counter clockwise arc?, only used in hatch, code 73 */ +}; + +//! Class to handle trace entity +/*! +* Class to handle trace entity +* @author Rallaz +*/ +class DRW_Trace : public DRW_Line { + SETENTFRIENDS +public: + DRW_Trace() { + eType = DRW::TRACE; + thirdPoint.z = 0; + fourPoint.z = 0; + } + + virtual void applyExtrusion(); + +protected: + void parseCode(int code, dxfReader *reader); + virtual bool parseDwg(DRW::Version v, dwgBuffer *buf, duint32 bs=0); + +public: + DRW_Coord thirdPoint; /*!< third point, code 12, 22 & 32 */ + DRW_Coord fourPoint; /*!< four point, code 13, 23 & 33 */ +}; + +//! Class to handle solid entity +/*! +* Class to handle solid entity +* @author Rallaz +*/ +class DRW_Solid : public DRW_Trace { + SETENTFRIENDS +public: + DRW_Solid() { + eType = DRW::SOLID; + } + +protected: + //! interpret code in dxf reading process or dispatch to inherited class + void parseCode(int code, dxfReader *reader); + //! interpret dwg data (was already determined to be part of this object) + virtual bool parseDwg(DRW::Version v, dwgBuffer *buf, duint32 bs=0); + +public: + //! first corner (2D) + const DRW_Coord & firstCorner() { return basePoint; } + //! second corner (2D) + const DRW_Coord & secondCorner() { return secPoint; } + //! third corner (2D) + const DRW_Coord & thirdCorner() { return thirdPoint; } + //! fourth corner (2D) + const DRW_Coord & fourthCorner() { return thirdPoint; } + //! thickness + double thick() { return thickness; } + //! elevation + double elevation() { return basePoint.z; } + //! extrusion + const DRW_Coord & extrusion() { return extPoint; } + +}; + +//! Class to handle 3dface entity +/*! +* Class to handle 3dface entity +* @author Rallaz +*/ +class DRW_3Dface : public DRW_Trace { + SETENTFRIENDS +public: + enum InvisibleEdgeFlags { + NoEdge = 0x00, + FirstEdge = 0x01, + SecodEdge = 0x02, + ThirdEdge = 0x04, + FourthEdge = 0x08, + AllEdges = 0x0F + }; + + DRW_3Dface() { + eType = DRW::E3DFACE; + invisibleflag = 0; + } + + virtual void applyExtrusion(){} + + //! first corner in WCS + const DRW_Coord & firstCorner() { return basePoint; } + //! second corner in WCS + const DRW_Coord & secondCorner() { return secPoint; } + //! third corner in WCS + const DRW_Coord & thirdCorner() { return thirdPoint; } + //! fourth corner in WCS + const DRW_Coord & fourthCorner() { return fourPoint; } + //! edge visibility flags + InvisibleEdgeFlags edgeFlags() { return (InvisibleEdgeFlags)invisibleflag; } + +protected: + //! interpret code in dxf reading process or dispatch to inherited class + void parseCode(int code, dxfReader *reader); + //! interpret dwg data (was already determined to be part of this object) + virtual bool parseDwg(DRW::Version v, dwgBuffer *buf, duint32 bs=0); + +public: + int invisibleflag; /*!< invisible edge flag, code 70 */ + +}; + +//! Class to handle block entries +/*! +* Class to handle block entries +* @author Rallaz +*/ +class DRW_Block : public DRW_Point { + SETENTFRIENDS +public: + DRW_Block() { + eType = DRW::BLOCK; + layer = "0"; + flags = 0; + name = "*U0"; + isEnd = false; + } + + virtual void applyExtrusion(){} + +protected: + void parseCode(int code, dxfReader *reader); + virtual bool parseDwg(DRW::Version v, dwgBuffer *buf, duint32 bs=0); + +public: + UTF8STRING name; /*!< block name, code 2 */ + int flags; /*!< block type, code 70 */ +private: + bool isEnd; //for dwg parsing +}; + + +//! Class to handle insert entries +/*! +* Class to handle insert entries +* @author Rallaz +*/ +class DRW_Insert : public DRW_Point { + SETENTFRIENDS +public: + DRW_Insert() { + eType = DRW::INSERT; + xscale = 1; + yscale = 1; + zscale = 1; + angle = 0; + colcount = 1; + rowcount = 1; + colspace = 0; + rowspace = 0; + } + + virtual void applyExtrusion(){DRW_Point::applyExtrusion();} + +protected: + void parseCode(int code, dxfReader *reader); + virtual bool parseDwg(DRW::Version v, dwgBuffer *buf, duint32 bs=0); + +public: + UTF8STRING name; /*!< block name, code 2 */ + double xscale; /*!< x scale factor, code 41 */ + double yscale; /*!< y scale factor, code 42 */ + double zscale; /*!< z scale factor, code 43 */ + double angle; /*!< rotation angle in radians, code 50 */ + int colcount; /*!< column count, code 70 */ + int rowcount; /*!< row count, code 71 */ + double colspace; /*!< column space, code 44 */ + double rowspace; /*!< row space, code 45 */ +public: //only for read dwg + dwgHandle blockRecH; + dwgHandle seqendH; //RLZ: on implement attrib remove this handle from obj list (see pline/vertex code) +}; + +//! Class to handle lwpolyline entity +/*! +* Class to handle lwpolyline entity +* @author Rallaz +*/ +class DRW_LWPolyline : public DRW_Entity { + SETENTFRIENDS +public: + DRW_LWPolyline() { + eType = DRW::LWPOLYLINE; + elevation = thickness = width = 0.0; + flags = 0; + extPoint.x = extPoint.y = 0; + extPoint.z = 1; + vertex = NULL; + } + + DRW_LWPolyline(const DRW_LWPolyline& p):DRW_Entity(p){ + this->eType = DRW::LWPOLYLINE; + this->elevation = p.elevation; + this->thickness = p.thickness; + this->width = p.width; + this->flags = p.flags; + this->extPoint = p.extPoint; + this->vertex = NULL; + for (unsigned i=0; ivertlist.push_back( new DRW_Vertex2D( *(p.vertlist.at(i)) ) ); + + this->vertex = NULL; + } + + ~DRW_LWPolyline() { + for(DRW_Vertex2D *item : vertlist) delete item; + } + virtual void applyExtrusion(); + void addVertex (DRW_Vertex2D v) { + DRW_Vertex2D *vert = new DRW_Vertex2D(); + vert->x = v.x; + vert->y = v.y; + vert->stawidth = v.stawidth; + vert->endwidth = v.endwidth; + vert->bulge = v.bulge; + vertlist.push_back(vert); + } + DRW_Vertex2D *addVertex () { + DRW_Vertex2D *vert = new DRW_Vertex2D(); + vert->stawidth = 0; + vert->endwidth = 0; + vert->bulge = 0; + vertlist.push_back(vert); + return vert; + } + +protected: + void parseCode(int code, dxfReader *reader); + bool parseDwg(DRW::Version v, dwgBuffer *buf, duint32 bs=0); + +public: + int vertexnum; /*!< number of vertex, code 90 */ + int flags; /*!< polyline flag, code 70, default 0 */ + double width; /*!< constant width, code 43 */ + double elevation; /*!< elevation, code 38 */ + double thickness; /*!< thickness, code 39 */ + DRW_Coord extPoint; /*!< Dir extrusion normal vector, code 210, 220 & 230 */ + DRW_Vertex2D *vertex; /*!< current vertex to add data */ + std::vector vertlist; /*!< vertex list */ +}; + +//! Class to handle insert entries +/*! +* Class to handle insert entries +* @author Rallaz +*/ +class DRW_Text : public DRW_Line { + SETENTFRIENDS +public: + //! Vertical alignments. + enum VAlign { + VBaseLine = 0, /*!< Top = 0 */ + VBottom, /*!< Bottom = 1 */ + VMiddle, /*!< Middle = 2 */ + VTop /*!< Top = 3 */ + }; + + //! Horizontal alignments. + enum HAlign { + HLeft = 0, /*!< Left = 0 */ + HCenter, /*!< Centered = 1 */ + HRight, /*!< Right = 2 */ + HAligned, /*!< Aligned = 3 (if VAlign==0) */ + HMiddle, /*!< middle = 4 (if VAlign==0) */ + HFit /*!< fit into point = 5 (if VAlign==0) */ + }; + + DRW_Text() { + eType = DRW::TEXT; + angle = 0; + widthscale = 1; + oblique = 0; + style = "STANDARD"; + textgen = 0; + alignH = HLeft; + alignV = VBaseLine; + } + + virtual void applyExtrusion(){} //RLZ TODO + +protected: + void parseCode(int code, dxfReader *reader); + virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); + +public: + double height; /*!< height text, code 40 */ + UTF8STRING text; /*!< text string, code 1 */ + double angle; /*!< rotation angle in degrees (360), code 50 */ + double widthscale; /*!< width factor, code 41 */ + double oblique; /*!< oblique angle, code 51 */ + UTF8STRING style; /*!< style name, code 7 */ + int textgen; /*!< text generation, code 71 */ + enum HAlign alignH; /*!< horizontal align, code 72 */ + enum VAlign alignV; /*!< vertical align, code 73 */ + dwgHandle styleH; /*!< handle for text style */ +}; + +//! Class to handle insert entries +/*! +* Class to handle insert entries +* @author Rallaz +*/ +class DRW_MText : public DRW_Text { + SETENTFRIENDS +public: + //! Attachments. + enum Attach { + TopLeft = 1, + TopCenter, + TopRight, + MiddleLeft, + MiddleCenter, + MiddleRight, + BottomLeft, + BottomCenter, + BottomRight + }; + + DRW_MText() { + eType = DRW::MTEXT; + interlin = 1; + alignV = (VAlign)TopLeft; + textgen = 1; + haveXAxis = false; //if true needed to recalculate angle + } + +protected: + void parseCode(int code, dxfReader *reader); + void updateAngle(); //recalculate angle if 'haveXAxis' is true + virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); + +public: + double interlin; /*!< width factor, code 44 */ +private: + bool haveXAxis; +}; + +//! Class to handle vertex +/*! +* Class to handle vertex for polyline entity +* @author Rallaz +*/ +class DRW_Vertex : public DRW_Point { + SETENTFRIENDS +public: + DRW_Vertex() { + eType = DRW::VERTEX; + stawidth = endwidth = bulge = 0; + vindex1 = vindex2 = vindex3 = vindex4 = 0; + flags = identifier = 0; + } + DRW_Vertex(double sx, double sy, double sz, double b) { + stawidth = endwidth = 0; + vindex1 = vindex2 = vindex3 = vindex4 = 0; + flags = identifier = 0; + basePoint.x = sx; + basePoint.y =sy; + basePoint.z =sz; + bulge = b; + } + +protected: + void parseCode(int code, dxfReader *reader); + bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0, double el=0); + virtual bool parseDwg(DRW::Version version, dwgBuffer* buf, duint32 bs=0){ + DRW_UNUSED(version); DRW_UNUSED(buf); DRW_UNUSED(bs); return true;} + +public: + double stawidth; /*!< Start width, code 40 */ + double endwidth; /*!< End width, code 41 */ + double bulge; /*!< bulge, code 42 */ + + int flags; /*!< vertex flag, code 70, default 0 */ + double tgdir; /*!< curve fit tangent direction, code 50 */ + int vindex1; /*!< polyface mesh vertex index, code 71, default 0 */ + int vindex2; /*!< polyface mesh vertex index, code 72, default 0 */ + int vindex3; /*!< polyface mesh vertex index, code 73, default 0 */ + int vindex4; /*!< polyface mesh vertex index, code 74, default 0 */ + int identifier; /*!< vertex identifier, code 91, default 0 */ +}; + +//! Class to handle polyline entity +/*! +* Class to handle polyline entity +* @author Rallaz +*/ +class DRW_Polyline : public DRW_Point { + SETENTFRIENDS +public: + DRW_Polyline() { + eType = DRW::POLYLINE; + defstawidth = defendwidth = 0.0; + basePoint.x = basePoint.y = 0.0; + flags = vertexcount = facecount = 0; + smoothM = smoothN = curvetype = 0; + } + + DRW_Polyline(const DRW_Polyline& p) : DRW_Point(p) { + flags = p.flags ; + defstawidth = p.defstawidth; + defendwidth = p.defendwidth; + vertexcount = p.vertexcount; + facecount = p.facecount ; + smoothM = p.smoothM ; + smoothN = p.smoothN ; + curvetype = p.curvetype ; + for (unsigned i=0; ivertlist.push_back( new DRW_Vertex( *(p.vertlist.at(i)) ) ); + } + + ~DRW_Polyline() { + for(DRW_Vertex *item : vertlist) delete item; + } + void addVertex (DRW_Vertex v) { + DRW_Vertex *vert = new DRW_Vertex(); + vert->basePoint.x = v.basePoint.x; + vert->basePoint.y = v.basePoint.y; + vert->basePoint.z = v.basePoint.z; + vert->stawidth = v.stawidth; + vert->endwidth = v.endwidth; + vert->bulge = v.bulge; + vertlist.push_back(vert); + } + void appendVertex (DRW_Vertex *v) { + vertlist.push_back(v); + } + +protected: + void parseCode(int code, dxfReader *reader); + virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); + +public: + int flags; /*!< polyline flag, code 70, default 0 */ + double defstawidth; /*!< Start width, code 40, default 0 */ + double defendwidth; /*!< End width, code 41, default 0 */ + int vertexcount; /*!< polygon mesh M vertex or polyface vertex num, code 71, default 0 */ + int facecount; /*!< polygon mesh N vertex or polyface face num, code 72, default 0 */ + int smoothM; /*!< smooth surface M density, code 73, default 0 */ + int smoothN; /*!< smooth surface M density, code 74, default 0 */ + int curvetype; /*!< curves & smooth surface type, code 75, default 0 */ + + std::vector vertlist; /*!< vertex list */ + +private: + std::listhadlesList; //list of handles, only in 2004+ + duint32 firstEH; //handle of first entity, only in pre-2004 + duint32 lastEH; //handle of last entity, only in pre-2004 + dwgHandle seqEndH; //handle of SEQEND entity +}; + + +//! Class to handle spline entity +/*! +* Class to handle spline entity +* @author Rallaz +*/ +class DRW_Spline : public DRW_Entity { + SETENTFRIENDS +public: + DRW_Spline() { + eType = DRW::SPLINE; + flags = nknots = ncontrol = nfit = 0; + tolknot = tolcontrol = tolfit = 0.0000001; + + } + + DRW_Spline(const DRW_Spline& p):DRW_Entity(p){ + eType = DRW::SPLINE; + normalVec = p.normalVec ; + tgStart = p.tgStart ; + tgEnd = p.tgEnd ; + flags = p.flags ; + degree = p.degree ; + nknots = p.nknots ; + ncontrol = p.ncontrol ; + nfit = p.nfit ; + tolknot = p.tolknot ; + tolcontrol = p.tolcontrol; + tolfit = p.tolfit ; + + for(double v : p.knotslist) knotslist.push_back(v); + for(double v : p.weightlist) weightlist.push_back(v); + for(DRW_Coord *v : p.controllist) controllist.push_back(new DRW_Coord(*v)); + for(DRW_Coord *v : p.fitlist) fitlist.push_back(new DRW_Coord(*v)); + } + + ~DRW_Spline() { + for(DRW_Coord *item : controllist) delete item; + for(DRW_Coord *item : fitlist) delete item; + } + virtual void applyExtrusion(){} + +protected: + void parseCode(int code, dxfReader *reader); + virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); + +public: +// double ex; /*!< normal vector x coordinate, code 210 */ +// double ey; /*!< normal vector y coordinate, code 220 */ +// double ez; /*!< normal vector z coordinate, code 230 */ + DRW_Coord normalVec; /*!< normal vector, code 210, 220, 230 */ + DRW_Coord tgStart; /*!< start tangent, code 12, 22, 32 */ +// double tgsx; /*!< start tangent x coordinate, code 12 */ +// double tgsy; /*!< start tangent y coordinate, code 22 */ +// double tgsz; /*!< start tangent z coordinate, code 32 */ + DRW_Coord tgEnd; /*!< end tangent, code 13, 23, 33 */ +// double tgex; /*!< end tangent x coordinate, code 13 */ +// double tgey; /*!< end tangent y coordinate, code 23 */ +// double tgez; /*!< end tangent z coordinate, code 33 */ + int flags; /*!< spline flag, code 70 */ + int degree; /*!< degree of the spline, code 71 */ + dint32 nknots; /*!< number of knots, code 72, default 0 */ + dint32 ncontrol; /*!< number of control points, code 73, default 0 */ + dint32 nfit; /*!< number of fit points, code 74, default 0 */ + double tolknot; /*!< knot tolerance, code 42, default 0.0000001 */ + double tolcontrol; /*!< control point tolerance, code 43, default 0.0000001 */ + double tolfit; /*!< fit point tolerance, code 44, default 0.0000001 */ + + std::vector knotslist; /*!< knots list, code 40 */ + std::vector weightlist; /*!< weight list, code 41 */ + std::vector controllist; /*!< control points list, code 10, 20 & 30 */ + std::vector fitlist; /*!< fit points list, code 11, 21 & 31 */ + +private: + DRW_Coord *controlpoint; /*!< current control point to add data */ + DRW_Coord *fitpoint; /*!< current fit point to add data */ +}; + +//! Class to handle hatch loop +/*! +* Class to handle hatch loop +* @author Rallaz +*/ +class DRW_HatchLoop { +public: + DRW_HatchLoop(int t) { + type = t; + numedges = 0; + } + + ~DRW_HatchLoop() { + // for(DRW_LWPolyline *item : pollist) delete item; + for(DRW_Entity *item : objlist) delete item; + } + + void update() { + numedges = (int)objlist.size(); + } + +public: + int type; /*!< boundary path type, code 92, polyline=2, default=0 */ + int numedges; /*!< number of edges (if not a polyline), code 93 */ +//TODO: store lwpolylines as entities +// std::vector pollist; /*!< polyline list */ + std::vector objlist; /*!< entities list */ +}; + +//! Class to handle hatch entity +/*! +* Class to handle hatch entity +* @author Rallaz +*/ +//TODO: handle lwpolylines, splines and ellipses +class DRW_Hatch : public DRW_Point { + SETENTFRIENDS +public: + DRW_Hatch() { + eType = DRW::HATCH; + angle = scale = 0.0; + basePoint.x = basePoint.y = basePoint.z = 0.0; + loopsnum = hstyle = associative = 0; + solid = hpattern = 1; + deflines = doubleflag = 0; + loop = NULL; + clearEntities(); + } + + ~DRW_Hatch() { + for(DRW_HatchLoop *item : looplist) delete item; + } + + void appendLoop (DRW_HatchLoop *v) { + looplist.push_back(v); + } + + virtual void applyExtrusion(){} + +protected: + void parseCode(int code, dxfReader *reader); + virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); + +public: + UTF8STRING name; /*!< hatch pattern name, code 2 */ + int solid; /*!< solid fill flag, code 70, solid=1, pattern=0 */ + int associative; /*!< associativity, code 71, associatve=1, non-assoc.=0 */ + int hstyle; /*!< hatch style, code 75 */ + int hpattern; /*!< hatch pattern type, code 76 */ + int doubleflag; /*!< hatch pattern double flag, code 77, double=1, single=0 */ + int loopsnum; /*!< namber of boundary paths (loops), code 91 */ + double angle; /*!< hatch pattern angle, code 52 */ + double scale; /*!< hatch pattern scale, code 41 */ + int deflines; /*!< number of pattern definition lines, code 78 */ + + std::vector looplist; /*!< polyline list */ + +private: + void clearEntities(){ + pt = line = NULL; + pline = NULL; + arc = NULL; + ellipse = NULL; + spline = NULL; + plvert = NULL; + } + + void addLine() { + clearEntities(); + if (loop) { + pt = line = new DRW_Line; + loop->objlist.push_back(line); + } + } + + void addArc() { + clearEntities(); + if (loop) { + pt = arc = new DRW_Arc; + loop->objlist.push_back(arc); + } + } + + void addEllipse() { + clearEntities(); + if (loop) { + pt = ellipse = new DRW_Ellipse; + loop->objlist.push_back(ellipse); + } + } + + void addSpline() { + clearEntities(); + if (loop) { + pt = NULL; + spline = new DRW_Spline; + loop->objlist.push_back(spline); + } + } + + DRW_HatchLoop *loop; /*!< current loop to add data */ + DRW_Line *line; + DRW_Arc *arc; + DRW_Ellipse *ellipse; + DRW_Spline *spline; + DRW_LWPolyline *pline; + DRW_Point *pt; + DRW_Vertex2D *plvert; + bool ispol; +}; + +//! Class to handle image entity +/*! +* Class to handle image entity +* @author Rallaz +*/ +class DRW_Image : public DRW_Line { + SETENTFRIENDS +public: + DRW_Image() { + eType = DRW::IMAGE; + fade = clip = 0; + brightness = contrast = 50; + } + +protected: + void parseCode(int code, dxfReader *reader); + virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); + +public: + duint32 ref; /*!< Hard reference to imagedef object, code 340 */ + DRW_Coord vVector; /*!< V-vector of single pixel, x coordinate, code 12, 22 & 32 */ +// double vx; /*!< V-vector of single pixel, x coordinate, code 12 */ +// double vy; /*!< V-vector of single pixel, y coordinate, code 22 */ +// double vz; /*!< V-vector of single pixel, z coordinate, code 32 */ + double sizeu; /*!< image size in pixels, U value, code 13 */ + double sizev; /*!< image size in pixels, V value, code 23 */ + double dz; /*!< z coordinate, code 33 */ + int clip; /*!< Clipping state, code 280, 0=off 1=on */ + int brightness; /*!< Brightness value, code 281, (0-100) default 50 */ + int contrast; /*!< Brightness value, code 282, (0-100) default 50 */ + int fade; /*!< Brightness value, code 283, (0-100) default 0 */ + +}; + + +//! Base class for dimension entity +/*! +* Base class for dimension entity +* @author Rallaz +*/ +class DRW_Dimension : public DRW_Entity { + SETENTFRIENDS +public: + DRW_Dimension() { + eType = DRW::DIMENSION; + type = 0; + linesty = 1; + linefactor = extPoint.z = 1.0; + angle = oblique = rot = 0.0; + align = 5; + style = "STANDARD"; + defPoint.z = extPoint.x = extPoint.y = 0; + textPoint.z = rot = 0; + clonePoint.x = clonePoint.y = clonePoint.z = 0; + length = 0.0; + hasActual = false; + actual = 0.0; + } + + DRW_Dimension(const DRW_Dimension& d): DRW_Entity(d) { + eType = DRW::DIMENSION; + type =d.type; + name = d.name; + defPoint = d.defPoint; + textPoint = d.textPoint; + text = d.text; + style = d.style; + align = d.align; + linesty = d.linesty; + linefactor = d.linefactor; + rot = d.rot; + extPoint = d.extPoint; + clonePoint = d.clonePoint; + def1 = d.def1; + def2 = d.def2; + angle = d.angle; + oblique = d.oblique; + arcPoint = d.arcPoint; + circlePoint = d.circlePoint; + length = d.length; + hasActual = d.hasActual; + actual = d.actual; + //RLZ needed a def value for this: hdir = ??? + } + virtual ~DRW_Dimension() {} + + virtual void applyExtrusion(){} + +protected: + void parseCode(int code, dxfReader *reader); + bool parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer *sBuf); + virtual bool parseDwg(DRW::Version version, dwgBuffer* buf, duint32 bs=0){ + DRW_UNUSED(version); DRW_UNUSED(buf); DRW_UNUSED(bs); return true;} + +public: + DRW_Coord getDefPoint() const {return defPoint;} /*!< Definition point, code 10, 20 & 30 */ + void setDefPoint(const DRW_Coord p) {defPoint =p;} + DRW_Coord getTextPoint() const {return textPoint;} /*!< Middle point of text, code 11, 21 & 31 */ + void setTextPoint(const DRW_Coord p) {textPoint =p;} + std::string getStyle() const {return style;} /*!< Dimension style, code 3 */ + void setStyle(const std::string s) {style = s;} + int getAlign() const { return align;} /*!< attachment point, code 71 */ + void setAlign(const int a) { align = a;} + int getTextLineStyle() const { return linesty;} /*!< Dimension text line spacing style, code 72, default 1 */ + void setTextLineStyle(const int l) { linesty = l;} + std::string getText() const {return text;} /*!< Dimension text explicitly entered by the user, code 1 */ + void setText(const std::string t) {text = t;} + double getTextLineFactor() const { return linefactor;} /*!< Dimension text line spacing factor, code 41, default 1? */ + void setTextLineFactor(const double l) { linefactor = l;} + double getDir() const { return rot;} /*!< rotation angle of the dimension text, code 53 (optional) default 0 */ + void setDir(const double d) { rot = d;} + + DRW_Coord getExtrusion(){return extPoint;} /*!< extrusion, code 210, 220 & 230 */ + void setExtrusion(const DRW_Coord p) {extPoint =p;} + std::string getName(){return name;} /*!< Name of the block that contains the entities, code 2 */ + void setName(const std::string s) {name = s;} +// int getType(){ return type;} /*!< Dimension type, code 70 */ + bool hasActualMeasurement() const { return hasActual; } + void setActualMeasurement(double value) { hasActual = true; actual = value; } + double getActualMeasurement() const { return actual; } + +protected: + DRW_Coord getPt2() const {return clonePoint;} + void setPt2(const DRW_Coord p) {clonePoint= p;} + DRW_Coord getPt3() const {return def1;} + void setPt3(const DRW_Coord p) {def1= p;} + DRW_Coord getPt4() const {return def2;} + void setPt4(const DRW_Coord p) {def2= p;} + DRW_Coord getPt5() const {return circlePoint;} + void setPt5(const DRW_Coord p) {circlePoint= p;} + DRW_Coord getPt6() const {return arcPoint;} + void setPt6(const DRW_Coord p) {arcPoint= p;} + double getAn50() const {return angle;} /*!< Angle of rotated, horizontal, or vertical dimensions, code 50 */ + void setAn50(const double d) {angle = d;} + double getOb52() const {return oblique;} /*!< oblique angle, code 52 */ + void setOb52(const double d) {oblique = d;} + double getRa40() const {return length;} /*!< Leader length, code 40 */ + void setRa40(const double d) {length = d;} +public: + int type; /*!< Dimension type, code 70 */ +private: + std::string name; /*!< Name of the block that contains the entities, code 2 */ + DRW_Coord defPoint; /*!< definition point, code 10, 20 & 30 (WCS) */ + DRW_Coord textPoint; /*!< Middle point of text, code 11, 21 & 31 (OCS) */ + UTF8STRING text; /*!< Dimension text explicitly entered by the user, code 1 */ + UTF8STRING style; /*!< Dimension style, code 3 */ + int align; /*!< attachment point, code 71 */ + int linesty; /*!< Dimension text line spacing style, code 72, default 1 */ + double linefactor; /*!< Dimension text line spacing factor, code 41, default 1? (value range 0.25 to 4.00*/ + double rot; /*!< rotation angle of the dimension text, code 53 */ + DRW_Coord extPoint; /*!< extrusion normal vector, code 210, 220 & 230 */ + + double hdir; /*!< horizontal direction for the dimension, code 51, default ? */ + DRW_Coord clonePoint; /*!< Insertion point for clones (Baseline & Continue), code 12, 22 & 32 (OCS) */ + DRW_Coord def1; /*!< Definition point 1for linear & angular, code 13, 23 & 33 (WCS) */ + DRW_Coord def2; /*!< Definition point 2, code 14, 24 & 34 (WCS) */ + double angle; /*!< Angle of rotated, horizontal, or vertical dimensions, code 50 */ + double oblique; /*!< oblique angle, code 52 */ + + DRW_Coord circlePoint; /*!< Definition point for diameter, radius & angular dims code 15, 25 & 35 (WCS) */ + DRW_Coord arcPoint; /*!< Point defining dimension arc, x coordinate, code 16, 26 & 36 (OCS) */ + double length; /*!< Leader length, code 40 */ + bool hasActual; /*!< Actual measurement has been read, code 42 */ + double actual; /*!< Actual measurement (optional; read-only value), code 42 */ + +protected: + dwgHandle dimStyleH; + dwgHandle blockH; +}; + + +//! Class to handle aligned dimension entity +/*! +* Class to handle aligned dimension entity +* @author Rallaz +*/ +class DRW_DimAligned : public DRW_Dimension { + SETENTFRIENDS +public: + DRW_DimAligned(){ + eType = DRW::DIMALIGNED; + type = 1; + } + DRW_DimAligned(const DRW_Dimension& d): DRW_Dimension(d) { + eType = DRW::DIMALIGNED; + } + + DRW_Coord getClonepoint() const {return getPt2();} /*!< Insertion for clones (Baseline & Continue), 12, 22 & 32 */ + void setClonePoint(DRW_Coord c){setPt2(c);} + + DRW_Coord getDimPoint() const {return getDefPoint();} /*!< dim line location point, code 10, 20 & 30 */ + void setDimPoint(const DRW_Coord p){setDefPoint(p);} + DRW_Coord getDef1Point() const {return getPt3();} /*!< Definition point 1, code 13, 23 & 33 */ + void setDef1Point(const DRW_Coord p) {setPt3(p);} + DRW_Coord getDef2Point() const {return getPt4();} /*!< Definition point 2, code 14, 24 & 34 */ + void setDef2Point(const DRW_Coord p) {setPt4(p);} + +protected: + virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); +}; + +//! Class to handle linear or rotated dimension entity +/*! +* Class to handle linear or rotated dimension entity +* @author Rallaz +*/ +class DRW_DimLinear : public DRW_DimAligned { +public: + DRW_DimLinear() { + eType = DRW::DIMLINEAR; + type = 0; + } + DRW_DimLinear(const DRW_Dimension& d): DRW_DimAligned(d) { + eType = DRW::DIMLINEAR; + } + + double getAngle() const {return getAn50();} /*!< Angle of rotated, horizontal, or vertical dimensions, code 50 */ + void setAngle(const double d) {setAn50(d);} + double getOblique() const {return getOb52();} /*!< oblique angle, code 52 */ + void setOblique(const double d) {setOb52(d);} +}; + +//! Class to handle radial dimension entity +/*! +* Class to handle aligned, linear or rotated dimension entity +* @author Rallaz +*/ +class DRW_DimRadial : public DRW_Dimension { + SETENTFRIENDS +public: + DRW_DimRadial() { + eType = DRW::DIMRADIAL; + type = 4; + } + DRW_DimRadial(const DRW_Dimension& d): DRW_Dimension(d) { + eType = DRW::DIMRADIAL; + } + + DRW_Coord getCenterPoint() const {return getDefPoint();} /*!< center point, code 10, 20 & 30 */ + void setCenterPoint(const DRW_Coord p){setDefPoint(p);} + DRW_Coord getDiameterPoint() const {return getPt5();} /*!< Definition point for radius, code 15, 25 & 35 */ + void setDiameterPoint(const DRW_Coord p){setPt5(p);} + double getLeaderLength() const {return getRa40();} /*!< Leader length, code 40 */ + void setLeaderLength(const double d) {setRa40(d);} + +protected: + virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); +}; + +//! Class to handle radial dimension entity +/*! +* Class to handle aligned, linear or rotated dimension entity +* @author Rallaz +*/ +class DRW_DimDiametric : public DRW_Dimension { + SETENTFRIENDS +public: + DRW_DimDiametric() { + eType = DRW::DIMDIAMETRIC; + type = 3; + } + DRW_DimDiametric(const DRW_Dimension& d): DRW_Dimension(d) { + eType = DRW::DIMDIAMETRIC; + } + + DRW_Coord getDiameter1Point() const {return getPt5();} /*!< First definition point for diameter, code 15, 25 & 35 */ + void setDiameter1Point(const DRW_Coord p){setPt5(p);} + DRW_Coord getDiameter2Point() const {return getDefPoint();} /*!< Oposite point for diameter, code 10, 20 & 30 */ + void setDiameter2Point(const DRW_Coord p){setDefPoint(p);} + double getLeaderLength() const {return getRa40();} /*!< Leader length, code 40 */ + void setLeaderLength(const double d) {setRa40(d);} + +protected: + virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); +}; + +//! Class to handle angular dimension entity +/*! +* Class to handle angular dimension entity +* @author Rallaz +*/ +class DRW_DimAngular : public DRW_Dimension { + SETENTFRIENDS +public: + DRW_DimAngular() { + eType = DRW::DIMANGULAR; + type = 2; + } + DRW_DimAngular(const DRW_Dimension& d): DRW_Dimension(d) { + eType = DRW::DIMANGULAR; + } + + DRW_Coord getFirstLine1() const {return getPt3();} /*!< Definition point line 1-1, code 13, 23 & 33 */ + void setFirstLine1(const DRW_Coord p) {setPt3(p);} + DRW_Coord getFirstLine2() const {return getPt4();} /*!< Definition point line 1-2, code 14, 24 & 34 */ + void setFirstLine2(const DRW_Coord p) {setPt4(p);} + DRW_Coord getSecondLine1() const {return getPt5();} /*!< Definition point line 2-1, code 15, 25 & 35 */ + void setSecondLine1(const DRW_Coord p) {setPt5(p);} + DRW_Coord getSecondLine2() const {return getDefPoint();} /*!< Definition point line 2-2, code 10, 20 & 30 */ + void setSecondLine2(const DRW_Coord p){setDefPoint(p);} + DRW_Coord getDimPoint() const {return getPt6();} /*!< Dimension definition point, code 16, 26 & 36 */ + void setDimPoint(const DRW_Coord p) {setPt6(p);} + +protected: + virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); +}; + + +//! Class to handle angular 3p dimension entity +/*! +* Class to handle angular 3p dimension entity +* @author Rallaz +*/ +class DRW_DimAngular3p : public DRW_Dimension { + SETENTFRIENDS +public: + DRW_DimAngular3p() { + eType = DRW::DIMANGULAR3P; + type = 5; + } + DRW_DimAngular3p(const DRW_Dimension& d): DRW_Dimension(d) { + eType = DRW::DIMANGULAR3P; + } + + DRW_Coord getFirstLine() const {return getPt3();} /*!< Definition point line 1, code 13, 23 & 33 */ + void setFirstLine(const DRW_Coord p) {setPt3(p);} + DRW_Coord getSecondLine() const {return getPt4();} /*!< Definition point line 2, code 14, 24 & 34 */ + void setSecondLine(const DRW_Coord p) {setPt4(p);} + DRW_Coord getVertexPoint() const {return getPt5();} /*!< Vertex point, code 15, 25 & 35 */ + void SetVertexPoint(const DRW_Coord p) {setPt5(p);} + DRW_Coord getDimPoint() const {return getDefPoint();} /*!< Dimension definition point, code 10, 20 & 30 */ + void setDimPoint(const DRW_Coord p) {setDefPoint(p);} + +protected: + virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); +}; + +//! Class to handle ordinate dimension entity +/*! +* Class to handle ordinate dimension entity +* @author Rallaz +*/ +class DRW_DimOrdinate : public DRW_Dimension { + SETENTFRIENDS +public: + DRW_DimOrdinate() { + eType = DRW::DIMORDINATE; + type = 6; + } + DRW_DimOrdinate(const DRW_Dimension& d): DRW_Dimension(d) { + eType = DRW::DIMORDINATE; + } + + DRW_Coord getOriginPoint() const {return getDefPoint();} /*!< Origin definition point, code 10, 20 & 30 */ + void setOriginPoint(const DRW_Coord p) {setDefPoint(p);} + DRW_Coord getFirstLine() const {return getPt3();} /*!< Feature location point, code 13, 23 & 33 */ + void setFirstLine(const DRW_Coord p) {setPt3(p);} + DRW_Coord getSecondLine() const {return getPt4();} /*!< Leader end point, code 14, 24 & 34 */ + void setSecondLine(const DRW_Coord p) {setPt4(p);} + +protected: + virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); +}; + + +//! Class to handle leader entity +/*! +* Class to handle leader entity +* @author Rallaz +*/ +class DRW_Leader : public DRW_Entity { + SETENTFRIENDS +public: + DRW_Leader() { + eType = DRW::LEADER; + flag = 3; + hookflag = vertnum = leadertype = 0; + extrusionPoint.x = extrusionPoint.y = 0.0; + arrow = 1; + extrusionPoint.z = 1.0; + } + ~DRW_Leader() { + for(DRW_Coord *item : vertexlist) delete item; + } + + virtual void applyExtrusion(){} + +protected: + void parseCode(int code, dxfReader *reader); + virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); + +public: + UTF8STRING style; /*!< Dimension style name, code 3 */ + int arrow; /*!< Arrowhead flag, code 71, 0=Disabled; 1=Enabled */ + int leadertype; /*!< Leader path type, code 72, 0=Straight line segments; 1=Spline */ + int flag; /*!< Leader creation flag, code 73, default 3 */ + int hookline; /*!< Hook line direction flag, code 74, default 1 */ + int hookflag; /*!< Hook line flag, code 75 */ + double textheight; /*!< Text annotation height, code 40 */ + double textwidth; /*!< Text annotation width, code 41 */ + int vertnum; /*!< Number of vertices, code 76 */ + int coloruse; /*!< Color to use if leader's DIMCLRD = BYBLOCK, code 77 */ + duint32 annotHandle; /*!< Hard reference to associated annotation, code 340 */ + DRW_Coord extrusionPoint; /*!< Normal vector, code 210, 220 & 230 */ + DRW_Coord horizdir; /*!< "Horizontal" direction for leader, code 211, 221 & 231 */ + DRW_Coord offsetblock; /*!< Offset of last leader vertex from block, code 212, 222 & 232 */ + DRW_Coord offsettext; /*!< Offset of last leader vertex from annotation, code 213, 223 & 233 */ + + std::vector vertexlist; /*!< vertex points list, code 10, 20 & 30 */ + +private: + DRW_Coord *vertexpoint; /*!< current control point to add data */ + dwgHandle dimStyleH; + dwgHandle AnnotH; +}; + +//! Class to handle viewport entity +/*! +* Class to handle viewport entity +* @author Rallaz +*/ +class DRW_Viewport : public DRW_Point { + SETENTFRIENDS +public: + DRW_Viewport() { + eType = DRW::VIEWPORT; + vpstatus = 0; + pswidth = 205; + psheight = 156; + centerPX = 128.5; + centerPY = 97.5; + } + + virtual void applyExtrusion(){} + +protected: + void parseCode(int code, dxfReader *reader); + virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); + +public: + double pswidth; /*!< Width in paper space units, code 40 */ + double psheight; /*!< Height in paper space units, code 41 */ + int vpstatus; /*!< Viewport status, code 68 */ + int vpID; /*!< Viewport ID, code 69 */ + double centerPX; /*!< view center point X, code 12 */ + double centerPY; /*!< view center point Y, code 22 */ + double snapPX; /*!< Snap base point X, code 13 */ + double snapPY; /*!< Snap base point Y, code 23 */ + double snapSpPX; /*!< Snap spacing X, code 14 */ + double snapSpPY; /*!< Snap spacing Y, code 24 */ + //TODO: complete in dxf + DRW_Coord viewDir; /*!< View direction vector, code 16, 26 & 36 */ + DRW_Coord viewTarget; /*!< View target point, code 17, 27, 37 */ + double viewLength; /*!< Perspective lens length, code 42 */ + double frontClip; /*!< Front clip plane Z value, code 43 */ + double backClip; /*!< Back clip plane Z value, code 44 */ + double viewHeight; /*!< View height in model space units, code 45 */ + double snapAngle; /*!< Snap angle, code 50 */ + double twistAngle; /*!< view twist angle, code 51 */ + +private: + duint32 frozenLyCount; +};//RLZ: missing 15,25, 72, 331, 90, 340, 1, 281, 71, 74, 110, 120, 130, 111, 121,131, 112,122, 132, 345,346, and more... + +//used //DRW_Coord basePoint; /*!< base point, code 10, 20 & 30 */ + +//double thickness; /*!< thickness, code 39 */ +//DRW_Coord extPoint; /*!< Dir extrusion normal vector, code 210, 220 & 230 */ +//enum DRW::ETYPE eType; /*!< enum: entity type, code 0 */ +//duint32 handle; /*!< entity identifier, code 5 */ +//std::list > appData; /*!< list of application data, code 102 */ +//duint32 parentHandle; /*!< Soft-pointer ID/handle to owner BLOCK_RECORD object, code 330 */ +//DRW::Space space; /*!< space indicator, code 67*/ +//UTF8STRING layer; /*!< layer name, code 8 */ +//UTF8STRING lineType; /*!< line type, code 6 */ +//duint32 material; /*!< hard pointer id to material object, code 347 */ +//int color; /*!< entity color, code 62 */ +//enum DRW_LW_Conv::lineWidth lWeight; /*!< entity lineweight, code 370 */ +//double ltypeScale; /*!< linetype scale, code 48 */ +//bool visible; /*!< entity visibility, code 60 */ +//int numProxyGraph; /*!< Number of bytes in proxy graphics, code 92 */ +//std::string proxyGraphics; /*!< proxy graphics bytes, code 310 */ +//int color24; /*!< 24-bit color, code 420 */ +//std::string colorName; /*!< color name, code 430 */ +//int transparency; /*!< transparency, code 440 */ +//int plotStyle; /*!< hard pointer id to plot style object, code 390 */ +//DRW::ShadowMode shadow; /*!< shadow mode, code 284 */ +//bool haveExtrusion; /*!< set to true if the entity have extrusion*/ + +#endif + +// EOF diff --git a/src/libs/vdxf/libdxfrw/drw_header.cpp b/src/libs/vdxf/libdxfrw/drw_header.cpp new file mode 100644 index 000000000..60be5ccb3 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/drw_header.cpp @@ -0,0 +1,2480 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#include "drw_header.h" +#include "intern/dxfreader.h" +#include "intern/dxfwriter.h" +#include "intern/drw_dbg.h" +#include "intern/dwgbuffer.h" + +DRW_Header::DRW_Header() { + linetypeCtrl = layerCtrl = styleCtrl = dimstyleCtrl = appidCtrl = 0; + blockCtrl = viewCtrl = ucsCtrl = vportCtrl = vpEntHeaderCtrl = 0; + version = DRW::AC1021; +} + +void DRW_Header::addComment(std::string c){ + if (!comments.empty()) + comments += '\n'; + comments += c; +} + +void DRW_Header::parseCode(int code, dxfReader *reader){ + switch (code) { + case 9: + curr = new DRW_Variant(); + name = reader->getString(); + if (version < DRW::AC1015 && name == "$DIMUNIT") + name="$DIMLUNIT"; + vars[name]=curr; + break; + case 1: + curr->addString(reader->getUtf8String()); + if (name =="$ACADVER") { + reader->setVersion(curr->content.s, true); + version = reader->getVersion(); + } + curr->code = code; + break; + case 2: + curr->addString(reader->getUtf8String()); + curr->code = code; + break; + case 3: + curr->addString(reader->getUtf8String()); + if (name =="$DWGCODEPAGE") { + reader->setCodePage(curr->content.s); + curr->addString(reader->getCodePage()); + } + curr->code = code; + break; + case 6: + curr->addString(reader->getUtf8String()); + curr->code = code; + break; + case 7: + curr->addString(reader->getUtf8String()); + curr->code = code; + break; + case 8: + curr->addString(reader->getUtf8String()); + curr->code = code; + break; + case 10: + curr->addCoord(); + curr->setCoordX(reader->getDouble()); + curr->code = code; + break; + case 20: + curr->setCoordY(reader->getDouble()); + break; + case 30: + curr->setCoordZ(reader->getDouble()); + curr->code = code; + break; + case 40: + curr->addDouble(reader->getDouble()); + curr->code = code; + break; + case 50: + curr->addDouble(reader->getDouble()); + curr->code = code; + break; + case 62: + curr->addInt(reader->getInt32()); + curr->code = code; + break; + case 70: + curr->addInt(reader->getInt32()); + curr->code = code; + break; + case 280: + curr->addInt(reader->getInt32()); + curr->code = code; + break; + case 290: + curr->addInt(reader->getInt32()); + curr->code = code; + break; + case 370: + curr->addInt(reader->getInt32()); + curr->code = code; + break; + case 380: + curr->addInt(reader->getInt32()); + curr->code = code; + break; + case 390: + curr->addString(reader->getUtf8String()); + curr->code = code; + break; + default: + break; + } +} + +void DRW_Header::write(dxfWriter *writer, DRW::Version ver){ +/*RLZ: TODO complete all vars to AC1024*/ + double varDouble; + int varInt; + std::string varStr; + DRW_Coord varCoord; + writer->writeString(2, "HEADER"); + writer->writeString(9, "$ACADVER"); + switch (ver) { + case DRW::AC1006: //unsupported version acad 10 + case DRW::AC1009: //acad 11 & 12 + varStr = "AC1009"; + break; + case DRW::AC1012: //unsupported version acad 13 + case DRW::AC1014: //acad 14 + varStr = "AC1014"; + break; + case DRW::AC1015: //acad 2000 + varStr = "AC1015"; + break; + case DRW::AC1018: //acad 2004 + varStr = "AC1018"; + break; +/* case DRW::AC1021: //acad 2007 + varStr = "AC1021"; + break;*/ + case DRW::AC1024: //acad 2010 + varStr = "AC1024"; + break; + case DRW::AC1027: //acad 2013 + varStr = "AC1027"; + break; + default: //acad 2007 default version + varStr = "AC1021"; + break; + } + writer->writeString(1, varStr); + writer->setVersion(&varStr, true); + + getStr("$ACADVER", &varStr); + getStr("$ACADMAINTVER", &varStr); + + if (!getStr("$DWGCODEPAGE", &varStr)) { + varStr = "ANSI_1252"; + } + writer->writeString(9, "$DWGCODEPAGE"); + writer->setCodePage(&varStr); + writer->writeString(3, writer->getCodePage() ); + writer->writeString(9, "$INSBASE"); + if (getCoord("$INSBASE", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + } + writer->writeString(9, "$EXTMIN"); + if (getCoord("$EXTMIN", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 1.0000000000000000E+020); + writer->writeDouble(20, 1.0000000000000000E+020); + writer->writeDouble(30, 1.0000000000000000E+020); + } + writer->writeString(9, "$EXTMAX"); + if (getCoord("$EXTMAX", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, -1.0000000000000000E+020); + writer->writeDouble(20, -1.0000000000000000E+020); + writer->writeDouble(30, -1.0000000000000000E+020); + } + writer->writeString(9, "$LIMMIN"); + if (getCoord("$LIMMIN", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + } + writer->writeString(9, "$LIMMAX"); + if (getCoord("$LIMMAX", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + } else { + writer->writeDouble(10, 420.0); + writer->writeDouble(20, 297.0); + } + writer->writeString(9, "$ORTHOMODE"); + if (getInt("$ORTHOMODE", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$REGENMODE"); + if (getInt("$REGENMODE", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 1); + writer->writeString(9, "$FILLMODE"); + if (getInt("$FILLMODE", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 1); + writer->writeString(9, "$QTEXTMODE"); + if (getInt("$QTEXTMODE", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$MIRRTEXT"); + if (getInt("$MIRRTEXT", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + if (ver == DRW::AC1009){ + writer->writeString(9, "$DRAGMODE"); + if (getInt("$DRAGMODE", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 2); + } + writer->writeString(9, "$LTSCALE"); + if (getDouble("$LTSCALE", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 1.0); + if (ver == DRW::AC1009){ + writer->writeString(9, "$OSMODE"); + if (getInt("$OSMODE", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + } + writer->writeString(9, "$ATTMODE"); + if (getInt("$ATTMODE", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$TEXTSIZE"); + if (getDouble("$TEXTSIZE", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 2.5); + writer->writeString(9, "$TRACEWID"); + if (getDouble("$TRACEWID", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 15.68); + writer->writeString(9, "$TEXTSTYLE"); + if (getStr("$TEXTSTYLE", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(7, varStr); + else + writer->writeUtf8String(7, varStr); + else + writer->writeString(7, "STANDARD"); + writer->writeString(9, "$CLAYER"); + if (getStr("$CLAYER", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(8, varStr); + else + writer->writeUtf8String(8, varStr); + else + writer->writeString(8, "0"); + writer->writeString(9, "$CELTYPE"); + if (getStr("$CELTYPE", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(6, varStr); + else + writer->writeUtf8String(6, varStr); + else + writer->writeString(6, "BYLAYER"); + writer->writeString(9, "$CECOLOR"); + if (getInt("$CECOLOR", &varInt)) + writer->writeInt16(62, varInt); + else + writer->writeInt16(62, 256); + if (ver > DRW::AC1009){ + writer->writeString(9, "$CELTSCALE"); + if (getDouble("$CELTSCALE", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 1.0); + writer->writeString(9, "$DISPSILH"); + if (getInt("$DISPSILH", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + } + + writer->writeString(9, "$DIMSCALE"); + if (getDouble("$DIMSCALE", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 1.0); + writer->writeString(9, "$DIMASZ"); + if (getDouble("$DIMASZ", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 2.5); + writer->writeString(9, "$DIMEXO"); + if (getDouble("$DIMEXO", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.625); + writer->writeString(9, "$DIMDLI"); + if (getDouble("$DIMDLI", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 3.75); + writer->writeString(9, "$DIMRND"); + if (getDouble("$DIMRND", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$DIMDLE"); + if (getDouble("$DIMDLE", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$DIMEXE"); + if (getDouble("$DIMEXE", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 1.25); + writer->writeString(9, "$DIMTP"); + if (getDouble("$DIMTP", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$DIMTM"); + if (getDouble("$DIMTM", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$DIMTXT"); + if (getDouble("$DIMTXT", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 2.5); + writer->writeString(9, "$DIMCEN"); + if (getDouble("$DIMCEN", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 2.5); + writer->writeString(9, "$DIMTSZ"); + if (getDouble("$DIMTSZ", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$DIMTOL"); + if (getInt("$DIMTOL", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMLIM"); + if (getInt("$DIMLIM", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMTIH"); + if (getInt("$DIMTIH", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMTOH"); + if (getInt("$DIMTOH", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMSE1"); + if (getInt("$DIMSE1", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMSE2"); + if (getInt("$DIMSE2", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMTAD"); + if (getInt("$DIMTAD", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 1); + writer->writeString(9, "$DIMZIN"); + if (getInt("$DIMZIN", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 8); + writer->writeString(9, "$DIMBLK"); + if (getStr("$DIMBLK", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(1, varStr); + else + writer->writeUtf8String(1, varStr); + else + writer->writeString(1, ""); + writer->writeString(9, "$DIMASO"); + if (getInt("$DIMASO", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 1); + writer->writeString(9, "$DIMSHO"); + if (getInt("$DIMSHO", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 1); + writer->writeString(9, "$DIMPOST"); + if (getStr("$DIMPOST", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(1, varStr); + else + writer->writeUtf8String(1, varStr); + else + writer->writeString(1, ""); + writer->writeString(9, "$DIMAPOST"); + if (getStr("$DIMAPOST", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(1, varStr); + else + writer->writeUtf8String(1, varStr); + else + writer->writeString(1, ""); + writer->writeString(9, "$DIMALT"); + if (getInt("$DIMALT", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMALTD"); + if (getInt("$DIMALTD", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 3); + writer->writeString(9, "$DIMALTF"); + if (getDouble("$DIMALTF", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.03937); + writer->writeString(9, "$DIMLFAC"); + if (getDouble("$DIMLFAC", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 1.0); + writer->writeString(9, "$DIMTOFL"); + if (getInt("$DIMTOFL", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 1); + writer->writeString(9, "$DIMTVP"); + if (getDouble("$DIMTVP", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$DIMTIX"); + if (getInt("$DIMTIX", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMSOXD"); + if (getInt("$DIMSOXD", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMSAH"); + if (getInt("$DIMSAH", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMBLK1"); + if (getStr("$DIMBLK1", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(1, varStr); + else + writer->writeUtf8String(1, varStr); + else + writer->writeString(1, ""); + writer->writeString(9, "$DIMBLK2"); + if (getStr("$DIMBLK2", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(1, varStr); + else + writer->writeUtf8String(1, varStr); + else + writer->writeString(1, ""); + writer->writeString(9, "$DIMSTYLE"); + if (getStr("$DIMSTYLE", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(2, varStr); + else + writer->writeUtf8String(2, varStr); + else + writer->writeString(2, "STANDARD"); + writer->writeString(9, "$DIMCLRD"); + if (getInt("$DIMCLRD", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMCLRE"); + if (getInt("$DIMCLRE", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMCLRT"); + if (getInt("$DIMCLRT", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMTFAC"); + if (getDouble("$DIMTFAC", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 1.0); + writer->writeString(9, "$DIMGAP"); + if (getDouble("$DIMGAP", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.625); + //post r12 dim vars + if (ver > DRW::AC1009) { + writer->writeString(9, "$DIMJUST"); + if (getInt("$DIMJUST", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMSD1"); + if (getInt("$DIMSD1", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMSD2"); + if (getInt("$DIMSD2", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMTOLJ"); + if (getInt("$DIMTOLJ", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMTZIN"); + if (getInt("$DIMTZIN", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 8); + writer->writeString(9, "$DIMALTZ"); + if (getInt("$DIMALTZ", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMALTTZ"); + if (getInt("$DIMALTTZ", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMUPT"); + if (getInt("$DIMUPT", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMDEC"); + if (getInt("$DIMDEC", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 2); + writer->writeString(9, "$DIMTDEC"); + if (getInt("$DIMTDEC", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 2); + writer->writeString(9, "$DIMALTU"); + if (getInt("$DIMALTU", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 2); + writer->writeString(9, "$DIMALTTD"); + if (getInt("$DIMALTTD", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 3); + writer->writeString(9, "$DIMTXSTY"); + if (getStr("$DIMTXSTY", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(7, varStr); + else + writer->writeUtf8String(7, varStr); + else + writer->writeString(7, "STANDARD"); + writer->writeString(9, "$DIMAUNIT"); + if (getInt("$DIMAUNIT", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMADEC"); + if (getInt("$DIMADEC", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMALTRND"); + if (getDouble("$DIMALTRND", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$DIMAZIN"); + if (getInt("$DIMAZIN", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMDSEP"); + if (getInt("$DIMDSEP", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 44); + writer->writeString(9, "$DIMATFIT"); + if (getInt("$DIMATFIT", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 3); + writer->writeString(9, "$DIMFRAC"); + if (getInt("$DIMFRAC", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMLDRBLK"); + if (getStr("$DIMLDRBLK", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(1, varStr); + else + writer->writeUtf8String(1, varStr); + else + writer->writeString(1, "STANDARD"); + //verify if exist "$DIMLUNIT" or obsolete "$DIMUNIT" (pre v2000) + if ( !getInt("$DIMLUNIT", &varInt) ){ + if (!getInt("$DIMUNIT", &varInt)) + varInt = 2; + } + //verify valid values from 1 to 6 + if (varInt<1 || varInt>6) + varInt = 2; + if (ver > DRW::AC1014) { + writer->writeString(9, "$DIMLUNIT"); + writer->writeInt16(70, varInt); + } else { + writer->writeString(9, "$DIMUNIT"); + writer->writeInt16(70, varInt); + } + writer->writeString(9, "$DIMLWD"); + if (getInt("$DIMLWD", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, -2); + writer->writeString(9, "$DIMLWE"); + if (getInt("$DIMLWE", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, -2); + writer->writeString(9, "$DIMTMOVE"); + if (getInt("$DIMTMOVE", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + + if (ver > DRW::AC1018) {// and post v2004 dim vars + writer->writeString(9, "$DIMFXL"); + if (getDouble("$DIMFXL", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 1.0); + writer->writeString(9, "$DIMFXLON"); + if (getInt("$DIMFXLON", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMJOGANG"); + if (getDouble("$DIMJOGANG", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.7854); + writer->writeString(9, "$DIMTFILL"); + if (getInt("$DIMTFILL", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMTFILLCLR"); + if (getInt("$DIMTFILLCLR", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMARCSYM"); + if (getInt("$DIMARCSYM", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$DIMLTYPE"); + if (getStr("$DIMLTYPE", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(6, varStr); + else + writer->writeUtf8String(6, varStr); + else + writer->writeString(6, ""); + writer->writeString(9, "$DIMLTEX1"); + if (getStr("$DIMLTEX1", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(6, varStr); + else + writer->writeUtf8String(6, varStr); + else + writer->writeString(6, ""); + writer->writeString(9, "$DIMLTEX2"); + if (getStr("$DIMLTEX2", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(6, varStr); + else + writer->writeUtf8String(6, varStr); + else + writer->writeString(6, ""); + if (ver > DRW::AC1021) {// and post v2007 dim vars + writer->writeString(9, "$DIMTXTDIRECTION"); + if (getInt("$DIMTXTDIRECTION", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + } + }// end post v2004 dim vars + }//end post r12 dim vars + + writer->writeString(9, "$LUNITS"); + if (getInt("$LUNITS", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 2); + writer->writeString(9, "$LUPREC"); + if (getInt("$LUPREC", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 4); + writer->writeString(9, "$SKETCHINC"); + if (getDouble("$SKETCHINC", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 1.0); + writer->writeString(9, "$FILLETRAD"); + if (getDouble("$FILLETRAD", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$AUNITS"); + if (getInt("$AUNITS", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$AUPREC"); + if (getInt("$AUPREC", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 2); + writer->writeString(9, "$MENU"); + if (getStr("$MENU", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(1, varStr); + else + writer->writeUtf8String(1, varStr); + else + writer->writeString(1, "."); + writer->writeString(9, "$ELEVATION"); + if (getDouble("$ELEVATION", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$PELEVATION"); + if (getDouble("$PELEVATION", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$THICKNESS"); + if (getDouble("$THICKNESS", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$LIMCHECK"); + if (getInt("$LIMCHECK", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + if (ver < DRW::AC1015) { + writer->writeString(9, "$BLIPMODE"); + if (getInt("$BLIPMODE", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + } + writer->writeString(9, "$CHAMFERA"); + if (getDouble("$CHAMFERA", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$CHAMFERB"); + if (getDouble("$CHAMFERB", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + if (ver > DRW::AC1009) { + writer->writeString(9, "$CHAMFERC"); + if (getDouble("$CHAMFERC", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$CHAMFERD"); + if (getDouble("$CHAMFERD", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + } + writer->writeString(9, "$SKPOLY"); + if (getInt("$SKPOLY", &varInt)) { + writer->writeInt16(70, varInt); + } else + writer->writeInt16(70, 0); + //rlz: todo, times + writer->writeString(9, "$USRTIMER"); + if (getInt("$USRTIMER", &varInt)) { + writer->writeInt16(70, varInt); + } else + writer->writeInt16(70, 1); + writer->writeString(9, "$ANGBASE"); + if (getDouble("$ANGBASE", &varDouble)) + writer->writeDouble(50, varDouble); + else + writer->writeDouble(50, 0.0); + writer->writeString(9, "$ANGDIR"); + if (getInt("$ANGDIR", &varInt)) { + writer->writeInt16(70, varInt); + } else + writer->writeInt16(70, 0); + writer->writeString(9, "$PDMODE"); + if (getInt("$PDMODE", &varInt)) { + writer->writeInt16(70, varInt); + } else + writer->writeInt16(70, 34); + writer->writeString(9, "$PDSIZE"); + if (getDouble("$PDSIZE", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$PLINEWID"); + if (getDouble("$PLINEWID", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + if (ver < DRW::AC1012) { + writer->writeString(9, "$COORDS"); + if (getInt("$COORDS", &varInt)) { + writer->writeInt16(70, varInt); + } else + writer->writeInt16(70, 2); + } + writer->writeString(9, "$SPLFRAME"); + if (getInt("$SPLFRAME", &varInt)) { + writer->writeInt16(70, varInt); + } else + writer->writeInt16(70, 0); + writer->writeString(9, "$SPLINETYPE"); + if (getInt("$SPLINETYPE", &varInt)) { + writer->writeInt16(70, varInt); + } else + writer->writeInt16(70, 2); + writer->writeString(9, "$SPLINESEGS"); + if (getInt("$SPLINESEGS", &varInt)) { + writer->writeInt16(70, varInt); + } else + writer->writeInt16(70, 8); + if (ver < DRW::AC1012) { + writer->writeString(9, "$ATTDIA"); + if (getInt("$ATTDIA", &varInt)) { + writer->writeInt16(70, varInt); + } else + writer->writeInt16(70, 1); + writer->writeString(9, "$ATTREQ"); + if (getInt("$ATTREQ", &varInt)) { + writer->writeInt16(70, varInt); + } else + writer->writeInt16(70, 1); + writer->writeString(9, "$HANDLING"); + if (getInt("$HANDLING", &varInt)) { + writer->writeInt16(70, varInt); + } else + writer->writeInt16(70, 1); + } + writer->writeString(9, "$HANDSEED"); + //RLZ dxfHex(5, 0xFFFF); + writer->writeString(5, "20000"); + writer->writeString(9, "$SURFTAB1"); + if (getInt("$SURFTAB1", &varInt)) { + writer->writeInt16(70, varInt); + } else + writer->writeInt16(70, 6); + writer->writeString(9, "$SURFTAB2"); + if (getInt("$SURFTAB2", &varInt)) { + writer->writeInt16(70, varInt); + } else + writer->writeInt16(70, 6); + writer->writeString(9, "$SURFTYPE"); + if (getInt("$SURFTYPE", &varInt)) { + writer->writeInt16(70, varInt); + } else + writer->writeInt16(70, 6); + writer->writeString(9, "$SURFU"); + if (getInt("$SURFU", &varInt)) { + writer->writeInt16(70, varInt); + } else + writer->writeInt16(70, 6); + writer->writeString(9, "$SURFV"); + if (getInt("$SURFV", &varInt)) { + writer->writeInt16(70, varInt); + } else + writer->writeInt16(70, 6); + if (getStr("$TDCREATE", &varStr)) { + writer->writeString(9, "$TDCREATE"); + writer->writeString(40, varStr); + } + if (ver > DRW::AC1009) { + writer->writeString(9, "$UCSBASE"); + if (getStr("$UCSBASE", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(2, varStr); + else + writer->writeUtf8String(2, varStr); + else + writer->writeString(2, ""); +} + writer->writeString(9, "$UCSNAME"); + if (getStr("$UCSNAME", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(2, varStr); + else + writer->writeUtf8String(2, varStr); + else + writer->writeString(2, ""); + writer->writeString(9, "$UCSORG"); + if (getCoord("$UCSORG", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + } + writer->writeString(9, "$UCSXDIR"); + if (getCoord("$UCSXDIR", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 1.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + } + writer->writeString(9, "$UCSYDIR"); + if (getCoord("$UCSYDIR", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 1.0); + writer->writeDouble(30, 0.0); + } + if (ver > DRW::AC1009) { //begin post r12 UCS vars + writer->writeString(9, "$UCSORTHOREF"); + if (getStr("$UCSORTHOREF", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(2, varStr); + else + writer->writeUtf8String(2, varStr); + else + writer->writeString(2, ""); + writer->writeString(9, "$UCSORTHOVIEW"); + if (getInt("$UCSORTHOVIEW", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$UCSORGTOP"); + if (getCoord("$UCSORGTOP", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + } + writer->writeString(9, "$UCSORGBOTTOM"); + if (getCoord("$UCSORGBOTTOM", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + } + writer->writeString(9, "$UCSORGLEFT"); + if (getCoord("$UCSORGLEFT", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + } + writer->writeString(9, "$UCSORGRIGHT"); + if (getCoord("$UCSORGRIGHT", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + } + writer->writeString(9, "$UCSORGFRONT"); + if (getCoord("$UCSORGFRONT", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + } + writer->writeString(9, "$UCSORGBACK"); + if (getCoord("$UCSORGBACK", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + } + writer->writeString(9, "$PUCSBASE"); + if (getStr("$PUCSBASE", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(2, varStr); + else + writer->writeUtf8String(2, varStr); + else + writer->writeString(2, ""); + } //end post r12 UCS vars + writer->writeString(9, "$PUCSNAME"); + if (getStr("$PUCSNAME", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(2, varStr); + else + writer->writeUtf8String(2, varStr); + else + writer->writeString(2, ""); + writer->writeString(9, "$PUCSORG"); + if (getCoord("$PUCSORG", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + } + writer->writeString(9, "$PUCSXDIR"); + if (getCoord("$PUCSXDIR", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 1.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + } + writer->writeString(9, "$PUCSYDIR"); + if (getCoord("$PUCSYDIR", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 1.0); + writer->writeDouble(30, 0.0); + } + if (ver > DRW::AC1009) { //begin post r12 PUCS vars + writer->writeString(9, "$PUCSORTHOREF"); + if (getStr("$PUCSORTHOREF", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(2, varStr); + else + writer->writeUtf8String(2, varStr); + else + writer->writeString(2, ""); + writer->writeString(9, "$PUCSORTHOVIEW"); + if (getInt("$PUCSORTHOVIEW", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$PUCSORGTOP"); + if (getCoord("$PUCSORGTOP", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + } + writer->writeString(9, "$PUCSORGBOTTOM"); + if (getCoord("$PUCSORGBOTTOM", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + } + writer->writeString(9, "$PUCSORGLEFT"); + if (getCoord("$PUCSORGLEFT", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + } + writer->writeString(9, "$PUCSORGRIGHT"); + if (getCoord("$PUCSORGRIGHT", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + } + writer->writeString(9, "$PUCSORGFRONT"); + if (getCoord("$PUCSORGFRONT", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + } + writer->writeString(9, "$PUCSORGBACK"); + if (getCoord("$PUCSORGBACK", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + } + } //end post r12 PUCS vars + + writer->writeString(9, "$USERI1"); + if (getInt("$USERI1", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$USERI2"); + if (getInt("$USERI2", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$USERI3"); + if (getInt("$USERI3", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$USERI4"); + if (getInt("$USERI4", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$USERI5"); + if (getInt("$USERI5", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$USERR1"); + if (getDouble("$USERR1", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$USERR2"); + if (getDouble("$USERR2", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$USERR3"); + if (getDouble("$USERR3", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$USERR4"); + if (getDouble("$USERR4", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$USERR5"); + if (getDouble("$USERR5", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$WORLDVIEW"); + if (getInt("$WORLDVIEW", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 1); + writer->writeString(9, "$SHADEDGE"); + if (getInt("$SHADEDGE", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 3); + writer->writeString(9, "$SHADEDIF"); + if (getInt("$SHADEDIF", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 70); + writer->writeString(9, "$TILEMODE"); + if (getInt("$TILEMODE", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 1); + writer->writeString(9, "$MAXACTVP"); + if (getInt("$MAXACTVP", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 64); + if (ver > DRW::AC1009) { //begin post r12 PUCS vars + writer->writeString(9, "$PINSBASE"); + if (getCoord("$PINSBASE", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + } + } + writer->writeString(9, "$PLIMCHECK"); + if (getInt("$PLIMCHECK", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$PEXTMIN"); + if (getCoord("$PEXTMIN", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + } + writer->writeString(9, "$PEXTMAX"); + if (getCoord("$PEXTMAX", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + writer->writeDouble(30, varCoord.z); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + } + +/* RLZ: moved to active VPORT, but can write in header if present*/ + if (getInt("$GRIDMODE", &varInt)) { + writer->writeString(9, "$GRIDMODE"); + writer->writeInt16(70, varInt); + } + if (getInt("$SNAPSTYLE", &varInt)) { + writer->writeString(9, "$SNAPSTYLE"); + writer->writeInt16(70, varInt); + } + if (getCoord("$GRIDUNIT", &varCoord)) { + writer->writeString(9, "$GRIDUNIT"); + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + } + if (getCoord("$VIEWCTR", &varCoord)) { + writer->writeString(9, "$VIEWCTR"); + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + } +/* RLZ: moved to active VPORT, but can write in header if present*/ + + writer->writeString(9, "$PLIMMIN"); + if (getCoord("$PLIMMIN", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + } else { + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + } + writer->writeString(9, "$PLIMMAX"); + if (getCoord("$PLIMMAX", &varCoord)) { + writer->writeDouble(10, varCoord.x); + writer->writeDouble(20, varCoord.y); + } else { + writer->writeDouble(10, 297.0); + writer->writeDouble(20, 210.0); + } + writer->writeString(9, "$UNITMODE"); + if (getInt("$UNITMODE", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$VISRETAIN"); + if (getInt("$VISRETAIN", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 1); + writer->writeString(9, "$PLINEGEN"); + if (getInt("$PLINEGEN", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$PSLTSCALE"); + if (getInt("$PSLTSCALE", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 1); + if (ver > DRW::AC1009){//start port r12 vars + writer->writeString(9, "$TREEDEPTH"); + if (getInt("$TREEDEPTH", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 3020); + writer->writeString(9, "$CMLSTYLE"); + if (getStr("$CMLSTYLE", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(2, varStr); + else + writer->writeUtf8String(2, varStr); + else + writer->writeString(2, "Standard"); + writer->writeString(9, "$CMLJUST"); + if (getInt("$CMLJUST", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + writer->writeString(9, "$CMLSCALE"); + if (getDouble("$CMLSCALE", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 20.0); + writer->writeString(9, "$PROXYGRAPHICS"); + if (getInt("$PROXYGRAPHICS", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 1); + writer->writeString(9, "$MEASUREMENT"); + if (getInt("$MEASUREMENT", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 1); + writer->writeString(9, "$CELWEIGHT"); + if (getInt("$CELWEIGHT", &varInt)) + writer->writeInt16(370, varInt); + else + writer->writeInt16(370, -1); + writer->writeString(9, "$ENDCAPS"); + if (getInt("$ENDCAPS", &varInt)) + writer->writeInt16(280, varInt); + else + writer->writeInt16(280, 0); + writer->writeString(9, "$JOINSTYLE"); + if (getInt("$JOINSTYLE", &varInt)) + writer->writeInt16(280, varInt); + else + writer->writeInt16(280, 0); + writer->writeString(9, "$LWDISPLAY"); //RLZ bool flag, verify in bin version + if (getInt("$LWDISPLAY", &varInt)) + writer->writeInt16(290, varInt); + else + writer->writeInt16(290, 0); + if (ver > DRW::AC1014) { + writer->writeString(9, "$INSUNITS"); + if (getInt("$INSUNITS", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 0); + } + writer->writeString(9, "$HYPERLINKBASE"); + if (getStr("$HYPERLINKBASE", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(1, varStr); + else + writer->writeUtf8String(1, varStr); + else + writer->writeString(1, ""); + writer->writeString(9, "$STYLESHEET"); + if (getStr("$STYLESHEET", &varStr)) + if (ver == DRW::AC1009) + writer->writeUtf8Caps(1, varStr); + else + writer->writeUtf8String(1, varStr); + else + writer->writeString(1, ""); + writer->writeString(9, "$XEDIT"); //RLZ bool flag, verify in bin version + if (getInt("$XEDIT", &varInt)) + writer->writeInt16(290, varInt); + else + writer->writeInt16(290, 1); + writer->writeString(9, "$CEPSNTYPE"); + if (getInt("$CEPSNTYPE", &varInt)) + writer->writeInt16(380, varInt); + else + writer->writeInt16(380, 0); + writer->writeString(9, "$PSTYLEMODE"); //RLZ bool flag, verify in bin version + if (getInt("$PSTYLEMODE", &varInt)) + writer->writeInt16(290, varInt); + else + writer->writeInt16(290, 1); +//RLZ: here $FINGERPRINTGUID and $VERSIONGUID, do not add? + writer->writeString(9, "$EXTNAMES"); //RLZ bool flag, verify in bin version + if (getInt("$EXTNAMES", &varInt)) + writer->writeInt16(290, varInt); + else + writer->writeInt16(290, 1); + writer->writeString(9, "$PSVPSCALE"); + if (getDouble("$PSVPSCALE", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$OLESTARTUP"); //RLZ bool flag, verify in bin version + if (getInt("$OLESTARTUP", &varInt)) + writer->writeInt16(290, varInt); + else + writer->writeInt16(290, 0); + } + if (ver > DRW::AC1015) {// and post v2004 vars + writer->writeString(9, "$SORTENTS"); + if (getInt("$SORTENTS", &varInt)) + writer->writeInt16(280, varInt); + else + writer->writeInt16(280, 127); + writer->writeString(9, "$INDEXCTL"); + if (getInt("$INDEXCTL", &varInt)) + writer->writeInt16(280, varInt); + else + writer->writeInt16(280, 0); + writer->writeString(9, "$HIDETEXT"); + if (getInt("$HIDETEXT", &varInt)) + writer->writeInt16(280, varInt); + else + writer->writeInt16(280, 1); + writer->writeString(9, "$XCLIPFRAME"); //RLZ bool flag, verify in bin version + if (ver > DRW::AC1021) { + if (getInt("$XCLIPFRAME", &varInt)) + writer->writeInt16(280, varInt); + else + writer->writeInt16(280, 0); + } else { + if (getInt("$XCLIPFRAME", &varInt)) + writer->writeInt16(290, varInt); + else + writer->writeInt16(290, 0); + } + writer->writeString(9, "$HALOGAP"); + if (getInt("$HALOGAP", &varInt)) + writer->writeInt16(280, varInt); + else + writer->writeInt16(280, 0); + writer->writeString(9, "$OBSCOLOR"); + if (getInt("$OBSCOLOR", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 257); + writer->writeString(9, "$OBSLTYPE"); + if (getInt("$OBSLTYPE", &varInt)) + writer->writeInt16(280, varInt); + else + writer->writeInt16(280, 0); + writer->writeString(9, "$INTERSECTIONDISPLAY"); + if (getInt("$INTERSECTIONDISPLAY", &varInt)) + writer->writeInt16(280, varInt); + else + writer->writeInt16(280, 0); + writer->writeString(9, "$INTERSECTIONCOLOR"); + if (getInt("$INTERSECTIONCOLOR", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 257); + writer->writeString(9, "$DIMASSOC"); + if (getInt("$DIMASSOC", &varInt)) + writer->writeInt16(280, varInt); + else + writer->writeInt16(280, 1); + writer->writeString(9, "$PROJECTNAME"); + if (getStr("$PROJECTNAME", &varStr)) + writer->writeUtf8String(1, varStr); + else + writer->writeString(1, ""); + } + if (ver > DRW::AC1018) {// and post v2007 vars + writer->writeString(9, "$CAMERADISPLAY"); //RLZ bool flag, verify in bin version + if (getInt("$CAMERADISPLAY", &varInt)) + writer->writeInt16(290, varInt); + else + writer->writeInt16(290, 0); + writer->writeString(9, "$LENSLENGTH"); + if (getDouble("$LENSLENGTH", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 50.0); + writer->writeString(9, "$CAMERAHEIGHT"); + if (getDouble("$CAMERAHEIGTH", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$STEPSPERSEC"); + if (getDouble("$STEPSPERSEC", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 2.0); + writer->writeString(9, "$STEPSIZE"); + if (getDouble("$STEPSIZE", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 50.0); + writer->writeString(9, "$3DDWFPREC"); + if (getDouble("$3DDWFPREC", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 2.0); + writer->writeString(9, "$PSOLWIDTH"); + if (getDouble("$PSOLWIDTH", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 5.0); + writer->writeString(9, "$PSOLHEIGHT"); + if (getDouble("$PSOLHEIGHT", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 80.0); + writer->writeString(9, "$LOFTANG1"); + if (getDouble("$LOFTANG1", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, M_PI_2); + writer->writeString(9, "$LOFTANG2"); + if (getDouble("$LOFTANG2", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, M_PI_2); + writer->writeString(9, "$LOFTMAG1"); + if (getDouble("$LOFTMAG1", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$LOFTMAG2"); + if (getDouble("$LOFTMAG2", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$LOFTPARAM"); + if (getInt("$LOFTPARAM", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, 7); + writer->writeString(9, "$LOFTNORMALS"); + if (getInt("$LOFTNORMALS", &varInt)) + writer->writeInt16(280, varInt); + else + writer->writeInt16(280, 1); + writer->writeString(9, "$LATITUDE"); + if (getDouble("$LATITUDE", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 1.0); + writer->writeString(9, "$LONGITUDE"); + if (getDouble("$LONGITUDE", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 1.0); + writer->writeString(9, "$NORTHDIRECTION"); + if (getDouble("$LONGITUDE", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + writer->writeString(9, "$TIMEZONE"); + if (getInt("$TIMEZONE", &varInt)) + writer->writeInt16(70, varInt); + else + writer->writeInt16(70, -8000); + writer->writeString(9, "$LIGHTGLYPHDISPLAY"); + if (getInt("$LIGHTGLYPHDISPLAY", &varInt)) + writer->writeInt16(280, varInt); + else + writer->writeInt16(280, 1); + writer->writeString(9, "$TILEMODELIGHTSYNCH"); + if (getInt("$TILEMODELIGHTSYNCH", &varInt)) + writer->writeInt16(280, varInt); + else + writer->writeInt16(280, 1); + //$CMATERIAL is a handle + writer->writeString(9, "$SOLIDHIST"); + if (getInt("$SOLIDHIST", &varInt)) + writer->writeInt16(280, varInt); + else + writer->writeInt16(280, 1); + writer->writeString(9, "$SHOWHIST"); + if (getInt("$SHOWHIST", &varInt)) + writer->writeInt16(280, varInt); + else + writer->writeInt16(280, 1); + writer->writeString(9, "$DWFFRAME"); + if (getInt("$DWFFRAME", &varInt)) + writer->writeInt16(280, varInt); + else + writer->writeInt16(280, 2); + writer->writeString(9, "$DGNFRAME"); + if (getInt("$DGNFRAME", &varInt)) + writer->writeInt16(280, varInt); + else + writer->writeInt16(280, 0); + writer->writeString(9, "$REALWORLDSCALE"); //RLZ bool flag, verify in bin version + if (getInt("$REALWORLDSCALE", &varInt)) + writer->writeInt16(290, varInt); + else + writer->writeInt16(290, 1); + writer->writeString(9, "$INTERFERECOLOR"); + if (getInt("$INTERFERECOLOR", &varInt)) + writer->writeInt16(62, varInt); + else + writer->writeInt16(62, 1); + //$INTERFEREOBJVS is a handle + //$INTERFEREVPVS is a handle + writer->writeString(9, "$CSHADOW"); + if (getInt("$CSHADOW", &varInt)) + writer->writeInt16(280, varInt); + else + writer->writeInt16(280, 0); + writer->writeString(9, "$SHADOWPLANELOCATION"); + if (getDouble("$SHADOWPLANELOCATION", &varDouble)) + writer->writeDouble(40, varDouble); + else + writer->writeDouble(40, 0.0); + } + +#ifdef DRW_DBG + std::map::const_iterator it; + for ( it=vars.begin() ; it != vars.end(); ++it ){ + DRW_DBG((*it).first); DRW_DBG("\n"); + } +#endif +} + +void DRW_Header::addDouble(std::string key, double value, int code){ + curr = new DRW_Variant(); + curr->addDouble( value ); + curr->code = code; + vars[key] =curr; +} + +void DRW_Header::addInt(std::string key, int value, int code){ + curr = new DRW_Variant(); + curr->addInt( value ); + curr->code = code; + vars[key] =curr; +} + +void DRW_Header::addStr(std::string key, std::string value, int code){ + curr = new DRW_Variant(); + curr->addString( value ); + curr->code = code; + vars[key] =curr; +} + +void DRW_Header::addCoord(std::string key, DRW_Coord value, int code){ + curr = new DRW_Variant(); + curr->addCoord( value ); + curr->code = code; + vars[key] =curr; +} + +bool DRW_Header::getDouble(std::string key, double *varDouble){ + bool result = false; + std::map::iterator it; + it=vars.find( key); + if (it != vars.end()) { + DRW_Variant *var = (*it).second; + if (var->type == DRW_Variant::DOUBLE) { + *varDouble = var->content.d; + result = true; + } + delete var; + vars.erase (it); + } + return result; +} + +bool DRW_Header::getInt(std::string key, int *varInt){ + bool result = false; + std::map::iterator it; + it=vars.find( key); + if (it != vars.end()) { + DRW_Variant *var = (*it).second; + if (var->type == DRW_Variant::INTEGER) { + *varInt = var->content.i; + result = true; + } + delete var; + vars.erase (it); + } + return result; +} + +bool DRW_Header::getStr(std::string key, std::string *varStr){ + bool result = false; + std::map::iterator it; + it=vars.find( key); + if (it != vars.end()) { + DRW_Variant *var = (*it).second; + if (var->type == DRW_Variant::STRING) { + *varStr = *var->content.s; + result = true; + } + delete var; + vars.erase (it); + } + return result; +} + +bool DRW_Header::getCoord(std::string key, DRW_Coord *varCoord){ + bool result = false; + std::map::iterator it; + it=vars.find( key); + if (it != vars.end()) { + DRW_Variant *var = (*it).second; + if (var->type == DRW_Variant::COORD) { + *varCoord = *var->content.v; + result = true; + } + delete var; + vars.erase (it); + } + return result; +} + +bool DRW_Header::parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer *hBbuf, duint8 mv){ + bool result = true; + duint32 size = buf->getRawLong32(); + duint32 bitSize = 0; + duint32 endBitPos = 160; //start bit: 16 sentinel + 4 size + DRW_DBG("\nbyte size of data: "); DRW_DBG(size); + if (version > DRW::AC1021 && mv > 3) { //2010+ + duint32 hSize = buf->getRawLong32(); + endBitPos += 32; //start bit: + 4 hight size + DRW_DBG("\n2010+ & MV> 3, higth 32b: "); DRW_DBG(hSize); + } +//RLZ TODO add $ACADVER var & $DWGCODEPAGE & $MEASUREMENT +//RLZ TODO EN 2000 falta $CELWEIGHT, $ENDCAPS, $EXTNAMES $JOINSTYLE $LWDISPLAY $PSTYLEMODE $TDUCREATE $TDUUPDATE $XEDIT + + //bit size of data needed to locate start of string stream in 2007+ + //and mark the start of handle stream + //header is one object reads data and continue read strings ??? + if (version > DRW::AC1018) {//2007+ + bitSize = buf->getRawLong32(); + DRW_DBG("\nsize in bits: "); DRW_DBG(bitSize); + endBitPos += bitSize; + hBbuf->setPosition(endBitPos >>3); + hBbuf->setBitPos(endBitPos&7); + } + + if (version > DRW::AC1024) {//2013+ + duint64 requiredVersions = buf->getBitLongLong(); + DRW_DBG("\nREQUIREDVERSIONS var: "); DRW_DBG(requiredVersions); + } + DRW_DBG("\nUnknown1: "); DRW_DBG(buf->getBitDouble()); + DRW_DBG("\nUnknown2: "); DRW_DBG(buf->getBitDouble()); + DRW_DBG("\nUnknown3: "); DRW_DBG(buf->getBitDouble()); + DRW_DBG("\nUnknown4: "); DRW_DBG(buf->getBitDouble()); + if (version < DRW::AC1021) {//2007- + DRW_DBG("\nUnknown text1: "); DRW_DBG(buf->getCP8Text()); + DRW_DBG("\nUnknown text2: "); DRW_DBG(buf->getCP8Text()); + DRW_DBG("\nUnknown text3: "); DRW_DBG(buf->getCP8Text()); + DRW_DBG("\nUnknown text4: "); DRW_DBG(buf->getCP8Text()); + } + DRW_DBG("\nUnknown long1 (24L): "); DRW_DBG(buf->getBitLong()); + DRW_DBG("\nUnknown long2 (0L): "); DRW_DBG(buf->getBitLong()); + if (version < DRW::AC1015) {//pre 2000 + DRW_DBG("\nUnknown short (0): "); DRW_DBG(buf->getBitShort()); + } + if (version < DRW::AC1018) {//pre 2004 + dwgHandle hcv = hBbuf->getHandle(); + DRW_DBG("\nhandle of current view: "); DRW_DBGHL(hcv.code, hcv.size, hcv.ref); + } + vars["DIMASO"]=new DRW_Variant(70, buf->getBit()); + vars["DIMSHO"]=new DRW_Variant(70, buf->getBit()); + if (version < DRW::AC1015) {//pre 2000 + vars["DIMSAV"]=new DRW_Variant(70, buf->getBit()); + } + vars["PLINEGEN"]=new DRW_Variant(70, buf->getBit()); + vars["ORTHOMODE"]=new DRW_Variant(70, buf->getBit()); + vars["REGENMODE"]=new DRW_Variant(70, buf->getBit()); + vars["FILLMODE"]=new DRW_Variant(70, buf->getBit()); + vars["QTEXTMODE"]=new DRW_Variant(70, buf->getBit()); + vars["PSLTSCALE"]=new DRW_Variant(70, buf->getBit()); + vars["LIMCHECK"]=new DRW_Variant(70, buf->getBit()); + if (version < DRW::AC1015) {//pre 2000 + vars["BLIPMODE"]=new DRW_Variant(70, buf->getBit()); + } + if (version > DRW::AC1015) {//2004+ + DRW_DBG("\nUndocumented: "); DRW_DBG(buf->getBit()); + } + vars["USRTIMER"]=new DRW_Variant(70, buf->getBit()); + vars["SKPOLY"]=new DRW_Variant(70, buf->getBit()); + vars["ANGDIR"]=new DRW_Variant(70, buf->getBit()); + vars["SPLFRAME"]=new DRW_Variant(70, buf->getBit()); + if (version < DRW::AC1015) {//pre 2000 + vars["ATTREQ"]=new DRW_Variant(70, buf->getBit()); + vars["ATTDIA"]=new DRW_Variant(70, buf->getBit()); + } + vars["MIRRTEXT"]=new DRW_Variant(70, buf->getBit()); + vars["WORLDVIEW"]=new DRW_Variant(70, buf->getBit()); + if (version < DRW::AC1015) {//pre 2000 + vars["WIREFRAME"]=new DRW_Variant(70, buf->getBit()); + } + vars["TILEMODE"]=new DRW_Variant(70, buf->getBit()); + vars["PLIMCHECK"]=new DRW_Variant(70, buf->getBit()); + vars["VISRETAIN"]=new DRW_Variant(70, buf->getBit()); + if (version < DRW::AC1015) {//pre 2000 + vars["DELOBJ"]=new DRW_Variant(70, buf->getBit()); + } + vars["DISPSILH"]=new DRW_Variant(70, buf->getBit()); + vars["PELLIPSE"]=new DRW_Variant(70, buf->getBit()); + vars["PROXIGRAPHICS"]=new DRW_Variant(70, buf->getBitShort());//RLZ short or bit?? + if (version < DRW::AC1015) {//pre 2000 + vars["DRAGMODE"]=new DRW_Variant(70, buf->getBitShort());//RLZ short or bit?? + } + vars["TREEDEPTH"]=new DRW_Variant(70, buf->getBitShort());//RLZ short or bit?? + vars["LUNITS"]=new DRW_Variant(70, buf->getBitShort()); + vars["LUPREC"]=new DRW_Variant(70, buf->getBitShort()); + vars["AUNITS"]=new DRW_Variant(70, buf->getBitShort()); + vars["AUPREC"]=new DRW_Variant(70, buf->getBitShort()); + if (version < DRW::AC1015) {//pre 2000 + vars["OSMODE"]=new DRW_Variant(70, buf->getBitShort()); + } + vars["ATTMODE"]=new DRW_Variant(70, buf->getBitShort()); + if (version < DRW::AC1015) {//pre 2000 + vars["COORDS"]=new DRW_Variant(70, buf->getBitShort()); + } + vars["PDMODE"]=new DRW_Variant(70, buf->getBitShort()); + if (version < DRW::AC1015) {//pre 2000 + vars["PICKSTYLE"]=new DRW_Variant(70, buf->getBitShort()); + } + if (version > DRW::AC1015) {//2004+ + DRW_DBG("\nUnknown long 1: "); DRW_DBG(buf->getBitLong()); + DRW_DBG("\nUnknown long 2: "); DRW_DBG(buf->getBitLong()); + DRW_DBG("\nUnknown long 3: "); DRW_DBG(buf->getBitLong()); + } + vars["USERI1"]=new DRW_Variant(70, buf->getBitShort()); + vars["USERI2"]=new DRW_Variant(70, buf->getBitShort()); + vars["USERI3"]=new DRW_Variant(70, buf->getBitShort()); + vars["USERI4"]=new DRW_Variant(70, buf->getBitShort()); + vars["USERI5"]=new DRW_Variant(70, buf->getBitShort()); + vars["SPLINESEGS"]=new DRW_Variant(70, buf->getBitShort()); + vars["SURFU"]=new DRW_Variant(70, buf->getBitShort()); + vars["SURFV"]=new DRW_Variant(70, buf->getBitShort()); + vars["SURFTYPE"]=new DRW_Variant(70, buf->getBitShort()); + vars["SURFTAB1"]=new DRW_Variant(70, buf->getBitShort()); + vars["SURFTAB2"]=new DRW_Variant(70, buf->getBitShort()); + vars["SPLINETYPE"]=new DRW_Variant(70, buf->getBitShort()); + vars["SHADEDGE"]=new DRW_Variant(70, buf->getBitShort()); + vars["SHADEDIF"]=new DRW_Variant(70, buf->getBitShort()); + vars["UNITMODE"]=new DRW_Variant(70, buf->getBitShort()); + vars["MAXACTVP"]=new DRW_Variant(70, buf->getBitShort()); + vars["ISOLINES"]=new DRW_Variant(70, buf->getBitShort());////////////////// + vars["CMLJUST"]=new DRW_Variant(70, buf->getBitShort()); + vars["TEXTQLTY"]=new DRW_Variant(70, buf->getBitShort());///////////////////// + vars["LTSCALE"]=new DRW_Variant(40, buf->getBitDouble()); + vars["TEXTSIZE"]=new DRW_Variant(40, buf->getBitDouble()); + vars["TRACEWID"]=new DRW_Variant(40, buf->getBitDouble()); + vars["SKETCHINC"]=new DRW_Variant(40, buf->getBitDouble()); + vars["FILLETRAD"]=new DRW_Variant(40, buf->getBitDouble()); + vars["THICKNESS"]=new DRW_Variant(40, buf->getBitDouble()); + vars["ANGBASE"]=new DRW_Variant(50, buf->getBitDouble()); + vars["PDSIZE"]=new DRW_Variant(40, buf->getBitDouble()); + vars["PLINEWID"]=new DRW_Variant(40, buf->getBitDouble()); + vars["USERR1"]=new DRW_Variant(40, buf->getBitDouble()); + vars["USERR2"]=new DRW_Variant(40, buf->getBitDouble()); + vars["USERR3"]=new DRW_Variant(40, buf->getBitDouble()); + vars["USERR4"]=new DRW_Variant(40, buf->getBitDouble()); + vars["USERR5"]=new DRW_Variant(40, buf->getBitDouble()); + vars["CHAMFERA"]=new DRW_Variant(40, buf->getBitDouble()); + vars["CHAMFERB"]=new DRW_Variant(40, buf->getBitDouble()); + vars["CHAMFERC"]=new DRW_Variant(40, buf->getBitDouble()); + vars["CHAMFERD"]=new DRW_Variant(40, buf->getBitDouble()); + vars["FACETRES"]=new DRW_Variant(40, buf->getBitDouble());///////////////////////// + vars["CMLSCALE"]=new DRW_Variant(40, buf->getBitDouble()); + vars["CELTSCALE"]=new DRW_Variant(40, buf->getBitDouble()); + if (version < DRW::AC1021) {//2004- + vars["MENU"]=new DRW_Variant(1, buf->getCP8Text()); + } + ddouble64 msec, day; + day = buf->getBitLong(); + msec = buf->getBitLong(); + while (msec > 0) + msec /=10; + vars["TDCREATE"]=new DRW_Variant(40, day+msec);//RLZ: TODO convert to day.msec +// vars["TDCREATE"]=new DRW_Variant(40, buf->getBitLong());//RLZ: TODO convert to day.msec +// vars["TDCREATE"]=new DRW_Variant(40, buf->getBitLong()); + day = buf->getBitLong(); + msec = buf->getBitLong(); + while (msec > 0) + msec /=10; + vars["TDUPDATE"]=new DRW_Variant(40, day+msec);//RLZ: TODO convert to day.msec +// vars["TDUPDATE"]=new DRW_Variant(40, buf->getBitLong());//RLZ: TODO convert to day.msec +// vars["TDUPDATE"]=new DRW_Variant(40, buf->getBitLong()); + if (version > DRW::AC1015) {//2004+ + DRW_DBG("\nUnknown long 4: "); DRW_DBG(buf->getBitLong()); + DRW_DBG("\nUnknown long 5: "); DRW_DBG(buf->getBitLong()); + DRW_DBG("\nUnknown long 6: "); DRW_DBG(buf->getBitLong()); + } + day = buf->getBitLong(); + msec = buf->getBitLong(); + while (msec > 0) + msec /=10; + vars["TDINDWG"]=new DRW_Variant(40, day+msec);//RLZ: TODO convert to day.msec +// vars["TDINDWG"]=new DRW_Variant(40, buf->getBitLong());//RLZ: TODO convert to day.msec +// vars["TDINDWG"]=new DRW_Variant(40, buf->getBitLong());//RLZ: TODO convert to day.msec + day = buf->getBitLong(); + msec = buf->getBitLong(); + while (msec > 0) + msec /=10; + vars["TDUSRTIMER"]=new DRW_Variant(40, day+msec);//RLZ: TODO convert to day.msec +// vars["TDUSRTIMER"]=new DRW_Variant(40, buf->getBitLong());//RLZ: TODO convert to day.msec +// vars["TDUSRTIMER"]=new DRW_Variant(40, buf->getBitLong());//RLZ: TODO convert to day.msec + vars["CECOLOR"]=new DRW_Variant(62, buf->getCmColor(version));//RLZ: TODO read CMC or EMC color + dwgHandle HANDSEED = buf->getHandle();//allways present in data stream + DRW_DBG("\nHANDSEED: "); DRW_DBGHL(HANDSEED.code, HANDSEED.size, HANDSEED.ref); + dwgHandle CLAYER = hBbuf->getHandle(); + DRW_DBG("\nCLAYER: "); DRW_DBGHL(CLAYER.code, CLAYER.size, CLAYER.ref); + dwgHandle TEXTSTYLE = hBbuf->getHandle(); + DRW_DBG("\nTEXTSTYLE: "); DRW_DBGHL(TEXTSTYLE.code, TEXTSTYLE.size, TEXTSTYLE.ref); + dwgHandle CELTYPE = hBbuf->getHandle(); + DRW_DBG("\nCELTYPE: "); DRW_DBGHL(CELTYPE.code, CELTYPE.size, CELTYPE.ref); + if (version > DRW::AC1018) {//2007+ + dwgHandle CMATERIAL = hBbuf->getHandle(); + DRW_DBG("\nCMATERIAL: "); DRW_DBGHL(CMATERIAL.code, CMATERIAL.size, CMATERIAL.ref); + } + dwgHandle DIMSTYLE = hBbuf->getHandle(); + DRW_DBG("\nDIMSTYLE: "); DRW_DBGHL(DIMSTYLE.code, DIMSTYLE.size, DIMSTYLE.ref); + dwgHandle CMLSTYLE = hBbuf->getHandle(); + DRW_DBG("\nCMLSTYLE: "); DRW_DBGHL(CMLSTYLE.code, CMLSTYLE.size, CMLSTYLE.ref); + if (version > DRW::AC1014) {//2000+ + vars["PSVPSCALE"]=new DRW_Variant(40, buf->getBitDouble()); + } + vars["PINSBASE"]=new DRW_Variant(10, buf->get3BitDouble()); + vars["PEXTMIN"]=new DRW_Variant(10, buf->get3BitDouble()); + vars["PEXTMAX"]=new DRW_Variant(10, buf->get3BitDouble()); + vars["PLIMMIN"]=new DRW_Variant(10, buf->get2RawDouble()); + vars["PLIMMAX"]=new DRW_Variant(10, buf->get2RawDouble()); + vars["PELEVATION"]=new DRW_Variant(40, buf->getBitDouble()); + vars["PUCSORG"]=new DRW_Variant(10, buf->get3BitDouble()); + vars["PUCSXDIR"]=new DRW_Variant(10, buf->get3BitDouble()); + vars["PUCSYDIR"]=new DRW_Variant(10, buf->get3BitDouble()); + dwgHandle PUCSNAME = hBbuf->getHandle(); + DRW_DBG("\nPUCSNAME: "); DRW_DBGHL(PUCSNAME.code, PUCSNAME.size, PUCSNAME.ref); + if (version > DRW::AC1014) {//2000+ + dwgHandle PUCSORTHOREF = hBbuf->getHandle(); + DRW_DBG("\nPUCSORTHOREF: "); DRW_DBGHL(PUCSORTHOREF.code, PUCSORTHOREF.size, PUCSORTHOREF.ref); + vars["PUCSORTHOVIEW"]=new DRW_Variant(70, buf->getBitShort()); + dwgHandle PUCSBASE = hBbuf->getHandle(); + DRW_DBG("\nPUCSBASE: "); DRW_DBGHL(PUCSBASE.code, PUCSBASE.size, PUCSBASE.ref); + vars["PUCSORGTOP"]=new DRW_Variant(10, buf->get3BitDouble()); + vars["PUCSORGBOTTOM"]=new DRW_Variant(10, buf->get3BitDouble()); + vars["PUCSORGLEFT"]=new DRW_Variant(10, buf->get3BitDouble()); + vars["PUCSORGRIGHT"]=new DRW_Variant(10, buf->get3BitDouble()); + vars["PUCSORGFRONT"]=new DRW_Variant(10, buf->get3BitDouble()); + vars["PUCSORGBACK"]=new DRW_Variant(10, buf->get3BitDouble()); + } + vars["INSBASE"]=new DRW_Variant(10, buf->get3BitDouble()); + vars["EXTMIN"]=new DRW_Variant(10, buf->get3BitDouble()); + vars["EXTMAX"]=new DRW_Variant(10, buf->get3BitDouble()); + vars["LIMMIN"]=new DRW_Variant(10, buf->get2RawDouble()); + vars["LIMMAX"]=new DRW_Variant(10, buf->get2RawDouble()); + vars["ELEVATION"]=new DRW_Variant(40, buf->getBitDouble()); + vars["UCSORG"]=new DRW_Variant(10, buf->get3BitDouble()); + vars["UCSXDIR"]=new DRW_Variant(10, buf->get3BitDouble()); + vars["UCSYDIR"]=new DRW_Variant(10, buf->get3BitDouble()); + dwgHandle UCSNAME = hBbuf->getHandle(); + DRW_DBG("\nUCSNAME: "); DRW_DBGHL(UCSNAME.code, UCSNAME.size, UCSNAME.ref); + if (version > DRW::AC1014) {//2000+ + dwgHandle UCSORTHOREF = hBbuf->getHandle(); + DRW_DBG("\nUCSORTHOREF: "); DRW_DBGHL(UCSORTHOREF.code, UCSORTHOREF.size, UCSORTHOREF.ref); + vars["UCSORTHOVIEW"]=new DRW_Variant(70, buf->getBitShort()); + dwgHandle UCSBASE = hBbuf->getHandle(); + DRW_DBG("\nUCSBASE: "); DRW_DBGHL(UCSBASE.code, UCSBASE.size, UCSBASE.ref); + vars["UCSORGTOP"]=new DRW_Variant(10, buf->get3BitDouble()); + vars["UCSORGBOTTOM"]=new DRW_Variant(10, buf->get3BitDouble()); + vars["UCSORGLEFT"]=new DRW_Variant(10, buf->get3BitDouble()); + vars["UCSORGRIGHT"]=new DRW_Variant(10, buf->get3BitDouble()); + vars["UCSORGFRONT"]=new DRW_Variant(10, buf->get3BitDouble()); + vars["UCSORGBACK"]=new DRW_Variant(10, buf->get3BitDouble()); + if (version < DRW::AC1021) {//2004- + vars["DIMPOST"]=new DRW_Variant(1, buf->getCP8Text()); + vars["DIMAPOST"]=new DRW_Variant(1, buf->getCP8Text()); + } + } + if (version < DRW::AC1015) {//r14- + vars["DIMTOL"]=new DRW_Variant(70, buf->getBit()); + vars["DIMLIM"]=new DRW_Variant(70, buf->getBit()); + vars["DIMTIH"]=new DRW_Variant(70, buf->getBit()); + vars["DIMTOH"]=new DRW_Variant(70, buf->getBit()); + vars["DIMSE1"]=new DRW_Variant(70, buf->getBit()); + vars["DIMSE2"]=new DRW_Variant(70, buf->getBit()); + vars["DIMALT"]=new DRW_Variant(70, buf->getBit()); + vars["DIMTOFL"]=new DRW_Variant(70, buf->getBit()); + vars["DIMSAH"]=new DRW_Variant(70, buf->getBit()); + vars["DIMTIX"]=new DRW_Variant(70, buf->getBit()); + vars["DIMSOXD"]=new DRW_Variant(70, buf->getBit()); + vars["DIMALTD"]=new DRW_Variant(70, buf->getRawChar8()); + vars["DIMZIN"]=new DRW_Variant(70, buf->getRawChar8()); + vars["DIMSD1"]=new DRW_Variant(70, buf->getBit()); + vars["DIMSD2"]=new DRW_Variant(70, buf->getBit()); + vars["DIMTOLJ"]=new DRW_Variant(70, buf->getRawChar8()); + vars["DIMJUST"]=new DRW_Variant(70, buf->getRawChar8()); + vars["DIMFIT"]=new DRW_Variant(70, buf->getRawChar8());/////////// + vars["DIMUPT"]=new DRW_Variant(70, buf->getBit()); + vars["DIMTZIN"]=new DRW_Variant(70, buf->getRawChar8()); + vars["DIMALTZ"]=new DRW_Variant(70, buf->getRawChar8()); + vars["DIMALTTZ"]=new DRW_Variant(70, buf->getRawChar8()); + vars["DIMTAD"]=new DRW_Variant(70, buf->getRawChar8()); + vars["DIMUNIT"]=new DRW_Variant(70, buf->getBitShort());/////////// + vars["DIMAUNIT"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMDEC"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMTDEC"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMALTU"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMALTTD"]=new DRW_Variant(70, buf->getBitShort()); + dwgHandle DIMTXSTY = hBbuf->getHandle(); + DRW_DBG("\nDIMTXSTY: "); DRW_DBGHL(DIMTXSTY.code, DIMTXSTY.size, DIMTXSTY.ref); + } + vars["DIMSCALE"]=new DRW_Variant(40, buf->getBitDouble()); + vars["DIMASZ"]=new DRW_Variant(40, buf->getBitDouble()); + vars["DIMEXO"]=new DRW_Variant(40, buf->getBitDouble()); + vars["DIMDLI"]=new DRW_Variant(40, buf->getBitDouble()); + vars["DIMEXE"]=new DRW_Variant(40, buf->getBitDouble()); + vars["DIMRND"]=new DRW_Variant(40, buf->getBitDouble()); + vars["DIMDLE"]=new DRW_Variant(40, buf->getBitDouble()); + vars["DIMTP"]=new DRW_Variant(40, buf->getBitDouble()); + vars["DIMTM"]=new DRW_Variant(40, buf->getBitDouble()); + if (version > DRW::AC1018) {//2007+ + vars["DIMFXL"]=new DRW_Variant(40, buf->getBitDouble());////////////////// + vars["DIMJOGANG"]=new DRW_Variant(40, buf->getBitDouble());/////////////// + vars["DIMTFILL"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMTFILLCLR"]=new DRW_Variant(62, buf->getCmColor(version)); + } + if (version > DRW::AC1014) {//2000+ + vars["DIMTOL"]=new DRW_Variant(70, buf->getBit()); + vars["DIMLIM"]=new DRW_Variant(70, buf->getBit()); + vars["DIMTIH"]=new DRW_Variant(70, buf->getBit()); + vars["DIMTOH"]=new DRW_Variant(70, buf->getBit()); + vars["DIMSE1"]=new DRW_Variant(70, buf->getBit()); + vars["DIMSE2"]=new DRW_Variant(70, buf->getBit()); + vars["DIMTAD"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMZIN"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMAZIN"]=new DRW_Variant(70, buf->getBitShort()); + } + if (version > DRW::AC1018) {//2007+ + vars["DIMARCSYM"]=new DRW_Variant(70, buf->getBitShort()); + } + vars["DIMTXT"]=new DRW_Variant(40, buf->getBitDouble()); + vars["DIMCEN"]=new DRW_Variant(40, buf->getBitDouble()); + vars["DIMTSZ"]=new DRW_Variant(40, buf->getBitDouble()); + vars["DIMALTF"]=new DRW_Variant(40, buf->getBitDouble()); + vars["DIMLFAC"]=new DRW_Variant(40, buf->getBitDouble()); + vars["DIMTVP"]=new DRW_Variant(40, buf->getBitDouble()); + vars["DIMTFAC"]=new DRW_Variant(40, buf->getBitDouble()); + vars["DIMGAP"]=new DRW_Variant(40, buf->getBitDouble()); + if (version < DRW::AC1015) {//r14- + vars["DIMPOST"]=new DRW_Variant(1, buf->getCP8Text()); + vars["DIMAPOST"]=new DRW_Variant(1, buf->getCP8Text()); + vars["DIMBLK"]=new DRW_Variant(1, buf->getCP8Text()); + vars["DIMBLK1"]=new DRW_Variant(1, buf->getCP8Text()); + vars["DIMBLK2"]=new DRW_Variant(1, buf->getCP8Text()); + } + if (version > DRW::AC1014) {//2000+ + vars["DIMALTRND"]=new DRW_Variant(40, buf->getBitDouble()); + vars["DIMALT"]=new DRW_Variant(70, buf->getBit()); + vars["DIMALTD"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMTOFL"]=new DRW_Variant(70, buf->getBit()); + vars["DIMSAH"]=new DRW_Variant(70, buf->getBit()); + vars["DIMTIX"]=new DRW_Variant(70, buf->getBit()); + vars["DIMSOXD"]=new DRW_Variant(70, buf->getBit()); + } + vars["DIMCLRD"]=new DRW_Variant(70, buf->getCmColor(version));//RLZ: TODO read CMC or EMC color + vars["DIMCLRE"]=new DRW_Variant(70, buf->getCmColor(version));//RLZ: TODO read CMC or EMC color + vars["DIMCLRT"]=new DRW_Variant(70, buf->getCmColor(version));//RLZ: TODO read CMC or EMC color + if (version > DRW::AC1014) {//2000+ + vars["DIAMDEC"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMDEC"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMTDEC"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMALTU"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMALTTD"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMAUNIT"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMFAC"]=new DRW_Variant(70, buf->getBitShort());///////////////// DIMFAC O DIMFRAC + vars["DIMLUNIT"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMDSEP"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMTMOVE"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMJUST"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMSD1"]=new DRW_Variant(70, buf->getBit()); + vars["DIMSD2"]=new DRW_Variant(70, buf->getBit()); + vars["DIMTOLJ"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMTZIN"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMALTZ"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMALTTZ"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMUPT"]=new DRW_Variant(70, buf->getBit()); + vars["DIMATFIT"]=new DRW_Variant(70, buf->getBitShort()); + } + if (version > DRW::AC1018) {//2007+ + vars["DIMFXLON"]=new DRW_Variant(70, buf->getBit());//////////////// + } + if (version > DRW::AC1021) {//2010+ + vars["DIMTXTDIRECTION"]=new DRW_Variant(70, buf->getBit());//////////////// + vars["DIMALTMZF"]=new DRW_Variant(40, buf->getBitDouble());//////////////// + vars["DIMMZF"]=new DRW_Variant(40, buf->getBitDouble());//////////////// + } + if (version > DRW::AC1014) {//2000+ + dwgHandle DIMTXSTY = hBbuf->getHandle(); + DRW_DBG("\nDIMTXSTY: "); DRW_DBGHL(DIMTXSTY.code, DIMTXSTY.size, DIMTXSTY.ref); + dwgHandle DIMLDRBLK = hBbuf->getHandle(); + DRW_DBG("\nDIMLDRBLK: "); DRW_DBGHL(DIMLDRBLK.code, DIMLDRBLK.size, DIMLDRBLK.ref); + dwgHandle DIMBLK = hBbuf->getHandle(); + DRW_DBG("\nDIMBLK: "); DRW_DBGHL(DIMBLK.code, DIMBLK.size, DIMBLK.ref); + dwgHandle DIMBLK1 = hBbuf->getHandle(); + DRW_DBG("\nDIMBLK1: "); DRW_DBGHL(DIMBLK1.code, DIMBLK1.size, DIMBLK1.ref); + dwgHandle DIMBLK2 = hBbuf->getHandle(); + DRW_DBG("\nDIMBLK2: "); DRW_DBGHL(DIMBLK2.code, DIMBLK2.size, DIMBLK2.ref); + } + if (version > DRW::AC1018) {//2007+ + dwgHandle DIMLTYPE = hBbuf->getHandle(); + DRW_DBG("\nDIMLTYPE: "); DRW_DBGHL(DIMLTYPE.code, DIMLTYPE.size, DIMLTYPE.ref); + dwgHandle DIMLTEX1 = hBbuf->getHandle(); + DRW_DBG("\nDIMLTEX1: "); DRW_DBGHL(DIMLTEX1.code, DIMLTEX1.size, DIMLTEX1.ref); + dwgHandle DIMLTEX2 = hBbuf->getHandle(); + DRW_DBG("\nDIMLTEX2: "); DRW_DBGHL(DIMLTEX2.code, DIMLTEX2.size, DIMLTEX2.ref); + } + if (version > DRW::AC1014) {//2000+ + vars["DIMLWD"]=new DRW_Variant(70, buf->getBitShort()); + vars["DIMLWE"]=new DRW_Variant(70, buf->getBitShort()); + } + dwgHandle CONTROL = hBbuf->getHandle(); + DRW_DBG("\nBLOCK CONTROL: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + blockCtrl = CONTROL.ref; + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nLAYER CONTROL: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + layerCtrl = CONTROL.ref; + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nSTYLE CONTROL: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + styleCtrl = CONTROL.ref; + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nLINETYPE CONTROL: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + linetypeCtrl = CONTROL.ref; + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nVIEW CONTROL: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + viewCtrl = CONTROL.ref; + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nUCS CONTROL: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + ucsCtrl = CONTROL.ref; + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nVPORT CONTROL: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + vportCtrl = CONTROL.ref; + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nAPPID CONTROL: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + appidCtrl = CONTROL.ref; + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nDIMSTYLE CONTROL: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + dimstyleCtrl = CONTROL.ref; + if (version < DRW::AC1018) {//r2000- + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nVIEWPORT ENTITY HEADER CONTROL: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + vpEntHeaderCtrl = CONTROL.ref; //RLZ: only in R13-R15 ???? + } + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nDICT ACAD_GROUP: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nDICT ACAD_MLINESTYLE: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nDICT NAMED OBJS: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + + if (version > DRW::AC1014) {//2000+ + vars["TSTACKALIGN"]=new DRW_Variant(70, buf->getBitShort()); + vars["TSTACKSIZE"]=new DRW_Variant(70, buf->getBitShort()); + if (version < DRW::AC1021) {//2004- + vars["HYPERLINKBASE"]=new DRW_Variant(1, buf->getCP8Text()); + vars["STYLESHEET"]=new DRW_Variant(1, buf->getCP8Text()); + } + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nDICT LAYOUTS: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nDICT PLOTSETTINGS: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nDICT PLOTSTYLES: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + } + if (version > DRW::AC1015) {//2004+ + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nDICT MATERIALS: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nDICT COLORS: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + } + if (version > DRW::AC1018) {//2007+ + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nDICT VISUALSTYLE: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + } + if (version > DRW::AC1024) {//2013+ + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nUNKNOWN HANDLE: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + } + if (version > DRW::AC1014) {//2000+ + DRW_DBG("\nFlags: "); DRW_DBGH(buf->getBitLong());//RLZ TODO change to 8 vars + vars["INSUNITS"]=new DRW_Variant(70, buf->getBitShort()); + duint16 cepsntype = buf->getBitShort(); + vars["CEPSNTYPE"]=new DRW_Variant(70, cepsntype); + if (cepsntype == 3){ + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nCPSNID HANDLE: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + } + if (version < DRW::AC1021) {//2004- + vars["FINGERPRINTGUID"]=new DRW_Variant(1, buf->getCP8Text()); + vars["VERSIONGUID"]=new DRW_Variant(1, buf->getCP8Text()); + } + } + if (version > DRW::AC1015) {//2004+ + vars["SORTENTS"]=new DRW_Variant(70, buf->getRawChar8()); + vars["INDEXCTL"]=new DRW_Variant(70, buf->getRawChar8()); + vars["HIDETEXT"]=new DRW_Variant(70, buf->getRawChar8()); + vars["XCLIPFRAME"]=new DRW_Variant(70, buf->getRawChar8()); + vars["DIMASSOC"]=new DRW_Variant(70, buf->getRawChar8()); + vars["HALOGAP"]=new DRW_Variant(70, buf->getRawChar8()); + vars["OBSCUREDCOLOR"]=new DRW_Variant(70, buf->getBitShort()); + vars["INTERSECTIONCOLOR"]=new DRW_Variant(70, buf->getBitShort()); + vars["OBSCUREDLTYPE"]=new DRW_Variant(70, buf->getRawChar8()); + vars["INTERSECTIONDISPLAY"]=new DRW_Variant(70, buf->getRawChar8()); + if (version < DRW::AC1021) {//2004- + vars["PROJECTNAME"]=new DRW_Variant(1, buf->getCP8Text()); + } + } + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nBLOCK PAPER_SPACE: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nBLOCK MODEL_SPACE: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nLTYPE BYLAYER: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nLTYPE BYBLOCK: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nLTYPE CONTINUOUS: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + if (version > DRW::AC1018) {//2007+ + vars["CAMERADISPLAY"]=new DRW_Variant(70, buf->getBit()); + DRW_DBG("\nUnknown 2007+ long1: "); DRW_DBG(buf->getBitLong()); + DRW_DBG("\nUnknown 2007+ long2: "); DRW_DBG(buf->getBitLong()); + DRW_DBG("\nUnknown 2007+ double2: "); DRW_DBG(buf->getBitDouble()); + vars["STEPSPERSEC"]=new DRW_Variant(40, buf->getBitDouble()); + vars["STEPSIZE"]=new DRW_Variant(40, buf->getBitDouble()); + vars["3DDWFPREC"]=new DRW_Variant(40, buf->getBitDouble()); + vars["LENSLENGTH"]=new DRW_Variant(40, buf->getBitDouble()); + vars["CAMERAHEIGHT"]=new DRW_Variant(40, buf->getBitDouble()); + vars["SOLIDHIST"]=new DRW_Variant(70, buf->getRawChar8()); + vars["SHOWHIST"]=new DRW_Variant(70, buf->getRawChar8()); + vars["PSOLWIDTH"]=new DRW_Variant(40, buf->getBitDouble()); + vars["PSOLHEIGHT"]=new DRW_Variant(40, buf->getBitDouble()); + vars["LOFTANG1"]=new DRW_Variant(40, buf->getBitDouble()); + vars["LOFTANG2"]=new DRW_Variant(40, buf->getBitDouble()); + vars["LOFTMAG1"]=new DRW_Variant(40, buf->getBitDouble()); + vars["LOFTMAG2"]=new DRW_Variant(40, buf->getBitDouble()); + vars["LOFTPARAM"]=new DRW_Variant(70, buf->getBitShort()); + vars["LOFTNORMALS"]=new DRW_Variant(40, buf->getRawChar8()); + vars["LATITUDE"]=new DRW_Variant(40, buf->getBitDouble()); + vars["LONGITUDE"]=new DRW_Variant(40, buf->getBitDouble()); + vars["NORTHDIRECTION"]=new DRW_Variant(40, buf->getBitDouble()); + vars["TIMEZONE"]=new DRW_Variant(70, buf->getBitLong()); + vars["LIGHTGLYPHDISPLAY"]=new DRW_Variant(70, buf->getRawChar8()); + vars["TILEMODELIGHTSYNCH"]=new DRW_Variant(70, buf->getRawChar8()); + vars["DWFFRAME"]=new DRW_Variant(70, buf->getRawChar8()); + vars["DGNFRAME"]=new DRW_Variant(70, buf->getRawChar8()); + DRW_DBG("\nUnknown 2007+ BIT: "); DRW_DBG(buf->getBit()); + vars["INTERFERECOLOR"]=new DRW_Variant(70, buf->getCmColor(version)); + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nINTERFEREOBJVS: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nINTERFEREVPVS: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + CONTROL = hBbuf->getHandle(); + DRW_DBG("\nDRAGVS: "); DRW_DBGHL(CONTROL.code, CONTROL.size, CONTROL.ref); + vars["CSHADOW"]=new DRW_Variant(70, buf->getRawChar8()); + DRW_DBG("\nUnknown 2007+ double2: "); DRW_DBG(buf->getBitDouble()); + } + if (version > DRW::AC1012) {//R14+ + DRW_DBG("\nUnknown R14+ short1: "); DRW_DBG(buf->getBitShort()); + DRW_DBG("\nUnknown R14+ short2: "); DRW_DBG(buf->getBitShort()); + DRW_DBG("\nUnknown R14+ short3: "); DRW_DBG(buf->getBitShort()); + DRW_DBG("\nUnknown R14+ short4: "); DRW_DBG(buf->getBitShort()); + } + + DRW_DBG("\nbuf position: "); DRW_DBG(buf->getPosition()); + DRW_DBG(" buf bit position: "); DRW_DBG(buf->getBitPos()); + + + /**** RLZ: disabled, pending to read all data ***/ + //Start reading string stream for 2007 and further + if (version > DRW::AC1018) {//2007+ + duint32 strStartPos = endBitPos -1; + buf->setPosition(strStartPos >>3); + buf->setBitPos(strStartPos&7); + if (buf->getBit() == 1){ + strStartPos -= 16; + buf->setPosition(strStartPos >>3); + buf->setBitPos(strStartPos&7); + duint32 strDataSize = buf->getRawShort16(); + if (strDataSize & 0x8000) { + strStartPos -= 16;//decrement 16 bits + strDataSize &= 0x7FFF; //strip 0x8000; + buf->setPosition(strStartPos >> 3); + buf->setBitPos(strStartPos & 7); + duint32 hiSize = buf->getRawShort16(); + strDataSize |= (hiSize << 15); + } + strStartPos -= strDataSize; + buf->setPosition(strStartPos >> 3); + buf->setBitPos(strStartPos & 7); + + DRW_DBG("\nstring buf position: "); DRW_DBG(buf->getPosition()); + DRW_DBG("\nstring buf bit position: "); DRW_DBG(buf->getBitPos()); + } + DRW_DBG("\nUnknown text1: "); DRW_DBG(buf->getUCSText(false)); + DRW_DBG("\nUnknown text2: "); DRW_DBG(buf->getUCSText(false)); + DRW_DBG("\nUnknown text3: "); DRW_DBG(buf->getUCSText(false)); + DRW_DBG("\nUnknown text4: "); DRW_DBG(buf->getUCSText(false)); + vars["MENU"]=new DRW_Variant(1, buf->getUCSText(false)); + vars["DIMPOST"]=new DRW_Variant(1, buf->getUCSText(false)); + vars["DIMAPOST"]=new DRW_Variant(1, buf->getUCSText(false)); + if (version > DRW::AC1021) {//2010+ + vars["DIMALTMZS"]=new DRW_Variant(70, buf->getUCSText(false));//RLZ: pending to verify////////////// + vars["DIMMZS"]=new DRW_Variant(70, buf->getUCSText(false));//RLZ: pending to verify////////////// + } + vars["HYPERLINKBASE"]=new DRW_Variant(1, buf->getUCSText(false)); + vars["STYLESHEET"]=new DRW_Variant(1, buf->getUCSText(false)); + vars["FINGERPRINTGUID"]=new DRW_Variant(1, buf->getUCSText(false)); + DRW_DBG("\nstring buf position: "); DRW_DBG(buf->getPosition()); + DRW_DBG(" string buf bit position: "); DRW_DBG(buf->getBitPos()); + vars["VERSIONGUID"]=new DRW_Variant(1, buf->getUCSText(false)); + DRW_DBG("\nstring buf position: "); DRW_DBG(buf->getPosition()); + DRW_DBG(" string buf bit position: "); DRW_DBG(buf->getBitPos()); + vars["PROJECTNAME"]=new DRW_Variant(1, buf->getUCSText(false)); + } +/*** ****/ + DRW_DBG("\nstring buf position: "); DRW_DBG(buf->getPosition()); + DRW_DBG(" string buf bit position: "); DRW_DBG(buf->getBitPos()); + + if (DRW_DBGGL == DRW_dbg::DEBUG){ + for (std::map::iterator it=vars.begin(); it!=vars.end(); ++it){ + DRW_DBG("\n"); DRW_DBG(it->first); DRW_DBG(": "); + switch (it->second->type){ + case DRW_Variant::INTEGER: + DRW_DBG(it->second->content.i); + break; + case DRW_Variant::DOUBLE: + DRW_DBG(it->second->content.d); + break; + case DRW_Variant::STRING: + DRW_DBG(it->second->content.s->c_str()); + break; + case DRW_Variant::COORD: + DRW_DBG("x= "); DRW_DBG(it->second->content.v->x); + DRW_DBG(", y= "); DRW_DBG(it->second->content.v->y); + DRW_DBG(", z= "); DRW_DBG(it->second->content.v->z); + break; + default: + break; + } + DRW_DBG(" code: ");DRW_DBG(it->second->code); + } + } + + buf->setPosition(size+16+4); //readed size +16 start sentinel + 4 size + if (version > DRW::AC1021 && mv > 3) { //2010+ + buf->getRawLong32();//advance 4 bytes (hisize) + } + DRW_DBG("\nseting position to: "); DRW_DBG(buf->getPosition()); + DRW_DBG("\nHeader CRC: "); DRW_DBGH(buf->getRawShort16()); + DRW_DBG("\nbuf position: "); DRW_DBG(buf->getPosition()); + DRW_DBG("\ndwg header end sentinel= "); + for (int i=0; i<16;i++) { + DRW_DBGH(buf->getRawChar8()); DRW_DBG(" "); + } + + //temporary code to show header end sentinel + duint64 sz= buf->size()-1; + if (version < DRW::AC1018) {//pre 2004 + sz= buf->size()-16; + buf->setPosition(sz); + DRW_DBG("\nseting position to: "); DRW_DBG(buf->getPosition()); + DRW_DBG("\ndwg header end sentinel= "); + for (int i=0; i<16;i++) { + DRW_DBGH(buf->getRawChar8()); DRW_DBG(" "); + } + } else if (version == DRW::AC1018) {//2004 +// sz= buf->size()-132; +// buf->setPosition(sz); + buf->moveBitPos(-128); + DRW_DBG("\nseting position to: "); DRW_DBG(buf->getPosition()); + DRW_DBG("\ndwg header end sentinel= "); + for (int i=0; i<16;i++) { + DRW_DBGH(buf->getRawChar8()); DRW_DBG(" "); + } + } else if (version == DRW::AC1021) {//2007 + sz= buf->size()-16; + buf->setPosition(sz); + DRW_DBG("\nseting position to: "); DRW_DBG(buf->getPosition()); + DRW_DBG("\ndwg header end sentinel= "); + for (int i=0; i<16;i++) { + DRW_DBGH(buf->getRawChar8()); DRW_DBG(" "); + } + } else if (version == DRW::AC1024) {//2010 +// sz= buf->size()-93; +// buf->setPosition(sz); + buf->moveBitPos(-128); + DRW_DBG("\nseting position to: "); DRW_DBG(buf->getPosition()); + DRW_DBG("\ndwg header end sentinel= "); + for (int i=0; i<16;i++) { + DRW_DBGH(buf->getRawChar8()); DRW_DBG(" "); + } + } else if (version == DRW::AC1027) {//2013 +// sz= buf->size()-76; +// buf->setPosition(sz); + buf->moveBitPos(-128); + DRW_DBG("\nseting position to: "); DRW_DBG(buf->getPosition()); + DRW_DBG("\ndwg header end sentinel= "); + for (int i=0; i<16;i++) { + DRW_DBGH(buf->getRawChar8()); DRW_DBG(" "); + } + } + + return result; +} diff --git a/src/libs/vdxf/libdxfrw/drw_header.h b/src/libs/vdxf/libdxfrw/drw_header.h new file mode 100644 index 000000000..a8fdc8e3f --- /dev/null +++ b/src/libs/vdxf/libdxfrw/drw_header.h @@ -0,0 +1,107 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#ifndef DRW_HEADER_H +#define DRW_HEADER_H + + +#include +#include "drw_base.h" + +class dxfReader; +class dxfWriter; +class dwgBuffer; + +#define SETHDRFRIENDS friend class dxfRW; \ + friend class dwgReader; + +//! Class to handle header entries +/*! +* Class to handle header vars, to read iterate over "std::map vars" +* to write add a DRW_Variant* into "std::map vars" (do not delete it, are cleared in dtor) +* or use add* helper functions. +* @author Rallaz +*/ +class DRW_Header { + SETHDRFRIENDS +public: + DRW_Header(); + ~DRW_Header() { + clearVars(); + } + + DRW_Header(const DRW_Header& h){ + this->version = h.version; + this->comments = h.comments; + for (std::map::const_iterator it=h.vars.begin(); it!=h.vars.end(); ++it){ + this->vars[it->first] = new DRW_Variant( *(it->second) ); + } + this->curr = NULL; + } + DRW_Header& operator=(const DRW_Header &h) { + if(this != &h) { + clearVars(); + this->version = h.version; + this->comments = h.comments; + for (std::map::const_iterator it=h.vars.begin(); it!=h.vars.end(); ++it){ + this->vars[it->first] = new DRW_Variant( *(it->second) ); + } + } + return *this; + } + + void addDouble(std::string key, double value, int code); + void addInt(std::string key, int value, int code); + void addStr(std::string key, std::string value, int code); + void addCoord(std::string key, DRW_Coord value, int code); + std::string getComments() const {return comments;} + void write(dxfWriter *writer, DRW::Version ver); + void addComment(std::string c); + +protected: + void parseCode(int code, dxfReader *reader); + bool parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer *hBbuf, duint8 mv=0); +private: + bool getDouble(std::string key, double *varDouble); + bool getInt(std::string key, int *varInt); + bool getStr(std::string key, std::string *varStr); + bool getCoord(std::string key, DRW_Coord *varStr); + void clearVars(){ + for (std::map::iterator it=vars.begin(); it!=vars.end(); ++it) + delete it->second; + + vars.clear(); + } + +public: + std::map vars; +private: + std::string comments; + std::string name; + DRW_Variant* curr; + int version; //to use on read + + duint32 linetypeCtrl; + duint32 layerCtrl; + duint32 styleCtrl; + duint32 dimstyleCtrl; + duint32 appidCtrl; + duint32 blockCtrl; + duint32 viewCtrl; + duint32 ucsCtrl; + duint32 vportCtrl; + duint32 vpEntHeaderCtrl; +}; + +#endif + +// EOF diff --git a/src/libs/vdxf/libdxfrw/drw_interface.h b/src/libs/vdxf/libdxfrw/drw_interface.h new file mode 100644 index 000000000..b0de89012 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/drw_interface.h @@ -0,0 +1,190 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#ifndef DRW_INTERFACE_H +#define DRW_INTERFACE_H + +#include + +#include "drw_entities.h" +#include "drw_objects.h" +#include "drw_header.h" + +/** + * Abstract class (interface) for comunicate dxfReader with the application. + * Inherit your class which takes care of the entities in the + * processed DXF file from this interface. + * + * @author Rallaz + */ +class DRW_Interface { +public: + DRW_Interface() { + } + virtual ~DRW_Interface() = default; + + /** Called when header is parsed. */ + virtual void addHeader(const DRW_Header *) { } + + /** Called for every line Type. */ + virtual void addLType(const DRW_LType &) { } + /** Called for every layer. */ + virtual void addLayer(const DRW_Layer &) { } + /** Called for every dim style. */ + virtual void addDimStyle(const DRW_Dimstyle &) { } + /** Called for every VPORT table. */ + virtual void addVport(const DRW_Vport &) { } + /** Called for every text style. */ + virtual void addTextStyle(const DRW_Textstyle &) { } + /** Called for every AppId entry. */ + virtual void addAppId(const DRW_AppId &) { } + + /** + * Called for every block. Note: all entities added after this + * command go into this block until endBlock() is called. + * + * @see endBlock() + */ + virtual void addBlock(const DRW_Block &) { } + + /** Called to end the current block */ + virtual void endBlock() { } + + /** Called for every point */ + virtual void addPoint(const DRW_Point &) { } + + /** Called for every line */ + virtual void addLine(const DRW_Line &) { } + + /** Called for every ray */ + virtual void addRay(const DRW_Ray &) { } + + /** Called for every xline */ + virtual void addXline(const DRW_Xline &) { } + + /** Called for every arc */ + virtual void addArc(const DRW_Arc &) { } + + /** Called for every circle */ + virtual void addCircle(const DRW_Circle &) { } + + /** Called for every ellipse */ + virtual void addEllipse(const DRW_Ellipse &) { } + + /** Called for every lwpolyline */ + virtual void addLWPolyline(const DRW_LWPolyline &) { } + + /** Called for every polyline start */ + virtual void addPolyline(const DRW_Polyline &) { } + + /** Called for every spline */ + virtual void addSpline(const DRW_Spline *) { } + + /** Called for every spline knot value */ + virtual void addKnot(const DRW_Entity &) { } + + /** Called for every insert. */ + virtual void addInsert(const DRW_Insert &) { } + + /** Called for every trace start */ + virtual void addTrace(const DRW_Trace &) { } + + /** Called for every 3dface start */ + virtual void add3dFace(const DRW_3Dface &) { } + + /** Called for every solid start */ + virtual void addSolid(const DRW_Solid &) { } + + + /** Called for every Multi Text entity. */ + virtual void addMText(const DRW_MText &) { } + + /** Called for every Text entity. */ + virtual void addText(const DRW_Text &) { } + + /** + * Called for every aligned dimension entity. + */ + virtual void addDimAlign(const DRW_DimAligned *) { } + /** + * Called for every linear or rotated dimension entity. + */ + virtual void addDimLinear(const DRW_DimLinear *) { } + + /** + * Called for every radial dimension entity. + */ + virtual void addDimRadial(const DRW_DimRadial *) { } + + /** + * Called for every diametric dimension entity. + */ + virtual void addDimDiametric(const DRW_DimDiametric *) { } + + /** + * Called for every angular dimension (2 lines version) entity. + */ + virtual void addDimAngular(const DRW_DimAngular *) { } + + /** + * Called for every angular dimension (3 points version) entity. + */ + virtual void addDimAngular3P(const DRW_DimAngular3p *) { } + + /** + * Called for every ordinate dimension entity. + */ + virtual void addDimOrdinate(const DRW_DimOrdinate *) { } + + /** + * Called for every leader start. + */ + virtual void addLeader(const DRW_Leader *) { } + + /** + * Called for every hatch entity. + */ + virtual void addHatch(const DRW_Hatch *) { } + + /** + * Called for every viewport entity. + */ + virtual void addViewport(const DRW_Viewport &) { } + + /** + * Called for every image entity. + */ + virtual void addImage(const DRW_Image *) { } + + /** + * Called for every image definition. + */ + virtual void linkImage(const DRW_ImageDef *) { } + + /** + * Called for every comment in the DXF file (code 999). + */ + virtual void addComment(const char *) { } + + virtual void writeHeader(DRW_Header &) { } + virtual void writeBlocks() { } + virtual void writeBlockRecords() { } + virtual void writeEntities() { } + virtual void writeLTypes() { } + virtual void writeLayers() { } + virtual void writeTextstyles() { } + virtual void writeVports() { } + virtual void writeDimstyles() { } + virtual void writeAppId() { } +}; + +#endif diff --git a/src/libs/vdxf/libdxfrw/drw_objects.cpp b/src/libs/vdxf/libdxfrw/drw_objects.cpp new file mode 100644 index 000000000..88818b313 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/drw_objects.cpp @@ -0,0 +1,1236 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#include +#include +#include "drw_objects.h" +#include "intern/dxfreader.h" +#include "intern/dxfwriter.h" +#include "intern/dwgbuffer.h" +#include "intern/drw_dbg.h" +#include "intern/dwgutil.h" + +//! Base class for tables entries +/*! +* Base class for tables entries +* @author Rallaz +*/ +void DRW_TableEntry::parseCode(int code, dxfReader *reader){ + switch (code) { + case 5: + handle = reader->getHandleString(); + break; + case 330: + parentHandle = reader->getHandleString(); + break; + case 2: + name = reader->getUtf8String(); + break; + case 70: + flags = reader->getInt32(); + break; + case 1000: + case 1001: + case 1002: + case 1003: + case 1004: + case 1005: + extData.push_back(new DRW_Variant(code, reader->getString())); + break; + case 1010: + case 1011: + case 1012: + case 1013: + curr = new DRW_Variant(); + curr->addCoord(); + curr->setCoordX(reader->getDouble()); + curr->code = code; + extData.push_back(curr); + break; + case 1020: + case 1021: + case 1022: + case 1023: + if (curr) + curr->setCoordY(reader->getDouble()); + break; + case 1030: + case 1031: + case 1032: + case 1033: + if (curr) + curr->setCoordZ(reader->getDouble()); + curr=NULL; + break; + case 1040: + case 1041: + case 1042: + extData.push_back(new DRW_Variant(code, reader->getDouble())); + break; + case 1070: + case 1071: + extData.push_back(new DRW_Variant(code, reader->getInt32() )); + break; + default: + break; + } +} + +bool DRW_TableEntry::parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer *strBuf, duint32 bs){ +DRW_DBG("\n***************************** parsing table entry *********************************************\n"); + objSize=0; + oType = buf->getObjType(version); + DRW_DBG("Object type: "); DRW_DBG(oType); DRW_DBG(", "); DRW_DBGH(oType); + if (version > DRW::AC1014 && version < DRW::AC1024) {//2000 to 2007 + objSize = buf->getRawLong32(); //RL 32bits object size in bits + DRW_DBG(" Object size: "); DRW_DBG(objSize); DRW_DBG("\n"); + } + if (version > DRW::AC1021) {//2010+ + duint32 ms = buf->size(); + objSize = ms*8 - bs; + DRW_DBG(" Object size: "); DRW_DBG(objSize); DRW_DBG("\n"); + } + if (strBuf != NULL && version > DRW::AC1018) {//2007+ + strBuf->moveBitPos(objSize-1); + DRW_DBG(" strBuf strbit pos 2007: "); DRW_DBG(strBuf->getPosition()); DRW_DBG(" strBuf bpos 2007: "); DRW_DBG(strBuf->getBitPos()); DRW_DBG("\n"); + if (strBuf->getBit() == 1){ + DRW_DBG("DRW_TableEntry::parseDwg string bit is 1\n"); + strBuf->moveBitPos(-17); + duint16 strDataSize = strBuf->getRawShort16(); + DRW_DBG("\nDRW_TableEntry::parseDwg string strDataSize: "); DRW_DBGH(strDataSize); DRW_DBG("\n"); + if ( (strDataSize& 0x8000) == 0x8000){ + DRW_DBG("\nDRW_TableEntry::parseDwg string 0x8000 bit is set"); + strBuf->moveBitPos(-33);//RLZ pending to verify + duint16 hiSize = strBuf->getRawShort16(); + strDataSize = ((strDataSize&0x7fff) | (hiSize<<15)); + } + strBuf->moveBitPos( -strDataSize -16); //-14 + DRW_DBG("strBuf start strDataSize pos 2007: "); DRW_DBG(strBuf->getPosition()); DRW_DBG(" strBuf bpos 2007: "); DRW_DBG(strBuf->getBitPos()); DRW_DBG("\n"); + } else + DRW_DBG("\nDRW_TableEntry::parseDwg string bit is 0"); + DRW_DBG("strBuf start pos 2007: "); DRW_DBG(strBuf->getPosition()); DRW_DBG(" strBuf bpos 2007: "); DRW_DBG(strBuf->getBitPos()); DRW_DBG("\n"); + } + + dwgHandle ho = buf->getHandle(); + handle = ho.ref; + DRW_DBG("TableEntry Handle: "); DRW_DBGHL(ho.code, ho.size, ho.ref); + dint16 extDataSize = buf->getBitShort(); //BS + DRW_DBG(" ext data size: "); DRW_DBG(extDataSize); + while (extDataSize>0 && buf->isGood()) { + /* RLZ: TODO */ + dwgHandle ah = buf->getHandle(); + DRW_DBG("App Handle: "); DRW_DBGHL(ah.code, ah.size, ah.ref); + duint8 *tmpExtData = new duint8[extDataSize]; + buf->getBytes(tmpExtData, extDataSize); + dwgBuffer tmpExtDataBuf(tmpExtData, extDataSize, buf->decoder); + int pos = tmpExtDataBuf.getPosition(); + int bpos = tmpExtDataBuf.getBitPos(); + DRW_DBG("ext data pos: "); DRW_DBG(pos); DRW_DBG("."); DRW_DBG(bpos); DRW_DBG("\n"); + duint8 dxfCode = tmpExtDataBuf.getRawChar8(); + DRW_DBG(" dxfCode: "); DRW_DBG(dxfCode); + switch (dxfCode){ + case 0:{ + duint8 strLength = tmpExtDataBuf.getRawChar8(); + DRW_DBG(" strLength: "); DRW_DBG(strLength); + duint16 cp = tmpExtDataBuf.getBERawShort16(); + DRW_DBG(" str codepage: "); DRW_DBG(cp); + for (int i=0;i< strLength+1;i++) {//string length + null terminating char + duint8 dxfChar = tmpExtDataBuf.getRawChar8(); + DRW_DBG(" dxfChar: "); DRW_DBG(dxfChar); + } + break; + } + default: + /* RLZ: TODO */ + break; + } + DRW_DBG("ext data pos: "); DRW_DBG(tmpExtDataBuf.getPosition()); DRW_DBG("."); DRW_DBG(tmpExtDataBuf.getBitPos()); DRW_DBG("\n"); + delete[]tmpExtData; + extDataSize = buf->getBitShort(); //BS + DRW_DBG(" ext data size: "); DRW_DBG(extDataSize); + } //end parsing extData (EED) + if (version < DRW::AC1015) {//14- + objSize = buf->getRawLong32(); //RL 32bits size in bits + } + DRW_DBG(" objSize in bits: "); DRW_DBG(objSize); + + numReactors = buf->getBitLong(); //BL + DRW_DBG(", numReactors: "); DRW_DBG(numReactors); DRW_DBG("\n"); + if (version > DRW::AC1015) {//2004+ + xDictFlag = buf->getBit(); + DRW_DBG("xDictFlag: "); DRW_DBG(xDictFlag); + } + if (version > DRW::AC1024) {//2013+ + duint8 bd = buf->getBit(); + DRW_DBG(" Have binary data: "); DRW_DBG(bd); DRW_DBG("\n"); + } + return buf->isGood(); +} + +//! Class to handle dimstyle entries +/*! +* Class to handle ldim style symbol table entries +* @author Rallaz +*/ +void DRW_Dimstyle::parseCode(int code, dxfReader *reader){ + switch (code) { + case 105: + handle = reader->getHandleString(); + break; + case 3: + dimpost = reader->getUtf8String(); + break; + case 4: + dimapost = reader->getUtf8String(); + break; + case 5: + dimblk = reader->getUtf8String(); + break; + case 6: + dimblk1 = reader->getUtf8String(); + break; + case 7: + dimblk2 = reader->getUtf8String(); + break; + case 40: + dimscale = reader->getDouble(); + break; + case 41: + dimasz = reader->getDouble(); + break; + case 42: + dimexo = reader->getDouble(); + break; + case 43: + dimdli = reader->getDouble(); + break; + case 44: + dimexe = reader->getDouble(); + break; + case 45: + dimrnd = reader->getDouble(); + break; + case 46: + dimdle = reader->getDouble(); + break; + case 47: + dimtp = reader->getDouble(); + break; + case 48: + dimtm = reader->getDouble(); + break; + case 49: + dimfxl = reader->getDouble(); + break; + case 140: + dimtxt = reader->getDouble(); + break; + case 141: + dimcen = reader->getDouble(); + break; + case 142: + dimtsz = reader->getDouble(); + break; + case 143: + dimaltf = reader->getDouble(); + break; + case 144: + dimlfac = reader->getDouble(); + break; + case 145: + dimtvp = reader->getDouble(); + break; + case 146: + dimtfac = reader->getDouble(); + break; + case 147: + dimgap = reader->getDouble(); + break; + case 148: + dimaltrnd = reader->getDouble(); + break; + case 71: + dimtol = reader->getInt32(); + break; + case 72: + dimlim = reader->getInt32(); + break; + case 73: + dimtih = reader->getInt32(); + break; + case 74: + dimtoh = reader->getInt32(); + break; + case 75: + dimse1 = reader->getInt32(); + break; + case 76: + dimse2 = reader->getInt32(); + break; + case 77: + dimtad = reader->getInt32(); + break; + case 78: + dimzin = reader->getInt32(); + break; + case 79: + dimazin = reader->getInt32(); + break; + case 170: + dimalt = reader->getInt32(); + break; + case 171: + dimaltd = reader->getInt32(); + break; + case 172: + dimtofl = reader->getInt32(); + break; + case 173: + dimsah = reader->getInt32(); + break; + case 174: + dimtix = reader->getInt32(); + break; + case 175: + dimsoxd = reader->getInt32(); + break; + case 176: + dimclrd = reader->getInt32(); + break; + case 177: + dimclre = reader->getInt32(); + break; + case 178: + dimclrt = reader->getInt32(); + break; + case 179: + dimadec = reader->getInt32(); + break; + case 270: + dimunit = reader->getInt32(); + break; + case 271: + dimdec = reader->getInt32(); + break; + case 272: + dimtdec = reader->getInt32(); + break; + case 273: + dimaltu = reader->getInt32(); + break; + case 274: + dimalttd = reader->getInt32(); + break; + case 275: + dimaunit = reader->getInt32(); + break; + case 276: + dimfrac = reader->getInt32(); + break; + case 277: + dimlunit = reader->getInt32(); + break; + case 278: + dimdsep = reader->getInt32(); + break; + case 279: + dimtmove = reader->getInt32(); + break; + case 280: + dimjust = reader->getInt32(); + break; + case 281: + dimsd1 = reader->getInt32(); + break; + case 282: + dimsd2 = reader->getInt32(); + break; + case 283: + dimtolj = reader->getInt32(); + break; + case 284: + dimtzin = reader->getInt32(); + break; + case 285: + dimaltz = reader->getInt32(); + break; + case 286: + dimaltttz = reader->getInt32(); + break; + case 287: + dimfit = reader->getInt32(); + break; + case 288: + dimupt = reader->getInt32(); + break; + case 289: + dimatfit = reader->getInt32(); + break; + case 290: + dimfxlon = reader->getInt32(); + break; + case 340: + dimtxsty = reader->getUtf8String(); + break; + case 341: + dimldrblk = reader->getUtf8String(); + break; + case 342: + dimblk = reader->getUtf8String(); + break; + case 343: + dimblk1 = reader->getUtf8String(); + break; + case 344: + dimblk2 = reader->getUtf8String(); + break; + default: + DRW_TableEntry::parseCode(code, reader); + break; + } +} + +bool DRW_Dimstyle::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dwgBuffer sBuff = *buf; + dwgBuffer *sBuf = buf; + if (version > DRW::AC1018) {//2007+ + sBuf = &sBuff; //separate buffer for strings + } + bool ret = DRW_TableEntry::parseDwg(version, buf, sBuf, bs); + DRW_DBG("\n***************************** parsing dimension style **************************************\n"); + if (!ret) + return ret; + name = sBuf->getVariableText(version, false); + DRW_DBG("dimension style name: "); DRW_DBG(name.c_str()); DRW_DBG("\n"); + +// handleObj = shpControlH.ref; + DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + // RS crc; //RS */ + return buf->isGood(); +} + + +//! Class to handle line type entries +/*! +* Class to handle line type symbol table entries +* @author Rallaz +*/ +void DRW_LType::parseCode(int code, dxfReader *reader){ + switch (code) { + case 3: + desc = reader->getUtf8String(); + break; + case 73: + size = reader->getInt32(); + path.clear(); + path.reserve(size); + break; + case 40: + length = reader->getDouble(); + break; + case 49: + path.push_back(reader->getDouble()); + pathIdx++; + break; +/* case 74: + haveShape = reader->getInt32(); + break;*/ + default: + DRW_TableEntry::parseCode(code, reader); + break; + } +} + +//! Update line type +/*! +* Update the size and length of line type acording to the path +* @author Rallaz +*/ +/*TODO: control max length permited */ +void DRW_LType::update(){ + double d =0; + size = (int)path.size(); + for (int i = 0; i< size; i++){ + d += fabs(path.at(i)); + } + length = d; +} + +bool DRW_LType::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dwgBuffer sBuff = *buf; + dwgBuffer *sBuf = buf; + if (version > DRW::AC1018) {//2007+ + sBuf = &sBuff; //separate buffer for strings + } + bool ret = DRW_TableEntry::parseDwg(version, buf, sBuf, bs); + DRW_DBG("\n***************************** parsing line type *********************************************\n"); + if (!ret) + return ret; + name = sBuf->getVariableText(version, false); + DRW_DBG("linetype name: "); DRW_DBG(name.c_str()); DRW_DBG("\n"); + flags = buf->getBit()<< 6; + DRW_DBG("flags: "); DRW_DBG(flags); + if (version > DRW::AC1018) {//2007+ + } else {//2004- //RLZ: verify in 2004, 2010 &2013 + dint16 xrefindex = buf->getBitShort(); + DRW_DBG(" xrefindex: "); DRW_DBG(xrefindex); + } + duint8 xdep = buf->getBit(); + DRW_DBG(" xdep: "); DRW_DBG(xdep); + flags |= xdep<< 4; + DRW_DBG(" flags: "); DRW_DBG(flags); + desc = sBuf->getVariableText(version, false); + DRW_DBG(" desc: "); DRW_DBG(desc.c_str()); + length = buf->getBitDouble(); + DRW_DBG(" pattern length: "); DRW_DBG(length); + char align = buf->getRawChar8(); + DRW_DBG(" align: "); DRW_DBG(std::string(&align, 1)); + size = buf->getRawChar8(); + DRW_DBG(" num dashes, size: "); DRW_DBG(size); + DRW_DBG("\n dashes:\n"); + bool haveStrArea = false; + for (int i=0; i< size; i++){ + path.push_back(buf->getBitDouble()); + /*int bs1 =*/ buf->getBitShort(); + /*double d1= */buf->getRawDouble(); + /*double d2=*/ buf->getRawDouble(); + /*double d3= */buf->getBitDouble(); + /*double d4= */buf->getBitDouble(); + int bs2 = buf->getBitShort(); + if((bs2 & 2) !=0) haveStrArea = true; + } + for (unsigned i=0; inumRemainingBytes()); DRW_DBG("\n"); + if (version < DRW::AC1021) { //2004- + duint8 strarea[256]; + buf->getBytes(strarea, 256); + DRW_DBG("string area 256 bytes:\n"); DRW_DBG(reinterpret_cast(strarea)); DRW_DBG("\n"); + } else { //2007+ + //first verify flag + if (haveStrArea) { + duint8 strarea[512]; + buf->getBytes(strarea, 512); + DRW_DBG("string area 512 bytes:\n"); DRW_DBG(reinterpret_cast(strarea)); DRW_DBG("\n"); + } else + DRW_DBG("string area 512 bytes not present\n"); + } + + if (version > DRW::AC1021) {//2007+ skip string area + DRW_DBG(" ltype end of object data pos 2010: "); DRW_DBG(buf->getPosition()); DRW_DBG(" strBuf bpos 2007: "); DRW_DBG(buf->getBitPos()); DRW_DBG("\n"); + } + if (version > DRW::AC1018) {//2007+ skip string area + buf->setPosition(objSize >> 3); + buf->setBitPos(objSize & 7); + } + + if (version > DRW::AC1021) {//2007+ skip string area + DRW_DBG(" ltype start of handles data pos 2010: "); DRW_DBG(buf->getPosition()); DRW_DBG(" strBuf bpos 2007: "); DRW_DBG(buf->getBitPos()); DRW_DBG("\n"); + } + + DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + dwgHandle ltControlH = buf->getHandle(); + DRW_DBG("linetype control Handle: "); DRW_DBGHL(ltControlH.code, ltControlH.size, ltControlH.ref); + parentHandle = ltControlH.ref; + DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + for (int i=0; i< numReactors;++i) { + dwgHandle reactorsH = buf->getHandle(); + DRW_DBG(" reactorsH control Handle: "); DRW_DBGHL(reactorsH.code, reactorsH.size, reactorsH.ref); DRW_DBG("\n"); + } + if (xDictFlag !=1){//linetype in 2004 seems not have XDicObjH or NULL handle + dwgHandle XDicObjH = buf->getHandle(); + DRW_DBG(" XDicObj control Handle: "); DRW_DBGHL(XDicObjH.code, XDicObjH.size, XDicObjH.ref); DRW_DBG("\n"); + DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + } + if(size>0){ + dwgHandle XRefH = buf->getHandle(); + DRW_DBG(" XRefH control Handle: "); DRW_DBGHL(XRefH.code, XRefH.size, XRefH.ref); DRW_DBG("\n"); + dwgHandle shpHandle = buf->getHandle(); + DRW_DBG(" shapeFile Handle: "); DRW_DBGHL(shpHandle.code, shpHandle.size, shpHandle.ref); + DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + } + dwgHandle shpHandle = buf->getHandle(); + DRW_DBG(" shapeFile +1 Handle ??: "); DRW_DBGHL(shpHandle.code, shpHandle.size, shpHandle.ref); DRW_DBG("\n"); + + DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); +// RS crc; //RS */ + return buf->isGood(); +} + +//! Class to handle layer entries +/*! +* Class to handle layer symbol table entries +* @author Rallaz +*/ +void DRW_Layer::parseCode(int code, dxfReader *reader){ + switch (code) { + case 6: + lineType = reader->getUtf8String(); + break; + case 62: + color = reader->getInt32(); + break; + case 290: + plotF = reader->getBool(); + break; + case 370: + lWeight = DRW_LW_Conv::dxfInt2lineWidth(reader->getInt32()); + break; + case 390: + handlePlotS = reader->getString(); + break; + case 347: + handleMaterialS = reader->getString(); + break; + case 420: + color24 = reader->getInt32(); + break; + default: + DRW_TableEntry::parseCode(code, reader); + break; + } +} + +bool DRW_Layer::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dwgBuffer sBuff = *buf; + dwgBuffer *sBuf = buf; + if (version > DRW::AC1018) {//2007+ + sBuf = &sBuff; //separate buffer for strings + } + bool ret = DRW_TableEntry::parseDwg(version, buf, sBuf, bs); + DRW_DBG("\n***************************** parsing layer *********************************************\n"); + if (!ret) + return ret; + name = sBuf->getVariableText(version, false); + DRW_DBG("layer name: "); DRW_DBG(name.c_str()); + + flags |= buf->getBit()<< 6;//layer have entity + if (version < DRW::AC1021) {//2004- + DRW_DBG(", xrefindex = "); DRW_DBG(buf->getBitShort()); DRW_DBG("\n"); + //dint16 xrefindex = buf->getBitShort(); + } + flags |= buf->getBit() << 4;//is refx dependent + if (version < DRW::AC1015) {//14- + flags |= buf->getBit(); //layer frozen + /*flags |=*/ buf->getBit(); //unused, negate the color + flags |= buf->getBit() << 1;//frozen in new + flags |= buf->getBit()<< 3;//locked + } + if (version > DRW::AC1014) {//2000+ + dint16 f = buf->getSBitShort();//bit2 are layer on + DRW_DBG(", flags 2000+: "); DRW_DBG(f); DRW_DBG("\n"); + flags |= f & 0x0001; //layer frozen + flags |= ( f>> 1) & 0x0002;//frozen in new + flags |= ( f>> 1) & 0x0004;//locked + plotF = ( f>> 4) & 0x0001; + lWeight = DRW_LW_Conv::dwgInt2lineWidth( (f & 0x03E0) >> 5 ); + } + color = buf->getCmColor(version); //BS or CMC //ok for R14 or negate + DRW_DBG(", entity color: "); DRW_DBG(color); DRW_DBG("\n"); + + if (version > DRW::AC1018) {//2007+ skip string area + buf->setPosition(objSize >> 3); + buf->setBitPos(objSize & 7); + } + dwgHandle layerControlH = buf->getHandle(); + DRW_DBG("layer control Handle: "); DRW_DBGHL(layerControlH.code, layerControlH.size, layerControlH.ref); + parentHandle = layerControlH.ref; + + if (xDictFlag !=1){//linetype in 2004 seems not have XDicObjH or NULL handle + dwgHandle XDicObjH = buf->getHandle(); + DRW_DBG(" XDicObj control Handle: "); DRW_DBGHL(XDicObjH.code, XDicObjH.size, XDicObjH.ref); DRW_DBG("\n"); + } + dwgHandle XRefH = buf->getHandle(); + DRW_DBG(" XRefH control Handle: "); DRW_DBGHL(XRefH.code, XRefH.size, XRefH.ref); DRW_DBG("\n"); + if (version > DRW::AC1014) {//2000+ + dwgHandle plotStyH = buf->getHandle(); + DRW_DBG(" PLot style control Handle: "); DRW_DBGHL(plotStyH.code, plotStyH.size, plotStyH.ref); DRW_DBG("\n"); + handlePlotS = DRW::toHexStr(plotStyH.ref);// std::string(plotStyH.ref);//RLZ: verify conversion + } + if (version > DRW::AC1018) {//2007+ + dwgHandle materialH = buf->getHandle(); + DRW_DBG(" Material control Handle: "); DRW_DBGHL(materialH.code, materialH.size, materialH.ref); DRW_DBG("\n"); + handleMaterialS = DRW::toHexStr(materialH.ref);//RLZ: verify conversion + } + //lineType handle + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + lTypeH = buf->getHandle(); + DRW_DBG("line type Handle: "); DRW_DBGHL(lTypeH.code, lTypeH.size, lTypeH.ref); + DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); +// RS crc; //RS */ + return buf->isGood(); +} + +bool DRW_Block_Record::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dwgBuffer sBuff = *buf; + dwgBuffer *sBuf = buf; + if (version > DRW::AC1018) {//2007+ + sBuf = &sBuff; //separate buffer for strings + } + bool ret = DRW_TableEntry::parseDwg(version, buf, sBuf, bs); + DRW_DBG("\n***************************** parsing block record ******************************************\n"); + if (!ret) + return ret; + duint32 insertCount = 0;//only 2000+ + duint32 objectCount = 0; //only 2004+ + + name = sBuf->getVariableText(version, false); + DRW_DBG("block record name: "); DRW_DBG(name.c_str()); DRW_DBG("\n"); + + flags |= buf->getBit()<< 6;//referenced external reference, block code 70, bit 7 (64) + if (version > DRW::AC1018) {//2007+ + } else {//2004- //RLZ: verify in 2004, 2010 &2013 + dint16 xrefindex = buf->getBitShort(); + DRW_DBG(" xrefindex: "); DRW_DBG(xrefindex); DRW_DBG("\n"); + } + flags |= buf->getBit() << 4;//is refx dependent, block code 70, bit 5 (16) + flags |= buf->getBit(); //if is anonimous block (*U) block code 70, bit 1 (1) + flags |= buf->getBit() << 1; //if block contains attdefs, block code 70, bit 2 (2) + bool blockIsXref = buf->getBit(); //if is a Xref, block code 70, bit 3 (4) + bool xrefOverlaid = buf->getBit(); //if is a overlaid Xref, block code 70, bit 4 (8) + flags |= blockIsXref << 2; //if is a Xref, block code 70, bit 3 (4) + flags |= xrefOverlaid << 3; //if is a overlaid Xref, block code 70, bit 4 (8) + if (version > DRW::AC1014) {//2000+ + flags |= buf->getBit() << 5; //if is a loaded Xref, block code 70, bit 6 (32) + } + DRW_DBG("flags: "); DRW_DBG(flags); DRW_DBG(", "); + if (version > DRW::AC1015) {//2004+ fails in 2007 + objectCount = buf->getBitLong(); //Number of objects owned by this block + entMap.reserve(objectCount); + } + basePoint.x = buf->getBitDouble(); + basePoint.y = buf->getBitDouble(); + basePoint.z = buf->getBitDouble(); + DRW_DBG("insertion point: "); DRW_DBGPT(basePoint.x, basePoint.y, basePoint.z); DRW_DBG("\n"); + UTF8STRING path = sBuf->getVariableText(version, false); + DRW_DBG("XRef path name: "); DRW_DBG(path.c_str()); DRW_DBG("\n"); + + if (version > DRW::AC1014) {//2000+ + insertCount = 0; + while (duint8 i = buf->getRawChar8() != 0) + insertCount +=i; + UTF8STRING bkdesc = sBuf->getVariableText(version, false); + DRW_DBG("Block description: "); DRW_DBG(bkdesc.c_str()); DRW_DBG("\n"); + + duint32 prevData = buf->getBitLong(); + for (unsigned int j= 0; j < prevData; ++j) + buf->getRawChar8(); + } + if (version > DRW::AC1018) {//2007+ + duint16 insUnits = buf->getBitShort(); + bool canExplode = buf->getBit(); //if block can be exploded + duint8 bkScaling = buf->getRawChar8(); + + DRW_UNUSED(insUnits); + DRW_UNUSED(canExplode); + DRW_UNUSED(bkScaling); + } + + if (version > DRW::AC1018) {//2007+ skip string area + buf->setPosition(objSize >> 3); + buf->setBitPos(objSize & 7); + } + + dwgHandle blockControlH = buf->getHandle(); + DRW_DBG("block control Handle: "); DRW_DBGHL(blockControlH.code, blockControlH.size, blockControlH.ref); DRW_DBG("\n"); + parentHandle = blockControlH.ref; + + for (int i=0; igetHandle(); + DRW_DBG(" reactor Handle #"); DRW_DBG(i); DRW_DBG(": "); DRW_DBGHL(reactorH.code, reactorH.size, reactorH.ref); DRW_DBG("\n"); + } + if (xDictFlag !=1) {//R14+ //seems present in 2000 + dwgHandle XDicObjH = buf->getHandle(); + DRW_DBG(" XDicObj control Handle: "); DRW_DBGHL(XDicObjH.code, XDicObjH.size, XDicObjH.ref); DRW_DBG("\n"); + } + if (version != DRW::AC1021) {//2007+ XDicObjH or NullH not present + } + dwgHandle NullH = buf->getHandle(); + DRW_DBG(" NullH control Handle: "); DRW_DBGHL(NullH.code, NullH.size, NullH.ref); DRW_DBG("\n"); + dwgHandle blockH = buf->getOffsetHandle(handle); + DRW_DBG(" blockH Handle: "); DRW_DBGHL(blockH.code, blockH.size, blockH.ref); DRW_DBG("\n"); + block = blockH.ref; + + if (version > DRW::AC1015) {//2004+ + for (unsigned int i=0; i< objectCount; i++){ + dwgHandle entityH = buf->getHandle(); + DRW_DBG(" entityH Handle #"); DRW_DBG(i); DRW_DBG(": "); DRW_DBGHL(entityH.code, entityH.size, entityH.ref); DRW_DBG("\n"); + entMap.push_back(entityH.ref); + } + } else {//2000- + if(!blockIsXref && !xrefOverlaid){ + dwgHandle firstH = buf->getHandle(); + DRW_DBG(" firstH entity Handle: "); DRW_DBGHL(firstH.code, firstH.size, firstH.ref); DRW_DBG("\n"); + firstEH = firstH.ref; + dwgHandle lastH = buf->getHandle(); + DRW_DBG(" lastH entity Handle: "); DRW_DBGHL(lastH.code, lastH.size, lastH.ref); DRW_DBG("\n"); + lastEH = lastH.ref; + } + } + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + dwgHandle endBlockH = buf->getOffsetHandle(handle); + DRW_DBG(" endBlockH Handle: "); DRW_DBGHL(endBlockH.code, endBlockH.size, endBlockH.ref); DRW_DBG("\n"); + endBlock = endBlockH.ref; + + if (version > DRW::AC1014) {//2000+ + for (unsigned int i=0; i< insertCount; i++){ + dwgHandle insertsH = buf->getHandle(); + DRW_DBG(" insertsH Handle #"); DRW_DBG(i); DRW_DBG(": "); DRW_DBGHL(insertsH.code, insertsH.size, insertsH.ref); DRW_DBG("\n"); + } + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + dwgHandle layoutH = buf->getHandle(); + DRW_DBG(" layoutH Handle: "); DRW_DBGHL(layoutH.code, layoutH.size, layoutH.ref); DRW_DBG("\n"); + } + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n\n"); +// RS crc; //RS */ + return buf->isGood(); +} + +//! Class to handle text style entries +/*! +* Class to handle text style symbol table entries +* @author Rallaz +*/ +void DRW_Textstyle::parseCode(int code, dxfReader *reader){ + switch (code) { + case 3: + font = reader->getUtf8String(); + break; + case 4: + bigFont = reader->getUtf8String(); + break; + case 40: + height = reader->getDouble(); + break; + case 41: + width = reader->getDouble(); + break; + case 50: + oblique = reader->getDouble(); + break; + case 42: + lastHeight = reader->getDouble(); + break; + case 71: + genFlag = reader->getInt32(); + break; + case 1071: + fontFamily = reader->getInt32(); + break; + default: + DRW_TableEntry::parseCode(code, reader); + break; + } +} + +bool DRW_Textstyle::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dwgBuffer sBuff = *buf; + dwgBuffer *sBuf = buf; + if (version > DRW::AC1018) {//2007+ + sBuf = &sBuff; //separate buffer for strings + } + bool ret = DRW_TableEntry::parseDwg(version, buf, sBuf, bs); + DRW_DBG("\n***************************** parsing text style *********************************************\n"); + if (!ret) + return ret; + name = sBuf->getVariableText(version, false); + DRW_DBG("text style name: "); DRW_DBG(name.c_str()); DRW_DBG("\n"); + flags |= buf->getBit()<< 6;//style are referenced for a entity, style code 70, bit 7 (64) + /*dint16 xrefindex =*/ buf->getBitShort(); + flags |= buf->getBit() << 4; //is refx dependent, style code 70, bit 5 (16) + flags |= buf->getBit() << 2; //vertical text, stile code 70, bit 3 (4) + flags |= buf->getBit(); //if is a shape file instead of text, style code 70, bit 1 (1) + height = buf->getBitDouble(); + width = buf->getBitDouble(); + oblique = buf->getBitDouble(); + genFlag = buf->getRawChar8(); + lastHeight = buf->getBitDouble(); + font = sBuf->getVariableText(version, false); + bigFont = sBuf->getVariableText(version, false); + if (version > DRW::AC1018) {//2007+ skip string area + buf->setPosition(objSize >> 3); + buf->setBitPos(objSize & 7); + } + dwgHandle shpControlH = buf->getHandle(); + DRW_DBG(" parentControlH Handle: "); DRW_DBGHL(shpControlH.code, shpControlH.size, shpControlH.ref); DRW_DBG("\n"); + parentHandle = shpControlH.ref; + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + if (xDictFlag !=1){//linetype in 2004 seems not have XDicObjH or NULL handle + dwgHandle XDicObjH = buf->getHandle(); + DRW_DBG(" XDicObj control Handle: "); DRW_DBGHL(XDicObjH.code, XDicObjH.size, XDicObjH.ref); DRW_DBG("\n"); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + } +/*RLZ: fails verify this part*/ dwgHandle XRefH = buf->getHandle(); + DRW_DBG(" XRefH control Handle: "); DRW_DBGHL(XRefH.code, XRefH.size, XRefH.ref); DRW_DBG("\n"); + + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n\n"); + // RS crc; //RS */ + return buf->isGood(); +} + +//! Class to handle vport entries +/*! +* Class to handle vport symbol table entries +* @author Rallaz +*/ +void DRW_Vport::parseCode(int code, dxfReader *reader){ + switch (code) { + case 10: + lowerLeft.x = reader->getDouble(); + break; + case 20: + lowerLeft.y = reader->getDouble(); + break; + case 11: + UpperRight.x = reader->getDouble(); + break; + case 21: + UpperRight.y = reader->getDouble(); + break; + case 12: + center.x = reader->getDouble(); + break; + case 22: + center.y = reader->getDouble(); + break; + case 13: + snapBase.x = reader->getDouble(); + break; + case 23: + snapBase.y = reader->getDouble(); + break; + case 14: + snapSpacing.x = reader->getDouble(); + break; + case 24: + snapSpacing.y = reader->getDouble(); + break; + case 15: + gridSpacing.x = reader->getDouble(); + break; + case 25: + gridSpacing.y = reader->getDouble(); + break; + case 16: + viewDir.x = reader->getDouble(); + break; + case 26: + viewDir.y = reader->getDouble(); + break; + case 36: + viewDir.z = reader->getDouble(); + break; + case 17: + viewTarget.x = reader->getDouble(); + break; + case 27: + viewTarget.y = reader->getDouble(); + break; + case 37: + viewTarget.z = reader->getDouble(); + break; + case 40: + height = reader->getDouble(); + break; + case 41: + ratio = reader->getDouble(); + break; + case 42: + lensHeight = reader->getDouble(); + break; + case 43: + frontClip = reader->getDouble(); + break; + case 44: + backClip = reader->getDouble(); + break; + case 50: + snapAngle = reader->getDouble(); + break; + case 51: + twistAngle = reader->getDouble(); + break; + case 71: + viewMode = reader->getInt32(); + break; + case 72: + circleZoom = reader->getInt32(); + break; + case 73: + fastZoom = reader->getInt32(); + break; + case 74: + ucsIcon = reader->getInt32(); + break; + case 75: + snap = reader->getInt32(); + break; + case 76: + grid = reader->getInt32(); + break; + case 77: + snapStyle = reader->getInt32(); + break; + case 78: + snapIsopair = reader->getInt32(); + break; + default: + DRW_TableEntry::parseCode(code, reader); + break; + } +} + +bool DRW_Vport::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dwgBuffer sBuff = *buf; + dwgBuffer *sBuf = buf; + if (version > DRW::AC1018) {//2007+ + sBuf = &sBuff; //separate buffer for strings + } + bool ret = DRW_TableEntry::parseDwg(version, buf, sBuf, bs); + DRW_DBG("\n***************************** parsing VPort ************************************************\n"); + if (!ret) + return ret; + name = sBuf->getVariableText(version, false); + DRW_DBG("vport name: "); DRW_DBG(name.c_str()); DRW_DBG("\n"); + flags |= buf->getBit()<< 6;// code 70, bit 7 (64) + if (version < DRW::AC1021) { //2004- + /*dint16 xrefindex =*/ buf->getBitShort(); + } + flags |= buf->getBit() << 4; //is refx dependent, style code 70, bit 5 (16) + height = buf->getBitDouble(); + ratio = buf->getBitDouble(); + DRW_DBG("flags: "); DRW_DBG(flags); DRW_DBG(" height: "); DRW_DBG(height); + DRW_DBG(" ratio: "); DRW_DBG(ratio); + center = buf->get2RawDouble(); + DRW_DBG("\nview center: "); DRW_DBGPT(center.x, center.y, center.z); + viewTarget.x = buf->getBitDouble(); + viewTarget.y = buf->getBitDouble(); + viewTarget.z = buf->getBitDouble(); + DRW_DBG("\nview target: "); DRW_DBGPT(viewTarget.x, viewTarget.y, viewTarget.z); + viewDir.x = buf->getBitDouble(); + viewDir.y = buf->getBitDouble(); + viewDir.z = buf->getBitDouble(); + DRW_DBG("\nview dir: "); DRW_DBGPT(viewDir.x, viewDir.y, viewDir.z); + twistAngle = buf->getBitDouble(); + lensHeight = buf->getBitDouble(); + frontClip = buf->getBitDouble(); + backClip = buf->getBitDouble(); + DRW_DBG("\ntwistAngle: "); DRW_DBG(twistAngle); DRW_DBG(" lensHeight: "); DRW_DBG(lensHeight); + DRW_DBG(" frontClip: "); DRW_DBG(frontClip); DRW_DBG(" backClip: "); DRW_DBG(backClip); + viewMode = buf->getBit(); //view mode, code 71, bit 0 (1) + viewMode |= buf->getBit() << 1; //view mode, code 71, bit 1 (2) + viewMode |= buf->getBit() << 2; //view mode, code 71, bit 2 (4) + viewMode |= buf->getBit() << 4; //view mode, code 71, bit 4 (16) + if (version > DRW::AC1014) { //2000+ + //duint8 renderMode = buf->getRawChar8(); + DRW_DBG("\n renderMode: "); DRW_DBG(buf->getRawChar8()); + if (version > DRW::AC1018) { //2007+ + DRW_DBG("\n use default lights: "); DRW_DBG(buf->getBit()); + DRW_DBG(" default lighting type: "); DRW_DBG(buf->getRawChar8()); + DRW_DBG(" brightness: "); DRW_DBG(buf->getBitDouble()); + DRW_DBG("\n contrast: "); DRW_DBG(buf->getBitDouble()); DRW_DBG("\n"); + DRW_DBG(" ambient color CMC: "); DRW_DBG(buf->getCmColor(version)); + } + } + lowerLeft = buf->get2RawDouble(); + DRW_DBG("\nlowerLeft: "); DRW_DBGPT(lowerLeft.x, lowerLeft.y, lowerLeft.z); + UpperRight = buf->get2RawDouble(); + DRW_DBG("\nUpperRight: "); DRW_DBGPT(UpperRight.x, UpperRight.y, UpperRight.z); + viewMode |= buf->getBit() << 3; //UCSFOLLOW, view mode, code 71, bit 3 (8) + circleZoom = buf->getBitShort(); + fastZoom = buf->getBit(); + DRW_DBG("\nviewMode: "); DRW_DBG(viewMode); DRW_DBG(" circleZoom: "); + DRW_DBG(circleZoom); DRW_DBG(" fastZoom: "); DRW_DBG(fastZoom); + ucsIcon = buf->getBit(); //ucs Icon, code 74, bit 0 (1) + ucsIcon |= buf->getBit() << 1; //ucs Icon, code 74, bit 1 (2) + grid = buf->getBit(); + DRW_DBG("\nucsIcon: "); DRW_DBG(ucsIcon); DRW_DBG(" grid: "); DRW_DBG(grid); + gridSpacing = buf->get2RawDouble(); + DRW_DBG("\ngrid Spacing: "); DRW_DBGPT(gridSpacing.x, gridSpacing.y, gridSpacing.z); + snap = buf->getBit(); + snapStyle = buf->getBit(); + DRW_DBG("\nsnap on/off: "); DRW_DBG(snap); DRW_DBG(" snap Style: "); DRW_DBG(snapStyle); + snapIsopair = buf->getBitShort(); + snapAngle = buf->getBitDouble(); + DRW_DBG("\nsnap Isopair: "); DRW_DBG(snapIsopair); DRW_DBG(" snap Angle: "); DRW_DBG(snapAngle); + snapBase = buf->get2RawDouble(); + DRW_DBG("\nsnap Base: "); DRW_DBGPT(snapBase.x, snapBase.y, snapBase.z); + snapSpacing = buf->get2RawDouble(); + DRW_DBG("\nsnap Spacing: "); DRW_DBGPT(snapSpacing.x, snapSpacing.y, snapSpacing.z); + if (version > DRW::AC1014) { //2000+ + DRW_DBG("\n Unknown: "); DRW_DBG(buf->getBit()); + DRW_DBG(" UCS per Viewport: "); DRW_DBG(buf->getBit()); + DRW_DBG("\nUCS origin: "); DRW_DBGPT(buf->getBitDouble(), buf->getBitDouble(), buf->getBitDouble()); + DRW_DBG("\nUCS X Axis: "); DRW_DBGPT(buf->getBitDouble(), buf->getBitDouble(), buf->getBitDouble()); + DRW_DBG("\nUCS Y Axis: "); DRW_DBGPT(buf->getBitDouble(), buf->getBitDouble(), buf->getBitDouble()); + DRW_DBG("\nUCS elevation: "); DRW_DBG(buf->getBitDouble()); + DRW_DBG(" UCS Orthographic type: "); DRW_DBG(buf->getBitShort()); + if (version > DRW::AC1018) { //2007+ + gridBehavior = buf->getBitShort(); + DRW_DBG(" gridBehavior (flags): "); DRW_DBG(gridBehavior); + DRW_DBG(" Grid major: "); DRW_DBG(buf->getBitShort()); + } + } + + //common handles + if (version > DRW::AC1018) {//2007+ skip string area + buf->setPosition(objSize >> 3); + buf->setBitPos(objSize & 7); + } + dwgHandle vpControlH = buf->getHandle(); + DRW_DBG("\n parentControlH Handle: "); DRW_DBGHL(vpControlH.code, vpControlH.size, vpControlH.ref); DRW_DBG("\n"); + parentHandle = vpControlH.ref; + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + if (xDictFlag !=1){ + dwgHandle XDicObjH = buf->getHandle(); + DRW_DBG(" XDicObj control Handle: "); DRW_DBGHL(XDicObjH.code, XDicObjH.size, XDicObjH.ref); DRW_DBG("\n"); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + } +/*RLZ: fails verify this part*/ dwgHandle XRefH = buf->getHandle(); + DRW_DBG(" XRefH control Handle: "); DRW_DBGHL(XRefH.code, XRefH.size, XRefH.ref); + + if (version > DRW::AC1014) { //2000+ + DRW_DBG("\nRemaining bytes: "); DRW_DBG(buf->numRemainingBytes()); + if (version > DRW::AC1018) { //2007+ + dwgHandle bkgrdH = buf->getHandle(); + DRW_DBG(" background Handle: "); DRW_DBGHL(bkgrdH.code, bkgrdH.size, bkgrdH.ref); + DRW_DBG("\nRemaining bytes: "); DRW_DBG(buf->numRemainingBytes()); + dwgHandle visualStH = buf->getHandle(); + DRW_DBG(" visual style Handle: "); DRW_DBGHL(visualStH.code, visualStH.size, visualStH.ref); + DRW_DBG("\nRemaining bytes: "); DRW_DBG(buf->numRemainingBytes()); + dwgHandle sunH = buf->getHandle(); + DRW_DBG(" sun Handle: "); DRW_DBGHL(sunH.code, sunH.size, sunH.ref); + DRW_DBG("\nRemaining bytes: "); DRW_DBG(buf->numRemainingBytes()); + } + dwgHandle namedUCSH = buf->getHandle(); + DRW_DBG(" named UCS Handle: "); DRW_DBGHL(namedUCSH.code, namedUCSH.size, namedUCSH.ref); + DRW_DBG("\nRemaining bytes: "); DRW_DBG(buf->numRemainingBytes()); + dwgHandle baseUCSH = buf->getHandle(); + DRW_DBG(" base UCS Handle: "); DRW_DBGHL(baseUCSH.code, baseUCSH.size, baseUCSH.ref); + } + + DRW_DBG("\n Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + // RS crc; //RS */ + return buf->isGood(); +} + +void DRW_ImageDef::parseCode(int code, dxfReader *reader){ + switch (code) { + case 1: + name = reader->getUtf8String(); + break; + case 5: + handle = reader->getHandleString(); + break; + case 10: + u = reader->getDouble(); + break; + case 20: + v = reader->getDouble(); + break; + case 11: + up = reader->getDouble(); + break; + case 12: + vp = reader->getDouble(); + break; + case 21: + vp = reader->getDouble(); + break; + case 280: + loaded = reader->getInt32(); + break; + case 281: + resolution = reader->getInt32(); + break; + default: + break; + } +} + +bool DRW_ImageDef::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dwgBuffer sBuff = *buf; + dwgBuffer *sBuf = buf; + if (version > DRW::AC1018) {//2007+ + sBuf = &sBuff; //separate buffer for strings + } + bool ret = DRW_TableEntry::parseDwg(version, buf, sBuf, bs); + DRW_DBG("\n***************************** parsing Image Def *********************************************\n"); + if (!ret) + return ret; + dint32 imgVersion = buf->getBitLong(); + DRW_DBG("class Version: "); DRW_DBG(imgVersion); + DRW_Coord size = buf->get2RawDouble(); + (void)size; + name = sBuf->getVariableText(version, false); + DRW_DBG("appId name: "); DRW_DBG(name.c_str()); DRW_DBG("\n"); + loaded = buf->getBit(); + resolution = buf->getRawChar8(); + up = buf->getRawDouble(); + vp = buf->getRawDouble(); + + dwgHandle parentH = buf->getHandle(); + DRW_DBG(" parentH Handle: "); DRW_DBGHL(parentH.code, parentH.size, parentH.ref); DRW_DBG("\n"); + parentHandle = parentH.ref; + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + //RLZ: Reactors handles + if (xDictFlag !=1){ + dwgHandle XDicObjH = buf->getHandle(); + DRW_DBG(" XDicObj control Handle: "); DRW_DBGHL(XDicObjH.code, XDicObjH.size, XDicObjH.ref); DRW_DBG("\n"); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + } +/*RLZ: fails verify this part*/ dwgHandle XRefH = buf->getHandle(); + DRW_DBG(" XRefH control Handle: "); DRW_DBGHL(XRefH.code, XRefH.size, XRefH.ref); DRW_DBG("\n"); + + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n\n"); + // RS crc; //RS */ + return buf->isGood(); +} + +bool DRW_AppId::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ + dwgBuffer sBuff = *buf; + dwgBuffer *sBuf = buf; + if (version > DRW::AC1018) {//2007+ + sBuf = &sBuff; //separate buffer for strings + } + bool ret = DRW_TableEntry::parseDwg(version, buf, sBuf, bs); + DRW_DBG("\n***************************** parsing app Id *********************************************\n"); + if (!ret) + return ret; + name = sBuf->getVariableText(version, false); + DRW_DBG("appId name: "); DRW_DBG(name.c_str()); DRW_DBG("\n"); + flags |= buf->getBit()<< 6;// code 70, bit 7 (64) + /*dint16 xrefindex =*/ buf->getBitShort(); + flags |= buf->getBit() << 4; //is refx dependent, style code 70, bit 5 (16) + duint8 unknown = buf->getRawChar8(); // unknown code 71 + DRW_DBG("unknown code 71: "); DRW_DBG(unknown); DRW_DBG("\n"); + if (version > DRW::AC1018) {//2007+ skip string area + buf->setPosition(objSize >> 3); + buf->setBitPos(objSize & 7); + } + dwgHandle appIdControlH = buf->getHandle(); + DRW_DBG(" parentControlH Handle: "); DRW_DBGHL(appIdControlH.code, appIdControlH.size, appIdControlH.ref); DRW_DBG("\n"); + parentHandle = appIdControlH.ref; + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + if (xDictFlag !=1){//linetype in 2004 seems not have XDicObjH or NULL handle + dwgHandle XDicObjH = buf->getHandle(); + DRW_DBG(" XDicObj control Handle: "); DRW_DBGHL(XDicObjH.code, XDicObjH.size, XDicObjH.ref); DRW_DBG("\n"); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + } +/*RLZ: fails verify this part*/ dwgHandle XRefH = buf->getHandle(); + DRW_DBG(" XRefH control Handle: "); DRW_DBGHL(XRefH.code, XRefH.size, XRefH.ref); DRW_DBG("\n"); + + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n\n"); + // RS crc; //RS */ + return buf->isGood(); +} diff --git a/src/libs/vdxf/libdxfrw/drw_objects.h b/src/libs/vdxf/libdxfrw/drw_objects.h new file mode 100644 index 000000000..07cba081a --- /dev/null +++ b/src/libs/vdxf/libdxfrw/drw_objects.h @@ -0,0 +1,772 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#ifndef DRW_OBJECTS_H +#define DRW_OBJECTS_H + + +#include +#include +#include +#include "drw_base.h" + +class dxfReader; +class dxfWriter; +class dwgBuffer; + +namespace DRW { + +//! Table entries type. + enum TTYPE { + UNKNOWNT, + LTYPE, + LAYER, + STYLE, + DIMSTYLE, + VPORT, + BLOCK_RECORD, + APPID, + IMAGEDEF + }; + +//pending VIEW, UCS, APPID, VP_ENT_HDR, GROUP, MLINESTYLE, LONG_TRANSACTION, XRECORD, +//ACDBPLACEHOLDER, VBA_PROJECT, ACAD_TABLE, CELLSTYLEMAP, DBCOLOR, DICTIONARYVAR, +//DICTIONARYWDFLT, FIELD, IDBUFFER, IMAGEDEF, IMAGEDEFREACTOR, LAYER_INDEX, LAYOUT +//MATERIAL, PLACEHOLDER, PLOTSETTINGS, RASTERVARIABLES, SCALE, SORTENTSTABLE, +//SPATIAL_INDEX, SPATIAL_FILTER, TABLEGEOMETRY, TABLESTYLES,VISUALSTYLE, +} + +#define SETOBJFRIENDS friend class dxfRW; \ + friend class dwgReader; + +//! Base class for tables entries +/*! +* Base class for tables entries +* @author Rallaz +*/ +class DRW_TableEntry { +public: + //initializes default values + DRW_TableEntry() { + tType = DRW::UNKNOWNT; + flags = 0; + numReactors = xDictFlag = 0; + parentHandle = 0; + curr = NULL; + } + + virtual~DRW_TableEntry() { + for (std::vector::iterator it=extData.begin(); it!=extData.end(); ++it) + delete *it; + + extData.clear(); + } + + DRW_TableEntry(const DRW_TableEntry& e) { + tType = e.tType; + handle = e.handle; + parentHandle = e.parentHandle; + name = e.name; + flags = e.flags; + numReactors = e.numReactors; + xDictFlag = e.xDictFlag; + curr = e.curr; + for (std::vector::const_iterator it=e.extData.begin(); it!=e.extData.end(); ++it){ + extData.push_back(new DRW_Variant(*(*it))); + } + } + +protected: + void parseCode(int code, dxfReader *reader); + virtual bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0) = 0; + bool parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer* strBuf, duint32 bs=0); + void reset(){ + flags =0; + for (std::vector::iterator it=extData.begin(); it!=extData.end(); ++it) + delete *it; + extData.clear(); + } + +public: + enum DRW::TTYPE tType; /*!< enum: entity type, code 0 */ + duint32 handle; /*!< entity identifier, code 5 */ + int parentHandle; /*!< Soft-pointer ID/handle to owner object, code 330 */ + UTF8STRING name; /*!< entry name, code 2 */ + int flags; /*!< Flags relevant to entry, code 70 */ + std::vector extData; /*!< FIFO list of extended data, codes 1000 to 1071*/ + +private: + DRW_Variant* curr; + + //***** dwg parse ********/ +protected: + dint16 oType; + duint8 xDictFlag; + dint32 numReactors; // + duint32 objSize; //RL 32bits object data size in bits +}; + + +//! Class to handle dimstyle entries +/*! +* Class to handle dim style symbol table entries +* @author Rallaz +*/ +class DRW_Dimstyle : public DRW_TableEntry { + SETOBJFRIENDS +public: + DRW_Dimstyle() { reset();} + + void reset(){ + tType = DRW::DIMSTYLE; + dimasz = dimtxt = dimcen = 2.5; + dimexe = 1.25; + dimexo = dimgap = 0.625; + dimtxsty = ""; + dimscale = dimlfac = dimtfac = dimfxl = 1.0; + dimdli = 3.75; + dimrnd = dimdle = dimtp = dimtm = dimtsz = dimtvp = 0.0; + dimaltf = 1.0 / 25.4; + dimtol = dimlim = dimse1 = dimse2 = 0; + dimtad = 1; + dimzin = 8; + dimtoh = dimtolj = 0; + dimalt = dimsah = dimtix = dimsoxd = dimfxlon = 0; + dimtofl = 1; + dimunit = dimaltu = dimlunit = 2; + dimaltd = dimalttd = 3; + dimclrd = dimclre = dimclrt = dimjust = dimupt = 0; + dimtzin = 8; + dimazin = dimaltz = dimaltttz = dimfrac = 0; + dimtih = dimadec = dimaunit = dimsd1 = dimsd2 = dimtmove = 0; + dimaltrnd = 0.0; + dimdec = dimtdec = 2; + dimfit = dimatfit = 3; + dimdsep = ','; + dimlwd = dimlwe = -2; + DRW_TableEntry::reset(); + } + +protected: + void parseCode(int code, dxfReader *reader); + bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); + +public: + //V12 + UTF8STRING dimpost; /*!< code 3 */ + UTF8STRING dimapost; /*!< code 4 */ +/* handle are code 105 */ + UTF8STRING dimblk; /*!< code 5, code 342 V2000+ */ + UTF8STRING dimblk1; /*!< code 6, code 343 V2000+ */ + UTF8STRING dimblk2; /*!< code 7, code 344 V2000+ */ + double dimscale; /*!< code 40 */ + double dimasz; /*!< code 41 */ + double dimexo; /*!< code 42 */ + double dimdli; /*!< code 43 */ + double dimexe; /*!< code 44 */ + double dimrnd; /*!< code 45 */ + double dimdle; /*!< code 46 */ + double dimtp; /*!< code 47 */ + double dimtm; /*!< code 48 */ + double dimfxl; /*!< code 49 V2007+ */ + double dimtxt; /*!< code 140 */ + double dimcen; /*!< code 141 */ + double dimtsz; /*!< code 142 */ + double dimaltf; /*!< code 143 */ + double dimlfac; /*!< code 144 */ + double dimtvp; /*!< code 145 */ + double dimtfac; /*!< code 146 */ + double dimgap; /*!< code 147 */ + double dimaltrnd; /*!< code 148 V2000+ */ + int dimtol; /*!< code 71 */ + int dimlim; /*!< code 72 */ + int dimtih; /*!< code 73 */ + int dimtoh; /*!< code 74 */ + int dimse1; /*!< code 75 */ + int dimse2; /*!< code 76 */ + int dimtad; /*!< code 77 */ + int dimzin; /*!< code 78 */ + int dimazin; /*!< code 79 V2000+ */ + int dimalt; /*!< code 170 */ + int dimaltd; /*!< code 171 */ + int dimtofl; /*!< code 172 */ + int dimsah; /*!< code 173 */ + int dimtix; /*!< code 174 */ + int dimsoxd; /*!< code 175 */ + int dimclrd; /*!< code 176 */ + int dimclre; /*!< code 177 */ + int dimclrt; /*!< code 178 */ + int dimadec; /*!< code 179 V2000+ */ + int dimunit; /*!< code 270 R13+ (obsolete 2000+, use dimlunit & dimfrac) */ + int dimdec; /*!< code 271 R13+ */ + int dimtdec; /*!< code 272 R13+ */ + int dimaltu; /*!< code 273 R13+ */ + int dimalttd; /*!< code 274 R13+ */ + int dimaunit; /*!< code 275 R13+ */ + int dimfrac; /*!< code 276 V2000+ */ + int dimlunit; /*!< code 277 V2000+ */ + int dimdsep; /*!< code 278 V2000+ */ + int dimtmove; /*!< code 279 V2000+ */ + int dimjust; /*!< code 280 R13+ */ + int dimsd1; /*!< code 281 R13+ */ + int dimsd2; /*!< code 282 R13+ */ + int dimtolj; /*!< code 283 R13+ */ + int dimtzin; /*!< code 284 R13+ */ + int dimaltz; /*!< code 285 R13+ */ + int dimaltttz; /*!< code 286 R13+ */ + int dimfit; /*!< code 287 R13+ (obsolete 2000+, use dimatfit & dimtmove)*/ + int dimupt; /*!< code 288 R13+ */ + int dimatfit; /*!< code 289 V2000+ */ + int dimfxlon; /*!< code 290 V2007+ */ + UTF8STRING dimtxsty; /*!< code 340 R13+ */ + UTF8STRING dimldrblk; /*!< code 341 V2000+ */ + int dimlwd; /*!< code 371 V2000+ */ + int dimlwe; /*!< code 372 V2000+ */ +}; + + +//! Class to handle line type entries +/*! +* Class to handle line type symbol table entries +* @author Rallaz +*/ +/*TODO: handle complex lineType*/ +class DRW_LType : public DRW_TableEntry { + SETOBJFRIENDS +public: + DRW_LType() { reset();} + + void reset(){ + tType = DRW::LTYPE; + desc = ""; + size = 0; + length = 0.0; + pathIdx = 0; + DRW_TableEntry::reset(); + } + +protected: + void parseCode(int code, dxfReader *reader); + bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); + void update(); + +public: + UTF8STRING desc; /*!< descriptive string, code 3 */ +// int align; /*!< align code, always 65 ('A') code 72 */ + int size; /*!< element number, code 73 */ + double length; /*!< total length of pattern, code 40 */ +// int haveShape; /*!< complex linetype type, code 74 */ + std::vector path; /*!< trace, point or space length sequence, code 49 */ +private: + int pathIdx; +}; + + +//! Class to handle layer entries +/*! +* Class to handle layer symbol table entries +* @author Rallaz +*/ +class DRW_Layer : public DRW_TableEntry { + SETOBJFRIENDS +public: + DRW_Layer() { reset();} + + void reset() { + tType = DRW::LAYER; + lineType = "CONTINUOUS"; + color = 7; // default BYLAYER (256) + plotF = true; // default TRUE (plot yes) + lWeight = DRW_LW_Conv::widthDefault; // default BYDEFAULT (dxf -3, dwg 31) + color24 = -1; //default -1 not set + DRW_TableEntry::reset(); + } + +protected: + void parseCode(int code, dxfReader *reader); + bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); + +public: + UTF8STRING lineType; /*!< line type, code 6 */ + int color; /*!< layer color, code 62 */ + int color24; /*!< 24-bit color, code 420 */ + bool plotF; /*!< Plot flag, code 290 */ + enum DRW_LW_Conv::lineWidth lWeight; /*!< layer lineweight, code 370 */ + std::string handlePlotS; /*!< Hard-pointer ID/handle of plotstyle, code 390 */ + std::string handleMaterialS; /*!< Hard-pointer ID/handle of materialstyle, code 347 */ +/*only used for read dwg*/ + dwgHandle lTypeH; +}; + +//! Class to handle block record entries +/*! +* Class to handle block record table entries +* @author Rallaz +*/ +class DRW_Block_Record : public DRW_TableEntry { + SETOBJFRIENDS +public: + DRW_Block_Record() { reset();} + void reset() { + tType = DRW::BLOCK_RECORD; + flags = 0; + firstEH = lastEH = DRW::NoHandle; + DRW_TableEntry::reset(); + } + +protected: +// void parseCode(int code, dxfReader *reader); + bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); + +public: +//Note: int DRW_TableEntry::flags; contains code 70 of block + int insUnits; /*!< block insertion units, code 70 of block_record*/ + DRW_Coord basePoint; /*!< block insertion base point dwg only */ +protected: + //dwg parser +private: + duint32 block; //handle for block entity + duint32 endBlock;//handle for end block entity + duint32 firstEH; //handle of first entity, only in pre-2004 + duint32 lastEH; //handle of last entity, only in pre-2004 + std::vectorentMap; +}; + +//! Class to handle text style entries +/*! +* Class to handle text style symbol table entries +* @author Rallaz +*/ +class DRW_Textstyle : public DRW_TableEntry { + SETOBJFRIENDS +public: + DRW_Textstyle() { reset();} + + void reset(){ + tType = DRW::STYLE; + height = oblique = 0.0; + width = lastHeight = 1.0; + font="txt"; + genFlag = 0; //2= X mirror, 4= Y mirror + fontFamily = 0; + DRW_TableEntry::reset(); + } + +protected: + void parseCode(int code, dxfReader *reader); + bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); + +public: + double height; /*!< Fixed text height (0 not set), code 40 */ + double width; /*!< Width factor, code 41 */ + double oblique; /*!< Oblique angle, code 50 */ + int genFlag; /*!< Text generation flags, code 71 */ + double lastHeight; /*!< Last height used, code 42 */ + UTF8STRING font; /*!< primary font file name, code 3 */ + UTF8STRING bigFont; /*!< bigfont file name or blank if none, code 4 */ + int fontFamily; /*!< ttf font family, italic and bold flags, code 1071 */ +}; + +//! Class to handle vport entries +/*! +* Class to handle vport symbol table entries +* @author Rallaz +*/ +class DRW_Vport : public DRW_TableEntry { + SETOBJFRIENDS +public: + DRW_Vport() { reset();} + + void reset(){ + tType = DRW::VPORT; + UpperRight.x = UpperRight.y = 1.0; + snapSpacing.x = snapSpacing.y = 10.0; + gridSpacing = snapSpacing; + center.x = 0.651828; + center.y = -0.16; + viewDir.z = 1; + height = 5.13732; + ratio = 2.4426877; + lensHeight = 50; + frontClip = backClip = snapAngle = twistAngle = 0.0; + viewMode = snap = grid = snapStyle = snapIsopair = 0; + fastZoom = 1; + circleZoom = 100; + ucsIcon = 3; + gridBehavior = 7; + DRW_TableEntry::reset(); + } + +protected: + void parseCode(int code, dxfReader *reader); + bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); + +public: + DRW_Coord lowerLeft; /*!< Lower left corner, code 10 & 20 */ + DRW_Coord UpperRight; /*!< Upper right corner, code 11 & 21 */ + DRW_Coord center; /*!< center point in WCS, code 12 & 22 */ + DRW_Coord snapBase; /*!< snap base point in DCS, code 13 & 23 */ + DRW_Coord snapSpacing; /*!< snap Spacing, code 14 & 24 */ + DRW_Coord gridSpacing; /*!< grid Spacing, code 15 & 25 */ + DRW_Coord viewDir; /*!< view direction from target point, code 16, 26 & 36 */ + DRW_Coord viewTarget; /*!< view target point, code 17, 27 & 37 */ + double height; /*!< view height, code 40 */ + double ratio; /*!< viewport aspect ratio, code 41 */ + double lensHeight; /*!< lens height, code 42 */ + double frontClip; /*!< front clipping plane, code 43 */ + double backClip; /*!< back clipping plane, code 44 */ + double snapAngle; /*!< snap rotation angle, code 50 */ + double twistAngle; /*!< view twist angle, code 51 */ + int viewMode; /*!< view mode, code 71 */ + int circleZoom; /*!< circle zoom percent, code 72 */ + int fastZoom; /*!< fast zoom setting, code 73 */ + int ucsIcon; /*!< UCSICON setting, code 74 */ + int snap; /*!< snap on/off, code 75 */ + int grid; /*!< grid on/off, code 76 */ + int snapStyle; /*!< snap style, code 77 */ + int snapIsopair; /*!< snap isopair, code 78 */ + int gridBehavior; /*!< grid behavior, code 60, undocummented */ + /** code 60, bit coded possible value are + * bit 1 (1) show out of limits + * bit 2 (2) adaptive grid + * bit 3 (4) allow subdivision + * bit 4 (8) follow dinamic SCP + **/ +}; + + +//! Class to handle imagedef entries +/*! +* Class to handle image definitions object entries +* @author Rallaz +*/ +class DRW_ImageDef : public DRW_TableEntry {// + SETOBJFRIENDS +public: + DRW_ImageDef() { + reset(); + } + + void reset(){ + tType = DRW::IMAGEDEF; + imgVersion = 0; + DRW_TableEntry::reset(); + } + +protected: + void parseCode(int code, dxfReader *reader); + bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); + +public: +// std::string handle; /*!< entity identifier, code 5 */ + UTF8STRING name; /*!< File name of image, code 1 */ + int imgVersion; /*!< class version, code 90, 0=R14 version */ + double u; /*!< image size in pixels U value, code 10 */ + double v; /*!< image size in pixels V value, code 20 */ + double up; /*!< default size of one pixel U value, code 11 */ + double vp; /*!< default size of one pixel V value, code 12 really is 21*/ + int loaded; /*!< image is loaded flag, code 280, 0=unloaded, 1=loaded */ + int resolution; /*!< resolution units, code 281, 0=no, 2=centimeters, 5=inch */ + + std::map reactors; +}; + +//! Class to handle AppId entries +/*! +* Class to handle AppId symbol table entries +* @author Rallaz +*/ +class DRW_AppId : public DRW_TableEntry { + SETOBJFRIENDS +public: + DRW_AppId() { reset();} + + void reset(){ + tType = DRW::APPID; + flags = 0; + name = ""; + } + +protected: + void parseCode(int code, dxfReader *reader){DRW_TableEntry::parseCode(code, reader);} + bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); +}; + +namespace DRW { + +// Extended color palette: +// The first entry is only for direct indexing starting with [1] +// Color 1 is red (1,0,0) +const unsigned char dxfColors[][3] = { + { 0, 0, 0}, // unused + {255, 0, 0}, // 1 red + {255,255, 0}, // 2 yellow + { 0,255, 0}, // 3 green + { 0,255,255}, // 4 cyan + { 0, 0,255}, // 5 blue + {255, 0,255}, // 6 magenta + { 0, 0, 0}, // 7 black or white + {128,128,128}, // 8 50% gray + {192,192,192}, // 9 75% gray + {255, 0, 0}, // 10 + {255,127,127}, + {204, 0, 0}, + {204,102,102}, + {153, 0, 0}, + {153, 76, 76}, // 15 + {127, 0, 0}, + {127, 63, 63}, + { 76, 0, 0}, + { 76, 38, 38}, + {255, 63, 0}, // 20 + {255,159,127}, + {204, 51, 0}, + {204,127,102}, + {153, 38, 0}, + {153, 95, 76}, // 25 + {127, 31, 0}, + {127, 79, 63}, + { 76, 19, 0}, + { 76, 47, 38}, + {255,127, 0}, // 30 + {255,191,127}, + {204,102, 0}, + {204,153,102}, + {153, 76, 0}, + {153,114, 76}, // 35 + {127, 63, 0}, + {127, 95, 63}, + { 76, 38, 0}, + { 76, 57, 38}, + {255,191, 0}, // 40 + {255,223,127}, + {204,153, 0}, + {204,178,102}, + {153,114, 0}, + {153,133, 76}, // 45 + {127, 95, 0}, + {127,111, 63}, + { 76, 57, 0}, + { 76, 66, 38}, + {255,255, 0}, // 50 + {255,255,127}, + {204,204, 0}, + {204,204,102}, + {153,153, 0}, + {153,153, 76}, // 55 + {127,127, 0}, + {127,127, 63}, + { 76, 76, 0}, + { 76, 76, 38}, + {191,255, 0}, // 60 + {223,255,127}, + {153,204, 0}, + {178,204,102}, + {114,153, 0}, + {133,153, 76}, // 65 + { 95,127, 0}, + {111,127, 63}, + { 57, 76, 0}, + { 66, 76, 38}, + {127,255, 0}, // 70 + {191,255,127}, + {102,204, 0}, + {153,204,102}, + { 76,153, 0}, + {114,153, 76}, // 75 + { 63,127, 0}, + { 95,127, 63}, + { 38, 76, 0}, + { 57, 76, 38}, + { 63,255, 0}, // 80 + {159,255,127}, + { 51,204, 0}, + {127,204,102}, + { 38,153, 0}, + { 95,153, 76}, // 85 + { 31,127, 0}, + { 79,127, 63}, + { 19, 76, 0}, + { 47, 76, 38}, + { 0,255, 0}, // 90 + {127,255,127}, + { 0,204, 0}, + {102,204,102}, + { 0,153, 0}, + { 76,153, 76}, // 95 + { 0,127, 0}, + { 63,127, 63}, + { 0, 76, 0}, + { 38, 76, 38}, + { 0,255, 63}, // 100 + {127,255,159}, + { 0,204, 51}, + {102,204,127}, + { 0,153, 38}, + { 76,153, 95}, // 105 + { 0,127, 31}, + { 63,127, 79}, + { 0, 76, 19}, + { 38, 76, 47}, + { 0,255,127}, // 110 + {127,255,191}, + { 0,204,102}, + {102,204,153}, + { 0,153, 76}, + { 76,153,114}, // 115 + { 0,127, 63}, + { 63,127, 95}, + { 0, 76, 38}, + { 38, 76, 57}, + { 0,255,191}, // 120 + {127,255,223}, + { 0,204,153}, + {102,204,178}, + { 0,153,114}, + { 76,153,133}, // 125 + { 0,127, 95}, + { 63,127,111}, + { 0, 76, 57}, + { 38, 76, 66}, + { 0,255,255}, // 130 + {127,255,255}, + { 0,204,204}, + {102,204,204}, + { 0,153,153}, + { 76,153,153}, // 135 + { 0,127,127}, + { 63,127,127}, + { 0, 76, 76}, + { 38, 76, 76}, + { 0,191,255}, // 140 + {127,223,255}, + { 0,153,204}, + {102,178,204}, + { 0,114,153}, + { 76,133,153}, // 145 + { 0, 95,127}, + { 63,111,127}, + { 0, 57, 76}, + { 38, 66, 76}, + { 0,127,255}, // 150 + {127,191,255}, + { 0,102,204}, + {102,153,204}, + { 0, 76,153}, + { 76,114,153}, // 155 + { 0, 63,127}, + { 63, 95,127}, + { 0, 38, 76}, + { 38, 57, 76}, + { 0, 66,255}, // 160 + {127,159,255}, + { 0, 51,204}, + {102,127,204}, + { 0, 38,153}, + { 76, 95,153}, // 165 + { 0, 31,127}, + { 63, 79,127}, + { 0, 19, 76}, + { 38, 47, 76}, + { 0, 0,255}, // 170 + {127,127,255}, + { 0, 0,204}, + {102,102,204}, + { 0, 0,153}, + { 76, 76,153}, // 175 + { 0, 0,127}, + { 63, 63,127}, + { 0, 0, 76}, + { 38, 38, 76}, + { 63, 0,255}, // 180 + {159,127,255}, + { 50, 0,204}, + {127,102,204}, + { 38, 0,153}, + { 95, 76,153}, // 185 + { 31, 0,127}, + { 79, 63,127}, + { 19, 0, 76}, + { 47, 38, 76}, + {127, 0,255}, // 190 + {191,127,255}, + {102, 0,204}, + {153,102,204}, + { 76, 0,153}, + {114, 76,153}, // 195 + { 63, 0,127}, + { 95, 63,127}, + { 38, 0, 76}, + { 57, 38, 76}, + {191, 0,255}, // 200 + {223,127,255}, + {153, 0,204}, + {178,102,204}, + {114, 0,153}, + {133, 76,153}, // 205 + { 95, 0,127}, + {111, 63,127}, + { 57, 0, 76}, + { 66, 38, 76}, + {255, 0,255}, // 210 + {255,127,255}, + {204, 0,204}, + {204,102,204}, + {153, 0,153}, + {153, 76,153}, // 215 + {127, 0,127}, + {127, 63,127}, + { 76, 0, 76}, + { 76, 38, 76}, + {255, 0,191}, // 220 + {255,127,223}, + {204, 0,153}, + {204,102,178}, + {153, 0,114}, + {153, 76,133}, // 225 + {127, 0, 95}, + {127, 63, 11}, + { 76, 0, 57}, + { 76, 38, 66}, + {255, 0,127}, // 230 + {255,127,191}, + {204, 0,102}, + {204,102,153}, + {153, 0, 76}, + {153, 76,114}, // 235 + {127, 0, 63}, + {127, 63, 95}, + { 76, 0, 38}, + { 76, 38, 57}, + {255, 0, 63}, // 240 + {255,127,159}, + {204, 0, 51}, + {204,102,127}, + {153, 0, 38}, + {153, 76, 95}, // 245 + {127, 0, 31}, + {127, 63, 79}, + { 76, 0, 19}, + { 76, 38, 47}, + { 51, 51, 51}, // 250 + { 91, 91, 91}, + {132,132,132}, + {173,173,173}, + {214,214,214}, + {255,255,255} // 255 +}; + +} + +#endif + +// EOF diff --git a/src/libs/vdxf/libdxfrw/intern/drw_dbg.cpp b/src/libs/vdxf/libdxfrw/intern/drw_dbg.cpp new file mode 100644 index 000000000..d999edf38 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/drw_dbg.cpp @@ -0,0 +1,164 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#include +#include +#include "drw_dbg.h" + +DRW_dbg *DRW_dbg::instance= NULL; + +/*********private clases*************/ +class print_none { +public: + virtual void printS(std::string s){(void)s;} + virtual void printI(long long int i){(void)i;} + virtual void printUI(long long unsigned int i){(void)i;} + virtual void printD(double d){(void)d;} + virtual void printH(long long int i){(void)i;} + virtual void printB(int i){(void)i;} + virtual void printHL(int c, int s, int h){(void)c;(void)s;(void)h;} + virtual void printPT(double x, double y, double z){(void)x;(void)y;(void)z;} + print_none(){} + virtual ~print_none(){} +}; + +class print_debug : public print_none { +public: + virtual void printS(std::string s); + virtual void printI(long long int i); + virtual void printUI(long long unsigned int i); + virtual void printD(double d); + virtual void printH(long long int i); + virtual void printB(int i); + virtual void printHL(int c, int s, int h); + virtual void printPT(double x, double y, double z); + print_debug(); + virtual ~print_debug(){} +private: + std::ios_base::fmtflags flags; +}; + +/********* debug class *************/ +DRW_dbg *DRW_dbg::getInstance(){ + if (instance == NULL){ + instance = new DRW_dbg; + } + return instance; +} + +DRW_dbg::DRW_dbg(){ + level = NONE; + prClass = new print_none; + flags = std::cerr.flags(); +} + +void DRW_dbg::setLevel(LEVEL lvl){ + level = lvl; + delete prClass; + switch (level){ + case DEBUG: + prClass = new print_debug; + break; + default: + prClass = new print_none; + } +} + +DRW_dbg::LEVEL DRW_dbg::getLevel(){ + return level; +} + +void DRW_dbg::print(std::string s){ + prClass->printS(s); +} + +void DRW_dbg::print(int i){ + prClass->printI(i); +} + +void DRW_dbg::print(unsigned int i){ + prClass->printUI(i); +} + +void DRW_dbg::print(long long int i){ + prClass->printI(i); +} + +void DRW_dbg::print(long unsigned int i){ + prClass->printUI(i); +} + +void DRW_dbg::print(long long unsigned int i){ + prClass->printUI(i); +} + +void DRW_dbg::print(double d){ + prClass->printD(d); +} + +void DRW_dbg::printH(long long int i){ + prClass->printH(i); +} + +void DRW_dbg::printB(int i){ + prClass->printB(i); +} +void DRW_dbg::printHL(int c, int s, int h){ + prClass->printHL(c, s, h); +} + +void DRW_dbg::printPT(double x, double y, double z){ + prClass->printPT(x, y, z); +} + +print_debug::print_debug(){ + flags = std::cerr.flags(); +} + +void print_debug::printS(std::string s){ + std::cerr << s; +} + +void print_debug::printI(long long int i){ + std::cerr << i; +} + +void print_debug::printUI(long long unsigned int i){ + std::cerr << i; +} + +void print_debug::printD(double d){ + std::cerr << std::fixed << d; +} + +void print_debug::printH(long long i){ + std::cerr << "0x" << std::setw(2) << std::setfill('0'); + std::cerr << std::hex << i; + std::cerr.flags(flags); +} + +void print_debug::printB(int i){ + std::cerr << std::setw(8) << std::setfill('0'); + std::cerr << std::setbase(2) << i; + std::cerr.flags(flags); +} + +void print_debug::printHL(int c, int s, int h){ + std::cerr << c << '.' << s << '.'; + std::cerr << "0x" << std::setw(2) << std::setfill('0'); + std::cerr << std::hex << h; + std::cerr.flags(flags); +} + +void print_debug::printPT(double x, double y, double z){ + std::cerr << std::fixed << "x: " << x << ", y: " << y << ", z: "<< z; +} diff --git a/src/libs/vdxf/libdxfrw/intern/drw_dbg.h b/src/libs/vdxf/libdxfrw/intern/drw_dbg.h new file mode 100644 index 000000000..a494c9cdb --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/drw_dbg.h @@ -0,0 +1,61 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#ifndef DRW_DBG_H +#define DRW_DBG_H + +#include +#include +//#include + +#define DRW_DBGSL(a) DRW_dbg::getInstance()->setLevel(a) +#define DRW_DBGGL DRW_dbg::getInstance()->getLevel() +#define DRW_DBG(a) DRW_dbg::getInstance()->print(a) +#define DRW_DBGH(a) DRW_dbg::getInstance()->printH(a) +#define DRW_DBGB(a) DRW_dbg::getInstance()->printB(a) +#define DRW_DBGHL(a, b, c) DRW_dbg::getInstance()->printHL(a, b ,c) +#define DRW_DBGPT(a, b, c) DRW_dbg::getInstance()->printPT(a, b, c) + + +class print_none; + +class DRW_dbg { +public: + enum LEVEL { + NONE, + DEBUG + }; + void setLevel(LEVEL lvl); + LEVEL getLevel(); + static DRW_dbg *getInstance(); + void print(std::string s); + void print(int i); + void print(unsigned int i); + void print(long long int i); + void print(long unsigned int i); + void print(long long unsigned int i); + void print(double d); + void printH(long long int i); + void printB(int i); + void printHL(int c, int s, int h); + void printPT(double x, double y, double z); + +private: + DRW_dbg(); + static DRW_dbg *instance; + LEVEL level; + std::ios_base::fmtflags flags; + print_none* prClass; +}; + + +#endif // DRW_DBG_H diff --git a/src/libs/vdxf/libdxfrw/intern/drw_textcodec.cpp b/src/libs/vdxf/libdxfrw/intern/drw_textcodec.cpp new file mode 100644 index 000000000..0c04122d4 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/drw_textcodec.cpp @@ -0,0 +1,165 @@ +#include "drw_textcodec.h" +#include +#include +#include +#include +#include +#include "../drw_base.h" + +DRW_TextCodec::DRW_TextCodec() { + version = DRW::AC1021; + conv = nullptr; +} + +void DRW_TextCodec::setVersion(int v, bool dxfFormat){ + if (v == DRW::AC1009 || v == DRW::AC1006) { + version = DRW::AC1009; + cp = "ANSI_1252"; + setCodePage(&cp, dxfFormat); + } else if (v == DRW::AC1012 || v == DRW::AC1014 + || v == DRW::AC1015 || v == DRW::AC1018) { + version = DRW::AC1015; +// if (cp.empty()) { //codepage not set, initialize + cp = "ANSI_1252"; + setCodePage(&cp, dxfFormat); +// } + } else { + version = DRW::AC1021; + if (dxfFormat) + cp = "UTF-8";//RLZ: can be UCS2 or UTF-16 16bits per char + else + cp = "UTF-16";//RLZ: can be UCS2 or UTF-16 16bits per char + setCodePage(&cp, dxfFormat); + } +} + +void DRW_TextCodec::setVersion(std::string *v, bool dxfFormat){ + std::string versionStr = *v; + if (versionStr == "AC1009" || versionStr == "AC1006") { + setVersion(DRW::AC1009, dxfFormat); + } else if (versionStr == "AC1012" || versionStr == "AC1014" + || versionStr == "AC1015" || versionStr == "AC1018") { + setVersion(DRW::AC1015, dxfFormat); + } + else + { + setVersion(DRW::AC1021, dxfFormat); + } +} + +void DRW_TextCodec::setCodePage(std::string *c, bool dxfFormat){ + cp = correctCodePage(*c); + if (version < DRW::AC1021) + { + if (cp == "UTF-8") + { //DXF older than 2007 are write in win codepages + cp = "ANSI_1252"; + } + conv = QTextCodec::codecForName(cp.c_str()); + } + else + { + if (dxfFormat) + { + conv = QTextCodec::codecForName("UTF-8"); + } + else + { + conv = QTextCodec::codecForName("UTF-16"); + } + } +} + +std::string DRW_TextCodec::toUtf8(std::string s) { + if (conv == nullptr) + { + return s; + } + + const QString encodedString = conv->toUnicode(s.c_str()); + return encodedString.toStdString(); +} + +std::string DRW_TextCodec::fromUtf8(std::string s) { + if (conv == nullptr) + { + return s; + } + + const QByteArray encodedString = conv->fromUnicode(QString::fromStdString(s)); + return std::string(encodedString.constData()); +} + +std::string DRW_TextCodec::correctCodePage(const std::string& s) { + //stringstream cause crash in OS/X, bug#3597944 + std::string cp=s; + transform(cp.begin(), cp.end(), cp.begin(), toupper); + //Latin/Thai + if (cp=="ANSI_874" || cp=="CP874" || cp=="ISO8859-11" || cp=="TIS-620") { + return "ANSI_874"; + //Central Europe and Eastern Europe + } else if (cp=="ANSI_1250" || cp=="CP1250" || cp=="ISO8859-2") { + return "ANSI_1250"; + //Cyrillic script + } else if (cp=="ANSI_1251" || cp=="CP1251" || cp=="ISO8859-5" || cp=="KOI8-R" || + cp=="KOI8-U" || cp=="IBM 866") { + return "ANSI_1251"; + //Western Europe + } else if (cp=="ANSI_1252" || cp=="CP1252" || cp=="LATIN1" || cp=="ISO-8859-1" || + cp=="CP819" || cp=="CSISO" || cp=="IBM819" || cp=="ISO_8859-1" || cp=="APPLE ROMAN" || + cp=="ISO8859-1" || cp=="ISO8859-15" || cp=="ISO-IR-100" || cp=="L1" || cp=="IBM 850") { + return "ANSI_1252"; + //Greek + } else if (cp=="ANSI_1253" || cp=="CP1253" || cp=="iso8859-7") { + return "ANSI_1253"; + //Turkish + } else if (cp=="ANSI_1254" || cp=="CP1254" || cp=="iso8859-9" || cp=="iso8859-3") { + return "ANSI_1254"; + //Hebrew + } else if (cp=="ANSI_1255" || cp=="CP1255" || cp=="iso8859-8") { + return "ANSI_1255"; + //Arabic + } else if (cp=="ANSI_1256" || cp=="CP1256" || cp=="ISO8859-6") { + return "ANSI_1256"; + //Baltic + } else if (cp=="ANSI_1257" || cp=="CP1257" || cp=="ISO8859-4" || cp=="ISO8859-10" || cp=="ISO8859-13") { + return "ANSI_1257"; + //Vietnamese + } else if (cp=="ANSI_1258" || cp=="CP1258") { + return "ANSI_1258"; + + //Japanese + } else if (cp=="ANSI_932" || cp=="SHIFT-JIS" || cp=="SHIFT_JIS" || cp=="CSSHIFTJIS" || + cp=="CSWINDOWS31J" || cp=="MS_KANJI" || cp=="X-MS-CP932" || cp=="X-SJIS" || + cp=="EUCJP" || cp=="EUC-JP" || cp=="CSEUCPKDFMTJAPANESE" || cp=="X-EUC" || + cp=="X-EUC-JP" || cp=="JIS7") { + return "ANSI_932"; + //Chinese PRC GBK (XGB) simplified + } else if (cp=="ANSI_936" || cp=="GBK" || cp=="GB2312" || cp=="CHINESE" || cp=="CN-GB" || + cp=="CSGB2312" || cp=="CSGB231280" || cp=="CSISO58BG231280" || + cp=="GB_2312-80" || cp=="GB231280" || cp=="GB2312-80" || + cp=="ISO-IR-58" || cp=="GB18030") { + return "ANSI_936"; + //Korean + } else if (cp=="ANSI_949" || cp=="EUCKR") { + return "ANSI_949"; + //Chinese Big5 (Taiwan, Hong Kong SAR) + } else if (cp=="ANSI_950" || cp=="BIG5" || cp=="CN-BIG5" || cp=="CSBIG5" || + cp=="X-X-BIG5" || cp=="BIG5-HKSCS") { + return "ANSI_950"; + +//celtic +/* } else if (cp=="ISO8859-14") { + return "ISO8859-14"; + } else if (cp=="TSCII") { + return "TSCII"; //tamil + }*/ + + } else if (cp=="UTF-8" || cp=="UTF8" || cp=="UTF8-BIT") { + return "UTF-8"; + } else if (cp=="UTF-16" || cp=="UTF16" || cp=="UTF16-BIT") { + return "UTF-16"; + } + + return "ANSI_1252"; +} diff --git a/src/libs/vdxf/libdxfrw/intern/drw_textcodec.h b/src/libs/vdxf/libdxfrw/intern/drw_textcodec.h new file mode 100644 index 000000000..d081f4120 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/drw_textcodec.h @@ -0,0 +1,30 @@ +#ifndef DRW_TEXTCODEC_H +#define DRW_TEXTCODEC_H + +#include + +class QTextCodec; + +class DRW_TextCodec +{ +public: + DRW_TextCodec(); + std::string fromUtf8(std::string s); + std::string toUtf8(std::string s); + int getVersion(){return version;} + void setVersion(std::string *v, bool dxfFormat); + void setVersion(int v, bool dxfFormat); + void setCodePage(std::string *c, bool dxfFormat); + void setCodePage(std::string c, bool dxfFormat){setCodePage(&c, dxfFormat);} + std::string getCodePage(){return cp;} + +private: + std::string correctCodePage(const std::string& s); + +private: + int version; + std::string cp; + QTextCodec *conv; +}; + +#endif // DRW_TEXTCODEC_H diff --git a/src/libs/vdxf/libdxfrw/intern/dwgbuffer.cpp b/src/libs/vdxf/libdxfrw/intern/dwgbuffer.cpp new file mode 100644 index 000000000..8bf914f21 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/dwgbuffer.cpp @@ -0,0 +1,923 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + + +#include "dwgbuffer.h" +#include "../libdwgr.h" +#include "drw_textcodec.h" +#include "drw_dbg.h" +//#include +/*#include +#include +#include +#include "dwgreader.h"*/ +//#include "dxfwriter.h" + + +//#define FIRSTHANDLE 48 + +/*enum sections { + secUnknown, + secHeader, + secTables, + secBlocks, + secEntities, + secObjects +};*/ + +static unsigned int crctable[256]= { +0x0000,0xC0C1,0xC181,0x0140,0xC301,0x03C0,0x0280,0xC241, +0xC601,0x06C0,0x0780,0xC741,0x0500,0xC5C1,0xC481,0x0440, +0xCC01,0x0CC0,0x0D80,0xCD41,0x0F00,0xCFC1,0xCE81,0x0E40, +0x0A00,0xCAC1,0xCB81,0x0B40,0xC901,0x09C0,0x0880,0xC841, +0xD801,0x18C0,0x1980,0xD941,0x1B00,0xDBC1,0xDA81,0x1A40, +0x1E00,0xDEC1,0xDF81,0x1F40,0xDD01,0x1DC0,0x1C80,0xDC41, +0x1400,0xD4C1,0xD581,0x1540,0xD701,0x17C0,0x1680,0xD641, +0xD201,0x12C0,0x1380,0xD341,0x1100,0xD1C1,0xD081,0x1040, +0xF001,0x30C0,0x3180,0xF141,0x3300,0xF3C1,0xF281,0x3240, +0x3600,0xF6C1,0xF781,0x3740,0xF501,0x35C0,0x3480,0xF441, +0x3C00,0xFCC1,0xFD81,0x3D40,0xFF01,0x3FC0,0x3E80,0xFE41, +0xFA01,0x3AC0,0x3B80,0xFB41,0x3900,0xF9C1,0xF881,0x3840, +0x2800,0xE8C1,0xE981,0x2940,0xEB01,0x2BC0,0x2A80,0xEA41, +0xEE01,0x2EC0,0x2F80,0xEF41,0x2D00,0xEDC1,0xEC81,0x2C40, +0xE401,0x24C0,0x2580,0xE541,0x2700,0xE7C1,0xE681,0x2640, +0x2200,0xE2C1,0xE381,0x2340,0xE101,0x21C0,0x2080,0xE041, +0xA001,0x60C0,0x6180,0xA141,0x6300,0xA3C1,0xA281,0x6240, +0x6600,0xA6C1,0xA781,0x6740,0xA501,0x65C0,0x6480,0xA441, +0x6C00,0xACC1,0xAD81,0x6D40,0xAF01,0x6FC0,0x6E80,0xAE41, +0xAA01,0x6AC0,0x6B80,0xAB41,0x6900,0xA9C1,0xA881,0x6840, +0x7800,0xB8C1,0xB981,0x7940,0xBB01,0x7BC0,0x7A80,0xBA41, +0xBE01,0x7EC0,0x7F80,0xBF41,0x7D00,0xBDC1,0xBC81,0x7C40, +0xB401,0x74C0,0x7580,0xB541,0x7700,0xB7C1,0xB681,0x7640, +0x7200,0xB2C1,0xB381,0x7340,0xB101,0x71C0,0x7080,0xB041, +0x5000,0x90C1,0x9181,0x5140,0x9301,0x53C0,0x5280,0x9241, +0x9601,0x56C0,0x5780,0x9741,0x5500,0x95C1,0x9481,0x5440, +0x9C01,0x5CC0,0x5D80,0x9D41,0x5F00,0x9FC1,0x9E81,0x5E40, +0x5A00,0x9AC1,0x9B81,0x5B40,0x9901,0x59C0,0x5880,0x9841, +0x8801,0x48C0,0x4980,0x8941,0x4B00,0x8BC1,0x8A81,0x4A40, +0x4E00,0x8EC1,0x8F81,0x4F40,0x8D01,0x4DC0,0x4C80,0x8C41, +0x4400,0x84C1,0x8581,0x4540,0x8701,0x47C0,0x4680,0x8641, +0x8201,0x42C0,0x4380,0x8341,0x4100,0x81C1,0x8081,0x4040 }; + +static unsigned int crc32Table[256] ={ +0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, +0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, +0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, +0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, +0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, +0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, +0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, +0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, +0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, +0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, +0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, +0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, +0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, +0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, +0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, +0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, +0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, +0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, +0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, +0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, +0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, +0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, +0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, +0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, +0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, +0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, +0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, +0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, +0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, +0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, +0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, +0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d}; + +union typeCast { + char buf[8]; + duint16 i16; + duint32 i32; + duint64 i64; + ddouble64 d64; +}; + +bool dwgFileStream::setPos(duint64 p){ + if (p >= sz) + return false; + + stream->seekg(p); + return stream->good(); +} + +bool dwgFileStream::read(duint8* s, duint64 n){ + stream->read (reinterpret_cast(s),n); + return stream->good(); +} + +bool dwgCharStream::setPos(duint64 p){ + if (p > size()) { + isOk = false; + return false; + } + + pos = p; + return true; +} + +bool dwgCharStream::read(duint8* s, duint64 n){ + if ( n > (sz - pos) ) { + isOk = false; + return false; + } + for (duint64 i=0; isize(); + bitPos = 0; +} + +dwgBuffer::dwgBuffer( const dwgBuffer& org ){ + filestr = org.filestr->clone(); + decoder = org.decoder; + maxSize = filestr->size(); + currByte = org.currByte; + bitPos = org.bitPos; +} + +dwgBuffer& dwgBuffer::operator=( const dwgBuffer& org ){ + filestr = org.filestr->clone(); + decoder = org.decoder; + maxSize = filestr->size(); + currByte = org.currByte; + bitPos = org.bitPos; + return *this; +} + +dwgBuffer::~dwgBuffer(){ + delete filestr; +} + +/**Gets the current byte position in buffer **/ +duint64 dwgBuffer::getPosition(){ + if (bitPos != 0) + return filestr->getPos() -1; + return filestr->getPos(); + } + +/**Sets the buffer position in pos byte, reset the bit position **/ +bool dwgBuffer::setPosition(duint64 pos){ + bitPos = 0; +/* if (pos>=maxSize) + return false;*/ + return filestr->setPos(pos); +// return true; +} + +//RLZ: Fails if ... ??? +void dwgBuffer::setBitPos(duint8 pos){ + if (pos>7) + return; + if (pos != 0 && bitPos == 0){ + duint8 buffer; + filestr->read (&buffer,1); + currByte = buffer; + } + if (pos == 0 && bitPos != 0){//reset current byte + filestr->setPos(filestr->getPos()-1); + } + bitPos = pos; +} + +bool dwgBuffer::moveBitPos(dint32 size){ + if (size == 0) return true; + + dint32 b= size + bitPos; + filestr->setPos(getPosition() + (b >> 3) ); + bitPos = b & 7; + + if (bitPos != 0){ + filestr->read (&currByte,1); + } + return filestr->good(); +} + +/**Reads one Bit returns a char with value 0/1 (B) **/ +duint8 dwgBuffer::getBit(){ + duint8 buffer; + duint8 ret = 0; + if (bitPos == 0){ + filestr->read (&buffer,1); + currByte = buffer; + } + + ret = (currByte >> (7 - bitPos) & 1); + bitPos +=1; + if (bitPos == 8) + bitPos = 0; + + return ret; +} + +/**Reads one Bit returns a bool value 0==false 1==true (B) **/ +bool dwgBuffer::getBoolBit(){ + return (getBit() != 0); +} + +/**Reads two Bits returns a char (BB) **/ +duint8 dwgBuffer::get2Bits(){ + duint8 buffer; + duint8 ret = 0; + if (bitPos == 0){ + filestr->read (&buffer,1); + currByte = buffer; + } + + bitPos +=2; + if (bitPos < 9) + ret = currByte >>(8 - bitPos); + else {//read one bit per byte + ret = currByte << 1; + filestr->read (&buffer,1); + currByte = buffer; + bitPos = 1; + ret = ret | currByte >> 7; + } + if (bitPos == 8) + bitPos = 0; + ret = ret & 3; + return ret; +} + +/**Reads thee Bits returns a char (3B) **/ +//RLZ: todo verify this +duint8 dwgBuffer::get3Bits(){ + duint8 buffer; + duint8 ret = 0; + if (bitPos == 0){ + filestr->read (&buffer,1); + currByte = buffer; + } + + bitPos +=3; + if (bitPos < 9) + ret = currByte >>(8 - bitPos); + else {//read one bit per byte + ret = currByte << 1; + filestr->read (&buffer,1); + currByte = buffer; + bitPos = 1; + ret = ret | currByte >> 7; + } + if (bitPos == 8) + bitPos = 0; + ret = ret & 7; + return ret; +} + +/**Reads tree Bits returns a char (3B) for R24 **/ +//to be written + +/**Reads compresed Short (max. 16 + 2 bits) little-endian order, returns a UNsigned 16 bits (BS) **/ +duint16 dwgBuffer::getBitShort(){ + duint8 b = get2Bits(); + if (b == 0) + return getRawShort16(); + else if (b== 1) + return getRawChar8(); + else if (b == 2) + return 0; + else + return 256; +} +/**Reads compresed Short (max. 16 + 2 bits) little-endian order, returns a signed 16 bits (BS) **/ +dint16 dwgBuffer::getSBitShort(){ + duint8 b = get2Bits(); + if (b == 0) + return (dint16)getRawShort16(); + else if (b== 1) + return (dint16)getRawChar8(); + else if (b == 2) + return 0; + else + return 256; +} + +/**Reads compresed 32 bits Int (max. 32 + 2 bits) little-endian order, returns a signed 32 bits (BL) **/ +//to be written +dint32 dwgBuffer::getBitLong(){ + dint8 b = get2Bits(); + if (b == 0) + return getRawLong32(); + else if (b== 1) + return getRawChar8(); + else //if (b == 2) + return 0; +} + +/**Reads compresed 64 bits Int (max. 56 + 3 bits) little-endian order, returns a unsigned 64 bits (BLL) **/ +duint64 dwgBuffer::getBitLongLong(){ + dint8 b = get3Bits(); + duint64 ret=0; + for (duint8 i=0; iread (buffer,8); + } + double* ret = reinterpret_cast( buffer ); + return *ret; + } + // if (b == 2) + return 0.0; +} + +/**Reads 3 compresed Double (max. 64 + 2 bits) returns a DRW_Coord of floating point double of 64 bits (3BD) **/ +DRW_Coord dwgBuffer::get3BitDouble(){ + DRW_Coord crd; + crd.x = getBitDouble(); + crd.y = getBitDouble(); + crd.z = getBitDouble(); + return crd; +} + +/**Reads raw char 8 bits returns a unsigned char (RC) **/ +duint8 dwgBuffer::getRawChar8(){ + duint8 ret; + duint8 buffer; + filestr->read (&buffer,1); + if (bitPos == 0) + return buffer; + else { + ret = currByte << bitPos; + currByte = buffer; + ret = ret | (currByte >>(8 - bitPos)); + } + return ret; +} + +/**Reads raw short 16 bits little-endian order, returns a unsigned short (RS) **/ +duint16 dwgBuffer::getRawShort16(){ + duint8 buffer[2]; + duint16 ret; + + filestr->read (buffer,2); + if (bitPos == 0) { + /* no offset directly swap bytes for little-endian */ + ret = (buffer[1] << 8) | (buffer[0] & 0x00FF); + } else { + ret = (buffer[0] << 8) | (buffer[1] & 0x00FF); + /* apply offset */ + ret = ret >> (8 - bitPos); + ret = ret | (currByte << (8 + bitPos)); + currByte = buffer[1]; + /* swap bytes for little-endian */ + ret = (ret << 8) | (ret >> 8); + } + return ret; +} + +/**Reads raw double IEEE standard 64 bits returns a double (RD) **/ +double dwgBuffer::getRawDouble(){ + duint8 buffer[8]; + if (bitPos == 0) + filestr->read (buffer,8); + else { + for (int i = 0; i < 8; i++) + buffer[i] = getRawChar8(); + } + double* nOffset = reinterpret_cast( buffer ); + return *nOffset; +} + +/**Reads 2 raw double IEEE standard 64 bits returns a DRW_Coord of floating point double 64 bits (2RD) **/ +DRW_Coord dwgBuffer::get2RawDouble(){ + DRW_Coord crd; + crd.x = getRawDouble(); + crd.y = getRawDouble(); + return crd; +} + + +/**Reads raw int 32 bits little-endian order, returns a unsigned int (RL) **/ +duint32 dwgBuffer::getRawLong32(){ + duint16 tmp1 = getRawShort16(); + duint16 tmp2 = getRawShort16(); + duint32 ret = (tmp2 << 16) | (tmp1 & 0x0000FFFF); + + return ret; +} + +/**Reads raw int 64 bits little-endian order, returns a unsigned long long (RLL) **/ +duint64 dwgBuffer::getRawLong64(){ + duint32 tmp1 = getRawLong32(); + duint64 tmp2 = getRawLong32(); + duint64 ret = (tmp2 << 32) | (tmp1 & 0x00000000FFFFFFFF); + + return ret; +} + +/**Reads modular unsigner int, char based, compresed form, little-endian order, returns a unsigned int (U-MC) **/ +duint32 dwgBuffer::getUModularChar(){ + std::vector buffer; + duint32 result =0; + for (int i=0; i<4;i++){ + duint8 b= getRawChar8(); + buffer.push_back(b & 0x7F); + if (! (b & 0x80)) + break; + } + int offset = 0; + for (unsigned int i=0; i buffer; + dint32 result =0; + for (int i=0; i<4;i++){ + duint8 b= getRawChar8(); + buffer.push_back(b & 0x7F); + if (! (b & 0x80)) + break; + } + dint8 b= buffer.back(); + if (b & 0x40) { + negative = true; + buffer.pop_back(); + buffer.push_back(b & 0x3F); + } + + int offset = 0; + for (unsigned int i=0; i buffer; + dint32 result =0; + for (int i=0; i<2;i++){ + duint16 b= getRawShort16(); + buffer.push_back(b & 0x7FFF); + if (! (b & 0x8000)) + break; + } + + //only positive ? +/* dint8 b= buffer.back(); + if (! (b & 0x40)) { + negative = true; + buffer.pop_back(); + buffer.push_back(b & 0x3F); + }*/ + + int offset = 0; + for (unsigned int i=0; i> 4) & 0x0F; + hl.size = data & 0x0F; + hl.ref=0; + for (int i=0; i< hl.size;i++){ + hl.ref = (hl.ref << 8) | getRawChar8(); + } + return hl; +} + +dwgHandle dwgBuffer::getOffsetHandle(duint32 href){ //H + dwgHandle hl = getHandle(); + + if (hl.code > 5){ + if (hl.code == 0x0C) + hl.ref = href - hl.ref; + else if (hl.code == 0x0A) + hl.ref = href + hl.ref; + else if (hl.code == 0x08) + hl.ref = href - 1; + else if (hl.code == 0x06) + hl.ref = href + 1; +//all are soft pointer reference change to 7 (without offset) + hl.code = 7; + } + return hl; +} + +//internal until 2004 +std::string dwgBuffer::get8bitStr(){ + duint16 textSize = getBitShort(); + if (textSize == 0) + return std::string(); + duint8 *tmpBuffer = new duint8[textSize]; + bool good = getBytes(tmpBuffer, textSize); + if (!good) + return std::string(); + +/* filestr->read (buffer,textSize); + if (!filestr->good()) + return std::string(); + + duint8 tmp; + if (bitPos != 0){ + for (int i=0; i> (8 - bitPos)); + currByte = tmp; + } + }*/ + std::string str(reinterpret_cast(tmpBuffer), textSize); + delete[]tmpBuffer; + + return str; +} + +//internal since 2007 //pending: are 2 bytes null terminated?? +//nullTerm = true if string are 2 bytes null terminated from the stream +std::string dwgBuffer::get16bitStr(duint16 textSize, bool nullTerm){ + if (textSize == 0) + return std::string(); + textSize *=2; + duint16 ts = textSize; + if (nullTerm) + ts += 2; + duint8 *tmpBuffer = new duint8[textSize + 2]; + bool good = getBytes(tmpBuffer, ts); + if (!good) + return std::string(); + if (!nullTerm) { + tmpBuffer[textSize] = '\0'; + tmpBuffer[textSize + 1] = '\0'; + } + std::string str(reinterpret_cast(tmpBuffer), ts); + delete[]tmpBuffer; + + return str; +} + +//T 8 bit text converted from codepage to utf8 +std::string dwgBuffer::getCP8Text(){ + std::string strData; + strData = get8bitStr();//RLZ correct these function + if (decoder == NULL) + return strData; + + return decoder->toUtf8(strData); +} + +//TU unicode 16 bit (UCS) text converted to utf8 +/**Reads 2-bytes char (UCS2, NULL terminated) and convert to std::string (only for Latin-1) + ts= total input size in bytes. +**/ +std::string dwgBuffer::getUCSStr(duint16 ts){ + std::string strData; + if (ts<4) //at least 1 char + return std::string(); + strData = get16bitStr(ts/2, false); + if (decoder == NULL) + return strData; + + return decoder->toUtf8(strData); +} + +//TU unicode 16 bit (UCS) text converted to utf8 +//nullTerm = true if string are 2 bytes null terminated from the stream +std::string dwgBuffer::getUCSText(bool nullTerm){ + std::string strData; + duint16 ts = getBitShort(); + if (ts == 0) + return std::string(); + + strData = get16bitStr(ts, nullTerm); + if (decoder == NULL) + return strData; + + return decoder->toUtf8(strData); +} + +//RLZ: read a T or TU if version is 2007+ +//nullTerm = true if string are 2 bytes null terminated from the stream +std::string dwgBuffer::getVariableText(DRW::Version v, bool nullTerm){//TV + if (v > DRW::AC1018) + return getUCSText(nullTerm); + return getCP8Text(); +} +duint16 dwgBuffer::getObjType(DRW::Version v){//OT + if (v > DRW::AC1021) { + duint8 b = get2Bits(); + if (b == 0) + return getRawChar8(); + else if (b== 1){ + return (getRawChar8() + 0x01F0); + } else //b == 2 + return getRawShort16(); + } + return getBitShort(); +} + +/* Bit Extrusion +* For R2000+, this is a single bit, If the single bit is 1, +* the extrusion value is assumed to be 0,0,1 and no explicit +* extrusion is stored. If the single bit is 0, then it will +* be followed by 3BD. +* For R13-R14 this is 3BD. +*/ +DRW_Coord dwgBuffer::getExtrusion(bool b_R2000_style) { + DRW_Coord ext(0.0,0.0,1.0); + if ( b_R2000_style ) + /* If the bit is one, the extrusion value is assumed to be 0,0,1*/ + if ( getBit() == 1 ) + return ext; + /*R13-R14 or bit == 0*/ + ext.x = getBitDouble(); + ext.y = getBitDouble(); + ext.z = getBitDouble(); + return ext; +} + +/**Reads compresed Double with default (max. 64 + 2 bits) returns a floating point double of 64 bits (DD) **/ +double dwgBuffer::getDefaultDouble(double d){ + dint8 b = get2Bits(); + if (b == 0) + return d; + else if (b == 1){ + duint8 buffer[4]; + char *tmp; + if (bitPos != 0) { + for (int i = 0; i < 4; i++) + buffer[i] = getRawChar8(); + } else { + filestr->read (buffer,4); + } + tmp = reinterpret_cast(&d); + for (int i = 0; i < 4; i++) + tmp[i] = buffer[i]; + double ret = *reinterpret_cast( tmp ); + return ret; + } else if (b == 2){ + duint8 buffer[6]; + char *tmp; + if (bitPos != 0) { + for (int i = 0; i < 6; i++) + buffer[i] = getRawChar8(); + } else { + filestr->read (buffer,6); + } + tmp = reinterpret_cast(&d); + for (int i = 2; i < 6; i++) + tmp[i-2] = buffer[i]; + tmp[4] = buffer[0]; + tmp[5] = buffer[1]; + double ret = *reinterpret_cast( tmp ); + return ret; + } + // if (b == 3) return a full raw double + return getRawDouble(); +} + + +/* BitThickness +* For R13-R14, this is a BD. +* For R2000+, this is a single bit, If the bit is one, +* the thickness value is assumed to be 0.0, if not a BD follow +*/ +double dwgBuffer::getThickness(bool b_R2000_style) { + if ( b_R2000_style ) + /* If the bit is one, the thickness value is assumed to be 0.0.*/ + if ( getBit() == 1 ) + return 0.0; + /*R13-R14 or bit == 0*/ + return getBitDouble(); +} + +/* CmColor (CMC) +* For R15 and earlier call directly BS as ACIS color. +* For R2004+, can be CMC or ENC +* RGB value, first 4bits 0xC0 => ByLayer, 0xC1 => ByBlock, 0xC2 => RGB, 0xC3 => last 4 are ACIS +*/ +duint32 dwgBuffer::getCmColor(DRW::Version v) { + if (v < DRW::AC1018) //2000- + return getSBitShort(); + duint16 idx = getBitShort(); + duint32 rgb = getBitLong(); + duint8 cb = getRawChar8(); + duint8 type = rgb >> 24; + DRW_DBG("\ntype COLOR: "); DRW_DBGH(type); + DRW_DBG("\nindex COLOR: "); DRW_DBGH(idx); + DRW_DBG("\nRGB COLOR: "); DRW_DBGH(rgb); + DRW_DBG("\nbyte COLOR: "); DRW_DBGH(cb); + if (cb&1){ + std::string colorName = getVariableText(v, false); + DRW_DBG("\ncolorName: "); DRW_DBG(colorName); + } + if (cb&2){ + std::string bookName = getVariableText(v, false); + DRW_DBG("\nbookName: "); DRW_DBG(bookName); + } + switch (type) { + case 0xC0: + return 256;//ByLayer + break; + case 0xC1: + return 0;//ByBlock + break; + case 0xC2: + return 256;//RGB RLZ TODO + break; + case 0xC3: + return rgb&0xFF;//ACIS + break; + default: + break; + } + //check cb if strings follows RLZ TODO + return 256; //default return ByLayer +} + +/* EnColor (ENC) +* For R15 and earlier call directly BS as ACIS color. +* For R2004+, can be CMC or ENC +* RGB value, first 4bits 0xC0 => ByLayer, 0xC1 => ByBlock, 0xC2 => RGB, 0xC3 => last 4 are ACIS +*/ +duint32 dwgBuffer::getEnColor(DRW::Version v) { + if (v < DRW::AC1018) //2000- + return getSBitShort(); + duint32 rgb = 0; + duint32 cb = 0; + duint16 idx = getBitShort(); + DRW_DBG("idx reads COLOR: "); DRW_DBGH(idx); + duint16 flags = idx>>8; + idx = idx & 0x1FF; //RLZ: warning this is correct? + DRW_DBG("\nflag COLOR: "); DRW_DBGH(flags); + DRW_DBG(", index COLOR: "); DRW_DBGH(idx); +// if (flags & 0x80) { +// rgb = getBitLong(); +// DRW_DBG("\nRGB COLOR: "); DRW_DBGH(rgb); +// } + if (flags & 0x20) { + cb = getBitLong(); + DRW_DBG("\nTransparency COLOR: "); DRW_DBGH(cb); + } + if (flags & 0x40) + DRW_DBG("\nacdbColor COLOR are present"); + else { + if (flags & 0x80) { + rgb = getBitLong(); + DRW_DBG("\nRGB COLOR: "); DRW_DBGH(rgb); + } + } + +/* if (flags & 0x80) + return getBitLong();*/ + + return idx; //default return ByLayer +} + + +/**Reads raw short 16 bits big-endian order, returns a unsigned short crc & size **/ +duint16 dwgBuffer::getBERawShort16(){ + char buffer[2]; + buffer[0] = getRawChar8(); + buffer[1] = getRawChar8(); + duint16 size = (buffer[0] << 8) | (buffer[1] & 0xFF); + return size; +} + +/* reads "size" bytes and stores in "buf" return false if fail */ +bool dwgBuffer::getBytes(unsigned char *buf, int size){ + duint8 tmp; + filestr->read (buf,size); + if (!filestr->good()) + return false; + + if (bitPos != 0){ + for (int i=0; i> (8 - bitPos)); + currByte = tmp; + } + } + return true; +} + +duint16 dwgBuffer::crc8(duint16 dx,dint32 start,dint32 end){ + int pos = filestr->getPos(); + filestr->setPos(start); + int n = end-start; + duint8 *tmpBuf = new duint8[n]; + duint8 *p = tmpBuf; + filestr->read (tmpBuf,n); + filestr->setPos(pos); + if (!filestr->good()) + return 0; + + duint8 al; + + while (n-- > 0) { + al = (duint8)((*p) ^ ((dint8)(dx & 0xFF))); + dx = (dx>>8) & 0xFF; + dx = dx ^ crctable[al & 0xFF]; + p++; + } + delete[]tmpBuf; + return(dx); +} + +duint32 dwgBuffer::crc32(duint32 seed,dint32 start,dint32 end){ + int pos = filestr->getPos(); + filestr->setPos(start); + int n = end-start; + duint8 *tmpBuf = new duint8[n]; + duint8 *p = tmpBuf; + filestr->read (tmpBuf,n); + filestr->setPos(pos); + if (!filestr->good()) + return 0; + + duint32 invertedCrc = ~seed; + while (n-- > 0) { + duint8 data = *p++; + invertedCrc = (invertedCrc >> 8) ^ crc32Table[(invertedCrc ^ data) & 0xff]; + } + delete[]tmpBuf; + return ~invertedCrc; +} + + +/*std::string dwgBuffer::getBytes(int size){ + char buffer[size]; + char tmp; + filestr->read (buffer,size); + if (!filestr->good()) + return NULL; + + if (bitPos != 0){ + for (int i=0; i<=size;i++){ + tmp = buffer[i]; + buffer[i] = (currByte << bitPos) | (tmp >> (8 - bitPos)); + currByte = tmp; + } + } + std::string st; + for (int i=0; i. ** +******************************************************************************/ + +#ifndef DWGBUFFER_H +#define DWGBUFFER_H + +#include +#include +#include "../drw_base.h" + +class DRW_Coord; +class DRW_TextCodec; + +class dwgBasicStream{ +protected: + dwgBasicStream(){} +public: + virtual ~dwgBasicStream(){} + virtual bool read(duint8* s, duint64 n) = 0; + virtual duint64 size() = 0; + virtual duint64 getPos() = 0; + virtual bool setPos(duint64 p) = 0; + virtual bool good() = 0; + virtual dwgBasicStream* clone() = 0; +}; + +class dwgFileStream: public dwgBasicStream{ +public: + dwgFileStream(std::istream *s){ + stream =s; + stream->seekg (0, std::ios::end); + sz = stream->tellg(); + stream->seekg(0, std::ios_base::beg); + } + virtual ~dwgFileStream(){} + virtual bool read(duint8* s, duint64 n); + virtual duint64 size(){return sz;} + virtual duint64 getPos(){return stream->tellg();} + virtual bool setPos(duint64 p); + virtual bool good(){return stream->good();} + virtual dwgBasicStream* clone(){return new dwgFileStream(stream);} +private: + std::istream *stream; + duint64 sz; +}; + +class dwgCharStream: public dwgBasicStream{ +public: + dwgCharStream(duint8 *buf, int s){ + stream =buf; + sz = s; + pos = 0; + isOk = true; + } + virtual ~dwgCharStream(){} + virtual bool read(duint8* s, duint64 n); + virtual duint64 size(){return sz;} + virtual duint64 getPos(){return pos;} + virtual bool setPos(duint64 p); + virtual bool good(){return isOk;} + virtual dwgBasicStream* clone(){return new dwgCharStream(stream, sz);} +private: + duint8 *stream; + duint64 sz; + duint64 pos; + bool isOk; +}; + +class dwgBuffer { +public: + dwgBuffer(std::istream *stream, DRW_TextCodec *decoder = NULL); + dwgBuffer(duint8 *buf, int size, DRW_TextCodec *decoder= NULL); + dwgBuffer( const dwgBuffer& org ); + dwgBuffer& operator=( const dwgBuffer& org ); + ~dwgBuffer(); + duint64 size(){return filestr->size();} + bool setPosition(duint64 pos); + duint64 getPosition(); + void resetPosition(){setPosition(0); setBitPos(0);} + void setBitPos(duint8 pos); + duint8 getBitPos(){return bitPos;} + bool moveBitPos(dint32 size); + + duint8 getBit(); //B + bool getBoolBit(); //B as bool + duint8 get2Bits(); //BB + duint8 get3Bits(); //3B + duint16 getBitShort(); //BS + dint16 getSBitShort(); //BS + dint32 getBitLong(); //BL + duint64 getBitLongLong(); //BLL (R24) + double getBitDouble(); //BD + //2BD => call BD 2 times + DRW_Coord get3BitDouble(); //3BD + duint8 getRawChar8(); //RC + duint16 getRawShort16(); //RS + double getRawDouble(); //RD + duint32 getRawLong32(); //RL + duint64 getRawLong64(); //RLL + DRW_Coord get2RawDouble(); //2RD + //3RD => call RD 3 times + duint32 getUModularChar(); //UMC, unsigned for offsets in 1015 + dint32 getModularChar(); //MC + dint32 getModularShort(); //MS + dwgHandle getHandle(); //H + dwgHandle getOffsetHandle(duint32 href); //H converted to hard + UTF8STRING getVariableText(DRW::Version v, bool nullTerm = true); //TV => call TU for 2007+ or T for previous versions + UTF8STRING getCP8Text(); //T 8 bit text converted from codepage to utf8 + UTF8STRING getUCSText(bool nullTerm = true); //TU unicode 16 bit (UCS) text converted to utf8 + UTF8STRING getUCSStr(duint16 ts); + + duint16 getObjType(DRW::Version v); //OT + + //X, U, SN, + + DRW_Coord getExtrusion(bool b_R2000_style); //BE + double getDefaultDouble(double d); //DD + double getThickness(bool b_R2000_style);//BT + //3DD + duint32 getCmColor(DRW::Version v); //CMC + duint32 getEnColor(DRW::Version v); //ENC + //TC + + duint16 getBERawShort16(); //RS big-endian order + + bool isGood(){return filestr->good();} + bool getBytes(duint8 *buf, int size); + int numRemainingBytes(){return (maxSize- filestr->getPos());} + + duint16 crc8(duint16 dx,dint32 start,dint32 end); + duint32 crc32(duint32 seed,dint32 start,dint32 end); + +// duint8 getCurrByte(){return currByte;} + DRW_TextCodec *decoder; + +private: + dwgBasicStream *filestr; + int maxSize; + duint8 currByte; + duint8 bitPos; + + UTF8STRING get8bitStr(); + UTF8STRING get16bitStr(duint16 textSize, bool nullTerm = true); +}; + +#endif // DWGBUFFER_H diff --git a/src/libs/vdxf/libdxfrw/intern/dwgreader.cpp b/src/libs/vdxf/libdxfrw/intern/dwgreader.cpp new file mode 100644 index 000000000..da6ac3555 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/dwgreader.cpp @@ -0,0 +1,1294 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#include +#include +#include +#include +#include +#include "dwgreader.h" +#include "drw_textcodec.h" +#include "drw_dbg.h" + +dwgReader::~dwgReader(){ + for (std::map::iterator it=ltypemap.begin(); it!=ltypemap.end(); ++it) + delete(it->second); + for (std::map::iterator it=layermap.begin(); it!=layermap.end(); ++it) + delete(it->second); + for (std::map::iterator it=blockmap.begin(); it!=blockmap.end(); ++it) + delete(it->second); + for (std::map::iterator it=stylemap.begin(); it!=stylemap.end(); ++it) + delete(it->second); + for (std::map::iterator it=dimstylemap.begin(); it!=dimstylemap.end(); ++it) + delete(it->second); + for (std::map::iterator it=vportmap.begin(); it!=vportmap.end(); ++it) + delete(it->second); + for (std::map::iterator it=classesmap.begin(); it!=classesmap.end(); ++it) + delete(it->second); + for (std::map::iterator it=blockRecordmap.begin(); it!=blockRecordmap.end(); ++it) + delete(it->second); + for (std::map::iterator it=appIdmap.begin(); it!=appIdmap.end(); ++it) + delete(it->second); + + delete fileBuf; +} + +void dwgReader::parseAttribs(DRW_Entity* e){ + if (e != NULL){ + duint32 ltref =e->lTypeH.ref; + duint32 lyref =e->layerH.ref; + std::map::iterator lt_it = ltypemap.find(ltref); + if (lt_it != ltypemap.end()){ + e->lineType = (lt_it->second)->name; + } + std::map::iterator ly_it = layermap.find(lyref); + if (ly_it != layermap.end()){ + e->layer = (ly_it->second)->name; + } + } +} + +std::string dwgReader::findTableName(DRW::TTYPE table, dint32 handle){ + std::string name; + switch (table){ + case DRW::STYLE:{ + std::map::iterator st_it = stylemap.find(handle); + if (st_it != stylemap.end()) + name = (st_it->second)->name; + break;} + case DRW::DIMSTYLE:{ + std::map::iterator ds_it = dimstylemap.find(handle); + if (ds_it != dimstylemap.end()) + name = (ds_it->second)->name; + break;} + case DRW::BLOCK_RECORD:{ //use DRW_Block because name are more correct +// std::map::iterator bk_it = blockmap.find(handle); +// if (bk_it != blockmap.end()) + std::map::iterator bk_it = blockRecordmap.find(handle); + if (bk_it != blockRecordmap.end()) + name = (bk_it->second)->name; + break;} +/* case DRW::VPORT:{ + std::map::iterator vp_it = vportmap.find(handle); + if (vp_it != vportmap.end()) + name = (vp_it->second)->name; + break;}*/ + case DRW::LAYER:{ + std::map::iterator ly_it = layermap.find(handle); + if (ly_it != layermap.end()) + name = (ly_it->second)->name; + break;} + case DRW::LTYPE:{ + std::map::iterator lt_it = ltypemap.find(handle); + if (lt_it != ltypemap.end()) + name = (lt_it->second)->name; + break;} + default: + break; + } + return name; +} + +bool dwgReader::readDwgHeader(DRW_Header& hdr, dwgBuffer *buf, dwgBuffer *hBuf){ + bool ret = hdr.parseDwg(version, buf, hBuf, maintenanceVersion); + //RLZ: copy objectControl handles + return ret; +} + +//RLZ: TODO add check instead print +bool dwgReader::checkSentinel(dwgBuffer *buf, enum secEnum::DWGSection, bool start){ + DRW_UNUSED(start); + for (int i=0; i<16;i++) { + DRW_DBGH(buf->getRawChar8()); DRW_DBG(" "); + } + return true; +} + +/*********** objects map ************************/ +/** Note: object map are split in sections with max size 2035? + * heach section are 2 bytes size + data bytes + 2 bytes crc + * size value are data bytes + 2 and to calculate crc are used + * 2 bytes size + data bytes + * last section are 2 bytes size + 2 bytes crc (size value always 2) +**/ +bool dwgReader::readDwgHandles(dwgBuffer *dbuf, duint32 offset, duint32 size) { + DRW_DBG("\ndwgReader::readDwgHandles\n"); + if (!dbuf->setPosition(offset)) + return false; + + duint32 maxPos = offset + size; + DRW_DBG("\nSection HANDLES offset= "); DRW_DBG(offset); + DRW_DBG("\nSection HANDLES size= "); DRW_DBG(size); + DRW_DBG("\nSection HANDLES maxPos= "); DRW_DBG(maxPos); + + int startPos = offset; + + while (maxPos > dbuf->getPosition()) { + DRW_DBG("\nstart handles section buf->curPosition()= "); DRW_DBG(dbuf->getPosition()); DRW_DBG("\n"); + duint16 size = dbuf->getBERawShort16(); + DRW_DBG("object map section size= "); DRW_DBG(size); DRW_DBG("\n"); + dbuf->setPosition(startPos); + duint8 *tmpByteStr = new duint8[size]; + dbuf->getBytes(tmpByteStr, size); + dwgBuffer buff(tmpByteStr, size, &decoder); + if (size != 2){ + buff.setPosition(2); + int lastHandle = 0; + int lastLoc = 0; + //read data + while(buff.getPosition()< size){ + lastHandle += buff.getUModularChar(); + DRW_DBG("object map lastHandle= "); DRW_DBGH(lastHandle); + lastLoc += buff.getModularChar(); + DRW_DBG(" lastLoc= "); DRW_DBG(lastLoc); DRW_DBG("\n"); + ObjectMap[lastHandle]= objHandle(0, lastHandle, lastLoc); + } + } + //verify crc + duint16 crcCalc = buff.crc8(0xc0c1,0,size); + delete[]tmpByteStr; + duint16 crcRead = dbuf->getBERawShort16(); + DRW_DBG("object map section crc8 read= "); DRW_DBG(crcRead); + DRW_DBG("\nobject map section crc8 calculated= "); DRW_DBG(crcCalc); + DRW_DBG("\nobject section buf->curPosition()= "); DRW_DBG(dbuf->getPosition()); DRW_DBG("\n"); + startPos = dbuf->getPosition(); + } + + bool ret = dbuf->isGood(); + return ret; +} + +/*********** objects ************************/ +/** + * Reads all the object referenced in the object map section of the DWG file + * (using their object file offsets) + */ +bool dwgReader::readDwgTables(DRW_Header& hdr, dwgBuffer *dbuf) { + DRW_DBG("\ndwgReader::readDwgTables start\n"); + bool ret = true; + bool ret2 = true; + objHandle oc; + std::map::iterator mit; + dint16 oType; + duint32 bs = 0; //bit size of handle stream 2010+ + duint8 *tmpByteStr; + + //parse linetypes, start with linetype Control + mit = ObjectMap.find(hdr.linetypeCtrl); + if (mit==ObjectMap.end()) { + DRW_DBG("\nWARNING: LineType control not found\n"); + ret = false; + } else { + DRW_DBG("\n**********Parsing LineType control*******\n"); + oc = mit->second; + ObjectMap.erase(mit); + DRW_ObjControl ltControl; + dbuf->setPosition(oc.loc); + int csize = dbuf->getModularShort(); + if (version > DRW::AC1021) //2010+ + bs = dbuf->getUModularChar(); + else + bs = 0; + tmpByteStr = new duint8[csize]; + dbuf->getBytes(tmpByteStr, csize); + dwgBuffer cbuff(tmpByteStr, csize, &decoder); + //verify if object are correct + oType = cbuff.getObjType(version); + if (oType != 0x38) { + DRW_DBG("\nWARNING: Not LineType control object, found oType "); + DRW_DBG(oType); DRW_DBG(" instead 0x38\n"); + ret = false; + } else { //reset position + cbuff.resetPosition(); + ret2 = ltControl.parseDwg(version, &cbuff, bs); + if(ret) + ret = ret2; + } + delete[]tmpByteStr; + for (std::list::iterator it=ltControl.hadlesList.begin(); it != ltControl.hadlesList.end(); ++it){ + mit = ObjectMap.find(*it); + if (mit==ObjectMap.end()) { + DRW_DBG("\nWARNING: LineType not found\n"); + ret = false; + } else { + oc = mit->second; + ObjectMap.erase(mit); + DRW_DBG("\nLineType Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" loc.: "); DRW_DBG(oc.loc); DRW_DBG("\n"); + DRW_LType *lt = new DRW_LType(); + dbuf->setPosition(oc.loc); + int lsize = dbuf->getModularShort(); + DRW_DBG("LineType size in bytes= "); DRW_DBG(lsize); + if (version > DRW::AC1021) //2010+ + bs = dbuf->getUModularChar(); + else + bs = 0; + tmpByteStr = new duint8[lsize]; + dbuf->getBytes(tmpByteStr, lsize); + dwgBuffer lbuff(tmpByteStr, lsize, &decoder); + ret2 = lt->parseDwg(version, &lbuff, bs); + ltypemap[lt->handle] = lt; + if(ret) + ret = ret2; + delete[]tmpByteStr; + } + } + } + + //parse layers, start with layer Control + mit = ObjectMap.find(hdr.layerCtrl); + if (mit==ObjectMap.end()) { + DRW_DBG("\nWARNING: Layer control not found\n"); + ret = false; + } else { + DRW_DBG("\n**********Parsing Layer control*******\n"); + oc = mit->second; + ObjectMap.erase(mit); + DRW_ObjControl layControl; + dbuf->setPosition(oc.loc); + int size = dbuf->getModularShort(); + if (version > DRW::AC1021) //2010+ + bs = dbuf->getUModularChar(); + else + bs = 0; + tmpByteStr = new duint8[size]; + dbuf->getBytes(tmpByteStr, size); + dwgBuffer buff(tmpByteStr, size, &decoder); + //verify if object are correct + oType = buff.getObjType(version); + if (oType != 0x32) { + DRW_DBG("\nWARNING: Not Layer control object, found oType "); + DRW_DBG(oType); DRW_DBG(" instead 0x32\n"); + ret = false; + } else { //reset position + buff.resetPosition(); + ret2 = layControl.parseDwg(version, &buff, bs); + if(ret) + ret = ret2; + } + delete[]tmpByteStr; + for (std::list::iterator it=layControl.hadlesList.begin(); it != layControl.hadlesList.end(); ++it){ + mit = ObjectMap.find(*it); + if (mit==ObjectMap.end()) { + DRW_DBG("\nWARNING: Layer not found\n"); + ret = false; + } else { + oc = mit->second; + ObjectMap.erase(mit); + DRW_DBG("Layer Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" "); DRW_DBG(oc.loc); DRW_DBG("\n"); + DRW_Layer *la = new DRW_Layer(); + dbuf->setPosition(oc.loc); + int size = dbuf->getModularShort(); + if (version > DRW::AC1021) //2010+ + bs = dbuf->getUModularChar(); + else + bs = 0; + tmpByteStr = new duint8[size]; + dbuf->getBytes(tmpByteStr, size); + dwgBuffer buff(tmpByteStr, size, &decoder); + ret2 = la->parseDwg(version, &buff, bs); + layermap[la->handle] = la; + if(ret) + ret = ret2; + delete[]tmpByteStr; + } + } + } + + //set linetype in layer + for (std::map::iterator it=layermap.begin(); it!=layermap.end(); ++it) { + DRW_Layer *ly = it->second; + duint32 ref =ly->lTypeH.ref; + std::map::iterator lt_it = ltypemap.find(ref); + if (lt_it != ltypemap.end()){ + ly->lineType = (lt_it->second)->name; + } + } + + //parse text styles, start with style Control + mit = ObjectMap.find(hdr.styleCtrl); + if (mit==ObjectMap.end()) { + DRW_DBG("\nWARNING: Style control not found\n"); + ret = false; + } else { + DRW_DBG("\n**********Parsing Style control*******\n"); + oc = mit->second; + ObjectMap.erase(mit); + DRW_ObjControl styControl; + dbuf->setPosition(oc.loc); + int size = dbuf->getModularShort(); + if (version > DRW::AC1021) //2010+ + bs = dbuf->getUModularChar(); + else + bs = 0; + tmpByteStr = new duint8[size]; + dbuf->getBytes(tmpByteStr, size); + dwgBuffer buff(tmpByteStr, size, &decoder); + //verify if object are correct + oType = buff.getObjType(version); + if (oType != 0x34) { + DRW_DBG("\nWARNING: Not Text Style control object, found oType "); + DRW_DBG(oType); DRW_DBG(" instead 0x34\n"); + ret = false; + } else { //reset position + buff.resetPosition(); + ret2 = styControl.parseDwg(version, &buff, bs); + if(ret) + ret = ret2; + } + delete[]tmpByteStr; + for (std::list::iterator it=styControl.hadlesList.begin(); it != styControl.hadlesList.end(); ++it){ + mit = ObjectMap.find(*it); + if (mit==ObjectMap.end()) { + DRW_DBG("\nWARNING: Style not found\n"); + ret = false; + } else { + oc = mit->second; + ObjectMap.erase(mit); + DRW_DBG("Style Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" "); DRW_DBG(oc.loc); DRW_DBG("\n"); + DRW_Textstyle *sty = new DRW_Textstyle(); + dbuf->setPosition(oc.loc); + int size = dbuf->getModularShort(); + if (version > DRW::AC1021) //2010+ + bs = dbuf->getUModularChar(); + else + bs = 0; + tmpByteStr = new duint8[size]; + dbuf->getBytes(tmpByteStr, size); + dwgBuffer buff(tmpByteStr, size, &decoder); + ret2 = sty->parseDwg(version, &buff, bs); + stylemap[sty->handle] = sty; + if(ret) + ret = ret2; + delete[]tmpByteStr; + } + } + } + + //parse dim styles, start with dimstyle Control + mit = ObjectMap.find(hdr.dimstyleCtrl); + if (mit==ObjectMap.end()) { + DRW_DBG("\nWARNING: Dimension Style control not found\n"); + ret = false; + } else { + DRW_DBG("\n**********Parsing Dimension Style control*******\n"); + oc = mit->second; + ObjectMap.erase(mit); + DRW_ObjControl dimstyControl; + dbuf->setPosition(oc.loc); + duint32 size = dbuf->getModularShort(); + if (version > DRW::AC1021) //2010+ + bs = dbuf->getUModularChar(); + else + bs = 0; + tmpByteStr = new duint8[size]; + dbuf->getBytes(tmpByteStr, size); + dwgBuffer buff(tmpByteStr, size, &decoder); + //verify if object are correct + oType = buff.getObjType(version); + if (oType != 0x44) { + DRW_DBG("\nWARNING: Not Dim Style control object, found oType "); + DRW_DBG(oType); DRW_DBG(" instead 0x44\n"); + ret = false; + } else { //reset position + buff.resetPosition(); + ret2 = dimstyControl.parseDwg(version, &buff, bs); + if(ret) + ret = ret2; + } + delete[]tmpByteStr; + for (std::list::iterator it=dimstyControl.hadlesList.begin(); it != dimstyControl.hadlesList.end(); ++it){ + mit = ObjectMap.find(*it); + if (mit==ObjectMap.end()) { + DRW_DBG("\nWARNING: Dimension Style not found\n"); + ret = false; + } else { + oc = mit->second; + ObjectMap.erase(mit); + DRW_DBG("Dimstyle Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" "); DRW_DBG(oc.loc); DRW_DBG("\n"); + DRW_Dimstyle *sty = new DRW_Dimstyle(); + dbuf->setPosition(oc.loc); + int size = dbuf->getModularShort(); + if (version > DRW::AC1021) //2010+ + bs = dbuf->getUModularChar(); + else + bs = 0; + tmpByteStr = new duint8[size]; + dbuf->getBytes(tmpByteStr, size); + dwgBuffer buff(tmpByteStr, size, &decoder); + ret2 = sty->parseDwg(version, &buff, bs); + dimstylemap[sty->handle] = sty; + if(ret) + ret = ret2; + delete[]tmpByteStr; + } + } + } + + //parse vports, start with vports Control + mit = ObjectMap.find(hdr.vportCtrl); + if (mit==ObjectMap.end()) { + DRW_DBG("\nWARNING: vports control not found\n"); + ret = false; + } else { + DRW_DBG("\n**********Parsing vports control*******\n"); + oc = mit->second; + ObjectMap.erase(mit); + DRW_ObjControl vportControl; + dbuf->setPosition(oc.loc); + int size = dbuf->getModularShort(); + if (version > DRW::AC1021) //2010+ + bs = dbuf->getUModularChar(); + else + bs = 0; + tmpByteStr = new duint8[size]; + dbuf->getBytes(tmpByteStr, size); + dwgBuffer buff(tmpByteStr, size, &decoder); + //verify if object are correct + oType = buff.getObjType(version); + if (oType != 0x40) { + DRW_DBG("\nWARNING: Not VPorts control object, found oType: "); + DRW_DBG(oType); DRW_DBG(" instead 0x40\n"); + ret = false; + } else { //reset position + buff.resetPosition(); + ret2 = vportControl.parseDwg(version, &buff, bs); + if(ret) + ret = ret2; + } + delete[]tmpByteStr; + for (std::list::iterator it=vportControl.hadlesList.begin(); it != vportControl.hadlesList.end(); ++it){ + mit = ObjectMap.find(*it); + if (mit==ObjectMap.end()) { + DRW_DBG("\nWARNING: vport not found\n"); + ret = false; + } else { + oc = mit->second; + ObjectMap.erase(mit); + DRW_DBG("Vport Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" "); DRW_DBG(oc.loc); DRW_DBG("\n"); + DRW_Vport *vp = new DRW_Vport(); + dbuf->setPosition(oc.loc); + int size = dbuf->getModularShort(); + if (version > DRW::AC1021) //2010+ + bs = dbuf->getUModularChar(); + else + bs = 0; + tmpByteStr = new duint8[size]; + dbuf->getBytes(tmpByteStr, size); + dwgBuffer buff(tmpByteStr, size, &decoder); + ret2 = vp->parseDwg(version, &buff, bs); + vportmap[vp->handle] = vp; + if(ret) + ret = ret2; + delete[]tmpByteStr; + } + } + } + + //parse Block_records , start with Block_record Control + mit = ObjectMap.find(hdr.blockCtrl); + if (mit==ObjectMap.end()) { + DRW_DBG("\nWARNING: Block_record control not found\n"); + ret = false; + } else { + DRW_DBG("\n**********Parsing Block_record control*******\n"); + oc = mit->second; + ObjectMap.erase(mit); + DRW_ObjControl blockControl; + dbuf->setPosition(oc.loc); + int csize = dbuf->getModularShort(); + if (version > DRW::AC1021) //2010+ + bs = dbuf->getUModularChar(); + else + bs = 0; + tmpByteStr = new duint8[csize]; + dbuf->getBytes(tmpByteStr, csize); + dwgBuffer buff(tmpByteStr, csize, &decoder); + //verify if object are correct + oType = buff.getObjType(version); + if (oType != 0x30) { + DRW_DBG("\nWARNING: Not Block Record control object, found oType "); + DRW_DBG(oType); DRW_DBG(" instead 0x30\n"); + ret = false; + } else { //reset position + buff.resetPosition(); + ret2 = blockControl.parseDwg(version, &buff, bs); + if(ret) + ret = ret2; + } + delete[]tmpByteStr; + for (std::list::iterator it=blockControl.hadlesList.begin(); it != blockControl.hadlesList.end(); ++it){ + mit = ObjectMap.find(*it); + if (mit==ObjectMap.end()) { + DRW_DBG("\nWARNING: block record not found\n"); + ret = false; + } else { + oc = mit->second; + ObjectMap.erase(mit); + DRW_DBG("block record Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" "); DRW_DBG(oc.loc); DRW_DBG("\n"); + DRW_Block_Record *br = new DRW_Block_Record(); + dbuf->setPosition(oc.loc); + int size = dbuf->getModularShort(); + if (version > DRW::AC1021) //2010+ + bs = dbuf->getUModularChar(); + else + bs = 0; + tmpByteStr = new duint8[size]; + dbuf->getBytes(tmpByteStr, size); + dwgBuffer buff(tmpByteStr, size, &decoder); + ret2 = br->parseDwg(version, &buff, bs); + blockRecordmap[br->handle] = br; + if(ret) + ret = ret2; + delete[]tmpByteStr; + } + } + } + + //parse appId , start with appId Control + mit = ObjectMap.find(hdr.appidCtrl); + if (mit==ObjectMap.end()) { + DRW_DBG("\nWARNING: AppId control not found\n"); + ret = false; + } else { + DRW_DBG("\n**********Parsing AppId control*******\n"); + oc = mit->second; + ObjectMap.erase(mit); + DRW_DBG("AppId Control Obj Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" "); DRW_DBG(oc.loc); DRW_DBG("\n"); + DRW_ObjControl appIdControl; + dbuf->setPosition(oc.loc); + int size = dbuf->getModularShort(); + if (version > DRW::AC1021) //2010+ + bs = dbuf->getUModularChar(); + else + bs = 0; + tmpByteStr = new duint8[size]; + dbuf->getBytes(tmpByteStr, size); + dwgBuffer buff(tmpByteStr, size, &decoder); + //verify if object are correct + oType = buff.getObjType(version); + if (oType != 0x42) { + DRW_DBG("\nWARNING: Not AppId control object, found oType "); + DRW_DBG(oType); DRW_DBG(" instead 0x42\n"); + ret = false; + } else { //reset position + buff.resetPosition(); + ret2 = appIdControl.parseDwg(version, &buff, bs); + if(ret) + ret = ret2; + } + delete[]tmpByteStr; + for (std::list::iterator it=appIdControl.hadlesList.begin(); it != appIdControl.hadlesList.end(); ++it){ + mit = ObjectMap.find(*it); + if (mit==ObjectMap.end()) { + DRW_DBG("\nWARNING: AppId not found\n"); + ret = false; + } else { + oc = mit->second; + ObjectMap.erase(mit); + DRW_DBG("AppId Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" "); DRW_DBG(oc.loc); DRW_DBG("\n"); + DRW_AppId *ai = new DRW_AppId(); + dbuf->setPosition(oc.loc); + int size = dbuf->getModularShort(); + if (version > DRW::AC1021) //2010+ + bs = dbuf->getUModularChar(); + else + bs = 0; + tmpByteStr = new duint8[size]; + dbuf->getBytes(tmpByteStr, size); + dwgBuffer buff(tmpByteStr, size, &decoder); + ret2 = ai->parseDwg(version, &buff, bs); + appIdmap[ai->handle] = ai; + if(ret) + ret = ret2; + delete[]tmpByteStr; + } + } + } + + //RLZ: parse remaining object controls, TODO: implement all + if (DRW_DBGGL == DRW_dbg::DEBUG){ + mit = ObjectMap.find(hdr.viewCtrl); + if (mit==ObjectMap.end()) { + DRW_DBG("\nWARNING: View control not found\n"); + ret = false; + } else { + DRW_DBG("\n**********Parsing View control*******\n"); + oc = mit->second; + ObjectMap.erase(mit); + DRW_DBG("View Control Obj Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" "); DRW_DBG(oc.loc); DRW_DBG("\n"); + DRW_ObjControl viewControl; + dbuf->setPosition(oc.loc); + int size = dbuf->getModularShort(); + if (version > DRW::AC1021) //2010+ + bs = dbuf->getUModularChar(); + else + bs = 0; + tmpByteStr = new duint8[size]; + dbuf->getBytes(tmpByteStr, size); + dwgBuffer buff(tmpByteStr, size, &decoder); + //verify if object are correct + oType = buff.getObjType(version); + if (oType != 0x3C) { + DRW_DBG("\nWARNING: Not View control object, found oType "); + DRW_DBG(oType); DRW_DBG(" instead 0x3C\n"); + ret = false; + } else { //reset position + buff.resetPosition(); + ret2 = viewControl.parseDwg(version, &buff, bs); + if(ret) + ret = ret2; + } + delete[]tmpByteStr; + } + + mit = ObjectMap.find(hdr.ucsCtrl); + if (mit==ObjectMap.end()) { + DRW_DBG("\nWARNING: Ucs control not found\n"); + ret = false; + } else { + oc = mit->second; + ObjectMap.erase(mit); + DRW_DBG("\n**********Parsing Ucs control*******\n"); + DRW_DBG("Ucs Control Obj Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" "); DRW_DBG(oc.loc); DRW_DBG("\n"); + DRW_ObjControl ucsControl; + dbuf->setPosition(oc.loc); + int size = dbuf->getModularShort(); + if (version > DRW::AC1021) //2010+ + bs = dbuf->getUModularChar(); + else + bs = 0; + tmpByteStr = new duint8[size]; + dbuf->getBytes(tmpByteStr, size); + dwgBuffer buff(tmpByteStr, size, &decoder); + //verify if object are correct + oType = buff.getObjType(version); + if (oType != 0x3E) { + DRW_DBG("\nWARNING: Not Ucs control object, found oType "); + DRW_DBG(oType); DRW_DBG(" instead 0x3E\n"); + ret = false; + } else { //reset position + buff.resetPosition(); + ret2 = ucsControl.parseDwg(version, &buff, bs); + if(ret) + ret = ret2; + } + delete[]tmpByteStr; + } + + if (version < DRW::AC1018) {//r2000- + mit = ObjectMap.find(hdr.vpEntHeaderCtrl); + if (mit==ObjectMap.end()) { + DRW_DBG("\nWARNING: vpEntHeader control not found\n"); + ret = false; + } else { + DRW_DBG("\n**********Parsing vpEntHeader control*******\n"); + oc = mit->second; + ObjectMap.erase(mit); + DRW_DBG("vpEntHeader Control Obj Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" "); DRW_DBG(oc.loc); DRW_DBG("\n"); + DRW_ObjControl vpEntHeaderCtrl; + dbuf->setPosition(oc.loc); + int size = dbuf->getModularShort(); + if (version > DRW::AC1021) //2010+ + bs = dbuf->getUModularChar(); + else + bs = 0; + tmpByteStr = new duint8[size]; + dbuf->getBytes(tmpByteStr, size); + dwgBuffer buff(tmpByteStr, size, &decoder); + //verify if object are correct + oType = buff.getObjType(version); + if (oType != 0x46) { + DRW_DBG("\nWARNING: Not vpEntHeader control object, found oType "); + DRW_DBG(oType); DRW_DBG(" instead 0x46\n"); + ret = false; + } else { //reset position + buff.resetPosition(); +/* RLZ: writeme ret2 = vpEntHeader.parseDwg(version, &buff, bs); + if(ret) + ret = ret2;*/ + } + delete[]tmpByteStr; + } + } + } + + return ret; +} + +bool dwgReader::readDwgBlocks(DRW_Interface& intfa, dwgBuffer *dbuf){ + bool ret = true; + bool ret2 = true; + duint32 bs =0; + duint8 *tmpByteStr; + std::map::iterator mit; + DRW_DBG("\nobject map total size= "); DRW_DBG(ObjectMap.size()); + + for (std::map::iterator it=blockRecordmap.begin(); it != blockRecordmap.end(); ++it){ + DRW_Block_Record* bkr= it->second; + DRW_DBG("\nParsing Block, record handle= "); DRW_DBGH(it->first); DRW_DBG(" Name= "); DRW_DBG(bkr->name); DRW_DBG("\n"); + DRW_DBG("\nFinding Block, handle= "); DRW_DBGH(bkr->block); DRW_DBG("\n"); + mit = ObjectMap.find(bkr->block); + if (mit==ObjectMap.end()) { + DRW_DBG("\nWARNING: block entity not found\n"); + ret = false; + continue; + } + objHandle oc = mit->second; + ObjectMap.erase(mit); + DRW_DBG("Block Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" Location: "); DRW_DBG(oc.loc); DRW_DBG("\n"); + if ( !(dbuf->setPosition(oc.loc)) ){ + DRW_DBG("Bad Location reading blocks\n"); + ret = false; + continue; + } + int size = dbuf->getModularShort(); + if (version > DRW::AC1021) //2010+ + bs = dbuf->getUModularChar(); + else + bs = 0; + tmpByteStr = new duint8[size]; + dbuf->getBytes(tmpByteStr, size); + dwgBuffer buff(tmpByteStr, size, &decoder); + DRW_Block bk; + ret2 = bk.parseDwg(version, &buff, bs); + delete[]tmpByteStr; + ret = ret && ret2; + parseAttribs(&bk); + //complete block entity with block record data + bk.basePoint = bkr->basePoint; + bk.flags = bkr->flags; + intfa.addBlock(bk); + //and update block record name + bkr->name = bk.name; + + /**read & send block entities**/ + // in dwg code 330 are not set like dxf in ModelSpace & PaperSpace, set it (RLZ: only tested in 2000) + if (bk.parentHandle == DRW::NoHandle) { + // in dwg code 330 are not set like dxf in ModelSpace & PaperSpace, set it + bk.parentHandle= bkr->handle; + //and do not send block entities like dxf + } else { + if (version < DRW::AC1018) { //pre 2004 + duint32 nextH = bkr->firstEH; + while (nextH != 0){ + mit = ObjectMap.find(nextH); + if (mit==ObjectMap.end()) { + nextH = bkr->lastEH;//end while if entity not foud + DRW_DBG("\nWARNING: Entity of block not found\n"); + ret = false; + continue; + } else {//foud entity reads it + oc = mit->second; + ObjectMap.erase(mit); + ret2 = readDwgEntity(dbuf, oc, intfa); + ret = ret && ret2; + } + if (nextH == bkr->lastEH) + nextH = 0; //redundant, but prevent read errors + else + nextH = nextEntLink; + } + } else {//2004+ + for (std::vector::iterator it = bkr->entMap.begin() ; it != bkr->entMap.end(); ++it){ + duint32 nextH = *it; + mit = ObjectMap.find(nextH); + if (mit==ObjectMap.end()) { + DRW_DBG("\nWARNING: Entity of block not found\n"); + ret = false; + continue; + } else {//foud entity reads it + oc = mit->second; + ObjectMap.erase(mit); + DRW_DBG("\nBlocks, parsing entity: "); DRW_DBGH(oc.handle); DRW_DBG(", pos: "); DRW_DBG(oc.loc); DRW_DBG("\n"); + ret2 = readDwgEntity(dbuf, oc, intfa); + ret = ret && ret2; + } + } + }//end 2004+ + } + + //end block entity, really needed to parse a dummy entity?? + mit = ObjectMap.find(bkr->endBlock); + if (mit==ObjectMap.end()) { + DRW_DBG("\nWARNING: end block entity not found\n"); + ret = false; + continue; + } + oc = mit->second; + ObjectMap.erase(mit); + DRW_DBG("End block Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" Location: "); DRW_DBG(oc.loc); DRW_DBG("\n"); + dbuf->setPosition(oc.loc); + size = dbuf->getModularShort(); + if (version > DRW::AC1021) //2010+ + bs = dbuf->getUModularChar(); + else + bs = 0; + tmpByteStr = new duint8[size]; + dbuf->getBytes(tmpByteStr, size); + dwgBuffer buff1(tmpByteStr, size, &decoder); + DRW_Block end; + end.isEnd = true; + ret2 = end.parseDwg(version, &buff1, bs); + delete[]tmpByteStr; + ret = ret && ret2; + if (bk.parentHandle == DRW::NoHandle) bk.parentHandle= bkr->handle; + parseAttribs(&end); + intfa.endBlock(); + } + + return ret; +} + +bool dwgReader::readPlineVertex(DRW_Polyline& pline, dwgBuffer *dbuf){ + bool ret = true; + bool ret2 = true; + objHandle oc; + duint32 bs = 0; + std::map::iterator mit; + + if (version < DRW::AC1018) { //pre 2004 + duint32 nextH = pline.firstEH; + while (nextH != 0){ + mit = ObjectMap.find(nextH); + if (mit==ObjectMap.end()) { + nextH = pline.lastEH;//end while if entity not foud + DRW_DBG("\nWARNING: pline vertex not found\n"); + ret = false; + continue; + } else {//foud entity reads it + oc = mit->second; + ObjectMap.erase(mit); + DRW_Vertex vt; + dbuf->setPosition(oc.loc); + //RLZ: verify if pos is ok + int size = dbuf->getModularShort(); + if (version > DRW::AC1021) {//2010+ + bs = dbuf->getUModularChar(); + } + duint8 *tmpByteStr = new duint8[size]; + dbuf->getBytes(tmpByteStr, size); + dwgBuffer buff(tmpByteStr, size, &decoder); + dint16 oType = buff.getObjType(version); + buff.resetPosition(); + DRW_DBG(" object type= "); DRW_DBG(oType); DRW_DBG("\n"); + ret2 = vt.parseDwg(version, &buff, bs, pline.basePoint.z); + delete[]tmpByteStr; + pline.addVertex(vt); + nextEntLink = vt.nextEntLink; \ + prevEntLink = vt.prevEntLink; + ret = ret && ret2; + } + if (nextH == pline.lastEH) + nextH = 0; //redundant, but prevent read errors + else + nextH = nextEntLink; + } + } else {//2004+ + for (std::list::iterator it = pline.hadlesList.begin() ; it != pline.hadlesList.end(); ++it){ + duint32 nextH = *it; + mit = ObjectMap.find(nextH); + if (mit==ObjectMap.end()) { + DRW_DBG("\nWARNING: Entity of block not found\n"); + ret = false; + continue; + } else {//foud entity reads it + oc = mit->second; + ObjectMap.erase(mit); + DRW_DBG("\nPline vertex, parsing entity: "); DRW_DBGH(oc.handle); DRW_DBG(", pos: "); DRW_DBG(oc.loc); DRW_DBG("\n"); + DRW_Vertex vt; + dbuf->setPosition(oc.loc); + //RLZ: verify if pos is ok + int size = dbuf->getModularShort(); + if (version > DRW::AC1021) {//2010+ + bs = dbuf->getUModularChar(); + } + duint8 *tmpByteStr = new duint8[size]; + dbuf->getBytes(tmpByteStr, size); + dwgBuffer buff(tmpByteStr, size, &decoder); + dint16 oType = buff.getObjType(version); + buff.resetPosition(); + DRW_DBG(" object type= "); DRW_DBG(oType); DRW_DBG("\n"); + ret2 = vt.parseDwg(version, &buff, bs, pline.basePoint.z); + delete[]tmpByteStr; + pline.addVertex(vt); + nextEntLink = vt.nextEntLink; \ + prevEntLink = vt.prevEntLink; + ret = ret && ret2; + } + } + }//end 2004+ + DRW_DBG("\nRemoved SEQEND entity: "); DRW_DBGH(pline.seqEndH.ref);DRW_DBG("\n"); + ObjectMap.erase(pline.seqEndH.ref); + + return ret; +} + +bool dwgReader::readDwgEntities(DRW_Interface& intfa, dwgBuffer *dbuf){ + bool ret = true; + bool ret2 = true; + + DRW_DBG("\nobject map total size= "); DRW_DBG(ObjectMap.size()); + std::map::iterator itB=ObjectMap.begin(); + std::map::iterator itE=ObjectMap.end(); + while (itB != itE){ + ret2 = readDwgEntity(dbuf, itB->second, intfa); + ObjectMap.erase(itB); + itB=ObjectMap.begin(); + if (ret) + ret = ret2; + } + return ret; +} + +/** + * Reads a dwg drawing entity (dwg object entity) given its offset in the file + */ +bool dwgReader::readDwgEntity(dwgBuffer *dbuf, objHandle& obj, DRW_Interface& intfa){ + bool ret = true; + duint32 bs = 0; + +#define ENTRY_PARSE(e) \ + ret = e.parseDwg(version, &buff, bs); \ + parseAttribs(&e); \ + nextEntLink = e.nextEntLink; \ + prevEntLink = e.prevEntLink; + + nextEntLink = prevEntLink = 0;// set to 0 to skip unimplemented entities + dbuf->setPosition(obj.loc); + //verify if position is ok: + if (!dbuf->isGood()){ + DRW_DBG(" Warning: readDwgEntity, bad location\n"); + return false; + } + int size = dbuf->getModularShort(); + if (version > DRW::AC1021) {//2010+ + bs = dbuf->getUModularChar(); + } + duint8 *tmpByteStr = new duint8[size]; + dbuf->getBytes(tmpByteStr, size); + //verify if getBytes is ok: + if (!dbuf->isGood()){ + DRW_DBG(" Warning: readDwgEntity, bad size\n"); + delete[]tmpByteStr; + return false; + } + dwgBuffer buff(tmpByteStr, size, &decoder); + dint16 oType = buff.getObjType(version); + buff.resetPosition(); + + if (oType > 499){ + std::map::iterator it = classesmap.find(oType); + if (it == classesmap.end()){//fail, not found in classes set error + DRW_DBG("Class "); DRW_DBG(oType);DRW_DBG("not found, handle: "); DRW_DBG(obj.handle); DRW_DBG("\n"); + delete[]tmpByteStr; + return false; + } else { + DRW_Class *cl = it->second; + if (cl->dwgType != 0) + oType = cl->dwgType; + } + } + + obj.type = oType; + switch (oType){ + case 17: { + DRW_Arc e; + ENTRY_PARSE(e) + intfa.addArc(e); + break; } + case 18: { + DRW_Circle e; + ENTRY_PARSE(e) + intfa.addCircle(e); + break; } + case 19:{ + DRW_Line e; + ENTRY_PARSE(e) + intfa.addLine(e); + break;} + case 27: { + DRW_Point e; + ENTRY_PARSE(e) + intfa.addPoint(e); + break; } + case 35: { + DRW_Ellipse e; + ENTRY_PARSE(e) + intfa.addEllipse(e); + break; } + case 7: + case 8: {//minsert = 8 + DRW_Insert e; + ENTRY_PARSE(e) + e.name = findTableName(DRW::BLOCK_RECORD, e.blockRecH.ref);//RLZ: find as block or blockrecord (ps & ps0) + intfa.addInsert(e); + break; } + case 77: { + DRW_LWPolyline e; + ENTRY_PARSE(e) + intfa.addLWPolyline(e); + break; } + case 1: { + DRW_Text e; + ENTRY_PARSE(e) + e.style = findTableName(DRW::STYLE, e.styleH.ref); + intfa.addText(e); + break; } + case 44: { + DRW_MText e; + ENTRY_PARSE(e) + e.style = findTableName(DRW::STYLE, e.styleH.ref); + intfa.addMText(e); + break; } + case 28: { + DRW_3Dface e; + ENTRY_PARSE(e) + intfa.add3dFace(e); + break; } + case 20: { + DRW_DimOrdinate e; + ENTRY_PARSE(e) + e.style = findTableName(DRW::DIMSTYLE, e.dimStyleH.ref); + intfa.addDimOrdinate(&e); + break; } + case 21: { + DRW_DimLinear e; + ENTRY_PARSE(e) + e.style = findTableName(DRW::DIMSTYLE, e.dimStyleH.ref); + intfa.addDimLinear(&e); + break; } + case 22: { + DRW_DimAligned e; + ENTRY_PARSE(e) + e.style = findTableName(DRW::DIMSTYLE, e.dimStyleH.ref); + intfa.addDimAlign(&e); + break; } + case 23: { + DRW_DimAngular3p e; + ENTRY_PARSE(e) + e.style = findTableName(DRW::DIMSTYLE, e.dimStyleH.ref); + intfa.addDimAngular3P(&e); + break; } + case 24: { + DRW_DimAngular e; + ENTRY_PARSE(e) + e.style = findTableName(DRW::DIMSTYLE, e.dimStyleH.ref); + intfa.addDimAngular(&e); + break; } + case 25: { + DRW_DimRadial e; + ENTRY_PARSE(e) + e.style = findTableName(DRW::DIMSTYLE, e.dimStyleH.ref); + intfa.addDimRadial(&e); + break; } + case 26: { + DRW_DimDiametric e; + ENTRY_PARSE(e) + e.style = findTableName(DRW::DIMSTYLE, e.dimStyleH.ref); + intfa.addDimDiametric(&e); + break; } + case 45: { + DRW_Leader e; + ENTRY_PARSE(e) + e.style = findTableName(DRW::DIMSTYLE, e.dimStyleH.ref); + intfa.addLeader(&e); + break; } + case 31: { + DRW_Solid e; + ENTRY_PARSE(e) + intfa.addSolid(e); + break; } + case 78: { + DRW_Hatch e; + ENTRY_PARSE(e) + intfa.addHatch(&e); + break; } + case 32: { + DRW_Trace e; + ENTRY_PARSE(e) + intfa.addTrace(e); + break; } + case 34: { + DRW_Viewport e; + ENTRY_PARSE(e) + intfa.addViewport(e); + break; } + case 36: { + DRW_Spline e; + ENTRY_PARSE(e) + intfa.addSpline(&e); + break; } + case 40: { + DRW_Ray e; + ENTRY_PARSE(e) + intfa.addRay(e); + break; } + case 15: // pline 2D + case 16: // pline 3D + case 29: { // pline PFACE + DRW_Polyline e; + ENTRY_PARSE(e) + readPlineVertex(e, dbuf); + intfa.addPolyline(e); + break; } +// case 30: { +// DRW_Polyline e;// MESH (not pline) +// ENTRY_PARSE(e) +// intfa.addRay(e); +// break; } + case 41: { + DRW_Xline e; + ENTRY_PARSE(e) + intfa.addXline(e); + break; } + case 101: { + DRW_Image e; + ENTRY_PARSE(e) + intfa.addImage(&e); + break; } + + default: + //not supported or are object add to remaining map + objObjectMap[obj.handle]= obj; + break; + } + if (!ret){ + DRW_DBG("Warning: Entity type "); DRW_DBG(oType);DRW_DBG("has failed, handle: "); DRW_DBG(obj.handle); DRW_DBG("\n"); + } + delete[]tmpByteStr; + return ret; +} + +bool dwgReader::readDwgObjects(DRW_Interface& intfa, dwgBuffer *dbuf){ + bool ret = true; + bool ret2 = true; + + duint32 i=0; + DRW_DBG("\nentities map total size= "); DRW_DBG(ObjectMap.size()); + DRW_DBG("\nobjects map total size= "); DRW_DBG(objObjectMap.size()); + std::map::iterator itB=objObjectMap.begin(); + std::map::iterator itE=objObjectMap.end(); + while (itB != itE){ + ret2 = readDwgObject(dbuf, itB->second, intfa); + objObjectMap.erase(itB); + itB=objObjectMap.begin(); + if (ret) + ret = ret2; + } + if (DRW_DBGGL == DRW_dbg::DEBUG) { + for (std::map::iterator it=remainingMap.begin(); it != remainingMap.end(); ++it){ + DRW_DBG("\nnum.# "); DRW_DBG(i++); DRW_DBG(" Remaining object Handle, loc, type= "); DRW_DBG(it->first); + DRW_DBG(" "); DRW_DBG(it->second.loc); DRW_DBG(" "); DRW_DBG(it->second.type); + } + DRW_DBG("\n"); + } + return ret; +} + +/** + * Reads a dwg drawing object (dwg object object) given its offset in the file + */ +bool dwgReader::readDwgObject(dwgBuffer *dbuf, objHandle& obj, DRW_Interface& intfa){ + bool ret = true; + duint32 bs = 0; + + dbuf->setPosition(obj.loc); + //verify if position is ok: + if (!dbuf->isGood()){ + DRW_DBG(" Warning: readDwgObject, bad location\n"); + return false; + } + int size = dbuf->getModularShort(); + if (version > DRW::AC1021) {//2010+ + bs = dbuf->getUModularChar(); + } + duint8 *tmpByteStr = new duint8[size]; + dbuf->getBytes(tmpByteStr, size); + //verify if getBytes is ok: + if (!dbuf->isGood()){ + DRW_DBG(" Warning: readDwgObject, bad size\n"); + delete[]tmpByteStr; + return false; + } + dwgBuffer buff(tmpByteStr, size, &decoder); + //oType are set parsing entities + dint16 oType = obj.type; + + switch (oType){ + case 102: { + DRW_ImageDef e; + ret = e.parseDwg(version, &buff, bs); + intfa.linkImage(&e); + break; } + default: + //not supported object or entity add to remaining map for debug + remainingMap[obj.handle]= obj; + break; + } + if (!ret){ + DRW_DBG("Warning: Object type "); DRW_DBG(oType);DRW_DBG("has failed, handle: "); DRW_DBG(obj.handle); DRW_DBG("\n"); + } + delete[]tmpByteStr; + return ret; +} + + + +bool DRW_ObjControl::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){ +int unkData=0; + bool ret = DRW_TableEntry::parseDwg(version, buf, NULL, bs); + DRW_DBG("\n***************************** parsing object control entry *********************************************\n"); + if (!ret) + return ret; + //last parsed is: XDic Missing Flag 2004+ + int numEntries = buf->getBitLong(); + DRW_DBG(" num entries: "); DRW_DBG(numEntries); DRW_DBG("\n"); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + +// if (oType == 68 && version== DRW::AC1015){//V2000 dimstyle seems have one unknown byte hard handle counter?? + if (oType == 68 && version > DRW::AC1014){//dimstyle seems have one unknown byte hard handle counter?? + unkData = buf->getRawChar8(); + DRW_DBG(" unknown v2000 byte: "); DRW_DBG( unkData); DRW_DBG("\n"); + } + if (version > DRW::AC1018){//from v2007+ have a bit for strings follows (ObjControl do not have) + int stringBit = buf->getBit(); + DRW_DBG(" string bit for v2007+: "); DRW_DBG( stringBit); DRW_DBG("\n"); + } + + dwgHandle objectH = buf->getHandle(); + DRW_DBG(" NULL Handle: "); DRW_DBGHL(objectH.code, objectH.size, objectH.ref); DRW_DBG("\n"); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + +// if (oType == 56 && version== DRW::AC1015){//linetype in 2004 seems not have XDicObjH or NULL handle + if (xDictFlag !=1){//linetype in 2004 seems not have XDicObjH or NULL handle + dwgHandle XDicObjH = buf->getHandle(); + DRW_DBG(" XDicObj control Handle: "); DRW_DBGHL(XDicObjH.code, XDicObjH.size, XDicObjH.ref); DRW_DBG("\n"); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + } +//add 2 for modelspace, paperspace blocks & bylayer, byblock linetypes + numEntries = ((oType == 48) || (oType == 56)) ? (numEntries +2) : numEntries; + + for (int i =0; i< numEntries; i++){ + objectH = buf->getOffsetHandle(handle); + if (objectH.ref != 0) //in vports R14 I found some NULL handles + hadlesList.push_back (objectH.ref); + DRW_DBG(" objectH Handle: "); DRW_DBGHL(objectH.code, objectH.size, objectH.ref); DRW_DBG("\n"); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + } + + for (int i =0; i< unkData; i++){ + objectH = buf->getOffsetHandle(handle); + DRW_DBG(" unknown Handle: "); DRW_DBGHL(objectH.code, objectH.size, objectH.ref); DRW_DBG("\n"); + DRW_DBG("Remaining bytes: "); DRW_DBG(buf->numRemainingBytes()); DRW_DBG("\n"); + } + return buf->isGood(); +} diff --git a/src/libs/vdxf/libdxfrw/intern/dwgreader.h b/src/libs/vdxf/libdxfrw/intern/dwgreader.h new file mode 100644 index 000000000..4e8893286 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/dwgreader.h @@ -0,0 +1,203 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#ifndef DWGREADER_H +#define DWGREADER_H + +#include +#include +#include "drw_textcodec.h" +#include "dwgutil.h" +#include "dwgbuffer.h" +#include "../libdwgr.h" + +class objHandle{ +public: + objHandle(){ handle = type = loc = 0; } + objHandle(duint32 t, duint32 h, duint32 l){ + type = t; + handle = h; + loc = l; + } + duint32 type; + duint32 handle; + duint32 loc; +}; + +//until 2000 = 2000- +//since 2004 except 2007 = 2004+ +// 2007 = 2007 +// pages of section +/* 2000-: No pages, only sections + * 2004+: Id, page number (index) + * size, size of page in file stream + * address, address in file stream + * dataSize, data size for this page + * startOffset, start offset for this page + * cSize, compresed size of data + * uSize, uncompresed size of data + * 2007: page Id, pageCount & pages + * size, size in file + * dataSize + * startOffset, start position in decompresed data stream + * cSize, compresed size of data + * uSize, uncompresed size of data + * address, address in file stream + * */ +class dwgPageInfo { +public: + dwgPageInfo(){} + dwgPageInfo(duint64 i, duint64 ad, duint32 sz){ + Id=i; address=ad; size=sz; + } + ~dwgPageInfo(){} + duint64 Id; + duint64 address; //in file stream, for rd18, rd21 + duint64 size; //in file stream, for rd18, rd21 + duint64 dataSize; //for rd18, rd21 + duint32 startOffset; //for rd18, rd21 + duint64 cSize; //compresed page size, for rd21 + duint64 uSize; //uncompresed page size, for rd21 +}; + +// sections of file +/* 2000-: No pages, only section Id, size & address in file + * 2004+: Id, Section Id + * size, total size of uncompresed data + * pageCount & pages, number of pages in section + * maxSize, max decompressed Size per page + * compresed, (1 = no, 2 = yes, normally 2) + * encrypted, (0 = no, 1 = yes, 2 = unknown) + * name, read & stored but not used + * 2007: same as 2004+ except encoding, saved in compresed field + * */ +class dwgSectionInfo { +public: + dwgSectionInfo(){ + compresed = 1;//1=no, 2=yes + encrypted = 0;//??? + pageCount = 0; + Id=-1; + } + ~dwgSectionInfo(){} + dint32 Id; //section Id, 2000- rd15 rd18 + std::string name; //section name rd18 + duint32 compresed;//is compresed? 1=no, 2=yes rd18, rd21(encoding) + duint32 encrypted;//encrypted (doc: 0=no, 1=yes, 2=unkn) on read: objects 0 and encrypted yes rd18 + std::mappages;//index, size, offset + duint64 size;//size of section, 2000- rd15, rd18, rd21 (data size) + duint64 pageCount; //number of pages (dwgPageInfo) in section rd18, rd21 + duint64 maxSize; //max decompressed size (needed??) rd18 rd21 + duint64 address; //address (seek) , 2000- +}; + + +//! Class to handle dwg obj control entries +/*! +* Class to handle dwg obj control entries +* @author Rallaz +*/ +class DRW_ObjControl : public DRW_TableEntry { +public: + DRW_ObjControl() { reset();} + + void reset(){ + } + bool parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs=0); + std::listhadlesList; +}; + + +class dwgReader { + friend class dwgR; +public: + dwgReader(std::istream *stream, dwgR *p){ + fileBuf = new dwgBuffer(stream); + parent = p; + decoder.setVersion(DRW::AC1021, false);//default 2007 in utf8(no convert) + decoder.setCodePage("UTF-16", false); +// blockCtrl=0; //RLZ: temporary +// blockCtrl=layerCtrl=styleCtrl=linetypeCtrl=viewCtrl=0; +// ucsCtrl=vportCtrl=appidCtrl=dimstyleCtrl=vpEntHeaderCtrl=0; + nextEntLink = prevEntLink = 0; + maintenanceVersion=0; + } + virtual ~dwgReader(); + +protected: + virtual bool readMetaData() = 0; + virtual bool readPreview(){return false;} + virtual bool readFileHeader() = 0; + virtual bool readDwgHeader(DRW_Header& hdr)=0; + virtual bool readDwgClasses() = 0; + virtual bool readDwgHandles() = 0; + virtual bool readDwgTables(DRW_Header& hdr)=0; + virtual bool readDwgBlocks(DRW_Interface& intfa) = 0; + virtual bool readDwgEntities(DRW_Interface& intfa) = 0; + virtual bool readDwgObjects(DRW_Interface& intfa) = 0; + + virtual bool readDwgEntity(dwgBuffer *dbuf, objHandle& obj, DRW_Interface& intfa); + bool readDwgObject(dwgBuffer *dbuf, objHandle& obj, DRW_Interface& intfa); + void parseAttribs(DRW_Entity* e); + std::string findTableName(DRW::TTYPE table, dint32 handle); + + void setCodePage(std::string *c){decoder.setCodePage(c, false);} + std::string getCodePage(){ return decoder.getCodePage();} + bool readDwgHeader(DRW_Header& hdr, dwgBuffer *buf, dwgBuffer *hBuf); + bool readDwgHandles(dwgBuffer *dbuf, duint32 offset, duint32 size); + bool readDwgTables(DRW_Header& hdr, dwgBuffer *dbuf); + bool checkSentinel(dwgBuffer *buf, enum secEnum::DWGSection, bool start); + + bool readDwgBlocks(DRW_Interface& intfa, dwgBuffer *dbuf); + bool readDwgEntities(DRW_Interface& intfa, dwgBuffer *dbuf); + bool readDwgObjects(DRW_Interface& intfa, dwgBuffer *dbuf); + bool readPlineVertex(DRW_Polyline& pline, dwgBuffer *dbuf); + +public: + std::mapObjectMap; + std::mapobjObjectMap; //stores the ojects & entities not read in readDwgEntities + std::mapremainingMap; //stores the ojects & entities not read in all proces, for debug only + std::map ltypemap; + std::map layermap; + std::map blockmap; + std::map stylemap; + std::map dimstylemap; + std::map vportmap; + std::map blockRecordmap; + std::map appIdmap; +// duint32 currBlock; + duint8 maintenanceVersion; + +protected: + dwgBuffer *fileBuf; + dwgR *parent; + DRW::Version version; + +//seeker (position) for the beginning sentinel of the image data (R13 to R15) + duint32 previewImagePos; + +//sections map + std::mapsections; + std::map classesmap; + +protected: + DRW_TextCodec decoder; + +protected: +// duint32 blockCtrl; + duint32 nextEntLink; + duint32 prevEntLink; +}; + + + +#endif // DWGREADER_H diff --git a/src/libs/vdxf/libdxfrw/intern/dwgreader15.cpp b/src/libs/vdxf/libdxfrw/intern/dwgreader15.cpp new file mode 100644 index 000000000..41bbe9b1d --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/dwgreader15.cpp @@ -0,0 +1,198 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#include +#include +#include +#include +#include +#include "drw_dbg.h" +#include "dwgreader15.h" +#include "drw_textcodec.h" +#include "../libdwgr.h" + +bool dwgReader15::readMetaData() { + version = parent->getVersion(); + decoder.setVersion(version, false); + DRW_DBG("dwgReader15::readMetaData\n"); + if (! fileBuf->setPosition(13)) + return false; + previewImagePos = fileBuf->getRawLong32(); + DRW_DBG("previewImagePos (seekerImageData) = "); DRW_DBG(previewImagePos); + /* MEASUREMENT system variable 2 bytes*/ + duint16 meas = fileBuf->getRawShort16(); + DRW_DBG("\nMEASUREMENT (0 = English, 1 = Metric)= "); DRW_DBG(meas); + duint16 cp = fileBuf->getRawShort16(); + DRW_DBG("\ncodepage= "); DRW_DBG(cp); DRW_DBG("\n"); + if (cp == 29) //TODO RLZ: locate wath code page and correct this + decoder.setCodePage("ANSI_1252", false); + if (cp == 30) + decoder.setCodePage("ANSI_1252", false); + return true; +} + +bool dwgReader15::readFileHeader() { + bool ret = true; + DRW_DBG("dwgReader15::readFileHeader\n"); + if (! fileBuf->setPosition(21)) + return false; + duint32 count = fileBuf->getRawLong32(); + DRW_DBG("count records= "); DRW_DBG(count); DRW_DBG("\n"); + + for (unsigned int i = 0; i < count; i++) { + duint8 rec = fileBuf->getRawChar8(); + duint32 address = fileBuf->getRawLong32(); + duint32 size = fileBuf->getRawLong32(); + dwgSectionInfo si; + si.Id = rec; + si.size = size; + si.address = address; + if (rec == 0) { + DRW_DBG("\nSection HEADERS address= "); + DRW_DBG(address); DRW_DBG(" size= "); DRW_DBG(size); + sections[secEnum::HEADER] = si; + } else if (rec == 1) { + DRW_DBG("\nSection CLASSES address= "); + DRW_DBG(address); DRW_DBG(" size= "); DRW_DBG(size); + sections[secEnum::CLASSES] = si; + } else if (rec == 2) { + DRW_DBG("\nSection OBJECTS (handles) address= "); + DRW_DBG(address); DRW_DBG(" size= "); DRW_DBG(size); + sections[secEnum::HANDLES] = si; + } else if (rec == 3) { + DRW_DBG("\nSection UNKNOWN address= "); + DRW_DBG(address); DRW_DBG(" size= "); DRW_DBG(size); + sections[secEnum::UNKNOWNS] = si; + } else if (rec == 4) { + DRW_DBG("\nSection R14DATA (AcDb:Template) address= "); + DRW_DBG(address); DRW_DBG(" size= "); DRW_DBG(size); + sections[secEnum::TEMPLATE] = si; + } else if (rec == 5) { + DRW_DBG("\nSection R14REC5 (AcDb:AuxHeader) address= "); + DRW_DBG(address); DRW_DBG(" size= "); DRW_DBG(size); + sections[secEnum::AUXHEADER] = si; + } else { + std::cerr << "\nUnsupported section number\n"; + } + } + if (! fileBuf->isGood()) + return false; + DRW_DBG("\nposition after read section locator records= "); DRW_DBG(fileBuf->getPosition()); + DRW_DBG(", bit are= "); DRW_DBG(fileBuf->getBitPos()); + duint32 ckcrc = fileBuf->crc8(0,0,fileBuf->getPosition()); + DRW_DBG("\nfile header crc8 0 result= "); DRW_DBG(ckcrc); + switch (count){ + case 3: + ckcrc = ckcrc ^ 0xA598; + break; + case 4: + ckcrc = ckcrc ^ 0x8101; + break; + case 5: + ckcrc = ckcrc ^ 0x3CC4; + break; + case 6: + ckcrc = ckcrc ^ 0x8461; + } + DRW_DBG("\nfile header crc8 xor result= "); DRW_DBG(ckcrc); + DRW_DBG("\nfile header CRC= "); DRW_DBG(fileBuf->getRawShort16()); + DRW_DBG("\nfile header sentinel= "); + checkSentinel(fileBuf, secEnum::FILEHEADER, false); + + DRW_DBG("\nposition after read file header sentinel= "); DRW_DBG(fileBuf->getPosition()); + DRW_DBG(", bit are= "); DRW_DBG(fileBuf->getBitPos()); + + DRW_DBG("\ndwgReader15::readFileHeader END\n"); + return ret; +} + +bool dwgReader15::readDwgHeader(DRW_Header& hdr){ + DRW_DBG("dwgReader15::readDwgHeader\n"); + dwgSectionInfo si = sections[secEnum::HEADER]; + if (si.Id<0)//not found, ends + return false; + if (!fileBuf->setPosition(si.address)) + return false; + duint8 *tmpByteStr = new duint8[si.size]; + fileBuf->getBytes(tmpByteStr, si.size); + dwgBuffer buff(tmpByteStr, si.size, &decoder); + DRW_DBG("Header section sentinel= "); + checkSentinel(&buff, secEnum::HEADER, true); + bool ret = dwgReader::readDwgHeader(hdr, &buff, &buff); + delete[]tmpByteStr; + return ret; +} + + +bool dwgReader15::readDwgClasses(){ + DRW_DBG("\ndwgReader15::readDwgClasses\n"); + dwgSectionInfo si = sections[secEnum::CLASSES]; + if (si.Id<0)//not found, ends + return false; + if (!fileBuf->setPosition(si.address)) + return false; + + DRW_DBG("classes section sentinel= "); + checkSentinel(fileBuf, secEnum::CLASSES, true); + + duint32 size = fileBuf->getRawLong32(); + if (size != (si.size - 38)) { + DRW_DBG("\nWARNING dwgReader15::readDwgClasses size are "); DRW_DBG(size); + DRW_DBG(" and secSize - 38 are "); DRW_DBG(si.size - 38); DRW_DBG("\n"); + } + duint8 *tmpByteStr = new duint8[size]; + fileBuf->getBytes(tmpByteStr, size); + dwgBuffer buff(tmpByteStr, size, &decoder); + size--; //reduce 1 byte instead of check pos + bitPos + while (size > buff.getPosition()) { + DRW_Class *cl = new DRW_Class(); + cl->parseDwg(version, &buff, &buff); + classesmap[cl->classNum] = cl; + } + DRW_DBG("\nCRC: "); DRW_DBGH(fileBuf->getRawShort16()); + DRW_DBG("\nclasses section end sentinel= "); + checkSentinel(fileBuf, secEnum::CLASSES, false); + bool ret = buff.isGood(); + delete[]tmpByteStr; + return ret; +} + +bool dwgReader15::readDwgHandles() { + DRW_DBG("\ndwgReader15::readDwgHandles\n"); + dwgSectionInfo si = sections[secEnum::HANDLES]; + if (si.Id<0)//not found, ends + return false; + + bool ret = dwgReader::readDwgHandles(fileBuf, si.address, si.size); + return ret; +} + +/*********** objects ************************/ +/** + * Reads all the object referenced in the object map section of the DWG file + * (using their object file offsets) + */ +bool dwgReader15::readDwgTables(DRW_Header& hdr) { + bool ret = dwgReader::readDwgTables(hdr, fileBuf); + + return ret; +} + +/** + * Reads all the object referenced in the object map section of the DWG file + * (using their object file offsets) + */ +bool dwgReader15::readDwgBlocks(DRW_Interface& intfa) { + bool ret = true; + ret = dwgReader::readDwgBlocks(intfa, fileBuf); + return ret; +} diff --git a/src/libs/vdxf/libdxfrw/intern/dwgreader15.h b/src/libs/vdxf/libdxfrw/intern/dwgreader15.h new file mode 100644 index 000000000..e3a1f97b7 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/dwgreader15.h @@ -0,0 +1,47 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#ifndef DWGREADER15_H +#define DWGREADER15_H + +#include +#include +#include "drw_textcodec.h" +#include "dwgbuffer.h" +#include "dwgreader.h" + +class dwgReader15 : public dwgReader { +public: + dwgReader15(std::istream *stream, dwgR *p):dwgReader(stream, p){ } + virtual ~dwgReader15() {} + bool readMetaData(); + bool readFileHeader(); + bool readDwgHeader(DRW_Header& hdr); + bool readDwgClasses(); + bool readDwgHandles(); + bool readDwgTables(DRW_Header& hdr); + bool readDwgBlocks(DRW_Interface& intfa); + bool readDwgEntities(DRW_Interface& intfa){ + bool ret = true; + ret = dwgReader::readDwgEntities(intfa, fileBuf); + return ret; + } + bool readDwgObjects(DRW_Interface& intfa){ + bool ret = true; + ret = dwgReader::readDwgObjects(intfa, fileBuf); + return ret; + } +// bool readDwgEntity(objHandle& obj, DRW_Interface& intfa); +}; + + +#endif // DWGREADER15_H diff --git a/src/libs/vdxf/libdxfrw/intern/dwgreader18.cpp b/src/libs/vdxf/libdxfrw/intern/dwgreader18.cpp new file mode 100644 index 000000000..d91b92e50 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/dwgreader18.cpp @@ -0,0 +1,594 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#include +#include +#include +#include +#include +#include "drw_dbg.h" +#include "dwgreader18.h" +#include "dwgutil.h" +#include "drw_textcodec.h" +#include "../libdwgr.h" + +void dwgReader18::genMagicNumber(){ + int size =0x114; + duint8 *tmpMagicStr = new duint8[size]; + duint8 *p = tmpMagicStr; + int rSeed =1; + while (size--) { + rSeed *= 0x343fd; + rSeed += 0x269ec3; + *p++ = static_cast(rSeed >> 0x10); + } + int j = 0; + size =0x114; + for (int i=0; i< size;i++) { + DRW_DBGH(tmpMagicStr[i]); + if (j == 15) { + DRW_DBG("\n"); + j = 0; + } else { + DRW_DBG(", "); + j++; + } + } + delete[]tmpMagicStr; +} + +duint32 dwgReader18::checksum(duint32 seed, duint8* data, duint32 sz){ + duint32 size = sz; + duint32 sum1 = seed & 0xffff; + duint32 sum2 = seed >> 0x10; + while (size != 0) { +// duint32 chunkSize = min(0x15b0, size); + duint32 chunkSize = 0x15b0 < size? 0x15b0:size; + size -= chunkSize; + for (duint32 i = 0; i < chunkSize; i++) { + sum1 += *data++; + sum2 += sum1; + } + sum1 %= 0xFFF1; + sum2 %= 0xFFF1; + } + return (sum2 << 0x10) | (sum1 & 0xffff); +} + + //called: Section page map: 0x41630e3b +void dwgReader18::parseSysPage(duint8 *decompSec, duint32 decompSize){ + DRW_DBG("\nparseSysPage:\n "); + duint32 compSize = fileBuf->getRawLong32(); + DRW_DBG("Compressed size= "); DRW_DBG(compSize); DRW_DBG(", "); DRW_DBGH(compSize); + DRW_DBG("\nCompression type= "); DRW_DBGH(fileBuf->getRawLong32()); + DRW_DBG("\nSection page checksum= "); DRW_DBGH(fileBuf->getRawLong32()); DRW_DBG("\n"); + + duint8 hdrData[20]; + fileBuf->moveBitPos(-160); + fileBuf->getBytes(hdrData, 20); + for (duint8 i= 16; i<20; ++i) + hdrData[i]=0; + duint32 calcsH = checksum(0, hdrData, 20); + DRW_DBG("Calc hdr checksum= "); DRW_DBGH(calcsH); + duint8 *tmpCompSec = new duint8[compSize]; + fileBuf->getBytes(tmpCompSec, compSize); + duint32 calcsD = checksum(calcsH, tmpCompSec, compSize); + DRW_DBG("\nCalc data checksum= "); DRW_DBGH(calcsD); DRW_DBG("\n"); + +#ifdef DRW_DBG_DUMP + for (unsigned int i=0, j=0; i< compSize;i++) { + DRW_DBGH( (unsigned char)compSec[i]); + if (j == 7) { DRW_DBG("\n"); j = 0; + } else { DRW_DBG(", "); j++; } + } DRW_DBG("\n"); +#endif + DRW_DBG("decompresing "); DRW_DBG(compSize); DRW_DBG(" bytes in "); DRW_DBG(decompSize); DRW_DBG(" bytes\n"); + dwgCompressor comp; + comp.decompress18(tmpCompSec, decompSec, compSize, decompSize); +#ifdef DRW_DBG_DUMP + for (unsigned int i=0, j=0; i< decompSize;i++) { + DRW_DBGH( decompSec[i]); + if (j == 7) { DRW_DBG("\n"); j = 0; + } else { DRW_DBG(", "); j++; } + } DRW_DBG("\n"); +#endif + delete[]tmpCompSec; +} + + //called ???: Section map: 0x4163003b +bool dwgReader18::parseDataPage(dwgSectionInfo si/*, duint8 *dData*/){ + DRW_DBG("\nparseDataPage\n "); + objData = new duint8 [si.pageCount * si.maxSize]; + + for (std::map::iterator it=si.pages.begin(); it!=si.pages.end(); ++it){ + dwgPageInfo pi = it->second; + if (!fileBuf->setPosition(pi.address)) + return false; + //decript section header + duint8 hdrData[32]; + fileBuf->getBytes(hdrData, 32); + dwgCompressor::decrypt18Hdr(hdrData, 32, pi.address); + DRW_DBG("Section "); DRW_DBG(si.name); DRW_DBG(" page header=\n"); + for (unsigned int i=0, j=0; i< 32;i++) { + DRW_DBGH( (unsigned char)hdrData[i]); + if (j == 7) { + DRW_DBG("\n"); + j = 0; + } else { + DRW_DBG(", "); + j++; + } + } DRW_DBG("\n"); + + DRW_DBG("\n Page number= "); DRW_DBGH(pi.Id); + DRW_DBG("\n size in file= "); DRW_DBGH(pi.size); + DRW_DBG("\n address in file= "); DRW_DBGH(pi.address); + DRW_DBG("\n Data size= "); DRW_DBGH(pi.dataSize); + DRW_DBG("\n Start offset= "); DRW_DBGH(pi.startOffset); DRW_DBG("\n"); + dwgBuffer bufHdr(hdrData, 32, &decoder); + DRW_DBG(" section page type= "); DRW_DBGH(bufHdr.getRawLong32()); + DRW_DBG("\n section number= "); DRW_DBGH(bufHdr.getRawLong32()); + pi.cSize = bufHdr.getRawLong32(); + DRW_DBG("\n data size (compressed)= "); DRW_DBGH(pi.cSize); DRW_DBG(" dec "); DRW_DBG(pi.cSize); + pi.uSize = bufHdr.getRawLong32(); + DRW_DBG("\n page size (decompressed)= "); DRW_DBGH(pi.uSize); DRW_DBG(" dec "); DRW_DBG(pi.uSize); + DRW_DBG("\n start offset (in decompressed buffer)= "); DRW_DBGH(bufHdr.getRawLong32()); + DRW_DBG("\n unknown= "); DRW_DBGH(bufHdr.getRawLong32()); + DRW_DBG("\n header checksum= "); DRW_DBGH(bufHdr.getRawLong32()); + DRW_DBG("\n data checksum= "); DRW_DBGH(bufHdr.getRawLong32()); DRW_DBG("\n"); + + //get compresed data + duint8 *cData = new duint8[pi.cSize]; + if (!fileBuf->setPosition(pi.address+32)) + return false; + fileBuf->getBytes(cData, pi.cSize); + + //calculate checksum + duint32 calcsD = checksum(0, cData, pi.cSize); + for (duint8 i= 24; i<28; ++i) + hdrData[i]=0; + duint32 calcsH = checksum(calcsD, hdrData, 32); + DRW_DBG("Calc header checksum= "); DRW_DBGH(calcsH); + DRW_DBG("\nCalc data checksum= "); DRW_DBGH(calcsD); DRW_DBG("\n"); + + duint8* oData = objData + pi.startOffset; + pi.uSize = si.maxSize; + DRW_DBG("decompresing "); DRW_DBG(pi.cSize); DRW_DBG(" bytes in "); DRW_DBG(pi.uSize); DRW_DBG(" bytes\n"); + dwgCompressor comp; + comp.decompress18(cData, oData, pi.cSize, pi.uSize); + delete[]cData; + } + return true; +} + +bool dwgReader18::readMetaData() { + version = parent->getVersion(); + decoder.setVersion(version, false); + DRW_DBG("dwgReader18::readMetaData\n"); + if (! fileBuf->setPosition(11)) + return false; + maintenanceVersion = fileBuf->getRawChar8(); + DRW_DBG("maintenance verion= "); DRW_DBGH(maintenanceVersion); + DRW_DBG("\nbyte at 0x0C= "); DRW_DBGH(fileBuf->getRawChar8()); + previewImagePos = fileBuf->getRawLong32(); //+ page header size (0x20). + DRW_DBG("\npreviewImagePos (seekerImageData) = "); DRW_DBG(previewImagePos); + DRW_DBG("\napp Dwg version= "); DRW_DBGH(fileBuf->getRawChar8()); DRW_DBG(", "); + DRW_DBG("\napp maintenance version= "); DRW_DBGH(fileBuf->getRawChar8()); + duint16 cp = fileBuf->getRawShort16(); + DRW_DBG("\ncodepage= "); DRW_DBG(cp); + if (cp == 30) + decoder.setCodePage("ANSI_1252", false); + DRW_DBG("\n3 0x00 bytes(seems 0x00, appDwgV & appMaintV) = "); DRW_DBGH(fileBuf->getRawChar8()); DRW_DBG(", "); + DRW_DBGH(fileBuf->getRawChar8()); DRW_DBG(", "); DRW_DBGH(fileBuf->getRawChar8()); + securityFlags = fileBuf->getRawLong32(); + DRW_DBG("\nsecurity flags= "); DRW_DBG(securityFlags); + // UNKNOWN SECTION 4 bytes + duint32 uk = fileBuf->getRawLong32(); + DRW_DBG("\nUNKNOWN SECTION ( 4 bytes) = "); DRW_DBG(uk); + duint32 sumInfoAddr = fileBuf->getRawLong32(); + DRW_DBG("\nsummary Info Address= "); DRW_DBG(sumInfoAddr); + duint32 vbaAdd = fileBuf->getRawLong32(); + DRW_DBG("\nVBA address= "); DRW_DBGH(vbaAdd); + DRW_DBG("\npos 0x28 are 0x00000080= "); DRW_DBGH(fileBuf->getRawLong32()); + DRW_DBG("\n"); + return true; +} + +bool dwgReader18::readFileHeader() { + + if (! fileBuf->setPosition(0x80)) + return false; + +// genMagicNumber(); DBG("\n"); DBG("\n"); + DRW_DBG("Encripted Header Data=\n"); + duint8 byteStr[0x6C]; + int size =0x6C; + for (int i=0, j=0; i< 0x6C;i++) { + duint8 ch = fileBuf->getRawChar8(); + DRW_DBGH(ch); + if (j == 15) { + DRW_DBG("\n"); + j = 0; + } else { + DRW_DBG(", "); + j++; + } + byteStr[i] = DRW_magicNum18[i] ^ ch; + } + DRW_DBG("\n"); + +// size =0x6C; + DRW_DBG("Decripted Header Data=\n"); + for (int i=0, j = 0; i< size;i++) { + DRW_DBGH( (unsigned char)byteStr[i]); + if (j == 15) { + DRW_DBG("\n"); + j = 0; + } else { + DRW_DBG(", "); + j++; + } + } + dwgBuffer buff(byteStr, 0x6C, &decoder); + std::string name = reinterpret_cast(byteStr); + DRW_DBG("\nFile ID string (AcFssFcAJMB)= "); DRW_DBG(name.c_str()); + //ID string + NULL = 12 + buff.setPosition(12); + DRW_DBG("\n0x00 long= "); DRW_DBGH(buff.getRawLong32()); + DRW_DBG("\n0x6c long= "); DRW_DBGH(buff.getRawLong32()); + DRW_DBG("\n0x04 long= "); DRW_DBGH(buff.getRawLong32()); + DRW_DBG("\nRoot tree node gap= "); DRW_DBGH(buff.getRawLong32()); + DRW_DBG("\nLowermost left tree node gap= "); DRW_DBGH(buff.getRawLong32()); + DRW_DBG("\nLowermost right tree node gap= "); DRW_DBGH(buff.getRawLong32()); + DRW_DBG("\nUnknown long (1)= "); DRW_DBGH(buff.getRawLong32()); + DRW_DBG("\nLast section page Id= "); DRW_DBGH(buff.getRawLong32()); + DRW_DBG("\nLast section page end address 64b= "); DRW_DBGH(buff.getRawLong64()); + DRW_DBG("\nStart of second header data address 64b= "); DRW_DBGH(buff.getRawLong64()); + DRW_DBG("\nGap amount= "); DRW_DBGH(buff.getRawLong32()); + DRW_DBG("\nSection page amount= "); DRW_DBGH(buff.getRawLong32()); + DRW_DBG("\n0x20 long= "); DRW_DBGH(buff.getRawLong32()); + DRW_DBG("\n0x80 long= "); DRW_DBGH(buff.getRawLong32()); + DRW_DBG("\n0x40 long= "); DRW_DBGH(buff.getRawLong32()); + dint32 secPageMapId = buff.getRawLong32(); + DRW_DBG("\nSection Page Map Id= "); DRW_DBGH(secPageMapId); + duint64 secPageMapAddr = buff.getRawLong64()+0x100; + DRW_DBG("\nSection Page Map address 64b= "); DRW_DBGH(secPageMapAddr); + DRW_DBG("\nSection Page Map address 64b dec= "); DRW_DBG(secPageMapAddr); + duint32 secMapId = buff.getRawLong32(); + DRW_DBG("\nSection Map Id= "); DRW_DBGH(secMapId); + DRW_DBG("\nSection page array size= "); DRW_DBGH(buff.getRawLong32()); + DRW_DBG("\nGap array size= "); DRW_DBGH(buff.getRawLong32()); + //TODO: verify CRC + DRW_DBG("\nCRC32= "); DRW_DBGH(buff.getRawLong32()); + for (duint8 i = 0x68; i < 0x6c; ++i) + byteStr[i] = '\0'; +// byteStr[i] = '\0'; + duint32 crcCalc = buff.crc32(0x00,0,0x6C); + DRW_DBG("\nCRC32 calculated= "); DRW_DBGH(crcCalc); + + DRW_DBG("\nEnd Encrypted Data. Reads 0x14 bytes, equal to magic number:\n"); + for (int i=0, j=0; i< 0x14;i++) { + DRW_DBG("magic num: "); DRW_DBGH( (unsigned char)DRW_magicNumEnd18[i]); + DRW_DBG(",read "); DRW_DBGH( (unsigned char)fileBuf->getRawChar8()); + if (j == 3) { + DRW_DBG("\n"); + j = 0; + } else { + DRW_DBG(", "); + j++; + } + } +// At this point are parsed the first 256 bytes + DRW_DBG("\nJump to Section Page Map address: "); DRW_DBGH(secPageMapAddr); + + if (! fileBuf->setPosition(secPageMapAddr)) + return false; + duint32 pageType = fileBuf->getRawLong32(); + DRW_DBG("\nSection page type= "); DRW_DBGH(pageType); + duint32 decompSize = fileBuf->getRawLong32(); + DRW_DBG("\nDecompressed size= "); DRW_DBG(decompSize); DRW_DBG(", "); DRW_DBGH(decompSize); + if (pageType != 0x41630e3b){ + //bad page type, ends + DRW_DBG("Warning, bad page type, was expected 0x41630e3b instead of"); DRW_DBGH(pageType); DRW_DBG("\n"); + return false; + } + duint8 *tmpDecompSec = new duint8[decompSize]; + parseSysPage(tmpDecompSec, decompSize); + +//parses "Section page map" decompresed data + dwgBuffer buff2(tmpDecompSec, decompSize, &decoder); + duint32 address = 0x100; + //stores temporaly info of all pages: + std::mapsectionPageMapTmp; + + for (unsigned int i = 0; i < decompSize;) { + dint32 id = buff2.getRawLong32();//RLZ bad can be +/- + duint32 size = buff2.getRawLong32(); + i += 8; + DRW_DBG("Page num= "); DRW_DBG(id); DRW_DBG(" size= "); DRW_DBGH(size); + DRW_DBG(" address= "); DRW_DBGH(address); DRW_DBG("\n"); + //TODO num can be negative indicating gap +// duint64 ind = id > 0 ? id : -id; + if (id < 0){ + DRW_DBG("Parent= "); DRW_DBG(buff2.getRawLong32()); + DRW_DBG("\nLeft= "); DRW_DBG(buff2.getRawLong32()); + DRW_DBG(", Right= "); DRW_DBG(buff2.getRawLong32()); + DRW_DBG(", 0x00= ");DRW_DBGH(buff2.getRawLong32()); DRW_DBG("\n"); + i += 16; + } + + sectionPageMapTmp[id] = dwgPageInfo(id, address, size); + address += size; + } + delete[]tmpDecompSec; + + DRW_DBG("\n*** dwgReader18: Processing Data Section Map ***\n"); + dwgPageInfo sectionMap = sectionPageMapTmp[secMapId]; + if (!fileBuf->setPosition(sectionMap.address)) + return false; + pageType = fileBuf->getRawLong32(); + DRW_DBG("\nSection page type= "); DRW_DBGH(pageType); + decompSize = fileBuf->getRawLong32(); + DRW_DBG("\nDecompressed size= "); DRW_DBG(decompSize); DRW_DBG(", "); DRW_DBGH(decompSize); + if (pageType != 0x4163003b){ + //bad page type, ends + DRW_DBG("Warning, bad page type, was expected 0x4163003b instead of"); DRW_DBGH(pageType); DRW_DBG("\n"); + return false; + } + tmpDecompSec = new duint8[decompSize]; + parseSysPage(tmpDecompSec, decompSize); + +//reads sections: + DRW_DBG("\n*** dwgReader18: reads sections:"); + dwgBuffer buff3(tmpDecompSec, decompSize, &decoder); + duint32 numDescriptions = buff3.getRawLong32(); + DRW_DBG("\nnumDescriptions (sections)= "); DRW_DBG(numDescriptions); + DRW_DBG("\n0x02 long= "); DRW_DBGH(buff3.getRawLong32()); + DRW_DBG("\n0x00007400 long= "); DRW_DBGH(buff3.getRawLong32()); + DRW_DBG("\n0x00 long= "); DRW_DBGH(buff3.getRawLong32()); + DRW_DBG("\nunknown long (numDescriptions?)= "); DRW_DBG(buff3.getRawLong32()); DRW_DBG("\n"); + + for (unsigned int i = 0; i < numDescriptions; i++) { + dwgSectionInfo secInfo; + secInfo.size = buff3.getRawLong64(); + DRW_DBG("\nSize of section= "); DRW_DBGH(secInfo.size); + secInfo.pageCount = buff3.getRawLong32(); + DRW_DBG("\nPage count= "); DRW_DBGH(secInfo.pageCount); + secInfo.maxSize = buff3.getRawLong32(); + DRW_DBG("\nMax Decompressed Size= "); DRW_DBGH(secInfo.maxSize); + DRW_DBG("\nunknown long= "); DRW_DBGH(buff3.getRawLong32()); + secInfo.compresed = buff3.getRawLong32(); + DRW_DBG("\nis Compressed? 1:no, 2:yes= "); DRW_DBGH(secInfo.compresed); + secInfo.Id = buff3.getRawLong32(); + DRW_DBG("\nSection Id= "); DRW_DBGH(secInfo.Id); + secInfo.encrypted = buff3.getRawLong32(); + //encrypted (doc: 0 no, 1 yes, 2 unkn) on read: objects 0 and encrypted yes + DRW_DBG("\nEncrypted= "); DRW_DBGH(secInfo.encrypted); + duint8 nameCStr[64]; + buff3.getBytes(nameCStr, 64); + secInfo.name = reinterpret_cast(nameCStr); + DRW_DBG("\nSection std::Name= "); DRW_DBG( secInfo.name.c_str() ); DRW_DBG("\n"); + for (unsigned int i = 0; i < secInfo.pageCount; i++){ + duint32 pn = buff3.getRawLong32(); + dwgPageInfo pi = sectionPageMapTmp[pn]; //get a copy + DRW_DBG(" reading pag num = "); DRW_DBGH(pn); + pi.dataSize = buff3.getRawLong32(); + pi.startOffset = buff3.getRawLong64(); + secInfo.pages[pn]= pi;//complete copy in secInfo + DRW_DBG("\n Page number= "); DRW_DBGH(secInfo.pages[pn].Id); + DRW_DBG("\n size in file= "); DRW_DBGH(secInfo.pages[pn].size); + DRW_DBG("\n address in file= "); DRW_DBGH(secInfo.pages[pn].address); + DRW_DBG("\n Data size= "); DRW_DBGH(secInfo.pages[pn].dataSize); + DRW_DBG("\n Start offset= "); DRW_DBGH(secInfo.pages[pn].startOffset); DRW_DBG("\n"); + } + //do not save empty section + if (!secInfo.name.empty()) { + DRW_DBG("Saved section Name= "); DRW_DBG( secInfo.name.c_str() ); DRW_DBG("\n"); + sections[secEnum::getEnum(secInfo.name)] = secInfo; + } + } + delete[]tmpDecompSec; + + if (! fileBuf->isGood()) + return false; + DRW_DBG("\ndwgReader18::readFileHeader END\n\n"); + return true; +} + +bool dwgReader18::readDwgHeader(DRW_Header& hdr){ + DRW_DBG("dwgReader18::readDwgHeader\n"); + dwgSectionInfo si = sections[secEnum::HEADER]; + if (si.Id<0)//not found, ends + return false; + bool ret = parseDataPage(si/*, objData*/); + //global store for uncompressed data of all pages + uncompSize=si.size; + if (ret) { + dwgBuffer dataBuf(objData, si.size, &decoder); + DRW_DBG("Header section sentinel= "); + checkSentinel(&dataBuf, secEnum::HEADER, true); + if (version == DRW::AC1018){ + ret = dwgReader::readDwgHeader(hdr, &dataBuf, &dataBuf); + } else { + dwgBuffer handleBuf(objData, si.size, &decoder); + ret = dwgReader::readDwgHeader(hdr, &dataBuf, &handleBuf); + } + } + //Cleanup: global store for uncompressed data of all pages + if (objData != NULL){ + delete[] objData; + objData = NULL; + } + return ret; +} + + +bool dwgReader18::readDwgClasses(){ + DRW_DBG("\ndwgReader18::readDwgClasses\n"); + dwgSectionInfo si = sections[secEnum::CLASSES]; + if (si.Id<0)//not found, ends + return false; + bool ret = parseDataPage(si/*, objData*/); + //global store for uncompressed data of all pages + uncompSize=si.size; + if (ret) { + + dwgBuffer dataBuf(objData, uncompSize, &decoder); + + DRW_DBG("classes section sentinel= "); + checkSentinel(&dataBuf, secEnum::CLASSES, true); + + duint32 size = dataBuf.getRawLong32(); + DRW_DBG("\ndata size in bytes "); DRW_DBG(size); + if (version > DRW::AC1021 && maintenanceVersion > 3) { //2010+ + duint32 hSize = dataBuf.getRawLong32(); + DRW_DBG("\n2010+ & MV> 3, higth 32b: "); DRW_DBG(hSize); + } + duint32 bitSize = 0; + if (version > DRW::AC1021) {//2007+ + bitSize = dataBuf.getRawLong32(); + DRW_DBG("\ntotal size in bits "); DRW_DBG(bitSize); +} + duint32 maxClassNum = dataBuf.getBitShort(); + DRW_DBG("\nMaximum class number "); DRW_DBG(maxClassNum); + DRW_DBG("\nRc 1 "); DRW_DBG(dataBuf.getRawChar8()); + DRW_DBG("\nRc 2 "); DRW_DBG(dataBuf.getRawChar8()); + DRW_DBG("\nBit "); DRW_DBG(dataBuf.getBit()); + + /*******************************/ + dwgBuffer *strBuf = &dataBuf; + dwgBuffer strBuff(objData, uncompSize, &decoder); + //prepare string stream for 2007+ + if (version > DRW::AC1021) {//2007+ + strBuf = &strBuff; + duint32 strStartPos = bitSize+191;//size in bits + 24 bytes (sn+size+hSize) - 1 bit (endbit) + DRW_DBG("\nstrStartPos: "); DRW_DBG(strStartPos); + strBuff.setPosition(strStartPos >> 3); + strBuff.setBitPos(strStartPos & 7); + DRW_DBG("\nclasses strings buff.getPosition: "); DRW_DBG(strBuff.getPosition()); + DRW_DBG("\nclasses strings buff.getBitPos: "); DRW_DBG(strBuff.getBitPos()); + DRW_DBG("\nendBit "); DRW_DBG(strBuff.getBit()); + strStartPos -= 16;//decrement 16 bits + DRW_DBG("\nstrStartPos: "); DRW_DBG(strStartPos); + strBuff.setPosition(strStartPos >> 3); + strBuff.setBitPos(strStartPos & 7); + DRW_DBG("\nclasses strings buff.getPosition: "); DRW_DBG(strBuff.getPosition()); + DRW_DBG("\nclasses strings buff.getBitPos: "); DRW_DBG(strBuff.getBitPos()); + duint32 strDataSize = strBuff.getRawShort16(); + DRW_DBG("\nstrDataSize: "); DRW_DBG(strDataSize); + if (strDataSize & 0x8000) { + strStartPos -= 16;//decrement 16 bits + strDataSize &= 0x7FFF; //strip 0x8000; + strBuff.setPosition(strStartPos >> 3); + strBuff.setBitPos(strStartPos & 7); + duint32 hiSize = strBuff.getRawShort16(); + strDataSize |= (hiSize << 15); + } + strStartPos -= strDataSize; + DRW_DBG("\nstrStartPos: "); DRW_DBG(strStartPos); + strBuff.setPosition(strStartPos >> 3); + strBuff.setBitPos(strStartPos & 7); + DRW_DBG("\nclasses strings buff.getPosition: "); DRW_DBG(strBuff.getPosition()); + DRW_DBG("\nclasses strings buff.getBitPos: "); DRW_DBG(strBuff.getBitPos()); + } + + /*******************************/ + + duint32 endDataPos = maxClassNum-499; + DRW_DBG("\nbuff.getPosition: "); DRW_DBG(dataBuf.getPosition()); + for (duint32 i= 0; iparseDwg(version, &dataBuf, strBuf); + classesmap[cl->classNum] = cl; + DRW_DBG("\nbuff.getPosition: "); DRW_DBG(dataBuf.getPosition()); + } + DRW_DBG("\nend classes data buff.getPosition: "); DRW_DBG(dataBuf.getPosition()); + DRW_DBG("\nend classes data buff.getBitPos: "); DRW_DBG(dataBuf.getBitPos()); + DRW_DBG("\nend classes strings buff.getPosition: "); DRW_DBG(strBuf->getPosition()); + DRW_DBG("\nend classes strings buff.getBitPos: "); DRW_DBG(strBuf->getBitPos()); + +/***************/ + + strBuf->setPosition(strBuf->getPosition()+1);//skip remaining bits + DRW_DBG("\nCRC: "); DRW_DBGH(strBuf->getRawShort16()); + if (version > DRW::AC1018){ + DRW_DBG("\nunknown CRC: "); DRW_DBGH(strBuf->getRawShort16()); + } + DRW_DBG("\nclasses section end sentinel= "); + checkSentinel(strBuf, secEnum::CLASSES, false); + + ret = strBuf->isGood(); + } + //Cleanup: global store for uncompressed data of all pages + if (objData != NULL){ + delete[] objData; + objData = NULL; + } + return ret; +} + + +/*********** objects map ************************/ +/** Note: object map are split in sections with max size 2035? + * heach section are 2 bytes size + data bytes + 2 bytes crc + * size value are data bytes + 2 and to calculate crc are used + * 2 bytes size + data bytes + * last section are 2 bytes size + 2 bytes crc (size value always 2) +**/ +bool dwgReader18::readDwgHandles() { + DRW_DBG("\ndwgReader18::readDwgHandles\n"); + dwgSectionInfo si = sections[secEnum::HANDLES]; + if (si.Id<0)//not found, ends + return false; + bool ret = parseDataPage(si); + //global store for uncompressed data of all pages + uncompSize=si.size; + if (ret) { + + dwgBuffer dataBuf(objData, uncompSize, &decoder); + + ret = dwgReader::readDwgHandles(&dataBuf, 0, si.size); + } + //Cleanup: global store for uncompressed data of all pages + if (objData != NULL){ + delete[] objData; + objData = NULL; + uncompSize = 0; + } + return ret; +} + + +/*********** objects ************************/ +/** + * Reads all the object referenced in the object map section of the DWG file + * (using their object file offsets) + */ +bool dwgReader18::readDwgTables(DRW_Header& hdr) { + DRW_DBG("\ndwgReader18::readDwgTables\n"); + dwgSectionInfo si = sections[secEnum::OBJECTS]; + + if (si.Id<0)//not found, ends + return false; + bool ret = parseDataPage(si/*, objData*/); + //global store for uncompressed data of all pages + uncompSize=si.size; + if (ret) { + + dwgBuffer dataBuf(objData, uncompSize, &decoder); + + ret = dwgReader::readDwgTables(hdr, &dataBuf); + + } + //Do not delete objData in this point, needed in the remaining code + return ret; +} diff --git a/src/libs/vdxf/libdxfrw/intern/dwgreader18.h b/src/libs/vdxf/libdxfrw/intern/dwgreader18.h new file mode 100644 index 000000000..f81409669 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/dwgreader18.h @@ -0,0 +1,99 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#ifndef DWGREADER18_H +#define DWGREADER18_H + +#include +#include +#include "dwgreader.h" +//#include "../drw_textcodec.h" +#include "dwgbuffer.h" + +static const int DRW_magicNum18[] = { + 0x29, 0x23, 0xbe, 0x84, 0xe1, 0x6c, 0xd6, 0xae, + 0x52, 0x90, 0x49, 0xf1, 0xf1, 0xbb, 0xe9, 0xeb, + 0xb3, 0xa6, 0xdb, 0x3c, 0x87, 0x0c, 0x3e, 0x99, + 0x24, 0x5e, 0x0d, 0x1c, 0x06, 0xb7, 0x47, 0xde, + 0xb3, 0x12, 0x4d, 0xc8, 0x43, 0xbb, 0x8b, 0xa6, + 0x1f, 0x03, 0x5a, 0x7d, 0x09, 0x38, 0x25, 0x1f, + 0x5d, 0xd4, 0xcb, 0xfc, 0x96, 0xf5, 0x45, 0x3b, + 0x13, 0x0d, 0x89, 0x0a, 0x1c, 0xdb, 0xae, 0x32, + 0x20, 0x9a, 0x50, 0xee, 0x40, 0x78, 0x36, 0xfd, + 0x12, 0x49, 0x32, 0xf6, 0x9e, 0x7d, 0x49, 0xdc, + 0xad, 0x4f, 0x14, 0xf2, 0x44, 0x40, 0x66, 0xd0, + 0x6b, 0xc4, 0x30, 0xb7, 0x32, 0x3b, 0xa1, 0x22, + 0xf6, 0x22, 0x91, 0x9d, 0xe1, 0x8b, 0x1f, 0xda, + 0xb0, 0xca, 0x99, 0x02 +}; + +static const int DRW_magicNumEnd18[] = { + 0xf8, 0x46, 0x6a, 0x04, 0x96, 0x73, 0x0e, 0xd9, + 0x16, 0x2f, 0x67, 0x68, 0xd4, 0xf7, 0x4a, 0x4a, + 0xd0, 0x57, 0x68, 0x76}; + +class dwgReader18 : public dwgReader { +public: + dwgReader18(std::istream *stream, dwgR *p):dwgReader(stream, p){ + objData = NULL; + } + virtual ~dwgReader18(){ + if (objData != NULL) + delete[] objData; + } + bool readMetaData(); + bool readFileHeader(); + bool readDwgHeader(DRW_Header& hdr); + bool readDwgClasses(); + bool readDwgHandles(); + bool readDwgTables(DRW_Header& hdr); + bool readDwgBlocks(DRW_Interface& intfa){ + bool ret = true; + dwgBuffer dataBuf(objData, uncompSize, &decoder); + ret = dwgReader::readDwgBlocks(intfa, &dataBuf); + return ret; + } + + virtual bool readDwgEntities(DRW_Interface& intfa){ + bool ret = true; + dwgBuffer dataBuf(objData, uncompSize, &decoder); + ret = dwgReader::readDwgEntities(intfa, &dataBuf); + return ret; + } + virtual bool readDwgObjects(DRW_Interface& intfa){ + bool ret = true; + dwgBuffer dataBuf(objData, uncompSize, &decoder); + ret = dwgReader::readDwgObjects(intfa, &dataBuf); + return ret; + } + +// bool readDwgEntity(objHandle& obj, DRW_Interface& intfa){ +// bool ret = true; +// return ret; +// } + +protected: + duint8 *objData; + duint64 uncompSize; + +private: + void genMagicNumber(); +// dwgBuffer* bufObj; + void parseSysPage(duint8 *decompSec, duint32 decompSize); //called: Section page map: 0x41630e3b + bool parseDataPage(dwgSectionInfo si/*, duint8 *dData*/); //called ???: Section map: 0x4163003b + duint32 checksum(duint32 seed, duint8* data, duint32 sz); + +private: +duint32 securityFlags; +}; + +#endif // DWGREADER18_H diff --git a/src/libs/vdxf/libdxfrw/intern/dwgreader21.cpp b/src/libs/vdxf/libdxfrw/intern/dwgreader21.cpp new file mode 100644 index 000000000..9d4f23c25 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/dwgreader21.cpp @@ -0,0 +1,487 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#include +#include +#include +#include +#include +#include "drw_dbg.h" +#include "dwgreader21.h" +#include "drw_textcodec.h" +#include "../libdwgr.h" + +bool dwgReader21::readMetaData() { + version = parent->getVersion(); + decoder.setVersion(version, false); + DRW_DBG("dwgReader21::readFileHeader()\n"); + DRW_DBG("dwgReader21::parsing metadata\n"); + if (! fileBuf->setPosition(11)) + return false; + maintenanceVersion = fileBuf->getRawChar8(); + DRW_DBG("maintenance verion= "); DRW_DBGH(maintenanceVersion); + DRW_DBG("\nbyte at 0x0C= "); DRW_DBG(fileBuf->getRawChar8()); + previewImagePos = fileBuf->getRawLong32(); + DRW_DBG("previewImagePos (seekerImageData) = "); DRW_DBG(previewImagePos); + DRW_DBG("\n\napp writer version= "); DRW_DBGH(fileBuf->getRawChar8()); + DRW_DBG("\napp writer maintenance version= "); DRW_DBGH(fileBuf->getRawChar8()); + duint16 cp = fileBuf->getRawShort16(); + DRW_DBG("\ncodepage= "); DRW_DBG(cp); + if (cp == 30) + decoder.setCodePage("ANSI_1252", false); + /* UNKNOUWN SECTION 2 bytes*/ + DRW_DBG("\nUNKNOWN SECTION= "); DRW_DBG(fileBuf->getRawShort16()); + DRW_DBG("\nUNKNOUWN SECTION 3b= "); DRW_DBG(fileBuf->getRawChar8()); + duint32 secType = fileBuf->getRawLong32(); + DRW_DBG("\nsecurity type flag= "); DRW_DBGH(secType); + /* UNKNOWN2 SECTION 4 bytes*/ + DRW_DBG("\nUNKNOWN SECTION 4bytes= "); DRW_DBG(fileBuf->getRawLong32()); + + DRW_DBG("\nSummary info address= "); DRW_DBGH(fileBuf->getRawLong32()); + DRW_DBG("\nVBA project address= "); DRW_DBGH(fileBuf->getRawLong32()); + DRW_DBG("\n0x00000080 32b= "); DRW_DBGH(fileBuf->getRawLong32()); + DRW_DBG("\nApp info address= "); DRW_DBGH(fileBuf->getRawLong32()); + //current position are 0x30 from here to 0x80 are undocumented + DRW_DBG("\nAnother address? = "); DRW_DBGH(fileBuf->getRawLong32()); + return true; +} + +bool dwgReader21::parseSysPage(duint64 sizeCompressed, duint64 sizeUncompressed, duint64 correctionFactor, duint64 offset, duint8 *decompData){ + //round to 8 + duint64 alsize = (sizeCompressed + 7) &(-8); + //minimum RS chunk: + duint32 chunks = (((alsize * correctionFactor)+238)/239); + duint64 fpsize = chunks * 255; + + if (! fileBuf->setPosition(offset)) + return false; + duint8 *tmpDataRaw = new duint8[fpsize]; + fileBuf->getBytes(tmpDataRaw, fpsize); + duint8 *tmpDataRS = new duint8[fpsize]; + dwgRSCodec::decode239I(tmpDataRaw, tmpDataRS, fpsize/255); + dwgCompressor::decompress21(tmpDataRS, decompData, sizeCompressed, sizeUncompressed); + delete[]tmpDataRaw; + delete[]tmpDataRS; + return true; +} + +bool dwgReader21::parseDataPage(dwgSectionInfo si, duint8 *dData){ + DRW_DBG("parseDataPage, section size: "); DRW_DBG(si.size); + for (std::map::iterator it=si.pages.begin(); it!=si.pages.end(); ++it){ + dwgPageInfo pi = it->second; + if (!fileBuf->setPosition(pi.address)) + return false; + + duint8 *tmpPageRaw = new duint8[pi.size]; + fileBuf->getBytes(tmpPageRaw, pi.size); + #ifdef DRW_DBG_DUMP + DRW_DBG("\nSection OBJECTS raw data=\n"); + for (unsigned int i=0, j=0; i< pi.size;i++) { + DRW_DBGH( (unsigned char)tmpPageRaw[i]); + if (j == 7) { DRW_DBG("\n"); j = 0; + } else { DRW_DBG(", "); j++; } + } DRW_DBG("\n"); + #endif + + duint8 *tmpPageRS = new duint8[pi.size]; + duint8 chunks =pi.size / 255; + dwgRSCodec::decode251I(tmpPageRaw, tmpPageRS, chunks); + #ifdef DRW_DBG_DUMP + DRW_DBG("\nSection OBJECTS RS data=\n"); + for (unsigned int i=0, j=0; i< pi.size;i++) { + DRW_DBGH( (unsigned char)tmpPageRS[i]); + if (j == 7) { DRW_DBG("\n"); j = 0; + } else { DRW_DBG(", "); j++; } + } DRW_DBG("\n"); + #endif + + DRW_DBG("\npage uncomp size: "); DRW_DBG(pi.uSize); DRW_DBG(" comp size: "); DRW_DBG(pi.cSize); + DRW_DBG("\noffset: "); DRW_DBG(pi.startOffset); + duint8 *pageData = dData + pi.startOffset; + dwgCompressor::decompress21(tmpPageRS, pageData, pi.cSize, pi.uSize); + + #ifdef DRW_DBG_DUMP + DRW_DBG("\n\nSection OBJECTS decompresed data=\n"); + for (unsigned int i=0, j=0; i< pi.uSize;i++) { + DRW_DBGH( (unsigned char)pageData[i]); + if (j == 7) { DRW_DBG("\n"); j = 0; + } else { DRW_DBG(", "); j++; } + } DRW_DBG("\n"); + #endif + + delete[]tmpPageRaw; + delete[]tmpPageRS; + } + DRW_DBG("\n"); + return true; +} + +bool dwgReader21::readFileHeader() { + + DRW_DBG("\n\ndwgReader21::parsing file header\n"); + if (! fileBuf->setPosition(0x80)) + return false; + duint8 fileHdrRaw[0x2FD];//0x3D8 + fileBuf->getBytes(fileHdrRaw, 0x2FD); + duint8 fileHdrdRS[0x2CD]; + dwgRSCodec::decode239I(fileHdrRaw, fileHdrdRS, 3); + +#ifdef DRW_DBG_DUMP + DRW_DBG("\ndwgReader21::parsed Reed Solomon decode:\n"); + int j = 0; + for (int i=0, j=0; i<0x2CD; i++){ + DRW_DBGH( (unsigned char)fileHdrdRS[i]); + if (j== 15){ j=0; DRW_DBG("\n"); + } else{ j++; DRW_DBG(", "); } + } DRW_DBG("\n"); +#endif + + dwgBuffer fileHdrBuf(fileHdrdRS, 0x2CD, &decoder); + DRW_DBG("\nCRC 64b= "); DRW_DBGH(fileHdrBuf.getRawLong64()); + DRW_DBG("\nunknown key 64b= "); DRW_DBGH(fileHdrBuf.getRawLong64()); + DRW_DBG("\ncomp data CRC 64b= "); DRW_DBGH(fileHdrBuf.getRawLong64()); + dint32 fileHdrCompLength = fileHdrBuf.getRawLong32(); + DRW_DBG("\ncompr len 4bytes= "); DRW_DBG(fileHdrCompLength); + dint32 fileHdrCompLength2 = fileHdrBuf.getRawLong32(); + DRW_DBG("\nlength2 4bytes= "); DRW_DBG(fileHdrCompLength2); + + int fileHdrDataLength = 0x110; + duint8 *fileHdrData; + if (fileHdrCompLength < 0) { + fileHdrDataLength = fileHdrCompLength * -1; + fileHdrData = new duint8[fileHdrDataLength]; + fileHdrBuf.getBytes(fileHdrData, fileHdrDataLength); + }else { + DRW_DBG("\ndwgReader21:: file header are compresed:\n"); + duint8 *compByteStr = new duint8[fileHdrCompLength]; + fileHdrBuf.getBytes(compByteStr, fileHdrCompLength); + fileHdrData = new duint8[fileHdrDataLength]; + dwgCompressor::decompress21(compByteStr, fileHdrData, fileHdrCompLength, fileHdrDataLength); + delete[] compByteStr; + } + +#ifdef DRW_DBG_DUMP + DRW_DBG("\ndwgReader21::parsed file header:\n"); + for (int i=0, j=0; isectionPageMapTmp; + +// dwgPageInfo *m_pages= new dwgPageInfo[PagesMaxId+1]; + while (PagesMapSizeUncompressed > i ) { + duint64 size = PagesMapBuf.getRawLong64(); + dint64 id = PagesMapBuf.getRawLong64(); + duint64 ind = id > 0 ? id : -id; + i += 16; + + DRW_DBG("Page gap= "); DRW_DBG(id); DRW_DBG(" Page num= "); DRW_DBG(ind); DRW_DBG(" size= "); DRW_DBGH(size); + DRW_DBG(" address= "); DRW_DBGH(address); DRW_DBG("\n"); + sectionPageMapTmp[ind] = dwgPageInfo(ind, address,size); + address += size; + //TODO num can be negative indicating gap +// seek += offset; + } + delete[]PagesMapData; + + DRW_DBG("\n*** dwgReader21: Processing Section Map ***\n"); + duint8 *SectionsMapData = new duint8[SectionsMapSizeUncompressed]; + dwgPageInfo sectionMap = sectionPageMapTmp[SectionsMapId]; + ret = parseSysPage(SectionsMapSizeCompressed, SectionsMapSizeUncompressed, SectionsMapCorrectionFactor, sectionMap.address, SectionsMapData); + if (!ret) + return false; + +//reads sections: + //Note: compressed value are not stored in file then, commpresed field are use to store + // encoding value + dwgBuffer SectionsMapBuf(SectionsMapData, SectionsMapSizeUncompressed, &decoder); + duint8 nextId =1; + while(SectionsMapBuf.getPosition() < SectionsMapBuf.size()){ + dwgSectionInfo secInfo; + secInfo.size = SectionsMapBuf.getRawLong64(); + DRW_DBG("\nSize of section (data size)= "); DRW_DBGH(secInfo.size); + secInfo.maxSize = SectionsMapBuf.getRawLong64(); + DRW_DBG("\nMax Decompressed Size= "); DRW_DBGH(secInfo.maxSize); + secInfo.encrypted = SectionsMapBuf.getRawLong64(); + //encrypted (doc: 0 no, 1 yes, 2 unkn) on read: objects 0 and encrypted yes + DRW_DBG("\nencription= "); DRW_DBGH(secInfo.encrypted); + DRW_DBG("\nHashCode = "); DRW_DBGH(SectionsMapBuf.getRawLong64()); + duint64 SectionNameLength = SectionsMapBuf.getRawLong64(); + DRW_DBG("\nSectionNameLength = "); DRW_DBG(SectionNameLength); + DRW_DBG("\nUnknown = "); DRW_DBGH(SectionsMapBuf.getRawLong64()); + secInfo.compresed = SectionsMapBuf.getRawLong64(); + DRW_DBG("\nEncoding (compresed) = "); DRW_DBGH(secInfo.compresed); + secInfo.pageCount = SectionsMapBuf.getRawLong64(); + DRW_DBG("\nPage count= "); DRW_DBGH(secInfo.pageCount); + secInfo.name = SectionsMapBuf.getUCSStr(SectionNameLength); + DRW_DBG("\nSection name = "); DRW_DBG(secInfo.name); DRW_DBG("\n"); + + for (unsigned int i=0; i< secInfo.pageCount; i++){ + duint64 po = SectionsMapBuf.getRawLong64(); + duint32 ds = SectionsMapBuf.getRawLong64(); + duint32 pn = SectionsMapBuf.getRawLong64(); + DRW_DBG(" pag Id = "); DRW_DBGH(pn); DRW_DBG(" data size = "); DRW_DBGH(ds); + dwgPageInfo pi = sectionPageMapTmp[pn]; //get a copy + pi.dataSize = ds; + pi.startOffset = po; + pi.uSize = SectionsMapBuf.getRawLong64(); + pi.cSize = SectionsMapBuf.getRawLong64(); + secInfo.pages[pn]= pi;//complete copy in secInfo + DRW_DBG("\n Page number= "); DRW_DBGH(secInfo.pages[pn].Id); + DRW_DBG("\n address in file= "); DRW_DBGH(secInfo.pages[pn].address); + DRW_DBG("\n size in file= "); DRW_DBGH(secInfo.pages[pn].size); + DRW_DBG("\n Data size= "); DRW_DBGH(secInfo.pages[pn].dataSize); + DRW_DBG("\n Start offset= "); DRW_DBGH(secInfo.pages[pn].startOffset); + DRW_DBG("\n Page uncompressed size = "); DRW_DBGH(secInfo.pages[pn].uSize); + DRW_DBG("\n Page compressed size = "); DRW_DBGH(secInfo.pages[pn].cSize); + + DRW_DBG("\n Page checksum = "); DRW_DBGH(SectionsMapBuf.getRawLong64()); + DRW_DBG("\n Page CRC = "); DRW_DBGH(SectionsMapBuf.getRawLong64()); DRW_DBG("\n"); + } + + if (!secInfo.name.empty()) { + secInfo.Id = nextId++; + DRW_DBG("Saved section Name= "); DRW_DBG( secInfo.name.c_str() ); DRW_DBG("\n"); + sections[secEnum::getEnum(secInfo.name)] = secInfo; + } + } + delete[]SectionsMapData; + + if (! fileBuf->isGood()) + return false; + + DRW_DBG("\ndwgReader21::readFileHeader END\n"); + return true; +} + +bool dwgReader21::readDwgHeader(DRW_Header& hdr){ + DRW_DBG("\ndwgReader21::readDwgHeader\n"); + dwgSectionInfo si = sections[secEnum::HEADER]; + if (si.Id<0)//not found, ends + return false; + DRW_DBG("\nprepare section of size "); DRW_DBG(si.size);DRW_DBG("\n"); + duint8 *tmpHeaderData = new duint8[si.size]; + bool ret = dwgReader21::parseDataPage(si, tmpHeaderData); + if (!ret) { + delete[]tmpHeaderData; + return ret; + } + + dwgBuffer dataBuf(tmpHeaderData, si.size, &decoder); + dwgBuffer handleBuf(tmpHeaderData, si.size, &decoder); + DRW_DBG("Header section sentinel= "); + checkSentinel(&dataBuf, secEnum::HEADER, true); + ret = dwgReader::readDwgHeader(hdr, &dataBuf, &handleBuf); + delete[]tmpHeaderData; + return ret; +} + +bool dwgReader21::readDwgClasses(){ + DRW_DBG("\ndwgReader21::readDwgClasses"); + dwgSectionInfo si = sections[secEnum::CLASSES]; + if (si.Id<0)//not found, ends + return false; + + DRW_DBG("\nprepare section of size "); DRW_DBG(si.size);DRW_DBG("\n"); + duint8 *tmpClassesData = new duint8[si.size]; + bool ret = dwgReader21::parseDataPage(si, tmpClassesData); + if (!ret) + return ret; + + dwgBuffer buff(tmpClassesData, si.size, &decoder); + DRW_DBG("classes section sentinel= "); + checkSentinel(&buff, secEnum::CLASSES, true); + + duint32 size = buff.getRawLong32(); + DRW_DBG("\ndata size in bytes "); DRW_DBG(size); + + duint32 bitSize = buff.getRawLong32(); + DRW_DBG("\ntotal size in bits "); DRW_DBG(bitSize); + + duint32 maxClassNum = buff.getBitShort(); + DRW_DBG("\nMaximum class number "); DRW_DBG(maxClassNum); + DRW_DBG("\nRc 1 "); DRW_DBG(buff.getRawChar8()); + DRW_DBG("\nRc 2 "); DRW_DBG(buff.getRawChar8()); + DRW_DBG("\nBit "); DRW_DBG(buff.getBit()); + + /*******************************/ + //prepare string stream + dwgBuffer strBuff(tmpClassesData, si.size, &decoder); + duint32 strStartPos = bitSize + 159;//size in bits + 20 bytes (sn+size) - 1 bit (endbit) + DRW_DBG("\nstrStartPos: "); DRW_DBG(strStartPos); + strBuff.setPosition(strStartPos >> 3); + strBuff.setBitPos(strStartPos & 7); + DRW_DBG("\nclasses strings buff.getPosition: "); DRW_DBG(strBuff.getPosition()); + DRW_DBG("\nclasses strings buff.getBitPos: "); DRW_DBG(strBuff.getBitPos()); + DRW_DBG("\nendBit "); DRW_DBG(strBuff.getBit()); + strStartPos -= 16;//decrement 16 bits + DRW_DBG("\nstrStartPos: "); DRW_DBG(strStartPos); + strBuff.setPosition(strStartPos >> 3); + strBuff.setBitPos(strStartPos & 7); + DRW_DBG("\nclasses strings buff.getPosition: "); DRW_DBG(strBuff.getPosition()); + DRW_DBG("\nclasses strings buff.getBitPos: "); DRW_DBG(strBuff.getBitPos()); + duint32 strDataSize = strBuff.getRawShort16(); + DRW_DBG("\nstrDataSize: "); DRW_DBG(strDataSize); + if (strDataSize & 0x8000) { + strStartPos -= 16;//decrement 16 bits + strDataSize &= 0x7FFF; //strip 0x8000; + strBuff.setPosition(strStartPos >> 3); + strBuff.setBitPos(strStartPos & 7); + duint32 hiSize = strBuff.getRawShort16(); + strDataSize |= (hiSize << 15); + } + strStartPos -= strDataSize; + DRW_DBG("\nstrStartPos: "); DRW_DBG(strStartPos); + strBuff.setPosition(strStartPos >> 3); + strBuff.setBitPos(strStartPos & 7); + DRW_DBG("\nclasses strings buff.getPosition: "); DRW_DBG(strBuff.getPosition()); + DRW_DBG("\nclasses strings buff.getBitPos: "); DRW_DBG(strBuff.getBitPos()); + + + /*******************************/ + + duint32 endDataPos = maxClassNum-499; + DRW_DBG("\nbuff.getPosition: "); DRW_DBG(buff.getPosition()); + for (duint32 i= 0; iparseDwg(version, &buff, &strBuff); + classesmap[cl->classNum] = cl; + DRW_DBG("\nbuff.getPosition: "); DRW_DBG(buff.getPosition()); + } + DRW_DBG("\nend classes data buff.getPosition: "); DRW_DBG(buff.getPosition()); + DRW_DBG("\nend classes data buff.getBitPos: "); DRW_DBG(buff.getBitPos()); + + buff.setPosition(size+20);//sizeVal+sn+32bSize + DRW_DBG("\nCRC: "); DRW_DBGH(buff.getRawShort16()); + DRW_DBG("\nclasses section end sentinel= "); + checkSentinel(&buff, secEnum::CLASSES, true); + delete[]tmpClassesData; + return buff.isGood(); +} + + +bool dwgReader21::readDwgHandles(){ + DRW_DBG("\ndwgReader21::readDwgHandles"); + dwgSectionInfo si = sections[secEnum::HANDLES]; + if (si.Id<0)//not found, ends + return false; + + DRW_DBG("\nprepare section of size "); DRW_DBG(si.size);DRW_DBG("\n"); + duint8 *tmpHandlesData = new duint8[si.size]; + bool ret = dwgReader21::parseDataPage(si, tmpHandlesData); + if (!ret) + return ret; + + dwgBuffer dataBuf(tmpHandlesData, si.size, &decoder); + + ret = dwgReader::readDwgHandles(&dataBuf, 0, si.size); + delete[]tmpHandlesData; + return ret; +} + +/*********** objects ************************/ +/** + * Reads all the object referenced in the object map section of the DWG file + * (using their object file offsets) + */ +bool dwgReader21::readDwgTables(DRW_Header& hdr) { + DRW_DBG("\ndwgReader21::readDwgTables\n"); + dwgSectionInfo si = sections[secEnum::OBJECTS]; + if (si.Id<0)//not found, ends + return false; + + DRW_DBG("\nprepare section of size "); DRW_DBG(si.size);DRW_DBG("\n"); + dataSize = si.size; + objData = new duint8 [dataSize]; + bool ret = dwgReader21::parseDataPage(si, objData); + if (!ret) + return ret; + + DRW_DBG("readDwgTables total data size= "); DRW_DBG(dataSize); DRW_DBG("\n"); + dwgBuffer dataBuf(objData, dataSize, &decoder); + ret = dwgReader::readDwgTables(hdr, &dataBuf); + + return ret; +} + + +bool dwgReader21::readDwgBlocks(DRW_Interface& intfa){ + bool ret = true; + dwgBuffer dataBuf(objData, dataSize, &decoder); + ret = dwgReader::readDwgBlocks(intfa, &dataBuf); + return ret; + + return false; +} diff --git a/src/libs/vdxf/libdxfrw/intern/dwgreader21.h b/src/libs/vdxf/libdxfrw/intern/dwgreader21.h new file mode 100644 index 000000000..f95c77a25 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/dwgreader21.h @@ -0,0 +1,65 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#ifndef DWGREADER21_H +#define DWGREADER21_H + +#include +#include +#include "drw_textcodec.h" +#include "dwgbuffer.h" +#include "dwgreader.h" + +//reader for AC1021 aka v2007, chapter 5 +class dwgReader21 : public dwgReader { +public: + dwgReader21(std::istream *stream, dwgR *p):dwgReader(stream, p){ + objData = NULL; + dataSize = 0; + } + virtual ~dwgReader21(){ + if (objData != NULL) + delete[] objData; + } + bool readMetaData(); + bool readFileHeader(); + bool readDwgHeader(DRW_Header& hdr); + bool readDwgClasses(); + bool readDwgHandles(); + bool readDwgTables(DRW_Header& hdr); + bool readDwgBlocks(DRW_Interface& intfa); + virtual bool readDwgEntities(DRW_Interface& intfa){ + bool ret = true; + dwgBuffer dataBuf(objData, dataSize, &decoder); + ret = dwgReader::readDwgEntities(intfa, &dataBuf); + return ret; + } + virtual bool readDwgObjects(DRW_Interface& intfa){ + bool ret = true; + dwgBuffer dataBuf(objData, dataSize, &decoder); + ret = dwgReader::readDwgObjects(intfa, &dataBuf); + return ret; + } +//bool readDwgEntity(objHandle& obj, DRW_Interface& intfa){ +// return false; +//} + +private: + bool parseSysPage(duint64 sizeCompressed, duint64 sizeUncompressed, duint64 correctionFactor, duint64 offset, duint8 *decompData); + bool parseDataPage(dwgSectionInfo si, duint8 *dData); + + duint8 *objData; + duint64 dataSize; + +}; + +#endif // DWGREADER21_H diff --git a/src/libs/vdxf/libdxfrw/intern/dwgreader24.cpp b/src/libs/vdxf/libdxfrw/intern/dwgreader24.cpp new file mode 100644 index 000000000..295032c20 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/dwgreader24.cpp @@ -0,0 +1,43 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#include +#include +#include +#include +#include +#include "drw_dbg.h" +#include "dwgreader24.h" +#include "drw_textcodec.h" +#include "../libdwgr.h" + + +bool dwgReader24::readFileHeader() { + DRW_DBG("dwgReader24::readFileHeader\n"); + bool ret = dwgReader18::readFileHeader(); + DRW_DBG("dwgReader24::readFileHeader END\n"); + return ret; +} + +bool dwgReader24::readDwgHeader(DRW_Header& hdr){ + DRW_DBG("dwgReader24::readDwgHeader\n"); + bool ret = dwgReader18::readDwgHeader(hdr); + DRW_DBG("dwgReader24::readDwgHeader END\n"); + return ret; +} + +bool dwgReader24::readDwgClasses(){ + DRW_DBG("\ndwgReader24::readDwgClasses"); + bool ret = dwgReader18::readDwgClasses(); + DRW_DBG("\ndwgReader24::readDwgClasses END\n"); + return ret; +} diff --git a/src/libs/vdxf/libdxfrw/intern/dwgreader24.h b/src/libs/vdxf/libdxfrw/intern/dwgreader24.h new file mode 100644 index 000000000..e5fc43a72 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/dwgreader24.h @@ -0,0 +1,56 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#ifndef DWGREADER24_H +#define DWGREADER24_H + +#include +#include +#include "drw_textcodec.h" +#include "dwgbuffer.h" +#include "dwgreader18.h" + +class dwgReader24 : public dwgReader18 { +public: + dwgReader24(std::istream *stream, dwgR *p):dwgReader18(stream, p){ } + virtual ~dwgReader24(){} + bool readFileHeader(); + bool readDwgHeader(DRW_Header& hdr); + bool readDwgClasses(); +// bool readDwgHandles(){return false;} +// bool readDwgTables(){return false;} + bool readDwgBlocks(DRW_Interface& intfa){ + bool ret = true; + dwgBuffer dataBuf(objData, uncompSize, &decoder); + ret = dwgReader::readDwgBlocks(intfa, &dataBuf); + return ret; + } + virtual bool readDwgEntities(DRW_Interface& intfa){ + bool ret = true; + dwgBuffer dataBuf(objData, uncompSize, &decoder); + ret = dwgReader::readDwgEntities(intfa, &dataBuf); + return ret; + } + virtual bool readDwgObjects(DRW_Interface& intfa){ + bool ret = true; + dwgBuffer dataBuf(objData, uncompSize, &decoder); + ret = dwgReader::readDwgObjects(intfa, &dataBuf); + return ret; + } + +// bool readDwgEntity(objHandle& obj, DRW_Interface& intfa){ +// DRW_UNUSED(obj); +// DRW_UNUSED(intfa); +// return false;} +}; + +#endif // DWGREADER24_H diff --git a/src/libs/vdxf/libdxfrw/intern/dwgreader27.cpp b/src/libs/vdxf/libdxfrw/intern/dwgreader27.cpp new file mode 100644 index 000000000..dea68f6a7 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/dwgreader27.cpp @@ -0,0 +1,43 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#include +#include +#include +#include +#include +#include "drw_dbg.h" +#include "dwgreader27.h" +#include "drw_textcodec.h" +#include "../libdwgr.h" + + +bool dwgReader27::readFileHeader() { + DRW_DBG("dwgReader27::readFileHeader\n"); + bool ret = dwgReader18::readFileHeader(); + DRW_DBG("dwgReader27::readFileHeader END\n"); + return ret; +} + +bool dwgReader27::readDwgHeader(DRW_Header& hdr){ + DRW_DBG("dwgReader27::readDwgHeader\n"); + bool ret = dwgReader18::readDwgHeader(hdr); + DRW_DBG("dwgReader27::readDwgHeader END\n"); + return ret; +} + +bool dwgReader27::readDwgClasses(){ + DRW_DBG("dwgReader27::readDwgClasses"); + bool ret = dwgReader18::readDwgClasses(); + DRW_DBG("\ndwgReader27::readDwgClasses END\n"); + return ret; +} diff --git a/src/libs/vdxf/libdxfrw/intern/dwgreader27.h b/src/libs/vdxf/libdxfrw/intern/dwgreader27.h new file mode 100644 index 000000000..32c67f65b --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/dwgreader27.h @@ -0,0 +1,55 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#ifndef DWGREADER27_H +#define DWGREADER27_H + +#include +#include +#include "drw_textcodec.h" +#include "dwgbuffer.h" +#include "dwgreader18.h" + +class dwgReader27 : public dwgReader18 { +public: + dwgReader27(std::istream *stream, dwgR *p):dwgReader18(stream, p){ } + virtual ~dwgReader27(){} + bool readFileHeader(); + bool readDwgHeader(DRW_Header& hdr); + bool readDwgClasses(); +// bool readDwgHandles(){return false;} +// bool readDwgTables(){return false;} + bool readDwgBlocks(DRW_Interface& intfa){ + bool ret = true; + dwgBuffer dataBuf(objData, uncompSize, &decoder); + ret = dwgReader::readDwgBlocks(intfa, &dataBuf); + return ret; + } + virtual bool readDwgEntities(DRW_Interface& intfa){ + bool ret = true; + dwgBuffer dataBuf(objData, uncompSize, &decoder); + ret = dwgReader::readDwgEntities(intfa, &dataBuf); + return ret; + } + virtual bool readDwgObjects(DRW_Interface& intfa){ + bool ret = true; + dwgBuffer dataBuf(objData, uncompSize, &decoder); + ret = dwgReader::readDwgObjects(intfa, &dataBuf); + return ret; + } +// bool readDwgEntity(objHandle& obj, DRW_Interface& intfa){ +// DRW_UNUSED(obj); +// DRW_UNUSED(intfa); +// return false;} +}; + +#endif // DWGREADER21_H diff --git a/src/libs/vdxf/libdxfrw/intern/dwgutil.cpp b/src/libs/vdxf/libdxfrw/intern/dwgutil.cpp new file mode 100644 index 000000000..10121cf3d --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/dwgutil.cpp @@ -0,0 +1,694 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#include +#include "drw_dbg.h" +#include "dwgutil.h" +#include "rscodec.h" +#include "../libdwgr.h" + +/** utility function + * convert a int to string in hex + **/ +namespace DRW { +std::string toHexStr(int n){ +#if defined(__APPLE__) + char buffer[9]= {'\0'}; + snprintf(buffer,9, "%X", n); + return std::string(buffer); +#else + std::ostringstream Convert; + Convert << std::uppercase << std::hex << n; + return Convert.str(); +#endif +} +} + +/** + * @brief dwgRSCodec::decode239I + * @param in : input data (at least 255*blk bytes) + * @param out : output data (at least 239*blk bytes) + * @param blk number of codewords ( 1 cw == 255 bytes) + */ +void dwgRSCodec::decode239I(unsigned char *in, unsigned char *out, duint32 blk){ + int k=0; + unsigned char data[255]; + RScodec rsc(0x96, 8, 8); //(255, 239) + for (duint32 i=0; i> 2) | (bufC[pos++] << 6); + *ll = (fb & 0x03); + return cont; +} + +duint32 dwgCompressor::longCompressionOffset(){ + duint32 cont = 0; + duint8 ll = bufC[pos++]; + while (ll == 0x00){ + cont += 0xFF; + ll = bufC[pos++]; + } + cont += ll; + return cont; +} + +duint32 dwgCompressor::long20CompressionOffset(){ +// duint32 cont = 0; + duint32 cont = 0x0F; + duint8 ll = bufC[pos++]; + while (ll == 0x00){ +// cont += 0xFF; + ll = bufC[pos++]; + } + cont += ll; + return cont; +} + +duint32 dwgCompressor::litLength18(){ + duint32 cont=0; + duint8 ll = bufC[pos++]; + //no literal length, this byte is next opCode + if (ll > 0x0F) { + pos--; + return 0; + } + + if (ll == 0x00) { + cont = 0x0F; + ll = bufC[pos++]; + while (ll == 0x00){//repeat until ll != 0x00 + cont +=0xFF; + ll = bufC[pos++]; + } + } + cont +=ll; + cont +=3; //already sum 3 + return cont; +} + +void dwgCompressor::decompress18(duint8 *cbuf, duint8 *dbuf, duint32 csize, duint32 dsize){ + bufC = cbuf; + bufD = dbuf; + sizeC = csize -2; + sizeD = dsize; + DRW_DBG("dwgCompressor::decompress, last 2 bytes: "); + DRW_DBGH(bufC[sizeC]);DRW_DBGH(bufC[sizeC+1]);DRW_DBG("\n"); + sizeC = csize; + + duint32 compBytes; + duint32 compOffset; + duint32 litCount; + + pos=0; //current position in compresed buffer + rpos=0; //current position in resulting decompresed buffer + litCount = litLength18(); + //copy first lileral lenght + for (duint32 i=0; i < litCount; ++i) { + bufD[rpos++] = bufC[pos++]; + } + + while (pos < csize && (rpos < dsize+1)){//rpos < dsize to prevent crash more robust are needed + duint8 oc = bufC[pos++]; //next opcode + if (oc == 0x10){ + compBytes = longCompressionOffset()+ 9; + compOffset = twoByteOffset(&litCount) + 0x3FFF; + if (litCount == 0) + litCount= litLength18(); + } else if (oc > 0x11 && oc< 0x20){ + compBytes = (oc & 0x0F) + 2; + compOffset = twoByteOffset(&litCount) + 0x3FFF; + if (litCount == 0) + litCount= litLength18(); + } else if (oc == 0x20){ + compBytes = longCompressionOffset() + 0x21; + compOffset = twoByteOffset(&litCount); + if (litCount == 0) + litCount= litLength18(); + else + oc = 0x00; + } else if (oc > 0x20 && oc< 0x40){ + compBytes = oc - 0x1E; + compOffset = twoByteOffset(&litCount); + if (litCount == 0) + litCount= litLength18(); + } else if ( oc > 0x3F){ + compBytes = ((oc & 0xF0) >> 4) - 1; + duint8 ll2 = bufC[pos++]; + compOffset = (ll2 << 2) | ((oc & 0x0C) >> 2); + litCount = oc & 0x03; + if (litCount < 1){ + litCount= litLength18();} + } else if (oc == 0x11){ + DRW_DBG("dwgCompressor::decompress, end of input stream, Cpos: "); + DRW_DBG(pos);DRW_DBG(", Dpos: ");DRW_DBG(rpos);DRW_DBG("\n"); + return; //end of input stream + } else { //ll < 0x10 + DRW_DBG("WARNING dwgCompressor::decompress, failed, illegal char, Cpos: "); + DRW_DBG(pos);DRW_DBG(", Dpos: ");DRW_DBG(rpos);DRW_DBG("\n"); + return; //fails, not valid + } + //copy "compresed data", TODO Needed verify out of bounds + duint32 remaining = sizeD - (litCount+rpos); + if (remaining < compBytes){ + compBytes = remaining; + DRW_DBG("WARNING dwgCompressor::decompress, bad compBytes size, Cpos: "); + DRW_DBG(pos);DRW_DBG(", Dpos: ");DRW_DBG(rpos);DRW_DBG("\n"); + } + for (duint32 i=0, j= rpos - compOffset -1; i < compBytes; i++) { + bufD[rpos++] = bufD[j++]; + } + //copy "uncompresed data", TODO Needed verify out of bounds + for (duint32 i=0; i < litCount; i++) { + bufD[rpos++] = bufC[pos++]; + } + } + DRW_DBG("WARNING dwgCompressor::decompress, bad out, Cpos: ");DRW_DBG(pos);DRW_DBG(", Dpos: ");DRW_DBG(rpos);DRW_DBG("\n"); +} + + +void dwgCompressor::decrypt18Hdr(duint8 *buf, duint32 size, duint32 offset){ + duint8 max = size / 4; + duint32 secMask = 0x4164536b ^ offset; + duint32* pHdr = (duint32*)buf; + for (duint8 j = 0; j < max; j++) + *pHdr++ ^= secMask; +} + +/*void dwgCompressor::decrypt18Data(duint8 *buf, duint32 size, duint32 offset){ + duint8 max = size / 4; + duint32 secMask = 0x4164536b ^ offset; + duint32* pHdr = (duint32*)buf; + for (duint8 j = 0; j < max; j++) + *pHdr++ ^= secMask; +}*/ + +duint32 dwgCompressor::litLength21(duint8 *cbuf, duint8 oc, duint32 *si){ + + duint32 srcIndex=*si; + + duint32 length = oc + 8; + if (length == 0x17) { + duint32 n = cbuf[srcIndex++]; + length += n; + if (n == 0xff) { + do { + n = cbuf[srcIndex++]; + n |= (duint32)(cbuf[srcIndex++] << 8); + length += n; + } while (n == 0xffff); + } + } + + *si = srcIndex; + return length; +} + +void dwgCompressor::decompress21(duint8 *cbuf, duint8 *dbuf, duint32 csize, duint32 dsize){ + duint32 srcIndex=0; + duint32 dstIndex=0; + duint32 length=0; + duint32 sourceOffset; + duint8 opCode; + + opCode = cbuf[srcIndex++]; + if ((opCode >> 4) == 2){ + srcIndex = srcIndex +2; + length = cbuf[srcIndex++] & 0x07; + } + + while (srcIndex < csize && (dstIndex < dsize+1)){//dstIndex < dsize to prevent crash more robust are needed + if (length == 0) + length = litLength21(cbuf, opCode, &srcIndex); + copyCompBytes21(cbuf, dbuf, length, srcIndex, dstIndex); + srcIndex += length; + dstIndex += length; + if (dstIndex >=dsize) break; //check if last chunk are compresed & terminate + + length = 0; + opCode = cbuf[srcIndex++]; + readInstructions21(cbuf, &srcIndex, &opCode, &sourceOffset, &length); + while (true) { + //prevent crash with corrupted data + if (sourceOffset > dstIndex){ + DRW_DBG("\nWARNING dwgCompressor::decompress21 => sourceOffset> dstIndex.\n"); + DRW_DBG("csize = "); DRW_DBG(csize); DRW_DBG(" srcIndex = "); DRW_DBG(srcIndex); + DRW_DBG("\ndsize = "); DRW_DBG(dsize); DRW_DBG(" dstIndex = "); DRW_DBG(dstIndex); + sourceOffset = dstIndex; + } + //prevent crash with corrupted data + if (length > dsize - dstIndex){ + DRW_DBG("\nWARNING dwgCompressor::decompress21 => length > dsize - dstIndex.\n"); + DRW_DBG("csize = "); DRW_DBG(csize); DRW_DBG(" srcIndex = "); DRW_DBG(srcIndex); + DRW_DBG("\ndsize = "); DRW_DBG(dsize); DRW_DBG(" dstIndex = "); DRW_DBG(dstIndex); + length = dsize - dstIndex; + srcIndex = csize;//force exit + } + sourceOffset = dstIndex-sourceOffset; + for (duint32 i=0; i< length; i++) + dbuf[dstIndex++] = dbuf[sourceOffset+i]; + + length = opCode & 7; + if ((length != 0) || (srcIndex >= csize)) { + break; + } + opCode = cbuf[srcIndex++]; + if ((opCode >> 4) == 0) { + break; + } + if ((opCode >> 4) == 15) { + opCode &= 15; + } + readInstructions21(cbuf, &srcIndex, &opCode, &sourceOffset, &length); + } + } + DRW_DBG("\ncsize = "); DRW_DBG(csize); DRW_DBG(" srcIndex = "); DRW_DBG(srcIndex); + DRW_DBG("\ndsize = "); DRW_DBG(dsize); DRW_DBG(" dstIndex = "); DRW_DBG(dstIndex);DRW_DBG("\n"); +} + +void dwgCompressor::readInstructions21(duint8 *cbuf, duint32 *si, duint8 *oc, duint32 *so, duint32 *l){ + duint32 length; + duint32 srcIndex = *si; + duint32 sourceOffset; + unsigned char opCode = *oc; + switch ((opCode >> 4)) { + case 0: + length = (opCode & 0xf) + 0x13; + sourceOffset = cbuf[srcIndex++]; + opCode = cbuf[srcIndex++]; + length = ((opCode >> 3) & 0x10) + length; + sourceOffset = ((opCode & 0x78) << 5) + 1 + sourceOffset; + break; + case 1: + length = (opCode & 0xf) + 3; + sourceOffset = cbuf[srcIndex++]; + opCode = cbuf[srcIndex++]; + sourceOffset = ((opCode & 0xf8) << 5) + 1 + sourceOffset; + break; + case 2: + sourceOffset = cbuf[srcIndex++]; + sourceOffset = ((cbuf[srcIndex++] << 8) & 0xff00) | sourceOffset; + length = opCode & 7; + if ((opCode & 8) == 0) { + opCode = cbuf[srcIndex++]; + length = (opCode & 0xf8) + length; + } else { + sourceOffset++; + length = (cbuf[srcIndex++] << 3) + length; + opCode = cbuf[srcIndex++]; + length = (((opCode & 0xf8) << 8) + length) + 0x100; + } + break; + default: + length = opCode >> 4; + sourceOffset = opCode & 15; + opCode = cbuf[srcIndex++]; + sourceOffset = (((opCode & 0xf8) << 1) + sourceOffset) + 1; + break; + } + *oc = opCode; + *si = srcIndex; + *so = sourceOffset; + *l = length; +} + + +void dwgCompressor::copyCompBytes21(duint8 *cbuf, duint8 *dbuf, duint32 l, duint32 si, duint32 di){ + duint32 length =l; + duint32 dix = di; + duint32 six = si; + + while (length > 31){ + //in doc: 16-31, 0-15 + for (duint32 i = six+24; i. ** +******************************************************************************/ + +#ifndef DWGUTIL_H +#define DWGUTIL_H + +#include "../drw_base.h" + +namespace DRW { +std::string toHexStr(int n); +} + +class dwgRSCodec { +public: + dwgRSCodec(){} + ~dwgRSCodec(){} + static void decode239I(duint8 *in, duint8 *out, duint32 blk); + static void decode251I(duint8 *in, duint8 *out, duint32 blk); +}; + +class dwgCompressor { +public: + dwgCompressor(){} + ~dwgCompressor(){} + + void decompress18(duint8 *cbuf, duint8 *dbuf, duint32 csize, duint32 dsize); + static void decrypt18Hdr(duint8 *buf, duint32 size, duint32 offset); +// static void decrypt18Data(duint8 *buf, duint32 size, duint32 offset); + static void decompress21(duint8 *cbuf, duint8 *dbuf, duint32 csize, duint32 dsize); + +private: + duint32 litLength18(); + static duint32 litLength21(duint8 *cbuf, duint8 oc, duint32 *si); + static void copyCompBytes21(duint8 *cbuf, duint8 *dbuf, duint32 l, duint32 si, duint32 di); + static void readInstructions21(duint8 *cbuf, duint32 *si, duint8 *oc, duint32 *so, duint32 *l); + + duint32 longCompressionOffset(); + duint32 long20CompressionOffset(); + duint32 twoByteOffset(duint32 *ll); + + duint8 *bufC; + duint8 *bufD; + duint32 sizeC; + duint32 sizeD; + duint32 pos; + duint32 rpos; + +}; + +class secEnum { +public: + enum DWGSection { + UNKNOWNS, /*!< UNKNOWN section. */ + FILEHEADER, /*!< File Header (in R3-R15*/ + HEADER, /*!< AcDb:Header */ + CLASSES, /*!< AcDb:Classes */ + SUMARYINFO, /*!< AcDb:SummaryInfo */ + PREVIEW, /*!< AcDb:Preview */ + VBAPROY, /*!< AcDb:VBAProject */ + APPINFO, /*!< AcDb:AppInfo */ + FILEDEP, /*!< AcDb:FileDepList */ + REVHISTORY, /*!< AcDb:RevHistory */ + SECURITY, /*!< AcDb:Security */ + OBJECTS, /*!< AcDb:AcDbObjects */ + OBJFREESPACE, /*!< AcDb:ObjFreeSpace */ + TEMPLATE, /*!< AcDb:Template */ + HANDLES, /*!< AcDb:Handles */ + PROTOTYPE, /*!< AcDb:AcDsPrototype_1b */ + AUXHEADER, /*!< AcDb:AuxHeader, in (R13-R15) second file header */ + SIGNATURE, /*!< AcDb:Signature */ + APPINFOHISTORY, /*!< AcDb:AppInfoHistory (in ac1021 may be a renamed section?*/ + EXTEDATA, /*!< Extended Entity Data */ + PROXYGRAPHICS /*!< PROXY ENTITY GRAPHICS */ + }; + + secEnum(){} + ~secEnum(){} + + static DWGSection getEnum(std::string nameSec); +}; + +#endif // DWGUTIL_H diff --git a/src/libs/vdxf/libdxfrw/intern/dxfreader.cpp b/src/libs/vdxf/libdxfrw/intern/dxfreader.cpp new file mode 100644 index 000000000..84f864101 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/dxfreader.cpp @@ -0,0 +1,263 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#include +#include +#include +#include +#include "dxfreader.h" +#include "drw_textcodec.h" +#include "drw_dbg.h" + +bool dxfReader::readRec(int *codeData) { +// std::string text; + int code; + + if (!readCode(&code)) + return false; + *codeData = code; + + if (code < 10) + readString(); + else if (code < 60) + readDouble(); + else if (code < 80) + readInt16(); + else if (code > 89 && code < 100) //TODO this is an int 32b + readInt32(); + else if (code == 100 || code == 102 || code == 105) + readString(); + else if (code > 109 && code < 150) //skip not used at the v2012 + readDouble(); + else if (code > 159 && code < 170) //skip not used at the v2012 + readInt64(); + else if (code < 180) + readInt16(); + else if (code > 209 && code < 240) //skip not used at the v2012 + readDouble(); + else if (code > 269 && code < 290) //skip not used at the v2012 + readInt16(); + else if (code < 300) //TODO this is a boolean indicator, int in Binary? + readBool(); + else if (code < 370) + readString(); + else if (code < 390) + readInt16(); + else if (code < 400) + readString(); + else if (code < 410) + readInt16(); + else if (code < 420) + readString(); + else if (code < 430) //TODO this is an int 32b + readInt32(); + else if (code < 440) + readString(); + else if (code < 450) //TODO this is an int 32b + readInt32(); + else if (code < 460) //TODO this is long?? + readInt32(); + else if (code < 470) //TODO this is a floating point double precision?? + readDouble(); + else if (code < 481) + readString(); + else if (code > 998 && code < 1009) //skip not used at the v2012 + readString(); + else if (code < 1060) //TODO this is a floating point double precision?? + readDouble(); + else if (code < 1071) + readInt16(); + else if (code == 1071) //TODO this is an int 32b + readInt32(); + else if (skip) + //skip safely this dxf entry ( ok for ascii dxf) + readString(); + else + //break in binary files because the conduct is unpredictable + return false; + + return (filestr->good()); +} +int dxfReader::getHandleString(){ + int res; +#if defined(__APPLE__) + int Succeeded = sscanf ( strData.c_str(), "%x", &res ); + if ( !Succeeded || Succeeded == EOF ) + res = 0; +#else + std::istringstream Convert(strData); + if ( !(Convert >> std::hex >>res) ) + res = 0; +#endif + return res; +} + +bool dxfReaderBinary::readCode(int *code) { + unsigned short *int16p; + char buffer[2]; + filestr->read(buffer,2); + int16p = (unsigned short *) buffer; +//exist a 32bits int (code 90) with 2 bytes??? + if ((*code == 90) && (*int16p>2000)){ + DRW_DBG(*code); DRW_DBG(" de 16bits\n"); + filestr->seekg(-4, std::ios_base::cur); + filestr->read(buffer,2); + int16p = (unsigned short *) buffer; + } + *code = *int16p; + DRW_DBG(*code); DRW_DBG("\n"); + + return (filestr->good()); +} + +bool dxfReaderBinary::readString() { + type = STRING; + std::getline(*filestr, strData, '\0'); + DRW_DBG(strData); DRW_DBG("\n"); + return (filestr->good()); +} + +bool dxfReaderBinary::readString(std::string *text) { + type = STRING; + std::getline(*filestr, *text, '\0'); + DRW_DBG(*text); DRW_DBG("\n"); + return (filestr->good()); +} + +bool dxfReaderBinary::readInt16() { + type = INT32; + char buffer[2]; + filestr->read(buffer,2); + intData = (int)((buffer[1] << 8) | buffer[0]); + DRW_DBG(intData); DRW_DBG("\n"); + return (filestr->good()); +} + +bool dxfReaderBinary::readInt32() { + type = INT32; + unsigned int *int32p; + char buffer[4]; + filestr->read(buffer,4); + int32p = (unsigned int *) buffer; + intData = *int32p; + DRW_DBG(intData); DRW_DBG("\n"); + return (filestr->good()); +} + +bool dxfReaderBinary::readInt64() { + type = INT64; + unsigned long long int *int64p; //64 bits integer pointer + char buffer[8]; + filestr->read(buffer,8); + int64p = (unsigned long long int *) buffer; + int64 = *int64p; + DRW_DBG(int64); DRW_DBG(" int64\n"); + return (filestr->good()); +} + +bool dxfReaderBinary::readDouble() { + type = DOUBLE; + double *result; + char buffer[8]; + filestr->read(buffer,8); + result = (double *) buffer; + doubleData = *result; + DRW_DBG(doubleData); DRW_DBG("\n"); + return (filestr->good()); +} + +//saved as int or add a bool member?? +bool dxfReaderBinary::readBool() { + char buffer[1]; + filestr->read(buffer,1); + intData = (int)(buffer[0]); + DRW_DBG(intData); DRW_DBG("\n"); + return (filestr->good()); +} + +bool dxfReaderAscii::readCode(int *code) { + std::string text; + std::getline(*filestr, text); + *code = atoi(text.c_str()); + DRW_DBG(*code); DRW_DBG("\n"); + return (filestr->good()); +} +bool dxfReaderAscii::readString(std::string *text) { + type = STRING; + std::getline(*filestr, *text); + if (!text->empty() && text->at(text->size()-1) == '\r') + text->erase(text->size()-1); + return (filestr->good()); +} + +bool dxfReaderAscii::readString() { + type = STRING; + std::getline(*filestr, strData); + if (!strData.empty() && strData.at(strData.size()-1) == '\r') + strData.erase(strData.size()-1); + DRW_DBG(strData); DRW_DBG("\n"); + return (filestr->good()); +} + +bool dxfReaderAscii::readInt16() { + type = INT32; + std::string text; + if (readString(&text)){ + intData = atoi(text.c_str()); + DRW_DBG(intData); DRW_DBG("\n"); + return true; + } else + return false; +} + +bool dxfReaderAscii::readInt32() { + type = INT32; + return readInt16(); +} + +bool dxfReaderAscii::readInt64() { + type = INT64; + return readInt16(); +} + +bool dxfReaderAscii::readDouble() { + type = DOUBLE; + std::string text; + if (readString(&text)){ +#if defined(__APPLE__) + int succeeded=sscanf( & (text[0]), "%lg", &doubleData); + if(succeeded != 1) { + DRW_DBG("dxfReaderAscii::readDouble(): reading double error: "); + DRW_DBG(text); + DRW_DBG('\n'); + } +#else + std::istringstream sd(text); + sd >> doubleData; + DRW_DBG(doubleData); DRW_DBG('\n'); +#endif + return true; + } else + return false; +} + +//saved as int or add a bool member?? +bool dxfReaderAscii::readBool() { + type = BOOL; + std::string text; + if (readString(&text)){ + intData = atoi(text.c_str()); + DRW_DBG(intData); DRW_DBG("\n"); + return true; + } else + return false; +} diff --git a/src/libs/vdxf/libdxfrw/intern/dxfreader.h b/src/libs/vdxf/libdxfrw/intern/dxfreader.h new file mode 100644 index 000000000..a0fa327c9 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/dxfreader.h @@ -0,0 +1,99 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#ifndef DXFREADER_H +#define DXFREADER_H + +#include "drw_textcodec.h" + +class dxfReader { +public: + enum TYPE { + STRING, + INT32, + INT64, + DOUBLE, + BOOL, + INVALID + }; + enum TYPE type; +public: + dxfReader(std::istream *stream){ + filestr = stream; + type = INVALID; + } + virtual ~dxfReader(){} + bool readRec(int *code); + + std::string getString() {return strData;} + int getHandleString();//Convert hex string to int + std::string toUtf8String(std::string t) {return decoder.toUtf8(t);} + std::string getUtf8String() {return decoder.toUtf8(strData);} + double getDouble() {return doubleData;} + int getInt32() {return intData;} + unsigned long long int getInt64() {return int64;} + bool getBool() { return (intData==0) ? false : true;} + int getVersion(){return decoder.getVersion();} + void setVersion(std::string *v, bool dxfFormat){decoder.setVersion(v, dxfFormat);} + void setCodePage(std::string *c){decoder.setCodePage(c, true);} + std::string getCodePage(){ return decoder.getCodePage();} + +protected: + virtual bool readCode(int *code) = 0; //return true if sucesful (not EOF) + virtual bool readString(std::string *text) = 0; + virtual bool readString() = 0; + virtual bool readInt16() = 0; + virtual bool readInt32() = 0; + virtual bool readInt64() = 0; + virtual bool readDouble() = 0; + virtual bool readBool() = 0; + +protected: + std::istream *filestr; + std::string strData; + double doubleData; + signed int intData; //32 bits integer + unsigned long long int int64; //64 bits integer + bool skip; //set to true for ascii dxf, false for binary +private: + DRW_TextCodec decoder; +}; + +class dxfReaderBinary : public dxfReader { +public: + dxfReaderBinary(std::istream *stream):dxfReader(stream){skip = false; } + virtual ~dxfReaderBinary() {} + virtual bool readCode(int *code); + virtual bool readString(std::string *text); + virtual bool readString(); + virtual bool readInt16(); + virtual bool readInt32(); + virtual bool readInt64(); + virtual bool readDouble(); + virtual bool readBool(); +}; + +class dxfReaderAscii : public dxfReader { +public: + dxfReaderAscii(std::istream *stream):dxfReader(stream){skip = true; } + virtual ~dxfReaderAscii(){} + virtual bool readCode(int *code); + virtual bool readString(std::string *text); + virtual bool readString(); + virtual bool readInt16(); + virtual bool readDouble(); + virtual bool readInt32(); + virtual bool readInt64(); + virtual bool readBool(); +}; + +#endif // DXFREADER_H diff --git a/src/libs/vdxf/libdxfrw/intern/dxfwriter.cpp b/src/libs/vdxf/libdxfrw/intern/dxfwriter.cpp new file mode 100644 index 000000000..40ca3fc15 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/dxfwriter.cpp @@ -0,0 +1,270 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#include +#include +#include +#include +#include "dxfwriter.h" + +//RLZ TODO change std::endl to x0D x0A (13 10) +/*bool dxfWriter::readRec(int *codeData, bool skip) { +// std::string text; + int code; + +#ifdef DRW_DBG + count = count+2; //DBG +#endif + + if (!readCode(&code)) + return false; + *codeData = code; + + if (code < 10) + readString(); + else if (code < 60) + readDouble(); + else if (code < 80) + readInt(); + else if (code > 89 && code < 100) //TODO this is an int 32b + readInt32(); + else if (code == 100 || code == 102 || code == 105) + readString(); + else if (code > 109 && code < 150) //skip not used at the v2012 + readDouble(); + else if (code > 159 && code < 170) //skip not used at the v2012 + readInt64(); + else if (code < 180) + readInt(); + else if (code > 209 && code < 240) //skip not used at the v2012 + readDouble(); + else if (code > 269 && code < 290) //skip not used at the v2012 + readInt(); + else if (code < 300) //TODO this is a boolean indicator, int in Binary? + readBool(); + else if (code < 370) + readString(); + else if (code < 390) + readInt(); + else if (code < 400) + readString(); + else if (code < 410) + readInt(); + else if (code < 420) + readString(); + else if (code < 430) //TODO this is an int 32b + readInt32(); + else if (code < 440) + readString(); + else if (code < 450) //TODO this is an int 32b + readInt32(); + else if (code < 460) //TODO this is long?? + readInt(); + else if (code < 470) //TODO this is a floating point double precision?? + readDouble(); + else if (code < 481) + readString(); + else if (code > 998 && code < 1009) //skip not used at the v2012 + readString(); + else if (code < 1060) //TODO this is a floating point double precision?? + readDouble(); + else if (code < 1071) + readInt(); + else if (code == 1071) //TODO this is an int 32b + readInt32(); + else if (skip) + //skip safely this dxf entry ( ok for ascii dxf) + readString(); + else + //break in binary files because the conduct is unpredictable + return false; + + return (filestr->good()); +}*/ + +bool dxfWriter::writeUtf8String(int code, std::string text) { + std::string t = encoder.fromUtf8(text); + return writeString(code, t); +} + +bool dxfWriter::writeUtf8Caps(int code, std::string text) { + std::string strname = text; + std::transform(strname.begin(), strname.end(), strname.begin(),::toupper); + std::string t = encoder.fromUtf8(strname); + return writeString(code, t); +} + +bool dxfWriterBinary::writeString(int code, std::string text) { + char bufcode[2]; + bufcode[0] =code & 0xFF; + bufcode[1] =code >> 8; + filestr->write(bufcode, 2); + *filestr << text << '\0'; + return (filestr->good()); +} + +/*bool dxfWriterBinary::readCode(int *code) { + unsigned short *int16p; + char buffer[2]; + filestr->read(buffer,2); + int16p = (unsigned short *) buffer; +//exist a 32bits int (code 90) with 2 bytes??? + if ((*code == 90) && (*int16p>2000)){ + DBG(*code); DBG(" de 16bits\n"); + filestr->seekg(-4, std::ios_base::cur); + filestr->read(buffer,2); + int16p = (unsigned short *) buffer; + } + *code = *int16p; + DBG(*code); DBG("\n"); + + return (filestr->good()); +}*/ + +/*bool dxfWriterBinary::readString() { + std::getline(*filestr, strData, '\0'); + DBG(strData); DBG("\n"); + return (filestr->good()); +}*/ + +/*bool dxfWriterBinary::readString(std::string *text) { + std::getline(*filestr, *text, '\0'); + DBG(*text); DBG("\n"); + return (filestr->good()); +}*/ + +bool dxfWriterBinary::writeInt16(int code, int data) { + char bufcode[2]; + char buffer[2]; + bufcode[0] =code & 0xFF; + bufcode[1] =code >> 8; + buffer[0] =data & 0xFF; + buffer[1] =data >> 8; + filestr->write(bufcode, 2); + filestr->write(buffer, 2); + return (filestr->good()); +} + +bool dxfWriterBinary::writeInt32(int code, int data) { + char buffer[4]; + buffer[0] =code & 0xFF; + buffer[1] =code >> 8; + filestr->write(buffer, 2); + + buffer[0] =data & 0xFF; + buffer[1] =data >> 8; + buffer[2] =data >> 16; + buffer[3] =data >> 24; + filestr->write(buffer, 4); + return (filestr->good()); +} + +bool dxfWriterBinary::writeInt64(int code, unsigned long long int data) { + char buffer[8]; + buffer[0] =code & 0xFF; + buffer[1] =code >> 8; + filestr->write(buffer, 2); + + buffer[0] =data & 0xFF; + buffer[1] =data >> 8; + buffer[2] =data >> 16; + buffer[3] =data >> 24; + buffer[4] =data >> 32; + buffer[5] =data >> 40; + buffer[6] =data >> 48; + buffer[7] =data >> 56; + filestr->write(buffer, 8); + return (filestr->good()); +} + +bool dxfWriterBinary::writeDouble(int code, double data) { + char bufcode[2]; + char buffer[8]; + bufcode[0] =code & 0xFF; + bufcode[1] =code >> 8; + filestr->write(bufcode, 2); + + unsigned char *val; + val = (unsigned char *) &data; + for (int i=0; i<8; i++) { + buffer[i] =val[i]; + } + filestr->write(buffer, 8); + return (filestr->good()); +} + +//saved as int or add a bool member?? +bool dxfWriterBinary::writeBool(int code, bool data) { + char buffer[1]; + char bufcode[2]; + bufcode[0] =code & 0xFF; + bufcode[1] =code >> 8; + filestr->write(bufcode, 2); + buffer[0] = data; + filestr->write(buffer, 1); + return (filestr->good()); +} + +dxfWriterAscii::dxfWriterAscii(std::ofstream *stream):dxfWriter(stream){ + filestr->precision(16); +} + +bool dxfWriterAscii::writeString(int code, std::string text) { +// *filestr << code << std::endl << text << std::endl ; + filestr->width(3); + *filestr << std::right << code << std::endl; + filestr->width(0); + *filestr << std::left << text << std::endl; + /* std::getline(*filestr, strData, '\0'); + DBG(strData); DBG("\n");*/ + return (filestr->good()); +} + +bool dxfWriterAscii::writeInt16(int code, int data) { +// *filestr << std::right << code << std::endl << data << std::endl; + filestr->width(3); + *filestr << std::right << code << std::endl; + filestr->width(5); + *filestr << data << std::endl; + return (filestr->good()); +} + +bool dxfWriterAscii::writeInt32(int code, int data) { + return writeInt16(code, data); +} + +bool dxfWriterAscii::writeInt64(int code, unsigned long long int data) { +// *filestr << code << std::endl << data << std::endl; + filestr->width(3); + *filestr << std::right << code << std::endl; + filestr->width(5); + *filestr << data << std::endl; + return (filestr->good()); +} + +bool dxfWriterAscii::writeDouble(int code, double data) { +// std::streamsize prec = filestr->precision(); +// filestr->precision(12); +// *filestr << code << std::endl << data << std::endl; + filestr->width(3); + *filestr << std::right << code << std::endl; + *filestr << data << std::endl; +// filestr->precision(prec); + return (filestr->good()); +} + +//saved as int or add a bool member?? +bool dxfWriterAscii::writeBool(int code, bool data) { + *filestr << code << std::endl << data << std::endl; + return (filestr->good()); +} + diff --git a/src/libs/vdxf/libdxfrw/intern/dxfwriter.h b/src/libs/vdxf/libdxfrw/intern/dxfwriter.h new file mode 100644 index 000000000..2af464bea --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/dxfwriter.h @@ -0,0 +1,64 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#ifndef DXFWRITER_H +#define DXFWRITER_H + +#include "drw_textcodec.h" + +class dxfWriter { +public: + dxfWriter(std::ofstream *stream){filestr = stream; /*count =0;*/} + virtual ~dxfWriter(){} + virtual bool writeString(int code, std::string text) = 0; + bool writeUtf8String(int code, std::string text); + bool writeUtf8Caps(int code, std::string text); + std::string fromUtf8String(std::string t) {return encoder.fromUtf8(t);} + virtual bool writeInt16(int code, int data) = 0; + virtual bool writeInt32(int code, int data) = 0; + virtual bool writeInt64(int code, unsigned long long int data) = 0; + virtual bool writeDouble(int code, double data) = 0; + virtual bool writeBool(int code, bool data) = 0; + void setVersion(std::string *v, bool dxfFormat){encoder.setVersion(v, dxfFormat);} + void setCodePage(std::string *c){encoder.setCodePage(c, true);} + std::string getCodePage(){return encoder.getCodePage();} +protected: + std::ofstream *filestr; +private: + DRW_TextCodec encoder; +}; + +class dxfWriterBinary : public dxfWriter { +public: + dxfWriterBinary(std::ofstream *stream):dxfWriter(stream){} + virtual ~dxfWriterBinary() {} + virtual bool writeString(int code, std::string text); + virtual bool writeInt16(int code, int data); + virtual bool writeInt32(int code, int data); + virtual bool writeInt64(int code, unsigned long long int data); + virtual bool writeDouble(int code, double data); + virtual bool writeBool(int code, bool data); +}; + +class dxfWriterAscii : public dxfWriter { +public: + dxfWriterAscii(std::ofstream *stream); + virtual ~dxfWriterAscii(){} + virtual bool writeString(int code, std::string text); + virtual bool writeInt16(int code, int data); + virtual bool writeInt32(int code, int data); + virtual bool writeInt64(int code, unsigned long long int data); + virtual bool writeDouble(int code, double data); + virtual bool writeBool(int code, bool data); +}; + +#endif // DXFWRITER_H diff --git a/src/libs/vdxf/libdxfrw/intern/rscodec.cpp b/src/libs/vdxf/libdxfrw/intern/rscodec.cpp new file mode 100644 index 000000000..78926f3fa --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/rscodec.cpp @@ -0,0 +1,401 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2014 J.F. Soriano (Rallaz), rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +/** + * Reed-Solomon codec + * Reed Solomon code lifted from encoder/decoder for Reed-Solomon written by Simon Rockliff + * + * Original code: + * This program may be freely modified and/or given to whoever wants it. + * A condition of such distribution is that the author's contribution be + * acknowledged by his name being left in the comments heading the program, + * however no responsibility is accepted for any financial or other loss which + * may result from some unforseen errors or malfunctioning of the program + * during use. + * Simon Rockliff, 26th June 1991 + */ + + +#include "rscodec.h" +#include // std::nothrow +#include + +RScodec::RScodec(unsigned int pp, int mm, int tt) { + this->mm = mm; + this->tt = tt; + nn = (1<polynomial form alpha_to[] contains j=alpha**i; + polynomial form -> index form index_of[j=alpha**i] = i + alpha=2 is the primitive element of GF(2^mm) +*/ +void RScodec::RSgenerate_gf(unsigned int pp) { + int i, mask ; + int pb; + + mask = 1 ; + alpha_to[mm] = 0 ; + for (i=0; i>(mm-1-i)) & 1; + if (pb!=0) { + alpha_to[mm] ^= mask; + } + mask <<= 1 ; + } + index_of[alpha_to[mm]] = mm ; + mask >>= 1 ; + for (i=mm+1; i= mask) { + alpha_to[i] = alpha_to[mm] ^ ((alpha_to[i-1]^mask)<<1) ; + } else alpha_to[i] = alpha_to[i-1]<<1 ; + index_of[alpha_to[i]] = i ; + } + index_of[0] = -1 ; +} + + +/* Obtain the generator polynomial of the tt-error correcting, length + nn=(2^mm -1) Reed Solomon code from the product of (X+alpha**i), i=1..2*tt +*/ +void RScodec::RSgen_poly() { + int i,j ; + int tmp; + int bb = nn-kk;; //nn-kk length of parity data + + gg[0] = 2 ; /* primitive element alpha = 2 for GF(2**mm) */ + gg[1] = 1 ; /* g(x) = (X+alpha) initially */ + for (i=2; i<=bb; i++) { + gg[i] = 1 ; + for (j=i-1; j>0; j--) + if (gg[j] != 0) { + if (gg[j]<0) { isOk=false; return; } + tmp = (index_of[gg[j]]+i)%nn; + if (tmp<0) { isOk=false; return; } + gg[j] = gg[j-1]^ alpha_to[tmp] ; + } else { + gg[j] = gg[j-1] ; + } + gg[0] = alpha_to[(index_of[gg[0]]+i)%nn] ; /* gg[0] can never be zero */ + } + /* convert gg[] to index form for quicker encoding */ + for (i=0; i<=bb; i++) gg[i] = index_of[gg[i]] ; +} + +int RScodec::calcDecode(unsigned char* data, int* recd, int** elp, int* d, int* l, int* u_lu, int* s, int* root, int* loc, int* z, int* err, int* reg, int bb) +{ + if (!isOk) return -1; + int count = 0; + int syn_error = 0; + int i, j, u, q; + + // for (int i=0; i error */ + s[i] = index_of[s[i]]; + } + + if (!syn_error) { /* if no errors, ends */ + /* no non-zero syndromes => no errors: output is received codeword */ + return 0; + } + + /* errors are present, try and correct */ + /* compute the error location polynomial via the Berlekamp iterative algorithm, + following the terminology of Lin and Costello : d[u] is the 'mu'th + discrepancy, where u='mu'+1 and 'mu' (the Greek letter!) is the step number + ranging from -1 to 2*tt (see L&C), l[u] is the + degree of the elp at that step, and u_l[u] is the difference between the + step number and the degree of the elp. + */ + /* initialise table entries */ + d[0] = 0; /* index form */ + d[1] = s[1]; /* index form */ + elp[0][0] = 0; /* index form */ + elp[1][0] = 1; /* polynomial form */ + for (i = 1; i0)) q--; + /* have found first non-zero d[q] */ + if (q>0) { + j = q; + do { + j--; + if ((d[j] != -1) && (u_lu[q]0); + } + + /* have now found q such that d[u]!=0 and u_lu[q] is maximum */ + /* store degree of new elp polynomial */ + if (l[u]>l[q] + u - q) { + l[u + 1] = l[u]; + } + else { + l[u + 1] = l[q] + u - q; + } + + /* form new elp(x) */ + for (i = 0; itt) { /* elp has degree has degree >tt hence cannot solve */ + return -1; /* just output is received codeword as is */ + } + + /* can correct error */ + /* put elp into index form */ + for (i = 0; i <= l[u]; i++) elp[u][i] = index_of[elp[u][i]]; + + /* find roots of the error location polynomial */ + for (i = 1; i <= l[u]; i++) { + reg[i] = elp[u][i]; + } + count = 0; + for (i = 1; i <= nn; i++) { + q = 1; + for (j = 1; j <= l[u]; j++) { + if (reg[j] != -1) { + reg[j] = (reg[j] + j) % nn; + q ^= alpha_to[reg[j]]; + } + } + if (!q) { /* store root and error location number indices */ + root[count] = i; + loc[count] = nn - i; + count++; + } + } + + if (count != l[u]) { /* no. roots != degree of elp => >tt errors and cannot solve */ + return -1; /* just output is received codeword as is */ + } + + /* no. roots = degree of elp hence <= tt errors */ + /* form polynomial z(x) */ + for (i = 1; i <= l[u]; i++) { /* Z[0] = 1 always - do not need */ + if ((s[i] != -1) && (elp[u][i] != -1)) { + z[i] = alpha_to[s[i]] ^ alpha_to[elp[u][i]]; + } + else if ((s[i] != -1) && (elp[u][i] == -1)) { + z[i] = alpha_to[s[i]]; + } + else if ((s[i] == -1) && (elp[u][i] != -1)) { + z[i] = alpha_to[elp[u][i]]; + } + else { + z[i] = 0; + } + for (j = 1; j=0; i--) { + feedback = index_of[idata[i]^bd[bb-1]] ; + if (feedback != -1) { + for (j=bb-1; j>0; j--) + if (gg[j] != -1) + bd[j] = bd[j-1]^alpha_to[(gg[j]+feedback)%nn] ; + else + bd[j] = bd[j-1] ; + bd[0] = alpha_to[(gg[0]+feedback)%nn] ; + } else { + for (j=bb-1; j>0; j--) + bd[j] = bd[j-1] ; + bd[0] = 0 ; + } + } + return true; +} + + +/* assume we have received bits grouped into mm-bit symbols in recd[i], + i=0..(nn-1), and recd[i] is index form (ie as powers of alpha). + We first compute the 2*tt syndromes by substituting alpha**i into rec(X) and + evaluating, storing the syndromes in s[i], i=1..2tt (leave s[0] zero) . + Then we use the Berlekamp iteration to find the error location polynomial + elp[i]. If the degree of the elp is >tt, we cannot correct all the errors + and hence just put out the information symbols uncorrected. If the degree of + elp is <=tt, we substitute alpha**i , i=1..n into the elp to get the roots, + hence the inverse roots, the error location numbers. If the number of errors + located does not equal the degree of the elp, we have more than tt errors + and cannot correct them. Otherwise, we then solve for the error value at + the error location and correct the error. The procedure is that found in + Lin and Costello. For the cases where the number of errors is known to be too + large to correct, the information symbols as received are output (the + advantage of systematic encoding is that hopefully some of the information + symbols will be okay and that if we are in luck, the errors are in the + parity part of the transmitted codeword). Of course, these insoluble cases + can be returned as error flags to the calling routine if desired. */ +/** return value: number of corrected errors or -1 if can't correct it */ +int RScodec::decode(unsigned char *data) { + if (!isOk) return -1; + int bb = nn-kk;; //nn-kk length of parity data + + int *recd = new (std::nothrow) int[nn]; + int **elp = new int*[bb + 2]; + for (int i = 0; i < bb + 2; ++i) + elp[i] = new int[bb]; + int *d = new int[bb + 2]; + int *l = new int[bb + 2]; + int *u_lu = new int[bb + 2]; + int *s = new int[bb + 1]; + int *root = new int[tt]; + int *loc = new int[tt]; + int *z = new int[tt+1]; + int *err = new int[nn]; + int *reg = new int[tt + 1]; + + int res = calcDecode(data, recd, elp ,d ,l, u_lu, s, root, loc ,z, err, reg, bb); + + delete[] recd; + for (int i = 0; i < bb + 2; ++i) + delete[] elp[i]; + delete[] elp; + delete[] d; + delete[] l; + delete[] u_lu; + delete[] s; + delete[] root; + delete[] loc; + delete[] z; + delete[] err; + delete[] reg; + + return res; +} diff --git a/src/libs/vdxf/libdxfrw/intern/rscodec.h b/src/libs/vdxf/libdxfrw/intern/rscodec.h new file mode 100644 index 000000000..10cb2a833 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/intern/rscodec.h @@ -0,0 +1,69 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2014 J.F. Soriano (Rallaz), rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +/** + * Reed-Solomon codec + * Reed Solomon code lifted from encoder/decoder for Reed-Solomon written by Simon Rockliff + * + * Original code: + * This program may be freely modified and/or given to whoever wants it. + * A condition of such distribution is that the author's contribution be + * acknowledged by his name being left in the comments heading the program, + * however no responsibility is accepted for any financial or other loss which + * may result from some unforseen errors or malfunctioning of the program + * during use. + * Simon Rockliff, 26th June 1991 + */ + + + +#ifndef RSCODEC_H +#define RSCODEC_H +/** +mm: RS code over GF(2^4) +nn: nn= (2^mm) - 1 length of codeword +tt: number of errors that can be corrected +kk: kk = nn-2*tt +pp: irreducible polynomial coeffts, pp [mm] send as int +*/ +class RScodec { +public: + RScodec(unsigned int pp, int mm, int tt); + + ~RScodec(); +// bool encode(int *data, int *parity); +// int decode(int *recd); + bool encode(unsigned char *data, unsigned char *parity); + int decode(unsigned char *data); + bool isOkey(){return isOk;} + const unsigned int* indexOf() {return index_of;} + const int* alphaTo() {return alpha_to;} + +private: + void RSgenerate_gf(unsigned int pp); + void RSgen_poly(); + int calcDecode(unsigned char* data, int* recd, int** elp, int* d, int* l, int* u_lu, int* s, int* root, int* loc, int* z, int* err, int* reg, int bb); + + +private: + int mm; //RS code over GF(2^4) + int tt; //number of errors that can be corrected + int nn; //(2^mm) - 1 length of codeword + int kk; //nn-2*tt length of original data + + int *gg; + bool isOk; + unsigned int *index_of; + int *alpha_to; +}; + +#endif // RSCODEC_H diff --git a/src/libs/vdxf/libdxfrw/libdwgr.cpp b/src/libs/vdxf/libdxfrw/libdwgr.cpp new file mode 100644 index 000000000..adca43c25 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/libdwgr.cpp @@ -0,0 +1,237 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + + +#include "libdwgr.h" +#include +#include +#include +#include "intern/drw_dbg.h" +#include "intern/drw_textcodec.h" +#include "intern/dwgreader.h" +#include "intern/dwgreader15.h" +#include "intern/dwgreader18.h" +#include "intern/dwgreader21.h" +#include "intern/dwgreader24.h" +#include "intern/dwgreader27.h" + +#define FIRSTHANDLE 48 + +/*enum sections { + secUnknown, + secHeader, + secTables, + secBlocks, + secEntities, + secObjects +};*/ + +dwgR::dwgR(){ + DRW_DBGSL(DRW_dbg::NONE); + reader = NULL; +// writer = NULL; + applyExt = false; + version = DRW::UNKNOWNV; + error = DRW::BAD_NONE; +} + +dwgR::~dwgR(){ + if (reader != NULL) + delete reader; + +} + +void dwgR::setDebug(DRW::DBG_LEVEL lvl){ + switch (lvl){ + case DRW::DEBUG: + DRW_DBGSL(DRW_dbg::DEBUG); + break; + default: + DRW_DBGSL(DRW_dbg::NONE); + } +} + +/*reads metadata and loads image preview*/ +bool dwgR::getPreview(std::istream &stream){ + bool isOk = false; + + isOk = open(&stream); + if (!isOk) + return false; + + isOk = reader->readMetaData(); + if (isOk) { + isOk = reader->readPreview(); + } else + error = DRW::BAD_READ_METADATA; + + if (reader != NULL) { + delete reader; + reader = NULL; + } + return isOk; +} + +bool dwgR::read(std::istream &stream, DRW_Interface *interface_, bool ext){ + applyExt = ext; + iface = interface_; + + bool isOk = false; + + isOk = open(&stream); + if (!isOk) + return false; + + isOk = reader->readMetaData(); + if (isOk) { + isOk = reader->readFileHeader(); + if (isOk) { + isOk = processDwg(); + } else + error = DRW::BAD_READ_FILE_HEADER; + } else + error = DRW::BAD_READ_METADATA; + + if (reader != NULL) { + delete reader; + reader = NULL; + } + + return isOk; +} + +bool dwgR::open(std::istream *stream){ + char line[7]; + stream->read (line, 6); + line[6]='\0'; + DRW_DBG("dwgR::read 2\n"); + DRW_DBG("dwgR::read line version: "); + DRW_DBG(line); + DRW_DBG("\n"); + + if (strcmp(line, "AC1006") == 0) + version = DRW::AC1006; + else if (strcmp(line, "AC1009") == 0) { + version = DRW::AC1009; +// reader = new dwgReader09(&filestr, this); + }else if (strcmp(line, "AC1012") == 0){ + version = DRW::AC1012; + reader = new dwgReader15(stream, this); + } else if (strcmp(line, "AC1014") == 0) { + version = DRW::AC1014; + reader = new dwgReader15(stream, this); + } else if (strcmp(line, "AC1015") == 0) { + version = DRW::AC1015; + reader = new dwgReader15(stream, this); + } else if (strcmp(line, "AC1018") == 0){ + version = DRW::AC1018; + reader = new dwgReader18(stream, this); + } else if (strcmp(line, "AC1021") == 0) { + version = DRW::AC1021; + reader = new dwgReader21(stream, this); + } else if (strcmp(line, "AC1024") == 0) { + version = DRW::AC1024; + reader = new dwgReader24(stream, this); + } else if (strcmp(line, "AC1027") == 0) { + version = DRW::AC1027; + reader = new dwgReader27(stream, this); + } else + version = DRW::UNKNOWNV; + + if (reader == NULL) { + error = DRW::BAD_VERSION; + return false; + } + return true; +} + +/********* Reader Process *********/ + +bool dwgR::processDwg() { + DRW_DBG("dwgR::processDwg() start processing dwg\n"); + bool ret; + bool ret2; + DRW_Header hdr; + ret = reader->readDwgHeader(hdr); + if (!ret) { + error = DRW::BAD_READ_HEADER; + } + + ret2 = reader->readDwgClasses(); + if (ret && !ret2) { + error = DRW::BAD_READ_CLASSES; + ret = ret2; + } + + ret2 = reader->readDwgHandles(); + if (ret && !ret2) { + error = DRW::BAD_READ_HANDLES; + ret = ret2; + } + + ret2 = reader->readDwgTables(hdr); + if (ret && !ret2) { + error = DRW::BAD_READ_TABLES; + ret = ret2; + } + + iface->addHeader(&hdr); + + for (std::map::iterator it=reader->ltypemap.begin(); it!=reader->ltypemap.end(); ++it) { + DRW_LType *lt = it->second; + iface->addLType(const_cast(*lt) ); + } + for (std::map::iterator it=reader->layermap.begin(); it!=reader->layermap.end(); ++it) { + DRW_Layer *ly = it->second; + iface->addLayer(const_cast(*ly)); + } + + for (std::map::iterator it=reader->stylemap.begin(); it!=reader->stylemap.end(); ++it) { + DRW_Textstyle *ly = it->second; + iface->addTextStyle(const_cast(*ly)); + } + + for (std::map::iterator it=reader->dimstylemap.begin(); it!=reader->dimstylemap.end(); ++it) { + DRW_Dimstyle *ly = it->second; + iface->addDimStyle(const_cast(*ly)); + } + + for (std::map::iterator it=reader->vportmap.begin(); it!=reader->vportmap.end(); ++it) { + DRW_Vport *ly = it->second; + iface->addVport(const_cast(*ly)); + } + + for (std::map::iterator it=reader->appIdmap.begin(); it!=reader->appIdmap.end(); ++it) { + DRW_AppId *ly = it->second; + iface->addAppId(const_cast(*ly)); + } + + ret2 = reader->readDwgBlocks(*iface); + if (ret && !ret2) { + error = DRW::BAD_READ_BLOCKS; + ret = ret2; + } + + ret2 = reader->readDwgEntities(*iface); + if (ret && !ret2) { + error = DRW::BAD_READ_ENTITIES; + ret = ret2; + } + + ret2 = reader->readDwgObjects(*iface); + if (ret && !ret2) { + error = DRW::BAD_READ_OBJECTS; + ret = ret2; + } + + return ret; +} diff --git a/src/libs/vdxf/libdxfrw/libdwgr.h b/src/libs/vdxf/libdxfrw/libdwgr.h new file mode 100644 index 000000000..060100495 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/libdwgr.h @@ -0,0 +1,50 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#ifndef LIBDWGR_H +#define LIBDWGR_H + +#include +//#include +#include "drw_entities.h" +#include "drw_objects.h" +#include "drw_classes.h" +#include "drw_interface.h" + +class dwgReader; + +class dwgR { +public: + dwgR(); + ~dwgR(); + //read: return true if all ok + bool read(std::istream &stream, DRW_Interface *interface_, bool ext); + bool getPreview(std::istream &stream); + DRW::Version getVersion(){return version;} + DRW::error getError(){return error;} + void setDebug(DRW::DBG_LEVEL lvl); + +private: + bool open(std::istream *stream); + bool processDwg(); +private: + DRW::Version version; + DRW::error error; + std::string fileName; + bool applyExt; /*apply extrusion in entities to conv in 2D?*/ + std::string codePage; + DRW_Interface *iface; + dwgReader *reader; + +}; + +#endif // LIBDWGR_H diff --git a/src/libs/vdxf/libdxfrw/libdxfrw.cpp b/src/libs/vdxf/libdxfrw/libdxfrw.cpp new file mode 100644 index 000000000..097e23bed --- /dev/null +++ b/src/libs/vdxf/libdxfrw/libdxfrw.cpp @@ -0,0 +1,2797 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + + +#include "libdxfrw.h" +#include +#include +#include +#include +#include "intern/drw_textcodec.h" +#include "intern/dxfreader.h" +#include "intern/dxfwriter.h" +#include "intern/drw_dbg.h" + +#define FIRSTHANDLE 48 + +/*enum sections { + secUnknown, + secHeader, + secTables, + secBlocks, + secEntities, + secObjects +};*/ + +dxfRW::dxfRW(const char* name){ + DRW_DBGSL(DRW_dbg::NONE); + fileName = name; + reader = NULL; + writer = NULL; + applyExt = false; + elParts = 128; //parts munber when convert ellipse to polyline +} +dxfRW::~dxfRW(){ + if (reader != NULL) + delete reader; + if (writer != NULL) + delete writer; + for (std::vector::iterator it=imageDef.begin(); it!=imageDef.end(); ++it) + delete *it; + + imageDef.clear(); +} + +void dxfRW::setDebug(DRW::DBG_LEVEL lvl){ + switch (lvl){ + case DRW::DEBUG: + DRW_DBGSL(DRW_dbg::DEBUG); + break; + default: + DRW_DBGSL(DRW_dbg::NONE); + } +} + +bool dxfRW::read(DRW_Interface *interface_, bool ext){ + drw_assert(fileName.empty() == false); + bool isOk = false; + applyExt = ext; + std::ifstream filestr; + if ( interface_ == NULL ) + return isOk; + DRW_DBG("dxfRW::read 1def\n"); + filestr.open (fileName.c_str(), std::ios_base::in | std::ios::binary); + if (!filestr.is_open()) + return isOk; + if (!filestr.good()) + return isOk; + + char line[22]; + char line2[22] = "AutoCAD Binary DXF\r\n"; + line2[20] = (char)26; + line2[21] = '\0'; + filestr.read (line, 22); + filestr.close(); + iface = interface_; + DRW_DBG("dxfRW::read 2\n"); + if (strcmp(line, line2) == 0) { + filestr.open (fileName.c_str(), std::ios_base::in | std::ios::binary); + binFile = true; + //skip sentinel + filestr.seekg (22, std::ios::beg); + reader = new dxfReaderBinary(&filestr); + DRW_DBG("dxfRW::read binary file\n"); + } else { + binFile = false; + filestr.open (fileName.c_str(), std::ios_base::in); + reader = new dxfReaderAscii(&filestr); + } + + isOk = processDxf(); + filestr.close(); + delete reader; + reader = NULL; + return isOk; +} + +bool dxfRW::write(DRW_Interface *interface_, DRW::Version ver, bool bin){ + bool isOk = false; + std::ofstream filestr; + version = ver; + binFile = bin; + iface = interface_; + if (binFile) { + filestr.open (fileName.c_str(), std::ios_base::out | std::ios::binary | std::ios::trunc); + //write sentinel + filestr << "AutoCAD Binary DXF\r\n" << (char)26 << '\0'; + writer = new dxfWriterBinary(&filestr); + DRW_DBG("dxfRW::read binary file\n"); + } else { + filestr.open (fileName.c_str(), std::ios_base::out | std::ios::trunc); + writer = new dxfWriterAscii(&filestr); + std::string comm = std::string("dxfrw ") + std::string(DRW_VERSION); + writer->writeString(999, comm); + } + DRW_Header header; + iface->writeHeader(header); + writer->writeString(0, "SECTION"); + entCount =FIRSTHANDLE; + header.write(writer, version); + writer->writeString(0, "ENDSEC"); + if (ver > DRW::AC1009) { + writer->writeString(0, "SECTION"); + writer->writeString(2, "CLASSES"); + writer->writeString(0, "ENDSEC"); + } + writer->writeString(0, "SECTION"); + writer->writeString(2, "TABLES"); + writeTables(); + writer->writeString(0, "ENDSEC"); + writer->writeString(0, "SECTION"); + writer->writeString(2, "BLOCKS"); + writeBlocks(); + writer->writeString(0, "ENDSEC"); + + writer->writeString(0, "SECTION"); + writer->writeString(2, "ENTITIES"); + iface->writeEntities(); + writer->writeString(0, "ENDSEC"); + + if (version > DRW::AC1009) { + writer->writeString(0, "SECTION"); + writer->writeString(2, "OBJECTS"); + writeObjects(); + writer->writeString(0, "ENDSEC"); + } + writer->writeString(0, "EOF"); + filestr.flush(); + filestr.close(); + isOk = true; + delete writer; + writer = NULL; + return isOk; +} + +bool dxfRW::writeEntity(DRW_Entity *ent) { + ent->handle = ++entCount; + writer->writeString(5, toHexStr(ent->handle)); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbEntity"); + } + if (ent->space == 1) + writer->writeInt16(67, 1); + if (version > DRW::AC1009) { + writer->writeUtf8String(8, ent->layer); + writer->writeUtf8String(6, ent->lineType); + } else { + writer->writeUtf8Caps(8, ent->layer); + writer->writeUtf8Caps(6, ent->lineType); + } + writer->writeInt16(62, ent->color); + if (version > DRW::AC1015 && ent->color24 >= 0) { + writer->writeInt32(420, ent->color24); + } + if (version > DRW::AC1014) { + writer->writeInt16(370, DRW_LW_Conv::lineWidth2dxfInt(ent->lWeight)); + } + return true; +} + +bool dxfRW::writeLineType(DRW_LType *ent){ + std::string strname = ent->name; + + transform(strname.begin(), strname.end(), strname.begin(),::toupper); +//do not write linetypes handled by library + if (strname == "BYLAYER" || strname == "BYBLOCK" || strname == "CONTINUOUS") { + return true; + } + writer->writeString(0, "LTYPE"); + if (version > DRW::AC1009) { + writer->writeString(5, toHexStr(++entCount)); + if (version > DRW::AC1012) { + writer->writeString(330, "5"); + } + writer->writeString(100, "AcDbSymbolTableRecord"); + writer->writeString(100, "AcDbLinetypeTableRecord"); + writer->writeUtf8String(2, ent->name); + } else + writer->writeUtf8Caps(2, ent->name); + writer->writeInt16(70, ent->flags); + writer->writeUtf8String(3, ent->desc); + ent->update(); + writer->writeInt16(72, 65); + writer->writeInt16(73, ent->size); + writer->writeDouble(40, ent->length); + + for (unsigned int i = 0; i< ent->path.size(); i++){ + writer->writeDouble(49, ent->path.at(i)); + if (version > DRW::AC1009) { + writer->writeInt16(74, 0); + } + } + return true; +} + +bool dxfRW::writeLayer(DRW_Layer *ent){ + writer->writeString(0, "LAYER"); + if (!wlayer0 && ent->name == "0") { + wlayer0 = true; + if (version > DRW::AC1009) { + writer->writeString(5, "10"); + } + } else { + if (version > DRW::AC1009) { + writer->writeString(5, toHexStr(++entCount)); + } + } + if (version > DRW::AC1012) { + writer->writeString(330, "2"); + } + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbSymbolTableRecord"); + writer->writeString(100, "AcDbLayerTableRecord"); + writer->writeUtf8String(2, ent->name); + } else { + writer->writeUtf8Caps(2, ent->name); + } + writer->writeInt16(70, ent->flags); + writer->writeInt16(62, ent->color); + if (version > DRW::AC1015 && ent->color24 >= 0) { + writer->writeInt32(420, ent->color24); + } + if (version > DRW::AC1009) { + writer->writeUtf8String(6, ent->lineType); + if (! ent->plotF) + writer->writeBool(290, ent->plotF); + writer->writeInt16(370, DRW_LW_Conv::lineWidth2dxfInt(ent->lWeight)); + writer->writeString(390, "F"); + } else + writer->writeUtf8Caps(6, ent->lineType); + if (!ent->extData.empty()){ + writeExtData(ent->extData); + } +// writer->writeString(347, "10012"); + return true; +} + +bool dxfRW::writeTextstyle(DRW_Textstyle *ent){ + writer->writeString(0, "STYLE"); + if (!dimstyleStd) { + //stringstream cause crash in OS/X, bug#3597944 + std::string name=ent->name; + transform(name.begin(), name.end(), name.begin(), toupper); + if (name == "STANDARD") + dimstyleStd = true; + } + if (version > DRW::AC1009) { + writer->writeString(5, toHexStr(++entCount)); + } + + if (version > DRW::AC1012) { + writer->writeString(330, "2"); + } + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbSymbolTableRecord"); + writer->writeString(100, "AcDbTextStyleTableRecord"); + writer->writeUtf8String(2, ent->name); + } else { + writer->writeUtf8Caps(2, ent->name); + } + writer->writeInt16(70, ent->flags); + writer->writeDouble(40, ent->height); + writer->writeDouble(41, ent->width); + writer->writeDouble(50, ent->oblique); + writer->writeInt16(71, ent->genFlag); + writer->writeDouble(42, ent->lastHeight); + if (version > DRW::AC1009) { + writer->writeUtf8String(3, ent->font); + writer->writeUtf8String(4, ent->bigFont); + writer->writeUtf8String(1001, "ACAD"); + writer->writeUtf8String(1000, ent->font); + if (ent->fontFamily != 0) + writer->writeInt32(1071, ent->fontFamily); + } else { + writer->writeUtf8Caps(3, ent->font); + writer->writeUtf8Caps(4, ent->bigFont); + } + return true; +} + +bool dxfRW::writeVport(DRW_Vport *ent){ + if (!dimstyleStd) { + ent->name = "*ACTIVE"; + dimstyleStd = true; + } + writer->writeString(0, "VPORT"); + if (version > DRW::AC1009) { + writer->writeString(5, toHexStr(++entCount)); + if (version > DRW::AC1012) + writer->writeString(330, "2"); + writer->writeString(100, "AcDbSymbolTableRecord"); + writer->writeString(100, "AcDbViewportTableRecord"); + writer->writeUtf8String(2, ent->name); + } else + writer->writeUtf8Caps(2, ent->name); + writer->writeInt16(70, ent->flags); + writer->writeDouble(10, ent->lowerLeft.x); + writer->writeDouble(20, ent->lowerLeft.y); + writer->writeDouble(11, ent->UpperRight.x); + writer->writeDouble(21, ent->UpperRight.y); + writer->writeDouble(12, ent->center.x); + writer->writeDouble(22, ent->center.y); + writer->writeDouble(13, ent->snapBase.x); + writer->writeDouble(23, ent->snapBase.y); + writer->writeDouble(14, ent->snapSpacing.x); + writer->writeDouble(24, ent->snapSpacing.y); + writer->writeDouble(15, ent->gridSpacing.x); + writer->writeDouble(25, ent->gridSpacing.y); + writer->writeDouble(16, ent->viewDir.x); + writer->writeDouble(26, ent->viewDir.y); + writer->writeDouble(36, ent->viewDir.z); + writer->writeDouble(17, ent->viewTarget.z); + writer->writeDouble(27, ent->viewTarget.z); + writer->writeDouble(37, ent->viewTarget.z); + writer->writeDouble(40, ent->height); + writer->writeDouble(41, ent->ratio); + writer->writeDouble(42, ent->lensHeight); + writer->writeDouble(43, ent->frontClip); + writer->writeDouble(44, ent->backClip); + writer->writeDouble(50, ent->snapAngle); + writer->writeDouble(51, ent->twistAngle); + writer->writeInt16(71, ent->viewMode); + writer->writeInt16(72, ent->circleZoom); + writer->writeInt16(73, ent->fastZoom); + writer->writeInt16(74, ent->ucsIcon); + writer->writeInt16(75, ent->snap); + writer->writeInt16(76, ent->grid); + writer->writeInt16(77, ent->snapStyle); + writer->writeInt16(78, ent->snapIsopair); + if (version > DRW::AC1014) { + writer->writeInt16(281, 0); + writer->writeInt16(65, 1); + writer->writeDouble(110, 0.0); + writer->writeDouble(120, 0.0); + writer->writeDouble(130, 0.0); + writer->writeDouble(111, 1.0); + writer->writeDouble(121, 0.0); + writer->writeDouble(131, 0.0); + writer->writeDouble(112, 0.0); + writer->writeDouble(122, 1.0); + writer->writeDouble(132, 0.0); + writer->writeInt16(79, 0); + writer->writeDouble(146, 0.0); + if (version > DRW::AC1018) { + writer->writeString(348, "10020"); + writer->writeInt16(60, ent->gridBehavior);//v2007 undocummented see DRW_Vport class + writer->writeInt16(61, 5); + writer->writeBool(292, 1); + writer->writeInt16(282, 1); + writer->writeDouble(141, 0.0); + writer->writeDouble(142, 0.0); + writer->writeInt16(63, 250); + writer->writeInt32(421, 3358443); + } + } + return true; +} + +bool dxfRW::writeDimstyle(DRW_Dimstyle *ent){ + writer->writeString(0, "DIMSTYLE"); + if (!dimstyleStd) { + std::string name = ent->name; + std::transform(name.begin(), name.end(), name.begin(),::toupper); + if (name == "STANDARD") + dimstyleStd = true; + } + if (version > DRW::AC1009) { + writer->writeString(105, toHexStr(++entCount)); + } + + if (version > DRW::AC1012) { + writer->writeString(330, "A"); + } + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbSymbolTableRecord"); + writer->writeString(100, "AcDbDimStyleTableRecord"); + writer->writeUtf8String(2, ent->name); + } else + writer->writeUtf8Caps(2, ent->name); + writer->writeInt16(70, ent->flags); + if ( version == DRW::AC1009 || !(ent->dimpost.empty()) ) + writer->writeUtf8String(3, ent->dimpost); + if ( version == DRW::AC1009 || !(ent->dimapost.empty()) ) + writer->writeUtf8String(4, ent->dimapost); + if ( version == DRW::AC1009 || !(ent->dimblk.empty()) ) + writer->writeUtf8String(5, ent->dimblk); + if ( version == DRW::AC1009 || !(ent->dimblk1.empty()) ) + writer->writeUtf8String(6, ent->dimblk1); + if ( version == DRW::AC1009 || !(ent->dimblk2.empty()) ) + writer->writeUtf8String(7, ent->dimblk2); + writer->writeDouble(40, ent->dimscale); + writer->writeDouble(41, ent->dimasz); + writer->writeDouble(42, ent->dimexo); + writer->writeDouble(43, ent->dimdli); + writer->writeDouble(44, ent->dimexe); + writer->writeDouble(45, ent->dimrnd); + writer->writeDouble(46, ent->dimdle); + writer->writeDouble(47, ent->dimtp); + writer->writeDouble(48, ent->dimtm); + writer->writeDouble(140, ent->dimtxt); + writer->writeDouble(141, ent->dimcen); + writer->writeDouble(142, ent->dimtsz); + writer->writeDouble(143, ent->dimaltf); + writer->writeDouble(144, ent->dimlfac); + writer->writeDouble(145, ent->dimtvp); + writer->writeDouble(146, ent->dimtfac); + writer->writeDouble(147, ent->dimgap); + if (version > DRW::AC1014) { + writer->writeDouble(148, ent->dimaltrnd); + } + writer->writeInt16(71, ent->dimtol); + writer->writeInt16(72, ent->dimlim); + writer->writeInt16(73, ent->dimtih); + writer->writeInt16(74, ent->dimtoh); + writer->writeInt16(75, ent->dimse1); + writer->writeInt16(76, ent->dimse2); + writer->writeInt16(77, ent->dimtad); + writer->writeInt16(78, ent->dimzin); + if (version > DRW::AC1014) { + writer->writeInt16(79, ent->dimazin); + } + writer->writeInt16(170, ent->dimalt); + writer->writeInt16(171, ent->dimaltd); + writer->writeInt16(172, ent->dimtofl); + writer->writeInt16(173, ent->dimsah); + writer->writeInt16(174, ent->dimtix); + writer->writeInt16(175, ent->dimsoxd); + writer->writeInt16(176, ent->dimclrd); + writer->writeInt16(177, ent->dimclre); + writer->writeInt16(178, ent->dimclrt); + if (version > DRW::AC1014) { + writer->writeInt16(179, ent->dimadec); + } + if (version > DRW::AC1009) { + if (version < DRW::AC1015) + writer->writeInt16(270, ent->dimunit); + writer->writeInt16(271, ent->dimdec); + writer->writeInt16(272, ent->dimtdec); + writer->writeInt16(273, ent->dimaltu); + writer->writeInt16(274, ent->dimalttd); + writer->writeInt16(275, ent->dimaunit); + } + if (version > DRW::AC1014) { + writer->writeInt16(276, ent->dimfrac); + writer->writeInt16(277, ent->dimlunit); + writer->writeInt16(278, ent->dimdsep); + writer->writeInt16(279, ent->dimtmove); + } + if (version > DRW::AC1009) { + writer->writeInt16(280, ent->dimjust); + writer->writeInt16(281, ent->dimsd1); + writer->writeInt16(282, ent->dimsd2); + writer->writeInt16(283, ent->dimtolj); + writer->writeInt16(284, ent->dimtzin); + writer->writeInt16(285, ent->dimaltz); + writer->writeInt16(286, ent->dimaltttz); + if (version < DRW::AC1015) + writer->writeInt16(287, ent->dimfit); + writer->writeInt16(288, ent->dimupt); + } + if (version > DRW::AC1014) { + writer->writeInt16(289, ent->dimatfit); + } + if (version > DRW::AC1009 && !ent->dimtxsty.empty()) { + writer->writeUtf8String(340, ent->dimtxsty); + } + if (version > DRW::AC1014) { + writer->writeUtf8String(341, ent->dimldrblk); + writer->writeInt16(371, ent->dimlwd); + writer->writeInt16(372, ent->dimlwe); + } + return true; +} + +bool dxfRW::writeAppId(DRW_AppId *ent){ + std::string strname = ent->name; + transform(strname.begin(), strname.end(), strname.begin(),::toupper); +//do not write mandatory ACAD appId, handled by library + if (strname == "ACAD") + return true; + writer->writeString(0, "APPID"); + if (version > DRW::AC1009) { + writer->writeString(5, toHexStr(++entCount)); + if (version > DRW::AC1014) { + writer->writeString(330, "9"); + } + writer->writeString(100, "AcDbSymbolTableRecord"); + writer->writeString(100, "AcDbRegAppTableRecord"); + writer->writeUtf8String(2, ent->name); + } else { + writer->writeUtf8Caps(2, ent->name); + } + writer->writeInt16(70, ent->flags); + return true; +} + +bool dxfRW::writePoint(DRW_Point *ent) { + writer->writeString(0, "POINT"); + writeEntity(ent); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbPoint"); + } + writer->writeDouble(10, ent->basePoint.x); + writer->writeDouble(20, ent->basePoint.y); + if (ent->basePoint.z != 0.0) { + writer->writeDouble(30, ent->basePoint.z); + } + return true; +} + +bool dxfRW::writeLine(DRW_Line *ent) { + writer->writeString(0, "LINE"); + writeEntity(ent); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbLine"); + } + writer->writeDouble(10, ent->basePoint.x); + writer->writeDouble(20, ent->basePoint.y); + if (ent->basePoint.z != 0.0 || ent->secPoint.z != 0.0) { + writer->writeDouble(30, ent->basePoint.z); + writer->writeDouble(11, ent->secPoint.x); + writer->writeDouble(21, ent->secPoint.y); + writer->writeDouble(31, ent->secPoint.z); + } else { + writer->writeDouble(11, ent->secPoint.x); + writer->writeDouble(21, ent->secPoint.y); + } + return true; +} + +bool dxfRW::writeRay(DRW_Ray *ent) { + writer->writeString(0, "RAY"); + writeEntity(ent); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbRay"); + } + DRW_Coord crd = ent->secPoint; + crd.unitize(); + writer->writeDouble(10, ent->basePoint.x); + writer->writeDouble(20, ent->basePoint.y); + if (ent->basePoint.z != 0.0 || ent->secPoint.z != 0.0) { + writer->writeDouble(30, ent->basePoint.z); + writer->writeDouble(11, crd.x); + writer->writeDouble(21, crd.y); + writer->writeDouble(31, crd.z); + } else { + writer->writeDouble(11, crd.x); + writer->writeDouble(21, crd.y); + } + return true; +} + +bool dxfRW::writeXline(DRW_Xline *ent) { + writer->writeString(0, "XLINE"); + writeEntity(ent); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbXline"); + } + DRW_Coord crd = ent->secPoint; + crd.unitize(); + writer->writeDouble(10, ent->basePoint.x); + writer->writeDouble(20, ent->basePoint.y); + if (ent->basePoint.z != 0.0 || ent->secPoint.z != 0.0) { + writer->writeDouble(30, ent->basePoint.z); + writer->writeDouble(11, crd.x); + writer->writeDouble(21, crd.y); + writer->writeDouble(31, crd.z); + } else { + writer->writeDouble(11, crd.x); + writer->writeDouble(21, crd.y); + } + return true; +} + +bool dxfRW::writeCircle(DRW_Circle *ent) { + writer->writeString(0, "CIRCLE"); + writeEntity(ent); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbCircle"); + } + writer->writeDouble(10, ent->basePoint.x); + writer->writeDouble(20, ent->basePoint.y); + if (ent->basePoint.z != 0.0) { + writer->writeDouble(30, ent->basePoint.z); + } + writer->writeDouble(40, ent->radious); + return true; +} + +bool dxfRW::writeArc(DRW_Arc *ent) { + writer->writeString(0, "ARC"); + writeEntity(ent); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbCircle"); + } + writer->writeDouble(10, ent->basePoint.x); + writer->writeDouble(20, ent->basePoint.y); + if (ent->basePoint.z != 0.0) { + writer->writeDouble(30, ent->basePoint.z); + } + writer->writeDouble(40, ent->radious); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbArc"); + } + writer->writeDouble(50, ent->staangle*ARAD); + writer->writeDouble(51, ent->endangle*ARAD); + return true; +} + +bool dxfRW::writeEllipse(DRW_Ellipse *ent){ + //verify axis/ratio and params for full ellipse + ent->correctAxis(); + if (version > DRW::AC1009) { + writer->writeString(0, "ELLIPSE"); + writeEntity(ent); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbEllipse"); + } + writer->writeDouble(10, ent->basePoint.x); + writer->writeDouble(20, ent->basePoint.y); + writer->writeDouble(30, ent->basePoint.z); + writer->writeDouble(11, ent->secPoint.x); + writer->writeDouble(21, ent->secPoint.y); + writer->writeDouble(31, ent->secPoint.z); + writer->writeDouble(40, ent->ratio); + writer->writeDouble(41, ent->staparam); + writer->writeDouble(42, ent->endparam); + } else { + DRW_Polyline pol; + //RLZ: copy properties + ent->toPolyline(&pol, elParts); + writePolyline(&pol); + } + return true; +} + +bool dxfRW::writeTrace(DRW_Trace *ent){ + writer->writeString(0, "TRACE"); + writeEntity(ent); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbTrace"); + } + writer->writeDouble(10, ent->basePoint.x); + writer->writeDouble(20, ent->basePoint.y); + writer->writeDouble(30, ent->basePoint.z); + writer->writeDouble(11, ent->secPoint.x); + writer->writeDouble(21, ent->secPoint.y); + writer->writeDouble(31, ent->secPoint.z); + writer->writeDouble(12, ent->thirdPoint.x); + writer->writeDouble(22, ent->thirdPoint.y); + writer->writeDouble(32, ent->thirdPoint.z); + writer->writeDouble(13, ent->fourPoint.x); + writer->writeDouble(23, ent->fourPoint.y); + writer->writeDouble(33, ent->fourPoint.z); + return true; +} + +bool dxfRW::writeSolid(DRW_Solid *ent){ + writer->writeString(0, "SOLID"); + writeEntity(ent); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbTrace"); + } + writer->writeDouble(10, ent->basePoint.x); + writer->writeDouble(20, ent->basePoint.y); + writer->writeDouble(30, ent->basePoint.z); + writer->writeDouble(11, ent->secPoint.x); + writer->writeDouble(21, ent->secPoint.y); + writer->writeDouble(31, ent->secPoint.z); + writer->writeDouble(12, ent->thirdPoint.x); + writer->writeDouble(22, ent->thirdPoint.y); + writer->writeDouble(32, ent->thirdPoint.z); + writer->writeDouble(13, ent->fourPoint.x); + writer->writeDouble(23, ent->fourPoint.y); + writer->writeDouble(33, ent->fourPoint.z); + return true; +} + +bool dxfRW::write3dface(DRW_3Dface *ent){ + writer->writeString(0, "3DFACE"); + writeEntity(ent); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbFace"); + } + writer->writeDouble(10, ent->basePoint.x); + writer->writeDouble(20, ent->basePoint.y); + writer->writeDouble(30, ent->basePoint.z); + writer->writeDouble(11, ent->secPoint.x); + writer->writeDouble(21, ent->secPoint.y); + writer->writeDouble(31, ent->secPoint.z); + writer->writeDouble(12, ent->thirdPoint.x); + writer->writeDouble(22, ent->thirdPoint.y); + writer->writeDouble(32, ent->thirdPoint.z); + writer->writeDouble(13, ent->fourPoint.x); + writer->writeDouble(23, ent->fourPoint.y); + writer->writeDouble(33, ent->fourPoint.z); + writer->writeInt16(70, ent->invisibleflag); + return true; +} + +bool dxfRW::writeLWPolyline(DRW_LWPolyline *ent){ + if (version > DRW::AC1009) { + writer->writeString(0, "LWPOLYLINE"); + writeEntity(ent); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbPolyline"); + } + ent->vertexnum = (int)ent->vertlist.size(); + writer->writeInt32(90, ent->vertexnum); + writer->writeInt16(70, ent->flags); + writer->writeDouble(43, ent->width); + if (ent->elevation != 0) + writer->writeDouble(38, ent->elevation); + if (ent->thickness != 0) + writer->writeDouble(39, ent->thickness); + for (int i = 0; i< ent->vertexnum; i++){ + DRW_Vertex2D *v = ent->vertlist.at(i); + writer->writeDouble(10, v->x); + writer->writeDouble(20, v->y); + if (v->stawidth != 0) + writer->writeDouble(40, v->stawidth); + if (v->endwidth != 0) + writer->writeDouble(41, v->endwidth); + if (v->bulge != 0) + writer->writeDouble(42, v->bulge); + } + } else { + //RLZ: TODO convert lwpolyline in polyline (not exist in acad 12) + } + return true; +} + +bool dxfRW::writePolyline(DRW_Polyline *ent) { + writer->writeString(0, "POLYLINE"); + writeEntity(ent); + bool is3d = false; + if (version > DRW::AC1009) { + if (ent->flags & 8 || ent->flags & 16) { + writer->writeString(100, "AcDb3dPolyline"); + is3d = true; + } else { + writer->writeString(100, "AcDb2dPolyline"); + } + } else + writer->writeInt16(66, 1); + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, ent->basePoint.z); + if (ent->thickness != 0) { + writer->writeDouble(39, ent->thickness); + } + writer->writeInt16(70, ent->flags); + if (ent->defstawidth != 0) { + writer->writeDouble(40, ent->defstawidth); + } + if (ent->defendwidth != 0) { + writer->writeDouble(41, ent->defendwidth); + } + if (ent->flags & 16 || ent->flags & 32) { + writer->writeInt16(71, ent->vertexcount); + writer->writeInt16(72, ent->facecount); + } + if (ent->smoothM != 0) { + writer->writeInt16(73, ent->smoothM); + } + if (ent->smoothN != 0) { + writer->writeInt16(74, ent->smoothN); + } + if (ent->curvetype != 0) { + writer->writeInt16(75, ent->curvetype); + } + DRW_Coord crd = ent->extPoint; + if (crd.x != 0 || crd.y != 0 || crd.z != 1) { + writer->writeDouble(210, crd.x); + writer->writeDouble(220, crd.y); + writer->writeDouble(230, crd.z); + } + + size_t vertexnum = ent->vertlist.size(); + for (size_t i = 0; i < vertexnum; i++) { + DRW_Vertex *v = ent->vertlist.at(i); + writer->writeString(0, "VERTEX"); + writeEntity(ent); + if (version > DRW::AC1009) + { + writer->writeString(100, "AcDbVertex"); + if(is3d) { + writer->writeString(100, "AcDb3dPolylineVertex"); + } else { + writer->writeString(100, "AcDb2dVertex"); + } + } + if ( (v->flags & 128) && !(v->flags & 64) ) { + writer->writeDouble(10, 0); + writer->writeDouble(20, 0); + writer->writeDouble(30, 0); + } else { + writer->writeDouble(10, v->basePoint.x); + writer->writeDouble(20, v->basePoint.y); + writer->writeDouble(30, v->basePoint.z); + } + if (v->stawidth != 0) + writer->writeDouble(40, v->stawidth); + if (v->endwidth != 0) + writer->writeDouble(41, v->endwidth); + if (v->bulge != 0) + writer->writeDouble(42, v->bulge); + if (v->flags != 0) { + writer->writeInt16(70, ent->flags); + } + if (v->flags & 2) { + writer->writeDouble(50, v->tgdir); + } + if ( v->flags & 128 ) { + if (v->vindex1 != 0) { + writer->writeInt16(71, v->vindex1); + } + if (v->vindex2 != 0) { + writer->writeInt16(72, v->vindex2); + } + if (v->vindex3 != 0) { + writer->writeInt16(73, v->vindex3); + } + if (v->vindex4 != 0) { + writer->writeInt16(74, v->vindex4); + } + if ( !(v->flags & 64) ) { + writer->writeInt32(91, v->identifier); + } + } + } + writer->writeString(0, "SEQEND"); + writeEntity(ent); + return true; +} + +bool dxfRW::writeSpline(DRW_Spline *ent){ + if (version > DRW::AC1009) { + writer->writeString(0, "SPLINE"); + writeEntity(ent); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbSpline"); + } + writer->writeDouble(210, ent->normalVec.x); + writer->writeDouble(220, ent->normalVec.y); + writer->writeDouble(230, ent->normalVec.z); + writer->writeInt16(70, ent->flags); + writer->writeInt16(71, ent->degree); + writer->writeInt16(72, ent->nknots); + writer->writeInt16(73, ent->ncontrol); + writer->writeInt16(74, ent->nfit); + writer->writeDouble(42, ent->tolknot); + writer->writeDouble(43, ent->tolcontrol); + //RLZ: warning check if nknots are correct and ncontrol + for (int i = 0; i< ent->nknots; i++){ + writer->writeDouble(40, ent->knotslist.at(i)); + } + for (int i = 0; i< (int)ent->weightlist.size(); i++) { + writer->writeDouble(41, ent->weightlist.at(i)); + } + for (int i = 0; i< ent->ncontrol; i++){ + DRW_Coord *crd = ent->controllist.at(i); + writer->writeDouble(10, crd->x); + writer->writeDouble(20, crd->y); + writer->writeDouble(30, crd->z); + } + } else { + //RLZ: TODO convert spline in polyline (not exist in acad 12) + } + return true; +} + +bool dxfRW::writeHatch(DRW_Hatch *ent){ + if (version > DRW::AC1009) { + writer->writeString(0, "HATCH"); + writeEntity(ent); + writer->writeString(100, "AcDbHatch"); + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, ent->basePoint.z); + writer->writeDouble(210, ent->extPoint.x); + writer->writeDouble(220, ent->extPoint.y); + writer->writeDouble(230, ent->extPoint.z); + writer->writeString(2, ent->name); + writer->writeInt16(70, ent->solid); + writer->writeInt16(71, ent->associative); + ent->loopsnum = (int)ent->looplist.size(); + writer->writeInt16(91, ent->loopsnum); + //write paths data + for (int i = 0; i< ent->loopsnum; i++){ + DRW_HatchLoop *loop = ent->looplist.at(i); + writer->writeInt16(92, loop->type); + if ( (loop->type & 2) == 2){ + //RLZ: polyline boundary writeme + } else { + //boundary path + loop->update(); + writer->writeInt16(93, loop->numedges); + for (int j = 0; jnumedges; ++j) { + switch ( (loop->objlist.at(j))->eType) { + case DRW::LINE: { + writer->writeInt16(72, 1); + DRW_Line* l = (DRW_Line*)loop->objlist.at(j); + writer->writeDouble(10, l->basePoint.x); + writer->writeDouble(20, l->basePoint.y); + writer->writeDouble(11, l->secPoint.x); + writer->writeDouble(21, l->secPoint.y); + break; } + case DRW::ARC: { + writer->writeInt16(72, 2); + DRW_Arc* a = (DRW_Arc*)loop->objlist.at(j); + writer->writeDouble(10, a->basePoint.x); + writer->writeDouble(20, a->basePoint.y); + writer->writeDouble(40, a->radious); + writer->writeDouble(50, a->staangle*ARAD); + writer->writeDouble(51, a->endangle*ARAD); + writer->writeInt16(73, a->isccw); + break; } + case DRW::ELLIPSE: { + writer->writeInt16(72, 3); + DRW_Ellipse* a = (DRW_Ellipse*)loop->objlist.at(j); + a->correctAxis(); + writer->writeDouble(10, a->basePoint.x); + writer->writeDouble(20, a->basePoint.y); + writer->writeDouble(11, a->secPoint.x); + writer->writeDouble(21, a->secPoint.y); + writer->writeDouble(40, a->ratio); + writer->writeDouble(50, a->staparam*ARAD); + writer->writeDouble(51, a->endparam*ARAD); + writer->writeInt16(73, a->isccw); + break; } + case DRW::SPLINE: + //RLZ: spline boundary writeme +// writer->writeInt16(72, 4); + break; + default: + break; + } + } + writer->writeInt16(97, 0); + } + } + writer->writeInt16(75, ent->hstyle); + writer->writeInt16(76, ent->hpattern); + if (!ent->solid){ + writer->writeDouble(52, ent->angle); + writer->writeDouble(41, ent->scale); + writer->writeInt16(77, ent->doubleflag); + writer->writeInt16(78, ent->deflines); + } +/* if (ent->deflines > 0){ + writer->writeInt16(78, ent->deflines); + }*/ + writer->writeInt32(98, 0); + } else { + //RLZ: TODO verify in acad12 + } + return true; +} + +bool dxfRW::writeLeader(DRW_Leader *ent){ + if (version > DRW::AC1009) { + writer->writeString(0, "LEADER"); + writeEntity(ent); + writer->writeString(100, "AcDbLeader"); + writer->writeUtf8String(3, ent->style); + writer->writeInt16(71, ent->arrow); + writer->writeInt16(72, ent->leadertype); + writer->writeInt16(73, ent->flag); + writer->writeInt16(74, ent->hookline); + writer->writeInt16(75, ent->hookflag); + writer->writeDouble(40, ent->textheight); + writer->writeDouble(41, ent->textwidth); + writer->writeDouble(76, ent->vertnum); + writer->writeDouble(76, ent->vertexlist.size()); + for (unsigned int i=0; ivertexlist.size(); i++) { + DRW_Coord *vert = ent->vertexlist.at(i); + writer->writeDouble(10, vert->x); + writer->writeDouble(20, vert->y); + writer->writeDouble(30, vert->z); + } + } else { + //RLZ: todo not supported by acad 12 saved as unnamed block + } + return true; +} +bool dxfRW::writeDimension(DRW_Dimension *ent) { + if (version > DRW::AC1009) { + writer->writeString(0, "DIMENSION"); + writeEntity(ent); + writer->writeString(100, "AcDbDimension"); + if (!ent->getName().empty()){ + writer->writeString(2, ent->getName()); + } + writer->writeDouble(10, ent->getDefPoint().x); + writer->writeDouble(20, ent->getDefPoint().y); + writer->writeDouble(30, ent->getDefPoint().z); + writer->writeDouble(11, ent->getTextPoint().x); + writer->writeDouble(21, ent->getTextPoint().y); + writer->writeDouble(31, ent->getTextPoint().z); + if ( !(ent->type & 32)) + ent->type = ent->type +32; + writer->writeInt16(70, ent->type); + if ( !(ent->getText().empty()) ) + writer->writeUtf8String(1, ent->getText()); + writer->writeInt16(71, ent->getAlign()); + if ( ent->getTextLineStyle() != 1) + writer->writeInt16(72, ent->getTextLineStyle()); + if ( ent->getTextLineFactor() != 1) + writer->writeDouble(41, ent->getTextLineFactor()); + writer->writeUtf8String(3, ent->getStyle()); + if ( ent->getTextLineFactor() != 0) + writer->writeDouble(53, ent->getDir()); + writer->writeDouble(210, ent->getExtrusion().x); + writer->writeDouble(220, ent->getExtrusion().y); + writer->writeDouble(230, ent->getExtrusion().z); + if ( ent->hasActualMeasurement()) + writer->writeDouble(42, ent->getActualMeasurement()); + + switch (ent->eType) { + case DRW::DIMALIGNED: + case DRW::DIMLINEAR: { + DRW_DimAligned * dd = (DRW_DimAligned*)ent; + writer->writeString(100, "AcDbAlignedDimension"); + DRW_Coord crd = dd->getClonepoint(); + if (crd.x != 0 || crd.y != 0 || crd.z != 0) { + writer->writeDouble(12, crd.x); + writer->writeDouble(22, crd.y); + writer->writeDouble(32, crd.z); + } + writer->writeDouble(13, dd->getDef1Point().x); + writer->writeDouble(23, dd->getDef1Point().y); + writer->writeDouble(33, dd->getDef1Point().z); + writer->writeDouble(14, dd->getDef2Point().x); + writer->writeDouble(24, dd->getDef2Point().y); + writer->writeDouble(34, dd->getDef2Point().z); + if (ent->eType == DRW::DIMLINEAR) { + DRW_DimLinear * dl = (DRW_DimLinear*)ent; + if (dl->getAngle() != 0) + writer->writeDouble(50, dl->getAngle()); + if (dl->getOblique() != 0) + writer->writeDouble(52, dl->getOblique()); + writer->writeString(100, "AcDbRotatedDimension"); + } + break; } + case DRW::DIMRADIAL: { + DRW_DimRadial * dd = (DRW_DimRadial*)ent; + writer->writeString(100, "AcDbRadialDimension"); + writer->writeDouble(15, dd->getDiameterPoint().x); + writer->writeDouble(25, dd->getDiameterPoint().y); + writer->writeDouble(35, dd->getDiameterPoint().z); + writer->writeDouble(40, dd->getLeaderLength()); + break; } + case DRW::DIMDIAMETRIC: { + DRW_DimDiametric * dd = (DRW_DimDiametric*)ent; + writer->writeString(100, "AcDbDiametricDimension"); + writer->writeDouble(15, dd->getDiameter1Point().x); + writer->writeDouble(25, dd->getDiameter1Point().y); + writer->writeDouble(35, dd->getDiameter1Point().z); + writer->writeDouble(40, dd->getLeaderLength()); + break; } + case DRW::DIMANGULAR: { + DRW_DimAngular * dd = (DRW_DimAngular*)ent; + writer->writeString(100, "AcDb2LineAngularDimension"); + writer->writeDouble(13, dd->getFirstLine1().x); + writer->writeDouble(23, dd->getFirstLine1().y); + writer->writeDouble(33, dd->getFirstLine1().z); + writer->writeDouble(14, dd->getFirstLine2().x); + writer->writeDouble(24, dd->getFirstLine2().y); + writer->writeDouble(34, dd->getFirstLine2().z); + writer->writeDouble(15, dd->getSecondLine1().x); + writer->writeDouble(25, dd->getSecondLine1().y); + writer->writeDouble(35, dd->getSecondLine1().z); + writer->writeDouble(16, dd->getDimPoint().x); + writer->writeDouble(26, dd->getDimPoint().y); + writer->writeDouble(36, dd->getDimPoint().z); + break; } + case DRW::DIMANGULAR3P: { + DRW_DimAngular3p * dd = (DRW_DimAngular3p*)ent; + writer->writeDouble(13, dd->getFirstLine().x); + writer->writeDouble(23, dd->getFirstLine().y); + writer->writeDouble(33, dd->getFirstLine().z); + writer->writeDouble(14, dd->getSecondLine().x); + writer->writeDouble(24, dd->getSecondLine().y); + writer->writeDouble(34, dd->getSecondLine().z); + writer->writeDouble(15, dd->getVertexPoint().x); + writer->writeDouble(25, dd->getVertexPoint().y); + writer->writeDouble(35, dd->getVertexPoint().z); + break; } + case DRW::DIMORDINATE: { + DRW_DimOrdinate * dd = (DRW_DimOrdinate*)ent; + writer->writeString(100, "AcDbOrdinateDimension"); + writer->writeDouble(13, dd->getFirstLine().x); + writer->writeDouble(23, dd->getFirstLine().y); + writer->writeDouble(33, dd->getFirstLine().z); + writer->writeDouble(14, dd->getSecondLine().x); + writer->writeDouble(24, dd->getSecondLine().y); + writer->writeDouble(34, dd->getSecondLine().z); + break; } + default: + break; + } + } else { + //RLZ: todo not supported by acad 12 saved as unnamed block + } + return true; +} + +bool dxfRW::writeInsert(DRW_Insert *ent){ + writer->writeString(0, "INSERT"); + writeEntity(ent); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbBlockReference"); + writer->writeUtf8String(2, ent->name); + } else + writer->writeUtf8Caps(2, ent->name); + writer->writeDouble(10, ent->basePoint.x); + writer->writeDouble(20, ent->basePoint.y); + writer->writeDouble(30, ent->basePoint.z); + writer->writeDouble(41, ent->xscale); + writer->writeDouble(42, ent->yscale); + writer->writeDouble(43, ent->zscale); + writer->writeDouble(50, (ent->angle)*ARAD); //in dxf angle is writed in degrees + writer->writeInt16(70, ent->colcount); + writer->writeInt16(71, ent->rowcount); + writer->writeDouble(44, ent->colspace); + writer->writeDouble(45, ent->rowspace); + return true; +} + +bool dxfRW::writeText(DRW_Text *ent){ + writer->writeString(0, "TEXT"); + writeEntity(ent); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbText"); + } +// writer->writeDouble(39, ent->thickness); + writer->writeDouble(10, ent->basePoint.x); + writer->writeDouble(20, ent->basePoint.y); + writer->writeDouble(30, ent->basePoint.z); + writer->writeDouble(40, ent->height); + writer->writeUtf8String(1, ent->text); + writer->writeDouble(50, ent->angle); + writer->writeDouble(41, ent->widthscale); + writer->writeDouble(51, ent->oblique); + if (version > DRW::AC1009) + writer->writeUtf8String(7, ent->style); + else + writer->writeUtf8Caps(7, ent->style); + writer->writeInt16(71, ent->textgen); + if (ent->alignH != DRW_Text::HLeft) { + writer->writeInt16(72, ent->alignH); + } + if (ent->alignH != DRW_Text::HLeft || ent->alignV != DRW_Text::VBaseLine) { + writer->writeDouble(11, ent->secPoint.x); + writer->writeDouble(21, ent->secPoint.y); + writer->writeDouble(31, ent->secPoint.z); + } + writer->writeDouble(210, ent->extPoint.x); + writer->writeDouble(220, ent->extPoint.y); + writer->writeDouble(230, ent->extPoint.z); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbText"); + } + if (ent->alignV != DRW_Text::VBaseLine) { + writer->writeInt16(73, ent->alignV); + } + return true; +} + +bool dxfRW::writeMText(DRW_MText *ent){ + if (version > DRW::AC1009) { + writer->writeString(0, "MTEXT"); + writeEntity(ent); + writer->writeString(100, "AcDbMText"); + writer->writeDouble(10, ent->basePoint.x); + writer->writeDouble(20, ent->basePoint.y); + writer->writeDouble(30, ent->basePoint.z); + writer->writeDouble(40, ent->height); + writer->writeDouble(41, ent->widthscale); + writer->writeInt16(71, ent->textgen); + writer->writeInt16(72, ent->alignH); + std::string text = writer->fromUtf8String(ent->text); + + int i; + for(i =0; (text.size()-i) > 250; ) { + writer->writeString(3, text.substr(i, 250)); + i +=250; + } + writer->writeString(1, text.substr(i)); + writer->writeString(7, ent->style); + writer->writeDouble(210, ent->extPoint.x); + writer->writeDouble(220, ent->extPoint.y); + writer->writeDouble(230, ent->extPoint.z); + writer->writeDouble(50, ent->angle); + writer->writeInt16(73, ent->alignV); + writer->writeDouble(44, ent->interlin); +//RLZ ... 11, 21, 31 needed? + } else { + //RLZ: TODO convert mtext in text lines (not exist in acad 12) + } + return true; +} + +bool dxfRW::writeViewport(DRW_Viewport *ent) { + writer->writeString(0, "VIEWPORT"); + writeEntity(ent); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbViewport"); + } + writer->writeDouble(10, ent->basePoint.x); + writer->writeDouble(20, ent->basePoint.y); + if (ent->basePoint.z != 0.0) + writer->writeDouble(30, ent->basePoint.z); + writer->writeDouble(40, ent->pswidth); + writer->writeDouble(41, ent->psheight); + writer->writeInt16(68, ent->vpstatus); + writer->writeInt16(69, ent->vpID); + writer->writeDouble(12, ent->centerPX);//RLZ: verify if exist in V12 + writer->writeDouble(22, ent->centerPY);//RLZ: verify if exist in V12 + return true; +} + +DRW_ImageDef* dxfRW::writeImage(DRW_Image *ent, std::string name){ + if (version > DRW::AC1009) { + //search if exist imagedef with this mane (image inserted more than 1 time) + //RLZ: imagedef_reactor seem needed to read in acad + DRW_ImageDef *id = NULL; + for (unsigned int i=0; iname == name ) { + id = imageDef.at(i); + continue; + } + } + if (id == NULL) { + id = new DRW_ImageDef(); + imageDef.push_back(id); + id->handle = ++entCount; + } + id->name = name; + std::string idReactor = toHexStr(++entCount); + + writer->writeString(0, "IMAGE"); + writeEntity(ent); + writer->writeString(100, "AcDbRasterImage"); + writer->writeDouble(10, ent->basePoint.x); + writer->writeDouble(20, ent->basePoint.y); + writer->writeDouble(30, ent->basePoint.z); + writer->writeDouble(11, ent->secPoint.x); + writer->writeDouble(21, ent->secPoint.y); + writer->writeDouble(31, ent->secPoint.z); + writer->writeDouble(12, ent->vVector.x); + writer->writeDouble(22, ent->vVector.y); + writer->writeDouble(32, ent->vVector.z); + writer->writeDouble(13, ent->sizeu); + writer->writeDouble(23, ent->sizev); + writer->writeString(340, toHexStr(id->handle)); + writer->writeInt16(70, 1); + writer->writeInt16(280, ent->clip); + writer->writeInt16(281, ent->brightness); + writer->writeInt16(282, ent->contrast); + writer->writeInt16(283, ent->fade); + writer->writeString(360, idReactor); + id->reactors[idReactor] = toHexStr(ent->handle); + return id; + } + return NULL; //not exist in acad 12 +} + +bool dxfRW::writeBlockRecord(std::string name){ + if (version > DRW::AC1009) { + writer->writeString(0, "BLOCK_RECORD"); + writer->writeString(5, toHexStr(++entCount)); + + blockMap[name] = entCount; + entCount = 2+entCount;//reserve 2 for BLOCK & ENDBLOCK + if (version > DRW::AC1014) { + writer->writeString(330, "1"); + } + writer->writeString(100, "AcDbSymbolTableRecord"); + writer->writeString(100, "AcDbBlockTableRecord"); + writer->writeUtf8String(2, name); + if (version > DRW::AC1018) { + // writer->writeInt16(340, 22); + writer->writeInt16(70, 0); + writer->writeInt16(280, 1); + writer->writeInt16(281, 0); + } + } + return true; +} + +bool dxfRW::writeBlock(DRW_Block *bk){ + if (writingBlock) { + writer->writeString(0, "ENDBLK"); + if (version > DRW::AC1009) { + writer->writeString(5, toHexStr(currHandle+2)); + if (version > DRW::AC1014) { + writer->writeString(330, toHexStr(currHandle)); + } + writer->writeString(100, "AcDbEntity"); + } + writer->writeString(8, "0"); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbBlockEnd"); + } + } + writingBlock = true; + writer->writeString(0, "BLOCK"); + if (version > DRW::AC1009) { + currHandle = (*(blockMap.find(bk->name))).second; + writer->writeString(5, toHexStr(currHandle+1)); + if (version > DRW::AC1014) { + writer->writeString(330, toHexStr(currHandle)); + } + writer->writeString(100, "AcDbEntity"); + } + writer->writeString(8, "0"); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbBlockBegin"); + writer->writeUtf8String(2, bk->name); + } else + writer->writeUtf8Caps(2, bk->name); + writer->writeInt16(70, bk->flags); + writer->writeDouble(10, bk->basePoint.x); + writer->writeDouble(20, bk->basePoint.y); + if (bk->basePoint.z != 0.0) { + writer->writeDouble(30, bk->basePoint.z); + } + if (version > DRW::AC1009) + writer->writeUtf8String(3, bk->name); + else + writer->writeUtf8Caps(3, bk->name); + writer->writeString(1, ""); + + return true; +} + +bool dxfRW::writeTables() { + writer->writeString(0, "TABLE"); + writer->writeString(2, "VPORT"); + if (version > DRW::AC1009) { + writer->writeString(5, "8"); + if (version > DRW::AC1014) { + writer->writeString(330, "0"); + } + writer->writeString(100, "AcDbSymbolTable"); + } + writer->writeInt16(70, 1); //end table def +/*** VPORT ***/ + dimstyleStd =false; + iface->writeVports(); + if (!dimstyleStd) { + DRW_Vport portact; + portact.name = "*ACTIVE"; + writeVport(&portact); + } + writer->writeString(0, "ENDTAB"); +/*** LTYPE ***/ + writer->writeString(0, "TABLE"); + writer->writeString(2, "LTYPE"); + if (version > DRW::AC1009) { + writer->writeString(5, "5"); + if (version > DRW::AC1014) { + writer->writeString(330, "0"); + } + writer->writeString(100, "AcDbSymbolTable"); + } + writer->writeInt16(70, 4); //end table def +//Mandatory linetypes + writer->writeString(0, "LTYPE"); + if (version > DRW::AC1009) { + writer->writeString(5, "14"); + if (version > DRW::AC1014) { + writer->writeString(330, "5"); + } + writer->writeString(100, "AcDbSymbolTableRecord"); + writer->writeString(100, "AcDbLinetypeTableRecord"); + writer->writeString(2, "ByBlock"); + } else + writer->writeString(2, "BYBLOCK"); + writer->writeInt16(70, 0); + writer->writeString(3, ""); + writer->writeInt16(72, 65); + writer->writeInt16(73, 0); + writer->writeDouble(40, 0.0); + + writer->writeString(0, "LTYPE"); + if (version > DRW::AC1009) { + writer->writeString(5, "15"); + if (version > DRW::AC1014) { + writer->writeString(330, "5"); + } + writer->writeString(100, "AcDbSymbolTableRecord"); + writer->writeString(100, "AcDbLinetypeTableRecord"); + writer->writeString(2, "ByLayer"); + } else + writer->writeString(2, "BYLAYER"); + writer->writeInt16(70, 0); + writer->writeString(3, ""); + writer->writeInt16(72, 65); + writer->writeInt16(73, 0); + writer->writeDouble(40, 0.0); + + writer->writeString(0, "LTYPE"); + if (version > DRW::AC1009) { + writer->writeString(5, "16"); + if (version > DRW::AC1014) { + writer->writeString(330, "5"); + } + writer->writeString(100, "AcDbSymbolTableRecord"); + writer->writeString(100, "AcDbLinetypeTableRecord"); + writer->writeString(2, "Continuous"); + } else { + writer->writeString(2, "CONTINUOUS"); + } + writer->writeInt16(70, 0); + writer->writeString(3, "Solid line"); + writer->writeInt16(72, 65); + writer->writeInt16(73, 0); + writer->writeDouble(40, 0.0); +//Aplication linetypes + iface->writeLTypes(); + writer->writeString(0, "ENDTAB"); +/*** LAYER ***/ + writer->writeString(0, "TABLE"); + writer->writeString(2, "LAYER"); + if (version > DRW::AC1009) { + writer->writeString(5, "2"); + if (version > DRW::AC1014) { + writer->writeString(330, "0"); + } + writer->writeString(100, "AcDbSymbolTable"); + } + writer->writeInt16(70, 1); //end table def + wlayer0 =false; + iface->writeLayers(); + if (!wlayer0) { + DRW_Layer lay0; + lay0.name = "0"; + writeLayer(&lay0); + } + writer->writeString(0, "ENDTAB"); +/*** STYLE ***/ + writer->writeString(0, "TABLE"); + writer->writeString(2, "STYLE"); + if (version > DRW::AC1009) { + writer->writeString(5, "3"); + if (version > DRW::AC1014) { + writer->writeString(330, "0"); + } + writer->writeString(100, "AcDbSymbolTable"); + } + writer->writeInt16(70, 3); //end table def + dimstyleStd =false; + iface->writeTextstyles(); + if (!dimstyleStd) { + DRW_Textstyle tsty; + tsty.name = "Standard"; + writeTextstyle(&tsty); + } + writer->writeString(0, "ENDTAB"); + + writer->writeString(0, "TABLE"); + writer->writeString(2, "VIEW"); + if (version > DRW::AC1009) { + writer->writeString(5, "6"); + if (version > DRW::AC1014) { + writer->writeString(330, "0"); + } + writer->writeString(100, "AcDbSymbolTable"); + } + writer->writeInt16(70, 0); //end table def + writer->writeString(0, "ENDTAB"); + + writer->writeString(0, "TABLE"); + writer->writeString(2, "UCS"); + if (version > DRW::AC1009) { + writer->writeString(5, "7"); + if (version > DRW::AC1014) { + writer->writeString(330, "0"); + } + writer->writeString(100, "AcDbSymbolTable"); + } + writer->writeInt16(70, 0); //end table def + writer->writeString(0, "ENDTAB"); + + writer->writeString(0, "TABLE"); + writer->writeString(2, "APPID"); + if (version > DRW::AC1009) { + writer->writeString(5, "9"); + if (version > DRW::AC1014) { + writer->writeString(330, "0"); + } + writer->writeString(100, "AcDbSymbolTable"); + } + writer->writeInt16(70, 1); //end table def + writer->writeString(0, "APPID"); + if (version > DRW::AC1009) { + writer->writeString(5, "12"); + if (version > DRW::AC1014) { + writer->writeString(330, "9"); + } + writer->writeString(100, "AcDbSymbolTableRecord"); + writer->writeString(100, "AcDbRegAppTableRecord"); + } + writer->writeString(2, "ACAD"); + writer->writeInt16(70, 0); + iface->writeAppId(); + writer->writeString(0, "ENDTAB"); + + writer->writeString(0, "TABLE"); + writer->writeString(2, "DIMSTYLE"); + if (version > DRW::AC1009) { + writer->writeString(5, "A"); + if (version > DRW::AC1014) { + writer->writeString(330, "0"); + } + writer->writeString(100, "AcDbSymbolTable"); + } + writer->writeInt16(70, 1); //end table def + if (version > DRW::AC1014) { + writer->writeString(100, "AcDbDimStyleTable"); + writer->writeInt16(71, 1); //end table def + } + dimstyleStd =false; + iface->writeDimstyles(); + if (!dimstyleStd) { + DRW_Dimstyle dsty; + dsty.name = "Standard"; + writeDimstyle(&dsty); + } + writer->writeString(0, "ENDTAB"); + + if (version > DRW::AC1009) { + writer->writeString(0, "TABLE"); + writer->writeString(2, "BLOCK_RECORD"); + writer->writeString(5, "1"); + if (version > DRW::AC1014) { + writer->writeString(330, "0"); + } + writer->writeString(100, "AcDbSymbolTable"); + writer->writeInt16(70, 2); //end table def + writer->writeString(0, "BLOCK_RECORD"); + writer->writeString(5, "1F"); + if (version > DRW::AC1014) { + writer->writeString(330, "1"); + } + writer->writeString(100, "AcDbSymbolTableRecord"); + writer->writeString(100, "AcDbBlockTableRecord"); + writer->writeString(2, "*Model_Space"); + if (version > DRW::AC1018) { + // writer->writeInt16(340, 22); + writer->writeInt16(70, 0); + writer->writeInt16(280, 1); + writer->writeInt16(281, 0); + } + writer->writeString(0, "BLOCK_RECORD"); + writer->writeString(5, "1E"); + if (version > DRW::AC1014) { + writer->writeString(330, "1"); + } + writer->writeString(100, "AcDbSymbolTableRecord"); + writer->writeString(100, "AcDbBlockTableRecord"); + writer->writeString(2, "*Paper_Space"); + if (version > DRW::AC1018) { + // writer->writeInt16(340, 22); + writer->writeInt16(70, 0); + writer->writeInt16(280, 1); + writer->writeInt16(281, 0); + } + } + /* allways call writeBlockRecords to iface for prepare unnamed blocks */ + iface->writeBlockRecords(); + if (version > DRW::AC1009) { + writer->writeString(0, "ENDTAB"); + } +return true; +} + +bool dxfRW::writeBlocks() { + writer->writeString(0, "BLOCK"); + if (version > DRW::AC1009) { + writer->writeString(5, "20"); + if (version > DRW::AC1014) { + writer->writeString(330, "1F"); + } + writer->writeString(100, "AcDbEntity"); + } + writer->writeString(8, "0"); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbBlockBegin"); + writer->writeString(2, "*Model_Space"); + } else + writer->writeString(2, "$MODEL_SPACE"); + writer->writeInt16(70, 0); + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + if (version > DRW::AC1009) + writer->writeString(3, "*Model_Space"); + else + writer->writeString(3, "$MODEL_SPACE"); + writer->writeString(1, ""); + writer->writeString(0, "ENDBLK"); + if (version > DRW::AC1009) { + writer->writeString(5, "21"); + if (version > DRW::AC1014) { + writer->writeString(330, "1F"); + } + writer->writeString(100, "AcDbEntity"); + } + writer->writeString(8, "0"); + if (version > DRW::AC1009) + writer->writeString(100, "AcDbBlockEnd"); + + writer->writeString(0, "BLOCK"); + if (version > DRW::AC1009) { + writer->writeString(5, "1C"); + if (version > DRW::AC1014) { + writer->writeString(330, "1B"); + } + writer->writeString(100, "AcDbEntity"); + } + writer->writeString(8, "0"); + if (version > DRW::AC1009) { + writer->writeString(100, "AcDbBlockBegin"); + writer->writeString(2, "*Paper_Space"); + } else + writer->writeString(2, "$PAPER_SPACE"); + writer->writeInt16(70, 0); + writer->writeDouble(10, 0.0); + writer->writeDouble(20, 0.0); + writer->writeDouble(30, 0.0); + if (version > DRW::AC1009) + writer->writeString(3, "*Paper_Space"); + else + writer->writeString(3, "$PAPER_SPACE"); + writer->writeString(1, ""); + writer->writeString(0, "ENDBLK"); + if (version > DRW::AC1009) { + writer->writeString(5, "1D"); + if (version > DRW::AC1014) { + writer->writeString(330, "1F"); + } + writer->writeString(100, "AcDbEntity"); + } + writer->writeString(8, "0"); + if (version > DRW::AC1009) + writer->writeString(100, "AcDbBlockEnd"); + writingBlock = false; + iface->writeBlocks(); + if (writingBlock) { + writingBlock = false; + writer->writeString(0, "ENDBLK"); + if (version > DRW::AC1009) { + writer->writeString(5, toHexStr(currHandle+2)); +// writer->writeString(5, "1D"); + if (version > DRW::AC1014) { + writer->writeString(330, toHexStr(currHandle)); + } + writer->writeString(100, "AcDbEntity"); + } + writer->writeString(8, "0"); + if (version > DRW::AC1009) + writer->writeString(100, "AcDbBlockEnd"); + } + return true; +} + +bool dxfRW::writeObjects() { + writer->writeString(0, "DICTIONARY"); + std::string imgDictH; + writer->writeString(5, "C"); + if (version > DRW::AC1014) { + writer->writeString(330, "0"); + } + writer->writeString(100, "AcDbDictionary"); + writer->writeInt16(281, 1); + writer->writeString(3, "ACAD_GROUP"); + writer->writeString(350, "D"); + if (imageDef.size() != 0) { + writer->writeString(3, "ACAD_IMAGE_DICT"); + imgDictH = toHexStr(++entCount); + writer->writeString(350, imgDictH); + } + writer->writeString(0, "DICTIONARY"); + writer->writeString(5, "D"); + writer->writeString(330, "C"); + writer->writeString(100, "AcDbDictionary"); + writer->writeInt16(281, 1); +//write IMAGEDEF_REACTOR + for (unsigned int i=0; i::iterator it; + for ( it=id->reactors.begin() ; it != id->reactors.end(); ++it ) { + writer->writeString(0, "IMAGEDEF_REACTOR"); + writer->writeString(5, (*it).first); + writer->writeString(330, (*it).second); + writer->writeString(100, "AcDbRasterImageDefReactor"); + writer->writeInt16(90, 2); //version 2=R14 to v2010 + writer->writeString(330, (*it).second); + } + } + if (imageDef.size() != 0) { + writer->writeString(0, "DICTIONARY"); + writer->writeString(5, imgDictH); + writer->writeString(330, "C"); + writer->writeString(100, "AcDbDictionary"); + writer->writeInt16(281, 1); + for (unsigned int i=0; iname.find_last_of("/\\"); + f2 =imageDef.at(i)->name.find_last_of('.'); + ++f1; + writer->writeString(3, imageDef.at(i)->name.substr(f1,f2-f1)); + writer->writeString(350, toHexStr(imageDef.at(i)->handle) ); + } + } + for (unsigned int i=0; iwriteString(0, "IMAGEDEF"); + writer->writeString(5, toHexStr(id->handle) ); + if (version > DRW::AC1014) { +// writer->writeString(330, "0"); handle to DICTIONARY + } + writer->writeString(102, "{ACAD_REACTORS"); + std::map::iterator it; + for ( it=id->reactors.begin() ; it != id->reactors.end(); ++it ) { + writer->writeString(330, (*it).first); + } + writer->writeString(102, "}"); + writer->writeString(100, "AcDbRasterImageDef"); + writer->writeInt16(90, 0); //version 0=R14 to v2010 + writer->writeUtf8String(1, id->name); + writer->writeDouble(10, id->u); + writer->writeDouble(20, id->v); + writer->writeDouble(11, id->up); + writer->writeDouble(21, id->vp); + writer->writeInt16(280, id->loaded); + writer->writeInt16(281, id->resolution); + } + //no more needed imageDef, delete it + while (!imageDef.empty()) { + imageDef.pop_back(); + } + + return true; +} + +bool dxfRW::writeExtData(const std::vector &ed){ + for (std::vector::const_iterator it=ed.begin(); it!=ed.end(); ++it){ + switch ((*it)->code) { + case 1000: + case 1001: + case 1002: + case 1003: + case 1004: + case 1005: + {int cc = (*it)->code; + if ((*it)->type == DRW_Variant::STRING) + writer->writeUtf8String(cc, *(*it)->content.s); +// writer->writeUtf8String((*it)->code, (*it)->content.s); + break;} + case 1010: + case 1011: + case 1012: + case 1013: + if ((*it)->type == DRW_Variant::COORD) { + writer->writeDouble((*it)->code, (*it)->content.v->x); + writer->writeDouble((*it)->code+10 , (*it)->content.v->y); + writer->writeDouble((*it)->code+20 , (*it)->content.v->z); + } + break; + case 1040: + case 1041: + case 1042: + if ((*it)->type == DRW_Variant::DOUBLE) + writer->writeDouble((*it)->code, (*it)->content.d); + break; + case 1070: + if ((*it)->type == DRW_Variant::INTEGER) + writer->writeInt16((*it)->code, (*it)->content.i); + break; + case 1071: + if ((*it)->type == DRW_Variant::INTEGER) + writer->writeInt32((*it)->code, (*it)->content.i); + break; + default: + break; + } + } + return true; +} + +/********* Reader Process *********/ + +bool dxfRW::processDxf() { + DRW_DBG("dxfRW::processDxf() start processing dxf\n"); + int code; + bool more = true; + std::string sectionstr; +// section = secUnknown; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG(" processDxf\n"); + if (code == 999) { + header.addComment(reader->getString()); + } else if (code == 0) { + sectionstr = reader->getString(); + DRW_DBG(sectionstr); DRW_DBG(" processDxf\n"); + if (sectionstr == "EOF") { + return true; //found EOF terminate + } + if (sectionstr == "SECTION") { + more = reader->readRec(&code); + DRW_DBG(code); DRW_DBG(" processDxf\n"); + if (!more) + return false; //wrong dxf file + if (code == 2) { + sectionstr = reader->getString(); + DRW_DBG(sectionstr); DRW_DBG(" processDxf\n"); + //found section, process it + if (sectionstr == "HEADER") { + processHeader(); + } else if (sectionstr == "CLASSES") { +// processClasses(); + } else if (sectionstr == "TABLES") { + processTables(); + } else if (sectionstr == "BLOCKS") { + processBlocks(); + } else if (sectionstr == "ENTITIES") { + processEntities(false); + } else if (sectionstr == "OBJECTS") { + processObjects(); + } + } + } + } +/* if (!more) + return true;*/ + } + return true; +} + +/********* Header Section *********/ + +bool dxfRW::processHeader() { + DRW_DBG("dxfRW::processHeader\n"); + int code; + std::string sectionstr; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG(" processHeader\n"); + if (code == 0) { + sectionstr = reader->getString(); + DRW_DBG(sectionstr); DRW_DBG(" processHeader\n\n"); + if (sectionstr == "ENDSEC") { + iface->addHeader(&header); + return true; //found ENDSEC terminate + } + } else header.parseCode(code, reader); + } + return true; +} + +/********* Tables Section *********/ + +bool dxfRW::processTables() { + DRW_DBG("dxfRW::processTables\n"); + int code; + std::string sectionstr; + bool more = true; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + if (code == 0) { + sectionstr = reader->getString(); + DRW_DBG(sectionstr); DRW_DBG(" processHeader\n\n"); + if (sectionstr == "TABLE") { + more = reader->readRec(&code); + DRW_DBG(code); DRW_DBG("\n"); + if (!more) + return false; //wrong dxf file + if (code == 2) { + sectionstr = reader->getString(); + DRW_DBG(sectionstr); DRW_DBG(" processHeader\n\n"); + //found section, process it + if (sectionstr == "LTYPE") { + processLType(); + } else if (sectionstr == "LAYER") { + processLayer(); + } else if (sectionstr == "STYLE") { + processTextStyle(); + } else if (sectionstr == "VPORT") { + processVports(); + } else if (sectionstr == "VIEW") { +// processView(); + } else if (sectionstr == "UCS") { +// processUCS(); + } else if (sectionstr == "APPID") { + processAppId(); + } else if (sectionstr == "DIMSTYLE") { + processDimStyle(); + } else if (sectionstr == "BLOCK_RECORD") { +// processBlockRecord(); + } + } + } else if (sectionstr == "ENDSEC") { + return true; //found ENDSEC terminate + } + } + } + return true; +} + +bool dxfRW::processLType() { + DRW_DBG("dxfRW::processLType\n"); + int code; + std::string sectionstr; + bool reading = false; + DRW_LType ltype; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + if (code == 0) { + if (reading) { + ltype.update(); + iface->addLType(ltype); + } + sectionstr = reader->getString(); + DRW_DBG(sectionstr); DRW_DBG("\n"); + if (sectionstr == "LTYPE") { + reading = true; + ltype.reset(); + } else if (sectionstr == "ENDTAB") { + return true; //found ENDTAB terminate + } + } else if (reading) + ltype.parseCode(code, reader); + } + return true; +} + +bool dxfRW::processLayer() { + DRW_DBG("dxfRW::processLayer\n"); + int code; + std::string sectionstr; + bool reading = false; + DRW_Layer layer; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + if (code == 0) { + if (reading) + iface->addLayer(layer); + sectionstr = reader->getString(); + DRW_DBG(sectionstr); DRW_DBG("\n"); + if (sectionstr == "LAYER") { + reading = true; + layer.reset(); + } else if (sectionstr == "ENDTAB") { + return true; //found ENDTAB terminate + } + } else if (reading) + layer.parseCode(code, reader); + } + return true; +} + +bool dxfRW::processDimStyle() { + DRW_DBG("dxfRW::processDimStyle"); + int code; + std::string sectionstr; + bool reading = false; + DRW_Dimstyle dimSty; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + if (code == 0) { + if (reading) + iface->addDimStyle(dimSty); + sectionstr = reader->getString(); + DRW_DBG(sectionstr); DRW_DBG("\n"); + if (sectionstr == "DIMSTYLE") { + reading = true; + dimSty.reset(); + } else if (sectionstr == "ENDTAB") { + return true; //found ENDTAB terminate + } + } else if (reading) + dimSty.parseCode(code, reader); + } + return true; +} + +bool dxfRW::processTextStyle(){ + DRW_DBG("dxfRW::processTextStyle"); + int code; + std::string sectionstr; + bool reading = false; + DRW_Textstyle TxtSty; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + if (code == 0) { + if (reading) + iface->addTextStyle(TxtSty); + sectionstr = reader->getString(); + DRW_DBG(sectionstr); DRW_DBG("\n"); + if (sectionstr == "STYLE") { + reading = true; + TxtSty.reset(); + } else if (sectionstr == "ENDTAB") { + return true; //found ENDTAB terminate + } + } else if (reading) + TxtSty.parseCode(code, reader); + } + return true; +} + +bool dxfRW::processVports(){ + DRW_DBG("dxfRW::processVports"); + int code; + std::string sectionstr; + bool reading = false; + DRW_Vport vp; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + if (code == 0) { + if (reading) + iface->addVport(vp); + sectionstr = reader->getString(); + DRW_DBG(sectionstr); DRW_DBG("\n"); + if (sectionstr == "VPORT") { + reading = true; + vp.reset(); + } else if (sectionstr == "ENDTAB") { + return true; //found ENDTAB terminate + } + } else if (reading) + vp.parseCode(code, reader); + } + return true; +} + +bool dxfRW::processAppId(){ + DRW_DBG("dxfRW::processAppId"); + int code; + std::string sectionstr; + bool reading = false; + DRW_AppId vp; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + if (code == 0) { + if (reading) + iface->addAppId(vp); + sectionstr = reader->getString(); + DRW_DBG(sectionstr); DRW_DBG("\n"); + if (sectionstr == "APPID") { + reading = true; + vp.reset(); + } else if (sectionstr == "ENDTAB") { + return true; //found ENDTAB terminate + } + } else if (reading) + vp.parseCode(code, reader); + } + return true; +} + +/********* Block Section *********/ + +bool dxfRW::processBlocks() { + DRW_DBG("dxfRW::processBlocks\n"); + int code; + std::string sectionstr; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + if (code == 0) { + sectionstr = reader->getString(); + DRW_DBG(sectionstr); DRW_DBG("\n"); + if (sectionstr == "BLOCK") { + processBlock(); + } else if (sectionstr == "ENDSEC") { + return true; //found ENDSEC terminate + } + } + } + return true; +} + +bool dxfRW::processBlock() { + DRW_DBG("dxfRW::processBlock"); + int code; + DRW_Block block; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + iface->addBlock(block); + if (nextentity == "ENDBLK") { + iface->endBlock(); + return true; //found ENDBLK, terminate + } else { + processEntities(true); + iface->endBlock(); + return true; //found ENDBLK, terminate + } + } + default: + block.parseCode(code, reader); + break; + } + } + return true; +} + + +/********* Entities Section *********/ + +bool dxfRW::processEntities(bool isblock) { + DRW_DBG("dxfRW::processEntities\n"); + int code; + if (!reader->readRec(&code)){ + return false; + } + bool next = true; + if (code == 0) { + nextentity = reader->getString(); + } else if (!isblock) { + return false; //first record in entities is 0 + } + do { + if (nextentity == "ENDSEC" || nextentity == "ENDBLK") { + return true; //found ENDSEC or ENDBLK terminate + } else if (nextentity == "POINT") { + processPoint(); + } else if (nextentity == "LINE") { + processLine(); + } else if (nextentity == "CIRCLE") { + processCircle(); + } else if (nextentity == "ARC") { + processArc(); + } else if (nextentity == "ELLIPSE") { + processEllipse(); + } else if (nextentity == "TRACE") { + processTrace(); + } else if (nextentity == "SOLID") { + processSolid(); + } else if (nextentity == "INSERT") { + processInsert(); + } else if (nextentity == "LWPOLYLINE") { + processLWPolyline(); + } else if (nextentity == "POLYLINE") { + processPolyline(); + } else if (nextentity == "TEXT") { + processText(); + } else if (nextentity == "MTEXT") { + processMText(); + } else if (nextentity == "HATCH") { + processHatch(); + } else if (nextentity == "SPLINE") { + processSpline(); + } else if (nextentity == "3DFACE") { + process3dface(); + } else if (nextentity == "VIEWPORT") { + processViewport(); + } else if (nextentity == "IMAGE") { + processImage(); + } else if (nextentity == "DIMENSION") { + processDimension(); + } else if (nextentity == "LEADER") { + processLeader(); + } else if (nextentity == "RAY") { + processRay(); + } else if (nextentity == "XLINE") { + processXline(); + } else { + if (reader->readRec(&code)){ + if (code == 0) + nextentity = reader->getString(); + } else + return false; //end of file without ENDSEC + } + + } while (next); + return true; +} + +bool dxfRW::processEllipse() { + DRW_DBG("dxfRW::processEllipse"); + int code; + DRW_Ellipse ellipse; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + if (applyExt) + ellipse.applyExtrusion(); + iface->addEllipse(ellipse); + return true; //found new entity or ENDSEC, terminate + } + default: + ellipse.parseCode(code, reader); + break; + } + } + return true; +} + +bool dxfRW::processTrace() { + DRW_DBG("dxfRW::processTrace"); + int code; + DRW_Trace trace; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + if (applyExt) + trace.applyExtrusion(); + iface->addTrace(trace); + return true; //found new entity or ENDSEC, terminate + } + default: + trace.parseCode(code, reader); + break; + } + } + return true; +} + +bool dxfRW::processSolid() { + DRW_DBG("dxfRW::processSolid"); + int code; + DRW_Solid solid; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + if (applyExt) + solid.applyExtrusion(); + iface->addSolid(solid); + return true; //found new entity or ENDSEC, terminate + } + default: + solid.parseCode(code, reader); + break; + } + } + return true; +} + +bool dxfRW::process3dface() { + DRW_DBG("dxfRW::process3dface"); + int code; + DRW_3Dface face; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + iface->add3dFace(face); + return true; //found new entity or ENDSEC, terminate + } + default: + face.parseCode(code, reader); + break; + } + } + return true; +} + +bool dxfRW::processViewport() { + DRW_DBG("dxfRW::processViewport"); + int code; + DRW_Viewport vp; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + iface->addViewport(vp); + return true; //found new entity or ENDSEC, terminate + } + default: + vp.parseCode(code, reader); + break; + } + } + return true; +} + +bool dxfRW::processPoint() { + DRW_DBG("dxfRW::processPoint\n"); + int code; + DRW_Point point; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + iface->addPoint(point); + return true; //found new entity or ENDSEC, terminate + } + default: + point.parseCode(code, reader); + break; + } + } + return true; +} + +bool dxfRW::processLine() { + DRW_DBG("dxfRW::processLine\n"); + int code; + DRW_Line line; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + iface->addLine(line); + return true; //found new entity or ENDSEC, terminate + } + default: + line.parseCode(code, reader); + break; + } + } + return true; +} + +bool dxfRW::processRay() { + DRW_DBG("dxfRW::processRay\n"); + int code; + DRW_Ray line; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + iface->addRay(line); + return true; //found new entity or ENDSEC, terminate + } + default: + line.parseCode(code, reader); + break; + } + } + return true; +} + +bool dxfRW::processXline() { + DRW_DBG("dxfRW::processXline\n"); + int code; + DRW_Xline line; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + iface->addXline(line); + return true; //found new entity or ENDSEC, terminate + } + default: + line.parseCode(code, reader); + break; + } + } + return true; +} + +bool dxfRW::processCircle() { + DRW_DBG("dxfRW::processPoint\n"); + int code; + DRW_Circle circle; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + if (applyExt) + circle.applyExtrusion(); + iface->addCircle(circle); + return true; //found new entity or ENDSEC, terminate + } + default: + circle.parseCode(code, reader); + break; + } + } + return true; +} + +bool dxfRW::processArc() { + DRW_DBG("dxfRW::processPoint\n"); + int code; + DRW_Arc arc; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + if (applyExt) + arc.applyExtrusion(); + iface->addArc(arc); + return true; //found new entity or ENDSEC, terminate + } + default: + arc.parseCode(code, reader); + break; + } + } + return true; +} + +bool dxfRW::processInsert() { + DRW_DBG("dxfRW::processInsert"); + int code; + DRW_Insert insert; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + iface->addInsert(insert); + return true; //found new entity or ENDSEC, terminate + } + default: + insert.parseCode(code, reader); + break; + } + } + return true; +} + +bool dxfRW::processLWPolyline() { + DRW_DBG("dxfRW::processLWPolyline"); + int code; + DRW_LWPolyline pl; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + if (applyExt) + pl.applyExtrusion(); + iface->addLWPolyline(pl); + return true; //found new entity or ENDSEC, terminate + } + default: + pl.parseCode(code, reader); + break; + } + } + return true; +} + +bool dxfRW::processPolyline() { + DRW_DBG("dxfRW::processPolyline"); + int code; + DRW_Polyline pl; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + if (nextentity != "VERTEX") { + iface->addPolyline(pl); + return true; //found new entity or ENDSEC, terminate + } else { + processVertex(&pl); + } + } + default: + pl.parseCode(code, reader); + break; + } + } + return true; +} + +bool dxfRW::processVertex(DRW_Polyline *pl) { + DRW_DBG("dxfRW::processVertex"); + int code; + DRW_Vertex *v = new DRW_Vertex(); + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + pl->appendVertex(v); + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + if (nextentity == "SEQEND") { + return true; //found SEQEND no more vertex, terminate + } else if (nextentity == "VERTEX"){ + v = new DRW_Vertex(); //another vertex + } + } + default: + v->parseCode(code, reader); + break; + } + } + return true; +} + +bool dxfRW::processText() { + DRW_DBG("dxfRW::processText"); + int code; + DRW_Text txt; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + iface->addText(txt); + return true; //found new entity or ENDSEC, terminate + } + default: + txt.parseCode(code, reader); + break; + } + } + return true; +} + +bool dxfRW::processMText() { + DRW_DBG("dxfRW::processMText"); + int code; + DRW_MText txt; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + txt.updateAngle(); + iface->addMText(txt); + return true; //found new entity or ENDSEC, terminate + } + default: + txt.parseCode(code, reader); + break; + } + } + return true; +} + +bool dxfRW::processHatch() { + DRW_DBG("dxfRW::processHatch"); + int code; + DRW_Hatch hatch; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + iface->addHatch(&hatch); + return true; //found new entity or ENDSEC, terminate + } + default: + hatch.parseCode(code, reader); + break; + } + } + return true; +} + + +bool dxfRW::processSpline() { + DRW_DBG("dxfRW::processSpline"); + int code; + DRW_Spline sp; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + iface->addSpline(&sp); + return true; //found new entity or ENDSEC, terminate + } + default: + sp.parseCode(code, reader); + break; + } + } + return true; +} + + +bool dxfRW::processImage() { + DRW_DBG("dxfRW::processImage"); + int code; + DRW_Image img; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + iface->addImage(&img); + return true; //found new entity or ENDSEC, terminate + } + default: + img.parseCode(code, reader); + break; + } + } + return true; +} + + +bool dxfRW::processDimension() { + DRW_DBG("dxfRW::processDimension"); + int code; + DRW_Dimension dim; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + int type = dim.type & 0x0F; + switch (type) { + case 0: { + DRW_DimLinear d(dim); + iface->addDimLinear(&d); + break; } + case 1: { + DRW_DimAligned d(dim); + iface->addDimAlign(&d); + break; } + case 2: { + DRW_DimAngular d(dim); + iface->addDimAngular(&d); + break;} + case 3: { + DRW_DimDiametric d(dim); + iface->addDimDiametric(&d); + break; } + case 4: { + DRW_DimRadial d(dim); + iface->addDimRadial(&d); + break; } + case 5: { + DRW_DimAngular3p d(dim); + iface->addDimAngular3P(&d); + break; } + case 6: { + DRW_DimOrdinate d(dim); + iface->addDimOrdinate(&d); + break; } + } + return true; //found new entity or ENDSEC, terminate + } + default: + dim.parseCode(code, reader); + break; + } + } + return true; +} + +bool dxfRW::processLeader() { + DRW_DBG("dxfRW::processLeader"); + int code; + DRW_Leader leader; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + iface->addLeader(&leader); + return true; //found new entity or ENDSEC, terminate + } + default: + leader.parseCode(code, reader); + break; + } + } + return true; +} + + +/********* Objects Section *********/ + +bool dxfRW::processObjects() { + DRW_DBG("dxfRW::processObjects\n"); + int code; + if (!reader->readRec(&code)){ + return false; + } + bool next = true; + if (code == 0) { + nextentity = reader->getString(); + } else { + return false; //first record in objects is 0 + } + do { + if (nextentity == "ENDSEC") { + return true; //found ENDSEC terminate + } else if (nextentity == "IMAGEDEF") { + processImageDef(); + } else { + if (reader->readRec(&code)){ + if (code == 0) + nextentity = reader->getString(); + } else + return false; //end of file without ENDSEC + } + + } while (next); + return true; +} + +bool dxfRW::processImageDef() { + DRW_DBG("dxfRW::processImageDef"); + int code; + DRW_ImageDef img; + while (reader->readRec(&code)) { + DRW_DBG(code); DRW_DBG("\n"); + switch (code) { + case 0: { + nextentity = reader->getString(); + DRW_DBG(nextentity); DRW_DBG("\n"); + iface->linkImage(&img); + return true; //found new entity or ENDSEC, terminate + } + default: + img.parseCode(code, reader); + break; + } + } + return true; +} + +/** utility function + * convert a int to string in hex + **/ +std::string dxfRW::toHexStr(int n){ +#if defined(__APPLE__) + char buffer[9]= {'\0'}; + snprintf(buffer,9, "%X", n); + return std::string(buffer); +#else + std::ostringstream Convert; + Convert << std::uppercase << std::hex << n; + return Convert.str(); +#endif +} diff --git a/src/libs/vdxf/libdxfrw/libdxfrw.h b/src/libs/vdxf/libdxfrw/libdxfrw.h new file mode 100644 index 000000000..18c264952 --- /dev/null +++ b/src/libs/vdxf/libdxfrw/libdxfrw.h @@ -0,0 +1,148 @@ +/****************************************************************************** +** libDXFrw - Library to read/write DXF files (ascii & binary) ** +** ** +** Copyright (C) 2011-2015 José F. Soriano, rallazz@gmail.com ** +** ** +** This library is free software, licensed under the terms of the GNU ** +** General Public License as published by the Free Software Foundation, ** +** either version 2 of the License, or (at your option) any later version. ** +** You should have received a copy of the GNU General Public License ** +** along with this program. If not, see . ** +******************************************************************************/ + +#ifndef LIBDXFRW_H +#define LIBDXFRW_H + +#include +#include "drw_entities.h" +#include "drw_objects.h" +#include "drw_header.h" +#include "drw_interface.h" + + +class dxfReader; +class dxfWriter; + +class dxfRW { +public: + dxfRW(const char* name); + ~dxfRW(); + void setDebug(DRW::DBG_LEVEL lvl); + /// reads the file specified in constructor + /*! + * An interface must be provided. It is used by the class to signal various + * components being added. + * @param interface_ the interface to use + * @param ext should the extrusion be applied to convert in 2D? + * @return true for success + */ + bool read(DRW_Interface *interface_, bool ext); + void setBinary(bool b) {binFile = b;} + + bool write(DRW_Interface *interface_, DRW::Version ver, bool bin); + bool writeLineType(DRW_LType *ent); + bool writeLayer(DRW_Layer *ent); + bool writeDimstyle(DRW_Dimstyle *ent); + bool writeTextstyle(DRW_Textstyle *ent); + bool writeVport(DRW_Vport *ent); + bool writeAppId(DRW_AppId *ent); + bool writePoint(DRW_Point *ent); + bool writeLine(DRW_Line *ent); + bool writeRay(DRW_Ray *ent); + bool writeXline(DRW_Xline *ent); + bool writeCircle(DRW_Circle *ent); + bool writeArc(DRW_Arc *ent); + bool writeEllipse(DRW_Ellipse *ent); + bool writeTrace(DRW_Trace *ent); + bool writeSolid(DRW_Solid *ent); + bool write3dface(DRW_3Dface *ent); + bool writeLWPolyline(DRW_LWPolyline *ent); + bool writePolyline(DRW_Polyline *ent); + bool writeSpline(DRW_Spline *ent); + bool writeBlockRecord(std::string name); + bool writeBlock(DRW_Block *ent); + bool writeInsert(DRW_Insert *ent); + bool writeMText(DRW_MText *ent); + bool writeText(DRW_Text *ent); + bool writeHatch(DRW_Hatch *ent); + bool writeViewport(DRW_Viewport *ent); + DRW_ImageDef *writeImage(DRW_Image *ent, std::string name); + bool writeLeader(DRW_Leader *ent); + bool writeDimension(DRW_Dimension *ent); + void setEllipseParts(int parts){elParts = parts;} /*!< set parts munber when convert ellipse to polyline */ + +private: + /// used by read() to parse the content of the file + bool processDxf(); + bool processHeader(); + bool processTables(); + bool processBlocks(); + bool processBlock(); + bool processEntities(bool isblock); + bool processObjects(); + + bool processLType(); + bool processLayer(); + bool processDimStyle(); + bool processTextStyle(); + bool processVports(); + bool processAppId(); + + bool processPoint(); + bool processLine(); + bool processRay(); + bool processXline(); + bool processCircle(); + bool processArc(); + bool processEllipse(); + bool processTrace(); + bool processSolid(); + bool processInsert(); + bool processLWPolyline(); + bool processPolyline(); + bool processVertex(DRW_Polyline* pl); + bool processText(); + bool processMText(); + bool processHatch(); + bool processSpline(); + bool process3dface(); + bool processViewport(); + bool processImage(); + bool processImageDef(); + bool processDimension(); + bool processLeader(); + +// bool writeHeader(); + bool writeEntity(DRW_Entity *ent); + bool writeTables(); + bool writeBlocks(); + bool writeObjects(); + bool writeExtData(const std::vector &ed); + /*use version from dwgutil.h*/ + std::string toHexStr(int n);//RLZ removeme + +private: + DRW::Version version; + std::string fileName; + std::string codePage; + bool binFile; + dxfReader *reader; + dxfWriter *writer; + DRW_Interface *iface; + DRW_Header header; +// int section; + std::string nextentity; + int entCount; + bool wlayer0; + bool dimstyleStd; + bool applyExt; + bool writingBlock; + int elParts; /*!< parts munber when convert ellipse to polyline */ + std::map blockMap; + std::vector imageDef; /*!< imageDef list */ + + int currHandle; + +}; + +#endif // LIBDXFRW_H diff --git a/src/libs/vdxf/libdxfrw/main_doc.h b/src/libs/vdxf/libdxfrw/main_doc.h new file mode 100644 index 000000000..9e290b41e --- /dev/null +++ b/src/libs/vdxf/libdxfrw/main_doc.h @@ -0,0 +1,14 @@ + +/** + * @mainpage + * + * This manual documents the use of libdxfrw. + * + * With libdxfrw you can read and write several parts of a dxf files.

+ * Dxf files can be written in assci and binary form, both are supported.

+ * Dwg support (only read) are work in progress.

+ * + * the complete documentation and examples are pending to free time, + * but to start see DRW_Interface, dxfRW & dwgR, clases + */ + diff --git a/src/libs/vdxf/vdxf.pri b/src/libs/vdxf/vdxf.pri index 81c17f424..198ba0e4e 100644 --- a/src/libs/vdxf/vdxf.pri +++ b/src/libs/vdxf/vdxf.pri @@ -2,27 +2,57 @@ # This need for corect working file translations.pro SOURCES += \ - $$PWD/dxflib/dl_dxf.cpp \ - $$PWD/dxflib/dl_writer_ascii.cpp \ $$PWD/vdxfengine.cpp \ $$PWD/vdxfpaintdevice.cpp \ - $$PWD/dxflib/dl_writer.cpp + $$PWD/libdxfrw/intern/drw_dbg.cpp \ + $$PWD/libdxfrw/intern/drw_textcodec.cpp \ + $$PWD/libdxfrw/intern/dwgbuffer.cpp \ + $$PWD/libdxfrw/intern/dwgreader.cpp \ + $$PWD/libdxfrw/intern/dwgreader15.cpp \ + $$PWD/libdxfrw/intern/dwgreader18.cpp \ + $$PWD/libdxfrw/intern/dwgreader21.cpp \ + $$PWD/libdxfrw/intern/dwgreader24.cpp \ + $$PWD/libdxfrw/intern/dwgreader27.cpp \ + $$PWD/libdxfrw/intern/dwgutil.cpp \ + $$PWD/libdxfrw/intern/dxfreader.cpp \ + $$PWD/libdxfrw/intern/dxfwriter.cpp \ + $$PWD/libdxfrw/intern/rscodec.cpp \ + $$PWD/libdxfrw/drw_classes.cpp \ + $$PWD/libdxfrw/drw_entities.cpp \ + $$PWD/libdxfrw/drw_header.cpp \ + $$PWD/libdxfrw/drw_objects.cpp \ + $$PWD/libdxfrw/libdwgr.cpp \ + $$PWD/libdxfrw/libdxfrw.cpp \ + $$PWD/dxiface.cpp \ + $$PWD/dxfdef.cpp win32-msvc*:SOURCES += $$PWD/stable.cpp HEADERS += \ $$PWD/stable.h \ - $$PWD/dxflib/dl_attributes.h \ - $$PWD/dxflib/dl_codes.h \ - $$PWD/dxflib/dl_creationadapter.h \ - $$PWD/dxflib/dl_creationinterface.h \ - $$PWD/dxflib/dl_dxf.h \ - $$PWD/dxflib/dl_entities.h \ - $$PWD/dxflib/dl_extrusion.h \ - $$PWD/dxflib/dl_global.h \ - $$PWD/dxflib/dl_writer.h \ - $$PWD/dxflib/dl_writer_ascii.h \ $$PWD/vdxfengine.h \ $$PWD/vdxfpaintdevice.h \ $$PWD/dxfdef.h \ - $$PWD/dxflib/strlcpy.h + $$PWD/libdxfrw/intern/drw_dbg.h \ + $$PWD/libdxfrw/intern/drw_textcodec.h \ + $$PWD/libdxfrw/intern/dwgbuffer.h \ + $$PWD/libdxfrw/intern/dwgreader.h \ + $$PWD/libdxfrw/intern/dwgreader15.h \ + $$PWD/libdxfrw/intern/dwgreader18.h \ + $$PWD/libdxfrw/intern/dwgreader21.h \ + $$PWD/libdxfrw/intern/dwgreader24.h \ + $$PWD/libdxfrw/intern/dwgreader27.h \ + $$PWD/libdxfrw/intern/dwgutil.h \ + $$PWD/libdxfrw/intern/dxfreader.h \ + $$PWD/libdxfrw/intern/dxfwriter.h \ + $$PWD/libdxfrw/intern/rscodec.h \ + $$PWD/libdxfrw/drw_base.h \ + $$PWD/libdxfrw/drw_classes.h \ + $$PWD/libdxfrw/drw_entities.h \ + $$PWD/libdxfrw/drw_header.h \ + $$PWD/libdxfrw/drw_interface.h \ + $$PWD/libdxfrw/drw_objects.h \ + $$PWD/libdxfrw/libdwgr.h \ + $$PWD/libdxfrw/libdxfrw.h \ + $$PWD/libdxfrw/main_doc.h \ + $$PWD/dxiface.h diff --git a/src/libs/vdxf/vdxfengine.cpp b/src/libs/vdxf/vdxfengine.cpp index 734532f19..a7bc3a0c9 100644 --- a/src/libs/vdxf/vdxfengine.cpp +++ b/src/libs/vdxf/vdxfengine.cpp @@ -48,11 +48,7 @@ #include "../vmisc/def.h" #include "../vmisc/diagnostic.h" #include "../vmisc/vmath.h" -#include "dxflib/dl_attributes.h" -#include "dxflib/dl_codes.h" -#include "dxflib/dl_dxf.h" -#include "dxflib/dl_entities.h" -#include "dxflib/dl_writer_ascii.h" +#include "dxiface.h" //--------------------------------------------------------------------------------------------------------------------- static inline QPaintEngine::PaintEngineFeatures svgEngineFeatures() @@ -77,20 +73,23 @@ VDxfEngine::VDxfEngine() size(), resolution(static_cast(PrintDPI)), fileName(), + m_version(DRW::AC1014), + m_binary(false), matrix(), - dxf(nullptr), - dw(nullptr), + input(), varMeasurement(VarMeasurement::Metric), - varInsunits(VarInsunits::Centimeters) + varInsunits(VarInsunits::Centimeters), + textBuffer(new DRW_Text()) { } - //--------------------------------------------------------------------------------------------------------------------- +//--------------------------------------------------------------------------------------------------------------------- VDxfEngine::~VDxfEngine() { + delete textBuffer; } - //--------------------------------------------------------------------------------------------------------------------- +//--------------------------------------------------------------------------------------------------------------------- bool VDxfEngine::begin(QPaintDevice *pdev) { Q_UNUSED(pdev) @@ -100,147 +99,19 @@ bool VDxfEngine::begin(QPaintDevice *pdev) return false; } - dxf = new DL_Dxf(); - DL_Codes::version exportVersion = DL_Codes::AC1015; - QByteArray fileNameArray = getFileName().toLocal8Bit(); - dw = dxf->out(fileNameArray.data(), exportVersion); - - if (dw==nullptr) - { - qWarning("VDxfEngine::begin(), can't open file"); - return false; - } - - dxf->writeHeader(*dw); - - dxf->writeComment(*dw, "Valentina DXF File"); - - dw->dxfString(9, "$ANGDIR"); // 1 = Clockwise angles, 0 = Counterclockwise - dw->dxfInt(70, 0); // Qt use counterclockwise - - dw->dxfString(9, "$MEASUREMENT"); // Sets drawing units: 0 = English; 1 = Metric - dw->dxfInt(70, static_cast(varMeasurement)); - - dw->dxfString(9, "$INSUNITS"); - dw->dxfInt(70, static_cast(varInsunits)); - - dw->dxfString(9, "$DIMSCALE"); - dw->dxfReal(40, 1.0); - - // Official documentation says that initial value is 1.0, however LibreCAD has trouble if not set this value - // explicitly. - dw->dxfString(9, "$DIMLFAC"); - dw->dxfReal(40, 1.0); - - QString dateTime = QDateTime::currentDateTime().toString("yyyyMMdd.HHmmsszzz"); - dateTime.chop(1);// we need hundredths of a second - dw->dxfString(9, "$TDCREATE"); - dw->dxfString(40, dateTime.toUtf8().constData()); - - dw->sectionEnd(); - - dw->sectionTables(); - dxf->writeVPort(*dw); - - dw->tableLinetypes(25); - dxf->writeLinetype(*dw, DL_LinetypeData("BYBLOCK", "BYBLOCK", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("BYLAYER", "BYLAYER", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("CONTINUOUS", "Continuous", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("ACAD_ISO02W100", "ACAD_ISO02W100", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("ACAD_ISO03W100", "ACAD_ISO03W100", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("ACAD_ISO04W100", "ACAD_ISO04W100", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("ACAD_ISO05W100", "ACAD_ISO05W100", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("BORDER", "BORDER", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("BORDER2", "BORDER2", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("BORDERX2", "BORDERX2", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("CENTER", "CENTER", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("CENTER2", "CENTER2", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("CENTERX2", "CENTERX2", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("DASHDOT", "DASHDOT", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("DASHDOT2", "DASHDOT2", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("DASHDOTX2", "DASHDOTX2", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("DASHED", "DASHED", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("DASHED2", "DASHED2", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("DASHEDX2", "DASHEDX2", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("DIVIDE", "DIVIDE", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("DIVIDE2", "DIVIDE2", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("DIVIDEX2", "DIVIDEX2", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("DOT", "DOT", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("DOT2", "DOT2", 0, 0, 0.0)); - dxf->writeLinetype(*dw, DL_LinetypeData("DOTX2", "DOTX2", 0, 0, 0.0)); - dw->tableEnd(); - - int numberOfLayers = 1; - dw->tableLayers(numberOfLayers); - dxf->writeLayer(*dw, - DL_LayerData("0", 0), - DL_Attributes( - std::string(""), // leave empty - DL_Codes::black, // default color - 100, // default width - "CONTINUOUS", // default line style - 1.0)); // default line type scale - - dw->tableEnd(); - - dw->tableStyle(1); - DL_StyleData style("Standard", 0, 0.0, 1.0, 0.0, 0, 2.5, "txt", ""); - style.bold = false; - style.italic = false; - dxf->writeStyle(*dw, style); - dw->tableEnd(); - - dxf->writeView(*dw); - dxf->writeUcs(*dw); - dw->tableAppid(1); - dw->tableAppidEntry(0x12); - dw->dxfString(2, "ACAD"); - dw->dxfInt(70, 0); - dw->tableEnd(); - - dxf->writeDimStyle(*dw, 1, 1, 1, 1, 1); - - dxf->writeBlockRecord(*dw); - dxf->writeBlockRecord(*dw, "layout"); - dw->tableEnd(); - - dw->sectionEnd(); - - dw->sectionBlocks(); - dxf->writeBlock(*dw, DL_BlockData("*Model_Space", 0, 0.0, 0.0, 0.0)); - dxf->writeEndBlock(*dw, "*Model_Space"); - dxf->writeBlock(*dw, DL_BlockData("*Paper_Space", 0, 0.0, 0.0, 0.0)); - dxf->writeEndBlock(*dw, "*Paper_Space"); - dxf->writeBlock(*dw, DL_BlockData("*Paper_Space0", 0, 0.0, 0.0, 0.0)); - dxf->writeEndBlock(*dw, "*Paper_Space0"); - - dxf->writeBlock(*dw, DL_BlockData("layout", 0, 0.0, 0.0, 0.0)); - // ... - // write block entities e.g. with dxf->writeLine(), .. - // ... - dxf->writeEndBlock(*dw, "layout"); - - dw->sectionEnd(); - - dw->sectionEntities(); + input = QSharedPointer(new dx_iface(fileName.toStdString(), m_version, varMeasurement, varInsunits)); return true; } - //--------------------------------------------------------------------------------------------------------------------- +//--------------------------------------------------------------------------------------------------------------------- bool VDxfEngine::end() { - dw->sectionEnd(); - dxf->writeObjects(*dw); - dxf->writeObjectsEnd(*dw); - dw->dxfEOF(); - dw->close(); - delete dw; - delete dxf; - return true; + const bool res = input->fileExport(m_binary); + return res; } - //--------------------------------------------------------------------------------------------------------------------- - // cppcheck-suppress unusedFunction +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction void VDxfEngine::updateState(const QPaintEngineState &state) { QPaintEngine::DirtyFlags flags = state.state(); @@ -255,7 +126,7 @@ void VDxfEngine::updateState(const QPaintEngineState &state) } } - //--------------------------------------------------------------------------------------------------------------------- +//--------------------------------------------------------------------------------------------------------------------- void VDxfEngine::drawPath(const QPainterPath &path) { const QList subpaths = path.toSubpathPolygons(matrix); @@ -265,21 +136,54 @@ void VDxfEngine::drawPath(const QPainterPath &path) const QPolygonF polygon = subpaths.at(j); if (polygon.isEmpty()) { - return; + continue; } - dxf->writePolyline(*dw, - DL_PolylineData(polygon.size(), 0, 0, 0), - DL_Attributes("0", getPenColor(), -1, getPenStyle(), 1.0)); + if (m_version > DRW::AC1009) + { // Use lwpolyline + DRW_LWPolyline *poly = new DRW_LWPolyline(); + poly->layer = "0"; + poly->color = getPenColor(); + poly->lWeight = DRW_LW_Conv::widthByLayer; + poly->lineType = getPenStyle(); - for (int i=0; i < polygon.count(); ++i) - { - dxf->writeVertex(*dw, - DL_VertexData(FromPixel(polygon.at(i).x(), varInsunits), + if (polygon.size() > 1 && polygon.first() == polygon.last()) + { + poly->flags |= 0x1; // closed + } + + poly->flags |= 0x80; // plinegen + + for (int i=0; i < polygon.count(); ++i) + { + poly->addVertex(DRW_Vertex2D(FromPixel(polygon.at(i).x(), varInsunits), + FromPixel(getSize().height() - polygon.at(i).y(), varInsunits), 0)); + } + + input->AddEntity(poly); + } + else + { // Use polyline + DRW_Polyline *poly = new DRW_Polyline(); + poly->layer = "0"; + poly->color = getPenColor(); + poly->lWeight = DRW_LW_Conv::widthByLayer; + poly->lineType = getPenStyle(); + if (polygon.size() > 1 && polygon.first() == polygon.last()) + { + poly->flags |= 0x1; // closed + } + + poly->flags |= 0x80; // plinegen + + for (int i=0; i < polygon.count(); ++i) + { + poly->addVertex(DRW_Vertex(FromPixel(polygon.at(i).x(), varInsunits), FromPixel(getSize().height() - polygon.at(i).y(), varInsunits), 0, 0)); - } + } - dxf->writePolylineEnd(*dw); + input->AddEntity(poly); + } } } @@ -291,14 +195,17 @@ void VDxfEngine::drawLines(const QLineF * lines, int lineCount) const QPointF p1 = matrix.map(lines[i].p1()); const QPointF p2 = matrix.map(lines[i].p2()); - dxf->writeLine(*dw, - DL_LineData(FromPixel(p1.x(), varInsunits), // start point - FromPixel(getSize().height() - p1.y(), varInsunits), - FromPixel(0.0, varInsunits), - FromPixel(p2.x(), varInsunits), // end point - FromPixel(getSize().height() - p2.y(), varInsunits), - FromPixel(0.0, varInsunits)), - DL_Attributes("0", getPenColor(), -1, getPenStyle(), 1.0)); + DRW_Line *line = new DRW_Line(); + line->basePoint = DRW_Coord(FromPixel(p1.x(), varInsunits), + FromPixel(getSize().height() - p1.y(), varInsunits), 0); + line->secPoint = DRW_Coord(FromPixel(p2.x(), varInsunits), + FromPixel(getSize().height() - p2.y(), varInsunits), 0); + line->layer = "0"; + line->color = getPenColor(); + line->lWeight = DRW_LW_Conv::widthByLayer; + line->lineType = getPenStyle(); + + input->AddEntity(line); } } @@ -318,19 +225,54 @@ void VDxfEngine::drawPolygon(const QPointF *points, int pointCount, PolygonDrawM return; } - dxf->writePolyline(*dw, - DL_PolylineData(pointCount, 0, 0, 0), - DL_Attributes("0", getPenColor(), -1, getPenStyle(), 1.0)); + if (m_version > DRW::AC1009) + { // Use lwpolyline + DRW_LWPolyline *poly = new DRW_LWPolyline(); + poly->layer = "0"; + poly->color = getPenColor(); + poly->lWeight = DRW_LW_Conv::widthByLayer; + poly->lineType = getPenStyle(); - for (int i = 0; i < pointCount; ++i) - { - const QPointF p = matrix.map(points[i]); - dxf->writeVertex(*dw, - DL_VertexData(FromPixel(p.x(), varInsunits), - FromPixel(getSize().height() - p.y(), varInsunits), 0, 0)); + if (pointCount > 1 && points[0] == points[pointCount]) + { + poly->flags |= 0x1; // closed + } + + poly->flags |= 0x80; // plinegen + + for (int i = 0; i < pointCount; ++i) + { + const QPointF p = matrix.map(points[i]); + poly->addVertex(DRW_Vertex2D(FromPixel(p.x(), varInsunits), + FromPixel(getSize().height() - p.y(), varInsunits), 0)); + } + + input->AddEntity(poly); } + else + { // Use polyline + DRW_Polyline *poly = new DRW_Polyline(); + poly->layer = "0"; + poly->color = getPenColor(); + poly->lWeight = DRW_LW_Conv::widthByLayer; + poly->lineType = getPenStyle(); - dxf->writePolylineEnd(*dw); + if (pointCount > 1 && points[0] == points[pointCount]) + { + poly->flags |= 0x1; // closed + } + + poly->flags |= 0x80; // plinegen + + for (int i = 0; i < pointCount; ++i) + { + const QPointF p = matrix.map(points[i]); + poly->addVertex(DRW_Vertex(FromPixel(p.x(), varInsunits), + FromPixel(getSize().height() - p.y(), varInsunits), 0, 0)); + } + + input->AddEntity(poly); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -364,17 +306,20 @@ void VDxfEngine::drawEllipse(const QRectF & rect) ratio = rect.height()/rect.width(); } - dxf->writeEllipse(*dw, - DL_EllipseData(FromPixel(newRect.center().x(), varInsunits), // center X - FromPixel(getSize().height() - newRect.center().y(), varInsunits), // center Y - FromPixel(0, varInsunits), // center Z - FromPixel(majorX, varInsunits), - FromPixel(majorY, varInsunits), - FromPixel(0, varInsunits), - FromPixel(ratio, varInsunits), - 0, 6.28 // startangle and endangle of ellipse in rad - ), - DL_Attributes("0", getPenColor(), -1, getPenStyle(), 1.0)); + DRW_Ellipse *ellipse = new DRW_Ellipse(); + ellipse->basePoint = DRW_Coord(FromPixel(newRect.center().x(), varInsunits), + FromPixel(getSize().height() - newRect.center().y(), varInsunits), 0); + ellipse->secPoint = DRW_Coord(FromPixel(majorX, varInsunits), FromPixel(majorY, varInsunits), 0); + ellipse->ratio = ratio; + ellipse->staparam = 0; + ellipse->endparam = 2*M_PI; + + ellipse->layer = "0"; + ellipse->color = getPenColor(); + ellipse->lWeight = DRW_LW_Conv::widthByLayer; + ellipse->lineType = getPenStyle(); + + input->AddEntity(ellipse); } //--------------------------------------------------------------------------------------------------------------------- @@ -386,38 +331,56 @@ void VDxfEngine::drawEllipse(const QRect & rect) //--------------------------------------------------------------------------------------------------------------------- void VDxfEngine::drawTextItem(const QPointF & p, const QTextItem & textItem) { - const QPointF startPoint = matrix.map(p); - const double rotationAngle = atan(matrix.m12()/matrix.m11()); + if (textBuffer->text.size() == 0) + { + const QPointF startPoint = matrix.map(p); + const double rotationAngle = qRadiansToDegrees(qAtan2(matrix.m12(), matrix.m11())); - const QFont f = textItem.font(); - const int textSize = f.pixelSize() == -1 ? f.pointSize() : f.pixelSize(); - dxf->writeText(*dw, - DL_TextData(FromPixel(startPoint.x(), varInsunits), - FromPixel(getSize().height() - startPoint.y(), varInsunits), - FromPixel(0, varInsunits), - FromPixel(startPoint.x(), varInsunits), - FromPixel(getSize().height() - startPoint.y(), varInsunits), - FromPixel(0, varInsunits), - textSize * matrix.m11(), - 1, // relative X scale factor - 0, // flag (0 = default, 2 = Backwards, 4 = Upside down) - 0, // Horizontal justification (0 = Left (default), 1 = Center, 2 = Right,) - 0, // Vertical justification (0 = Baseline (default), 1 = Bottom, 2 = Middle, 3= Top) - textItem.text().toUtf8().constData(), // text data - f.family().toUtf8().constData(), // font - -rotationAngle - ), - DL_Attributes("0", getPenColor(), -1, getPenStyle(), 1.0)); + const QFont f = textItem.font(); + const UTF8STRING fontStyle = input->AddFont(f); + + textBuffer->basePoint = DRW_Coord(FromPixel(startPoint.x(), varInsunits), + FromPixel(getSize().height() - startPoint.y(), varInsunits), 0); + textBuffer->secPoint = DRW_Coord(FromPixel(startPoint.x(), varInsunits), + FromPixel(getSize().height() - startPoint.y(), varInsunits), 0); + textBuffer->height = FromPixel(QFontMetrics(f).height(), varInsunits); + + textBuffer->style = fontStyle; + textBuffer->angle = -rotationAngle; + + textBuffer->layer = "0"; + textBuffer->color = getPenColor(); + textBuffer->lWeight = DRW_LW_Conv::widthByLayer; + textBuffer->lineType = getPenStyle(); + } + + /* Because QPaintEngine::drawTextItem doesn't pass whole string per time we mark end of each string by adding + * special placholder. */ + QString t = textItem.text(); + const bool foundEndOfString = t.contains(endStringPlaceholder); + + if (foundEndOfString) + { + t.replace(endStringPlaceholder, ""); + } + + textBuffer->text += t.toStdString(); + + if (foundEndOfString) + { + input->AddEntity(textBuffer); + textBuffer = new DRW_Text(); + } } - //--------------------------------------------------------------------------------------------------------------------- +//--------------------------------------------------------------------------------------------------------------------- QPaintEngine::Type VDxfEngine::type() const { return QPaintEngine::User; } - //--------------------------------------------------------------------------------------------------------------------- - // cppcheck-suppress unusedFunction +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction void VDxfEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) { Q_UNUSED(r) @@ -444,26 +407,51 @@ double VDxfEngine::getResolution() const return resolution; } - //--------------------------------------------------------------------------------------------------------------------- +//--------------------------------------------------------------------------------------------------------------------- void VDxfEngine::setResolution(double value) { Q_ASSERT(not isActive()); resolution = value; } - //--------------------------------------------------------------------------------------------------------------------- +//--------------------------------------------------------------------------------------------------------------------- QString VDxfEngine::getFileName() const { return fileName; } - //--------------------------------------------------------------------------------------------------------------------- +//--------------------------------------------------------------------------------------------------------------------- void VDxfEngine::setFileName(const QString &value) { Q_ASSERT(not isActive()); fileName = value; } +//--------------------------------------------------------------------------------------------------------------------- +DRW::Version VDxfEngine::GetVersion() const +{ + return m_version; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::SetVersion(DRW::Version version) +{ + Q_ASSERT(not isActive()); + m_version = version; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfEngine::SetBinaryFormat(bool binary) +{ + m_binary = binary; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VDxfEngine::IsBinaryFormat() const +{ + return m_binary; +} + //--------------------------------------------------------------------------------------------------------------------- std::string VDxfEngine::getPenStyle() { @@ -474,9 +462,9 @@ std::string VDxfEngine::getPenStyle() case Qt::DotLine: return "DOT"; case Qt::DashDotLine: - return "DASHDOT"; + return "DASHDOT2"; case Qt::DashDotDotLine: - return "DIVIDE"; + return "DIVIDE2"; case Qt::SolidLine: default: return "BYLAYER"; @@ -490,67 +478,67 @@ int VDxfEngine::getPenColor() if(color == Qt::black) { - return DL_Codes::black; + return DRW::black; } else if(color == Qt::white) { - return DL_Codes::white; + return DRW::white; } else if(color == Qt::darkGray) { - return DL_Codes::gray; + return DRW::gray; } else if(color == Qt::gray) { - return DL_Codes::l_gray; + return DRW::l_gray; } else if(color == Qt::darkMagenta) { - return DL_Codes::magenta; + return DRW::magenta; } else if(color == Qt::magenta) { - return DL_Codes::l_magenta; + return DRW::l_magenta; } else if(color == Qt::cyan) { - return DL_Codes::l_cyan; + return DRW::l_cyan; } else if(color == Qt::darkCyan) { - return DL_Codes::cyan; + return DRW::cyan; } else if(color == Qt::blue) { - return DL_Codes::l_blue; + return DRW::l_blue; } else if(color == Qt::darkBlue) { - return DL_Codes::blue; + return DRW::blue; } else if(color == Qt::darkGreen) { - return DL_Codes::green; + return DRW::green; } else if(color == Qt::green) { - return DL_Codes::l_green; + return DRW::l_green; } else if(color == Qt::darkRed) { - return DL_Codes::red; + return DRW::red; } else if(color == Qt::red) { - return DL_Codes::l_red; + return DRW::l_red; } else if(color == Qt::yellow) { - return DL_Codes::yellow; + return DRW::yellow; } else { - return DL_Codes::bylayer; + return DRW::ColorByLayer; } } diff --git a/src/libs/vdxf/vdxfengine.h b/src/libs/vdxf/vdxfengine.h index 839e50a6a..1382b2a81 100644 --- a/src/libs/vdxf/vdxfengine.h +++ b/src/libs/vdxf/vdxfengine.h @@ -41,15 +41,17 @@ #include "../vmisc/def.h" #include "dxfdef.h" -#include "dxflib/dl_dxf.h" +#include "libdxfrw/drw_base.h" class QTextStream; +class dx_iface; +class DRW_Text; class VDxfEngine : public QPaintEngine { public: VDxfEngine(); - virtual ~VDxfEngine() Q_DECL_OVERRIDE; + virtual ~VDxfEngine(); virtual bool begin(QPaintDevice *pdev) Q_DECL_OVERRIDE; virtual bool end() Q_DECL_OVERRIDE; @@ -74,6 +76,12 @@ public: QString getFileName() const; void setFileName(const QString &value); + DRW::Version GetVersion() const; + void SetVersion(DRW::Version version); + + void SetBinaryFormat(bool binary); + bool IsBinaryFormat() const; + std::string getPenStyle(); int getPenColor(); @@ -85,11 +93,13 @@ private: QSize size; double resolution; QString fileName; + DRW::Version m_version; + bool m_binary; QMatrix matrix; - DL_Dxf* dxf; - DL_WriterA* dw; + QSharedPointer input; VarMeasurement varMeasurement; VarInsunits varInsunits; + DRW_Text *textBuffer; Q_REQUIRED_RESULT double FromPixel(double pix, const VarInsunits &unit) const; }; diff --git a/src/libs/vdxf/vdxfpaintdevice.cpp b/src/libs/vdxf/vdxfpaintdevice.cpp index 38c6cec44..cbfdb4deb 100644 --- a/src/libs/vdxf/vdxfpaintdevice.cpp +++ b/src/libs/vdxf/vdxfpaintdevice.cpp @@ -98,18 +98,67 @@ double VDxfPaintDevice::getResolution() const //--------------------------------------------------------------------------------------------------------------------- void VDxfPaintDevice::setResolution(double dpi) { + if (engine->isActive()) + { + qWarning("VDxfPaintDevice::setResolution(), cannot set dpi while Dxf is being generated"); + return; + } engine->setResolution(dpi); } +//--------------------------------------------------------------------------------------------------------------------- +DRW::Version VDxfPaintDevice::GetVersion() const +{ + return engine->GetVersion(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfPaintDevice::SetVersion(DRW::Version version) +{ + if (engine->isActive()) + { + qWarning("VDxfPaintDevice::SetVersion(), cannot set version while Dxf is being generated"); + return; + } + engine->SetVersion(version); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VDxfPaintDevice::SetBinaryFormat(bool binary) +{ + if (engine->isActive()) + { + qWarning("VDxfPaintDevice::SetBinaryFormat(), cannot set binary format while Dxf is being generated"); + return; + } + engine->SetBinaryFormat(binary); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VDxfPaintDevice::IsBinaryFromat() const +{ + return engine->IsBinaryFormat(); +} + //--------------------------------------------------------------------------------------------------------------------- void VDxfPaintDevice::setMeasurement(const VarMeasurement &var) { + if (engine->isActive()) + { + qWarning("VDxfPaintDevice::setMeasurement(), cannot set measurements while Dxf is being generated"); + return; + } engine->setMeasurement(var); } //--------------------------------------------------------------------------------------------------------------------- void VDxfPaintDevice::setInsunits(const VarInsunits &var) { + if (engine->isActive()) + { + qWarning("VDxfPaintDevice::setInsunits(), cannot set units while Dxf is being generated"); + return; + } engine->setInsunits(var); } diff --git a/src/libs/vdxf/vdxfpaintdevice.h b/src/libs/vdxf/vdxfpaintdevice.h index 643c79f03..0739005a2 100644 --- a/src/libs/vdxf/vdxfpaintdevice.h +++ b/src/libs/vdxf/vdxfpaintdevice.h @@ -36,7 +36,7 @@ #include #include "dxfdef.h" -#include "dxflib/../dxfdef.h" +#include "libdxfrw/drw_base.h" class VDxfEngine; @@ -56,6 +56,12 @@ public: double getResolution() const; void setResolution(double dpi); + DRW::Version GetVersion() const; + void SetVersion(DRW::Version version); + + void SetBinaryFormat(bool binary); + bool IsBinaryFromat() const; + void setMeasurement(const VarMeasurement &var); void setInsunits(const VarInsunits &var); diff --git a/src/libs/vdxf/warnings.pri b/src/libs/vdxf/warnings.pri index 84d1846db..074e23573 100644 --- a/src/libs/vdxf/warnings.pri +++ b/src/libs/vdxf/warnings.pri @@ -10,6 +10,17 @@ unix { QMAKE_CXXFLAGS += -Werror } + # -isystem key works only for headers. In some cases it's not enough. But we can't delete these warnings and + # want them in the global list. Compromise decision is to delete them from the local list. + QMAKE_CXXFLAGS -= \ + -Weffc++ \ + -Wconversion \ + -Wold-style-cast \ + -Wstack-protector \ + -Wswitch-default \ + -Wimplicit-fallthrough \ + -Wfloat-equal + noAddressSanitizer{ # For enable run qmake with CONFIG+=noAddressSanitizer # do nothing } else { diff --git a/src/libs/vlayout/vlayoutgenerator.cpp b/src/libs/vlayout/vlayoutgenerator.cpp index 5813ec678..914c4c717 100644 --- a/src/libs/vlayout/vlayoutgenerator.cpp +++ b/src/libs/vlayout/vlayoutgenerator.cpp @@ -61,7 +61,8 @@ VLayoutGenerator::VLayoutGenerator(QObject *parent) unitePages(false), stripOptimizationEnabled(false), multiplier(1), - stripOptimization(false) + stripOptimization(false), + textAsPaths(false) {} //--------------------------------------------------------------------------------------------------------------------- @@ -209,7 +210,7 @@ QList VLayoutGenerator::GetPapersItems() const QList list; for (int i=0; i < papers.count(); ++i) { - list.append(papers.at(i).GetPaperItem(autoCrop)); + list.append(papers.at(i).GetPaperItem(autoCrop, IsTestAsPaths())); } return list; } @@ -220,7 +221,7 @@ QList > VLayoutGenerator::GetAllDetails() const QList > list; for (int i=0; i < papers.count(); ++i) { - list.append(papers.at(i).GetItemDetails()); + list.append(papers.at(i).GetItemDetails(IsTestAsPaths())); } return list; } @@ -245,6 +246,18 @@ void VLayoutGenerator::SetStripOptimization(bool value) stripOptimization = value; } +//--------------------------------------------------------------------------------------------------------------------- +bool VLayoutGenerator::IsTestAsPaths() const +{ + return textAsPaths; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutGenerator::SetTestAsPaths(bool value) +{ + textAsPaths = value; +} + //--------------------------------------------------------------------------------------------------------------------- quint8 VLayoutGenerator::GetMultiplier() const { diff --git a/src/libs/vlayout/vlayoutgenerator.h b/src/libs/vlayout/vlayoutgenerator.h index 334afd00d..0055e919c 100644 --- a/src/libs/vlayout/vlayoutgenerator.h +++ b/src/libs/vlayout/vlayoutgenerator.h @@ -106,6 +106,9 @@ public: bool IsStripOptimization() const; void SetStripOptimization(bool value); + bool IsTestAsPaths() const; + void SetTestAsPaths(bool value); + signals: void Start(); void Arranged(int count); @@ -134,6 +137,7 @@ private: bool stripOptimizationEnabled; quint8 multiplier; bool stripOptimization; + bool textAsPaths; int PageHeight() const; int PageWidth() const; diff --git a/src/libs/vlayout/vlayoutpaper.cpp b/src/libs/vlayout/vlayoutpaper.cpp index 82379571d..911f8d884 100644 --- a/src/libs/vlayout/vlayoutpaper.cpp +++ b/src/libs/vlayout/vlayoutpaper.cpp @@ -315,13 +315,13 @@ bool VLayoutPaper::SaveResult(const VBestSquare &bestResult, const VLayoutPiece } //--------------------------------------------------------------------------------------------------------------------- -QGraphicsRectItem *VLayoutPaper::GetPaperItem(bool autoCrop) const +QGraphicsRectItem *VLayoutPaper::GetPaperItem(bool autoCrop, bool textAsPaths) const { QGraphicsRectItem *paper; if (autoCrop) { QScopedPointer scene(new QGraphicsScene()); - QList list = GetItemDetails(); + QList list = GetItemDetails(textAsPaths); for (int i=0; i < list.size(); ++i) { scene->addItem(list.at(i)); @@ -346,12 +346,12 @@ QGraphicsRectItem *VLayoutPaper::GetPaperItem(bool autoCrop) const } //--------------------------------------------------------------------------------------------------------------------- -QList VLayoutPaper::GetItemDetails() const +QList VLayoutPaper::GetItemDetails(bool textAsPaths) const { QList list; for (int i=0; i < d->details.count(); ++i) { - list.append(d->details.at(i).GetItem()); + list.append(d->details.at(i).GetItem(textAsPaths)); } return list; } diff --git a/src/libs/vlayout/vlayoutpaper.h b/src/libs/vlayout/vlayoutpaper.h index 80b76a612..8d100bd63 100644 --- a/src/libs/vlayout/vlayoutpaper.h +++ b/src/libs/vlayout/vlayoutpaper.h @@ -88,8 +88,8 @@ public: bool ArrangeDetail(const VLayoutPiece &detail, std::atomic_bool &stop); int Count() const; - Q_REQUIRED_RESULT QGraphicsRectItem *GetPaperItem(bool autoCrop) const; - Q_REQUIRED_RESULT QList GetItemDetails() const; + Q_REQUIRED_RESULT QGraphicsRectItem *GetPaperItem(bool autoCrop, bool textAsPaths) const; + Q_REQUIRED_RESULT QList GetItemDetails(bool textAsPaths) const; QVector GetDetails() const; void SetDetails(const QList& details); diff --git a/src/libs/vlayout/vlayoutpiece.cpp b/src/libs/vlayout/vlayoutpiece.cpp index a05f7b640..6f6c704c7 100644 --- a/src/libs/vlayout/vlayoutpiece.cpp +++ b/src/libs/vlayout/vlayoutpiece.cpp @@ -336,19 +336,6 @@ QPointF RotatePoint(const QPointF &ptCenter, const QPointF& pt, qreal dAng) return ptDest + ptCenter; } - -//--------------------------------------------------------------------------------------------------------------------- -void CreateLabel(QGraphicsItem *parent, const QPainterPath &path) -{ - SCASSERT(parent != nullptr) - - if (not path.isEmpty()) - { - QGraphicsPathItem* item = new QGraphicsPathItem(parent); - item->setPath(path); - item->setBrush(QBrush(Qt::black)); - } -} } //--------------------------------------------------------------------------------------------------------------------- @@ -398,14 +385,15 @@ VLayoutPiece VLayoutPiece::Create(const VPiece &piece, const VContainer *pattern const VPieceLabelData& data = piece.GetPatternPieceData(); if (data.IsVisible() == true) { - det.SetDetail(piece.GetName(), data, QApplication::font(), pattern); + det.SetDetail(piece.GetName(), data, qApp->Settings()->GetLabelFont(), pattern); } const VPatternLabelData& geom = piece.GetPatternInfo(); if (geom.IsVisible() == true) { VAbstractPattern* pDoc = qApp->getCurrentDocument(); - det.SetPatternInfo(pDoc, geom, QApplication::font(), VContainer::size(), VContainer::height(), pattern); + det.SetPatternInfo(pDoc, geom, qApp->Settings()->GetLabelFont(), VContainer::size(), VContainer::height(), + pattern); } const VGrainlineData& grainlineGeom = piece.GetGrainlineGeometry(); @@ -489,8 +477,9 @@ void VLayoutPiece::SetDetail(const QString& qsName, const VPieceLabelData& data, << QPointF(ptPos.x() + labelWidth, ptPos.y() + labelHeight) << QPointF(ptPos.x(), ptPos.y() + labelHeight); - const qreal dAng = qDegreesToRadians(labelAngle); + const qreal dAng = qDegreesToRadians(-labelAngle); const QPointF ptCenter(ptPos.x() + labelWidth/2, ptPos.y() + labelHeight/2); + for (int i = 0; i < v.count(); ++i) { v[i] = RotatePoint(ptCenter, v.at(i), dAng); @@ -530,7 +519,7 @@ void VLayoutPiece::SetPatternInfo(const VAbstractPattern* pDoc, const VPatternLa << QPointF(ptPos.x() + labelWidth, ptPos.y() + labelHeight) << QPointF(ptPos.x(), ptPos.y() + labelHeight); - const qreal dAng = qDegreesToRadians(labelAngle); + const qreal dAng = qDegreesToRadians(-labelAngle); const QPointF ptCenter(ptPos.x() + labelWidth/2, ptPos.y() + labelHeight/2); for (int i = 0; i < v.count(); ++i) { @@ -934,7 +923,7 @@ QPainterPath VLayoutPiece::LayoutAllowancePath() const } //--------------------------------------------------------------------------------------------------------------------- -QGraphicsItem *VLayoutPiece::GetItem() const +QGraphicsItem *VLayoutPiece::GetItem(bool textAsPaths) const { QGraphicsPathItem *item = GetMainItem(); @@ -943,13 +932,108 @@ QGraphicsItem *VLayoutPiece::GetItem() const CreateInternalPathItem(i, item); } - CreateLabel(item, CreateLabelText(d->detailLabel, d->m_tmDetail)); - CreateLabel(item, CreateLabelText(d->patternInfo, d->m_tmPattern)); + CreateLabelStrings(item, d->detailLabel, d->m_tmDetail, textAsPaths); + CreateLabelStrings(item, d->patternInfo, d->m_tmPattern, textAsPaths); CreateGrainlineItem(item); return item; } +//--------------------------------------------------------------------------------------------------------------------- +void VLayoutPiece::CreateLabelStrings(QGraphicsItem *parent, const QVector &labelShape, + const VTextManager &tm, bool textAsPaths) const +{ + SCASSERT(parent != nullptr) + + if (labelShape.count() > 2) + { + const qreal dW = QLineF(labelShape.at(0), labelShape.at(1)).length(); + const qreal dH = QLineF(labelShape.at(1), labelShape.at(2)).length(); + const qreal angle = - QLineF(labelShape.at(0), labelShape.at(1)).angle(); + qreal dY = 0; + qreal dX = 0; + + for (int i = 0; i < tm.GetSourceLinesCount(); ++i) + { + const TextLine& tl = tm.GetSourceLine(i); + QFont fnt = tm.GetFont(); + fnt.setPixelSize(tm.GetFont().pixelSize() + tl.m_iFontSize); + fnt.setWeight(tl.m_eFontWeight); + fnt.setStyle(tl.m_eStyle); + + QFontMetrics fm(fnt); + + if (textAsPaths) + { + dY += fm.height(); + } + + if (dY > dH) + { + break; + } + + QString qsText = tl.m_qsText; + if (fm.width(qsText) > dW) + { + qsText = fm.elidedText(qsText, Qt::ElideMiddle, static_cast(dW)); + } + if ((tl.m_eAlign & Qt::AlignLeft) > 0) + { + dX = 0; + } + else if ((tl.m_eAlign & Qt::AlignHCenter) > 0) + { + dX = (dW - fm.width(qsText))/2; + } + else + { + dX = dW - fm.width(qsText); + } + + // set up the rotation around top-left corner matrix + QTransform labelMatrix; + labelMatrix.translate(labelShape.at(0).x(), labelShape.at(0).y()); + if (d->mirror) + { + labelMatrix.scale(-1, 1); + labelMatrix.rotate(angle); + labelMatrix.translate(-dW, 0); + labelMatrix.translate(dX, dY); // Each string has own position + } + else + { + labelMatrix.rotate(angle); + labelMatrix.translate(dX, dY); // Each string has own position + } + + labelMatrix *= d->matrix; + + if (textAsPaths) + { + QPainterPath path; + path.addText(0, - static_cast(fm.ascent())/6., fnt, qsText); + + QGraphicsPathItem* item = new QGraphicsPathItem(parent); + item->setPath(path); + item->setBrush(QBrush(Qt::black)); + item->setTransform(labelMatrix); + + dY += tm.GetSpacing(); + } + else + { + QGraphicsSimpleTextItem* item = new QGraphicsSimpleTextItem(parent); + item->setFont(fnt); + item->setText(qsText); + item->setTransform(labelMatrix); + + dY += (fm.height() + tm.GetSpacing()); + } + } + } +} + //--------------------------------------------------------------------------------------------------------------------- void VLayoutPiece::CreateGrainlineItem(QGraphicsItem *parent) const { @@ -1062,74 +1146,3 @@ int VLayoutPiece::EdgeByPoint(const QVector &path, const QPointF &p1) c } return 0; // Did not find edge } - -//--------------------------------------------------------------------------------------------------------------------- -QPainterPath VLayoutPiece::CreateLabelText(const QVector &labelShape, const VTextManager &tm) const -{ - QPainterPath textpath; - if (labelShape.count() > 2) - { - const qreal dW = QLineF(labelShape.at(0), labelShape.at(1)).length(); - const qreal dH = QLineF(labelShape.at(1), labelShape.at(2)).length(); - const qreal angle = QLineF(labelShape.at(0), labelShape.at(1)).angle(); - qreal dY = 0; - qreal dX; - - // set up the rotation around top-left corner matrix - QTransform mat; - mat.translate(labelShape.at(0).x(), labelShape.at(0).y()); - if (d->mirror) - { - mat.scale(-1, 1); - mat.rotate(angle); - mat.translate(-dW, 0); - } - else - { - mat.rotate(angle); - } - - mat *= d->matrix; - - for (int i = 0; i < tm.GetSourceLinesCount(); ++i) - { - const TextLine& tl = tm.GetSourceLine(i); - QFont fnt = tm.GetFont(); - fnt.setPixelSize(tm.GetFont().pixelSize() + tl.m_iFontSize); - fnt.setWeight(tl.m_eFontWeight); - fnt.setStyle(tl.m_eStyle); - - QFontMetrics fm(fnt); - - dY += fm.height(); - if (dY > dH) - { - break; - } - - QString qsText = tl.m_qsText; - if (fm.width(qsText) > dW) - { - qsText = fm.elidedText(qsText, Qt::ElideMiddle, static_cast(dW)); - } - if ((tl.m_eAlign & Qt::AlignLeft) > 0) - { - dX = 0; - } - else if ((tl.m_eAlign & Qt::AlignHCenter) > 0) - { - dX = (dW - fm.width(qsText))/2; - } - else - { - dX = dW - fm.width(qsText); - } - QPainterPath path; - path.addText(dX, dY - (fm.height() - fm.ascent())/2, fnt, qsText); - textpath.addPath(mat.map(path)); - dY += tm.GetSpacing(); - } - } - - return textpath; -} diff --git a/src/libs/vlayout/vlayoutpiece.h b/src/libs/vlayout/vlayoutpiece.h index ba43d4235..358abe18b 100644 --- a/src/libs/vlayout/vlayoutpiece.h +++ b/src/libs/vlayout/vlayoutpiece.h @@ -126,7 +126,7 @@ public: QPainterPath ContourPath() const; QPainterPath LayoutAllowancePath() const; - Q_REQUIRED_RESULT QGraphicsItem *GetItem() const; + Q_REQUIRED_RESULT QGraphicsItem *GetItem(bool textAsPaths) const; private: QSharedDataPointer d; @@ -135,9 +135,9 @@ private: Q_REQUIRED_RESULT QGraphicsPathItem *GetMainItem() const; - QPainterPath CreateLabelText(const QVector &labelShape, const VTextManager &tm) const; - void CreateInternalPathItem(int i, QGraphicsItem *parent) const; + void CreateLabelStrings(QGraphicsItem *parent, const QVector &labelShape, const VTextManager &tm, + bool textAsPaths) const; void CreateGrainlineItem(QGraphicsItem *parent) const; template diff --git a/src/libs/vlayout/warnings.pri b/src/libs/vlayout/warnings.pri index f80effc8d..29c54daef 100644 --- a/src/libs/vlayout/warnings.pri +++ b/src/libs/vlayout/warnings.pri @@ -11,11 +11,6 @@ unix { QMAKE_CXXFLAGS += -Werror } - # -isystem key works only for headers. In some cases it's not enough. But we can't delete these warnings and - # want them in the global list. Compromise decision is to delete them from the local list. - QMAKE_CXXFLAGS -= \ - -Wlong-long \ - noAddressSanitizer{ # For enable run qmake with CONFIG+=noAddressSanitizer # do nothing } else { diff --git a/src/libs/vmisc/commandoptions.cpp b/src/libs/vmisc/commandoptions.cpp index 3b5c1c674..5f3e072d2 100644 --- a/src/libs/vmisc/commandoptions.cpp +++ b/src/libs/vmisc/commandoptions.cpp @@ -49,6 +49,9 @@ const QString SINGLE_OPTION_PAGETEMPLATE = QStringLiteral("p"); const QString LONG_OPTION_EXP2FORMAT = QStringLiteral("format"); const QString SINGLE_OPTION_EXP2FORMAT = QStringLiteral("f"); +const QString LONG_OPTION_BINARYDXF = QStringLiteral("bdxf"); +const QString LONG_OPTION_TEXT2PATHS = QStringLiteral("text2paths"); + const QString LONG_OPTION_ROTATE = QStringLiteral("rotate"); const QString SINGLE_OPTION_ROTATE = QStringLiteral("r"); @@ -115,6 +118,7 @@ QStringList AllKeys() << LONG_OPTION_MEASUREFILE << SINGLE_OPTION_MEASUREFILE << LONG_OPTION_PAGETEMPLATE << SINGLE_OPTION_PAGETEMPLATE << LONG_OPTION_EXP2FORMAT << SINGLE_OPTION_EXP2FORMAT + << LONG_OPTION_BINARYDXF << LONG_OPTION_ROTATE << SINGLE_OPTION_ROTATE << LONG_OPTION_CROP << SINGLE_OPTION_CROP << LONG_OPTION_UNITE << SINGLE_OPTION_UNITE diff --git a/src/libs/vmisc/commandoptions.h b/src/libs/vmisc/commandoptions.h index dc8cb5125..fb7888dc9 100644 --- a/src/libs/vmisc/commandoptions.h +++ b/src/libs/vmisc/commandoptions.h @@ -46,6 +46,9 @@ extern const QString SINGLE_OPTION_PAGETEMPLATE; extern const QString LONG_OPTION_EXP2FORMAT; extern const QString SINGLE_OPTION_EXP2FORMAT; +extern const QString LONG_OPTION_BINARYDXF; +extern const QString LONG_OPTION_TEXT2PATHS; + extern const QString LONG_OPTION_ROTATE; extern const QString SINGLE_OPTION_ROTATE; diff --git a/src/libs/vmisc/vcommonsettings.cpp b/src/libs/vmisc/vcommonsettings.cpp index 11a84390f..f3242184c 100644 --- a/src/libs/vmisc/vcommonsettings.cpp +++ b/src/libs/vmisc/vcommonsettings.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include "../vmisc/def.h" #include "../vmisc/vmath.h" @@ -65,6 +66,7 @@ const QString settingPatternForbidFlipping = QStringLiteral("pattern/fo const QString settingPatternHideMainPath = QStringLiteral("pattern/hideMainPath"); const QString settingDoublePassmark = QStringLiteral("pattern/doublePassmark"); const QString settingPatternDefaultSeamAllowance = QStringLiteral("pattern/defaultSeamAllowance"); +const QString settingLabelFont = QStringLiteral("pattern/labelFont"); const QString settingGeneralRecentFileList = QStringLiteral("recentFileList"); const QString settingGeneralRestoreFileList = QStringLiteral("restoreFileList"); @@ -810,4 +812,14 @@ double VCommonSettings::GetDefaultSeamAllowance() return val; } +//--------------------------------------------------------------------------------------------------------------------- +QFont VCommonSettings::GetLabelFont() const +{ + return qvariant_cast(value(settingLabelFont, QApplication::font())); +} +//--------------------------------------------------------------------------------------------------------------------- +void VCommonSettings::SetLabelFont(const QFont &f) +{ + setValue(settingLabelFont, f); +} diff --git a/src/libs/vmisc/vcommonsettings.h b/src/libs/vmisc/vcommonsettings.h index d30c8b5d3..ab57fe4ca 100644 --- a/src/libs/vmisc/vcommonsettings.h +++ b/src/libs/vmisc/vcommonsettings.h @@ -160,6 +160,8 @@ public: void SetDefaultSeamAllowance(double value); double GetDefaultSeamAllowance(); + QFont GetLabelFont() const; + void SetLabelFont(const QFont &f); #if !defined(Q_OS_WIN) static const QString unixStandardSharePath; diff --git a/src/libs/vmisc/vsettings.cpp b/src/libs/vmisc/vsettings.cpp index 10f4fbee1..5cab4a234 100644 --- a/src/libs/vmisc/vsettings.cpp +++ b/src/libs/vmisc/vsettings.cpp @@ -44,6 +44,8 @@ Q_DECLARE_METATYPE(QMarginsF) +namespace +{ const QString settingConfigurationLabelLanguage = QStringLiteral("configuration/label_language"); const QString settingPathsPattern = QStringLiteral("paths/pattern"); @@ -76,6 +78,8 @@ const QString settingFields = QStringLiteral("layout/fields"); const QString settingIgnoreFields = QStringLiteral("layout/ignoreFields"); const QString settingStripOptimization = QStringLiteral("layout/stripOptimization"); const QString settingMultiplier = QStringLiteral("layout/multiplier"); +const QString settingTextAsPaths = QStringLiteral("layout/textAsPaths"); +} //--------------------------------------------------------------------------------------------------------------------- VSettings::VSettings(Format format, Scope scope, const QString &organization, const QString &application, @@ -584,3 +588,21 @@ void VSettings::SetMultiplier(quint8 value) setValue(settingMultiplier, value); } +//--------------------------------------------------------------------------------------------------------------------- +bool VSettings::GetTextAsPaths() const +{ + return value(settingTextAsPaths, GetDefTextAsPaths()).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VSettings::GetDefTextAsPaths() +{ + return false; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VSettings::SetTextAsPaths(bool value) +{ + setValue(settingTextAsPaths, value); +} + diff --git a/src/libs/vmisc/vsettings.h b/src/libs/vmisc/vsettings.h index 5e2a4b966..bd3d37f7e 100644 --- a/src/libs/vmisc/vsettings.h +++ b/src/libs/vmisc/vsettings.h @@ -151,6 +151,10 @@ public: static quint8 GetDefMultiplier(); void SetMultiplier(quint8 value); + bool GetTextAsPaths() const; + static bool GetDefTextAsPaths(); + void SetTextAsPaths(bool value); + private: Q_DISABLE_COPY(VSettings) }; diff --git a/src/libs/vtools/dialogs/support/dialogeditwrongformula.h b/src/libs/vtools/dialogs/support/dialogeditwrongformula.h index 63b6e6455..957b9f49f 100644 --- a/src/libs/vtools/dialogs/support/dialogeditwrongformula.h +++ b/src/libs/vtools/dialogs/support/dialogeditwrongformula.h @@ -40,6 +40,7 @@ #include "../tools/dialogtool.h" template class QSharedPointer; +class VMeasurement; namespace Ui { diff --git a/src/libs/vtools/dialogs/tools/dialoginsertnode.cpp b/src/libs/vtools/dialogs/tools/dialoginsertnode.cpp index 8bfce9fc3..bd5d1f227 100644 --- a/src/libs/vtools/dialogs/tools/dialoginsertnode.cpp +++ b/src/libs/vtools/dialogs/tools/dialoginsertnode.cpp @@ -28,6 +28,7 @@ #include "dialoginsertnode.h" #include "ui_dialoginsertnode.h" +#include "../vpatterndb/vcontainer.h" //--------------------------------------------------------------------------------------------------------------------- DialogInsertNode::DialogInsertNode(const VContainer *data, quint32 toolId, QWidget *parent) diff --git a/src/libs/vtools/tools/vtoolseamallowance.cpp b/src/libs/vtools/tools/vtoolseamallowance.cpp index db4aad286..0a80c7071 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.cpp +++ b/src/libs/vtools/tools/vtoolseamallowance.cpp @@ -1557,7 +1557,7 @@ bool VToolSeamAllowance::PrepareLabelData(const VPatternLabelData &labelData, VT } labelItem->SetMoveType(type); - QFont fnt = QApplication::font(); + QFont fnt = qApp->Settings()->GetLabelFont(); { const int iFS = labelData.GetFontSize(); iFS < MIN_FONT_SIZE ? fnt.setPixelSize(MIN_FONT_SIZE) : fnt.setPixelSize(iFS); diff --git a/src/libs/vtools/tools/vtoolseamallowance.h b/src/libs/vtools/tools/vtoolseamallowance.h index 9b7b5ad82..f8375705e 100644 --- a/src/libs/vtools/tools/vtoolseamallowance.h +++ b/src/libs/vtools/tools/vtoolseamallowance.h @@ -105,9 +105,9 @@ public slots: virtual void UpdateAll(); virtual void retranslateUi(); void Highlight(quint32 id); + void UpdateDetailLabel(); + void UpdatePatternInfo(); protected slots: - void UpdateDetailLabel(); - void UpdatePatternInfo(); void UpdateGrainline(); void SaveMoveDetail(const QPointF &ptPos); void SaveResizeDetail(qreal dLabelW, int iFontSize); diff --git a/src/libs/vtools/visualization/line/operation/visoperation.h b/src/libs/vtools/visualization/line/operation/visoperation.h index 83ffbb06e..491bb69be 100644 --- a/src/libs/vtools/visualization/line/operation/visoperation.h +++ b/src/libs/vtools/visualization/line/operation/visoperation.h @@ -32,6 +32,7 @@ #include #include "../visline.h" +#include "../vpatterndb/vcontainer.h" class VisOperation : public VisLine { diff --git a/src/libs/vtools/visualization/line/vistoolpin.cpp b/src/libs/vtools/visualization/line/vistoolpin.cpp index 369a0d60f..3da8f48e7 100644 --- a/src/libs/vtools/visualization/line/vistoolpin.cpp +++ b/src/libs/vtools/visualization/line/vistoolpin.cpp @@ -29,6 +29,7 @@ #include "vistoolpin.h" #include "../vwidgets/vsimplepoint.h" #include "../vgeometry/vpointf.h" +#include "../vpatterndb/vcontainer.h" //--------------------------------------------------------------------------------------------------------------------- VisToolPin::VisToolPin(const VContainer *data, QGraphicsItem *parent) diff --git a/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.h b/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.h index afd5801df..d11aae3a8 100644 --- a/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.h +++ b/src/libs/vtools/visualization/line/vistoolpointfromarcandtangent.h @@ -41,6 +41,8 @@ #include "../vmisc/def.h" #include "visline.h" +class VArc; + class VisToolPointFromArcAndTangent : public VisLine { Q_OBJECT diff --git a/src/libs/vtools/visualization/path/vispiecepins.cpp b/src/libs/vtools/visualization/path/vispiecepins.cpp index 0bc203128..d197e6f39 100644 --- a/src/libs/vtools/visualization/path/vispiecepins.cpp +++ b/src/libs/vtools/visualization/path/vispiecepins.cpp @@ -29,6 +29,7 @@ #include "vispiecepins.h" #include "../vwidgets/vsimplepoint.h" #include "../vgeometry/vpointf.h" +#include "../vpatterndb/vcontainer.h" //--------------------------------------------------------------------------------------------------------------------- VisPiecePins::VisPiecePins(const VContainer *data, QGraphicsItem *parent) diff --git a/src/libs/vtools/visualization/visualization.h b/src/libs/vtools/visualization/visualization.h index db88ae295..523221735 100644 --- a/src/libs/vtools/visualization/visualization.h +++ b/src/libs/vtools/visualization/visualization.h @@ -37,15 +37,16 @@ #include "../vmisc/def.h" #include "../vmisc/logging.h" #include "../vmisc/vabstractapplication.h" -#include "../vpatterndb/vcontainer.h" #include "../vwidgets/vmaingraphicsscene.h" #include "../vwidgets/vcurvepathitem.h" #include "../vwidgets/global.h" +#include "../vgeometry/vabstractcurve.h" Q_DECLARE_LOGGING_CATEGORY(vVis) class VScaledEllipse; class VScaledLine; +class VContainer; enum class Mode : char {Creation, Show};