Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / VISU_SWIG / batchmode_visu.py
index 06dd539c5dcf361e8250669b302ea4ae346afcf8..559a3eb448664431ec4703ac1f9fd93433138526 100644 (file)
@@ -1,70 +1,76 @@
-import os
-import SALOME_MED
-import batchmode_salome 
-from omniORB import CORBA
-import SALOMEDS
+#  VISU VISU_SWIG : binding of C++ implementation and Python
+#
+#  Copyright (C) 2003  CEA/DEN, EDF R&D
+#
+#
+#
+#  File   : batchmode_visu.py
+#  Module : VISU
 
-mySession = batchmode_salome.naming_service.Resolve("/Kernel/Session")
-mySession.GetInterface()
-myVisu = batchmode_salome.lcc.FindOrLoadComponent("FactoryServer", "VISU")
+from batchmode_salome import *
+import visu
 
-def getMedObjectFromStudy():
-    mySO = batchmode_salome.myStudy.FindObject("Objet MED")
-    anAttr = mySO.FindAttribute("AttributeIOR")[1]
-    obj = batchmode_salome.orb.string_to_object(anAttr.Value())
-    myObj = obj._narrow(SALOME_MED.MED)
-    return myObj
+myVisu = visu.Initialize(orb,naming_service,lcc,myStudyManager,myStudy,10)
+if myVisu is None:
+    raise RuntimeError, "myVisu is none, VISU component is not loaded  or found"
 
-def getFieldObjectFromStudy(number,subnumber):
-    mySO = batchmode_salome.myStudy.FindObject("MEDFIELD")
-    if mySO is None:
-        raise Runtime, "getFieldObjectFromStudy mySO is None"
-    mysub = mySO.FindSubObject(number)[1]
-    if mysub:
-        mysubsub = mysub.FindSubObject(subnumber)[1]
-        if mysubsub:
-            Builder = batchmode_salome.myStudy.NewBuilder()
-            anAttr = Builder.FindOrCreateAttribute(mysubsub, "AttributeIOR")
-            obj = batchmode_salome.orb.string_to_object(anAttr.Value())
-            myObj = obj._narrow(SALOME_MED.FIELDINT)
-            if (myObj == None):
-               myObj = obj._narrow(SALOME_MED.FIELDDOUBLE)
-            return myObj
-    else:
-        print "ERROR: No Field Object stored in this Study"
-        return None
+def try_mesh_parameters(theMeshPattern):
+    aResult = []
+    if theMeshPattern is None : return aResult ;
+    theMeshPattern =  theMeshPattern._narrow(VISU.Mesh)
+    if theMeshPattern is None : return aResult ;
 
+    aTYPES = [VISU.POINT, VISU.WIREFRAME, VISU.SHADED, VISU.INSIDEFRAME, VISU.SHRINK]
+    import copy; import os;
+    for ind in aTYPES:
+        aNewMesh = copy.deepcopy(theMeshPattern);
+        aNewMesh.SetPresentationType(ind)
+        aResult.append(aNewMesh)
 
+    return aResult
+    
+def try_scalarmap_parameters(thePattern, theNum):
+    aList = []
+    if thePattern  is None : return aList 
+    thePattern =  thePattern._narrow(VISU.ScalarMap)
+    if thePattern  is None : return aList 
+    SCALING = [VISU.LINEAR, VISU.LOGARITHMIC]
+    import copy
+    import random
+    for ind in range(0,theNum):
+        anObj = copy.deepcopy(thePattern);
+        if ind%2 :
+            #try incorrect value deliberately (but allowed by idl description)
+            #try SetScalarMode(long)
+            mode = random.randint(-100000,100000); #incorrect value deliberately
+        else:
+            #correct value of ScalarMode
+            mode = random.randint(0, 3)
 
-def SObjectToObject(theSObject) :
-    if theSObject is None :
-        print "SObjectToObject : argument is None"
-    anObj = None                         
-    res,Attr = theSObject.FindAttribute("AttributeIOR")
-    if (res != 0) and (Attr is not None)  : 
-      anIOR  = Attr._narrow(SALOMEDS.AttributeIOR);
-      aValue = anIOR.Value();
-      if(len(aValue) != 0) :
-       anObj = orb.string_to_object(aValue);
-      else:
-       print "SObjectToObject - IOR = ''"
-    return anObj;
-med_comp = batchmode_salome.lcc.FindOrLoadComponent("FactoryServer", "Med")
+        print "\tSetScalarMode(" + str(mode) +")"
+        anObj.SetScalarMode(mode)
 
-
-#med_obj = getMedObjectFromStudy()
-
-#myBuilder = batchmode_salome.myStudy.NewBuilder()
-#father = batchmode_salome.myStudy.FindComponent("VISU")
-#myVisu.SetCurrentStudy(batchmode_salome.myStudy)
-#father = batchmode_salome.myStudy.FindComponent("VISU")
-#if father is None:
-#        father = myBuilder.NewComponent("VISU")
-#        A1 = myBuilder.FindOrCreateAttribute(father, "AttributeName");
-#        FName = A1._narrow(SALOMEDS.AttributeName)
-#        FName.SetValue("Visu")
-#              A2 = myBuilder.FindOrCreateAttribute(father, "AttributePixMap");
-#              aPixmap = A2._narrow(SALOMEDS.AttributePixMap);
-#      aPixmap.SetPixMap( "ICON_OBJBROWSER_Visu" );
-#      myBuilder.DefineComponentInstance(father,myVisu)
+        # --- SCALING ---
+        scal = random.randint(0,1)
+        print "\tSetScaling(" + str(SCALING[scal]) +")"
+        anObj.SetScaling(SCALING[scal])
+        
+        # --- BOUNDARIES ---
+        if ind%2 :
+            alfa =  random.random()*random.randint(-100000,100000)
+            betta = random.random()*random.randint(-100000,100000)
+            aMin = alfa; aMax = betta
+        else:
+            #more correct set
+            aPMin = thePattern.GetMin()
+            aPMax = thePattern.GetMax()
+            aLen = aPMax - aPMin
+            alfa =  random.random()%0.5
+            betta = random.random()%0.5
+            aMin = alfa*aLen*random.randint(-1,1) + aPMin
+            aMax = betta*aLen*random.randint(-1,1) + aPMax
+        print "\tSetRange(" + str(aMin) + ", " + str(aMax) + ")"
+        anObj.SetRange(aMin, aMax)
+        aList.append(anObj) 
+       
+    return aList