here's the code:
#include "occ_header.h"
int main(int argc, char *argv[]) {
TopoDS_Solid aBox;
TopoDS_Edge anEdge;
TopoDS_Vertex Vertex1,Vertex2;
Standard_Real Length=1, Width=1, Depth=1;
TopTools_IndexedMapOfShape edgeMap;
TopTools_IndexedMapOfShape vertexMap;
// create a box
aBox = BRepPrimAPI_MakeBox(Length,Width,Depth);
BRepTools::Write(aBox,"aBox.brep");
// asign an edge to split
TopExp::MapShapes(aBox,TopAbs_EDGE,edgeMap);
anEdge= TopoDS::Edge(edgeMap(1));
// find the end point of this edge
TopExp::MapShapes(anEdge, TopAbs_VERTEX, vertexMap);
Vertex1=TopoDS::Vertex(vertexMap(1));
Vertex2=TopoDS::Vertex(vertexMap(2));
// assign u=Param to split
Standard_Real First,Last,Param;
const Handle(Geom_Curve)& Curve=BRep_Tool::Curve(anEdge,First,Last);
cout << " First= " << First << " Last= " << Last << " \n";
Param = (Last-First)*0.5;
// create two new edges by spliting the original edge
TopoDS_Edge edge1 = BRepBuilderAPI_MakeEdge(Curve,First,Param);
TopoDS_Edge edge2 = BRepBuilderAPI_MakeEdge(Curve,Param,Last);
// create a wire to add these two edges
BRepBuilderAPI_MakeWire wire;
wire.Add(edge1);
wire.Add(edge2);
// replace edge with wire
BRepTools_ReShape *reshaper = new BRepTools_ReShape;
reshaper->Replace(anEdge,wire.Wire());
TopoDS_Shape aBox2=reshaper->Apply(aBox);
BRepTools::Write(aBox2,"aBox2.brep");
return 0;
}