mirror of
https://github.com/leozide/leocad
synced 2024-12-25 21:58:23 +01:00
Use unique_ptr for models.
This commit is contained in:
parent
3378359ae8
commit
b070b0af29
9 changed files with 126 additions and 118 deletions
|
@ -164,8 +164,15 @@ PieceInfo* lcPiecesLibrary::FindPiece(const char* PieceName, Project* CurrentPro
|
||||||
if (PieceIt != mPieces.end())
|
if (PieceIt != mPieces.end())
|
||||||
{
|
{
|
||||||
PieceInfo* Info = PieceIt->second;
|
PieceInfo* Info = PieceIt->second;
|
||||||
|
bool HasModel = false;
|
||||||
|
|
||||||
if ((!CurrentProject || !Info->IsModel() || CurrentProject->GetModels().FindIndex(Info->GetModel()) != -1) && (!ProjectPath.isEmpty() || !Info->IsProject() || Info->IsProjectPiece()))
|
if (lcGetActiveProject())
|
||||||
|
{
|
||||||
|
const std::vector<std::unique_ptr<lcModel>>& Models = lcGetActiveProject()->GetModels();
|
||||||
|
HasModel = std::find_if(Models.begin(), Models.end(), [Model = Info->GetModel()](const std::unique_ptr<lcModel>& CheckModel) { return CheckModel.get() == Model; }) != Models.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!CurrentProject || !Info->IsModel() || HasModel) && (!ProjectPath.isEmpty() || !Info->IsProject() || Info->IsProjectPiece()))
|
||||||
return Info;
|
return Info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1070,7 +1070,7 @@ void lcMainWindow::ModelTabChanged(int Index)
|
||||||
Project* Project = lcGetActiveProject();
|
Project* Project = lcGetActiveProject();
|
||||||
lcModelTabWidget* CurrentTab = (lcModelTabWidget*)mModelTabWidget->widget(Index);
|
lcModelTabWidget* CurrentTab = (lcModelTabWidget*)mModelTabWidget->widget(Index);
|
||||||
|
|
||||||
Project->SetActiveModel(Project->GetModels().FindIndex(CurrentTab ? CurrentTab->GetModel() : nullptr));
|
Project->SetActiveModel(CurrentTab ? CurrentTab->GetModel() : nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcMainWindow::ClipboardChanged()
|
void lcMainWindow::ClipboardChanged()
|
||||||
|
@ -2234,24 +2234,29 @@ void lcMainWindow::UpdateSelectionMode()
|
||||||
|
|
||||||
void lcMainWindow::UpdateModels()
|
void lcMainWindow::UpdateModels()
|
||||||
{
|
{
|
||||||
const lcArray<lcModel*>& Models = lcGetActiveProject()->GetModels();
|
const std::vector<std::unique_ptr<lcModel>>& Models = lcGetActiveProject()->GetModels();
|
||||||
lcModel* CurrentModel = lcGetActiveModel();
|
lcModel* CurrentModel = lcGetActiveModel();
|
||||||
|
|
||||||
for (int ActionIdx = LC_MODEL_FIRST; ActionIdx <= LC_MODEL_LAST; ActionIdx++)
|
for (size_t ActionIndex = LC_MODEL_FIRST; ActionIndex <= LC_MODEL_LAST; ActionIndex++)
|
||||||
{
|
{
|
||||||
QAction* Action = mActions[ActionIdx];
|
QAction* Action = mActions[ActionIndex];
|
||||||
int ModelIdx = ActionIdx - LC_MODEL_FIRST;
|
size_t ModelIndex = ActionIndex - LC_MODEL_FIRST;
|
||||||
|
|
||||||
if (ModelIdx < Models.size())
|
if (ModelIndex < Models.size())
|
||||||
{
|
{
|
||||||
Action->setChecked(CurrentModel == Models[ModelIdx]);
|
Action->setChecked(CurrentModel == Models[ModelIndex].get());
|
||||||
Action->setText(QString::fromLatin1("%1%2 %3").arg(ModelIdx < 9 ? QString("&") : QString(), QString::number(ModelIdx + 1), Models[ModelIdx]->GetProperties().mFileName));
|
Action->setText(QString::fromLatin1("%1%2 %3").arg(ModelIndex < 9 ? QString("&") : QString(), QString::number(ModelIndex + 1), Models[ModelIndex]->GetProperties().mFileName));
|
||||||
Action->setVisible(true);
|
Action->setVisible(true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Action->setVisible(false);
|
Action->setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto HasModel = [&Models](lcModel* Model)
|
||||||
|
{
|
||||||
|
return std::find_if(Models.begin(), Models.end(), [Model](const std::unique_ptr<lcModel>& CheckModel) { return CheckModel.get() == Model; }) != Models.end();
|
||||||
|
};
|
||||||
|
|
||||||
for (int TabIdx = 0; TabIdx < mModelTabWidget->count(); )
|
for (int TabIdx = 0; TabIdx < mModelTabWidget->count(); )
|
||||||
{
|
{
|
||||||
lcModelTabWidget* TabWidget = (lcModelTabWidget*)mModelTabWidget->widget(TabIdx);
|
lcModelTabWidget* TabWidget = (lcModelTabWidget*)mModelTabWidget->widget(TabIdx);
|
||||||
|
@ -2259,7 +2264,7 @@ void lcMainWindow::UpdateModels()
|
||||||
|
|
||||||
if (!Model)
|
if (!Model)
|
||||||
TabIdx++;
|
TabIdx++;
|
||||||
else if (Models.FindIndex(Model) != -1)
|
else if (HasModel(Model))
|
||||||
{
|
{
|
||||||
mModelTabWidget->setTabText(TabIdx, Model->GetProperties().mFileName);
|
mModelTabWidget->setTabText(TabIdx, Model->GetProperties().mFileName);
|
||||||
TabIdx++;
|
TabIdx++;
|
||||||
|
@ -2271,7 +2276,7 @@ void lcMainWindow::UpdateModels()
|
||||||
mPartSelectionWidget->UpdateModels();
|
mPartSelectionWidget->UpdateModels();
|
||||||
|
|
||||||
if (mCurrentPieceInfo && mCurrentPieceInfo->IsModel())
|
if (mCurrentPieceInfo && mCurrentPieceInfo->IsModel())
|
||||||
if (Models.FindIndex(mCurrentPieceInfo->GetModel()) == -1)
|
if (!HasModel(mCurrentPieceInfo->GetModel()))
|
||||||
SetCurrentPieceInfo(nullptr);
|
SetCurrentPieceInfo(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2395,14 +2400,14 @@ void lcMainWindow::MergeProject()
|
||||||
|
|
||||||
if (NewProject->Load(LoadFileName, true))
|
if (NewProject->Load(LoadFileName, true))
|
||||||
{
|
{
|
||||||
int NumModels = NewProject->GetModels().size();
|
size_t ModelCount = NewProject->GetModels().size();
|
||||||
|
|
||||||
lcGetActiveProject()->Merge(NewProject);
|
lcGetActiveProject()->Merge(NewProject);
|
||||||
|
|
||||||
if (NumModels == 1)
|
if (ModelCount == 1)
|
||||||
QMessageBox::information(this, tr("LeoCAD"), tr("Merged 1 submodel."));
|
QMessageBox::information(this, tr("LeoCAD"), tr("Merged 1 submodel."));
|
||||||
else
|
else
|
||||||
QMessageBox::information(this, tr("LeoCAD"), tr("Merged %1 submodels.").arg(NumModels));
|
QMessageBox::information(this, tr("LeoCAD"), tr("Merged %1 submodels.").arg(ModelCount));
|
||||||
|
|
||||||
UpdateModels();
|
UpdateModels();
|
||||||
}
|
}
|
||||||
|
@ -2522,7 +2527,7 @@ bool lcMainWindow::SetModelFromFocus()
|
||||||
if (Model)
|
if (Model)
|
||||||
{
|
{
|
||||||
Project* Project = lcGetActiveProject();
|
Project* Project = lcGetActiveProject();
|
||||||
Project->SetActiveModel(Project->GetModels().FindIndex(Model));
|
Project->SetActiveModel(Model);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2539,7 +2544,7 @@ void lcMainWindow::SetModelFromSelection()
|
||||||
if (Model)
|
if (Model)
|
||||||
{
|
{
|
||||||
Project* Project = lcGetActiveProject();
|
Project* Project = lcGetActiveProject();
|
||||||
Project->SetActiveModel(Project->GetModels().FindIndex(Model));
|
Project->SetActiveModel(Model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3250,15 +3250,15 @@ lcModel* lcModel::GetFirstSelectedSubmodel() const
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcModel::GetSubModels(lcArray<lcModel*>& SubModels) const
|
void lcModel::GetSubModels(std::set<lcModel*>& SubModels) const
|
||||||
{
|
{
|
||||||
for (const lcPiece* Piece : mPieces)
|
for (const lcPiece* Piece : mPieces)
|
||||||
{
|
{
|
||||||
if (Piece->mPieceInfo->IsModel())
|
if (Piece->mPieceInfo->IsModel())
|
||||||
{
|
{
|
||||||
lcModel* SubModel = Piece->mPieceInfo->GetModel();
|
lcModel* SubModel = Piece->mPieceInfo->GetModel();
|
||||||
if (SubModels.FindIndex(SubModel) == -1)
|
|
||||||
SubModels.emplace_back(SubModel);
|
SubModels.insert(SubModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -281,7 +281,7 @@ public:
|
||||||
bool AnyPiecesSelected() const;
|
bool AnyPiecesSelected() const;
|
||||||
bool AnyObjectsSelected() const;
|
bool AnyObjectsSelected() const;
|
||||||
lcModel* GetFirstSelectedSubmodel() const;
|
lcModel* GetFirstSelectedSubmodel() const;
|
||||||
void GetSubModels(lcArray<lcModel*>& SubModels) const;
|
void GetSubModels(std::set<lcModel*>& SubModels) const;
|
||||||
bool GetMoveRotateTransform(lcVector3& Center, lcMatrix33& RelativeRotation) const;
|
bool GetMoveRotateTransform(lcVector3& Center, lcMatrix33& RelativeRotation) const;
|
||||||
bool CanRotateSelection() const;
|
bool CanRotateSelection() const;
|
||||||
bool GetPieceFocusOrSelectionCenter(lcVector3& Center) const;
|
bool GetPieceFocusOrSelectionCenter(lcVector3& Center) const;
|
||||||
|
|
|
@ -11,21 +11,28 @@ enum class lcModelListRole
|
||||||
DuplicateModel
|
DuplicateModel
|
||||||
};
|
};
|
||||||
|
|
||||||
lcModelListDialog::lcModelListDialog(QWidget* Parent, const lcArray<lcModel*> Models)
|
lcModelListDialog::lcModelListDialog(QWidget* Parent, const std::vector<std::unique_ptr<lcModel>>& Models)
|
||||||
: QDialog(Parent), ui(new Ui::lcModelListDialog)
|
: QDialog(Parent), ui(new Ui::lcModelListDialog)
|
||||||
{
|
{
|
||||||
mActiveModelItem = nullptr;
|
mActiveModelItem = nullptr;
|
||||||
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
for (const lcModel* Model : Models)
|
lcModel* ActiveModel = lcGetActiveProject()->GetActiveModel();
|
||||||
|
int ActiveModelIndex = -1;
|
||||||
|
|
||||||
|
for (const std::unique_ptr<lcModel>& Model : Models)
|
||||||
{
|
{
|
||||||
QListWidgetItem* Item = new QListWidgetItem(Model->GetProperties().mFileName);
|
QListWidgetItem* Item = new QListWidgetItem(Model->GetProperties().mFileName);
|
||||||
Item->setData(static_cast<int>(lcModelListRole::ExistingModel), QVariant::fromValue<uintptr_t>((uintptr_t)Model));
|
Item->setData(static_cast<int>(lcModelListRole::ExistingModel), QVariant::fromValue<uintptr_t>((uintptr_t)Model.get()));
|
||||||
ui->ModelList->addItem(Item);
|
ui->ModelList->addItem(Item);
|
||||||
|
|
||||||
|
if (Model.get() == ActiveModel )
|
||||||
|
ActiveModelIndex = ui->ModelList->count() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->ModelList->setCurrentRow(lcGetActiveProject()->GetActiveModelIndex());
|
if (ActiveModelIndex != -1)
|
||||||
|
ui->ModelList->setCurrentRow(ActiveModelIndex);
|
||||||
|
|
||||||
QSettings Settings;
|
QSettings Settings;
|
||||||
ui->SetActiveModel->setChecked(Settings.value("Settings/ModelListSetActive", true).toBool());
|
ui->SetActiveModel->setChecked(Settings.value("Settings/ModelListSetActive", true).toBool());
|
||||||
|
|
|
@ -19,7 +19,7 @@ class lcModelListDialog : public QDialog
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
lcModelListDialog(QWidget* Parent, const lcArray<lcModel*> Models);
|
lcModelListDialog(QWidget* Parent, const std::vector<std::unique_ptr<lcModel>>& Models);
|
||||||
~lcModelListDialog();
|
~lcModelListDialog();
|
||||||
|
|
||||||
int GetActiveModelIndex() const;
|
int GetActiveModelIndex() const;
|
||||||
|
|
|
@ -176,16 +176,12 @@ void lcPartSelectionListModel::SetModelsCategory()
|
||||||
|
|
||||||
mParts.clear();
|
mParts.clear();
|
||||||
|
|
||||||
const lcArray<lcModel*>& Models = lcGetActiveProject()->GetModels();
|
const std::vector<std::unique_ptr<lcModel>>& Models = lcGetActiveProject()->GetModels();
|
||||||
lcModel* ActiveModel = gMainWindow->GetActiveModel();
|
lcModel* ActiveModel = gMainWindow->GetActiveModel();
|
||||||
|
|
||||||
for (int ModelIdx = 0; ModelIdx < Models.size(); ModelIdx++)
|
for (const std::unique_ptr<lcModel>& Model : Models)
|
||||||
{
|
|
||||||
lcModel* Model = Models[ModelIdx];
|
|
||||||
|
|
||||||
if (!Model->IncludesModel(ActiveModel))
|
if (!Model->IncludesModel(ActiveModel))
|
||||||
mParts.emplace_back(std::pair<PieceInfo*, QPixmap>(Model->GetPieceInfo(), QPixmap()));
|
mParts.emplace_back(std::pair<PieceInfo*, QPixmap>(Model->GetPieceInfo(), QPixmap()));
|
||||||
}
|
|
||||||
|
|
||||||
auto lcPartSortFunc = [](const std::pair<PieceInfo*, QPixmap>& a, const std::pair<PieceInfo*, QPixmap>& b)
|
auto lcPartSortFunc = [](const std::pair<PieceInfo*, QPixmap>& a, const std::pair<PieceInfo*, QPixmap>& b)
|
||||||
{
|
{
|
||||||
|
|
|
@ -78,14 +78,13 @@ Project::Project(bool IsPreview)
|
||||||
|
|
||||||
Project::~Project()
|
Project::~Project()
|
||||||
{
|
{
|
||||||
mModels.DeleteAll();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lcModel* Project::GetModel(const QString& FileName) const
|
lcModel* Project::GetModel(const QString& FileName) const
|
||||||
{
|
{
|
||||||
for (lcModel* Model : mModels)
|
for (const std::unique_ptr<lcModel>& Model : mModels)
|
||||||
if (Model->GetProperties().mFileName == FileName)
|
if (Model->GetProperties().mFileName == FileName)
|
||||||
return Model;
|
return Model.get();
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -95,8 +94,8 @@ bool Project::IsModified() const
|
||||||
if (mModified)
|
if (mModified)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
for (int ModelIdx = 0; ModelIdx < mModels.size(); ModelIdx++)
|
for (const std::unique_ptr<lcModel>& Model : mModels)
|
||||||
if (mModels[ModelIdx]->IsModified())
|
if (Model->IsModified())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -135,21 +134,21 @@ QString Project::GetImageFileName(bool AllowCurrentFolder) const
|
||||||
return QDir::toNativeSeparators(FileName) + lcGetProfileString(LC_PROFILE_IMAGE_EXTENSION);
|
return QDir::toNativeSeparators(FileName) + lcGetProfileString(LC_PROFILE_IMAGE_EXTENSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::SetActiveModel(int ModelIndex)
|
void Project::SetActiveModel(lcModel* ActiveModel)
|
||||||
{
|
{
|
||||||
if (ModelIndex < 0 || ModelIndex >= mModels.size())
|
if (!ActiveModel)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (int ModelIdx = 0; ModelIdx < mModels.size(); ModelIdx++)
|
for (const std::unique_ptr<lcModel> &Model : mModels)
|
||||||
mModels[ModelIdx]->SetActive(ModelIdx == ModelIndex);
|
Model->SetActive(Model.get() == ActiveModel);
|
||||||
|
|
||||||
std::vector<lcModel*> UpdatedModels;
|
std::vector<lcModel*> UpdatedModels;
|
||||||
UpdatedModels.reserve(mModels.size());
|
UpdatedModels.reserve(mModels.size());
|
||||||
|
|
||||||
for (int ModelIdx = 0; ModelIdx < mModels.size(); ModelIdx++)
|
for (const std::unique_ptr<lcModel> &Model : mModels)
|
||||||
mModels[ModelIdx]->UpdatePieceInfo(UpdatedModels);
|
Model->UpdatePieceInfo(UpdatedModels);
|
||||||
|
|
||||||
mActiveModel = mModels[ModelIndex];
|
mActiveModel = ActiveModel;
|
||||||
|
|
||||||
if (!mIsPreview && gMainWindow)
|
if (!mIsPreview && gMainWindow)
|
||||||
{
|
{
|
||||||
|
@ -158,13 +157,21 @@ void Project::SetActiveModel(int ModelIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Project::SetActiveModel(int ModelIndex)
|
||||||
|
{
|
||||||
|
if (ModelIndex < 0 || ModelIndex >= static_cast<int>(mModels.size()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SetActiveModel(mModels[ModelIndex].get());
|
||||||
|
}
|
||||||
|
|
||||||
void Project::SetActiveModel(const QString& FileName)
|
void Project::SetActiveModel(const QString& FileName)
|
||||||
{
|
{
|
||||||
for (int ModelIdx = 0; ModelIdx < mModels.size(); ModelIdx++)
|
for (const std::unique_ptr<lcModel>& Model : mModels)
|
||||||
{
|
{
|
||||||
if (FileName.compare(mModels[ModelIdx]->GetFileName(), Qt::CaseInsensitive) == 0)
|
if (FileName.compare(Model->GetFileName(), Qt::CaseInsensitive) == 0)
|
||||||
{
|
{
|
||||||
SetActiveModel(ModelIdx);
|
SetActiveModel(Model.get());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -241,8 +248,8 @@ lcModel* Project::CreateNewModel(bool ShowModel)
|
||||||
{
|
{
|
||||||
QStringList ModelNames;
|
QStringList ModelNames;
|
||||||
|
|
||||||
for (int ModelIdx = 0; ModelIdx < mModels.size(); ModelIdx++)
|
for (const std::unique_ptr<lcModel> &Model : mModels)
|
||||||
ModelNames.append(mModels[ModelIdx]->GetProperties().mFileName);
|
ModelNames.append(Model->GetProperties().mFileName);
|
||||||
|
|
||||||
QString Name = GetNewModelName(gMainWindow, tr("New Submodel"), QString(), ModelNames);
|
QString Name = GetNewModelName(gMainWindow, tr("New Submodel"), QString(), ModelNames);
|
||||||
|
|
||||||
|
@ -257,7 +264,7 @@ lcModel* Project::CreateNewModel(bool ShowModel)
|
||||||
|
|
||||||
if (ShowModel)
|
if (ShowModel)
|
||||||
{
|
{
|
||||||
SetActiveModel(mModels.size() - 1);
|
SetActiveModel(mModels.back().get());
|
||||||
|
|
||||||
lcView* ActiveView = gMainWindow ? gMainWindow->GetActiveView() : nullptr;
|
lcView* ActiveView = gMainWindow ? gMainWindow->GetActiveView() : nullptr;
|
||||||
if (ActiveView)
|
if (ActiveView)
|
||||||
|
@ -266,7 +273,7 @@ lcModel* Project::CreateNewModel(bool ShowModel)
|
||||||
gMainWindow->UpdateTitle();
|
gMainWindow->UpdateTitle();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
SetActiveModel(mModels.FindIndex(mActiveModel));
|
SetActiveModel(mActiveModel);
|
||||||
|
|
||||||
return Model;
|
return Model;
|
||||||
}
|
}
|
||||||
|
@ -278,7 +285,7 @@ void Project::ShowModelListDialog()
|
||||||
if (Dialog.exec() != QDialog::Accepted)
|
if (Dialog.exec() != QDialog::Accepted)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lcArray<lcModel*> NewModels;
|
std::vector<std::unique_ptr<lcModel>> NewModels;
|
||||||
std::vector<lcModelListDialogEntry> Results = Dialog.GetResults();
|
std::vector<lcModelListDialogEntry> Results = Dialog.GetResults();
|
||||||
|
|
||||||
for (const lcModelListDialogEntry& Entry : Results)
|
for (const lcModelListDialogEntry& Entry : Results)
|
||||||
|
@ -321,7 +328,7 @@ void Project::ShowModelListDialog()
|
||||||
Model->SetFileName(Entry.Name);
|
Model->SetFileName(Entry.Name);
|
||||||
lcGetPiecesLibrary()->RenamePiece(Model->GetPieceInfo(), Entry.Name.toLatin1().constData());
|
lcGetPiecesLibrary()->RenamePiece(Model->GetPieceInfo(), Entry.Name.toLatin1().constData());
|
||||||
|
|
||||||
for (lcModel* CheckModel : mModels)
|
for (const std::unique_ptr<lcModel> &CheckModel : mModels)
|
||||||
CheckModel->RenamePiece(Model->GetPieceInfo());
|
CheckModel->RenamePiece(Model->GetPieceInfo());
|
||||||
|
|
||||||
mModified = true;
|
mModified = true;
|
||||||
|
@ -330,18 +337,15 @@ void Project::ShowModelListDialog()
|
||||||
NewModels.emplace_back(Model);
|
NewModels.emplace_back(Model);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int ModelIdx = 0; ModelIdx < mModels.size(); ModelIdx++)
|
for (std::unique_ptr<lcModel>& Model : mModels)
|
||||||
{
|
{
|
||||||
lcModel* Model = mModels[ModelIdx];
|
if (std::find(NewModels.begin(), NewModels.end(), Model) != NewModels.end())
|
||||||
|
Model.release();
|
||||||
if (NewModels.FindIndex(Model) == -1)
|
else
|
||||||
{
|
|
||||||
delete Model;
|
|
||||||
mModified = true;
|
mModified = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
mModels = NewModels;
|
mModels = std::move(NewModels);
|
||||||
|
|
||||||
gMainWindow->UpdateTitle();
|
gMainWindow->UpdateTitle();
|
||||||
gMainWindow->UpdateModels();
|
gMainWindow->UpdateModels();
|
||||||
|
@ -380,7 +384,7 @@ bool Project::Load(const QString& FileName, bool ShowErrors)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mModels.DeleteAll();
|
mModels.clear();
|
||||||
SetFileName(FileName);
|
SetFileName(FileName);
|
||||||
QFileInfo FileInfo(FileName);
|
QFileInfo FileInfo(FileName);
|
||||||
QString Extension = FileInfo.suffix().toLower();
|
QString Extension = FileInfo.suffix().toLower();
|
||||||
|
@ -461,7 +465,7 @@ bool Project::Load(const QString& FileName, bool ShowErrors)
|
||||||
|
|
||||||
if (mModels.size() == 1)
|
if (mModels.size() == 1)
|
||||||
{
|
{
|
||||||
lcModel* Model = mModels[0];
|
lcModel* Model = mModels.front().get();
|
||||||
|
|
||||||
if (Model->GetProperties().mFileName.isEmpty())
|
if (Model->GetProperties().mFileName.isEmpty())
|
||||||
{
|
{
|
||||||
|
@ -473,7 +477,7 @@ bool Project::Load(const QString& FileName, bool ShowErrors)
|
||||||
std::vector<lcModel*> UpdatedModels;
|
std::vector<lcModel*> UpdatedModels;
|
||||||
UpdatedModels.reserve(mModels.size());
|
UpdatedModels.reserve(mModels.size());
|
||||||
|
|
||||||
for (lcModel* Model : mModels)
|
for (const std::unique_ptr<lcModel>& Model : mModels)
|
||||||
{
|
{
|
||||||
Model->UpdateMesh();
|
Model->UpdateMesh();
|
||||||
Model->UpdatePieceInfo(UpdatedModels);
|
Model->UpdatePieceInfo(UpdatedModels);
|
||||||
|
@ -513,7 +517,7 @@ bool Project::Save(QTextStream& Stream)
|
||||||
{
|
{
|
||||||
bool MPD = mModels.size() > 1;
|
bool MPD = mModels.size() > 1;
|
||||||
|
|
||||||
for (lcModel* Model : mModels)
|
for (const std::unique_ptr<lcModel>& Model : mModels)
|
||||||
{
|
{
|
||||||
if (MPD)
|
if (MPD)
|
||||||
Stream << QLatin1String("0 FILE ") << Model->GetProperties().mFileName << QLatin1String("\r\n");
|
Stream << QLatin1String("0 FILE ") << Model->GetProperties().mFileName << QLatin1String("\r\n");
|
||||||
|
@ -530,7 +534,7 @@ bool Project::Save(QTextStream& Stream)
|
||||||
|
|
||||||
void Project::Merge(Project* Other)
|
void Project::Merge(Project* Other)
|
||||||
{
|
{
|
||||||
for (lcModel* Model : Other->mModels)
|
for (std::unique_ptr<lcModel>& Model : Other->mModels)
|
||||||
{
|
{
|
||||||
QString FileName = Model->GetProperties().mFileName;
|
QString FileName = Model->GetProperties().mFileName;
|
||||||
|
|
||||||
|
@ -538,9 +542,9 @@ void Project::Merge(Project* Other)
|
||||||
{
|
{
|
||||||
bool Duplicate = false;
|
bool Duplicate = false;
|
||||||
|
|
||||||
for (int SearchIdx = 0; SearchIdx < mModels.size(); SearchIdx++)
|
for (const std::unique_ptr<lcModel>& ExistingModel : mModels)
|
||||||
{
|
{
|
||||||
if (mModels[SearchIdx]->GetProperties().mFileName == FileName)
|
if (ExistingModel->GetProperties().mFileName == FileName)
|
||||||
{
|
{
|
||||||
Duplicate = true;
|
Duplicate = true;
|
||||||
break;
|
break;
|
||||||
|
@ -554,10 +558,10 @@ void Project::Merge(Project* Other)
|
||||||
Model->SetFileName(FileName);
|
Model->SetFileName(FileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
mModels.emplace_back(Model);
|
mModels.emplace_back(std::move(Model));
|
||||||
}
|
}
|
||||||
|
|
||||||
Other->mModels.RemoveAll();
|
Other->mModels.clear();
|
||||||
mModified = true;
|
mModified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -572,29 +576,25 @@ bool Project::ImportLDD(const QString& FileName)
|
||||||
if (!ZipFile.ExtractFile("IMAGE100.LXFML", XMLFile))
|
if (!ZipFile.ExtractFile("IMAGE100.LXFML", XMLFile))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
mModels.DeleteAll();
|
|
||||||
QString ModelName = QFileInfo(FileName).completeBaseName();
|
QString ModelName = QFileInfo(FileName).completeBaseName();
|
||||||
lcModel* Model = new lcModel(ModelName, this, false);
|
std::unique_ptr<lcModel> NewModel(new lcModel(ModelName, this, false));
|
||||||
|
|
||||||
if (Model->LoadLDD(QString::fromUtf8((const char*)XMLFile.mBuffer)))
|
if (!NewModel->LoadLDD(QString::fromUtf8((const char*)XMLFile.mBuffer)))
|
||||||
{
|
|
||||||
mModels.emplace_back(Model);
|
|
||||||
Model->SetSaved();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
delete Model;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
for (int ModelIdx = 0; ModelIdx < mModels.size(); ModelIdx++)
|
NewModel->SetSaved();
|
||||||
mModels[ModelIdx]->CreatePieceInfo(this);
|
|
||||||
|
mModels.clear();
|
||||||
|
mModels.emplace_back(std::move(NewModel));
|
||||||
|
|
||||||
|
for (const std::unique_ptr<lcModel>& Model : mModels)
|
||||||
|
Model->CreatePieceInfo(this);
|
||||||
|
|
||||||
std::vector<lcModel*> UpdatedModels;
|
std::vector<lcModel*> UpdatedModels;
|
||||||
UpdatedModels.reserve(mModels.size());
|
UpdatedModels.reserve(mModels.size());
|
||||||
|
|
||||||
for (int ModelIdx = 0; ModelIdx < mModels.size(); ModelIdx++)
|
for (const std::unique_ptr<lcModel>& Model : mModels)
|
||||||
mModels[ModelIdx]->UpdatePieceInfo(UpdatedModels);
|
Model->UpdatePieceInfo(UpdatedModels);
|
||||||
|
|
||||||
mModified = false;
|
mModified = false;
|
||||||
|
|
||||||
|
@ -606,30 +606,25 @@ bool Project::ImportInventory(const QByteArray& Inventory, const QString& Name,
|
||||||
if (Inventory.isEmpty())
|
if (Inventory.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
mModels.DeleteAll();
|
std::unique_ptr<lcModel> NewModel(new lcModel(Name, this, false));
|
||||||
lcModel* Model = new lcModel(Name, this, false);
|
|
||||||
|
|
||||||
if (Model->LoadInventory(Inventory))
|
if (!NewModel->LoadInventory(Inventory))
|
||||||
{
|
|
||||||
mModels.emplace_back(Model);
|
|
||||||
Model->SetSaved();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
delete Model;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
Model->SetDescription(Description);
|
NewModel->SetSaved();
|
||||||
|
NewModel->SetDescription(Description);
|
||||||
|
|
||||||
for (int ModelIdx = 0; ModelIdx < mModels.size(); ModelIdx++)
|
mModels.clear();
|
||||||
mModels[ModelIdx]->CreatePieceInfo(this);
|
mModels.emplace_back(std::move(NewModel));
|
||||||
|
|
||||||
|
for (const std::unique_ptr<lcModel>& Model : mModels)
|
||||||
|
Model->CreatePieceInfo(this);
|
||||||
|
|
||||||
std::vector<lcModel*> UpdatedModels;
|
std::vector<lcModel*> UpdatedModels;
|
||||||
UpdatedModels.reserve(mModels.size());
|
UpdatedModels.reserve(mModels.size());
|
||||||
|
|
||||||
for (int ModelIdx = 0; ModelIdx < mModels.size(); ModelIdx++)
|
for (const std::unique_ptr<lcModel>& Model : mModels)
|
||||||
mModels[ModelIdx]->UpdatePieceInfo(UpdatedModels);
|
Model->UpdatePieceInfo(UpdatedModels);
|
||||||
|
|
||||||
mModified = false;
|
mModified = false;
|
||||||
|
|
||||||
|
@ -643,12 +638,12 @@ std::vector<lcModelPartsEntry> Project::GetModelParts()
|
||||||
if (mModels.empty())
|
if (mModels.empty())
|
||||||
return ModelParts;
|
return ModelParts;
|
||||||
|
|
||||||
for (lcModel* Model : mModels)
|
for (const std::unique_ptr<lcModel>& Model : mModels)
|
||||||
Model->CalculateStep(LC_STEP_MAX);
|
Model->CalculateStep(LC_STEP_MAX);
|
||||||
|
|
||||||
mModels[0]->GetModelParts(lcMatrix44Identity(), gDefaultColor, ModelParts);
|
mModels[0]->GetModelParts(lcMatrix44Identity(), gDefaultColor, ModelParts);
|
||||||
|
|
||||||
SetActiveModel(mModels.FindIndex(mActiveModel));
|
SetActiveModel(mActiveModel);
|
||||||
|
|
||||||
return ModelParts;
|
return ModelParts;
|
||||||
}
|
}
|
||||||
|
@ -671,7 +666,7 @@ bool Project::ExportCurrentStep(const QString& FileName)
|
||||||
{
|
{
|
||||||
Models.append(ModelName);
|
Models.append(ModelName);
|
||||||
|
|
||||||
for (lcModel* Model : mModels)
|
for (const std::unique_ptr<lcModel>& Model : mModels)
|
||||||
{
|
{
|
||||||
if (Model->GetProperties().mFileName == ModelName)
|
if (Model->GetProperties().mFileName == ModelName)
|
||||||
{
|
{
|
||||||
|
@ -724,7 +719,7 @@ bool Project::ExportCurrentStep(const QString& FileName)
|
||||||
|
|
||||||
QTextStream Stream(&File);
|
QTextStream Stream(&File);
|
||||||
|
|
||||||
for (lcModel* Model : mModels)
|
for (const std::unique_ptr<lcModel>& Model : mModels)
|
||||||
{
|
{
|
||||||
if (!Models.contains(Model->GetProperties().mFileName))
|
if (!Models.contains(Model->GetProperties().mFileName))
|
||||||
continue;
|
continue;
|
||||||
|
@ -1591,17 +1586,20 @@ void Project::ExportHTML(const lcHTMLExportOptions& Options)
|
||||||
QDir Dir(Options.PathName);
|
QDir Dir(Options.PathName);
|
||||||
Dir.mkpath(QLatin1String("."));
|
Dir.mkpath(QLatin1String("."));
|
||||||
|
|
||||||
lcArray<lcModel*> Models;
|
std::set<lcModel*> Models;
|
||||||
|
|
||||||
if (Options.CurrentOnly)
|
if (Options.CurrentOnly)
|
||||||
Models.emplace_back(mActiveModel);
|
Models.insert(mActiveModel);
|
||||||
else if (Options.SubModels)
|
else if (Options.SubModels)
|
||||||
{
|
{
|
||||||
Models.emplace_back(mActiveModel);
|
Models.insert(mActiveModel);
|
||||||
mActiveModel->GetSubModels(Models);
|
mActiveModel->GetSubModels(Models);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Models = mModels;
|
{
|
||||||
|
for (const std::unique_ptr<lcModel>& Model : mModels)
|
||||||
|
Models.insert(Model.get());
|
||||||
|
}
|
||||||
|
|
||||||
QString ProjectTitle = GetTitle();
|
QString ProjectTitle = GetTitle();
|
||||||
|
|
||||||
|
@ -1772,9 +1770,8 @@ void Project::ExportHTML(const lcHTMLExportOptions& Options)
|
||||||
|
|
||||||
Stream << QString::fromLatin1("<HTML>\r\n<HEAD>\r\n<TITLE>Instructions for %1</TITLE>\r\n</HEAD>\r\n<BR>\r\n<CENTER>\r\n").arg(ProjectTitle);
|
Stream << QString::fromLatin1("<HTML>\r\n<HEAD>\r\n<TITLE>Instructions for %1</TITLE>\r\n</HEAD>\r\n<BR>\r\n<CENTER>\r\n").arg(ProjectTitle);
|
||||||
|
|
||||||
for (int ModelIdx = 0; ModelIdx < Models.size(); ModelIdx++)
|
for (const lcModel* Model : Models)
|
||||||
{
|
{
|
||||||
lcModel* Model = Models[ModelIdx];
|
|
||||||
BaseName = ProjectTitle.left(ProjectTitle.length() - QFileInfo(ProjectTitle).suffix().length() - 1) + '-' + Model->GetProperties().mFileName;
|
BaseName = ProjectTitle.left(ProjectTitle.length() - QFileInfo(ProjectTitle).suffix().length() - 1) + '-' + Model->GetProperties().mFileName;
|
||||||
BaseName.replace('#', '_');
|
BaseName.replace('#', '_');
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
Project& operator=(const Project&) = delete;
|
Project& operator=(const Project&) = delete;
|
||||||
Project& operator=(Project&&) = delete;
|
Project& operator=(Project&&) = delete;
|
||||||
|
|
||||||
const lcArray<lcModel*>& GetModels() const
|
const std::vector<std::unique_ptr<lcModel>>& GetModels() const
|
||||||
{
|
{
|
||||||
return mModels;
|
return mModels;
|
||||||
}
|
}
|
||||||
|
@ -51,14 +51,9 @@ public:
|
||||||
return mActiveModel;
|
return mActiveModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetActiveModelIndex() const
|
|
||||||
{
|
|
||||||
return mModels.FindIndex(mActiveModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
lcModel* GetMainModel() const
|
lcModel* GetMainModel() const
|
||||||
{
|
{
|
||||||
return !mModels.empty() ? mModels[0] : nullptr;
|
return !mModels.empty() ? mModels[0].get() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsModified() const;
|
bool IsModified() const;
|
||||||
|
@ -74,6 +69,7 @@ public:
|
||||||
|
|
||||||
lcInstructions* GetInstructions();
|
lcInstructions* GetInstructions();
|
||||||
|
|
||||||
|
void SetActiveModel(lcModel* Model);
|
||||||
void SetActiveModel(int ModelIndex);
|
void SetActiveModel(int ModelIndex);
|
||||||
void SetActiveModel(const QString& FileName);
|
void SetActiveModel(const QString& FileName);
|
||||||
|
|
||||||
|
@ -112,7 +108,7 @@ protected:
|
||||||
QString mFileName;
|
QString mFileName;
|
||||||
QFileSystemWatcher mFileWatcher;
|
QFileSystemWatcher mFileWatcher;
|
||||||
|
|
||||||
lcArray<lcModel*> mModels;
|
std::vector<std::unique_ptr<lcModel>> mModels;
|
||||||
lcModel* mActiveModel;
|
lcModel* mActiveModel;
|
||||||
std::unique_ptr<lcInstructions> mInstructions;
|
std::unique_ptr<lcInstructions> mInstructions;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue