1 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 # Copyright (C) 2003-2007 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
22 # VISU VISU_SWIG : binding of C++ implementation and Python
28 from time import sleep
32 import SALOME_Session_idl
35 import SALOME_ModuleCatalog
36 from omniORB import CORBA
38 from time import sleep
41 myNamingService = None
42 myLifeCycleCORBA = None
43 myNamingService = None
44 myLocalStudyManager = None
50 def Initialize(theORB, theNamingService, theLifeCycleCORBA, theStudyManager, theStudy, theDelay) :
51 global myORB, myNamingService, myLifeCycleCORBA, myLocalStudyManager, myLocalStudy
52 global mySession, myLocalVisu, myDelay
55 myNamingService = theNamingService
56 myLifeCycleCORBA = theLifeCycleCORBA
57 myLocalStudyManager = theStudyManager
58 while mySession == None:
59 mySession = myNamingService.Resolve("/Kernel/Session")
60 mySession = mySession._narrow(SALOME.Session)
61 mySession.GetInterface()
64 myLocalVisu = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "VISU")
65 myLocalStudy = theStudy
66 myLocalVisu.SetCurrentStudy(myLocalStudy)
69 def PublishComponent(theStudyDocument):
70 aComponentDataType = myLocalVisu.ComponentDataType()
71 aSComponent = theStudyDocument.FindComponent(aComponentDataType)
72 if aSComponent == None:
73 aStudyBuilder = theStudyDocument.NewBuilder()
74 aStudyBuilder.NewCommand()
75 aLocked = theStudyDocument.GetProperties().IsLocked()
77 theStudyDocument.GetProperties().SetLocked(0)
80 aSComponent = aStudyBuilder.NewComponent(aComponentDataType);
81 aName = aStudyBuilder.FindOrCreateAttribute(aSComponent,"AttributeName")
82 aModuleCatalogObj = myNamingService.Resolve("/Kernel/ModulCatalog");
83 aModuleCatalog = aModuleCatalogObj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
84 aComponent = aModuleCatalog.GetComponent(aComponentDataType);
85 if aComponent != None:
86 aComponentUserName = aComponent._get_componentusername()
87 aName.SetValue(aComponentUserName)
90 aPixMap = aStudyBuilder.FindOrCreateAttribute(aSComponent,"AttributePixMap")
91 aPixMap.SetPixMap("ICON_OBJBROWSER_Visu")
93 aStudyBuilder.DefineComponentInstance(aSComponent,myLocalVisu);
95 theStudyDocument.GetProperties().SetLocked(1);
98 aStudyBuilder.CommitCommand();
103 def SetName(theObj, theName):
104 anIOR = myORB.object_to_string(theObj)
105 aSObj = myLocalStudy.FindObjectIOR(anIOR)
106 anAttr = aSObj.FindAttribute("AttributeName")[1]
107 anAttr.SetValue(theName)
109 def StrToMap(theString) :
110 aPairList = split(theString,";")
112 iEnd = len(aPairList)
113 for i in range(iEnd) :
114 aPair = split(aPairList[i],"=")
115 aMap[aPair[0]] = aPair[1]
118 def IntToEntity(theInt) :
119 theInt = atoi(theInt)
129 def HasValue(theList, theValue) :
131 return theList.index(theValue) + 1
132 except StandardError, e :
135 def CreateStudyForMed(theVisu, theFileName) :
136 print "CreateStudyForMed ", theFileName,
137 if os.path.isfile(theFileName) :
138 if re.search("\.med$", theFileName) is not None :
140 aStudyName = os.path.basename(theFileName)
141 aStudyName = re.sub(r'\.med', "", aStudyName)
142 aStudyName = generateName(aStudyName)
143 print "myLocalStudyManager.NewStudy -", aStudyName, "...",
144 aStudy = myLocalStudyManager.NewStudy(aStudyName)
145 if aStudy is None : raise RuntimeError, "Error"
148 print "CreateStudyForMed - Creating a 3D viewer...",
149 theVisu.SetCurrentStudy(aStudy)
150 myViewManager = theVisu.GetViewManager()
151 if myViewManager is None : raise RuntimeError, "Error - theVisu.GetViewManager"
152 myView = myViewManager.Create3DView()
153 if myView is None : raise RuntimeError, "Error - myViewManager.Create3DView"
157 return [aStudy, myViewManager, myView]
158 raise RuntimeError, "Error: There is no such file."
160 def getMedSObject(theStudy = myLocalStudy ):
162 theStudy = myLocalStudy
163 aSO = theStudy.FindObject("Med")
164 anIsPresetn, aSObject = aSO.FindSubObject(1)
167 def getMedObjectFromStudy(theStudy = myLocalStudy):
168 aSObject = getMedSObject(theStudy)
170 anAttr = aSObject.FindAttribute("AttributeIOR")[1]
171 anObj = myORB.string_to_object(anAttr.Value())
172 return anObj._narrow(SALOME_MED.MED)
175 def getFieldObjectFromStudy(number, subnumber, theStudy = myLocalStudy):
177 theStudy = myLocalStudy
178 mySO = theStudy.FindObject("MEDFIELD")
180 raise Runtime, "getFieldObjectFromStudy mySO is None"
181 mysub = mySO.FindSubObject(number)[1]
183 mysubsub = mysub.FindSubObject(subnumber)[1]
185 Builder = theStudy.NewBuilder()
186 anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
187 obj = myORB.string_to_object(anAttr.Value())
188 myObj = obj._narrow(SALOME_MED.FIELDINT)
190 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
193 print "ERROR: No Field Object stored in this Study"
196 def SObjectToObject(theSObject) :
198 if theSObject is None :
199 print "SObjectToObject : argument is None"
201 res,Attr = theSObject.FindAttribute("AttributeIOR")
202 if (res != 0) and (Attr is not None) :
203 anIOR = Attr._narrow(SALOMEDS.AttributeIOR);
204 aValue = anIOR.Value();
205 if(len(aValue) != 0) :
206 anObj = myORB.string_to_object(aValue);
208 print "SObjectToObject - IOR = ''"
211 def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
213 global myLifeCycleCORBA
214 print "lcc.FindOrLoadComponent...",
215 aMedComp = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "MED")
216 if aMedComp is None : print "Error"
219 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
221 print "aMedComp.readStructFileWithFieldType...",
222 aMedComp.readStructFileWithFieldType(theFileName,myLocalStudy._get_Name())
223 aMedSObj = getMedSObject(myLocalStudy)
224 if aMedSObj is None : raise RuntimeError, "Error"
227 print "theVisu.ImportMed...",
228 aResult = theVisu.ImportMed(aMedSObj)
229 if aResult is None : raise RuntimeError, "Error"
232 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
234 aResult.RemoveFromStudy()
236 aVISUObjList.append(aResult)
238 aFolderIter = myLocalStudy.NewChildIterator(aMedSObj.GetFather());
239 while aFolderIter.More() :
240 aFolderSObj = aFolderIter.Value()
242 anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
243 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
244 aFolderName = anAttr.Value()
245 print " ", aFolderName
247 if aFolderName == 'MEDMESH' :
248 aMeshIter = myLocalStudy.NewChildIterator(aFolderSObj);
249 while aMeshIter.More() :
250 aMeshSObj = aMeshIter.Value()
252 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
253 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
254 aMeshName = anAttr.Value()
257 aSupportIter = myLocalStudy.NewChildIterator(aMeshSObj);
258 while aSupportIter.More() :
259 aSupportSObj = aSupportIter.Value()
261 anAttr = aSupportSObj.FindAttribute("AttributeName")[1]
262 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
263 aSupportName = anAttr.Value()
264 print " ", aSupportName
266 if aFolderName == 'MEDFIELD' :
267 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
268 while aFieldIter.More() :
269 aFieldSObj = aFieldIter.Value()
271 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
272 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
273 aFieldName = anAttr.Value()
274 print " ", aFieldName
276 print "theVisu.ImportMed...",
277 aResult = theVisu.ImportMed(aFieldSObj)
278 if aResult is None : raise RuntimeError, "Error"
281 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
283 aResult.RemoveFromStudy()
285 aVISUObjList.append(aResult)
287 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
288 if aTimeStampIter.More() :
289 aTimeStampIter.Next()
290 while aTimeStampIter.More() :
291 aTimeStampSObj = aTimeStampIter.Value()
292 aTimeStampIter.Next()
293 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
294 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
295 aTimeStampName = anAttr.Value()
296 print " ", aTimeStampName
298 print "theVisu.ImportMed...",
299 aMedField = SObjectToObject(aTimeStampSObj)
300 aResult = theVisu.ImportMedField(aMedField)
301 if aResult is None : raise RuntimeError, "Error"
304 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
306 aResult.RemoveFromStudy()
308 aVISUObjList.append(aResult)
312 # except Exception, e:
315 def CreatePrsForFile(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
317 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
319 print "theVisu.ImportMed...",
320 aResult = theVisu.ImportFile(theFileName)
321 if aResult is None : raise RuntimeError, "Error"
324 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
327 aResult.RemoveFromStudy()
329 aVISUObjList.append(aResult)
333 # except Exception, e:
336 def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
338 if theIsAutoDelete is not None :
342 print "CreatePrsForResult - myLocalStudy.FindObjectIOR...",
343 myLocalStudy = theVisu.GetCurrentStudy()
345 aSObj = myLocalStudy.FindObjectIOR(theResult.GetID())
346 if aSObj is None : raise RuntimeError, "Error"
348 aMeshIter = myLocalStudy.NewChildIterator(aSObj);
349 while aMeshIter.More() :
350 aMeshSObj = aMeshIter.Value()
352 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
354 aMeshSObj = aMeshIter.Value()
356 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
357 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
358 aMeshName = anAttr.Value()
359 aMeshNamePic = re.sub(".","_",aMeshName)
362 aFolderIter = myLocalStudy.NewChildIterator(aMeshSObj);
363 while aFolderIter.More() :
364 aFolderSObj = aFolderIter.Value()
366 anIsFound, anAttr = aFolderSObj.FindAttribute("AttributeName")
369 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
370 aFolderName = anAttr.Value()
371 print " ", aFolderName
373 if aFolderName == 'Families' :
374 anEntityIter = myLocalStudy.NewChildIterator(aFolderSObj);
375 while anEntityIter.More() :
376 anEntitySObj = anEntityIter.Value()
378 anAttr = anEntitySObj.FindAttribute("AttributeName")[1]
379 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
380 anEntityName = anAttr.Value()
383 if anEntityName == 'onNodes' :
386 if anEntityName == 'onEdges' :
389 if anEntityName == 'onFaces' :
392 if anEntityName == 'onCells' :
396 if HasValue(thePrsTypeList,VISU.TMESH) :
397 print " ", anEntityName, aMeshName,
398 aMesh = theVisu.MeshOnEntity(theResult,aMeshName,anEntity)
399 if aMesh is None : print "Error"
402 theView.DisplayOnly(aMesh)
404 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "." + thePictureExt
405 aPictureName = re.sub("\s+","_", aPictureName);
406 theView.SavePicture(aPictureName)
408 aMesh.RemoveFromStudy()
410 aVISUObjList.append(aMesh)
412 anFamilyIter = myLocalStudy.NewChildIterator(anEntitySObj);
413 while anFamilyIter.More() :
414 aFamilySObj = anFamilyIter.Value()
416 anAttr = aFamilySObj.FindAttribute("AttributeName")[1]
417 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
418 anFamilyName = anAttr.Value()
419 if HasValue(thePrsTypeList,VISU.TMESH) :
420 print " ", anFamilyName,
421 aMesh = theVisu.FamilyMeshOnEntity(theResult,aMeshName,anEntity,anFamilyName)
422 if aMesh is None : print "Error"
425 theView.DisplayOnly(aMesh)
427 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + anFamilyName + "." + thePictureExt
428 aPictureName = re.sub("\s+","_", aPictureName);
429 theView.SavePicture(aPictureName)
431 aMesh.RemoveFromStudy()
433 aVISUObjList.append(aMesh)
435 if aFolderName == 'Groups' :
436 aGroupIter = myLocalStudy.NewChildIterator(aFolderSObj);
437 while aGroupIter.More() :
438 aGroupSObj = aGroupIter.Value()
440 anAttr = aGroupSObj.FindAttribute("AttributeName")[1]
441 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
442 aGroupName = anAttr.Value()
443 if HasValue(thePrsTypeList,VISU.TMESH) :
444 print " ", aGroupName,
445 aMesh = theVisu.GroupMesh(theResult,aMeshName,aGroupName)
446 if aMesh is None : print "Error"
449 theView.DisplayOnly(aMesh)
451 aPictureName = thePictureDir + aMeshNamePic + "_" + aGroupName + "." + thePictureExt
452 aPictureName = re.sub("\s+","_", aPictureName);
453 theView.SavePicture(aPictureName)
455 aMesh.RemoveFromStudy()
457 aVISUObjList.append(aMesh)
459 if aFolderName == 'Fields' :
460 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
461 while aFieldIter.More() :
462 aFieldSObj = aFieldIter.Value()
464 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
465 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
466 aFieldName = anAttr.Value()
467 print " ", aFieldName
469 anAttr = aFieldSObj.FindAttribute("AttributeString")[1]
470 anAttr = anAttr._narrow(SALOMEDS.AttributeString);
471 aFieldComment = anAttr.Value()
472 aMap = StrToMap(aFieldComment)
474 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
475 if aTimeStampIter.More() :
476 aTimeStampIter.Next()
477 while aTimeStampIter.More() :
478 aTimeStampSObj = aTimeStampIter.Value()
479 aTimeStampIter.Next()
480 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
481 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
482 aTimeStampName = anAttr.Value()
483 print " ", aTimeStampName
485 anAttr = aTimeStampSObj.FindAttribute("AttributeString")[1]
486 anAttr = anAttr._narrow(SALOMEDS.AttributeString);
487 aTimeStampComment = anAttr.Value()
488 aMap = StrToMap(aTimeStampComment)
489 aMeshName = aMap["myMeshName"]
490 aFieldName = aMap["myFieldName"]
491 aTimeStampId = atoi(aMap["myTimeStampId"])
492 anEntity = IntToEntity(aMap["myEntityId"])
493 anEntityId = str(aMap["myEntityId"]);
494 #print aMeshName, aFieldName, anEntity, aTimeStampId
495 if HasValue(thePrsTypeList,VISU.TSCALARMAP) :
496 print " Creating ScalarMapOnField",
497 aPrsObj = theVisu.ScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
498 if aPrsObj is None : print "Error"
501 theView.DisplayOnly(aPrsObj)
503 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAP." + thePictureExt
504 aPictureName = re.sub("\s+","_", aPictureName);
505 theView.SavePicture(aPictureName)
507 aPrsObj.RemoveFromStudy()
509 aVISUObjList.append(aPrsObj)
511 if HasValue(thePrsTypeList,VISU.TISOSURFACES) :
512 print " Creating IsoSurfacesOnField",
513 aPrsObj = theVisu.IsoSurfacesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
514 if aPrsObj is None : print "Error"
517 theView.DisplayOnly(aPrsObj)
519 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TISOSURFACES." + thePictureExt
520 aPictureName = re.sub("\s+","_", aPictureName);
521 theView.SavePicture(aPictureName)
523 aPrsObj.RemoveFromStudy()
525 aVISUObjList.append(aPrsObj)
527 if HasValue(thePrsTypeList,VISU.TCUTPLANES) :
528 print " Creating CutPlanesOnField",
529 aPrsObj = theVisu.CutPlanesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
530 if aPrsObj is None : print "Error"
533 aPrsObj.SetOrientation(VISU.CutPlanes.ZX,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
534 theView.DisplayOnly(aPrsObj)
536 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTPLANES." + thePictureExt
537 aPictureName = re.sub("\s+","_", aPictureName)
538 theView.SavePicture(aPictureName)
540 aPrsObj.RemoveFromStudy()
542 aVISUObjList.append(aPrsObj)
544 if HasValue(thePrsTypeList,VISU.TCUTLINES) :
545 print " Creating CutLinesOnField",
546 aPrsObj = theVisu.CutLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
547 if aPrsObj is None : print "Error"
550 aPrsObj.SetOrientation(VISU.CutPlanes.XY,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
551 aPrsObj.SetOrientation2(VISU.CutPlanes.ZX,aPrsObj.GetRotateX2(),aPrsObj.GetRotateY2())
552 theView.DisplayOnly(aPrsObj)
554 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTLINES." + thePictureExt
555 aPictureName = re.sub("\s+","_", aPictureName)
556 theView.SavePicture(aPictureName)
558 aPrsObj.RemoveFromStudy()
560 aVISUObjList.append(aPrsObj)
562 if HasValue(thePrsTypeList,VISU.TCUTSEGMENT) :
563 print " Creating CutSegmentOnField",
564 aPrsObj = theVisu.CutSegmentOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
565 if aPrsObj is None : print "Error"
568 theView.DisplayOnly(aPrsObj)
570 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTSEGMENT." + thePictureExt
571 aPictureName = re.sub("\s+","_", aPictureName)
572 theView.SavePicture(aPictureName)
574 aPrsObj.RemoveFromStudy()
576 aVISUObjList.append(aPrsObj)
578 if HasValue(thePrsTypeList,VISU.TPLOT3D) :
579 print " Creating Plot3DOnField",
580 aPrsObj = theVisu.Plot3DOnField(theResult,aMeshName,anEntity,
581 aFieldName,aTimeStampId)
582 if aPrsObj is None : print "Error"
585 #aPrsObj.SetOrientation(VISU.CutPlanes.ZX,
586 # aPrsObj.GetRotateX(),
587 # aPrsObj.GetRotateY())
588 theView.DisplayOnly(aPrsObj)
590 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TPLOT3D." + thePictureExt
591 aPictureName = re.sub("\s+","_", aPictureName)
592 theView.SavePicture(aPictureName)
594 aPrsObj.RemoveFromStudy()
596 aVISUObjList.append(aPrsObj)
598 aNumComponent = atoi(aMap["myNumComponent"])
599 if aNumComponent > 1 :
600 if HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPE) :
601 print " Creating DeformedShapeOnField",
602 aPrsObj = theVisu.DeformedShapeOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
603 if aPrsObj is None : print "Error"
606 theView.DisplayOnly(aPrsObj)
608 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPE." + thePictureExt
609 aPictureName = re.sub("\s+","_", aPictureName)
610 theView.SavePicture(aPictureName)
612 aPrsObj.RemoveFromStudy()
614 aVISUObjList.append(aPrsObj)
616 if HasValue(thePrsTypeList,VISU.TVECTORS) :
617 print " Creating VectorsOnField",
618 aPrsObj = theVisu.VectorsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
619 if aPrsObj is None : print "Error"
622 theView.DisplayOnly(aPrsObj)
624 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TVECTORS." + thePictureExt
625 aPictureName = re.sub("\s+","_", aPictureName)
626 theView.SavePicture(aPictureName)
628 aPrsObj.RemoveFromStudy()
630 aVISUObjList.append(aPrsObj)
632 if HasValue(thePrsTypeList,VISU.TSTREAMLINES) :
633 print " Creating StreamLinesOnField",
634 aPrsObj = theVisu.StreamLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
635 if aPrsObj is None : print "Error"
638 theView.DisplayOnly(aPrsObj)
640 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSTREAMLINES." + thePictureExt
641 aPictureName = re.sub("\s+","_", aPictureName)
642 theView.SavePicture(aPictureName)
644 aPrsObj.RemoveFromStudy()
646 aVISUObjList.append(aPrsObj)
648 if HasValue(thePrsTypeList,VISU.TSCALARMAPONDEFORMEDSHAPE) or HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPEANDSCALARMAP) :
649 print " Creating DeformedShapeAndScalarMapOnField",
650 aPrsObj = theVisu.DeformedShapeAndScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
651 if aPrsObj is None : print "Error"
654 theView.DisplayOnly(aPrsObj)
656 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPEANDSCALARMAP." + thePictureExt
657 aPictureName = re.sub("\s+","_", aPictureName)
658 theView.SavePicture(aPictureName)
660 aPrsObj.RemoveFromStudy()
662 aVISUObjList.append(aPrsObj)
664 if HasValue(thePrsTypeList,VISU.TGAUSSPOINTS) :
665 print " Creating GaussPointsOnField",
666 aPrsObj = theVisu.GaussPointsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
667 if aPrsObj is None : print "Error"
670 theView.DisplayOnly(aPrsObj)
672 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TGAUSSPOINTS." + thePictureExt
673 aPictureName = re.sub("\s+","_", aPictureName)
674 theView.SavePicture(aPictureName)
676 aPrsObj.RemoveFromStudy()
679 aVISUObjList.append(aPrsObj)
687 def generateName(prefix = None):
689 int = whrandom.randint(1,1000);
691 return "Study" + str(int)
693 return prefix + str(int)
697 # ----------------------
699 # ----------------------
700 def try_mesh_parameters(theMeshPattern):
702 if theMeshPattern is None : return aResult ;
703 theMeshPattern = theMeshPattern._narrow(VISU.Mesh)
704 if theMeshPattern is None : return aResult ;
706 aTYPES = [VISU.POINT, VISU.WIREFRAME, VISU.SHADED, VISU.INSIDEFRAME, VISU.SHRINK]
707 import copy; import os;
709 aNewMesh = copy.deepcopy(theMeshPattern);
710 aNewMesh.SetPresentationType(ind)
711 aResult.append(aNewMesh)
716 # ----------------------------
718 # ----------------------------
720 def try_scalarmap_parameters(thePattern, dump = 0):
722 if thePattern is None : return None
724 SCALING = [VISU.LINEAR, VISU.LOGARITHMIC]
728 anObj = thePattern#copy.deepcopy(thePattern);
729 #ind = random.randint(1,2)
731 #try incorrect value deliberately (but allowed by idl description)
732 #try SetScalarMode(long)
733 mode = random.randint(-100000,100000); #incorrect value deliberately
735 #correct value of ScalarMode
736 mode = random.randint(0, 3)
738 if dump : print "\tSetScalarMode(" + str(mode) +")"
739 anObj.SetScalarMode(mode)
742 scal = random.randint(0,1)
743 if dump : print "\tSetScaling(" + str(SCALING[scal]) +")"
744 anObj.SetScaling(SCALING[scal])
748 alfa = random.random()*random.randint(-100000,100000)
749 betta = random.random()*random.randint(-100000,100000)
750 aMin = alfa; aMax = betta
753 aPMin = thePattern.GetMin()
754 aPMax = thePattern.GetMax()
756 alfa = random.random()%0.5
757 betta = random.random()%0.5
758 aMin = alfa*aLen*random.randint(-1,1) + aPMin
759 aMax = betta*aLen*random.randint(-1,1) + aPMax
760 if dump : print "\tSetRange(" + str(aMin) + ", " + str(aMax) + ")"
761 anObj.SetRange(aMin, aMax)
765 X=random.random()*random.randint(-100000,100000)
766 Y=random.random()*random.randint(-100000,100000)
770 if dump : print "SetPosition("+ str(X) + ", " + str(Y) + " )"
771 anObj.SetPosition(X, Y)
773 # --- SCALAR BAR SIZE ---
775 aWidth=random.random()*random.randint(-100000,100000)
776 aHeight=random.random()*random.randint(-100000,100000)
778 aWidth=random.random()
779 aHeight=random.random()
780 if dump : print " SCALAR BAR Width = " + str(aWidth) + " Height = ", str(aHeight)
781 anObj.SetSize(aWidth, aHeight)
786 def dump_scalarmap_parameters(anObj):
788 print "\tGetScalarMode() = " + str(anObj.GetScalarMode())
789 print "\tGetScaling() = " + str(anObj.GetScaling())
790 print "\tGetMin() = " + str(anObj.GetMin()) + " GetMax() = " + str (anObj.GetMax())
791 print "\tGetOrientation() = " + str(anObj.GetOrientation())
792 print "\tGetPosX() = ", str(anObj.GetPosX()) + " GetPosY() = ", str(anObj.GetPosY())
793 print "\tGetWidth() = ", str ( anObj.GetWidth()) + " GetHeight() = " + str(anObj.GetHeight())
795 # ----------------------
797 # ----------------------
798 def try_deformedshape_parameters(thePattern) :
800 if thePattern is None : return None
804 anObj = try_scalarmap_parameters(thePattern)
808 anObj.SetScale( random.random()*random.randint(-100000, 100000))
810 anObj.SetScale( anObj.GetScale()*random.random())
815 def dump_deformedshape_parameters(theObject):
816 dump_scalarmap_parameters(theObject)
817 print "GetScale() = ", theObject.GetScale()
819 # ----------------------
821 # ----------------------
822 def try_cutplanes_parameters(thePattern) :
824 if thePattern is None : return None
828 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
830 ind = random.randint(1,2)
831 anObj = try_scalarmap_parameters(thePattern)
833 if ind%2 : anObj.SetNbPlanes(random.randint(-40,40))
834 else : anObj.SetNbPlanes(random.randint(0,10)) #try behaivor if NbPlanes=0
836 # --- DISPLACEMENT ---
837 anObj.SetDisplacement(random.randint(-100000,100000))
839 # --- PLANE POSITION ---
841 PlaneNb = random.randint(-100000,100000) #incorrect value is possible
842 else : PlaneNb = random.randint(0, anObj.GetNbPlanes())
844 anObj.SetPlanePosition(PlaneNb, random.random()*random.randint(-100000,100000))
846 # --- SET DEFAULT ---
847 anObj.SetDefault(PlaneNb)
849 # --- SET X,Y,Z ROTATION ---
851 angle1 = random.random()*random.randint(-100000,100000)
852 angle2 = random.random()*random.randint(-100000,100000)
854 angle1 = random.random()*3.14
855 angle2 = random.random()*3.14
857 # --- ORIENTATION ---
858 anObj.SetOrientation(ORIENT[random.randint(0,2)],angle1,angle2)
862 def dump_cutplanes_parameters(theObject):
863 dump_saclarmap_parameters(theObject)
865 print "GetOrientationType = " + str(theObject.GetOrientationType())
866 PlanesNb = theObject.GetNbPlanes()
867 print "GetNbPlanes() = ", str(PlanesNb)
868 for i in range(0,PlanesNb+1):
869 if theObject.IsDefault(i) :
870 print "Default plane : "+str(i); break
871 print "GetPlanePosition(" + str(i) + ") = ", theObject.GetPlanePosition(i)
872 print "GetDisplacement() = ", str(theObject.GetDisplacement())
873 print "GetRotateX() = ", str(theObject.GetRotateX())
874 print "GetRotateY() = ", str(theObject.GetRotateY())
875 print "GetRotateZ() = ", str(theObject.GetRotateZ())
877 # ----------------------
879 # ----------------------
880 def try_cutlines_parameters(thePattern):
882 if thePattern is None : return None
886 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
887 ind = random.randint(1,2)
888 anObj = try_scalarmap_parameters(thePattern)
890 # --- ORIENTATION ---
891 anObj.SetOrientation(ORIENT[random.randint(0,2)],
892 random.randint(-100,100)*random.random(),
893 random.randint(-100,100)*random.random())
894 anObj.SetOrientation2(ORIENT[random.randint(0,2)],
895 random.randint(-100,100)*random.random(),
896 random.randint(-100,100)*random.random())
898 # --- Base Plane Position ---
899 anObj.SetBasePlanePosition( random.random()*random.randint(-100000,100000))
901 # --- NUMBER OF LINES ---
903 anObj.SetNbLines(random.randint(-5, 50))
907 def dump_cutlines_parameters(theObject):
908 dump_scalarmap_parameters(theObject)
910 print "GetOrientationType() = " + str(theObject.GetOrientationType())
911 print "GetOrientationType2() = " + str(theObject.GetOrientationType2())
912 print "GetBasePlanePosition() = "+ str(theObject.GetBasePlanePosition())
913 print "GetNbLines() = " + str(theObject.GetNbLines())
914 print "GetRotateX() = ", str(theObject.GetRotateX())
915 print "GetRotateX2() = ", str(theObject.GetRotateX2())
916 print "GetRotateY() = ", str(theObject.GetRotateY())
917 print "GetRotateY2() = ", str(theObject.GetRotateY2())
919 # ----------------------
921 # ----------------------
922 def try_cutsegment_parameters(thePattern):
924 if thePattern is None : return None
928 anObj = try_scalarmap_parameters(thePattern)
930 anObj.SetPoint1(random.randint(-100,100)*random.random(),
931 random.randint(-100,100)*random.random(),
932 random.randint(-100,100)*random.random())
933 anObj.SetPoint2(random.randint(-100,100)*random.random(),
934 random.randint(-100,100)*random.random(),
935 random.randint(-100,100)*random.random())
939 def dump_cutsegment_parameters(theObject):
940 dump_scalarmap_parameters(theObject)
944 theObject.GetPoint1(x1, y1, z1)
945 theObject.GetPoint1(x2, y2, z2)
946 print "GetPoint1() = " + str(x1) + ", " + str(y1) + ", " + str(z1)
947 print "GetPoint2() = " + str(x2) + ", " + str(y2) + ", " + str(z2)
949 # ----------------------
951 # ----------------------
952 def try_streamlines_parameters(thePattern):
954 if thePattern is None : return None
958 DIRECTION = [VISU.StreamLines.FORWARD, VISU.StreamLines.BACKWARD, VISU.StreamLines.BOTH]
960 ind = random.randint(1,2)
961 anObj = (try_deformedshape_parameters(thePattern))[0]
964 anObj.SetDirection(DIRECTION[random.randint(0,2)])
966 # --- STEP LENGTH ---
967 if ind%2 : anObj.SetStepLength(random.random()*random.randint(-1000,1000))
969 aLen = anObj.GetMax() - anObj.GetMin()
970 anObj.SetStepLength(aLen/random.randint(1,100))
972 # --- PROPAGATION TIME ---
973 anObj.SetPropagationTime(random.random()*random.randint(1,100))
975 # --- INTEGRATION STEP ---
977 anObj.SetIntegrationStep(random.random()*random.randint(-1000,1000))
979 anObj.SetIntegrationStep(random.random())
982 anObj.SetUsedPoints(random.random()*random.randint(-10000,10000))
986 def dump_streamlines_parameters(theObject):
988 dump_deformedshape_parameters(theObject)
990 print "GetDirection() = " + str(theObject.GetDirection())
991 print "GetStepLength() = " + str(theObject.GetStepLength())
992 print "GetPropagationTime() =" + str(theObject.GetPropagationTime())
993 print "GetIntegrationStep() =" + str(theObject.GetIntegrationStep())
994 print "GetUsedPoints() =" + str(theObject.GetUsedPoints())
996 # ----------------------
998 # ----------------------
999 def try_vectors_parameters(thePattern, theNum):
1001 if thePattern is None : return None
1004 GLIPH_TYPE = [VISU.Vectors.ARROW, VISU.Vectors.CONE2, VISU.Vectors.CONE6, VISU.Vectors.NONE]
1005 GLIPH_POS = [VISU.Vectors.CENTER, VISU.Vectors.TAIL, VISU.Vectors.HEAD]
1006 ind = random.randint(1,2)
1007 anObj = (try_deformedshape_parameters(thePattern))[0]
1009 # --- LINE WIDTH ---
1011 anObj.SetLineWidth(random.random()*random.randint(-10000,10000))
1013 anObj.SetLineWidth(random.randint(1, 10))
1015 # --- GLIPH TYPE ---
1016 anObj.SetGlyphType(GLIPH_TYPE[random.randint(0, len(GLIPH_TYPE)-1)])
1019 anObj.SetGlyphPos(GLIPH_POS[random.randint(0, len(GLIPH_POS)-1)])
1023 def dump_vectors_parameters(theObject):
1025 dump_deformedshape_parameters(theObject)
1027 print "GetLineWidth() = " +str(theObject.GetLineWidth())
1028 print "GetGlyphType() = " +str(theObject.GetGlyphType())
1029 print "GetGlyphPos() = " +str(theObject.GetGlyphPos())
1032 # ----------------------
1034 # ----------------------
1036 def try_isosurfaces_parameters(thePattern) :
1037 if thePattern is None : return None
1041 anObj = try_scalarmap_parameters(thePattern)
1042 ind = random.randint(1,2)
1043 # --- SURFACES NUMBER ---
1045 anObj.SetNbSurfaces(random.randint(-100000,100000))
1047 anObj.SetNbSurfaces(random.randint(1, 50))
1051 def dump_isosurfaces_parameters(theObject):
1053 dump_scalarmap_parameters(theObject)
1054 print "GetNbSurfaces() = "+ str(theObject.GetNbSurfaces())
1056 # ----------------------------
1057 # SCALAR MAP ON DEFORMED SHAPE
1058 # ----------------------------
1059 def dump_scalarmapondeformedshape_parameters(theObject):
1060 dump_scalarmap_parameters(theObject)
1061 print "GetScale() =", theObject.GetScale()
1062 print "GetScalarCMeshName ()=|",theObject.GetScalarCMeshName(),"|"
1063 print "GetScalarCFieldName()=|",theObject.GetScalarCFieldName(),"|"
1064 print "GetScalarEEntity() =",theObject.GetScalarEEntity()
1065 print "GetScalarLIteration()=",theObject.GetScalarLIteration()
1068 def try_scalarmapondeformedshape_parameters(thePattern):
1070 if thePattern is None : return None
1074 anObj = try_scalarmap_parameters(thePattern)
1078 anObj.SetScale( anObj.GetScale()/random.random()*random.randint(1,10))
1080 # --- Scalar Field ---
1081 # not implemented yet.
1084 # ----------------------
1086 # ----------------------
1087 def dump_plot3d_parameters(theObject):
1088 dump_scalarmap_parameters(theObject)
1089 print "GetOrientationType()=",str(theObject.GetOrientationType())
1090 print "GetRotateX()=",theObject.GetRotateX()
1091 print "GetRotateY()=",theObject.GetRotateY()
1092 print "GetPlanePosition()=",theObject.GetPlanePosition()
1093 print "IsPositionRelative()=",theObject.IsPositionRelative()
1094 print "GetScaleFactor()=",theObject.GetScaleFactor()
1095 print "GetIsContourPrs()=",theObject.GetIsContourPrs()
1096 print "GetNbOfContours()=",theObject.GetNbOfContours()
1099 def try_plot3d_parameters(thePattern):
1100 if thePattern is None : return None
1103 anObj = try_scalarmap_parameters(thePattern)
1105 ORIENT = [VISU.Plot3D.XY, VISU.Plot3D.YZ, VISU.Plot3D.ZX]
1107 theXAngle = random.random()*random.randint(-180,180)
1108 theYAngle = random.random()*random.randint(-180,180)
1110 # ORIENTATION and ANGLES
1111 anObj.SetOrientation(ORIENT[random.randint(0,2)],theXAngle,theYAngle)
1113 # Plane position (revative)
1114 anObj.SetPlanePosition(random.random(),1)
1117 anObj.SetScaleFactor(random.random()*random.randint(-10000,10000))
1120 anObj.SetContourPrs(random.randint(0,1))
1121 if anObj.GetIsContourPrs():
1122 anObj.SetNbOfContours(random.randint(1,999))
1127 # ----------------------
1129 # ----------------------
1130 def dump_gausspoints_parameters(theObject):
1132 print "\tGetScalarMode() = " + str(anObj.GetScalarMode())
1133 print "\tGetMin() = " + str(anObj.GetMin()) + " GetMax() = " + str (anObj.GetMax())
1134 print "\tGetPosX() = ", str(anObj.GetPosX()) + " GetPosY() = ", str(anObj.GetPosY())
1135 print "\tGetWidth() = ", str ( anObj.GetWidth()) + " GetHeight() = " + str(anObj.GetHeight())
1136 print "\tGetNbColors() = " + str(anObj.GetNbColors())
1137 print "\tGetLabels() = " + str(anObj.GetLabels())
1138 print "\tGetTitle() = " + str(anObj.GetTitle())
1141 def try_plot3d_parameters(thePattern):
1142 if thePattern is None : return None
1147 # ----------------------
1149 # ----------------------
1151 def FillTable( theTable, theValues, theRows, theColumns, theRowTitles, theRowUnits, theColumnTitles ):
1152 if theTable is None: return
1153 if len(theRows) != len(theColumns): return
1154 if len(theRows) != len(theValues): return
1156 for value in theValues:
1157 theTable.PutValue( value, theRows[ i ], theColumns[ i ])
1161 for title in theRowTitles:
1162 theTable.SetRowTitle( i, title )
1163 theTable.SetRowUnit( i, theRowUnits[ i - 1 ])
1167 for title in theColumnTitles:
1168 theTable.SetColumnTitle( i, title )
1173 def CreateCurve( theTable, theHRow, theVRow, theTitle, theColor, theMarker, theLineType, theLineWidth ):
1174 if theTitle is None: return
1175 curve = myLocalVisu.CreateCurve( theTable, theHRow, theVRow );
1177 curve.SetTitle( theTitle )
1178 curve.SetColor( theColor )
1179 curve.SetMarker( theMarker )
1180 curve.SetLine( theLineType, theLineWidth )