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