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