From 8e52a0baf8eed5daea81817bf1a294fcabeefc05 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Thu, 20 Jul 2023 21:25:23 -0400 Subject: [PATCH] [TD]Rotate CosmeticEdge with View --- src/Mod/TechDraw/App/Cosmetic.cpp | 19 +++++++ src/Mod/TechDraw/App/Cosmetic.h | 1 + src/Mod/TechDraw/App/CosmeticExtension.cpp | 58 ++++++++++++++-------- src/Mod/TechDraw/Gui/CommandAnnotate.cpp | 4 +- src/Mod/TechDraw/Gui/TaskCosmeticLine.cpp | 42 +++++++++------- 5 files changed, 81 insertions(+), 43 deletions(-) diff --git a/src/Mod/TechDraw/App/Cosmetic.cpp b/src/Mod/TechDraw/App/Cosmetic.cpp index d273a7b2bb..f3242f2017 100644 --- a/src/Mod/TechDraw/App/Cosmetic.cpp +++ b/src/Mod/TechDraw/App/Cosmetic.cpp @@ -193,6 +193,25 @@ TechDraw::BaseGeomPtr CosmeticEdge::scaledGeometry(const double scale) return newGeom; } +TechDraw::BaseGeomPtr CosmeticEdge::scaledAndRotatedGeometry(const double scale, const double rotDegrees) +{ + TopoDS_Edge e = m_geometry->getOCCEdge(); +// TopoDS_Shape s = TechDraw::scaleShape(e, scale); + // Mirror shape in Y and scale + TopoDS_Shape s = TechDraw::mirrorShape(e, gp_Pnt(0.0, 0.0, 0.0), scale); + // rotate using OXYZ as the coordinate system + s = TechDraw::rotateShape(s, gp_Ax2(), rotDegrees); + s = TechDraw::mirrorShape(s); + TopoDS_Edge newEdge = TopoDS::Edge(s); + TechDraw::BaseGeomPtr newGeom = TechDraw::BaseGeom::baseFactory(newEdge); + newGeom->setClassOfEdge(ecHARD); + newGeom->setHlrVisible( true); + newGeom->setCosmetic(true); + newGeom->source(COSMETICEDGE); + newGeom->setCosmeticTag(getTagAsString()); + return newGeom; +} + std::string CosmeticEdge::toString() const { std::stringstream ss; diff --git a/src/Mod/TechDraw/App/Cosmetic.h b/src/Mod/TechDraw/App/Cosmetic.h index 679ae4b8d3..095ef3cea8 100644 --- a/src/Mod/TechDraw/App/Cosmetic.h +++ b/src/Mod/TechDraw/App/Cosmetic.h @@ -77,6 +77,7 @@ public: void initialize(); TopoDS_Edge TopoDS_EdgeFromVectors(const Base::Vector3d& pt1, const Base::Vector3d& pt2); TechDraw::BaseGeomPtr scaledGeometry(const double scale); + TechDraw::BaseGeomPtr scaledAndRotatedGeometry(const double scale, const double rotDegrees); std::string toString() const override; void dump(const char* title) const; diff --git a/src/Mod/TechDraw/App/CosmeticExtension.cpp b/src/Mod/TechDraw/App/CosmeticExtension.cpp index 41ef829e7c..7245d3f09e 100644 --- a/src/Mod/TechDraw/App/CosmeticExtension.cpp +++ b/src/Mod/TechDraw/App/CosmeticExtension.cpp @@ -56,6 +56,7 @@ CosmeticExtension::~CosmeticExtension() // delete any entries. } +/// get a pointer to the parent view TechDraw::DrawViewPart* CosmeticExtension::getOwner() { return static_cast(getExtendedObject()); @@ -69,6 +70,7 @@ TechDraw::DrawViewPart* CosmeticExtension::getOwner() //mirror again before creation. // this is never called! +/// remove all the cosmetic vertices in the property list void CosmeticExtension::clearCosmeticVertexes() { std::vector cVerts = CosmeticVertexes.getValues(); @@ -79,7 +81,7 @@ void CosmeticExtension::clearCosmeticVertexes() CosmeticVertexes.setValues(noVerts); } -//add the cosmetic verts to owner's geometry vertex list +/// add the cosmetic verts in the property list to view's vertex geometry list void CosmeticExtension::addCosmeticVertexesToGeom() { // Base::Console().Message("CE::addCosmeticVertexesToGeom()\n"); @@ -93,6 +95,7 @@ void CosmeticExtension::addCosmeticVertexesToGeom() } } +/// add a single cosmetic vertex in the property list to the view's vertex geometry list int CosmeticExtension::add1CVToGV(const std::string& tag) { // Base::Console().Message("CE::add1CVToGV(%s)\n", tag.c_str()); @@ -109,7 +112,7 @@ int CosmeticExtension::add1CVToGV(const std::string& tag) return iGV; } -//update Vertex geometry with current CV's +/// update the parent view's vertex geometry with all the cosmetic vertices in the list property void CosmeticExtension::refreshCVGeoms() { // Base::Console().Message("CE::refreshCVGeoms()\n"); @@ -126,6 +129,7 @@ void CosmeticExtension::refreshCVGeoms() } //what is the CV's position in the big geometry q +/// find the position of a cosmetic vertex with the given tag in the parent view's geometry list int CosmeticExtension::getCVIndex(const std::string& tag) { // Base::Console().Message("CE::getCVIndex(%s)\n", tag.c_str()); @@ -156,8 +160,8 @@ int CosmeticExtension::getCVIndex(const std::string& tag) return -1; } -//returns unique CV id -//only adds cv to cvlist property. does not add to display geometry until dvp executes. +/// adds a cosmetic vertex to the property list. does not add to display geometry until dvp executes. +/// returns unique CV id std::string CosmeticExtension::addCosmeticVertex(const Base::Vector3d& pos) { // Base::Console().Message("CEx::addCosmeticVertex(%s)\n", @@ -171,22 +175,22 @@ std::string CosmeticExtension::addCosmeticVertex(const Base::Vector3d& pos) return result; } -//get CV by unique id -TechDraw::CosmeticVertex* CosmeticExtension::getCosmeticVertex(const std::string& tag) const +/// retrieve a cosmetic vertex by unique id +TechDraw::CosmeticVertex* CosmeticExtension::getCosmeticVertex(const std::string& tagString) const { // Base::Console().Message("CEx::getCosmeticVertex(%s)\n", tagString.c_str()); const std::vector verts = CosmeticVertexes.getValues(); for (auto& cv: verts) { std::string cvTag = cv->getTagAsString(); - if (cvTag == tag) { + if (cvTag == tagString) { return cv; } } return nullptr; } -// find the cosmetic vertex corresponding to selection name (Vertex5) -// used when selecting +/// retrieve a cosmetic vertex by selection name (Vertex5) +/// used when selecting TechDraw::CosmeticVertex* CosmeticExtension::getCosmeticVertexBySelection(const std::string& name) const { // Base::Console().Message("CEx::getCVBySelection(%s)\n", name.c_str()); @@ -203,7 +207,7 @@ TechDraw::CosmeticVertex* CosmeticExtension::getCosmeticVertexBySelection(const return getCosmeticVertex(v->getCosmeticTag()); } -//overload for index only +/// retrieve a cosmetic vertex by index (the 5 in Vertex5) TechDraw::CosmeticVertex* CosmeticExtension::getCosmeticVertexBySelection(const int i) const { // Base::Console().Message("CEx::getCVBySelection(%d)\n", i); @@ -213,6 +217,7 @@ TechDraw::CosmeticVertex* CosmeticExtension::getCosmeticVertexBySelection(const return getCosmeticVertexBySelection(vName); } +/// remove the cosmetic vertex with the given tag from the list property void CosmeticExtension::removeCosmeticVertex(const std::string& delTag) { // Base::Console().Message("DVP::removeCV(%s)\n", delTag.c_str()); @@ -228,6 +233,7 @@ void CosmeticExtension::removeCosmeticVertex(const std::string& delTag) CosmeticVertexes.setValues(newVerts); } +/// remove the cosmetic vertices with the given tags from the list property void CosmeticExtension::removeCosmeticVertex(const std::vector& delTags) { for (auto& t: delTags) { @@ -238,6 +244,7 @@ void CosmeticExtension::removeCosmeticVertex(const std::vector& del //********** Cosmetic Edge ***************************************************** // this is never called! +/// remove all the cosmetic edges for this view void CosmeticExtension::clearCosmeticEdges() { std::vector cEdges = CosmeticEdges.getValues(); @@ -248,14 +255,15 @@ void CosmeticExtension::clearCosmeticEdges() CosmeticEdges.setValues(noEdges); } -//add the cosmetic edges to geometry edge list +/// add the cosmetic edges to geometry edge list void CosmeticExtension::addCosmeticEdgesToGeom() { - // Base::Console().Message("CEx::addCosmeticEdgesToGeom()\n"); +// Base::Console().Message("CEx::addCosmeticEdgesToGeom()\n"); const std::vector cEdges = CosmeticEdges.getValues(); for (auto& ce : cEdges) { double scale = getOwner()->getScale(); - TechDraw::BaseGeomPtr scaledGeom = ce->scaledGeometry(scale); + double rotDegrees = getOwner()->Rotation.getValue(); + TechDraw::BaseGeomPtr scaledGeom = ce->scaledAndRotatedGeometry(scale, rotDegrees); if (!scaledGeom) continue; // int iGE = @@ -263,6 +271,7 @@ void CosmeticExtension::addCosmeticEdgesToGeom() } } +/// add a single cosmetic edge to the geometry edge list int CosmeticExtension::add1CEToGE(const std::string& tag) { // Base::Console().Message("CEx::add1CEToGE(%s) 2\n", tag.c_str()); @@ -271,13 +280,15 @@ int CosmeticExtension::add1CEToGE(const std::string& tag) Base::Console().Message("CEx::add1CEToGE 2 - ce %s not found\n", tag.c_str()); return -1; } - TechDraw::BaseGeomPtr scaledGeom = ce->scaledGeometry(getOwner()->getScale()); + double scale = getOwner()->getScale(); + double rotDegrees = getOwner()->Rotation.getValue(); + TechDraw::BaseGeomPtr scaledGeom = ce->scaledAndRotatedGeometry(scale, rotDegrees); int iGE = getOwner()->getGeometryObject()->addCosmeticEdge(scaledGeom, tag); return iGE; } -//update Edge geometry with current CE's +/// update Edge geometry with current CE's void CosmeticExtension::refreshCEGeoms() { // Base::Console().Message("CEx::refreshCEGeoms()\n"); @@ -292,8 +303,8 @@ void CosmeticExtension::refreshCEGeoms() addCosmeticEdgesToGeom(); } -//returns unique CE id -//only adds ce to celist property. does not add to display geometry until dvp executes. +/// adds a new cosmetic edge to the list property. does not add to display geometry until dvp executes. +/// returns unique CE id std::string CosmeticExtension::addCosmeticEdge(Base::Vector3d start, Base::Vector3d end) { @@ -305,6 +316,8 @@ std::string CosmeticExtension::addCosmeticEdge(Base::Vector3d start, return ce->getTagAsString(); } +/// adds a new cosmetic edge to the list property. does not add to display geometry until dvp executes. +/// returns unique CE id std::string CosmeticExtension::addCosmeticEdge(TechDraw::BaseGeomPtr bg) { // Base::Console().Message("CEx::addCosmeticEdge(bg: %X)\n", bg); @@ -315,7 +328,7 @@ std::string CosmeticExtension::addCosmeticEdge(TechDraw::BaseGeomPtr bg) return ce->getTagAsString(); } -//get CE by unique id +/// retrieve a CE by unique id TechDraw::CosmeticEdge* CosmeticExtension::getCosmeticEdge(const std::string& tagString) const { // Base::Console().Message("CEx::getCosmeticEdge(%s)\n", tagString.c_str()); @@ -332,8 +345,8 @@ TechDraw::CosmeticEdge* CosmeticExtension::getCosmeticEdge(const std::string& ta return nullptr; } -// find the cosmetic edge corresponding to selection name (Edge5) -// used when selecting +/// find the cosmetic edge corresponding to selection name (Edge5) +/// used when selecting TechDraw::CosmeticEdge* CosmeticExtension::getCosmeticEdgeBySelection(const std::string& name) const { // Base::Console().Message("CEx::getCEBySelection(%s)\n", name.c_str()); @@ -351,7 +364,7 @@ TechDraw::CosmeticEdge* CosmeticExtension::getCosmeticEdgeBySelection(const std: return getCosmeticEdge(base->getCosmeticTag()); } -//overload for index only +/// find the cosmetic edge corresponding to the input parameter (the 5 in Edge5) TechDraw::CosmeticEdge* CosmeticExtension::getCosmeticEdgeBySelection(int i) const { // Base::Console().Message("CEx::getCEBySelection(%d)\n", i); @@ -360,6 +373,7 @@ TechDraw::CosmeticEdge* CosmeticExtension::getCosmeticEdgeBySelection(int i) con return getCosmeticEdgeBySelection(edgeName.str()); } +/// remove the cosmetic edge with the given tag from the list property void CosmeticExtension::removeCosmeticEdge(const std::string& delTag) { // Base::Console().Message("DVP::removeCE(%s)\n", delTag.c_str()); @@ -375,6 +389,8 @@ void CosmeticExtension::removeCosmeticEdge(const std::string& delTag) CosmeticEdges.setValues(newEdges); } + +/// remove the cosmetic edges with the given tags from the list property void CosmeticExtension::removeCosmeticEdge(const std::vector& delTags) { for (auto& t: delTags) { diff --git a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp index e4da1a48d8..b3ed6e0ea3 100644 --- a/src/Mod/TechDraw/Gui/CommandAnnotate.cpp +++ b/src/Mod/TechDraw/Gui/CommandAnnotate.cpp @@ -1074,7 +1074,6 @@ void execLine2Points(Gui::Command* cmd) return; } - double scale = baseFeat->getScale(); std::vector points; std::vector is3d; //get the 2D points @@ -1083,8 +1082,7 @@ void execLine2Points(Gui::Command* cmd) int idx = DrawUtil::getIndexFromName(v2d); TechDraw::VertexPtr v = baseFeat->getProjVertexByIndex(idx); if (v) { - Base::Vector3d p = DrawUtil::invertY(v->point()); - points.push_back(p / scale); + points.push_back(v->point()); is3d.push_back(false); } } diff --git a/src/Mod/TechDraw/Gui/TaskCosmeticLine.cpp b/src/Mod/TechDraw/Gui/TaskCosmeticLine.cpp index b66d0107b6..2ff8b7e7be 100644 --- a/src/Mod/TechDraw/Gui/TaskCosmeticLine.cpp +++ b/src/Mod/TechDraw/Gui/TaskCosmeticLine.cpp @@ -43,6 +43,7 @@ using namespace Gui; using namespace TechDraw; using namespace TechDrawGui; +using DU = DrawUtil; //ctor for edit TaskCosmeticLine::TaskCosmeticLine(TechDraw::DrawViewPart* partFeat, @@ -111,21 +112,39 @@ void TaskCosmeticLine::setUiPrimary() { setWindowTitle(QObject::tr("Create Cosmetic Line")); + double rotDeg = m_partFeat->Rotation.getValue(); + double rotRad = rotDeg * M_PI / 180.0; + Base::Vector3d centroid = m_partFeat->getCurrentCentroid(); + Base::Vector3d p1, p2; if (m_is3d.front()) { + // center, project and invert the 3d point + p1 = DrawUtil::invertY(m_partFeat->projectPoint(m_points.front() - centroid)); ui->rb2d1->setChecked(false); ui->rb3d1->setChecked(true); } else { + // invert, unscale and unrotate the selected 2d point + p1 = DU::invertY(m_points.front()) / m_partFeat->getScale(); + if (rotDeg != 0.0) { + // we always rotate around the origin. + p1.RotateZ(-rotRad); + } ui->rb2d1->setChecked(true); ui->rb3d1->setChecked(false); } + if (m_is3d.back()) { + p2 = DrawUtil::invertY(m_partFeat->projectPoint(m_points.back() - centroid)); ui->rb2d2->setChecked(false); ui->rb3d2->setChecked(true); } else { + p2 = DU::invertY(m_points.back()) / m_partFeat->getScale(); + if (rotDeg != 0.0) { + p2.RotateZ(-rotRad); + } ui->rb2d2->setChecked(true); ui->rb3d2->setChecked(false); } - Base::Vector3d p1 = m_points.front(); + ui->qsbx1->setUnit(Base::Unit::Length); ui->qsbx1->setValue(p1.x); ui->qsby1->setUnit(Base::Unit::Length); @@ -133,7 +152,6 @@ void TaskCosmeticLine::setUiPrimary() ui->qsby1->setUnit(Base::Unit::Length); ui->qsbz1->setValue(p1.z); - Base::Vector3d p2 = m_points.back(); ui->qsbx2->setUnit(Base::Unit::Length); ui->qsbx2->setValue(p2.x); ui->qsby2->setUnit(Base::Unit::Length); @@ -165,6 +183,7 @@ void TaskCosmeticLine::setUiEdit() //****************************************************************************** void TaskCosmeticLine::createCosmeticLine(void) { +// Base::Console().Message("TCL::createCosmeticLine()\n"); Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Create Cosmetic Line")); double x = ui->qsbx1->value().getValue(); @@ -177,18 +196,6 @@ void TaskCosmeticLine::createCosmeticLine(void) z = ui->qsbz2->value().getValue(); Base::Vector3d p1(x, y, z); - Base::Vector3d centroid = m_partFeat->getOriginalCentroid(); - - if (ui->rb3d1->isChecked()) { - p0 = p0 - centroid; - p0 = DrawUtil::invertY(m_partFeat->projectPoint(p0)); - } - - if (ui->rb3d2->isChecked()) { - p1 = p1 - centroid; - p1 = DrawUtil::invertY(m_partFeat->projectPoint(p1)); - } - m_tag = m_partFeat->addCosmeticEdge(p0, p1); m_ce = m_partFeat->getCosmeticEdge(m_tag); @@ -197,6 +204,7 @@ void TaskCosmeticLine::createCosmeticLine(void) void TaskCosmeticLine::updateCosmeticLine(void) { +// Base::Console().Message("TCL::updateCosmeticLine()\n"); double x = ui->qsbx1->value().getValue(); double y = ui->qsby1->value().getValue(); double z = ui->qsbz1->value().getValue(); @@ -212,15 +220,11 @@ void TaskCosmeticLine::updateCosmeticLine(void) //replace the geometry m_ce->permaStart = p0; m_ce->permaEnd = p1; + gp_Pnt gp1(p0.x, p0.y, p0.z); gp_Pnt gp2(p1.x, p1.y, p1.z); TopoDS_Edge e = BRepBuilderAPI_MakeEdge(gp1, gp2); -// auto oldGeom = m_ce->m_geometry; m_ce->m_geometry = TechDraw::BaseGeom::baseFactory(e); -// delete oldGeom; - -// Gui::Command::updateActive(); -// Gui::Command::commitCommand(); } //******************************************************************************