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