8 from PyQt5.QtCore import *
9 from PyQt5.QtGui import *
11 from random import randint
13 def getChildrenInStudy(obj):
15 Given an object published in SALOME study (for instance a GEOM object), retreive its children.
16 return a dictionary [name] --> object
18 SO = salome.myStudy.FindObjectIOR(salome.myStudy.ConvertObjectToIOR(obj))
19 childIterator = salome.myStudy.NewChildIterator(SO)
21 while childIterator.More():
22 childItem = childIterator.Value()
23 print("item", childItem)
24 itemName = childItem.GetName()
25 itemID = childItem.GetID()
26 itemObj = salome.IDToObject(str(itemID))
27 children[itemName] = itemObj
31 def loadImage(document, imageFile, imageName, displayLevel):
34 image = document.CreateObject(KIND_IMAGE)
35 image.SetName(imageName)
36 image.SetZLevel(displayLevel)
37 if not(image.LoadImage(imageFile)):
38 raise ValueError('problem while loading image %s'%imageFile)
42 def GeolocaliseImageCoords(image, a, b, c ,d):
45 image.SetLocalPoints(a, b)
46 image.SetGlobalPoints(1, c, d)
49 def GeolocaliseImageReference(image, imageRef, a, b, c ,d):
52 image.SetLocalPoints(a, b)
53 image.SetGlobalPoints(3, c, d)
54 image.SetTrsfReferenceImage(imageRef)
57 def importPolylines(document, shapeFile, shapeName, iSpline, displayLevel):
60 HYDROData_PolylineXY.ImportShapesFromFile(shapeFile)
61 shapeType = 0 # polyline
63 shapeType = 1 # polyline
66 print("importPolylines %s %s"%(shapeName, shapeType))
67 index = 0 # for multiple shapes
69 shapeNameIndex = shapeName + "_%d" % index
71 print("try name %s"%shapeNameIndex)
72 shape = document.FindObjectByName(shapeNameIndex)
76 print("found %s"%shapeNameIndex)
77 for i in range(shape.NbSections()):
78 shape.SetSectionType(i, shapeType)
80 shape.SetZLevel(displayLevel)
82 if index <= 1: # no multiple shapes, try single shape
83 print("try name %s"%shapeName)
84 shape = document.FindObjectByName(shapeName) # single shape
86 print("found %s"%shapeName)
87 for i in range(shape.NbSections()):
88 shape.SetSectionType(i, shapeType)
90 shape.SetZLevel(displayLevel)
94 def importBathymetry(document, bathyName, bathyPath):
97 bathy = document.CreateObject(KIND_BATHYMETRY)
98 bathy.SetName(bathyName)
99 bathy.SetAltitudesInverted(0)
100 if not(bathy.ImportFromFile( os.path.join(bathyPath, bathyName + '.xyz' ))):
101 raise ValueError('problem while loading bathymetry')
105 def createImmersibleZone(document, imzName, polyLine, bathy, isImmersible, displayLevel):
108 imz = document.CreateObject(KIND_IMMERSIBLE_ZONE)
110 imz.SetZLevel(displayLevel)
111 imz.SetAltitudeObject(bathy)
112 imz.SetPolyline(polyLine)
113 imz.SetIsSubmersible(isImmersible)
114 imz.SetFillingColor(QColor(randint(0,255), randint(0,255), randint(0,255), 255))
118 def mergePolylines(document, polyName, polyLines, isConnectedBySegment = False, tolerance = 1.E-3):
121 op=HYDROData_PolylineOperator()
122 op.Merge(document, polyName, polyLines, isConnectedBySegment, tolerance)
123 shape = document.FindObjectByName(polyName)
126 def createAxis3DDEmbankmentAltiProfile(document, axis3DName, axisXY, altiPts):
128 document: current HYDROData_Document
129 axis3DName: name to give to the axis3D created
130 axisXY: imported polyline, Embankment line
131 altiPts: list of tuples(x, h) : parametric coordinate, altitude, along the axis
132 return altiProfile, axis3D
134 altiProfile = document.CreateObject(KIND_PROFILE)
135 altiProfile.SetName("%s_altiProfile"%axis3DName)
136 altiProfilePoints = []
138 altiProfilePoints.append(gp_XY(p[0], p[1]))
139 altiProfile.SetParametricPoints(altiProfilePoints)
141 axis3D = document.CreateObject(KIND_POLYLINE)
142 axis3D.SetName(axis3DName)
143 axis3D.SetPolylineXY(axisXY)
144 axis3D.SetProfileUZ(altiProfile.GetProfileUZ())
146 return (altiProfile, axis3D)
148 def createAxis3DDEmbankmentBathy(document, axis3DName, axisXY, aCloud):
150 document: current HYDROData_Document
151 axis3DName: name to give to the axis3D created
152 axisXY: imported polyline, Embankment line
153 aCloud: altimetry, for projection of axisXY
154 return altiProfile, axis3D
156 altiProfile = document.CreateObject(KIND_PROFILE)
157 altiProfile.SetName("%s_altiProfile"%axis3DName)
158 axis3D = document.CreateObject(KIND_POLYLINE)
159 axis3D.SetName(axis3DName)
160 axis3D.SetPolylineXY(axisXY)
161 axis3D.SetAltitudeObject(aCloud)
162 axis3D.SetChildProfileUZ(altiProfile.GetProfileUZ())
165 return (altiProfile, axis3D)
167 def createEmbankmentSectionA(document, embankmentName, axis3D, sectionPoints, d, displayLevel):
169 document: current HYDROData_Document
170 embankmentName: name to give to the embankment
171 axis3D: the 3D axis of the embankment
172 sectionPoints: a list of tuple (x, h) to define a half section, beginning to x=0 (center)
173 d calculation parameter, take 2 or 3 times the section width
174 displayLevel : z level for 2D representation: high values are drawn above low values
175 return section, embankment
177 section = document.CreateObject(KIND_PROFILE)
178 section.SetName("%s_section"%embankmentName)
180 for i,p in enumerate(sectionPoints):
181 sectionPts.append(gp_XY(p[0], p[1]))
183 sectionPts.insert(0, gp_XY(-p[0], p[1]))
184 section.SetParametricPoints(sectionPts)
186 embankment = document.CreateObject(KIND_DIGUE)
187 embankment.SetName(embankmentName)
188 embankment.SetGuideLine(axis3D)
189 embankment.SetProfileMode(True)
190 embankment.SetProfile(section)
191 embankment.SetEquiDistance(d)
192 embankment.SetZLevel(displayLevel)
193 embankment.SetFillingColor(QColor(randint(0,255), randint(0,255), randint(0,255), 255))
195 return (section, embankment)
197 def createEmbankmentSectionB(document, embankmentName, axis3D, LC,DZ,CZ, d, displayLevel):
199 document: current HYDROData_Document
200 embankmentName: name to give to the embankment
201 axis3D: the 3D axis of the embankment
202 LC, DZ, CZ: width, height, height offset above axis3D
203 d calculation parameter, take 2 or 3 times the section width
204 displayLevel : z level for 2D representation: high values are drawn above low values
207 embankment = document.CreateObject(KIND_DIGUE)
208 embankment.SetName(embankmentName)
209 embankment.SetGuideLine(axis3D)
210 embankment.SetProfileMode(False)
211 embankment.SetLCValue(LC)
212 embankment.SetDeltaZValue(DZ)
213 embankment.SetCoteZValue(CZ)
214 embankment.SetEquiDistance(d)
215 embankment.SetZLevel(displayLevel)
216 embankment.SetFillingColor(QColor(randint(0,255), randint(0,255), randint(0,255), 255))