]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
More examples. Working with tables.
authorjfa <jfa@opencascade.com>
Wed, 25 May 2005 07:07:26 +0000 (07:07 +0000)
committerjfa <jfa@opencascade.com>
Wed, 25 May 2005 07:07:26 +0000 (07:07 +0000)
examples/VISU_Example_05.py [new file with mode: 0644]
examples/VISU_Example_06.py [new file with mode: 0644]
examples/tables_test.xls [new file with mode: 0644]

diff --git a/examples/VISU_Example_05.py b/examples/VISU_Example_05.py
new file mode 100644 (file)
index 0000000..a70943e
--- /dev/null
@@ -0,0 +1,77 @@
+# Create a table and show it in Plot2d viewer
+# 
+# This script is equivalent to script VISU_SWIG/visu_big_table.py
+
+import salome
+import math
+import SALOMEDS
+import VISU
+#from visu_gui import *
+
+# >>> Getting study builder ==================================================
+myStudy = salome.myStudy
+myBuilder = myStudy.NewBuilder()
+
+# >>> Getting (loading) VISU component =======================================
+myVisu = salome.lcc.FindOrLoadComponent("FactoryServer", "VISU")
+myComponent = myStudy.FindComponent("VISU")
+myVisu.SetCurrentStudy(myStudy)
+if not myComponent:
+   myComponent = myBuilder.NewComponent("VISU")
+   aName = myBuilder.FindOrCreateAttribute(myComponent, "AttributeName")
+   aName.SetValue( salome.sg.getComponentUserName("VISU") )
+   
+   A2 = myBuilder.FindOrCreateAttribute(myComponent, "AttributePixMap");
+   aPixmap = A2._narrow(SALOMEDS.AttributePixMap);
+   aPixmap.SetPixMap( "ICON_OBJBROWSER_Visu" );
+   
+   myBuilder.DefineComponentInstance(myComponent,myVisu)
+
+# >>> Creating object with Table of real[ 200 * 20 ] =========================
+myTRealObject = myBuilder.NewObject(myComponent)
+AName = myBuilder.FindOrCreateAttribute(myTRealObject, "AttributeName")
+AName.SetValue("Table Of Real")
+ARealTable = myBuilder.FindOrCreateAttribute(myTRealObject, "AttributeTableOfReal")
+myHorNb = 10
+myVerNb = 200
+
+k={}
+for j in range(0,myHorNb):
+   k[j] = j*10+1
+ARealTable.AddRow(k.values())
+ARealTable.SetRowTitle(1, "Frequency")
+ARealTable.SetRowUnit(1, "Hz")
+
+for i in range(1,myVerNb+1):
+   for j in range(0,myHorNb):
+      if j % 2 == 1:
+         k[j] = math.log10(j*30*math.pi/180) * 20 + i * 15 + j*5
+      else:
+         k[j] = math.sin(j*30*math.pi/180) * 20 + i * 15 + j*5 
+   ARealTable.AddRow(k.values())
+   ARealTable.SetRowTitle(i+1, "Power " + str(i))
+   ARealTable.SetRowUnit(i+1, "Wt")
+
+ARealTable.SetTitle("Very useful data")
+
+# >>> Create Visu table ======================================================
+myVisuTableReal = myVisu.CreateTable( myTRealObject.GetID() )
+
+# >>> Create container and insert curves
+myContainer = myVisu.CreateContainer()
+
+# >>> Create curves ==========================================================
+for i in range(1,myVerNb+1):
+   myCurve = myVisu.CreateCurve( myVisuTableReal, 1, i+1 )
+   myContainer.AddCurve(myCurve)
+
+# >>> Updating Object Browser ================================================
+salome.sg.updateObjBrowser(1)
+
+# >>> Display curves in Plot2d viewer ========================================
+myViewManager = myVisu.GetViewManager();
+myView = myViewManager.CreateXYPlot();
+myView.SetTitle("The viewer for Curves from the Table")
+myView.Display(myContainer)
+
+# ============================================================================
diff --git a/examples/VISU_Example_06.py b/examples/VISU_Example_06.py
new file mode 100644 (file)
index 0000000..a4eee6c
--- /dev/null
@@ -0,0 +1,61 @@
+# Import a table from file and show it in Plot2d viewer
+
+import salome
+import math
+import SALOMEDS
+import VISU
+#from visu_gui import *
+
+# >>> Getting study builder ==================================================
+myStudy = salome.myStudy
+myBuilder = myStudy.NewBuilder()
+
+# >>> Getting (loading) VISU component =======================================
+myVisu = salome.lcc.FindOrLoadComponent("FactoryServer", "VISU")
+myComponent = myStudy.FindComponent("VISU")
+myVisu.SetCurrentStudy(myStudy)
+if not myComponent:
+   myComponent = myBuilder.NewComponent("VISU")
+   aName = myBuilder.FindOrCreateAttribute(myComponent, "AttributeName")
+   #aName.SetValue("Visu")
+   aName.SetValue( salome.sg.getComponentUserName("VISU") )
+   
+   A2 = myBuilder.FindOrCreateAttribute(myComponent, "AttributePixMap");
+   aPixmap = A2._narrow(SALOMEDS.AttributePixMap);
+   aPixmap.SetPixMap( "ICON_OBJBROWSER_Visu" );
+   
+   myBuilder.DefineComponentInstance(myComponent,myVisu)
+
+# >>> Import a tables from a file ============================================
+aFileName = os.getenv("VISU_ROOT_DIR") + "/examples/tables_test.xls"
+sobj = myVisu.ImportTables(aFileName)
+
+# >>> Create container and insert curves =====================================
+myContainer = myVisu.CreateContainer()
+
+chiter = myStudy.NewChildIterator(sobj)
+while chiter.More():
+  sobj_table = chiter.Value()
+
+  # >>> Create Visu table ====================================================
+  myVisuTableReal = myVisu.CreateTable(sobj_table.GetID())
+
+  nbRows = myVisuTableReal.GetNbRows()
+
+  # >>> Create curves ========================================================
+  for i in range(1, nbRows):
+    myCurve = myVisu.CreateCurve(myVisuTableReal, 1, i+1)
+    myContainer.AddCurve(myCurve)
+
+  chiter.Next()
+
+# >>> Updating Object Browser ================================================
+salome.sg.updateObjBrowser(1)
+
+# >>> Display curves in Plot2d viewer ========================================
+myViewManager = myVisu.GetViewManager();
+myView = myViewManager.CreateXYPlot();
+myView.SetTitle("The viewer for Curves from the Table")
+myView.Display(myContainer)
+
+# ============================================================================
diff --git a/examples/tables_test.xls b/examples/tables_test.xls
new file mode 100644 (file)
index 0000000..4fedc01
--- /dev/null
@@ -0,0 +1,115 @@
+0 1
+1 2
+2 2.5
+
+#TITLE: Table toto 1
+#COLUMN_TITLES: toto 1 | titi2 | subtitle 2.3
+#COLUMN_UNITS: s kg/m3 m
+# It's a comment ...
+0 4.3 -3    #TITLE: row title 1
+1 5 6       #TITLE: row title 2
+# Another comment
+2 -7 4.5    #TITLE: row title 3
+
+#TITLE: sinus
+0.0 0.0
+0.01 0.125333233564
+0.02 0.248689887165
+0.03 0.368124552685
+0.04 0.481753674102
+0.05 0.587785252292
+0.06 0.684547105929
+0.07 0.770513242776
+0.08 0.844327925502
+0.09 0.904827052466
+0.1 0.951056516295
+0.11 0.982287250729
+0.12 0.998026728428
+0.13 0.998026728428
+0.14 0.982287250729
+0.15 0.951056516295
+0.16 0.904827052466
+0.17 0.844327925502
+0.18 0.770513242776
+0.19 0.684547105929
+0.2 0.587785252292
+0.21 0.481753674102
+0.22 0.368124552685
+0.23 0.248689887165
+0.24 0.125333233564
+0.25 1.22460635382e-16
+0.26 -0.125333233564
+0.27 -0.248689887165
+0.28 -0.368124552685
+0.29 -0.481753674102
+0.3 -0.587785252292
+0.31 -0.684547105929
+0.32 -0.770513242776
+0.33 -0.844327925502
+0.34 -0.904827052466
+0.35 -0.951056516295
+0.36 -0.982287250729
+0.37 -0.998026728428
+0.38 -0.998026728428
+0.39 -0.982287250729
+0.4 -0.951056516295
+0.41 -0.904827052466
+0.42 -0.844327925502
+0.43 -0.770513242776
+0.44 -0.684547105929
+0.45 -0.587785252292
+0.46 -0.481753674102
+0.47 -0.368124552685
+0.48 -0.248689887165
+0.49 -0.125333233564
+0.5 -2.44921270764e-16
+0.51 0.125333233564
+0.52 0.248689887165
+0.53 0.368124552685
+0.54 0.481753674102
+0.55 0.587785252292
+0.56 0.684547105929
+0.57 0.770513242776
+0.58 0.844327925502
+0.59 0.904827052466
+0.6 0.951056516295
+0.61 0.982287250729
+0.62 0.998026728428
+0.63 0.998026728428
+0.64 0.982287250729
+0.65 0.951056516295
+0.66 0.904827052466
+0.67 0.844327925502
+0.68 0.770513242776
+0.69 0.684547105929
+0.7 0.587785252292
+0.71 0.481753674102
+0.72 0.368124552685
+0.73 0.248689887165
+0.74 0.125333233564
+0.75 3.67381906147e-16
+0.76 -0.125333233564
+0.77 -0.248689887165
+0.78 -0.368124552685
+0.79 -0.481753674102
+0.8 -0.587785252292
+0.81 -0.684547105929
+0.82 -0.770513242776
+0.83 -0.844327925502
+0.84 -0.904827052466
+0.85 -0.951056516295
+0.86 -0.982287250729
+0.87 -0.998026728428
+0.88 -0.998026728428
+0.89 -0.982287250729
+0.9 -0.951056516295
+0.91 -0.904827052466
+0.92 -0.844327925502
+0.93 -0.770513242776
+0.94 -0.684547105929
+0.95 -0.587785252292
+0.96 -0.481753674102
+0.97 -0.368124552685
+0.98 -0.248689887165
+0.99 -0.125333233564
+1.0 -4.89842541529e-16