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 getMedSObject(theStudy = myLocalStudy ):
104 theStudy = myLocalStudy
105 aSO = theStudy.FindObject("Med")
106 anIsPresetn, aSObject = aSO.FindSubObject(1)
109 def getMedObjectFromStudy(theStudy = myLocalStudy):
110 aSObject = getMedSObject(theStudy)
112 anAttr = aSObject.FindAttribute("AttributeIOR")[1]
113 anObj = myORB.string_to_object(anAttr.Value())
114 return anObj._narrow(SALOME_MED.MED)
117 def getFieldObjectFromStudy(number, subnumber, theStudy = myLocalStudy):
119 theStudy = myLocalStudy
120 mySO = theStudy.FindObject("MEDFIELD")
122 raise Runtime, "getFieldObjectFromStudy mySO is None"
123 mysub = mySO.FindSubObject(number)[1]
125 mysubsub = mysub.FindSubObject(subnumber)[1]
127 Builder = theStudy.NewBuilder()
128 anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
129 obj = myORB.string_to_object(anAttr.Value())
130 myObj = obj._narrow(SALOME_MED.FIELDINT)
132 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
135 print "ERROR: No Field Object stored in this Study"
138 def SObjectToObject(theSObject) :
140 if theSObject is None :
141 print "SObjectToObject : argument is None"
143 res,Attr = theSObject.FindAttribute("AttributeIOR")
144 if (res != 0) and (Attr is not None) :
145 anIOR = Attr._narrow(SALOMEDS.AttributeIOR);
146 aValue = anIOR.Value();
147 if(len(aValue) != 0) :
148 anObj = myORB.string_to_object(aValue);
150 print "SObjectToObject - IOR = ''"
153 def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt) :
155 global myLifeCycleCORBA
156 print "lcc.FindOrLoadComponent...",
157 aMedComp = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "MED")
158 if aMedComp is None : print "Error"
161 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
163 print "aMedComp.readStructFileWithFieldType...",
164 aMedComp.readStructFileWithFieldType(theFileName,myLocalStudy._get_Name())
165 aMedSObj = getMedSObject(myLocalStudy)
166 if aMedSObj is None : raise RuntimeError, "Error"
169 print "theVisu.ImportMed...",
170 aResult = theVisu.ImportMed(aMedSObj)
171 if aResult is None : raise RuntimeError, "Error"
173 aVISUObjList.append(aResult)
174 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
176 aFolderIter = myLocalStudy.NewChildIterator(aMedSObj.GetFather());
177 while aFolderIter.More() :
178 aFolderSObj = aFolderIter.Value()
180 anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
181 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
182 aFolderName = anAttr.Value()
183 print " ", aFolderName
185 if aFolderName == 'MEDMESH' :
186 aMeshIter = myLocalStudy.NewChildIterator(aFolderSObj);
187 while aMeshIter.More() :
188 aMeshSObj = aMeshIter.Value()
190 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
191 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
192 aMeshName = anAttr.Value()
195 aSupportIter = myLocalStudy.NewChildIterator(aMeshSObj);
196 while aSupportIter.More() :
197 aSupportSObj = aSupportIter.Value()
199 anAttr = aSupportSObj.FindAttribute("AttributeName")[1]
200 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
201 aSupportName = anAttr.Value()
202 print " ", aSupportName
204 if aFolderName == 'MEDFIELD' :
205 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
206 while aFieldIter.More() :
207 aFieldSObj = aFieldIter.Value()
209 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
210 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
211 aFieldName = anAttr.Value()
212 print " ", aFieldName
214 print "theVisu.ImportMed...",
215 aResult = theVisu.ImportMed(aFieldSObj)
216 if aResult is None : raise RuntimeError, "Error"
218 aVISUObjList.append(aResult)
219 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
221 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
222 if aTimeStampIter.More() :
223 aTimeStampIter.Next()
224 while aTimeStampIter.More() :
225 aTimeStampSObj = aTimeStampIter.Value()
226 aTimeStampIter.Next()
227 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
228 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
229 aTimeStampName = anAttr.Value()
230 print " ", aTimeStampName
232 print "theVisu.ImportMed...",
233 aMedField = SObjectToObject(aTimeStampSObj)
234 aResult = theVisu.ImportMedField(aMedField)
235 if aResult is None : raise RuntimeError, "Error"
237 aVISUObjList.append(aResult)
238 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
242 # except Exception, e:
245 def CreatePrsForFile(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt) :
247 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
249 print "theVisu.ImportMed...",
250 aResult = theVisu.ImportFile(theFileName)
251 if aResult is None : raise RuntimeError, "Error"
254 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
258 # except Exception, e:
261 def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDir, thePictureExt) :
263 print "CreatePrsForResult - myLocalStudy.FindObjectIOR...",
264 myLocalStudy = theVisu.GetCurrentStudy()
265 aSObj = myLocalStudy.FindObjectIOR(theResult.GetID())
266 if aSObj is None : raise RuntimeError, "Error"
268 aMeshIter = myLocalStudy.NewChildIterator(aSObj);
269 while aMeshIter.More() :
270 aMeshSObj = aMeshIter.Value()
272 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
274 aMeshSObj = aMeshIter.Value()
276 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
277 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
278 aMeshName = anAttr.Value()
279 aMeshNamePic = re.sub(".","_",aMeshName)
282 aFolderIter = myLocalStudy.NewChildIterator(aMeshSObj);
283 while aFolderIter.More() :
284 aFolderSObj = aFolderIter.Value()
286 anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
287 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
288 aFolderName = anAttr.Value()
289 print " ", aFolderName
291 if aFolderName == 'Families' :
292 anEntityIter = myLocalStudy.NewChildIterator(aFolderSObj);
293 while anEntityIter.More() :
294 anEntitySObj = anEntityIter.Value()
296 anAttr = anEntitySObj.FindAttribute("AttributeName")[1]
297 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
298 anEntityName = anAttr.Value()
301 if anEntityName == 'onNodes' :
304 if anEntityName == 'onEdges' :
307 if anEntityName == 'onFaces' :
310 if anEntityName == 'onCells' :
314 if HasValue(thePrsTypeList,VISU.TMESH) :
315 print " ", anEntityName, aMeshName,
316 aMesh = theVisu.MeshOnEntity(theResult,aMeshName,anEntity)
317 if aMesh is None : print "Error"
319 theView.DisplayOnly(aMesh)
321 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "." + thePictureExt
322 aPictureName = re.sub("\s+","_", aPictureName);
323 theView.SavePicture(aPictureName)
324 aVISUObjList.append(aMesh)
326 anFamilyIter = myLocalStudy.NewChildIterator(anEntitySObj);
327 while anFamilyIter.More() :
328 aFamilySObj = anFamilyIter.Value()
330 anAttr = aFamilySObj.FindAttribute("AttributeName")[1]
331 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
332 anFamilyName = anAttr.Value()
333 if HasValue(thePrsTypeList,VISU.TMESH) :
334 print " ", anFamilyName,
335 aMesh = theVisu.FamilyMeshOnEntity(theResult,aMeshName,anEntity,anFamilyName)
336 if aMesh is None : print "Error"
338 theView.DisplayOnly(aMesh)
340 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + anFamilyName + "." + thePictureExt
341 aPictureName = re.sub("\s+","_", aPictureName);
342 theView.SavePicture(aPictureName)
343 aVISUObjList.append(aMesh)
345 if aFolderName == 'Groups' :
346 aGroupIter = myLocalStudy.NewChildIterator(aFolderSObj);
347 while aGroupIter.More() :
348 aGroupSObj = aGroupIter.Value()
350 anAttr = aGroupSObj.FindAttribute("AttributeName")[1]
351 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
352 aGroupName = anAttr.Value()
353 if HasValue(thePrsTypeList,VISU.TMESH) :
354 print " ", aGroupName,
355 aMesh = theVisu.GroupMesh(theResult,aMeshName,aGroupName)
356 if aMesh is None : print "Error"
358 theView.DisplayOnly(aMesh)
360 aPictureName = thePictureDir + aMeshNamePic + "_" + aGroupName + "." + thePictureExt
361 aPictureName = re.sub("\s+","_", aPictureName);
362 theView.SavePicture(aPictureName)
363 aVISUObjList.append(aMesh)
365 if aFolderName == 'Fields' :
366 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
367 while aFieldIter.More() :
368 aFieldSObj = aFieldIter.Value()
370 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
371 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
372 aFieldName = anAttr.Value()
373 print " ", aFieldName
375 anAttr = aFieldSObj.FindAttribute("AttributeComment")[1]
376 anAttr = anAttr._narrow(SALOMEDS.AttributeComment);
377 aFieldComment = anAttr.Value()
378 aMap = StrToMap(aFieldComment)
380 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
381 if aTimeStampIter.More() :
382 aTimeStampIter.Next()
383 while aTimeStampIter.More() :
384 aTimeStampSObj = aTimeStampIter.Value()
385 aTimeStampIter.Next()
386 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
387 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
388 aTimeStampName = anAttr.Value()
389 print " ", aTimeStampName
391 anAttr = aTimeStampSObj.FindAttribute("AttributeComment")[1]
392 anAttr = anAttr._narrow(SALOMEDS.AttributeComment);
393 aTimeStampComment = anAttr.Value()
394 aMap = StrToMap(aTimeStampComment)
395 aMeshName = aMap["myMeshName"]
396 aFieldName = aMap["myFieldName"]
397 aTimeStampId = atoi(aMap["myTimeStampId"])
398 anEntity = IntToEntity(aMap["myEntityId"])
399 anEntityId = str(aMap["myEntityId"]);
400 #print aMeshName, aFieldName, anEntity, aTimeStampId
401 if HasValue(thePrsTypeList,VISU.TSCALARMAP) :
402 print " Creating ScalarMapOnField",
403 aPrsObj = theVisu.ScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
404 if aPrsObj is None : print "Error"
406 theView.DisplayOnly(aPrsObj)
408 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAP." + thePictureExt
409 aPictureName = re.sub("\s+","_", aPictureName);
410 theView.SavePicture(aPictureName)
411 aVISUObjList.append(aPrsObj)
413 if HasValue(thePrsTypeList,VISU.TISOSURFACE) :
414 print " Creating IsoSurfacesOnField",
415 aPrsObj = theVisu.IsoSurfacesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
416 if aPrsObj is None : print "Error"
418 theView.DisplayOnly(aPrsObj)
420 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TISOSURFACE." + thePictureExt
421 aPictureName = re.sub("\s+","_", aPictureName);
422 theView.SavePicture(aPictureName)
423 aVISUObjList.append(aPrsObj)
425 if HasValue(thePrsTypeList,VISU.TCUTPLANES) :
426 print " Creating CutPlanesOnField",
427 aPrsObj = theVisu.CutPlanesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
428 if aPrsObj is None : print "Error"
430 aPrsObj.SetOrientation(VISU.CutPlanes.ZX,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
431 theView.DisplayOnly(aPrsObj)
433 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTPLANES." + thePictureExt
434 aPictureName = re.sub("\s+","_", aPictureName)
435 theView.SavePicture(aPictureName)
436 aVISUObjList.append(aPrsObj)
438 if HasValue(thePrsTypeList,VISU.TCUTLINES) :
439 print " Creating CutLinesOnField",
440 aPrsObj = theVisu.CutLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
441 if aPrsObj is None : print "Error"
443 aPrsObj.SetOrientation(VISU.CutPlanes.XY,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
444 aPrsObj.SetOrientation2(VISU.CutPlanes.ZX,aPrsObj.GetRotateX2(),aPrsObj.GetRotateY2())
445 theView.DisplayOnly(aPrsObj)
447 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTLINES." + thePictureExt
448 aPictureName = re.sub("\s+","_", aPictureName)
449 theView.SavePicture(aPictureName)
450 aVISUObjList.append(aPrsObj)
452 aNumComponent = atoi(aMap["myNumComponent"])
453 if aNumComponent > 1 :
454 if HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPE) :
455 print " Creating DeformedShapeOnField",
456 aPrsObj = theVisu.DeformedShapeOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
457 if aPrsObj is None : print "Error"
459 theView.DisplayOnly(aPrsObj)
461 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPE." + thePictureExt
462 aPictureName = re.sub("\s+","_", aPictureName)
463 theView.SavePicture(aPictureName)
464 aVISUObjList.append(aPrsObj)
466 if HasValue(thePrsTypeList,VISU.TVECTORS) :
467 print " Creating VectorsOnField",
468 aPrsObj = theVisu.VectorsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
469 if aPrsObj is None : print "Error"
471 theView.DisplayOnly(aPrsObj)
473 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TVECTORS." + thePictureExt
474 aPictureName = re.sub("\s+","_", aPictureName)
475 theView.SavePicture(aPictureName)
476 aVISUObjList.append(aPrsObj)
478 if HasValue(thePrsTypeList,VISU.TSTREAMLINES) :
479 print " Creating StreamLinesOnField",
480 aPrsObj = theVisu.StreamLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
481 if aPrsObj is None : print "Error"
483 theView.DisplayOnly(aPrsObj)
485 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSTREAMLINES." + thePictureExt
486 aPictureName = re.sub("\s+","_", aPictureName)
487 theView.SavePicture(aPictureName)
488 aVISUObjList.append(aPrsObj)
493 def generateName(prefix = None):
495 int = whrandom.randint(1,1000);
497 return "Study" + str(int)
499 return prefix + str(int)
503 # ----------------------
505 # ----------------------
506 def try_mesh_parameters(theMeshPattern):
508 if theMeshPattern is None : return aResult ;
509 theMeshPattern = theMeshPattern._narrow(VISU.Mesh)
510 if theMeshPattern is None : return aResult ;
512 aTYPES = [VISU.POINT, VISU.WIREFRAME, VISU.SHADED, VISU.INSIDEFRAME, VISU.SHRINK]
513 import copy; import os;
515 aNewMesh = copy.deepcopy(theMeshPattern);
516 aNewMesh.SetPresentationType(ind)
517 aResult.append(aNewMesh)
522 # ----------------------------
524 # ----------------------------
526 def try_scalarmap_parameters(thePattern, dump = 0):
528 if thePattern is None : return None
530 SCALING = [VISU.LINEAR, VISU.LOGARITHMIC]
534 anObj = thePattern#copy.deepcopy(thePattern);
535 #ind = random.randint(1,2)
537 #try incorrect value deliberately (but allowed by idl description)
538 #try SetScalarMode(long)
539 mode = random.randint(-100000,100000); #incorrect value deliberately
541 #correct value of ScalarMode
542 mode = random.randint(0, 3)
544 if dump : print "\tSetScalarMode(" + str(mode) +")"
545 anObj.SetScalarMode(mode)
548 scal = random.randint(0,1)
549 if dump : print "\tSetScaling(" + str(SCALING[scal]) +")"
550 anObj.SetScaling(SCALING[scal])
554 alfa = random.random()*random.randint(-100000,100000)
555 betta = random.random()*random.randint(-100000,100000)
556 aMin = alfa; aMax = betta
559 aPMin = thePattern.GetMin()
560 aPMax = thePattern.GetMax()
562 alfa = random.random()%0.5
563 betta = random.random()%0.5
564 aMin = alfa*aLen*random.randint(-1,1) + aPMin
565 aMax = betta*aLen*random.randint(-1,1) + aPMax
566 if dump : print "\tSetRange(" + str(aMin) + ", " + str(aMax) + ")"
567 anObj.SetRange(aMin, aMax)
571 X=random.random()*random.randint(-100000,100000)
572 Y=random.random()*random.randint(-100000,100000)
576 if dump : print "SetPosition("+ str(X) + ", " + str(Y) + " )"
577 anObj.SetPosition(X, Y)
579 # --- SCALAR BAR SIZE ---
581 aWidth=random.random()*random.randint(-100000,100000)
582 aHeight=random.random()*random.randint(-100000,100000)
584 aWidth=random.random()
585 aHeight=random.random()
586 if dump : print " SCALAR BAR Width = " + str(aWidth) + " Height = ", str(aHeight)
587 anObj.SetSize(aWidth, aHeight)
592 def dump_scalarmap_parameters(anObj):
594 print "\tGetScalarMode() = " + str(anObj.GetScalarMode())
595 print "\tGetScaling() = " + str(anObj.GetScaling())
596 print "\tGetMin() = " + str(anObj.GetMin()) + " GetMax() = " + str (anObj.GetMax())
597 print "\tGetOrientation() = " + str(anObj.GetOrientation())
598 print "\tGetPosX() = ", str(anObj.GetPosX()) + " GetPosY() = ", str(anObj.GetPosY())
599 print "\tGetWidth() = ", str ( anObj.GetWidth()) + " GetHeight() = " + str(anObj.GetHeight())
601 # ----------------------
603 # ----------------------
604 def try_deformedshape_parameters(thePattern) :
606 if thePattern is None : return None
610 anObj = try_scalarmap_parameters(thePattern)
614 anObj.SetScale( random.random()*random.randint(-100000, 100000))
616 anObj.SetScale( anObj.GetScale()*random.random())
621 def dump_deformedshape_parameters(theObject):
622 dump_scalarmap_parameters(theObject)
623 print "GetScale() = ", theObject.GetScale()
625 # ----------------------
627 # ----------------------
628 def try_cutplanes_parameters(thePattern) :
630 if thePattern is None : return aList
634 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
636 ind = random.randint(1,2)
637 anObj = try_scalarmap_parameters(thePattern)
639 if ind%2 : anObj.SetNbPlanes(random.randint(-40,40))
640 else : anObj.SetNbPlanes(random.randint(0,10)) #try behaivor if NbPlanes=0
642 # --- DISPLACEMENT ---
643 anObj.SetDisplacement(random.randint(-100000,100000))
645 # --- PLANE POSITION ---
647 PlaneNb = random.randint(-100000,100000) #incorrect value is possible
648 else : PlaneNb = random.randint(0, anObj.GetNbPlanes())
650 anObj.SetPlanePosition(PlaneNb, random.random()*random.randint(-100000,100000))
652 # --- SET DEFAULT ---
653 anObj.SetDefault(PlaneNb)
655 # --- SET X,Y,Z ROTATION ---
657 angle1 = random.random()*random.randint(-100000,100000)
658 angle2 = random.random()*random.randint(-100000,100000)
660 angle1 = random.random()*3.14
661 angle2 = random.random()*3.14
663 # --- ORIENTATION ---
664 anObj.SetOrientation(ORIENT[random.randint(0,2)],angle1,angle2)
668 def dump_cutplanes_parameters(theObject):
669 dump_saclarmap_parameters(theObject)
671 print "GetOrientationType = " + str(theObject.GetOrientationType())
672 PlanesNb = theObject.GetNbPlanes()
673 print "GetNbPlanes() = ", str(PlanesNb)
674 for i in range(0,PlanesNb+1):
675 if theObject.IsDefault(i) :
676 print "Default plane : "+str(i); break
677 print "GetPlanePosition(" + str(i) + ") = ", theObject.GetPlanePosition(i)
678 print "GetDisplacement() = ", str(theObject.GetDisplacement())
679 print "GetRotateX() = ", str(theObject.GetRotateX())
680 print "GetRotateY() = ", str(theObject.GetRotateY())
681 print "GetRotateZ() = ", str(theObject.GetRotateZ())
683 # ----------------------
685 # ----------------------
686 def try_cutlines_parameters(thePattern):
688 if thePattern is None : return None
692 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
693 ind = random.randint(1,2)
694 anObj = try_scalarmap_parameters(thePattern)
696 # --- ORIENTATION ---
697 anObj.SetOrientation(ORIENT[random.randint(0,2)],
698 random.randint(-100,100)*random.random(),
699 random.randint(-100,100)*random.random())
700 anObj.SetOrientation2(ORIENT[random.randint(0,2)],
701 random.randint(-100,100)*random.random(),
702 random.randint(-100,100)*random.random())
704 # --- Base Plane Position ---
705 anObj.SetBasePlanePosition( random.random()*random.randint(-100000,100000))
707 # --- NUMBER OF LINES ---
709 anObj.SetNbLines(random.randint(-5, 50))
713 def dump_cutlines_parameters(theObject):
714 dump_scalarmap_parameters(theObject)
716 print "GetOrientationType() = " + str(theObject.GetOrientationType())
717 print "GetOrientationType2() = " + str(theObject.GetOrientationType2())
718 print "GetBasePlanePosition() = "+ str(theObject.GetBasePlanePosition())
719 print "GetNbLines() = " + str(theObject.GetNbLines())
720 print "GetRotateX() = ", str(theObject.GetRotateX())
721 print "GetRotateX2() = ", str(theObject.GetRotateX2())
722 print "GetRotateY() = ", str(theObject.GetRotateY())
723 print "GetRotateY2() = ", str(theObject.GetRotateY2())
725 # ----------------------
727 # ----------------------
728 def try_streamlines_parameters(thePattern):
730 if thePattern is None : return None
734 DIRECTION = [VISU.StreamLines.FORWARD, VISU.StreamLines.BACKWARD, VISU.StreamLines.BOTH]
736 ind = random.randint(1,2)
737 anObj = (try_deformedshape_parameters(thePattern))[0]
740 anObj.SetDirection(DIRECTION[random.randint(0,2)])
742 # --- STEP LENGTH ---
743 if ind%2 : anObj.SetStepLength(random.random()*random.randint(-1000,1000))
745 aLen = anObj.GetMax() - anObj.GetMin()
746 anObj.SetStepLength(aLen/random.randint(1,100))
748 # --- PROPAGATION TIME ---
749 anObj.SetPropagationTime(random.random()*random.randint(1,100))
751 # --- INTEGRATION STEP ---
753 anObj.SetIntegrationStep(random.random()*random.randint(-1000,1000))
755 anObj.SetIntegrationStep(random.random())
758 anObj.SetUsedPoints(random.random()*random.randint(-10000,10000))
762 def dump_streamlines_parameters(theObject):
764 dump_deformedshape_parameters(theObject)
766 print "GetDirection() = " + str(theObject.GetDirection())
767 print "GetStepLength() = " + str(theObject.GetStepLength())
768 print "GetPropagationTime() =" + str(theObject.GetPropagationTime())
769 print "GetIntegrationStep() =" + str(theObject.GetIntegrationStep())
770 print "GetUsedPoints() =" + str(theObject.GetUsedPoints())
772 # ----------------------
774 # ----------------------
775 def try_vectors_parameters(thePattern, theNum):
777 if thePattern is None : return None
780 GLIPH_TYPE = [VISU.Vectors.ARROW, VISU.Vectors.CONE2, VISU.Vectors.CONE6, VISU.Vectors.NONE]
781 GLIPH_POS = [VISU.Vectors.CENTER, VISU.Vectors.TAIL, VISU.Vectors.HEAD]
782 ind = random.randint(1,2)
783 anObj = (try_deformedshape_parameters(thePattern))[0]
787 anObj.SetLineWidth(random.random()*random.randint(-10000,10000))
789 anObj.SetLineWidth(random.randint(1, 10))
792 anObj.SetGlyphType(GLIPH_TYPE[random.randint(0, len(GLIPH_TYPE)-1)])
795 anObj.SetGlyphPos(GLIPH_POS[random.randint(0, len(GLIPH_POS)-1)])
799 def dump_vetctors_parameters(theObject):
801 dump_deformedshape_parameters(theObject)
803 print "GetLineWidth() = " +str(theObject.GetLineWidth())
804 print "GetGlyphType() = " +str(theObject.GetGlyphType())
805 print "GetGlyphPos() = " +str(theObject.GetGlyphPos())
808 # ----------------------
810 # ----------------------
812 def try_isosurfaces_parameters(thePattern) :
813 if thePattern is None : return None
817 anObj = try_scalarmap_parameters(thePattern)
818 ind = random.randint(1,2)
819 # --- SURFACES NUMBER ---
821 anObj.SetNbSurfaces(random.randint(-100000,100000))
823 anObj.SetNbSurfaces(random.randint(1, 50))
827 def dump_isosurfaces_parameters(theObject):
829 dump_scalarmap_parameters(theObject)
830 print "GetNbSurfaces() = "+ str(theObject.GetNbSurfaces())