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 shape = document.FindObjectByName(shapeName) # single shape
68 for i in range(shape.NbSections()):
69 shape.SetSectionType(i, shapeType)
71 shape.SetZLevel(displayLevel)
73 index = 0 # for multiple shapes
75 shapeNameIndex = shapeName + "_%d" % index
78 shape = document.FindObjectByName(shapeNameIndex)
83 for i in range(shape.NbSections()):
84 shape.SetSectionType(i, shapeType)
86 shape.SetZLevel(displayLevel)
90 def importBathymetry(document, bathyName, bathyPath):
93 bathy = document.CreateObject(KIND_BATHYMETRY)
94 bathy.SetName(bathyName)
95 bathy.SetAltitudesInverted(0)
96 if not(bathy.ImportFromFile( os.path.join(bathyPath, bathyName + '.xyz' ))):
97 raise ValueError('problem while loading bathymetry')
101 def createImmersibleZone(document, imzName, polyLine, bathy, isImmersible, displayLevel):
104 imz = document.CreateObject(KIND_IMMERSIBLE_ZONE)
106 imz.SetZLevel(displayLevel)
107 imz.SetAltitudeObject(bathy)
108 imz.SetPolyline(polyLine)
109 imz.SetIsSubmersible(isImmersible)
110 imz.SetFillingColor(QColor(randint(0,255), randint(0,255), randint(0,255), 255))
114 def mergePolylines(document, polyName, polyLines, isConnectedBySegment = False, tolerance = 1.E-3):
117 op=HYDROData_PolylineOperator()
118 op.Merge(document, polyName, polyLines, isConnectedBySegment, tolerance)
119 shape = document.FindObjectByName(polyName)
122 def createAxis3DDEmbankmentAltiProfile(document, axis3DName, axisXY, altiPts):
124 document: current HYDROData_Document
125 axis3DName: name to give to the axis3D created
126 axisXY: imported polyline, Embankment line
127 altiPts: list of tuples(x, h) : parametric coordinate, altitude, along the axis
128 return altiProfile, axis3D
130 altiProfile = document.CreateObject(KIND_PROFILE)
131 altiProfile.SetName("%s_altiProfile"%axis3DName)
132 altiProfilePoints = []
134 altiProfilePoints.append(gp_XY(p[0], p[1]))
135 altiProfile.SetParametricPoints(altiProfilePoints)
137 axis3D = document.CreateObject(KIND_POLYLINE)
138 axis3D.SetName(axis3DName)
139 axis3D.SetPolylineXY(axisXY)
140 axis3D.SetProfileUZ(altiProfile.GetProfileUZ())
142 return (altiProfile, axis3D)
144 def createAxis3DDEmbankmentBathy(document, axis3DName, axisXY, aCloud):
146 document: current HYDROData_Document
147 axis3DName: name to give to the axis3D created
148 axisXY: imported polyline, Embankment line
149 aCloud: altimetry, for projection of axisXY
150 return altiProfile, axis3D
152 altiProfile = document.CreateObject(KIND_PROFILE)
153 altiProfile.SetName("%s_altiProfile"%axis3DName)
154 axis3D = document.CreateObject(KIND_POLYLINE)
155 axis3D.SetName(axis3DName)
156 axis3D.SetPolylineXY(axisXY)
157 axis3D.SetAltitudeObject(aCloud)
158 axis3D.SetChildProfileUZ(altiProfile.GetProfileUZ())
161 return (altiProfile, axis3D)
163 def createEmbankmentSectionA(document, embankmentName, axis3D, sectionPoints, d, displayLevel):
165 document: current HYDROData_Document
166 embankmentName: name to give to the embankment
167 axis3D: the 3D axis of the embankment
168 sectionPoints: a list of tuple (x, h) to define a half section, beginning to x=0 (center)
169 d calculation parameter, take 2 or 3 times the section width
170 displayLevel : z level for 2D representation: high values are drawn above low values
171 return section, embankment
173 section = document.CreateObject(KIND_PROFILE)
174 section.SetName("%s_section"%embankmentName)
176 for i,p in enumerate(sectionPoints):
177 sectionPts.append(gp_XY(p[0], p[1]))
179 sectionPts.insert(0, gp_XY(-p[0], p[1]))
180 section.SetParametricPoints(sectionPts)
182 embankment = document.CreateObject(KIND_DIGUE)
183 embankment.SetName(embankmentName)
184 embankment.SetGuideLine(axis3D)
185 embankment.SetProfileMode(True)
186 embankment.SetProfile(section)
187 embankment.SetEquiDistance(d)
188 embankment.SetZLevel(displayLevel)
189 embankment.SetFillingColor(QColor(randint(0,255), randint(0,255), randint(0,255), 255))
191 return (section, embankment)
193 def createEmbankmentSectionB(document, embankmentName, axis3D, LC,DZ,CZ, d, displayLevel):
195 document: current HYDROData_Document
196 embankmentName: name to give to the embankment
197 axis3D: the 3D axis of the embankment
198 LC, DZ, CZ: width, height, height offset above axis3D
199 d calculation parameter, take 2 or 3 times the section width
200 displayLevel : z level for 2D representation: high values are drawn above low values
203 embankment = document.CreateObject(KIND_DIGUE)
204 embankment.SetName(embankmentName)
205 embankment.SetGuideLine(axis3D)
206 embankment.SetProfileMode(False)
207 embankment.SetLCValue(LC)
208 embankment.SetDeltaZValue(DZ)
209 embankment.SetCoteZValue(CZ)
210 embankment.SetEquiDistance(d)
211 embankment.SetZLevel(displayLevel)
212 embankment.SetFillingColor(QColor(randint(0,255), randint(0,255), randint(0,255), 255))