[TD]Long and link dim refs (fix #13375) (#18641)

* [Meas]Changes for TD dimension refs for links

* [TD]App changes for dim refs to links

* [TD]Gui changes for dim refs to links

* [TD]fix 2 lint messages

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
WandererFan
2024-12-23 17:36:22 -05:00
committed by GitHub
parent a13ecd87db
commit f144a87539
16 changed files with 1092 additions and 198 deletions

View File

@@ -33,7 +33,10 @@
#include <App/GeoFeature.h>
#include <App/DocumentObject.h>
#include <App/Document.h>
#include <App/Link.h>
#include <Base/Console.h>
#include <Mod/Measure/App/ShapeFinder.h>
#include <Mod/Part/App/TopoShape.h>
#include <Mod/PartDesign/App/Body.h>
#include <Mod/PartDesign/App/Feature.h>
@@ -45,11 +48,12 @@
#include "CosmeticVertex.h"
using namespace TechDraw;
using namespace Measure;
using DU = DrawUtil;
using SU = ShapeUtils;
ReferenceEntry::ReferenceEntry( App::DocumentObject* docObject, std::string subName, App::Document* document)
ReferenceEntry::ReferenceEntry( App::DocumentObject* docObject, const std::string& subName, App::Document* document)
{
setObject(docObject);
setSubName(subName);
@@ -66,7 +70,7 @@ ReferenceEntry::ReferenceEntry( App::DocumentObject* docObject, std::string subN
ReferenceEntry::ReferenceEntry(const ReferenceEntry& other)
{
setObject(other.getObject());
setSubName(other.getSubName());
setSubName(other.getSubName(true));
setObjectName(other.getObjectName());
setDocument(other.getDocument());
}
@@ -79,7 +83,7 @@ ReferenceEntry& ReferenceEntry::operator=(const ReferenceEntry& otherRef)
return *this;
}
setObject(otherRef.getObject());
setSubName(otherRef.getSubName());
setSubName(otherRef.getSubName(true));
setObjectName(otherRef.getObjectName());
setDocument(otherRef.getDocument());
return *this;
@@ -94,8 +98,6 @@ bool ReferenceEntry::operator==(const ReferenceEntry& otherRef) const
TopoDS_Shape ReferenceEntry::getGeometry() const
{
// Base::Console().Message("RE::getGeometry() - objectName: %s sub: **%s**\n",
// getObjectName(), getSubName());
// first, make sure the object has not been deleted!
App::DocumentObject* obj = getDocument()->getObject(getObjectName().c_str());
if (!obj) {
@@ -112,24 +114,13 @@ TopoDS_Shape ReferenceEntry::getGeometry() const
}
// 3d geometry
Part::TopoShape shape = Part::Feature::getTopoShape(getObject());
auto geoFeat = getObject<App::GeoFeature>();
if (geoFeat) {
shape.setPlacement(geoFeat->globalPlacement());
}
if (getSubName().empty()) {
return shape.getShape();
}
// TODO: what happens if the subelement is no longer present?
return shape.getSubShape(getSubName().c_str());
return ShapeFinder::getLocatedShape(*getObject(), getSubName(true));
}
//! get a shape for this 2d reference
TopoDS_Shape ReferenceEntry::getGeometry2d() const
{
// Base::Console().Message("RE::getGeometry2d()\n");
std::string gType;
try {
auto dvp = getObject<TechDraw::DrawViewPart>(); //NOLINT cppcoreguidelines-pro-type-static-cast-downcast
@@ -160,7 +151,6 @@ TopoDS_Shape ReferenceEntry::getGeometry2d() const
}
catch (...) {
Base::Console().Message("RE::getGeometry2d - no shape for dimension 2d reference - gType: **%s**\n", gType.c_str());
return {};
}
return {};
@@ -172,12 +162,8 @@ std::string ReferenceEntry::getSubName(bool longForm) const
if (longForm) {
return m_subName;
}
std::string workingSubName(m_subName);
size_t lastDot = workingSubName.rfind('.');
if (lastDot != std::string::npos) {
workingSubName = workingSubName.substr(lastDot + 1);
}
return workingSubName;
return ShapeFinder::getLastTerm(m_subName);
}
@@ -198,10 +184,8 @@ App::DocumentObject* ReferenceEntry::getObject() const
//! return the reference geometry as a Part::TopoShape.
Part::TopoShape ReferenceEntry::asTopoShape() const
{
// Base::Console().Message("RE::asTopoShape()\n");
TopoDS_Shape geom = getGeometry();
if (geom.IsNull()) {
// throw Base::RuntimeError("Dimension Reference has null geometry");
return {};
}
if (geom.ShapeType() == TopAbs_VERTEX) {
@@ -222,7 +206,6 @@ Part::TopoShape ReferenceEntry::asTopoShape() const
//! returns unscaled, unrotated version of inShape. inShape is assumed to be a 2d shape, but this is not enforced.
Part::TopoShape ReferenceEntry::asCanonicalTopoShape() const
{
// Base::Console().Message("RE::asCanonicalTopoShape()\n");
if (is3d()) {
return asTopoShape();
}
@@ -240,7 +223,6 @@ Part::TopoShape ReferenceEntry::asCanonicalTopoShape() const
//! operations.
Part::TopoShape ReferenceEntry::asCanonicalTopoShape(const Part::TopoShape& inShape, const DrawViewPart& dvp)
{
// Base::Console().Message("RE::(static)asCanonicalTopoShape()\n");
gp_Ax2 OXYZ;
auto unscaledShape = SU::scaleShape(inShape.getShape(), 1.0 / dvp.getScale());
if (dvp.Rotation.getValue() != 0.0) {
@@ -270,7 +252,6 @@ Part::TopoShape ReferenceEntry::asTopoShapeFace(const TopoDS_Face &face)
std::string ReferenceEntry::geomType() const
{
// Base::Console().Message("RE::geomType() - subName: **%s**\n", getSubName().c_str());
return DrawUtil::getGeomTypeFromName(getSubName());
}
@@ -295,14 +276,21 @@ bool ReferenceEntry::isWholeObject() const
//! true if this reference point to 3d model geometry
bool ReferenceEntry::is3d() const
{
if (!getObject()) {
// we should really fail here?
return false;
}
if (getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
if (getObject() &&
getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId()) &&
!getSubName().empty()) {
// this is a well formed 2d reference
return false;
}
if (getObject() &&
getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId()) &&
getSubName().empty()) {
// this is a broken 3d reference, so it should be treated as 3d
return true;
}
// either we have no object or we have an object and it is a 3d object
return true;
}
@@ -310,7 +298,6 @@ bool ReferenceEntry::is3d() const
//! true if the target of this reference has a shape
bool ReferenceEntry::hasGeometry() const
{
// Base::Console().Message("RE::hasGeometry()\n");
if (!getObject()) {
return false;
}
@@ -321,6 +308,7 @@ bool ReferenceEntry::hasGeometry() const
}
// 3d reference
// TODO: shouldn't this be ShapeFinder.getLocatedShape?
auto shape = Part::Feature::getTopoShape(getObject());
auto subShape = shape.getSubShape(getSubName().c_str());