mirror of
https://github.com/leozide/leocad
synced 2025-02-07 08:45:49 +01:00
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:
parent
5adcfb4027
commit
f91da8a7ce
8 changed files with 77 additions and 8 deletions
|
@ -347,7 +347,10 @@ bool lcApplication::Initialize(QList<QPair<QString, bool>>& LibraryPaths, bool&
|
||||||
else if (Param == QLatin1String("-sl") || Param == QLatin1String("--stud-logo"))
|
else if (Param == QLatin1String("-sl") || Param == QLatin1String("--stud-logo"))
|
||||||
{
|
{
|
||||||
ParseInteger(StudLogo);
|
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"))
|
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_ANTIALIASING_SAMPLES, Options.AASamples);
|
||||||
lcSetProfileInt(LC_PROFILE_STUD_LOGO, Options.StudLogo);
|
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."));
|
QMessageBox::information(gMainWindow, tr("LeoCAD"), tr("Some changes will only take effect the next time you start LeoCAD."));
|
||||||
|
|
||||||
if (Options.CategoriesModified)
|
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
|
// TODO: printing preferences
|
||||||
/*
|
/*
|
||||||
strcpy(opts.strFooter, m_strFooter);
|
strcpy(opts.strFooter, m_strFooter);
|
||||||
|
|
|
@ -248,6 +248,8 @@ bool lcPiecesLibrary::Load(const QString& LibraryPath, bool ShowProgress)
|
||||||
{
|
{
|
||||||
Unload();
|
Unload();
|
||||||
|
|
||||||
|
mReloadStudLogo = false;
|
||||||
|
|
||||||
auto LoadCustomColors = []()
|
auto LoadCustomColors = []()
|
||||||
{
|
{
|
||||||
QString CustomColorsPath = lcGetProfileString(LC_PROFILE_COLOR_CONFIG);
|
QString CustomColorsPath = lcGetProfileString(LC_PROFILE_COLOR_CONFIG);
|
||||||
|
@ -1151,8 +1153,11 @@ void lcPiecesLibrary::LoadPieceInfo(PieceInfo* Info, bool Wait, bool Priority)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (Info->AddRef() == 1)
|
bool ReloadStudLogo = Info->mHasLogoStud && mReloadStudLogo;
|
||||||
|
if (Info->AddRef() == 1 || ReloadStudLogo)
|
||||||
{
|
{
|
||||||
|
if (ReloadStudLogo)
|
||||||
|
Info->mState = LC_PIECEINFO_UNLOADED;
|
||||||
if (Priority)
|
if (Priority)
|
||||||
mLoadQueue.prepend(Info);
|
mLoadQueue.prepend(Info);
|
||||||
else
|
else
|
||||||
|
@ -1251,7 +1256,10 @@ bool lcPiecesLibrary::LoadPieceData(PieceInfo* Info)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (Info)
|
if (Info)
|
||||||
|
{
|
||||||
|
Info->mHasLogoStud = MeshData.mHasLogoStud;
|
||||||
Info->SetMesh(MeshData.CreateMesh());
|
Info->SetMesh(MeshData.CreateMesh());
|
||||||
|
}
|
||||||
|
|
||||||
if (SaveCache)
|
if (SaveCache)
|
||||||
SaveCachePiece(Info);
|
SaveCachePiece(Info);
|
||||||
|
@ -1549,6 +1557,21 @@ void lcPiecesLibrary::UploadTextures(lcContext* Context)
|
||||||
mTextureUploads.clear();
|
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)
|
bool lcPiecesLibrary::GetStudLogo(lcMemFile& PrimFile, int StudLogo, bool OpenStud)
|
||||||
{
|
{
|
||||||
// validate logo choice and unofficial lib available
|
// validate logo choice and unofficial lib available
|
||||||
|
@ -1619,8 +1642,9 @@ bool lcPiecesLibrary::LoadPrimitive(lcLibraryPrimitive* Primitive)
|
||||||
if (StudLogo)
|
if (StudLogo)
|
||||||
{
|
{
|
||||||
bool OpenStud = !strcmp(Primitive->mName,"stud2.dat");
|
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);
|
SetStudLogo = GetStudLogo(PrimFile,StudLogo,OpenStud);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1653,9 +1677,10 @@ bool lcPiecesLibrary::LoadPrimitive(lcLibraryPrimitive* Primitive)
|
||||||
lcMemFile PrimFile;
|
lcMemFile PrimFile;
|
||||||
|
|
||||||
bool OpenStud = !strcmp(Primitive->mName,"stud2.dat");
|
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);
|
SetStudLogo = MeshLoader.LoadMesh(PrimFile, LC_MESHDATA_SHARED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ public:
|
||||||
mState = lcPrimitiveState::NOT_LOADED;
|
mState = lcPrimitiveState::NOT_LOADED;
|
||||||
mStud = Stud;
|
mStud = Stud;
|
||||||
mSubFile = SubFile;
|
mSubFile = SubFile;
|
||||||
|
mReloadStudLogo = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetZipFile(lcZipFileType ZipFileType, quint32 ZipFileIndex)
|
void SetZipFile(lcZipFileType ZipFileType, quint32 ZipFileIndex)
|
||||||
|
@ -60,6 +61,7 @@ public:
|
||||||
lcPrimitiveState mState;
|
lcPrimitiveState mState;
|
||||||
bool mStud;
|
bool mStud;
|
||||||
bool mSubFile;
|
bool mSubFile;
|
||||||
|
bool mReloadStudLogo;
|
||||||
lcLibraryMeshData mMeshData;
|
lcLibraryMeshData mMeshData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -115,6 +117,8 @@ public:
|
||||||
|
|
||||||
bool GetStudLogo(lcMemFile& PrimFile, int StudLogo, bool OpenStud = false);
|
bool GetStudLogo(lcMemFile& PrimFile, int StudLogo, bool OpenStud = false);
|
||||||
|
|
||||||
|
void SetStudLogo(int StudLogo);
|
||||||
|
|
||||||
void SetOfficialPieces()
|
void SetOfficialPieces()
|
||||||
{
|
{
|
||||||
if (mZipFiles[LC_ZIPFILE_OFFICIAL])
|
if (mZipFiles[LC_ZIPFILE_OFFICIAL])
|
||||||
|
@ -138,6 +142,7 @@ public:
|
||||||
|
|
||||||
QDir mLibraryDir;
|
QDir mLibraryDir;
|
||||||
|
|
||||||
|
bool mReloadStudLogo;
|
||||||
bool mBuffersDirty;
|
bool mBuffersDirty;
|
||||||
lcVertexBuffer mVertexBuffer;
|
lcVertexBuffer mVertexBuffer;
|
||||||
lcIndexBuffer mIndexBuffer;
|
lcIndexBuffer mIndexBuffer;
|
||||||
|
|
|
@ -1623,11 +1623,22 @@ bool lcMeshLoader::ReadMeshData(lcFile& File, const lcMatrix44& CurrentTransform
|
||||||
|
|
||||||
if (Primitive)
|
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))
|
if (Primitive->mState != lcPrimitiveState::LOADED && !Library->LoadPrimitive(Primitive))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (Primitive->mStud)
|
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);
|
mMeshData.AddMeshDataNoDuplicateCheck(Primitive->mMeshData, IncludeTransform, ColorCode, Mirror ^ InvertNext, InvertNext, TextureMap, MeshDataType);
|
||||||
|
}
|
||||||
else if (!Primitive->mSubFile)
|
else if (!Primitive->mSubFile)
|
||||||
{
|
{
|
||||||
if (mOptimize)
|
if (mOptimize)
|
||||||
|
|
|
@ -97,6 +97,7 @@ public:
|
||||||
lcLibraryMeshData()
|
lcLibraryMeshData()
|
||||||
{
|
{
|
||||||
mHasTextures = false;
|
mHasTextures = false;
|
||||||
|
mHasLogoStud = false;
|
||||||
|
|
||||||
for (int MeshDataIdx = 0; MeshDataIdx < LC_NUM_MESHDATA_TYPES; MeshDataIdx++)
|
for (int MeshDataIdx = 0; MeshDataIdx < LC_NUM_MESHDATA_TYPES; MeshDataIdx++)
|
||||||
mVertices[MeshDataIdx].SetGrow(1024);
|
mVertices[MeshDataIdx].SetGrow(1024);
|
||||||
|
@ -117,6 +118,17 @@ public:
|
||||||
return true;
|
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();
|
lcMesh* CreateMesh();
|
||||||
lcLibraryMeshSection* AddSection(lcMeshDataType MeshDataType, lcMeshPrimitiveType PrimitiveType, quint32 ColorCode, lcTexture* Texture);
|
lcLibraryMeshSection* AddSection(lcMeshDataType MeshDataType, lcMeshPrimitiveType PrimitiveType, quint32 ColorCode, lcTexture* Texture);
|
||||||
quint32 AddVertex(lcMeshDataType MeshDataType, const lcVector3& Position, bool Optimize);
|
quint32 AddVertex(lcMeshDataType MeshDataType, const lcVector3& Position, bool Optimize);
|
||||||
|
@ -135,6 +147,7 @@ public:
|
||||||
lcArray<lcLibraryMeshSection*> mSections[LC_NUM_MESHDATA_TYPES];
|
lcArray<lcLibraryMeshSection*> mSections[LC_NUM_MESHDATA_TYPES];
|
||||||
lcArray<lcLibraryMeshVertex> mVertices[LC_NUM_MESHDATA_TYPES];
|
lcArray<lcLibraryMeshVertex> mVertices[LC_NUM_MESHDATA_TYPES];
|
||||||
bool mHasTextures;
|
bool mHasTextures;
|
||||||
|
bool mHasLogoStud;
|
||||||
};
|
};
|
||||||
|
|
||||||
class lcMeshLoader
|
class lcMeshLoader
|
||||||
|
|
|
@ -25,6 +25,7 @@ PieceInfo::PieceInfo()
|
||||||
mModel = nullptr;
|
mModel = nullptr;
|
||||||
mProject = nullptr;
|
mProject = nullptr;
|
||||||
mSynthInfo = nullptr;
|
mSynthInfo = nullptr;
|
||||||
|
mHasLogoStud = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PieceInfo::~PieceInfo()
|
PieceInfo::~PieceInfo()
|
||||||
|
|
|
@ -169,6 +169,7 @@ public:
|
||||||
lcPieceInfoState mState;
|
lcPieceInfoState mState;
|
||||||
int mFolderType;
|
int mFolderType;
|
||||||
int mFolderIndex;
|
int mFolderIndex;
|
||||||
|
bool mHasLogoStud;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void ReleaseMesh();
|
void ReleaseMesh();
|
||||||
|
|
|
@ -453,6 +453,8 @@ bool Project::Load(const QString& FileName)
|
||||||
Model->UpdatePieceInfo(UpdatedModels);
|
Model->UpdatePieceInfo(UpdatedModels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lcGetPiecesLibrary()->mReloadStudLogo = false;
|
||||||
|
|
||||||
mModified = false;
|
mModified = false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Reference in a new issue