[TD]apply tester feedback on DimRepair

This commit is contained in:
wandererfan
2023-01-18 10:41:20 -05:00
committed by WandererFan
parent 75ceb8e03e
commit 547df2b4df
7 changed files with 398 additions and 362 deletions

View File

@@ -22,39 +22,39 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <cmath>
# include <cstdlib>
# include <cstring>
# include <sstream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <sstream>
# include <boost_regex.hpp>
#include <boost_regex.hpp>
# include <QChar>
# include <QPointF>
# include <QString>
#include <QChar>
#include <QPointF>
#include <QString>
# include <BRep_Builder.hxx>
# include <BRep_Tool.hxx>
# include <BRepAdaptor_Curve.hxx>
# include <BRepAdaptor_Surface.hxx>
# include <BRepBndLib.hxx>
# include <BRepBuilderAPI_MakeEdge.hxx>
# include <BRepExtrema_DistShapeShape.hxx>
# include <BRepLProp_CLProps.hxx>
# include <BRepLProp_CurveTool.hxx>
# include <BRepLProp_SLProps.hxx>
# include <BRepTools.hxx>
# include <GCPnts_AbscissaPoint.hxx>
# include <GeomAPI_ExtremaCurveCurve.hxx>
# include <gp_Ax3.hxx>
# include <gp_Dir.hxx>
# include <gp_Elips.hxx>
# include <gp_Pnt.hxx>
# include <gp_Vec.hxx>
# include <Precision.hxx>
# include <TopExp.hxx>
# include <TopExp_Explorer.hxx>
# include <TopTools_IndexedMapOfShape.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepAdaptor_Surface.hxx>
#include <BRepBndLib.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepExtrema_DistShapeShape.hxx>
#include <BRepLProp_CLProps.hxx>
#include <BRepLProp_CurveTool.hxx>
#include <BRepLProp_SLProps.hxx>
#include <BRepTools.hxx>
#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>
#include <GCPnts_AbscissaPoint.hxx>
#include <GeomAPI_ExtremaCurveCurve.hxx>
#include <Precision.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <gp_Ax3.hxx>
#include <gp_Dir.hxx>
#include <gp_Elips.hxx>
#include <gp_Pnt.hxx>
#include <gp_Vec.hxx>
#endif
#include <App/Application.h>
@@ -72,7 +72,7 @@
using namespace TechDraw;
/*static*/ int DrawUtil::getIndexFromName(std::string geomName)
/*static*/ int DrawUtil::getIndexFromName(const std::string& geomName)
{
// Base::Console().Message("DU::getIndexFromName(%s)\n", geomName.c_str());
boost::regex re("\\d+$");// one of more digits at end of string
@@ -81,8 +81,9 @@ using namespace TechDraw;
// char* endChar;
std::string::const_iterator begin = geomName.begin();
auto pos = geomName.rfind('.');
if (pos != std::string::npos)
if (pos != std::string::npos) {
begin += pos + 1;
}
std::string::const_iterator end = geomName.end();
std::stringstream ErrorMsg;
@@ -93,39 +94,38 @@ using namespace TechDraw;
if (boost::regex_search(begin, end, what, re, flags)) {
return int(std::stoi(what.str()));
}
else {
} else {
ErrorMsg << "getIndexFromName: malformed geometry name - " << geomName;
throw Base::ValueError(ErrorMsg.str());
}
}
std::string DrawUtil::getGeomTypeFromName(std::string geomName)
std::string DrawUtil::getGeomTypeFromName(const std::string& geomName)
{
if (geomName.empty()) {
throw Base::ValueError("getGeomTypeFromName - empty geometry name");
}
boost::regex re("^[a-zA-Z]*");//one or more letters at start of string
boost::match_results<std::string::const_iterator> what;
boost::match_flag_type flags = boost::match_default;
std::string::const_iterator begin = geomName.begin();
auto pos = geomName.rfind('.');
if (pos != std::string::npos)
if (pos != std::string::npos) {
begin += pos + 1;
}
std::string::const_iterator end = geomName.end();
std::stringstream ErrorMsg;
if (geomName.empty()) {
throw Base::ValueError("getGeomTypeFromName - empty geometry name");
}
if (boost::regex_search(begin, end, what, re, flags)) {
return what.str();//TODO: use std::stoi() in c++11
}
else {
} else {
ErrorMsg << "In getGeomTypeFromName: malformed geometry name - " << geomName;
throw Base::ValueError(ErrorMsg.str());
}
}
std::string DrawUtil::makeGeomName(std::string geomType, int index)
std::string DrawUtil::makeGeomName(const std::string& geomType, int index)
{
std::stringstream newName;
newName << geomType << index;
@@ -170,8 +170,7 @@ double DrawUtil::simpleMinDist(TopoDS_Shape s1, TopoDS_Shape s2)
int count = extss.NbSolution();
if (count != 0) {
return extss.Value();
}
else {
} else {
return -1;
}
}
@@ -187,8 +186,7 @@ double DrawUtil::angleWithX(TopoDS_Edge e, bool reverse)
Base::Vector3d u;
if (reverse) {
u = start - end;
}
else {
} else {
u = end - start;
}
double result = atan2(u.y, u.x);
@@ -207,11 +205,9 @@ double DrawUtil::angleWithX(TopoDS_Edge e, TopoDS_Vertex v, double tolerance)
BRepAdaptor_Curve adapt(e);
if (isFirstVert(e, v, tolerance)) {
param = adapt.FirstParameter();
}
else if (isLastVert(e, v, tolerance)) {
} else if (isLastVert(e, v, tolerance)) {
param = adapt.LastParameter();
}
else {
} else {
//TARFU
Base::Console().Message("Error: DU::angleWithX - v is neither first nor last \n");
}
@@ -240,19 +236,17 @@ double DrawUtil::incidenceAngleAtVertex(TopoDS_Edge e, TopoDS_Vertex v, double t
int noTangents = 0;
if (isFirstVert(e, v, tolerance)) {
vertexParam = adapt.FirstParameter();
BRepLProp_CLProps prop(adapt, vertexParam + paramOffset, noTangents,
Precision::Confusion());
BRepLProp_CLProps prop(
adapt, vertexParam + paramOffset, noTangents, Precision::Confusion());
const gp_Pnt& gOffsetPoint = prop.Value();
offsetPoint = Base::Vector3d(gOffsetPoint.X(), gOffsetPoint.Y(), gOffsetPoint.Z());
}
else if (isLastVert(e, v, tolerance)) {
} else if (isLastVert(e, v, tolerance)) {
vertexParam = adapt.LastParameter();
BRepLProp_CLProps prop(adapt, vertexParam - paramOffset, noTangents,
Precision::Confusion());
BRepLProp_CLProps prop(
adapt, vertexParam - paramOffset, noTangents, Precision::Confusion());
const gp_Pnt& gOffsetPoint = prop.Value();
offsetPoint = Base::Vector3d(gOffsetPoint.X(), gOffsetPoint.Y(), gOffsetPoint.Z());
}
else {
} else {
//TARFU
// Base::Console().Message("DU::incidenceAngle - v is neither first nor last \n");
}
@@ -306,16 +300,14 @@ DrawUtil::boxIntersect2d(Base::Vector3d point, Base::Vector3d dirIn, double xRan
if (DrawUtil::fpCompare(dir.x, 0.0)) {//vertical case
p1 = Base::Vector3d(point.x, point.y - (yRange / 2.0), 0.0);
p2 = Base::Vector3d(point.x, point.y + (yRange / 2.0), 0.0);
}
else {
} else {
double slope = dir.y / dir.x;
double left = -xRange / 2.0;
double right = xRange / 2.0;
if (DrawUtil::fpCompare(slope, 0.0)) {//horizontal case
p1 = Base::Vector3d(point.x - (xRange / 2.0), point.y);
p2 = Base::Vector3d(point.x + (xRange / 2.0), point.y);
}
else {//normal case
} else {//normal case
double top = yRange / 2.0;
double bottom = -yRange / 2.0;
double yLeft = point.y - slope * (point.x - left);
@@ -325,21 +317,17 @@ DrawUtil::boxIntersect2d(Base::Vector3d point, Base::Vector3d dirIn, double xRan
if ((bottom < yLeft) && (top > yLeft)) {
p1 = Base::Vector3d(left, yLeft);
}
else if (yLeft <= bottom) {
} else if (yLeft <= bottom) {
p1 = Base::Vector3d(xBottom, bottom);
}
else if (yLeft >= top) {
} else if (yLeft >= top) {
p1 = Base::Vector3d(xTop, top);
}
if ((bottom < yRight) && (top > yRight)) {
p2 = Base::Vector3d(right, yRight);
}
else if (yRight <= bottom) {
} else if (yRight <= bottom) {
p2 = Base::Vector3d(xBottom, bottom);
}
else if (yRight >= top) {
} else if (yRight >= top) {
p2 = Base::Vector3d(xTop, top);
}
}
@@ -388,8 +376,8 @@ bool DrawUtil::apparentIntersection(TopoDS_Edge& edge0, TopoDS_Edge& edge1, gp_P
gp_Vec D(gStart1.XYZ());
gp_Vec e(gEnd0.XYZ() - gStart0.XYZ());//direction of line0
gp_Vec f(gEnd1.XYZ() - gStart1.XYZ());//direction of line1
Base::Console().Message("DU::apparentInter - e: %s f: %s\n", formatVector(e).c_str(),
formatVector(f).c_str());
Base::Console().Message(
"DU::apparentInter - e: %s f: %s\n", formatVector(e).c_str(), formatVector(f).c_str());
//check for cases the algorithm doesn't handle well
gp_Vec C1(gEnd0.XYZ());
@@ -404,8 +392,10 @@ bool DrawUtil::apparentIntersection(TopoDS_Edge& edge0, TopoDS_Edge& edge1, gp_P
}
gp_Vec g(D - C);//between a point on each line
Base::Console().Message("DU::apparentInter - C: %s D: %s g: %s\n", formatVector(C).c_str(),
formatVector(D).c_str(), formatVector(g).c_str());
Base::Console().Message("DU::apparentInter - C: %s D: %s g: %s\n",
formatVector(C).c_str(),
formatVector(D).c_str(),
formatVector(g).c_str());
gp_Vec fxg = f.Crossed(g);
double h = fxg.Magnitude();
@@ -527,11 +517,9 @@ bool DrawUtil::vectorLess(const Base::Vector3d& v1, const Base::Vector3d& v2)
if ((v1 - v2).Length() > EWTOLERANCE) {//ie v1 != v2
if (!DrawUtil::fpCompare(v1.x, v2.x, 2.0 * EWTOLERANCE)) {
return (v1.x < v2.x);
}
else if (!DrawUtil::fpCompare(v1.y, v2.y, 2.0 * EWTOLERANCE)) {
} else if (!DrawUtil::fpCompare(v1.y, v2.y, 2.0 * EWTOLERANCE)) {
return (v1.y < v2.y);
}
else {
} else {
return (v1.z < v2.z);
}
}
@@ -800,17 +788,34 @@ double DrawUtil::sensibleScale(double working_scale)
working_scale *= std::pow(10, -exponent); //now find what 'a' is.
//int choices = 10;
float valid_scales[2][10] = {{1.0, 1.25, 2.0, 2.5, 3.75, 5.0, 7.5, 10.0, 50.0,
float valid_scales[2][10] = {{1.0,
1.25,
2.0,
2.5,
3.75,
5.0,
7.5,
10.0,
50.0,
100.0},//equate to 1:10, 1:8, 1:5, 1:4, 3:8, 1:2, 3:4, 1:1
// .1 .125 .375 .75
{1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 8.0, 10.0, 50.0,
{1.0,
1.5,
2.0,
3.0,
4.0,
5.0,
8.0,
10.0,
50.0,
100.0}};//equate to 1:1, 3:2, 2:1, 3:1, 4:1, 5:1, 8:1, 10:1
// 1.5:1
//int i = choices - 1;
int i = 9;
while (valid_scales[(exponent >= 0)][i]
> working_scale)//choose closest value smaller than 'a' from list.
i -= 1; //choosing top list if exponent -ve, bottom list for +ve exponent
> working_scale) {//choose closest value smaller than 'a' from list.
i -= 1; //choosing top list if exponent -ve, bottom list for +ve exponent
}
//now have the appropriate scale, reapply the *10^b
return valid_scales[(exponent >= 0)][i] * pow(10, exponent);
@@ -898,9 +903,15 @@ TopoDS_Shape DrawUtil::shapeFromString(std::string s)
return result;
}
Base::Vector3d DrawUtil::invertY(Base::Vector3d v) { return Base::Vector3d(v.x, -v.y, v.z); }
Base::Vector3d DrawUtil::invertY(Base::Vector3d v)
{
return Base::Vector3d(v.x, -v.y, v.z);
}
QPointF DrawUtil::invertY(QPointF v) { return QPointF(v.x(), -v.y()); }
QPointF DrawUtil::invertY(QPointF v)
{
return QPointF(v.x(), -v.y());
}
//obs? was used in CSV prototype of Cosmetics
@@ -1014,15 +1025,13 @@ bool DrawUtil::isCrazy(TopoDS_Edge e)
if (adapt.GetType() == GeomAbs_BSplineCurve && distance > 0.001 &&// not a closed loop
ratio > 9999.9) { // 10, 000x
return true; //this is crazy edge
}
else if (adapt.GetType() == GeomAbs_Ellipse) {
} else if (adapt.GetType() == GeomAbs_Ellipse) {
gp_Elips ellp = adapt.Ellipse();
double major = ellp.MajorRadius();
double minor = ellp.MinorRadius();
if (minor < 0.001) {//too narrow
return true;
}
else if (major > 9999.9) {//too big
} else if (major > 9999.9) {//too big
return true;
}
}
@@ -1049,10 +1058,11 @@ Base::Vector3d DrawUtil::getFaceCenter(TopoDS_Face f)
// test the circulation of the triangle A-B-C
bool DrawUtil::circulation(Base::Vector3d A, Base::Vector3d B, Base::Vector3d C)
{
if (A.x * B.y + A.y * C.x + B.x * C.y - C.x * B.y - C.y * A.x - B.x * A.y > 0.0)
if (A.x * B.y + A.y * C.x + B.x * C.y - C.x * B.y - C.y * A.x - B.x * A.y > 0.0) {
return true;
else
} else {
return false;
}
}
int DrawUtil::countSubShapes(TopoDS_Shape shape, TopAbs_ShapeEnum subShape)
@@ -1121,8 +1131,9 @@ std::list<TopoDS_Edge> DrawUtil::sort_Edges(double tol3d, std::list<TopoDS_Edge>
edge_points.push_back(ep);
}
if (edge_points.empty())
if (edge_points.empty()) {
return std::list<TopoDS_Edge>();
}
std::list<TopoDS_Edge> sorted;
gp_Pnt gpChainFirst, gpChainLast;
@@ -1145,8 +1156,7 @@ std::list<TopoDS_Edge> DrawUtil::sort_Edges(double tol3d, std::list<TopoDS_Edge>
edge_points.erase(itEdgePoint);
itEdgePoint = edge_points.begin();
break;
}
else if (itEdgePoint->v2.SquareDistance(gpChainFirst) <= tol3d) {
} else if (itEdgePoint->v2.SquareDistance(gpChainFirst) <= tol3d) {
//found a connection from start of chain to end of edge
gpChainFirst = itEdgePoint->v1;
sorted.push_front(itEdgePoint->edge);
@@ -1154,8 +1164,7 @@ std::list<TopoDS_Edge> DrawUtil::sort_Edges(double tol3d, std::list<TopoDS_Edge>
edge_points.erase(itEdgePoint);
itEdgePoint = edge_points.begin();
break;
}
else if (itEdgePoint->v2.SquareDistance(gpChainLast) <= tol3d) {
} else if (itEdgePoint->v2.SquareDistance(gpChainLast) <= tol3d) {
//found a connection from end of chain to end of edge
gpChainLast = itEdgePoint->v1;
Standard_Real firstParam, lastParam;
@@ -1170,8 +1179,7 @@ std::list<TopoDS_Edge> DrawUtil::sort_Edges(double tol3d, std::list<TopoDS_Edge>
edge_points.erase(itEdgePoint);
itEdgePoint = edge_points.begin();
break;
}
else if (itEdgePoint->v1.SquareDistance(gpChainFirst) <= tol3d) {
} else if (itEdgePoint->v1.SquareDistance(gpChainFirst) <= tol3d) {
//found a connection from start of chain to start of edge
gpChainFirst = itEdgePoint->v2;
Standard_Real firstParam, lastParam;
@@ -1207,7 +1215,10 @@ int DrawUtil::sgn(double x)
return (x > +Precision::Confusion()) - (x < -Precision::Confusion());
}
double DrawUtil::sqr(double x) { return x * x; }
double DrawUtil::sqr(double x)
{
return x * x;
}
void DrawUtil::angleNormalize(double& fi)
{
@@ -1344,8 +1355,7 @@ int DrawUtil::findRootForValue(double Ax2, double Bxy, double Cy2, double Dx, do
qA = Ax2;
qB = Bxy * value + Dx;
qC = Cy2 * value * value + Ey * value + F;
}
else {
} else {
qA = Cy2;
qB = Bxy * value + Ey;
qC = Ax2 * value * value + Dx * value + F;
@@ -1358,30 +1368,25 @@ int DrawUtil::findRootForValue(double Ax2, double Bxy, double Cy2, double Dx, do
if (fabs(qC) > Precision::Confusion()) {
// This equation has no solution
return 0;
}
else {
} else {
// Signal infinite number of solutions by returning 2, but do not touch root variables
return 2;
}
}
else {
} else {
roots[0] = -qC / qB;
return 1;
}
}
else {
} else {
double qD = sqr(qB) - 4.0 * qA * qC;
if (qD < -Precision::Confusion()) {
// Negative discriminant => no real roots
return 0;
}
else if (qD > +Precision::Confusion()) {
} else if (qD > +Precision::Confusion()) {
// Two distinctive roots
roots[0] = (-qB + sqrt(qD)) * 0.5 / qA;
roots[1] = (-qB - sqrt(qD)) * 0.5 / qA;
return 2;
}
else {
} else {
// Double root
roots[0] = -qB * 0.5 / qA;
return 1;
@@ -1417,8 +1422,8 @@ void DrawUtil::findConicRectangleIntersections(double conicAx2, double conicBxy,
// Find intersections with rectangle left side line
roots[0] = rectangle.MinY;
roots[1] = rectangle.MaxY;
rootCount = findRootForValue(conicAx2, conicBxy, conicCy2, conicDx, conicEy, conicF,
rectangle.MinX, false, roots);
rootCount = findRootForValue(
conicAx2, conicBxy, conicCy2, conicDx, conicEy, conicF, rectangle.MinX, false, roots);
if (rootCount > 0) {
mergeBoundedPoint(Base::Vector2d(rectangle.MinX, roots[0]), rectangle, intersections);
}
@@ -1429,8 +1434,8 @@ void DrawUtil::findConicRectangleIntersections(double conicAx2, double conicBxy,
// Find intersections with rectangle right side line
roots[0] = rectangle.MinY;
roots[1] = rectangle.MaxY;
rootCount = findRootForValue(conicAx2, conicBxy, conicCy2, conicDx, conicEy, conicF,
rectangle.MaxX, false, roots);
rootCount = findRootForValue(
conicAx2, conicBxy, conicCy2, conicDx, conicEy, conicF, rectangle.MaxX, false, roots);
if (rootCount > 0) {
mergeBoundedPoint(Base::Vector2d(rectangle.MaxX, roots[0]), rectangle, intersections);
}
@@ -1441,8 +1446,8 @@ void DrawUtil::findConicRectangleIntersections(double conicAx2, double conicBxy,
// Find intersections with rectangle top side line
roots[0] = rectangle.MinX;
roots[1] = rectangle.MaxX;
rootCount = findRootForValue(conicAx2, conicBxy, conicCy2, conicDx, conicEy, conicF,
rectangle.MinY, true, roots);
rootCount = findRootForValue(
conicAx2, conicBxy, conicCy2, conicDx, conicEy, conicF, rectangle.MinY, true, roots);
if (rootCount > 0) {
mergeBoundedPoint(Base::Vector2d(roots[0], rectangle.MinY), rectangle, intersections);
}
@@ -1453,8 +1458,8 @@ void DrawUtil::findConicRectangleIntersections(double conicAx2, double conicBxy,
// Find intersections with rectangle top side line
roots[0] = rectangle.MinX;
roots[1] = rectangle.MaxX;
rootCount = findRootForValue(conicAx2, conicBxy, conicCy2, conicDx, conicEy, conicF,
rectangle.MaxY, true, roots);
rootCount = findRootForValue(
conicAx2, conicBxy, conicCy2, conicDx, conicEy, conicF, rectangle.MaxY, true, roots);
if (rootCount > 0) {
mergeBoundedPoint(Base::Vector2d(roots[0], rectangle.MaxY), rectangle, intersections);
}
@@ -1468,9 +1473,14 @@ void DrawUtil::findLineRectangleIntersections(const Base::Vector2d& linePoint, d
std::vector<Base::Vector2d>& intersections)
{
Base::Vector2d lineDirection(Base::Vector2d::FromPolar(1.0, lineAngle));
findConicRectangleIntersections(0.0, 0.0, 0.0, +lineDirection.y, -lineDirection.x,
findConicRectangleIntersections(0.0,
0.0,
0.0,
+lineDirection.y,
-lineDirection.x,
lineDirection.x * linePoint.y - lineDirection.y * linePoint.x,
rectangle, intersections);
rectangle,
intersections);
}
void DrawUtil::findCircleRectangleIntersections(const Base::Vector2d& circleCenter,
@@ -1478,9 +1488,14 @@ void DrawUtil::findCircleRectangleIntersections(const Base::Vector2d& circleCent
const Base::BoundBox2d& rectangle,
std::vector<Base::Vector2d>& intersections)
{
findConicRectangleIntersections(1.0, 0.0, 1.0, -2.0 * circleCenter.x, -2.0 * circleCenter.y,
findConicRectangleIntersections(1.0,
0.0,
1.0,
-2.0 * circleCenter.x,
-2.0 * circleCenter.y,
sqr(circleCenter.x) + sqr(circleCenter.y) - sqr(circleRadius),
rectangle, intersections);
rectangle,
intersections);
}
void DrawUtil::findLineSegmentRectangleIntersections(const Base::Vector2d& linePoint,
@@ -1504,8 +1519,7 @@ void DrawUtil::findLineSegmentRectangleIntersections(const Base::Vector2d& lineP
if (pointPosition < segmentBasePosition - Precision::Confusion()
|| pointPosition > segmentBasePosition + segmentLength + Precision::Confusion()) {
intersections.erase(intersections.begin() + i);
}
else {
} else {
++i;
}
}
@@ -1513,7 +1527,8 @@ void DrawUtil::findLineSegmentRectangleIntersections(const Base::Vector2d& lineP
// Try to add the line segment end points
mergeBoundedPoint(linePoint + segmentBasePosition * segmentDirection, rectangle, intersections);
mergeBoundedPoint(linePoint + (segmentBasePosition + segmentLength) * segmentDirection,
rectangle, intersections);
rectangle,
intersections);
}
void DrawUtil::findCircularArcRectangleIntersections(const Base::Vector2d& circleCenter,
@@ -1541,18 +1556,19 @@ void DrawUtil::findCircularArcRectangleIntersections(const Base::Vector2d& circl
if (pointAngle > arcBaseAngle + arcRotation + Precision::Confusion()) {
intersections.erase(intersections.begin() + i);
}
else {
} else {
++i;
}
}
// Try to add the circular arc end points
mergeBoundedPoint(circleCenter + Base::Vector2d::FromPolar(circleRadius, arcBaseAngle),
rectangle, intersections);
rectangle,
intersections);
mergeBoundedPoint(circleCenter
+ Base::Vector2d::FromPolar(circleRadius, arcBaseAngle + arcRotation),
rectangle, intersections);
rectangle,
intersections);
}
//copy whole text file from inSpec to outSpec
@@ -1572,8 +1588,8 @@ void DrawUtil::copyFile(std::string inSpec, std::string outSpec)
}
bool rc = fi.copyTo(outSpec.c_str());
if (!rc) {
Base::Console().Message("DU::copyFile - failed - in: %s out:%s\n", inSpec.c_str(),
outSpec.c_str());
Base::Console().Message(
"DU::copyFile - failed - in: %s out:%s\n", inSpec.c_str(), outSpec.c_str());
}
}
@@ -1645,15 +1661,28 @@ void DrawUtil::dumpEdge(const char* label, int i, TopoDS_Edge e)
//Base::Console().Message("%s edge:%d start:(%.3f, %.3f, %.3f)/%0.3f end:(%.2f, %.3f, %.3f)/%.3f\n", label, i,
// vStart.X(), vStart.Y(), vStart.Z(), start, vEnd.X(), vEnd.Y(), vEnd.Z(), end);
Base::Console().Message(
"%s edge:%d start:(%.3f, %.3f, %.3f) end:(%.2f, %.3f, %.3f) Orient: %d\n", label, i,
vStart.X(), vStart.Y(), vStart.Z(), vEnd.X(), vEnd.Y(), vEnd.Z(), e.Orientation());
"%s edge:%d start:(%.3f, %.3f, %.3f) end:(%.2f, %.3f, %.3f) Orient: %d\n",
label,
i,
vStart.X(),
vStart.Y(),
vStart.Z(),
vEnd.X(),
vEnd.Y(),
vEnd.Z(),
e.Orientation());
double edgeLength = GCPnts_AbscissaPoint::Length(adapt, Precision::Confusion());
Base::Console().Message(">>>>>>> length: %.3f distance: %.3f ration: %.3f type: %d\n",
edgeLength, vStart.Distance(vEnd), edgeLength / vStart.Distance(vEnd),
edgeLength,
vStart.Distance(vEnd),
edgeLength / vStart.Distance(vEnd),
adapt.GetType());
}
const char* DrawUtil::printBool(bool b) { return (b ? "True" : "False"); }
const char* DrawUtil::printBool(bool b)
{
return (b ? "True" : "False");
}
QString DrawUtil::qbaToDebug(const QByteArray& line)
{
@@ -1664,8 +1693,7 @@ QString DrawUtil::qbaToDebug(const QByteArray& line)
c = line[i];
if ((c >= 0x20) && (c <= 126)) {
s.append(QChar::fromLatin1(c));
}
else {
} else {
s.append(QString::fromUtf8("<%1>").arg(c, 2, 16, QChar::fromLatin1('0')));
}
}
@@ -1678,10 +1706,12 @@ void DrawUtil::dumpCS(const char* text, const gp_Ax2& CS)
gp_Dir baseX = CS.XDirection();
gp_Dir baseY = CS.YDirection();
gp_Pnt baseOrg = CS.Location();
Base::Console().Message(
"DU::dumpCS - %s Loc: %s Axis: %s X: %s Y: %s\n", text,
DrawUtil::formatVector(baseOrg).c_str(), DrawUtil::formatVector(baseAxis).c_str(),
DrawUtil::formatVector(baseX).c_str(), DrawUtil::formatVector(baseY).c_str());
Base::Console().Message("DU::dumpCS - %s Loc: %s Axis: %s X: %s Y: %s\n",
text,
DrawUtil::formatVector(baseOrg).c_str(),
DrawUtil::formatVector(baseAxis).c_str(),
DrawUtil::formatVector(baseX).c_str(),
DrawUtil::formatVector(baseY).c_str());
}
void DrawUtil::dumpCS3(const char* text, const gp_Ax3& CS)
@@ -1690,8 +1720,10 @@ void DrawUtil::dumpCS3(const char* text, const gp_Ax3& CS)
gp_Dir baseX = CS.XDirection();
gp_Dir baseY = CS.YDirection();
gp_Pnt baseOrg = CS.Location();
Base::Console().Message(
"DU::dumpCS3 - %s Loc: %s Axis: %s X: %s Y: %s\n", text,
DrawUtil::formatVector(baseOrg).c_str(), DrawUtil::formatVector(baseAxis).c_str(),
DrawUtil::formatVector(baseX).c_str(), DrawUtil::formatVector(baseY).c_str());
Base::Console().Message("DU::dumpCS3 - %s Loc: %s Axis: %s X: %s Y: %s\n",
text,
DrawUtil::formatVector(baseOrg).c_str(),
DrawUtil::formatVector(baseAxis).c_str(),
DrawUtil::formatVector(baseX).c_str(),
DrawUtil::formatVector(baseY).c_str());
}

View File

@@ -30,18 +30,18 @@
#include <QString>
#include <Geom_Curve.hxx>
#include <gp_Ax2.hxx>
#include <gp_Dir.hxx>
#include <gp_Dir2d.hxx>
#include <gp_Pnt.hxx>
#include <gp_Pnt2d.hxx>
#include <gp_Vec.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Wire.hxx>
#include <gp_Ax2.hxx>
#include <gp_Dir.hxx>
#include <gp_Dir2d.hxx>
#include <gp_Pnt.hxx>
#include <gp_Pnt2d.hxx>
#include <gp_Vec.hxx>
#include <Base/Vector3D.h>
#include <Mod/Part/App/PartFeature.h>
@@ -72,7 +72,8 @@ namespace TechDraw
{
//used by sort_Edges
struct EdgePoints {
struct EdgePoints
{
gp_Pnt v1, v2;
std::list<TopoDS_Edge>::iterator it;
TopoDS_Edge edge;
@@ -82,9 +83,9 @@ struct EdgePoints {
class TechDrawExport DrawUtil
{
public:
static int getIndexFromName(std::string geomName);
static std::string getGeomTypeFromName(std::string geomName);
static std::string makeGeomName(std::string geomType, int index);
static int getIndexFromName(const std::string& geomName);
static std::string getGeomTypeFromName(const std::string& geomName);
static std::string makeGeomName(const std::string& geomType, int index);
static bool isSamePoint(TopoDS_Vertex v1, TopoDS_Vertex v2, double tolerance = VERTEXTOLERANCE);
static bool isZeroEdge(TopoDS_Edge e, double tolerance = VERTEXTOLERANCE);
static double simpleMinDist(TopoDS_Shape s1, TopoDS_Shape s2);
@@ -117,7 +118,8 @@ public:
static bool vectorLess(const Base::Vector3d& v1, const Base::Vector3d& v2);
//!std::map require comparator to be a type not a function
struct vectorLessType {
struct vectorLessType
{
bool operator()(const Base::Vector3d& a, const Base::Vector3d& b) const
{
return DrawUtil::vectorLess(a, b);
@@ -171,10 +173,22 @@ public:
return Base::Vector3d(gp.x(), gp.y(), 0.0);
}
static gp_Pnt togp_Pnt(const Base::Vector3d v) { return gp_Pnt(v.x, v.y, v.z); }
static gp_Dir togp_Dir(const Base::Vector3d v) { return gp_Dir(v.x, v.y, v.z); }
static gp_Vec togp_Vec(const Base::Vector3d v) { return gp_Vec(v.x, v.y, v.z); }
static QPointF toQPointF(const Base::Vector3d v) { return QPointF(v.x, v.y); }
static gp_Pnt togp_Pnt(const Base::Vector3d v)
{
return gp_Pnt(v.x, v.y, v.z);
}
static gp_Dir togp_Dir(const Base::Vector3d v)
{
return gp_Dir(v.x, v.y, v.z);
}
static gp_Vec togp_Vec(const Base::Vector3d v)
{
return gp_Vec(v.x, v.y, v.z);
}
static QPointF toQPointF(const Base::Vector3d v)
{
return QPointF(v.x, v.y);
}
static std::string shapeToString(TopoDS_Shape s);
static TopoDS_Shape shapeFromString(std::string s);

View File

@@ -1222,12 +1222,13 @@ void CmdTechDrawDimensionRepair::activated(int iMsg)
dim = static_cast<TechDraw::DrawViewDimension*>(dimObjs.at(0));
}
ReferenceVector references2d;
ReferenceVector references3d;
//TechDraw::DrawViewPart* partFeat =
TechDraw::getReferencesFromSelection(references2d, references3d);
// ReferenceVector references2d;
// ReferenceVector references3d;
// //TechDraw::DrawViewPart* partFeat =
// TechDraw::getReferencesFromSelection(references2d, references3d);
Gui::Control().showDialog(new TaskDlgDimReference(dim, references2d, references3d));
// Gui::Control().showDialog(new TaskDlgDimReference(dim, references2d, references3d));
Gui::Control().showDialog(new TaskDlgDimReference(dim));
}
bool CmdTechDrawDimensionRepair::isActive(void)

View File

@@ -22,10 +22,10 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <BRep_Tool.hxx>
# include <BRepAdaptor_Curve.hxx>
# include <TopExp.hxx>
#endif //#ifndef _PreComp_
#include <BRepAdaptor_Curve.hxx>
#include <BRep_Tool.hxx>
#include <TopExp.hxx>
#endif//#ifndef _PreComp_
#include <App/DocumentObject.h>
#include <Base/Console.h>
@@ -48,11 +48,11 @@ TechDraw::DrawViewPart* TechDraw::getReferencesFromSelection(ReferenceVector& re
for (auto& selItem : selectionAll) {
if (selItem.getObject()->isDerivedFrom(TechDraw::DrawViewDimension::getClassTypeId())) {
//we are probably repairing a dimension, but we will check later
dim = static_cast<TechDraw::DrawViewDimension*> (selItem.getObject());
dim = static_cast<TechDraw::DrawViewDimension*>(selItem.getObject());
} else if (selItem.getObject()->isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
//this could be a 2d geometry selection or just a DrawViewPart for context in
//a 3d selection
dvp = static_cast<TechDraw::DrawViewPart*> (selItem.getObject());
dvp = static_cast<TechDraw::DrawViewPart*>(selItem.getObject());
if (selItem.getSubNames().empty()) {
//there are no subNames, so we think this is a 3d case,
//and we only need to select the view. We set the reference
@@ -64,7 +64,7 @@ TechDraw::DrawViewPart* TechDraw::getReferencesFromSelection(ReferenceVector& re
ReferenceEntry ref(dvp, sub);
references2d.push_back(ref);
}
} else if ( !selItem.getObject()->isDerivedFrom(TechDraw::DrawView::getClassTypeId()) ) {
} else if (!selItem.getObject()->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
//this is not a TechDraw object, so we check to see if it has 3d geometry
std::vector<App::DocumentObject*> links;
links.push_back(selItem.getObject());
@@ -90,8 +90,7 @@ TechDraw::DrawViewPart* TechDraw::getReferencesFromSelection(ReferenceVector& re
ReferenceEntry ref(obj3d, sub3d);
references3d.push_back(ref);
}
}
else {
} else {
Base::Console().Message("DV::getRefsFromSel - %s has no shape!\n",
selItem.getObject()->getNameInDocument());
}
@@ -117,8 +116,8 @@ DimensionGeometryType TechDraw::validateDimSelection(
StringVector subNames;
TechDraw::DrawViewPart* dvpSave(nullptr);
for (auto& ref : references) {
TechDraw::DrawViewPart* dvp = dynamic_cast<TechDraw::DrawViewPart *>(ref.getObject());
if ( dvp ) {
TechDraw::DrawViewPart* dvp = dynamic_cast<TechDraw::DrawViewPart*>(ref.getObject());
if (dvp) {
dvpSave = dvp;
//TODO: check for non-empty subname?
subNames.push_back(ref.getSubName());
@@ -217,22 +216,20 @@ DimensionGeometryType TechDraw::validateDimSelection3d(
return isInvalid;
}
bool TechDraw::validateSubnameList(StringVector subNames,
GeometrySet acceptableGeometrySet)
bool TechDraw::validateSubnameList(StringVector subNames, GeometrySet acceptableGeometrySet)
{
for (auto& sub : subNames) {
std::string geometryType = DrawUtil::getGeomTypeFromName(sub);
if (acceptableGeometrySet.count(geometryType) == 0) {
//this geometry type is not allowed
return false;
}
}
}
return true;
}
//count how many of each "Edge", "Vertex, etc and compare totals to required minimum
bool TechDraw::checkGeometryOccurences(StringVector subNames,
GeomCountMap keyedMinimumCounts)
bool TechDraw::checkGeometryOccurences(StringVector subNames, GeomCountMap keyedMinimumCounts)
{
//how many of each geometry descriptor are input
GeomCountMap foundCounts;
@@ -270,19 +267,19 @@ bool TechDraw::checkGeometryOccurences(StringVector subNames,
DimensionGeometryType TechDraw::getGeometryConfiguration(ReferenceVector valid2dReferences)
{
DimensionGeometryType config = isValidMultiEdge(valid2dReferences);
if ( config > isInvalid) {
if (config > isInvalid) {
return config;
}
config = isValidVertexes(valid2dReferences);
if ( config > isInvalid) {
if (config > isInvalid) {
return config;
}
config = isValidSingleEdge(valid2dReferences.front());
if ( config > isInvalid) {
if (config > isInvalid) {
return config;
}
config = isValidHybrid(valid2dReferences);
if ( config > isInvalid) {
if (config > isInvalid) {
return config;
}
@@ -310,24 +307,24 @@ DimensionGeometryType TechDraw::getGeometryConfiguration3d(DrawViewPart* dvp,
}
if (!wholeObjectRefs.empty()) {
//mix of whole object and subelement refs
return isMultiEdge; //??? correct ???
return isMultiEdge;//??? correct ???
}
//only have subelement refs
DimensionGeometryType config = isValidMultiEdge3d(dvp, valid3dReferences);
if ( config > isInvalid) {
if (config > isInvalid) {
return config;
}
config = isValidVertexes3d(dvp, valid3dReferences);
if ( config > isInvalid) {
if (config > isInvalid) {
return config;
}
config = isValidSingleEdge3d(dvp, valid3dReferences.front());
if ( config > isInvalid) {
if (config > isInvalid) {
return config;
}
config = isValidHybrid3d(dvp, valid3dReferences);
if ( config > isInvalid) {
if (config > isInvalid) {
return config;
}
@@ -338,7 +335,7 @@ DimensionGeometryType TechDraw::getGeometryConfiguration3d(DrawViewPart* dvp,
//fill the GeomCountMap with pairs made from corresponding items in acceptableGeometry
//and minimumCounts
GeomCountMap TechDraw::loadRequiredCounts(StringVector& acceptableGeometry,
std::vector<int>& minimumCounts)
std::vector<int>& minimumCounts)
{
if (acceptableGeometry.size() != minimumCounts.size()) {
throw Base::IndexError("acceptableGeometry and minimum counts have different sizes.");
@@ -356,7 +353,7 @@ GeomCountMap TechDraw::loadRequiredCounts(StringVector& acceptableGeometry,
//! verify that Selection contains a valid Geometry for a single Edge Dimension
DimensionGeometryType TechDraw::isValidSingleEdge(ReferenceEntry ref)
{
auto objFeat( dynamic_cast<TechDraw::DrawViewPart *>(ref.getObject()) );
auto objFeat(dynamic_cast<TechDraw::DrawViewPart*>(ref.getObject()));
if (!objFeat) {
return isInvalid;
}
@@ -368,7 +365,7 @@ DimensionGeometryType TechDraw::isValidSingleEdge(ReferenceEntry ref)
}
//the geometry exists (redundant?)
int GeoId( TechDraw::DrawUtil::getIndexFromName(ref.getSubName()) );
int GeoId(TechDraw::DrawUtil::getIndexFromName(ref.getSubName()));
TechDraw::BaseGeomPtr geom = objFeat->getGeomByIndex(GeoId);
if (!geom) {
return isInvalid;
@@ -382,26 +379,20 @@ DimensionGeometryType TechDraw::isValidSingleEdge(ReferenceEntry ref)
Base::Vector3d line = gen1->points.at(1) - gen1->points.at(0);
if (fabs(line.y) < FLT_EPSILON) {
return TechDraw::isHorizontal;
}
else if (fabs(line.x) < FLT_EPSILON) {
} else if (fabs(line.x) < FLT_EPSILON) {
return TechDraw::isVertical;
}
else {
} else {
return TechDraw::isDiagonal;
}
}
else if (geom->geomType == TechDraw::CIRCLE || geom->geomType == TechDraw::ARCOFCIRCLE) {
} else if (geom->geomType == TechDraw::CIRCLE || geom->geomType == TechDraw::ARCOFCIRCLE) {
return isCircle;
}
else if (geom->geomType == TechDraw::ELLIPSE || geom->geomType == TechDraw::ARCOFELLIPSE) {
} else if (geom->geomType == TechDraw::ELLIPSE || geom->geomType == TechDraw::ARCOFELLIPSE) {
return isEllipse;
}
else if (geom->geomType == TechDraw::BSPLINE) {
} else if (geom->geomType == TechDraw::BSPLINE) {
TechDraw::BSplinePtr spline = std::static_pointer_cast<TechDraw::BSpline>(geom);
if (spline->isCircle()) {
return isBSplineCircle;
}
else {
} else {
return isBSpline;
}
}
@@ -409,9 +400,9 @@ DimensionGeometryType TechDraw::isValidSingleEdge(ReferenceEntry ref)
}
//! verify that Selection contains a valid Geometry for a single Edge Dimension
DimensionGeometryType TechDraw::isValidSingleEdge3d(DrawViewPart *dvp, ReferenceEntry ref)
DimensionGeometryType TechDraw::isValidSingleEdge3d(DrawViewPart* dvp, ReferenceEntry ref)
{
(void) dvp;
(void)dvp;
//the Name starts with "Edge"
std::string geomName = DrawUtil::getGeomTypeFromName(ref.getSubName());
if (geomName != "Edge") {
@@ -427,32 +418,29 @@ DimensionGeometryType TechDraw::isValidSingleEdge3d(DrawViewPart *dvp, Reference
BRepAdaptor_Curve adapt(occEdge);
if (adapt.GetType() == GeomAbs_Line) {
Base::Vector3d point0 = DU::toVector3d(BRep_Tool::Pnt(TopExp::FirstVertex(occEdge)));
point0 = dvp->projectPoint(point0);
Base::Vector3d point1 = DU::toVector3d(BRep_Tool::Pnt(TopExp::LastVertex(occEdge)));
point1 = dvp->projectPoint(point1);
Base::Vector3d line = point1 - point0;
if (fabs(line.y) < FLT_EPSILON) {
return TechDraw::isHorizontal;
}
else if (fabs(line.x) < FLT_EPSILON) {
} else if (fabs(line.x) < FLT_EPSILON) {
return TechDraw::isVertical;
}
else if (fabs(line.z) < FLT_EPSILON) {
return TechDraw::isZLimited;
}
// else if (fabs(line.z) < FLT_EPSILON) {
// return TechDraw::isZLimited;
// }
else {
return TechDraw::isDiagonal;
}
}
else if (adapt.GetType() == GeomAbs_Circle) {
} else if (adapt.GetType() == GeomAbs_Circle) {
return isCircle;
}
else if (adapt.GetType() == GeomAbs_Ellipse) {
} else if (adapt.GetType() == GeomAbs_Ellipse) {
return isEllipse;
}
else if (adapt.GetType() == GeomAbs_BSplineCurve) {
} else if (adapt.GetType() == GeomAbs_BSplineCurve) {
if (GeometryUtils::isCircle(occEdge)) {
return isBSplineCircle;
}
else {
} else {
return isBSpline;
}
}
@@ -465,19 +453,19 @@ DimensionGeometryType TechDraw::isValidSingleEdge3d(DrawViewPart *dvp, Reference
DimensionGeometryType TechDraw::isValidMultiEdge(ReferenceVector refs)
{
//there has to be at least 2
if(refs.size() < 2) {
if (refs.size() < 2) {
return isInvalid;
}
auto objFeat0( dynamic_cast<TechDraw::DrawViewPart *>(refs.at(0).getObject()));
if ( !objFeat0 ) {
auto objFeat0(dynamic_cast<TechDraw::DrawViewPart*>(refs.at(0).getObject()));
if (!objFeat0) {
//probably redundant
throw Base::RuntimeError("Logic error in isValidMultiEdge");
}
//they all must start with "Edge"
for (auto& ref : refs) {
if(TechDraw::DrawUtil::getGeomTypeFromName(ref.getSubName()) != "Edge" ) {
if (TechDraw::DrawUtil::getGeomTypeFromName(ref.getSubName()) != "Edge") {
return isInvalid;
}
}
@@ -488,29 +476,27 @@ DimensionGeometryType TechDraw::isValidMultiEdge(ReferenceVector refs)
}
//exactly 2 edges. could be angle, could be distance
int GeoId0( TechDraw::DrawUtil::getIndexFromName(refs.at(0).getSubName()) );
int GeoId1( TechDraw::DrawUtil::getIndexFromName(refs.at(1).getSubName()) );
int GeoId0(TechDraw::DrawUtil::getIndexFromName(refs.at(0).getSubName()));
int GeoId1(TechDraw::DrawUtil::getIndexFromName(refs.at(1).getSubName()));
TechDraw::BaseGeomPtr geom0 = objFeat0->getGeomByIndex(GeoId0);
TechDraw::BaseGeomPtr geom1 = objFeat0->getGeomByIndex(GeoId1);
if(geom0->geomType == TechDraw::GENERIC &&
geom1->geomType == TechDraw::GENERIC) {
TechDraw::GenericPtr gen0 = std::static_pointer_cast<TechDraw::Generic> (geom0);
TechDraw::GenericPtr gen1 = std::static_pointer_cast<TechDraw::Generic> (geom1);
if(gen0->points.size() > 2 ||
gen1->points.size() > 2) { //the edge is a polyline
return isInvalid; //not supported yet
if (geom0->geomType == TechDraw::GENERIC && geom1->geomType == TechDraw::GENERIC) {
TechDraw::GenericPtr gen0 = std::static_pointer_cast<TechDraw::Generic>(geom0);
TechDraw::GenericPtr gen1 = std::static_pointer_cast<TechDraw::Generic>(geom1);
if (gen0->points.size() > 2 || gen1->points.size() > 2) {//the edge is a polyline
return isInvalid; //not supported yet
}
Base::Vector3d line0 = gen0->points.at(1) - gen0->points.at(0);
Base::Vector3d line1 = gen1->points.at(1) - gen1->points.at(0);
double xprod = fabs(line0.x * line1.y - line0.y * line1.x);
if (xprod > FLT_EPSILON) { //edges are not parallel
return isAngle; //angle or distance
if (xprod > FLT_EPSILON) {//edges are not parallel
return isAngle; //angle or distance
} else {
return isDiagonal; //distance || line
return isDiagonal;//distance || line
}
} else {
return isDiagonal; //two edges, not both straight lines
return isDiagonal;//two edges, not both straight lines
}
return isInvalid;
@@ -518,11 +504,11 @@ DimensionGeometryType TechDraw::isValidMultiEdge(ReferenceVector refs)
//! verify that the edge references can make a dimension. Currently only extent
//! dimensions support more than 2 edges
DimensionGeometryType TechDraw::isValidMultiEdge3d(DrawViewPart *dvp, ReferenceVector refs)
DimensionGeometryType TechDraw::isValidMultiEdge3d(DrawViewPart* dvp, ReferenceVector refs)
{
(void) dvp;
(void)dvp;
//there has to be at least 2
if(refs.size() < 2) {
if (refs.size() < 2) {
return isInvalid;
}
@@ -580,8 +566,8 @@ DimensionGeometryType TechDraw::isValidMultiEdge3d(DrawViewPart *dvp, ReferenceV
//! verify that the vertex references can make a dimension
DimensionGeometryType TechDraw::isValidVertexes(ReferenceVector refs)
{
TechDraw::DrawViewPart* dvp( dynamic_cast<TechDraw::DrawViewPart*>(refs.front().getObject()) );
if ( !dvp ) {
TechDraw::DrawViewPart* dvp(dynamic_cast<TechDraw::DrawViewPart*>(refs.front().getObject()));
if (!dvp) {
//probably redundant
throw Base::RuntimeError("Logic error in isValidMultiEdge");
}
@@ -591,9 +577,9 @@ DimensionGeometryType TechDraw::isValidVertexes(ReferenceVector refs)
TechDraw::VertexPtr v0 = dvp->getVertex(refs.at(0).getSubName());
TechDraw::VertexPtr v1 = dvp->getVertex(refs.at(1).getSubName());
Base::Vector3d line = v1->point() - v0->point();
if(fabs(line.y) < FLT_EPSILON ) {
if (fabs(line.y) < FLT_EPSILON) {
return isHorizontal;
} else if(fabs(line.x) < FLT_EPSILON) {
} else if (fabs(line.x) < FLT_EPSILON) {
return isVertical;
} else {
return isDiagonal;
@@ -603,21 +589,20 @@ DimensionGeometryType TechDraw::isValidVertexes(ReferenceVector refs)
return isAngle3Pt;
}
// did not find a valid configuration
return isInvalid;
// did not find a valid configuration
return isInvalid;
}
//! verify that the vertex references can make a dimension
DimensionGeometryType TechDraw::isValidVertexes3d(DrawViewPart *dvp, ReferenceVector refs)
DimensionGeometryType TechDraw::isValidVertexes3d(DrawViewPart* dvp, ReferenceVector refs)
{
(void) dvp;
(void)dvp;
if (refs.size() == 2) {
//2 vertices can only make a distance dimension
TopoDS_Shape geometry0 = refs.at(0).getGeometry();
TopoDS_Shape geometry1 = refs.at(1).getGeometry();
if (geometry0.IsNull() || geometry1.IsNull() ||
geometry0.ShapeType() != TopAbs_VERTEX ||
geometry1.ShapeType() != TopAbs_VERTEX) {
if (geometry0.IsNull() || geometry1.IsNull() || geometry0.ShapeType() != TopAbs_VERTEX
|| geometry1.ShapeType() != TopAbs_VERTEX) {
return isInvalid;
}
Base::Vector3d point0 = DU::toVector3d(BRep_Tool::Pnt(TopoDS::Vertex(geometry0)));
@@ -625,12 +610,12 @@ DimensionGeometryType TechDraw::isValidVertexes3d(DrawViewPart *dvp, ReferenceVe
Base::Vector3d point1 = DU::toVector3d(BRep_Tool::Pnt(TopoDS::Vertex(geometry1)));
point1 = dvp->projectPoint(point1);
Base::Vector3d line = point1 - point0;
if(fabs(line.y) < FLT_EPSILON ) {
if (fabs(line.y) < FLT_EPSILON) {
return isHorizontal;
} else if(fabs(line.x) < FLT_EPSILON) {
} else if (fabs(line.x) < FLT_EPSILON) {
return isVertical;
// } else if(fabs(line.z) < FLT_EPSILON) {
// return isZLimited;
// } else if(fabs(line.z) < FLT_EPSILON) {
// return isZLimited;
} else {
return isDiagonal;
}
@@ -640,8 +625,8 @@ DimensionGeometryType TechDraw::isValidVertexes3d(DrawViewPart *dvp, ReferenceVe
return isAngle3Pt;
}
// did not find a valid configuration
return isInvalid;
// did not find a valid configuration
return isInvalid;
}
//! verify that the mixed bag (ex Vertex-Edge) of references can make a dimension
@@ -661,8 +646,7 @@ DimensionGeometryType TechDraw::isValidHybrid(ReferenceVector refs)
edgeCount++;
}
}
if (vertexCount > 0 &&
edgeCount > 0) {
if (vertexCount > 0 && edgeCount > 0) {
//must be a diagonal dim? could it be isHorizontal or isVertical?
return isDiagonal;
}
@@ -671,16 +655,15 @@ DimensionGeometryType TechDraw::isValidHybrid(ReferenceVector refs)
}
//! verify that the mixed bag (ex Vertex-Edge) of references can make a dimension
DimensionGeometryType TechDraw::isValidHybrid3d(DrawViewPart *dvp, ReferenceVector refs)
DimensionGeometryType TechDraw::isValidHybrid3d(DrawViewPart* dvp, ReferenceVector refs)
{
(void) dvp;
(void)dvp;
//we don't have a special check for 3d in this case
return isValidHybrid(refs);
}
//handle situations where revised geometry type is valid but not suitable for existing dimType
long int TechDraw::mapGeometryTypeToDimType(long int dimType,
DimensionGeometryType geometry2d,
long int TechDraw::mapGeometryTypeToDimType(long int dimType, DimensionGeometryType geometry2d,
DimensionGeometryType geometry3d)
{
if (geometry2d == isInvalid && geometry3d == isInvalid) {

View File

@@ -22,12 +22,12 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <string>
# include <vector>
#include <string>
#include <vector>
# include <QMessageBox>
# include <QTableWidgetItem>
#endif // #ifndef _PreComp_
#include <QMessageBox>
#include <QTableWidgetItem>
#endif// #ifndef _PreComp_
#include <App/Document.h>
#include <Base/Tools.h>
@@ -38,32 +38,21 @@
#include <Mod/TechDraw/App/DrawView.h>
#include <Mod/TechDraw/App/DrawViewPart.h>
#include "DimensionValidators.h"
#include "TaskDimRepair.h"
#include "ui_TaskDimRepair.h"
#include "DimensionValidators.h"
using namespace Gui;
using namespace TechDraw;
using namespace TechDrawGui;
TaskDimRepair::TaskDimRepair(TechDraw::DrawViewDimension* inDvd,
ReferenceVector references2d,
ReferenceVector references3d) :
ui(new Ui_TaskDimRepair),
m_dim(inDvd),
m_references2d(references2d),
m_references3d(references3d)
TaskDimRepair::TaskDimRepair(TechDraw::DrawViewDimension* inDvd)
: ui(new Ui_TaskDimRepair),
m_dim(inDvd)
{
ui->setupUi(this);
if (m_references2d.size() == 1 &&
m_references2d.front().getSubName().empty() &&
m_references3d.empty()) {
//the entry in references2d is a spurious View reference (from getReferencesFromSelection),
// not a geometry reference, so we treat it as empty
m_references2d.clear();
}
connect(ui->pbSelection, SIGNAL(clicked(bool)), this, SLOT(slotUseSelection()));
saveDimState();
@@ -71,8 +60,7 @@ TaskDimRepair::TaskDimRepair(TechDraw::DrawViewDimension* inDvd,
}
TaskDimRepair::~TaskDimRepair()
{
}
{}
void TaskDimRepair::setUiPrimary()
{
@@ -90,19 +78,11 @@ void TaskDimRepair::setUiPrimary()
std::vector<std::string> noLabels(subElements2d.size());
fillList(ui->lwGeometry2d, subElements2d, noLabels);
const std::vector<App::DocumentObject*>& objs3d = m_dim->References3D.getValues();
QStringList headers;
headers << tr("Object Name")
<< tr("Object Label")
<< tr("SubElement");
headers << tr("Object Name") << tr("Object Label") << tr("SubElement");
ui->twReferences3d->setHorizontalHeaderLabels(headers);
ReferenceVector references3d;
if (!m_references3d.empty()) {
references3d = m_references3d;
} else if (!objs3d.empty()) {
references3d = m_dim->getReferences3d();
}
ReferenceVector references3d = m_dim->getReferences3d();
loadTableWidget(ui->twReferences3d, references3d);
}
@@ -129,13 +109,14 @@ void TaskDimRepair::restoreDimState()
//use the current selection to replace the references in dim
void TaskDimRepair::slotUseSelection()
{
const std::vector<App::DocumentObject*> dimObjects = Gui::Selection().getObjectsOfType(TechDraw::DrawViewDimension::getClassTypeId());
const std::vector<App::DocumentObject*> dimObjects =
Gui::Selection().getObjectsOfType(TechDraw::DrawViewDimension::getClassTypeId());
if (dimObjects.empty()) {
//selection does not include a dimension, so we need to add our dimension to keep the
//validators happy
//bool accepted =
static_cast<void> (Gui::Selection().addSelection(m_dim->getDocument()->getName(),
m_dim->getNameInDocument()));
static_cast<void>(Gui::Selection().addSelection(m_dim->getDocument()->getName(),
m_dim->getNameInDocument()));
}
ReferenceVector references2d;
ReferenceVector references3d;
@@ -147,13 +128,11 @@ void TaskDimRepair::slotUseSelection()
return;
}
StringVector acceptableGeometry( { "Edge", "Vertex" } );
std::vector<int> minimumCounts( { 1, 1 } );
std::vector<DimensionGeometryType> acceptableDimensionGeometrys; //accept anything
DimensionGeometryType geometryRefs2d = validateDimSelection(references2d,
acceptableGeometry,
minimumCounts,
acceptableDimensionGeometrys);
StringVector acceptableGeometry({"Edge", "Vertex"});
std::vector<int> minimumCounts({1, 1});
std::vector<DimensionGeometryType> acceptableDimensionGeometrys;//accept anything
DimensionGeometryType geometryRefs2d = validateDimSelection(
references2d, acceptableGeometry, minimumCounts, acceptableDimensionGeometrys);
if (geometryRefs2d == isInvalid) {
QMessageBox::warning(Gui::getMainWindow(),
QObject::tr("Incorrect Selection"),
@@ -162,14 +141,10 @@ void TaskDimRepair::slotUseSelection()
}
//what 3d geometry configuration did we receive?
DimensionGeometryType geometryRefs3d(isInvalid);
if (geometryRefs2d == TechDraw::isViewReference &&
!references3d.empty()) {
geometryRefs3d = validateDimSelection3d(dvp,
references3d,
acceptableGeometry,
minimumCounts,
acceptableDimensionGeometrys);
if ( geometryRefs3d == isInvalid) {
if (geometryRefs2d == TechDraw::isViewReference && !references3d.empty()) {
geometryRefs3d = validateDimSelection3d(
dvp, references3d, acceptableGeometry, minimumCounts, acceptableDimensionGeometrys);
if (geometryRefs3d == isInvalid) {
QMessageBox::warning(Gui::getMainWindow(),
QObject::tr("Incorrect Selection"),
QObject::tr("Can not make dimension from selection"));
@@ -177,14 +152,12 @@ void TaskDimRepair::slotUseSelection()
}
}
m_dimType = mapGeometryTypeToDimType(m_dim->Type.getValue(),
geometryRefs2d,
geometryRefs3d);
m_references2d = references2d;
m_dimType = mapGeometryTypeToDimType(m_dim->Type.getValue(), geometryRefs2d, geometryRefs3d);
m_toApply2d = references2d;
if (references3d.empty()) {
m_references3d.clear();
m_toApply3d.clear();
} else {
m_references3d = references3d;
m_toApply3d = references3d;
}
updateUi();
}
@@ -196,12 +169,13 @@ void TaskDimRepair::updateUi()
ui->leObject2d->setText(Base::Tools::fromStdString(objName + " / " + objLabel));
std::vector<std::string> subElements2d;
for (auto& ref : m_references2d) {
for (auto& ref : m_toApply2d) {
subElements2d.push_back(ref.getSubName());
}
std::vector<std::string> noLabels(subElements2d.size());
fillList(ui->lwGeometry2d, subElements2d, noLabels);
loadTableWidget(ui->twReferences3d, m_references3d);
loadTableWidget(ui->twReferences3d, m_toApply3d);
}
void TaskDimRepair::loadTableWidget(QTableWidget* tw, ReferenceVector refs)
@@ -213,20 +187,21 @@ void TaskDimRepair::loadTableWidget(QTableWidget* tw, ReferenceVector refs)
QString qName = Base::Tools::fromStdString(ref.getObject()->getNameInDocument());
QTableWidgetItem* itemName = new QTableWidgetItem(qName);
itemName->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
tw->setItem(iRow,0, itemName);
tw->setItem(iRow, 0, itemName);
QString qLabel = Base::Tools::fromStdString(std::string(ref.getObject()->Label.getValue()));
QTableWidgetItem* itemLabel = new QTableWidgetItem(qLabel);
itemLabel->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
tw->setItem(iRow,1, itemLabel);
tw->setItem(iRow, 1, itemLabel);
QString qSubName = Base::Tools::fromStdString(ref.getSubName());
QTableWidgetItem* itemSubName = new QTableWidgetItem(qSubName);
itemSubName->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
tw->setItem(iRow,2, itemSubName);
tw->setItem(iRow, 2, itemSubName);
iRow++;
}
}
void TaskDimRepair::fillList(QListWidget* lwItems, std::vector<std::string> labels, std::vector<std::string> names)
void TaskDimRepair::fillList(QListWidget* lwItems, std::vector<std::string> labels,
std::vector<std::string> names)
{
QListWidgetItem* item;
QString qLabel;
@@ -249,19 +224,23 @@ void TaskDimRepair::replaceReferences()
if (!m_dim) {
return;
}
if (!m_references2d.empty()) {
m_dim->setReferences2d(m_references2d);
if (!m_toApply2d.empty()) {
m_dim->setReferences2d(m_toApply2d);
}
if (!m_references3d.empty()) {
m_dim->setReferences3d(m_references3d);
if (!m_toApply3d.empty()) {
m_dim->setReferences3d(m_toApply3d);
}
}
bool TaskDimRepair::accept()
{
Gui::Command::doCommand(Gui::Command::Gui, "Gui.ActiveDocument.resetEdit()");
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Repair Dimension"));
replaceReferences();
m_dim->Type.setValue(m_dimType);
Gui::Command::commitCommand();
m_dim->recomputeFeature();
return true;
}
@@ -273,7 +252,7 @@ bool TaskDimRepair::reject()
return false;
}
void TaskDimRepair::changeEvent(QEvent *e)
void TaskDimRepair::changeEvent(QEvent* e)
{
if (e->type() == QEvent::LanguageChange) {
ui->retranslateUi(this);
@@ -281,22 +260,19 @@ void TaskDimRepair::changeEvent(QEvent *e)
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TaskDlgDimReference::TaskDlgDimReference(TechDraw::DrawViewDimension* inDvd,
ReferenceVector references2d,
ReferenceVector references3d) :
TaskDialog()
TaskDlgDimReference::TaskDlgDimReference(TechDraw::DrawViewDimension* inDvd)
: TaskDialog()
{
widget = new TaskDimRepair(inDvd, references2d, references3d);
taskbox = new Gui::TaskView::TaskBox(Gui::BitmapFactory().pixmap("TechDraw_DimensionRepair"),
widget->windowTitle(), true, 0);
widget = new TaskDimRepair(inDvd);
taskbox = new Gui::TaskView::TaskBox(
Gui::BitmapFactory().pixmap("TechDraw_DimensionRepair"), widget->windowTitle(), true, 0);
taskbox->groupLayout()->addWidget(widget);
Content.push_back(taskbox);
}
TaskDlgDimReference::~TaskDlgDimReference()
{
}
{}
void TaskDlgDimReference::update()
{
@@ -305,8 +281,7 @@ void TaskDlgDimReference::update()
//==== calls from the TaskView ===============================================================
void TaskDlgDimReference::open()
{
}
{}
void TaskDlgDimReference::clicked(int i)
{

View File

@@ -28,8 +28,8 @@
#include <Gui/TaskView/TaskDialog.h>
#include <Gui/TaskView/TaskView.h>
#include <Mod/TechDraw/TechDrawGlobal.h>
#include <Mod/TechDraw/App/DrawViewDimension.h>
#include <Mod/TechDraw/TechDrawGlobal.h>
class Ui_TaskDimRepair;
@@ -42,14 +42,12 @@ class DocumentObject;
namespace TechDrawGui
{
class TaskDimRepair : public QWidget
class TaskDimRepair: public QWidget
{
Q_OBJECT
public:
TaskDimRepair(TechDraw::DrawViewDimension* inDvd,
TechDraw::ReferenceVector references2d,
TechDraw::ReferenceVector references3d);
TaskDimRepair(TechDraw::DrawViewDimension* inDvd);
~TaskDimRepair();
public:
@@ -60,12 +58,13 @@ protected Q_SLOTS:
void slotUseSelection();
protected:
void changeEvent(QEvent *e);
void changeEvent(QEvent* e);
void setUiPrimary();
void replaceReferences();
void updateUi();
void fillList(QListWidget* lwItems, std::vector<std::string> labels, std::vector<std::string> names);
void fillList(QListWidget* lwItems, std::vector<std::string> labels,
std::vector<std::string> names);
void loadTableWidget(QTableWidget* tw, TechDraw::ReferenceVector refs);
void saveDimState();
void restoreDimState();
@@ -73,8 +72,6 @@ protected:
private:
std::unique_ptr<Ui_TaskDimRepair> ui;
TechDraw::DrawViewDimension* m_dim;
TechDraw::ReferenceVector m_references2d;
TechDraw::ReferenceVector m_references3d;
long int m_dimType;
long int m_saveMeasureType;
@@ -82,16 +79,16 @@ private:
TechDraw::DrawViewPart* m_saveDvp;
TechDraw::ReferenceVector m_saveRefs2d;
TechDraw::ReferenceVector m_saveRefs3d;
TechDraw::ReferenceVector m_toApply2d;
TechDraw::ReferenceVector m_toApply3d;
};
class TaskDlgDimReference : public Gui::TaskView::TaskDialog
class TaskDlgDimReference: public Gui::TaskView::TaskDialog
{
Q_OBJECT
public:
TaskDlgDimReference(TechDraw::DrawViewDimension* inDvd,
TechDraw::ReferenceVector references2d,
TechDraw::ReferenceVector references3d);
TaskDlgDimReference(TechDraw::DrawViewDimension* inDvd);
~TaskDlgDimReference();
public:
@@ -104,19 +101,23 @@ public:
/// is called by the framework if the dialog is rejected (Cancel)
virtual bool reject();
/// is called by the framework if the user presses the help button
virtual void helpRequested() { return;}
virtual void helpRequested()
{
return;
}
virtual bool isAllowedAlterDocument(void) const
{ return false; }
{
return false;
}
void update();
protected:
private:
TaskDimRepair * widget;
TaskDimRepair* widget;
Gui::TaskView::TaskBox* taskbox;
};
} //namespace TechDrawGui
}//namespace TechDrawGui
#endif // #ifndef TECHDRAW_TASKDIMREPAIR_H
#endif// #ifndef TECHDRAW_TASKDIMREPAIR_H

View File

@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>356</width>
<width>355</width>
<height>512</height>
</rect>
</property>
@@ -41,6 +41,12 @@
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
@@ -54,6 +60,12 @@
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
@@ -64,6 +76,12 @@
</item>
<item row="2" column="1">
<widget class="QPushButton" name="pbSelection">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Replace References with Current Selection</string>
</property>
@@ -91,6 +109,12 @@
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="leObject2d">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>The View that owns this Dimension</string>
</property>
@@ -165,6 +189,12 @@
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QTableWidget" name="twReferences3d">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>