File tree 2 files changed +31
-7
lines changed
2 files changed +31
-7
lines changed Original file line number Diff line number Diff line change @@ -984,15 +984,24 @@ Parameter theProgress the range of progress indicator to fill in.
984
984
BRepTools::Write (shape, s);
985
985
return s.str ();}
986
986
};
987
- %feature(" autodoc" , " Deserializes TopoDS_Shape from string" ) ReadFromString;
987
+ %feature(" autodoc" , " Deserializes TopoDS_Shape from string. Create and return a new TopoDS_Shape each time the method is called. " ) ReadFromString;
988
988
%extend {
989
989
static TopoDS_Shape ReadFromString (const std::string & src) {
990
- std::stringstream s (src);
991
- TopoDS_Shape shape;
992
- BRep_Builder b;
993
- BRepTools::Read (shape, s, b);
994
- return shape;}
990
+ std::istringstream s (std::move (src));
991
+ TopoDS_Shape shape;
992
+ BRep_Builder b;
993
+ BRepTools::Read (shape, s, b);
994
+ return shape;
995
+ }
995
996
};
997
+ %feature(" autodoc" , " Deserializes TopoDS_Shape from string. Take a TopoDS_Shape instance by reference to prevent memory increase." ) ReadFromString;
998
+ %extend {
999
+ static void ReadFromString (const std::string & src, TopoDS_Shape& shape) {
1000
+ std::istringstream s (std::move (src));
1001
+ BRep_Builder b;
1002
+ BRepTools::Read (shape, s, b);
1003
+ }
1004
+ };
996
1005
};
997
1006
998
1007
Original file line number Diff line number Diff line change 48
48
BRepBuilderAPI_MakeEdge ,
49
49
BRepBuilderAPI_Sewing ,
50
50
)
51
- from OCC .Core .BRepTools import BRepTools_ShapeSet
51
+ from OCC .Core .BRepTools import BRepTools_ShapeSet , breptools
52
52
from OCC .Core .gp import (
53
53
gp_Pnt ,
54
54
gp_Vec ,
@@ -1218,3 +1218,18 @@ def test_breptools_shape_set_extensions():
1218
1218
brep_string_content = f .read ()
1219
1219
new_shape_set = BRepTools_ShapeSet ()
1220
1220
new_shape_set .ReadFromString (brep_string_content )
1221
+
1222
+
1223
+ def test_topods_readfromstring_extension ():
1224
+ box = BRepPrimAPI_MakeBox (100 , 100 , 100 ).Shape ()
1225
+ string = breptools .WriteToString (box )
1226
+
1227
+ # create a new shape each time
1228
+ for i in range (10 ):
1229
+ box1 = breptools .ReadFromString (string )
1230
+
1231
+ # same, but fill in the shape
1232
+ topods_shape = TopoDS_Shape ()
1233
+ # create a new shape each time
1234
+ for i in range (10 ):
1235
+ breptools .ReadFromString (string , topods_shape )
You can’t perform that action at this time.
0 commit comments