378 lines
7.9 KiB
C++
378 lines
7.9 KiB
C++
|
#include "OCCCabin.h"
|
||
|
#include "Stdafx.h"
|
||
|
#include <stdio.h>
|
||
|
//#include <io.h> /pj
|
||
|
#include <fcntl.h>
|
||
|
#include "TopoDS_Shape.hxx"
|
||
|
#include "BRepBuilderAPI_MakeFace.hxx"
|
||
|
#include "TopoDS.hxx"
|
||
|
#include "TopExp_Explorer.hxx"
|
||
|
#include "BRep_Builder.hxx"
|
||
|
#include "BRepTools_ShapeSet.hxx"
|
||
|
#include "BRepAlgoAPI_Section.hxx"
|
||
|
#include "TopoDS_Face.hxx"
|
||
|
#include "TopoDS_Shell.hxx"
|
||
|
#include "BRepExtrema_DistShapeShape.hxx"
|
||
|
#include "TopoDS_Vertex.hxx"
|
||
|
#include "BRep_Tool.hxx"
|
||
|
#include "BRepBuilderAPI_MakeVertex.hxx"
|
||
|
#include "TopoDS_Compound.hxx"
|
||
|
#include "TopoDS_Edge.hxx"
|
||
|
#include "Hermit.hxx"
|
||
|
#include "Geom_Curve.hxx"
|
||
|
|
||
|
//#include "Handle_Standard_OutOfRange.hxx" //XUEFENG DELETE 202009
|
||
|
|
||
|
#include "Geom2d_BSplineCurve.hxx"
|
||
|
#include "Geom_BSplineCurve.hxx"
|
||
|
#include "GeomConvert.hxx"
|
||
|
#include "BRepTools.hxx"
|
||
|
#include "BRepBuilderAPI_MakeEdge.hxx"
|
||
|
#include "Geom_TrimmedCurve.hxx"
|
||
|
#include <BRepBndLib.hxx>
|
||
|
//#include "BRepAdaptor_HCurve2d.hxx" // NOT EXIST in 7.6.0
|
||
|
//#include "GeomAdaptor_HSurface.hxx" // NOT EXIST in 7.6.0
|
||
|
#include "Adaptor3d_CurveOnSurface.hxx"
|
||
|
#include "ShapeConstruct_ProjectCurveOnSurface.hxx"
|
||
|
#include "TopTools_IndexedMapOfShape.hxx"
|
||
|
|
||
|
//#include "BOPTools_Tools.hxx" //XUEFENG DELETE 202009
|
||
|
//#include "BOPTools_Tools2D.hxx" //XUEFENG DELETE 202009
|
||
|
|
||
|
#include "CutSurfaceAlgo.h"
|
||
|
#include "Standard_OStream.hxx"
|
||
|
#include "BRepTools.hxx"
|
||
|
#include "Standard_IStream.hxx"
|
||
|
#include "GeomConvert.hxx"
|
||
|
#include "Hermit.hxx"
|
||
|
#include "TopoDS_Solid.hxx"
|
||
|
#include "GeomProjLib.hxx"
|
||
|
#include "BRepOffsetAPI_Sewing.hxx"
|
||
|
#include "CutSolidAlgo.h"
|
||
|
#include "BRepPrimAPI_MakeHalfSpace.hxx"
|
||
|
#include "OCCLib.h"
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
OCCCabin::OCCCabin(void)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
OCCCabin::~OCCCabin(void)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
OCCCabin::OCCCabin(TopoDS_Shape sld, TopoDS_Shape front, TopoDS_Shape back, TopoDS_Shape splitFace, gp_Pnt cutPoint)
|
||
|
{
|
||
|
Init(sld, front, back, splitFace, cutPoint);
|
||
|
}
|
||
|
|
||
|
bool OCCCabin::Init(TopoDS_Shape sld, TopoDS_Shape front, TopoDS_Shape back, TopoDS_Shape splitFace, gp_Pnt cutPoint)
|
||
|
{
|
||
|
this->sld = sld;
|
||
|
this->frontFace = front;
|
||
|
this->backFace = back;
|
||
|
this->splitFace = splitFace;
|
||
|
this->cutPoint = cutPoint;
|
||
|
this->isDone = false;
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
TopoDS_Shape OCCCabin::SplitSolidByFront(TopoDS_Shape solid)
|
||
|
{
|
||
|
BRep_Builder b;
|
||
|
TopoDS_Compound c;
|
||
|
b.MakeCompound(c);
|
||
|
|
||
|
gp_Pnt p(10000, 0, 0);
|
||
|
|
||
|
for(TopExp_Explorer ex(solid, TopAbs_SOLID);ex.More(); ex.Next())
|
||
|
{
|
||
|
CutSolidAlgo cutSolid(TopoDS::Solid(ex.Current()), this->frontFace);
|
||
|
cutSolid.SetCutPoint(p);
|
||
|
cutSolid.Perform();
|
||
|
|
||
|
TopoDS_Shape S = cutSolid.GetResult();
|
||
|
|
||
|
for(TopExp_Explorer ex1(S, TopAbs_SOLID); ex1.More(); ex1.Next())
|
||
|
{
|
||
|
b.Add(c, TopoDS::Solid(ex1.Current()));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return c;
|
||
|
}
|
||
|
|
||
|
TopoDS_Shape OCCCabin::SplitSolidByBack(TopoDS_Shape solid)
|
||
|
{
|
||
|
BRep_Builder b;
|
||
|
TopoDS_Compound c;
|
||
|
b.MakeCompound(c);
|
||
|
|
||
|
gp_Pnt p(-10000, 0, 0);
|
||
|
|
||
|
for(TopExp_Explorer ex(solid, TopAbs_SOLID);ex.More(); ex.Next())
|
||
|
{
|
||
|
CutSolidAlgo cutSolid(TopoDS::Solid(ex.Current()), this->backFace);
|
||
|
cutSolid.SetCutPoint(p);
|
||
|
cutSolid.Perform();
|
||
|
|
||
|
TopoDS_Shape S = cutSolid.GetResult();
|
||
|
|
||
|
for(TopExp_Explorer ex1(S, TopAbs_SOLID); ex1.More(); ex1.Next())
|
||
|
{
|
||
|
b.Add(c, TopoDS::Solid(ex1.Current()));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return c;
|
||
|
}
|
||
|
|
||
|
TopoDS_Shape OCCCabin::SplitSolidByFront_bool(TopoDS_Shape solid)
|
||
|
{
|
||
|
BRep_Builder b;
|
||
|
TopoDS_Shape c;
|
||
|
BaseAlgo algo;
|
||
|
|
||
|
gp_Pnt p(10000, 0, 0);
|
||
|
|
||
|
TopAbs_ShapeEnum type=this->frontFace.ShapeType();
|
||
|
BRepPrimAPI_MakeHalfSpace MHS(TopoDS::Face(frontFace), p);
|
||
|
TopoDS_Solid sld1=MHS.Solid();
|
||
|
|
||
|
TopoDS_Compound sld2;
|
||
|
b.MakeCompound(sld2);
|
||
|
|
||
|
for(TopExp_Explorer ex(solid, TopAbs_SOLID); ex.More();ex.Next())
|
||
|
{
|
||
|
TopoDS_Solid sld = TopoDS::Solid(ex.Current());
|
||
|
|
||
|
if(algo.IsReversed(sld))
|
||
|
{
|
||
|
sld.Reverse();
|
||
|
}
|
||
|
b.Add(sld2,sld);
|
||
|
}
|
||
|
|
||
|
BRepAlgoAPI_Common newcut(sld1 ,sld2);
|
||
|
if(!newcut.IsDone())
|
||
|
{
|
||
|
return c;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
c = newcut.Shape();
|
||
|
}
|
||
|
|
||
|
return c;
|
||
|
}
|
||
|
|
||
|
TopoDS_Shape OCCCabin::SplitSolidByBack_bool(TopoDS_Shape solid)
|
||
|
{
|
||
|
BRep_Builder b;
|
||
|
TopoDS_Shape c;
|
||
|
BaseAlgo algo;
|
||
|
gp_Pnt p(-10000, 0, 0);
|
||
|
|
||
|
TopAbs_ShapeEnum type=this->backFace.ShapeType();
|
||
|
BRepPrimAPI_MakeHalfSpace MHS(TopoDS::Face(backFace), p);
|
||
|
TopoDS_Solid sld1=MHS.Solid();
|
||
|
|
||
|
TopoDS_Compound sld2;
|
||
|
b.MakeCompound(sld2);
|
||
|
|
||
|
for(TopExp_Explorer ex(solid, TopAbs_SOLID); ex.More();ex.Next())
|
||
|
{
|
||
|
TopoDS_Solid sld = TopoDS::Solid(ex.Current());
|
||
|
|
||
|
if(algo.IsReversed(sld))
|
||
|
{
|
||
|
sld.Reverse();
|
||
|
}
|
||
|
b.Add(sld2,sld);
|
||
|
}
|
||
|
|
||
|
BRepAlgoAPI_Common newcut(sld1 ,sld2);
|
||
|
if(!newcut.IsDone())
|
||
|
{
|
||
|
return c;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
c =newcut.Shape();
|
||
|
}
|
||
|
|
||
|
return c;
|
||
|
}
|
||
|
|
||
|
TopoDS_Shape OCCCabin::SplitSolid_bool(TopoDS_Shape solid, TopoDS_Shape shell, gp_Pnt cPoint)
|
||
|
{
|
||
|
BRep_Builder b;
|
||
|
TopoDS_Shape c;
|
||
|
BaseAlgo algo;
|
||
|
TopoDS_Solid sld1 = this->sld3;
|
||
|
|
||
|
if(algo.IsReversed(sld1))
|
||
|
{
|
||
|
sld1.Reverse();
|
||
|
}
|
||
|
|
||
|
TopoDS_Compound sld_cut;
|
||
|
b.MakeCompound(sld_cut);
|
||
|
|
||
|
for(TopExp_Explorer ex(solid, TopAbs_SOLID); ex.More();ex.Next())
|
||
|
{
|
||
|
TopoDS_Solid sld = TopoDS::Solid(ex.Current());
|
||
|
|
||
|
if(algo.IsReversed(sld))
|
||
|
{
|
||
|
sld.Reverse();
|
||
|
}
|
||
|
BRepAlgoAPI_Common newcut(sld1 ,sld);
|
||
|
if(!newcut.IsDone())
|
||
|
{
|
||
|
//return c;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
b.Add(sld_cut,newcut.Shape());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return sld_cut;
|
||
|
}
|
||
|
|
||
|
TopoDS_Shape OCCCabin::SplitSolid(TopoDS_Shape solid, TopoDS_Shape shell, gp_Pnt cPoint)
|
||
|
{
|
||
|
BRep_Builder b;
|
||
|
TopoDS_Compound c;
|
||
|
b.MakeCompound(c);
|
||
|
|
||
|
|
||
|
for(TopExp_Explorer ex(solid, TopAbs_SOLID);ex.More(); ex.Next())
|
||
|
{
|
||
|
CutSolidAlgo cutSolid(TopoDS::Solid(ex.Current()), shell);
|
||
|
cutSolid.SetCutPoint(cPoint);
|
||
|
//cutSolid.flag = 1;
|
||
|
cutSolid.Perform();
|
||
|
|
||
|
TopoDS_Shape S = cutSolid.GetResult();
|
||
|
|
||
|
for(TopExp_Explorer ex1(S, TopAbs_SOLID); ex1.More(); ex1.Next())
|
||
|
{
|
||
|
b.Add(c, TopoDS::Solid(ex1.Current()));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return c;
|
||
|
}
|
||
|
|
||
|
void OCCCabin::Build()
|
||
|
{
|
||
|
isDone = true;
|
||
|
TopoDS_Shape TopoShape;
|
||
|
//TopoShape = SplitSolidByBack_bool(this->sld);
|
||
|
//this->result = TopoShape;
|
||
|
////return;
|
||
|
//TopoShape = SplitSolidByFront_bool(TopoShape);
|
||
|
//this->result = TopoShape;
|
||
|
////return;
|
||
|
|
||
|
BaseAlgo algo;
|
||
|
if(algo.IsReversed(this->sld3))
|
||
|
{
|
||
|
this->sld3.Reverse();
|
||
|
}
|
||
|
if(algo.IsReversed(this->sld2))
|
||
|
{
|
||
|
this->sld2.Reverse();
|
||
|
}
|
||
|
if(algo.IsReversed(this->sld))
|
||
|
{
|
||
|
this->sld.Reverse();
|
||
|
}
|
||
|
//this->result = s;
|
||
|
//return;
|
||
|
BRepAlgoAPI_Common com(this->sld, this->sld2);
|
||
|
if(!com.IsDone())
|
||
|
{
|
||
|
TopoDS_Compound c;
|
||
|
BRep_Builder b;
|
||
|
b.MakeCompound(c);
|
||
|
b.Add(c, sld);
|
||
|
b.Add(c,sld2);
|
||
|
//BRepTools::Write(c, "C://solidbool.brep");
|
||
|
return;
|
||
|
}
|
||
|
TopoShape = com.Shape();
|
||
|
this->result = TopoShape;
|
||
|
return;
|
||
|
try
|
||
|
{
|
||
|
if(!this->splitFace.IsNull())
|
||
|
{
|
||
|
TopoShape = SplitSolid_bool(TopoShape, this->splitFace, this->cutPoint);
|
||
|
}
|
||
|
}
|
||
|
catch(int e)
|
||
|
{
|
||
|
//TopoShape = SplitSolid1(TopoShape, this->splitFace, this->cutPoint);
|
||
|
return;
|
||
|
}
|
||
|
catch(TopoDS_Shape s)
|
||
|
{
|
||
|
//TopoShape = SplitSolid1(TopoShape, this->splitFace, this->cutPoint);
|
||
|
this->result = s;
|
||
|
return ;
|
||
|
}
|
||
|
this->result = TopoShape;
|
||
|
|
||
|
}
|
||
|
|
||
|
TopoDS_Shape OCCCabin::GetResult()
|
||
|
{
|
||
|
TopoDS_Shape TopoShape;
|
||
|
if(isDone)
|
||
|
{
|
||
|
return this->result;
|
||
|
}
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
void OCCCabin::SetSecondSolid(TopoDS_Solid solid)
|
||
|
{
|
||
|
this->sld2 = solid;
|
||
|
}
|
||
|
|
||
|
void OCCCabin::SetThirdSolid(TopoDS_Solid solid)
|
||
|
{
|
||
|
this->sld3 = solid;
|
||
|
}
|
||
|
|
||
|
TopoDS_Solid OCCCabin::CreateSecondSolid()
|
||
|
{
|
||
|
TopoDS_Face f1,f2,f3,f4,f5,f6;
|
||
|
vector<TopoDS_Shape> faceSet;
|
||
|
OCCLib lib;
|
||
|
f1 = lib.CreateFaceByPoints(gp_Pnt(40,5,3),gp_Pnt(40,-5,3),gp_Pnt(45,-5,3),gp_Pnt(45,5,3));
|
||
|
f2 = lib.CreateFaceByPoints(gp_Pnt(40,-5,3),gp_Pnt(40,-5,-3),gp_Pnt(45,-5,-3),gp_Pnt(45,-5,3));
|
||
|
f3 = lib.CreateFaceByPoints(gp_Pnt(40,-5,-3),gp_Pnt(40,5,-3),gp_Pnt(45,5,-3),gp_Pnt(45,-5,-3));
|
||
|
f4 = lib.CreateFaceByPoints(gp_Pnt(40,5,-3),gp_Pnt(40,5,3),gp_Pnt(45,5,3),gp_Pnt(45,5,-3));
|
||
|
f5 = lib.CreateFaceByPoints(gp_Pnt(40,5,3),gp_Pnt(40,-5,3),gp_Pnt(40,-5,-3),gp_Pnt(40,5,-3));
|
||
|
f6 = lib.CreateFaceByPoints(gp_Pnt(45,5,3),gp_Pnt(45,-5,3),gp_Pnt(45,-5,-3),gp_Pnt(45,5,-3));
|
||
|
|
||
|
faceSet.push_back(f1);
|
||
|
faceSet.push_back(f2);
|
||
|
faceSet.push_back(f3);
|
||
|
faceSet.push_back(f4);
|
||
|
faceSet.push_back(f5);
|
||
|
faceSet.push_back(f6);
|
||
|
|
||
|
TopoDS_Shell shell = lib.SewShell(faceSet);
|
||
|
return BRepBuilderAPI_MakeSolid(shell);
|
||
|
}
|
||
|
|