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