Rotate DrawViewPart around part centroid

This commit is contained in:
WandererFan
2017-10-19 20:17:11 -04:00
parent 03f439caf7
commit 44fd200166
10 changed files with 89 additions and 15 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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;

View File

@@ -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)

View File

@@ -26,6 +26,7 @@
#include <TopoDS_Shape.hxx>
#include <TopoDS_Compound.hxx>
#include <gp_Pnt.hxx>
#include <gp_Ax2.hxx>
#include <Base/Vector3D.h>
#include <Base/BoundBox.h>
@@ -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,

View File

@@ -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();

View File

@@ -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.
* @{ */

View File

@@ -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;

View File

@@ -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()