Added Duplicate Piece action.

This commit is contained in:
leozide 2017-03-08 15:49:57 -08:00
parent 6915c3a456
commit cf65201095
8 changed files with 79 additions and 14 deletions

View file

@ -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"),

View file

@ -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,

View file

@ -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);

View file

@ -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<lcObject*> 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<QPair<lcPiece*, lcStep>>& 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);
}
}

View file

@ -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;

View file

@ -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)

View file

@ -56,6 +56,7 @@ class lcPiece : public lcObject
{
public:
lcPiece(PieceInfo* Info);
lcPiece(const lcPiece& Other);
~lcPiece();
virtual bool IsSelected() const

View file

@ -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();