Add stud logo preference and command line option (#387)

* Add stud logo preference and command line option

* Support add stud logo when using disk library
This commit is contained in:
Trevor SANDY 2019-09-21 18:47:33 +02:00 committed by Leonardo Zide
parent 23eb88df4f
commit 5adcfb4027
9 changed files with 190 additions and 63 deletions

View file

@ -75,8 +75,8 @@ lcApplication::lcApplication(int& Argc, char** Argv)
lcApplication::~lcApplication()
{
delete mProject;
delete mLibrary;
delete mProject;
delete mLibrary;
gApplication = nullptr;
}
@ -189,6 +189,7 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
bool ImageHighlight = false;
int ImageWidth = lcGetProfileInt(LC_PROFILE_IMAGE_WIDTH);
int ImageHeight = lcGetProfileInt(LC_PROFILE_IMAGE_HEIGHT);
int StudLogo = lcGetProfileInt(LC_PROFILE_STUD_LOGO);
int ImageStart = 0;
int ImageEnd = 0;
int PartImagesWidth = -1;
@ -343,6 +344,11 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
}
else if (Param == QLatin1String("--line-width"))
ParseFloat(mPreferences.mLineWidth);
else if (Param == QLatin1String("-sl") || Param == QLatin1String("--stud-logo"))
{
ParseInteger(StudLogo);
lcSetProfileInt(LC_PROFILE_STUD_LOGO, StudLogo);
}
else if (Param == QLatin1String("-obj") || Param == QLatin1String("--export-wavefront"))
{
SaveWavefront = true;
@ -392,6 +398,7 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
printf(" -t, --to <time>: Set the last step to save pictures.\n");
printf(" -s, --submodel <submodel>: Set the active submodel.\n");
printf(" -c, --camera <camera>: Set the active camera.\n");
printf(" -sl --stud-logo <type>: Set the stud logo type 0 - 5, 0 is no logo.\n");
printf(" --viewpoint <front|back|left|right|top|bottom|home>: Set the viewpoint.\n");
printf(" --camera-angles <latitude> <longitude>: Set the camera angles in degrees around the model.\n");
printf(" --orthographic: Make the view orthographic.\n");
@ -647,6 +654,7 @@ void lcApplication::ShowPreferencesDialog()
{
lcPreferencesDialogOptions Options;
int CurrentAASamples = lcGetProfileInt(LC_PROFILE_ANTIALIASING_SAMPLES);
int CurrentStudLogo = lcGetProfileInt(LC_PROFILE_STUD_LOGO);
Options.Preferences = mPreferences;
@ -659,6 +667,7 @@ void lcApplication::ShowPreferencesDialog()
Options.CheckForUpdates = lcGetProfileInt(LC_PROFILE_CHECK_UPDATES);
Options.AASamples = CurrentAASamples;
Options.StudLogo = CurrentStudLogo;
Options.Categories = gCategories;
Options.CategoriesModified = false;
@ -678,6 +687,7 @@ void lcApplication::ShowPreferencesDialog()
bool LibraryChanged = Options.LibraryPath != lcGetProfileString(LC_PROFILE_PARTS_LIBRARY);
bool ColorsChanged = Options.ColorConfigPath != lcGetProfileString(LC_PROFILE_COLOR_CONFIG);
bool AAChanged = CurrentAASamples != Options.AASamples;
bool StudLogoChanged = CurrentStudLogo != Options.StudLogo;
mPreferences = Options.Preferences;
@ -691,8 +701,9 @@ void lcApplication::ShowPreferencesDialog()
lcSetProfileString(LC_PROFILE_POVRAY_LGEO_PATH, Options.LGEOPath);
lcSetProfileInt(LC_PROFILE_CHECK_UPDATES, Options.CheckForUpdates);
lcSetProfileInt(LC_PROFILE_ANTIALIASING_SAMPLES, Options.AASamples);
lcSetProfileInt(LC_PROFILE_STUD_LOGO, Options.StudLogo);
if (LibraryChanged || ColorsChanged || AAChanged)
if (LibraryChanged || ColorsChanged || AAChanged || StudLogoChanged)
QMessageBox::information(gMainWindow, tr("LeoCAD"), tr("Some changes will only take effect the next time you start LeoCAD."));
if (Options.CategoriesModified)

View file

@ -29,6 +29,7 @@ struct lcPreferencesDialogOptions
int CheckForUpdates;
int AASamples;
int StudLogo;
lcArray<lcLibraryCategory> Categories;
bool CategoriesModified;

View file

@ -366,7 +366,7 @@ bool lcPiecesLibrary::OpenArchive(lcFile* File, const QString& FileName, lcZipFi
if (!memcmp(Dst, ".PNG", 4))
{
if ((ZipFileType == LC_ZIPFILE_OFFICIAL && !memcmp(Name, "LDRAW/PARTS/TEXTURES/", 21)) ||
(ZipFileType == LC_ZIPFILE_UNOFFICIAL && !memcmp(Name, "PARTS/TEXTURES/", 15)))
(ZipFileType == LC_ZIPFILE_UNOFFICIAL && !memcmp(Name, "PARTS/TEXTURES/", 15)))
{
lcTexture* Texture = new lcTexture();
mTextures.push_back(Texture);
@ -629,7 +629,7 @@ void lcPiecesLibrary::ReadDirectoryDescriptions(const QFileInfoList (&FileLists)
const char* FileName = (const char*)IndexFile.mBuffer + IndexFile.GetPosition();
CachedDescriptions.push_back(FileName);
IndexFile.Seek(strlen(FileName) + 1, SEEK_CUR);
const char* Description = (const char*)IndexFile.mBuffer + IndexFile.GetPosition();
const char* Description = (const char*)IndexFile.mBuffer + IndexFile.GetPosition();
IndexFile.Seek(strlen(Description) + 1, SEEK_CUR);
IndexFile.Seek(4 + 1 + 8, SEEK_CUR);
}
@ -823,7 +823,7 @@ bool lcPiecesLibrary::ReadArchiveCacheFile(const QString& FileName, lcMemFile& C
return false;
quint32 CacheVersion, CacheFlags;
if (File.read((char*)&CacheVersion, sizeof(CacheVersion)) == -1 || CacheVersion != LC_LIBRARY_CACHE_VERSION)
return false;
@ -899,7 +899,7 @@ bool lcPiecesLibrary::ReadArchiveCacheFile(const QString& FileName, lcMemFile& C
} while (ret != Z_STREAM_END);
(void)inflateEnd(&strm);
CacheFile.Seek(0, SEEK_SET);
return ret == Z_STREAM_END;
@ -914,7 +914,7 @@ bool lcPiecesLibrary::WriteArchiveCacheFile(const QString& FileName, lcMemFile&
quint32 CacheVersion = LC_LIBRARY_CACHE_VERSION;
quint32 CacheFlags = LC_LIBRARY_CACHE_ARCHIVE;
if (File.write((char*)&CacheVersion, sizeof(CacheVersion)) == -1)
return false;
@ -965,7 +965,7 @@ bool lcPiecesLibrary::WriteArchiveCacheFile(const QString& FileName, lcMemFile&
} while (Stream.avail_out == 0);
} while (FlushMode != Z_FINISH);
deflateEnd(&Stream);
deflateEnd(&Stream);
return true;
}
@ -1246,7 +1246,7 @@ bool lcPiecesLibrary::LoadPieceData(PieceInfo* Info)
Loaded = MeshLoader.LoadMesh(PieceFile, LC_MESHDATA_SHARED);
}
}
if (!Loaded || mCancelLoading)
return false;
@ -1549,6 +1549,33 @@ void lcPiecesLibrary::UploadTextures(lcContext* Context)
mTextureUploads.clear();
}
bool lcPiecesLibrary::GetStudLogo(lcMemFile& PrimFile, int StudLogo, bool OpenStud)
{
// validate logo choice and unofficial lib available
if (!StudLogo || (!mZipFiles[LC_ZIPFILE_UNOFFICIAL] && !mHasUnofficial))
return false;
// construct logo reference line
QString Logo = QString("%1").arg(StudLogo);
QString LogoRefLine = QString("1 16 0 0 0 1 0 0 0 1 0 0 0 1 ");
LogoRefLine += (OpenStud ? QString("stud2-logo%1.dat").arg(StudLogo > 1 ? Logo : ""):
QString("stud-logo%1.dat").arg(StudLogo > 1 ? Logo : ""));
// construct primitive file
QByteArray FileData;
QTextStream out(&FileData);
out << (OpenStud ? "0 Stud Open" : "0 Stud") << endl;
out << (OpenStud ? "0 Name: stud2.dat" : "0 Name: stud.dat") << endl;
out << "0 Author: James Jessiman" << endl;
out << "0 !LDRAW_ORG Primitive" << endl;
out << "0 BFC CERTIFY CCW" << endl;
out << LogoRefLine << endl;
PrimFile.WriteBuffer(FileData.constData(), size_t(FileData.size()));
PrimFile.Seek(0, SEEK_SET);
return true;
}
bool lcPiecesLibrary::LoadPrimitive(lcLibraryPrimitive* Primitive)
{
mLoadMutex.lock();
@ -1569,22 +1596,37 @@ bool lcPiecesLibrary::LoadPrimitive(lcLibraryPrimitive* Primitive)
lcMeshLoader MeshLoader(Primitive->mMeshData, true, nullptr, false);
bool SetStudLogo = false;
int StudLogo = lcGetProfileInt(LC_PROFILE_STUD_LOGO);
if (mZipFiles[LC_ZIPFILE_OFFICIAL])
{
lcLibraryPrimitive* LowPrimitive = nullptr;
if (Primitive->mStud && strncmp(Primitive->mName, "8/", 2)) // todo: this is currently the only place that uses mName so use mFileName instead. this should also be done for the loose file libraries.
{
char Name[LC_PIECE_NAME_LEN];
strcpy(Name, "8/");
strcat(Name, Primitive->mName);
LowPrimitive = FindPrimitive(Name);
}
lcMemFile PrimFile;
if (!mZipFiles[Primitive->mZipFileType]->ExtractFile(Primitive->mZipFileIndex, PrimFile))
if (Primitive->mStud)
{
if (strncmp(Primitive->mName, "8/", 2)) // todo: this is currently the only place that uses mName so use mFileName instead. this should also be done for the loose file libraries.
{
char Name[LC_PIECE_NAME_LEN];
strcpy(Name, "8/");
strcat(Name, Primitive->mName);
LowPrimitive = FindPrimitive(Name);
}
if (StudLogo)
{
bool OpenStud = !strcmp(Primitive->mName,"stud2.dat");
if ((SetStudLogo = (OpenStud || !strcmp(Primitive->mName,"stud.dat"))))
{
SetStudLogo = GetStudLogo(PrimFile,StudLogo,OpenStud);
}
}
}
if (!SetStudLogo && !mZipFiles[Primitive->mZipFileType]->ExtractFile(Primitive->mZipFileIndex, PrimFile))
return false;
if (!LowPrimitive)
@ -1606,10 +1648,25 @@ bool lcPiecesLibrary::LoadPrimitive(lcLibraryPrimitive* Primitive)
}
else
{
lcDiskFile PrimFile(Primitive->mFileName);
if (StudLogo && Primitive->mStud)
{
lcMemFile PrimFile;
if (!PrimFile.Open(QIODevice::ReadOnly) || !MeshLoader.LoadMesh(PrimFile, LC_MESHDATA_SHARED)) // todo: LOD like the zip files
return false;
bool OpenStud = !strcmp(Primitive->mName,"stud2.dat");
if ((SetStudLogo = (OpenStud || !strcmp(Primitive->mName,"stud.dat"))))
{
if ((SetStudLogo = GetStudLogo(PrimFile,StudLogo,OpenStud)))
SetStudLogo = MeshLoader.LoadMesh(PrimFile, LC_MESHDATA_SHARED);
}
}
if (!SetStudLogo)
{
lcDiskFile PrimFile(Primitive->mFileName);
if (!PrimFile.Open(QIODevice::ReadOnly) || !MeshLoader.LoadMesh(PrimFile, LC_MESHDATA_SHARED)) // todo: LOD like the zip files
return false;
}
}
mLoadMutex.lock();

View file

@ -113,6 +113,8 @@ public:
bool LoadPrimitive(lcLibraryPrimitive* Primitive);
bool GetStudLogo(lcMemFile& PrimFile, int StudLogo, bool OpenStud = false);
void SetOfficialPieces()
{
if (mZipFiles[LC_ZIPFILE_OFFICIAL])

View file

@ -98,6 +98,7 @@ static lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] =
lcProfileEntry("Settings", "PartsListDecorated", 1), // LC_PROFILE_PARTS_LIST_DECORATED
lcProfileEntry("Settings", "PartsListAliases", 1), // LC_PROFILE_PARTS_LIST_ALIASES
lcProfileEntry("Settings", "PartsListListMode", 0), // LC_PROFILE_PARTS_LIST_LISTMODE
lcProfileEntry("Settings", "StudLogo", 0), // LC_PROFILE_STUD_LOGO
lcProfileEntry("Defaults", "Author", ""), // LC_PROFILE_DEFAULT_AUTHOR_NAME
lcProfileEntry("Defaults", "FloorColor", LC_RGB(0, 191, 0)), // LC_PROFILE_DEFAULT_FLOOR_COLOR

View file

@ -46,6 +46,7 @@ enum LC_PROFILE_KEY
LC_PROFILE_PARTS_LIST_DECORATED,
LC_PROFILE_PARTS_LIST_ALIASES,
LC_PROFILE_PARTS_LIST_LISTMODE,
LC_PROFILE_STUD_LOGO,
// Defaults for new projects.
LC_PROFILE_DEFAULT_AUTHOR_NAME,

View file

@ -13,7 +13,7 @@
lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogOptions* Options)
: QDialog(Parent), mOptions(Options), ui(new Ui::lcQPreferencesDialog)
{
ui->setupUi(this);
ui->setupUi(this);
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
ui->povrayLabel->hide();
@ -77,6 +77,12 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogO
break;
}
ui->studLogo->setChecked(mOptions->StudLogo);
if (ui->studLogo->isChecked())
ui->studLogoCombo->setCurrentIndex(mOptions->StudLogo - 1);
else
ui->studLogoCombo->setCurrentIndex(mOptions->StudLogo);
if (!gSupportsShaderObjects)
ui->ShadingMode->removeItem(LC_SHADING_DEFAULT_LIGHTS);
ui->ShadingMode->setCurrentIndex(mOptions->Preferences.mShadingMode);
@ -98,6 +104,7 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogO
pix.fill(QColor(LC_RGBA_RED(mOptions->Preferences.mViewSphereHighlightColor), LC_RGBA_GREEN(mOptions->Preferences.mViewSphereHighlightColor), LC_RGBA_BLUE(mOptions->Preferences.mViewSphereHighlightColor)));
ui->ViewSphereHighlightColorButton->setIcon(pix);
on_studLogo_toggled();
on_antiAliasing_toggled();
on_edgeLines_toggled();
on_gridStuds_toggled();
@ -126,7 +133,7 @@ lcQPreferencesDialog::lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogO
lcQPreferencesDialog::~lcQPreferencesDialog()
{
delete ui;
delete ui;
}
void lcQPreferencesDialog::accept()
@ -186,6 +193,11 @@ void lcQPreferencesDialog::accept()
mOptions->Preferences.mShadingMode = (lcShadingMode)ui->ShadingMode->currentIndex();
if (ui->studLogoCombo->isEnabled())
mOptions->StudLogo = ui->studLogoCombo->currentIndex() + 1;
else
mOptions->StudLogo = 0;
QDialog::accept();
}
@ -297,6 +309,11 @@ void lcQPreferencesDialog::ColorButtonClicked()
((QToolButton*)button)->setIcon(pix);
}
void lcQPreferencesDialog::on_studLogo_toggled()
{
ui->studLogoCombo->setEnabled(ui->studLogo->isChecked());
}
void lcQPreferencesDialog::on_antiAliasing_toggled()
{
ui->antiAliasingSamples->setEnabled(ui->antiAliasing->isChecked());
@ -682,7 +699,7 @@ void lcQPreferencesDialog::on_KeyboardFilterEdit_textEdited(const QString& Text)
void lcQPreferencesDialog::on_shortcutAssign_clicked()
{
QTreeWidgetItem *current = ui->commandList->currentItem();
QTreeWidgetItem *current = ui->commandList->currentItem();
if (!current || !current->data(0, Qt::UserRole).isValid())
return;

View file

@ -10,7 +10,7 @@ class lcQPreferencesDialog;
class lcQPreferencesDialog : public QDialog
{
Q_OBJECT
public:
lcQPreferencesDialog(QWidget* Parent, lcPreferencesDialogOptions* Options);
~lcQPreferencesDialog();
@ -55,6 +55,7 @@ public slots:
void on_mouseAssign_clicked();
void on_mouseRemove_clicked();
void on_mouseReset_clicked();
void on_studLogo_toggled();
void MouseTreeItemChanged(QTreeWidgetItem* Current);
private:

View file

@ -17,7 +17,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tabGeneral">
<attribute name="title">
@ -225,13 +225,49 @@
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QCheckBox" name="edgeLines">
<item row="3" column="0">
<widget class="QCheckBox" name="axisIcon">
<property name="text">
<string>Edge lines</string>
<string>Axis icon</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Shading Mode:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="lineWidth">
<property name="maximumSize">
<size>
<width>75</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="5" column="1" colspan="2">
<widget class="QComboBox" name="ShadingMode">
<item>
<property name="text">
<string>Wireframe</string>
</property>
</item>
<item>
<property name="text">
<string>Flat Shading</string>
</property>
</item>
<item>
<property name="text">
<string>Default Lights</string>
</property>
</item>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="antiAliasingSamples">
<item>
@ -251,23 +287,6 @@
</item>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineWidth">
<property name="maximumSize">
<size>
<width>75</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="axisIcon">
<property name="text">
<string>Axis icon</string>
</property>
</widget>
</item>
<item row="0" column="3">
<spacer name="horizontalSpacer_2">
<property name="orientation">
@ -281,6 +300,20 @@
</property>
</spacer>
</item>
<item row="2" column="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>width</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="edgeLines">
<property name="text">
<string>Edge lines</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="antiAliasing">
<property name="text">
@ -288,35 +321,38 @@
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_2">
<item row="1" column="0">
<widget class="QCheckBox" name="studLogo">
<property name="text">
<string>width</string>
<string>Stud Logo</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Shading Mode:</string>
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<widget class="QComboBox" name="ShadingMode">
<item row="1" column="1">
<widget class="QComboBox" name="studLogoCombo">
<item>
<property name="text">
<string>Wireframe</string>
<string>Logo1</string>
</property>
</item>
<item>
<property name="text">
<string>Flat Shading</string>
<string>Logo2</string>
</property>
</item>
<item>
<property name="text">
<string>Default Lights</string>
<string>Logo3</string>
</property>
</item>
<item>
<property name="text">
<string>Logo4</string>
</property>
</item>
<item>
<property name="text">
<string>Logo5</string>
</property>
</item>
</widget>