[TD]split GeometryObject
This commit is contained in:
@@ -413,30 +413,30 @@ private:
|
||||
obj = static_cast<App::DocumentObjectPy*>(viewObj)->getDocumentObjectPtr();
|
||||
dvp = static_cast<TechDraw::DrawViewPart*>(obj);
|
||||
TechDraw::GeometryObjectPtr gObj = dvp->getGeometryObject();
|
||||
TopoDS_Shape shape = TechDraw::mirrorShape(gObj->getVisHard());
|
||||
TopoDS_Shape shape = ShapeUtils::mirrorShape(gObj->getVisHard());
|
||||
ss << dxfOut.exportEdges(shape);
|
||||
shape = TechDraw::mirrorShape(gObj->getVisOutline());
|
||||
shape = ShapeUtils::mirrorShape(gObj->getVisOutline());
|
||||
ss << dxfOut.exportEdges(shape);
|
||||
if (dvp->SmoothVisible.getValue()) {
|
||||
shape = TechDraw::mirrorShape(gObj->getVisSmooth());
|
||||
shape = ShapeUtils::mirrorShape(gObj->getVisSmooth());
|
||||
ss << dxfOut.exportEdges(shape);
|
||||
}
|
||||
if (dvp->SeamVisible.getValue()) {
|
||||
shape = TechDraw::mirrorShape(gObj->getVisSeam());
|
||||
shape = ShapeUtils::mirrorShape(gObj->getVisSeam());
|
||||
ss << dxfOut.exportEdges(shape);
|
||||
}
|
||||
if (dvp->HardHidden.getValue()) {
|
||||
shape = TechDraw::mirrorShape(gObj->getHidHard());
|
||||
shape = ShapeUtils::mirrorShape(gObj->getHidHard());
|
||||
ss << dxfOut.exportEdges(shape);
|
||||
shape = TechDraw::mirrorShape(gObj->getHidOutline());
|
||||
shape = ShapeUtils::mirrorShape(gObj->getHidOutline());
|
||||
ss << dxfOut.exportEdges(shape);
|
||||
}
|
||||
if (dvp->SmoothHidden.getValue()) {
|
||||
shape = TechDraw::mirrorShape(gObj->getHidSmooth());
|
||||
shape = ShapeUtils::mirrorShape(gObj->getHidSmooth());
|
||||
ss << dxfOut.exportEdges(shape);
|
||||
}
|
||||
if (dvp->SeamHidden.getValue()) {
|
||||
shape = TechDraw::mirrorShape(gObj->getHidSeam());
|
||||
shape = ShapeUtils::mirrorShape(gObj->getHidSeam());
|
||||
ss << dxfOut.exportEdges(shape);
|
||||
}
|
||||
// ss now contains all edges as Dxf
|
||||
@@ -535,7 +535,7 @@ private:
|
||||
if(!dvp->hasGeometry())
|
||||
return;
|
||||
TechDraw::GeometryObjectPtr gObj = dvp->getGeometryObject();
|
||||
TopoDS_Shape shape = TechDraw::mirrorShape(gObj->getVisHard());
|
||||
TopoDS_Shape shape = ShapeUtils::mirrorShape(gObj->getVisHard());
|
||||
double offX = 0.0;
|
||||
double offY = 0.0;
|
||||
if (dvp->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) {
|
||||
@@ -557,40 +557,40 @@ private:
|
||||
BRepBuilderAPI_Transform mkTrf(shape, xLate);
|
||||
shape = mkTrf.Shape();
|
||||
writer.exportShape(shape);
|
||||
shape = TechDraw::mirrorShape(gObj->getVisOutline());
|
||||
shape = ShapeUtils::mirrorShape(gObj->getVisOutline());
|
||||
mkTrf.Perform(shape);
|
||||
shape = mkTrf.Shape();
|
||||
writer.exportShape(shape);
|
||||
if (dvp->SmoothVisible.getValue()) {
|
||||
shape = TechDraw::mirrorShape(gObj->getVisSmooth());
|
||||
shape = ShapeUtils::mirrorShape(gObj->getVisSmooth());
|
||||
mkTrf.Perform(shape);
|
||||
shape = mkTrf.Shape();
|
||||
writer.exportShape(shape);
|
||||
}
|
||||
if (dvp->SeamVisible.getValue()) {
|
||||
shape = TechDraw::mirrorShape(gObj->getVisSeam());
|
||||
shape = ShapeUtils::mirrorShape(gObj->getVisSeam());
|
||||
mkTrf.Perform(shape);
|
||||
shape = mkTrf.Shape();
|
||||
writer.exportShape(shape);
|
||||
}
|
||||
if (dvp->HardHidden.getValue()) {
|
||||
shape = TechDraw::mirrorShape(gObj->getHidHard());
|
||||
shape = ShapeUtils::mirrorShape(gObj->getHidHard());
|
||||
mkTrf.Perform(shape);
|
||||
shape = mkTrf.Shape();
|
||||
writer.exportShape(shape);
|
||||
shape = TechDraw::mirrorShape(gObj->getHidOutline());
|
||||
shape = ShapeUtils::mirrorShape(gObj->getHidOutline());
|
||||
mkTrf.Perform(shape);
|
||||
shape = mkTrf.Shape();
|
||||
writer.exportShape(shape);
|
||||
}
|
||||
if (dvp->SmoothHidden.getValue()) {
|
||||
shape = TechDraw::mirrorShape(gObj->getHidSmooth());
|
||||
shape = ShapeUtils::mirrorShape(gObj->getHidSmooth());
|
||||
mkTrf.Perform(shape);
|
||||
shape = mkTrf.Shape();
|
||||
writer.exportShape(shape);
|
||||
}
|
||||
if (dvp->SeamHidden.getValue()) {
|
||||
shape = TechDraw::mirrorShape(gObj->getHidSeam());
|
||||
shape = ShapeUtils::mirrorShape(gObj->getHidSeam());
|
||||
mkTrf.Perform(shape);
|
||||
shape = mkTrf.Shape();
|
||||
writer.exportShape(shape);
|
||||
@@ -604,7 +604,7 @@ private:
|
||||
}
|
||||
}
|
||||
if (!cosmeticEdges.empty()) {
|
||||
shape = TechDraw::mirrorShape(DrawUtil::vectorToCompound(cosmeticEdges));
|
||||
shape = ShapeUtils::mirrorShape(DrawUtil::vectorToCompound(cosmeticEdges));
|
||||
mkTrf.Perform(shape);
|
||||
shape = mkTrf.Shape();
|
||||
writer.exportShape(shape);
|
||||
@@ -813,13 +813,13 @@ private:
|
||||
|
||||
TopoShapePy* pShape = static_cast<TopoShapePy*>(pcObjShape);
|
||||
if (!pShape) {
|
||||
Base::Console().Error("TechDraw::findCentroid - input shape is null\n");
|
||||
Base::Console().Error("ShapeUtils::findCentroid - input shape is null\n");
|
||||
return Py::None();
|
||||
}
|
||||
|
||||
const TopoDS_Shape& shape = pShape->getTopoShapePtr()->getShape();
|
||||
Base::Vector3d dir = static_cast<Base::VectorPy*>(pcObjDir)->value();
|
||||
Base::Vector3d centroid = TechDraw::findCentroidVec(shape, dir);
|
||||
Base::Vector3d centroid = ShapeUtils::findCentroidVec(shape, dir);
|
||||
PyObject* result = nullptr;
|
||||
result = new Base::VectorPy(new Base::Vector3d(centroid));
|
||||
return Py::asObject(result);
|
||||
|
||||
@@ -182,6 +182,8 @@ SET(Geometry_SRCS
|
||||
Geometry.h
|
||||
GeometryObject.cpp
|
||||
GeometryObject.h
|
||||
ShapeUtils.cpp
|
||||
ShapeUtils.h
|
||||
CenterLine.cpp
|
||||
CenterLine.h
|
||||
Cosmetic.cpp
|
||||
|
||||
@@ -259,7 +259,7 @@ TechDraw::BaseGeomPtr CenterLine::scaledGeometry(TechDraw::DrawViewPart* partFea
|
||||
gp_Pnt gp1(p1.x, p1.y, p1.z);
|
||||
gp_Pnt gp2(p2.x, p2.y, p2.z);
|
||||
TopoDS_Edge e = BRepBuilderAPI_MakeEdge(gp1, gp2);
|
||||
TopoDS_Shape s = TechDraw::scaleShape(e, scale);
|
||||
TopoDS_Shape s = ShapeUtils::scaleShape(e, scale);
|
||||
TopoDS_Edge newEdge = TopoDS::Edge(s);
|
||||
TechDraw::BaseGeomPtr newGeom = TechDraw::BaseGeom::baseFactory(newEdge);
|
||||
newGeom->setClassOfEdge(ecHARD);
|
||||
|
||||
@@ -182,7 +182,7 @@ TopoDS_Edge CosmeticEdge::TopoDS_EdgeFromVectors(Base::Vector3d pt1, Base::Vecto
|
||||
TechDraw::BaseGeomPtr CosmeticEdge::scaledGeometry(double scale)
|
||||
{
|
||||
TopoDS_Edge e = m_geometry->getOCCEdge();
|
||||
TopoDS_Shape s = TechDraw::scaleShape(e, scale);
|
||||
TopoDS_Shape s = ShapeUtils::scaleShape(e, scale);
|
||||
TopoDS_Edge newEdge = TopoDS::Edge(s);
|
||||
TechDraw::BaseGeomPtr newGeom = TechDraw::BaseGeom::baseFactory(newEdge);
|
||||
newGeom->setClassOfEdge(ecHARD);
|
||||
|
||||
@@ -138,7 +138,7 @@ Part::TopoShape ReferenceEntry::asTopoShapeEdge(TopoDS_Edge &edge) const
|
||||
if (!is3d()) {
|
||||
// 2d reference - projected and scaled. scale might have changed, so we need to unscale
|
||||
auto dvp = static_cast<TechDraw::DrawViewPart*>(getObject());
|
||||
TopoDS_Shape unscaledShape = TechDraw::scaleShape(edge, 1.0 / dvp->getScale());
|
||||
TopoDS_Shape unscaledShape = ShapeUtils::scaleShape(edge, 1.0 / dvp->getScale());
|
||||
unscaledEdge = TopoDS::Edge(unscaledShape);
|
||||
}
|
||||
return { unscaledEdge };
|
||||
|
||||
@@ -121,6 +121,7 @@
|
||||
#include "DrawComplexSection.h"
|
||||
#include "DrawUtil.h"
|
||||
#include "GeometryObject.h"
|
||||
#include "ShapeUtils.h"
|
||||
|
||||
using namespace TechDraw;
|
||||
using namespace std;
|
||||
@@ -256,12 +257,11 @@ TopoDS_Shape DrawComplexSection::prepareShape(const TopoDS_Shape& cutShape, doub
|
||||
return TopoDS_Shape();
|
||||
}
|
||||
|
||||
TopoDS_Shape centeredShape = TechDraw::centerShapeXY(m_alignResult, getProjectionCS());
|
||||
// m_preparedShape = scaleShape(m_alignResult, getScale());
|
||||
m_preparedShape = scaleShape(centeredShape, getScale());
|
||||
TopoDS_Shape centeredShape = ShapeUtils::centerShapeXY(m_alignResult, getProjectionCS());
|
||||
m_preparedShape = ShapeUtils::scaleShape(centeredShape, getScale());
|
||||
if (!DrawUtil::fpCompare(Rotation.getValue(), 0.0)) {
|
||||
m_preparedShape =
|
||||
TechDraw::rotateShape(m_preparedShape, getProjectionCS(), Rotation.getValue());
|
||||
ShapeUtils::rotateShape(m_preparedShape, getProjectionCS(), Rotation.getValue());
|
||||
}
|
||||
|
||||
return m_preparedShape;
|
||||
@@ -394,7 +394,7 @@ void DrawComplexSection::makeAlignedPieces(const TopoDS_Shape& rawShape)
|
||||
|
||||
//move intersection shape to the origin
|
||||
gp_Trsf xPieceCenter;
|
||||
xPieceCenter.SetTranslation(gp_Vec(findCentroid(intersect).XYZ()) * -1.0);
|
||||
xPieceCenter.SetTranslation(gp_Vec(ShapeUtils::findCentroid(intersect).XYZ()) * -1.0);
|
||||
BRepBuilderAPI_Transform mkTransXLate(intersect, xPieceCenter, true);
|
||||
TopoDS_Shape pieceCentered = mkTransXLate.Shape();
|
||||
|
||||
@@ -436,7 +436,7 @@ void DrawComplexSection::makeAlignedPieces(const TopoDS_Shape& rawShape)
|
||||
//with the paper plane
|
||||
//yVector is movement of cut face to paperPlane (XZ)
|
||||
gp_Vec yVector(gp::OY().Direction().XYZ() * pieceYSize / 2.0);//move "back"
|
||||
gp_Vec netDisplacement = -1.0 * gp_Vec(findCentroid(pieceAligned).XYZ()) + yVector;
|
||||
gp_Vec netDisplacement = -1.0 * gp_Vec(ShapeUtils::findCentroid(pieceAligned).XYZ()) + yVector;
|
||||
//if we are going to space along X, we need to bring the pieces back into alignment
|
||||
//with the XY plane. If we are stacking the pieces along Z, we don't want a vertical adjustment.
|
||||
gp_Vec xyDisplacement =
|
||||
@@ -498,7 +498,7 @@ void DrawComplexSection::makeAlignedPieces(const TopoDS_Shape& rawShape)
|
||||
|
||||
//center the compound along SectionCS XDirection
|
||||
Base::Vector3d centerVector = DU::toVector3d(gMovementVector) * distanceToMove / -2.0;
|
||||
TopoDS_Shape centeredCompound = moveShape(comp, centerVector);
|
||||
TopoDS_Shape centeredCompound = ShapeUtils::moveShape(comp, centerVector);
|
||||
if (debugSection()) {
|
||||
BRepTools::Write(centeredCompound, "DCSmap40CenteredCompound.brep");//debug
|
||||
}
|
||||
@@ -796,8 +796,8 @@ TopoDS_Wire DrawComplexSection::makeSectionLineWire()
|
||||
if (baseDvp) {
|
||||
Base::Vector3d centroid = baseDvp->getCurrentCentroid();
|
||||
TopoDS_Shape sTrans =
|
||||
TechDraw::moveShape(Part::Feature::getShape(toolObj), centroid * -1.0);
|
||||
TopoDS_Shape sScaled = TechDraw::scaleShape(sTrans, baseDvp->getScale());
|
||||
ShapeUtils::ShapeUtils::moveShape(Part::Feature::getShape(toolObj), centroid * -1.0);
|
||||
TopoDS_Shape sScaled = ShapeUtils::scaleShape(sTrans, baseDvp->getScale());
|
||||
//we don't mirror the scaled shape here as it will be mirrored by the projection
|
||||
|
||||
if (sScaled.ShapeType() == TopAbs_WIRE) {
|
||||
|
||||
@@ -267,9 +267,9 @@ std::vector<LineSet> DrawGeomHatch::getTrimmedLinesSection(DrawViewSection* sou
|
||||
|
||||
//f may be above or below paper plane and must be moved so Common operation in
|
||||
//getTrimmedLines succeeds
|
||||
TopoDS_Shape moved = TechDraw::moveShape(f,
|
||||
TopoDS_Shape moved = ShapeUtils::moveShape(f,
|
||||
offset);
|
||||
TopoDS_Face fMoved = TopoDS::Face(GeometryObject::invertGeometry(moved));
|
||||
TopoDS_Face fMoved = TopoDS::Face(ShapeUtils::invertGeometry(moved));
|
||||
return getTrimmedLines(
|
||||
source,
|
||||
lineSets,
|
||||
|
||||
@@ -227,7 +227,7 @@ gp_Ax2 DrawProjGroupItem::getViewAxis(const Base::Vector3d& pt,
|
||||
catch (Standard_Failure& e4) {
|
||||
Base::Console().Message("PROBLEM - DPGI (%s) failed to create viewAxis: %s **\n",
|
||||
getNameInDocument(), e4.GetMessageString());
|
||||
return TechDraw::getViewAxis(pt, axis, false);
|
||||
return ShapeUtils::getViewAxis(pt, axis, false);
|
||||
}
|
||||
|
||||
return viewAxis;
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
#include "DrawUtil.h"
|
||||
#include "Geometry.h"
|
||||
#include "GeometryObject.h"
|
||||
#include "ShapeUtils.h"
|
||||
|
||||
|
||||
using namespace TechDraw;
|
||||
@@ -82,9 +83,9 @@ std::vector<TopoDS_Edge> DrawProjectSplit::getEdgesForWalker(TopoDS_Shape shape,
|
||||
|
||||
gp_Pnt inputCenter(0, 0, 0);
|
||||
TopoDS_Shape scaledShape;
|
||||
scaledShape = TechDraw::scaleShape(copyShape,
|
||||
scaledShape = ShapeUtils::scaleShape(copyShape,
|
||||
scale);
|
||||
gp_Ax2 viewAxis = TechDraw::legacyViewAxis1(Base::Vector3d(0.0, 0.0, 0.0), direction, false);
|
||||
gp_Ax2 viewAxis = ShapeUtils::legacyViewAxis1(Base::Vector3d(0.0, 0.0, 0.0), direction, false);
|
||||
TechDraw::GeometryObjectPtr go = buildGeometryObject(scaledShape, viewAxis);
|
||||
const std::vector<TechDraw::BaseGeomPtr>& goEdges = go->getVisibleFaceEdges(false, false);
|
||||
for (auto& e: goEdges){
|
||||
|
||||
@@ -546,7 +546,7 @@ TopoDS_Shape DrawUtil::vectorToCompound(std::vector<TopoDS_Edge> vecIn, bool inv
|
||||
builder.Add(compOut, v);
|
||||
}
|
||||
if (invert) {
|
||||
return TechDraw::mirrorShape(compOut);
|
||||
return ShapeUtils::mirrorShape(compOut);
|
||||
}
|
||||
return compOut;
|
||||
}
|
||||
@@ -561,7 +561,7 @@ TopoDS_Shape DrawUtil::vectorToCompound(std::vector<TopoDS_Wire> vecIn, bool inv
|
||||
builder.Add(compOut, v);
|
||||
}
|
||||
if (invert) {
|
||||
return TechDraw::mirrorShape(compOut);
|
||||
return ShapeUtils::mirrorShape(compOut);
|
||||
}
|
||||
return compOut;
|
||||
}
|
||||
|
||||
@@ -215,13 +215,13 @@ void DrawViewDetail::makeDetailShape(const TopoDS_Shape& shape, DrawViewPart* dv
|
||||
m_saveDvp = dvp;
|
||||
m_saveDvs = dvs;
|
||||
|
||||
gp_Pnt gpCenter = TechDraw::findCentroid(copyShape, dirDetail);
|
||||
gp_Pnt gpCenter = ShapeUtils::findCentroid(copyShape, dirDetail);
|
||||
Base::Vector3d shapeCenter = Base::Vector3d(gpCenter.X(), gpCenter.Y(), gpCenter.Z());
|
||||
m_saveCentroid = shapeCenter;//centroid of original shape
|
||||
|
||||
if (!dvs) {
|
||||
//section cutShape should already be on origin
|
||||
copyShape = TechDraw::moveShape(copyShape,//centre shape on origin
|
||||
copyShape = ShapeUtils::moveShape(copyShape,//centre shape on origin
|
||||
-shapeCenter);
|
||||
}
|
||||
|
||||
@@ -344,14 +344,14 @@ void DrawViewDetail::makeDetailShape(const TopoDS_Shape& shape, DrawViewPart* dv
|
||||
gp_Pnt inputCenter;
|
||||
try {
|
||||
//centroid of result
|
||||
inputCenter = TechDraw::findCentroid(pieces, dirDetail);
|
||||
inputCenter = ShapeUtils::findCentroid(pieces, dirDetail);
|
||||
Base::Vector3d centroid(inputCenter.X(), inputCenter.Y(), inputCenter.Z());
|
||||
m_saveCentroid += centroid;//center of massaged shape
|
||||
|
||||
if ((solidCount > 0) || (shellCount > 0)) {
|
||||
//align shape with detail anchor
|
||||
TopoDS_Shape centeredShape = TechDraw::moveShape(pieces, anchor * -1.0);
|
||||
m_scaledShape = TechDraw::scaleShape(centeredShape, getScale());
|
||||
TopoDS_Shape centeredShape = ShapeUtils::moveShape(pieces, anchor * -1.0);
|
||||
m_scaledShape = ShapeUtils::scaleShape(centeredShape, getScale());
|
||||
if (debugDetail()) {
|
||||
BRepTools::Write(m_scaledShape, "DVDScaled.brep");//debug
|
||||
}
|
||||
@@ -359,19 +359,19 @@ void DrawViewDetail::makeDetailShape(const TopoDS_Shape& shape, DrawViewPart* dv
|
||||
else {
|
||||
//no solids, no shells, do what you can with edges
|
||||
TopoDS_Shape projectedEdges = projectEdgesOntoFace(copyShape, extrusionFace, gdir);
|
||||
TopoDS_Shape centeredShape = TechDraw::moveShape(projectedEdges, anchor * -1.0);
|
||||
TopoDS_Shape centeredShape = ShapeUtils::moveShape(projectedEdges, anchor * -1.0);
|
||||
if (debugDetail()) {
|
||||
BRepTools::Write(projectedEdges, "DVDProjectedEdges.brep");//debug
|
||||
BRepTools::Write(centeredShape, "DVDCenteredShape.brep"); //debug
|
||||
}
|
||||
m_scaledShape = TechDraw::scaleShape(centeredShape, getScale());
|
||||
m_scaledShape = ShapeUtils::scaleShape(centeredShape, getScale());
|
||||
}
|
||||
|
||||
Base::Vector3d stdOrg(0.0, 0.0, 0.0);
|
||||
m_viewAxis = dvp->getProjectionCS(stdOrg);
|
||||
|
||||
if (!DrawUtil::fpCompare(Rotation.getValue(), 0.0)) {
|
||||
m_scaledShape = TechDraw::rotateShape(m_scaledShape, m_viewAxis, Rotation.getValue());
|
||||
m_scaledShape = ShapeUtils::rotateShape(m_scaledShape, m_viewAxis, Rotation.getValue());
|
||||
}
|
||||
}//end try block
|
||||
|
||||
|
||||
@@ -108,15 +108,15 @@ App::DocumentObjectExecReturn *DrawViewMulti::execute()
|
||||
|
||||
gp_Pnt inputCenter;
|
||||
try {
|
||||
inputCenter = TechDraw::findCentroid(comp,
|
||||
inputCenter = ShapeUtils::findCentroid(comp,
|
||||
Direction.getValue());
|
||||
shapeCentroid = Base::Vector3d(inputCenter.X(), inputCenter.Y(), inputCenter.Z());
|
||||
TopoDS_Shape mirroredShape = TechDraw::mirrorShape(comp,
|
||||
TopoDS_Shape mirroredShape = ShapeUtils::mirrorShape(comp,
|
||||
inputCenter,
|
||||
getScale());
|
||||
gp_Ax2 viewAxis = getViewAxis(Base::Vector3d(inputCenter.X(), inputCenter.Y(), inputCenter.Z()), Direction.getValue());
|
||||
if (!DrawUtil::fpCompare(Rotation.getValue(), 0.0)) {
|
||||
mirroredShape = TechDraw::rotateShape(mirroredShape,
|
||||
mirroredShape = ShapeUtils::rotateShape(mirroredShape,
|
||||
viewAxis,
|
||||
Rotation.getValue());
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
#include "GeometryObject.h"
|
||||
#include "ShapeExtractor.h"
|
||||
#include "Preferences.h"
|
||||
|
||||
#include "ShapeUtils.h"
|
||||
|
||||
using namespace TechDraw;
|
||||
using DU = DrawUtil;
|
||||
@@ -175,7 +175,7 @@ TopoDS_Shape DrawViewPart::getSourceShape(bool fuse) const
|
||||
// version of the shape? Should we have a getShapeForSection?
|
||||
TopoDS_Shape DrawViewPart::getShapeForDetail() const
|
||||
{
|
||||
return TechDraw::rotateShape(getSourceShape(true), getProjectionCS(), Rotation.getValue());
|
||||
return ShapeUtils::rotateShape(getSourceShape(true), getProjectionCS(), Rotation.getValue());
|
||||
}
|
||||
|
||||
// combine the regular links and xlinks into a single list
|
||||
@@ -211,11 +211,11 @@ void DrawViewPart::addShapes2d(void)
|
||||
else if (s.ShapeType() == TopAbs_EDGE) {
|
||||
//not supporting edges yet. Why?
|
||||
//Base::Console().Message("DVP::add2dShapes - found loose edge - isNull: %d\n", s.IsNull());
|
||||
TopoDS_Shape sTrans = TechDraw::moveShape(s,
|
||||
TopoDS_Shape sTrans = ShapeUtils::moveShape(s,
|
||||
m_saveCentroid * -1.0);
|
||||
TopoDS_Shape sScale = TechDraw::scaleShape(sTrans,
|
||||
TopoDS_Shape sScale = ShapeUtils::scaleShape(sTrans,
|
||||
getScale());
|
||||
TopoDS_Shape sMirror = TechDraw::mirrorShape(sScale);
|
||||
TopoDS_Shape sMirror = ShapeUtils::mirrorShape(sScale);
|
||||
TopoDS_Edge edge = TopoDS::Edge(sMirror);
|
||||
BaseGeomPtr bg = projectEdge(edge);
|
||||
|
||||
@@ -313,7 +313,7 @@ GeometryObjectPtr DrawViewPart::makeGeometryForShape(TopoDS_Shape& shape)
|
||||
BRepBuilderAPI_Copy copier(shape, copyGeometry, copyMesh);
|
||||
TopoDS_Shape localShape = copier.Shape();
|
||||
|
||||
gp_Pnt gCentroid = TechDraw::findCentroid(localShape, getProjectionCS());
|
||||
gp_Pnt gCentroid = ShapeUtils::findCentroid(localShape, getProjectionCS());
|
||||
m_saveCentroid = DU::toVector3d(gCentroid);
|
||||
m_saveShape = centerScaleRotate(this, localShape, m_saveCentroid);
|
||||
|
||||
@@ -328,11 +328,11 @@ TopoDS_Shape DrawViewPart::centerScaleRotate(DrawViewPart* dvp, TopoDS_Shape& in
|
||||
gp_Ax2 viewAxis = dvp->getProjectionCS();
|
||||
|
||||
//center shape on origin
|
||||
TopoDS_Shape centeredShape = TechDraw::moveShape(inOutShape, centroid * -1.0);
|
||||
TopoDS_Shape centeredShape = ShapeUtils::moveShape(inOutShape, centroid * -1.0);
|
||||
|
||||
inOutShape = TechDraw::scaleShape(centeredShape, dvp->getScale());
|
||||
inOutShape = ShapeUtils::scaleShape(centeredShape, dvp->getScale());
|
||||
if (!DrawUtil::fpCompare(dvp->Rotation.getValue(), 0.0)) {
|
||||
inOutShape = TechDraw::rotateShape(inOutShape, viewAxis,
|
||||
inOutShape = ShapeUtils::rotateShape(inOutShape, viewAxis,
|
||||
dvp->Rotation.getValue());//conventional rotation
|
||||
}
|
||||
// BRepTools::Write(inOutShape, "DVPScaled.brep"); //debug
|
||||
@@ -993,7 +993,7 @@ double DrawViewPart::getSizeAlongVector(Base::Vector3d alignmentVector)
|
||||
if (getEdgeCompound().IsNull()) {
|
||||
return 1.0;
|
||||
}
|
||||
TopoDS_Shape rotatedShape = rotateShape(getEdgeCompound(), OXYZ, alignmentAngle * 180.0 / M_PI);
|
||||
TopoDS_Shape rotatedShape = ShapeUtils::rotateShape(getEdgeCompound(), OXYZ, alignmentAngle * 180.0 / M_PI);
|
||||
Bnd_Box shapeBox;
|
||||
shapeBox.SetGap(0.0);
|
||||
BRepBndLib::AddOptimal(rotatedShape, shapeBox);
|
||||
@@ -1145,7 +1145,7 @@ Base::Vector3d DrawViewPart::getCurrentCentroid() const
|
||||
return Base::Vector3d(0.0, 0.0, 0.0);
|
||||
}
|
||||
gp_Ax2 cs = getProjectionCS();
|
||||
gp_Pnt gCenter = TechDraw::findCentroid(shape, cs);
|
||||
gp_Pnt gCenter = ShapeUtils::findCentroid(shape, cs);
|
||||
return DU::toVector3d(gCenter);
|
||||
}
|
||||
|
||||
@@ -1287,7 +1287,7 @@ Base::Vector3d DrawViewPart::getLegacyX(const Base::Vector3d& pt, const Base::Ve
|
||||
const bool flip) const
|
||||
{
|
||||
// Base::Console().Message("DVP::getLegacyX() - %s\n", Label.getValue());
|
||||
gp_Ax2 viewAxis = TechDraw::legacyViewAxis1(pt, axis, flip);
|
||||
gp_Ax2 viewAxis = ShapeUtils::legacyViewAxis1(pt, axis, flip);
|
||||
gp_Dir gXDir = viewAxis.XDirection();
|
||||
return Base::Vector3d(gXDir.X(), gXDir.Y(), gXDir.Z());
|
||||
}
|
||||
|
||||
@@ -658,7 +658,7 @@ PyObject* DrawViewPartPy::getEdgeByIndex(PyObject *args)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TopoDS_Shape temp = TechDraw::mirrorShapeVec(geom->getOCCEdge(),
|
||||
TopoDS_Shape temp = ShapeUtils::mirrorShapeVec(geom->getOCCEdge(),
|
||||
Base::Vector3d(0.0, 0.0, 0.0),
|
||||
1.0 / dvp->getScale());
|
||||
|
||||
@@ -712,7 +712,7 @@ PyObject* DrawViewPartPy::getEdgeBySelection(PyObject *args)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TopoDS_Shape temp = TechDraw::mirrorShapeVec(geom->getOCCEdge(),
|
||||
TopoDS_Shape temp = ShapeUtils::mirrorShapeVec(geom->getOCCEdge(),
|
||||
Base::Vector3d(0.0, 0.0, 0.0),
|
||||
1.0 / dvp->getScale());
|
||||
|
||||
|
||||
@@ -297,7 +297,7 @@ TopoDS_Shape DrawViewSection::getShapeToCut()
|
||||
|
||||
TopoDS_Shape DrawViewSection::getShapeForDetail() const
|
||||
{
|
||||
return TechDraw::rotateShape(getCutShape(), getProjectionCS(), Rotation.getValue());
|
||||
return ShapeUtils::rotateShape(getCutShape(), getProjectionCS(), Rotation.getValue());
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn* DrawViewSection::execute()
|
||||
@@ -476,18 +476,18 @@ TopoDS_Shape DrawViewSection::prepareShape(const TopoDS_Shape& rawShape, double
|
||||
Base::Vector3d origin(0.0, 0.0, 0.0);
|
||||
m_projectionCS = getProjectionCS(origin);
|
||||
gp_Pnt inputCenter;
|
||||
inputCenter = TechDraw::findCentroid(rawShape, m_projectionCS);
|
||||
inputCenter = ShapeUtils::findCentroid(rawShape, m_projectionCS);
|
||||
Base::Vector3d centroid(inputCenter.X(), inputCenter.Y(), inputCenter.Z());
|
||||
|
||||
preparedShape = TechDraw::moveShape(rawShape, centroid * -1.0);
|
||||
preparedShape = ShapeUtils::moveShape(rawShape, centroid * -1.0);
|
||||
m_cutShape = preparedShape;
|
||||
m_saveCentroid = centroid;
|
||||
|
||||
preparedShape = TechDraw::scaleShape(preparedShape, getScale());
|
||||
preparedShape = ShapeUtils::scaleShape(preparedShape, getScale());
|
||||
|
||||
if (!DrawUtil::fpCompare(Rotation.getValue(), 0.0)) {
|
||||
preparedShape =
|
||||
TechDraw::rotateShape(preparedShape, m_projectionCS, Rotation.getValue());
|
||||
ShapeUtils::rotateShape(preparedShape, m_projectionCS, Rotation.getValue());
|
||||
}
|
||||
if (debugSection()) {
|
||||
BRepTools::Write(m_cutShape, "DVSCutShape.brep");//debug
|
||||
@@ -564,12 +564,12 @@ void DrawViewSection::postHlrTasks(void)
|
||||
BRepTools::Write(faceIntersections, "DVSFaceIntersections.brep");//debug
|
||||
}
|
||||
|
||||
TopoDS_Shape centeredFaces = TechDraw::moveShape(faceIntersections, m_saveCentroid * -1.0);
|
||||
TopoDS_Shape centeredFaces = ShapeUtils::moveShape(faceIntersections, m_saveCentroid * -1.0);
|
||||
|
||||
TopoDS_Shape scaledSection = TechDraw::scaleShape(centeredFaces, getScale());
|
||||
TopoDS_Shape scaledSection = ShapeUtils::scaleShape(centeredFaces, getScale());
|
||||
if (!DrawUtil::fpCompare(Rotation.getValue(), 0.0)) {
|
||||
scaledSection =
|
||||
TechDraw::rotateShape(scaledSection, getProjectionCS(), Rotation.getValue());
|
||||
ShapeUtils::rotateShape(scaledSection, getProjectionCS(), Rotation.getValue());
|
||||
}
|
||||
|
||||
m_sectionTopoDSFaces = alignSectionFaces(faceIntersections);
|
||||
@@ -662,12 +662,12 @@ TopoDS_Compound DrawViewSection::alignSectionFaces(TopoDS_Shape faceIntersection
|
||||
// faceIntersections.IsNull());
|
||||
TopoDS_Compound sectionFaces;
|
||||
TopoDS_Shape centeredShape =
|
||||
TechDraw::moveShape(faceIntersections, getOriginalCentroid() * -1.0);
|
||||
ShapeUtils::moveShape(faceIntersections, getOriginalCentroid() * -1.0);
|
||||
|
||||
TopoDS_Shape scaledSection = TechDraw::scaleShape(centeredShape, getScale());
|
||||
TopoDS_Shape scaledSection = ShapeUtils::scaleShape(centeredShape, getScale());
|
||||
if (!DrawUtil::fpCompare(Rotation.getValue(), 0.0)) {
|
||||
scaledSection =
|
||||
TechDraw::rotateShape(scaledSection, getProjectionCS(), Rotation.getValue());
|
||||
ShapeUtils::rotateShape(scaledSection, getProjectionCS(), Rotation.getValue());
|
||||
}
|
||||
|
||||
return mapToPage(scaledSection);
|
||||
|
||||
@@ -424,7 +424,7 @@ bool BaseGeom::closed()
|
||||
BaseGeomPtr BaseGeom::inverted()
|
||||
{
|
||||
Base::Console().Message("BG::inverted()\n");
|
||||
TopoDS_Shape invertedShape = GeometryObject::invertGeometry(occEdge);
|
||||
TopoDS_Shape invertedShape = ShapeUtils::invertGeometry(occEdge);
|
||||
TopoDS_Edge invertedEdge = TopoDS::Edge(invertedShape);
|
||||
return baseFactory(invertedEdge);
|
||||
}
|
||||
@@ -713,7 +713,7 @@ void BaseGeom::intersectionCC(TechDraw::BaseGeomPtr geom1,
|
||||
TopoShape BaseGeom::asTopoShape(double scale)
|
||||
{
|
||||
// Base::Console().Message("BG::asTopoShape(%.3f) - dump: %s\n", scale, dump().c_str());
|
||||
TopoDS_Shape unscaledShape = TechDraw::scaleShape(getOCCEdge(), 1.0 / scale);
|
||||
TopoDS_Shape unscaledShape = ShapeUtils::scaleShape(getOCCEdge(), 1.0 / scale);
|
||||
TopoDS_Edge unscaledEdge = TopoDS::Edge(unscaledShape);
|
||||
return unscaledEdge;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
#ifndef TECHDRAW_GEOMETRYOBJECT_H
|
||||
#define TECHDRAW_GEOMETRYOBJECT_H
|
||||
|
||||
//! a class to the projection of shapes, removal/identifying hidden lines and
|
||||
// converting the output for OCC HLR into the BaseGeom intermediate representation.
|
||||
|
||||
|
||||
#include <Mod/TechDraw/TechDrawGlobal.h>
|
||||
|
||||
#include <memory>
|
||||
@@ -37,6 +41,7 @@
|
||||
#include <Base/Vector3D.h>
|
||||
|
||||
#include "Geometry.h"
|
||||
#include "ShapeUtils.h"
|
||||
|
||||
|
||||
namespace TechDraw
|
||||
@@ -55,46 +60,6 @@ class Vector;
|
||||
class Face;
|
||||
class Vertex;
|
||||
|
||||
//! scales & mirrors a shape about a center
|
||||
|
||||
TopoDS_Shape TechDrawExport mirrorShapeVec(
|
||||
const TopoDS_Shape& input, const Base::Vector3d& inputCenter = Base::Vector3d(0.0, 0.0, 0.0),
|
||||
double scale = 1.0);
|
||||
|
||||
TopoDS_Shape TechDrawExport mirrorShape(const TopoDS_Shape& input,
|
||||
const gp_Pnt& inputCenter = gp_Pnt(0.0, 0.0, 0.0),
|
||||
double scale = 1.0);
|
||||
|
||||
TopoDS_Shape TechDrawExport scaleShape(const TopoDS_Shape& input, double scale);
|
||||
TopoDS_Shape TechDrawExport rotateShape(const TopoDS_Shape& input, const gp_Ax2& viewAxis,
|
||||
double rotAngle);
|
||||
TopoDS_Shape TechDrawExport moveShape(const TopoDS_Shape& input, const Base::Vector3d& motion);
|
||||
TopoDS_Shape TechDrawExport moveShapeRestricted(const TopoDS_Shape& input,
|
||||
const Base::Vector3d& motion, bool allowX = true,
|
||||
bool allowY = true, bool allowZ = true);
|
||||
TopoDS_Shape TechDrawExport moveShapeRestricted(const TopoDS_Shape& input,
|
||||
const Base::Vector3d& motion,
|
||||
const Base::Vector3d& mask);
|
||||
TopoDS_Shape TechDrawExport moveShapeRestricted(const TopoDS_Shape& input, const gp_Vec& motion,
|
||||
const gp_Vec& mask);
|
||||
TopoDS_Shape TechDrawExport centerShapeXY(const TopoDS_Shape& inShape, const gp_Ax2& coordSys);
|
||||
|
||||
//! Returns the centroid of shape, as viewed according to direction
|
||||
gp_Pnt TechDrawExport findCentroid(const TopoDS_Shape& shape);
|
||||
gp_Pnt TechDrawExport findCentroid(const TopoDS_Shape& shape, const Base::Vector3d& direction);
|
||||
gp_Pnt TechDrawExport findCentroid(const TopoDS_Shape& shape, const gp_Ax2& viewAxis);
|
||||
Base::Vector3d TechDrawExport findCentroidVec(const TopoDS_Shape& shape,
|
||||
const Base::Vector3d& direction);
|
||||
Base::Vector3d TechDrawExport findCentroidVec(const TopoDS_Shape& shape, const gp_Ax2& cs);
|
||||
gp_Pnt TechDrawExport findCentroidXY(const TopoDS_Shape& shape, const gp_Ax2& coordSys);
|
||||
|
||||
gp_Ax2 TechDrawExport getViewAxis(const Base::Vector3d origin, const Base::Vector3d& direction,
|
||||
const bool flip = true);
|
||||
gp_Ax2 TechDrawExport getViewAxis(const Base::Vector3d origin, const Base::Vector3d& direction,
|
||||
const Base::Vector3d& xAxis, const bool flip = true);
|
||||
gp_Ax2 TechDrawExport legacyViewAxis1(const Base::Vector3d origin, const Base::Vector3d& direction,
|
||||
const bool flip = true);
|
||||
|
||||
class TechDrawExport GeometryObject
|
||||
{
|
||||
public:
|
||||
@@ -137,9 +102,6 @@ public:
|
||||
|
||||
void pruneVertexGeom(Base::Vector3d center, double radius);
|
||||
|
||||
//dupl mirrorShape???
|
||||
static TopoDS_Shape invertGeometry(const TopoDS_Shape s);
|
||||
|
||||
TopoDS_Shape getVisHard() { return visHard; }
|
||||
TopoDS_Shape getVisOutline() { return visOutline; }
|
||||
TopoDS_Shape getVisSmooth() { return visSmooth; }
|
||||
@@ -210,3 +172,4 @@ using GeometryObjectPtr = std::shared_ptr<GeometryObject>;
|
||||
}//namespace TechDraw
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
355
src/Mod/TechDraw/App/ShapeUtils.cpp
Normal file
355
src/Mod/TechDraw/App/ShapeUtils.cpp
Normal file
@@ -0,0 +1,355 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 WandererFan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
//! a class to contain useful shape manipulations. these methods were orginally in
|
||||
// GeometryObject.
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
#include <BRepAlgo_NormalProjection.hxx>
|
||||
#include <BRepBndLib.hxx>
|
||||
#include <BRepBuilderAPI_Copy.hxx>
|
||||
#include <BRepBuilderAPI_MakeEdge.hxx>
|
||||
#include <BRepBuilderAPI_MakeFace.hxx>
|
||||
#include <BRepBuilderAPI_Transform.hxx>
|
||||
#include <BRepLProp_CLProps.hxx>
|
||||
#include <BRepLProp_CurveTool.hxx>
|
||||
#include <BRepLib.hxx>
|
||||
#include <BRepMesh_IncrementalMesh.hxx>
|
||||
#include <BRepTools.hxx>
|
||||
#include <BRep_Builder.hxx>
|
||||
#include <BRep_Tool.hxx>
|
||||
#include <Bnd_Box.hxx>
|
||||
#include <HLRAlgo_Projector.hxx>
|
||||
#include <HLRBRep.hxx>
|
||||
#include <HLRBRep_Algo.hxx>
|
||||
#include <HLRBRep_HLRToShape.hxx>
|
||||
#include <HLRBRep_PolyAlgo.hxx>
|
||||
#include <HLRBRep_PolyHLRToShape.hxx>
|
||||
#include <TopExp.hxx>
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopoDS_Edge.hxx>
|
||||
#include <TopoDS_Face.hxx>
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <TopoDS_Vertex.hxx>
|
||||
#include <gp_Ax1.hxx>
|
||||
#include <gp_Ax2.hxx>
|
||||
#include <gp_Ax3.hxx>
|
||||
#include <gp_Dir.hxx>
|
||||
#include <gp_Pln.hxx>
|
||||
#include <gp_Trsf.hxx>
|
||||
#include <gp_Vec.hxx>
|
||||
#endif// #ifndef _PreComp_
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
|
||||
#include <Base/Console.h>
|
||||
|
||||
#include "DrawUtil.h"
|
||||
#include "ShapeUtils.h"
|
||||
|
||||
using namespace TechDraw;
|
||||
using namespace std;
|
||||
|
||||
using DU = DrawUtil;
|
||||
|
||||
|
||||
//! 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 ShapeUtils::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 ShapeUtils::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 ShapeUtils::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 ShapeUtils::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 ShapeUtils::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 ShapeUtils::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 ShapeUtils::findCentroidVec(const TopoDS_Shape& shape, const Base::Vector3d& direction)
|
||||
{
|
||||
// Base::Console().Message("GO::findCentroidVec() - 1\n");
|
||||
gp_Pnt p = ShapeUtils::findCentroid(shape, direction);
|
||||
return Base::Vector3d(p.X(), p.Y(), p.Z());
|
||||
}
|
||||
|
||||
Base::Vector3d ShapeUtils::findCentroidVec(const TopoDS_Shape& shape, const gp_Ax2& cs)
|
||||
{
|
||||
// Base::Console().Message("GO::findCentroidVec() - 2\n");
|
||||
gp_Pnt p = ShapeUtils::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 ShapeUtils::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 ShapeUtils::mirrorShapeVec(const TopoDS_Shape& input, const Base::Vector3d& inputCenter,
|
||||
double scale)
|
||||
{
|
||||
gp_Pnt gInput(inputCenter.x, inputCenter.y, inputCenter.z);
|
||||
return ShapeUtils::mirrorShape(input, gInput, scale);
|
||||
}
|
||||
|
||||
TopoDS_Shape ShapeUtils::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 ShapeUtils::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 ShapeUtils::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 ShapeUtils::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;
|
||||
}
|
||||
|
||||
TopoDS_Shape ShapeUtils::centerShapeXY(const TopoDS_Shape& inShape, const gp_Ax2& coordSys)
|
||||
{
|
||||
gp_Pnt inputCenter = findCentroidXY(inShape, coordSys);
|
||||
Base::Vector3d centroid = DrawUtil::toVector3d(inputCenter);
|
||||
return ShapeUtils::moveShape(inShape, centroid * -1.0);
|
||||
}
|
||||
110
src/Mod/TechDraw/App/ShapeUtils.h
Normal file
110
src/Mod/TechDraw/App/ShapeUtils.h
Normal file
@@ -0,0 +1,110 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2023 WandererFan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef TECHDRAW_SHAPEUTILS_H
|
||||
#define TECHDRAW_SHAPEUTILS_H
|
||||
|
||||
#include <Mod/TechDraw/TechDrawGlobal.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <TopoDS_Shape.hxx>
|
||||
#include <gp_Ax2.hxx>
|
||||
#include <gp_Pnt.hxx>
|
||||
|
||||
#include <Base/Vector3D.h>
|
||||
|
||||
//! a class to contain useful shape manipulations. these methods were orginally in
|
||||
// GeometryObject.
|
||||
|
||||
namespace TechDraw
|
||||
{
|
||||
class DrawViewPart;
|
||||
class DrawViewDetail;
|
||||
class DrawView;
|
||||
class CosmeticVertex;
|
||||
class CosmeticEdge;
|
||||
class BaseGeom;
|
||||
class Vector;
|
||||
class Face;
|
||||
class Vertex;
|
||||
|
||||
class TechDrawExport ShapeUtils
|
||||
{
|
||||
public:
|
||||
//! scales & mirrors a shape about a center
|
||||
static TopoDS_Shape mirrorShapeVec( const TopoDS_Shape& input,
|
||||
const Base::Vector3d& inputCenter = Base::Vector3d(0.0, 0.0, 0.0),
|
||||
double scale = 1.0);
|
||||
//! scales & mirrors a shape about a center
|
||||
static TopoDS_Shape mirrorShapeVec(TopoDS_Shape& input, const Base::Vector3d& inputCenter = Base::Vector3d(0.0, 0.0, 0.0),
|
||||
double scale = 1.0);
|
||||
|
||||
//! mirrors a shape around the y axis. this is need to deal with Qt's odd coordinate choice where the Y-axis
|
||||
//! has increasing values in the down direction. also performs a scaling of the input shaft
|
||||
static TopoDS_Shape mirrorShape(const TopoDS_Shape& input,
|
||||
const gp_Pnt& inputCenter = gp_Pnt(0.0, 0.0, 0.0),
|
||||
double scale = 1.0);
|
||||
//! another mirroring routine that modifies the shape to conform with the Qt coordinate system.
|
||||
static TopoDS_Shape invertGeometry(const TopoDS_Shape s);
|
||||
|
||||
//! scales a shape uniformly in all directions
|
||||
static TopoDS_Shape scaleShape(const TopoDS_Shape& input, double scale);
|
||||
|
||||
//! rotates a shape around the Z axis of a coordinate system
|
||||
static TopoDS_Shape rotateShape(const TopoDS_Shape& input, const gp_Ax2& coordSys,
|
||||
double rotAngle);
|
||||
|
||||
//! moves a shape in a direction and distance specified by the motion parameter
|
||||
static TopoDS_Shape moveShape(const TopoDS_Shape& input, const Base::Vector3d& motion);
|
||||
|
||||
//! move a shape such that its centroid is aligned with the origin point of a CoordinateSystem
|
||||
static TopoDS_Shape centerShapeXY(const TopoDS_Shape& inShape, const gp_Ax2& coordSys);
|
||||
|
||||
//! Returns the centroid of shape, as viewed according to direction
|
||||
static gp_Pnt findCentroid(const TopoDS_Shape& shape);
|
||||
static gp_Pnt findCentroid(const TopoDS_Shape& shape, const Base::Vector3d& direction);
|
||||
static gp_Pnt findCentroid(const TopoDS_Shape& shape, const gp_Ax2& viewAxis);
|
||||
static Base::Vector3d findCentroidVec(const TopoDS_Shape& shape,
|
||||
const Base::Vector3d& direction);
|
||||
static Base::Vector3d findCentroidVec(const TopoDS_Shape& shape, const gp_Ax2& cs);
|
||||
static gp_Pnt findCentroidXY(const TopoDS_Shape& shape, const gp_Ax2& coordSys);
|
||||
|
||||
|
||||
//! creates a RH coordinate system with the origin at origin and the Z axis along direction.
|
||||
// the flip will cause the Z axis to be the reversed of direction
|
||||
static gp_Ax2 getViewAxis(const Base::Vector3d origin, const Base::Vector3d& direction,
|
||||
const bool flip = true);
|
||||
static gp_Ax2 getViewAxis(const Base::Vector3d origin, const Base::Vector3d& direction,
|
||||
const Base::Vector3d& xAxis, const bool flip = true);
|
||||
static gp_Ax2 legacyViewAxis1(const Base::Vector3d origin, const Base::Vector3d& direction,
|
||||
const bool flip = true);
|
||||
|
||||
static TopoDS_Shape projectSimpleShape(const TopoDS_Shape& shape, const gp_Ax2& CS);
|
||||
static TopoDS_Shape simpleProjection(const TopoDS_Shape& shape, const gp_Ax2& projCS);
|
||||
static TopoDS_Shape projectFace(const TopoDS_Shape& face, const gp_Ax2& CS);
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user