From 51fe5416b411fd7639a8a84ff64835514d445993 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Tue, 14 Jan 2020 12:48:18 -0800 Subject: [PATCH] Replaced HTML parts list with BOM style image. --- common/lc_application.cpp | 14 ---- common/lc_profile.cpp | 3 - common/lc_profile.h | 3 - common/project.cpp | 149 ++------------------------------------ common/project.h | 10 --- docs/leocad.1 | 8 -- qt/lc_qhtmldialog.cpp | 10 --- qt/lc_qhtmldialog.ui | 110 +++------------------------- 8 files changed, 14 insertions(+), 293 deletions(-) diff --git a/common/lc_application.cpp b/common/lc_application.cpp index 38e77df3..3a25b332 100644 --- a/common/lc_application.cpp +++ b/common/lc_application.cpp @@ -200,8 +200,6 @@ bool lcApplication::Initialize(QList>& LibraryPaths, bool& int StudLogo = lcGetProfileInt(LC_PROFILE_STUD_LOGO); int ImageStart = 0; int ImageEnd = 0; - int PartImagesWidth = -1; - int PartImagesHeight = -1; float CameraLatitude = 0.0f, CameraLongitude = 0.0f; QString ImageName; QString ModelName; @@ -380,10 +378,6 @@ bool lcApplication::Initialize(QList>& LibraryPaths, bool& SaveHTML = true; ParseString(SaveHTMLName, false); } - else if (Param == QLatin1String("--html-parts-width")) - ParseInteger(PartImagesWidth); - else if (Param == QLatin1String("--html-parts-height")) - ParseInteger(PartImagesHeight); else if (Param == QLatin1String("-v") || Param == QLatin1String("--version")) { #ifdef LC_CONTINUOUS_BUILD @@ -420,8 +414,6 @@ bool lcApplication::Initialize(QList>& LibraryPaths, bool& printf(" -3ds, --export-3ds : Export the model to 3D Studio 3DS format.\n"); printf(" -dae, --export-collada : Export the model to COLLADA DAE format.\n"); printf(" -html, --export-html : Create an HTML page for the model.\n"); - printf(" --html-parts-width : Set the HTML part pictures width.\n"); - printf(" --html-parts-height : Set the HTML part pictures height.\n"); printf(" -v, --version: Output version information and exit.\n"); printf(" -?, --help: Display this help message and exit.\n"); printf(" \n"); @@ -634,12 +626,6 @@ bool lcApplication::Initialize(QList>& LibraryPaths, bool& if (!SaveHTMLName.isEmpty()) Options.PathName = SaveHTMLName; - if (PartImagesWidth > 0) - Options.PartImagesWidth = PartImagesWidth; - - if (PartImagesHeight > 0) - Options.PartImagesHeight = PartImagesHeight; - mProject->ExportHTML(Options); } } diff --git a/common/lc_profile.cpp b/common/lc_profile.cpp index a666b626..b3c4deaa 100644 --- a/common/lc_profile.cpp +++ b/common/lc_profile.cpp @@ -119,9 +119,6 @@ static lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] = lcProfileEntry("HTML", "ImageOptions", LC_IMAGE_TRANSPARENT), // LC_PROFILE_HTML_IMAGE_OPTIONS lcProfileEntry("HTML", "ImageWidth", 640), // LC_PROFILE_HTML_IMAGE_WIDTH lcProfileEntry("HTML", "ImageHeight", 480), // LC_PROFILE_HTML_IMAGE_HEIGHT - lcProfileEntry("HTML", "PartsColor", 16), // LC_PROFILE_HTML_PARTS_COLOR - lcProfileEntry("HTML", "PartsWidth", 128), // LC_PROFILE_HTML_PARTS_WIDTH - lcProfileEntry("HTML", "PartsHeight", 128), // LC_PROFILE_HTML_PARTS_HEIGHT lcProfileEntry("POVRay", "Path", "/usr/bin/povray"), // LC_PROFILE_POVRAY_PATH lcProfileEntry("POVRay", "LGEOPath", ""), // LC_PROFILE_POVRAY_LGEO_PATH diff --git a/common/lc_profile.h b/common/lc_profile.h index 72ef5da3..f50c495c 100644 --- a/common/lc_profile.h +++ b/common/lc_profile.h @@ -69,9 +69,6 @@ enum LC_PROFILE_KEY LC_PROFILE_HTML_IMAGE_OPTIONS, LC_PROFILE_HTML_IMAGE_WIDTH, LC_PROFILE_HTML_IMAGE_HEIGHT, - LC_PROFILE_HTML_PARTS_COLOR, - LC_PROFILE_HTML_PARTS_WIDTH, - LC_PROFILE_HTML_PARTS_HEIGHT, LC_PROFILE_POVRAY_PATH, LC_PROFILE_POVRAY_LGEO_PATH, LC_PROFILE_POVRAY_WIDTH, diff --git a/common/project.cpp b/common/project.cpp index 4d3c550f..81a3aeac 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -39,10 +39,6 @@ lcHTMLExportOptions::lcHTMLExportOptions(const Project* Project) HighlightNewParts = (HTMLOptions & LC_HTML_HIGHLIGHT) != 0; PartsListStep = (HTMLOptions & LC_HTML_LISTSTEP) != 0; PartsListEnd = (HTMLOptions & LC_HTML_LISTEND) != 0; - PartsListImages = (HTMLOptions & LC_HTML_IMAGES) != 0; - PartImagesColor = lcGetColorIndex(lcGetProfileInt(LC_PROFILE_HTML_PARTS_COLOR)); - PartImagesWidth = lcGetProfileInt(LC_PROFILE_HTML_PARTS_WIDTH); - PartImagesHeight = lcGetProfileInt(LC_PROFILE_HTML_PARTS_HEIGHT); } void lcHTMLExportOptions::SaveDefaults() @@ -63,16 +59,11 @@ void lcHTMLExportOptions::SaveDefaults() HTMLOptions |= LC_HTML_LISTSTEP; if (PartsListEnd) HTMLOptions |= LC_HTML_LISTEND; - if (PartsListImages) - HTMLOptions |= LC_HTML_IMAGES; lcSetProfileInt(LC_PROFILE_HTML_IMAGE_OPTIONS, TransparentImages ? LC_IMAGE_TRANSPARENT : 0); lcSetProfileInt(LC_PROFILE_HTML_OPTIONS, HTMLOptions); lcSetProfileInt(LC_PROFILE_HTML_IMAGE_WIDTH, StepImagesWidth); lcSetProfileInt(LC_PROFILE_HTML_IMAGE_HEIGHT, StepImagesHeight); - lcSetProfileInt(LC_PROFILE_HTML_PARTS_COLOR, lcGetColorCode(PartImagesColor)); - lcSetProfileInt(LC_PROFILE_HTML_PARTS_WIDTH, PartImagesWidth); - lcSetProfileInt(LC_PROFILE_HTML_PARTS_HEIGHT, PartImagesHeight); } Project::Project() @@ -1697,68 +1688,6 @@ QImage Project::CreatePartsListImage(lcModel* Model, lcStep Step) return PainterImage; } -void Project::CreateHTMLPieceList(QTextStream& Stream, lcModel* Model, lcStep Step, bool Images) -{ - std::vector ColorsUsed(gColorList.size(), 0); - int NumColors = 0; - - lcPartsList PartsList; - - if (Step == 0) - Model->GetPartsList(gDefaultColor, true, false, PartsList); - else - Model->GetPartsListForStep(Step, gDefaultColor, PartsList); - - for (const auto& PartIt : PartsList) - for (const auto& ColorIt : PartIt.second) - ColorsUsed[ColorIt.first]++; - - Stream << QLatin1String("
\r\n"); - - for (size_t ColorIdx = 0; ColorIdx < gColorList.size(); ColorIdx++) - { - if (ColorsUsed[ColorIdx]) - { - ColorsUsed[ColorIdx] = NumColors++; - Stream << QString("\r\n").arg(gColorList[ColorIdx].Name); - } - } - NumColors++; - Stream << QLatin1String("\r\n"); - - for (const auto& PartIt : PartsList) - { - const PieceInfo* Info = PartIt.first; - - if (Images) - Stream << QString("\r\n").arg(QString::fromLatin1(Info->mFileName).replace('#', '_'), Info->m_strDescription); - else - Stream << QString("\r\n").arg(Info->m_strDescription); - - int CurrentColumn = 1; - for (const auto& ColorIt : PartIt.second) - { - while (CurrentColumn != ColorsUsed[ColorIt.first] + 1) - { - Stream << QLatin1String("\r\n"); - CurrentColumn++; - } - - Stream << QString("\r\n").arg(QString::number(ColorIt.second)); - CurrentColumn++; - } - - while (CurrentColumn != NumColors) - { - Stream << QLatin1String("\r\n"); - CurrentColumn++; - } - - Stream << QLatin1String("\r\n"); - } - Stream << QLatin1String("
Piece
%1
\"%2\"
%1
-
%1
-
\r\n
"); -} - void Project::ExportHTML(const lcHTMLExportOptions& Options) { QDir Dir(Options.PathName); @@ -1789,13 +1718,12 @@ void Project::ExportHTML(const lcHTMLExportOptions& Options) Image.save(FileName); - Stream << QString::fromLatin1("\r\n").arg(ImageName); + Stream << QString::fromLatin1("



\r\n").arg(ImageName); } }; - for (int ModelIdx = 0; ModelIdx < Models.GetSize(); ModelIdx++) + for (lcModel* Model : Models) { - lcModel* Model = mModels[ModelIdx]; QString BaseName = ProjectTitle.left(ProjectTitle.length() - QFileInfo(ProjectTitle).suffix().length() - 1); lcStep LastStep = Model->GetLastStep(); QString PageTitle; @@ -1827,10 +1755,10 @@ void Project::ExportHTML(const lcHTMLExportOptions& Options) for (lcStep Step = 1; Step <= LastStep; Step++) { QString StepString = QString::fromLatin1("%1").arg(Step, 2, 10, QLatin1Char('0')); - Stream << QString::fromLatin1("\"Step

\r\n").arg(BaseName, StepString, StepString, QString::number(Options.StepImagesWidth), QString::number(Options.StepImagesHeight)); + Stream << QString::fromLatin1("

\"Step



\r\n").arg(BaseName, StepString, StepString, QString::number(Options.StepImagesWidth), QString::number(Options.StepImagesHeight)); if (Options.PartsListStep) - CreateHTMLPieceList(Stream, Model, Step, Options.PartsListImages); + AddPartsListImage(Stream, Model, Step, QString("%1-%2").arg(BaseName, StepString)); } if (Options.PartsListEnd) @@ -1882,7 +1810,7 @@ void Project::ExportHTML(const lcHTMLExportOptions& Options) Stream << QString::fromLatin1("\"Step

\r\n").arg(BaseName, StepString, StepString, QString::number(Options.StepImagesWidth), QString::number(Options.StepImagesHeight)); if (Options.PartsListStep) - CreateHTMLPieceList(Stream, Model, Step, Options.PartsListImages); + AddPartsListImage(Stream, Model, Step, QString("%1-%2").arg(BaseName, StepString)); Stream << QLatin1String("\r\n


"); if (Step != 1) @@ -1928,73 +1856,6 @@ void Project::ExportHTML(const lcHTMLExportOptions& Options) QString StepImageBaseName = QFileInfo(Dir, BaseName + QLatin1String("-%1.png")).absoluteFilePath(); Model->SaveStepImages(StepImageBaseName, true, false, Options.HighlightNewParts, Options.StepImagesWidth, Options.StepImagesHeight, 1, LastStep); - - if (Options.PartsListImages) - { - View* View = gMainWindow->GetActiveView(); - View->MakeCurrent(); - lcContext* Context = View->mContext; - int Width = Options.PartImagesWidth; - int Height = Options.PartImagesHeight; - - std::pair RenderFramebuffer = Context->CreateRenderFramebuffer(Width, Height); - - if (!RenderFramebuffer.first.IsValid()) - { - QMessageBox::warning(gMainWindow, tr("LeoCAD"), tr("Error creating images.")); - return; - } - - Context->BindFramebuffer(RenderFramebuffer.first); - - float AspectRatio = (float)Width / (float)Height; - Context->SetViewport(0, 0, Width, Height); - - lcPartsList PartsList; - Model->GetPartsList(gDefaultColor, true, true, PartsList); - - lcMatrix44 ProjectionMatrix, ViewMatrix; - - Context->SetDefaultState(); - - for (const auto& PartIt : PartsList) - { - const PieceInfo* Info = PartIt.first; - - glClearColor(1.0f, 1.0f, 1.0f, 0.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - Info->ZoomExtents(30.0f, AspectRatio, ProjectionMatrix, ViewMatrix); - - Context->SetProjectionMatrix(ProjectionMatrix); - - lcScene Scene; - Scene.SetAllowWireframe(false); - Scene.SetAllowLOD(false); - Scene.Begin(ViewMatrix); - - Info->AddRenderMeshes(Scene, lcMatrix44Identity(), Options.PartImagesColor, lcRenderMeshState::Default, true); - - Scene.End(); - - Scene.Draw(Context); - - QString FileName = QFileInfo(Dir, QString::fromLatin1(Info->mFileName).replace('#', '_') + QLatin1String(".png")).absoluteFilePath(); - QImage Image = Context->GetRenderFramebufferImage(RenderFramebuffer); - - QImageWriter Writer(FileName); - - if (!Writer.write(Image)) - { - QMessageBox::information(gMainWindow, tr("Error"), tr("Error writing to file '%1':\n%2").arg(FileName, Writer.errorString())); - break; - } - } - - Context->ClearFramebuffer(); - Context->DestroyRenderFramebuffer(RenderFramebuffer); - Context->ClearResources(); - } } if (Models.GetSize() > 1) diff --git a/common/project.h b/common/project.h index 4fb01af2..e217aa74 100644 --- a/common/project.h +++ b/common/project.h @@ -4,13 +4,8 @@ #include "lc_array.h" #include "lc_application.h" -#define LC_SCENE_BG 0x010 // Draw bg image -#define LC_SCENE_BG_TILE 0x040 // Tile bg image -#define LC_SCENE_GRADIENT 0x100 // Draw gradient - #define LC_HTML_SINGLEPAGE 0x01 #define LC_HTML_INDEX 0x02 -#define LC_HTML_IMAGES 0x04 #define LC_HTML_LISTEND 0x08 #define LC_HTML_LISTSTEP 0x10 #define LC_HTML_HIGHLIGHT 0x20 @@ -34,10 +29,6 @@ public: bool HighlightNewParts; bool PartsListStep; bool PartsListEnd; - bool PartsListImages; - int PartImagesColor; - int PartImagesWidth; - int PartImagesHeight; }; enum LC_MOUSE_TRACK @@ -118,7 +109,6 @@ protected: QString GetExportFileName(const QString& FileName, const QString& DefaultExtension, const QString& DialogTitle, const QString& DialogFilter) const; std::vector GetModelParts(); QImage CreatePartsListImage(lcModel* Model, lcStep Step); - void CreateHTMLPieceList(QTextStream& Stream, lcModel* Model, lcStep Step, bool Images); void SetFileName(const QString& FileName); bool mModified; diff --git a/docs/leocad.1 b/docs/leocad.1 index 5940df18..56069c89 100644 --- a/docs/leocad.1 +++ b/docs/leocad.1 @@ -110,14 +110,6 @@ Exports the model to COLLADA DAE format. .BI "\-html [" path ] Creates an HTML page for the model. -.TP -.BI "\-\-html\-parts\-width "width -Sets the width of the part pictures when creating HTML pages to \fIwidth\fR. - -.TP -.BI "\-\-html\-parts\-height "height -Sets the height of the part pictures when creating HTML pages to \fIheight\fR. - .SH ENVIRONMENT ``LEOCAD_LIB'' may be set to the path of the parts library. diff --git a/qt/lc_qhtmldialog.cpp b/qt/lc_qhtmldialog.cpp index 733580b3..3a225ed3 100644 --- a/qt/lc_qhtmldialog.cpp +++ b/qt/lc_qhtmldialog.cpp @@ -10,8 +10,6 @@ lcQHTMLDialog::lcQHTMLDialog(QWidget* Parent, lcHTMLExportOptions* Options) ui->stepWidth->setValidator(new QIntValidator(0, 2048, ui->stepWidth)); ui->stepHeight->setValidator(new QIntValidator(0, 2048, ui->stepHeight)); - ui->partImagesWidth->setValidator(new QIntValidator(0, 2048, ui->partImagesWidth)); - ui->partImagesHeight->setValidator(new QIntValidator(0, 2048, ui->partImagesHeight)); mOptions = Options; @@ -33,10 +31,6 @@ lcQHTMLDialog::lcQHTMLDialog(QWidget* Parent, lcHTMLExportOptions* Options) ui->highlightNewParts->setChecked(mOptions->HighlightNewParts); ui->partsAfterEachStep->setChecked(mOptions->PartsListStep); ui->partsAtTheEnd->setChecked(mOptions->PartsListEnd); - ui->partImages->setChecked(mOptions->PartsListImages); - ui->partColor->setCurrentColor(mOptions->PartImagesColor); - ui->partImagesWidth->setText(QString::number(mOptions->PartImagesWidth)); - ui->partImagesHeight->setText(QString::number(mOptions->PartImagesHeight)); } lcQHTMLDialog::~lcQHTMLDialog() @@ -65,10 +59,6 @@ void lcQHTMLDialog::accept() mOptions->HighlightNewParts = ui->highlightNewParts->isChecked(); mOptions->PartsListStep = ui->partsAfterEachStep->isChecked(); mOptions->PartsListEnd = ui->partsAtTheEnd->isChecked(); - mOptions->PartsListImages = ui->partImages->isChecked(); - mOptions->PartImagesColor = ui->partColor->currentColor(); - mOptions->PartImagesWidth = ui->partImagesWidth->text().toInt(); - mOptions->PartImagesHeight = ui->partImagesHeight->text().toInt(); QDialog::accept(); } diff --git a/qt/lc_qhtmldialog.ui b/qt/lc_qhtmldialog.ui index b4129946..f6fbb8ed 100644 --- a/qt/lc_qhtmldialog.ui +++ b/qt/lc_qhtmldialog.ui @@ -178,102 +178,21 @@ Parts List - - - - - Color: - - - partColor - - - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Width: - - - partImagesWidth - - - - - - - - 75 - 16777215 - - - - - - - - Height: - - - partImagesHeight - - - - - - - - 75 - 16777215 - - - - - - - - After each step - - - - - - - Create images - - - - + + At the end + + + + After each step + + + @@ -289,13 +208,6 @@ - - - lcQColorPicker - QToolButton -
lc_qcolorpicker.h
-
-
outputFolder outputFolderBrowse @@ -311,10 +223,6 @@ highlightNewParts partsAtTheEnd partsAfterEachStep - partImages - partColor - partImagesWidth - partImagesHeight