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