diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index d6f60c5f..72f9c1d8 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -204,66 +204,34 @@ bool lcMainWindow::OpenProject(const QString& FileName) void lcMainWindow::MergeProject() { - /* - QString LoadFileName = FileName; + QString LoadFileName = lcGetActiveProject()->GetFileName(); if (LoadFileName.isEmpty()) - { - LoadFileName = lcGetActiveProject()->GetFileName(); + LoadFileName = lcGetProfileString(LC_PROFILE_PROJECTS_PATH); - if (LoadFileName.isEmpty()) - LoadFileName = lcGetProfileString(LC_PROFILE_PROJECTS_PATH); + LoadFileName = QFileDialog::getOpenFileName(mHandle, tr("Open Project"), LoadFileName, tr("Supported Files (*.lcd *.ldr *.dat *.mpd);;All Files (*.*)")); - LoadFileName = QFileDialog::getOpenFileName(mHandle, tr("Open Project"), LoadFileName, tr("Supported Files (*.lcd *.ldr *.dat *.mpd);;All Files (*.*)")); - - if (LoadFileName.isEmpty()) - return false; - } + if (LoadFileName.isEmpty()) + return; Project* NewProject = new Project(); if (NewProject->Load(LoadFileName)) { - g_App->SetProject(NewProject); - AddRecentFile(LoadFileName); + int NumModels = NewProject->GetModels().GetSize(); - return true; + lcGetActiveProject()->Merge(NewProject); + + if (NumModels == 1) + QMessageBox::information(mHandle, tr("LeoCAD"), tr("Merged 1 model.")); + else + QMessageBox::information(mHandle, tr("LeoCAD"), tr("Merged %1 models.").arg(NumModels)); + } + else + { + QMessageBox::information(mHandle, tr("LeoCAD"), tr("Error loading '%1'.").arg(LoadFileName)); + delete NewProject; } - - QMessageBox::information(mHandle, tr("LeoCAD"), tr("Error loading '%1'.").arg(LoadFileName)); - delete NewProject; - - return false; - */ - -/* - case LC_FILE_MERGE: - { - QString FileName; - - if (!mFileName.isEmpty()) - FileName = mFileName; - else - FileName = lcGetProfileString(LC_PROFILE_PROJECTS_PATH); - - FileName = QFileDialog::getOpenFileName(gMainWindow->mHandle, tr("Merge Project"), FileName, tr("Supported Files (*.lcd *.ldr *.dat *.mpd);;All Files (*.*)")); - - if (!FileName.isEmpty()) - { - // todo: detect format - lcDiskFile file; - if (file.Open(FileName.toLatin1().constData(), "rb")) // todo: qstring - { - if (file.GetLength() != 0) - { - FileLoad(&file, false, true); - CheckPoint("Merging"); - } - file.Close(); - } - } - } break; -*/ } bool lcMainWindow::SaveProject(const QString& FileName) diff --git a/common/project.cpp b/common/project.cpp index c48d37ae..e0684488 100644 --- a/common/project.cpp +++ b/common/project.cpp @@ -248,12 +248,6 @@ bool Project::Load(const QString& FileName) { Success = FileLoad(&file, false, false); - UpdateBackgroundTexture(); - CalculateStep(); - - if (!bUndo) - ClearSelection(false); - if (!bMerge) gMainWindow->UpdateFocusObject(GetFocusObject()); @@ -320,6 +314,14 @@ bool Project::Save(const QString& FileName) return true; } +void Project::Merge(Project* Other) +{ + for (int ModelIdx = 0; ModelIdx < Other->mModels.GetSize(); ModelIdx++) + mModels.Add(Other->mModels[ModelIdx]); + + mModified = true; +} + /* void Project::LoadDefaults() // todo: Change the interface in SetProject() instead { diff --git a/common/project.h b/common/project.h index 8cb10d87..96ce6adb 100644 --- a/common/project.h +++ b/common/project.h @@ -61,6 +61,7 @@ public: void ShowModelListDialog(); bool Load(const QString& FileName); bool Save(const QString& FileName); + void Merge(Project* Other); protected: bool mModified;