[TD]remove unused code dvp & sections

This commit is contained in:
wandererfan
2023-07-04 15:38:22 -04:00
committed by WandererFan
parent 5df5be3774
commit 08237b6c2c
6 changed files with 256 additions and 405 deletions

View File

@@ -147,32 +147,6 @@ DrawComplexSection::DrawComplexSection()
"Make a single cut, or use the profile in pieces");
}
TopoDS_Shape DrawComplexSection::getShapeToCut()
{
// Base::Console().Message("DCS::getShapeToCut()\n");
App::DocumentObject* base = BaseView.getValue();
TopoDS_Shape shapeToCut;
if (base && base == this) {
shapeToCut = getSourceShape();
if (FuseBeforeCut.getValue()) {
shapeToCut = getSourceShapeFused();
}
return shapeToCut;
}
if (!base
|| !base->getTypeId().isDerivedFrom(
TechDraw::DrawViewPart::getClassTypeId())) {//is second clause necessary?
//Complex section is based on 3d objects, need to get our own shapes since we can't ask a dvp
shapeToCut = getSourceShape();
if (FuseBeforeCut.getValue()) {
shapeToCut = getSourceShapeFused();
}
return shapeToCut;
}
//complex section is based on a DVP, so get the shape the normal way
return DrawViewSection::getShapeToCut();
}
TopoDS_Shape DrawComplexSection::makeCuttingTool(double dMax)
{
// Base::Console().Message("DCS::makeCuttingTool()\n");

View File

@@ -46,7 +46,6 @@ public:
App::PropertyLink CuttingToolWireObject;
App::PropertyEnumeration ProjectionStrategy;//Offset or Aligned
TopoDS_Shape getShapeToCut() override;
TopoDS_Shape makeCuttingTool(double dMax) override;
gp_Ax2 getCSFromBase(const std::string sectionName) const override;
bool isBaseValid() const override;

View File

@@ -87,7 +87,6 @@ using DU = DrawUtil;
//===========================================================================
//PROPERTY_SOURCE(TechDraw::DrawViewPart, TechDraw::DrawView)
PROPERTY_SOURCE_WITH_EXTENSIONS(TechDraw::DrawViewPart, TechDraw::DrawView)
DrawViewPart::DrawViewPart(void)
@@ -101,42 +100,42 @@ DrawViewPart::DrawViewPart(void)
CosmeticExtension::initExtension(this);
double defDist = Preferences::getPreferenceGroup("General")->GetFloat("FocusDistance", 100.0);
//properties that affect Geometry
ADD_PROPERTY_TYPE(Source, (nullptr), group, App::Prop_None, "3D Shape to view");
Source.setScope(App::LinkScope::Global);
Source.setAllowExternal(true);
ADD_PROPERTY_TYPE(XSource, (nullptr), group, App::Prop_None, "External 3D Shape to view");
ADD_PROPERTY_TYPE(Direction, (0.0, -1.0, 0.0), group, App::Prop_None,
"Projection Plane normal. The direction you are looking from.");
ADD_PROPERTY_TYPE(XDirection, (0.0, 0.0, 0.0), group, App::Prop_None,
"Projection Plane X Axis in R3. Rotates/Mirrors View");
ADD_PROPERTY_TYPE(Perspective, (false), group, App::Prop_None,
"Perspective(true) or Orthographic(false) projection");
ADD_PROPERTY_TYPE(Focus, (defDist), group, App::Prop_None, "Perspective view focus distance");
ADD_PROPERTY_TYPE(Focus, (Preferences::getPreferenceGroup("General")->GetFloat("FocusDistance", 100.0)),
group, App::Prop_None, "Perspective view focus distance");
//properties that control HLR algo
bool coarseView = Preferences::getPreferenceGroup("General")->GetBool("CoarseView", false);
ADD_PROPERTY_TYPE(CoarseView, (coarseView), sgroup, App::Prop_None, "Coarse View on/off");
ADD_PROPERTY_TYPE(SmoothVisible, (prefSmoothViz()), sgroup, App::Prop_None,
"Show Visible Smooth lines");
ADD_PROPERTY_TYPE(SeamVisible, (prefSeamViz()), sgroup, App::Prop_None,
ADD_PROPERTY_TYPE(CoarseView, (Preferences::getPreferenceGroup("General")->GetBool("CoarseView", false)),
sgroup, App::Prop_None, "Coarse View on/off");
ADD_PROPERTY_TYPE(SmoothVisible, (Preferences::getPreferenceGroup("HLR")->GetBool("SmoothViz", true)),
sgroup, App::Prop_None, "Show Visible Smooth lines");
ADD_PROPERTY_TYPE(SeamVisible, (Preferences::getPreferenceGroup("HLR")->GetBool("SeamViz", false)),
sgroup, App::Prop_None,
"Show Visible Seam lines");
ADD_PROPERTY_TYPE(IsoVisible, (prefIsoViz()), sgroup, App::Prop_None,
"Show Visible Iso u, v lines");
ADD_PROPERTY_TYPE(HardHidden, (prefHardHid()), sgroup, App::Prop_None,
"Show Hidden Hard lines");
ADD_PROPERTY_TYPE(SmoothHidden, (prefSmoothHid()), sgroup, App::Prop_None,
"Show Hidden Smooth lines");
ADD_PROPERTY_TYPE(SeamHidden, (prefSeamHid()), sgroup, App::Prop_None,
"Show Hidden Seam lines");
ADD_PROPERTY_TYPE(IsoHidden, (prefIsoHid()), sgroup, App::Prop_None,
"Show Hidden Iso u, v lines");
ADD_PROPERTY_TYPE(IsoCount, (prefIsoCount()), sgroup, App::Prop_None,
"Number of iso parameters lines");
ADD_PROPERTY_TYPE(IsoVisible, (Preferences::getPreferenceGroup("HLR")->GetBool("IsoViz", false)),
sgroup, App::Prop_None, "Show Visible Iso u, v lines");
ADD_PROPERTY_TYPE(HardHidden, (Preferences::getPreferenceGroup("HLR")->GetBool("HardHid", false)),
sgroup, App::Prop_None, "Show Hidden Hard lines");
ADD_PROPERTY_TYPE(SmoothHidden, (Preferences::getPreferenceGroup("HLR")->GetBool("SmoothHid", false)),
sgroup, App::Prop_None, "Show Hidden Smooth lines");
ADD_PROPERTY_TYPE(SeamHidden, (Preferences::getPreferenceGroup("HLR")->GetBool("SeamHid", false)),
sgroup, App::Prop_None, "Show Hidden Seam lines");
ADD_PROPERTY_TYPE(IsoHidden, (Preferences::getPreferenceGroup("HLR")->GetBool("IsoHid", false)),
sgroup, App::Prop_None, "Show Hidden Iso u, v lines");
ADD_PROPERTY_TYPE(IsoCount, (Preferences::getPreferenceGroup("HLR")->GetBool("IsoCount", 0)),
sgroup, App::Prop_None, "Number of iso parameters lines");
ADD_PROPERTY_TYPE(ScrubCount, (Preferences::scrubCount()), sgroup, App::Prop_None,
"The number of times FreeCAD should try to clean the HLR result.");
@@ -158,43 +157,33 @@ DrawViewPart::~DrawViewPart()
removeAllReferencesFromGeom();
}
std::vector<TopoDS_Shape> DrawViewPart::getSourceShape2d() const
{
// Base::Console().Message("DVP::getSourceShape2d()\n");
const std::vector<App::DocumentObject*>& links = getAllSources();
return ShapeExtractor::getShapes2d(links);
}
TopoDS_Shape DrawViewPart::getSourceShape() const
TopoDS_Shape DrawViewPart::getSourceShape(bool fuse) const
{
// Base::Console().Message("DVP::getSourceShape()\n");
const std::vector<App::DocumentObject*>& links = getAllSources();
if (links.empty()) {
return TopoDS_Shape();
}
if (fuse) {
return ShapeExtractor::getShapesFused(links);
}
return ShapeExtractor::getShapes(links);
}
TopoDS_Shape DrawViewPart::getSourceShapeFused() const
{
// Base::Console().Message("DVP::getSourceShapeFused()\n");
const std::vector<App::DocumentObject*>& links = getAllSources();
if (links.empty()) {
return TopoDS_Shape();
}
return ShapeExtractor::getShapesFused(links);
}
// deliver a shape appropriate for making a detail view based on this view
// TODO: why does dvp do the thinking for detail, but section picks its own
// version of the shape? Should we have a getShapeForSection?
TopoDS_Shape DrawViewPart::getShapeForDetail() const
{
return TechDraw::rotateShape(getSourceShapeFused(), getProjectionCS(), Rotation.getValue());
return TechDraw::rotateShape(getSourceShape(true), getProjectionCS(), Rotation.getValue());
}
// combine the regular links and xlinks into a single list
std::vector<App::DocumentObject*> DrawViewPart::getAllSources() const
{
// Base::Console().Message("DVP::getAllSources()\n");
std::vector<App::DocumentObject*> links = Source.getValues();
std::vector<DocumentObject*> xLinks = XSource.getValues();
std::vector<App::DocumentObject*> xLinks = XSource.getValues();
std::vector<App::DocumentObject*> result = links;
if (!xLinks.empty()) {
@@ -207,7 +196,7 @@ std::vector<App::DocumentObject*> DrawViewPart::getAllSources() const
//add them directly to the geometry without going through HLR
void DrawViewPart::addShapes2d(void)
{
std::vector<TopoDS_Shape> shapes = getSourceShape2d();
std::vector<TopoDS_Shape> shapes = ShapeExtractor::getShapes2d(getAllSources());
for (auto& s : shapes) {
//just vertices for now
if (s.ShapeType() == TopAbs_VERTEX) {
@@ -220,17 +209,17 @@ void DrawViewPart::addShapes2d(void)
geometryObject->addVertex(v1);
}
else if (s.ShapeType() == TopAbs_EDGE) {
//not supporting edges yet.
// Base::Console().Message("DVP::add2dShapes - found loose edge - isNull: %d\n", s.IsNull());
// TopoDS_Shape sTrans = TechDraw::moveShape(s,
// m_saveCentroid * -1.0);
// TopoDS_Shape sScale = TechDraw::scaleShape(sTrans,
// getScale());
// TopoDS_Shape sMirror = TechDraw::mirrorShape(sScale);
// TopoDS_Edge edge = TopoDS::Edge(sMirror);
// BaseGeomPtr bg = projectEdge(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,
m_saveCentroid * -1.0);
TopoDS_Shape sScale = TechDraw::scaleShape(sTrans,
getScale());
TopoDS_Shape sMirror = TechDraw::mirrorShape(sScale);
TopoDS_Edge edge = TopoDS::Edge(sMirror);
BaseGeomPtr bg = projectEdge(edge);
// geometryObject->addEdge(bg);
geometryObject->addEdge(bg);
//save connection between source feat and this edge
}
}
@@ -522,177 +511,188 @@ void DrawViewPart::extractFaces()
}
if (newFaceFinder()) {
std::vector<TopoDS_Edge> closedEdges;
std::vector<TopoDS_Edge> cleanEdges = DrawProjectSplit::scrubEdges(goEdges, closedEdges);
findFacesNew(goEdges);
} else {
findFacesOld(goEdges);
}
}
if (cleanEdges.empty() && closedEdges.empty()) {
//how does this happen? something wrong somewhere
// Base::Console().Message("DVP::extractFaces - no clean or closed wires\n"); //debug
return;
// use the revised face finder algo
void DrawViewPart::findFacesNew(const std::vector<BaseGeomPtr> &goEdges)
{
std::vector<TopoDS_Edge> closedEdges;
std::vector<TopoDS_Edge> cleanEdges = DrawProjectSplit::scrubEdges(goEdges, closedEdges);
if (cleanEdges.empty() && closedEdges.empty()) {
//how does this happen? something wrong somewhere
// Base::Console().Message("DVP::findFacesNew - no clean or closed wires\n"); //debug
return;
}
//use EdgeWalker to make wires from edges
EdgeWalker eWalker;
std::vector<TopoDS_Wire> sortedWires;
try {
if (!cleanEdges.empty()) {
sortedWires = eWalker.execute(cleanEdges, true);//include outer wire
}
}
catch (Base::Exception& e) {
throw Base::RuntimeError(e.what());
}
geometryObject->clearFaceGeom();
//use EdgeWalker to make wires from edges
EdgeWalker eWalker;
std::vector<TopoDS_Wire> sortedWires;
try {
if (!cleanEdges.empty()) {
sortedWires = eWalker.execute(cleanEdges, true);//include outer wire
std::vector<TopoDS_Wire> closedWires;
for (auto& e : closedEdges) {
BRepBuilderAPI_MakeWire mkWire(e);
TopoDS_Wire w = mkWire.Wire();
closedWires.push_back(w);
}
if (!closedWires.empty()) {
sortedWires.insert(sortedWires.end(), closedWires.begin(), closedWires.end());
//inserting the closedWires that did not go through EdgeWalker into
//sortedWires ruins EdgeWalker's sort by size, so we have to do it again.
sortedWires = eWalker.sortWiresBySize(sortedWires);
}
if (sortedWires.empty()) {
Base::Console().Warning(
"DVP::findFacesNew - %s - Can't make faces from projected edges\n",
getNameInDocument());
}
else {
constexpr double minWireArea = 0.000001;//arbitrary very small face size
std::vector<TopoDS_Wire>::iterator itWire = sortedWires.begin();
for (; itWire != sortedWires.end(); itWire++) {
if (!BRep_Tool::IsClosed(*itWire)) {
continue;//can not make a face from open wire
}
}
catch (Base::Exception& e) {
throw Base::RuntimeError(e.what());
}
geometryObject->clearFaceGeom();
std::vector<TopoDS_Wire> closedWires;
for (auto& e : closedEdges) {
BRepBuilderAPI_MakeWire mkWire(e);
TopoDS_Wire w = mkWire.Wire();
closedWires.push_back(w);
}
if (!closedWires.empty()) {
sortedWires.insert(sortedWires.end(), closedWires.begin(), closedWires.end());
//inserting the closedWires that did not go through EdgeWalker into
//sortedWires ruins EdgeWalker's sort by size, so we have to do it again.
sortedWires = eWalker.sortWiresBySize(sortedWires);
}
double area = ShapeAnalysis::ContourArea(*itWire);
if (area <= minWireArea) {
continue;//can not make a face from wire with no area
}
if (sortedWires.empty()) {
Base::Console().Warning(
"DVP::extractFaces - %s - Can't make faces from projected edges\n",
getNameInDocument());
}
else {
constexpr double minWireArea = 0.000001;//arbitrary very small face size
std::vector<TopoDS_Wire>::iterator itWire = sortedWires.begin();
for (; itWire != sortedWires.end(); itWire++) {
if (!BRep_Tool::IsClosed(*itWire)) {
continue;//can not make a face from open wire
}
double area = ShapeAnalysis::ContourArea(*itWire);
if (area <= minWireArea) {
continue;//can not make a face from wire with no area
}
TechDraw::FacePtr f(std::make_shared<TechDraw::Face>());
const TopoDS_Wire& wire = (*itWire);
f->wires.push_back(new TechDraw::Wire(wire));
if (geometryObject) {
geometryObject->addFaceGeom(f);
}
TechDraw::FacePtr f(std::make_shared<TechDraw::Face>());
const TopoDS_Wire& wire = (*itWire);
f->wires.push_back(new TechDraw::Wire(wire));
if (geometryObject) {
geometryObject->addFaceGeom(f);
}
}
}
else {//use original method
//make a copy of the input edges so the loose tolerances of face finding are
//not applied to the real edge geometry. See TopoDS_Shape::TShape().
std::vector<TopoDS_Edge> copyEdges;
bool copyGeometry = true;
bool copyMesh = false;
for (const auto& e : goEdges) {
BRepBuilderAPI_Copy copier(e->getOCCEdge(), copyGeometry, copyMesh);
copyEdges.push_back(TopoDS::Edge(copier.Shape()));
}
std::vector<TopoDS_Edge> nonZero;
for (auto& e : copyEdges) {//drop any zero edges (shouldn't be any by now!!!)
if (!DrawUtil::isZeroEdge(e)) {
nonZero.push_back(e);
}
}
}
//HLR algo does not provide all edge intersections for edge endpoints.
//need to split long edges touched by Vertex of another edge
std::vector<splitPoint> splits;
std::vector<TopoDS_Edge>::iterator itOuter = nonZero.begin();
int iOuter = 0;
for (; itOuter != nonZero.end(); ++itOuter, iOuter++) {//*** itOuter != nonZero.end() - 1
TopoDS_Vertex v1 = TopExp::FirstVertex((*itOuter));
TopoDS_Vertex v2 = TopExp::LastVertex((*itOuter));
Bnd_Box sOuter;
BRepBndLib::AddOptimal(*itOuter, sOuter);
sOuter.SetGap(0.1);
if (sOuter.IsVoid()) {
// original face finding method
void DrawViewPart::findFacesOld(const std::vector<BaseGeomPtr> &goEdges)
{
//make a copy of the input edges so the loose tolerances of face finding are
//not applied to the real edge geometry. See TopoDS_Shape::TShape().
std::vector<TopoDS_Edge> copyEdges;
bool copyGeometry = true;
bool copyMesh = false;
for (const auto& e : goEdges) {
BRepBuilderAPI_Copy copier(e->getOCCEdge(), copyGeometry, copyMesh);
copyEdges.push_back(TopoDS::Edge(copier.Shape()));
}
std::vector<TopoDS_Edge> nonZero;
for (auto& e : copyEdges) {//drop any zero edges (shouldn't be any by now!!!)
if (!DrawUtil::isZeroEdge(e)) {
nonZero.push_back(e);
}
}
//HLR algo does not provide all edge intersections for edge endpoints.
//need to split long edges touched by Vertex of another edge
std::vector<splitPoint> splits;
std::vector<TopoDS_Edge>::iterator itOuter = nonZero.begin();
int iOuter = 0;
for (; itOuter != nonZero.end(); ++itOuter, iOuter++) {//*** itOuter != nonZero.end() - 1
TopoDS_Vertex v1 = TopExp::FirstVertex((*itOuter));
TopoDS_Vertex v2 = TopExp::LastVertex((*itOuter));
Bnd_Box sOuter;
BRepBndLib::AddOptimal(*itOuter, sOuter);
sOuter.SetGap(0.1);
if (sOuter.IsVoid()) {
continue;
}
if (DrawUtil::isZeroEdge(*itOuter)) {
continue; //skip zero length edges. shouldn't happen ;)
}
int iInner = 0;
std::vector<TopoDS_Edge>::iterator itInner = nonZero.begin();//***sb itOuter + 1;
for (; itInner != nonZero.end(); ++itInner, iInner++) {
if (iInner == iOuter) {
continue;
}
if (DrawUtil::isZeroEdge(*itOuter)) {
continue; //skip zero length edges. shouldn't happen ;)
if (DrawUtil::isZeroEdge((*itInner))) {
continue;//skip zero length edges. shouldn't happen ;)
}
int iInner = 0;
std::vector<TopoDS_Edge>::iterator itInner = nonZero.begin();//***sb itOuter + 1;
for (; itInner != nonZero.end(); ++itInner, iInner++) {
if (iInner == iOuter) {
continue;
}
if (DrawUtil::isZeroEdge((*itInner))) {
continue;//skip zero length edges. shouldn't happen ;)
}
Bnd_Box sInner;
BRepBndLib::AddOptimal(*itInner, sInner);
sInner.SetGap(0.1);
if (sInner.IsVoid()) {
continue;
}
if (sOuter.IsOut(sInner)) {//bboxes of edges don't intersect, don't bother
continue;
}
Bnd_Box sInner;
BRepBndLib::AddOptimal(*itInner, sInner);
sInner.SetGap(0.1);
if (sInner.IsVoid()) {
continue;
}
if (sOuter.IsOut(sInner)) {//bboxes of edges don't intersect, don't bother
continue;
}
double param = -1;
if (DrawProjectSplit::isOnEdge((*itInner), v1, param, false)) {
gp_Pnt pnt1 = BRep_Tool::Pnt(v1);
splitPoint s1;
s1.i = iInner;
s1.v = Base::Vector3d(pnt1.X(), pnt1.Y(), pnt1.Z());
s1.param = param;
splits.push_back(s1);
}
if (DrawProjectSplit::isOnEdge((*itInner), v2, param, false)) {
gp_Pnt pnt2 = BRep_Tool::Pnt(v2);
splitPoint s2;
s2.i = iInner;
s2.v = Base::Vector3d(pnt2.X(), pnt2.Y(), pnt2.Z());
s2.param = param;
splits.push_back(s2);
}
}//inner loop
} //outer loop
double param = -1;
if (DrawProjectSplit::isOnEdge((*itInner), v1, param, false)) {
gp_Pnt pnt1 = BRep_Tool::Pnt(v1);
splitPoint s1;
s1.i = iInner;
s1.v = Base::Vector3d(pnt1.X(), pnt1.Y(), pnt1.Z());
s1.param = param;
splits.push_back(s1);
}
if (DrawProjectSplit::isOnEdge((*itInner), v2, param, false)) {
gp_Pnt pnt2 = BRep_Tool::Pnt(v2);
splitPoint s2;
s2.i = iInner;
s2.v = Base::Vector3d(pnt2.X(), pnt2.Y(), pnt2.Z());
s2.param = param;
splits.push_back(s2);
}
}//inner loop
} //outer loop
std::vector<splitPoint> sorted = DrawProjectSplit::sortSplits(splits, true);
auto last = std::unique(sorted.begin(), sorted.end(),
DrawProjectSplit::splitEqual);//duplicates to back
sorted.erase(last, sorted.end()); //remove dupl splits
std::vector<TopoDS_Edge> newEdges = DrawProjectSplit::splitEdges(nonZero, sorted);
std::vector<splitPoint> sorted = DrawProjectSplit::sortSplits(splits, true);
auto last = std::unique(sorted.begin(), sorted.end(),
DrawProjectSplit::splitEqual);//duplicates to back
sorted.erase(last, sorted.end()); //remove dupl splits
std::vector<TopoDS_Edge> newEdges = DrawProjectSplit::splitEdges(nonZero, sorted);
if (newEdges.empty()) {
return;
}
if (newEdges.empty()) {
return;
}
newEdges = DrawProjectSplit::removeDuplicateEdges(newEdges);
newEdges = DrawProjectSplit::removeDuplicateEdges(newEdges);
geometryObject->clearFaceGeom();
geometryObject->clearFaceGeom();
//find all the wires in the pile of faceEdges
std::vector<TopoDS_Wire> sortedWires;
EdgeWalker eWalker;
sortedWires = eWalker.execute(newEdges);
if (sortedWires.empty()) {
Base::Console().Warning(
"DVP::extractFaces - %s -Can't make faces from projected edges\n",
getNameInDocument());
return;
}
else {
std::vector<TopoDS_Wire>::iterator itWire = sortedWires.begin();
for (; itWire != sortedWires.end(); itWire++) {
//version 1: 1 wire/face - no voids in face
TechDraw::FacePtr f(std::make_shared<TechDraw::Face>());
const TopoDS_Wire& wire = (*itWire);
TechDraw::Wire* w = new TechDraw::Wire(wire);
f->wires.push_back(w);
if (geometryObject) {
geometryObject->addFaceGeom(f);
}
//find all the wires in the pile of faceEdges
std::vector<TopoDS_Wire> sortedWires;
EdgeWalker eWalker;
sortedWires = eWalker.execute(newEdges);
if (sortedWires.empty()) {
Base::Console().Warning(
"DVP::findFacesOld - %s -Can't make faces from projected edges\n",
getNameInDocument());
return;
}
else {
std::vector<TopoDS_Wire>::iterator itWire = sortedWires.begin();
for (; itWire != sortedWires.end(); itWire++) {
//version 1: 1 wire/face - no voids in face
TechDraw::FacePtr f(std::make_shared<TechDraw::Face>());
const TopoDS_Wire& wire = (*itWire);
TechDraw::Wire* w = new TechDraw::Wire(wire);
f->wires.push_back(w);
if (geometryObject) {
geometryObject->addFaceGeom(f);
}
}
}
@@ -956,7 +956,7 @@ QRectF DrawViewPart::getRect() const
}
//returns a compound of all the visible projected edges
TopoDS_Shape DrawViewPart::getShape() const
TopoDS_Shape DrawViewPart::getEdgeCompound() const
{
BRep_Builder builder;
TopoDS_Compound result;
@@ -982,17 +982,18 @@ TopoDS_Shape DrawViewPart::getShape() const
return TopoDS_Shape();
}
//returns the (unscaled) size of the visible lines along the alignment vector.
//alignment vector is already projected onto our CS, so only has X,Y components
// returns the (unscaled) size of the visible lines along the alignment vector.
// alignment vector is already projected onto our CS, so only has X,Y components
// used in calculating the length of a section line
double DrawViewPart::getSizeAlongVector(Base::Vector3d alignmentVector)
{
// Base::Console().Message("DVP::GetSizeAlongVector(%s)\n", DrawUtil::formatVector(alignmentVector).c_str());
double alignmentAngle = atan2(alignmentVector.y, alignmentVector.x) * -1.0;
gp_Ax2 OXYZ;//shape has already been projected and we will rotate around Z
if (getShape().IsNull()) {
if (getEdgeCompound().IsNull()) {
return 1.0;
}
TopoDS_Shape rotatedShape = rotateShape(getShape(), OXYZ, alignmentAngle * 180.0 / M_PI);
TopoDS_Shape rotatedShape = rotateShape(getEdgeCompound(), OXYZ, alignmentAngle * 180.0 / M_PI);
Bnd_Box shapeBox;
shapeBox.SetGap(0.0);
BRepBndLib::AddOptimal(rotatedShape, shapeBox);
@@ -1021,8 +1022,7 @@ Base::Vector3d DrawViewPart::projectPoint(const Base::Vector3d& pt, bool invert)
return result;
}
//project a loose edge onto the paper plane
//TODO:: loose edges not supported yet
//project an edge onto the paper plane
BaseGeomPtr DrawViewPart::projectEdge(const TopoDS_Edge& e) const
{
Base::Vector3d stdOrg(0.0, 0.0, 0.0);
@@ -1037,27 +1037,6 @@ BaseGeomPtr DrawViewPart::projectEdge(const TopoDS_Edge& e) const
return BaseGeom::baseFactory(TopoDS::Edge(s));
}
//simple projection of inWire with conversion of the result to TD geometry
BaseGeomPtrVector DrawViewPart::projectWire(const TopoDS_Wire& inWire) const
{
// Base::Console().Message("DVP::projectWire() - inWire.IsNull: %d\n", inWire.IsNull());
BaseGeomPtrVector result;
Base::Vector3d stdOrg(0.0, 0.0, 0.0);
TopoDS_Face paper = BRepBuilderAPI_MakeFace(gp_Pln(getProjectionCS(stdOrg)));
BRepAlgo_NormalProjection projector(paper);
projector.Add(inWire);
projector.Build();
BRepTools::Write(projector.Projection(), "DVPprojectedWire.brep");//debug
TopExp_Explorer expShape(projector.Projection(), TopAbs_EDGE);
for (; expShape.More(); expShape.Next()) {
BaseGeomPtr edge = BaseGeom::baseFactory(TopoDS::Edge(expShape.Current()));
result.push_back(edge);
}
return result;
}
bool DrawViewPart::waitingForResult() const
{
if (waitingForHlr() || waitingForFaces()) {
@@ -1170,19 +1149,6 @@ Base::Vector3d DrawViewPart::getCurrentCentroid() const
return DU::toVector3d(gCenter);
}
Base::Vector3d DrawViewPart::getLocalOrigin3d() const
{
return getCurrentCentroid();
}
Base::Vector3d DrawViewPart::getLocalOrigin2d() const
{
Base::Vector3d centroid = getCurrentCentroid();
return projectPoint(centroid, false);
}
std::vector<DrawViewSection*> DrawViewPart::getSectionRefs() const
{
std::vector<DrawViewSection*> result;
@@ -1228,6 +1194,7 @@ bool DrawViewPart::newFaceFinder(void)
//! hatches, geomhatches, dimensions, ...
void DrawViewPart::unsetupObject()
{
// Base::Console().Message("DVP::unsetupObject()\n");
nowUnsetting = true;
App::Document* doc = getDocument();
std::string docName = doc->getName();
@@ -1283,17 +1250,6 @@ void DrawViewPart::unsetupObject()
}
}
//! is this an Isometric projection?
bool DrawViewPart::isIso() const
{
Base::Vector3d dir = Direction.getValue();
if (DrawUtil::fpCompare(fabs(dir.x), fabs(dir.y))
&& DrawUtil::fpCompare(fabs(dir.x), fabs(dir.z))) {
return true;
}
return false;
}
bool DrawViewPart::checkXDirection() const
{
// Base::Console().Message("DVP::checkXDirection()\n");
@@ -1650,58 +1606,6 @@ PyObject* DrawViewPart::getPyObject()
return Py::new_reference_to(PythonObject);
}
void DrawViewPart::handleChangedPropertyName(Base::XMLReader& reader, const char* TypeName,
const char* PropName)
{
// extHandleChangedPropertyName(reader, TypeName, PropName); // CosmeticExtension
DrawView::handleChangedPropertyName(reader, TypeName, PropName);
}
bool DrawViewPart::prefHardViz()
{
return Preferences::getPreferenceGroup("HLR")->GetBool("HardViz", true);
}
bool DrawViewPart::prefSeamViz()
{
return Preferences::getPreferenceGroup("HLR")->GetBool("SeamViz", false);
}
bool DrawViewPart::prefSmoothViz()
{
return Preferences::getPreferenceGroup("HLR")->GetBool("SmoothViz", true);
}
bool DrawViewPart::prefIsoViz()
{
return Preferences::getPreferenceGroup("HLR")->GetBool("IsoViz", false);
}
bool DrawViewPart::prefHardHid()
{
return Preferences::getPreferenceGroup("HLR")->GetBool("HardHid", false);
}
bool DrawViewPart::prefSeamHid()
{
return Preferences::getPreferenceGroup("HLR")->GetBool("SeamHid", false);
}
bool DrawViewPart::prefSmoothHid()
{
return Preferences::getPreferenceGroup("HLR")->GetBool("SmoothHid", false);
}
bool DrawViewPart::prefIsoHid()
{
return Preferences::getPreferenceGroup("HLR")->GetBool("IsoHid", false);
}
int DrawViewPart::prefIsoCount()
{
return Preferences::getPreferenceGroup("HLR")->GetBool("IsoCount", false);
}
// Python Drawing feature ---------------------------------------------------------
namespace App

View File

@@ -118,10 +118,13 @@ public:
static TopoDS_Shape centerScaleRotate(DrawViewPart* dvp, TopoDS_Shape& inOutShape,
Base::Vector3d centroid);
std::vector<TechDraw::DrawHatch*> getHatches() const;
std::vector<TechDraw::DrawGeomHatch*> getGeomHatches() const;
std::vector<TechDraw::DrawViewDimension*> getDimensions() const;
std::vector<TechDraw::DrawViewBalloon*> getBalloons() const;
virtual std::vector<DrawViewSection*> getSectionRefs() const;
virtual std::vector<DrawViewDetail*> getDetailRefs() const;
const std::vector<TechDraw::VertexPtr> getVertexGeometry() const;
const BaseGeomPtrVector getEdgeGeometry() const;
@@ -135,27 +138,29 @@ public:
TechDraw::BaseGeomPtr getEdge(std::string edgeName) const;
TechDraw::FacePtr getFace(std::string faceName) const;
TechDraw::BaseGeomPtr
getGeomByIndex(int idx) const;//get existing geom for edge idx in projection
TechDraw::VertexPtr
getProjVertexByIndex(int idx) const;//get existing geom for vertex idx in projection
//get existing geom for edge idx in projection
TechDraw::BaseGeomPtr getGeomByIndex(int idx) const;
//get existing geom for vertex idx in projection
TechDraw::VertexPtr getProjVertexByIndex(int idx) const;
// get existing geom for vertex by unique tag
TechDraw::VertexPtr getProjVertexByCosTag(std::string cosTag);
std::vector<TechDraw::BaseGeomPtr>
getFaceEdgesByIndex(int idx) const;//get edges for face idx in projection
//get edges for face idx in projection
std::vector<TechDraw::BaseGeomPtr> getFaceEdgesByIndex(int idx) const;
// get the wires that define face idx
virtual std::vector<TopoDS_Wire> getWireForFace(int idx) const;
//returns a compound of all the visible projected edges
TopoDS_Shape getEdgeCompound() const;
// projected geometry measurements
virtual Base::BoundBox3d getBoundingBox() const;
double getBoxX() const;
double getBoxY() const;
QRectF getRect() const override;
virtual std::vector<DrawViewSection*>
getSectionRefs() const;//are there ViewSections based on this ViewPart?
virtual std::vector<DrawViewDetail*> getDetailRefs() const;
double getSizeAlongVector(Base::Vector3d alignmentVector);
// ancillary projection routines
virtual Base::Vector3d projectPoint(const Base::Vector3d& pt, bool invert = true) const;
virtual BaseGeomPtr projectEdge(const TopoDS_Edge& e) const;
virtual BaseGeomPtrVector projectWire(const TopoDS_Wire& inWire) const;
virtual gp_Ax2 getViewAxis(const Base::Vector3d& pt, const Base::Vector3d& direction,
const bool flip = true) const;
@@ -166,32 +171,33 @@ public:
virtual Base::Vector3d getCurrentCentroid() const;
virtual Base::Vector3d getLegacyX(const Base::Vector3d& pt, const Base::Vector3d& axis,
const bool flip = true) const;
gp_Ax2 localVectorToCS(const Base::Vector3d localUnit) const;
Base::Vector3d localVectorToDirection(const Base::Vector3d localUnit) const;
Base::Vector3d getLocalOrigin3d() const;
Base::Vector3d getLocalOrigin2d() const;
// switches
bool handleFaces();
bool newFaceFinder();
bool isUnsetting() { return nowUnsetting; }
virtual std::vector<TopoDS_Wire> getWireForFace(int idx) const;
virtual TopoDS_Shape getSourceShape() const;
virtual TopoDS_Shape getSourceShapeFused() const;
virtual std::vector<TopoDS_Shape> getSourceShape2d() const;
virtual TopoDS_Shape getSourceShape(bool fuse = false) const;
virtual TopoDS_Shape getShapeForDetail() const;
std::vector<App::DocumentObject*> getAllSources() const;
TopoDS_Shape getShape() const;
double getSizeAlongVector(Base::Vector3d alignmentVector);
// debug routines
void dumpVerts(const std::string text);
void dumpCosVerts(const std::string text);
void dumpCosEdges(const std::string text);
virtual void postHlrTasks(void);
virtual void postFaceExtractionTasks(void);
bool isIso() const;
// routines related to landmark dimensions (obs?)
std::string addReferenceVertex(Base::Vector3d v);
void addReferencesToGeom();
void removeReferenceVertex(std::string tag);
void updateReferenceVert(std::string tag, Base::Vector3d loc2d);
void removeAllReferencesFromGeom();
void resetReferenceVerts();
// routines related to cosmetic features
void clearCosmeticVertexes();
void refreshCVGeoms();
void addCosmeticVertexesToGeom();
@@ -210,25 +216,14 @@ public:
void clearGeomFormats();
void dumpVerts(const std::string text);
void dumpCosVerts(const std::string text);
void dumpCosEdges(const std::string text);
std::string addReferenceVertex(Base::Vector3d v);
void addReferencesToGeom();
void removeReferenceVertex(std::string tag);
void updateReferenceVert(std::string tag, Base::Vector3d loc2d);
void removeAllReferencesFromGeom();
void resetReferenceVerts();
std::vector<App::DocumentObject*> getAllSources() const;
// routines related to multi-threading
virtual void postHlrTasks(void);
virtual void postFaceExtractionTasks(void);
bool waitingForFaces() const { return m_waitingForFaces; }
void waitingForFaces(bool s) { m_waitingForFaces = s; }
bool waitingForHlr() const { return m_waitingForHlr; }
void waitingForHlr(bool s) { m_waitingForHlr = s; }
virtual bool waitingForResult() const;
void progressValueChanged(int v);
public Q_SLOTS:
@@ -252,28 +247,16 @@ protected:
virtual void addShapes2d(void);
void extractFaces();
void findFacesNew(const std::vector<TechDraw::BaseGeomPtr>& goEdges);
void findFacesOld(const std::vector<TechDraw::BaseGeomPtr>& goEdges);
Base::Vector3d shapeCentroid;
void getRunControl();
bool m_handleFaces;
TopoDS_Shape m_saveShape; //TODO: make this a Property. Part::TopoShapeProperty??
Base::Vector3d m_saveCentroid;//centroid before centering shape in origin
void handleChangedPropertyName(Base::XMLReader& reader, const char* TypeName,
const char* PropName) override;
bool prefHardViz();
bool prefSeamViz();
bool prefSmoothViz();
bool prefIsoViz();
bool prefHardHid();
bool prefSeamHid();
bool prefSmoothHid();
bool prefIsoHid();
int prefIsoCount();
std::vector<TechDraw::VertexPtr> m_referenceVerts;
private:

View File

@@ -85,11 +85,11 @@
#include "DrawGeomHatch.h"
#include "DrawHatch.h"
#include "DrawProjGroupItem.h"
#include "DrawUtil.h"
#include "EdgeWalker.h"
#include "GeometryObject.h"
#include "Preferences.h"
#include "DrawViewDetail.h"
#include "DrawViewSection.h"
@@ -270,6 +270,7 @@ TopoDS_Shape DrawViewSection::getShapeToCut()
App::DocumentObject *base = BaseView.getValue();
TechDraw::DrawViewPart *dvp = nullptr;
TechDraw::DrawViewSection *dvs = nullptr;
TechDraw::DrawViewDetail *dvd = nullptr;
if (!base) {
return TopoDS_Shape();
}
@@ -278,13 +279,15 @@ TopoDS_Shape DrawViewSection::getShapeToCut()
if (base->getTypeId().isDerivedFrom(TechDraw::DrawViewSection::getClassTypeId())) {
dvs = static_cast<TechDraw::DrawViewSection *>(base);
shapeToCut = dvs->getCutShape();
} else if (base->getTypeId().isDerivedFrom(TechDraw::DrawViewDetail::getClassTypeId())) {
dvd = static_cast<TechDraw::DrawViewDetail *>(base);
shapeToCut = dvd->getDetailShape();
} else if (base->getTypeId().isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId())) {
dvp = static_cast<TechDraw::DrawViewPart *>(base);
shapeToCut = dvp->getSourceShape();
if (FuseBeforeCut.getValue()) {
shapeToCut = dvp->getSourceShapeFused();
shapeToCut = dvp->getSourceShape(true);
}
} else {
Base::Console().Message("DVS::getShapeToCut - base is weird\n");
return TopoDS_Shape();
@@ -1076,16 +1079,6 @@ TechDraw::DrawViewPart* DrawViewSection::getBaseDVP() const
return nullptr;
}
TechDraw::DrawProjGroupItem* DrawViewSection::getBaseDPGI() const
{
App::DocumentObject* base = BaseView.getValue();
if (base && base->getTypeId().isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) {
TechDraw::DrawProjGroupItem* baseDPGI = static_cast<TechDraw::DrawProjGroupItem*>(base);
return baseDPGI;
}
return nullptr;
}
// setup / tear down routines
void DrawViewSection::unsetupObject()

View File

@@ -139,10 +139,8 @@ public:
Base::Vector3d getXDirection() const override;//don't use XDirection.getValue()
TechDraw::DrawViewPart* getBaseDVP() const;
TechDraw::DrawProjGroupItem* getBaseDPGI() const;
//section face related methods
TopoDS_Compound getSectionTFaces() { return m_sectionTopoDSFaces; }
std::vector<TechDraw::FacePtr> getTDFaceGeometry() { return m_tdSectionFaces; }
TopoDS_Face getSectionTopoDSFace(int i);
virtual TopoDS_Compound alignSectionFaces(TopoDS_Shape faceIntersections);