[TD]rotate CosmeticVertex with View

This commit is contained in:
wandererfan
2023-07-20 12:21:43 -04:00
committed by WandererFan
parent 3c96cd9c26
commit 6eae743361
4 changed files with 42 additions and 5 deletions

View File

@@ -34,6 +34,7 @@
using namespace TechDraw;
using namespace std;
using DU = DrawUtil;
EXTENSION_PROPERTY_SOURCE(TechDraw::CosmeticExtension, App::DocumentObjectExtension)
@@ -81,25 +82,29 @@ void CosmeticExtension::clearCosmeticVertexes()
//add the cosmetic verts to owner's geometry vertex list
void CosmeticExtension::addCosmeticVertexesToGeom()
{
// Base::Console().Message("CE::addCosmeticVertexesToGeom()\n");
// Base::Console().Message("CE::addCosmeticVertexesToGeom()\n");
const std::vector<TechDraw::CosmeticVertex*> cVerts = CosmeticVertexes.getValues();
for (auto& cv : cVerts) {
double scale = getOwner()->getScale();
int iGV = getOwner()->getGeometryObject()->addCosmeticVertex(cv->scaled(scale), cv->getTagAsString());
double rotDegrees = getOwner()->Rotation.getValue();
Base::Vector3d cvPosition = cv->rotatedAndScaled(scale, rotDegrees);
int iGV = getOwner()->getGeometryObject()->addCosmeticVertex(cvPosition, cv->getTagAsString());
cv->linkGeom = iGV;
}
}
int CosmeticExtension::add1CVToGV(const std::string& tag)
{
// Base::Console().Message("CE::add1CVToGV(%s)\n", tag.c_str());
// Base::Console().Message("CE::add1CVToGV(%s)\n", tag.c_str());
TechDraw::CosmeticVertex* cv = getCosmeticVertex(tag);
if (!cv) {
Base::Console().Message("CE::add1CVToGV - cv %s not found\n", tag.c_str());
return 0;
}
double scale = getOwner()->getScale();
int iGV = getOwner()->getGeometryObject()->addCosmeticVertex(cv->scaled(scale), cv->getTagAsString());
double rotDegrees = getOwner()->Rotation.getValue();
Base::Vector3d cvPosition = cv->rotatedAndScaled(scale, rotDegrees);
int iGV = getOwner()->getGeometryObject()->addCosmeticVertex(cvPosition, cv->getTagAsString());
cv->linkGeom = iGV;
return iGV;
}
@@ -156,7 +161,7 @@ int CosmeticExtension::getCVIndex(const std::string& tag)
std::string CosmeticExtension::addCosmeticVertex(const Base::Vector3d& pos)
{
// Base::Console().Message("CEx::addCosmeticVertex(%s)\n",
// DrawUtil::formatVector(pos).c_str());
// DrawUtil::formatVector(pos).c_str());
std::vector<CosmeticVertex*> verts = CosmeticVertexes.getValues();
Base::Vector3d tempPos = DrawUtil::invertY(pos);
TechDraw::CosmeticVertex* cv = new TechDraw::CosmeticVertex(tempPos);

View File

@@ -35,9 +35,11 @@
#include "CosmeticVertexPy.h"
#include "LineGroup.h"
#include "Preferences.h"
#include "DrawUtil.h"
using namespace TechDraw;
using namespace std;
using DU = DrawUtil;
TYPESYSTEM_SOURCE(TechDraw::CosmeticVertex, Base::Persistence)
@@ -73,6 +75,7 @@ CosmeticVertex::CosmeticVertex(const TechDraw::CosmeticVertex* cv) : TechDraw::V
CosmeticVertex::CosmeticVertex(const Base::Vector3d& loc) : TechDraw::Vertex(loc)
{
// Base::Console().Message("CV::CV(%s)\n", DU::formatVector(loc).c_str());
permaPoint = loc;
linkGeom = -1;
color = Preferences::vertexColor();
@@ -177,6 +180,18 @@ Base::Vector3d CosmeticVertex::scaled(const double factor)
return permaPoint * factor;
}
Base::Vector3d CosmeticVertex::rotatedAndScaled(const double scale, const double rotDegrees)
{
Base::Vector3d scaledPoint = scaled(scale);
if (rotDegrees != 0.0) {
// invert the Y coordinate so the rotation math works out
scaledPoint = DU::invertY(scaledPoint);
scaledPoint.RotateZ(rotDegrees * M_PI / 180.0);
scaledPoint = DU::invertY(scaledPoint);
}
return scaledPoint;
}
boost::uuids::uuid CosmeticVertex::getTag() const
{
return tag;

View File

@@ -53,6 +53,7 @@ public:
std::string toString() const;
void dump(const char* title) override;
Base::Vector3d scaled(const double factor);
Base::Vector3d rotatedAndScaled(const double scale, const double rotDegrees);
static bool restoreCosmetic();

View File

@@ -55,6 +55,7 @@
using namespace Gui;
using namespace TechDraw;
using namespace TechDrawGui;
using DU = DrawUtil;
TaskCosVertex::TaskCosVertex(TechDraw::DrawViewPart* baseFeat,
TechDraw::DrawPage* page) :
@@ -122,6 +123,7 @@ void TaskCosVertex::setUiPrimary()
ui->dsbY->setUnit(Base::Unit::Length);
}
// set the ui x,y to apparent coords (ie invertY)
void TaskCosVertex::updateUi()
{
double x = m_savePoint.x();
@@ -235,6 +237,18 @@ void TaskCosVertex::onTrackerFinished(std::vector<QPointF> pts, QGIView* qgParen
QPointF displace = dragEnd - basePosScene;
QPointF scenePosCV = displace / scale;
// if the base view is rotated, we need to unrotate it before saving
double rotDeg = m_baseFeat->Rotation.getValue();
if (rotDeg != 0.0) {
// Invert Y value so the math works.
Base::Vector3d posToRotate = DU::invertY(DU::toVector3d(scenePosCV));
double rotRad = rotDeg * M_PI / 180.0;
// we always rotate around the origin.
posToRotate.RotateZ(-rotRad);
// now put Y value back to display form
scenePosCV = DU::toQPointF(DU::invertY(posToRotate));
}
m_savePoint = Rez::appX(scenePosCV);
updateUi();
@@ -299,6 +313,8 @@ bool TaskCosVertex::accept()
return false;
removeTracker();
// whatever is in the ui for x,y is treated as an unscaled, unrotated, invertedY position.
// the position from the tracker is unscaled & unrotated before updating the ui
double x = ui->dsbX->value().getValue();
double y = ui->dsbY->value().getValue();
QPointF uiPoint(x, -y);