]> SALOME platform Git repositories - modules/visu.git/blob - src/VISU_SWIG/visu.py
Salome HOME
Debug visu.py; add visu_split_views.py as example of view parameters management
[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 : print ",OK"
353                         theView.DisplayOnly(aMesh)
354                         theView.FitAll()
355                         aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "." + thePictureExt
356                         aPictureName = re.sub("\s+","_", aPictureName);
357                         theView.SavePicture(aPictureName)
358                         aVISUObjList.append(aMesh)
359                         
360                         anFamilyIter = myLocalStudy.NewChildIterator(anEntitySObj);
361                         while anFamilyIter.More() :
362                             aFamilySObj = anFamilyIter.Value()
363                             anFamilyIter.Next()
364                             anAttr = aFamilySObj.FindAttribute("AttributeName")[1]
365                             anAttr = anAttr._narrow(SALOMEDS.AttributeName);
366                             anFamilyName = anAttr.Value()
367                             if HasValue(thePrsTypeList,VISU.TMESH) :
368                                 print "        ", anFamilyName,
369                                 aMesh = theVisu.FamilyMeshOnEntity(theResult,aMeshName,anEntity,anFamilyName)
370                                 if aMesh is None : print "Error"
371                                 else : print ",OK"
372                                 theView.DisplayOnly(aMesh)
373                                 theView.FitAll()
374                                 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + anFamilyName + "." + thePictureExt
375                                 aPictureName = re.sub("\s+","_", aPictureName);
376                                 theView.SavePicture(aPictureName)
377                                 aVISUObjList.append(aMesh)
378                                 
379             if aFolderName == 'Groups' :
380                 aGroupIter = myLocalStudy.NewChildIterator(aFolderSObj);
381                 while aGroupIter.More() :
382                     aGroupSObj = aGroupIter.Value()
383                     aGroupIter.Next()
384                     anAttr = aGroupSObj.FindAttribute("AttributeName")[1]
385                     anAttr = anAttr._narrow(SALOMEDS.AttributeName);
386                     aGroupName = anAttr.Value()
387                     if HasValue(thePrsTypeList,VISU.TMESH) :
388                         print "      ", aGroupName,
389                         aMesh = theVisu.GroupMesh(theResult,aMeshName,aGroupName)
390                         if aMesh is None : print "Error"
391                         else : print ",OK"
392                         theView.DisplayOnly(aMesh)
393                         theView.FitAll()
394                         aPictureName = thePictureDir + aMeshNamePic + "_" + aGroupName + "." + thePictureExt
395                         aPictureName = re.sub("\s+","_", aPictureName);
396                         theView.SavePicture(aPictureName)
397                         aVISUObjList.append(aMesh)
398                         
399             if aFolderName == 'Fields' :
400                 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
401                 while aFieldIter.More() :
402                     aFieldSObj = aFieldIter.Value()
403                     aFieldIter.Next()
404                     anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
405                     anAttr = anAttr._narrow(SALOMEDS.AttributeName);
406                     aFieldName = anAttr.Value()
407                     print "      ", aFieldName
408                     
409                     anAttr = aFieldSObj.FindAttribute("AttributeComment")[1]
410                     anAttr = anAttr._narrow(SALOMEDS.AttributeComment);
411                     aFieldComment = anAttr.Value()
412                     aMap = StrToMap(aFieldComment)
413                     
414                     aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
415                     if aTimeStampIter.More() :
416                         aTimeStampIter.Next()
417                         while aTimeStampIter.More() :
418                             aTimeStampSObj = aTimeStampIter.Value()
419                             aTimeStampIter.Next()
420                             anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
421                             anAttr = anAttr._narrow(SALOMEDS.AttributeName);
422                             aTimeStampName = anAttr.Value()
423                             print "        ", aTimeStampName
424                             
425                             anAttr = aTimeStampSObj.FindAttribute("AttributeComment")[1]
426                             anAttr = anAttr._narrow(SALOMEDS.AttributeComment);
427                             aTimeStampComment = anAttr.Value()
428                             aMap = StrToMap(aTimeStampComment)
429                             aMeshName = aMap["myMeshName"]
430                             aFieldName = aMap["myFieldName"]
431                             aTimeStampId = atoi(aMap["myTimeStampId"])
432                             anEntity = IntToEntity(aMap["myEntityId"])
433                             anEntityId = str(aMap["myEntityId"]);
434                             #print aMeshName, aFieldName, anEntity, aTimeStampId
435                             if HasValue(thePrsTypeList,VISU.TSCALARMAP) :
436                                 print "          Creating ScalarMapOnField",
437                                 aPrsObj = theVisu.ScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
438                                 if aPrsObj is None : print "Error"
439                                 else : print ",OK"
440                                 theView.DisplayOnly(aPrsObj)
441                                 theView.FitAll()
442                                 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAP." + thePictureExt
443                                 aPictureName = re.sub("\s+","_", aPictureName);
444                                 theView.SavePicture(aPictureName)
445                                 aVISUObjList.append(aPrsObj)
446                                 
447                             if HasValue(thePrsTypeList,VISU.TISOSURFACE) :
448                                 print "          Creating IsoSurfacesOnField",
449                                 aPrsObj = theVisu.IsoSurfacesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
450                                 if aPrsObj is None : print "Error"
451                                 else : print ",OK"
452                                 theView.DisplayOnly(aPrsObj)
453                                 theView.FitAll()
454                                 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TISOSURFACE." + thePictureExt
455                                 aPictureName = re.sub("\s+","_", aPictureName);
456                                 theView.SavePicture(aPictureName)
457                                 aVISUObjList.append(aPrsObj)
458                                 
459                             if HasValue(thePrsTypeList,VISU.TCUTPLANES) :
460                                 print "          Creating CutPlanesOnField",
461                                 aPrsObj = theVisu.CutPlanesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
462                                 if aPrsObj is None : print "Error"
463                                 else : print ",OK"
464                                 aPrsObj.SetOrientation(VISU.CutPlanes.ZX,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
465                                 theView.DisplayOnly(aPrsObj)
466                                 theView.FitAll()
467                                 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTPLANES." + thePictureExt
468                                 aPictureName = re.sub("\s+","_", aPictureName)
469                                 theView.SavePicture(aPictureName)
470                                 aVISUObjList.append(aPrsObj)
471                                 
472                             if HasValue(thePrsTypeList,VISU.TCUTLINES) :
473                                 print "          Creating CutLinesOnField",
474                                 aPrsObj = theVisu.CutLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
475                                 if aPrsObj is None : print "Error"
476                                 else : print ",OK"
477                                 aPrsObj.SetOrientation(VISU.CutPlanes.XY,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
478                                 aPrsObj.SetOrientation2(VISU.CutPlanes.ZX,aPrsObj.GetRotateX2(),aPrsObj.GetRotateY2())
479                                 theView.DisplayOnly(aPrsObj)
480                                 theView.FitAll()
481                                 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTLINES." + thePictureExt
482                                 aPictureName = re.sub("\s+","_", aPictureName)
483                                 theView.SavePicture(aPictureName)
484                                 aVISUObjList.append(aPrsObj)
485                                 
486                             if HasValue(thePrsTypeList,VISU.TPLOT3D) :
487                                 print "          Creating Plot3DOnField",
488                                 aPrsObj = theVisu.Plot3DOnField(theResult,aMeshName,anEntity,
489                                                                 aFieldName,aTimeStampId)
490                                 if aPrsObj is None : print "Error"
491                                 else : print ",OK"
492                                 #aPrsObj.SetOrientation(VISU.CutPlanes.ZX,
493                                 #                       aPrsObj.GetRotateX(),
494                                 #                       aPrsObj.GetRotateY())
495                                 theView.DisplayOnly(aPrsObj)
496                                 theView.FitAll()
497                                 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TPLOT3D." + thePictureExt
498                                 aPictureName = re.sub("\s+","_", aPictureName)
499                                 theView.SavePicture(aPictureName)
500                                 aVISUObjList.append(aPrsObj)
501                                 
502                             aNumComponent = atoi(aMap["myNumComponent"])
503                             if aNumComponent > 1 :
504                                 if HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPE) :
505                                     print "          Creating DeformedShapeOnField",
506                                     aPrsObj = theVisu.DeformedShapeOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
507                                     if aPrsObj is None : print "Error"
508                                     else : print ",OK"
509                                     theView.DisplayOnly(aPrsObj)
510                                     theView.FitAll()
511                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPE." + thePictureExt
512                                     aPictureName = re.sub("\s+","_", aPictureName)
513                                     theView.SavePicture(aPictureName)
514                                     aVISUObjList.append(aPrsObj)
515
516                                 if HasValue(thePrsTypeList,VISU.TVECTORS) :
517                                     print "          Creating VectorsOnField",
518                                     aPrsObj = theVisu.VectorsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
519                                     if aPrsObj is None : print "Error"
520                                     else : print ",OK"
521                                     theView.DisplayOnly(aPrsObj)
522                                     theView.FitAll()
523                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TVECTORS." + thePictureExt
524                                     aPictureName = re.sub("\s+","_", aPictureName)
525                                     theView.SavePicture(aPictureName)
526                                     aVISUObjList.append(aPrsObj)
527                                     
528                                 if HasValue(thePrsTypeList,VISU.TSTREAMLINES) :
529                                     print "          Creating StreamLinesOnField",
530                                     aPrsObj = theVisu.StreamLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
531                                     if aPrsObj is None : print "Error"
532                                     else : print ",OK"
533                                     theView.DisplayOnly(aPrsObj)
534                                     theView.FitAll()
535                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSTREAMLINES." + thePictureExt
536                                     aPictureName = re.sub("\s+","_", aPictureName)
537                                     theView.SavePicture(aPictureName)
538                                     aVISUObjList.append(aPrsObj)
539                     
540     return aVISUObjList
541
542
543 def generateName(prefix = None):
544     import whrandom;
545     int = whrandom.randint(1,1000);
546     if prefix is None:
547         return "Study" + str(int)
548     else :
549         return prefix + str(int)
550     
551
552
553 # ----------------------
554 # MESH
555 # ----------------------
556 def try_mesh_parameters(theMeshPattern):
557     aResult = []
558     if theMeshPattern is None : return aResult ;
559     theMeshPattern =  theMeshPattern._narrow(VISU.Mesh)
560     if theMeshPattern is None : return aResult ;
561
562     aTYPES = [VISU.POINT, VISU.WIREFRAME, VISU.SHADED, VISU.INSIDEFRAME, VISU.SHRINK]
563     import copy; import os;
564     for ind in aTYPES:
565         aNewMesh = copy.deepcopy(theMeshPattern);
566         aNewMesh.SetPresentationType(ind)
567         aResult.append(aNewMesh)
568
569     return aResult
570
571
572 # ----------------------------    
573 # SCALAR MAP 
574 # ----------------------------    
575 ind=1  #try safe way
576 def try_scalarmap_parameters(thePattern, dump = 0):
577
578     if thePattern  is None : return None 
579
580     SCALING = [VISU.LINEAR, VISU.LOGARITHMIC]
581     import copy
582     import random
583
584     anObj = thePattern#copy.deepcopy(thePattern);
585     #ind = random.randint(1,2)
586     if ind%2 :
587             #try incorrect value deliberately (but allowed by idl description)
588             #try SetScalarMode(long)
589             mode = random.randint(-100000,100000); #incorrect value deliberately
590     else:
591             #correct value of ScalarMode
592             mode = random.randint(0, 3)
593
594     if dump : print "\tSetScalarMode(" + str(mode) +")"
595     anObj.SetScalarMode(mode)
596
597     # --- SCALING ---
598     scal = random.randint(0,1)
599     if dump : print "\tSetScaling(" + str(SCALING[scal]) +")"
600     anObj.SetScaling(SCALING[scal])
601         
602     # --- BOUNDARIES ---
603     if ind%2 :
604             alfa =  random.random()*random.randint(-100000,100000)
605             betta = random.random()*random.randint(-100000,100000)
606             aMin = alfa; aMax = betta
607     else:
608             #more correct set
609             aPMin = thePattern.GetMin()
610             aPMax = thePattern.GetMax()
611             aLen = aPMax - aPMin
612             alfa =  random.random()%0.5
613             betta = random.random()%0.5
614             aMin = alfa*aLen*random.randint(-1,1) + aPMin
615             aMax = betta*aLen*random.randint(-1,1) + aPMax
616     if dump : print "\tSetRange(" + str(aMin) + ", " + str(aMax) + ")"
617     anObj.SetRange(aMin, aMax)
618
619         # --- POSITION ---
620     if ind%2:
621             X=random.random()*random.randint(-100000,100000)
622             Y=random.random()*random.randint(-100000,100000)
623     else :
624              X=random.random()
625              Y=random.random()
626     if dump : print "SetPosition("+ str(X) + ", " + str(Y) + " )"
627     anObj.SetPosition(X, Y)
628
629         # --- SCALAR BAR SIZE ---
630     if ind%2:
631             aWidth=random.random()*random.randint(-100000,100000)
632             aHeight=random.random()*random.randint(-100000,100000)
633     else :
634              aWidth=random.random()
635              aHeight=random.random()
636     if dump : print " SCALAR BAR Width = " + str(aWidth) + " Height = ", str(aHeight)
637     anObj.SetSize(aWidth, aHeight)
638     
639     return anObj
640
641
642 def dump_scalarmap_parameters(anObj):
643     
644     print "\tGetScalarMode() = " + str(anObj.GetScalarMode()) 
645     print "\tGetScaling() = " + str(anObj.GetScaling()) 
646     print "\tGetMin() = " + str(anObj.GetMin()) + "  GetMax() = " + str (anObj.GetMax())
647     print "\tGetOrientation() = " + str(anObj.GetOrientation())
648     print "\tGetPosX() = ", str(anObj.GetPosX()) + "  GetPosY() = ", str(anObj.GetPosY())
649     print "\tGetWidth() = ", str ( anObj.GetWidth()) + "  GetHeight() = " + str(anObj.GetHeight())
650
651 # ----------------------
652 # DEFORMED SHAPE
653 # ----------------------
654 def try_deformedshape_parameters(thePattern) :
655
656     if thePattern  is None : return None 
657     import copy
658     import random
659
660     anObj = try_scalarmap_parameters(thePattern)
661
662     # --- SCALING ---
663     if ind%2:
664         anObj.SetScale( random.random()*random.randint(-100000, 100000))
665     else :
666         anObj.SetScale( anObj.GetScale()*random.random())
667
668     return anObj
669
670
671 def dump_deformedshape_parameters(theObject):
672     dump_scalarmap_parameters(theObject)
673     print "GetScale() = ", theObject.GetScale()
674     
675 # ----------------------
676 # CUT PLANES
677 # ----------------------
678 def try_cutplanes_parameters(thePattern) :
679
680     if thePattern  is None : return aList 
681     import copy
682     import random
683
684     ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
685
686     ind = random.randint(1,2)
687     anObj = try_scalarmap_parameters(thePattern)
688         
689     if ind%2 :   anObj.SetNbPlanes(random.randint(-40,40))
690     else :       anObj.SetNbPlanes(random.randint(0,10)) #try behaivor if NbPlanes=0
691
692     # --- DISPLACEMENT ---
693     anObj.SetDisplacement(random.randint(-100000,100000))
694
695     # --- PLANE POSITION ---
696     if ind%2:
697         PlaneNb = random.randint(-100000,100000) #incorrect value is possible
698     else    : PlaneNb = random.randint(0, anObj.GetNbPlanes())
699         
700     anObj.SetPlanePosition(PlaneNb, random.random()*random.randint(-100000,100000))
701
702     # --- SET DEFAULT ---
703     anObj.SetDefault(PlaneNb)
704
705     # --- SET X,Y,Z ROTATION ---
706     if ind%2 :
707             angle1 = random.random()*random.randint(-100000,100000)
708             angle2 = random.random()*random.randint(-100000,100000)
709     else :
710             angle1 = random.random()*3.14
711             angle2 = random.random()*3.14
712         
713     # --- ORIENTATION ---
714     anObj.SetOrientation(ORIENT[random.randint(0,2)],angle1,angle2)
715
716     return anObj
717         
718 def dump_cutplanes_parameters(theObject):
719         dump_saclarmap_parameters(theObject)
720
721         print "GetOrientationType = " + str(theObject.GetOrientationType())
722         PlanesNb = theObject.GetNbPlanes()
723         print "GetNbPlanes() = ", str(PlanesNb)
724         for i in range(0,PlanesNb+1):
725             if theObject.IsDefault(i) :
726                 print "Default plane : "+str(i); break
727         print "GetPlanePosition(" + str(i) + ") = ", theObject.GetPlanePosition(i)
728         print "GetDisplacement() = ", str(theObject.GetDisplacement())
729         print "GetRotateX() = ", str(theObject.GetRotateX())
730         print "GetRotateY() = ", str(theObject.GetRotateY())
731         print "GetRotateZ() = ", str(theObject.GetRotateZ())
732
733 # ----------------------
734 # CUT LINES
735 # ----------------------
736 def try_cutlines_parameters(thePattern):
737
738     if thePattern  is None : return None 
739     import copy
740     import random
741
742     ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
743     ind = random.randint(1,2)
744     anObj = try_scalarmap_parameters(thePattern)
745
746     # --- ORIENTATION ---
747     anObj.SetOrientation(ORIENT[random.randint(0,2)],
748                          random.randint(-100,100)*random.random(),
749                          random.randint(-100,100)*random.random())
750     anObj.SetOrientation2(ORIENT[random.randint(0,2)],
751                           random.randint(-100,100)*random.random(),
752                           random.randint(-100,100)*random.random())
753
754     # --- Base Plane Position ---
755     anObj.SetBasePlanePosition( random.random()*random.randint(-100000,100000))
756
757     # --- NUMBER OF LINES ---
758     if ind%2:
759             anObj.SetNbLines(random.randint(-5, 50))
760
761     return anObj
762
763 def dump_cutlines_parameters(theObject):
764     dump_scalarmap_parameters(theObject)
765
766     print "GetOrientationType() = " + str(theObject.GetOrientationType())
767     print "GetOrientationType2() = " + str(theObject.GetOrientationType2())
768     print "GetBasePlanePosition() = "+ str(theObject.GetBasePlanePosition())
769     print "GetNbLines() = " + str(theObject.GetNbLines())
770     print "GetRotateX() = ", str(theObject.GetRotateX())
771     print "GetRotateX2() = ", str(theObject.GetRotateX2())
772     print "GetRotateY() = ", str(theObject.GetRotateY())
773     print "GetRotateY2() = ", str(theObject.GetRotateY2())
774
775 # ----------------------
776 # STREAM LINES
777 # ----------------------
778 def try_streamlines_parameters(thePattern):
779
780     if thePattern  is None : return None 
781     import copy
782     import random
783
784     DIRECTION = [VISU.StreamLines.FORWARD, VISU.StreamLines.BACKWARD, VISU.StreamLines.BOTH]
785
786     ind = random.randint(1,2)
787     anObj = (try_deformedshape_parameters(thePattern))[0]
788
789     # --- DIREACTION ---
790     anObj.SetDirection(DIRECTION[random.randint(0,2)])
791
792     # --- STEP LENGTH ---
793     if ind%2 : anObj.SetStepLength(random.random()*random.randint(-1000,1000))
794     else :
795             aLen = anObj.GetMax() - anObj.GetMin()
796             anObj.SetStepLength(aLen/random.randint(1,100))
797             
798     # --- PROPAGATION TIME ---
799     anObj.SetPropagationTime(random.random()*random.randint(1,100))
800
801     # --- INTEGRATION STEP ---
802     if ind%2 :
803             anObj.SetIntegrationStep(random.random()*random.randint(-1000,1000))
804     else:
805             anObj.SetIntegrationStep(random.random())
806
807     # --- USED POINT ---
808     anObj.SetUsedPoints(random.random()*random.randint(-10000,10000))
809
810     return anObj
811         
812 def dump_streamlines_parameters(theObject):
813     
814     dump_deformedshape_parameters(theObject)
815     
816     print "GetDirection() = "      + str(theObject.GetDirection())
817     print "GetStepLength() = "     + str(theObject.GetStepLength())
818     print "GetPropagationTime() =" + str(theObject.GetPropagationTime())
819     print "GetIntegrationStep() =" + str(theObject.GetIntegrationStep())
820     print "GetUsedPoints()      =" + str(theObject.GetUsedPoints())
821     
822 # ----------------------
823 # VECTORS     
824 # ----------------------
825 def try_vectors_parameters(thePattern, theNum):
826
827     if thePattern  is None : return None 
828     import copy
829     import random
830     GLIPH_TYPE = [VISU.Vectors.ARROW, VISU.Vectors.CONE2, VISU.Vectors.CONE6, VISU.Vectors.NONE]
831     GLIPH_POS = [VISU.Vectors.CENTER, VISU.Vectors.TAIL, VISU.Vectors.HEAD]
832     ind = random.randint(1,2)
833     anObj = (try_deformedshape_parameters(thePattern))[0]
834
835     # --- LINE WIDTH ---
836     if ind%2 :
837             anObj.SetLineWidth(random.random()*random.randint(-10000,10000))
838     else :
839             anObj.SetLineWidth(random.randint(1, 10))
840
841     # --- GLIPH TYPE ---
842     anObj.SetGlyphType(GLIPH_TYPE[random.randint(0, len(GLIPH_TYPE)-1)])
843         
844     # --- GLIPH POS ---
845     anObj.SetGlyphPos(GLIPH_POS[random.randint(0, len(GLIPH_POS)-1)])
846     
847     return anObj
848
849 def dump_vetctors_parameters(theObject):
850     
851     dump_deformedshape_parameters(theObject)
852     
853     print "GetLineWidth() = " +str(theObject.GetLineWidth())
854     print "GetGlyphType() = " +str(theObject.GetGlyphType())
855     print "GetGlyphPos()  = " +str(theObject.GetGlyphPos())
856
857
858 # ----------------------
859 # ISO SURFACES     
860 # ----------------------
861
862 def try_isosurfaces_parameters(thePattern) :
863     if thePattern  is None : return None 
864     import copy
865     import random
866     
867     anObj = try_scalarmap_parameters(thePattern)
868     ind = random.randint(1,2)   
869     # --- SURFACES NUMBER ---
870     if ind%2 :
871             anObj.SetNbSurfaces(random.randint(-100000,100000))
872     else:
873             anObj.SetNbSurfaces(random.randint(1, 50))
874             
875     return anObj
876
877 def dump_isosurfaces_parameters(theObject):
878     
879     dump_scalarmap_parameters(theObject)
880     print "GetNbSurfaces() = "+ str(theObject.GetNbSurfaces())
881
882
883 # ----------------------
884 # TABLES AND CURVES
885 # ----------------------
886
887 def FillTable( theTable, theValues, theRows, theColumns, theRowTitles, theRowUnits, theColumnTitles ):
888     if theTable is None: return
889     if len(theRows) != len(theColumns): return
890     if len(theRows) != len(theValues): return
891     i = 0
892     for value in theValues:
893         theTable.PutValue( value, theRows[ i ], theColumns[ i ])
894         i = i + 1
895         pass
896     i = 1
897     for title in theRowTitles:
898         theTable.SetRowTitle( i, title )
899         theTable.SetRowUnit( i, theRowUnits[ i - 1 ])
900         i = i + 1
901         pass
902     i = 1
903     for title in theColumnTitles:
904         theTable.SetColumnTitle( i, title )
905         i = i + 1
906         pass
907     pass
908
909 def CreateCurve( theTable, theHRow, theVRow, theTitle, theColor, theMarker, theLineType, theLineWidth ):
910     if theTitle is None: return
911     curve = myLocalVisu.CreateCurve( theTable, theHRow, theVRow );
912     if curve:
913         curve.SetTitle( theTitle )
914         curve.SetColor( theColor )
915         curve.SetMarker( theMarker )
916         curve.SetLine( theLineType, theLineWidth )
917         pass
918     return curve