From b7e8ad9a4e5f28284ba4ba3edda9a65d224cb838 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Wed, 24 Jun 2020 21:04:03 -0400 Subject: [PATCH] [TD]DPG spacing for oblique views --- src/Mod/TechDraw/App/DrawProjGroup.cpp | 132 ++++++++++++++++-------- src/Mod/TechDraw/App/DrawViewPart.cpp | 6 +- src/Mod/TechDraw/App/DrawViewPart.h | 3 +- src/Mod/TechDraw/App/GeometryObject.cpp | 3 +- src/Mod/TechDraw/Gui/QGIView.cpp | 12 +++ src/Mod/TechDraw/Gui/QGIViewPart.cpp | 1 + 6 files changed, 107 insertions(+), 50 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawProjGroup.cpp b/src/Mod/TechDraw/App/DrawProjGroup.cpp index fca8658170..9dd37ac7c1 100644 --- a/src/Mod/TechDraw/App/DrawProjGroup.cpp +++ b/src/Mod/TechDraw/App/DrawProjGroup.cpp @@ -663,16 +663,8 @@ Base::Vector3d DrawProjGroup::getXYPosition(const char *viewTypeCStr) //TODO: bounding boxes do not take view orientation into account // i.e. X&Y widths might be swapped on page - // if (AutoDistribute.getValue()) { - if (true) { + if (AutoDistribute.getValue()) { std::vector position(idxCount); - int idx = 0; - for (;idx < idxCount; idx++) { - if (viewPtrs[idx]) { - position[idx].x = viewPtrs[idx]->X.getValue(); - position[idx].y = viewPtrs[idx]->Y.getValue(); - } - } // Calculate bounding boxes for each displayed view Base::BoundBox3d bboxes[10]; @@ -681,87 +673,136 @@ Base::Vector3d DrawProjGroup::getXYPosition(const char *viewTypeCStr) double xSpacing = spacingX.getValue(); //in mm, no scale double ySpacing = spacingY.getValue(); //in mm, no scale + std::vector xOff; + std::vector yOff; double bigRow = 0.0; double bigCol = 0.0; + int ibbx = 0; for (auto& b: bboxes) { //space based on width/height of biggest view if (!b.IsValid()) { + Base::Console().Message("DVP::getXYPos - bbox %d is not valid!\n"); continue; } + double xOffset = -( (b.LengthX() / 2.0) + b.MinX ); //scaled distance to move to zero + double yOffset = -( (b.LengthY() / 2.0) + b.MinY ); + xOff.push_back(xOffset); + yOff.push_back(yOffset); if (b.LengthX() > bigCol) { bigCol = b.LengthX(); } if (b.LengthY() > bigRow) { bigRow = b.LengthY(); } + ibbx++; } + double xOffFront = -( (bboxes[4].LengthX() / 2.0) + bboxes[4].MinX ); + double yOffFront = -( (bboxes[4].LengthY() / 2.0) + bboxes[4].MinY ); + //if we have iso's, make sure they fit the grid. if (viewPtrs[0] || viewPtrs[2] || viewPtrs[7] || viewPtrs[9]) { bigCol = std::max(bigCol,bigRow); bigRow = bigCol; } - //TODO: find biggest for each row/column and adjust calculation to use bigCol[i], bigRow[j] ????? - if (viewPtrs[0] && //iso - bboxes[0].IsValid()) { - position[0].x = -bigCol - xSpacing; - position[0].y = bigRow + ySpacing; - } - if (viewPtrs[1] && // T/B - bboxes[1].IsValid()) { - position[1].x = 0.0; - position[1].y = bigRow + ySpacing; - } - if (viewPtrs[2] && //iso - bboxes[2].IsValid()) { - position[2].x = bigCol + xSpacing; - position[2].y = bigRow + ySpacing; - } - if (viewPtrs[3] && // L/R - bboxes[3].IsValid() && - bboxes[4].IsValid()) { - position[3].x = -bigCol - xSpacing; - position[3].y = 0.0; - } if (viewPtrs[4] && //Front bboxes[4].IsValid()) { position[4].x = 0.0; position[4].y = 0.0; } - if (viewPtrs[5] && // R/L + + if (viewPtrs[3] && // L/R (third/first) + bboxes[3].IsValid() && + bboxes[4].IsValid()) { + double netOffset = xOff[3] - xOffFront; + double xOffBig = -(bigCol - bboxes[3].LengthX()) / 2.0; + position[3].x = -bigCol - xSpacing + netOffset - xOffBig; + position[3].y = 0.0; + } + + if (viewPtrs[5] && // R/L (third/first) bboxes[5].IsValid() && bboxes[4].IsValid()) { - position[5].x = bigCol + xSpacing; + double netOffset = xOff[5] - xOffFront; + double xOffBig = -(bigCol - bboxes[5].LengthX()) / 2.0; + position[5].x = bigCol + xSpacing + netOffset + xOffBig; position[5].y = 0.0; } + if (viewPtrs[6] && bboxes[6].IsValid()) { //"Rear" if (viewPtrs[5] && bboxes[5].IsValid()) { - position[6].x = position[5].x + bigCol + xSpacing; + double netOffset = xOff[5] - xOff[6]; + position[6].x = position[5].x + bigCol + xSpacing - netOffset; position[6].y = 0.0; - }else if (viewPtrs[4] && + } else if (viewPtrs[4] && bboxes[4].IsValid()) { - position[6].x = bigCol + xSpacing; + double netOffset = xOff[6] - xOff[5]; + double xOffBig = -(bigCol - bboxes[6].LengthX()) / 2.0; + position[6].x = bigCol + xSpacing + netOffset + xOffBig; position[6].y = 0.0; } } - if (viewPtrs[7] && - bboxes[7].IsValid()) { //iso - position[7].x = -bigCol - xSpacing; - position[7].y = -bigRow - ySpacing; + + if (viewPtrs[1] && // T/B (third/first) + bboxes[1].IsValid() && + bboxes[4].IsValid()) { + double netOffset = -yOff[1] + yOffFront; + double yOffBig = -(bigRow - bboxes[1].LengthY()) / 2.0; + position[1].x = 0.0; + position[1].y = bigRow + ySpacing + netOffset + yOffBig; } - if (viewPtrs[8] && // B/T + + if (viewPtrs[8] && // B/T (third/first) bboxes[8].IsValid() && bboxes[4].IsValid()) { + double netOffset = -yOff[8] + yOffFront; + double yOffBig = -(bigRow - bboxes[8].LengthY()) / 2.0; position[8].x = 0.0; - position[8].y = -bigRow - ySpacing; + position[8].y = -bigRow - ySpacing + netOffset + yOffBig; } - if (viewPtrs[9] && //iso + + if (viewPtrs[0] && + bboxes[0].IsValid()) { + double netOffset = xOff[0] - xOffFront; + double xOffBig = -(bigCol - bboxes[0].LengthX()) / 2.0; + position[0].x = -bigCol - xSpacing + netOffset - xOffBig; + netOffset = -yOff[0] + yOffFront; + double yOffBig = -(bigRow - bboxes[0].LengthY()) / 2.0; + position[0].y = bigRow + ySpacing + netOffset + yOffBig; + } + + if (viewPtrs[2] && + bboxes[2].IsValid()) { + double netOffset = xOff[2] - xOffFront; + double xOffBig = -(bigCol - bboxes[2].LengthX()) / 2.0; + position[2].x = bigCol + xSpacing + netOffset + xOffBig; + netOffset = -yOff[2] + yOffFront; + double yOffBig = -(bigRow - bboxes[2].LengthY()) / 2.0; + position[2].y = bigRow + ySpacing + netOffset + yOffBig; + } + + if (viewPtrs[7] && + bboxes[7].IsValid()) { + double netOffset = xOff[7] - xOffFront; + double xOffBig = -(bigCol - bboxes[7].LengthX()) / 2.0; + position[7].x = - bigCol - xSpacing + netOffset - xOffBig; + netOffset = -yOff[7] + yOffFront; + double yOffBig = -(bigRow - bboxes[7].LengthY()) / 2.0; + position[7].y = -bigRow - ySpacing + netOffset + yOffBig; + } + + if (viewPtrs[9] && bboxes[9].IsValid()) { - position[9].x = bigCol + xSpacing; - position[9].y = -bigRow - ySpacing; + double netOffset = xOff[9] - xOffFront; + double xOffBig = -(bigCol - bboxes[9].LengthX()) / 2.0; + position[9].x = bigCol + xSpacing + netOffset + xOffBig; + netOffset = -yOff[9] + yOffFront; + double yOffBig = -(bigRow - bboxes[9].LengthY()) / 2.0; + position[9].y = -bigRow - ySpacing + netOffset + yOffBig; } + result.x = position[viewIndex].x; result.y = position[viewIndex].y; } else { @@ -918,6 +959,7 @@ void DrawProjGroup::makeViewBbs(DrawProjGroupItem *viewPtrs[10], bboxes[i] = empty; if (viewPtrs[i]) { bboxes[i] = viewPtrs[i]->getBoundingBox(); +// bboxes[i] = viewPtrs[i]->getBoundingBox(viewPtrs[i]->getProjectionCS(Base::Vector3d(0.0, 0.0, 0.0))); if (!documentScale) { double scale = 1.0 / viewPtrs[i]->getScale(); //convert bbx to 1:1 scale bboxes[i].ScaleX(scale); diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index d22fac572d..08dc544e0d 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -823,7 +823,7 @@ QRectF DrawViewPart::getRect() const } //used to project a pt (ex SectionOrigin) onto paper plane -Base::Vector3d DrawViewPart::projectPoint(const Base::Vector3d& pt) const +Base::Vector3d DrawViewPart::projectPoint(const Base::Vector3d& pt, bool invert) const { // Base::Console().Message("DVP::projectPoint()\n"); Base::Vector3d stdOrg(0.0,0.0,0.0); @@ -834,7 +834,9 @@ Base::Vector3d DrawViewPart::projectPoint(const Base::Vector3d& pt) const gp_Pnt2d prjPnt; projector.Project(gPt, prjPnt); Base::Vector3d result(prjPnt.X(),prjPnt.Y(), 0.0); - result = DrawUtil::invertY(result); + if (invert) { + result = DrawUtil::invertY(result); + } return result; } diff --git a/src/Mod/TechDraw/App/DrawViewPart.h b/src/Mod/TechDraw/App/DrawViewPart.h index c366e44823..03a668d354 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.h +++ b/src/Mod/TechDraw/App/DrawViewPart.h @@ -146,7 +146,8 @@ public: virtual std::vector getDetailRefs() const; - virtual Base::Vector3d projectPoint(const Base::Vector3d& pt) const; + virtual Base::Vector3d projectPoint(const Base::Vector3d& pt, + bool invert = true) const; virtual BaseGeom* projectEdge(const TopoDS_Edge& e) const; virtual gp_Ax2 getViewAxis(const Base::Vector3d& pt, diff --git a/src/Mod/TechDraw/App/GeometryObject.cpp b/src/Mod/TechDraw/App/GeometryObject.cpp index 1c5d19d3c4..9b05c37870 100644 --- a/src/Mod/TechDraw/App/GeometryObject.cpp +++ b/src/Mod/TechDraw/App/GeometryObject.cpp @@ -788,6 +788,7 @@ Base::BoundBox3d GeometryObject::calcBoundingBox() const BRepBndLib::Add((*it)->occEdge, testBox); } } + double xMin = 0,xMax = 0,yMin = 0,yMax = 0, zMin = 0, zMax = 0; if (testBox.IsVoid()) { @@ -815,8 +816,6 @@ void GeometryObject::pruneVertexGeom(Base::Vector3d center, double radius) vertexGeom = newVerts; } - - //! does this GeometryObject already have this vertex bool GeometryObject::findVertex(Base::Vector3d v) { diff --git a/src/Mod/TechDraw/Gui/QGIView.cpp b/src/Mod/TechDraw/Gui/QGIView.cpp index 056ddf7953..cd8dfff134 100644 --- a/src/Mod/TechDraw/Gui/QGIView.cpp +++ b/src/Mod/TechDraw/Gui/QGIView.cpp @@ -424,6 +424,18 @@ void QGIView::draw() if (getViewObject() != nullptr) { x = Rez::guiX(getViewObject()->X.getValue()); y = Rez::guiX(getViewObject()->Y.getValue()); + if (getFrameState()) { + //+/- space for label if DPGI + TechDraw::DrawProjGroupItem* dpgi = dynamic_cast(getViewObject()); + if (dpgi != nullptr) { + double vertLabelSpace = Rez::guiX(Preferences::labelFontSizeMM()); + if (y > 0) { + y += vertLabelSpace; + } else if (y < 0) { + y -= vertLabelSpace; + } + } + } setPosition(x, y); } if (isVisible()) { diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.cpp b/src/Mod/TechDraw/Gui/QGIViewPart.cpp index fad1b8002a..0be0303ecb 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewPart.cpp @@ -59,6 +59,7 @@ #include #include #include +#include #include #include //#include