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 SetName(theObj, theName):
86 anIOR = myORB.object_to_string(theObj)
87 aSObj = myLocalStudy.FindObjectIOR(anIOR)
88 anAttr = aSObj.FindAttribute("AttributeName")[1]
89 anAttr.SetValue(theName)
91 def StrToMap(theString) :
92 aPairList = split(theString,";")
95 for i in range(iEnd) :
96 aPair = split(aPairList[i],"=")
97 aMap[aPair[0]] = aPair[1]
100 def IntToEntity(theInt) :
101 theInt = atoi(theInt)
111 def HasValue(theList, theValue) :
113 return theList.index(theValue) + 1
114 except StandardError, e :
117 def CreateStudyForMed(theVisu, theFileName) :
118 print "CreateStudyForMed ", theFileName,
119 if os.path.isfile(theFileName) :
120 if re.search("\.med$", theFileName) is not None :
122 aStudyName = os.path.basename(theFileName)
123 aStudyName = re.sub(r'\.med', "", aStudyName)
124 aStudyName = generateName(aStudyName)
125 print "myLocalStudyManager.NewStudy -", aStudyName, "...",
126 aStudy = myLocalStudyManager.NewStudy(aStudyName)
127 if aStudy is None : raise RuntimeError, "Error"
130 print "CreateStudyForMed - Creating a 3D viewer...",
131 theVisu.SetCurrentStudy(aStudy)
132 myViewManager = theVisu.GetViewManager()
133 if myViewManager is None : raise RuntimeError, "Error - theVisu.GetViewManager"
134 myView = myViewManager.Create3DView()
135 if myView is None : raise RuntimeError, "Error - myViewManager.Create3DView"
139 return [aStudy, myViewManager, myView]
140 raise RuntimeError, "Error: There is no shuch file."
142 def getMedSObject(theStudy = myLocalStudy ):
144 theStudy = myLocalStudy
145 aSO = theStudy.FindObject("Med")
146 anIsPresetn, aSObject = aSO.FindSubObject(1)
149 def getMedObjectFromStudy(theStudy = myLocalStudy):
150 aSObject = getMedSObject(theStudy)
152 anAttr = aSObject.FindAttribute("AttributeIOR")[1]
153 anObj = myORB.string_to_object(anAttr.Value())
154 return anObj._narrow(SALOME_MED.MED)
157 def getFieldObjectFromStudy(number, subnumber, theStudy = myLocalStudy):
159 theStudy = myLocalStudy
160 mySO = theStudy.FindObject("MEDFIELD")
162 raise Runtime, "getFieldObjectFromStudy mySO is None"
163 mysub = mySO.FindSubObject(number)[1]
165 mysubsub = mysub.FindSubObject(subnumber)[1]
167 Builder = theStudy.NewBuilder()
168 anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
169 obj = myORB.string_to_object(anAttr.Value())
170 myObj = obj._narrow(SALOME_MED.FIELDINT)
172 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
175 print "ERROR: No Field Object stored in this Study"
178 def SObjectToObject(theSObject) :
180 if theSObject is None :
181 print "SObjectToObject : argument is None"
183 res,Attr = theSObject.FindAttribute("AttributeIOR")
184 if (res != 0) and (Attr is not None) :
185 anIOR = Attr._narrow(SALOMEDS.AttributeIOR);
186 aValue = anIOR.Value();
187 if(len(aValue) != 0) :
188 anObj = myORB.string_to_object(aValue);
190 print "SObjectToObject - IOR = ''"
193 def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
195 global myLifeCycleCORBA
196 print "lcc.FindOrLoadComponent...",
197 aMedComp = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "MED")
198 if aMedComp is None : print "Error"
201 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
203 print "aMedComp.readStructFileWithFieldType...",
204 aMedComp.readStructFileWithFieldType(theFileName,myLocalStudy._get_Name())
205 aMedSObj = getMedSObject(myLocalStudy)
206 if aMedSObj is None : raise RuntimeError, "Error"
209 print "theVisu.ImportMed...",
210 aResult = theVisu.ImportMed(aMedSObj)
211 if aResult is None : raise RuntimeError, "Error"
214 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
216 aResult.RemoveFromStudy()
218 aVISUObjList.append(aResult)
220 aFolderIter = myLocalStudy.NewChildIterator(aMedSObj.GetFather());
221 while aFolderIter.More() :
222 aFolderSObj = aFolderIter.Value()
224 anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
225 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
226 aFolderName = anAttr.Value()
227 print " ", aFolderName
229 if aFolderName == 'MEDMESH' :
230 aMeshIter = myLocalStudy.NewChildIterator(aFolderSObj);
231 while aMeshIter.More() :
232 aMeshSObj = aMeshIter.Value()
234 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
235 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
236 aMeshName = anAttr.Value()
239 aSupportIter = myLocalStudy.NewChildIterator(aMeshSObj);
240 while aSupportIter.More() :
241 aSupportSObj = aSupportIter.Value()
243 anAttr = aSupportSObj.FindAttribute("AttributeName")[1]
244 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
245 aSupportName = anAttr.Value()
246 print " ", aSupportName
248 if aFolderName == 'MEDFIELD' :
249 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
250 while aFieldIter.More() :
251 aFieldSObj = aFieldIter.Value()
253 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
254 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
255 aFieldName = anAttr.Value()
256 print " ", aFieldName
258 print "theVisu.ImportMed...",
259 aResult = theVisu.ImportMed(aFieldSObj)
260 if aResult is None : raise RuntimeError, "Error"
263 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
265 aResult.RemoveFromStudy()
267 aVISUObjList.append(aResult)
269 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
270 if aTimeStampIter.More() :
271 aTimeStampIter.Next()
272 while aTimeStampIter.More() :
273 aTimeStampSObj = aTimeStampIter.Value()
274 aTimeStampIter.Next()
275 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
276 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
277 aTimeStampName = anAttr.Value()
278 print " ", aTimeStampName
280 print "theVisu.ImportMed...",
281 aMedField = SObjectToObject(aTimeStampSObj)
282 aResult = theVisu.ImportMedField(aMedField)
283 if aResult is None : raise RuntimeError, "Error"
286 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
288 aResult.RemoveFromStudy()
290 aVISUObjList.append(aResult)
294 # except Exception, e:
297 def CreatePrsForFile(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
299 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
301 print "theVisu.ImportMed...",
302 aResult = theVisu.ImportFile(theFileName)
303 if aResult is None : raise RuntimeError, "Error"
306 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
309 aResult.RemoveFromStudy()
311 aVISUObjList.append(aResult)
315 # except Exception, e:
318 def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
320 if theIsAutoDelete is not None :
324 print "CreatePrsForResult - myLocalStudy.FindObjectIOR...",
325 myLocalStudy = theVisu.GetCurrentStudy()
327 aSObj = myLocalStudy.FindObjectIOR(theResult.GetID())
328 if aSObj is None : raise RuntimeError, "Error"
330 aMeshIter = myLocalStudy.NewChildIterator(aSObj);
331 while aMeshIter.More() :
332 aMeshSObj = aMeshIter.Value()
334 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
336 aMeshSObj = aMeshIter.Value()
338 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
339 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
340 aMeshName = anAttr.Value()
341 aMeshNamePic = re.sub(".","_",aMeshName)
344 aFolderIter = myLocalStudy.NewChildIterator(aMeshSObj);
345 while aFolderIter.More() :
346 aFolderSObj = aFolderIter.Value()
348 anIsFound, anAttr = aFolderSObj.FindAttribute("AttributeName")
351 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
352 aFolderName = anAttr.Value()
353 print " ", aFolderName
355 if aFolderName == 'Families' :
356 anEntityIter = myLocalStudy.NewChildIterator(aFolderSObj);
357 while anEntityIter.More() :
358 anEntitySObj = anEntityIter.Value()
360 anAttr = anEntitySObj.FindAttribute("AttributeName")[1]
361 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
362 anEntityName = anAttr.Value()
365 if anEntityName == 'onNodes' :
368 if anEntityName == 'onEdges' :
371 if anEntityName == 'onFaces' :
374 if anEntityName == 'onCells' :
378 if HasValue(thePrsTypeList,VISU.TMESH) :
379 print " ", anEntityName, aMeshName,
380 aMesh = theVisu.MeshOnEntity(theResult,aMeshName,anEntity)
381 if aMesh is None : print "Error"
384 theView.DisplayOnly(aMesh)
386 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "." + thePictureExt
387 aPictureName = re.sub("\s+","_", aPictureName);
388 theView.SavePicture(aPictureName)
390 aMesh.RemoveFromStudy()
392 aVISUObjList.append(aMesh)
394 anFamilyIter = myLocalStudy.NewChildIterator(anEntitySObj);
395 while anFamilyIter.More() :
396 aFamilySObj = anFamilyIter.Value()
398 anAttr = aFamilySObj.FindAttribute("AttributeName")[1]
399 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
400 anFamilyName = anAttr.Value()
401 if HasValue(thePrsTypeList,VISU.TMESH) :
402 print " ", anFamilyName,
403 aMesh = theVisu.FamilyMeshOnEntity(theResult,aMeshName,anEntity,anFamilyName)
404 if aMesh is None : print "Error"
407 theView.DisplayOnly(aMesh)
409 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + anFamilyName + "." + thePictureExt
410 aPictureName = re.sub("\s+","_", aPictureName);
411 theView.SavePicture(aPictureName)
413 aMesh.RemoveFromStudy()
415 aVISUObjList.append(aMesh)
417 if aFolderName == 'Groups' :
418 aGroupIter = myLocalStudy.NewChildIterator(aFolderSObj);
419 while aGroupIter.More() :
420 aGroupSObj = aGroupIter.Value()
422 anAttr = aGroupSObj.FindAttribute("AttributeName")[1]
423 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
424 aGroupName = anAttr.Value()
425 if HasValue(thePrsTypeList,VISU.TMESH) :
426 print " ", aGroupName,
427 aMesh = theVisu.GroupMesh(theResult,aMeshName,aGroupName)
428 if aMesh is None : print "Error"
431 theView.DisplayOnly(aMesh)
433 aPictureName = thePictureDir + aMeshNamePic + "_" + aGroupName + "." + thePictureExt
434 aPictureName = re.sub("\s+","_", aPictureName);
435 theView.SavePicture(aPictureName)
437 aMesh.RemoveFromStudy()
439 aVISUObjList.append(aMesh)
441 if aFolderName == 'Fields' :
442 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
443 while aFieldIter.More() :
444 aFieldSObj = aFieldIter.Value()
446 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
447 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
448 aFieldName = anAttr.Value()
449 print " ", aFieldName
451 anAttr = aFieldSObj.FindAttribute("AttributeComment")[1]
452 anAttr = anAttr._narrow(SALOMEDS.AttributeComment);
453 aFieldComment = anAttr.Value()
454 aMap = StrToMap(aFieldComment)
456 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
457 if aTimeStampIter.More() :
458 aTimeStampIter.Next()
459 while aTimeStampIter.More() :
460 aTimeStampSObj = aTimeStampIter.Value()
461 aTimeStampIter.Next()
462 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
463 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
464 aTimeStampName = anAttr.Value()
465 print " ", aTimeStampName
467 anAttr = aTimeStampSObj.FindAttribute("AttributeComment")[1]
468 anAttr = anAttr._narrow(SALOMEDS.AttributeComment);
469 aTimeStampComment = anAttr.Value()
470 aMap = StrToMap(aTimeStampComment)
471 aMeshName = aMap["myMeshName"]
472 aFieldName = aMap["myFieldName"]
473 aTimeStampId = atoi(aMap["myTimeStampId"])
474 anEntity = IntToEntity(aMap["myEntityId"])
475 anEntityId = str(aMap["myEntityId"]);
476 #print aMeshName, aFieldName, anEntity, aTimeStampId
477 if HasValue(thePrsTypeList,VISU.TSCALARMAP) :
478 print " Creating ScalarMapOnField",
479 aPrsObj = theVisu.ScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
480 if aPrsObj is None : print "Error"
483 theView.DisplayOnly(aPrsObj)
485 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAP." + thePictureExt
486 aPictureName = re.sub("\s+","_", aPictureName);
487 theView.SavePicture(aPictureName)
489 aPrsObj.RemoveFromStudy()
491 aVISUObjList.append(aPrsObj)
493 if HasValue(thePrsTypeList,VISU.TISOSURFACE) :
494 print " Creating IsoSurfacesOnField",
495 aPrsObj = theVisu.IsoSurfacesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
496 if aPrsObj is None : print "Error"
499 theView.DisplayOnly(aPrsObj)
501 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TISOSURFACE." + thePictureExt
502 aPictureName = re.sub("\s+","_", aPictureName);
503 theView.SavePicture(aPictureName)
505 aPrsObj.RemoveFromStudy()
507 aVISUObjList.append(aPrsObj)
509 if HasValue(thePrsTypeList,VISU.TCUTPLANES) :
510 print " Creating CutPlanesOnField",
511 aPrsObj = theVisu.CutPlanesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
512 if aPrsObj is None : print "Error"
515 aPrsObj.SetOrientation(VISU.CutPlanes.ZX,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
516 theView.DisplayOnly(aPrsObj)
518 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTPLANES." + thePictureExt
519 aPictureName = re.sub("\s+","_", aPictureName)
520 theView.SavePicture(aPictureName)
522 aPrsObj.RemoveFromStudy()
524 aVISUObjList.append(aPrsObj)
526 if HasValue(thePrsTypeList,VISU.TCUTLINES) :
527 print " Creating CutLinesOnField",
528 aPrsObj = theVisu.CutLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
529 if aPrsObj is None : print "Error"
532 aPrsObj.SetOrientation(VISU.CutPlanes.XY,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
533 aPrsObj.SetOrientation2(VISU.CutPlanes.ZX,aPrsObj.GetRotateX2(),aPrsObj.GetRotateY2())
534 theView.DisplayOnly(aPrsObj)
536 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTLINES." + thePictureExt
537 aPictureName = re.sub("\s+","_", aPictureName)
538 theView.SavePicture(aPictureName)
540 aPrsObj.RemoveFromStudy()
542 aVISUObjList.append(aPrsObj)
544 if HasValue(thePrsTypeList,VISU.TPLOT3D) :
545 print " Creating Plot3DOnField",
546 aPrsObj = theVisu.Plot3DOnField(theResult,aMeshName,anEntity,
547 aFieldName,aTimeStampId)
548 if aPrsObj is None : print "Error"
551 #aPrsObj.SetOrientation(VISU.CutPlanes.ZX,
552 # aPrsObj.GetRotateX(),
553 # aPrsObj.GetRotateY())
554 theView.DisplayOnly(aPrsObj)
556 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TPLOT3D." + thePictureExt
557 aPictureName = re.sub("\s+","_", aPictureName)
558 theView.SavePicture(aPictureName)
560 aPrsObj.RemoveFromStudy()
562 aVISUObjList.append(aPrsObj)
564 aNumComponent = atoi(aMap["myNumComponent"])
565 if aNumComponent > 1 :
566 if HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPE) :
567 print " Creating DeformedShapeOnField",
568 aPrsObj = theVisu.DeformedShapeOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
569 if aPrsObj is None : print "Error"
572 theView.DisplayOnly(aPrsObj)
574 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPE." + thePictureExt
575 aPictureName = re.sub("\s+","_", aPictureName)
576 theView.SavePicture(aPictureName)
578 aPrsObj.RemoveFromStudy()
580 aVISUObjList.append(aPrsObj)
582 if HasValue(thePrsTypeList,VISU.TVECTORS) :
583 print " Creating VectorsOnField",
584 aPrsObj = theVisu.VectorsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
585 if aPrsObj is None : print "Error"
588 theView.DisplayOnly(aPrsObj)
590 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TVECTORS." + thePictureExt
591 aPictureName = re.sub("\s+","_", aPictureName)
592 theView.SavePicture(aPictureName)
594 aPrsObj.RemoveFromStudy()
596 aVISUObjList.append(aPrsObj)
598 if HasValue(thePrsTypeList,VISU.TSTREAMLINES) :
599 print " Creating StreamLinesOnField",
600 aPrsObj = theVisu.StreamLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
601 if aPrsObj is None : print "Error"
604 theView.DisplayOnly(aPrsObj)
606 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSTREAMLINES." + thePictureExt
607 aPictureName = re.sub("\s+","_", aPictureName)
608 theView.SavePicture(aPictureName)
610 aPrsObj.RemoveFromStudy()
612 aVISUObjList.append(aPrsObj)
614 if HasValue(thePrsTypeList,VISU.TSCALARMAPONDEFORMEDSHAPE) :
615 print " Creating ScalarMapOnDeformedShapeOnField",
616 aPrsObj = theVisu.ScalarMapOnDeformedShapeOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
617 if aPrsObj is None : print "Error"
620 theView.DisplayOnly(aPrsObj)
622 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAPONDEFORMEDSHAPE." + thePictureExt
623 aPictureName = re.sub("\s+","_", aPictureName)
624 theView.SavePicture(aPictureName)
626 aPrsObj.RemoveFromStudy()
628 aVISUObjList.append(aPrsObj)
633 def generateName(prefix = None):
635 int = whrandom.randint(1,1000);
637 return "Study" + str(int)
639 return prefix + str(int)
643 # ----------------------
645 # ----------------------
646 def try_mesh_parameters(theMeshPattern):
648 if theMeshPattern is None : return aResult ;
649 theMeshPattern = theMeshPattern._narrow(VISU.Mesh)
650 if theMeshPattern is None : return aResult ;
652 aTYPES = [VISU.POINT, VISU.WIREFRAME, VISU.SHADED, VISU.INSIDEFRAME, VISU.SHRINK]
653 import copy; import os;
655 aNewMesh = copy.deepcopy(theMeshPattern);
656 aNewMesh.SetPresentationType(ind)
657 aResult.append(aNewMesh)
662 # ----------------------------
664 # ----------------------------
666 def try_scalarmap_parameters(thePattern, dump = 0):
668 if thePattern is None : return None
670 SCALING = [VISU.LINEAR, VISU.LOGARITHMIC]
674 anObj = thePattern#copy.deepcopy(thePattern);
675 #ind = random.randint(1,2)
677 #try incorrect value deliberately (but allowed by idl description)
678 #try SetScalarMode(long)
679 mode = random.randint(-100000,100000); #incorrect value deliberately
681 #correct value of ScalarMode
682 mode = random.randint(0, 3)
684 if dump : print "\tSetScalarMode(" + str(mode) +")"
685 anObj.SetScalarMode(mode)
688 scal = random.randint(0,1)
689 if dump : print "\tSetScaling(" + str(SCALING[scal]) +")"
690 anObj.SetScaling(SCALING[scal])
694 alfa = random.random()*random.randint(-100000,100000)
695 betta = random.random()*random.randint(-100000,100000)
696 aMin = alfa; aMax = betta
699 aPMin = thePattern.GetMin()
700 aPMax = thePattern.GetMax()
702 alfa = random.random()%0.5
703 betta = random.random()%0.5
704 aMin = alfa*aLen*random.randint(-1,1) + aPMin
705 aMax = betta*aLen*random.randint(-1,1) + aPMax
706 if dump : print "\tSetRange(" + str(aMin) + ", " + str(aMax) + ")"
707 anObj.SetRange(aMin, aMax)
711 X=random.random()*random.randint(-100000,100000)
712 Y=random.random()*random.randint(-100000,100000)
716 if dump : print "SetPosition("+ str(X) + ", " + str(Y) + " )"
717 anObj.SetPosition(X, Y)
719 # --- SCALAR BAR SIZE ---
721 aWidth=random.random()*random.randint(-100000,100000)
722 aHeight=random.random()*random.randint(-100000,100000)
724 aWidth=random.random()
725 aHeight=random.random()
726 if dump : print " SCALAR BAR Width = " + str(aWidth) + " Height = ", str(aHeight)
727 anObj.SetSize(aWidth, aHeight)
732 def dump_scalarmap_parameters(anObj):
734 print "\tGetScalarMode() = " + str(anObj.GetScalarMode())
735 print "\tGetScaling() = " + str(anObj.GetScaling())
736 print "\tGetMin() = " + str(anObj.GetMin()) + " GetMax() = " + str (anObj.GetMax())
737 print "\tGetOrientation() = " + str(anObj.GetOrientation())
738 print "\tGetPosX() = ", str(anObj.GetPosX()) + " GetPosY() = ", str(anObj.GetPosY())
739 print "\tGetWidth() = ", str ( anObj.GetWidth()) + " GetHeight() = " + str(anObj.GetHeight())
741 # ----------------------
743 # ----------------------
744 def try_deformedshape_parameters(thePattern) :
746 if thePattern is None : return None
750 anObj = try_scalarmap_parameters(thePattern)
754 anObj.SetScale( random.random()*random.randint(-100000, 100000))
756 anObj.SetScale( anObj.GetScale()*random.random())
761 def dump_deformedshape_parameters(theObject):
762 dump_scalarmap_parameters(theObject)
763 print "GetScale() = ", theObject.GetScale()
765 # ----------------------
767 # ----------------------
768 def try_cutplanes_parameters(thePattern) :
770 if thePattern is None : return None
774 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
776 ind = random.randint(1,2)
777 anObj = try_scalarmap_parameters(thePattern)
779 if ind%2 : anObj.SetNbPlanes(random.randint(-40,40))
780 else : anObj.SetNbPlanes(random.randint(0,10)) #try behaivor if NbPlanes=0
782 # --- DISPLACEMENT ---
783 anObj.SetDisplacement(random.randint(-100000,100000))
785 # --- PLANE POSITION ---
787 PlaneNb = random.randint(-100000,100000) #incorrect value is possible
788 else : PlaneNb = random.randint(0, anObj.GetNbPlanes())
790 anObj.SetPlanePosition(PlaneNb, random.random()*random.randint(-100000,100000))
792 # --- SET DEFAULT ---
793 anObj.SetDefault(PlaneNb)
795 # --- SET X,Y,Z ROTATION ---
797 angle1 = random.random()*random.randint(-100000,100000)
798 angle2 = random.random()*random.randint(-100000,100000)
800 angle1 = random.random()*3.14
801 angle2 = random.random()*3.14
803 # --- ORIENTATION ---
804 anObj.SetOrientation(ORIENT[random.randint(0,2)],angle1,angle2)
808 def dump_cutplanes_parameters(theObject):
809 dump_saclarmap_parameters(theObject)
811 print "GetOrientationType = " + str(theObject.GetOrientationType())
812 PlanesNb = theObject.GetNbPlanes()
813 print "GetNbPlanes() = ", str(PlanesNb)
814 for i in range(0,PlanesNb+1):
815 if theObject.IsDefault(i) :
816 print "Default plane : "+str(i); break
817 print "GetPlanePosition(" + str(i) + ") = ", theObject.GetPlanePosition(i)
818 print "GetDisplacement() = ", str(theObject.GetDisplacement())
819 print "GetRotateX() = ", str(theObject.GetRotateX())
820 print "GetRotateY() = ", str(theObject.GetRotateY())
821 print "GetRotateZ() = ", str(theObject.GetRotateZ())
823 # ----------------------
825 # ----------------------
826 def try_cutlines_parameters(thePattern):
828 if thePattern is None : return None
832 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
833 ind = random.randint(1,2)
834 anObj = try_scalarmap_parameters(thePattern)
836 # --- ORIENTATION ---
837 anObj.SetOrientation(ORIENT[random.randint(0,2)],
838 random.randint(-100,100)*random.random(),
839 random.randint(-100,100)*random.random())
840 anObj.SetOrientation2(ORIENT[random.randint(0,2)],
841 random.randint(-100,100)*random.random(),
842 random.randint(-100,100)*random.random())
844 # --- Base Plane Position ---
845 anObj.SetBasePlanePosition( random.random()*random.randint(-100000,100000))
847 # --- NUMBER OF LINES ---
849 anObj.SetNbLines(random.randint(-5, 50))
853 def dump_cutlines_parameters(theObject):
854 dump_scalarmap_parameters(theObject)
856 print "GetOrientationType() = " + str(theObject.GetOrientationType())
857 print "GetOrientationType2() = " + str(theObject.GetOrientationType2())
858 print "GetBasePlanePosition() = "+ str(theObject.GetBasePlanePosition())
859 print "GetNbLines() = " + str(theObject.GetNbLines())
860 print "GetRotateX() = ", str(theObject.GetRotateX())
861 print "GetRotateX2() = ", str(theObject.GetRotateX2())
862 print "GetRotateY() = ", str(theObject.GetRotateY())
863 print "GetRotateY2() = ", str(theObject.GetRotateY2())
865 # ----------------------
867 # ----------------------
868 def try_streamlines_parameters(thePattern):
870 if thePattern is None : return None
874 DIRECTION = [VISU.StreamLines.FORWARD, VISU.StreamLines.BACKWARD, VISU.StreamLines.BOTH]
876 ind = random.randint(1,2)
877 anObj = (try_deformedshape_parameters(thePattern))[0]
880 anObj.SetDirection(DIRECTION[random.randint(0,2)])
882 # --- STEP LENGTH ---
883 if ind%2 : anObj.SetStepLength(random.random()*random.randint(-1000,1000))
885 aLen = anObj.GetMax() - anObj.GetMin()
886 anObj.SetStepLength(aLen/random.randint(1,100))
888 # --- PROPAGATION TIME ---
889 anObj.SetPropagationTime(random.random()*random.randint(1,100))
891 # --- INTEGRATION STEP ---
893 anObj.SetIntegrationStep(random.random()*random.randint(-1000,1000))
895 anObj.SetIntegrationStep(random.random())
898 anObj.SetUsedPoints(random.random()*random.randint(-10000,10000))
902 def dump_streamlines_parameters(theObject):
904 dump_deformedshape_parameters(theObject)
906 print "GetDirection() = " + str(theObject.GetDirection())
907 print "GetStepLength() = " + str(theObject.GetStepLength())
908 print "GetPropagationTime() =" + str(theObject.GetPropagationTime())
909 print "GetIntegrationStep() =" + str(theObject.GetIntegrationStep())
910 print "GetUsedPoints() =" + str(theObject.GetUsedPoints())
912 # ----------------------
914 # ----------------------
915 def try_vectors_parameters(thePattern, theNum):
917 if thePattern is None : return None
920 GLIPH_TYPE = [VISU.Vectors.ARROW, VISU.Vectors.CONE2, VISU.Vectors.CONE6, VISU.Vectors.NONE]
921 GLIPH_POS = [VISU.Vectors.CENTER, VISU.Vectors.TAIL, VISU.Vectors.HEAD]
922 ind = random.randint(1,2)
923 anObj = (try_deformedshape_parameters(thePattern))[0]
927 anObj.SetLineWidth(random.random()*random.randint(-10000,10000))
929 anObj.SetLineWidth(random.randint(1, 10))
932 anObj.SetGlyphType(GLIPH_TYPE[random.randint(0, len(GLIPH_TYPE)-1)])
935 anObj.SetGlyphPos(GLIPH_POS[random.randint(0, len(GLIPH_POS)-1)])
939 def dump_vetctors_parameters(theObject):
941 dump_deformedshape_parameters(theObject)
943 print "GetLineWidth() = " +str(theObject.GetLineWidth())
944 print "GetGlyphType() = " +str(theObject.GetGlyphType())
945 print "GetGlyphPos() = " +str(theObject.GetGlyphPos())
948 # ----------------------
950 # ----------------------
952 def try_isosurfaces_parameters(thePattern) :
953 if thePattern is None : return None
957 anObj = try_scalarmap_parameters(thePattern)
958 ind = random.randint(1,2)
959 # --- SURFACES NUMBER ---
961 anObj.SetNbSurfaces(random.randint(-100000,100000))
963 anObj.SetNbSurfaces(random.randint(1, 50))
967 def dump_isosurfaces_parameters(theObject):
969 dump_scalarmap_parameters(theObject)
970 print "GetNbSurfaces() = "+ str(theObject.GetNbSurfaces())
973 # ----------------------
975 # ----------------------
977 def FillTable( theTable, theValues, theRows, theColumns, theRowTitles, theRowUnits, theColumnTitles ):
978 if theTable is None: return
979 if len(theRows) != len(theColumns): return
980 if len(theRows) != len(theValues): return
982 for value in theValues:
983 theTable.PutValue( value, theRows[ i ], theColumns[ i ])
987 for title in theRowTitles:
988 theTable.SetRowTitle( i, title )
989 theTable.SetRowUnit( i, theRowUnits[ i - 1 ])
993 for title in theColumnTitles:
994 theTable.SetColumnTitle( i, title )
999 def CreateCurve( theTable, theHRow, theVRow, theTitle, theColor, theMarker, theLineType, theLineWidth ):
1000 if theTitle is None: return
1001 curve = myLocalVisu.CreateCurve( theTable, theHRow, theVRow );
1003 curve.SetTitle( theTitle )
1004 curve.SetColor( theColor )
1005 curve.SetMarker( theMarker )
1006 curve.SetLine( theLineType, theLineWidth )