1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 # VISU VISU_SWIG : binding of C++ implementation and Python
30 from time import sleep
34 import SALOME_Session_idl
37 import SALOME_ModuleCatalog
38 from omniORB import CORBA
40 from time import sleep
41 from salome import ObjectToID
44 myNamingService = None
45 myLifeCycleCORBA = None
46 myNamingService = None
47 myLocalStudyManager = None
53 def Initialize(theORB, theNamingService, theLifeCycleCORBA, theStudyManager, theStudy, theDelay) :
54 global myORB, myNamingService, myLifeCycleCORBA, myLocalStudyManager, myLocalStudy
55 global mySession, myLocalVisu, myDelay
58 myNamingService = theNamingService
59 myLifeCycleCORBA = theLifeCycleCORBA
60 myLocalStudyManager = theStudyManager
61 while mySession == None:
62 mySession = myNamingService.Resolve("/Kernel/Session")
63 mySession = mySession._narrow(SALOME.Session)
64 mySession.GetInterface()
67 myLocalVisu = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "VISU")
68 myLocalStudy = theStudy
69 myLocalVisu.SetCurrentStudy(myLocalStudy)
72 def PublishComponent(theStudyDocument):
73 aComponentDataType = myLocalVisu.ComponentDataType()
74 aSComponent = theStudyDocument.FindComponent(aComponentDataType)
75 if aSComponent == None:
76 aStudyBuilder = theStudyDocument.NewBuilder()
77 aStudyBuilder.NewCommand()
78 aLocked = theStudyDocument.GetProperties().IsLocked()
80 theStudyDocument.GetProperties().SetLocked(0)
83 aSComponent = aStudyBuilder.NewComponent(aComponentDataType);
84 aName = aStudyBuilder.FindOrCreateAttribute(aSComponent,"AttributeName")
85 aModuleCatalogObj = myNamingService.Resolve("/Kernel/ModulCatalog");
86 aModuleCatalog = aModuleCatalogObj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
87 aComponent = aModuleCatalog.GetComponent(aComponentDataType);
88 if aComponent != None:
89 aComponentUserName = aComponent._get_componentusername()
90 aName.SetValue(aComponentUserName)
93 aPixMap = aStudyBuilder.FindOrCreateAttribute(aSComponent,"AttributePixMap")
94 aPixMap.SetPixMap("ICON_OBJBROWSER_Visu")
96 aStudyBuilder.DefineComponentInstance(aSComponent,myLocalVisu);
98 theStudyDocument.GetProperties().SetLocked(1);
101 aStudyBuilder.CommitCommand();
106 def SetName(theObj, theName):
107 anIOR = myORB.object_to_string(theObj)
108 aSObj = myLocalStudy.FindObjectIOR(anIOR)
109 anAttr = aSObj.FindAttribute("AttributeName")[1]
110 anAttr.SetValue(theName)
112 def StrToMap(theString) :
113 aPairList = split(theString,";")
115 iEnd = len(aPairList)
116 for i in range(iEnd) :
117 aPair = split(aPairList[i],"=")
118 aMap[aPair[0]] = aPair[1]
121 def IntToEntity(theInt) :
122 theInt = atoi(theInt)
132 def getObjectID(obj):
134 entry = ObjectToID(obj)
135 if entry is not None:
136 lst = entry.split(":")
143 def HasValue(theList, theValue) :
145 return theList.index(theValue) + 1
146 except StandardError, e :
149 def CreateStudyForMed(theVisu, theFileName) :
150 print "CreateStudyForMed ", theFileName,
151 if os.path.isfile(theFileName) :
152 if re.search("\.med$", theFileName) is not None :
154 aStudyName = os.path.basename(theFileName)
155 aStudyName = re.sub(r'\.med', "", aStudyName)
156 aStudyName = generateName(aStudyName)
157 print "myLocalStudyManager.NewStudy -", aStudyName, "...",
158 aStudy = myLocalStudyManager.NewStudy(aStudyName)
159 if aStudy is None : raise RuntimeError, "Error"
162 print "CreateStudyForMed - Creating a 3D viewer...",
163 theVisu.SetCurrentStudy(aStudy)
164 myViewManager = theVisu.GetViewManager()
165 if myViewManager is None : raise RuntimeError, "Error - theVisu.GetViewManager"
166 myView = myViewManager.Create3DView()
167 if myView is None : raise RuntimeError, "Error - myViewManager.Create3DView"
171 return [aStudy, myViewManager, myView]
172 raise RuntimeError, "Error: There is no such file."
174 def getMedSObject(theStudy = myLocalStudy ):
176 theStudy = myLocalStudy
177 aSO = theStudy.FindObject("Med")
178 anIsPresetn, aSObject = aSO.FindSubObject(1)
181 def getMedObjectFromStudy(theStudy = myLocalStudy):
182 aSObject = getMedSObject(theStudy)
184 anAttr = aSObject.FindAttribute("AttributeIOR")[1]
185 anObj = myORB.string_to_object(anAttr.Value())
186 return anObj._narrow(SALOME_MED.MED)
189 def getFieldObjectFromStudy(number, subnumber, theStudy = myLocalStudy):
191 theStudy = myLocalStudy
192 mySO = theStudy.FindObject("MEDFIELD")
194 raise Runtime, "getFieldObjectFromStudy mySO is None"
195 mysub = mySO.FindSubObject(number)[1]
197 mysubsub = mysub.FindSubObject(subnumber)[1]
199 Builder = theStudy.NewBuilder()
200 anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
201 obj = myORB.string_to_object(anAttr.Value())
202 myObj = obj._narrow(SALOME_MED.FIELDINT)
204 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
207 print "ERROR: No Field Object stored in this Study"
210 def getSObjectByFatherPathAndName(theStudy, thePath, theName):
211 father = theStudy.FindObjectByPath(thePath)
212 itr = theStudy.NewChildIterator(father)
215 if so.GetName()==theName: return so
220 def SObjectToObject(theSObject) :
222 if theSObject is None :
223 print "SObjectToObject : argument is None"
225 res,Attr = theSObject.FindAttribute("AttributeIOR")
226 if (res != 0) and (Attr is not None) :
227 anIOR = Attr._narrow(SALOMEDS.AttributeIOR);
228 aValue = anIOR.Value();
229 if(len(aValue) != 0) :
230 anObj = myORB.string_to_object(aValue);
232 print "SObjectToObject - IOR = ''"
235 def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
237 global myLifeCycleCORBA
238 print "lcc.FindOrLoadComponent...",
239 aMedComp = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "MED")
240 if aMedComp is None : print "Error"
243 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
245 print "aMedComp.readStructFileWithFieldType...",
246 aMedComp.readStructFileWithFieldType(theFileName,myLocalStudy._get_Name())
247 aMedSObj = getMedSObject(myLocalStudy)
248 if aMedSObj is None : raise RuntimeError, "Error"
251 print "theVisu.ImportMed...",
252 aResult = theVisu.ImportMed(aMedSObj)
253 if aResult is None : raise RuntimeError, "Error"
256 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
258 aResult.RemoveFromStudy()
260 aVISUObjList.append(aResult)
262 aFolderIter = myLocalStudy.NewChildIterator(aMedSObj.GetFather());
263 while aFolderIter.More() :
264 aFolderSObj = aFolderIter.Value()
266 anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
267 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
268 aFolderName = anAttr.Value()
269 print " ", aFolderName
271 if aFolderName == 'MEDMESH' :
272 aMeshIter = myLocalStudy.NewChildIterator(aFolderSObj);
273 while aMeshIter.More() :
274 aMeshSObj = aMeshIter.Value()
276 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
277 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
278 aMeshName = anAttr.Value()
281 aSupportIter = myLocalStudy.NewChildIterator(aMeshSObj);
282 while aSupportIter.More() :
283 aSupportSObj = aSupportIter.Value()
285 anAttr = aSupportSObj.FindAttribute("AttributeName")[1]
286 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
287 aSupportName = anAttr.Value()
288 print " ", aSupportName
290 if aFolderName == 'MEDFIELD' :
291 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
292 while aFieldIter.More() :
293 aFieldSObj = aFieldIter.Value()
295 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
296 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
297 aFieldName = anAttr.Value()
298 print " ", aFieldName
300 print "theVisu.ImportMed...",
301 aResult = theVisu.ImportMed(aFieldSObj)
302 if aResult is None : raise RuntimeError, "Error"
305 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
307 aResult.RemoveFromStudy()
309 aVISUObjList.append(aResult)
311 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
312 if aTimeStampIter.More() :
313 aTimeStampIter.Next()
314 while aTimeStampIter.More() :
315 aTimeStampSObj = aTimeStampIter.Value()
316 aTimeStampIter.Next()
317 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
318 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
319 aTimeStampName = anAttr.Value()
320 print " ", aTimeStampName
322 print "theVisu.ImportMed...",
323 aMedField = SObjectToObject(aTimeStampSObj)
324 aResult = theVisu.ImportMedField(aMedField)
325 if aResult is None : raise RuntimeError, "Error"
328 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
330 aResult.RemoveFromStudy()
332 aVISUObjList.append(aResult)
336 # except Exception, e:
339 def CreatePrsForFile(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
341 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
343 print "theVisu.ImportMed...",
344 aResult = theVisu.ImportFile(theFileName)
345 if aResult is None : raise RuntimeError, "Error"
348 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
351 aResult.RemoveFromStudy()
353 aVISUObjList.append(aResult)
357 # except Exception, e:
360 def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
362 if theIsAutoDelete is not None :
366 print "CreatePrsForResult - myLocalStudy.FindObjectIOR...",
367 myLocalStudy = theVisu.GetCurrentStudy()
369 aSObj = myLocalStudy.FindObjectIOR(theResult.GetID())
370 if aSObj is None : raise RuntimeError, "Error"
372 aMeshIter = myLocalStudy.NewChildIterator(aSObj);
373 while aMeshIter.More() :
374 aMeshSObj = aMeshIter.Value()
376 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
378 aMeshSObj = aMeshIter.Value()
380 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
381 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
382 aMeshName = anAttr.Value()
383 aMeshNamePic = re.sub(".","_",aMeshName)
386 aFolderIter = myLocalStudy.NewChildIterator(aMeshSObj);
387 while aFolderIter.More() :
388 aFolderSObj = aFolderIter.Value()
390 anIsFound, anAttr = aFolderSObj.FindAttribute("AttributeName")
393 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
394 aFolderName = anAttr.Value()
395 print " ", aFolderName
397 if aFolderName == 'Families' :
398 anEntityIter = myLocalStudy.NewChildIterator(aFolderSObj);
399 while anEntityIter.More() :
400 anEntitySObj = anEntityIter.Value()
402 anAttr = anEntitySObj.FindAttribute("AttributeName")[1]
403 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
404 anEntityName = anAttr.Value()
407 if anEntityName == 'onNodes' :
410 if anEntityName == 'onEdges' :
413 if anEntityName == 'onFaces' :
416 if anEntityName == 'onCells' :
420 if HasValue(thePrsTypeList,VISU.TMESH) :
421 print " ", anEntityName, aMeshName,
422 aMesh = theVisu.MeshOnEntity(theResult,aMeshName,anEntity)
423 if aMesh is None : print "Error"
426 theView.DisplayOnly(aMesh)
428 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "." + thePictureExt
429 aPictureName = re.sub("\s+","_", aPictureName);
430 theView.SavePicture(aPictureName)
432 aMesh.RemoveFromStudy()
434 aVISUObjList.append(aMesh)
436 anFamilyIter = myLocalStudy.NewChildIterator(anEntitySObj);
437 while anFamilyIter.More() :
438 aFamilySObj = anFamilyIter.Value()
440 anAttr = aFamilySObj.FindAttribute("AttributeName")[1]
441 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
442 anFamilyName = anAttr.Value()
443 if HasValue(thePrsTypeList,VISU.TMESH) :
444 print " ", anFamilyName,
445 aMesh = theVisu.FamilyMeshOnEntity(theResult,aMeshName,anEntity,anFamilyName)
446 if aMesh is None : print "Error"
449 theView.DisplayOnly(aMesh)
451 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + anFamilyName + "." + thePictureExt
452 aPictureName = re.sub("\s+","_", aPictureName);
453 theView.SavePicture(aPictureName)
455 aMesh.RemoveFromStudy()
457 aVISUObjList.append(aMesh)
459 if aFolderName == 'Groups' :
460 aGroupIter = myLocalStudy.NewChildIterator(aFolderSObj);
461 while aGroupIter.More() :
462 aGroupSObj = aGroupIter.Value()
464 anAttr = aGroupSObj.FindAttribute("AttributeName")[1]
465 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
466 aGroupName = anAttr.Value()
467 if HasValue(thePrsTypeList,VISU.TMESH) :
468 print " ", aGroupName,
469 aMesh = theVisu.GroupMesh(theResult,aMeshName,aGroupName)
470 if aMesh is None : print "Error"
473 theView.DisplayOnly(aMesh)
475 aPictureName = thePictureDir + aMeshNamePic + "_" + aGroupName + "." + thePictureExt
476 aPictureName = re.sub("\s+","_", aPictureName);
477 theView.SavePicture(aPictureName)
479 aMesh.RemoveFromStudy()
481 aVISUObjList.append(aMesh)
483 if aFolderName == 'Fields' :
484 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
485 while aFieldIter.More() :
486 aFieldSObj = aFieldIter.Value()
488 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
489 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
490 aFieldName = anAttr.Value()
491 print " ", aFieldName
493 anAttr = aFieldSObj.FindAttribute("AttributeString")[1]
494 anAttr = anAttr._narrow(SALOMEDS.AttributeString);
495 aFieldComment = anAttr.Value()
496 aMap = StrToMap(aFieldComment)
498 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
499 if aTimeStampIter.More() :
500 aTimeStampIter.Next()
501 while aTimeStampIter.More() :
502 aTimeStampSObj = aTimeStampIter.Value()
503 aTimeStampIter.Next()
504 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
505 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
506 aTimeStampName = anAttr.Value()
507 print " ", aTimeStampName
509 anAttr = aTimeStampSObj.FindAttribute("AttributeString")[1]
510 anAttr = anAttr._narrow(SALOMEDS.AttributeString);
511 aTimeStampComment = anAttr.Value()
512 aMap = StrToMap(aTimeStampComment)
513 aMeshName = aMap["myMeshName"]
514 aFieldName = aMap["myFieldName"]
515 aTimeStampId = atoi(aMap["myTimeStampId"])
516 anEntity = IntToEntity(aMap["myEntityId"])
517 anEntityId = str(aMap["myEntityId"]);
518 #print aMeshName, aFieldName, anEntity, aTimeStampId
519 if HasValue(thePrsTypeList,VISU.TSCALARMAP) :
520 print " Creating ScalarMapOnField",
521 aPrsObj = theVisu.ScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
522 if aPrsObj is None : print "Error"
525 theView.DisplayOnly(aPrsObj)
527 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAP." + thePictureExt
528 aPictureName = re.sub("\s+","_", aPictureName);
529 theView.SavePicture(aPictureName)
531 aPrsObj.RemoveFromStudy()
533 aVISUObjList.append(aPrsObj)
535 if HasValue(thePrsTypeList,VISU.TISOSURFACES) :
536 print " Creating IsoSurfacesOnField",
537 aPrsObj = theVisu.IsoSurfacesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
538 if aPrsObj is None : print "Error"
541 theView.DisplayOnly(aPrsObj)
543 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TISOSURFACES." + thePictureExt
544 aPictureName = re.sub("\s+","_", aPictureName);
545 theView.SavePicture(aPictureName)
547 aPrsObj.RemoveFromStudy()
549 aVISUObjList.append(aPrsObj)
551 if HasValue(thePrsTypeList,VISU.TCUTPLANES) :
552 print " Creating CutPlanesOnField",
553 aPrsObj = theVisu.CutPlanesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
554 if aPrsObj is None : print "Error"
557 aPrsObj.SetOrientation(VISU.CutPlanes.ZX,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
558 theView.DisplayOnly(aPrsObj)
560 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTPLANES." + thePictureExt
561 aPictureName = re.sub("\s+","_", aPictureName)
562 theView.SavePicture(aPictureName)
564 aPrsObj.RemoveFromStudy()
566 aVISUObjList.append(aPrsObj)
568 if HasValue(thePrsTypeList,VISU.TCUTLINES) :
569 print " Creating CutLinesOnField",
570 aPrsObj = theVisu.CutLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
571 if aPrsObj is None : print "Error"
574 aPrsObj.SetOrientation(VISU.CutPlanes.XY,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
575 aPrsObj.SetOrientation2(VISU.CutPlanes.ZX,aPrsObj.GetRotateX2(),aPrsObj.GetRotateY2())
576 theView.DisplayOnly(aPrsObj)
578 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTLINES." + thePictureExt
579 aPictureName = re.sub("\s+","_", aPictureName)
580 theView.SavePicture(aPictureName)
582 aPrsObj.RemoveFromStudy()
584 aVISUObjList.append(aPrsObj)
586 if HasValue(thePrsTypeList,VISU.TCUTSEGMENT) :
587 print " Creating CutSegmentOnField",
588 aPrsObj = theVisu.CutSegmentOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
589 if aPrsObj is None : print "Error"
592 theView.DisplayOnly(aPrsObj)
594 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTSEGMENT." + thePictureExt
595 aPictureName = re.sub("\s+","_", aPictureName)
596 theView.SavePicture(aPictureName)
598 aPrsObj.RemoveFromStudy()
600 aVISUObjList.append(aPrsObj)
602 if HasValue(thePrsTypeList,VISU.TPLOT3D) :
603 print " Creating Plot3DOnField",
604 aPrsObj = theVisu.Plot3DOnField(theResult,aMeshName,anEntity,
605 aFieldName,aTimeStampId)
606 if aPrsObj is None : print "Error"
609 #aPrsObj.SetOrientation(VISU.CutPlanes.ZX,
610 # aPrsObj.GetRotateX(),
611 # aPrsObj.GetRotateY())
612 theView.DisplayOnly(aPrsObj)
614 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TPLOT3D." + thePictureExt
615 aPictureName = re.sub("\s+","_", aPictureName)
616 theView.SavePicture(aPictureName)
618 aPrsObj.RemoveFromStudy()
620 aVISUObjList.append(aPrsObj)
622 aNumComponent = atoi(aMap["myNumComponent"])
623 if aNumComponent > 1 :
624 if HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPE) :
625 print " Creating DeformedShapeOnField",
626 aPrsObj = theVisu.DeformedShapeOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
627 if aPrsObj is None : print "Error"
630 theView.DisplayOnly(aPrsObj)
632 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPE." + thePictureExt
633 aPictureName = re.sub("\s+","_", aPictureName)
634 theView.SavePicture(aPictureName)
636 aPrsObj.RemoveFromStudy()
638 aVISUObjList.append(aPrsObj)
640 if HasValue(thePrsTypeList,VISU.TVECTORS) :
641 print " Creating VectorsOnField",
642 aPrsObj = theVisu.VectorsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
643 if aPrsObj is None : print "Error"
646 theView.DisplayOnly(aPrsObj)
648 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TVECTORS." + thePictureExt
649 aPictureName = re.sub("\s+","_", aPictureName)
650 theView.SavePicture(aPictureName)
652 aPrsObj.RemoveFromStudy()
654 aVISUObjList.append(aPrsObj)
656 if HasValue(thePrsTypeList,VISU.TSTREAMLINES) :
657 print " Creating StreamLinesOnField",
658 aPrsObj = theVisu.StreamLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
659 if aPrsObj is None : print "Error"
662 theView.DisplayOnly(aPrsObj)
664 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSTREAMLINES." + thePictureExt
665 aPictureName = re.sub("\s+","_", aPictureName)
666 theView.SavePicture(aPictureName)
668 aPrsObj.RemoveFromStudy()
670 aVISUObjList.append(aPrsObj)
672 if HasValue(thePrsTypeList,VISU.TSCALARMAPONDEFORMEDSHAPE) or HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPEANDSCALARMAP) :
673 print " Creating DeformedShapeAndScalarMapOnField",
674 aPrsObj = theVisu.DeformedShapeAndScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
675 if aPrsObj is None : print "Error"
678 theView.DisplayOnly(aPrsObj)
680 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPEANDSCALARMAP." + thePictureExt
681 aPictureName = re.sub("\s+","_", aPictureName)
682 theView.SavePicture(aPictureName)
684 aPrsObj.RemoveFromStudy()
686 aVISUObjList.append(aPrsObj)
688 if HasValue(thePrsTypeList,VISU.TGAUSSPOINTS) :
689 print " Creating GaussPointsOnField",
690 aPrsObj = theVisu.GaussPointsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
691 if aPrsObj is None : print "Error"
694 theView.DisplayOnly(aPrsObj)
696 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TGAUSSPOINTS." + thePictureExt
697 aPictureName = re.sub("\s+","_", aPictureName)
698 theView.SavePicture(aPictureName)
700 aPrsObj.RemoveFromStudy()
703 aVISUObjList.append(aPrsObj)
711 def generateName(prefix = None):
713 int = random.randint(1,1000);
715 return "Study" + str(int)
717 return prefix + str(int)
721 # ----------------------
723 # ----------------------
724 def try_mesh_parameters(theMeshPattern):
726 if theMeshPattern is None : return aResult ;
727 theMeshPattern = theMeshPattern._narrow(VISU.Mesh)
728 if theMeshPattern is None : return aResult ;
730 aTYPES = [VISU.POINT, VISU.WIREFRAME, VISU.SHADED, VISU.INSIDEFRAME, VISU.SHRINK]
731 import copy; import os;
733 aNewMesh = copy.deepcopy(theMeshPattern);
734 aNewMesh.SetPresentationType(ind)
735 aResult.append(aNewMesh)
740 # ----------------------------
742 # ----------------------------
744 def try_scalarmap_parameters(thePattern, dump = 0):
746 if thePattern is None : return None
748 SCALING = [VISU.LINEAR, VISU.LOGARITHMIC]
752 anObj = thePattern#copy.deepcopy(thePattern);
753 #ind = random.randint(1,2)
755 #try incorrect value deliberately (but allowed by idl description)
756 #try SetScalarMode(long)
757 mode = random.randint(-100000,100000); #incorrect value deliberately
759 #correct value of ScalarMode
760 mode = random.randint(0, 3)
762 if dump : print "\tSetScalarMode(" + str(mode) +")"
763 anObj.SetScalarMode(mode)
766 scal = random.randint(0,1)
767 if dump : print "\tSetScaling(" + str(SCALING[scal]) +")"
768 anObj.SetScaling(SCALING[scal])
772 alfa = random.random()*random.randint(-100000,100000)
773 betta = random.random()*random.randint(-100000,100000)
774 aMin = alfa; aMax = betta
777 aPMin = thePattern.GetMin()
778 aPMax = thePattern.GetMax()
780 alfa = random.random()%0.5
781 betta = random.random()%0.5
782 aMin = alfa*aLen*random.randint(-1,1) + aPMin
783 aMax = betta*aLen*random.randint(-1,1) + aPMax
784 if dump : print "\tSetRange(" + str(aMin) + ", " + str(aMax) + ")"
785 anObj.SetRange(aMin, aMax)
789 X=random.random()*random.randint(-100000,100000)
790 Y=random.random()*random.randint(-100000,100000)
794 if dump : print "SetPosition("+ str(X) + ", " + str(Y) + " )"
795 anObj.SetPosition(X, Y)
797 # --- SCALAR BAR SIZE ---
799 aWidth=random.random()*random.randint(-100000,100000)
800 aHeight=random.random()*random.randint(-100000,100000)
802 aWidth=random.random()
803 aHeight=random.random()
804 if dump : print " SCALAR BAR Width = " + str(aWidth) + " Height = ", str(aHeight)
805 anObj.SetSize(aWidth, aHeight)
810 def dump_scalarmap_parameters(anObj):
812 print "\tGetScalarMode() = " + str(anObj.GetScalarMode())
813 print "\tGetScaling() = " + str(anObj.GetScaling())
814 print "\tGetMin() = " + str(anObj.GetMin()) + " GetMax() = " + str (anObj.GetMax())
815 print "\tGetOrientation() = " + str(anObj.GetOrientation())
816 print "\tGetPosX() = ", str(anObj.GetPosX()) + " GetPosY() = ", str(anObj.GetPosY())
817 print "\tGetWidth() = ", str ( anObj.GetWidth()) + " GetHeight() = " + str(anObj.GetHeight())
819 # ----------------------
821 # ----------------------
822 def try_deformedshape_parameters(thePattern) :
824 if thePattern is None : return None
828 anObj = try_scalarmap_parameters(thePattern)
832 anObj.SetScale( random.random()*random.randint(-100000, 100000))
834 anObj.SetScale( anObj.GetScale()*random.random())
839 def dump_deformedshape_parameters(theObject):
840 dump_scalarmap_parameters(theObject)
841 print "GetScale() = ", theObject.GetScale()
843 # ----------------------
845 # ----------------------
846 def try_cutplanes_parameters(thePattern) :
848 if thePattern is None : return None
852 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
854 ind = random.randint(1,2)
855 anObj = try_scalarmap_parameters(thePattern)
857 if ind%2 : anObj.SetNbPlanes(random.randint(-40,40))
858 else : anObj.SetNbPlanes(random.randint(0,10)) #try behaivor if NbPlanes=0
860 # --- DISPLACEMENT ---
861 anObj.SetDisplacement(random.randint(-100000,100000))
863 # --- PLANE POSITION ---
865 PlaneNb = random.randint(-100000,100000) #incorrect value is possible
866 else : PlaneNb = random.randint(0, anObj.GetNbPlanes())
868 anObj.SetPlanePosition(PlaneNb, random.random()*random.randint(-100000,100000))
870 # --- SET DEFAULT ---
871 anObj.SetDefault(PlaneNb)
873 # --- SET X,Y,Z ROTATION ---
875 angle1 = random.random()*random.randint(-100000,100000)
876 angle2 = random.random()*random.randint(-100000,100000)
878 angle1 = random.random()*3.14
879 angle2 = random.random()*3.14
881 # --- ORIENTATION ---
882 anObj.SetOrientation(ORIENT[random.randint(0,2)],angle1,angle2)
886 def dump_cutplanes_parameters(theObject):
887 dump_saclarmap_parameters(theObject)
889 print "GetOrientationType = " + str(theObject.GetOrientationType())
890 PlanesNb = theObject.GetNbPlanes()
891 print "GetNbPlanes() = ", str(PlanesNb)
892 for i in range(0,PlanesNb+1):
893 if theObject.IsDefault(i) :
894 print "Default plane : "+str(i); break
895 print "GetPlanePosition(" + str(i) + ") = ", theObject.GetPlanePosition(i)
896 print "GetDisplacement() = ", str(theObject.GetDisplacement())
897 print "GetRotateX() = ", str(theObject.GetRotateX())
898 print "GetRotateY() = ", str(theObject.GetRotateY())
899 print "GetRotateZ() = ", str(theObject.GetRotateZ())
901 # ----------------------
903 # ----------------------
904 def try_cutlines_parameters(thePattern):
906 if thePattern is None : return None
910 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
911 ind = random.randint(1,2)
912 anObj = try_scalarmap_parameters(thePattern)
914 # --- ORIENTATION ---
915 anObj.SetOrientation(ORIENT[random.randint(0,2)],
916 random.randint(-100,100)*random.random(),
917 random.randint(-100,100)*random.random())
918 anObj.SetOrientation2(ORIENT[random.randint(0,2)],
919 random.randint(-100,100)*random.random(),
920 random.randint(-100,100)*random.random())
922 # --- Base Plane Position ---
923 anObj.SetBasePlanePosition( random.random()*random.randint(-100000,100000))
925 # --- NUMBER OF LINES ---
927 anObj.SetNbLines(random.randint(-5, 50))
931 def dump_cutlines_parameters(theObject):
932 dump_scalarmap_parameters(theObject)
934 print "GetOrientationType() = " + str(theObject.GetOrientationType())
935 print "GetOrientationType2() = " + str(theObject.GetOrientationType2())
936 print "GetBasePlanePosition() = "+ str(theObject.GetBasePlanePosition())
937 print "GetNbLines() = " + str(theObject.GetNbLines())
938 print "GetRotateX() = ", str(theObject.GetRotateX())
939 print "GetRotateX2() = ", str(theObject.GetRotateX2())
940 print "GetRotateY() = ", str(theObject.GetRotateY())
941 print "GetRotateY2() = ", str(theObject.GetRotateY2())
943 # ----------------------
945 # ----------------------
946 def try_cutsegment_parameters(thePattern):
948 if thePattern is None : return None
952 anObj = try_scalarmap_parameters(thePattern)
954 anObj.SetPoint1(random.randint(-100,100)*random.random(),
955 random.randint(-100,100)*random.random(),
956 random.randint(-100,100)*random.random())
957 anObj.SetPoint2(random.randint(-100,100)*random.random(),
958 random.randint(-100,100)*random.random(),
959 random.randint(-100,100)*random.random())
963 def dump_cutsegment_parameters(theObject):
964 dump_scalarmap_parameters(theObject)
968 theObject.GetPoint1(x1, y1, z1)
969 theObject.GetPoint1(x2, y2, z2)
970 print "GetPoint1() = " + str(x1) + ", " + str(y1) + ", " + str(z1)
971 print "GetPoint2() = " + str(x2) + ", " + str(y2) + ", " + str(z2)
973 # ----------------------
975 # ----------------------
976 def try_streamlines_parameters(thePattern):
978 if thePattern is None : return None
982 DIRECTION = [VISU.StreamLines.FORWARD, VISU.StreamLines.BACKWARD, VISU.StreamLines.BOTH]
984 ind = random.randint(1,2)
985 anObj = (try_deformedshape_parameters(thePattern))[0]
988 anObj.SetDirection(DIRECTION[random.randint(0,2)])
990 # --- STEP LENGTH ---
991 if ind%2 : anObj.SetStepLength(random.random()*random.randint(-1000,1000))
993 aLen = anObj.GetMax() - anObj.GetMin()
994 anObj.SetStepLength(aLen/random.randint(1,100))
996 # --- PROPAGATION TIME ---
997 anObj.SetPropagationTime(random.random()*random.randint(1,100))
999 # --- INTEGRATION STEP ---
1001 anObj.SetIntegrationStep(random.random()*random.randint(-1000,1000))
1003 anObj.SetIntegrationStep(random.random())
1005 # --- USED POINT ---
1006 anObj.SetUsedPoints(random.random()*random.randint(-10000,10000))
1010 def dump_streamlines_parameters(theObject):
1012 dump_deformedshape_parameters(theObject)
1014 print "GetDirection() = " + str(theObject.GetDirection())
1015 print "GetStepLength() = " + str(theObject.GetStepLength())
1016 print "GetPropagationTime() =" + str(theObject.GetPropagationTime())
1017 print "GetIntegrationStep() =" + str(theObject.GetIntegrationStep())
1018 print "GetUsedPoints() =" + str(theObject.GetUsedPoints())
1020 # ----------------------
1022 # ----------------------
1023 def try_vectors_parameters(thePattern, theNum):
1025 if thePattern is None : return None
1028 GLIPH_TYPE = [VISU.Vectors.ARROW, VISU.Vectors.CONE2, VISU.Vectors.CONE6, VISU.Vectors.NONE]
1029 GLIPH_POS = [VISU.Vectors.CENTER, VISU.Vectors.TAIL, VISU.Vectors.HEAD]
1030 ind = random.randint(1,2)
1031 anObj = (try_deformedshape_parameters(thePattern))[0]
1033 # --- LINE WIDTH ---
1035 anObj.SetLineWidth(random.random()*random.randint(-10000,10000))
1037 anObj.SetLineWidth(random.randint(1, 10))
1039 # --- GLIPH TYPE ---
1040 anObj.SetGlyphType(GLIPH_TYPE[random.randint(0, len(GLIPH_TYPE)-1)])
1043 anObj.SetGlyphPos(GLIPH_POS[random.randint(0, len(GLIPH_POS)-1)])
1047 def dump_vectors_parameters(theObject):
1049 dump_deformedshape_parameters(theObject)
1051 print "GetLineWidth() = " +str(theObject.GetLineWidth())
1052 print "GetGlyphType() = " +str(theObject.GetGlyphType())
1053 print "GetGlyphPos() = " +str(theObject.GetGlyphPos())
1056 # ----------------------
1058 # ----------------------
1060 def try_isosurfaces_parameters(thePattern) :
1061 if thePattern is None : return None
1065 anObj = try_scalarmap_parameters(thePattern)
1066 ind = random.randint(1,2)
1067 # --- SURFACES NUMBER ---
1069 anObj.SetNbSurfaces(random.randint(-100000,100000))
1071 anObj.SetNbSurfaces(random.randint(1, 50))
1075 def dump_isosurfaces_parameters(theObject):
1077 dump_scalarmap_parameters(theObject)
1078 print "GetNbSurfaces() = "+ str(theObject.GetNbSurfaces())
1080 # ----------------------------
1081 # SCALAR MAP ON DEFORMED SHAPE
1082 # ----------------------------
1083 def dump_scalarmapondeformedshape_parameters(theObject):
1084 dump_scalarmap_parameters(theObject)
1085 print "GetScale() =", theObject.GetScale()
1086 print "GetScalarCMeshName ()=|",theObject.GetScalarCMeshName(),"|"
1087 print "GetScalarCFieldName()=|",theObject.GetScalarCFieldName(),"|"
1088 print "GetScalarEEntity() =",theObject.GetScalarEEntity()
1089 print "GetScalarLIteration()=",theObject.GetScalarLIteration()
1092 def try_scalarmapondeformedshape_parameters(thePattern):
1094 if thePattern is None : return None
1098 anObj = try_scalarmap_parameters(thePattern)
1102 anObj.SetScale( anObj.GetScale()/random.random()*random.randint(1,10))
1104 # --- Scalar Field ---
1105 # not implemented yet.
1108 # ----------------------
1110 # ----------------------
1111 def dump_plot3d_parameters(theObject):
1112 dump_scalarmap_parameters(theObject)
1113 print "GetOrientationType()=",str(theObject.GetOrientationType())
1114 print "GetRotateX()=",theObject.GetRotateX()
1115 print "GetRotateY()=",theObject.GetRotateY()
1116 print "GetPlanePosition()=",theObject.GetPlanePosition()
1117 print "IsPositionRelative()=",theObject.IsPositionRelative()
1118 print "GetScaleFactor()=",theObject.GetScaleFactor()
1119 print "GetIsContourPrs()=",theObject.GetIsContourPrs()
1120 print "GetNbOfContours()=",theObject.GetNbOfContours()
1123 def try_plot3d_parameters(thePattern):
1124 if thePattern is None : return None
1127 anObj = try_scalarmap_parameters(thePattern)
1129 ORIENT = [VISU.Plot3D.XY, VISU.Plot3D.YZ, VISU.Plot3D.ZX]
1131 theXAngle = random.random()*random.randint(-180,180)
1132 theYAngle = random.random()*random.randint(-180,180)
1134 # ORIENTATION and ANGLES
1135 anObj.SetOrientation(ORIENT[random.randint(0,2)],theXAngle,theYAngle)
1137 # Plane position (revative)
1138 anObj.SetPlanePosition(random.random(),1)
1141 anObj.SetScaleFactor(random.random()*random.randint(-10000,10000))
1144 anObj.SetContourPrs(random.randint(0,1))
1145 if anObj.GetIsContourPrs():
1146 anObj.SetNbOfContours(random.randint(1,999))
1151 # ----------------------
1153 # ----------------------
1154 def dump_gausspoints_parameters(theObject):
1156 print "\tGetScalarMode() = " + str(anObj.GetScalarMode())
1157 print "\tGetMin() = " + str(anObj.GetMin()) + " GetMax() = " + str (anObj.GetMax())
1158 print "\tGetPosX() = ", str(anObj.GetPosX()) + " GetPosY() = ", str(anObj.GetPosY())
1159 print "\tGetWidth() = ", str ( anObj.GetWidth()) + " GetHeight() = " + str(anObj.GetHeight())
1160 print "\tGetNbColors() = " + str(anObj.GetNbColors())
1161 print "\tGetLabels() = " + str(anObj.GetLabels())
1162 print "\tGetTitle() = " + str(anObj.GetTitle())
1165 def try_plot3d_parameters(thePattern):
1166 if thePattern is None : return None
1171 # ----------------------
1173 # ----------------------
1175 def FillTable( theTable, theValues, theRows, theColumns, theRowTitles, theRowUnits, theColumnTitles ):
1176 if theTable is None: return
1177 if len(theRows) != len(theColumns): return
1178 if len(theRows) != len(theValues): return
1180 for value in theValues:
1181 theTable.PutValue( value, theRows[ i ], theColumns[ i ])
1185 for title in theRowTitles:
1186 theTable.SetRowTitle( i, title )
1187 theTable.SetRowUnit( i, theRowUnits[ i - 1 ])
1191 for title in theColumnTitles:
1192 theTable.SetColumnTitle( i, title )
1197 def CreateCurve( theTable, theHRow, theVRow, theTitle, theColor, theMarker, theLineType, theLineWidth ):
1198 if theTitle is None: return
1199 curve = myLocalVisu.CreateCurve( theTable, theHRow, theVRow );
1201 curve.SetTitle( theTitle )
1202 curve.SetColor( theColor )
1203 curve.SetMarker( theMarker )
1204 curve.SetLine( theLineType, theLineWidth )
1208 def CreateCurveWithZ( theTable, theHRow, theVRow, theZRow, theTitle, theColor, theMarker, theLineType, theLineWidth ):
1209 if theTitle is None: return
1210 curve = myLocalVisu.CreateCurveWithZ( theTable, theHRow, theVRow, theZRow );
1212 curve.SetTitle( theTitle )
1213 curve.SetColor( theColor )
1214 curve.SetMarker( theMarker )
1215 curve.SetLine( theLineType, theLineWidth )
1219 def CreateCurveWithZExt( theTable, theHRow, theVRow, theZRow, theIsV2, theTitle, theColor, theMarker, theLineType, theLineWidth ):
1220 if theTitle is None: return
1221 curve = myLocalVisu.CreateCurveWithZExt( theTable, theHRow, theVRow, theZRow, theIsV2 );
1223 curve.SetTitle( theTitle )
1224 curve.SetColor( theColor )
1225 curve.SetMarker( theMarker )
1226 curve.SetLine( theLineType, theLineWidth )