1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2010 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 SObjectToObject(theSObject) :
200 if theSObject is None :
201 print "SObjectToObject : argument is None"
203 res,Attr = theSObject.FindAttribute("AttributeIOR")
204 if (res != 0) and (Attr is not None) :
205 anIOR = Attr._narrow(SALOMEDS.AttributeIOR);
206 aValue = anIOR.Value();
207 if(len(aValue) != 0) :
208 anObj = myORB.string_to_object(aValue);
210 print "SObjectToObject - IOR = ''"
213 def CreatePrsForMed(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
215 global myLifeCycleCORBA
216 print "lcc.FindOrLoadComponent...",
217 aMedComp = myLifeCycleCORBA.FindOrLoadComponent("FactoryServer", "MED")
218 if aMedComp is None : print "Error"
221 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
223 print "aMedComp.readStructFileWithFieldType...",
224 aMedComp.readStructFileWithFieldType(theFileName,myLocalStudy._get_Name())
225 aMedSObj = getMedSObject(myLocalStudy)
226 if aMedSObj is None : raise RuntimeError, "Error"
229 print "theVisu.ImportMed...",
230 aResult = theVisu.ImportMed(aMedSObj)
231 if aResult is None : raise RuntimeError, "Error"
234 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
236 aResult.RemoveFromStudy()
238 aVISUObjList.append(aResult)
240 aFolderIter = myLocalStudy.NewChildIterator(aMedSObj.GetFather());
241 while aFolderIter.More() :
242 aFolderSObj = aFolderIter.Value()
244 anAttr = aFolderSObj.FindAttribute("AttributeName")[1]
245 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
246 aFolderName = anAttr.Value()
247 print " ", aFolderName
249 if aFolderName == 'MEDMESH' :
250 aMeshIter = myLocalStudy.NewChildIterator(aFolderSObj);
251 while aMeshIter.More() :
252 aMeshSObj = aMeshIter.Value()
254 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
255 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
256 aMeshName = anAttr.Value()
259 aSupportIter = myLocalStudy.NewChildIterator(aMeshSObj);
260 while aSupportIter.More() :
261 aSupportSObj = aSupportIter.Value()
263 anAttr = aSupportSObj.FindAttribute("AttributeName")[1]
264 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
265 aSupportName = anAttr.Value()
266 print " ", aSupportName
268 if aFolderName == 'MEDFIELD' :
269 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
270 while aFieldIter.More() :
271 aFieldSObj = aFieldIter.Value()
273 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
274 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
275 aFieldName = anAttr.Value()
276 print " ", aFieldName
278 print "theVisu.ImportMed...",
279 aResult = theVisu.ImportMed(aFieldSObj)
280 if aResult is None : raise RuntimeError, "Error"
283 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
285 aResult.RemoveFromStudy()
287 aVISUObjList.append(aResult)
289 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
290 if aTimeStampIter.More() :
291 aTimeStampIter.Next()
292 while aTimeStampIter.More() :
293 aTimeStampSObj = aTimeStampIter.Value()
294 aTimeStampIter.Next()
295 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
296 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
297 aTimeStampName = anAttr.Value()
298 print " ", aTimeStampName
300 print "theVisu.ImportMed...",
301 aMedField = SObjectToObject(aTimeStampSObj)
302 aResult = theVisu.ImportMedField(aMedField)
303 if aResult is None : raise RuntimeError, "Error"
306 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
308 aResult.RemoveFromStudy()
310 aVISUObjList.append(aResult)
314 # except Exception, e:
317 def CreatePrsForFile(theVisu, theFileName, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
319 aVISUObjList = [myLocalStudy, myViewManager, myView] = CreateStudyForMed(theVisu, theFileName)
321 print "theVisu.ImportMed...",
322 aResult = theVisu.ImportFile(theFileName)
323 if aResult is None : raise RuntimeError, "Error"
326 aVISUObjList.extend(CreatePrsForResult(theVisu, aResult, myView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete))
329 aResult.RemoveFromStudy()
331 aVISUObjList.append(aResult)
335 # except Exception, e:
338 def CreatePrsForResult(theVisu, theResult, theView, thePrsTypeList, thePictureDir, thePictureExt, theIsAutoDelete = 0) :
340 if theIsAutoDelete is not None :
344 print "CreatePrsForResult - myLocalStudy.FindObjectIOR...",
345 myLocalStudy = theVisu.GetCurrentStudy()
347 aSObj = myLocalStudy.FindObjectIOR(theResult.GetID())
348 if aSObj is None : raise RuntimeError, "Error"
350 aMeshIter = myLocalStudy.NewChildIterator(aSObj);
351 while aMeshIter.More() :
352 aMeshSObj = aMeshIter.Value()
354 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
356 aMeshSObj = aMeshIter.Value()
358 anAttr = aMeshSObj.FindAttribute("AttributeName")[1]
359 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
360 aMeshName = anAttr.Value()
361 aMeshNamePic = re.sub(".","_",aMeshName)
364 aFolderIter = myLocalStudy.NewChildIterator(aMeshSObj);
365 while aFolderIter.More() :
366 aFolderSObj = aFolderIter.Value()
368 anIsFound, anAttr = aFolderSObj.FindAttribute("AttributeName")
371 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
372 aFolderName = anAttr.Value()
373 print " ", aFolderName
375 if aFolderName == 'Families' :
376 anEntityIter = myLocalStudy.NewChildIterator(aFolderSObj);
377 while anEntityIter.More() :
378 anEntitySObj = anEntityIter.Value()
380 anAttr = anEntitySObj.FindAttribute("AttributeName")[1]
381 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
382 anEntityName = anAttr.Value()
385 if anEntityName == 'onNodes' :
388 if anEntityName == 'onEdges' :
391 if anEntityName == 'onFaces' :
394 if anEntityName == 'onCells' :
398 if HasValue(thePrsTypeList,VISU.TMESH) :
399 print " ", anEntityName, aMeshName,
400 aMesh = theVisu.MeshOnEntity(theResult,aMeshName,anEntity)
401 if aMesh is None : print "Error"
404 theView.DisplayOnly(aMesh)
406 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "." + thePictureExt
407 aPictureName = re.sub("\s+","_", aPictureName);
408 theView.SavePicture(aPictureName)
410 aMesh.RemoveFromStudy()
412 aVISUObjList.append(aMesh)
414 anFamilyIter = myLocalStudy.NewChildIterator(anEntitySObj);
415 while anFamilyIter.More() :
416 aFamilySObj = anFamilyIter.Value()
418 anAttr = aFamilySObj.FindAttribute("AttributeName")[1]
419 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
420 anFamilyName = anAttr.Value()
421 if HasValue(thePrsTypeList,VISU.TMESH) :
422 print " ", anFamilyName,
423 aMesh = theVisu.FamilyMeshOnEntity(theResult,aMeshName,anEntity,anFamilyName)
424 if aMesh is None : print "Error"
427 theView.DisplayOnly(aMesh)
429 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + anFamilyName + "." + thePictureExt
430 aPictureName = re.sub("\s+","_", aPictureName);
431 theView.SavePicture(aPictureName)
433 aMesh.RemoveFromStudy()
435 aVISUObjList.append(aMesh)
437 if aFolderName == 'Groups' :
438 aGroupIter = myLocalStudy.NewChildIterator(aFolderSObj);
439 while aGroupIter.More() :
440 aGroupSObj = aGroupIter.Value()
442 anAttr = aGroupSObj.FindAttribute("AttributeName")[1]
443 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
444 aGroupName = anAttr.Value()
445 if HasValue(thePrsTypeList,VISU.TMESH) :
446 print " ", aGroupName,
447 aMesh = theVisu.GroupMesh(theResult,aMeshName,aGroupName)
448 if aMesh is None : print "Error"
451 theView.DisplayOnly(aMesh)
453 aPictureName = thePictureDir + aMeshNamePic + "_" + aGroupName + "." + thePictureExt
454 aPictureName = re.sub("\s+","_", aPictureName);
455 theView.SavePicture(aPictureName)
457 aMesh.RemoveFromStudy()
459 aVISUObjList.append(aMesh)
461 if aFolderName == 'Fields' :
462 aFieldIter = myLocalStudy.NewChildIterator(aFolderSObj);
463 while aFieldIter.More() :
464 aFieldSObj = aFieldIter.Value()
466 anAttr = aFieldSObj.FindAttribute("AttributeName")[1]
467 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
468 aFieldName = anAttr.Value()
469 print " ", aFieldName
471 anAttr = aFieldSObj.FindAttribute("AttributeString")[1]
472 anAttr = anAttr._narrow(SALOMEDS.AttributeString);
473 aFieldComment = anAttr.Value()
474 aMap = StrToMap(aFieldComment)
476 aTimeStampIter = myLocalStudy.NewChildIterator(aFieldSObj);
477 if aTimeStampIter.More() :
478 aTimeStampIter.Next()
479 while aTimeStampIter.More() :
480 aTimeStampSObj = aTimeStampIter.Value()
481 aTimeStampIter.Next()
482 anAttr = aTimeStampSObj.FindAttribute("AttributeName")[1]
483 anAttr = anAttr._narrow(SALOMEDS.AttributeName);
484 aTimeStampName = anAttr.Value()
485 print " ", aTimeStampName
487 anAttr = aTimeStampSObj.FindAttribute("AttributeString")[1]
488 anAttr = anAttr._narrow(SALOMEDS.AttributeString);
489 aTimeStampComment = anAttr.Value()
490 aMap = StrToMap(aTimeStampComment)
491 aMeshName = aMap["myMeshName"]
492 aFieldName = aMap["myFieldName"]
493 aTimeStampId = atoi(aMap["myTimeStampId"])
494 anEntity = IntToEntity(aMap["myEntityId"])
495 anEntityId = str(aMap["myEntityId"]);
496 #print aMeshName, aFieldName, anEntity, aTimeStampId
497 if HasValue(thePrsTypeList,VISU.TSCALARMAP) :
498 print " Creating ScalarMapOnField",
499 aPrsObj = theVisu.ScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
500 if aPrsObj is None : print "Error"
503 theView.DisplayOnly(aPrsObj)
505 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSCALARMAP." + thePictureExt
506 aPictureName = re.sub("\s+","_", aPictureName);
507 theView.SavePicture(aPictureName)
509 aPrsObj.RemoveFromStudy()
511 aVISUObjList.append(aPrsObj)
513 if HasValue(thePrsTypeList,VISU.TISOSURFACES) :
514 print " Creating IsoSurfacesOnField",
515 aPrsObj = theVisu.IsoSurfacesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
516 if aPrsObj is None : print "Error"
519 theView.DisplayOnly(aPrsObj)
521 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TISOSURFACES." + thePictureExt
522 aPictureName = re.sub("\s+","_", aPictureName);
523 theView.SavePicture(aPictureName)
525 aPrsObj.RemoveFromStudy()
527 aVISUObjList.append(aPrsObj)
529 if HasValue(thePrsTypeList,VISU.TCUTPLANES) :
530 print " Creating CutPlanesOnField",
531 aPrsObj = theVisu.CutPlanesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
532 if aPrsObj is None : print "Error"
535 aPrsObj.SetOrientation(VISU.CutPlanes.ZX,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
536 theView.DisplayOnly(aPrsObj)
538 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTPLANES." + thePictureExt
539 aPictureName = re.sub("\s+","_", aPictureName)
540 theView.SavePicture(aPictureName)
542 aPrsObj.RemoveFromStudy()
544 aVISUObjList.append(aPrsObj)
546 if HasValue(thePrsTypeList,VISU.TCUTLINES) :
547 print " Creating CutLinesOnField",
548 aPrsObj = theVisu.CutLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
549 if aPrsObj is None : print "Error"
552 aPrsObj.SetOrientation(VISU.CutPlanes.XY,aPrsObj.GetRotateX(),aPrsObj.GetRotateY())
553 aPrsObj.SetOrientation2(VISU.CutPlanes.ZX,aPrsObj.GetRotateX2(),aPrsObj.GetRotateY2())
554 theView.DisplayOnly(aPrsObj)
556 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTLINES." + thePictureExt
557 aPictureName = re.sub("\s+","_", aPictureName)
558 theView.SavePicture(aPictureName)
560 aPrsObj.RemoveFromStudy()
562 aVISUObjList.append(aPrsObj)
564 if HasValue(thePrsTypeList,VISU.TCUTSEGMENT) :
565 print " Creating CutSegmentOnField",
566 aPrsObj = theVisu.CutSegmentOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
567 if aPrsObj is None : print "Error"
570 theView.DisplayOnly(aPrsObj)
572 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TCUTSEGMENT." + thePictureExt
573 aPictureName = re.sub("\s+","_", aPictureName)
574 theView.SavePicture(aPictureName)
576 aPrsObj.RemoveFromStudy()
578 aVISUObjList.append(aPrsObj)
580 if HasValue(thePrsTypeList,VISU.TPLOT3D) :
581 print " Creating Plot3DOnField",
582 aPrsObj = theVisu.Plot3DOnField(theResult,aMeshName,anEntity,
583 aFieldName,aTimeStampId)
584 if aPrsObj is None : print "Error"
587 #aPrsObj.SetOrientation(VISU.CutPlanes.ZX,
588 # aPrsObj.GetRotateX(),
589 # aPrsObj.GetRotateY())
590 theView.DisplayOnly(aPrsObj)
592 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TPLOT3D." + thePictureExt
593 aPictureName = re.sub("\s+","_", aPictureName)
594 theView.SavePicture(aPictureName)
596 aPrsObj.RemoveFromStudy()
598 aVISUObjList.append(aPrsObj)
600 aNumComponent = atoi(aMap["myNumComponent"])
601 if aNumComponent > 1 :
602 if HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPE) :
603 print " Creating DeformedShapeOnField",
604 aPrsObj = theVisu.DeformedShapeOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
605 if aPrsObj is None : print "Error"
608 theView.DisplayOnly(aPrsObj)
610 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPE." + thePictureExt
611 aPictureName = re.sub("\s+","_", aPictureName)
612 theView.SavePicture(aPictureName)
614 aPrsObj.RemoveFromStudy()
616 aVISUObjList.append(aPrsObj)
618 if HasValue(thePrsTypeList,VISU.TVECTORS) :
619 print " Creating VectorsOnField",
620 aPrsObj = theVisu.VectorsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
621 if aPrsObj is None : print "Error"
624 theView.DisplayOnly(aPrsObj)
626 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TVECTORS." + thePictureExt
627 aPictureName = re.sub("\s+","_", aPictureName)
628 theView.SavePicture(aPictureName)
630 aPrsObj.RemoveFromStudy()
632 aVISUObjList.append(aPrsObj)
634 if HasValue(thePrsTypeList,VISU.TSTREAMLINES) :
635 print " Creating StreamLinesOnField",
636 aPrsObj = theVisu.StreamLinesOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
637 if aPrsObj is None : print "Error"
640 theView.DisplayOnly(aPrsObj)
642 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TSTREAMLINES." + thePictureExt
643 aPictureName = re.sub("\s+","_", aPictureName)
644 theView.SavePicture(aPictureName)
646 aPrsObj.RemoveFromStudy()
648 aVISUObjList.append(aPrsObj)
650 if HasValue(thePrsTypeList,VISU.TSCALARMAPONDEFORMEDSHAPE) or HasValue(thePrsTypeList,VISU.TDEFORMEDSHAPEANDSCALARMAP) :
651 print " Creating DeformedShapeAndScalarMapOnField",
652 aPrsObj = theVisu.DeformedShapeAndScalarMapOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
653 if aPrsObj is None : print "Error"
656 theView.DisplayOnly(aPrsObj)
658 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TDEFORMEDSHAPEANDSCALARMAP." + thePictureExt
659 aPictureName = re.sub("\s+","_", aPictureName)
660 theView.SavePicture(aPictureName)
662 aPrsObj.RemoveFromStudy()
664 aVISUObjList.append(aPrsObj)
666 if HasValue(thePrsTypeList,VISU.TGAUSSPOINTS) :
667 print " Creating GaussPointsOnField",
668 aPrsObj = theVisu.GaussPointsOnField(theResult,aMeshName,anEntity,aFieldName,aTimeStampId)
669 if aPrsObj is None : print "Error"
672 theView.DisplayOnly(aPrsObj)
674 aPictureName = thePictureDir + aMeshNamePic + "_" + anEntityId + "_" + aFieldName + "_" + str(aTimeStampId) + "_TGAUSSPOINTS." + thePictureExt
675 aPictureName = re.sub("\s+","_", aPictureName)
676 theView.SavePicture(aPictureName)
678 aPrsObj.RemoveFromStudy()
681 aVISUObjList.append(aPrsObj)
689 def generateName(prefix = None):
691 int = random.randint(1,1000);
693 return "Study" + str(int)
695 return prefix + str(int)
699 # ----------------------
701 # ----------------------
702 def try_mesh_parameters(theMeshPattern):
704 if theMeshPattern is None : return aResult ;
705 theMeshPattern = theMeshPattern._narrow(VISU.Mesh)
706 if theMeshPattern is None : return aResult ;
708 aTYPES = [VISU.POINT, VISU.WIREFRAME, VISU.SHADED, VISU.INSIDEFRAME, VISU.SHRINK]
709 import copy; import os;
711 aNewMesh = copy.deepcopy(theMeshPattern);
712 aNewMesh.SetPresentationType(ind)
713 aResult.append(aNewMesh)
718 # ----------------------------
720 # ----------------------------
722 def try_scalarmap_parameters(thePattern, dump = 0):
724 if thePattern is None : return None
726 SCALING = [VISU.LINEAR, VISU.LOGARITHMIC]
730 anObj = thePattern#copy.deepcopy(thePattern);
731 #ind = random.randint(1,2)
733 #try incorrect value deliberately (but allowed by idl description)
734 #try SetScalarMode(long)
735 mode = random.randint(-100000,100000); #incorrect value deliberately
737 #correct value of ScalarMode
738 mode = random.randint(0, 3)
740 if dump : print "\tSetScalarMode(" + str(mode) +")"
741 anObj.SetScalarMode(mode)
744 scal = random.randint(0,1)
745 if dump : print "\tSetScaling(" + str(SCALING[scal]) +")"
746 anObj.SetScaling(SCALING[scal])
750 alfa = random.random()*random.randint(-100000,100000)
751 betta = random.random()*random.randint(-100000,100000)
752 aMin = alfa; aMax = betta
755 aPMin = thePattern.GetMin()
756 aPMax = thePattern.GetMax()
758 alfa = random.random()%0.5
759 betta = random.random()%0.5
760 aMin = alfa*aLen*random.randint(-1,1) + aPMin
761 aMax = betta*aLen*random.randint(-1,1) + aPMax
762 if dump : print "\tSetRange(" + str(aMin) + ", " + str(aMax) + ")"
763 anObj.SetRange(aMin, aMax)
767 X=random.random()*random.randint(-100000,100000)
768 Y=random.random()*random.randint(-100000,100000)
772 if dump : print "SetPosition("+ str(X) + ", " + str(Y) + " )"
773 anObj.SetPosition(X, Y)
775 # --- SCALAR BAR SIZE ---
777 aWidth=random.random()*random.randint(-100000,100000)
778 aHeight=random.random()*random.randint(-100000,100000)
780 aWidth=random.random()
781 aHeight=random.random()
782 if dump : print " SCALAR BAR Width = " + str(aWidth) + " Height = ", str(aHeight)
783 anObj.SetSize(aWidth, aHeight)
788 def dump_scalarmap_parameters(anObj):
790 print "\tGetScalarMode() = " + str(anObj.GetScalarMode())
791 print "\tGetScaling() = " + str(anObj.GetScaling())
792 print "\tGetMin() = " + str(anObj.GetMin()) + " GetMax() = " + str (anObj.GetMax())
793 print "\tGetOrientation() = " + str(anObj.GetOrientation())
794 print "\tGetPosX() = ", str(anObj.GetPosX()) + " GetPosY() = ", str(anObj.GetPosY())
795 print "\tGetWidth() = ", str ( anObj.GetWidth()) + " GetHeight() = " + str(anObj.GetHeight())
797 # ----------------------
799 # ----------------------
800 def try_deformedshape_parameters(thePattern) :
802 if thePattern is None : return None
806 anObj = try_scalarmap_parameters(thePattern)
810 anObj.SetScale( random.random()*random.randint(-100000, 100000))
812 anObj.SetScale( anObj.GetScale()*random.random())
817 def dump_deformedshape_parameters(theObject):
818 dump_scalarmap_parameters(theObject)
819 print "GetScale() = ", theObject.GetScale()
821 # ----------------------
823 # ----------------------
824 def try_cutplanes_parameters(thePattern) :
826 if thePattern is None : return None
830 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
832 ind = random.randint(1,2)
833 anObj = try_scalarmap_parameters(thePattern)
835 if ind%2 : anObj.SetNbPlanes(random.randint(-40,40))
836 else : anObj.SetNbPlanes(random.randint(0,10)) #try behaivor if NbPlanes=0
838 # --- DISPLACEMENT ---
839 anObj.SetDisplacement(random.randint(-100000,100000))
841 # --- PLANE POSITION ---
843 PlaneNb = random.randint(-100000,100000) #incorrect value is possible
844 else : PlaneNb = random.randint(0, anObj.GetNbPlanes())
846 anObj.SetPlanePosition(PlaneNb, random.random()*random.randint(-100000,100000))
848 # --- SET DEFAULT ---
849 anObj.SetDefault(PlaneNb)
851 # --- SET X,Y,Z ROTATION ---
853 angle1 = random.random()*random.randint(-100000,100000)
854 angle2 = random.random()*random.randint(-100000,100000)
856 angle1 = random.random()*3.14
857 angle2 = random.random()*3.14
859 # --- ORIENTATION ---
860 anObj.SetOrientation(ORIENT[random.randint(0,2)],angle1,angle2)
864 def dump_cutplanes_parameters(theObject):
865 dump_saclarmap_parameters(theObject)
867 print "GetOrientationType = " + str(theObject.GetOrientationType())
868 PlanesNb = theObject.GetNbPlanes()
869 print "GetNbPlanes() = ", str(PlanesNb)
870 for i in range(0,PlanesNb+1):
871 if theObject.IsDefault(i) :
872 print "Default plane : "+str(i); break
873 print "GetPlanePosition(" + str(i) + ") = ", theObject.GetPlanePosition(i)
874 print "GetDisplacement() = ", str(theObject.GetDisplacement())
875 print "GetRotateX() = ", str(theObject.GetRotateX())
876 print "GetRotateY() = ", str(theObject.GetRotateY())
877 print "GetRotateZ() = ", str(theObject.GetRotateZ())
879 # ----------------------
881 # ----------------------
882 def try_cutlines_parameters(thePattern):
884 if thePattern is None : return None
888 ORIENT = [VISU.CutPlanes.XY, VISU.CutPlanes.YZ, VISU.CutPlanes.ZX]
889 ind = random.randint(1,2)
890 anObj = try_scalarmap_parameters(thePattern)
892 # --- ORIENTATION ---
893 anObj.SetOrientation(ORIENT[random.randint(0,2)],
894 random.randint(-100,100)*random.random(),
895 random.randint(-100,100)*random.random())
896 anObj.SetOrientation2(ORIENT[random.randint(0,2)],
897 random.randint(-100,100)*random.random(),
898 random.randint(-100,100)*random.random())
900 # --- Base Plane Position ---
901 anObj.SetBasePlanePosition( random.random()*random.randint(-100000,100000))
903 # --- NUMBER OF LINES ---
905 anObj.SetNbLines(random.randint(-5, 50))
909 def dump_cutlines_parameters(theObject):
910 dump_scalarmap_parameters(theObject)
912 print "GetOrientationType() = " + str(theObject.GetOrientationType())
913 print "GetOrientationType2() = " + str(theObject.GetOrientationType2())
914 print "GetBasePlanePosition() = "+ str(theObject.GetBasePlanePosition())
915 print "GetNbLines() = " + str(theObject.GetNbLines())
916 print "GetRotateX() = ", str(theObject.GetRotateX())
917 print "GetRotateX2() = ", str(theObject.GetRotateX2())
918 print "GetRotateY() = ", str(theObject.GetRotateY())
919 print "GetRotateY2() = ", str(theObject.GetRotateY2())
921 # ----------------------
923 # ----------------------
924 def try_cutsegment_parameters(thePattern):
926 if thePattern is None : return None
930 anObj = try_scalarmap_parameters(thePattern)
932 anObj.SetPoint1(random.randint(-100,100)*random.random(),
933 random.randint(-100,100)*random.random(),
934 random.randint(-100,100)*random.random())
935 anObj.SetPoint2(random.randint(-100,100)*random.random(),
936 random.randint(-100,100)*random.random(),
937 random.randint(-100,100)*random.random())
941 def dump_cutsegment_parameters(theObject):
942 dump_scalarmap_parameters(theObject)
946 theObject.GetPoint1(x1, y1, z1)
947 theObject.GetPoint1(x2, y2, z2)
948 print "GetPoint1() = " + str(x1) + ", " + str(y1) + ", " + str(z1)
949 print "GetPoint2() = " + str(x2) + ", " + str(y2) + ", " + str(z2)
951 # ----------------------
953 # ----------------------
954 def try_streamlines_parameters(thePattern):
956 if thePattern is None : return None
960 DIRECTION = [VISU.StreamLines.FORWARD, VISU.StreamLines.BACKWARD, VISU.StreamLines.BOTH]
962 ind = random.randint(1,2)
963 anObj = (try_deformedshape_parameters(thePattern))[0]
966 anObj.SetDirection(DIRECTION[random.randint(0,2)])
968 # --- STEP LENGTH ---
969 if ind%2 : anObj.SetStepLength(random.random()*random.randint(-1000,1000))
971 aLen = anObj.GetMax() - anObj.GetMin()
972 anObj.SetStepLength(aLen/random.randint(1,100))
974 # --- PROPAGATION TIME ---
975 anObj.SetPropagationTime(random.random()*random.randint(1,100))
977 # --- INTEGRATION STEP ---
979 anObj.SetIntegrationStep(random.random()*random.randint(-1000,1000))
981 anObj.SetIntegrationStep(random.random())
984 anObj.SetUsedPoints(random.random()*random.randint(-10000,10000))
988 def dump_streamlines_parameters(theObject):
990 dump_deformedshape_parameters(theObject)
992 print "GetDirection() = " + str(theObject.GetDirection())
993 print "GetStepLength() = " + str(theObject.GetStepLength())
994 print "GetPropagationTime() =" + str(theObject.GetPropagationTime())
995 print "GetIntegrationStep() =" + str(theObject.GetIntegrationStep())
996 print "GetUsedPoints() =" + str(theObject.GetUsedPoints())
998 # ----------------------
1000 # ----------------------
1001 def try_vectors_parameters(thePattern, theNum):
1003 if thePattern is None : return None
1006 GLIPH_TYPE = [VISU.Vectors.ARROW, VISU.Vectors.CONE2, VISU.Vectors.CONE6, VISU.Vectors.NONE]
1007 GLIPH_POS = [VISU.Vectors.CENTER, VISU.Vectors.TAIL, VISU.Vectors.HEAD]
1008 ind = random.randint(1,2)
1009 anObj = (try_deformedshape_parameters(thePattern))[0]
1011 # --- LINE WIDTH ---
1013 anObj.SetLineWidth(random.random()*random.randint(-10000,10000))
1015 anObj.SetLineWidth(random.randint(1, 10))
1017 # --- GLIPH TYPE ---
1018 anObj.SetGlyphType(GLIPH_TYPE[random.randint(0, len(GLIPH_TYPE)-1)])
1021 anObj.SetGlyphPos(GLIPH_POS[random.randint(0, len(GLIPH_POS)-1)])
1025 def dump_vectors_parameters(theObject):
1027 dump_deformedshape_parameters(theObject)
1029 print "GetLineWidth() = " +str(theObject.GetLineWidth())
1030 print "GetGlyphType() = " +str(theObject.GetGlyphType())
1031 print "GetGlyphPos() = " +str(theObject.GetGlyphPos())
1034 # ----------------------
1036 # ----------------------
1038 def try_isosurfaces_parameters(thePattern) :
1039 if thePattern is None : return None
1043 anObj = try_scalarmap_parameters(thePattern)
1044 ind = random.randint(1,2)
1045 # --- SURFACES NUMBER ---
1047 anObj.SetNbSurfaces(random.randint(-100000,100000))
1049 anObj.SetNbSurfaces(random.randint(1, 50))
1053 def dump_isosurfaces_parameters(theObject):
1055 dump_scalarmap_parameters(theObject)
1056 print "GetNbSurfaces() = "+ str(theObject.GetNbSurfaces())
1058 # ----------------------------
1059 # SCALAR MAP ON DEFORMED SHAPE
1060 # ----------------------------
1061 def dump_scalarmapondeformedshape_parameters(theObject):
1062 dump_scalarmap_parameters(theObject)
1063 print "GetScale() =", theObject.GetScale()
1064 print "GetScalarCMeshName ()=|",theObject.GetScalarCMeshName(),"|"
1065 print "GetScalarCFieldName()=|",theObject.GetScalarCFieldName(),"|"
1066 print "GetScalarEEntity() =",theObject.GetScalarEEntity()
1067 print "GetScalarLIteration()=",theObject.GetScalarLIteration()
1070 def try_scalarmapondeformedshape_parameters(thePattern):
1072 if thePattern is None : return None
1076 anObj = try_scalarmap_parameters(thePattern)
1080 anObj.SetScale( anObj.GetScale()/random.random()*random.randint(1,10))
1082 # --- Scalar Field ---
1083 # not implemented yet.
1086 # ----------------------
1088 # ----------------------
1089 def dump_plot3d_parameters(theObject):
1090 dump_scalarmap_parameters(theObject)
1091 print "GetOrientationType()=",str(theObject.GetOrientationType())
1092 print "GetRotateX()=",theObject.GetRotateX()
1093 print "GetRotateY()=",theObject.GetRotateY()
1094 print "GetPlanePosition()=",theObject.GetPlanePosition()
1095 print "IsPositionRelative()=",theObject.IsPositionRelative()
1096 print "GetScaleFactor()=",theObject.GetScaleFactor()
1097 print "GetIsContourPrs()=",theObject.GetIsContourPrs()
1098 print "GetNbOfContours()=",theObject.GetNbOfContours()
1101 def try_plot3d_parameters(thePattern):
1102 if thePattern is None : return None
1105 anObj = try_scalarmap_parameters(thePattern)
1107 ORIENT = [VISU.Plot3D.XY, VISU.Plot3D.YZ, VISU.Plot3D.ZX]
1109 theXAngle = random.random()*random.randint(-180,180)
1110 theYAngle = random.random()*random.randint(-180,180)
1112 # ORIENTATION and ANGLES
1113 anObj.SetOrientation(ORIENT[random.randint(0,2)],theXAngle,theYAngle)
1115 # Plane position (revative)
1116 anObj.SetPlanePosition(random.random(),1)
1119 anObj.SetScaleFactor(random.random()*random.randint(-10000,10000))
1122 anObj.SetContourPrs(random.randint(0,1))
1123 if anObj.GetIsContourPrs():
1124 anObj.SetNbOfContours(random.randint(1,999))
1129 # ----------------------
1131 # ----------------------
1132 def dump_gausspoints_parameters(theObject):
1134 print "\tGetScalarMode() = " + str(anObj.GetScalarMode())
1135 print "\tGetMin() = " + str(anObj.GetMin()) + " GetMax() = " + str (anObj.GetMax())
1136 print "\tGetPosX() = ", str(anObj.GetPosX()) + " GetPosY() = ", str(anObj.GetPosY())
1137 print "\tGetWidth() = ", str ( anObj.GetWidth()) + " GetHeight() = " + str(anObj.GetHeight())
1138 print "\tGetNbColors() = " + str(anObj.GetNbColors())
1139 print "\tGetLabels() = " + str(anObj.GetLabels())
1140 print "\tGetTitle() = " + str(anObj.GetTitle())
1143 def try_plot3d_parameters(thePattern):
1144 if thePattern is None : return None
1149 # ----------------------
1151 # ----------------------
1153 def FillTable( theTable, theValues, theRows, theColumns, theRowTitles, theRowUnits, theColumnTitles ):
1154 if theTable is None: return
1155 if len(theRows) != len(theColumns): return
1156 if len(theRows) != len(theValues): return
1158 for value in theValues:
1159 theTable.PutValue( value, theRows[ i ], theColumns[ i ])
1163 for title in theRowTitles:
1164 theTable.SetRowTitle( i, title )
1165 theTable.SetRowUnit( i, theRowUnits[ i - 1 ])
1169 for title in theColumnTitles:
1170 theTable.SetColumnTitle( i, title )
1175 def CreateCurve( theTable, theHRow, theVRow, theTitle, theColor, theMarker, theLineType, theLineWidth ):
1176 if theTitle is None: return
1177 curve = myLocalVisu.CreateCurve( theTable, theHRow, theVRow );
1179 curve.SetTitle( theTitle )
1180 curve.SetColor( theColor )
1181 curve.SetMarker( theMarker )
1182 curve.SetLine( theLineType, theLineWidth )
1186 def CreateCurveWithZ( theTable, theHRow, theVRow, theZRow, theTitle, theColor, theMarker, theLineType, theLineWidth ):
1187 if theTitle is None: return
1188 curve = myLocalVisu.CreateCurveWithZ( theTable, theHRow, theVRow, theZRow );
1190 curve.SetTitle( theTitle )
1191 curve.SetColor( theColor )
1192 curve.SetMarker( theMarker )
1193 curve.SetLine( theLineType, theLineWidth )
1197 def CreateCurveWithZExt( theTable, theHRow, theVRow, theZRow, theIsV2, theTitle, theColor, theMarker, theLineType, theLineWidth ):
1198 if theTitle is None: return
1199 curve = myLocalVisu.CreateCurveWithZExt( theTable, theHRow, theVRow, theZRow, theIsV2 );
1201 curve.SetTitle( theTitle )
1202 curve.SetColor( theColor )
1203 curve.SetMarker( theMarker )
1204 curve.SetLine( theLineType, theLineWidth )