2525from contextlib import contextmanager
2626
2727from OCC .Core .Standard import Standard_Transient
28- from OCC .Core .BRepPrimAPI import BRepPrimAPI_MakeBox
28+ from OCC .Core .Bnd import Bnd_Box
29+ from OCC .Core .BRepBndLib import brepbndlib_Add
30+ from OCC .Core .BRepPrimAPI import BRepPrimAPI_MakeBox , BRepPrimAPI_MakeSphere
2931from OCC .Core .BRepBuilderAPI import (BRepBuilderAPI_MakeVertex ,
3032 BRepBuilderAPI_MakeEdge )
3133from OCC .Core .gp import (gp_Pnt , gp_Vec , gp_Pnt2d , gp_Lin , gp_Dir , gp_Ax2 ,
3234 gp_Quaternion , gp_QuaternionSLerp , gp_XYZ , gp_Mat )
33- from OCC .Core .math import math_Matrix
35+ from OCC .Core .math import math_Matrix , math_Vector
3436from OCC .Core .GC import GC_MakeSegment
3537from OCC .Core .STEPControl import STEPControl_Writer
3638from OCC .Core .Interface import Interface_Static_SetCVal , Interface_Static_CVal
@@ -655,9 +657,10 @@ def test_in_place_operators(self):
655657 self .assertEqual (d .Z (), 9. )
656658
657659 def test_shape_conversion_as_py_none (self ):
658- # see issue #600 and PR #614
659- # a null topods_shape should be returned as Py_None by the TopoDS transformer
660- # the following test case returns a null topods_shape
660+ """ see issue #600 and PR #614
661+ a null topods_shape should be returned as Py_None by the TopoDS transformer
662+ the following test case returns a null topods_shape
663+ """
661664 box = BRepPrimAPI_MakeBox (1. , 1. , 1. ).Shape ()
662665 hlr = HLRBRep_Algo ()
663666 hlr .Add (box )
@@ -669,6 +672,33 @@ def test_shape_conversion_as_py_none(self):
669672 visible_smooth_edges = hlr_shapes .Rg1LineVCompound ()
670673 self .assertTrue (visible_smooth_edges is None )
671674
675+ def test_DumpToString (self ):
676+ """ some objects can be serialized to a string
677+ """
678+ v = math_Vector (0 , 2 )
679+ serialized_v = v .DumpToString ()
680+ # should output
681+ expected_output = 'math_Vector of Length = 3\n math_Vector(0) = 0\n math_Vector(1) = 0\n math_Vector(2) = 0\n '
682+ self .assertEqual (expected_output , serialized_v )
683+
684+ def test_DumpJsonToString (self ):
685+ """ Since opencascade 7x, some objects can be serialized to json
686+ """
687+ # create a sphere with a radius of 10.
688+ sph = BRepPrimAPI_MakeSphere (10. ).Shape ()
689+ # compute the Bnd box for this sphere
690+ bnd_box = Bnd_Box ()
691+ brepbndlib_Add (sph , bnd_box )
692+ # check the result
693+ corner_min = bnd_box .CornerMin ()
694+ self .assertEqual ([round (corner_min .X (), 3 ), round (corner_min .Y (), 3 ), round (corner_min .Z (), 3 )],
695+ [- 10. , - 10. , - 10. ])
696+ # check dump json is working
697+ json_string = bnd_box .DumpJsonToString ()
698+ expected_output = '"Bnd_Box": {"CornerMin": [-10, -10, -10], "CornerMax": [10, 10, 10], "Gap": 1e-07, "Flags": 0}'
699+ self .assertEqual (json_string , expected_output )
700+
701+
672702def suite ():
673703 test_suite = unittest .TestSuite ()
674704 test_suite .addTest (unittest .makeSuite (TestWrapperFeatures ))
0 commit comments