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 while mySession == None:
42 mySession = myNamingService.Resolve("/Kernel/Session")
43 mySession = mySession._narrow(SALOME.Session)
44 mySession.GetInterface()
47 myLocalVisu = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "VISU")
48 myLocalStudy = theStudy
49 myLocalVisu.SetCurrentStudy(myLocalStudy)
52 def StrToMap(theString) :
53 aPairList = split(theString,";")
56 for i in range(iEnd) :
57 aPair = split(aPairList[i],"=")
58 aMap[aPair[0]] = aPair[1]
61 def IntToEntity(theInt) :
72 def HasValue(theList, theValue) :
74 return theList.index(theValue) + 1
75 except StandardError, e :
78 def CreateStudyForMed(theVisu, theFileName) :
79 print "CreateStudyForMed ", theFileName,
80 if os.path.isfile(theFileName) :
81 if re.search("\.med$", theFileName) is not None :
83 aStudyName = os.path.basename(theFileName)
84 aStudyName = re.sub(r'\.med', "", aStudyName)
85 aStudyName = generateName(aStudyName)
86 print "myLocalStudyManager.NewStudy -", aStudyName, "...",
87 aStudy = myLocalStudyManager.NewStudy(aStudyName)
88 if aStudy is None : raise RuntimeError, "Error"
91 print "CreateStudyForMed - Creating a 3D viewer...",
92 theVisu.SetCurrentStudy(aStudy)
93 myViewManager = theVisu.GetViewManager()
94 if myViewManager is None : raise RuntimeError, "Error - theVisu.GetViewManager"
95 myView = myViewManager.Create3DView()
96 if myView is None : raise RuntimeError, "Error - myViewManager.Create3DView"
100 return [aStudy, myViewManager, myView]
101 raise RuntimeError, "Error: There is no shuch file."
103 def getMedSObject(theStudy = myLocalStudy ):
105 theStudy = myLocalStudy
106 aSO = theStudy.FindObject("Med")
107 anIsPresetn, aSObject = aSO.FindSubObject(1)
110 def getMedObjectFromStudy(theStudy = myLocalStudy):
111 aSObject = getMedSObject(theStudy)
113 anAttr = aSObject.FindAttribute("AttributeIOR")[1]
114 anObj = myORB.string_to_object(anAttr.Value())
115 return anObj._narrow(SALOME_MED.MED)
118 def getFieldObjectFromStudy(number, subnumber, theStudy = myLocalStudy):
120 theStudy = myLocalStudy
121 mySO = theStudy.FindObject("MEDFIELD")
123 raise Runtime, "getFieldObjectFromStudy mySO is None"
124 mysub = mySO.FindSubObject(number)[1]
126 mysubsub = mysub.FindSubObject(subnumber)[1]
128 Builder = theStudy.NewBuilder()
129 anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
130 obj = myORB.string_to_object(anAttr.Value())
131 myObj = obj._narrow(SALOME_MED.FIELDINT)
133 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
136 print "ERROR: No Field Object stored in this Study"
139 def SObjectToObject(theSObject) :
141 if theSObject is None :
142 print "SObjectToObject : argument is None"
144 res,Attr = theSObject.FindAttribute("AttributeIOR")
145 if (res != 0) and (Attr is not None) :
146 anIOR = Attr._narrow(SALOMEDS.AttributeIOR);
147 aValue = anIOR.Value();
148 if(len(aValue) != 0) :
149 anObj = myORB.string_to_object(aValue);
151 print "SObjectToObject - IOR = ''"
154 def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt) :
156 global myLifeCycleCORBA
157 print "lcc.FindOrLoadComponent...",
158 aMedComp = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "MED")
159 if aMedComp is None : print "Error"
162 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
164 print "aMedComp.readStructFileWithFieldType...",
165 aMedComp.readStructFileWithFieldType(theFileName,myLocalStudy._get_Name())
166 aMedSObj = getMedSObject(myLocalStudy)
167 if aMedSObj is None : raise RuntimeError, "Error"
170 print "theVisu.ImportMed...",
171 aResult = theVisu.ImportMed(aMedSObj)
172 if aResult is None : raise RuntimeError, "Error"
174 aVISUObjList.append(aResult)
175 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
177 aFolderIter = myLocalStudy.NewChildIterator(aMedSObj.GetFather());
178 while aFolderIter.More() :
179 aFolderSObj = aFolderIter.Value()
181 anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
182 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
183 aFolderName = anAttr.Value()
184 print " ", aFolderName
186 if aFolderName == 'MEDMESH' :
187 aMeshIter = myLocalStudy.NewChildIterator(aFolderSObj);
188 while aMeshIter.More() :
189 aMeshSObj = aMeshIter.Value()
191 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
192 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
193 aMeshName = anAttr.Value()
196 aSupportIter = myLocalStudy.NewChildIterator(aMeshSObj);
197 while aSupportIter.More() :
198 aSupportSObj = aSupportIter.Value()
200 anAttr = aSupportSObj.FindAttribute("AttributeName")[1]
201 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
202 aSupportName = anAttr.Value()
203 print " ", aSupportName
205 if aFolderName == 'MEDFIELD' :
206 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
207 while aFieldIter.More() :
208 aFieldSObj = aFieldIter.Value()
210 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
211 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
212 aFieldName = anAttr.Value()
213 print " ", aFieldName
215 print "theVisu.ImportMed...",
216 aResult = theVisu.ImportMed(aFieldSObj)
217 if aResult is None : raise RuntimeError, "Error"
219 aVISUObjList.append(aResult)
220 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
222 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
223 if aTimeStampIter.More() :
224 aTimeStampIter.Next()
225 while aTimeStampIter.More() :
226 aTimeStampSObj = aTimeStampIter.Value()
227 aTimeStampIter.Next()
228 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
229 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
230 aTimeStampName = anAttr.Value()
231 print " ", aTimeStampName
233 print "theVisu.ImportMed...",
234 aMedField = SObjectToObject(aTimeStampSObj)
235 aResult = theVisu.ImportMedField(aMedField)
236 if aResult is None : raise RuntimeError, "Error"
238 aVISUObjList.append(aResult)
239 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
243 # except Exception, e:
246 def CreatePrsForFile(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt) :
248 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
250 print "theVisu.ImportMed...",
251 aResult = theVisu.ImportFile(theFileName)
252 if aResult is None : raise RuntimeError, "Error"
255 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
259 # except Exception, e:
262 def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDir, thePictureExt) :
264 print "CreatePrsForResult - myLocalStudy.FindObjectIOR...",
265 myLocalStudy = theVisu.GetCurrentStudy()
266 aSObj = myLocalStudy.FindObjectIOR(theResult.GetID())
267 if aSObj is None : raise RuntimeError, "Error"
269 aMeshIter = myLocalStudy.NewChildIterator(aSObj);
270 while aMeshIter.More() :
271 aMeshSObj = aMeshIter.Value()
273 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
275 aMeshSObj = aMeshIter.Value()
277 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
278 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
279 aMeshName = anAttr.Value()
280 aMeshNamePic = re.sub(".","_",aMeshName)
283 aFolderIter = myLocalStudy.NewChildIterator(aMeshSObj);
284 while aFolderIter.More() :
285 aFolderSObj = aFolderIter.Value()
287 anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
288 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
289 aFolderName = anAttr.Value()
290 print " ", aFolderName
292 if aFolderName == 'Families' :
293 anEntityIter = myLocalStudy.NewChildIterator(aFolderSObj);
294 while anEntityIter.More() :
295 anEntitySObj = anEntityIter.Value()
297 anAttr = anEntitySObj.FindAttribute("AttributeName")[1]
298 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
299 anEntityName = anAttr.Value()
302 if anEntityName == 'onNodes' :
305 if anEntityName == 'onEdges' :
308 if anEntityName == 'onFaces' :
311 if anEntityName == 'onCells' :
315 if HasValue(thePrsTypeList,VISU.TMESH) :
316 print " ", anEntityName, aMeshName,
317 aMesh = theVisu.MeshOnEntity(theResult,aMeshName,anEntity)
318 if aMesh is None : print "Error"
320 theView.DisplayOnly(aMesh)
322 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "." + thePictureExt
323 aPictureName = re.sub("\s+","_", aPictureName);
324 theView.SavePicture(aPictureName)
325 aVISUObjList.append(aMesh)
327 anFamilyIter = myLocalStudy.NewChildIterator(anEntitySObj);
328 while anFamilyIter.More() :
329 aFamilySObj = anFamilyIter.Value()
331 anAttr = aFamilySObj.FindAttribute("AttributeName")[1]
332 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
333 anFamilyName = anAttr.Value()
334 if HasValue(thePrsTypeList,VISU.TMESH) :
335 print " ", anFamilyName,
336 aMesh = theVisu.FamilyMeshOnEntity(theResult,aMeshName,anEntity,anFamilyName)
337 if aMesh is None : print "Error"
339 theView.DisplayOnly(aMesh)
341 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + anFamilyName + "." + thePictureExt
342 aPictureName = re.sub("\s+","_", aPictureName);
343 theView.SavePicture(aPictureName)
344 aVISUObjList.append(aMesh)
346 if aFolderName == 'Groups' :
347 aGroupIter = myLocalStudy.NewChildIterator(aFolderSObj);
348 while aGroupIter.More() :
349 aGroupSObj = aGroupIter.Value()
351 anAttr = aGroupSObj.FindAttribute("AttributeName")[1]
352 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
353 aGroupName = anAttr.Value()
354 if HasValue(thePrsTypeList,VISU.TMESH) :
355 print " ", aGroupName,
356 aMesh = theVisu.GroupMesh(theResult,aMeshName,aGroupName)
357 if aMesh is None : print "Error"
359 theView.DisplayOnly(aMesh)
361 aPictureName = thePictureDir + aMeshNamePic + "_" + aGroupName + "." + thePictureExt
362 aPictureName = re.sub("\s+","_", aPictureName);
363 theView.SavePicture(aPictureName)
364 aVISUObjList.append(aMesh)
366 if aFolderName == 'Fields' :
367 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
368 while aFieldIter.More() :
369 aFieldSObj = aFieldIter.Value()
371 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
372 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
373 aFieldName = anAttr.Value()
374 print " ", aFieldName
376 anAttr = aFieldSObj.FindAttribute("AttributeComment")[1]
377 anAttr = anAttr._narrow(SALOMEDS.AttributeComment);
378 aFieldComment = anAttr.Value()
379 aMap = StrToMap(aFieldComment)
381 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
382 if aTimeStampIter.More() :
383 aTimeStampIter.Next()
384 while aTimeStampIter.More() :
385 aTimeStampSObj = aTimeStampIter.Value()
386 aTimeStampIter.Next()
387 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
388 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
389 aTimeStampName = anAttr.Value()
390 print " ", aTimeStampName
392 anAttr = aTimeStampSObj.FindAttribute("AttributeComment")[1]
393 anAttr = anAttr._narrow(SALOMEDS.AttributeComment);
394 aTimeStampComment = anAttr.Value()
395 aMap = StrToMap(aTimeStampComment)
396 aMeshName = aMap["myMeshName"]
397 aFieldName = aMap["myFieldName"]
398 aTimeStampId = atoi(aMap["myTimeStampId"])
399 anEntity = IntToEntity(aMap["myEntityId"])
400 anEntityId = str(aMap["myEntityId"]);
401 #print aMeshName, aFieldName, anEntity, aTimeStampId
402 if HasValue(thePrsTypeList,VISU.TSCALARMAP) :
403 print " Creating ScalarMapOnField",
404 aPrsObj = theVisu.ScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
405 if aPrsObj is None : print "Error"
407 theView.DisplayOnly(aPrsObj)
409 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAP." + thePictureExt
410 aPictureName = re.sub("\s+","_", aPictureName);
411 theView.SavePicture(aPictureName)
412 aVISUObjList.append(aPrsObj)
414 if HasValue(thePrsTypeList,VISU.TISOSURFACE) :
415 print " Creating IsoSurfacesOnField",
416 aPrsObj = theVisu.IsoSurfacesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
417 if aPrsObj is None : print "Error"
419 theView.DisplayOnly(aPrsObj)
421 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TISOSURFACE." + thePictureExt
422 aPictureName = re.sub("\s+","_", aPictureName);
423 theView.SavePicture(aPictureName)
424 aVISUObjList.append(aPrsObj)
426 if HasValue(thePrsTypeList,VISU.TCUTPLANES) :
427 print " Creating CutPlanesOnField",
428 aPrsObj = theVisu.CutPlanesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
429 if aPrsObj is None : print "Error"
431 aPrsObj.SetOrientation(VISU.CutPlanes.ZX,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
432 theView.DisplayOnly(aPrsObj)
434 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTPLANES." + thePictureExt
435 aPictureName = re.sub("\s+","_", aPictureName)
436 theView.SavePicture(aPictureName)
437 aVISUObjList.append(aPrsObj)
439 if HasValue(thePrsTypeList,VISU.TCUTLINES) :
440 print " Creating CutLinesOnField",
441 aPrsObj = theVisu.CutLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
442 if aPrsObj is None : print "Error"
444 aPrsObj.SetOrientation(VISU.CutPlanes.XY,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
445 aPrsObj.SetOrientation2(VISU.CutPlanes.ZX,aPrsObj.GetRotateX2(),aPrsObj.GetRotateY2())
446 theView.DisplayOnly(aPrsObj)
448 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTLINES." + thePictureExt
449 aPictureName = re.sub("\s+","_", aPictureName)
450 theView.SavePicture(aPictureName)
451 aVISUObjList.append(aPrsObj)
453 aNumComponent = atoi(aMap["myNumComponent"])
454 if aNumComponent > 1 :
455 if HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPE) :
456 print " Creating DeformedShapeOnField",
457 aPrsObj = theVisu.DeformedShapeOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
458 if aPrsObj is None : print "Error"
460 theView.DisplayOnly(aPrsObj)
462 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPE." + thePictureExt
463 aPictureName = re.sub("\s+","_", aPictureName)
464 theView.SavePicture(aPictureName)
465 aVISUObjList.append(aPrsObj)
467 if HasValue(thePrsTypeList,VISU.TVECTORS) :
468 print " Creating VectorsOnField",
469 aPrsObj = theVisu.VectorsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
470 if aPrsObj is None : print "Error"
472 theView.DisplayOnly(aPrsObj)
474 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TVECTORS." + thePictureExt
475 aPictureName = re.sub("\s+","_", aPictureName)
476 theView.SavePicture(aPictureName)
477 aVISUObjList.append(aPrsObj)
479 if HasValue(thePrsTypeList,VISU.TSTREAMLINES) :
480 print " Creating StreamLinesOnField",
481 aPrsObj = theVisu.StreamLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
482 if aPrsObj is None : print "Error"
484 theView.DisplayOnly(aPrsObj)
486 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSTREAMLINES." + thePictureExt
487 aPictureName = re.sub("\s+","_", aPictureName)
488 theView.SavePicture(aPictureName)
489 aVISUObjList.append(aPrsObj)
494 def generateName(prefix = None):
496 int = whrandom.randint(1,1000);
498 return "Study" + str(int)
500 return prefix + str(int)
504 # ----------------------
506 # ----------------------
507 def try_mesh_parameters(theMeshPattern):
509 if theMeshPattern is None : return aResult ;
510 theMeshPattern = theMeshPattern._narrow(VISU.Mesh)
511 if theMeshPattern is None : return aResult ;
513 aTYPES = [VISU.POINT, VISU.WIREFRAME, VISU.SHADED, VISU.INSIDEFRAME, VISU.SHRINK]
514 import copy; import os;
516 aNewMesh = copy.deepcopy(theMeshPattern);
517 aNewMesh.SetPresentationType(ind)
518 aResult.append(aNewMesh)
523 # ----------------------------
525 # ----------------------------
527 def try_scalarmap_parameters(thePattern, dump = 0):
529 if thePattern is None : return None
531 SCALING = [VISU.LINEAR, VISU.LOGARITHMIC]
535 anObj = thePattern#copy.deepcopy(thePattern);
536 #ind = random.randint(1,2)
538 #try incorrect value deliberately (but allowed by idl description)
539 #try SetScalarMode(long)
540 mode = random.randint(-100000,100000); #incorrect value deliberately
542 #correct value of ScalarMode
543 mode = random.randint(0, 3)
545 if dump : print "\tSetScalarMode(" + str(mode) +")"
546 anObj.SetScalarMode(mode)
549 scal = random.randint(0,1)
550 if dump : print "\tSetScaling(" + str(SCALING[scal]) +")"
551 anObj.SetScaling(SCALING[scal])
555 alfa = random.random()*random.randint(-100000,100000)
556 betta = random.random()*random.randint(-100000,100000)
557 aMin = alfa; aMax = betta
560 aPMin = thePattern.GetMin()
561 aPMax = thePattern.GetMax()
563 alfa = random.random()%0.5
564 betta = random.random()%0.5
565 aMin = alfa*aLen*random.randint(-1,1) + aPMin
566 aMax = betta*aLen*random.randint(-1,1) + aPMax
567 if dump : print "\tSetRange(" + str(aMin) + ", " + str(aMax) + ")"
568 anObj.SetRange(aMin, aMax)
572 X=random.random()*random.randint(-100000,100000)
573 Y=random.random()*random.randint(-100000,100000)
577 if dump : print "SetPosition("+ str(X) + ", " + str(Y) + " )"
578 anObj.SetPosition(X, Y)
580 # --- SCALAR BAR SIZE ---
582 aWidth=random.random()*random.randint(-100000,100000)
583 aHeight=random.random()*random.randint(-100000,100000)
585 aWidth=random.random()
586 aHeight=random.random()
587 if dump : print " SCALAR BAR Width = " + str(aWidth) + " Height = ", str(aHeight)
588 anObj.SetSize(aWidth, aHeight)
593 def dump_scalarmap_parameters(anObj):
595 print "\tGetScalarMode() = " + str(anObj.GetScalarMode())
596 print "\tGetScaling() = " + str(anObj.GetScaling())
597 print "\tGetMin() = " + str(anObj.GetMin()) + " GetMax() = " + str (anObj.GetMax())
598 print "\tGetOrientation() = " + str(anObj.GetOrientation())
599 print "\tGetPosX() = ", str(anObj.GetPosX()) + " GetPosY() = ", str(anObj.GetPosY())
600 print "\tGetWidth() = ", str ( anObj.GetWidth()) + " GetHeight() = " + str(anObj.GetHeight())
602 # ----------------------
604 # ----------------------
605 def try_deformedshape_parameters(thePattern) :
607 if thePattern is None : return None
611 anObj = try_scalarmap_parameters(thePattern)
615 anObj.SetScale( random.random()*random.randint(-100000, 100000))
617 anObj.SetScale( anObj.GetScale()*random.random())
622 def dump_deformedshape_parameters(theObject):
623 dump_scalarmap_parameters(theObject)
624 print "GetScale() = ", theObject.GetScale()
626 # ----------------------
628 # ----------------------
629 def try_cutplanes_parameters(thePattern) :
631 if thePattern is None : return aList
635 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
637 ind = random.randint(1,2)
638 anObj = try_scalarmap_parameters(thePattern)
640 if ind%2 : anObj.SetNbPlanes(random.randint(-40,40))
641 else : anObj.SetNbPlanes(random.randint(0,10)) #try behaivor if NbPlanes=0
643 # --- DISPLACEMENT ---
644 anObj.SetDisplacement(random.randint(-100000,100000))
646 # --- PLANE POSITION ---
648 PlaneNb = random.randint(-100000,100000) #incorrect value is possible
649 else : PlaneNb = random.randint(0, anObj.GetNbPlanes())
651 anObj.SetPlanePosition(PlaneNb, random.random()*random.randint(-100000,100000))
653 # --- SET DEFAULT ---
654 anObj.SetDefault(PlaneNb)
656 # --- SET X,Y,Z ROTATION ---
658 angle1 = random.random()*random.randint(-100000,100000)
659 angle2 = random.random()*random.randint(-100000,100000)
661 angle1 = random.random()*3.14
662 angle2 = random.random()*3.14
664 # --- ORIENTATION ---
665 anObj.SetOrientation(ORIENT[random.randint(0,2)],angle1,angle2)
669 def dump_cutplanes_parameters(theObject):
670 dump_saclarmap_parameters(theObject)
672 print "GetOrientationType = " + str(theObject.GetOrientationType())
673 PlanesNb = theObject.GetNbPlanes()
674 print "GetNbPlanes() = ", str(PlanesNb)
675 for i in range(0,PlanesNb+1):
676 if theObject.IsDefault(i) :
677 print "Default plane : "+str(i); break
678 print "GetPlanePosition(" + str(i) + ") = ", theObject.GetPlanePosition(i)
679 print "GetDisplacement() = ", str(theObject.GetDisplacement())
680 print "GetRotateX() = ", str(theObject.GetRotateX())
681 print "GetRotateY() = ", str(theObject.GetRotateY())
682 print "GetRotateZ() = ", str(theObject.GetRotateZ())
684 # ----------------------
686 # ----------------------
687 def try_cutlines_parameters(thePattern):
689 if thePattern is None : return None
693 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
694 ind = random.randint(1,2)
695 anObj = try_scalarmap_parameters(thePattern)
697 # --- ORIENTATION ---
698 anObj.SetOrientation(ORIENT[random.randint(0,2)],
699 random.randint(-100,100)*random.random(),
700 random.randint(-100,100)*random.random())
701 anObj.SetOrientation2(ORIENT[random.randint(0,2)],
702 random.randint(-100,100)*random.random(),
703 random.randint(-100,100)*random.random())
705 # --- Base Plane Position ---
706 anObj.SetBasePlanePosition( random.random()*random.randint(-100000,100000))
708 # --- NUMBER OF LINES ---
710 anObj.SetNbLines(random.randint(-5, 50))
714 def dump_cutlines_parameters(theObject):
715 dump_scalarmap_parameters(theObject)
717 print "GetOrientationType() = " + str(theObject.GetOrientationType())
718 print "GetOrientationType2() = " + str(theObject.GetOrientationType2())
719 print "GetBasePlanePosition() = "+ str(theObject.GetBasePlanePosition())
720 print "GetNbLines() = " + str(theObject.GetNbLines())
721 print "GetRotateX() = ", str(theObject.GetRotateX())
722 print "GetRotateX2() = ", str(theObject.GetRotateX2())
723 print "GetRotateY() = ", str(theObject.GetRotateY())
724 print "GetRotateY2() = ", str(theObject.GetRotateY2())
726 # ----------------------
728 # ----------------------
729 def try_streamlines_parameters(thePattern):
731 if thePattern is None : return None
735 DIRECTION = [VISU.StreamLines.FORWARD, VISU.StreamLines.BACKWARD, VISU.StreamLines.BOTH]
737 ind = random.randint(1,2)
738 anObj = (try_deformedshape_parameters(thePattern))[0]
741 anObj.SetDirection(DIRECTION[random.randint(0,2)])
743 # --- STEP LENGTH ---
744 if ind%2 : anObj.SetStepLength(random.random()*random.randint(-1000,1000))
746 aLen = anObj.GetMax() - anObj.GetMin()
747 anObj.SetStepLength(aLen/random.randint(1,100))
749 # --- PROPAGATION TIME ---
750 anObj.SetPropagationTime(random.random()*random.randint(1,100))
752 # --- INTEGRATION STEP ---
754 anObj.SetIntegrationStep(random.random()*random.randint(-1000,1000))
756 anObj.SetIntegrationStep(random.random())
759 anObj.SetUsedPoints(random.random()*random.randint(-10000,10000))
763 def dump_streamlines_parameters(theObject):
765 dump_deformedshape_parameters(theObject)
767 print "GetDirection() = " + str(theObject.GetDirection())
768 print "GetStepLength() = " + str(theObject.GetStepLength())
769 print "GetPropagationTime() =" + str(theObject.GetPropagationTime())
770 print "GetIntegrationStep() =" + str(theObject.GetIntegrationStep())
771 print "GetUsedPoints() =" + str(theObject.GetUsedPoints())
773 # ----------------------
775 # ----------------------
776 def try_vectors_parameters(thePattern, theNum):
778 if thePattern is None : return None
781 GLIPH_TYPE = [VISU.Vectors.ARROW, VISU.Vectors.CONE2, VISU.Vectors.CONE6, VISU.Vectors.NONE]
782 GLIPH_POS = [VISU.Vectors.CENTER, VISU.Vectors.TAIL, VISU.Vectors.HEAD]
783 ind = random.randint(1,2)
784 anObj = (try_deformedshape_parameters(thePattern))[0]
788 anObj.SetLineWidth(random.random()*random.randint(-10000,10000))
790 anObj.SetLineWidth(random.randint(1, 10))
793 anObj.SetGlyphType(GLIPH_TYPE[random.randint(0, len(GLIPH_TYPE)-1)])
796 anObj.SetGlyphPos(GLIPH_POS[random.randint(0, len(GLIPH_POS)-1)])
800 def dump_vetctors_parameters(theObject):
802 dump_deformedshape_parameters(theObject)
804 print "GetLineWidth() = " +str(theObject.GetLineWidth())
805 print "GetGlyphType() = " +str(theObject.GetGlyphType())
806 print "GetGlyphPos() = " +str(theObject.GetGlyphPos())
809 # ----------------------
811 # ----------------------
813 def try_isosurfaces_parameters(thePattern) :
814 if thePattern is None : return None
818 anObj = try_scalarmap_parameters(thePattern)
819 ind = random.randint(1,2)
820 # --- SURFACES NUMBER ---
822 anObj.SetNbSurfaces(random.randint(-100000,100000))
824 anObj.SetNbSurfaces(random.randint(1, 50))
828 def dump_isosurfaces_parameters(theObject):
830 dump_scalarmap_parameters(theObject)
831 print "GetNbSurfaces() = "+ str(theObject.GetNbSurfaces())