1 # VISU VISU_SWIG : binding of C++ implementation and Python
3 # Copyright (C) 2003 CEA/DEN, EDF R&D
12 from time import sleep
16 import SALOME_Session_idl
19 from omniORB import CORBA
21 from time import sleep
24 myNamingService = None
25 myLifeCycleCORBA = None
26 myNamingService = None
27 myLocalStudyManager = None
33 def Initialize(theORB, theNamingService, theLifeCycleCORBA, theStudyManager, theStudy, theDelay) :
34 global myORB, myNamingService, myLifeCycleCORBA, myLocalStudyManager, myLocalStudy
35 global mySession, myLocalVisu, myDelay
38 myNamingService = theNamingService
39 myLifeCycleCORBA = theLifeCycleCORBA
40 myLocalStudyManager = theStudyManager
41 mySession = myNamingService.Resolve("/Kernel/Session")
42 mySession = mySession._narrow(SALOME.Session)
43 mySession.GetInterface()
46 myLocalVisu = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "VISU")
47 myLocalStudy = theStudy
48 myLocalVisu.SetCurrentStudy(myLocalStudy)
51 def StrToMap(theString) :
52 aPairList = split(theString,";")
55 for i in range(iEnd) :
56 aPair = split(aPairList[i],"=")
57 aMap[aPair[0]] = aPair[1]
60 def IntToEntity(theInt) :
71 def HasValue(theList, theValue) :
73 return theList.index(theValue) + 1
74 except StandardError, e :
77 def CreateStudyForMed(theVisu, theFileName) :
78 print "CreateStudyForMed ", theFileName,
79 if os.path.isfile(theFileName) :
80 if re.search("\.med$", theFileName) is not None :
82 aStudyName = os.path.basename(theFileName)
83 aStudyName = re.sub(r'\.med', "", aStudyName)
84 aStudyName = generateName(aStudyName)
85 print "myLocalStudyManager.NewStudy -", aStudyName, "...",
86 aStudy = myLocalStudyManager.NewStudy(aStudyName)
87 if aStudy is None : raise RuntimeError, "Error"
90 print "CreateStudyForMed - Creating a 3D viewer...",
91 theVisu.SetCurrentStudy(aStudy)
92 myViewManager = theVisu.GetViewManager()
93 if myViewManager is None : raise RuntimeError, "Error - theVisu.GetViewManager"
94 myView = myViewManager.Create3DView()
95 if myView is None : raise RuntimeError, "Error - myViewManager.Create3DView"
99 return [aStudy, myViewManager, myView]
100 raise RuntimeError, "Error: There is no shuch file."
102 def getMedObjectFromStudy(theStudy = myLocalStudy):
104 theStudy = myLocalStudy
105 mySO = theStudy.FindObject("Objet MED")
106 anAttr = mySO.FindAttribute("AttributeIOR")[1]
107 obj = myORB.string_to_object(anAttr.Value())
108 myObj = obj._narrow(SALOME_MED.MED)
111 def getMedSObject(theStudy = myLocalStudy ):
112 return theStudy.FindObject("Objet MED")
114 def getFieldObjectFromStudy(number, subnumber, theStudy = myLocalStudy):
116 theStudy = myLocalStudy
117 mySO = theStudy.FindObject("MEDFIELD")
119 raise Runtime, "getFieldObjectFromStudy mySO is None"
120 mysub = mySO.FindSubObject(number)[1]
122 mysubsub = mysub.FindSubObject(subnumber)[1]
124 Builder = theStudy.NewBuilder()
125 anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
126 obj = myORB.string_to_object(anAttr.Value())
127 myObj = obj._narrow(SALOME_MED.FIELDINT)
129 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
132 print "ERROR: No Field Object stored in this Study"
135 def SObjectToObject(theSObject) :
137 if theSObject is None :
138 print "SObjectToObject : argument is None"
140 res,Attr = theSObject.FindAttribute("AttributeIOR")
141 if (res != 0) and (Attr is not None) :
142 anIOR = Attr._narrow(SALOMEDS.AttributeIOR);
143 aValue = anIOR.Value();
144 if(len(aValue) != 0) :
145 anObj = myORB.string_to_object(aValue);
147 print "SObjectToObject - IOR = ''"
150 def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt) :
152 global myLifeCycleCORBA
153 print "lcc.FindOrLoadComponent...",
154 aMedComp = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "MED")
155 if aMedComp is None : print "Error"
158 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
160 print "aMedComp.readStructFileWithFieldType...",
161 aMedComp.readStructFileWithFieldType(theFileName,myLocalStudy._get_Name())
162 aMedSObj = getMedSObject(myLocalStudy)
163 if aMedSObj is None : raise RuntimeError, "Error"
166 print "theVisu.ImportMed...",
167 aResult = theVisu.ImportMed(aMedSObj)
168 if aResult is None : raise RuntimeError, "Error"
170 aVISUObjList.append(aResult)
171 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
173 aFolderIter = myLocalStudy.NewChildIterator(aMedSObj.GetFather());
174 while aFolderIter.More() :
175 aFolderSObj = aFolderIter.Value()
177 anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
178 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
179 aFolderName = anAttr.Value()
180 print " ", aFolderName
182 if aFolderName == 'MEDMESH' :
183 aMeshIter = myLocalStudy.NewChildIterator(aFolderSObj);
184 while aMeshIter.More() :
185 aMeshSObj = aMeshIter.Value()
187 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
188 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
189 aMeshName = anAttr.Value()
192 aSupportIter = myLocalStudy.NewChildIterator(aMeshSObj);
193 while aSupportIter.More() :
194 aSupportSObj = aSupportIter.Value()
196 anAttr = aSupportSObj.FindAttribute("AttributeName")[1]
197 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
198 aSupportName = anAttr.Value()
199 print " ", aSupportName
201 if aFolderName == 'MEDFIELD' :
202 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
203 while aFieldIter.More() :
204 aFieldSObj = aFieldIter.Value()
206 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
207 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
208 aFieldName = anAttr.Value()
209 print " ", aFieldName
211 print "theVisu.ImportMed...",
212 aResult = theVisu.ImportMed(aFieldSObj)
213 if aResult is None : raise RuntimeError, "Error"
215 aVISUObjList.append(aResult)
216 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
218 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
219 if aTimeStampIter.More() :
220 aTimeStampIter.Next()
221 while aTimeStampIter.More() :
222 aTimeStampSObj = aTimeStampIter.Value()
223 aTimeStampIter.Next()
224 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
225 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
226 aTimeStampName = anAttr.Value()
227 print " ", aTimeStampName
229 print "theVisu.ImportMed...",
230 aMedField = SObjectToObject(aTimeStampSObj)
231 aResult = theVisu.ImportMedField(aMedField)
232 if aResult is None : raise RuntimeError, "Error"
234 aVISUObjList.append(aResult)
235 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
239 # except Exception, e:
242 def CreatePrsForFile(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt) :
244 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
246 print "theVisu.ImportMed...",
247 aResult = theVisu.ImportFile(theFileName)
248 if aResult is None : raise RuntimeError, "Error"
251 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
255 # except Exception, e:
258 def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDir, thePictureExt) :
260 print "CreatePrsForResult - myLocalStudy.FindObjectIOR...",
261 myLocalStudy = theVisu.GetCurrentStudy()
262 aSObj = myLocalStudy.FindObjectIOR(theResult.GetID())
263 if aSObj is None : raise RuntimeError, "Error"
265 aMeshIter = myLocalStudy.NewChildIterator(aSObj);
266 while aMeshIter.More() :
267 aMeshSObj = aMeshIter.Value()
269 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
271 aMeshSObj = aMeshIter.Value()
273 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
274 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
275 aMeshName = anAttr.Value()
276 aMeshNamePic = re.sub(".","_",aMeshName)
279 aFolderIter = myLocalStudy.NewChildIterator(aMeshSObj);
280 while aFolderIter.More() :
281 aFolderSObj = aFolderIter.Value()
283 anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
284 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
285 aFolderName = anAttr.Value()
286 print " ", aFolderName
288 if aFolderName == 'Families' :
289 anEntityIter = myLocalStudy.NewChildIterator(aFolderSObj);
290 while anEntityIter.More() :
291 anEntitySObj = anEntityIter.Value()
293 anAttr = anEntitySObj.FindAttribute("AttributeName")[1]
294 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
295 anEntityName = anAttr.Value()
298 if anEntityName == 'onNodes' :
301 if anEntityName == 'onEdges' :
304 if anEntityName == 'onFaces' :
307 if anEntityName == 'onCells' :
311 if HasValue(thePrsTypeList,VISU.TMESH) :
312 print " ", anEntityName, aMeshName,
313 aMesh = theVisu.MeshOnEntity(theResult,aMeshName,anEntity)
314 if aMesh is None : print "Error"
316 theView.DisplayOnly(aMesh)
318 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "." + thePictureExt
319 aPictureName = re.sub("\s+","_", aPictureName);
320 theView.SavePicture(aPictureName)
321 aVISUObjList.append(aMesh)
323 anFamilyIter = myLocalStudy.NewChildIterator(anEntitySObj);
324 while anFamilyIter.More() :
325 aFamilySObj = anFamilyIter.Value()
327 anAttr = aFamilySObj.FindAttribute("AttributeName")[1]
328 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
329 anFamilyName = anAttr.Value()
330 if HasValue(thePrsTypeList,VISU.TMESH) :
331 print " ", anFamilyName,
332 aMesh = theVisu.FamilyMeshOnEntity(theResult,aMeshName,anEntity,anFamilyName)
333 if aMesh is None : print "Error"
335 theView.DisplayOnly(aMesh)
337 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + anFamilyName + "." + thePictureExt
338 aPictureName = re.sub("\s+","_", aPictureName);
339 theView.SavePicture(aPictureName)
340 aVISUObjList.append(aMesh)
342 if aFolderName == 'Groups' :
343 aGroupIter = myLocalStudy.NewChildIterator(aFolderSObj);
344 while aGroupIter.More() :
345 aGroupSObj = aGroupIter.Value()
347 anAttr = aGroupSObj.FindAttribute("AttributeName")[1]
348 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
349 aGroupName = anAttr.Value()
350 if HasValue(thePrsTypeList,VISU.TMESH) :
351 print " ", aGroupName,
352 aMesh = theVisu.GroupMesh(theResult,aMeshName,aGroupName)
353 if aMesh is None : print "Error"
355 theView.DisplayOnly(aMesh)
357 aPictureName = thePictureDir + aMeshNamePic + "_" + aGroupName + "." + thePictureExt
358 aPictureName = re.sub("\s+","_", aPictureName);
359 theView.SavePicture(aPictureName)
360 aVISUObjList.append(aMesh)
362 if aFolderName == 'Fields' :
363 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
364 while aFieldIter.More() :
365 aFieldSObj = aFieldIter.Value()
367 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
368 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
369 aFieldName = anAttr.Value()
370 print " ", aFieldName
372 anAttr = aFieldSObj.FindAttribute("AttributeComment")[1]
373 anAttr = anAttr._narrow(SALOMEDS.AttributeComment);
374 aFieldComment = anAttr.Value()
375 aMap = StrToMap(aFieldComment)
377 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
378 if aTimeStampIter.More() :
379 aTimeStampIter.Next()
380 while aTimeStampIter.More() :
381 aTimeStampSObj = aTimeStampIter.Value()
382 aTimeStampIter.Next()
383 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
384 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
385 aTimeStampName = anAttr.Value()
386 print " ", aTimeStampName
388 anAttr = aTimeStampSObj.FindAttribute("AttributeComment")[1]
389 anAttr = anAttr._narrow(SALOMEDS.AttributeComment);
390 aTimeStampComment = anAttr.Value()
391 aMap = StrToMap(aTimeStampComment)
392 aMeshName = aMap["myMeshName"]
393 aFieldName = aMap["myFieldName"]
394 aTimeStampId = atoi(aMap["myTimeStampId"])
395 anEntity = IntToEntity(aMap["myEntityId"])
396 anEntityId = str(aMap["myEntityId"]);
397 #print aMeshName, aFieldName, anEntity, aTimeStampId
398 if HasValue(thePrsTypeList,VISU.TSCALARMAP) :
399 print " Creating ScalarMapOnField",
400 aPrsObj = theVisu.ScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
401 if aPrsObj is None : print "Error"
403 theView.DisplayOnly(aPrsObj)
405 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAP." + thePictureExt
406 aPictureName = re.sub("\s+","_", aPictureName);
407 theView.SavePicture(aPictureName)
408 aVISUObjList.append(aPrsObj)
410 if HasValue(thePrsTypeList,VISU.TISOSURFACE) :
411 print " Creating IsoSurfacesOnField",
412 aPrsObj = theVisu.IsoSurfacesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
413 if aPrsObj is None : print "Error"
415 theView.DisplayOnly(aPrsObj)
417 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TISOSURFACE." + thePictureExt
418 aPictureName = re.sub("\s+","_", aPictureName);
419 theView.SavePicture(aPictureName)
420 aVISUObjList.append(aPrsObj)
422 if HasValue(thePrsTypeList,VISU.TCUTPLANES) :
423 print " Creating CutPlanesOnField",
424 aPrsObj = theVisu.CutPlanesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
425 if aPrsObj is None : print "Error"
427 aPrsObj.SetOrientation(VISU.CutPlanes.ZX,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
428 theView.DisplayOnly(aPrsObj)
430 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTPLANES." + thePictureExt
431 aPictureName = re.sub("\s+","_", aPictureName)
432 theView.SavePicture(aPictureName)
433 aVISUObjList.append(aPrsObj)
435 if HasValue(thePrsTypeList,VISU.TCUTLINES) :
436 print " Creating CutLinesOnField",
437 aPrsObj = theVisu.CutLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
438 if aPrsObj is None : print "Error"
440 aPrsObj.SetOrientation(VISU.CutPlanes.XY,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
441 aPrsObj.SetOrientation2(VISU.CutPlanes.ZX,aPrsObj.GetRotateX2(),aPrsObj.GetRotateY2())
442 theView.DisplayOnly(aPrsObj)
444 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTLINES." + thePictureExt
445 aPictureName = re.sub("\s+","_", aPictureName)
446 theView.SavePicture(aPictureName)
447 aVISUObjList.append(aPrsObj)
449 aNumComponent = atoi(aMap["myNumComponent"])
450 if aNumComponent > 1 :
451 if HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPE) :
452 print " Creating DeformedShapeOnField",
453 aPrsObj = theVisu.DeformedShapeOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
454 if aPrsObj is None : print "Error"
456 theView.DisplayOnly(aPrsObj)
458 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPE." + thePictureExt
459 aPictureName = re.sub("\s+","_", aPictureName)
460 theView.SavePicture(aPictureName)
461 aVISUObjList.append(aPrsObj)
463 if HasValue(thePrsTypeList,VISU.TVECTORS) :
464 print " Creating VectorsOnField",
465 aPrsObj = theVisu.VectorsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
466 if aPrsObj is None : print "Error"
468 theView.DisplayOnly(aPrsObj)
470 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TVECTORS." + thePictureExt
471 aPictureName = re.sub("\s+","_", aPictureName)
472 theView.SavePicture(aPictureName)
473 aVISUObjList.append(aPrsObj)
475 if HasValue(thePrsTypeList,VISU.TSTREAMLINES) :
476 print " Creating StreamLinesOnField",
477 aPrsObj = theVisu.StreamLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
478 if aPrsObj is None : print "Error"
480 theView.DisplayOnly(aPrsObj)
482 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSTREAMLINES." + thePictureExt
483 aPictureName = re.sub("\s+","_", aPictureName)
484 theView.SavePicture(aPictureName)
485 aVISUObjList.append(aPrsObj)
490 def generateName(prefix = None):
492 int = whrandom.randint(1,1000);
494 return "Study" + str(int)
496 return prefix + str(int)
500 # ----------------------
502 # ----------------------
503 def try_mesh_parameters(theMeshPattern):
505 if theMeshPattern is None : return aResult ;
506 theMeshPattern = theMeshPattern._narrow(VISU.Mesh)
507 if theMeshPattern is None : return aResult ;
509 aTYPES = [VISU.POINT, VISU.WIREFRAME, VISU.SHADED, VISU.INSIDEFRAME, VISU.SHRINK]
510 import copy; import os;
512 aNewMesh = copy.deepcopy(theMeshPattern);
513 aNewMesh.SetPresentationType(ind)
514 aResult.append(aNewMesh)
519 # ----------------------------
521 # ----------------------------
523 def try_scalarmap_parameters(thePattern, dump = 0):
525 if thePattern is None : return None
527 SCALING = [VISU.LINEAR, VISU.LOGARITHMIC]
531 anObj = thePattern#copy.deepcopy(thePattern);
532 #ind = random.randint(1,2)
534 #try incorrect value deliberately (but allowed by idl description)
535 #try SetScalarMode(long)
536 mode = random.randint(-100000,100000); #incorrect value deliberately
538 #correct value of ScalarMode
539 mode = random.randint(0, 3)
541 if dump : print "\tSetScalarMode(" + str(mode) +")"
542 anObj.SetScalarMode(mode)
545 scal = random.randint(0,1)
546 if dump : print "\tSetScaling(" + str(SCALING[scal]) +")"
547 anObj.SetScaling(SCALING[scal])
551 alfa = random.random()*random.randint(-100000,100000)
552 betta = random.random()*random.randint(-100000,100000)
553 aMin = alfa; aMax = betta
556 aPMin = thePattern.GetMin()
557 aPMax = thePattern.GetMax()
559 alfa = random.random()%0.5
560 betta = random.random()%0.5
561 aMin = alfa*aLen*random.randint(-1,1) + aPMin
562 aMax = betta*aLen*random.randint(-1,1) + aPMax
563 if dump : print "\tSetRange(" + str(aMin) + ", " + str(aMax) + ")"
564 anObj.SetRange(aMin, aMax)
568 X=random.random()*random.randint(-100000,100000)
569 Y=random.random()*random.randint(-100000,100000)
573 if dump : print "SetPosition("+ str(X) + ", " + str(Y) + " )"
574 anObj.SetPosition(X, Y)
576 # --- SCALAR BAR SIZE ---
578 aWidth=random.random()*random.randint(-100000,100000)
579 aHeight=random.random()*random.randint(-100000,100000)
581 aWidth=random.random()
582 aHeight=random.random()
583 if dump : print " SCALAR BAR Width = " + str(aWidth) + " Height = ", str(aHeight)
584 anObj.SetSize(aWidth, aHeight)
589 def dump_scalarmap_parameters(anObj):
591 print "\tGetScalarMode() = " + str(anObj.GetScalarMode())
592 print "\tGetScaling() = " + str(anObj.GetScaling())
593 print "\tGetMin() = " + str(anObj.GetMin()) + " GetMax() = " + str (anObj.GetMax())
594 print "\tGetOrientation() = " + str(anObj.GetOrientation())
595 print "\tGetPosX() = ", str(anObj.GetPosX()) + " GetPosY() = ", str(anObj.GetPosY())
596 print "\tGetWidth() = ", str ( anObj.GetWidth()) + " GetHeight() = " + str(anObj.GetHeight())
598 # ----------------------
600 # ----------------------
601 def try_deformedshape_parameters(thePattern) :
603 if thePattern is None : return None
607 anObj = try_scalarmap_parameters(thePattern)
611 anObj.SetScale( random.random()*random.randint(-100000, 100000))
613 anObj.SetScale( anObj.GetScale()*random.random())
618 def dump_deformedshape_parameters(theObject):
619 dump_scalarmap_parameters(theObject)
620 print "GetScale() = ", theObject.GetScale()
622 # ----------------------
624 # ----------------------
625 def try_cutplanes_parameters(thePattern) :
627 if thePattern is None : return aList
631 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
633 ind = random.randint(1,2)
634 anObj = try_scalarmap_parameters(thePattern)
636 if ind%2 : anObj.SetNbPlanes(random.randint(-40,40))
637 else : anObj.SetNbPlanes(random.randint(0,10)) #try behaivor if NbPlanes=0
639 # --- DISPLACEMENT ---
640 anObj.SetDisplacement(random.randint(-100000,100000))
642 # --- PLANE POSITION ---
644 PlaneNb = random.randint(-100000,100000) #incorrect value is possible
645 else : PlaneNb = random.randint(0, anObj.GetNbPlanes())
647 anObj.SetPlanePosition(PlaneNb, random.random()*random.randint(-100000,100000))
649 # --- SET DEFAULT ---
650 anObj.SetDefault(PlaneNb)
652 # --- SET X,Y,Z ROTATION ---
654 angle1 = random.random()*random.randint(-100000,100000)
655 angle2 = random.random()*random.randint(-100000,100000)
657 angle1 = random.random()*3.14
658 angle2 = random.random()*3.14
660 # --- ORIENTATION ---
661 anObj.SetOrientation(ORIENT[random.randint(0,2)],angle1,angle2)
665 def dump_cutplanes_parameters(theObject):
666 dump_saclarmap_parameters(theObject)
668 print "GetOrientationType = " + str(theObject.GetOrientationType())
669 PlanesNb = theObject.GetNbPlanes()
670 print "GetNbPlanes() = ", str(PlanesNb)
671 for i in range(0,PlanesNb+1):
672 if theObject.IsDefault(i) :
673 print "Default plane : "+str(i); break
674 print "GetPlanePosition(" + str(i) + ") = ", theObject.GetPlanePosition(i)
675 print "GetDisplacement() = ", str(theObject.GetDisplacement())
676 print "GetRotateX() = ", str(theObject.GetRotateX())
677 print "GetRotateY() = ", str(theObject.GetRotateY())
678 print "GetRotateZ() = ", str(theObject.GetRotateZ())
680 # ----------------------
682 # ----------------------
683 def try_cutlines_parameters(thePattern):
685 if thePattern is None : return None
689 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
690 ind = random.randint(1,2)
691 anObj = try_scalarmap_parameters(thePattern)
693 # --- ORIENTATION ---
694 anObj.SetOrientation(ORIENT[random.randint(0,2)],
695 random.randint(-100,100)*random.random(),
696 random.randint(-100,100)*random.random())
697 anObj.SetOrientation2(ORIENT[random.randint(0,2)],
698 random.randint(-100,100)*random.random(),
699 random.randint(-100,100)*random.random())
701 # --- Base Plane Position ---
702 anObj.SetBasePlanePosition( random.random()*random.randint(-100000,100000))
704 # --- NUMBER OF LINES ---
706 anObj.SetNbLines(random.randint(-5, 50))
710 def dump_cutlines_parameters(theObject):
711 dump_scalarmap_parameters(theObject)
713 print "GetOrientationType() = " + str(theObject.GetOrientationType())
714 print "GetOrientationType2() = " + str(theObject.GetOrientationType2())
715 print "GetBasePlanePosition() = "+ str(theObject.GetBasePlanePosition())
716 print "GetNbLines() = " + str(theObject.GetNbLines())
717 print "GetRotateX() = ", str(theObject.GetRotateX())
718 print "GetRotateX2() = ", str(theObject.GetRotateX2())
719 print "GetRotateY() = ", str(theObject.GetRotateY())
720 print "GetRotateY2() = ", str(theObject.GetRotateY2())
722 # ----------------------
724 # ----------------------
725 def try_streamlines_parameters(thePattern):
727 if thePattern is None : return None
731 DIRECTION = [VISU.StreamLines.FORWARD, VISU.StreamLines.BACKWARD, VISU.StreamLines.BOTH]
733 ind = random.randint(1,2)
734 anObj = (try_deformedshape_parameters(thePattern))[0]
737 anObj.SetDirection(DIRECTION[random.randint(0,2)])
739 # --- STEP LENGTH ---
740 if ind%2 : anObj.SetStepLength(random.random()*random.randint(-1000,1000))
742 aLen = anObj.GetMax() - anObj.GetMin()
743 anObj.SetStepLength(aLen/random.randint(1,100))
745 # --- PROPAGATION TIME ---
746 anObj.SetPropagationTime(random.random()*random.randint(1,100))
748 # --- INTEGRATION STEP ---
750 anObj.SetIntegrationStep(random.random()*random.randint(-1000,1000))
752 anObj.SetIntegrationStep(random.random())
755 anObj.SetUsedPoints(random.random()*random.randint(-10000,10000))
759 def dump_streamlines_parameters(theObject):
761 dump_deformedshape_parameters(theObject)
763 print "GetDirection() = " + str(theObject.GetDirection())
764 print "GetStepLength() = " + str(theObject.GetStepLength())
765 print "GetPropagationTime() =" + str(theObject.GetPropagationTime())
766 print "GetIntegrationStep() =" + str(theObject.GetIntegrationStep())
767 print "GetUsedPoints() =" + str(theObject.GetUsedPoints())
769 # ----------------------
771 # ----------------------
772 def try_vectors_parameters(thePattern, theNum):
774 if thePattern is None : return None
777 GLIPH_TYPE = [VISU.Vectors.ARROW, VISU.Vectors.CONE2, VISU.Vectors.CONE6, VISU.Vectors.NONE]
778 GLIPH_POS = [VISU.Vectors.CENTER, VISU.Vectors.TAIL, VISU.Vectors.HEAD]
779 ind = random.randint(1,2)
780 anObj = (try_deformedshape_parameters(thePattern))[0]
784 anObj.SetLineWidth(random.random()*random.randint(-10000,10000))
786 anObj.SetLineWidth(random.randint(1, 10))
789 anObj.SetGlyphType(GLIPH_TYPE[random.randint(0, len(GLIPH_TYPE)-1)])
792 anObj.SetGlyphPos(GLIPH_POS[random.randint(0, len(GLIPH_POS)-1)])
796 def dump_vetctors_parameters(theObject):
798 dump_deformedshape_parameters(theObject)
800 print "GetLineWidth() = " +str(theObject.GetLineWidth())
801 print "GetGlyphType() = " +str(theObject.GetGlyphType())
802 print "GetGlyphPos() = " +str(theObject.GetGlyphPos())
805 # ----------------------
807 # ----------------------
809 def try_isosurfaces_parameters(thePattern) :
810 if thePattern is None : return None
814 anObj = try_scalarmap_parameters(thePattern)
815 ind = random.randint(1,2)
816 # --- SURFACES NUMBER ---
818 anObj.SetNbSurfaces(random.randint(-100000,100000))
820 anObj.SetNbSurfaces(random.randint(1, 50))
824 def dump_isosurfaces_parameters(theObject):
826 dump_scalarmap_parameters(theObject)
827 print "GetNbSurfaces() = "+ str(theObject.GetNbSurfaces())