diff --git a/src/Mod/TechDraw/App/DrawProjGroup.cpp b/src/Mod/TechDraw/App/DrawProjGroup.cpp index 9eaa39edf2..d462636e48 100644 --- a/src/Mod/TechDraw/App/DrawProjGroup.cpp +++ b/src/Mod/TechDraw/App/DrawProjGroup.cpp @@ -29,6 +29,11 @@ #include #endif +#include +#include +#include +#include + #include #include #include @@ -506,6 +511,7 @@ std::pair DrawProjGroup::getDirsFromFront(DrawPro std::pair DrawProjGroup::getDirsFromFront(std::string viewType) { +// Base::Console().Message("DPG::getDirsFromFront(%s)\n", viewType.c_str()); std::pair result; Base::Vector3d projDir, rotVec; @@ -517,50 +523,70 @@ std::pair DrawProjGroup::getDirsFromFront(std::st Base::Vector3d dirAnch = anch->Direction.getValue(); Base::Vector3d rotAnch = anch->getXDirection(); - Base::Vector3d upAnch = dirAnch.Cross(rotAnch); //this can get weird after rotations - projDir = dirAnch; //need default - rotVec = rotAnch; - Base::Vector3d realUp = DrawUtil::closestBasis(upAnch); + result = std::make_pair(dirAnch,rotAnch); Base::Vector3d org(0.0,0.0,0.0); - result = std::make_pair(dirAnch,rotAnch); + gp_Ax2 anchorCS = anch->getProjectionCS(org); + gp_Pnt gOrg(0.0, 0.0, 0.0); + gp_Dir gDir = anchorCS.Direction(); + gp_Dir gXDir = anchorCS.XDirection(); + gp_Dir gYDir = anchorCS.YDirection(); + gp_Ax1 gUpAxis(gOrg, gYDir); + gp_Ax2 newCS; + gp_Dir gNewDir; + gp_Dir gNewXDir; + double angle = M_PI / 2.0; //90* if (viewType == "Right") { - projDir = DrawUtil::vecRotate(dirAnch,angle,realUp,org); - rotVec = DrawUtil::vecRotate(rotAnch,angle,upAnch,org); + newCS = anchorCS.Rotated(gUpAxis, angle); + projDir = dir2vec(newCS.Direction()); + rotVec = dir2vec(newCS.XDirection()); } else if (viewType == "Left") { - projDir = DrawUtil::vecRotate(dirAnch,-angle,realUp,org); - rotVec = DrawUtil::vecRotate(rotAnch,-angle,upAnch,org); + newCS = anchorCS.Rotated(gUpAxis, -angle); + projDir = dir2vec(newCS.Direction()); + rotVec = dir2vec(newCS.XDirection()); } else if (viewType == "Top") { - projDir = upAnch; - rotVec = rotAnch; + projDir = dir2vec(gYDir); + rotVec = dir2vec(gXDir); } else if (viewType == "Bottom") { - projDir = upAnch * (-1.0); - rotVec = rotAnch; + projDir = dir2vec(gYDir.Reversed()); + rotVec = dir2vec(gXDir); } else if (viewType == "Rear") { - projDir = DrawUtil::vecRotate(dirAnch,2.0 * angle,realUp,org); - rotVec = -rotAnch; + projDir = dir2vec(gDir.Reversed()); + rotVec = dir2vec(gXDir.Reversed()); } else if (viewType == "FrontTopLeft") { - projDir = dirAnch + //front - DrawUtil::vecRotate(dirAnch,-angle,realUp,org) + //left - upAnch; //top - rotVec = rotAnch + dirAnch; //sb current front rot + curr right rot + 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") { - projDir = dirAnch + //front - DrawUtil::vecRotate(dirAnch,angle,realUp,org) + //right - upAnch; //top - rotVec = rotAnch - dirAnch; + 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") { - projDir = dirAnch + //front - DrawUtil::vecRotate(dirAnch,-angle,realUp,org) + //left - upAnch * (-1.0); //bottom - rotVec = rotAnch + dirAnch; + 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") { - projDir = dirAnch + //front - DrawUtil::vecRotate(dirAnch,angle,realUp,org) + //right - upAnch * (-1.0); //bottom - rotVec = rotAnch - dirAnch; + 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 { Base::Console().Error("DrawProjGroup - %s unknown projection: %s\n",getNameInDocument(),viewType.c_str()); return result; @@ -570,6 +596,22 @@ std::pair DrawProjGroup::getDirsFromFront(std::st return result; } +Base::Vector3d DrawProjGroup::dir2vec(gp_Dir d) +{ + Base::Vector3d result(d.X(), + d.Y(), + d.Z()); + return result; +} + +gp_Dir DrawProjGroup::vec2dir(Base::Vector3d v) +{ + gp_Dir result(v.x, + v.y, + v.z); + return result; +} + Base::Vector3d DrawProjGroup::getXYPosition(const char *viewTypeCStr) { Base::Vector3d result(0.0,0.0,0.0); @@ -1030,6 +1072,8 @@ Base::Vector3d DrawProjGroup::getAnchorDirection(void) //* view direction manipulation routines //************************************* +//note: must calculate all the new directions before applying any of them or +// the process will get confused. void DrawProjGroup::updateSecondaryDirs() { DrawProjGroupItem* anchor = getAnchor(); @@ -1040,8 +1084,6 @@ void DrawProjGroup::updateSecondaryDirs() std::string key; std::pair data; for (auto& docObj: Views.getValues()) { - Base::Vector3d newDir; - Base::Vector3d newRot; std::pair newDirs; std::string pic; DrawProjGroupItem* v = static_cast(docObj); @@ -1057,89 +1099,64 @@ void DrawProjGroup::updateSecondaryDirs() key = "Rear"; newDirs = getDirsFromFront(key); saveVals[key] = newDirs; -// newDir = newDirs.first; -// newRot = newDirs.second; break; case Left : key = "Left"; newDirs = getDirsFromFront(key); saveVals[key] = newDirs; -// newDir = newDirs.first; -// newRot = newDirs.second; break; case Right : key = "Right"; newDirs = getDirsFromFront(key); saveVals[key] = newDirs; -// newDir = newDirs.first; -// newRot = newDirs.second; break; case Top : key = "Top"; newDirs = getDirsFromFront(key); saveVals[key] = newDirs; -// newDir = newDirs.first; -// newRot = newDirs.second; break; case Bottom : key = "Bottom"; newDirs = getDirsFromFront(key); saveVals[key] = newDirs; -// newDir = newDirs.first; -// newRot = newDirs.second; break; case FrontTopLeft : key = "FrontTopLeft"; newDirs = getDirsFromFront(key); saveVals[key] = newDirs; -// newDir = newDirs.first; -// newRot = newDirs.second; break; case FrontTopRight : key = "FrontTopRight"; newDirs = getDirsFromFront(key); saveVals[key] = newDirs; -// newDir = newDirs.first; -// newRot = newDirs.second; break; case FrontBottomLeft : key = "FrontBottomLeft"; newDirs = getDirsFromFront(key); saveVals[key] = newDirs; -// newDir = newDirs.first; -// newRot = newDirs.second; break; case FrontBottomRight : key = "FrontBottomRight"; newDirs = getDirsFromFront(key); saveVals[key] = newDirs; - newDir = newDirs.first; - newRot = newDirs.second; break; default: { //TARFU invalid secondary type Base::Console().Message("ERROR - DPG::updateSecondaryDirs - invalid projection type\n"); - newDir = v->Direction.getValue(); - newRot = v->getXDirection(); } } -// v->Direction.setValue(newDir); -// v->XDirection.setValue(newRot); } - //not sure if this is required. for (auto& docObj: Views.getValues()) { DrawProjGroupItem* v = static_cast(docObj); std::string type = v->Type.getValueAsString(); data = saveVals[type]; v->Direction.setValue(data.first); + v->Direction.purgeTouched(); v->XDirection.setValue(data.second); + v->XDirection.purgeTouched(); } - - auto page = findParentPage(); - if (page != nullptr) { - page->requestPaint(); - } + recomputeChildren(); } void DrawProjGroup::rotateRight() diff --git a/src/Mod/TechDraw/App/DrawProjGroup.h b/src/Mod/TechDraw/App/DrawProjGroup.h index 333bd3df1f..15e1989e17 100644 --- a/src/Mod/TechDraw/App/DrawProjGroup.h +++ b/src/Mod/TechDraw/App/DrawProjGroup.h @@ -34,6 +34,9 @@ #include "DrawViewCollection.h" +class gp_Dir; +class gp_Pnt; + namespace TechDraw { @@ -168,6 +171,8 @@ protected: void updateChildrenLock(void); int getViewIndex(const char *viewTypeCStr) const; int getDefProjConv(void) const; + Base::Vector3d dir2vec(gp_Dir d); + gp_Dir vec2dir(Base::Vector3d v); };