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 anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
349 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
350 aFolderName = anAttr.Value()
351 print " ", aFolderName
353 if aFolderName == 'Families' :
354 anEntityIter = myLocalStudy.NewChildIterator(aFolderSObj);
355 while anEntityIter.More() :
356 anEntitySObj = anEntityIter.Value()
358 anAttr = anEntitySObj.FindAttribute("AttributeName")[1]
359 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
360 anEntityName = anAttr.Value()
363 if anEntityName == 'onNodes' :
366 if anEntityName == 'onEdges' :
369 if anEntityName == 'onFaces' :
372 if anEntityName == 'onCells' :
376 if HasValue(thePrsTypeList,VISU.TMESH) :
377 print " ", anEntityName, aMeshName,
378 aMesh = theVisu.MeshOnEntity(theResult,aMeshName,anEntity)
379 if aMesh is None : print "Error"
382 theView.DisplayOnly(aMesh)
384 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "." + thePictureExt
385 aPictureName = re.sub("\s+","_", aPictureName);
386 theView.SavePicture(aPictureName)
388 aMesh.RemoveFromStudy()
390 aVISUObjList.append(aMesh)
392 anFamilyIter = myLocalStudy.NewChildIterator(anEntitySObj);
393 while anFamilyIter.More() :
394 aFamilySObj = anFamilyIter.Value()
396 anAttr = aFamilySObj.FindAttribute("AttributeName")[1]
397 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
398 anFamilyName = anAttr.Value()
399 if HasValue(thePrsTypeList,VISU.TMESH) :
400 print " ", anFamilyName,
401 aMesh = theVisu.FamilyMeshOnEntity(theResult,aMeshName,anEntity,anFamilyName)
402 if aMesh is None : print "Error"
405 theView.DisplayOnly(aMesh)
407 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + anFamilyName + "." + thePictureExt
408 aPictureName = re.sub("\s+","_", aPictureName);
409 theView.SavePicture(aPictureName)
411 aMesh.RemoveFromStudy()
413 aVISUObjList.append(aMesh)
415 if aFolderName == 'Groups' :
416 aGroupIter = myLocalStudy.NewChildIterator(aFolderSObj);
417 while aGroupIter.More() :
418 aGroupSObj = aGroupIter.Value()
420 anAttr = aGroupSObj.FindAttribute("AttributeName")[1]
421 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
422 aGroupName = anAttr.Value()
423 if HasValue(thePrsTypeList,VISU.TMESH) :
424 print " ", aGroupName,
425 aMesh = theVisu.GroupMesh(theResult,aMeshName,aGroupName)
426 if aMesh is None : print "Error"
429 theView.DisplayOnly(aMesh)
431 aPictureName = thePictureDir + aMeshNamePic + "_" + aGroupName + "." + thePictureExt
432 aPictureName = re.sub("\s+","_", aPictureName);
433 theView.SavePicture(aPictureName)
435 aMesh.RemoveFromStudy()
437 aVISUObjList.append(aMesh)
439 if aFolderName == 'Fields' :
440 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
441 while aFieldIter.More() :
442 aFieldSObj = aFieldIter.Value()
444 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
445 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
446 aFieldName = anAttr.Value()
447 print " ", aFieldName
449 anAttr = aFieldSObj.FindAttribute("AttributeComment")[1]
450 anAttr = anAttr._narrow(SALOMEDS.AttributeComment);
451 aFieldComment = anAttr.Value()
452 aMap = StrToMap(aFieldComment)
454 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
455 if aTimeStampIter.More() :
456 aTimeStampIter.Next()
457 while aTimeStampIter.More() :
458 aTimeStampSObj = aTimeStampIter.Value()
459 aTimeStampIter.Next()
460 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
461 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
462 aTimeStampName = anAttr.Value()
463 print " ", aTimeStampName
465 anAttr = aTimeStampSObj.FindAttribute("AttributeComment")[1]
466 anAttr = anAttr._narrow(SALOMEDS.AttributeComment);
467 aTimeStampComment = anAttr.Value()
468 aMap = StrToMap(aTimeStampComment)
469 aMeshName = aMap["myMeshName"]
470 aFieldName = aMap["myFieldName"]
471 aTimeStampId = atoi(aMap["myTimeStampId"])
472 anEntity = IntToEntity(aMap["myEntityId"])
473 anEntityId = str(aMap["myEntityId"]);
474 #print aMeshName, aFieldName, anEntity, aTimeStampId
475 if HasValue(thePrsTypeList,VISU.TSCALARMAP) :
476 print " Creating ScalarMapOnField",
477 aPrsObj = theVisu.ScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
478 if aPrsObj is None : print "Error"
481 theView.DisplayOnly(aPrsObj)
483 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAP." + thePictureExt
484 aPictureName = re.sub("\s+","_", aPictureName);
485 theView.SavePicture(aPictureName)
487 aPrsObj.RemoveFromStudy()
489 aVISUObjList.append(aPrsObj)
491 if HasValue(thePrsTypeList,VISU.TISOSURFACE) :
492 print " Creating IsoSurfacesOnField",
493 aPrsObj = theVisu.IsoSurfacesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
494 if aPrsObj is None : print "Error"
497 theView.DisplayOnly(aPrsObj)
499 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TISOSURFACE." + thePictureExt
500 aPictureName = re.sub("\s+","_", aPictureName);
501 theView.SavePicture(aPictureName)
503 aPrsObj.RemoveFromStudy()
505 aVISUObjList.append(aPrsObj)
507 if HasValue(thePrsTypeList,VISU.TCUTPLANES) :
508 print " Creating CutPlanesOnField",
509 aPrsObj = theVisu.CutPlanesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
510 if aPrsObj is None : print "Error"
513 aPrsObj.SetOrientation(VISU.CutPlanes.ZX,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
514 theView.DisplayOnly(aPrsObj)
516 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTPLANES." + thePictureExt
517 aPictureName = re.sub("\s+","_", aPictureName)
518 theView.SavePicture(aPictureName)
520 aPrsObj.RemoveFromStudy()
522 aVISUObjList.append(aPrsObj)
524 if HasValue(thePrsTypeList,VISU.TCUTLINES) :
525 print " Creating CutLinesOnField",
526 aPrsObj = theVisu.CutLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
527 if aPrsObj is None : print "Error"
530 aPrsObj.SetOrientation(VISU.CutPlanes.XY,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
531 aPrsObj.SetOrientation2(VISU.CutPlanes.ZX,aPrsObj.GetRotateX2(),aPrsObj.GetRotateY2())
532 theView.DisplayOnly(aPrsObj)
534 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTLINES." + thePictureExt
535 aPictureName = re.sub("\s+","_", aPictureName)
536 theView.SavePicture(aPictureName)
538 aPrsObj.RemoveFromStudy()
540 aVISUObjList.append(aPrsObj)
542 if HasValue(thePrsTypeList,VISU.TPLOT3D) :
543 print " Creating Plot3DOnField",
544 aPrsObj = theVisu.Plot3DOnField(theResult,aMeshName,anEntity,
545 aFieldName,aTimeStampId)
546 if aPrsObj is None : print "Error"
549 #aPrsObj.SetOrientation(VISU.CutPlanes.ZX,
550 # aPrsObj.GetRotateX(),
551 # aPrsObj.GetRotateY())
552 theView.DisplayOnly(aPrsObj)
554 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TPLOT3D." + thePictureExt
555 aPictureName = re.sub("\s+","_", aPictureName)
556 theView.SavePicture(aPictureName)
558 aPrsObj.RemoveFromStudy()
560 aVISUObjList.append(aPrsObj)
562 aNumComponent = atoi(aMap["myNumComponent"])
563 if aNumComponent > 1 :
564 if HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPE) :
565 print " Creating DeformedShapeOnField",
566 aPrsObj = theVisu.DeformedShapeOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
567 if aPrsObj is None : print "Error"
570 theView.DisplayOnly(aPrsObj)
572 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPE." + thePictureExt
573 aPictureName = re.sub("\s+","_", aPictureName)
574 theView.SavePicture(aPictureName)
576 aPrsObj.RemoveFromStudy()
578 aVISUObjList.append(aPrsObj)
580 if HasValue(thePrsTypeList,VISU.TVECTORS) :
581 print " Creating VectorsOnField",
582 aPrsObj = theVisu.VectorsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
583 if aPrsObj is None : print "Error"
586 theView.DisplayOnly(aPrsObj)
588 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TVECTORS." + thePictureExt
589 aPictureName = re.sub("\s+","_", aPictureName)
590 theView.SavePicture(aPictureName)
592 aPrsObj.RemoveFromStudy()
594 aVISUObjList.append(aPrsObj)
596 if HasValue(thePrsTypeList,VISU.TSTREAMLINES) :
597 print " Creating StreamLinesOnField",
598 aPrsObj = theVisu.StreamLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
599 if aPrsObj is None : print "Error"
602 theView.DisplayOnly(aPrsObj)
604 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSTREAMLINES." + thePictureExt
605 aPictureName = re.sub("\s+","_", aPictureName)
606 theView.SavePicture(aPictureName)
608 aPrsObj.RemoveFromStudy()
610 aVISUObjList.append(aPrsObj)
612 if HasValue(thePrsTypeList,VISU.TSCALARMAPONDEFORMEDSHAPE) :
613 print " Creating ScalarMapOnDeformedShapeOnField",
614 aPrsObj = theVisu.ScalarMapOnDeformedShapeOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
615 if aPrsObj is None : print "Error"
618 theView.DisplayOnly(aPrsObj)
620 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAPONDEFORMEDSHAPE." + thePictureExt
621 aPictureName = re.sub("\s+","_", aPictureName)
622 theView.SavePicture(aPictureName)
624 aPrsObj.RemoveFromStudy()
626 aVISUObjList.append(aPrsObj)
631 def generateName(prefix = None):
633 int = whrandom.randint(1,1000);
635 return "Study" + str(int)
637 return prefix + str(int)
641 # ----------------------
643 # ----------------------
644 def try_mesh_parameters(theMeshPattern):
646 if theMeshPattern is None : return aResult ;
647 theMeshPattern = theMeshPattern._narrow(VISU.Mesh)
648 if theMeshPattern is None : return aResult ;
650 aTYPES = [VISU.POINT, VISU.WIREFRAME, VISU.SHADED, VISU.INSIDEFRAME, VISU.SHRINK]
651 import copy; import os;
653 aNewMesh = copy.deepcopy(theMeshPattern);
654 aNewMesh.SetPresentationType(ind)
655 aResult.append(aNewMesh)
660 # ----------------------------
662 # ----------------------------
664 def try_scalarmap_parameters(thePattern, dump = 0):
666 if thePattern is None : return None
668 SCALING = [VISU.LINEAR, VISU.LOGARITHMIC]
672 anObj = thePattern#copy.deepcopy(thePattern);
673 #ind = random.randint(1,2)
675 #try incorrect value deliberately (but allowed by idl description)
676 #try SetScalarMode(long)
677 mode = random.randint(-100000,100000); #incorrect value deliberately
679 #correct value of ScalarMode
680 mode = random.randint(0, 3)
682 if dump : print "\tSetScalarMode(" + str(mode) +")"
683 anObj.SetScalarMode(mode)
686 scal = random.randint(0,1)
687 if dump : print "\tSetScaling(" + str(SCALING[scal]) +")"
688 anObj.SetScaling(SCALING[scal])
692 alfa = random.random()*random.randint(-100000,100000)
693 betta = random.random()*random.randint(-100000,100000)
694 aMin = alfa; aMax = betta
697 aPMin = thePattern.GetMin()
698 aPMax = thePattern.GetMax()
700 alfa = random.random()%0.5
701 betta = random.random()%0.5
702 aMin = alfa*aLen*random.randint(-1,1) + aPMin
703 aMax = betta*aLen*random.randint(-1,1) + aPMax
704 if dump : print "\tSetRange(" + str(aMin) + ", " + str(aMax) + ")"
705 anObj.SetRange(aMin, aMax)
709 X=random.random()*random.randint(-100000,100000)
710 Y=random.random()*random.randint(-100000,100000)
714 if dump : print "SetPosition("+ str(X) + ", " + str(Y) + " )"
715 anObj.SetPosition(X, Y)
717 # --- SCALAR BAR SIZE ---
719 aWidth=random.random()*random.randint(-100000,100000)
720 aHeight=random.random()*random.randint(-100000,100000)
722 aWidth=random.random()
723 aHeight=random.random()
724 if dump : print " SCALAR BAR Width = " + str(aWidth) + " Height = ", str(aHeight)
725 anObj.SetSize(aWidth, aHeight)
730 def dump_scalarmap_parameters(anObj):
732 print "\tGetScalarMode() = " + str(anObj.GetScalarMode())
733 print "\tGetScaling() = " + str(anObj.GetScaling())
734 print "\tGetMin() = " + str(anObj.GetMin()) + " GetMax() = " + str (anObj.GetMax())
735 print "\tGetOrientation() = " + str(anObj.GetOrientation())
736 print "\tGetPosX() = ", str(anObj.GetPosX()) + " GetPosY() = ", str(anObj.GetPosY())
737 print "\tGetWidth() = ", str ( anObj.GetWidth()) + " GetHeight() = " + str(anObj.GetHeight())
739 # ----------------------
741 # ----------------------
742 def try_deformedshape_parameters(thePattern) :
744 if thePattern is None : return None
748 anObj = try_scalarmap_parameters(thePattern)
752 anObj.SetScale( random.random()*random.randint(-100000, 100000))
754 anObj.SetScale( anObj.GetScale()*random.random())
759 def dump_deformedshape_parameters(theObject):
760 dump_scalarmap_parameters(theObject)
761 print "GetScale() = ", theObject.GetScale()
763 # ----------------------
765 # ----------------------
766 def try_cutplanes_parameters(thePattern) :
768 if thePattern is None : return None
772 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
774 ind = random.randint(1,2)
775 anObj = try_scalarmap_parameters(thePattern)
777 if ind%2 : anObj.SetNbPlanes(random.randint(-40,40))
778 else : anObj.SetNbPlanes(random.randint(0,10)) #try behaivor if NbPlanes=0
780 # --- DISPLACEMENT ---
781 anObj.SetDisplacement(random.randint(-100000,100000))
783 # --- PLANE POSITION ---
785 PlaneNb = random.randint(-100000,100000) #incorrect value is possible
786 else : PlaneNb = random.randint(0, anObj.GetNbPlanes())
788 anObj.SetPlanePosition(PlaneNb, random.random()*random.randint(-100000,100000))
790 # --- SET DEFAULT ---
791 anObj.SetDefault(PlaneNb)
793 # --- SET X,Y,Z ROTATION ---
795 angle1 = random.random()*random.randint(-100000,100000)
796 angle2 = random.random()*random.randint(-100000,100000)
798 angle1 = random.random()*3.14
799 angle2 = random.random()*3.14
801 # --- ORIENTATION ---
802 anObj.SetOrientation(ORIENT[random.randint(0,2)],angle1,angle2)
806 def dump_cutplanes_parameters(theObject):
807 dump_saclarmap_parameters(theObject)
809 print "GetOrientationType = " + str(theObject.GetOrientationType())
810 PlanesNb = theObject.GetNbPlanes()
811 print "GetNbPlanes() = ", str(PlanesNb)
812 for i in range(0,PlanesNb+1):
813 if theObject.IsDefault(i) :
814 print "Default plane : "+str(i); break
815 print "GetPlanePosition(" + str(i) + ") = ", theObject.GetPlanePosition(i)
816 print "GetDisplacement() = ", str(theObject.GetDisplacement())
817 print "GetRotateX() = ", str(theObject.GetRotateX())
818 print "GetRotateY() = ", str(theObject.GetRotateY())
819 print "GetRotateZ() = ", str(theObject.GetRotateZ())
821 # ----------------------
823 # ----------------------
824 def try_cutlines_parameters(thePattern):
826 if thePattern is None : return None
830 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
831 ind = random.randint(1,2)
832 anObj = try_scalarmap_parameters(thePattern)
834 # --- ORIENTATION ---
835 anObj.SetOrientation(ORIENT[random.randint(0,2)],
836 random.randint(-100,100)*random.random(),
837 random.randint(-100,100)*random.random())
838 anObj.SetOrientation2(ORIENT[random.randint(0,2)],
839 random.randint(-100,100)*random.random(),
840 random.randint(-100,100)*random.random())
842 # --- Base Plane Position ---
843 anObj.SetBasePlanePosition( random.random()*random.randint(-100000,100000))
845 # --- NUMBER OF LINES ---
847 anObj.SetNbLines(random.randint(-5, 50))
851 def dump_cutlines_parameters(theObject):
852 dump_scalarmap_parameters(theObject)
854 print "GetOrientationType() = " + str(theObject.GetOrientationType())
855 print "GetOrientationType2() = " + str(theObject.GetOrientationType2())
856 print "GetBasePlanePosition() = "+ str(theObject.GetBasePlanePosition())
857 print "GetNbLines() = " + str(theObject.GetNbLines())
858 print "GetRotateX() = ", str(theObject.GetRotateX())
859 print "GetRotateX2() = ", str(theObject.GetRotateX2())
860 print "GetRotateY() = ", str(theObject.GetRotateY())
861 print "GetRotateY2() = ", str(theObject.GetRotateY2())
863 # ----------------------
865 # ----------------------
866 def try_streamlines_parameters(thePattern):
868 if thePattern is None : return None
872 DIRECTION = [VISU.StreamLines.FORWARD, VISU.StreamLines.BACKWARD, VISU.StreamLines.BOTH]
874 ind = random.randint(1,2)
875 anObj = (try_deformedshape_parameters(thePattern))[0]
878 anObj.SetDirection(DIRECTION[random.randint(0,2)])
880 # --- STEP LENGTH ---
881 if ind%2 : anObj.SetStepLength(random.random()*random.randint(-1000,1000))
883 aLen = anObj.GetMax() - anObj.GetMin()
884 anObj.SetStepLength(aLen/random.randint(1,100))
886 # --- PROPAGATION TIME ---
887 anObj.SetPropagationTime(random.random()*random.randint(1,100))
889 # --- INTEGRATION STEP ---
891 anObj.SetIntegrationStep(random.random()*random.randint(-1000,1000))
893 anObj.SetIntegrationStep(random.random())
896 anObj.SetUsedPoints(random.random()*random.randint(-10000,10000))
900 def dump_streamlines_parameters(theObject):
902 dump_deformedshape_parameters(theObject)
904 print "GetDirection() = " + str(theObject.GetDirection())
905 print "GetStepLength() = " + str(theObject.GetStepLength())
906 print "GetPropagationTime() =" + str(theObject.GetPropagationTime())
907 print "GetIntegrationStep() =" + str(theObject.GetIntegrationStep())
908 print "GetUsedPoints() =" + str(theObject.GetUsedPoints())
910 # ----------------------
912 # ----------------------
913 def try_vectors_parameters(thePattern, theNum):
915 if thePattern is None : return None
918 GLIPH_TYPE = [VISU.Vectors.ARROW, VISU.Vectors.CONE2, VISU.Vectors.CONE6, VISU.Vectors.NONE]
919 GLIPH_POS = [VISU.Vectors.CENTER, VISU.Vectors.TAIL, VISU.Vectors.HEAD]
920 ind = random.randint(1,2)
921 anObj = (try_deformedshape_parameters(thePattern))[0]
925 anObj.SetLineWidth(random.random()*random.randint(-10000,10000))
927 anObj.SetLineWidth(random.randint(1, 10))
930 anObj.SetGlyphType(GLIPH_TYPE[random.randint(0, len(GLIPH_TYPE)-1)])
933 anObj.SetGlyphPos(GLIPH_POS[random.randint(0, len(GLIPH_POS)-1)])
937 def dump_vetctors_parameters(theObject):
939 dump_deformedshape_parameters(theObject)
941 print "GetLineWidth() = " +str(theObject.GetLineWidth())
942 print "GetGlyphType() = " +str(theObject.GetGlyphType())
943 print "GetGlyphPos() = " +str(theObject.GetGlyphPos())
946 # ----------------------
948 # ----------------------
950 def try_isosurfaces_parameters(thePattern) :
951 if thePattern is None : return None
955 anObj = try_scalarmap_parameters(thePattern)
956 ind = random.randint(1,2)
957 # --- SURFACES NUMBER ---
959 anObj.SetNbSurfaces(random.randint(-100000,100000))
961 anObj.SetNbSurfaces(random.randint(1, 50))
965 def dump_isosurfaces_parameters(theObject):
967 dump_scalarmap_parameters(theObject)
968 print "GetNbSurfaces() = "+ str(theObject.GetNbSurfaces())
971 # ----------------------
973 # ----------------------
975 def FillTable( theTable, theValues, theRows, theColumns, theRowTitles, theRowUnits, theColumnTitles ):
976 if theTable is None: return
977 if len(theRows) != len(theColumns): return
978 if len(theRows) != len(theValues): return
980 for value in theValues:
981 theTable.PutValue( value, theRows[ i ], theColumns[ i ])
985 for title in theRowTitles:
986 theTable.SetRowTitle( i, title )
987 theTable.SetRowUnit( i, theRowUnits[ i - 1 ])
991 for title in theColumnTitles:
992 theTable.SetColumnTitle( i, title )
997 def CreateCurve( theTable, theHRow, theVRow, theTitle, theColor, theMarker, theLineType, theLineWidth ):
998 if theTitle is None: return
999 curve = myLocalVisu.CreateCurve( theTable, theHRow, theVRow );
1001 curve.SetTitle( theTitle )
1002 curve.SetColor( theColor )
1003 curve.SetMarker( theMarker )
1004 curve.SetLine( theLineType, theLineWidth )