Not valid shape error

Dear all,
I'm trying to build a simple face which is a quarter of a cylinder,
but when I check the validity of the face I always get that it is not valid,
the error seems to be related to pCurves on edges.
I compute pCurves by using the method ShapeFix_Edge::FixAddPCurve because this is only a simple test but I will have more complicated faces to build and I won't be always able to directly assign pCurves.
I started from an example by Roman Lygin taken from his blog which builds a cylinder.

Here is my code

TopoDS_Shape OCCBShape::CreateCylinderFace()
const Standard_Real aR = 10.; //radius
const Standard_Real aZ = 20; //heigth

//axis placements
gp_Ax2 aBAx (gp::XOY());
gp_Ax2 aTAx (gp_Pnt (0, 0, aZ), gp::DZ(), gp::DX());

Handle(Geom_Plane) aBPlane = new Geom_Plane (aBAx);
Handle(Geom_Plane) aTPlane = new Geom_Plane (aTAx);
Handle(Geom_CylindricalSurface) aCSurf = new Geom_CylindricalSurface (aBAx, aR);

//3D curves
Handle(Geom_Circle) aBCirc = new Geom_Circle (aBAx, aR);
Handle(Geom_Circle) aTCirc = new Geom_Circle (aTAx, aR);
gp_Pnt aBPnt (aR, 0, 0);

BRep_Builder aBuilder;

gp_Pnt p1 = gp_Pnt(aR,0,0);
gp_Pnt p2 = gp_Pnt(0,aR,0);
gp_Pnt p3 = gp_Pnt(0,aR,aZ);
gp_Pnt p4 = gp_Pnt(aR,0,aZ);

Handle(Geom_Line) aLine = new Geom_Line (p2, gp::DZ());
Handle(Geom_Line) aLine2 = new Geom_Line (p1, gp::DZ());

TopoDS_Vertex p1V;
aBuilder.MakeVertex (p1V, p1, Precision::Confusion());
TopoDS_Vertex p2V;
aBuilder.MakeVertex (p2V, p2, Precision::Confusion());
TopoDS_Vertex p3V;
aBuilder.MakeVertex (p3V, p3, Precision::Confusion());
TopoDS_Vertex p4V;
aBuilder.MakeVertex (p4V, p4, Precision::Confusion());

TopoDS_Edge aBEdge = BRepBuilderAPI_MakeEdge (aBCirc, p1V, p2V); //arc of circle
TopoDS_Edge aTEdge = BRepBuilderAPI_MakeEdge (aTCirc, p4V, p3V); //arc of circle
TopoDS_Edge aLEdge = BRepBuilderAPI_MakeEdge (aLine, p2V, p3V);
TopoDS_Edge aLEdge2 = BRepBuilderAPI_MakeEdge (aLine2, p1V, p4V);

TopoDS_Wire aCWire;
aBuilder.MakeWire (aCWire);
aBuilder.Add (aCWire, aBEdge);
aBuilder.Add (aCWire, aLEdge);
aBuilder.Add (aCWire, aTEdge.Reversed());
aBuilder.Add (aCWire, aLEdge2.Reversed());

TopoDS_Face aCFace;
aBuilder.MakeFace (aCFace, aCSurf, Precision::Confusion());
aBuilder.Add (aCFace, aCWire);

ShapeFix_Edge fixEdge = ShapeFix_Edge();
Standard_Boolean bAdded = fixEdge.FixAddPCurve(aBEdge,aCFace,Standard_False);

TopoDS_Shell aShell;
aBuilder.MakeShell (aShell);
aBuilder.Add (aShell, aCFace);

BRepCheck_Analyzer shapeChecker(aShell);
if (!shapeChecker.IsValid()){
cout }
return aShell;

Do you have any idea or simple example I could start from?
Thank you very much for your attention.


raviarya's picture
Silvia's picture

Thank you Ravi,
I'll study carefully these examples.

Anyway, for this particular problem I've found a solution, I'll write it here in case it may be useful for someone else.

After using fixEdge.FixAddPCurve, you have to run also FixSameParameter() indeed this was the reason why the shape was not valid.
Adding this fix in the above code returns a valid shape.