[TD]split GeometryObject

This commit is contained in:
wandererfan
2023-08-12 15:10:38 -04:00
committed by WandererFan
parent d23ca906b0
commit 3e164a5700
20 changed files with 577 additions and 470 deletions

View File

@@ -20,6 +20,9 @@
* *
***************************************************************************/
//! a class to the projection of shapes, removal/identifying hidden lines and
//! converting the output for OCC HLR into the BaseGeom intermediate representation.
#include "PreCompiled.h"
#ifndef _PreComp_
@@ -71,17 +74,13 @@
#include "DrawViewPart.h"
#include "GeometryObject.h"
#include "DrawProjectSplit.h"
#include "ShapeUtils.h"
using namespace TechDraw;
using namespace std;
using DU = DrawUtil;
struct EdgePoints {
gp_Pnt v1, v2;
TopoDS_Edge edge;
};
GeometryObject::GeometryObject(const string& parent, TechDraw::DrawView* parentObj)
: m_parentName(parent), m_parent(parentObj), m_isoCount(0), m_isPersp(false), m_focus(100.0),
m_usePolygonHLR(false), m_scrubCount(0)
@@ -178,63 +177,63 @@ void GeometryObject::projectShape(const TopoDS_Shape& inShape, const gp_Ax2& vie
if (!hlrToShape.VCompound().IsNull()) {
visHard = hlrToShape.VCompound();
BRepLib::BuildCurves3d(visHard);
visHard = invertGeometry(visHard);
visHard =ShapeUtils::invertGeometry(visHard);
// BRepTools::Write(visHard, "GOvisHard.brep"); //debug
}
if (!hlrToShape.Rg1LineVCompound().IsNull()) {
visSmooth = hlrToShape.Rg1LineVCompound();
BRepLib::BuildCurves3d(visSmooth);
visSmooth = invertGeometry(visSmooth);
visSmooth =ShapeUtils::invertGeometry(visSmooth);
}
if (!hlrToShape.RgNLineVCompound().IsNull()) {
visSeam = hlrToShape.RgNLineVCompound();
BRepLib::BuildCurves3d(visSeam);
visSeam = invertGeometry(visSeam);
visSeam =ShapeUtils::invertGeometry(visSeam);
}
if (!hlrToShape.OutLineVCompound().IsNull()) {
// BRepTools::Write(hlrToShape.OutLineVCompound(), "GOOutLineVCompound.brep"); //debug
visOutline = hlrToShape.OutLineVCompound();
BRepLib::BuildCurves3d(visOutline);
visOutline = invertGeometry(visOutline);
visOutline =ShapeUtils::invertGeometry(visOutline);
}
if (!hlrToShape.IsoLineVCompound().IsNull()) {
visIso = hlrToShape.IsoLineVCompound();
BRepLib::BuildCurves3d(visIso);
visIso = invertGeometry(visIso);
visIso =ShapeUtils::invertGeometry(visIso);
}
if (!hlrToShape.HCompound().IsNull()) {
hidHard = hlrToShape.HCompound();
BRepLib::BuildCurves3d(hidHard);
hidHard = invertGeometry(hidHard);
hidHard =ShapeUtils::invertGeometry(hidHard);
}
if (!hlrToShape.Rg1LineHCompound().IsNull()) {
hidSmooth = hlrToShape.Rg1LineHCompound();
BRepLib::BuildCurves3d(hidSmooth);
hidSmooth = invertGeometry(hidSmooth);
hidSmooth =ShapeUtils::invertGeometry(hidSmooth);
}
if (!hlrToShape.RgNLineHCompound().IsNull()) {
hidSeam = hlrToShape.RgNLineHCompound();
BRepLib::BuildCurves3d(hidSeam);
hidSeam = invertGeometry(hidSeam);
hidSeam =ShapeUtils::invertGeometry(hidSeam);
}
if (!hlrToShape.OutLineHCompound().IsNull()) {
hidOutline = hlrToShape.OutLineHCompound();
BRepLib::BuildCurves3d(hidOutline);
hidOutline = invertGeometry(hidOutline);
hidOutline =ShapeUtils::invertGeometry(hidOutline);
}
if (!hlrToShape.IsoLineHCompound().IsNull()) {
hidIso = hlrToShape.IsoLineHCompound();
BRepLib::BuildCurves3d(hidIso);
hidIso = invertGeometry(hidIso);
hidIso =ShapeUtils::invertGeometry(hidIso);
}
}
catch (const Standard_Failure&) {
@@ -288,7 +287,7 @@ void GeometryObject::makeTDGeometry()
}
//mirror a shape thru XZ plane for Qt's inverted Y coordinate
TopoDS_Shape GeometryObject::invertGeometry(const TopoDS_Shape s)
TopoDS_Shape ShapeUtils::invertGeometry(const TopoDS_Shape s)
{
if (s.IsNull()) {
return s;
@@ -314,9 +313,9 @@ void GeometryObject::projectShapeWithPolygonAlgo(const TopoDS_Shape& input, cons
//to be reverted.
TopoDS_Shape inCopy;
if (!m_isPersp) {
gp_Pnt gCenter = findCentroid(input, viewAxis);
gp_Pnt gCenter = ShapeUtils::findCentroid(input, viewAxis);
Base::Vector3d motion(-gCenter.X(), -gCenter.Y(), -gCenter.Z());
inCopy = moveShape(input, motion);
inCopy = ShapeUtils::moveShape(input, motion);
}
else {
BRepBuilderAPI_Copy BuilderCopy(input);
@@ -363,37 +362,37 @@ void GeometryObject::projectShapeWithPolygonAlgo(const TopoDS_Shape& input, cons
visHard = polyhlrToShape.VCompound();
BRepLib::BuildCurves3d(visHard);
visHard = invertGeometry(visHard);
visHard =ShapeUtils::invertGeometry(visHard);
// BRepTools::Write(visHard, "GOvisHardi.brep"); //debug
visSmooth = polyhlrToShape.Rg1LineVCompound();
BRepLib::BuildCurves3d(visSmooth);
visSmooth = invertGeometry(visSmooth);
visSmooth =ShapeUtils::invertGeometry(visSmooth);
visSeam = polyhlrToShape.RgNLineVCompound();
BRepLib::BuildCurves3d(visSeam);
visSeam = invertGeometry(visSeam);
visSeam =ShapeUtils::invertGeometry(visSeam);
visOutline = polyhlrToShape.OutLineVCompound();
BRepLib::BuildCurves3d(visOutline);
visOutline = invertGeometry(visOutline);
visOutline =ShapeUtils::invertGeometry(visOutline);
hidHard = polyhlrToShape.HCompound();
BRepLib::BuildCurves3d(hidHard);
hidHard = invertGeometry(hidHard);
hidHard =ShapeUtils::invertGeometry(hidHard);
// BRepTools::Write(hidHard, "GOhidHardi.brep"); //debug
hidSmooth = polyhlrToShape.Rg1LineHCompound();
BRepLib::BuildCurves3d(hidSmooth);
hidSmooth = invertGeometry(hidSmooth);
hidSmooth =ShapeUtils::invertGeometry(hidSmooth);
hidSeam = polyhlrToShape.RgNLineHCompound();
BRepLib::BuildCurves3d(hidSeam);
hidSeam = invertGeometry(hidSeam);
hidSeam =ShapeUtils::invertGeometry(hidSeam);
hidOutline = polyhlrToShape.OutLineHCompound();
BRepLib::BuildCurves3d(hidOutline);
hidOutline = invertGeometry(hidOutline);
hidOutline =ShapeUtils::invertGeometry(hidOutline);
}
catch (const Standard_Failure& e) {
Base::Console().Error(
@@ -431,7 +430,7 @@ TopoDS_Shape GeometryObject::projectSimpleShape(const TopoDS_Shape& shape, const
HLRBRep_HLRToShape hlrToShape(brep_hlr);
TopoDS_Shape hardEdges = hlrToShape.VCompound();
BRepLib::BuildCurves3d(hardEdges);
hardEdges = invertGeometry(hardEdges);
hardEdges =ShapeUtils::invertGeometry(hardEdges);
return hardEdges;
}
@@ -465,7 +464,7 @@ TopoDS_Shape GeometryObject::projectFace(const TopoDS_Shape& face, const gp_Ax2&
HLRBRep_HLRToShape hlrToShape(brep_hlr);
TopoDS_Shape hardEdges = hlrToShape.VCompound();
BRepLib::BuildCurves3d(hardEdges);
hardEdges = invertGeometry(hardEdges);
hardEdges =ShapeUtils::invertGeometry(hardEdges);
return hardEdges;
}
@@ -869,326 +868,3 @@ bool GeometryObject::findVertex(Base::Vector3d v)
return false;
}
/// utility non-class member functions
//! gets a coordinate system that matches view system used in 3D with +Z up (or +Y up if necessary)
//! used for individual views, but not secondary views in projection groups
//! flip determines Y mirror or not.
// getViewAxis 1
gp_Ax2 TechDraw::getViewAxis(const Base::Vector3d origin, const Base::Vector3d& direction,
const bool flip)
{
// Base::Console().Message("GO::getViewAxis() - 1 - use only with getLegacyX\n");
(void)flip;
gp_Ax2 viewAxis;
gp_Pnt inputCenter(origin.x, origin.y, origin.z);
Base::Vector3d stdZ(0.0, 0.0, 1.0);
Base::Vector3d stdOrg(0.0, 0.0, 0.0);
Base::Vector3d cross = direction;
if (DU::checkParallel(direction, stdZ)) {
cross = Base::Vector3d(1.0, 0.0, 0.0);
}
else {
cross.Normalize();
cross = cross.Cross(stdZ);
}
if (cross.IsEqual(stdOrg, FLT_EPSILON)) {
viewAxis = gp_Ax2(inputCenter, gp_Dir(direction.x, direction.y, direction.z));
return viewAxis;
}
viewAxis = gp_Ax2(inputCenter, gp_Dir(direction.x, direction.y, direction.z),
gp_Dir(cross.x, cross.y, cross.z));
return viewAxis;
}
//! gets a coordinate system specified by Z and X directions
//getViewAxis 2
gp_Ax2 TechDraw::getViewAxis(const Base::Vector3d origin, const Base::Vector3d& direction,
const Base::Vector3d& xAxis, const bool flip)
{
// Base::Console().Message("GO::getViewAxis() - 2\n");
(void)flip;
gp_Pnt inputCenter(origin.x, origin.y, origin.z);
return gp_Ax2(inputCenter,
gp_Dir(direction.x, direction.y, direction.z),
gp_Dir(xAxis.x, xAxis.y, xAxis.z));
}
// was getViewAxis 1
// getViewAxis as used before XDirection property adopted
gp_Ax2 TechDraw::legacyViewAxis1(const Base::Vector3d origin, const Base::Vector3d& direction,
const bool flip)
{
// Base::Console().Message("GO::legacyViewAxis1()\n");
gp_Pnt inputCenter(origin.x, origin.y, origin.z);
Base::Vector3d stdZ(0.0, 0.0, 1.0);
Base::Vector3d stdOrg(0.0, 0.0, 0.0);
Base::Vector3d flipDirection(direction.x, -direction.y, direction.z);
if (!flip) {
flipDirection = Base::Vector3d(direction.x, direction.y, direction.z);
}
Base::Vector3d cross = flipDirection;
// //special case
if (DU::checkParallel(flipDirection, stdZ)) {
cross = Base::Vector3d(1.0, 0.0, 0.0);
}
else {
cross.Normalize();
cross = cross.Cross(stdZ);
}
if (cross.IsEqual(stdOrg, FLT_EPSILON)) {
return gp_Ax2(inputCenter, gp_Dir(flipDirection.x, flipDirection.y, flipDirection.z));
}
gp_Ax2 viewAxis = gp_Ax2(inputCenter,
gp_Dir(flipDirection.x, flipDirection.y, flipDirection.z),
gp_Dir(cross.x, cross.y, cross.z));
//this bit is to handle the old mirror Y logic, but it messes up
//some old files.
gp_Trsf mirrorXForm;
gp_Ax2 mirrorCS(inputCenter, gp_Dir(0, -1, 0));
mirrorXForm.SetMirror(mirrorCS);
viewAxis = viewAxis.Transformed(mirrorXForm);
return viewAxis;
}
//! Returns the centroid of shape based on R3
gp_Pnt TechDraw::findCentroid(const TopoDS_Shape& shape)
{
Bnd_Box tBounds;
tBounds.SetGap(0.0);
BRepBndLib::AddOptimal(shape, tBounds, true, false);
Standard_Real xMin, yMin, zMin, xMax, yMax, zMax;
tBounds.Get(xMin, yMin, zMin, xMax, yMax, zMax);
Standard_Real x = (xMin + xMax) / 2.0, y = (yMin + yMax) / 2.0, z = (zMin + zMax) / 2.0;
return gp_Pnt(x, y, z);
}
//! Returns the centroid of shape, as viewed according to direction
gp_Pnt TechDraw::findCentroid(const TopoDS_Shape& shape, const Base::Vector3d& direction)
{
// Base::Console().Message("GO::findCentroid() - 1\n");
Base::Vector3d origin(0.0, 0.0, 0.0);
gp_Ax2 viewAxis = getViewAxis(origin, direction);
return findCentroid(shape, viewAxis);
}
//! Returns the centroid of shape, as viewed according to direction
gp_Pnt TechDraw::findCentroid(const TopoDS_Shape& shape, const gp_Ax2& viewAxis)
{
// Base::Console().Message("GO::findCentroid() - 2\n");
gp_Trsf tempTransform;
tempTransform.SetTransformation(viewAxis);
BRepBuilderAPI_Transform builder(shape, tempTransform);
Bnd_Box tBounds;
tBounds.SetGap(0.0);
BRepBndLib::AddOptimal(builder.Shape(), tBounds, true, false);
Standard_Real xMin, yMin, zMin, xMax, yMax, zMax;
tBounds.Get(xMin, yMin, zMin, xMax, yMax, zMax);
Standard_Real x = (xMin + xMax) / 2.0, y = (yMin + yMax) / 2.0, z = (zMin + zMax) / 2.0;
// Get centroid back into object space
tempTransform.Inverted().Transforms(x, y, z);
return gp_Pnt(x, y, z);
}
Base::Vector3d TechDraw::findCentroidVec(const TopoDS_Shape& shape, const Base::Vector3d& direction)
{
// Base::Console().Message("GO::findCentroidVec() - 1\n");
gp_Pnt p = TechDraw::findCentroid(shape, direction);
return Base::Vector3d(p.X(), p.Y(), p.Z());
}
Base::Vector3d TechDraw::findCentroidVec(const TopoDS_Shape& shape, const gp_Ax2& cs)
{
// Base::Console().Message("GO::findCentroidVec() - 2\n");
gp_Pnt p = TechDraw::findCentroid(shape, cs);
return Base::Vector3d(p.X(), p.Y(), p.Z());
}
//! Returns the XY plane center of shape with respect to coordSys
gp_Pnt TechDraw::findCentroidXY(const TopoDS_Shape& shape, const gp_Ax2& coordSys)
{
// Base::Console().Message("GO::findCentroid() - 2\n");
gp_Trsf tempTransform;
tempTransform.SetTransformation(coordSys);
BRepBuilderAPI_Transform builder(shape, tempTransform);
Bnd_Box tBounds;
tBounds.SetGap(0.0);
BRepBndLib::AddOptimal(builder.Shape(), tBounds, true, false);
Standard_Real xMin, yMin, zMin, xMax, yMax, zMax;
tBounds.Get(xMin, yMin, zMin, xMax, yMax, zMax);
Standard_Real x = (xMin + xMax) / 2.0, y = (yMin + yMax) / 2.0, z = 0.0;
// Get "centroid" back into object space
tempTransform.Inverted().Transforms(x, y, z);
return gp_Pnt(x, y, z);
}
//!scales & mirrors a shape about a center
TopoDS_Shape TechDraw::mirrorShapeVec(const TopoDS_Shape& input, const Base::Vector3d& inputCenter,
double scale)
{
gp_Pnt gInput(inputCenter.x, inputCenter.y, inputCenter.z);
return TechDraw::mirrorShape(input, gInput, scale);
}
TopoDS_Shape TechDraw::mirrorShape(const TopoDS_Shape& input, const gp_Pnt& inputCenter,
double scale)
{
TopoDS_Shape transShape;
if (input.IsNull()) {
return transShape;
}
try {
// Make tempTransform scale the object around it's centre point and
// mirror about the Y axis
gp_Trsf tempTransform;
//BRepBuilderAPI_Transform will loop forever if asked to use 0.0 as scale
if (scale <= 0.0) {
tempTransform.SetScale(inputCenter, 1.0);
}
else {
tempTransform.SetScale(inputCenter, scale);
}
gp_Trsf mirrorTransform;
mirrorTransform.SetMirror(gp_Ax2(inputCenter, gp_Dir(0, -1, 0)));
tempTransform.Multiply(mirrorTransform);
// Apply that transform to the shape. This should preserve the centre.
BRepBuilderAPI_Transform mkTrf(input, tempTransform);
transShape = mkTrf.Shape();
}
catch (...) {
return transShape;
}
return transShape;
}
//!rotates a shape about a viewAxis
TopoDS_Shape TechDraw::rotateShape(const TopoDS_Shape& input, const gp_Ax2& viewAxis,
double rotAngle)
{
TopoDS_Shape transShape;
if (input.IsNull()) {
return transShape;
}
gp_Ax1 rotAxis = viewAxis.Axis();
double rotation = rotAngle * M_PI / 180.0;
try {
gp_Trsf tempTransform;
tempTransform.SetRotation(rotAxis, rotation);
BRepBuilderAPI_Transform mkTrf(input, tempTransform);
transShape = mkTrf.Shape();
}
catch (...) {
return transShape;
}
return transShape;
}
//!scales a shape about origin
TopoDS_Shape TechDraw::scaleShape(const TopoDS_Shape& input, double scale)
{
TopoDS_Shape transShape;
try {
gp_Trsf scaleTransform;
scaleTransform.SetScale(gp_Pnt(0, 0, 0), scale);
BRepBuilderAPI_Transform mkTrf(input, scaleTransform);
transShape = mkTrf.Shape();
}
catch (...) {
return transShape;
}
return transShape;
}
//!moves a shape
TopoDS_Shape TechDraw::moveShape(const TopoDS_Shape& input, const Base::Vector3d& motion)
{
TopoDS_Shape transShape;
try {
gp_Trsf xlate;
xlate.SetTranslation(gp_Vec(motion.x, motion.y, motion.z));
BRepBuilderAPI_Transform mkTrf(input, xlate);
transShape = mkTrf.Shape();
}
catch (...) {
return transShape;
}
return transShape;
}
//!moves a shape with restricts on directions
TopoDS_Shape TechDraw::moveShapeRestricted(const TopoDS_Shape& input, const Base::Vector3d& motion,
bool allowX, bool allowY, bool allowZ)
{
gp_Vec gMotion(allowX ? motion.x : 0.0, allowY ? motion.y : 0.0, allowZ ? motion.z : 0.0);
TopoDS_Shape transShape;
try {
gp_Trsf xlate;
xlate.SetTranslation(gMotion);
BRepBuilderAPI_Transform mkTrf(input, xlate);
transShape = mkTrf.Shape();
}
catch (...) {
return transShape;
}
return transShape;
}
//!moves a shape with restricts on directions
TopoDS_Shape TechDraw::moveShapeRestricted(const TopoDS_Shape& input, const Base::Vector3d& motion,
const Base::Vector3d& mask)
{
gp_Vec gMotion(mask.x ? motion.x : 0.0, mask.y ? motion.y : 0.0, mask.z ? motion.z : 0.0);
TopoDS_Shape transShape;
try {
gp_Trsf xlate;
xlate.SetTranslation(gMotion);
BRepBuilderAPI_Transform mkTrf(input, xlate);
transShape = mkTrf.Shape();
}
catch (...) {
return transShape;
}
return transShape;
}
TopoDS_Shape TechDraw::moveShapeRestricted(const TopoDS_Shape& input, const gp_Vec& motion,
const gp_Vec& mask)
{
return moveShapeRestricted(input, DU::toVector3d(motion), DU::toVector3d(mask));
}
TopoDS_Shape TechDraw::centerShapeXY(const TopoDS_Shape& inShape, const gp_Ax2& coordSys)
{
gp_Pnt inputCenter = findCentroidXY(inShape, coordSys);
Base::Vector3d centroid = DrawUtil::toVector3d(inputCenter);
return TechDraw::moveShape(inShape, centroid * -1.0);
}