Salome HOME
SMH: 3.0.0 preparation - merged and adopted version (POLYWORK+HEAD)
[modules/visu.git] / src / VISU_SWIG / visu.py
index 86d8adc8a7392b8dccfdde36f65d6f9a3d58a542..1519f9ce7a7c4c01b616ed8f5aa496f598740754 100644 (file)
@@ -38,7 +38,8 @@ def Initialize(theORB, theNamingService, theLifeCycleCORBA, theStudyManager, the
     myNamingService = theNamingService
     myLifeCycleCORBA = theLifeCycleCORBA
     myLocalStudyManager = theStudyManager
-    mySession = myNamingService.Resolve("/Kernel/Session")
+    while mySession == None:
+       mySession = myNamingService.Resolve("/Kernel/Session")
     mySession = mySession._narrow(SALOME.Session)
     mySession.GetInterface()
     myDelay = theDelay
@@ -47,7 +48,40 @@ def Initialize(theORB, theNamingService, theLifeCycleCORBA, theStudyManager, the
     myLocalStudy = theStudy
     myLocalVisu.SetCurrentStudy(myLocalStudy)
     return myLocalVisu
+
+def PublishComponent(theStudyDocument):
+    aComponentDataType = myLocalVisu.ComponentDataType()
+    aSComponent = theStudyDocument.FindComponent(aComponentDataType)
+    if aSComponent == None:
+        aStudyBuilder = theStudyDocument.NewBuilder()
+        aStudyBuilder.NewCommand()
+        aLocked = theStudyDocument.GetProperties().IsLocked()
+        if aLocked:
+            theStudyDocument.GetProperties().SetLocked(0)
+            pass
+
+        aSComponent = aStudyBuilder.NewComponent(aComponentDataType);
+        aName = aStudyBuilder.FindOrCreateAttribute(aSComponent,"AttributeName")
+        aModuleCatalog = myNamingService.Resolve("/Kernel/ModulCatalog");
+        aComponent = aModuleCatalog.GetComponent(aComponentDataType);
+        if aComponent != None:
+            aComponentUserName = aComponent._get_componentusername()
+            aName.SetValue(aComponentUserName)
+            pass
+        
+        aPixMap = aStudyBuilder.FindOrCreateAttribute(aSComponent,"AttributePixMap")
+        aPixMap.SetPixMap("ICON_OBJBROWSER_Visu")
+        
+        aStudyBuilder.DefineComponentInstance(aSComponent,myLocalVisu);
+        if aLocked:
+            theStudyDocument.GetProperties().SetLocked(1);
+            pass
+        
+        aStudyBuilder.CommitCommand();
+        pass
     
+    return aSComponent;
+        
 def StrToMap(theString) :
     aPairList = split(theString,";")
     aMap = {}
@@ -99,17 +133,20 @@ def CreateStudyForMed(theVisu, theFileName) :
             return [aStudy, myViewManager, myView]
     raise RuntimeError, "Error: There is no shuch file."
 
-def getMedObjectFromStudy(theStudy = myLocalStudy):
+def getMedSObject(theStudy = myLocalStudy ):
     if theStudy is None:
         theStudy = myLocalStudy
-    mySO = theStudy.FindObject("Objet MED")
-    anAttr = mySO.FindAttribute("AttributeIOR")[1]
-    obj = myORB.string_to_object(anAttr.Value())
-    myObj = obj._narrow(SALOME_MED.MED)
-    return myObj
+    aSO = theStudy.FindObject("Med")
+    anIsPresetn, aSObject = aSO.FindSubObject(1)
+    return aSObject
 
-def getMedSObject(theStudy = myLocalStudy ):
-    return theStudy.FindObject("Objet MED")
+def getMedObjectFromStudy(theStudy = myLocalStudy):
+    aSObject = getMedSObject(theStudy)
+    if aSObject:
+        anAttr = aSObject.FindAttribute("AttributeIOR")[1]
+        anObj = myORB.string_to_object(anAttr.Value())
+        return  anObj._narrow(SALOME_MED.MED)
+    return None
 
 def getFieldObjectFromStudy(number, subnumber, theStudy = myLocalStudy):
     if theStudy is None:
@@ -825,3 +862,41 @@ def dump_isosurfaces_parameters(theObject):
     
     dump_scalarmap_parameters(theObject)
     print "GetNbSurfaces() = "+ str(theObject.GetNbSurfaces())
+
+
+# ----------------------
+# TABLES AND CURVES
+# ----------------------
+
+def FillTable( theTable, theValues, theRows, theColumns, theRowTitles, theRowUnits, theColumnTitles ):
+    if theTable is None: return
+    if len(theRows) != len(theColumns): return
+    if len(theRows) != len(theValues): return
+    i = 0
+    for value in theValues:
+        theTable.PutValue( value, theRows[ i ], theColumns[ i ])
+        i = i + 1
+        pass
+    i = 1
+    for title in theRowTitles:
+        theTable.SetRowTitle( i, title )
+        theTable.SetRowUnit( i, theRowUnits[ i - 1 ])
+        i = i + 1
+        pass
+    i = 1
+    for title in theColumnTitles:
+        theTable.SetColumnTitle( i, title )
+        i = i + 1
+        pass
+    pass
+
+def CreateCurve( theTable, theHRow, theVRow, theTitle, theColor, theMarker, theLineType, theLineWidth ):
+    if theTitle is None: return
+    curve = myLocalVisu.CreateCurve( theTable, theHRow, theVRow );
+    if curve:
+        curve.SetTitle( theTitle )
+        curve.SetColor( theColor )
+        curve.SetMarker( theMarker )
+        curve.SetLine( theLineType, theLineWidth )
+        pass
+    return curve