Change stud logo without application restart (#389)

* Change stud logo without application restart

* Refactor change stud logo without application restart
This commit is contained in:
Trevor SANDY 2019-09-24 01:22:11 +02:00 committed by Leonardo Zide
parent 5adcfb4027
commit f91da8a7ce
8 changed files with 77 additions and 8 deletions

View file

@ -347,7 +347,10 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
else if (Param == QLatin1String("-sl") || Param == QLatin1String("--stud-logo"))
{
ParseInteger(StudLogo);
lcSetProfileInt(LC_PROFILE_STUD_LOGO, StudLogo);
if (StudLogo != lcGetProfileInt(LC_PROFILE_STUD_LOGO))
{
lcGetPiecesLibrary()->SetStudLogo(StudLogo);
}
}
else if (Param == QLatin1String("-obj") || Param == QLatin1String("--export-wavefront"))
{
@ -703,7 +706,7 @@ void lcApplication::ShowPreferencesDialog()
lcSetProfileInt(LC_PROFILE_ANTIALIASING_SAMPLES, Options.AASamples);
lcSetProfileInt(LC_PROFILE_STUD_LOGO, Options.StudLogo);
if (LibraryChanged || ColorsChanged || AAChanged || StudLogoChanged)
if (LibraryChanged || ColorsChanged || AAChanged)
QMessageBox::information(gMainWindow, tr("LeoCAD"), tr("Some changes will only take effect the next time you start LeoCAD."));
if (Options.CategoriesModified)
@ -743,6 +746,14 @@ void lcApplication::ShowPreferencesDialog()
}
}
if (StudLogoChanged)
{
lcGetPiecesLibrary()->SetStudLogo(Options.StudLogo);
QString ProjectName = lcGetProfileString(LC_PROFILE_RECENT_FILE1);
if (!ProjectName.isEmpty())
gMainWindow->OpenProject(ProjectName);
}
// TODO: printing preferences
/*
strcpy(opts.strFooter, m_strFooter);

View file

@ -248,6 +248,8 @@ bool lcPiecesLibrary::Load(const QString& LibraryPath, bool ShowProgress)
{
Unload();
mReloadStudLogo = false;
auto LoadCustomColors = []()
{
QString CustomColorsPath = lcGetProfileString(LC_PROFILE_COLOR_CONFIG);
@ -1151,8 +1153,11 @@ void lcPiecesLibrary::LoadPieceInfo(PieceInfo* Info, bool Wait, bool Priority)
}
else
{
if (Info->AddRef() == 1)
bool ReloadStudLogo = Info->mHasLogoStud && mReloadStudLogo;
if (Info->AddRef() == 1 || ReloadStudLogo)
{
if (ReloadStudLogo)
Info->mState = LC_PIECEINFO_UNLOADED;
if (Priority)
mLoadQueue.prepend(Info);
else
@ -1250,8 +1255,11 @@ bool lcPiecesLibrary::LoadPieceData(PieceInfo* Info)
if (!Loaded || mCancelLoading)
return false;
if (Info)
if (Info)
{
Info->mHasLogoStud = MeshData.mHasLogoStud;
Info->SetMesh(MeshData.CreateMesh());
}
if (SaveCache)
SaveCachePiece(Info);
@ -1549,6 +1557,21 @@ void lcPiecesLibrary::UploadTextures(lcContext* Context)
mTextureUploads.clear();
}
void lcPiecesLibrary::SetStudLogo(int StudLogo)
{
mReloadStudLogo = true;
lcSetProfileInt(LC_PROFILE_STUD_LOGO, StudLogo);
std::vector<std::string> Studs { "STUD.DAT", "STUD2.DAT" };
for (auto const& Stud: Studs)
{
lcLibraryPrimitive* StudPrim = FindPrimitive(Stud.c_str());
if (StudPrim) {
StudPrim->mReloadStudLogo = mReloadStudLogo;
mPrimitives[Stud] = StudPrim;
}
}
}
bool lcPiecesLibrary::GetStudLogo(lcMemFile& PrimFile, int StudLogo, bool OpenStud)
{
// validate logo choice and unofficial lib available
@ -1619,8 +1642,9 @@ bool lcPiecesLibrary::LoadPrimitive(lcLibraryPrimitive* Primitive)
if (StudLogo)
{
bool OpenStud = !strcmp(Primitive->mName,"stud2.dat");
if ((SetStudLogo = (OpenStud || !strcmp(Primitive->mName,"stud.dat"))))
if (OpenStud || !strcmp(Primitive->mName,"stud.dat"))
{
Primitive->mReloadStudLogo = false;
SetStudLogo = GetStudLogo(PrimFile,StudLogo,OpenStud);
}
}
@ -1653,9 +1677,10 @@ bool lcPiecesLibrary::LoadPrimitive(lcLibraryPrimitive* Primitive)
lcMemFile PrimFile;
bool OpenStud = !strcmp(Primitive->mName,"stud2.dat");
if ((SetStudLogo = (OpenStud || !strcmp(Primitive->mName,"stud.dat"))))
if (OpenStud || !strcmp(Primitive->mName,"stud.dat"))
{
if ((SetStudLogo = GetStudLogo(PrimFile,StudLogo,OpenStud)))
Primitive->mReloadStudLogo = false;
if (GetStudLogo(PrimFile,StudLogo,OpenStud))
SetStudLogo = MeshLoader.LoadMesh(PrimFile, LC_MESHDATA_SHARED);
}
}

View file

@ -45,6 +45,7 @@ public:
mState = lcPrimitiveState::NOT_LOADED;
mStud = Stud;
mSubFile = SubFile;
mReloadStudLogo = false;
}
void SetZipFile(lcZipFileType ZipFileType, quint32 ZipFileIndex)
@ -60,6 +61,7 @@ public:
lcPrimitiveState mState;
bool mStud;
bool mSubFile;
bool mReloadStudLogo;
lcLibraryMeshData mMeshData;
};
@ -113,7 +115,9 @@ public:
bool LoadPrimitive(lcLibraryPrimitive* Primitive);
bool GetStudLogo(lcMemFile& PrimFile, int StudLogo, bool OpenStud = false);
bool GetStudLogo(lcMemFile& PrimFile, int StudLogo, bool OpenStud = false);
void SetStudLogo(int StudLogo);
void SetOfficialPieces()
{
@ -138,6 +142,7 @@ public:
QDir mLibraryDir;
bool mReloadStudLogo;
bool mBuffersDirty;
lcVertexBuffer mVertexBuffer;
lcIndexBuffer mIndexBuffer;

View file

@ -1623,11 +1623,22 @@ bool lcMeshLoader::ReadMeshData(lcFile& File, const lcMatrix44& CurrentTransform
if (Primitive)
{
if (Primitive->mStud &&
Primitive->mReloadStudLogo &&
Primitive->mState == lcPrimitiveState::LOADED )
{
Primitive->mMeshData.RemoveAll();
Primitive->mState = lcPrimitiveState::NOT_LOADED;
}
if (Primitive->mState != lcPrimitiveState::LOADED && !Library->LoadPrimitive(Primitive))
break;
if (Primitive->mStud)
{
mMeshData.mHasLogoStud = !strcmp(Primitive->mName,"stud2.dat") || !strcmp(Primitive->mName,"stud.dat");
mMeshData.AddMeshDataNoDuplicateCheck(Primitive->mMeshData, IncludeTransform, ColorCode, Mirror ^ InvertNext, InvertNext, TextureMap, MeshDataType);
}
else if (!Primitive->mSubFile)
{
if (mOptimize)

View file

@ -97,6 +97,7 @@ public:
lcLibraryMeshData()
{
mHasTextures = false;
mHasLogoStud = false;
for (int MeshDataIdx = 0; MeshDataIdx < LC_NUM_MESHDATA_TYPES; MeshDataIdx++)
mVertices[MeshDataIdx].SetGrow(1024);
@ -117,6 +118,17 @@ public:
return true;
}
void RemoveAll()
{
for (int MeshDataIdx = 0; MeshDataIdx < LC_NUM_MESHDATA_TYPES; MeshDataIdx++)
mVertices[MeshDataIdx].RemoveAll();
for (int MeshDataIdx = 0; MeshDataIdx < LC_NUM_MESHDATA_TYPES; MeshDataIdx++)
mSections[MeshDataIdx].RemoveAll();
mHasTextures = false;
}
lcMesh* CreateMesh();
lcLibraryMeshSection* AddSection(lcMeshDataType MeshDataType, lcMeshPrimitiveType PrimitiveType, quint32 ColorCode, lcTexture* Texture);
quint32 AddVertex(lcMeshDataType MeshDataType, const lcVector3& Position, bool Optimize);
@ -135,6 +147,7 @@ public:
lcArray<lcLibraryMeshSection*> mSections[LC_NUM_MESHDATA_TYPES];
lcArray<lcLibraryMeshVertex> mVertices[LC_NUM_MESHDATA_TYPES];
bool mHasTextures;
bool mHasLogoStud;
};
class lcMeshLoader

View file

@ -25,6 +25,7 @@ PieceInfo::PieceInfo()
mModel = nullptr;
mProject = nullptr;
mSynthInfo = nullptr;
mHasLogoStud = false;
}
PieceInfo::~PieceInfo()

View file

@ -169,6 +169,7 @@ public:
lcPieceInfoState mState;
int mFolderType;
int mFolderIndex;
bool mHasLogoStud;
protected:
void ReleaseMesh();

View file

@ -453,6 +453,8 @@ bool Project::Load(const QString& FileName)
Model->UpdatePieceInfo(UpdatedModels);
}
lcGetPiecesLibrary()->mReloadStudLogo = false;
mModified = false;
return true;