#include #include "BRepBuilderAPI_MakeSolid.hxx" #include "BRepBuilderAPI_MakeFace.hxx" #include "BRepBuilderAPI_Sewing.hxx" #include "gp_Ax3.hxx" #include "gp_Dir.hxx" #include "gp_Pln.hxx" #include "gp_Pnt.hxx" #include "TopoDS.hxx" #include "TopoDS_Face.hxx" #include "TopoDS_Shape.hxx" #include "TopoDS_Shell.hxx" #include "TopoDS_Solid.hxx" int main( int argc, char** argv ) { double length = 2.0; double width = 4.0; double height = 8.0; gp_Dir positiveXDir(1.0, 0.0, 0.0); gp_Dir positiveYDir(0.0, 1.0, 0.0); gp_Dir positiveZDir(0.0, 0.0, 1.0); gp_Dir negativeXDir(-1.0, 0.0, 0.0); gp_Dir negativeYDir(0.0, -1.0, 0.0); gp_Dir negativeZDir(0.0, 0.0, -1.0); // prepare to make top face gp_Pnt topFaceOrigin(0.0, 0.0, height / 2.0); gp_Ax3 topFaceCoordSys(topFaceOrigin, positiveZDir, positiveXDir); gp_Pln topFacePlane(topFaceCoordSys); BRepBuilderAPI_MakeFace topFaceMaker(topFacePlane, -1.0 * length / 2.0, length / 2.0, -1.0 * width / 2.0, width / 2.0); // prepare to make right face gp_Pnt rightFaceOrigin(length / 2.0, 0.0, 0.0); gp_Ax3 rightFaceCoordSys(rightFaceOrigin, positiveXDir, positiveYDir); gp_Pln rightFacePlane(rightFaceCoordSys); BRepBuilderAPI_MakeFace rightFaceMaker(rightFacePlane, -1.0 * width / 2.0, width / 2.0, -1.0 * height / 2.0, height / 2.0); // prepare to make front face gp_Pnt frontFaceOrigin(0.0, -1.0 * width / 2.0, 0.0); gp_Ax3 frontFaceCoordSys(frontFaceOrigin, negativeYDir, positiveXDir); gp_Pln frontFacePlane(frontFaceCoordSys); BRepBuilderAPI_MakeFace frontFaceMaker(frontFacePlane, -1.0 * length / 2.0, length / 2.0, -1.0 * height / 2.0, height / 2.0); // prepare to make back face gp_Pnt backFaceOrigin(0.0, width / 2.0, 0.0); gp_Ax3 backFaceCoordSys(backFaceOrigin, positiveYDir, positiveZDir); gp_Pln backFacePlane(backFaceCoordSys); BRepBuilderAPI_MakeFace backFaceMaker(backFacePlane, -1.0 * height / 2.0, height / 2.0, -1.0 * length / 2.0, length / 2.0); // prepare to make left face gp_Pnt leftFaceOrigin(-1.0 * length / 2.0, 0.0, 0.0); gp_Ax3 leftFaceCoordSys(leftFaceOrigin, negativeXDir, positiveZDir); gp_Pln leftFacePlane(leftFaceCoordSys); BRepBuilderAPI_MakeFace leftFaceMaker(leftFacePlane, -1.0 * height / 2.0, height / 2.0, -1.0 * width / 2.0, width / 2.0); // prepare to make bottom face gp_Pnt bottomFaceOrigin(0.0, 0.0, -1.0 * height / 2.0); gp_Ax3 bottomFaceCoordSys(bottomFaceOrigin, negativeZDir, positiveYDir); gp_Pln bottomFacePlane(bottomFaceCoordSys); BRepBuilderAPI_MakeFace bottomFaceMaker(bottomFacePlane, -1.0 * width / 2.0, width / 2.0, -1.0 * length / 2.0, length / 2.0); BRepBuilderAPI_Sewing boxSewImp; boxSewImp.Add(topFaceMaker.Face()); boxSewImp.Add(rightFaceMaker.Face()); boxSewImp.Add(frontFaceMaker.Face()); boxSewImp.Add(backFaceMaker.Face()); boxSewImp.Add(leftFaceMaker.Face()); boxSewImp.Add(bottomFaceMaker.Face()); boxSewImp.Perform(); TopoDS_Shape boxShellShape = boxSewImp.SewedShape(); TopoDS_Shell boxShell = TopoDS::Shell(boxShellShape); BRepBuilderAPI_MakeSolid boxMaker(boxShell); TopoDS_Solid box = boxMaker.Solid(); return 0; }