Salome HOME
Initial version
[modules/gui.git] / doc / salome / tui / KERNEL / exemple / Example17.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML>\r
2 <HEAD>\r
3 <!-- hennerik CVSweb $Revision$ -->\r
4 <TITLE>Example</TITLE></HEAD>\r
5 <BODY BGCOLOR="#eeeeee">\r
6 <HR noshade><PRE>#% Check &nbsp;methods : %\r
7 SALOMEDS methods : RemoveAttribute, FindOrCreateAttribute, NewStudy, GetAllAttributes, NewCommand, CommitCommand, AbortCommand, NewComponent%\r
8 \r
9 batchmode_geompy.myBuilder._set_UndoLimit(20)\r
10 \r
11 batchmode_geompy.myBuilder.NewCommand() \r
12 child = batchmode_geompy.myBuilder.NewObject(batchmode_geompy.father)\r
13 batchmode_geompy.myBuilder.CommitCommand()\r
14 \r
15 batchmode_geompy.myBuilder.NewCommand() \r
16 #==========================================================\r
17 # &nbsp; &nbsp; &nbsp; create AttributeSequenceOfReal &nbsp; &nbsp; &nbsp;\r
18 #==========================================================\r
19 A = batchmode_geompy.myBuilder.FindOrCreateAttribute(child, &quot;AttributeSequenceOfReal&quot;)\r
20 if A == None :\r
21  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't create AttributeSequenceOfReal attribute&quot;\r
22 A = A._narrow(SALOMEDS.AttributeSequenceOfReal)\r
23 if A == None :\r
24  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;_narrow returns None instead of AttributeSequenceOfReal pointer&quot;\r
25 \r
26 A.Add(0.0293)\r
27 A.Add(522)\r
28 A.Add(98234)\r
29 A.Add(83.287)\r
30 batchmode_geompy.myBuilder.CommitCommand()\r
31 \r
32 \r
33 batchmode_geompy.myBuilder.NewCommand() \r
34 #==========================================================\r
35 # &nbsp; &nbsp; &nbsp;create &nbsp;AttributeInteger &nbsp; &nbsp; &nbsp;\r
36 #==========================================================\r
37 A = batchmode_geompy.myBuilder.FindOrCreateAttribute(child, &quot;AttributeInteger&quot;)\r
38 if A == None :\r
39  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't create AttributeInteger attribute&quot;\r
40 A = A._narrow(SALOMEDS.AttributeInteger)\r
41 A.SetValue(1000000)\r
42 \r
43 if A.Value() != 1000000:\r
44  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Error : wrong value of &nbsp;AttributeInteger&quot;\r
45 \r
46 batchmode_geompy.myBuilder.CommitCommand()\r
47 \r
48 batchmode_geompy.myBuilder.NewCommand() #===================\r
49 # &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;create AttributeName &nbsp; &nbsp; \r
50 #===========================================================\r
51 A = batchmode_geompy.myBuilder.FindOrCreateAttribute(child, &quot;AttributeName&quot;)\r
52 if A == None :\r
53  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't create AttributeName attribute&quot;\r
54 A = A._narrow(SALOMEDS.AttributeName)\r
55 \r
56 if A == None :\r
57  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't create AttributeName attribute&quot;\r
58 A.SetValue(&quot;AttributesTesting&quot;)\r
59 \r
60 if A.Value() != &quot;AttributesTesting&quot;:\r
61  &nbsp; &nbsp; &nbsp; &nbsp;print &quot;Wrong &nbsp;value of AttributeName&quot; &nbsp; &nbsp; &nbsp; &nbsp;\r
62 \r
63 batchmode_geompy.myBuilder.CommitCommand()\r
64 \r
65 batchmode_geompy.myBuilder.NewCommand() #===================\r
66 # &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;create &nbsp; &nbsp; AttributeComment \r
67 #===========================================================\r
68 A = batchmode_geompy.myBuilder.FindOrCreateAttribute(child, &quot;AttributeComment&quot;)\r
69 if A == None :\r
70  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't create AttributeComment attribute&quot;\r
71 A = A._narrow(SALOMEDS.AttributeComment)\r
72 \r
73 if A == None :\r
74  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't create AttributeComment attribute&quot;\r
75 \r
76 A.SetValue(&quot;GEOM&quot;)\r
77 \r
78 batchmode_geompy.myBuilder.AbortCommand()\r
79 \r
80 batchmode_geompy.myBuilder.NewCommand() #===================\r
81 # &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; create &nbsp; AttributePersistentRef &nbsp; \r
82 #===========================================================\r
83 A = batchmode_geompy.myBuilder.FindOrCreateAttribute(child, &quot;AttributePersistentRef&quot;)\r
84 if A == None :\r
85  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't create AttributePersistentRef attribute&quot;\r
86 A = A._narrow(SALOMEDS.AttributePersistentRef)\r
87 \r
88 if A == None :\r
89  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't create AttributePersistentRef attribute&quot;\r
90 \r
91 A.SetValue(&quot;/tmp/test;1&quot;)\r
92 batchmode_geompy.myBuilder.CommitCommand()\r
93 \r
94 batchmode_geompy.myBuilder.NewCommand() &nbsp;#===================================\r
95 # &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;create &nbsp; &nbsp;AttributeDrawable &nbsp;\r
96 #===========================================================\r
97 A = batchmode_geompy.myBuilder.FindOrCreateAttribute(child, &quot;AttributeDrawable&quot;)\r
98 if A == None :\r
99  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't create AttributeDrawable attribute&quot;\r
100 A = A._narrow(SALOMEDS.AttributeDrawable)\r
101 \r
102 if A == None :\r
103  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't create AttributeDrawable attribute&quot;\r
104 \r
105 A.SetDrawable(1)\r
106 \r
107 if A.IsDrawable() == 0:\r
108  &nbsp; &nbsp; &nbsp; &nbsp;&quot;Error: wrong value of AttributeDrawable&quot;\r
109 batchmode_geompy.myBuilder.CommitCommand()\r
110 \r
111 \r
112 \r
113 batchmode_geompy.myBuilder.NewCommand() #===================\r
114 # &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;create &nbsp; &nbsp;AttributeSelectable &nbsp;\r
115 #===========================================================\r
116 A = batchmode_geompy.myBuilder.FindOrCreateAttribute(child, &quot;AttributeSelectable&quot;)\r
117 if A == None :\r
118  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't create AttributeSelectable attribute&quot;\r
119 A = A._narrow(SALOMEDS.AttributeSelectable)\r
120 \r
121 if A == None :\r
122  &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't create AttributeSelectable attribute&quot;\r
123 \r
124 A.SetSelectable(1)\r
125 \r
126 if A.IsSelectable() == 0:\r
127  &nbsp; &nbsp; &nbsp; &nbsp;&quot;Error: wrong value of AttributeSelectable&quot;\r
128 batchmode_geompy.myBuilder.CommitCommand()\r
129 \r
130 \r
131 batchmode_geompy.myBuilder.NewCommand() #===================\r
132 #===========================================================\r
133 batchmode_geompy.myBuilder.RemoveAttribute(child,&quot;AttributeSelectable&quot;)\r
134 batchmode_geompy.myBuilder.CommitCommand()\r
135 \r
136 # Control the attributes \r
137 #===========================================================\r
138 \r
139 res, A = batchmode_geompy.myBuilder.FindAttribute(child, &quot;AttributeComment&quot;)\r
140 print &quot;res = &quot;, res\r
141 if A != None :\r
142  &nbsp; &nbsp; &nbsp; &nbsp;print &quot; AttributeComment was found&quot;\r
143 else:\r
144  &nbsp; &nbsp; &nbsp; &nbsp;print &quot; AttributeComment is not found. It's correct&quot;\r
145 \r
146 attributes=[]\r
147  \r
148 attributes = child.GetAllAttributes()\r
149 \r
150 length = len(attributes)\r
151 \r
152 print &quot;Attributes number = &quot;, length\r
153 print attributes\r
154 for i in range(0, length) :\r
155  &nbsp; &nbsp; &nbsp; &nbsp;attr = attributes[i]\r
156  &nbsp; &nbsp; &nbsp; &nbsp;if attr is None :\r
157  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print i,&quot;None item of object attributes list&quot;\r
158 \r
159 if length != 5 :\r
160  &nbsp; &nbsp; &nbsp; &nbsp;raise RuntimeError, &quot;Wrong number of attributes&quot;\r
161 \r
162 </PRE>