2010/3/31 Dave Cowden <dave.cow...@gmail.com> > I have committed a Wrappers file i use for everyones use in the users > contrib folder. > > Most of the code is quite rough-- I am limited in time today but wanted not > to forget to upload it. Please understand this is not production quality > code, but hopefully its good enough to determine if there's value. > > One pattern I think is particularly useful is the Edge().discretePoints. It > is a python generator, so it nicely wraps up GcPnts_QuasiUniformAbscissa > without any scoping issues, and without having to create an in memory list > to return. > > The beauty of the generator approach is that the C++ objects are stored in > a closure while the caller is retriving points. Example usage would be: > > myEdge = BRepBuilderAPI_MakeEdge(...); > > ew = Edge(myEdge); > DEFLECTION=0.1 > > for pt in ew.discretePoints(DEFLECTION): > #do whatever you want with your point. As long as you are iterating, > #GcPnts is still retained in a closure, and is destroyed when you are > done > > > Hi Dave,
Thanks for this contribution! The generator approach is very convincing and may be a good way to 'wrap the wrapper', that is to say build more pythonic classes to handle basic topologies or geometries. I would however suggest that your Point, Edge or Wire class inherit from gp_Pnt, TopoDS_Edge or TopoDS_Wire. This way, the Point/Edge/Wire instances could be passed to and processed by basic OCC classes/methods. There's a unittest, named testSubClass ( http://code.google.com/p/pythonocc/source/browse/trunk/src/unittest/occ_unittest.py) which validate this feature. Your work could then 'extend' OCC features, rather than rebuild a new wrapper from scratch. At last, we use the following convention for the high level API: - class naming use the CamelCase convention, - methods/function use the lowercase do_something() convention. This convention allows distinguishing builtin OCC methods/our high level methods. Best Regards, Thomas ========================== def testSubClass(self): ''' Checks that OCC objects can be subclassed, and passed as parameters. In this test, we create a MyPoint and MyVec class, inheriting from gp_Pnt and gp_Vec. ''' class MyPoint(gp_Pnt): def __init__(self,*kargs): gp_Pnt.__init__(self,*kargs) self.x = 4 def get_x(self): return self.x class MyVec(gp_Vec): def __init__(self,*kargs): gp_Vec.__init__(self,*kargs) self._an_attribute = "something" def get_attribute(self): return self._an_attribute # Create the first point point1 = MyPoint(1,2,3) self.assertEqual(point1.Coord(),(1.,2.,3.)) self.assertEqual(point1.get_x(),4) # Create the second point point2 = MyPoint(2,2,3) # Then create the vec from these two points # The magnitude of the vector should equal 1.0 vec = MyVec(point1,point2) self.assertEqual(vec.Magnitude(),1.) self.assertEqual(vec.get_attribute(),"something")
_______________________________________________ Pythonocc-users mailing list Pythonocc-users@gna.org https://mail.gna.org/listinfo/pythonocc-users