Salome HOME
This commit was generated by cvs2git to create branch 'BSEC_br1'.
[modules/kernel.git] / doc / html / INPUT / exemple / Example20.html
diff --git a/doc/html/INPUT/exemple/Example20.html b/doc/html/INPUT/exemple/Example20.html
new file mode 100755 (executable)
index 0000000..3019ad8
--- /dev/null
@@ -0,0 +1,160 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML>\r
+<HEAD>\r
+<!-- hennerik CVSweb $Revision$ -->\r
+<TITLE>Exemple</TITLE></HEAD>\r
+<BODY BGCOLOR="#eeeeee">\r
+<HR noshade><PRE>\r
+#^SALOMEDS methods : FindOrCreateAttribute, SaveAs, FindComponent, FindAttribute, NewCommand, GetProperties, Open, CommitCommand, NewBuilder^\r
+#^Attribute methods : SetLocked, IsLocked, GetCreationMode, SetCreationDate, IsModified, GetUserName, Value, SetUserName, SetValue, GetCreationDate^\r
+\r
+batchmode_geompy.myBuilder._set_UndoLimit(20)\r
+\r
+#--------------------------------------------------------------------------\r
+# &nbsp; &nbsp; &nbsp; create AttributeReal &nbsp; &nbsp; &nbsp;\r
+#===============================================\r
+A = batchmode_geompy.myBuilder.FindOrCreateAttribute(batchmode_geompy.father, &quot;AttributeReal&quot;)\r
+if A == None :\r
+ &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't create AttributeReal attribute&quot;\r
+A = A._narrow(SALOMEDS.AttributeReal)\r
+A.SetValue(0.0001)\r
+if A.Value() != 0.0001:\r
+ &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Error : wrong value of &nbsp;AttributeReal&quot;\r
+\r
+# &nbsp; &nbsp; &nbsp;create AttributeStudyProperties\r
+#================================================\r
+A = batchmode_geompy.myStudy.GetProperties()\r
+if A == None :\r
+ &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't create AttributeStudyProperties attribute&quot;\r
+A = A._narrow(SALOMEDS.AttributeStudyProperties)\r
+\r
+batchmode_geompy.myBuilder.NewCommand();\r
+print &quot;A.GetUserName()= &quot;, A.GetUserName()\r
+res,mm,hh,dd,mnth,yy=A.GetCreationDate()\r
+print &quot;A.GetCreationDate() = &quot;, mm,hh,dd,mnth,yy\r
+print &quot;A.GetCreationMode() = &quot;, A.GetCreationMode()\r
+print &quot;A.IsModified() = &quot;, A.IsModified()\r
+print &quot;A.IsLocked() = &quot;, A.IsLocked()\r
+if A.IsLocked() == 0 :\r
+ &nbsp; &nbsp; &nbsp; &nbsp;A.SetUserName(&quot;tester&quot;); print 'A.SetUserName(&quot;tester&quot;), A.GetUserName() = ', A.GetUserName()\r
+ &nbsp; &nbsp; &nbsp; &nbsp;A.SetCreationDate(11,11,11,11,2002); print 'A.SetCreationDate(11,11,11,11,2002), A.GetCreationDate() =', A.GetCreationDate()\r
+ &nbsp; &nbsp; &nbsp; &nbsp;print &quot;A.IsModified() = &quot;, A.IsModified()\r
+A.SetLocked(1)\r
+\r
+#check the transaction result \r
+batchmode_geompy.myBuilder.CommitCommand()\r
+if A.GetUserName() != &quot;tester&quot;:\r
+ &nbsp; &nbsp; &nbsp; &nbsp;print 'Control after transaction close : A.GetUserName() = ', A.GetUserName()\r
+ &nbsp; &nbsp; &nbsp; &nbsp;raise RuntimeError, &quot;Field 'UserName' was not modified but had to!&quot;\r
+\r
+# try to make some changes wrapped by transaction \r
+#================================================\r
+batchmode_geompy.myBuilder.NewCommand()\r
+A = batchmode_geompy.myBuilder.FindOrCreateAttribute(batchmode_geompy.father, &quot;AttributeInteger&quot;)\r
+\r
+if A == None :\r
+ &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't create AttributeInteger attribute&quot;\r
+A = A._narrow(SALOMEDS.AttributeInteger)\r
+A.SetValue(1000000)\r
+\r
+exception_was = None\r
+try : batchmode_geompy.myBuilder.CommitCommand()\r
+except Exception: exception_was = 1\r
+\r
+if exception_was is None:\r
+ &nbsp; &nbsp; &nbsp; &nbsp;raise RuntimeError, &quot;Study was locked for changes but CommitCommand did not generate an exception !&quot;\r
+\r
+# &nbsp; &nbsp; &nbsp;save / restore study &nbsp; &nbsp; &nbsp;\r
+\r
+#================================================\r
+str= os.getenv(&quot;TmpDir&quot;)\r
+if str == None:\r
+ &nbsp; &nbsp; &nbsp; &nbsp;str = &quot;/tmp&quot;\r
+file = str+&quot;/test.hdf&quot;\r
+\r
+print &quot; ------- &nbsp;We will save to&quot;, file, &quot;-----------&quot;\r
+\r
+batchmode_geompy.myStudyManager.SaveAs(file, batchmode_geompy.myStudy)\r
+\r
+\r
+#--------------------------------------------------------------------------#\r
+#--------------------------- Open file ------------------------------------# \r
+#--------------------------------------------------------------------------#\r
+\r
+print&quot; -------------- Open &nbsp;&quot; + file + &quot;-------------- &quot; \r
+\r
+openedStudy = batchmode_geompy.myStudyManager.Open(file)\r
+if openedStudy == None:\r
+ &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't open saved study!&quot;\r
+\r
+father = openedStudy.FindComponent(&quot;GEOM&quot;)\r
+if father is None:\r
+ &nbsp; &nbsp; &nbsp; &nbsp; raise &nbsp;RuntimeError, &quot;Geom component is not found! &nbsp;Wrong study is opened.&quot; \r
+\r
+\r
+#1. &nbsp; &nbsp; find AttributeReal\r
+#================================================\r
+\r
+res,A=father.FindAttribute(&quot;AttributeReal&quot;)\r
+if res == 0 or A == None:\r
+ &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Error: &nbsp;not found AttributeReal&quot;\r
+\r
+A = A._narrow(SALOMEDS.AttributeReal)\r
+if A.Value() != 0.0001:\r
+ &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Error : wrong value of &nbsp;AttributeReal&quot;\r
\r
+\r
+#2. &nbsp; &nbsp; find AttributeStudyProperties\r
+#=================================================\r
+A=openedStudy.GetProperties()\r
+if res == 0 or A == None:\r
+ &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Error: &nbsp;not found AttributeStudyProperties&quot;\r
+\r
+A = A._narrow(SALOMEDS.AttributeStudyProperties)\r
+if A.IsLocked() == 0 :\r
+ &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Error : AttributeStudyProperties must have Locked flag but have no!&quot;\r
+\r
+#get the builder\r
+myBuilder = openedStudy.NewBuilder()\r
+\r
+#3. try to make some changes wrapped by transaction \r
+#==================================================\r
+exception_was = None\r
+try : \r
+ &nbsp; &nbsp; &nbsp; &nbsp;myBuilder.NewCommand()\r
+ &nbsp; &nbsp; &nbsp; &nbsp;A = myBuilder.FindOrCreateAttribute(father, &quot;AttributeInteger&quot;)\r
+\r
+ &nbsp; &nbsp; &nbsp; &nbsp;if A == None :\r
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;raise &nbsp;RuntimeError, &quot;Can't create AttributeInteger attribute&quot;\r
+ &nbsp; &nbsp; &nbsp; &nbsp;A = A._narrow(SALOMEDS.AttributeInteger)\r
+ &nbsp; &nbsp; &nbsp; &nbsp;A.SetValue(1000000)\r
+ &nbsp; &nbsp; &nbsp; &nbsp;myBuilder.CommitCommand()\r
+except Exception: exception_was = 1\r
+\r
+if exception_was is None:\r
+ &nbsp; &nbsp; &nbsp; &nbsp;raise RuntimeError, &quot;Study was locked for changes but CommitCommand did not generate an exception !&quot;\r
+\r
+\r
+myBuilder.NewCommand()\r
+A=openedStudy.GetProperties()\r
+A = A._narrow(SALOMEDS.AttributeStudyProperties)\r
+A.SetLocked(0)\r
+myBuilder.CommitCommand()\r
+\r
+#4.\r
+myBuilder.NewCommand()\r
+A.SetLocked(0);\r
+print &quot;A.GetUserName()= &quot;, A.GetUserName()\r
+print &quot;A.GetCreationDate() = &quot;, A.GetCreationDate()\r
+print &quot;A.GetCreationMode() = &quot;, A.GetCreationMode()\r
+print &quot;A.IsModified() = &quot;, A.IsModified()\r
+myBuilder.CommitCommand()\r
+\r
+#5.\r
+myBuilder.NewCommand()\r
+A.SetUserName(&quot;tester1&quot;)\r
+myBuilder.CommitCommand()\r
+print &quot;A.GetUserName()= &quot;, A.GetUserName()\r
+\r
+#remove the document file\r
+os.remove(file)\r
+</PRE>
\ No newline at end of file