From 17b69c7c3a29fe8cba46a0fa73746ecc5e903d59 Mon Sep 17 00:00:00 2001 From: WandererFan Date: Tue, 13 Jun 2017 10:34:57 -0400 Subject: [PATCH] Replace DPG table lookup logic with calculations DPG used a pair of large tables to determine view direction and rotation vector when subject was rotated and spun. There were many errors in the tables that needed manual checking to correct. The new version uses calculations on a virtual glass cube to find view direction and rotation vector. --- src/Mod/TechDraw/App/Cube.cpp | 912 ++++++++------------- src/Mod/TechDraw/App/Cube.h | 120 +-- src/Mod/TechDraw/App/DrawProjGroup.cpp | 204 +---- src/Mod/TechDraw/App/DrawProjGroup.h | 14 +- src/Mod/TechDraw/App/DrawProjGroupItem.cpp | 4 +- src/Mod/TechDraw/Gui/TaskProjGroup.cpp | 31 +- src/Mod/TechDraw/Gui/TaskProjGroup.ui | 4 +- 7 files changed, 423 insertions(+), 866 deletions(-) diff --git a/src/Mod/TechDraw/App/Cube.cpp b/src/Mod/TechDraw/App/Cube.cpp index df65fbbe0f..bfe11309ff 100644 --- a/src/Mod/TechDraw/App/Cube.cpp +++ b/src/Mod/TechDraw/App/Cube.cpp @@ -33,17 +33,26 @@ using namespace TechDraw; -const std::map Cube::m_viewToStdDir = { - { "A", Base::Vector3d(0, -1, 0) }, //front - { "B", Base::Vector3d(0, 0, 1) }, //top - { "C", Base::Vector3d(-1, 0, 0) }, //left - { "D", Base::Vector3d(1, 0, 0) }, //right - { "E", Base::Vector3d(0, 0, -1) }, //bottom - { "F", Base::Vector3d(0, 1, 0) }, //rear - { "G", Base::Vector3d(-1,-1,1) }, //FTL - { "H", Base::Vector3d(1, -1, 1) }, //FTR - { "I", Base::Vector3d(1, -1, -1) }, //FBR - { "J", Base::Vector3d(-1, -1, -1) } }; //FBL +//default starting dirs & rots +const std::map Cube::m_viewDefault = { + { "Front", Base::Vector3d(0, -1, 0) }, //front + { "Rear", Base::Vector3d(0, 1, 0) }, //rear + { "Right", Base::Vector3d(1, 0, 0) }, //right + { "Left", Base::Vector3d(-1, 0, 0) }, //left + { "Top", Base::Vector3d(0, 0, 1) }, //top + { "Bottom", Base::Vector3d(0, 0, -1) }, //bottom + }; + +const std::map Cube::m_rotDefault = { + { "Front", Base::Vector3d(1, 0, 0) }, //front RightDir + { "Rear", Base::Vector3d(-1, 0, 0) }, //rear LeftDir + { "Right", Base::Vector3d(0, -1, 0) }, //right FrontDir + { "Left", Base::Vector3d(0, 1, 0) }, //left RearDir + { "Top", Base::Vector3d(1, 0, 0) }, //top RightDir + { "Bottom", Base::Vector3d(1, 0, 0) }, //bottom RightDir + }; + +const Base::Vector3d _Y(0,1,0); Cube::Cube(void) @@ -54,242 +63,221 @@ Cube::~Cube(void) { } -// D/C/A/F/B/E/FBL/FBR/FTL/FTR +void Cube::initialize() +{ + m_mapCubeDir = m_viewDefault; + m_mapCubeRot = m_rotDefault; +} + +// left,right,front,back,top,bottom void Cube::initialize(Base::Vector3d r, Base::Vector3d rr, Base::Vector3d l, Base::Vector3d lr, Base::Vector3d f, Base::Vector3d fr, Base::Vector3d k, Base::Vector3d kr, //k for bacK (rear) - Base::Vector3d t, Base::Vector3d tr, Base::Vector3d b, Base::Vector3d br, - Base::Vector3d fbl, Base::Vector3d fblr, Base::Vector3d fbr, Base::Vector3d fbrr, - Base::Vector3d ftl, Base::Vector3d ftlr, Base::Vector3d ftr, Base::Vector3d ftrr) + Base::Vector3d t, Base::Vector3d tr, Base::Vector3d b, Base::Vector3d br) { - //these frames are only used at DPGI creation time? - m_mapFrameDir.clear(); - m_mapFrameDir.insert(std::map::value_type("Bottom", b)); - m_mapFrameDir.insert(std::map::value_type("Front" , f)); - m_mapFrameDir.insert(std::map::value_type("Left" , l)); - m_mapFrameDir.insert(std::map::value_type("Rear" , k)); - m_mapFrameDir.insert(std::map::value_type("Right" , r)); - m_mapFrameDir.insert(std::map::value_type("Top" , t)); - m_mapFrameDir.insert(std::map::value_type("FrontBottomLeft" , fbl)); - m_mapFrameDir.insert(std::map::value_type("FrontBottomRight", fbr)); - m_mapFrameDir.insert(std::map::value_type("FrontTopLeft" , ftl)); - m_mapFrameDir.insert(std::map::value_type("FrontTopRight" , ftr)); + m_mapCubeDir.clear(); + m_mapCubeDir.insert(std::map::value_type("Bottom", b)); + m_mapCubeDir.insert(std::map::value_type("Front" , f)); + m_mapCubeDir.insert(std::map::value_type("Left" , l)); + m_mapCubeDir.insert(std::map::value_type("Rear" , k)); + m_mapCubeDir.insert(std::map::value_type("Right" , r)); + m_mapCubeDir.insert(std::map::value_type("Top" , t)); - m_mapFrameRot.clear(); - m_mapFrameRot.insert(std::map::value_type("Bottom", br)); - m_mapFrameRot.insert(std::map::value_type("Front" , fr)); - m_mapFrameRot.insert(std::map::value_type("Left" , lr)); - m_mapFrameRot.insert(std::map::value_type("Rear" , kr)); - m_mapFrameRot.insert(std::map::value_type("Right" , rr)); - m_mapFrameRot.insert(std::map::value_type("Top" , tr)); - m_mapFrameRot.insert(std::map::value_type("FrontTopRight" , ftrr)); - m_mapFrameRot.insert(std::map::value_type("FrontTopLeft" , ftlr)); - m_mapFrameRot.insert(std::map::value_type("FrontBottomLeft" , fblr)); - m_mapFrameRot.insert(std::map::value_type("FrontBottomRight", fbrr)); - - m_conTab.initialize(); //all possible configs of ABCDEF in bottom/front/left/(k)rear/right/top order + m_mapCubeRot.clear(); + m_mapCubeRot.insert(std::map::value_type("Bottom", br)); + m_mapCubeRot.insert(std::map::value_type("Front" , fr)); + m_mapCubeRot.insert(std::map::value_type("Left" , lr)); + m_mapCubeRot.insert(std::map::value_type("Rear" , kr)); + m_mapCubeRot.insert(std::map::value_type("Right" , rr)); + m_mapCubeRot.insert(std::map::value_type("Top" , tr)); } -void Cube::rotateUp() -{ - //Front -> Top -> Rear -> Bottom -> Front??? - saveSwap("Front"); - shiftFrame("Bottom", "Front"); - shiftFrame("Rear" , "Bottom"); - shiftFrame("Top" , "Rear"); - restoreSwap("Top"); +// rotate/spin the subject inside the glass cube +// effectively, rotate/spin the cube in reverse of the apparent subject movement - updateIsoDirs(); //calculatge iso directions from ortho dirs - updateRotsToConfig(getCurrConfig()); //update rotations for ortho views from config table +//TODO: there is a problem with calculaion of view rotation vector when the axis of rotation is +// +/-Y. There is hack code here to handle it, but there should be a more elegant solution + +// subject CW about Right +void Cube::rotateUp(double angle) +{ + //Front -> Top -> Rear -> Bottom -> Front + Base::Vector3d axis = getRight(); + std::map newDirs; + for (auto& d: m_mapCubeDir) { + Base::Vector3d v = rodrigues(d.second,angle,axis); + newDirs.insert(std::map::value_type(d.first, v)); + } + + std::map newRots; + for (auto& r: m_mapCubeRot) { + Base::Vector3d v = rodrigues(r.second,-angle,axis); + newRots.insert(std::map::value_type(r.first, v)); + } + + double flipper = 1.0; + if (DrawUtil::checkParallel(axis,_Y)) { + flipper = -flipper; + newRots["Right"] = newRots["Right"] * flipper; + newRots["Left"] = newRots["Left"] * flipper; + } + + m_mapCubeDir = newDirs; + m_mapCubeRot = newRots; } -void Cube::rotateDown() +// CCW about Right +void Cube::rotateDown(double angle) { - //Front -> Bottom -> Rear -> Top -> Front??? - saveSwap("Front"); - shiftFrame("Top" , "Front"); - shiftFrame("Rear" , "Top"); - shiftFrame("Bottom" , "Rear"); - restoreSwap("Bottom"); - - updateIsoDirs(); - updateRotsToConfig(getCurrConfig()); -} - -void Cube::rotateRight() -{ - //Front -> Right -> Rear -> Left -> Front??? - saveSwap("Front"); - shiftFrame("Left" , "Front"); - shiftFrame("Rear" , "Left"); - shiftFrame("Right" , "Rear"); - restoreSwap("Right"); - - updateIsoDirs(); - updateRotsToConfig(getCurrConfig()); -} - -void Cube::rotateLeft() -{ - //Front -> Left -> Rear -> Right -> Front??? - saveSwap("Front"); - shiftFrame("Right", "Front"); - shiftFrame("Rear" , "Right"); - shiftFrame("Left" , "Rear"); - restoreSwap("Left"); - - updateIsoDirs(); - updateRotsToConfig(getCurrConfig()); -} - -void Cube::spinCCW() -{ - //Right -> Top -> Left -> Bottom -> Right??? - saveSwap("Right"); - shiftFrame("Bottom", "Right"); - shiftFrame("Left" , "Bottom"); - shiftFrame("Top" , "Left"); - restoreSwap("Top"); - - updateIsoDirs(); - updateRotsToConfig(getCurrConfig()); -} - -void Cube::spinCW() -{ - //Left -> Top -> Right -> Bottom -> Left??? - saveSwap("Left"); - shiftFrame("Bottom", "Left"); - shiftFrame("Right" , "Bottom"); - shiftFrame("Top", "Right"); - restoreSwap("Top"); - - updateIsoDirs(); - updateRotsToConfig(getCurrConfig()); -} - -void Cube::updateIsoDirs() -{ - Base::Vector3d flb = getFront() + getLeft() + getBottom(); - Base::Vector3d frb = getFront() + getRight() + getBottom(); - Base::Vector3d flt = getFront() + getLeft() + getTop(); - Base::Vector3d frt = getFront() + getRight() + getTop(); - m_mapFrameDir.at("FrontBottomLeft") = flb; - m_mapFrameDir.at("FrontBottomRight") = frb; - m_mapFrameDir.at("FrontTopLeft") = flt; - m_mapFrameDir.at("FrontTopRight") = frt; -} - -std::string Cube::dirToView(Base::Vector3d v) -{ - std::string result; - for (auto& i: m_viewToStdDir) { - if (i.second == v) { - result = i.first; - break; - } + //Front -> Bottom -> Rear -> Top -> Front + Base::Vector3d axis = getRight(); + std::map newDirs; + for (auto& d: m_mapCubeDir) { + Base::Vector3d v = rodrigues(d.second,-angle,axis); + newDirs.insert(std::map::value_type(d.first, v)); } - return result; -} -void Cube::updateDirsToConfig(std::string cfg) -{ - Base::Vector3d boardValue = m_conTab.getDirItem(cfg,"Front"); - m_mapFrameDir.at("Front") = boardValue; - boardValue = m_conTab.getDirItem(cfg,"Rear"); - m_mapFrameDir.at("Rear") = boardValue; - boardValue = m_conTab.getDirItem(cfg,"Left"); - m_mapFrameDir.at("Left") = boardValue; - boardValue = m_conTab.getDirItem(cfg,"Right"); - m_mapFrameDir.at("Right") = boardValue; - boardValue = m_conTab.getDirItem(cfg,"Top"); - m_mapFrameDir.at("Top") = boardValue; - boardValue = m_conTab.getDirItem(cfg,"Bottom"); - m_mapFrameDir.at("Bottom") = boardValue; -} + std::map newRots; + for (auto& r: m_mapCubeRot) { + Base::Vector3d v = rodrigues(r.second,angle,axis); + newRots.insert(std::map::value_type(r.first, v)); + } -void Cube::updateRotsToConfig(std::string cfg) -{ - Base::Vector3d boardValue = m_conTab.getRotItem(cfg,"Front"); - m_mapFrameRot.at("Front") = boardValue; - boardValue = m_conTab.getRotItem(cfg,"Rear"); - m_mapFrameRot.at("Rear") = boardValue; - boardValue = m_conTab.getRotItem(cfg,"Left"); - m_mapFrameRot.at("Left") = boardValue; - boardValue = m_conTab.getRotItem(cfg,"Right"); - m_mapFrameRot.at("Right") = boardValue; - boardValue = m_conTab.getRotItem(cfg,"Top"); - m_mapFrameRot.at("Top") = boardValue; - boardValue = m_conTab.getRotItem(cfg,"Bottom"); - m_mapFrameRot.at("Bottom") = boardValue; -} + double flipper = 1.0; + if (DrawUtil::checkParallel(axis,_Y)) { + flipper = -flipper; + newRots["Right"] = newRots["Right"] * flipper; + newRots["Left"] = newRots["Left"] * flipper; + } -bool Cube::validateBoard(std::string cfg) + m_mapCubeDir = newDirs; + m_mapCubeRot = newRots; +} + +// CCW about Top +void Cube::rotateRight(double angle) { - bool result = true; - //check that Dirs match - std::string strCfgDir; - std::string strBoardDir; - for (auto& f: m_mapFrameDir) { - Base::Vector3d boardValue = f.second; - strBoardDir += dirToView(boardValue); + //Front -> Right -> Rear -> Left -> Front + Base::Vector3d axis = getTop(); + std::map newDirs; + for (auto& d: m_mapCubeDir) { + Base::Vector3d v = rodrigues(d.second,-angle,axis); + newDirs.insert(std::map::value_type(d.first, v)); + } + + std::map newRots; + for (auto& r: m_mapCubeRot) { + Base::Vector3d v = rodrigues(r.second,angle,axis); + newRots.insert(std::map::value_type(r.first, v)); + } + + double flipper = 1.0; + if (DrawUtil::checkParallel(axis,_Y)) { + flipper = -flipper; + newRots["Top"] = newRots["Top"] * flipper; + newRots["Bottom"] = newRots["Bottom"] * flipper; + newRots["Left"] = newDirs["Front"]; + newRots["Right"] = newRots["Left"] * -1.0; + } + newRots["Front"] = newRots["Top"]; + newRots["Rear"] = newRots["Front"] * -1.0; + + m_mapCubeDir = newDirs; + m_mapCubeRot = newRots; +} + +// CW about Top +void Cube::rotateLeft(double angle) +{ + //Front -> Left -> Rear -> Right -> Front + Base::Vector3d axis = getTop(); + std::map newDirs; + for (auto& d: m_mapCubeDir) { + Base::Vector3d v = rodrigues(d.second,angle,axis); + newDirs.insert(std::map::value_type(d.first, v)); + } + + std::map newRots; + for (auto& r: m_mapCubeRot) { + Base::Vector3d v = rodrigues(r.second,-angle,axis); + newRots.insert(std::map::value_type(r.first, v)); } - strCfgDir = m_conTab.getCfgDirStr(cfg); - if (strCfgDir != strBoardDir) { - result = false; - return result; + double flipper = 1.0; + if (DrawUtil::checkParallel(axis,_Y)) { + flipper = -flipper; + newRots["Top"] = newRots["Top"] * flipper; + newRots["Bottom"] = newRots["Bottom"] * flipper; + newRots["Left"] = newDirs["Front"]; + newRots["Right"] = newRots["Left"] * -1.0; } - //check that Rots match - std::string strCfgRot; - std::string strBoardRot; - - for (auto& f: m_mapFrameRot) { - Base::Vector3d boardValue = f.second; - strBoardRot += dirToView(boardValue); + newRots["Front"] = newRots["Top"]; + newRots["Rear"] = newRots["Front"] * -1.0; + + m_mapCubeDir = newDirs; + m_mapCubeRot = newRots; +} + +// CCW about Front +void Cube::spinCCW(double angle) +{ + Base::Vector3d axis = getFront(); + std::map newDirs; + for (auto& d: m_mapCubeDir) { + Base::Vector3d v = rodrigues(d.second,-angle,axis); + newDirs.insert(std::map::value_type(d.first, v)); } - - strCfgRot = m_conTab.getCfgRotStr(cfg); - if (strCfgRot != strBoardRot) { - result = false; + std::map newRots; + for (auto& r: m_mapCubeRot) { + Base::Vector3d v = rodrigues(r.second,angle,axis); + newRots.insert(std::map::value_type(r.first, v)); } - return result; -} -//get the current configuration on the board -std::string Cube::getCurrConfig(void) + double flipper = 1.0; + if (DrawUtil::checkParallel(axis,_Y)) { + flipper = -flipper; + } + newRots["Front"] = newRots["Front"] * flipper; + newRots["Rear"] = newRots["Rear"] * flipper; + newRots["Top"] = newRots["Front"]; + newRots["Bottom"] = newRots["Front"]; + + m_mapCubeDir = newDirs; + m_mapCubeRot = newRots; +} + +// CW about Front +void Cube::spinCW(double angle) { - Base::Vector3d boardValue = m_mapFrameDir.at("Front"); //what's in the bucket "Front" - std::string viewFront = dirToView(boardValue); - boardValue = m_mapFrameDir.at("Right"); - std::string viewRight = dirToView(boardValue); - std::string result = viewFront + viewRight; - return result; -} + //Right -> Bottom -> Left -> Top -> Right + Base::Vector3d axis = getFront(); + std::map newDirs; + for (auto& d: m_mapCubeDir) { + Base::Vector3d v = rodrigues(d.second,angle,axis); + newDirs.insert(std::map::value_type(d.first, v)); + } -void Cube::saveSwap(std::string frame) -{ - m_swapDir = m_mapFrameDir.at(frame); - m_swapRot = m_mapFrameRot.at(frame); -} + std::map newRots; + for (auto& r: m_mapCubeRot) { + Base::Vector3d v = rodrigues(r.second,-angle,axis); + newRots.insert(std::map::value_type(r.first, v)); + } + double flipper = 1.0; + if (DrawUtil::checkParallel(axis,_Y)) { + flipper = -flipper; + newRots["Front"] = newRots["Front"] * flipper; + newRots["Rear"] = newRots["Rear"] * flipper; + } + newRots["Top"] = newRots["Front"]; + newRots["Bottom"] = newRots["Front"]; -void Cube::restoreSwap(std::string frame) -{ - m_mapFrameDir.at(frame) = m_swapDir; - m_mapFrameRot.at(frame) = m_swapRot; -} + m_mapCubeDir = newDirs; + m_mapCubeRot = newRots; +} -void Cube::shiftFrame(std::string from, std::string to) -{ - m_mapFrameDir.at(to) = m_mapFrameDir.at(from); - m_mapFrameRot.at(to) = m_mapFrameRot.at(from); -} - - -//dumps the current "board" +//dumps the current ortho state of cube void Cube::dump(char * title) { //Bottom/Front/Left/Rear/Right/Top -// EACFDB Base::Console().Message("Cube: %s\n", title); Base::Console().Message("B: %s/%s \nF: %s/%s \nL: %s/%s\n", DrawUtil::formatVector(getBottom()).c_str(),DrawUtil::formatVector(getBottomRot()).c_str(), @@ -299,511 +287,279 @@ void Cube::dump(char * title) DrawUtil::formatVector(getRear()).c_str(),DrawUtil::formatVector(getRearRot()).c_str(), DrawUtil::formatVector(getRight()).c_str(),DrawUtil::formatVector(getRightRot()).c_str(), DrawUtil::formatVector(getTop()).c_str(),DrawUtil::formatVector(getTopRot()).c_str()); - std::string boardDirs = dirToView(getBottom()) + dirToView(getFront()) + dirToView(getLeft()) + - dirToView(getRear()) + dirToView(getRight()) + dirToView(getTop()); - std::string boardRots = dirToView(getBottomRot()) + dirToView(getFrontRot()) + dirToView(getLeftRot()) + - dirToView(getRearRot()) + dirToView(getRightRot()) + dirToView(getTopRot()); - std::string boardConfig = dirToView(getFront()) + dirToView(getRight()); - Base::Console().Message("Cube: Board State - config: %s Dirs: %s Rots: %s\n",boardConfig.c_str(),boardDirs.c_str(),boardRots.c_str()); } //dumps the current "board" -ISO's void Cube::dumpISO(char * title) { //FBL/FBR/FTL/FTR -// Base::Console().Message("Cube ISO: %s\n", title); Base::Console().Message("FBL: %s/%s \nFBR: %s/%s \nFTL: %s/%s\nFTR: %s/%s\n", DrawUtil::formatVector(getFBL()).c_str(),DrawUtil::formatVector(getFBLRot()).c_str(), DrawUtil::formatVector(getFBR()).c_str(),DrawUtil::formatVector(getFBRRot()).c_str(), DrawUtil::formatVector(getFTL()).c_str(),DrawUtil::formatVector(getFTLRot()).c_str(), DrawUtil::formatVector(getFTR()).c_str(),DrawUtil::formatVector(getFTRRot()).c_str()); - std::string boardDirs = dirToView(getBottom()) + dirToView(getFront()) + dirToView(getLeft()) + - dirToView(getRear()) + dirToView(getRight()) + dirToView(getTop()); - std::string boardRots = dirToView(getBottomRot()) + dirToView(getFrontRot()) + dirToView(getLeftRot()) + - dirToView(getRearRot()) + dirToView(getRightRot()) + dirToView(getTopRot()); - std::string boardConfig = dirToView(getFront()) + dirToView(getRight()); - Base::Console().Message("Cube: Board State - config: %s Dirs: %s Rots: %s\n",boardConfig.c_str(),boardDirs.c_str(),boardRots.c_str()); } -//dumps the config state -void Cube::dumpState(char* title) +Base::Vector3d Cube::getViewDir(std::string name) { - std::string cfg = getCurrConfig(); - std::string strCfgDir = m_conTab.getCfgDirStr(cfg); - std::string strCfgRot = m_conTab.getCfgRotStr(cfg); - Base::Console().Message("Cube: dumpState - %s - config: %s Dirs: %s Rots: %s\n",title,cfg.c_str(),strCfgDir.c_str(),strCfgRot.c_str()); + Base::Vector3d result; + auto x = m_mapCubeDir.find(name); + if (x != m_mapCubeDir.end()) { + result = m_mapCubeDir.at(name); + } else { + if (name == "FrontTopRight") { + result = getFTR(); + } else if (name == "FrontBottomRight") { + result = getFBR(); + } else if (name == "FrontTopLeft") { + result = getFTL(); + } else if (name == "FrontBottomLeft") { + result = getFBL(); + } else { + result = Base::Vector3d(0,-1,0); + Base::Console().Log("Cube: invalid direction name - %s\n",name.c_str()); + } + } + return result; } Base::Vector3d Cube::getRight() { Base::Vector3d result; - result = m_mapFrameDir.at("Right"); + result = m_mapCubeDir.at("Right"); return result; } Base::Vector3d Cube::getFront() { Base::Vector3d result; - result = m_mapFrameDir.at("Front"); + result = m_mapCubeDir.at("Front"); return result; } Base::Vector3d Cube::getTop() { Base::Vector3d result; - result = m_mapFrameDir.at("Top"); + result = m_mapCubeDir.at("Top"); return result; } Base::Vector3d Cube::getLeft() { Base::Vector3d result; - result = m_mapFrameDir.at("Left"); + result = m_mapCubeDir.at("Left"); return result; } Base::Vector3d Cube::getRear() { Base::Vector3d result; - result = m_mapFrameDir.at("Rear"); + result = m_mapCubeDir.at("Rear"); return result; } Base::Vector3d Cube::getBottom() { Base::Vector3d result; - result = m_mapFrameDir.at("Bottom"); + result = m_mapCubeDir.at("Bottom"); return result; } Base::Vector3d Cube::getFBL() { Base::Vector3d result; - result = m_mapFrameDir.at("FrontBottomLeft"); + result = getFront() + getBottom() + getLeft(); return result; } Base::Vector3d Cube::getFBR() { Base::Vector3d result; - result = m_mapFrameDir.at("FrontBottomRight"); + result = getFront() + getBottom() + getRight(); return result; } Base::Vector3d Cube::getFTL() { Base::Vector3d result; - result = m_mapFrameDir.at("FrontTopLeft"); + result = getFront() + getTop() + getLeft(); return result; } Base::Vector3d Cube::getFTR() { Base::Vector3d result; - result = m_mapFrameDir.at("FrontTopRight"); + result = getFront() + getTop() + getRight(); return result; } +Base::Vector3d Cube::getRotationDir(std::string name) +{ + Base::Vector3d result; + auto x = m_mapCubeRot.find(name); + if (x != m_mapCubeRot.end()) { + result = m_mapCubeRot.at(name); + } else { + if (name == "FrontTopRight") { + result = getFTRRot(); + } else if (name == "FrontBottomRight") { + result = getFBRRot(); + } else if (name == "FrontTopLeft") { + result = getFTLRot(); + } else if (name == "FrontBottomLeft") { + result = getFBLRot(); + } else { + result = Base::Vector3d(1,0,0); + Base::Console().Log("Cube: invalid rotation name - %s\n",name.c_str()); + } + } + return result; +} Base::Vector3d Cube::getRightRot() { - std::string myFace = "D"; Base::Vector3d result; - result = m_mapFrameRot.at("Right"); + result = m_mapCubeRot.at("Right"); return result; } Base::Vector3d Cube::getFrontRot() { Base::Vector3d result; - result = m_mapFrameRot.at("Front"); + result = m_mapCubeRot.at("Front"); return result; } Base::Vector3d Cube::getTopRot() { Base::Vector3d result; - result = m_mapFrameRot.at("Top"); + result = m_mapCubeRot.at("Top"); return result; } Base::Vector3d Cube::getLeftRot() { Base::Vector3d result; - result = m_mapFrameRot.at("Left"); + result = m_mapCubeRot.at("Left"); return result; } Base::Vector3d Cube::getRearRot() { Base::Vector3d result; - result = m_mapFrameRot.at("Rear"); + result = m_mapCubeRot.at("Rear"); return result; } Base::Vector3d Cube::getBottomRot() { - std::string myFace = "E"; Base::Vector3d result; - result = m_mapFrameRot.at("Bottom"); + result = m_mapCubeRot.at("Bottom"); return result; } Base::Vector3d Cube::getFBLRot() { Base::Vector3d result; - double magic1 = 157.5 * M_PI / 180.0; // 90 + 45 + magic1 - double magic2 = -17.632 * M_PI / 180.0; //±35.264° / 2 "magic angle"?? - // <::value_type("Bottom", b)); - itemMap.insert(std::map::value_type("Front", f)); - itemMap.insert(std::map::value_type("Left", l)); - itemMap.insert(std::map::value_type("Rear", k)); - itemMap.insert(std::map::value_type("Right", r)); - itemMap.insert(std::map::value_type("Top", t)); -} - -Base::Vector3d configLine::getItem(std::string frame) -{ - return itemMap.at(frame); -} - -std::string configLine::getString() -{ - //this outputs Bottom/Left/Front/Rear/Right/Top - std::string result; - for (auto& i: itemMap) { - Base::Vector3d itemVec = i.second; - result += Cube::dirToView(itemVec); - } - return result; -} - -void configLine::dump(char* title) -{ - Base::Console().Message("DUMP: configLine %s key: %s\n",title,key.c_str()); - for (auto& i: itemMap) { - Base::Console().Message(">>> %s - %s - %s\n", - i.first.c_str(),DrawUtil::formatVector(i.second).c_str(),Cube::dirToView(i.second).c_str()); - } -} - -//******************************************************** - -std::string configTable::getCfgDirStr(std::string cfg) -{ - std::string result; - configLine dirLine = getDirLine(cfg); - result = dirLine.getString(); - return result; -} - -std::string configTable::getCfgRotStr(std::string cfg) -{ - std::string result; - configLine dirLine = getRotLine(cfg); - result = dirLine.getString(); - return result; -} - -configLine configTable::getDirLine(std::string key) -{ - return getLine(key, dirs); -} - -configLine configTable::getRotLine(std::string k) -{ - return getLine(k,rots); -} - -configLine configTable::getLine(std::string k, std::vector list) -{ - configLine result; - for (auto& l: list) { - if (k == l.getKey()) { - result = l; - break; - } - } - return result; -} - -Base::Vector3d configTable::getDirItem(std::string k, std::string v) -{ - return getItem(k, v, dirs); -} - -Base::Vector3d configTable::getRotItem(std::string k, std::string v) -{ - return getItem(k, v, rots); -} - -Base::Vector3d configTable::getItem(std::string k, std::string v, std::vector list) +Base::Vector3d Cube::rodrigues(Base::Vector3d v, + double angle, + Base::Vector3d axis) { Base::Vector3d result; - configLine line = getLine(k, list); - result = line.itemMap.at(v); + if (DrawUtil::checkParallel(v,axis)) { + result = v; + } else { + Base::Vector3d around = axis; + around.Normalize(); + double theta = angle * (M_PI / 180.0); + Base::Vector3d t1 = cos(theta) * v; + Base::Vector3d t2 = sin(theta) * around.Cross(v); + Base::Vector3d t3 = around.Dot(v) * (1 - cos(theta)) * around; + result = t1 + t2 + t3; + } return result; } -void configTable::addDirItem(configLine cl) +std::vector Cube::getAllDirs(void) { - dirs.push_back(cl); -} - -void configTable::addRotItem(configLine cl) -{ - rots.push_back(cl); -} - -void configTable::initialize(void) -{ - dirs.clear(); - rots.clear(); - configLine cl; - -//Rotations -// Rots - b/f/l/k/r/t - cl = configLine( 1 , "AB", Base::Vector3d(0,0,1), Base::Vector3d(0,0,1), Base::Vector3d(0,1,0), - Base::Vector3d(0,0,-1), Base::Vector3d(0,-1,0), Base::Vector3d(0,0,1) ); - addRotItem(cl); - cl = configLine( 2 , "AC", Base::Vector3d(-1,0,0), Base::Vector3d(-1,0,0), Base::Vector3d(0,1,0), - Base::Vector3d(1,0,0), Base::Vector3d(0,-1,0), Base::Vector3d(-1,0,0) ); - addRotItem(cl); - cl = configLine( 3 , "AD", Base::Vector3d(1,0,0), Base::Vector3d(1,0,0), Base::Vector3d(0,1,0), - Base::Vector3d(-1,0,0), Base::Vector3d(0,-1,0), Base::Vector3d(1,0,0) ); - addRotItem(cl); - cl = configLine( 4 , "AE", Base::Vector3d(0,0,-1), Base::Vector3d(0,0,-1), Base::Vector3d(0,1,0), - Base::Vector3d(0,0,1), Base::Vector3d(0,-1,0), Base::Vector3d(0,0,-1) ); - addRotItem(cl); - cl = configLine( 5 , "BA", Base::Vector3d(0,-1,0), Base::Vector3d(0,1,0), Base::Vector3d(0,0,-1), - Base::Vector3d(0,-1,0), Base::Vector3d(0,0,-1), Base::Vector3d(0,1,0) ); - addRotItem(cl); - cl = configLine( 6 , "BC", Base::Vector3d(-1,0,0), Base::Vector3d(-1,0,0), Base::Vector3d(0,0,1), - Base::Vector3d(1,0,0), Base::Vector3d(0,0,-1), Base::Vector3d(-1,0,0) ); - addRotItem(cl); - cl = configLine( 7 , "BD", Base::Vector3d(1,0,0), Base::Vector3d(1,0,0), Base::Vector3d(0,0,1), - Base::Vector3d(-1,0,0), Base::Vector3d(0,0,-1), Base::Vector3d(1,0,0) ); - addRotItem(cl); - cl = configLine( 8 , "BF", Base::Vector3d(-1,0,0), Base::Vector3d(0,-1,0), Base::Vector3d(0,0,1), - Base::Vector3d(0,1,0), Base::Vector3d(0,0,-1), Base::Vector3d(0,1,0) ); - addRotItem(cl); - cl = configLine( 9 , "CA", Base::Vector3d(0,1,0), Base::Vector3d(1,0,0), Base::Vector3d(-1,0,0), - Base::Vector3d(1,0,0), Base::Vector3d(0,1,0), Base::Vector3d(0,1,0) ); - addRotItem(cl); - cl = configLine( 10 , "CB", Base::Vector3d(0,0,1), Base::Vector3d(0,0,1), Base::Vector3d(-1,0,0), - Base::Vector3d(0,0,-1), Base::Vector3d(1,0,0), Base::Vector3d(0,0,1) ); - addRotItem(cl); - cl = configLine( 11 , "CE", Base::Vector3d(0,0,-1), Base::Vector3d(0,0,-1), Base::Vector3d(-1,0,0), - Base::Vector3d(0,0,1), Base::Vector3d(1,0,0), Base::Vector3d(0,0,-1) ); - addRotItem(cl); - cl = configLine( 12 , "CF", Base::Vector3d(0,-1,0), Base::Vector3d(0,-1,0), Base::Vector3d(-1,0,0), - Base::Vector3d(0,1,0), Base::Vector3d(1,0,0), Base::Vector3d(0,-1,0) ); - addRotItem(cl); - cl = configLine( 13 , "DA", Base::Vector3d(0,1,0), Base::Vector3d(0,1,0), Base::Vector3d(1,0,0), - Base::Vector3d(0,-1,0), Base::Vector3d(-1,0,0), Base::Vector3d(0,1,0) ); - addRotItem(cl); - cl = configLine( 14 , "DB", Base::Vector3d(0,0,1), Base::Vector3d(0,0,1), Base::Vector3d(1,0,0), - Base::Vector3d(0,0,-1), Base::Vector3d(-1,0,0), Base::Vector3d(0,0,1) ); - addRotItem(cl); - cl = configLine( 15 , "DE", Base::Vector3d(0,0,-1), Base::Vector3d(0,0,-1), Base::Vector3d(1,0,0), - Base::Vector3d(0,0,1), Base::Vector3d(-1,0,0), Base::Vector3d(0,0,-1) ); - addRotItem(cl); - cl = configLine( 16 , "DF", Base::Vector3d(0,-1,0), Base::Vector3d(-1,0,0), Base::Vector3d(1,0,0), - Base::Vector3d(1,0,0), Base::Vector3d(0,-1,0), Base::Vector3d(0,-1,0) ); - addRotItem(cl); - cl = configLine( 17 , "EA", Base::Vector3d(0,1,0), Base::Vector3d(0,1,0), Base::Vector3d(0,0,-1), - Base::Vector3d(0,-1,0), Base::Vector3d(0,0,1), Base::Vector3d(0,1,0) ); - addRotItem(cl); - cl = configLine( 18 , "EC", Base::Vector3d(-1,0,0), Base::Vector3d(-1,0,0), Base::Vector3d(0,0,-1), - Base::Vector3d(1,0,0), Base::Vector3d(0,0,1), Base::Vector3d(-1,0,0) ); - addRotItem(cl); - cl = configLine( 19 , "ED", Base::Vector3d(1,0,0), Base::Vector3d(1,0,0), Base::Vector3d(0,0,-1), - Base::Vector3d(-1,0,0), Base::Vector3d(0,0,1), Base::Vector3d(1,0,0) ); - addRotItem(cl); - cl = configLine( 20 , "EF", Base::Vector3d(0,-1,0), Base::Vector3d(0,-1,0), Base::Vector3d(0,0,-1), - Base::Vector3d(0,1,0), Base::Vector3d(0,0,1), Base::Vector3d(-1,0,0) ); - addRotItem(cl); - cl = configLine( 21 , "FB", Base::Vector3d(0,0,1), Base::Vector3d(0,0,1), Base::Vector3d(0,-1,0), - Base::Vector3d(0,0,-1), Base::Vector3d(0,1,0), Base::Vector3d(0,0,1) ); - addRotItem(cl); - cl = configLine( 22 , "FC", Base::Vector3d(-1,0,0), Base::Vector3d(0,1,0), Base::Vector3d(-1,0,0), - Base::Vector3d(1,0,0), Base::Vector3d(0,1,0), Base::Vector3d(-1,0,0) ); - addRotItem(cl); - cl = configLine( 23 , "FD", Base::Vector3d(1,0,0), Base::Vector3d(1,0,0), Base::Vector3d(0,-1,0), - Base::Vector3d(-1,0,0), Base::Vector3d(0,1,0), Base::Vector3d(1,0,0) ); - addRotItem(cl); - cl = configLine( 24 , "FE", Base::Vector3d(0,0,-1), Base::Vector3d(0,0,-1), Base::Vector3d(0,-1,0), - Base::Vector3d(0,0,1), Base::Vector3d(0,1,0), Base::Vector3d(0,0,-1) ); - addRotItem(cl); - - -//Directions items -// Dirs - b/f/l/k/r/t - cl = configLine( 1 , "AB", Base::Vector3d(1,0,0), Base::Vector3d(0,-1,0), Base::Vector3d(0,0,-1), - Base::Vector3d(0,1,0), Base::Vector3d(0,0,1), Base::Vector3d(-1,0,0) ); - addDirItem(cl); - cl = configLine( 2 , "AC", Base::Vector3d(0,0,1), Base::Vector3d(0,-1,0), Base::Vector3d(1,0,0), - Base::Vector3d(0,1,0), Base::Vector3d(-1,0,0), Base::Vector3d(0,0,-1) ); - addDirItem(cl); - cl = configLine( 3 , "AD", Base::Vector3d(0,0,-1), Base::Vector3d(0,-1,0), Base::Vector3d(-1,0,0), - Base::Vector3d(0,1,0), Base::Vector3d(1,0,0), Base::Vector3d(0,0,1) ); - addDirItem(cl); - cl = configLine( 4 , "AE", Base::Vector3d(-1,0,0), Base::Vector3d(0,-1,0), Base::Vector3d(0,0,1), - Base::Vector3d(0,1,0), Base::Vector3d(0,0,-1), Base::Vector3d(1,0,0) ); - addDirItem(cl); - cl = configLine( 5 , "BA", Base::Vector3d(-1,0,0), Base::Vector3d(0,0,1), Base::Vector3d(0,1,0), - Base::Vector3d(0,0,-1), Base::Vector3d(0,-1,0), Base::Vector3d(1,0,0) ); - addDirItem(cl); - //BC = FBDECA - cl = configLine( 6 , "BC", Base::Vector3d(0,1,0), Base::Vector3d(0,0,1), Base::Vector3d(1,0,0), - Base::Vector3d(0,0,-1), Base::Vector3d(-1,0,0), Base::Vector3d(0,-1,0) ); - addDirItem(cl); - cl = configLine( 7 , "BD", Base::Vector3d(0,-1,0), Base::Vector3d(0,0,1), Base::Vector3d(-1,0,0), - Base::Vector3d(0,0,-1), Base::Vector3d(1,0,0), Base::Vector3d(0,1,0) ); - addDirItem(cl); - cl = configLine( 8 , "BF", Base::Vector3d(1,0,0), Base::Vector3d(0,0,1), Base::Vector3d(0,-1,0), - Base::Vector3d(0,0,-1), Base::Vector3d(0,1,0), Base::Vector3d(-1,0,0) ); - addDirItem(cl); - cl = configLine( 9 , "CA", Base::Vector3d(0,0,-1), Base::Vector3d(-1,0,0), Base::Vector3d(0,1,0), - Base::Vector3d(1,0,0), Base::Vector3d(0,-1,0), Base::Vector3d(0,0,1) ); - addDirItem(cl); - cl = configLine( 10 , "CB", Base::Vector3d(0,-1,0), Base::Vector3d(-1,0,0), Base::Vector3d(0,0,-1), - Base::Vector3d(1,0,0), Base::Vector3d(0,0,1), Base::Vector3d(0,1,0) ); - addDirItem(cl); - cl = configLine( 11 , "CE", Base::Vector3d(0,1,0), Base::Vector3d(-1,0,0), Base::Vector3d(0,0,1), - Base::Vector3d(1,0,0), Base::Vector3d(0,0,-1), Base::Vector3d(0,-1,0) ); - addDirItem(cl); - cl = configLine( 12 , "CF", Base::Vector3d(0,0,1), Base::Vector3d(-1,0,0), Base::Vector3d(0,-1,0), - Base::Vector3d(1,0,0), Base::Vector3d(0,1,0), Base::Vector3d(0,0,-1) ); - addDirItem(cl); - cl = configLine( 13 , "DA", Base::Vector3d(0,0,1), Base::Vector3d(1,0,0), Base::Vector3d(0,1,0), - Base::Vector3d(-1,0,0), Base::Vector3d(0,-1,0), Base::Vector3d(0,0,-1) ); - addDirItem(cl); - cl = configLine( 14 , "DB", Base::Vector3d(0,1,0), Base::Vector3d(1,0,0), Base::Vector3d(0,0,-1), - Base::Vector3d(-1,0,0), Base::Vector3d(0,0,1), Base::Vector3d(0,-1,0) ); - addDirItem(cl); - cl = configLine( 15 , "DE", Base::Vector3d(0,-1,0), Base::Vector3d(1,0,0), Base::Vector3d(0,0,1), - Base::Vector3d(-1,0,0), Base::Vector3d(0,0,-1), Base::Vector3d(0,1,0) ); - addDirItem(cl); - cl = configLine( 16 , "DF", Base::Vector3d(0,0,-1), Base::Vector3d(1,0,0), Base::Vector3d(0,-1,0), - Base::Vector3d(-1,0,0), Base::Vector3d(0,1,0), Base::Vector3d(0,0,1) ); - addDirItem(cl); - cl = configLine( 17 , "EA", Base::Vector3d(1,0,0), Base::Vector3d(0,0,-1), Base::Vector3d(0,1,0), - Base::Vector3d(0,0,1), Base::Vector3d(0,-1,0), Base::Vector3d(-1,0,0) ); - addDirItem(cl); - cl = configLine( 18 , "EC", Base::Vector3d(0,-1,0), Base::Vector3d(0,0,-1), Base::Vector3d(1,0,0), - Base::Vector3d(0,0,1), Base::Vector3d(-1,0,0), Base::Vector3d(0,1,0) ); - addDirItem(cl); - cl = configLine( 19 , "ED", Base::Vector3d(0,1,0), Base::Vector3d(0,0,-1), Base::Vector3d(-1,0,0), - Base::Vector3d(0,0,1), Base::Vector3d(1,0,0), Base::Vector3d(0,-1,0) ); - addDirItem(cl); - cl = configLine( 20 , "EF", Base::Vector3d(-1,0,0), Base::Vector3d(0,0,-1), Base::Vector3d(0,-1,0), - Base::Vector3d(0,0,1), Base::Vector3d(0,1,0), Base::Vector3d(1,0,0) ); - addDirItem(cl); - cl = configLine( 21 , "FB", Base::Vector3d(-1,0,0), Base::Vector3d(0,1,0), Base::Vector3d(0,0,-1), - Base::Vector3d(0,-1,0), Base::Vector3d(0,0,1), Base::Vector3d(1,0,0) ); - addDirItem(cl); - cl = configLine( 22 , "FC", Base::Vector3d(0,0,-1), Base::Vector3d(0,1,0), Base::Vector3d(1,0,0), - Base::Vector3d(0,-1,0), Base::Vector3d(-1,0,0), Base::Vector3d(0,0,1) ); - addDirItem(cl); - cl = configLine( 23 , "FD", Base::Vector3d(0,0,1), Base::Vector3d(0,1,0), Base::Vector3d(-1,0,0), - Base::Vector3d(0,-1,0), Base::Vector3d(1,0,0), Base::Vector3d(0,0,-1) ); - addDirItem(cl); - cl = configLine( 24 , "FE", Base::Vector3d(1,0,0), Base::Vector3d(0,1,0), Base::Vector3d(0,0,1), - Base::Vector3d(0,-1,0), Base::Vector3d(0,0,-1), Base::Vector3d(-1,0,0) ); - addDirItem(cl); -} - -void configTable::dump(char* title) -{ - Base::Console().Message("DUMP: configTable - %s\n",title); - for (auto& cl: dirs) { - cl.dump("dirs - "); + std::vector result; + for (auto& d: m_mapCubeDir) { + Base::Vector3d v = d.second; + result.push_back(v); } - for (auto& cl: rots) { - cl.dump("rots - "); + return result; +} + +std::vector Cube::getAllRots(void) +{ + std::vector result; + for (auto& r: m_mapCubeRot) { + Base::Vector3d v = r.second; + result.push_back(v); } + return result; +} + +void Cube::setAllDirs(std::vector dirs) +{ + if (dirs.size() != 6) { + Base::Console().Error("Cube:setAllDirs - missing dirs: %d\n",dirs.size()); + return; //throw something? + } + + auto i = dirs.begin(); + std::map newDirs; + for (auto& d: m_mapCubeDir) { + Base::Vector3d v = (*i); + newDirs.insert(std::map::value_type(d.first, v)); + i++; + } + m_mapCubeDir = newDirs; +} + +void Cube::setAllRots(std::vector rots) +{ + if (rots.size() != 6) { + Base::Console().Error("Cube:setAllRots - missing rots: %d\n",rots.size()); + return; //throw something? + } + + auto i = rots.begin(); + std::map newRots; + for (auto& r: m_mapCubeRot) { + Base::Vector3d v = (*i); + newRots.insert(std::map::value_type(r.first, v)); + i++; + } + m_mapCubeRot = newRots; } + + diff --git a/src/Mod/TechDraw/App/Cube.h b/src/Mod/TechDraw/App/Cube.h index e1d537c8a7..6d268f36f9 100644 --- a/src/Mod/TechDraw/App/Cube.h +++ b/src/Mod/TechDraw/App/Cube.h @@ -26,54 +26,8 @@ #include -namespace TechDraw { - -class configLine +namespace TechDraw { -public: - configLine() {} - ~configLine() {} - - configLine(int ln, std::string ky, Base::Vector3d b, Base::Vector3d f, - Base::Vector3d l, Base::Vector3d k, - Base::Vector3d r, Base::Vector3d t); - Base::Vector3d getItem(std::string s); - std::string getKey(void) { return key; } - std::string getString(); - void dump(char* title); - - std::map itemMap; -// Base::Vector3d getItem(std::string s); -private: - int lineNumber; - std::string key; -// std::map itemMap; -}; - -class configTable -{ -public: - configTable(void) {} - ~configTable(void) {} - void initialize(); - std::string getCfgDirStr(std::string cfg); - std::string getCfgRotStr(std::string cfg); - - configLine getDirLine(std::string k); - configLine getRotLine(std::string k); - Base::Vector3d getDirItem(std::string k, std::string v); - Base::Vector3d getRotItem(std::string k, std::string v); - void addDirItem(configLine); - void addRotItem(configLine); - //bool checkConfig(std::vector c); - void dump(char* title); - -private: - configLine getLine(std::string k, std::vector list); - Base::Vector3d getItem(std::string k, std::string v, std::vector list); - std::vector dirs; - std::vector rots; -}; class Cube @@ -82,23 +36,23 @@ public: Cube(); ~Cube(); +void initialize(); void initialize(Base::Vector3d r, Base::Vector3d rr, Base::Vector3d l, Base::Vector3d lr, Base::Vector3d f, Base::Vector3d fr, Base::Vector3d k, Base::Vector3d kr, //k for bacK (rear) - Base::Vector3d t, Base::Vector3d tr, Base::Vector3d b, Base::Vector3d br, - Base::Vector3d fbl, Base::Vector3d fblr, Base::Vector3d fbr, Base::Vector3d fbrr, - Base::Vector3d ftl, Base::Vector3d ftlr, Base::Vector3d ftr, Base::Vector3d ftrr); + Base::Vector3d t, Base::Vector3d tr, Base::Vector3d b, Base::Vector3d br); - void rotateUp(); - void rotateDown(); - void rotateRight(); - void rotateLeft (); - void spinCCW(); - void spinCW(); - + void rotateUp(double angle = 90.0); + void rotateDown(double angle = 90.0); + void rotateRight(double angle = 90.0); + void rotateLeft (double angle = 90.0); + void spinCCW(double angle = 90.0); + void spinCW(double angle = 90.0); void updateIsoDirs(); + //viewDirection getters + Base::Vector3d getViewDir(std::string name); Base::Vector3d getRight(); Base::Vector3d getFront(); Base::Vector3d getTop(); @@ -110,6 +64,8 @@ void initialize(Base::Vector3d r, Base::Vector3d rr, Base::Vector3d l, Base::Vec Base::Vector3d getFTL(); Base::Vector3d getFTR(); + //rotation getters + Base::Vector3d getRotationDir(std::string name); Base::Vector3d getRightRot(); Base::Vector3d getFrontRot(); Base::Vector3d getTopRot(); @@ -121,48 +77,30 @@ void initialize(Base::Vector3d r, Base::Vector3d rr, Base::Vector3d l, Base::Vec Base::Vector3d getFTLRot(); Base::Vector3d getFTRRot(); - static std::string dirToView(Base::Vector3d v); - void updateDirsToConfig(std::string cfg); - void updateRotsToConfig(std::string cfg); - bool validateBoard(std::string cfg); - std::string getCurrConfig(void); - void dump(char * title); void dumpISO(char * title); - void dumpState(char * title); + + std::vector getAllDirs(void); + std::vector getAllRots(void); + void setAllDirs(std::vector dirs); + void setAllRots(std::vector rots); private: -// Base::Vector3d currRight; -// Base::Vector3d currRightRot; -// Base::Vector3d currFront; -// Base::Vector3d currFrontRot; -// Base::Vector3d currTop; -// Base::Vector3d currTopRot; -// Base::Vector3d currLeft; -// Base::Vector3d currLeftRot; -// Base::Vector3d currRear; -// Base::Vector3d currRearRot; -// Base::Vector3d currBottom; -// Base::Vector3d currBottomRot; - - - //the current state of the "board" - //the "board" is always full - entries for every position - std::map m_mapFrameDir; - std::map m_mapFrameRot; + //the current state of the "cube" + //the "cube" is always full - entries for every ortho position (6 total) + std::map m_mapCubeDir; + std::map m_mapCubeRot; - static const std::map m_viewToStdDir; //would really like this map the other way round. + static const std::map m_viewDefault; + static const std::map m_rotDefault; + +//should be in drawutil? + Base::Vector3d rodrigues(Base::Vector3d v, + double angle, + Base::Vector3d axis); - void shiftFrame(std::string from, std::string to); - void saveSwap(std::string frame); - void restoreSwap(std::string frame); - Base::Vector3d m_swapDir; - Base::Vector3d m_swapRot; - configTable m_conTab; - }; - } #endif diff --git a/src/Mod/TechDraw/App/DrawProjGroup.cpp b/src/Mod/TechDraw/App/DrawProjGroup.cpp index cbc001c44d..1f5e51b812 100644 --- a/src/Mod/TechDraw/App/DrawProjGroup.cpp +++ b/src/Mod/TechDraw/App/DrawProjGroup.cpp @@ -53,87 +53,6 @@ const char* DrawProjGroup::ProjectionTypeEnums[] = {"Default", "Third Angle", NULL}; -//default starting dirs & rots -const std::map DrawProjGroup::m_frameToStdDir = { - { "Front", Base::Vector3d(0, -1, 0) }, //front - { "Rear", Base::Vector3d(0, 1, 0) }, //rear - { "Right", Base::Vector3d(1, 0, 0) }, //right - { "Left", Base::Vector3d(-1, 0, 0) }, //left - { "Top", Base::Vector3d(0, 0, 1) }, //top - { "Bottom", Base::Vector3d(0, 0, -1) }, //bottom - { "FrontBottomLeft", Base::Vector3d(-1, -1, -1) }, //FBL - { "FrontBottomRight", Base::Vector3d(1, -1, -1) }, //FBR - { "FrontTopLeft", Base::Vector3d(-1,-1,1) }, //FTL - { "FrontTopRight", Base::Vector3d(1, -1, 1) } //FTR - }; - -const std::map DrawProjGroup::m_frameToStdRot = { - { "Front", Base::Vector3d(1, 0, 0) }, //front - { "Rear", Base::Vector3d(-1, 0, 0) }, //rear - { "Right", Base::Vector3d(0, -1, 0) }, //right - { "Left", Base::Vector3d(0, 1, 0) }, //left - { "Top", Base::Vector3d(1, 0, 0) }, //top - { "Bottom", Base::Vector3d(1, 0, 0) }, //bottom - { "FrontBottomLeft", Base::Vector3d(2, 1, 0.5) }, - { "FrontBottomRight", Base::Vector3d(2, -1, -0.5) }, - { "FrontTopLeft", Base::Vector3d(2, 1, -0.5) }, - { "FrontTopRight", Base::Vector3d(2, -1, 0.5) } - }; - -//one of these is obs?? -// map of front.dir+front.rot onto config -const std::map DrawProjGroup::m_dirRotToConfig = { - {"AB","AB"}, - {"AC","AC"}, - {"AD","AD"}, - {"AE","AE"}, - {"BF","BA"}, - {"BC","BC"}, - {"BD","BD"}, - {"BA","BF"}, - {"CD","CA"}, - {"CB","CB"}, - {"CE","CE"}, - {"CA","CF"}, - {"DF","DA"}, - {"DB","DB"}, - {"DE","DE"}, - {"DC","DF"}, - {"EF","EA"}, - {"EC","EC"}, - {"ED","ED"}, - {"EA","EF"}, - {"FB","FB"}, - {"FF","FC"}, - {"FD","FD"}, - {"FE","FE"} }; - -// map frontDir + topDir onto config -const std::map DrawProjGroup::m_frontTopToConfig = { - { "AC" , "AB" }, - { "AE" , "AC" }, - { "AB" , "AD" }, - { "AD" , "AE" }, - { "BD" , "BA" }, - { "BA" , "BC" }, - { "BF" , "BD" }, - { "BC" , "BF" }, - { "CB" , "CA" }, - { "CF" , "CB" }, - { "CA" , "CE" }, - { "CE" , "CF" }, - { "DE" , "DA" }, - { "DA" , "DB" }, - { "DF" , "DE" }, - { "DB" , "DF" }, - { "EC" , "EA" }, - { "EF" , "EC" }, - { "EA" , "ED" }, - { "ED" , "EF" }, - { "FD" , "FB" }, - { "FB" , "FC" }, - { "FE" , "FD" }, - { "FC" , "FE" } }; PROPERTY_SOURCE(TechDraw::DrawProjGroup, TechDraw::DrawViewCollection) @@ -152,16 +71,10 @@ DrawProjGroup::DrawProjGroup(void) ADD_PROPERTY_TYPE(spacingX, (15), agroup, App::Prop_None, "Horizontal spacing between views"); ADD_PROPERTY_TYPE(spacingY, (15), agroup, App::Prop_None, "Vertical spacing between views"); + ADD_PROPERTY_TYPE(CubeDirs,(Base::Vector3d()) ,agroup, App::Prop_None, "Current view directions"); + ADD_PROPERTY_TYPE(CubeRotations,(Base::Vector3d()),agroup, App::Prop_None, "Current rotations"); m_cube = new Cube(); - // D/C/A/F/B/E/FBL/ - m_cube->initialize(m_frameToStdDir.at("Right"), m_frameToStdRot.at("Right"), - m_frameToStdDir.at("Left"), m_frameToStdRot.at("Left"), - m_frameToStdDir.at("Front"), m_frameToStdRot.at("Front"), m_frameToStdDir.at("Rear"), m_frameToStdRot.at("Rear"), - m_frameToStdDir.at("Top"), m_frameToStdRot.at("Top"), m_frameToStdDir.at("Bottom"), m_frameToStdRot.at("Bottom"), - m_frameToStdDir.at("FrontBottomLeft"), m_frameToStdRot.at("FrontBottomLeft"), - m_frameToStdDir.at("FrontBottomRight"), m_frameToStdRot.at("FrontBottomRight"), - m_frameToStdDir.at("FrontTopLeft"), m_frameToStdRot.at("FrontTopLeft"), - m_frameToStdDir.at("FrontTopRight"), m_frameToStdRot.at("FrontTopRight") ); + m_cube->initialize(); //set default dirs & rots } DrawProjGroup::~DrawProjGroup() @@ -169,6 +82,12 @@ DrawProjGroup::~DrawProjGroup() delete m_cube; } +void DrawProjGroup::resetCube(void) +{ + m_cube->initialize(); + updateSecondaryDirs(); +} + void DrawProjGroup::onChanged(const App::Property* prop) { //TODO: For some reason, when the projection type is changed, the isometric views show change appropriately, but the orthographic ones don't... Or vice-versa. WF: why would you change from 1st to 3rd in mid drawing? @@ -201,9 +120,28 @@ void DrawProjGroup::onChanged(const App::Property* prop) recompute(); } } + if (isRestoring() && (prop == &CubeDirs)) { + m_cube->setAllDirs(CubeDirs.getValues()); //override defaults from saved value if valid + } + if (isRestoring() && (prop == &CubeRotations)) { + m_cube->setAllRots(CubeRotations.getValues()); //override defaults from saved value if valid + } + TechDraw::DrawViewCollection::onChanged(prop); } +//! call this after changing the Cube +void DrawProjGroup::setPropsFromCube(void) +{ + CubeDirs.setValues(m_cube->getAllDirs()); + CubeRotations.setValues(m_cube->getAllRots()); +} + +void DrawProjGroup::setCubeFromProps(void) +{ + m_cube->setAllDirs(CubeDirs.getValues()); + m_cube->setAllRots(CubeRotations.getValues()); +} App::DocumentObjectExecReturn *DrawProjGroup::execute(void) { //if group hasn't been added to page yet, can't scale or distribute projItems @@ -461,8 +399,8 @@ App::DocumentObject * DrawProjGroup::addProjection(const char *viewProjType) view->Type.setValue( viewProjType ); view->Label.setValue( viewProjType ); view->Source.setValue( Source.getValue() ); - view->Direction.setValue(m_frameToStdDir.at(viewProjType)); - view->RotationVector.setValue(m_frameToStdRot.at(viewProjType)); + view->Direction.setValue(m_cube->getViewDir(viewProjType)); + view->RotationVector.setValue(m_cube->getRotationDir(viewProjType)); addView(view); //from DrawViewCollection - add to ProjGroup Views moveToCentre(); view->recomputeFeature(); @@ -896,8 +834,9 @@ void DrawProjGroup::updateSecondaryDirs() } v->Direction.setValue(newDir); v->RotationVector.setValue(newAxis); - v->recomputeFeature(); +// v->recomputeFeature(); } + setPropsFromCube(); } @@ -943,50 +882,10 @@ void DrawProjGroup::spinCCW() updateSecondaryDirs(); } -// find a config with Dir as Front view and Up as Top view -// used in setting view to match OpenInventor -void DrawProjGroup::setTable(Base::Vector3d dir, Base::Vector3d up) -{ - std::string viewFront = Cube::dirToView(dir); //convert to closest basis vector? - std::string viewUp = Cube::dirToView(up); //convert to closest basis vector - std::string altKey = viewFront + viewUp; - std::string config; - try { - config = m_frontTopToConfig.at(altKey); - } - catch (const std::out_of_range& oor) { - Base::Console().Error("Error - DPG::setTable - no match for alt config: %s - %s\n",altKey.c_str(),oor.what()); - return; - } - setConfig(config); -} - -// set config to a specific value -void DrawProjGroup::setConfig(std::string cfg) -{ - m_cube->updateDirsToConfig(cfg); - m_cube->updateRotsToConfig(cfg); - updateSecondaryDirs(); -} - -void DrawProjGroup::resetTable(void) -{ - m_cube->initialize(m_frameToStdDir.at("Right"), m_frameToStdRot.at("Right"), - m_frameToStdDir.at("Left"), m_frameToStdRot.at("Left"), - m_frameToStdDir.at("Front"), m_frameToStdRot.at("Front"), m_frameToStdDir.at("Rear"), m_frameToStdRot.at("Rear"), - m_frameToStdDir.at("Top"), m_frameToStdRot.at("Top"), m_frameToStdDir.at("Bottom"), m_frameToStdRot.at("Bottom"), - m_frameToStdDir.at("FrontBottomLeft"), m_frameToStdRot.at("FrontBottomLeft"), - m_frameToStdDir.at("FrontBottomRight"), m_frameToStdRot.at("FrontBottomRight"), - m_frameToStdDir.at("FrontTopLeft"), m_frameToStdRot.at("FrontTopLeft"), - m_frameToStdDir.at("FrontTopRight"), m_frameToStdRot.at("FrontTopRight") ); - updateSecondaryDirs(); -} //dumps the current iso DPGI's void DrawProjGroup::dumpISO(char * title) { -//FBL/FBR/FTL/FTR -// Base::Console().Message("DPG ISO: %s\n", title); for (auto& docObj: Views.getValues()) { Base::Vector3d dir; @@ -1001,45 +900,6 @@ void DrawProjGroup::dumpISO(char * title) } } -//************************************* -//! rebuild view direction map from existing DPGI's -void DrawProjGroup::onDocumentRestored() -{ - if (hasProjection("Front") && hasProjection("Right")) { - Base::Vector3d dirFront = getProjItem("Front")->Direction.getValue(); - std::string viewFront = Cube::dirToView(dirFront); - Base::Vector3d dirRight = getProjItem("Right")->Direction.getValue(); - std::string viewRight = Cube::dirToView(dirRight); - std::string config = viewFront + viewRight; - setConfig(config); - } else if (hasProjection("Front")) { - Base::Vector3d dirFront = getProjItem("Front")->Direction.getValue(); - std::string viewDir = Cube::dirToView(dirFront); - Base::Vector3d rotFront(1.0,0.0,0.0); - App::Property* prop = getPropertyByName("RotationVector"); - if (prop) { - Base::Console().Log("INFO - DPG::onRestore - DPG has RotationVector property\n"); - rotFront = getProjItem("Front")->RotationVector.getValue(); - } else { - Base::Console().Log("INFO - DPG::onRestore - DPG has NO RotationVector property\n"); - } - std::string viewRot = Cube::dirToView(rotFront); - std::string config = viewDir + viewRot; - //find(config) or try/catch - try { - config = m_dirRotToConfig.at(config); - setConfig(config); - } - catch (...) { - Base::Console().Message("PROBLEM: DPG cannot set configuration: %s using default instead\n",config.c_str()); - setConfig("AD"); - } - } else { - Base::Console().Message("PROBLEM: DPG cannot find Front view on restore. Using default instead.\n"); - setConfig("AD"); - } -} - PyObject *DrawProjGroup::getPyObject(void) { if (PythonObject.is(Py::_None())) { diff --git a/src/Mod/TechDraw/App/DrawProjGroup.h b/src/Mod/TechDraw/App/DrawProjGroup.h index bf48148e94..aea5b390db 100644 --- a/src/Mod/TechDraw/App/DrawProjGroup.h +++ b/src/Mod/TechDraw/App/DrawProjGroup.h @@ -63,6 +63,8 @@ public: App::PropertyFloat spacingY; App::PropertyLink Anchor; /// Anchor Element to align views to + App::PropertyVectorList CubeDirs; + App::PropertyVectorList CubeRotations; Base::BoundBox3d getBoundingBox() const; double calculateAutomaticScale() const; @@ -95,7 +97,6 @@ public: /** @name methods overide Feature */ //@{ /// recalculate the Feature - virtual void onDocumentRestored() override; virtual App::DocumentObjectExecReturn *execute(void) override; //@} @@ -118,6 +119,7 @@ public: TechDraw::DrawProjGroupItem* getAnchor(void); void updateSecondaryDirs(); + void resetCube(void); void rotateRight(void); void rotateLeft(void); @@ -126,9 +128,6 @@ public: void spinCW(void); void spinCCW(void); - void setTable(Base::Vector3d dir, Base::Vector3d rot); - void setConfig(std::string cfg); - void resetTable(void); void dumpISO(char * title); protected: @@ -166,13 +165,10 @@ protected: /// Returns pointer to our page, or NULL if it couldn't be located TechDraw::DrawPage * getPage(void) const; void updateChildren(double scale); + void setPropsFromCube(void); + void setCubeFromProps(void); - //TechDraw::Cube m_cube; TechDraw::Cube* m_cube; - static const std::map m_frameToStdDir; //for initializing cube and - static const std::map m_frameToStdRot; //creating DPGI's - static const std::map m_dirRotToConfig; - static const std::map m_frontTopToConfig; }; } //namespace TechDraw diff --git a/src/Mod/TechDraw/App/DrawProjGroupItem.cpp b/src/Mod/TechDraw/App/DrawProjGroupItem.cpp index 5f2e107ab8..342fb7e56a 100644 --- a/src/Mod/TechDraw/App/DrawProjGroupItem.cpp +++ b/src/Mod/TechDraw/App/DrawProjGroupItem.cpp @@ -62,8 +62,8 @@ DrawProjGroupItem::DrawProjGroupItem(void) ADD_PROPERTY_TYPE(RotationVector ,(1.0,0.0,0.0) ,"Base",App::Prop_None,"Controls rotation of item in view. "); //projection group controls these - Direction.setStatus(App::Property::ReadOnly,true); - RotationVector.setStatus(App::Property::ReadOnly,true); +// Direction.setStatus(App::Property::ReadOnly,true); +// RotationVector.setStatus(App::Property::ReadOnly,true); Scale.setStatus(App::Property::ReadOnly,true); ScaleType.setStatus(App::Property::ReadOnly,true); } diff --git a/src/Mod/TechDraw/Gui/TaskProjGroup.cpp b/src/Mod/TechDraw/Gui/TaskProjGroup.cpp index 551f352bfe..fb1d6ac0aa 100644 --- a/src/Mod/TechDraw/Gui/TaskProjGroup.cpp +++ b/src/Mod/TechDraw/Gui/TaskProjGroup.cpp @@ -176,24 +176,31 @@ void TaskProjGroup::rotateButtonClicked(void) void TaskProjGroup::on3DClicked(void) { - std::pair dir3D = get3DViewDir(); - Base::Vector3d dir = dir3D.first; - dir = DrawUtil::closestBasis(dir); - Base::Vector3d up = dir3D.second; - up = DrawUtil::closestBasis(up); - TechDraw::DrawProjGroupItem* front = multiView->getProjItem("Front"); - if (front) { //why "if front"??? - multiView->setTable(dir,up); - setUiPrimary(); - Gui::Command::updateActive(); - } + Base::Console().Warning("TaskProjGroup - this function is temporarily unavailable\n"); +//TODO: how to set the DPG.Cube (or a brand new replacement Cube) to a specific orientation +// {10x(viewDirection + RotationVector)} given only the +// viewDirection + upDirection(!= RotationVector) of the front view? +// need to find the sequence of rotations Left/Right, Up/Down, CW/CCW +// from current orientation to desired orientation. + +// std::pair dir3D = get3DViewDir(); +// Base::Vector3d dir = dir3D.first; +// dir = DrawUtil::closestBasis(dir); +// Base::Vector3d up = dir3D.second; +// up = DrawUtil::closestBasis(up); +// TechDraw::DrawProjGroupItem* front = multiView->getProjItem("Front"); +// if (front) { //why "if front"??? +// multiView->setTable(dir,up); +// setUiPrimary(); +// Gui::Command::updateActive(); +// } } void TaskProjGroup::onResetClicked(void) { TechDraw::DrawProjGroupItem* front = multiView->getProjItem("Front"); if (front) { - multiView->resetTable(); + multiView->resetCube(); setUiPrimary(); Gui::Command::updateActive(); } diff --git a/src/Mod/TechDraw/Gui/TaskProjGroup.ui b/src/Mod/TechDraw/Gui/TaskProjGroup.ui index 3c58068c30..7e942f95c2 100644 --- a/src/Mod/TechDraw/Gui/TaskProjGroup.ui +++ b/src/Mod/TechDraw/Gui/TaskProjGroup.ui @@ -309,10 +309,10 @@ - true + false - Try to match Primary Direction to 3D view + This function is temporarily unavailable. Match 3D