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, theIsAutoDelete = 0) :
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"
208 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
210 aResult.RemoveFromStudy()
212 aVISUObjList.append(aResult)
214 aFolderIter = myLocalStudy.NewChildIterator(aMedSObj.GetFather());
215 while aFolderIter.More() :
216 aFolderSObj = aFolderIter.Value()
218 anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
219 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
220 aFolderName = anAttr.Value()
221 print " ", aFolderName
223 if aFolderName == 'MEDMESH' :
224 aMeshIter = myLocalStudy.NewChildIterator(aFolderSObj);
225 while aMeshIter.More() :
226 aMeshSObj = aMeshIter.Value()
228 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
229 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
230 aMeshName = anAttr.Value()
233 aSupportIter = myLocalStudy.NewChildIterator(aMeshSObj);
234 while aSupportIter.More() :
235 aSupportSObj = aSupportIter.Value()
237 anAttr = aSupportSObj.FindAttribute("AttributeName")[1]
238 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
239 aSupportName = anAttr.Value()
240 print " ", aSupportName
242 if aFolderName == 'MEDFIELD' :
243 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
244 while aFieldIter.More() :
245 aFieldSObj = aFieldIter.Value()
247 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
248 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
249 aFieldName = anAttr.Value()
250 print " ", aFieldName
252 print "theVisu.ImportMed...",
253 aResult = theVisu.ImportMed(aFieldSObj)
254 if aResult is None : raise RuntimeError, "Error"
257 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
259 aResult.RemoveFromStudy()
261 aVISUObjList.append(aResult)
263 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
264 if aTimeStampIter.More() :
265 aTimeStampIter.Next()
266 while aTimeStampIter.More() :
267 aTimeStampSObj = aTimeStampIter.Value()
268 aTimeStampIter.Next()
269 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
270 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
271 aTimeStampName = anAttr.Value()
272 print " ", aTimeStampName
274 print "theVisu.ImportMed...",
275 aMedField = SObjectToObject(aTimeStampSObj)
276 aResult = theVisu.ImportMedField(aMedField)
277 if aResult is None : raise RuntimeError, "Error"
280 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
282 aResult.RemoveFromStudy()
284 aVISUObjList.append(aResult)
288 # except Exception, e:
291 def CreatePrsForFile(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
293 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
295 print "theVisu.ImportMed...",
296 aResult = theVisu.ImportFile(theFileName)
297 if aResult is None : raise RuntimeError, "Error"
300 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
303 aResult.RemoveFromStudy()
305 aVISUObjList.append(aResult)
309 # except Exception, e:
312 def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
314 if theIsAutoDelete is not None :
318 print "CreatePrsForResult - myLocalStudy.FindObjectIOR...",
319 myLocalStudy = theVisu.GetCurrentStudy()
321 aSObj = myLocalStudy.FindObjectIOR(theResult.GetID())
322 if aSObj is None : raise RuntimeError, "Error"
324 aMeshIter = myLocalStudy.NewChildIterator(aSObj);
325 while aMeshIter.More() :
326 aMeshSObj = aMeshIter.Value()
328 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
330 aMeshSObj = aMeshIter.Value()
332 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
333 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
334 aMeshName = anAttr.Value()
335 aMeshNamePic = re.sub(".","_",aMeshName)
338 aFolderIter = myLocalStudy.NewChildIterator(aMeshSObj);
339 while aFolderIter.More() :
340 aFolderSObj = aFolderIter.Value()
342 anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
343 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
344 aFolderName = anAttr.Value()
345 print " ", aFolderName
347 if aFolderName == 'Families' :
348 anEntityIter = myLocalStudy.NewChildIterator(aFolderSObj);
349 while anEntityIter.More() :
350 anEntitySObj = anEntityIter.Value()
352 anAttr = anEntitySObj.FindAttribute("AttributeName")[1]
353 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
354 anEntityName = anAttr.Value()
357 if anEntityName == 'onNodes' :
360 if anEntityName == 'onEdges' :
363 if anEntityName == 'onFaces' :
366 if anEntityName == 'onCells' :
370 if HasValue(thePrsTypeList,VISU.TMESH) :
371 print " ", anEntityName, aMeshName,
372 aMesh = theVisu.MeshOnEntity(theResult,aMeshName,anEntity)
373 if aMesh is None : print "Error"
376 theView.DisplayOnly(aMesh)
378 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "." + thePictureExt
379 aPictureName = re.sub("\s+","_", aPictureName);
380 theView.SavePicture(aPictureName)
382 aMesh.RemoveFromStudy()
384 aVISUObjList.append(aMesh)
386 anFamilyIter = myLocalStudy.NewChildIterator(anEntitySObj);
387 while anFamilyIter.More() :
388 aFamilySObj = anFamilyIter.Value()
390 anAttr = aFamilySObj.FindAttribute("AttributeName")[1]
391 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
392 anFamilyName = anAttr.Value()
393 if HasValue(thePrsTypeList,VISU.TMESH) :
394 print " ", anFamilyName,
395 aMesh = theVisu.FamilyMeshOnEntity(theResult,aMeshName,anEntity,anFamilyName)
396 if aMesh is None : print "Error"
399 theView.DisplayOnly(aMesh)
401 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + anFamilyName + "." + thePictureExt
402 aPictureName = re.sub("\s+","_", aPictureName);
403 theView.SavePicture(aPictureName)
405 aMesh.RemoveFromStudy()
407 aVISUObjList.append(aMesh)
409 if aFolderName == 'Groups' :
410 aGroupIter = myLocalStudy.NewChildIterator(aFolderSObj);
411 while aGroupIter.More() :
412 aGroupSObj = aGroupIter.Value()
414 anAttr = aGroupSObj.FindAttribute("AttributeName")[1]
415 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
416 aGroupName = anAttr.Value()
417 if HasValue(thePrsTypeList,VISU.TMESH) :
418 print " ", aGroupName,
419 aMesh = theVisu.GroupMesh(theResult,aMeshName,aGroupName)
420 if aMesh is None : print "Error"
423 theView.DisplayOnly(aMesh)
425 aPictureName = thePictureDir + aMeshNamePic + "_" + aGroupName + "." + thePictureExt
426 aPictureName = re.sub("\s+","_", aPictureName);
427 theView.SavePicture(aPictureName)
429 aMesh.RemoveFromStudy()
431 aVISUObjList.append(aMesh)
433 if aFolderName == 'Fields' :
434 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
435 while aFieldIter.More() :
436 aFieldSObj = aFieldIter.Value()
438 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
439 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
440 aFieldName = anAttr.Value()
441 print " ", aFieldName
443 anAttr = aFieldSObj.FindAttribute("AttributeComment")[1]
444 anAttr = anAttr._narrow(SALOMEDS.AttributeComment);
445 aFieldComment = anAttr.Value()
446 aMap = StrToMap(aFieldComment)
448 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
449 if aTimeStampIter.More() :
450 aTimeStampIter.Next()
451 while aTimeStampIter.More() :
452 aTimeStampSObj = aTimeStampIter.Value()
453 aTimeStampIter.Next()
454 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
455 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
456 aTimeStampName = anAttr.Value()
457 print " ", aTimeStampName
459 anAttr = aTimeStampSObj.FindAttribute("AttributeComment")[1]
460 anAttr = anAttr._narrow(SALOMEDS.AttributeComment);
461 aTimeStampComment = anAttr.Value()
462 aMap = StrToMap(aTimeStampComment)
463 aMeshName = aMap["myMeshName"]
464 aFieldName = aMap["myFieldName"]
465 aTimeStampId = atoi(aMap["myTimeStampId"])
466 anEntity = IntToEntity(aMap["myEntityId"])
467 anEntityId = str(aMap["myEntityId"]);
468 #print aMeshName, aFieldName, anEntity, aTimeStampId
469 if HasValue(thePrsTypeList,VISU.TSCALARMAP) :
470 print " Creating ScalarMapOnField",
471 aPrsObj = theVisu.ScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
472 if aPrsObj is None : print "Error"
475 theView.DisplayOnly(aPrsObj)
477 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAP." + thePictureExt
478 aPictureName = re.sub("\s+","_", aPictureName);
479 theView.SavePicture(aPictureName)
481 aPrsObj.RemoveFromStudy()
483 aVISUObjList.append(aPrsObj)
485 if HasValue(thePrsTypeList,VISU.TISOSURFACE) :
486 print " Creating IsoSurfacesOnField",
487 aPrsObj = theVisu.IsoSurfacesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
488 if aPrsObj is None : print "Error"
491 theView.DisplayOnly(aPrsObj)
493 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TISOSURFACE." + thePictureExt
494 aPictureName = re.sub("\s+","_", aPictureName);
495 theView.SavePicture(aPictureName)
497 aPrsObj.RemoveFromStudy()
499 aVISUObjList.append(aPrsObj)
501 if HasValue(thePrsTypeList,VISU.TCUTPLANES) :
502 print " Creating CutPlanesOnField",
503 aPrsObj = theVisu.CutPlanesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
504 if aPrsObj is None : print "Error"
507 aPrsObj.SetOrientation(VISU.CutPlanes.ZX,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
508 theView.DisplayOnly(aPrsObj)
510 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTPLANES." + thePictureExt
511 aPictureName = re.sub("\s+","_", aPictureName)
512 theView.SavePicture(aPictureName)
514 aPrsObj.RemoveFromStudy()
516 aVISUObjList.append(aPrsObj)
518 if HasValue(thePrsTypeList,VISU.TCUTLINES) :
519 print " Creating CutLinesOnField",
520 aPrsObj = theVisu.CutLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
521 if aPrsObj is None : print "Error"
524 aPrsObj.SetOrientation(VISU.CutPlanes.XY,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
525 aPrsObj.SetOrientation2(VISU.CutPlanes.ZX,aPrsObj.GetRotateX2(),aPrsObj.GetRotateY2())
526 theView.DisplayOnly(aPrsObj)
528 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTLINES." + thePictureExt
529 aPictureName = re.sub("\s+","_", aPictureName)
530 theView.SavePicture(aPictureName)
532 aPrsObj.RemoveFromStudy()
534 aVISUObjList.append(aPrsObj)
536 if HasValue(thePrsTypeList,VISU.TPLOT3D) :
537 print " Creating Plot3DOnField",
538 aPrsObj = theVisu.Plot3DOnField(theResult,aMeshName,anEntity,
539 aFieldName,aTimeStampId)
540 if aPrsObj is None : print "Error"
543 #aPrsObj.SetOrientation(VISU.CutPlanes.ZX,
544 # aPrsObj.GetRotateX(),
545 # aPrsObj.GetRotateY())
546 theView.DisplayOnly(aPrsObj)
548 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TPLOT3D." + thePictureExt
549 aPictureName = re.sub("\s+","_", aPictureName)
550 theView.SavePicture(aPictureName)
552 aPrsObj.RemoveFromStudy()
554 aVISUObjList.append(aPrsObj)
556 aNumComponent = atoi(aMap["myNumComponent"])
557 if aNumComponent > 1 :
558 if HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPE) :
559 print " Creating DeformedShapeOnField",
560 aPrsObj = theVisu.DeformedShapeOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
561 if aPrsObj is None : print "Error"
564 theView.DisplayOnly(aPrsObj)
566 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPE." + thePictureExt
567 aPictureName = re.sub("\s+","_", aPictureName)
568 theView.SavePicture(aPictureName)
570 aPrsObj.RemoveFromStudy()
572 aVISUObjList.append(aPrsObj)
574 if HasValue(thePrsTypeList,VISU.TVECTORS) :
575 print " Creating VectorsOnField",
576 aPrsObj = theVisu.VectorsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
577 if aPrsObj is None : print "Error"
580 theView.DisplayOnly(aPrsObj)
582 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TVECTORS." + thePictureExt
583 aPictureName = re.sub("\s+","_", aPictureName)
584 theView.SavePicture(aPictureName)
586 aPrsObj.RemoveFromStudy()
588 aVISUObjList.append(aPrsObj)
590 if HasValue(thePrsTypeList,VISU.TSTREAMLINES) :
591 print " Creating StreamLinesOnField",
592 aPrsObj = theVisu.StreamLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
593 if aPrsObj is None : print "Error"
596 theView.DisplayOnly(aPrsObj)
598 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSTREAMLINES." + thePictureExt
599 aPictureName = re.sub("\s+","_", aPictureName)
600 theView.SavePicture(aPictureName)
602 aPrsObj.RemoveFromStudy()
604 aVISUObjList.append(aPrsObj)
608 def generateName(prefix = None):
610 int = whrandom.randint(1,1000);
612 return "Study" + str(int)
614 return prefix + str(int)
618 # ----------------------
620 # ----------------------
621 def try_mesh_parameters(theMeshPattern):
623 if theMeshPattern is None : return aResult ;
624 theMeshPattern = theMeshPattern._narrow(VISU.Mesh)
625 if theMeshPattern is None : return aResult ;
627 aTYPES = [VISU.POINT, VISU.WIREFRAME, VISU.SHADED, VISU.INSIDEFRAME, VISU.SHRINK]
628 import copy; import os;
630 aNewMesh = copy.deepcopy(theMeshPattern);
631 aNewMesh.SetPresentationType(ind)
632 aResult.append(aNewMesh)
637 # ----------------------------
639 # ----------------------------
641 def try_scalarmap_parameters(thePattern, dump = 0):
643 if thePattern is None : return None
645 SCALING = [VISU.LINEAR, VISU.LOGARITHMIC]
649 anObj = thePattern#copy.deepcopy(thePattern);
650 #ind = random.randint(1,2)
652 #try incorrect value deliberately (but allowed by idl description)
653 #try SetScalarMode(long)
654 mode = random.randint(-100000,100000); #incorrect value deliberately
656 #correct value of ScalarMode
657 mode = random.randint(0, 3)
659 if dump : print "\tSetScalarMode(" + str(mode) +")"
660 anObj.SetScalarMode(mode)
663 scal = random.randint(0,1)
664 if dump : print "\tSetScaling(" + str(SCALING[scal]) +")"
665 anObj.SetScaling(SCALING[scal])
669 alfa = random.random()*random.randint(-100000,100000)
670 betta = random.random()*random.randint(-100000,100000)
671 aMin = alfa; aMax = betta
674 aPMin = thePattern.GetMin()
675 aPMax = thePattern.GetMax()
677 alfa = random.random()%0.5
678 betta = random.random()%0.5
679 aMin = alfa*aLen*random.randint(-1,1) + aPMin
680 aMax = betta*aLen*random.randint(-1,1) + aPMax
681 if dump : print "\tSetRange(" + str(aMin) + ", " + str(aMax) + ")"
682 anObj.SetRange(aMin, aMax)
686 X=random.random()*random.randint(-100000,100000)
687 Y=random.random()*random.randint(-100000,100000)
691 if dump : print "SetPosition("+ str(X) + ", " + str(Y) + " )"
692 anObj.SetPosition(X, Y)
694 # --- SCALAR BAR SIZE ---
696 aWidth=random.random()*random.randint(-100000,100000)
697 aHeight=random.random()*random.randint(-100000,100000)
699 aWidth=random.random()
700 aHeight=random.random()
701 if dump : print " SCALAR BAR Width = " + str(aWidth) + " Height = ", str(aHeight)
702 anObj.SetSize(aWidth, aHeight)
707 def dump_scalarmap_parameters(anObj):
709 print "\tGetScalarMode() = " + str(anObj.GetScalarMode())
710 print "\tGetScaling() = " + str(anObj.GetScaling())
711 print "\tGetMin() = " + str(anObj.GetMin()) + " GetMax() = " + str (anObj.GetMax())
712 print "\tGetOrientation() = " + str(anObj.GetOrientation())
713 print "\tGetPosX() = ", str(anObj.GetPosX()) + " GetPosY() = ", str(anObj.GetPosY())
714 print "\tGetWidth() = ", str ( anObj.GetWidth()) + " GetHeight() = " + str(anObj.GetHeight())
716 # ----------------------
718 # ----------------------
719 def try_deformedshape_parameters(thePattern) :
721 if thePattern is None : return None
725 anObj = try_scalarmap_parameters(thePattern)
729 anObj.SetScale( random.random()*random.randint(-100000, 100000))
731 anObj.SetScale( anObj.GetScale()*random.random())
736 def dump_deformedshape_parameters(theObject):
737 dump_scalarmap_parameters(theObject)
738 print "GetScale() = ", theObject.GetScale()
740 # ----------------------
742 # ----------------------
743 def try_cutplanes_parameters(thePattern) :
745 if thePattern is None : return None
749 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
751 ind = random.randint(1,2)
752 anObj = try_scalarmap_parameters(thePattern)
754 if ind%2 : anObj.SetNbPlanes(random.randint(-40,40))
755 else : anObj.SetNbPlanes(random.randint(0,10)) #try behaivor if NbPlanes=0
757 # --- DISPLACEMENT ---
758 anObj.SetDisplacement(random.randint(-100000,100000))
760 # --- PLANE POSITION ---
762 PlaneNb = random.randint(-100000,100000) #incorrect value is possible
763 else : PlaneNb = random.randint(0, anObj.GetNbPlanes())
765 anObj.SetPlanePosition(PlaneNb, random.random()*random.randint(-100000,100000))
767 # --- SET DEFAULT ---
768 anObj.SetDefault(PlaneNb)
770 # --- SET X,Y,Z ROTATION ---
772 angle1 = random.random()*random.randint(-100000,100000)
773 angle2 = random.random()*random.randint(-100000,100000)
775 angle1 = random.random()*3.14
776 angle2 = random.random()*3.14
778 # --- ORIENTATION ---
779 anObj.SetOrientation(ORIENT[random.randint(0,2)],angle1,angle2)
783 def dump_cutplanes_parameters(theObject):
784 dump_saclarmap_parameters(theObject)
786 print "GetOrientationType = " + str(theObject.GetOrientationType())
787 PlanesNb = theObject.GetNbPlanes()
788 print "GetNbPlanes() = ", str(PlanesNb)
789 for i in range(0,PlanesNb+1):
790 if theObject.IsDefault(i) :
791 print "Default plane : "+str(i); break
792 print "GetPlanePosition(" + str(i) + ") = ", theObject.GetPlanePosition(i)
793 print "GetDisplacement() = ", str(theObject.GetDisplacement())
794 print "GetRotateX() = ", str(theObject.GetRotateX())
795 print "GetRotateY() = ", str(theObject.GetRotateY())
796 print "GetRotateZ() = ", str(theObject.GetRotateZ())
798 # ----------------------
800 # ----------------------
801 def try_cutlines_parameters(thePattern):
803 if thePattern is None : return None
807 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
808 ind = random.randint(1,2)
809 anObj = try_scalarmap_parameters(thePattern)
811 # --- ORIENTATION ---
812 anObj.SetOrientation(ORIENT[random.randint(0,2)],
813 random.randint(-100,100)*random.random(),
814 random.randint(-100,100)*random.random())
815 anObj.SetOrientation2(ORIENT[random.randint(0,2)],
816 random.randint(-100,100)*random.random(),
817 random.randint(-100,100)*random.random())
819 # --- Base Plane Position ---
820 anObj.SetBasePlanePosition( random.random()*random.randint(-100000,100000))
822 # --- NUMBER OF LINES ---
824 anObj.SetNbLines(random.randint(-5, 50))
828 def dump_cutlines_parameters(theObject):
829 dump_scalarmap_parameters(theObject)
831 print "GetOrientationType() = " + str(theObject.GetOrientationType())
832 print "GetOrientationType2() = " + str(theObject.GetOrientationType2())
833 print "GetBasePlanePosition() = "+ str(theObject.GetBasePlanePosition())
834 print "GetNbLines() = " + str(theObject.GetNbLines())
835 print "GetRotateX() = ", str(theObject.GetRotateX())
836 print "GetRotateX2() = ", str(theObject.GetRotateX2())
837 print "GetRotateY() = ", str(theObject.GetRotateY())
838 print "GetRotateY2() = ", str(theObject.GetRotateY2())
840 # ----------------------
842 # ----------------------
843 def try_streamlines_parameters(thePattern):
845 if thePattern is None : return None
849 DIRECTION = [VISU.StreamLines.FORWARD, VISU.StreamLines.BACKWARD, VISU.StreamLines.BOTH]
851 ind = random.randint(1,2)
852 anObj = (try_deformedshape_parameters(thePattern))[0]
855 anObj.SetDirection(DIRECTION[random.randint(0,2)])
857 # --- STEP LENGTH ---
858 if ind%2 : anObj.SetStepLength(random.random()*random.randint(-1000,1000))
860 aLen = anObj.GetMax() - anObj.GetMin()
861 anObj.SetStepLength(aLen/random.randint(1,100))
863 # --- PROPAGATION TIME ---
864 anObj.SetPropagationTime(random.random()*random.randint(1,100))
866 # --- INTEGRATION STEP ---
868 anObj.SetIntegrationStep(random.random()*random.randint(-1000,1000))
870 anObj.SetIntegrationStep(random.random())
873 anObj.SetUsedPoints(random.random()*random.randint(-10000,10000))
877 def dump_streamlines_parameters(theObject):
879 dump_deformedshape_parameters(theObject)
881 print "GetDirection() = " + str(theObject.GetDirection())
882 print "GetStepLength() = " + str(theObject.GetStepLength())
883 print "GetPropagationTime() =" + str(theObject.GetPropagationTime())
884 print "GetIntegrationStep() =" + str(theObject.GetIntegrationStep())
885 print "GetUsedPoints() =" + str(theObject.GetUsedPoints())
887 # ----------------------
889 # ----------------------
890 def try_vectors_parameters(thePattern, theNum):
892 if thePattern is None : return None
895 GLIPH_TYPE = [VISU.Vectors.ARROW, VISU.Vectors.CONE2, VISU.Vectors.CONE6, VISU.Vectors.NONE]
896 GLIPH_POS = [VISU.Vectors.CENTER, VISU.Vectors.TAIL, VISU.Vectors.HEAD]
897 ind = random.randint(1,2)
898 anObj = (try_deformedshape_parameters(thePattern))[0]
902 anObj.SetLineWidth(random.random()*random.randint(-10000,10000))
904 anObj.SetLineWidth(random.randint(1, 10))
907 anObj.SetGlyphType(GLIPH_TYPE[random.randint(0, len(GLIPH_TYPE)-1)])
910 anObj.SetGlyphPos(GLIPH_POS[random.randint(0, len(GLIPH_POS)-1)])
914 def dump_vetctors_parameters(theObject):
916 dump_deformedshape_parameters(theObject)
918 print "GetLineWidth() = " +str(theObject.GetLineWidth())
919 print "GetGlyphType() = " +str(theObject.GetGlyphType())
920 print "GetGlyphPos() = " +str(theObject.GetGlyphPos())
923 # ----------------------
925 # ----------------------
927 def try_isosurfaces_parameters(thePattern) :
928 if thePattern is None : return None
932 anObj = try_scalarmap_parameters(thePattern)
933 ind = random.randint(1,2)
934 # --- SURFACES NUMBER ---
936 anObj.SetNbSurfaces(random.randint(-100000,100000))
938 anObj.SetNbSurfaces(random.randint(1, 50))
942 def dump_isosurfaces_parameters(theObject):
944 dump_scalarmap_parameters(theObject)
945 print "GetNbSurfaces() = "+ str(theObject.GetNbSurfaces())
948 # ----------------------
950 # ----------------------
952 def FillTable( theTable, theValues, theRows, theColumns, theRowTitles, theRowUnits, theColumnTitles ):
953 if theTable is None: return
954 if len(theRows) != len(theColumns): return
955 if len(theRows) != len(theValues): return
957 for value in theValues:
958 theTable.PutValue( value, theRows[ i ], theColumns[ i ])
962 for title in theRowTitles:
963 theTable.SetRowTitle( i, title )
964 theTable.SetRowUnit( i, theRowUnits[ i - 1 ])
968 for title in theColumnTitles:
969 theTable.SetColumnTitle( i, title )
974 def CreateCurve( theTable, theHRow, theVRow, theTitle, theColor, theMarker, theLineType, theLineWidth ):
975 if theTitle is None: return
976 curve = myLocalVisu.CreateCurve( theTable, theHRow, theVRow );
978 curve.SetTitle( theTitle )
979 curve.SetColor( theColor )
980 curve.SetMarker( theMarker )
981 curve.SetLine( theLineType, theLineWidth )