Salome HOME
Merge multi-study removal branch.
[modules/geom.git] / doc / salome / examples / complex_objs_ex07.py
1 # Creation of a PipeShellsWithoutPath
2
3 import salome
4 salome.salome_init()
5 import GEOM
6 from salome.geom import geomBuilder
7 geompy = geomBuilder.New()
8 import salome
9 gg = salome.ImportComponentGUI("GEOM")
10
11 # Add a section based on quadrangles
12 # ----------------------------------
13 def section(s, p1, p2=None, p3=None, p4=None):
14     if p2==None:
15         q = p1
16     else:
17         q = geompy.MakeQuad4Vertices(p1, p2, p3, p4)
18         pass
19     s.append(q)
20     publish(q, "section")
21     return q
22
23
24 # find distance between two points
25 # -------------------------------
26 def Dist(p1,p2):
27     c1 = geompy.PointCoordinates(p1)
28     c2 = geompy.PointCoordinates(p2)
29     return math.sqrt( (c2[0]-c1[0])*(c2[0]-c1[0]) +
30                       (c2[1]-c1[1])*(c2[1]-c1[1]) +
31                       (c2[2]-c1[2])*(c2[2]-c1[2]) )
32
33
34 # return middle point
35 # -------------------------------
36 def MiddleVert(p1,p2):
37     c1 = geompy.PointCoordinates(p1)
38     c2 = geompy.PointCoordinates(p2)
39     return geompy.MakeVertex( (c2[0]+c1[0])/2, (c2[1]+c1[1])/2, (c2[2]+c1[2])/2 )
40
41
42 # Complex section
43 # result - 16 quads from lines
44 # pnt - point from path
45 # vec - direction from path
46 def MakeComplexSect(pnt,vec,rmax,rmin,nb):
47     dang = 1.0/nb/2
48     cmax = geompy.MakeCircle(pnt,vec,rmax)
49     cmin = geompy.MakeCircle(pnt,vec,rmin)
50     faces = []
51     for i in range(0,2*nb,2):
52         p1 = geompy.MakeVertexOnCurve(cmin,dang*i)
53         p2 = geompy.MakeVertexOnCurve(cmax,dang*(i+1))
54         p3 = geompy.MakeVertexOnCurve(cmin,dang*(i+2))
55         f = geompy.MakeQuad4Vertices(pnt,p1,p2,p3)
56         faces.append(f)
57         pass
58     shell = geompy.MakeSewing(faces,1.e-6)
59     return shell
60
61
62 #=======================================================
63 #       Create simple path and recieve points
64 #              for section creation
65 #=======================================================
66 WirePath = geompy.MakeSketcher("Sketcher:F 0 0:T 60 0:T 40 0:R 0:C 100 90:",
67                                [0, 0, 0, 0, 0, 1, 1, 0, 0])
68 vs = geompy.SubShapeAll(WirePath, geompy.ShapeType["VERTEX"])
69
70 #=======================================================
71 #                 Create shell sections
72 #=======================================================
73 shells = []
74 subbases = []
75 locs = []
76
77 # 1 section
78 shell = MakeComplexSect(vs[0], geompy.MakeVectorDXDYDZ(1,0,0), 60, 40, 16)
79 shells.append(shell)
80 vs1 = geompy.SubShapeAllSortedCentres(shell,geompy.ShapeType["VERTEX"])
81 locs.append(vs1[17])
82
83 # 2 section
84 shell = MakeComplexSect(vs[1], geompy.MakeVectorDXDYDZ(1,0,0), 80, 30, 16)
85 shells.append(shell)
86 vs2 = geompy.SubShapeAllSortedCentres(shell,geompy.ShapeType["VERTEX"])
87 locs.append(vs2[17])
88
89 # 3 section
90 shell = MakeComplexSect(vs[2], geompy.MakeVectorDXDYDZ(1,0,0), 60, 40, 16)
91 shells.append(shell)
92 vs3 = geompy.SubShapeAllSortedCentres(shell,geompy.ShapeType["VERTEX"])
93 locs.append(vs3[17])
94
95 # 4 section
96 shell = MakeComplexSect(vs[3], geompy.MakeVectorDXDYDZ(0,1,0), 40, 35, 16)
97 shells.append(shell)
98 vs4 = geompy.SubShapeAllSortedCentres(shell,geompy.ShapeType["VERTEX"])
99 locs.append(vs4[17])
100
101
102 #===========================================================
103 #                   Create Pipe
104 #===========================================================
105
106 Pipe = geompy.MakePipeShellsWithoutPath(shells,locs)
107
108 # add objects in the study
109 resc = geompy.MakeCompound(shells)
110 id_sec = geompy.addToStudy(resc,"sections")
111 resl = geompy.MakeCompound(locs)
112 id_loc = geompy.addToStudy(resl,"locations")
113 id_pipe = geompy.addToStudy(Pipe, "Pipe")
114
115 # display the sections, locations and pipe
116 gg.createAndDisplayGO(id_sec)
117 gg.createAndDisplayGO(id_loc)
118 gg.createAndDisplayGO(id_pipe)
119 gg.setDisplayMode(id_pipe,1)