Salome HOME
Update copyright information
[modules/visu.git] / src / VISU_SWIG / VISU_Example_06.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
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.
11 #
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.
16 #
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
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23
24 # Import a table from file and show it in Plot2d viewer
25 #
26 import salome
27 import math
28 import SALOMEDS
29 import VISU
30 from visu_gui import *
31
32 # >>> Getting study builder ==================================================
33 myStudy = salome.myStudy
34 myBuilder = myStudy.NewBuilder()
35
36 # >>> Getting (loading) VISU component =======================================
37 myVisu = salome.lcc.FindOrLoadComponent("FactoryServer", "VISU")
38 myComponent = myStudy.FindComponent("VISU")
39 myVisu.SetCurrentStudy(myStudy)
40 if not myComponent:
41    myComponent = myBuilder.NewComponent("VISU")
42    aName = myBuilder.FindOrCreateAttribute(myComponent, "AttributeName")
43    #aName.SetValue("Visu")
44    aName.SetValue( salome.sg.getComponentUserName("VISU") )
45    
46    A2 = myBuilder.FindOrCreateAttribute(myComponent, "AttributePixMap");
47    aPixmap = A2._narrow(SALOMEDS.AttributePixMap);
48    aPixmap.SetPixMap( "ICON_OBJBROWSER_Visu" );
49    
50    myBuilder.DefineComponentInstance(myComponent,myVisu)
51
52 # >>> Import a tables from a file ============================================
53 aFileName = os.getenv("DATA_DIR") + "/Tables/tables_test.xls"
54 sobj = myVisu.ImportTables(aFileName, False)
55
56 # >>> Create container and insert curves =====================================
57 myContainer = myVisu.CreateContainer()
58
59 chiter = myStudy.NewChildIterator(sobj)
60 while chiter.More():
61   sobj_table = chiter.Value()
62
63   # >>> Create Visu table ====================================================
64   myVisuTableReal = myVisu.CreateTable(sobj_table.GetID())
65
66   nbRows = myVisuTableReal.GetNbRows()
67
68   # >>> Create curves ========================================================
69   for i in range(1, nbRows):
70     myCurve = myVisu.CreateCurve(myVisuTableReal, 1, i+1)
71     myContainer.AddCurve(myCurve)
72
73   chiter.Next()
74
75 # >>> Updating Object Browser ================================================
76 salome.sg.updateObjBrowser(1)
77
78 # >>> Display curves in Plot2d viewer ========================================
79 myViewManager = myVisu.GetViewManager();
80 myView = myViewManager.CreateXYPlot();
81 myView.SetTitle("The viewer for Curves from the Table")
82 myView.Display(myContainer)
83
84 # ============================================================================