mirror of
https://github.com/leozide/leocad
synced 2025-01-17 18:11:42 +01:00
Fixed timeline update crash.
This commit is contained in:
parent
9446e2cde7
commit
c4b15d05a9
6 changed files with 144 additions and 59 deletions
|
@ -72,9 +72,8 @@ void lcApplication::SetProject(Project* Project)
|
||||||
View->SetModel(lcGetActiveModel());
|
View->SetModel(lcGetActiveModel());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Project->SetActiveModel(0);
|
||||||
lcGetPiecesLibrary()->RemoveTemporaryPieces();
|
lcGetPiecesLibrary()->RemoveTemporaryPieces();
|
||||||
lcGetActiveModel()->UpdateInterface();
|
|
||||||
gMainWindow->UpdateAllViews();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcApplication::SetClipboard(const QByteArray& Clipboard)
|
void lcApplication::SetClipboard(const QByteArray& Clipboard)
|
||||||
|
|
|
@ -1658,8 +1658,6 @@ bool lcMainWindow::OpenProject(const QString& FileName)
|
||||||
|
|
||||||
if (NewProject->Load(LoadFileName))
|
if (NewProject->Load(LoadFileName))
|
||||||
{
|
{
|
||||||
NewProject->SetActiveModel(0);
|
|
||||||
|
|
||||||
g_App->SetProject(NewProject);
|
g_App->SetProject(NewProject);
|
||||||
AddRecentFile(LoadFileName);
|
AddRecentFile(LoadFileName);
|
||||||
|
|
||||||
|
|
|
@ -510,7 +510,7 @@ void lcModel::LoadLDraw(QIODevice& Device, Project* Project)
|
||||||
Piece->SetPieceInfo(Info);
|
Piece->SetPieceInfo(Info);
|
||||||
Piece->Initialize(Transform, CurrentStep);
|
Piece->Initialize(Transform, CurrentStep);
|
||||||
Piece->SetColorCode(ColorCode);
|
Piece->SetColorCode(ColorCode);
|
||||||
mPieces.Add(Piece);
|
AddPiece(Piece);
|
||||||
Piece = NULL;
|
Piece = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -587,7 +587,7 @@ bool lcModel::LoadBinary(lcFile* file)
|
||||||
{
|
{
|
||||||
lcPiece* pPiece = new lcPiece(NULL);
|
lcPiece* pPiece = new lcPiece(NULL);
|
||||||
pPiece->FileLoad(*file);
|
pPiece->FileLoad(*file);
|
||||||
mPieces.Add(pPiece);
|
AddPiece(pPiece);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -611,7 +611,7 @@ bool lcModel::LoadBinary(lcFile* file)
|
||||||
|
|
||||||
pPiece->Initialize(WorldMatrix, step);
|
pPiece->Initialize(WorldMatrix, step);
|
||||||
pPiece->SetColorCode(lcGetColorCodeFromOriginalColor(color));
|
pPiece->SetColorCode(lcGetColorCodeFromOriginalColor(color));
|
||||||
mPieces.Add(pPiece);
|
AddPiece(pPiece);
|
||||||
|
|
||||||
// pPiece->SetGroup((lcGroup*)group);
|
// pPiece->SetGroup((lcGroup*)group);
|
||||||
}
|
}
|
||||||
|
@ -816,7 +816,7 @@ void lcModel::Merge(lcModel* Other)
|
||||||
for (int PieceIdx = 0; PieceIdx < Other->mPieces.GetSize(); PieceIdx++)
|
for (int PieceIdx = 0; PieceIdx < Other->mPieces.GetSize(); PieceIdx++)
|
||||||
{
|
{
|
||||||
lcPiece* Piece = Other->mPieces[PieceIdx];
|
lcPiece* Piece = Other->mPieces[PieceIdx];
|
||||||
mPieces.Add(Piece);
|
AddPiece(Piece);
|
||||||
}
|
}
|
||||||
|
|
||||||
Other->mPieces.RemoveAll();
|
Other->mPieces.RemoveAll();
|
||||||
|
@ -1834,12 +1834,26 @@ void lcModel::AddPiece()
|
||||||
lcPiece* Piece = new lcPiece(CurPiece);
|
lcPiece* Piece = new lcPiece(CurPiece);
|
||||||
Piece->Initialize(WorldMatrix, mCurrentStep);
|
Piece->Initialize(WorldMatrix, mCurrentStep);
|
||||||
Piece->SetColorIndex(gMainWindow->mColorIndex);
|
Piece->SetColorIndex(gMainWindow->mColorIndex);
|
||||||
mPieces.Add(Piece);
|
AddPiece(Piece);
|
||||||
ClearSelectionAndSetFocus(Piece, LC_PIECE_SECTION_POSITION);
|
ClearSelectionAndSetFocus(Piece, LC_PIECE_SECTION_POSITION);
|
||||||
|
|
||||||
SaveCheckpoint("Adding Piece");
|
SaveCheckpoint("Adding Piece");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lcModel::AddPiece(lcPiece* Piece)
|
||||||
|
{
|
||||||
|
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
|
||||||
|
{
|
||||||
|
if (mPieces[PieceIdx]->GetStepShow() > Piece->GetStepShow())
|
||||||
|
{
|
||||||
|
mPieces.InsertAt(PieceIdx, Piece);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mPieces.Add(Piece);
|
||||||
|
}
|
||||||
|
|
||||||
void lcModel::DeleteAllCameras()
|
void lcModel::DeleteAllCameras()
|
||||||
{
|
{
|
||||||
if (mCameras.IsEmpty())
|
if (mCameras.IsEmpty())
|
||||||
|
@ -1866,9 +1880,9 @@ void lcModel::DeleteSelectedObjects()
|
||||||
|
|
||||||
void lcModel::ShowSelectedPiecesEarlier()
|
void lcModel::ShowSelectedPiecesEarlier()
|
||||||
{
|
{
|
||||||
bool Modified = false;
|
lcArray<lcPiece*> MovedPieces;
|
||||||
|
|
||||||
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
|
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); )
|
||||||
{
|
{
|
||||||
lcPiece* Piece = mPieces[PieceIdx];
|
lcPiece* Piece = mPieces[PieceIdx];
|
||||||
|
|
||||||
|
@ -1879,25 +1893,34 @@ void lcModel::ShowSelectedPiecesEarlier()
|
||||||
if (Step > 1)
|
if (Step > 1)
|
||||||
{
|
{
|
||||||
Step--;
|
Step--;
|
||||||
Modified = true;
|
|
||||||
Piece->SetStepShow(Step);
|
Piece->SetStepShow(Step);
|
||||||
}
|
|
||||||
|
MovedPieces.Add(Piece);
|
||||||
|
mPieces.RemoveIndex(PieceIdx);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Modified)
|
PieceIdx++;
|
||||||
{
|
}
|
||||||
|
|
||||||
|
if (MovedPieces.IsEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (int PieceIdx = 0; PieceIdx < MovedPieces.GetSize(); PieceIdx++)
|
||||||
|
AddPiece(MovedPieces[PieceIdx]);
|
||||||
|
|
||||||
SaveCheckpoint("Modifying");
|
SaveCheckpoint("Modifying");
|
||||||
gMainWindow->UpdateAllViews();
|
gMainWindow->UpdateAllViews();
|
||||||
|
gMainWindow->UpdateTimeline();
|
||||||
UpdateSelection();
|
UpdateSelection();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void lcModel::ShowSelectedPiecesLater()
|
void lcModel::ShowSelectedPiecesLater()
|
||||||
{
|
{
|
||||||
bool Modified = false;
|
lcArray<lcPiece*> MovedPieces;
|
||||||
|
|
||||||
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++)
|
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); )
|
||||||
{
|
{
|
||||||
lcPiece* Piece = mPieces[PieceIdx];
|
lcPiece* Piece = mPieces[PieceIdx];
|
||||||
|
|
||||||
|
@ -1908,22 +1931,30 @@ void lcModel::ShowSelectedPiecesLater()
|
||||||
if (Step < LC_STEP_MAX)
|
if (Step < LC_STEP_MAX)
|
||||||
{
|
{
|
||||||
Step++;
|
Step++;
|
||||||
Modified = true;
|
|
||||||
Piece->SetStepShow(Step);
|
Piece->SetStepShow(Step);
|
||||||
|
|
||||||
if (Step > mCurrentStep)
|
if (Step > mCurrentStep)
|
||||||
Piece->SetSelected(false);
|
Piece->SetSelected(false);
|
||||||
}
|
|
||||||
|
MovedPieces.Add(Piece);
|
||||||
|
mPieces.RemoveIndex(PieceIdx);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Modified)
|
PieceIdx++;
|
||||||
{
|
}
|
||||||
|
|
||||||
|
if (MovedPieces.IsEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (int PieceIdx = 0; PieceIdx < MovedPieces.GetSize(); PieceIdx++)
|
||||||
|
AddPiece(MovedPieces[PieceIdx]);
|
||||||
|
|
||||||
SaveCheckpoint("Modifying");
|
SaveCheckpoint("Modifying");
|
||||||
gMainWindow->UpdateAllViews();
|
gMainWindow->UpdateAllViews();
|
||||||
|
gMainWindow->UpdateTimeline();
|
||||||
UpdateSelection();
|
UpdateSelection();
|
||||||
gMainWindow->UpdateFocusObject(GetFocusObject());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcModel::SetPieceSteps(const QList<QPair<lcPiece*, int>>& PieceSteps)
|
void lcModel::SetPieceSteps(const QList<QPair<lcPiece*, int>>& PieceSteps)
|
||||||
|
@ -3153,7 +3184,7 @@ void lcModel::InsertPieceToolClicked(const lcMatrix44& WorldMatrix)
|
||||||
Piece->Initialize(WorldMatrix, mCurrentStep);
|
Piece->Initialize(WorldMatrix, mCurrentStep);
|
||||||
Piece->SetColorIndex(gMainWindow->mColorIndex);
|
Piece->SetColorIndex(gMainWindow->mColorIndex);
|
||||||
Piece->UpdatePosition(mCurrentStep);
|
Piece->UpdatePosition(mCurrentStep);
|
||||||
mPieces.Add(Piece);
|
AddPiece(Piece);
|
||||||
|
|
||||||
ClearSelectionAndSetFocus(Piece, LC_PIECE_SECTION_POSITION);
|
ClearSelectionAndSetFocus(Piece, LC_PIECE_SECTION_POSITION);
|
||||||
|
|
||||||
|
@ -3515,7 +3546,7 @@ void lcModel::ShowArrayDialog()
|
||||||
{
|
{
|
||||||
lcPiece* Piece = (lcPiece*)NewPieces[PieceIdx];
|
lcPiece* Piece = (lcPiece*)NewPieces[PieceIdx];
|
||||||
Piece->UpdatePosition(mCurrentStep);
|
Piece->UpdatePosition(mCurrentStep);
|
||||||
mPieces.Add(Piece);
|
AddPiece(Piece);
|
||||||
}
|
}
|
||||||
|
|
||||||
AddToSelection(NewPieces);
|
AddToSelection(NewPieces);
|
||||||
|
@ -3544,7 +3575,7 @@ void lcModel::ShowMinifigDialog()
|
||||||
Piece->Initialize(Minifig.Matrices[PartIdx], mCurrentStep);
|
Piece->Initialize(Minifig.Matrices[PartIdx], mCurrentStep);
|
||||||
Piece->SetColorIndex(Minifig.Colors[PartIdx]);
|
Piece->SetColorIndex(Minifig.Colors[PartIdx]);
|
||||||
Piece->SetGroup(Group);
|
Piece->SetGroup(Group);
|
||||||
mPieces.Add(Piece);
|
AddPiece(Piece);
|
||||||
Piece->UpdatePosition(mCurrentStep);
|
Piece->UpdatePosition(mCurrentStep);
|
||||||
|
|
||||||
Pieces.Add(Piece);
|
Pieces.Add(Piece);
|
||||||
|
@ -3556,6 +3587,7 @@ void lcModel::ShowMinifigDialog()
|
||||||
|
|
||||||
void lcModel::UpdateInterface()
|
void lcModel::UpdateInterface()
|
||||||
{
|
{
|
||||||
|
gMainWindow->UpdateTimeline();
|
||||||
gMainWindow->UpdateUndoRedo(mUndoHistory.GetSize() > 1 ? mUndoHistory[0]->Description : NULL, !mRedoHistory.IsEmpty() ? mRedoHistory[0]->Description : NULL);
|
gMainWindow->UpdateUndoRedo(mUndoHistory.GetSize() > 1 ? mUndoHistory[0]->Description : NULL, !mRedoHistory.IsEmpty() ? mRedoHistory[0]->Description : NULL);
|
||||||
gMainWindow->UpdatePaste(!g_App->mClipboard.isEmpty());
|
gMainWindow->UpdatePaste(!g_App->mClipboard.isEmpty());
|
||||||
gMainWindow->UpdateCategories();
|
gMainWindow->UpdateCategories();
|
||||||
|
|
|
@ -327,6 +327,8 @@ protected:
|
||||||
void UpdateSelection() const;
|
void UpdateSelection() const;
|
||||||
void SelectGroup(lcGroup* TopGroup, bool Select);
|
void SelectGroup(lcGroup* TopGroup, bool Select);
|
||||||
|
|
||||||
|
void AddPiece(lcPiece* Piece);
|
||||||
|
|
||||||
lcModelProperties mProperties;
|
lcModelProperties mProperties;
|
||||||
PieceInfo* mPieceInfo;
|
PieceInfo* mPieceInfo;
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,6 @@ lcTimelineWidget::~lcTimelineWidget()
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcTimelineWidget::CustomMenuRequested(QPoint Pos)
|
void lcTimelineWidget::CustomMenuRequested(QPoint Pos)
|
||||||
{
|
|
||||||
QList<QTreeWidgetItem*> SelectedItems = selectedItems();
|
|
||||||
|
|
||||||
if (!SelectedItems.isEmpty())
|
|
||||||
{
|
{
|
||||||
QMenu* Menu = new QMenu(this);
|
QMenu* Menu = new QMenu(this);
|
||||||
|
|
||||||
|
@ -40,7 +36,6 @@ void lcTimelineWidget::CustomMenuRequested(QPoint Pos)
|
||||||
|
|
||||||
Menu->popup(viewport()->mapToGlobal(Pos));
|
Menu->popup(viewport()->mapToGlobal(Pos));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void lcTimelineWidget::Update()
|
void lcTimelineWidget::Update()
|
||||||
{
|
{
|
||||||
|
@ -57,8 +52,20 @@ void lcTimelineWidget::Update()
|
||||||
|
|
||||||
int Steps = Model->GetLastStep();
|
int Steps = Model->GetLastStep();
|
||||||
|
|
||||||
for (int TopLevelItemIdx = Steps; TopLevelItemIdx < topLevelItemCount(); TopLevelItemIdx++)
|
for (int TopLevelItemIdx = Steps; TopLevelItemIdx < topLevelItemCount(); )
|
||||||
delete topLevelItem(TopLevelItemIdx);
|
{
|
||||||
|
QTreeWidgetItem* StepItem = topLevelItem(TopLevelItemIdx);
|
||||||
|
|
||||||
|
while (StepItem->childCount())
|
||||||
|
{
|
||||||
|
QTreeWidgetItem* PieceItem = StepItem->child(0);
|
||||||
|
lcPiece* Piece = (lcPiece*)PieceItem->data(0, Qt::UserRole).value<uintptr_t>();
|
||||||
|
mItems.remove(Piece);
|
||||||
|
delete PieceItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete StepItem;
|
||||||
|
}
|
||||||
|
|
||||||
for (int Step = topLevelItemCount(); Step < Steps; Step++)
|
for (int Step = topLevelItemCount(); Step < Steps; Step++)
|
||||||
{
|
{
|
||||||
|
@ -69,28 +76,76 @@ void lcTimelineWidget::Update()
|
||||||
}
|
}
|
||||||
|
|
||||||
const lcArray<lcPiece*>& Pieces = Model->GetPieces();
|
const lcArray<lcPiece*>& Pieces = Model->GetPieces();
|
||||||
|
QTreeWidgetItem* StepItem = NULL;
|
||||||
|
int PieceItemIndex = 0;
|
||||||
|
int Step = -1;
|
||||||
|
|
||||||
for (int PieceIdx = 0; PieceIdx < Pieces.GetSize(); PieceIdx++)
|
for (int PieceIdx = 0; PieceIdx != Pieces.GetSize(); PieceIdx++)
|
||||||
{
|
{
|
||||||
lcPiece* Piece = Pieces[PieceIdx];
|
lcPiece* Piece = Pieces[PieceIdx];
|
||||||
QTreeWidgetItem* PieceItem = mItems.value(Piece);
|
|
||||||
QTreeWidgetItem* StepItem = topLevelItem(Piece->GetStepShow() - 1);
|
|
||||||
|
|
||||||
if (PieceItem)
|
if (Step != Piece->GetStepShow())
|
||||||
{
|
{
|
||||||
if (PieceItem->parent() != StepItem)
|
if (StepItem)
|
||||||
StepItem->addChild(PieceItem);
|
{
|
||||||
|
while (PieceItemIndex < StepItem->childCount())
|
||||||
|
{
|
||||||
|
QTreeWidgetItem* PieceItem = StepItem->child(PieceItemIndex);
|
||||||
|
lcPiece* RemovePiece = (lcPiece*)PieceItem->data(0, Qt::UserRole).value<uintptr_t>();
|
||||||
|
|
||||||
|
if (Pieces.FindIndex(RemovePiece) == -1)
|
||||||
|
{
|
||||||
|
mItems.remove(RemovePiece);
|
||||||
|
delete PieceItem;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PieceItem = new QTreeWidgetItem(StepItem, QStringList(Piece->mPieceInfo->m_strDescription));
|
PieceItem->parent()->removeChild(PieceItem);
|
||||||
|
topLevelItem(RemovePiece->GetStepShow() - 1)->addChild(PieceItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Step = Piece->GetStepShow();
|
||||||
|
StepItem = topLevelItem(Step - 1);
|
||||||
|
PieceItemIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
QTreeWidgetItem* PieceItem = mItems.value(Piece);
|
||||||
|
|
||||||
|
if (!PieceItem)
|
||||||
|
{
|
||||||
|
PieceItem = new QTreeWidgetItem(QStringList(Piece->mPieceInfo->m_strDescription));
|
||||||
PieceItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled);
|
PieceItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled);
|
||||||
PieceItem->setData(0, Qt::UserRole, qVariantFromValue<uintptr_t>((uintptr_t)Piece));
|
PieceItem->setData(0, Qt::UserRole, qVariantFromValue<uintptr_t>((uintptr_t)Piece));
|
||||||
StepItem->addChild(PieceItem);
|
StepItem->insertChild(PieceItemIndex, PieceItem);
|
||||||
mItems[Piece] = PieceItem;
|
mItems[Piece] = PieceItem;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (PieceItemIndex >= StepItem->childCount() || PieceItem != StepItem->child(PieceItemIndex))
|
||||||
|
{
|
||||||
|
if (PieceItem->parent() == StepItem)
|
||||||
|
StepItem->removeChild(PieceItem);
|
||||||
|
|
||||||
|
StepItem->insertChild(PieceItemIndex, PieceItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PieceItem->setSelected(Piece->IsSelected());
|
PieceItem->setSelected(Piece->IsSelected());
|
||||||
|
PieceItemIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!StepItem)
|
||||||
|
StepItem = topLevelItem(0);
|
||||||
|
|
||||||
|
while (PieceItemIndex < StepItem->childCount())
|
||||||
|
{
|
||||||
|
QTreeWidgetItem* PieceItem = StepItem->child(PieceItemIndex);
|
||||||
|
lcPiece* RemovePiece = (lcPiece*)PieceItem->data(0, Qt::UserRole).value<uintptr_t>();
|
||||||
|
|
||||||
|
mItems.remove(RemovePiece);
|
||||||
|
delete PieceItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
blockSignals(Blocked);
|
blockSignals(Blocked);
|
||||||
|
|
|
@ -178,7 +178,6 @@ int main(int argc, char *argv[])
|
||||||
if (!g_App->Initialize(argc, argv, libPath, LDrawPath, cachePath.toLocal8Bit().data()))
|
if (!g_App->Initialize(argc, argv, libPath, LDrawPath, cachePath.toLocal8Bit().data()))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
lcGetActiveModel()->UpdateInterface();
|
|
||||||
gMainWindow->SetColorIndex(lcGetColorIndex(4));
|
gMainWindow->SetColorIndex(lcGetColorIndex(4));
|
||||||
gMainWindow->UpdateRecentFiles();
|
gMainWindow->UpdateRecentFiles();
|
||||||
gMainWindow->show();
|
gMainWindow->show();
|
||||||
|
|
Loading…
Reference in a new issue