Support merging multiple files at once. Fixes #1007.

This commit is contained in:
Leonardo Zide
2026-05-20 16:54:03 -07:00
parent 043e867061
commit 60c4a674c6
2 changed files with 31 additions and 22 deletions
+30 -20
View File
@@ -2468,37 +2468,47 @@ bool lcMainWindow::OpenProjectFile(const QString& FileName)
return false; return false;
} }
void lcMainWindow::MergeProject() void lcMainWindow::ShowMergeDialog()
{ {
QString LoadFileName = lcGetActiveProject()->GetFileName(); QString InitialFolder = lcGetActiveProject()->GetFileName();
if (LoadFileName.isEmpty()) if (InitialFolder.isEmpty())
LoadFileName = lcGetProfileString(LC_PROFILE_PROJECTS_PATH); InitialFolder = lcGetProfileString(LC_PROFILE_PROJECTS_PATH);
else
InitialFolder = QFileInfo(InitialFolder).absolutePath();
LoadFileName = QFileDialog::getOpenFileName(this, tr("Merge Model"), LoadFileName, tr("Supported Files (*.lcd *.ldr *.dat *.mpd);;All Files (*.*)")); QStringList LoadFileNames = QFileDialog::getOpenFileNames(this, tr("Merge Model"), InitialFolder, tr("Supported Files (*.lcd *.ldr *.dat *.mpd);;All Files (*.*)"));
if (LoadFileName.isEmpty()) if (LoadFileNames.isEmpty())
return; return;
lcSetProfileString(LC_PROFILE_PROJECTS_PATH, QFileInfo(LoadFileName).absolutePath()); lcSetProfileString(LC_PROFILE_PROJECTS_PATH, QFileInfo(LoadFileNames.first()).absolutePath());
Project* NewProject = new Project(); std::vector<std::unique_ptr<Project>> ProjectsToMerge;
if (NewProject->Load(LoadFileName, true)) for (const QString& LoadFileName : LoadFileNames)
{ {
size_t ModelCount = NewProject->GetModels().size(); std::unique_ptr<Project>& NewProject = ProjectsToMerge.emplace_back(std::make_unique<Project>());
lcGetActiveProject()->Merge(NewProject); if (!NewProject->Load(LoadFileName, true))
return;
if (ModelCount == 1)
QMessageBox::information(this, tr("LeoCAD"), tr("Merged 1 submodel."));
else
QMessageBox::information(this, tr("LeoCAD"), tr("Merged %1 submodels.").arg(ModelCount));
UpdateModels();
} }
delete NewProject; size_t ModelCount = 0;
for (const std::unique_ptr<Project>& ProjectToMerge : ProjectsToMerge)
{
ModelCount += ProjectToMerge->GetModels().size();
lcGetActiveProject()->Merge(ProjectToMerge.get());
}
if (ModelCount == 1)
QMessageBox::information(this, tr("LeoCAD"), tr("Merged 1 submodel."));
else
QMessageBox::information(this, tr("LeoCAD"), tr("Merged %1 submodels.").arg(ModelCount));
UpdateModels();
} }
void lcMainWindow::ImportLDD() void lcMainWindow::ImportLDD()
@@ -2674,7 +2684,7 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId)
break; break;
case LC_FILE_MERGE: case LC_FILE_MERGE:
MergeProject(); ShowMergeDialog();
break; break;
case LC_FILE_SAVE: case LC_FILE_SAVE:
+1 -2
View File
@@ -214,7 +214,6 @@ public:
void RemoveAllModelTabs(); void RemoveAllModelTabs();
void CloseCurrentModelTab(); void CloseCurrentModelTab();
void SetCurrentModelTab(lcModel* Model); void SetCurrentModelTab(lcModel* Model);
void ResetCameras();
void AddView(lcView* View); void AddView(lcView* View);
void RemoveView(lcView* View); void RemoveView(lcView* View);
@@ -238,7 +237,7 @@ public:
void NewProject(); void NewProject();
bool OpenProject(const QString& FileName); bool OpenProject(const QString& FileName);
void OpenRecentProject(int RecentFileIndex); void OpenRecentProject(int RecentFileIndex);
void MergeProject(); void ShowMergeDialog();
void ImportLDD(); void ImportLDD();
void ImportInventory(); void ImportInventory();
bool SaveProject(const QString& FileName); bool SaveProject(const QString& FileName);