[TD]correct alignment of Section & Detail with Base

This commit is contained in:
wandererfan
2019-11-17 13:55:19 -05:00
committed by WandererFan
parent 333b67026c
commit 92dfecea75
17 changed files with 625 additions and 418 deletions

View File

@@ -24,6 +24,7 @@
#ifndef _PreComp_
#include <BRep_Tool.hxx>
#include <BRepTools.hxx>
#include <BRepMesh_IncrementalMesh.hxx>
#include <BRepLib.hxx>
#include <BRepLProp_CurveTool.hxx>
@@ -161,9 +162,10 @@ void GeometryObject::clear()
void GeometryObject::projectShape(const TopoDS_Shape& input,
const gp_Ax2 viewAxis)
{
// Base::Console().Message("GO::projectShape()\n");
// Base::Console().Message("GO::projectShape() - %s\n", m_parentName.c_str());
// Clear previous Geometry
clear();
// DrawUtil::dumpCS("GO::projectShape - VA in", viewAxis); //debug
auto start = chrono::high_resolution_clock::now();
@@ -173,11 +175,9 @@ void GeometryObject::projectShape(const TopoDS_Shape& input,
brep_hlr->Add(input, m_isoCount);
if (m_isPersp) {
double fLength = std::max(Precision::Confusion(),m_focus);
// HLRAlgo_Projector projector( projAxis, fLength );
HLRAlgo_Projector projector( viewAxis, fLength );
brep_hlr->Projector(projector);
} else {
// HLRAlgo_Projector projector( projAxis );
HLRAlgo_Projector projector( viewAxis );
brep_hlr->Projector(projector);
}
@@ -191,7 +191,6 @@ void GeometryObject::projectShape(const TopoDS_Shape& input,
}
catch (...) {
throw Base::RuntimeError("GeometryObject::projectShape - unknown error occurred while projecting shape");
// Standard_Failure::Raise("GeometryObject::projectShape - error occurred while projecting shape");
}
auto end = chrono::high_resolution_clock::now();
@@ -205,27 +204,47 @@ void GeometryObject::projectShape(const TopoDS_Shape& input,
HLRBRep_HLRToShape hlrToShape(brep_hlr);
visHard = hlrToShape.VCompound();
visSmooth = hlrToShape.Rg1LineVCompound();
visSeam = hlrToShape.RgNLineVCompound();
visOutline = hlrToShape.OutLineVCompound();
visIso = hlrToShape.IsoLineVCompound();
hidHard = hlrToShape.HCompound();
hidSmooth = hlrToShape.Rg1LineHCompound();
hidSeam = hlrToShape.RgNLineHCompound();
hidOutline = hlrToShape.OutLineHCompound();
hidIso = hlrToShape.IsoLineHCompound();
//need these 3d curves to prevent "zero edges" later
BRepLib::BuildCurves3d(visHard);
visHard = invertGeometry(visHard);
// BRepTools::Write(visHard, "GOvisHardi.brep"); //debug
visSmooth = hlrToShape.Rg1LineVCompound();
BRepLib::BuildCurves3d(visSmooth);
visSmooth = invertGeometry(visSmooth);
visSeam = hlrToShape.RgNLineVCompound();
BRepLib::BuildCurves3d(visSeam);
visSeam = invertGeometry(visSeam);
visOutline = hlrToShape.OutLineVCompound();
BRepLib::BuildCurves3d(visOutline);
visOutline = invertGeometry(visOutline);
visIso = hlrToShape.IsoLineVCompound();
BRepLib::BuildCurves3d(visIso);
visIso = invertGeometry(visIso);
hidHard = hlrToShape.HCompound();
BRepLib::BuildCurves3d(hidHard);
hidHard = invertGeometry(hidHard);
// BRepTools::Write(hidHard, "GOhidHardi.brep"); //debug
hidSmooth = hlrToShape.Rg1LineHCompound();
BRepLib::BuildCurves3d(hidSmooth);
hidSmooth = invertGeometry(hidSmooth);
hidSeam = hlrToShape.RgNLineHCompound();
BRepLib::BuildCurves3d(hidSeam);
hidSeam = invertGeometry(hidSeam);
hidOutline = hlrToShape.OutLineHCompound();
BRepLib::BuildCurves3d(hidOutline);
hidOutline = invertGeometry(hidOutline);
hidIso = hlrToShape.IsoLineHCompound();
BRepLib::BuildCurves3d(hidIso);
hidIso = invertGeometry(hidIso);
}
catch (const Standard_Failure& e) {
Base::Console().Error("GO::projectShape - OCC error - %s - while extracting edges\n",
@@ -240,6 +259,26 @@ void GeometryObject::projectShape(const TopoDS_Shape& input,
Base::Console().Log("TIMING - %s GO spent: %.3f millisecs in hlrToShape and BuildCurves\n",m_parentName.c_str(),diffOut);
}
//mirror a shape thru XZ plane for Qt's inverted Y coordinate
TopoDS_Shape GeometryObject::invertGeometry(const TopoDS_Shape s)
{
TopoDS_Shape result;
if (s.IsNull()) {
result = s;
return result;
}
gp_Trsf mirrorY;
gp_Pnt org(0.0, 0.0, 0.0);
gp_Dir Y(0.0, 1.0, 0.0);
gp_Ax2 mirrorPlane(org,
Y);
mirrorY.SetMirror(mirrorPlane);
BRepBuilderAPI_Transform mkTrf(s, mirrorY, true);
result = mkTrf.Shape();
return result;
}
//!set up a hidden line remover and project a shape with it
void GeometryObject::projectShapeWithPolygonAlgo(const TopoDS_Shape& input,
const gp_Ax2 viewAxis)
@@ -300,24 +339,39 @@ void GeometryObject::projectShapeWithPolygonAlgo(const TopoDS_Shape& input,
HLRBRep_PolyHLRToShape polyhlrToShape;
polyhlrToShape.Update(brep_hlrPoly);
visHard = polyhlrToShape.VCompound();
visSmooth = polyhlrToShape.Rg1LineVCompound();
visSeam = polyhlrToShape.RgNLineVCompound();
visOutline = polyhlrToShape.OutLineVCompound();
hidHard = polyhlrToShape.HCompound();
hidSmooth = polyhlrToShape.Rg1LineHCompound();
hidSeam = polyhlrToShape.RgNLineHCompound();
hidOutline = polyhlrToShape.OutLineHCompound();
//need these 3d curves to prevent "zero edges" later
visHard = polyhlrToShape.VCompound();
BRepLib::BuildCurves3d(visHard);
visHard = invertGeometry(visHard);
// BRepTools::Write(visHard, "GOvisHardi.brep"); //debug
visSmooth = polyhlrToShape.Rg1LineVCompound();
BRepLib::BuildCurves3d(visSmooth);
visSmooth = invertGeometry(visSmooth);
visSeam = polyhlrToShape.RgNLineVCompound();
BRepLib::BuildCurves3d(visSeam);
visSeam = invertGeometry(visSeam);
visOutline = polyhlrToShape.OutLineVCompound();
BRepLib::BuildCurves3d(visOutline);
visOutline = invertGeometry(visOutline);
hidHard = polyhlrToShape.HCompound();
BRepLib::BuildCurves3d(hidHard);
hidHard = invertGeometry(hidHard);
// BRepTools::Write(hidHard, "GOhidHardi.brep"); //debug
hidSmooth = polyhlrToShape.Rg1LineHCompound();
BRepLib::BuildCurves3d(hidSmooth);
hidSmooth = invertGeometry(hidSmooth);
hidSeam = polyhlrToShape.RgNLineHCompound();
BRepLib::BuildCurves3d(hidSeam);
hidSeam = invertGeometry(hidSeam);
hidOutline = polyhlrToShape.OutLineHCompound();
BRepLib::BuildCurves3d(hidOutline);
hidOutline = invertGeometry(hidOutline);
}
catch (const Standard_Failure& e) {
Base::Console().Error("GO::projectShapeWithPolygonAlgo - OCC error - %s - while extracting edges\n",
@@ -333,6 +387,29 @@ void GeometryObject::projectShapeWithPolygonAlgo(const TopoDS_Shape& input,
Base::Console().Log("TIMING - %s GO spent: %.3f millisecs in HLRBRep_PolyAlgo & co\n", m_parentName.c_str(), diffOut);
}
TopoDS_Shape GeometryObject::projectFace(const TopoDS_Shape &face,
const gp_Ax2 CS)
{
// Base::Console().Message("GO::projectFace()\n");
if(face.IsNull()) {
throw Base::ValueError("GO::projectFace - input Face is NULL");
}
HLRBRep_Algo *brep_hlr = new HLRBRep_Algo();
brep_hlr->Add(face);
HLRAlgo_Projector projector( CS );
brep_hlr->Projector(projector);
brep_hlr->Update();
brep_hlr->Hide();
HLRBRep_HLRToShape hlrToShape(brep_hlr);
TopoDS_Shape hardEdges = hlrToShape.VCompound();
BRepLib::BuildCurves3d(hardEdges);
hardEdges = invertGeometry(hardEdges);
return hardEdges;
}
//!add edges meeting filter criteria for category, visibility
void GeometryObject::extractGeometry(edgeClass category, bool hlrVisible)
{
@@ -655,7 +732,55 @@ 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 (TechDraw::DrawUtil::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);
gp_Ax2 viewAxis;
viewAxis = gp_Ax2(inputCenter,
gp_Dir(direction.x, direction.y, direction.z),
gp_Dir(xAxis.x, xAxis.y, xAxis.z));
return viewAxis;
}
// 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)
{
gp_Ax2 viewAxis;
gp_Pnt inputCenter(origin.x,origin.y,origin.z);
Base::Vector3d stdZ(0.0,0.0,1.0);
@@ -685,30 +810,11 @@ gp_Ax2 TechDraw::getViewAxis(const Base::Vector3d origin,
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)
{
(void) flip;
gp_Pnt inputCenter(origin.x,origin.y,origin.z);
Base::Vector3d flipDirection(direction.x,-direction.y,direction.z);
if (!flip) {
flipDirection = Base::Vector3d(direction.x,direction.y,direction.z);
}
gp_Ax2 viewAxis;
viewAxis = gp_Ax2(inputCenter,
gp_Dir(flipDirection.x, flipDirection.y, flipDirection.z),
gp_Dir(xAxis.x, xAxis.y, xAxis.z));
return viewAxis;
}
//! 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);
@@ -718,6 +824,7 @@ gp_Pnt TechDraw::findCentroid(const TopoDS_Shape &shape,
gp_Pnt TechDraw::findCentroid(const TopoDS_Shape &shape,
const gp_Ax2 viewAxis)
{
// Base::Console().Message("GO::findCentroid() - 2\n");
// Base::Vector3d origin(0.0,0.0,0.0);
// gp_Ax2 viewAxis = getViewAxis(origin,direction);
@@ -745,11 +852,22 @@ gp_Pnt TechDraw::findCentroid(const TopoDS_Shape &shape,
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);
Base::Vector3d result(p.X(),p.Y(),p.Z());
return result;
}
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);
Base::Vector3d result(p.X(),p.Y(),p.Z());
return result;
}
//!scales & mirrors a shape about a center
TopoDS_Shape TechDraw::mirrorShape(const TopoDS_Shape &input,
const gp_Pnt& inputCenter,
@@ -831,7 +949,7 @@ TopoDS_Shape TechDraw::scaleShape(const TopoDS_Shape &input,
//!moves a shape
TopoDS_Shape TechDraw::moveShape(const TopoDS_Shape &input,
const Base::Vector3d& motion)
const Base::Vector3d& motion)
{
TopoDS_Shape transShape;
try {