diff --git a/common/lc_commands.cpp b/common/lc_commands.cpp index 42d0caf6..3e0cab11 100644 --- a/common/lc_commands.cpp +++ b/common/lc_commands.cpp @@ -179,6 +179,13 @@ lcCommand gCommands[LC_NUM_COMMANDS] = QT_TRANSLATE_NOOP("Status", "Insert Clipboard contents"), QT_TRANSLATE_NOOP("Shortcut", "Ctrl+V") }, + // LC_EDIT_DUPLICATE + { + QT_TRANSLATE_NOOP("Action", "Edit.Duplicate"), + QT_TRANSLATE_NOOP("Menu", "&Duplicate"), + QT_TRANSLATE_NOOP("Status", "Create a copy of the selected pieces"), + QT_TRANSLATE_NOOP("Shortcut", "Ctrl+D") + }, // LC_EDIT_FIND { QT_TRANSLATE_NOOP("Action", "Edit.Find"), diff --git a/common/lc_commands.h b/common/lc_commands.h index 0f0fb938..a1b33319 100644 --- a/common/lc_commands.h +++ b/common/lc_commands.h @@ -30,6 +30,7 @@ enum lcCommandId LC_EDIT_CUT, LC_EDIT_COPY, LC_EDIT_PASTE, + LC_EDIT_DUPLICATE, LC_EDIT_FIND, LC_EDIT_FIND_NEXT, LC_EDIT_FIND_PREVIOUS, diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index d80e317e..93533854 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -366,6 +366,7 @@ void lcMainWindow::CreateMenus() EditMenu->addAction(mActions[LC_EDIT_CUT]); EditMenu->addAction(mActions[LC_EDIT_COPY]); EditMenu->addAction(mActions[LC_EDIT_PASTE]); + EditMenu->addAction(mActions[LC_EDIT_DUPLICATE]); EditMenu->addSeparator(); EditMenu->addAction(mActions[LC_EDIT_FIND]); @@ -1470,6 +1471,7 @@ void lcMainWindow::UpdateSelectedObjects(bool SelectionChanged) mActions[LC_EDIT_CUT]->setEnabled(Flags & LC_SEL_SELECTED); mActions[LC_EDIT_COPY]->setEnabled(Flags & LC_SEL_SELECTED); + mActions[LC_EDIT_DUPLICATE]->setEnabled(Flags & LC_SEL_SELECTED); mActions[LC_EDIT_FIND]->setEnabled((Flags & LC_SEL_NO_PIECES) == 0); mActions[LC_EDIT_FIND_NEXT]->setEnabled((Flags & LC_SEL_NO_PIECES) == 0); mActions[LC_EDIT_FIND_PREVIOUS]->setEnabled((Flags & LC_SEL_NO_PIECES) == 0); @@ -2034,6 +2036,10 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId) lcGetActiveModel()->Paste(); break; + case LC_EDIT_DUPLICATE: + lcGetActiveModel()->DuplicateSelectedPieces(); + break; + case LC_EDIT_FIND: if (DoDialog(LC_DIALOG_FIND, &mSearchOptions)) lcGetActiveModel()->FindPiece(true, true); diff --git a/common/lc_model.cpp b/common/lc_model.cpp index 2e306899..0479f893 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -996,7 +996,7 @@ void lcModel::Cut() gMainWindow->UpdateTimeline(false, false); gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateAllViews(); - SaveCheckpoint("Cutting"); + SaveCheckpoint(tr("Cutting")); } } @@ -1049,6 +1049,33 @@ void lcModel::Paste() gMainWindow->UpdateAllViews(); } +void lcModel::DuplicateSelectedPieces() +{ + lcArray NewPieces; + + for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++) + { + lcPiece* Piece = mPieces[PieceIdx]; + + if (!Piece->IsSelected()) + continue; + + lcPiece* NewPiece = new lcPiece(*Piece); + NewPiece->UpdatePosition(mCurrentStep); + NewPieces.Add(NewPiece); + + PieceIdx++; + InsertPiece(NewPiece, PieceIdx); + } + + if (NewPieces.IsEmpty()) + return; + + gMainWindow->UpdateTimeline(false, false); + SetSelectionAndFocus(NewPieces, NULL, 0); + SaveCheckpoint(tr("Duplicating Pieces")); +} + void lcModel::GetScene(lcScene& Scene, lcCamera* ViewCamera, bool DrawInterface) const { Scene.Begin(ViewCamera->mWorldView); @@ -1978,7 +2005,7 @@ void lcModel::AddPiece() gMainWindow->UpdateTimeline(false, false); ClearSelectionAndSetFocus(Piece, LC_PIECE_SECTION_POSITION); - SaveCheckpoint("Adding Piece"); + SaveCheckpoint(tr("Adding Piece")); } void lcModel::AddPiece(lcPiece* Piece) @@ -2020,7 +2047,7 @@ void lcModel::DeleteAllCameras() gMainWindow->UpdateCameraMenu(); gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateAllViews(); - SaveCheckpoint("Reseting Cameras"); + SaveCheckpoint(tr("Reseting Cameras")); } void lcModel::DeleteSelectedObjects() @@ -2030,7 +2057,7 @@ void lcModel::DeleteSelectedObjects() gMainWindow->UpdateTimeline(false, false); gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateAllViews(); - SaveCheckpoint("Deleting"); + SaveCheckpoint(tr("Deleting")); } } @@ -2061,7 +2088,7 @@ void lcModel::InsertControlPoint() if (Piece->InsertControlPoint(Start, End)) { - SaveCheckpoint("Modifying"); + SaveCheckpoint(tr("Modifying")); gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateAllViews(); } @@ -2078,7 +2105,7 @@ void lcModel::RemoveFocusedControlPoint() if (Piece->RemoveFocusedControlPoint()) { - SaveCheckpoint("Modifying"); + SaveCheckpoint(tr("Modifying")); gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateAllViews(); } @@ -2120,7 +2147,7 @@ void lcModel::ShowSelectedPiecesEarlier() AddPiece(Piece); } - SaveCheckpoint("Modifying"); + SaveCheckpoint(tr("Modifying")); gMainWindow->UpdateTimeline(false, false); gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateAllViews(); @@ -2165,7 +2192,7 @@ void lcModel::ShowSelectedPiecesLater() AddPiece(Piece); } - SaveCheckpoint("Modifying"); + SaveCheckpoint(tr("Modifying")); gMainWindow->UpdateTimeline(false, false); gMainWindow->UpdateSelectedObjects(true); gMainWindow->UpdateAllViews(); @@ -2200,7 +2227,7 @@ void lcModel::SetPieceSteps(const QList>& PieceSteps) if (Modified) { - SaveCheckpoint("Modifying"); + SaveCheckpoint(tr("Modifying")); gMainWindow->UpdateAllViews(); gMainWindow->UpdateTimeline(false, false); gMainWindow->UpdateSelectedObjects(true); @@ -2252,7 +2279,7 @@ void lcModel::MoveSelectionToModel(lcModel* Model) if (ModelPiece) ModelPiece->UpdatePosition(mCurrentStep); - SaveCheckpoint("New Model"); + SaveCheckpoint(tr("New Model")); gMainWindow->UpdateTimeline(false, false); ClearSelectionAndSetFocus(ModelPiece, LC_PIECE_SECTION_POSITION); } @@ -2302,7 +2329,7 @@ void lcModel::InlineSelectedModels() return; } - SaveCheckpoint("Inlining"); + SaveCheckpoint(tr("Inlining")); gMainWindow->UpdateTimeline(false, false); SetSelectionAndFocus(NewPieces, NULL, 0); } @@ -2449,7 +2476,7 @@ void lcModel::MoveSelectedObjects(const lcVector3& PieceDistance, const lcVector { gMainWindow->UpdateAllViews(); if (Checkpoint) - SaveCheckpoint("Moving"); + SaveCheckpoint(tr("Moving")); gMainWindow->UpdateSelectedObjects(false); } } @@ -2515,7 +2542,7 @@ void lcModel::RotateSelectedPieces(const lcVector3& Angles, bool Relative, bool { gMainWindow->UpdateAllViews(); if (Checkpoint) - SaveCheckpoint("Rotating"); + SaveCheckpoint(tr("Rotating")); gMainWindow->UpdateSelectedObjects(false); } } @@ -2541,7 +2568,7 @@ void lcModel::ScaleSelectedPieces(const float Scale, bool Update, bool Checkpoin { gMainWindow->UpdateAllViews(); if (Checkpoint) - SaveCheckpoint("Scaling"); + SaveCheckpoint(tr("Scaling")); gMainWindow->UpdateSelectedObjects(false); } } diff --git a/common/lc_model.h b/common/lc_model.h index a26f2117..a0452129 100644 --- a/common/lc_model.h +++ b/common/lc_model.h @@ -211,6 +211,7 @@ public: void Cut(); void Copy(); void Paste(); + void DuplicateSelectedPieces(); void GetScene(lcScene& Scene, lcCamera* ViewCamera, bool DrawInterface) const; void SubModelAddRenderMeshes(lcScene& Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, bool Focused, bool Selected) const; diff --git a/common/piece.cpp b/common/piece.cpp index d06f62e2..172dadde 100644 --- a/common/piece.cpp +++ b/common/piece.cpp @@ -34,6 +34,27 @@ lcPiece::lcPiece(PieceInfo* Info) ChangeKey(mRotationKeys, lcMatrix33Identity(), 1, true); } +lcPiece::lcPiece(const lcPiece& Other) + : lcObject(LC_OBJECT_PIECE) +{ + mMesh = NULL; + SetPieceInfo(Other.mPieceInfo, true); + mState = 0; + mColorIndex = Other.mColorIndex; + mColorCode = Other.mColorCode; + mStepShow = Other.mStepShow; + mStepHide = Other.mStepHide; + mGroup = Other.mGroup; + mFileLine = -1; + mPivotMatrix = Other.mPivotMatrix; + + mPositionKeys = Other.mPositionKeys; + mRotationKeys = Other.mRotationKeys; + mControlPoints = Other.mControlPoints; + + UpdateMesh(); +} + lcPiece::~lcPiece() { if (mPieceInfo) diff --git a/common/piece.h b/common/piece.h index aa0c684e..47dec6a8 100644 --- a/common/piece.h +++ b/common/piece.h @@ -56,6 +56,7 @@ class lcPiece : public lcObject { public: lcPiece(PieceInfo* Info); + lcPiece(const lcPiece& Other); ~lcPiece(); virtual bool IsSelected() const diff --git a/common/view.cpp b/common/view.cpp index e9e1a459..a4d63235 100644 --- a/common/view.cpp +++ b/common/view.cpp @@ -341,6 +341,7 @@ void View::ShowContextMenu() const Popup->addAction(Actions[LC_EDIT_CUT]); Popup->addAction(Actions[LC_EDIT_COPY]); Popup->addAction(Actions[LC_EDIT_PASTE]); + Popup->addAction(Actions[LC_EDIT_DUPLICATE]); Popup->addSeparator();