Salome HOME
Fix for 10531.
[modules/visu.git] / src / VISU_SWIG / visu.py
1 #  VISU VISU_SWIG : binding of C++ implementation and Python
2 #
3 #  Copyright (C) 2003  CEA/DEN, EDF R&D
4 #
5 #
6 #
7 #  File   : visu.py
8 #  Module : VISU
9
10 import os
11 import re
12 from time import sleep
13
14 import VISU
15 import SALOME
16 import SALOME_Session_idl
17 import SALOMEDS
18 import SALOME_MED
19 from omniORB import CORBA
20 from string import *
21 from time import sleep
22
23 myORB = None
24 myNamingService = None
25 myLifeCycleCORBA = None
26 myNamingService = None
27 myLocalStudyManager = None
28 myLocalStudy = None
29 myLocalVisu = None
30 myDelay = None
31 mySession = None
32  
33 def Initialize(theORB, theNamingService, theLifeCycleCORBA, theStudyManager, theStudy, theDelay) :
34     global myORB, myNamingService, myLifeCycleCORBA, myLocalStudyManager, myLocalStudy
35     global mySession, myLocalVisu, myDelay
36     myDelay = theDelay
37     myORB = theORB
38     myNamingService = theNamingService
39     myLifeCycleCORBA = theLifeCycleCORBA
40     myLocalStudyManager = theStudyManager
41     while mySession == None:
42         mySession = myNamingService.Resolve("/Kernel/Session")
43     mySession = mySession._narrow(SALOME.Session)
44     mySession.GetInterface()
45     myDelay = theDelay
46     sleep(myDelay)
47     myLocalVisu = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "VISU")
48     myLocalStudy = theStudy
49     myLocalVisu.SetCurrentStudy(myLocalStudy)
50     return myLocalVisu
51
52 def PublishComponent(theStudyDocument):
53     aComponentDataType = myLocalVisu.ComponentDataType()
54     aSComponent = theStudyDocument.FindComponent(aComponentDataType)
55     if aSComponent == None:
56         aStudyBuilder = theStudyDocument.NewBuilder()
57         aStudyBuilder.NewCommand()
58         aLocked = theStudyDocument.GetProperties().IsLocked()
59         if aLocked:
60             theStudyDocument.GetProperties().SetLocked(0)
61             pass
62
63         aSComponent = aStudyBuilder.NewComponent(aComponentDataType);
64         aName = aStudyBuilder.FindOrCreateAttribute(aSComponent,"AttributeName")
65         aModuleCatalog = myNamingService.Resolve("/Kernel/ModulCatalog");
66         aComponent = aModuleCatalog.GetComponent(aComponentDataType);
67         if aComponent != None:
68             aComponentUserName = aComponent._get_componentusername()
69             aName.SetValue(aComponentUserName)
70             pass
71         
72         aPixMap = aStudyBuilder.FindOrCreateAttribute(aSComponent,"AttributePixMap")
73         aPixMap.SetPixMap("ICON_OBJBROWSER_Visu")
74         
75         aStudyBuilder.DefineComponentInstance(aSComponent,myLocalVisu);
76         if aLocked:
77             theStudyDocument.GetProperties().SetLocked(1);
78             pass
79         
80         aStudyBuilder.CommitCommand();
81         pass
82     
83     return aSComponent;
84         
85 def StrToMap(theString) :
86     aPairList = split(theString,";")
87     aMap = {}
88     iEnd = len(aPairList)
89     for i in range(iEnd) :
90         aPair = split(aPairList[i],"=")
91         aMap[aPair[0]] = aPair[1]
92     return aMap
93
94 def IntToEntity(theInt) :
95     theInt = atoi(theInt)
96     if theInt == 0 :
97         return VISU.NODE;
98     elif theInt == 1 :
99         return VISU.EDGE;
100     elif theInt == 2 :
101         return VISU.FACE;
102     else :
103         return VISU.CELL;
104         
105 def HasValue(theList, theValue) :
106     try :
107         return theList.index(theValue) + 1
108     except StandardError, e :
109         return 0
110
111 def CreateStudyForMed(theVisu, theFileName) :
112     print "CreateStudyForMed ", theFileName,
113     if os.path.isfile(theFileName) :
114         if re.search("\.med$", theFileName) is not None :
115             print "OK"
116             aStudyName = os.path.basename(theFileName)
117             aStudyName = re.sub(r'\.med', "", aStudyName)
118             aStudyName = generateName(aStudyName)
119             print "myLocalStudyManager.NewStudy -", aStudyName, "...",
120             aStudy = myLocalStudyManager.NewStudy(aStudyName)
121             if aStudy is None : raise RuntimeError, "Error"
122             else : print "OK"
123             
124             print "CreateStudyForMed - Creating a 3D viewer...",
125             theVisu.SetCurrentStudy(aStudy)
126             myViewManager = theVisu.GetViewManager()
127             if myViewManager is None : raise RuntimeError, "Error - theVisu.GetViewManager"
128             myView = myViewManager.Create3DView()
129             if myView is None : raise RuntimeError, "Error - myViewManager.Create3DView"
130             myView.Maximize()
131             print "OK"
132
133             return [aStudy, myViewManager, myView]
134     raise RuntimeError, "Error: There is no shuch file."
135
136 def getMedSObject(theStudy = myLocalStudy ):
137     if theStudy is None:
138         theStudy = myLocalStudy
139     aSO = theStudy.FindObject("Med")
140     anIsPresetn, aSObject = aSO.FindSubObject(1)
141     return aSObject
142
143 def getMedObjectFromStudy(theStudy = myLocalStudy):
144     aSObject = getMedSObject(theStudy)
145     if aSObject:
146         anAttr = aSObject.FindAttribute("AttributeIOR")[1]
147         anObj = myORB.string_to_object(anAttr.Value())
148         return  anObj._narrow(SALOME_MED.MED)
149     return None
150
151 def getFieldObjectFromStudy(number, subnumber, theStudy = myLocalStudy):
152     if theStudy is None:
153         theStudy = myLocalStudy
154     mySO = theStudy.FindObject("MEDFIELD")
155     if mySO is None:
156         raise Runtime, "getFieldObjectFromStudy mySO is None"
157     mysub = mySO.FindSubObject(number)[1]
158     if mysub:
159         mysubsub = mysub.FindSubObject(subnumber)[1]
160         if mysubsub:
161             Builder = theStudy.NewBuilder()
162             anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
163             obj = myORB.string_to_object(anAttr.Value())
164             myObj = obj._narrow(SALOME_MED.FIELDINT)
165             if (myObj == None):
166                 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
167             return myObj
168     else:
169         print "ERROR: No Field Object stored in this Study"
170         return None
171
172 def SObjectToObject(theSObject) :
173      #    global myORB
174     if theSObject is None :
175         print "SObjectToObject : argument is None"
176     anObj = None                         
177     res,Attr = theSObject.FindAttribute("AttributeIOR")
178     if (res != 0) and (Attr is not None)  : 
179       anIOR  = Attr._narrow(SALOMEDS.AttributeIOR);
180       aValue = anIOR.Value();
181       if(len(aValue) != 0) :
182         anObj = myORB.string_to_object(aValue);
183       else:
184         print "SObjectToObject - IOR = ''"
185     return anObj;
186  
187 def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt) :
188 #    try:
189         global myLifeCycleCORBA
190         print "lcc.FindOrLoadComponent...",
191         aMedComp = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "MED")
192         if aMedComp is None : print "Error"
193         else : print "OK"
194         
195         aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
196
197         print "aMedComp.readStructFileWithFieldType...",
198         aMedComp.readStructFileWithFieldType(theFileName,myLocalStudy._get_Name())
199         aMedSObj = getMedSObject(myLocalStudy)
200         if aMedSObj is None : raise RuntimeError, "Error"
201         else : print "OK"
202         
203         print "theVisu.ImportMed...",
204         aResult = theVisu.ImportMed(aMedSObj)
205         if aResult is None : raise RuntimeError, "Error"
206         else : print "OK"
207         aVISUObjList.append(aResult)
208         aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
209         
210         aFolderIter = myLocalStudy.NewChildIterator(aMedSObj.GetFather());
211         while aFolderIter.More() :
212             aFolderSObj = aFolderIter.Value()
213             aFolderIter.Next()
214             anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
215             anAttr = anAttr._narrow(SALOMEDS.AttributeName);
216             aFolderName = anAttr.Value()
217             print "  ", aFolderName
218             
219             if aFolderName == 'MEDMESH' :
220                 aMeshIter = myLocalStudy.NewChildIterator(aFolderSObj);
221                 while aMeshIter.More() :
222                     aMeshSObj = aMeshIter.Value()
223                     aMeshIter.Next()
224                     anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
225                     anAttr = anAttr._narrow(SALOMEDS.AttributeName);
226                     aMeshName = anAttr.Value()
227                     print "    ", aMeshName
228                 
229                     aSupportIter = myLocalStudy.NewChildIterator(aMeshSObj);
230                     while aSupportIter.More() :
231                         aSupportSObj = aSupportIter.Value()
232                         aSupportIter.Next()
233                         anAttr = aSupportSObj.FindAttribute("AttributeName")[1]
234                         anAttr = anAttr._narrow(SALOMEDS.AttributeName);
235                         aSupportName = anAttr.Value()
236                         print "      ", aSupportName
237
238             if aFolderName == 'MEDFIELD' :
239                 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
240                 while aFieldIter.More() :
241                     aFieldSObj = aFieldIter.Value()
242                     aFieldIter.Next()
243                     anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
244                     anAttr = anAttr._narrow(SALOMEDS.AttributeName);
245                     aFieldName = anAttr.Value()
246                     print "    ", aFieldName
247                 
248                     print "theVisu.ImportMed...",
249                     aResult = theVisu.ImportMed(aFieldSObj)
250                     if aResult is None : raise RuntimeError, "Error"
251                     else : print "OK"
252                     aVISUObjList.append(aResult)
253                     aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
254
255                     aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
256                     if aTimeStampIter.More() :
257                         aTimeStampIter.Next()
258                         while aTimeStampIter.More() :
259                             aTimeStampSObj = aTimeStampIter.Value()
260                             aTimeStampIter.Next()
261                             anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
262                             anAttr = anAttr._narrow(SALOMEDS.AttributeName);
263                             aTimeStampName = anAttr.Value()
264                             print "        ", aTimeStampName
265
266                             print "theVisu.ImportMed...",
267                             aMedField = SObjectToObject(aTimeStampSObj)
268                             aResult = theVisu.ImportMedField(aMedField)
269                             if aResult is None : raise RuntimeError, "Error"
270                             else : print "OK"
271                             aVISUObjList.append(aResult)
272                             aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
273                     
274         return aVISUObjList
275     
276 #    except Exception, e:
277 #        print str(e)
278         
279 def CreatePrsForFile(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt) :
280  #   try:
281         aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
282
283         print "theVisu.ImportMed...",
284         aResult = theVisu.ImportFile(theFileName)
285         if aResult is None : raise RuntimeError, "Error"
286         else : print "OK"
287         
288         aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt))
289         
290         return aVISUObjList
291     
292 #    except Exception, e:
293 #        print str(e)
294                 
295 def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDir, thePictureExt) :
296     aVISUObjList = []
297     print "CreatePrsForResult - myLocalStudy.FindObjectIOR...",
298     myLocalStudy = theVisu.GetCurrentStudy()
299     aSObj = myLocalStudy.FindObjectIOR(theResult.GetID())
300     if aSObj is None : raise RuntimeError, "Error"
301     else : print "OK"
302     aMeshIter = myLocalStudy.NewChildIterator(aSObj);
303     while aMeshIter.More() :
304         aMeshSObj = aMeshIter.Value()
305         aMeshIter.Next()
306         anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
307         if anAttr is None :
308             aMeshSObj = aMeshIter.Value()
309             aMeshIter.Next()
310             anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
311         anAttr = anAttr._narrow(SALOMEDS.AttributeName);
312         aMeshName = anAttr.Value()
313         aMeshNamePic = re.sub(".","_",aMeshName)
314         print "  ", aMeshName
315         
316         aFolderIter = myLocalStudy.NewChildIterator(aMeshSObj);
317         while aFolderIter.More() :
318             aFolderSObj = aFolderIter.Value()
319             aFolderIter.Next()
320             anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
321             anAttr = anAttr._narrow(SALOMEDS.AttributeName);
322             aFolderName = anAttr.Value()
323             print "    ", aFolderName
324             
325             if aFolderName == 'Families' :
326                 anEntityIter = myLocalStudy.NewChildIterator(aFolderSObj);
327                 while anEntityIter.More() :
328                     anEntitySObj = anEntityIter.Value()
329                     anEntityIter.Next()
330                     anAttr = anEntitySObj.FindAttribute("AttributeName")[1]
331                     anAttr = anAttr._narrow(SALOMEDS.AttributeName);
332                     anEntityName = anAttr.Value()
333                     
334                     anEntityId = "3"
335                     if anEntityName == 'onNodes' :
336                         anEntity = VISU.NODE
337                         anEntityId = "0"
338                     if anEntityName == 'onEdges' :
339                         anEntity = VISU.EDGE
340                         anEntityId = "1"
341                     if anEntityName == 'onFaces' :
342                         anEntity = VISU.FACE
343                         anEntityId = "2"
344                     if anEntityName == 'onCells' :
345                         anEntity = VISU.CELL
346                         anEntityId = "3"
347
348                     if HasValue(thePrsTypeList,VISU.TMESH) :
349                         print "      ", anEntityName, aMeshName,
350                         aMesh = theVisu.MeshOnEntity(theResult,aMeshName,anEntity)
351                         if aMesh is None : print "Error"
352                         else :
353                             print ",OK"
354                             theView.DisplayOnly(aMesh)
355                             theView.FitAll()
356                             aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "." + thePictureExt
357                             aPictureName = re.sub("\s+","_", aPictureName);
358                             theView.SavePicture(aPictureName)
359                             aVISUObjList.append(aMesh)
360                         
361                         anFamilyIter = myLocalStudy.NewChildIterator(anEntitySObj);
362                         while anFamilyIter.More() :
363                             aFamilySObj = anFamilyIter.Value()
364                             anFamilyIter.Next()
365                             anAttr = aFamilySObj.FindAttribute("AttributeName")[1]
366                             anAttr = anAttr._narrow(SALOMEDS.AttributeName);
367                             anFamilyName = anAttr.Value()
368                             if HasValue(thePrsTypeList,VISU.TMESH) :
369                                 print "        ", anFamilyName,
370                                 aMesh = theVisu.FamilyMeshOnEntity(theResult,aMeshName,anEntity,anFamilyName)
371                                 if aMesh is None : print "Error"
372                                 else :
373                                     print ",OK"
374                                     theView.DisplayOnly(aMesh)
375                                     theView.FitAll()
376                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + anFamilyName + "." + thePictureExt
377                                     aPictureName = re.sub("\s+","_", aPictureName);
378                                     theView.SavePicture(aPictureName)
379                                     aVISUObjList.append(aMesh)
380                                 
381             if aFolderName == 'Groups' :
382                 aGroupIter = myLocalStudy.NewChildIterator(aFolderSObj);
383                 while aGroupIter.More() :
384                     aGroupSObj = aGroupIter.Value()
385                     aGroupIter.Next()
386                     anAttr = aGroupSObj.FindAttribute("AttributeName")[1]
387                     anAttr = anAttr._narrow(SALOMEDS.AttributeName);
388                     aGroupName = anAttr.Value()
389                     if HasValue(thePrsTypeList,VISU.TMESH) :
390                         print "      ", aGroupName,
391                         aMesh = theVisu.GroupMesh(theResult,aMeshName,aGroupName)
392                         if aMesh is None : print "Error"
393                         else :
394                             print ",OK"
395                             theView.DisplayOnly(aMesh)
396                             theView.FitAll()
397                             aPictureName = thePictureDir + aMeshNamePic + "_" + aGroupName + "." + thePictureExt
398                             aPictureName = re.sub("\s+","_", aPictureName);
399                             theView.SavePicture(aPictureName)
400                             aVISUObjList.append(aMesh)
401                         
402             if aFolderName == 'Fields' :
403                 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
404                 while aFieldIter.More() :
405                     aFieldSObj = aFieldIter.Value()
406                     aFieldIter.Next()
407                     anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
408                     anAttr = anAttr._narrow(SALOMEDS.AttributeName);
409                     aFieldName = anAttr.Value()
410                     print "      ", aFieldName
411                     
412                     anAttr = aFieldSObj.FindAttribute("AttributeComment")[1]
413                     anAttr = anAttr._narrow(SALOMEDS.AttributeComment);
414                     aFieldComment = anAttr.Value()
415                     aMap = StrToMap(aFieldComment)
416                     
417                     aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
418                     if aTimeStampIter.More() :
419                         aTimeStampIter.Next()
420                         while aTimeStampIter.More() :
421                             aTimeStampSObj = aTimeStampIter.Value()
422                             aTimeStampIter.Next()
423                             anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
424                             anAttr = anAttr._narrow(SALOMEDS.AttributeName);
425                             aTimeStampName = anAttr.Value()
426                             print "        ", aTimeStampName
427                             
428                             anAttr = aTimeStampSObj.FindAttribute("AttributeComment")[1]
429                             anAttr = anAttr._narrow(SALOMEDS.AttributeComment);
430                             aTimeStampComment = anAttr.Value()
431                             aMap = StrToMap(aTimeStampComment)
432                             aMeshName = aMap["myMeshName"]
433                             aFieldName = aMap["myFieldName"]
434                             aTimeStampId = atoi(aMap["myTimeStampId"])
435                             anEntity = IntToEntity(aMap["myEntityId"])
436                             anEntityId = str(aMap["myEntityId"]);
437                             #print aMeshName, aFieldName, anEntity, aTimeStampId
438                             if HasValue(thePrsTypeList,VISU.TSCALARMAP) :
439                                 print "          Creating ScalarMapOnField",
440                                 aPrsObj = theVisu.ScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
441                                 if aPrsObj is None : print "Error"
442                                 else :
443                                     print ",OK"
444                                     theView.DisplayOnly(aPrsObj)
445                                     theView.FitAll()
446                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAP." + thePictureExt
447                                     aPictureName = re.sub("\s+","_", aPictureName);
448                                     theView.SavePicture(aPictureName)
449                                     aVISUObjList.append(aPrsObj)
450                                 
451                             if HasValue(thePrsTypeList,VISU.TISOSURFACE) :
452                                 print "          Creating IsoSurfacesOnField",
453                                 aPrsObj = theVisu.IsoSurfacesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
454                                 if aPrsObj is None : print "Error"
455                                 else :
456                                     print ",OK"
457                                     theView.DisplayOnly(aPrsObj)
458                                     theView.FitAll()
459                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TISOSURFACE." + thePictureExt
460                                     aPictureName = re.sub("\s+","_", aPictureName);
461                                     theView.SavePicture(aPictureName)
462                                     aVISUObjList.append(aPrsObj)
463                                 
464                             if HasValue(thePrsTypeList,VISU.TCUTPLANES) :
465                                 print "          Creating CutPlanesOnField",
466                                 aPrsObj = theVisu.CutPlanesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
467                                 if aPrsObj is None : print "Error"
468                                 else :
469                                     print ",OK"
470                                     aPrsObj.SetOrientation(VISU.CutPlanes.ZX,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
471                                     theView.DisplayOnly(aPrsObj)
472                                     theView.FitAll()
473                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTPLANES." + thePictureExt
474                                     aPictureName = re.sub("\s+","_", aPictureName)
475                                     theView.SavePicture(aPictureName)
476                                     aVISUObjList.append(aPrsObj)
477                                 
478                             if HasValue(thePrsTypeList,VISU.TCUTLINES) :
479                                 print "          Creating CutLinesOnField",
480                                 aPrsObj = theVisu.CutLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
481                                 if aPrsObj is None : print "Error"
482                                 else :
483                                     print ",OK"
484                                     aPrsObj.SetOrientation(VISU.CutPlanes.XY,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
485                                     aPrsObj.SetOrientation2(VISU.CutPlanes.ZX,aPrsObj.GetRotateX2(),aPrsObj.GetRotateY2())
486                                     theView.DisplayOnly(aPrsObj)
487                                     theView.FitAll()
488                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTLINES." + thePictureExt
489                                     aPictureName = re.sub("\s+","_", aPictureName)
490                                     theView.SavePicture(aPictureName)
491                                     aVISUObjList.append(aPrsObj)
492                                 
493                             if HasValue(thePrsTypeList,VISU.TPLOT3D) :
494                                 print "          Creating Plot3DOnField",
495                                 aPrsObj = theVisu.Plot3DOnField(theResult,aMeshName,anEntity,
496                                                                 aFieldName,aTimeStampId)
497                                 if aPrsObj is None : print "Error"
498                                 else :
499                                     print ",OK"
500                                 #aPrsObj.SetOrientation(VISU.CutPlanes.ZX,
501                                 #                       aPrsObj.GetRotateX(),
502                                 #                       aPrsObj.GetRotateY())
503                                     theView.DisplayOnly(aPrsObj)
504                                     theView.FitAll()
505                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TPLOT3D." + thePictureExt
506                                     aPictureName = re.sub("\s+","_", aPictureName)
507                                     theView.SavePicture(aPictureName)
508                                     aVISUObjList.append(aPrsObj)
509                                 
510                             aNumComponent = atoi(aMap["myNumComponent"])
511                             if aNumComponent > 1 :
512                                 if HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPE) :
513                                     print "          Creating DeformedShapeOnField",
514                                     aPrsObj = theVisu.DeformedShapeOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
515                                     if aPrsObj is None : print "Error"
516                                     else :
517                                         print ",OK"
518                                         theView.DisplayOnly(aPrsObj)
519                                         theView.FitAll()
520                                         aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPE." + thePictureExt
521                                         aPictureName = re.sub("\s+","_", aPictureName)
522                                         theView.SavePicture(aPictureName)
523                                         aVISUObjList.append(aPrsObj)
524
525                                 if HasValue(thePrsTypeList,VISU.TVECTORS) :
526                                     print "          Creating VectorsOnField",
527                                     aPrsObj = theVisu.VectorsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
528                                     if aPrsObj is None : print "Error"
529                                     else :
530                                         print ",OK"
531                                         theView.DisplayOnly(aPrsObj)
532                                         theView.FitAll()
533                                         aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TVECTORS." + thePictureExt
534                                         aPictureName = re.sub("\s+","_", aPictureName)
535                                         theView.SavePicture(aPictureName)
536                                         aVISUObjList.append(aPrsObj)
537                                     
538                                 if HasValue(thePrsTypeList,VISU.TSTREAMLINES) :
539                                     print "          Creating StreamLinesOnField",
540                                     aPrsObj = theVisu.StreamLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
541                                     if aPrsObj is None : print "Error"
542                                     else :
543                                         print ",OK"
544                                         theView.DisplayOnly(aPrsObj)
545                                         theView.FitAll()
546                                         aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSTREAMLINES." + thePictureExt
547                                         aPictureName = re.sub("\s+","_", aPictureName)
548                                         theView.SavePicture(aPictureName)
549                                         aVISUObjList.append(aPrsObj)
550                     
551     return aVISUObjList
552
553
554 def generateName(prefix = None):
555     import whrandom;
556     int = whrandom.randint(1,1000);
557     if prefix is None:
558         return "Study" + str(int)
559     else :
560         return prefix + str(int)
561     
562
563
564 # ----------------------
565 # MESH
566 # ----------------------
567 def try_mesh_parameters(theMeshPattern):
568     aResult = []
569     if theMeshPattern is None : return aResult ;
570     theMeshPattern =  theMeshPattern._narrow(VISU.Mesh)
571     if theMeshPattern is None : return aResult ;
572
573     aTYPES = [VISU.POINT, VISU.WIREFRAME, VISU.SHADED, VISU.INSIDEFRAME, VISU.SHRINK]
574     import copy; import os;
575     for ind in aTYPES:
576         aNewMesh = copy.deepcopy(theMeshPattern);
577         aNewMesh.SetPresentationType(ind)
578         aResult.append(aNewMesh)
579
580     return aResult
581
582
583 # ----------------------------    
584 # SCALAR MAP 
585 # ----------------------------    
586 ind=1  #try safe way
587 def try_scalarmap_parameters(thePattern, dump = 0):
588
589     if thePattern  is None : return None 
590
591     SCALING = [VISU.LINEAR, VISU.LOGARITHMIC]
592     import copy
593     import random
594
595     anObj = thePattern#copy.deepcopy(thePattern);
596     #ind = random.randint(1,2)
597     if ind%2 :
598             #try incorrect value deliberately (but allowed by idl description)
599             #try SetScalarMode(long)
600             mode = random.randint(-100000,100000); #incorrect value deliberately
601     else:
602             #correct value of ScalarMode
603             mode = random.randint(0, 3)
604
605     if dump : print "\tSetScalarMode(" + str(mode) +")"
606     anObj.SetScalarMode(mode)
607
608     # --- SCALING ---
609     scal = random.randint(0,1)
610     if dump : print "\tSetScaling(" + str(SCALING[scal]) +")"
611     anObj.SetScaling(SCALING[scal])
612         
613     # --- BOUNDARIES ---
614     if ind%2 :
615             alfa =  random.random()*random.randint(-100000,100000)
616             betta = random.random()*random.randint(-100000,100000)
617             aMin = alfa; aMax = betta
618     else:
619             #more correct set
620             aPMin = thePattern.GetMin()
621             aPMax = thePattern.GetMax()
622             aLen = aPMax - aPMin
623             alfa =  random.random()%0.5
624             betta = random.random()%0.5
625             aMin = alfa*aLen*random.randint(-1,1) + aPMin
626             aMax = betta*aLen*random.randint(-1,1) + aPMax
627     if dump : print "\tSetRange(" + str(aMin) + ", " + str(aMax) + ")"
628     anObj.SetRange(aMin, aMax)
629
630         # --- POSITION ---
631     if ind%2:
632             X=random.random()*random.randint(-100000,100000)
633             Y=random.random()*random.randint(-100000,100000)
634     else :
635              X=random.random()
636              Y=random.random()
637     if dump : print "SetPosition("+ str(X) + ", " + str(Y) + " )"
638     anObj.SetPosition(X, Y)
639
640         # --- SCALAR BAR SIZE ---
641     if ind%2:
642             aWidth=random.random()*random.randint(-100000,100000)
643             aHeight=random.random()*random.randint(-100000,100000)
644     else :
645              aWidth=random.random()
646              aHeight=random.random()
647     if dump : print " SCALAR BAR Width = " + str(aWidth) + " Height = ", str(aHeight)
648     anObj.SetSize(aWidth, aHeight)
649     
650     return anObj
651
652
653 def dump_scalarmap_parameters(anObj):
654     
655     print "\tGetScalarMode() = " + str(anObj.GetScalarMode()) 
656     print "\tGetScaling() = " + str(anObj.GetScaling()) 
657     print "\tGetMin() = " + str(anObj.GetMin()) + "  GetMax() = " + str (anObj.GetMax())
658     print "\tGetOrientation() = " + str(anObj.GetOrientation())
659     print "\tGetPosX() = ", str(anObj.GetPosX()) + "  GetPosY() = ", str(anObj.GetPosY())
660     print "\tGetWidth() = ", str ( anObj.GetWidth()) + "  GetHeight() = " + str(anObj.GetHeight())
661
662 # ----------------------
663 # DEFORMED SHAPE
664 # ----------------------
665 def try_deformedshape_parameters(thePattern) :
666
667     if thePattern  is None : return None 
668     import copy
669     import random
670
671     anObj = try_scalarmap_parameters(thePattern)
672
673     # --- SCALING ---
674     if ind%2:
675         anObj.SetScale( random.random()*random.randint(-100000, 100000))
676     else :
677         anObj.SetScale( anObj.GetScale()*random.random())
678
679     return anObj
680
681
682 def dump_deformedshape_parameters(theObject):
683     dump_scalarmap_parameters(theObject)
684     print "GetScale() = ", theObject.GetScale()
685     
686 # ----------------------
687 # CUT PLANES
688 # ----------------------
689 def try_cutplanes_parameters(thePattern) :
690
691     if thePattern  is None : return aList 
692     import copy
693     import random
694
695     ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
696
697     ind = random.randint(1,2)
698     anObj = try_scalarmap_parameters(thePattern)
699         
700     if ind%2 :   anObj.SetNbPlanes(random.randint(-40,40))
701     else :       anObj.SetNbPlanes(random.randint(0,10)) #try behaivor if NbPlanes=0
702
703     # --- DISPLACEMENT ---
704     anObj.SetDisplacement(random.randint(-100000,100000))
705
706     # --- PLANE POSITION ---
707     if ind%2:
708         PlaneNb = random.randint(-100000,100000) #incorrect value is possible
709     else    : PlaneNb = random.randint(0, anObj.GetNbPlanes())
710         
711     anObj.SetPlanePosition(PlaneNb, random.random()*random.randint(-100000,100000))
712
713     # --- SET DEFAULT ---
714     anObj.SetDefault(PlaneNb)
715
716     # --- SET X,Y,Z ROTATION ---
717     if ind%2 :
718             angle1 = random.random()*random.randint(-100000,100000)
719             angle2 = random.random()*random.randint(-100000,100000)
720     else :
721             angle1 = random.random()*3.14
722             angle2 = random.random()*3.14
723         
724     # --- ORIENTATION ---
725     anObj.SetOrientation(ORIENT[random.randint(0,2)],angle1,angle2)
726
727     return anObj
728         
729 def dump_cutplanes_parameters(theObject):
730         dump_saclarmap_parameters(theObject)
731
732         print "GetOrientationType = " + str(theObject.GetOrientationType())
733         PlanesNb = theObject.GetNbPlanes()
734         print "GetNbPlanes() = ", str(PlanesNb)
735         for i in range(0,PlanesNb+1):
736             if theObject.IsDefault(i) :
737                 print "Default plane : "+str(i); break
738         print "GetPlanePosition(" + str(i) + ") = ", theObject.GetPlanePosition(i)
739         print "GetDisplacement() = ", str(theObject.GetDisplacement())
740         print "GetRotateX() = ", str(theObject.GetRotateX())
741         print "GetRotateY() = ", str(theObject.GetRotateY())
742         print "GetRotateZ() = ", str(theObject.GetRotateZ())
743
744 # ----------------------
745 # CUT LINES
746 # ----------------------
747 def try_cutlines_parameters(thePattern):
748
749     if thePattern  is None : return None 
750     import copy
751     import random
752
753     ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
754     ind = random.randint(1,2)
755     anObj = try_scalarmap_parameters(thePattern)
756
757     # --- ORIENTATION ---
758     anObj.SetOrientation(ORIENT[random.randint(0,2)],
759                          random.randint(-100,100)*random.random(),
760                          random.randint(-100,100)*random.random())
761     anObj.SetOrientation2(ORIENT[random.randint(0,2)],
762                           random.randint(-100,100)*random.random(),
763                           random.randint(-100,100)*random.random())
764
765     # --- Base Plane Position ---
766     anObj.SetBasePlanePosition( random.random()*random.randint(-100000,100000))
767
768     # --- NUMBER OF LINES ---
769     if ind%2:
770             anObj.SetNbLines(random.randint(-5, 50))
771
772     return anObj
773
774 def dump_cutlines_parameters(theObject):
775     dump_scalarmap_parameters(theObject)
776
777     print "GetOrientationType() = " + str(theObject.GetOrientationType())
778     print "GetOrientationType2() = " + str(theObject.GetOrientationType2())
779     print "GetBasePlanePosition() = "+ str(theObject.GetBasePlanePosition())
780     print "GetNbLines() = " + str(theObject.GetNbLines())
781     print "GetRotateX() = ", str(theObject.GetRotateX())
782     print "GetRotateX2() = ", str(theObject.GetRotateX2())
783     print "GetRotateY() = ", str(theObject.GetRotateY())
784     print "GetRotateY2() = ", str(theObject.GetRotateY2())
785
786 # ----------------------
787 # STREAM LINES
788 # ----------------------
789 def try_streamlines_parameters(thePattern):
790
791     if thePattern  is None : return None 
792     import copy
793     import random
794
795     DIRECTION = [VISU.StreamLines.FORWARD, VISU.StreamLines.BACKWARD, VISU.StreamLines.BOTH]
796
797     ind = random.randint(1,2)
798     anObj = (try_deformedshape_parameters(thePattern))[0]
799
800     # --- DIREACTION ---
801     anObj.SetDirection(DIRECTION[random.randint(0,2)])
802
803     # --- STEP LENGTH ---
804     if ind%2 : anObj.SetStepLength(random.random()*random.randint(-1000,1000))
805     else :
806             aLen = anObj.GetMax() - anObj.GetMin()
807             anObj.SetStepLength(aLen/random.randint(1,100))
808             
809     # --- PROPAGATION TIME ---
810     anObj.SetPropagationTime(random.random()*random.randint(1,100))
811
812     # --- INTEGRATION STEP ---
813     if ind%2 :
814             anObj.SetIntegrationStep(random.random()*random.randint(-1000,1000))
815     else:
816             anObj.SetIntegrationStep(random.random())
817
818     # --- USED POINT ---
819     anObj.SetUsedPoints(random.random()*random.randint(-10000,10000))
820
821     return anObj
822         
823 def dump_streamlines_parameters(theObject):
824     
825     dump_deformedshape_parameters(theObject)
826     
827     print "GetDirection() = "      + str(theObject.GetDirection())
828     print "GetStepLength() = "     + str(theObject.GetStepLength())
829     print "GetPropagationTime() =" + str(theObject.GetPropagationTime())
830     print "GetIntegrationStep() =" + str(theObject.GetIntegrationStep())
831     print "GetUsedPoints()      =" + str(theObject.GetUsedPoints())
832     
833 # ----------------------
834 # VECTORS     
835 # ----------------------
836 def try_vectors_parameters(thePattern, theNum):
837
838     if thePattern  is None : return None 
839     import copy
840     import random
841     GLIPH_TYPE = [VISU.Vectors.ARROW, VISU.Vectors.CONE2, VISU.Vectors.CONE6, VISU.Vectors.NONE]
842     GLIPH_POS = [VISU.Vectors.CENTER, VISU.Vectors.TAIL, VISU.Vectors.HEAD]
843     ind = random.randint(1,2)
844     anObj = (try_deformedshape_parameters(thePattern))[0]
845
846     # --- LINE WIDTH ---
847     if ind%2 :
848             anObj.SetLineWidth(random.random()*random.randint(-10000,10000))
849     else :
850             anObj.SetLineWidth(random.randint(1, 10))
851
852     # --- GLIPH TYPE ---
853     anObj.SetGlyphType(GLIPH_TYPE[random.randint(0, len(GLIPH_TYPE)-1)])
854         
855     # --- GLIPH POS ---
856     anObj.SetGlyphPos(GLIPH_POS[random.randint(0, len(GLIPH_POS)-1)])
857     
858     return anObj
859
860 def dump_vetctors_parameters(theObject):
861     
862     dump_deformedshape_parameters(theObject)
863     
864     print "GetLineWidth() = " +str(theObject.GetLineWidth())
865     print "GetGlyphType() = " +str(theObject.GetGlyphType())
866     print "GetGlyphPos()  = " +str(theObject.GetGlyphPos())
867
868
869 # ----------------------
870 # ISO SURFACES     
871 # ----------------------
872
873 def try_isosurfaces_parameters(thePattern) :
874     if thePattern  is None : return None 
875     import copy
876     import random
877     
878     anObj = try_scalarmap_parameters(thePattern)
879     ind = random.randint(1,2)   
880     # --- SURFACES NUMBER ---
881     if ind%2 :
882             anObj.SetNbSurfaces(random.randint(-100000,100000))
883     else:
884             anObj.SetNbSurfaces(random.randint(1, 50))
885             
886     return anObj
887
888 def dump_isosurfaces_parameters(theObject):
889     
890     dump_scalarmap_parameters(theObject)
891     print "GetNbSurfaces() = "+ str(theObject.GetNbSurfaces())
892
893
894 # ----------------------
895 # TABLES AND CURVES
896 # ----------------------
897
898 def FillTable( theTable, theValues, theRows, theColumns, theRowTitles, theRowUnits, theColumnTitles ):
899     if theTable is None: return
900     if len(theRows) != len(theColumns): return
901     if len(theRows) != len(theValues): return
902     i = 0
903     for value in theValues:
904         theTable.PutValue( value, theRows[ i ], theColumns[ i ])
905         i = i + 1
906         pass
907     i = 1
908     for title in theRowTitles:
909         theTable.SetRowTitle( i, title )
910         theTable.SetRowUnit( i, theRowUnits[ i - 1 ])
911         i = i + 1
912         pass
913     i = 1
914     for title in theColumnTitles:
915         theTable.SetColumnTitle( i, title )
916         i = i + 1
917         pass
918     pass
919
920 def CreateCurve( theTable, theHRow, theVRow, theTitle, theColor, theMarker, theLineType, theLineWidth ):
921     if theTitle is None: return
922     curve = myLocalVisu.CreateCurve( theTable, theHRow, theVRow );
923     if curve:
924         curve.SetTitle( theTitle )
925         curve.SetColor( theColor )
926         curve.SetMarker( theMarker )
927         curve.SetLine( theLineType, theLineWidth )
928         pass
929     return curve