How to convert TopoDS_Shape to TopoDS_Wire????

Hi All,

Can anyone please tell me how to convert a TopoDS_Shape to a TopoDS_Wire?
My code goes like this:

TopoDS_Shape res1=TopoDS::Wire(W1);
TopoDS_Shape res2=TopoDS::Wire(W2);
TopoDS_Shape S1=BRepAlgoAPI_Cut(res2,res1);

Now the obtained shape S1 should be converted to wire so as to offset the resultant wire.

Paul Jimenez's picture

TopoDS_Wire S1_wire = TopoDS::Wire(S1);


TopoDS_Wire S1_wire = static_cast(S1); // only if you are completely sure it IS a wire

Actually, if W1 and W2 in your example are Wires, you can assign them directly to TopoDS_Shape. As a matter of fact, calling TopoDS::Wire with a Wire makes no sense (cast a Wire to a Wire).

SINDHU's picture

Thank you Paul,
I already tried the 1st part

TopoDS_Wire W=TopoDS::Wire(S1);

but it didn't work. It doesn't give any compilation errors but the program breaks when it executes that statement. Even in the OCC Documentation for TopoDS they have mention a line "Types are verified, thus in the example below, the first two blocks are correct but the third is rejected by the compiler." So, I was confused and want to make clear if the breakdown is due to the fault of the function or is there any other way to do that. Can you please tell me why the program breaks at that statement. My code is as follows:

TopoDS_Shape res1=TopoDS::Wire(W1);
Handle(AIS_Shape) ais1=new AIS_Shape(res1); //wire code
const gp_Pnt P9(-1,0,-1),P10(1,0,-1),P11(1,0,-2),P12(-1,0,-2);
BRepBuilderAPI_MakeEdge E9(P9,P10),E10(P10,P11),E11(P11,P12),E12(P12,P9);
BRepBuilderAPI_MakeWire W2(E9);W2.Add(E10);W2.Add(E11);W2.Add(E12);
TopoDS_Shape res2=TopoDS::Wire(W2);
Handle(AIS_Shape) ais3=new AIS_Shape(res2); //wire code
TopoDS_Shape S1=BRepAlgoAPI_Cut(res1,res2);
Handle(AIS_Shape) ais4=new AIS_Shape(S1); //wire code
TopoDS_Wire W=TopoDS::Wire(S1);

I want to convert the obtained shape to wire inorder to offset it. But the program breaks when the statement
TopoDS_Wire W=TopoDS::Wire(S1);
is executed.

I didn't try the second one. I'll try it.

Thanks a lot

SINDHU's picture


When I tried the second one it worked. The shape 'S1' was converted to wire 'W' but when I tried to offset the obtained wire. The program breaks...

TopoDS_Wire W=static_cast(S1);
const GeomAbs_JoinType Join=GeomAbs_Arc;
Standard_Real dist2 = -0.5;
BRepOffsetAPI_MakeOffset off(W,GeomAbs_Arc);
off.Perform(dist2); // program breaks at this point
TopoDS_Shape S= off.Shape();
Handle(AIS_Shape) ais2=new AIS_Shape(S);

And also when I carry out the Boolean operation CUT.
TopoDS_Shape S1=BRepAlgoAPI_Cut(res1,res2);
The shape 'res1' which is a wire is displayed.
if the statement is
TopoDS_Shape S1=BRepAlgoAPI_Cut(res1,res2);
the shape 'res2' which is a wire is displayed.

Because it is a wire, it doesn't have an area so it displays the wire which is the 1st parameter. But can we in anyway be able to cut the wires and display the resultant wire obtained ie., the combination of both the wires 'res1' and 'res2'.

Paul Jimenez's picture

Well, it looks like S1 is not really a Wire. Chances are S1 is a Compound with a Wire inside, so you would have to explore the Compound and extract the Wire(s) from it. You may want to check the value of S1.ShapeType() to be sure of what it really is.