Replaced HTML parts list with BOM style image.

This commit is contained in:
Leonardo Zide 2020-01-14 12:48:18 -08:00
parent 6d818d48d2
commit 51fe5416b4
8 changed files with 14 additions and 293 deletions

View file

@ -200,8 +200,6 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& 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<QPair<QString, bool>>& 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<QPair<QString, bool>>& LibraryPaths, bool&
printf(" -3ds, --export-3ds <outfile.3ds>: Export the model to 3D Studio 3DS format.\n");
printf(" -dae, --export-collada <outfile.dae>: Export the model to COLLADA DAE format.\n");
printf(" -html, --export-html <folder>: Create an HTML page for the model.\n");
printf(" --html-parts-width <width>: Set the HTML part pictures width.\n");
printf(" --html-parts-height <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<QPair<QString, bool>>& LibraryPaths, bool&
if (!SaveHTMLName.isEmpty())
Options.PathName = SaveHTMLName;
if (PartImagesWidth > 0)
Options.PartImagesWidth = PartImagesWidth;
if (PartImagesHeight > 0)
Options.PartImagesHeight = PartImagesHeight;
mProject->ExportHTML(Options);
}
}

View file

@ -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

View file

@ -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,

View file

@ -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<int> 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("<br><table border=1><tr><td><center>Piece</center></td>\r\n");
for (size_t ColorIdx = 0; ColorIdx < gColorList.size(); ColorIdx++)
{
if (ColorsUsed[ColorIdx])
{
ColorsUsed[ColorIdx] = NumColors++;
Stream << QString("<td><center>%1</center></td>\r\n").arg(gColorList[ColorIdx].Name);
}
}
NumColors++;
Stream << QLatin1String("</tr>\r\n");
for (const auto& PartIt : PartsList)
{
const PieceInfo* Info = PartIt.first;
if (Images)
Stream << QString("<tr><td><IMG SRC=\"%1.png\" ALT=\"%2\"></td>\r\n").arg(QString::fromLatin1(Info->mFileName).replace('#', '_'), Info->m_strDescription);
else
Stream << QString("<tr><td>%1</td>\r\n").arg(Info->m_strDescription);
int CurrentColumn = 1;
for (const auto& ColorIt : PartIt.second)
{
while (CurrentColumn != ColorsUsed[ColorIt.first] + 1)
{
Stream << QLatin1String("<td><center>-</center></td>\r\n");
CurrentColumn++;
}
Stream << QString("<td><center>%1</center></td>\r\n").arg(QString::number(ColorIt.second));
CurrentColumn++;
}
while (CurrentColumn != NumColors)
{
Stream << QLatin1String("<td><center>-</center></td>\r\n");
CurrentColumn++;
}
Stream << QLatin1String("</tr>\r\n");
}
Stream << QLatin1String("</table>\r\n<br>");
}
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("<IMG SRC=\"%1\" />\r\n").arg(ImageName);
Stream << QString::fromLatin1("<p><IMG SRC=\"%1\" /></p><br><br>\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("<IMG SRC=\"%1-%2.png\" ALT=\"Step %3\" WIDTH=%4 HEIGHT=%5><BR><BR>\r\n").arg(BaseName, StepString, StepString, QString::number(Options.StepImagesWidth), QString::number(Options.StepImagesHeight));
Stream << QString::fromLatin1("<p><IMG SRC=\"%1-%2.png\" ALT=\"Step %3\" WIDTH=%4 HEIGHT=%5></p><BR><BR>\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("<IMG SRC=\"%1-%2.png\" ALT=\"Step %3\" WIDTH=%4 HEIGHT=%5><BR><BR>\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("</CENTER>\r\n<BR><HR><BR>");
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<lcFramebuffer, lcFramebuffer> 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)

View file

@ -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<lcModelPartsEntry> GetModelParts();
QImage CreatePartsListImage(lcModel* Model, lcStep Step);
void CreateHTMLPieceList(QTextStream& Stream, lcModel* Model, lcStep Step, bool Images);
void SetFileName(const QString& FileName);
bool mModified;

View file

@ -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.

View file

@ -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();
}

View file

@ -178,102 +178,21 @@
<property name="title">
<string>Parts List</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="5" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Color:</string>
</property>
<property name="buddy">
<cstring>partColor</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="lcQColorPicker" name="partColor">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Width:</string>
</property>
<property name="buddy">
<cstring>partImagesWidth</cstring>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="partImagesWidth">
<property name="maximumSize">
<size>
<width>75</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Height:</string>
</property>
<property name="buddy">
<cstring>partImagesHeight</cstring>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QLineEdit" name="partImagesHeight">
<property name="maximumSize">
<size>
<width>75</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="partsAfterEachStep">
<property name="text">
<string>After each step</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="partImages">
<property name="text">
<string>Create images</string>
</property>
</widget>
</item>
<item row="2" column="0">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QCheckBox" name="partsAtTheEnd">
<property name="text">
<string>At the end</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="partsAfterEachStep">
<property name="text">
<string>After each step</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -289,13 +208,6 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>lcQColorPicker</class>
<extends>QToolButton</extends>
<header>lc_qcolorpicker.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>outputFolder</tabstop>
<tabstop>outputFolderBrowse</tabstop>
@ -311,10 +223,6 @@
<tabstop>highlightNewParts</tabstop>
<tabstop>partsAtTheEnd</tabstop>
<tabstop>partsAfterEachStep</tabstop>
<tabstop>partImages</tabstop>
<tabstop>partColor</tabstop>
<tabstop>partImagesWidth</tabstop>
<tabstop>partImagesHeight</tabstop>
</tabstops>
<resources/>
<connections>