1 # VISU VISU_SWIG : binding of C++ implementation and Python
3 # Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
27 from time import sleep
31 import SALOME_Session_idl
34 import SALOME_ModuleCatalog
35 from omniORB import CORBA
37 from time import sleep
40 myNamingService = None
41 myLifeCycleCORBA = None
42 myNamingService = None
43 myLocalStudyManager = None
49 def Initialize(theORB, theNamingService, theLifeCycleCORBA, theStudyManager, theStudy, theDelay) :
50 global myORB, myNamingService, myLifeCycleCORBA, myLocalStudyManager, myLocalStudy
51 global mySession, myLocalVisu, myDelay
54 myNamingService = theNamingService
55 myLifeCycleCORBA = theLifeCycleCORBA
56 myLocalStudyManager = theStudyManager
57 while mySession == None:
58 mySession = myNamingService.Resolve("/Kernel/Session")
59 mySession = mySession._narrow(SALOME.Session)
60 mySession.GetInterface()
63 myLocalVisu = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "VISU")
64 myLocalStudy = theStudy
65 myLocalVisu.SetCurrentStudy(myLocalStudy)
68 def PublishComponent(theStudyDocument):
69 aComponentDataType = myLocalVisu.ComponentDataType()
70 aSComponent = theStudyDocument.FindComponent(aComponentDataType)
71 if aSComponent == None:
72 aStudyBuilder = theStudyDocument.NewBuilder()
73 aStudyBuilder.NewCommand()
74 aLocked = theStudyDocument.GetProperties().IsLocked()
76 theStudyDocument.GetProperties().SetLocked(0)
79 aSComponent = aStudyBuilder.NewComponent(aComponentDataType);
80 aName = aStudyBuilder.FindOrCreateAttribute(aSComponent,"AttributeName")
81 aModuleCatalogObj = myNamingService.Resolve("/Kernel/ModulCatalog");
82 aModuleCatalog = aModuleCatalogObj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
83 aComponent = aModuleCatalog.GetComponent(aComponentDataType);
84 if aComponent != None:
85 aComponentUserName = aComponent._get_componentusername()
86 aName.SetValue(aComponentUserName)
89 aPixMap = aStudyBuilder.FindOrCreateAttribute(aSComponent,"AttributePixMap")
90 aPixMap.SetPixMap("ICON_OBJBROWSER_Visu")
92 aStudyBuilder.DefineComponentInstance(aSComponent,myLocalVisu);
94 theStudyDocument.GetProperties().SetLocked(1);
97 aStudyBuilder.CommitCommand();
102 def SetName(theObj, theName):
103 anIOR = myORB.object_to_string(theObj)
104 aSObj = myLocalStudy.FindObjectIOR(anIOR)
105 anAttr = aSObj.FindAttribute("AttributeName")[1]
106 anAttr.SetValue(theName)
108 def StrToMap(theString) :
109 aPairList = split(theString,";")
111 iEnd = len(aPairList)
112 for i in range(iEnd) :
113 aPair = split(aPairList[i],"=")
114 aMap[aPair[0]] = aPair[1]
117 def IntToEntity(theInt) :
118 theInt = atoi(theInt)
128 def HasValue(theList, theValue) :
130 return theList.index(theValue) + 1
131 except StandardError, e :
134 def CreateStudyForMed(theVisu, theFileName) :
135 print "CreateStudyForMed ", theFileName,
136 if os.path.isfile(theFileName) :
137 if re.search("\.med$", theFileName) is not None :
139 aStudyName = os.path.basename(theFileName)
140 aStudyName = re.sub(r'\.med', "", aStudyName)
141 aStudyName = generateName(aStudyName)
142 print "myLocalStudyManager.NewStudy -", aStudyName, "...",
143 aStudy = myLocalStudyManager.NewStudy(aStudyName)
144 if aStudy is None : raise RuntimeError, "Error"
147 print "CreateStudyForMed - Creating a 3D viewer...",
148 theVisu.SetCurrentStudy(aStudy)
149 myViewManager = theVisu.GetViewManager()
150 if myViewManager is None : raise RuntimeError, "Error - theVisu.GetViewManager"
151 myView = myViewManager.Create3DView()
152 if myView is None : raise RuntimeError, "Error - myViewManager.Create3DView"
156 return [aStudy, myViewManager, myView]
157 raise RuntimeError, "Error: There is no such file."
159 def getMedSObject(theStudy = myLocalStudy ):
161 theStudy = myLocalStudy
162 aSO = theStudy.FindObject("Med")
163 anIsPresetn, aSObject = aSO.FindSubObject(1)
166 def getMedObjectFromStudy(theStudy = myLocalStudy):
167 aSObject = getMedSObject(theStudy)
169 anAttr = aSObject.FindAttribute("AttributeIOR")[1]
170 anObj = myORB.string_to_object(anAttr.Value())
171 return anObj._narrow(SALOME_MED.MED)
174 def getFieldObjectFromStudy(number, subnumber, theStudy = myLocalStudy):
176 theStudy = myLocalStudy
177 mySO = theStudy.FindObject("MEDFIELD")
179 raise Runtime, "getFieldObjectFromStudy mySO is None"
180 mysub = mySO.FindSubObject(number)[1]
182 mysubsub = mysub.FindSubObject(subnumber)[1]
184 Builder = theStudy.NewBuilder()
185 anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
186 obj = myORB.string_to_object(anAttr.Value())
187 myObj = obj._narrow(SALOME_MED.FIELDINT)
189 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
192 print "ERROR: No Field Object stored in this Study"
195 def SObjectToObject(theSObject) :
197 if theSObject is None :
198 print "SObjectToObject : argument is None"
200 res,Attr = theSObject.FindAttribute("AttributeIOR")
201 if (res != 0) and (Attr is not None) :
202 anIOR = Attr._narrow(SALOMEDS.AttributeIOR);
203 aValue = anIOR.Value();
204 if(len(aValue) != 0) :
205 anObj = myORB.string_to_object(aValue);
207 print "SObjectToObject - IOR = ''"
210 def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
212 global myLifeCycleCORBA
213 print "lcc.FindOrLoadComponent...",
214 aMedComp = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "MED")
215 if aMedComp is None : print "Error"
218 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
220 print "aMedComp.readStructFileWithFieldType...",
221 aMedComp.readStructFileWithFieldType(theFileName,myLocalStudy._get_Name())
222 aMedSObj = getMedSObject(myLocalStudy)
223 if aMedSObj is None : raise RuntimeError, "Error"
226 print "theVisu.ImportMed...",
227 aResult = theVisu.ImportMed(aMedSObj)
228 if aResult is None : raise RuntimeError, "Error"
231 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
233 aResult.RemoveFromStudy()
235 aVISUObjList.append(aResult)
237 aFolderIter = myLocalStudy.NewChildIterator(aMedSObj.GetFather());
238 while aFolderIter.More() :
239 aFolderSObj = aFolderIter.Value()
241 anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
242 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
243 aFolderName = anAttr.Value()
244 print " ", aFolderName
246 if aFolderName == 'MEDMESH' :
247 aMeshIter = myLocalStudy.NewChildIterator(aFolderSObj);
248 while aMeshIter.More() :
249 aMeshSObj = aMeshIter.Value()
251 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
252 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
253 aMeshName = anAttr.Value()
256 aSupportIter = myLocalStudy.NewChildIterator(aMeshSObj);
257 while aSupportIter.More() :
258 aSupportSObj = aSupportIter.Value()
260 anAttr = aSupportSObj.FindAttribute("AttributeName")[1]
261 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
262 aSupportName = anAttr.Value()
263 print " ", aSupportName
265 if aFolderName == 'MEDFIELD' :
266 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
267 while aFieldIter.More() :
268 aFieldSObj = aFieldIter.Value()
270 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
271 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
272 aFieldName = anAttr.Value()
273 print " ", aFieldName
275 print "theVisu.ImportMed...",
276 aResult = theVisu.ImportMed(aFieldSObj)
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)
286 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
287 if aTimeStampIter.More() :
288 aTimeStampIter.Next()
289 while aTimeStampIter.More() :
290 aTimeStampSObj = aTimeStampIter.Value()
291 aTimeStampIter.Next()
292 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
293 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
294 aTimeStampName = anAttr.Value()
295 print " ", aTimeStampName
297 print "theVisu.ImportMed...",
298 aMedField = SObjectToObject(aTimeStampSObj)
299 aResult = theVisu.ImportMedField(aMedField)
300 if aResult is None : raise RuntimeError, "Error"
303 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
305 aResult.RemoveFromStudy()
307 aVISUObjList.append(aResult)
311 # except Exception, e:
314 def CreatePrsForFile(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
316 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
318 print "theVisu.ImportMed...",
319 aResult = theVisu.ImportFile(theFileName)
320 if aResult is None : raise RuntimeError, "Error"
323 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
326 aResult.RemoveFromStudy()
328 aVISUObjList.append(aResult)
332 # except Exception, e:
335 def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
337 if theIsAutoDelete is not None :
341 print "CreatePrsForResult - myLocalStudy.FindObjectIOR...",
342 myLocalStudy = theVisu.GetCurrentStudy()
344 aSObj = myLocalStudy.FindObjectIOR(theResult.GetID())
345 if aSObj is None : raise RuntimeError, "Error"
347 aMeshIter = myLocalStudy.NewChildIterator(aSObj);
348 while aMeshIter.More() :
349 aMeshSObj = aMeshIter.Value()
351 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
353 aMeshSObj = aMeshIter.Value()
355 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
356 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
357 aMeshName = anAttr.Value()
358 aMeshNamePic = re.sub(".","_",aMeshName)
361 aFolderIter = myLocalStudy.NewChildIterator(aMeshSObj);
362 while aFolderIter.More() :
363 aFolderSObj = aFolderIter.Value()
365 anIsFound, anAttr = aFolderSObj.FindAttribute("AttributeName")
368 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
369 aFolderName = anAttr.Value()
370 print " ", aFolderName
372 if aFolderName == 'Families' :
373 anEntityIter = myLocalStudy.NewChildIterator(aFolderSObj);
374 while anEntityIter.More() :
375 anEntitySObj = anEntityIter.Value()
377 anAttr = anEntitySObj.FindAttribute("AttributeName")[1]
378 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
379 anEntityName = anAttr.Value()
382 if anEntityName == 'onNodes' :
385 if anEntityName == 'onEdges' :
388 if anEntityName == 'onFaces' :
391 if anEntityName == 'onCells' :
395 if HasValue(thePrsTypeList,VISU.TMESH) :
396 print " ", anEntityName, aMeshName,
397 aMesh = theVisu.MeshOnEntity(theResult,aMeshName,anEntity)
398 if aMesh is None : print "Error"
401 theView.DisplayOnly(aMesh)
403 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "." + thePictureExt
404 aPictureName = re.sub("\s+","_", aPictureName);
405 theView.SavePicture(aPictureName)
407 aMesh.RemoveFromStudy()
409 aVISUObjList.append(aMesh)
411 anFamilyIter = myLocalStudy.NewChildIterator(anEntitySObj);
412 while anFamilyIter.More() :
413 aFamilySObj = anFamilyIter.Value()
415 anAttr = aFamilySObj.FindAttribute("AttributeName")[1]
416 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
417 anFamilyName = anAttr.Value()
418 if HasValue(thePrsTypeList,VISU.TMESH) :
419 print " ", anFamilyName,
420 aMesh = theVisu.FamilyMeshOnEntity(theResult,aMeshName,anEntity,anFamilyName)
421 if aMesh is None : print "Error"
424 theView.DisplayOnly(aMesh)
426 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + anFamilyName + "." + thePictureExt
427 aPictureName = re.sub("\s+","_", aPictureName);
428 theView.SavePicture(aPictureName)
430 aMesh.RemoveFromStudy()
432 aVISUObjList.append(aMesh)
434 if aFolderName == 'Groups' :
435 aGroupIter = myLocalStudy.NewChildIterator(aFolderSObj);
436 while aGroupIter.More() :
437 aGroupSObj = aGroupIter.Value()
439 anAttr = aGroupSObj.FindAttribute("AttributeName")[1]
440 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
441 aGroupName = anAttr.Value()
442 if HasValue(thePrsTypeList,VISU.TMESH) :
443 print " ", aGroupName,
444 aMesh = theVisu.GroupMesh(theResult,aMeshName,aGroupName)
445 if aMesh is None : print "Error"
448 theView.DisplayOnly(aMesh)
450 aPictureName = thePictureDir + aMeshNamePic + "_" + aGroupName + "." + thePictureExt
451 aPictureName = re.sub("\s+","_", aPictureName);
452 theView.SavePicture(aPictureName)
454 aMesh.RemoveFromStudy()
456 aVISUObjList.append(aMesh)
458 if aFolderName == 'Fields' :
459 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
460 while aFieldIter.More() :
461 aFieldSObj = aFieldIter.Value()
463 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
464 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
465 aFieldName = anAttr.Value()
466 print " ", aFieldName
468 anAttr = aFieldSObj.FindAttribute("AttributeString")[1]
469 anAttr = anAttr._narrow(SALOMEDS.AttributeString);
470 aFieldComment = anAttr.Value()
471 aMap = StrToMap(aFieldComment)
473 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
474 if aTimeStampIter.More() :
475 aTimeStampIter.Next()
476 while aTimeStampIter.More() :
477 aTimeStampSObj = aTimeStampIter.Value()
478 aTimeStampIter.Next()
479 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
480 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
481 aTimeStampName = anAttr.Value()
482 print " ", aTimeStampName
484 anAttr = aTimeStampSObj.FindAttribute("AttributeString")[1]
485 anAttr = anAttr._narrow(SALOMEDS.AttributeString);
486 aTimeStampComment = anAttr.Value()
487 aMap = StrToMap(aTimeStampComment)
488 aMeshName = aMap["myMeshName"]
489 aFieldName = aMap["myFieldName"]
490 aTimeStampId = atoi(aMap["myTimeStampId"])
491 anEntity = IntToEntity(aMap["myEntityId"])
492 anEntityId = str(aMap["myEntityId"]);
493 #print aMeshName, aFieldName, anEntity, aTimeStampId
494 if HasValue(thePrsTypeList,VISU.TSCALARMAP) :
495 print " Creating ScalarMapOnField",
496 aPrsObj = theVisu.ScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
497 if aPrsObj is None : print "Error"
500 theView.DisplayOnly(aPrsObj)
502 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAP." + thePictureExt
503 aPictureName = re.sub("\s+","_", aPictureName);
504 theView.SavePicture(aPictureName)
506 aPrsObj.RemoveFromStudy()
508 aVISUObjList.append(aPrsObj)
510 if HasValue(thePrsTypeList,VISU.TISOSURFACES) :
511 print " Creating IsoSurfacesOnField",
512 aPrsObj = theVisu.IsoSurfacesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
513 if aPrsObj is None : print "Error"
516 theView.DisplayOnly(aPrsObj)
518 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TISOSURFACES." + thePictureExt
519 aPictureName = re.sub("\s+","_", aPictureName);
520 theView.SavePicture(aPictureName)
522 aPrsObj.RemoveFromStudy()
524 aVISUObjList.append(aPrsObj)
526 if HasValue(thePrsTypeList,VISU.TCUTPLANES) :
527 print " Creating CutPlanesOnField",
528 aPrsObj = theVisu.CutPlanesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
529 if aPrsObj is None : print "Error"
532 aPrsObj.SetOrientation(VISU.CutPlanes.ZX,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
533 theView.DisplayOnly(aPrsObj)
535 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTPLANES." + thePictureExt
536 aPictureName = re.sub("\s+","_", aPictureName)
537 theView.SavePicture(aPictureName)
539 aPrsObj.RemoveFromStudy()
541 aVISUObjList.append(aPrsObj)
543 if HasValue(thePrsTypeList,VISU.TCUTLINES) :
544 print " Creating CutLinesOnField",
545 aPrsObj = theVisu.CutLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
546 if aPrsObj is None : print "Error"
549 aPrsObj.SetOrientation(VISU.CutPlanes.XY,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
550 aPrsObj.SetOrientation2(VISU.CutPlanes.ZX,aPrsObj.GetRotateX2(),aPrsObj.GetRotateY2())
551 theView.DisplayOnly(aPrsObj)
553 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTLINES." + thePictureExt
554 aPictureName = re.sub("\s+","_", aPictureName)
555 theView.SavePicture(aPictureName)
557 aPrsObj.RemoveFromStudy()
559 aVISUObjList.append(aPrsObj)
561 if HasValue(thePrsTypeList,VISU.TPLOT3D) :
562 print " Creating Plot3DOnField",
563 aPrsObj = theVisu.Plot3DOnField(theResult,aMeshName,anEntity,
564 aFieldName,aTimeStampId)
565 if aPrsObj is None : print "Error"
568 #aPrsObj.SetOrientation(VISU.CutPlanes.ZX,
569 # aPrsObj.GetRotateX(),
570 # aPrsObj.GetRotateY())
571 theView.DisplayOnly(aPrsObj)
573 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TPLOT3D." + thePictureExt
574 aPictureName = re.sub("\s+","_", aPictureName)
575 theView.SavePicture(aPictureName)
577 aPrsObj.RemoveFromStudy()
579 aVISUObjList.append(aPrsObj)
581 aNumComponent = atoi(aMap["myNumComponent"])
582 if aNumComponent > 1 :
583 if HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPE) :
584 print " Creating DeformedShapeOnField",
585 aPrsObj = theVisu.DeformedShapeOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
586 if aPrsObj is None : print "Error"
589 theView.DisplayOnly(aPrsObj)
591 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPE." + thePictureExt
592 aPictureName = re.sub("\s+","_", aPictureName)
593 theView.SavePicture(aPictureName)
595 aPrsObj.RemoveFromStudy()
597 aVISUObjList.append(aPrsObj)
599 if HasValue(thePrsTypeList,VISU.TVECTORS) :
600 print " Creating VectorsOnField",
601 aPrsObj = theVisu.VectorsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
602 if aPrsObj is None : print "Error"
605 theView.DisplayOnly(aPrsObj)
607 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TVECTORS." + thePictureExt
608 aPictureName = re.sub("\s+","_", aPictureName)
609 theView.SavePicture(aPictureName)
611 aPrsObj.RemoveFromStudy()
613 aVISUObjList.append(aPrsObj)
615 if HasValue(thePrsTypeList,VISU.TSTREAMLINES) :
616 print " Creating StreamLinesOnField",
617 aPrsObj = theVisu.StreamLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
618 if aPrsObj is None : print "Error"
621 theView.DisplayOnly(aPrsObj)
623 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSTREAMLINES." + thePictureExt
624 aPictureName = re.sub("\s+","_", aPictureName)
625 theView.SavePicture(aPictureName)
627 aPrsObj.RemoveFromStudy()
629 aVISUObjList.append(aPrsObj)
631 if HasValue(thePrsTypeList,VISU.TSCALARMAPONDEFORMEDSHAPE) :
632 print " Creating ScalarMapOnDeformedShapeOnField",
633 aPrsObj = theVisu.ScalarMapOnDeformedShapeOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
634 if aPrsObj is None : print "Error"
637 theView.DisplayOnly(aPrsObj)
639 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAPONDEFORMEDSHAPE." + thePictureExt
640 aPictureName = re.sub("\s+","_", aPictureName)
641 theView.SavePicture(aPictureName)
643 aPrsObj.RemoveFromStudy()
645 aVISUObjList.append(aPrsObj)
647 if HasValue(thePrsTypeList,VISU.TGAUSSPOINTS) :
648 print " Creating GaussPointsOnField",
649 aPrsObj = theVisu.GaussPointsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
650 if aPrsObj is None : print "Error"
653 theView.DisplayOnly(aPrsObj)
655 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TGAUSSPOINTS." + thePictureExt
656 aPictureName = re.sub("\s+","_", aPictureName)
657 theView.SavePicture(aPictureName)
659 aPrsObj.RemoveFromStudy()
662 aVISUObjList.append(aPrsObj)
670 def generateName(prefix = None):
672 int = whrandom.randint(1,1000);
674 return "Study" + str(int)
676 return prefix + str(int)
680 # ----------------------
682 # ----------------------
683 def try_mesh_parameters(theMeshPattern):
685 if theMeshPattern is None : return aResult ;
686 theMeshPattern = theMeshPattern._narrow(VISU.Mesh)
687 if theMeshPattern is None : return aResult ;
689 aTYPES = [VISU.POINT, VISU.WIREFRAME, VISU.SHADED, VISU.INSIDEFRAME, VISU.SHRINK]
690 import copy; import os;
692 aNewMesh = copy.deepcopy(theMeshPattern);
693 aNewMesh.SetPresentationType(ind)
694 aResult.append(aNewMesh)
699 # ----------------------------
701 # ----------------------------
703 def try_scalarmap_parameters(thePattern, dump = 0):
705 if thePattern is None : return None
707 SCALING = [VISU.LINEAR, VISU.LOGARITHMIC]
711 anObj = thePattern#copy.deepcopy(thePattern);
712 #ind = random.randint(1,2)
714 #try incorrect value deliberately (but allowed by idl description)
715 #try SetScalarMode(long)
716 mode = random.randint(-100000,100000); #incorrect value deliberately
718 #correct value of ScalarMode
719 mode = random.randint(0, 3)
721 if dump : print "\tSetScalarMode(" + str(mode) +")"
722 anObj.SetScalarMode(mode)
725 scal = random.randint(0,1)
726 if dump : print "\tSetScaling(" + str(SCALING[scal]) +")"
727 anObj.SetScaling(SCALING[scal])
731 alfa = random.random()*random.randint(-100000,100000)
732 betta = random.random()*random.randint(-100000,100000)
733 aMin = alfa; aMax = betta
736 aPMin = thePattern.GetMin()
737 aPMax = thePattern.GetMax()
739 alfa = random.random()%0.5
740 betta = random.random()%0.5
741 aMin = alfa*aLen*random.randint(-1,1) + aPMin
742 aMax = betta*aLen*random.randint(-1,1) + aPMax
743 if dump : print "\tSetRange(" + str(aMin) + ", " + str(aMax) + ")"
744 anObj.SetRange(aMin, aMax)
748 X=random.random()*random.randint(-100000,100000)
749 Y=random.random()*random.randint(-100000,100000)
753 if dump : print "SetPosition("+ str(X) + ", " + str(Y) + " )"
754 anObj.SetPosition(X, Y)
756 # --- SCALAR BAR SIZE ---
758 aWidth=random.random()*random.randint(-100000,100000)
759 aHeight=random.random()*random.randint(-100000,100000)
761 aWidth=random.random()
762 aHeight=random.random()
763 if dump : print " SCALAR BAR Width = " + str(aWidth) + " Height = ", str(aHeight)
764 anObj.SetSize(aWidth, aHeight)
769 def dump_scalarmap_parameters(anObj):
771 print "\tGetScalarMode() = " + str(anObj.GetScalarMode())
772 print "\tGetScaling() = " + str(anObj.GetScaling())
773 print "\tGetMin() = " + str(anObj.GetMin()) + " GetMax() = " + str (anObj.GetMax())
774 print "\tGetOrientation() = " + str(anObj.GetOrientation())
775 print "\tGetPosX() = ", str(anObj.GetPosX()) + " GetPosY() = ", str(anObj.GetPosY())
776 print "\tGetWidth() = ", str ( anObj.GetWidth()) + " GetHeight() = " + str(anObj.GetHeight())
778 # ----------------------
780 # ----------------------
781 def try_deformedshape_parameters(thePattern) :
783 if thePattern is None : return None
787 anObj = try_scalarmap_parameters(thePattern)
791 anObj.SetScale( random.random()*random.randint(-100000, 100000))
793 anObj.SetScale( anObj.GetScale()*random.random())
798 def dump_deformedshape_parameters(theObject):
799 dump_scalarmap_parameters(theObject)
800 print "GetScale() = ", theObject.GetScale()
802 # ----------------------
804 # ----------------------
805 def try_cutplanes_parameters(thePattern) :
807 if thePattern is None : return None
811 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
813 ind = random.randint(1,2)
814 anObj = try_scalarmap_parameters(thePattern)
816 if ind%2 : anObj.SetNbPlanes(random.randint(-40,40))
817 else : anObj.SetNbPlanes(random.randint(0,10)) #try behaivor if NbPlanes=0
819 # --- DISPLACEMENT ---
820 anObj.SetDisplacement(random.randint(-100000,100000))
822 # --- PLANE POSITION ---
824 PlaneNb = random.randint(-100000,100000) #incorrect value is possible
825 else : PlaneNb = random.randint(0, anObj.GetNbPlanes())
827 anObj.SetPlanePosition(PlaneNb, random.random()*random.randint(-100000,100000))
829 # --- SET DEFAULT ---
830 anObj.SetDefault(PlaneNb)
832 # --- SET X,Y,Z ROTATION ---
834 angle1 = random.random()*random.randint(-100000,100000)
835 angle2 = random.random()*random.randint(-100000,100000)
837 angle1 = random.random()*3.14
838 angle2 = random.random()*3.14
840 # --- ORIENTATION ---
841 anObj.SetOrientation(ORIENT[random.randint(0,2)],angle1,angle2)
845 def dump_cutplanes_parameters(theObject):
846 dump_saclarmap_parameters(theObject)
848 print "GetOrientationType = " + str(theObject.GetOrientationType())
849 PlanesNb = theObject.GetNbPlanes()
850 print "GetNbPlanes() = ", str(PlanesNb)
851 for i in range(0,PlanesNb+1):
852 if theObject.IsDefault(i) :
853 print "Default plane : "+str(i); break
854 print "GetPlanePosition(" + str(i) + ") = ", theObject.GetPlanePosition(i)
855 print "GetDisplacement() = ", str(theObject.GetDisplacement())
856 print "GetRotateX() = ", str(theObject.GetRotateX())
857 print "GetRotateY() = ", str(theObject.GetRotateY())
858 print "GetRotateZ() = ", str(theObject.GetRotateZ())
860 # ----------------------
862 # ----------------------
863 def try_cutlines_parameters(thePattern):
865 if thePattern is None : return None
869 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
870 ind = random.randint(1,2)
871 anObj = try_scalarmap_parameters(thePattern)
873 # --- ORIENTATION ---
874 anObj.SetOrientation(ORIENT[random.randint(0,2)],
875 random.randint(-100,100)*random.random(),
876 random.randint(-100,100)*random.random())
877 anObj.SetOrientation2(ORIENT[random.randint(0,2)],
878 random.randint(-100,100)*random.random(),
879 random.randint(-100,100)*random.random())
881 # --- Base Plane Position ---
882 anObj.SetBasePlanePosition( random.random()*random.randint(-100000,100000))
884 # --- NUMBER OF LINES ---
886 anObj.SetNbLines(random.randint(-5, 50))
890 def dump_cutlines_parameters(theObject):
891 dump_scalarmap_parameters(theObject)
893 print "GetOrientationType() = " + str(theObject.GetOrientationType())
894 print "GetOrientationType2() = " + str(theObject.GetOrientationType2())
895 print "GetBasePlanePosition() = "+ str(theObject.GetBasePlanePosition())
896 print "GetNbLines() = " + str(theObject.GetNbLines())
897 print "GetRotateX() = ", str(theObject.GetRotateX())
898 print "GetRotateX2() = ", str(theObject.GetRotateX2())
899 print "GetRotateY() = ", str(theObject.GetRotateY())
900 print "GetRotateY2() = ", str(theObject.GetRotateY2())
902 # ----------------------
904 # ----------------------
905 def try_streamlines_parameters(thePattern):
907 if thePattern is None : return None
911 DIRECTION = [VISU.StreamLines.FORWARD, VISU.StreamLines.BACKWARD, VISU.StreamLines.BOTH]
913 ind = random.randint(1,2)
914 anObj = (try_deformedshape_parameters(thePattern))[0]
917 anObj.SetDirection(DIRECTION[random.randint(0,2)])
919 # --- STEP LENGTH ---
920 if ind%2 : anObj.SetStepLength(random.random()*random.randint(-1000,1000))
922 aLen = anObj.GetMax() - anObj.GetMin()
923 anObj.SetStepLength(aLen/random.randint(1,100))
925 # --- PROPAGATION TIME ---
926 anObj.SetPropagationTime(random.random()*random.randint(1,100))
928 # --- INTEGRATION STEP ---
930 anObj.SetIntegrationStep(random.random()*random.randint(-1000,1000))
932 anObj.SetIntegrationStep(random.random())
935 anObj.SetUsedPoints(random.random()*random.randint(-10000,10000))
939 def dump_streamlines_parameters(theObject):
941 dump_deformedshape_parameters(theObject)
943 print "GetDirection() = " + str(theObject.GetDirection())
944 print "GetStepLength() = " + str(theObject.GetStepLength())
945 print "GetPropagationTime() =" + str(theObject.GetPropagationTime())
946 print "GetIntegrationStep() =" + str(theObject.GetIntegrationStep())
947 print "GetUsedPoints() =" + str(theObject.GetUsedPoints())
949 # ----------------------
951 # ----------------------
952 def try_vectors_parameters(thePattern, theNum):
954 if thePattern is None : return None
957 GLIPH_TYPE = [VISU.Vectors.ARROW, VISU.Vectors.CONE2, VISU.Vectors.CONE6, VISU.Vectors.NONE]
958 GLIPH_POS = [VISU.Vectors.CENTER, VISU.Vectors.TAIL, VISU.Vectors.HEAD]
959 ind = random.randint(1,2)
960 anObj = (try_deformedshape_parameters(thePattern))[0]
964 anObj.SetLineWidth(random.random()*random.randint(-10000,10000))
966 anObj.SetLineWidth(random.randint(1, 10))
969 anObj.SetGlyphType(GLIPH_TYPE[random.randint(0, len(GLIPH_TYPE)-1)])
972 anObj.SetGlyphPos(GLIPH_POS[random.randint(0, len(GLIPH_POS)-1)])
976 def dump_vectors_parameters(theObject):
978 dump_deformedshape_parameters(theObject)
980 print "GetLineWidth() = " +str(theObject.GetLineWidth())
981 print "GetGlyphType() = " +str(theObject.GetGlyphType())
982 print "GetGlyphPos() = " +str(theObject.GetGlyphPos())
985 # ----------------------
987 # ----------------------
989 def try_isosurfaces_parameters(thePattern) :
990 if thePattern is None : return None
994 anObj = try_scalarmap_parameters(thePattern)
995 ind = random.randint(1,2)
996 # --- SURFACES NUMBER ---
998 anObj.SetNbSurfaces(random.randint(-100000,100000))
1000 anObj.SetNbSurfaces(random.randint(1, 50))
1004 def dump_isosurfaces_parameters(theObject):
1006 dump_scalarmap_parameters(theObject)
1007 print "GetNbSurfaces() = "+ str(theObject.GetNbSurfaces())
1009 # ----------------------------
1010 # SCALAR MAP ON DEFORMED SHAPE
1011 # ----------------------------
1012 def dump_scalarmapondeformedshape_parameters(theObject):
1013 dump_scalarmap_parameters(theObject)
1014 print "GetScale() =", theObject.GetScale()
1015 print "GetScalarCMeshName ()=|",theObject.GetScalarCMeshName(),"|"
1016 print "GetScalarCFieldName()=|",theObject.GetScalarCFieldName(),"|"
1017 print "GetScalarEEntity() =",theObject.GetScalarEEntity()
1018 print "GetScalarLIteration()=",theObject.GetScalarLIteration()
1021 def try_scalarmapondeformedshape_parameters(thePattern):
1023 if thePattern is None : return None
1027 anObj = try_scalarmap_parameters(thePattern)
1031 anObj.SetScale( anObj.GetScale()/random.random()*random.randint(1,10))
1033 # --- Scalar Field ---
1034 # not implemented yet.
1037 # ----------------------
1039 # ----------------------
1040 def dump_plot3d_parameters(theObject):
1041 dump_scalarmap_parameters(theObject)
1042 print "GetOrientationType()=",str(theObject.GetOrientationType())
1043 print "GetRotateX()=",theObject.GetRotateX()
1044 print "GetRotateY()=",theObject.GetRotateY()
1045 print "GetPlanePosition()=",theObject.GetPlanePosition()
1046 print "IsPositionRelative()=",theObject.IsPositionRelative()
1047 print "GetScaleFactor()=",theObject.GetScaleFactor()
1048 print "GetIsContourPrs()=",theObject.GetIsContourPrs()
1049 print "GetNbOfContours()=",theObject.GetNbOfContours()
1052 def try_plot3d_parameters(thePattern):
1053 if thePattern is None : return None
1056 anObj = try_scalarmap_parameters(thePattern)
1058 ORIENT = [VISU.Plot3D.XY, VISU.Plot3D.YZ, VISU.Plot3D.ZX]
1060 theXAngle = random.random()*random.randint(-180,180)
1061 theYAngle = random.random()*random.randint(-180,180)
1063 # ORIENTATION and ANGLES
1064 anObj.SetOrientation(ORIENT[random.randint(0,2)],theXAngle,theYAngle)
1066 # Plane position (revative)
1067 anObj.SetPlanePosition(random.random(),1)
1070 anObj.SetScaleFactor(random.random()*random.randint(-10000,10000))
1073 anObj.SetContourPrs(random.randint(0,1))
1074 if anObj.GetIsContourPrs():
1075 anObj.SetNbOfContours(random.randint(1,999))
1080 # ----------------------
1082 # ----------------------
1083 def dump_gausspoints_parameters(theObject):
1085 print "\tGetScalarMode() = " + str(anObj.GetScalarMode())
1086 print "\tGetMin() = " + str(anObj.GetMin()) + " GetMax() = " + str (anObj.GetMax())
1087 print "\tGetPosX() = ", str(anObj.GetPosX()) + " GetPosY() = ", str(anObj.GetPosY())
1088 print "\tGetWidth() = ", str ( anObj.GetWidth()) + " GetHeight() = " + str(anObj.GetHeight())
1089 print "\tGetNbColors() = " + str(anObj.GetNbColors())
1090 print "\tGetLabels() = " + str(anObj.GetLabels())
1091 print "\tGetTitle() = " + str(anObj.GetTitle())
1094 def try_plot3d_parameters(thePattern):
1095 if thePattern is None : return None
1100 # ----------------------
1102 # ----------------------
1104 def FillTable( theTable, theValues, theRows, theColumns, theRowTitles, theRowUnits, theColumnTitles ):
1105 if theTable is None: return
1106 if len(theRows) != len(theColumns): return
1107 if len(theRows) != len(theValues): return
1109 for value in theValues:
1110 theTable.PutValue( value, theRows[ i ], theColumns[ i ])
1114 for title in theRowTitles:
1115 theTable.SetRowTitle( i, title )
1116 theTable.SetRowUnit( i, theRowUnits[ i - 1 ])
1120 for title in theColumnTitles:
1121 theTable.SetColumnTitle( i, title )
1126 def CreateCurve( theTable, theHRow, theVRow, theTitle, theColor, theMarker, theLineType, theLineWidth ):
1127 if theTitle is None: return
1128 curve = myLocalVisu.CreateCurve( theTable, theHRow, theVRow );
1130 curve.SetTitle( theTitle )
1131 curve.SetColor( theColor )
1132 curve.SetMarker( theMarker )
1133 curve.SetLine( theLineType, theLineWidth )