Added option to inline models.

This commit is contained in:
leo
2015-12-01 23:31:28 +00:00
parent 526e35d2aa
commit a95cbfa8c0
5 changed files with 99 additions and 2 deletions
+14
View File
@@ -1047,6 +1047,20 @@ lcCommand gCommands[LC_NUM_COMMANDS] =
QT_TRANSLATE_NOOP("Status", "Make copies of the selected pieces"),
QT_TRANSLATE_NOOP("Shortcut", "")
},
// LC_PIECE_MOVE_SELECTION_TO_MODEL
{
"Piece.MoveSelectionToModel",
QT_TRANSLATE_NOOP("Menu", "Move Selection To Model..."),
QT_TRANSLATE_NOOP("Status", "Move the currently selected pieces to a new model and replaces them with a reference to the model"),
QT_TRANSLATE_NOOP("Shortcut", "")
},
// LC_PIECE_INLINE_SELECTED_MODELS
{
"Piece.InlineSelectedModels",
QT_TRANSLATE_NOOP("Menu", "Inline Selected Models"),
QT_TRANSLATE_NOOP("Status", "Insert the contents of the selected model references into the current model"),
QT_TRANSLATE_NOOP("Shortcut", "")
},
// LC_PIECE_GROUP
{
"Piece.Group",
+2
View File
@@ -160,6 +160,8 @@ enum lcCommandId
LC_PIECE_ROTATE_MINUSZ,
LC_PIECE_MINIFIG_WIZARD,
LC_PIECE_ARRAY,
LC_PIECE_MOVE_SELECTION_TO_MODEL,
LC_PIECE_INLINE_SELECTED_MODELS,
LC_PIECE_GROUP,
LC_PIECE_UNGROUP,
LC_PIECE_GROUP_ADD,
+13
View File
@@ -415,6 +415,9 @@ void lcMainWindow::CreateMenus()
PieceMenu->addAction(mActions[LC_PIECE_ARRAY]);
PieceMenu->addAction(mActions[LC_PIECE_MINIFIG_WIZARD]);
PieceMenu->addSeparator();
PieceMenu->addAction(mActions[LC_PIECE_MOVE_SELECTION_TO_MODEL]);
PieceMenu->addAction(mActions[LC_PIECE_INLINE_SELECTED_MODELS]);
PieceMenu->addSeparator();
PieceMenu->addAction(mActions[LC_PIECE_GROUP]);
PieceMenu->addAction(mActions[LC_PIECE_UNGROUP]);
PieceMenu->addAction(mActions[LC_PIECE_GROUP_REMOVE]);
@@ -1485,6 +1488,8 @@ void lcMainWindow::UpdateSelectedObjects(int Flags, int SelectedCount, lcObject*
mActions[LC_PIECE_HIDE_UNSELECTED]->setEnabled(Flags & LC_SEL_UNSELECTED);
mActions[LC_PIECE_UNHIDE_SELECTED]->setEnabled(Flags & LC_SEL_HIDDEN_SELECTED);
mActions[LC_PIECE_UNHIDE_ALL]->setEnabled(Flags & LC_SEL_HIDDEN);
mActions[LC_PIECE_MOVE_SELECTION_TO_MODEL]->setEnabled(Flags & LC_SEL_PIECE);
mActions[LC_PIECE_INLINE_SELECTED_MODELS]->setEnabled(Flags & LC_SEL_MODEL_SELECTED);
mActions[LC_PIECE_GROUP]->setEnabled(Flags & LC_SEL_CAN_GROUP);
mActions[LC_PIECE_UNGROUP]->setEnabled(Flags & LC_SEL_GROUPED);
mActions[LC_PIECE_GROUP_ADD]->setEnabled((Flags & (LC_SEL_GROUPED | LC_SEL_FOCUS_GROUPED)) == LC_SEL_GROUPED);
@@ -2109,6 +2114,14 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId)
lcGetActiveModel()->ShowArrayDialog();
break;
case LC_PIECE_MOVE_SELECTION_TO_MODEL:
lcGetActiveModel()->MoveSelectionToModel();
break;
case LC_PIECE_INLINE_SELECTED_MODELS:
lcGetActiveModel()->InlineSelectedModels();
break;
case LC_PIECE_GROUP:
lcGetActiveModel()->GroupSelection();
break;
+65 -2
View File
@@ -1890,12 +1890,18 @@ void lcModel::AddPiece(lcPiece* Piece)
{
if (mPieces[PieceIdx]->GetStepShow() > Piece->GetStepShow())
{
mPieces.InsertAt(PieceIdx, Piece);
InsertPiece(Piece, PieceIdx);
return;
}
}
InsertPiece(Piece, mPieces.GetSize());
}
void lcModel::InsertPiece(lcPiece* Piece, int Index)
{
PieceInfo* Info = Piece->mPieceInfo;
if (!Info->IsModel())
{
lcMesh* Mesh = Info->IsTemporary() ? gPlaceholderMesh : Info->GetMesh();
@@ -1904,7 +1910,7 @@ void lcModel::AddPiece(lcPiece* Piece)
lcGetPiecesLibrary()->mBuffersDirty = true;
}
mPieces.Add(Piece);
mPieces.InsertAt(Index, Piece);
}
void lcModel::DeleteAllCameras()
@@ -2056,6 +2062,60 @@ void lcModel::SetPieceSteps(const QList<QPair<lcPiece*, lcStep>>& PieceSteps)
}
}
void lcModel::MoveSelectionToModel()
{
}
void lcModel::InlineSelectedModels()
{
lcArray<lcPiece*> NewPieces;
for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); )
{
lcPiece* Piece = mPieces[PieceIdx];
if (!Piece->IsSelected() || !Piece->mPieceInfo->IsModel())
{
PieceIdx++;
continue;
}
mPieces.RemoveIndex(PieceIdx);
lcArray<lcModelPartsEntry> ModelParts;
Piece->mPieceInfo->GetModelParts(Piece->mModelWorld, Piece->mColorIndex, ModelParts);
for (int InsertIdx = 0; InsertIdx < ModelParts.GetSize(); InsertIdx++)
{
lcModelPartsEntry& Entry = ModelParts[InsertIdx];
lcPiece* NewPiece = new lcPiece(Entry.Info);
NewPiece->Initialize(Entry.WorldMatrix, Piece->GetStepShow());
NewPiece->SetColorIndex(Entry.ColorIndex);
NewPiece->UpdatePosition(mCurrentStep);
NewPieces.Add(NewPiece);
InsertPiece(NewPiece, PieceIdx);
PieceIdx++;
}
delete Piece;
}
if (!NewPieces.GetSize())
{
QMessageBox::information(gMainWindow, tr("LeoCAD"), tr("No models selected."));
return;
}
SaveCheckpoint("Inlining");
gMainWindow->UpdateAllViews();
gMainWindow->UpdateTimeline(false, false);
gMainWindow->UpdateFocusObject(GetFocusObject());
UpdateSelection();
}
bool lcModel::RemoveSelectedObjects()
{
bool RemovedPiece = false;
@@ -2844,6 +2904,9 @@ void lcModel::UpdateSelection() const
if (Piece->IsFocused())
Focus = Piece;
if (Piece->mPieceInfo->IsModel())
Flags |= LC_SEL_MODEL_SELECTED;
if (Piece->IsHidden())
Flags |= LC_SEL_HIDDEN | LC_SEL_HIDDEN_SELECTED;
else
+5
View File
@@ -15,6 +15,7 @@
#define LC_SEL_GROUPED 0x080 // At least one piece selected is grouped
#define LC_SEL_FOCUS_GROUPED 0x100 // Focused piece is grouped
#define LC_SEL_CAN_GROUP 0x200 // Can make a new group
#define LC_SEL_MODEL_SELECTED 0x400 // At least one model reference is selected
enum lcTransformType
{
@@ -199,6 +200,9 @@ public:
void ShowSelectedPiecesLater();
void SetPieceSteps(const QList<QPair<lcPiece*, lcStep>>& PieceSteps);
void MoveSelectionToModel();
void InlineSelectedModels();
lcGroup* AddGroup(const QString& Prefix, lcGroup* Parent);
lcGroup* GetGroup(const QString& Name, bool CreateIfMissing);
void RemoveGroup(lcGroup* Group);
@@ -331,6 +335,7 @@ protected:
void SelectGroup(lcGroup* TopGroup, bool Select);
void AddPiece(lcPiece* Piece);
void InsertPiece(lcPiece* Piece, int Index);
lcModelProperties mProperties;
PieceInfo* mPieceInfo;