From 44fd20016602310434315a65ebf4bde8ec1a2d7e Mon Sep 17 00:00:00 2001 From: WandererFan Date: Thu, 19 Oct 2017 20:17:11 -0400 Subject: [PATCH] Rotate DrawViewPart around part centroid --- src/Mod/TechDraw/App/DrawViewDetail.cpp | 5 +++++ src/Mod/TechDraw/App/DrawViewMulti.cpp | 6 ++++++ src/Mod/TechDraw/App/DrawViewPart.cpp | 5 +++++ src/Mod/TechDraw/App/DrawViewSection.cpp | 11 ++++++++++ src/Mod/TechDraw/App/GeometryObject.cpp | 26 ++++++++++++++++++++++++ src/Mod/TechDraw/App/GeometryObject.h | 5 +++++ src/Mod/TechDraw/Gui/QGIView.cpp | 20 +++++++++++------- src/Mod/TechDraw/Gui/QGIView.h | 1 + src/Mod/TechDraw/Gui/QGIViewPart.cpp | 23 +++++++++++++-------- src/Mod/TechDraw/Gui/QGIViewPart.h | 2 ++ 10 files changed, 89 insertions(+), 15 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawViewDetail.cpp b/src/Mod/TechDraw/App/DrawViewDetail.cpp index 4e1cc491bb..17344252eb 100644 --- a/src/Mod/TechDraw/App/DrawViewDetail.cpp +++ b/src/Mod/TechDraw/App/DrawViewDetail.cpp @@ -249,6 +249,11 @@ App::DocumentObjectExecReturn *DrawViewDetail::execute(void) inputCenter, scale); gp_Ax2 viewAxis = getViewAxis(Base::Vector3d(inputCenter.X(),inputCenter.Y(),inputCenter.Z()),Direction.getValue()); + if (!DrawUtil::fpCompare(Rotation.getValue(),0.0)) { + mirroredShape = TechDrawGeometry::rotateShape(mirroredShape, + viewAxis, + Rotation.getValue()); + } geometryObject = buildGeometryObject(mirroredShape,viewAxis); geometryObject->pruneVertexGeom(Base::Vector3d(0.0,0.0,0.0),Radius.getValue() * scale); //remove vertices beyond clipradius diff --git a/src/Mod/TechDraw/App/DrawViewMulti.cpp b/src/Mod/TechDraw/App/DrawViewMulti.cpp index a5331130c4..8a5bb5c8b2 100644 --- a/src/Mod/TechDraw/App/DrawViewMulti.cpp +++ b/src/Mod/TechDraw/App/DrawViewMulti.cpp @@ -61,6 +61,7 @@ #include "Geometry.h" #include "GeometryObject.h" +#include "DrawUtil.h" #include "DrawViewMulti.h" using namespace TechDraw; @@ -179,6 +180,11 @@ App::DocumentObjectExecReturn *DrawViewMulti::execute(void) inputCenter, getScale()); gp_Ax2 viewAxis = getViewAxis(Base::Vector3d(inputCenter.X(),inputCenter.Y(),inputCenter.Z()),Direction.getValue()); + if (!DrawUtil::fpCompare(Rotation.getValue(),0.0)) { + mirroredShape = TechDrawGeometry::rotateShape(mirroredShape, + viewAxis, + Rotation.getValue()); + } geometryObject = buildGeometryObject(mirroredShape,viewAxis); #if MOD_TECHDRAW_HANDLE_FACES diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index 5c9c54133b..096d85b969 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -218,6 +218,11 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void) getScale()); gp_Ax2 viewAxis = getViewAxis(shapeCentroid,Direction.getValue()); + if (!DrawUtil::fpCompare(Rotation.getValue(),0.0)) { + mirroredShape = TechDrawGeometry::rotateShape(mirroredShape, + viewAxis, + Rotation.getValue()); + } geometryObject = buildGeometryObject(mirroredShape,viewAxis); #if MOD_TECHDRAW_HANDLE_FACES diff --git a/src/Mod/TechDraw/App/DrawViewSection.cpp b/src/Mod/TechDraw/App/DrawViewSection.cpp index dddf990f1b..69ceec3f06 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.cpp +++ b/src/Mod/TechDraw/App/DrawViewSection.cpp @@ -260,6 +260,11 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void) inputCenter, getScale()); gp_Ax2 viewAxis = getViewAxis(Base::Vector3d(inputCenter.X(),inputCenter.Y(),inputCenter.Z()),Direction.getValue()); + if (!DrawUtil::fpCompare(Rotation.getValue(),0.0)) { + mirroredShape = TechDrawGeometry::rotateShape(mirroredShape, + viewAxis, + Rotation.getValue()); + } geometryObject = buildGeometryObject(mirroredShape,viewAxis); //this is original shape after cut by section prism #if MOD_TECHDRAW_HANDLE_FACES @@ -276,6 +281,12 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void) TopoDS_Shape mirroredSection = TechDrawGeometry::mirrorShape(sectionCompound, inputCenter, getScale()); + gp_Ax2 viewAxis = getViewAxis(Base::Vector3d(inputCenter.X(),inputCenter.Y(),inputCenter.Z()),Direction.getValue()); + if (!DrawUtil::fpCompare(Rotation.getValue(),0.0)) { + mirroredSection = TechDrawGeometry::rotateShape(mirroredSection, + viewAxis, + Rotation.getValue()); + } sectionFaceWires.clear(); TopoDS_Compound newFaces; diff --git a/src/Mod/TechDraw/App/GeometryObject.cpp b/src/Mod/TechDraw/App/GeometryObject.cpp index 7602bbba9f..a19bcbbb99 100644 --- a/src/Mod/TechDraw/App/GeometryObject.cpp +++ b/src/Mod/TechDraw/App/GeometryObject.cpp @@ -561,6 +561,32 @@ TopoDS_Shape TechDrawGeometry::mirrorShape(const TopoDS_Shape &input, return transShape; } +//!rotates a shape about a viewAxis +TopoDS_Shape TechDrawGeometry::rotateShape(const TopoDS_Shape &input, + gp_Ax2& viewAxis, + double rotAngle) +{ + TopoDS_Shape transShape; + if (input.IsNull()) { + return transShape; + } + + gp_Ax1 rotAxis = viewAxis.Axis(); + double rotation = rotAngle * M_PI/180.0; + + try { + gp_Trsf tempTransform; + tempTransform.SetRotation(rotAxis,rotation); + BRepBuilderAPI_Transform mkTrf(input, tempTransform); + transShape = mkTrf.Shape(); + } + catch (...) { + Base::Console().Log("GeometryObject::rotateShape - rotate failed.\n"); + return transShape; + } + return transShape; +} + //!scales a shape about a origin TopoDS_Shape TechDrawGeometry::scaleShape(const TopoDS_Shape &input, double scale) diff --git a/src/Mod/TechDraw/App/GeometryObject.h b/src/Mod/TechDraw/App/GeometryObject.h index d6a411edde..45c9dbb122 100644 --- a/src/Mod/TechDraw/App/GeometryObject.h +++ b/src/Mod/TechDraw/App/GeometryObject.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -55,6 +56,10 @@ TopoDS_Shape TechDrawExport mirrorShape(const TopoDS_Shape &input, double scale = 1.0); TopoDS_Shape TechDrawExport scaleShape(const TopoDS_Shape &input, double scale); +TopoDS_Shape TechDrawExport rotateShape(const TopoDS_Shape &input, + gp_Ax2& viewAxis, + double rotAngle); + //! Returns the centroid of shape, as viewed according to direction gp_Pnt TechDrawExport findCentroid(const TopoDS_Shape &shape, diff --git a/src/Mod/TechDraw/Gui/QGIView.cpp b/src/Mod/TechDraw/Gui/QGIView.cpp index 0d9f2f8e6e..f6eb071714 100644 --- a/src/Mod/TechDraw/Gui/QGIView.cpp +++ b/src/Mod/TechDraw/Gui/QGIView.cpp @@ -267,19 +267,25 @@ void QGIView::updateView(bool update) if (update || getViewObject()->Rotation.isTouched() ) { - //NOTE: QPainterPaths have to be rotated individually. This transform handles Rotation for everything else. - //Scale is handled in GeometryObject for DVP & descendents - //Objects not descended from DVP must setScale for themselves - //note that setTransform(,,rotation,,) is not the same as setRotation!!! - double rot = getViewObject()->Rotation.getValue(); - QPointF centre = boundingRect().center(); - setTransform(QTransform().translate(centre.x(), centre.y()).rotate(-rot).translate(-centre.x(), -centre.y())); + rotateView(); } if (update) QGraphicsItem::update(); } +//QGIVP derived classes do not need a rotate view method as rotation is handled on App side. +void QGIView::rotateView(void) +{ +//NOTE: QPainterPaths have to be rotated individually. This transform handles Rotation for everything else. +//Scale is handled in GeometryObject for DVP & descendents +//Objects not descended from DVP must setScale for themselves +//note that setTransform(,,rotation,,) is not the same as setRotation!!! + double rot = getViewObject()->Rotation.getValue(); + QPointF centre = boundingRect().center(); + setTransform(QTransform().translate(centre.x(), centre.y()).rotate(-rot).translate(-centre.x(), -centre.y())); +} + const char * QGIView::getViewName() const { return viewName.c_str(); diff --git a/src/Mod/TechDraw/Gui/QGIView.h b/src/Mod/TechDraw/Gui/QGIView.h index eb217b32f5..f319cb07a1 100644 --- a/src/Mod/TechDraw/Gui/QGIView.h +++ b/src/Mod/TechDraw/Gui/QGIView.h @@ -73,6 +73,7 @@ public: virtual bool isVisible(void) {return m_visibility;}; virtual void draw(void); virtual void drawCaption(void); + virtual void rotateView(void); /** Methods to ensure that Y-Coordinates are orientated correctly. * @{ */ diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.cpp b/src/Mod/TechDraw/Gui/QGIViewPart.cpp index 35e5b9c900..90c021b7de 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewPart.cpp @@ -147,6 +147,7 @@ QPainterPath QGIViewPart::drawPainterPath(TechDrawGeometry::BaseGeom *baseGeom) QPainterPath QGIViewPart::geomToPainterPath(TechDrawGeometry::BaseGeom *baseGeom, double rot) { + Q_UNUSED(rot); QPainterPath path; switch(baseGeom->geomType) { @@ -291,11 +292,12 @@ QPainterPath QGIViewPart::geomToPainterPath(TechDrawGeometry::BaseGeom *baseGeom break; } - if (rot != 0.0) { - QTransform t; - t.rotate(-rot); - path = t.map(path); - } +//old rotate path logic. now done on App side. +// if (rot != 0.0) { +// QTransform t; +// t.rotate(-rot); +// path = t.map(path); +// } return path; } @@ -643,7 +645,7 @@ void QGIViewPart::drawSectionLine(TechDraw::DrawViewSection* viewSection, bool b sectionLine->setWidth(Rez::guiX(viewPart->LineWidth.getValue())); //TODO: add fudge to make sectionLine thinner than reg lines? sectionLine->setFont(m_font,Rez::guiX(6.0)); sectionLine->setZValue(ZVALUE::SECTIONLINE); - sectionLine->setRotation(- viewPart->Rotation.getValue()); + sectionLine->setRotation(viewPart->Rotation.getValue()); sectionLine->draw(); } } @@ -673,7 +675,7 @@ void QGIViewPart::drawCenterLines(bool b) centerLine->setBounds(-xVal,-yVal,xVal,yVal); //centerLine->setWidth(viewPart->LineWidth.getValue()); centerLine->setZValue(ZVALUE::SECTIONLINE); - centerLine->setRotation(- viewPart->Rotation.getValue()); + centerLine->setRotation(viewPart->Rotation.getValue()); centerLine->draw(); } if (vert) { @@ -686,7 +688,7 @@ void QGIViewPart::drawCenterLines(bool b) centerLine->setBounds(-xVal,-yVal,xVal,yVal); //centerLine->setWidth(viewPart->LineWidth.getValue()); centerLine->setZValue(ZVALUE::SECTIONLINE); - centerLine->setRotation(- viewPart->Rotation.getValue()); + centerLine->setRotation(viewPart->Rotation.getValue()); centerLine->draw(); } } @@ -954,6 +956,11 @@ QRectF QGIViewPart::boundingRect() const return childrenBoundingRect(); } +//QGIViewPart derived classes do not need a rotate view method as rotation is handled on App side. +void QGIViewPart::rotateView(void) +{ +} + bool QGIViewPart::getFaceEdgesPref(void) { bool result = false; diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.h b/src/Mod/TechDraw/Gui/QGIViewPart.h index 682a323426..dfba1ee6b4 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.h +++ b/src/Mod/TechDraw/Gui/QGIViewPart.h @@ -67,6 +67,8 @@ public: bool showSection; virtual void draw() override; + virtual void rotateView(void) override; + static QPainterPath geomToPainterPath(TechDrawGeometry::BaseGeom *baseGeom, double rotation = 0.0); /// Helper for pathArc()