Remove magic number and hard type enums in DrawViewPart.h
- Remove currently present magic numbers - Hard type enums, so magic numbers can no longer be introduced. We don't want people to introduce magic numbers.
This commit is contained in:
@@ -1276,29 +1276,29 @@ Base::Vector3d DrawViewPart::getXDirection() const
|
||||
}
|
||||
|
||||
|
||||
void DrawViewPart::rotate(const std::string& rotationdirection)
|
||||
void DrawViewPart::rotate(const RotationMotion& motion)
|
||||
{
|
||||
std::pair<Base::Vector3d, Base::Vector3d> newDirs;
|
||||
if (rotationdirection == "Right")
|
||||
newDirs = getDirsFromFront("Left");// Front -> Right -> Rear -> Left -> Front
|
||||
else if (rotationdirection == "Left")
|
||||
newDirs = getDirsFromFront("Right");// Front -> Left -> Rear -> Right -> Front
|
||||
else if (rotationdirection == "Up")
|
||||
newDirs = getDirsFromFront("Bottom");// Front -> Top -> Rear -> Bottom -> Front
|
||||
else if (rotationdirection == "Down")
|
||||
newDirs = getDirsFromFront("Top");// Front -> Bottom -> Rear -> Top -> Front
|
||||
if (motion == RotationMotion::Right)
|
||||
newDirs = getDirsFromFront(ProjDirection::Left);// Front -> Right -> Rear -> Left -> Front
|
||||
else if (motion == RotationMotion::Left)
|
||||
newDirs = getDirsFromFront(ProjDirection::Right);// Front -> Left -> Rear -> Right -> Front
|
||||
else if (motion == RotationMotion::Up)
|
||||
newDirs = getDirsFromFront(ProjDirection::Bottom);// Front -> Top -> Rear -> Bottom -> Front
|
||||
else if (motion == RotationMotion::Down)
|
||||
newDirs = getDirsFromFront(ProjDirection::Top);// Front -> Bottom -> Rear -> Top -> Front
|
||||
|
||||
Direction.setValue(newDirs.first);
|
||||
XDirection.setValue(newDirs.second);
|
||||
recompute();
|
||||
}
|
||||
|
||||
void DrawViewPart::spin(const std::string& spindirection)
|
||||
void DrawViewPart::spin(const SpinDirection& spindirection)
|
||||
{
|
||||
double angle;
|
||||
if (spindirection == "CW")
|
||||
if (spindirection == SpinDirection::CW)
|
||||
angle = M_PI / 2.0;// Top -> Right -> Bottom -> Left -> Top
|
||||
if (spindirection == "CCW")
|
||||
if (spindirection == SpinDirection::CCW)
|
||||
angle = -M_PI / 2.0;// Top -> Left -> Bottom -> Right -> Top
|
||||
|
||||
spin(angle);
|
||||
@@ -1315,7 +1315,7 @@ void DrawViewPart::spin(double angle)
|
||||
recompute();
|
||||
}
|
||||
|
||||
std::pair<Base::Vector3d, Base::Vector3d> DrawViewPart::getDirsFromFront(std::string viewType)
|
||||
std::pair<Base::Vector3d, Base::Vector3d> DrawViewPart::getDirsFromFront(ProjDirection viewType)
|
||||
{
|
||||
// Base::Console().Message("DVP::getDirsFromFront(%s)\n", viewType.c_str());
|
||||
std::pair<Base::Vector3d, Base::Vector3d> result;
|
||||
@@ -1335,60 +1335,52 @@ std::pair<Base::Vector3d, Base::Vector3d> DrawViewPart::getDirsFromFront(std::st
|
||||
|
||||
double angle = M_PI / 2.0;//90*
|
||||
|
||||
if (viewType == "Right") {
|
||||
if (viewType == ProjDirection::Right) {
|
||||
newCS = anchorCS.Rotated(gUpAxis, angle);
|
||||
projDir = dir2vec(newCS.Direction());
|
||||
rotVec = dir2vec(newCS.XDirection());
|
||||
}
|
||||
else if (viewType == "Left") {
|
||||
else if (viewType == ProjDirection::Left) {
|
||||
newCS = anchorCS.Rotated(gUpAxis, -angle);
|
||||
projDir = dir2vec(newCS.Direction());
|
||||
rotVec = dir2vec(newCS.XDirection());
|
||||
}
|
||||
else if (viewType == "Top") {
|
||||
else if (viewType == ProjDirection::Top) {
|
||||
projDir = dir2vec(gYDir);
|
||||
rotVec = dir2vec(gXDir);
|
||||
}
|
||||
else if (viewType == "Bottom") {
|
||||
else if (viewType == ProjDirection::Bottom) {
|
||||
projDir = dir2vec(gYDir.Reversed());
|
||||
rotVec = dir2vec(gXDir);
|
||||
}
|
||||
else if (viewType == "Rear") {
|
||||
else if (viewType == ProjDirection::Rear) {
|
||||
projDir = dir2vec(gDir.Reversed());
|
||||
rotVec = dir2vec(gXDir.Reversed());
|
||||
}
|
||||
else if (viewType == "FrontTopLeft") {
|
||||
else if (viewType == ProjDirection::FrontTopLeft) {
|
||||
gp_Dir newDir = gp_Dir(gp_Vec(gDir) - gp_Vec(gXDir) + gp_Vec(gYDir));
|
||||
projDir = dir2vec(newDir);
|
||||
gp_Dir newXDir = gp_Dir(gp_Vec(gXDir) + gp_Vec(gDir));
|
||||
rotVec = dir2vec(newXDir);
|
||||
}
|
||||
else if (viewType == "FrontTopRight") {
|
||||
else if (viewType == ProjDirection::FrontTopRight) {
|
||||
gp_Dir newDir = gp_Dir(gp_Vec(gDir) + gp_Vec(gXDir) + gp_Vec(gYDir));
|
||||
projDir = dir2vec(newDir);
|
||||
gp_Dir newXDir = gp_Dir(gp_Vec(gXDir) - gp_Vec(gDir));
|
||||
rotVec = dir2vec(newXDir);
|
||||
}
|
||||
else if (viewType == "FrontBottomLeft") {
|
||||
else if (viewType == ProjDirection::FrontBottomLeft) {
|
||||
gp_Dir newDir = gp_Dir(gp_Vec(gDir) - gp_Vec(gXDir) - gp_Vec(gYDir));
|
||||
projDir = dir2vec(newDir);
|
||||
gp_Dir newXDir = gp_Dir(gp_Vec(gXDir) + gp_Vec(gDir));
|
||||
rotVec = dir2vec(newXDir);
|
||||
}
|
||||
else if (viewType == "FrontBottomRight") {
|
||||
else if (viewType == ProjDirection::FrontBottomRight) {
|
||||
gp_Dir newDir = gp_Dir(gp_Vec(gDir) + gp_Vec(gXDir) - gp_Vec(gYDir));
|
||||
projDir = dir2vec(newDir);
|
||||
gp_Dir newXDir = gp_Dir(gp_Vec(gXDir) - gp_Vec(gDir));
|
||||
rotVec = dir2vec(newXDir);
|
||||
}
|
||||
else {
|
||||
// not one of the standard view directions, so complain and use the values for "Front"
|
||||
Base::Console().Error("DrawViewPart - %s unknown projection: %s\n", getNameInDocument(),
|
||||
viewType.c_str());
|
||||
Base::Vector3d dirAnch = Direction.getValue();
|
||||
Base::Vector3d rotAnch = getXDirection();
|
||||
return std::make_pair(dirAnch, rotAnch);
|
||||
}
|
||||
|
||||
return std::make_pair(projDir, rotVec);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user