From 16ce8d40f583c72b68e928e1da9c1972fc8bb30b Mon Sep 17 00:00:00 2001 From: WandererFan Date: Tue, 27 Dec 2016 19:38:47 -0500 Subject: [PATCH] Section directions from rotated DPGI's --- src/Mod/TechDraw/App/Cube.cpp | 35 ------------- src/Mod/TechDraw/App/Cube.h | 2 - src/Mod/TechDraw/App/DrawProjGroup.cpp | 14 +++--- src/Mod/TechDraw/App/DrawProjGroupItem.cpp | 47 +++++++++++------- src/Mod/TechDraw/App/DrawProjGroupItem.h | 10 ++-- src/Mod/TechDraw/App/DrawUtil.cpp | 12 ++++- src/Mod/TechDraw/App/DrawViewPart.cpp | 7 ++- src/Mod/TechDraw/App/DrawViewSection.cpp | 58 ++++++++++++++++------ src/Mod/TechDraw/App/DrawViewSection.h | 5 +- src/Mod/TechDraw/Gui/TaskProjGroup.cpp | 3 +- src/Mod/TechDraw/Gui/TaskProjGroup.ui | 2 +- src/Mod/TechDraw/Gui/TaskSectionView.cpp | 9 ++-- 12 files changed, 113 insertions(+), 91 deletions(-) diff --git a/src/Mod/TechDraw/App/Cube.cpp b/src/Mod/TechDraw/App/Cube.cpp index 892ad229a2f4..df65fbbe0ff4 100644 --- a/src/Mod/TechDraw/App/Cube.cpp +++ b/src/Mod/TechDraw/App/Cube.cpp @@ -100,7 +100,6 @@ void Cube::rotateUp() updateIsoDirs(); //calculatge iso directions from ortho dirs updateRotsToConfig(getCurrConfig()); //update rotations for ortho views from config table - updateIsoRots(); //calculate iso rotations from iso/ortho dirs } void Cube::rotateDown() @@ -114,7 +113,6 @@ void Cube::rotateDown() updateIsoDirs(); updateRotsToConfig(getCurrConfig()); - updateIsoRots(); } void Cube::rotateRight() @@ -128,7 +126,6 @@ void Cube::rotateRight() updateIsoDirs(); updateRotsToConfig(getCurrConfig()); - updateIsoRots(); } void Cube::rotateLeft() @@ -142,7 +139,6 @@ void Cube::rotateLeft() updateIsoDirs(); updateRotsToConfig(getCurrConfig()); - updateIsoRots(); } void Cube::spinCCW() @@ -156,7 +152,6 @@ void Cube::spinCCW() updateIsoDirs(); updateRotsToConfig(getCurrConfig()); - updateIsoRots(); } void Cube::spinCW() @@ -170,7 +165,6 @@ void Cube::spinCW() updateIsoDirs(); updateRotsToConfig(getCurrConfig()); - updateIsoRots(); } void Cube::updateIsoDirs() @@ -185,18 +179,6 @@ void Cube::updateIsoDirs() m_mapFrameDir.at("FrontTopRight") = frt; } -void Cube::updateIsoRots() -{ -// Base::Vector3d flb = getFrontRot() + getLeftRot() + getBottomRot(); -// Base::Vector3d frb = getFrontRot() + getRightRot() + getBottomRot(); -// Base::Vector3d flt = getFrontRot() + getLeftRot() + getTopRot(); -//// Base::Vector3d frt = getFrontRot() + getRightRot() + getTopRot(); -// m_mapFrameRot.at("FrontBottomLeft") = flb; -// m_mapFrameRot.at("FrontBottomRight") = frb; -// m_mapFrameRot.at("FrontTopLeft") = flt; -//// m_mapFrameRot.at("FrontTopRight") = frt; -} - std::string Cube::dirToView(Base::Vector3d v) { std::string result; @@ -273,18 +255,6 @@ bool Cube::validateBoard(std::string cfg) return result; } -//dupl!! -std::string Cube::getBoardKey() -{ - std::string result; -// Base::Vector3d frontDir = m_mapFrameDir.at("Front"); -// std::string frontView = dirToView(frontDir); -// Base::Vector3d rightDir = m_mapFrameDir.at("Right"); -// std::string rightView = dirToView(rightDir); -// result = frontView + rightView; - return result; -} - //get the current configuration on the board std::string Cube::getCurrConfig(void) { @@ -484,7 +454,6 @@ Base::Vector3d Cube::getFBLRot() { Base::Vector3d result; double magic1 = 157.5 * M_PI / 180.0; // 90 + 45 + magic1 -// double magic1 = -22.5 * M_PI / 180.0; //45*/2 double magic2 = -17.632 * M_PI / 180.0; //±35.264° / 2 "magic angle"?? // <Direction.setValue(m_frameToStdDir.at("Front")); //just (Base::Vector3d(0.0,-1.0,0.0)) - view->OrientBasis.setValue(m_frameToStdRot.at("Front")); + view->RotationVector.setValue(m_frameToStdRot.at("Front")); } else { //TODO: really need to check with Cube to get current dir & rot this uses initial values from table //if (DPGI(front) and DPGI(right) exist) config = front.face + right.face @@ -472,7 +472,7 @@ App::DocumentObject * DrawProjGroup::addProjection(const char *viewProjType) //else // use start up values (m_frameToStdDir/m_frameToStdRot) view->Direction.setValue(m_frameToStdDir.at(viewProjType)); - view->OrientBasis.setValue(m_frameToStdRot.at(viewProjType)); + view->RotationVector.setValue(m_frameToStdRot.at(viewProjType)); } addView(view); //from DrawViewCollection - add to ProjGroup Views @@ -899,11 +899,11 @@ void DrawProjGroup::updateSecondaryDirs() //TARFU invalid secondary type Base::Console().Message("ERROR - DPG::updateSecondaryDirs - invalid projection type\n"); newDir = v->Direction.getValue(); - newAxis = v->OrientBasis.getValue(); + newAxis = v->RotationVector.getValue(); } } v->Direction.setValue(newDir); - v->OrientBasis.setValue(newAxis); + v->RotationVector.setValue(newAxis); v->recomputeFeature(); } } @@ -955,7 +955,7 @@ void DrawProjGroup::spinCCW() // 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 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; @@ -1002,7 +1002,7 @@ void DrawProjGroup::dumpISO(char * title) DrawProjGroupItem* v = static_cast(docObj); std::string t = v->Type.getValueAsString(); dir = v->Direction.getValue(); - axis = v->OrientBasis.getValue(); + axis = v->RotationVector.getValue(); Base::Console().Message("%s: %s/%s\n", t.c_str(),DrawUtil::formatVector(dir).c_str(),DrawUtil::formatVector(axis).c_str()); @@ -1023,7 +1023,7 @@ void DrawProjGroup::onDocumentRestored() } else if (hasProjection("Front")) { Base::Vector3d dirFront = getProjItem("Front")->Direction.getValue(); std::string viewDir = Cube::dirToView(dirFront); - Base::Vector3d rotFront = getProjItem("Rot")->OrientBasis.getValue(); + Base::Vector3d rotFront = getProjItem("Rot")->RotationVector.getValue(); std::string viewRot = Cube::dirToView(rotFront); std::string config = viewDir + viewRot; //find(config) or try/catch diff --git a/src/Mod/TechDraw/App/DrawProjGroupItem.cpp b/src/Mod/TechDraw/App/DrawProjGroupItem.cpp index b50633788921..e53f0069ce88 100644 --- a/src/Mod/TechDraw/App/DrawProjGroupItem.cpp +++ b/src/Mod/TechDraw/App/DrawProjGroupItem.cpp @@ -59,11 +59,11 @@ DrawProjGroupItem::DrawProjGroupItem(void) { Type.setEnums(TypeEnums); ADD_PROPERTY(Type, ((long)0)); - ADD_PROPERTY_TYPE(OrientBasis ,(1.0,0.0,0.0) ,"Base",App::Prop_None,"Controls rotary orientation of item in view. "); + 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); - //OrientBasis.setStatus(App::Property::ReadOnly,true); + RotationVector.setStatus(App::Property::ReadOnly,true); Scale.setStatus(App::Property::ReadOnly,true); ScaleType.setStatus(App::Property::ReadOnly,true); } @@ -73,7 +73,7 @@ short DrawProjGroupItem::mustExecute() const short result = 0; if (!isRestoring()) { result = (Direction.isTouched() || - OrientBasis.isTouched() || + RotationVector.isTouched() || Source.isTouched() || Scale.isTouched() || ScaleType.isTouched()); @@ -121,32 +121,43 @@ gp_Ax2 DrawProjGroupItem::getViewAxis(const Base::Vector3d& pt, const bool flip) const { gp_Ax2 viewAxis; - Base::Vector3d x = OrientBasis.getValue(); + Base::Vector3d x = RotationVector.getValue(); Base::Vector3d nx = x; x.Normalize(); Base::Vector3d na = axis; na.Normalize(); - - if (DrawUtil::checkParallel(nx,na)) { //parallel/antiparallel - viewAxis = TechDrawGeometry::getViewAxis(pt,axis,flip); //use default orientation - } else { + viewAxis = TechDrawGeometry::getViewAxis(pt,axis,flip); //default orientation + + if (!DrawUtil::checkParallel(nx,na)) { //!parallel/antiparallel viewAxis = TechDrawGeometry::getViewAxis(pt,axis,x,flip); } - return viewAxis; } -//! rotate OrientBasis by angle radians around view Direction -Base::Vector3d DrawProjGroupItem::rotated(const double angle) +//get the angle between the current RotationVector vector and the original X dir angle +double DrawProjGroupItem::getRotateAngle() { - Base::Vector3d line = Direction.getValue(); - Base::Vector3d oldBasis = OrientBasis.getValue(); - Base::Vector3d newBasis; + gp_Ax2 viewAxis; + Base::Vector3d x = RotationVector.getValue(); //current rotation + Base::Vector3d nx = x; + x.Normalize(); + Base::Vector3d na = Direction.getValue(); + na.Normalize(); Base::Vector3d org(0.0,0.0,0.0); - Base::Matrix4D xForm; - xForm.rotLine(line,angle); - newBasis = xForm * (oldBasis); - return newBasis; + + viewAxis = TechDrawGeometry::getViewAxis(org,na,true); //default orientation + + gp_Dir gxDir = viewAxis.XDirection(); + Base::Vector3d origX(gxDir.X(),gxDir.Y(),gxDir.Z()); + origX.Normalize(); + double dot = fabs(origX.Dot(nx)); + double angle = acos(dot); + + Base::Vector3d rotAxis = origX.Cross(nx); + if (rotAxis == Direction.getValue()) { + angle *= -1.0; + } + return angle; } PyObject *DrawProjGroupItem::getPyObject(void) diff --git a/src/Mod/TechDraw/App/DrawProjGroupItem.h b/src/Mod/TechDraw/App/DrawProjGroupItem.h index 739dac7c0ac6..ac831f82a3bb 100644 --- a/src/Mod/TechDraw/App/DrawProjGroupItem.h +++ b/src/Mod/TechDraw/App/DrawProjGroupItem.h @@ -23,6 +23,8 @@ #ifndef _DrawProjGroupItem_h_ #define _DrawProjGroupItem_h_ +#include + #include #include #include @@ -54,7 +56,7 @@ class TechDrawExport DrawProjGroupItem : public TechDraw::DrawViewPart ~DrawProjGroupItem(); App::PropertyEnumeration Type; - App::PropertyVector OrientBasis; + App::PropertyVector RotationVector; short mustExecute() const; /** @name methods overide Feature */ @@ -65,6 +67,7 @@ class TechDrawExport DrawProjGroupItem : public TechDraw::DrawViewPart //@} DrawProjGroup* getGroup(void) const; + double getRotateAngle(); /// returns the type name of the ViewProvider virtual const char* getViewProviderName(void) const { @@ -72,15 +75,14 @@ class TechDrawExport DrawProjGroupItem : public TechDraw::DrawViewPart } //return PyObject as DrawProjGroupItemPy virtual PyObject *getPyObject(void); -//************************************ - Base::Vector3d rotated(const double angle) ; + virtual gp_Ax2 getViewAxis(const Base::Vector3d& pt, const Base::Vector3d& direction, const bool flip=true) const override; protected: - /// Called by the container when a Property was changed void onChanged(const App::Property* prop); + private: static const char* TypeEnums[]; }; diff --git a/src/Mod/TechDraw/App/DrawUtil.cpp b/src/Mod/TechDraw/App/DrawUtil.cpp index 6a8af27a331c..db00a2154c07 100644 --- a/src/Mod/TechDraw/App/DrawUtil.cpp +++ b/src/Mod/TechDraw/App/DrawUtil.cpp @@ -354,7 +354,17 @@ Base::Vector3d DrawUtil::closestBasis(Base::Vector3d v) Base::Vector3d stdYr(0.0,-1.0,0.0); Base::Vector3d stdZr(0.0,0.0,-1.0); double angleX,angleY,angleZ,angleXr,angleYr,angleZr, angleMin; - + + //first check if already a basis + if (checkParallel(v,stdZ)) { + return v; + } else if (checkParallel(v,stdY)) { + return v; + } else if (checkParallel(v,stdX)) { + return v; + } + + //not a basis. find smallest angle with a basis. angleX = stdX.GetAngle(v); angleY = stdY.GetAngle(v); angleZ = stdZ.GetAngle(v); diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index 9b288c1e484b..ca58c4855a41 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -156,7 +156,7 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void) if (shape.IsNull()) { return new App::DocumentObjectExecReturn("FVP - Linked shape object is empty"); } -// Base::Console().Message("TRACE - DVP::execute() - %s - %s - dir: %s\n",getNameInDocument(), Label.getValue(),DrawUtil::formatVector(Direction.getValue()).c_str()); + //Base::Console().Message("TRACE - DVP::execute() - %s - %s - dir: %s\n",getNameInDocument(), Label.getValue(),DrawUtil::formatVector(Direction.getValue()).c_str()); (void) DrawView::execute(); //make sure Scale is up to date @@ -173,6 +173,9 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void) gp_Ax2 viewAxis = getViewAxis(shapeCentroid,Direction.getValue()); geometryObject = buildGeometryObject(mirroredShape,viewAxis); + + //Base::Console().Message("TRACE - DVP::execute - u: %s v: %s w: %s\n", + // DrawUtil::formatVector(getUDir()).c_str(), DrawUtil::formatVector(getVDir()).c_str(), DrawUtil::formatVector(getWDir()).c_str()); #if MOD_TECHDRAW_HANDLE_FACES if (handleFaces()) { @@ -523,9 +526,9 @@ gp_Ax2 DrawViewPart::getViewAxis(const Base::Vector3d& pt, return viewAxis; } -//this might have to be virtual for dpgi? void DrawViewPart::saveParamSpace(const Base::Vector3d& direction, const Base::Vector3d& xAxis) { + //Base::Console().Message("TRACE - DVP::saveParamSpace()\n"); (void)xAxis; Base::Vector3d origin(0.0,0.0,0.0); gp_Ax2 viewAxis = getViewAxis(origin,direction); diff --git a/src/Mod/TechDraw/App/DrawViewSection.cpp b/src/Mod/TechDraw/App/DrawViewSection.cpp index 1f97d8b777f0..55dbd10ce0fb 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.cpp +++ b/src/Mod/TechDraw/App/DrawViewSection.cpp @@ -75,6 +75,7 @@ #include "GeometryObject.h" #include "EdgeWalker.h" #include "DrawUtil.h" +#include "DrawProjGroupItem.h" #include "DrawProjectSplit.h" #include "DrawViewSection.h" @@ -452,34 +453,43 @@ bool DrawViewSection::isReallyInBox (const Base::Vector3d v, const Base::BoundBo } //! calculate the section Normal/Projection Direction given baseView projection direction and section name -/*static*/ -Base::Vector3d DrawViewSection::getSectionVector (const Base::Vector3d baseViewDir, const std::string sectionName) +Base::Vector3d DrawViewSection::getSectionVector (const std::string sectionName) { Base::Vector3d result; Base::Vector3d stdX(1.0,0.0,0.0); Base::Vector3d stdY(0.0,1.0,0.0); Base::Vector3d stdZ(0.0,0.0,1.0); - Base::Vector3d view = baseViewDir; + + double adjustAngle = 0.0; + if (getBaseDPGI() != nullptr) { + adjustAngle = getBaseDPGI()->getRotateAngle(); + } + + Base::Vector3d view = getBaseDVP()->Direction.getValue(); view.Normalize(); Base::Vector3d left = view.Cross(stdZ); - left.Normalize(); //redundent? - Base::Vector3d down = view.Cross(left); - down.Normalize(); //redundent? + left.Normalize(); + Base::Vector3d up = view.Cross(left); + up.Normalize(); double dot = view.Dot(stdZ); if (sectionName == "Up") { - result = down; - if (DrawUtil::fpCompare(fabs(dot),1.0)) { - result = (-1.0 * stdY); + result = up; + if (DrawUtil::fpCompare(dot,1.0)) { //view = stdZ + result = (-1.0 * stdY); + } else if (DrawUtil::fpCompare(dot,-1.0)) { //view = -stdZ + result = stdY; } } else if (sectionName == "Down") { - result = down * -1.0; - if (DrawUtil::fpCompare(fabs(dot),1.0)) { + result = up * -1.0; + if (DrawUtil::fpCompare(dot,1.0)) { //view = stdZ result = stdY; + } else if (DrawUtil::fpCompare(dot, -1.0)) { //view = -stdZ + result = (-1.0 * stdY); } } else if (sectionName == "Left") { result = left * -1.0; - if (DrawUtil::fpCompare(fabs(dot),1.0)) { + if (DrawUtil::fpCompare(fabs(dot),1.0)) { //view = +/- stdZ result = stdX; } } else if (sectionName == "Right") { @@ -491,8 +501,28 @@ Base::Vector3d DrawViewSection::getSectionVector (const Base::Vector3d baseViewD Base::Console().Log("Error - DVS::getSectionVector - bad sectionName: %s\n",sectionName.c_str()); result = stdZ; } - - return result; + Base::Vector3d adjResult = DrawUtil::vecRotate(result,adjustAngle,view); + return adjResult; +} + +TechDraw::DrawViewPart* DrawViewSection::getBaseDVP() +{ + TechDraw::DrawViewPart* baseDVP = nullptr; + App::DocumentObject* base = BaseView.getValue(); + if (base->getTypeId().isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) { + baseDVP = static_cast(base); + } + return baseDVP; +} + +TechDraw::DrawProjGroupItem* DrawViewSection::getBaseDPGI() +{ + TechDraw::DrawProjGroupItem* baseDPGI = nullptr; + App::DocumentObject* base = BaseView.getValue(); + if (base->getTypeId().isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) { + baseDPGI = static_cast(base); + } + return baseDPGI; } void DrawViewSection::getParameters() diff --git a/src/Mod/TechDraw/App/DrawViewSection.h b/src/Mod/TechDraw/App/DrawViewSection.h index cc1afe8fd85e..5096ef1d087e 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.h +++ b/src/Mod/TechDraw/App/DrawViewSection.h @@ -44,6 +44,7 @@ class Face; namespace TechDraw { +class DrawProjGroupItem; /** Base class of all View Features in the drawing module @@ -84,7 +85,9 @@ class TechDrawExport DrawViewSection : public DrawViewPart public: std::vector getFaceGeometry(); - static Base::Vector3d getSectionVector (const Base::Vector3d baseViewDir, const std::string sectionName); + Base::Vector3d getSectionVector (const std::string sectionName); + TechDraw::DrawViewPart* getBaseDVP(); + TechDraw::DrawProjGroupItem* getBaseDPGI(); static const char* SectionDirEnums[]; diff --git a/src/Mod/TechDraw/Gui/TaskProjGroup.cpp b/src/Mod/TechDraw/Gui/TaskProjGroup.cpp index 3aa270e7d15b..aadf659fa0bd 100644 --- a/src/Mod/TechDraw/Gui/TaskProjGroup.cpp +++ b/src/Mod/TechDraw/Gui/TaskProjGroup.cpp @@ -178,8 +178,9 @@ 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); diff --git a/src/Mod/TechDraw/Gui/TaskProjGroup.ui b/src/Mod/TechDraw/Gui/TaskProjGroup.ui index 0a95b2940727..3c58068c300b 100644 --- a/src/Mod/TechDraw/Gui/TaskProjGroup.ui +++ b/src/Mod/TechDraw/Gui/TaskProjGroup.ui @@ -312,7 +312,7 @@ true - Set Primary Direction to match 3D + Try to match Primary Direction to 3D view Match 3D diff --git a/src/Mod/TechDraw/Gui/TaskSectionView.cpp b/src/Mod/TechDraw/Gui/TaskSectionView.cpp index c29d26be4769..877d8cac1ba9 100644 --- a/src/Mod/TechDraw/Gui/TaskSectionView.cpp +++ b/src/Mod/TechDraw/Gui/TaskSectionView.cpp @@ -121,20 +121,19 @@ void TaskSectionView::resetValues() bool TaskSectionView::calcValues() { bool result = true; - Base::Vector3d view = m_base->Direction.getValue(); if (ui->pb_Up->isChecked()) { sectionDir = "Up"; - sectionProjDir = DrawViewSection::getSectionVector(view,sectionDir); + sectionProjDir = m_section->getSectionVector(sectionDir); } else if (ui->pb_Down->isChecked()) { sectionDir = "Down"; - sectionProjDir = DrawViewSection::getSectionVector(view,sectionDir); + sectionProjDir = m_section->getSectionVector(sectionDir); } else if (ui->pb_Left->isChecked()) { sectionDir = "Left"; - sectionProjDir = DrawViewSection::getSectionVector(view,sectionDir); + sectionProjDir = m_section->getSectionVector(sectionDir); } else if (ui->pb_Right->isChecked()) { sectionDir = "Right"; - sectionProjDir = DrawViewSection::getSectionVector(view,sectionDir); + sectionProjDir = m_section->getSectionVector(sectionDir); } else { Base::Console().Message("Select a direction\n"); result = false;