PageRenderTime 13ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/src/examples/Level2/XMLRPC/geometry_server.py

http://pythonocc.googlecode.com/
Python | 76 lines | 44 code | 12 blank | 20 comment | 2 complexity | 1400ee81dfb52d98358f273a784d3c3a MD5 | raw file
 1#!/usr/bin/env python
 2
 3##Copyright 2009-2011 Thomas Paviot (tpaviot@gmail.com)
 4##
 5##This file is part of pythonOCC.
 6##
 7##pythonOCC is free software: you can redistribute it and/or modify
 8##it under the terms of the GNU Lesser General Public License as published by
 9##the Free Software Foundation, either version 3 of the License, or
10##(at your option) any later version.
11##
12##pythonOCC is distributed in the hope that it will be useful,
13##but WITHOUT ANY WARRANTY; without even the implied warranty of
14##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15##GNU Lesser General Public License for more details.
16##
17##You should have received a copy of the GNU Lesser General Public License
18##along with pythonOCC.  If not, see <http://www.gnu.org/licenses/>.
19
20import SimpleXMLRPCServer
21from OCC.BRepPrimAPI import *
22from OCC.TopoDS import *
23from OCC.gp import *
24from OCC.Geom import *
25from OCC.GeomAPI import *
26from OCC.TColgp import *
27from OCC.BRepBuilderAPI import *
28import pickle
29# Creating XMLRPC server
30server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8888))
31
32def point_list_to_TColgp_Array1OfPnt(li):
33    pts = TColgp_Array1OfPnt(0, len(li)-1)
34    for n,i in enumerate(li):
35        pts.SetValue(n,i)
36    return pts
37
38def make_face(shape):
39    face = BRepBuilderAPI_MakeFace(shape)
40    face.Build()
41    return face.Shape()
42
43class ShapeFactory(object):
44    def getBox(self, x,y,z):
45        print 'Box creation (%f,%f,%f)'%(x,y,z)
46        shape = BRepPrimAPI_MakeBox(x,y,z).Shape()
47        return pickle.dumps(shape)
48    
49    def getSphere(self, radius):
50        print 'Sphere creation of radius %f'%radius
51        shape = BRepPrimAPI_MakeSphere(radius).Shape()
52        return pickle.dumps(shape)
53
54    def getSurfaceFromRevolution(self):
55        print 'Surface of revolution created'
56
57        array = []
58        array.append(gp_Pnt(0,0,1))                                         
59        
60        array.append(gp_Pnt(1,2,2))                                         
61        array.append(gp_Pnt(2,3,3))                                         
62        array.append(gp_Pnt(4,3,4))                                         
63        array.append(gp_Pnt(5,5,5))                                         
64        aCurve = GeomAPI_PointsToBSpline(point_list_to_TColgp_Array1OfPnt(array)).Curve()
65        
66        SOR =Geom_SurfaceOfRevolution(aCurve, gp.gp().OX())
67        
68        shape = make_face(SOR.GetHandle())
69        return pickle.dumps(shape)
70    
71# Creating object to share
72shape_factory = ShapeFactory()
73server.register_instance(shape_factory)
74#Go into the main listener loop
75print "Listening on port 8888"
76server.serve_forever()