Back to index

salome-gui  6.5.0
test_table.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 # File   : test_table.py
00025 # Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
00026 #
00027 import salome
00028 import math
00029 import SALOMEDS
00030 
00031 # >>> Getting study builder ==================================================
00032 myStudy = salome.myStudy
00033 myBuilder = myStudy.NewBuilder()
00034 
00035 # >>> Creating virtual component =============================================
00036 myComponent = myStudy.FindComponent("VirtualComponent")
00037 if not myComponent:
00038    myComponent = myBuilder.NewComponent("VirtualComponent")
00039    aName = myBuilder.FindOrCreateAttribute(myComponent, "AttributeName")
00040    aName.SetValue("VirtualComponent")
00041 
00042 # >>> Creating object with Table of integer ==================================
00043 myTIntObject = myBuilder.NewObject(myComponent)
00044 AName = myBuilder.FindOrCreateAttribute(myTIntObject, "AttributeName")
00045 AName.SetValue("Table Of Integer")
00046 AIntTable = myBuilder.FindOrCreateAttribute(myTIntObject, "AttributeTableOfInteger")
00047 
00048 a=[1,2,3,4,5,6,7,8,9,10]
00049 AIntTable.AddRow(a)
00050 a=[110,120,130,140,150,160,170,180,190,200]
00051 AIntTable.AddRow(a)
00052 a=[-1,272,0,0,-642,10000,13,578,-578,99]
00053 AIntTable.AddRow(a)
00054 AIntTable.SetTitle("TEST table of integer")
00055 AIntTable.SetRowTitle(1,"FR")
00056 AIntTable.SetRowUnit(1,"m/h")
00057 AIntTable.SetRowTitle(2,"SR")
00058 AIntTable.SetRowUnit(2,"s")
00059 AIntTable.SetRowTitle(3,"TR")
00060 AIntTable.SetRowUnit(3,"$")
00061 c=["C1","C2","C3","C4","C5","C6","C7","C8","C9","C10"]
00062 AIntTable.SetColumnTitles(c)
00063 
00064 # >>> Creating object with Table of real =====================================
00065 myTRealObject = myBuilder.NewObject(myComponent)
00066 AName = myBuilder.FindOrCreateAttribute(myTRealObject, "AttributeName")
00067 AName.SetValue("Table Of Real")
00068 ARealTable = myBuilder.FindOrCreateAttribute(myTRealObject, "AttributeTableOfReal")
00069 
00070 k={}
00071 l={}
00072 for j in range(0,20):
00073    k[j] = j*10+1
00074    l[j] = "C"+str(j+1)
00075 ARealTable.AddRow(k.values())
00076 ARealTable.SetRowTitle(1, "Row 0")
00077 ARealTable.SetRowUnit(1, "Hz")
00078 ARealTable.SetColumnTitles(l.values())
00079 for i in range(1,11):
00080    for j in range(1,21):
00081       if j % 2 == 1:
00082          k[j] = math.log10(j*30*math.pi/180) * 20 + i * 15 + j*5
00083       else:
00084          k[j] = math.sin(j*30*math.pi/180) * 20 + i * 15 + j*5 
00085    ARealTable.AddRow(k.values())
00086    ARealTable.SetRowTitle(i+1, "Row " + str(i))
00087    ARealTable.SetRowUnit(i+1, "Wt")
00088 ARealTable.SetTitle("TEST table of real")
00089 
00090 # >>> Creating object with integer attribute =================================
00091 myIntObject = myBuilder.NewObject(myComponent)
00092 AName = myBuilder.FindOrCreateAttribute(myIntObject, "AttributeName")
00093 AName.SetValue("Integer")
00094 AInt = myBuilder.FindOrCreateAttribute(myIntObject, "AttributeInteger")
00095 AInt.SetValue(123)
00096 
00097 # >>> Creating object with real attribute ====================================
00098 myRealObject = myBuilder.NewObject(myComponent)
00099 AName = myBuilder.FindOrCreateAttribute(myRealObject, "AttributeName")
00100 AName.SetValue("Real")
00101 AReal = myBuilder.FindOrCreateAttribute(myRealObject, "AttributeReal")
00102 AReal.SetValue(-56.9634)
00103 
00104 # >>> Creating object with comment attribute =================================
00105 myCmtObject = myBuilder.NewObject(myComponent)
00106 AName = myBuilder.FindOrCreateAttribute(myCmtObject, "AttributeName")
00107 AName.SetValue("Comment")
00108 ACmt = myBuilder.FindOrCreateAttribute(myCmtObject, "AttributeComment")
00109 ACmt.SetValue("Just a comment")
00110 
00111 # >>> Updating Object Browser ================================================
00112 salome.sg.updateObjBrowser(1)
00113 
00114 # ============================================================================
00115 
00116 
00117