bool IfcGeom::Kernel::convert(const IfcSchema::IfcExtrudedAreaSolid* l, TopoDS_Shape& shape) { const double height = l->Depth() * getValue(GV_LENGTH_UNIT); if (height < getValue(GV_PRECISION)) { Logger::Message(Logger::LOG_ERROR, "Non-positive extrusion height encountered for:", l->entity); return false; } TopoDS_Shape face; if ( !convert_face(l->SweptArea(),face) ) return false; gp_Trsf trsf; IfcGeom::Kernel::convert(l->Position(),trsf); gp_Dir dir; convert(l->ExtrudedDirection(),dir); shape.Nullify(); if (face.ShapeType() == TopAbs_COMPOUND) { // For compounds (most likely the result of a IfcCompositeProfileDef) // create a compound solid shape. TopExp_Explorer exp(face, TopAbs_FACE); TopoDS_CompSolid compound; BRep_Builder builder; builder.MakeCompSolid(compound); int num_faces_extruded = 0; for (; exp.More(); exp.Next(), ++num_faces_extruded) { builder.Add(compound, BRepPrimAPI_MakePrism(exp.Current(), height*dir)); } if (num_faces_extruded) { shape = compound; } } if (shape.IsNull()) { shape = BRepPrimAPI_MakePrism(face, height*dir); } // IfcSweptAreaSolid.Position (trsf) is an IfcAxis2Placement3D // and therefore has a unit scale factor shape.Move(trsf); return ! shape.IsNull(); }
bool IfcGeom::Kernel::convert(const IfcSchema::IfcPolygonalBoundedHalfSpace* l, TopoDS_Shape& shape) { TopoDS_Shape halfspace; if ( ! IfcGeom::Kernel::convert((IfcSchema::IfcHalfSpaceSolid*)l,halfspace) ) return false; TopoDS_Wire wire; if ( ! convert_wire(l->PolygonalBoundary(),wire) || ! wire.Closed() ) return false; gp_Trsf trsf; if ( ! convert(l->Position(),trsf) ) return false; TColgp_SequenceOfPnt points; if (wire_to_sequence_of_point(wire, points)) { remove_duplicate_points_from_loop(points, wire.Closed()); // Note: wire always closed, as per if statement above remove_collinear_points_from_loop(points, wire.Closed()); sequence_of_point_to_wire(points, wire, wire.Closed()); } TopoDS_Shape prism = BRepPrimAPI_MakePrism(BRepBuilderAPI_MakeFace(wire),gp_Vec(0,0,200)); gp_Trsf down; down.SetTranslation(gp_Vec(0,0,-100.0)); // `trsf` and `down` both have a unit scale factor prism.Move(trsf*down); shape = BRepAlgoAPI_Common(halfspace,prism); return true; }
bool IfcGeom::Kernel::convert(const IfcSchema::IfcExtrudedAreaSolid* l, TopoDS_Shape& shape) { TopoDS_Shape face; if ( !convert_face(l->SweptArea(),face) ) return false; const double height = l->Depth() * getValue(GV_LENGTH_UNIT); gp_Trsf trsf; IfcGeom::Kernel::convert(l->Position(),trsf); gp_Dir dir; convert(l->ExtrudedDirection(),dir); shape.Nullify(); if (face.ShapeType() == TopAbs_COMPOUND) { // For compounds (most likely the result of a IfcCompositeProfileDef) // create a compound solid shape. TopExp_Explorer exp(face, TopAbs_FACE); TopoDS_CompSolid compound; BRep_Builder builder; builder.MakeCompSolid(compound); int num_faces_extruded = 0; for (; exp.More(); exp.Next(), ++num_faces_extruded) { builder.Add(compound, BRepPrimAPI_MakePrism(exp.Current(), height*dir)); } if (num_faces_extruded) { shape = compound; } } if (shape.IsNull()) { shape = BRepPrimAPI_MakePrism(face, height*dir); } shape.Move(trsf); return ! shape.IsNull(); }
TopoDS_Shape OCCPartFactory::makeCube( const Standard_Real width, const Standard_Real height, const Standard_Real depth) { // define points gp_Pnt pt1( -width / 2.0, 0.0, 0.0 ); gp_Pnt pt2( -width / 2.0, -depth / 2.0, 0.0 ); gp_Pnt pt3( width / 2.0, -depth / 2.0, 0.0 ); gp_Pnt pt4( width /2.0, 0.0, 0.0 ); // define segments Handle_Geom_TrimmedCurve seg1 = GC_MakeSegment( pt1, pt2 ); Handle_Geom_TrimmedCurve seg2 = GC_MakeSegment( pt2, pt3 ); Handle_Geom_TrimmedCurve seg3 = GC_MakeSegment( pt3, pt4 ); // make edge TopoDS_Edge edge1 = BRepBuilderAPI_MakeEdge( seg1 ); TopoDS_Edge edge2 = BRepBuilderAPI_MakeEdge( seg2 ); TopoDS_Edge edge3 = BRepBuilderAPI_MakeEdge( seg3 ); // make wire TopoDS_Wire wire1 = BRepBuilderAPI_MakeWire( edge1, edge2, edge3 ); //Complete Profile gp_Ax1 xAxis = gp::OX(); gp_Trsf transfer; transfer.SetMirror( xAxis ); BRepBuilderAPI_Transform aBRepTrsf( wire1 , transfer ); TopoDS_Shape mirroredShape = aBRepTrsf.Shape(); TopoDS_Wire mirroredWire1 = TopoDS::Wire( mirroredShape ); BRepBuilderAPI_MakeWire mkWire; mkWire.Add( wire1 ); mkWire.Add( mirroredWire1 ); TopoDS_Wire wireProfile = mkWire.Wire(); //Body : Prism the Profile TopoDS_Face faceProfile = BRepBuilderAPI_MakeFace( wireProfile ); gp_Vec prismVec( 0.0 , 0.0 , height ); TopoDS_Shape cube = BRepPrimAPI_MakePrism( faceProfile, prismVec); // cube.setMaterial( Graphic3d_NOM_JADE ); // Handle_AIS_Shape shape = new AIS_Shape( cube ); // shape->SetColor( Quantity_NOC_RED ); // return shape; return cube; }
bool IfcGeom::Kernel::convert(const IfcSchema::IfcPolygonalBoundedHalfSpace* l, TopoDS_Shape& shape) { TopoDS_Shape halfspace; if ( ! IfcGeom::Kernel::convert((IfcSchema::IfcHalfSpaceSolid*)l,halfspace) ) return false; TopoDS_Wire wire; if ( ! convert_wire(l->PolygonalBoundary(),wire) || ! wire.Closed() ) return false; gp_Trsf trsf; convert(l->Position(),trsf); TopoDS_Shape prism = BRepPrimAPI_MakePrism(BRepBuilderAPI_MakeFace(wire),gp_Vec(0,0,200)); gp_Trsf down; down.SetTranslation(gp_Vec(0,0,-100.0)); prism.Move(trsf*down); shape = BRepAlgoAPI_Common(halfspace,prism); return true; }
void occQt::makeExtrude() { // prism a vertex result is an edge. TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(gp_Pnt(0.0, 60.0, 0.0)); TopoDS_Shape aPrismVertex = BRepPrimAPI_MakePrism(aVertex, gp_Vec(0.0, 0.0, 5.0)); Handle_AIS_Shape anAisPrismVertex = new AIS_Shape(aPrismVertex); // prism an edge result is a face. TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(5.0, 60.0, 0.0), gp_Pnt(10.0, 60.0, 0.0)); TopoDS_Shape aPrismEdge = BRepPrimAPI_MakePrism(anEdge, gp_Vec(0.0, 0.0, 5.0)); Handle_AIS_Shape anAisPrismEdge = new AIS_Shape(aPrismEdge); // prism a wire result is a shell. gp_Ax2 anAxis; anAxis.SetLocation(gp_Pnt(16.0, 60.0, 0.0)); TopoDS_Edge aCircleEdge = BRepBuilderAPI_MakeEdge(gp_Circ(anAxis, 3.0)); TopoDS_Wire aCircleWire = BRepBuilderAPI_MakeWire(aCircleEdge); TopoDS_Shape aPrismCircle = BRepPrimAPI_MakePrism(aCircleWire, gp_Vec(0.0, 0.0, 5.0)); Handle_AIS_Shape anAisPrismCircle = new AIS_Shape(aPrismCircle); // prism a face or a shell result is a solid. anAxis.SetLocation(gp_Pnt(24.0, 60.0, 0.0)); TopoDS_Edge aEllipseEdge = BRepBuilderAPI_MakeEdge(gp_Elips(anAxis, 3.0, 2.0)); TopoDS_Wire aEllipseWire = BRepBuilderAPI_MakeWire(aEllipseEdge); TopoDS_Face aEllipseFace = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY()), aEllipseWire); TopoDS_Shape aPrismEllipse = BRepPrimAPI_MakePrism(aEllipseFace, gp_Vec(0.0, 0.0, 5.0)); Handle_AIS_Shape anAisPrismEllipse = new AIS_Shape(aPrismEllipse); anAisPrismVertex->SetColor(Quantity_NOC_PAPAYAWHIP); anAisPrismEdge->SetColor(Quantity_NOC_PEACHPUFF); anAisPrismCircle->SetColor(Quantity_NOC_PERU); anAisPrismEllipse->SetColor(Quantity_NOC_PINK); mContext->Display(anAisPrismVertex); mContext->Display(anAisPrismEdge); mContext->Display(anAisPrismCircle); mContext->Display(anAisPrismEllipse); }
bool IfcGeom::Kernel::convert(const IfcSchema::IfcSurfaceOfLinearExtrusion* l, TopoDS_Shape& shape) { TopoDS_Wire wire; if ( !convert_wire(l->SweptCurve(), wire) ) { TopoDS_Face face; if ( !convert_face(l->SweptCurve(),face) ) return false; TopExp_Explorer exp(face, TopAbs_WIRE); wire = TopoDS::Wire(exp.Current()); } const double height = l->Depth() * getValue(GV_LENGTH_UNIT); gp_Trsf trsf; IfcGeom::Kernel::convert(l->Position(),trsf); gp_Dir dir; convert(l->ExtrudedDirection(),dir); shape = BRepPrimAPI_MakePrism(wire, height*dir); shape.Move(trsf); return !shape.IsNull(); }
void Werkstuck::BulkForm(float Xmin, float Ymin, float Zmin, float Xmax, float Ymax, float Zmax) { Xstart=Xmax+10; //начальное положение инструмента Ystart=Ymax+10; // за заготовкой Zstart=Zmax+10; Xwz=Xstart; Ywz=Ystart; Zwz=Zstart; H0=Zmax; Xfmin=Xmin; Xfmax=Xmax; Yfmin=Ymin; Yfmax=Ymax; gp_Pnt punkt1(Xmin, Ymin, Zmin); gp_Pnt punkt2(Xmin, Ymax, Zmin); gp_Pnt punkt3(Xmax, Ymax, Zmin); gp_Pnt punkt4(Xmax, Ymin, Zmin); Handle(Geom_TrimmedCurve) aSeg1 = GC_MakeSegment(punkt1 , punkt2); Handle(Geom_TrimmedCurve) aSeg2 = GC_MakeSegment(punkt2 , punkt3); Handle(Geom_TrimmedCurve) aSeg3 = GC_MakeSegment(punkt3 , punkt4); Handle(Geom_TrimmedCurve) aSeg4 = GC_MakeSegment(punkt4 , punkt1); TopoDS_Edge aEdge1 = BRepBuilderAPI_MakeEdge(aSeg1); TopoDS_Edge aEdge2 = BRepBuilderAPI_MakeEdge(aSeg2); TopoDS_Edge aEdge3 = BRepBuilderAPI_MakeEdge(aSeg3); TopoDS_Edge aEdge4 = BRepBuilderAPI_MakeEdge(aSeg4); TopoDS_Wire Basis = BRepBuilderAPI_MakeWire(aEdge1 , aEdge2 , aEdge3, aEdge4); TopoDS_Face FlacheBasis = BRepBuilderAPI_MakeFace(Basis); gp_Vec PrismVec(0 , 0 , Zmax-Zmin); TopoDS_Shape sBulkForm = BRepPrimAPI_MakePrism(FlacheBasis , PrismVec); WS = sBulkForm; //Erst_weg = true; }
TopoDS_Shape MakeBottle(const Standard_Real myWidth, const Standard_Real myHeight, const Standard_Real myThickness) { BRepBuilderAPI_MakeWire wireMaker; // Profile : Define Support Points { Handle(TColgp_HArray1OfPnt) gp_array = new TColgp_HArray1OfPnt(1, 4); gp_Pnt p0(-myWidth / 2., 0, 0); gp_Pnt p4(myWidth / 2., 0, 0); // gp_array->SetValue(0, p0); gp_array->SetValue(1, gp_Pnt(-myWidth / 2., -myThickness / 4., 0)); gp_array->SetValue(2, gp_Pnt(0, -myThickness / 2., 0)); gp_array->SetValue(3, gp_Pnt(myWidth / 2., -myThickness / 4., 0)); gp_array->SetValue(4, p4); GeomAPI_Interpolate sp(gp_array, true, 1.0e-3); sp.Perform(); wireMaker.Add(BRepBuilderAPI_MakeEdge(sp.Curve())); } // Body : Prism the Profile TopoDS_Face myFaceProfile = BRepBuilderAPI_MakeFace(wireMaker.Wire()); gp_Vec aPrismVec(0, 0, myHeight); TopoDS_Shape myBody = BRepPrimAPI_MakePrism(myFaceProfile, aPrismVec); // Building the Resulting Compound TopoDS_Compound aRes; BRep_Builder aBuilder; aBuilder.MakeCompound(aRes); aBuilder.Add(aRes, myBody); // aBuilder.Add(aRes, myThreading); return aRes; }
//======================================================================= //function : Execute //purpose : //======================================================================= Standard_Integer GEOMImpl_PrismDriver::Execute(TFunction_Logbook& log) const { if (Label().IsNull()) return 0; Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); GEOMImpl_IPrism aCI (aFunction); Standard_Integer aType = aFunction->GetType(); TopoDS_Shape aShape; if (aType == PRISM_BASE_VEC_H || aType == PRISM_BASE_VEC_H_2WAYS) { Handle(GEOM_Function) aRefBase = aCI.GetBase(); Handle(GEOM_Function) aRefVector = aCI.GetVector(); TopoDS_Shape aShapeBase = aRefBase->GetValue(); TopoDS_Shape aShapeVec = aRefVector->GetValue(); if (aShapeVec.ShapeType() == TopAbs_EDGE) { TopoDS_Edge anE = TopoDS::Edge(aShapeVec); TopoDS_Vertex V1, V2; TopExp::Vertices(anE, V1, V2, Standard_True); if (!V1.IsNull() && !V2.IsNull()) { gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2)); if (Abs(aCI.GetH()) < Precision::Confusion()) { Standard_ConstructionError::Raise("Absolute value of prism height is too small"); } if (aV.Magnitude() > Precision::Confusion()) { aV.Normalize(); if (aType != PRISM_BASE_DXDYDZ_2WAYS && aCI.GetScale() > Precision::Confusion()) { aShape = MakeScaledPrism(aShapeBase, aV * aCI.GetH(), aCI.GetScale()); } else { if (aType == PRISM_BASE_VEC_H_2WAYS) { gp_Trsf aTrsf; aTrsf.SetTranslation( (-aV) * aCI.GetH() ); BRepBuilderAPI_Transform aTransformation(aShapeBase, aTrsf, Standard_False); aShapeBase = aTransformation.Shape(); aCI.SetH( aCI.GetH()*2 ); } aShape = BRepPrimAPI_MakePrism(aShapeBase, aV * aCI.GetH(), Standard_False).Shape(); } } } } } else if (aType == PRISM_BASE_TWO_PNT || aType == PRISM_BASE_TWO_PNT_2WAYS) { Handle(GEOM_Function) aRefBase = aCI.GetBase(); Handle(GEOM_Function) aRefPnt1 = aCI.GetFirstPoint(); Handle(GEOM_Function) aRefPnt2 = aCI.GetLastPoint(); TopoDS_Shape aShapeBase = aRefBase->GetValue(); TopoDS_Shape aShapePnt1 = aRefPnt1->GetValue(); TopoDS_Shape aShapePnt2 = aRefPnt2->GetValue(); if (aShapePnt1.ShapeType() == TopAbs_VERTEX && aShapePnt2.ShapeType() == TopAbs_VERTEX) { TopoDS_Vertex V1 = TopoDS::Vertex(aShapePnt1); TopoDS_Vertex V2 = TopoDS::Vertex(aShapePnt2); if (!V1.IsNull() && !V2.IsNull()) { gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2)); if (aV.Magnitude() > gp::Resolution()) { if (aType != PRISM_BASE_DXDYDZ_2WAYS && aCI.GetScale() > Precision::Confusion()) { aShape = MakeScaledPrism(aShapeBase, aV, aCI.GetScale()); } else { if (aType == PRISM_BASE_TWO_PNT_2WAYS) { gp_Trsf aTrsf; aTrsf.SetTranslation(-aV); BRepBuilderAPI_Transform aTransformation(aShapeBase, aTrsf, Standard_False); aShapeBase = aTransformation.Shape(); aV = aV * 2; } aShape = BRepPrimAPI_MakePrism(aShapeBase, aV, Standard_False).Shape(); } } } } } else if (aType == PRISM_BASE_VEC_H_ANG) { Handle(GEOM_Function) aRefBase = aCI.GetBase(); Handle(GEOM_Function) aRefVector = aCI.GetVector(); TopoDS_Shape aShapeBase = aRefBase->GetValue(); TopoDS_Shape aShapeVec = aRefVector->GetValue(); if (aShapeVec.ShapeType() == TopAbs_EDGE) { TopoDS_Edge anE = TopoDS::Edge(aShapeVec); TopoDS_Vertex V1, V2; TopExp::Vertices(anE, V1, V2, Standard_True); if (!V1.IsNull() && !V2.IsNull()) { gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2)); if (Abs(aCI.GetH()) < Precision::Confusion()) { Standard_ConstructionError::Raise("Absolute value of prism height is too small"); } if (aV.Magnitude() > Precision::Confusion()) { aV.Normalize(); TopAbs_ShapeEnum myBaseType = aShapeBase.ShapeType(); if ( (myBaseType != TopAbs_EDGE) && (myBaseType != TopAbs_WIRE) && (myBaseType != TopAbs_FACE) && (myBaseType != TopAbs_SHELL) ) Standard_ConstructionError::Raise("Base shape type is not of the requested type"); if (myBaseType == TopAbs_EDGE) aShapeBase = BRepBuilderAPI_MakeWire(TopoDS::Edge(aShapeBase)); BRepOffsetAPI_MakeDraft aDraft(aShapeBase, aV, aCI.GetAngle()); if (aCI.GetAngle() < 0.) aDraft.SetDraft(Standard_True); aDraft.Perform(aCI.GetH()); aShape = aDraft.Shape(); } } } } else if (aType == PRISM_BASE_DXDYDZ || aType == PRISM_BASE_DXDYDZ_2WAYS) { Handle(GEOM_Function) aRefBase = aCI.GetBase(); TopoDS_Shape aShapeBase = aRefBase->GetValue(); gp_Vec aV (aCI.GetDX(), aCI.GetDY(), aCI.GetDZ()); if (aV.Magnitude() > gp::Resolution()) { if (aType != PRISM_BASE_DXDYDZ_2WAYS && aCI.GetScale() > Precision::Confusion()) { aShape = MakeScaledPrism(aShapeBase, aV, aCI.GetScale()); } else { if (aType == PRISM_BASE_DXDYDZ_2WAYS) { gp_Trsf aTrsf; aTrsf.SetTranslation(-aV); BRepBuilderAPI_Transform aTransformation(aShapeBase, aTrsf, Standard_False); aShapeBase = aTransformation.Shape(); aV = aV * 2; } aShape = BRepPrimAPI_MakePrism(aShapeBase, aV, Standard_False).Shape(); } } } if (aShape.IsNull()) return 0; TopoDS_Shape aRes = GEOMImpl_IShapesOperations::CompsolidToCompound(aShape); aFunction->SetValue(aRes); log.SetTouched(Label()); return 1; }
void Werkstuck::LY(float endPunkt, float Rwz, float Lwz, float Rwz2) // прямое фрезерование по оси Х // endPunkt - конечная точка { if (Zwz<H0) { gp_Pnt punkt1(Xwz-Rwz,Ywz,Zwz); gp_Pnt punkt2(Xwz+Rwz,Ywz,Zwz); gp_Pnt punkt3(Xwz+Rwz,endPunkt,Zwz); gp_Pnt punkt4(Xwz,endPunkt,Zwz); if (endPunkt>=Ywz) punkt4.SetY(endPunkt+Rwz); else punkt4.SetY(endPunkt-Rwz); gp_Pnt punkt5(Xwz-Rwz,endPunkt,Zwz); Handle(Geom_TrimmedCurve) aSeg1 = GC_MakeSegment(punkt1 , punkt2); Handle(Geom_TrimmedCurve) aSeg2 = GC_MakeSegment(punkt2 , punkt3); Handle(Geom_TrimmedCurve) aSeg3 = GC_MakeArcOfCircle(punkt3,punkt4 ,punkt5); Handle(Geom_TrimmedCurve) aSeg4 = GC_MakeSegment(punkt5 , punkt1); TopoDS_Edge aEdge1 = BRepBuilderAPI_MakeEdge(aSeg1); TopoDS_Edge aEdge2 = BRepBuilderAPI_MakeEdge(aSeg2); TopoDS_Edge aEdge3 = BRepBuilderAPI_MakeEdge(aSeg3); TopoDS_Edge aEdge4 = BRepBuilderAPI_MakeEdge(aSeg4); TopoDS_Wire Basis = BRepBuilderAPI_MakeWire(aEdge1 , aEdge2 , aEdge3, aEdge4); TopoDS_Face FlacheBasis = BRepBuilderAPI_MakeFace(Basis); if (firstRun) { fBasis = FlacheBasis; firstRun = false; } else { fBasis = BRepAlgo_Fuse(fBasis, FlacheBasis); gp_Vec PrismVec(0 , 0 , Lwz); TopoDS_Shape sLY = BRepPrimAPI_MakePrism(fBasis , PrismVec); if (Rwz2>0) { BRepFilletAPI_MakeFillet mkFillet(sLY); TopExp_Explorer aEdgeExplorer(sLY , TopAbs_EDGE); while(aEdgeExplorer.More()) { TopoDS_Edge aEdge = TopoDS::Edge(aEdgeExplorer.Current()); mkFillet.Add(Rwz2 , aEdge); aEdgeExplorer.Next(); } sLY = mkFillet.Shape(); } WS = BRepAlgo_Cut(WS,sLY); firstRun = true; } /*gp_Vec PrismVec(0 , 0 , Lwz); TopoDS_Shape sLY = BRepPrimAPI_MakePrism(FlacheBasis , PrismVec); if (Rwz2>0) { BRepFilletAPI_MakeFillet mkFillet(sLY); TopExp_Explorer aEdgeExplorer(sLY , TopAbs_EDGE); while(aEdgeExplorer.More()){ TopoDS_Edge aEdge = TopoDS::Edge(aEdgeExplorer.Current()); mkFillet.Add(Rwz2 , aEdge); aEdgeExplorer.Next(); } sLY = mkFillet.Shape(); } WS = BRepAlgo_Cut(WS,sLY);*/ } Ywz=endPunkt; }
TopoDS_Shape MakeBottle(const Standard_Real myWidth, const Standard_Real myHeight, const Standard_Real myThickness) { // Profile : Define Support Points gp_Pnt aPnt1(-myWidth / 2., 0, 0); gp_Pnt aPnt2(-myWidth / 2., -myThickness / 4., 0); gp_Pnt aPnt3(0, -myThickness / 2., 0); gp_Pnt aPnt4(myWidth / 2., -myThickness / 4., 0); gp_Pnt aPnt5(myWidth / 2., 0, 0); // Profile : Define the Geometry Handle(Geom_TrimmedCurve) anArcOfCircle = GC_MakeArcOfCircle(aPnt2,aPnt3,aPnt4); Handle(Geom_TrimmedCurve) aSegment1 = GC_MakeSegment(aPnt1, aPnt2); Handle(Geom_TrimmedCurve) aSegment2 = GC_MakeSegment(aPnt4, aPnt5); // Profile : Define the Topology TopoDS_Edge anEdge1 = BRepBuilderAPI_MakeEdge(aSegment1); TopoDS_Edge anEdge2 = BRepBuilderAPI_MakeEdge(anArcOfCircle); TopoDS_Edge anEdge3 = BRepBuilderAPI_MakeEdge(aSegment2); TopoDS_Wire aWire = BRepBuilderAPI_MakeWire(anEdge1, anEdge2, anEdge3); // Complete Profile gp_Ax1 xAxis = gp::OX(); gp_Trsf aTrsf; aTrsf.SetMirror(xAxis); BRepBuilderAPI_Transform aBRepTrsf(aWire, aTrsf); TopoDS_Shape aMirroredShape = aBRepTrsf.Shape(); TopoDS_Wire aMirroredWire = TopoDS::Wire(aMirroredShape); BRepBuilderAPI_MakeWire mkWire; mkWire.Add(aWire); mkWire.Add(aMirroredWire); TopoDS_Wire myWireProfile = mkWire.Wire(); // Body : Prism the Profile TopoDS_Face myFaceProfile = BRepBuilderAPI_MakeFace(myWireProfile); gp_Vec aPrismVec(0, 0, myHeight); TopoDS_Shape myBody = BRepPrimAPI_MakePrism(myFaceProfile, aPrismVec); // Body : Apply Fillets BRepFilletAPI_MakeFillet mkFillet(myBody); TopExp_Explorer anEdgeExplorer(myBody, TopAbs_EDGE); while(anEdgeExplorer.More()) { TopoDS_Edge anEdge = TopoDS::Edge(anEdgeExplorer.Current()); //Add edge to fillet algorithm mkFillet.Add(myThickness / 12., anEdge); anEdgeExplorer.Next(); } myBody = mkFillet.Shape(); // Body : Add the Neck gp_Pnt neckLocation(0, 0, myHeight); gp_Dir neckAxis = gp::DZ(); gp_Ax2 neckAx2(neckLocation, neckAxis); Standard_Real myNeckRadius = myThickness / 4.; Standard_Real myNeckHeight = myHeight / 10.; BRepPrimAPI_MakeCylinder MKCylinder(neckAx2, myNeckRadius, myNeckHeight); TopoDS_Shape myNeck = MKCylinder.Shape(); myBody = BRepAlgoAPI_Fuse(myBody, myNeck); // Body : Create a Hollowed Solid TopoDS_Face faceToRemove; Standard_Real zMax = -1; for(TopExp_Explorer aFaceExplorer(myBody, TopAbs_FACE); aFaceExplorer.More(); aFaceExplorer.Next()) { TopoDS_Face aFace = TopoDS::Face(aFaceExplorer.Current()); // Check if <aFace> is the top face of the bottle�s neck Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace); if(aSurface->DynamicType() == STANDARD_TYPE(Geom_Plane)) { Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurface); gp_Pnt aPnt = aPlane->Location(); Standard_Real aZ = aPnt.Z(); if(aZ > zMax) { zMax = aZ; faceToRemove = aFace; } } } TopTools_ListOfShape facesToRemove; facesToRemove.Append(faceToRemove); myBody = BRepOffsetAPI_MakeThickSolid(myBody, facesToRemove, -myThickness / 50, 1.e-3); // Threading : Create Surfaces Handle(Geom_CylindricalSurface) aCyl1 = new Geom_CylindricalSurface(neckAx2, myNeckRadius * 0.99); Handle(Geom_CylindricalSurface) aCyl2 = new Geom_CylindricalSurface(neckAx2, myNeckRadius * 1.05); // Threading : Define 2D Curves gp_Pnt2d aPnt(2. * M_PI, myNeckHeight / 2.); gp_Dir2d aDir(2. * M_PI, myNeckHeight / 4.); gp_Ax2d anAx2d(aPnt, aDir); Standard_Real aMajor = 2. * M_PI; Standard_Real aMinor = myNeckHeight / 10; Handle(Geom2d_Ellipse) anEllipse1 = new Geom2d_Ellipse(anAx2d, aMajor, aMinor); Handle(Geom2d_Ellipse) anEllipse2 = new Geom2d_Ellipse(anAx2d, aMajor, aMinor / 4); Handle(Geom2d_TrimmedCurve) anArc1 = new Geom2d_TrimmedCurve(anEllipse1, 0, M_PI); Handle(Geom2d_TrimmedCurve) anArc2 = new Geom2d_TrimmedCurve(anEllipse2, 0, M_PI); gp_Pnt2d anEllipsePnt1 = anEllipse1->Value(0); gp_Pnt2d anEllipsePnt2 = anEllipse1->Value(M_PI); Handle(Geom2d_TrimmedCurve) aSegment = GCE2d_MakeSegment(anEllipsePnt1, anEllipsePnt2); // Threading : Build Edges and Wires TopoDS_Edge anEdge1OnSurf1 = BRepBuilderAPI_MakeEdge(anArc1, aCyl1); TopoDS_Edge anEdge2OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment, aCyl1); TopoDS_Edge anEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(anArc2, aCyl2); TopoDS_Edge anEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment, aCyl2); TopoDS_Wire threadingWire1 = BRepBuilderAPI_MakeWire(anEdge1OnSurf1, anEdge2OnSurf1); TopoDS_Wire threadingWire2 = BRepBuilderAPI_MakeWire(anEdge1OnSurf2, anEdge2OnSurf2); BRepLib::BuildCurves3d(threadingWire1); BRepLib::BuildCurves3d(threadingWire2); // Create Threading BRepOffsetAPI_ThruSections aTool(Standard_True); aTool.AddWire(threadingWire1); aTool.AddWire(threadingWire2); aTool.CheckCompatibility(Standard_False); TopoDS_Shape myThreading = aTool.Shape(); // Building the Resulting Compound TopoDS_Compound aRes; BRep_Builder aBuilder; aBuilder.MakeCompound (aRes); aBuilder.Add (aRes, myBody); aBuilder.Add (aRes, myThreading); return aRes; }