Salome HOME
Fix for the "0051899: curves are not shown in opened study" issue.
[modules/visu.git] / src / VISU_SWIG / visu.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23
24 #  VISU VISU_SWIG : binding of C++ implementation and Python
25 #  File   : visu.py
26 #  Module : VISU
27 #
28 import os
29 import re
30 from time import sleep
31
32 import VISU
33 import SALOME
34 import SALOME_Session_idl
35 import SALOMEDS
36 import SALOME_MED
37 import SALOME_ModuleCatalog
38 from omniORB import CORBA
39 from string import *
40 from time import sleep
41 from salome import ObjectToID
42
43 myORB = None
44 myNamingService = None
45 myLifeCycleCORBA = None
46 myNamingService = None
47 myLocalStudyManager = None
48 myLocalStudy = None
49 myLocalVisu = None
50 myDelay = None
51 mySession = None
52  
53 def Initialize(theORB, theNamingService, theLifeCycleCORBA, theStudyManager, theStudy, theDelay) :
54     global myORB, myNamingService, myLifeCycleCORBA, myLocalStudyManager, myLocalStudy
55     global mySession, myLocalVisu, myDelay
56     myDelay = theDelay
57     myORB = theORB
58     myNamingService = theNamingService
59     myLifeCycleCORBA = theLifeCycleCORBA
60     myLocalStudyManager = theStudyManager
61     while mySession == None:
62         mySession = myNamingService.Resolve("/Kernel/Session")
63     mySession = mySession._narrow(SALOME.Session)
64     mySession.GetInterface()
65     myDelay = theDelay
66     sleep(myDelay)
67     myLocalVisu = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "VISU")
68     myLocalStudy = theStudy
69     myLocalVisu.SetCurrentStudy(myLocalStudy)
70     return myLocalVisu
71
72 def PublishComponent(theStudyDocument):
73     aComponentDataType = myLocalVisu.ComponentDataType()
74     aSComponent = theStudyDocument.FindComponent(aComponentDataType)
75     if aSComponent == None:
76         aStudyBuilder = theStudyDocument.NewBuilder()
77         aStudyBuilder.NewCommand()
78         aLocked = theStudyDocument.GetProperties().IsLocked()
79         if aLocked:
80             theStudyDocument.GetProperties().SetLocked(0)
81             pass
82
83         aSComponent = aStudyBuilder.NewComponent(aComponentDataType);
84         aName = aStudyBuilder.FindOrCreateAttribute(aSComponent,"AttributeName")
85         aModuleCatalogObj = myNamingService.Resolve("/Kernel/ModulCatalog");
86         aModuleCatalog = aModuleCatalogObj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
87         aComponent = aModuleCatalog.GetComponent(aComponentDataType);
88         if aComponent != None:
89             aComponentUserName = aComponent._get_componentusername()
90             aName.SetValue(aComponentUserName)
91             pass
92         
93         aPixMap = aStudyBuilder.FindOrCreateAttribute(aSComponent,"AttributePixMap")
94         aPixMap.SetPixMap("ICON_OBJBROWSER_Visu")
95         
96         aStudyBuilder.DefineComponentInstance(aSComponent,myLocalVisu);
97         if aLocked:
98             theStudyDocument.GetProperties().SetLocked(1);
99             pass
100         
101         aStudyBuilder.CommitCommand();
102         pass
103     
104     return aSComponent;
105
106 def SetName(theObj, theName):
107     anIOR  = myORB.object_to_string(theObj)
108     aSObj  = myLocalStudy.FindObjectIOR(anIOR)
109     anAttr = aSObj.FindAttribute("AttributeName")[1]
110     anAttr.SetValue(theName)
111         
112 def StrToMap(theString) :
113     aPairList = split(theString,";")
114     aMap = {}
115     iEnd = len(aPairList)
116     for i in range(iEnd) :
117         aPair = split(aPairList[i],"=")
118         aMap[aPair[0]] = aPair[1]
119     return aMap
120
121 def IntToEntity(theInt) :
122     theInt = atoi(theInt)
123     if theInt == 0 :
124         return VISU.NODE;
125     elif theInt == 1 :
126         return VISU.EDGE;
127     elif theInt == 2 :
128         return VISU.FACE;
129     else :
130         return VISU.CELL;
131
132 def getObjectID(obj):
133    ID = ""
134    entry = ObjectToID(obj)
135    if entry is not None:
136         lst = entry.split(":")
137         if len(entry) > 6:
138                 ID = entry[6:]            
139                 return "VISU_" + ID
140         return ID
141
142         
143 def HasValue(theList, theValue) :
144     try :
145         return theList.index(theValue) + 1
146     except StandardError, e :
147         return 0
148
149 def CreateStudyForMed(theVisu, theFileName) :
150     print "CreateStudyForMed ", theFileName,
151     if os.path.isfile(theFileName) :
152         if re.search("\.med$", theFileName) is not None :
153             print "OK"
154             aStudyName = os.path.basename(theFileName)
155             aStudyName = re.sub(r'\.med', "", aStudyName)
156             aStudyName = generateName(aStudyName)
157             print "myLocalStudyManager.NewStudy -", aStudyName, "...",
158             aStudy = myLocalStudyManager.NewStudy(aStudyName)
159             if aStudy is None : raise RuntimeError, "Error"
160             else : print "OK"
161             
162             print "CreateStudyForMed - Creating a 3D viewer...",
163             theVisu.SetCurrentStudy(aStudy)
164             myViewManager = theVisu.GetViewManager()
165             if myViewManager is None : raise RuntimeError, "Error - theVisu.GetViewManager"
166             myView = myViewManager.Create3DView()
167             if myView is None : raise RuntimeError, "Error - myViewManager.Create3DView"
168             myView.Maximize()
169             print "OK"
170
171             return [aStudy, myViewManager, myView]
172     raise RuntimeError, "Error: There is no such file."
173
174 def getMedSObject(theStudy = myLocalStudy ):
175     if theStudy is None:
176         theStudy = myLocalStudy
177     aSO = theStudy.FindObject("Med")
178     anIsPresetn, aSObject = aSO.FindSubObject(1)
179     return aSObject
180
181 def getMedObjectFromStudy(theStudy = myLocalStudy):
182     aSObject = getMedSObject(theStudy)
183     if aSObject:
184         anAttr = aSObject.FindAttribute("AttributeIOR")[1]
185         anObj = myORB.string_to_object(anAttr.Value())
186         return  anObj._narrow(SALOME_MED.MED)
187     return None
188
189 def getFieldObjectFromStudy(number, subnumber, theStudy = myLocalStudy):
190     if theStudy is None:
191         theStudy = myLocalStudy
192     mySO = theStudy.FindObject("MEDFIELD")
193     if mySO is None:
194         raise Runtime, "getFieldObjectFromStudy mySO is None"
195     mysub = mySO.FindSubObject(number)[1]
196     if mysub:
197         mysubsub = mysub.FindSubObject(subnumber)[1]
198         if mysubsub:
199             Builder = theStudy.NewBuilder()
200             anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
201             obj = myORB.string_to_object(anAttr.Value())
202             myObj = obj._narrow(SALOME_MED.FIELDINT)
203             if (myObj == None):
204                 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
205             return myObj
206     else:
207         print "ERROR: No Field Object stored in this Study"
208         return None
209
210 def getSObjectByFatherPathAndName(theStudy, thePath, theName):
211     father = theStudy.FindObjectByPath(thePath)
212     itr = theStudy.NewChildIterator(father)
213     while itr.More():
214         so = itr.Value()
215         if so.GetName()==theName: return so
216         itr.Next()
217         pass
218     return None
219
220 def SObjectToObject(theSObject) :
221      #    global myORB
222     if theSObject is None :
223         print "SObjectToObject : argument is None"
224     anObj = None                         
225     res,Attr = theSObject.FindAttribute("AttributeIOR")
226     if (res != 0) and (Attr is not None)  : 
227       anIOR  = Attr._narrow(SALOMEDS.AttributeIOR);
228       aValue = anIOR.Value();
229       if(len(aValue) != 0) :
230         anObj = myORB.string_to_object(aValue);
231       else:
232         print "SObjectToObject - IOR = ''"
233     return anObj;
234  
235 def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
236 #    try:
237         global myLifeCycleCORBA
238         print "lcc.FindOrLoadComponent...",
239         aMedComp = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "MED")
240         if aMedComp is None : print "Error"
241         else : print "OK"
242         
243         aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
244
245         print "aMedComp.readStructFileWithFieldType...",
246         aMedComp.readStructFileWithFieldType(theFileName,myLocalStudy._get_Name())
247         aMedSObj = getMedSObject(myLocalStudy)
248         if aMedSObj is None : raise RuntimeError, "Error"
249         else : print "OK"
250         
251         print "theVisu.ImportMed...",
252         aResult = theVisu.ImportMed(aMedSObj)
253         if aResult is None : raise RuntimeError, "Error"
254         else : print "OK"
255
256         aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
257         if theIsAutoDelete :
258             aResult.RemoveFromStudy()
259         else :
260             aVISUObjList.append(aResult)
261         
262         aFolderIter = myLocalStudy.NewChildIterator(aMedSObj.GetFather());
263         while aFolderIter.More() :
264             aFolderSObj = aFolderIter.Value()
265             aFolderIter.Next()
266             anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
267             anAttr = anAttr._narrow(SALOMEDS.AttributeName);
268             aFolderName = anAttr.Value()
269             print "  ", aFolderName
270             
271             if aFolderName == 'MEDMESH' :
272                 aMeshIter = myLocalStudy.NewChildIterator(aFolderSObj);
273                 while aMeshIter.More() :
274                     aMeshSObj = aMeshIter.Value()
275                     aMeshIter.Next()
276                     anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
277                     anAttr = anAttr._narrow(SALOMEDS.AttributeName);
278                     aMeshName = anAttr.Value()
279                     print "    ", aMeshName
280                 
281                     aSupportIter = myLocalStudy.NewChildIterator(aMeshSObj);
282                     while aSupportIter.More() :
283                         aSupportSObj = aSupportIter.Value()
284                         aSupportIter.Next()
285                         anAttr = aSupportSObj.FindAttribute("AttributeName")[1]
286                         anAttr = anAttr._narrow(SALOMEDS.AttributeName);
287                         aSupportName = anAttr.Value()
288                         print "      ", aSupportName
289
290             if aFolderName == 'MEDFIELD' :
291                 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
292                 while aFieldIter.More() :
293                     aFieldSObj = aFieldIter.Value()
294                     aFieldIter.Next()
295                     anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
296                     anAttr = anAttr._narrow(SALOMEDS.AttributeName);
297                     aFieldName = anAttr.Value()
298                     print "    ", aFieldName
299                 
300                     print "theVisu.ImportMed...",
301                     aResult = theVisu.ImportMed(aFieldSObj)
302                     if aResult is None : raise RuntimeError, "Error"
303                     else : print "OK"
304
305                     aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
306                     if theIsAutoDelete :
307                         aResult.RemoveFromStudy()
308                     else :
309                         aVISUObjList.append(aResult)
310
311                     aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
312                     if aTimeStampIter.More() :
313                         aTimeStampIter.Next()
314                         while aTimeStampIter.More() :
315                             aTimeStampSObj = aTimeStampIter.Value()
316                             aTimeStampIter.Next()
317                             anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
318                             anAttr = anAttr._narrow(SALOMEDS.AttributeName);
319                             aTimeStampName = anAttr.Value()
320                             print "        ", aTimeStampName
321
322                             print "theVisu.ImportMed...",
323                             aMedField = SObjectToObject(aTimeStampSObj)
324                             aResult = theVisu.ImportMedField(aMedField)
325                             if aResult is None : raise RuntimeError, "Error"
326                             else : print "OK"
327
328                             aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
329                             if theIsAutoDelete :
330                                 aResult.RemoveFromStudy()
331                             else :
332                                 aVISUObjList.append(aResult)
333                     
334         return aVISUObjList
335     
336 #    except Exception, e:
337 #        print str(e)
338         
339 def CreatePrsForFile(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
340  #   try:
341         aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
342
343         print "theVisu.ImportMed...",
344         aResult = theVisu.ImportFile(theFileName)
345         if aResult is None : raise RuntimeError, "Error"
346         else : print "OK"
347         
348         aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
349
350         if theIsAutoDelete :
351             aResult.RemoveFromStudy()
352         else :
353             aVISUObjList.append(aResult)
354
355         return aVISUObjList
356     
357 #    except Exception, e:
358 #        print str(e)
359                 
360 def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
361     aVISUObjList = None
362     if theIsAutoDelete is not None :
363         aVISUObjList = []
364         pass
365         
366     print "CreatePrsForResult - myLocalStudy.FindObjectIOR...",
367     myLocalStudy = theVisu.GetCurrentStudy()
368
369     aSObj = myLocalStudy.FindObjectIOR(theResult.GetID())
370     if aSObj is None : raise RuntimeError, "Error"
371     else : print "OK"
372     aMeshIter = myLocalStudy.NewChildIterator(aSObj);
373     while aMeshIter.More() :
374         aMeshSObj = aMeshIter.Value()
375         aMeshIter.Next()
376         anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
377         if anAttr is None :
378             aMeshSObj = aMeshIter.Value()
379             aMeshIter.Next()
380             anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
381         anAttr = anAttr._narrow(SALOMEDS.AttributeName);
382         aMeshName = anAttr.Value()
383         aMeshNamePic = re.sub(".","_",aMeshName)
384         print "  ", aMeshName
385         
386         aFolderIter = myLocalStudy.NewChildIterator(aMeshSObj);
387         while aFolderIter.More() :
388             aFolderSObj = aFolderIter.Value()
389             aFolderIter.Next()
390             anIsFound, anAttr = aFolderSObj.FindAttribute("AttributeName")
391             if not anIsFound :
392                 continue
393             anAttr = anAttr._narrow(SALOMEDS.AttributeName);
394             aFolderName = anAttr.Value()
395             print "    ", aFolderName
396             
397             if aFolderName == 'Families' :
398                 anEntityIter = myLocalStudy.NewChildIterator(aFolderSObj);
399                 while anEntityIter.More() :
400                     anEntitySObj = anEntityIter.Value()
401                     anEntityIter.Next()
402                     anAttr = anEntitySObj.FindAttribute("AttributeName")[1]
403                     anAttr = anAttr._narrow(SALOMEDS.AttributeName);
404                     anEntityName = anAttr.Value()
405                     
406                     anEntityId = "3"
407                     if anEntityName == 'onNodes' :
408                         anEntity = VISU.NODE
409                         anEntityId = "0"
410                     if anEntityName == 'onEdges' :
411                         anEntity = VISU.EDGE
412                         anEntityId = "1"
413                     if anEntityName == 'onFaces' :
414                         anEntity = VISU.FACE
415                         anEntityId = "2"
416                     if anEntityName == 'onCells' :
417                         anEntity = VISU.CELL
418                         anEntityId = "3"
419
420                     if HasValue(thePrsTypeList,VISU.TMESH) :
421                         print "      ", anEntityName, aMeshName,
422                         aMesh = theVisu.MeshOnEntity(theResult,aMeshName,anEntity)
423                         if aMesh is None : print "Error"
424                         else :
425                             print ",OK"
426                             theView.DisplayOnly(aMesh)
427                             theView.FitAll()
428                             aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "." + thePictureExt
429                             aPictureName = re.sub("\s+","_", aPictureName);
430                             theView.SavePicture(aPictureName)
431                             if theIsAutoDelete :
432                                 aMesh.RemoveFromStudy()
433                             else :
434                                 aVISUObjList.append(aMesh)
435                         
436                         anFamilyIter = myLocalStudy.NewChildIterator(anEntitySObj);
437                         while anFamilyIter.More() :
438                             aFamilySObj = anFamilyIter.Value()
439                             anFamilyIter.Next()
440                             anAttr = aFamilySObj.FindAttribute("AttributeName")[1]
441                             anAttr = anAttr._narrow(SALOMEDS.AttributeName);
442                             anFamilyName = anAttr.Value()
443                             if HasValue(thePrsTypeList,VISU.TMESH) :
444                                 print "        ", anFamilyName,
445                                 aMesh = theVisu.FamilyMeshOnEntity(theResult,aMeshName,anEntity,anFamilyName)
446                                 if aMesh is None : print "Error"
447                                 else :
448                                     print ",OK"
449                                     theView.DisplayOnly(aMesh)
450                                     theView.FitAll()
451                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + anFamilyName + "." + thePictureExt
452                                     aPictureName = re.sub("\s+","_", aPictureName);
453                                     theView.SavePicture(aPictureName)
454                                     if theIsAutoDelete :
455                                         aMesh.RemoveFromStudy()
456                                     else :
457                                         aVISUObjList.append(aMesh)
458                                 
459             if aFolderName == 'Groups' :
460                 aGroupIter = myLocalStudy.NewChildIterator(aFolderSObj);
461                 while aGroupIter.More() :
462                     aGroupSObj = aGroupIter.Value()
463                     aGroupIter.Next()
464                     anAttr = aGroupSObj.FindAttribute("AttributeName")[1]
465                     anAttr = anAttr._narrow(SALOMEDS.AttributeName);
466                     aGroupName = anAttr.Value()
467                     if HasValue(thePrsTypeList,VISU.TMESH) :
468                         print "      ", aGroupName,
469                         aMesh = theVisu.GroupMesh(theResult,aMeshName,aGroupName)
470                         if aMesh is None : print "Error"
471                         else :
472                             print ",OK"
473                             theView.DisplayOnly(aMesh)
474                             theView.FitAll()
475                             aPictureName = thePictureDir + aMeshNamePic + "_" + aGroupName + "." + thePictureExt
476                             aPictureName = re.sub("\s+","_", aPictureName);
477                             theView.SavePicture(aPictureName)
478                             if theIsAutoDelete :
479                                 aMesh.RemoveFromStudy()
480                             else :
481                                 aVISUObjList.append(aMesh)
482                         
483             if aFolderName == 'Fields' :
484                 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
485                 while aFieldIter.More() :
486                     aFieldSObj = aFieldIter.Value()
487                     aFieldIter.Next()
488                     anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
489                     anAttr = anAttr._narrow(SALOMEDS.AttributeName);
490                     aFieldName = anAttr.Value()
491                     print "      ", aFieldName
492                     
493                     anAttr = aFieldSObj.FindAttribute("AttributeString")[1]
494                     anAttr = anAttr._narrow(SALOMEDS.AttributeString);
495                     aFieldComment = anAttr.Value()
496                     aMap = StrToMap(aFieldComment)
497                     
498                     aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
499                     if aTimeStampIter.More() :
500                         aTimeStampIter.Next()
501                         while aTimeStampIter.More() :
502                             aTimeStampSObj = aTimeStampIter.Value()
503                             aTimeStampIter.Next()
504                             anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
505                             anAttr = anAttr._narrow(SALOMEDS.AttributeName);
506                             aTimeStampName = anAttr.Value()
507                             print "        ", aTimeStampName
508                             
509                             anAttr = aTimeStampSObj.FindAttribute("AttributeString")[1]
510                             anAttr = anAttr._narrow(SALOMEDS.AttributeString);
511                             aTimeStampComment = anAttr.Value()
512                             aMap = StrToMap(aTimeStampComment)
513                             aMeshName = aMap["myMeshName"]
514                             aFieldName = aMap["myFieldName"]
515                             aTimeStampId = atoi(aMap["myTimeStampId"])
516                             anEntity = IntToEntity(aMap["myEntityId"])
517                             anEntityId = str(aMap["myEntityId"]);
518                             #print aMeshName, aFieldName, anEntity, aTimeStampId
519                             if HasValue(thePrsTypeList,VISU.TSCALARMAP) :
520                                 print "          Creating ScalarMapOnField",
521                                 aPrsObj = theVisu.ScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
522                                 if aPrsObj is None : print "Error"
523                                 else :
524                                     print ",OK"
525                                     theView.DisplayOnly(aPrsObj)
526                                     theView.FitAll()
527                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAP." + thePictureExt
528                                     aPictureName = re.sub("\s+","_", aPictureName);
529                                     theView.SavePicture(aPictureName)
530                                     if theIsAutoDelete :
531                                         aPrsObj.RemoveFromStudy()
532                                     else :
533                                         aVISUObjList.append(aPrsObj)
534
535                             if HasValue(thePrsTypeList,VISU.TISOSURFACES) :
536                                 print "          Creating IsoSurfacesOnField",
537                                 aPrsObj = theVisu.IsoSurfacesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
538                                 if aPrsObj is None : print "Error"
539                                 else :
540                                     print ",OK"
541                                     theView.DisplayOnly(aPrsObj)
542                                     theView.FitAll()
543                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TISOSURFACES." + thePictureExt
544                                     aPictureName = re.sub("\s+","_", aPictureName);
545                                     theView.SavePicture(aPictureName)
546                                     if theIsAutoDelete :
547                                         aPrsObj.RemoveFromStudy()
548                                     else :
549                                         aVISUObjList.append(aPrsObj)
550                                 
551                             if HasValue(thePrsTypeList,VISU.TCUTPLANES) :
552                                 print "          Creating CutPlanesOnField",
553                                 aPrsObj = theVisu.CutPlanesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
554                                 if aPrsObj is None : print "Error"
555                                 else :
556                                     print ",OK"
557                                     aPrsObj.SetOrientation(VISU.CutPlanes.ZX,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
558                                     theView.DisplayOnly(aPrsObj)
559                                     theView.FitAll()
560                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTPLANES." + thePictureExt
561                                     aPictureName = re.sub("\s+","_", aPictureName)
562                                     theView.SavePicture(aPictureName)
563                                     if theIsAutoDelete :
564                                         aPrsObj.RemoveFromStudy()
565                                     else :
566                                         aVISUObjList.append(aPrsObj)
567                                 
568                             if HasValue(thePrsTypeList,VISU.TCUTLINES) :
569                                 print "          Creating CutLinesOnField",
570                                 aPrsObj = theVisu.CutLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
571                                 if aPrsObj is None : print "Error"
572                                 else :
573                                     print ",OK"
574                                     aPrsObj.SetOrientation(VISU.CutPlanes.XY,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
575                                     aPrsObj.SetOrientation2(VISU.CutPlanes.ZX,aPrsObj.GetRotateX2(),aPrsObj.GetRotateY2())
576                                     theView.DisplayOnly(aPrsObj)
577                                     theView.FitAll()
578                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTLINES." + thePictureExt
579                                     aPictureName = re.sub("\s+","_", aPictureName)
580                                     theView.SavePicture(aPictureName)
581                                     if theIsAutoDelete :
582                                         aPrsObj.RemoveFromStudy()
583                                     else :
584                                         aVISUObjList.append(aPrsObj)
585                                 
586                             if HasValue(thePrsTypeList,VISU.TCUTSEGMENT) :
587                                 print "          Creating CutSegmentOnField",
588                                 aPrsObj = theVisu.CutSegmentOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
589                                 if aPrsObj is None : print "Error"
590                                 else :
591                                     print ",OK"
592                                     theView.DisplayOnly(aPrsObj)
593                                     theView.FitAll()
594                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTSEGMENT." + thePictureExt
595                                     aPictureName = re.sub("\s+","_", aPictureName)
596                                     theView.SavePicture(aPictureName)
597                                     if theIsAutoDelete :
598                                         aPrsObj.RemoveFromStudy()
599                                     else :
600                                         aVISUObjList.append(aPrsObj)
601                                 
602                             if HasValue(thePrsTypeList,VISU.TPLOT3D) :
603                                 print "          Creating Plot3DOnField",
604                                 aPrsObj = theVisu.Plot3DOnField(theResult,aMeshName,anEntity,
605                                                                 aFieldName,aTimeStampId)
606                                 if aPrsObj is None : print "Error"
607                                 else :
608                                     print ",OK"
609                                 #aPrsObj.SetOrientation(VISU.CutPlanes.ZX,
610                                 #                       aPrsObj.GetRotateX(),
611                                 #                       aPrsObj.GetRotateY())
612                                     theView.DisplayOnly(aPrsObj)
613                                     theView.FitAll()
614                                     aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TPLOT3D." + thePictureExt
615                                     aPictureName = re.sub("\s+","_", aPictureName)
616                                     theView.SavePicture(aPictureName)
617                                     if theIsAutoDelete :
618                                         aPrsObj.RemoveFromStudy()
619                                     else :
620                                         aVISUObjList.append(aPrsObj)
621                                 
622                             aNumComponent = atoi(aMap["myNumComponent"])
623                             if aNumComponent > 1 :
624                                 if HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPE) :
625                                     print "          Creating DeformedShapeOnField",
626                                     aPrsObj = theVisu.DeformedShapeOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
627                                     if aPrsObj is None : print "Error"
628                                     else :
629                                         print ",OK"
630                                         theView.DisplayOnly(aPrsObj)
631                                         theView.FitAll()
632                                         aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPE." + thePictureExt
633                                         aPictureName = re.sub("\s+","_", aPictureName)
634                                         theView.SavePicture(aPictureName)
635                                         if theIsAutoDelete :
636                                             aPrsObj.RemoveFromStudy()
637                                         else :
638                                             aVISUObjList.append(aPrsObj)
639
640                                 if HasValue(thePrsTypeList,VISU.TVECTORS) :
641                                     print "          Creating VectorsOnField",
642                                     aPrsObj = theVisu.VectorsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
643                                     if aPrsObj is None : print "Error"
644                                     else :
645                                         print ",OK"
646                                         theView.DisplayOnly(aPrsObj)
647                                         theView.FitAll()
648                                         aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TVECTORS." + thePictureExt
649                                         aPictureName = re.sub("\s+","_", aPictureName)
650                                         theView.SavePicture(aPictureName)
651                                         if theIsAutoDelete :
652                                             aPrsObj.RemoveFromStudy()
653                                         else :
654                                             aVISUObjList.append(aPrsObj)
655                                     
656                                 if HasValue(thePrsTypeList,VISU.TSTREAMLINES) :
657                                     print "          Creating StreamLinesOnField",
658                                     aPrsObj = theVisu.StreamLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
659                                     if aPrsObj is None : print "Error"
660                                     else :
661                                         print ",OK"
662                                         theView.DisplayOnly(aPrsObj)
663                                         theView.FitAll()
664                                         aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSTREAMLINES." + thePictureExt
665                                         aPictureName = re.sub("\s+","_", aPictureName)
666                                         theView.SavePicture(aPictureName)
667                                         if theIsAutoDelete :
668                                             aPrsObj.RemoveFromStudy()
669                                         else :
670                                             aVISUObjList.append(aPrsObj)
671
672                                 if HasValue(thePrsTypeList,VISU.TSCALARMAPONDEFORMEDSHAPE) or HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPEANDSCALARMAP) :
673                                     print "          Creating DeformedShapeAndScalarMapOnField",
674                                     aPrsObj = theVisu.DeformedShapeAndScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
675                                     if aPrsObj is None : print "Error"
676                                     else :
677                                         print ",OK"
678                                         theView.DisplayOnly(aPrsObj)
679                                         theView.FitAll()
680                                         aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPEANDSCALARMAP." + thePictureExt
681                                         aPictureName = re.sub("\s+","_", aPictureName)
682                                         theView.SavePicture(aPictureName)
683                                         if theIsAutoDelete :
684                                             aPrsObj.RemoveFromStudy()
685                                         else :
686                                             aVISUObjList.append(aPrsObj)
687
688                                 if HasValue(thePrsTypeList,VISU.TGAUSSPOINTS) :
689                                     print "          Creating GaussPointsOnField",
690                                     aPrsObj = theVisu.GaussPointsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
691                                     if aPrsObj is None : print "Error"
692                                     else :
693                                         print ",OK"
694                                         theView.DisplayOnly(aPrsObj)
695                                         theView.FitAll()
696                                         aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TGAUSSPOINTS." + thePictureExt
697                                         aPictureName = re.sub("\s+","_", aPictureName)
698                                         theView.SavePicture(aPictureName)
699                                         if theIsAutoDelete :
700                                             aPrsObj.RemoveFromStudy()
701                                             pass
702                                         else :
703                                             aVISUObjList.append(aPrsObj)
704                                             pass
705                                         pass
706                                     pass
707                                 
708     return aVISUObjList
709
710
711 def generateName(prefix = None):
712     import random;
713     int = random.randint(1,1000);
714     if prefix is None:
715         return "Study" + str(int)
716     else :
717         return prefix + str(int)
718     
719
720
721 # ----------------------
722 # MESH
723 # ----------------------
724 def try_mesh_parameters(theMeshPattern):
725     aResult = []
726     if theMeshPattern is None : return aResult ;
727     theMeshPattern =  theMeshPattern._narrow(VISU.Mesh)
728     if theMeshPattern is None : return aResult ;
729
730     aTYPES = [VISU.POINT, VISU.WIREFRAME, VISU.SHADED, VISU.INSIDEFRAME, VISU.SHRINK]
731     import copy; import os;
732     for ind in aTYPES:
733         aNewMesh = copy.deepcopy(theMeshPattern);
734         aNewMesh.SetPresentationType(ind)
735         aResult.append(aNewMesh)
736
737     return aResult
738
739
740 # ----------------------------    
741 # SCALAR MAP 
742 # ----------------------------    
743 ind=1  #try safe way
744 def try_scalarmap_parameters(thePattern, dump = 0):
745
746     if thePattern  is None : return None 
747
748     SCALING = [VISU.LINEAR, VISU.LOGARITHMIC]
749     import copy
750     import random
751
752     anObj = thePattern#copy.deepcopy(thePattern);
753     #ind = random.randint(1,2)
754     if ind%2 :
755             #try incorrect value deliberately (but allowed by idl description)
756             #try SetScalarMode(long)
757             mode = random.randint(-100000,100000); #incorrect value deliberately
758     else:
759             #correct value of ScalarMode
760             mode = random.randint(0, 3)
761
762     if dump : print "\tSetScalarMode(" + str(mode) +")"
763     anObj.SetScalarMode(mode)
764
765     # --- SCALING ---
766     scal = random.randint(0,1)
767     if dump : print "\tSetScaling(" + str(SCALING[scal]) +")"
768     anObj.SetScaling(SCALING[scal])
769         
770     # --- BOUNDARIES ---
771     if ind%2 :
772             alfa =  random.random()*random.randint(-100000,100000)
773             betta = random.random()*random.randint(-100000,100000)
774             aMin = alfa; aMax = betta
775     else:
776             #more correct set
777             aPMin = thePattern.GetMin()
778             aPMax = thePattern.GetMax()
779             aLen = aPMax - aPMin
780             alfa =  random.random()%0.5
781             betta = random.random()%0.5
782             aMin = alfa*aLen*random.randint(-1,1) + aPMin
783             aMax = betta*aLen*random.randint(-1,1) + aPMax
784     if dump : print "\tSetRange(" + str(aMin) + ", " + str(aMax) + ")"
785     anObj.SetRange(aMin, aMax)
786
787         # --- POSITION ---
788     if ind%2:
789             X=random.random()*random.randint(-100000,100000)
790             Y=random.random()*random.randint(-100000,100000)
791     else :
792              X=random.random()
793              Y=random.random()
794     if dump : print "SetPosition("+ str(X) + ", " + str(Y) + " )"
795     anObj.SetPosition(X, Y)
796
797         # --- SCALAR BAR SIZE ---
798     if ind%2:
799             aWidth=random.random()*random.randint(-100000,100000)
800             aHeight=random.random()*random.randint(-100000,100000)
801     else :
802              aWidth=random.random()
803              aHeight=random.random()
804     if dump : print " SCALAR BAR Width = " + str(aWidth) + " Height = ", str(aHeight)
805     anObj.SetSize(aWidth, aHeight)
806     
807     return anObj
808
809
810 def dump_scalarmap_parameters(anObj):
811     
812     print "\tGetScalarMode() = " + str(anObj.GetScalarMode()) 
813     print "\tGetScaling() = " + str(anObj.GetScaling()) 
814     print "\tGetMin() = " + str(anObj.GetMin()) + "  GetMax() = " + str (anObj.GetMax())
815     print "\tGetOrientation() = " + str(anObj.GetOrientation())
816     print "\tGetPosX() = ", str(anObj.GetPosX()) + "  GetPosY() = ", str(anObj.GetPosY())
817     print "\tGetWidth() = ", str ( anObj.GetWidth()) + "  GetHeight() = " + str(anObj.GetHeight())
818
819 # ----------------------
820 # DEFORMED SHAPE
821 # ----------------------
822 def try_deformedshape_parameters(thePattern) :
823
824     if thePattern  is None : return None 
825     import copy
826     import random
827
828     anObj = try_scalarmap_parameters(thePattern)
829
830     # --- SCALING ---
831     if ind%2:
832         anObj.SetScale( random.random()*random.randint(-100000, 100000))
833     else :
834         anObj.SetScale( anObj.GetScale()*random.random())
835
836     return anObj
837
838
839 def dump_deformedshape_parameters(theObject):
840     dump_scalarmap_parameters(theObject)
841     print "GetScale() = ", theObject.GetScale()
842     
843 # ----------------------
844 # CUT PLANES
845 # ----------------------
846 def try_cutplanes_parameters(thePattern) :
847
848     if thePattern  is None : return None 
849     import copy
850     import random
851
852     ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
853
854     ind = random.randint(1,2)
855     anObj = try_scalarmap_parameters(thePattern)
856         
857     if ind%2 :   anObj.SetNbPlanes(random.randint(-40,40))
858     else :       anObj.SetNbPlanes(random.randint(0,10)) #try behaivor if NbPlanes=0
859
860     # --- DISPLACEMENT ---
861     anObj.SetDisplacement(random.randint(-100000,100000))
862
863     # --- PLANE POSITION ---
864     if ind%2:
865         PlaneNb = random.randint(-100000,100000) #incorrect value is possible
866     else    : PlaneNb = random.randint(0, anObj.GetNbPlanes())
867         
868     anObj.SetPlanePosition(PlaneNb, random.random()*random.randint(-100000,100000))
869
870     # --- SET DEFAULT ---
871     anObj.SetDefault(PlaneNb)
872
873     # --- SET X,Y,Z ROTATION ---
874     if ind%2 :
875             angle1 = random.random()*random.randint(-100000,100000)
876             angle2 = random.random()*random.randint(-100000,100000)
877     else :
878             angle1 = random.random()*3.14
879             angle2 = random.random()*3.14
880         
881     # --- ORIENTATION ---
882     anObj.SetOrientation(ORIENT[random.randint(0,2)],angle1,angle2)
883
884     return anObj
885         
886 def dump_cutplanes_parameters(theObject):
887         dump_saclarmap_parameters(theObject)
888
889         print "GetOrientationType = " + str(theObject.GetOrientationType())
890         PlanesNb = theObject.GetNbPlanes()
891         print "GetNbPlanes() = ", str(PlanesNb)
892         for i in range(0,PlanesNb+1):
893             if theObject.IsDefault(i) :
894                 print "Default plane : "+str(i); break
895         print "GetPlanePosition(" + str(i) + ") = ", theObject.GetPlanePosition(i)
896         print "GetDisplacement() = ", str(theObject.GetDisplacement())
897         print "GetRotateX() = ", str(theObject.GetRotateX())
898         print "GetRotateY() = ", str(theObject.GetRotateY())
899         print "GetRotateZ() = ", str(theObject.GetRotateZ())
900
901 # ----------------------
902 # CUT LINES
903 # ----------------------
904 def try_cutlines_parameters(thePattern):
905
906     if thePattern  is None : return None 
907     import copy
908     import random
909
910     ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
911     ind = random.randint(1,2)
912     anObj = try_scalarmap_parameters(thePattern)
913
914     # --- ORIENTATION ---
915     anObj.SetOrientation(ORIENT[random.randint(0,2)],
916                          random.randint(-100,100)*random.random(),
917                          random.randint(-100,100)*random.random())
918     anObj.SetOrientation2(ORIENT[random.randint(0,2)],
919                           random.randint(-100,100)*random.random(),
920                           random.randint(-100,100)*random.random())
921
922     # --- Base Plane Position ---
923     anObj.SetBasePlanePosition( random.random()*random.randint(-100000,100000))
924
925     # --- NUMBER OF LINES ---
926     if ind%2:
927             anObj.SetNbLines(random.randint(-5, 50))
928
929     return anObj
930
931 def dump_cutlines_parameters(theObject):
932     dump_scalarmap_parameters(theObject)
933
934     print "GetOrientationType() = " + str(theObject.GetOrientationType())
935     print "GetOrientationType2() = " + str(theObject.GetOrientationType2())
936     print "GetBasePlanePosition() = "+ str(theObject.GetBasePlanePosition())
937     print "GetNbLines() = " + str(theObject.GetNbLines())
938     print "GetRotateX() = ", str(theObject.GetRotateX())
939     print "GetRotateX2() = ", str(theObject.GetRotateX2())
940     print "GetRotateY() = ", str(theObject.GetRotateY())
941     print "GetRotateY2() = ", str(theObject.GetRotateY2())
942
943 # ----------------------
944 # CUT SEGMENT
945 # ----------------------
946 def try_cutsegment_parameters(thePattern):
947
948     if thePattern  is None : return None 
949     import copy
950     import random
951
952     anObj = try_scalarmap_parameters(thePattern)
953
954     anObj.SetPoint1(random.randint(-100,100)*random.random(),
955                     random.randint(-100,100)*random.random(),
956                     random.randint(-100,100)*random.random())
957     anObj.SetPoint2(random.randint(-100,100)*random.random(),
958                     random.randint(-100,100)*random.random(),
959                     random.randint(-100,100)*random.random())
960
961     return anObj
962
963 def dump_cutsegment_parameters(theObject):
964     dump_scalarmap_parameters(theObject)
965
966     x1 = y1 = z1 = 0
967     x2 = y2 = z2 = 0
968     theObject.GetPoint1(x1, y1, z1)
969     theObject.GetPoint1(x2, y2, z2)
970     print "GetPoint1() = " + str(x1) + ", " + str(y1) + ", " + str(z1)
971     print "GetPoint2() = " + str(x2) + ", " + str(y2) + ", " + str(z2)
972
973 # ----------------------
974 # STREAM LINES
975 # ----------------------
976 def try_streamlines_parameters(thePattern):
977
978     if thePattern  is None : return None 
979     import copy
980     import random
981
982     DIRECTION = [VISU.StreamLines.FORWARD, VISU.StreamLines.BACKWARD, VISU.StreamLines.BOTH]
983
984     ind = random.randint(1,2)
985     anObj = (try_deformedshape_parameters(thePattern))[0]
986
987     # --- DIREACTION ---
988     anObj.SetDirection(DIRECTION[random.randint(0,2)])
989
990     # --- STEP LENGTH ---
991     if ind%2 : anObj.SetStepLength(random.random()*random.randint(-1000,1000))
992     else :
993             aLen = anObj.GetMax() - anObj.GetMin()
994             anObj.SetStepLength(aLen/random.randint(1,100))
995             
996     # --- PROPAGATION TIME ---
997     anObj.SetPropagationTime(random.random()*random.randint(1,100))
998
999     # --- INTEGRATION STEP ---
1000     if ind%2 :
1001             anObj.SetIntegrationStep(random.random()*random.randint(-1000,1000))
1002     else:
1003             anObj.SetIntegrationStep(random.random())
1004
1005     # --- USED POINT ---
1006     anObj.SetUsedPoints(random.random()*random.randint(-10000,10000))
1007
1008     return anObj
1009         
1010 def dump_streamlines_parameters(theObject):
1011     
1012     dump_deformedshape_parameters(theObject)
1013     
1014     print "GetDirection() = "      + str(theObject.GetDirection())
1015     print "GetStepLength() = "     + str(theObject.GetStepLength())
1016     print "GetPropagationTime() =" + str(theObject.GetPropagationTime())
1017     print "GetIntegrationStep() =" + str(theObject.GetIntegrationStep())
1018     print "GetUsedPoints()      =" + str(theObject.GetUsedPoints())
1019     
1020 # ----------------------
1021 # VECTORS     
1022 # ----------------------
1023 def try_vectors_parameters(thePattern, theNum):
1024
1025     if thePattern  is None : return None 
1026     import copy
1027     import random
1028     GLIPH_TYPE = [VISU.Vectors.ARROW, VISU.Vectors.CONE2, VISU.Vectors.CONE6, VISU.Vectors.NONE]
1029     GLIPH_POS = [VISU.Vectors.CENTER, VISU.Vectors.TAIL, VISU.Vectors.HEAD]
1030     ind = random.randint(1,2)
1031     anObj = (try_deformedshape_parameters(thePattern))[0]
1032
1033     # --- LINE WIDTH ---
1034     if ind%2 :
1035             anObj.SetLineWidth(random.random()*random.randint(-10000,10000))
1036     else :
1037             anObj.SetLineWidth(random.randint(1, 10))
1038
1039     # --- GLIPH TYPE ---
1040     anObj.SetGlyphType(GLIPH_TYPE[random.randint(0, len(GLIPH_TYPE)-1)])
1041         
1042     # --- GLIPH POS ---
1043     anObj.SetGlyphPos(GLIPH_POS[random.randint(0, len(GLIPH_POS)-1)])
1044     
1045     return anObj
1046
1047 def dump_vectors_parameters(theObject):
1048     
1049     dump_deformedshape_parameters(theObject)
1050     
1051     print "GetLineWidth() = " +str(theObject.GetLineWidth())
1052     print "GetGlyphType() = " +str(theObject.GetGlyphType())
1053     print "GetGlyphPos()  = " +str(theObject.GetGlyphPos())
1054
1055
1056 # ----------------------
1057 # ISO SURFACES     
1058 # ----------------------
1059
1060 def try_isosurfaces_parameters(thePattern) :
1061     if thePattern  is None : return None 
1062     import copy
1063     import random
1064     
1065     anObj = try_scalarmap_parameters(thePattern)
1066     ind = random.randint(1,2)   
1067     # --- SURFACES NUMBER ---
1068     if ind%2 :
1069             anObj.SetNbSurfaces(random.randint(-100000,100000))
1070     else:
1071             anObj.SetNbSurfaces(random.randint(1, 50))
1072             
1073     return anObj
1074
1075 def dump_isosurfaces_parameters(theObject):
1076     
1077     dump_scalarmap_parameters(theObject)
1078     print "GetNbSurfaces() = "+ str(theObject.GetNbSurfaces())
1079
1080 # ----------------------------
1081 # SCALAR MAP ON DEFORMED SHAPE
1082 # ----------------------------
1083 def dump_scalarmapondeformedshape_parameters(theObject):
1084     dump_scalarmap_parameters(theObject)
1085     print "GetScale()          =", theObject.GetScale()
1086     print "GetScalarCMeshName ()=|",theObject.GetScalarCMeshName(),"|"
1087     print "GetScalarCFieldName()=|",theObject.GetScalarCFieldName(),"|"
1088     print "GetScalarEEntity()   =",theObject.GetScalarEEntity()
1089     print "GetScalarLIteration()=",theObject.GetScalarLIteration()
1090     pass
1091
1092 def try_scalarmapondeformedshape_parameters(thePattern):
1093
1094     if thePattern  is None : return None 
1095     import copy
1096     import random
1097
1098     anObj = try_scalarmap_parameters(thePattern)
1099
1100     # --- SCALING ---
1101     print 
1102     anObj.SetScale( anObj.GetScale()/random.random()*random.randint(1,10))
1103
1104     # --- Scalar Field ---
1105     # not implemented yet.
1106     
1107     return anObj
1108 # ----------------------
1109 # PLOT 3D 
1110 # ----------------------
1111 def dump_plot3d_parameters(theObject):
1112     dump_scalarmap_parameters(theObject)
1113     print "GetOrientationType()=",str(theObject.GetOrientationType())
1114     print "GetRotateX()=",theObject.GetRotateX()
1115     print "GetRotateY()=",theObject.GetRotateY()
1116     print "GetPlanePosition()=",theObject.GetPlanePosition()
1117     print "IsPositionRelative()=",theObject.IsPositionRelative()
1118     print "GetScaleFactor()=",theObject.GetScaleFactor()
1119     print "GetIsContourPrs()=",theObject.GetIsContourPrs()
1120     print "GetNbOfContours()=",theObject.GetNbOfContours()
1121     pass
1122
1123 def try_plot3d_parameters(thePattern):
1124     if thePattern is None : return None
1125     import random
1126     
1127     anObj = try_scalarmap_parameters(thePattern)
1128
1129     ORIENT = [VISU.Plot3D.XY, VISU.Plot3D.YZ, VISU.Plot3D.ZX]
1130
1131     theXAngle = random.random()*random.randint(-180,180)
1132     theYAngle = random.random()*random.randint(-180,180)
1133
1134     # ORIENTATION and ANGLES
1135     anObj.SetOrientation(ORIENT[random.randint(0,2)],theXAngle,theYAngle)
1136
1137     # Plane position (revative)
1138     anObj.SetPlanePosition(random.random(),1)
1139
1140     # SCALE FACTOR
1141     anObj.SetScaleFactor(random.random()*random.randint(-10000,10000))
1142
1143     # CONTOUR PRS
1144     anObj.SetContourPrs(random.randint(0,1))
1145     if anObj.GetIsContourPrs():
1146         anObj.SetNbOfContours(random.randint(1,999))
1147         pass
1148     
1149     pass
1150
1151 # ----------------------
1152 # Gauss points
1153 # ----------------------
1154 def dump_gausspoints_parameters(theObject):
1155     
1156     print "\tGetScalarMode() = " + str(anObj.GetScalarMode())
1157     print "\tGetMin() = " + str(anObj.GetMin()) + "  GetMax() = " + str (anObj.GetMax())
1158     print "\tGetPosX() = ", str(anObj.GetPosX()) + "  GetPosY() = ", str(anObj.GetPosY())
1159     print "\tGetWidth() = ", str ( anObj.GetWidth()) + "  GetHeight() = " + str(anObj.GetHeight())
1160     print "\tGetNbColors() = " + str(anObj.GetNbColors())
1161     print "\tGetLabels() = " + str(anObj.GetLabels())
1162     print "\tGetTitle() = " + str(anObj.GetTitle())
1163     pass
1164
1165 def try_plot3d_parameters(thePattern):
1166     if thePattern is None : return None
1167     import random
1168     
1169     pass
1170
1171 # ----------------------
1172 # TABLES AND CURVES
1173 # ----------------------
1174
1175 def FillTable( theTable, theValues, theRows, theColumns, theRowTitles, theRowUnits, theColumnTitles ):
1176     if theTable is None: return
1177     if len(theRows) != len(theColumns): return
1178     if len(theRows) != len(theValues): return
1179     i = 0
1180     for value in theValues:
1181         theTable.PutValue( value, theRows[ i ], theColumns[ i ])
1182         i = i + 1
1183         pass
1184     i = 1
1185     for title in theRowTitles:
1186         theTable.SetRowTitle( i, title )
1187         theTable.SetRowUnit( i, theRowUnits[ i - 1 ])
1188         i = i + 1
1189         pass
1190     i = 1
1191     for title in theColumnTitles:
1192         theTable.SetColumnTitle( i, title )
1193         i = i + 1
1194         pass
1195     pass
1196
1197 def CreateCurve( theTable, theHRow, theVRow, theTitle, theColor, theMarker, theLineType, theLineWidth ):
1198     if theTitle is None: return
1199     curve = myLocalVisu.CreateCurve( theTable, theHRow, theVRow );
1200     if curve:
1201         curve.SetTitle( theTitle )
1202         curve.SetColor( theColor )
1203         curve.SetMarker( theMarker )
1204         curve.SetLine( theLineType, theLineWidth )
1205         pass
1206     return curve
1207
1208 def CreateCurveWithZ( theTable, theHRow, theVRow, theZRow, theTitle, theColor, theMarker, theLineType, theLineWidth ):
1209     if theTitle is None: return
1210     curve = myLocalVisu.CreateCurveWithZ( theTable, theHRow, theVRow, theZRow );
1211     if curve:
1212         curve.SetTitle( theTitle )
1213         curve.SetColor( theColor )
1214         curve.SetMarker( theMarker )
1215         curve.SetLine( theLineType, theLineWidth )
1216         pass
1217     return curve
1218
1219 def CreateCurveWithZExt( theTable, theHRow, theVRow, theZRow, theIsV2, theTitle, theColor, theMarker, theLineType, theLineWidth ):
1220     if theTitle is None: return
1221     curve = myLocalVisu.CreateCurveWithZExt( theTable, theHRow, theVRow, theZRow, theIsV2 );
1222     if curve:
1223         curve.SetTitle( theTitle )
1224         curve.SetColor( theColor )
1225         curve.SetMarker( theMarker )
1226         curve.SetLine( theLineType, theLineWidth )
1227         pass
1228     return curve