[TD] fix small angle dims (fix #21114) (#21208)

* [TD]fix handling of very small angle dimensions

- also remove test for too small format specifier

* [TD]lint messages

* [TD]apply review comments.
This commit is contained in:
WandererFan
2025-05-26 11:19:19 -04:00
committed by GitHub
parent 82696359f6
commit 4dd2313425
6 changed files with 127 additions and 153 deletions

View File

@@ -24,6 +24,7 @@
#ifndef _PreComp_
# include <QLocale>
# include <QRegularExpression>
# include <QString>
#endif
#include <Base/Console.h>
@@ -124,13 +125,6 @@ std::string DimensionFormatter::formatValue(const qreal value,
}
}
if (isTooSmall(userVal, formatSpecifier)) {
Base::Console().warning("Dimension %s value %.6f is too small for format specifier: %s\n",
m_dimension->getNameInDocument(),
userVal,
qPrintable(formatSpecifier));
}
QString formattedValue = formatValueToSpec(userVal, formatSpecifier);
// replace decimal sign if necessary
@@ -403,25 +397,3 @@ std::string DimensionFormatter::getDefaultFormatSpec(bool isToleranceFormat) con
return formatSpec.toStdString();
}
//true if value is too small to display using formatSpec
bool DimensionFormatter::isTooSmall(const double value, const QString& formatSpec) const
{
if (TechDraw::DrawUtil::fpCompare(value, 0.0)) {
//zero values always fit, so it isn't too small
return false;
}
QRegularExpression rxFormat(QStringLiteral("%[+-]?[0-9]*\\.*([0-9]*)[aefgrwAEFGRW]")); //printf double format spec
QRegularExpressionMatch rxMatch = rxFormat.match(formatSpec);
if (rxMatch.hasMatch()) {
QString decimalGroup = rxMatch.captured(1);
int factor = decimalGroup.toInt();
double minValue = pow(10.0, -factor);
if (std::fabs(value) < minValue) {
return true;
}
} else {
Base::Console().warning("Failed to parse dimension format spec\n");
}
return false;
}

View File

@@ -23,10 +23,13 @@
#ifndef DIMENSIONFORMATTER_H
#define DIMENSIONFORMATTER_H
#include <QString>
#include <Mod/TechDraw/TechDrawGlobal.h>
//#include <DrawViewDimension.h> Cyclic dependency issue!
class QString;
namespace TechDraw {
class DrawViewDimension;
@@ -57,7 +60,6 @@ public:
std::string getDefaultFormatSpec(bool isToleranceFormat) const;
private:
bool isTooSmall(double value, const QString& formatSpec) const;
QString formatValueToSpec(double value, QString formatSpecifier) const;
bool isNumericFormat(const QString& formatSpecifier) const;

View File

@@ -608,7 +608,7 @@ bool DrawViewDimension::isMultiValueSchema() const
}
std::string
DrawViewDimension::formatValue(qreal value, QString qFormatSpec, DimensionFormatter::Format partial, bool isDim)
DrawViewDimension::formatValue(qreal value, const QString& qFormatSpec, DimensionFormatter::Format partial, bool isDim)
{
return m_formatter->formatValue(value, qFormatSpec, partial, isDim);
}
@@ -617,12 +617,9 @@ bool DrawViewDimension::haveTolerance()
{
// if a numeric tolerance is specified AND
// tolerances are NOT arbitrary
if ((!DrawUtil::fpCompare(OverTolerance.getValue(), 0.0)
|| !DrawUtil::fpCompare(UnderTolerance.getValue(), 0.0))
&& !ArbitraryTolerances.getValue()) {
return true;
}
return false;
return (!DrawUtil::fpCompare(OverTolerance.getValue(), 0.0) ||
!DrawUtil::fpCompare(UnderTolerance.getValue(), 0.0)) &&
!ArbitraryTolerances.getValue();
}
std::string DrawViewDimension::getFormattedToleranceValue(DimensionFormatter::Format partial)
@@ -763,7 +760,7 @@ double DrawViewDimension::getProjectedDimValue() const
}
else if (Type.isValue("Diameter")) {
arcPoints pts = m_arcPoints;
result = (pts.radius * 2.0) / scale; // Projected BaseGeom is scaled for drawing
result = (pts.radius * 2) / scale; // Projected BaseGeom is scaled for drawing
}
else if (Type.isValue("Angle") || Type.isValue("Angle3Pt")) { // same as case "Angle"?
anglePoints pts = m_anglePoints;
@@ -1004,7 +1001,7 @@ arcPoints DrawViewDimension::getArcParameters(ReferenceVector references)
return pts;
}
arcPoints DrawViewDimension::arcPointsFromBaseGeom(TechDraw::BaseGeomPtr base)
arcPoints DrawViewDimension::arcPointsFromBaseGeom(const TechDraw::BaseGeomPtr& base)
{
TechDraw::CirclePtr circle;
arcPoints pts;
@@ -1107,7 +1104,7 @@ arcPoints DrawViewDimension::arcPointsFromBaseGeom(TechDraw::BaseGeomPtr base)
return pts;
}
arcPoints DrawViewDimension::arcPointsFromEdge(TopoDS_Edge occEdge)
arcPoints DrawViewDimension::arcPointsFromEdge(const TopoDS_Edge& occEdge)
{
arcPoints pts;
pts.isArc = !BRep_Tool::IsClosed(occEdge);
@@ -1134,8 +1131,8 @@ arcPoints DrawViewDimension::arcPointsFromEdge(TopoDS_Edge occEdge)
if (pts.isArc) {
// part of circle
gp_Ax1 axis = circle.Axis();
gp_Vec startVec = Base::convertTo<gp_Vec>(pts.arcEnds.first() - pts.center);
gp_Vec endVec = Base::convertTo<gp_Vec>(pts.arcEnds.second() - pts.center);
auto startVec = Base::convertTo<gp_Vec>(pts.arcEnds.first() - pts.center);
auto endVec = Base::convertTo<gp_Vec>(pts.arcEnds.second() - pts.center);
double angle = startVec.AngleWithRef(endVec, axis.Direction().XYZ());
pts.arcCW = (angle < 0.0);
}
@@ -1150,12 +1147,12 @@ arcPoints DrawViewDimension::arcPointsFromEdge(TopoDS_Edge occEdge)
else if (adapt.GetType() == GeomAbs_Ellipse) {
gp_Elips ellipse = adapt.Ellipse();
pts.center = Base::convertTo<Base::Vector3d>(ellipse.Location());
pts.radius = (ellipse.MajorRadius() + ellipse.MinorRadius()) / 2.0;
pts.radius = (ellipse.MajorRadius() + ellipse.MinorRadius()) / 2;
if (pts.isArc) {
// part of ellipse
gp_Ax1 axis = ellipse.Axis();
gp_Vec startVec = Base::convertTo<gp_Vec>(pts.arcEnds.first() - pts.center);
gp_Vec endVec = Base::convertTo<gp_Vec>(pts.arcEnds.second() - pts.center);
auto startVec = Base::convertTo<gp_Vec>(pts.arcEnds.first() - pts.center);
auto endVec = Base::convertTo<gp_Vec>(pts.arcEnds.second() - pts.center);
double angle = startVec.AngleWithRef(endVec, axis.Direction().XYZ());
pts.arcCW = (angle < 0.0);
}
@@ -1183,8 +1180,8 @@ arcPoints DrawViewDimension::arcPointsFromEdge(TopoDS_Edge occEdge)
if (pts.isArc) {
// part of circle
gp_Ax1 axis = circle.Axis();
gp_Vec startVec = Base::convertTo<gp_Vec>(pts.arcEnds.first() - pts.center);
gp_Vec endVec = Base::convertTo<gp_Vec>(pts.arcEnds.second() - pts.center);
auto startVec = Base::convertTo<gp_Vec>(pts.arcEnds.first() - pts.center);
auto endVec = Base::convertTo<gp_Vec>(pts.arcEnds.second() - pts.center);
double angle = startVec.AngleWithRef(endVec, axis.Direction().XYZ());
pts.arcCW = (angle < 0.0);
}
@@ -1234,58 +1231,40 @@ anglePoints DrawViewDimension::getAnglePointsTwoEdges(ReferenceVector references
<< geom0->geomTypeName();
throw Base::RuntimeError(ssMessage.str());
}
TechDraw::GenericPtr generic0 = std::static_pointer_cast<TechDraw::Generic>(geom0);
TechDraw::GenericPtr generic1 = std::static_pointer_cast<TechDraw::Generic>(geom1);
auto generic0 = std::static_pointer_cast<TechDraw::Generic>(geom0);
auto generic1 = std::static_pointer_cast<TechDraw::Generic>(geom1);
Base::Vector3d apex = generic0->apparentInter(generic1);
Base::Vector3d farPoint0;
Base::Vector3d farPoint1;
// pick the end of generic0 farthest from the apex
Base::Vector3d farPoint0{generic0->getEndPoint()};
if ((generic0->getStartPoint() - apex).Length()
> (generic0->getEndPoint() - apex).Length()) {
farPoint0 = generic0->getStartPoint();
}
else {
farPoint0 = generic0->getEndPoint();
}
// pick the end of generic1 farthest from the apex
Base::Vector3d farPoint1{generic1->getEndPoint()};
if ((generic1->getStartPoint() - apex).Length()
> (generic1->getEndPoint() - apex).Length()) {
farPoint1 = generic1->getStartPoint();
}
else {
farPoint1 = generic1->getEndPoint();
}
Base::Vector3d leg0Dir = (generic0->getStartPoint() - generic0->getEndPoint()).Normalize();
Base::Vector3d leg1Dir = (generic1->getStartPoint() - generic1->getEndPoint()).Normalize();
if (DrawUtil::fpCompare(fabs(leg0Dir.Dot(leg1Dir)), 1.0)) {
// legs of the angle are parallel.
throw Base::RuntimeError("Can not make angle from parallel edges");
farPoint1 = (generic1->getStartPoint());
}
Base::Vector3d leg0Dir = (farPoint0 - apex).Normalize();
Base::Vector3d leg1Dir = (farPoint1 - apex).Normalize();
Base::Vector3d extenPoint0 = farPoint0; // extension line points
Base::Vector3d extenPoint1 = farPoint1;
if (DrawUtil::fpCompare(fabs(leg0Dir.Dot(leg1Dir)), 0.0)) {
// legs of angle are perpendicular farPoints will do
}
else {
// legs of the angle are skew
// project farthest points onto opposite edge
Base::Vector3d projFar0OnLeg1 = farPoint0.Perpendicular(apex, leg1Dir);
Base::Vector3d projFar1OnLeg0 = farPoint1.Perpendicular(apex, leg0Dir);
if (DrawUtil::isBetween(projFar0OnLeg1,
generic1->getStartPoint(),
generic1->getEndPoint())) {
extenPoint1 = projFar0OnLeg1;
}
else if (DrawUtil::isBetween(projFar1OnLeg0,
generic0->getStartPoint(),
generic0->getEndPoint())) {
extenPoint0 = projFar1OnLeg0;
}
double extenRadius = std::min(extenPoint0.Length(),
extenPoint1.Length());
if (extenRadius == 0) {
// one of the legs has 0 length??
throw Base::RuntimeError("No extension point radius!!");
}
anglePoints pts;
pts.first(extenPoint0);
pts.second(extenPoint1);
pts.first(apex + leg0Dir * extenRadius);
pts.second(apex + leg1Dir * extenRadius);
pts.vertex(apex);
return pts;
}
@@ -1320,7 +1299,7 @@ anglePoints DrawViewDimension::getAnglePointsTwoEdges(ReferenceVector references
if (!haveIntersection) {
throw Base::RuntimeError("Geometry for 3d angle dimension does not intersect");
}
gp_Pnt gApex = Base::convertTo<gp_Pnt>(vApex);
auto gApex = Base::convertTo<gp_Pnt>(vApex);
gp_Pnt gFar0 = gEnd0;
if (gStart0.Distance(gApex) > gEnd0.Distance(gApex)) {
@@ -1487,8 +1466,8 @@ ReferenceVector DrawViewDimension::getEffectiveReferences() const
// is deleted.
if (objects3d.empty()) {
// use 2d references
int refCount = objects.size();
for (int i = 0; i < refCount; i++) {
size_t refCount = objects.size();
for (size_t i = 0; i < refCount; i++) {
if (subElements.empty()) {
// the 3d references have likely been nulled out by an object
// deletion.
@@ -1504,8 +1483,8 @@ ReferenceVector DrawViewDimension::getEffectiveReferences() const
}
else {
// use 3d references
int refCount = objects3d.size();
for (int i = 0; i < refCount; i++) {
size_t refCount = objects3d.size();
for (size_t i = 0; i < refCount; i++) {
ReferenceEntry ref(objects3d.at(i), std::string(subElements3d.at(i)));
effectiveRefs.push_back(ref);
}
@@ -1662,11 +1641,11 @@ void DrawViewDimension::updateSavedGeometry()
continue;
}
if (entry.hasGeometry()) {
newGeometry.push_back(entry.asCanonicalTopoShape());
newGeometry.emplace_back(entry.asCanonicalTopoShape());
}
else {
// have to put something in the vector so SavedGeometry and references stay in sync.
newGeometry.push_back(Part::TopoShape());
newGeometry.emplace_back(Part::TopoShape());
}
}
if (!newGeometry.empty()) {
@@ -1689,7 +1668,7 @@ std::vector<TopoShape> DrawViewDimension::getEdges(const TopoShape& inShape)
for (Standard_Integer k = 1; k <= shapeMap.Extent(); k++) {
const TopoDS_Shape& shape = shapeMap(k);
ret.push_back(TopoShape(shape));
ret.emplace_back(TopoShape(shape));
}
return ret;
@@ -1708,7 +1687,7 @@ std::vector<TopoShape> DrawViewDimension::getVertexes(const TopoShape& inShape)
for (Standard_Integer k = 1; k <= shapeMap.Extent(); k++) {
const TopoDS_Shape& shape = shapeMap(k);
ret.push_back(TopoShape(shape));
ret.emplace_back(TopoShape(shape));
}
return ret;
@@ -1721,14 +1700,14 @@ double DrawViewDimension::getArcAngle(Base::Vector3d center, Base::Vector3d star
auto leg1 = endPoint - startPoint;
auto referenceDirection = leg0.Cross(leg1);
gp_Ax1 axis{Base::convertTo<gp_Pnt>(center), Base::convertTo<gp_Vec>(referenceDirection)};
gp_Vec startVec = Base::convertTo<gp_Vec>(leg0);
gp_Vec endVec = Base::convertTo<gp_Vec>(leg1);
auto startVec = Base::convertTo<gp_Vec>(leg0);
auto endVec = Base::convertTo<gp_Vec>(leg1);
double angle = startVec.AngleWithRef(endVec, axis.Direction().XYZ());
return angle;
}
pointPair DrawViewDimension::closestPoints(TopoDS_Shape s1, TopoDS_Shape s2) const
pointPair DrawViewDimension::closestPoints(const TopoDS_Shape& s1, const TopoDS_Shape& s2) const
{
pointPair result;
BRepExtrema_DistShapeShape extss(s1, s2);
@@ -1804,8 +1783,8 @@ void DrawViewDimension::setAll3DMeasurement()
measurement->clear();
const std::vector<App::DocumentObject*>& Objs = References3D.getValues();
const std::vector<std::string>& Subs = References3D.getSubValues();
int end = Objs.size();
int iObject = 0;
size_t end = Objs.size();
size_t iObject = 0;
for (; iObject < end; iObject++) {
static_cast<void>(measurement->addReference3D(Objs.at(iObject), Subs.at(iObject)));
// cache the referenced object
@@ -1909,10 +1888,7 @@ bool DrawViewDimension::validateReferenceForm() const
return false;
}
std::string subGeom = DrawUtil::getGeomTypeFromName(references.front().getSubName());
if (subGeom != "Face") {
return false;
}
return true;
return (subGeom == "Face");
}
return false;
@@ -2017,8 +1993,8 @@ ReferenceVector DrawViewDimension::getReferences2d() const
const std::vector<App::DocumentObject*>& objects = References2D.getValues();
const std::vector<std::string>& subElements = References2D.getSubValues();
ReferenceVector refs2d;
int refCount = objects.size();
for (int i = 0; i < refCount; i++) {
size_t refCount = objects.size();
for (size_t i = 0; i < refCount; i++) {
ReferenceEntry ref(objects.at(i), subElements.at(i));
refs2d.push_back(ref);
}
@@ -2031,8 +2007,8 @@ ReferenceVector DrawViewDimension::getReferences3d() const
const std::vector<App::DocumentObject*>& objects3d = References3D.getValues();
const std::vector<std::string>& subElements3d = References3D.getSubValues();
ReferenceVector refs3d;
int refCount = objects3d.size();
for (int i = 0; i < refCount; i++) {
size_t refCount = objects3d.size();
for (size_t i = 0; i < refCount; i++) {
ReferenceEntry ref(objects3d.at(i), subElements3d.at(i));
refs3d.push_back(ref);
}
@@ -2136,7 +2112,7 @@ void DrawViewDimension::saveFeatureBox()
BoxCorners.setValues(bbxCorners);
}
Base::BoundBox3d DrawViewDimension::getSavedBox()
Base::BoundBox3d DrawViewDimension::getSavedBox() const
{
std::vector<Base::Vector3d> bbxCorners = BoxCorners.getValues();
if (bbxCorners.empty()) {
@@ -2153,7 +2129,7 @@ Base::BoundBox3d DrawViewDimension::getSavedBox()
bbxCorners.back().z);
}
Base::BoundBox3d DrawViewDimension::getFeatureBox()
Base::BoundBox3d DrawViewDimension::getFeatureBox() const
{
if (getViewPart() && getViewPart()->getBoundingBox().IsValid()) {
return getViewPart()->getBoundingBox();

View File

@@ -51,6 +51,7 @@ using DF = DimensionFormatter;
//TODO: Cyclic dependency issue with DimensionFormatter
//NOLINTBEGIN
class TechDrawExport DrawViewDimension: public TechDraw::DrawView
{
PROPERTY_HEADER_WITH_OVERRIDE(TechDraw::DrawViewDimension);
@@ -98,6 +99,7 @@ public:
App::PropertyBool UseActualArea;
App::PropertyBool ShowUnits;
//NOLINTEND
enum class RefType
{
@@ -129,8 +131,10 @@ public:
virtual std::string getFormattedToleranceValue(DF::Format partial);
virtual std::pair<std::string, std::string> getFormattedToleranceValues(DF::Format partial = DF::Format::UNALTERED);
virtual std::string getFormattedDimensionValue(DF::Format partial = DF::Format::UNALTERED);
virtual std::string
formatValue(qreal value, QString qFormatSpec, DF::Format partial = DF::Format::UNALTERED, bool isDim = true);
virtual std::string formatValue(qreal value,
const QString& qFormatSpec,
DF::Format partial = DF::Format::UNALTERED,
bool isDim = true);
virtual bool haveTolerance();
@@ -171,7 +175,7 @@ public:
m_linearPoints.first(point0);
m_linearPoints.second(point1);
};
virtual void setLinearPoints(pointPair newPair)
virtual void setLinearPoints(const pointPair& newPair)
{
m_linearPoints = newPair;
}
@@ -193,7 +197,7 @@ public:
bool isMultiValueSchema() const;
pointPair getArrowPositions();
void saveArrowPositions(const Base::Vector2d positions[]);
void saveArrowPositions(const Base::Vector2d positions[]); //NOLINT
bool showUnits() const;
bool useDecimals() const;
@@ -215,15 +219,15 @@ public:
// autocorrect support methods
void saveFeatureBox();
Base::BoundBox3d getSavedBox();
Base::BoundBox3d getFeatureBox();
Base::BoundBox3d getSavedBox() const;
Base::BoundBox3d getFeatureBox() const;
static double getActualArea(const TopoDS_Face& face);
static double getFilledArea(const TopoDS_Face& face);
static Base::Vector3d getFaceCenter(const TopoDS_Face& face);
protected:
void handleChangedPropertyType(Base::XMLReader&, const char*, App::Property*) override;
void handleChangedPropertyType(Base::XMLReader& reader, const char* typeName, App::Property* propss) override;
void Restore(Base::XMLReader& reader) override;
void onChanged(const App::Property* prop) override;
void onDocumentRestored() override;
@@ -235,18 +239,17 @@ protected:
virtual pointPair getPointsEdgeVert(ReferenceVector references);
virtual arcPoints getArcParameters(ReferenceVector references);
virtual arcPoints arcPointsFromBaseGeom(BaseGeomPtr base);
virtual arcPoints arcPointsFromEdge(TopoDS_Edge occEdge);
virtual arcPoints arcPointsFromBaseGeom(const BaseGeomPtr& base);
virtual arcPoints arcPointsFromEdge(const TopoDS_Edge& occEdge);
virtual anglePoints getAnglePointsTwoEdges(ReferenceVector references);
virtual anglePoints getAnglePointsThreeVerts(ReferenceVector references);
virtual areaPoint getAreaParameters(ReferenceVector references);
Measure::Measurement* measurement;
double
dist2Segs(Base::Vector3d s1, Base::Vector3d e1, Base::Vector3d s2, Base::Vector3d e2) const;
pointPair closestPoints(TopoDS_Shape s1, TopoDS_Shape s2) const;
pointPair closestPoints(const TopoDS_Shape& s1, const TopoDS_Shape& s2) const;
void resetLinear();
void resetAngular();
@@ -260,8 +263,9 @@ protected:
bool autocorrectReferences();
private:
static const char* TypeEnums[];
static const char* MeasureTypeEnums[];
Measure::Measurement* measurement;
static const char* TypeEnums[]; //NOLINT
static const char* MeasureTypeEnums[]; //NOLINT
void dumpRefs2D(const char* text) const;
// Dimension "geometry"
pointPair m_linearPoints;

View File

@@ -211,9 +211,9 @@ DimensionGeometry TechDraw::validateDimSelection3d(
return DimensionGeometry::isInvalid;
}
bool TechDraw::validateSubnameList(const StringVector& subNames, GeometrySet acceptableGeometrySet)
bool TechDraw::validateSubnameList(const StringVector& subNames, const GeometrySet& acceptableGeometrySet)
{
for (auto& sub : subNames) {
for (auto& sub : subNames) { // NOLINT (std::ranges::all_of())
std::string geometryType = DrawUtil::getGeomTypeFromName(ShapeFinder::getLastTerm(sub));
if (!acceptableGeometrySet.contains(geometryType)) {
//this geometry type is not allowed
@@ -394,17 +394,24 @@ DimensionGeometry TechDraw::isValidSingleEdge(const ReferenceEntry& ref)
return DimensionGeometry::isHorizontal;
}
return DimensionGeometry::isDiagonal;
} else if (geom->getGeomType() == GeomType::CIRCLE || geom->getGeomType() == GeomType::ARCOFCIRCLE) {
}
if (geom->getGeomType() == GeomType::CIRCLE || geom->getGeomType() == GeomType::ARCOFCIRCLE) {
return DimensionGeometry::isCircle;
} else if (geom->getGeomType() == GeomType::ELLIPSE || geom->getGeomType() == GeomType::ARCOFELLIPSE) {
}
if (geom->getGeomType() == GeomType::ELLIPSE || geom->getGeomType() == GeomType::ARCOFELLIPSE) {
return DimensionGeometry::isEllipse;
} else if (geom->getGeomType() == GeomType::BSPLINE) {
}
if (geom->getGeomType() == GeomType::BSPLINE) {
TechDraw::BSplinePtr spline = std::static_pointer_cast<TechDraw::BSpline>(geom);
if (spline->isCircle()) {
return DimensionGeometry::isBSplineCircle;
}
return DimensionGeometry::isBSpline;
}
return DimensionGeometry::isInvalid;
}
@@ -426,28 +433,35 @@ DimensionGeometry TechDraw::isValidSingleEdge3d(DrawViewPart* dvp, const Referen
TopoDS_Edge occEdge = TopoDS::Edge(refShape);
BRepAdaptor_Curve adapt(occEdge);
if (adapt.GetType() == GeomAbs_Line) {
Base::Vector3d point0 = Base::convertTo<Base::Vector3d>(BRep_Tool::Pnt(TopExp::FirstVertex(occEdge)));
auto point0 = Base::convertTo<Base::Vector3d>(BRep_Tool::Pnt(TopExp::FirstVertex(occEdge)));
point0 = dvp->projectPoint(point0);
Base::Vector3d point1 = Base::convertTo<Base::Vector3d>(BRep_Tool::Pnt(TopExp::LastVertex(occEdge)));
auto point1 = Base::convertTo<Base::Vector3d>(BRep_Tool::Pnt(TopExp::LastVertex(occEdge)));
point1 = dvp->projectPoint(point1);
Base::Vector3d line = point1 - point0;
if (fabs(line.y) < std::numeric_limits<float>::epsilon()) {
return DimensionGeometry::isVertical;
}
if (fabs(line.x) < std::numeric_limits<float>::epsilon()) {
return DimensionGeometry::isHorizontal;
}
// we don't support Z direction dimensions
// else if (fabs(line.z) < std::numeric_limits<float>::epsilon()) {
// return TechDraw::isZLimited;
// }
else {
return DimensionGeometry::isDiagonal;
}
} else if (adapt.GetType() == GeomAbs_Circle) {
return DimensionGeometry::isDiagonal;
}
if (adapt.GetType() == GeomAbs_Circle) {
return DimensionGeometry::isCircle;
} else if (adapt.GetType() == GeomAbs_Ellipse) {
}
if (adapt.GetType() == GeomAbs_Ellipse) {
return DimensionGeometry::isEllipse;
} else if (adapt.GetType() == GeomAbs_BSplineCurve) {
}
else if (adapt.GetType() == GeomAbs_BSplineCurve) {
if (GeometryUtils::isCircle(occEdge)) {
return DimensionGeometry::isBSplineCircle;
}
@@ -540,8 +554,10 @@ DimensionGeometry TechDraw::isValidMultiEdge(const ReferenceVector& refs)
line0.Normalize();
Base::Vector3d line1 = gen1->points.at(1) - gen1->points.at(0);
line1.Normalize();
double dot = fabs(line0.Dot(line1));
if (DU::fpCompare(dot, 1.0, EWTOLERANCE)) {
auto lineDot{line0.Dot(line1)};
if (lineDot >= 1 ||
lineDot <= -1) {
// the edges are parallel
return DimensionGeometry::isDiagonal; //distance || line
}
return DimensionGeometry::isAngle; //angle or distance
@@ -594,16 +610,17 @@ DimensionGeometry TechDraw::isValidMultiEdge3d(DrawViewPart* dvp, const Referenc
}
if (edgesAll.size() == 2) {
Base::Vector3d first0 = Base::convertTo<Base::Vector3d>(BRep_Tool::Pnt(TopExp::FirstVertex(edgesAll.at(0))));
Base::Vector3d last0 = Base::convertTo<Base::Vector3d>(BRep_Tool::Pnt(TopExp::LastVertex(edgesAll.at(1))));
auto first0 = Base::convertTo<Base::Vector3d>(BRep_Tool::Pnt(TopExp::FirstVertex(edgesAll.at(0))));
auto last0 = Base::convertTo<Base::Vector3d>(BRep_Tool::Pnt(TopExp::LastVertex(edgesAll.at(1))));
Base::Vector3d line0 = last0 - first0;
Base::Vector3d first1 = Base::convertTo<Base::Vector3d>(BRep_Tool::Pnt(TopExp::FirstVertex(edgesAll.at(0))));
Base::Vector3d last1 = Base::convertTo<Base::Vector3d>(BRep_Tool::Pnt(TopExp::LastVertex(edgesAll.at(1))));
auto first1 = Base::convertTo<Base::Vector3d>(BRep_Tool::Pnt(TopExp::FirstVertex(edgesAll.at(0))));
auto last1 = Base::convertTo<Base::Vector3d>(BRep_Tool::Pnt(TopExp::LastVertex(edgesAll.at(1))));
Base::Vector3d line1 = last1 - first1;
line0.Normalize();
line1.Normalize();
auto dot = fabs(line0.Dot(line1));
if (DU::fpCompare(dot, 1.0, EWTOLERANCE)) {
auto lineDot{std::fabs(line0.Dot(line1))};
double localTolerance{std::numeric_limits<float>::epsilon()}; // this is as close as we can reliably measure
if (DU::fpCompare(lineDot, 1, localTolerance)) {
//lines are parallel, must be distance dim
return DimensionGeometry::isDiagonal;
}
@@ -620,7 +637,7 @@ DimensionGeometry TechDraw::isValidVertexes(const ReferenceVector& refs)
auto* dvp(dynamic_cast<TechDraw::DrawViewPart*>(refs.front().getObject()));
if (!dvp) {
//probably redundant
throw Base::RuntimeError("Logic error in isValidMultiEdge");
throw Base::RuntimeError("Logic error in isValidVertexes");
}
const std::string matchToken{"Vertex"};
@@ -635,11 +652,13 @@ DimensionGeometry TechDraw::isValidVertexes(const ReferenceVector& refs)
Base::Vector3d line = v1->point() - v0->point();
if (fabs(line.y) < std::numeric_limits<float>::epsilon()) {
return DimensionGeometry::isHorizontal;
} else if (fabs(line.x) < std::numeric_limits<float>::epsilon()) {
return DimensionGeometry::isHorizontal;
} else {
return DimensionGeometry::isDiagonal;
}
if (fabs(line.x) < std::numeric_limits<float>::epsilon()) {
return DimensionGeometry::isVertical;
}
return DimensionGeometry::isDiagonal;
} else if (refs.size() == 3) {
//three vertices make an angle dimension
return DimensionGeometry::isAngle3Pt;
@@ -666,9 +685,9 @@ DimensionGeometry TechDraw::isValidVertexes3d(DrawViewPart* dvp, const Reference
|| geometry1.ShapeType() != TopAbs_VERTEX) {
return DimensionGeometry::isInvalid;
}
Base::Vector3d point0 = Base::convertTo<Base::Vector3d>(BRep_Tool::Pnt(TopoDS::Vertex(geometry0)));
auto point0 = Base::convertTo<Base::Vector3d>(BRep_Tool::Pnt(TopoDS::Vertex(geometry0)));
point0 = dvp->projectPoint(point0);
Base::Vector3d point1 = Base::convertTo<Base::Vector3d>(BRep_Tool::Pnt(TopoDS::Vertex(geometry1)));
auto point1 = Base::convertTo<Base::Vector3d>(BRep_Tool::Pnt(TopoDS::Vertex(geometry1)));
point1 = dvp->projectPoint(point1);
Base::Vector3d line = point1 - point0;
if (fabs(line.y) < std::numeric_limits<float>::epsilon()) {
@@ -678,9 +697,9 @@ DimensionGeometry TechDraw::isValidVertexes3d(DrawViewPart* dvp, const Reference
return DimensionGeometry::isHorizontal;
// } else if(fabs(line.z) < std::numeric_limits<float>::epsilon()) {
// return isZLimited;
} else {
return DimensionGeometry::isDiagonal;
}
return DimensionGeometry::isDiagonal;
} else if (refs.size() == 3) {
//three vertices make an angle dimension
//we could check here that all the geometries are Vertex
@@ -774,6 +793,7 @@ long int TechDraw::mapGeometryTypeToDimType(long int dimType, DimensionGeometry
//! type token.
bool TechDraw::refsMatchToken(const ReferenceVector& refs, const std::string& matchToken)
{
//NOLINTNEXTLINE
for (auto& entry : refs) {
std::string entryToken = DU::getGeomTypeFromName(entry.getSubName(false));
if (entryToken != matchToken) {

View File

@@ -74,7 +74,7 @@ DimensionGeometry validateDimSelection3d(DrawViewPart* dvp,
const std::vector<int>& minimumCounts, //how many of each geometry are needed for a good dimension
const std::vector<DimensionGeometry>& acceptableDimensionGeometrys);//isVertical, isHorizontal, ...
bool validateSubnameList(const StringVector& subNames, GeometrySet acceptableGeometrySet);
bool validateSubnameList(const StringVector& subNames, const GeometrySet& acceptableGeometrySet);
DimensionGeometry getGeometryConfiguration(ReferenceVector valid2dReferences);
DimensionGeometry getGeometryConfiguration3d(DrawViewPart* dvp,