Use scoped enum.

This commit is contained in:
Leonardo Zide 2020-05-03 13:04:40 -07:00
parent 13ae577533
commit 9fa660313a
3 changed files with 49 additions and 37 deletions

View file

@ -89,7 +89,7 @@ lcMainWindow::lcMainWindow()
{ {
memset(mActions, 0, sizeof(mActions)); memset(mActions, 0, sizeof(mActions));
mTransformType = LC_TRANSFORM_RELATIVE_TRANSLATION; mTransformType = lcTransformType::RelativeTranslation;
mColorIndex = lcGetColorIndex(4); mColorIndex = lcGetColorIndex(4);
mTool = LC_TOOL_SELECT; mTool = LC_TOOL_SELECT;
@ -102,7 +102,7 @@ lcMainWindow::lcMainWindow()
mRelativeTransform = true; mRelativeTransform = true;
mLocalTransform = false; mLocalTransform = false;
mCurrentPieceInfo = nullptr; mCurrentPieceInfo = nullptr;
mSelectionMode = lcSelectionMode::SINGLE; mSelectionMode = lcSelectionMode::Single;
mModelTabWidget = nullptr; mModelTabWidget = nullptr;
memset(&mSearchOptions, 0, sizeof(mSearchOptions)); memset(&mSearchOptions, 0, sizeof(mSearchOptions));
@ -1667,9 +1667,12 @@ void lcMainWindow::SetLocalTransform(bool SelectionTransform)
void lcMainWindow::SetTransformType(lcTransformType TransformType) void lcMainWindow::SetTransformType(lcTransformType TransformType)
{ {
if (TransformType < lcTransformType::First || TransformType >= lcTransformType::Count)
return;
mTransformType = TransformType; mTransformType = TransformType;
const char* IconNames[] = const char* IconNames[static_cast<int>(lcTransformType::Count)] =
{ {
":/resources/edit_transform_absolute_translation.png", ":/resources/edit_transform_absolute_translation.png",
":/resources/edit_transform_relative_translation.png", ":/resources/edit_transform_relative_translation.png",
@ -1677,11 +1680,9 @@ void lcMainWindow::SetTransformType(lcTransformType TransformType)
":/resources/edit_transform_relative_rotation.png" ":/resources/edit_transform_relative_rotation.png"
}; };
if (TransformType >= 0 && TransformType <= 3) int TransformIndex = static_cast<int>(TransformType);
{ mActions[LC_EDIT_TRANSFORM_ABSOLUTE_TRANSLATION + TransformIndex]->setChecked(true);
mActions[LC_EDIT_TRANSFORM_ABSOLUTE_TRANSLATION + TransformType]->setChecked(true); mActions[LC_EDIT_TRANSFORM]->setIcon(QIcon(IconNames[TransformIndex]));
mActions[LC_EDIT_TRANSFORM]->setIcon(QIcon(IconNames[TransformType]));
}
} }
void lcMainWindow::SetCurrentPieceInfo(PieceInfo* Info) void lcMainWindow::SetCurrentPieceInfo(PieceInfo* Info)
@ -2105,19 +2106,19 @@ void lcMainWindow::UpdateSelectionMode()
{ {
switch (mSelectionMode) switch (mSelectionMode)
{ {
case lcSelectionMode::SINGLE: case lcSelectionMode::Single:
mActions[LC_EDIT_SELECTION_SINGLE]->setChecked(true); mActions[LC_EDIT_SELECTION_SINGLE]->setChecked(true);
break; break;
case lcSelectionMode::PIECE: case lcSelectionMode::Piece:
mActions[LC_EDIT_SELECTION_PIECE]->setChecked(true); mActions[LC_EDIT_SELECTION_PIECE]->setChecked(true);
break; break;
case lcSelectionMode::COLOR: case lcSelectionMode::Color:
mActions[LC_EDIT_SELECTION_COLOR]->setChecked(true); mActions[LC_EDIT_SELECTION_COLOR]->setChecked(true);
break; break;
case lcSelectionMode::PIECE_COLOR: case lcSelectionMode::PieceColor:
mActions[LC_EDIT_SELECTION_PIECE_COLOR]->setChecked(true); mActions[LC_EDIT_SELECTION_PIECE_COLOR]->setChecked(true);
break; break;
} }
@ -2609,19 +2610,19 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId)
break; break;
case LC_EDIT_SELECTION_SINGLE: case LC_EDIT_SELECTION_SINGLE:
SetSelectionMode(lcSelectionMode::SINGLE); SetSelectionMode(lcSelectionMode::Single);
break; break;
case LC_EDIT_SELECTION_PIECE: case LC_EDIT_SELECTION_PIECE:
SetSelectionMode(lcSelectionMode::PIECE); SetSelectionMode(lcSelectionMode::Piece);
break; break;
case LC_EDIT_SELECTION_COLOR: case LC_EDIT_SELECTION_COLOR:
SetSelectionMode(lcSelectionMode::COLOR); SetSelectionMode(lcSelectionMode::Color);
break; break;
case LC_EDIT_SELECTION_PIECE_COLOR: case LC_EDIT_SELECTION_PIECE_COLOR:
SetSelectionMode(lcSelectionMode::PIECE_COLOR); SetSelectionMode(lcSelectionMode::PieceColor);
break; break;
case LC_VIEW_SPLIT_HORIZONTAL: case LC_VIEW_SPLIT_HORIZONTAL:
@ -3139,10 +3140,19 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId)
break; break;
case LC_EDIT_TRANSFORM_ABSOLUTE_TRANSLATION: case LC_EDIT_TRANSFORM_ABSOLUTE_TRANSLATION:
SetTransformType(lcTransformType::AbsoluteTranslation);
break;
case LC_EDIT_TRANSFORM_RELATIVE_TRANSLATION: case LC_EDIT_TRANSFORM_RELATIVE_TRANSLATION:
SetTransformType(lcTransformType::RelativeTranslation);
break;
case LC_EDIT_TRANSFORM_ABSOLUTE_ROTATION: case LC_EDIT_TRANSFORM_ABSOLUTE_ROTATION:
SetTransformType(lcTransformType::AbsoluteRotation);
break;
case LC_EDIT_TRANSFORM_RELATIVE_ROTATION: case LC_EDIT_TRANSFORM_RELATIVE_ROTATION:
SetTransformType((lcTransformType)(CommandId - LC_EDIT_TRANSFORM_ABSOLUTE_TRANSLATION)); SetTransformType(lcTransformType::RelativeRotation);
break; break;
case LC_EDIT_ACTION_SELECT: case LC_EDIT_ACTION_SELECT:

View file

@ -3002,19 +3002,19 @@ void lcModel::TransformSelectedObjects(lcTransformType TransformType, const lcVe
{ {
switch (TransformType) switch (TransformType)
{ {
case LC_TRANSFORM_ABSOLUTE_TRANSLATION: case lcTransformType::AbsoluteTranslation:
MoveSelectedObjects(Transform, false, false, true, true); MoveSelectedObjects(Transform, false, false, true, true);
break; break;
case LC_TRANSFORM_RELATIVE_TRANSLATION: case lcTransformType::RelativeTranslation:
MoveSelectedObjects(Transform, true, false, true, true); MoveSelectedObjects(Transform, true, false, true, true);
break; break;
case LC_TRANSFORM_ABSOLUTE_ROTATION: case lcTransformType::AbsoluteRotation:
RotateSelectedPieces(Transform, false, false, true, true); RotateSelectedPieces(Transform, false, false, true, true);
break; break;
case LC_TRANSFORM_RELATIVE_ROTATION: case lcTransformType::RelativeRotation:
RotateSelectedPieces(Transform, true, false, true, true); RotateSelectedPieces(Transform, true, false, true, true);
break; break;
} }
@ -3599,22 +3599,22 @@ lcArray<lcObject*> lcModel::GetSelectionModePieces(lcPiece* SelectedPiece) const
switch (gMainWindow->GetSelectionMode()) switch (gMainWindow->GetSelectionMode())
{ {
case lcSelectionMode::SINGLE: case lcSelectionMode::Single:
break; break;
case lcSelectionMode::PIECE: case lcSelectionMode::Piece:
for (lcPiece* Piece : mPieces) for (lcPiece* Piece : mPieces)
if (Piece->IsVisible(mCurrentStep) && Piece->mPieceInfo == Info && Piece != SelectedPiece) if (Piece->IsVisible(mCurrentStep) && Piece->mPieceInfo == Info && Piece != SelectedPiece)
Pieces.Add(Piece); Pieces.Add(Piece);
break; break;
case lcSelectionMode::COLOR: case lcSelectionMode::Color:
for (lcPiece* Piece : mPieces) for (lcPiece* Piece : mPieces)
if (Piece->IsVisible(mCurrentStep) && Piece->mColorIndex == ColorIndex && Piece != SelectedPiece) if (Piece->IsVisible(mCurrentStep) && Piece->mColorIndex == ColorIndex && Piece != SelectedPiece)
Pieces.Add(Piece); Pieces.Add(Piece);
break; break;
case lcSelectionMode::PIECE_COLOR: case lcSelectionMode::PieceColor:
for (lcPiece* Piece : mPieces) for (lcPiece* Piece : mPieces)
if (Piece->IsVisible(mCurrentStep) && Piece->mPieceInfo == Info && Piece->mColorIndex == ColorIndex && Piece != SelectedPiece) if (Piece->IsVisible(mCurrentStep) && Piece->mPieceInfo == Info && Piece->mColorIndex == ColorIndex && Piece != SelectedPiece)
Pieces.Add(Piece); Pieces.Add(Piece);
@ -3678,7 +3678,7 @@ void lcModel::FocusOrDeselectObject(const lcObjectSection& ObjectSection)
{ {
lcPiece* Piece = (lcPiece*)Object; lcPiece* Piece = (lcPiece*)Object;
if (gMainWindow->GetSelectionMode() == lcSelectionMode::SINGLE) if (gMainWindow->GetSelectionMode() == lcSelectionMode::Single)
SelectGroup(Piece->GetTopGroup(), IsSelected); SelectGroup(Piece->GetTopGroup(), IsSelected);
else else
{ {
@ -3787,7 +3787,7 @@ void lcModel::RemoveFromSelection(const lcArray<lcObject*>& Objects)
{ {
lcPiece* Piece = (lcPiece*)SelectedObject; lcPiece* Piece = (lcPiece*)SelectedObject;
if (gMainWindow->GetSelectionMode() == lcSelectionMode::SINGLE) if (gMainWindow->GetSelectionMode() == lcSelectionMode::Single)
SelectGroup(Piece->GetTopGroup(), false); SelectGroup(Piece->GetTopGroup(), false);
else else
{ {
@ -3828,7 +3828,7 @@ void lcModel::RemoveFromSelection(const lcObjectSection& ObjectSection)
{ {
lcPiece* Piece = (lcPiece*)SelectedObject; lcPiece* Piece = (lcPiece*)SelectedObject;
if (gMainWindow->GetSelectionMode() == lcSelectionMode::SINGLE) if (gMainWindow->GetSelectionMode() == lcSelectionMode::Single)
SelectGroup(Piece->GetTopGroup(), false); SelectGroup(Piece->GetTopGroup(), false);
else else
{ {

View file

@ -22,18 +22,20 @@ class lcGLWidget;
enum class lcSelectionMode enum class lcSelectionMode
{ {
SINGLE, Single,
PIECE, Piece,
COLOR, Color,
PIECE_COLOR PieceColor
}; };
enum lcTransformType enum class lcTransformType
{ {
LC_TRANSFORM_ABSOLUTE_TRANSLATION, First,
LC_TRANSFORM_RELATIVE_TRANSLATION, AbsoluteTranslation = First,
LC_TRANSFORM_ABSOLUTE_ROTATION, RelativeTranslation,
LC_TRANSFORM_RELATIVE_ROTATION AbsoluteRotation,
RelativeRotation,
Count
}; };
enum lcBackgroundType enum lcBackgroundType