1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2011 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
24 # VISU VISU_SWIG : binding of C++ implementation and Python
30 from time import sleep
34 import SALOME_Session_idl
37 import SALOME_ModuleCatalog
38 from omniORB import CORBA
40 from time import sleep
43 myNamingService = None
44 myLifeCycleCORBA = None
45 myNamingService = None
46 myLocalStudyManager = None
52 def Initialize(theORB, theNamingService, theLifeCycleCORBA, theStudyManager, theStudy, theDelay) :
53 global myORB, myNamingService, myLifeCycleCORBA, myLocalStudyManager, myLocalStudy
54 global mySession, myLocalVisu, myDelay
57 myNamingService = theNamingService
58 myLifeCycleCORBA = theLifeCycleCORBA
59 myLocalStudyManager = theStudyManager
60 while mySession == None:
61 mySession = myNamingService.Resolve("/Kernel/Session")
62 mySession = mySession._narrow(SALOME.Session)
63 mySession.GetInterface()
66 myLocalVisu = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "VISU")
67 myLocalStudy = theStudy
68 myLocalVisu.SetCurrentStudy(myLocalStudy)
71 def PublishComponent(theStudyDocument):
72 aComponentDataType = myLocalVisu.ComponentDataType()
73 aSComponent = theStudyDocument.FindComponent(aComponentDataType)
74 if aSComponent == None:
75 aStudyBuilder = theStudyDocument.NewBuilder()
76 aStudyBuilder.NewCommand()
77 aLocked = theStudyDocument.GetProperties().IsLocked()
79 theStudyDocument.GetProperties().SetLocked(0)
82 aSComponent = aStudyBuilder.NewComponent(aComponentDataType);
83 aName = aStudyBuilder.FindOrCreateAttribute(aSComponent,"AttributeName")
84 aModuleCatalogObj = myNamingService.Resolve("/Kernel/ModulCatalog");
85 aModuleCatalog = aModuleCatalogObj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
86 aComponent = aModuleCatalog.GetComponent(aComponentDataType);
87 if aComponent != None:
88 aComponentUserName = aComponent._get_componentusername()
89 aName.SetValue(aComponentUserName)
92 aPixMap = aStudyBuilder.FindOrCreateAttribute(aSComponent,"AttributePixMap")
93 aPixMap.SetPixMap("ICON_OBJBROWSER_Visu")
95 aStudyBuilder.DefineComponentInstance(aSComponent,myLocalVisu);
97 theStudyDocument.GetProperties().SetLocked(1);
100 aStudyBuilder.CommitCommand();
105 def SetName(theObj, theName):
106 anIOR = myORB.object_to_string(theObj)
107 aSObj = myLocalStudy.FindObjectIOR(anIOR)
108 anAttr = aSObj.FindAttribute("AttributeName")[1]
109 anAttr.SetValue(theName)
111 def StrToMap(theString) :
112 aPairList = split(theString,";")
114 iEnd = len(aPairList)
115 for i in range(iEnd) :
116 aPair = split(aPairList[i],"=")
117 aMap[aPair[0]] = aPair[1]
120 def IntToEntity(theInt) :
121 theInt = atoi(theInt)
131 def HasValue(theList, theValue) :
133 return theList.index(theValue) + 1
134 except StandardError, e :
137 def CreateStudyForMed(theVisu, theFileName) :
138 print "CreateStudyForMed ", theFileName,
139 if os.path.isfile(theFileName) :
140 if re.search("\.med$", theFileName) is not None :
142 aStudyName = os.path.basename(theFileName)
143 aStudyName = re.sub(r'\.med', "", aStudyName)
144 aStudyName = generateName(aStudyName)
145 print "myLocalStudyManager.NewStudy -", aStudyName, "...",
146 aStudy = myLocalStudyManager.NewStudy(aStudyName)
147 if aStudy is None : raise RuntimeError, "Error"
150 print "CreateStudyForMed - Creating a 3D viewer...",
151 theVisu.SetCurrentStudy(aStudy)
152 myViewManager = theVisu.GetViewManager()
153 if myViewManager is None : raise RuntimeError, "Error - theVisu.GetViewManager"
154 myView = myViewManager.Create3DView()
155 if myView is None : raise RuntimeError, "Error - myViewManager.Create3DView"
159 return [aStudy, myViewManager, myView]
160 raise RuntimeError, "Error: There is no such file."
162 def getMedSObject(theStudy = myLocalStudy ):
164 theStudy = myLocalStudy
165 aSO = theStudy.FindObject("Med")
166 anIsPresetn, aSObject = aSO.FindSubObject(1)
169 def getMedObjectFromStudy(theStudy = myLocalStudy):
170 aSObject = getMedSObject(theStudy)
172 anAttr = aSObject.FindAttribute("AttributeIOR")[1]
173 anObj = myORB.string_to_object(anAttr.Value())
174 return anObj._narrow(SALOME_MED.MED)
177 def getFieldObjectFromStudy(number, subnumber, theStudy = myLocalStudy):
179 theStudy = myLocalStudy
180 mySO = theStudy.FindObject("MEDFIELD")
182 raise Runtime, "getFieldObjectFromStudy mySO is None"
183 mysub = mySO.FindSubObject(number)[1]
185 mysubsub = mysub.FindSubObject(subnumber)[1]
187 Builder = theStudy.NewBuilder()
188 anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
189 obj = myORB.string_to_object(anAttr.Value())
190 myObj = obj._narrow(SALOME_MED.FIELDINT)
192 myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
195 print "ERROR: No Field Object stored in this Study"
198 def getSObjectByFatherPathAndName(theStudy, thePath, theName):
199 father = theStudy.FindObjectByPath(thePath)
200 itr = theStudy.NewChildIterator(father)
203 if so.GetName()==theName: return so
208 def SObjectToObject(theSObject) :
210 if theSObject is None :
211 print "SObjectToObject : argument is None"
213 res,Attr = theSObject.FindAttribute("AttributeIOR")
214 if (res != 0) and (Attr is not None) :
215 anIOR = Attr._narrow(SALOMEDS.AttributeIOR);
216 aValue = anIOR.Value();
217 if(len(aValue) != 0) :
218 anObj = myORB.string_to_object(aValue);
220 print "SObjectToObject - IOR = ''"
223 def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
225 global myLifeCycleCORBA
226 print "lcc.FindOrLoadComponent...",
227 aMedComp = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "MED")
228 if aMedComp is None : print "Error"
231 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
233 print "aMedComp.readStructFileWithFieldType...",
234 aMedComp.readStructFileWithFieldType(theFileName,myLocalStudy._get_Name())
235 aMedSObj = getMedSObject(myLocalStudy)
236 if aMedSObj is None : raise RuntimeError, "Error"
239 print "theVisu.ImportMed...",
240 aResult = theVisu.ImportMed(aMedSObj)
241 if aResult is None : raise RuntimeError, "Error"
244 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
246 aResult.RemoveFromStudy()
248 aVISUObjList.append(aResult)
250 aFolderIter = myLocalStudy.NewChildIterator(aMedSObj.GetFather());
251 while aFolderIter.More() :
252 aFolderSObj = aFolderIter.Value()
254 anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
255 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
256 aFolderName = anAttr.Value()
257 print " ", aFolderName
259 if aFolderName == 'MEDMESH' :
260 aMeshIter = myLocalStudy.NewChildIterator(aFolderSObj);
261 while aMeshIter.More() :
262 aMeshSObj = aMeshIter.Value()
264 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
265 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
266 aMeshName = anAttr.Value()
269 aSupportIter = myLocalStudy.NewChildIterator(aMeshSObj);
270 while aSupportIter.More() :
271 aSupportSObj = aSupportIter.Value()
273 anAttr = aSupportSObj.FindAttribute("AttributeName")[1]
274 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
275 aSupportName = anAttr.Value()
276 print " ", aSupportName
278 if aFolderName == 'MEDFIELD' :
279 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
280 while aFieldIter.More() :
281 aFieldSObj = aFieldIter.Value()
283 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
284 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
285 aFieldName = anAttr.Value()
286 print " ", aFieldName
288 print "theVisu.ImportMed...",
289 aResult = theVisu.ImportMed(aFieldSObj)
290 if aResult is None : raise RuntimeError, "Error"
293 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
295 aResult.RemoveFromStudy()
297 aVISUObjList.append(aResult)
299 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
300 if aTimeStampIter.More() :
301 aTimeStampIter.Next()
302 while aTimeStampIter.More() :
303 aTimeStampSObj = aTimeStampIter.Value()
304 aTimeStampIter.Next()
305 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
306 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
307 aTimeStampName = anAttr.Value()
308 print " ", aTimeStampName
310 print "theVisu.ImportMed...",
311 aMedField = SObjectToObject(aTimeStampSObj)
312 aResult = theVisu.ImportMedField(aMedField)
313 if aResult is None : raise RuntimeError, "Error"
316 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
318 aResult.RemoveFromStudy()
320 aVISUObjList.append(aResult)
324 # except Exception, e:
327 def CreatePrsForFile(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
329 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
331 print "theVisu.ImportMed...",
332 aResult = theVisu.ImportFile(theFileName)
333 if aResult is None : raise RuntimeError, "Error"
336 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
339 aResult.RemoveFromStudy()
341 aVISUObjList.append(aResult)
345 # except Exception, e:
348 def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
350 if theIsAutoDelete is not None :
354 print "CreatePrsForResult - myLocalStudy.FindObjectIOR...",
355 myLocalStudy = theVisu.GetCurrentStudy()
357 aSObj = myLocalStudy.FindObjectIOR(theResult.GetID())
358 if aSObj is None : raise RuntimeError, "Error"
360 aMeshIter = myLocalStudy.NewChildIterator(aSObj);
361 while aMeshIter.More() :
362 aMeshSObj = aMeshIter.Value()
364 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
366 aMeshSObj = aMeshIter.Value()
368 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
369 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
370 aMeshName = anAttr.Value()
371 aMeshNamePic = re.sub(".","_",aMeshName)
374 aFolderIter = myLocalStudy.NewChildIterator(aMeshSObj);
375 while aFolderIter.More() :
376 aFolderSObj = aFolderIter.Value()
378 anIsFound, anAttr = aFolderSObj.FindAttribute("AttributeName")
381 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
382 aFolderName = anAttr.Value()
383 print " ", aFolderName
385 if aFolderName == 'Families' :
386 anEntityIter = myLocalStudy.NewChildIterator(aFolderSObj);
387 while anEntityIter.More() :
388 anEntitySObj = anEntityIter.Value()
390 anAttr = anEntitySObj.FindAttribute("AttributeName")[1]
391 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
392 anEntityName = anAttr.Value()
395 if anEntityName == 'onNodes' :
398 if anEntityName == 'onEdges' :
401 if anEntityName == 'onFaces' :
404 if anEntityName == 'onCells' :
408 if HasValue(thePrsTypeList,VISU.TMESH) :
409 print " ", anEntityName, aMeshName,
410 aMesh = theVisu.MeshOnEntity(theResult,aMeshName,anEntity)
411 if aMesh is None : print "Error"
414 theView.DisplayOnly(aMesh)
416 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "." + thePictureExt
417 aPictureName = re.sub("\s+","_", aPictureName);
418 theView.SavePicture(aPictureName)
420 aMesh.RemoveFromStudy()
422 aVISUObjList.append(aMesh)
424 anFamilyIter = myLocalStudy.NewChildIterator(anEntitySObj);
425 while anFamilyIter.More() :
426 aFamilySObj = anFamilyIter.Value()
428 anAttr = aFamilySObj.FindAttribute("AttributeName")[1]
429 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
430 anFamilyName = anAttr.Value()
431 if HasValue(thePrsTypeList,VISU.TMESH) :
432 print " ", anFamilyName,
433 aMesh = theVisu.FamilyMeshOnEntity(theResult,aMeshName,anEntity,anFamilyName)
434 if aMesh is None : print "Error"
437 theView.DisplayOnly(aMesh)
439 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + anFamilyName + "." + thePictureExt
440 aPictureName = re.sub("\s+","_", aPictureName);
441 theView.SavePicture(aPictureName)
443 aMesh.RemoveFromStudy()
445 aVISUObjList.append(aMesh)
447 if aFolderName == 'Groups' :
448 aGroupIter = myLocalStudy.NewChildIterator(aFolderSObj);
449 while aGroupIter.More() :
450 aGroupSObj = aGroupIter.Value()
452 anAttr = aGroupSObj.FindAttribute("AttributeName")[1]
453 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
454 aGroupName = anAttr.Value()
455 if HasValue(thePrsTypeList,VISU.TMESH) :
456 print " ", aGroupName,
457 aMesh = theVisu.GroupMesh(theResult,aMeshName,aGroupName)
458 if aMesh is None : print "Error"
461 theView.DisplayOnly(aMesh)
463 aPictureName = thePictureDir + aMeshNamePic + "_" + aGroupName + "." + thePictureExt
464 aPictureName = re.sub("\s+","_", aPictureName);
465 theView.SavePicture(aPictureName)
467 aMesh.RemoveFromStudy()
469 aVISUObjList.append(aMesh)
471 if aFolderName == 'Fields' :
472 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
473 while aFieldIter.More() :
474 aFieldSObj = aFieldIter.Value()
476 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
477 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
478 aFieldName = anAttr.Value()
479 print " ", aFieldName
481 anAttr = aFieldSObj.FindAttribute("AttributeString")[1]
482 anAttr = anAttr._narrow(SALOMEDS.AttributeString);
483 aFieldComment = anAttr.Value()
484 aMap = StrToMap(aFieldComment)
486 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
487 if aTimeStampIter.More() :
488 aTimeStampIter.Next()
489 while aTimeStampIter.More() :
490 aTimeStampSObj = aTimeStampIter.Value()
491 aTimeStampIter.Next()
492 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
493 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
494 aTimeStampName = anAttr.Value()
495 print " ", aTimeStampName
497 anAttr = aTimeStampSObj.FindAttribute("AttributeString")[1]
498 anAttr = anAttr._narrow(SALOMEDS.AttributeString);
499 aTimeStampComment = anAttr.Value()
500 aMap = StrToMap(aTimeStampComment)
501 aMeshName = aMap["myMeshName"]
502 aFieldName = aMap["myFieldName"]
503 aTimeStampId = atoi(aMap["myTimeStampId"])
504 anEntity = IntToEntity(aMap["myEntityId"])
505 anEntityId = str(aMap["myEntityId"]);
506 #print aMeshName, aFieldName, anEntity, aTimeStampId
507 if HasValue(thePrsTypeList,VISU.TSCALARMAP) :
508 print " Creating ScalarMapOnField",
509 aPrsObj = theVisu.ScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
510 if aPrsObj is None : print "Error"
513 theView.DisplayOnly(aPrsObj)
515 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAP." + thePictureExt
516 aPictureName = re.sub("\s+","_", aPictureName);
517 theView.SavePicture(aPictureName)
519 aPrsObj.RemoveFromStudy()
521 aVISUObjList.append(aPrsObj)
523 if HasValue(thePrsTypeList,VISU.TISOSURFACES) :
524 print " Creating IsoSurfacesOnField",
525 aPrsObj = theVisu.IsoSurfacesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
526 if aPrsObj is None : print "Error"
529 theView.DisplayOnly(aPrsObj)
531 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TISOSURFACES." + thePictureExt
532 aPictureName = re.sub("\s+","_", aPictureName);
533 theView.SavePicture(aPictureName)
535 aPrsObj.RemoveFromStudy()
537 aVISUObjList.append(aPrsObj)
539 if HasValue(thePrsTypeList,VISU.TCUTPLANES) :
540 print " Creating CutPlanesOnField",
541 aPrsObj = theVisu.CutPlanesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
542 if aPrsObj is None : print "Error"
545 aPrsObj.SetOrientation(VISU.CutPlanes.ZX,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
546 theView.DisplayOnly(aPrsObj)
548 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTPLANES." + thePictureExt
549 aPictureName = re.sub("\s+","_", aPictureName)
550 theView.SavePicture(aPictureName)
552 aPrsObj.RemoveFromStudy()
554 aVISUObjList.append(aPrsObj)
556 if HasValue(thePrsTypeList,VISU.TCUTLINES) :
557 print " Creating CutLinesOnField",
558 aPrsObj = theVisu.CutLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
559 if aPrsObj is None : print "Error"
562 aPrsObj.SetOrientation(VISU.CutPlanes.XY,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
563 aPrsObj.SetOrientation2(VISU.CutPlanes.ZX,aPrsObj.GetRotateX2(),aPrsObj.GetRotateY2())
564 theView.DisplayOnly(aPrsObj)
566 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTLINES." + thePictureExt
567 aPictureName = re.sub("\s+","_", aPictureName)
568 theView.SavePicture(aPictureName)
570 aPrsObj.RemoveFromStudy()
572 aVISUObjList.append(aPrsObj)
574 if HasValue(thePrsTypeList,VISU.TCUTSEGMENT) :
575 print " Creating CutSegmentOnField",
576 aPrsObj = theVisu.CutSegmentOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
577 if aPrsObj is None : print "Error"
580 theView.DisplayOnly(aPrsObj)
582 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTSEGMENT." + thePictureExt
583 aPictureName = re.sub("\s+","_", aPictureName)
584 theView.SavePicture(aPictureName)
586 aPrsObj.RemoveFromStudy()
588 aVISUObjList.append(aPrsObj)
590 if HasValue(thePrsTypeList,VISU.TPLOT3D) :
591 print " Creating Plot3DOnField",
592 aPrsObj = theVisu.Plot3DOnField(theResult,aMeshName,anEntity,
593 aFieldName,aTimeStampId)
594 if aPrsObj is None : print "Error"
597 #aPrsObj.SetOrientation(VISU.CutPlanes.ZX,
598 # aPrsObj.GetRotateX(),
599 # aPrsObj.GetRotateY())
600 theView.DisplayOnly(aPrsObj)
602 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TPLOT3D." + thePictureExt
603 aPictureName = re.sub("\s+","_", aPictureName)
604 theView.SavePicture(aPictureName)
606 aPrsObj.RemoveFromStudy()
608 aVISUObjList.append(aPrsObj)
610 aNumComponent = atoi(aMap["myNumComponent"])
611 if aNumComponent > 1 :
612 if HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPE) :
613 print " Creating DeformedShapeOnField",
614 aPrsObj = theVisu.DeformedShapeOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
615 if aPrsObj is None : print "Error"
618 theView.DisplayOnly(aPrsObj)
620 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPE." + thePictureExt
621 aPictureName = re.sub("\s+","_", aPictureName)
622 theView.SavePicture(aPictureName)
624 aPrsObj.RemoveFromStudy()
626 aVISUObjList.append(aPrsObj)
628 if HasValue(thePrsTypeList,VISU.TVECTORS) :
629 print " Creating VectorsOnField",
630 aPrsObj = theVisu.VectorsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
631 if aPrsObj is None : print "Error"
634 theView.DisplayOnly(aPrsObj)
636 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TVECTORS." + thePictureExt
637 aPictureName = re.sub("\s+","_", aPictureName)
638 theView.SavePicture(aPictureName)
640 aPrsObj.RemoveFromStudy()
642 aVISUObjList.append(aPrsObj)
644 if HasValue(thePrsTypeList,VISU.TSTREAMLINES) :
645 print " Creating StreamLinesOnField",
646 aPrsObj = theVisu.StreamLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
647 if aPrsObj is None : print "Error"
650 theView.DisplayOnly(aPrsObj)
652 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSTREAMLINES." + thePictureExt
653 aPictureName = re.sub("\s+","_", aPictureName)
654 theView.SavePicture(aPictureName)
656 aPrsObj.RemoveFromStudy()
658 aVISUObjList.append(aPrsObj)
660 if HasValue(thePrsTypeList,VISU.TSCALARMAPONDEFORMEDSHAPE) or HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPEANDSCALARMAP) :
661 print " Creating DeformedShapeAndScalarMapOnField",
662 aPrsObj = theVisu.DeformedShapeAndScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
663 if aPrsObj is None : print "Error"
666 theView.DisplayOnly(aPrsObj)
668 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPEANDSCALARMAP." + thePictureExt
669 aPictureName = re.sub("\s+","_", aPictureName)
670 theView.SavePicture(aPictureName)
672 aPrsObj.RemoveFromStudy()
674 aVISUObjList.append(aPrsObj)
676 if HasValue(thePrsTypeList,VISU.TGAUSSPOINTS) :
677 print " Creating GaussPointsOnField",
678 aPrsObj = theVisu.GaussPointsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
679 if aPrsObj is None : print "Error"
682 theView.DisplayOnly(aPrsObj)
684 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TGAUSSPOINTS." + thePictureExt
685 aPictureName = re.sub("\s+","_", aPictureName)
686 theView.SavePicture(aPictureName)
688 aPrsObj.RemoveFromStudy()
691 aVISUObjList.append(aPrsObj)
699 def generateName(prefix = None):
701 int = random.randint(1,1000);
703 return "Study" + str(int)
705 return prefix + str(int)
709 # ----------------------
711 # ----------------------
712 def try_mesh_parameters(theMeshPattern):
714 if theMeshPattern is None : return aResult ;
715 theMeshPattern = theMeshPattern._narrow(VISU.Mesh)
716 if theMeshPattern is None : return aResult ;
718 aTYPES = [VISU.POINT, VISU.WIREFRAME, VISU.SHADED, VISU.INSIDEFRAME, VISU.SHRINK]
719 import copy; import os;
721 aNewMesh = copy.deepcopy(theMeshPattern);
722 aNewMesh.SetPresentationType(ind)
723 aResult.append(aNewMesh)
728 # ----------------------------
730 # ----------------------------
732 def try_scalarmap_parameters(thePattern, dump = 0):
734 if thePattern is None : return None
736 SCALING = [VISU.LINEAR, VISU.LOGARITHMIC]
740 anObj = thePattern#copy.deepcopy(thePattern);
741 #ind = random.randint(1,2)
743 #try incorrect value deliberately (but allowed by idl description)
744 #try SetScalarMode(long)
745 mode = random.randint(-100000,100000); #incorrect value deliberately
747 #correct value of ScalarMode
748 mode = random.randint(0, 3)
750 if dump : print "\tSetScalarMode(" + str(mode) +")"
751 anObj.SetScalarMode(mode)
754 scal = random.randint(0,1)
755 if dump : print "\tSetScaling(" + str(SCALING[scal]) +")"
756 anObj.SetScaling(SCALING[scal])
760 alfa = random.random()*random.randint(-100000,100000)
761 betta = random.random()*random.randint(-100000,100000)
762 aMin = alfa; aMax = betta
765 aPMin = thePattern.GetMin()
766 aPMax = thePattern.GetMax()
768 alfa = random.random()%0.5
769 betta = random.random()%0.5
770 aMin = alfa*aLen*random.randint(-1,1) + aPMin
771 aMax = betta*aLen*random.randint(-1,1) + aPMax
772 if dump : print "\tSetRange(" + str(aMin) + ", " + str(aMax) + ")"
773 anObj.SetRange(aMin, aMax)
777 X=random.random()*random.randint(-100000,100000)
778 Y=random.random()*random.randint(-100000,100000)
782 if dump : print "SetPosition("+ str(X) + ", " + str(Y) + " )"
783 anObj.SetPosition(X, Y)
785 # --- SCALAR BAR SIZE ---
787 aWidth=random.random()*random.randint(-100000,100000)
788 aHeight=random.random()*random.randint(-100000,100000)
790 aWidth=random.random()
791 aHeight=random.random()
792 if dump : print " SCALAR BAR Width = " + str(aWidth) + " Height = ", str(aHeight)
793 anObj.SetSize(aWidth, aHeight)
798 def dump_scalarmap_parameters(anObj):
800 print "\tGetScalarMode() = " + str(anObj.GetScalarMode())
801 print "\tGetScaling() = " + str(anObj.GetScaling())
802 print "\tGetMin() = " + str(anObj.GetMin()) + " GetMax() = " + str (anObj.GetMax())
803 print "\tGetOrientation() = " + str(anObj.GetOrientation())
804 print "\tGetPosX() = ", str(anObj.GetPosX()) + " GetPosY() = ", str(anObj.GetPosY())
805 print "\tGetWidth() = ", str ( anObj.GetWidth()) + " GetHeight() = " + str(anObj.GetHeight())
807 # ----------------------
809 # ----------------------
810 def try_deformedshape_parameters(thePattern) :
812 if thePattern is None : return None
816 anObj = try_scalarmap_parameters(thePattern)
820 anObj.SetScale( random.random()*random.randint(-100000, 100000))
822 anObj.SetScale( anObj.GetScale()*random.random())
827 def dump_deformedshape_parameters(theObject):
828 dump_scalarmap_parameters(theObject)
829 print "GetScale() = ", theObject.GetScale()
831 # ----------------------
833 # ----------------------
834 def try_cutplanes_parameters(thePattern) :
836 if thePattern is None : return None
840 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
842 ind = random.randint(1,2)
843 anObj = try_scalarmap_parameters(thePattern)
845 if ind%2 : anObj.SetNbPlanes(random.randint(-40,40))
846 else : anObj.SetNbPlanes(random.randint(0,10)) #try behaivor if NbPlanes=0
848 # --- DISPLACEMENT ---
849 anObj.SetDisplacement(random.randint(-100000,100000))
851 # --- PLANE POSITION ---
853 PlaneNb = random.randint(-100000,100000) #incorrect value is possible
854 else : PlaneNb = random.randint(0, anObj.GetNbPlanes())
856 anObj.SetPlanePosition(PlaneNb, random.random()*random.randint(-100000,100000))
858 # --- SET DEFAULT ---
859 anObj.SetDefault(PlaneNb)
861 # --- SET X,Y,Z ROTATION ---
863 angle1 = random.random()*random.randint(-100000,100000)
864 angle2 = random.random()*random.randint(-100000,100000)
866 angle1 = random.random()*3.14
867 angle2 = random.random()*3.14
869 # --- ORIENTATION ---
870 anObj.SetOrientation(ORIENT[random.randint(0,2)],angle1,angle2)
874 def dump_cutplanes_parameters(theObject):
875 dump_saclarmap_parameters(theObject)
877 print "GetOrientationType = " + str(theObject.GetOrientationType())
878 PlanesNb = theObject.GetNbPlanes()
879 print "GetNbPlanes() = ", str(PlanesNb)
880 for i in range(0,PlanesNb+1):
881 if theObject.IsDefault(i) :
882 print "Default plane : "+str(i); break
883 print "GetPlanePosition(" + str(i) + ") = ", theObject.GetPlanePosition(i)
884 print "GetDisplacement() = ", str(theObject.GetDisplacement())
885 print "GetRotateX() = ", str(theObject.GetRotateX())
886 print "GetRotateY() = ", str(theObject.GetRotateY())
887 print "GetRotateZ() = ", str(theObject.GetRotateZ())
889 # ----------------------
891 # ----------------------
892 def try_cutlines_parameters(thePattern):
894 if thePattern is None : return None
898 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
899 ind = random.randint(1,2)
900 anObj = try_scalarmap_parameters(thePattern)
902 # --- ORIENTATION ---
903 anObj.SetOrientation(ORIENT[random.randint(0,2)],
904 random.randint(-100,100)*random.random(),
905 random.randint(-100,100)*random.random())
906 anObj.SetOrientation2(ORIENT[random.randint(0,2)],
907 random.randint(-100,100)*random.random(),
908 random.randint(-100,100)*random.random())
910 # --- Base Plane Position ---
911 anObj.SetBasePlanePosition( random.random()*random.randint(-100000,100000))
913 # --- NUMBER OF LINES ---
915 anObj.SetNbLines(random.randint(-5, 50))
919 def dump_cutlines_parameters(theObject):
920 dump_scalarmap_parameters(theObject)
922 print "GetOrientationType() = " + str(theObject.GetOrientationType())
923 print "GetOrientationType2() = " + str(theObject.GetOrientationType2())
924 print "GetBasePlanePosition() = "+ str(theObject.GetBasePlanePosition())
925 print "GetNbLines() = " + str(theObject.GetNbLines())
926 print "GetRotateX() = ", str(theObject.GetRotateX())
927 print "GetRotateX2() = ", str(theObject.GetRotateX2())
928 print "GetRotateY() = ", str(theObject.GetRotateY())
929 print "GetRotateY2() = ", str(theObject.GetRotateY2())
931 # ----------------------
933 # ----------------------
934 def try_cutsegment_parameters(thePattern):
936 if thePattern is None : return None
940 anObj = try_scalarmap_parameters(thePattern)
942 anObj.SetPoint1(random.randint(-100,100)*random.random(),
943 random.randint(-100,100)*random.random(),
944 random.randint(-100,100)*random.random())
945 anObj.SetPoint2(random.randint(-100,100)*random.random(),
946 random.randint(-100,100)*random.random(),
947 random.randint(-100,100)*random.random())
951 def dump_cutsegment_parameters(theObject):
952 dump_scalarmap_parameters(theObject)
956 theObject.GetPoint1(x1, y1, z1)
957 theObject.GetPoint1(x2, y2, z2)
958 print "GetPoint1() = " + str(x1) + ", " + str(y1) + ", " + str(z1)
959 print "GetPoint2() = " + str(x2) + ", " + str(y2) + ", " + str(z2)
961 # ----------------------
963 # ----------------------
964 def try_streamlines_parameters(thePattern):
966 if thePattern is None : return None
970 DIRECTION = [VISU.StreamLines.FORWARD, VISU.StreamLines.BACKWARD, VISU.StreamLines.BOTH]
972 ind = random.randint(1,2)
973 anObj = (try_deformedshape_parameters(thePattern))[0]
976 anObj.SetDirection(DIRECTION[random.randint(0,2)])
978 # --- STEP LENGTH ---
979 if ind%2 : anObj.SetStepLength(random.random()*random.randint(-1000,1000))
981 aLen = anObj.GetMax() - anObj.GetMin()
982 anObj.SetStepLength(aLen/random.randint(1,100))
984 # --- PROPAGATION TIME ---
985 anObj.SetPropagationTime(random.random()*random.randint(1,100))
987 # --- INTEGRATION STEP ---
989 anObj.SetIntegrationStep(random.random()*random.randint(-1000,1000))
991 anObj.SetIntegrationStep(random.random())
994 anObj.SetUsedPoints(random.random()*random.randint(-10000,10000))
998 def dump_streamlines_parameters(theObject):
1000 dump_deformedshape_parameters(theObject)
1002 print "GetDirection() = " + str(theObject.GetDirection())
1003 print "GetStepLength() = " + str(theObject.GetStepLength())
1004 print "GetPropagationTime() =" + str(theObject.GetPropagationTime())
1005 print "GetIntegrationStep() =" + str(theObject.GetIntegrationStep())
1006 print "GetUsedPoints() =" + str(theObject.GetUsedPoints())
1008 # ----------------------
1010 # ----------------------
1011 def try_vectors_parameters(thePattern, theNum):
1013 if thePattern is None : return None
1016 GLIPH_TYPE = [VISU.Vectors.ARROW, VISU.Vectors.CONE2, VISU.Vectors.CONE6, VISU.Vectors.NONE]
1017 GLIPH_POS = [VISU.Vectors.CENTER, VISU.Vectors.TAIL, VISU.Vectors.HEAD]
1018 ind = random.randint(1,2)
1019 anObj = (try_deformedshape_parameters(thePattern))[0]
1021 # --- LINE WIDTH ---
1023 anObj.SetLineWidth(random.random()*random.randint(-10000,10000))
1025 anObj.SetLineWidth(random.randint(1, 10))
1027 # --- GLIPH TYPE ---
1028 anObj.SetGlyphType(GLIPH_TYPE[random.randint(0, len(GLIPH_TYPE)-1)])
1031 anObj.SetGlyphPos(GLIPH_POS[random.randint(0, len(GLIPH_POS)-1)])
1035 def dump_vectors_parameters(theObject):
1037 dump_deformedshape_parameters(theObject)
1039 print "GetLineWidth() = " +str(theObject.GetLineWidth())
1040 print "GetGlyphType() = " +str(theObject.GetGlyphType())
1041 print "GetGlyphPos() = " +str(theObject.GetGlyphPos())
1044 # ----------------------
1046 # ----------------------
1048 def try_isosurfaces_parameters(thePattern) :
1049 if thePattern is None : return None
1053 anObj = try_scalarmap_parameters(thePattern)
1054 ind = random.randint(1,2)
1055 # --- SURFACES NUMBER ---
1057 anObj.SetNbSurfaces(random.randint(-100000,100000))
1059 anObj.SetNbSurfaces(random.randint(1, 50))
1063 def dump_isosurfaces_parameters(theObject):
1065 dump_scalarmap_parameters(theObject)
1066 print "GetNbSurfaces() = "+ str(theObject.GetNbSurfaces())
1068 # ----------------------------
1069 # SCALAR MAP ON DEFORMED SHAPE
1070 # ----------------------------
1071 def dump_scalarmapondeformedshape_parameters(theObject):
1072 dump_scalarmap_parameters(theObject)
1073 print "GetScale() =", theObject.GetScale()
1074 print "GetScalarCMeshName ()=|",theObject.GetScalarCMeshName(),"|"
1075 print "GetScalarCFieldName()=|",theObject.GetScalarCFieldName(),"|"
1076 print "GetScalarEEntity() =",theObject.GetScalarEEntity()
1077 print "GetScalarLIteration()=",theObject.GetScalarLIteration()
1080 def try_scalarmapondeformedshape_parameters(thePattern):
1082 if thePattern is None : return None
1086 anObj = try_scalarmap_parameters(thePattern)
1090 anObj.SetScale( anObj.GetScale()/random.random()*random.randint(1,10))
1092 # --- Scalar Field ---
1093 # not implemented yet.
1096 # ----------------------
1098 # ----------------------
1099 def dump_plot3d_parameters(theObject):
1100 dump_scalarmap_parameters(theObject)
1101 print "GetOrientationType()=",str(theObject.GetOrientationType())
1102 print "GetRotateX()=",theObject.GetRotateX()
1103 print "GetRotateY()=",theObject.GetRotateY()
1104 print "GetPlanePosition()=",theObject.GetPlanePosition()
1105 print "IsPositionRelative()=",theObject.IsPositionRelative()
1106 print "GetScaleFactor()=",theObject.GetScaleFactor()
1107 print "GetIsContourPrs()=",theObject.GetIsContourPrs()
1108 print "GetNbOfContours()=",theObject.GetNbOfContours()
1111 def try_plot3d_parameters(thePattern):
1112 if thePattern is None : return None
1115 anObj = try_scalarmap_parameters(thePattern)
1117 ORIENT = [VISU.Plot3D.XY, VISU.Plot3D.YZ, VISU.Plot3D.ZX]
1119 theXAngle = random.random()*random.randint(-180,180)
1120 theYAngle = random.random()*random.randint(-180,180)
1122 # ORIENTATION and ANGLES
1123 anObj.SetOrientation(ORIENT[random.randint(0,2)],theXAngle,theYAngle)
1125 # Plane position (revative)
1126 anObj.SetPlanePosition(random.random(),1)
1129 anObj.SetScaleFactor(random.random()*random.randint(-10000,10000))
1132 anObj.SetContourPrs(random.randint(0,1))
1133 if anObj.GetIsContourPrs():
1134 anObj.SetNbOfContours(random.randint(1,999))
1139 # ----------------------
1141 # ----------------------
1142 def dump_gausspoints_parameters(theObject):
1144 print "\tGetScalarMode() = " + str(anObj.GetScalarMode())
1145 print "\tGetMin() = " + str(anObj.GetMin()) + " GetMax() = " + str (anObj.GetMax())
1146 print "\tGetPosX() = ", str(anObj.GetPosX()) + " GetPosY() = ", str(anObj.GetPosY())
1147 print "\tGetWidth() = ", str ( anObj.GetWidth()) + " GetHeight() = " + str(anObj.GetHeight())
1148 print "\tGetNbColors() = " + str(anObj.GetNbColors())
1149 print "\tGetLabels() = " + str(anObj.GetLabels())
1150 print "\tGetTitle() = " + str(anObj.GetTitle())
1153 def try_plot3d_parameters(thePattern):
1154 if thePattern is None : return None
1159 # ----------------------
1161 # ----------------------
1163 def FillTable( theTable, theValues, theRows, theColumns, theRowTitles, theRowUnits, theColumnTitles ):
1164 if theTable is None: return
1165 if len(theRows) != len(theColumns): return
1166 if len(theRows) != len(theValues): return
1168 for value in theValues:
1169 theTable.PutValue( value, theRows[ i ], theColumns[ i ])
1173 for title in theRowTitles:
1174 theTable.SetRowTitle( i, title )
1175 theTable.SetRowUnit( i, theRowUnits[ i - 1 ])
1179 for title in theColumnTitles:
1180 theTable.SetColumnTitle( i, title )
1185 def CreateCurve( theTable, theHRow, theVRow, theTitle, theColor, theMarker, theLineType, theLineWidth ):
1186 if theTitle is None: return
1187 curve = myLocalVisu.CreateCurve( theTable, theHRow, theVRow );
1189 curve.SetTitle( theTitle )
1190 curve.SetColor( theColor )
1191 curve.SetMarker( theMarker )
1192 curve.SetLine( theLineType, theLineWidth )
1196 def CreateCurveWithZ( theTable, theHRow, theVRow, theZRow, theTitle, theColor, theMarker, theLineType, theLineWidth ):
1197 if theTitle is None: return
1198 curve = myLocalVisu.CreateCurveWithZ( theTable, theHRow, theVRow, theZRow );
1200 curve.SetTitle( theTitle )
1201 curve.SetColor( theColor )
1202 curve.SetMarker( theMarker )
1203 curve.SetLine( theLineType, theLineWidth )
1207 def CreateCurveWithZExt( theTable, theHRow, theVRow, theZRow, theIsV2, theTitle, theColor, theMarker, theLineType, theLineWidth ):
1208 if theTitle is None: return
1209 curve = myLocalVisu.CreateCurveWithZExt( theTable, theHRow, theVRow, theZRow, theIsV2 );
1211 curve.SetTitle( theTitle )
1212 curve.SetColor( theColor )
1213 curve.SetMarker( theMarker )
1214 curve.SetLine( theLineType, theLineWidth )