Skip to content

Commit

Permalink
[TD]improve handling of Assembly4 Models
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Oct 28, 2019
1 parent a8ee33a commit 3124323
Show file tree
Hide file tree
Showing 7 changed files with 302 additions and 134 deletions.
2 changes: 2 additions & 0 deletions src/Mod/TechDraw/App/CMakeLists.txt
Expand Up @@ -133,6 +133,8 @@ SET(TechDraw_SRCS
AppTechDrawPy.cpp
DrawUtil.cpp
DrawUtil.h
ShapeExtractor.cpp
ShapeExtractor.h
HatchLine.cpp
HatchLine.h
PreCompiled.cpp
Expand Down
181 changes: 50 additions & 131 deletions src/Mod/TechDraw/App/DrawViewPart.cpp
Expand Up @@ -28,47 +28,47 @@
#ifndef _PreComp_
# include <sstream>

#include <BRep_Tool.hxx>
#include <BRepGProp.hxx>
#include <Bnd_Box.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
#include <BRepBndLib.hxx>
#include <BRepBuilderAPI_Copy.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepBuilderAPI_MakeWire.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
#include <BRep_Builder.hxx>
#include <BRepExtrema_DistShapeShape.hxx>
#include <BRepGProp.hxx>
#include <BRepLib.hxx>
#include <BRepLProp_CurveTool.hxx>
#include <BRepLProp_CLProps.hxx>
#include <BRepExtrema_DistShapeShape.hxx>
# include <BRep_Builder.hxx>
#include <BRepBuilderAPI_Copy.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepBndLib.hxx>
#include <Bnd_Box.hxx>
#include <Geom_Curve.hxx>
#include <BRepLProp_CurveTool.hxx>
#include <BRep_Tool.hxx>
#include <BRepTools.hxx>
#include <GeomAPI_ProjectPointOnCurve.hxx>
#include <GProp_GProps.hxx>
#include <Geom_Curve.hxx>
#include <GeomLib_Tool.hxx>
#include <gp_Ax2.hxx>
#include <gp_Pnt.hxx>
#include <gp_Dir.hxx>
#include <gp_Pln.hxx>
#include <gp_Pnt.hxx>
#include <GProp_GProps.hxx>
#include <gp_XYZ.hxx>
#include <HLRBRep_Algo.hxx>
#include <HLRAlgo_Projector.hxx>
#include <HLRBRep_ShapeBounds.hxx>
#include <HLRBRep_Algo.hxx>
#include <HLRBRep_HLRToShape.hxx>
#include <ShapeFix_ShapeTolerance.hxx>
#include <HLRBRep_ShapeBounds.hxx>
#include <ShapeExtend_WireData.hxx>
#include <ShapeFix_ShapeTolerance.hxx>
#include <ShapeFix_Wire.hxx>
#include <TopExp_Explorer.hxx>
#include <TopExp.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Wire.hxx>

#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <GeomLib_Tool.hxx>

#endif

Expand All @@ -87,22 +87,24 @@
#include <Base/Parameter.h>
#include <Mod/Part/App/PartFeature.h>
#include <Mod/Part/App/TopoShape.h>
#include <Mod/Part/App/PropertyTopoShape.h>

#include "DrawUtil.h"
#include "DrawViewSection.h"
#include "DrawProjectSplit.h"
#include "Geometry.h"
#include "GeometryObject.h"
#include "DrawViewPart.h"
#include "DrawHatch.h"
#include "Cosmetic.h"
#include "DrawGeomHatch.h"
#include "DrawViewDimension.h"
#include "DrawHatch.h"
#include "DrawPage.h"
#include "DrawProjectSplit.h"
#include "DrawUtil.h"
#include "DrawViewBalloon.h"
#include "DrawViewDetail.h"
#include "DrawPage.h"
#include "DrawViewDimension.h"
#include "DrawViewPart.h"
#include "DrawViewSection.h"
#include "EdgeWalker.h"
#include "Geometry.h"
#include "GeometryObject.h"
#include "LineGroup.h"
#include "Cosmetic.h"
#include "ShapeExtractor.h"

#include <Mod/TechDraw/App/DrawViewPartPy.h> // generated from DrawViewPartPy.xml

Expand Down Expand Up @@ -178,108 +180,28 @@ TopoDS_Shape DrawViewPart::getSourceShape(void) const
getNameInDocument());
}
} else {
std::vector<TopoDS_Shape> sourceShapes;
for (auto& l:links) {
auto shape = Part::Feature::getShape(l);
if(!shape.IsNull())
sourceShapes.push_back(shape);
else {
std::vector<TopoDS_Shape> shapeList = getShapesFromObject(l);
sourceShapes.insert(sourceShapes.end(),shapeList.begin(),shapeList.end());
}
}

BRep_Builder builder;
TopoDS_Compound comp;
builder.MakeCompound(comp);
bool found = false;
for (auto& s:sourceShapes) {
if (s.IsNull()) {
continue; //has no shape
}
found = true;
BRepBuilderAPI_Copy BuilderCopy(s);
TopoDS_Shape shape = BuilderCopy.Shape();
builder.Add(comp, shape);
}
//it appears that an empty compound is !IsNull(), so we need to check a different way
//if we added anything to the compound.
if (!found) {
Base::Console().Error("DVP::getSourceShapes - source shape is empty!\n");
} else {
result = comp;
}
}
return result;
}

std::vector<TopoDS_Shape> DrawViewPart::getShapesFromObject(App::DocumentObject* docObj) const
{
std::vector<TopoDS_Shape> result;
App::GroupExtension* gex = dynamic_cast<App::GroupExtension*>(docObj);
App::Property* gProp = docObj->getPropertyByName("Group");
App::Property* sProp = docObj->getPropertyByName("Shape");
if (docObj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
Part::Feature* pf = static_cast<Part::Feature*>(docObj);
Part::TopoShape ts = pf->Shape.getShape();
ts.setPlacement(pf->globalPlacement());
result.push_back(ts.getShape());
} else if (gex != nullptr) { //is a group extension
std::vector<App::DocumentObject*> objs = gex->Group.getValues();
std::vector<TopoDS_Shape> shapes;
for (auto& d: objs) {
shapes = getShapesFromObject(d);
if (!shapes.empty()) {
result.insert(result.end(),shapes.begin(),shapes.end());
}
}
//the next 2 bits are mostly for Arch module objects
} else if (gProp != nullptr) { //has a Group property
App::PropertyLinkList* list = dynamic_cast<App::PropertyLinkList*>(gProp);
if (list != nullptr) {
std::vector<App::DocumentObject*> objs = list->getValues();
std::vector<TopoDS_Shape> shapes;
for (auto& d: objs) {
shapes = getShapesFromObject(d);
if (!shapes.empty()) {
result.insert(result.end(),shapes.begin(),shapes.end());
}
}
} else {
Base::Console().Log("DVP::getShapesFromObject - Group is not a PropertyLinkList!\n");
}
} else if (sProp != nullptr) { //has a Shape property
Part::PropertyPartShape* shape = dynamic_cast<Part::PropertyPartShape*>(sProp);
if (shape != nullptr) {
TopoDS_Shape occShape = shape->getValue();
result.push_back(occShape);
} else {
Base::Console().Log("DVP::getShapesFromObject - Shape is not a PropertyPartShape!\n");
}
result = ShapeExtractor::getShapes(links);
}
return result;
}

TopoDS_Shape DrawViewPart::getSourceShapeFused(void) const
{
TopoDS_Shape baseShape = getSourceShape();
if (!baseShape.IsNull()) {
TopoDS_Iterator it(baseShape);
TopoDS_Shape fusedShape = it.Value();
it.Next();
for (; it.More(); it.Next()) {
const TopoDS_Shape& aChild = it.Value();
BRepAlgoAPI_Fuse mkFuse(fusedShape, aChild);
// Let's check if the fusion has been successful
if (!mkFuse.IsDone()) {
Base::Console().Error("DVP - Fusion failed - %s\n",getNameInDocument());
return baseShape;
}
fusedShape = mkFuse.Shape();
TopoDS_Shape result;
const std::vector<App::DocumentObject*>& links = Source.getValues();
if (links.empty()) {
bool isRestoring = getDocument()->testStatus(App::Document::Status::Restoring);
if (isRestoring) {
Base::Console().Warning("DVP::getSourceShape - No Sources (but document is restoring) - %s\n",
getNameInDocument());
} else {
Base::Console().Error("Error: DVP::getSourceShape - No Source(s) linked. - %s\n",
getNameInDocument());
}
baseShape = fusedShape;
} else {
result = ShapeExtractor::getShapesFused(links);
}
return baseShape;
return result;
}

App::DocumentObjectExecReturn *DrawViewPart::execute(void)
Expand All @@ -303,7 +225,7 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
return App::DocumentObject::StdReturn;
}

TopoDS_Shape shape = getSourceShape(); //if shape is null, it is probably(?) obj creation time.
TopoDS_Shape shape = getSourceShape();
if (shape.IsNull()) {
if (isRestoring) {
Base::Console().Warning("DVP::execute - source shape is invalid - (but document is restoring) - %s\n",
Expand All @@ -319,7 +241,7 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
Base::Vector3d stdOrg(0.0,0.0,0.0);

inputCenter = TechDraw::findCentroid(shape,
getViewAxis(stdOrg,Direction.getValue()));
getViewAxis(stdOrg,Direction.getValue()));

shapeCentroid = Base::Vector3d(inputCenter.X(),inputCenter.Y(),inputCenter.Z());
TopoDS_Shape mirroredShape;
Expand Down Expand Up @@ -347,11 +269,8 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void)
}
}

//add the cosmetic vertices to the geometry vertices list
addCosmeticVertexesToGeom();
//add the cosmetic Edges to geometry Edges list
addCosmeticEdgesToGeom();
//add centerlines to geometry edges list
addCenterLinesToGeom();

auto end = std::chrono::high_resolution_clock::now();
Expand Down
5 changes: 4 additions & 1 deletion src/Mod/TechDraw/App/DrawViewPart.h
Expand Up @@ -161,9 +161,12 @@ class TechDrawExport DrawViewPart : public DrawView

gp_Pln getProjPlane(void) const;
virtual std::vector<TopoDS_Wire> getWireForFace(int idx) const;

virtual TopoDS_Shape getSourceShape(void) const;
virtual std::vector<TopoDS_Shape> getShapesFromObject(App::DocumentObject* docObj) const;
/* virtual std::vector<TopoDS_Shape> getShapesFromObject(App::DocumentObject* docObj) const; */
virtual TopoDS_Shape getSourceShapeFused(void) const;
/* std::vector<TopoDS_Shape> extractDrawableShapes(TopoDS_Shape shapeIn) const;*/

bool isIso(void) const;

virtual int addCosmeticVertex(Base::Vector3d pos);
Expand Down
2 changes: 0 additions & 2 deletions src/Mod/TechDraw/App/DrawViewSection.cpp
Expand Up @@ -265,7 +265,6 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void)
}

TopoDS_Shape rawShape = mkCut.Shape();

// BRepTools::Write(myShape, "DVSCopy.brep"); //debug
// BRepTools::Write(prism, "DVSTool.brep"); //debug
// BRepTools::Write(rawShape, "DVSResult.brep"); //debug
Expand All @@ -281,7 +280,6 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void)
m_cutShape = rawShape;
m_cutShape = TechDraw::moveShape(m_cutShape, //centre on origin
-SectionOrigin.getValue());

gp_Pnt inputCenter;
gp_Ax2 viewAxis;
try {
Expand Down
1 change: 1 addition & 0 deletions src/Mod/TechDraw/App/GeometryObject.cpp
Expand Up @@ -193,6 +193,7 @@ void GeometryObject::projectShape(const TopoDS_Shape& input,
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();
auto diff = end - start;
double diffOut = chrono::duration <double, milli> (diff).count();
Expand Down

0 comments on commit 3124323

Please sign in to comment.