[TD]fix wrong calculation of 3d two edge angle

This commit is contained in:
wandererfan
2023-01-07 07:17:15 -05:00
committed by WandererFan
parent 7d5c47c633
commit 97b6788464
6 changed files with 987 additions and 849 deletions

View File

@@ -30,8 +30,8 @@
#include <Base/Console.h>
#include "DrawViewPart.h"
#include "DrawUtil.h"
#include "DrawViewPart.h"
#include "DimensionGeometry.h"
@@ -44,12 +44,14 @@ pointPair::pointPair(const pointPair& pp)
second(pp.second());
}
//move the points by offset
void pointPair::move(Base::Vector3d offset)
{
m_first = m_first - offset;
m_second = m_second - offset;
}
// project the points onto the dvp's paper plane. Points are still in R3 coords.
void pointPair::project(DrawViewPart* dvp)
{
Base::Vector3d normal = DrawUtil::toVector3d(dvp->getProjectionCS().Direction());
@@ -58,11 +60,12 @@ void pointPair::project(DrawViewPart* dvp)
m_second = m_second.ProjectToPlane(stdOrigin, normal) * dvp->getScale();
}
// map the points onto the dvp's XY coordinate system
void pointPair::mapToPage(DrawViewPart* dvp)
{
gp_Trsf xOXYZ;
gp_Ax3 OXYZ;
xOXYZ.SetTransformation(OXYZ, gp_Ax3(dvp->getProjectionCS()));
xOXYZ.SetTransformation(OXYZ, gp_Ax3(dvp->getRotatedCS()));
gp_Vec gvFirst = DU::togp_Vec(m_first).Transformed(xOXYZ);
m_first = DU::toVector3d(gvFirst);
@@ -80,8 +83,7 @@ void pointPair::dump(std::string text) const
{
Base::Console().Message("pointPair - %s\n", text.c_str());
Base::Console().Message("pointPair - first: %s second: %s\n",
DU::formatVector(first()).c_str(),
DU::formatVector(second()).c_str());
DU::formatVector(first()).c_str(), DU::formatVector(second()).c_str());
}
anglePoints::anglePoints()
@@ -91,26 +93,23 @@ anglePoints::anglePoints()
m_vertex = Base::Vector3d(0.0, 0.0, 0.0);
}
anglePoints::anglePoints(const anglePoints& ap)
: m_ends(ap.ends()),
m_vertex(ap.vertex())
{
anglePoints::anglePoints(const anglePoints& ap) : m_ends(ap.ends()), m_vertex(ap.vertex()) {}
}
anglePoints& anglePoints::operator= (const anglePoints& ap)
anglePoints& anglePoints::operator=(const anglePoints& ap)
{
m_ends = ap.ends();
m_vertex = ap.vertex();
return *this;
}
// move the points by offset
void anglePoints::move(Base::Vector3d offset)
{
m_ends.move(offset);
m_vertex = m_vertex - offset;
}
// project the points onto the dvp's paper plane. Points are still in R3 coords.
void anglePoints::project(DrawViewPart* dvp)
{
Base::Vector3d normal = DrawUtil::toVector3d(dvp->getProjectionCS().Direction());
@@ -119,17 +118,19 @@ void anglePoints::project(DrawViewPart* dvp)
m_vertex = m_vertex.ProjectToPlane(stdOrigin, normal) * dvp->getScale();
}
// map the points onto the dvp's XY coordinate system
void anglePoints::mapToPage(DrawViewPart* dvp)
{
m_ends.mapToPage(dvp);
gp_Trsf xOXYZ;
gp_Ax3 OXYZ;
xOXYZ.SetTransformation(OXYZ, gp_Ax3(dvp->getProjectionCS()));
xOXYZ.SetTransformation(OXYZ, gp_Ax3(dvp->getRotatedCS()));
gp_Vec gvVertex = DU::togp_Vec(m_vertex).Transformed(xOXYZ);
m_vertex = DU::toVector3d(gvVertex);
}
// map the points onto the coordinate system used for drawing where -Y direction is "up"
void anglePoints::invertY()
{
m_ends.invertY();
@@ -140,38 +141,29 @@ void anglePoints::dump(std::string text) const
{
Base::Console().Message("anglePoints - %s\n", text.c_str());
Base::Console().Message("anglePoints - ends - first: %s second: %s\n",
DU::formatVector(first()).c_str(),
DU::formatVector(second()).c_str());
Base::Console().Message("anglePoints - vertex: %s\n",
DU::formatVector(vertex()).c_str());
DU::formatVector(first()).c_str(), DU::formatVector(second()).c_str());
Base::Console().Message("anglePoints - vertex: %s\n", DU::formatVector(vertex()).c_str());
}
arcPoints::arcPoints()
{
isArc = false;
radius = 0.0;
center = Base::Vector3d(0.0, 0.0, 0.0);
onCurve.first(Base::Vector3d(0.0, 0.0, 0.0));
onCurve.second(Base::Vector3d(0.0, 0.0, 0.0));
arcEnds.first(Base::Vector3d(0.0, 0.0, 0.0));
arcEnds.second(Base::Vector3d(0.0, 0.0, 0.0));
midArc = Base::Vector3d(0.0, 0.0, 0.0);
arcCW = false;
isArc = false;
radius = 0.0;
center = Base::Vector3d(0.0, 0.0, 0.0);
onCurve.first(Base::Vector3d(0.0, 0.0, 0.0));
onCurve.second(Base::Vector3d(0.0, 0.0, 0.0));
arcEnds.first(Base::Vector3d(0.0, 0.0, 0.0));
arcEnds.second(Base::Vector3d(0.0, 0.0, 0.0));
midArc = Base::Vector3d(0.0, 0.0, 0.0);
arcCW = false;
}
arcPoints::arcPoints(const arcPoints& ap)
: isArc(ap.isArc)
, radius(ap.radius)
, center(ap.center)
, onCurve(ap.onCurve)
, arcEnds(ap.arcEnds)
, midArc(ap.midArc)
, arcCW(ap.arcCW)
{
: isArc(ap.isArc), radius(ap.radius), center(ap.center), onCurve(ap.onCurve),
arcEnds(ap.arcEnds), midArc(ap.midArc), arcCW(ap.arcCW)
{}
}
arcPoints& arcPoints::operator= (const arcPoints& ap)
arcPoints& arcPoints::operator=(const arcPoints& ap)
{
isArc = ap.isArc;
radius = ap.radius;
@@ -210,7 +202,7 @@ void arcPoints::mapToPage(DrawViewPart* dvp)
{
gp_Trsf xOXYZ;
gp_Ax3 OXYZ;
xOXYZ.SetTransformation(OXYZ, gp_Ax3(dvp->getProjectionCS()));
xOXYZ.SetTransformation(OXYZ, gp_Ax3(dvp->getRotatedCS()));
gp_Vec gvCenter = DU::togp_Vec(center).Transformed(xOXYZ);
center = DU::toVector3d(gvCenter);
@@ -237,7 +229,8 @@ void arcPoints::invertY()
void arcPoints::dump(std::string text) const
{
Base::Console().Message("arcPoints - %s\n", text.c_str());
Base::Console().Message("arcPoints - radius: %.3f center: %s\n", radius, DrawUtil::formatVector(center).c_str());
Base::Console().Message("arcPoints - radius: %.3f center: %s\n", radius,
DrawUtil::formatVector(center).c_str());
Base::Console().Message("arcPoints - isArc: %d arcCW: %d\n", isArc, arcCW);
Base::Console().Message("arcPoints - onCurve: %s %s\n",
DrawUtil::formatVector(onCurve.first()).c_str(),
@@ -245,7 +238,5 @@ void arcPoints::dump(std::string text) const
Base::Console().Message("arcPoints - arcEnds: %s %s\n",
DrawUtil::formatVector(arcEnds.first()).c_str(),
DrawUtil::formatVector(arcEnds.second()).c_str());
Base::Console().Message("arcPoints - midArc: %s\n",
DrawUtil::formatVector(midArc).c_str());
Base::Console().Message("arcPoints - midArc: %s\n", DrawUtil::formatVector(midArc).c_str());
}

File diff suppressed because it is too large Load Diff

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>
@@ -49,13 +49,13 @@
#ifndef M_2PI
# define M_2PI ((M_PI) * 2.0)
#define M_2PI ((M_PI)*2.0)
#endif
#define VERTEXTOLERANCE (2.0 * Precision::Confusion())
#define VECTORTOLERANCE (Precision::Confusion())
#define SVG_NS_URI "http://www.w3.org/2000/svg"
#define SVG_NS_URI "http://www.w3.org/2000/svg"
#define FREECAD_SVG_NS_URI "http://www.freecadweb.org/wiki/index.php?title=Svg_Namespace"
//some shapes are being passed in where edges that should be connected are in fact
@@ -79,161 +79,177 @@ struct EdgePoints {
};
/// Convenient utility functions for TechDraw Module
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 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);
static double sensibleScale(double working_scale);
static double angleWithX(TopoDS_Edge e, bool reverse);
static double angleWithX(TopoDS_Edge e, TopoDS_Vertex v, double tolerance = VERTEXTOLERANCE);
static double incidenceAngleAtVertex(TopoDS_Edge e, TopoDS_Vertex v, double tolerance);
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 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);
static double sensibleScale(double working_scale);
static double angleWithX(TopoDS_Edge e, bool reverse);
static double angleWithX(TopoDS_Edge e, TopoDS_Vertex v, double tolerance = VERTEXTOLERANCE);
static double incidenceAngleAtVertex(TopoDS_Edge e, TopoDS_Vertex v, double tolerance);
static bool isFirstVert(TopoDS_Edge e, TopoDS_Vertex v, double tolerance = VERTEXTOLERANCE);
static bool isLastVert(TopoDS_Edge e, TopoDS_Vertex v, double tolerance = VERTEXTOLERANCE);
static bool fpCompare(const double& d1, const double& d2, double tolerance = FLT_EPSILON);
static std::pair<Base::Vector3d, Base::Vector3d> boxIntersect2d(Base::Vector3d point,
Base::Vector3d dir,
double xRange,
double yRange) ;
static bool apparentIntersection(const Handle(Geom_Curve) curve1,
const Handle(Geom_Curve) curve2,
Base::Vector3d& result);
static bool isFirstVert(TopoDS_Edge e, TopoDS_Vertex v, double tolerance = VERTEXTOLERANCE);
static bool isLastVert(TopoDS_Edge e, TopoDS_Vertex v, double tolerance = VERTEXTOLERANCE);
static bool fpCompare(const double& d1, const double& d2, double tolerance = FLT_EPSILON);
static std::pair<Base::Vector3d, Base::Vector3d>
boxIntersect2d(Base::Vector3d point, Base::Vector3d dir, double xRange, double yRange);
static bool apparentIntersection(const Handle(Geom_Curve) curve1,
const Handle(Geom_Curve) curve2, Base::Vector3d& result);
static bool apparentIntersection(TopoDS_Edge& edge0, TopoDS_Edge& edge1, gp_Pnt& intersect);
static bool intersect2Lines3d(Base::Vector3d p0, Base::Vector3d d0, Base::Vector3d p1,
Base::Vector3d d1, Base::Vector3d& intersect);
static Base::Vector3d vertex2Vector(const TopoDS_Vertex& v);
static Base::Vector3d vertex2Vector(const TopoDS_Vertex& v);
static std::string formatVector(const Base::Vector3d& v);
static std::string formatVector(const gp_Dir& v);
static std::string formatVector(const gp_Dir2d& v);
static std::string formatVector(const gp_Vec& v);
static std::string formatVector(const gp_Pnt& v);
static std::string formatVector(const gp_Pnt2d& v);
static std::string formatVector(const QPointF& v);
static std::string formatVector(const Base::Vector3d& v);
static std::string formatVector(const gp_Dir& v);
static std::string formatVector(const gp_Dir2d& v);
static std::string formatVector(const gp_Vec& v);
static std::string formatVector(const gp_Pnt& v);
static std::string formatVector(const gp_Pnt2d& v);
static std::string formatVector(const QPointF& v);
static bool vectorLess(const Base::Vector3d& v1, const Base::Vector3d& v2);
//!std::map require comparator to be a type not a function
struct vectorLessType {
bool operator()(const Base::Vector3d& a, const Base::Vector3d& b) const
{
return DrawUtil::vectorLess(a, b);
}
};
static bool vertexEqual(TopoDS_Vertex& v1, TopoDS_Vertex& v2);
static bool vectorEqual(Base::Vector3d& v1, Base::Vector3d& v2);
static bool vectorLess(const Base::Vector3d& v1, const Base::Vector3d& v2);
//!std::map require comparator to be a type not a function
struct vectorLessType {
bool operator()(const Base::Vector3d& a, const Base::Vector3d& b) const {
return DrawUtil::vectorLess(a, b);
}
};
static bool vertexEqual(TopoDS_Vertex& v1, TopoDS_Vertex& v2);
static bool vectorEqual(Base::Vector3d& v1, Base::Vector3d& v2);
static TopoDS_Shape vectorToCompound(std::vector<TopoDS_Edge> vecIn);
static TopoDS_Shape vectorToCompound(std::vector<TopoDS_Wire> vecIn);
static std::vector<TopoDS_Edge> shapeToVector(TopoDS_Shape shapeIn);
static TopoDS_Shape vectorToCompound(std::vector<TopoDS_Edge> vecIn);
static TopoDS_Shape vectorToCompound(std::vector<TopoDS_Wire> vecIn);
static std::vector<TopoDS_Edge> shapeToVector(TopoDS_Shape shapeIn);
static Base::Vector3d toR3(const gp_Ax2& fromSystem, const Base::Vector3d& fromPoint);
static bool checkParallel(const Base::Vector3d v1, const Base::Vector3d v2,
double tolerance = FLT_EPSILON);
//! rotate vector by angle radians around axis through org
static Base::Vector3d vecRotate(Base::Vector3d vec, double angle, Base::Vector3d axis,
Base::Vector3d org = Base::Vector3d(0.0, 0.0, 0.0));
static Base::Vector3d toR3(const gp_Ax2& fromSystem, const Base::Vector3d& fromPoint);
static bool checkParallel(const Base::Vector3d v1, const Base::Vector3d v2, double tolerance = FLT_EPSILON);
//! rotate vector by angle radians around axis through org
static Base::Vector3d vecRotate(Base::Vector3d vec,
double angle,
Base::Vector3d axis,
Base::Vector3d org = Base::Vector3d(0.0, 0.0, 0.0));
static Base::Vector3d closestBasis(Base::Vector3d v);
static gp_Vec closestBasis(gp_Vec inVec);
static Base::Vector3d closestBasis(Base::Vector3d vDir, gp_Ax2 coordSys);
static Base::Vector3d closestBasis(gp_Dir gDir, gp_Ax2 coordSys);
static Base::Vector3d closestBasis(Base::Vector3d v);
static gp_Vec closestBasis(gp_Vec inVec);
static Base::Vector3d closestBasis(Base::Vector3d vDir, gp_Ax2 coordSys);
static Base::Vector3d closestBasis(gp_Dir gDir, gp_Ax2 coordSys);
static double getWidthInDirection(gp_Dir direction, TopoDS_Shape& shape);
static double getWidthInDirection(gp_Dir direction, TopoDS_Shape& shape);
static double getDefaultLineWeight(std::string s);
//! is pt between end1 and end2?
static bool isBetween(const Base::Vector3d pt, const Base::Vector3d end1,
const Base::Vector3d end2);
//! find intersection in 2d for 2 lines in point+direction form
static Base::Vector3d Intersect2d(Base::Vector3d p1, Base::Vector3d d1, Base::Vector3d p2,
Base::Vector3d d2);
static Base::Vector2d Intersect2d(Base::Vector2d p1, Base::Vector2d d1, Base::Vector2d p2,
Base::Vector2d d2);
static double getDefaultLineWeight(std::string s);
//! is pt between end1 and end2?
static bool isBetween(const Base::Vector3d pt, const Base::Vector3d end1, const Base::Vector3d end2);
//! find intersection in 2d for 2 lines in point+direction form
static Base::Vector3d Intersect2d(Base::Vector3d p1, Base::Vector3d d1,
Base::Vector3d p2, Base::Vector3d d2);
static Base::Vector2d Intersect2d(Base::Vector2d p1, Base::Vector2d d1,
Base::Vector2d p2, Base::Vector2d d2);
static Base::Vector3d toVector3d(const gp_Pnt gp)
{
return Base::Vector3d(gp.X(), gp.Y(), gp.Z());
}
static Base::Vector3d toVector3d(const gp_Dir gp)
{
return Base::Vector3d(gp.X(), gp.Y(), gp.Z());
}
static Base::Vector3d toVector3d(const gp_Vec gp)
{
return Base::Vector3d(gp.X(), gp.Y(), gp.Z());
}
static Base::Vector3d toVector3d(const QPointF gp)
{
return Base::Vector3d(gp.x(), gp.y(), 0.0);
}
static Base::Vector3d toVector3d(const gp_Pnt gp) { return Base::Vector3d(gp.X(), gp.Y(), gp.Z()); }
static Base::Vector3d toVector3d(const gp_Dir gp) { return Base::Vector3d(gp.X(), gp.Y(), gp.Z()); }
static Base::Vector3d toVector3d(const gp_Vec gp) { return Base::Vector3d(gp.X(), gp.Y(), gp.Z()); }
static Base::Vector3d toVector3d(const QPointF gp) { 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);
static Base::Vector3d invertY(Base::Vector3d v);
static QPointF invertY(QPointF p);
static std::vector<std::string> split(std::string csvLine);
static std::vector<std::string> tokenize(std::string csvLine,
std::string delimiter = ", $$$, ");
static App::Color pyTupleToColor(PyObject* pColor);
static PyObject* colorToPyTuple(App::Color color);
static bool isCrazy(TopoDS_Edge e);
static Base::Vector3d getFaceCenter(TopoDS_Face f);
static bool circulation(Base::Vector3d A, Base::Vector3d B, Base::Vector3d C);
static int countSubShapes(TopoDS_Shape shape, TopAbs_ShapeEnum subShape);
static void encodeXmlSpecialChars(std::string& inoutText);
static std::list<TopoDS_Edge> sort_Edges(double tol3d, std::list<TopoDS_Edge>& edges);
static std::string shapeToString(TopoDS_Shape s);
static TopoDS_Shape shapeFromString(std::string s);
static Base::Vector3d invertY(Base::Vector3d v);
static QPointF invertY(QPointF p);
static std::vector<std::string> split(std::string csvLine);
static std::vector<std::string> tokenize(std::string csvLine, std::string delimiter = ", $$$, ");
static App::Color pyTupleToColor(PyObject* pColor);
static PyObject* colorToPyTuple(App::Color color);
static bool isCrazy(TopoDS_Edge e);
static Base::Vector3d getFaceCenter(TopoDS_Face f);
static bool circulation(Base::Vector3d A, Base::Vector3d B, Base::Vector3d C);
static int countSubShapes(TopoDS_Shape shape, TopAbs_ShapeEnum subShape);
static void encodeXmlSpecialChars(std::string& inoutText);
static std::list<TopoDS_Edge> sort_Edges(double tol3d, std::list<TopoDS_Edge>& edges);
// Supplementary mathematical functions
static int sgn(double x);
static double sqr(double x);
static void angleNormalize(double& fi);
static double angleComposition(double fi, double delta);
static double angleDifference(double fi1, double fi2, bool reflex = false);
// Supplementary mathematical functions
static int sgn(double x);
static double sqr(double x);
static void angleNormalize(double &fi);
static double angleComposition(double fi, double delta);
static double angleDifference(double fi1, double fi2, bool reflex = false);
// Interval marking functions
static unsigned int intervalMerge(std::vector<std::pair<double, bool>>& marking,
double boundary, bool wraps);
static void intervalMarkLinear(std::vector<std::pair<double, bool>>& marking, double start,
double length, bool value);
static void intervalMarkCircular(std::vector<std::pair<double, bool>>& marking, double start,
double length, bool value);
// Interval marking functions
static unsigned int intervalMerge(std::vector<std::pair<double, bool>> &marking,
double boundary, bool wraps);
static void intervalMarkLinear(std::vector<std::pair<double, bool>> &marking,
double start, double length, bool value);
static void intervalMarkCircular(std::vector<std::pair<double, bool>> &marking,
double start, double length, bool value);
// Supplementary 2D analytic geometry functions
static int findRootForValue(double Ax2, double Bxy, double Cy2, double Dx, double Ey, double F,
double value, bool findX, double roots[]);
static bool mergeBoundedPoint(const Base::Vector2d& point, const Base::BoundBox2d& boundary,
std::vector<Base::Vector2d>& storage);
// Supplementary 2D analytic geometry functions
static int findRootForValue(double Ax2, double Bxy, double Cy2, double Dx, double Ey, double F,
double value, bool findX, double roots[]);
static bool mergeBoundedPoint(const Base::Vector2d &point, const Base::BoundBox2d &boundary,
std::vector<Base::Vector2d> &storage);
static void findConicRectangleIntersections(double conicAx2, double conicBxy, double conicCy2,
double conicDx, double conicEy, double conicF,
const Base::BoundBox2d& rectangle,
std::vector<Base::Vector2d>& intersections);
static void findLineRectangleIntersections(const Base::Vector2d& linePoint, double lineAngle,
const Base::BoundBox2d& rectangle,
std::vector<Base::Vector2d>& intersections);
static void findCircleRectangleIntersections(const Base::Vector2d& circleCenter,
double circleRadius,
const Base::BoundBox2d& rectangle,
std::vector<Base::Vector2d>& intersections);
static void findConicRectangleIntersections(double conicAx2, double conicBxy, double conicCy2,
double conicDx, double conicEy, double conicF,
const Base::BoundBox2d &rectangle,
std::vector<Base::Vector2d> &intersections);
static void findLineRectangleIntersections(const Base::Vector2d &linePoint, double lineAngle,
const Base::BoundBox2d &rectangle,
std::vector<Base::Vector2d> &intersections);
static void findCircleRectangleIntersections(const Base::Vector2d &circleCenter, double circleRadius,
const Base::BoundBox2d &rectangle,
std::vector<Base::Vector2d> &intersections);
static void findLineSegmentRectangleIntersections(const Base::Vector2d &linePoint, double lineAngle,
double segmentBasePosition, double segmentLength,
const Base::BoundBox2d &rectangle,
std::vector<Base::Vector2d> &intersections);
static void findCircularArcRectangleIntersections(const Base::Vector2d &circleCenter, double circleRadius,
double arcBaseAngle, double arcRotation,
const Base::BoundBox2d &rectangle,
std::vector<Base::Vector2d> &intersections);
static void copyFile(std::string inSpec, std::string outSpec);
//debugging routines
static void dumpVertexes(const char* text, const TopoDS_Shape& s);
static void dumpEdge(const char* label, int i, TopoDS_Edge e);
static void dump1Vertex(const char* label, const TopoDS_Vertex& v);
static void countFaces(const char* label, const TopoDS_Shape& s);
static void countWires(const char* label, const TopoDS_Shape& s);
static void countEdges(const char* label, const TopoDS_Shape& s);
static const char* printBool(bool b);
static QString qbaToDebug(const QByteArray& line);
static void dumpCS(const char* text, const gp_Ax2& CS);
static void dumpCS3(const char* text, const gp_Ax3& CS);
static void dumpEdges(const char* text, const TopoDS_Shape& s);
static void findLineSegmentRectangleIntersections(const Base::Vector2d& linePoint,
double lineAngle, double segmentBasePosition,
double segmentLength,
const Base::BoundBox2d& rectangle,
std::vector<Base::Vector2d>& intersections);
static void findCircularArcRectangleIntersections(const Base::Vector2d& circleCenter,
double circleRadius, double arcBaseAngle,
double arcRotation,
const Base::BoundBox2d& rectangle,
std::vector<Base::Vector2d>& intersections);
static void copyFile(std::string inSpec, std::string outSpec);
//debugging routines
static void dumpVertexes(const char* text, const TopoDS_Shape& s);
static void dumpEdge(const char* label, int i, TopoDS_Edge e);
static void dump1Vertex(const char* label, const TopoDS_Vertex& v);
static void countFaces(const char* label, const TopoDS_Shape& s);
static void countWires(const char* label, const TopoDS_Shape& s);
static void countEdges(const char* label, const TopoDS_Shape& s);
static const char* printBool(bool b);
static QString qbaToDebug(const QByteArray& line);
static void dumpCS(const char* text, const gp_Ax2& CS);
static void dumpCS3(const char* text, const gp_Ax3& CS);
static void dumpEdges(const char* text, const TopoDS_Shape& s);
};
} //end namespace TechDraw
}//end namespace TechDraw
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -318,34 +318,30 @@ void DrawViewPart::partExec(TopoDS_Shape& shape)
//prepare the shape for HLR processing by centering, scaling and rotating it
GeometryObjectPtr DrawViewPart::makeGeometryForShape(TopoDS_Shape& shape)
{
// Base::Console().Message("DVP::makeGeometryForShape() - %s\n", getNameInDocument());
gp_Pnt inputCenter = TechDraw::findCentroid(shape,
getProjectionCS());
// Base::Console().Message("DVP::makeGeometryForShape() - %s\n", getNameInDocument());
gp_Pnt inputCenter = TechDraw::findCentroid(shape, getProjectionCS());
m_saveCentroid = DU::toVector3d(inputCenter);
m_saveShape = centerScaleRotate(this, shape, m_saveCentroid);
GeometryObjectPtr go = buildGeometryObject(shape, getProjectionCS());
GeometryObjectPtr go = buildGeometryObject(shape, getProjectionCS());
return go;
}
//Modify a shape by centering, scaling and rotating and return the centered (but not rotated) shape
TopoDS_Shape DrawViewPart::centerScaleRotate(DrawViewPart* dvp,
TopoDS_Shape& inOutShape,
TopoDS_Shape DrawViewPart::centerScaleRotate(DrawViewPart* dvp, TopoDS_Shape& inOutShape,
Base::Vector3d centroid)
{
// Base::Console().Message("DVP::centerScaleRotate() - %s\n", dvp->getNameInDocument());
// Base::Console().Message("DVP::centerScaleRotate() - %s\n", dvp->getNameInDocument());
gp_Ax2 viewAxis = dvp->getProjectionCS();
//center shape on origin
TopoDS_Shape centeredShape = TechDraw::moveShape(inOutShape,
centroid * -1.0);
TopoDS_Shape centeredShape = TechDraw::moveShape(inOutShape, centroid * -1.0);
inOutShape = TechDraw::scaleShape(centeredShape, dvp->getScale());
if (!DrawUtil::fpCompare(dvp->Rotation.getValue(), 0.0)) {
inOutShape = TechDraw::rotateShape(inOutShape,
viewAxis,
dvp->Rotation.getValue()); //conventional rotation
}
// BRepTools::Write(inOutShape, "DVPScaled.brep"); //debug
inOutShape = TechDraw::rotateShape(inOutShape, viewAxis,
dvp->Rotation.getValue());//conventional rotation
}
// BRepTools::Write(inOutShape, "DVPScaled.brep"); //debug
return centeredShape;
}
@@ -798,7 +794,7 @@ TechDraw::VertexPtr DrawViewPart::getVertex(std::string vertexName) const
//! returns existing BaseGeom of 2D Edge
TechDraw::BaseGeomPtr DrawViewPart::getEdge(std::string edgeName) const
{
const std::vector<TechDraw::BaseGeomPtr> &geoms = getEdgeGeometry();
const std::vector<TechDraw::BaseGeomPtr>& geoms = getEdgeGeometry();
if (geoms.empty()) {
//should not happen
throw Base::IndexError("DVP::getEdge - No edges found.");
@@ -813,7 +809,7 @@ TechDraw::BaseGeomPtr DrawViewPart::getEdge(std::string edgeName) const
//! returns existing 2d Face
TechDraw::FacePtr DrawViewPart::getFace(std::string faceName) const
{
const std::vector<TechDraw::FacePtr> &faces = getFaceGeometry();
const std::vector<TechDraw::FacePtr>& faces = getFaceGeometry();
if (faces.empty()) {
//should not happen
throw Base::IndexError("DVP::getFace - No faces found.");
@@ -980,7 +976,7 @@ TopoDS_Shape DrawViewPart::getShape() const
builder.Add(result, geometryObject->getVisSmooth());
}
}
//check for empty compound
//check for empty compound
if (!result.IsNull() && TopoDS_Iterator(result).More()) {
return result;
}
@@ -1141,6 +1137,16 @@ gp_Ax2 DrawViewPart::getProjectionCS(const Base::Vector3d pt) const
return viewAxis;
}
gp_Ax2 DrawViewPart::getRotatedCS(const Base::Vector3d basePoint) const
{
// Base::Console().Message("DVP::getRotatedCS() - %s - %s\n", getNameInDocument(), Label.getValue());
gp_Ax2 unrotated = getProjectionCS(basePoint);
gp_Ax1 rotationAxis(DU::togp_Pnt(basePoint), unrotated.Direction());
double angleRad = Rotation.getValue() * M_PI / 180.0;
gp_Ax2 rotated = unrotated.Rotated(rotationAxis, -angleRad);
return rotated;
}
gp_Ax2 DrawViewPart::getViewAxis(const Base::Vector3d& pt, const Base::Vector3d& direction,
const bool flip) const
{

View File

@@ -114,9 +114,8 @@ public:
const char* getViewProviderName() const override { return "TechDrawGui::ViewProviderViewPart"; }
PyObject* getPyObject() override;
static TopoDS_Shape centerScaleRotate(DrawViewPart* dvp,
TopoDS_Shape& inOutShape,
Base::Vector3d centroid);
static TopoDS_Shape centerScaleRotate(DrawViewPart* dvp, TopoDS_Shape& inOutShape,
Base::Vector3d centroid);
std::vector<TechDraw::DrawHatch*> getHatches() const;
std::vector<TechDraw::DrawGeomHatch*> getGeomHatches() const;
std::vector<TechDraw::DrawViewDimension*> getDimensions() const;
@@ -134,8 +133,10 @@ public:
TechDraw::BaseGeomPtr getEdge(std::string edgeName) const;
TechDraw::FacePtr getFace(std::string faceName) const;
TechDraw::BaseGeomPtr getGeomByIndex(int idx) const; //get existing geom for edge idx in projection
TechDraw::VertexPtr getProjVertexByIndex(int idx) const; //get existing geom for vertex idx in projection
TechDraw::BaseGeomPtr
getGeomByIndex(int idx) const;//get existing geom for edge idx in projection
TechDraw::VertexPtr
getProjVertexByIndex(int idx) const;//get existing geom for vertex idx in projection
TechDraw::VertexPtr getProjVertexByCosTag(std::string cosTag);
std::vector<TechDraw::BaseGeomPtr>
@@ -157,6 +158,7 @@ public:
virtual gp_Ax2 getViewAxis(const Base::Vector3d& pt, const Base::Vector3d& direction,
const bool flip = true) const;
virtual gp_Ax2 getProjectionCS(Base::Vector3d pt = Base::Vector3d(0.0, 0.0, 0.0)) const;
virtual gp_Ax2 getRotatedCS(Base::Vector3d basePoint = Base::Vector3d(0.0, 0.0, 0.0)) const;
virtual Base::Vector3d getXDirection() const;//don't use XDirection.getValue()
virtual Base::Vector3d getOriginalCentroid() const;
virtual Base::Vector3d getCurrentCentroid() const;