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