Hi,
I've added a "Context.py" file on SVN, in the Utils folder.
The idea here is to use python 2.5 `with` statement, for checking
whether an operation IsDone() or it raises an AssertionError, printing
a specified error message.
In the case presented below, when the Vertex would not build
succesfully, it would raise the AssertionError, with the "vertex not
build" statement.
Since this is such a dominant pattern in pythonOCC, I think its best
to facilitate it. I see that often I ignore the pattern since its such
a bore to add a try / except loop, which is really a bad idea. Using
the with assert_isdone its easy to do this in a really clean manner.
Cheers,
-jelle
class assert_isdone(object):
def __init__(self, to_check, error_statement):
self.to_check = to_check
self.error_statement = error_statement
def __enter__(self, ):
if self.to_check.IsDone():
print 'done!'
pass
else:
raise AssertionError, self.error_statement
def __exit__(self, type, value, traceback):
pass
pnt = gp_Pnt()
bpnt = BRepBuilderAPI_MakeVertex(pnt)
with assert_isdone(bpnt, 'vertex not build'):
bpnt.Vertex()
_______________________________________________
Pythonocc-users mailing list
Pythonocc-users@gna.org
https://mail.gna.org/listinfo/pythonocc-users