diff --git a/src/Mod/TechDraw/App/DrawProjGroup.cpp b/src/Mod/TechDraw/App/DrawProjGroup.cpp index 6cc158927e..2b491aff97 100644 --- a/src/Mod/TechDraw/App/DrawProjGroup.cpp +++ b/src/Mod/TechDraw/App/DrawProjGroup.cpp @@ -561,12 +561,11 @@ int DrawProjGroup::purgeProjections() std::pair DrawProjGroup::getDirsFromFront(DrawProjGroupItem* view) { - std::pair result; - std::string viewType = view->Type.getValueAsString(); + ProjDirection viewType = static_cast(view->Type.getValue()); return getDirsFromFront(viewType); } -std::pair DrawProjGroup::getDirsFromFront(std::string viewType) +std::pair DrawProjGroup::getDirsFromFront(ProjDirection viewType) { // Base::Console().Message("DPG::getDirsFromFront(%s)\n", viewType.c_str()); std::pair result; @@ -1106,77 +1105,26 @@ void DrawProjGroup::updateSecondaryDirs() Base::Vector3d anchDir = anchor->Direction.getValue(); Base::Vector3d anchRot = anchor->getXDirection(); - std::map> saveVals; - std::string key; + std::map> saveVals; std::pair data; for (auto& docObj : Views.getValues()) { - std::pair newDirs; - std::string pic; DrawProjGroupItem* v = static_cast(docObj); - ProjItemType t = static_cast(v->Type.getValue()); - switch (t) { - case Front: - data.first = anchDir; - data.second = anchRot; - key = "Front"; - saveVals[key] = data; - break; - case Rear: - key = "Rear"; - newDirs = getDirsFromFront(key); - saveVals[key] = newDirs; - break; - case Left: - key = "Left"; - newDirs = getDirsFromFront(key); - saveVals[key] = newDirs; - break; - case Right: - key = "Right"; - newDirs = getDirsFromFront(key); - saveVals[key] = newDirs; - break; - case Top: - key = "Top"; - newDirs = getDirsFromFront(key); - saveVals[key] = newDirs; - break; - case Bottom: - key = "Bottom"; - newDirs = getDirsFromFront(key); - saveVals[key] = newDirs; - break; - case FrontTopLeft: - key = "FrontTopLeft"; - newDirs = getDirsFromFront(key); - saveVals[key] = newDirs; - break; - case FrontTopRight: - key = "FrontTopRight"; - newDirs = getDirsFromFront(key); - saveVals[key] = newDirs; - break; - case FrontBottomLeft: - key = "FrontBottomLeft"; - newDirs = getDirsFromFront(key); - saveVals[key] = newDirs; - break; - case FrontBottomRight: - key = "FrontBottomRight"; - newDirs = getDirsFromFront(key); - saveVals[key] = newDirs; - break; - default: { - //TARFU invalid secondary type - Base::Console().Message( - "ERROR - DPG::updateSecondaryDirs - invalid projection type\n"); - } + ProjDirection t = static_cast(v->Type.getValue()); + + if (t == ProjDirection::Front) { + data.first = anchDir; + data.second = anchRot; + saveVals[ProjDirection::Front] = data; + } + else { + std::pair newDirs = getDirsFromFront(t); + saveVals[t] = newDirs; } } for (auto& docObj : Views.getValues()) { DrawProjGroupItem* v = static_cast(docObj); - std::string type = v->Type.getValueAsString(); + ProjDirection type = static_cast(v->Type.getValue()); data = saveVals[type]; v->Direction.setValue(data.first); v->Direction.purgeTouched(); @@ -1186,31 +1134,20 @@ void DrawProjGroup::updateSecondaryDirs() recomputeChildren(); } -void DrawProjGroup::rotate(const std::string& rotationdirection) +void DrawProjGroup::rotate(const RotationMotion& motion) { - std::pair 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 - - DrawProjGroupItem* anchor = getAnchor(); - anchor->Direction.setValue(newDirs.first); - anchor->XDirection.setValue(newDirs.second); - + getAnchor()->rotate(motion); updateSecondaryDirs(); } -void DrawProjGroup::spin(const std::string& spindirection) +// TODO: should these functions identical to those +// in DrawViewPart be moved to DrawView? +void DrawProjGroup::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); diff --git a/src/Mod/TechDraw/App/DrawProjGroup.h b/src/Mod/TechDraw/App/DrawProjGroup.h index 05c0934cc8..a10935a51c 100644 --- a/src/Mod/TechDraw/App/DrawProjGroup.h +++ b/src/Mod/TechDraw/App/DrawProjGroup.h @@ -43,6 +43,9 @@ namespace TechDraw const int MAXPROJECTIONCOUNT = 10; class DrawProjGroupItem; +enum class ProjDirection : int; +enum class SpinDirection : int; +enum class RotationMotion : int; /** * Class super-container for managing a collection of DrawProjGroupItem @@ -123,12 +126,12 @@ public: Base::Vector3d getAnchorDirection(); TechDraw::DrawProjGroupItem* getAnchor(); std::pair getDirsFromFront(DrawProjGroupItem* view); - std::pair getDirsFromFront(std::string viewType); + std::pair getDirsFromFront(TechDraw::ProjDirection viewType); void updateSecondaryDirs(); - void rotate(const std::string &rotationdirection); - void spin(const std::string &spindirection); + void rotate(const TechDraw::RotationMotion& motion); + void spin(const TechDraw::SpinDirection& spindirection); void spin(double angle); void dumpISO(const char * title); diff --git a/src/Mod/TechDraw/App/DrawProjGroupItem.h b/src/Mod/TechDraw/App/DrawProjGroupItem.h index ea115e0755..a0199350e8 100644 --- a/src/Mod/TechDraw/App/DrawProjGroupItem.h +++ b/src/Mod/TechDraw/App/DrawProjGroupItem.h @@ -35,17 +35,6 @@ namespace TechDraw { -enum ProjItemType{ Front, - Left, - Right, - Rear, - Top, - Bottom, - FrontTopLeft, - FrontTopRight, - FrontBottomLeft, - FrontBottomRight }; - class DrawProjGroup; class TechDrawExport DrawProjGroupItem : public TechDraw::DrawViewPart diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index 987f37b84a..1dfc2af7ed 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -1276,29 +1276,29 @@ Base::Vector3d DrawViewPart::getXDirection() const } -void DrawViewPart::rotate(const std::string& rotationdirection) +void DrawViewPart::rotate(const RotationMotion& motion) { std::pair 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 DrawViewPart::getDirsFromFront(std::string viewType) +std::pair DrawViewPart::getDirsFromFront(ProjDirection viewType) { // Base::Console().Message("DVP::getDirsFromFront(%s)\n", viewType.c_str()); std::pair result; @@ -1335,60 +1335,52 @@ std::pair 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); } diff --git a/src/Mod/TechDraw/App/DrawViewPart.h b/src/Mod/TechDraw/App/DrawViewPart.h index e5d772097e..7423e1a73a 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.h +++ b/src/Mod/TechDraw/App/DrawViewPart.h @@ -77,9 +77,34 @@ class GeomFormat; namespace TechDraw { - class DrawViewSection; + +enum class ProjDirection { + Front, + Left, + Right, + Rear, + Top, + Bottom, + FrontTopLeft, + FrontTopRight, + FrontBottomLeft, + FrontBottomRight +}; + +enum class RotationMotion { + Left, + Right, + Up, + Down +}; + +enum class SpinDirection { + CW, + CCW +}; + class TechDrawExport DrawViewPart: public DrawView, public CosmeticExtension { PROPERTY_HEADER_WITH_EXTENSIONS(TechDraw::DrawViewPart); @@ -172,10 +197,10 @@ public: virtual Base::Vector3d getLegacyX(const Base::Vector3d& pt, const Base::Vector3d& axis, const bool flip = true) const; - void rotate(const std::string& rotationdirection); - void spin(const std::string& spindirection); + void rotate(const RotationMotion& motion); + void spin(const SpinDirection& spindirection); void spin(double val); - std::pair getDirsFromFront(std::string viewType); + std::pair getDirsFromFront(ProjDirection viewType); Base::Vector3d dir2vec(gp_Dir d); gp_Ax2 localVectorToCS(const Base::Vector3d localUnit) const; diff --git a/src/Mod/TechDraw/Gui/TaskProjGroup.cpp b/src/Mod/TechDraw/Gui/TaskProjGroup.cpp index fd1e7d9873..21d60f6dac 100644 --- a/src/Mod/TechDraw/Gui/TaskProjGroup.cpp +++ b/src/Mod/TechDraw/Gui/TaskProjGroup.cpp @@ -444,12 +444,12 @@ void TaskProjGroup::rotateButtonClicked() if (multiView) { //change Front View Dir by 90 - if (clicked == ui->butTopRotate) multiView->rotate("Up"); - else if (clicked == ui->butDownRotate) multiView->rotate("Down"); - else if (clicked == ui->butRightRotate) multiView->rotate("Right"); - else if (clicked == ui->butLeftRotate) multiView->rotate("Left"); - else if (clicked == ui->butCWRotate) multiView->spin("CW"); - else if (clicked == ui->butCCWRotate) multiView->spin("CCW"); + if (clicked == ui->butTopRotate) multiView->rotate(RotationMotion::Up); + else if (clicked == ui->butDownRotate) multiView->rotate(RotationMotion::Down); + else if (clicked == ui->butRightRotate) multiView->rotate(RotationMotion::Right); + else if (clicked == ui->butLeftRotate) multiView->rotate(RotationMotion::Left); + else if (clicked == ui->butCWRotate) multiView->spin(SpinDirection::CW); + else if (clicked == ui->butCCWRotate) multiView->spin(SpinDirection::CCW); else if (clicked == ui->butFront) { multiView->getAnchor()->Direction.setValue(Base::Vector3d(0.0, -1.0, 0.0)); multiView->getAnchor()->RotationVector.setValue(Base::Vector3d(1.0, 0.0, 0.0)); @@ -466,12 +466,12 @@ void TaskProjGroup::rotateButtonClicked() } else { auto* viewPart = static_cast(view); - if (clicked == ui->butTopRotate) viewPart->rotate("Up"); - else if (clicked == ui->butDownRotate) viewPart->rotate("Down"); - else if (clicked == ui->butRightRotate) viewPart->rotate("Right"); - else if (clicked == ui->butLeftRotate) viewPart->rotate("Left"); - else if (clicked == ui->butCWRotate) viewPart->spin("CW"); - else if (clicked == ui->butCCWRotate) viewPart->spin("CCW"); + if (clicked == ui->butTopRotate) viewPart->rotate(RotationMotion::Up); + else if (clicked == ui->butDownRotate) viewPart->rotate(RotationMotion::Down); + else if (clicked == ui->butRightRotate) viewPart->rotate(RotationMotion::Right); + else if (clicked == ui->butLeftRotate) viewPart->rotate(RotationMotion::Left); + else if (clicked == ui->butCWRotate) viewPart->spin(SpinDirection::CW); + else if (clicked == ui->butCCWRotate) viewPart->spin(SpinDirection::CCW); else if (clicked == ui->butFront) { viewPart->Direction.setValue(Base::Vector3d(0.0,-1.0,0.0)); viewPart->XDirection.setValue(Base::Vector3d(1.0, 0.0, 0.0));