1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 # VISU VISU_SWIG : binding of C++ implementation and Python
29 from time import sleep
33 import SALOME_Session_idl
36 import SALOME_ModuleCatalog
37 from omniORB import CORBA
39 from time import sleep
42 myNamingService = None
43 myLifeCycleCORBA = None
44 myNamingService = None
45 myLocalStudyManager = None
51 def Initialize(theORB, theNamingService, theLifeCycleCORBA, theStudyManager, theStudy, theDelay) :
52 global myORB, myNamingService, myLifeCycleCORBA, myLocalStudyManager, myLocalStudy
53 global mySession, myLocalVisu, myDelay
56 myNamingService = theNamingService
57 myLifeCycleCORBA = theLifeCycleCORBA
58 myLocalStudyManager = theStudyManager
59 while mySession == None:
60 mySession = myNamingService.Resolve("/Kernel/Session")
61 mySession = mySession._narrow(SALOME.Session)
62 mySession.GetInterface()
65 myLocalVisu = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "VISU")
66 myLocalStudy = theStudy
67 myLocalVisu.SetCurrentStudy(myLocalStudy)
70 def PublishComponent(theStudyDocument):
71 aComponentDataType = myLocalVisu.ComponentDataType()
72 aSComponent = theStudyDocument.FindComponent(aComponentDataType)
73 if aSComponent == None:
74 aStudyBuilder = theStudyDocument.NewBuilder()
75 aStudyBuilder.NewCommand()
76 aLocked = theStudyDocument.GetProperties().IsLocked()
78 theStudyDocument.GetProperties().SetLocked(0)
81 aSComponent = aStudyBuilder.NewComponent(aComponentDataType);
82 aName = aStudyBuilder.FindOrCreateAttribute(aSComponent,"AttributeName")
83 aModuleCatalogObj = myNamingService.Resolve("/Kernel/ModulCatalog");
84 aModuleCatalog = aModuleCatalogObj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
85 aComponent = aModuleCatalog.GetComponent(aComponentDataType);
86 if aComponent != None:
87 aComponentUserName = aComponent._get_componentusername()
88 aName.SetValue(aComponentUserName)
91 aPixMap = aStudyBuilder.FindOrCreateAttribute(aSComponent,"AttributePixMap")
92 aPixMap.SetPixMap("ICON_OBJBROWSER_Visu")
94 aStudyBuilder.DefineComponentInstance(aSComponent,myLocalVisu);
96 theStudyDocument.GetProperties().SetLocked(1);
99 aStudyBuilder.CommitCommand();
104 def SetName(theObj, theName):
105 anIOR = myORB.object_to_string(theObj)
106 aSObj = myLocalStudy.FindObjectIOR(anIOR)
107 anAttr = aSObj.FindAttribute("AttributeName")[1]
108 anAttr.SetValue(theName)
110 def StrToMap(theString) :
111 aPairList = split(theString,";")
113 iEnd = len(aPairList)
114 for i in range(iEnd) :
115 aPair = split(aPairList[i],"=")
116 aMap[aPair[0]] = aPair[1]
119 def IntToEntity(theInt) :
120 theInt = atoi(theInt)
130 def HasValue(theList, theValue) :
132 return theList.index(theValue) + 1
133 except StandardError, e :
136 def CreateStudyForMed(theVisu, theFileName) :
137 print "CreateStudyForMed ", theFileName,
138 if os.path.isfile(theFileName) :
139 if re.search("\.med$", theFileName) is not None :
141 aStudyName = os.path.basename(theFileName)
142 aStudyName = re.sub(r'\.med', "", aStudyName)
143 aStudyName = generateName(aStudyName)
144 print "myLocalStudyManager.NewStudy -", aStudyName, "...",
145 aStudy = myLocalStudyManager.NewStudy(aStudyName)
146 if aStudy is None : raise RuntimeError, "Error"
149 print "CreateStudyForMed - Creating a 3D viewer...",
150 theVisu.SetCurrentStudy(aStudy)
151 myViewManager = theVisu.GetViewManager()
152 if myViewManager is None : raise RuntimeError, "Error - theVisu.GetViewManager"
153 myView = myViewManager.Create3DView()
154 if myView is None : raise RuntimeError, "Error - myViewManager.Create3DView"
158 return [aStudy, myViewManager, myView]
159 raise RuntimeError, "Error: There is no such file."
161 def getMedSObject(theStudy = myLocalStudy ):
163 theStudy = myLocalStudy
164 aSO = theStudy.FindObject("Med")
165 anIsPresetn, aSObject = aSO.FindSubObject(1)
168 def getMedObjectFromStudy(theStudy = myLocalStudy):
169 aSObject = getMedSObject(theStudy)
171 anAttr = aSObject.FindAttribute("AttributeIOR")[1]
172 anObj = myORB.string_to_object(anAttr.Value())
173 return anObj._narrow(SALOME_MED.MED)
176 def getFieldObjectFromStudy(number, subnumber, theStudy = myLocalStudy):
178 theStudy = myLocalStudy
179 mySO = theStudy.FindObject("MEDFIELD")
181 raise Runtime, "getFieldObjectFromStudy mySO is None"
182 mysub = mySO.FindSubObject(number)[1]
184 mysubsub = mysub.FindSubObject(subnumber)[1]
186 Builder = theStudy.NewBuilder()
187 anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
188 obj = myORB.string_to_object(anAttr.Value())
189 myObj = obj._narrow(SALOME_MED.FIELDINT)
191 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
194 print "ERROR: No Field Object stored in this Study"
197 def SObjectToObject(theSObject) :
199 if theSObject is None :
200 print "SObjectToObject : argument is None"
202 res,Attr = theSObject.FindAttribute("AttributeIOR")
203 if (res != 0) and (Attr is not None) :
204 anIOR = Attr._narrow(SALOMEDS.AttributeIOR);
205 aValue = anIOR.Value();
206 if(len(aValue) != 0) :
207 anObj = myORB.string_to_object(aValue);
209 print "SObjectToObject - IOR = ''"
212 def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
214 global myLifeCycleCORBA
215 print "lcc.FindOrLoadComponent...",
216 aMedComp = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "MED")
217 if aMedComp is None : print "Error"
220 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
222 print "aMedComp.readStructFileWithFieldType...",
223 aMedComp.readStructFileWithFieldType(theFileName,myLocalStudy._get_Name())
224 aMedSObj = getMedSObject(myLocalStudy)
225 if aMedSObj is None : raise RuntimeError, "Error"
228 print "theVisu.ImportMed...",
229 aResult = theVisu.ImportMed(aMedSObj)
230 if aResult is None : raise RuntimeError, "Error"
233 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
235 aResult.RemoveFromStudy()
237 aVISUObjList.append(aResult)
239 aFolderIter = myLocalStudy.NewChildIterator(aMedSObj.GetFather());
240 while aFolderIter.More() :
241 aFolderSObj = aFolderIter.Value()
243 anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
244 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
245 aFolderName = anAttr.Value()
246 print " ", aFolderName
248 if aFolderName == 'MEDMESH' :
249 aMeshIter = myLocalStudy.NewChildIterator(aFolderSObj);
250 while aMeshIter.More() :
251 aMeshSObj = aMeshIter.Value()
253 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
254 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
255 aMeshName = anAttr.Value()
258 aSupportIter = myLocalStudy.NewChildIterator(aMeshSObj);
259 while aSupportIter.More() :
260 aSupportSObj = aSupportIter.Value()
262 anAttr = aSupportSObj.FindAttribute("AttributeName")[1]
263 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
264 aSupportName = anAttr.Value()
265 print " ", aSupportName
267 if aFolderName == 'MEDFIELD' :
268 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
269 while aFieldIter.More() :
270 aFieldSObj = aFieldIter.Value()
272 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
273 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
274 aFieldName = anAttr.Value()
275 print " ", aFieldName
277 print "theVisu.ImportMed...",
278 aResult = theVisu.ImportMed(aFieldSObj)
279 if aResult is None : raise RuntimeError, "Error"
282 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
284 aResult.RemoveFromStudy()
286 aVISUObjList.append(aResult)
288 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
289 if aTimeStampIter.More() :
290 aTimeStampIter.Next()
291 while aTimeStampIter.More() :
292 aTimeStampSObj = aTimeStampIter.Value()
293 aTimeStampIter.Next()
294 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
295 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
296 aTimeStampName = anAttr.Value()
297 print " ", aTimeStampName
299 print "theVisu.ImportMed...",
300 aMedField = SObjectToObject(aTimeStampSObj)
301 aResult = theVisu.ImportMedField(aMedField)
302 if aResult is None : raise RuntimeError, "Error"
305 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
307 aResult.RemoveFromStudy()
309 aVISUObjList.append(aResult)
313 # except Exception, e:
316 def CreatePrsForFile(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
318 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
320 print "theVisu.ImportMed...",
321 aResult = theVisu.ImportFile(theFileName)
322 if aResult is None : raise RuntimeError, "Error"
325 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
328 aResult.RemoveFromStudy()
330 aVISUObjList.append(aResult)
334 # except Exception, e:
337 def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
339 if theIsAutoDelete is not None :
343 print "CreatePrsForResult - myLocalStudy.FindObjectIOR...",
344 myLocalStudy = theVisu.GetCurrentStudy()
346 aSObj = myLocalStudy.FindObjectIOR(theResult.GetID())
347 if aSObj is None : raise RuntimeError, "Error"
349 aMeshIter = myLocalStudy.NewChildIterator(aSObj);
350 while aMeshIter.More() :
351 aMeshSObj = aMeshIter.Value()
353 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
355 aMeshSObj = aMeshIter.Value()
357 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
358 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
359 aMeshName = anAttr.Value()
360 aMeshNamePic = re.sub(".","_",aMeshName)
363 aFolderIter = myLocalStudy.NewChildIterator(aMeshSObj);
364 while aFolderIter.More() :
365 aFolderSObj = aFolderIter.Value()
367 anIsFound, anAttr = aFolderSObj.FindAttribute("AttributeName")
370 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
371 aFolderName = anAttr.Value()
372 print " ", aFolderName
374 if aFolderName == 'Families' :
375 anEntityIter = myLocalStudy.NewChildIterator(aFolderSObj);
376 while anEntityIter.More() :
377 anEntitySObj = anEntityIter.Value()
379 anAttr = anEntitySObj.FindAttribute("AttributeName")[1]
380 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
381 anEntityName = anAttr.Value()
384 if anEntityName == 'onNodes' :
387 if anEntityName == 'onEdges' :
390 if anEntityName == 'onFaces' :
393 if anEntityName == 'onCells' :
397 if HasValue(thePrsTypeList,VISU.TMESH) :
398 print " ", anEntityName, aMeshName,
399 aMesh = theVisu.MeshOnEntity(theResult,aMeshName,anEntity)
400 if aMesh is None : print "Error"
403 theView.DisplayOnly(aMesh)
405 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "." + thePictureExt
406 aPictureName = re.sub("\s+","_", aPictureName);
407 theView.SavePicture(aPictureName)
409 aMesh.RemoveFromStudy()
411 aVISUObjList.append(aMesh)
413 anFamilyIter = myLocalStudy.NewChildIterator(anEntitySObj);
414 while anFamilyIter.More() :
415 aFamilySObj = anFamilyIter.Value()
417 anAttr = aFamilySObj.FindAttribute("AttributeName")[1]
418 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
419 anFamilyName = anAttr.Value()
420 if HasValue(thePrsTypeList,VISU.TMESH) :
421 print " ", anFamilyName,
422 aMesh = theVisu.FamilyMeshOnEntity(theResult,aMeshName,anEntity,anFamilyName)
423 if aMesh is None : print "Error"
426 theView.DisplayOnly(aMesh)
428 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + anFamilyName + "." + thePictureExt
429 aPictureName = re.sub("\s+","_", aPictureName);
430 theView.SavePicture(aPictureName)
432 aMesh.RemoveFromStudy()
434 aVISUObjList.append(aMesh)
436 if aFolderName == 'Groups' :
437 aGroupIter = myLocalStudy.NewChildIterator(aFolderSObj);
438 while aGroupIter.More() :
439 aGroupSObj = aGroupIter.Value()
441 anAttr = aGroupSObj.FindAttribute("AttributeName")[1]
442 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
443 aGroupName = anAttr.Value()
444 if HasValue(thePrsTypeList,VISU.TMESH) :
445 print " ", aGroupName,
446 aMesh = theVisu.GroupMesh(theResult,aMeshName,aGroupName)
447 if aMesh is None : print "Error"
450 theView.DisplayOnly(aMesh)
452 aPictureName = thePictureDir + aMeshNamePic + "_" + aGroupName + "." + thePictureExt
453 aPictureName = re.sub("\s+","_", aPictureName);
454 theView.SavePicture(aPictureName)
456 aMesh.RemoveFromStudy()
458 aVISUObjList.append(aMesh)
460 if aFolderName == 'Fields' :
461 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
462 while aFieldIter.More() :
463 aFieldSObj = aFieldIter.Value()
465 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
466 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
467 aFieldName = anAttr.Value()
468 print " ", aFieldName
470 anAttr = aFieldSObj.FindAttribute("AttributeString")[1]
471 anAttr = anAttr._narrow(SALOMEDS.AttributeString);
472 aFieldComment = anAttr.Value()
473 aMap = StrToMap(aFieldComment)
475 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
476 if aTimeStampIter.More() :
477 aTimeStampIter.Next()
478 while aTimeStampIter.More() :
479 aTimeStampSObj = aTimeStampIter.Value()
480 aTimeStampIter.Next()
481 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
482 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
483 aTimeStampName = anAttr.Value()
484 print " ", aTimeStampName
486 anAttr = aTimeStampSObj.FindAttribute("AttributeString")[1]
487 anAttr = anAttr._narrow(SALOMEDS.AttributeString);
488 aTimeStampComment = anAttr.Value()
489 aMap = StrToMap(aTimeStampComment)
490 aMeshName = aMap["myMeshName"]
491 aFieldName = aMap["myFieldName"]
492 aTimeStampId = atoi(aMap["myTimeStampId"])
493 anEntity = IntToEntity(aMap["myEntityId"])
494 anEntityId = str(aMap["myEntityId"]);
495 #print aMeshName, aFieldName, anEntity, aTimeStampId
496 if HasValue(thePrsTypeList,VISU.TSCALARMAP) :
497 print " Creating ScalarMapOnField",
498 aPrsObj = theVisu.ScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
499 if aPrsObj is None : print "Error"
502 theView.DisplayOnly(aPrsObj)
504 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAP." + thePictureExt
505 aPictureName = re.sub("\s+","_", aPictureName);
506 theView.SavePicture(aPictureName)
508 aPrsObj.RemoveFromStudy()
510 aVISUObjList.append(aPrsObj)
512 if HasValue(thePrsTypeList,VISU.TISOSURFACES) :
513 print " Creating IsoSurfacesOnField",
514 aPrsObj = theVisu.IsoSurfacesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
515 if aPrsObj is None : print "Error"
518 theView.DisplayOnly(aPrsObj)
520 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TISOSURFACES." + thePictureExt
521 aPictureName = re.sub("\s+","_", aPictureName);
522 theView.SavePicture(aPictureName)
524 aPrsObj.RemoveFromStudy()
526 aVISUObjList.append(aPrsObj)
528 if HasValue(thePrsTypeList,VISU.TCUTPLANES) :
529 print " Creating CutPlanesOnField",
530 aPrsObj = theVisu.CutPlanesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
531 if aPrsObj is None : print "Error"
534 aPrsObj.SetOrientation(VISU.CutPlanes.ZX,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
535 theView.DisplayOnly(aPrsObj)
537 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTPLANES." + thePictureExt
538 aPictureName = re.sub("\s+","_", aPictureName)
539 theView.SavePicture(aPictureName)
541 aPrsObj.RemoveFromStudy()
543 aVISUObjList.append(aPrsObj)
545 if HasValue(thePrsTypeList,VISU.TCUTLINES) :
546 print " Creating CutLinesOnField",
547 aPrsObj = theVisu.CutLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
548 if aPrsObj is None : print "Error"
551 aPrsObj.SetOrientation(VISU.CutPlanes.XY,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
552 aPrsObj.SetOrientation2(VISU.CutPlanes.ZX,aPrsObj.GetRotateX2(),aPrsObj.GetRotateY2())
553 theView.DisplayOnly(aPrsObj)
555 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTLINES." + thePictureExt
556 aPictureName = re.sub("\s+","_", aPictureName)
557 theView.SavePicture(aPictureName)
559 aPrsObj.RemoveFromStudy()
561 aVISUObjList.append(aPrsObj)
563 if HasValue(thePrsTypeList,VISU.TCUTSEGMENT) :
564 print " Creating CutSegmentOnField",
565 aPrsObj = theVisu.CutSegmentOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
566 if aPrsObj is None : print "Error"
569 theView.DisplayOnly(aPrsObj)
571 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTSEGMENT." + thePictureExt
572 aPictureName = re.sub("\s+","_", aPictureName)
573 theView.SavePicture(aPictureName)
575 aPrsObj.RemoveFromStudy()
577 aVISUObjList.append(aPrsObj)
579 if HasValue(thePrsTypeList,VISU.TPLOT3D) :
580 print " Creating Plot3DOnField",
581 aPrsObj = theVisu.Plot3DOnField(theResult,aMeshName,anEntity,
582 aFieldName,aTimeStampId)
583 if aPrsObj is None : print "Error"
586 #aPrsObj.SetOrientation(VISU.CutPlanes.ZX,
587 # aPrsObj.GetRotateX(),
588 # aPrsObj.GetRotateY())
589 theView.DisplayOnly(aPrsObj)
591 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TPLOT3D." + thePictureExt
592 aPictureName = re.sub("\s+","_", aPictureName)
593 theView.SavePicture(aPictureName)
595 aPrsObj.RemoveFromStudy()
597 aVISUObjList.append(aPrsObj)
599 aNumComponent = atoi(aMap["myNumComponent"])
600 if aNumComponent > 1 :
601 if HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPE) :
602 print " Creating DeformedShapeOnField",
603 aPrsObj = theVisu.DeformedShapeOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
604 if aPrsObj is None : print "Error"
607 theView.DisplayOnly(aPrsObj)
609 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPE." + thePictureExt
610 aPictureName = re.sub("\s+","_", aPictureName)
611 theView.SavePicture(aPictureName)
613 aPrsObj.RemoveFromStudy()
615 aVISUObjList.append(aPrsObj)
617 if HasValue(thePrsTypeList,VISU.TVECTORS) :
618 print " Creating VectorsOnField",
619 aPrsObj = theVisu.VectorsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
620 if aPrsObj is None : print "Error"
623 theView.DisplayOnly(aPrsObj)
625 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TVECTORS." + thePictureExt
626 aPictureName = re.sub("\s+","_", aPictureName)
627 theView.SavePicture(aPictureName)
629 aPrsObj.RemoveFromStudy()
631 aVISUObjList.append(aPrsObj)
633 if HasValue(thePrsTypeList,VISU.TSTREAMLINES) :
634 print " Creating StreamLinesOnField",
635 aPrsObj = theVisu.StreamLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
636 if aPrsObj is None : print "Error"
639 theView.DisplayOnly(aPrsObj)
641 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSTREAMLINES." + thePictureExt
642 aPictureName = re.sub("\s+","_", aPictureName)
643 theView.SavePicture(aPictureName)
645 aPrsObj.RemoveFromStudy()
647 aVISUObjList.append(aPrsObj)
649 if HasValue(thePrsTypeList,VISU.TSCALARMAPONDEFORMEDSHAPE) or HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPEANDSCALARMAP) :
650 print " Creating DeformedShapeAndScalarMapOnField",
651 aPrsObj = theVisu.DeformedShapeAndScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
652 if aPrsObj is None : print "Error"
655 theView.DisplayOnly(aPrsObj)
657 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPEANDSCALARMAP." + thePictureExt
658 aPictureName = re.sub("\s+","_", aPictureName)
659 theView.SavePicture(aPictureName)
661 aPrsObj.RemoveFromStudy()
663 aVISUObjList.append(aPrsObj)
665 if HasValue(thePrsTypeList,VISU.TGAUSSPOINTS) :
666 print " Creating GaussPointsOnField",
667 aPrsObj = theVisu.GaussPointsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
668 if aPrsObj is None : print "Error"
671 theView.DisplayOnly(aPrsObj)
673 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TGAUSSPOINTS." + thePictureExt
674 aPictureName = re.sub("\s+","_", aPictureName)
675 theView.SavePicture(aPictureName)
677 aPrsObj.RemoveFromStudy()
680 aVISUObjList.append(aPrsObj)
688 def generateName(prefix = None):
690 int = whrandom.randint(1,1000);
692 return "Study" + str(int)
694 return prefix + str(int)
698 # ----------------------
700 # ----------------------
701 def try_mesh_parameters(theMeshPattern):
703 if theMeshPattern is None : return aResult ;
704 theMeshPattern = theMeshPattern._narrow(VISU.Mesh)
705 if theMeshPattern is None : return aResult ;
707 aTYPES = [VISU.POINT, VISU.WIREFRAME, VISU.SHADED, VISU.INSIDEFRAME, VISU.SHRINK]
708 import copy; import os;
710 aNewMesh = copy.deepcopy(theMeshPattern);
711 aNewMesh.SetPresentationType(ind)
712 aResult.append(aNewMesh)
717 # ----------------------------
719 # ----------------------------
721 def try_scalarmap_parameters(thePattern, dump = 0):
723 if thePattern is None : return None
725 SCALING = [VISU.LINEAR, VISU.LOGARITHMIC]
729 anObj = thePattern#copy.deepcopy(thePattern);
730 #ind = random.randint(1,2)
732 #try incorrect value deliberately (but allowed by idl description)
733 #try SetScalarMode(long)
734 mode = random.randint(-100000,100000); #incorrect value deliberately
736 #correct value of ScalarMode
737 mode = random.randint(0, 3)
739 if dump : print "\tSetScalarMode(" + str(mode) +")"
740 anObj.SetScalarMode(mode)
743 scal = random.randint(0,1)
744 if dump : print "\tSetScaling(" + str(SCALING[scal]) +")"
745 anObj.SetScaling(SCALING[scal])
749 alfa = random.random()*random.randint(-100000,100000)
750 betta = random.random()*random.randint(-100000,100000)
751 aMin = alfa; aMax = betta
754 aPMin = thePattern.GetMin()
755 aPMax = thePattern.GetMax()
757 alfa = random.random()%0.5
758 betta = random.random()%0.5
759 aMin = alfa*aLen*random.randint(-1,1) + aPMin
760 aMax = betta*aLen*random.randint(-1,1) + aPMax
761 if dump : print "\tSetRange(" + str(aMin) + ", " + str(aMax) + ")"
762 anObj.SetRange(aMin, aMax)
766 X=random.random()*random.randint(-100000,100000)
767 Y=random.random()*random.randint(-100000,100000)
771 if dump : print "SetPosition("+ str(X) + ", " + str(Y) + " )"
772 anObj.SetPosition(X, Y)
774 # --- SCALAR BAR SIZE ---
776 aWidth=random.random()*random.randint(-100000,100000)
777 aHeight=random.random()*random.randint(-100000,100000)
779 aWidth=random.random()
780 aHeight=random.random()
781 if dump : print " SCALAR BAR Width = " + str(aWidth) + " Height = ", str(aHeight)
782 anObj.SetSize(aWidth, aHeight)
787 def dump_scalarmap_parameters(anObj):
789 print "\tGetScalarMode() = " + str(anObj.GetScalarMode())
790 print "\tGetScaling() = " + str(anObj.GetScaling())
791 print "\tGetMin() = " + str(anObj.GetMin()) + " GetMax() = " + str (anObj.GetMax())
792 print "\tGetOrientation() = " + str(anObj.GetOrientation())
793 print "\tGetPosX() = ", str(anObj.GetPosX()) + " GetPosY() = ", str(anObj.GetPosY())
794 print "\tGetWidth() = ", str ( anObj.GetWidth()) + " GetHeight() = " + str(anObj.GetHeight())
796 # ----------------------
798 # ----------------------
799 def try_deformedshape_parameters(thePattern) :
801 if thePattern is None : return None
805 anObj = try_scalarmap_parameters(thePattern)
809 anObj.SetScale( random.random()*random.randint(-100000, 100000))
811 anObj.SetScale( anObj.GetScale()*random.random())
816 def dump_deformedshape_parameters(theObject):
817 dump_scalarmap_parameters(theObject)
818 print "GetScale() = ", theObject.GetScale()
820 # ----------------------
822 # ----------------------
823 def try_cutplanes_parameters(thePattern) :
825 if thePattern is None : return None
829 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
831 ind = random.randint(1,2)
832 anObj = try_scalarmap_parameters(thePattern)
834 if ind%2 : anObj.SetNbPlanes(random.randint(-40,40))
835 else : anObj.SetNbPlanes(random.randint(0,10)) #try behaivor if NbPlanes=0
837 # --- DISPLACEMENT ---
838 anObj.SetDisplacement(random.randint(-100000,100000))
840 # --- PLANE POSITION ---
842 PlaneNb = random.randint(-100000,100000) #incorrect value is possible
843 else : PlaneNb = random.randint(0, anObj.GetNbPlanes())
845 anObj.SetPlanePosition(PlaneNb, random.random()*random.randint(-100000,100000))
847 # --- SET DEFAULT ---
848 anObj.SetDefault(PlaneNb)
850 # --- SET X,Y,Z ROTATION ---
852 angle1 = random.random()*random.randint(-100000,100000)
853 angle2 = random.random()*random.randint(-100000,100000)
855 angle1 = random.random()*3.14
856 angle2 = random.random()*3.14
858 # --- ORIENTATION ---
859 anObj.SetOrientation(ORIENT[random.randint(0,2)],angle1,angle2)
863 def dump_cutplanes_parameters(theObject):
864 dump_saclarmap_parameters(theObject)
866 print "GetOrientationType = " + str(theObject.GetOrientationType())
867 PlanesNb = theObject.GetNbPlanes()
868 print "GetNbPlanes() = ", str(PlanesNb)
869 for i in range(0,PlanesNb+1):
870 if theObject.IsDefault(i) :
871 print "Default plane : "+str(i); break
872 print "GetPlanePosition(" + str(i) + ") = ", theObject.GetPlanePosition(i)
873 print "GetDisplacement() = ", str(theObject.GetDisplacement())
874 print "GetRotateX() = ", str(theObject.GetRotateX())
875 print "GetRotateY() = ", str(theObject.GetRotateY())
876 print "GetRotateZ() = ", str(theObject.GetRotateZ())
878 # ----------------------
880 # ----------------------
881 def try_cutlines_parameters(thePattern):
883 if thePattern is None : return None
887 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
888 ind = random.randint(1,2)
889 anObj = try_scalarmap_parameters(thePattern)
891 # --- ORIENTATION ---
892 anObj.SetOrientation(ORIENT[random.randint(0,2)],
893 random.randint(-100,100)*random.random(),
894 random.randint(-100,100)*random.random())
895 anObj.SetOrientation2(ORIENT[random.randint(0,2)],
896 random.randint(-100,100)*random.random(),
897 random.randint(-100,100)*random.random())
899 # --- Base Plane Position ---
900 anObj.SetBasePlanePosition( random.random()*random.randint(-100000,100000))
902 # --- NUMBER OF LINES ---
904 anObj.SetNbLines(random.randint(-5, 50))
908 def dump_cutlines_parameters(theObject):
909 dump_scalarmap_parameters(theObject)
911 print "GetOrientationType() = " + str(theObject.GetOrientationType())
912 print "GetOrientationType2() = " + str(theObject.GetOrientationType2())
913 print "GetBasePlanePosition() = "+ str(theObject.GetBasePlanePosition())
914 print "GetNbLines() = " + str(theObject.GetNbLines())
915 print "GetRotateX() = ", str(theObject.GetRotateX())
916 print "GetRotateX2() = ", str(theObject.GetRotateX2())
917 print "GetRotateY() = ", str(theObject.GetRotateY())
918 print "GetRotateY2() = ", str(theObject.GetRotateY2())
920 # ----------------------
922 # ----------------------
923 def try_cutsegment_parameters(thePattern):
925 if thePattern is None : return None
929 anObj = try_scalarmap_parameters(thePattern)
931 anObj.SetPoint1(random.randint(-100,100)*random.random(),
932 random.randint(-100,100)*random.random(),
933 random.randint(-100,100)*random.random())
934 anObj.SetPoint2(random.randint(-100,100)*random.random(),
935 random.randint(-100,100)*random.random(),
936 random.randint(-100,100)*random.random())
940 def dump_cutsegment_parameters(theObject):
941 dump_scalarmap_parameters(theObject)
945 theObject.GetPoint1(x1, y1, z1)
946 theObject.GetPoint1(x2, y2, z2)
947 print "GetPoint1() = " + str(x1) + ", " + str(y1) + ", " + str(z1)
948 print "GetPoint2() = " + str(x2) + ", " + str(y2) + ", " + str(z2)
950 # ----------------------
952 # ----------------------
953 def try_streamlines_parameters(thePattern):
955 if thePattern is None : return None
959 DIRECTION = [VISU.StreamLines.FORWARD, VISU.StreamLines.BACKWARD, VISU.StreamLines.BOTH]
961 ind = random.randint(1,2)
962 anObj = (try_deformedshape_parameters(thePattern))[0]
965 anObj.SetDirection(DIRECTION[random.randint(0,2)])
967 # --- STEP LENGTH ---
968 if ind%2 : anObj.SetStepLength(random.random()*random.randint(-1000,1000))
970 aLen = anObj.GetMax() - anObj.GetMin()
971 anObj.SetStepLength(aLen/random.randint(1,100))
973 # --- PROPAGATION TIME ---
974 anObj.SetPropagationTime(random.random()*random.randint(1,100))
976 # --- INTEGRATION STEP ---
978 anObj.SetIntegrationStep(random.random()*random.randint(-1000,1000))
980 anObj.SetIntegrationStep(random.random())
983 anObj.SetUsedPoints(random.random()*random.randint(-10000,10000))
987 def dump_streamlines_parameters(theObject):
989 dump_deformedshape_parameters(theObject)
991 print "GetDirection() = " + str(theObject.GetDirection())
992 print "GetStepLength() = " + str(theObject.GetStepLength())
993 print "GetPropagationTime() =" + str(theObject.GetPropagationTime())
994 print "GetIntegrationStep() =" + str(theObject.GetIntegrationStep())
995 print "GetUsedPoints() =" + str(theObject.GetUsedPoints())
997 # ----------------------
999 # ----------------------
1000 def try_vectors_parameters(thePattern, theNum):
1002 if thePattern is None : return None
1005 GLIPH_TYPE = [VISU.Vectors.ARROW, VISU.Vectors.CONE2, VISU.Vectors.CONE6, VISU.Vectors.NONE]
1006 GLIPH_POS = [VISU.Vectors.CENTER, VISU.Vectors.TAIL, VISU.Vectors.HEAD]
1007 ind = random.randint(1,2)
1008 anObj = (try_deformedshape_parameters(thePattern))[0]
1010 # --- LINE WIDTH ---
1012 anObj.SetLineWidth(random.random()*random.randint(-10000,10000))
1014 anObj.SetLineWidth(random.randint(1, 10))
1016 # --- GLIPH TYPE ---
1017 anObj.SetGlyphType(GLIPH_TYPE[random.randint(0, len(GLIPH_TYPE)-1)])
1020 anObj.SetGlyphPos(GLIPH_POS[random.randint(0, len(GLIPH_POS)-1)])
1024 def dump_vectors_parameters(theObject):
1026 dump_deformedshape_parameters(theObject)
1028 print "GetLineWidth() = " +str(theObject.GetLineWidth())
1029 print "GetGlyphType() = " +str(theObject.GetGlyphType())
1030 print "GetGlyphPos() = " +str(theObject.GetGlyphPos())
1033 # ----------------------
1035 # ----------------------
1037 def try_isosurfaces_parameters(thePattern) :
1038 if thePattern is None : return None
1042 anObj = try_scalarmap_parameters(thePattern)
1043 ind = random.randint(1,2)
1044 # --- SURFACES NUMBER ---
1046 anObj.SetNbSurfaces(random.randint(-100000,100000))
1048 anObj.SetNbSurfaces(random.randint(1, 50))
1052 def dump_isosurfaces_parameters(theObject):
1054 dump_scalarmap_parameters(theObject)
1055 print "GetNbSurfaces() = "+ str(theObject.GetNbSurfaces())
1057 # ----------------------------
1058 # SCALAR MAP ON DEFORMED SHAPE
1059 # ----------------------------
1060 def dump_scalarmapondeformedshape_parameters(theObject):
1061 dump_scalarmap_parameters(theObject)
1062 print "GetScale() =", theObject.GetScale()
1063 print "GetScalarCMeshName ()=|",theObject.GetScalarCMeshName(),"|"
1064 print "GetScalarCFieldName()=|",theObject.GetScalarCFieldName(),"|"
1065 print "GetScalarEEntity() =",theObject.GetScalarEEntity()
1066 print "GetScalarLIteration()=",theObject.GetScalarLIteration()
1069 def try_scalarmapondeformedshape_parameters(thePattern):
1071 if thePattern is None : return None
1075 anObj = try_scalarmap_parameters(thePattern)
1079 anObj.SetScale( anObj.GetScale()/random.random()*random.randint(1,10))
1081 # --- Scalar Field ---
1082 # not implemented yet.
1085 # ----------------------
1087 # ----------------------
1088 def dump_plot3d_parameters(theObject):
1089 dump_scalarmap_parameters(theObject)
1090 print "GetOrientationType()=",str(theObject.GetOrientationType())
1091 print "GetRotateX()=",theObject.GetRotateX()
1092 print "GetRotateY()=",theObject.GetRotateY()
1093 print "GetPlanePosition()=",theObject.GetPlanePosition()
1094 print "IsPositionRelative()=",theObject.IsPositionRelative()
1095 print "GetScaleFactor()=",theObject.GetScaleFactor()
1096 print "GetIsContourPrs()=",theObject.GetIsContourPrs()
1097 print "GetNbOfContours()=",theObject.GetNbOfContours()
1100 def try_plot3d_parameters(thePattern):
1101 if thePattern is None : return None
1104 anObj = try_scalarmap_parameters(thePattern)
1106 ORIENT = [VISU.Plot3D.XY, VISU.Plot3D.YZ, VISU.Plot3D.ZX]
1108 theXAngle = random.random()*random.randint(-180,180)
1109 theYAngle = random.random()*random.randint(-180,180)
1111 # ORIENTATION and ANGLES
1112 anObj.SetOrientation(ORIENT[random.randint(0,2)],theXAngle,theYAngle)
1114 # Plane position (revative)
1115 anObj.SetPlanePosition(random.random(),1)
1118 anObj.SetScaleFactor(random.random()*random.randint(-10000,10000))
1121 anObj.SetContourPrs(random.randint(0,1))
1122 if anObj.GetIsContourPrs():
1123 anObj.SetNbOfContours(random.randint(1,999))
1128 # ----------------------
1130 # ----------------------
1131 def dump_gausspoints_parameters(theObject):
1133 print "\tGetScalarMode() = " + str(anObj.GetScalarMode())
1134 print "\tGetMin() = " + str(anObj.GetMin()) + " GetMax() = " + str (anObj.GetMax())
1135 print "\tGetPosX() = ", str(anObj.GetPosX()) + " GetPosY() = ", str(anObj.GetPosY())
1136 print "\tGetWidth() = ", str ( anObj.GetWidth()) + " GetHeight() = " + str(anObj.GetHeight())
1137 print "\tGetNbColors() = " + str(anObj.GetNbColors())
1138 print "\tGetLabels() = " + str(anObj.GetLabels())
1139 print "\tGetTitle() = " + str(anObj.GetTitle())
1142 def try_plot3d_parameters(thePattern):
1143 if thePattern is None : return None
1148 # ----------------------
1150 # ----------------------
1152 def FillTable( theTable, theValues, theRows, theColumns, theRowTitles, theRowUnits, theColumnTitles ):
1153 if theTable is None: return
1154 if len(theRows) != len(theColumns): return
1155 if len(theRows) != len(theValues): return
1157 for value in theValues:
1158 theTable.PutValue( value, theRows[ i ], theColumns[ i ])
1162 for title in theRowTitles:
1163 theTable.SetRowTitle( i, title )
1164 theTable.SetRowUnit( i, theRowUnits[ i - 1 ])
1168 for title in theColumnTitles:
1169 theTable.SetColumnTitle( i, title )
1174 def CreateCurve( theTable, theHRow, theVRow, theTitle, theColor, theMarker, theLineType, theLineWidth ):
1175 if theTitle is None: return
1176 curve = myLocalVisu.CreateCurve( theTable, theHRow, theVRow );
1178 curve.SetTitle( theTitle )
1179 curve.SetColor( theColor )
1180 curve.SetMarker( theMarker )
1181 curve.SetLine( theLineType, theLineWidth )