Section Rebuild subproject

new dialog
new Section/SectionLine logic
remove XAxisDirection property
This commit is contained in:
WandererFan
2016-10-06 15:15:09 -04:00
committed by Yorik van Havre
parent 7c740c9369
commit 6b175cc0c9
25 changed files with 1132 additions and 503 deletions

View File

@@ -30,13 +30,15 @@
#include <Bnd_Box.hxx>
#include <BRepBndLib.hxx>
#include <BRepBuilderAPI_MakePolygon.hxx>
//#include <BRepBuilderAPI_MakePolygon.hxx>
#include <BRepBuilderAPI_Copy.hxx>
#include <BRepAlgoAPI_Cut.hxx>
#include <BRepPrimAPI_MakePrism.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepAdaptor_Surface.hxx>
# include <BRep_Builder.hxx>
#include <gp_Ax2.hxx>
#include <gp_Ax3.hxx>
#include <gp_Pnt.hxx>
#include <gp_Pln.hxx>
#include <gp_Dir.hxx>
@@ -49,6 +51,7 @@
#include <TopoDS_Face.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Compound.hxx>
#include <TopExp.hxx>
#include <TopExp_Explorer.hxx>
@@ -76,6 +79,14 @@
using namespace TechDraw;
using namespace std;
const char* DrawViewSection::SectionDirEnums[]= {"Right",
"Left",
"Up",
"Down",
NULL};
//===========================================================================
// DrawViewSection
//===========================================================================
@@ -89,12 +100,14 @@ DrawViewSection::DrawViewSection()
//static const char *lgroup = "Line";
ADD_PROPERTY_TYPE(BaseView ,(0),sgroup,App::Prop_None,"2D View with SectionLine");
ADD_PROPERTY_TYPE(SectionSymbol ,("A"),sgroup,App::Prop_None,"The identifier for this section");
ADD_PROPERTY_TYPE(BaseView ,(0),sgroup,App::Prop_None,"2D View source for this Section");
ADD_PROPERTY_TYPE(SectionNormal ,(0,0,1.0) ,sgroup,App::Prop_None,"Section Plane normal direction"); //direction of extrusion of cutting prism
ADD_PROPERTY_TYPE(SectionOrigin ,(0,0,0) ,sgroup,App::Prop_None,"Section Plane Origin");
SectionDirection.setEnums(SectionDirEnums);
ADD_PROPERTY_TYPE(SectionDirection,((long)0),sgroup, App::Prop_None, "Direction in Base View for this Section");
ADD_PROPERTY_TYPE(ShowCutSurface ,(true),fgroup,App::Prop_None,"Shade the cut surface");
ADD_PROPERTY_TYPE(CutSurfaceColor,(0.0,0.0,0.0),fgroup,App::Prop_None,"The color to shade the cut surface");
ADD_PROPERTY_TYPE(HatchCutSurface ,(false),fgroup,App::Prop_None,"Hatch the cut surface");
ADD_PROPERTY_TYPE(HatchPattern ,(""),fgroup,App::Prop_None,"The hatch pattern file for the cut surface");
@@ -114,7 +127,6 @@ short DrawViewSection::mustExecute() const
if (!isRestoring()) {
result = (Scale.isTouched() ||
Direction.isTouched() ||
XAxisDirection.isTouched() ||
BaseView.isTouched() ||
SectionNormal.isTouched() ||
SectionOrigin.isTouched() );
@@ -127,8 +139,23 @@ short DrawViewSection::mustExecute() const
void DrawViewSection::onChanged(const App::Property* prop)
{
if (!isRestoring()) {
//Base::Console().Message("TRACE - DVS::onChanged(%s) - %s\n",prop->getName(),Label.getValue());
if (prop == &SectionSymbol) {
std::string lblText = "Section " +
std::string(SectionSymbol.getValue()) +
" - " +
std::string(SectionSymbol.getValue());
Label.setValue(lblText);
}
if (prop == &SectionOrigin) {
App::DocumentObject* base = BaseView.getValue();
base->touch();
}
}
DrawView::onChanged(prop);
}
App::DocumentObjectExecReturn *DrawViewSection::execute(void)
{
App::DocumentObject* link = Source.getValue();
@@ -143,8 +170,9 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void)
if (!base->getTypeId().isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId()))
return new App::DocumentObjectExecReturn("BaseView object is not a DrawViewPart object");
//Base::Console().Message("TRACE - DVS::execute() - %s/%s\n",getNameInDocument(),Label.getValue());
const Part::TopoShape &partTopo = static_cast<Part::Feature*>(link)->Shape.getShape();
//const TechDraw::DrawViewPart* dvp = static_cast<TechDraw::DrawViewPart*>(base);
if (partTopo.getShape().IsNull())
return new App::DocumentObjectExecReturn("Linked shape object is empty");
@@ -152,47 +180,25 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void)
(void) DrawView::execute(); //make sure Scale is up to date
gp_Pln pln = getSectionPlane();
// Get the Axis Directions for the Plane to transform UV components again
gp_XYZ xAxis = pln.XAxis().Direction().XYZ();
gp_XYZ yAxis = pln.YAxis().Direction().XYZ();
gp_XYZ origin = pln.Location().XYZ();
gp_Dir plnNormal = pln.Axis().Direction().XYZ();
gp_Dir gpNormal = pln.Axis().Direction();
Base::Vector3d orgPnt = SectionOrigin.getValue();
Base::BoundBox3d bb = partTopo.getBoundBox();
Base::Vector3d tmp1 = SectionOrigin.getValue();
Base::Vector3d plnPnt(tmp1.x, tmp1.y, tmp1.z);
Base::Vector3d plnNorm(plnNormal.X(), plnNormal.Y(), plnNormal.Z());
// if(!bb.IsCutPlane(plnPnt, plnNorm)) { //this test doesn't work if plane is coincident with bb!
if(!isReallyInBox(plnPnt, bb)) {
if(!isReallyInBox(orgPnt, bb)) {
Base::Console().Warning("DVS: Section Plane doesn't intersect part in %s\n",getNameInDocument());
Base::Console().Warning("DVS: Using center of bounding box.\n");
plnPnt = bb.GetCenter();
//SectionOrigin.setValue(plnPnt);
orgPnt = bb.GetCenter();
SectionOrigin.setValue(orgPnt);
}
double dMax = bb.CalcDiagonalLength();
double maxParm = dMax;
BRepBuilderAPI_MakePolygon mkPoly;
gp_Pnt pn1(origin + xAxis * maxParm + yAxis * maxParm);
gp_Pnt pn2(origin + xAxis * maxParm + yAxis * -maxParm);
gp_Pnt pn3(origin + xAxis * -maxParm + yAxis * -maxParm);
gp_Pnt pn4(origin + xAxis * -maxParm + yAxis * +maxParm);
mkPoly.Add(pn1);
mkPoly.Add(pn2);
mkPoly.Add(pn3);
mkPoly.Add(pn4);
mkPoly.Close();
// Make the extrusion face
BRepBuilderAPI_MakeFace mkFace(mkPoly.Wire());
double dMax = bb.CalcDiagonalLength();
BRepBuilderAPI_MakeFace mkFace(pln, -dMax,dMax,-dMax,dMax);
TopoDS_Face aProjFace = mkFace.Face();
if(aProjFace.IsNull())
return new App::DocumentObjectExecReturn("DrawViewSection - Projected face is NULL");
TopoDS_Shape prism = BRepPrimAPI_MakePrism(aProjFace, dMax * gp_Vec(pln.Axis().Direction()), false, true).Shape();
gp_Vec extrudeDir = dMax * gp_Vec(gpNormal);
TopoDS_Shape prism = BRepPrimAPI_MakePrism(aProjFace, extrudeDir, false, true).Shape();
// We need to copy the shape to not modify the BRepstructure
BRepBuilderAPI_Copy BuilderCopy(partTopo.getShape());
@@ -207,18 +213,17 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void)
BRepBndLib::Add(rawShape, testBox);
testBox.SetGap(0.0);
if (testBox.IsVoid()) { //prism & input don't intersect. rawShape is garbage, don't bother.
Base::Console().Log("INFO - DVS::execute - prism & input don't intersect\n");
return DrawView::execute();
}
geometryObject->setTolerance(Tolerance.getValue());
geometryObject->setScale(Scale.getValue());
Base::Vector3d validXDir = getValidXDir();
gp_Pnt inputCenter;
try {
inputCenter = TechDrawGeometry::findCentroid(rawShape,
Direction.getValue(),
validXDir);
Direction.getValue());
TopoDS_Shape mirroredShape = TechDrawGeometry::mirrorShape(rawShape,
inputCenter,
Scale.getValue());
@@ -248,8 +253,7 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void)
const TopoDS_Face& face = TopoDS::Face(expl.Current());
TopoDS_Face pFace = projectFace(face,
inputCenter,
Direction.getValue(),
validXDir);
Direction.getValue());
if (!pFace.IsNull()) {
builder.Add(newFaces,pFace);
}
@@ -270,10 +274,13 @@ gp_Pln DrawViewSection::getSectionPlane() const
{
Base::Vector3d plnPnt = SectionOrigin.getValue();
Base::Vector3d plnNorm = SectionNormal.getValue();
gp_Ax2 viewAxis = TechDrawGeometry::getViewAxis(plnPnt,plnNorm,false);
gp_Ax3 viewAxis3(viewAxis);
return gp_Pln(gp_Pnt(plnPnt.x, plnPnt.y, plnPnt.z), gp_Dir(plnNorm.x, plnNorm.y, plnNorm.z));
return gp_Pln(viewAxis3);
}
//! tries to find the intersection of the section plane with the shape giving a collection of planar faces
TopoDS_Compound DrawViewSection::findSectionPlaneIntersections(const TopoDS_Shape& shape)
{
@@ -336,22 +343,18 @@ std::vector<TechDrawGeometry::Face*> DrawViewSection::getFaceGeometry()
//! project a single face using HLR - used for section faces
TopoDS_Face DrawViewSection::projectFace(const TopoDS_Shape &face,
gp_Pnt faceCenter,
const Base::Vector3d &direction,
const Base::Vector3d &xaxis)
const Base::Vector3d &direction)
{
if(face.IsNull()) {
throw Base::Exception("DrawViewSection::projectFace - input Face is NULL");
}
gp_Ax2 transform;
transform = gp_Ax2(faceCenter,
gp_Dir(direction.x, direction.y, direction.z),
gp_Dir(xaxis.x, xaxis.y, xaxis.z));
Base::Vector3d origin(faceCenter.X(),faceCenter.Y(),faceCenter.Z());
gp_Ax2 viewAxis = TechDrawGeometry::getViewAxis(origin,direction);
HLRBRep_Algo *brep_hlr = new HLRBRep_Algo();
brep_hlr->Add(face);
HLRAlgo_Projector projector( transform );
HLRAlgo_Projector projector( viewAxis );
brep_hlr->Projector(projector);
brep_hlr->Update();
brep_hlr->Hide();