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 PublishComponent(theStudyDocument):
53 aComponentDataType = myLocalVisu.ComponentDataType()
54 aSComponent = theStudyDocument.FindComponent(aComponentDataType)
55 if aSComponent == None:
56 aStudyBuilder = theStudyDocument.NewBuilder()
57 aStudyBuilder.NewCommand()
58 aLocked = theStudyDocument.GetProperties().IsLocked()
60 theStudyDocument.GetProperties().SetLocked(0)
63 aSComponent = aStudyBuilder.NewComponent(aComponentDataType);
64 aName = aStudyBuilder.FindOrCreateAttribute(aSComponent,"AttributeName")
65 aModuleCatalog = myNamingService.Resolve("/Kernel/ModulCatalog");
66 aComponent = aModuleCatalog.GetComponent(aComponentDataType);
67 if aComponent != None:
68 aComponentUserName = aComponent._get_componentusername()
69 aName.SetValue(aComponentUserName)
72 aPixMap = aStudyBuilder.FindOrCreateAttribute(aSComponent,"AttributePixMap")
73 aPixMap.SetPixMap("ICON_OBJBROWSER_Visu")
75 aStudyBuilder.DefineComponentInstance(aSComponent,myLocalVisu);
77 theStudyDocument.GetProperties().SetLocked(1);
80 aStudyBuilder.CommitCommand();
85 def StrToMap(theString) :
86 aPairList = split(theString,";")
89 for i in range(iEnd) :
90 aPair = split(aPairList[i],"=")
91 aMap[aPair[0]] = aPair[1]
94 def IntToEntity(theInt) :
105 def HasValue(theList, theValue) :
107 return theList.index(theValue) + 1
108 except StandardError, e :
111 def CreateStudyForMed(theVisu, theFileName) :
112 print "CreateStudyForMed ", theFileName,
113 if os.path.isfile(theFileName) :
114 if re.search("\.med$", theFileName) is not None :
116 aStudyName = os.path.basename(theFileName)
117 aStudyName = re.sub(r'\.med', "", aStudyName)
118 aStudyName = generateName(aStudyName)
119 print "myLocalStudyManager.NewStudy -", aStudyName, "...",
120 aStudy = myLocalStudyManager.NewStudy(aStudyName)
121 if aStudy is None : raise RuntimeError, "Error"
124 print "CreateStudyForMed - Creating a 3D viewer...",
125 theVisu.SetCurrentStudy(aStudy)
126 myViewManager = theVisu.GetViewManager()
127 if myViewManager is None : raise RuntimeError, "Error - theVisu.GetViewManager"
128 myView = myViewManager.Create3DView()
129 if myView is None : raise RuntimeError, "Error - myViewManager.Create3DView"
133 return [aStudy, myViewManager, myView]
134 raise RuntimeError, "Error: There is no shuch file."
136 def getMedSObject(theStudy = myLocalStudy ):
138 theStudy = myLocalStudy
139 aSO = theStudy.FindObject("Med")
140 anIsPresetn, aSObject = aSO.FindSubObject(1)
143 def getMedObjectFromStudy(theStudy = myLocalStudy):
144 aSObject = getMedSObject(theStudy)
146 anAttr = aSObject.FindAttribute("AttributeIOR")[1]
147 anObj = myORB.string_to_object(anAttr.Value())
148 return anObj._narrow(SALOME_MED.MED)
151 def getFieldObjectFromStudy(number, subnumber, theStudy = myLocalStudy):
153 theStudy = myLocalStudy
154 mySO = theStudy.FindObject("MEDFIELD")
156 raise Runtime, "getFieldObjectFromStudy mySO is None"
157 mysub = mySO.FindSubObject(number)[1]
159 mysubsub = mysub.FindSubObject(subnumber)[1]
161 Builder = theStudy.NewBuilder()
162 anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
163 obj = myORB.string_to_object(anAttr.Value())
164 myObj = obj._narrow(SALOME_MED.FIELDINT)
166 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
169 print "ERROR: No Field Object stored in this Study"
172 def SObjectToObject(theSObject) :
174 if theSObject is None :
175 print "SObjectToObject : argument is None"
177 res,Attr = theSObject.FindAttribute("AttributeIOR")
178 if (res != 0) and (Attr is not None) :
179 anIOR = Attr._narrow(SALOMEDS.AttributeIOR);
180 aValue = anIOR.Value();
181 if(len(aValue) != 0) :
182 anObj = myORB.string_to_object(aValue);
184 print "SObjectToObject - IOR = ''"
187 def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt) :
189 global myLifeCycleCORBA
190 print "lcc.FindOrLoadComponent...",
191 aMedComp = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "MED")
192 if aMedComp is None : print "Error"
195 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
197 print "aMedComp.readStructFileWithFieldType...",
198 aMedComp.readStructFileWithFieldType(theFileName,myLocalStudy._get_Name())
199 aMedSObj = getMedSObject(myLocalStudy)
200 if aMedSObj is None : raise RuntimeError, "Error"
203 print "theVisu.ImportMed...",
204 aResult = theVisu.ImportMed(aMedSObj)
205 if aResult is None : raise RuntimeError, "Error"
207 aVISUObjList.append(aResult)
208 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
210 aFolderIter = myLocalStudy.NewChildIterator(aMedSObj.GetFather());
211 while aFolderIter.More() :
212 aFolderSObj = aFolderIter.Value()
214 anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
215 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
216 aFolderName = anAttr.Value()
217 print " ", aFolderName
219 if aFolderName == 'MEDMESH' :
220 aMeshIter = myLocalStudy.NewChildIterator(aFolderSObj);
221 while aMeshIter.More() :
222 aMeshSObj = aMeshIter.Value()
224 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
225 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
226 aMeshName = anAttr.Value()
229 aSupportIter = myLocalStudy.NewChildIterator(aMeshSObj);
230 while aSupportIter.More() :
231 aSupportSObj = aSupportIter.Value()
233 anAttr = aSupportSObj.FindAttribute("AttributeName")[1]
234 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
235 aSupportName = anAttr.Value()
236 print " ", aSupportName
238 if aFolderName == 'MEDFIELD' :
239 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
240 while aFieldIter.More() :
241 aFieldSObj = aFieldIter.Value()
243 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
244 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
245 aFieldName = anAttr.Value()
246 print " ", aFieldName
248 print "theVisu.ImportMed...",
249 aResult = theVisu.ImportMed(aFieldSObj)
250 if aResult is None : raise RuntimeError, "Error"
252 aVISUObjList.append(aResult)
253 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
255 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
256 if aTimeStampIter.More() :
257 aTimeStampIter.Next()
258 while aTimeStampIter.More() :
259 aTimeStampSObj = aTimeStampIter.Value()
260 aTimeStampIter.Next()
261 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
262 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
263 aTimeStampName = anAttr.Value()
264 print " ", aTimeStampName
266 print "theVisu.ImportMed...",
267 aMedField = SObjectToObject(aTimeStampSObj)
268 aResult = theVisu.ImportMedField(aMedField)
269 if aResult is None : raise RuntimeError, "Error"
271 aVISUObjList.append(aResult)
272 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
276 # except Exception, e:
279 def CreatePrsForFile(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt) :
281 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
283 print "theVisu.ImportMed...",
284 aResult = theVisu.ImportFile(theFileName)
285 if aResult is None : raise RuntimeError, "Error"
288 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
292 # except Exception, e:
295 def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDir, thePictureExt) :
297 print "CreatePrsForResult - myLocalStudy.FindObjectIOR...",
298 myLocalStudy = theVisu.GetCurrentStudy()
299 aSObj = myLocalStudy.FindObjectIOR(theResult.GetID())
300 if aSObj is None : raise RuntimeError, "Error"
302 aMeshIter = myLocalStudy.NewChildIterator(aSObj);
303 while aMeshIter.More() :
304 aMeshSObj = aMeshIter.Value()
306 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
308 aMeshSObj = aMeshIter.Value()
310 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
311 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
312 aMeshName = anAttr.Value()
313 aMeshNamePic = re.sub(".","_",aMeshName)
316 aFolderIter = myLocalStudy.NewChildIterator(aMeshSObj);
317 while aFolderIter.More() :
318 aFolderSObj = aFolderIter.Value()
320 anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
321 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
322 aFolderName = anAttr.Value()
323 print " ", aFolderName
325 if aFolderName == 'Families' :
326 anEntityIter = myLocalStudy.NewChildIterator(aFolderSObj);
327 while anEntityIter.More() :
328 anEntitySObj = anEntityIter.Value()
330 anAttr = anEntitySObj.FindAttribute("AttributeName")[1]
331 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
332 anEntityName = anAttr.Value()
335 if anEntityName == 'onNodes' :
338 if anEntityName == 'onEdges' :
341 if anEntityName == 'onFaces' :
344 if anEntityName == 'onCells' :
348 if HasValue(thePrsTypeList,VISU.TMESH) :
349 print " ", anEntityName, aMeshName,
350 aMesh = theVisu.MeshOnEntity(theResult,aMeshName,anEntity)
351 if aMesh is None : print "Error"
353 theView.DisplayOnly(aMesh)
355 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "." + thePictureExt
356 aPictureName = re.sub("\s+","_", aPictureName);
357 theView.SavePicture(aPictureName)
358 aVISUObjList.append(aMesh)
360 anFamilyIter = myLocalStudy.NewChildIterator(anEntitySObj);
361 while anFamilyIter.More() :
362 aFamilySObj = anFamilyIter.Value()
364 anAttr = aFamilySObj.FindAttribute("AttributeName")[1]
365 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
366 anFamilyName = anAttr.Value()
367 if HasValue(thePrsTypeList,VISU.TMESH) :
368 print " ", anFamilyName,
369 aMesh = theVisu.FamilyMeshOnEntity(theResult,aMeshName,anEntity,anFamilyName)
370 if aMesh is None : print "Error"
372 theView.DisplayOnly(aMesh)
374 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + anFamilyName + "." + thePictureExt
375 aPictureName = re.sub("\s+","_", aPictureName);
376 theView.SavePicture(aPictureName)
377 aVISUObjList.append(aMesh)
379 if aFolderName == 'Groups' :
380 aGroupIter = myLocalStudy.NewChildIterator(aFolderSObj);
381 while aGroupIter.More() :
382 aGroupSObj = aGroupIter.Value()
384 anAttr = aGroupSObj.FindAttribute("AttributeName")[1]
385 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
386 aGroupName = anAttr.Value()
387 if HasValue(thePrsTypeList,VISU.TMESH) :
388 print " ", aGroupName,
389 aMesh = theVisu.GroupMesh(theResult,aMeshName,aGroupName)
390 if aMesh is None : print "Error"
392 theView.DisplayOnly(aMesh)
394 aPictureName = thePictureDir + aMeshNamePic + "_" + aGroupName + "." + thePictureExt
395 aPictureName = re.sub("\s+","_", aPictureName);
396 theView.SavePicture(aPictureName)
397 aVISUObjList.append(aMesh)
399 if aFolderName == 'Fields' :
400 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
401 while aFieldIter.More() :
402 aFieldSObj = aFieldIter.Value()
404 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
405 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
406 aFieldName = anAttr.Value()
407 print " ", aFieldName
409 anAttr = aFieldSObj.FindAttribute("AttributeComment")[1]
410 anAttr = anAttr._narrow(SALOMEDS.AttributeComment);
411 aFieldComment = anAttr.Value()
412 aMap = StrToMap(aFieldComment)
414 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
415 if aTimeStampIter.More() :
416 aTimeStampIter.Next()
417 while aTimeStampIter.More() :
418 aTimeStampSObj = aTimeStampIter.Value()
419 aTimeStampIter.Next()
420 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
421 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
422 aTimeStampName = anAttr.Value()
423 print " ", aTimeStampName
425 anAttr = aTimeStampSObj.FindAttribute("AttributeComment")[1]
426 anAttr = anAttr._narrow(SALOMEDS.AttributeComment);
427 aTimeStampComment = anAttr.Value()
428 aMap = StrToMap(aTimeStampComment)
429 aMeshName = aMap["myMeshName"]
430 aFieldName = aMap["myFieldName"]
431 aTimeStampId = atoi(aMap["myTimeStampId"])
432 anEntity = IntToEntity(aMap["myEntityId"])
433 anEntityId = str(aMap["myEntityId"]);
434 #print aMeshName, aFieldName, anEntity, aTimeStampId
435 if HasValue(thePrsTypeList,VISU.TSCALARMAP) :
436 print " Creating ScalarMapOnField",
437 aPrsObj = theVisu.ScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
438 if aPrsObj is None : print "Error"
440 theView.DisplayOnly(aPrsObj)
442 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAP." + thePictureExt
443 aPictureName = re.sub("\s+","_", aPictureName);
444 theView.SavePicture(aPictureName)
445 aVISUObjList.append(aPrsObj)
447 if HasValue(thePrsTypeList,VISU.TISOSURFACE) :
448 print " Creating IsoSurfacesOnField",
449 aPrsObj = theVisu.IsoSurfacesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
450 if aPrsObj is None : print "Error"
452 theView.DisplayOnly(aPrsObj)
454 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TISOSURFACE." + thePictureExt
455 aPictureName = re.sub("\s+","_", aPictureName);
456 theView.SavePicture(aPictureName)
457 aVISUObjList.append(aPrsObj)
459 if HasValue(thePrsTypeList,VISU.TCUTPLANES) :
460 print " Creating CutPlanesOnField",
461 aPrsObj = theVisu.CutPlanesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
462 if aPrsObj is None : print "Error"
464 aPrsObj.SetOrientation(VISU.CutPlanes.ZX,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
465 theView.DisplayOnly(aPrsObj)
467 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTPLANES." + thePictureExt
468 aPictureName = re.sub("\s+","_", aPictureName)
469 theView.SavePicture(aPictureName)
470 aVISUObjList.append(aPrsObj)
472 if HasValue(thePrsTypeList,VISU.TCUTLINES) :
473 print " Creating CutLinesOnField",
474 aPrsObj = theVisu.CutLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
475 if aPrsObj is None : print "Error"
477 aPrsObj.SetOrientation(VISU.CutPlanes.XY,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
478 aPrsObj.SetOrientation2(VISU.CutPlanes.ZX,aPrsObj.GetRotateX2(),aPrsObj.GetRotateY2())
479 theView.DisplayOnly(aPrsObj)
481 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTLINES." + thePictureExt
482 aPictureName = re.sub("\s+","_", aPictureName)
483 theView.SavePicture(aPictureName)
484 aVISUObjList.append(aPrsObj)
486 if HasValue(thePrsTypeList,VISU.TPLOT3D) :
487 print " Creating Plot3DOnField",
488 aPrsObj = theVisu.Plot3DOnField(theResult,aMeshName,anEntity,
489 aFieldName,aTimeStampId)
490 if aPrsObj is None : print "Error"
492 #aPrsObj.SetOrientation(VISU.CutPlanes.ZX,
493 # aPrsObj.GetRotateX(),
494 # aPrsObj.GetRotateY())
495 theView.DisplayOnly(aPrsObj)
497 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId +
498 "_" + aFieldName + "_" + str(aTimeStampId) +
499 "_TPLOT3D." + thePictureExt
500 aPictureName = re.sub("\s+","_", aPictureName)
501 theView.SavePicture(aPictureName)
502 aVISUObjList.append(aPrsObj)
504 aNumComponent = atoi(aMap["myNumComponent"])
505 if aNumComponent > 1 :
506 if HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPE) :
507 print " Creating DeformedShapeOnField",
508 aPrsObj = theVisu.DeformedShapeOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
509 if aPrsObj is None : print "Error"
511 theView.DisplayOnly(aPrsObj)
513 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPE." + thePictureExt
514 aPictureName = re.sub("\s+","_", aPictureName)
515 theView.SavePicture(aPictureName)
516 aVISUObjList.append(aPrsObj)
518 if HasValue(thePrsTypeList,VISU.TVECTORS) :
519 print " Creating VectorsOnField",
520 aPrsObj = theVisu.VectorsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
521 if aPrsObj is None : print "Error"
523 theView.DisplayOnly(aPrsObj)
525 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TVECTORS." + thePictureExt
526 aPictureName = re.sub("\s+","_", aPictureName)
527 theView.SavePicture(aPictureName)
528 aVISUObjList.append(aPrsObj)
530 if HasValue(thePrsTypeList,VISU.TSTREAMLINES) :
531 print " Creating StreamLinesOnField",
532 aPrsObj = theVisu.StreamLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
533 if aPrsObj is None : print "Error"
535 theView.DisplayOnly(aPrsObj)
537 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSTREAMLINES." + thePictureExt
538 aPictureName = re.sub("\s+","_", aPictureName)
539 theView.SavePicture(aPictureName)
540 aVISUObjList.append(aPrsObj)
545 def generateName(prefix = None):
547 int = whrandom.randint(1,1000);
549 return "Study" + str(int)
551 return prefix + str(int)
555 # ----------------------
557 # ----------------------
558 def try_mesh_parameters(theMeshPattern):
560 if theMeshPattern is None : return aResult ;
561 theMeshPattern = theMeshPattern._narrow(VISU.Mesh)
562 if theMeshPattern is None : return aResult ;
564 aTYPES = [VISU.POINT, VISU.WIREFRAME, VISU.SHADED, VISU.INSIDEFRAME, VISU.SHRINK]
565 import copy; import os;
567 aNewMesh = copy.deepcopy(theMeshPattern);
568 aNewMesh.SetPresentationType(ind)
569 aResult.append(aNewMesh)
574 # ----------------------------
576 # ----------------------------
578 def try_scalarmap_parameters(thePattern, dump = 0):
580 if thePattern is None : return None
582 SCALING = [VISU.LINEAR, VISU.LOGARITHMIC]
586 anObj = thePattern#copy.deepcopy(thePattern);
587 #ind = random.randint(1,2)
589 #try incorrect value deliberately (but allowed by idl description)
590 #try SetScalarMode(long)
591 mode = random.randint(-100000,100000); #incorrect value deliberately
593 #correct value of ScalarMode
594 mode = random.randint(0, 3)
596 if dump : print "\tSetScalarMode(" + str(mode) +")"
597 anObj.SetScalarMode(mode)
600 scal = random.randint(0,1)
601 if dump : print "\tSetScaling(" + str(SCALING[scal]) +")"
602 anObj.SetScaling(SCALING[scal])
606 alfa = random.random()*random.randint(-100000,100000)
607 betta = random.random()*random.randint(-100000,100000)
608 aMin = alfa; aMax = betta
611 aPMin = thePattern.GetMin()
612 aPMax = thePattern.GetMax()
614 alfa = random.random()%0.5
615 betta = random.random()%0.5
616 aMin = alfa*aLen*random.randint(-1,1) + aPMin
617 aMax = betta*aLen*random.randint(-1,1) + aPMax
618 if dump : print "\tSetRange(" + str(aMin) + ", " + str(aMax) + ")"
619 anObj.SetRange(aMin, aMax)
623 X=random.random()*random.randint(-100000,100000)
624 Y=random.random()*random.randint(-100000,100000)
628 if dump : print "SetPosition("+ str(X) + ", " + str(Y) + " )"
629 anObj.SetPosition(X, Y)
631 # --- SCALAR BAR SIZE ---
633 aWidth=random.random()*random.randint(-100000,100000)
634 aHeight=random.random()*random.randint(-100000,100000)
636 aWidth=random.random()
637 aHeight=random.random()
638 if dump : print " SCALAR BAR Width = " + str(aWidth) + " Height = ", str(aHeight)
639 anObj.SetSize(aWidth, aHeight)
644 def dump_scalarmap_parameters(anObj):
646 print "\tGetScalarMode() = " + str(anObj.GetScalarMode())
647 print "\tGetScaling() = " + str(anObj.GetScaling())
648 print "\tGetMin() = " + str(anObj.GetMin()) + " GetMax() = " + str (anObj.GetMax())
649 print "\tGetOrientation() = " + str(anObj.GetOrientation())
650 print "\tGetPosX() = ", str(anObj.GetPosX()) + " GetPosY() = ", str(anObj.GetPosY())
651 print "\tGetWidth() = ", str ( anObj.GetWidth()) + " GetHeight() = " + str(anObj.GetHeight())
653 # ----------------------
655 # ----------------------
656 def try_deformedshape_parameters(thePattern) :
658 if thePattern is None : return None
662 anObj = try_scalarmap_parameters(thePattern)
666 anObj.SetScale( random.random()*random.randint(-100000, 100000))
668 anObj.SetScale( anObj.GetScale()*random.random())
673 def dump_deformedshape_parameters(theObject):
674 dump_scalarmap_parameters(theObject)
675 print "GetScale() = ", theObject.GetScale()
677 # ----------------------
679 # ----------------------
680 def try_cutplanes_parameters(thePattern) :
682 if thePattern is None : return aList
686 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
688 ind = random.randint(1,2)
689 anObj = try_scalarmap_parameters(thePattern)
691 if ind%2 : anObj.SetNbPlanes(random.randint(-40,40))
692 else : anObj.SetNbPlanes(random.randint(0,10)) #try behaivor if NbPlanes=0
694 # --- DISPLACEMENT ---
695 anObj.SetDisplacement(random.randint(-100000,100000))
697 # --- PLANE POSITION ---
699 PlaneNb = random.randint(-100000,100000) #incorrect value is possible
700 else : PlaneNb = random.randint(0, anObj.GetNbPlanes())
702 anObj.SetPlanePosition(PlaneNb, random.random()*random.randint(-100000,100000))
704 # --- SET DEFAULT ---
705 anObj.SetDefault(PlaneNb)
707 # --- SET X,Y,Z ROTATION ---
709 angle1 = random.random()*random.randint(-100000,100000)
710 angle2 = random.random()*random.randint(-100000,100000)
712 angle1 = random.random()*3.14
713 angle2 = random.random()*3.14
715 # --- ORIENTATION ---
716 anObj.SetOrientation(ORIENT[random.randint(0,2)],angle1,angle2)
720 def dump_cutplanes_parameters(theObject):
721 dump_saclarmap_parameters(theObject)
723 print "GetOrientationType = " + str(theObject.GetOrientationType())
724 PlanesNb = theObject.GetNbPlanes()
725 print "GetNbPlanes() = ", str(PlanesNb)
726 for i in range(0,PlanesNb+1):
727 if theObject.IsDefault(i) :
728 print "Default plane : "+str(i); break
729 print "GetPlanePosition(" + str(i) + ") = ", theObject.GetPlanePosition(i)
730 print "GetDisplacement() = ", str(theObject.GetDisplacement())
731 print "GetRotateX() = ", str(theObject.GetRotateX())
732 print "GetRotateY() = ", str(theObject.GetRotateY())
733 print "GetRotateZ() = ", str(theObject.GetRotateZ())
735 # ----------------------
737 # ----------------------
738 def try_cutlines_parameters(thePattern):
740 if thePattern is None : return None
744 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
745 ind = random.randint(1,2)
746 anObj = try_scalarmap_parameters(thePattern)
748 # --- ORIENTATION ---
749 anObj.SetOrientation(ORIENT[random.randint(0,2)],
750 random.randint(-100,100)*random.random(),
751 random.randint(-100,100)*random.random())
752 anObj.SetOrientation2(ORIENT[random.randint(0,2)],
753 random.randint(-100,100)*random.random(),
754 random.randint(-100,100)*random.random())
756 # --- Base Plane Position ---
757 anObj.SetBasePlanePosition( random.random()*random.randint(-100000,100000))
759 # --- NUMBER OF LINES ---
761 anObj.SetNbLines(random.randint(-5, 50))
765 def dump_cutlines_parameters(theObject):
766 dump_scalarmap_parameters(theObject)
768 print "GetOrientationType() = " + str(theObject.GetOrientationType())
769 print "GetOrientationType2() = " + str(theObject.GetOrientationType2())
770 print "GetBasePlanePosition() = "+ str(theObject.GetBasePlanePosition())
771 print "GetNbLines() = " + str(theObject.GetNbLines())
772 print "GetRotateX() = ", str(theObject.GetRotateX())
773 print "GetRotateX2() = ", str(theObject.GetRotateX2())
774 print "GetRotateY() = ", str(theObject.GetRotateY())
775 print "GetRotateY2() = ", str(theObject.GetRotateY2())
777 # ----------------------
779 # ----------------------
780 def try_streamlines_parameters(thePattern):
782 if thePattern is None : return None
786 DIRECTION = [VISU.StreamLines.FORWARD, VISU.StreamLines.BACKWARD, VISU.StreamLines.BOTH]
788 ind = random.randint(1,2)
789 anObj = (try_deformedshape_parameters(thePattern))[0]
792 anObj.SetDirection(DIRECTION[random.randint(0,2)])
794 # --- STEP LENGTH ---
795 if ind%2 : anObj.SetStepLength(random.random()*random.randint(-1000,1000))
797 aLen = anObj.GetMax() - anObj.GetMin()
798 anObj.SetStepLength(aLen/random.randint(1,100))
800 # --- PROPAGATION TIME ---
801 anObj.SetPropagationTime(random.random()*random.randint(1,100))
803 # --- INTEGRATION STEP ---
805 anObj.SetIntegrationStep(random.random()*random.randint(-1000,1000))
807 anObj.SetIntegrationStep(random.random())
810 anObj.SetUsedPoints(random.random()*random.randint(-10000,10000))
814 def dump_streamlines_parameters(theObject):
816 dump_deformedshape_parameters(theObject)
818 print "GetDirection() = " + str(theObject.GetDirection())
819 print "GetStepLength() = " + str(theObject.GetStepLength())
820 print "GetPropagationTime() =" + str(theObject.GetPropagationTime())
821 print "GetIntegrationStep() =" + str(theObject.GetIntegrationStep())
822 print "GetUsedPoints() =" + str(theObject.GetUsedPoints())
824 # ----------------------
826 # ----------------------
827 def try_vectors_parameters(thePattern, theNum):
829 if thePattern is None : return None
832 GLIPH_TYPE = [VISU.Vectors.ARROW, VISU.Vectors.CONE2, VISU.Vectors.CONE6, VISU.Vectors.NONE]
833 GLIPH_POS = [VISU.Vectors.CENTER, VISU.Vectors.TAIL, VISU.Vectors.HEAD]
834 ind = random.randint(1,2)
835 anObj = (try_deformedshape_parameters(thePattern))[0]
839 anObj.SetLineWidth(random.random()*random.randint(-10000,10000))
841 anObj.SetLineWidth(random.randint(1, 10))
844 anObj.SetGlyphType(GLIPH_TYPE[random.randint(0, len(GLIPH_TYPE)-1)])
847 anObj.SetGlyphPos(GLIPH_POS[random.randint(0, len(GLIPH_POS)-1)])
851 def dump_vetctors_parameters(theObject):
853 dump_deformedshape_parameters(theObject)
855 print "GetLineWidth() = " +str(theObject.GetLineWidth())
856 print "GetGlyphType() = " +str(theObject.GetGlyphType())
857 print "GetGlyphPos() = " +str(theObject.GetGlyphPos())
860 # ----------------------
862 # ----------------------
864 def try_isosurfaces_parameters(thePattern) :
865 if thePattern is None : return None
869 anObj = try_scalarmap_parameters(thePattern)
870 ind = random.randint(1,2)
871 # --- SURFACES NUMBER ---
873 anObj.SetNbSurfaces(random.randint(-100000,100000))
875 anObj.SetNbSurfaces(random.randint(1, 50))
879 def dump_isosurfaces_parameters(theObject):
881 dump_scalarmap_parameters(theObject)
882 print "GetNbSurfaces() = "+ str(theObject.GetNbSurfaces())
885 # ----------------------
887 # ----------------------
889 def FillTable( theTable, theValues, theRows, theColumns, theRowTitles, theRowUnits, theColumnTitles ):
890 if theTable is None: return
891 if len(theRows) != len(theColumns): return
892 if len(theRows) != len(theValues): return
894 for value in theValues:
895 theTable.PutValue( value, theRows[ i ], theColumns[ i ])
899 for title in theRowTitles:
900 theTable.SetRowTitle( i, title )
901 theTable.SetRowUnit( i, theRowUnits[ i - 1 ])
905 for title in theColumnTitles:
906 theTable.SetColumnTitle( i, title )
911 def CreateCurve( theTable, theHRow, theVRow, theTitle, theColor, theMarker, theLineType, theLineWidth ):
912 if theTitle is None: return
913 curve = myLocalVisu.CreateCurve( theTable, theHRow, theVRow );
915 curve.SetTitle( theTitle )
916 curve.SetColor( theColor )
917 curve.SetMarker( theMarker )
918 curve.SetLine( theLineType, theLineWidth )