[Mobies-commit] [commit] r4244 - in UDM/trunk: bin lib src/Udm/PythonAPIGen src/UdmPython tests/test_UdmPythonDS

endre at redhat3.isis.vanderbilt.edu endre at redhat3.isis.vanderbilt.edu
Mon Jan 20 00:20:47 CST 2014


Author: endre
Date: Mon Jan 20 00:20:47 2014
New Revision: 4244

Log:
Working on Domain-Specific Python API & test (still not finished)

Added:
   UDM/trunk/lib/UdmPython.py
Deleted:
   UDM/trunk/bin/UdmPython.py
Modified:
   UDM/trunk/src/Udm/PythonAPIGen/PythonAPIGen.cpp
   UDM/trunk/src/UdmPython/UdmPython.cpp
   UDM/trunk/tests/test_UdmPythonDS/Makefile.OSX
   UDM/trunk/tests/test_UdmPythonDS/test.py

Added: UDM/trunk/lib/UdmPython.py
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ UDM/trunk/lib/UdmPython.py	Mon Jan 20 00:20:47 2014	(r4244)
@@ -0,0 +1,24 @@
+
+class UdmPython:
+	def __init__(self, impl):
+		self.__dict__['impl'] = impl
+		self.__dict__['id'] = impl.id
+		#self.name = impl.name
+	def is_lib_root(self):
+		return self.impl.is_lib_root
+	def is_lib_object(self):
+		return self.impl.is_lib_object
+	
+	def __eq__(self, other):
+		return self.impl == other.impl
+#	def __str__(self):
+#		return self.impl.type.name+"(id="+str(self.id)+", name="+self.name+")"
+	def __repr__(self):
+		return self.impl.__repr__()
+	def __getattr__(self, name):
+		return self.impl.__getattr__(name)
+	def __setattr__(self, name, value):
+		self.impl.__setattr__(name, value)
+
+	
+	

Modified: UDM/trunk/src/Udm/PythonAPIGen/PythonAPIGen.cpp
==============================================================================
--- UDM/trunk/src/Udm/PythonAPIGen/PythonAPIGen.cpp	Fri Jan 17 17:11:27 2014	(r4243)
+++ UDM/trunk/src/Udm/PythonAPIGen/PythonAPIGen.cpp	Mon Jan 20 00:20:47 2014	(r4244)
@@ -49,7 +49,7 @@
   m_output << "import sys" << endl;
   m_output << "import udm" << endl;
   m_output << "import Uml" << endl;
-  //m_output << "from UdmPython import *" << endl << endl;
+  m_output << "from UdmPython import *" << endl << endl;
 
 
   /*GENERATE PYTHON CLASSES*/
@@ -108,9 +108,8 @@
 
 void PythonAPIGen::generateClass(::Uml::Class &cls)
 {
-	//m_output << "class " << cls.name() << "(UdmPython):" << endl;
-	m_output << "class " << cls.name() << "(udm.Object):" << endl;
-    m_output << "\t\"\"\"Generated\"\"\"" << endl;
+	m_output << "class " << cls.name() << "(UdmPython):" << endl;
+   	m_output << "\t\"\"\"Generated\"\"\"" << endl;
 
 	generateAttributes(cls);
 	

Modified: UDM/trunk/src/UdmPython/UdmPython.cpp
==============================================================================
--- UDM/trunk/src/UdmPython/UdmPython.cpp	Fri Jan 17 17:11:27 2014	(r4243)
+++ UDM/trunk/src/UdmPython/UdmPython.cpp	Mon Jan 20 00:20:47 2014	(r4244)
@@ -572,6 +572,11 @@
 				// FIXME: does this leak?
 				return __Create(meta, parent, role, archetype, subtype);
 		}
+		static Udm::ObjectImpl* Cast(const Udm::Object &a, const Uml::Class & meta)
+		{
+			return __Cast(a, meta);
+		
+		}
 	};
 }
 
@@ -579,6 +584,11 @@
 	return Object_access::Create(Uml::Class::Cast(meta), parent, Udm::NULLCHILDROLE);
 }
 
+Udm::Object Object_cast(Udm::Object& o, Udm::Object& meta)
+{
+	return Object_access::Cast(o, Uml::Class::Cast(meta));
+}
+
 extern "C" {
 #ifdef _WIN32
 __declspec(dllexport) PyObject* __cdecl Object_Convert(Udm::Object udmObject) {
@@ -606,6 +616,8 @@
 		.add_property("id", &Udm::Object::uniqueId)
 		.add_property("parent", &Udm::Object::GetParent, &Object_SetParent)
 		.def("create", Object_create)
+		.def("__cast", Object_cast)
+		.staticmethod("__cast")
 		.def("delete", &Udm::Object::DeleteObject)
 		.def("_children", Object_children)
 		.def("_adjacent", Object_adjacent)

Modified: UDM/trunk/tests/test_UdmPythonDS/Makefile.OSX
==============================================================================
--- UDM/trunk/tests/test_UdmPythonDS/Makefile.OSX	Fri Jan 17 17:11:27 2014	(r4243)
+++ UDM/trunk/tests/test_UdmPythonDS/Makefile.OSX	Mon Jan 20 00:20:47 2014	(r4244)
@@ -14,6 +14,8 @@
 Lamp:../../samples/CreateLampModel/CreateLampModel
 	DYLD_LIBRARY_PATH=$(DYLDLIBRARYPATH) $< $@.mem $@.xml
 
+test:test.py Uml.py LampDiagram.py ../../lib/udm.so
+	DYLD_LIBRARY_PATH=$(DYLDLIBRARYPATH) VERSIONER_PYTHON_PREFER_32_BIT=$(VERSIONER_PYTHON_PREFER_32_BIT) python test.py
 
 
 

Modified: UDM/trunk/tests/test_UdmPythonDS/test.py
==============================================================================
--- UDM/trunk/tests/test_UdmPythonDS/test.py	Fri Jan 17 17:11:27 2014	(r4243)
+++ UDM/trunk/tests/test_UdmPythonDS/test.py	Mon Jan 20 00:20:47 2014	(r4244)
@@ -1,7 +1,29 @@
 import sys
 sys.path.append('/Users/endre/trunk/lib')
-import udm
-import Uml
-import LampDiagram
+import udm          # C++ UdmPhyton module
+import UdmPython    # python wrapper
+import Uml          # generated UML classes
+import LampDiagram  # generated Domain Specific API
 
 
+
+pdn = udm.SmartDataNetwork(udm.uml_diagram())
+pdn.open(r"../../samples/LampDiagram_udm.xml","")
+LampDiagram.initialize(udm.map_uml_names(pdn.root), udm.map_uml_names(udm.uml_diagram()))
+
+
+dn = udm.SmartDataNetwork(pdn.root)
+dn.open(r"Lamp.mem","")
+
+rf =LampDiagram.RootFolder(dn.root)
+l_children = rf.getLampChildren()
+lamp_1 = l_children[0]
+
+print lamp_1.ModelName
+lamp_1.ModelName = "test_python"
+print lamp_1.ModelName
+print lamp_1.meta.name
+
+
+dn.close_no_update()
+pdn.close_no_update()


More information about the Mobies-commit mailing list