From 7edfd902a3a775f7c48887ab2176282e7a0c9f83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Br=C3=A6strup=20Sayoc?= Date: Mon, 31 Jan 2022 13:46:46 +0100 Subject: [PATCH] Improve code simplicity/readability --- src/Mod/TechDraw/App/DrawProjGroup.cpp | 65 +++++--------------------- src/Mod/TechDraw/App/DrawProjGroup.h | 8 +--- src/Mod/TechDraw/Gui/TaskProjGroup.cpp | 20 +++----- 3 files changed, 21 insertions(+), 72 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawProjGroup.cpp b/src/Mod/TechDraw/App/DrawProjGroup.cpp index 9dd37ac7c1..ee2d7d6b6f 100644 --- a/src/Mod/TechDraw/App/DrawProjGroup.cpp +++ b/src/Mod/TechDraw/App/DrawProjGroup.cpp @@ -508,7 +508,7 @@ int DrawProjGroup::removeProjection(const char *viewProjType) } return -1; -} +} //removes all DPGI - used when deleting DPG int DrawProjGroup::purgeProjections() @@ -1231,73 +1231,32 @@ void DrawProjGroup::updateSecondaryDirs() recomputeChildren(); } -void DrawProjGroup::rotateRight() -{ -//Front -> Right -> Rear -> Left -> Front +void DrawProjGroup::rotate(const std::string &rotationdirection) { std::pair newDirs; - newDirs = getDirsFromFront("Left"); + 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); + updateSecondaryDirs(); } -void DrawProjGroup::rotateLeft() +void DrawProjGroup::spin(const std::string &spindirection) { -//Front -> Left -> Rear -> Right -> Front - std::pair newDirs; - newDirs = getDirsFromFront("Right"); - DrawProjGroupItem* anchor = getAnchor(); - anchor->Direction.setValue(newDirs.first); - anchor->XDirection.setValue(newDirs.second); - updateSecondaryDirs(); -} + double angle; + if(spindirection == "CW") angle = M_PI / 2.0; // Top -> Right -> Bottom -> Left -> Top + if(spindirection == "CCW") angle = - M_PI / 2.0; // Top -> Left -> Bottom -> Right -> Top -void DrawProjGroup::rotateUp() -{ -//Front -> Top -> Rear -> Bottom -> Front - std::pair newDirs; - newDirs = getDirsFromFront("Bottom"); DrawProjGroupItem* anchor = getAnchor(); - anchor->Direction.setValue(newDirs.first); - anchor->XDirection.setValue(newDirs.second); - updateSecondaryDirs(); -} - -void DrawProjGroup::rotateDown() -{ -//Front -> Bottom -> Rear -> Top -> Front - std::pair newDirs; - newDirs = getDirsFromFront("Top"); - DrawProjGroupItem* anchor = getAnchor(); - anchor->Direction.setValue(newDirs.first); - anchor->XDirection.setValue(newDirs.second); - updateSecondaryDirs(); -} - -void DrawProjGroup::spinCW() -{ -//Top -> Right -> Bottom -> Left -> Top - DrawProjGroupItem* anchor = getAnchor(); - double angle = M_PI / 2.0; Base::Vector3d org(0.0,0.0,0.0); Base::Vector3d curRot = anchor->getXDirection(); Base::Vector3d curDir = anchor->Direction.getValue(); Base::Vector3d newRot = DrawUtil::vecRotate(curRot,angle,curDir,org); anchor->XDirection.setValue(newRot); - updateSecondaryDirs(); -} - -void DrawProjGroup::spinCCW() -{ -//Top -> Left -> Bottom -> Right -> Top - DrawProjGroupItem* anchor = getAnchor(); - double angle = M_PI / 2.0; - Base::Vector3d org(0.0,0.0,0.0); - Base::Vector3d curRot = anchor->getXDirection(); - Base::Vector3d curDir = anchor->Direction.getValue(); - Base::Vector3d newRot = DrawUtil::vecRotate(curRot,-angle,curDir,org); - anchor->XDirection.setValue(newRot); updateSecondaryDirs(); } diff --git a/src/Mod/TechDraw/App/DrawProjGroup.h b/src/Mod/TechDraw/App/DrawProjGroup.h index f3a885187f..1f870e9dc2 100644 --- a/src/Mod/TechDraw/App/DrawProjGroup.h +++ b/src/Mod/TechDraw/App/DrawProjGroup.h @@ -124,12 +124,8 @@ public: void updateSecondaryDirs(); - void rotateRight(void); - void rotateLeft(void); - void rotateUp(void); - void rotateDown(void); - void spinCW(void); - void spinCCW(void); + void rotate(const std::string &rotationdirection); + void spin(const std::string &spindirection); void dumpISO(const char * title); std::vector getViewsAsDPGI(); diff --git a/src/Mod/TechDraw/Gui/TaskProjGroup.cpp b/src/Mod/TechDraw/Gui/TaskProjGroup.cpp index bf6fa0cd1e..c2508f13d8 100644 --- a/src/Mod/TechDraw/Gui/TaskProjGroup.cpp +++ b/src/Mod/TechDraw/Gui/TaskProjGroup.cpp @@ -214,20 +214,14 @@ void TaskProjGroup::rotateButtonClicked(void) if ( multiView && ui ) { const QObject *clicked = sender(); + //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 ) { //change Front View Dir by 90 - multiView->rotateUp(); - } else if ( clicked == ui->butDownRotate) { - multiView->rotateDown(); - } else if ( clicked == ui->butRightRotate) { - multiView->rotateRight(); - } else if ( clicked == ui->butLeftRotate) { - multiView->rotateLeft(); - } else if ( clicked == ui->butCWRotate ) { - multiView->spinCW(); - } else if ( clicked == ui->butCCWRotate) { - multiView->spinCCW(); - } setUiPrimary(); } }