[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 0d128517de
commit abb50a4daa
16 changed files with 1092 additions and 198 deletions

View File

@@ -645,7 +645,6 @@ QStringList DrawViewDimension::getPrefixSuffixSpec(const QString &fSpec)
//! NOTE: this returns the Dimension value in internal units (ie mm)!!!!
double DrawViewDimension::getDimValue()
{
// Base::Console().Message("DVD::getDimValue()\n");
constexpr double CircleDegrees{360.0};
double result = 0.0;
if (!has2DReferences() && !has3DReferences()) {
@@ -703,7 +702,7 @@ double DrawViewDimension::getTrueDimValue() const
result = measurement->radius();
}
else if (Type.isValue("Diameter")) {
result = 2.0 * measurement->radius();
result = 2 * measurement->radius();
}
else if (Type.isValue("Angle") || Type.isValue("Angle3Pt")) {
result = measurement->angle();
@@ -720,7 +719,6 @@ double DrawViewDimension::getTrueDimValue() const
//! retrieve the dimension value for "projected" (2d) dimensions. The returned value is in internal units (mm).
double DrawViewDimension::getProjectedDimValue() const
{
// Base::Console().Message("DVD::getProjectedDimValue()\n");
double result = 0.0;
double scale = getViewPart()->getScale();
@@ -736,7 +734,8 @@ double DrawViewDimension::getProjectedDimValue() const
// then we should not move the points.
//
pts.invertY();
pts.scale(1.0 / scale);
// unscale the points, map them to the broken view then rescale them to draw.
pts.scale(1 / scale);
pts.first(dbv->mapPoint2dFromView(pts.first()));
pts.second(dbv->mapPoint2dFromView(pts.second()));
pts.invertY();
@@ -808,7 +807,6 @@ pointPair DrawViewDimension::getLinearPoints() const
pointPair DrawViewDimension::getPointsOneEdge(ReferenceVector references)
{
// Base::Console().Message("DVD::getPointsOneEdge()\n");
App::DocumentObject* refObject = references.front().getObject();
int iSubelement = DrawUtil::getIndexFromName(references.front().getSubName());
if (refObject->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())
@@ -849,7 +847,6 @@ pointPair DrawViewDimension::getPointsOneEdge(ReferenceVector references)
pointPair DrawViewDimension::getPointsTwoEdges(ReferenceVector references)
{
// Base::Console().Message("DVD::getPointsTwoEdges() - %s\n", getNameInDocument());
App::DocumentObject* refObject = references.front().getObject();
int iSubelement0 = DrawUtil::getIndexFromName(references.at(0).getSubName());
int iSubelement1 = DrawUtil::getIndexFromName(references.at(1).getSubName());
@@ -882,7 +879,6 @@ pointPair DrawViewDimension::getPointsTwoEdges(ReferenceVector references)
pointPair DrawViewDimension::getPointsTwoVerts(ReferenceVector references)
{
// Base::Console().Message("DVD::getPointsTwoVerts() - %s\n", getNameInDocument());
App::DocumentObject* refObject = references.front().getObject();
int iSubelement0 = DrawUtil::getIndexFromName(references.at(0).getSubName());
int iSubelement1 = DrawUtil::getIndexFromName(references.at(1).getSubName());
@@ -920,7 +916,6 @@ pointPair DrawViewDimension::getPointsTwoVerts(ReferenceVector references)
pointPair DrawViewDimension::getPointsEdgeVert(ReferenceVector references)
{
// Base::Console().Message("DVD::getPointsEdgeVert() - %s\n", getNameInDocument());
App::DocumentObject* refObject = references.front().getObject();
int iSubelement0 = DrawUtil::getIndexFromName(references.at(0).getSubName());
int iSubelement1 = DrawUtil::getIndexFromName(references.at(1).getSubName());
@@ -978,7 +973,6 @@ pointPair DrawViewDimension::getPointsEdgeVert(ReferenceVector references)
arcPoints DrawViewDimension::getArcParameters(ReferenceVector references)
{
// Base::Console().Message("DVD::getArcParameters()\n");
App::DocumentObject* refObject = references.front().getObject();
int iSubelement = DrawUtil::getIndexFromName(references.front().getSubName());
if (refObject->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())
@@ -1039,7 +1033,7 @@ arcPoints DrawViewDimension::arcPointsFromBaseGeom(TechDraw::BaseGeomPtr base)
if (ellipse->closed()) {
double r1 = ellipse->minor;
double r2 = ellipse->major;
double rAvg = (r1 + r2) / 2.0;
double rAvg = (r1 + r2) / 2;
pts.center = Base::Vector3d(ellipse->center.x, ellipse->center.y, 0.0);
pts.radius = rAvg;
pts.isArc = false;
@@ -1052,7 +1046,7 @@ arcPoints DrawViewDimension::arcPointsFromBaseGeom(TechDraw::BaseGeomPtr base)
TechDraw::AOEPtr aoe = std::static_pointer_cast<TechDraw::AOE>(base);
double r1 = aoe->minor;
double r2 = aoe->major;
double rAvg = (r1 + r2) / 2.0;
double rAvg = (r1 + r2) / 2;
pts.isArc = true;
pts.center = Base::Vector3d(aoe->center.x, aoe->center.y, 0.0);
pts.radius = rAvg;
@@ -1113,10 +1107,12 @@ arcPoints DrawViewDimension::arcPointsFromEdge(TopoDS_Edge occEdge)
arcPoints pts;
pts.isArc = !BRep_Tool::IsClosed(occEdge);
pts.arcCW = false;
// get all the common information for circle, ellipse and bspline conversions
BRepAdaptor_Curve adapt(occEdge);
double pFirst = adapt.FirstParameter();
double pLast = adapt.LastParameter();
double pMid = (pFirst + pLast) / 2.0;
double pMid = (pFirst + pLast) / 2;
BRepLProp_CLProps props(adapt, pFirst, 0, Precision::Confusion());
pts.arcEnds.first(DrawUtil::toVector3d(props.Value()));
props.SetParameter(pLast);
@@ -1208,7 +1204,6 @@ arcPoints DrawViewDimension::arcPointsFromEdge(TopoDS_Edge occEdge)
anglePoints DrawViewDimension::getAnglePointsTwoEdges(ReferenceVector references)
{
// Base::Console().Message("DVD::getAnglePointsTwoEdges() - %s\n", getNameInDocument());
App::DocumentObject* refObject = references.front().getObject();
int iSubelement0 = DrawUtil::getIndexFromName(references.at(0).getSubName());
int iSubelement1 = DrawUtil::getIndexFromName(references.at(1).getSubName());
@@ -1343,7 +1338,6 @@ anglePoints DrawViewDimension::getAnglePointsTwoEdges(ReferenceVector references
// somewhere?
anglePoints DrawViewDimension::getAnglePointsThreeVerts(ReferenceVector references)
{
// Base::Console().Message("DVD::getAnglePointsThreeVerts() - %s\n", getNameInDocument());
if (references.size() < 3) {
throw Base::RuntimeError("Not enough references to make angle dimension");
}
@@ -1478,7 +1472,6 @@ DrawViewPart* DrawViewDimension::getViewPart() const
// subName)
ReferenceVector DrawViewDimension::getEffectiveReferences() const
{
// Base::Console().Message("DVD::getEffectiveReferences()\n");
const std::vector<App::DocumentObject*>& objects3d = References3D.getValues();
const std::vector<std::string>& subElements3d = References3D.getSubValues();
const std::vector<App::DocumentObject*>& objects = References2D.getValues();
@@ -1549,7 +1542,7 @@ int DrawViewDimension::getRefType() const
// decide what the reference configuration is by examining the names of the sub elements
int DrawViewDimension::getRefTypeSubElements(const std::vector<std::string>& subElements)
{
int refType = invalidRef;
int refType{invalidRef};
int refEdges{0};
int refVertices{0};
int refFaces{0};
@@ -1591,7 +1584,6 @@ int DrawViewDimension::getRefTypeSubElements(const std::vector<std::string>& sub
//! validate 2D references - only checks if the target exists
bool DrawViewDimension::checkReferences2D() const
{
// Base::Console().Message("DVD::checkReferences2d() - %s\n", getNameInDocument());
const std::vector<App::DocumentObject*>& objects = References2D.getValues();
if (objects.empty()) {
return false;
@@ -1650,8 +1642,6 @@ bool DrawViewDimension::hasBroken3dReferences() const
void DrawViewDimension::updateSavedGeometry()
{
// Base::Console().Message("DVD::updateSavedGeometry() - %s - savedGeometry: %d\n",
// getNameInDocument(), SavedGeometry.getValues().size());
ReferenceVector references = getEffectiveReferences();
if (references.empty()) {
// no references to save
@@ -1719,6 +1709,20 @@ std::vector<TopoShape> DrawViewDimension::getVertexes(const TopoShape& inShape)
return ret;
}
//! returns the angle subtended by an arc from 3 points.
double DrawViewDimension::getArcAngle(Base::Vector3d center, Base::Vector3d startPoint, Base::Vector3d endPoint)
{
auto leg0 = startPoint - center;
auto leg1 = endPoint - startPoint;
auto referenceDirection = leg0.Cross(leg1);
gp_Ax1 axis{DU::togp_Pnt(center), DU::togp_Vec(referenceDirection)};
gp_Vec startVec = DrawUtil::togp_Vec(leg0);
gp_Vec endVec = DrawUtil::togp_Vec(leg1);
double angle = startVec.AngleWithRef(endVec, axis.Direction().XYZ());
return angle;
}
pointPair DrawViewDimension::closestPoints(TopoDS_Shape s1, TopoDS_Shape s2) const
{
pointPair result;
@@ -1740,7 +1744,6 @@ pointPair DrawViewDimension::closestPoints(TopoDS_Shape s1, TopoDS_Shape s2) con
// set the reference property from a reference vector
void DrawViewDimension::setReferences2d(const ReferenceVector& refsAll)
{
// Base::Console().Message("DVD::setReferences2d(%d)\n", refs.size());
std::vector<App::DocumentObject*> objects;
std::vector<std::string> subNames;
if (objects.size() != subNames.size()) {
@@ -1759,7 +1762,6 @@ void DrawViewDimension::setReferences2d(const ReferenceVector& refsAll)
// set the reference property from a reference vector
void DrawViewDimension::setReferences3d(const ReferenceVector &refsAll)
{
// Base::Console().Message("DVD::setReferences3d()\n");
if (refsAll.empty() && !References3D.getValues().empty()) {
// clear the property of any old links
References3D.setValue(nullptr, nullptr);
@@ -1773,7 +1775,7 @@ void DrawViewDimension::setReferences3d(const ReferenceVector &refsAll)
for (auto& ref : refsAll) {
objects.push_back(ref.getObject());
subNames.push_back(ref.getSubName());
subNames.push_back(ref.getSubName(true));
// cache the referenced object
m_3dObjectCache.insert(ref.getObject()->getNameInDocument());
// cache the parent object if available. Ideally, we would handle deletion
@@ -1794,7 +1796,6 @@ void DrawViewDimension::setReferences3d(const ReferenceVector &refsAll)
//! add Dimension 3D references to measurement
void DrawViewDimension::setAll3DMeasurement()
{
// Base::Console().Message("DVD::setAll3dMeasurement()\n");
measurement->clear();
const std::vector<App::DocumentObject*>& Objs = References3D.getValues();
const std::vector<std::string>& Subs = References3D.getSubValues();
@@ -1820,7 +1821,6 @@ void DrawViewDimension::setAll3DMeasurement()
//! dimension.
bool DrawViewDimension::validateReferenceForm() const
{
// Base::Console().Message("DVD::validateReferenceForm()\n");
// we have either or both valid References3D and References2D
ReferenceVector references = getEffectiveReferences();
if (references.empty()) {
@@ -1925,8 +1925,8 @@ void DrawViewDimension::dumpRefs2D(const char* text) const
Base::Console().Message("DUMP - %s\n", text);
const std::vector<App::DocumentObject*>& objects = References2D.getValues();
const std::vector<std::string>& subElements = References2D.getSubValues();
std::vector<App::DocumentObject*>::const_iterator objIt = objects.begin();
std::vector<std::string>::const_iterator subIt = subElements.begin();
auto objIt = objects.begin();
auto subIt = subElements.begin();
int i = 0;
for (; objIt != objects.end(); objIt++, subIt++, i++) {
Base::Console().Message("DUMP - ref: %d object: %s subElement: %s\n",
@@ -1936,6 +1936,7 @@ void DrawViewDimension::dumpRefs2D(const char* text) const
}
}
// TODO: this should go into DrawUtil or ShapeUtil or ??
double DrawViewDimension::dist2Segs(Base::Vector3d s1,
Base::Vector3d e1,
Base::Vector3d s2,
@@ -2043,7 +2044,6 @@ pointPair DrawViewDimension::getArrowPositions()
bool DrawViewDimension::has2DReferences() const
{
// Base::Console().Message("DVD::has2DReferences() - %s\n",getNameInDocument());
const std::vector<App::DocumentObject*>& objects = References2D.getValues();
const std::vector<std::string>& subNames = References2D.getSubValues();
if (objects.empty()) {
@@ -2120,6 +2120,8 @@ PyObject* DrawViewDimension::getPyObject()
return Py::new_reference_to(PythonObject);
}
//! store the corners of this dimension's base view for use by phase 2 of the auto correct process.
void DrawViewDimension::saveFeatureBox()
{
std::vector<Base::Vector3d> bbxCorners;